Browse Source

feat: add models.dev schema ref for model autocomplete in opencode.json (#12112)

Tommy D. Rossi 3 weeks ago
parent
commit
9ef319f25f
1 changed files with 11 additions and 4 deletions
  1. 11 4
      packages/opencode/src/config/config.ts

+ 11 - 4
packages/opencode/src/config/config.ts

@@ -35,6 +35,8 @@ import { iife } from "@/util/iife"
 export namespace Config {
 export namespace Config {
   const log = Log.create({ service: "config" })
   const log = Log.create({ service: "config" })
 
 
+  const ModelRef = { $ref: "https://models.dev/model-schema.json#/$defs/Model" }
+
   // Managed settings directory for enterprise deployments (highest priority, admin-controlled)
   // Managed settings directory for enterprise deployments (highest priority, admin-controlled)
   // These settings override all user and project settings
   // These settings override all user and project settings
   function getManagedConfigDir(): string {
   function getManagedConfigDir(): string {
@@ -660,7 +662,7 @@ export namespace Config {
     template: z.string(),
     template: z.string(),
     description: z.string().optional(),
     description: z.string().optional(),
     agent: z.string().optional(),
     agent: z.string().optional(),
-    model: z.string().optional(),
+    model: z.string().optional().meta(ModelRef),
     subtask: z.boolean().optional(),
     subtask: z.boolean().optional(),
   })
   })
   export type Command = z.infer<typeof Command>
   export type Command = z.infer<typeof Command>
@@ -672,7 +674,7 @@ export namespace Config {
 
 
   export const Agent = z
   export const Agent = z
     .object({
     .object({
-      model: z.string().optional(),
+      model: z.string().optional().meta(ModelRef),
       variant: z
       variant: z
         .string()
         .string()
         .optional()
         .optional()
@@ -1043,11 +1045,16 @@ export namespace Config {
         .array(z.string())
         .array(z.string())
         .optional()
         .optional()
         .describe("When set, ONLY these providers will be enabled. All other providers will be ignored"),
         .describe("When set, ONLY these providers will be enabled. All other providers will be ignored"),
-      model: z.string().describe("Model to use in the format of provider/model, eg anthropic/claude-2").optional(),
+      model: z
+        .string()
+        .describe("Model to use in the format of provider/model, eg anthropic/claude-2")
+        .optional()
+        .meta(ModelRef),
       small_model: z
       small_model: z
         .string()
         .string()
         .describe("Small model to use for tasks like title generation in the format of provider/model")
         .describe("Small model to use for tasks like title generation in the format of provider/model")
-        .optional(),
+        .optional()
+        .meta(ModelRef),
       default_agent: z
       default_agent: z
         .string()
         .string()
         .optional()
         .optional()