Skip to content

Commit d08d971

Browse files
committed
docs(ai-chat): show the new API shapes in the rc.6 changelog entry
1 parent 99a19ae commit d08d971

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

docs/ai-chat/changelog.mdx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ A batch of fixes for edge cases around message delivery, stopping, and error han
1414
- **Idempotent input appends.** Sends to `session.in` carry an idempotency key, so a client retry after a network blip can't append the same message twice.
1515
- **Stop clears streaming state.** Stopping a generation now clears the session's streaming snapshot, so a page reload right after a stop no longer replays the stopped turn.
1616
- **`onTurnComplete` fires on errored turns.** When `run()` or a lifecycle hook throws, `onTurnComplete` now runs with `error` carrying the thrown value and `finishReason: "error"`, and the failed turn's user message is persisted so it isn't lost on the next run. Use this to mark the turn failed in your own storage. See [error handling](/ai-chat/error-handling#using-onturncomplete).
17+
18+
```ts
19+
onTurnComplete: async ({ chatId, uiMessages, stopped, error }) => {
20+
await db.chat.update({
21+
where: { id: chatId },
22+
data: {
23+
messages: uiMessages,
24+
lastTurnStatus: error ? "errored" : stopped ? "stopped" : "ok",
25+
},
26+
});
27+
},
28+
```
1729
- **Full tag sets on chat runs.** Runs triggered by chat sessions can now carry the full set of dashboard tags instead of being silently truncated.
1830
- **Stream hygiene for custom agents.** Manual `chat.writeTurnComplete()` callers now trim the output stream the way `chat.agent` does, sending a custom action no longer leaves a second stream reader running, and a long-lived `watch` subscription no longer grows its dedupe set without bound.
1931

@@ -32,7 +44,21 @@ Two fixes for the [Head Start](/ai-chat/fast-starts) handover:
3244

3345
Stopping a generation no longer wedges the run: `turn.complete()` bare-awaited the AI SDK's `totalUsage` promise, which never settles after a stop-abort, so the loop hung inside the stopped turn and the chat couldn't take another message. It's now raced with a timeout, the same guard `chat.agent`'s turn loop uses.
3446

35-
Continuation runs also no longer invoke the model with an empty prompt: a message-less continuation boot now waits for the next session input, and `turn.continuation` is preserved so your loop can seed stored history on the first turn. See [chat.createSession](/ai-chat/backend#chat-createsession).
47+
Continuation runs also no longer invoke the model with an empty prompt: a message-less continuation boot now waits for the next session input, and `turn.continuation` is preserved so your loop can seed stored history on the first turn:
48+
49+
```ts
50+
for await (const turn of session) {
51+
if (turn.continuation && turn.number === 0) {
52+
const stored = await loadMessages(turn.chatId);
53+
const incoming = turn.uiMessages.filter((m) => !stored.some((s) => s.id === m.id));
54+
await turn.setMessages([...stored, ...incoming]);
55+
}
56+
57+
// ... streamText + turn.complete as usual
58+
}
59+
```
60+
61+
See [chat.createSession](/ai-chat/backend#chat-createsession).
3662

3763
## trigger skills: agent skills for your coding assistant
3864

0 commit comments

Comments
 (0)