Skip to content

Commit 4961d72

Browse files
authored
tweak: separate ModelsDev.Model and Config model schemas (anomalyco#21561)
1 parent 00cb883 commit 4961d72

File tree

5 files changed

+169
-116
lines changed

5 files changed

+169
-116
lines changed

packages/opencode/src/config/config.ts

Lines changed: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -786,28 +786,81 @@ export namespace Config {
786786
})
787787
export type Layout = z.infer<typeof Layout>
788788

789-
export const Provider = ModelsDev.Provider.partial()
790-
.extend({
791-
whitelist: z.array(z.string()).optional(),
792-
blacklist: z.array(z.string()).optional(),
793-
models: z
789+
export const Model = z
790+
.object({
791+
id: z.string(),
792+
name: z.string(),
793+
family: z.string().optional(),
794+
release_date: z.string(),
795+
attachment: z.boolean(),
796+
reasoning: z.boolean(),
797+
temperature: z.boolean(),
798+
tool_call: z.boolean(),
799+
interleaved: z
800+
.union([
801+
z.literal(true),
802+
z
803+
.object({
804+
field: z.enum(["reasoning_content", "reasoning_details"]),
805+
})
806+
.strict(),
807+
])
808+
.optional(),
809+
cost: z
810+
.object({
811+
input: z.number(),
812+
output: z.number(),
813+
cache_read: z.number().optional(),
814+
cache_write: z.number().optional(),
815+
context_over_200k: z
816+
.object({
817+
input: z.number(),
818+
output: z.number(),
819+
cache_read: z.number().optional(),
820+
cache_write: z.number().optional(),
821+
})
822+
.optional(),
823+
})
824+
.optional(),
825+
limit: z.object({
826+
context: z.number(),
827+
input: z.number().optional(),
828+
output: z.number(),
829+
}),
830+
modalities: z
831+
.object({
832+
input: z.array(z.enum(["text", "audio", "image", "video", "pdf"])),
833+
output: z.array(z.enum(["text", "audio", "image", "video", "pdf"])),
834+
})
835+
.optional(),
836+
experimental: z.boolean().optional(),
837+
status: z.enum(["alpha", "beta", "deprecated"]).optional(),
838+
provider: z.object({ npm: z.string().optional(), api: z.string().optional() }).optional(),
839+
options: z.record(z.string(), z.any()),
840+
headers: z.record(z.string(), z.string()).optional(),
841+
variants: z
794842
.record(
795843
z.string(),
796-
ModelsDev.Model.partial().extend({
797-
variants: z
798-
.record(
799-
z.string(),
800-
z
801-
.object({
802-
disabled: z.boolean().optional().describe("Disable this variant for the model"),
803-
})
804-
.catchall(z.any()),
805-
)
806-
.optional()
807-
.describe("Variant-specific configuration"),
808-
}),
844+
z
845+
.object({
846+
disabled: z.boolean().optional().describe("Disable this variant for the model"),
847+
})
848+
.catchall(z.any()),
809849
)
810-
.optional(),
850+
.optional()
851+
.describe("Variant-specific configuration"),
852+
})
853+
.partial()
854+
855+
export const Provider = z
856+
.object({
857+
api: z.string().optional(),
858+
name: z.string(),
859+
env: z.array(z.string()),
860+
id: z.string(),
861+
npm: z.string().optional(),
862+
whitelist: z.array(z.string()).optional(),
863+
blacklist: z.array(z.string()).optional(),
811864
options: z
812865
.object({
813866
apiKey: z.string().optional(),
@@ -840,11 +893,14 @@ export namespace Config {
840893
})
841894
.catchall(z.any())
842895
.optional(),
896+
models: z.record(z.string(), Model).optional(),
843897
})
898+
.partial()
844899
.strict()
845900
.meta({
846901
ref: "ProviderConfig",
847902
})
903+
848904
export type Provider = z.infer<typeof Provider>
849905

850906
export const Info = z

packages/opencode/src/provider/models.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ export namespace ModelsDev {
7070
.optional(),
7171
experimental: z.boolean().optional(),
7272
status: z.enum(["alpha", "beta", "deprecated"]).optional(),
73-
options: z.record(z.string(), z.any()),
74-
headers: z.record(z.string(), z.string()).optional(),
7573
provider: z.object({ npm: z.string().optional(), api: z.string().optional() }).optional(),
76-
variants: z.record(z.string(), z.record(z.string(), z.any())).optional(),
7774
})
7875
export type Model = z.infer<typeof Model>
7976

packages/opencode/src/provider/provider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,8 @@ export namespace Provider {
937937
npm: model.provider?.npm ?? provider.npm ?? "@ai-sdk/openai-compatible",
938938
},
939939
status: model.status ?? "active",
940-
headers: model.headers ?? {},
941-
options: model.options ?? {},
940+
headers: {},
941+
options: {},
942942
cost: {
943943
input: model.cost?.input ?? 0,
944944
output: model.cost?.output ?? 0,

packages/sdk/js/src/v2/gen/types.gen.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,29 @@ export type ProviderConfig = {
12501250
env?: Array<string>
12511251
id?: string
12521252
npm?: string
1253+
whitelist?: Array<string>
1254+
blacklist?: Array<string>
1255+
options?: {
1256+
apiKey?: string
1257+
baseURL?: string
1258+
/**
1259+
* GitHub Enterprise URL for copilot authentication
1260+
*/
1261+
enterpriseUrl?: string
1262+
/**
1263+
* Enable promptCacheKey for this provider (default false)
1264+
*/
1265+
setCacheKey?: boolean
1266+
/**
1267+
* Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.
1268+
*/
1269+
timeout?: number | false
1270+
/**
1271+
* Timeout in milliseconds between streamed SSE chunks for this provider. If no chunk arrives within this window, the request is aborted.
1272+
*/
1273+
chunkTimeout?: number
1274+
[key: string]: unknown | string | boolean | number | false | number | undefined
1275+
}
12531276
models?: {
12541277
[key: string]: {
12551278
id?: string
@@ -1288,16 +1311,16 @@ export type ProviderConfig = {
12881311
}
12891312
experimental?: boolean
12901313
status?: "alpha" | "beta" | "deprecated"
1314+
provider?: {
1315+
npm?: string
1316+
api?: string
1317+
}
12911318
options?: {
12921319
[key: string]: unknown
12931320
}
12941321
headers?: {
12951322
[key: string]: string
12961323
}
1297-
provider?: {
1298-
npm?: string
1299-
api?: string
1300-
}
13011324
/**
13021325
* Variant-specific configuration
13031326
*/
@@ -1312,29 +1335,6 @@ export type ProviderConfig = {
13121335
}
13131336
}
13141337
}
1315-
whitelist?: Array<string>
1316-
blacklist?: Array<string>
1317-
options?: {
1318-
apiKey?: string
1319-
baseURL?: string
1320-
/**
1321-
* GitHub Enterprise URL for copilot authentication
1322-
*/
1323-
enterpriseUrl?: string
1324-
/**
1325-
* Enable promptCacheKey for this provider (default false)
1326-
*/
1327-
setCacheKey?: boolean
1328-
/**
1329-
* Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.
1330-
*/
1331-
timeout?: number | false
1332-
/**
1333-
* Timeout in milliseconds between streamed SSE chunks for this provider. If no chunk arrives within this window, the request is aborted.
1334-
*/
1335-
chunkTimeout?: number
1336-
[key: string]: unknown | string | boolean | number | false | number | undefined
1337-
}
13381338
}
13391339

13401340
export type McpLocalConfig = {

packages/sdk/openapi.json

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -10596,6 +10596,60 @@
1059610596
"npm": {
1059710597
"type": "string"
1059810598
},
10599+
"whitelist": {
10600+
"type": "array",
10601+
"items": {
10602+
"type": "string"
10603+
}
10604+
},
10605+
"blacklist": {
10606+
"type": "array",
10607+
"items": {
10608+
"type": "string"
10609+
}
10610+
},
10611+
"options": {
10612+
"type": "object",
10613+
"properties": {
10614+
"apiKey": {
10615+
"type": "string"
10616+
},
10617+
"baseURL": {
10618+
"type": "string"
10619+
},
10620+
"enterpriseUrl": {
10621+
"description": "GitHub Enterprise URL for copilot authentication",
10622+
"type": "string"
10623+
},
10624+
"setCacheKey": {
10625+
"description": "Enable promptCacheKey for this provider (default false)",
10626+
"type": "boolean"
10627+
},
10628+
"timeout": {
10629+
"description": "Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.",
10630+
"anyOf": [
10631+
{
10632+
"description": "Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.",
10633+
"type": "integer",
10634+
"exclusiveMinimum": 0,
10635+
"maximum": 9007199254740991
10636+
},
10637+
{
10638+
"description": "Disable timeout for this provider entirely.",
10639+
"type": "boolean",
10640+
"const": false
10641+
}
10642+
]
10643+
},
10644+
"chunkTimeout": {
10645+
"description": "Timeout in milliseconds between streamed SSE chunks for this provider. If no chunk arrives within this window, the request is aborted.",
10646+
"type": "integer",
10647+
"exclusiveMinimum": 0,
10648+
"maximum": 9007199254740991
10649+
}
10650+
},
10651+
"additionalProperties": {}
10652+
},
1059910653
"models": {
1060010654
"type": "object",
1060110655
"propertyNames": {
@@ -10725,6 +10779,17 @@
1072510779
"type": "string",
1072610780
"enum": ["alpha", "beta", "deprecated"]
1072710781
},
10782+
"provider": {
10783+
"type": "object",
10784+
"properties": {
10785+
"npm": {
10786+
"type": "string"
10787+
},
10788+
"api": {
10789+
"type": "string"
10790+
}
10791+
}
10792+
},
1072810793
"options": {
1072910794
"type": "object",
1073010795
"propertyNames": {
@@ -10741,17 +10806,6 @@
1074110806
"type": "string"
1074210807
}
1074310808
},
10744-
"provider": {
10745-
"type": "object",
10746-
"properties": {
10747-
"npm": {
10748-
"type": "string"
10749-
},
10750-
"api": {
10751-
"type": "string"
10752-
}
10753-
}
10754-
},
1075510809
"variants": {
1075610810
"description": "Variant-specific configuration",
1075710811
"type": "object",
@@ -10771,60 +10825,6 @@
1077110825
}
1077210826
}
1077310827
}
10774-
},
10775-
"whitelist": {
10776-
"type": "array",
10777-
"items": {
10778-
"type": "string"
10779-
}
10780-
},
10781-
"blacklist": {
10782-
"type": "array",
10783-
"items": {
10784-
"type": "string"
10785-
}
10786-
},
10787-
"options": {
10788-
"type": "object",
10789-
"properties": {
10790-
"apiKey": {
10791-
"type": "string"
10792-
},
10793-
"baseURL": {
10794-
"type": "string"
10795-
},
10796-
"enterpriseUrl": {
10797-
"description": "GitHub Enterprise URL for copilot authentication",
10798-
"type": "string"
10799-
},
10800-
"setCacheKey": {
10801-
"description": "Enable promptCacheKey for this provider (default false)",
10802-
"type": "boolean"
10803-
},
10804-
"timeout": {
10805-
"description": "Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.",
10806-
"anyOf": [
10807-
{
10808-
"description": "Timeout in milliseconds for requests to this provider. Default is 300000 (5 minutes). Set to false to disable timeout.",
10809-
"type": "integer",
10810-
"exclusiveMinimum": 0,
10811-
"maximum": 9007199254740991
10812-
},
10813-
{
10814-
"description": "Disable timeout for this provider entirely.",
10815-
"type": "boolean",
10816-
"const": false
10817-
}
10818-
]
10819-
},
10820-
"chunkTimeout": {
10821-
"description": "Timeout in milliseconds between streamed SSE chunks for this provider. If no chunk arrives within this window, the request is aborted.",
10822-
"type": "integer",
10823-
"exclusiveMinimum": 0,
10824-
"maximum": 9007199254740991
10825-
}
10826-
},
10827-
"additionalProperties": {}
1082810828
}
1082910829
},
1083010830
"additionalProperties": false

0 commit comments

Comments
 (0)