From 318e83e344eba221652b52dafb5b99b007b72c15 Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Fri, 23 Oct 2026 09:43:12 +1000 Subject: [PATCH 1/5] fix: regenerate broken OpenAPI documents and check them in CI (#58262) --- .github/workflows/test.yml | 5 + packages/protocol/openapi.json | 365 +++++++++++++++++++++++++------ services/www/openapi.json | 365 +++++++++++++++++++++++++------ services/www/public/openapi.json | 365 +++++++++++++++++++++++++------ 4 files changed, 914 insertions(+), 186 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a653c180126..8cbba41cf06 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -133,6 +133,11 @@ jobs: working-directory: packages/client run: bun run check:generated + - name: Check generated OpenAPI document + if: runner.os == 'Linux' + working-directory: packages/protocol + run: bun run check:generated + - name: Check generated documentation if: runner.os == 'Linux' working-directory: services/www diff --git a/packages/protocol/openapi.json b/packages/protocol/openapi.json index 9e8396c5af5..de24c6a4b64 100644 --- a/packages/protocol/openapi.json +++ b/packages/protocol/openapi.json @@ -7781,6 +7781,247 @@ "summary": "List MCP resources" } }, + "/api/experimental/client-mcp/token": { + "post": { + "tags": ["mcp"], + "operationId": "experimental.mcp.client.token", + "parameters": [ + { + "name": "x-opencode-ticket", + "in": "header", + "schema": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "required": false + }, + { + "name": "location", + "in": "query", + "schema": { + "anyOf": [ + { + "type": "object", + "properties": { + "directory": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, + { + "type": "null" + } + ] + }, + "required": false, + "style": "deepObject", + "explode": true + }, + { + "name": "name", + "in": "query", + "schema": { + "type": "string" + }, + "required": true + } + ], + "security": [], + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "location": { + "$ref": "#/components/schemas/Location.PublicRef" + }, + "data": { + "$ref": "#/components/schemas/PtyTicket.ConnectToken" + } + }, + "required": ["location", "data"], + "additionalProperties": false + } + } + } + }, + "400": { + "description": "InvalidRequestError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/InvalidRequestErrorEncoded" + } + } + } + }, + "401": { + "description": "UnauthorizedError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UnauthorizedErrorEncoded" + } + } + } + }, + "403": { + "description": "ForbiddenError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ForbiddenErrorEncoded" + } + } + } + }, + "404": { + "description": "LocationNotFoundError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LocationNotFoundErrorEncoded" + } + } + } + } + }, + "description": "Create a short-lived single-use ticket for opening a client MCP WebSocket connection from a browser.", + "summary": "Create client MCP WebSocket token" + } + }, + "/api/experimental/client-mcp": { + "get": { + "tags": ["mcp"], + "operationId": "experimental.mcp.client", + "parameters": [ + { + "name": "location", + "in": "query", + "schema": { + "anyOf": [ + { + "type": "object", + "properties": { + "directory": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, + { + "type": "null" + } + ] + }, + "required": false + }, + { + "name": "name", + "in": "query", + "schema": { + "type": "string" + }, + "required": true + }, + { + "name": "ticket", + "in": "query", + "schema": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "required": false + } + ], + "security": [], + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "type": "boolean" + } + } + } + }, + "400": { + "description": "InvalidRequestError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/InvalidRequestErrorEncoded" + } + } + } + }, + "401": { + "description": "UnauthorizedError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UnauthorizedErrorEncoded" + } + } + } + }, + "403": { + "description": "ForbiddenError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ForbiddenErrorEncoded" + } + } + } + }, + "404": { + "description": "LocationNotFoundError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LocationNotFoundErrorEncoded" + } + } + } + } + }, + "description": "Upgrade to a WebSocket over which the client hosts an MCP server named after `name`; its tools stay available while the socket is open. One JSON-RPC message per text frame. Experimental: may change without compatibility guarantees.", + "summary": "Attach client MCP server", + "x-websocket": true + } + }, "/api/credential": { "get": { "tags": ["credential"], @@ -13175,6 +13416,68 @@ "summary": "VCS diff" } }, + "/api/debug/heap-dump": { + "post": { + "tags": ["debug"], + "operationId": "debug.heapDump", + "parameters": [], + "security": [], + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "path": { + "type": "string" + }, + "pid": { + "type": "integer" + } + }, + "required": ["path", "pid"], + "additionalProperties": false + } + } + } + }, + "400": { + "description": "InvalidRequestError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/InvalidRequestErrorEncoded" + } + } + } + }, + "401": { + "description": "UnauthorizedError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UnauthorizedErrorEncoded" + } + } + } + }, + "500": { + "description": "UnknownError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UnknownErrorEncoded" + } + } + } + } + }, + "description": "Write a JavaScript heap snapshot of the server process into its log directory and return the server-local path once the file is complete. Pauses the server while the heap serializes and can temporarily increase its memory use. The snapshot can contain credentials, prompts, and file contents.", + "summary": "Write a heap snapshot" + } + }, "/api/debug/location": { "get": { "tags": ["debug"], @@ -13416,68 +13719,6 @@ { "type": "null" } - "/api/debug/heap-dump": { - "post": { - "tags": ["debug"], - "operationId": "debug.heapDump", - "parameters": [], - "security": [], - "responses": { - "200": { - "description": "Success", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "pid": { - "type": "integer" - } - }, - "required": ["path", "pid"], - "additionalProperties": false - } - } - } - }, - "400": { - "description": "InvalidRequestError", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/InvalidRequestErrorEncoded" - } - } - } - }, - "401": { - "description": "UnauthorizedError", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/UnauthorizedErrorEncoded" - } - } - } - }, - "500": { - "description": "UnknownError", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/UnknownErrorEncoded" - } - } - } - } - }, - "description": "Write a JavaScript heap snapshot of the server process into its log directory and return the server-local path once the file is complete. Pauses the server while the heap serializes and can temporarily increase its memory use. The snapshot can contain credentials, prompts, and file contents.", - "summary": "Write a heap snapshot" - } - }, ] } }, diff --git a/services/www/openapi.json b/services/www/openapi.json index 9e8396c5af5..de24c6a4b64 100644 --- a/services/www/openapi.json +++ b/services/www/openapi.json @@ -7781,6 +7781,247 @@ "summary": "List MCP resources" } }, + "/api/experimental/client-mcp/token": { + "post": { + "tags": ["mcp"], + "operationId": "experimental.mcp.client.token", + "parameters": [ + { + "name": "x-opencode-ticket", + "in": "header", + "schema": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "required": false + }, + { + "name": "location", + "in": "query", + "schema": { + "anyOf": [ + { + "type": "object", + "properties": { + "directory": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, + { + "type": "null" + } + ] + }, + "required": false, + "style": "deepObject", + "explode": true + }, + { + "name": "name", + "in": "query", + "schema": { + "type": "string" + }, + "required": true + } + ], + "security": [], + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "location": { + "$ref": "#/components/schemas/Location.PublicRef" + }, + "data": { + "$ref": "#/components/schemas/PtyTicket.ConnectToken" + } + }, + "required": ["location", "data"], + "additionalProperties": false + } + } + } + }, + "400": { + "description": "InvalidRequestError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/InvalidRequestErrorEncoded" + } + } + } + }, + "401": { + "description": "UnauthorizedError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UnauthorizedErrorEncoded" + } + } + } + }, + "403": { + "description": "ForbiddenError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ForbiddenErrorEncoded" + } + } + } + }, + "404": { + "description": "LocationNotFoundError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LocationNotFoundErrorEncoded" + } + } + } + } + }, + "description": "Create a short-lived single-use ticket for opening a client MCP WebSocket connection from a browser.", + "summary": "Create client MCP WebSocket token" + } + }, + "/api/experimental/client-mcp": { + "get": { + "tags": ["mcp"], + "operationId": "experimental.mcp.client", + "parameters": [ + { + "name": "location", + "in": "query", + "schema": { + "anyOf": [ + { + "type": "object", + "properties": { + "directory": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, + { + "type": "null" + } + ] + }, + "required": false + }, + { + "name": "name", + "in": "query", + "schema": { + "type": "string" + }, + "required": true + }, + { + "name": "ticket", + "in": "query", + "schema": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "required": false + } + ], + "security": [], + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "type": "boolean" + } + } + } + }, + "400": { + "description": "InvalidRequestError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/InvalidRequestErrorEncoded" + } + } + } + }, + "401": { + "description": "UnauthorizedError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UnauthorizedErrorEncoded" + } + } + } + }, + "403": { + "description": "ForbiddenError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ForbiddenErrorEncoded" + } + } + } + }, + "404": { + "description": "LocationNotFoundError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LocationNotFoundErrorEncoded" + } + } + } + } + }, + "description": "Upgrade to a WebSocket over which the client hosts an MCP server named after `name`; its tools stay available while the socket is open. One JSON-RPC message per text frame. Experimental: may change without compatibility guarantees.", + "summary": "Attach client MCP server", + "x-websocket": true + } + }, "/api/credential": { "get": { "tags": ["credential"], @@ -13175,6 +13416,68 @@ "summary": "VCS diff" } }, + "/api/debug/heap-dump": { + "post": { + "tags": ["debug"], + "operationId": "debug.heapDump", + "parameters": [], + "security": [], + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "path": { + "type": "string" + }, + "pid": { + "type": "integer" + } + }, + "required": ["path", "pid"], + "additionalProperties": false + } + } + } + }, + "400": { + "description": "InvalidRequestError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/InvalidRequestErrorEncoded" + } + } + } + }, + "401": { + "description": "UnauthorizedError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UnauthorizedErrorEncoded" + } + } + } + }, + "500": { + "description": "UnknownError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UnknownErrorEncoded" + } + } + } + } + }, + "description": "Write a JavaScript heap snapshot of the server process into its log directory and return the server-local path once the file is complete. Pauses the server while the heap serializes and can temporarily increase its memory use. The snapshot can contain credentials, prompts, and file contents.", + "summary": "Write a heap snapshot" + } + }, "/api/debug/location": { "get": { "tags": ["debug"], @@ -13416,68 +13719,6 @@ { "type": "null" } - "/api/debug/heap-dump": { - "post": { - "tags": ["debug"], - "operationId": "debug.heapDump", - "parameters": [], - "security": [], - "responses": { - "200": { - "description": "Success", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "pid": { - "type": "integer" - } - }, - "required": ["path", "pid"], - "additionalProperties": false - } - } - } - }, - "400": { - "description": "InvalidRequestError", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/InvalidRequestErrorEncoded" - } - } - } - }, - "401": { - "description": "UnauthorizedError", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/UnauthorizedErrorEncoded" - } - } - } - }, - "500": { - "description": "UnknownError", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/UnknownErrorEncoded" - } - } - } - } - }, - "description": "Write a JavaScript heap snapshot of the server process into its log directory and return the server-local path once the file is complete. Pauses the server while the heap serializes and can temporarily increase its memory use. The snapshot can contain credentials, prompts, and file contents.", - "summary": "Write a heap snapshot" - } - }, ] } }, diff --git a/services/www/public/openapi.json b/services/www/public/openapi.json index 9e8396c5af5..de24c6a4b64 100644 --- a/services/www/public/openapi.json +++ b/services/www/public/openapi.json @@ -7781,6 +7781,247 @@ "summary": "List MCP resources" } }, + "/api/experimental/client-mcp/token": { + "post": { + "tags": ["mcp"], + "operationId": "experimental.mcp.client.token", + "parameters": [ + { + "name": "x-opencode-ticket", + "in": "header", + "schema": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "required": false + }, + { + "name": "location", + "in": "query", + "schema": { + "anyOf": [ + { + "type": "object", + "properties": { + "directory": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, + { + "type": "null" + } + ] + }, + "required": false, + "style": "deepObject", + "explode": true + }, + { + "name": "name", + "in": "query", + "schema": { + "type": "string" + }, + "required": true + } + ], + "security": [], + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "location": { + "$ref": "#/components/schemas/Location.PublicRef" + }, + "data": { + "$ref": "#/components/schemas/PtyTicket.ConnectToken" + } + }, + "required": ["location", "data"], + "additionalProperties": false + } + } + } + }, + "400": { + "description": "InvalidRequestError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/InvalidRequestErrorEncoded" + } + } + } + }, + "401": { + "description": "UnauthorizedError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UnauthorizedErrorEncoded" + } + } + } + }, + "403": { + "description": "ForbiddenError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ForbiddenErrorEncoded" + } + } + } + }, + "404": { + "description": "LocationNotFoundError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LocationNotFoundErrorEncoded" + } + } + } + } + }, + "description": "Create a short-lived single-use ticket for opening a client MCP WebSocket connection from a browser.", + "summary": "Create client MCP WebSocket token" + } + }, + "/api/experimental/client-mcp": { + "get": { + "tags": ["mcp"], + "operationId": "experimental.mcp.client", + "parameters": [ + { + "name": "location", + "in": "query", + "schema": { + "anyOf": [ + { + "type": "object", + "properties": { + "directory": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, + { + "type": "null" + } + ] + }, + "required": false + }, + { + "name": "name", + "in": "query", + "schema": { + "type": "string" + }, + "required": true + }, + { + "name": "ticket", + "in": "query", + "schema": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + }, + "required": false + } + ], + "security": [], + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "type": "boolean" + } + } + } + }, + "400": { + "description": "InvalidRequestError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/InvalidRequestErrorEncoded" + } + } + } + }, + "401": { + "description": "UnauthorizedError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UnauthorizedErrorEncoded" + } + } + } + }, + "403": { + "description": "ForbiddenError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ForbiddenErrorEncoded" + } + } + } + }, + "404": { + "description": "LocationNotFoundError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LocationNotFoundErrorEncoded" + } + } + } + } + }, + "description": "Upgrade to a WebSocket over which the client hosts an MCP server named after `name`; its tools stay available while the socket is open. One JSON-RPC message per text frame. Experimental: may change without compatibility guarantees.", + "summary": "Attach client MCP server", + "x-websocket": true + } + }, "/api/credential": { "get": { "tags": ["credential"], @@ -13175,6 +13416,68 @@ "summary": "VCS diff" } }, + "/api/debug/heap-dump": { + "post": { + "tags": ["debug"], + "operationId": "debug.heapDump", + "parameters": [], + "security": [], + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "path": { + "type": "string" + }, + "pid": { + "type": "integer" + } + }, + "required": ["path", "pid"], + "additionalProperties": false + } + } + } + }, + "400": { + "description": "InvalidRequestError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/InvalidRequestErrorEncoded" + } + } + } + }, + "401": { + "description": "UnauthorizedError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UnauthorizedErrorEncoded" + } + } + } + }, + "500": { + "description": "UnknownError", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UnknownErrorEncoded" + } + } + } + } + }, + "description": "Write a JavaScript heap snapshot of the server process into its log directory and return the server-local path once the file is complete. Pauses the server while the heap serializes and can temporarily increase its memory use. The snapshot can contain credentials, prompts, and file contents.", + "summary": "Write a heap snapshot" + } + }, "/api/debug/location": { "get": { "tags": ["debug"], @@ -13416,68 +13719,6 @@ { "type": "null" } - "/api/debug/heap-dump": { - "post": { - "tags": ["debug"], - "operationId": "debug.heapDump", - "parameters": [], - "security": [], - "responses": { - "200": { - "description": "Success", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "path": { - "type": "string" - }, - "pid": { - "type": "integer" - } - }, - "required": ["path", "pid"], - "additionalProperties": false - } - } - } - }, - "400": { - "description": "InvalidRequestError", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/InvalidRequestErrorEncoded" - } - } - } - }, - "401": { - "description": "UnauthorizedError", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/UnauthorizedErrorEncoded" - } - } - } - }, - "500": { - "description": "UnknownError", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/UnknownErrorEncoded" - } - } - } - } - }, - "description": "Write a JavaScript heap snapshot of the server process into its log directory and return the server-local path once the file is complete. Pauses the server while the heap serializes and can temporarily increase its memory use. The snapshot can contain credentials, prompts, and file contents.", - "summary": "Write a heap snapshot" - } - }, ] } }, From cca52cfe65e89d55f0b645327e5cf751cb99ded6 Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Thu, 22 Oct 2026 18:43:55 -0500 Subject: [PATCH 2/5] refactor(ai): decode WebSocket frames once and derive provider option types from schemas (#58001) --- packages/ai/src/experimental/evaluation.ts | 13 +- packages/ai/src/protocols/mistral-chat.ts | 19 +-- .../src/protocols/open-responses-channel.ts | 160 +++++++++--------- .../protocols/open-responses-continuation.ts | 21 ++- packages/ai/src/protocols/venice-chat.ts | 40 +---- packages/ai/src/protocols/zai-chat.ts | 30 ++-- packages/ai/src/protocols/zai-messages.ts | 14 +- 7 files changed, 135 insertions(+), 162 deletions(-) diff --git a/packages/ai/src/experimental/evaluation.ts b/packages/ai/src/experimental/evaluation.ts index 06d656c67b6..57bf67cc76e 100644 --- a/packages/ai/src/experimental/evaluation.ts +++ b/packages/ai/src/experimental/evaluation.ts @@ -1,8 +1,8 @@ import { Effect, Schema } from "effect" +import { tryRequest } from "../media-model.js" import { AIError, HttpOptions, - InvalidRequestError, ModelID, ProviderID, ProviderMetadata, @@ -223,16 +223,7 @@ export function run, AIError, Service> export function run(input: EvaluationRequest): Effect.Effect export function run(input: EvaluationRequest | EvaluationRequestInput) { - return Effect.try({ - try: () => request(input), - catch: (cause) => - new AIError({ - reason: new InvalidRequestError({ - message: cause instanceof Error ? cause.message : String(cause), - cause, - }), - }), - }).pipe(Effect.flatMap(EvaluationClient.evaluate)) + return tryRequest(() => request(input)).pipe(Effect.flatMap(EvaluationClient.evaluate)) } export const Evaluation = { diff --git a/packages/ai/src/protocols/mistral-chat.ts b/packages/ai/src/protocols/mistral-chat.ts index fe573bb7e5e..619f169d2a2 100644 --- a/packages/ai/src/protocols/mistral-chat.ts +++ b/packages/ai/src/protocols/mistral-chat.ts @@ -102,28 +102,19 @@ const MistralTool = Schema.Struct({ }) type MistralTool = Schema.Schema.Type +const ReasoningEffort = ProviderShared.knownString<"none" | "minimal" | "low" | "medium" | "high" | "xhigh">() +export type ReasoningEffort = typeof ReasoningEffort.Type + const MistralOptions = Schema.Struct({ safePrompt: Schema.optional(Schema.Boolean), documentImageLimit: Schema.optional(Schema.Number), documentPageLimit: Schema.optional(Schema.Number), parallelToolCalls: Schema.optional(Schema.Boolean), - reasoningEffort: Schema.optional(Schema.String), + reasoningEffort: Schema.optional(ReasoningEffort), promptMode: Schema.optional(Schema.Literal("reasoning")), promptCacheKey: Schema.optional(Schema.String), }) - -export type ReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | (string & {}) - -export type ProviderOptionsInput = { - readonly safePrompt?: boolean - readonly documentImageLimit?: number - readonly documentPageLimit?: number - readonly parallelToolCalls?: boolean - readonly reasoningEffort?: ReasoningEffort - readonly promptMode?: "reasoning" - readonly promptCacheKey?: string - readonly [key: string]: unknown -} +export type ProviderOptionsInput = typeof MistralOptions.Type & { readonly [key: string]: unknown } export const MistralBody = Schema.Struct({ model: Schema.String, diff --git a/packages/ai/src/protocols/open-responses-channel.ts b/packages/ai/src/protocols/open-responses-channel.ts index 233d528ec1c..2317eb0885c 100644 --- a/packages/ai/src/protocols/open-responses-channel.ts +++ b/packages/ai/src/protocols/open-responses-channel.ts @@ -1,10 +1,12 @@ import { Effect, Schema, Stream } from "effect" import { Headers } from "effect/http" import { Framing } from "../route/framing.js" -import type { HttpContext } from "../schema/index.js" +import type { AIError, HttpContext } from "../schema/index.js" import { HttpTransport, WebSocketTransport, + type ChannelCreate, + type ChannelObservation, type Transport, type WebSocketChannelDriver, type WebSocketChannelExchange, @@ -48,9 +50,81 @@ const message = (body: unknown) => return { request: decoded, message: encodeMessage(decoded) } }) -const driver = (options: Options, body: string): WebSocketChannelDriver => { +const driver = (options: Options, body: string): OpenResponsesContinuation.BaseDriver => { let responseID: string | undefined let terminal = false + const observeEvent = Effect.fnUntraced(function* ( + _create: ChannelCreate, + frame: string, + event: OpenResponses.Event, + ): Effect.fn.Return { + if (terminal) + return yield* ProviderShared.eventError( + options.id, + `${options.name} emitted ${event.type} after a terminal event`, + frame, + ) + if (event.type === "error") { + terminal = true + return { + type: "provider-failure", + error: OpenResponses.providerFailure(event, `${options.name} stream error`, frame), + } + } + if (event.type === "response.failed") { + terminal = true + if (responseID && event.response?.id && event.response.id !== responseID) + return yield* ProviderShared.eventError( + options.id, + `${options.name} response ID changed during execution`, + frame, + ) + return { + type: "provider-failure", + error: OpenResponses.providerFailure(event, `${options.name} response failed`, frame), + } + } + if (event.type === "response.created") { + const created = event.response?.id + if (responseID) + return yield* ProviderShared.eventError( + options.id, + `${options.name} emitted duplicate response.created`, + frame, + ) + if (!created) + return yield* ProviderShared.eventError( + options.id, + `${options.name} response.created is missing response.id`, + frame, + ) + responseID = created + return { type: "frame", frame } + } + // Keepalives and provider notifications carry no response state and may precede response.created. + if (!event.type.startsWith("response.")) return { type: "frame", frame } + if (!responseID) + return yield* ProviderShared.eventError( + options.id, + `${options.name} emitted ${event.type} before response.created`, + frame, + ) + if (event.response?.id && event.response.id !== responseID) + return yield* ProviderShared.eventError( + options.id, + `${options.name} response ID changed during execution`, + frame, + ) + if (event.type === "response.completed") { + terminal = true + return { type: "completed", frame } + } + if (event.type === "response.incomplete") { + terminal = true + return { type: "incomplete", frame } + } + return { type: "frame", frame } + }) return { create: () => Effect.sync(() => { @@ -58,80 +132,14 @@ const driver = (options: Options, body: string): WebSocketChannelDriver => { terminal = false return { message: body, mode: "full" } }), - observe: (_create, frame) => - Effect.gen(function* () { - const event = yield* OpenResponses.decodeChannelEvent(frame).pipe( - Effect.mapError((cause) => - ProviderShared.eventError(options.id, `Invalid ${options.name} WebSocket event`, frame, cause), - ), - ) - if (terminal) - return yield* ProviderShared.eventError( - options.id, - `${options.name} emitted ${event.type} after a terminal event`, - frame, - ) - if (event.type === "error") { - terminal = true - return { - type: "provider-failure", - error: OpenResponses.providerFailure(event, `${options.name} stream error`, frame), - } - } - if (event.type === "response.failed") { - terminal = true - if (responseID && event.response?.id && event.response.id !== responseID) - return yield* ProviderShared.eventError( - options.id, - `${options.name} response ID changed during execution`, - frame, - ) - return { - type: "provider-failure", - error: OpenResponses.providerFailure(event, `${options.name} response failed`, frame), - } - } - if (event.type === "response.created") { - const created = event.response?.id - if (responseID) - return yield* ProviderShared.eventError( - options.id, - `${options.name} emitted duplicate response.created`, - frame, - ) - if (!created) - return yield* ProviderShared.eventError( - options.id, - `${options.name} response.created is missing response.id`, - frame, - ) - responseID = created - return { type: "frame", frame } - } - // Keepalives and provider notifications carry no response state and may precede response.created. - if (!event.type.startsWith("response.")) return { type: "frame", frame } - if (!responseID) - return yield* ProviderShared.eventError( - options.id, - `${options.name} emitted ${event.type} before response.created`, - frame, - ) - if (event.response?.id && event.response.id !== responseID) - return yield* ProviderShared.eventError( - options.id, - `${options.name} response ID changed during execution`, - frame, - ) - if (event.type === "response.completed") { - terminal = true - return { type: "completed", frame } - } - if (event.type === "response.incomplete") { - terminal = true - return { type: "incomplete", frame } - } - return { type: "frame", frame } - }), + observeEvent, + observe: (create, frame) => + OpenResponses.decodeChannelEvent(frame).pipe( + Effect.mapError((cause) => + ProviderShared.eventError(options.id, `Invalid ${options.name} WebSocket event`, frame, cause), + ), + Effect.flatMap((event) => observeEvent(create, frame, event)), + ), } } diff --git a/packages/ai/src/protocols/open-responses-continuation.ts b/packages/ai/src/protocols/open-responses-continuation.ts index 6bddcd036b3..074bbb07dc4 100644 --- a/packages/ai/src/protocols/open-responses-continuation.ts +++ b/packages/ai/src/protocols/open-responses-continuation.ts @@ -1,5 +1,10 @@ import { AIError, TransportError } from "../schema/index.js" -import type { ChannelCheckpoint, ChannelObservation, WebSocketChannelDriver } from "../route/transport/index.js" +import type { + ChannelCheckpoint, + ChannelCreate, + ChannelObservation, + WebSocketChannelDriver, +} from "../route/transport/index.js" import { Effect, Option, Schema } from "effect" import * as ProviderShared from "./shared.js" import { OpenResponses } from "./open-responses.js" @@ -20,12 +25,20 @@ interface CheckpointValue { */ export type Shape = (request: Readonly>) => Readonly> | undefined +export interface BaseDriver extends WebSocketChannelDriver { + readonly observeEvent?: ( + create: ChannelCreate, + frame: string, + event: OpenResponses.Event, + ) => Effect.Effect +} + export interface DriverInput { readonly id: string readonly name: string readonly request: Readonly> readonly message: string - readonly base: WebSocketChannelDriver + readonly base: BaseDriver readonly continuation?: Shape } @@ -157,7 +170,9 @@ export const driver = (input: DriverInput): WebSocketChannelDriver => { ProviderShared.eventError(input.id, `Invalid ${input.name} WebSocket event`, frame, cause), ), ) - const observation = yield* input.base.observe(create, frame) + const observation = yield* input.base.observeEvent + ? input.base.observeEvent(create, frame, event) + : input.base.observe(create, frame) if (event.type === "response.output_item.done" && event.item) output.push(event.item) if (observation.type === "provider-failure") { const rejection = code(event) diff --git a/packages/ai/src/protocols/venice-chat.ts b/packages/ai/src/protocols/venice-chat.ts index cd2c1b36ecf..660611700be 100644 --- a/packages/ai/src/protocols/venice-chat.ts +++ b/packages/ai/src/protocols/venice-chat.ts @@ -5,15 +5,16 @@ import { classifyProviderFailure } from "../provider-error.js" import { OpenAIChat } from "./openai-chat.js" import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared.js" import { cacheControl } from "./utils/cache.js" +import { OpenResponsesOptions } from "./utils/open-responses-options.js" // --------------------------------------------------------------------------- // Public options and request body // --------------------------------------------------------------------------- -export type ReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | (string & {}) +export type ReasoningEffort = OpenResponsesOptions.ReasoningEffort const Parameters = Schema.Struct({ - enableWebSearch: Schema.optional(Schema.String), + enableWebSearch: Schema.optional(ProviderShared.knownString<"off" | "on" | "auto">()), enableWebScraping: Schema.optional(Schema.Boolean), enableWebCitations: Schema.optional(Schema.Boolean), enableXSearch: Schema.optional(Schema.Boolean), @@ -26,43 +27,17 @@ const Parameters = Schema.Struct({ }) const Reasoning = Schema.Struct({ - effort: Schema.optional(Schema.String), + effort: Schema.optional(OpenResponsesOptions.ReasoningEffort), enabled: Schema.optional(Schema.Boolean), - summary: Schema.optional(Schema.String), + summary: Schema.optional(ProviderShared.knownString<"auto" | "concise" | "detailed">()), }) -export type OptionsInput = { - readonly reasoningEffort?: ReasoningEffort - readonly reasoning?: { - readonly effort?: ReasoningEffort - readonly enabled?: boolean - readonly summary?: "auto" | "concise" | "detailed" | (string & {}) - } - readonly veniceParameters?: Omit & { - readonly enableWebSearch?: "off" | "on" | "auto" | (string & {}) - } - readonly promptCacheKey?: string - readonly promptCacheRetention?: "default" | "extended" | "24h" | (string & {}) - readonly parallelToolCalls?: boolean - readonly maxCompletionTokens?: number - readonly maxTokens?: number - readonly minP?: number - readonly repetitionPenalty?: number - readonly stopTokenIds?: readonly number[] - readonly logprobs?: boolean - readonly topLogprobs?: number - readonly maxTemp?: number - readonly minTemp?: number - readonly responseFormat?: Readonly> - readonly user?: string -} - const Options = Schema.Struct({ - reasoningEffort: Schema.optional(Schema.String), + reasoningEffort: Schema.optional(OpenResponsesOptions.ReasoningEffort), reasoning: Schema.optional(Reasoning), veniceParameters: Schema.optional(Parameters), promptCacheKey: Schema.optional(Schema.String), - promptCacheRetention: Schema.optional(Schema.String), + promptCacheRetention: Schema.optional(ProviderShared.knownString<"default" | "extended" | "24h">()), parallelToolCalls: Schema.optional(Schema.Boolean), maxCompletionTokens: Schema.optional(Schema.Number), maxTokens: Schema.optional(Schema.Number), @@ -76,6 +51,7 @@ const Options = Schema.Struct({ responseFormat: Schema.optional(JsonObject), user: Schema.optional(Schema.String), }) +export type OptionsInput = typeof Options.Type const ToolCall = Schema.Struct({ ...OpenAIChat.OpenAIChatAssistantToolCall.fields, diff --git a/packages/ai/src/protocols/zai-chat.ts b/packages/ai/src/protocols/zai-chat.ts index a82135f7bb3..6455f3fbe20 100644 --- a/packages/ai/src/protocols/zai-chat.ts +++ b/packages/ai/src/protocols/zai-chat.ts @@ -3,34 +3,28 @@ import { Protocol } from "../route/protocol.js" import type { LanguageModelCompatibility, LLMRequest } from "../schema/index.js" import { OpenAIChat } from "./openai-chat.js" import { ProviderShared } from "./shared.js" +import { OpenResponsesOptions } from "./utils/open-responses-options.js" -export type ReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | (string & {}) - -export type OptionsInput = { - readonly reasoningEffort?: ReasoningEffort - readonly thinking?: { - readonly type?: "enabled" | "disabled" | (string & {}) - /** False retains historical reasoning; omission preserves the endpoint's default. */ - readonly clear_thinking?: boolean - } - readonly toolStream?: boolean - readonly doSample?: boolean - readonly responseFormat?: { readonly type: "text" | "json_object" | (string & {}) } - readonly requestID?: string - readonly userID?: string -} +export type ReasoningEffort = OpenResponsesOptions.ReasoningEffort const Options = Schema.Struct({ - reasoningEffort: Schema.optional(Schema.String), + reasoningEffort: Schema.optional(OpenResponsesOptions.ReasoningEffort), thinking: Schema.optional( - Schema.Struct({ type: Schema.optional(Schema.String), clear_thinking: Schema.optional(Schema.Boolean) }), + Schema.Struct({ + type: Schema.optional(ProviderShared.knownString<"enabled" | "disabled">()), + /** False retains historical reasoning; omission preserves the endpoint's default. */ + clear_thinking: Schema.optional(Schema.Boolean), + }), ), toolStream: Schema.optional(Schema.Boolean), doSample: Schema.optional(Schema.Boolean), - responseFormat: Schema.optional(Schema.Struct({ type: Schema.String })), + responseFormat: Schema.optional( + Schema.Struct({ type: ProviderShared.knownString<"text" | "json_object">() }), + ), requestID: Schema.optional(Schema.String), userID: Schema.optional(Schema.String), }) +export type OptionsInput = typeof Options.Type const Body = Schema.Struct({ ...OpenAIChat.bodyFields, diff --git a/packages/ai/src/protocols/zai-messages.ts b/packages/ai/src/protocols/zai-messages.ts index 4f609c844c9..1336b255474 100644 --- a/packages/ai/src/protocols/zai-messages.ts +++ b/packages/ai/src/protocols/zai-messages.ts @@ -3,17 +3,15 @@ import { Protocol } from "../route/protocol.js" import { LLMRequest } from "../schema/index.js" import { AnthropicMessages } from "./anthropic-messages.js" import { ProviderShared } from "./shared.js" -import type { ZAIChat } from "./zai-chat.js" - -export type OptionsInput = { - readonly effort?: ZAIChat.ReasoningEffort - readonly thinking?: { readonly type: "enabled" | "adaptive" | "disabled" | (string & {}) } -} +import { OpenResponsesOptions } from "./utils/open-responses-options.js" const Options = Schema.Struct({ - effort: Schema.optional(Schema.String), - thinking: Schema.optional(Schema.Struct({ type: Schema.String })), + effort: Schema.optional(OpenResponsesOptions.ReasoningEffort), + thinking: Schema.optional( + Schema.Struct({ type: ProviderShared.knownString<"enabled" | "adaptive" | "disabled">() }), + ), }) +export type OptionsInput = typeof Options.Type const Body = Schema.Struct({ ...AnthropicMessages.AnthropicMessagesBody.fields, thinking: Options.fields.thinking, From 7a62a466959bb49838b666bf5ba6222fb14b55cd Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Thu, 22 Oct 2026 18:53:01 -0500 Subject: [PATCH 3/5] refactor: remove redundant casts and duplicate helpers across sdk, plugin, codemode, and schema (#57996) --- packages/client/src/effect/service.ts | 2 +- packages/codemode/src/stdlib/url.ts | 2 +- packages/plugin/src/promise/adapter.ts | 5 +++-- packages/plugin/src/promise/agent.ts | 8 ++++---- packages/plugin/src/promise/mcp.ts | 8 ++++---- packages/plugin/src/promise/model.ts | 8 ++++---- packages/plugin/src/promise/provider.ts | 6 +++--- packages/plugin/src/promise/skill.ts | 8 ++++---- packages/plugin/src/promise/types.ts | 9 --------- packages/schema/src/workspace-id.ts | 1 - packages/sdk/src/internal/instances.ts | 3 +-- packages/sdk/src/logging.ts | 10 ++++------ 12 files changed, 29 insertions(+), 41 deletions(-) delete mode 100644 packages/plugin/src/promise/types.ts diff --git a/packages/client/src/effect/service.ts b/packages/client/src/effect/service.ts index c8a809961d5..4ec16aa7fcb 100644 --- a/packages/client/src/effect/service.ts +++ b/packages/client/src/effect/service.ts @@ -9,7 +9,7 @@ import { decide, fallback, headers, probeResult, same } from "../service-probe.j export * from "../service.js" export { headers } /** Contents of the local service registration file. */ -export type Info = import("../service.js").Info +export type Info = typeof Info.Type // Find, start, and stop the local opencode background service. // diff --git a/packages/codemode/src/stdlib/url.ts b/packages/codemode/src/stdlib/url.ts index 666f692045c..f04e2cac5e5 100644 --- a/packages/codemode/src/stdlib/url.ts +++ b/packages/codemode/src/stdlib/url.ts @@ -103,7 +103,7 @@ export const urlGlobal = (ctx: Interpreter) => { : (thisValue, value) => { const target = self(thisValue, name) try { - ;(target.url as unknown as Record)[name] = coerceToString(value) + target.url[name] = coerceToString(value) } catch (error) { if (error instanceof PendingThrow) throw error throw typeError(`URL.${name} received an invalid value.`) diff --git a/packages/plugin/src/promise/adapter.ts b/packages/plugin/src/promise/adapter.ts index f7088b4cfdc..34e8c908657 100644 --- a/packages/plugin/src/promise/adapter.ts +++ b/packages/plugin/src/promise/adapter.ts @@ -223,6 +223,7 @@ export function fromPromise(plugin: Plugin) { const [{ ClientApi }, { OpenCodeEvent }] = yield* Effect.promise(() => Promise.all([import("@opencode/protocol/client"), import("@opencode/protocol/groups/event")]), ) + const encodeOpenCodeEvent = Schema.encodeUnknownEffect(OpenCodeEvent) const AgentEndpoints = ClientApi.groups["server.agent"].endpoints const CommandEndpoints = ClientApi.groups["server.command"].endpoints const CredentialEndpoints = ClientApi.groups["server.credential"].endpoints @@ -331,8 +332,8 @@ export function fromPromise(plugin: Plugin) { subscribe: (options) => streams( host.event.subscribe().pipe( - Stream.mapEffect((event) => Schema.encodeUnknownEffect(OpenCodeEvent)(event)), - Stream.map((event) => event as unknown as PromiseEvent), + Stream.mapEffect((event) => encodeOpenCodeEvent(event)), + Stream.map((event) => event as PromiseEvent), ), options, ), diff --git a/packages/plugin/src/promise/agent.ts b/packages/plugin/src/promise/agent.ts index b6b8e3bfd9d..687420a1a7a 100644 --- a/packages/plugin/src/promise/agent.ts +++ b/packages/plugin/src/promise/agent.ts @@ -1,13 +1,13 @@ import type { AgentApi } from "@opencode/client/promise/api" import type { Agent } from "@opencode/schema/agent" +import type { Types } from "effect" import type { Transform } from "./registration.js" -import type { DeepMutable } from "./types.js" export interface AgentEditor { - list(): readonly DeepMutable[] - get(id: string): DeepMutable | undefined + list(): readonly Types.DeepMutable[] + get(id: string): Types.DeepMutable | undefined default(id: string | undefined): void - update(id: string, update: (agent: DeepMutable) => void): void + update(id: string, update: (agent: Types.DeepMutable) => void): void remove(id: string): void } diff --git a/packages/plugin/src/promise/mcp.ts b/packages/plugin/src/promise/mcp.ts index bffe93a89f8..1731ae1dd76 100644 --- a/packages/plugin/src/promise/mcp.ts +++ b/packages/plugin/src/promise/mcp.ts @@ -1,13 +1,13 @@ import type { McpApi } from "@opencode/client/promise/api" import type { Mcp } from "@opencode/schema/mcp" +import type { Types } from "effect" import type { Transform } from "./registration.js" -import type { DeepMutable } from "./types.js" export interface MCPEditor { - list(): readonly [string, DeepMutable][] - get(name: string): DeepMutable | undefined + list(): readonly [string, Types.DeepMutable][] + get(name: string): Types.DeepMutable | undefined set(name: string, config: Mcp.ServerConfig): void - update(name: string, update: (config: DeepMutable) => void): void + update(name: string, update: (config: Types.DeepMutable) => void): void remove(name: string): void } diff --git a/packages/plugin/src/promise/model.ts b/packages/plugin/src/promise/model.ts index 55248eaf322..f566277cbfd 100644 --- a/packages/plugin/src/promise/model.ts +++ b/packages/plugin/src/promise/model.ts @@ -1,15 +1,15 @@ import type { ModelApi } from "@opencode/client/promise/api" import type { Model } from "@opencode/schema/model" +import type { Types } from "effect" import type { ProviderRecord } from "./provider.js" import type { Transform } from "./registration.js" -import type { DeepMutable } from "./types.js" export interface ModelEditor { /** Candidates from available providers, including models disabled by earlier transforms. */ - list(providerID?: string): readonly DeepMutable[] - get(providerID: string, modelID: string): DeepMutable | undefined + list(providerID?: string): readonly Types.DeepMutable[] + get(providerID: string, modelID: string): Types.DeepMutable | undefined /** Edits raw model overrides; cannot create an unavailable provider. */ - update(providerID: string, modelID: string, update: (model: DeepMutable) => void): void + update(providerID: string, modelID: string, update: (model: Types.DeepMutable) => void): void remove(providerID: string, modelID: string): void readonly default: { get(): { providerID: string; modelID: string } | undefined diff --git a/packages/plugin/src/promise/provider.ts b/packages/plugin/src/promise/provider.ts index d8f5383fae8..466ff7fdfaf 100644 --- a/packages/plugin/src/promise/provider.ts +++ b/packages/plugin/src/promise/provider.ts @@ -2,8 +2,8 @@ import type { ProviderApi } from "@opencode/client/promise/api" import type { Model } from "@opencode/schema/model" import type { Provider } from "@opencode/schema/provider" import type { ConnectionInfo } from "@opencode/client" +import type { Types } from "effect" import type { Transform } from "./registration.js" -import type { DeepMutable } from "./types.js" /** Provider metadata and immutable source definitions, including inactive providers. */ export interface ProviderRecord { @@ -17,12 +17,12 @@ export interface ProviderEditor { get(providerID: string): ProviderRecord | undefined /** A discovered account-specific inventory can be bound to the connection that produced it. */ add(input: { info: Provider.Info; models: readonly Model.Info[]; sourceConnection?: ConnectionInfo }): void - update(providerID: string, update: (provider: DeepMutable) => void): void + update(providerID: string, update: (provider: Types.DeepMutable) => void): void remove(providerID: string): void readonly models: { set(providerID: string, models: readonly Model.Info[]): void /** Updates an owned copy of a source definition. */ - update(providerID: string, modelID: string, update: (model: DeepMutable) => void): void + update(providerID: string, modelID: string, update: (model: Types.DeepMutable) => void): void remove(providerID: string, modelID: string): void } } diff --git a/packages/plugin/src/promise/skill.ts b/packages/plugin/src/promise/skill.ts index a0733f86a31..d357352c28c 100644 --- a/packages/plugin/src/promise/skill.ts +++ b/packages/plugin/src/promise/skill.ts @@ -1,13 +1,13 @@ import type { SkillApi } from "@opencode/client/promise/api" import type { Skill } from "@opencode/schema/skill" +import type { Types } from "effect" import type { Transform } from "./registration.js" -import type { DeepMutable } from "./types.js" export interface SkillEditor { - list(): readonly DeepMutable[] - get(id: string): DeepMutable | undefined + list(): readonly Types.DeepMutable[] + get(id: string): Types.DeepMutable | undefined add(skill: Skill.Info): void - update(id: string, update: (skill: DeepMutable) => void): void + update(id: string, update: (skill: Types.DeepMutable) => void): void remove(id: string): void } diff --git a/packages/plugin/src/promise/types.ts b/packages/plugin/src/promise/types.ts deleted file mode 100644 index 418fa6c2439..00000000000 --- a/packages/plugin/src/promise/types.ts +++ /dev/null @@ -1,9 +0,0 @@ -export type DeepMutable = A extends (...args: never[]) => unknown - ? A - : A extends ReadonlyMap - ? Map, DeepMutable> - : A extends ReadonlyArray - ? DeepMutable[] - : A extends object - ? { -readonly [K in keyof A]: DeepMutable } - : A diff --git a/packages/schema/src/workspace-id.ts b/packages/schema/src/workspace-id.ts index e930e5df391..0fcc0bcad34 100644 --- a/packages/schema/src/workspace-id.ts +++ b/packages/schema/src/workspace-id.ts @@ -10,7 +10,6 @@ export const WorkspaceID = Schema.String.check(Schema.isStartingWith("wrk")).pip return { ascending: (id?: string) => { if (!id) return create() - if (!id.startsWith("wrk")) throw new Error(`ID ${id} does not start with wrk`) return schema.make(id) }, create, diff --git a/packages/sdk/src/internal/instances.ts b/packages/sdk/src/internal/instances.ts index 1adecd3a4ea..ad2a6c6d460 100644 --- a/packages/sdk/src/internal/instances.ts +++ b/packages/sdk/src/internal/instances.ts @@ -4,7 +4,6 @@ import { Instance } from "@opencode/core/instance" import { LocationServiceMap } from "@opencode/core/location-service-map" import { Plugin } from "@opencode/core/plugin" import type { InstancePlugins } from "@opencode/core/plugin/instance" -import { Location } from "@opencode/schema/location" import type { Session } from "@opencode/schema/session" import { makeGlobalNode } from "@opencode/util/effect/app-node" import type { LayerNode } from "@opencode/util/effect/layer-node" @@ -66,7 +65,7 @@ export function layer(options: Options, replacements: () => LayerNode.Replacemen Layer.unwrap( Effect.gen(function* () { const configuration = yield* options.configure(input.key).pipe(Effect.orDie) - return Instance.layer(Location.Ref.make({ directory: input.directory, workspaceID: input.workspaceID }), { + return Instance.layer(input, { plugins: configuration.plugins, replacements: [ ...replacements(), diff --git a/packages/sdk/src/logging.ts b/packages/sdk/src/logging.ts index 2838d97222f..9a07c1445d7 100644 --- a/packages/sdk/src/logging.ts +++ b/packages/sdk/src/logging.ts @@ -33,20 +33,18 @@ const levelNames = new Map["logLevel"], LogLevel>([ [levels.fatal, "fatal"], ]) -function normalizeLevel(level: Logger.Options["logLevel"]): LogLevel | undefined { - return levelNames.get(level) -} - export function layer(log?: LogOptions) { const logger = Logger.make((options) => { if (!log) return - const level = normalizeLevel(options.logLevel) + const level = levelNames.get(options.logLevel) if (!level) return const entry = Logger.formatStructured.log(options) const values = Array.isArray(entry.message) ? entry.message : [entry.message] const [message, ...data] = values const details = - data.length === 1 && !Array.isArray(data[0]) ? (data[0] as Readonly>) : undefined + data.length === 1 && typeof data[0] === "object" && data[0] !== null && !Array.isArray(data[0]) + ? (data[0] as Readonly>) + : undefined const { cause: detailCause, ...detailAttributes } = details ?? {} const attributes = { ...entry.annotations, From 91a7fe54cf9e50e844cf2a2ff18df6e8f30e6779 Mon Sep 17 00:00:00 2001 From: Imamuzzaki Abu Salam Date: Fri, 23 Oct 2026 00:02:07 +0000 Subject: [PATCH 4/5] fix(desktop): stop AppImage executable name ending in .desktop (#58263) --- .../desktop/electron-builder.config.test.ts | 13 ++++++++++--- packages/desktop/electron-builder.config.ts | 19 ++++++++++++++++++- .../resources/linux/opencode-desktop.desktop | 4 ++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/packages/desktop/electron-builder.config.test.ts b/packages/desktop/electron-builder.config.test.ts index 49dec8d2681..3b4f618fb12 100644 --- a/packages/desktop/electron-builder.config.test.ts +++ b/packages/desktop/electron-builder.config.test.ts @@ -51,7 +51,14 @@ test.each(channels)("channel identity for $channel", ({ channel, appId }) => { const config = load(channel) expect(config.appId).toBe(appId) expect(config.extraMetadata?.desktopName).toBe(`${appId}.desktop`) - expect(config.linux?.executableName).toBe(appId) + // The executable must never end in `.desktop`: libappimage resolves the + // AppImage's desktop entry by globbing `*.desktop`, and an ELF matching + // that glob breaks integration (anomalyco/opencode#51867). + expect(config.linux?.executableName).toBe(appId.replace(/\.desktop$/, "")) + expect(config.linux?.executableName).not.toMatch(/\.desktop$/) + // The installed `.desktop` filename still derives from `desktopName` so + // window association (StartupWMClass/desktop file basename) is unchanged. + expect(config.linux?.syncDesktopName).toBe(true) expect(config.linux?.desktop?.entry?.StartupWMClass).toBe(appId) for (const fpm of [config.deb?.fpm, config.rpm?.fpm]) { @@ -69,8 +76,8 @@ test.each(channels)("channel identity for $channel", ({ channel, appId }) => { test("legacy Linux launcher stays hidden", async () => { const desktop = await Bun.file(path.join(import.meta.dirname, "resources/linux/opencode-desktop.desktop")).text() - expect(desktop).toContain("Exec=/opt/OpenCode/ai.opencode.desktop %U") - expect(desktop).toContain("Icon=ai.opencode.desktop") + expect(desktop).toContain("Exec=/opt/OpenCode/ai.opencode %U") + expect(desktop).toContain("Icon=ai.opencode") expect(desktop).toContain("StartupWMClass=ai.opencode.desktop") expect(desktop).toContain("NoDisplay=true") }) diff --git a/packages/desktop/electron-builder.config.ts b/packages/desktop/electron-builder.config.ts index 947754454d7..2bb89e1bd7b 100644 --- a/packages/desktop/electron-builder.config.ts +++ b/packages/desktop/electron-builder.config.ts @@ -76,6 +76,19 @@ const APP_IDS = { prod: "ai.opencode.desktop", } as const +// libappimage (used by AppImageLauncher) resolves the .desktop entry inside an +// AppImage by globbing `*.desktop` at the squashfs root. If the main +// executable itself ends in `.desktop` (prod appId `ai.opencode.desktop`), the +// ELF binary matches the glob and is parsed as a desktop entry, so +// integration fails with `Malformed desktop entry: Unexpected char '\x7f' at 0` +// (0x7F is the first byte of the ELF magic). +// https://github.com/anomalyco/opencode/issues/51867 +// Strip a trailing `.desktop` so the executable can never collide with the +// desktop-entry glob. Beta/dev appIds end in `.beta`/`.dev` and are unaffected. +function linuxExecutableName(appId: string): string { + return appId.replace(/\.desktop$/, "") +} + const getBase = (appId: string): Configuration => { const target = getCurrentCli() @@ -205,7 +218,11 @@ const getBase = (appId: string): Configuration => { linux: { icon: `resources/icons`, category: "Development", - executableName: appId, + executableName: linuxExecutableName(appId), + // Derive the installed `.desktop` filename from `desktopName` + // (`ai.opencode.desktop.desktop` for prod) instead of `executableName`, + // so window association is unaffected by the executable rename above. + syncDesktopName: true, desktop: { entry: { // Match the installed .desktop file and hicolor icon basename so diff --git a/packages/desktop/resources/linux/opencode-desktop.desktop b/packages/desktop/resources/linux/opencode-desktop.desktop index a5f677412c0..ce895529962 100644 --- a/packages/desktop/resources/linux/opencode-desktop.desktop +++ b/packages/desktop/resources/linux/opencode-desktop.desktop @@ -1,9 +1,9 @@ [Desktop Entry] Name=OpenCode -Exec=/opt/OpenCode/ai.opencode.desktop %U +Exec=/opt/OpenCode/ai.opencode %U Terminal=false Type=Application -Icon=ai.opencode.desktop +Icon=ai.opencode StartupWMClass=ai.opencode.desktop NoDisplay=true Comment=Open source AI coding agent From 199ad46421fbb22c50a6c995666cc7d020f84571 Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Fri, 23 Oct 2026 10:25:37 +1000 Subject: [PATCH 5/5] feat(desktop): capture app and server heap snapshots into one folder (#58259) --- .opencode/skills/opencode-dev/SKILL.md | 4 +- packages/cli/src/commands/commands.ts | 4 + .../src/commands/handlers/debug/heap-dump.ts | 15 ++- packages/cli/test/debug-heap-dump.test.ts | 27 +++++ packages/client/src/effect/api/api.ts | 3 +- .../client/src/effect/generated/client.ts | 7 +- .../client/src/promise/generated/client.ts | 4 +- .../client/src/promise/generated/types.ts | 2 + packages/gui-extensions/README.md | 2 +- packages/gui-extensions/src/debug/contract.ts | 25 ++++ packages/gui-extensions/src/debug/i18n/en.ts | 7 ++ packages/gui-extensions/src/debug/index.ts | 2 + packages/gui-extensions/src/debug/main.ts | 108 ++++++++++++++++++ .../gui-extensions/src/debug/renderer.tsx | 41 ++++++- .../src/debug/server-heap.test.ts | 56 +++++++++ .../gui-extensions/src/debug/server-heap.ts | 58 ++++++++++ packages/gui-extensions/src/main.ts | 2 +- packages/protocol/openapi.json | 21 +++- packages/protocol/src/groups/debug.ts | 15 ++- packages/server/src/handlers/debug.ts | 16 ++- packages/server/test/heap-dump.test.ts | 42 ++++++- services/www/openapi.json | 21 +++- services/www/public/openapi.json | 21 +++- .../www/src/docs/content/cli/commands.mdx | 6 + .../www/src/docs/content/troubleshooting.mdx | 24 ++++ 25 files changed, 508 insertions(+), 25 deletions(-) create mode 100644 packages/gui-extensions/src/debug/contract.ts create mode 100644 packages/gui-extensions/src/debug/main.ts create mode 100644 packages/gui-extensions/src/debug/server-heap.test.ts create mode 100644 packages/gui-extensions/src/debug/server-heap.ts diff --git a/.opencode/skills/opencode-dev/SKILL.md b/.opencode/skills/opencode-dev/SKILL.md index befc8c0177f..3f0c488c78a 100644 --- a/.opencode/skills/opencode-dev/SKILL.md +++ b/.opencode/skills/opencode-dev/SKILL.md @@ -130,7 +130,9 @@ On every platform, including Windows, capture the running background server with opencode debug heap-dump ``` -It discovers the already-running service (never starts or replaces one), calls `POST /api/debug/heap-dump`, waits until the file is complete, and prints its server-local path. Pass `--server ` (with `OPENCODE_PASSWORD`) for a server started with `serve`. A 404 means the running server predates the endpoint. +It discovers the already-running service (never starts or replaces one), calls `POST /api/debug/heap-dump`, waits until the file is complete, and prints its server-local path. Pass `--server ` (with `OPENCODE_PASSWORD`) for a server started with `serve`, and `--directory ` to write somewhere other than the server's log directory (the server creates it; a server that predates the option ignores it and the CLI warns). A 404 means the running server predates the endpoint. + +For desktop memory, run **Capture heap snapshots** from the desktop command palette (`packages/gui-extensions/src/debug/main.ts`). It writes `~/Downloads/opencode-heap-