Skip to content

Commit d889cb2

Browse files
authored
feat(core): read model reasoning from config (#55853)
1 parent 00e7472 commit d889cb2

17 files changed

Lines changed: 426 additions & 8 deletions

File tree

‎packages/client/src/promise/generated/types.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export type ModelMaxTokensField = "max_completion_tokens" | "max_tokens"
168168

169169
export type ModelCacheFormat = "anthropic" | "alibaba"
170170

171-
export type ModelCapabilities = { tools: boolean; input: Array<string>; output: Array<string> }
171+
export type ModelCapabilities = { tools: boolean; input: Array<string>; output: Array<string>; temperature?: boolean }
172172

173173
export type MoneyUSDPerMillionTokens = number
174174

@@ -298,7 +298,9 @@ export type McpProtocol = "legacy" | "auto" | "2026-07-28"
298298

299299
export type ConfigWorktree = { directory: string }
300300

301-
export type ConfigModelCapabilities = { tools?: boolean; input?: Array<string>; output?: Array<string> }
301+
export type ConfigModelReasoning =
302+
| { supported: false }
303+
| { supported: true; toggle?: boolean; effort?: Array<string>; budget?: { min?: number; max?: number } }
302304

303305
export type ConfigShellOption = { path: string; name: string; acceptable: boolean }
304306

@@ -846,6 +848,14 @@ export type VcsInfo = { provider?: string; branch: VcsBranch }
846848

847849
export type WebSearchProvider = { id: WebSearchID; name: string }
848850

851+
export type ConfigModelCapabilities = {
852+
tools?: boolean
853+
input?: Array<string>
854+
output?: Array<string>
855+
temperature?: boolean
856+
reasoning?: ConfigModelReasoning
857+
}
858+
849859
export type SessionMessageLocationSwitched = {
850860
id: SessionMessageID
851861
metadata?: { [x: string]: JsonValue }
@@ -2274,6 +2284,7 @@ export type ConfigEntry =
22742284
modelID?: string
22752285
family?: string
22762286
name?: string
2287+
releaseDate?: string
22772288
compatibility?: ModelCompatibility
22782289
package?: string
22792290
settings?: ConfigModelSettings

‎packages/core/src/config/plugin/provider.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export const Plugin = define({
121121
if (config.family !== undefined) model.family = config.family
122122
if (config.name) model.name = config.name
123123
if (config.modelID !== undefined) model.modelID = config.modelID
124+
if (config.releaseDate !== undefined) model.time = { released: Date.parse(config.releaseDate) }
124125
if (config.compatibility !== undefined)
125126
model.compatibility = { ...model.compatibility, ...config.compatibility }
126127
if (config.package !== undefined) model.package = config.package
@@ -129,6 +130,15 @@ export const Plugin = define({
129130
if (config.body !== undefined) model.body = Provider.mergeOverlay(model.body, config.body)
130131
if (config.capabilities !== undefined)
131132
model.capabilities = Model.mergeCapabilities(config.capabilities, model.capabilities)
133+
if (config.limit !== undefined) model.limit = { ...model.limit, ...config.limit }
134+
// Configured reasoning replaces the base variants; configured variants still overlay them below.
135+
if (config.capabilities?.reasoning !== undefined)
136+
model.variants = [
137+
...Variant.resolve(
138+
{ ...model, package: model.package ?? models.provider.get(providerID)?.provider.package },
139+
Variant.supports(config.capabilities.reasoning),
140+
),
141+
]
132142
if (config.variants !== undefined) {
133143
model.variants ??= []
134144
for (const variant of config.variants) {
@@ -156,15 +166,14 @@ export const Plugin = define({
156166
}))
157167
}
158168
if (config.disabled !== undefined) model.enabled = !config.disabled
159-
if (config.limit !== undefined) model.limit = { ...model.limit, ...config.limit }
160169
})
161170
// Inherited variants are spelled for the base model's package, so a package override needs fresh ones.
162171
// A base without variants has no reasoning support to respell.
163172
const repackaged =
164173
source?.base !== undefined &&
165174
source.base.variants.length > 0 &&
166175
models.get(providerID, id)?.package !== source.base.package
167-
if (config.variants === undefined && (!source?.base || repackaged))
176+
if (config.variants === undefined && config.capabilities?.reasoning === undefined && (!source?.base || repackaged))
168177
models.update(providerID, id, (model) => {
169178
model.variants = [
170179
...Variant.resolve({

‎packages/core/src/model.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const mergeCapabilities = (config: Partial<Capabilities>, base: Capabilit
3535
tools: config.tools ?? fallback.tools,
3636
input: [...(config.input ?? fallback.input)],
3737
output: [...(config.output ?? fallback.output)],
38+
temperature: config.temperature ?? base?.temperature,
3839
}
3940
}
4041

‎packages/core/src/models-dev.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ function modelInfo(
233233
tools: model.tool_call,
234234
input: [...(model.modalities?.input ?? [])],
235235
output: [...(model.modalities?.output ?? [])],
236+
temperature: model.temperature,
236237
},
237238
variants: [...(input.variants ?? [])],
238239
time: { released: released(model.release_date) },

‎packages/core/src/plugin/provider/opencode.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { IntegrationConnection } from "../../integration/connection.js"
1111
import { ManagedPolicy } from "../../managed-policy.js"
1212
import { Model } from "../../model.js"
1313
import { Provider } from "../../provider.js"
14+
import { Variant } from "../../variant.js"
1415
import { WebSearch } from "../../websearch.js"
1516
import { ConfigPolicy } from "@opencode/schema/config/policy"
1617
import { ConfigProvider } from "@opencode/schema/config/provider"
@@ -287,6 +288,7 @@ export const OpencodePlugin = define<HttpClient.HttpClient | Bus.Service | Manag
287288
if (config.family !== undefined) model.family = config.family
288289
if (config.name !== undefined) model.name = config.name
289290
if (config.modelID !== undefined) model.modelID = config.modelID
291+
if (config.releaseDate !== undefined) model.time = { released: Date.parse(config.releaseDate) }
290292
if (config.compatibility !== undefined)
291293
model.compatibility = { ...model.compatibility, ...config.compatibility }
292294
model.package = config.package ?? (item.package !== undefined ? undefined : model.package)
@@ -299,6 +301,15 @@ export const OpencodePlugin = define<HttpClient.HttpClient | Bus.Service | Manag
299301
)
300302
model.headers = Provider.mergeHeaders(model.headers, config.headers)
301303
model.body = Provider.mergeOverlay(model.body, config.body)
304+
if (config.limit !== undefined) model.limit = { ...model.limit, ...config.limit }
305+
// The Console's reasoning replaces the base variants; its variants still overlay them below.
306+
if (config.capabilities?.reasoning !== undefined)
307+
model.variants = [
308+
...Variant.resolve(
309+
{ ...model, package: model.package ?? providers.get(providerID)?.provider.package },
310+
Variant.supports(config.capabilities.reasoning),
311+
),
312+
]
302313
for (const variant of config.variants ?? []) {
303314
let existing = model.variants.find((item) => item.id === variant.id)
304315
if (!existing) {
@@ -322,7 +333,6 @@ export const OpencodePlugin = define<HttpClient.HttpClient | Bus.Service | Manag
322333
},
323334
}))
324335
model.enabled = !config.disabled
325-
if (config.limit !== undefined) model.limit = { ...model.limit, ...config.limit }
326336
})
327337
}
328338
const configured = providers.get(providerID)

‎packages/core/src/variant.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * as Variant from "./variant.js"
22

3+
import { ConfigProvider } from "@opencode/schema/config/provider"
34
import { Model } from "./model.js"
45
import { Provider } from "./provider.js"
56

@@ -8,6 +9,18 @@ export type Support =
89
| { readonly type: "toggle" }
910
| { readonly type: "budget_tokens"; readonly min?: number; readonly max?: number }
1011

12+
/** Reasoning controls in models.dev v2's shape, where `default` is the provider default rather than a variant. */
13+
export function supports(reasoning: ConfigProvider.Reasoning): readonly Support[] {
14+
if (!reasoning.supported) return []
15+
return [
16+
...(reasoning.toggle ? [{ type: "toggle" as const }] : []),
17+
...(reasoning.effort
18+
? [{ type: "effort" as const, values: reasoning.effort.filter((value) => value !== "default") }]
19+
: []),
20+
...(reasoning.budget ? [{ type: "budget_tokens" as const, ...reasoning.budget }] : []),
21+
]
22+
}
23+
1124
type Variants = Model.Info["variants"]
1225
type Overlay = Omit<Variants[number], "id">
1326

‎packages/core/test/config/provider.test.ts‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,78 @@ describe("ConfigProviderPlugin.Plugin", () => {
762762
}),
763763
)
764764

765+
it.effect("builds variants from configured reasoning and overlays configured variants", () =>
766+
Effect.gen(function* () {
767+
const models = yield* Model.Service
768+
const providerID = Provider.ID.make("custom")
769+
yield* addPlugin([
770+
new Document({
771+
type: "document",
772+
info: decode({
773+
providers: {
774+
custom: {
775+
package: "aisdk:@ai-sdk/openai",
776+
models: {
777+
effort: {
778+
capabilities: { reasoning: { supported: true, effort: ["default", "low", "high"] } },
779+
variants: [{ id: "high", headers: { "x-tier": "high" } }],
780+
},
781+
fixed: { capabilities: { reasoning: { supported: true } } },
782+
plain: { capabilities: { reasoning: { supported: false } } },
783+
},
784+
},
785+
},
786+
}),
787+
}),
788+
])
789+
790+
const effort = required(yield* models.get(providerID, Model.ID.make("effort")))
791+
expect(effort.variants).toEqual([
792+
{
793+
id: Model.VariantID.make("low"),
794+
settings: { reasoningEffort: "low", reasoningSummary: "auto", include: ["reasoning.encrypted_content"] },
795+
},
796+
{
797+
id: Model.VariantID.make("high"),
798+
settings: { reasoningEffort: "high", reasoningSummary: "auto", include: ["reasoning.encrypted_content"] },
799+
headers: { "x-tier": "high" },
800+
},
801+
])
802+
expect(required(yield* models.get(providerID, Model.ID.make("fixed"))).variants).toEqual([])
803+
expect(required(yield* models.get(providerID, Model.ID.make("plain"))).variants).toEqual([])
804+
}),
805+
)
806+
807+
it.effect("applies configured release date, temperature support, and reasoning field", () =>
808+
Effect.gen(function* () {
809+
const models = yield* Model.Service
810+
yield* addPlugin([
811+
new Document({
812+
type: "document",
813+
info: decode({
814+
providers: {
815+
custom: {
816+
package: "aisdk:@ai-sdk/openai-compatible",
817+
models: {
818+
reasoner: {
819+
releaseDate: "2026-02-03",
820+
capabilities: { temperature: false },
821+
compatibility: { reasoningField: "reasoning_content" },
822+
},
823+
},
824+
},
825+
},
826+
}),
827+
}),
828+
])
829+
830+
const model = required(yield* models.get(Provider.ID.make("custom"), Model.ID.make("reasoner")))
831+
expect(model.time.released).toBe(Date.UTC(2026, 1, 3))
832+
expect(model.capabilities.temperature).toBe(false)
833+
expect(model.compatibility?.reasoningField).toBe("reasoning_content")
834+
}),
835+
)
836+
765837
it.effect("keeps configured model variant bodies unchanged", () =>
766838
Effect.gen(function* () {
767839
const models = yield* Model.Service

‎packages/core/test/models.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const fixtureSnapshot = [
6161
family: undefined,
6262
package: undefined,
6363
settings: { provider: "acme" },
64-
capabilities: { tools: true, input: [], output: [] },
64+
capabilities: { tools: true, input: [], output: [], temperature: true },
6565
variants: [],
6666
time: { released: Date.parse("2026-01-01") },
6767
cost: [
@@ -123,7 +123,7 @@ const fixture2Snapshot = [
123123
family: undefined,
124124
package: undefined,
125125
settings: { provider: "beta" },
126-
capabilities: { tools: false, input: [], output: [] },
126+
capabilities: { tools: false, input: [], output: [], temperature: false },
127127
variants: [],
128128
time: { released: Date.parse("2026-02-01") },
129129
cost: [

‎packages/core/test/plugin/provider-opencode.test.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,58 @@ describe("OpencodePlugin", () => {
583583
),
584584
)
585585

586+
it.live("builds Console model variants from its reasoning and applies its release date", () =>
587+
Effect.acquireUseRelease(
588+
Effect.sync(() =>
589+
Bun.serve({
590+
port: 0,
591+
fetch: () =>
592+
Response.json({
593+
providers: {
594+
remote: {
595+
name: "Remote",
596+
package: "aisdk:@ai-sdk/openai",
597+
models: {
598+
reasoner: {
599+
releaseDate: "2026-02-03",
600+
capabilities: { reasoning: { supported: true, effort: ["default", "low", "high"] } },
601+
variants: [{ id: "high", headers: { "x-tier": "high" } }],
602+
},
603+
},
604+
},
605+
},
606+
}),
607+
}),
608+
),
609+
(server) =>
610+
Effect.gen(function* () {
611+
const credentials = yield* Credential.Service
612+
const models = yield* Model.Service
613+
yield* credentials.create({
614+
integrationID: Integration.ID.make("opencode"),
615+
value: Credential.Key.make({ type: "key", key: "secret", metadata: { server: server.url.origin } }),
616+
})
617+
618+
yield* addPlugin()
619+
620+
const reasoner = required(yield* models.get(Provider.ID.make("remote"), Model.ID.make("reasoner")))
621+
expect(reasoner.time.released).toBe(Date.UTC(2026, 1, 3))
622+
expect(reasoner.variants).toEqual([
623+
{
624+
id: Model.VariantID.make("low"),
625+
settings: { reasoningEffort: "low", reasoningSummary: "auto", include: ["reasoning.encrypted_content"] },
626+
},
627+
{
628+
id: Model.VariantID.make("high"),
629+
settings: { reasoningEffort: "high", reasoningSummary: "auto", include: ["reasoning.encrypted_content"] },
630+
headers: { "x-tier": "high" },
631+
},
632+
])
633+
}),
634+
(server) => Effect.promise(() => server.stop(true)),
635+
),
636+
)
637+
586638
it.effect("refreshes hosted search with Console config, retains it on failure, and skips unchanged snapshots", () =>
587639
Effect.acquireUseRelease(
588640
Effect.sync(() => {

‎packages/core/test/variant.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,3 +544,15 @@ test("spells Google Interactions variants as thinking levels", () => {
544544
{ id: "high", settings: { thinkingLevel: "high", thinkingSummaries: "auto" } },
545545
])
546546
})
547+
548+
test("reads models.dev v2 reasoning as variant support", () => {
549+
expect(Variant.supports({ supported: false })).toEqual([])
550+
expect(Variant.supports({ supported: true })).toEqual([])
551+
expect(
552+
Variant.supports({ supported: true, toggle: true, effort: ["default", "low"], budget: { min: 1024, max: 8000 } }),
553+
).toEqual([
554+
{ type: "toggle" },
555+
{ type: "effort", values: ["low"] },
556+
{ type: "budget_tokens", min: 1024, max: 8000 },
557+
])
558+
})

0 commit comments

Comments
 (0)