Skip to content

feat: add models.dev schema ref for model autocomplete in opencode.json#12528

Merged
rekram1-node merged 2 commits intoanomalyco:devfrom
remorses:feat/models-dev-schema-ref
Feb 6, 2026
Merged

feat: add models.dev schema ref for model autocomplete in opencode.json#12528
rekram1-node merged 2 commits intoanomalyco:devfrom
remorses:feat/models-dev-schema-ref

Conversation

@remorses
Copy link
Contributor

@remorses remorses commented Feb 6, 2026

Adds external $ref to model fields in opencode.json schema, enabling editors to provide autocomplete for all available models from https://models.dev/model-schema.json.

Affected fields:

  • model (root level)
  • small_model (root level)
  • agent.*.model
  • command.*.model

Includes a patch for @standard-community/standard-openapi@0.2.9 which has a bug where external $ref URLs (like https://models.dev/model-schema.json#/$defs/Model) get incorrectly converted to local #/components/schemas/Model refs, colliding with existing schemas. Upstream fix: standard-community/standard-openapi#11, related issue: standard-community/standard-openapi#8

Related: anomalyco/models.dev#767

Screenshot 2026-02-04 at 12 48 16

…ef URLs

The previous PR (anomalyco#12112) added `.meta({ $ref: 'https://models.dev/...' })` to model
fields for editor autocomplete, but `@standard-community/standard-openapi` has a bug
in `convertToOpenAPISchema` where it converts external $ref URLs into local
`#/components/schemas/{lastSegment}` references.

For `https://models.dev/model-schema.json#/$defs/Model`, this extracted just 'Model'
and created `#/components/schemas/Model` - colliding with the existing runtime Model
object schema. This caused config model fields (which should be strings like
'anthropic/claude-4') to be typed as the full Model object in the generated SDK.

The patch strips external $ref URLs (containing '://') and preserves the remaining
schema properties (like `type: 'string'`) instead of converting them to broken local
references.

Verified: SDK generation + typecheck pass, all model fields correctly typed as string.
Copilot AI review requested due to automatic review settings February 6, 2026 21:37
@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

…ma-ref

# Conflicts:
#	bun.lock
#	package.json
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates OpenCode’s configuration JSON Schema generation to reference the external models.dev schema for model fields, enabling editor autocomplete for valid model IDs while ensuring OpenAPI generation doesn’t break on external $refs.

Changes:

  • Introduces a shared ModelId Zod schema annotated with an external $ref to https://models.dev/model-schema.json#/$defs/Model.
  • Switches config fields (model, small_model, agent.*.model, command.*.model) to use ModelId.
  • Adds a Bun patch for @standard-community/standard-openapi@0.2.9 to handle external $ref during OpenAPI conversion.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
patches/@standard-community%2Fstandard-openapi@0.2.9.patch Patches standard-openapi’s JSON Schema → OpenAPI conversion logic for schemas containing $ref.
packages/opencode/src/config/config.ts Introduces ModelId and applies it to relevant config model fields.
package.json Registers the new patched dependency for Bun.
bun.lock Records the patched dependency in the lockfile.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rekram1-node rekram1-node merged commit 576a681 into anomalyco:dev Feb 6, 2026
6 checks passed
kyashrathore pushed a commit to kyashrathore/Claxedo that referenced this pull request Feb 7, 2026
kyashrathore pushed a commit to kyashrathore/Claxedo that referenced this pull request Feb 8, 2026
fanjia1024 pushed a commit to fanjia1024/opencode that referenced this pull request Feb 10, 2026
BryceRyan pushed a commit to BryceRyan/opencode that referenced this pull request Feb 10, 2026
avion23 pushed a commit to avion23/opencode that referenced this pull request Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants