@trigger.dev/sdk 4.5.11 → 4.5.13

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 (102) hide show
  1. package/dist/commonjs/v3/ai.d.ts +154 -20
  2. package/dist/commonjs/v3/ai.js +1247 -406
  3. package/dist/commonjs/v3/ai.js.map +1 -1
  4. package/dist/commonjs/v3/auth.d.ts +3 -3
  5. package/dist/commonjs/v3/chat-client.d.ts +5 -4
  6. package/dist/commonjs/v3/chat-client.js +2 -6
  7. package/dist/commonjs/v3/chat-client.js.map +1 -1
  8. package/dist/commonjs/v3/chat.d.ts +7 -2
  9. package/dist/commonjs/v3/chat.js +22 -7
  10. package/dist/commonjs/v3/chat.js.map +1 -1
  11. package/dist/commonjs/v3/chat.test.js +13 -4
  12. package/dist/commonjs/v3/chat.test.js.map +1 -1
  13. package/dist/commonjs/v3/envvars.js.map +1 -1
  14. package/dist/commonjs/v3/retry.d.ts +1 -1
  15. package/dist/commonjs/v3/retry.js +1 -2
  16. package/dist/commonjs/v3/retry.js.map +1 -1
  17. package/dist/commonjs/v3/runs.d.ts +2 -6
  18. package/dist/commonjs/v3/runs.js.map +1 -1
  19. package/dist/commonjs/v3/schedules/api.d.ts +8 -1
  20. package/dist/commonjs/v3/schedules/index.d.ts +11 -6
  21. package/dist/commonjs/v3/schedules/index.js +2 -0
  22. package/dist/commonjs/v3/schedules/index.js.map +1 -1
  23. package/dist/commonjs/v3/schedules/index.test.d.ts +1 -0
  24. package/dist/commonjs/v3/schedules/index.test.js +49 -0
  25. package/dist/commonjs/v3/schedules/index.test.js.map +1 -0
  26. package/dist/commonjs/v3/schedules/index.types.test.d.ts +1 -0
  27. package/dist/commonjs/v3/schedules/index.types.test.js +93 -0
  28. package/dist/commonjs/v3/schedules/index.types.test.js.map +1 -0
  29. package/dist/commonjs/v3/sessions.d.ts +4 -10
  30. package/dist/commonjs/v3/sessions.js +73 -47
  31. package/dist/commonjs/v3/sessions.js.map +1 -1
  32. package/dist/commonjs/v3/shared.d.ts +2 -3
  33. package/dist/commonjs/v3/shared.js +14 -0
  34. package/dist/commonjs/v3/shared.js.map +1 -1
  35. package/dist/commonjs/v3/test/mock-chat-agent.d.ts +1 -1
  36. package/dist/commonjs/v3/test/mock-chat-agent.js +1 -0
  37. package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -1
  38. package/dist/commonjs/v3/test/test-session-handle.d.ts +1 -31
  39. package/dist/commonjs/v3/test/test-session-handle.js +22 -25
  40. package/dist/commonjs/v3/test/test-session-handle.js.map +1 -1
  41. package/dist/commonjs/version.js +1 -1
  42. package/dist/esm/v3/ai.d.ts +154 -20
  43. package/dist/esm/v3/ai.js +1245 -406
  44. package/dist/esm/v3/ai.js.map +1 -1
  45. package/dist/esm/v3/auth.d.ts +3 -3
  46. package/dist/esm/v3/chat-client.d.ts +5 -4
  47. package/dist/esm/v3/chat-client.js +2 -6
  48. package/dist/esm/v3/chat-client.js.map +1 -1
  49. package/dist/esm/v3/chat.d.ts +7 -2
  50. package/dist/esm/v3/chat.js +22 -7
  51. package/dist/esm/v3/chat.js.map +1 -1
  52. package/dist/esm/v3/chat.test.js +13 -4
  53. package/dist/esm/v3/chat.test.js.map +1 -1
  54. package/dist/esm/v3/envvars.js.map +1 -1
  55. package/dist/esm/v3/retry.d.ts +1 -1
  56. package/dist/esm/v3/retry.js +1 -2
  57. package/dist/esm/v3/retry.js.map +1 -1
  58. package/dist/esm/v3/runs.d.ts +2 -6
  59. package/dist/esm/v3/runs.js.map +1 -1
  60. package/dist/esm/v3/schedules/api.d.ts +8 -1
  61. package/dist/esm/v3/schedules/index.d.ts +11 -6
  62. package/dist/esm/v3/schedules/index.js +2 -0
  63. package/dist/esm/v3/schedules/index.js.map +1 -1
  64. package/dist/esm/v3/schedules/index.test.d.ts +1 -0
  65. package/dist/esm/v3/schedules/index.test.js +47 -0
  66. package/dist/esm/v3/schedules/index.test.js.map +1 -0
  67. package/dist/esm/v3/schedules/index.types.test.d.ts +1 -0
  68. package/dist/esm/v3/schedules/index.types.test.js +91 -0
  69. package/dist/esm/v3/schedules/index.types.test.js.map +1 -0
  70. package/dist/esm/v3/sessions.d.ts +4 -10
  71. package/dist/esm/v3/sessions.js +73 -47
  72. package/dist/esm/v3/sessions.js.map +1 -1
  73. package/dist/esm/v3/shared.d.ts +2 -3
  74. package/dist/esm/v3/shared.js +15 -1
  75. package/dist/esm/v3/shared.js.map +1 -1
  76. package/dist/esm/v3/test/mock-chat-agent.d.ts +1 -1
  77. package/dist/esm/v3/test/mock-chat-agent.js +2 -1
  78. package/dist/esm/v3/test/mock-chat-agent.js.map +1 -1
  79. package/dist/esm/v3/test/test-session-handle.d.ts +1 -31
  80. package/dist/esm/v3/test/test-session-handle.js +24 -25
  81. package/dist/esm/v3/test/test-session-handle.js.map +1 -1
  82. package/dist/esm/version.js +1 -1
  83. package/docs/ai-chat/client-protocol.mdx +8 -3
  84. package/docs/ai-chat/custom-agents.mdx +181 -46
  85. package/docs/ai-chat/patterns/recovery-boot.mdx +9 -2
  86. package/docs/ai-chat/patterns/version-upgrades.mdx +26 -6
  87. package/docs/ai-chat/pending-messages.mdx +5 -3
  88. package/docs/ai-chat/reference.mdx +26 -10
  89. package/docs/ai-chat/types.mdx +5 -1
  90. package/docs/apikeys.mdx +159 -27
  91. package/docs/deployment/atomic-deployment.mdx +12 -0
  92. package/docs/deployment/overview.mdx +7 -1
  93. package/docs/deployment/version-skew-protection.mdx +430 -0
  94. package/docs/github-actions.mdx +33 -5
  95. package/docs/github-integration.mdx +12 -0
  96. package/docs/realtime/auth.mdx +3 -1
  97. package/docs/self-hosting/env/supervisor.mdx +1 -0
  98. package/docs/self-hosting/env/webapp.mdx +1 -0
  99. package/docs/tasks/scheduled.mdx +45 -0
  100. package/docs/vercel-integration.mdx +43 -9
  101. package/docs/versioning.mdx +2 -0
  102. package/package.json +3 -15
package/docs/apikeys.mdx CHANGED
@@ -1,54 +1,186 @@
1
1
  ---
2
2
  title: "API keys"
3
- description: "How to authenticate with Trigger.dev so you can trigger tasks."
3
+ description: "Authenticate backend requests with environment-specific API keys."
4
4
  ---
5
5
 
6
- ### Authentication and your secret keys
6
+ **API keys authenticate backend requests to a specific Trigger.dev project and environment.** Each environment can have multiple keys, with optional scopes and restrictions attached.
7
7
 
8
- When you [trigger a task](/triggering) from your backend code, you need to set the `TRIGGER_SECRET_KEY` environment variable.
8
+ <Warning>
9
+ API keys grant access to your Trigger.dev environment. Store them in a secret manager or backend
10
+ environment variable, never commit them to source control, and never expose them in frontend code.
11
+ </Warning>
9
12
 
10
- Each environment has its own secret key. You can find the value on the API keys page in the Trigger.dev dashboard:
13
+ ## Find your API keys
11
14
 
12
- ![How to find your secret key](/images/api-keys.png)
15
+ Open your project in the dashboard, select an environment, and open the [**API keys**](https://cloud.trigger.dev/_/apikeys) page.
16
+
17
+ API keys belong to one environment. A Development key cannot access Production, and a Production key cannot access Staging.
13
18
 
14
19
  <Note>
15
- For preview branches, you need to also set the `TRIGGER_PREVIEW_BRANCH` environment variable as
16
- well. You can find the value on the API keys page when you're on the preview branch.
20
+ Every team member has their own Development environment and keys. Copy the Development key from
21
+ your own API keys page so local requests run against your machine.
17
22
  </Note>
18
23
 
19
- ### Automatically Configuring the SDK
24
+ ## Configure the SDK
20
25
 
21
- To automatically configure the SDK with your secret key, you can set the `TRIGGER_SECRET_KEY` environment variable. The SDK will automatically use this value when calling API methods (like `trigger`).
26
+ Set `TRIGGER_SECRET_KEY` in your backend environment. The SDK reads it automatically for operations such as triggering tasks and retrieving runs.
22
27
 
23
28
  ```bash .env
24
- TRIGGER_SECRET_KEY="tr_dev_…"
25
- TRIGGER_PREVIEW_BRANCH="my-branch" # Only needed for preview branches
29
+ TRIGGER_SECRET_KEY="tr_prod_sk_…"
30
+ ```
31
+
32
+ To configure the SDK in code, pass the key to `configure`:
33
+
34
+ ```ts Your backend code
35
+ import { configure, tasks } from "@trigger.dev/sdk";
36
+ import type { sendEmail } from "./trigger/send-email";
37
+
38
+ configure({
39
+ secretKey: process.env.TRIGGER_SECRET_KEY,
40
+ previewBranch: "my-branch", // Only needed for preview branches
41
+ baseURL: "https://mytrigger.example.com", // Optional
42
+ });
43
+
44
+ await tasks.trigger<typeof sendEmail>("send-email", {
45
+ to: "user@example.com",
46
+ });
26
47
  ```
27
48
 
28
- You can do the same if you are self-hosting and need to change the default URL by using `TRIGGER_API_URL`.
49
+ If you self-host Trigger.dev, set `TRIGGER_API_URL` or pass `baseURL` to `configure`:
29
50
 
30
51
  ```bash .env
52
+ TRIGGER_SECRET_KEY="tr_prod_…"
31
53
  TRIGGER_API_URL="https://trigger.example.com"
32
- TRIGGER_PREVIEW_BRANCH="my-branch" # Only needed for preview branches
33
54
  ```
34
55
 
35
- The default URL is `https://api.trigger.dev`.
56
+ The default API URL is `https://api.trigger.dev`.
57
+
58
+ ## Create a key
36
59
 
37
- ### Manually Configuring the SDK
60
+ Create a separate key for each service or integration that accesses Trigger.dev.
38
61
 
39
- If you prefer to manually configure the SDK, you can call the `configure` method:
62
+ <Note>
63
+ Creating and revoking keys requires permission to manage API keys for the selected environment.
64
+ The dashboard disables these actions when your role does not have permission.
65
+ </Note>
40
66
 
41
- ```ts
42
- import { configure } from "@trigger.dev/sdk";
43
- import { myTask } from "./trigger/myTasks";
67
+ <Steps titleSize="h3">
68
+ <Step title="Open the API keys page">
69
+ Select the project and environment the integration needs to access, then open [**API keys**](https://cloud.trigger.dev/_/apikeys).
70
+ </Step>
71
+ <Step title="Create the key">
72
+ Click **New API key**, enter a descriptive name, and optionally set an expiration date. Names can
73
+ contain up to 64 characters.
74
+ </Step>
75
+ <Step title="Choose its access">
76
+ Select an access preset. For task-aware presets, choose all tasks or up to 10 task identifiers.
77
+ </Step>
78
+ <Step title="Copy and store the secret">
79
+ Copy the key into your secret manager or backend environment. Trigger.dev shows the complete
80
+ value only once.
81
+ </Step>
82
+ </Steps>
83
+
84
+ ## Access presets
85
+
86
+ Access presets define what a key can do. Some presets require a paid plan. The dashboard shows which presets your organization can use — see [pricing](https://trigger.dev/pricing).
87
+
88
+ | Preset | Access |
89
+ | --- | --- |
90
+ | **Trigger only** | Trigger runs and batches for all or selected tasks. Trigger responses include scoped public access tokens for the runs and batches they create |
91
+ | **Task operator** | Trigger all or selected tasks and inspect or operate on their runs |
92
+ | **Observer** | Read runs, tasks, batches, logs, traces, and queues |
93
+ | **Operator** | Observe and operate on runs and queues, and trigger tasks |
94
+ | **Deploy only** | Deploy versions, sync environment variables, and manage Preview branches |
95
+ | **Variables only** | Read and write environment variables in this environment |
96
+ | **No restrictions** | Full access to the environment |
97
+
98
+ **Trigger only** and **Task operator** can be restricted to selected tasks. Task restrictions use task identifiers, such as `send-email`. A request involving multiple tasks — such as a batch trigger — succeeds only when the key can access every task in the request, so a task-restricted key can batch-trigger only its selected tasks.
99
+
100
+ ## Deploy with an API key
101
+
102
+ Set a key in `TRIGGER_ACCESS_TOKEN` to authenticate `trigger deploy` without logging in.
103
+
104
+ <CodeGroup>
105
+
106
+ ```bash npm
107
+ TRIGGER_ACCESS_TOKEN="tr_prod_sk_…" npx trigger.dev@latest deploy
108
+ ```
109
+ </CodeGroup>
44
110
 
45
- configure({
46
- secretKey: "tr_dev_1234", // WARNING: Never actually hardcode your secret key like this
47
- previewBranch: "my-branch", // Only needed for preview branches
48
- baseURL: "https://mytrigger.example.com", // Optional
49
- });
111
+ The key must belong to the target environment. Use a Production key for the default deployment, a Staging key with `--env staging`, or a key from the Preview environment with `--env preview`. A Preview deployment key can create and archive Preview branches and sync their environment variables.
112
+
113
+ <Note>
114
+ The deploy CLI reads environment API keys from `TRIGGER_ACCESS_TOKEN`, not
115
+ `TRIGGER_SECRET_KEY`. Setting an API key in `TRIGGER_ACCESS_TOKEN` takes precedence over a saved
116
+ CLI login.
117
+ </Note>
118
+
119
+ ## Expire and revoke keys
120
+
121
+ Set an expiration date when creating a key if the integration only needs temporary access. An expired key stops authenticating automatically.
50
122
 
51
- async function triggerTask() {
52
- await myTask.trigger({ userId: "1234" }); // This will use the secret key and base URL you configured
53
- }
123
+ Revoking a key takes effect immediately and cannot be reversed. Requests using the key fail, and the key can no longer create public access tokens. Create a replacement before revoking a key when you need to rotate it without interrupting the integration.
124
+
125
+ Removing a team member does not revoke keys they created. Review and revoke their keys separately when their access changes.
126
+
127
+ ## Root keys
128
+
129
+ <Warning>
130
+ Root keys are legacy, and are likely to be deprecated in the future. We recommend against using them.
131
+ </Warning>
132
+
133
+ Each environment has a single legacy root key. It can be regenerated, which creates a new value immediately. The previous root key remains valid for 24 hours so you can update services without downtime, then stops authenticating.
134
+
135
+ Public access tokens signed with the previous root key remain valid until the earlier of their own expiration and the end of the 24-hour grace period.
136
+
137
+ ## Create public access tokens
138
+
139
+ API keys can be used to create scoped [Public Access Tokens](/realtime/auth) using `auth.createPublicToken()`.
140
+
141
+ To do so with the newer non-root keys, you must use `@trigger.dev/sdk` version 4.5.8 or later. Creating public tokens with non-root keys has the following restrictions:
142
+
143
+ - The token must request at least one scope.
144
+ - Its scopes cannot exceed the key's access.
145
+ - Its expiration cannot exceed 30 days.
146
+
147
+ <Note>
148
+ Revoking or expiring an API key does not revoke tokens it already created. Those tokens remain valid until their own expiration, unless the environment's root key is regenerated.
149
+ </Note>
150
+
151
+ ## Target Preview and Development branches
152
+
153
+ Preview and named Development branches use their parent environment's keys. Select the branch by setting `TRIGGER_PREVIEW_BRANCH` alongside the environment key:
154
+
155
+ ```bash .env
156
+ TRIGGER_SECRET_KEY="tr_preview_sk_…"
157
+ TRIGGER_PREVIEW_BRANCH="feature/new-checkout"
54
158
  ```
159
+
160
+ The SDK sends the branch automatically. When calling the API directly, send the same value in the `x-trigger-branch` header.
161
+
162
+ ## Self-hosting
163
+
164
+ Self-hosted installations support multiple keys with **No restrictions**. The restricted access presets are available in Trigger.dev Cloud.
165
+
166
+ Keep your instance and SDK current before creating keys. Calling a public-token API with a key on a server that does not support server-minted tokens returns an upgrade error; use the root key until the server is upgraded.
167
+
168
+ ## Security recommendations
169
+
170
+ - Create one key per service or integration instead of sharing keys.
171
+ - Choose the narrowest access preset and task selection that supports the integration.
172
+ - Store keys in a secret manager and inject them as backend environment variables.
173
+ - Set expiration dates for temporary integrations and deployment credentials.
174
+ - Revoke keys when an integration or team member no longer needs access.
175
+ - Never put an API key in frontend code. Use scoped [Public Access Tokens](/realtime/auth) for client-side access.
176
+
177
+ ## Next steps
178
+
179
+ <CardGroup cols={2}>
180
+ <Card title="Trigger tasks" icon="bolt" href="/triggering">
181
+ Trigger tasks from your backend with an environment API key.
182
+ </Card>
183
+ <Card title="Realtime authentication" icon="key" href="/realtime/auth">
184
+ Create scoped public tokens for frontend and realtime access.
185
+ </Card>
186
+ </CardGroup>
@@ -4,6 +4,18 @@ sidebarTitle: "Atomic deploys"
4
4
  description: "Use atomic deploys to coordinate changes to your tasks and your application."
5
5
  ---
6
6
 
7
+ <Warning>
8
+ **There's now a simpler way to do this.** [Version skew
9
+ protection](/deployment/version-skew-protection) solves the same problem without a second
10
+ deployment, without gating your app's deploy, and without setting `TRIGGER_VERSION` — and it covers
11
+ staging and preview as well as production. If you use the [Vercel
12
+ integration](/vercel-integration), its **automatic atomic deployments** setting is now deprecated
13
+ in favour of skew protection.
14
+
15
+ The manual workflows on this page still work, and remain the right answer if you specifically want
16
+ your application's deployment held back until your tasks have finished building.
17
+ </Warning>
18
+
7
19
  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
20
 
9
21
  ## How it works
@@ -122,6 +122,12 @@ If you want to set a global version to run all tasks against, you can use the `T
122
122
  TRIGGER_VERSION=20250228.1
123
123
  ```
124
124
 
125
+ <Tip>
126
+ If what you actually want is for each release of your app to run against the tasks built from the
127
+ same commit, you don't need to plumb version numbers around by hand. See [version skew
128
+ protection](/deployment/version-skew-protection).
129
+ </Tip>
130
+
125
131
  ### Child tasks and auto-version locking
126
132
 
127
133
  Trigger and wait functions version lock child task runs to the parent task run version. This ensures the results from child runs match what the parent task is expecting. If you don't wait then version locking doesn't apply.
@@ -155,7 +161,7 @@ Or from the dashboard:
155
161
 
156
162
  ![Trigger.dev dashboard showing the promote button](/deployment/promote-button.png)
157
163
 
158
- To learn more about skipping promotion and how this enables atomic deployments, see our [Atomic deployment](/deployment/atomic-deployment) guide.
164
+ To learn more about skipping promotion and how this enables atomic deployments, see our [Atomic deployment](/deployment/atomic-deployment) guide. To keep your app and tasks in sync without coordinating promotion at all, see [version skew protection](/deployment/version-skew-protection).
159
165
 
160
166
  ## Staging deploys
161
167