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

features.ts

198 lines5.1 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': {
56 tools: [],
57 modelOptions: {},
58 },
59 'tool-calling': {
60 tools: [getGuitars],
61 modelOptions: {},
62 },
63 'tool-choice': {
64 tools: [getGuitars],
65 modelOptions: {},
66 toolChoice: { type: 'tool', name: 'getGuitars' },
67 },
68 'parallel-tool-calls': {
69 tools: [getGuitars, compareGuitars],
70 modelOptions: {},
71 },
72 'tool-approval': {
73 tools: [addToCart],
74 modelOptions: {},
75 },
76 'text-tool-text': {
77 tools: [getGuitars],
78 modelOptions: {},
79 },
80 'structured-output': {
81 tools: [],
82 modelOptions: {},
83 modelOverrides: { byteplus: BYTEPLUS_STRUCTURED_MODEL },
84 },
85 'structured-output-stream': {
86 tools: [],
87 modelOptions: {},
88 modelOverrides: { byteplus: BYTEPLUS_STRUCTURED_MODEL },
89 },
90 'multi-turn-structured': {
91 tools: [],
92 modelOptions: {},
93 modelOverrides: { byteplus: BYTEPLUS_STRUCTURED_MODEL },
94 systemPrompt:
95 '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.',
96 },
97 'agentic-structured': {
98 tools: [getGuitars],
99 modelOptions: {},
100 modelOverrides: { byteplus: BYTEPLUS_STRUCTURED_MODEL },
101 },
102 // Pins #605 native-combined-mode: `outputSchema` + `tools` + `stream: true`
103 // in a single chat call. Default openai (gpt-4o) and anthropic
104 // (claude-sonnet-4-5) are already in their combined-mode-capable sets;
105 // gemini, vertex, and grok need overrides to gated models so the engine
106 // takes the native path instead of the legacy
107 // `runStructuredFinalization` round-trip.
108 'agentic-structured-stream': {
109 tools: [getGuitars],
110 modelOptions: {},
111 modelOverrides: {
112 gemini: 'gemini-3-flash-preview',
113 vertex: 'gemini-3-flash-preview',
114 grok: 'grok-build-0.1',
115 'vertex-grok': 'grok-4.3',
116 // Reports combined tools+schema support, so the engine takes the
117 // native path here too.
118 byteplus: BYTEPLUS_STRUCTURED_MODEL,
119 },
120 },
121 'multimodal-image': {
122 tools: [],
123 modelOptions: {},
124 },
125 'multimodal-document': {
126 tools: [],
127 modelOptions: {},
128 },
129 'multimodal-structured': {
130 tools: [],
131 modelOptions: {},
132 modelOverrides: { byteplus: BYTEPLUS_STRUCTURED_MODEL },
133 },
134 summarize: {
135 tools: [],
136 modelOptions: {},
137 },
138 'summarize-stream': {
139 tools: [],
140 modelOptions: {},
141 },
142 embedding: {
143 tools: [],
144 modelOptions: {},
145 },
146 'image-gen': {
147 tools: [],
148 modelOptions: {},
149 },
150 'image-to-image': {
151 tools: [],
152 modelOptions: {},
153 },
154 'audio-gen': {
155 tools: [],
156 modelOptions: {},
157 },
158 'sound-effects': {
159 tools: [],
160 modelOptions: {},
161 },
162 tts: {
163 tools: [],
164 modelOptions: {},
165 },
166 'voice-design': {
167 tools: [],
168 modelOptions: {},
169 },
170 transcription: {
171 tools: [],
172 modelOptions: {},
173 },
174 'transcription-diarization': {
175 tools: [],
176 modelOptions: {},
177 },
178 'video-gen': {
179 tools: [],
180 modelOptions: {},
181 },
182 'image-to-video': {
183 tools: [],
184 modelOptions: {},
185 },
186 'interactions-video': {
187 tools: [],
188 modelOptions: {},
189 },
190 'stateful-interactions': {
191 tools: [],
192 modelOptions: {},
193 },
194 'video-understanding': {
195 tools: [],
196 modelOptions: {},
197 },