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

features.ts

204 lines5.3 KB

1import type { ReasoningRequest, ToolChoice } from '@tanstack/ai'
2import type { Feature, Provider } from '@/lib/types'
3import { getGuitars, compareGuitars, addToCart } from '@/lib/tools'
4​
5interface FeatureConfig {
6 tools: Array<any>
7 modelOptions: Record<string, any>
8 /** `chat({ reasoning })` for the feature. */
9 reasoning?: ReasoningRequest
10 /** `chat({ toolChoice })` for the feature. */
11 toolChoice?: ToolChoice
12 modelOverrides?: Partial<Record<Provider, string>>
13 dedicatedRoute?: string
14 /**
15 * Optional system prompt override. Defaults (in `api.chat.ts`) to the
16 * guitar-store assistant prompt that covers most features; only set this
17 * when the feature genuinely needs a different persona (e.g. the
18 * `multi-turn-structured` chef recipe-builder).
19 */
20 systemPrompt?: string
22​
23/**
24 * The byteplus model every structured-output feature overrides to.
25 *
26 * The default e2e chat model (`seed-2-0-lite-260428`, in `providers.ts`)
27 * rejects both `response_format: json_schema` and `json_object` — live-probed,
28 * and the adapter throws rather than silently degrading, so any feature that
29 * asks for a schema has to move off it. `seed-2-0-lite-260228` is the nearest
30 * sibling that accepts json_schema *and* honours it (glm-4-7 accepts it and
31 * returns prose, so acceptance alone isn't enough), and it keeps image input,
32 * which `multimodal-structured` needs.
33 */
34const BYTEPLUS_STRUCTURED_MODEL = 'seed-2-0-lite-260228'
35​
36export const featureConfigs: Record<Feature, FeatureConfig> = {
37 chat: {
38 tools: [],
39 modelOptions: {},
40 },
41 'one-shot-text': {
42 tools: [],
43 modelOptions: {},
44 },
45 reasoning: {
46 tools: [],
47 modelOptions: {},
48 reasoning: { level: 'high', summary: true },
49 modelOverrides: {
50 openai: 'o3',
51 anthropic: 'claude-sonnet-4-5',
52 mistral: 'magistral-medium-latest',
53 },
54 },
55 'multi-turn-reasoning': {
56 tools: [getGuitars],
57 modelOptions: {},
58 reasoning: { level: 'high', summary: true },
59 modelOverrides: { anthropic: 'claude-sonnet-4-5' },
60 },
61 'multi-turn': {
62 tools: [],
63 modelOptions: {},
64 },
65 'tool-calling': {
66 tools: [getGuitars],
67 modelOptions: {},
68 },
69 'tool-choice': {
70 tools: [getGuitars],
71 modelOptions: {},
72 toolChoice: { type: 'tool', name: 'getGuitars' },
73 },
74 'parallel-tool-calls': {
75 tools: [getGuitars, compareGuitars],
76 modelOptions: {},
77 },
78 'tool-approval': {
79 tools: [addToCart],
80 modelOptions: {},
81 },
82 'text-tool-text': {
83 tools: [getGuitars],
84 modelOptions: {},
85 },
86 'structured-output': {
87 tools: [],
88 modelOptions: {},
89 modelOverrides: { byteplus: BYTEPLUS_STRUCTURED_MODEL },
90 },
91 'structured-output-stream': {
92 tools: [],
93 modelOptions: {},
94 modelOverrides: { byteplus: BYTEPLUS_STRUCTURED_MODEL },
95 },
96 'multi-turn-structured': {
97 tools: [],
98 modelOptions: {},
99 modelOverrides: { byteplus: BYTEPLUS_STRUCTURED_MODEL },
100 systemPrompt:
101 'You are a chef assistant that always responds with a single recipe matching the provided JSON schema. When the user asks for modifications, produce a new recipe in the same shape that reflects the change. Stay terse — short titles, short steps.',
102 },
103 'agentic-structured': {
104 tools: [getGuitars],
105 modelOptions: {},
106 modelOverrides: { byteplus: BYTEPLUS_STRUCTURED_MODEL },
107 },
108 // Pins #605 native-combined-mode: `outputSchema` + `tools` + `stream: true`
109 // in a single chat call. Default openai (gpt-4o) and anthropic
110 // (claude-sonnet-4-5) are already in their combined-mode-capable sets;
111 // gemini, vertex, and grok need overrides to gated models so the engine
112 // takes the native path instead of the legacy
113 // `runStructuredFinalization` round-trip.
114 'agentic-structured-stream': {
115 tools: [getGuitars],
116 modelOptions: {},
117 modelOverrides: {
118 gemini: 'gemini-3-flash-preview',
119 vertex: 'gemini-3-flash-preview',
120 grok: 'grok-build-0.1',
121 'vertex-grok': 'grok-4.3',
122 // Reports combined tools+schema support, so the engine takes the
123 // native path here too.
124 byteplus: BYTEPLUS_STRUCTURED_MODEL,
125 },
126 },
127 'multimodal-image': {
128 tools: [],
129 modelOptions: {},
130 },
131 'multimodal-document': {
132 tools: [],
133 modelOptions: {},
134 },
135 'multimodal-structured': {
136 tools: [],
137 modelOptions: {},
138 modelOverrides: { byteplus: BYTEPLUS_STRUCTURED_MODEL },
139 },
140 summarize: {
141 tools: [],
142 modelOptions: {},
143 },
144 'summarize-stream': {
145 tools: [],
146 modelOptions: {},
147 },
148 embedding: {
149 tools: [],
150 modelOptions: {},
151 },
152 'image-gen': {
153 tools: [],
154 modelOptions: {},
155 },
156 'image-to-image': {
157 tools: [],
158 modelOptions: {},
159 },
160 'audio-gen': {
161 tools: [],
162 modelOptions: {},
163 },
164 'sound-effects': {
165 tools: [],
166 modelOptions: {},
167 },
168 tts: {
169 tools: [],
170 modelOptions: {},
171 },
172 'voice-design': {
173 tools: [],
174 modelOptions: {},
175 },
176 transcription: {
177 tools: [],
178 modelOptions: {},
179 },
180 'transcription-diarization': {
181 tools: [],
182 modelOptions: {},
183 },
184 'video-gen': {
185 tools: [],
186 modelOptions: {},
187 },
188 'image-to-video': {
189 tools: [],
190 modelOptions: {},
191 },
192 'interactions-video': {
193 tools: [],
194 modelOptions: {},
195 },
196 'stateful-interactions': {
197 tools: [],
198 modelOptions: {},
199 },
200 'video-understanding': {
201 tools: [],
202 modelOptions: {},
203 },