From 4961d72c0fa23ee23bca9ea59b86a2b13bcf4427 Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Wed, 8 Apr 2026 15:55:14 -0500 Subject: [PATCH] tweak: separate ModelsDev.Model and Config model schemas (#21561) --- packages/opencode/src/config/config.ts | 94 ++++++++++++--- packages/opencode/src/provider/models.ts | 3 - packages/opencode/src/provider/provider.ts | 4 +- packages/sdk/js/src/v2/gen/types.gen.ts | 54 ++++----- packages/sdk/openapi.json | 130 ++++++++++----------- 5 files changed, 169 insertions(+), 116 deletions(-) diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts index efae2ca551..1952e3b572 100644 --- a/packages/opencode/src/config/config.ts +++ b/packages/opencode/src/config/config.ts @@ -786,28 +786,81 @@ export namespace Config { }) export type Layout = z.infer - export const Provider = ModelsDev.Provider.partial() - .extend({ - whitelist: z.array(z.string()).optional(), - blacklist: z.array(z.string()).optional(), - models: z + export const Model = z + .object({ + id: z.string(), + name: z.string(), + family: z.string().optional(), + release_date: z.string(), + attachment: z.boolean(), + reasoning: z.boolean(), + temperature: z.boolean(), + tool_call: z.boolean(), + interleaved: z + .union([ + z.literal(true), + z + .object({ + field: z.enum(["reasoning_content", "reasoning_details"]), + }) + .strict(), + ]) + .optional(), + cost: z + .object({ + input: z.number(), + output: z.number(), + cache_read: z.number().optional(), + cache_write: z.number().optional(), + context_over_200k: z + .object({ + input: z.number(), + output: z.number(), + cache_read: z.number().optional(), + cache_write: z.number().optional(), + }) + .optional(), + }) + .optional(), + limit: z.object({ + context: z.number(), + input: z.number().optional(), + output: z.number(), + }), + modalities: z + .object({ + input: z.array(z.enum(["text", "audio", "image", "video", "pdf"])), + output: z.array(z.enum(["text", "audio", "image", "video", "pdf"])), + }) + .optional(), + experimental: z.boolean().optional(), + status: z.enum(["alpha", "beta", "deprecated"]).optional(), + provider: z.object({ npm: z.string().optional(), api: z.string().optional() }).optional(), + options: z.record(z.string(), z.any()), + headers: z.record(z.string(), z.string()).optional(), + variants: z .record( z.string(), - ModelsDev.Model.partial().extend({ - variants: z - .record( - z.string(), - z - .object({ - disabled: z.boolean().optional().describe("Disable this variant for the model"), - }) - .catchall(z.any()), - ) - .optional() - .describe("Variant-specific configuration"), - }), + z + .object({ + disabled: z.boolean().optional().describe("Disable this variant for the model"), + }) + .catchall(z.any()), ) - .optional(), + .optional() + .describe("Variant-specific configuration"), + }) + .partial() + + export const Provider = z + .object({ + api: z.string().optional(), + name: z.string(), + env: z.array(z.string()), + id: z.string(), + npm: z.string().optional(), + whitelist: z.array(z.string()).optional(), + blacklist: z.array(z.string()).optional(), options: z .object({ apiKey: z.string().optional(), @@ -840,11 +893,14 @@ export namespace Config { }) .catchall(z.any()) .optional(), + models: z.record(z.string(), Model).optional(), }) + .partial() .strict() .meta({ ref: "ProviderConfig", }) + export type Provider = z.infer export const Info = z diff --git a/packages/opencode/src/provider/models.ts b/packages/opencode/src/provider/models.ts index c6ab5d8365..23f61d804e 100644 --- a/packages/opencode/src/provider/models.ts +++ b/packages/opencode/src/provider/models.ts @@ -70,10 +70,7 @@ export namespace ModelsDev { .optional(), experimental: z.boolean().optional(), status: z.enum(["alpha", "beta", "deprecated"]).optional(), - options: z.record(z.string(), z.any()), - headers: z.record(z.string(), z.string()).optional(), provider: z.object({ npm: z.string().optional(), api: z.string().optional() }).optional(), - variants: z.record(z.string(), z.record(z.string(), z.any())).optional(), }) export type Model = z.infer diff --git a/packages/opencode/src/provider/provider.ts b/packages/opencode/src/provider/provider.ts index 9ca49bf8f1..9febf634f2 100644 --- a/packages/opencode/src/provider/provider.ts +++ b/packages/opencode/src/provider/provider.ts @@ -937,8 +937,8 @@ export namespace Provider { npm: model.provider?.npm ?? provider.npm ?? "@ai-sdk/openai-compatible", }, status: model.status ?? "active", - headers: model.headers ?? {}, - options: model.options ?? {}, + headers: {}, + options: {}, cost: { input: model.cost?.input ?? 0, output: model.cost?.output ?? 0, diff --git a/packages/sdk/js/src/v2/gen/types.gen.ts b/packages/sdk/js/src/v2/gen/types.gen.ts index e21e093c6f..4f226e60cf 100644 --- a/packages/sdk/js/src/v2/gen/types.gen.ts +++ b/packages/sdk/js/src/v2/gen/types.gen.ts @@ -1250,6 +1250,29 @@ export type ProviderConfig = { env?: Array id?: string npm?: string + whitelist?: Array + blacklist?: Array + options?: { + apiKey?: string + baseURL?: string + /** + * GitHub Enterprise URL for copilot authentication + */ + enterpriseUrl?: string + /** + * Enable promptCacheKey for this provider (default false) + */ + setCacheKey?: boolean + /** + * Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout. + */ + timeout?: number | false + /** + * Timeout in milliseconds between streamed SSE chunks for this provider. If no chunk arrives within this window, the request is aborted. + */ + chunkTimeout?: number + [key: string]: unknown | string | boolean | number | false | number | undefined + } models?: { [key: string]: { id?: string @@ -1288,16 +1311,16 @@ export type ProviderConfig = { } experimental?: boolean status?: "alpha" | "beta" | "deprecated" + provider?: { + npm?: string + api?: string + } options?: { [key: string]: unknown } headers?: { [key: string]: string } - provider?: { - npm?: string - api?: string - } /** * Variant-specific configuration */ @@ -1312,29 +1335,6 @@ export type ProviderConfig = { } } } - whitelist?: Array - blacklist?: Array - options?: { - apiKey?: string - baseURL?: string - /** - * GitHub Enterprise URL for copilot authentication - */ - enterpriseUrl?: string - /** - * Enable promptCacheKey for this provider (default false) - */ - setCacheKey?: boolean - /** - * Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout. - */ - timeout?: number | false - /** - * Timeout in milliseconds between streamed SSE chunks for this provider. If no chunk arrives within this window, the request is aborted. - */ - chunkTimeout?: number - [key: string]: unknown | string | boolean | number | false | number | undefined - } } export type McpLocalConfig = { diff --git a/packages/sdk/openapi.json b/packages/sdk/openapi.json index 0f3b2c3971..a0672df2d7 100644 --- a/packages/sdk/openapi.json +++ b/packages/sdk/openapi.json @@ -10596,6 +10596,60 @@ "npm": { "type": "string" }, + "whitelist": { + "type": "array", + "items": { + "type": "string" + } + }, + "blacklist": { + "type": "array", + "items": { + "type": "string" + } + }, + "options": { + "type": "object", + "properties": { + "apiKey": { + "type": "string" + }, + "baseURL": { + "type": "string" + }, + "enterpriseUrl": { + "description": "GitHub Enterprise URL for copilot authentication", + "type": "string" + }, + "setCacheKey": { + "description": "Enable promptCacheKey for this provider (default false)", + "type": "boolean" + }, + "timeout": { + "description": "Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.", + "anyOf": [ + { + "description": "Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.", + "type": "integer", + "exclusiveMinimum": 0, + "maximum": 9007199254740991 + }, + { + "description": "Disable timeout for this provider entirely.", + "type": "boolean", + "const": false + } + ] + }, + "chunkTimeout": { + "description": "Timeout in milliseconds between streamed SSE chunks for this provider. If no chunk arrives within this window, the request is aborted.", + "type": "integer", + "exclusiveMinimum": 0, + "maximum": 9007199254740991 + } + }, + "additionalProperties": {} + }, "models": { "type": "object", "propertyNames": { @@ -10725,6 +10779,17 @@ "type": "string", "enum": ["alpha", "beta", "deprecated"] }, + "provider": { + "type": "object", + "properties": { + "npm": { + "type": "string" + }, + "api": { + "type": "string" + } + } + }, "options": { "type": "object", "propertyNames": { @@ -10741,17 +10806,6 @@ "type": "string" } }, - "provider": { - "type": "object", - "properties": { - "npm": { - "type": "string" - }, - "api": { - "type": "string" - } - } - }, "variants": { "description": "Variant-specific configuration", "type": "object", @@ -10771,60 +10825,6 @@ } } } - }, - "whitelist": { - "type": "array", - "items": { - "type": "string" - } - }, - "blacklist": { - "type": "array", - "items": { - "type": "string" - } - }, - "options": { - "type": "object", - "properties": { - "apiKey": { - "type": "string" - }, - "baseURL": { - "type": "string" - }, - "enterpriseUrl": { - "description": "GitHub Enterprise URL for copilot authentication", - "type": "string" - }, - "setCacheKey": { - "description": "Enable promptCacheKey for this provider (default false)", - "type": "boolean" - }, - "timeout": { - "description": "Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.", - "anyOf": [ - { - "description": "Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.", - "type": "integer", - "exclusiveMinimum": 0, - "maximum": 9007199254740991 - }, - { - "description": "Disable timeout for this provider entirely.", - "type": "boolean", - "const": false - } - ] - }, - "chunkTimeout": { - "description": "Timeout in milliseconds between streamed SSE chunks for this provider. If no chunk arrives within this window, the request is aborted.", - "type": "integer", - "exclusiveMinimum": 0, - "maximum": 9007199254740991 - } - }, - "additionalProperties": {} } }, "additionalProperties": false