-
-
Notifications
You must be signed in to change notification settings - Fork 301
fix(ai-persistence): persist structured output #1126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@tanstack/ai': patch | ||
| '@tanstack/ai-persistence': patch | ||
| --- | ||
|
|
||
| Persist completed structured outputs as structured-output message parts and restore them during chat hydration. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,7 +99,7 @@ generation hooks. [How persistence works](./internals) has the rest. | |
| | --- | --- | --- | | ||
| | **Start of a run** (`onStart`) | Pending turn (just-submitted user message + prior history) so a reload mid-generation still shows the question | Yes. Failure does not abort the run; finish is authoritative | | ||
| | **Interrupt boundary** | New interrupt records, run status `interrupted`, and a thread snapshot of current messages | No. Store failures propagate | | ||
| | **Finish** (`onFinish`) | Complete transcript (including the terminal assistant reply with its stream `messageId` for in-place reload identity), run status `completed`, and commit of consumed resumes | No. The transcript is saved **before** the run is marked completed | | ||
| | **Finish** (`onFinish`) | Complete transcript (including completed assistant messages, their stream identities, and any completed structured-output part), run status `completed`, and commit of consumed resumes | No. The transcript is saved **before** the run is marked completed | | ||
| | **Optionally while streaming** | Throttled partial assistant text when `snapshotStreaming: true` | Yes | | ||
|
|
||
| ```ts group=chat-persistence | ||
|
|
@@ -112,6 +112,12 @@ Streaming snapshots default off (finish is the authoritative save); enable | |
| them to trade extra writes for partial-output durability. Tune the interval | ||
| with `snapshotIntervalMs` (default `1000`). | ||
|
|
||
| The chat engine completes the canonical transcript before `onFinish` runs, and | ||
| `withPersistence` saves that transcript directly. Native-combined output keeps | ||
| the structured result on its terminal assistant message. The | ||
| separate-finalization path can preserve a plain-text assistant message followed | ||
| by a structured-output assistant message. | ||
|
|
||
|
Comment on lines
+115
to
+120
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π Maintainability & Code Quality | π‘ Minor | β‘ Quick win Add a client hydration example. This page describes persisted structured-output hydration but only shows the server As per coding guidelines: βWhen a doc spans both server and client, include snippets for both halves.β π€ Prompt for AI AgentsSource: Coding guidelines
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of scope for my changes.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
π You are interacting with an AI system. |
||
| On **error**, the run is marked `failed`. On **abort**, the run is marked | ||
| `aborted` with a `finishedAt`; `interrupted` is written only at an interrupt | ||
| boundary, and it is not terminal. Resumes accepted in `onConfig` are **not** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.