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

model-meta.ts

198 lines7.9 KB

1import { GENERATED_BEDROCK_MODELS } from './model-catalog.generated.js'
2import type { Modality, ModelReasoning } from '@tanstack/ai'
3import type { ModelReasoningCapability } from '@tanstack/ai/adapter-internals'
4import type { BedrockTextProviderOptions } from './text/text-provider-options'
5import type { BedrockConverseProviderOptions } from './converse/provider-options'
6import type {
7 BedrockCohereEmbeddingProviderOptions,
8 BedrockEmbeddingProviderOptions,
9 BedrockTitanImageEmbeddingProviderOptions,
10 BedrockTitanTextEmbeddingProviderOptions,
11} from './embedding/embedding-provider-options'
12​
13// Reasoning shapes: the levels a model has for `chat({ reasoning })`, and
14// the provider value to send for each. Each model points at one of them.
15const BUDGET_OFF_HIGH = {
16 levels: { off: 'off', high: 'high' },
17 budget: true,
18} as const
19const EFFORT_LOW_TO_HIGH = {
20 levels: { low: 'low', medium: 'medium', high: 'high' },
21 budget: false,
22} as const
23const EFFORT_NONE_HIGH = {
24 levels: { off: 'none', high: 'high' },
25 budget: false,
26} as const
27​
28type Entry = (typeof GENERATED_BEDROCK_MODELS)[number]
29​
30/**
31 * Type-level per-API filter over the generated catalog. Because the catalog is
32 * `as const`, `Extract` preserves literal `id` unions (no widening to `string`).
33 */
34type IdsWhere<TApi extends 'converse' | 'chat' | 'responses'> = Extract<
35 Entry,
36 { apis: Record<TApi, true> }
37>['id']
38​
39export type BedrockConverseModels = IdsWhere<'converse'>
40export type BedrockChatModels = IdsWhere<'chat'>
41export type BedrockResponsesModels = IdsWhere<'responses'>
42​
43/** Runtime catalogs. Cast-free narrowing via a type predicate (the ai-bedrock pattern). */
44export const BEDROCK_CONVERSE_MODELS: ReadonlyArray<BedrockConverseModels> =
45 GENERATED_BEDROCK_MODELS.filter(
46 (m): m is Extract<Entry, { apis: { converse: true } }> => m.apis.converse,
47 ).map((m) => m.id)
48​
49export const BEDROCK_CHAT_MODELS: ReadonlyArray<BedrockChatModels> =
50 GENERATED_BEDROCK_MODELS.filter(
51 (m): m is Extract<Entry, { apis: { chat: true } }> => m.apis.chat,
52 ).map((m) => m.id)
53​
54export const BEDROCK_RESPONSES_MODELS: ReadonlyArray<BedrockResponsesModels> =
55 GENERATED_BEDROCK_MODELS.filter(
56 (m): m is Extract<Entry, { apis: { responses: true } }> => m.apis.responses,
57 ).map((m) => m.id)
58​
59/** Per-model input modalities (drives type-safe multimodal content). Covers ALL models. */
60export type BedrockModelInputModalitiesByName = {
61 [E in Entry as E['id']]: E['input']
63​
64/**
65 * Runtime map from model id to its input modalities, for the text adapters'
66 * `inputModalities`. An unknown id gives `undefined`.
67 */
68export const BEDROCK_MODEL_INPUT_MODALITIES: Readonly<
69 Record<string, ReadonlyArray<Modality>>
70> = Object.fromEntries(GENERATED_BEDROCK_MODELS.map((m) => [m.id, m.input]))
71​
72/** Provider options per model. Same options for every model; keyed over the full catalog. */
73export type BedrockChatModelProviderOptionsByName = {
74 [E in Entry as E['id']]: BedrockTextProviderOptions
76​
77/** Converse provider options per model (narrower than the Chat Completions set). */
78export type BedrockConverseModelProviderOptionsByName = {
79 [E in Entry as E['id']]: BedrockConverseProviderOptions
81​
82/** No provider-specific tools — empty tuple makes cross-provider ProviderTool a compile error. */
83export type BedrockChatModelToolCapabilitiesByName = {
84 [E in Entry as E['id']]: readonly []
86​
87export type ResolveProviderOptions<TModel extends string> =
88 TModel extends keyof BedrockChatModelProviderOptionsByName
89 ? BedrockChatModelProviderOptionsByName[TModel]
90 : BedrockTextProviderOptions
91​
92export type ResolveConverseProviderOptions<TModel extends string> =
93 TModel extends keyof BedrockConverseModelProviderOptionsByName
94 ? BedrockConverseModelProviderOptionsByName[TModel]
95 : BedrockConverseProviderOptions
96​
97export type ResolveInputModalities<TModel extends string> =
98 TModel extends keyof BedrockModelInputModalitiesByName
99 ? BedrockModelInputModalitiesByName[TModel]
100 : readonly ['text']
101​
102// ============================================================================
103// Reasoning
104// ============================================================================
105//
106// Each model's data for `chat({ reasoning })`: the levels it has, with the
107// provider value for each, and whether it takes a thinking token budget. The
108// data comes from models.dev. The generator that writes it comes with the model
109// catalog later. Until then, edit these entries by hand.
110// scripts/fetch-bedrock-models.ts does not touch them.
111​
112const BEDROCK_REASONING = {
113 'openai.gpt-oss-120b-1:0': EFFORT_LOW_TO_HIGH,
114 'openai.gpt-oss-20b-1:0': EFFORT_LOW_TO_HIGH,
115 'us.anthropic.claude-sonnet-4-5-20250929-v1:0': BUDGET_OFF_HIGH,
116 'us.anthropic.claude-haiku-4-5-20251001-v1:0': BUDGET_OFF_HIGH,
117 'google.gemma-4-31b': EFFORT_NONE_HIGH,
118 'google.gemma-4-26b-a4b': EFFORT_NONE_HIGH,
119 'google.gemma-4-e2b': EFFORT_NONE_HIGH,
120} satisfies Partial<Record<Entry['id'], ModelReasoning>>
121​
122/**
123 * Each model's reasoning levels, and whether it takes a token budget, for
124 * `chat({ reasoning })`. A model that is not here does not reason.
125 */
126export type BedrockModelReasoningByName = {
127 [K in keyof typeof BEDROCK_REASONING]: ModelReasoningCapability<
128 (typeof BEDROCK_REASONING)[K]
129 >
131​
132/**
133 * Runtime map from model id to its reasoning data, for the text adapters. An
134 * unknown id gives `undefined`: the adapter sends no reasoning field.
135 */
136export const BEDROCK_MODEL_REASONING: Readonly<Record<string, ModelReasoning>> =
137 BEDROCK_REASONING
138​
139/**
140 * The Claude families that reject a forced tool (`any` or a named `tool`) on
141 * every request, with or without thinking. A Bedrock id has the family name
142 * inside it, for example `us.anthropic.claude-opus-5-5-...`.
143 * ponytail: names, not catalog entries, because the generated catalog has no
144 * entry for these models yet. Move it to the catalog when it has them.
145 */
146export const BEDROCK_CLAUDE_NO_FORCED_TOOL_FAMILIES: ReadonlyArray<string> = [
147 'claude-fable-5-1',
148 'claude-mythos-5-1',
149 'claude-opus-5-5',
150 'claude-sonnet-5-5',
152​
153// ============================================================================
154// Embedding models
155// ============================================================================
156​
157/**
158 * Embedding models reachable through Bedrock's `InvokeModel` API. These are
159 * not part of the generated Converse catalog (embedding models have no
160 * conversational surface), so they're maintained by hand here.
161 */
162export const BEDROCK_EMBEDDING_MODELS = [
163 'amazon.titan-embed-text-v2:0',
164 'amazon.titan-embed-image-v1',
165 'cohere.embed-english-v3',
166 'cohere.embed-multilingual-v3',
167] as const
168​
169export type BedrockEmbeddingModel = (typeof BEDROCK_EMBEDDING_MODELS)[number]
170​
171/**
172 * Type-only map from embedding model name to its provider options type.
173 * The Cohere models make `modelOptions` REQUIRED at the `embed()` call site
174 * because `inputType` is a required field.
175 */
176export type BedrockEmbeddingModelProviderOptionsByName = {
177 'amazon.titan-embed-text-v2:0': BedrockTitanTextEmbeddingProviderOptions
178 'amazon.titan-embed-image-v1': BedrockTitanImageEmbeddingProviderOptions
179 'cohere.embed-english-v3': BedrockCohereEmbeddingProviderOptions
180 'cohere.embed-multilingual-v3': BedrockCohereEmbeddingProviderOptions
182​
183/**
184 * Per-model input modalities for embedding models. Titan Multimodal accepts
185 * text and/or images (including fused text+image items embedded into one
186 * vector); the rest are text-only, so image inputs fail at compile time.
187 */
188export type BedrockEmbeddingModelInputModalitiesByName = {
189 'amazon.titan-embed-text-v2:0': readonly ['text']
190 'amazon.titan-embed-image-v1': readonly ['text', 'image']
191 'cohere.embed-english-v3': readonly ['text']
192 'cohere.embed-multilingual-v3': readonly ['text']
194​
195export type ResolveEmbeddingProviderOptions<TModel extends string> =
196 TModel extends keyof BedrockEmbeddingModelProviderOptionsByName
197 ? BedrockEmbeddingModelProviderOptionsByName[TModel]
198 : BedrockEmbeddingProviderOptions