MCPcopy Index your code
hub / github.com/TanStack/ai / configureServer

Function configureServer

examples/ts-vue-chat/vite.config.ts:192–301  ·  view source on GitHub ↗
(server)

Source from the content-addressed store, hash-verified

190 {
191 name: 'api-handler',
192 configureServer(server) {
193 server.middlewares.use('/api/chat', async (req, res) => {
194 if (req.method !== 'POST') {
195 res.statusCode = 405
196 res.end('Method Not Allowed')
197 return
198 }
199
200 let body = ''
201 for await (const chunk of req) {
202 body += chunk
203 }
204
205 let params
206 try {
207 params = await chatParamsFromRequestBody(JSON.parse(body))
208 } catch (error) {
209 res.statusCode = 400
210 res.end(error instanceof Error ? error.message : 'Bad request')
211 return
212 }
213
214 try {
215 const fp = params.forwardedProps as Record<string, unknown>
216 const provider: Provider =
217 typeof fp.provider === 'string'
218 ? (fp.provider as Provider)
219 : 'openai'
220 const model: string | undefined =
221 typeof fp.model === 'string' ? fp.model : undefined
222
223 let adapter
224
225 let selectedModel: string
226
227 switch (provider) {
228 case 'anthropic':
229 selectedModel = model || 'claude-sonnet-4-5-20250929'
230 adapter = anthropicText(selectedModel)
231 break
232 case 'gemini':
233 selectedModel = model || 'gemini-2.5-flash'
234 adapter = geminiText(selectedModel)
235 break
236 case 'ollama':
237 selectedModel = model || 'mistral:7b'
238 adapter = ollamaText(selectedModel)
239 break
240 case 'openai':
241 default:
242 selectedModel = model || 'gpt-4o'
243 adapter = openaiText(selectedModel)
244 break
245 }
246
247 console.log(
248 `[API] Using provider: ${provider}, model: ${selectedModel}`,
249 )

Callers

nothing calls this directly

Calls 15

anthropicTextFunction · 0.90
geminiTextFunction · 0.90
ollamaTextFunction · 0.90
openaiTextFunction · 0.90
chatFunction · 0.90
mergeAgentToolsFunction · 0.90
maxIterationsFunction · 0.90
toServerSentEventsStreamFunction · 0.90
parseMethod · 0.80
logMethod · 0.80
valuesMethod · 0.80

Tested by

no test coverage detected