@trigger.dev/sdk 4.5.0-rc.5 → 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 (213) hide show
  1. package/dist/commonjs/v3/ai.d.ts +178 -5
  2. package/dist/commonjs/v3/ai.js +603 -119
  3. package/dist/commonjs/v3/ai.js.map +1 -1
  4. package/dist/commonjs/v3/chat-client.js +3 -0
  5. package/dist/commonjs/v3/chat-client.js.map +1 -1
  6. package/dist/commonjs/v3/chat-react.js +10 -7
  7. package/dist/commonjs/v3/chat-react.js.map +1 -1
  8. package/dist/commonjs/v3/chat-server.d.ts +8 -0
  9. package/dist/commonjs/v3/chat-server.js +32 -10
  10. package/dist/commonjs/v3/chat-server.js.map +1 -1
  11. package/dist/commonjs/v3/chat-server.test.js +51 -0
  12. package/dist/commonjs/v3/chat-server.test.js.map +1 -1
  13. package/dist/commonjs/v3/chat.js +34 -6
  14. package/dist/commonjs/v3/chat.js.map +1 -1
  15. package/dist/commonjs/v3/chat.test.js +53 -0
  16. package/dist/commonjs/v3/chat.test.js.map +1 -1
  17. package/dist/commonjs/v3/createStartSessionAction.test.js +30 -0
  18. package/dist/commonjs/v3/createStartSessionAction.test.js.map +1 -1
  19. package/dist/commonjs/v3/sessions.d.ts +11 -6
  20. package/dist/commonjs/v3/sessions.js +10 -5
  21. package/dist/commonjs/v3/sessions.js.map +1 -1
  22. package/dist/commonjs/v3/test/mock-chat-agent.d.ts +6 -0
  23. package/dist/commonjs/v3/test/mock-chat-agent.js +1 -0
  24. package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -1
  25. package/dist/commonjs/version.js +1 -1
  26. package/dist/esm/v3/ai.d.ts +178 -5
  27. package/dist/esm/v3/ai.js +603 -120
  28. package/dist/esm/v3/ai.js.map +1 -1
  29. package/dist/esm/v3/chat-client.js +3 -0
  30. package/dist/esm/v3/chat-client.js.map +1 -1
  31. package/dist/esm/v3/chat-react.js +10 -7
  32. package/dist/esm/v3/chat-react.js.map +1 -1
  33. package/dist/esm/v3/chat-server.d.ts +8 -0
  34. package/dist/esm/v3/chat-server.js +32 -10
  35. package/dist/esm/v3/chat-server.js.map +1 -1
  36. package/dist/esm/v3/chat-server.test.js +51 -0
  37. package/dist/esm/v3/chat-server.test.js.map +1 -1
  38. package/dist/esm/v3/chat.js +34 -6
  39. package/dist/esm/v3/chat.js.map +1 -1
  40. package/dist/esm/v3/chat.test.js +53 -0
  41. package/dist/esm/v3/chat.test.js.map +1 -1
  42. package/dist/esm/v3/createStartSessionAction.test.js +30 -0
  43. package/dist/esm/v3/createStartSessionAction.test.js.map +1 -1
  44. package/dist/esm/v3/sessions.d.ts +11 -6
  45. package/dist/esm/v3/sessions.js +10 -5
  46. package/dist/esm/v3/sessions.js.map +1 -1
  47. package/dist/esm/v3/test/mock-chat-agent.d.ts +6 -0
  48. package/dist/esm/v3/test/mock-chat-agent.js +1 -0
  49. package/dist/esm/v3/test/mock-chat-agent.js.map +1 -1
  50. package/dist/esm/version.js +1 -1
  51. package/docs/ai/prompts.mdx +430 -0
  52. package/docs/ai-chat/actions.mdx +115 -0
  53. package/docs/ai-chat/anatomy.mdx +71 -0
  54. package/docs/ai-chat/backend.mdx +817 -0
  55. package/docs/ai-chat/background-injection.mdx +221 -0
  56. package/docs/ai-chat/changelog.mdx +850 -0
  57. package/docs/ai-chat/chat-local.mdx +174 -0
  58. package/docs/ai-chat/client-protocol.mdx +1081 -0
  59. package/docs/ai-chat/compaction.mdx +411 -0
  60. package/docs/ai-chat/custom-agents.mdx +364 -0
  61. package/docs/ai-chat/error-handling.mdx +415 -0
  62. package/docs/ai-chat/fast-starts.mdx +672 -0
  63. package/docs/ai-chat/frontend.mdx +580 -0
  64. package/docs/ai-chat/how-it-works.mdx +230 -0
  65. package/docs/ai-chat/lifecycle-hooks.mdx +530 -0
  66. package/docs/ai-chat/mcp.mdx +101 -0
  67. package/docs/ai-chat/overview.mdx +90 -0
  68. package/docs/ai-chat/patterns/branching-conversations.mdx +284 -0
  69. package/docs/ai-chat/patterns/code-sandbox.mdx +126 -0
  70. package/docs/ai-chat/patterns/database-persistence.mdx +414 -0
  71. package/docs/ai-chat/patterns/human-in-the-loop.mdx +275 -0
  72. package/docs/ai-chat/patterns/large-payloads.mdx +169 -0
  73. package/docs/ai-chat/patterns/oom-resilience.mdx +120 -0
  74. package/docs/ai-chat/patterns/persistence-and-replay.mdx +211 -0
  75. package/docs/ai-chat/patterns/recovery-boot.mdx +230 -0
  76. package/docs/ai-chat/patterns/skills.mdx +221 -0
  77. package/docs/ai-chat/patterns/sub-agents.mdx +383 -0
  78. package/docs/ai-chat/patterns/tool-result-auditing.mdx +148 -0
  79. package/docs/ai-chat/patterns/trusted-edge-signals.mdx +337 -0
  80. package/docs/ai-chat/patterns/version-upgrades.mdx +172 -0
  81. package/docs/ai-chat/pending-messages.mdx +343 -0
  82. package/docs/ai-chat/prompt-caching.mdx +206 -0
  83. package/docs/ai-chat/quick-start.mdx +161 -0
  84. package/docs/ai-chat/reference.mdx +909 -0
  85. package/docs/ai-chat/server-chat.mdx +263 -0
  86. package/docs/ai-chat/sessions.mdx +333 -0
  87. package/docs/ai-chat/testing.mdx +682 -0
  88. package/docs/ai-chat/tools.mdx +191 -0
  89. package/docs/ai-chat/types.mdx +242 -0
  90. package/docs/ai-chat/upgrade-guide.mdx +515 -0
  91. package/docs/apikeys.mdx +54 -0
  92. package/docs/building-with-ai.mdx +261 -0
  93. package/docs/bulk-actions.mdx +49 -0
  94. package/docs/changelog.mdx +6 -0
  95. package/docs/cli-deploy-commands.mdx +9 -0
  96. package/docs/cli-dev-commands.mdx +9 -0
  97. package/docs/cli-dev.mdx +8 -0
  98. package/docs/cli-init-commands.mdx +58 -0
  99. package/docs/cli-introduction.mdx +25 -0
  100. package/docs/cli-list-profiles-commands.mdx +42 -0
  101. package/docs/cli-login-commands.mdx +33 -0
  102. package/docs/cli-logout-commands.mdx +33 -0
  103. package/docs/cli-preview-archive.mdx +59 -0
  104. package/docs/cli-promote-commands.mdx +9 -0
  105. package/docs/cli-switch.mdx +43 -0
  106. package/docs/cli-update-commands.mdx +42 -0
  107. package/docs/cli-whoami-commands.mdx +33 -0
  108. package/docs/community.mdx +6 -0
  109. package/docs/config/config-file.mdx +602 -0
  110. package/docs/config/extensions/additionalFiles.mdx +38 -0
  111. package/docs/config/extensions/additionalPackages.mdx +40 -0
  112. package/docs/config/extensions/aptGet.mdx +34 -0
  113. package/docs/config/extensions/audioWaveform.mdx +20 -0
  114. package/docs/config/extensions/custom.mdx +380 -0
  115. package/docs/config/extensions/emitDecoratorMetadata.mdx +29 -0
  116. package/docs/config/extensions/esbuildPlugin.mdx +31 -0
  117. package/docs/config/extensions/ffmpeg.mdx +45 -0
  118. package/docs/config/extensions/lightpanda.mdx +56 -0
  119. package/docs/config/extensions/overview.mdx +67 -0
  120. package/docs/config/extensions/playwright.mdx +195 -0
  121. package/docs/config/extensions/prismaExtension.mdx +1014 -0
  122. package/docs/config/extensions/puppeteer.mdx +30 -0
  123. package/docs/config/extensions/pythonExtension.mdx +182 -0
  124. package/docs/config/extensions/syncEnvVars.mdx +291 -0
  125. package/docs/context.mdx +235 -0
  126. package/docs/database-connections.mdx +213 -0
  127. package/docs/deploy-environment-variables.mdx +435 -0
  128. package/docs/deployment/atomic-deployment.mdx +172 -0
  129. package/docs/deployment/overview.mdx +257 -0
  130. package/docs/deployment/preview-branches.mdx +224 -0
  131. package/docs/errors-retrying.mdx +379 -0
  132. package/docs/github-actions.mdx +222 -0
  133. package/docs/github-integration.mdx +136 -0
  134. package/docs/github-repo.mdx +8 -0
  135. package/docs/help-email.mdx +6 -0
  136. package/docs/help-slack.mdx +11 -0
  137. package/docs/hidden-tasks.mdx +56 -0
  138. package/docs/how-it-works.mdx +454 -0
  139. package/docs/how-to-reduce-your-spend.mdx +217 -0
  140. package/docs/idempotency.mdx +504 -0
  141. package/docs/introduction.mdx +223 -0
  142. package/docs/limits.mdx +241 -0
  143. package/docs/logging.mdx +195 -0
  144. package/docs/machines.mdx +952 -0
  145. package/docs/manual-setup.mdx +632 -0
  146. package/docs/mcp-agent-rules.mdx +41 -0
  147. package/docs/mcp-introduction.mdx +385 -0
  148. package/docs/mcp-tools.mdx +273 -0
  149. package/docs/migrating-from-v3.mdx +334 -0
  150. package/docs/observability/dashboards.mdx +102 -0
  151. package/docs/observability/query.mdx +585 -0
  152. package/docs/open-source-contributing.mdx +16 -0
  153. package/docs/open-source-self-hosting.mdx +541 -0
  154. package/docs/private-networking/aws-console-setup.mdx +304 -0
  155. package/docs/private-networking/overview.mdx +144 -0
  156. package/docs/private-networking/troubleshooting.mdx +78 -0
  157. package/docs/queue-concurrency.mdx +354 -0
  158. package/docs/quick-start.mdx +97 -0
  159. package/docs/realtime/auth.mdx +208 -0
  160. package/docs/realtime/backend/overview.mdx +45 -0
  161. package/docs/realtime/backend/streams.mdx +418 -0
  162. package/docs/realtime/backend/subscribe.mdx +225 -0
  163. package/docs/realtime/how-it-works.mdx +94 -0
  164. package/docs/realtime/overview.mdx +63 -0
  165. package/docs/realtime/react-hooks/overview.mdx +73 -0
  166. package/docs/realtime/react-hooks/streams.mdx +449 -0
  167. package/docs/realtime/react-hooks/subscribe.mdx +674 -0
  168. package/docs/realtime/react-hooks/swr.mdx +87 -0
  169. package/docs/realtime/react-hooks/triggering.mdx +194 -0
  170. package/docs/realtime/react-hooks/use-wait-token.mdx +34 -0
  171. package/docs/realtime/run-object.mdx +174 -0
  172. package/docs/replaying.mdx +72 -0
  173. package/docs/request-feature.mdx +6 -0
  174. package/docs/roadmap.mdx +6 -0
  175. package/docs/run-tests.mdx +20 -0
  176. package/docs/run-usage.mdx +113 -0
  177. package/docs/runs/heartbeats.mdx +38 -0
  178. package/docs/runs/max-duration.mdx +139 -0
  179. package/docs/runs/metadata.mdx +734 -0
  180. package/docs/runs/priority.mdx +31 -0
  181. package/docs/runs.mdx +396 -0
  182. package/docs/self-hosting/docker.mdx +458 -0
  183. package/docs/self-hosting/env/supervisor.mdx +74 -0
  184. package/docs/self-hosting/env/webapp.mdx +276 -0
  185. package/docs/self-hosting/kubernetes.mdx +601 -0
  186. package/docs/self-hosting/overview.mdx +108 -0
  187. package/docs/skills.mdx +85 -0
  188. package/docs/tags.mdx +120 -0
  189. package/docs/tasks/overview.mdx +697 -0
  190. package/docs/tasks/scheduled.mdx +382 -0
  191. package/docs/tasks/schemaTask.mdx +413 -0
  192. package/docs/tasks/streams.mdx +884 -0
  193. package/docs/triggering.mdx +1320 -0
  194. package/docs/troubleshooting-alerts.mdx +385 -0
  195. package/docs/troubleshooting-debugging-in-vscode.mdx +8 -0
  196. package/docs/troubleshooting-github-issues.mdx +6 -0
  197. package/docs/troubleshooting-uptime-status.mdx +6 -0
  198. package/docs/troubleshooting.mdx +398 -0
  199. package/docs/upgrading-packages.mdx +80 -0
  200. package/docs/vercel-integration.mdx +207 -0
  201. package/docs/versioning.mdx +56 -0
  202. package/docs/video-walkthrough.mdx +23 -0
  203. package/docs/wait-for-token.mdx +540 -0
  204. package/docs/wait-for.mdx +42 -0
  205. package/docs/wait-until.mdx +53 -0
  206. package/docs/wait.mdx +18 -0
  207. package/docs/writing-tasks-introduction.mdx +33 -0
  208. package/package.json +10 -6
  209. package/skills/trigger-authoring-chat-agent/SKILL.md +296 -0
  210. package/skills/trigger-authoring-tasks/SKILL.md +254 -0
  211. package/skills/trigger-chat-agent-advanced/SKILL.md +368 -0
  212. package/skills/trigger-cost-savings/SKILL.md +116 -0
  213. package/skills/trigger-realtime-and-frontend/SKILL.md +276 -0
@@ -0,0 +1,87 @@
1
+ ---
2
+ title: SWR hooks
3
+ sidebarTitle: SWR
4
+ description: Fetch and cache data using SWR-based hooks
5
+ ---
6
+
7
+ SWR hooks use the [swr](https://swr.vercel.app/) library to fetch data once and cache it. These hooks are useful when you need to fetch data without real-time updates.
8
+
9
+ <Note>
10
+ While SWR can be configured to poll for updates, we recommend using our other [Realtime
11
+ hooks](/realtime/react-hooks/) for most use-cases due to rate-limits and the way the Trigger.dev
12
+ API works.
13
+ </Note>
14
+
15
+ ## useRun
16
+
17
+ The `useRun` hook allows you to fetch a run by its ID.
18
+
19
+ ```tsx
20
+ "use client"; // This is needed for Next.js App Router or other RSC frameworks
21
+
22
+ import { useRun } from "@trigger.dev/react-hooks";
23
+
24
+ export function MyComponent({ runId }: { runId: string }) {
25
+ const { run, error, isLoading } = useRun(runId);
26
+
27
+ if (isLoading) return <div>Loading...</div>;
28
+ if (error) return <div>Error: {error.message}</div>;
29
+
30
+ return <div>Run: {run.id}</div>;
31
+ }
32
+ ```
33
+
34
+ The `run` object returned is the same as the [run object](/management/runs/retrieve) returned by the Trigger.dev API. To correctly type the run's payload and output, you can provide the type of your task to the `useRun` hook:
35
+
36
+ ```tsx
37
+ import { useRun } from "@trigger.dev/react-hooks";
38
+ import type { myTask } from "@/trigger/myTask";
39
+
40
+ export function MyComponent({ runId }: { runId: string }) {
41
+ const { run, error, isLoading } = useRun<typeof myTask>(runId, {
42
+ refreshInterval: 0, // Disable polling
43
+ });
44
+
45
+ if (isLoading) return <div>Loading...</div>;
46
+ if (error) return <div>Error: {error.message}</div>;
47
+
48
+ // Now run.payload and run.output are correctly typed
49
+
50
+ return <div>Run: {run.id}</div>;
51
+ }
52
+ ```
53
+
54
+ ## Common SWR options
55
+
56
+ You can pass the following options to the all SWR hooks:
57
+
58
+ <ParamField path="revalidateOnFocus" type="boolean">
59
+ Revalidate the data when the window regains focus.
60
+ </ParamField>
61
+
62
+ <ParamField path="revalidateOnReconnect" type="boolean">
63
+ Revalidate the data when the browser regains a network connection.
64
+ </ParamField>
65
+
66
+ <ParamField path="refreshInterval" type="number">
67
+ Poll for updates at the specified interval (in milliseconds). Polling is not recommended for most
68
+ use-cases. Use the Realtime hooks instead.
69
+ </ParamField>
70
+
71
+ ## Common SWR return values
72
+
73
+ <ResponseField name="error" type="Error">
74
+ An error object if an error occurred while fetching the data.
75
+ </ResponseField>
76
+
77
+ <ResponseField name="isLoading" type="boolean">
78
+ A boolean indicating if the data is currently being fetched.
79
+ </ResponseField>
80
+
81
+ <ResponseField name="isValidating" type="boolean">
82
+ A boolean indicating if the data is currently being revalidated.
83
+ </ResponseField>
84
+
85
+ <ResponseField name="isError" type="boolean">
86
+ A boolean indicating if an error occurred while fetching the data.
87
+ </ResponseField>{" "}
@@ -0,0 +1,194 @@
1
+ ---
2
+ title: "Trigger tasks from React"
3
+ sidebarTitle: Triggering
4
+ description: "Trigger background tasks from React components and optionally subscribe to their progress or stream their output."
5
+ ---
6
+
7
+ Trigger tasks directly from your React components. You can fire-and-forget, or trigger and immediately subscribe to the run's progress or streamed output.
8
+
9
+ <Note>
10
+ For triggering tasks from your frontend, you need to use “trigger” tokens. These can only be used
11
+ once to trigger a task and are more secure than regular Public Access Tokens. To learn more about
12
+ how to create and use these tokens, see our [Trigger
13
+ Tokens](/realtime/auth#trigger-tokens-for-frontend-triggering-only) documentation.
14
+ </Note>
15
+
16
+ ## Hooks
17
+
18
+ We provide three hooks for triggering tasks from your frontend application:
19
+
20
+ - `useTaskTrigger` - Trigger a task from your frontend application.
21
+ - `useRealtimeTaskTrigger` - Trigger a task from your frontend application and subscribe to the run.
22
+ - `useRealtimeTaskTriggerWithStreams` - Trigger a task from your frontend application and subscribe to the run, and also receive any streams that are emitted by the task.
23
+
24
+ ### useTaskTrigger
25
+
26
+ The `useTaskTrigger` hook allows you to trigger a task from your frontend application.
27
+
28
+ ```tsx
29
+ "use client"; // This is needed for Next.js App Router or other RSC frameworks
30
+
31
+ import { useTaskTrigger } from "@trigger.dev/react-hooks";
32
+ import type { myTask } from "@/trigger/myTask";
33
+ // 👆 This is the type of your task, include this to get type-safety
34
+
35
+ export function MyComponent({ publicAccessToken }: { publicAccessToken: string }) {
36
+ // pass the type of your task here 👇
37
+ const { submit, handle, error, isLoading } = useTaskTrigger<typeof myTask>("my-task", {
38
+ accessToken: publicAccessToken, // 👈 this is the "trigger" token
39
+ });
40
+
41
+ if (error) {
42
+ return <div>Error: {error.message}</div>;
43
+ }
44
+
45
+ if (handle) {
46
+ return <div>Run ID: {handle.id}</div>;
47
+ }
48
+
49
+ return (
50
+ <button onClick={() => submit({ foo: "bar" })} disabled={isLoading}>
51
+ {isLoading ? "Loading..." : "Trigger Task"}
52
+ </button>
53
+ );
54
+ }
55
+ ```
56
+
57
+ `useTaskTrigger` returns an object with the following properties:
58
+
59
+ - `submit`: A function that triggers the task. It takes the payload of the task as an argument.
60
+ - `handle`: The run handle object. This object contains the ID of the run that was triggered, along with a Public Access Token that can be used to access the run.
61
+ - `isLoading`: A boolean that indicates whether the task is currently being triggered.
62
+ - `error`: An error object that contains any errors that occurred while triggering the task.
63
+
64
+ The `submit` function triggers the task with the specified payload. You can additionally pass an optional [options](/triggering#options) argument to the `submit` function:
65
+
66
+ ```tsx
67
+ submit({ foo: "bar" }, { tags: ["tag1", "tag2"] });
68
+ ```
69
+
70
+ #### Using the handle object
71
+
72
+ You can use the `handle` object to initiate a subsequent [Realtime hook](/realtime/react-hooks/subscribe#userealtimerun) to subscribe to the run.
73
+
74
+ ```tsx
75
+ "use client"; // This is needed for Next.js App Router or other RSC frameworks
76
+
77
+ import { useTaskTrigger, useRealtimeRun } from "@trigger.dev/react-hooks";
78
+ import type { myTask } from "@/trigger/myTask";
79
+ // 👆 This is the type of your task
80
+
81
+ export function MyComponent({ publicAccessToken }: { publicAccessToken: string }) {
82
+ // pass the type of your task here 👇
83
+ const { submit, handle, error, isLoading } = useTaskTrigger<typeof myTask>("my-task", {
84
+ accessToken: publicAccessToken, // 👈 this is the "trigger" token
85
+ });
86
+
87
+ // use the handle object to preserve type-safety 👇
88
+ const { run, error: realtimeError } = useRealtimeRun(handle, {
89
+ accessToken: handle?.publicAccessToken,
90
+ enabled: !!handle, // Only subscribe to the run if the handle is available
91
+ });
92
+
93
+ if (error) {
94
+ return <div>Error: {error.message}</div>;
95
+ }
96
+
97
+ if (handle) {
98
+ return <div>Run ID: {handle.id}</div>;
99
+ }
100
+
101
+ if (realtimeError) {
102
+ return <div>Error: {realtimeError.message}</div>;
103
+ }
104
+
105
+ if (run) {
106
+ return <div>Run ID: {run.id}</div>;
107
+ }
108
+
109
+ return (
110
+ <button onClick={() => submit({ foo: "bar" })} disabled={isLoading}>
111
+ {isLoading ? "Loading..." : "Trigger Task"}
112
+ </button>
113
+ );
114
+ }
115
+ ```
116
+
117
+ We've also created some additional hooks that allow you to trigger tasks and subscribe to the run in one step:
118
+
119
+ ### useRealtimeTaskTrigger
120
+
121
+ The `useRealtimeTaskTrigger` hook allows you to trigger a task from your frontend application and then subscribe to the run in using Realtime:
122
+
123
+ ```tsx
124
+ "use client"; // This is needed for Next.js App Router or other RSC frameworks
125
+
126
+ import { useRealtimeTaskTrigger } from "@trigger.dev/react-hooks";
127
+ import type { myTask } from "@/trigger/myTask";
128
+
129
+ export function MyComponent({ publicAccessToken }: { publicAccessToken: string }) {
130
+ const { submit, run, error, isLoading } = useRealtimeTaskTrigger<typeof myTask>("my-task", {
131
+ accessToken: publicAccessToken,
132
+ });
133
+
134
+ if (error) {
135
+ return <div>Error: {error.message}</div>;
136
+ }
137
+
138
+ // This is the Realtime run object, which will automatically update when the run changes
139
+ if (run) {
140
+ return <div>Run ID: {run.id}</div>;
141
+ }
142
+
143
+ return (
144
+ <button onClick={() => submit({ foo: "bar" })} disabled={isLoading}>
145
+ {isLoading ? "Loading..." : "Trigger Task"}
146
+ </button>
147
+ );
148
+ }
149
+ ```
150
+
151
+ ### useRealtimeTaskTriggerWithStreams
152
+
153
+ The `useRealtimeTaskTriggerWithStreams` hook allows you to trigger a task from your frontend application and then subscribe to the run in using Realtime, and also receive any streams that are emitted by the task.
154
+
155
+ ```tsx
156
+ "use client"; // This is needed for Next.js App Router or other RSC frameworks
157
+
158
+ import { useRealtimeTaskTriggerWithStreams } from "@trigger.dev/react-hooks";
159
+ import type { myTask } from "@/trigger/myTask";
160
+
161
+ type STREAMS = {
162
+ openai: string; // this is the type of each "part" of the stream
163
+ };
164
+
165
+ export function MyComponent({ publicAccessToken }: { publicAccessToken: string }) {
166
+ const { submit, run, streams, error, isLoading } = useRealtimeTaskTriggerWithStreams<
167
+ typeof myTask,
168
+ STREAMS
169
+ >("my-task", {
170
+ accessToken: publicAccessToken,
171
+ });
172
+
173
+ if (error) {
174
+ return <div>Error: {error.message}</div>;
175
+ }
176
+
177
+ if (streams && run) {
178
+ const text = streams.openai?.map((part) => part).join("");
179
+
180
+ return (
181
+ <div>
182
+ <div>Run ID: {run.id}</div>
183
+ <div>{text}</div>
184
+ </div>
185
+ );
186
+ }
187
+
188
+ return (
189
+ <button onClick={() => submit({ foo: "bar" })} disabled={isLoading}>
190
+ {isLoading ? "Loading..." : "Trigger Task"}
191
+ </button>
192
+ );
193
+ }
194
+ ```
@@ -0,0 +1,34 @@
1
+ ---
2
+ title: useWaitToken
3
+ description: Use the useWaitToken hook to complete a wait token from a React component
4
+ ---
5
+
6
+ We've added a new `useWaitToken` react hook that allows you to complete a wait token from a React component, using a Public Access Token.
7
+
8
+ ```ts backend.ts
9
+ import { wait } from "@trigger.dev/sdk";
10
+
11
+ // Somewhere in your code, you'll need to create the token and then pass the token ID and the public token to the frontend
12
+ const token = await wait.createToken({
13
+ timeout: "10m",
14
+ });
15
+
16
+ return {
17
+ tokenId: token.id,
18
+ publicToken: token.publicAccessToken, // An automatically generated public access token that expires in 1 hour
19
+ };
20
+ ```
21
+
22
+ Now you can use the `useWaitToken` hook in your frontend code:
23
+
24
+ ```tsx frontend.tsx
25
+ import { useWaitToken } from "@trigger.dev/react-hooks";
26
+
27
+ export function MyComponent({ publicToken, tokenId }: { publicToken: string; tokenId: string }) {
28
+ const { complete } = useWaitToken(tokenId, {
29
+ accessToken: publicToken,
30
+ });
31
+
32
+ return <button onClick={() => complete({ foo: "bar" })}>Complete</button>;
33
+ }
34
+ ```
@@ -0,0 +1,174 @@
1
+ ---
2
+ title: "The run object"
3
+ sidebarTitle: "The run object"
4
+ description: "The run object schema for Realtime subscriptions"
5
+ ---
6
+
7
+ The [run object](/realtime/run-object#the-run-object) is the main object returned by Realtime subscriptions (e.g., `runs.subscribeToRun()`). It contains all the information about the run, including the run ID, task identifier, payload, output, and more.
8
+
9
+ Type-safety is supported for the run object, so you can infer the types of the run's payload and output. See [type-safety](#type-safety) for more information.
10
+
11
+ ## The run object
12
+
13
+ ### Properties
14
+
15
+ <ParamField path="id" type="string" required>
16
+ The run ID.
17
+ </ParamField>
18
+
19
+ <ParamField path="taskIdentifier" type="string" required>
20
+ The task identifier.
21
+ </ParamField>
22
+
23
+ <ParamField path="payload" type="object" required>
24
+ The input payload for the run.
25
+ </ParamField>
26
+
27
+ <ParamField path="output" type="object">
28
+ The output result of the run.
29
+ </ParamField>
30
+
31
+ <ParamField path="createdAt" type="Date" required>
32
+ Timestamp when the run was created.
33
+ </ParamField>
34
+
35
+ <ParamField path="updatedAt" type="Date" required>
36
+ Timestamp when the run was last updated.
37
+ </ParamField>
38
+
39
+ <ParamField path="number" type="number" required>
40
+ Sequential number assigned to the run.
41
+ </ParamField>
42
+
43
+ <ParamField path="status" type="RunStatus" required>
44
+ Current status of the run.
45
+
46
+ <Accordion title="RunStatus enum">
47
+
48
+ | Status | Description |
49
+ | -------------------- | --------------------------------------------------------------------------------------------------------- |
50
+ | `WAITING_FOR_DEPLOY` | Task hasn't been deployed yet but is waiting to be executed |
51
+ | `QUEUED` | Run is waiting to be executed by a worker |
52
+ | `EXECUTING` | Run is currently being executed by a worker |
53
+ | `REATTEMPTING` | Run has failed and is waiting to be retried |
54
+ | `FROZEN` | Run has been paused by the system, and will be resumed by the system |
55
+ | `COMPLETED` | Run has been completed successfully |
56
+ | `CANCELED` | Run has been canceled by the user |
57
+ | `FAILED` | Run has been completed with errors |
58
+ | `CRASHED` | Run has crashed and won't be retried, most likely the worker ran out of resources, e.g. memory or storage |
59
+ | `INTERRUPTED` | Run was interrupted during execution, mostly this happens in development environments |
60
+ | `SYSTEM_FAILURE` | Run has failed to complete, due to an error in the system |
61
+ | `DELAYED` | Run has been scheduled to run at a specific time |
62
+ | `EXPIRED` | Run has expired and won't be executed |
63
+ | `TIMED_OUT` | Run has reached it's maxDuration and has been stopped |
64
+
65
+ </Accordion>
66
+ </ParamField>
67
+
68
+ <ParamField path="durationMs" type="number" required>
69
+ Duration of the run in milliseconds.
70
+ </ParamField>
71
+
72
+ <ParamField path="costInCents" type="number" required>
73
+ Total cost of the run in cents.
74
+ </ParamField>
75
+
76
+ <ParamField path="baseCostInCents" type="number" required>
77
+ Base cost of the run in cents before any additional charges.
78
+ </ParamField>
79
+
80
+ <ParamField path="tags" type="string[]" required>
81
+ Array of tags associated with the run.
82
+ </ParamField>
83
+
84
+ <ParamField path="idempotencyKey" type="string">
85
+ Key used to ensure idempotent execution.
86
+ </ParamField>
87
+
88
+ <ParamField path="expiredAt" type="Date">
89
+ Timestamp when the run expired.
90
+ </ParamField>
91
+
92
+ <ParamField path="ttl" type="string">
93
+ Time-to-live duration for the run.
94
+ </ParamField>
95
+
96
+ <ParamField path="finishedAt" type="Date">
97
+ Timestamp when the run finished.
98
+ </ParamField>
99
+
100
+ <ParamField path="startedAt" type="Date">
101
+ Timestamp when the run started.
102
+ </ParamField>
103
+
104
+ <ParamField path="delayedUntil" type="Date">
105
+ Timestamp until which the run is delayed.
106
+ </ParamField>
107
+
108
+ <ParamField path="queuedAt" type="Date">
109
+ Timestamp when the run was queued.
110
+ </ParamField>
111
+
112
+ <ParamField path="metadata" type="Record<string, DeserializedJson>">
113
+ Additional metadata associated with the run.
114
+ </ParamField>
115
+
116
+ <ParamField path="error" type="SerializedError">
117
+ Error information if the run failed.
118
+ </ParamField>
119
+
120
+ <ParamField path="isTest" type="boolean" required>
121
+ Indicates whether this is a test run.
122
+ </ParamField>
123
+
124
+ ## Type-safety
125
+
126
+ You can infer the types of the run's payload and output by passing the type of the task to the `subscribeToRun` function. This will give you type-safe access to the run's payload and output.
127
+
128
+ ```ts
129
+ import { runs, tasks } from "@trigger.dev/sdk";
130
+ import type { myTask } from "./trigger/my-task";
131
+
132
+ // Somewhere in your backend code
133
+ async function myBackend() {
134
+ const handle = await tasks.trigger("my-task", { some: "data" });
135
+
136
+ for await (const run of runs.subscribeToRun<typeof myTask>(handle.id)) {
137
+ // This will log the run every time it changes
138
+ console.log(run.payload.some);
139
+
140
+ if (run.output) {
141
+ // This will log the output if it exists
142
+ console.log(run.output.some);
143
+ }
144
+ }
145
+ }
146
+ ```
147
+
148
+ When using `subscribeToRunsWithTag`, you can pass a union of task types for all the possible tasks that can have the tag.
149
+
150
+ ```ts
151
+ import { runs } from "@trigger.dev/sdk";
152
+ import type { myTask, myOtherTask } from "./trigger/my-task";
153
+
154
+ // Somewhere in your backend code
155
+ for await (const run of runs.subscribeToRunsWithTag<typeof myTask | typeof myOtherTask>("my-tag")) {
156
+ // You can narrow down the type based on the taskIdentifier
157
+ switch (run.taskIdentifier) {
158
+ case "my-task": {
159
+ console.log("Run output:", run.output.foo); // This will be type-safe
160
+ break;
161
+ }
162
+ case "my-other-task": {
163
+ console.log("Run output:", run.output.bar); // This will be type-safe
164
+ break;
165
+ }
166
+ }
167
+ }
168
+ ```
169
+
170
+ This works with all realtime subscription functions:
171
+
172
+ - `runs.subscribeToRun<TaskType>()`
173
+ - `runs.subscribeToRunsWithTag<TaskType>()`
174
+ - `runs.subscribeToBatch<TaskType>()`
@@ -0,0 +1,72 @@
1
+ ---
2
+ title: "Replaying"
3
+ description: "A replay is a copy of a run with the same payload but against the latest version in that environment. This is useful if something went wrong and you want to try again with the latest version of your code."
4
+ ---
5
+
6
+ ### Replaying from the UI
7
+
8
+ <Tabs>
9
+ <Tab title="From a run">
10
+ <Steps>
11
+ <Step title="Click the Replay button in the top right">
12
+ ![Select a task, then in the bottom right
13
+ click "Replay"](/images/replay-run-action.png)
14
+ </Step>
15
+ <Step title="Confirm replay settings">
16
+ You can edit the payload <Icon icon="circle-1" iconType="solid" size={20} color="F43F47" /> (if available) and choose the environment <Icon icon="circle-2" iconType="solid" size={20} color="F43F47" /> to replay the run in.
17
+
18
+ ![Select a task, then in the bottom right
19
+ click "Replay"](/images/replay-run-modal.png)
20
+ </Step>
21
+ </Steps>
22
+ </Tab>
23
+ <Tab title="Runs list">
24
+ <Steps>
25
+ <Step title="Click the action button on a run">
26
+ ![On the runs page, press the triple dot button](/images/replay-runs-list.png)
27
+ </Step>
28
+ <Step title="Click replay">![Click replay](/images/replay-runs-list-popover.png)</Step>
29
+ </Steps>
30
+ </Tab>
31
+ </Tabs>
32
+
33
+ ### Detecting replays in your task
34
+
35
+ You can check if a run is a replay using the [context](/context) object:
36
+
37
+ ```ts
38
+ export const myTask = task({
39
+ id: "my-task",
40
+ run: async (payload, { ctx }) => {
41
+ if (ctx.run.isReplay) {
42
+ // This run is a replay of a previous run
43
+ }
44
+ },
45
+ });
46
+ ```
47
+
48
+ ### Replaying using the SDK
49
+
50
+ You can replay a run using the SDK:
51
+
52
+ ```ts
53
+ const replayedRun = await runs.replay(run.id);
54
+ ```
55
+
56
+ When you call `trigger()` or `batchTrigger()` on a task you receive back a run handle which has an `id` property. You can use that `id` to replay the run.
57
+
58
+ You can also access the run id from inside a run. You could write this to your database and then replay it later.
59
+
60
+ ```ts
61
+ export const simpleChildTask = task({
62
+ id: "simple-child-task",
63
+ run: async (payload, { ctx }) => {
64
+ // the run ID (and other useful info) is in ctx
65
+ const runId = ctx.run.id;
66
+ },
67
+ });
68
+ ```
69
+
70
+ ### Bulk replaying
71
+
72
+ See [Bulk actions](/bulk-actions) for more information.
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: "Request a feature"
3
+ url: "https://feedback.trigger.dev/"
4
+ ---
5
+
6
+ If you have a feature request or idea for Trigger, we'd love to hear it! You can submit your ideas on our [public roadmap](https://feedback.trigger.dev/). We're always looking for feedback on what to build next, so feel free to submit your ideas or vote on existing ones.
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: "Roadmap"
3
+ url: "https://feedback.trigger.dev/roadmap"
4
+ ---
5
+
6
+ See what's coming up next on our [public roadmap](https://feedback.trigger.dev/roadmap). We're always looking for feedback on what to build next, so feel free to submit your ideas or vote on existing ones.
@@ -0,0 +1,20 @@
1
+ ---
2
+ title: "Run tests"
3
+ description: "You can use the dashboard to run a test of your tasks."
4
+ ---
5
+
6
+ From the "Test" page in the side menu of the dashboard you can run a test for any of your tasks from any environment.
7
+
8
+ ![Select an environment](/images/test-dashboard.png)
9
+
10
+ <Icon icon="circle-1" iconType="solid" color="#FF2D6B" size="20" /> Select a task to test
11
+
12
+ <Icon icon="circle-2" iconType="solid" color="#FF2D6B" size="20" /> Include a payload or metadata
13
+
14
+ <Icon icon="circle-3" iconType="solid" color="#FF2D6B" size="20" /> Configure any additional options like the machine size, queue or delay
15
+
16
+ <Icon icon="circle-4" iconType="solid" color="#FF2D6B" size="20" /> Select from previous test runs
17
+
18
+ <Icon icon="circle-5" iconType="solid" color="#FF2D6B" size="20" /> Save the current test configuration as a template for later
19
+
20
+ <Icon icon="circle-6" iconType="solid" color="#FF2D6B" size="20" /> Run the test