@trigger.dev/sdk 0.0.0-prerelease-20260909121655 → 0.0.0-prerelease-20260911153544
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/v3/ai.d.ts +36 -0
- package/dist/commonjs/v3/ai.js +260 -55
- package/dist/commonjs/v3/ai.js.map +1 -1
- package/dist/commonjs/v3/auth.d.ts +10 -4
- package/dist/commonjs/v3/auth.js.map +1 -1
- package/dist/commonjs/v3/chatSnapshotIo.js +6 -7
- package/dist/commonjs/v3/chatSnapshotIo.js.map +1 -1
- package/dist/commonjs/v3/retry.d.ts +4 -0
- package/dist/commonjs/v3/retry.js +22 -13
- package/dist/commonjs/v3/retry.js.map +1 -1
- package/dist/commonjs/v3/test/transcript-storage-tests.js.map +1 -1
- package/dist/commonjs/v3/transcriptStorage.d.ts +43 -6
- package/dist/commonjs/v3/transcriptStorage.js +87 -8
- package/dist/commonjs/v3/transcriptStorage.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/ai.d.ts +36 -0
- package/dist/esm/v3/ai.js +260 -55
- package/dist/esm/v3/ai.js.map +1 -1
- package/dist/esm/v3/auth.d.ts +10 -4
- package/dist/esm/v3/auth.js.map +1 -1
- package/dist/esm/v3/chatSnapshotIo.js +7 -8
- package/dist/esm/v3/chatSnapshotIo.js.map +1 -1
- package/dist/esm/v3/retry.d.ts +4 -0
- package/dist/esm/v3/retry.js +14 -8
- package/dist/esm/v3/retry.js.map +1 -1
- package/dist/esm/v3/test/transcript-storage-tests.js.map +1 -1
- package/dist/esm/v3/transcriptStorage.d.ts +43 -6
- package/dist/esm/v3/transcriptStorage.js +85 -8
- package/dist/esm/v3/transcriptStorage.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/docs/ai-chat/background-injection.mdx +54 -1
- package/docs/ai-chat/how-it-works.mdx +1 -1
- package/docs/ai-chat/migrating-from-hydrate-messages.mdx +299 -0
- package/docs/ai-chat/patterns/database-persistence.mdx +18 -7
- package/docs/ai-chat/reference.mdx +2 -1
- package/docs/ai-chat/side-channels.mdx +1 -1
- package/docs/ai-chat/transcript-storage.mdx +21 -7
- package/docs/self-hosting/security.mdx +12 -0
- package/package.json +2 -2
- package/skills/trigger-chat-agent-advanced/SKILL.md +31 -15
|
@@ -185,37 +185,53 @@ compaction: {
|
|
|
185
185
|
},
|
|
186
186
|
```
|
|
187
187
|
|
|
188
|
-
### 5. Actions:
|
|
189
|
-
|
|
190
|
-
`actionSchema` validates; `onAction`
|
|
191
|
-
`remove`, `getPendingToolCalls`, `extractNewToolResults`).
|
|
192
|
-
`onAction` only
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
188
|
+
### 5. Actions: edit state, and optionally answer
|
|
189
|
+
|
|
190
|
+
`actionSchema` validates; `onAction` edits via `chat.history` (`slice`, `replace`, `rollbackTo`,
|
|
191
|
+
`remove`, `getPendingToolCalls`, `extractNewToolResults`). An action fires `hydrateMessages` and
|
|
192
|
+
`onAction` only. Return nothing for an edit-only action: no model call, and the turn counter does not
|
|
193
|
+
advance. Return `chat.turn()` to answer after the edit: a turn runs on the edited history with
|
|
194
|
+
everything a turn has (the agent's system prompt and tools, steering, compaction, injected
|
|
195
|
+
instructions, `onTurnStart` and `onTurnComplete`, persistence), and `run()` receives it with
|
|
196
|
+
`trigger: "action-turn"`. `onAction` has no `streamText` argument, and returning a
|
|
197
|
+
`StreamTextResult`, string or `UIMessage` from it throws.
|
|
198
|
+
|
|
199
|
+
Persistence splits by model. With transcript storage (`storage` on `chat.agent`; the platform
|
|
200
|
+
snapshot by default), the runtime hands storage a changeset with `reason: "action"` after an action
|
|
201
|
+
that changed the conversation: an undo is one `truncateAfter`, a regenerate is a `truncateAfter`
|
|
202
|
+
followed by the new answer's `put` when the turn completes, and an edit is a `put` for the edited
|
|
203
|
+
id. With the deprecated `hydrateMessages` your store is the source of truth and the runtime does
|
|
204
|
+
not write, so mirror every mutation yourself: a regenerate is a delete and an insert, and the
|
|
205
|
+
answer that follows `chat.turn()` arrives through `onTurnComplete` like any turn's answer.
|
|
201
206
|
|
|
202
207
|
```ts
|
|
203
208
|
export const myChat = chat.agent({
|
|
204
209
|
id: "my-chat",
|
|
205
210
|
actionSchema: z.discriminatedUnion("type", [
|
|
206
211
|
z.object({ type: z.literal("undo") }),
|
|
212
|
+
z.object({ type: z.literal("regenerate") }),
|
|
207
213
|
z.object({ type: z.literal("rollback"), targetMessageId: z.string() }),
|
|
208
214
|
]),
|
|
209
215
|
onAction: async ({ action }) => {
|
|
210
|
-
if (action.type === "undo") chat.history.slice(0, -2);
|
|
216
|
+
if (action.type === "undo") chat.history.slice(0, -2); // edit only
|
|
211
217
|
if (action.type === "rollback") chat.history.rollbackTo(action.targetMessageId);
|
|
218
|
+
if (action.type === "regenerate") {
|
|
219
|
+
chat.history.slice(0, -1);
|
|
220
|
+
return chat.turn(); // answer the edited history
|
|
221
|
+
}
|
|
212
222
|
},
|
|
213
223
|
run: async ({ messages, signal, streamText }) =>
|
|
214
224
|
streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }),
|
|
215
225
|
});
|
|
216
226
|
```
|
|
217
227
|
|
|
218
|
-
Send from the browser
|
|
228
|
+
Send from the browser through `useChat`, so the answer a turn produces renders like any turn:
|
|
229
|
+
`sendMessage(undefined, { body: { action: { type: "regenerate" } } })`, `regenerate({ body: { action } })`,
|
|
230
|
+
or `useChatActions({ sendMessage })` from `@trigger.dev/sdk/chat/react`. For regeneration, use
|
|
231
|
+
`regenerate()` from `useChat` (Vercel AI SDK) which removes the last assistant message before
|
|
232
|
+
streaming the new one; calling `sendMessage` with a regenerate action appends without removal,
|
|
233
|
+
leaving both answers visible. `transport.sendAction(chatId, action)` returns a raw stream the
|
|
234
|
+
caller must read and apply itself. Server-side, use
|
|
219
235
|
`agentChat.sendAction({ type: "rollback", targetMessageId: "msg-3" })`.
|
|
220
236
|
|
|
221
237
|
### 6. Fast starts: Head Start
|