@trigger.dev/sdk 4.7.4 → 4.7.6
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 +26 -0
- package/dist/commonjs/v3/ai.js +7 -5
- package/dist/commonjs/v3/ai.js.map +1 -1
- package/dist/commonjs/v3/query.d.ts +434 -1
- package/dist/commonjs/v3/query.js +115 -0
- package/dist/commonjs/v3/query.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/ai.d.ts +26 -0
- package/dist/esm/v3/ai.js +7 -5
- package/dist/esm/v3/ai.js.map +1 -1
- package/dist/esm/v3/query.d.ts +434 -1
- package/dist/esm/v3/query.js +115 -0
- package/dist/esm/v3/query.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/docs/ai-chat/actions.mdx +6 -1
- package/docs/ai-chat/backend.mdx +47 -0
- package/docs/ai-chat/patterns/redacting-telemetry.mdx +117 -0
- package/docs/ai-chat/pending-messages.mdx +2 -0
- package/docs/ai-chat/reference.mdx +53 -2
- package/docs/ai-chat/transcript-storage.mdx +1 -1
- package/docs/apikeys.mdx +6 -4
- package/docs/cli-runs-commands.mdx +2 -2
- package/docs/cli-tasks-commands.mdx +95 -0
- package/docs/config/config-file.mdx +58 -0
- package/docs/config/extensions/prismaExtension.mdx +4 -4
- package/docs/deploy-environment-variables.mdx +4 -0
- package/docs/deployment/atomic-deployment.mdx +3 -3
- package/docs/deployment/overview.mdx +1 -1
- package/docs/deployment/preview-branches.mdx +1 -1
- package/docs/github-actions.mdx +3 -3
- package/docs/limits.mdx +6 -0
- package/docs/manual-setup.mdx +1 -1
- package/docs/mcp-tools.mdx +99 -3
- package/docs/observability/dashboards.mdx +62 -0
- package/docs/runs/max-duration.mdx +4 -0
- package/docs/self-hosting/env/supervisor.mdx +1 -0
- package/docs/webhooks/channels.mdx +158 -0
- package/docs/webhooks/connect.mdx +84 -0
- package/docs/webhooks/deliveries.mdx +103 -0
- package/docs/webhooks/filters.mdx +150 -0
- package/docs/webhooks/human-in-the-loop.mdx +162 -0
- package/docs/webhooks/linear.mdx +190 -0
- package/docs/webhooks/overview.mdx +119 -0
- package/docs/webhooks/session-routing.mdx +145 -0
- package/docs/webhooks/slack.mdx +397 -0
- package/docs/webhooks/sources.mdx +224 -0
- package/docs/webhooks/waiters.mdx +194 -0
- package/package.json +3 -2
package/docs/mcp-tools.mdx
CHANGED
|
@@ -4,6 +4,8 @@ sidebarTitle: "Tools"
|
|
|
4
4
|
description: "Learn about how to use the tools available in the Trigger.dev MCP Server"
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
+
import WebhooksBetaNote from "/snippets/webhooks-beta-note.mdx";
|
|
8
|
+
|
|
7
9
|
## Documentation and Search Tools
|
|
8
10
|
|
|
9
11
|
### search_docs
|
|
@@ -189,7 +191,7 @@ Execute a TRQL query against your Trigger.dev data. TRQL is a SQL-style query la
|
|
|
189
191
|
|
|
190
192
|
### list_dashboards
|
|
191
193
|
|
|
192
|
-
List
|
|
194
|
+
List the built-in dashboards and your organization's custom dashboards, with their widgets.
|
|
193
195
|
|
|
194
196
|
**Example usage:**
|
|
195
197
|
- `"What dashboards are available?"`
|
|
@@ -197,12 +199,28 @@ List available built-in dashboards with their widgets. Each dashboard contains p
|
|
|
197
199
|
|
|
198
200
|
### run_dashboard_query
|
|
199
201
|
|
|
200
|
-
Execute a single widget query from a built-in dashboard. Use `list_dashboards` first to see available dashboards and widget IDs.
|
|
202
|
+
Execute a single widget query from a built-in or custom dashboard. Use `list_dashboards` first to see available dashboards and widget IDs.
|
|
201
203
|
|
|
202
204
|
**Example usage:**
|
|
203
205
|
- `"Run the total runs widget from the overview dashboard"`
|
|
204
206
|
- `"Show me the LLM cost over time from the AI dashboard"`
|
|
205
207
|
|
|
208
|
+
### create_dashboard
|
|
209
|
+
|
|
210
|
+
Create a custom dashboard, optionally with widgets. Each widget has a title, a TRQL query and a display: a table, a bar or line chart, a big number, or a section title. Queries are checked when the dashboard is saved.
|
|
211
|
+
|
|
212
|
+
**Example usage:**
|
|
213
|
+
- `"Make a dashboard for the email tasks with total runs, failures and runs per day"`
|
|
214
|
+
- `"Create a dashboard that charts p95 duration by task"`
|
|
215
|
+
|
|
216
|
+
### set_dashboard_widgets
|
|
217
|
+
|
|
218
|
+
Replace every widget on a custom dashboard, and optionally rename it.
|
|
219
|
+
|
|
220
|
+
**Example usage:**
|
|
221
|
+
- `"Add a failed runs widget to the email dashboard"`
|
|
222
|
+
- `"Change the runs per day chart to a line chart"`
|
|
223
|
+
|
|
206
224
|
### get_report
|
|
207
225
|
|
|
208
226
|
Render an interpreted [health report](/reports) — a deterministic verdict, not a raw panel — as text with sparklines. The `health` report answers whether work is flowing, whether the runs that start are healthy, and whether the telemetry is fresh, with a headline verdict and a suggested next action. Returns markdown by default, or ANSI when `color` is set. Read-only.
|
|
@@ -239,7 +257,7 @@ Check the status of the dev server and view recent output. Shows whether it is s
|
|
|
239
257
|
- `"Are there any build errors?"`
|
|
240
258
|
|
|
241
259
|
<Callout type="warning">
|
|
242
|
-
The deploy and list_preview_branches tools are not available when the MCP server is running with the `--dev-only` flag. The `--readonly` flag hides deploy, trigger_task, cancel_run, and
|
|
260
|
+
The deploy and list_preview_branches tools are not available when the MCP server is running with the `--dev-only` flag. The `--readonly` flag hides deploy, trigger_task, cancel_run, replay_run, create_dashboard, and set_dashboard_widgets.
|
|
243
261
|
</Callout>
|
|
244
262
|
|
|
245
263
|
## Agent Chat Tools
|
|
@@ -331,3 +349,81 @@ Append one record to a named side channel's `in` stream. Sends control input to
|
|
|
331
349
|
<Callout type="warning">
|
|
332
350
|
`write_session_channel` is a write operation and is not available in readonly mode.
|
|
333
351
|
</Callout>
|
|
352
|
+
|
|
353
|
+
## Webhook Tools
|
|
354
|
+
|
|
355
|
+
<WebhooksBetaNote />
|
|
356
|
+
|
|
357
|
+
Set up and debug [hosted webhook endpoints](/webhooks/overview). Endpoint ids start with `wh_` and delivery ids with `whd_`; endpoint tools also accept an endpoint's declared id. The same operations are on the [Webhooks API](/management/webhooks/list-endpoints).
|
|
358
|
+
|
|
359
|
+
### list_webhook_endpoints
|
|
360
|
+
|
|
361
|
+
List the environment's webhook endpoints: each one's id, declared id, source, status, URL and whether its signing secret is set.
|
|
362
|
+
|
|
363
|
+
**Example usage:**
|
|
364
|
+
- `"Which webhook endpoints do I have in dev?"`
|
|
365
|
+
|
|
366
|
+
### get_webhook_endpoint_details
|
|
367
|
+
|
|
368
|
+
Get an endpoint's subscribers, with the filters that decide which events each accepts, and its setup prompt: the steps for registering the endpoint and its signing secret with the provider.
|
|
369
|
+
|
|
370
|
+
**Parameters:**
|
|
371
|
+
- `endpointId` (required): the endpoint's declared id (such as `payments`) or `wh_` id
|
|
372
|
+
|
|
373
|
+
**Example usage:**
|
|
374
|
+
- `"Connect my payments webhook to Stripe"`
|
|
375
|
+
|
|
376
|
+
### list_webhook_deliveries
|
|
377
|
+
|
|
378
|
+
List recent deliveries, newest first.
|
|
379
|
+
|
|
380
|
+
**Parameters:**
|
|
381
|
+
- `endpointId` (optional): only this endpoint's deliveries, by declared id or `wh_` id
|
|
382
|
+
- `status` (optional): only these statuses, such as `["failed", "filtered"]`
|
|
383
|
+
- `period` (optional, default: `7d`): how far back to look
|
|
384
|
+
- `limit` (optional, default: `20`): how many to return, up to 100
|
|
385
|
+
- `cursor` (optional): the cursor from a previous call, for the next page
|
|
386
|
+
|
|
387
|
+
**Example usage:**
|
|
388
|
+
- `"Did the Stripe checkout event arrive in the last hour?"`
|
|
389
|
+
- `"Show me failed deliveries on the github endpoint"`
|
|
390
|
+
|
|
391
|
+
### get_webhook_delivery
|
|
392
|
+
|
|
393
|
+
Get one delivery: its status and error, each subscriber's result (the run or session it started, or why its filter skipped the event), how many waiting runs it resumed, and its event and headers.
|
|
394
|
+
|
|
395
|
+
**Parameters:**
|
|
396
|
+
- `deliveryId` (required): the delivery's `whd_` id
|
|
397
|
+
|
|
398
|
+
**Example usage:**
|
|
399
|
+
- `"Why didn't this webhook trigger my order task?"`
|
|
400
|
+
|
|
401
|
+
### replay_webhook_delivery
|
|
402
|
+
|
|
403
|
+
Replay a delivery from its stored event. Without `targetId` it goes to every subscriber again, with their filters checked again. With `targetId` it goes to that subscriber even if its filter skipped the event.
|
|
404
|
+
|
|
405
|
+
**Parameters:**
|
|
406
|
+
- `deliveryId` (required): the delivery's `whd_` id
|
|
407
|
+
- `targetId` (optional): the subscriber id to replay to
|
|
408
|
+
|
|
409
|
+
**Example usage:**
|
|
410
|
+
- `"Replay that delivery to the refunds task"`
|
|
411
|
+
|
|
412
|
+
### generate_webhook_secret
|
|
413
|
+
|
|
414
|
+
Generate a new signing secret for an endpoint and return it once, for providers where you choose the secret (such as GitHub). It replaces any existing secret.
|
|
415
|
+
|
|
416
|
+
**Parameters:**
|
|
417
|
+
- `endpointId` (required): the endpoint's declared id (such as `payments`) or `wh_` id
|
|
418
|
+
|
|
419
|
+
### set_webhook_secret
|
|
420
|
+
|
|
421
|
+
Store a signing secret or public key the provider issued, such as Stripe's `whsec_` secret. It replaces any existing secret.
|
|
422
|
+
|
|
423
|
+
**Parameters:**
|
|
424
|
+
- `endpointId` (required): the endpoint's declared id (such as `payments`) or `wh_` id
|
|
425
|
+
- `secret` (required): the secret or public key
|
|
426
|
+
|
|
427
|
+
<Callout type="warning">
|
|
428
|
+
`replay_webhook_delivery`, `generate_webhook_secret` and `set_webhook_secret` are write operations and are not available in readonly mode.
|
|
429
|
+
</Callout>
|
|
@@ -45,6 +45,68 @@ You can also filter the data by:
|
|
|
45
45
|
4. For charts you write [TRQL queries](/observability/query) and choose a visualization type.
|
|
46
46
|
5. You can resize and reposition widgets on your dashboards.
|
|
47
47
|
|
|
48
|
+
## Managing dashboards with the SDK
|
|
49
|
+
|
|
50
|
+
Custom dashboards can also be created and edited from code, so you can keep them in your repository and set them up from CI or a script. `query.dashboards` covers the same operations as the dashboard UI.
|
|
51
|
+
|
|
52
|
+
```ts scripts/dashboards.ts
|
|
53
|
+
import { query } from "@trigger.dev/sdk";
|
|
54
|
+
|
|
55
|
+
const dashboard = await query.dashboards.create({
|
|
56
|
+
title: "Email tasks",
|
|
57
|
+
widgets: [
|
|
58
|
+
{ title: "Overview", display: { type: "title" } },
|
|
59
|
+
{
|
|
60
|
+
title: "Total runs",
|
|
61
|
+
query: "SELECT count() AS total FROM runs WHERE task_identifier = 'send-email'",
|
|
62
|
+
display: { type: "bignumber", column: "total", aggregation: "sum" },
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
title: "Runs per day",
|
|
66
|
+
query:
|
|
67
|
+
"SELECT timeBucket(), count() AS runs FROM runs WHERE task_identifier = 'send-email' GROUP BY timeBucket ORDER BY timeBucket",
|
|
68
|
+
display: {
|
|
69
|
+
type: "chart",
|
|
70
|
+
chartType: "bar",
|
|
71
|
+
xAxisColumn: "timebucket",
|
|
72
|
+
yAxisColumns: ["runs"],
|
|
73
|
+
groupByColumn: null,
|
|
74
|
+
stacked: false,
|
|
75
|
+
sortByColumn: null,
|
|
76
|
+
sortDirection: "asc",
|
|
77
|
+
aggregation: "sum",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
console.log(dashboard.id); // dashboard_...
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Widgets without a `position` are stacked full width in the order you list them. Pass `position: { x, y, w, h }` on a 12-column grid to place a widget yourself.
|
|
87
|
+
|
|
88
|
+
To keep a dashboard in sync with code, replace all of its widgets in one call. Widgets you keep, matched by `id`, stay where they are unless you pass a new `position`:
|
|
89
|
+
|
|
90
|
+
```ts scripts/dashboards.ts
|
|
91
|
+
const current = await query.dashboards.retrieve(dashboard.id);
|
|
92
|
+
|
|
93
|
+
await query.dashboards.replace(dashboard.id, {
|
|
94
|
+
widgets: [
|
|
95
|
+
{
|
|
96
|
+
id: "failures",
|
|
97
|
+
title: "Failed runs",
|
|
98
|
+
query: "SELECT count() AS failed FROM runs WHERE status = 'Failed'",
|
|
99
|
+
display: { type: "bignumber", column: "failed", aggregation: "sum" },
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
revision: current.revision,
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`revision` is optional. When you pass the revision you last read, the write fails with a 409 if someone changed the dashboard in the meantime, instead of overwriting their change.
|
|
107
|
+
|
|
108
|
+
Every widget query is checked against the queryable tables when you save it, so a typo in a table or column name fails the request with the list of valid columns. `query.dashboards.widgets.add`, `widgets.update` and `widgets.del` change one widget at a time. Creating a dashboard or widget past your plan's limits returns a 403. See the [Query API reference](/management/query/create-dashboard) for every endpoint.
|
|
109
|
+
|
|
48
110
|
## Performance considerations
|
|
49
111
|
|
|
50
112
|
### Optimize queries for metrics
|
|
@@ -4,6 +4,10 @@ sidebarTitle: "Max duration"
|
|
|
4
4
|
description: "Set a maximum duration for a task to run."
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
+
Runs have no maximum duration. You set a default `maxDuration` for your project and can override it per task or per run, or set it to `timeout.None` to let a run execute indefinitely.
|
|
8
|
+
|
|
9
|
+
Trigger is built for long running AI agents and workflows and we have seen Trigger.dev users with runs lasting more than six months.
|
|
10
|
+
|
|
7
11
|
The `maxDuration` parameter sets a maximum compute time limit for tasks. When a task exceeds this duration, it will be automatically stopped. This helps prevent runaway tasks and manage compute resources effectively.
|
|
8
12
|
|
|
9
13
|
You must set a default maxDuration in your `trigger.config.ts` file, which will apply to all tasks unless overridden:
|
|
@@ -65,6 +65,7 @@ mode: "wide"
|
|
|
65
65
|
| `FAILED_POD_HANDLER_ENABLED` | No | true | Enable failed pod handler. |
|
|
66
66
|
| `FAILED_POD_HANDLER_RECONNECT_INTERVAL_MS` | No | 1000 (1s) | Failed pod handler reconnect interval (ms). |
|
|
67
67
|
| `FAILED_POD_HANDLER_WATCH_TIMEOUT_SECONDS` | No | 300 (5m) | How long the server keeps each failed pod watch open (s). |
|
|
68
|
+
| `RUNNER_KILL_REPORTS_ENABLED` | No | true | Fail a run straight away when its pod is killed, as out of memory only if Kubernetes reports `OOMKilled`. |
|
|
68
69
|
| **Debug** | | | |
|
|
69
70
|
| `DEBUG` | No | false | Enable debug logs. |
|
|
70
71
|
| `SEND_RUN_DEBUG_LOGS` | No | false | Send run debug logs to the platform. |
|
|
@@ -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.
|