@trigger.dev/sdk 4.7.4 → 4.8.0-webhooks.20261015065339

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 (77) hide show
  1. package/dist/commonjs/v3/ai.d.ts +560 -8
  2. package/dist/commonjs/v3/ai.js +2263 -178
  3. package/dist/commonjs/v3/ai.js.map +1 -1
  4. package/dist/commonjs/v3/chat.d.ts +23 -0
  5. package/dist/commonjs/v3/chat.js.map +1 -1
  6. package/dist/commonjs/v3/index.d.ts +2 -0
  7. package/dist/commonjs/v3/index.js +23 -17
  8. package/dist/commonjs/v3/index.js.map +1 -1
  9. package/dist/commonjs/v3/modelFileDownload.d.ts +10 -0
  10. package/dist/commonjs/v3/modelFileDownload.js +164 -0
  11. package/dist/commonjs/v3/modelFileDownload.js.map +1 -0
  12. package/dist/commonjs/v3/test/index.d.ts +2 -1
  13. package/dist/commonjs/v3/test/index.js +4 -1
  14. package/dist/commonjs/v3/test/index.js.map +1 -1
  15. package/dist/commonjs/v3/test/mock-channel-connector.d.ts +172 -0
  16. package/dist/commonjs/v3/test/mock-channel-connector.js +173 -0
  17. package/dist/commonjs/v3/test/mock-channel-connector.js.map +1 -0
  18. package/dist/commonjs/v3/test/mock-chat-agent.d.ts +81 -1
  19. package/dist/commonjs/v3/test/mock-chat-agent.js +137 -10
  20. package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -1
  21. package/dist/commonjs/v3/transcriptStorage.d.ts +44 -1
  22. package/dist/commonjs/v3/transcriptStorage.js +24 -0
  23. package/dist/commonjs/v3/transcriptStorage.js.map +1 -1
  24. package/dist/commonjs/v3/webhookWaiters.d.ts +80 -0
  25. package/dist/commonjs/v3/webhookWaiters.js +156 -0
  26. package/dist/commonjs/v3/webhookWaiters.js.map +1 -0
  27. package/dist/commonjs/v3/webhooks.d.ts +178 -2
  28. package/dist/commonjs/v3/webhooks.js +322 -1
  29. package/dist/commonjs/v3/webhooks.js.map +1 -1
  30. package/dist/commonjs/version.js +1 -1
  31. package/dist/esm/v3/ai.d.ts +560 -8
  32. package/dist/esm/v3/ai.js +2257 -178
  33. package/dist/esm/v3/ai.js.map +1 -1
  34. package/dist/esm/v3/chat.d.ts +23 -0
  35. package/dist/esm/v3/chat.js.map +1 -1
  36. package/dist/esm/v3/index.d.ts +2 -0
  37. package/dist/esm/v3/index.js +1 -0
  38. package/dist/esm/v3/index.js.map +1 -1
  39. package/dist/esm/v3/modelFileDownload.d.ts +10 -0
  40. package/dist/esm/v3/modelFileDownload.js +161 -0
  41. package/dist/esm/v3/modelFileDownload.js.map +1 -0
  42. package/dist/esm/v3/test/index.d.ts +2 -1
  43. package/dist/esm/v3/test/index.js +2 -1
  44. package/dist/esm/v3/test/index.js.map +1 -1
  45. package/dist/esm/v3/test/mock-channel-connector.d.ts +172 -0
  46. package/dist/esm/v3/test/mock-channel-connector.js +170 -0
  47. package/dist/esm/v3/test/mock-channel-connector.js.map +1 -0
  48. package/dist/esm/v3/test/mock-chat-agent.d.ts +81 -1
  49. package/dist/esm/v3/test/mock-chat-agent.js +137 -11
  50. package/dist/esm/v3/test/mock-chat-agent.js.map +1 -1
  51. package/dist/esm/v3/transcriptStorage.d.ts +44 -1
  52. package/dist/esm/v3/transcriptStorage.js +24 -0
  53. package/dist/esm/v3/transcriptStorage.js.map +1 -1
  54. package/dist/esm/v3/webhookWaiters.d.ts +80 -0
  55. package/dist/esm/v3/webhookWaiters.js +149 -0
  56. package/dist/esm/v3/webhookWaiters.js.map +1 -0
  57. package/dist/esm/v3/webhooks.d.ts +178 -2
  58. package/dist/esm/v3/webhooks.js +318 -1
  59. package/dist/esm/v3/webhooks.js.map +1 -1
  60. package/dist/esm/version.js +1 -1
  61. package/docs/ai-chat/actions.mdx +6 -1
  62. package/docs/ai-chat/backend.mdx +34 -0
  63. package/docs/ai-chat/pending-messages.mdx +2 -0
  64. package/docs/ai-chat/reference.mdx +50 -2
  65. package/docs/mcp-tools.mdx +76 -0
  66. package/docs/webhooks/channels.mdx +128 -0
  67. package/docs/webhooks/connect.mdx +80 -0
  68. package/docs/webhooks/deliveries.mdx +92 -0
  69. package/docs/webhooks/filters.mdx +109 -0
  70. package/docs/webhooks/human-in-the-loop.mdx +149 -0
  71. package/docs/webhooks/linear.mdx +185 -0
  72. package/docs/webhooks/overview.mdx +99 -0
  73. package/docs/webhooks/session-routing.mdx +132 -0
  74. package/docs/webhooks/slack.mdx +360 -0
  75. package/docs/webhooks/sources.mdx +217 -0
  76. package/docs/webhooks/waiters.mdx +170 -0
  77. package/package.json +3 -2
@@ -0,0 +1,170 @@
1
+ ---
2
+ title: "Waiting for a webhook"
3
+ description: "Pause a run until a matching webhook arrives on an endpoint, then resume it with the verified event."
4
+ sidebarTitle: "Waiters"
5
+ ---
6
+
7
+ **A waiter pauses a run until a matching delivery arrives on an [endpoint](/webhooks/overview).** Use it when your task starts something in another system and needs to know when that system reports back: a payment that settles, a build that finishes, a document that gets signed.
8
+
9
+ ```ts /trigger/checkout.ts
10
+ import { task, webhooks } from "@trigger.dev/sdk";
11
+ import { stripe } from "./stripe"; // webhooks.endpoint.define({ id: "stripe", source: webhooks.stripe() })
12
+
13
+ export const checkout = task({
14
+ id: "checkout",
15
+ run: async ({ orderId }: { orderId: string }) => {
16
+ const waiter = await webhooks.waiter.create(stripe, {
17
+ match: {
18
+ "event.type": "payment_intent.succeeded",
19
+ "event.data.object.metadata.orderId": orderId,
20
+ },
21
+ timeout: "1h",
22
+ // the same waiter (and its event) if this run is retried
23
+ idempotencyKey: `payment-${orderId}`,
24
+ });
25
+
26
+ await stripeClient.paymentIntents.create({ amount: 4200, currency: "usd", metadata: { orderId } });
27
+
28
+ const { event, deliveryId } = await webhooks.waiter.wait(waiter).unwrap();
29
+ return { paymentIntent: event.data.object.id, deliveryId };
30
+ },
31
+ });
32
+ ```
33
+
34
+ While the run waits it is suspended, so it uses no compute. The endpoint's other subscribers still receive the delivery.
35
+
36
+ ## Create before you act
37
+
38
+ A waiter only matches deliveries that arrive after it was created. Create it before the call that makes the provider send the webhook, as above, or a fast provider can deliver the event before anything is waiting for it.
39
+
40
+ Match on values you control, such as your own order id in the provider object's metadata. Two runs waiting for the same values are both resumed by the delivery.
41
+
42
+ ## Matching
43
+
44
+ `match` maps paths to the scalar each must equal. Paths use the same namespaces as a [filter](/webhooks/filters):
45
+
46
+ | Path | Reads |
47
+ | --- | --- |
48
+ | `event.*` | The verified event body, for example `event.data.object.id`. |
49
+ | `header.*` | A request header, matched case-insensitively, for example `header.x-shop-domain`. |
50
+ | `webhook.*` | The endpoint: `id`, `source`, `externalRef`, `tenantId`, or `deliveryId`. |
51
+
52
+ A waiter can match up to five paths, and each value is a string, number or boolean. Paths are checked against the endpoint's event type at build time: an unknown field on a typed event, a path to an object, or a path without a namespace is a type error. The API refuses the same paths at create time.
53
+
54
+ For conditions that aren't equality, add a `filter`. It is checked after `match`:
55
+
56
+ ```ts
57
+ await webhooks.waiter.create(stripe, {
58
+ match: { "event.data.object.metadata.orderId": orderId },
59
+ filter: "event.type in ['payment_intent.succeeded', 'payment_intent.payment_failed']",
60
+ });
61
+ ```
62
+
63
+ ## The result
64
+
65
+ `webhooks.waiter.wait(waiter)` returns a result you can check, and `.unwrap()` returns the output or throws:
66
+
67
+ ```ts
68
+ const result = await webhooks.waiter.wait(waiter);
69
+ if (result.ok) {
70
+ console.log(result.output.event, result.output.headers, result.output.endpoint);
71
+ } else {
72
+ console.log(result.error.name); // "WaitpointTimeoutError" or "WebhookWaiterCancelledError"
73
+ }
74
+ ```
75
+
76
+ | Output field | Value |
77
+ | --- | --- |
78
+ | `event` | The verified event body, typed by the endpoint's source. |
79
+ | `headers` | The request headers, with credentials such as signatures removed. |
80
+ | `deliveryId` | The delivery that resumed the run (`whd_...`). |
81
+ | `endpoint` | The endpoint the delivery arrived on. |
82
+
83
+ `timeout` accepts a duration such as `"30m"` or a `Date`. It defaults to 24 hours and can be up to 90 days. A waiter that times out fails the wait with `WaitpointTimeoutError`.
84
+
85
+ A waiter is a [waitpoint](/wait-for-token): its id starts with `waitpoint_` and it is tagged `webhook:<endpoint id>` plus any `tags` you pass (up to 10).
86
+
87
+ ## Providers that take a callback URL
88
+
89
+ Some providers accept a webhook URL per request instead of one account-wide URL, such as Replicate's `webhook` parameter. Omit `match` and the waiter gets its own URL:
90
+
91
+ ```ts
92
+ const waiter = await webhooks.waiter.create(replicateEndpoint, { timeout: "2h" });
93
+
94
+ await replicate.predictions.create({ version, input, webhook: waiter.url });
95
+
96
+ const { event } = await webhooks.waiter.wait(waiter).unwrap();
97
+ ```
98
+
99
+ A delivery to `waiter.url` is verified with the endpoint's source, resumes only that waiter, and is not sent to the endpoint's subscribers.
100
+
101
+ ## Creating from your backend
102
+
103
+ `webhooks.waiter.create` also works outside a run, for example in the API route that starts a checkout. Pass the waiter, or its id, to a task that waits on it:
104
+
105
+ ```ts
106
+ const waiter = await webhooks.waiter.create(stripe, { match: { "event.data.object.metadata.orderId": orderId } });
107
+ await fulfillWhenPaid.trigger({ waiterId: waiter.id });
108
+ ```
109
+
110
+ ```ts
111
+ export const fulfillWhenPaid = task({
112
+ id: "fulfill-when-paid",
113
+ run: async ({ waiterId }: { waiterId: string }) => {
114
+ const { event } = await webhooks.waiter.wait(waiterId).unwrap();
115
+ },
116
+ });
117
+ ```
118
+
119
+ The same operations are on the REST API: [`POST /api/v1/webhooks/endpoints/{endpointId}/waiters`](/management/webhooks/create-waiter) with `match`, `filter`, `timeout`, `tags` and `idempotencyKey`, and [`POST /api/v1/webhooks/waiters/{waiterId}/cancel`](/management/webhooks/cancel-waiter). `endpointId` is the endpoint's declared id or its `wh_` id.
120
+
121
+ ## Retries and idempotency
122
+
123
+ Pass an `idempotencyKey` so a task can be retried without losing its webhook. A create with a key it has seen returns the original waiter, with `isCached: true`, even if it has already completed, and waiting on a completed waiter returns its event straight away. Inside a task a string key is scoped to the run, as it is for [`trigger()`](/idempotency), so a retried attempt gets the waiter (and the event) the attempt before it created:
124
+
125
+ ```ts
126
+ const waiter = await webhooks.waiter.create(stripe, {
127
+ match: { "event.data.object.metadata.orderId": orderId },
128
+ idempotencyKey: `payment-${orderId}`,
129
+ });
130
+ ```
131
+
132
+ Use [`idempotencyKeys.create(key, { scope })`](/idempotency) for a key scoped to one attempt or shared across runs, and `idempotencyKeyTTL` to set how long the key lasts.
133
+
134
+ Without a key every call creates a new waiter, and a waiter only matches deliveries that arrive after it. If an attempt fails after its webhook arrived, the retry's new waiter waits for an event the provider already sent.
135
+
136
+ ## Cancelling
137
+
138
+ `webhooks.waiter.cancel(waiter)` frees the waiter's slot and fails its wait with `WebhookWaiterCancelledError`. If a delivery has already claimed the waiter, the cancel is too late and the run resumes with that delivery:
139
+
140
+ ```ts
141
+ const result = await webhooks.waiter.cancel(waiter);
142
+ if (!result.cancelled) {
143
+ console.log("Already resumed by", result.deliveryId); // result.reason is "too_late"
144
+ }
145
+ ```
146
+
147
+ ## Errors
148
+
149
+ `webhooks.waiter.create` throws a typed error when nothing was created:
150
+
151
+ | Error | Cause |
152
+ | --- | --- |
153
+ | `WebhookWaiterLimitError` | A limit was reached. `reason` is `endpoint_limit`, `environment_limit`, `shape_limit` or `timeout_too_long`. |
154
+ | `WebhookEndpointNotFoundError` | The endpoint isn't in the environment's current deployment. |
155
+ | `WebhookFilterError` | The `filter` doesn't parse. |
156
+
157
+ ## Limits
158
+
159
+ | Limit | Default |
160
+ | --- | --- |
161
+ | Live waiters per endpoint | 10,000. This is also the most one delivery can resume. |
162
+ | Live waiters per environment | 1,000,000 on self-hosted installs. |
163
+ | Distinct sets of `match` paths per endpoint | 25 |
164
+ | Paths per `match` | 5 |
165
+ | Tags per waiter | 10 |
166
+ | Timeout | 24 hours by default, 90 days at most |
167
+
168
+ On Trigger.dev Cloud the per-endpoint and per-environment limits depend on your plan. Self-hosted installs can change them with `WEBHOOK_WAITER_MAX_PER_ENDPOINT`, `WEBHOOK_WAITER_MAX_PER_ENVIRONMENT` and `WEBHOOK_WAITER_MAX_SHAPES`.
169
+
170
+ A delivery that resumes waiters shows one **Waiting runs** row on its [delivery page](/webhooks/deliveries#where-a-delivery-went) with how many matched, resumed and failed. A delivery that arrives while runs are waiting but matches none of them, and no subscriber takes, is `UNMATCHED`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trigger.dev/sdk",
3
- "version": "4.7.4",
3
+ "version": "4.8.0-webhooks.20261015065339",
4
4
  "description": "trigger.dev Node.JS SDK",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -69,7 +69,7 @@
69
69
  "dependencies": {
70
70
  "@opentelemetry/api": "1.9.1",
71
71
  "@opentelemetry/semantic-conventions": "1.41.1",
72
- "@trigger.dev/core": "4.7.4",
72
+ "@trigger.dev/core": "4.8.0-webhooks.20261015065339",
73
73
  "uncrypto": "^0.1.3"
74
74
  },
75
75
  "devDependencies": {
@@ -79,6 +79,7 @@
79
79
  "ai": "^6.0.116",
80
80
  "ai-v7": "npm:ai@7.0.0-canary.159",
81
81
  "rimraf": "^6.0.1",
82
+ "stripe": "23.0.0",
82
83
  "tshy": "^4.1.3",
83
84
  "tsx": "4.17.0",
84
85
  "typescript": "7.0.2",