From 9a9386edbcfc9a32b2c58b002b3f56dff771dec7 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Wed, 28 Oct 2026 15:18:38 -0700 Subject: [PATCH] refactor(client): group experimental SDK methods under client.experimental (#59072) --- AGENTS.md | 11 + packages/app/src/home/projects/controller.tsx | 2 +- packages/app/src/providers/connect/mcp.ts | 17 +- packages/app/src/runtime/server/sync.tsx | 7 +- packages/app/src/session/revert.ts | 2 +- .../app/src/settings/general/controllers.ts | 2 +- packages/app/src/voice/tools.ts | 3 +- packages/app/src/voice/transport.ts | 13 +- packages/app/src/workspaces/files/model.tsx | 4 +- packages/cli/src/acp/sessions.ts | 2 +- .../cli/src/commands/handlers/auth/login.ts | 2 +- .../src/commands/handlers/session/export.ts | 2 +- packages/cli/src/commands/handlers/stats.ts | 2 +- packages/cli/src/run/noninteractive.ts | 2 +- packages/cli/test/fixture/mini-wait.ts | 8 +- packages/cli/test/run/noninteractive.test.ts | 4 +- packages/client/script/generate.ts | 22 +- packages/client/src/contract.ts | 2 +- packages/client/src/effect/api/api.ts | 1105 ++++++++++----- .../client/src/effect/generated/client.ts | 714 ++++++---- packages/client/src/promise/api.ts | 3 + .../client/src/promise/generated/client.ts | 1180 +++++++++-------- .../client/src/promise/generated/types.ts | 790 ++++++----- packages/client/src/solid/data.ts | 2 +- packages/client/test/api.types.ts | 14 +- .../client/test/deprecated-aliases.test.ts | 45 + packages/client/test/effect.test.ts | 16 +- packages/client/test/promise.test.ts | 144 +- .../desktop/src/renderer/migration-status.tsx | 6 +- .../gui-plugins/src/details/server-panel.tsx | 4 +- packages/httpapi-codegen/src/index.ts | 512 +++++-- .../httpapi-codegen/test/generate.test.ts | 181 +++ packages/plugin/src/effect/plugin.ts | 6 +- packages/plugin/src/effect/session.ts | 11 +- packages/plugin/src/promise/plugin.ts | 6 +- packages/plugin/src/promise/session.ts | 11 +- packages/protocol/openapi.json | 24 +- packages/protocol/src/client.ts | 6 + .../protocol/src/groups/persistent-pty.ts | 21 +- packages/protocol/src/groups/session.ts | 2 +- .../test/experimental-identifiers.test.ts | 24 + packages/sdk/test/contract-identity.test.ts | 6 +- packages/sdk/test/embedded.test.ts | 24 +- packages/sdk/test/instances-effect.test.ts | 6 +- packages/sdk/test/promise.test.ts | 2 +- packages/sdk/test/transport.test.ts | 4 +- packages/server/test/media.test.ts | 4 +- packages/server/test/message.test.ts | 2 +- packages/server/test/sse-failure.test.ts | 2 +- packages/tui/src/component/devtools-bar.tsx | 2 +- packages/tui/src/component/dialog-mcp.tsx | 2 +- .../tui/src/component/migration-overlay.tsx | 2 +- .../tui/src/feature-plugins/system/stats.tsx | 2 +- packages/tui/src/mini/stream-v2.transport.ts | 2 +- packages/tui/src/routes/session/index.tsx | 6 +- .../tui/test/mini/stream-v2.transport.test.ts | 2 +- .../src/docs/content/build/client/effect.mdx | 2 +- .../src/docs/content/build/plugins/effect.mdx | 2 +- .../src/docs/content/build/plugins/server.mdx | 8 +- 59 files changed, 3277 insertions(+), 1737 deletions(-) create mode 100644 packages/client/test/deprecated-aliases.test.ts create mode 100644 packages/protocol/test/experimental-identifiers.test.ts diff --git a/AGENTS.md b/AGENTS.md index 44d368b8e04..d4282d4db0e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -169,6 +169,17 @@ const table = sqliteTable("session", { }) ``` +### Experimental API + +- An experimental endpoint lives at `/api/experimental//...`, its OpenAPI identifier is `experimental..`, and it lands in the SDK as `client.experimental..`. Its description says "Experimental: may change without compatibility guarantees." +- `packages/protocol/test/experimental-identifiers.test.ts` enforces the path and identifier match in both directions; the SDK namespace follows from the path. +- An experimental field or parameter on a stable endpoint goes under an `experimental` key (`experimental.`), the same way config does (`config.experimental.*`). +- New endpoints and new default behaviors start experimental. +- To graduate one, move the route out of `/api/experimental`, drop the `experimental.` prefix, and note it in `CHANGELOG.md`. +- Experimental HTTP routes change without aliases: rename or remove the route, then update the callers. +- A breaking move of shipped SDK or plugin API (including moving it under `experimental`) keeps the old path and type names as deprecated aliases of the new ones until the next minor, each marked `@deprecated` with the replacement and "Removed in the next minor". Generated SDK moves get them from the codegen (`compile(..., { aliases: true })` in `packages/client/script/generate.ts`), not by hand. +- Experimental plugin hooks are named `experimental.*` (`experimental.ws.handshake`). + ## Testing - Avoid mocks as much as possible, you shouldn't be using globalThis.\* at all unless it's the only option. diff --git a/packages/app/src/home/projects/controller.tsx b/packages/app/src/home/projects/controller.tsx index 25cac9498bd..7d3743b00df 100644 --- a/packages/app/src/home/projects/controller.tsx +++ b/packages/app/src/home/projects/controller.tsx @@ -123,7 +123,7 @@ export function createHomeProjectsController(home: HomeController) { Schema.fromJsonString(Schema.Record(Schema.String, Schema.Json)), )(await file.text()) - const api = home.server.context(conn).sdk.api.session + const api = home.server.context(conn).sdk.api.experimental.session // SAFETY: the import endpoint validates the transcript, including exports written by earlier releases. const imported = await api.import({ diff --git a/packages/app/src/providers/connect/mcp.ts b/packages/app/src/providers/connect/mcp.ts index c578895ed30..686a07c2e88 100644 --- a/packages/app/src/providers/connect/mcp.ts +++ b/packages/app/src/providers/connect/mcp.ts @@ -13,7 +13,7 @@ export type McpControls = { change: (name: string, enabled: boolean) => void } -export function useMcpToggle(directory?: Accessor, onSuccess?: () => unknown) { +export function useMcpToggle(directory?: Accessor, onSuccess?: () => void) { const data = useData() const serverSDK = useServerSDK() const platform = usePlatform() @@ -27,19 +27,22 @@ export function useMcpToggle(directory?: Accessor, onSuccess return useMutation(() => ({ mutationFn: async (input: string | { name: string; enabled: boolean; directory?: string }) => { - const name = typeof input === "string" ? input : input.name - const ref = typeof input !== "string" && input.directory ? { directory: input.directory } : location() + // A bare name toggles the server; an object sets an explicit state. + // oxlint-disable-next-line anti-slop/no-runtime-typeof -- discriminates this function's own input union + const request: { name: string; enabled?: boolean; directory?: string } = typeof input === "string" ? { name: input } : input + const name = request.name + const ref = request.directory ? { directory: request.directory } : location() const server = (await serverSDK.api.mcp.list({ location: ref })).data.find((item) => item.name === name) - if (!server || (server.status.status === "pending" && typeof input === "string")) return - const enabled = typeof input === "string" ? server.status.status !== "connected" : input.enabled + if (!server || (server.status.status === "pending" && request.enabled === undefined)) return + const enabled = request.enabled ?? server.status.status !== "connected" if (!enabled) { - await serverSDK.api.mcp.disconnect({ server: name, location: ref }) + await serverSDK.api.experimental.mcp.disconnect({ server: name, location: ref }) } if (enabled && server.status.status !== "needs_auth") { - await serverSDK.api.mcp.connect({ server: name, location: ref }) + await serverSDK.api.experimental.mcp.connect({ server: name, location: ref }) } data.location.mcp.server.invalidate(ref) diff --git a/packages/app/src/runtime/server/sync.tsx b/packages/app/src/runtime/server/sync.tsx index 5952f0c3123..0bd6b329968 100644 --- a/packages/app/src/runtime/server/sync.tsx +++ b/packages/app/src/runtime/server/sync.tsx @@ -244,6 +244,7 @@ function createServerSyncContextInner(serverSDK: ServerSDK, data: Data) { if (update.time.archived) return rest const previous = projects.find((project) => project.id === update.id) + // The wire payload carries no worktrees; keep the inventory this project already loaded. const next = withWorktreeInventory( previous ? updateProjectInfo(previous, update) : normalizeProjectInfo(update), @@ -314,7 +315,7 @@ function createServerSyncContextInner(serverSDK: ServerSDK, data: Data) { const updateConfigMutation = useMutation(() => ({ mutationFn: async (config: Config) => { // TODO: Restore config updates when the V2 client exposes a config API. - // await serverSDK.api.config.update({ config }) + // await serverSDK.api.experimental.config.update({ config }) throw new Error(`Config updates are unavailable: ${Object.keys(config).length} fields were not saved`) }, onSuccess: () => { @@ -343,10 +344,10 @@ function createServerSyncContextInner(serverSDK: ServerSDK, data: Data) { await toggleMcp({ status, connect: async () => { - await serverSDK.api.mcp.connect({ server: name, location: { directory: key } }) + await serverSDK.api.experimental.mcp.connect({ server: name, location: { directory: key } }) }, disconnect: async () => { - await serverSDK.api.mcp.disconnect({ server: name, location: { directory: key } }) + await serverSDK.api.experimental.mcp.disconnect({ server: name, location: { directory: key } }) }, authenticate: async () => { const server = (await serverSDK.api.mcp.list({ location: { directory: key } })).data.find( diff --git a/packages/app/src/session/revert.ts b/packages/app/src/session/revert.ts index a4b3fbc1fea..d0d48966c39 100644 --- a/packages/app/src/session/revert.ts +++ b/packages/app/src/session/revert.ts @@ -88,7 +88,7 @@ export function createSessionRevert(input: { // Like the TUI, stop at the first failure instead of waiting on work that was never interrupted. if (!(await request(() => server.api.session.interrupt({ sessionID })))) return - if (!(await request(() => server.api.session.wait({ sessionID })))) return + if (!(await request(() => server.api.experimental.session.wait({ sessionID })))) return // Read before staging: the staged event can land before the request resolves. const prior = input.session.data.revertMessageID() diff --git a/packages/app/src/settings/general/controllers.ts b/packages/app/src/settings/general/controllers.ts index 2c40beb2d94..ccc0cd0960f 100644 --- a/packages/app/src/settings/general/controllers.ts +++ b/packages/app/src/settings/general/controllers.ts @@ -59,7 +59,7 @@ export function createServerShellController(server: Accessor { actions.mutate(previous) showToast({ diff --git a/packages/app/src/voice/tools.ts b/packages/app/src/voice/tools.ts index a2425e4c27c..1b9e2de2afd 100644 --- a/packages/app/src/voice/tools.ts +++ b/packages/app/src/voice/tools.ts @@ -120,6 +120,7 @@ export class VoiceTools { const seen = new Set() const tabs = new Set(this.screen.tabs()) + // Best match first; among equal matches, top-level sessions with an open tab, then the most recent. const rank = (session: SessionInfo) => (search.score(session) ?? 0) * 4 + (session.parentID ? 0 : 2) + (tabs.has(session.id) ? 1 : 0) @@ -300,7 +301,7 @@ export class VoiceTools { if (call.name === "read_session" || call.name === "wait_for_session") { if (call.name === "wait_for_session") { - await api.session.wait({ sessionID }, { signal: AbortSignal.any([signal, AbortSignal.timeout(90_000)]) }) + await api.experimental.session.wait({ sessionID }, { signal: AbortSignal.any([signal, AbortSignal.timeout(90_000)]) }) } const [session, messages] = await Promise.all([ diff --git a/packages/app/src/voice/transport.ts b/packages/app/src/voice/transport.ts index 7ad543c5fc4..673966e1c4a 100644 --- a/packages/app/src/voice/transport.ts +++ b/packages/app/src/voice/transport.ts @@ -8,6 +8,13 @@ export class VoiceFailure extends Error { } } +/** A client event sent over the Live data channel; the transport adds `event_id`. */ +export type VoiceClientEvent = + | { type: "session.input_audio.mute" | "session.input_audio.unmute" | "response.create" } + | { type: "session.update"; session: { delegation: { type: "responses"; responses: { instructions: string } } } } + | { type: "response.item.create"; item: { type: "function_call_output"; call_id: string; output: string } } + | { type: "session.commentary.append"; delegation_id: null; content: string } + export class VoiceTransport { readonly abort = new AbortController() private peer = new RTCPeerConnection({ iceServers: [], bundlePolicy: "max-bundle", rtcpMuxPolicy: "require" }) @@ -78,7 +85,7 @@ export class VoiceTransport { async join(viewing: { id: string; title?: string }, tail: string) { const signal = AbortSignal.any([this.abort.signal, AbortSignal.timeout(35_000)]) await this.context.resume() - const offered = await this.inputOptions.api.voice.models({ signal }) + const offered = await this.inputOptions.api.experimental.voice.models({ signal }) if ( !offered.models.some( @@ -106,7 +113,7 @@ export class VoiceTransport { }) signal.throwIfAborted() - const response = await this.inputOptions.api.voice.session( + const response = await this.inputOptions.api.experimental.voice.session( { model: "gpt-live-1", session: { @@ -153,7 +160,7 @@ export class VoiceTransport { this.timer = setInterval(() => this.inputOptions.levels(this.level(this.input), this.level(this.output)), 100) } - send(event: object) { + send(event: VoiceClientEvent) { if (this.ended || this.channel.readyState !== "open") throw new VoiceFailure("dropped") this.channel.send(JSON.stringify({ event_id: crypto.randomUUID(), ...event })) } diff --git a/packages/app/src/workspaces/files/model.tsx b/packages/app/src/workspaces/files/model.tsx index 9d5630cdd1e..9a6042b670b 100644 --- a/packages/app/src/workspaces/files/model.tsx +++ b/packages/app/src/workspaces/files/model.tsx @@ -298,14 +298,14 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({ const file = path.normalize(input) if (!file || path.absolute(file)) return - void serverSDK.api.file.watch({ path: file, location: { directory: scope() } }).catch(() => {}) + void serverSDK.api.experimental.file.watch({ path: file, location: { directory: scope() } }).catch(() => {}) } const unwatch = (input: string) => { const file = path.normalize(input) if (!file || path.absolute(file)) return - void serverSDK.api.file.unwatch({ path: file, location: { directory: scope() } }).catch(() => {}) + void serverSDK.api.experimental.file.unwatch({ path: file, location: { directory: scope() } }).catch(() => {}) } createEffect(() => { diff --git a/packages/cli/src/acp/sessions.ts b/packages/cli/src/acp/sessions.ts index 1384893e597..5a39eac2aaa 100644 --- a/packages/cli/src/acp/sessions.ts +++ b/packages/cli/src/acp/sessions.ts @@ -101,7 +101,7 @@ export const make = Effect.fnUntraced(function* (input: { const config = mcpConfig(server) if (isDeepStrictEqual(registered.get(server.name), config)) return Effect.void registered.set(server.name, config) - return input.client.mcp.add({ server: server.name, location: { directory: attached.cwd }, config }).pipe( + return input.client.experimental.mcp.add({ server: server.name, location: { directory: attached.cwd }, config }).pipe( Effect.catch(ACPClient.classify), Effect.onError(() => Effect.sync(() => registered.delete(server.name))), Effect.uninterruptible, diff --git a/packages/cli/src/commands/handlers/auth/login.ts b/packages/cli/src/commands/handlers/auth/login.ts index 7bd17698e9a..82b31b58168 100644 --- a/packages/cli/src/commands/handlers/auth/login.ts +++ b/packages/cli/src/commands/handlers/auth/login.ts @@ -61,7 +61,7 @@ const findIntegration = Effect.fn("cli.auth.login.integration")(function* (clien if (protocol === "http:" || protocol === "https:") { const progress = spinner() progress.start("Discovering authentication provider...") - yield* request((signal) => client.integration.wellknown.add({ url: target, location }, { signal })).pipe( + yield* request((signal) => client.experimental.integration.wellknown.add({ url: target, location }, { signal })).pipe( Effect.tap(() => Effect.sync(() => progress.stop("Authentication provider discovered"))), Effect.tapCause(() => Effect.sync(() => progress.stop("Discovery failed", 1))), ) diff --git a/packages/cli/src/commands/handlers/session/export.ts b/packages/cli/src/commands/handlers/session/export.ts index 52a155b7bf6..f52ef725b92 100644 --- a/packages/cli/src/commands/handlers/session/export.ts +++ b/packages/cli/src/commands/handlers/session/export.ts @@ -68,7 +68,7 @@ export default Runtime.handler( }) if (!sessionID) return const data = yield* Effect.tryPromise({ - try: () => client.session.export({ sessionID, sanitize: input.sanitize }), + try: () => client.experimental.session.export({ sessionID, sanitize: input.sanitize }), catch: (cause) => cause, }) process.stdout.write(JSON.stringify(data, null, 2) + EOL) diff --git a/packages/cli/src/commands/handlers/stats.ts b/packages/cli/src/commands/handlers/stats.ts index 1fd251f1166..b6507ab4946 100644 --- a/packages/cli/src/commands/handlers/stats.ts +++ b/packages/cli/src/commands/handlers/stats.ts @@ -29,7 +29,7 @@ const handler = Effect.fn("cli.stats")(function* (input: Runtime.Input - client.session.stats( + client.experimental.session.stats( { from: range.from, to: range.to, diff --git a/packages/cli/src/run/noninteractive.ts b/packages/cli/src/run/noninteractive.ts index af42a1ac078..22900f3e116 100644 --- a/packages/cli/src/run/noninteractive.ts +++ b/packages/cli/src/run/noninteractive.ts @@ -758,7 +758,7 @@ export async function runNonInteractivePrompt(input: Input) { return } - const waiting = input.client.session.wait({ sessionID: input.sessionID }) + const waiting = input.client.experimental.session.wait({ sessionID: input.sessionID }) await Promise.race([waiting, completed.then(() => waiting)]) finalizing = true const projected = await reconcile() diff --git a/packages/cli/test/fixture/mini-wait.ts b/packages/cli/test/fixture/mini-wait.ts index 5787110bfbe..acd94111972 100644 --- a/packages/cli/test/fixture/mini-wait.ts +++ b/packages/cli/test/fixture/mini-wait.ts @@ -14,11 +14,11 @@ const timeout = (error: unknown) => error.cause.name === "TimeoutError" await Promise.all([ - connection.sdk.session.wait({ sessionID: "ses_initial" }), - replacement.session.wait({ sessionID: "ses_reconnected" }), - assert.rejects(OpenCode.make({ baseUrl: endpoint.url }).session.wait({ sessionID: "ses_control" }), timeout), + connection.sdk.experimental.session.wait({ sessionID: "ses_initial" }), + replacement.experimental.session.wait({ sessionID: "ses_reconnected" }), + assert.rejects(OpenCode.make({ baseUrl: endpoint.url }).experimental.session.wait({ sessionID: "ses_control" }), timeout), assert.rejects( - connection.sdk.session.wait({ sessionID: "ses_cancelled" }, { signal: AbortSignal.timeout(100) }), + connection.sdk.experimental.session.wait({ sessionID: "ses_cancelled" }, { signal: AbortSignal.timeout(100) }), timeout, ), ]) diff --git a/packages/cli/test/run/noninteractive.test.ts b/packages/cli/test/run/noninteractive.test.ts index 10a679dea7b..27779c82a68 100644 --- a/packages/cli/test/run/noninteractive.test.ts +++ b/packages/cli/test/run/noninteractive.test.ts @@ -253,7 +253,7 @@ async function run(input: { ) spyOn(sdk.session.form, "cancel").mockImplementation((request) => (input.cancel?.(request) ?? ok(undefined)) as never) let promptID = "msg_prompt" - spyOn(sdk.session, "wait").mockImplementation(() => input.wait?.() ?? wait.promise) + spyOn(sdk.experimental.session, "wait").mockImplementation(() => input.wait?.() ?? wait.promise) spyOn(sdk.message, "list").mockImplementation(() => ok({ data: input.messages?.(promptID) ?? [{ id: promptID, type: "user", text: "hello", time: { created: 1 } }], @@ -479,7 +479,7 @@ describe("runNonInteractivePrompt", () => { ]) expect(output.stderr).toBe("") const sdk = await run({ compatibility: "v1", turn: (messageID) => [prompted(messageID), settled()] }) - expect(sdk.session.wait).not.toHaveBeenCalled() + expect(sdk.experimental.session.wait).not.toHaveBeenCalled() expect(sdk.message.list).not.toHaveBeenCalled() }) diff --git a/packages/client/script/generate.ts b/packages/client/script/generate.ts index 1b3395cc7e2..e70cd5f79d7 100644 --- a/packages/client/script/generate.ts +++ b/packages/client/script/generate.ts @@ -1,6 +1,12 @@ import { NodeFileSystem } from "@effect/platform-node" import { compile, emitEffectImported, emitEffectShape, emitPromise, write } from "@opencode/httpapi-codegen" -import { ClientApi, effectOmitEndpoints, groupNames, promiseOmitEndpoints } from "@opencode/protocol/client" +import { + ClientApi, + clientNamespace, + effectOmitEndpoints, + groupNames, + promiseOmitEndpoints, +} from "@opencode/protocol/client" import { Agent } from "@opencode/schema/agent" import { Command } from "@opencode/schema/command" import { Config } from "@opencode/schema/config" @@ -44,8 +50,18 @@ import { Workspace } from "@opencode/schema/workspace" import { Effect, Schema } from "effect" import { fileURLToPath } from "url" -const promiseContract = compile(ClientApi, { groupNames, omitEndpoints: promiseOmitEndpoints }) -const effectContract = compile(ClientApi, { groupNames, omitEndpoints: effectOmitEndpoints }) +const promiseContract = compile(ClientApi, { + groupNames, + omitEndpoints: promiseOmitEndpoints, + namespace: clientNamespace, + aliases: true, +}) +const effectContract = compile(ClientApi, { + groupNames, + omitEndpoints: effectOmitEndpoints, + namespace: clientNamespace, + aliases: true, +}) const effectTypeReferences = [ ...namespaceTypes("Agent", "@opencode/schema/agent", Agent), ...namespaceTypes("Command", "@opencode/schema/command", Command), diff --git a/packages/client/src/contract.ts b/packages/client/src/contract.ts index aa033158041..b5326bfa00d 100644 --- a/packages/client/src/contract.ts +++ b/packages/client/src/contract.ts @@ -1 +1 @@ -export { ClientApi, effectOmitEndpoints, groupNames, promiseOmitEndpoints } from "@opencode/protocol/client" +export { ClientApi, clientNamespace, effectOmitEndpoints, groupNames, promiseOmitEndpoints } from "@opencode/protocol/client" diff --git a/packages/client/src/effect/api/api.ts b/packages/client/src/effect/api/api.ts index 3c80f44505d..6a6ac1c3f6c 100644 --- a/packages/client/src/effect/api/api.ts +++ b/packages/client/src/effect/api/api.ts @@ -7,16 +7,17 @@ import type { Session } from "@opencode/schema/session" import type { AbsolutePath } from "@opencode/schema/schema" import type { Project } from "@opencode/schema/project" import type { RelativePath } from "@opencode/schema/schema" -import type { Money } from "@opencode/schema/money" import type { Model } from "@opencode/schema/model" -import type { DateTime } from "effect" import type { Permission } from "@opencode/schema/permission" import type { SessionMessage } from "@opencode/schema/session-message" import type { SessionInbox } from "@opencode/schema/session-inbox" import type { PromptInput } from "@opencode/schema/prompt-input" import type { AgentAttachment } from "@opencode/schema/prompt" -import type { Skill } from "@opencode/schema/skill" import type { FileDiff } from "@opencode/schema/file-diff" +import type { Form } from "@opencode/schema/form" +import type { DateTime } from "effect" +import type { Money } from "@opencode/schema/money" +import type { Skill } from "@opencode/schema/skill" import type { InstructionEntry } from "@opencode/schema/instruction-entry" import type { Schema } from "effect" import type { Event } from "@opencode/schema/event" @@ -25,7 +26,6 @@ import type { Workspace } from "@opencode/schema/workspace" import type { Instruction } from "@opencode/schema/instruction" import type { Snapshot } from "@opencode/schema/snapshot" import type { Shell } from "@opencode/schema/shell" -import type { Form } from "@opencode/schema/form" import type { Generate } from "@opencode/schema/generate" import type { Provider } from "@opencode/schema/provider" import type { Integration } from "@opencode/schema/integration" @@ -147,71 +147,6 @@ export type SessionListOutput = { } export type SessionListOperation = (input?: SessionListInput) => Effect.Effect -export type SessionStatsInput = { - readonly from?: number | undefined - readonly to?: number | undefined - readonly project?: Project.ID | undefined - readonly timezone?: string | undefined - readonly tools?: "none" | "summary" | "detail" | undefined -} -export type SessionStatsOutput = { - readonly range: { readonly from: DateTime.Utc; readonly to: DateTime.Utc } - readonly sessions: number - readonly subagents: number - readonly prompts: number - readonly steps: number - readonly tokens: { - readonly input: number - readonly output: number - readonly reasoning: number - readonly cache: { readonly read: number; readonly write: number } - } - readonly cost: Money.USD - readonly tools: - | { readonly mode: "none" } - | { - readonly mode: "summary" - readonly totals: { - readonly calls: number - readonly succeeded: number - readonly failed: number - readonly unfinished: number - } - } - | { - readonly mode: "detail" - readonly totals: { - readonly calls: number - readonly succeeded: number - readonly failed: number - readonly unfinished: number - } - readonly usage: ReadonlyArray<{ - readonly name: string - readonly calls: number - readonly succeeded: number - readonly failed: number - readonly unfinished: number - readonly durationP50?: number | undefined - }> - } - readonly activeDays: number - readonly streak: number - readonly activity: ReadonlyArray<{ readonly date: string; readonly steps: number }> - readonly models: ReadonlyArray<{ - readonly model: Model.Ref - readonly steps: number - readonly tokens: { - readonly input: number - readonly output: number - readonly reasoning: number - readonly cache: { readonly read: number; readonly write: number } - } - readonly cost: Money.USD - }> -} -export type SessionStatsOperation = (input?: SessionStatsInput) => Effect.Effect - export type SessionCreateInput = { readonly id?: Session.ID | undefined readonly parentID?: Session.ID | undefined @@ -225,18 +160,6 @@ export type SessionCreateInput = { export type SessionCreateOutput = Session.Info export type SessionCreateOperation = (input?: SessionCreateInput) => Effect.Effect -export type SessionImportInput = { - readonly info: Session.Info - readonly messages: ReadonlyArray - readonly location?: Location.PublicRef | undefined -} -export type SessionImportOutput = Session.Info -export type SessionImportOperation = (input: SessionImportInput) => Effect.Effect - -export type SessionExportInput = { readonly sessionID: Session.ID; readonly sanitize?: boolean | undefined } -export type SessionExportOutput = { readonly info: Session.Info; readonly messages: ReadonlyArray } -export type SessionExportOperation = (input: SessionExportInput) => Effect.Effect - export type SessionActiveOutput = { readonly [x: Session.ID]: { readonly type: "running" } } export type SessionActiveOperation = () => Effect.Effect @@ -308,14 +231,6 @@ export type SessionCommandInput = { export type SessionCommandOutput = void export type SessionCommandOperation = (input: SessionCommandInput) => Effect.Effect -export type SessionSkillInput = { - readonly sessionID: Session.ID - readonly id: Skill.ID - readonly resume?: boolean | undefined -} -export type SessionSkillOutput = void -export type SessionSkillOperation = (input: SessionSkillInput) => Effect.Effect - export type SessionSyntheticInput = { readonly sessionID: Session.ID readonly id?: SessionMessage.ID | undefined @@ -346,10 +261,6 @@ export type SessionCompactInput = { export type SessionCompactOutput = SessionInbox.Compaction export type SessionCompactOperation = (input: SessionCompactInput) => Effect.Effect -export type SessionWaitInput = { readonly sessionID: Session.ID } -export type SessionWaitOutput = void -export type SessionWaitOperation = (input: SessionWaitInput) => Effect.Effect - export type SessionRevertStageInput = { readonly sessionID: Session.ID readonly messageID: SessionMessage.ID @@ -407,40 +318,294 @@ export type SessionInboxUpdateOperation = ( input: SessionInboxUpdateInput, ) => Effect.Effect -export type SessionInstructionsEntryListInput = { readonly sessionID: Session.ID } -export type SessionInstructionsEntryListOutput = ReadonlyArray -export type SessionInstructionsEntryListOperation = ( - input: SessionInstructionsEntryListInput, -) => Effect.Effect - -export type SessionInstructionsEntryPutInput = { - readonly sessionID: Session.ID - readonly key: InstructionEntry.Key - readonly value: Schema.Json -} -export type SessionInstructionsEntryPutOutput = void -export type SessionInstructionsEntryPutOperation = ( - input: SessionInstructionsEntryPutInput, -) => Effect.Effect - -export type SessionInstructionsEntryRemoveInput = { readonly sessionID: Session.ID; readonly key: InstructionEntry.Key } -export type SessionInstructionsEntryRemoveOutput = void -export type SessionInstructionsEntryRemoveOperation = ( - input: SessionInstructionsEntryRemoveInput, -) => Effect.Effect - export type SessionGenerateInput = { readonly sessionID: Session.ID; readonly prompt: string } export type SessionGenerateOutput = { readonly text: string } export type SessionGenerateOperation = ( input: SessionGenerateInput, ) => Effect.Effect -export type SessionLogInput = { +export type SessionInterruptInput = { readonly sessionID: Session.ID; readonly resume?: boolean | undefined } +export type SessionInterruptOutput = { readonly interrupted: boolean } +export type SessionInterruptOperation = ( + input: SessionInterruptInput, +) => Effect.Effect + +export type SessionBackgroundInput = { readonly sessionID: Session.ID } +export type SessionBackgroundOutput = void +export type SessionBackgroundOperation = ( + input: SessionBackgroundInput, +) => Effect.Effect + +export type SessionMessageGetInput = { readonly sessionID: Session.ID; readonly messageID: SessionMessage.ID } +export type SessionMessageGetOutput = SessionMessage.Info +export type SessionMessageGetOperation = ( + input: SessionMessageGetInput, +) => Effect.Effect + +export type SessionFormListInput = { readonly sessionID: string } +export type SessionFormListOutput = ReadonlyArray +export type SessionFormListOperation = ( + input: SessionFormListInput, +) => Effect.Effect + +export type SessionFormCreateInput = { + readonly sessionID: string + readonly id?: Form.ID | undefined + readonly title: string + readonly metadata?: Form.Metadata | undefined + readonly fields: Form.Fields +} +export type SessionFormCreateOutput = Form.Info +export type SessionFormCreateOperation = ( + input: SessionFormCreateInput, +) => Effect.Effect + +export type SessionFormGetInput = { readonly sessionID: string; readonly formID: Form.ID } +export type SessionFormGetOutput = Form.Detail +export type SessionFormGetOperation = (input: SessionFormGetInput) => Effect.Effect + +export type SessionFormReplyInput = { + readonly sessionID: string + readonly formID: Form.ID + readonly answer: Form.Answer +} +export type SessionFormReplyOutput = void +export type SessionFormReplyOperation = ( + input: SessionFormReplyInput, +) => Effect.Effect + +export type SessionFormCancelInput = { + readonly sessionID: string + readonly formID: Form.ID + readonly message?: string | undefined +} +export type SessionFormCancelOutput = void +export type SessionFormCancelOperation = ( + input: SessionFormCancelInput, +) => Effect.Effect + +export type SessionEnvironmentInput = { + readonly sessionID: Session.ID + readonly variables: { readonly [x: string]: string } +} +export type SessionEnvironmentOutput = void +export type SessionEnvironmentOperation = ( + input: SessionEnvironmentInput, +) => Effect.Effect + +export type SessionViewInput = { readonly sessionID: Session.ID; readonly idle: DateTime.Utc } +export type SessionViewOutput = void +export type SessionViewOperation = (input: SessionViewInput) => Effect.Effect + +export interface SessionApi { + readonly list: SessionListOperation + readonly create: SessionCreateOperation + readonly active: SessionActiveOperation + readonly get: SessionGetOperation + readonly remove: SessionRemoveOperation + readonly fork: SessionForkOperation + readonly switchAgent: SessionSwitchAgentOperation + readonly switchModel: SessionSwitchModelOperation + readonly update: SessionUpdateOperation + readonly move: SessionMoveOperation + readonly prompt: SessionPromptOperation + readonly command: SessionCommandOperation + readonly synthetic: SessionSyntheticOperation + readonly shell: SessionShellOperation + readonly compact: SessionCompactOperation + readonly revert: { + readonly stage: SessionRevertStageOperation + readonly clear: SessionRevertClearOperation + readonly commit: SessionRevertCommitOperation + } + readonly context: SessionContextOperation + readonly diff: SessionDiffOperation + readonly inbox: { + readonly list: SessionInboxListOperation + readonly cancel: SessionInboxCancelOperation + readonly update: SessionInboxUpdateOperation + } + readonly generate: SessionGenerateOperation + readonly interrupt: SessionInterruptOperation + readonly background: SessionBackgroundOperation + readonly message: { readonly get: SessionMessageGetOperation } + readonly form: { + readonly list: SessionFormListOperation + readonly create: SessionFormCreateOperation + readonly get: SessionFormGetOperation + readonly reply: SessionFormReplyOperation + readonly cancel: SessionFormCancelOperation + } + readonly environment: SessionEnvironmentOperation + readonly view: SessionViewOperation + + /** @deprecated Use `client.experimental.session.stats`. Removed in the next minor. */ + readonly stats: ExperimentalSessionStatsOperation + + /** @deprecated Use `client.experimental.session.import`. Removed in the next minor. */ + readonly import: ExperimentalSessionImportOperation + + /** @deprecated Use `client.experimental.session.export`. Removed in the next minor. */ + readonly export: ExperimentalSessionExportOperation + + /** @deprecated Use `client.experimental.session.skill`. Removed in the next minor. */ + readonly skill: ExperimentalSessionSkillOperation + + /** @deprecated Use `client.experimental.session.wait`. Removed in the next minor. */ + readonly wait: ExperimentalSessionWaitOperation + + /** @deprecated Use `client.experimental.session.instructions`. Removed in the next minor. */ + readonly instructions: { + /** @deprecated Use `client.experimental.session.instructions.entry`. Removed in the next minor. */ + readonly entry: { + /** @deprecated Use `client.experimental.session.instructions.entry.list`. Removed in the next minor. */ + readonly list: ExperimentalSessionInstructionsEntryListOperation + + /** @deprecated Use `client.experimental.session.instructions.entry.put`. Removed in the next minor. */ + readonly put: ExperimentalSessionInstructionsEntryPutOperation + + /** @deprecated Use `client.experimental.session.instructions.entry.remove`. Removed in the next minor. */ + readonly remove: ExperimentalSessionInstructionsEntryRemoveOperation + } + } + + /** @deprecated Use `client.experimental.session.log`. Removed in the next minor. */ + readonly log: ExperimentalSessionLogOperation +} + +export type ExperimentalSessionStatsInput = { + readonly from?: number | undefined + readonly to?: number | undefined + readonly project?: Project.ID | undefined + readonly timezone?: string | undefined + readonly tools?: "none" | "summary" | "detail" | undefined +} +export type ExperimentalSessionStatsOutput = { + readonly range: { readonly from: DateTime.Utc; readonly to: DateTime.Utc } + readonly sessions: number + readonly subagents: number + readonly prompts: number + readonly steps: number + readonly tokens: { + readonly input: number + readonly output: number + readonly reasoning: number + readonly cache: { readonly read: number; readonly write: number } + } + readonly cost: Money.USD + readonly tools: + | { readonly mode: "none" } + | { + readonly mode: "summary" + readonly totals: { + readonly calls: number + readonly succeeded: number + readonly failed: number + readonly unfinished: number + } + } + | { + readonly mode: "detail" + readonly totals: { + readonly calls: number + readonly succeeded: number + readonly failed: number + readonly unfinished: number + } + readonly usage: ReadonlyArray<{ + readonly name: string + readonly calls: number + readonly succeeded: number + readonly failed: number + readonly unfinished: number + readonly durationP50?: number | undefined + }> + } + readonly activeDays: number + readonly streak: number + readonly activity: ReadonlyArray<{ readonly date: string; readonly steps: number }> + readonly models: ReadonlyArray<{ + readonly model: Model.Ref + readonly steps: number + readonly tokens: { + readonly input: number + readonly output: number + readonly reasoning: number + readonly cache: { readonly read: number; readonly write: number } + } + readonly cost: Money.USD + }> +} +export type ExperimentalSessionStatsOperation = ( + input?: ExperimentalSessionStatsInput, +) => Effect.Effect + +export type ExperimentalSessionImportInput = { + readonly info: Session.Info + readonly messages: ReadonlyArray + readonly location?: Location.PublicRef | undefined +} +export type ExperimentalSessionImportOutput = Session.Info +export type ExperimentalSessionImportOperation = ( + input: ExperimentalSessionImportInput, +) => Effect.Effect + +export type ExperimentalSessionExportInput = { readonly sessionID: Session.ID; readonly sanitize?: boolean | undefined } +export type ExperimentalSessionExportOutput = { + readonly info: Session.Info + readonly messages: ReadonlyArray +} +export type ExperimentalSessionExportOperation = ( + input: ExperimentalSessionExportInput, +) => Effect.Effect + +export type ExperimentalSessionSkillInput = { + readonly sessionID: Session.ID + readonly id: Skill.ID + readonly resume?: boolean | undefined +} +export type ExperimentalSessionSkillOutput = void +export type ExperimentalSessionSkillOperation = ( + input: ExperimentalSessionSkillInput, +) => Effect.Effect + +export type ExperimentalSessionWaitInput = { readonly sessionID: Session.ID } +export type ExperimentalSessionWaitOutput = void +export type ExperimentalSessionWaitOperation = ( + input: ExperimentalSessionWaitInput, +) => Effect.Effect + +export type ExperimentalSessionInstructionsEntryListInput = { readonly sessionID: Session.ID } +export type ExperimentalSessionInstructionsEntryListOutput = ReadonlyArray +export type ExperimentalSessionInstructionsEntryListOperation = ( + input: ExperimentalSessionInstructionsEntryListInput, +) => Effect.Effect + +export type ExperimentalSessionInstructionsEntryPutInput = { + readonly sessionID: Session.ID + readonly key: InstructionEntry.Key + readonly value: Schema.Json +} +export type ExperimentalSessionInstructionsEntryPutOutput = void +export type ExperimentalSessionInstructionsEntryPutOperation = ( + input: ExperimentalSessionInstructionsEntryPutInput, +) => Effect.Effect + +export type ExperimentalSessionInstructionsEntryRemoveInput = { + readonly sessionID: Session.ID + readonly key: InstructionEntry.Key +} +export type ExperimentalSessionInstructionsEntryRemoveOutput = void +export type ExperimentalSessionInstructionsEntryRemoveOperation = ( + input: ExperimentalSessionInstructionsEntryRemoveInput, +) => Effect.Effect + +export type ExperimentalSessionLogInput = { readonly sessionID: Session.ID readonly after?: Event.Seq | undefined readonly follow?: boolean | undefined } -export type SessionLogOutput = +export type ExperimentalSessionLogOutput = | ( | { readonly id: Event.ID @@ -1248,135 +1413,24 @@ export type SessionLogOutput = } ) | EventLog.Synced -export type SessionLogOperation = (input: SessionLogInput) => Stream.Stream +export type ExperimentalSessionLogOperation = ( + input: ExperimentalSessionLogInput, +) => Stream.Stream -export type SessionInterruptInput = { readonly sessionID: Session.ID; readonly resume?: boolean | undefined } -export type SessionInterruptOutput = { readonly interrupted: boolean } -export type SessionInterruptOperation = ( - input: SessionInterruptInput, -) => Effect.Effect - -export type SessionBackgroundInput = { readonly sessionID: Session.ID } -export type SessionBackgroundOutput = void -export type SessionBackgroundOperation = ( - input: SessionBackgroundInput, -) => Effect.Effect - -export type SessionMessageGetInput = { readonly sessionID: Session.ID; readonly messageID: SessionMessage.ID } -export type SessionMessageGetOutput = SessionMessage.Info -export type SessionMessageGetOperation = ( - input: SessionMessageGetInput, -) => Effect.Effect - -export type SessionFormListInput = { readonly sessionID: string } -export type SessionFormListOutput = ReadonlyArray -export type SessionFormListOperation = ( - input: SessionFormListInput, -) => Effect.Effect - -export type SessionFormCreateInput = { - readonly sessionID: string - readonly id?: Form.ID | undefined - readonly title: string - readonly metadata?: Form.Metadata | undefined - readonly fields: Form.Fields -} -export type SessionFormCreateOutput = Form.Info -export type SessionFormCreateOperation = ( - input: SessionFormCreateInput, -) => Effect.Effect - -export type SessionFormGetInput = { readonly sessionID: string; readonly formID: Form.ID } -export type SessionFormGetOutput = Form.Detail -export type SessionFormGetOperation = (input: SessionFormGetInput) => Effect.Effect - -export type SessionFormReplyInput = { - readonly sessionID: string - readonly formID: Form.ID - readonly answer: Form.Answer -} -export type SessionFormReplyOutput = void -export type SessionFormReplyOperation = ( - input: SessionFormReplyInput, -) => Effect.Effect - -export type SessionFormCancelInput = { - readonly sessionID: string - readonly formID: Form.ID - readonly message?: string | undefined -} -export type SessionFormCancelOutput = void -export type SessionFormCancelOperation = ( - input: SessionFormCancelInput, -) => Effect.Effect - -export type SessionEnvironmentInput = { - readonly sessionID: Session.ID - readonly variables: { readonly [x: string]: string } -} -export type SessionEnvironmentOutput = void -export type SessionEnvironmentOperation = ( - input: SessionEnvironmentInput, -) => Effect.Effect - -export type SessionViewInput = { readonly sessionID: Session.ID; readonly idle: DateTime.Utc } -export type SessionViewOutput = void -export type SessionViewOperation = (input: SessionViewInput) => Effect.Effect - -export interface SessionApi { - readonly list: SessionListOperation - readonly stats: SessionStatsOperation - readonly create: SessionCreateOperation - readonly import: SessionImportOperation - readonly export: SessionExportOperation - readonly active: SessionActiveOperation - readonly get: SessionGetOperation - readonly remove: SessionRemoveOperation - readonly fork: SessionForkOperation - readonly switchAgent: SessionSwitchAgentOperation - readonly switchModel: SessionSwitchModelOperation - readonly update: SessionUpdateOperation - readonly move: SessionMoveOperation - readonly prompt: SessionPromptOperation - readonly command: SessionCommandOperation - readonly skill: SessionSkillOperation - readonly synthetic: SessionSyntheticOperation - readonly shell: SessionShellOperation - readonly compact: SessionCompactOperation - readonly wait: SessionWaitOperation - readonly revert: { - readonly stage: SessionRevertStageOperation - readonly clear: SessionRevertClearOperation - readonly commit: SessionRevertCommitOperation - } - readonly context: SessionContextOperation - readonly diff: SessionDiffOperation - readonly inbox: { - readonly list: SessionInboxListOperation - readonly cancel: SessionInboxCancelOperation - readonly update: SessionInboxUpdateOperation - } +export interface ExperimentalSessionApi { + readonly stats: ExperimentalSessionStatsOperation + readonly import: ExperimentalSessionImportOperation + readonly export: ExperimentalSessionExportOperation + readonly skill: ExperimentalSessionSkillOperation + readonly wait: ExperimentalSessionWaitOperation readonly instructions: { readonly entry: { - readonly list: SessionInstructionsEntryListOperation - readonly put: SessionInstructionsEntryPutOperation - readonly remove: SessionInstructionsEntryRemoveOperation + readonly list: ExperimentalSessionInstructionsEntryListOperation + readonly put: ExperimentalSessionInstructionsEntryPutOperation + readonly remove: ExperimentalSessionInstructionsEntryRemoveOperation } } - readonly generate: SessionGenerateOperation - readonly log: SessionLogOperation - readonly interrupt: SessionInterruptOperation - readonly background: SessionBackgroundOperation - readonly message: { readonly get: SessionMessageGetOperation } - readonly form: { - readonly list: SessionFormListOperation - readonly create: SessionFormCreateOperation - readonly get: SessionFormGetOperation - readonly reply: SessionFormReplyOperation - readonly cancel: SessionFormCancelOperation - } - readonly environment: SessionEnvironmentOperation - readonly view: SessionViewOperation + readonly log: ExperimentalSessionLogOperation } export type MessageListInput = { @@ -1424,11 +1478,13 @@ export interface ModelApi { readonly default: ModelDefaultOperation } -export type GenerateTextInput = { readonly prompt: string; readonly model?: Model.Ref | undefined } -export type GenerateTextOutput = { readonly text: string } -export type GenerateTextOperation = (input: GenerateTextInput) => Effect.Effect +export type ExperimentalGenerateTextInput = { readonly prompt: string; readonly model?: Model.Ref | undefined } +export type ExperimentalGenerateTextOutput = { readonly text: string } +export type ExperimentalGenerateTextOperation = ( + input: ExperimentalGenerateTextInput, +) => Effect.Effect -export type GenerateImageInput = { +export type ExperimentalGenerateImageInput = { readonly model: Model.Ref readonly prompt: string readonly images?: ReadonlyArray | undefined @@ -1436,26 +1492,28 @@ export type GenerateImageInput = { readonly aspect?: Generate.ImageAspect | undefined readonly resolution?: Generate.ImageResolution | undefined } -export type GenerateImageOutput = Generate.ImageResult -export type GenerateImageOperation = (input: GenerateImageInput) => Effect.Effect +export type ExperimentalGenerateImageOutput = Generate.ImageResult +export type ExperimentalGenerateImageOperation = ( + input: ExperimentalGenerateImageInput, +) => Effect.Effect -export type GenerateDecisionsInput = { +export type ExperimentalGenerateDecisionsInput = { readonly model: Model.Ref readonly input: ReadonlyArray readonly questions: ReadonlyArray } -export type GenerateDecisionsOutput = Generate.DecisionResult -export type GenerateDecisionsOperation = ( - input: GenerateDecisionsInput, -) => Effect.Effect +export type ExperimentalGenerateDecisionsOutput = Generate.DecisionResult +export type ExperimentalGenerateDecisionsOperation = ( + input: ExperimentalGenerateDecisionsInput, +) => Effect.Effect -export interface GenerateApi { - readonly text: GenerateTextOperation - readonly image: GenerateImageOperation - readonly decisions: GenerateDecisionsOperation +export interface ExperimentalGenerateApi { + readonly text: ExperimentalGenerateTextOperation + readonly image: ExperimentalGenerateImageOperation + readonly decisions: ExperimentalGenerateDecisionsOperation } -export type VoiceModelsOutput = { +export type ExperimentalVoiceModelsOutput = { readonly models: ReadonlyArray<{ readonly model: string readonly provider: string @@ -1464,25 +1522,27 @@ export type VoiceModelsOutput = { }> readonly default?: string | undefined } -export type VoiceModelsOperation = () => Effect.Effect +export type ExperimentalVoiceModelsOperation = () => Effect.Effect -export type VoiceSessionInput = { +export type ExperimentalVoiceSessionInput = { readonly model: string readonly session?: { readonly [x: string]: unknown } | undefined readonly transport: | { readonly type: "webrtc"; readonly sdp: string; readonly dcid?: number | undefined } | { readonly type: "websocket" } } -export type VoiceSessionOutput = { +export type ExperimentalVoiceSessionOutput = { readonly transport: | { readonly type: "webrtc"; readonly sdp: string } | { readonly type: "websocket"; readonly url: string; readonly token: string; readonly expiresAt: number } } -export type VoiceSessionOperation = (input: VoiceSessionInput) => Effect.Effect +export type ExperimentalVoiceSessionOperation = ( + input: ExperimentalVoiceSessionInput, +) => Effect.Effect -export interface VoiceApi { - readonly models: VoiceModelsOperation - readonly session: VoiceSessionOperation +export interface ExperimentalVoiceApi { + readonly models: ExperimentalVoiceModelsOperation + readonly session: ExperimentalVoiceSessionOperation } export type ProviderListInput = { readonly location?: { readonly directory?: string | undefined } | undefined } @@ -1517,15 +1577,6 @@ export type IntegrationGetInput = { export type IntegrationGetOutput = { readonly location: Location.PublicRef; readonly data: Integration.Info } export type IntegrationGetOperation = (input: IntegrationGetInput) => Effect.Effect -export type IntegrationWellknownAddInput = { - readonly location?: { readonly directory?: string | undefined } | undefined - readonly url: string -} -export type IntegrationWellknownAddOutput = void -export type IntegrationWellknownAddOperation = ( - input: IntegrationWellknownAddInput, -) => Effect.Effect - export type IntegrationConnectKeyInput = { readonly integrationID: Integration.ID readonly location?: { readonly directory?: string | undefined } | undefined @@ -1639,7 +1690,6 @@ export type IntegrationCommandCancelOperation = ( export interface IntegrationApi { readonly list: IntegrationListOperation readonly get: IntegrationGetOperation - readonly wellknown: { readonly add: IntegrationWellknownAddOperation } readonly connect: { readonly key: IntegrationConnectKeyOperation readonly external: IntegrationConnectExternalOperation @@ -1655,63 +1705,116 @@ export interface IntegrationApi { readonly status: IntegrationCommandStatusOperation readonly cancel: IntegrationCommandCancelOperation } + + /** @deprecated Use `client.experimental.integration.wellknown`. Removed in the next minor. */ + readonly wellknown: { + /** @deprecated Use `client.experimental.integration.wellknown.add`. Removed in the next minor. */ + readonly add: ExperimentalIntegrationWellknownAddOperation + } +} + +export type ExperimentalIntegrationWellknownAddInput = { + readonly location?: { readonly directory?: string | undefined } | undefined + readonly url: string +} +export type ExperimentalIntegrationWellknownAddOutput = void +export type ExperimentalIntegrationWellknownAddOperation = ( + input: ExperimentalIntegrationWellknownAddInput, +) => Effect.Effect + +export interface ExperimentalIntegrationApi { + readonly wellknown: { readonly add: ExperimentalIntegrationWellknownAddOperation } } export type McpListInput = { readonly location?: { readonly directory?: string | undefined } | undefined } export type McpListOutput = { readonly location: Location.PublicRef; readonly data: ReadonlyArray } export type McpListOperation = (input?: McpListInput) => Effect.Effect -export type McpAddInput = { - readonly server: string - readonly location?: { readonly directory?: string | undefined } | undefined - readonly config: Mcp.LocalConfig | Mcp.RemoteConfig -} -export type McpAddOutput = void -export type McpAddOperation = (input: McpAddInput) => Effect.Effect - -export type McpRemoveInput = { - readonly server: string - readonly location?: { readonly directory?: string | undefined } | undefined -} -export type McpRemoveOutput = void -export type McpRemoveOperation = (input: McpRemoveInput) => Effect.Effect - -export type McpConnectInput = { - readonly server: string - readonly location?: { readonly directory?: string | undefined } | undefined -} -export type McpConnectOutput = void -export type McpConnectOperation = (input: McpConnectInput) => Effect.Effect - -export type McpDisconnectInput = { - readonly server: string - readonly location?: { readonly directory?: string | undefined } | undefined -} -export type McpDisconnectOutput = void -export type McpDisconnectOperation = (input: McpDisconnectInput) => Effect.Effect - export type McpResourceCatalogInput = { readonly location?: { readonly directory?: string | undefined } | undefined } export type McpResourceCatalogOutput = { readonly location: Location.PublicRef; readonly data: Mcp.ResourceCatalog } export type McpResourceCatalogOperation = ( input?: McpResourceCatalogInput, ) => Effect.Effect -export type McpClientTokenInput = { +export interface McpApi { + readonly list: McpListOperation + readonly resource: { readonly catalog: McpResourceCatalogOperation } + + /** @deprecated Use `client.experimental.mcp.add`. Removed in the next minor. */ + readonly add: ExperimentalMcpAddOperation + + /** @deprecated Use `client.experimental.mcp.remove`. Removed in the next minor. */ + readonly remove: ExperimentalMcpRemoveOperation + + /** @deprecated Use `client.experimental.mcp.connect`. Removed in the next minor. */ + readonly connect: ExperimentalMcpConnectOperation + + /** @deprecated Use `client.experimental.mcp.disconnect`. Removed in the next minor. */ + readonly disconnect: ExperimentalMcpDisconnectOperation + + /** @deprecated Use `client.experimental.mcp.client`. Removed in the next minor. */ + readonly client: { + /** @deprecated Use `client.experimental.mcp.client.token`. Removed in the next minor. */ + readonly token: ExperimentalMcpClientTokenOperation + } +} + +export type ExperimentalMcpAddInput = { + readonly server: string + readonly location?: { readonly directory?: string | undefined } | undefined + readonly config: Mcp.LocalConfig | Mcp.RemoteConfig +} +export type ExperimentalMcpAddOutput = void +export type ExperimentalMcpAddOperation = ( + input: ExperimentalMcpAddInput, +) => Effect.Effect + +export type ExperimentalMcpRemoveInput = { + readonly server: string + readonly location?: { readonly directory?: string | undefined } | undefined +} +export type ExperimentalMcpRemoveOutput = void +export type ExperimentalMcpRemoveOperation = ( + input: ExperimentalMcpRemoveInput, +) => Effect.Effect + +export type ExperimentalMcpConnectInput = { + readonly server: string + readonly location?: { readonly directory?: string | undefined } | undefined +} +export type ExperimentalMcpConnectOutput = void +export type ExperimentalMcpConnectOperation = ( + input: ExperimentalMcpConnectInput, +) => Effect.Effect + +export type ExperimentalMcpDisconnectInput = { + readonly server: string + readonly location?: { readonly directory?: string | undefined } | undefined +} +export type ExperimentalMcpDisconnectOutput = void +export type ExperimentalMcpDisconnectOperation = ( + input: ExperimentalMcpDisconnectInput, +) => Effect.Effect + +export type ExperimentalMcpClientTokenInput = { readonly location?: { readonly directory?: string | undefined } | undefined readonly name: string readonly "x-opencode-ticket"?: string | undefined } -export type McpClientTokenOutput = { readonly location: Location.PublicRef; readonly data: PtyTicket.ConnectToken } -export type McpClientTokenOperation = (input: McpClientTokenInput) => Effect.Effect +export type ExperimentalMcpClientTokenOutput = { + readonly location: Location.PublicRef + readonly data: PtyTicket.ConnectToken +} +export type ExperimentalMcpClientTokenOperation = ( + input: ExperimentalMcpClientTokenInput, +) => Effect.Effect -export interface McpApi { - readonly list: McpListOperation - readonly add: McpAddOperation - readonly remove: McpRemoveOperation - readonly connect: McpConnectOperation - readonly disconnect: McpDisconnectOperation - readonly resource: { readonly catalog: McpResourceCatalogOperation } - readonly client: { readonly token: McpClientTokenOperation } +export interface ExperimentalMcpApi { + readonly add: ExperimentalMcpAddOperation + readonly remove: ExperimentalMcpRemoveOperation + readonly connect: ExperimentalMcpConnectOperation + readonly disconnect: ExperimentalMcpDisconnectOperation + readonly client: { readonly token: ExperimentalMcpClientTokenOperation } } export type CredentialListOutput = ReadonlyArray @@ -1876,25 +1979,38 @@ export type FileFindInput = { export type FileFindOutput = { readonly location: Location.PublicRef; readonly data: ReadonlyArray } export type FileFindOperation = (input: FileFindInput) => Effect.Effect -export type FileWatchInput = { - readonly location?: { readonly directory?: string | undefined } | undefined - readonly path: string -} -export type FileWatchOutput = void -export type FileWatchOperation = (input: FileWatchInput) => Effect.Effect - -export type FileUnwatchInput = { - readonly location?: { readonly directory?: string | undefined } | undefined - readonly path: string -} -export type FileUnwatchOutput = void -export type FileUnwatchOperation = (input: FileUnwatchInput) => Effect.Effect - export interface FileApi { readonly list: FileListOperation readonly find: FileFindOperation - readonly watch: FileWatchOperation - readonly unwatch: FileUnwatchOperation + + /** @deprecated Use `client.experimental.file.watch`. Removed in the next minor. */ + readonly watch: ExperimentalFileWatchOperation + + /** @deprecated Use `client.experimental.file.unwatch`. Removed in the next minor. */ + readonly unwatch: ExperimentalFileUnwatchOperation +} + +export type ExperimentalFileWatchInput = { + readonly location?: { readonly directory?: string | undefined } | undefined + readonly path: string +} +export type ExperimentalFileWatchOutput = void +export type ExperimentalFileWatchOperation = ( + input: ExperimentalFileWatchInput, +) => Effect.Effect + +export type ExperimentalFileUnwatchInput = { + readonly location?: { readonly directory?: string | undefined } | undefined + readonly path: string +} +export type ExperimentalFileUnwatchOutput = void +export type ExperimentalFileUnwatchOperation = ( + input: ExperimentalFileUnwatchInput, +) => Effect.Effect + +export interface ExperimentalFileApi { + readonly watch: ExperimentalFileWatchOperation + readonly unwatch: ExperimentalFileUnwatchOperation } export type CommandListInput = { readonly location?: { readonly directory?: string | undefined } | undefined } @@ -2442,7 +2558,7 @@ export interface DebugApi { readonly location: { readonly list: DebugLocationListOperation; readonly evict: DebugLocationEvictOperation } } -export type MigrationV1StatusOutput = +export type ExperimentalMigrationV1StatusOutput = | { readonly status: "required" | "completed" } | { readonly status: "running" @@ -2453,10 +2569,13 @@ export type MigrationV1StatusOutput = } } | { readonly status: "error"; readonly error: string } -export type MigrationV1StatusOperation = () => Effect.Effect +export type ExperimentalMigrationV1StatusOperation = () => Effect.Effect< + ExperimentalMigrationV1StatusOutput, + E +> -export interface MigrationApi { - readonly v1: { readonly status: MigrationV1StatusOperation } +export interface ExperimentalMigrationApi { + readonly v1: { readonly status: ExperimentalMigrationV1StatusOperation } } export type WebsearchProvidersInput = { readonly location?: { readonly directory?: string | undefined } | undefined } @@ -2481,12 +2600,19 @@ export interface WebsearchApi { readonly query: WebsearchQueryOperation } -export type UsageLimitsInput = { readonly location?: { readonly directory?: string | undefined } | undefined } -export type UsageLimitsOutput = { readonly location: Location.PublicRef; readonly data: UsageLimits.Info | null } -export type UsageLimitsOperation = (input?: UsageLimitsInput) => Effect.Effect +export type ExperimentalUsageLimitsInput = { + readonly location?: { readonly directory?: string | undefined } | undefined +} +export type ExperimentalUsageLimitsOutput = { + readonly location: Location.PublicRef + readonly data: UsageLimits.Info | null +} +export type ExperimentalUsageLimitsOperation = ( + input?: ExperimentalUsageLimitsInput, +) => Effect.Effect -export interface UsageApi { - readonly limits: UsageLimitsOperation +export interface ExperimentalUsageApi { + readonly limits: ExperimentalUsageLimitsOperation } export type ConfigGetInput = { readonly location?: { readonly directory?: string | undefined } | undefined } @@ -2500,26 +2626,274 @@ export type ConfigShellsOutput = ReadonlyArray<{ }> export type ConfigShellsOperation = () => Effect.Effect -export type ConfigUpdateInput = { readonly shell: string | null } -export type ConfigUpdateOutput = void -export type ConfigUpdateOperation = (input: ConfigUpdateInput) => Effect.Effect - export interface ConfigApi { readonly get: ConfigGetOperation readonly shells: ConfigShellsOperation - readonly update: ConfigUpdateOperation + + /** @deprecated Use `client.experimental.config.update`. Removed in the next minor. */ + readonly update: ExperimentalConfigUpdateOperation } +export type ExperimentalConfigUpdateInput = { readonly shell: string | null } +export type ExperimentalConfigUpdateOutput = void +export type ExperimentalConfigUpdateOperation = ( + input: ExperimentalConfigUpdateInput, +) => Effect.Effect + +export interface ExperimentalConfigApi { + readonly update: ExperimentalConfigUpdateOperation +} + +/** @deprecated Use `ExperimentalSessionStatsInput`. Removed in the next minor. */ +export type SessionStatsInput = ExperimentalSessionStatsInput + +/** @deprecated Use `ExperimentalSessionStatsOutput`. Removed in the next minor. */ +export type SessionStatsOutput = ExperimentalSessionStatsOutput + +/** @deprecated Use `ExperimentalSessionStatsOperation`. Removed in the next minor. */ +export type SessionStatsOperation = ExperimentalSessionStatsOperation + +/** @deprecated Use `ExperimentalSessionImportInput`. Removed in the next minor. */ +export type SessionImportInput = ExperimentalSessionImportInput + +/** @deprecated Use `ExperimentalSessionImportOutput`. Removed in the next minor. */ +export type SessionImportOutput = ExperimentalSessionImportOutput + +/** @deprecated Use `ExperimentalSessionImportOperation`. Removed in the next minor. */ +export type SessionImportOperation = ExperimentalSessionImportOperation + +/** @deprecated Use `ExperimentalSessionExportInput`. Removed in the next minor. */ +export type SessionExportInput = ExperimentalSessionExportInput + +/** @deprecated Use `ExperimentalSessionExportOutput`. Removed in the next minor. */ +export type SessionExportOutput = ExperimentalSessionExportOutput + +/** @deprecated Use `ExperimentalSessionExportOperation`. Removed in the next minor. */ +export type SessionExportOperation = ExperimentalSessionExportOperation + +/** @deprecated Use `ExperimentalSessionSkillInput`. Removed in the next minor. */ +export type SessionSkillInput = ExperimentalSessionSkillInput + +/** @deprecated Use `ExperimentalSessionSkillOutput`. Removed in the next minor. */ +export type SessionSkillOutput = ExperimentalSessionSkillOutput + +/** @deprecated Use `ExperimentalSessionSkillOperation`. Removed in the next minor. */ +export type SessionSkillOperation = ExperimentalSessionSkillOperation + +/** @deprecated Use `ExperimentalSessionWaitInput`. Removed in the next minor. */ +export type SessionWaitInput = ExperimentalSessionWaitInput + +/** @deprecated Use `ExperimentalSessionWaitOutput`. Removed in the next minor. */ +export type SessionWaitOutput = ExperimentalSessionWaitOutput + +/** @deprecated Use `ExperimentalSessionWaitOperation`. Removed in the next minor. */ +export type SessionWaitOperation = ExperimentalSessionWaitOperation + +/** @deprecated Use `ExperimentalSessionInstructionsEntryListInput`. Removed in the next minor. */ +export type SessionInstructionsEntryListInput = ExperimentalSessionInstructionsEntryListInput + +/** @deprecated Use `ExperimentalSessionInstructionsEntryListOutput`. Removed in the next minor. */ +export type SessionInstructionsEntryListOutput = ExperimentalSessionInstructionsEntryListOutput + +/** @deprecated Use `ExperimentalSessionInstructionsEntryListOperation`. Removed in the next minor. */ +export type SessionInstructionsEntryListOperation = ExperimentalSessionInstructionsEntryListOperation + +/** @deprecated Use `ExperimentalSessionInstructionsEntryPutInput`. Removed in the next minor. */ +export type SessionInstructionsEntryPutInput = ExperimentalSessionInstructionsEntryPutInput + +/** @deprecated Use `ExperimentalSessionInstructionsEntryPutOutput`. Removed in the next minor. */ +export type SessionInstructionsEntryPutOutput = ExperimentalSessionInstructionsEntryPutOutput + +/** @deprecated Use `ExperimentalSessionInstructionsEntryPutOperation`. Removed in the next minor. */ +export type SessionInstructionsEntryPutOperation = ExperimentalSessionInstructionsEntryPutOperation + +/** @deprecated Use `ExperimentalSessionInstructionsEntryRemoveInput`. Removed in the next minor. */ +export type SessionInstructionsEntryRemoveInput = ExperimentalSessionInstructionsEntryRemoveInput + +/** @deprecated Use `ExperimentalSessionInstructionsEntryRemoveOutput`. Removed in the next minor. */ +export type SessionInstructionsEntryRemoveOutput = ExperimentalSessionInstructionsEntryRemoveOutput + +/** @deprecated Use `ExperimentalSessionInstructionsEntryRemoveOperation`. Removed in the next minor. */ +export type SessionInstructionsEntryRemoveOperation = ExperimentalSessionInstructionsEntryRemoveOperation + +/** @deprecated Use `ExperimentalSessionLogInput`. Removed in the next minor. */ +export type SessionLogInput = ExperimentalSessionLogInput + +/** @deprecated Use `ExperimentalSessionLogOutput`. Removed in the next minor. */ +export type SessionLogOutput = ExperimentalSessionLogOutput + +/** @deprecated Use `ExperimentalSessionLogOperation`. Removed in the next minor. */ +export type SessionLogOperation = ExperimentalSessionLogOperation + +/** @deprecated Use `ExperimentalGenerateTextInput`. Removed in the next minor. */ +export type GenerateTextInput = ExperimentalGenerateTextInput + +/** @deprecated Use `ExperimentalGenerateTextOutput`. Removed in the next minor. */ +export type GenerateTextOutput = ExperimentalGenerateTextOutput + +/** @deprecated Use `ExperimentalGenerateTextOperation`. Removed in the next minor. */ +export type GenerateTextOperation = ExperimentalGenerateTextOperation + +/** @deprecated Use `ExperimentalGenerateImageInput`. Removed in the next minor. */ +export type GenerateImageInput = ExperimentalGenerateImageInput + +/** @deprecated Use `ExperimentalGenerateImageOutput`. Removed in the next minor. */ +export type GenerateImageOutput = ExperimentalGenerateImageOutput + +/** @deprecated Use `ExperimentalGenerateImageOperation`. Removed in the next minor. */ +export type GenerateImageOperation = ExperimentalGenerateImageOperation + +/** @deprecated Use `ExperimentalGenerateDecisionsInput`. Removed in the next minor. */ +export type GenerateDecisionsInput = ExperimentalGenerateDecisionsInput + +/** @deprecated Use `ExperimentalGenerateDecisionsOutput`. Removed in the next minor. */ +export type GenerateDecisionsOutput = ExperimentalGenerateDecisionsOutput + +/** @deprecated Use `ExperimentalGenerateDecisionsOperation`. Removed in the next minor. */ +export type GenerateDecisionsOperation = ExperimentalGenerateDecisionsOperation + +/** @deprecated Use `ExperimentalVoiceModelsOutput`. Removed in the next minor. */ +export type VoiceModelsOutput = ExperimentalVoiceModelsOutput + +/** @deprecated Use `ExperimentalVoiceModelsOperation`. Removed in the next minor. */ +export type VoiceModelsOperation = ExperimentalVoiceModelsOperation + +/** @deprecated Use `ExperimentalVoiceSessionInput`. Removed in the next minor. */ +export type VoiceSessionInput = ExperimentalVoiceSessionInput + +/** @deprecated Use `ExperimentalVoiceSessionOutput`. Removed in the next minor. */ +export type VoiceSessionOutput = ExperimentalVoiceSessionOutput + +/** @deprecated Use `ExperimentalVoiceSessionOperation`. Removed in the next minor. */ +export type VoiceSessionOperation = ExperimentalVoiceSessionOperation + +/** @deprecated Use `ExperimentalIntegrationWellknownAddInput`. Removed in the next minor. */ +export type IntegrationWellknownAddInput = ExperimentalIntegrationWellknownAddInput + +/** @deprecated Use `ExperimentalIntegrationWellknownAddOutput`. Removed in the next minor. */ +export type IntegrationWellknownAddOutput = ExperimentalIntegrationWellknownAddOutput + +/** @deprecated Use `ExperimentalIntegrationWellknownAddOperation`. Removed in the next minor. */ +export type IntegrationWellknownAddOperation = ExperimentalIntegrationWellknownAddOperation + +/** @deprecated Use `ExperimentalMcpAddInput`. Removed in the next minor. */ +export type McpAddInput = ExperimentalMcpAddInput + +/** @deprecated Use `ExperimentalMcpAddOutput`. Removed in the next minor. */ +export type McpAddOutput = ExperimentalMcpAddOutput + +/** @deprecated Use `ExperimentalMcpAddOperation`. Removed in the next minor. */ +export type McpAddOperation = ExperimentalMcpAddOperation + +/** @deprecated Use `ExperimentalMcpRemoveInput`. Removed in the next minor. */ +export type McpRemoveInput = ExperimentalMcpRemoveInput + +/** @deprecated Use `ExperimentalMcpRemoveOutput`. Removed in the next minor. */ +export type McpRemoveOutput = ExperimentalMcpRemoveOutput + +/** @deprecated Use `ExperimentalMcpRemoveOperation`. Removed in the next minor. */ +export type McpRemoveOperation = ExperimentalMcpRemoveOperation + +/** @deprecated Use `ExperimentalMcpConnectInput`. Removed in the next minor. */ +export type McpConnectInput = ExperimentalMcpConnectInput + +/** @deprecated Use `ExperimentalMcpConnectOutput`. Removed in the next minor. */ +export type McpConnectOutput = ExperimentalMcpConnectOutput + +/** @deprecated Use `ExperimentalMcpConnectOperation`. Removed in the next minor. */ +export type McpConnectOperation = ExperimentalMcpConnectOperation + +/** @deprecated Use `ExperimentalMcpDisconnectInput`. Removed in the next minor. */ +export type McpDisconnectInput = ExperimentalMcpDisconnectInput + +/** @deprecated Use `ExperimentalMcpDisconnectOutput`. Removed in the next minor. */ +export type McpDisconnectOutput = ExperimentalMcpDisconnectOutput + +/** @deprecated Use `ExperimentalMcpDisconnectOperation`. Removed in the next minor. */ +export type McpDisconnectOperation = ExperimentalMcpDisconnectOperation + +/** @deprecated Use `ExperimentalMcpClientTokenInput`. Removed in the next minor. */ +export type McpClientTokenInput = ExperimentalMcpClientTokenInput + +/** @deprecated Use `ExperimentalMcpClientTokenOutput`. Removed in the next minor. */ +export type McpClientTokenOutput = ExperimentalMcpClientTokenOutput + +/** @deprecated Use `ExperimentalMcpClientTokenOperation`. Removed in the next minor. */ +export type McpClientTokenOperation = ExperimentalMcpClientTokenOperation + +/** @deprecated Use `ExperimentalFileWatchInput`. Removed in the next minor. */ +export type FileWatchInput = ExperimentalFileWatchInput + +/** @deprecated Use `ExperimentalFileWatchOutput`. Removed in the next minor. */ +export type FileWatchOutput = ExperimentalFileWatchOutput + +/** @deprecated Use `ExperimentalFileWatchOperation`. Removed in the next minor. */ +export type FileWatchOperation = ExperimentalFileWatchOperation + +/** @deprecated Use `ExperimentalFileUnwatchInput`. Removed in the next minor. */ +export type FileUnwatchInput = ExperimentalFileUnwatchInput + +/** @deprecated Use `ExperimentalFileUnwatchOutput`. Removed in the next minor. */ +export type FileUnwatchOutput = ExperimentalFileUnwatchOutput + +/** @deprecated Use `ExperimentalFileUnwatchOperation`. Removed in the next minor. */ +export type FileUnwatchOperation = ExperimentalFileUnwatchOperation + +/** @deprecated Use `ExperimentalMigrationV1StatusOutput`. Removed in the next minor. */ +export type MigrationV1StatusOutput = ExperimentalMigrationV1StatusOutput + +/** @deprecated Use `ExperimentalMigrationV1StatusOperation`. Removed in the next minor. */ +export type MigrationV1StatusOperation = ExperimentalMigrationV1StatusOperation + +/** @deprecated Use `ExperimentalUsageLimitsInput`. Removed in the next minor. */ +export type UsageLimitsInput = ExperimentalUsageLimitsInput + +/** @deprecated Use `ExperimentalUsageLimitsOutput`. Removed in the next minor. */ +export type UsageLimitsOutput = ExperimentalUsageLimitsOutput + +/** @deprecated Use `ExperimentalUsageLimitsOperation`. Removed in the next minor. */ +export type UsageLimitsOperation = ExperimentalUsageLimitsOperation + +/** @deprecated Use `ExperimentalConfigUpdateInput`. Removed in the next minor. */ +export type ConfigUpdateInput = ExperimentalConfigUpdateInput + +/** @deprecated Use `ExperimentalConfigUpdateOutput`. Removed in the next minor. */ +export type ConfigUpdateOutput = ExperimentalConfigUpdateOutput + +/** @deprecated Use `ExperimentalConfigUpdateOperation`. Removed in the next minor. */ +export type ConfigUpdateOperation = ExperimentalConfigUpdateOperation + +/** @deprecated Use `ExperimentalGenerateApi`. Removed in the next minor. */ +export type GenerateApi = ExperimentalGenerateApi + +/** @deprecated Use `ExperimentalVoiceApi`. Removed in the next minor. */ +export type VoiceApi = ExperimentalVoiceApi + +/** @deprecated Use `ExperimentalMigrationApi`. Removed in the next minor. */ +export type MigrationApi = ExperimentalMigrationApi + +/** @deprecated Use `ExperimentalUsageApi`. Removed in the next minor. */ +export type UsageApi = ExperimentalUsageApi + export interface AppApi { readonly server: ServerApi readonly location: LocationApi readonly agent: AgentApi readonly plugin: PluginApi readonly session: SessionApi + readonly experimental: ExperimentalApi & { + readonly session: ExperimentalSessionApi + readonly generate: ExperimentalGenerateApi + readonly voice: ExperimentalVoiceApi + readonly integration: ExperimentalIntegrationApi + readonly mcp: ExperimentalMcpApi + readonly file: ExperimentalFileApi + readonly migration: ExperimentalMigrationApi + readonly usage: ExperimentalUsageApi + readonly config: ExperimentalConfigApi + } readonly message: MessageApi readonly model: ModelApi - readonly generate: GenerateApi - readonly voice: VoiceApi readonly provider: ProviderApi readonly integration: IntegrationApi readonly mcp: McpApi @@ -2533,14 +2907,47 @@ export interface AppApi { readonly rpc: RpcApi readonly event: EventApi readonly pty: PtyApi - readonly experimental: ExperimentalApi readonly shell: ShellApi readonly reference: ReferenceApi readonly worktree: WorktreeApi readonly vcs: VcsApi readonly debug: DebugApi - readonly migration: MigrationApi readonly websearch: WebsearchApi - readonly usage: UsageApi readonly config: ConfigApi + + /** @deprecated Use `client.experimental.generate`. Removed in the next minor. */ + readonly generate: { + /** @deprecated Use `client.experimental.generate.text`. Removed in the next minor. */ + readonly text: ExperimentalGenerateTextOperation + + /** @deprecated Use `client.experimental.generate.image`. Removed in the next minor. */ + readonly image: ExperimentalGenerateImageOperation + + /** @deprecated Use `client.experimental.generate.decisions`. Removed in the next minor. */ + readonly decisions: ExperimentalGenerateDecisionsOperation + } + + /** @deprecated Use `client.experimental.voice`. Removed in the next minor. */ + readonly voice: { + /** @deprecated Use `client.experimental.voice.models`. Removed in the next minor. */ + readonly models: ExperimentalVoiceModelsOperation + + /** @deprecated Use `client.experimental.voice.session`. Removed in the next minor. */ + readonly session: ExperimentalVoiceSessionOperation + } + + /** @deprecated Use `client.experimental.migration`. Removed in the next minor. */ + readonly migration: { + /** @deprecated Use `client.experimental.migration.v1`. Removed in the next minor. */ + readonly v1: { + /** @deprecated Use `client.experimental.migration.v1.status`. Removed in the next minor. */ + readonly status: ExperimentalMigrationV1StatusOperation + } + } + + /** @deprecated Use `client.experimental.usage`. Removed in the next minor. */ + readonly usage: { + /** @deprecated Use `client.experimental.usage.limits`. Removed in the next minor. */ + readonly limits: ExperimentalUsageLimitsOperation + } } diff --git a/packages/client/src/effect/generated/client.ts b/packages/client/src/effect/generated/client.ts index a7d53fd2b02..1012306cea6 100644 --- a/packages/client/src/effect/generated/client.ts +++ b/packages/client/src/effect/generated/client.ts @@ -26,14 +26,8 @@ import type { PluginUpdateOutput, SessionListInput, SessionListOutput, - SessionStatsInput, - SessionStatsOutput, SessionCreateInput, SessionCreateOutput, - SessionImportInput, - SessionImportOutput, - SessionExportInput, - SessionExportOutput, SessionActiveOutput, SessionGetInput, SessionGetOutput, @@ -53,16 +47,12 @@ import type { SessionPromptOutput, SessionCommandInput, SessionCommandOutput, - SessionSkillInput, - SessionSkillOutput, SessionSyntheticInput, SessionSyntheticOutput, SessionShellInput, SessionShellOutput, SessionCompactInput, SessionCompactOutput, - SessionWaitInput, - SessionWaitOutput, SessionRevertStageInput, SessionRevertStageOutput, SessionRevertClearInput, @@ -79,16 +69,8 @@ import type { SessionInboxCancelOutput, SessionInboxUpdateInput, SessionInboxUpdateOutput, - SessionInstructionsEntryListInput, - SessionInstructionsEntryListOutput, - SessionInstructionsEntryPutInput, - SessionInstructionsEntryPutOutput, - SessionInstructionsEntryRemoveInput, - SessionInstructionsEntryRemoveOutput, SessionGenerateInput, SessionGenerateOutput, - SessionLogInput, - SessionLogOutput, SessionInterruptInput, SessionInterruptOutput, SessionBackgroundInput, @@ -109,21 +91,39 @@ import type { SessionEnvironmentOutput, SessionViewInput, SessionViewOutput, + ExperimentalSessionStatsInput, + ExperimentalSessionStatsOutput, + ExperimentalSessionImportInput, + ExperimentalSessionImportOutput, + ExperimentalSessionExportInput, + ExperimentalSessionExportOutput, + ExperimentalSessionSkillInput, + ExperimentalSessionSkillOutput, + ExperimentalSessionWaitInput, + ExperimentalSessionWaitOutput, + ExperimentalSessionInstructionsEntryListInput, + ExperimentalSessionInstructionsEntryListOutput, + ExperimentalSessionInstructionsEntryPutInput, + ExperimentalSessionInstructionsEntryPutOutput, + ExperimentalSessionInstructionsEntryRemoveInput, + ExperimentalSessionInstructionsEntryRemoveOutput, + ExperimentalSessionLogInput, + ExperimentalSessionLogOutput, MessageListInput, MessageListOutput, ModelListInput, ModelListOutput, ModelDefaultInput, ModelDefaultOutput, - GenerateTextInput, - GenerateTextOutput, - GenerateImageInput, - GenerateImageOutput, - GenerateDecisionsInput, - GenerateDecisionsOutput, - VoiceModelsOutput, - VoiceSessionInput, - VoiceSessionOutput, + ExperimentalGenerateTextInput, + ExperimentalGenerateTextOutput, + ExperimentalGenerateImageInput, + ExperimentalGenerateImageOutput, + ExperimentalGenerateDecisionsInput, + ExperimentalGenerateDecisionsOutput, + ExperimentalVoiceModelsOutput, + ExperimentalVoiceSessionInput, + ExperimentalVoiceSessionOutput, ProviderListInput, ProviderListOutput, ProviderGetInput, @@ -132,8 +132,6 @@ import type { IntegrationListOutput, IntegrationGetInput, IntegrationGetOutput, - IntegrationWellknownAddInput, - IntegrationWellknownAddOutput, IntegrationConnectKeyInput, IntegrationConnectKeyOutput, IntegrationConnectExternalInput, @@ -152,20 +150,22 @@ import type { IntegrationCommandStatusOutput, IntegrationCommandCancelInput, IntegrationCommandCancelOutput, + ExperimentalIntegrationWellknownAddInput, + ExperimentalIntegrationWellknownAddOutput, McpListInput, McpListOutput, - McpAddInput, - McpAddOutput, - McpRemoveInput, - McpRemoveOutput, - McpConnectInput, - McpConnectOutput, - McpDisconnectInput, - McpDisconnectOutput, McpResourceCatalogInput, McpResourceCatalogOutput, - McpClientTokenInput, - McpClientTokenOutput, + ExperimentalMcpAddInput, + ExperimentalMcpAddOutput, + ExperimentalMcpRemoveInput, + ExperimentalMcpRemoveOutput, + ExperimentalMcpConnectInput, + ExperimentalMcpConnectOutput, + ExperimentalMcpDisconnectInput, + ExperimentalMcpDisconnectOutput, + ExperimentalMcpClientTokenInput, + ExperimentalMcpClientTokenOutput, CredentialListOutput, CredentialCreateInput, CredentialCreateOutput, @@ -201,10 +201,10 @@ import type { FileListOutput, FileFindInput, FileFindOutput, - FileWatchInput, - FileWatchOutput, - FileUnwatchInput, - FileUnwatchOutput, + ExperimentalFileWatchInput, + ExperimentalFileWatchOutput, + ExperimentalFileUnwatchInput, + ExperimentalFileUnwatchOutput, CommandListInput, CommandListOutput, SkillListInput, @@ -280,18 +280,18 @@ import type { DebugLocationListOutput, DebugLocationEvictInput, DebugLocationEvictOutput, - MigrationV1StatusOutput, + ExperimentalMigrationV1StatusOutput, WebsearchProvidersInput, WebsearchProvidersOutput, WebsearchQueryInput, WebsearchQueryOutput, - UsageLimitsInput, - UsageLimitsOutput, + ExperimentalUsageLimitsInput, + ExperimentalUsageLimitsOutput, ConfigGetInput, ConfigGetOutput, ConfigShellsOutput, - ConfigUpdateInput, - ConfigUpdateOutput, + ExperimentalConfigUpdateInput, + ExperimentalConfigUpdateOutput, } from "../api/api.js" import { ClientError } from "./client-error.js" @@ -418,22 +418,6 @@ const EndpointSessionList = (raw: RawClient["server.session"]) => (input?: Sessi }).pipe(Effect.mapError(mapClientError)), ) -const EndpointSessionStats = (raw: RawClient["server.session"]) => (input?: SessionStatsInput) => - preserveEffect()( - raw["session.stats"]({ - query: { - from: input?.["from"], - to: input?.["to"], - project: input?.["project"], - timezone: input?.["timezone"], - tools: input?.["tools"], - }, - }).pipe( - Effect.mapError(mapClientError), - Effect.map((value) => value.data), - ), - ) - const EndpointSessionCreate = (raw: RawClient["server.session"]) => (input?: SessionCreateInput) => preserveEffect()( raw["session.create"]({ @@ -453,24 +437,6 @@ const EndpointSessionCreate = (raw: RawClient["server.session"]) => (input?: Ses ), ) -const EndpointSessionImport = (raw: RawClient["server.session"]) => (input: SessionImportInput) => - preserveEffect()( - raw["session.import"]({ - payload: { info: input["info"], messages: input["messages"], location: input["location"] }, - }).pipe( - Effect.mapError(mapClientError), - Effect.map((value) => value.data), - ), - ) - -const EndpointSessionExport = (raw: RawClient["server.session"]) => (input: SessionExportInput) => - preserveEffect()( - raw["session.export"]({ params: { sessionID: input["sessionID"] }, query: { sanitize: input["sanitize"] } }).pipe( - Effect.mapError(mapClientError), - Effect.map((value) => value.data), - ), - ) - const EndpointSessionActive = (raw: RawClient["server.session"]) => () => preserveEffect()( raw["session.active"]({}).pipe( @@ -570,14 +536,6 @@ const EndpointSessionCommand = (raw: RawClient["server.session"]) => (input: Ses }).pipe(Effect.mapError(mapClientError)), ) -const EndpointSessionSkill = (raw: RawClient["server.session"]) => (input: SessionSkillInput) => - preserveEffect()( - raw["session.skill"]({ - params: { sessionID: input["sessionID"] }, - payload: { id: input["id"], resume: input["resume"] }, - }).pipe(Effect.mapError(mapClientError)), - ) - const EndpointSessionSynthetic = (raw: RawClient["server.session"]) => (input: SessionSyntheticInput) => preserveEffect()( raw["session.synthetic"]({ @@ -615,11 +573,6 @@ const EndpointSessionCompact = (raw: RawClient["server.session"]) => (input: Ses ), ) -const EndpointSessionWait = (raw: RawClient["server.session"]) => (input: SessionWaitInput) => - preserveEffect()( - raw["session.wait"]({ params: { sessionID: input["sessionID"] } }).pipe(Effect.mapError(mapClientError)), - ) - const EndpointSessionRevertStage = (raw: RawClient["server.session"]) => (input: SessionRevertStageInput) => preserveEffect()( raw["session.revert.stage"]({ @@ -683,32 +636,6 @@ const EndpointSessionInboxUpdate = (raw: RawClient["server.session"]) => (input: }).pipe(Effect.mapError(mapClientError)), ) -const EndpointSessionInstructionsEntryList = - (raw: RawClient["server.session"]) => (input: SessionInstructionsEntryListInput) => - preserveEffect()( - raw["session.instructions.entry.list"]({ params: { sessionID: input["sessionID"] } }).pipe( - Effect.mapError(mapClientError), - Effect.map((value) => value.data), - ), - ) - -const EndpointSessionInstructionsEntryPut = - (raw: RawClient["server.session"]) => (input: SessionInstructionsEntryPutInput) => - preserveEffect()( - raw["session.instructions.entry.put"]({ - params: { sessionID: input["sessionID"], key: input["key"] }, - payload: { value: input["value"] }, - }).pipe(Effect.mapError(mapClientError)), - ) - -const EndpointSessionInstructionsEntryRemove = - (raw: RawClient["server.session"]) => (input: SessionInstructionsEntryRemoveInput) => - preserveEffect()( - raw["session.instructions.entry.remove"]({ params: { sessionID: input["sessionID"], key: input["key"] } }).pipe( - Effect.mapError(mapClientError), - ), - ) - const EndpointSessionGenerate = (raw: RawClient["server.session"]) => (input: SessionGenerateInput) => preserveEffect()( raw["session.generate"]({ params: { sessionID: input["sessionID"] }, payload: { prompt: input["prompt"] } }).pipe( @@ -717,19 +644,6 @@ const EndpointSessionGenerate = (raw: RawClient["server.session"]) => (input: Se ), ) -const EndpointSessionLog = (raw: RawClient["server.session"]) => (input: SessionLogInput) => - preserveStream()( - Stream.unwrap( - raw["session.log"]({ - params: { sessionID: input["sessionID"] }, - query: { after: input["after"], follow: input["follow"] }, - }).pipe( - Effect.mapError(mapClientError), - Effect.map((stream) => stream.pipe(Stream.mapError(mapClientError))), - ), - ), - ) - const EndpointSessionInterrupt = (raw: RawClient["server.session"]) => (input: SessionInterruptInput) => preserveEffect()( raw["session.interrupt"]({ params: { sessionID: input["sessionID"] }, query: { resume: input["resume"] } }).pipe( @@ -810,10 +724,7 @@ const EndpointSessionView = (raw: RawClient["server.session"]) => (input: Sessio const adaptGroupSession = (raw: RawClient["server.session"]) => ({ list: EndpointSessionList(raw), - stats: EndpointSessionStats(raw), create: EndpointSessionCreate(raw), - import: EndpointSessionImport(raw), - export: EndpointSessionExport(raw), active: EndpointSessionActive(raw), get: EndpointSessionGet(raw), remove: EndpointSessionRemove(raw), @@ -824,11 +735,9 @@ const adaptGroupSession = (raw: RawClient["server.session"]) => ({ move: EndpointSessionMove(raw), prompt: EndpointSessionPrompt(raw), command: EndpointSessionCommand(raw), - skill: EndpointSessionSkill(raw), synthetic: EndpointSessionSynthetic(raw), shell: EndpointSessionShell(raw), compact: EndpointSessionCompact(raw), - wait: EndpointSessionWait(raw), revert: { stage: EndpointSessionRevertStage(raw), clear: EndpointSessionRevertClear(raw), @@ -841,15 +750,7 @@ const adaptGroupSession = (raw: RawClient["server.session"]) => ({ cancel: EndpointSessionInboxCancel(raw), update: EndpointSessionInboxUpdate(raw), }, - instructions: { - entry: { - list: EndpointSessionInstructionsEntryList(raw), - put: EndpointSessionInstructionsEntryPut(raw), - remove: EndpointSessionInstructionsEntryRemove(raw), - }, - }, generate: EndpointSessionGenerate(raw), - log: EndpointSessionLog(raw), interrupt: EndpointSessionInterrupt(raw), background: EndpointSessionBackground(raw), message: { get: EndpointSessionMessageGet(raw) }, @@ -864,6 +765,111 @@ const adaptGroupSession = (raw: RawClient["server.session"]) => ({ view: EndpointSessionView(raw), }) +const EndpointExperimentalSessionStats = + (raw: RawClient["server.session"]) => (input?: ExperimentalSessionStatsInput) => + preserveEffect()( + raw["session.stats"]({ + query: { + from: input?.["from"], + to: input?.["to"], + project: input?.["project"], + timezone: input?.["timezone"], + tools: input?.["tools"], + }, + }).pipe( + Effect.mapError(mapClientError), + Effect.map((value) => value.data), + ), + ) + +const EndpointExperimentalSessionImport = + (raw: RawClient["server.session"]) => (input: ExperimentalSessionImportInput) => + preserveEffect()( + raw["session.import"]({ + payload: { info: input["info"], messages: input["messages"], location: input["location"] }, + }).pipe( + Effect.mapError(mapClientError), + Effect.map((value) => value.data), + ), + ) + +const EndpointExperimentalSessionExport = + (raw: RawClient["server.session"]) => (input: ExperimentalSessionExportInput) => + preserveEffect()( + raw["session.export"]({ params: { sessionID: input["sessionID"] }, query: { sanitize: input["sanitize"] } }).pipe( + Effect.mapError(mapClientError), + Effect.map((value) => value.data), + ), + ) + +const EndpointExperimentalSessionSkill = (raw: RawClient["server.session"]) => (input: ExperimentalSessionSkillInput) => + preserveEffect()( + raw["session.skill"]({ + params: { sessionID: input["sessionID"] }, + payload: { id: input["id"], resume: input["resume"] }, + }).pipe(Effect.mapError(mapClientError)), + ) + +const EndpointExperimentalSessionWait = (raw: RawClient["server.session"]) => (input: ExperimentalSessionWaitInput) => + preserveEffect()( + raw["session.wait"]({ params: { sessionID: input["sessionID"] } }).pipe(Effect.mapError(mapClientError)), + ) + +const EndpointExperimentalSessionInstructionsEntryList = + (raw: RawClient["server.session"]) => (input: ExperimentalSessionInstructionsEntryListInput) => + preserveEffect()( + raw["session.instructions.entry.list"]({ params: { sessionID: input["sessionID"] } }).pipe( + Effect.mapError(mapClientError), + Effect.map((value) => value.data), + ), + ) + +const EndpointExperimentalSessionInstructionsEntryPut = + (raw: RawClient["server.session"]) => (input: ExperimentalSessionInstructionsEntryPutInput) => + preserveEffect()( + raw["session.instructions.entry.put"]({ + params: { sessionID: input["sessionID"], key: input["key"] }, + payload: { value: input["value"] }, + }).pipe(Effect.mapError(mapClientError)), + ) + +const EndpointExperimentalSessionInstructionsEntryRemove = + (raw: RawClient["server.session"]) => (input: ExperimentalSessionInstructionsEntryRemoveInput) => + preserveEffect()( + raw["session.instructions.entry.remove"]({ params: { sessionID: input["sessionID"], key: input["key"] } }).pipe( + Effect.mapError(mapClientError), + ), + ) + +const EndpointExperimentalSessionLog = (raw: RawClient["server.session"]) => (input: ExperimentalSessionLogInput) => + preserveStream()( + Stream.unwrap( + raw["session.log"]({ + params: { sessionID: input["sessionID"] }, + query: { after: input["after"], follow: input["follow"] }, + }).pipe( + Effect.mapError(mapClientError), + Effect.map((stream) => stream.pipe(Stream.mapError(mapClientError))), + ), + ), + ) + +const adaptGroupExperimentalSession = (raw: RawClient["server.session"]) => ({ + stats: EndpointExperimentalSessionStats(raw), + import: EndpointExperimentalSessionImport(raw), + export: EndpointExperimentalSessionExport(raw), + skill: EndpointExperimentalSessionSkill(raw), + wait: EndpointExperimentalSessionWait(raw), + instructions: { + entry: { + list: EndpointExperimentalSessionInstructionsEntryList(raw), + put: EndpointExperimentalSessionInstructionsEntryPut(raw), + remove: EndpointExperimentalSessionInstructionsEntryRemove(raw), + }, + }, + log: EndpointExperimentalSessionLog(raw), +}) + const EndpointMessageList = (raw: RawClient["server.message"]) => (input: MessageListInput) => preserveEffect()( raw["session.messages"]({ @@ -891,57 +897,60 @@ const adaptGroupModel = (raw: RawClient["server.model"]) => ({ default: EndpointModelDefault(raw), }) -const EndpointGenerateText = (raw: RawClient["server.generate"]) => (input: GenerateTextInput) => - preserveEffect()( - raw["generate.text"]({ payload: { prompt: input["prompt"], model: input["model"] } }).pipe( - Effect.mapError(mapClientError), - Effect.map((value) => value.data), - ), - ) +const EndpointExperimentalGenerateText = + (raw: RawClient["server.generate"]) => (input: ExperimentalGenerateTextInput) => + preserveEffect()( + raw["generate.text"]({ payload: { prompt: input["prompt"], model: input["model"] } }).pipe( + Effect.mapError(mapClientError), + Effect.map((value) => value.data), + ), + ) -const EndpointGenerateImage = (raw: RawClient["server.generate"]) => (input: GenerateImageInput) => - preserveEffect()( - raw["generate.image"]({ - payload: { - model: input["model"], - prompt: input["prompt"], - images: input["images"], - n: input["n"], - aspect: input["aspect"], - resolution: input["resolution"], - }, - }).pipe( - Effect.mapError(mapClientError), - Effect.map((value) => value.data), - ), - ) +const EndpointExperimentalGenerateImage = + (raw: RawClient["server.generate"]) => (input: ExperimentalGenerateImageInput) => + preserveEffect()( + raw["generate.image"]({ + payload: { + model: input["model"], + prompt: input["prompt"], + images: input["images"], + n: input["n"], + aspect: input["aspect"], + resolution: input["resolution"], + }, + }).pipe( + Effect.mapError(mapClientError), + Effect.map((value) => value.data), + ), + ) -const EndpointGenerateDecisions = (raw: RawClient["server.generate"]) => (input: GenerateDecisionsInput) => - preserveEffect()( - raw["generate.decisions"]({ - payload: { model: input["model"], input: input["input"], questions: input["questions"] }, - }).pipe( - Effect.mapError(mapClientError), - Effect.map((value) => value.data), - ), - ) +const EndpointExperimentalGenerateDecisions = + (raw: RawClient["server.generate"]) => (input: ExperimentalGenerateDecisionsInput) => + preserveEffect()( + raw["generate.decisions"]({ + payload: { model: input["model"], input: input["input"], questions: input["questions"] }, + }).pipe( + Effect.mapError(mapClientError), + Effect.map((value) => value.data), + ), + ) -const adaptGroupGenerate = (raw: RawClient["server.generate"]) => ({ - text: EndpointGenerateText(raw), - image: EndpointGenerateImage(raw), - decisions: EndpointGenerateDecisions(raw), +const adaptGroupExperimentalGenerate = (raw: RawClient["server.generate"]) => ({ + text: EndpointExperimentalGenerateText(raw), + image: EndpointExperimentalGenerateImage(raw), + decisions: EndpointExperimentalGenerateDecisions(raw), }) -const EndpointVoiceModels = (raw: RawClient["server.voice"]) => () => - preserveEffect()( +const EndpointExperimentalVoiceModels = (raw: RawClient["server.voice"]) => () => + preserveEffect()( raw["voice.models"]({}).pipe( Effect.mapError(mapClientError), Effect.map((value) => value.data), ), ) -const EndpointVoiceSession = (raw: RawClient["server.voice"]) => (input: VoiceSessionInput) => - preserveEffect()( +const EndpointExperimentalVoiceSession = (raw: RawClient["server.voice"]) => (input: ExperimentalVoiceSessionInput) => + preserveEffect()( raw["voice.session"]({ payload: { model: input["model"], session: input["session"], transport: input["transport"] }, }).pipe( @@ -950,9 +959,9 @@ const EndpointVoiceSession = (raw: RawClient["server.voice"]) => (input: VoiceSe ), ) -const adaptGroupVoice = (raw: RawClient["server.voice"]) => ({ - models: EndpointVoiceModels(raw), - session: EndpointVoiceSession(raw), +const adaptGroupExperimentalVoice = (raw: RawClient["server.voice"]) => ({ + models: EndpointExperimentalVoiceModels(raw), + session: EndpointExperimentalVoiceSession(raw), }) const EndpointProviderList = (raw: RawClient["server.provider"]) => (input?: ProviderListInput) => @@ -985,14 +994,6 @@ const EndpointIntegrationGet = (raw: RawClient["server.integration"]) => (input: }).pipe(Effect.mapError(mapClientError)), ) -const EndpointIntegrationWellknownAdd = - (raw: RawClient["server.integration"]) => (input: IntegrationWellknownAddInput) => - preserveEffect()( - raw["integration.wellknown.add"]({ query: { location: input["location"] }, payload: { url: input["url"] } }).pipe( - Effect.mapError(mapClientError), - ), - ) - const EndpointIntegrationConnectKey = (raw: RawClient["server.integration"]) => (input: IntegrationConnectKeyInput) => preserveEffect()( raw["integration.connect.key"]({ @@ -1079,7 +1080,6 @@ const EndpointIntegrationCommandCancel = const adaptGroupIntegration = (raw: RawClient["server.integration"]) => ({ list: EndpointIntegrationList(raw), get: EndpointIntegrationGet(raw), - wellknown: { add: EndpointIntegrationWellknownAdd(raw) }, connect: { key: EndpointIntegrationConnectKey(raw), external: EndpointIntegrationConnectExternal(raw) }, oauth: { connect: EndpointIntegrationOauthConnect(raw), @@ -1094,62 +1094,77 @@ const adaptGroupIntegration = (raw: RawClient["server.integration"]) => ({ }, }) +const EndpointExperimentalIntegrationWellknownAdd = + (raw: RawClient["server.integration"]) => (input: ExperimentalIntegrationWellknownAddInput) => + preserveEffect()( + raw["integration.wellknown.add"]({ query: { location: input["location"] }, payload: { url: input["url"] } }).pipe( + Effect.mapError(mapClientError), + ), + ) + +const adaptGroupExperimentalIntegration = (raw: RawClient["server.integration"]) => ({ + wellknown: { add: EndpointExperimentalIntegrationWellknownAdd(raw) }, +}) + const EndpointMcpList = (raw: RawClient["server.mcp"]) => (input?: McpListInput) => preserveEffect()( raw["mcp.list"]({ query: { location: input?.["location"] } }).pipe(Effect.mapError(mapClientError)), ) -const EndpointMcpAdd = (raw: RawClient["server.mcp"]) => (input: McpAddInput) => - preserveEffect()( - raw["mcp.add"]({ - params: { server: input["server"] }, - query: { location: input["location"] }, - payload: { config: input["config"] }, - }).pipe(Effect.mapError(mapClientError)), - ) - -const EndpointMcpRemove = (raw: RawClient["server.mcp"]) => (input: McpRemoveInput) => - preserveEffect()( - raw["mcp.remove"]({ params: { server: input["server"] }, query: { location: input["location"] } }).pipe( - Effect.mapError(mapClientError), - ), - ) - -const EndpointMcpConnect = (raw: RawClient["server.mcp"]) => (input: McpConnectInput) => - preserveEffect()( - raw["mcp.connect"]({ params: { server: input["server"] }, query: { location: input["location"] } }).pipe( - Effect.mapError(mapClientError), - ), - ) - -const EndpointMcpDisconnect = (raw: RawClient["server.mcp"]) => (input: McpDisconnectInput) => - preserveEffect()( - raw["mcp.disconnect"]({ params: { server: input["server"] }, query: { location: input["location"] } }).pipe( - Effect.mapError(mapClientError), - ), - ) - const EndpointMcpResourceCatalog = (raw: RawClient["server.mcp"]) => (input?: McpResourceCatalogInput) => preserveEffect()( raw["mcp.resource.catalog"]({ query: { location: input?.["location"] } }).pipe(Effect.mapError(mapClientError)), ) -const EndpointMcpClientToken = (raw: RawClient["server.mcp"]) => (input: McpClientTokenInput) => - preserveEffect()( +const adaptGroupMcp = (raw: RawClient["server.mcp"]) => ({ + list: EndpointMcpList(raw), + resource: { catalog: EndpointMcpResourceCatalog(raw) }, +}) + +const EndpointExperimentalMcpAdd = (raw: RawClient["server.mcp"]) => (input: ExperimentalMcpAddInput) => + preserveEffect()( + raw["mcp.add"]({ + params: { server: input["server"] }, + query: { location: input["location"] }, + payload: { config: input["config"] }, + }).pipe(Effect.mapError(mapClientError)), + ) + +const EndpointExperimentalMcpRemove = (raw: RawClient["server.mcp"]) => (input: ExperimentalMcpRemoveInput) => + preserveEffect()( + raw["mcp.remove"]({ params: { server: input["server"] }, query: { location: input["location"] } }).pipe( + Effect.mapError(mapClientError), + ), + ) + +const EndpointExperimentalMcpConnect = (raw: RawClient["server.mcp"]) => (input: ExperimentalMcpConnectInput) => + preserveEffect()( + raw["mcp.connect"]({ params: { server: input["server"] }, query: { location: input["location"] } }).pipe( + Effect.mapError(mapClientError), + ), + ) + +const EndpointExperimentalMcpDisconnect = (raw: RawClient["server.mcp"]) => (input: ExperimentalMcpDisconnectInput) => + preserveEffect()( + raw["mcp.disconnect"]({ params: { server: input["server"] }, query: { location: input["location"] } }).pipe( + Effect.mapError(mapClientError), + ), + ) + +const EndpointExperimentalMcpClientToken = (raw: RawClient["server.mcp"]) => (input: ExperimentalMcpClientTokenInput) => + preserveEffect()( raw["mcp.clientToken"]({ query: { location: input["location"], name: input["name"] }, headers: { "x-opencode-ticket": input["x-opencode-ticket"] }, }).pipe(Effect.mapError(mapClientError)), ) -const adaptGroupMcp = (raw: RawClient["server.mcp"]) => ({ - list: EndpointMcpList(raw), - add: EndpointMcpAdd(raw), - remove: EndpointMcpRemove(raw), - connect: EndpointMcpConnect(raw), - disconnect: EndpointMcpDisconnect(raw), - resource: { catalog: EndpointMcpResourceCatalog(raw) }, - client: { token: EndpointMcpClientToken(raw) }, +const adaptGroupExperimentalMcp = (raw: RawClient["server.mcp"]) => ({ + add: EndpointExperimentalMcpAdd(raw), + remove: EndpointExperimentalMcpRemove(raw), + connect: EndpointExperimentalMcpConnect(raw), + disconnect: EndpointExperimentalMcpDisconnect(raw), + client: { token: EndpointExperimentalMcpClientToken(raw) }, }) const EndpointCredentialList = (raw: RawClient["server.credential"]) => () => @@ -1328,25 +1343,25 @@ const EndpointFileFind = (raw: RawClient["server.fs"]) => (input: FileFindInput) }).pipe(Effect.mapError(mapClientError)), ) -const EndpointFileWatch = (raw: RawClient["server.fs"]) => (input: FileWatchInput) => - preserveEffect()( +const adaptGroupFile = (raw: RawClient["server.fs"]) => ({ list: EndpointFileList(raw), find: EndpointFileFind(raw) }) + +const EndpointExperimentalFileWatch = (raw: RawClient["server.fs"]) => (input: ExperimentalFileWatchInput) => + preserveEffect()( raw["fs.watch"]({ query: { location: input["location"] }, payload: { path: input["path"] } }).pipe( Effect.mapError(mapClientError), ), ) -const EndpointFileUnwatch = (raw: RawClient["server.fs"]) => (input: FileUnwatchInput) => - preserveEffect()( +const EndpointExperimentalFileUnwatch = (raw: RawClient["server.fs"]) => (input: ExperimentalFileUnwatchInput) => + preserveEffect()( raw["fs.unwatch"]({ query: { location: input["location"] }, payload: { path: input["path"] } }).pipe( Effect.mapError(mapClientError), ), ) -const adaptGroupFile = (raw: RawClient["server.fs"]) => ({ - list: EndpointFileList(raw), - find: EndpointFileFind(raw), - watch: EndpointFileWatch(raw), - unwatch: EndpointFileUnwatch(raw), +const adaptGroupExperimentalFile = (raw: RawClient["server.fs"]) => ({ + watch: EndpointExperimentalFileWatch(raw), + unwatch: EndpointExperimentalFileUnwatch(raw), }) const EndpointCommandList = (raw: RawClient["server.command"]) => (input?: CommandListInput) => @@ -1712,10 +1727,14 @@ const adaptGroupDebug = (raw: RawClient["server.debug"]) => ({ location: { list: EndpointDebugLocationList(raw), evict: EndpointDebugLocationEvict(raw) }, }) -const EndpointMigrationV1Status = (raw: RawClient["server.migration"]) => () => - preserveEffect()(raw["migration.v1.status"]({}).pipe(Effect.mapError(mapClientError))) +const EndpointExperimentalMigrationV1Status = (raw: RawClient["server.migration"]) => () => + preserveEffect()( + raw["migration.v1.status"]({}).pipe(Effect.mapError(mapClientError)), + ) -const adaptGroupMigration = (raw: RawClient["server.migration"]) => ({ v1: { status: EndpointMigrationV1Status(raw) } }) +const adaptGroupExperimentalMigration = (raw: RawClient["server.migration"]) => ({ + v1: { status: EndpointExperimentalMigrationV1Status(raw) }, +}) const EndpointWebsearchProviders = (raw: RawClient["server.websearch"]) => (input?: WebsearchProvidersInput) => preserveEffect()( @@ -1735,12 +1754,14 @@ const adaptGroupWebsearch = (raw: RawClient["server.websearch"]) => ({ query: EndpointWebsearchQuery(raw), }) -const EndpointUsageLimits = (raw: RawClient["server.usage"]) => (input?: UsageLimitsInput) => - preserveEffect()( +const EndpointExperimentalUsageLimits = (raw: RawClient["server.usage"]) => (input?: ExperimentalUsageLimitsInput) => + preserveEffect()( raw["usage.limits"]({ query: { location: input?.["location"] } }).pipe(Effect.mapError(mapClientError)), ) -const adaptGroupUsage = (raw: RawClient["server.usage"]) => ({ limits: EndpointUsageLimits(raw) }) +const adaptGroupExperimentalUsage = (raw: RawClient["server.usage"]) => ({ + limits: EndpointExperimentalUsageLimits(raw), +}) const EndpointConfigGet = (raw: RawClient["server.config"]) => (input?: ConfigGetInput) => preserveEffect()( @@ -1750,51 +1771,158 @@ const EndpointConfigGet = (raw: RawClient["server.config"]) => (input?: ConfigGe const EndpointConfigShells = (raw: RawClient["server.config"]) => () => preserveEffect()(raw["config.shells"]({}).pipe(Effect.mapError(mapClientError))) -const EndpointConfigUpdate = (raw: RawClient["server.config"]) => (input: ConfigUpdateInput) => - preserveEffect()( - raw["config.update"]({ payload: { shell: input["shell"] } }).pipe(Effect.mapError(mapClientError)), - ) - const adaptGroupConfig = (raw: RawClient["server.config"]) => ({ get: EndpointConfigGet(raw), shells: EndpointConfigShells(raw), - update: EndpointConfigUpdate(raw), }) -const adaptClient = (raw: RawClient) => ({ - server: adaptGroupServer(raw["server.server"]), - location: adaptGroupLocation(raw["server.location"]), - agent: adaptGroupAgent(raw["server.agent"]), - plugin: adaptGroupPlugin(raw["server.plugin"]), - session: adaptGroupSession(raw["server.session"]), - message: adaptGroupMessage(raw["server.message"]), - model: adaptGroupModel(raw["server.model"]), - generate: adaptGroupGenerate(raw["server.generate"]), - voice: adaptGroupVoice(raw["server.voice"]), - provider: adaptGroupProvider(raw["server.provider"]), - integration: adaptGroupIntegration(raw["server.integration"]), - mcp: adaptGroupMcp(raw["server.mcp"]), - credential: adaptGroupCredential(raw["server.credential"]), - project: adaptGroupProject(raw["server.project"]), - form: adaptGroupForm(raw["server.form"]), - permission: adaptGroupPermission(raw["server.permission"]), - file: adaptGroupFile(raw["server.fs"]), - command: adaptGroupCommand(raw["server.command"]), - skill: adaptGroupSkill(raw["server.skill"]), - rpc: adaptGroupRpc(raw["server.rpc"]), - event: adaptGroupEvent(raw["server.event"]), - pty: adaptGroupPty(raw["server.pty"]), - experimental: adaptGroupExperimental(raw["server.experimental"]), - shell: adaptGroupShell(raw["server.shell"]), - reference: adaptGroupReference(raw["server.reference"]), - worktree: adaptGroupWorktree(raw["server.worktree"]), - vcs: adaptGroupVcs(raw["server.vcs"]), - debug: adaptGroupDebug(raw["server.debug"]), - migration: adaptGroupMigration(raw["server.migration"]), - websearch: adaptGroupWebsearch(raw["server.websearch"]), - usage: adaptGroupUsage(raw["server.usage"]), - config: adaptGroupConfig(raw["server.config"]), +const EndpointExperimentalConfigUpdate = (raw: RawClient["server.config"]) => (input: ExperimentalConfigUpdateInput) => + preserveEffect()( + raw["config.update"]({ payload: { shell: input["shell"] } }).pipe(Effect.mapError(mapClientError)), + ) + +const adaptGroupExperimentalConfig = (raw: RawClient["server.config"]) => ({ + update: EndpointExperimentalConfigUpdate(raw), }) +const adaptClient = (raw: RawClient) => { + const client = { + server: adaptGroupServer(raw["server.server"]), + location: adaptGroupLocation(raw["server.location"]), + agent: adaptGroupAgent(raw["server.agent"]), + plugin: adaptGroupPlugin(raw["server.plugin"]), + session: adaptGroupSession(raw["server.session"]), + experimental: { + ...adaptGroupExperimental(raw["server.experimental"]), + session: adaptGroupExperimentalSession(raw["server.session"]), + generate: adaptGroupExperimentalGenerate(raw["server.generate"]), + voice: adaptGroupExperimentalVoice(raw["server.voice"]), + integration: adaptGroupExperimentalIntegration(raw["server.integration"]), + mcp: adaptGroupExperimentalMcp(raw["server.mcp"]), + file: adaptGroupExperimentalFile(raw["server.fs"]), + migration: adaptGroupExperimentalMigration(raw["server.migration"]), + usage: adaptGroupExperimentalUsage(raw["server.usage"]), + config: adaptGroupExperimentalConfig(raw["server.config"]), + }, + message: adaptGroupMessage(raw["server.message"]), + model: adaptGroupModel(raw["server.model"]), + provider: adaptGroupProvider(raw["server.provider"]), + integration: adaptGroupIntegration(raw["server.integration"]), + mcp: adaptGroupMcp(raw["server.mcp"]), + credential: adaptGroupCredential(raw["server.credential"]), + project: adaptGroupProject(raw["server.project"]), + form: adaptGroupForm(raw["server.form"]), + permission: adaptGroupPermission(raw["server.permission"]), + file: adaptGroupFile(raw["server.fs"]), + command: adaptGroupCommand(raw["server.command"]), + skill: adaptGroupSkill(raw["server.skill"]), + rpc: adaptGroupRpc(raw["server.rpc"]), + event: adaptGroupEvent(raw["server.event"]), + pty: adaptGroupPty(raw["server.pty"]), + shell: adaptGroupShell(raw["server.shell"]), + reference: adaptGroupReference(raw["server.reference"]), + worktree: adaptGroupWorktree(raw["server.worktree"]), + vcs: adaptGroupVcs(raw["server.vcs"]), + debug: adaptGroupDebug(raw["server.debug"]), + websearch: adaptGroupWebsearch(raw["server.websearch"]), + config: adaptGroupConfig(raw["server.config"]), + } + return { + ...client, + session: { + ...client.session, + /** @deprecated Use `client.experimental.session.stats`. Removed in the next minor. */ + stats: client.experimental.session.stats, + /** @deprecated Use `client.experimental.session.import`. Removed in the next minor. */ + import: client.experimental.session.import, + /** @deprecated Use `client.experimental.session.export`. Removed in the next minor. */ + export: client.experimental.session.export, + /** @deprecated Use `client.experimental.session.skill`. Removed in the next minor. */ + skill: client.experimental.session.skill, + /** @deprecated Use `client.experimental.session.wait`. Removed in the next minor. */ + wait: client.experimental.session.wait, + /** @deprecated Use `client.experimental.session.instructions`. Removed in the next minor. */ + instructions: { + /** @deprecated Use `client.experimental.session.instructions.entry`. Removed in the next minor. */ + entry: { + /** @deprecated Use `client.experimental.session.instructions.entry.list`. Removed in the next minor. */ + list: client.experimental.session.instructions.entry.list, + /** @deprecated Use `client.experimental.session.instructions.entry.put`. Removed in the next minor. */ + put: client.experimental.session.instructions.entry.put, + /** @deprecated Use `client.experimental.session.instructions.entry.remove`. Removed in the next minor. */ + remove: client.experimental.session.instructions.entry.remove, + }, + }, + /** @deprecated Use `client.experimental.session.log`. Removed in the next minor. */ + log: client.experimental.session.log, + }, + /** @deprecated Use `client.experimental.generate`. Removed in the next minor. */ + generate: { + /** @deprecated Use `client.experimental.generate.text`. Removed in the next minor. */ + text: client.experimental.generate.text, + /** @deprecated Use `client.experimental.generate.image`. Removed in the next minor. */ + image: client.experimental.generate.image, + /** @deprecated Use `client.experimental.generate.decisions`. Removed in the next minor. */ + decisions: client.experimental.generate.decisions, + }, + /** @deprecated Use `client.experimental.voice`. Removed in the next minor. */ + voice: { + /** @deprecated Use `client.experimental.voice.models`. Removed in the next minor. */ + models: client.experimental.voice.models, + /** @deprecated Use `client.experimental.voice.session`. Removed in the next minor. */ + session: client.experimental.voice.session, + }, + integration: { + ...client.integration, + /** @deprecated Use `client.experimental.integration.wellknown`. Removed in the next minor. */ + wellknown: { + /** @deprecated Use `client.experimental.integration.wellknown.add`. Removed in the next minor. */ + add: client.experimental.integration.wellknown.add, + }, + }, + mcp: { + ...client.mcp, + /** @deprecated Use `client.experimental.mcp.add`. Removed in the next minor. */ + add: client.experimental.mcp.add, + /** @deprecated Use `client.experimental.mcp.remove`. Removed in the next minor. */ + remove: client.experimental.mcp.remove, + /** @deprecated Use `client.experimental.mcp.connect`. Removed in the next minor. */ + connect: client.experimental.mcp.connect, + /** @deprecated Use `client.experimental.mcp.disconnect`. Removed in the next minor. */ + disconnect: client.experimental.mcp.disconnect, + /** @deprecated Use `client.experimental.mcp.client`. Removed in the next minor. */ + client: { + /** @deprecated Use `client.experimental.mcp.client.token`. Removed in the next minor. */ + token: client.experimental.mcp.client.token, + }, + }, + file: { + ...client.file, + /** @deprecated Use `client.experimental.file.watch`. Removed in the next minor. */ + watch: client.experimental.file.watch, + /** @deprecated Use `client.experimental.file.unwatch`. Removed in the next minor. */ + unwatch: client.experimental.file.unwatch, + }, + /** @deprecated Use `client.experimental.migration`. Removed in the next minor. */ + migration: { + /** @deprecated Use `client.experimental.migration.v1`. Removed in the next minor. */ + v1: { + /** @deprecated Use `client.experimental.migration.v1.status`. Removed in the next minor. */ + status: client.experimental.migration.v1.status, + }, + }, + /** @deprecated Use `client.experimental.usage`. Removed in the next minor. */ + usage: { + /** @deprecated Use `client.experimental.usage.limits`. Removed in the next minor. */ + limits: client.experimental.usage.limits, + }, + config: { + ...client.config, + /** @deprecated Use `client.experimental.config.update`. Removed in the next minor. */ + update: client.experimental.config.update, + }, + } +} + export const make = (options?: { readonly baseUrl?: URL | string }) => HttpApiClient.make(ClientApi, options).pipe(Effect.map(adaptClient)) diff --git a/packages/client/src/promise/api.ts b/packages/client/src/promise/api.ts index 2c202ac3133..2c3d7d67c11 100644 --- a/packages/client/src/promise/api.ts +++ b/packages/client/src/promise/api.ts @@ -10,7 +10,10 @@ export type CommandApi = Client["command"] export type ConfigApi = Client["config"] export type CredentialApi = Client["credential"] export type EventApi = Client["event"] +/** @deprecated Use `ExperimentalGenerateApi`. Removed in the next minor. */ export type GenerateApi = Client["generate"] +export type ExperimentalGenerateApi = Client["experimental"]["generate"] +export type ExperimentalSessionApi = Client["experimental"]["session"] export type IntegrationApi = Client["integration"] export type McpApi = Client["mcp"] export type ModelApi = Client["model"] diff --git a/packages/client/src/promise/generated/client.ts b/packages/client/src/promise/generated/client.ts index 32aec4b71f1..8db7a72b9f6 100644 --- a/packages/client/src/promise/generated/client.ts +++ b/packages/client/src/promise/generated/client.ts @@ -20,14 +20,8 @@ import type { PluginUpdateOutput, SessionListInput, SessionListOutput, - SessionStatsInput, - SessionStatsOutput, SessionCreateInput, SessionCreateOutput, - SessionImportInput, - SessionImportOutput, - SessionExportInput, - SessionExportOutput, SessionActiveOutput, SessionGetInput, SessionGetOutput, @@ -47,16 +41,12 @@ import type { SessionPromptOutput, SessionCommandInput, SessionCommandOutput, - SessionSkillInput, - SessionSkillOutput, SessionSyntheticInput, SessionSyntheticOutput, SessionShellInput, SessionShellOutput, SessionCompactInput, SessionCompactOutput, - SessionWaitInput, - SessionWaitOutput, SessionRevertStageInput, SessionRevertStageOutput, SessionRevertClearInput, @@ -73,16 +63,8 @@ import type { SessionInboxCancelOutput, SessionInboxUpdateInput, SessionInboxUpdateOutput, - SessionInstructionsEntryListInput, - SessionInstructionsEntryListOutput, - SessionInstructionsEntryPutInput, - SessionInstructionsEntryPutOutput, - SessionInstructionsEntryRemoveInput, - SessionInstructionsEntryRemoveOutput, SessionGenerateInput, SessionGenerateOutput, - SessionLogInput, - SessionLogOutput, SessionInterruptInput, SessionInterruptOutput, SessionBackgroundInput, @@ -103,21 +85,39 @@ import type { SessionEnvironmentOutput, SessionViewInput, SessionViewOutput, + ExperimentalSessionStatsInput, + ExperimentalSessionStatsOutput, + ExperimentalSessionImportInput, + ExperimentalSessionImportOutput, + ExperimentalSessionExportInput, + ExperimentalSessionExportOutput, + ExperimentalSessionSkillInput, + ExperimentalSessionSkillOutput, + ExperimentalSessionWaitInput, + ExperimentalSessionWaitOutput, + ExperimentalSessionInstructionsEntryListInput, + ExperimentalSessionInstructionsEntryListOutput, + ExperimentalSessionInstructionsEntryPutInput, + ExperimentalSessionInstructionsEntryPutOutput, + ExperimentalSessionInstructionsEntryRemoveInput, + ExperimentalSessionInstructionsEntryRemoveOutput, + ExperimentalSessionLogInput, + ExperimentalSessionLogOutput, MessageListInput, MessageListOutput, ModelListInput, ModelListOutput, ModelDefaultInput, ModelDefaultOutput, - GenerateTextInput, - GenerateTextOutput, - GenerateImageInput, - GenerateImageOutput, - GenerateDecisionsInput, - GenerateDecisionsOutput, - VoiceModelsOutput, - VoiceSessionInput, - VoiceSessionOutput, + ExperimentalGenerateTextInput, + ExperimentalGenerateTextOutput, + ExperimentalGenerateImageInput, + ExperimentalGenerateImageOutput, + ExperimentalGenerateDecisionsInput, + ExperimentalGenerateDecisionsOutput, + ExperimentalVoiceModelsOutput, + ExperimentalVoiceSessionInput, + ExperimentalVoiceSessionOutput, ProviderListInput, ProviderListOutput, ProviderGetInput, @@ -126,8 +126,6 @@ import type { IntegrationListOutput, IntegrationGetInput, IntegrationGetOutput, - IntegrationWellknownAddInput, - IntegrationWellknownAddOutput, IntegrationConnectKeyInput, IntegrationConnectKeyOutput, IntegrationConnectExternalInput, @@ -146,20 +144,22 @@ import type { IntegrationCommandStatusOutput, IntegrationCommandCancelInput, IntegrationCommandCancelOutput, + ExperimentalIntegrationWellknownAddInput, + ExperimentalIntegrationWellknownAddOutput, McpListInput, McpListOutput, - McpAddInput, - McpAddOutput, - McpRemoveInput, - McpRemoveOutput, - McpConnectInput, - McpConnectOutput, - McpDisconnectInput, - McpDisconnectOutput, McpResourceCatalogInput, McpResourceCatalogOutput, - McpClientTokenInput, - McpClientTokenOutput, + ExperimentalMcpAddInput, + ExperimentalMcpAddOutput, + ExperimentalMcpRemoveInput, + ExperimentalMcpRemoveOutput, + ExperimentalMcpConnectInput, + ExperimentalMcpConnectOutput, + ExperimentalMcpDisconnectInput, + ExperimentalMcpDisconnectOutput, + ExperimentalMcpClientTokenInput, + ExperimentalMcpClientTokenOutput, CredentialListOutput, CredentialCreateInput, CredentialCreateOutput, @@ -197,12 +197,12 @@ import type { FileListOutput, FileFindInput, FileFindOutput, - FileWriteInput, - FileWriteOutput, - FileWatchInput, - FileWatchOutput, - FileUnwatchInput, - FileUnwatchOutput, + ExperimentalFileWriteInput, + ExperimentalFileWriteOutput, + ExperimentalFileWatchInput, + ExperimentalFileWatchOutput, + ExperimentalFileUnwatchInput, + ExperimentalFileUnwatchOutput, CommandListInput, CommandListOutput, SkillListInput, @@ -280,18 +280,18 @@ import type { DebugLocationListOutput, DebugLocationEvictInput, DebugLocationEvictOutput, - MigrationV1StatusOutput, + ExperimentalMigrationV1StatusOutput, WebsearchProvidersInput, WebsearchProvidersOutput, WebsearchQueryInput, WebsearchQueryOutput, - UsageLimitsInput, - UsageLimitsOutput, + ExperimentalUsageLimitsInput, + ExperimentalUsageLimitsOutput, ConfigGetInput, ConfigGetOutput, ConfigShellsOutput, - ConfigUpdateInput, - ConfigUpdateOutput, + ExperimentalConfigUpdateInput, + ExperimentalConfigUpdateOutput, } from "./types.js" import { ClientError } from "./client-error.js" @@ -444,7 +444,7 @@ export function make(options: ClientOptions) { }, }) - return { + const client = { server: { info: (requestOptions?: RequestOptions) => request( @@ -594,24 +594,6 @@ export function make(options: ClientOptions) { }, requestOptions, ), - stats: (input?: SessionStatsInput, requestOptions?: RequestOptions) => - request<{ readonly data: SessionStatsOutput }>( - { - method: "GET", - path: `/api/experimental/session/stats`, - query: { - from: input?.["from"], - to: input?.["to"], - project: input?.["project"], - timezone: input?.["timezone"], - tools: input?.["tools"], - }, - successStatus: 200, - declaredStatuses: [400, 401], - empty: false, - }, - requestOptions, - ).then((value) => value.data), create: (input?: SessionCreateInput, requestOptions?: RequestOptions) => request<{ readonly data: SessionCreateOutput }>( { @@ -633,30 +615,6 @@ export function make(options: ClientOptions) { }, requestOptions, ).then((value) => value.data), - import: (input: SessionImportInput, requestOptions?: RequestOptions) => - request<{ readonly data: SessionImportOutput }>( - { - method: "POST", - path: `/api/experimental/session/import`, - body: { info: input["info"], messages: input["messages"], location: input["location"] }, - successStatus: 200, - declaredStatuses: [400, 401, 404, 409], - empty: false, - }, - requestOptions, - ).then((value) => value.data), - export: (input: SessionExportInput, requestOptions?: RequestOptions) => - request<{ readonly data: SessionExportOutput }>( - { - method: "GET", - path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/export`, - query: { sanitize: input["sanitize"] }, - successStatus: 200, - declaredStatuses: [400, 401, 404, 500], - empty: false, - }, - requestOptions, - ).then((value) => value.data), active: (requestOptions?: RequestOptions) => request<{ readonly data: SessionActiveOutput }>( { @@ -795,18 +753,6 @@ export function make(options: ClientOptions) { }, requestOptions, ), - skill: (input: SessionSkillInput, requestOptions?: RequestOptions) => - request( - { - method: "POST", - path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/skill`, - body: { id: input["id"], resume: input["resume"] }, - successStatus: 204, - declaredStatuses: [400, 401, 404], - empty: true, - }, - requestOptions, - ), synthetic: (input: SessionSyntheticInput, requestOptions?: RequestOptions) => request<{ readonly data: SessionSyntheticOutput }>( { @@ -850,17 +796,6 @@ export function make(options: ClientOptions) { }, requestOptions, ).then((value) => value.data), - wait: (input: SessionWaitInput, requestOptions?: RequestOptions) => - request( - { - method: "POST", - path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/wait`, - successStatus: 204, - declaredStatuses: [400, 401, 404, 503], - empty: true, - }, - requestOptions, - ), revert: { stage: (input: SessionRevertStageInput, requestOptions?: RequestOptions) => request<{ readonly data: SessionRevertStageOutput }>( @@ -956,44 +891,6 @@ export function make(options: ClientOptions) { requestOptions, ), }, - instructions: { - entry: { - list: (input: SessionInstructionsEntryListInput, requestOptions?: RequestOptions) => - request<{ readonly data: SessionInstructionsEntryListOutput }>( - { - method: "GET", - path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/instructions/entries`, - successStatus: 200, - declaredStatuses: [400, 401, 404], - empty: false, - }, - requestOptions, - ).then((value) => value.data), - put: (input: SessionInstructionsEntryPutInput, requestOptions?: RequestOptions) => - request( - { - method: "PUT", - path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/instructions/entries/${encodeURIComponent(input.key)}`, - body: { value: input["value"] }, - successStatus: 204, - declaredStatuses: [400, 401, 404, 413], - empty: true, - }, - requestOptions, - ), - remove: (input: SessionInstructionsEntryRemoveInput, requestOptions?: RequestOptions) => - request( - { - method: "DELETE", - path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/instructions/entries/${encodeURIComponent(input.key)}`, - successStatus: 204, - declaredStatuses: [400, 401, 404], - empty: true, - }, - requestOptions, - ), - }, - }, generate: (input: SessionGenerateInput, requestOptions?: RequestOptions) => request<{ readonly data: SessionGenerateOutput }>( { @@ -1006,18 +903,6 @@ export function make(options: ClientOptions) { }, requestOptions, ).then((value) => value.data), - log: (input: SessionLogInput, requestOptions?: RequestOptions): AsyncIterable => - sse( - { - method: "GET", - path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/log`, - query: { after: input["after"], follow: input["follow"] }, - successStatus: 200, - declaredStatuses: [400, 401, 404], - empty: false, - }, - requestOptions, - ), interrupt: (input: SessionInterruptInput, requestOptions?: RequestOptions) => request( { @@ -1139,6 +1024,503 @@ export function make(options: ClientOptions) { requestOptions, ), }, + experimental: { + session: { + stats: (input?: ExperimentalSessionStatsInput, requestOptions?: RequestOptions) => + request<{ readonly data: ExperimentalSessionStatsOutput }>( + { + method: "GET", + path: `/api/experimental/session/stats`, + query: { + from: input?.["from"], + to: input?.["to"], + project: input?.["project"], + timezone: input?.["timezone"], + tools: input?.["tools"], + }, + successStatus: 200, + declaredStatuses: [400, 401], + empty: false, + }, + requestOptions, + ).then((value) => value.data), + import: (input: ExperimentalSessionImportInput, requestOptions?: RequestOptions) => + request<{ readonly data: ExperimentalSessionImportOutput }>( + { + method: "POST", + path: `/api/experimental/session/import`, + body: { info: input["info"], messages: input["messages"], location: input["location"] }, + successStatus: 200, + declaredStatuses: [400, 401, 404, 409], + empty: false, + }, + requestOptions, + ).then((value) => value.data), + export: (input: ExperimentalSessionExportInput, requestOptions?: RequestOptions) => + request<{ readonly data: ExperimentalSessionExportOutput }>( + { + method: "GET", + path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/export`, + query: { sanitize: input["sanitize"] }, + successStatus: 200, + declaredStatuses: [400, 401, 404, 500], + empty: false, + }, + requestOptions, + ).then((value) => value.data), + skill: (input: ExperimentalSessionSkillInput, requestOptions?: RequestOptions) => + request( + { + method: "POST", + path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/skill`, + body: { id: input["id"], resume: input["resume"] }, + successStatus: 204, + declaredStatuses: [400, 401, 404], + empty: true, + }, + requestOptions, + ), + wait: (input: ExperimentalSessionWaitInput, requestOptions?: RequestOptions) => + request( + { + method: "POST", + path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/wait`, + successStatus: 204, + declaredStatuses: [400, 401, 404, 503], + empty: true, + }, + requestOptions, + ), + instructions: { + entry: { + list: (input: ExperimentalSessionInstructionsEntryListInput, requestOptions?: RequestOptions) => + request<{ readonly data: ExperimentalSessionInstructionsEntryListOutput }>( + { + method: "GET", + path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/instructions/entries`, + successStatus: 200, + declaredStatuses: [400, 401, 404], + empty: false, + }, + requestOptions, + ).then((value) => value.data), + put: (input: ExperimentalSessionInstructionsEntryPutInput, requestOptions?: RequestOptions) => + request( + { + method: "PUT", + path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/instructions/entries/${encodeURIComponent(input.key)}`, + body: { value: input["value"] }, + successStatus: 204, + declaredStatuses: [400, 401, 404, 413], + empty: true, + }, + requestOptions, + ), + remove: (input: ExperimentalSessionInstructionsEntryRemoveInput, requestOptions?: RequestOptions) => + request( + { + method: "DELETE", + path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/instructions/entries/${encodeURIComponent(input.key)}`, + successStatus: 204, + declaredStatuses: [400, 401, 404], + empty: true, + }, + requestOptions, + ), + }, + }, + log: ( + input: ExperimentalSessionLogInput, + requestOptions?: RequestOptions, + ): AsyncIterable => + sse( + { + method: "GET", + path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/log`, + query: { after: input["after"], follow: input["follow"] }, + successStatus: 200, + declaredStatuses: [400, 401, 404], + empty: false, + }, + requestOptions, + ), + }, + generate: { + text: (input: ExperimentalGenerateTextInput, requestOptions?: RequestOptions) => + request<{ readonly data: ExperimentalGenerateTextOutput }>( + { + method: "POST", + path: `/api/experimental/generate/text`, + body: { prompt: input["prompt"], model: input["model"] }, + successStatus: 200, + declaredStatuses: [400, 401, 404, 422, 502, 503], + empty: false, + }, + requestOptions, + ).then((value) => value.data), + image: (input: ExperimentalGenerateImageInput, requestOptions?: RequestOptions) => + request<{ readonly data: ExperimentalGenerateImageOutput }>( + { + method: "POST", + path: `/api/experimental/generate/image`, + body: { + model: input["model"], + prompt: input["prompt"], + images: input["images"], + n: input["n"], + aspect: input["aspect"], + resolution: input["resolution"], + }, + successStatus: 200, + declaredStatuses: [400, 401, 404, 422, 502, 503], + empty: false, + }, + requestOptions, + ).then((value) => value.data), + decisions: (input: ExperimentalGenerateDecisionsInput, requestOptions?: RequestOptions) => + request<{ readonly data: ExperimentalGenerateDecisionsOutput }>( + { + method: "POST", + path: `/api/experimental/generate/decisions`, + body: { model: input["model"], input: input["input"], questions: input["questions"] }, + successStatus: 200, + declaredStatuses: [400, 401, 404, 422, 502, 503], + empty: false, + }, + requestOptions, + ).then((value) => value.data), + }, + voice: { + models: (requestOptions?: RequestOptions) => + request<{ readonly data: ExperimentalVoiceModelsOutput }>( + { + method: "GET", + path: `/api/experimental/voice/models`, + successStatus: 200, + declaredStatuses: [400, 401, 404, 503], + empty: false, + }, + requestOptions, + ).then((value) => value.data), + session: (input: ExperimentalVoiceSessionInput, requestOptions?: RequestOptions) => + request<{ readonly data: ExperimentalVoiceSessionOutput }>( + { + method: "POST", + path: `/api/experimental/voice/session`, + body: { model: input["model"], session: input["session"], transport: input["transport"] }, + successStatus: 200, + declaredStatuses: [400, 401, 404, 503], + empty: false, + }, + requestOptions, + ).then((value) => value.data), + }, + integration: { + wellknown: { + add: (input: ExperimentalIntegrationWellknownAddInput, requestOptions?: RequestOptions) => + request( + { + method: "POST", + path: `/api/experimental/integration/wellknown`, + query: { location: input["location"] }, + body: { url: input["url"] }, + successStatus: 204, + declaredStatuses: [400, 401, 404], + empty: true, + }, + requestOptions, + ), + }, + }, + mcp: { + add: (input: ExperimentalMcpAddInput, requestOptions?: RequestOptions) => + request( + { + method: "PUT", + path: `/api/experimental/mcp/${encodeURIComponent(input.server)}`, + query: { location: input["location"] }, + body: { config: input["config"] }, + successStatus: 204, + declaredStatuses: [400, 401, 404], + empty: true, + }, + requestOptions, + ), + remove: (input: ExperimentalMcpRemoveInput, requestOptions?: RequestOptions) => + request( + { + method: "DELETE", + path: `/api/experimental/mcp/${encodeURIComponent(input.server)}`, + query: { location: input["location"] }, + successStatus: 204, + declaredStatuses: [400, 401, 404], + empty: true, + }, + requestOptions, + ), + connect: (input: ExperimentalMcpConnectInput, requestOptions?: RequestOptions) => + request( + { + method: "POST", + path: `/api/experimental/mcp/${encodeURIComponent(input.server)}/connect`, + query: { location: input["location"] }, + successStatus: 204, + declaredStatuses: [400, 401, 404], + empty: true, + }, + requestOptions, + ), + disconnect: (input: ExperimentalMcpDisconnectInput, requestOptions?: RequestOptions) => + request( + { + method: "POST", + path: `/api/experimental/mcp/${encodeURIComponent(input.server)}/disconnect`, + query: { location: input["location"] }, + successStatus: 204, + declaredStatuses: [400, 401, 404], + empty: true, + }, + requestOptions, + ), + client: { + token: (input: ExperimentalMcpClientTokenInput, requestOptions?: RequestOptions) => + request( + { + method: "POST", + path: `/api/experimental/client-mcp/token`, + query: { location: input["location"], name: input["name"] }, + headers: { "x-opencode-ticket": input["x-opencode-ticket"] }, + successStatus: 200, + declaredStatuses: [400, 401, 403, 404], + empty: false, + }, + requestOptions, + ), + }, + }, + file: { + write: (input: ExperimentalFileWriteInput, requestOptions?: RequestOptions) => + request( + { + method: "POST", + path: `/api/experimental/fs/write`, + query: { location: input["location"], path: input["path"] }, + body: input["payload"], + successStatus: 200, + declaredStatuses: [400, 401, 404], + empty: false, + binaryBody: true, + }, + requestOptions, + ), + watch: (input: ExperimentalFileWatchInput, requestOptions?: RequestOptions) => + request( + { + method: "POST", + path: `/api/experimental/fs/watch`, + query: { location: input["location"] }, + body: { path: input["path"] }, + successStatus: 204, + declaredStatuses: [400, 401, 404, 503], + empty: true, + }, + requestOptions, + ), + unwatch: (input: ExperimentalFileUnwatchInput, requestOptions?: RequestOptions) => + request( + { + method: "DELETE", + path: `/api/experimental/fs/watch`, + query: { location: input["location"] }, + body: { path: input["path"] }, + successStatus: 204, + declaredStatuses: [400, 401, 404], + empty: true, + }, + requestOptions, + ), + }, + persistentPty: { + read: (input: ExperimentalPersistentPtyReadInput, requestOptions?: RequestOptions) => + request<{ readonly data: ExperimentalPersistentPtyReadOutput }>( + { + method: "GET", + path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/terminal/read`, + query: { lines: input["lines"] }, + successStatus: 200, + declaredStatuses: [400, 401, 503], + empty: false, + }, + requestOptions, + ).then((value) => value.data), + list: (input: ExperimentalPersistentPtyListInput, requestOptions?: RequestOptions) => + request<{ readonly data: ExperimentalPersistentPtyListOutput }>( + { + method: "GET", + path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/terminal`, + successStatus: 200, + declaredStatuses: [400, 401, 503], + empty: false, + }, + requestOptions, + ).then((value) => value.data), + create: (input: ExperimentalPersistentPtyCreateInput, requestOptions?: RequestOptions) => + request<{ readonly data: ExperimentalPersistentPtyCreateOutput }>( + { + method: "POST", + path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/terminal`, + body: { + command: input["command"], + args: input["args"], + cwd: input["cwd"], + title: input["title"], + env: input["env"], + size: input["size"], + }, + successStatus: 200, + declaredStatuses: [400, 401, 503], + empty: false, + }, + requestOptions, + ).then((value) => value.data), + shutdown: (requestOptions?: RequestOptions) => + request( + { + method: "POST", + path: `/api/experimental/persistent-pty/shutdown`, + successStatus: 204, + declaredStatuses: [400, 401, 503], + empty: true, + }, + requestOptions, + ), + handoff: (requestOptions?: RequestOptions) => + request( + { + method: "POST", + path: `/api/experimental/persistent-pty/handoff`, + successStatus: 200, + declaredStatuses: [400, 401, 503], + empty: false, + }, + requestOptions, + ), + get: (input: ExperimentalPersistentPtyGetInput, requestOptions?: RequestOptions) => + request<{ readonly data: ExperimentalPersistentPtyGetOutput }>( + { + method: "GET", + path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}`, + successStatus: 200, + declaredStatuses: [400, 401, 404, 503], + empty: false, + }, + requestOptions, + ).then((value) => value.data), + update: (input: ExperimentalPersistentPtyUpdateInput, requestOptions?: RequestOptions) => + request<{ readonly data: ExperimentalPersistentPtyUpdateOutput }>( + { + method: "PUT", + path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}`, + body: { attachmentID: input["attachmentID"], size: input["size"] }, + successStatus: 200, + declaredStatuses: [400, 401, 404, 503], + empty: false, + }, + requestOptions, + ).then((value) => value.data), + snapshot: (input: ExperimentalPersistentPtySnapshotInput, requestOptions?: RequestOptions) => + request<{ readonly data: ExperimentalPersistentPtySnapshotOutput }>( + { + method: "GET", + path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}/snapshot`, + successStatus: 200, + declaredStatuses: [400, 401, 404, 503], + empty: false, + }, + requestOptions, + ).then((value) => value.data), + remove: (input: ExperimentalPersistentPtyRemoveInput, requestOptions?: RequestOptions) => + request( + { + method: "DELETE", + path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}`, + successStatus: 204, + declaredStatuses: [400, 401, 404, 503], + empty: true, + }, + requestOptions, + ), + connectToken: (input: ExperimentalPersistentPtyConnectTokenInput, requestOptions?: RequestOptions) => + request<{ readonly data: ExperimentalPersistentPtyConnectTokenOutput }>( + { + method: "POST", + path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}/connect-token`, + headers: { "x-opencode-ticket": input["x-opencode-ticket"] }, + successStatus: 200, + declaredStatuses: [400, 401, 403, 404, 503], + empty: false, + }, + requestOptions, + ).then((value) => value.data), + }, + media: { + get: (input: ExperimentalMediaGetInput, requestOptions?: RequestOptions) => + request( + { + method: "GET", + path: `/api/experimental/media/${encodeURIComponent(input.hash)}`, + successStatus: 200, + declaredStatuses: [400, 401, 404], + empty: false, + binary: true, + }, + requestOptions, + ), + }, + migration: { + v1: { + status: (requestOptions?: RequestOptions) => + request( + { + method: "GET", + path: `/api/experimental/migration/v1`, + successStatus: 200, + declaredStatuses: [400, 401], + empty: false, + }, + requestOptions, + ), + }, + }, + usage: { + limits: (input?: ExperimentalUsageLimitsInput, requestOptions?: RequestOptions) => + request( + { + method: "GET", + path: `/api/experimental/usage/limits`, + query: { location: input?.["location"] }, + successStatus: 200, + declaredStatuses: [400, 401, 404, 503], + empty: false, + }, + requestOptions, + ), + }, + config: { + update: (input: ExperimentalConfigUpdateInput, requestOptions?: RequestOptions) => + request( + { + method: "PATCH", + path: `/api/experimental/config`, + body: { shell: input["shell"] }, + successStatus: 204, + declaredStatuses: [400, 401, 404], + empty: true, + }, + requestOptions, + ), + }, + }, message: { list: (input: MessageListInput, requestOptions?: RequestOptions) => request( @@ -1179,76 +1561,6 @@ export function make(options: ClientOptions) { requestOptions, ), }, - generate: { - text: (input: GenerateTextInput, requestOptions?: RequestOptions) => - request<{ readonly data: GenerateTextOutput }>( - { - method: "POST", - path: `/api/experimental/generate/text`, - body: { prompt: input["prompt"], model: input["model"] }, - successStatus: 200, - declaredStatuses: [400, 401, 404, 422, 502, 503], - empty: false, - }, - requestOptions, - ).then((value) => value.data), - image: (input: GenerateImageInput, requestOptions?: RequestOptions) => - request<{ readonly data: GenerateImageOutput }>( - { - method: "POST", - path: `/api/experimental/generate/image`, - body: { - model: input["model"], - prompt: input["prompt"], - images: input["images"], - n: input["n"], - aspect: input["aspect"], - resolution: input["resolution"], - }, - successStatus: 200, - declaredStatuses: [400, 401, 404, 422, 502, 503], - empty: false, - }, - requestOptions, - ).then((value) => value.data), - decisions: (input: GenerateDecisionsInput, requestOptions?: RequestOptions) => - request<{ readonly data: GenerateDecisionsOutput }>( - { - method: "POST", - path: `/api/experimental/generate/decisions`, - body: { model: input["model"], input: input["input"], questions: input["questions"] }, - successStatus: 200, - declaredStatuses: [400, 401, 404, 422, 502, 503], - empty: false, - }, - requestOptions, - ).then((value) => value.data), - }, - voice: { - models: (requestOptions?: RequestOptions) => - request<{ readonly data: VoiceModelsOutput }>( - { - method: "GET", - path: `/api/experimental/voice/models`, - successStatus: 200, - declaredStatuses: [400, 401, 404, 503], - empty: false, - }, - requestOptions, - ).then((value) => value.data), - session: (input: VoiceSessionInput, requestOptions?: RequestOptions) => - request<{ readonly data: VoiceSessionOutput }>( - { - method: "POST", - path: `/api/experimental/voice/session`, - body: { model: input["model"], session: input["session"], transport: input["transport"] }, - successStatus: 200, - declaredStatuses: [400, 401, 404, 503], - empty: false, - }, - requestOptions, - ).then((value) => value.data), - }, provider: { list: (input?: ProviderListInput, requestOptions?: RequestOptions) => request( @@ -1300,21 +1612,6 @@ export function make(options: ClientOptions) { }, requestOptions, ), - wellknown: { - add: (input: IntegrationWellknownAddInput, requestOptions?: RequestOptions) => - request( - { - method: "POST", - path: `/api/experimental/integration/wellknown`, - query: { location: input["location"] }, - body: { url: input["url"] }, - successStatus: 204, - declaredStatuses: [400, 401, 404], - empty: true, - }, - requestOptions, - ), - }, connect: { key: (input: IntegrationConnectKeyInput, requestOptions?: RequestOptions) => request( @@ -1448,55 +1745,6 @@ export function make(options: ClientOptions) { }, requestOptions, ), - add: (input: McpAddInput, requestOptions?: RequestOptions) => - request( - { - method: "PUT", - path: `/api/experimental/mcp/${encodeURIComponent(input.server)}`, - query: { location: input["location"] }, - body: { config: input["config"] }, - successStatus: 204, - declaredStatuses: [400, 401, 404], - empty: true, - }, - requestOptions, - ), - remove: (input: McpRemoveInput, requestOptions?: RequestOptions) => - request( - { - method: "DELETE", - path: `/api/experimental/mcp/${encodeURIComponent(input.server)}`, - query: { location: input["location"] }, - successStatus: 204, - declaredStatuses: [400, 401, 404], - empty: true, - }, - requestOptions, - ), - connect: (input: McpConnectInput, requestOptions?: RequestOptions) => - request( - { - method: "POST", - path: `/api/experimental/mcp/${encodeURIComponent(input.server)}/connect`, - query: { location: input["location"] }, - successStatus: 204, - declaredStatuses: [400, 401, 404], - empty: true, - }, - requestOptions, - ), - disconnect: (input: McpDisconnectInput, requestOptions?: RequestOptions) => - request( - { - method: "POST", - path: `/api/experimental/mcp/${encodeURIComponent(input.server)}/disconnect`, - query: { location: input["location"] }, - successStatus: 204, - declaredStatuses: [400, 401, 404], - empty: true, - }, - requestOptions, - ), resource: { catalog: (input?: McpResourceCatalogInput, requestOptions?: RequestOptions) => request( @@ -1511,21 +1759,6 @@ export function make(options: ClientOptions) { requestOptions, ), }, - client: { - token: (input: McpClientTokenInput, requestOptions?: RequestOptions) => - request( - { - method: "POST", - path: `/api/experimental/client-mcp/token`, - query: { location: input["location"], name: input["name"] }, - headers: { "x-opencode-ticket": input["x-opencode-ticket"] }, - successStatus: 200, - declaredStatuses: [400, 401, 403, 404], - empty: false, - }, - requestOptions, - ), - }, }, credential: { list: (requestOptions?: RequestOptions) => @@ -1776,46 +2009,6 @@ export function make(options: ClientOptions) { }, requestOptions, ), - write: (input: FileWriteInput, requestOptions?: RequestOptions) => - request( - { - method: "POST", - path: `/api/experimental/fs/write`, - query: { location: input["location"], path: input["path"] }, - body: input["payload"], - successStatus: 200, - declaredStatuses: [400, 401, 404], - empty: false, - binaryBody: true, - }, - requestOptions, - ), - watch: (input: FileWatchInput, requestOptions?: RequestOptions) => - request( - { - method: "POST", - path: `/api/experimental/fs/watch`, - query: { location: input["location"] }, - body: { path: input["path"] }, - successStatus: 204, - declaredStatuses: [400, 401, 404, 503], - empty: true, - }, - requestOptions, - ), - unwatch: (input: FileUnwatchInput, requestOptions?: RequestOptions) => - request( - { - method: "DELETE", - path: `/api/experimental/fs/watch`, - query: { location: input["location"] }, - body: { path: input["path"] }, - successStatus: 204, - declaredStatuses: [400, 401, 404], - empty: true, - }, - requestOptions, - ), }, command: { list: (input?: CommandListInput, requestOptions?: RequestOptions) => @@ -1959,145 +2152,6 @@ export function make(options: ClientOptions) { ), }, }, - experimental: { - persistentPty: { - read: (input: ExperimentalPersistentPtyReadInput, requestOptions?: RequestOptions) => - request<{ readonly data: ExperimentalPersistentPtyReadOutput }>( - { - method: "GET", - path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/terminal/read`, - query: { lines: input["lines"] }, - successStatus: 200, - declaredStatuses: [400, 401, 503], - empty: false, - }, - requestOptions, - ).then((value) => value.data), - list: (input: ExperimentalPersistentPtyListInput, requestOptions?: RequestOptions) => - request<{ readonly data: ExperimentalPersistentPtyListOutput }>( - { - method: "GET", - path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/terminal`, - successStatus: 200, - declaredStatuses: [400, 401, 503], - empty: false, - }, - requestOptions, - ).then((value) => value.data), - create: (input: ExperimentalPersistentPtyCreateInput, requestOptions?: RequestOptions) => - request<{ readonly data: ExperimentalPersistentPtyCreateOutput }>( - { - method: "POST", - path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/terminal`, - body: { - command: input["command"], - args: input["args"], - cwd: input["cwd"], - title: input["title"], - env: input["env"], - size: input["size"], - }, - successStatus: 200, - declaredStatuses: [400, 401, 503], - empty: false, - }, - requestOptions, - ).then((value) => value.data), - shutdown: (requestOptions?: RequestOptions) => - request( - { - method: "POST", - path: `/api/experimental/persistent-pty/shutdown`, - successStatus: 204, - declaredStatuses: [400, 401, 503], - empty: true, - }, - requestOptions, - ), - handoff: (requestOptions?: RequestOptions) => - request( - { - method: "POST", - path: `/api/experimental/persistent-pty/handoff`, - successStatus: 200, - declaredStatuses: [400, 401, 503], - empty: false, - }, - requestOptions, - ), - get: (input: ExperimentalPersistentPtyGetInput, requestOptions?: RequestOptions) => - request<{ readonly data: ExperimentalPersistentPtyGetOutput }>( - { - method: "GET", - path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}`, - successStatus: 200, - declaredStatuses: [400, 401, 404, 503], - empty: false, - }, - requestOptions, - ).then((value) => value.data), - update: (input: ExperimentalPersistentPtyUpdateInput, requestOptions?: RequestOptions) => - request<{ readonly data: ExperimentalPersistentPtyUpdateOutput }>( - { - method: "PUT", - path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}`, - body: { attachmentID: input["attachmentID"], size: input["size"] }, - successStatus: 200, - declaredStatuses: [400, 401, 404, 503], - empty: false, - }, - requestOptions, - ).then((value) => value.data), - snapshot: (input: ExperimentalPersistentPtySnapshotInput, requestOptions?: RequestOptions) => - request<{ readonly data: ExperimentalPersistentPtySnapshotOutput }>( - { - method: "GET", - path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}/snapshot`, - successStatus: 200, - declaredStatuses: [400, 401, 404, 503], - empty: false, - }, - requestOptions, - ).then((value) => value.data), - remove: (input: ExperimentalPersistentPtyRemoveInput, requestOptions?: RequestOptions) => - request( - { - method: "DELETE", - path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}`, - successStatus: 204, - declaredStatuses: [400, 401, 404, 503], - empty: true, - }, - requestOptions, - ), - connectToken: (input: ExperimentalPersistentPtyConnectTokenInput, requestOptions?: RequestOptions) => - request<{ readonly data: ExperimentalPersistentPtyConnectTokenOutput }>( - { - method: "POST", - path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}/connect-token`, - headers: { "x-opencode-ticket": input["x-opencode-ticket"] }, - successStatus: 200, - declaredStatuses: [400, 401, 403, 404, 503], - empty: false, - }, - requestOptions, - ).then((value) => value.data), - }, - media: { - get: (input: ExperimentalMediaGetInput, requestOptions?: RequestOptions) => - request( - { - method: "GET", - path: `/api/experimental/media/${encodeURIComponent(input.hash)}`, - successStatus: 200, - declaredStatuses: [400, 401, 404], - empty: false, - binary: true, - }, - requestOptions, - ), - }, - }, shell: { list: (input?: ShellListInput, requestOptions?: RequestOptions) => request( @@ -2357,21 +2411,6 @@ export function make(options: ClientOptions) { ), }, }, - migration: { - v1: { - status: (requestOptions?: RequestOptions) => - request( - { - method: "GET", - path: `/api/experimental/migration/v1`, - successStatus: 200, - declaredStatuses: [400, 401], - empty: false, - }, - requestOptions, - ), - }, - }, websearch: { providers: (input?: WebsearchProvidersInput, requestOptions?: RequestOptions) => request( @@ -2399,20 +2438,6 @@ export function make(options: ClientOptions) { requestOptions, ), }, - usage: { - limits: (input?: UsageLimitsInput, requestOptions?: RequestOptions) => - request( - { - method: "GET", - path: `/api/experimental/usage/limits`, - query: { location: input?.["location"] }, - successStatus: 200, - declaredStatuses: [400, 401, 404, 503], - empty: false, - }, - requestOptions, - ), - }, config: { get: (input?: ConfigGetInput, requestOptions?: RequestOptions) => request( @@ -2437,18 +2462,103 @@ export function make(options: ClientOptions) { }, requestOptions, ), - update: (input: ConfigUpdateInput, requestOptions?: RequestOptions) => - request( - { - method: "PATCH", - path: `/api/experimental/config`, - body: { shell: input["shell"] }, - successStatus: 204, - declaredStatuses: [400, 401, 404], - empty: true, - }, - requestOptions, - ), + }, + } + return { + ...client, + session: { + ...client.session, + /** @deprecated Use `client.experimental.session.stats`. Removed in the next minor. */ + stats: client.experimental.session.stats, + /** @deprecated Use `client.experimental.session.import`. Removed in the next minor. */ + import: client.experimental.session.import, + /** @deprecated Use `client.experimental.session.export`. Removed in the next minor. */ + export: client.experimental.session.export, + /** @deprecated Use `client.experimental.session.skill`. Removed in the next minor. */ + skill: client.experimental.session.skill, + /** @deprecated Use `client.experimental.session.wait`. Removed in the next minor. */ + wait: client.experimental.session.wait, + /** @deprecated Use `client.experimental.session.instructions`. Removed in the next minor. */ + instructions: { + /** @deprecated Use `client.experimental.session.instructions.entry`. Removed in the next minor. */ + entry: { + /** @deprecated Use `client.experimental.session.instructions.entry.list`. Removed in the next minor. */ + list: client.experimental.session.instructions.entry.list, + /** @deprecated Use `client.experimental.session.instructions.entry.put`. Removed in the next minor. */ + put: client.experimental.session.instructions.entry.put, + /** @deprecated Use `client.experimental.session.instructions.entry.remove`. Removed in the next minor. */ + remove: client.experimental.session.instructions.entry.remove, + }, + }, + /** @deprecated Use `client.experimental.session.log`. Removed in the next minor. */ + log: client.experimental.session.log, + }, + /** @deprecated Use `client.experimental.generate`. Removed in the next minor. */ + generate: { + /** @deprecated Use `client.experimental.generate.text`. Removed in the next minor. */ + text: client.experimental.generate.text, + /** @deprecated Use `client.experimental.generate.image`. Removed in the next minor. */ + image: client.experimental.generate.image, + /** @deprecated Use `client.experimental.generate.decisions`. Removed in the next minor. */ + decisions: client.experimental.generate.decisions, + }, + /** @deprecated Use `client.experimental.voice`. Removed in the next minor. */ + voice: { + /** @deprecated Use `client.experimental.voice.models`. Removed in the next minor. */ + models: client.experimental.voice.models, + /** @deprecated Use `client.experimental.voice.session`. Removed in the next minor. */ + session: client.experimental.voice.session, + }, + integration: { + ...client.integration, + /** @deprecated Use `client.experimental.integration.wellknown`. Removed in the next minor. */ + wellknown: { + /** @deprecated Use `client.experimental.integration.wellknown.add`. Removed in the next minor. */ + add: client.experimental.integration.wellknown.add, + }, + }, + mcp: { + ...client.mcp, + /** @deprecated Use `client.experimental.mcp.add`. Removed in the next minor. */ + add: client.experimental.mcp.add, + /** @deprecated Use `client.experimental.mcp.remove`. Removed in the next minor. */ + remove: client.experimental.mcp.remove, + /** @deprecated Use `client.experimental.mcp.connect`. Removed in the next minor. */ + connect: client.experimental.mcp.connect, + /** @deprecated Use `client.experimental.mcp.disconnect`. Removed in the next minor. */ + disconnect: client.experimental.mcp.disconnect, + /** @deprecated Use `client.experimental.mcp.client`. Removed in the next minor. */ + client: { + /** @deprecated Use `client.experimental.mcp.client.token`. Removed in the next minor. */ + token: client.experimental.mcp.client.token, + }, + }, + file: { + ...client.file, + /** @deprecated Use `client.experimental.file.write`. Removed in the next minor. */ + write: client.experimental.file.write, + /** @deprecated Use `client.experimental.file.watch`. Removed in the next minor. */ + watch: client.experimental.file.watch, + /** @deprecated Use `client.experimental.file.unwatch`. Removed in the next minor. */ + unwatch: client.experimental.file.unwatch, + }, + /** @deprecated Use `client.experimental.migration`. Removed in the next minor. */ + migration: { + /** @deprecated Use `client.experimental.migration.v1`. Removed in the next minor. */ + v1: { + /** @deprecated Use `client.experimental.migration.v1.status`. Removed in the next minor. */ + status: client.experimental.migration.v1.status, + }, + }, + /** @deprecated Use `client.experimental.usage`. Removed in the next minor. */ + usage: { + /** @deprecated Use `client.experimental.usage.limits`. Removed in the next minor. */ + limits: client.experimental.usage.limits, + }, + config: { + ...client.config, + /** @deprecated Use `client.experimental.config.update`. Removed in the next minor. */ + update: client.experimental.config.update, }, } } diff --git a/packages/client/src/promise/generated/types.ts b/packages/client/src/promise/generated/types.ts index 21c1f0d2a03..738fb50180f 100644 --- a/packages/client/src/promise/generated/types.ts +++ b/packages/client/src/promise/generated/types.ts @@ -77,18 +77,7 @@ export type FileDiffInfo = { export type SessionsCursor = string -export type SessionStatsToolTotals = { calls: number; succeeded: number; failed: number; unfinished: number } - -export type SessionStatsToolUsage = { - name: string - calls: number - succeeded: number - failed: number - unfinished: number - durationP50?: number -} - -export type SessionStatsActivity = { date: string; steps: number } +export type SessionActive = { type: "running" } export type PromptBase64 = string @@ -100,6 +89,12 @@ export type SkillID = string export type SkillName = string +export type SessionInboxDelivery = "steer" | "queue" + +export type SessionInboxSyntheticPayload = { text: string; description?: string; metadata?: { [x: string]: JsonValue } } + +export type SessionInboxCompactionPayload = {} + export type ShellID = string export type SessionMessageNative = { [x: string]: JsonValue } @@ -124,18 +119,41 @@ export type SessionStructuredError = { retryAfterMs?: number } -export type SessionActive = { type: "running" } +export type SessionGenerateResponse = { data: { text: string } } -export type SessionInboxDelivery = "steer" | "queue" +export type SessionInterruptResponse = { interrupted: boolean } -export type SessionInboxSyntheticPayload = { text: string; description?: string; metadata?: { [x: string]: JsonValue } } +export type FormID = string -export type SessionInboxCompactionPayload = {} +export type FormMetadata = { [x: string]: JsonValue } + +export type FormWhen = { + key: string + op: "eq" | "neq" + value: string | number | "Infinity" | "-Infinity" | "NaN" | boolean +} + +export type FormOption = { value: string; label: string; description?: string } + +export type FormExternalField = { key: string; type: "external"; url: string; title?: string; description?: string } + +export type FormValue = string | number | "Infinity" | "-Infinity" | "NaN" | boolean | Array + +export type SessionStatsToolTotals = { calls: number; succeeded: number; failed: number; unfinished: number } + +export type SessionStatsToolUsage = { + name: string + calls: number + succeeded: number + failed: number + unfinished: number + durationP50?: number +} + +export type SessionStatsActivity = { date: string; steps: number } export type InstructionEntryKey = string -export type SessionGenerateResponse = { data: { text: string } } - export type EventID = string export type EventSeq = number @@ -158,24 +176,6 @@ export type SessionMessageToolStateRunning1 = { metadata: { [x: string]: JsonValue } } -export type SessionInterruptResponse = { interrupted: boolean } - -export type FormID = string - -export type FormMetadata = { [x: string]: JsonValue } - -export type FormWhen = { - key: string - op: "eq" | "neq" - value: string | number | "Infinity" | "-Infinity" | "NaN" | boolean -} - -export type FormOption = { value: string; label: string; description?: string } - -export type FormExternalField = { key: string; type: "external"; url: string; title?: string; description?: string } - -export type FormValue = string | number | "Infinity" | "-Infinity" | "NaN" | boolean | Array - export type ModelType = "chat" | "decision" | "image" | (string & {}) export type ModelReasoningField = "reasoning" | "reasoning_content" | "reasoning_text" | (string & {}) @@ -433,11 +433,6 @@ export type SessionRevert = { files?: Array } -export type SessionStatsTools = - | { mode: "none" } - | { mode: "summary"; totals: SessionStatsToolTotals } - | { mode: "detail"; totals: SessionStatsToolTotals; usage: Array } - export type GenerateImageOutput2 = { type: "image"; data: PromptBase64; mime: string; name?: string } export type PromptFileAttachment = { @@ -472,6 +467,24 @@ export type SkillInfo = { content: string } +export type SessionInboxSynthetic = { + id: SessionMessageID + sessionID: SessionID + time: { created: number } + type: "synthetic" + payload: SessionInboxSyntheticPayload + delivery: SessionInboxDelivery +} + +export type SessionInboxCompaction = { + id: SessionMessageID + sessionID: SessionID + time: { created: number } + type: "compaction" + payload: SessionInboxCompactionPayload + delivery: SessionInboxDelivery +} + export type SessionMessageShell = { id: SessionMessageID metadata?: { [x: string]: JsonValue } @@ -546,43 +559,6 @@ export type SessionMessageIdle = { error?: SessionStructuredError } -export type SessionInboxSynthetic = { - id: SessionMessageID - sessionID: SessionID - time: { created: number } - type: "synthetic" - payload: SessionInboxSyntheticPayload - delivery: SessionInboxDelivery -} - -export type SessionInboxCompaction = { - id: SessionMessageID - sessionID: SessionID - time: { created: number } - type: "compaction" - payload: SessionInboxCompactionPayload - delivery: SessionInboxDelivery -} - -export type InstructionEntryInfo = { key: InstructionEntryKey; value: JsonValue } - -export type InstructionEntrySnapshot = Array<{ key: InstructionEntryKey; value: JsonValue; removed: boolean }> - -export type EventLogSynced = { type: "log.synced"; aggregateID: string; seq?: EventSeq } - -export type LocationRef = { directory: AbsolutePath; workspaceID?: WorkspaceID } - -export type SessionMessageAssistantText1 = { type: "text"; text: string; native?: SessionMessageNative1 } - -export type SessionMessageAssistantReasoning1 = { - type: "reasoning" - text: string - native?: SessionMessageNative1 - time?: { created: number; completed?: number } -} - -export type ToolContent1 = ToolTextContent | ToolFileContent1 - export type FormNumberField = { key: string title?: string @@ -655,6 +631,30 @@ export type FormMultiselectField = { export type FormAnswer = { [x: string]: FormValue } +export type SessionStatsTools = + | { mode: "none" } + | { mode: "summary"; totals: SessionStatsToolTotals } + | { mode: "detail"; totals: SessionStatsToolTotals; usage: Array } + +export type InstructionEntryInfo = { key: InstructionEntryKey; value: JsonValue } + +export type InstructionEntrySnapshot = Array<{ key: InstructionEntryKey; value: JsonValue; removed: boolean }> + +export type EventLogSynced = { type: "log.synced"; aggregateID: string; seq?: EventSeq } + +export type LocationRef = { directory: AbsolutePath; workspaceID?: WorkspaceID } + +export type SessionMessageAssistantText1 = { type: "text"; text: string; native?: SessionMessageNative1 } + +export type SessionMessageAssistantReasoning1 = { + type: "reasoning" + text: string + native?: SessionMessageNative1 + time?: { created: number; completed?: number } +} + +export type ToolContent1 = ToolTextContent | ToolFileContent1 + export type ModelCompatibility = { reasoningField?: ModelReasoningField requireReasoning?: boolean @@ -935,8 +935,6 @@ export type ReferenceSource = ReferenceLocalSource | ReferenceGitSource export type WorktreeList = Array -export type SessionStatsModelUsage = { model: ModelRef; steps: number; tokens: TokenUsageInfo; cost: MoneyUSD } - export type SessionMessageModelSelected = { id: SessionMessageID metadata?: { [x: string]: JsonValue } @@ -960,6 +958,8 @@ export type SessionMessageCompactionCompleted = { tokens?: TokenUsageInfo } +export type SessionStatsModelUsage = { model: ModelRef; steps: number; tokens: TokenUsageInfo; cost: MoneyUSD } + export type ProviderSettings = { timeout?: number | false headerTimeout?: number | false @@ -1021,6 +1021,14 @@ export type GenerateImageResult = { native?: GenerateNative } +export type SessionInboxUserPayload = { + text: string + files?: Array + agents?: Array + skills?: Array + metadata?: { [x: string]: JsonValue } +} + export type SessionMessageUser = { id: SessionMessageID metadata?: { [x: string]: JsonValue } @@ -1032,14 +1040,6 @@ export type SessionMessageUser = { type: "user" } -export type SessionInboxUserPayload = { - text: string - files?: Array - agents?: Array - skills?: Array - metadata?: { [x: string]: JsonValue } -} - export type SessionInboxUserPayload1 = { text: string files?: Array @@ -1063,6 +1063,19 @@ export type SessionMessageToolStateError = { metadata?: { [x: string]: JsonValue } } +export type FormField = + | FormStringField + | FormNumberField + | FormIntegerField + | FormBooleanField + | FormMultiselectField + | FormExternalField + +export type FormState = + | { status: "pending" } + | { status: "answered"; answer: FormAnswer } + | { status: "cancelled"; message?: string } + export type SessionAgentSelected = { id: EventID created: number @@ -2044,19 +2057,6 @@ export type SessionMessageToolStateError1 = { metadata?: { [x: string]: JsonValue } } -export type FormField = - | FormStringField - | FormNumberField - | FormIntegerField - | FormBooleanField - | FormMultiselectField - | FormExternalField - -export type FormState = - | { status: "pending" } - | { status: "answered"; answer: FormAnswer } - | { status: "cancelled"; message?: string } - export type GenerateDecisionAnswer = | GeneratePredicateAnswer | GenerateChoiceAnswer @@ -2139,6 +2139,11 @@ export type ReferenceInfo = { source: ReferenceSource } +export type SessionMessageCompaction = + | SessionMessageCompactionRunning + | SessionMessageCompactionCompleted + | SessionMessageCompactionFailed + export type SessionStatsInfo = { range: { from: number; to: number } sessions: number @@ -2154,11 +2159,6 @@ export type SessionStatsInfo = { models: Array } -export type SessionMessageCompaction = - | SessionMessageCompactionRunning - | SessionMessageCompactionCompleted - | SessionMessageCompactionFailed - export type ProviderRequest = { settings: ProviderSettings headers: { [x: string]: string } @@ -2470,6 +2470,8 @@ export type SessionMessageAssistantTool = { time: { created: number; ran?: number; completed?: number } } +export type FormFields = [FormField, ...Array] + export type SessionInboxItem = | { type: "user"; payload: SessionInboxUserPayload1; delivery: SessionInboxDelivery } | { type: "synthetic"; payload: SessionInboxSyntheticPayload1; delivery: SessionInboxDelivery } @@ -2490,8 +2492,6 @@ export type SessionMessageAssistantTool1 = { time: { created: number; ran?: number; completed?: number } } -export type FormFields = [FormField, ...Array] - export type GenerateDecisionResult = { answers: Array cost?: MoneyUSD @@ -2548,21 +2548,6 @@ export type SessionMessageAssistant = { retry?: SessionMessageAssistantRetry } -export type SessionInboxEnqueued = { - id: EventID - created: number - metadata?: { [x: string]: any } - type: "session.inbox.enqueued" - durable: { aggregateID: string; seq: EventSeq; version: 1 } - location?: LocationRef - data: { sessionID: SessionID; inboxID: SessionMessageID; item: SessionInboxItem } -} - -export type SessionMessageAssistantContentEncoded = - | SessionMessageAssistantText1 - | SessionMessageAssistantReasoning1 - | SessionMessageAssistantTool1 - export type FormInfo = { id: FormID; sessionID: string; title: string; metadata?: FormMetadata; fields: FormFields } export type FormDetail = { @@ -2580,6 +2565,21 @@ export type IntegrationKeyMethod = { type: "key"; label?: string; form?: FormFie export type IntegrationExternalMethod = { id: IntegrationMethodID; type: "external"; label: string; form?: FormFields } +export type SessionInboxEnqueued = { + id: EventID + created: number + metadata?: { [x: string]: any } + type: "session.inbox.enqueued" + durable: { aggregateID: string; seq: EventSeq; version: 1 } + location?: LocationRef + data: { sessionID: SessionID; inboxID: SessionMessageID; item: SessionInboxItem } +} + +export type SessionMessageAssistantContentEncoded = + | SessionMessageAssistantText1 + | SessionMessageAssistantReasoning1 + | SessionMessageAssistantTool1 + export type GenerateDecisionsResponse = { data: GenerateDecisionResult } export type FormInfo1 = { id: FormID; sessionID: string; title: string; metadata?: FormMetadata1; fields: FormFields2 } @@ -2597,6 +2597,13 @@ export type SessionMessageInfo = | SessionMessageCompaction | SessionMessageIdle +export type IntegrationMethod = + | IntegrationOAuthMethod + | IntegrationCommandMethod + | IntegrationKeyMethod + | IntegrationExternalMethod + | IntegrationEnvMethod + export type SessionMessageContentUpdated = { id: EventID created: number @@ -2607,13 +2614,6 @@ export type SessionMessageContentUpdated = { data: { sessionID: SessionID; messageID: SessionMessageID; content: Array } } -export type IntegrationMethod = - | IntegrationOAuthMethod - | IntegrationCommandMethod - | IntegrationKeyMethod - | IntegrationExternalMethod - | IntegrationEnvMethod - export type FormCreated = { id: EventID created: number @@ -2630,6 +2630,14 @@ export type SessionMessagesResponse = { cursor: { previous?: string | null; next?: string | null } } +export type IntegrationInfo = { + id: IntegrationID + name: string + metadata?: { [x: string]: any } + methods: Array + connections: Array +} + export type SessionEventDurable = | SessionCreated | SessionAgentSelected @@ -2679,14 +2687,6 @@ export type SessionEventDurable = | SessionUsageRecorded | SessionMessageContentUpdated -export type IntegrationInfo = { - id: IntegrationID - name: string - metadata?: { [x: string]: any } - methods: Array - connections: Array -} - export type V2Event = | LocationShutdown | ModelsDevRefreshed @@ -2844,22 +2844,6 @@ export type SessionNotFoundError = { export const isSessionNotFoundError = (value: unknown): value is SessionNotFoundError => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "SessionNotFoundError" -export type ConflictError = { - readonly _tag: "ConflictError" - readonly message: string - readonly resource?: string | undefined -} -export const isConflictError = (value: unknown): value is ConflictError => - typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ConflictError" - -export type UnknownError = { - readonly _tag: "UnknownError" - readonly message: string - readonly ref?: string | undefined -} -export const isUnknownError = (value: unknown): value is UnknownError => - typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "UnknownError" - export type MessageNotFoundError = { readonly _tag: "MessageNotFoundError" readonly sessionID: string @@ -2869,6 +2853,14 @@ export type MessageNotFoundError = { export const isMessageNotFoundError = (value: unknown): value is MessageNotFoundError => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "MessageNotFoundError" +export type ConflictError = { + readonly _tag: "ConflictError" + readonly message: string + readonly resource?: string | undefined +} +export const isConflictError = (value: unknown): value is ConflictError => + typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ConflictError" + export type CommandNotFoundError = { readonly _tag: "CommandNotFoundError" readonly command: string @@ -2885,14 +2877,6 @@ export type CommandExecutionError = { export const isCommandExecutionError = (value: unknown): value is CommandExecutionError => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "CommandExecutionError" -export type SkillNotFoundError = { - readonly _tag: "SkillNotFoundError" - readonly skill: string - readonly message: string -} -export const isSkillNotFoundError = (value: unknown): value is SkillNotFoundError => - typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "SkillNotFoundError" - export type SessionBusyError = { readonly _tag: "SessionBusyError" readonly sessionID: string @@ -2901,17 +2885,13 @@ export type SessionBusyError = { export const isSessionBusyError = (value: unknown): value is SessionBusyError => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "SessionBusyError" -export type InstructionEntryValueTooLargeError = { - readonly _tag: "InstructionEntryValueTooLargeError" - readonly actualBytes: number - readonly maxBytes: number +export type UnknownError = { + readonly _tag: "UnknownError" readonly message: string + readonly ref?: string | undefined } -export const isInstructionEntryValueTooLargeError = (value: unknown): value is InstructionEntryValueTooLargeError => - typeof value === "object" && - value !== null && - "_tag" in value && - value["_tag"] === "InstructionEntryValueTooLargeError" +export const isUnknownError = (value: unknown): value is UnknownError => + typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "UnknownError" export type FormNotFoundError = { readonly _tag: "FormNotFoundError"; readonly id: string; readonly message: string } export const isFormNotFoundError = (value: unknown): value is FormNotFoundError => @@ -2933,6 +2913,26 @@ export type FormAlreadySettledError = { export const isFormAlreadySettledError = (value: unknown): value is FormAlreadySettledError => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "FormAlreadySettledError" +export type SkillNotFoundError = { + readonly _tag: "SkillNotFoundError" + readonly skill: string + readonly message: string +} +export const isSkillNotFoundError = (value: unknown): value is SkillNotFoundError => + typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "SkillNotFoundError" + +export type InstructionEntryValueTooLargeError = { + readonly _tag: "InstructionEntryValueTooLargeError" + readonly actualBytes: number + readonly maxBytes: number + readonly message: string +} +export const isInstructionEntryValueTooLargeError = (value: unknown): value is InstructionEntryValueTooLargeError => + typeof value === "object" && + value !== null && + "_tag" in value && + value["_tag"] === "InstructionEntryValueTooLargeError" + export type ProviderNotFoundError = { readonly _tag: "ProviderNotFoundError" readonly providerID: string @@ -3143,16 +3143,6 @@ export type SessionListInput = { export type SessionListOutput = SessionsResponse -export type SessionStatsInput = { - readonly from?: number | undefined - readonly to?: number | undefined - readonly project?: string | undefined - readonly timezone?: string | undefined - readonly tools?: "none" | "summary" | "detail" | undefined -} - -export type SessionStatsOutput = { data: SessionStatsInfo }["data"] - export type SessionCreateInput = { readonly id?: string | null | undefined readonly parentID?: string | null | undefined @@ -3169,67 +3159,6 @@ export type SessionCreateInput = { export type SessionCreateOutput = { data: SessionInfo }["data"] -export type SessionImportInput = { - readonly info: { - readonly id: string - readonly parentID?: string - readonly fork?: { - readonly sessionID: string - readonly boundary: - | { readonly type: "before"; readonly messageID: string } - | { readonly type: "through"; readonly messageID: string } - } - readonly projectID: string - readonly agent?: string - readonly model?: { readonly id: string; readonly providerID: string; readonly variant?: string } - readonly cost: number - readonly tokens: { - readonly input: number - readonly output: number - readonly reasoning: number - readonly cache: { readonly read: number; readonly write: number } - } - readonly outcome?: "succeeded" | "failed" | "interrupted" - readonly time: { - readonly created: number - readonly updated: number - readonly idle?: number - readonly viewed?: number - readonly archived?: number - } - readonly title?: string - readonly subpath?: string - readonly metadata?: { readonly [x: string]: JsonValue } - readonly permissions?: ReadonlyArray<{ - readonly action: string - readonly resource: string - readonly effect: "allow" | "deny" | "ask" - }> - readonly revert?: { - readonly messageID: string - readonly partID?: string - readonly snapshot?: string - readonly files?: ReadonlyArray<{ - readonly file: string - readonly patch: string - readonly additions: number - readonly deletions: number - readonly status: "added" | "deleted" | "modified" - readonly more?: true - }> - } - readonly location: { readonly directory: string } - } - readonly messages: ReadonlyArray - readonly location?: { readonly directory: string } | null | undefined -} - -export type SessionImportOutput = { data: SessionInfo }["data"] - -export type SessionExportInput = { readonly sessionID: string; readonly sanitize?: boolean | undefined } - -export type SessionExportOutput = { data: SessionTransferData }["data"] - export type SessionActiveOutput = { data: { [x: SessionID]: SessionActive } }["data"] export type SessionGetInput = { readonly sessionID: string } @@ -3335,14 +3264,6 @@ export type SessionCommandInput = { export type SessionCommandOutput = void -export type SessionSkillInput = { - readonly sessionID: string - readonly id: string - readonly resume?: boolean | undefined -} - -export type SessionSkillOutput = void - export type SessionSyntheticInput = { readonly sessionID: string readonly id?: string | null | undefined @@ -3371,10 +3292,6 @@ export type SessionCompactInput = { export type SessionCompactOutput = { data: SessionInboxCompaction }["data"] -export type SessionWaitInput = { readonly sessionID: string } - -export type SessionWaitOutput = void - export type SessionRevertStageInput = { readonly sessionID: string readonly messageID: string @@ -3420,34 +3337,10 @@ export type SessionInboxUpdateInput = { export type SessionInboxUpdateOutput = void -export type SessionInstructionsEntryListInput = { readonly sessionID: string } - -export type SessionInstructionsEntryListOutput = { data: Array }["data"] - -export type SessionInstructionsEntryPutInput = { - readonly sessionID: string - readonly key: string - readonly value: JsonValue -} - -export type SessionInstructionsEntryPutOutput = void - -export type SessionInstructionsEntryRemoveInput = { readonly sessionID: string; readonly key: string } - -export type SessionInstructionsEntryRemoveOutput = void - export type SessionGenerateInput = { readonly sessionID: string; readonly prompt: string } export type SessionGenerateOutput = SessionGenerateResponse["data"] -export type SessionLogInput = { - readonly sessionID: string - readonly after?: number | undefined - readonly follow?: boolean | undefined -} - -export type SessionLogOutput = SessionLogItem - export type SessionInterruptInput = { readonly sessionID: string; readonly resume?: boolean | undefined } export type SessionInterruptOutput = SessionInterruptResponse @@ -3710,6 +3603,113 @@ export type SessionViewInput = { readonly sessionID: string; readonly idle: numb export type SessionViewOutput = void +export type ExperimentalSessionStatsInput = { + readonly from?: number | undefined + readonly to?: number | undefined + readonly project?: string | undefined + readonly timezone?: string | undefined + readonly tools?: "none" | "summary" | "detail" | undefined +} + +export type ExperimentalSessionStatsOutput = { data: SessionStatsInfo }["data"] + +export type ExperimentalSessionImportInput = { + readonly info: { + readonly id: string + readonly parentID?: string + readonly fork?: { + readonly sessionID: string + readonly boundary: + | { readonly type: "before"; readonly messageID: string } + | { readonly type: "through"; readonly messageID: string } + } + readonly projectID: string + readonly agent?: string + readonly model?: { readonly id: string; readonly providerID: string; readonly variant?: string } + readonly cost: number + readonly tokens: { + readonly input: number + readonly output: number + readonly reasoning: number + readonly cache: { readonly read: number; readonly write: number } + } + readonly outcome?: "succeeded" | "failed" | "interrupted" + readonly time: { + readonly created: number + readonly updated: number + readonly idle?: number + readonly viewed?: number + readonly archived?: number + } + readonly title?: string + readonly subpath?: string + readonly metadata?: { readonly [x: string]: JsonValue } + readonly permissions?: ReadonlyArray<{ + readonly action: string + readonly resource: string + readonly effect: "allow" | "deny" | "ask" + }> + readonly revert?: { + readonly messageID: string + readonly partID?: string + readonly snapshot?: string + readonly files?: ReadonlyArray<{ + readonly file: string + readonly patch: string + readonly additions: number + readonly deletions: number + readonly status: "added" | "deleted" | "modified" + readonly more?: true + }> + } + readonly location: { readonly directory: string } + } + readonly messages: ReadonlyArray + readonly location?: { readonly directory: string } | null | undefined +} + +export type ExperimentalSessionImportOutput = { data: SessionInfo }["data"] + +export type ExperimentalSessionExportInput = { readonly sessionID: string; readonly sanitize?: boolean | undefined } + +export type ExperimentalSessionExportOutput = { data: SessionTransferData }["data"] + +export type ExperimentalSessionSkillInput = { + readonly sessionID: string + readonly id: string + readonly resume?: boolean | undefined +} + +export type ExperimentalSessionSkillOutput = void + +export type ExperimentalSessionWaitInput = { readonly sessionID: string } + +export type ExperimentalSessionWaitOutput = void + +export type ExperimentalSessionInstructionsEntryListInput = { readonly sessionID: string } + +export type ExperimentalSessionInstructionsEntryListOutput = { data: Array }["data"] + +export type ExperimentalSessionInstructionsEntryPutInput = { + readonly sessionID: string + readonly key: string + readonly value: JsonValue +} + +export type ExperimentalSessionInstructionsEntryPutOutput = void + +export type ExperimentalSessionInstructionsEntryRemoveInput = { readonly sessionID: string; readonly key: string } + +export type ExperimentalSessionInstructionsEntryRemoveOutput = void + +export type ExperimentalSessionLogInput = { + readonly sessionID: string + readonly after?: number | undefined + readonly follow?: boolean | undefined +} + +export type ExperimentalSessionLogOutput = SessionLogItem + export type MessageListInput = { readonly sessionID: string readonly limit?: number | undefined @@ -3743,14 +3743,14 @@ export type ModelDefaultInput = { readonly location?: { readonly directory?: str export type ModelDefaultOutput = { location: LocationPublicRef; data: ModelInfo | null } -export type GenerateTextInput = { +export type ExperimentalGenerateTextInput = { readonly prompt: string readonly model?: { readonly id: string; readonly providerID: string; readonly variant?: string } | null | undefined } -export type GenerateTextOutput = GenerateTextResponse["data"] +export type ExperimentalGenerateTextOutput = GenerateTextResponse["data"] -export type GenerateImageInput = { +export type ExperimentalGenerateImageInput = { readonly model: { readonly id: string; readonly providerID: string; readonly variant?: string } readonly prompt: string readonly images?: ReadonlyArray<{ readonly data: string; readonly mime: string; readonly name?: string }> | undefined @@ -3759,9 +3759,9 @@ export type GenerateImageInput = { readonly resolution?: ("1K" | "2K" | "4K" | (string & {})) | undefined } -export type GenerateImageOutput = GenerateImageResponse["data"] +export type ExperimentalGenerateImageOutput = GenerateImageResponse["data"] -export type GenerateDecisionsInput = { +export type ExperimentalGenerateDecisionsInput = { readonly model: { readonly id: string; readonly providerID: string; readonly variant?: string } readonly input: ReadonlyArray< | { readonly type: "text"; readonly text: string } @@ -3785,11 +3785,11 @@ export type GenerateDecisionsInput = { > } -export type GenerateDecisionsOutput = GenerateDecisionsResponse["data"] +export type ExperimentalGenerateDecisionsOutput = GenerateDecisionsResponse["data"] -export type VoiceModelsOutput = VoiceModelsResponse["data"] +export type ExperimentalVoiceModelsOutput = VoiceModelsResponse["data"] -export type VoiceSessionInput = { +export type ExperimentalVoiceSessionInput = { readonly model: string readonly session?: { readonly [x: string]: unknown } | undefined readonly transport: @@ -3797,7 +3797,7 @@ export type VoiceSessionInput = { | { readonly type: "websocket" } } -export type VoiceSessionOutput = VoiceSessionResponse["data"] +export type ExperimentalVoiceSessionOutput = VoiceSessionResponse["data"] export type ProviderListInput = { readonly location?: { readonly directory?: string | undefined } | undefined } @@ -3821,13 +3821,6 @@ export type IntegrationGetInput = { export type IntegrationGetOutput = { location: LocationPublicRef; data: IntegrationInfo } -export type IntegrationWellknownAddInput = { - readonly location?: { readonly directory?: string | undefined } | undefined - readonly url: string -} - -export type IntegrationWellknownAddOutput = void - export type IntegrationConnectKeyInput = { readonly integrationID: string readonly location?: { readonly directory?: string | undefined } | undefined @@ -3908,11 +3901,22 @@ export type IntegrationCommandCancelInput = { export type IntegrationCommandCancelOutput = void +export type ExperimentalIntegrationWellknownAddInput = { + readonly location?: { readonly directory?: string | undefined } | undefined + readonly url: string +} + +export type ExperimentalIntegrationWellknownAddOutput = void + export type McpListInput = { readonly location?: { readonly directory?: string | undefined } | undefined } export type McpListOutput = { location: LocationPublicRef; data: Array } -export type McpAddInput = { +export type McpResourceCatalogInput = { readonly location?: { readonly directory?: string | undefined } | undefined } + +export type McpResourceCatalogOutput = { location: LocationPublicRef; data: McpResourceCatalog } + +export type ExperimentalMcpAddInput = { readonly server: string readonly location?: { readonly directory?: string | undefined } | undefined readonly config: @@ -3947,40 +3951,36 @@ export type McpAddInput = { } } -export type McpAddOutput = void +export type ExperimentalMcpAddOutput = void -export type McpRemoveInput = { +export type ExperimentalMcpRemoveInput = { readonly server: string readonly location?: { readonly directory?: string | undefined } | undefined } -export type McpRemoveOutput = void +export type ExperimentalMcpRemoveOutput = void -export type McpConnectInput = { +export type ExperimentalMcpConnectInput = { readonly server: string readonly location?: { readonly directory?: string | undefined } | undefined } -export type McpConnectOutput = void +export type ExperimentalMcpConnectOutput = void -export type McpDisconnectInput = { +export type ExperimentalMcpDisconnectInput = { readonly server: string readonly location?: { readonly directory?: string | undefined } | undefined } -export type McpDisconnectOutput = void +export type ExperimentalMcpDisconnectOutput = void -export type McpResourceCatalogInput = { readonly location?: { readonly directory?: string | undefined } | undefined } - -export type McpResourceCatalogOutput = { location: LocationPublicRef; data: McpResourceCatalog } - -export type McpClientTokenInput = { +export type ExperimentalMcpClientTokenInput = { readonly location?: { readonly directory?: string | undefined } | undefined readonly name: string readonly "x-opencode-ticket"?: string | undefined } -export type McpClientTokenOutput = { location: LocationPublicRef; data: PtyTicketConnectToken } +export type ExperimentalMcpClientTokenOutput = { location: LocationPublicRef; data: PtyTicketConnectToken } export type CredentialListOutput = { data: Array }["data"] @@ -4107,27 +4107,27 @@ export type FileFindInput = { export type FileFindOutput = { location: LocationPublicRef; data: Array } -export type FileWriteInput = { +export type ExperimentalFileWriteInput = { readonly location?: { readonly directory?: string | undefined } | undefined readonly path: string readonly payload: globalThis.Uint8Array } -export type FileWriteOutput = { location: LocationPublicRef; data: FileSystemWrite } +export type ExperimentalFileWriteOutput = { location: LocationPublicRef; data: FileSystemWrite } -export type FileWatchInput = { +export type ExperimentalFileWatchInput = { readonly location?: { readonly directory?: string | undefined } | undefined readonly path: string } -export type FileWatchOutput = void +export type ExperimentalFileWatchOutput = void -export type FileUnwatchInput = { +export type ExperimentalFileUnwatchInput = { readonly location?: { readonly directory?: string | undefined } | undefined readonly path: string } -export type FileUnwatchOutput = void +export type ExperimentalFileUnwatchOutput = void export type CommandListInput = { readonly location?: { readonly directory?: string | undefined } | undefined } @@ -4468,7 +4468,7 @@ export type DebugLocationEvictInput = { readonly location?: { readonly directory export type DebugLocationEvictOutput = void -export type MigrationV1StatusOutput = +export type ExperimentalMigrationV1StatusOutput = | { status: "required" | "completed" } | { status: "running"; progress: { label: string; numerator?: number | undefined; denominator?: number | undefined } } | { status: "error"; error: string } @@ -4488,9 +4488,11 @@ export type WebsearchQueryOutput = { data: { providerID: WebSearchID; results: Array } } -export type UsageLimitsInput = { readonly location?: { readonly directory?: string | undefined } | undefined } +export type ExperimentalUsageLimitsInput = { + readonly location?: { readonly directory?: string | undefined } | undefined +} -export type UsageLimitsOutput = { location: LocationPublicRef; data: UsageLimitsInfo | null } +export type ExperimentalUsageLimitsOutput = { location: LocationPublicRef; data: UsageLimitsInfo | null } export type ConfigGetInput = { readonly location?: { readonly directory?: string | undefined } | undefined } @@ -4498,6 +4500,156 @@ export type ConfigGetOutput = Array export type ConfigShellsOutput = Array -export type ConfigUpdateInput = { readonly shell: string | null } +export type ExperimentalConfigUpdateInput = { readonly shell: string | null } -export type ConfigUpdateOutput = void +export type ExperimentalConfigUpdateOutput = void + +/** @deprecated Use `ExperimentalSessionStatsInput`. Removed in the next minor. */ +export type SessionStatsInput = ExperimentalSessionStatsInput + +/** @deprecated Use `ExperimentalSessionStatsOutput`. Removed in the next minor. */ +export type SessionStatsOutput = ExperimentalSessionStatsOutput + +/** @deprecated Use `ExperimentalSessionImportInput`. Removed in the next minor. */ +export type SessionImportInput = ExperimentalSessionImportInput + +/** @deprecated Use `ExperimentalSessionImportOutput`. Removed in the next minor. */ +export type SessionImportOutput = ExperimentalSessionImportOutput + +/** @deprecated Use `ExperimentalSessionExportInput`. Removed in the next minor. */ +export type SessionExportInput = ExperimentalSessionExportInput + +/** @deprecated Use `ExperimentalSessionExportOutput`. Removed in the next minor. */ +export type SessionExportOutput = ExperimentalSessionExportOutput + +/** @deprecated Use `ExperimentalSessionSkillInput`. Removed in the next minor. */ +export type SessionSkillInput = ExperimentalSessionSkillInput + +/** @deprecated Use `ExperimentalSessionSkillOutput`. Removed in the next minor. */ +export type SessionSkillOutput = ExperimentalSessionSkillOutput + +/** @deprecated Use `ExperimentalSessionWaitInput`. Removed in the next minor. */ +export type SessionWaitInput = ExperimentalSessionWaitInput + +/** @deprecated Use `ExperimentalSessionWaitOutput`. Removed in the next minor. */ +export type SessionWaitOutput = ExperimentalSessionWaitOutput + +/** @deprecated Use `ExperimentalSessionInstructionsEntryListInput`. Removed in the next minor. */ +export type SessionInstructionsEntryListInput = ExperimentalSessionInstructionsEntryListInput + +/** @deprecated Use `ExperimentalSessionInstructionsEntryListOutput`. Removed in the next minor. */ +export type SessionInstructionsEntryListOutput = ExperimentalSessionInstructionsEntryListOutput + +/** @deprecated Use `ExperimentalSessionInstructionsEntryPutInput`. Removed in the next minor. */ +export type SessionInstructionsEntryPutInput = ExperimentalSessionInstructionsEntryPutInput + +/** @deprecated Use `ExperimentalSessionInstructionsEntryPutOutput`. Removed in the next minor. */ +export type SessionInstructionsEntryPutOutput = ExperimentalSessionInstructionsEntryPutOutput + +/** @deprecated Use `ExperimentalSessionInstructionsEntryRemoveInput`. Removed in the next minor. */ +export type SessionInstructionsEntryRemoveInput = ExperimentalSessionInstructionsEntryRemoveInput + +/** @deprecated Use `ExperimentalSessionInstructionsEntryRemoveOutput`. Removed in the next minor. */ +export type SessionInstructionsEntryRemoveOutput = ExperimentalSessionInstructionsEntryRemoveOutput + +/** @deprecated Use `ExperimentalSessionLogInput`. Removed in the next minor. */ +export type SessionLogInput = ExperimentalSessionLogInput + +/** @deprecated Use `ExperimentalSessionLogOutput`. Removed in the next minor. */ +export type SessionLogOutput = ExperimentalSessionLogOutput + +/** @deprecated Use `ExperimentalGenerateTextInput`. Removed in the next minor. */ +export type GenerateTextInput = ExperimentalGenerateTextInput + +/** @deprecated Use `ExperimentalGenerateTextOutput`. Removed in the next minor. */ +export type GenerateTextOutput = ExperimentalGenerateTextOutput + +/** @deprecated Use `ExperimentalGenerateImageInput`. Removed in the next minor. */ +export type GenerateImageInput = ExperimentalGenerateImageInput + +/** @deprecated Use `ExperimentalGenerateImageOutput`. Removed in the next minor. */ +export type GenerateImageOutput = ExperimentalGenerateImageOutput + +/** @deprecated Use `ExperimentalGenerateDecisionsInput`. Removed in the next minor. */ +export type GenerateDecisionsInput = ExperimentalGenerateDecisionsInput + +/** @deprecated Use `ExperimentalGenerateDecisionsOutput`. Removed in the next minor. */ +export type GenerateDecisionsOutput = ExperimentalGenerateDecisionsOutput + +/** @deprecated Use `ExperimentalVoiceModelsOutput`. Removed in the next minor. */ +export type VoiceModelsOutput = ExperimentalVoiceModelsOutput + +/** @deprecated Use `ExperimentalVoiceSessionInput`. Removed in the next minor. */ +export type VoiceSessionInput = ExperimentalVoiceSessionInput + +/** @deprecated Use `ExperimentalVoiceSessionOutput`. Removed in the next minor. */ +export type VoiceSessionOutput = ExperimentalVoiceSessionOutput + +/** @deprecated Use `ExperimentalIntegrationWellknownAddInput`. Removed in the next minor. */ +export type IntegrationWellknownAddInput = ExperimentalIntegrationWellknownAddInput + +/** @deprecated Use `ExperimentalIntegrationWellknownAddOutput`. Removed in the next minor. */ +export type IntegrationWellknownAddOutput = ExperimentalIntegrationWellknownAddOutput + +/** @deprecated Use `ExperimentalMcpAddInput`. Removed in the next minor. */ +export type McpAddInput = ExperimentalMcpAddInput + +/** @deprecated Use `ExperimentalMcpAddOutput`. Removed in the next minor. */ +export type McpAddOutput = ExperimentalMcpAddOutput + +/** @deprecated Use `ExperimentalMcpRemoveInput`. Removed in the next minor. */ +export type McpRemoveInput = ExperimentalMcpRemoveInput + +/** @deprecated Use `ExperimentalMcpRemoveOutput`. Removed in the next minor. */ +export type McpRemoveOutput = ExperimentalMcpRemoveOutput + +/** @deprecated Use `ExperimentalMcpConnectInput`. Removed in the next minor. */ +export type McpConnectInput = ExperimentalMcpConnectInput + +/** @deprecated Use `ExperimentalMcpConnectOutput`. Removed in the next minor. */ +export type McpConnectOutput = ExperimentalMcpConnectOutput + +/** @deprecated Use `ExperimentalMcpDisconnectInput`. Removed in the next minor. */ +export type McpDisconnectInput = ExperimentalMcpDisconnectInput + +/** @deprecated Use `ExperimentalMcpDisconnectOutput`. Removed in the next minor. */ +export type McpDisconnectOutput = ExperimentalMcpDisconnectOutput + +/** @deprecated Use `ExperimentalMcpClientTokenInput`. Removed in the next minor. */ +export type McpClientTokenInput = ExperimentalMcpClientTokenInput + +/** @deprecated Use `ExperimentalMcpClientTokenOutput`. Removed in the next minor. */ +export type McpClientTokenOutput = ExperimentalMcpClientTokenOutput + +/** @deprecated Use `ExperimentalFileWriteInput`. Removed in the next minor. */ +export type FileWriteInput = ExperimentalFileWriteInput + +/** @deprecated Use `ExperimentalFileWriteOutput`. Removed in the next minor. */ +export type FileWriteOutput = ExperimentalFileWriteOutput + +/** @deprecated Use `ExperimentalFileWatchInput`. Removed in the next minor. */ +export type FileWatchInput = ExperimentalFileWatchInput + +/** @deprecated Use `ExperimentalFileWatchOutput`. Removed in the next minor. */ +export type FileWatchOutput = ExperimentalFileWatchOutput + +/** @deprecated Use `ExperimentalFileUnwatchInput`. Removed in the next minor. */ +export type FileUnwatchInput = ExperimentalFileUnwatchInput + +/** @deprecated Use `ExperimentalFileUnwatchOutput`. Removed in the next minor. */ +export type FileUnwatchOutput = ExperimentalFileUnwatchOutput + +/** @deprecated Use `ExperimentalMigrationV1StatusOutput`. Removed in the next minor. */ +export type MigrationV1StatusOutput = ExperimentalMigrationV1StatusOutput + +/** @deprecated Use `ExperimentalUsageLimitsInput`. Removed in the next minor. */ +export type UsageLimitsInput = ExperimentalUsageLimitsInput + +/** @deprecated Use `ExperimentalUsageLimitsOutput`. Removed in the next minor. */ +export type UsageLimitsOutput = ExperimentalUsageLimitsOutput + +/** @deprecated Use `ExperimentalConfigUpdateInput`. Removed in the next minor. */ +export type ConfigUpdateInput = ExperimentalConfigUpdateInput + +/** @deprecated Use `ExperimentalConfigUpdateOutput`. Removed in the next minor. */ +export type ConfigUpdateOutput = ExperimentalConfigUpdateOutput diff --git a/packages/client/src/solid/data.ts b/packages/client/src/solid/data.ts index 21dbb7ca73b..8bbcf9525a6 100644 --- a/packages/client/src/solid/data.ts +++ b/packages/client/src/solid/data.ts @@ -1433,7 +1433,7 @@ export function createData(config: CreateDataInput) { } const vcs = locationResource("vcs", (location) => api().vcs.get({ location })) - const usageLimits = locationResource("usageLimits", (location) => api().usage.limits({ location })) + const usageLimits = locationResource("usageLimits", (location) => api().experimental.usage.limits({ location })) const shells = locationResource("shell", async (location) => { const response = await api().shell.list({ location }) const ref = { directory: response.location.directory } diff --git a/packages/client/test/api.types.ts b/packages/client/test/api.types.ts index 02533630fed..93aad966fe0 100644 --- a/packages/client/test/api.types.ts +++ b/packages/client/test/api.types.ts @@ -18,30 +18,30 @@ const effectSession: Effect.Effect = effectClient.session sessionID: "ses_test" as Session.ID, }) -declare const sessionID: Parameters[0]["sessionID"] +declare const sessionID: Parameters[0]["sessionID"] const effectList: Effect.Effect< ReadonlyArray<{ readonly key: string; readonly value: unknown }>, unknown -> = effectApi.session.instructions.entry.list({ sessionID }) -const effectPut: Effect.Effect = effectApi.session.instructions.entry.put({ +> = effectApi.experimental.session.instructions.entry.list({ sessionID }) +const effectPut: Effect.Effect = effectApi.experimental.session.instructions.entry.put({ sessionID, key: "review-notes", value: { text: "Check the diff" }, }) -const effectRemove: Effect.Effect = effectApi.session.instructions.entry.remove({ +const effectRemove: Effect.Effect = effectApi.experimental.session.instructions.entry.remove({ sessionID, key: "review-notes", }) const promiseList: Promise> = - promiseClient.session.instructions.entry.list({ sessionID: "ses_test" }) -const promisePut: Promise = promiseClient.session.instructions.entry.put({ + promiseClient.experimental.session.instructions.entry.list({ sessionID: "ses_test" }) +const promisePut: Promise = promiseClient.experimental.session.instructions.entry.put({ sessionID: "ses_test", key: "review-notes", value: { text: "Check the diff" }, }) -const promiseRemove: Promise = promiseClient.session.instructions.entry.remove({ +const promiseRemove: Promise = promiseClient.experimental.session.instructions.entry.remove({ sessionID: "ses_test", key: "review-notes", }) diff --git a/packages/client/test/deprecated-aliases.test.ts b/packages/client/test/deprecated-aliases.test.ts new file mode 100644 index 00000000000..465e8c1aa68 --- /dev/null +++ b/packages/client/test/deprecated-aliases.test.ts @@ -0,0 +1,45 @@ +import { expect, test } from "bun:test" +import { compile } from "@opencode/httpapi-codegen" +import { + ClientApi, + clientNamespace, + effectOmitEndpoints, + groupNames, + promiseOmitEndpoints, +} from "@opencode/protocol/client" +import { Effect } from "effect" +import { HttpClient } from "effect/http" +import { OpenCode as EffectOpenCode } from "../src/effect/index" +import { OpenCode as PromiseOpenCode } from "../src/promise/index" + +// The pre-experimental paths stay until the next minor. +const aliases = (omitEndpoints: ReadonlySet) => + compile(ClientApi, { groupNames, omitEndpoints, namespace: clientNamespace, aliases: true }).aliases ?? [] + +const at = (root: unknown, path: ReadonlyArray) => + path.reduce((parent, key) => (parent as Record | undefined)?.[key], root) + +const expectSameFunctions = (client: unknown, list: ReturnType) => { + expect(list.length).toBeGreaterThan(20) + for (const alias of list) { + expect(alias.to[0]).toBe("experimental") + const target = at(client, alias.to) + expect(target).toBeFunction() + expect(at(client, alias.from)).toBe(target) + } +} + +test("every Promise client alias is the same function as its client.experimental path", () => { + expectSameFunctions(PromiseOpenCode.make({ baseUrl: "http://localhost:3000" }), aliases(promiseOmitEndpoints)) +}) + +test("every Effect client alias is the same function as its client.experimental path", async () => { + const client = await EffectOpenCode.make({ baseUrl: "http://localhost:3000" }).pipe( + Effect.provideService( + HttpClient.HttpClient, + HttpClient.make(() => Effect.die("unused")), + ), + Effect.runPromise, + ) + expectSameFunctions(client, aliases(effectOmitEndpoints)) +}) diff --git a/packages/client/test/effect.test.ts b/packages/client/test/effect.test.ts index b1c1d156847..cc132f4e770 100644 --- a/packages/client/test/effect.test.ts +++ b/packages/client/test/effect.test.ts @@ -92,13 +92,15 @@ test("session instructions methods use the public HTTP contract", async () => { }) const result = await Effect.gen(function* () { const client = yield* OpenCode.make({ baseUrl: "http://localhost:3000" }) - const listed = yield* client.session.instructions.entry.list({ sessionID: Session.ID.make("ses_test") }) - yield* client.session.instructions.entry.put({ + const listed = yield* client.experimental.session.instructions.entry.list({ + sessionID: Session.ID.make("ses_test"), + }) + yield* client.experimental.session.instructions.entry.put({ sessionID: Session.ID.make("ses_test"), key: "review-notes", value: instructions[0].value, }) - yield* client.session.instructions.entry.remove({ + yield* client.experimental.session.instructions.entry.remove({ sessionID: Session.ID.make("ses_test"), key: "review-notes", }) @@ -264,9 +266,9 @@ test("session methods retain decoded Effect inputs and outputs", async () => { resume: false, }) yield* client.session.compact({ sessionID: Session.ID.make("ses_test") }) - yield* client.session.wait({ sessionID: Session.ID.make("ses_test") }) + yield* client.experimental.session.wait({ sessionID: Session.ID.make("ses_test") }) const context = yield* client.session.context({ sessionID: Session.ID.make("ses_test") }) - const log = yield* client.session + const log = yield* client.experimental.session .log({ sessionID: Session.ID.make("ses_test"), after: Event.Seq.make(0) }) .pipe(Stream.runCollect) const interrupted = yield* client.session.interrupt({ sessionID: Session.ID.make("ses_test") }) @@ -314,7 +316,9 @@ test("session.log retains the typed SessionNotFoundError", async () => { ) const error = await Effect.gen(function* () { const client = yield* OpenCode.make({ baseUrl: "http://localhost:3000" }) - return yield* client.session.log({ sessionID: Session.ID.make("ses_missing") }).pipe(Stream.runCollect, Effect.flip) + return yield* client.experimental.session + .log({ sessionID: Session.ID.make("ses_missing") }) + .pipe(Stream.runCollect, Effect.flip) }).pipe(Effect.provideService(HttpClient.HttpClient, httpClient), Effect.runPromise) expect(error._tag).toBe("SessionNotFoundError") diff --git a/packages/client/test/promise.test.ts b/packages/client/test/promise.test.ts index f2f9255da01..313272efcb5 100644 --- a/packages/client/test/promise.test.ts +++ b/packages/client/test/promise.test.ts @@ -10,10 +10,9 @@ test("exposes every standard HTTP API group", () => { "agent", "plugin", "session", + "experimental", "message", "model", - "generate", - "voice", "provider", "integration", "mcp", @@ -27,35 +26,144 @@ test("exposes every standard HTTP API group", () => { "rpc", "event", "pty", - "experimental", "shell", "reference", "worktree", "vcs", "debug", - "migration", "websearch", - "usage", "config", + "generate", + "voice", + "migration", + "usage", ]) expect(Object.keys(client.debug)).toEqual(["heapDump", "location"]) expect(Object.keys(client.debug.location)).toEqual(["list", "evict"]) expect(Object.keys(client.message)).toEqual(["list"]) - expect(Object.keys(client.integration)).toEqual(["list", "get", "wellknown", "connect", "oauth", "command"]) - expect(Object.keys(client.integration.wellknown)).toEqual(["add"]) + expect(Object.keys(client.integration)).toEqual(["list", "get", "connect", "oauth", "command", "wellknown"]) expect(Object.keys(client.integration.connect)).toEqual(["key", "external"]) expect(Object.keys(client.integration.oauth)).toEqual(["connect", "status", "complete", "cancel"]) expect(Object.keys(client.integration.command)).toEqual(["connect", "status", "cancel"]) expect(Object.keys(client.websearch)).toEqual(["providers", "query"]) - expect(Object.keys(client.voice)).toEqual(["models", "session"]) - expect(Object.keys(client.usage)).toEqual(["limits"]) expect(Object.keys(client.file)).toEqual(["read", "list", "find", "write", "watch", "unwatch"]) + expect(Object.keys(client.mcp)).toEqual(["list", "resource", "add", "remove", "connect", "disconnect", "client"]) + expect(Object.keys(client.config)).toEqual(["get", "shells", "update"]) expect(Object.keys(client.vcs)).toEqual(["init", "get", "base", "status", "branch", "diff"]) expect(Object.keys(client.pty)).toEqual(["list", "create", "get", "update", "remove", "connect"]) expect(Object.keys(client.pty.connect)).toEqual(["token"]) - expect(Object.keys(client.experimental).sort()).toEqual(["media", "persistentPty"]) + expect(Object.keys(client.experimental)).toEqual([ + "session", + "generate", + "voice", + "integration", + "mcp", + "file", + "persistentPty", + "media", + "migration", + "usage", + "config", + ]) + expect(Object.keys(client.experimental.session)).toEqual([ + "stats", + "import", + "export", + "skill", + "wait", + "instructions", + "log", + ]) + expect(Object.keys(client.experimental.voice)).toEqual(["models", "session"]) + expect(Object.keys(client.experimental.usage)).toEqual(["limits"]) + expect(Object.keys(client.experimental.mcp)).toEqual(["add", "remove", "connect", "disconnect", "client"]) + expect(Object.keys(client.experimental.integration.wellknown)).toEqual(["add"]) + expect(Object.keys(client.experimental.file)).toEqual(["write", "watch", "unwatch"]) expect(Object.keys(client.experimental.media)).toEqual(["get"]) expect(client.experimental.persistentPty.read).toBeFunction() +}) + +test("nests a method under client.experimental exactly when its route is experimental", async () => { + let url: URL | undefined + const client = OpenCode.make({ + baseUrl: "http://localhost:3000", + fetch: async (input) => { + url = new URL(input instanceof Request ? input.url : String(input)) + throw new Error("captured") + }, + }) + // Every field reads as "x" so path params resolve; request options stay unset. + const input = new Proxy( + {}, + { get: (_target, key) => (key === "signal" || key === "headers" || key === "onActivity" ? undefined : "x") }, + ) + const routes: Array<{ readonly method: string; readonly experimentalRoute: boolean }> = [] + const deprecated: Array = [] + const visit = async (node: object, path: ReadonlyArray): Promise => { + for (const [name, value] of Object.entries(node)) { + // `rpc` is a callable that also carries its generated routes. + if (typeof value !== "function" || Object.keys(value).length > 0) { + await visit(value, [...path, name]) + continue + } + const target = [...path, name].reduce( + (parent, key) => (parent as Record | undefined)?.[key], + client.experimental, + ) + if (path[0] !== "experimental" && target === value) { + deprecated.push([...path, name].join(".")) + continue + } + url = undefined + const result: unknown = value(input) + if (typeof result === "object" && result !== null && Symbol.asyncIterator in result) { + await (result as AsyncIterable) + [Symbol.asyncIterator]() + .next() + .catch(() => undefined) + } else await Promise.resolve(result).catch(() => undefined) + const method = [...path, name].join(".") + if (url === undefined) throw new Error(`${method} did not send a request`) + routes.push({ method, experimentalRoute: url.pathname.startsWith("/api/experimental/") }) + } + } + await visit(client, []) + + expect(routes.filter((route) => route.experimentalRoute).length).toBeGreaterThan(20) + expect( + routes + .filter((route) => route.experimentalRoute !== route.method.startsWith("experimental.")) + .map((route) => route.method), + ).toEqual([]) + // Pre-experimental paths kept as deprecated aliases until the next minor. + expect(deprecated.toSorted()).toEqual([ + "config.update", + "file.unwatch", + "file.watch", + "file.write", + "generate.decisions", + "generate.image", + "generate.text", + "integration.wellknown.add", + "mcp.add", + "mcp.client.token", + "mcp.connect", + "mcp.disconnect", + "mcp.remove", + "migration.v1.status", + "session.export", + "session.import", + "session.instructions.entry.list", + "session.instructions.entry.put", + "session.instructions.entry.remove", + "session.log", + "session.skill", + "session.stats", + "session.wait", + "usage.limits", + "voice.models", + "voice.session", + ]) expect(Object.keys(client.shell)).toEqual(["list", "create", "get", "output", "remove"]) expect(Object.keys(client.project)).toEqual(["list", "update"]) expect(Object.keys(client.worktree)).toEqual(["list", "create", "remove", "refresh"]) @@ -254,7 +362,7 @@ test("generate.text uses the locationless public contract", async () => { }, }) - expect(await client.generate.text({ prompt: "ping" })).toEqual({ text: "pong" }) + expect(await client.experimental.generate.text({ prompt: "ping" })).toEqual({ text: "pong" }) expect(request?.url).toBe("http://localhost:3000/api/experimental/generate/text") expect(await request?.json()).toEqual({ prompt: "ping" }) }) @@ -325,7 +433,7 @@ test("experimental wellknown integration add uses the public HTTP contract", asy }, }) - await client.integration.wellknown.add({ + await client.experimental.integration.wellknown.add({ url: "https://example.com", location: { directory: "/tmp/project" }, }) @@ -587,13 +695,13 @@ test("session instructions methods use the public HTTP contract", async () => { }, }) - const result = await client.session.instructions.entry.list({ sessionID: "ses_test" }) - await client.session.instructions.entry.put({ + const result = await client.experimental.session.instructions.entry.list({ sessionID: "ses_test" }) + await client.experimental.session.instructions.entry.put({ sessionID: "ses_test", key: "review-notes", value: instructions[0].value, }) - await client.session.instructions.entry.remove({ sessionID: "ses_test", key: "review-notes" }) + await client.experimental.session.instructions.entry.remove({ sessionID: "ses_test", key: "review-notes" }) expect(result).toEqual(instructions) expect(requests).toEqual([ @@ -972,10 +1080,10 @@ test("session methods use the public HTTP contract", async () => { resume: false, }) await client.session.compact({ sessionID: "ses_test" }) - await client.session.wait({ sessionID: "ses_test" }) + await client.experimental.session.wait({ sessionID: "ses_test" }) const context = await client.session.context({ sessionID: "ses_test" }) const log = [] - for await (const item of client.session.log({ sessionID: "ses_test", after: 0 })) log.push(item) + for await (const item of client.experimental.session.log({ sessionID: "ses_test", after: 0 })) log.push(item) const interrupted = await client.session.interrupt({ sessionID: "ses_test", resume: true }) const message = await client.session.message.get({ sessionID: "ses_test", messageID: "msg_model" }) @@ -1051,7 +1159,7 @@ test("session.log decodes SessionNotFoundError", async () => { }) try { - await client.session.log({ sessionID: "ses_missing" })[Symbol.asyncIterator]().next() + await client.experimental.session.log({ sessionID: "ses_missing" })[Symbol.asyncIterator]().next() throw new Error("Expected request to fail") } catch (error) { expect(isSessionNotFoundError(error)).toBe(true) diff --git a/packages/desktop/src/renderer/migration-status.tsx b/packages/desktop/src/renderer/migration-status.tsx index c14124a7035..35fa12539d0 100644 --- a/packages/desktop/src/renderer/migration-status.tsx +++ b/packages/desktop/src/renderer/migration-status.tsx @@ -1,11 +1,11 @@ -import { OpenCode, type MigrationV1StatusOutput } from "@opencode/client/promise" +import { OpenCode, type ExperimentalMigrationV1StatusOutput } from "@opencode/client/promise" import { useLanguage } from "@opencode/app/desktop" import { Loader } from "@opencode/ui/loader" import { showToast, toaster, Toast } from "@opencode/ui/toast" import { createRoot, createSignal, onCleanup, onMount } from "solid-js" import type { ServerReadyData } from "../shared/ipc-contract" -type Progress = Extract["progress"] +type Progress = Extract["progress"] export function MigrationStatus(props: { server: ServerReadyData }) { const language = useLanguage() @@ -87,7 +87,7 @@ export function MigrationStatus(props: { server: ServerReadyData }) { void (async () => { while (true) { - const status = await client.migration.v1.status({ signal: abort.signal }) + const status = await client.experimental.migration.v1.status({ signal: abort.signal }) setProgress(status.status === "running" ? status.progress : undefined) if (status.status === "running") show() diff --git a/packages/gui-plugins/src/details/server-panel.tsx b/packages/gui-plugins/src/details/server-panel.tsx index 513e891aa54..fcca9bd905e 100644 --- a/packages/gui-plugins/src/details/server-panel.tsx +++ b/packages/gui-plugins/src/details/server-panel.tsx @@ -1053,11 +1053,11 @@ function useMcpToggle(session: MountedSession, directory: () => string) { if (!server) return if (!input.enabled) { - await client.mcp.disconnect({ server: input.name, location: ref }) + await client.experimental.mcp.disconnect({ server: input.name, location: ref }) } if (input.enabled && server.status.status !== "needs_auth") { - await client.mcp.connect({ server: input.name, location: ref }) + await client.experimental.mcp.connect({ server: input.name, location: ref }) } source.location.mcp.server.invalidate(ref) diff --git a/packages/httpapi-codegen/src/index.ts b/packages/httpapi-codegen/src/index.ts index 3df97570fa3..44401be4761 100644 --- a/packages/httpapi-codegen/src/index.ts +++ b/packages/httpapi-codegen/src/index.ts @@ -33,6 +33,16 @@ export type Output = { export type Contract = { readonly groups: ReadonlyArray + readonly aliases?: ReadonlyArray +} + +/** A namespaced endpoint's pre-namespace client path and group, kept as a deprecated alias of its new location. */ +export type Alias = { + readonly from: ReadonlyArray + readonly to: ReadonlyArray + readonly fromGroup: string + readonly group: Group + readonly endpoint: Endpoint } export type EffectTypeReference = { @@ -61,6 +71,7 @@ export class GenerationError extends Schema.TaggedError()("Gene export type Endpoint = { readonly group: string + readonly groupPath: ReadonlyArray readonly sourceGroup: string readonly topLevel: boolean readonly endpoint: HttpApiEndpoint.Top @@ -79,6 +90,8 @@ export type Endpoint = { export type Group = { readonly identifier: string + /** Where the group's methods live on the client; empty for top-level groups outside a namespace. */ + readonly path: ReadonlyArray readonly sourceIdentifier: string readonly module: string readonly endpoints: ReadonlyArray @@ -103,16 +116,41 @@ export function compile> readonly omitEndpoints?: ReadonlySet + /** + * Nests an endpoint's group under a client namespace, so `client..` becomes + * `client...`. A group whose name equals the namespace is not repeated. + */ + readonly namespace?: (endpoint: HttpApiEndpoint.Top) => string | undefined + /** + * Keeps each namespaced endpoint's pre-namespace client path and generated type names as deprecated aliases of + * the namespaced ones, so moving an endpoint into a namespace does not break callers. + */ + readonly aliases?: boolean }, ): Contract { const endpoints: Array = [] const portable = new Map() + // Where each namespaced endpoint would sit without its namespace. + const unnamespaced = new Map }>() HttpApi.reflect(api, { onGroup() {}, onEndpoint({ endpoint, errors, group, middleware }) { if (options?.omitEndpoints?.has(endpoint.identifier)) return - const groupName = options?.groupNames?.[group.identifier] ?? group.identifier + const sourceName = options?.groupNames?.[group.identifier] ?? group.identifier + const namespace = options?.namespace?.(endpoint) + if (namespace === "" || namespace === "__proto__") { + throw new GenerationError({ reason: `Invalid client namespace: ${JSON.stringify(namespace)}` }) + } + const groupName = namespace === undefined || namespace === sourceName ? sourceName : `${namespace}.${sourceName}` + const groupPath = + namespace === undefined + ? group.topLevel + ? [] + : [sourceName] + : group.topLevel || namespace === sourceName + ? [namespace] + : [namespace, sourceName] const name = `${groupName}.${endpoint.identifier}` const required = Array.from(middleware).find((item) => item.requiredForClient) if (required !== undefined) { @@ -180,8 +218,9 @@ export function compile endpoint.sourceGroup)).size > 1) { throw new GenerationError({ reason: `Client group name collision: ${identifier}` }) } + const path = endpoints[0].groupPath + if (endpoints.some((endpoint) => endpoint.groupPath.join("\0") !== path.join("\0"))) { + throw new GenerationError({ reason: `Client group path conflict: ${identifier}` }) + } // Module names derive from the group identifier so unrelated groups never rename. const sanitized = identifier.replace(/[^A-Za-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") const reserved = /^(aux|client|client-error|con|index|nul|prn|com[1-9]|lpt[1-9])$/i.test(sanitized) @@ -234,10 +281,9 @@ export function compile() const groupTypeNames = new Set() const endpointTypeNames = new Set() const operationKeys = new Set() @@ -272,22 +318,50 @@ export function compile item.clientPath[0]))].map((name) => [name]) - : [[group.identifier]] - for (const path of paths) { - const key = path.join("\0") - for (const existing of publicNames) { - if (existing === key || existing.startsWith(`${key}\0`) || key.startsWith(`${existing}\0`)) { - throw new GenerationError({ reason: `Client name collision: ${path.join(".")}` }) - } + } + const visit = (node: GroupNode, path: ReadonlyArray) => { + const keys = new Set() + for (const entry of node.entries) { + const names = + typeof entry === "string" ? [entry] : [...new Set(entry.endpoints.map((item) => item.clientPath[0]))] + for (const name of names) { + if (keys.has(name)) throw new GenerationError({ reason: `Client name collision: ${[...path, name].join(".")}` }) + keys.add(name) } - publicNames.add(key) } + for (const [name, child] of node.children) visit(child, [...path, name]) } - return { - groups, + visit(groupTree(groups), []) + if (options?.aliases !== true) return { groups } + const aliases = groups.flatMap((group) => + group.endpoints.flatMap((endpoint): Array => { + const previous = unnamespaced.get(endpoint) + if (previous === undefined) return [] + return [ + { + from: [...previous.path, ...endpoint.clientPath], + to: [...group.path, ...endpoint.clientPath], + fromGroup: previous.group, + group, + endpoint, + }, + ] + }), + ) + const paths = groups.flatMap((group) => group.endpoints.map((endpoint) => [...group.path, ...endpoint.clientPath])) + for (const alias of aliases) { + const key = alias.from.join("\0") + const conflict = paths.some((path) => { + const other = path.join("\0") + return other === key || other.startsWith(`${key}\0`) || key.startsWith(`${other}\0`) + }) + if (conflict) throw new GenerationError({ reason: `Client alias collision: ${alias.from.join(".")}` }) } + assertUniqueClientPaths( + aliases.map((alias) => alias.from), + (path) => `Client alias collision: ${path.join(".")}`, + ) + return { groups, aliases } } export function emitEffect(contract: Contract): Output { @@ -297,7 +371,7 @@ export function emitEffect(contract: Contract): Output { reason: `Effect schema requires authoritative import: ${endpoint.group}.${endpoint.endpoint.identifier}`, }) } - return { operations: operations(contract.groups), files: renderEffectFiles(contract.groups) } + return { operations: operations(contract.groups), files: renderEffectFiles(contract.groups, contract.aliases ?? []) } } export function emitEffectImported( @@ -313,7 +387,7 @@ export function emitEffectImported( ): Output { return { operations: operations(contract.groups), - files: renderImportedEffectFiles(contract.groups, options), + files: renderImportedEffectFiles(contract.groups, contract.aliases ?? [], options), } } @@ -329,7 +403,12 @@ export function emitEffectShape( files: [ { path: "api.ts", - content: renderEffectShape(contract.groups, options?.typeReferences ?? [], options?.outputTypes), + content: renderEffectShape( + contract.groups, + options?.typeReferences ?? [], + options?.outputTypes, + contract.aliases ?? [], + ), }, ], } @@ -349,14 +428,17 @@ export function emitPromise( return { operations: promiseOperations(groups), files: [ - { path: "types.ts", content: renderPromiseTypes(groups, options?.outputTypes, options?.mutableOutputs ?? false) }, + { + path: "types.ts", + content: renderPromiseTypes(groups, options?.outputTypes, options?.mutableOutputs ?? false, contract.aliases), + }, { path: "client-error.ts", content: `export type ClientErrorReason = "Transport" | "UnexpectedStatus" | "UnsupportedContentType" | "MalformedResponse" | "SseEventTooLarge"\n\nexport class ClientError extends Error {\n override readonly name = "ClientError"\n constructor(readonly reason: ClientErrorReason, options?: ErrorOptions & { readonly detail?: string | null }) {\n const detail = options?.detail ?? (options?.cause instanceof Error ? options.cause.message : undefined)\n super(detail ? \`\${reason}: \${detail}\` : reason, options)\n }\n}\n`, }, { path: "client.ts", - content: normalizePromiseClientContent(renderPromiseClient(groups), groups), + content: normalizePromiseClientContent(renderPromiseClient(groups, contract.aliases), groups), }, { path: "index.ts", @@ -370,7 +452,8 @@ export function emitPromise( function renderEffectShape( groups: ReadonlyArray, typeReferences: ReadonlyArray, - outputTypes?: Readonly>, + outputTypes: Readonly> | undefined, + aliases: ReadonlyArray, ) { const references = effectTypeReferences(typeReferences) const imports = new Set() @@ -393,6 +476,64 @@ function renderEffectShape( if (collision !== undefined) { throw new GenerationError({ reason: `Generated Effect type collides with imported type: ${collision}` }) } + // An alias joins the interface of the deepest group above its old path, so code typed against that group keeps + // compiling; an alias with no such group becomes a field of AppApi. + type AliasField = { readonly path: ReadonlyArray; readonly value: string; readonly alias: Alias } + const groupAliases = new Map>() + const rootAliases: Array = [] + for (const alias of aliases) { + const value = `${groupShapeTypeName(alias.group, alias.endpoint)}` + const owner = groups + .filter( + (group) => + group.path.length > 0 && + group.path.length < alias.from.length && + group.path.every((name, index) => alias.from[index] === name), + ) + .toSorted((a, b) => b.path.length - a.path.length)[0] + if (owner === undefined) { + rootAliases.push({ path: alias.from, value, alias }) + continue + } + groupAliases.set(owner, [ + ...(groupAliases.get(owner) ?? []), + { path: alias.from.slice(owner.path.length), value, alias }, + ]) + } + const rootNames = new Set( + groups.flatMap((group) => group.endpoints.map((endpoint) => [...group.path, ...endpoint.clientPath][0])), + ) + const unowned = rootAliases.find((item) => rootNames.has(item.path[0])) + if (unowned !== undefined) { + throw new GenerationError({ reason: `Client alias has no group to join: ${unowned.alias.from.join(".")}` }) + } + const aliasTypes: Array<{ readonly name: string; readonly target: string; readonly generic?: true }> = + aliases.flatMap((alias) => { + const from = `${identifierPart(alias.fromGroup)}${alias.endpoint.clientPath.map(identifierPart).join("")}` + const to = endpointTypeName(alias.group, alias.endpoint) + return [ + ...(alias.endpoint.operation.inputMode === "none" ? [] : [{ name: `${from}Input`, target: `${to}Input` }]), + { name: `${from}Output`, target: `${to}Output` }, + { name: `${from}Operation`, target: `${to}Operation`, generic: true as const }, + ] + }) + // A group whose endpoints all moved into one group keeps its interface name as an alias of that group's. + for (const fromGroup of new Set(aliases.map((alias) => alias.fromGroup))) { + if (groups.some((group) => group.identifier === fromGroup)) continue + const moved = aliases.filter((alias) => alias.fromGroup === fromGroup) + const target = moved[0].group + if (moved.some((alias) => alias.group !== target) || moved.length !== target.endpoints.length) continue + aliasTypes.push({ name: `${identifierPart(fromGroup)}Api`, target: groupShapeName(target), generic: true }) + } + const takenNames = new Set([...externalNames, ...generatedNames]) + for (const { name } of aliasTypes) { + if (takenNames.has(name)) throw new GenerationError({ reason: `Client type alias collision: ${name}` }) + takenNames.add(name) + } + const renderedAliasTypes = aliasTypes.map( + (item) => + `${deprecatedTypeAliasDoc(item.target)}\nexport type ${item.name}${item.generic ? "" : ""} = ${item.target}${item.generic ? "" : ""}`, + ) const endpointTypes = groups.map((group) => { const endpoints = group.endpoints.map((endpoint) => { const prefix = endpointTypeName(group, endpoint) @@ -425,29 +566,42 @@ function renderEffectShape( (endpoint) => `${groupShapeTypeName(group, endpoint)}`, (name, value) => `readonly ${JSON.stringify(name)}: ${value}`, "\n", + groupAliases.get(group), ) return `${endpoints.join("\n\n")}\n\nexport interface ${groupShapeName(group)} {\n${methods}\n}` }) - const clientFields = groups.flatMap((group) => - group.endpoints[0]?.topLevel - ? [ - renderClientTree( - group.endpoints, - (endpoint) => `${groupShapeTypeName(group, endpoint)}`, - (name, value) => `readonly ${JSON.stringify(name)}: ${value}`, - "\n", - ), - ] - : [`readonly ${JSON.stringify(group.identifier)}: ${groupShapeName(group)}`], + const clientFields = renderGroupTree( + groups, + (group) => + group.endpoints[0]?.topLevel + ? { + fields: renderClientTree( + group.endpoints, + (endpoint) => `${groupShapeTypeName(group, endpoint)}`, + (name, value) => `readonly ${JSON.stringify(name)}: ${value}`, + "\n", + ), + } + : { whole: `${groupShapeName(group)}` }, + (name, value) => `readonly ${JSON.stringify(name)}: ${value}`, + (wholes, fields) => [...wholes, ...(fields.length === 0 ? [] : [`{\n${fields.join("\n")}\n}`])].join(" & "), + "\n", + ) + const rootAliasFields = renderClientTree( + [], + () => "", + (name, value) => `readonly ${JSON.stringify(name)}: ${value}`, + "\n", + rootAliases, ) return `// Generated by @opencode/httpapi-codegen. Do not edit. import type { Effect, Stream } from "effect" ${[...imports].join("\n")} -${endpointTypes.join("\n\n")} +${[...endpointTypes, ...renderedAliasTypes].join("\n\n")} export interface AppApi { -${clientFields.join("\n")} +${[clientFields, rootAliasFields].filter(Boolean).join("\n")} } ` } @@ -622,7 +776,7 @@ function promiseOperations(groups: ReadonlyArray) { ) } -function renderEffectFiles(groups: ReadonlyArray): Output["files"] { +function renderEffectFiles(groups: ReadonlyArray, aliases: ReadonlyArray): Output["files"] { return [ ...groups.map((group) => ({ path: `${group.module}.ts`, content: renderGroup(group) })), { @@ -630,7 +784,7 @@ function renderEffectFiles(groups: ReadonlyArray): Output["files"] { content: 'import { Schema } from "effect"\n\nexport class ClientError extends Schema.TaggedError()("ClientError", {\n cause: Schema.Defect(),\n}) {}\n', }, - { path: "client.ts", content: renderClient(groups) }, + { path: "client.ts", content: renderClient(groups, aliases) }, { path: "index.ts", content: 'export { ClientError } from "./client-error.js"\nexport * as OpenCode from "./client.js"\n', @@ -640,6 +794,7 @@ function renderEffectFiles(groups: ReadonlyArray): Output["files"] { function renderImportedEffectFiles( groups: ReadonlyArray, + aliases: ReadonlyArray, options: | { readonly module: string; readonly api: string; readonly shapeModule?: string } | { readonly module: string; readonly group: string; readonly shapeModule?: string } @@ -649,8 +804,10 @@ function renderImportedEffectFiles( readonly shapeModule?: string }, ): Output["files"] { + // An imported Api or group keeps its source group names; a projection rebuilds groups under their client names. + const rawKey = (group: Group) => JSON.stringify("endpoints" in options ? group.identifier : group.sourceIdentifier) const adapters = groups.map((group) => { - const rawGroup = group.endpoints[0]?.topLevel ? "RawClient" : `RawClient[${JSON.stringify(group.sourceIdentifier)}]` + const rawGroup = group.endpoints[0]?.topLevel ? "RawClient" : `RawClient[${rawKey(group)}]` const methods = group.endpoints.map((item) => { const prefix = endpointTypeName(group, item) const adapter = endpointAdapterName(group, item) @@ -710,12 +867,15 @@ function renderImportedEffectFiles( ) return `${methods.join("\n\n")}\n\nconst adaptGroup${groupTypeName(group)} = (raw: ${rawGroup}) => ({ ${fields} })` }) - const fields = groups.flatMap((group) => - group.endpoints[0]?.topLevel - ? [`...adaptGroup${groupTypeName(group)}(raw)`] - : [ - `${JSON.stringify(group.identifier)}: adaptGroup${groupTypeName(group)}(raw[${JSON.stringify(group.sourceIdentifier)}])`, - ], + const fields = renderGroupTree( + groups, + (group) => + group.endpoints[0]?.topLevel + ? { fields: `...adaptGroup${groupTypeName(group)}(raw)` } + : { whole: `adaptGroup${groupTypeName(group)}(raw[${rawKey(group)}])` }, + (name, value) => `${JSON.stringify(name)}: ${value}`, + spreadObject, + ", ", ) const usesStream = groups.some((group) => group.endpoints.some((item) => item.operation.success === "stream")) const imported = "api" in options @@ -753,7 +913,7 @@ function renderImportedEffectFiles( options.shapeModule === undefined ? "" : `const preserveEffect = () => (effect: Effect.Effect & ([A] extends [Actual] ? unknown : { readonly __generatedOutputWiderThanContract: [expected: Actual, generated: A] })): Effect.Effect => effect\n${usesStream ? "const preserveStream = () => (stream: Stream.Stream & ([A] extends [Actual] ? unknown : { readonly __generatedOutputWiderThanContract: [expected: Actual, generated: A] })): Stream.Stream => stream\n" : ""}\n` - const client = `// Generated by @opencode/httpapi-codegen. Do not edit.\nimport { Effect${usesStream ? ", Stream" : ""}, Schema } from "effect"\nimport { Sse } from "effect/encoding"\nimport { HttpClientError } from "effect/http"\n${httpApiImport}${imports}\n${shapeImport}import { ClientError } from "./client-error.js"\n\n${projection?.source ?? ""}type RawClient = HttpApiClient.ForApi\n\nconst mapClientError = (error: E) => HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error) ? new ClientError({ cause: error }) : error\n\n${preserve}${adapters.join("\n\n")}\n\nconst adaptClient = (raw: RawClient) => ({ ${fields.join(", ")} })\n\nexport const make = (options?: { readonly baseUrl?: URL | string }) => HttpApiClient.make(${api}, options).pipe(Effect.map(adaptClient))\n` + const client = `// Generated by @opencode/httpapi-codegen. Do not edit.\nimport { Effect${usesStream ? ", Stream" : ""}, Schema } from "effect"\nimport { Sse } from "effect/encoding"\nimport { HttpClientError } from "effect/http"\n${httpApiImport}${imports}\n${shapeImport}import { ClientError } from "./client-error.js"\n\n${projection?.source ?? ""}type RawClient = HttpApiClient.ForApi\n\nconst mapClientError = (error: E) => HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error) ? new ClientError({ cause: error }) : error\n\n${preserve}${adapters.join("\n\n")}\n\nconst adaptClient = ${aliases.length === 0 ? `(raw: RawClient) => ({ ${fields} })` : `(raw: RawClient) => {\n const client = { ${fields} }\n return ${renderAliasedClient(groups, aliases, "client")}\n}`}\n\nexport const make = (options?: { readonly baseUrl?: URL | string }) => HttpApiClient.make(${api}, options).pipe(Effect.map(adaptClient))\n` return [ { path: "client-error.ts", @@ -800,6 +960,7 @@ function renderPromiseTypes( groups: ReadonlyArray, outputTypes?: Readonly>, mutableOutputs = false, + aliases: ReadonlyArray = [], ) { const types = new Map() const typeOf = (schema: Schema.Top, decoded = false) => { @@ -896,6 +1057,17 @@ function renderPromiseTypes( ), ...Object.values(outputTypes ?? {}).map((output) => output.name), ]) + const aliasTypes = aliases.flatMap((alias) => { + const from = promiseTypePrefix(alias.fromGroup, alias.endpoint.clientPath) + const to = promiseTypePrefix(alias.group.identifier, alias.endpoint.clientPath) + return [...(promiseInputMode(alias.endpoint) === "none" ? [] : ["Input"]), "Output"].map( + (suffix) => [`${from}${suffix}`, `${to}${suffix}`] as const, + ) + }) + for (const [name] of aliasTypes) { + if (reservedNames.has(name)) throw new GenerationError({ reason: `Client type alias collision: ${name}` }) + reservedNames.add(name) + } const rendered = structuralTypes(outputSchemas, mutableOutputs, reservedNames) const resolve = (source: string) => rendered.types.reduce((result, type, index) => result.replaceAll(`__PROMISE_TYPE_${index}__`, type), source) @@ -907,21 +1079,27 @@ function renderPromiseTypes( ? `export type JsonValue = null | boolean | number | string | ${mutableOutputs ? "Array | { [key: string]: JsonValue }" : "ReadonlyArray | { readonly [key: string]: JsonValue }"}` : "" const imports = [...new Set(Object.values(outputTypes ?? {}).map((override) => override.import))] - return [...imports, json, ...rendered.definitions, ...resolvedErrors, resolvedOperations].filter(Boolean).join("\n\n") + const resolvedAliases = aliasTypes + .map(([from, to]) => `${deprecatedTypeAliasDoc(to)}\nexport type ${from} = ${to}`) + .join("\n\n") + return [...imports, json, ...rendered.definitions, ...resolvedErrors, resolvedOperations, resolvedAliases] + .filter(Boolean) + .join("\n\n") } function mutableType(type: string) { return type.replaceAll("ReadonlyArray<", "Array<").replaceAll(/\breadonly\s+/g, "") } -function renderPromiseClient(groups: ReadonlyArray) { +function renderPromiseClient(groups: ReadonlyArray, aliases: ReadonlyArray = []) { const imports = groups.flatMap((group) => group.endpoints.flatMap((endpoint) => { const prefix = promiseTypePrefix(group.identifier, endpoint.clientPath) return [...(promiseInputMode(endpoint) === "none" ? [] : [`${prefix}Input`]), `${prefix}Output`] }), ) - const fields = groups.map((group) => { + const groupFields = new Map() + for (const group of groups) { const methods = group.endpoints.map((endpoint) => { const prefix = promiseTypePrefix(group.identifier, endpoint.clientPath) const inputMode = promiseInputMode(endpoint) @@ -960,16 +1138,28 @@ function renderPromiseClient(groups: ReadonlyArray) { const unwrap = endpoint.unwrapData ? ".then((value) => value.data)" : "" return `(${argument}) => request<${endpoint.unwrapData ? `{ readonly data: ${prefix}Output }` : `${prefix}Output`}>(${descriptor}, requestOptions)${unwrap}` }) - const fields = renderClientTree( - group.endpoints, - (_endpoint, endpointIndex) => methods[endpointIndex], - (name, value) => `${JSON.stringify(name)}: ${value}`, - ", ", + groupFields.set( + group, + renderClientTree( + group.endpoints, + (_endpoint, endpointIndex) => methods[endpointIndex], + (name, value) => `${JSON.stringify(name)}: ${value}`, + ", ", + ), ) - if (group.endpoints[0]?.topLevel) return fields - return `${JSON.stringify(group.identifier)}: { ${fields} }` - }) - return `import type { ${imports.join(", ")} } from "./types.js"\nimport { ClientError } from "./client-error.js"\n\nexport interface ClientOptions {\n readonly baseUrl: string\n readonly fetch?: typeof globalThis.fetch\n readonly headers?: RequestInit["headers"]\n}\n\nexport interface RequestOptions {\n readonly signal?: AbortSignal\n readonly headers?: RequestInit["headers"]\n /** Reports every chunk a streaming response receives, including keepalive comments that yield no event. */\n readonly onActivity?: () => void\n}\n\ninterface RequestDescriptor {\n readonly method: string\n readonly path: string\n readonly query?: Record\n readonly headers?: Record\n readonly body?: unknown\n readonly successStatus: number\n readonly declaredStatuses: ReadonlyArray\n readonly empty: boolean\n}\n\nconst maxSseEventBytes = 16 * 1024 * 1024\n\nexport function make(options: ClientOptions) {\n const fetch = options.fetch ?? globalThis.fetch\n\n const prepare = (descriptor: RequestDescriptor, requestOptions?: RequestOptions) => {\n // A leading slash would replace any path prefix on baseUrl, so join relative to it.\n const baseUrl = new URL(options.baseUrl)\n if (!baseUrl.pathname.endsWith("/")) baseUrl.pathname += "/"\n const url = new URL(descriptor.path.slice(1), baseUrl)\n for (const [key, value] of Object.entries(descriptor.query ?? {})) appendQuery(url.searchParams, key, value)\n const headers = new Headers(options.headers)\n for (const [key, value] of Object.entries(descriptor.headers ?? {})) {\n if (value !== undefined && value !== null) headers.set(key, String(value))\n }\n for (const [key, value] of new Headers(requestOptions?.headers)) headers.set(key, value)\n if (descriptor.body !== undefined && !headers.has("content-type")) headers.set("content-type", "application/json")\n return {\n url,\n init: {\n method: descriptor.method,\n signal: requestOptions?.signal,\n headers,\n body: descriptor.body === undefined ? undefined : JSON.stringify(descriptor.body),\n } satisfies RequestInit,\n }\n }\n\n const execute = async (descriptor: RequestDescriptor, requestOptions?: RequestOptions) => {\n try {\n const prepared = prepare(descriptor, requestOptions)\n return await fetch(prepared.url, prepared.init)\n } catch (cause) {\n throw new ClientError("Transport", { cause })\n }\n }\n\n const responseError = async (response: Response, descriptor: RequestDescriptor): Promise => {\n if (descriptor.declaredStatuses.includes(response.status)) throw declared(await json(response) as DeclaredErrorBody)\n try {\n await response.body?.cancel()\n } catch {}\n throw new ClientError("UnexpectedStatus", { cause: { status: response.status }, detail: String(response.status) })\n }\n\n const request = async (descriptor: RequestDescriptor, requestOptions?: RequestOptions): Promise => {\n const response = await execute(descriptor, requestOptions)\n if (response.status !== descriptor.successStatus) return responseError(response, descriptor)\n if (descriptor.empty) {\n try {\n await response.body?.cancel()\n } catch {}\n return undefined as A\n }\n return await json(response) as A\n }\n\n const sse = (descriptor: RequestDescriptor, requestOptions?: RequestOptions): AsyncIterable => ({\n async *[Symbol.asyncIterator]() {\n const response = await execute(descriptor, requestOptions)\n if (response.status !== descriptor.successStatus) await responseError(response, descriptor)\n if (!isContentType(response, "text/event-stream")) {\n try {\n await response.body?.cancel()\n } catch {}\n throw new ClientError("UnsupportedContentType", { detail: response.headers.get("content-type") })\n }\n if (response.body === null) throw new ClientError("MalformedResponse")\n const reader = response.body.getReader()\n const decoder = new TextDecoder()\n let buffer = ""\n try {\n while (true) {\n let next: ReadableStreamReadResult\n try {\n next = await reader.read()\n } catch (cause) {\n throw new ClientError("Transport", { cause })\n }\n if (!next.done) requestOptions?.onActivity?.()\n buffer += decoder.decode(next.value, { stream: !next.done })\n if (buffer.length > maxSseEventBytes) throw new ClientError("SseEventTooLarge")\n const trailingCarriageReturn = !next.done && buffer.endsWith("\\r")\n if (trailingCarriageReturn) buffer = buffer.slice(0, -1)\n buffer = buffer.replaceAll("\\r\\n", "\\n").replaceAll("\\r", "\\n")\n if (trailingCarriageReturn) buffer += "\\r"\n if (next.done && buffer !== "") buffer += "\\n\\n"\n let boundary = buffer.indexOf("\\n\\n")\n while (boundary >= 0) {\n const block = buffer.slice(0, boundary)\n buffer = buffer.slice(boundary + 2)\n const data = block.split("\\n").flatMap((line) => line.startsWith("data:") ? [line.slice(5).trimStart()] : []).join("\\n")\n if (data !== "") {\n try {\n yield JSON.parse(data) as A\n } catch (cause) {\n throw new ClientError("MalformedResponse", { cause })\n }\n }\n boundary = buffer.indexOf("\\n\\n")\n }\n if (next.done) return\n }\n } finally {\n try {\n await reader.cancel()\n } catch {}\n reader.releaseLock()\n }\n },\n })\n\n return { ${fields.join(", ")} }\n}\n\nfunction appendQuery(params: URLSearchParams, key: string, value: unknown): void {\n if (value === undefined) return\n if (value === null) {\n params.append(key, "null")\n return\n }\n if (Array.isArray(value)) {\n for (const item of value) appendQuery(params, key, item)\n return\n }\n if (typeof value === "object") {\n for (const [child, item] of Object.entries(value)) appendQuery(params, \`\${key}[\${child}]\`, item)\n return\n }\n params.append(key, String(value))\n}\n\nasync function json(response: Response): Promise {\n if (!isContentType(response, "application/json") && !response.headers.get("content-type")?.includes("+json")) {\n try {\n await response.body?.cancel()\n } catch {}\n throw new ClientError("UnsupportedContentType", { detail: response.headers.get("content-type") })\n }\n let text: string\n try {\n text = await response.text()\n } catch (cause) {\n throw new ClientError("Transport", { cause })\n }\n if (text === "") throw new ClientError("MalformedResponse")\n try {\n return JSON.parse(text)\n } catch (cause) {\n throw new ClientError("MalformedResponse", { cause })\n }\n}\n\ntype DeclaredErrorBody = { readonly _tag?: string; readonly message?: string; readonly data?: { readonly message?: string } }\n\n/** Throw declared error bodies as Errors. The body's fields stay on the error, so narrowing on \`_tag\` or \`name\` still works. */\nfunction declared(body: DeclaredErrorBody) {\n const error = Object.assign(new Error(body.message ?? body.data?.message), body)\n if (body._tag) error.name = body._tag\n return error\n}\n\nfunction isContentType(response: Response, expected: string) {\n return response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase() === expected\n}\n` + } + const fields = renderGroupTree( + groups, + (group) => ({ fields: groupFields.get(group)! }), + (name, value) => `${JSON.stringify(name)}: ${value}`, + spreadObject, + ", ", + ) + const returned = + aliases.length === 0 + ? `return { ${fields} }` + : `const client = { ${fields} }\n return ${renderAliasedClient(groups, aliases, "client")}` + return `import type { ${imports.join(", ")} } from "./types.js"\nimport { ClientError } from "./client-error.js"\n\nexport interface ClientOptions {\n readonly baseUrl: string\n readonly fetch?: typeof globalThis.fetch\n readonly headers?: RequestInit["headers"]\n}\n\nexport interface RequestOptions {\n readonly signal?: AbortSignal\n readonly headers?: RequestInit["headers"]\n /** Reports every chunk a streaming response receives, including keepalive comments that yield no event. */\n readonly onActivity?: () => void\n}\n\ninterface RequestDescriptor {\n readonly method: string\n readonly path: string\n readonly query?: Record\n readonly headers?: Record\n readonly body?: unknown\n readonly successStatus: number\n readonly declaredStatuses: ReadonlyArray\n readonly empty: boolean\n}\n\nconst maxSseEventBytes = 16 * 1024 * 1024\n\nexport function make(options: ClientOptions) {\n const fetch = options.fetch ?? globalThis.fetch\n\n const prepare = (descriptor: RequestDescriptor, requestOptions?: RequestOptions) => {\n // A leading slash would replace any path prefix on baseUrl, so join relative to it.\n const baseUrl = new URL(options.baseUrl)\n if (!baseUrl.pathname.endsWith("/")) baseUrl.pathname += "/"\n const url = new URL(descriptor.path.slice(1), baseUrl)\n for (const [key, value] of Object.entries(descriptor.query ?? {})) appendQuery(url.searchParams, key, value)\n const headers = new Headers(options.headers)\n for (const [key, value] of Object.entries(descriptor.headers ?? {})) {\n if (value !== undefined && value !== null) headers.set(key, String(value))\n }\n for (const [key, value] of new Headers(requestOptions?.headers)) headers.set(key, value)\n if (descriptor.body !== undefined && !headers.has("content-type")) headers.set("content-type", "application/json")\n return {\n url,\n init: {\n method: descriptor.method,\n signal: requestOptions?.signal,\n headers,\n body: descriptor.body === undefined ? undefined : JSON.stringify(descriptor.body),\n } satisfies RequestInit,\n }\n }\n\n const execute = async (descriptor: RequestDescriptor, requestOptions?: RequestOptions) => {\n try {\n const prepared = prepare(descriptor, requestOptions)\n return await fetch(prepared.url, prepared.init)\n } catch (cause) {\n throw new ClientError("Transport", { cause })\n }\n }\n\n const responseError = async (response: Response, descriptor: RequestDescriptor): Promise => {\n if (descriptor.declaredStatuses.includes(response.status)) throw declared(await json(response) as DeclaredErrorBody)\n try {\n await response.body?.cancel()\n } catch {}\n throw new ClientError("UnexpectedStatus", { cause: { status: response.status }, detail: String(response.status) })\n }\n\n const request = async (descriptor: RequestDescriptor, requestOptions?: RequestOptions): Promise => {\n const response = await execute(descriptor, requestOptions)\n if (response.status !== descriptor.successStatus) return responseError(response, descriptor)\n if (descriptor.empty) {\n try {\n await response.body?.cancel()\n } catch {}\n return undefined as A\n }\n return await json(response) as A\n }\n\n const sse = (descriptor: RequestDescriptor, requestOptions?: RequestOptions): AsyncIterable => ({\n async *[Symbol.asyncIterator]() {\n const response = await execute(descriptor, requestOptions)\n if (response.status !== descriptor.successStatus) await responseError(response, descriptor)\n if (!isContentType(response, "text/event-stream")) {\n try {\n await response.body?.cancel()\n } catch {}\n throw new ClientError("UnsupportedContentType", { detail: response.headers.get("content-type") })\n }\n if (response.body === null) throw new ClientError("MalformedResponse")\n const reader = response.body.getReader()\n const decoder = new TextDecoder()\n let buffer = ""\n try {\n while (true) {\n let next: ReadableStreamReadResult\n try {\n next = await reader.read()\n } catch (cause) {\n throw new ClientError("Transport", { cause })\n }\n if (!next.done) requestOptions?.onActivity?.()\n buffer += decoder.decode(next.value, { stream: !next.done })\n if (buffer.length > maxSseEventBytes) throw new ClientError("SseEventTooLarge")\n const trailingCarriageReturn = !next.done && buffer.endsWith("\\r")\n if (trailingCarriageReturn) buffer = buffer.slice(0, -1)\n buffer = buffer.replaceAll("\\r\\n", "\\n").replaceAll("\\r", "\\n")\n if (trailingCarriageReturn) buffer += "\\r"\n if (next.done && buffer !== "") buffer += "\\n\\n"\n let boundary = buffer.indexOf("\\n\\n")\n while (boundary >= 0) {\n const block = buffer.slice(0, boundary)\n buffer = buffer.slice(boundary + 2)\n const data = block.split("\\n").flatMap((line) => line.startsWith("data:") ? [line.slice(5).trimStart()] : []).join("\\n")\n if (data !== "") {\n try {\n yield JSON.parse(data) as A\n } catch (cause) {\n throw new ClientError("MalformedResponse", { cause })\n }\n }\n boundary = buffer.indexOf("\\n\\n")\n }\n if (next.done) return\n }\n } finally {\n try {\n await reader.cancel()\n } catch {}\n reader.releaseLock()\n }\n },\n })\n\n ${returned}\n}\n\nfunction appendQuery(params: URLSearchParams, key: string, value: unknown): void {\n if (value === undefined) return\n if (value === null) {\n params.append(key, "null")\n return\n }\n if (Array.isArray(value)) {\n for (const item of value) appendQuery(params, key, item)\n return\n }\n if (typeof value === "object") {\n for (const [child, item] of Object.entries(value)) appendQuery(params, \`\${key}[\${child}]\`, item)\n return\n }\n params.append(key, String(value))\n}\n\nasync function json(response: Response): Promise {\n if (!isContentType(response, "application/json") && !response.headers.get("content-type")?.includes("+json")) {\n try {\n await response.body?.cancel()\n } catch {}\n throw new ClientError("UnsupportedContentType", { detail: response.headers.get("content-type") })\n }\n let text: string\n try {\n text = await response.text()\n } catch (cause) {\n throw new ClientError("Transport", { cause })\n }\n if (text === "") throw new ClientError("MalformedResponse")\n try {\n return JSON.parse(text)\n } catch (cause) {\n throw new ClientError("MalformedResponse", { cause })\n }\n}\n\ntype DeclaredErrorBody = { readonly _tag?: string; readonly message?: string; readonly data?: { readonly message?: string } }\n\n/** Throw declared error bodies as Errors. The body's fields stay on the error, so narrowing on \`_tag\` or \`name\` still works. */\nfunction declared(body: DeclaredErrorBody) {\n const error = Object.assign(new Error(body.message ?? body.data?.message), body)\n if (body._tag) error.name = body._tag\n return error\n}\n\nfunction isContentType(response: Response, expected: string) {\n return response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase() === expected\n}\n` } function promiseTypePrefix(group: string, path: ReadonlyArray) { @@ -1010,30 +1200,175 @@ function assertUniqueClientPaths( } } +/** + * Renders a group's methods as nested fields. `aliases` adds deprecated fields at their path relative to the tree; + * a field that holds only aliases carries the deprecation note. + */ function renderClientTree( endpoints: ReadonlyArray, leaf: (endpoint: Endpoint, index: number) => string, field: (name: string, value: string) => string, separator: string, + aliases: ReadonlyArray<{ readonly path: ReadonlyArray; readonly value: string; readonly alias: Alias }> = [], ) { - type Node = { endpoint?: { readonly value: Endpoint; readonly index: number }; readonly children: Map } - const root: Node = { children: new Map() } + type Node = { + endpoint?: { readonly value: Endpoint; readonly index: number } + alias?: { readonly value: string; readonly alias: Alias; readonly depth: number } + real: boolean + readonly children: Map + } + const root: Node = { real: false, children: new Map() } + const insert = (path: ReadonlyArray, real: boolean) => + path.reduce((parent, name) => { + const child: Node = parent.children.get(name) ?? { real: false, children: new Map() } + child.real ||= real + parent.children.set(name, child) + return child + }, root) endpoints.forEach((endpoint, index) => { - const node = endpoint.clientPath.reduce((parent, name) => { + insert(endpoint.clientPath, true).endpoint = { value: endpoint, index } + }) + for (const item of aliases) { + const node = insert(item.path, false) + if (node.endpoint !== undefined || node.alias !== undefined || node.children.size > 0) { + throw new GenerationError({ reason: `Client alias collision: ${item.alias.from.join(".")}` }) + } + node.alias = { value: item.value, alias: item.alias, depth: item.path.length } + } + const firstAlias = (node: Node): { readonly alias: Alias; readonly depth: number } => + node.alias ?? firstAlias(node.children.values().next().value!) + const render = (node: Node, depth: number): string => + Array.from(node.children, ([name, child]) => { + const value = + child.endpoint !== undefined + ? leaf(child.endpoint.value, child.endpoint.index) + : child.alias !== undefined + ? child.alias.value + : `{ ${render(child, depth + 1)} }` + if (child.real) return field(name, value) + const { alias, depth: aliasDepth } = firstAlias(child) + return `\n${deprecatedAliasDoc(alias.to.slice(0, alias.to.length - (aliasDepth - depth - 1)))}\n${field(name, value)}` + }).join(separator) + return render(root, 0) +} + +function deprecatedAliasDoc(replacement: ReadonlyArray) { + return `/** @deprecated Use \`client.${replacement.join(".")}\`. Removed in the next minor. */` +} + +function deprecatedTypeAliasDoc(replacement: string) { + return `/** @deprecated Use \`${replacement}\`. Removed in the next minor. */` +} + +function propertyAccess(root: string, path: ReadonlyArray) { + return path.reduce( + (result, name) => + /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name) ? `${result}.${name}` : `${result}[${JSON.stringify(name)}]`, + root, + ) +} + +/** + * Renders the runtime client with its aliases: `{ ...client, }`, where each alias is the namespaced + * function itself and an existing object on an alias path is spread rather than replaced. + */ +function renderAliasedClient(groups: ReadonlyArray, aliases: ReadonlyArray, client: string) { + const existing = new Set( + groups.flatMap((group) => + group.endpoints.flatMap((endpoint) => { + const path = [...group.path, ...endpoint.clientPath] + return path.slice(0, -1).map((_, index) => path.slice(0, index + 1).join("\0")) + }), + ), + ) + type Node = { alias?: Alias; readonly children: Map } + const root: Node = { children: new Map() } + for (const alias of aliases) { + const node = alias.from.reduce((parent, name) => { const child: Node = parent.children.get(name) ?? { children: new Map() } parent.children.set(name, child) return child }, root) - node.endpoint = { value: endpoint, index } - }) - const render = (node: Node): string => - Array.from(node.children, ([name, child]) => - field( - name, - child.endpoint === undefined ? `{ ${render(child)} }` : leaf(child.endpoint.value, child.endpoint.index), - ), - ).join(separator) - return render(root) + node.alias = alias + } + const firstAlias = (node: Node): Alias => node.alias ?? firstAlias(node.children.values().next().value!) + const render = (node: Node, path: ReadonlyArray): string => + Array.from(node.children, ([name, child]) => { + const childPath = [...path, name] + const key = JSON.stringify(name) + if (child.alias !== undefined) { + return `\n${deprecatedAliasDoc(child.alias.to)}\n${key}: ${propertyAccess(client, child.alias.to)}` + } + if (existing.has(childPath.join("\0"))) { + return `${key}: { ...${propertyAccess(client, childPath)}, ${render(child, childPath)} }` + } + const alias = firstAlias(child) + const replacement = alias.to.slice(0, alias.to.length - (alias.from.length - childPath.length)) + return `\n${deprecatedAliasDoc(replacement)}\n${key}: { ${render(child, childPath)} }` + }).join(", ") + return `{ ...${client}, ${render(root, [])} }` +} + +// A node of the public client object: groups whose methods sit at this path, and nested +// namespaces, kept in declaration order so adding a group never reorders unrelated output. +type GroupNode = { + readonly entries: Array + readonly children: Map +} + +function groupTree(groups: ReadonlyArray) { + const root: GroupNode = { entries: [], children: new Map() } + for (const group of groups) { + const node = group.path.reduce((parent, name) => { + const existing = parent.children.get(name) + if (existing !== undefined) return existing + const child: GroupNode = { entries: [], children: new Map() } + parent.children.set(name, child) + parent.entries.push(name) + return child + }, root) + node.entries.push(group) + } + return root +} + +/** + * Renders the client object from its groups. A group either renders as one whole value (a + * reference or call) or as fields; a node holding exactly one whole and nothing else collapses + * to that whole, anything else goes through `combine`. + */ +function renderGroupTree( + groups: ReadonlyArray, + member: (group: Group) => { readonly whole: string } | { readonly fields: string }, + field: (name: string, value: string) => string, + combine: (wholes: ReadonlyArray, fields: ReadonlyArray) => string, + separator: string, +) { + const parts = (node: GroupNode) => { + const wholes: Array = [] + const fields: Array = [] + for (const entry of node.entries) { + if (typeof entry === "string") { + fields.push(field(entry, value(node.children.get(entry)!))) + continue + } + const rendered = member(entry) + if ("whole" in rendered) wholes.push(rendered.whole) + else if (rendered.fields !== "") fields.push(rendered.fields) + } + return { wholes, fields } + } + const value = (node: GroupNode): string => { + const { wholes, fields } = parts(node) + return wholes.length === 1 && fields.length === 0 ? wholes[0] : combine(wholes, fields) + } + const root = parts(groupTree(groups)) + if (root.wholes.length > 0) throw new GenerationError({ reason: "Client root cannot hold a nested group" }) + return root.fields.join(separator) +} + +function spreadObject(wholes: ReadonlyArray, fields: ReadonlyArray) { + return `{ ${[...wholes.map((whole) => `...${whole}`), ...fields].join(", ")} }` } function identifierPart(value: string) { @@ -1093,9 +1428,7 @@ function structuralTypes(schemas: ReadonlyArray, mutable: boolean, r const pattern = `(?() @@ -1149,10 +1482,7 @@ function structuralType(schema: Schema.Top) { } return type } - return preserveStringSuggestions( - expand(document.codes[0].Type) - .replaceAll("Schema.Json", "JsonValue"), - ) + return preserveStringSuggestions(expand(document.codes[0].Type).replaceAll("Schema.Json", "JsonValue")) } function includesUndefined(ast: SchemaAST.AST): boolean { @@ -1956,7 +2286,7 @@ function renderSchemas(slots: ReadonlyArray) { return [...artifacts, ...references, ...declarations].join("\n\n") } -function renderClient(groups: ReadonlyArray) { +function renderClient(groups: ReadonlyArray, aliases: ReadonlyArray) { const imports = groups .map( (group) => @@ -1964,14 +2294,18 @@ function renderClient(groups: ReadonlyArray) { ) .join("\n") const api = `HttpApi.make("generated")${groups.map((group) => `.add(Group${groupTypeName(group)})`).join("")}` - const fields = groups.flatMap((group) => { - if (!group.endpoints[0]?.topLevel) { - return [ - `${JSON.stringify(group.identifier)}: adaptGroup${groupTypeName(group)}(raw[${JSON.stringify(group.identifier)}])`, - ] - } - const raw = `{ ${group.endpoints.map((item) => `${JSON.stringify(item.endpoint.identifier)}: raw[${JSON.stringify(item.endpoint.identifier)}]`).join(", ")} }` - return [`...adaptGroup${groupTypeName(group)}(${raw})`] - }) - return `// Generated by @opencode/httpapi-codegen. Do not edit.\nimport { Effect } from "effect"\nimport { HttpApi, HttpApiClient } from "effect/http-api"\n${imports}\n\nconst Api = ${api}\nconst adaptClient = (raw: HttpApiClient.ForApi) => ({ ${fields.join(", ")} })\n\nexport const make = (options?: { readonly baseUrl?: URL | string }) =>\n HttpApiClient.make(Api, options).pipe(Effect.map(adaptClient))\n` + const fields = renderGroupTree( + groups, + (group) => { + if (!group.endpoints[0]?.topLevel) { + return { whole: `adaptGroup${groupTypeName(group)}(raw[${JSON.stringify(group.identifier)}])` } + } + const raw = `{ ${group.endpoints.map((item) => `${JSON.stringify(item.endpoint.identifier)}: raw[${JSON.stringify(item.endpoint.identifier)}]`).join(", ")} }` + return { fields: `...adaptGroup${groupTypeName(group)}(${raw})` } + }, + (name, value) => `${JSON.stringify(name)}: ${value}`, + spreadObject, + ", ", + ) + return `// Generated by @opencode/httpapi-codegen. Do not edit.\nimport { Effect } from "effect"\nimport { HttpApi, HttpApiClient } from "effect/http-api"\n${imports}\n\nconst Api = ${api}\nconst adaptClient = ${aliases.length === 0 ? `(raw: HttpApiClient.ForApi) => ({ ${fields} })` : `(raw: HttpApiClient.ForApi) => {\n const client = { ${fields} }\n return ${renderAliasedClient(groups, aliases, "client")}\n}`}\n\nexport const make = (options?: { readonly baseUrl?: URL | string }) =>\n HttpApiClient.make(Api, options).pipe(Effect.map(adaptClient))\n` } diff --git a/packages/httpapi-codegen/test/generate.test.ts b/packages/httpapi-codegen/test/generate.test.ts index 40fa54126b4..8e4b68d9c0a 100644 --- a/packages/httpapi-codegen/test/generate.test.ts +++ b/packages/httpapi-codegen/test/generate.test.ts @@ -393,6 +393,187 @@ describe("HttpApiCodegen.generate", () => { expect(contract.groups[0]?.endpoints[0]?.operation).toMatchObject({ group: "sessions", name: "get" }) }) + test("nests namespaced endpoints and merges them with a group of the same name", async () => { + const source = HttpApi.make("test") + .add( + HttpApiGroup.make("server.session") + .add(HttpApiEndpoint.get("get", "/session", { success: Schema.String })) + .add(HttpApiEndpoint.get("stats", "/experimental/session/stats", { success: Schema.String })), + ) + .add( + HttpApiGroup.make("server.experimental").add( + HttpApiEndpoint.get("read", "/experimental/terminal", { success: Schema.String }).annotateMerge( + OpenApi.annotations({ identifier: "server.experimental.terminal.read" }), + ), + ), + ) + const contract = compileContract(source, { + groupNames: { "server.session": "session", "server.experimental": "experimental" }, + namespace: (endpoint) => (endpoint.path.startsWith("/experimental/") ? "experimental" : undefined), + }) + + expect(contract.groups.map((group) => [group.identifier, group.path])).toEqual([ + ["session", ["session"]], + ["experimental.session", ["experimental", "session"]], + ["experimental", ["experimental"]], + ]) + + const paths: Array = [] + await using emitted = await emittedModule(emitPromise(contract)) + const client = emitted.module.OpenCode.make({ + baseUrl: "https://example.com", + fetch: async (input: RequestInfo | URL) => { + paths.push(new URL(input instanceof Request ? input.url : input).pathname) + return Response.json("ok") + }, + }) + expect(Object.keys(client)).toEqual(["session", "experimental"]) + expect(Object.keys(client.session)).toEqual(["get"]) + expect(Object.keys(client.experimental)).toEqual(["session", "terminal"]) + expect(await client.session.get()).toBe("ok") + expect(await client.experimental.session.stats()).toBe("ok") + expect(await client.experimental.terminal.read()).toBe("ok") + expect(paths).toEqual(["/session", "/experimental/session/stats", "/experimental/terminal"]) + + expect(emitEffect(contract).files.find((file) => file.path === "client.ts")?.content).toContain( + '"experimental": { ...adaptGroupExperimental(raw["experimental"]), "session": adaptGroupExperimentalSession(raw["experimental.session"]) }', + ) + const imported = emitEffectImported(contract, { module: "@example/api", api: "Api" }) + expect(imported.files.find((file) => file.path === "client.ts")?.content).toContain( + '"experimental": { ...adaptGroupExperimental(raw["server.experimental"]), "session": adaptGroupExperimentalSession(raw["server.session"]) }', + ) + // A projection rebuilds the split group under its client name, so the raw client is keyed by that name. + const projected = emitEffectImported(contract, { + module: "@example/api", + endpoints: { "session.get": "Get", "experimental.session.stats": "Stats", "experimental.read": "Read" }, + }).files.find((file) => file.path === "client.ts")?.content + expect(projected).toContain('HttpApiGroup.make("experimental.session").add(Stats)') + expect(projected).toContain('const adaptGroupExperimentalSession = (raw: RawClient["experimental.session"])') + expect(projected).toContain( + '"experimental": { ...adaptGroupExperimental(raw["experimental"]), "session": adaptGroupExperimentalSession(raw["experimental.session"]) }', + ) + expect(projected).not.toContain('raw["server.') + const shape = emitEffectShape(contract).files.find((file) => file.path === "api.ts")?.content + expect(shape).toContain('readonly "session": SessionApi') + expect(shape).toContain( + 'readonly "experimental": ExperimentalApi & {\nreadonly "session": ExperimentalSessionApi\n}', + ) + }) + + test("rejects a namespaced group that collides with a method in the namespace", () => { + const source = HttpApi.make("test") + .add( + HttpApiGroup.make("experimental").add( + HttpApiEndpoint.get("read", "/experimental/session", { success: Schema.String }).annotateMerge( + OpenApi.annotations({ identifier: "experimental.session.read" }), + ), + ), + ) + .add( + HttpApiGroup.make("session").add( + HttpApiEndpoint.get("stats", "/experimental/stats", { success: Schema.String }), + ), + ) + + expect(() => compileContract(source, { namespace: () => "experimental" })).toThrow( + "Client name collision: experimental.session", + ) + }) + + test("keeps pre-namespace paths and type names as deprecated aliases", async () => { + const source = HttpApi.make("test") + .add( + HttpApiGroup.make("server.session") + .add(HttpApiEndpoint.get("get", "/session", { success: Schema.String })) + .add( + HttpApiEndpoint.get("stats", "/experimental/session/:sessionID/stats", { + params: { sessionID: Schema.String }, + success: Schema.String, + }), + ), + ) + .add( + HttpApiGroup.make("server.generate").add( + HttpApiEndpoint.post("text", "/experimental/generate/text", { + payload: Schema.Struct({ prompt: Schema.String }), + success: Schema.String, + }), + ), + ) + const options = { + groupNames: { "server.session": "session", "server.generate": "generate" }, + namespace: (endpoint: HttpApiEndpoint.Top) => + endpoint.path.startsWith("/experimental/") ? "experimental" : undefined, + } + expect(compileContract(source, options).aliases).toBeUndefined() + expect( + emitPromise(compileContract(source, options)) + .files.map((file) => file.content) + .join(""), + ).not.toContain("@deprecated") + + const contract = compileContract(source, { ...options, aliases: true }) + expect(contract.aliases?.map((alias) => [alias.from.join("."), alias.to.join(".")])).toEqual([ + ["session.stats", "experimental.session.stats"], + ["generate.text", "experimental.generate.text"], + ]) + + const paths: Array = [] + const promise = emitPromise(contract) + await using emitted = await emittedModule(promise) + const client = emitted.module.OpenCode.make({ + baseUrl: "https://example.com", + fetch: async (input: RequestInfo | URL) => { + paths.push(new URL(input instanceof Request ? input.url : input).pathname) + return Response.json("ok") + }, + }) + expect(Object.keys(client)).toEqual(["session", "experimental", "generate"]) + expect(Object.keys(client.session)).toEqual(["get", "stats"]) + expect(client.session.stats).toBe(client.experimental.session.stats) + expect(client.generate.text).toBe(client.experimental.generate.text) + expect(await client.session.stats({ sessionID: "a" })).toBe("ok") + expect(paths).toEqual(["/experimental/session/a/stats"]) + const promiseFile = (path: string) => promise.files.find((file) => file.path === path)?.content + expect(promiseFile("client.ts")).toContain( + "/** @deprecated Use `client.experimental.generate.text`. Removed in the next minor. */", + ) + expect(promiseFile("types.ts")).toContain( + "/** @deprecated Use `ExperimentalSessionStatsInput`. Removed in the next minor. */\nexport type SessionStatsInput = ExperimentalSessionStatsInput", + ) + + const shape = emitEffectShape(contract).files.find((file) => file.path === "api.ts")?.content + // The alias joins the interface of the group still at its old path, so code typed against SessionApi compiles. + expect(shape).toContain( + 'export interface SessionApi {\nreadonly "get": SessionGetOperation\n\n/** @deprecated Use `client.experimental.session.stats`. Removed in the next minor. */\nreadonly "stats": ExperimentalSessionStatsOperation\n}', + ) + expect(shape).toContain("export type SessionStatsOperation = ExperimentalSessionStatsOperation") + expect(shape).toContain("export type GenerateApi = ExperimentalGenerateApi") + expect(shape).toContain( + '/** @deprecated Use `client.experimental.generate`. Removed in the next minor. */\nreadonly "generate": {', + ) + expect(emitEffect(contract).files.find((file) => file.path === "client.ts")?.content).toContain( + 'return { ...client, "session": { ...client.session, ', + ) + }) + + test("rejects an alias that collides with a client path", () => { + const source = HttpApi.make("test").add( + HttpApiGroup.make("session") + .add(HttpApiEndpoint.get("stats", "/session/stats", { success: Schema.String })) + .add( + HttpApiEndpoint.get("experimentalStats", "/experimental/session/stats", { + success: Schema.String, + }).annotateMerge(OpenApi.annotations({ identifier: "experimental.session.stats" })), + ), + ) + const namespace = (endpoint: HttpApiEndpoint.Top) => + endpoint.path.startsWith("/experimental/") ? "experimental" : undefined + + expect(() => compileContract(source, { namespace })).not.toThrow() + expect(() => compileContract(source, { namespace, aliases: true })).toThrow("Client alias collision: session.stats") + }) + test("derives nested paths from OpenAPI operation IDs", () => { const source = HttpApi.make("test").add( HttpApiGroup.make("server.session").add( diff --git a/packages/plugin/src/effect/plugin.ts b/packages/plugin/src/effect/plugin.ts index a60b7c0b453..9902197bfa4 100644 --- a/packages/plugin/src/effect/plugin.ts +++ b/packages/plugin/src/effect/plugin.ts @@ -1,4 +1,4 @@ -import type { CredentialApi, ExperimentalApi, GenerateApi, PluginApi } from "@opencode/client/effect/api" +import type { CredentialApi, ExperimentalApi, ExperimentalGenerateApi, PluginApi } from "@opencode/client/effect/api" import type { Location } from "@opencode/schema/location" import type { Effect, Scope } from "effect" import type { PluginOptions } from "../options.js" @@ -35,13 +35,13 @@ export interface Context { readonly experimental: { readonly terminal: Pick["persistentPty"], "read"> /** Stateless generation with a model and a prompt: no session, history or tools. */ - readonly generate: GenerateApi + readonly generate: ExperimentalGenerateApi } readonly integration: IntegrationDomain readonly mcp: MCPDomain readonly model: ModelDomain /** @deprecated Use `experimental.generate.text`. */ - readonly generate: Pick, "text"> + readonly generate: Pick, "text"> readonly permission: PermissionDomain readonly plugin: Pick, "list"> readonly provider: ProviderDomain diff --git a/packages/plugin/src/effect/session.ts b/packages/plugin/src/effect/session.ts index 2fb53b80f4f..90446cf156f 100644 --- a/packages/plugin/src/effect/session.ts +++ b/packages/plugin/src/effect/session.ts @@ -1,4 +1,4 @@ -import type { SessionApi } from "@opencode/client/effect/api" +import type { ExperimentalSessionApi, SessionApi } from "@opencode/client/effect/api" import type { GenerationOptionsFields, Message, SystemPart } from "@opencode/ai/effect" import type { Agent } from "@opencode/schema/agent" import type { Model } from "@opencode/schema/model" @@ -167,9 +167,8 @@ export type SessionDomain = Pick< | "interrupt" | "update" | "move" - | "wait" | "context" - | "instructions" -> & { - readonly hook: ModelHooks -} +> & + Pick, "wait" | "instructions"> & { + readonly hook: ModelHooks + } diff --git a/packages/plugin/src/promise/plugin.ts b/packages/plugin/src/promise/plugin.ts index 30e144d4776..d12eaeefb75 100644 --- a/packages/plugin/src/promise/plugin.ts +++ b/packages/plugin/src/promise/plugin.ts @@ -1,5 +1,5 @@ import type { OpenCodeClient } from "@opencode/client" -import type { CredentialApi, GenerateApi, PluginApi } from "@opencode/client/promise/api" +import type { CredentialApi, ExperimentalGenerateApi, PluginApi } from "@opencode/client/promise/api" import type { Location } from "@opencode/schema/location" import type { PluginOptions } from "../options.js" import type { App } from "../app.js" @@ -35,13 +35,13 @@ export interface Context { readonly experimental: { readonly terminal: Pick /** Stateless generation with a model and a prompt: no session, history or tools. */ - readonly generate: GenerateApi + readonly generate: ExperimentalGenerateApi } readonly integration: IntegrationDomain readonly mcp: MCPDomain readonly model: ModelDomain /** @deprecated Use `experimental.generate.text`. */ - readonly generate: Pick + readonly generate: Pick readonly permission: PermissionDomain readonly plugin: Pick readonly provider: ProviderDomain diff --git a/packages/plugin/src/promise/session.ts b/packages/plugin/src/promise/session.ts index 4330340c8eb..48422b78fbc 100644 --- a/packages/plugin/src/promise/session.ts +++ b/packages/plugin/src/promise/session.ts @@ -1,4 +1,4 @@ -import type { SessionApi } from "@opencode/client/promise/api" +import type { ExperimentalSessionApi, SessionApi } from "@opencode/client/promise/api" import type { GenerationOptionsFields, Message, SystemPart } from "@opencode/ai/effect" import type { Agent } from "@opencode/schema/agent" import type { Model } from "@opencode/schema/model" @@ -167,9 +167,8 @@ export type SessionDomain = Pick< | "interrupt" | "update" | "move" - | "wait" | "context" - | "instructions" -> & { - readonly hook: ModelHooks -} +> & + Pick & { + readonly hook: ModelHooks + } diff --git a/packages/protocol/openapi.json b/packages/protocol/openapi.json index fe4e1bd0663..cdd95560389 100644 --- a/packages/protocol/openapi.json +++ b/packages/protocol/openapi.json @@ -3993,7 +3993,7 @@ "/api/experimental/session/{sessionID}/log": { "get": { "tags": ["session"], - "operationId": "session.log", + "operationId": "experimental.session.log", "parameters": [ { "name": "sessionID", @@ -11732,7 +11732,7 @@ "/api/experimental/session/{sessionID}/terminal/read": { "get": { "tags": ["persistentPty"], - "operationId": "server.experimental.persistentPty.read", + "operationId": "experimental.persistentPty.read", "parameters": [ { "name": "sessionID", @@ -11822,7 +11822,7 @@ "/api/experimental/session/{sessionID}/terminal": { "get": { "tags": ["persistentPty"], - "operationId": "server.experimental.persistentPty.list", + "operationId": "experimental.persistentPty.list", "parameters": [ { "name": "sessionID", @@ -11889,7 +11889,7 @@ }, "post": { "tags": ["persistentPty"], - "operationId": "server.experimental.persistentPty.create", + "operationId": "experimental.persistentPty.create", "parameters": [ { "name": "sessionID", @@ -11965,7 +11965,7 @@ "/api/experimental/persistent-pty/shutdown": { "post": { "tags": ["persistentPty"], - "operationId": "server.experimental.persistentPty.shutdown", + "operationId": "experimental.persistentPty.shutdown", "parameters": [], "security": [], "responses": { @@ -12008,7 +12008,7 @@ "/api/experimental/persistent-pty/handoff": { "post": { "tags": ["persistentPty"], - "operationId": "server.experimental.persistentPty.handoff", + "operationId": "experimental.persistentPty.handoff", "parameters": [], "security": [], "responses": { @@ -12072,7 +12072,7 @@ "/api/experimental/persistent-pty/{ptyID}": { "get": { "tags": ["persistentPty"], - "operationId": "server.experimental.persistentPty.get", + "operationId": "experimental.persistentPty.get", "parameters": [ { "name": "ptyID", @@ -12146,7 +12146,7 @@ }, "put": { "tags": ["persistentPty"], - "operationId": "server.experimental.persistentPty.update", + "operationId": "experimental.persistentPty.update", "parameters": [ { "name": "ptyID", @@ -12230,7 +12230,7 @@ }, "delete": { "tags": ["persistentPty"], - "operationId": "server.experimental.persistentPty.remove", + "operationId": "experimental.persistentPty.remove", "parameters": [ { "name": "ptyID", @@ -12292,7 +12292,7 @@ "/api/experimental/persistent-pty/{ptyID}/snapshot": { "get": { "tags": ["persistentPty"], - "operationId": "server.experimental.persistentPty.snapshot", + "operationId": "experimental.persistentPty.snapshot", "parameters": [ { "name": "ptyID", @@ -12368,7 +12368,7 @@ "/api/experimental/persistent-pty/{ptyID}/connect-token": { "post": { "tags": ["persistentPty"], - "operationId": "server.experimental.persistentPty.connectToken", + "operationId": "experimental.persistentPty.connectToken", "parameters": [ { "name": "ptyID", @@ -12469,7 +12469,7 @@ "/api/experimental/persistent-pty/{ptyID}/connect": { "get": { "tags": ["persistentPty"], - "operationId": "persistentPty.connect", + "operationId": "experimental.persistentPty.connect", "parameters": [ { "name": "ptyID", diff --git a/packages/protocol/src/client.ts b/packages/protocol/src/client.ts index 9c5c0912219..40ae172abb4 100644 --- a/packages/protocol/src/client.ts +++ b/packages/protocol/src/client.ts @@ -68,6 +68,12 @@ export const groupNames = { "server.config": "config", } as const +// Experimental routes carry no compatibility promise, so the generated clients nest them under +// `client.experimental` instead of beside stable methods. The URL decides rather than the OpenAPI +// id, because the URL is what callers depend on and an id can miss its `experimental.` prefix. +export const clientNamespace = (endpoint: { readonly path: string }) => + endpoint.path === "/api/experimental" || endpoint.path.startsWith("/api/experimental/") ? "experimental" : undefined + export const promiseOmitEndpoints = new Set([ "pty.connect", "persistentPty.connect", diff --git a/packages/protocol/src/groups/persistent-pty.ts b/packages/protocol/src/groups/persistent-pty.ts index d77ef6c8789..720ea75bd86 100644 --- a/packages/protocol/src/groups/persistent-pty.ts +++ b/packages/protocol/src/groups/persistent-pty.ts @@ -31,6 +31,7 @@ export const PersistentPtyGroup = HttpApiGroup.make("server.experimental") error: [ServiceUnavailableError], }).annotateMerge( OpenApi.annotations({ + identifier: "experimental.persistentPty.read", summary: "Read the session's most recently controlled terminal", description: "Read the last physical rows without changing selection or taking control. Omitted lines uses the live terminal height; larger counts include retained history. Blank rows are preserved. Screen dimensions and cursor remain relative to the live screen. Returns null when no current terminal exists. Selection is server-local and resets on restart. Experimental: may change without compatibility guarantees.", @@ -42,7 +43,7 @@ export const PersistentPtyGroup = HttpApiGroup.make("server.experimental") params: { sessionID: Session.ID }, success: Schema.Struct({ data: Schema.Array(PersistentPty.Info) }), error: errors, - }), + }).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.list" })), ) .add( HttpApiEndpoint.post("persistentPty.create", "/api/experimental/session/:sessionID/terminal", { @@ -50,26 +51,26 @@ export const PersistentPtyGroup = HttpApiGroup.make("server.experimental") payload: PersistentPty.CreateInput, success: Schema.Struct({ data: PersistentPty.Info }), error: errors, - }), + }).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.create" })), ) .add( HttpApiEndpoint.post("persistentPty.shutdown", "/api/experimental/persistent-pty/shutdown", { success: HttpApiSchema.NoContent, error: [ServiceUnavailableError], - }), + }).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.shutdown" })), ) .add( HttpApiEndpoint.post("persistentPty.handoff", "/api/experimental/persistent-pty/handoff", { success: Schema.Struct({ handoff: Schema.NullOr(PersistentPty.Handoff) }), error: [ServiceUnavailableError], - }), + }).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.handoff" })), ) .add( HttpApiEndpoint.get("persistentPty.get", "/api/experimental/persistent-pty/:ptyID", { params: { ptyID: Pty.ID }, success: Schema.Struct({ data: PersistentPty.Info }), error: terminalErrors, - }), + }).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.get" })), ) .add( HttpApiEndpoint.put("persistentPty.update", "/api/experimental/persistent-pty/:ptyID", { @@ -77,21 +78,21 @@ export const PersistentPtyGroup = HttpApiGroup.make("server.experimental") payload: PersistentPty.UpdateInput, success: Schema.Struct({ data: PersistentPty.Info }), error: terminalErrors, - }), + }).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.update" })), ) .add( HttpApiEndpoint.get("persistentPty.snapshot", "/api/experimental/persistent-pty/:ptyID/snapshot", { params: { ptyID: Pty.ID }, success: Schema.Struct({ data: PersistentPty.Snapshot }), error: terminalErrors, - }), + }).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.snapshot" })), ) .add( HttpApiEndpoint.delete("persistentPty.remove", "/api/experimental/persistent-pty/:ptyID", { params: { ptyID: Pty.ID }, success: HttpApiSchema.NoContent, error: terminalErrors, - }), + }).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.remove" })), ) .add( HttpApiEndpoint.post("persistentPty.connectToken", "/api/experimental/persistent-pty/:ptyID/connect-token", { @@ -99,7 +100,7 @@ export const PersistentPtyGroup = HttpApiGroup.make("server.experimental") headers: Schema.Struct({ [PTY_CONNECT_TOKEN_HEADER]: Schema.optional(Schema.String) }), success: Schema.Struct({ data: PtyTicket.ConnectToken }), error: [ForbiddenError, PtyNotFoundError, ServiceUnavailableError], - }), + }).annotateMerge(OpenApi.annotations({ identifier: "experimental.persistentPty.connectToken" })), ) .add( HttpApiEndpoint.get("persistentPty.connect", PERSISTENT_PTY_CONNECT_PATH, { @@ -108,7 +109,7 @@ export const PersistentPtyGroup = HttpApiGroup.make("server.experimental") error: [ForbiddenError, PtyNotFoundError, ServiceUnavailableError], }).annotateMerge( OpenApi.annotations({ - identifier: "persistentPty.connect", + identifier: "experimental.persistentPty.connect", summary: "Connect to a persistent PTY", description: "Stream persistent PTY output through the OpenCode server.", transform: (operation) => ({ diff --git a/packages/protocol/src/groups/session.ts b/packages/protocol/src/groups/session.ts index 47ac7cd4724..a1249ce9054 100644 --- a/packages/protocol/src/groups/session.ts +++ b/packages/protocol/src/groups/session.ts @@ -665,7 +665,7 @@ export const makeSessionGroup = { + const operations = Object.entries(OpenApi.fromApi(ClientApi).paths).flatMap(([path, item]) => + methods.flatMap((method) => { + const operation = item[method] + return operation ? [{ path, identifier: operation.operationId }] : [] + }), + ) + const offenders = operations + .filter( + ({ path, identifier }) => + (path === "/api/experimental" || path.startsWith("/api/experimental/")) !== + identifier.startsWith("experimental."), + ) + .map(({ path, identifier }) => `${identifier} ${path}`) + + expect(operations.length).toBeGreaterThan(100) + expect(offenders).toEqual([]) +}) diff --git a/packages/sdk/test/contract-identity.test.ts b/packages/sdk/test/contract-identity.test.ts index 6149bb05fa8..fec447b281f 100644 --- a/packages/sdk/test/contract-identity.test.ts +++ b/packages/sdk/test/contract-identity.test.ts @@ -19,7 +19,7 @@ import { SessionMessage } from "@opencode/schema/session-message" import { Workspace } from "@opencode/schema/workspace" import { Worktree } from "@opencode/schema/worktree" import { Api } from "@opencode/server/api" -import { ClientApi, groupNames, promiseOmitEndpoints } from "@opencode/protocol/client" +import { ClientApi, clientNamespace, groupNames, promiseOmitEndpoints } from "@opencode/protocol/client" import { compile, emitPromise } from "@opencode/httpapi-codegen" const SDK = await import("../src/index") @@ -97,8 +97,8 @@ test("Core and Server reuse the authoritative Schema and Protocol values", () => }) test("client and Server contracts generate identically", () => { - const server = compile(Api, { groupNames, omitEndpoints: promiseOmitEndpoints }) - const client = compile(ClientApi, { groupNames, omitEndpoints: promiseOmitEndpoints }) + const server = compile(Api, { groupNames, omitEndpoints: promiseOmitEndpoints, namespace: clientNamespace }) + const client = compile(ClientApi, { groupNames, omitEndpoints: promiseOmitEndpoints, namespace: clientNamespace }) expect(emitPromise(client)).toEqual(emitPromise(server)) }) diff --git a/packages/sdk/test/embedded.test.ts b/packages/sdk/test/embedded.test.ts index 3c2e4474061..2f53f805b2d 100644 --- a/packages/sdk/test/embedded.test.ts +++ b/packages/sdk/test/embedded.test.ts @@ -68,7 +68,7 @@ for (const selection of ["explicit", "default"] as const) { }, ) - const result = yield* opencode.generate.text({ + const result = yield* opencode.experimental.generate.text({ prompt: "Say ready", ...(selection === "explicit" ? { @@ -137,7 +137,7 @@ it.live("seeds host plugins from CreateOptions and waits for delayed model plugi ) const [defaultModel, generated] = yield* Effect.all( - [opencode.model.default({ location: location(fixture) }), opencode.generate.text({ prompt: "Say ready" })], + [opencode.model.default({ location: location(fixture) }), opencode.experimental.generate.text({ prompt: "Say ready" })], { concurrency: "unbounded" }, ) @@ -223,16 +223,16 @@ it.live( }) const context = yield* opencode.sessions.context({ sessionID: id }) const pendingAfterAdmit = yield* opencode.sessions.inbox.list({ sessionID: id }) - yield* opencode.sessions.instructions.entry.put({ sessionID: id, key: "deploy-target", value: "production" }) - yield* opencode.sessions.instructions.entry.put({ sessionID: id, key: "flags", value: { beta: true } }) - const contextEntries = yield* opencode.sessions.instructions.entry.list({ sessionID: id }) - yield* opencode.sessions.instructions.entry.remove({ sessionID: id, key: "flags" }) - const remainingContextEntries = yield* opencode.sessions.instructions.entry.list({ sessionID: id }) + yield* opencode.experimental.session.instructions.entry.put({ sessionID: id, key: "deploy-target", value: "production" }) + yield* opencode.experimental.session.instructions.entry.put({ sessionID: id, key: "flags", value: { beta: true } }) + const contextEntries = yield* opencode.experimental.session.instructions.entry.list({ sessionID: id }) + yield* opencode.experimental.session.instructions.entry.remove({ sessionID: id, key: "flags" }) + const remainingContextEntries = yield* opencode.experimental.session.instructions.entry.list({ sessionID: id }) const wake = yield* opencode.sessions.prompt({ sessionID: id, text: "Promote this input", }) - const prompted = yield* opencode.sessions.log({ sessionID: id, follow: true }).pipe( + const prompted = yield* opencode.experimental.session.log({ sessionID: id, follow: true }).pipe( Stream.filter((event) => event.type === "session.inbox.delivered" && event.data.inboxID === wake.id), Stream.runHead, Effect.timeout("10 seconds"), @@ -240,7 +240,7 @@ it.live( ) const wakeContext = yield* opencode.sessions.context({ sessionID: id }) const pendingAfterPromote = yield* opencode.sessions.inbox.list({ sessionID: id }) - const event = yield* opencode.sessions.log({ sessionID: id }).pipe( + const event = yield* opencode.experimental.session.log({ sessionID: id }).pipe( Stream.filter((item) => item.type === "session.model.selected"), Stream.take(1), Stream.runHead, @@ -255,10 +255,10 @@ it.live( const missingSessionID = fixture.sdk.Session.ID.create() const missing = yield* Effect.all( [ - opencode.sessions.log({ sessionID: missingSessionID }).pipe(Stream.runHead, Effect.flip), + opencode.experimental.session.log({ sessionID: missingSessionID }).pipe(Stream.runHead, Effect.flip), opencode.sessions.interrupt({ sessionID: missingSessionID }).pipe(Effect.flip), opencode.sessions.message.get({ sessionID: missingSessionID, messageID: modelMessage.id }).pipe(Effect.flip), - opencode.sessions.instructions.entry.list({ sessionID: missingSessionID }).pipe(Effect.flip), + opencode.experimental.session.instructions.entry.list({ sessionID: missingSessionID }).pipe(Effect.flip), opencode.sessions.inbox.list({ sessionID: missingSessionID }).pipe(Effect.flip), ], { concurrency: "unbounded" }, @@ -635,7 +635,7 @@ it.live( expect(calls).toEqual(["create"]) yield* Deferred.succeed(createRelease, undefined) - yield* opencode.sessions.wait({ sessionID: session.id }) + yield* opencode.experimental.session.wait({ sessionID: session.id }) // Provisioning settled, the workspace connected, and the turn completed. The // memory driver rejects the actual spawn, which surfaces to the model as an // ordinary tool error before the final text response. diff --git a/packages/sdk/test/instances-effect.test.ts b/packages/sdk/test/instances-effect.test.ts index 15515d510b4..c47d9a1d325 100644 --- a/packages/sdk/test/instances-effect.test.ts +++ b/packages/sdk/test/instances-effect.test.ts @@ -126,7 +126,7 @@ it.live( expect((yield* llm.requests()).length).toBe(1) yield* Deferred.succeed(release, undefined) yield* llm.wait(3).pipe(Effect.timeout("5 seconds")) - yield* second.sessions.wait({ sessionID: session.id }) + yield* second.experimental.session.wait({ sessionID: session.id }) expect(configured).toEqual(["thread-recovery", "thread-recovery"]) expect(executed).toEqual([2]) @@ -215,7 +215,7 @@ it.live( for (const session of [first, second]) { const admitted = yield* opencode.sessions.prompt({ sessionID: session.id, text: "Hello" }) expect(admitted.payload.text).toBe(`Hello:${session.location.workspaceID}`) - yield* opencode.sessions.wait({ sessionID: session.id }) + yield* opencode.experimental.session.wait({ sessionID: session.id }) } expect(configured).toEqual(["same-thread", "same-thread"]) expect(placements.map((location) => location.workspaceID)).toEqual([firstWorkspace, secondWorkspace]) @@ -225,7 +225,7 @@ it.live( directory: AbsolutePath.make(directory.path), workspaceID: secondWorkspace, }) - yield* opencode.sessions.wait({ sessionID: first.id }) + yield* opencode.experimental.session.wait({ sessionID: first.id }) const moved = yield* opencode.sessions.get({ sessionID: first.id }) expect(moved.location.workspaceID).toBe(secondWorkspace) const admitted = yield* opencode.sessions.prompt({ sessionID: first.id, text: "Moved", resume: false }) diff --git a/packages/sdk/test/promise.test.ts b/packages/sdk/test/promise.test.ts index 1671906a24b..a389ac25372 100644 --- a/packages/sdk/test/promise.test.ts +++ b/packages/sdk/test/promise.test.ts @@ -18,7 +18,7 @@ test("Promise host uses the embedded router", async () => { const session = await opencode.sessions.create({ location }) const selected = await opencode.sessions.get({ sessionID: session.id }) const page = await opencode.sessions.list({ directory: directory.path }) - const events = Array.fromAsync(opencode.sessions.log({ sessionID: session.id })) + const events = Array.fromAsync(opencode.experimental.session.log({ sessionID: session.id })) expect(selected.id).toBe(session.id) expect(page.data.some((item) => item.id === session.id)).toBe(true) diff --git a/packages/sdk/test/transport.test.ts b/packages/sdk/test/transport.test.ts index 6955fcdb552..bdf4daa94b5 100644 --- a/packages/sdk/test/transport.test.ts +++ b/packages/sdk/test/transport.test.ts @@ -40,14 +40,14 @@ for (const entrypoint of ["create", "layer"] as const) { location: Location.Ref.make({ directory: AbsolutePath.make(directory.path) }), }) expect((yield* client.sessions.get({ sessionID: session.id })).id).toBe(session.id) - const events = yield* client.sessions.log({ sessionID: session.id }).pipe(Stream.runCollect) + const events = yield* client.experimental.session.log({ sessionID: session.id }).pipe(Stream.runCollect) expect(events.some((event) => event.type === "session.created")).toBe(true) expect(yield* client.events.subscribe().pipe(Stream.take(1), Stream.runCollect)).toMatchObject([ { type: "server.connected" }, ]) const missing = Session.ID.create() // Error responses must decode over the SDK transport too; sessions.get is served by core without HTTP. - expect(yield* client.sessions.export({ sessionID: missing }).pipe(Effect.flip)).toMatchObject({ + expect(yield* client.experimental.session.export({ sessionID: missing }).pipe(Effect.flip)).toMatchObject({ _tag: "SessionNotFoundError", }) expect(yield* client.sessions.get({ sessionID: missing }).pipe(Effect.flip)).toMatchObject({ diff --git a/packages/server/test/media.test.ts b/packages/server/test/media.test.ts index 83f19306c36..17ce2da1ceb 100644 --- a/packages/server/test/media.test.ts +++ b/packages/server/test/media.test.ts @@ -125,7 +125,7 @@ it.live("serves stored media as refs only to clients that opt in while experimen yield* Effect.promise(async () => { const template = await plain.session.create({ title: "Media wire" }) - await plain.session.import({ info: { ...template, id: sessionID }, messages: [user, assistant] }) + await plain.experimental.session.import({ info: { ...template, id: sessionID }, messages: [user, assistant] }) storeAsBlobs(database) // Without the capability, reads stay byte-for-byte what was imported. @@ -187,7 +187,7 @@ it.live("serves stored media as refs only to clients that opt in while experimen const single: unknown = await opted.session.message.get({ sessionID, messageID: "msg_media_user" }) expect(single).toMatchObject({ files: [{ uri: media(png) }, { uri: media(text) }, {}, {}] }) expect(await plain.session.message.get({ sessionID, messageID: "msg_media_user" })).toEqual(user) - expect((await opted.session.export({ sessionID })).messages).toEqual([user, assistant]) + expect((await opted.experimental.session.export({ sessionID })).messages).toEqual([user, assistant]) // The route serves raw bytes, immutable caching and a 304, and never renders active content inline. const image = await handler(new Request(route(png))) diff --git a/packages/server/test/message.test.ts b/packages/server/test/message.test.ts index 2899f87d03f..84957e4f293 100644 --- a/packages/server/test/message.test.ts +++ b/packages/server/test/message.test.ts @@ -48,7 +48,7 @@ const setup = Effect.gen(function* () { }) const session = yield* Effect.promise(async () => { const template = await api.session.create({ title: "Message filtering" }) - return api.session.import({ info: { ...template, id: Session.ID.create() }, messages }) + return api.experimental.session.import({ info: { ...template, id: Session.ID.create() }, messages }) }) return { api, handler, sessionID: session.id } }) diff --git a/packages/server/test/sse-failure.test.ts b/packages/server/test/sse-failure.test.ts index df5c19ef5e8..adf5622f5da 100644 --- a/packages/server/test/sse-failure.test.ts +++ b/packages/server/test/sse-failure.test.ts @@ -58,7 +58,7 @@ it.live("the generated Effect client fails the session log stream with the serve const received: unknown[] = [] const exit = yield* Effect.gen(function* () { const client = yield* OpenCode.make({ baseUrl: "http://opencode.local" }) - return yield* client.session + return yield* client.experimental.session .log({ sessionID: Session.ID.make("ses_test") }) .pipe(Stream.runForEach((item) => Effect.sync(() => received.push(item)))) }).pipe(Effect.provideService(HttpClient.HttpClient, httpClient), Effect.exit) diff --git a/packages/tui/src/component/devtools-bar.tsx b/packages/tui/src/component/devtools-bar.tsx index 10af2019d60..a80163edea6 100644 --- a/packages/tui/src/component/devtools-bar.tsx +++ b/packages/tui/src/component/devtools-bar.tsx @@ -162,7 +162,7 @@ export function DevToolsBar() { const events = await (sessionID ? (async () => { const events: { readonly created: number }[] = [] - for await (const event of client.api.session.log({ sessionID, follow: false })) { + for await (const event of client.api.experimental.session.log({ sessionID, follow: false })) { if (event.type !== "log.synced") events.push(event) } // Durable events stay in aggregate order even when their wall-clock timestamps differ. diff --git a/packages/tui/src/component/dialog-mcp.tsx b/packages/tui/src/component/dialog-mcp.tsx index 68e3778b42f..a8241623fd1 100644 --- a/packages/tui/src/component/dialog-mcp.tsx +++ b/packages/tui/src/component/dialog-mcp.tsx @@ -121,7 +121,7 @@ export function DialogMcp(props: { initialServer?: string; details?: boolean } = setLoading((prev) => new Set(prev).add(name)) const target = current() const input = { server: name, location: { directory: target.directory } } - const call = server.status.status === "connected" ? client.api.mcp.disconnect(input) : client.api.mcp.connect(input) + const call = server.status.status === "connected" ? client.api.experimental.mcp.disconnect(input) : client.api.experimental.mcp.connect(input) void call.catch(toast.error).finally(() => setLoading((prev) => { const next = new Set(prev) diff --git a/packages/tui/src/component/migration-overlay.tsx b/packages/tui/src/component/migration-overlay.tsx index fc73e36b853..3f6676fd1ba 100644 --- a/packages/tui/src/component/migration-overlay.tsx +++ b/packages/tui/src/component/migration-overlay.tsx @@ -19,7 +19,7 @@ export function MigrationOverlay() { await Bun.sleep(1_000) void (async () => { while (true) { - const status = await client.api.migration.v1.status({ signal: abort.signal }) + const status = await client.api.experimental.migration.v1.status({ signal: abort.signal }) setProgress(status.status === "running" ? status.progress : undefined) if (status.status === "completed") return if (status.status === "error") throw new Error(status.error) diff --git a/packages/tui/src/feature-plugins/system/stats.tsx b/packages/tui/src/feature-plugins/system/stats.tsx index 950d322422d..09d79e426bb 100644 --- a/packages/tui/src/feature-plugins/system/stats.tsx +++ b/packages/tui/src/feature-plugins/system/stats.tsx @@ -140,7 +140,7 @@ export function StatsPoster(props: { stats: SessionStatsInfo }) { function StatsPage(props: { context: Plugin.Context; onClose: () => void }) { const [result] = createResource(() => { const now = new Date() - return props.context.client.session.stats({ + return props.context.client.experimental.session.stats({ from: new Date(now.getFullYear(), 0, 1).getTime(), timezone: Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC", tools: "none", diff --git a/packages/tui/src/mini/stream-v2.transport.ts b/packages/tui/src/mini/stream-v2.transport.ts index 52117b21d55..4d2f84e41d6 100644 --- a/packages/tui/src/mini/stream-v2.transport.ts +++ b/packages/tui/src/mini/stream-v2.transport.ts @@ -911,7 +911,7 @@ export async function createSessionTransport(input: StreamInput): Promise ok(input.active?.() ?? {})) spyOn(client.session.inbox, "list").mockImplementation((request) => ok(input.pending?.[request.sessionID] ?? [])) - spyOn(client.session, "wait").mockImplementation(() => input.wait?.() ?? ok(undefined)) + spyOn(client.experimental.session, "wait").mockImplementation(() => input.wait?.() ?? ok(undefined)) spyOn(client.session.message, "get").mockImplementation((request) => { const message = input.messages?.[request.sessionID]?.find((item) => item.id === request.messageID) return message ? (ok(message) as never) : Promise.reject(new Error(`message not found: ${request.messageID}`)) diff --git a/services/www/src/docs/content/build/client/effect.mdx b/services/www/src/docs/content/build/client/effect.mdx index 9358c63e72a..938f2941d4d 100644 --- a/services/www/src/docs/content/build/client/effect.mdx +++ b/services/www/src/docs/content/build/client/effect.mdx @@ -58,7 +58,7 @@ const sessions = yield* client.session.list() ## Stream events -Streaming operations such as `event.subscribe()` and `session.log()` return Effect Streams. +Streaming operations such as `event.subscribe()` and `experimental.session.log()` return Effect Streams. {/* prettier-ignore */} ```ts diff --git a/services/www/src/docs/content/build/plugins/effect.mdx b/services/www/src/docs/content/build/plugins/effect.mdx index 91c050bcc0a..6feb090f94e 100644 --- a/services/www/src/docs/content/build/plugins/effect.mdx +++ b/services/www/src/docs/content/build/plugins/effect.mdx @@ -129,7 +129,7 @@ interface Context { readonly mcp: MCPDomain readonly model: ModelDomain /** @deprecated Use `experimental.generate.text`. */ - readonly generate: Pick, "text"> + readonly generate: Pick, "text"> readonly permission: PermissionDomain readonly plugin: Pick, "list"> readonly provider: ProviderDomain diff --git a/services/www/src/docs/content/build/plugins/server.mdx b/services/www/src/docs/content/build/plugins/server.mdx index 20a8425f5fc..87378941fc0 100644 --- a/services/www/src/docs/content/build/plugins/server.mdx +++ b/services/www/src/docs/content/build/plugins/server.mdx @@ -846,11 +846,11 @@ interface SessionContext { instructions: { entry: { list( - input: SessionInstructionsEntryListInput, + input: ExperimentalSessionInstructionsEntryListInput, requestOptions?: RequestOptions, ): Promise - put(input: SessionInstructionsEntryPutInput, requestOptions?: RequestOptions): Promise - remove(input: SessionInstructionsEntryRemoveInput, requestOptions?: RequestOptions): Promise + put(input: ExperimentalSessionInstructionsEntryPutInput, requestOptions?: RequestOptions): Promise + remove(input: ExperimentalSessionInstructionsEntryRemoveInput, requestOptions?: RequestOptions): Promise } } switchAgent(input: SessionSwitchAgentInput, requestOptions?: RequestOptions): Promise @@ -863,7 +863,7 @@ interface SessionContext { compact(input: SessionCompactInput, requestOptions?: RequestOptions): Promise synthetic(input: SessionSyntheticInput, requestOptions?: RequestOptions): Promise interrupt(input: SessionInterruptInput, requestOptions?: RequestOptions): Promise<{ interrupted: boolean }> - wait(input: SessionWaitInput, requestOptions?: RequestOptions): Promise + wait(input: ExperimentalSessionWaitInput, requestOptions?: RequestOptions): Promise } ```