refactor(core): move v1 schemas into core (#30473)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { NodeHttpServer, NodeServices } from "@effect/platform-node"
|
||||
import { NamedError } from "@opencode-ai/core/util/error"
|
||||
import { describe, expect } from "bun:test"
|
||||
import { ConfigError } from "../../src/config/error"
|
||||
import { ConfigErrorV1 } from "@opencode-ai/core/v1/config/error"
|
||||
import { Effect, Layer } from "effect"
|
||||
import { HttpClient, HttpClientRequest, HttpRouter } from "effect/unstable/http"
|
||||
import { errorLayer } from "../../src/server/routes/instance/httpapi/middleware/error"
|
||||
@@ -55,7 +55,7 @@ describe("HttpApi error middleware", () => {
|
||||
|
||||
it.live("does not expose config defects from generic middleware", () =>
|
||||
Effect.gen(function* () {
|
||||
const configError = new ConfigError.InvalidError({
|
||||
const configError = new ConfigErrorV1.InvalidError({
|
||||
path: "/tmp/opencode.json",
|
||||
issues: [{ message: "Expected object", path: ["provider", "anthropic", "options"] }],
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Flag } from "@opencode-ai/core/flag/flag"
|
||||
import { SessionLegacy } from "@opencode-ai/core/session/legacy"
|
||||
import { ConfigV1 } from "@opencode-ai/core/v1/config/config"
|
||||
import { SessionV1 } from "@opencode-ai/core/v1/session"
|
||||
import { Cause, Duration, Effect, Layer, Scope } from "effect"
|
||||
import { TestLLMServer } from "../../lib/llm-server"
|
||||
import type { Config } from "../../../src/config/config"
|
||||
@@ -144,7 +145,7 @@ function withContext<A, E>(
|
||||
}),
|
||||
message: (sessionID, input) =>
|
||||
Effect.gen(function* () {
|
||||
const info: SessionLegacy.User = {
|
||||
const info: SessionV1.User = {
|
||||
id: MessageID.ascending(),
|
||||
sessionID,
|
||||
role: "user",
|
||||
@@ -155,7 +156,7 @@ function withContext<A, E>(
|
||||
modelID: ProviderV2.ModelID.make("test"),
|
||||
},
|
||||
}
|
||||
const part: SessionLegacy.TextPart = {
|
||||
const part: SessionV1.TextPart = {
|
||||
id: PartID.ascending(),
|
||||
sessionID,
|
||||
messageID: info.id,
|
||||
@@ -205,7 +206,7 @@ function trace(options: Options, scenario: ActiveScenario, phase: string) {
|
||||
function projectOptions(
|
||||
project: ProjectOptions,
|
||||
llmUrl: string | undefined,
|
||||
): { git?: boolean; config?: Partial<Config.Info> } {
|
||||
): { git?: boolean; config?: Partial<ConfigV1.Info> } {
|
||||
if (!project.llm || !llmUrl) return { git: project.git, config: project.config }
|
||||
const fake = fakeLlmConfig(llmUrl)
|
||||
return {
|
||||
@@ -221,7 +222,7 @@ function projectOptions(
|
||||
}
|
||||
}
|
||||
|
||||
function fakeLlmConfig(url: string): Partial<Config.Info> {
|
||||
function fakeLlmConfig(url: string): Partial<ConfigV1.Info> {
|
||||
return {
|
||||
model: "test/test-model",
|
||||
small_model: "test/test-model",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { Duration, Effect } from "effect"
|
||||
import { SessionLegacy } from "@opencode-ai/core/session/legacy"
|
||||
import { ConfigV1 } from "@opencode-ai/core/v1/config/config"
|
||||
import { SessionV1 } from "@opencode-ai/core/v1/session"
|
||||
import type { Config } from "../../../src/config/config"
|
||||
import type { Project } from "../../../src/project/project"
|
||||
import type { Worktree } from "../../../src/worktree"
|
||||
@@ -15,7 +16,7 @@ export type Mode = "effect" | "coverage" | "auth"
|
||||
export type Comparison = "none" | "status" | "json"
|
||||
export type CaptureMode = "full" | "stream"
|
||||
export type AuthPolicy = "protected" | "public" | "public-bypass" | "ticket-bypass"
|
||||
export type ProjectOptions = { git?: boolean; config?: Partial<Config.Info>; llm?: boolean }
|
||||
export type ProjectOptions = { git?: boolean; config?: Partial<ConfigV1.Info>; llm?: boolean }
|
||||
export type OpenApiSpec = { paths?: Record<string, Partial<Record<OpenApiMethod, unknown>>> }
|
||||
export type JsonObject = Record<string, unknown>
|
||||
|
||||
@@ -58,7 +59,7 @@ export type ScenarioContext = {
|
||||
sessionGet: (sessionID: SessionID) => Effect.Effect<SessionInfo | undefined>
|
||||
project: () => Effect.Effect<Project.Info>
|
||||
message: (sessionID: SessionID, input?: { text?: string }) => Effect.Effect<MessageSeed>
|
||||
messages: (sessionID: SessionID) => Effect.Effect<SessionLegacy.WithParts[]>
|
||||
messages: (sessionID: SessionID) => Effect.Effect<SessionV1.WithParts[]>
|
||||
todos: (sessionID: SessionID, todos: TodoInfo[]) => Effect.Effect<void>
|
||||
worktree: (input?: { name?: string }) => Effect.Effect<Worktree.Info>
|
||||
worktreeRemove: (directory: string) => Effect.Effect<void>
|
||||
@@ -119,4 +120,4 @@ export type Result =
|
||||
|
||||
export type SessionInfo = { id: SessionID; title: string; parentID?: SessionID }
|
||||
export type TodoInfo = { content: string; status: string; priority: string }
|
||||
export type MessageSeed = { info: SessionLegacy.User; part: SessionLegacy.TextPart }
|
||||
export type MessageSeed = { info: SessionV1.User; part: SessionV1.TextPart }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PermissionLegacy } from "@opencode-ai/core/permission/legacy"
|
||||
import { PermissionV1 } from "@opencode-ai/core/v1/permission"
|
||||
import { NodeHttpServer, NodeServices } from "@effect/platform-node"
|
||||
import { Flag } from "@opencode-ai/core/flag/flag"
|
||||
import { describe, expect } from "bun:test"
|
||||
@@ -167,7 +167,7 @@ describe("instance HttpApi", () => {
|
||||
handlerContext,
|
||||
),
|
||||
)
|
||||
const permissionID = PermissionLegacy.ID.ascending()
|
||||
const permissionID = PermissionV1.ID.ascending()
|
||||
const questionReplyID = QuestionID.ascending()
|
||||
const questionRejectID = QuestionID.ascending()
|
||||
const [permission, questionReply, questionReject] = yield* Effect.all(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { afterEach, describe, expect } from "bun:test"
|
||||
import { SessionLegacy } from "@opencode-ai/core/session/legacy"
|
||||
import { ConfigV1 } from "@opencode-ai/core/v1/config/config"
|
||||
import { SessionV1 } from "@opencode-ai/core/v1/session"
|
||||
import { Deferred, Effect, Layer } from "effect"
|
||||
import type * as Scope from "effect/Scope"
|
||||
import { HttpServer } from "effect/unstable/http"
|
||||
@@ -190,7 +191,7 @@ function httpapiInstance<A, E>(
|
||||
options: {
|
||||
serverPath: ServerPath
|
||||
git?: boolean
|
||||
config?: Partial<Config.Info>
|
||||
config?: Partial<ConfigV1.Info>
|
||||
setup?: (dir: string) => Effect.Effect<void, E, TestServices>
|
||||
},
|
||||
run: (input: ProjectFixture) => Effect.Effect<A, E, TestScope>,
|
||||
@@ -214,7 +215,7 @@ function withProject<A, E, E2 = never>(
|
||||
serverPath: ServerPath,
|
||||
options: {
|
||||
git?: boolean
|
||||
config?: Partial<Config.Info>
|
||||
config?: Partial<ConfigV1.Info>
|
||||
setup?: (dir: string) => Effect.Effect<void, E2, TestServices>
|
||||
},
|
||||
run: (input: ProjectFixture) => Effect.Effect<A, E, TestScope>,
|
||||
@@ -300,7 +301,7 @@ function seedMessage(directory: string, sessionID: string) {
|
||||
agent: "test",
|
||||
model: { providerID: ProviderV2.ID.make("test"), modelID: ProviderV2.ModelID.make("test") },
|
||||
tools: {},
|
||||
} satisfies SessionLegacy.User)
|
||||
} satisfies SessionV1.User)
|
||||
const part = yield* svc.updatePart({
|
||||
id: PartID.ascending(),
|
||||
sessionID: id,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { PermissionLegacy } from "@opencode-ai/core/permission/legacy"
|
||||
import { PermissionV1 } from "@opencode-ai/core/v1/permission"
|
||||
import { afterEach, describe, expect } from "bun:test"
|
||||
import { NodeHttpServer, NodeServices } from "@effect/platform-node"
|
||||
import { SessionLegacy } from "@opencode-ai/core/session/legacy"
|
||||
import { SessionV1 } from "@opencode-ai/core/v1/session"
|
||||
import { mkdir } from "node:fs/promises"
|
||||
import path from "node:path"
|
||||
import { Cause, Config, Effect, Exit, Layer } from "effect"
|
||||
@@ -362,7 +362,7 @@ describe("session HttpApi", () => {
|
||||
const messages = yield* request(`${pathFor(SessionPaths.messages, { sessionID: parent.id })}?limit=1`, {
|
||||
headers,
|
||||
})
|
||||
const messagePage = yield* json<SessionLegacy.WithParts[]>(messages)
|
||||
const messagePage = yield* json<SessionV1.WithParts[]>(messages)
|
||||
const nextCursor = messages.headers["x-next-cursor"]
|
||||
expect(nextCursor).toBeTruthy()
|
||||
expect(messagePage[0]?.parts[0]).toMatchObject({ type: "text" })
|
||||
@@ -379,7 +379,7 @@ describe("session HttpApi", () => {
|
||||
).toBe(400)
|
||||
|
||||
expect(
|
||||
yield* requestJson<SessionLegacy.WithParts>(
|
||||
yield* requestJson<SessionV1.WithParts>(
|
||||
pathFor(SessionPaths.message, { sessionID: parent.id, messageID: message.info.id }),
|
||||
{ headers },
|
||||
),
|
||||
@@ -829,7 +829,7 @@ describe("session HttpApi", () => {
|
||||
const first = yield* createTextMessage(session.id, "first")
|
||||
const second = yield* createTextMessage(session.id, "second")
|
||||
|
||||
const updated = yield* requestJson<SessionLegacy.Part>(
|
||||
const updated = yield* requestJson<SessionV1.Part>(
|
||||
pathFor(SessionPaths.updatePart, {
|
||||
sessionID: session.id,
|
||||
messageID: first.info.id,
|
||||
@@ -913,7 +913,7 @@ describe("session HttpApi", () => {
|
||||
}),
|
||||
).toMatchObject({ id: session.id })
|
||||
|
||||
const permissionID = String(PermissionLegacy.ID.ascending())
|
||||
const permissionID = String(PermissionV1.ID.ascending())
|
||||
const permission = yield* request(
|
||||
pathFor(SessionPaths.permissions, {
|
||||
sessionID: session.id,
|
||||
|
||||
@@ -15,7 +15,7 @@ import { Effect, Layer } from "effect"
|
||||
import { SessionPaths } from "@/server/routes/instance/httpapi/groups/session"
|
||||
import { Session } from "@/session/session"
|
||||
import { Storage } from "@/storage/storage"
|
||||
import { SessionLegacy } from "@opencode-ai/core/session/legacy"
|
||||
import { SessionV1 } from "@opencode-ai/core/v1/session"
|
||||
import { MessageID } from "@/session/schema"
|
||||
import { ProviderV2 } from "@opencode-ai/core/provider"
|
||||
import { resetDatabase } from "../fixture/db"
|
||||
@@ -83,7 +83,7 @@ describe("session diff with missing patch (#26574)", () => {
|
||||
summary: {
|
||||
diffs: [{ file: "turn.ts", additions: 1, deletions: 0, status: "modified" }],
|
||||
},
|
||||
} satisfies SessionLegacy.User)
|
||||
} satisfies SessionV1.User)
|
||||
|
||||
const response = yield* requestInDirectory(
|
||||
`${pathFor(SessionPaths.diff, { sessionID: session.id })}?messageID=${messageID}`,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { afterEach, describe, expect } from "bun:test"
|
||||
import { SessionLegacy } from "@opencode-ai/core/session/legacy"
|
||||
import { SessionV1 } from "@opencode-ai/core/v1/session"
|
||||
import { Effect, Layer } from "effect"
|
||||
import { HttpClientResponse } from "effect/unstable/http"
|
||||
import { Session as SessionNs } from "@/session/session"
|
||||
@@ -65,14 +65,14 @@ const fill = Effect.fn("SessionMessagesTest.fill")(function* (
|
||||
agent: "test",
|
||||
model,
|
||||
tools: {},
|
||||
} satisfies SessionLegacy.User)
|
||||
} satisfies SessionV1.User)
|
||||
yield* session.updatePart({
|
||||
id: PartID.ascending(),
|
||||
sessionID,
|
||||
messageID: id,
|
||||
type: "text",
|
||||
text: `m${i}`,
|
||||
} satisfies SessionLegacy.TextPart)
|
||||
} satisfies SessionV1.TextPart)
|
||||
return id
|
||||
}),
|
||||
)
|
||||
@@ -96,7 +96,7 @@ describe("session messages endpoint", () => {
|
||||
|
||||
const a = yield* request(`/session/${session.id}/message?limit=2`)
|
||||
expect(a.status).toBe(200)
|
||||
const aBody = yield* json<SessionLegacy.WithParts[]>(a)
|
||||
const aBody = yield* json<SessionV1.WithParts[]>(a)
|
||||
expect(aBody.map((item) => item.info.id)).toEqual(ids.slice(-2))
|
||||
const cursor = a.headers["x-next-cursor"]
|
||||
expect(cursor).toBeTruthy()
|
||||
@@ -104,7 +104,7 @@ describe("session messages endpoint", () => {
|
||||
|
||||
const b = yield* request(`/session/${session.id}/message?limit=2&before=${encodeURIComponent(cursor!)}`)
|
||||
expect(b.status).toBe(200)
|
||||
const bBody = yield* json<SessionLegacy.WithParts[]>(b)
|
||||
const bBody = yield* json<SessionV1.WithParts[]>(b)
|
||||
expect(bBody.map((item) => item.info.id)).toEqual(ids.slice(-4, -2))
|
||||
}),
|
||||
),
|
||||
@@ -120,7 +120,7 @@ describe("session messages endpoint", () => {
|
||||
|
||||
const res = yield* request(`/session/${session.id}/message`)
|
||||
expect(res.status).toBe(200)
|
||||
const body = yield* json<SessionLegacy.WithParts[]>(res)
|
||||
const body = yield* json<SessionV1.WithParts[]>(res)
|
||||
expect(body.map((item) => item.info.id)).toEqual(ids)
|
||||
}),
|
||||
),
|
||||
@@ -152,7 +152,7 @@ describe("session messages endpoint", () => {
|
||||
|
||||
const res = yield* request(`/session/${session.id}/message?limit=510`)
|
||||
expect(res.status).toBe(200)
|
||||
const body = yield* json<SessionLegacy.WithParts[]>(res)
|
||||
const body = yield* json<SessionV1.WithParts[]>(res)
|
||||
expect(body).toHaveLength(510)
|
||||
}),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user