From 0854324b22d0e49d783fb806fc832ee8dbf261b4 Mon Sep 17 00:00:00 2001 From: Aiden Cline Date: Wed, 4 Nov 2026 10:58:06 -0600 Subject: [PATCH] fix(core): drop inherited tool formats on configured routes --- packages/core/src/config/plugin/provider.ts | 31 +++++++++- packages/core/test/config/provider.test.ts | 63 ++++++++++++++++++++- services/www/src/docs/content/models.mdx | 2 + 3 files changed, 93 insertions(+), 3 deletions(-) diff --git a/packages/core/src/config/plugin/provider.ts b/packages/core/src/config/plugin/provider.ts index e6c68668b15..5be5dcfae49 100644 --- a/packages/core/src/config/plugin/provider.ts +++ b/packages/core/src/config/plugin/provider.ts @@ -56,12 +56,19 @@ export const Plugin = define({ } yield* ctx.provider.transform((providers) => { const next: typeof sources.models = new Map() - for (const [id, item] of configuredProviders(loaded.entries)) { + const configured = configuredProviders(loaded.entries) + const rerouted = new Set(configured.filter(([, item]) => overridesRoute(item)).map(([id]) => id)) + for (const [id, item] of configured) { const providerID = id const { current, source, changed } = overlayProvider(providers, providerID, item) const definitions = new Map() for (const [id, config] of Object.entries(item.models ?? {})) { - const base = source?.models.get(config.modelID ?? id) ?? source?.models.get(id) + const original = source?.models.get(config.modelID ?? id) ?? source?.models.get(id) + // The route override and an alias copied from the catalog may live in different config files. + const base = + original?.capabilities.freeform && rerouted.has(providerID) + ? { ...original, capabilities: { ...original.capabilities, freeform: undefined } } + : original const inherit = changed || !current?.models.has(id) // Bind the source at this point in the provider fold. Later source edits/removal // and its credential availability must not change an already-defined alias. @@ -149,6 +156,10 @@ function configuredProviders(entries: readonly Entry[]) { .flatMap((file) => Object.entries(file.info.providers ?? {})) } +function overridesRoute(config: Pick) { + return config.package !== undefined || config.settings?.baseURL !== undefined +} + /** * Applies an integration document's providers. The integration's plugin calls this at its own position in the * provider chain, so provider plugins registered after it treat these providers as configured ones rather than @@ -201,6 +212,14 @@ function overlayProvider( if (item.headers !== undefined) provider.headers = Provider.mergeHeaders(provider.headers, item.headers) if (item.body !== undefined) provider.body = Provider.mergeOverlay(provider.body, item.body) }) + // A proxy or alternate package hasn't advertised the catalog endpoint's tool formats. + // Include catalog models not listed in this config document. + if (overridesRoute(item)) + for (const [id, model] of providers.get(providerID)?.models ?? []) + if (model.capabilities.freeform?.length) + providers.models.update(providerID, id, (model) => { + delete model.capabilities.freeform + }) return { current, source, changed } } @@ -223,6 +242,14 @@ function overlay( if (config.type !== undefined) model.type = config.type if (config.family !== undefined) model.family = config.family if (config.name) model.name = config.name + // An alias may just have copied its canonical model again. Apply route overrides + // before merging any formats explicitly declared for the new destination. + if ( + overridesRoute(item) || + overridesRoute(config) || + (config.modelID !== undefined && config.modelID !== model.modelID) + ) + delete model.capabilities.freeform if (config.modelID !== undefined) model.modelID = config.modelID if (config.releaseDate !== undefined) model.time = { released: Date.parse(config.releaseDate) } if (config.compatibility !== undefined) model.compatibility = { ...model.compatibility, ...config.compatibility } diff --git a/packages/core/test/config/provider.test.ts b/packages/core/test/config/provider.test.ts index 334f353cea4..2399785a8bc 100644 --- a/packages/core/test/config/provider.test.ts +++ b/packages/core/test/config/provider.test.ts @@ -761,6 +761,7 @@ describe("ConfigProviderPlugin.Plugin", () => { for (const id of ["chat", "pinned"]) editor.models.update(providerID, Model.ID.make(id), (model) => { model.settings = { baseURL: "https://catalog.example/v1" } + model.capabilities.freeform = ["text", "lark"] }) }) yield* addPlugin([ @@ -770,7 +771,9 @@ describe("ConfigProviderPlugin.Plugin", () => { providers: { gateway: { settings: { baseURL: "http://127.0.0.1:17322" }, - models: { pinned: { settings: { baseURL: "http://127.0.0.1:9000" } } }, + models: { + pinned: { settings: { baseURL: "http://127.0.0.1:9000" }, capabilities: { freeform: ["text"] } }, + }, }, }, }), @@ -781,6 +784,64 @@ describe("ConfigProviderPlugin.Plugin", () => { models.get(providerID, Model.ID.make(id)).pipe(Effect.map((model) => required(model).settings?.baseURL)) expect(yield* baseURL("chat")).toBe("http://127.0.0.1:17322") expect(yield* baseURL("pinned")).toBe("http://127.0.0.1:9000") + expect(required(yield* models.get(providerID, Model.ID.make("chat"))).capabilities.freeform).toBeUndefined() + expect(required(yield* models.get(providerID, Model.ID.make("pinned"))).capabilities.freeform).toEqual(["text"]) + }), + ) + + it.effect("only inherits freeform formats for an unchanged catalog route", () => + Effect.gen(function* () { + const providers = yield* Provider.Service + const models = yield* Model.Service + const providerID = Provider.ID.make("gateway") + yield* providers.transform((editor) => { + editor.update(providerID, (provider) => { + provider.package = "@opencode/ai/providers/openai" + }) + editor.models.update(providerID, Model.ID.make("source"), (model) => { + model.capabilities.freeform = ["lark"] + }) + }) + yield* addPlugin([ + new Document({ + type: "document", + info: decode({ + providers: { + gateway: { + models: { + renamed: { modelID: "source" }, + repackaged: { modelID: "source", package: "@opencode/ai/providers/openai-compatible" }, + proxied: { modelID: "source", settings: { baseURL: "https://proxy.test/v1" } }, + }, + }, + alternate: { + canonical: "gateway", + package: "@opencode/ai/providers/openai-compatible", + models: { + chat: { modelID: "source" }, + configured: { modelID: "source", capabilities: { freeform: ["regex"] } }, + }, + }, + }, + }), + }), + new Document({ + type: "document", + info: decode({ providers: { alternate: { models: { later: { modelID: "source" } } } } }), + }), + ]) + for (const [provider, id, formats] of [ + ["gateway", "source", ["lark"]], + ["gateway", "renamed", ["lark"]], + ["gateway", "repackaged", undefined], + ["gateway", "proxied", undefined], + ["alternate", "chat", undefined], + ["alternate", "configured", ["regex"]], + ["alternate", "later", undefined], + ] as const) + expect( + required(yield* models.get(Provider.ID.make(provider), Model.ID.make(id))).capabilities.freeform, + ).toEqual(formats) }), ) diff --git a/services/www/src/docs/content/models.mdx b/services/www/src/docs/content/models.mdx index 1596b7cd494..430f3ee574f 100644 --- a/services/www/src/docs/content/models.mdx +++ b/services/www/src/docs/content/models.mdx @@ -234,6 +234,8 @@ 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. + 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: