@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
|
@@ -50,23 +50,28 @@ const isToolPart = (p: { type?: string }) =>
|
|
|
50
50
|
typeof p?.type === "string" && (p.type.startsWith("tool-") || p.type === "dynamic-tool");
|
|
51
51
|
|
|
52
52
|
// Drop the oldest n tool parts, mirroring what the provider cleared. A tool call
|
|
53
|
-
// and its result live in one part, so pairing stays intact.
|
|
53
|
+
// and its result live in one part, so pairing stays intact. Once a message is
|
|
54
|
+
// edited, its thinking and every later message's thinking no longer verify on
|
|
55
|
+
// Claude 5.5 models, so those reasoning parts are dropped too.
|
|
54
56
|
function pruneOldestToolParts(messages: UIMessage[], n: number): UIMessage[] {
|
|
55
57
|
let toRemove = n;
|
|
58
|
+
let edited = false;
|
|
56
59
|
const out: UIMessage[] = [];
|
|
57
60
|
for (const m of messages) {
|
|
58
|
-
if (
|
|
61
|
+
if (m.role !== "assistant" || !m.parts) {
|
|
59
62
|
out.push(m);
|
|
60
63
|
continue;
|
|
61
64
|
}
|
|
62
65
|
const kept = m.parts.filter((p) => {
|
|
63
66
|
if (toRemove > 0 && isToolPart(p)) {
|
|
64
67
|
toRemove--;
|
|
68
|
+
edited = true;
|
|
65
69
|
return false;
|
|
66
70
|
}
|
|
67
71
|
return true;
|
|
68
72
|
});
|
|
69
|
-
|
|
73
|
+
const parts = edited ? kept.filter((p) => p.type !== "reasoning") : kept;
|
|
74
|
+
if (parts.length > 0) out.push({ ...m, parts });
|
|
70
75
|
}
|
|
71
76
|
return out;
|
|
72
77
|
}
|
|
@@ -77,7 +82,7 @@ export const nativePersist = chat.agent({
|
|
|
77
82
|
tools: { fetchRecord },
|
|
78
83
|
run: async ({ messages, chatId, tools, signal, streamText }) => {
|
|
79
84
|
return streamText({
|
|
80
|
-
model: anthropic("claude-sonnet-
|
|
85
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
81
86
|
messages,
|
|
82
87
|
tools,
|
|
83
88
|
abortSignal: signal,
|
|
@@ -126,6 +131,10 @@ Turn 1 sends the user message and accumulates six tool results. Anthropic clears
|
|
|
126
131
|
`onTurnComplete` is where persistence happens. Action turns fire `onAction` only, and a `chat.history.set()` inside `run()` is overwritten by the accumulator at turn end. See [Persistence and replay](/ai-chat/patterns/persistence-and-replay#action-turns-no-snapshot-write).
|
|
127
132
|
</Note>
|
|
128
133
|
|
|
134
|
+
<Warning>
|
|
135
|
+
Thinking is on by default on Claude 5.5 models, and each thinking block is bound to the conversation that came before it. Removing tool parts from earlier turns in your own code changes that history, so Anthropic can reject the next request with a 400 (`Invalid signature in thinking block`). Server-side context editing, as configured above, doesn't count as an edit. That's why `pruneOldestToolParts` also removes the reasoning parts from the turns it changes and every turn after them.
|
|
136
|
+
</Warning>
|
|
137
|
+
|
|
129
138
|
## Persist OpenAI stored responses
|
|
130
139
|
|
|
131
140
|
OpenAI's `store: true` keeps the thread server-side and returns a `responseId`. Pass that back as `previousResponseId` on the next turn and send only the messages since the last assistant reply; everything before it lives on OpenAI's side.
|
|
@@ -156,7 +165,7 @@ export const openaiStore = chat.agent({
|
|
|
156
165
|
const outbound = native ? messagesSinceLastAssistant(messages) : messages;
|
|
157
166
|
|
|
158
167
|
const result = streamText({
|
|
159
|
-
model: openai("gpt-
|
|
168
|
+
model: openai("gpt-6-luna"),
|
|
160
169
|
messages: outbound,
|
|
161
170
|
abortSignal: signal,
|
|
162
171
|
stopWhen: stepCountIs(5),
|
|
@@ -197,10 +206,17 @@ const FALLBACK_ORDER: Provider[] = ["anthropic", "openai"];
|
|
|
197
206
|
type NativeState = { provider: "openai"; previousResponseId: string };
|
|
198
207
|
const nativeStore = new Map<string, NativeState>();
|
|
199
208
|
|
|
209
|
+
// Retained messages follow a different history after compaction, so their thinking
|
|
210
|
+
// blocks no longer verify on Claude 5.5 models. Drop reasoning parts before replaying them.
|
|
211
|
+
function stripReasoning(message: ModelMessage): ModelMessage {
|
|
212
|
+
if (message.role !== "assistant" || typeof message.content === "string") return message;
|
|
213
|
+
return { ...message, content: message.content.filter((part) => part.type !== "reasoning") };
|
|
214
|
+
}
|
|
215
|
+
|
|
200
216
|
// Provider-agnostic summary: a plain string, portable across any provider.
|
|
201
217
|
async function summarizeConversation(messages: ModelMessage[]): Promise<string> {
|
|
202
218
|
const { text } = await generateText({
|
|
203
|
-
model: openai("gpt-
|
|
219
|
+
model: openai("gpt-6-luna"),
|
|
204
220
|
messages: [
|
|
205
221
|
...messages,
|
|
206
222
|
{
|
|
@@ -223,7 +239,7 @@ export const resilientChat = chat.agent({
|
|
|
223
239
|
summarize: ({ messages }) => summarizeConversation(messages),
|
|
224
240
|
compactModelMessages: ({ modelMessages, summary }) => [
|
|
225
241
|
{ role: "user", content: `Summary of the conversation so far:\n\n${summary}` },
|
|
226
|
-
...modelMessages.slice(-2),
|
|
242
|
+
...modelMessages.slice(-2).map(stripReasoning),
|
|
227
243
|
],
|
|
228
244
|
compactUIMessages: ({ uiMessages, summary }) => [
|
|
229
245
|
{
|
|
@@ -251,7 +267,7 @@ export const resilientChat = chat.agent({
|
|
|
251
267
|
// compacted baseline (summary + recent), so raw history is not re-sent.
|
|
252
268
|
const useHandle = native?.provider === "openai";
|
|
253
269
|
const result = streamText({
|
|
254
|
-
model: openai("gpt-
|
|
270
|
+
model: openai("gpt-6-luna"),
|
|
255
271
|
messages,
|
|
256
272
|
abortSignal: signal,
|
|
257
273
|
stopWhen: stepCountIs(5),
|
|
@@ -269,7 +285,7 @@ export const resilientChat = chat.agent({
|
|
|
269
285
|
}
|
|
270
286
|
|
|
271
287
|
return streamText({
|
|
272
|
-
model: anthropic("claude-sonnet-
|
|
288
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
273
289
|
messages,
|
|
274
290
|
abortSignal: signal,
|
|
275
291
|
stopWhen: stepCountIs(5),
|
|
@@ -292,6 +308,10 @@ export const resilientChat = chat.agent({
|
|
|
292
308
|
|
|
293
309
|
When Anthropic is down, the loop falls through to OpenAI. Because `compaction` has already reduced `messages` to a summary plus the last couple of exchanges, the switch sends the portable baseline, not megabytes of raw transcript.
|
|
294
310
|
|
|
311
|
+
<Note>
|
|
312
|
+
The messages that `compactModelMessages` keeps after the summary now follow a different history from the one their thinking blocks were produced in. Claude 5.5 models reject those blocks with a 400 (`Invalid signature in thinking block`), which is why the example runs the retained messages through `stripReasoning`.
|
|
313
|
+
</Note>
|
|
314
|
+
|
|
295
315
|
<Warning>
|
|
296
316
|
Fallback here retries a turn that hasn't started streaming yet. Once a response is streaming to the client, a mid-stream provider failure can't be swapped transparently. Surface the error and let the frontend regenerate the turn. See [Error handling](/ai-chat/error-handling).
|
|
297
317
|
</Warning>
|
|
@@ -163,7 +163,7 @@ export const myChat = chat.agent({
|
|
|
163
163
|
await db.chat.update({ where: { id: chatId }, data: { messages: uiMessages } });
|
|
164
164
|
},
|
|
165
165
|
run: async ({ messages, signal }) => {
|
|
166
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
166
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
167
167
|
},
|
|
168
168
|
});
|
|
169
169
|
```
|
|
@@ -28,7 +28,7 @@ export const supportAgent = chat.agent({
|
|
|
28
28
|
id: "support-agent",
|
|
29
29
|
telemetry: { recordUserMessage: false, recordClientData: false },
|
|
30
30
|
run: async ({ messages, signal, streamText }) =>
|
|
31
|
-
streamText({ model: anthropic("claude-sonnet-
|
|
31
|
+
streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }),
|
|
32
32
|
});
|
|
33
33
|
```
|
|
34
34
|
|
|
@@ -47,7 +47,7 @@ export const supportAgent = chat.agent({
|
|
|
47
47
|
telemetry: { recordUserMessage: false, recordClientData: false },
|
|
48
48
|
run: async ({ messages, signal, streamText }) =>
|
|
49
49
|
streamText({
|
|
50
|
-
model: anthropic("claude-sonnet-
|
|
50
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
51
51
|
messages,
|
|
52
52
|
abortSignal: signal,
|
|
53
53
|
// Replaces the default telemetry config (and chat.prompt.set()'s), so keep isEnabled on
|
|
@@ -94,7 +94,7 @@ export const agent = chat.agent({
|
|
|
94
94
|
},
|
|
95
95
|
run: async ({ messages, signal, streamText }) => {
|
|
96
96
|
return streamText({
|
|
97
|
-
model: anthropic("claude-sonnet-
|
|
97
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
98
98
|
messages,
|
|
99
99
|
abortSignal: signal,
|
|
100
100
|
stopWhen: stepCountIs(15),
|
|
@@ -165,7 +165,7 @@ If you also define your own AI SDK tools, pass them through `chat.toStreamTextOp
|
|
|
165
165
|
|
|
166
166
|
```ts
|
|
167
167
|
return streamText({
|
|
168
|
-
model: anthropic("claude-sonnet-
|
|
168
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
169
169
|
messages,
|
|
170
170
|
abortSignal: signal,
|
|
171
171
|
tools: {
|
|
@@ -301,7 +301,7 @@ export const myAgent = chat.agent({
|
|
|
301
301
|
tools, // declare here so toModelOutput survives across turns
|
|
302
302
|
run: async ({ messages, tools, stopSignal, streamText }) => {
|
|
303
303
|
return streamText({
|
|
304
|
-
model: anthropic("claude-sonnet-
|
|
304
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
305
305
|
messages,
|
|
306
306
|
tools,
|
|
307
307
|
abortSignal: stopSignal,
|
|
@@ -37,7 +37,7 @@ export const myChat = chat.agent({
|
|
|
37
37
|
return await db.getMessages(chatId);
|
|
38
38
|
},
|
|
39
39
|
run: async ({ messages, signal, streamText }) => {
|
|
40
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
40
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
41
41
|
},
|
|
42
42
|
});
|
|
43
43
|
```
|
|
@@ -247,7 +247,7 @@ export const myAgent = chat
|
|
|
247
247
|
// Score-based routing. The values arrive from the edge proxy.
|
|
248
248
|
if (clientData.__cf.botScore < 30) {
|
|
249
249
|
return streamText({
|
|
250
|
-
model: anthropic("claude-haiku-
|
|
250
|
+
model: anthropic("claude-haiku-5-5"),
|
|
251
251
|
messages: [{ role: "system", content: "Reject politely; do not engage." }],
|
|
252
252
|
abortSignal: signal,
|
|
253
253
|
stopWhen: stepCountIs(15),
|
|
@@ -255,7 +255,7 @@ export const myAgent = chat
|
|
|
255
255
|
}
|
|
256
256
|
|
|
257
257
|
return streamText({
|
|
258
|
-
model: anthropic("claude-sonnet-
|
|
258
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
259
259
|
messages,
|
|
260
260
|
abortSignal: signal,
|
|
261
261
|
// ...
|
|
@@ -122,7 +122,7 @@ export const myChat = chat
|
|
|
122
122
|
}
|
|
123
123
|
},
|
|
124
124
|
run: async ({ messages, signal, streamText }) => {
|
|
125
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
125
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
126
126
|
},
|
|
127
127
|
});
|
|
128
128
|
```
|
|
@@ -184,7 +184,7 @@ export const myChat = chat
|
|
|
184
184
|
}
|
|
185
185
|
},
|
|
186
186
|
run: async ({ messages, signal, streamText }) => {
|
|
187
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
187
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
188
188
|
},
|
|
189
189
|
});
|
|
190
190
|
```
|
|
@@ -45,7 +45,7 @@ export const myChat = chat.agent({
|
|
|
45
45
|
},
|
|
46
46
|
run: async ({ messages, signal, streamText }) => {
|
|
47
47
|
return streamText({
|
|
48
|
-
model: anthropic("claude-sonnet-
|
|
48
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
49
49
|
messages,
|
|
50
50
|
tools: {
|
|
51
51
|
inspectDocument: tool({
|
|
@@ -151,7 +151,7 @@ const session = chat.createSession(payload, {
|
|
|
151
151
|
|
|
152
152
|
for await (const turn of session) {
|
|
153
153
|
const result = streamText({
|
|
154
|
-
model: anthropic("claude-sonnet-
|
|
154
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
155
155
|
messages: turn.messages,
|
|
156
156
|
abortSignal: turn.signal,
|
|
157
157
|
prepareStep: turn.prepareStep(), // Handles injection + compaction
|
|
@@ -193,7 +193,7 @@ for (let turn = 0; turn < 100; turn++) {
|
|
|
193
193
|
});
|
|
194
194
|
|
|
195
195
|
const result = streamText({
|
|
196
|
-
model: anthropic("claude-sonnet-
|
|
196
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
197
197
|
messages,
|
|
198
198
|
prepareStep: conversation.prepareStep(), // Handles injection + compaction
|
|
199
199
|
stopWhen: stepCountIs(15),
|
|
@@ -248,7 +248,7 @@ function Chat({ chatId }: { chatId: string }) {
|
|
|
248
248
|
messages,
|
|
249
249
|
setMessages,
|
|
250
250
|
sendMessage,
|
|
251
|
-
metadata: { model: "gpt-
|
|
251
|
+
metadata: { model: "gpt-6-luna" },
|
|
252
252
|
});
|
|
253
253
|
|
|
254
254
|
return (
|
|
@@ -345,7 +345,7 @@ const sent = await transport.sendPendingMessage(chatId, {
|
|
|
345
345
|
id: crypto.randomUUID(),
|
|
346
346
|
role: "user",
|
|
347
347
|
parts: [{ type: "text", text: "and compare to vercel" }],
|
|
348
|
-
}, { model: "gpt-
|
|
348
|
+
}, { model: "gpt-6-luna" });
|
|
349
349
|
```
|
|
350
350
|
|
|
351
351
|
Unlike `sendMessage()` from useChat, this does NOT:
|
|
@@ -4,7 +4,7 @@ sidebarTitle: "Prompt caching"
|
|
|
4
4
|
description: "Cache the stable prefix of your agent's prompt with Anthropic prompt caching to cut token cost and latency on every turn."
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
**Prompt caching lets a provider reuse the unchanged prefix of your prompt across requests, billing it at a fraction of the input price and skipping re-processing.** With Anthropic, cache reads cost ~
|
|
7
|
+
**Prompt caching lets a provider reuse the unchanged prefix of your prompt across requests, billing it at a fraction of the input price and skipping re-processing.** With Anthropic, cache reads cost ~5% of base input tokens on Claude Sonnet 5.5 and Opus 5.5, so a long, stable system prompt or a growing conversation history pays full price once and reads cheaply on every turn after.
|
|
8
8
|
|
|
9
9
|
Caching is a **byte-exact prefix match**: any change in the prefix invalidates everything after it. A multi-turn agent is the ideal case — the system prompt, tools, and earlier turns are identical turn over turn, so the cacheable prefix only grows. `chat.agent` is built to keep that prefix stable across turns, suspends, and resumes; this page shows how to place the cache breakpoints and verify they're hitting.
|
|
10
10
|
|
|
@@ -46,7 +46,7 @@ export const myChat = chat.agent({
|
|
|
46
46
|
},
|
|
47
47
|
run: async ({ messages, signal, streamText }) => {
|
|
48
48
|
return streamText({
|
|
49
|
-
model: anthropic("claude-sonnet-
|
|
49
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
50
50
|
// Caches the system block with a 5-minute breakpoint.
|
|
51
51
|
messages,
|
|
52
52
|
abortSignal: signal,
|
|
@@ -63,7 +63,7 @@ export const myChat = chat.agent({
|
|
|
63
63
|
systemProviderOptions: { anthropic: { cacheControl: { type: "ephemeral" } } },
|
|
64
64
|
run: async ({ messages, signal, streamText }) =>
|
|
65
65
|
streamText({
|
|
66
|
-
model: anthropic("claude-sonnet-
|
|
66
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
67
67
|
messages,
|
|
68
68
|
abortSignal: signal,
|
|
69
69
|
}),
|
|
@@ -80,7 +80,7 @@ onChatStart: async () => {
|
|
|
80
80
|
},
|
|
81
81
|
run: async ({ messages, signal, streamText }) => {
|
|
82
82
|
return streamText({
|
|
83
|
-
model: anthropic("claude-sonnet-
|
|
83
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
84
84
|
messages,
|
|
85
85
|
abortSignal: signal,
|
|
86
86
|
});
|
|
@@ -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
|
abortSignal: signal,
|
|
123
123
|
});
|
|
@@ -128,7 +128,7 @@ export const myChat = chat.agent({
|
|
|
128
128
|
The system breakpoint and the conversation breakpoint compose: the system block is cached once for the life of the chat, and each turn extends the cached message prefix.
|
|
129
129
|
|
|
130
130
|
<Note>
|
|
131
|
-
Anthropic allows **at most 4** cache breakpoints per request, and a prefix must
|
|
131
|
+
Anthropic allows **at most 4** cache breakpoints per request, and a prefix must reach a model-dependent minimum to cache at all (512 tokens on Claude Sonnet 5.5 and Opus 5.5) — shorter prefixes silently don't cache. One system breakpoint plus one rolling message breakpoint is the typical setup and leaves headroom.
|
|
132
132
|
</Note>
|
|
133
133
|
|
|
134
134
|
<Note>
|
|
@@ -171,7 +171,7 @@ run: async ({ messages, signal, previousTurnUsage, streamText }) => {
|
|
|
171
171
|
console.log("cache write", previousTurnUsage?.inputTokenDetails?.cacheWriteTokens);
|
|
172
172
|
|
|
173
173
|
return streamText({
|
|
174
|
-
model: anthropic("claude-sonnet-
|
|
174
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
175
175
|
messages,
|
|
176
176
|
abortSignal: signal,
|
|
177
177
|
});
|
|
@@ -23,7 +23,7 @@ The chat surface works with Vercel AI SDK **v5, v6, or v7**; install whichever m
|
|
|
23
23
|
id: "my-chat",
|
|
24
24
|
run: async ({ messages, signal, streamText }) => {
|
|
25
25
|
return streamText({
|
|
26
|
-
model: anthropic("claude-sonnet-
|
|
26
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
27
27
|
messages,
|
|
28
28
|
abortSignal: signal,
|
|
29
29
|
stopWhen: stepCountIs(15),
|
|
@@ -76,7 +76,7 @@ The chat surface works with Vercel AI SDK **v5, v6, or v7**; install whichever m
|
|
|
76
76
|
|
|
77
77
|
`requireChatOwner` is your application helper: authenticate the request, load the chat by ID and owner, and throw if it doesn't belong to that user. Create the chat record on your server before rendering the frontend, and pass its ID into `Chat`. Check ownership in both actions, including token refresh.
|
|
78
78
|
|
|
79
|
-
Set `TRIGGER_SECRET_KEY` and your model provider key in the
|
|
79
|
+
Set `TRIGGER_SECRET_KEY` on your server and your model provider key in the worker environment. Keep both keys out of the browser.
|
|
80
80
|
|
|
81
81
|
</Step>
|
|
82
82
|
|
package/docs/ai-chat/testing.mdx
CHANGED
|
@@ -92,7 +92,7 @@ export const myChatAgent = chat
|
|
|
92
92
|
id: "my-chat",
|
|
93
93
|
run: async ({ messages, clientData, signal, streamText }) => {
|
|
94
94
|
return streamText({
|
|
95
|
-
model: clientData?.model ?? "openai/gpt-
|
|
95
|
+
model: clientData?.model ?? "openai/gpt-6-luna",
|
|
96
96
|
messages,
|
|
97
97
|
abortSignal: signal,
|
|
98
98
|
stopWhen: stepCountIs(15),
|
|
@@ -161,7 +161,7 @@ export const agent = chat
|
|
|
161
161
|
id: "agent",
|
|
162
162
|
run: async ({ messages, clientData, signal, streamText }) => {
|
|
163
163
|
return streamText({
|
|
164
|
-
model: clientData?.model ?? anthropic("claude-haiku-
|
|
164
|
+
model: clientData?.model ?? anthropic("claude-haiku-5-5"),
|
|
165
165
|
messages,
|
|
166
166
|
abortSignal: signal,
|
|
167
167
|
stopWhen: stepCountIs(15),
|
|
@@ -177,9 +177,13 @@ const harness = mockChatAgent(agent, {
|
|
|
177
177
|
});
|
|
178
178
|
```
|
|
179
179
|
|
|
180
|
+
`clientData` reaches `run()` and the callbacks an agent can call a model from: `prepareMessages`, `onValidateMessages`, `onAction`, `onTurnComplete`, `onCompacted`, the compaction `shouldCompact` and `summarize` callbacks (between steps and between turns, also through `chat.MessageAccumulator` and `chat.createSession` turns), and the `pendingMessages` `onReceived` and `onInjected` callbacks. Read the mock model from `clientData` in each of them and those calls stay offline.
|
|
181
|
+
|
|
182
|
+
In a hand-rolled `chat.customAgent` loop that doesn't use `chat.createSession`, the SDK has no turn to read from. `conversation.prepareStep()` then calls the inner `summarize` without `chatId`, `turn` or `clientData`, so close over `clientData` when you build the `summarize` config. Pass `{ chatId, turn, clientData }` to `conversation.compactIfNeeded()` for the outer compaction.
|
|
183
|
+
|
|
180
184
|
## Driving turns
|
|
181
185
|
|
|
182
|
-
The harness exposes one method per chat trigger. Each waits for the next `trigger:turn-complete` chunk before resolving.
|
|
186
|
+
The harness exposes one method per chat trigger. Each waits for the next `trigger:turn-complete` chunk, and for the turn's post-turn hooks (`onTurnComplete` and the transcript save) to finish, before resolving. You can assert on what those hooks recorded right after the `await`.
|
|
183
187
|
|
|
184
188
|
### sendMessage
|
|
185
189
|
|
|
@@ -283,9 +287,6 @@ const agent = chat.agent({
|
|
|
283
287
|
const harness = mockChatAgent(agent, { chatId: "t" });
|
|
284
288
|
await harness.sendMessage(userMessage("hi"));
|
|
285
289
|
|
|
286
|
-
// onTurnComplete fires after the turn-complete chunk is written —
|
|
287
|
-
// give it a tick before asserting.
|
|
288
|
-
await new Promise((r) => setTimeout(r, 20));
|
|
289
290
|
expect(events).toEqual([
|
|
290
291
|
"onChatStart",
|
|
291
292
|
"onTurnStart",
|
|
@@ -413,7 +414,6 @@ try {
|
|
|
413
414
|
role: "user",
|
|
414
415
|
parts: [{ type: "text", text: "where were we?" }],
|
|
415
416
|
});
|
|
416
|
-
await new Promise((r) => setTimeout(r, 20));
|
|
417
417
|
|
|
418
418
|
expect(onChatStart).not.toHaveBeenCalled();
|
|
419
419
|
expect(onTurnStart).toHaveBeenCalledTimes(1);
|
|
@@ -534,7 +534,7 @@ export const agent = chat.agent({
|
|
|
534
534
|
});
|
|
535
535
|
},
|
|
536
536
|
run: async ({ messages, signal }) => {
|
|
537
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
537
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
538
538
|
},
|
|
539
539
|
});
|
|
540
540
|
```
|
|
@@ -675,7 +675,7 @@ await runInMockTaskContext(
|
|
|
675
675
|
|
|
676
676
|
- **No network.** The mock task context replaces realtime streams, run metadata, lifecycle managers, and the runtime. Anything that bypasses these (raw `fetch`, direct DB clients) runs against the real network.
|
|
677
677
|
- **Single agent per process.** The resource catalog is process-global; tests within a file are sequential by default. If you parallelize across files, vitest runs each file in its own worker, which avoids registry collisions.
|
|
678
|
-
- **
|
|
678
|
+
- **Deferred work.** Turn methods wait for `onTurnComplete`, but not for work you start with `chat.defer()`. That work runs alongside the idle wait, as it does in production, so await your own promise before asserting on it.
|
|
679
679
|
- **No real LLM.** The harness does not call providers — you must inject `MockLanguageModelV3` (or another mock) yourself.
|
|
680
680
|
|
|
681
681
|
## Check the deployed behavior
|
package/docs/ai-chat/tools.mdx
CHANGED
|
@@ -26,7 +26,7 @@ export const myChat = chat.agent({
|
|
|
26
26
|
run: async ({ messages, tools, signal, streamText }) =>
|
|
27
27
|
streamText({
|
|
28
28
|
tools,
|
|
29
|
-
model: anthropic("claude-sonnet-
|
|
29
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
30
30
|
messages,
|
|
31
31
|
abortSignal: signal,
|
|
32
32
|
stopWhen: stepCountIs(15),
|
|
@@ -88,7 +88,7 @@ export const chartChat = chat.agent({
|
|
|
88
88
|
run: async ({ messages, tools, signal, streamText }) =>
|
|
89
89
|
streamText({
|
|
90
90
|
tools,
|
|
91
|
-
model: anthropic("claude-sonnet-
|
|
91
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
92
92
|
messages,
|
|
93
93
|
abortSignal: signal,
|
|
94
94
|
stopWhen: stepCountIs(15),
|
|
@@ -112,7 +112,7 @@ export const myChat = chat
|
|
|
112
112
|
run: async ({ messages, tools, signal, streamText }) =>
|
|
113
113
|
streamText({
|
|
114
114
|
tools,
|
|
115
|
-
model: anthropic("claude-sonnet-
|
|
115
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
116
116
|
messages,
|
|
117
117
|
abortSignal: signal,
|
|
118
118
|
stopWhen: stepCountIs(15),
|
|
@@ -120,6 +120,10 @@ export const myChat = chat
|
|
|
120
120
|
});
|
|
121
121
|
```
|
|
122
122
|
|
|
123
|
+
<Note>
|
|
124
|
+
Claude 5.5 models bind each thinking block to the tool set it was produced with. Adding or removing a tool partway through a chat can make Anthropic reject the earlier thinking blocks with a 400, so keep a chat's tool set stable once it starts (for example, decide `plan`-based tools on the first turn).
|
|
125
|
+
</Note>
|
|
126
|
+
|
|
123
127
|
The function receives a `ResolveToolsEvent` and runs once per turn (after `clientData` is parsed):
|
|
124
128
|
|
|
125
129
|
| Field | Type | Description |
|
|
@@ -140,7 +144,7 @@ run: async ({ messages, tools, signal, streamText }) => {
|
|
|
140
144
|
// `tools` is typed as your tool set, not a broad `ToolSet`
|
|
141
145
|
return streamText({
|
|
142
146
|
tools,
|
|
143
|
-
model: anthropic("claude-sonnet-
|
|
147
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
144
148
|
messages,
|
|
145
149
|
abortSignal: signal,
|
|
146
150
|
});
|
|
@@ -181,7 +185,7 @@ const messages = await convertToModelMessages(uiMessages, {
|
|
|
181
185
|
ignoreIncompleteToolCalls: true,
|
|
182
186
|
});
|
|
183
187
|
|
|
184
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
188
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, tools });
|
|
185
189
|
```
|
|
186
190
|
|
|
187
191
|
## Learn more
|
|
@@ -36,7 +36,7 @@ import { anthropic } from "@ai-sdk/anthropic";
|
|
|
36
36
|
export const myChat = chat.agent({
|
|
37
37
|
id: "my-chat",
|
|
38
38
|
run: async ({ messages, signal, streamText }) =>
|
|
39
|
-
streamText({ model: anthropic("claude-sonnet-
|
|
39
|
+
streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }),
|
|
40
40
|
});
|
|
41
41
|
```
|
|
42
42
|
|
|
@@ -55,7 +55,7 @@ export const myChat = chat.agent({
|
|
|
55
55
|
id: "my-chat",
|
|
56
56
|
storage: myTranscriptStorage,
|
|
57
57
|
run: async ({ messages, signal, streamText }) =>
|
|
58
|
-
streamText({ model: anthropic("claude-sonnet-
|
|
58
|
+
streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal }),
|
|
59
59
|
});
|
|
60
60
|
```
|
|
61
61
|
|
package/docs/ai-chat/types.mdx
CHANGED
|
@@ -93,10 +93,12 @@ export const myChat = chat
|
|
|
93
93
|
run: async ({ messages, tools, signal, streamText }) => {
|
|
94
94
|
// `tools` is myTools, typed, handed back on the payload
|
|
95
95
|
return streamText({
|
|
96
|
-
model: anthropic("claude-sonnet-
|
|
96
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
97
97
|
messages,
|
|
98
98
|
tools,
|
|
99
99
|
abortSignal: signal,
|
|
100
|
+
// Claude 5.5 models omit thinking text unless you ask for a summary
|
|
101
|
+
providerOptions: { anthropic: { thinking: { type: "adaptive", display: "summarized" } } },
|
|
100
102
|
stopWhen: stepCountIs(15),
|
|
101
103
|
});
|
|
102
104
|
},
|
|
@@ -194,7 +196,12 @@ export const myChat = chat
|
|
|
194
196
|
.agent({
|
|
195
197
|
id: "my-chat",
|
|
196
198
|
run: async ({ messages, signal, streamText }) => {
|
|
197
|
-
return streamText({
|
|
199
|
+
return streamText({
|
|
200
|
+
model: anthropic("claude-sonnet-5-5"),
|
|
201
|
+
messages,
|
|
202
|
+
abortSignal: signal,
|
|
203
|
+
providerOptions: { anthropic: { thinking: { type: "adaptive", display: "summarized" } } },
|
|
204
|
+
});
|
|
198
205
|
},
|
|
199
206
|
});
|
|
200
207
|
```
|
|
@@ -219,7 +226,7 @@ chat
|
|
|
219
226
|
await createChatRecord(event.chatId);
|
|
220
227
|
},
|
|
221
228
|
run: async ({ messages, signal, streamText }) => {
|
|
222
|
-
return streamText({ model: anthropic("claude-sonnet-
|
|
229
|
+
return streamText({ model: anthropic("claude-sonnet-5-5"), messages, abortSignal: signal });
|
|
223
230
|
},
|
|
224
231
|
});
|
|
225
232
|
```
|
package/docs/apikeys.mdx
CHANGED
|
@@ -123,11 +123,12 @@ The key must belong to the target environment. Use a Production key with `--env
|
|
|
123
123
|
|
|
124
124
|
Give a key a list of allowed IP addresses to limit where it can be used. Requests using the key from any other address are rejected, so a leaked key is useless outside your network. They get the same `Invalid API key` error as a key that doesn't exist, so the response never confirms the key is real. If a working key suddenly returns that error, check its allowed IP addresses.
|
|
125
125
|
|
|
126
|
-
-
|
|
126
|
+
- Add IPv4 or IPv6 addresses or CIDR ranges, for example `203.0.113.9` or `203.0.113.0/24`. Press Enter, comma or space after each one, or paste a list. A key can have up to 50 ranges.
|
|
127
127
|
- Leave the list empty to allow any IP address.
|
|
128
128
|
- Private and reserved ranges, such as `10.0.0.0/8` or `192.168.0.0/16`, are not accepted. Use the public addresses your requests come from.
|
|
129
129
|
- Set the list when you create the key, or change it later with **Edit allowed IPs** in the key's menu. Changes take effect immediately.
|
|
130
130
|
- The API keys page shows the IP address each key was last used from, so you can check it before saving a list.
|
|
131
|
+
- **Test an IP**, beside the list, checks whether an address would be allowed before you save.
|
|
131
132
|
- [Public Access Tokens](/realtime/auth) created with the key are not IP-restricted, since they are meant for browsers. Creating one still requires an allowed IP address.
|
|
132
133
|
|
|
133
134
|
<Tip>
|
|
@@ -26,6 +26,18 @@ yarn dlx trigger.dev@latest login
|
|
|
26
26
|
|
|
27
27
|
When the CLI opens your browser, approving the login sends you back to the CLI automatically. If the browser is on another machine, for example when you're connected over SSH, use `--no-browser`: after you approve, the page shows a code to paste into the terminal.
|
|
28
28
|
|
|
29
|
+
## Login expiry
|
|
30
|
+
|
|
31
|
+
A login stops working after 7 days without use. The 7 days count from the last command that used it, or from when you logged in if you never used it. Running a command that uses your login, such as `dev` or `deploy`, at least once a week keeps you logged in.
|
|
32
|
+
|
|
33
|
+
When a login has expired, commands that log you in, such as `login`, `dev` and `deploy`, start a new login. You don't need to log out first. The [MCP server](/mcp-introduction#authentication) does the same on its next tool call.
|
|
34
|
+
|
|
35
|
+
- **In CI**, the CLI can't complete a login, so it fails and tells you to run `npx trigger.dev@latest login`. To deploy from CI, use an environment API key in `TRIGGER_ACCESS_TOKEN` instead of a copied CLI login. See [CI / GitHub Actions](/github-actions).
|
|
36
|
+
- **CLI versions before 4.8.4** show the server's error but can't start a new login over an expired one. Run `trigger.dev logout`, then `trigger.dev login`.
|
|
37
|
+
- **Logins made before login expiry was introduced** (in 4.8.4 for self-hosted instances) don't expire.
|
|
38
|
+
|
|
39
|
+
If you self-host, `CLI_LOGIN_IDLE_TIMEOUT_DAYS` sets the window (default `7`), and `0` turns idle expiry off for new logins. Each login keeps the setting it was created with. See the [webapp environment variables](/self-hosting/env/webapp).
|
|
40
|
+
|
|
29
41
|
## Options
|
|
30
42
|
|
|
31
43
|
<ParamField body="No browser" type="--no-browser">
|
package/docs/concurrency.mdx
CHANGED
|
@@ -201,6 +201,46 @@ export const processWebhook = task({
|
|
|
201
201
|
await processWebhook.trigger(payload, { concurrencyKey: tenantId });
|
|
202
202
|
```
|
|
203
203
|
|
|
204
|
+
## A different key for each limit
|
|
205
|
+
|
|
206
|
+
A string `concurrencyKey` keys every `perKey` bound the run holds. When two limits need different keys, for example a cap per session and a cap per organization on the same run, pass an object. `default` is the run's own key, and every other entry is a named limit and the key to use for it:
|
|
207
|
+
|
|
208
|
+
```ts /trigger/subagent.ts
|
|
209
|
+
import { concurrencyLimit, task } from "@trigger.dev/sdk";
|
|
210
|
+
|
|
211
|
+
// each organization runs at most 20 sub-agents at once
|
|
212
|
+
export const orgLimit = concurrencyLimit({ name: "org-subagents", perKey: 20 });
|
|
213
|
+
|
|
214
|
+
export const subagent = task({
|
|
215
|
+
id: "subagent",
|
|
216
|
+
// 3 per session, 200 in total, plus the organization limit
|
|
217
|
+
concurrency: [{ perKey: 3, total: 200 }, orgLimit],
|
|
218
|
+
run: async (payload) => {
|
|
219
|
+
//...
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
```ts app/api/subagent/route.ts
|
|
225
|
+
import { orgLimit, subagent } from "~/trigger/subagent";
|
|
226
|
+
|
|
227
|
+
await subagent.trigger(payload, {
|
|
228
|
+
concurrencyKey: {
|
|
229
|
+
default: sessionId,
|
|
230
|
+
[orgLimit.name]: orgId,
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
The run starts only when the session has fewer than 3 running, the organization has fewer than 20, and fewer than 200 are running in total.
|
|
236
|
+
|
|
237
|
+
- **A limit uses its own entry if it has one, otherwise `default`.** A string is shorthand for `{ default: "..." }`.
|
|
238
|
+
- **`default` is required.** Runs are queued and scheduled fairly per default key, so pick the key you want fairness across.
|
|
239
|
+
- **A limit's own key is 1-128 characters.**
|
|
240
|
+
- **An entry for a limit the task doesn't declare adds that limit to the run.** If the limit is declared in the same environment, by another task or by a deploy that is still rolling out, the run counts towards it, so triggers keep working during the deploy.
|
|
241
|
+
- **A name that matches no declared limit caps nothing**, and the limit you meant falls back to `default`. Use `[limit.name]` rather than a string literal.
|
|
242
|
+
- **`default` always means the default key**, so a limit that is itself named `default` can't be given its own key.
|
|
243
|
+
|
|
204
244
|
## A global cap for a shared resource
|
|
205
245
|
|
|
206
246
|
To cap something global, like total traffic to an external API, across many tasks and all tenants: declare a limit with only a `total` and share it. It counts every run holding it, whether or not the run has a `concurrencyKey`:
|
|
@@ -186,7 +186,7 @@ export const myChat = chat.agent({
|
|
|
186
186
|
const user = await prisma.user.findUnique({ where: { id: clientData.userId } });
|
|
187
187
|
// The connection is back in the pool before the model stream starts.
|
|
188
188
|
return streamText({
|
|
189
|
-
model: openai("gpt-
|
|
189
|
+
model: openai("gpt-6-luna"),
|
|
190
190
|
system: `Helping ${user?.name ?? "the user"}.`,
|
|
191
191
|
messages,
|
|
192
192
|
abortSignal: signal,
|