Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai): preserve message roles during assistant reasoning #2262

Mergedjperasmus(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/2262/headmerged by AlemTuzlak View on GitHub

Showing 6 changed files with 8 additions and 1 deletion (loading 3).

x
0 of 6 viewed, 6 left
5 additions and 0 deletions.changeset/keep-streamed-message-roles.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/ai': patch
+---
+​
+Keep streamed user and system messages separate from assistant reasoning in the chat transcript.
2 additions and 0 deletionsdocs/chat/stream-events.mdModified
View file
@@ -80,6 +80,8 @@
| `TOOL_CALL_START` / `ARGS` / `END` | `toolCallId`, `toolCallName`, args `delta` |
| `RUN_FINISHED` / `RUN_ERROR` | usage and finish reason |
​
+Give each message its own `messageId` and set its `role` on `TEXT_MESSAGE_START`. User and system messages stay separate from the assistant message during streamed reasoning.
+​
A rate-limited `RUN_ERROR` also says how long to wait. See [Rate limits](#rate-limits). For the provider response id, see [Read the provider response identity](#read-the-provider-response-identity).
​
Later, as you need them:
1 addition and 1 deletionpackages/ai/src/activities/chat/stream/processor.tsModified
View file
@@ -1725,7 +1725,7 @@
pendingRun !== undefined &&
targetRun !== undefined &&
pendingRun !== targetRun
- if (pendingId && !separateRuns) {
+ if (uiRole === 'assistant' && pendingId && !separateRuns) {
this.pendingManualMessageId = null
if (pendingId !== messageId) {