@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,435 @@
1
+ ---
2
+ title: "Environment Variables"
3
+ description: "Any environment variables used in your tasks need to be added so the deployed code will run successfully."
4
+ ---
5
+
6
+ An environment variable in Node.js is accessed in your code using `process.env.MY_ENV_VAR`.
7
+
8
+ We deploy your tasks and scale them up and down when they are triggered. So any environment variables you use in your tasks need to accessible to us so your code will run successfully.
9
+
10
+ ## In the dashboard
11
+
12
+ ### Setting environment variables
13
+
14
+ <Steps>
15
+
16
+ <Step title="Go to the Environment Variables page">
17
+ In the sidebar select the "Environment Variables" page, then press the "New environment variable"
18
+ button. ![Environment variables page](/images/environment-variables-page.jpg)
19
+ </Step>
20
+
21
+ <Step title="Add your environment variables">
22
+ You can add values for your local dev environment, staging and prod. ![Environment variables
23
+ page](/images/environment-variables-panel.jpg)
24
+ </Step>
25
+
26
+ </Steps>
27
+
28
+ <Note>
29
+ Specifying Dev values is optional. They will be overriden by values in your .env file when running
30
+ locally.
31
+ </Note>
32
+
33
+ ### Secret environment variables
34
+
35
+ When creating an environment variable, you can mark it as a **Secret**. Secret values are hidden in the dashboard and cannot be viewed after creation.
36
+
37
+ <Warning>
38
+ Marking a variable as a Secret is irreversible and can only be done when creating the variable. To
39
+ change this setting, you must delete the variable and create a new one.
40
+ </Warning>
41
+
42
+ ### Editing environment variables
43
+
44
+ You can edit an environment variable's values. You cannot edit the key name, you must delete and create a new one.
45
+
46
+ <Steps>
47
+
48
+ <Step title="Press the action button on a variable">
49
+ ![Environment variables page](/images/environment-variables-actions.png)
50
+ </Step>
51
+
52
+ <Step title="Press edit">
53
+ ![Environment variables page](/images/environment-variables-edit-popover.png)
54
+ </Step>
55
+
56
+ </Steps>
57
+
58
+ ### Deleting environment variables
59
+
60
+ <Warn>
61
+ Environment variables are fetched and injected before a runs begins. So if you delete one you can
62
+ cause runs to fail that are expecting variables to be set.
63
+ </Warn>
64
+
65
+ <Steps>
66
+
67
+ <Step title="Press the action button on a variable">
68
+ ![Environment variables page](/images/environment-variables-actions.png)
69
+ </Step>
70
+
71
+ <Step title="Press delete">
72
+ This will immediately delete the variable. ![Environment variables
73
+ page](/images/environment-variables-delete-popover.png)
74
+ </Step>
75
+
76
+ </Steps>
77
+
78
+ ## Local development
79
+
80
+ When running `npx trigger.dev dev`, the CLI automatically loads environment variables from these files in order (later files override any duplicate keys from earlier ones):
81
+
82
+ - `.env`
83
+ - `.env.development`
84
+ - `.env.local`
85
+ - `.env.development.local`
86
+ - `dev.vars`
87
+
88
+ These variables are available to your tasks via `process.env`. You don't need to use the `--env-file` flag for this automatic loading.
89
+
90
+ ## In your code
91
+
92
+ You can use our SDK to get and manipulate environment variables. You can also easily sync environment variables from another service into Trigger.dev.
93
+
94
+ ### Directly manipulating environment variables
95
+
96
+ We have a complete set of SDK functions (and REST API) you can use to directly manipulate environment variables.
97
+
98
+ | Function | Description |
99
+ | -------------------------------------------------- | ----------------------------------------------------------- |
100
+ | [envvars.list()](/management/envvars/list) | List all environment variables |
101
+ | [envvars.upload()](/management/envvars/import) | Upload multiple env vars. You can override existing values. |
102
+ | [envvars.create()](/management/envvars/create) | Create a new environment variable |
103
+ | [envvars.retrieve()](/management/envvars/retrieve) | Retrieve an environment variable |
104
+ | [envvars.update()](/management/envvars/update) | Update a single environment variable |
105
+ | [envvars.del()](/management/envvars/delete) | Delete a single environment variable |
106
+
107
+ #### Initial load from .env file
108
+
109
+ To initially load environment variables from a `.env` file into your Trigger.dev cloud environment, you can use `envvars.upload()`. This is useful for one-time bulk imports when setting up a new project or environment.
110
+
111
+ ```ts
112
+ import { envvars } from "@trigger.dev/sdk";
113
+ import { readFileSync } from "fs";
114
+ import { parse } from "dotenv";
115
+
116
+ // Read and parse your .env file
117
+ const envContent = readFileSync(".env.production", "utf-8");
118
+ const parsed = parse(envContent);
119
+
120
+ // Upload to Trigger.dev (replace with your project ref and environment slug)
121
+ await envvars.upload("proj_your_project_ref", "prod", {
122
+ variables: parsed,
123
+ override: false, // Set to true to override existing variables
124
+ });
125
+ ```
126
+
127
+ When called inside a task, you can omit the project ref and environment slug as they'll be automatically inferred from the task context:
128
+
129
+ ```ts
130
+ import { envvars, task } from "@trigger.dev/sdk";
131
+ import { readFileSync } from "fs";
132
+ import { parse } from "dotenv";
133
+
134
+ export const setupEnvVars = task({
135
+ id: "setup-env-vars",
136
+ run: async () => {
137
+ const envContent = readFileSync(".env.production", "utf-8");
138
+ const parsed = parse(envContent);
139
+
140
+ // projectRef and environment slug are automatically inferred from ctx
141
+ await envvars.upload({
142
+ variables: parsed,
143
+ override: false,
144
+ });
145
+ },
146
+ });
147
+ ```
148
+
149
+ <Note>
150
+ This is different from `syncEnvVars` which automatically syncs variables during every deploy. Use `envvars.upload()` for one-time initial loads, and `syncEnvVars` for ongoing synchronization.
151
+ </Note>
152
+
153
+ #### Getting the current environment
154
+
155
+ When using `envvars.retrieve()` inside a task, you can access the current environment information from the task context (`ctx`). The `envvars.retrieve()` function doesn't return the environment, but you can get it from `ctx.environment`:
156
+
157
+ ```ts
158
+ import { envvars, task } from "@trigger.dev/sdk";
159
+
160
+ export const myTask = task({
161
+ id: "my-task",
162
+ run: async (payload, { ctx }) => {
163
+ // Get the current environment information
164
+ const currentEnv = ctx.environment.slug; // e.g., "dev", "prod", "staging"
165
+ const envType = ctx.environment.type; // e.g., "DEVELOPMENT", "PRODUCTION", "STAGING", "PREVIEW"
166
+
167
+ // Retrieve an environment variable
168
+ // When called inside a task, projectRef and slug are automatically inferred
169
+ const apiKey = await envvars.retrieve("API_KEY");
170
+
171
+ console.log(`Retrieved API_KEY from environment: ${currentEnv} (${envType})`);
172
+ console.log(`Value: ${apiKey.value}`);
173
+ },
174
+ });
175
+ ```
176
+
177
+ The context object provides:
178
+ - `ctx.environment.slug` - The environment slug (e.g., "dev", "prod")
179
+ - `ctx.environment.type` - The environment type ("DEVELOPMENT", "PRODUCTION", "STAGING", or "PREVIEW")
180
+ - `ctx.environment.id` - The environment ID
181
+ - `ctx.project.ref` - The project reference
182
+
183
+ For more information about the context object, see the [Context documentation](/context).
184
+
185
+ ### Sync env vars from another service
186
+
187
+ You could use the SDK functions above but it's much easier to use our `syncEnvVars` build extension in your `trigger.config` file.
188
+
189
+ <Note>
190
+ To use the `syncEnvVars` build extension, you should first install the `@trigger.dev/build`
191
+ package into your devDependencies.
192
+ </Note>
193
+
194
+ In this example we're using env vars from [Infisical](https://infisical.com).
195
+
196
+ ```ts trigger.config.ts
197
+ import { defineConfig } from "@trigger.dev/sdk";
198
+ import { syncEnvVars } from "@trigger.dev/build/extensions/core";
199
+ import { InfisicalSDK } from "@infisical/sdk";
200
+
201
+ export default defineConfig({
202
+ build: {
203
+ extensions: [
204
+ syncEnvVars(async (ctx) => {
205
+ const client = new InfisicalSDK();
206
+
207
+ await client.auth().universalAuth.login({
208
+ clientId: process.env.INFISICAL_CLIENT_ID!,
209
+ clientSecret: process.env.INFISICAL_CLIENT_SECRET!,
210
+ });
211
+
212
+ const { secrets } = await client.secrets().listSecrets({
213
+ environment: ctx.environment,
214
+ projectId: process.env.INFISICAL_PROJECT_ID!,
215
+ });
216
+
217
+ return secrets.map((secret) => ({
218
+ name: secret.secretKey,
219
+ value: secret.secretValue,
220
+ }));
221
+ }),
222
+ ],
223
+ },
224
+ });
225
+ ```
226
+
227
+ #### Syncing environment variables from Vercel
228
+
229
+ To sync environment variables from your Vercel projects to Trigger.dev, you can use our build extension. Check out our [syncing environment variables from Vercel guide](/guides/examples/vercel-sync-env-vars).
230
+
231
+ #### Deploy
232
+
233
+ When you run the [CLI deploy command](/cli-deploy) directly or using [GitHub Actions](/github-actions) it will sync the environment variables from [Infisical](https://infisical.com) to Trigger.dev. This means they'll appear on the Environment Variables page so you can confirm that it's worked.
234
+
235
+ This means that you need to redeploy your Trigger.dev tasks if you change the environment variables in [Infisical](https://infisical.com).
236
+
237
+ <Note>
238
+ The `process.env.INFISICAL_CLIENT_ID`, `process.env.INFISICAL_CLIENT_SECRET` and
239
+ `process.env.INFISICAL_PROJECT_ID` will need to be supplied to the `deploy` CLI command. You can
240
+ do this via the `--env-file .env` flag or by setting them as environment variables in your
241
+ terminal.
242
+ </Note>
243
+
244
+ #### Dev
245
+
246
+ `syncEnvVars` does not have any effect when running the `dev` command locally. If you want to inject environment variables from another service into your local environment you can do so via a `.env` file or just supplying them as environment variables in your terminal. Most services will have a CLI tool that allows you to run a command with environment variables set:
247
+
248
+ ```sh
249
+ infisical run -- npx trigger.dev@latest dev
250
+ ```
251
+
252
+ Any environment variables set in the CLI command will be available to your local Trigger.dev tasks.
253
+
254
+ ### The syncEnvVars callback return type
255
+
256
+ You can return env vars as an object with string keys and values, or an array of names + values.
257
+
258
+ ```ts
259
+ return {
260
+ MY_ENV_VAR: "my value",
261
+ MY_OTHER_ENV_VAR: "my other value",
262
+ };
263
+ ```
264
+
265
+ or
266
+
267
+ ```ts
268
+ return [
269
+ {
270
+ name: "MY_ENV_VAR",
271
+ value: "my value",
272
+ },
273
+ {
274
+ name: "MY_OTHER_ENV_VAR",
275
+ value: "my other value",
276
+ },
277
+ ];
278
+ ```
279
+
280
+ This should mean that for most secret services you won't need to convert the data into a different format.
281
+
282
+ ### Using Google credential JSON files
283
+
284
+ Securely pass a Google credential JSON file to your Trigger.dev task using environment variables.
285
+
286
+ <Steps>
287
+
288
+ <Step title="Convert the Google credential file to base64">
289
+
290
+ In your terminal, run the following command and copy the resulting base64 string:
291
+
292
+ ```
293
+ base64 -i path/to/your/service-account-file.json
294
+ ```
295
+
296
+ </Step>
297
+
298
+ <Step title="Set up the environment variable in Trigger.dev">
299
+
300
+ Follow [these steps](/deploy-environment-variables) to set a new environment variable using the base64 string as the value.
301
+
302
+ ```
303
+ GOOGLE_CREDENTIALS_BASE64="<your base64 string>"
304
+ ```
305
+
306
+ </Step>
307
+
308
+ <Step title="Use the environment variable in your code">
309
+
310
+ Add the following code to your Trigger.dev task:
311
+
312
+ ```ts
313
+ import { google } from "googleapis";
314
+
315
+ const credentials = JSON.parse(
316
+ Buffer.from(process.env.GOOGLE_CREDENTIALS_BASE64, "base64").toString("utf8")
317
+ );
318
+
319
+ const auth = new google.auth.GoogleAuth({
320
+ credentials,
321
+ scopes: ["https://www.googleapis.com/auth/cloud-platform"],
322
+ });
323
+
324
+ const client = await auth.getClient();
325
+ ```
326
+
327
+ </Step>
328
+
329
+ <Step title="Use the client in your code">
330
+
331
+ You can now use the `client` object to make authenticated requests to Google APIs
332
+
333
+ </Step>
334
+
335
+ </Steps>
336
+
337
+ ## Using `.env.production` or dotenvx with Trigger.dev
338
+
339
+ Trigger.dev does not automatically load `.env.production` files or dotenvx files during deploys.
340
+ To use these files in your Trigger.dev environment:
341
+
342
+ ### Option 1 — Manually add your environment variables
343
+
344
+ 1. Open your `.env.production` (or `.env`) file
345
+ 2. Copy the full contents
346
+ 3. Go to your Trigger.dev project → **Environment Variables**
347
+ 4. Click **Add variables**
348
+ 5. Paste the contents directly into the editor
349
+
350
+ Trigger.dev will automatically parse and create each key/value pair.
351
+
352
+ This is the simplest way to bring dotenvx or `.env.production` variables into your Trigger.dev environment.
353
+
354
+ ### Option 2 — Sync variables automatically using `syncEnvVars`
355
+
356
+ If you'd prefer an automated flow, you can use the `syncEnvVars` build extension to programmatically load and return your variables:
357
+
358
+ ```ts
359
+ import { defineConfig } from "@trigger.dev/sdk";
360
+ import { syncEnvVars } from "@trigger.dev/build/extensions/core";
361
+ import dotenvx from "@dotenvx/dotenvx";
362
+ import { readFileSync } from "fs";
363
+
364
+ export default defineConfig({
365
+ project: "<project id>",
366
+ build: {
367
+ extensions: [
368
+ syncEnvVars(async () => {
369
+ const envContent = readFileSync(".env.production", "utf-8");
370
+ const parsed = dotenvx.parse(envContent);
371
+ return parsed ?? {};
372
+ }),
373
+ ],
374
+ },
375
+ });
376
+ ```
377
+
378
+ This will read your .env.production file using dotenvx and sync the variables to Trigger.dev during every deploy.
379
+
380
+ **Summary**
381
+
382
+ - Trigger.dev does not automatically detect .env.production or dotenvx files
383
+ - You can paste them manually into the dashboard
384
+ - Or sync them automatically using a build extension
385
+
386
+ ## Multi-tenant applications
387
+
388
+ If you're building a multi-tenant application where each tenant needs different environment variables (like tenant-specific API keys or database credentials), you don't need a separate project for each tenant. Instead, use a single project and load tenant-specific secrets at runtime.
389
+
390
+ <Note>
391
+ This is different from [syncing environment variables at deploy time](#sync-env-vars-from-another-service).
392
+ Here, secrets are loaded dynamically during task execution, not synced to Trigger.dev's environment variables.
393
+ </Note>
394
+
395
+ ### Recommended approach
396
+
397
+ Use a secrets service (Infisical, AWS Secrets Manager, HashiCorp Vault, etc.) to store tenant-specific secrets, then retrieve them at the start of each task run based on the tenant identifier in your payload or context.
398
+
399
+ **Important:** Never pass secrets in the task payload, as payloads are logged and visible in the dashboard.
400
+
401
+ ### Example implementation
402
+
403
+ ```ts
404
+ import { task } from "@trigger.dev/sdk";
405
+ import { SecretsManagerClient, GetSecretValueCommand } from "@aws-sdk/client-secrets-manager";
406
+
407
+ export const processTenantData = task({
408
+ id: "process-tenant-data",
409
+ run: async (payload: { tenantId: string; data: unknown }) => {
410
+ // Retrieve tenant-specific secret at runtime
411
+ const client = new SecretsManagerClient({ region: "us-east-1" });
412
+ const response = await client.send(
413
+ new GetSecretValueCommand({
414
+ SecretId: `tenants/${payload.tenantId}/supabase-key`,
415
+ })
416
+ );
417
+
418
+ const supabaseKey = JSON.parse(response.SecretString!).SUPABASE_SERVICE_KEY;
419
+
420
+ // Your task logic using the tenant-specific secret
421
+ // ...
422
+ },
423
+ });
424
+ ```
425
+
426
+ You can use any secrets service - see the [sync env vars section](#sync-env-vars-from-another-service) for an example with Infisical.
427
+
428
+ ### Benefits
429
+
430
+ - **Single codebase** - Deploy once, works for all tenants
431
+ - **Secure** - Secrets never appear in payloads or logs
432
+ - **Scalable** - No project limit constraints
433
+ - **Flexible** - Easy to add new tenants without redeploying
434
+
435
+ This approach allows you to support unlimited tenants with a single Trigger.dev project, avoiding the [project limit](/limits#projects) while maintaining security and separation of tenant data.
@@ -0,0 +1,172 @@
1
+ ---
2
+ title: "Atomic deploys"
3
+ sidebarTitle: "Atomic deploys"
4
+ description: "Use atomic deploys to coordinate changes to your tasks and your application."
5
+ ---
6
+
7
+ Atomic deploys in Trigger.dev allow you to synchronize the deployment of your application with a specific version of your tasks. This ensures that your application always uses the correct version of its associated tasks, preventing inconsistencies or errors due to version mismatches.
8
+
9
+ ## How it works
10
+
11
+ Atomic deploys achieve synchronization by deploying your tasks to Trigger.dev without promoting them to the default version. Instead, you explicitly specify the deployed task version in your application’s environment. Here’s the process at a glance:
12
+
13
+ 1. **Deploy Tasks to Trigger.dev**: Use the Trigger.dev CLI to deploy your tasks with the `--skip-promotion` flag. This creates a new task version without making it the default.
14
+ 2. **Capture the Deployment Version**: The CLI outputs the version of the deployed tasks, which you’ll use in the next step.
15
+ 3. **Deploy Your Application**: Deploy your application (e.g., to Vercel), setting an environment variable like `TRIGGER_VERSION` to the captured task version.
16
+
17
+ ## Vercel CLI & GitHub Actions
18
+
19
+ If you deploy to Vercel via their CLI, you can use this sample workflow that demonstrates performing atomic deploys with GitHub Actions, Trigger.dev, and Vercel:
20
+
21
+ ```yml
22
+ name: Deploy to Trigger.dev (prod)
23
+ on:
24
+ push:
25
+ branches:
26
+ - main
27
+ concurrency:
28
+ group: ${{ github.workflow }}
29
+ cancel-in-progress: true
30
+ jobs:
31
+ deploy:
32
+ runs-on: ubuntu-latest
33
+ steps:
34
+ - uses: actions/checkout@v4
35
+
36
+ - name: Use Node.js 20.x
37
+ uses: actions/setup-node@v4
38
+ with:
39
+ node-version: "20.x"
40
+
41
+ - name: Install dependencies
42
+ run: npm install
43
+
44
+ - name: Deploy Trigger.dev
45
+ id: deploy-trigger
46
+ env:
47
+ TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }}
48
+ run: |
49
+ npx trigger.dev@latest deploy --skip-promotion
50
+
51
+ - name: Deploy to Vercel
52
+ run: npx vercel --yes --prod -e TRIGGER_VERSION=$TRIGGER_VERSION --token $VERCEL_TOKEN
53
+ env:
54
+ VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
55
+ TRIGGER_VERSION: ${{ steps.deploy-trigger.outputs.deploymentVersion }}
56
+
57
+ - name: Promote Trigger.dev Version
58
+ run: npx trigger.dev@latest promote $TRIGGER_VERSION
59
+ env:
60
+ TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }}
61
+ TRIGGER_VERSION: ${{ steps.deploy-trigger.outputs.deploymentVersion }}
62
+ ```
63
+
64
+ - Deploy to Trigger.dev
65
+
66
+ - The `npx trigger.dev deploy` command uses `--skip-promotion` to deploy the tasks without setting the version as the default.
67
+ - The step’s id: `deploy-trigger` allows us to capture the deployment version in the output (deploymentVersion).
68
+
69
+ - Deploy to Vercel:
70
+ - The `npx vercel` command deploys the application, setting the `TRIGGER_VERSION` environment variable to the task version from the previous step.
71
+ - The --prod flag ensures a production deployment, and -e passes the environment variable.
72
+ - The `@trigger.dev/sdk` automatically uses the `TRIGGER_VERSION` environment variable to trigger the correct version of the tasks.
73
+
74
+ For this workflow to work, you need to set up the following secrets in your GitHub repository:
75
+
76
+ - `TRIGGER_ACCESS_TOKEN`: Your Trigger.dev personal access token. View the instructions [here](/github-actions) to learn more.
77
+ - `VERCEL_TOKEN`: Your Vercel personal access token. You can find this in your Vercel account settings.
78
+
79
+ ## Vercel GitHub integration
80
+
81
+ If you're are using Vercel, chances are you are using their GitHub integration and deploying your application directly from pushes to GitHub. This section covers how to achieve atomic deploys with Trigger.dev in this setup.
82
+
83
+ ### Turn off automatic promotion
84
+
85
+ By default, Vercel automatically promotes new deployments to production. To prevent this, you need to disable the auto-promotion feature in your Vercel project settings:
86
+
87
+ 1. Go to your Production environment settings in Vercel at `https://vercel.com/<team-slug>/<project-slug>/settings/environments/production`
88
+ 2. Disable the "Auto-assign Custom Production Domains" setting:
89
+
90
+ ![Vercel project settings showing the auto-promotion setting](/deployment/auto-assign-production-domains.png)
91
+
92
+ 3. Hit the "Save" button to apply the changes.
93
+
94
+ Now whenever you push to your main branch, Vercel will deploy your application to the production environment without promoting it, and you can control the promotion manually.
95
+
96
+ ### Deploy with Trigger.dev
97
+
98
+ Now we want to deploy that same commit to Trigger.dev, and then promote the Vercel deployment when that completes. Here's a sample GitHub Actions workflow that does this:
99
+
100
+ ```yml
101
+ name: Deploy to Trigger.dev (prod)
102
+
103
+ on:
104
+ push:
105
+ branches:
106
+ - main
107
+
108
+ concurrency:
109
+ group: ${{ github.workflow }}
110
+ cancel-in-progress: true
111
+
112
+ jobs:
113
+ deploy:
114
+ runs-on: ubuntu-latest
115
+
116
+ steps:
117
+ - uses: actions/checkout@v4
118
+
119
+ - name: Use Node.js 20.x
120
+ uses: actions/setup-node@v4
121
+ with:
122
+ node-version: "20.x"
123
+
124
+ - name: Install dependencies
125
+ run: npm install
126
+
127
+ - name: Wait for vercel deployment (push)
128
+ id: wait-for-vercel
129
+ uses: ludalex/vercel-wait@v1
130
+ with:
131
+ project-id: ${{ secrets.VERCEL_PROJECT_ID }}
132
+ team-id: ${{ secrets.VERCEL_SCOPE_NAME }}
133
+ token: ${{ secrets.VERCEL_TOKEN }}
134
+ sha: ${{ github.sha }}
135
+
136
+ - name: 🚀 Deploy Trigger.dev
137
+ id: deploy-trigger
138
+ env:
139
+ TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }}
140
+ run: |
141
+ npx trigger.dev@latest deploy
142
+
143
+ - name: Promote Vercel deploy
144
+ run: npx vercel promote $VERCEL_DEPLOYMENT_ID --yes --token $VERCEL_TOKEN --scope $VERCEL_SCOPE_NAME
145
+ env:
146
+ VERCEL_DEPLOYMENT_ID: ${{ steps.wait-for-vercel.outputs.deployment-id }}
147
+ VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
148
+ VERCEL_SCOPE_NAME: ${{ secrets.VERCEL_SCOPE_NAME }}
149
+ ```
150
+
151
+ This workflow does the following:
152
+
153
+ 1. Waits for the Vercel deployment to complete using the `ludalex/vercel-wait` action.
154
+ 2. Deploys the tasks to Trigger.dev using the `npx trigger.dev deploy` command. There's no need to use the `--skip-promotion` flag because we want to promote the deployment.
155
+ 3. Promotes the Vercel deployment using the `npx vercel promote` command.
156
+
157
+ For this workflow to work, you need to set up the following secrets in your GitHub repository:
158
+
159
+ - `TRIGGER_ACCESS_TOKEN`: Your Trigger.dev personal access token. View the instructions [here](/github-actions) to learn more.
160
+ - `VERCEL_TOKEN`: Your Vercel personal access token. You can find this in your Vercel account settings.
161
+ - `VERCEL_PROJECT_ID`: Your Vercel project ID. You can find this in your Vercel project settings.
162
+ - `VERCEL_SCOPE_NAME`: Your Vercel team slug.
163
+
164
+ Checkout our [example repo](https://github.com/ericallam/vercel-atomic-deploys) to see this workflow in action.
165
+
166
+ <Note>
167
+ We are using the `ludalex/vercel-wait` action above as a fork of the [official
168
+ tj-actions/vercel-wait](https://github.com/tj-actions/vercel-wait) action because there is a bug
169
+ in the official action that exits early if the deployment isn't found in the first check and due
170
+ to the fact that it supports treating skipped (cancelled) Vercel deployments as valid (on by default).
171
+ I've opened a PR for this issue [here](https://github.com/tj-actions/vercel-wait/pull/106).
172
+ </Note>