@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.
Files changed (40) hide show
  1. package/dist/commonjs/v3/ai.d.ts +36 -0
  2. package/dist/commonjs/v3/ai.js +260 -55
  3. package/dist/commonjs/v3/ai.js.map +1 -1
  4. package/dist/commonjs/v3/auth.d.ts +10 -4
  5. package/dist/commonjs/v3/auth.js.map +1 -1
  6. package/dist/commonjs/v3/chatSnapshotIo.js +6 -7
  7. package/dist/commonjs/v3/chatSnapshotIo.js.map +1 -1
  8. package/dist/commonjs/v3/retry.d.ts +4 -0
  9. package/dist/commonjs/v3/retry.js +22 -13
  10. package/dist/commonjs/v3/retry.js.map +1 -1
  11. package/dist/commonjs/v3/test/transcript-storage-tests.js.map +1 -1
  12. package/dist/commonjs/v3/transcriptStorage.d.ts +43 -6
  13. package/dist/commonjs/v3/transcriptStorage.js +87 -8
  14. package/dist/commonjs/v3/transcriptStorage.js.map +1 -1
  15. package/dist/commonjs/version.js +1 -1
  16. package/dist/esm/v3/ai.d.ts +36 -0
  17. package/dist/esm/v3/ai.js +260 -55
  18. package/dist/esm/v3/ai.js.map +1 -1
  19. package/dist/esm/v3/auth.d.ts +10 -4
  20. package/dist/esm/v3/auth.js.map +1 -1
  21. package/dist/esm/v3/chatSnapshotIo.js +7 -8
  22. package/dist/esm/v3/chatSnapshotIo.js.map +1 -1
  23. package/dist/esm/v3/retry.d.ts +4 -0
  24. package/dist/esm/v3/retry.js +14 -8
  25. package/dist/esm/v3/retry.js.map +1 -1
  26. package/dist/esm/v3/test/transcript-storage-tests.js.map +1 -1
  27. package/dist/esm/v3/transcriptStorage.d.ts +43 -6
  28. package/dist/esm/v3/transcriptStorage.js +85 -8
  29. package/dist/esm/v3/transcriptStorage.js.map +1 -1
  30. package/dist/esm/version.js +1 -1
  31. package/docs/ai-chat/background-injection.mdx +54 -1
  32. package/docs/ai-chat/how-it-works.mdx +1 -1
  33. package/docs/ai-chat/migrating-from-hydrate-messages.mdx +299 -0
  34. package/docs/ai-chat/patterns/database-persistence.mdx +18 -7
  35. package/docs/ai-chat/reference.mdx +2 -1
  36. package/docs/ai-chat/side-channels.mdx +1 -1
  37. package/docs/ai-chat/transcript-storage.mdx +21 -7
  38. package/docs/self-hosting/security.mdx +12 -0
  39. package/package.json +2 -2
  40. package/skills/trigger-chat-agent-advanced/SKILL.md +31 -15
@@ -185,37 +185,53 @@ compaction: {
185
185
  },
186
186
  ```
187
187
 
188
- ### 5. Actions: mutate state without a turn
189
-
190
- `actionSchema` validates; `onAction` mutates via `chat.history` (`slice`, `replace`, `rollbackTo`,
191
- `remove`, `getPendingToolCalls`, `extractNewToolResults`). Actions fire `hydrateMessages` and
192
- `onAction` only, never `run()` or the turn hooks. Return a `StreamTextResult`, string, or `UIMessage`
193
- to also emit a model response, built with the `streamText` from `onAction`'s own argument so it
194
- carries the agent's prompt and tools like any other turn.
195
-
196
- Persistence goes through the agent's transcript storage (`storage` on `chat.agent`; the platform
197
- snapshot by default). After an action that changed the conversation the runtime hands the storage a
198
- changeset: an undo is one `truncateAfter`, a regenerate is a `truncateAfter` plus the new answer's
199
- `put`. With the deprecated `hydrateMessages` your store is the source of truth and the runtime does
200
- not write, so mirror every mutation yourself: a regenerate is a delete and an insert.
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 with `transport.sendAction(chatId, { type: "undo" })`, or server-side with
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