You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a7a672d
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/ai-chat/client-protocol.mdx
+40-2Lines changed: 40 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -569,7 +569,7 @@ for await (const ev of readSessionOut(sseUrl, publicAccessToken)) {
569
569
570
570
### Chunk types
571
571
572
-
Data records on the stream carry a `UIMessageChunk` from the [AI SDK](https://ai-sdk.dev/docs/ai-sdk-ui/ui-message-stream). Two Trigger.dev-specific control events ride alongside as **header-form control records** (see [Records on session.out](#records-on-session-out)).
572
+
Data records on the stream carry a `UIMessageChunk` from the [AI SDK](https://ai-sdk.dev/docs/ai-sdk-ui/ui-message-stream). Trigger.dev-specific control events ride alongside as **header-form control records** (see [Records on session.out](#records-on-session-out)).
573
573
574
574
Within a single assistant turn the AI SDK chunk types you'll typically see, in order:
575
575
@@ -584,7 +584,7 @@ Within a single assistant turn the AI SDK chunk types you'll typically see, in o
584
584
| `data-subagent` | `{ type: "data-subagent", transient: true, data: { toolCallId, seq, chunks } }` | A batch of a sub-agent's chunks written by [`chat.forwardSubAgent`](/ai-chat/patterns/sub-agents). `seq` counts from 0 per `toolCallId`; skip batches you have already applied when you resume. |
585
585
|`finish-step` / `finish`| end markers for the assistant message | Followed by the `turn-complete` control record. |
586
586
587
-
Refer to the AI SDK docs linked above for the full union — only the two control records below are Trigger.dev-specific.
587
+
Refer to the AI SDK docs linked above for the full union — only the control records below are Trigger.dev-specific.
588
588
589
589
### `turn-complete` control record
590
590
@@ -656,6 +656,44 @@ body: ""
656
656
657
657
Only agents on a recent SDK version write these. Against an older agent a reader sees neither, and has to fall back to the `turn-complete` correlation described above.
658
658
659
+
### `session-closed` control record
660
+
661
+
Signals that the session was closed by [`chat.close()`](/ai-chat/backend) and accepts no more messages.
| `trigger-control: session-closed` | Always present on this record. |
673
+
| `session-closed-reason: <text>` (optional) | The `reason` passed to `chat.close({ reason })`. Omitted when no reason was given. |
674
+
675
+
This record is written after the turn's `turn-complete`, so a reader that stops on `turn-complete` won't see it; it's there for reconnects and replay. When the close is decided before the turn ends, that `turn-complete` also carries `["session-closed", "true"]` and the optional `session-closed-reason` header.
676
+
677
+
When you receive this record:
678
+
1. Stop reading and stop sending. Further `.in` appends are refused with `409`, and a closed session can't be reopened.
679
+
2. Optionally show the reason in your UI.
680
+
681
+
### `pending-version` control record
682
+
683
+
Signals that the agent handed the chat to a new run (for example after [`chat.requestUpgrade()`](/ai-chat/patterns/version-upgrades)) and that run is parked waiting for its deployment to land.
684
+
685
+
```
686
+
headers:
687
+
["trigger-control", "pending-version"]
688
+
body: ""
689
+
```
690
+
691
+
When you receive this record:
692
+
1. Treat it as informational and keep the stream open. Messages you send meanwhile are durable and answered once the deployment lands.
693
+
2. Optionally show a "deploy in progress" indicator in your UI.
694
+
695
+
`TriggerChatTransport` surfaces this as a [`run-pending-version`](/ai-chat/reference#transport-events) event.
696
+
659
697
### Resuming a stream
660
698
661
699
If the SSE connection drops, or the server sends an `error` event, reconnect with the `Last-Event-ID` header set to the **last `record.seq_num` you successfully processed** (decoded from the batch body, not the SSE `id:` line, which is a comma-list internal to S2):
The call returns as soon as the backend accepts the action. Because `onTurnComplete` replaces the `uiMessages` with the summary, `useChat` receives the new state via the normal turn-complete flow — the UI updates automatically.
296
+
The call returns as soon as the backend accepts the action. Because `onAction` replaces the history with the summary via `chat.history.set`, `useChat` receives the new state via the normal turn-complete flow — the UI updates automatically.
0 commit comments