Open History to see the last commit
1import type { ModelReasoning } from '@tanstack/ai'
2import type { ModelReasoningCapability } from '@tanstack/ai/adapter-internals'
3
4// Reasoning shapes: the levels a model has for `chat({ reasoning })`, and
5// the provider value to send for each. Each model points at one of them.
6const BUDGET_LOW_TO_HIGH = {
7 levels: { low: 'low', medium: 'medium', high: 'high' },
8 budget: true,
9} as const
10const BUDGET_OFF_TO_HIGH = {
11 levels: {
12 off: 'off',
13 minimal: 'minimal',
14 low: 'low',
15 medium: 'medium',
16 high: 'high',
17 },
18 budget: true,
19} as const
20const EFFORT_LOW_TO_HIGH = {
21 levels: { low: 'low', medium: 'medium', high: 'high' },
22 budget: false,
23} as const
24const EFFORT_NONE_LOW_TO_XHIGH = {
25 levels: {
26 off: 'none',
27 low: 'low',
28 medium: 'medium',
29 high: 'high',
30 xhigh: 'xhigh',
31 },
32 budget: false,
33} as const
34/**
35 * Models known to work with OpenCode. OpenCode is provider-agnostic — it
36 * resolves any `provider/model` id its configured providers support (via the
37 * Vercel AI SDK + Models.dev), so this list exists for autocomplete. Any
38 * string is accepted via the `(string & {})` escape hatch in
39 * {@link OpencodeModel}.
40 *
41 * Models are addressed as `provider_id/model_id` (e.g.
42 * `anthropic/claude-sonnet-4-5`); the adapter splits on the first `/`.
43 */
44export const OPENCODE_MODELS = [
45 'anthropic/claude-opus-4-5',
46 'anthropic/claude-sonnet-4-5',
47 'openai/gpt-5.2',
48 'openai/gpt-5.1-codex',
49 'google/gemini-3-pro-preview',
50 'opencode/claude-sonnet-4-5',
51 'opencode/gpt-5.1-codex',
52] as const
53
54export type KnownOpencodeModel = (typeof OPENCODE_MODELS)[number]
55
56/** Any `provider/model` id accepted by OpenCode; known ids get autocomplete. */
57export type OpencodeModel = KnownOpencodeModel | (string & {})
58
59// Reasoning
60//
61// Each model's data for `chat({ reasoning })`: the levels it has, with the
62// provider value for each, and whether it takes a thinking token budget. The
63// data comes from models.dev. The generator that writes it comes with the model
64// catalog later. Until then, edit these entries by hand.
65
66const OPENCODE_REASONING = {
67 'anthropic/claude-opus-4-5': BUDGET_LOW_TO_HIGH,
68 'anthropic/claude-sonnet-4-5': BUDGET_OFF_TO_HIGH,
69 'openai/gpt-5.2': EFFORT_NONE_LOW_TO_XHIGH,
70 'openai/gpt-5.1-codex': EFFORT_LOW_TO_HIGH,
71 'opencode/claude-sonnet-4-5': BUDGET_OFF_TO_HIGH,
72 'opencode/gpt-5.1-codex': EFFORT_LOW_TO_HIGH,
73} satisfies Partial<Record<KnownOpencodeModel, ModelReasoning>>
74
75/**
76 * Each model's reasoning levels, and whether it takes a token budget, for
77 * `chat({ reasoning })`. A model that is not here does not reason.
78 */
79export type OpenCodeModelReasoningByName = {
80 [K in keyof typeof OPENCODE_REASONING]: ModelReasoningCapability<
81 (typeof OPENCODE_REASONING)[K]
82 >
83}
84
85/**
86 * Runtime map from model id to its reasoning data, for the text adapter. An
87 * unknown id gives `undefined`: the adapter sends no reasoning field.
88 */
89export const OPENCODE_MODEL_REASONING: Readonly<
90 Record<string, ModelReasoning>
91> = OPENCODE_REASONING