@trigger.dev/sdk 4.5.16 → 4.6.1
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/imports/ai-runtime-cjs.cjs.map +1 -1
- package/dist/commonjs/imports/ai-runtime.js +2 -0
- package/dist/commonjs/v3/ai-shared.d.ts +15 -0
- package/dist/commonjs/v3/ai-shared.js +35 -1
- package/dist/commonjs/v3/ai-shared.js.map +1 -1
- package/dist/commonjs/v3/ai.d.ts +311 -25
- package/dist/commonjs/v3/ai.js +1633 -380
- 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/chat-client.d.ts +11 -2
- package/dist/commonjs/v3/chat-client.js +227 -111
- package/dist/commonjs/v3/chat-client.js.map +1 -1
- package/dist/commonjs/v3/chat-react.d.ts +88 -0
- package/dist/commonjs/v3/chat-react.js +130 -1
- package/dist/commonjs/v3/chat-react.js.map +1 -1
- package/dist/commonjs/v3/chat-server.d.ts +42 -6
- package/dist/commonjs/v3/chat-server.js +52 -7
- package/dist/commonjs/v3/chat-server.js.map +1 -1
- package/dist/commonjs/v3/chat.d.ts +92 -10
- package/dist/commonjs/v3/chat.js +328 -73
- package/dist/commonjs/v3/chat.js.map +1 -1
- package/dist/commonjs/v3/chatSnapshotIo.d.ts +2 -0
- package/dist/commonjs/v3/chatSnapshotIo.js +173 -0
- package/dist/commonjs/v3/chatSnapshotIo.js.map +1 -0
- package/dist/commonjs/v3/chatVersionSkew.d.ts +12 -0
- package/dist/commonjs/v3/chatVersionSkew.js +30 -0
- package/dist/commonjs/v3/chatVersionSkew.js.map +1 -0
- package/dist/commonjs/v3/externalDeploymentId.d.ts +23 -0
- package/dist/commonjs/v3/externalDeploymentId.js +43 -0
- package/dist/commonjs/v3/externalDeploymentId.js.map +1 -0
- 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/sessions.d.ts +15 -2
- package/dist/commonjs/v3/sessions.js +12 -1
- package/dist/commonjs/v3/sessions.js.map +1 -1
- package/dist/commonjs/v3/shared.js +30 -36
- package/dist/commonjs/v3/shared.js.map +1 -1
- package/dist/commonjs/v3/test/index.d.ts +1 -0
- package/dist/commonjs/v3/test/index.js +3 -1
- package/dist/commonjs/v3/test/index.js.map +1 -1
- package/dist/commonjs/v3/test/mock-chat-agent.d.ts +47 -4
- package/dist/commonjs/v3/test/mock-chat-agent.js +116 -10
- package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -1
- package/dist/commonjs/v3/test/test-session-handle.js +6 -0
- package/dist/commonjs/v3/test/test-session-handle.js.map +1 -1
- package/dist/commonjs/v3/test/transcript-storage-tests.d.ts +40 -0
- package/dist/commonjs/v3/test/transcript-storage-tests.js +258 -0
- package/dist/commonjs/v3/test/transcript-storage-tests.js.map +1 -0
- package/dist/commonjs/v3/transcriptStorage.d.ts +261 -0
- package/dist/commonjs/v3/transcriptStorage.js +374 -0
- package/dist/commonjs/v3/transcriptStorage.js.map +1 -0
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/imports/ai-runtime.d.ts +2 -2
- package/dist/esm/imports/ai-runtime.js +2 -2
- package/dist/esm/imports/ai-runtime.js.map +1 -1
- package/dist/esm/v3/ai-shared.d.ts +15 -0
- package/dist/esm/v3/ai-shared.js +33 -0
- package/dist/esm/v3/ai-shared.js.map +1 -1
- package/dist/esm/v3/ai.d.ts +311 -25
- package/dist/esm/v3/ai.js +1625 -377
- 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/chat-client.d.ts +11 -2
- package/dist/esm/v3/chat-client.js +228 -112
- package/dist/esm/v3/chat-client.js.map +1 -1
- package/dist/esm/v3/chat-react.d.ts +88 -0
- package/dist/esm/v3/chat-react.js +127 -1
- package/dist/esm/v3/chat-react.js.map +1 -1
- package/dist/esm/v3/chat-server.d.ts +42 -6
- package/dist/esm/v3/chat-server.js +53 -8
- package/dist/esm/v3/chat-server.js.map +1 -1
- package/dist/esm/v3/chat.d.ts +92 -10
- package/dist/esm/v3/chat.js +329 -74
- package/dist/esm/v3/chat.js.map +1 -1
- package/dist/esm/v3/chatSnapshotIo.d.ts +2 -0
- package/dist/esm/v3/chatSnapshotIo.js +165 -0
- package/dist/esm/v3/chatSnapshotIo.js.map +1 -0
- package/dist/esm/v3/chatVersionSkew.d.ts +12 -0
- package/dist/esm/v3/chatVersionSkew.js +27 -0
- package/dist/esm/v3/chatVersionSkew.js.map +1 -0
- package/dist/esm/v3/externalDeploymentId.d.ts +23 -0
- package/dist/esm/v3/externalDeploymentId.js +38 -0
- package/dist/esm/v3/externalDeploymentId.js.map +1 -0
- 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/sessions.d.ts +15 -2
- package/dist/esm/v3/sessions.js +11 -1
- package/dist/esm/v3/sessions.js.map +1 -1
- package/dist/esm/v3/shared.js +17 -23
- package/dist/esm/v3/shared.js.map +1 -1
- package/dist/esm/v3/test/index.d.ts +1 -0
- package/dist/esm/v3/test/index.js +1 -0
- package/dist/esm/v3/test/index.js.map +1 -1
- package/dist/esm/v3/test/mock-chat-agent.d.ts +47 -4
- package/dist/esm/v3/test/mock-chat-agent.js +118 -12
- package/dist/esm/v3/test/mock-chat-agent.js.map +1 -1
- package/dist/esm/v3/test/test-session-handle.js +6 -0
- package/dist/esm/v3/test/test-session-handle.js.map +1 -1
- package/dist/esm/v3/test/transcript-storage-tests.d.ts +40 -0
- package/dist/esm/v3/test/transcript-storage-tests.js +255 -0
- package/dist/esm/v3/test/transcript-storage-tests.js.map +1 -0
- package/dist/esm/v3/transcriptStorage.d.ts +261 -0
- package/dist/esm/v3/transcriptStorage.js +360 -0
- package/dist/esm/v3/transcriptStorage.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/docs/ai-chat/actions.mdx +55 -23
- package/docs/ai-chat/anatomy.mdx +47 -27
- package/docs/ai-chat/backend.mdx +125 -48
- package/docs/ai-chat/background-injection.mdx +122 -19
- package/docs/ai-chat/client-protocol.mdx +5 -4
- package/docs/ai-chat/compaction.mdx +13 -7
- package/docs/ai-chat/custom-agents.mdx +23 -0
- package/docs/ai-chat/fast-starts.mdx +27 -20
- package/docs/ai-chat/frontend.mdx +19 -14
- package/docs/ai-chat/how-it-works.mdx +1 -1
- package/docs/ai-chat/lifecycle-hooks.mdx +6 -2
- package/docs/ai-chat/migrating-from-a-route-handler.mdx +16 -14
- package/docs/ai-chat/migrating-from-hydrate-messages.mdx +299 -0
- package/docs/ai-chat/patterns/database-persistence.mdx +24 -9
- package/docs/ai-chat/patterns/native-compaction.mdx +310 -0
- package/docs/ai-chat/patterns/persistence-and-replay.mdx +34 -23
- package/docs/ai-chat/patterns/skills.mdx +7 -10
- package/docs/ai-chat/patterns/version-upgrades.mdx +79 -6
- package/docs/ai-chat/pending-messages.mdx +3 -3
- package/docs/ai-chat/prompt-caching.mdx +23 -25
- package/docs/ai-chat/quick-start.mdx +11 -11
- package/docs/ai-chat/reference.mdx +69 -10
- package/docs/ai-chat/sessions.mdx +6 -1
- package/docs/ai-chat/side-channels.mdx +1 -1
- package/docs/ai-chat/testing.mdx +2 -1
- package/docs/ai-chat/tools.mdx +18 -13
- package/docs/ai-chat/transcript-storage.mdx +247 -0
- package/docs/ai-chat/upgrade-guide.mdx +2 -2
- package/docs/apikeys.mdx +27 -45
- package/docs/cli-env-commands.mdx +114 -0
- package/docs/cli-projects-commands.mdx +62 -0
- package/docs/cli-runs-commands.mdx +94 -0
- package/docs/config/extensions/syncEnvVars.mdx +6 -0
- package/docs/deploy-environment-variables.mdx +23 -2
- package/docs/deployment/overview.mdx +4 -8
- package/docs/deployment/preview-branches.mdx +4 -4
- package/docs/deployment/version-skew-protection.mdx +62 -0
- package/docs/introduction.mdx +58 -152
- package/docs/manual-setup.mdx +7 -7
- package/docs/mcp-tools.mdx +9 -0
- package/docs/quick-start.mdx +3 -3
- package/docs/realtime/auth.mdx +1 -1
- package/docs/reports.mdx +157 -0
- package/docs/self-hosting/security.mdx +17 -0
- package/docs/tasks/scheduled.mdx +24 -0
- package/docs/triggering.mdx +1 -1
- package/docs/troubleshooting-zod.mdx +158 -0
- package/package.json +4 -4
- package/skills/trigger-authoring-chat-agent/SKILL.md +41 -29
- package/skills/trigger-chat-agent-advanced/SKILL.md +54 -19
|
@@ -143,6 +143,12 @@ await waitUntilComplete();
|
|
|
143
143
|
5s timeout, before `onTurnComplete`). `chat.inject(messages)` queues `ModelMessage[]` that drain at
|
|
144
144
|
the next turn start or `prepareStep` boundary.
|
|
145
145
|
|
|
146
|
+
Two lanes, decided by role. A `role: "system"` message goes to the model's instructions, where it is
|
|
147
|
+
trusted like the system prompt, and applies to the next turn only. Any other role joins the
|
|
148
|
+
conversation and is untrusted by construction, so put checkable facts there and directives in the
|
|
149
|
+
system lane. The instructions lane reaches the model only through the managed `streamText` (or a
|
|
150
|
+
`chat.toStreamTextOptions()` spread), since that is where the SDK can set instructions.
|
|
151
|
+
|
|
146
152
|
```ts
|
|
147
153
|
export const myChat = chat.agent({
|
|
148
154
|
id: "my-chat",
|
|
@@ -154,8 +160,9 @@ export const myChat = chat.agent({
|
|
|
154
160
|
})()
|
|
155
161
|
);
|
|
156
162
|
},
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
registry,
|
|
164
|
+
run: async ({ messages, signal, streamText }) =>
|
|
165
|
+
streamText({ messages, abortSignal: signal, stopWhen: stepCountIs(15) }),
|
|
159
166
|
});
|
|
160
167
|
```
|
|
161
168
|
|
|
@@ -163,8 +170,9 @@ export const myChat = chat.agent({
|
|
|
163
170
|
|
|
164
171
|
`compaction.shouldCompact` decides when, `summarize` produces the summary that replaces the model
|
|
165
172
|
messages. UI messages are preserved by default (customize via `compactUIMessages`). The `prepareStep`
|
|
166
|
-
that performs inner-loop compaction
|
|
167
|
-
you pass after
|
|
173
|
+
that performs inner-loop compaction rides the managed `streamText`, which composes a `prepareStep`
|
|
174
|
+
you pass after it. Spreading `chat.toStreamTextOptions()` and then passing your own replaces it,
|
|
175
|
+
switching compaction off.
|
|
168
176
|
|
|
169
177
|
```ts
|
|
170
178
|
compaction: {
|
|
@@ -177,29 +185,53 @@ compaction: {
|
|
|
177
185
|
},
|
|
178
186
|
```
|
|
179
187
|
|
|
180
|
-
### 5. Actions:
|
|
181
|
-
|
|
182
|
-
`actionSchema` validates; `onAction`
|
|
183
|
-
`remove`, `getPendingToolCalls`, `extractNewToolResults`).
|
|
184
|
-
`onAction` only
|
|
185
|
-
to
|
|
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.
|
|
186
206
|
|
|
187
207
|
```ts
|
|
188
208
|
export const myChat = chat.agent({
|
|
189
209
|
id: "my-chat",
|
|
190
210
|
actionSchema: z.discriminatedUnion("type", [
|
|
191
211
|
z.object({ type: z.literal("undo") }),
|
|
212
|
+
z.object({ type: z.literal("regenerate") }),
|
|
192
213
|
z.object({ type: z.literal("rollback"), targetMessageId: z.string() }),
|
|
193
214
|
]),
|
|
194
215
|
onAction: async ({ action }) => {
|
|
195
|
-
if (action.type === "undo") chat.history.slice(0, -2);
|
|
216
|
+
if (action.type === "undo") chat.history.slice(0, -2); // edit only
|
|
196
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
|
+
}
|
|
197
222
|
},
|
|
198
|
-
run: async ({ messages, signal }) =>
|
|
223
|
+
run: async ({ messages, signal, streamText }) =>
|
|
224
|
+
streamText({ model: anthropic("claude-sonnet-4-5"), messages, abortSignal: signal }),
|
|
199
225
|
});
|
|
200
226
|
```
|
|
201
227
|
|
|
202
|
-
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
|
|
203
235
|
`agentChat.sendAction({ type: "rollback", targetMessageId: "msg-3" })`.
|
|
204
236
|
|
|
205
237
|
### 6. Fast starts: Head Start
|
|
@@ -210,18 +242,19 @@ must be **schema-only** (a module importing `ai` + `zod` only); heavy executes s
|
|
|
210
242
|
|
|
211
243
|
```ts
|
|
212
244
|
import { chat } from "@trigger.dev/sdk/chat-server";
|
|
213
|
-
import { streamText, stepCountIs } from "ai";
|
|
214
245
|
import { anthropic } from "@ai-sdk/anthropic";
|
|
215
246
|
import { headStartTools } from "@/lib/chat-tools/schemas";
|
|
216
247
|
|
|
217
248
|
export const chatHandler = chat.headStart({
|
|
218
249
|
agentId: "my-chat",
|
|
219
|
-
run
|
|
250
|
+
// `streamText` from the run argument owns `messages`, `prompt`, `stopWhen`
|
|
251
|
+
// and `abortSignal`: the handover needs `stopWhen: stepCountIs(1)` so the agent,
|
|
252
|
+
// not this handler, runs step 2 onward. Passing any of them is a type error.
|
|
253
|
+
run: async ({ streamText }) =>
|
|
220
254
|
streamText({
|
|
221
|
-
...helper.toStreamTextOptions({ tools: headStartTools }),
|
|
222
255
|
model: anthropic("claude-sonnet-4-6"),
|
|
223
256
|
system: "You are helpful.",
|
|
224
|
-
|
|
257
|
+
tools: headStartTools,
|
|
225
258
|
}),
|
|
226
259
|
});
|
|
227
260
|
// Next.js: export const POST = chatHandler; Transport: headStart: "/api/chat"
|
|
@@ -248,8 +281,10 @@ export const myChat = chat.agent({
|
|
|
248
281
|
### 8. Pending messages (mid-stream user input)
|
|
249
282
|
|
|
250
283
|
A message sent while a turn is streaming should NOT cancel the stream. Configure
|
|
251
|
-
`pendingMessages` (`shouldInject`, `prepare`, `onReceived`, `onInjected`) on the agent so the
|
|
252
|
-
|
|
284
|
+
`pendingMessages` (`shouldInject`, `prepare`, `onReceived`, `onInjected`) on the agent so the managed
|
|
285
|
+
`streamText`'s `prepareStep` folds them in at the next boundary. An injected steering message is part
|
|
286
|
+
of the conversation your hooks see, so it arrives in `uiMessages` and `newUIMessages` at
|
|
287
|
+
`onTurnComplete` and an app persisting from there stores it without extra work. On the frontend, `usePendingMessages`
|
|
253
288
|
returns `pending`, `steer(text)`, `queue(text)`, and `promoteToSteering(id)`; send via
|
|
254
289
|
`transport.sendPendingMessage(chatId, uiMessage, metadata?)`.
|
|
255
290
|
|