mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-21 04:12:08 +03:00
fix(core): expose only known freeform formats
This commit is contained in:
+10
-8
@@ -188,13 +188,7 @@ export type ModelCacheFormat = "anthropic" | "alibaba"
|
||||
|
||||
export type ModelMediaInput = "assets" | "state" | "root"
|
||||
|
||||
export type ModelCapabilities = {
|
||||
tools: boolean
|
||||
freeform?: Array<string>
|
||||
input: Array<string>
|
||||
output: Array<string>
|
||||
temperature?: boolean
|
||||
}
|
||||
export type ToolFreeformFormat = "text" | "regex" | "lark"
|
||||
|
||||
export type MoneyUSDPerMillionTokens = number
|
||||
|
||||
@@ -719,6 +713,14 @@ export type ProviderCompatibility = {
|
||||
mediaInput?: ModelMediaInput
|
||||
}
|
||||
|
||||
export type ModelCapabilities = {
|
||||
tools: boolean
|
||||
freeform?: Array<ToolFreeformFormat>
|
||||
input: Array<string>
|
||||
output: Array<string>
|
||||
temperature?: boolean
|
||||
}
|
||||
|
||||
export type ModelCost = {
|
||||
tier?: { type: "context"; size: number }
|
||||
input: MoneyUSDPerMillionTokens
|
||||
@@ -989,7 +991,7 @@ export type UsageLimitsGo = { rolling: UsageLimitsMeter; weekly: UsageLimitsMete
|
||||
|
||||
export type ConfigModelCapabilities = {
|
||||
tools?: boolean
|
||||
freeform?: Array<string>
|
||||
freeform?: Array<ToolFreeformFormat>
|
||||
input?: Array<string>
|
||||
output?: Array<string>
|
||||
temperature?: boolean
|
||||
|
||||
@@ -4,6 +4,7 @@ import { ConfigProvider } from "@opencode/schema/config/provider"
|
||||
import { MaxTokensField, MediaInput } from "@opencode/schema/model-compatibility"
|
||||
import { ModelsDev } from "@opencode/schema/models-dev"
|
||||
import { Money } from "@opencode/schema/money"
|
||||
import { FreeformFormat } from "@opencode/schema/tool"
|
||||
import { App } from "./app.js"
|
||||
import { Hash } from "@opencode/util/hash"
|
||||
import { FSUtil } from "@opencode/util/fs-util"
|
||||
@@ -71,7 +72,7 @@ const SourceApi = Schema.Struct({
|
||||
base_url: Schema.optional(Schema.String),
|
||||
capabilities: Schema.optional(
|
||||
Schema.Struct({
|
||||
tools: Schema.optional(Schema.Struct({ freeform: Schema.optional(Schema.Array(Schema.String)) })),
|
||||
tools: Schema.optional(Schema.Struct({ freeform: Schema.optional(Schema.Array(Schema.Unknown)) })),
|
||||
}),
|
||||
),
|
||||
sdk: Schema.optional(
|
||||
@@ -141,6 +142,7 @@ const decodeProvider = Schema.decodeUnknownOption(SourceProvider)
|
||||
const decodeContext = Schema.decodeUnknownOption(ContextCondition)
|
||||
const decodeMaxTokensField = Schema.decodeUnknownOption(MaxTokensField)
|
||||
const decodeMediaInput = Schema.decodeUnknownOption(MediaInput)
|
||||
const knownFreeformFormat = Schema.is(FreeformFormat)
|
||||
const decodeStatus = Schema.decodeUnknownOption(Schema.Literals(["alpha", "beta", "deprecated"]))
|
||||
|
||||
export type Snapshot = {
|
||||
@@ -151,7 +153,7 @@ export type Snapshot = {
|
||||
|
||||
type Route = {
|
||||
readonly package: string
|
||||
readonly freeform?: readonly string[]
|
||||
readonly freeform?: readonly FreeformFormat[]
|
||||
readonly baseURL?: string
|
||||
readonly compatibility?: Model.Compatibility
|
||||
}
|
||||
@@ -278,7 +280,7 @@ function route(providerID: Provider.ID, model: SourceModel, unknown: Set<string>
|
||||
}
|
||||
return {
|
||||
package: packageName,
|
||||
freeform: api.capabilities?.tools?.freeform,
|
||||
freeform: api.capabilities?.tools?.freeform?.filter(knownFreeformFormat),
|
||||
// An empty base_url is how models.dev says it has no URL for the API.
|
||||
...(BUILDS_OWN_URL.has(packageName) || !api.base_url ? {} : { baseURL: api.base_url }),
|
||||
...(Object.keys(compatibility).length > 0 ? { compatibility } : {}),
|
||||
|
||||
@@ -278,7 +278,7 @@ describe("ModelsDev Service", () => {
|
||||
responses: {
|
||||
base_url: "https://api.acme.test/v1",
|
||||
sdk: { aisdk: "@ai-sdk/openai", opencodeai: "@opencode/ai/providers/openai/responses" },
|
||||
capabilities: { tools: { freeform: ["text", "lark"] } },
|
||||
capabilities: { tools: { freeform: ["text", "future-grammar", "lark"] } },
|
||||
},
|
||||
"chat-completions": {
|
||||
base_url: "https://other.acme.test/v1",
|
||||
@@ -288,7 +288,13 @@ describe("ModelsDev Service", () => {
|
||||
},
|
||||
}),
|
||||
"acme-fallback": sourceModel("acme-fallback", {
|
||||
api: { messages: { base_url: "https://claude.acme.test/v1", sdk: { aisdk: "@ai-sdk/anthropic" } } },
|
||||
api: {
|
||||
messages: {
|
||||
base_url: "https://claude.acme.test/v1",
|
||||
sdk: { aisdk: "@ai-sdk/anthropic" },
|
||||
capabilities: { tools: { freeform: ["future-grammar"] } },
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
@@ -322,9 +328,10 @@ describe("ModelsDev Service", () => {
|
||||
expect(acmeModel("acme-responses")?.package).toBe("@opencode/ai/providers/openai/responses")
|
||||
expect(acmeModel("acme-responses")?.settings).toBeUndefined()
|
||||
expect(acmeModel("acme-responses")?.capabilities.freeform).toEqual(["text", "lark"])
|
||||
expect(acmeModel("acme-1")?.capabilities.freeform).toBeUndefined()
|
||||
// Without an opencode package, the AI SDK package maps to the native one as before.
|
||||
expect(acmeModel("acme-fallback")?.package).toBe("@opencode/ai/providers/anthropic")
|
||||
expect(acmeModel("acme-fallback")?.capabilities.freeform).toBeUndefined()
|
||||
expect(acmeModel("acme-fallback")?.capabilities.freeform).toEqual([])
|
||||
expect(acmeModel("acme-fallback")?.settings).toEqual({ baseURL: "https://claude.acme.test/v1" })
|
||||
|
||||
const azureModel = (id: string) => azure?.models.find((model) => model.id === id)
|
||||
|
||||
@@ -58,7 +58,8 @@ describe("SessionModelRequest HTTP hooks", () => {
|
||||
execute: () => Effect.die("unused tool execution"),
|
||||
}
|
||||
const requests = yield* SessionModelRequest.Service.pipe(Effect.provide(SessionModelRequest.layer))
|
||||
for (const supported of [undefined, [], ["text", "lark"], ["regex"]]) {
|
||||
const cases: Array<typeof model.capabilities.freeform> = [undefined, [], ["text", "lark"], ["regex"]]
|
||||
for (const supported of cases) {
|
||||
const prepared = yield* requests.primary({
|
||||
session,
|
||||
agent: Agent.ID.make("build"),
|
||||
|
||||
Generated
+6
-2
@@ -16805,7 +16805,7 @@
|
||||
"freeform": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
"$ref": "#/components/schemas/Tool.FreeformFormat"
|
||||
}
|
||||
},
|
||||
"input": {
|
||||
@@ -20501,7 +20501,7 @@
|
||||
"freeform": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
"$ref": "#/components/schemas/Tool.FreeformFormat"
|
||||
}
|
||||
},
|
||||
"input": {
|
||||
@@ -25070,6 +25070,10 @@
|
||||
"required": ["type", "uri", "mime"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"Tool.FreeformFormat": {
|
||||
"type": "string",
|
||||
"enum": ["text", "regex", "lark"]
|
||||
},
|
||||
"Tool.TextContent": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { optional, statics } from "./schema.js"
|
||||
import { Provider } from "./provider.js"
|
||||
import { Compatibility, MaxTokensField, MediaInput, ReasoningField } from "./model-compatibility.js"
|
||||
import { Money } from "./money.js"
|
||||
import { FreeformFormat } from "./tool.js"
|
||||
import { ephemeral, inventory } from "./event.js"
|
||||
|
||||
export const ID = Schema.String.pipe(Schema.brand("Model.ID"))
|
||||
@@ -78,7 +79,7 @@ export interface Capabilities extends Schema.Schema.Type<typeof Capabilities> {}
|
||||
export const Capabilities = Schema.Struct({
|
||||
tools: Schema.Boolean,
|
||||
/** Freeform tool input formats advertised by the selected API. Absent or empty means JSON tools only. */
|
||||
freeform: Schema.Array(Schema.String).pipe(optional),
|
||||
freeform: Schema.Array(FreeformFormat).pipe(optional),
|
||||
input: Schema.Array(Schema.String),
|
||||
output: Schema.Array(Schema.String),
|
||||
/** Whether the model accepts a sampling temperature. Unknown when unset. */
|
||||
|
||||
@@ -16,6 +16,11 @@ export const Freeform = Schema.Union([
|
||||
]).annotate({ identifier: "LLM.Freeform" })
|
||||
export type Freeform = typeof Freeform.Type
|
||||
|
||||
export const FreeformFormat = Schema.Literals(Freeform.members.map((member) => member.fields.type.literal)).annotate({
|
||||
identifier: "Tool.FreeformFormat",
|
||||
})
|
||||
export type FreeformFormat = typeof FreeformFormat.Type
|
||||
|
||||
export const CallID = Schema.String.pipe(Schema.brand("Tool.CallID"))
|
||||
export type CallID = typeof CallID.Type
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ already in the catalog, OpenCode assumes:
|
||||
- A 200,000-token context limit and 32,000-token output limit.
|
||||
- An unspecified input limit.
|
||||
|
||||
If you configure a different endpoint (`settings.baseURL`) or provider package, OpenCode does not assume the new route supports the catalog route's freeform formats. Set `capabilities.freeform` on the model to opt back in for that route.
|
||||
OpenCode recognizes `text`, `regex`, and `lark`. Other format names from models.dev are ignored without dropping the model or its tools. If you configure a different endpoint (`settings.baseURL`) or provider package, set `capabilities.freeform` on the model to opt back in for that route.
|
||||
|
||||
These are fallback assumptions, not detected capabilities. Set accurate `capabilities` and `limit` values when known;
|
||||
explicit values replace the fallbacks. Add `disabled: true` to hide a model from the available catalog:
|
||||
|
||||
Reference in New Issue
Block a user