@trigger.dev/sdk 0.0.0-prerelease-20250503193704 → 0.0.0-prerelease-20250703115146
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.
- package/dist/commonjs/v3/auth.d.ts +37 -1
- package/dist/commonjs/v3/auth.js +5 -0
- package/dist/commonjs/v3/auth.js.map +1 -1
- package/dist/commonjs/v3/runs.d.ts +39 -2
- package/dist/commonjs/v3/runs.js +5 -2
- package/dist/commonjs/v3/runs.js.map +1 -1
- package/dist/commonjs/v3/schedules/index.d.ts +17 -2
- package/dist/commonjs/v3/schedules/index.js +2 -0
- package/dist/commonjs/v3/schedules/index.js.map +1 -1
- package/dist/commonjs/v3/wait.d.ts +35 -3
- package/dist/commonjs/v3/wait.js +106 -54
- package/dist/commonjs/v3/wait.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/auth.d.ts +37 -1
- package/dist/esm/v3/auth.js +6 -1
- package/dist/esm/v3/auth.js.map +1 -1
- package/dist/esm/v3/runs.d.ts +39 -2
- package/dist/esm/v3/runs.js +5 -2
- package/dist/esm/v3/runs.js.map +1 -1
- package/dist/esm/v3/schedules/index.d.ts +17 -2
- package/dist/esm/v3/schedules/index.js +2 -0
- package/dist/esm/v3/schedules/index.js.map +1 -1
- package/dist/esm/v3/wait.d.ts +35 -3
- package/dist/esm/v3/wait.js +107 -55
- package/dist/esm/v3/wait.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ApiClientConfiguration } from "@trigger.dev/core/v3";
|
|
1
|
+
import { type ApiClientConfiguration, RealtimeRunSkipColumns } from "@trigger.dev/core/v3";
|
|
2
2
|
/**
|
|
3
3
|
* Register the global API client configuration. Alternatively, you can set the `TRIGGER_SECRET_KEY` and `TRIGGER_API_URL` environment variables.
|
|
4
4
|
* @param options The API client configuration.
|
|
@@ -90,6 +90,23 @@ export type CreatePublicTokenOptions = {
|
|
|
90
90
|
* ```
|
|
91
91
|
*/
|
|
92
92
|
expirationTime?: number | Date | string;
|
|
93
|
+
realtime?: {
|
|
94
|
+
/**
|
|
95
|
+
* Skip columns from the subscription.
|
|
96
|
+
*
|
|
97
|
+
* @default []
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* auth.createPublicToken({
|
|
102
|
+
* realtime: {
|
|
103
|
+
* skipColumns: ["payload", "output"]
|
|
104
|
+
* }
|
|
105
|
+
* });
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
skipColumns?: RealtimeRunSkipColumns;
|
|
109
|
+
};
|
|
93
110
|
};
|
|
94
111
|
/**
|
|
95
112
|
* Creates a public token using the provided options.
|
|
@@ -97,6 +114,8 @@ export type CreatePublicTokenOptions = {
|
|
|
97
114
|
* @param options - Optional parameters for creating the public token.
|
|
98
115
|
* @param options.scopes - An array of permission scopes to be included in the token.
|
|
99
116
|
* @param options.expirationTime - The expiration time for the token.
|
|
117
|
+
* @param options.realtime - Options for realtime subscriptions.
|
|
118
|
+
* @param options.realtime.skipColumns - Skip columns from the subscription.
|
|
100
119
|
* @returns A promise that resolves to a string representing the generated public token.
|
|
101
120
|
*
|
|
102
121
|
* @example
|
|
@@ -136,6 +155,23 @@ export type CreateTriggerTokenOptions = {
|
|
|
136
155
|
* @default false
|
|
137
156
|
*/
|
|
138
157
|
multipleUse?: boolean;
|
|
158
|
+
realtime?: {
|
|
159
|
+
/**
|
|
160
|
+
* Skip columns from the subscription.
|
|
161
|
+
*
|
|
162
|
+
* @default []
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* auth.createTriggerPublicToken("my-task", {
|
|
167
|
+
* realtime: {
|
|
168
|
+
* skipColumns: ["payload", "output"]
|
|
169
|
+
* }
|
|
170
|
+
* });
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
skipColumns?: RealtimeRunSkipColumns;
|
|
174
|
+
};
|
|
139
175
|
};
|
|
140
176
|
/**
|
|
141
177
|
* Creates a one-time use token to trigger a specific task.
|
package/dist/commonjs/v3/auth.js
CHANGED
|
@@ -40,6 +40,8 @@ exports.auth = {
|
|
|
40
40
|
* @param options - Optional parameters for creating the public token.
|
|
41
41
|
* @param options.scopes - An array of permission scopes to be included in the token.
|
|
42
42
|
* @param options.expirationTime - The expiration time for the token.
|
|
43
|
+
* @param options.realtime - Options for realtime subscriptions.
|
|
44
|
+
* @param options.realtime.skipColumns - Skip columns from the subscription.
|
|
43
45
|
* @returns A promise that resolves to a string representing the generated public token.
|
|
44
46
|
*
|
|
45
47
|
* @example
|
|
@@ -63,6 +65,7 @@ async function createPublicToken(options) {
|
|
|
63
65
|
payload: {
|
|
64
66
|
...claims,
|
|
65
67
|
scopes: options?.scopes ? flattenScopes(options.scopes) : undefined,
|
|
68
|
+
realtime: options?.realtime,
|
|
66
69
|
},
|
|
67
70
|
expirationTime: options?.expirationTime,
|
|
68
71
|
});
|
|
@@ -117,6 +120,7 @@ async function createTriggerPublicToken(task, options) {
|
|
|
117
120
|
payload: {
|
|
118
121
|
...claims,
|
|
119
122
|
otu: typeof options?.multipleUse === "boolean" ? !options.multipleUse : true,
|
|
123
|
+
realtime: options?.realtime,
|
|
120
124
|
scopes: flattenScopes({
|
|
121
125
|
trigger: {
|
|
122
126
|
tasks: task,
|
|
@@ -176,6 +180,7 @@ async function createBatchTriggerPublicToken(task, options) {
|
|
|
176
180
|
payload: {
|
|
177
181
|
...claims,
|
|
178
182
|
otu: typeof options?.multipleUse === "boolean" ? !options.multipleUse : true,
|
|
183
|
+
realtime: options?.realtime,
|
|
179
184
|
scopes: flattenScopes({
|
|
180
185
|
batchTrigger: {
|
|
181
186
|
tasks: task,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/v3/auth.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"auth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zB,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC;wBAC7D,CAAC;oBACH,CAAC;yBAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;wBACrC,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,QAAQ,IAAI,KAAK,EAAE,CAAC,CAAC;oBAC9D,CAAC;yBAAM,IAAI,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,EAAE,CAAC;wBAC/C,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,QAAQ,EAAE,CAAC,CAAC;oBACrD,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,oBAAoB,CAAC;AAC9B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyRetrieveRunResult, AnyRunShape, ApiRequestOptions, InferRunTypes, ListProjectRunsQueryParams, ListRunsQueryParams, RescheduleRunRequestBody, RetrieveRunResult, RunShape, RealtimeRun, AnyRealtimeRun, RunSubscription, TaskRunShape, AnyBatchedRunHandle, AsyncIterableStream, ApiPromise } from "@trigger.dev/core/v3";
|
|
1
|
+
import type { AnyRetrieveRunResult, AnyRunShape, ApiRequestOptions, InferRunTypes, ListProjectRunsQueryParams, ListRunsQueryParams, RescheduleRunRequestBody, RetrieveRunResult, RunShape, RealtimeRun, AnyRealtimeRun, RunSubscription, TaskRunShape, AnyBatchedRunHandle, AsyncIterableStream, ApiPromise, RealtimeRunSkipColumns } from "@trigger.dev/core/v3";
|
|
2
2
|
import { CanceledRunResponse, CursorPagePromise, ListRunResponseItem, ReplayRunResponse, RetrieveRunResponse } from "@trigger.dev/core/v3";
|
|
3
3
|
import { AnyRunHandle, AnyTask } from "./shared.js";
|
|
4
4
|
export type { AnyRetrieveRunResult, AnyRunShape, RetrieveRunResult, RunShape, TaskRunShape, RealtimeRun, AnyRealtimeRun, };
|
|
@@ -187,6 +187,17 @@ export type SubscribeToRunOptions = {
|
|
|
187
187
|
* Set this to false if you are making updates to the run metadata after completion through child runs
|
|
188
188
|
*/
|
|
189
189
|
stopOnCompletion?: boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Skip columns from the subscription.
|
|
192
|
+
*
|
|
193
|
+
* @default []
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* runs.subscribeToRun("123", { skipColumns: ["payload", "output"] });
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
skipColumns?: RealtimeRunSkipColumns;
|
|
190
201
|
};
|
|
191
202
|
/**
|
|
192
203
|
* Subscribes to real-time updates for a specific run.
|
|
@@ -220,6 +231,30 @@ export type SubscribeToRunOptions = {
|
|
|
220
231
|
* ```
|
|
221
232
|
*/
|
|
222
233
|
declare function subscribeToRun<TRunId extends AnyRunHandle | AnyTask | string>(runId: RunId<TRunId>, options?: SubscribeToRunOptions): RunSubscription<InferRunTypes<TRunId>>;
|
|
234
|
+
export type SubscribeToRunsFilterOptions = {
|
|
235
|
+
/**
|
|
236
|
+
* Filter runs by the time they were created. You must specify the duration string like "1h", "10s", "30m", etc.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* "1h" - 1 hour ago
|
|
240
|
+
* "10s" - 10 seconds ago
|
|
241
|
+
* "30m" - 30 minutes ago
|
|
242
|
+
* "1d" - 1 day ago
|
|
243
|
+
* "1w" - 1 week ago
|
|
244
|
+
*
|
|
245
|
+
* The maximum duration is 1 week
|
|
246
|
+
*
|
|
247
|
+
* @note The timestamp will be calculated on the server side when you first subscribe to the runs.
|
|
248
|
+
*
|
|
249
|
+
*/
|
|
250
|
+
createdAt?: string;
|
|
251
|
+
/**
|
|
252
|
+
* Skip columns from the subscription.
|
|
253
|
+
*
|
|
254
|
+
* @default []
|
|
255
|
+
*/
|
|
256
|
+
skipColumns?: RealtimeRunSkipColumns;
|
|
257
|
+
};
|
|
223
258
|
/**
|
|
224
259
|
* Subscribes to real-time updates for all runs that have specific tags.
|
|
225
260
|
*
|
|
@@ -250,7 +285,9 @@ declare function subscribeToRun<TRunId extends AnyRunHandle | AnyTask | string>(
|
|
|
250
285
|
* }
|
|
251
286
|
* ```
|
|
252
287
|
*/
|
|
253
|
-
declare function subscribeToRunsWithTag<TTasks extends AnyTask>(tag: string | string[]
|
|
288
|
+
declare function subscribeToRunsWithTag<TTasks extends AnyTask>(tag: string | string[], filters?: SubscribeToRunsFilterOptions, options?: {
|
|
289
|
+
signal?: AbortSignal;
|
|
290
|
+
}): RunSubscription<InferRunTypes<TTasks>>;
|
|
254
291
|
/**
|
|
255
292
|
* Subscribes to real-time updates for all runs within a specific batch.
|
|
256
293
|
*
|
package/dist/commonjs/v3/runs.js
CHANGED
|
@@ -232,6 +232,7 @@ function subscribeToRun(runId, options) {
|
|
|
232
232
|
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
233
233
|
return apiClient.subscribeToRun($runId, {
|
|
234
234
|
closeOnComplete: typeof options?.stopOnCompletion === "boolean" ? options.stopOnCompletion : true,
|
|
235
|
+
skipColumns: options?.skipColumns,
|
|
235
236
|
});
|
|
236
237
|
}
|
|
237
238
|
/**
|
|
@@ -264,9 +265,11 @@ function subscribeToRun(runId, options) {
|
|
|
264
265
|
* }
|
|
265
266
|
* ```
|
|
266
267
|
*/
|
|
267
|
-
function subscribeToRunsWithTag(tag) {
|
|
268
|
+
function subscribeToRunsWithTag(tag, filters, options) {
|
|
268
269
|
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
269
|
-
return apiClient.subscribeToRunsWithTag(tag
|
|
270
|
+
return apiClient.subscribeToRunsWithTag(tag, filters, {
|
|
271
|
+
...(options ? { signal: options.signal } : {}),
|
|
272
|
+
});
|
|
270
273
|
}
|
|
271
274
|
/**
|
|
272
275
|
* Subscribes to real-time updates for all runs within a specific batch.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runs.js","sourceRoot":"","sources":["../../../src/v3/runs.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"runs.js","sourceRoot":"","sources":["../../../src/v3/runs.ts"],"names":[],"mappings":";;;AAmBA,6CAW8B;AAC9B,gFAAuF;AAEvF,2CAAqC;AAYxB,QAAA,IAAI,GAAG;IAClB,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,SAAS;IACjB,QAAQ,EAAE,WAAW;IACrB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE,aAAa;IACzB,IAAI;IACJ,cAAc;IACd,sBAAsB;IACtB,gBAAgB,EAAE,sBAAsB;IACxC,WAAW;CACZ,CAAC;AAaF,SAAS,QAAQ,CACf,kBAAiD,EACjD,eAAsF,EACtF,cAAkC;IAElC,MAAM,SAAS,GAAG,qBAAgB,CAAC,aAAa,EAAE,CAAC;IAEnD,MAAM,eAAe,GAAG,sBAAsB,CAC5C,kBAAkB,EAClB,eAAe,EACf,cAAc,CACf,CAAC;IAEF,IAAI,OAAO,kBAAkB,KAAK,QAAQ,EAAE,CAAC;QAC3C,IAAI,IAAA,qBAAgB,EAAC,eAAe,CAAC,EAAE,CAAC;YACtC,OAAO,SAAS,CAAC,eAAe,CAAC,kBAAkB,EAAE,EAAE,EAAE,eAAe,CAAC,CAAC;QAC5E,CAAC;aAAM,CAAC;YACN,OAAO,SAAS,CAAC,eAAe,CAAC,kBAAkB,EAAE,eAAe,EAAE,eAAe,CAAC,CAAC;QACzF,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;AACjE,CAAC;AAED,SAAS,sBAAsB,CAC7B,kBAAiD,EACjD,eAAsF,EACtF,cAAkC;IAElC,IAAI,OAAO,kBAAkB,KAAK,QAAQ,EAAE,CAAC;QAC3C,IAAI,IAAA,qBAAgB,EAAC,eAAe,CAAC,EAAE,CAAC;YACtC,OAAO,IAAA,wBAAmB,EACxB;gBACE,MAAM,EAAN,kBAAM;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SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -9,11 +9,12 @@ export type ScheduleOptions<TIdentifier extends string, TOutput, TInitOutput ext
|
|
|
9
9
|
* "0 0 * * *"
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
12
|
-
* 2. Or an object with a pattern
|
|
12
|
+
* 2. Or an object with a pattern, optional timezone, and optional environments
|
|
13
13
|
* ```ts
|
|
14
14
|
* {
|
|
15
15
|
* pattern: "0 0 * * *",
|
|
16
|
-
* timezone: "America/Los_Angeles"
|
|
16
|
+
* timezone: "America/Los_Angeles",
|
|
17
|
+
* environments: ["PRODUCTION", "STAGING"]
|
|
17
18
|
* }
|
|
18
19
|
* ```
|
|
19
20
|
*
|
|
@@ -22,6 +23,20 @@ export type ScheduleOptions<TIdentifier extends string, TOutput, TInitOutput ext
|
|
|
22
23
|
cron?: string | {
|
|
23
24
|
pattern: string;
|
|
24
25
|
timezone?: string;
|
|
26
|
+
/** You can optionally specify which environments this schedule should run in.
|
|
27
|
+
* When not specified, the schedule will run in all environments.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* environments: ["PRODUCTION", "STAGING"]
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* environments: ["PRODUCTION"] // Only run in production
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
environments?: Array<"DEVELOPMENT" | "STAGING" | "PRODUCTION" | "PREVIEW">;
|
|
25
40
|
};
|
|
26
41
|
};
|
|
27
42
|
export declare function task<TIdentifier extends string, TOutput, TInitOutput extends InitOutput>(params: ScheduleOptions<TIdentifier, TOutput, TInitOutput>): Task<TIdentifier, SchedulesAPI.ScheduledTaskPayload, TOutput>;
|
|
@@ -21,12 +21,14 @@ function task(params) {
|
|
|
21
21
|
: params.cron.pattern
|
|
22
22
|
: undefined;
|
|
23
23
|
const timezone = (params.cron && typeof params.cron !== "string" ? params.cron.timezone : "UTC") ?? "UTC";
|
|
24
|
+
const environments = params.cron && typeof params.cron !== "string" ? params.cron.environments : undefined;
|
|
24
25
|
v3_1.resourceCatalog.updateTaskMetadata(task.id, {
|
|
25
26
|
triggerSource: "schedule",
|
|
26
27
|
schedule: cron
|
|
27
28
|
? {
|
|
28
29
|
cron: cron,
|
|
29
30
|
timezone,
|
|
31
|
+
environments,
|
|
30
32
|
}
|
|
31
33
|
: undefined,
|
|
32
34
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/v3/schedules/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/v3/schedules/index.ts"],"names":[],"mappings":";;AA+DA,oBA2BC;AAYD,wBA2BC;AAOD,4BA4BC;AAYD,wBA6BC;AAMD,kBA4BC;AAMD,gCA4BC;AAMD,4BA4BC;AASD,oBAgBC;AAMD,8BAaC;AA/VD,6CAY8B;AAC9B,4DAAyD;AACzD,4CAA6D;AAE7D,4CAAsC;AA+CtC,SAAgB,IAAI,CAClB,MAA0D;IAE1D,MAAM,IAAI,GAAG,IAAA,sBAAU,EAAC,MAAM,CAAC,CAAC;IAEhC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI;QACtB,CAAC,CAAC,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;YAC/B,CAAC,CAAC,MAAM,CAAC,IAAI;YACb,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO;QACvB,CAAC,CAAC,SAAS,CAAC;IACd,MAAM,QAAQ,GACZ,CAAC,MAAM,CAAC,IAAI,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;IAC3F,MAAM,YAAY,GAChB,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S,GAAG,qBAAgB,CAAC,aAAa,EAAE,CAAC;IAEnD,MAAM,eAAe,GAAG,IAAA,wBAAmB,EACzC;QACE,MAAM,EAAN,kBAAM;QACN,IAAI,EAAE,kBAAkB;QACxB,IAAI,EAAE,OAAO;KACd,EACD,cAAc,CACf,CAAC;IAEF,OAAO,SAAS,CAAC,aAAa,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;AAC3D,CAAC;AAED;;;GAGG;AACH,SAAgB,SAAS,CAAC,OAAkC;IAC1D,MAAM,OAAO,GAAG,qBAAgB,CAAC,OAAO,CAAC;IAEzC,OAAO,IAAA,mBAAQ,EACb,oBAAe,EACf,GAAG,OAAO,oBAAoB,OAAO,EAAE,UAAU,KAAK,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,EAAE,EACtF;QACE,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;KACF,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { ApiPromise, ApiRequestOptions, CreateWaitpointTokenRequestBody,
|
|
1
|
+
import { ApiPromise, ApiRequestOptions, CreateWaitpointTokenRequestBody, CreateWaitpointTokenResponse, CursorPagePromise, ListWaitpointTokensQueryParams, WaitpointListTokenItem, WaitpointTokenStatus, WaitpointTokenTypedResult } from "@trigger.dev/core/v3";
|
|
2
2
|
/**
|
|
3
3
|
* This creates a waitpoint token.
|
|
4
4
|
* You can use this to pause a run until you complete the waitpoint (or it times out).
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
7
|
*
|
|
8
|
+
* **Manually completing a token**
|
|
9
|
+
*
|
|
8
10
|
* ```ts
|
|
9
11
|
* const token = await wait.createToken({
|
|
10
12
|
* idempotencyKey: `approve-document-${documentId}`,
|
|
@@ -19,6 +21,30 @@ import { ApiPromise, ApiRequestOptions, CreateWaitpointTokenRequestBody, Waitpoi
|
|
|
19
21
|
* });
|
|
20
22
|
* ```
|
|
21
23
|
*
|
|
24
|
+
* @example
|
|
25
|
+
*
|
|
26
|
+
* **Completing a token with a webhook**
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* const token = await wait.createToken({
|
|
30
|
+
* timeout: "10m",
|
|
31
|
+
* tags: ["replicate"],
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* // Later, in a different part of your codebase, you can complete the waitpoint
|
|
35
|
+
* await replicate.predictions.create({
|
|
36
|
+
* version: "27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478",
|
|
37
|
+
* input: {
|
|
38
|
+
* prompt: "A painting of a cat by Andy Warhol",
|
|
39
|
+
* },
|
|
40
|
+
* // pass the provided URL to Replicate's webhook, so they can "callback"
|
|
41
|
+
* webhook: token.url,
|
|
42
|
+
* webhook_events_filter: ["completed"],
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* const prediction = await wait.forToken<Prediction>(token).unwrap();
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
22
48
|
* @param options - The options for the waitpoint token.
|
|
23
49
|
* @param requestOptions - The request options for the waitpoint token.
|
|
24
50
|
* @returns The waitpoint token.
|
|
@@ -74,6 +100,8 @@ declare function listTokens(params?: ListWaitpointTokensQueryParams, requestOpti
|
|
|
74
100
|
*/
|
|
75
101
|
export type WaitpointRetrievedToken<T> = {
|
|
76
102
|
id: string;
|
|
103
|
+
/** A URL that you can make a POST request to in order to complete the waitpoint. */
|
|
104
|
+
url: string;
|
|
77
105
|
status: WaitpointTokenStatus;
|
|
78
106
|
completedAt?: Date;
|
|
79
107
|
timeoutAt?: Date;
|
|
@@ -180,6 +208,10 @@ type WaitPeriod = {
|
|
|
180
208
|
export declare class WaitpointTimeoutError extends Error {
|
|
181
209
|
constructor(message: string);
|
|
182
210
|
}
|
|
211
|
+
declare class ManualWaitpointPromise<TOutput> extends Promise<WaitpointTokenTypedResult<TOutput>> {
|
|
212
|
+
constructor(executor: (resolve: (value: WaitpointTokenTypedResult<TOutput> | PromiseLike<WaitpointTokenTypedResult<TOutput>>) => void, reject: (reason?: any) => void) => void);
|
|
213
|
+
unwrap(): Promise<TOutput>;
|
|
214
|
+
}
|
|
183
215
|
export declare const wait: {
|
|
184
216
|
for: (options: WaitForOptions) => Promise<void>;
|
|
185
217
|
until: (options: {
|
|
@@ -209,7 +241,7 @@ export declare const wait: {
|
|
|
209
241
|
*
|
|
210
242
|
* @param token - The token to wait for.
|
|
211
243
|
* @param options - The options for the waitpoint token.
|
|
212
|
-
* @returns
|
|
244
|
+
* @returns A promise that resolves to the result of the waitpoint. You can use `.unwrap()` to get the result and an error will throw.
|
|
213
245
|
*/
|
|
214
246
|
forToken: <T>(token: string | {
|
|
215
247
|
id: string;
|
|
@@ -222,6 +254,6 @@ export declare const wait: {
|
|
|
222
254
|
* @default false
|
|
223
255
|
*/
|
|
224
256
|
releaseConcurrency?: boolean;
|
|
225
|
-
}) =>
|
|
257
|
+
}) => ManualWaitpointPromise<T>;
|
|
226
258
|
};
|
|
227
259
|
export {};
|
package/dist/commonjs/v3/wait.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.wait = exports.WaitpointTimeoutError = void 0;
|
|
4
|
+
const api_1 = require("@opentelemetry/api");
|
|
4
5
|
const v3_1 = require("@trigger.dev/core/v3");
|
|
5
|
-
const tracer_js_1 = require("./tracer.js");
|
|
6
6
|
const ioSerialization_1 = require("@trigger.dev/core/v3/utils/ioSerialization");
|
|
7
|
-
const
|
|
7
|
+
const tracer_js_1 = require("./tracer.js");
|
|
8
8
|
/**
|
|
9
9
|
* This creates a waitpoint token.
|
|
10
10
|
* You can use this to pause a run until you complete the waitpoint (or it times out).
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
*
|
|
14
|
+
* **Manually completing a token**
|
|
15
|
+
*
|
|
14
16
|
* ```ts
|
|
15
17
|
* const token = await wait.createToken({
|
|
16
18
|
* idempotencyKey: `approve-document-${documentId}`,
|
|
@@ -25,6 +27,30 @@ const api_1 = require("@opentelemetry/api");
|
|
|
25
27
|
* });
|
|
26
28
|
* ```
|
|
27
29
|
*
|
|
30
|
+
* @example
|
|
31
|
+
*
|
|
32
|
+
* **Completing a token with a webhook**
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* const token = await wait.createToken({
|
|
36
|
+
* timeout: "10m",
|
|
37
|
+
* tags: ["replicate"],
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Later, in a different part of your codebase, you can complete the waitpoint
|
|
41
|
+
* await replicate.predictions.create({
|
|
42
|
+
* version: "27b93a2413e7f36cd83da926f3656280b2931564ff050bf9575f1fdf9bcd7478",
|
|
43
|
+
* input: {
|
|
44
|
+
* prompt: "A painting of a cat by Andy Warhol",
|
|
45
|
+
* },
|
|
46
|
+
* // pass the provided URL to Replicate's webhook, so they can "callback"
|
|
47
|
+
* webhook: token.url,
|
|
48
|
+
* webhook_events_filter: ["completed"],
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* const prediction = await wait.forToken<Prediction>(token).unwrap();
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
28
54
|
* @param options - The options for the waitpoint token.
|
|
29
55
|
* @param requestOptions - The request options for the waitpoint token.
|
|
30
56
|
* @returns The waitpoint token.
|
|
@@ -48,6 +74,7 @@ function createToken(options, requestOptions) {
|
|
|
48
74
|
onResponseBody: (body, span) => {
|
|
49
75
|
span.setAttribute("id", body.id);
|
|
50
76
|
span.setAttribute("isCached", body.isCached);
|
|
77
|
+
span.setAttribute("url", body.url);
|
|
51
78
|
},
|
|
52
79
|
}, requestOptions);
|
|
53
80
|
return apiClient.createWaitpointToken(options ?? {}, $requestOptions);
|
|
@@ -140,6 +167,7 @@ async function retrieveToken(token, requestOptions) {
|
|
|
140
167
|
},
|
|
141
168
|
onResponseBody: (body, span) => {
|
|
142
169
|
span.setAttribute("id", body.id);
|
|
170
|
+
span.setAttribute("url", body.url);
|
|
143
171
|
span.setAttribute("status", body.status);
|
|
144
172
|
if (body.completedAt) {
|
|
145
173
|
span.setAttribute("completedAt", body.completedAt.toISOString());
|
|
@@ -171,6 +199,7 @@ async function retrieveToken(token, requestOptions) {
|
|
|
171
199
|
}
|
|
172
200
|
return {
|
|
173
201
|
id: result.id,
|
|
202
|
+
url: result.url,
|
|
174
203
|
status: result.status,
|
|
175
204
|
completedAt: result.completedAt,
|
|
176
205
|
timeoutAt: result.timeoutAt,
|
|
@@ -237,6 +266,21 @@ const DURATION_WAIT_CHARGE_THRESHOLD_MS = 5000;
|
|
|
237
266
|
function printWaitBelowThreshold() {
|
|
238
267
|
console.warn(`Waits of ${DURATION_WAIT_CHARGE_THRESHOLD_MS / 1000}s or less count towards compute usage.`);
|
|
239
268
|
}
|
|
269
|
+
class ManualWaitpointPromise extends Promise {
|
|
270
|
+
constructor(executor) {
|
|
271
|
+
super(executor);
|
|
272
|
+
}
|
|
273
|
+
unwrap() {
|
|
274
|
+
return this.then((result) => {
|
|
275
|
+
if (result.ok) {
|
|
276
|
+
return result.output;
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
throw new WaitpointTimeoutError(result.error.message);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
240
284
|
exports.wait = {
|
|
241
285
|
for: async (options) => {
|
|
242
286
|
const ctx = v3_1.taskContext.ctx;
|
|
@@ -381,9 +425,9 @@ exports.wait = {
|
|
|
381
425
|
*
|
|
382
426
|
* @param token - The token to wait for.
|
|
383
427
|
* @param options - The options for the waitpoint token.
|
|
384
|
-
* @returns
|
|
428
|
+
* @returns A promise that resolves to the result of the waitpoint. You can use `.unwrap()` to get the result and an error will throw.
|
|
385
429
|
*/
|
|
386
|
-
forToken:
|
|
430
|
+
forToken: (
|
|
387
431
|
/**
|
|
388
432
|
* The token to wait for.
|
|
389
433
|
* This can be a string token ID or an object with an `id` property.
|
|
@@ -393,58 +437,66 @@ exports.wait = {
|
|
|
393
437
|
* The options for the waitpoint token.
|
|
394
438
|
*/
|
|
395
439
|
options) => {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
440
|
+
return new ManualWaitpointPromise(async (resolve, reject) => {
|
|
441
|
+
try {
|
|
442
|
+
const ctx = v3_1.taskContext.ctx;
|
|
443
|
+
if (!ctx) {
|
|
444
|
+
throw new Error("wait.forToken can only be used from inside a task.run()");
|
|
445
|
+
}
|
|
446
|
+
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
447
|
+
const tokenId = typeof token === "string" ? token : token.id;
|
|
448
|
+
const result = await tracer_js_1.tracer.startActiveSpan(`wait.forToken()`, async (span) => {
|
|
449
|
+
const response = await apiClient.waitForWaitpointToken({
|
|
450
|
+
runFriendlyId: ctx.run.id,
|
|
451
|
+
waitpointFriendlyId: tokenId,
|
|
452
|
+
releaseConcurrency: options?.releaseConcurrency,
|
|
453
|
+
});
|
|
454
|
+
if (!response.success) {
|
|
455
|
+
throw new Error(`Failed to wait for wait token ${tokenId}`);
|
|
456
|
+
}
|
|
457
|
+
const result = await v3_1.runtime.waitUntil(tokenId);
|
|
458
|
+
const data = result.output
|
|
459
|
+
? await (0, ioSerialization_1.conditionallyImportAndParsePacket)({ data: result.output, dataType: result.outputType ?? "application/json" }, apiClient)
|
|
460
|
+
: undefined;
|
|
461
|
+
if (result.ok) {
|
|
462
|
+
return {
|
|
463
|
+
ok: result.ok,
|
|
464
|
+
output: data,
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
const error = new WaitpointTimeoutError(data.message);
|
|
469
|
+
span.recordException(error);
|
|
470
|
+
span.setStatus({
|
|
471
|
+
code: api_1.SpanStatusCode.ERROR,
|
|
472
|
+
});
|
|
473
|
+
return {
|
|
474
|
+
ok: result.ok,
|
|
475
|
+
error,
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
}, {
|
|
479
|
+
attributes: {
|
|
480
|
+
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "wait",
|
|
481
|
+
[v3_1.SemanticInternalAttributes.ENTITY_TYPE]: "waitpoint",
|
|
482
|
+
[v3_1.SemanticInternalAttributes.ENTITY_ID]: tokenId,
|
|
483
|
+
id: tokenId,
|
|
484
|
+
...(0, v3_1.accessoryAttributes)({
|
|
485
|
+
items: [
|
|
486
|
+
{
|
|
487
|
+
text: tokenId,
|
|
488
|
+
variant: "normal",
|
|
489
|
+
},
|
|
490
|
+
],
|
|
491
|
+
style: "codepath",
|
|
492
|
+
}),
|
|
493
|
+
},
|
|
426
494
|
});
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
495
|
+
resolve(result);
|
|
496
|
+
}
|
|
497
|
+
catch (error) {
|
|
498
|
+
reject(error);
|
|
431
499
|
}
|
|
432
|
-
}, {
|
|
433
|
-
attributes: {
|
|
434
|
-
[v3_1.SemanticInternalAttributes.STYLE_ICON]: "wait",
|
|
435
|
-
[v3_1.SemanticInternalAttributes.ENTITY_TYPE]: "waitpoint",
|
|
436
|
-
[v3_1.SemanticInternalAttributes.ENTITY_ID]: tokenId,
|
|
437
|
-
id: tokenId,
|
|
438
|
-
...(0, v3_1.accessoryAttributes)({
|
|
439
|
-
items: [
|
|
440
|
-
{
|
|
441
|
-
text: tokenId,
|
|
442
|
-
variant: "normal",
|
|
443
|
-
},
|
|
444
|
-
],
|
|
445
|
-
style: "codepath",
|
|
446
|
-
}),
|
|
447
|
-
},
|
|
448
500
|
});
|
|
449
501
|
},
|
|
450
502
|
};
|