Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

model-meta.ts

86 lines2.7 KB

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_MAX = {
7 levels: { low: 'low', medium: 'medium', high: 'high', max: 'max' },
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_MAX = {
21 levels: {
22 low: 'low',
23 medium: 'medium',
24 high: 'high',
25 xhigh: 'xhigh',
26 max: 'max',
27 },
28 budget: false,
29} as const
30/**
31 * Models known to work with Claude Code. The harness accepts any Anthropic
32 * model id (and the `opus` / `sonnet` / `haiku` aliases resolved by the CLI),
33 * so this list exists for autocomplete — any string is accepted via the
34 * `(string & {})` escape hatch in {@link ClaudeCodeModel}.
35 */
36export const CLAUDE_CODE_MODELS = [
37 'claude-opus-4-8',
38 'claude-opus-4-7',
39 'claude-opus-4-6',
40 'claude-sonnet-4-6',
41 'claude-haiku-4-5',
42 'opus',
43 'sonnet',
44 'haiku',
45] as const
46​
47export type KnownClaudeCodeModel = (typeof CLAUDE_CODE_MODELS)[number]
48​
49/** Any Claude model id accepted by Claude Code; known ids get autocomplete. */
50export type ClaudeCodeModel = KnownClaudeCodeModel | (string & {})
51​
52// Reasoning
53//
54// Each model's data for `chat({ reasoning })`: the levels it has, with the
55// provider value for each, and whether it takes a thinking token budget. The
56// data comes from models.dev. The generator that writes it comes with the model
57// catalog later. Until then, edit these entries by hand.
58​
59const CLAUDE_CODE_REASONING = {
60 'claude-opus-4-8': EFFORT_LOW_TO_MAX,
61 'claude-opus-4-7': EFFORT_LOW_TO_MAX,
62 'claude-opus-4-6': BUDGET_LOW_TO_HIGH_MAX,
63 'claude-sonnet-4-6': BUDGET_LOW_TO_HIGH_MAX,
64 'claude-haiku-4-5': BUDGET_OFF_TO_HIGH,
65 opus: EFFORT_LOW_TO_MAX,
66 sonnet: BUDGET_LOW_TO_HIGH_MAX,
67 haiku: BUDGET_OFF_TO_HIGH,
68} satisfies Partial<Record<KnownClaudeCodeModel, ModelReasoning>>
69​
70/**
71 * Each model's reasoning levels, and whether it takes a token budget, for
72 * `chat({ reasoning })`. A model that is not here does not reason.
73 */
74export type ClaudeCodeModelReasoningByName = {
75 [K in keyof typeof CLAUDE_CODE_REASONING]: ModelReasoningCapability<
76 (typeof CLAUDE_CODE_REASONING)[K]
77 >
79​
80/**
81 * Runtime map from model id to its reasoning data, for the text adapter. An
82 * unknown id gives `undefined`: the adapter sends no reasoning field.
83 */
84export const CLAUDE_CODE_MODEL_REASONING: Readonly<
85 Record<string, ModelReasoning>
86> = CLAUDE_CODE_REASONING