Skip to content

Commit 576a681

Browse files
authored
feat: add models.dev schema ref for model autocomplete in opencode.json (#12528)
1 parent 95d2d4d commit 576a681

4 files changed

Lines changed: 28 additions & 8 deletions

File tree

bun.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,7 @@
100100
"@types/bun": "catalog:",
101101
"@types/node": "catalog:"
102102
},
103-
"patchedDependencies": {}
103+
"patchedDependencies": {
104+
"@standard-community/[email protected]": "patches/@standard-community%[email protected]"
105+
}
104106
}

packages/opencode/src/config/config.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import { proxied } from "@/util/proxied"
3333
import { iife } from "@/util/iife"
3434

3535
export namespace Config {
36+
const ModelId = z.string().meta({ $ref: "https://models.dev/model-schema.json#/$defs/Model" })
37+
3638
const log = Log.create({ service: "config" })
3739

3840
// Managed settings directory for enterprise deployments (highest priority, admin-controlled)
@@ -653,7 +655,7 @@ export namespace Config {
653655
template: z.string(),
654656
description: z.string().optional(),
655657
agent: z.string().optional(),
656-
model: z.string().optional(),
658+
model: ModelId.optional(),
657659
subtask: z.boolean().optional(),
658660
})
659661
export type Command = z.infer<typeof Command>
@@ -669,7 +671,7 @@ export namespace Config {
669671

670672
export const Agent = z
671673
.object({
672-
model: z.string().optional(),
674+
model: ModelId.optional(),
673675
variant: z
674676
.string()
675677
.optional()
@@ -1040,11 +1042,8 @@ export namespace Config {
10401042
.array(z.string())
10411043
.optional()
10421044
.describe("When set, ONLY these providers will be enabled. All other providers will be ignored"),
1043-
model: z.string().describe("Model to use in the format of provider/model, eg anthropic/claude-2").optional(),
1044-
small_model: z
1045-
.string()
1046-
.describe("Small model to use for tasks like title generation in the format of provider/model")
1047-
.optional(),
1045+
model: ModelId.describe("Model to use in the format of provider/model, eg anthropic/claude-2").optional(),
1046+
small_model: ModelId.describe("Small model to use for tasks like title generation in the format of provider/model").optional(),
10481047
default_agent: z
10491048
.string()
10501049
.optional()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
diff --git a/dist/vendors/convert.js b/dist/vendors/convert.js
2+
index 0d615eebfd7cd646937ec1b29f8332db73586ec1..7b146f903c07a9377d676753691cba67781879be 100644
3+
--- a/dist/vendors/convert.js
4+
+++ b/dist/vendors/convert.js
5+
@@ -74,7 +74,10 @@ function convertToOpenAPISchema(jsonSchema, context) {
6+
$ref: `#/components/schemas/${id}`
7+
};
8+
} else if (_jsonSchema.$ref) {
9+
- const { $ref, $defs } = _jsonSchema;
10+
+ const { $ref, $defs, ...rest } = _jsonSchema;
11+
+ if ($ref.includes("://")) {
12+
+ return Object.keys(rest).length > 0 ? rest : { type: "string" };
13+
+ }
14+
const ref = $ref.split("/").pop();
15+
context.components.schemas = {
16+
...context.components.schemas,

0 commit comments

Comments
 (0)