@upstash/workflow 0.2.12 → 0.2.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.
- package/astro.d.mts +2 -2
- package/astro.d.ts +2 -2
- package/astro.js +1205 -1036
- package/astro.mjs +1 -1
- package/{chunk-4GTHIL7S.mjs → chunk-XVNSBBDC.mjs} +870 -699
- package/cloudflare.d.mts +2 -2
- package/cloudflare.d.ts +2 -2
- package/cloudflare.js +1205 -1036
- package/cloudflare.mjs +1 -1
- package/express.d.mts +2 -2
- package/express.d.ts +2 -2
- package/express.js +1221 -1052
- package/express.mjs +1 -1
- package/h3.d.mts +2 -2
- package/h3.d.ts +2 -2
- package/h3.js +1205 -1036
- package/h3.mjs +1 -1
- package/hono.d.mts +2 -2
- package/hono.d.ts +2 -2
- package/hono.js +1206 -1037
- package/hono.mjs +2 -2
- package/index.d.mts +10 -4
- package/index.d.ts +10 -4
- package/index.js +1184 -1008
- package/index.mjs +10 -3
- package/nextjs.d.mts +2 -2
- package/nextjs.d.ts +2 -2
- package/nextjs.js +1205 -1036
- package/nextjs.mjs +1 -1
- package/package.json +1 -1
- package/{serve-many-DLguU9iR.d.mts → serve-many-BF71QZHQ.d.mts} +1 -1
- package/{serve-many-BdMq5rFX.d.ts → serve-many-BMlN2PAB.d.ts} +1 -1
- package/solidjs.d.mts +1 -1
- package/solidjs.d.ts +1 -1
- package/solidjs.js +1173 -1004
- package/solidjs.mjs +1 -1
- package/svelte.d.mts +2 -2
- package/svelte.d.ts +2 -2
- package/svelte.js +1205 -1036
- package/svelte.mjs +1 -1
- package/{types-D1W0VOpy.d.ts → types-C1WIgVLA.d.mts} +58 -45
- package/{types-D1W0VOpy.d.mts → types-C1WIgVLA.d.ts} +58 -45
package/solidjs.js
CHANGED
|
@@ -89,11 +89,12 @@ var WORKFLOW_PROTOCOL_VERSION_HEADER = "Upstash-Workflow-Sdk-Version";
|
|
|
89
89
|
var DEFAULT_CONTENT_TYPE = "application/json";
|
|
90
90
|
var NO_CONCURRENCY = 1;
|
|
91
91
|
var DEFAULT_RETRIES = 3;
|
|
92
|
-
var VERSION = "v0.2.
|
|
92
|
+
var VERSION = "v0.2.13";
|
|
93
93
|
var SDK_TELEMETRY = `@upstash/workflow@${VERSION}`;
|
|
94
94
|
var TELEMETRY_HEADER_SDK = "Upstash-Telemetry-Sdk";
|
|
95
95
|
var TELEMETRY_HEADER_FRAMEWORK = "Upstash-Telemetry-Framework";
|
|
96
96
|
var TELEMETRY_HEADER_RUNTIME = "Upstash-Telemetry-Runtime";
|
|
97
|
+
var TELEMETRY_HEADER_AGENT = "Upstash-Telemetry-Agent";
|
|
97
98
|
|
|
98
99
|
// src/error.ts
|
|
99
100
|
var import_qstash2 = require("@upstash/qstash");
|
|
@@ -136,6 +137,12 @@ var formatWorkflowError = (error) => {
|
|
|
136
137
|
};
|
|
137
138
|
};
|
|
138
139
|
|
|
140
|
+
// src/context/auto-executor.ts
|
|
141
|
+
var import_qstash5 = require("@upstash/qstash");
|
|
142
|
+
|
|
143
|
+
// src/qstash/headers.ts
|
|
144
|
+
var import_qstash4 = require("@upstash/qstash");
|
|
145
|
+
|
|
139
146
|
// src/utils.ts
|
|
140
147
|
var NANOID_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
|
|
141
148
|
var NANOID_LENGTH = 21;
|
|
@@ -161,574 +168,231 @@ function decodeBase64(base64) {
|
|
|
161
168
|
}
|
|
162
169
|
}
|
|
163
170
|
|
|
164
|
-
//
|
|
165
|
-
var
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
// node_modules/neverthrow/dist/index.es.js
|
|
172
|
+
var defaultErrorConfig = {
|
|
173
|
+
withStackTrace: false
|
|
174
|
+
};
|
|
175
|
+
var createNeverThrowError = (message, result, config = defaultErrorConfig) => {
|
|
176
|
+
const data = result.isOk() ? { type: "Ok", value: result.value } : { type: "Err", value: result.error };
|
|
177
|
+
const maybeStack = config.withStackTrace ? new Error().stack : void 0;
|
|
178
|
+
return {
|
|
179
|
+
data,
|
|
180
|
+
message,
|
|
181
|
+
stack: maybeStack
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
185
|
+
function adopt(value) {
|
|
186
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
187
|
+
resolve(value);
|
|
188
|
+
});
|
|
174
189
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
* @returns parsed out field
|
|
182
|
-
*/
|
|
183
|
-
parseOut(out) {
|
|
184
|
-
if (out === void 0) {
|
|
185
|
-
if (this.allowUndefinedOut) {
|
|
186
|
-
return void 0;
|
|
187
|
-
} else {
|
|
188
|
-
throw new WorkflowError(
|
|
189
|
-
`Error while parsing output of ${this.stepType} step. Expected a string, but got: undefined`
|
|
190
|
-
);
|
|
190
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
191
|
+
function fulfilled(value) {
|
|
192
|
+
try {
|
|
193
|
+
step(generator.next(value));
|
|
194
|
+
} catch (e) {
|
|
195
|
+
reject(e);
|
|
191
196
|
}
|
|
192
197
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
);
|
|
198
|
-
return out;
|
|
198
|
+
function rejected(value) {
|
|
199
|
+
try {
|
|
200
|
+
step(generator["throw"](value));
|
|
201
|
+
} catch (e) {
|
|
202
|
+
reject(e);
|
|
199
203
|
}
|
|
200
|
-
return {
|
|
201
|
-
...out,
|
|
202
|
-
eventData: _BaseLazyStep.tryParsing(out.eventData)
|
|
203
|
-
};
|
|
204
204
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
`Error while parsing output of ${this.stepType} step. Expected a string or undefined, but got: ${typeof out}`
|
|
208
|
-
);
|
|
205
|
+
function step(result) {
|
|
206
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
209
207
|
}
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
208
|
+
step((generator = generator.apply(thisArg, [])).next());
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
function __values(o) {
|
|
212
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
213
|
+
if (m) return m.call(o);
|
|
214
|
+
if (o && typeof o.length === "number") return {
|
|
215
|
+
next: function() {
|
|
216
|
+
if (o && i >= o.length) o = void 0;
|
|
217
|
+
return { value: o && o[i++], done: !o };
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
221
|
+
}
|
|
222
|
+
function __await(v) {
|
|
223
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
224
|
+
}
|
|
225
|
+
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
226
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
227
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
228
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
|
|
229
|
+
return this;
|
|
230
|
+
}, i;
|
|
231
|
+
function verb(n) {
|
|
232
|
+
if (g[n]) i[n] = function(v) {
|
|
233
|
+
return new Promise(function(a, b) {
|
|
234
|
+
q.push([n, v, a, b]) > 1 || resume(n, v);
|
|
235
|
+
});
|
|
236
|
+
};
|
|
214
237
|
}
|
|
215
|
-
|
|
238
|
+
function resume(n, v) {
|
|
216
239
|
try {
|
|
217
|
-
|
|
218
|
-
} catch {
|
|
219
|
-
|
|
240
|
+
step(g[n](v));
|
|
241
|
+
} catch (e) {
|
|
242
|
+
settle(q[0][3], e);
|
|
220
243
|
}
|
|
221
244
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
stepFunction;
|
|
225
|
-
stepType = "Run";
|
|
226
|
-
allowUndefinedOut = true;
|
|
227
|
-
constructor(stepName, stepFunction) {
|
|
228
|
-
super(stepName);
|
|
229
|
-
this.stepFunction = stepFunction;
|
|
245
|
+
function step(r) {
|
|
246
|
+
r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
|
|
230
247
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
stepId: 0,
|
|
234
|
-
stepName: this.stepName,
|
|
235
|
-
stepType: this.stepType,
|
|
236
|
-
concurrent,
|
|
237
|
-
targetStep
|
|
238
|
-
};
|
|
248
|
+
function fulfill(value) {
|
|
249
|
+
resume("next", value);
|
|
239
250
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if (result instanceof Promise) {
|
|
243
|
-
result = await result;
|
|
244
|
-
}
|
|
245
|
-
return {
|
|
246
|
-
stepId,
|
|
247
|
-
stepName: this.stepName,
|
|
248
|
-
stepType: this.stepType,
|
|
249
|
-
out: result,
|
|
250
|
-
concurrent
|
|
251
|
-
};
|
|
251
|
+
function reject(value) {
|
|
252
|
+
resume("throw", value);
|
|
252
253
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
sleep;
|
|
256
|
-
stepType = "SleepFor";
|
|
257
|
-
allowUndefinedOut = true;
|
|
258
|
-
constructor(stepName, sleep) {
|
|
259
|
-
super(stepName);
|
|
260
|
-
this.sleep = sleep;
|
|
254
|
+
function settle(f, v) {
|
|
255
|
+
if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
|
|
261
256
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
257
|
+
}
|
|
258
|
+
function __asyncDelegator(o) {
|
|
259
|
+
var i, p;
|
|
260
|
+
return i = {}, verb("next"), verb("throw", function(e) {
|
|
261
|
+
throw e;
|
|
262
|
+
}), verb("return"), i[Symbol.iterator] = function() {
|
|
263
|
+
return this;
|
|
264
|
+
}, i;
|
|
265
|
+
function verb(n, f) {
|
|
266
|
+
i[n] = o[n] ? function(v) {
|
|
267
|
+
return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v;
|
|
268
|
+
} : f;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function __asyncValues(o) {
|
|
272
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
273
|
+
var m = o[Symbol.asyncIterator], i;
|
|
274
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
|
|
275
|
+
return this;
|
|
276
|
+
}, i);
|
|
277
|
+
function verb(n) {
|
|
278
|
+
i[n] = o[n] && function(v) {
|
|
279
|
+
return new Promise(function(resolve, reject) {
|
|
280
|
+
v = o[n](v), settle(resolve, reject, v.done, v.value);
|
|
281
|
+
});
|
|
270
282
|
};
|
|
271
283
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
stepType: this.stepType,
|
|
277
|
-
sleepFor: this.sleep,
|
|
278
|
-
concurrent
|
|
279
|
-
});
|
|
284
|
+
function settle(resolve, reject, d, v) {
|
|
285
|
+
Promise.resolve(v).then(function(v2) {
|
|
286
|
+
resolve({ value: v2, done: d });
|
|
287
|
+
}, reject);
|
|
280
288
|
}
|
|
281
|
-
}
|
|
282
|
-
var
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
allowUndefinedOut = true;
|
|
286
|
-
constructor(stepName, sleepUntil) {
|
|
287
|
-
super(stepName);
|
|
288
|
-
this.sleepUntil = sleepUntil;
|
|
289
|
+
}
|
|
290
|
+
var ResultAsync = class _ResultAsync {
|
|
291
|
+
constructor(res) {
|
|
292
|
+
this._promise = res;
|
|
289
293
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
stepName: this.stepName,
|
|
294
|
-
stepType: this.stepType,
|
|
295
|
-
sleepUntil: this.sleepUntil,
|
|
296
|
-
concurrent,
|
|
297
|
-
targetStep
|
|
298
|
-
};
|
|
294
|
+
static fromSafePromise(promise) {
|
|
295
|
+
const newPromise = promise.then((value) => new Ok(value));
|
|
296
|
+
return new _ResultAsync(newPromise);
|
|
299
297
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
stepName: this.stepName,
|
|
304
|
-
stepType: this.stepType,
|
|
305
|
-
sleepUntil: this.sleepUntil,
|
|
306
|
-
concurrent
|
|
307
|
-
});
|
|
298
|
+
static fromPromise(promise, errorFn) {
|
|
299
|
+
const newPromise = promise.then((value) => new Ok(value)).catch((e) => new Err(errorFn(e)));
|
|
300
|
+
return new _ResultAsync(newPromise);
|
|
308
301
|
}
|
|
309
|
-
|
|
310
|
-
|
|
302
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
303
|
+
static fromThrowable(fn, errorFn) {
|
|
304
|
+
return (...args) => {
|
|
305
|
+
return new _ResultAsync((() => __awaiter(this, void 0, void 0, function* () {
|
|
306
|
+
try {
|
|
307
|
+
return new Ok(yield fn(...args));
|
|
308
|
+
} catch (error) {
|
|
309
|
+
return new Err(errorFn ? errorFn(error) : error);
|
|
310
|
+
}
|
|
311
|
+
}))());
|
|
312
|
+
};
|
|
311
313
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
url;
|
|
315
|
-
method;
|
|
316
|
-
body;
|
|
317
|
-
headers;
|
|
318
|
-
retries;
|
|
319
|
-
timeout;
|
|
320
|
-
flowControl;
|
|
321
|
-
stepType = "Call";
|
|
322
|
-
allowUndefinedOut = false;
|
|
323
|
-
constructor(stepName, url, method, body, headers, retries, timeout, flowControl) {
|
|
324
|
-
super(stepName);
|
|
325
|
-
this.url = url;
|
|
326
|
-
this.method = method;
|
|
327
|
-
this.body = body;
|
|
328
|
-
this.headers = headers;
|
|
329
|
-
this.retries = retries;
|
|
330
|
-
this.timeout = timeout;
|
|
331
|
-
this.flowControl = flowControl;
|
|
332
|
-
}
|
|
333
|
-
getPlanStep(concurrent, targetStep) {
|
|
334
|
-
return {
|
|
335
|
-
stepId: 0,
|
|
336
|
-
stepName: this.stepName,
|
|
337
|
-
stepType: this.stepType,
|
|
338
|
-
concurrent,
|
|
339
|
-
targetStep
|
|
340
|
-
};
|
|
314
|
+
static combine(asyncResultList) {
|
|
315
|
+
return combineResultAsyncList(asyncResultList);
|
|
341
316
|
}
|
|
342
|
-
|
|
343
|
-
return
|
|
344
|
-
stepId,
|
|
345
|
-
stepName: this.stepName,
|
|
346
|
-
stepType: this.stepType,
|
|
347
|
-
concurrent,
|
|
348
|
-
callUrl: this.url,
|
|
349
|
-
callMethod: this.method,
|
|
350
|
-
callBody: this.body,
|
|
351
|
-
callHeaders: this.headers
|
|
352
|
-
});
|
|
317
|
+
static combineWithAllErrors(asyncResultList) {
|
|
318
|
+
return combineResultAsyncListWithAllErrors(asyncResultList);
|
|
353
319
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
const bytes = new Uint8Array(out.length);
|
|
359
|
-
for (let i = 0; i < out.length; i++) {
|
|
360
|
-
bytes[i] = out.charCodeAt(i);
|
|
320
|
+
map(f) {
|
|
321
|
+
return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
322
|
+
if (res.isErr()) {
|
|
323
|
+
return new Err(res.error);
|
|
361
324
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
return {
|
|
365
|
-
status,
|
|
366
|
-
header,
|
|
367
|
-
body: BaseLazyStep.tryParsing(newBody)
|
|
368
|
-
};
|
|
369
|
-
} else {
|
|
370
|
-
return { header, status, body };
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
static applicationHeaders = /* @__PURE__ */ new Set([
|
|
374
|
-
"application/json",
|
|
375
|
-
"application/xml",
|
|
376
|
-
"application/javascript",
|
|
377
|
-
"application/x-www-form-urlencoded",
|
|
378
|
-
"application/xhtml+xml",
|
|
379
|
-
"application/ld+json",
|
|
380
|
-
"application/rss+xml",
|
|
381
|
-
"application/atom+xml"
|
|
382
|
-
]);
|
|
383
|
-
static isText = (contentTypeHeader) => {
|
|
384
|
-
if (!contentTypeHeader) {
|
|
385
|
-
return false;
|
|
386
|
-
}
|
|
387
|
-
if (_LazyCallStep.applicationHeaders.has(contentTypeHeader)) {
|
|
388
|
-
return true;
|
|
389
|
-
}
|
|
390
|
-
if (contentTypeHeader.startsWith("text/")) {
|
|
391
|
-
return true;
|
|
392
|
-
}
|
|
393
|
-
return false;
|
|
394
|
-
};
|
|
395
|
-
};
|
|
396
|
-
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
397
|
-
eventId;
|
|
398
|
-
timeout;
|
|
399
|
-
stepType = "Wait";
|
|
400
|
-
allowUndefinedOut = false;
|
|
401
|
-
constructor(stepName, eventId, timeout) {
|
|
402
|
-
super(stepName);
|
|
403
|
-
this.eventId = eventId;
|
|
404
|
-
this.timeout = timeout;
|
|
325
|
+
return new Ok(yield f(res.value));
|
|
326
|
+
})));
|
|
405
327
|
}
|
|
406
|
-
|
|
407
|
-
return {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
328
|
+
andThrough(f) {
|
|
329
|
+
return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
330
|
+
if (res.isErr()) {
|
|
331
|
+
return new Err(res.error);
|
|
332
|
+
}
|
|
333
|
+
const newRes = yield f(res.value);
|
|
334
|
+
if (newRes.isErr()) {
|
|
335
|
+
return new Err(newRes.error);
|
|
336
|
+
}
|
|
337
|
+
return new Ok(res.value);
|
|
338
|
+
})));
|
|
416
339
|
}
|
|
417
|
-
|
|
418
|
-
return
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
340
|
+
andTee(f) {
|
|
341
|
+
return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
342
|
+
if (res.isErr()) {
|
|
343
|
+
return new Err(res.error);
|
|
344
|
+
}
|
|
345
|
+
try {
|
|
346
|
+
yield f(res.value);
|
|
347
|
+
} catch (e) {
|
|
348
|
+
}
|
|
349
|
+
return new Ok(res.value);
|
|
350
|
+
})));
|
|
426
351
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
352
|
+
mapErr(f) {
|
|
353
|
+
return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
354
|
+
if (res.isOk()) {
|
|
355
|
+
return new Ok(res.value);
|
|
356
|
+
}
|
|
357
|
+
return new Err(yield f(res.error));
|
|
358
|
+
})));
|
|
433
359
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
notifyResponse
|
|
444
|
-
};
|
|
445
|
-
});
|
|
360
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
|
361
|
+
andThen(f) {
|
|
362
|
+
return new _ResultAsync(this._promise.then((res) => {
|
|
363
|
+
if (res.isErr()) {
|
|
364
|
+
return new Err(res.error);
|
|
365
|
+
}
|
|
366
|
+
const newValue = f(res.value);
|
|
367
|
+
return newValue instanceof _ResultAsync ? newValue._promise : newValue;
|
|
368
|
+
}));
|
|
446
369
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
return {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
370
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
|
371
|
+
orElse(f) {
|
|
372
|
+
return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
373
|
+
if (res.isErr()) {
|
|
374
|
+
return f(res.error);
|
|
375
|
+
}
|
|
376
|
+
return new Ok(res.value);
|
|
377
|
+
})));
|
|
453
378
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
stepType = "Invoke";
|
|
457
|
-
params;
|
|
458
|
-
allowUndefinedOut = false;
|
|
459
|
-
constructor(stepName, {
|
|
460
|
-
workflow,
|
|
461
|
-
body,
|
|
462
|
-
headers = {},
|
|
463
|
-
workflowRunId,
|
|
464
|
-
retries,
|
|
465
|
-
flowControl
|
|
466
|
-
}) {
|
|
467
|
-
super(stepName);
|
|
468
|
-
this.params = {
|
|
469
|
-
workflow,
|
|
470
|
-
body,
|
|
471
|
-
headers,
|
|
472
|
-
workflowRunId: getWorkflowRunId(workflowRunId),
|
|
473
|
-
retries,
|
|
474
|
-
flowControl
|
|
475
|
-
};
|
|
379
|
+
match(ok2, _err) {
|
|
380
|
+
return this._promise.then((res) => res.match(ok2, _err));
|
|
476
381
|
}
|
|
477
|
-
|
|
478
|
-
return
|
|
479
|
-
stepId: 0,
|
|
480
|
-
stepName: this.stepName,
|
|
481
|
-
stepType: this.stepType,
|
|
482
|
-
concurrent,
|
|
483
|
-
targetStep
|
|
484
|
-
};
|
|
382
|
+
unwrapOr(t) {
|
|
383
|
+
return this._promise.then((res) => res.unwrapOr(t));
|
|
485
384
|
}
|
|
486
385
|
/**
|
|
487
|
-
*
|
|
488
|
-
* in Invoke step.
|
|
386
|
+
* Emulates Rust's `?` operator in `safeTry`'s body. See also `safeTry`.
|
|
489
387
|
*/
|
|
490
|
-
|
|
491
|
-
return
|
|
492
|
-
|
|
493
|
-
stepName: this.stepName,
|
|
494
|
-
stepType: this.stepType,
|
|
495
|
-
concurrent
|
|
388
|
+
safeUnwrap() {
|
|
389
|
+
return __asyncGenerator(this, arguments, function* safeUnwrap_1() {
|
|
390
|
+
return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(yield __await(this._promise.then((res) => res.safeUnwrap()))))));
|
|
496
391
|
});
|
|
497
392
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
return
|
|
501
|
-
...result,
|
|
502
|
-
body: BaseLazyStep.tryParsing(result.body)
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
};
|
|
506
|
-
|
|
507
|
-
// node_modules/neverthrow/dist/index.es.js
|
|
508
|
-
var defaultErrorConfig = {
|
|
509
|
-
withStackTrace: false
|
|
510
|
-
};
|
|
511
|
-
var createNeverThrowError = (message, result, config = defaultErrorConfig) => {
|
|
512
|
-
const data = result.isOk() ? { type: "Ok", value: result.value } : { type: "Err", value: result.error };
|
|
513
|
-
const maybeStack = config.withStackTrace ? new Error().stack : void 0;
|
|
514
|
-
return {
|
|
515
|
-
data,
|
|
516
|
-
message,
|
|
517
|
-
stack: maybeStack
|
|
518
|
-
};
|
|
519
|
-
};
|
|
520
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
521
|
-
function adopt(value) {
|
|
522
|
-
return value instanceof P ? value : new P(function(resolve) {
|
|
523
|
-
resolve(value);
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
return new (P || (P = Promise))(function(resolve, reject) {
|
|
527
|
-
function fulfilled(value) {
|
|
528
|
-
try {
|
|
529
|
-
step(generator.next(value));
|
|
530
|
-
} catch (e) {
|
|
531
|
-
reject(e);
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
function rejected(value) {
|
|
535
|
-
try {
|
|
536
|
-
step(generator["throw"](value));
|
|
537
|
-
} catch (e) {
|
|
538
|
-
reject(e);
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
function step(result) {
|
|
542
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
543
|
-
}
|
|
544
|
-
step((generator = generator.apply(thisArg, [])).next());
|
|
545
|
-
});
|
|
546
|
-
}
|
|
547
|
-
function __values(o) {
|
|
548
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
549
|
-
if (m) return m.call(o);
|
|
550
|
-
if (o && typeof o.length === "number") return {
|
|
551
|
-
next: function() {
|
|
552
|
-
if (o && i >= o.length) o = void 0;
|
|
553
|
-
return { value: o && o[i++], done: !o };
|
|
554
|
-
}
|
|
555
|
-
};
|
|
556
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
557
|
-
}
|
|
558
|
-
function __await(v) {
|
|
559
|
-
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
560
|
-
}
|
|
561
|
-
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
562
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
563
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
564
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
|
|
565
|
-
return this;
|
|
566
|
-
}, i;
|
|
567
|
-
function verb(n) {
|
|
568
|
-
if (g[n]) i[n] = function(v) {
|
|
569
|
-
return new Promise(function(a, b) {
|
|
570
|
-
q.push([n, v, a, b]) > 1 || resume(n, v);
|
|
571
|
-
});
|
|
572
|
-
};
|
|
573
|
-
}
|
|
574
|
-
function resume(n, v) {
|
|
575
|
-
try {
|
|
576
|
-
step(g[n](v));
|
|
577
|
-
} catch (e) {
|
|
578
|
-
settle(q[0][3], e);
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
function step(r) {
|
|
582
|
-
r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
|
|
583
|
-
}
|
|
584
|
-
function fulfill(value) {
|
|
585
|
-
resume("next", value);
|
|
586
|
-
}
|
|
587
|
-
function reject(value) {
|
|
588
|
-
resume("throw", value);
|
|
589
|
-
}
|
|
590
|
-
function settle(f, v) {
|
|
591
|
-
if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
function __asyncDelegator(o) {
|
|
595
|
-
var i, p;
|
|
596
|
-
return i = {}, verb("next"), verb("throw", function(e) {
|
|
597
|
-
throw e;
|
|
598
|
-
}), verb("return"), i[Symbol.iterator] = function() {
|
|
599
|
-
return this;
|
|
600
|
-
}, i;
|
|
601
|
-
function verb(n, f) {
|
|
602
|
-
i[n] = o[n] ? function(v) {
|
|
603
|
-
return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v;
|
|
604
|
-
} : f;
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
function __asyncValues(o) {
|
|
608
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
609
|
-
var m = o[Symbol.asyncIterator], i;
|
|
610
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
|
|
611
|
-
return this;
|
|
612
|
-
}, i);
|
|
613
|
-
function verb(n) {
|
|
614
|
-
i[n] = o[n] && function(v) {
|
|
615
|
-
return new Promise(function(resolve, reject) {
|
|
616
|
-
v = o[n](v), settle(resolve, reject, v.done, v.value);
|
|
617
|
-
});
|
|
618
|
-
};
|
|
619
|
-
}
|
|
620
|
-
function settle(resolve, reject, d, v) {
|
|
621
|
-
Promise.resolve(v).then(function(v2) {
|
|
622
|
-
resolve({ value: v2, done: d });
|
|
623
|
-
}, reject);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
var ResultAsync = class _ResultAsync {
|
|
627
|
-
constructor(res) {
|
|
628
|
-
this._promise = res;
|
|
629
|
-
}
|
|
630
|
-
static fromSafePromise(promise) {
|
|
631
|
-
const newPromise = promise.then((value) => new Ok(value));
|
|
632
|
-
return new _ResultAsync(newPromise);
|
|
633
|
-
}
|
|
634
|
-
static fromPromise(promise, errorFn) {
|
|
635
|
-
const newPromise = promise.then((value) => new Ok(value)).catch((e) => new Err(errorFn(e)));
|
|
636
|
-
return new _ResultAsync(newPromise);
|
|
637
|
-
}
|
|
638
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
639
|
-
static fromThrowable(fn, errorFn) {
|
|
640
|
-
return (...args) => {
|
|
641
|
-
return new _ResultAsync((() => __awaiter(this, void 0, void 0, function* () {
|
|
642
|
-
try {
|
|
643
|
-
return new Ok(yield fn(...args));
|
|
644
|
-
} catch (error) {
|
|
645
|
-
return new Err(errorFn ? errorFn(error) : error);
|
|
646
|
-
}
|
|
647
|
-
}))());
|
|
648
|
-
};
|
|
649
|
-
}
|
|
650
|
-
static combine(asyncResultList) {
|
|
651
|
-
return combineResultAsyncList(asyncResultList);
|
|
652
|
-
}
|
|
653
|
-
static combineWithAllErrors(asyncResultList) {
|
|
654
|
-
return combineResultAsyncListWithAllErrors(asyncResultList);
|
|
655
|
-
}
|
|
656
|
-
map(f) {
|
|
657
|
-
return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
658
|
-
if (res.isErr()) {
|
|
659
|
-
return new Err(res.error);
|
|
660
|
-
}
|
|
661
|
-
return new Ok(yield f(res.value));
|
|
662
|
-
})));
|
|
663
|
-
}
|
|
664
|
-
andThrough(f) {
|
|
665
|
-
return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
666
|
-
if (res.isErr()) {
|
|
667
|
-
return new Err(res.error);
|
|
668
|
-
}
|
|
669
|
-
const newRes = yield f(res.value);
|
|
670
|
-
if (newRes.isErr()) {
|
|
671
|
-
return new Err(newRes.error);
|
|
672
|
-
}
|
|
673
|
-
return new Ok(res.value);
|
|
674
|
-
})));
|
|
675
|
-
}
|
|
676
|
-
andTee(f) {
|
|
677
|
-
return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
678
|
-
if (res.isErr()) {
|
|
679
|
-
return new Err(res.error);
|
|
680
|
-
}
|
|
681
|
-
try {
|
|
682
|
-
yield f(res.value);
|
|
683
|
-
} catch (e) {
|
|
684
|
-
}
|
|
685
|
-
return new Ok(res.value);
|
|
686
|
-
})));
|
|
687
|
-
}
|
|
688
|
-
mapErr(f) {
|
|
689
|
-
return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
690
|
-
if (res.isOk()) {
|
|
691
|
-
return new Ok(res.value);
|
|
692
|
-
}
|
|
693
|
-
return new Err(yield f(res.error));
|
|
694
|
-
})));
|
|
695
|
-
}
|
|
696
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
|
697
|
-
andThen(f) {
|
|
698
|
-
return new _ResultAsync(this._promise.then((res) => {
|
|
699
|
-
if (res.isErr()) {
|
|
700
|
-
return new Err(res.error);
|
|
701
|
-
}
|
|
702
|
-
const newValue = f(res.value);
|
|
703
|
-
return newValue instanceof _ResultAsync ? newValue._promise : newValue;
|
|
704
|
-
}));
|
|
705
|
-
}
|
|
706
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
|
707
|
-
orElse(f) {
|
|
708
|
-
return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
709
|
-
if (res.isErr()) {
|
|
710
|
-
return f(res.error);
|
|
711
|
-
}
|
|
712
|
-
return new Ok(res.value);
|
|
713
|
-
})));
|
|
714
|
-
}
|
|
715
|
-
match(ok2, _err) {
|
|
716
|
-
return this._promise.then((res) => res.match(ok2, _err));
|
|
717
|
-
}
|
|
718
|
-
unwrapOr(t) {
|
|
719
|
-
return this._promise.then((res) => res.unwrapOr(t));
|
|
720
|
-
}
|
|
721
|
-
/**
|
|
722
|
-
* Emulates Rust's `?` operator in `safeTry`'s body. See also `safeTry`.
|
|
723
|
-
*/
|
|
724
|
-
safeUnwrap() {
|
|
725
|
-
return __asyncGenerator(this, arguments, function* safeUnwrap_1() {
|
|
726
|
-
return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(yield __await(this._promise.then((res) => res.safeUnwrap()))))));
|
|
727
|
-
});
|
|
728
|
-
}
|
|
729
|
-
// Makes ResultAsync implement PromiseLike<Result>
|
|
730
|
-
then(successCallback, failureCallback) {
|
|
731
|
-
return this._promise.then(successCallback, failureCallback);
|
|
393
|
+
// Makes ResultAsync implement PromiseLike<Result>
|
|
394
|
+
then(successCallback, failureCallback) {
|
|
395
|
+
return this._promise.then(successCallback, failureCallback);
|
|
732
396
|
}
|
|
733
397
|
};
|
|
734
398
|
var errAsync = (err2) => new ResultAsync(Promise.resolve(new Err(err2)));
|
|
@@ -938,18 +602,22 @@ var triggerFirstInvocation = async ({
|
|
|
938
602
|
useJSONContent,
|
|
939
603
|
telemetry,
|
|
940
604
|
debug,
|
|
941
|
-
invokeCount
|
|
605
|
+
invokeCount,
|
|
606
|
+
delay
|
|
942
607
|
}) => {
|
|
943
608
|
const { headers } = getHeaders({
|
|
944
609
|
initHeaderValue: "true",
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
610
|
+
workflowConfig: {
|
|
611
|
+
workflowRunId: workflowContext.workflowRunId,
|
|
612
|
+
workflowUrl: workflowContext.url,
|
|
613
|
+
failureUrl: workflowContext.failureUrl,
|
|
614
|
+
retries: workflowContext.retries,
|
|
615
|
+
telemetry,
|
|
616
|
+
flowControl: workflowContext.flowControl,
|
|
617
|
+
useJSONContent: useJSONContent ?? false
|
|
618
|
+
},
|
|
619
|
+
invokeCount: invokeCount ?? 0,
|
|
620
|
+
userHeaders: workflowContext.headers
|
|
953
621
|
});
|
|
954
622
|
if (workflowContext.headers.get("content-type")) {
|
|
955
623
|
headers["content-type"] = workflowContext.headers.get("content-type");
|
|
@@ -963,7 +631,8 @@ var triggerFirstInvocation = async ({
|
|
|
963
631
|
headers,
|
|
964
632
|
method: "POST",
|
|
965
633
|
body,
|
|
966
|
-
url: workflowContext.url
|
|
634
|
+
url: workflowContext.url,
|
|
635
|
+
delay
|
|
967
636
|
});
|
|
968
637
|
if (result.deduplicated) {
|
|
969
638
|
await debug?.log("WARN", "SUBMIT_FIRST_INVOCATION", {
|
|
@@ -1119,14 +788,16 @@ ${atob(callbackMessage.body ?? "")}`
|
|
|
1119
788
|
const userHeaders = recreateUserHeaders(request.headers);
|
|
1120
789
|
const { headers: requestHeaders } = getHeaders({
|
|
1121
790
|
initHeaderValue: "false",
|
|
1122
|
-
|
|
1123
|
-
|
|
791
|
+
workflowConfig: {
|
|
792
|
+
workflowRunId,
|
|
793
|
+
workflowUrl,
|
|
794
|
+
failureUrl,
|
|
795
|
+
retries,
|
|
796
|
+
telemetry,
|
|
797
|
+
flowControl
|
|
798
|
+
},
|
|
1124
799
|
userHeaders,
|
|
1125
|
-
|
|
1126
|
-
retries,
|
|
1127
|
-
telemetry,
|
|
1128
|
-
invokeCount: Number(invokeCount),
|
|
1129
|
-
flowControl
|
|
800
|
+
invokeCount: Number(invokeCount)
|
|
1130
801
|
});
|
|
1131
802
|
const callResponse = {
|
|
1132
803
|
status: callbackMessage.status,
|
|
@@ -1165,275 +836,906 @@ ${atob(callbackMessage.body ?? "")}`
|
|
|
1165
836
|
);
|
|
1166
837
|
}
|
|
1167
838
|
};
|
|
1168
|
-
var getTelemetryHeaders = (telemetry) => {
|
|
1169
|
-
return {
|
|
1170
|
-
[TELEMETRY_HEADER_SDK]: telemetry.sdk,
|
|
1171
|
-
[TELEMETRY_HEADER_FRAMEWORK]: telemetry.framework,
|
|
1172
|
-
[TELEMETRY_HEADER_RUNTIME]: telemetry.runtime ?? "unknown"
|
|
1173
|
-
};
|
|
1174
|
-
};
|
|
1175
|
-
var
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
839
|
+
var getTelemetryHeaders = (telemetry) => {
|
|
840
|
+
return {
|
|
841
|
+
[TELEMETRY_HEADER_SDK]: telemetry.sdk,
|
|
842
|
+
[TELEMETRY_HEADER_FRAMEWORK]: telemetry.framework,
|
|
843
|
+
[TELEMETRY_HEADER_RUNTIME]: telemetry.runtime ?? "unknown"
|
|
844
|
+
};
|
|
845
|
+
};
|
|
846
|
+
var verifyRequest = async (body, signature, verifier) => {
|
|
847
|
+
if (!verifier) {
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
try {
|
|
851
|
+
if (!signature) {
|
|
852
|
+
throw new Error("`Upstash-Signature` header is not passed.");
|
|
853
|
+
}
|
|
854
|
+
const isValid = await verifier.verify({
|
|
855
|
+
body,
|
|
856
|
+
signature
|
|
857
|
+
});
|
|
858
|
+
if (!isValid) {
|
|
859
|
+
throw new Error("Signature in `Upstash-Signature` header is not valid");
|
|
860
|
+
}
|
|
861
|
+
} catch (error) {
|
|
862
|
+
throw new WorkflowError(
|
|
863
|
+
`Failed to verify that the Workflow request comes from QStash: ${error}
|
|
864
|
+
|
|
865
|
+
If signature is missing, trigger the workflow endpoint by publishing your request to QStash instead of calling it directly.
|
|
866
|
+
|
|
867
|
+
If you want to disable QStash Verification, you should clear env variables QSTASH_CURRENT_SIGNING_KEY and QSTASH_NEXT_SIGNING_KEY`
|
|
868
|
+
);
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
|
|
872
|
+
// src/context/steps.ts
|
|
873
|
+
var BaseLazyStep = class _BaseLazyStep {
|
|
874
|
+
stepName;
|
|
875
|
+
constructor(stepName) {
|
|
876
|
+
if (!stepName) {
|
|
877
|
+
throw new WorkflowError(
|
|
878
|
+
"A workflow step name cannot be undefined or an empty string. Please provide a name for your workflow step."
|
|
879
|
+
);
|
|
880
|
+
}
|
|
881
|
+
if (typeof stepName !== "string") {
|
|
882
|
+
console.warn(
|
|
883
|
+
"Workflow Warning: A workflow step name must be a string. In a future release, this will throw an error."
|
|
884
|
+
);
|
|
885
|
+
}
|
|
886
|
+
this.stepName = stepName;
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* parse the out field of a step result.
|
|
890
|
+
*
|
|
891
|
+
* will be called when returning the steps to the context from auto executor
|
|
892
|
+
*
|
|
893
|
+
* @param out field of the step
|
|
894
|
+
* @returns parsed out field
|
|
895
|
+
*/
|
|
896
|
+
parseOut(out) {
|
|
897
|
+
if (out === void 0) {
|
|
898
|
+
if (this.allowUndefinedOut) {
|
|
899
|
+
return void 0;
|
|
900
|
+
} else {
|
|
901
|
+
throw new WorkflowError(
|
|
902
|
+
`Error while parsing output of ${this.stepType} step. Expected a string, but got: undefined`
|
|
903
|
+
);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
if (typeof out === "object") {
|
|
907
|
+
if (this.stepType !== "Wait") {
|
|
908
|
+
console.warn(
|
|
909
|
+
`Error while parsing ${this.stepType} step output. Expected a string, but got object. Please reach out to Upstash Support.`
|
|
910
|
+
);
|
|
911
|
+
return out;
|
|
912
|
+
}
|
|
913
|
+
return {
|
|
914
|
+
...out,
|
|
915
|
+
eventData: _BaseLazyStep.tryParsing(out.eventData)
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
if (typeof out !== "string") {
|
|
919
|
+
throw new WorkflowError(
|
|
920
|
+
`Error while parsing output of ${this.stepType} step. Expected a string or undefined, but got: ${typeof out}`
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
return this.safeParseOut(out);
|
|
924
|
+
}
|
|
925
|
+
safeParseOut(out) {
|
|
926
|
+
return _BaseLazyStep.tryParsing(out);
|
|
927
|
+
}
|
|
928
|
+
static tryParsing(stepOut) {
|
|
929
|
+
try {
|
|
930
|
+
return JSON.parse(stepOut);
|
|
931
|
+
} catch {
|
|
932
|
+
return stepOut;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
getBody({ step }) {
|
|
936
|
+
step.out = JSON.stringify(step.out);
|
|
937
|
+
return JSON.stringify(step);
|
|
938
|
+
}
|
|
939
|
+
getHeaders({ context, telemetry, invokeCount, step }) {
|
|
940
|
+
return getHeaders({
|
|
941
|
+
initHeaderValue: "false",
|
|
942
|
+
workflowConfig: {
|
|
943
|
+
workflowRunId: context.workflowRunId,
|
|
944
|
+
workflowUrl: context.url,
|
|
945
|
+
failureUrl: context.failureUrl,
|
|
946
|
+
retries: context.retries,
|
|
947
|
+
useJSONContent: false,
|
|
948
|
+
telemetry,
|
|
949
|
+
flowControl: context.flowControl
|
|
950
|
+
},
|
|
951
|
+
userHeaders: context.headers,
|
|
952
|
+
invokeCount,
|
|
953
|
+
stepInfo: {
|
|
954
|
+
step,
|
|
955
|
+
lazyStep: this
|
|
956
|
+
}
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
async submitStep({ context, body, headers }) {
|
|
960
|
+
return await context.qstashClient.batch([
|
|
961
|
+
{
|
|
962
|
+
body,
|
|
963
|
+
headers,
|
|
964
|
+
method: "POST",
|
|
965
|
+
url: context.url
|
|
966
|
+
}
|
|
967
|
+
]);
|
|
968
|
+
}
|
|
969
|
+
};
|
|
970
|
+
var LazyFunctionStep = class extends BaseLazyStep {
|
|
971
|
+
stepFunction;
|
|
972
|
+
stepType = "Run";
|
|
973
|
+
allowUndefinedOut = true;
|
|
974
|
+
constructor(stepName, stepFunction) {
|
|
975
|
+
super(stepName);
|
|
976
|
+
this.stepFunction = stepFunction;
|
|
977
|
+
}
|
|
978
|
+
getPlanStep(concurrent, targetStep) {
|
|
979
|
+
return {
|
|
980
|
+
stepId: 0,
|
|
981
|
+
stepName: this.stepName,
|
|
982
|
+
stepType: this.stepType,
|
|
983
|
+
concurrent,
|
|
984
|
+
targetStep
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
async getResultStep(concurrent, stepId) {
|
|
988
|
+
let result = this.stepFunction();
|
|
989
|
+
if (result instanceof Promise) {
|
|
990
|
+
result = await result;
|
|
991
|
+
}
|
|
992
|
+
return {
|
|
993
|
+
stepId,
|
|
994
|
+
stepName: this.stepName,
|
|
995
|
+
stepType: this.stepType,
|
|
996
|
+
out: result,
|
|
997
|
+
concurrent
|
|
998
|
+
};
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
var LazySleepStep = class extends BaseLazyStep {
|
|
1002
|
+
sleep;
|
|
1003
|
+
stepType = "SleepFor";
|
|
1004
|
+
allowUndefinedOut = true;
|
|
1005
|
+
constructor(stepName, sleep) {
|
|
1006
|
+
super(stepName);
|
|
1007
|
+
this.sleep = sleep;
|
|
1008
|
+
}
|
|
1009
|
+
getPlanStep(concurrent, targetStep) {
|
|
1010
|
+
return {
|
|
1011
|
+
stepId: 0,
|
|
1012
|
+
stepName: this.stepName,
|
|
1013
|
+
stepType: this.stepType,
|
|
1014
|
+
sleepFor: this.sleep,
|
|
1015
|
+
concurrent,
|
|
1016
|
+
targetStep
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
async getResultStep(concurrent, stepId) {
|
|
1020
|
+
return await Promise.resolve({
|
|
1021
|
+
stepId,
|
|
1022
|
+
stepName: this.stepName,
|
|
1023
|
+
stepType: this.stepType,
|
|
1024
|
+
sleepFor: this.sleep,
|
|
1025
|
+
concurrent
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
async submitStep({ context, body, headers, isParallel }) {
|
|
1029
|
+
return await context.qstashClient.batch([
|
|
1030
|
+
{
|
|
1031
|
+
body,
|
|
1032
|
+
headers,
|
|
1033
|
+
method: "POST",
|
|
1034
|
+
url: context.url,
|
|
1035
|
+
delay: isParallel ? void 0 : this.sleep
|
|
1036
|
+
}
|
|
1037
|
+
]);
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
1041
|
+
sleepUntil;
|
|
1042
|
+
stepType = "SleepUntil";
|
|
1043
|
+
allowUndefinedOut = true;
|
|
1044
|
+
constructor(stepName, sleepUntil) {
|
|
1045
|
+
super(stepName);
|
|
1046
|
+
this.sleepUntil = sleepUntil;
|
|
1047
|
+
}
|
|
1048
|
+
getPlanStep(concurrent, targetStep) {
|
|
1049
|
+
return {
|
|
1050
|
+
stepId: 0,
|
|
1051
|
+
stepName: this.stepName,
|
|
1052
|
+
stepType: this.stepType,
|
|
1053
|
+
sleepUntil: this.sleepUntil,
|
|
1054
|
+
concurrent,
|
|
1055
|
+
targetStep
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
async getResultStep(concurrent, stepId) {
|
|
1059
|
+
return await Promise.resolve({
|
|
1060
|
+
stepId,
|
|
1061
|
+
stepName: this.stepName,
|
|
1062
|
+
stepType: this.stepType,
|
|
1063
|
+
sleepUntil: this.sleepUntil,
|
|
1064
|
+
concurrent
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
safeParseOut() {
|
|
1068
|
+
return void 0;
|
|
1069
|
+
}
|
|
1070
|
+
async submitStep({ context, body, headers, isParallel }) {
|
|
1071
|
+
return await context.qstashClient.batch([
|
|
1072
|
+
{
|
|
1073
|
+
body,
|
|
1074
|
+
headers,
|
|
1075
|
+
method: "POST",
|
|
1076
|
+
url: context.url,
|
|
1077
|
+
notBefore: isParallel ? void 0 : this.sleepUntil
|
|
1078
|
+
}
|
|
1079
|
+
]);
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
1083
|
+
url;
|
|
1084
|
+
method;
|
|
1085
|
+
body;
|
|
1086
|
+
headers;
|
|
1087
|
+
retries;
|
|
1088
|
+
timeout;
|
|
1089
|
+
flowControl;
|
|
1090
|
+
stepType = "Call";
|
|
1091
|
+
allowUndefinedOut = false;
|
|
1092
|
+
constructor(stepName, url, method, body, headers, retries, timeout, flowControl) {
|
|
1093
|
+
super(stepName);
|
|
1094
|
+
this.url = url;
|
|
1095
|
+
this.method = method;
|
|
1096
|
+
this.body = body;
|
|
1097
|
+
this.headers = headers;
|
|
1098
|
+
this.retries = retries;
|
|
1099
|
+
this.timeout = timeout;
|
|
1100
|
+
this.flowControl = flowControl;
|
|
1101
|
+
}
|
|
1102
|
+
getPlanStep(concurrent, targetStep) {
|
|
1103
|
+
return {
|
|
1104
|
+
stepId: 0,
|
|
1105
|
+
stepName: this.stepName,
|
|
1106
|
+
stepType: this.stepType,
|
|
1107
|
+
concurrent,
|
|
1108
|
+
targetStep
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
async getResultStep(concurrent, stepId) {
|
|
1112
|
+
return await Promise.resolve({
|
|
1113
|
+
stepId,
|
|
1114
|
+
stepName: this.stepName,
|
|
1115
|
+
stepType: this.stepType,
|
|
1116
|
+
concurrent,
|
|
1117
|
+
callUrl: this.url,
|
|
1118
|
+
callMethod: this.method,
|
|
1119
|
+
callBody: this.body,
|
|
1120
|
+
callHeaders: this.headers
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
safeParseOut(out) {
|
|
1124
|
+
const { header, status, body } = JSON.parse(out);
|
|
1125
|
+
const responseHeaders = new Headers(header);
|
|
1126
|
+
if (_LazyCallStep.isText(responseHeaders.get("content-type"))) {
|
|
1127
|
+
const bytes = new Uint8Array(out.length);
|
|
1128
|
+
for (let i = 0; i < out.length; i++) {
|
|
1129
|
+
bytes[i] = out.charCodeAt(i);
|
|
1130
|
+
}
|
|
1131
|
+
const processedResult = new TextDecoder().decode(bytes);
|
|
1132
|
+
const newBody = JSON.parse(processedResult).body;
|
|
1133
|
+
return {
|
|
1134
|
+
status,
|
|
1135
|
+
header,
|
|
1136
|
+
body: BaseLazyStep.tryParsing(newBody)
|
|
1137
|
+
};
|
|
1138
|
+
} else {
|
|
1139
|
+
return { header, status, body };
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
static applicationHeaders = /* @__PURE__ */ new Set([
|
|
1143
|
+
"application/json",
|
|
1144
|
+
"application/xml",
|
|
1145
|
+
"application/javascript",
|
|
1146
|
+
"application/x-www-form-urlencoded",
|
|
1147
|
+
"application/xhtml+xml",
|
|
1148
|
+
"application/ld+json",
|
|
1149
|
+
"application/rss+xml",
|
|
1150
|
+
"application/atom+xml"
|
|
1151
|
+
]);
|
|
1152
|
+
static isText = (contentTypeHeader) => {
|
|
1153
|
+
if (!contentTypeHeader) {
|
|
1154
|
+
return false;
|
|
1155
|
+
}
|
|
1156
|
+
if (_LazyCallStep.applicationHeaders.has(contentTypeHeader)) {
|
|
1157
|
+
return true;
|
|
1158
|
+
}
|
|
1159
|
+
if (contentTypeHeader.startsWith("text/")) {
|
|
1160
|
+
return true;
|
|
1161
|
+
}
|
|
1162
|
+
return false;
|
|
1163
|
+
};
|
|
1164
|
+
getBody({ step }) {
|
|
1165
|
+
if (!step.callUrl) {
|
|
1166
|
+
throw new WorkflowError("Incompatible step received in LazyCallStep.getBody");
|
|
1167
|
+
}
|
|
1168
|
+
return JSON.stringify(step.callBody);
|
|
1169
|
+
}
|
|
1170
|
+
getHeaders({ context, telemetry, invokeCount, step }) {
|
|
1171
|
+
const { headers, contentType } = super.getHeaders({ context, telemetry, invokeCount, step });
|
|
1172
|
+
headers["Upstash-Retries"] = this.retries.toString();
|
|
1173
|
+
headers[WORKFLOW_FEATURE_HEADER] = "WF_NoDelete,InitialBody";
|
|
1174
|
+
if (this.flowControl) {
|
|
1175
|
+
const { flowControlKey, flowControlValue } = prepareFlowControl(this.flowControl);
|
|
1176
|
+
headers["Upstash-Flow-Control-Key"] = flowControlKey;
|
|
1177
|
+
headers["Upstash-Flow-Control-Value"] = flowControlValue;
|
|
1178
|
+
}
|
|
1179
|
+
if (this.timeout) {
|
|
1180
|
+
headers["Upstash-Timeout"] = this.timeout.toString();
|
|
1181
|
+
}
|
|
1182
|
+
const forwardedHeaders = Object.fromEntries(
|
|
1183
|
+
Object.entries(this.headers).map(([header, value]) => [`Upstash-Forward-${header}`, value])
|
|
1184
|
+
);
|
|
1185
|
+
return {
|
|
1186
|
+
headers: {
|
|
1187
|
+
...headers,
|
|
1188
|
+
...forwardedHeaders,
|
|
1189
|
+
"Upstash-Callback": context.url,
|
|
1190
|
+
"Upstash-Callback-Workflow-RunId": context.workflowRunId,
|
|
1191
|
+
"Upstash-Callback-Workflow-CallType": "fromCallback",
|
|
1192
|
+
"Upstash-Callback-Workflow-Init": "false",
|
|
1193
|
+
"Upstash-Callback-Workflow-Url": context.url,
|
|
1194
|
+
"Upstash-Callback-Feature-Set": "LazyFetch,InitialBody",
|
|
1195
|
+
"Upstash-Callback-Forward-Upstash-Workflow-Callback": "true",
|
|
1196
|
+
"Upstash-Callback-Forward-Upstash-Workflow-StepId": step.stepId.toString(),
|
|
1197
|
+
"Upstash-Callback-Forward-Upstash-Workflow-StepName": this.stepName,
|
|
1198
|
+
"Upstash-Callback-Forward-Upstash-Workflow-StepType": this.stepType,
|
|
1199
|
+
"Upstash-Callback-Forward-Upstash-Workflow-Concurrent": step.concurrent.toString(),
|
|
1200
|
+
"Upstash-Callback-Forward-Upstash-Workflow-ContentType": contentType,
|
|
1201
|
+
"Upstash-Workflow-CallType": "toCallback"
|
|
1202
|
+
},
|
|
1203
|
+
contentType
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
async submitStep({ context, headers }) {
|
|
1207
|
+
return await context.qstashClient.batch([
|
|
1208
|
+
{
|
|
1209
|
+
headers,
|
|
1210
|
+
body: JSON.stringify(this.body),
|
|
1211
|
+
method: this.method,
|
|
1212
|
+
url: this.url
|
|
1213
|
+
}
|
|
1214
|
+
]);
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
1218
|
+
eventId;
|
|
1219
|
+
timeout;
|
|
1220
|
+
stepType = "Wait";
|
|
1221
|
+
allowUndefinedOut = false;
|
|
1222
|
+
constructor(stepName, eventId, timeout) {
|
|
1223
|
+
super(stepName);
|
|
1224
|
+
this.eventId = eventId;
|
|
1225
|
+
this.timeout = timeout;
|
|
1226
|
+
}
|
|
1227
|
+
getPlanStep(concurrent, targetStep) {
|
|
1228
|
+
return {
|
|
1229
|
+
stepId: 0,
|
|
1230
|
+
stepName: this.stepName,
|
|
1231
|
+
stepType: this.stepType,
|
|
1232
|
+
waitEventId: this.eventId,
|
|
1233
|
+
timeout: this.timeout,
|
|
1234
|
+
concurrent,
|
|
1235
|
+
targetStep
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
async getResultStep(concurrent, stepId) {
|
|
1239
|
+
return await Promise.resolve({
|
|
1240
|
+
stepId,
|
|
1241
|
+
stepName: this.stepName,
|
|
1242
|
+
stepType: this.stepType,
|
|
1243
|
+
waitEventId: this.eventId,
|
|
1244
|
+
timeout: this.timeout,
|
|
1245
|
+
concurrent
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
safeParseOut(out) {
|
|
1249
|
+
const result = JSON.parse(out);
|
|
1250
|
+
return {
|
|
1251
|
+
...result,
|
|
1252
|
+
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
getHeaders({ context, telemetry, invokeCount, step }) {
|
|
1256
|
+
const headers = super.getHeaders({ context, telemetry, invokeCount, step });
|
|
1257
|
+
headers.headers["Upstash-Workflow-CallType"] = "step";
|
|
1258
|
+
return headers;
|
|
1259
|
+
}
|
|
1260
|
+
getBody({ context, step, headers, telemetry }) {
|
|
1261
|
+
if (!step.waitEventId) {
|
|
1262
|
+
throw new WorkflowError("Incompatible step received in LazyWaitForEventStep.getBody");
|
|
1263
|
+
}
|
|
1264
|
+
const timeoutHeaders = {
|
|
1265
|
+
// to include user headers:
|
|
1266
|
+
...Object.fromEntries(Object.entries(headers).map(([header, value]) => [header, [value]])),
|
|
1267
|
+
// to include telemetry headers:
|
|
1268
|
+
...telemetry ? Object.fromEntries(
|
|
1269
|
+
Object.entries(getTelemetryHeaders(telemetry)).map(([header, value]) => [
|
|
1270
|
+
header,
|
|
1271
|
+
[value]
|
|
1272
|
+
])
|
|
1273
|
+
) : {},
|
|
1274
|
+
// note: using WORKFLOW_ID_HEADER doesn't work, because Runid -> RunId:
|
|
1275
|
+
"Upstash-Workflow-Runid": [context.workflowRunId],
|
|
1276
|
+
[WORKFLOW_INIT_HEADER]: ["false"],
|
|
1277
|
+
[WORKFLOW_URL_HEADER]: [context.url],
|
|
1278
|
+
"Upstash-Workflow-CallType": ["step"]
|
|
1279
|
+
};
|
|
1280
|
+
const waitBody = {
|
|
1281
|
+
url: context.url,
|
|
1282
|
+
timeout: step.timeout,
|
|
1283
|
+
timeoutBody: void 0,
|
|
1284
|
+
timeoutUrl: context.url,
|
|
1285
|
+
timeoutHeaders,
|
|
1286
|
+
step: {
|
|
1287
|
+
stepId: step.stepId,
|
|
1288
|
+
stepType: "Wait",
|
|
1289
|
+
stepName: step.stepName,
|
|
1290
|
+
concurrent: step.concurrent,
|
|
1291
|
+
targetStep: step.targetStep
|
|
1292
|
+
}
|
|
1293
|
+
};
|
|
1294
|
+
return JSON.stringify(waitBody);
|
|
1295
|
+
}
|
|
1296
|
+
async submitStep({ context, body, headers }) {
|
|
1297
|
+
const result = await context.qstashClient.http.request({
|
|
1298
|
+
path: ["v2", "wait", this.eventId],
|
|
1299
|
+
body,
|
|
1300
|
+
headers,
|
|
1301
|
+
method: "POST",
|
|
1302
|
+
parseResponseAsJson: false
|
|
1303
|
+
});
|
|
1304
|
+
return [result];
|
|
1305
|
+
}
|
|
1306
|
+
};
|
|
1307
|
+
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1308
|
+
stepType = "Notify";
|
|
1309
|
+
constructor(stepName, eventId, eventData, requester) {
|
|
1310
|
+
super(stepName, async () => {
|
|
1311
|
+
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
1312
|
+
return {
|
|
1313
|
+
eventId,
|
|
1314
|
+
eventData,
|
|
1315
|
+
notifyResponse
|
|
1316
|
+
};
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
safeParseOut(out) {
|
|
1320
|
+
const result = JSON.parse(out);
|
|
1321
|
+
return {
|
|
1322
|
+
...result,
|
|
1323
|
+
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
};
|
|
1327
|
+
var LazyInvokeStep = class extends BaseLazyStep {
|
|
1328
|
+
stepType = "Invoke";
|
|
1329
|
+
params;
|
|
1330
|
+
allowUndefinedOut = false;
|
|
1331
|
+
/**
|
|
1332
|
+
* workflow id of the invoked workflow
|
|
1333
|
+
*/
|
|
1334
|
+
workflowId;
|
|
1335
|
+
constructor(stepName, {
|
|
1336
|
+
workflow,
|
|
1337
|
+
body,
|
|
1338
|
+
headers = {},
|
|
1339
|
+
workflowRunId,
|
|
1340
|
+
retries,
|
|
1341
|
+
flowControl
|
|
1342
|
+
}) {
|
|
1343
|
+
super(stepName);
|
|
1344
|
+
this.params = {
|
|
1345
|
+
workflow,
|
|
1346
|
+
body,
|
|
1347
|
+
headers,
|
|
1348
|
+
workflowRunId: getWorkflowRunId(workflowRunId),
|
|
1349
|
+
retries,
|
|
1350
|
+
flowControl
|
|
1351
|
+
};
|
|
1352
|
+
const { workflowId } = workflow;
|
|
1353
|
+
if (!workflowId) {
|
|
1354
|
+
throw new WorkflowError("You can only invoke workflow which has a workflowId");
|
|
1355
|
+
}
|
|
1356
|
+
this.workflowId = workflowId;
|
|
1357
|
+
}
|
|
1358
|
+
getPlanStep(concurrent, targetStep) {
|
|
1359
|
+
return {
|
|
1360
|
+
stepId: 0,
|
|
1361
|
+
stepName: this.stepName,
|
|
1362
|
+
stepType: this.stepType,
|
|
1363
|
+
concurrent,
|
|
1364
|
+
targetStep
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
/**
|
|
1368
|
+
* won't be used as it's the server who will add the result step
|
|
1369
|
+
* in Invoke step.
|
|
1370
|
+
*/
|
|
1371
|
+
getResultStep(concurrent, stepId) {
|
|
1372
|
+
return Promise.resolve({
|
|
1373
|
+
stepId,
|
|
1374
|
+
stepName: this.stepName,
|
|
1375
|
+
stepType: this.stepType,
|
|
1376
|
+
concurrent
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
safeParseOut(out) {
|
|
1380
|
+
const result = JSON.parse(out);
|
|
1381
|
+
return {
|
|
1382
|
+
...result,
|
|
1383
|
+
body: BaseLazyStep.tryParsing(result.body)
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
getBody({ context, step, telemetry, invokeCount }) {
|
|
1387
|
+
const { headers: invokerHeaders } = getHeaders({
|
|
1388
|
+
initHeaderValue: "false",
|
|
1389
|
+
workflowConfig: {
|
|
1390
|
+
workflowRunId: context.workflowRunId,
|
|
1391
|
+
workflowUrl: context.url,
|
|
1392
|
+
failureUrl: context.failureUrl,
|
|
1393
|
+
retries: context.retries,
|
|
1394
|
+
telemetry,
|
|
1395
|
+
flowControl: context.flowControl,
|
|
1396
|
+
useJSONContent: false
|
|
1397
|
+
},
|
|
1398
|
+
userHeaders: context.headers,
|
|
1399
|
+
invokeCount
|
|
1400
|
+
});
|
|
1401
|
+
invokerHeaders["Upstash-Workflow-Runid"] = context.workflowRunId;
|
|
1402
|
+
const request = {
|
|
1403
|
+
body: JSON.stringify(this.params.body),
|
|
1404
|
+
headers: Object.fromEntries(
|
|
1405
|
+
Object.entries(invokerHeaders).map((pairs) => [pairs[0], [pairs[1]]])
|
|
1406
|
+
),
|
|
1407
|
+
workflowRunId: context.workflowRunId,
|
|
1408
|
+
workflowUrl: context.url,
|
|
1409
|
+
step
|
|
1410
|
+
};
|
|
1411
|
+
return JSON.stringify(request);
|
|
1412
|
+
}
|
|
1413
|
+
getHeaders({ context, telemetry, invokeCount }) {
|
|
1414
|
+
const {
|
|
1415
|
+
workflow,
|
|
1416
|
+
headers = {},
|
|
1417
|
+
workflowRunId = getWorkflowRunId(),
|
|
1418
|
+
retries,
|
|
1419
|
+
flowControl
|
|
1420
|
+
} = this.params;
|
|
1421
|
+
const newUrl = context.url.replace(/[^/]+$/, this.workflowId);
|
|
1422
|
+
const {
|
|
1423
|
+
retries: workflowRetries,
|
|
1424
|
+
failureFunction,
|
|
1425
|
+
failureUrl,
|
|
1426
|
+
useJSONContent,
|
|
1427
|
+
flowControl: workflowFlowControl
|
|
1428
|
+
} = workflow.options;
|
|
1429
|
+
const { headers: triggerHeaders, contentType } = getHeaders({
|
|
1430
|
+
initHeaderValue: "true",
|
|
1431
|
+
workflowConfig: {
|
|
1432
|
+
workflowRunId,
|
|
1433
|
+
workflowUrl: newUrl,
|
|
1434
|
+
retries: retries ?? workflowRetries,
|
|
1435
|
+
telemetry,
|
|
1436
|
+
failureUrl: failureFunction ? newUrl : failureUrl,
|
|
1437
|
+
flowControl: flowControl ?? workflowFlowControl,
|
|
1438
|
+
useJSONContent: useJSONContent ?? false
|
|
1439
|
+
},
|
|
1440
|
+
invokeCount: invokeCount + 1,
|
|
1441
|
+
userHeaders: new Headers(headers)
|
|
1442
|
+
});
|
|
1443
|
+
triggerHeaders["Upstash-Workflow-Invoke"] = "true";
|
|
1444
|
+
return { headers: triggerHeaders, contentType };
|
|
1445
|
+
}
|
|
1446
|
+
async submitStep({ context, body, headers }) {
|
|
1447
|
+
const newUrl = context.url.replace(/[^/]+$/, this.workflowId);
|
|
1448
|
+
const result = await context.qstashClient.publish({
|
|
1449
|
+
headers,
|
|
1450
|
+
method: "POST",
|
|
1451
|
+
body,
|
|
1452
|
+
url: newUrl
|
|
1453
|
+
});
|
|
1454
|
+
return [result];
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
|
|
1458
|
+
// src/agents/constants.ts
|
|
1459
|
+
var AGENT_NAME_HEADER = "upstash-agent-name";
|
|
1460
|
+
var MANAGER_AGENT_PROMPT = `You are an agent orchestrating other AI Agents.
|
|
1461
|
+
|
|
1462
|
+
These other agents have tools available to them.
|
|
1463
|
+
|
|
1464
|
+
Given a prompt, utilize these agents to address requests.
|
|
1465
|
+
|
|
1466
|
+
Don't always call all the agents provided to you at the same time. You can call one and use it's response to call another.
|
|
1467
|
+
|
|
1468
|
+
Avoid calling the same agent twice in one turn. Instead, prefer to call it once but provide everything
|
|
1469
|
+
you need from that agent.
|
|
1470
|
+
`;
|
|
1471
|
+
|
|
1472
|
+
// src/qstash/headers.ts
|
|
1473
|
+
var WorkflowHeaders = class {
|
|
1474
|
+
userHeaders;
|
|
1475
|
+
workflowConfig;
|
|
1476
|
+
invokeCount;
|
|
1477
|
+
initHeaderValue;
|
|
1478
|
+
stepInfo;
|
|
1479
|
+
headers;
|
|
1480
|
+
constructor({
|
|
1481
|
+
userHeaders,
|
|
1482
|
+
workflowConfig,
|
|
1483
|
+
invokeCount,
|
|
1484
|
+
initHeaderValue,
|
|
1485
|
+
stepInfo
|
|
1486
|
+
}) {
|
|
1487
|
+
this.userHeaders = userHeaders;
|
|
1488
|
+
this.workflowConfig = workflowConfig;
|
|
1489
|
+
this.invokeCount = invokeCount;
|
|
1490
|
+
this.initHeaderValue = initHeaderValue;
|
|
1491
|
+
this.stepInfo = stepInfo;
|
|
1492
|
+
this.headers = {
|
|
1493
|
+
rawHeaders: {},
|
|
1494
|
+
workflowHeaders: {},
|
|
1495
|
+
failureHeaders: {}
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
getHeaders() {
|
|
1499
|
+
this.addBaseHeaders();
|
|
1500
|
+
this.addRetries();
|
|
1501
|
+
this.addFlowControl();
|
|
1502
|
+
this.addUserHeaders();
|
|
1503
|
+
this.addInvokeCount();
|
|
1504
|
+
this.addFailureUrl();
|
|
1505
|
+
const contentType = this.addContentType();
|
|
1506
|
+
return this.prefixHeaders(contentType);
|
|
1507
|
+
}
|
|
1508
|
+
addBaseHeaders() {
|
|
1509
|
+
this.headers.rawHeaders = {
|
|
1510
|
+
...this.headers.rawHeaders,
|
|
1511
|
+
[WORKFLOW_INIT_HEADER]: this.initHeaderValue,
|
|
1512
|
+
[WORKFLOW_ID_HEADER]: this.workflowConfig.workflowRunId,
|
|
1513
|
+
[WORKFLOW_URL_HEADER]: this.workflowConfig.workflowUrl,
|
|
1514
|
+
[WORKFLOW_FEATURE_HEADER]: "LazyFetch,InitialBody",
|
|
1515
|
+
[WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION,
|
|
1516
|
+
...this.workflowConfig.telemetry ? getTelemetryHeaders(this.workflowConfig.telemetry) : {},
|
|
1517
|
+
...this.workflowConfig.telemetry && this.stepInfo?.lazyStep instanceof LazyCallStep && this.stepInfo.lazyStep.headers[AGENT_NAME_HEADER] ? { [TELEMETRY_HEADER_AGENT]: "true" } : {}
|
|
1518
|
+
};
|
|
1519
|
+
if (this.stepInfo?.lazyStep.stepType !== "Call") {
|
|
1520
|
+
this.headers.rawHeaders[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`] = WORKFLOW_PROTOCOL_VERSION;
|
|
1245
1521
|
}
|
|
1246
|
-
}
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1522
|
+
}
|
|
1523
|
+
addInvokeCount() {
|
|
1524
|
+
if (this.invokeCount === void 0 || this.invokeCount === 0) {
|
|
1525
|
+
return;
|
|
1526
|
+
}
|
|
1527
|
+
const invokeCount = this.invokeCount.toString();
|
|
1528
|
+
this.headers.workflowHeaders[`Forward-${WORKFLOW_INVOKE_COUNT_HEADER}`] = invokeCount;
|
|
1529
|
+
if (this.workflowConfig.failureUrl) {
|
|
1530
|
+
this.headers.failureHeaders[`Forward-${WORKFLOW_INVOKE_COUNT_HEADER}`] = invokeCount;
|
|
1251
1531
|
}
|
|
1252
|
-
if (
|
|
1253
|
-
|
|
1254
|
-
baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
|
|
1532
|
+
if (this.stepInfo?.lazyStep instanceof LazyCallStep) {
|
|
1533
|
+
this.headers.rawHeaders[`Upstash-Forward-${WORKFLOW_INVOKE_COUNT_HEADER}`] = invokeCount;
|
|
1255
1534
|
}
|
|
1256
1535
|
}
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1536
|
+
addRetries() {
|
|
1537
|
+
if (this.workflowConfig.retries === void 0 || this.workflowConfig.retries === DEFAULT_RETRIES) {
|
|
1538
|
+
return;
|
|
1539
|
+
}
|
|
1540
|
+
const retries = this.workflowConfig.retries.toString();
|
|
1541
|
+
this.headers.workflowHeaders["Retries"] = retries;
|
|
1542
|
+
if (this.workflowConfig.failureUrl) {
|
|
1543
|
+
this.headers.failureHeaders["Retries"] = retries;
|
|
1265
1544
|
}
|
|
1266
1545
|
}
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1546
|
+
addFlowControl() {
|
|
1547
|
+
if (!this.workflowConfig.flowControl) {
|
|
1548
|
+
return;
|
|
1549
|
+
}
|
|
1550
|
+
const { flowControlKey, flowControlValue } = prepareFlowControl(
|
|
1551
|
+
this.workflowConfig.flowControl
|
|
1273
1552
|
);
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
"Upstash-Callback-Forward-Upstash-Workflow-StepType": step.stepType,
|
|
1288
|
-
"Upstash-Callback-Forward-Upstash-Workflow-Concurrent": step.concurrent.toString(),
|
|
1289
|
-
"Upstash-Callback-Forward-Upstash-Workflow-ContentType": contentType,
|
|
1290
|
-
[`Upstash-Callback-Forward-${WORKFLOW_INVOKE_COUNT_HEADER}`]: (invokeCount ?? 0).toString(),
|
|
1291
|
-
"Upstash-Workflow-CallType": "toCallback"
|
|
1553
|
+
this.headers.workflowHeaders["Flow-Control-Key"] = flowControlKey;
|
|
1554
|
+
this.headers.workflowHeaders["Flow-Control-Value"] = flowControlValue;
|
|
1555
|
+
if (this.workflowConfig.failureUrl) {
|
|
1556
|
+
this.headers.failureHeaders["Flow-Control-Key"] = flowControlKey;
|
|
1557
|
+
this.headers.failureHeaders["Flow-Control-Value"] = flowControlValue;
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
addUserHeaders() {
|
|
1561
|
+
for (const [key, value] of this.userHeaders.entries()) {
|
|
1562
|
+
const forwardKey = `Forward-${key}`;
|
|
1563
|
+
this.headers.workflowHeaders[forwardKey] = value;
|
|
1564
|
+
if (this.workflowConfig.failureUrl) {
|
|
1565
|
+
this.headers.failureHeaders[forwardKey] = value;
|
|
1292
1566
|
}
|
|
1293
|
-
}
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
addFailureUrl() {
|
|
1570
|
+
if (!this.workflowConfig.failureUrl) {
|
|
1571
|
+
return;
|
|
1572
|
+
}
|
|
1573
|
+
this.headers.workflowHeaders["Failure-Callback"] = this.workflowConfig.failureUrl;
|
|
1574
|
+
this.headers.failureHeaders[`Forward-${WORKFLOW_FAILURE_HEADER}`] = "true";
|
|
1575
|
+
this.headers.failureHeaders[`Forward-Upstash-Workflow-Failure-Callback`] = "true";
|
|
1576
|
+
this.headers.failureHeaders["Workflow-Runid"] = this.workflowConfig.workflowRunId;
|
|
1577
|
+
this.headers.failureHeaders["Workflow-Init"] = "false";
|
|
1578
|
+
this.headers.failureHeaders["Workflow-Url"] = this.workflowConfig.workflowUrl;
|
|
1579
|
+
this.headers.failureHeaders["Workflow-Calltype"] = "failureCall";
|
|
1580
|
+
this.headers.failureHeaders["Feature-Set"] = "LazyFetch,InitialBody";
|
|
1581
|
+
if (this.workflowConfig.retries !== void 0 && this.workflowConfig.retries !== DEFAULT_RETRIES) {
|
|
1582
|
+
this.headers.failureHeaders["Retries"] = this.workflowConfig.retries.toString();
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
addContentType() {
|
|
1586
|
+
if (this.workflowConfig.useJSONContent) {
|
|
1587
|
+
this.headers.rawHeaders["content-type"] = "application/json";
|
|
1588
|
+
return "application/json";
|
|
1589
|
+
}
|
|
1590
|
+
const callHeaders = new Headers(
|
|
1591
|
+
this.stepInfo?.lazyStep instanceof LazyCallStep ? this.stepInfo.lazyStep.headers : {}
|
|
1592
|
+
);
|
|
1593
|
+
const contentType = (callHeaders.get("content-type") ? callHeaders.get("content-type") : this.userHeaders?.get("Content-Type") ? this.userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
|
|
1594
|
+
this.headers.rawHeaders["content-type"] = contentType;
|
|
1595
|
+
return contentType;
|
|
1294
1596
|
}
|
|
1295
|
-
|
|
1597
|
+
prefixHeaders(contentType) {
|
|
1598
|
+
const { rawHeaders, workflowHeaders, failureHeaders } = this.headers;
|
|
1599
|
+
const isCall = this.stepInfo?.lazyStep.stepType === "Call";
|
|
1296
1600
|
return {
|
|
1297
1601
|
headers: {
|
|
1298
|
-
...
|
|
1299
|
-
"Upstash-
|
|
1602
|
+
...rawHeaders,
|
|
1603
|
+
...addPrefixToHeaders(workflowHeaders, isCall ? "Upstash-Callback-" : "Upstash-"),
|
|
1604
|
+
...addPrefixToHeaders(failureHeaders, "Upstash-Failure-Callback-"),
|
|
1605
|
+
...isCall ? addPrefixToHeaders(failureHeaders, "Upstash-Callback-Failure-Callback-") : {}
|
|
1300
1606
|
},
|
|
1301
|
-
|
|
1302
|
-
// to include user headers:
|
|
1303
|
-
...Object.fromEntries(
|
|
1304
|
-
Object.entries(baseHeaders).map(([header, value]) => [header, [value]])
|
|
1305
|
-
),
|
|
1306
|
-
// to include telemetry headers:
|
|
1307
|
-
...telemetry ? Object.fromEntries(
|
|
1308
|
-
Object.entries(getTelemetryHeaders(telemetry)).map(([header, value]) => [
|
|
1309
|
-
header,
|
|
1310
|
-
[value]
|
|
1311
|
-
])
|
|
1312
|
-
) : {},
|
|
1313
|
-
// note: using WORKFLOW_ID_HEADER doesn't work, because Runid -> RunId:
|
|
1314
|
-
"Upstash-Workflow-Runid": [workflowRunId],
|
|
1315
|
-
[WORKFLOW_INIT_HEADER]: ["false"],
|
|
1316
|
-
[WORKFLOW_URL_HEADER]: [workflowUrl],
|
|
1317
|
-
"Upstash-Workflow-CallType": ["step"]
|
|
1318
|
-
}
|
|
1607
|
+
contentType
|
|
1319
1608
|
};
|
|
1320
1609
|
}
|
|
1321
|
-
return { headers: baseHeaders };
|
|
1322
1610
|
};
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
try {
|
|
1328
|
-
if (!signature) {
|
|
1329
|
-
throw new Error("`Upstash-Signature` header is not passed.");
|
|
1330
|
-
}
|
|
1331
|
-
const isValid = await verifier.verify({
|
|
1332
|
-
body,
|
|
1333
|
-
signature
|
|
1334
|
-
});
|
|
1335
|
-
if (!isValid) {
|
|
1336
|
-
throw new Error("Signature in `Upstash-Signature` header is not valid");
|
|
1337
|
-
}
|
|
1338
|
-
} catch (error) {
|
|
1339
|
-
throw new WorkflowError(
|
|
1340
|
-
`Failed to verify that the Workflow request comes from QStash: ${error}
|
|
1341
|
-
|
|
1342
|
-
If signature is missing, trigger the workflow endpoint by publishing your request to QStash instead of calling it directly.
|
|
1343
|
-
|
|
1344
|
-
If you want to disable QStash Verification, you should clear env variables QSTASH_CURRENT_SIGNING_KEY and QSTASH_NEXT_SIGNING_KEY`
|
|
1345
|
-
);
|
|
1611
|
+
function addPrefixToHeaders(headers, prefix) {
|
|
1612
|
+
const prefixedHeaders = {};
|
|
1613
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
1614
|
+
prefixedHeaders[`${prefix}${key}`] = value;
|
|
1346
1615
|
}
|
|
1347
|
-
|
|
1616
|
+
return prefixedHeaders;
|
|
1617
|
+
}
|
|
1348
1618
|
var prepareFlowControl = (flowControl) => {
|
|
1349
1619
|
const parallelism = flowControl.parallelism?.toString();
|
|
1350
|
-
const rate = flowControl.ratePerSecond?.toString();
|
|
1620
|
+
const rate = (flowControl.rate ?? flowControl.ratePerSecond)?.toString();
|
|
1621
|
+
const period = typeof flowControl.period === "number" ? `${flowControl.period}s` : flowControl.period;
|
|
1351
1622
|
const controlValue = [
|
|
1352
1623
|
parallelism ? `parallelism=${parallelism}` : void 0,
|
|
1353
|
-
rate ? `rate=${rate}` : void 0
|
|
1624
|
+
rate ? `rate=${rate}` : void 0,
|
|
1625
|
+
period ? `period=${period}` : void 0
|
|
1354
1626
|
].filter(Boolean);
|
|
1355
1627
|
if (controlValue.length === 0) {
|
|
1356
|
-
throw new
|
|
1628
|
+
throw new import_qstash4.QstashError("Provide at least one of parallelism or ratePerSecond for flowControl");
|
|
1357
1629
|
}
|
|
1358
1630
|
return {
|
|
1359
1631
|
flowControlKey: flowControl.key,
|
|
1360
1632
|
flowControlValue: controlValue.join(", ")
|
|
1361
1633
|
};
|
|
1362
1634
|
};
|
|
1635
|
+
var getHeaders = (params) => {
|
|
1636
|
+
const workflowHeaders = new WorkflowHeaders(params);
|
|
1637
|
+
return workflowHeaders.getHeaders();
|
|
1638
|
+
};
|
|
1363
1639
|
|
|
1364
|
-
// src/
|
|
1365
|
-
var
|
|
1366
|
-
|
|
1367
|
-
// src/serve/serve-many.ts
|
|
1368
|
-
var invokeWorkflow = async ({
|
|
1369
|
-
settings,
|
|
1370
|
-
invokeStep,
|
|
1640
|
+
// src/qstash/submit-steps.ts
|
|
1641
|
+
var submitParallelSteps = async ({
|
|
1371
1642
|
context,
|
|
1643
|
+
steps,
|
|
1644
|
+
initialStepCount,
|
|
1372
1645
|
invokeCount,
|
|
1373
|
-
telemetry
|
|
1646
|
+
telemetry,
|
|
1647
|
+
debug
|
|
1374
1648
|
}) => {
|
|
1375
|
-
const
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1649
|
+
const planSteps = steps.map(
|
|
1650
|
+
(step, index) => step.getPlanStep(steps.length, initialStepCount + index)
|
|
1651
|
+
);
|
|
1652
|
+
await debug?.log("SUBMIT", "SUBMIT_STEP", {
|
|
1653
|
+
length: planSteps.length,
|
|
1654
|
+
steps: planSteps
|
|
1655
|
+
});
|
|
1656
|
+
const result = await context.qstashClient.batch(
|
|
1657
|
+
planSteps.map((planStep) => {
|
|
1658
|
+
const { headers } = getHeaders({
|
|
1659
|
+
initHeaderValue: "false",
|
|
1660
|
+
workflowConfig: {
|
|
1661
|
+
workflowRunId: context.workflowRunId,
|
|
1662
|
+
workflowUrl: context.url,
|
|
1663
|
+
failureUrl: context.failureUrl,
|
|
1664
|
+
retries: context.retries,
|
|
1665
|
+
flowControl: context.flowControl,
|
|
1666
|
+
telemetry
|
|
1667
|
+
},
|
|
1668
|
+
userHeaders: context.headers,
|
|
1669
|
+
invokeCount
|
|
1670
|
+
});
|
|
1671
|
+
return {
|
|
1672
|
+
headers,
|
|
1673
|
+
method: "POST",
|
|
1674
|
+
url: context.url,
|
|
1675
|
+
body: JSON.stringify(planStep),
|
|
1676
|
+
notBefore: planStep.sleepUntil,
|
|
1677
|
+
delay: planStep.sleepFor
|
|
1678
|
+
};
|
|
1679
|
+
})
|
|
1680
|
+
);
|
|
1681
|
+
await debug?.log("INFO", "SUBMIT_STEP", {
|
|
1682
|
+
messageIds: result.map((message) => {
|
|
1683
|
+
return {
|
|
1684
|
+
message: message.messageId
|
|
1685
|
+
};
|
|
1686
|
+
})
|
|
1687
|
+
});
|
|
1688
|
+
throw new WorkflowAbort(planSteps[0].stepName, planSteps[0]);
|
|
1689
|
+
};
|
|
1690
|
+
var submitSingleStep = async ({
|
|
1691
|
+
context,
|
|
1692
|
+
lazyStep,
|
|
1693
|
+
stepId,
|
|
1694
|
+
invokeCount,
|
|
1695
|
+
concurrency,
|
|
1696
|
+
telemetry,
|
|
1697
|
+
debug
|
|
1698
|
+
}) => {
|
|
1699
|
+
const resultStep = await lazyStep.getResultStep(concurrency, stepId);
|
|
1700
|
+
await debug?.log("INFO", "RUN_SINGLE", {
|
|
1701
|
+
fromRequest: false,
|
|
1702
|
+
step: resultStep,
|
|
1703
|
+
stepCount: stepId
|
|
1704
|
+
});
|
|
1705
|
+
const { headers } = lazyStep.getHeaders({
|
|
1706
|
+
context,
|
|
1707
|
+
step: resultStep,
|
|
1402
1708
|
invokeCount,
|
|
1403
|
-
|
|
1709
|
+
telemetry
|
|
1404
1710
|
});
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
userHeaders: new Headers(headers),
|
|
1412
|
-
retries: retries ?? workflowRetries,
|
|
1413
|
-
telemetry,
|
|
1414
|
-
failureUrl: failureFunction ? newUrl : failureUrl,
|
|
1415
|
-
invokeCount: invokeCount + 1,
|
|
1416
|
-
flowControl: flowControl ?? workflowFlowControl
|
|
1711
|
+
const body = lazyStep.getBody({
|
|
1712
|
+
context,
|
|
1713
|
+
step: resultStep,
|
|
1714
|
+
headers,
|
|
1715
|
+
invokeCount,
|
|
1716
|
+
telemetry
|
|
1417
1717
|
});
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
}
|
|
1422
|
-
const
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
};
|
|
1431
|
-
await
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1718
|
+
await debug?.log("SUBMIT", "SUBMIT_STEP", {
|
|
1719
|
+
length: 1,
|
|
1720
|
+
steps: [resultStep]
|
|
1721
|
+
});
|
|
1722
|
+
const submitResult = await lazyStep.submitStep({
|
|
1723
|
+
context,
|
|
1724
|
+
body,
|
|
1725
|
+
headers,
|
|
1726
|
+
isParallel: concurrency !== NO_CONCURRENCY,
|
|
1727
|
+
invokeCount,
|
|
1728
|
+
step: resultStep,
|
|
1729
|
+
telemetry
|
|
1730
|
+
});
|
|
1731
|
+
await debug?.log("INFO", "SUBMIT_STEP", {
|
|
1732
|
+
messageIds: submitResult.map((message) => {
|
|
1733
|
+
return {
|
|
1734
|
+
message: message.messageId
|
|
1735
|
+
};
|
|
1736
|
+
})
|
|
1436
1737
|
});
|
|
1738
|
+
return resultStep;
|
|
1437
1739
|
};
|
|
1438
1740
|
|
|
1439
1741
|
// src/context/auto-executor.ts
|
|
@@ -1540,14 +1842,16 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1540
1842
|
});
|
|
1541
1843
|
return lazyStep.parseOut(step.out);
|
|
1542
1844
|
}
|
|
1543
|
-
const resultStep = await
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1845
|
+
const resultStep = await submitSingleStep({
|
|
1846
|
+
context: this.context,
|
|
1847
|
+
lazyStep,
|
|
1848
|
+
stepId: this.stepCount,
|
|
1849
|
+
invokeCount: this.invokeCount,
|
|
1850
|
+
concurrency: 1,
|
|
1851
|
+
telemetry: this.telemetry,
|
|
1852
|
+
debug: this.debug
|
|
1548
1853
|
});
|
|
1549
|
-
|
|
1550
|
-
return resultStep.out;
|
|
1854
|
+
throw new WorkflowAbort(lazyStep.stepName, resultStep);
|
|
1551
1855
|
}
|
|
1552
1856
|
/**
|
|
1553
1857
|
* Runs steps in parallel.
|
|
@@ -1575,10 +1879,14 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1575
1879
|
});
|
|
1576
1880
|
switch (parallelCallState) {
|
|
1577
1881
|
case "first": {
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1882
|
+
await submitParallelSteps({
|
|
1883
|
+
context: this.context,
|
|
1884
|
+
steps: parallelSteps,
|
|
1885
|
+
initialStepCount,
|
|
1886
|
+
invokeCount: this.invokeCount,
|
|
1887
|
+
telemetry: this.telemetry,
|
|
1888
|
+
debug: this.debug
|
|
1889
|
+
});
|
|
1582
1890
|
break;
|
|
1583
1891
|
}
|
|
1584
1892
|
case "partial": {
|
|
@@ -1592,13 +1900,18 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1592
1900
|
validateStep(parallelSteps[stepIndex], planStep);
|
|
1593
1901
|
try {
|
|
1594
1902
|
const parallelStep = parallelSteps[stepIndex];
|
|
1595
|
-
const resultStep = await
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1903
|
+
const resultStep = await submitSingleStep({
|
|
1904
|
+
context: this.context,
|
|
1905
|
+
lazyStep: parallelStep,
|
|
1906
|
+
stepId: planStep.targetStep,
|
|
1907
|
+
invokeCount: this.invokeCount,
|
|
1908
|
+
concurrency: parallelSteps.length,
|
|
1909
|
+
telemetry: this.telemetry,
|
|
1910
|
+
debug: this.debug
|
|
1911
|
+
});
|
|
1912
|
+
throw new WorkflowAbort(parallelStep.stepName, resultStep);
|
|
1600
1913
|
} catch (error) {
|
|
1601
|
-
if (error instanceof WorkflowAbort || error instanceof
|
|
1914
|
+
if (error instanceof WorkflowAbort || error instanceof import_qstash5.QstashError && error.status === 400) {
|
|
1602
1915
|
throw error;
|
|
1603
1916
|
}
|
|
1604
1917
|
throw new WorkflowError(
|
|
@@ -1654,128 +1967,6 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1654
1967
|
return "discard";
|
|
1655
1968
|
}
|
|
1656
1969
|
}
|
|
1657
|
-
/**
|
|
1658
|
-
* sends the steps to QStash as batch
|
|
1659
|
-
*
|
|
1660
|
-
* @param steps steps to send
|
|
1661
|
-
*/
|
|
1662
|
-
async submitStepsToQStash(steps, lazySteps) {
|
|
1663
|
-
if (steps.length === 0) {
|
|
1664
|
-
throw new WorkflowError(
|
|
1665
|
-
`Unable to submit steps to QStash. Provided list is empty. Current step: ${this.stepCount}`
|
|
1666
|
-
);
|
|
1667
|
-
}
|
|
1668
|
-
await this.debug?.log("SUBMIT", "SUBMIT_STEP", {
|
|
1669
|
-
length: steps.length,
|
|
1670
|
-
steps
|
|
1671
|
-
});
|
|
1672
|
-
if (steps[0].waitEventId && steps.length === 1) {
|
|
1673
|
-
const waitStep = steps[0];
|
|
1674
|
-
const { headers, timeoutHeaders } = getHeaders({
|
|
1675
|
-
initHeaderValue: "false",
|
|
1676
|
-
workflowRunId: this.context.workflowRunId,
|
|
1677
|
-
workflowUrl: this.context.url,
|
|
1678
|
-
userHeaders: this.context.headers,
|
|
1679
|
-
step: waitStep,
|
|
1680
|
-
failureUrl: this.context.failureUrl,
|
|
1681
|
-
retries: this.context.retries,
|
|
1682
|
-
telemetry: this.telemetry,
|
|
1683
|
-
invokeCount: this.invokeCount,
|
|
1684
|
-
flowControl: this.context.flowControl
|
|
1685
|
-
});
|
|
1686
|
-
const waitBody = {
|
|
1687
|
-
url: this.context.url,
|
|
1688
|
-
timeout: waitStep.timeout,
|
|
1689
|
-
timeoutBody: void 0,
|
|
1690
|
-
timeoutUrl: this.context.url,
|
|
1691
|
-
timeoutHeaders,
|
|
1692
|
-
step: {
|
|
1693
|
-
stepId: waitStep.stepId,
|
|
1694
|
-
stepType: "Wait",
|
|
1695
|
-
stepName: waitStep.stepName,
|
|
1696
|
-
concurrent: waitStep.concurrent,
|
|
1697
|
-
targetStep: waitStep.targetStep
|
|
1698
|
-
}
|
|
1699
|
-
};
|
|
1700
|
-
await this.context.qstashClient.http.request({
|
|
1701
|
-
path: ["v2", "wait", waitStep.waitEventId],
|
|
1702
|
-
body: JSON.stringify(waitBody),
|
|
1703
|
-
headers,
|
|
1704
|
-
method: "POST",
|
|
1705
|
-
parseResponseAsJson: false
|
|
1706
|
-
});
|
|
1707
|
-
throw new WorkflowAbort(waitStep.stepName, waitStep);
|
|
1708
|
-
}
|
|
1709
|
-
if (steps.length === 1 && lazySteps[0] instanceof LazyInvokeStep) {
|
|
1710
|
-
const invokeStep = steps[0];
|
|
1711
|
-
const lazyInvokeStep = lazySteps[0];
|
|
1712
|
-
await invokeWorkflow({
|
|
1713
|
-
settings: lazyInvokeStep.params,
|
|
1714
|
-
invokeStep,
|
|
1715
|
-
context: this.context,
|
|
1716
|
-
invokeCount: this.invokeCount,
|
|
1717
|
-
telemetry: this.telemetry
|
|
1718
|
-
});
|
|
1719
|
-
throw new WorkflowAbort(invokeStep.stepName, invokeStep);
|
|
1720
|
-
}
|
|
1721
|
-
const result = await this.context.qstashClient.batch(
|
|
1722
|
-
steps.map((singleStep, index) => {
|
|
1723
|
-
const lazyStep = lazySteps[index];
|
|
1724
|
-
const { headers } = getHeaders({
|
|
1725
|
-
initHeaderValue: "false",
|
|
1726
|
-
workflowRunId: this.context.workflowRunId,
|
|
1727
|
-
workflowUrl: this.context.url,
|
|
1728
|
-
userHeaders: this.context.headers,
|
|
1729
|
-
step: singleStep,
|
|
1730
|
-
failureUrl: this.context.failureUrl,
|
|
1731
|
-
retries: this.context.retries,
|
|
1732
|
-
callRetries: lazyStep instanceof LazyCallStep ? lazyStep.retries : void 0,
|
|
1733
|
-
callTimeout: lazyStep instanceof LazyCallStep ? lazyStep.timeout : void 0,
|
|
1734
|
-
telemetry: this.telemetry,
|
|
1735
|
-
invokeCount: this.invokeCount,
|
|
1736
|
-
flowControl: this.context.flowControl,
|
|
1737
|
-
callFlowControl: lazyStep instanceof LazyCallStep ? lazyStep.flowControl : void 0
|
|
1738
|
-
});
|
|
1739
|
-
const willWait = singleStep.concurrent === NO_CONCURRENCY || singleStep.stepId === 0;
|
|
1740
|
-
singleStep.out = JSON.stringify(singleStep.out);
|
|
1741
|
-
return singleStep.callUrl && lazyStep instanceof LazyCallStep ? (
|
|
1742
|
-
// if the step is a third party call, we call the third party
|
|
1743
|
-
// url (singleStep.callUrl) and pass information about the workflow
|
|
1744
|
-
// in the headers (handled in getHeaders). QStash makes the request
|
|
1745
|
-
// to callUrl and returns the result to Workflow endpoint.
|
|
1746
|
-
// handleThirdPartyCallResult method sends the result of the third
|
|
1747
|
-
// party call to QStash.
|
|
1748
|
-
{
|
|
1749
|
-
headers,
|
|
1750
|
-
method: singleStep.callMethod,
|
|
1751
|
-
body: JSON.stringify(singleStep.callBody),
|
|
1752
|
-
url: singleStep.callUrl
|
|
1753
|
-
}
|
|
1754
|
-
) : (
|
|
1755
|
-
// if the step is not a third party call, we use workflow
|
|
1756
|
-
// endpoint (context.url) as URL when calling QStash. QStash
|
|
1757
|
-
// calls us back with the updated steps list.
|
|
1758
|
-
{
|
|
1759
|
-
headers,
|
|
1760
|
-
method: "POST",
|
|
1761
|
-
body: JSON.stringify(singleStep),
|
|
1762
|
-
url: this.context.url,
|
|
1763
|
-
notBefore: willWait ? singleStep.sleepUntil : void 0,
|
|
1764
|
-
delay: willWait ? singleStep.sleepFor : void 0
|
|
1765
|
-
}
|
|
1766
|
-
);
|
|
1767
|
-
})
|
|
1768
|
-
);
|
|
1769
|
-
const _result = result;
|
|
1770
|
-
await this.debug?.log("INFO", "SUBMIT_STEP", {
|
|
1771
|
-
messageIds: _result.map((message) => {
|
|
1772
|
-
return {
|
|
1773
|
-
message: message.messageId
|
|
1774
|
-
};
|
|
1775
|
-
})
|
|
1776
|
-
});
|
|
1777
|
-
throw new WorkflowAbort(steps[0].stepName, steps[0]);
|
|
1778
|
-
}
|
|
1779
1970
|
/**
|
|
1780
1971
|
* Get the promise by executing the lazt steps list. If there is a single
|
|
1781
1972
|
* step, we call `runSingle`. Otherwise `runParallel` is called.
|
|
@@ -1849,7 +2040,7 @@ var sortSteps = (steps) => {
|
|
|
1849
2040
|
};
|
|
1850
2041
|
|
|
1851
2042
|
// src/context/api/anthropic.ts
|
|
1852
|
-
var
|
|
2043
|
+
var import_qstash6 = require("@upstash/qstash");
|
|
1853
2044
|
|
|
1854
2045
|
// src/context/provider.ts
|
|
1855
2046
|
var getProviderInfo = (api) => {
|
|
@@ -1913,7 +2104,7 @@ var AnthropicAPI = class extends BaseWorkflowApi {
|
|
|
1913
2104
|
return await this.callApi(stepName, {
|
|
1914
2105
|
api: {
|
|
1915
2106
|
name: "llm",
|
|
1916
|
-
provider: (0,
|
|
2107
|
+
provider: (0, import_qstash6.anthropic)({ token })
|
|
1917
2108
|
},
|
|
1918
2109
|
...parameters
|
|
1919
2110
|
});
|
|
@@ -1921,12 +2112,12 @@ var AnthropicAPI = class extends BaseWorkflowApi {
|
|
|
1921
2112
|
};
|
|
1922
2113
|
|
|
1923
2114
|
// src/context/api/openai.ts
|
|
1924
|
-
var
|
|
2115
|
+
var import_qstash7 = require("@upstash/qstash");
|
|
1925
2116
|
var OpenAIAPI = class extends BaseWorkflowApi {
|
|
1926
2117
|
async call(stepName, settings) {
|
|
1927
2118
|
const { token, organization, operation, baseURL, ...parameters } = settings;
|
|
1928
2119
|
const useOpenAI = baseURL === void 0;
|
|
1929
|
-
const provider = useOpenAI ? (0,
|
|
2120
|
+
const provider = useOpenAI ? (0, import_qstash7.openai)({ token, organization }) : (0, import_qstash7.custom)({ baseUrl: baseURL, token });
|
|
1930
2121
|
return await this.callApi(stepName, {
|
|
1931
2122
|
api: {
|
|
1932
2123
|
name: "llm",
|
|
@@ -1938,14 +2129,14 @@ var OpenAIAPI = class extends BaseWorkflowApi {
|
|
|
1938
2129
|
};
|
|
1939
2130
|
|
|
1940
2131
|
// src/context/api/resend.ts
|
|
1941
|
-
var
|
|
2132
|
+
var import_qstash8 = require("@upstash/qstash");
|
|
1942
2133
|
var ResendAPI = class extends BaseWorkflowApi {
|
|
1943
2134
|
async call(stepName, settings) {
|
|
1944
2135
|
const { token, batch = false, ...parameters } = settings;
|
|
1945
2136
|
return await this.callApi(stepName, {
|
|
1946
2137
|
api: {
|
|
1947
2138
|
name: "email",
|
|
1948
|
-
provider: (0,
|
|
2139
|
+
provider: (0, import_qstash8.resend)({ token, batch })
|
|
1949
2140
|
},
|
|
1950
2141
|
...parameters
|
|
1951
2142
|
});
|
|
@@ -1972,28 +2163,11 @@ var WorkflowApi = class extends BaseWorkflowApi {
|
|
|
1972
2163
|
};
|
|
1973
2164
|
|
|
1974
2165
|
// src/agents/index.ts
|
|
1975
|
-
var import_openai3 = require("@ai-sdk/openai");
|
|
1976
|
-
|
|
1977
|
-
// src/agents/adapters.ts
|
|
1978
2166
|
var import_openai2 = require("@ai-sdk/openai");
|
|
1979
|
-
var import_ai = require("ai");
|
|
1980
|
-
|
|
1981
|
-
// src/agents/constants.ts
|
|
1982
|
-
var AGENT_NAME_HEADER = "upstash-agent-name";
|
|
1983
|
-
var MANAGER_AGENT_PROMPT = `You are an agent orchestrating other AI Agents.
|
|
1984
|
-
|
|
1985
|
-
These other agents have tools available to them.
|
|
1986
|
-
|
|
1987
|
-
Given a prompt, utilize these agents to address requests.
|
|
1988
|
-
|
|
1989
|
-
Don't always call all the agents provided to you at the same time. You can call one and use it's response to call another.
|
|
1990
|
-
|
|
1991
|
-
Avoid calling the same agent twice in one turn. Instead, prefer to call it once but provide everything
|
|
1992
|
-
you need from that agent.
|
|
1993
|
-
`;
|
|
1994
2167
|
|
|
1995
2168
|
// src/agents/adapters.ts
|
|
1996
|
-
var
|
|
2169
|
+
var import_ai = require("ai");
|
|
2170
|
+
var fetchWithContextCall = async (context, agentCallParams, ...params) => {
|
|
1997
2171
|
const [input, init] = params;
|
|
1998
2172
|
try {
|
|
1999
2173
|
const headers = init?.headers ? Object.fromEntries(new Headers(init.headers).entries()) : {};
|
|
@@ -2004,7 +2178,10 @@ var fetchWithContextCall = async (context, ...params) => {
|
|
|
2004
2178
|
url: input.toString(),
|
|
2005
2179
|
method: init?.method,
|
|
2006
2180
|
headers,
|
|
2007
|
-
body
|
|
2181
|
+
body,
|
|
2182
|
+
timeout: agentCallParams?.timeout,
|
|
2183
|
+
retries: agentCallParams?.retries,
|
|
2184
|
+
flowControl: agentCallParams?.flowControl
|
|
2008
2185
|
});
|
|
2009
2186
|
const responseHeaders = new Headers(
|
|
2010
2187
|
Object.entries(responseInfo.header).reduce(
|
|
@@ -2031,10 +2208,11 @@ var fetchWithContextCall = async (context, ...params) => {
|
|
|
2031
2208
|
var createWorkflowModel = ({
|
|
2032
2209
|
context,
|
|
2033
2210
|
provider,
|
|
2034
|
-
providerParams
|
|
2211
|
+
providerParams,
|
|
2212
|
+
agentCallParams
|
|
2035
2213
|
}) => {
|
|
2036
2214
|
return provider({
|
|
2037
|
-
fetch: (...params) => fetchWithContextCall(context, ...params),
|
|
2215
|
+
fetch: (...params) => fetchWithContextCall(context, agentCallParams, ...params),
|
|
2038
2216
|
...providerParams
|
|
2039
2217
|
});
|
|
2040
2218
|
};
|
|
@@ -2274,17 +2452,26 @@ var WorkflowAgents = class {
|
|
|
2274
2452
|
*/
|
|
2275
2453
|
openai(...params) {
|
|
2276
2454
|
const [model, settings] = params;
|
|
2277
|
-
const { baseURL, apiKey, ...otherSettings } = settings ?? {};
|
|
2455
|
+
const { baseURL, apiKey, callSettings, ...otherSettings } = settings ?? {};
|
|
2278
2456
|
const openaiModel = this.AISDKModel({
|
|
2279
2457
|
context: this.context,
|
|
2280
|
-
provider:
|
|
2281
|
-
providerParams: { baseURL, apiKey, compatibility: "strict" }
|
|
2458
|
+
provider: import_openai2.createOpenAI,
|
|
2459
|
+
providerParams: { baseURL, apiKey, compatibility: "strict" },
|
|
2460
|
+
agentCallParams: callSettings
|
|
2282
2461
|
});
|
|
2283
2462
|
return openaiModel(model, otherSettings);
|
|
2284
2463
|
}
|
|
2285
2464
|
AISDKModel = createWorkflowModel;
|
|
2286
2465
|
};
|
|
2287
2466
|
|
|
2467
|
+
// src/serve/serve-many.ts
|
|
2468
|
+
var getNewUrlFromWorkflowId = (url, workflowId) => {
|
|
2469
|
+
if (!workflowId) {
|
|
2470
|
+
throw new WorkflowError("You can only call workflow which has a workflowId");
|
|
2471
|
+
}
|
|
2472
|
+
return url.replace(/[^/]+$/, workflowId);
|
|
2473
|
+
};
|
|
2474
|
+
|
|
2288
2475
|
// src/context/context.ts
|
|
2289
2476
|
var WorkflowContext = class {
|
|
2290
2477
|
executor;
|
|
@@ -2506,60 +2693,42 @@ var WorkflowContext = class {
|
|
|
2506
2693
|
}
|
|
2507
2694
|
await this.addStep(new LazySleepUntilStep(stepName, time));
|
|
2508
2695
|
}
|
|
2509
|
-
/**
|
|
2510
|
-
* Makes a third party call through QStash in order to make a
|
|
2511
|
-
* network call without consuming any runtime.
|
|
2512
|
-
*
|
|
2513
|
-
* ```ts
|
|
2514
|
-
* const { status, body } = await context.call<string>(
|
|
2515
|
-
* "post call step",
|
|
2516
|
-
* {
|
|
2517
|
-
* url: "https://www.some-endpoint.com/api",
|
|
2518
|
-
* method: "POST",
|
|
2519
|
-
* body: "my-payload"
|
|
2520
|
-
* }
|
|
2521
|
-
* );
|
|
2522
|
-
* ```
|
|
2523
|
-
*
|
|
2524
|
-
* tries to parse the result of the request as JSON. If it's
|
|
2525
|
-
* not a JSON which can be parsed, simply returns the response
|
|
2526
|
-
* body as it is.
|
|
2527
|
-
*
|
|
2528
|
-
* @param stepName
|
|
2529
|
-
* @param url url to call
|
|
2530
|
-
* @param method call method. "GET" by default.
|
|
2531
|
-
* @param body call body
|
|
2532
|
-
* @param headers call headers
|
|
2533
|
-
* @param retries number of call retries. 0 by default
|
|
2534
|
-
* @param timeout max duration to wait for the endpoint to respond. in seconds.
|
|
2535
|
-
* @returns call result as {
|
|
2536
|
-
* status: number;
|
|
2537
|
-
* body: unknown;
|
|
2538
|
-
* header: Record<string, string[]>
|
|
2539
|
-
* }
|
|
2540
|
-
*/
|
|
2541
2696
|
async call(stepName, settings) {
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2697
|
+
let callStep;
|
|
2698
|
+
if ("workflow" in settings) {
|
|
2699
|
+
const url = getNewUrlFromWorkflowId(this.url, settings.workflow.workflowId);
|
|
2700
|
+
callStep = new LazyCallStep(
|
|
2701
|
+
stepName,
|
|
2702
|
+
url,
|
|
2703
|
+
"POST",
|
|
2704
|
+
settings.body,
|
|
2705
|
+
settings.headers || {},
|
|
2706
|
+
settings.retries || 0,
|
|
2707
|
+
settings.timeout,
|
|
2708
|
+
settings.flowControl ?? settings.workflow.options.flowControl
|
|
2709
|
+
);
|
|
2710
|
+
} else {
|
|
2711
|
+
const {
|
|
2712
|
+
url,
|
|
2713
|
+
method = "GET",
|
|
2714
|
+
body,
|
|
2715
|
+
headers = {},
|
|
2716
|
+
retries = 0,
|
|
2717
|
+
timeout,
|
|
2718
|
+
flowControl
|
|
2719
|
+
} = settings;
|
|
2720
|
+
callStep = new LazyCallStep(
|
|
2553
2721
|
stepName,
|
|
2554
2722
|
url,
|
|
2555
2723
|
method,
|
|
2556
|
-
|
|
2724
|
+
body,
|
|
2557
2725
|
headers,
|
|
2558
2726
|
retries,
|
|
2559
2727
|
timeout,
|
|
2560
2728
|
flowControl
|
|
2561
|
-
)
|
|
2562
|
-
|
|
2729
|
+
);
|
|
2730
|
+
}
|
|
2731
|
+
return await this.addStep(callStep);
|
|
2563
2732
|
}
|
|
2564
2733
|
/**
|
|
2565
2734
|
* Pauses workflow execution until a specific event occurs or a timeout is reached.
|
|
@@ -2707,7 +2876,7 @@ var WorkflowLogger = class _WorkflowLogger {
|
|
|
2707
2876
|
};
|
|
2708
2877
|
|
|
2709
2878
|
// src/serve/authorization.ts
|
|
2710
|
-
var
|
|
2879
|
+
var import_qstash9 = require("@upstash/qstash");
|
|
2711
2880
|
var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowContext {
|
|
2712
2881
|
static disabledMessage = "disabled-qstash-worklfow-run";
|
|
2713
2882
|
disabled = true;
|
|
@@ -2739,7 +2908,7 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
|
|
|
2739
2908
|
*/
|
|
2740
2909
|
static async tryAuthentication(routeFunction, context) {
|
|
2741
2910
|
const disabledContext = new _DisabledWorkflowContext({
|
|
2742
|
-
qstashClient: new
|
|
2911
|
+
qstashClient: new import_qstash9.Client({
|
|
2743
2912
|
baseUrl: "disabled-client",
|
|
2744
2913
|
token: "disabled-client"
|
|
2745
2914
|
}),
|
|
@@ -2953,15 +3122,15 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
|
|
|
2953
3122
|
};
|
|
2954
3123
|
|
|
2955
3124
|
// src/serve/options.ts
|
|
2956
|
-
var import_qstash9 = require("@upstash/qstash");
|
|
2957
3125
|
var import_qstash10 = require("@upstash/qstash");
|
|
3126
|
+
var import_qstash11 = require("@upstash/qstash");
|
|
2958
3127
|
var processOptions = (options) => {
|
|
2959
3128
|
const environment = options?.env ?? (typeof process === "undefined" ? {} : process.env);
|
|
2960
3129
|
const receiverEnvironmentVariablesSet = Boolean(
|
|
2961
3130
|
environment.QSTASH_CURRENT_SIGNING_KEY && environment.QSTASH_NEXT_SIGNING_KEY
|
|
2962
3131
|
);
|
|
2963
3132
|
return {
|
|
2964
|
-
qstashClient: new
|
|
3133
|
+
qstashClient: new import_qstash11.Client({
|
|
2965
3134
|
baseUrl: environment.QSTASH_URL,
|
|
2966
3135
|
token: environment.QSTASH_TOKEN
|
|
2967
3136
|
}),
|
|
@@ -2996,7 +3165,7 @@ var processOptions = (options) => {
|
|
|
2996
3165
|
throw error;
|
|
2997
3166
|
}
|
|
2998
3167
|
},
|
|
2999
|
-
receiver: receiverEnvironmentVariablesSet ? new
|
|
3168
|
+
receiver: receiverEnvironmentVariablesSet ? new import_qstash10.Receiver({
|
|
3000
3169
|
currentSigningKey: environment.QSTASH_CURRENT_SIGNING_KEY,
|
|
3001
3170
|
nextSigningKey: environment.QSTASH_NEXT_SIGNING_KEY
|
|
3002
3171
|
}) : void 0,
|