@trigger.dev/sdk 4.8.5 → 4.8.7
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 +34 -8
- package/dist/commonjs/v3/ai.js +304 -168
- package/dist/commonjs/v3/ai.js.map +1 -1
- package/dist/commonjs/v3/auth.d.ts +4 -4
- package/dist/commonjs/v3/auth.js +21 -75
- package/dist/commonjs/v3/auth.js.map +1 -1
- package/dist/commonjs/v3/chat-client.d.ts +1 -1
- package/dist/commonjs/v3/chat.d.ts +1 -1
- package/dist/commonjs/v3/prompt.js +6 -8
- package/dist/commonjs/v3/prompt.js.map +1 -1
- package/dist/commonjs/v3/runs.d.ts +5 -1
- package/dist/commonjs/v3/runs.js.map +1 -1
- package/dist/commonjs/v3/sessions.js +10 -7
- package/dist/commonjs/v3/sessions.js.map +1 -1
- package/dist/commonjs/v3/shared.d.ts +2 -2
- package/dist/commonjs/v3/shared.js +16 -15
- package/dist/commonjs/v3/shared.js.map +1 -1
- package/dist/commonjs/v3/steeringContext.d.ts +35 -10
- package/dist/commonjs/v3/steeringContext.js +86 -14
- package/dist/commonjs/v3/steeringContext.js.map +1 -1
- package/dist/commonjs/v3/streams.js +10 -8
- package/dist/commonjs/v3/streams.js.map +1 -1
- package/dist/commonjs/v3/tasks.d.ts +2 -2
- package/dist/commonjs/v3/tasks.js.map +1 -1
- package/dist/commonjs/v3/test/mock-chat-agent.js +24 -13
- package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -1
- package/dist/commonjs/v3/toolOutputJson.d.ts +17 -0
- package/dist/commonjs/v3/toolOutputJson.js +241 -0
- package/dist/commonjs/v3/toolOutputJson.js.map +1 -0
- package/dist/commonjs/v3/webhooks.d.ts +8 -2
- package/dist/commonjs/v3/webhooks.js +20 -11
- package/dist/commonjs/v3/webhooks.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/ai.d.ts +34 -8
- package/dist/esm/v3/ai.js +306 -171
- package/dist/esm/v3/ai.js.map +1 -1
- package/dist/esm/v3/auth.d.ts +4 -4
- package/dist/esm/v3/auth.js +22 -76
- package/dist/esm/v3/auth.js.map +1 -1
- package/dist/esm/v3/chat-client.d.ts +1 -1
- package/dist/esm/v3/chat.d.ts +1 -1
- package/dist/esm/v3/prompt.js +6 -8
- package/dist/esm/v3/prompt.js.map +1 -1
- package/dist/esm/v3/runs.d.ts +5 -1
- package/dist/esm/v3/runs.js.map +1 -1
- package/dist/esm/v3/sessions.js +10 -7
- package/dist/esm/v3/sessions.js.map +1 -1
- package/dist/esm/v3/shared.d.ts +2 -2
- package/dist/esm/v3/shared.js +16 -15
- package/dist/esm/v3/shared.js.map +1 -1
- package/dist/esm/v3/steeringContext.d.ts +35 -10
- package/dist/esm/v3/steeringContext.js +85 -14
- package/dist/esm/v3/steeringContext.js.map +1 -1
- package/dist/esm/v3/streams.js +10 -8
- package/dist/esm/v3/streams.js.map +1 -1
- package/dist/esm/v3/tasks.d.ts +2 -2
- package/dist/esm/v3/tasks.js.map +1 -1
- package/dist/esm/v3/test/mock-chat-agent.js +25 -14
- package/dist/esm/v3/test/mock-chat-agent.js.map +1 -1
- package/dist/esm/v3/toolOutputJson.d.ts +17 -0
- package/dist/esm/v3/toolOutputJson.js +238 -0
- package/dist/esm/v3/toolOutputJson.js.map +1 -0
- package/dist/esm/v3/webhooks.d.ts +8 -2
- package/dist/esm/v3/webhooks.js +20 -11
- package/dist/esm/v3/webhooks.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/docs/ai/observability.mdx +25 -19
- package/docs/ai/prompts.mdx +25 -19
- package/docs/ai-chat/actions.mdx +1 -1
- package/docs/ai-chat/anatomy.mdx +1 -1
- package/docs/ai-chat/backend.mdx +24 -24
- package/docs/ai-chat/background-injection.mdx +5 -5
- package/docs/ai-chat/chat-local.mdx +2 -2
- package/docs/ai-chat/compaction.mdx +47 -18
- package/docs/ai-chat/custom-agents.mdx +4 -4
- package/docs/ai-chat/error-handling.mdx +4 -4
- package/docs/ai-chat/fast-starts.mdx +8 -7
- package/docs/ai-chat/frontend.mdx +6 -2
- package/docs/ai-chat/lifecycle-hooks.mdx +11 -11
- package/docs/ai-chat/migrating-from-a-route-handler.mdx +4 -4
- package/docs/ai-chat/migrating-from-hydrate-messages.mdx +1 -1
- package/docs/ai-chat/overview.mdx +1 -1
- package/docs/ai-chat/patterns/branching-conversations.mdx +1 -1
- package/docs/ai-chat/patterns/database-persistence.mdx +2 -2
- package/docs/ai-chat/patterns/human-in-the-loop.mdx +1 -1
- package/docs/ai-chat/patterns/native-compaction.mdx +29 -9
- package/docs/ai-chat/patterns/persistence-and-replay.mdx +1 -1
- package/docs/ai-chat/patterns/redacting-telemetry.mdx +2 -2
- package/docs/ai-chat/patterns/skills.mdx +2 -2
- package/docs/ai-chat/patterns/sub-agents.mdx +1 -1
- package/docs/ai-chat/patterns/tool-result-auditing.mdx +1 -1
- package/docs/ai-chat/patterns/trusted-edge-signals.mdx +2 -2
- package/docs/ai-chat/patterns/version-upgrades.mdx +2 -2
- package/docs/ai-chat/pending-messages.mdx +5 -5
- package/docs/ai-chat/prompt-caching.mdx +7 -7
- package/docs/ai-chat/quick-start.mdx +2 -2
- package/docs/ai-chat/testing.mdx +9 -9
- package/docs/ai-chat/tools.mdx +9 -5
- package/docs/ai-chat/transcript-storage.mdx +2 -2
- package/docs/ai-chat/types.mdx +10 -3
- package/docs/apikeys.mdx +2 -1
- package/docs/cli-login-commands.mdx +12 -0
- package/docs/concurrency.mdx +40 -0
- package/docs/database-connections.mdx +1 -1
- package/docs/deploy-environment-variables.mdx +84 -2
- package/docs/deployment/trusted-publishing.mdx +4 -0
- package/docs/errors-retrying.mdx +25 -18
- package/docs/github-actions.mdx +1 -1
- package/docs/github-integration.mdx +32 -1
- package/docs/how-it-works.mdx +4 -2
- package/docs/introduction.mdx +1 -1
- package/docs/mcp-introduction.mdx +7 -1
- package/docs/mcp-remote.mdx +90 -0
- package/docs/oidc/azure.mdx +81 -0
- package/docs/oidc/databricks.mdx +99 -0
- package/docs/oidc/doppler.mdx +60 -0
- package/docs/oidc/gcp.mdx +109 -0
- package/docs/oidc/hugging-face.mdx +90 -0
- package/docs/oidc/openrouter.mdx +91 -0
- package/docs/oidc/snowflake.mdx +91 -0
- package/docs/oidc/vault.mdx +71 -0
- package/docs/oidc.mdx +2 -0
- package/docs/runs/metadata.mdx +1 -1
- package/docs/self-hosting/docker.mdx +2 -0
- package/docs/self-hosting/env/webapp.mdx +4 -1
- package/docs/self-hosting/kubernetes.mdx +2 -0
- package/docs/tasks/schemaTask.mdx +26 -13
- package/docs/tasks/streams.mdx +2 -2
- package/docs/troubleshooting.mdx +7 -0
- package/docs/webhooks/channels.mdx +6 -6
- package/docs/webhooks/connect.mdx +9 -75
- package/docs/webhooks/custom-providers.mdx +87 -0
- package/docs/webhooks/deliveries.mdx +7 -7
- package/docs/webhooks/filters.mdx +2 -2
- package/docs/webhooks/how-it-works.mdx +58 -0
- package/docs/webhooks/human-in-the-loop.mdx +3 -3
- package/docs/webhooks/linear.mdx +5 -3
- package/docs/webhooks/overview.mdx +20 -71
- package/docs/webhooks/own-handler.mdx +62 -0
- package/docs/webhooks/pricing-and-limits.mdx +13 -0
- package/docs/webhooks/providers/attio.mdx +38 -0
- package/docs/webhooks/providers/autumn.mdx +40 -0
- package/docs/webhooks/providers/cal-com.mdx +41 -0
- package/docs/webhooks/providers/calendly.mdx +41 -0
- package/docs/webhooks/providers/clerk.mdx +40 -0
- package/docs/webhooks/providers/discord.mdx +45 -0
- package/docs/webhooks/providers/docusign.mdx +41 -0
- package/docs/webhooks/providers/elevenlabs.mdx +41 -0
- package/docs/webhooks/providers/firecrawl.mdx +54 -0
- package/docs/webhooks/providers/github.mdx +46 -0
- package/docs/webhooks/providers/gitlab.mdx +41 -0
- package/docs/webhooks/providers/granola.mdx +44 -0
- package/docs/webhooks/providers/hookdeck.mdx +98 -0
- package/docs/webhooks/providers/infisical.mdx +41 -0
- package/docs/webhooks/providers/jira.mdx +41 -0
- package/docs/webhooks/providers/langfuse.mdx +40 -0
- package/docs/webhooks/providers/linear.mdx +45 -0
- package/docs/webhooks/providers/loops.mdx +40 -0
- package/docs/webhooks/providers/metronome.mdx +42 -0
- package/docs/webhooks/providers/mux.mdx +40 -0
- package/docs/webhooks/providers/openai.mdx +40 -0
- package/docs/webhooks/providers/pagerduty.mdx +40 -0
- package/docs/webhooks/providers/plain.mdx +41 -0
- package/docs/webhooks/providers/planetscale.mdx +40 -0
- package/docs/webhooks/providers/recall-ai.mdx +54 -0
- package/docs/webhooks/providers/replicate.mdx +41 -0
- package/docs/webhooks/providers/resend.mdx +44 -0
- package/docs/webhooks/providers/retell.mdx +41 -0
- package/docs/webhooks/providers/sentry.mdx +41 -0
- package/docs/webhooks/providers/shopify.mdx +49 -0
- package/docs/webhooks/providers/slack.mdx +48 -0
- package/docs/webhooks/providers/square.mdx +40 -0
- package/docs/webhooks/providers/stripe.mdx +86 -0
- package/docs/webhooks/providers/supabase.mdx +41 -0
- package/docs/webhooks/providers/tailscale.mdx +43 -0
- package/docs/webhooks/providers/typeform.mdx +42 -0
- package/docs/webhooks/providers/vapi.mdx +47 -0
- package/docs/webhooks/providers/vercel.mdx +40 -0
- package/docs/webhooks/providers/whatsapp.mdx +45 -0
- package/docs/webhooks/providers/workos.mdx +41 -0
- package/docs/webhooks/providers/zendesk.mdx +41 -0
- package/docs/webhooks/providers.mdx +53 -0
- package/docs/webhooks/quick-start.mdx +131 -0
- package/docs/webhooks/session-routing.mdx +6 -6
- package/docs/webhooks/signing-secrets.mdx +80 -0
- package/docs/webhooks/slack.mdx +11 -2
- package/docs/webhooks/verification.mdx +139 -0
- package/docs/webhooks/waiters.mdx +2 -2
- package/docs/webhooks/webhook-tasks.mdx +46 -0
- package/package.json +4 -5
- package/docs/migrating-from-v3.mdx +0 -332
- package/docs/webhooks/public-beta.mdx +0 -70
- package/docs/webhooks/sources.mdx +0 -252
|
@@ -87,7 +87,7 @@ const registry = createProviderRegistry({ anthropic });
|
|
|
87
87
|
|
|
88
88
|
const selfReviewPrompt = prompts.define({
|
|
89
89
|
id: "self-review",
|
|
90
|
-
model: "anthropic:claude-haiku-
|
|
90
|
+
model: "anthropic:claude-haiku-5-5",
|
|
91
91
|
content: `You are a conversation quality reviewer. Analyze the assistant's most recent response.
|
|
92
92
|
|
|
93
93
|
Focus on:
|
|
@@ -107,7 +107,7 @@ export const myChat = chat.agent({
|
|
|
107
107
|
const resolved = await selfReviewPrompt.resolve({});
|
|
108
108
|
|
|
109
109
|
const review = await generateObject({
|
|
110
|
-
model: registry.languageModel(resolved.model ?? "anthropic:claude-haiku-
|
|
110
|
+
model: registry.languageModel(resolved.model ?? "anthropic:claude-haiku-5-5"),
|
|
111
111
|
...resolved.toAISDKTelemetry(),
|
|
112
112
|
system: resolved.text,
|
|
113
113
|
prompt: messages
|
|
@@ -152,7 +152,7 @@ export const myChat = chat.agent({
|
|
|
152
152
|
});
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
-
The self-review runs on `claude-haiku-
|
|
155
|
+
The self-review runs on `claude-haiku-5-5` (fast, cheap) in the background. If the user sends another message before it completes, the coaching is still injected, because `chat.inject()` persists across the idle wait.
|
|
156
156
|
|
|
157
157
|
## Other use cases
|
|
158
158
|
|
|
@@ -173,7 +173,7 @@ export const myChat = chat.agent({
|
|
|
173
173
|
chat.defer(analytics.track("turn_started", { chatId, runId }));
|
|
174
174
|
},
|
|
175
175
|
run: async ({ messages, signal, streamText }) => {
|
|
176
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
176
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
177
177
|
},
|
|
178
178
|
});
|
|
179
179
|
```
|
|
@@ -200,7 +200,7 @@ export const myChat = chat.agent({
|
|
|
200
200
|
);
|
|
201
201
|
},
|
|
202
202
|
run: async ({ messages, signal, streamText }) => {
|
|
203
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
203
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
204
204
|
},
|
|
205
205
|
});
|
|
206
206
|
```
|
|
@@ -48,7 +48,7 @@ export const myChat = chat.agent({
|
|
|
48
48
|
userContext.messageCount++;
|
|
49
49
|
|
|
50
50
|
return streamText({
|
|
51
|
-
model: anthropic("claude-sonnet-
|
|
51
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
52
52
|
system: `Helping ${userContext.name} (${userContext.plan} plan).`,
|
|
53
53
|
messages,
|
|
54
54
|
abortSignal: signal,
|
|
@@ -117,7 +117,7 @@ export const myChat = chat.agent({
|
|
|
117
117
|
},
|
|
118
118
|
run: async ({ messages, signal, streamText }) => {
|
|
119
119
|
return streamText({
|
|
120
|
-
model: anthropic("claude-sonnet-
|
|
120
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
121
121
|
messages,
|
|
122
122
|
tools: { analyzeData },
|
|
123
123
|
abortSignal: signal,
|
|
@@ -29,7 +29,7 @@ export const myChat = chat.agent({
|
|
|
29
29
|
shouldCompact: ({ totalTokens }) => (totalTokens ?? 0) > 80_000,
|
|
30
30
|
summarize: async ({ messages }) => {
|
|
31
31
|
const result = await generateText({
|
|
32
|
-
model: anthropic("claude-haiku-
|
|
32
|
+
model: anthropic("claude-haiku-5-5"),
|
|
33
33
|
messages: [...messages, { role: "user", content: "Summarize this conversation concisely." }],
|
|
34
34
|
});
|
|
35
35
|
return result.text;
|
|
@@ -84,7 +84,7 @@ export const myChat = chat.agent({
|
|
|
84
84
|
shouldCompact: ({ totalTokens }) => (totalTokens ?? 0) > 80_000,
|
|
85
85
|
summarize: async ({ messages }) => {
|
|
86
86
|
return generateText({
|
|
87
|
-
model: anthropic("claude-haiku-
|
|
87
|
+
model: anthropic("claude-haiku-5-5"),
|
|
88
88
|
messages: [...messages, { role: "user", content: "Summarize." }],
|
|
89
89
|
}).then((r) => r.text);
|
|
90
90
|
},
|
|
@@ -98,7 +98,7 @@ export const myChat = chat.agent({
|
|
|
98
98
|
],
|
|
99
99
|
},
|
|
100
100
|
run: async ({ messages, signal, streamText }) => {
|
|
101
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
101
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
102
102
|
},
|
|
103
103
|
});
|
|
104
104
|
```
|
|
@@ -123,12 +123,20 @@ By default, model messages are replaced with a single summary message. Use `comp
|
|
|
123
123
|
|
|
124
124
|
### Summary + recent context
|
|
125
125
|
|
|
126
|
-
Keep the last few model messages so the LLM has recent detail alongside the summary:
|
|
126
|
+
Keep the last few model messages so the LLM has recent detail alongside the summary. The kept messages now follow a different history, so strip their reasoning: Claude 5.5 models reject thinking blocks whose earlier conversation changed with a 400 (`Invalid signature in thinking block`).
|
|
127
127
|
|
|
128
128
|
```ts
|
|
129
|
+
import type { ModelMessage } from "ai";
|
|
130
|
+
|
|
131
|
+
function stripReasoning(message: ModelMessage): ModelMessage {
|
|
132
|
+
if (message.role !== "assistant" || typeof message.content === "string") return message;
|
|
133
|
+
return { ...message, content: message.content.filter((part) => part.type !== "reasoning") };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ...
|
|
129
137
|
compactModelMessages: ({ modelMessages, summary }) => [
|
|
130
138
|
{ role: "user", content: summary },
|
|
131
|
-
...modelMessages.slice(-2), // Keep last exchange for detail
|
|
139
|
+
...modelMessages.slice(-2).map(stripReasoning), // Keep last exchange for detail
|
|
132
140
|
],
|
|
133
141
|
```
|
|
134
142
|
|
|
@@ -192,7 +200,7 @@ export const myChat = chat.agent({
|
|
|
192
200
|
});
|
|
193
201
|
},
|
|
194
202
|
run: async ({ messages, signal, streamText }) => {
|
|
195
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
203
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
196
204
|
},
|
|
197
205
|
});
|
|
198
206
|
```
|
|
@@ -214,7 +222,7 @@ import { z } from "zod";
|
|
|
214
222
|
// Reusable summarize fn — also used by the automatic compaction config.
|
|
215
223
|
async function summarize(messages: ModelMessage[]) {
|
|
216
224
|
const result = await generateText({
|
|
217
|
-
model: anthropic("claude-haiku-
|
|
225
|
+
model: anthropic("claude-haiku-5-5"),
|
|
218
226
|
messages: [...messages, { role: "user", content: "Summarize this conversation concisely." }],
|
|
219
227
|
});
|
|
220
228
|
return result.text;
|
|
@@ -250,7 +258,7 @@ export const myChat = chat.agent({
|
|
|
250
258
|
},
|
|
251
259
|
|
|
252
260
|
run: async ({ messages, signal, streamText }) => {
|
|
253
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
261
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
254
262
|
},
|
|
255
263
|
});
|
|
256
264
|
```
|
|
@@ -317,7 +325,10 @@ const session = chat.createSession(payload, {
|
|
|
317
325
|
compaction: {
|
|
318
326
|
shouldCompact: ({ totalTokens }) => (totalTokens ?? 0) > 80_000,
|
|
319
327
|
summarize: async ({ messages }) =>
|
|
320
|
-
generateText({
|
|
328
|
+
generateText({
|
|
329
|
+
model: anthropic("claude-haiku-5-5"),
|
|
330
|
+
messages: [...messages, { role: "user", content: "Summarize this conversation concisely." }],
|
|
331
|
+
}).then((r) => r.text),
|
|
321
332
|
compactUIMessages: ({ uiMessages, summary }) => [
|
|
322
333
|
{ id: generateId(), role: "assistant",
|
|
323
334
|
parts: [{ type: "text", text: `[Summary]\n\n${summary}` }] },
|
|
@@ -328,7 +339,7 @@ const session = chat.createSession(payload, {
|
|
|
328
339
|
|
|
329
340
|
for await (const turn of session) {
|
|
330
341
|
const result = streamText({
|
|
331
|
-
model: anthropic("claude-sonnet-
|
|
342
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
332
343
|
messages: turn.messages,
|
|
333
344
|
abortSignal: turn.signal,
|
|
334
345
|
stopWhen: stepCountIs(15),
|
|
@@ -353,7 +364,10 @@ const conversation = new chat.MessageAccumulator({
|
|
|
353
364
|
compaction: {
|
|
354
365
|
shouldCompact: ({ totalTokens }) => (totalTokens ?? 0) > 80_000,
|
|
355
366
|
summarize: async ({ messages }) =>
|
|
356
|
-
generateText({
|
|
367
|
+
generateText({
|
|
368
|
+
model: anthropic("claude-haiku-5-5"),
|
|
369
|
+
messages: [...messages, { role: "user", content: "Summarize this conversation concisely." }],
|
|
370
|
+
}).then((r) => r.text),
|
|
357
371
|
compactUIMessages: ({ summary }) => [
|
|
358
372
|
{ id: generateId(), role: "assistant",
|
|
359
373
|
parts: [{ type: "text", text: `[Summary]\n\n${summary}` }] },
|
|
@@ -365,7 +379,7 @@ for (let turn = 0; turn < 100; turn++) {
|
|
|
365
379
|
const messages = await conversation.addIncoming(payload.messages, payload.trigger, turn);
|
|
366
380
|
|
|
367
381
|
const result = streamText({
|
|
368
|
-
model: anthropic("claude-sonnet-
|
|
382
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
369
383
|
messages,
|
|
370
384
|
prepareStep: conversation.prepareStep(), // Inner-loop compaction
|
|
371
385
|
stopWhen: stepCountIs(15),
|
|
@@ -374,9 +388,15 @@ for (let turn = 0; turn < 100; turn++) {
|
|
|
374
388
|
const { message } = await chat.pipeAndCapture(result);
|
|
375
389
|
if (message) await conversation.addResponse(message);
|
|
376
390
|
|
|
377
|
-
// Outer-loop compaction
|
|
378
|
-
|
|
379
|
-
|
|
391
|
+
// Outer-loop compaction. Pass the last step's usage: it's what the model's
|
|
392
|
+
// context window held on its final call. `result.usage` is the turn's sum on
|
|
393
|
+
// AI SDK 7, so read it from `steps`, and pass the turn's sum separately.
|
|
394
|
+
const lastStepUsage = (await result.steps).at(-1)?.usage;
|
|
395
|
+
await conversation.compactIfNeeded(lastStepUsage, {
|
|
396
|
+
chatId: payload.chatId,
|
|
397
|
+
turn,
|
|
398
|
+
turnUsage: await result.totalUsage,
|
|
399
|
+
});
|
|
380
400
|
|
|
381
401
|
await db.chat.update({ data: { messages: conversation.uiMessages } });
|
|
382
402
|
await chat.writeTurnComplete();
|
|
@@ -388,11 +408,17 @@ for (let turn = 0; turn < 100; turn++) {
|
|
|
388
408
|
For maximum control, use `chat.compact()` directly inside a custom `prepareStep`:
|
|
389
409
|
|
|
390
410
|
```ts
|
|
391
|
-
prepareStep: async ({ messages: stepMessages, steps }) => {
|
|
411
|
+
prepareStep: async ({ messages: stepMessages, steps, responseMessages }) => {
|
|
392
412
|
const result = await chat.compact(stepMessages, steps, {
|
|
413
|
+
// On AI SDK 7, pass these so the steps after a compaction are rebuilt
|
|
414
|
+
// with every new tool result. Earlier AI SDK versions don't need them.
|
|
415
|
+
responseMessages,
|
|
393
416
|
threshold: 80_000,
|
|
394
417
|
summarize: async (msgs) =>
|
|
395
|
-
generateText({
|
|
418
|
+
generateText({
|
|
419
|
+
model: anthropic("claude-haiku-5-5"),
|
|
420
|
+
messages: [...msgs, { role: "user", content: "Summarize this conversation concisely." }],
|
|
421
|
+
}).then((r) => r.text),
|
|
396
422
|
});
|
|
397
423
|
return result.type === "skipped" ? undefined : result;
|
|
398
424
|
},
|
|
@@ -404,7 +430,10 @@ Or use the `chat.compactionStep()` factory:
|
|
|
404
430
|
prepareStep: chat.compactionStep({
|
|
405
431
|
threshold: 80_000,
|
|
406
432
|
summarize: async (msgs) =>
|
|
407
|
-
generateText({
|
|
433
|
+
generateText({
|
|
434
|
+
model: anthropic("claude-haiku-5-5"),
|
|
435
|
+
messages: [...msgs, { role: "user", content: "Summarize this conversation concisely." }],
|
|
436
|
+
}).then((r) => r.text),
|
|
408
437
|
}),
|
|
409
438
|
```
|
|
410
439
|
|
|
@@ -109,7 +109,7 @@ export const myChat = chat
|
|
|
109
109
|
});
|
|
110
110
|
|
|
111
111
|
const result = streamText({
|
|
112
|
-
model: anthropic("claude-sonnet-
|
|
112
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
113
113
|
messages: turn.messages,
|
|
114
114
|
abortSignal: turn.signal,
|
|
115
115
|
stopWhen: stepCountIs(15),
|
|
@@ -230,7 +230,7 @@ For more control, you can do each step manually:
|
|
|
230
230
|
```ts
|
|
231
231
|
for await (const turn of session) {
|
|
232
232
|
const result = streamText({
|
|
233
|
-
model: anthropic("claude-sonnet-
|
|
233
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
234
234
|
messages: turn.messages,
|
|
235
235
|
abortSignal: turn.signal,
|
|
236
236
|
stopWhen: stepCountIs(15),
|
|
@@ -267,7 +267,7 @@ and aborts that turn as normal.
|
|
|
267
267
|
```ts trigger/my-chat.ts
|
|
268
268
|
for await (const turn of session) {
|
|
269
269
|
const result = streamText({
|
|
270
|
-
model: anthropic("claude-sonnet-
|
|
270
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
271
271
|
messages: turn.messages,
|
|
272
272
|
abortSignal: turn.signal, // fires on a user stop OR a run cancel
|
|
273
273
|
stopWhen: stepCountIs(15),
|
|
@@ -442,7 +442,7 @@ export const myChat = chat.customAgent({
|
|
|
442
442
|
const combinedSignal = AbortSignal.any([runSignal, stop.signal]);
|
|
443
443
|
|
|
444
444
|
const result = streamText({
|
|
445
|
-
model: anthropic("claude-sonnet-
|
|
445
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
446
446
|
messages,
|
|
447
447
|
abortSignal: combinedSignal,
|
|
448
448
|
stopWhen: stepCountIs(15),
|
|
@@ -38,7 +38,7 @@ export const myChat = chat.agent({
|
|
|
38
38
|
},
|
|
39
39
|
},
|
|
40
40
|
run: async ({ messages, signal, streamText }) => {
|
|
41
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
41
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
42
42
|
},
|
|
43
43
|
});
|
|
44
44
|
```
|
|
@@ -74,7 +74,7 @@ export const myChat = chat.agent({
|
|
|
74
74
|
await db.chat.update({ where: { id: chatId }, data: { messages: uiMessages } });
|
|
75
75
|
},
|
|
76
76
|
run: async ({ messages, signal, streamText }) => {
|
|
77
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
77
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
78
78
|
},
|
|
79
79
|
});
|
|
80
80
|
```
|
|
@@ -142,7 +142,7 @@ chat.agent({
|
|
|
142
142
|
});
|
|
143
143
|
},
|
|
144
144
|
run: async ({ messages, signal, streamText }) => {
|
|
145
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
145
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
146
146
|
},
|
|
147
147
|
});
|
|
148
148
|
```
|
|
@@ -174,7 +174,7 @@ chat.agent({
|
|
|
174
174
|
}
|
|
175
175
|
},
|
|
176
176
|
run: async ({ messages, signal, streamText }) => {
|
|
177
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
177
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
178
178
|
},
|
|
179
179
|
});
|
|
180
180
|
```
|
|
@@ -81,7 +81,7 @@ export const myChat = chat.agent({
|
|
|
81
81
|
// ... fallback initialization for non-preloaded runs
|
|
82
82
|
},
|
|
83
83
|
run: async ({ messages, signal, streamText }) => {
|
|
84
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
84
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
85
85
|
},
|
|
86
86
|
});
|
|
87
87
|
```
|
|
@@ -241,7 +241,8 @@ This is an **import-chain** problem, not a runtime one. A "we'll strip the execu
|
|
|
241
241
|
id: "my-chat",
|
|
242
242
|
run: async ({ messages, signal, streamText }) =>
|
|
243
243
|
streamText({
|
|
244
|
-
model: anthropic("claude-sonnet-
|
|
244
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
245
|
+
system: "You are a helpful assistant.",
|
|
245
246
|
messages,
|
|
246
247
|
tools: chatTools,
|
|
247
248
|
stopWhen: stepCountIs(10),
|
|
@@ -263,7 +264,7 @@ This is an **import-chain** problem, not a runtime one. A "we'll strip the execu
|
|
|
263
264
|
agentId: "my-chat",
|
|
264
265
|
run: async ({ streamText }) =>
|
|
265
266
|
streamText({
|
|
266
|
-
model: anthropic("claude-sonnet-
|
|
267
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
267
268
|
system: "You are a helpful assistant.",
|
|
268
269
|
tools: headStartTools,
|
|
269
270
|
}),
|
|
@@ -280,7 +281,7 @@ This is an **import-chain** problem, not a runtime one. A "we'll strip the execu
|
|
|
280
281
|
</Note>
|
|
281
282
|
|
|
282
283
|
<Tip>
|
|
283
|
-
Use the **same model** on both sides (route handler and `chat.agent`)
|
|
284
|
+
Use the **same model and system prompt** on both sides (route handler and `chat.agent`), with the same tool names and schemas. On Claude 5.5 models, step 1's thinking is bound to that system prompt and tool set, so a mismatch makes step 2 fail with a 400. Your LLM provider keys stay server-side in your warm process — Trigger.dev never holds them in this design.
|
|
284
285
|
</Tip>
|
|
285
286
|
|
|
286
287
|
Mount the handler in whatever framework you use — see [Mounting in your framework](#mounting-in-your-framework) below.
|
|
@@ -569,7 +570,7 @@ for await (const turn of session) {
|
|
|
569
570
|
const result = turn.handover?.isFinal
|
|
570
571
|
? undefined
|
|
571
572
|
: streamText({
|
|
572
|
-
model: anthropic("claude-sonnet-
|
|
573
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
573
574
|
messages: turn.messages,
|
|
574
575
|
abortSignal: turn.signal,
|
|
575
576
|
stopWhen: stepCountIs(10),
|
|
@@ -593,7 +594,7 @@ if (turn === 0 && payload.trigger === "handover-prepare") {
|
|
|
593
594
|
// passing originalMessages so the tool output merges into the
|
|
594
595
|
// handed-over assistant instead of starting a new message.
|
|
595
596
|
const result = streamText({
|
|
596
|
-
model: anthropic("claude-sonnet-
|
|
597
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
597
598
|
messages: conversation.modelMessages,
|
|
598
599
|
stopWhen: stepCountIs(10),
|
|
599
600
|
});
|
|
@@ -691,7 +692,7 @@ export async function POST(req: Request) {
|
|
|
691
692
|
messages, // first-turn user history
|
|
692
693
|
run: async ({ streamText }) =>
|
|
693
694
|
streamText({
|
|
694
|
-
model: anthropic("claude-sonnet-
|
|
695
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
695
696
|
system: "You are a helpful assistant.",
|
|
696
697
|
tools: headStartTools,
|
|
697
698
|
}),
|
|
@@ -267,7 +267,7 @@ Browser-supplied `clientData` is input, including after schema validation. Use i
|
|
|
267
267
|
Pass metadata with individual messages via `sendMessage`. Per-message values are merged with transport-level client data (per-message wins on conflicts):
|
|
268
268
|
|
|
269
269
|
```ts
|
|
270
|
-
sendMessage({ text: "Hello" }, { metadata: { model: "gpt-
|
|
270
|
+
sendMessage({ text: "Hello" }, { metadata: { model: "gpt-6-luna", priority: "high" } });
|
|
271
271
|
```
|
|
272
272
|
|
|
273
273
|
### Typed client data with clientDataSchema
|
|
@@ -287,7 +287,7 @@ export const myChat = chat.agent({
|
|
|
287
287
|
}),
|
|
288
288
|
run: async ({ messages, clientData, signal, streamText }) => {
|
|
289
289
|
return streamText({
|
|
290
|
-
model: anthropic("claude-sonnet-
|
|
290
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
291
291
|
system: clientData?.locale === "fr" ? "Reply in French." : "Reply in English.",
|
|
292
292
|
messages,
|
|
293
293
|
abortSignal: signal,
|
|
@@ -297,6 +297,10 @@ export const myChat = chat.agent({
|
|
|
297
297
|
});
|
|
298
298
|
```
|
|
299
299
|
|
|
300
|
+
<Note>
|
|
301
|
+
On Claude 5.5 models, each thinking block is bound to the system prompt it was produced with, so changing `system` partway through a chat makes Anthropic reject the next request with a 400 (`Invalid signature in thinking block`). If users can switch language mid-chat, start a new chat when the locale changes.
|
|
302
|
+
</Note>
|
|
303
|
+
|
|
300
304
|
The schema also types the `clientData` option on the frontend transport:
|
|
301
305
|
|
|
302
306
|
```ts
|
|
@@ -62,7 +62,7 @@ export const myChat = chat.agent({
|
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
run: async ({ messages, signal }) => {
|
|
65
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
65
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
66
66
|
},
|
|
67
67
|
});
|
|
68
68
|
```
|
|
@@ -101,7 +101,7 @@ export const myChat = chat.agent({
|
|
|
101
101
|
// (splice partial + first user into chain, dispatch the rest).
|
|
102
102
|
},
|
|
103
103
|
run: async ({ messages, signal }) =>
|
|
104
|
-
streamText({ model: anthropic("claude-sonnet-
|
|
104
|
+
streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }),
|
|
105
105
|
});
|
|
106
106
|
```
|
|
107
107
|
|
|
@@ -157,7 +157,7 @@ export const myChat = chat.agent({
|
|
|
157
157
|
// ... non-preloaded chat-row initialization
|
|
158
158
|
},
|
|
159
159
|
run: async ({ messages, signal }) => {
|
|
160
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
160
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
161
161
|
},
|
|
162
162
|
});
|
|
163
163
|
```
|
|
@@ -206,7 +206,7 @@ export const myChat = chat.agent({
|
|
|
206
206
|
});
|
|
207
207
|
},
|
|
208
208
|
run: async ({ messages, signal }) => {
|
|
209
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
209
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
210
210
|
},
|
|
211
211
|
});
|
|
212
212
|
```
|
|
@@ -245,7 +245,7 @@ export const myChat = chat.agent({
|
|
|
245
245
|
return messages;
|
|
246
246
|
},
|
|
247
247
|
run: async ({ messages, signal }) => {
|
|
248
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
248
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, tools: chatTools, abortSignal: signal });
|
|
249
249
|
},
|
|
250
250
|
});
|
|
251
251
|
```
|
|
@@ -305,7 +305,7 @@ export const myChat = chat.agent({
|
|
|
305
305
|
return stored;
|
|
306
306
|
},
|
|
307
307
|
run: async ({ messages, signal }) => {
|
|
308
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
308
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
309
309
|
},
|
|
310
310
|
});
|
|
311
311
|
```
|
|
@@ -363,7 +363,7 @@ export const myChat = chat.agent({
|
|
|
363
363
|
});
|
|
364
364
|
},
|
|
365
365
|
run: async ({ messages, signal }) => {
|
|
366
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
366
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
367
367
|
},
|
|
368
368
|
});
|
|
369
369
|
```
|
|
@@ -398,7 +398,7 @@ export const myChat = chat.agent({
|
|
|
398
398
|
}
|
|
399
399
|
},
|
|
400
400
|
run: async ({ messages, signal }) => {
|
|
401
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
401
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
402
402
|
},
|
|
403
403
|
});
|
|
404
404
|
```
|
|
@@ -446,7 +446,7 @@ export const myChat = chat.agent({
|
|
|
446
446
|
]);
|
|
447
447
|
},
|
|
448
448
|
run: async ({ messages, signal }) => {
|
|
449
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
449
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
450
450
|
},
|
|
451
451
|
});
|
|
452
452
|
```
|
|
@@ -489,7 +489,7 @@ export const myChat = chat.agent({
|
|
|
489
489
|
logger.info("Resumed", { phase: event.phase });
|
|
490
490
|
},
|
|
491
491
|
run: async ({ messages, signal }) => {
|
|
492
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
492
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
493
493
|
},
|
|
494
494
|
});
|
|
495
495
|
```
|
|
@@ -523,7 +523,7 @@ export const myChat = chat.agent({
|
|
|
523
523
|
await initializeChat(chatId, clientData);
|
|
524
524
|
},
|
|
525
525
|
run: async ({ messages, signal }) => {
|
|
526
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
526
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
527
527
|
},
|
|
528
528
|
});
|
|
529
529
|
```
|
|
@@ -119,7 +119,7 @@ export async function POST(req: Request) {
|
|
|
119
119
|
if (!session) return new Response("Unauthorized", { status: 401 });
|
|
120
120
|
|
|
121
121
|
const result = streamText({
|
|
122
|
-
model: anthropic("claude-sonnet-
|
|
122
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
123
123
|
system: "You are a helpful assistant.",
|
|
124
124
|
messages: convertToModelMessages(messages),
|
|
125
125
|
tools,
|
|
@@ -148,7 +148,7 @@ export const myChat = chat.agent({
|
|
|
148
148
|
run: async ({ messages, tools, signal, streamText }) =>
|
|
149
149
|
streamText({
|
|
150
150
|
tools,
|
|
151
|
-
model: anthropic("claude-sonnet-
|
|
151
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
152
152
|
system: "You are a helpful assistant.",
|
|
153
153
|
messages,
|
|
154
154
|
abortSignal: signal,
|
|
@@ -359,7 +359,7 @@ export const myChat = chat.agent({
|
|
|
359
359
|
run: async ({ messages, tools, signal, streamText }) =>
|
|
360
360
|
streamText({
|
|
361
361
|
tools,
|
|
362
|
-
model: anthropic("claude-sonnet-
|
|
362
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
363
363
|
system: "You are a helpful assistant.",
|
|
364
364
|
messages,
|
|
365
365
|
abortSignal: signal,
|
|
@@ -469,7 +469,7 @@ Head Start brings the route handler back for exactly that first turn. It runs st
|
|
|
469
469
|
agentId: "my-chat",
|
|
470
470
|
run: async ({ streamText }) =>
|
|
471
471
|
streamText({
|
|
472
|
-
model: anthropic("claude-sonnet-
|
|
472
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
473
473
|
system: "You are a helpful assistant.",
|
|
474
474
|
tools: headStartTools,
|
|
475
475
|
}),
|
|
@@ -194,7 +194,7 @@ With `hydrateMessages`, your hook was the source of truth and the runtime wrote
|
|
|
194
194
|
storage: transcriptStorage,
|
|
195
195
|
clientDataSchema: z.object({ userId: z.string() }),
|
|
196
196
|
run: async ({ messages, signal, streamText }) =>
|
|
197
|
-
streamText({ model: anthropic("claude-sonnet-
|
|
197
|
+
streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }),
|
|
198
198
|
});
|
|
199
199
|
```
|
|
200
200
|
</Step>
|
|
@@ -19,7 +19,7 @@ export const myChat = chat.agent({
|
|
|
19
19
|
id: "my-chat",
|
|
20
20
|
run: async ({ messages, signal, streamText }) =>
|
|
21
21
|
streamText({
|
|
22
|
-
model: anthropic("claude-sonnet-
|
|
22
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
23
23
|
messages,
|
|
24
24
|
abortSignal: signal,
|
|
25
25
|
stopWhen: stepCountIs(15),
|
|
@@ -227,7 +227,7 @@ export const myChat = chat.agent({
|
|
|
227
227
|
]);
|
|
228
228
|
},
|
|
229
229
|
run: async ({ messages, signal, streamText }) => {
|
|
230
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
230
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
231
231
|
},
|
|
232
232
|
});
|
|
233
233
|
```
|
|
@@ -298,7 +298,7 @@ export const myChat = chat.agent({
|
|
|
298
298
|
},
|
|
299
299
|
run: async ({ messages, signal, streamText }) => {
|
|
300
300
|
return streamText({
|
|
301
|
-
model: anthropic("claude-sonnet-
|
|
301
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
302
302
|
messages,
|
|
303
303
|
abortSignal: signal,
|
|
304
304
|
stopWhen: stepCountIs(15),
|
|
@@ -76,7 +76,7 @@ export const myChat = chat.withUIMessage<ChatMessage>().agent({
|
|
|
76
76
|
tools,
|
|
77
77
|
run: async ({ messages, tools, signal, streamText }) => {
|
|
78
78
|
return streamText({
|
|
79
|
-
model: anthropic("claude-sonnet-
|
|
79
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
80
80
|
messages,
|
|
81
81
|
tools,
|
|
82
82
|
abortSignal: signal,
|