@trigger.dev/sdk 4.7.3 → 4.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/dist/commonjs/v3/ai.d.ts +26 -0
  2. package/dist/commonjs/v3/ai.js +7 -5
  3. package/dist/commonjs/v3/ai.js.map +1 -1
  4. package/dist/commonjs/v3/concurrencyLimits.d.ts +37 -7
  5. package/dist/commonjs/v3/concurrencyLimits.js +38 -70
  6. package/dist/commonjs/v3/concurrencyLimits.js.map +1 -1
  7. package/dist/commonjs/v3/index.d.ts +1 -1
  8. package/dist/commonjs/v3/index.js.map +1 -1
  9. package/dist/commonjs/v3/query.d.ts +434 -1
  10. package/dist/commonjs/v3/query.js +115 -0
  11. package/dist/commonjs/v3/query.js.map +1 -1
  12. package/dist/commonjs/v3/runs.d.ts +22 -1
  13. package/dist/commonjs/v3/runs.js +6 -3
  14. package/dist/commonjs/v3/runs.js.map +1 -1
  15. package/dist/commonjs/version.js +1 -1
  16. package/dist/esm/v3/ai.d.ts +26 -0
  17. package/dist/esm/v3/ai.js +7 -5
  18. package/dist/esm/v3/ai.js.map +1 -1
  19. package/dist/esm/v3/concurrencyLimits.d.ts +37 -7
  20. package/dist/esm/v3/concurrencyLimits.js +38 -70
  21. package/dist/esm/v3/concurrencyLimits.js.map +1 -1
  22. package/dist/esm/v3/index.d.ts +1 -1
  23. package/dist/esm/v3/index.js.map +1 -1
  24. package/dist/esm/v3/query.d.ts +434 -1
  25. package/dist/esm/v3/query.js +115 -0
  26. package/dist/esm/v3/query.js.map +1 -1
  27. package/dist/esm/v3/runs.d.ts +22 -1
  28. package/dist/esm/v3/runs.js +6 -3
  29. package/dist/esm/v3/runs.js.map +1 -1
  30. package/dist/esm/version.js +1 -1
  31. package/docs/ai-chat/actions.mdx +6 -1
  32. package/docs/ai-chat/backend.mdx +47 -0
  33. package/docs/ai-chat/patterns/redacting-telemetry.mdx +117 -0
  34. package/docs/ai-chat/patterns/sub-agents.mdx +33 -0
  35. package/docs/ai-chat/pending-messages.mdx +2 -0
  36. package/docs/ai-chat/reference.mdx +53 -2
  37. package/docs/ai-chat/transcript-storage.mdx +1 -1
  38. package/docs/apikeys.mdx +9 -7
  39. package/docs/billing-limits.mdx +1 -1
  40. package/docs/cli-env-commands.mdx +5 -4
  41. package/docs/cli-init-commands.mdx +27 -1
  42. package/docs/cli-login-commands.mdx +20 -0
  43. package/docs/cli-projects-commands.mdx +13 -1
  44. package/docs/cli-runs-commands.mdx +3 -2
  45. package/docs/cli-tasks-commands.mdx +95 -0
  46. package/docs/cli-update-commands.mdx +9 -3
  47. package/docs/cli-whoami-commands.mdx +12 -0
  48. package/docs/concurrency.mdx +32 -0
  49. package/docs/config/config-file.mdx +58 -0
  50. package/docs/config/extensions/audioWaveform.mdx +4 -1
  51. package/docs/config/extensions/overview.mdx +2 -0
  52. package/docs/config/extensions/prismaExtension.mdx +6 -7
  53. package/docs/config/extensions/puppeteer.mdx +3 -5
  54. package/docs/config/extensions/pythonExtension.mdx +9 -1
  55. package/docs/config/extensions/syncEnvVars.mdx +6 -0
  56. package/docs/deploy-environment-variables.mdx +5 -1
  57. package/docs/deployment/atomic-deployment.mdx +5 -3
  58. package/docs/deployment/dev-branches.mdx +5 -5
  59. package/docs/deployment/overview.mdx +9 -8
  60. package/docs/deployment/preview-branches.mdx +7 -4
  61. package/docs/errors-retrying.mdx +4 -4
  62. package/docs/github-actions.mdx +3 -3
  63. package/docs/how-it-works.mdx +5 -5
  64. package/docs/introduction.mdx +6 -0
  65. package/docs/limits.mdx +32 -8
  66. package/docs/logging.mdx +1 -1
  67. package/docs/machines.mdx +1 -1
  68. package/docs/manual-setup.mdx +1 -1
  69. package/docs/mcp-introduction.mdx +8 -7
  70. package/docs/mcp-tools.mdx +113 -3
  71. package/docs/migrating-from-v3.mdx +1 -1
  72. package/docs/observability/dashboards.mdx +64 -0
  73. package/docs/observability/query.mdx +6 -2
  74. package/docs/private-networking/aws-console-setup.mdx +1 -1
  75. package/docs/private-networking/overview.mdx +1 -1
  76. package/docs/quick-start.mdx +3 -40
  77. package/docs/realtime/auth.mdx +1 -1
  78. package/docs/realtime/backend/input-streams.mdx +159 -0
  79. package/docs/realtime/backend/streams.mdx +25 -10
  80. package/docs/realtime/how-it-works.mdx +1 -1
  81. package/docs/realtime/react-hooks/overview.mdx +1 -1
  82. package/docs/realtime/react-hooks/streams.mdx +2 -2
  83. package/docs/realtime/react-hooks/subscribe.mdx +19 -3
  84. package/docs/realtime/react-hooks/triggering.mdx +2 -2
  85. package/docs/realtime/react-hooks/use-wait-token.mdx +1 -1
  86. package/docs/realtime/run-object.mdx +47 -24
  87. package/docs/replaying.mdx +26 -1
  88. package/docs/reports.mdx +4 -2
  89. package/docs/run-tests.mdx +2 -2
  90. package/docs/run-usage.mdx +3 -3
  91. package/docs/runs/heartbeats.mdx +2 -2
  92. package/docs/runs/list-best-practices.mdx +234 -0
  93. package/docs/runs/max-duration.mdx +4 -0
  94. package/docs/runs/metadata.mdx +7 -10
  95. package/docs/runs.mdx +18 -8
  96. package/docs/self-hosting/env/supervisor.mdx +3 -0
  97. package/docs/self-hosting/env/webapp.mdx +5 -0
  98. package/docs/self-hosting/overview.mdx +26 -0
  99. package/docs/tags.mdx +6 -0
  100. package/docs/tasks/scheduled.mdx +11 -5
  101. package/docs/triggering.mdx +8 -0
  102. package/docs/troubleshooting-alerts.mdx +102 -3
  103. package/docs/troubleshooting.mdx +1 -1
  104. package/docs/upgrading-packages.mdx +3 -3
  105. package/docs/vercel-integration.mdx +13 -3
  106. package/docs/versioning.mdx +1 -1
  107. package/docs/wait-for-token.mdx +3 -3
  108. package/docs/webhooks/channels.mdx +158 -0
  109. package/docs/webhooks/connect.mdx +84 -0
  110. package/docs/webhooks/deliveries.mdx +103 -0
  111. package/docs/webhooks/filters.mdx +144 -0
  112. package/docs/webhooks/human-in-the-loop.mdx +162 -0
  113. package/docs/webhooks/linear.mdx +190 -0
  114. package/docs/webhooks/overview.mdx +119 -0
  115. package/docs/webhooks/session-routing.mdx +145 -0
  116. package/docs/webhooks/slack.mdx +397 -0
  117. package/docs/webhooks/sources.mdx +221 -0
  118. package/docs/webhooks/waiters.mdx +194 -0
  119. package/package.json +3 -2
@@ -243,13 +243,17 @@ This webhook is sent when a run fails. The payload is available on the `object`
243
243
  </ParamField>
244
244
 
245
245
  <ParamField path="object.environment.type" type="string">
246
- Environment type (STAGING or PRODUCTION)
246
+ Environment type (`PRODUCTION`, `STAGING`, or `PREVIEW`)
247
247
  </ParamField>
248
248
 
249
249
  <ParamField path="object.environment.slug" type="string">
250
250
  Environment slug
251
251
  </ParamField>
252
252
 
253
+ <ParamField path="object.environment.branchName" type="string">
254
+ Environment branch name (optional)
255
+ </ParamField>
256
+
253
257
  <ParamField path="object.organization.id" type="string">
254
258
  Organization ID
255
259
  </ParamField>
@@ -311,7 +315,7 @@ This webhook is sent when a deployment succeeds. The payload is available on the
311
315
  </ParamField>
312
316
 
313
317
  <ParamField path="object.environment.type" type="string">
314
- Environment type (STAGING or PRODUCTION)
318
+ Environment type (`PRODUCTION`, `STAGING`, or `PREVIEW`)
315
319
  </ParamField>
316
320
 
317
321
  <ParamField path="object.environment.slug" type="string">
@@ -346,6 +350,54 @@ This webhook is sent when a deployment succeeds. The payload is available on the
346
350
  Project name
347
351
  </ParamField>
348
352
 
353
+ <ParamField path="object.git" type="object">
354
+ Git metadata for the deployment (optional). When present, `branch`, `commitSha`, `commitMessage`, `commitUrl` and `branchUrl` are always set.
355
+ </ParamField>
356
+
357
+ <ParamField path="object.git.branch" type="string">
358
+ Git branch
359
+ </ParamField>
360
+
361
+ <ParamField path="object.git.commitSha" type="string">
362
+ Short commit SHA (first 7 characters)
363
+ </ParamField>
364
+
365
+ <ParamField path="object.git.commitMessage" type="string">
366
+ Commit message (empty string if unavailable)
367
+ </ParamField>
368
+
369
+ <ParamField path="object.git.commitUrl" type="string">
370
+ URL of the commit
371
+ </ParamField>
372
+
373
+ <ParamField path="object.git.branchUrl" type="string">
374
+ URL of the branch
375
+ </ParamField>
376
+
377
+ <ParamField path="object.git.pullRequestNumber" type="number">
378
+ Pull request number (optional)
379
+ </ParamField>
380
+
381
+ <ParamField path="object.git.pullRequestTitle" type="string">
382
+ Pull request title (optional)
383
+ </ParamField>
384
+
385
+ <ParamField path="object.git.pullRequestUrl" type="string">
386
+ Pull request URL (optional)
387
+ </ParamField>
388
+
389
+ <ParamField path="object.git.provider" type="string">
390
+ Git provider (optional)
391
+ </ParamField>
392
+
393
+ <ParamField path="object.vercel" type="object">
394
+ Vercel metadata for the deployment (optional)
395
+ </ParamField>
396
+
397
+ <ParamField path="object.vercel.deploymentUrl" type="string">
398
+ URL of the deployment in the Vercel dashboard
399
+ </ParamField>
400
+
349
401
  ### Deployment Failed Alert
350
402
 
351
403
  This webhook is sent when a deployment fails. The payload is available on the `object` property:
@@ -391,7 +443,7 @@ This webhook is sent when a deployment fails. The payload is available on the `o
391
443
  </ParamField>
392
444
 
393
445
  <ParamField path="object.environment.type" type="string">
394
- Environment type (STAGING or PRODUCTION)
446
+ Environment type (`PRODUCTION`, `STAGING`, or `PREVIEW`)
395
447
  </ParamField>
396
448
 
397
449
  <ParamField path="object.environment.slug" type="string">
@@ -426,6 +478,53 @@ This webhook is sent when a deployment fails. The payload is available on the `o
426
478
  Project name
427
479
  </ParamField>
428
480
 
481
+ <ParamField path="object.git" type="object">
482
+ Git metadata for the deployment (optional). When present, `branch`, `commitSha`, `commitMessage`, `commitUrl` and `branchUrl` are always set.
483
+ </ParamField>
484
+
485
+ <ParamField path="object.git.branch" type="string">
486
+ Git branch
487
+ </ParamField>
488
+
489
+ <ParamField path="object.git.commitSha" type="string">
490
+ Short commit SHA (first 7 characters)
491
+ </ParamField>
492
+
493
+ <ParamField path="object.git.commitMessage" type="string">
494
+ Commit message (empty string if unavailable)
495
+ </ParamField>
496
+
497
+ <ParamField path="object.git.commitUrl" type="string">
498
+ URL of the commit
499
+ </ParamField>
500
+
501
+ <ParamField path="object.git.branchUrl" type="string">
502
+ URL of the branch
503
+ </ParamField>
504
+
505
+ <ParamField path="object.git.pullRequestNumber" type="number">
506
+ Pull request number (optional)
507
+ </ParamField>
508
+
509
+ <ParamField path="object.git.pullRequestTitle" type="string">
510
+ Pull request title (optional)
511
+ </ParamField>
512
+
513
+ <ParamField path="object.git.pullRequestUrl" type="string">
514
+ Pull request URL (optional)
515
+ </ParamField>
516
+
517
+ <ParamField path="object.git.provider" type="string">
518
+ Git provider (optional)
519
+ </ParamField>
520
+
521
+ <ParamField path="object.vercel" type="object">
522
+ Vercel metadata for the deployment (optional)
523
+ </ParamField>
524
+
525
+ <ParamField path="object.vercel.deploymentUrl" type="string">
526
+ URL of the deployment in the Vercel dashboard
527
+ </ParamField>
429
528
 
430
529
  ### Error Group Alert
431
530
 
@@ -251,7 +251,7 @@ If runs are staying in the `QUEUED` state for extended periods, check your concu
251
251
  **Solutions:**
252
252
 
253
253
  - **Increase concurrency limits** - If you're on a paid plan, increase your environment concurrency limit via the dashboard
254
- - **Review queue concurrency limits** - Check if individual queues have restrictive `concurrencyLimit` settings
254
+ - **Review concurrency settings** - Check if your tasks have restrictive `concurrency` settings, or your queues a restrictive legacy `concurrencyLimit`. See [Concurrency](/concurrency)
255
255
  - **Check for stuck runs** - See if stalled runs are blocking new executions
256
256
 
257
257
  ### Runs queued because a billing limit was reached
@@ -39,12 +39,12 @@ You can deploy using [GitHub Actions](/github-actions). We recommend that you lo
39
39
 
40
40
  <Steps>
41
41
  <Step title="Find your workflow file">
42
- In your `.githubs/workflows` folder you can find your workflow yml files. You may have a prod
42
+ In your `.github/workflows` folder you can find your workflow yml files. You may have a prod
43
43
  and staging one.
44
44
  </Step>
45
45
  <Step title="Update the version for the run command">
46
46
  In the steps you'll see a `run` command. It will run the trigger.dev deploy CLI command. Make
47
- sure to update this version to the latest version (e.g. `npx trigger.dev@3.0.0 deploy`).
47
+ sure to update this version to the latest version (e.g. `npx trigger.dev@4.7.3 deploy`).
48
48
  </Step>
49
49
  </Steps>
50
50
 
@@ -57,7 +57,7 @@ For example:
57
57
  ```json
58
58
  {
59
59
  "devDependencies": {
60
- "trigger.dev": "3.0.0"
60
+ "trigger.dev": "4.7.3"
61
61
  }
62
62
  }
63
63
  ```
@@ -129,7 +129,17 @@ The integration sets this up for you:
129
129
  - It passes your commit SHA as the deployment's external id.
130
130
  - `VERCEL_GIT_COMMIT_SHA` is available at runtime on Vercel, so the SDK finds the matching id with no work from you.
131
131
 
132
- There is nothing to enable, and it works in production, staging and preview alike. Nothing is gated: your Vercel deployment is never held back.
132
+ There is nothing to enable, and it works in production, staging and preview alike.
133
+
134
+ ### Production waits for your tasks
135
+
136
+ A production deployment from a push to the branch Trigger.dev builds for production gets a blocking **Trigger.dev Build** check. Vercel holds the deployment until the task build for the same commit finishes, then assigns your production domains as usual. If the task build fails or is canceled, the check fails and the Vercel deployment doesn't go live, so your app never ships against tasks that didn't build.
137
+
138
+ If no task build for the commit has started within 10 minutes, the check fails too.
139
+
140
+ To retry after a failed build, re-run the **Trigger.dev deployment** check on the commit in GitHub. Once that build succeeds, redeploy from Vercel or push a new commit.
141
+
142
+ A production deployment with no task build to wait for is never held: its check is marked skipped. That covers deployments from the Vercel CLI, from a branch that isn't your production branch in Trigger.dev, and from projects without a connected GitHub repository. Preview and staging deployments aren't held either: their check passes straight away, and version skew protection makes their runs wait for the matching task build instead.
133
143
 
134
144
  <Note>
135
145
  Version skew protection requires the `@trigger.dev/sdk` release that introduces external
@@ -146,8 +156,8 @@ To opt out, set `TRIGGER_AUTOMATIC_SKEW_VERSION_PROTECTION` to `0` on your Verce
146
156
  <Warning>
147
157
  **Automatic atomic deployments are deprecated.** Use [version skew
148
158
  protection](/deployment/atomic-deployment) instead — it needs no second Vercel deployment,
149
- never gates your app's deploy, doesn't touch `Auto-assign Custom Production Domains`, and covers
150
- staging and preview as well as production.
159
+ doesn't touch `Auto-assign Custom Production Domains`, and covers staging and preview as well as
160
+ production. Production deployments still wait for your task build through the blocking check.
151
161
 
152
162
  Nothing is being switched off. The setting stays in your project's Vercel settings, keeps working,
153
163
  and remains the way to hold your Vercel deployment back until your tasks have built. New
@@ -51,7 +51,7 @@ Because your application and your tasks deploy separately, a release of your app
51
51
 
52
52
  ## Retries and reattempts
53
53
 
54
- When a task has an uncaught error it will [retry](/errors-retrying), assuming you have not set `maxAttempts` to 0. Retries are locked to the original version of the run.
54
+ When a task has an uncaught error it will [retry](/errors-retrying), if the task has retries configured (the `retry` option or `retries.default` in your config). Retries are locked to the original version of the run.
55
55
 
56
56
  ## Replays
57
57
 
@@ -135,7 +135,7 @@ Create a waitpoint token.
135
135
  The `createToken` function accepts an object with the following properties:
136
136
 
137
137
  <ParamField query="timeout" type="string" optional>
138
- The maximum amount of time to wait for the token to be completed. Defaults to "10m".
138
+ The maximum amount of time to wait for the token to be completed. If omitted, the token has no timeout. Accepts a duration string like `"30s"` or `"4w"`, or a `Date`.
139
139
  </ParamField>
140
140
 
141
141
  <ParamField query="idempotencyKey" type="string" optional>
@@ -144,7 +144,7 @@ The `createToken` function accepts an object with the following properties:
144
144
  </ParamField>
145
145
 
146
146
  <ParamField query="idempotencyKeyTTL" type="string" optional>
147
- The time to live for the idempotency key. Defaults to "1h".
147
+ The time to live for the idempotency key. If omitted, the key does not expire.
148
148
  </ParamField>
149
149
 
150
150
  <ParamField query="tags" type="string[]" optional>
@@ -380,7 +380,7 @@ The `listTokens` function accepts an object with the following properties:
380
380
  </ParamField>
381
381
 
382
382
  <ParamField query="period" type="string" optional>
383
- The period to filter by. Can be one of: `1h`, `1d`, `7d`, `30d`.
383
+ The period to filter by, as a duration string such as `1h`, `1d`, `7d` or `30d`.
384
384
  </ParamField>
385
385
 
386
386
  <ParamField query="from" type="Date | number" optional>
@@ -0,0 +1,158 @@
1
+ ---
2
+ title: "Channels (chat frontends)"
3
+ description: "Point Slack (or any chat surface) at an agent: messages become turns and replies post back."
4
+ sidebarTitle: "Channels"
5
+ ---
6
+
7
+ import WebhooksBetaBanner from "/snippets/webhooks-beta-banner.mdx";
8
+
9
+ <WebhooksBetaBanner />
10
+
11
+ A [session route](/webhooks/session-routing) delivers a verified event to an agent as an [action](/ai-chat/actions): the agent reacts, and the response is a side effect. A **channel** is the other half: the webhook IS the chat surface. Inbound messages become **turns** (the normal `run()` loop), and the agent's reply is posted **back** to the surface. A Slack thread becomes a real conversation with the agent, exactly like the browser chat, just a different frontend.
12
+
13
+ List channels on a [`chat.agent`](/ai-chat/overview) alongside (or instead of) `events`:
14
+
15
+ ```ts
16
+ import { webhooks } from "@trigger.dev/sdk";
17
+ import { chat } from "@trigger.dev/sdk/ai";
18
+ import { appMentions, slack, webhookSource } from "@trigger.dev/slack";
19
+ import { anthropic } from "@ai-sdk/anthropic";
20
+
21
+ const slackEvents = webhooks.endpoint.define({ id: "slack", source: webhookSource() });
22
+
23
+ export const supportAgent = chat.agent({
24
+ id: "support-agent",
25
+ channels: [
26
+ slack({
27
+ id: "support-slack",
28
+ endpoint: slackEvents,
29
+ token: process.env.SLACK_BOT_TOKEN!,
30
+ startOn: appMentions(),
31
+ }),
32
+ ],
33
+ run: async ({ messages, streamText }) =>
34
+ streamText({ model: anthropic("claude-sonnet-4-5"), messages }),
35
+ });
36
+ ```
37
+
38
+ The `run()` loop is unchanged: the agent does not know or care that it is talking to Slack. One verified Slack message in a thread is routed to a durable [session](/ai-chat/sessions) keyed to that thread, run as a turn, and the reply is posted into the thread.
39
+
40
+ ## Slack
41
+
42
+ `slack()` from `@trigger.dev/slack` makes the agent a native Slack agent: the session shows its status, the reply streams into the thread with tool calls as task cards, approvals are buttons and Slack's stop button stops the turn. Shared images and PDFs reach the model, messages sent mid-reply can be folded into it, and the agent can post its own buttons. See [Slack agents](/webhooks/slack) for setup and options.
43
+
44
+ ## Linear
45
+
46
+ `linear()` from `@trigger.dev/linear` makes the agent a Linear agent: assign it an issue or @mention it and it works the issue inside Linear's agent session UI, with thoughts, actions, a plan and approvals. See [Linear agents](/webhooks/linear).
47
+
48
+ ## Approvals and interactive controls
49
+
50
+ An agent on a channel can pause a turn to get a human decision, approving a refund or confirming a deletion, and resume once someone clicks a button in the thread. `slack()` renders Approve and Deny buttons for you and collapses them to the decision once clicked; you can replace them, or give a tool its own UI whose click becomes the tool's result (see [Slack agents](/webhooks/slack#approvals-and-buttons)). See [human-in-the-loop](/webhooks/human-in-the-loop).
51
+
52
+ ## Any surface: `chat.channels.custom`
53
+
54
+ For a surface without a preset, `chat.channels.custom` is the generic connector. You supply the [endpoint](/webhooks/overview) it subscribes to, the session `key`, the `inbound` map, and the egress `send`:
55
+
56
+ ```ts
57
+ import { chat } from "@trigger.dev/sdk/ai";
58
+ import { webhooks } from "@trigger.dev/sdk";
59
+
60
+ const surface = webhooks.endpoint.define({
61
+ id: "my-surface",
62
+ source: webhooks.custom<MyEvent>({ /* verifier config */ }),
63
+ });
64
+
65
+ const mySurface = chat.channels.custom({
66
+ id: "my-surface",
67
+ endpoint: surface,
68
+ key: "{event.conversationId}",
69
+ inbound: (e) => e.text,
70
+ outbound: (reply) => (reply.text ? { text: reply.text } : null), // null posts nothing
71
+ send: async (message, ctx) => {
72
+ const ref = await postToMySurface(ctx.event, message.text, ctx.previousRef);
73
+ return { ref }; // later sends in the same turn get it back as ctx.previousRef
74
+ },
75
+ });
76
+ ```
77
+
78
+ `send` is called to post the reply. Within a turn, `ctx.previousRef` is the ref you returned from the turn's earlier `send` (the acknowledgement, or the message being streamed), so later sends edit that message instead of posting a new one. Each turn starts without a ref: the next turn's answer is a new message. Return `null` from `outbound` to stay silent (a tool-only turn, say).
79
+
80
+ An event that `inbound` maps to an empty message (no text, and no file or data parts) runs no turn. A click or system event your surface sends to the same endpoint is dropped rather than answered with an empty prompt.
81
+
82
+ List the connector in `chat.agent({ channels: [mySurface] })`, which subscribes the agent to the endpoint with the id `agentId:connectorId`. Other subscribers on the endpoint keep receiving its deliveries.
83
+
84
+ ## When a turn fails
85
+
86
+ When a turn fails (the model or provider returns an error, or the turn throws), the channel shows a short line instead of the error: "Something went wrong answering this. Try again." by default, or the connector's `errorMessage`. If the reply had partly streamed, the line goes after that text. The error is logged on the run, and `outbound` receives it as `reply.error`, so you can render a failure differently.
87
+
88
+ `errorMessage` is a fixed string, or a function that builds the line from the failure. It receives the `error`, the `partialText` streamed before it failed, the triggering `event` (undefined on a turn the channel didn't start), the `runId`, the `chatId`, and the `defaultMessage`. Return nothing, or throw, to fall back to the default line.
89
+
90
+ ```ts
91
+ slack({
92
+ id: "slack",
93
+ endpoint: slackEvents,
94
+ token: process.env.SLACK_BOT_TOKEN!,
95
+ startOn: appMentions(),
96
+ errorMessage: ({ error, runId }) =>
97
+ error.message.includes("rate limit")
98
+ ? "I'm getting a lot of requests right now. Try again in a minute."
99
+ : `Something went wrong answering this. Try again, or share ref ${runId} with support.`,
100
+ });
101
+ ```
102
+
103
+ ## Stopping a turn from the channel
104
+
105
+ A connector can map an event to a control with `onControl`. Returning `{ kind: "stop" }` while a turn is running aborts it through the run's `stopSignal`, exactly like the browser's stop button: the partial reply posts with `stopped: true` and the event is consumed instead of running as a turn. `linear()` and `slack()` map their stop buttons this way; a custom connector might map a `/stop` command:
106
+
107
+ ```ts
108
+ chat.channels.custom({
109
+ // ...
110
+ onControl: (e) => (e.text.trim() === "/stop" ? { kind: "stop" } : null),
111
+ });
112
+ ```
113
+
114
+ When nothing is running, the event is handled by `inbound` as an ordinary message. Return `whenIdle: "drop"` to consume it instead: no turn runs, and if the session is waiting on an [approval](/webhooks/human-in-the-loop) the pending tool calls are resolved as stopped and the connector's `cancelInteraction(cancelled, ctx)` takes the controls down (each cancelled call carries the `ref` its controls were posted with). Set `at` to when the user asked (epoch milliseconds), and a stop older than the latest turn is consumed without stopping it or cancelling that turn's approval, so a late or repeated delivery never stops the wrong turn. A stop pressed while the latest turn ran but delivered after it ended is consumed too, rather than handled as a message.
115
+
116
+ ## Status and native streaming
117
+
118
+ Two more hooks let a connector mirror the session into a surface that has its own notion of an agent, the way `slack()` does:
119
+
120
+ - `lifecycle(state, ctx)` reports `working` when a turn starts (and every 50 minutes while it runs), `waiting` when it pauses on a human decision, `idle` when it ends for any reason, and `closed` on `chat.close()`. `ctx.firstTurn` and `ctx.prompt` are there to title a new conversation. Calls are serialized, so an older report never lands after a newer one.
121
+ - `stream(ctx)`, with `delivery: "stream"`, returns a per-turn transport `{ text(delta), progress?(event), end(outcome) }`. The runtime feeds it the reply's markdown deltas and tool progress, then calls `end({ stopped, pending, errorText? })` once, with the connector's error line as `errorText` when the turn failed. Resolve `{ delivered: true }` when the reply reached the surface, and the runtime does not post it again. Call `ctx.opened(ref)` once the surface has created the stream message: the ref is saved with the session while the turn runs, and if the worker dies mid-stream the next one calls the connector's `endInterruptedStream(ref, ctx)` before it answers, so the old stream does not look like it is still being written.
122
+
123
+ ## Bound sessions
124
+
125
+ The first channel message binds the session to its connector and thread. From then on, any turn on that session posts its answer back through the same connector, including turns no channel delivery started: a [`chat.event`](/webhooks/session-routing#answering-into-a-channel) action that returns `chat.turn()`, or a message from a browser client sharing the session via [`chat.createWatchToken`](/ai-chat/reference). `slack()` binds to the team, channel, thread and the user it is answering; a custom connector opts in with `bind`:
126
+
127
+ ```ts
128
+ chat.channels.custom({
129
+ id: "my-surface",
130
+ endpoint: surface,
131
+ key: "{event.conversationId}",
132
+ inbound: (e) => ({ message: e.text, externalUserId: e.userId, externalMessageId: e.id }),
133
+ bind: (e) => ({ conversationId: e.conversationId }),
134
+ send: async (message, ctx) => {
135
+ // ctx.event is absent on a bound turn; ctx.handle always carries what bind() returned
136
+ const target = ctx.handle ?? { conversationId: ctx.event!.conversationId };
137
+ return { ref: await postToMySurface(target, message.text, ctx.previousRef) };
138
+ },
139
+ });
140
+ ```
141
+
142
+ `inbound` may return `{ message, externalUserId, externalMessageId }` as well as a plain string or `UIMessage`. The runtime stamps every channel-delivered user message with `metadata: { source: "channel", connectorId, provider, deliveryId, externalDeliveryId?, externalUserId?, externalMessageId? }` (`deliveryId` is the delivery's `whd_` id and `externalDeliveryId` the provider's), and a [transcript storage](/ai-chat/transcript-storage) receives `source: "channel"` and the `connectorId` on its save context, so a store you own can attribute and reconcile channel messages.
143
+
144
+ ## Files, buttons and steering
145
+
146
+ Three more hooks cover what a chat surface carries besides text:
147
+
148
+ - `download(url, { handle })` fetches files only the surface's credentials can read. Have `inbound` return file parts on the surface's URLs, and the `streamText` passed to `run()` asks each connector's `download` for every file URL in the prompt (return null for URLs it doesn't own). Downloads are cached for the run and the transcript keeps the URL. A file `download` throws on becomes a short note in that turn's messages, and the turn still runs.
149
+ - `toAction(event)` maps a click on a control the agent posted to an action. It reaches `onAction`, validated against `actionSchema`, with the click itself as `channel.event`. Returning `chat.turn(message)` answers in the bound thread. Return null for anything else, such as a click answering a pending tool call, which `onInteraction` handles.
150
+ - With [`pendingMessages`](/ai-chat/pending-messages) on the agent, a channel message that arrives while a turn is running goes through `inbound` and is offered to `shouldInject` like a browser message (its `metadata.source` is `"channel"`). Stops, clicks and empty messages are never offered.
151
+ - `received(ctx)` acknowledges a channel message that arrives while a turn is running, as soon as it arrives and whether or not `pendingMessages` folds it in, so its wording should be true either way: `slack()` reacts with 👀, `linear()` posts a thought. Stops, clicks and empty messages are not acknowledged.
152
+
153
+ ## Channels vs events
154
+
155
+ Both are inbound surfaces on a `chat.agent`, and an agent can list both:
156
+
157
+ - [`events`](/webhooks/session-routing) (`chat.event`): the webhook is a signal. Delivered to `onAction`; the agent acts, no reply is sent back.
158
+ - `channels` (`slack`, `chat.channels.custom`): the webhook is a chat frontend. Delivered as a turn to `run()`; the reply is posted back.
@@ -0,0 +1,84 @@
1
+ ---
2
+ title: "Connect a webhook provider"
3
+ description: "Register an endpoint's URL and signing secret with the provider, by hand or with an AI coding agent, then check that events arrive."
4
+ sidebarTitle: "Connect a provider"
5
+ ---
6
+
7
+ import WebhooksBetaBanner from "/snippets/webhooks-beta-banner.mdx";
8
+
9
+ <WebhooksBetaBanner />
10
+
11
+ Connect a provider to an [endpoint](/webhooks/overview) by registering the endpoint's URL with the provider and giving Trigger.dev the credential that verifies its requests.
12
+
13
+ Deploy the project or start `trigger dev` first. Once the CLI finds the endpoint, it appears on the environment's **Webhooks** page. The **Signing secret** column shows **Ready** when the endpoint can verify deliveries and **Needs secret** until then. Every delivery is rejected while an endpoint needs its secret.
14
+
15
+ ## Set it up with an AI agent
16
+
17
+ Each endpoint has a setup prompt: the URL, the events its subscribers filter on, the provider's own setup steps, and how to generate or store the signing secret. Choose **Copy setup prompt** on the Webhooks page or the endpoint's page, and paste it into an AI coding agent such as Claude Code.
18
+
19
+ The prompt tells the agent to use the Trigger.dev MCP server (`npx trigger.dev@latest install-mcp`), which has these tools:
20
+
21
+ | Tool | What it does |
22
+ | --- | --- |
23
+ | `list_webhook_endpoints` | Lists the environment's endpoints, with their URL and whether a secret is set. |
24
+ | `get_webhook_endpoint_details` | Reads one endpoint: URL, subscribers and their filters, secret state, and the setup prompt. |
25
+ | `generate_webhook_secret` | Generates a signing secret and returns it once, for providers where you choose the secret. |
26
+ | `set_webhook_secret` | Stores a secret the provider issued. |
27
+
28
+ Without the MCP server, the same operations are available on the REST API with the environment's secret key:
29
+
30
+ | Request | What it does |
31
+ | --- | --- |
32
+ | [`GET /api/v1/webhooks/endpoints`](/management/webhooks/list-endpoints) | Lists the environment's endpoints, with their URL and whether a secret is set. |
33
+ | [`GET /api/v1/webhooks/endpoints/{endpointId}`](/management/webhooks/retrieve-endpoint) | Reads the endpoint, including `subscribers` and `setupPrompt`. |
34
+ | [`POST /api/v1/webhooks/endpoints/{endpointId}/rotate-secret`](/management/webhooks/generate-secret) | Generates a secret and returns it once. |
35
+ | [`PUT /api/v1/webhooks/endpoints/{endpointId}/secret`](/management/webhooks/set-secret) | Stores a secret, sent as `{ "secret": "..." }`. |
36
+
37
+ `endpointId` is the endpoint's declared id (the `id` passed to `webhooks.endpoint.define`) or its `wh_` id, shown on its page and returned by `list_webhook_endpoints`:
38
+
39
+ ```bash
40
+ curl -X PUT "https://api.trigger.dev/api/v1/webhooks/endpoints/stripe/secret" \
41
+ -H "Authorization: Bearer $TRIGGER_SECRET_KEY" \
42
+ -H "Content-Type: application/json" \
43
+ -d '{"secret": "whsec_..."}'
44
+ ```
45
+
46
+ ## Set it up by hand
47
+
48
+ <Steps>
49
+ <Step title="Copy the webhook URL">
50
+ Open the endpoint from the Webhooks page and copy the **Webhook URL**.
51
+ </Step>
52
+ <Step title="Configure the provider">
53
+ Add the URL as the webhook destination in your provider's dashboard and select the events your subscribers need. The provider's setup determines where the verification credential comes from:
54
+
55
+ | Provider setup | Action |
56
+ | --- | --- |
57
+ | The provider supplies a signing secret, as Stripe and Svix do | Copy the secret from the provider, then choose **Set signing secret** on the endpoint. |
58
+ | The provider accepts a secret you choose, as GitHub does | Choose **Generate secret** on the endpoint, then paste the value into the provider's webhook configuration. |
59
+ | The provider uses an asymmetric signature, as Discord does | Copy the application's public key from the provider and choose **Set public key** on the endpoint. |
60
+
61
+ Set the credential before sending a test event or asking the provider to validate the URL.
62
+ </Step>
63
+ </Steps>
64
+
65
+ ## Verify the connection
66
+
67
+ Send a test event from your provider, or use the endpoint's **Test** tab. The event appears on the endpoint's **Deliveries** tab. Open it to see which subscribers it reached and follow the links to their runs; see [Deliveries and endpoints](/webhooks/deliveries) for the statuses.
68
+
69
+ If no delivery appears, check that the provider uses the copied URL and that both sides have the same signing secret or public key.
70
+
71
+ ## Verify a WhatsApp endpoint URL
72
+
73
+ `webhooks.whatsapp()` also needs a verify token for Meta's URL check. On the endpoint, choose **Generate verify token** and paste the value into Meta's **Verify Token** field. Set Meta's App Secret as the signing secret, then validate the URL in Meta's dashboard.
74
+
75
+ The verify token answers the URL check. The signing secret verifies event deliveries. See [Sources and verification](/webhooks/sources#endpoint-validation) for the response behavior.
76
+
77
+ ## Rotate a credential
78
+
79
+ Choose **Rotate signing secret** to replace a provider-supplied secret. For a secret you generate, choose **Regenerate secret**, copy the new value, and update the provider's configuration. Use **Rotate public key** when replacing an asymmetric provider's key.
80
+
81
+ <Warning>
82
+ Trigger.dev stores credentials encrypted and doesn't display saved values. Copy a generated secret
83
+ before closing the dialog. Deliveries signed with the old secret fail verification after rotation.
84
+ </Warning>
@@ -0,0 +1,103 @@
1
+ ---
2
+ title: "Deliveries and endpoints"
3
+ description: "Inspect webhook payloads, where each delivery went, and the runs it started or resumed."
4
+ sidebarTitle: "Deliveries and endpoints"
5
+ ---
6
+
7
+ import WebhooksBetaBanner from "/snippets/webhooks-beta-banner.mdx";
8
+
9
+ <WebhooksBetaBanner />
10
+
11
+ **A delivery records a verified webhook event and what happened to it at each subscriber.** Find deliveries on an endpoint's **Deliveries** tab. A run that a delivery triggered links back to it, and to its endpoint, from the run's **Detail** tab.
12
+
13
+ ## Endpoints
14
+
15
+ The environment's **Webhooks** page lists its endpoints with their URL, whether the signing secret is set, the last 24 hours of activity, and the last delivery. Open an endpoint for its tabs:
16
+
17
+ | Tab | Shows |
18
+ | --- | --- |
19
+ | **Deliveries** | The endpoint's deliveries, filterable by status and time. |
20
+ | **Subscribers** | Every task, agent session and channel subscribed to the endpoint, with each one's filter. |
21
+ | **Waiters** | Runs currently [waiting](/webhooks/waiters) on the endpoint. |
22
+ | **Test** | Sends a sample event through the endpoint. |
23
+
24
+ The endpoint's details show its URL, source, verification scheme and signing secret actions. See [Connect a provider](/webhooks/connect).
25
+
26
+ ### Disable an endpoint
27
+
28
+ Disable an endpoint to stop accepting its deliveries without removing it from your code. Its status becomes `inactive` and its URL responds with `404`, so the provider records failed deliveries and retries them on its own schedule:
29
+
30
+ ```bash
31
+ curl -X POST "https://api.trigger.dev/api/v1/webhooks/endpoints/stripe/disable" \
32
+ -H "Authorization: Bearer $TRIGGER_SECRET_KEY"
33
+ ```
34
+
35
+ [Enable](/management/webhooks/enable-endpoint) it again with `POST /api/v1/webhooks/endpoints/{endpointId}/enable`. An endpoint that is no longer in the environment's current deployment is also `inactive`.
36
+
37
+ ## Delivery status
38
+
39
+ | Status | Meaning |
40
+ | --- | --- |
41
+ | `PENDING` | Waiting to be routed, including after a retryable error at a subscriber. |
42
+ | `PROCESSING` | Being routed. A delivery that resumes many waiting runs stays here until they have all been resumed. |
43
+ | `SUCCEEDED` | At least one subscriber or waiting run received it, and nothing failed. |
44
+ | `FAILED` | A subscriber failed after its retries. The delivery's error names it. |
45
+ | `FILTERED` | No subscriber's filter matched, or the endpoint has no subscribers. The reason shows the failed clause. |
46
+ | `UNMATCHED` | Runs were waiting on the endpoint, but none matched and no subscriber took it. |
47
+
48
+ Delivery status tracks routing. Each run it started has its own status and retry history.
49
+
50
+ ## Where a delivery went
51
+
52
+ Open a delivery to see its payload and headers, and a row per subscriber with its result (`SUCCEEDED`, `FILTERED` with the reason, or `FAILED` with the error) and a link to the run it started. Waiting runs are summarized in one row: how many waiters matched, how many were resumed, and how many failed to resume.
53
+
54
+ A subscriber that fails transiently is retried on its own; subscribers that already succeeded are not run again.
55
+
56
+ ## Replay
57
+
58
+ Replaying a delivery routes its event again as a new delivery. Filters are checked again, so the replay reaches the subscribers that would take the event now:
59
+
60
+ ```bash
61
+ curl -X POST "https://api.trigger.dev/api/v1/webhooks/deliveries/whd_1234/replay" \
62
+ -H "Authorization: Bearer $TRIGGER_SECRET_KEY"
63
+ ```
64
+
65
+ Add `?targetId=` to send it to one subscriber regardless of its filter. `targetId` is the subscriber id: a `webhook()` task's id, or `agentId:eventId` for an agent's `chat.event` or channel. A replay never resumes waiting runs.
66
+
67
+ ## From an agent or the API
68
+
69
+ The [MCP server](/mcp-introduction) has `list_webhook_deliveries` (filter by endpoint, status and time), `get_webhook_delivery` (each subscriber's result, the waiter summary, the event and headers) and `replay_webhook_delivery`. The same data is on the REST API:
70
+
71
+ | Request | What it does |
72
+ | --- | --- |
73
+ | [`GET /api/v1/webhooks/deliveries`](/management/webhooks/list-deliveries) | Lists deliveries, newest first. Filter with `filter[endpoint]` (declared or `wh_` ids), `filter[status]`, and `filter[period]` or `filter[from]`/`filter[to]`. |
74
+ | [`GET /api/v1/webhooks/deliveries/{deliveryId}`](/management/webhooks/retrieve-delivery) | Reads a delivery, with a `targets` entry per subscriber and one for waiting runs. |
75
+ | [`POST /api/v1/webhooks/deliveries/{deliveryId}/replay`](/management/webhooks/replay-delivery) | Replays it, as above. The key needs permission to trigger every task the replay starts, and to write sessions if it reaches an agent's subscriber. |
76
+
77
+ ## Deduplication
78
+
79
+ Trigger.dev uses the endpoint and idempotency key to deduplicate incoming events. Delivery records and task runs have separate deduplication windows:
80
+
81
+ | What is deduplicated | Window |
82
+ | --- | --- |
83
+ | Delivery records | Six hours by default. |
84
+ | Task runs | Three days for Stripe; one day for other sources. |
85
+
86
+ A retry after the delivery window expires can create another delivery record. If the task-run idempotency window is still active, routing returns the existing run instead of starting another one.
87
+
88
+ When the source maps a provider event ID, that ID becomes the key, so the provider's own retries of an event are recognised as duplicates:
89
+
90
+ | Key | Sources |
91
+ | --- | --- |
92
+ | A header | GitHub (`X-GitHub-Delivery`), Svix and Autumn (`svix-id`), Standard Webhooks, Loops and Granola (`webhook-id`), Linear (`Linear-Delivery`), PagerDuty (`X-Webhook-Id`), Jira (`X-Atlassian-Webhook-Identifier`), Zendesk (`X-Zendesk-Webhook-Invocation-Id`), Attio (`Idempotency-Key`), Shopify (`X-Shopify-Webhook-Id`) |
93
+ | A body field | Stripe, Notion, Vercel, Intercom, WorkOS, Metronome, Mux, Langfuse and Plain (`id`), Square, Slack and Typeform (`event_id`), Firecrawl (`webhookId`) |
94
+
95
+ The other named sources (Zoom, Calendly, Sentry, DocuSign, ElevenLabs, Vapi, Retell, Tailscale, Infisical, PlanetScale, Supabase, Discord) use the fallback below.
96
+
97
+ If the source doesn't map an event ID, the key is derived from the raw body, timestamp, and signature. A retry with a different timestamp or signature can therefore produce a different key. For a [custom source](/webhooks/sources#custom-providers), set `idempotencyField` to a stable event identifier when the provider supplies one.
98
+
99
+ ## Verification and recording
100
+
101
+ Requests must pass the source's verification checks before they are recorded. Timestamp checks apply when configured by the source. A verification failure returns the source's rejected HTTP status (`400` by default) and creates no delivery or run.
102
+
103
+ Provider handshakes receive their configured response without creating a delivery. Other verified events are checked for duplicates, recorded, and routed. Filtered and unmatched deliveries stay visible, so you can see what arrived and why nothing ran.