@trigger.dev/sdk 4.5.0-rc.6 → 4.5.0-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/dist/commonjs/v3/ai.d.ts +171 -5
  2. package/dist/commonjs/v3/ai.js +309 -22
  3. package/dist/commonjs/v3/ai.js.map +1 -1
  4. package/dist/commonjs/v3/chat-server.d.ts +8 -0
  5. package/dist/commonjs/v3/chat-server.js +32 -10
  6. package/dist/commonjs/v3/chat-server.js.map +1 -1
  7. package/dist/commonjs/v3/chat-server.test.js +51 -0
  8. package/dist/commonjs/v3/chat-server.test.js.map +1 -1
  9. package/dist/commonjs/v3/createStartSessionAction.test.js +30 -0
  10. package/dist/commonjs/v3/createStartSessionAction.test.js.map +1 -1
  11. package/dist/commonjs/v3/sessions.d.ts +3 -2
  12. package/dist/commonjs/v3/sessions.js +3 -2
  13. package/dist/commonjs/v3/sessions.js.map +1 -1
  14. package/dist/commonjs/version.js +1 -1
  15. package/dist/esm/v3/ai.d.ts +171 -5
  16. package/dist/esm/v3/ai.js +309 -22
  17. package/dist/esm/v3/ai.js.map +1 -1
  18. package/dist/esm/v3/chat-server.d.ts +8 -0
  19. package/dist/esm/v3/chat-server.js +32 -10
  20. package/dist/esm/v3/chat-server.js.map +1 -1
  21. package/dist/esm/v3/chat-server.test.js +51 -0
  22. package/dist/esm/v3/chat-server.test.js.map +1 -1
  23. package/dist/esm/v3/createStartSessionAction.test.js +30 -0
  24. package/dist/esm/v3/createStartSessionAction.test.js.map +1 -1
  25. package/dist/esm/v3/sessions.d.ts +3 -2
  26. package/dist/esm/v3/sessions.js +3 -2
  27. package/dist/esm/v3/sessions.js.map +1 -1
  28. package/dist/esm/version.js +1 -1
  29. package/docs/ai/prompts.mdx +430 -0
  30. package/docs/ai-chat/actions.mdx +115 -0
  31. package/docs/ai-chat/anatomy.mdx +71 -0
  32. package/docs/ai-chat/backend.mdx +817 -0
  33. package/docs/ai-chat/background-injection.mdx +221 -0
  34. package/docs/ai-chat/changelog.mdx +850 -0
  35. package/docs/ai-chat/chat-local.mdx +174 -0
  36. package/docs/ai-chat/client-protocol.mdx +1081 -0
  37. package/docs/ai-chat/compaction.mdx +411 -0
  38. package/docs/ai-chat/custom-agents.mdx +364 -0
  39. package/docs/ai-chat/error-handling.mdx +415 -0
  40. package/docs/ai-chat/fast-starts.mdx +672 -0
  41. package/docs/ai-chat/frontend.mdx +580 -0
  42. package/docs/ai-chat/how-it-works.mdx +230 -0
  43. package/docs/ai-chat/lifecycle-hooks.mdx +530 -0
  44. package/docs/ai-chat/mcp.mdx +101 -0
  45. package/docs/ai-chat/overview.mdx +90 -0
  46. package/docs/ai-chat/patterns/branching-conversations.mdx +284 -0
  47. package/docs/ai-chat/patterns/code-sandbox.mdx +126 -0
  48. package/docs/ai-chat/patterns/database-persistence.mdx +414 -0
  49. package/docs/ai-chat/patterns/human-in-the-loop.mdx +275 -0
  50. package/docs/ai-chat/patterns/large-payloads.mdx +169 -0
  51. package/docs/ai-chat/patterns/oom-resilience.mdx +120 -0
  52. package/docs/ai-chat/patterns/persistence-and-replay.mdx +211 -0
  53. package/docs/ai-chat/patterns/recovery-boot.mdx +230 -0
  54. package/docs/ai-chat/patterns/skills.mdx +221 -0
  55. package/docs/ai-chat/patterns/sub-agents.mdx +383 -0
  56. package/docs/ai-chat/patterns/tool-result-auditing.mdx +148 -0
  57. package/docs/ai-chat/patterns/trusted-edge-signals.mdx +337 -0
  58. package/docs/ai-chat/patterns/version-upgrades.mdx +172 -0
  59. package/docs/ai-chat/pending-messages.mdx +343 -0
  60. package/docs/ai-chat/prompt-caching.mdx +206 -0
  61. package/docs/ai-chat/quick-start.mdx +161 -0
  62. package/docs/ai-chat/reference.mdx +909 -0
  63. package/docs/ai-chat/server-chat.mdx +263 -0
  64. package/docs/ai-chat/sessions.mdx +333 -0
  65. package/docs/ai-chat/testing.mdx +682 -0
  66. package/docs/ai-chat/tools.mdx +191 -0
  67. package/docs/ai-chat/types.mdx +242 -0
  68. package/docs/ai-chat/upgrade-guide.mdx +515 -0
  69. package/docs/apikeys.mdx +54 -0
  70. package/docs/building-with-ai.mdx +261 -0
  71. package/docs/bulk-actions.mdx +49 -0
  72. package/docs/changelog.mdx +6 -0
  73. package/docs/cli-deploy-commands.mdx +9 -0
  74. package/docs/cli-dev-commands.mdx +9 -0
  75. package/docs/cli-dev.mdx +8 -0
  76. package/docs/cli-init-commands.mdx +58 -0
  77. package/docs/cli-introduction.mdx +25 -0
  78. package/docs/cli-list-profiles-commands.mdx +42 -0
  79. package/docs/cli-login-commands.mdx +33 -0
  80. package/docs/cli-logout-commands.mdx +33 -0
  81. package/docs/cli-preview-archive.mdx +59 -0
  82. package/docs/cli-promote-commands.mdx +9 -0
  83. package/docs/cli-switch.mdx +43 -0
  84. package/docs/cli-update-commands.mdx +42 -0
  85. package/docs/cli-whoami-commands.mdx +33 -0
  86. package/docs/community.mdx +6 -0
  87. package/docs/config/config-file.mdx +602 -0
  88. package/docs/config/extensions/additionalFiles.mdx +38 -0
  89. package/docs/config/extensions/additionalPackages.mdx +40 -0
  90. package/docs/config/extensions/aptGet.mdx +34 -0
  91. package/docs/config/extensions/audioWaveform.mdx +20 -0
  92. package/docs/config/extensions/custom.mdx +380 -0
  93. package/docs/config/extensions/emitDecoratorMetadata.mdx +29 -0
  94. package/docs/config/extensions/esbuildPlugin.mdx +31 -0
  95. package/docs/config/extensions/ffmpeg.mdx +45 -0
  96. package/docs/config/extensions/lightpanda.mdx +56 -0
  97. package/docs/config/extensions/overview.mdx +67 -0
  98. package/docs/config/extensions/playwright.mdx +195 -0
  99. package/docs/config/extensions/prismaExtension.mdx +1014 -0
  100. package/docs/config/extensions/puppeteer.mdx +30 -0
  101. package/docs/config/extensions/pythonExtension.mdx +182 -0
  102. package/docs/config/extensions/syncEnvVars.mdx +291 -0
  103. package/docs/context.mdx +235 -0
  104. package/docs/database-connections.mdx +213 -0
  105. package/docs/deploy-environment-variables.mdx +435 -0
  106. package/docs/deployment/atomic-deployment.mdx +172 -0
  107. package/docs/deployment/overview.mdx +257 -0
  108. package/docs/deployment/preview-branches.mdx +224 -0
  109. package/docs/errors-retrying.mdx +379 -0
  110. package/docs/github-actions.mdx +222 -0
  111. package/docs/github-integration.mdx +136 -0
  112. package/docs/github-repo.mdx +8 -0
  113. package/docs/help-email.mdx +6 -0
  114. package/docs/help-slack.mdx +11 -0
  115. package/docs/hidden-tasks.mdx +56 -0
  116. package/docs/how-it-works.mdx +454 -0
  117. package/docs/how-to-reduce-your-spend.mdx +217 -0
  118. package/docs/idempotency.mdx +504 -0
  119. package/docs/introduction.mdx +223 -0
  120. package/docs/limits.mdx +241 -0
  121. package/docs/logging.mdx +195 -0
  122. package/docs/machines.mdx +952 -0
  123. package/docs/manual-setup.mdx +632 -0
  124. package/docs/mcp-agent-rules.mdx +41 -0
  125. package/docs/mcp-introduction.mdx +385 -0
  126. package/docs/mcp-tools.mdx +273 -0
  127. package/docs/migrating-from-v3.mdx +334 -0
  128. package/docs/observability/dashboards.mdx +102 -0
  129. package/docs/observability/query.mdx +585 -0
  130. package/docs/open-source-contributing.mdx +16 -0
  131. package/docs/open-source-self-hosting.mdx +541 -0
  132. package/docs/private-networking/aws-console-setup.mdx +304 -0
  133. package/docs/private-networking/overview.mdx +144 -0
  134. package/docs/private-networking/troubleshooting.mdx +78 -0
  135. package/docs/queue-concurrency.mdx +354 -0
  136. package/docs/quick-start.mdx +97 -0
  137. package/docs/realtime/auth.mdx +208 -0
  138. package/docs/realtime/backend/overview.mdx +45 -0
  139. package/docs/realtime/backend/streams.mdx +418 -0
  140. package/docs/realtime/backend/subscribe.mdx +225 -0
  141. package/docs/realtime/how-it-works.mdx +94 -0
  142. package/docs/realtime/overview.mdx +63 -0
  143. package/docs/realtime/react-hooks/overview.mdx +73 -0
  144. package/docs/realtime/react-hooks/streams.mdx +449 -0
  145. package/docs/realtime/react-hooks/subscribe.mdx +674 -0
  146. package/docs/realtime/react-hooks/swr.mdx +87 -0
  147. package/docs/realtime/react-hooks/triggering.mdx +194 -0
  148. package/docs/realtime/react-hooks/use-wait-token.mdx +34 -0
  149. package/docs/realtime/run-object.mdx +174 -0
  150. package/docs/replaying.mdx +72 -0
  151. package/docs/request-feature.mdx +6 -0
  152. package/docs/roadmap.mdx +6 -0
  153. package/docs/run-tests.mdx +20 -0
  154. package/docs/run-usage.mdx +113 -0
  155. package/docs/runs/heartbeats.mdx +38 -0
  156. package/docs/runs/max-duration.mdx +139 -0
  157. package/docs/runs/metadata.mdx +734 -0
  158. package/docs/runs/priority.mdx +31 -0
  159. package/docs/runs.mdx +396 -0
  160. package/docs/self-hosting/docker.mdx +458 -0
  161. package/docs/self-hosting/env/supervisor.mdx +74 -0
  162. package/docs/self-hosting/env/webapp.mdx +276 -0
  163. package/docs/self-hosting/kubernetes.mdx +601 -0
  164. package/docs/self-hosting/overview.mdx +108 -0
  165. package/docs/skills.mdx +85 -0
  166. package/docs/tags.mdx +120 -0
  167. package/docs/tasks/overview.mdx +697 -0
  168. package/docs/tasks/scheduled.mdx +382 -0
  169. package/docs/tasks/schemaTask.mdx +413 -0
  170. package/docs/tasks/streams.mdx +884 -0
  171. package/docs/triggering.mdx +1320 -0
  172. package/docs/troubleshooting-alerts.mdx +385 -0
  173. package/docs/troubleshooting-debugging-in-vscode.mdx +8 -0
  174. package/docs/troubleshooting-github-issues.mdx +6 -0
  175. package/docs/troubleshooting-uptime-status.mdx +6 -0
  176. package/docs/troubleshooting.mdx +398 -0
  177. package/docs/upgrading-packages.mdx +80 -0
  178. package/docs/vercel-integration.mdx +207 -0
  179. package/docs/versioning.mdx +56 -0
  180. package/docs/video-walkthrough.mdx +23 -0
  181. package/docs/wait-for-token.mdx +540 -0
  182. package/docs/wait-for.mdx +42 -0
  183. package/docs/wait-until.mdx +53 -0
  184. package/docs/wait.mdx +18 -0
  185. package/docs/writing-tasks-introduction.mdx +33 -0
  186. package/package.json +8 -5
  187. package/skills/trigger-authoring-chat-agent/SKILL.md +296 -0
  188. package/skills/trigger-authoring-tasks/SKILL.md +254 -0
  189. package/skills/trigger-chat-agent-advanced/SKILL.md +368 -0
  190. package/skills/trigger-cost-savings/SKILL.md +116 -0
  191. package/skills/trigger-realtime-and-frontend/SKILL.md +276 -0
@@ -0,0 +1,31 @@
1
+ ---
2
+ title: "Priority"
3
+ description: "Specify a priority when triggering a run."
4
+ ---
5
+
6
+ You can set a priority when you trigger a run. This allows you to prioritize some of your runs over others, so they are started sooner. This is very useful when:
7
+
8
+ - You have critical work that needs to start more quickly (and you have long queues).
9
+ - You want runs for your premium users to take priority over free users.
10
+
11
+ The value for priority is a time offset in seconds that determines the order of dequeuing.
12
+
13
+ ![Priority runs](/images/priority-runs.png)
14
+
15
+ If you specify a priority of `10` the run will dequeue before runs that were triggered with no priority 8 seconds ago, like in this example:
16
+
17
+ ```ts
18
+ // no priority = 0
19
+ await myTask.trigger({ foo: "bar" });
20
+
21
+ //... imagine 8s pass by
22
+
23
+ // this run will start before the run above that was triggered 8s ago (with no priority)
24
+ await myTask.trigger({ foo: "bar" }, { priority: 10 });
25
+ ```
26
+
27
+ If you passed a value of `3600` the run would dequeue before runs that were triggered an hour ago (with no priority).
28
+
29
+ <Note>
30
+ Setting a high priority will not allow you to beat runs from other organizations. It will only affect the order of your own runs.
31
+ </Note>
package/docs/runs.mdx ADDED
@@ -0,0 +1,396 @@
1
+ ---
2
+ title: "Runs"
3
+ description: "Understanding the lifecycle of task run execution in Trigger.dev"
4
+ ---
5
+
6
+ import RunBooleanHelpers from "/snippets/run-boolean-helpers.mdx";
7
+
8
+ In Trigger.dev, the concepts of runs and attempts are fundamental to understanding how tasks are executed and managed. This article explains these concepts in detail and provides insights into the various states a run can go through during its lifecycle.
9
+
10
+ ## What are runs?
11
+
12
+ A run is created when you trigger a task (e.g. calling `yourTask.trigger({ foo: "bar" })`). It represents a single instance of a task being executed and contains the following key information:
13
+
14
+ - A unique run ID
15
+ - The current status of the run
16
+ - The payload (input data) for the task
17
+ - Lots of other metadata
18
+
19
+ ## The run lifecycle
20
+
21
+ A run can go through **various** states during its lifecycle. The following diagram illustrates a typical state transition where a single run is triggered and completes successfully:
22
+
23
+ ![Run Lifecycle](/images/run-lifecycle.png)
24
+
25
+ Runs can also find themselves in lots of other states depending on what's happening at any given time. The following sections describe all the possible states in more detail.
26
+
27
+ ### Initial states
28
+
29
+ <Icon icon="rectangle-history" iconType="solid" color="#FBBF24" size={17} /> **Pending version**:
30
+ The task is waiting for a version update because it cannot execute without additional information (task, queue, etc.).
31
+
32
+ <Icon icon="clock" iconType="solid" color="#878C99" size={17} /> **Delayed**: When a run is triggered
33
+ with a delay, it enters this state until the specified delay period has passed.
34
+
35
+ <Icon icon="rectangle-history" iconType="solid" color="#878C99" size={17} /> **Queued**: The run is ready
36
+ to be executed and is waiting in the queue.
37
+
38
+ <Icon icon="rectangle-history" iconType="solid" color="#878C99" size={17} /> **Dequeued**: The task has been dequeued and is being sent to a worker to start executing.
39
+
40
+ ### Execution states
41
+
42
+ <Icon icon="spinner-third" iconType="duotone" color="#3B82F6" size={17} /> **Executing**: The task is
43
+ currently being executed by a worker.
44
+
45
+ <Icon icon="hourglass" iconType="solid" color="#878C99" size={17} /> **Waiting**: You have used a
46
+ [triggerAndWait()](/triggering#yourtask-triggerandwait), [batchTriggerAndWait()](/triggering#yourtask-batchtriggerandwait) or a [wait function](/wait). When the wait is complete, the task will resume execution.
47
+
48
+ ### Final states
49
+
50
+ <Icon icon="circle-check" iconType="solid" color="#28BF5C" size={17} /> **Completed**: The task has successfully
51
+ finished execution.
52
+
53
+ <Icon icon="ban" iconType="solid" color="#878C99" size={17} /> **Canceled**: The run was manually canceled
54
+ by the user.
55
+
56
+ <Icon icon="circle-xmark" iconType="solid" color="#E11D48" size={17} /> **Failed**: The task has failed
57
+ to complete successfully due to an error in the task code.
58
+
59
+ <Icon icon="alarm-exclamation" iconType="solid" color="#E11D48" size={17} /> **Timed out**: Task has
60
+ failed because it exceeded its `maxDuration`.
61
+
62
+ <Icon icon="fire" iconType="solid" color="#E11D48" size={17} /> **Crashed**: The worker process crashed
63
+ during execution (likely due to an Out of Memory error) and won’t be retried.
64
+
65
+ <Icon icon="bug" iconType="solid" color="#E11D48" size={17} /> **System failure**: An unrecoverable system
66
+ error has occurred.
67
+
68
+ <Icon icon="trash-can" iconType="solid" color="#878C99" size={17} /> **Expired**: The run's [Time-to-Live](#time-to-live-ttl)
69
+ (TTL) has passed before it could start executing.
70
+
71
+ ## Attempts
72
+
73
+ An attempt represents a single execution of a task within a run. A run can have one or more attempts, depending on the task's retry settings and whether it fails. Each attempt has:
74
+
75
+ - A unique attempt ID
76
+ - A status
77
+ - An output (if successful) or an error (if failed)
78
+
79
+ When a task fails, it will be retried according to its retry settings, creating new attempts until it either succeeds or reaches the retry limit.
80
+
81
+ ![Run with retries](/images/run-with-retries.png)
82
+
83
+ ## Run completion
84
+
85
+ A run is considered finished when:
86
+
87
+ 1. The last attempt succeeds, or
88
+ 2. The task has reached its retry limit and all attempts have failed
89
+
90
+ At this point, the run will have either an output (if successful) or an error (if failed).
91
+
92
+ ## Boolean helpers
93
+
94
+ Run objects returned from the API and Realtime include convenient boolean helper methods to check the run's status:
95
+
96
+ ```ts
97
+ import { runs } from "@trigger.dev/sdk";
98
+
99
+ const run = await runs.retrieve("run_1234");
100
+
101
+ if (run.isCompleted) {
102
+ console.log("Run completed successfully");
103
+ }
104
+ ```
105
+
106
+ <RunBooleanHelpers />
107
+
108
+ These helpers are also available when subscribing to Realtime run updates:
109
+
110
+ ```ts
111
+ import { runs } from "@trigger.dev/sdk";
112
+
113
+ for await (const run of runs.subscribeToRun("run_1234")) {
114
+ if (run.isCompleted) {
115
+ console.log("Run completed successfully!");
116
+ break;
117
+ }
118
+ }
119
+ ```
120
+
121
+ ## Advanced run features
122
+
123
+ ### Idempotency Keys
124
+
125
+ When triggering a task, you can provide an idempotency key to ensure the task is executed only once, even if triggered multiple times. This is useful for preventing duplicate executions in distributed systems.
126
+
127
+ ```ts
128
+ await yourTask.trigger({ foo: "bar" }, { idempotencyKey: "unique-key" });
129
+ ```
130
+
131
+ - If a run with the same idempotency key is already in progress, the new trigger will be ignored.
132
+ - If the run has already finished, the previous output or error will be returned.
133
+
134
+ See our [Idempotency docs](/idempotency) for more information.
135
+
136
+ ### Canceling runs
137
+
138
+ You can cancel an in-progress run using the API or the dashboard:
139
+
140
+ ```ts
141
+ await runs.cancel(runId);
142
+ ```
143
+
144
+ When a run is canceled:
145
+
146
+ – The task execution is stopped
147
+
148
+ – The run is marked as canceled
149
+
150
+ – The task will not be retried
151
+
152
+ – Any in-progress child runs are also canceled
153
+
154
+ ### Time-to-live (TTL)
155
+
156
+ TTL is a time-to-live setting that defines the maximum duration a run can remain in a queued state before being automatically expired. You can set a TTL at three levels, with the following precedence:
157
+
158
+ 1. **Per-trigger** (highest priority):
159
+
160
+ ```ts
161
+ await yourTask.trigger({ foo: "bar" }, { ttl: "10m" });
162
+ ```
163
+
164
+ 2. **Task-level default**:
165
+
166
+ ```ts
167
+ export const myTask = task({
168
+ id: "my-task",
169
+ ttl: "10m",
170
+ run: async (payload) => {
171
+ //...
172
+ },
173
+ });
174
+ ```
175
+
176
+ 3. **Global config default** (lowest priority):
177
+
178
+ ```ts trigger.config.ts
179
+ export default defineConfig({
180
+ project: "<project ref>",
181
+ ttl: "1h",
182
+ });
183
+ ```
184
+
185
+ To opt out of a config-level or task-level TTL for a specific trigger, pass `ttl: 0`:
186
+
187
+ ```ts
188
+ // This run will not have a TTL, even if the task or config defines one
189
+ await yourTask.trigger({ foo: "bar" }, { ttl: 0 });
190
+ ```
191
+
192
+ Similarly, to opt out of a config-level TTL for a specific task, set `ttl: 0` on the task definition:
193
+
194
+ ```ts
195
+ export const longRunningTask = task({
196
+ id: "long-running-task",
197
+ ttl: 0, // Opt out of the config-level TTL
198
+ run: async (payload) => {
199
+ //...
200
+ },
201
+ });
202
+ ```
203
+
204
+ <Note>
205
+ Setting `ttl: 0` removes the config-level or task-level TTL, but the platform-level maximum still applies. See [Limits - Maximum run TTL](/limits#maximum-run-ttl) for details.
206
+ </Note>
207
+
208
+ If the run hasn't started within the specified TTL, it will automatically expire, returning the status `Expired`. This is useful for time-sensitive tasks where immediate execution is important. For example, when you queue many runs simultaneously and exceed your concurrency limits, some runs might be delayed - using TTL ensures they only execute if they can start within your specified timeframe.
209
+
210
+ Dev runs automatically have a 10-minute TTL. On Trigger.dev Cloud, staging and production runs have a maximum TTL of 14 days applied automatically (runs without an explicit TTL get 14 days; longer TTLs are clamped). See [Limits — Maximum run TTL](/limits#maximum-run-ttl) for details.
211
+
212
+ ![Run with TTL](/images/run-with-ttl.png)
213
+
214
+ ### Delayed runs
215
+
216
+ You can schedule a run to start after a specified delay:
217
+
218
+ ```ts
219
+ await yourTask.trigger({ foo: "bar" }, { delay: "1h" });
220
+ ```
221
+
222
+ This is useful for tasks that need to be executed at a specific time in the future.
223
+
224
+ ![Run with delay](/images/run-with-delay.png)
225
+
226
+ ### Replaying runs
227
+
228
+ You can create a new run with the same payload as a previous run:
229
+
230
+ ```ts
231
+ await runs.replay(runId);
232
+ ```
233
+
234
+ This is useful for re-running a task with the same input, especially for debugging or recovering from failures. The new run will use the latest version of the task.
235
+
236
+ You can also replay runs from the dashboard using the same or different payload. Learn how to do this [here](/replaying).
237
+
238
+ ### Waiting for runs
239
+
240
+ #### triggerAndWait()
241
+
242
+ The `triggerAndWait()` function triggers a task and then lets you wait for the result before continuing. [Learn more about triggerAndWait()](/triggering#yourtask-triggerandwait).
243
+
244
+ ![Run with triggerAndWait](</images/run-with-triggerAndWait().png>)
245
+
246
+ #### batchTriggerAndWait()
247
+
248
+ Similar to `triggerAndWait()`, the `batchTriggerAndWait()` function lets you batch trigger a task and wait for all the results [Learn more about batchTriggerAndWait()](/triggering#yourtask-batchtriggerandwait).
249
+
250
+ ![Run with batchTriggerAndWait](</images/run-with-batchTriggerAndWait().png>)
251
+
252
+ ### Runs API
253
+
254
+ #### runs.list()
255
+
256
+ List runs in a specific environment. You can filter the runs by status, created at, task identifier, version, and more:
257
+
258
+ ```ts
259
+ import { runs } from "@trigger.dev/sdk";
260
+
261
+ // Get the first page of runs, returning up to 20 runs
262
+ let page = await runs.list({ limit: 20 });
263
+
264
+ for (const run of page.data) {
265
+ console.log(run);
266
+ }
267
+
268
+ // Keep getting the next page until there are no more runs
269
+ while (page.hasNextPage()) {
270
+ page = await page.getNextPage();
271
+ // Do something with the next page of runs
272
+ }
273
+ ```
274
+
275
+ You can also use an Async Iterator to get all runs:
276
+
277
+ ```ts
278
+ import { runs } from "@trigger.dev/sdk";
279
+
280
+ for await (const run of runs.list({ limit: 20 })) {
281
+ console.log(run);
282
+ }
283
+ ```
284
+
285
+ You can provide multiple filters to the `list()` function to narrow down the results:
286
+
287
+ ```ts
288
+ import { runs } from "@trigger.dev/sdk";
289
+
290
+ const response = await runs.list({
291
+ status: ["QUEUED", "EXECUTING"], // Filter by status
292
+ taskIdentifier: ["my-task", "my-other-task"], // Filter by task identifier
293
+ from: new Date("2024-04-01T00:00:00Z"), // Filter by created at
294
+ to: new Date(),
295
+ version: "20241127.2", // Filter by deployment version,
296
+ tag: ["tag1", "tag2"], // Filter by tags
297
+ batch: "batch_1234", // Filter by batch ID
298
+ schedule: "sched_1234", // Filter by schedule ID
299
+ });
300
+ ```
301
+
302
+ #### runs.retrieve()
303
+
304
+ Fetch a single run by it's ID:
305
+
306
+ ```ts
307
+ import { runs } from "@trigger.dev/sdk";
308
+
309
+ const run = await runs.retrieve(runId);
310
+ ```
311
+
312
+ You can provide the type of the task to correctly type the `run.payload` and `run.output`:
313
+
314
+ ```ts
315
+ import { runs } from "@trigger.dev/sdk";
316
+ import type { myTask } from "./trigger/myTask";
317
+
318
+ const run = await runs.retrieve<typeof myTask>(runId);
319
+
320
+ console.log(run.payload.foo); // string
321
+ console.log(run.output.bar); // string
322
+ ```
323
+
324
+ If you have just triggered a run, you can pass the entire response object to `retrieve()` and the response will already be typed:
325
+
326
+ ```ts
327
+ import { runs, tasks } from "@trigger.dev/sdk";
328
+ import type { myTask } from "./trigger/myTask";
329
+
330
+ const response = await tasks.trigger<typeof myTask>({ foo: "bar" });
331
+ const run = await runs.retrieve(response);
332
+
333
+ console.log(run.payload.foo); // string
334
+ console.log(run.output.bar); // string
335
+ ```
336
+
337
+ #### runs.cancel()
338
+
339
+ Cancel a run:
340
+
341
+ ```ts
342
+ import { runs } from "@trigger.dev/sdk";
343
+
344
+ await runs.cancel(runId);
345
+ ```
346
+
347
+ #### runs.replay()
348
+
349
+ Replay a run:
350
+
351
+ ```ts
352
+ import { runs } from "@trigger.dev/sdk";
353
+
354
+ await runs.replay(runId);
355
+ ```
356
+
357
+ #### runs.reschedule()
358
+
359
+ Updates a delayed run with a new delay. Only valid when the run is in the DELAYED state.
360
+
361
+ ```ts
362
+ import { runs } from "@trigger.dev/sdk";
363
+
364
+ await runs.reschedule(runId, { delay: "1h" });
365
+ ```
366
+
367
+ ### Real-time updates
368
+
369
+ Subscribe to changes to a specific run in real-time:
370
+
371
+ ```ts
372
+ import { runs } from "@trigger.dev/sdk";
373
+
374
+ for await (const run of runs.subscribeToRun(runId)) {
375
+ console.log(run);
376
+ }
377
+ ```
378
+
379
+ Similar to `runs.retrieve()`, you can provide the type of the task to correctly type the `run.payload` and `run.output`:
380
+
381
+ ```ts
382
+ import { runs } from "@trigger.dev/sdk";
383
+ import type { myTask } from "./trigger/myTask";
384
+
385
+ for await (const run of runs.subscribeToRun<typeof myTask>(runId)) {
386
+ console.log(run.payload.foo); // string
387
+ console.log(run.output?.bar); // string | undefined
388
+ }
389
+ ```
390
+
391
+ For more on real-time updates, see the [Realtime](/realtime) documentation.
392
+
393
+ ### Triggering runs for undeployed tasks
394
+
395
+ It's possible to trigger a run for a task that hasn't been deployed yet. The run will enter the "Waiting for deploy" state until the task is deployed. Once deployed, the run will be queued and executed normally.
396
+ This feature is particularly useful in CI/CD pipelines where you want to trigger tasks before the deployment is complete.