Commit 5ba1b6d
committed
feat(chat): route Gemma via LiteLLM, add Qwen 3.6, deadline + fallback
Regolo's gemma4-31b endpoint hangs upstream — every notebook chat with
the default Gemma model just spun forever because the AI SDK has no
built-in first-token deadline. This change:
- Adds litellmFetchWithThinkingDisabled (sibling to regoloThinkingFetch)
injecting Ollama's `think: false` so LiteLLM-served gemma streams
content instead of burning its entire token budget on `reasoning`.
- Re-routes the user-facing "Gemma 4" model from Regolo → LiteLLM. Old
`gemma-regolo` ID is aliased server-side and migrated client-side
(chatStore v6) to the new `gemma-litellm` ID.
- Adds Qwen 3.6 27B as a selectable model (already in the existing
Regolo reasoning-stream allowlist, so no extra wiring).
- Introduces a 20s first-token deadline + single-step cross-provider
fallback (gemma-litellm ↔ gpt-oss-regolo) in responseStreamingService.
Qwen entries intentionally have no `fallback` field — the
Chinese-only-when-selected firewall (informed-consent boundary,
documented in ModelConfig).
- Fixes pre-existing bug: getModel('litellm', modelId) ignored the
modelId arg and always used LITELLM_DEFAULT_MODEL.
Fallback is silent end-user-side: server emits a `fallback` SSE event,
both runtime adapters log it to the browser console, no UI banner.
Implementation notes:
- streamAndAccumulate / streamAndAccumulateWithReasoning now have a
shared `wrapWithCompatCatch` factory and an `*OrThrow` internal layer
used by streamWithFallback. Existing chat router callers see the same
null-on-failure shape, plus the new deadline + empty-completion
safety nets for free.
- Single shared deadline across initial-probe iterations (was
accidentally giving 40s grace via per-call setTimeout).
- Reasoning streamer split into Phase-1 (race vs deadline until first
text) + Phase-2 (drain without race) — eliminates wasted Promise.race
microtask hops on every reasoning chunk after first content.
- Uses native AbortSignal.any() (Node 20.3+) instead of a hand-rolled
composeAbortSignals helper.1 parent f44d8d6 commit 5ba1b6d
9 files changed
Lines changed: 632 additions & 205 deletions
File tree
- apps/api
- routes/chat
- agents
- services
- services/ai
- packages/chat/src
- hooks
- runtime
- stores
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
36 | 51 | | |
37 | 52 | | |
38 | 53 | | |
39 | 54 | | |
40 | 55 | | |
41 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
42 | 62 | | |
43 | 63 | | |
44 | 64 | | |
45 | 65 | | |
46 | 66 | | |
47 | | - | |
48 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
49 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
50 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
51 | 90 | | |
52 | 91 | | |
53 | 92 | | |
54 | 93 | | |
55 | 94 | | |
56 | | - | |
57 | | - | |
58 | | - | |
| 95 | + | |
59 | 96 | | |
60 | 97 | | |
61 | 98 | | |
| |||
108 | 145 | | |
109 | 146 | | |
110 | 147 | | |
| 148 | + | |
111 | 149 | | |
112 | 150 | | |
113 | 151 | | |
| |||
169 | 207 | | |
170 | 208 | | |
171 | 209 | | |
172 | | - | |
| 210 | + | |
| 211 | + | |
173 | 212 | | |
174 | | - | |
| 213 | + | |
175 | 214 | | |
176 | 215 | | |
177 | 216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 18 | + | |
22 | 19 | | |
23 | 20 | | |
24 | 21 | | |
| |||
30 | 27 | | |
31 | 28 | | |
32 | 29 | | |
33 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
253 | 254 | | |
254 | 255 | | |
255 | 256 | | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
264 | 261 | | |
265 | 262 | | |
266 | 263 | | |
| |||
281 | 278 | | |
282 | 279 | | |
283 | 280 | | |
284 | | - | |
285 | | - | |
286 | | - | |
| 281 | + | |
287 | 282 | | |
288 | | - | |
289 | 283 | | |
290 | 284 | | |
291 | 285 | | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
299 | 294 | | |
300 | | - | |
| 295 | + | |
301 | 296 | | |
| 297 | + | |
302 | 298 | | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
| 299 | + | |
323 | 300 | | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
| 301 | + | |
| 302 | + | |
347 | 303 | | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
375 | 308 | | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
| 309 | + | |
| 310 | + | |
399 | 311 | | |
400 | 312 | | |
401 | 313 | | |
402 | 314 | | |
403 | 315 | | |
404 | | - | |
| 316 | + | |
405 | 317 | | |
406 | 318 | | |
407 | 319 | | |
| |||
466 | 378 | | |
467 | 379 | | |
468 | 380 | | |
469 | | - | |
| 381 | + | |
470 | 382 | | |
471 | 383 | | |
472 | 384 | | |
| |||
0 commit comments