Skip to content

Commit 23c8656

Browse files
authored
refactor: split up models.dev and config model definitions to prevent coupling (anomalyco#20605)
1 parent ec3ae17 commit 23c8656

4 files changed

Lines changed: 70 additions & 26 deletions

File tree

‎packages/opencode/src/config/config.ts‎

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -730,28 +730,77 @@ export namespace Config {
730730
})
731731
export type Layout = z.infer<typeof Layout>
732732

733+
export const Model = z
734+
.object({
735+
id: z.string(),
736+
name: z.string(),
737+
family: z.string().optional(),
738+
release_date: z.string(),
739+
attachment: z.boolean(),
740+
reasoning: z.boolean(),
741+
temperature: z.boolean(),
742+
tool_call: z.boolean(),
743+
interleaved: z
744+
.union([
745+
z.literal(true),
746+
z
747+
.object({
748+
field: z.enum(["reasoning_content", "reasoning_details"]),
749+
})
750+
.strict(),
751+
])
752+
.optional(),
753+
cost: z
754+
.object({
755+
input: z.number(),
756+
output: z.number(),
757+
cache_read: z.number().optional(),
758+
cache_write: z.number().optional(),
759+
context_over_200k: z
760+
.object({
761+
input: z.number(),
762+
output: z.number(),
763+
cache_read: z.number().optional(),
764+
cache_write: z.number().optional(),
765+
})
766+
.optional(),
767+
})
768+
.optional(),
769+
limit: z.object({
770+
context: z.number(),
771+
input: z.number().optional(),
772+
output: z.number(),
773+
}),
774+
modalities: z
775+
.object({
776+
input: z.array(z.enum(["text", "audio", "image", "video", "pdf"])),
777+
output: z.array(z.enum(["text", "audio", "image", "video", "pdf"])),
778+
})
779+
.optional(),
780+
experimental: z.boolean().optional(),
781+
status: z.enum(["alpha", "beta", "deprecated"]).optional(),
782+
options: z.record(z.string(), z.any()),
783+
headers: z.record(z.string(), z.string()).optional(),
784+
provider: z.object({ npm: z.string().optional(), api: z.string().optional() }).optional(),
785+
variants: z
786+
.record(
787+
z.string(),
788+
z
789+
.object({
790+
disabled: z.boolean().optional().describe("Disable this variant for the model"),
791+
})
792+
.catchall(z.any()),
793+
)
794+
.optional()
795+
.describe("Variant-specific configuration"),
796+
})
797+
.partial()
798+
733799
export const Provider = ModelsDev.Provider.partial()
734800
.extend({
735801
whitelist: z.array(z.string()).optional(),
736802
blacklist: z.array(z.string()).optional(),
737-
models: z
738-
.record(
739-
z.string(),
740-
ModelsDev.Model.partial().extend({
741-
variants: z
742-
.record(
743-
z.string(),
744-
z
745-
.object({
746-
disabled: z.boolean().optional().describe("Disable this variant for the model"),
747-
})
748-
.catchall(z.any()),
749-
)
750-
.optional()
751-
.describe("Variant-specific configuration"),
752-
}),
753-
)
754-
.optional(),
803+
models: z.record(z.string(), Model).optional(),
755804
options: z
756805
.object({
757806
apiKey: z.string().optional(),

‎packages/opencode/src/provider/models.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,8 @@ export namespace ModelsDev {
6161
output: z.array(z.enum(["text", "audio", "image", "video", "pdf"])),
6262
})
6363
.optional(),
64-
experimental: z.boolean().optional(),
6564
status: z.enum(["alpha", "beta", "deprecated"]).optional(),
66-
options: z.record(z.string(), z.any()),
67-
headers: z.record(z.string(), z.string()).optional(),
6865
provider: z.object({ npm: z.string().optional(), api: z.string().optional() }).optional(),
69-
variants: z.record(z.string(), z.record(z.string(), z.any())).optional(),
7066
})
7167
export type Model = z.infer<typeof Model>
7268

‎packages/opencode/src/provider/provider.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -903,8 +903,8 @@ export namespace Provider {
903903
npm: model.provider?.npm ?? provider.npm ?? "@ai-sdk/openai-compatible",
904904
},
905905
status: model.status ?? "active",
906-
headers: model.headers ?? {},
907-
options: model.options ?? {},
906+
headers: {},
907+
options: {},
908908
cost: {
909909
input: model.cost?.input ?? 0,
910910
output: model.cost?.output ?? 0,

‎packages/opencode/src/session/llm.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Provider } from "@/provider/provider"
22
import { Log } from "@/util/log"
3-
import { Cause, Effect, Layer, Record, ServiceMap } from "effect"
4-
import * as Queue from "effect/Queue"
3+
import { Effect, Layer, Record, ServiceMap } from "effect"
54
import * as Stream from "effect/Stream"
65
import { streamText, wrapLanguageModel, type ModelMessage, type Tool, tool, jsonSchema } from "ai"
76
import { mergeDeep, pipe } from "remeda"

0 commit comments

Comments
 (0)