Commit cb04ed8
Fix AI Chat reasoning display with correct Vercel AI SDK Data Stream Protocol
This commit fixes the reasoning/thinking display in the Studio AI chat by
correcting both the backend stream encoding and frontend parsing to align
with the Vercel AI SDK v6 Data Stream Protocol.
## Backend Changes
**packages/services/service-ai/src/stream/vercel-stream-encoder.ts**
- Add `dataStreamLine()` helper for Data Stream Protocol format
- Fix reasoning event encoding to use `g:` prefix instead of standard SSE:
- `reasoning-start` → `g:{"text":""}\n`
- `reasoning-delta` → `g:{"text":"..."}\n`
- `reasoning-end` → empty string (no marker needed)
- Aligns with Vercel AI SDK protocol specification
**packages/services/service-ai/src/__tests__/vercel-stream-encoder.test.ts**
- Update tests to expect `g:` prefix format for reasoning events
- All 17 tests passing
## Frontend Changes
**apps/studio/src/components/AiChatPanel.tsx**
- Extract reasoning from `message.parts` instead of incorrect `data` property
- Process `reasoning-delta`/`reasoning` parts from message parts array
- Process `step-start`/`step-finish` parts for progress tracking
- Remove unused stream event type interfaces (fixes TypeScript warnings)
## Technical Details
The Vercel AI SDK v6 Data Stream Protocol uses prefix identifiers:
- `0:` - Text content
- `2:` - Custom data annotations
- `g:` - Reasoning/thinking content (DeepSeek R1, OpenAI o1-style models)
Previously the backend was encoding reasoning as standard SSE events
(`data: {"type":"reasoning-delta",...}`) which the frontend couldn't
access through the `useChat` hook. The correct format is the Data Stream
Protocol format (`g:{"text":"..."}\n`) which appears in `message.parts`.
Fixes: #1093 (AI chat reasoning display)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>1 parent 6b50186 commit cb04ed8
File tree
3 files changed
+43
-98
lines changed- apps/studio/src/components
- packages/services/service-ai/src
- __tests__
- stream
3 files changed
+43
-98
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | 37 | | |
70 | 38 | | |
71 | 39 | | |
| |||
457 | 425 | | |
458 | 426 | | |
459 | 427 | | |
460 | | - | |
| 428 | + | |
461 | 429 | | |
462 | 430 | | |
463 | | - | |
464 | 431 | | |
465 | 432 | | |
466 | 433 | | |
| |||
473 | 440 | | |
474 | 441 | | |
475 | 442 | | |
476 | | - | |
| 443 | + | |
477 | 444 | | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | | - | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
503 | | - | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
508 | 463 | | |
| 464 | + | |
| 465 | + | |
509 | 466 | | |
510 | 467 | | |
511 | | - | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
512 | 471 | | |
513 | 472 | | |
514 | 473 | | |
| |||
Lines changed: 6 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
| 132 | + | |
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
| 139 | + | |
144 | 140 | | |
145 | 141 | | |
146 | | - | |
| 142 | + | |
147 | 143 | | |
148 | 144 | | |
149 | 145 | | |
150 | 146 | | |
151 | 147 | | |
152 | 148 | | |
153 | 149 | | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
| 150 | + | |
160 | 151 | | |
161 | 152 | | |
162 | | - | |
| 153 | + | |
163 | 154 | | |
164 | 155 | | |
165 | 156 | | |
166 | 157 | | |
167 | 158 | | |
168 | 159 | | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
| 160 | + | |
174 | 161 | | |
175 | 162 | | |
176 | 163 | | |
| |||
Lines changed: 12 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
26 | 34 | | |
27 | 35 | | |
28 | 36 | | |
| |||
72 | 80 | | |
73 | 81 | | |
74 | 82 | | |
| 83 | + | |
75 | 84 | | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
| 85 | + | |
80 | 86 | | |
81 | 87 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
| 88 | + | |
87 | 89 | | |
88 | 90 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 91 | + | |
93 | 92 | | |
94 | 93 | | |
95 | 94 | | |
| |||
0 commit comments