@upstash/workflow 0.2.12 → 0.2.14
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 +1254 -1072
- package/astro.mjs +1 -1
- package/{chunk-4GTHIL7S.mjs → chunk-RMS2NQ3K.mjs} +918 -734
- package/cloudflare.d.mts +2 -2
- package/cloudflare.d.ts +2 -2
- package/cloudflare.js +1254 -1072
- package/cloudflare.mjs +1 -1
- package/express.d.mts +2 -2
- package/express.d.ts +2 -2
- package/express.js +1270 -1088
- package/express.mjs +1 -1
- package/h3.d.mts +2 -2
- package/h3.d.ts +2 -2
- package/h3.js +1254 -1072
- package/h3.mjs +1 -1
- package/hono.d.mts +2 -2
- package/hono.d.ts +2 -2
- package/hono.js +1255 -1073
- package/hono.mjs +2 -2
- package/index.d.mts +124 -15
- package/index.d.ts +124 -15
- package/index.js +1259 -1101
- package/index.mjs +32 -56
- package/nextjs.d.mts +2 -2
- package/nextjs.d.ts +2 -2
- package/nextjs.js +1254 -1072
- 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 +1220 -1038
- package/solidjs.mjs +1 -1
- package/svelte.d.mts +2 -2
- package/svelte.d.ts +2 -2
- package/svelte.js +1254 -1072
- 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.14";
|
|
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)));
|
|
@@ -933,54 +597,72 @@ var StepTypes = [
|
|
|
933
597
|
|
|
934
598
|
// src/workflow-requests.ts
|
|
935
599
|
var import_qstash3 = require("@upstash/qstash");
|
|
936
|
-
var triggerFirstInvocation = async ({
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
headers,
|
|
964
|
-
method: "POST",
|
|
965
|
-
body,
|
|
966
|
-
url: workflowContext.url
|
|
967
|
-
});
|
|
968
|
-
if (result.deduplicated) {
|
|
969
|
-
await debug?.log("WARN", "SUBMIT_FIRST_INVOCATION", {
|
|
970
|
-
message: `Workflow run ${workflowContext.workflowRunId} already exists. A new one isn't created.`,
|
|
600
|
+
var triggerFirstInvocation = async (params) => {
|
|
601
|
+
const firstInvocationParams = Array.isArray(params) ? params : [params];
|
|
602
|
+
const workflowContextClient = firstInvocationParams[0].workflowContext.qstashClient;
|
|
603
|
+
const invocationBatch = firstInvocationParams.map(
|
|
604
|
+
({ workflowContext, useJSONContent, telemetry, invokeCount, delay }) => {
|
|
605
|
+
const { headers } = getHeaders({
|
|
606
|
+
initHeaderValue: "true",
|
|
607
|
+
workflowConfig: {
|
|
608
|
+
workflowRunId: workflowContext.workflowRunId,
|
|
609
|
+
workflowUrl: workflowContext.url,
|
|
610
|
+
failureUrl: workflowContext.failureUrl,
|
|
611
|
+
retries: workflowContext.retries,
|
|
612
|
+
telemetry,
|
|
613
|
+
flowControl: workflowContext.flowControl,
|
|
614
|
+
useJSONContent: useJSONContent ?? false
|
|
615
|
+
},
|
|
616
|
+
invokeCount: invokeCount ?? 0,
|
|
617
|
+
userHeaders: workflowContext.headers
|
|
618
|
+
});
|
|
619
|
+
if (workflowContext.headers.get("content-type")) {
|
|
620
|
+
headers["content-type"] = workflowContext.headers.get("content-type");
|
|
621
|
+
}
|
|
622
|
+
if (useJSONContent) {
|
|
623
|
+
headers["content-type"] = "application/json";
|
|
624
|
+
}
|
|
625
|
+
const body = typeof workflowContext.requestPayload === "string" ? workflowContext.requestPayload : JSON.stringify(workflowContext.requestPayload);
|
|
626
|
+
return {
|
|
971
627
|
headers,
|
|
972
|
-
|
|
628
|
+
method: "POST",
|
|
629
|
+
body,
|
|
973
630
|
url: workflowContext.url,
|
|
974
|
-
|
|
975
|
-
}
|
|
631
|
+
delay
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
);
|
|
635
|
+
try {
|
|
636
|
+
const results = await workflowContextClient.batch(invocationBatch);
|
|
637
|
+
const invocationStatuses = [];
|
|
638
|
+
for (let i = 0; i < results.length; i++) {
|
|
639
|
+
const result = results[i];
|
|
640
|
+
const invocationParams = firstInvocationParams[i];
|
|
641
|
+
if (result.deduplicated) {
|
|
642
|
+
await invocationParams.debug?.log("WARN", "SUBMIT_FIRST_INVOCATION", {
|
|
643
|
+
message: `Workflow run ${invocationParams.workflowContext.workflowRunId} already exists. A new one isn't created.`,
|
|
644
|
+
headers: invocationBatch[i].headers,
|
|
645
|
+
requestPayload: invocationParams.workflowContext.requestPayload,
|
|
646
|
+
url: invocationParams.workflowContext.url,
|
|
647
|
+
messageId: result.messageId
|
|
648
|
+
});
|
|
649
|
+
invocationStatuses.push("workflow-run-already-exists");
|
|
650
|
+
} else {
|
|
651
|
+
await invocationParams.debug?.log("SUBMIT", "SUBMIT_FIRST_INVOCATION", {
|
|
652
|
+
headers: invocationBatch[i].headers,
|
|
653
|
+
requestPayload: invocationParams.workflowContext.requestPayload,
|
|
654
|
+
url: invocationParams.workflowContext.url,
|
|
655
|
+
messageId: result.messageId
|
|
656
|
+
});
|
|
657
|
+
invocationStatuses.push("success");
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
const hasAnyDeduplicated = invocationStatuses.some(
|
|
661
|
+
(status) => status === "workflow-run-already-exists"
|
|
662
|
+
);
|
|
663
|
+
if (hasAnyDeduplicated) {
|
|
976
664
|
return ok("workflow-run-already-exists");
|
|
977
665
|
} else {
|
|
978
|
-
await debug?.log("SUBMIT", "SUBMIT_FIRST_INVOCATION", {
|
|
979
|
-
headers,
|
|
980
|
-
requestPayload: workflowContext.requestPayload,
|
|
981
|
-
url: workflowContext.url,
|
|
982
|
-
messageId: result.messageId
|
|
983
|
-
});
|
|
984
666
|
return ok("success");
|
|
985
667
|
}
|
|
986
668
|
} catch (error) {
|
|
@@ -1119,14 +801,16 @@ ${atob(callbackMessage.body ?? "")}`
|
|
|
1119
801
|
const userHeaders = recreateUserHeaders(request.headers);
|
|
1120
802
|
const { headers: requestHeaders } = getHeaders({
|
|
1121
803
|
initHeaderValue: "false",
|
|
1122
|
-
|
|
1123
|
-
|
|
804
|
+
workflowConfig: {
|
|
805
|
+
workflowRunId,
|
|
806
|
+
workflowUrl,
|
|
807
|
+
failureUrl,
|
|
808
|
+
retries,
|
|
809
|
+
telemetry,
|
|
810
|
+
flowControl
|
|
811
|
+
},
|
|
1124
812
|
userHeaders,
|
|
1125
|
-
|
|
1126
|
-
retries,
|
|
1127
|
-
telemetry,
|
|
1128
|
-
invokeCount: Number(invokeCount),
|
|
1129
|
-
flowControl
|
|
813
|
+
invokeCount: Number(invokeCount)
|
|
1130
814
|
});
|
|
1131
815
|
const callResponse = {
|
|
1132
816
|
status: callbackMessage.status,
|
|
@@ -1165,275 +849,906 @@ ${atob(callbackMessage.body ?? "")}`
|
|
|
1165
849
|
);
|
|
1166
850
|
}
|
|
1167
851
|
};
|
|
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
|
-
|
|
852
|
+
var getTelemetryHeaders = (telemetry) => {
|
|
853
|
+
return {
|
|
854
|
+
[TELEMETRY_HEADER_SDK]: telemetry.sdk,
|
|
855
|
+
[TELEMETRY_HEADER_FRAMEWORK]: telemetry.framework,
|
|
856
|
+
[TELEMETRY_HEADER_RUNTIME]: telemetry.runtime ?? "unknown"
|
|
857
|
+
};
|
|
858
|
+
};
|
|
859
|
+
var verifyRequest = async (body, signature, verifier) => {
|
|
860
|
+
if (!verifier) {
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
try {
|
|
864
|
+
if (!signature) {
|
|
865
|
+
throw new Error("`Upstash-Signature` header is not passed.");
|
|
866
|
+
}
|
|
867
|
+
const isValid = await verifier.verify({
|
|
868
|
+
body,
|
|
869
|
+
signature
|
|
870
|
+
});
|
|
871
|
+
if (!isValid) {
|
|
872
|
+
throw new Error("Signature in `Upstash-Signature` header is not valid");
|
|
873
|
+
}
|
|
874
|
+
} catch (error) {
|
|
875
|
+
throw new WorkflowError(
|
|
876
|
+
`Failed to verify that the Workflow request comes from QStash: ${error}
|
|
877
|
+
|
|
878
|
+
If signature is missing, trigger the workflow endpoint by publishing your request to QStash instead of calling it directly.
|
|
879
|
+
|
|
880
|
+
If you want to disable QStash Verification, you should clear env variables QSTASH_CURRENT_SIGNING_KEY and QSTASH_NEXT_SIGNING_KEY`
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
// src/context/steps.ts
|
|
886
|
+
var BaseLazyStep = class _BaseLazyStep {
|
|
887
|
+
stepName;
|
|
888
|
+
constructor(stepName) {
|
|
889
|
+
if (!stepName) {
|
|
890
|
+
throw new WorkflowError(
|
|
891
|
+
"A workflow step name cannot be undefined or an empty string. Please provide a name for your workflow step."
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
if (typeof stepName !== "string") {
|
|
895
|
+
console.warn(
|
|
896
|
+
"Workflow Warning: A workflow step name must be a string. In a future release, this will throw an error."
|
|
897
|
+
);
|
|
898
|
+
}
|
|
899
|
+
this.stepName = stepName;
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* parse the out field of a step result.
|
|
903
|
+
*
|
|
904
|
+
* will be called when returning the steps to the context from auto executor
|
|
905
|
+
*
|
|
906
|
+
* @param out field of the step
|
|
907
|
+
* @returns parsed out field
|
|
908
|
+
*/
|
|
909
|
+
parseOut(out) {
|
|
910
|
+
if (out === void 0) {
|
|
911
|
+
if (this.allowUndefinedOut) {
|
|
912
|
+
return void 0;
|
|
913
|
+
} else {
|
|
914
|
+
throw new WorkflowError(
|
|
915
|
+
`Error while parsing output of ${this.stepType} step. Expected a string, but got: undefined`
|
|
916
|
+
);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
if (typeof out === "object") {
|
|
920
|
+
if (this.stepType !== "Wait") {
|
|
921
|
+
console.warn(
|
|
922
|
+
`Error while parsing ${this.stepType} step output. Expected a string, but got object. Please reach out to Upstash Support.`
|
|
923
|
+
);
|
|
924
|
+
return out;
|
|
925
|
+
}
|
|
926
|
+
return {
|
|
927
|
+
...out,
|
|
928
|
+
eventData: _BaseLazyStep.tryParsing(out.eventData)
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
if (typeof out !== "string") {
|
|
932
|
+
throw new WorkflowError(
|
|
933
|
+
`Error while parsing output of ${this.stepType} step. Expected a string or undefined, but got: ${typeof out}`
|
|
934
|
+
);
|
|
935
|
+
}
|
|
936
|
+
return this.safeParseOut(out);
|
|
937
|
+
}
|
|
938
|
+
safeParseOut(out) {
|
|
939
|
+
return _BaseLazyStep.tryParsing(out);
|
|
940
|
+
}
|
|
941
|
+
static tryParsing(stepOut) {
|
|
942
|
+
try {
|
|
943
|
+
return JSON.parse(stepOut);
|
|
944
|
+
} catch {
|
|
945
|
+
return stepOut;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
getBody({ step }) {
|
|
949
|
+
step.out = JSON.stringify(step.out);
|
|
950
|
+
return JSON.stringify(step);
|
|
951
|
+
}
|
|
952
|
+
getHeaders({ context, telemetry, invokeCount, step }) {
|
|
953
|
+
return getHeaders({
|
|
954
|
+
initHeaderValue: "false",
|
|
955
|
+
workflowConfig: {
|
|
956
|
+
workflowRunId: context.workflowRunId,
|
|
957
|
+
workflowUrl: context.url,
|
|
958
|
+
failureUrl: context.failureUrl,
|
|
959
|
+
retries: context.retries,
|
|
960
|
+
useJSONContent: false,
|
|
961
|
+
telemetry,
|
|
962
|
+
flowControl: context.flowControl
|
|
963
|
+
},
|
|
964
|
+
userHeaders: context.headers,
|
|
965
|
+
invokeCount,
|
|
966
|
+
stepInfo: {
|
|
967
|
+
step,
|
|
968
|
+
lazyStep: this
|
|
969
|
+
}
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
async submitStep({ context, body, headers }) {
|
|
973
|
+
return await context.qstashClient.batch([
|
|
974
|
+
{
|
|
975
|
+
body,
|
|
976
|
+
headers,
|
|
977
|
+
method: "POST",
|
|
978
|
+
url: context.url
|
|
979
|
+
}
|
|
980
|
+
]);
|
|
981
|
+
}
|
|
982
|
+
};
|
|
983
|
+
var LazyFunctionStep = class extends BaseLazyStep {
|
|
984
|
+
stepFunction;
|
|
985
|
+
stepType = "Run";
|
|
986
|
+
allowUndefinedOut = true;
|
|
987
|
+
constructor(stepName, stepFunction) {
|
|
988
|
+
super(stepName);
|
|
989
|
+
this.stepFunction = stepFunction;
|
|
990
|
+
}
|
|
991
|
+
getPlanStep(concurrent, targetStep) {
|
|
992
|
+
return {
|
|
993
|
+
stepId: 0,
|
|
994
|
+
stepName: this.stepName,
|
|
995
|
+
stepType: this.stepType,
|
|
996
|
+
concurrent,
|
|
997
|
+
targetStep
|
|
998
|
+
};
|
|
999
|
+
}
|
|
1000
|
+
async getResultStep(concurrent, stepId) {
|
|
1001
|
+
let result = this.stepFunction();
|
|
1002
|
+
if (result instanceof Promise) {
|
|
1003
|
+
result = await result;
|
|
1004
|
+
}
|
|
1005
|
+
return {
|
|
1006
|
+
stepId,
|
|
1007
|
+
stepName: this.stepName,
|
|
1008
|
+
stepType: this.stepType,
|
|
1009
|
+
out: result,
|
|
1010
|
+
concurrent
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
};
|
|
1014
|
+
var LazySleepStep = class extends BaseLazyStep {
|
|
1015
|
+
sleep;
|
|
1016
|
+
stepType = "SleepFor";
|
|
1017
|
+
allowUndefinedOut = true;
|
|
1018
|
+
constructor(stepName, sleep) {
|
|
1019
|
+
super(stepName);
|
|
1020
|
+
this.sleep = sleep;
|
|
1021
|
+
}
|
|
1022
|
+
getPlanStep(concurrent, targetStep) {
|
|
1023
|
+
return {
|
|
1024
|
+
stepId: 0,
|
|
1025
|
+
stepName: this.stepName,
|
|
1026
|
+
stepType: this.stepType,
|
|
1027
|
+
sleepFor: this.sleep,
|
|
1028
|
+
concurrent,
|
|
1029
|
+
targetStep
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
async getResultStep(concurrent, stepId) {
|
|
1033
|
+
return await Promise.resolve({
|
|
1034
|
+
stepId,
|
|
1035
|
+
stepName: this.stepName,
|
|
1036
|
+
stepType: this.stepType,
|
|
1037
|
+
sleepFor: this.sleep,
|
|
1038
|
+
concurrent
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
async submitStep({ context, body, headers, isParallel }) {
|
|
1042
|
+
return await context.qstashClient.batch([
|
|
1043
|
+
{
|
|
1044
|
+
body,
|
|
1045
|
+
headers,
|
|
1046
|
+
method: "POST",
|
|
1047
|
+
url: context.url,
|
|
1048
|
+
delay: isParallel ? void 0 : this.sleep
|
|
1049
|
+
}
|
|
1050
|
+
]);
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
1054
|
+
sleepUntil;
|
|
1055
|
+
stepType = "SleepUntil";
|
|
1056
|
+
allowUndefinedOut = true;
|
|
1057
|
+
constructor(stepName, sleepUntil) {
|
|
1058
|
+
super(stepName);
|
|
1059
|
+
this.sleepUntil = sleepUntil;
|
|
1060
|
+
}
|
|
1061
|
+
getPlanStep(concurrent, targetStep) {
|
|
1062
|
+
return {
|
|
1063
|
+
stepId: 0,
|
|
1064
|
+
stepName: this.stepName,
|
|
1065
|
+
stepType: this.stepType,
|
|
1066
|
+
sleepUntil: this.sleepUntil,
|
|
1067
|
+
concurrent,
|
|
1068
|
+
targetStep
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
async getResultStep(concurrent, stepId) {
|
|
1072
|
+
return await Promise.resolve({
|
|
1073
|
+
stepId,
|
|
1074
|
+
stepName: this.stepName,
|
|
1075
|
+
stepType: this.stepType,
|
|
1076
|
+
sleepUntil: this.sleepUntil,
|
|
1077
|
+
concurrent
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
safeParseOut() {
|
|
1081
|
+
return void 0;
|
|
1082
|
+
}
|
|
1083
|
+
async submitStep({ context, body, headers, isParallel }) {
|
|
1084
|
+
return await context.qstashClient.batch([
|
|
1085
|
+
{
|
|
1086
|
+
body,
|
|
1087
|
+
headers,
|
|
1088
|
+
method: "POST",
|
|
1089
|
+
url: context.url,
|
|
1090
|
+
notBefore: isParallel ? void 0 : this.sleepUntil
|
|
1091
|
+
}
|
|
1092
|
+
]);
|
|
1093
|
+
}
|
|
1094
|
+
};
|
|
1095
|
+
var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
1096
|
+
url;
|
|
1097
|
+
method;
|
|
1098
|
+
body;
|
|
1099
|
+
headers;
|
|
1100
|
+
retries;
|
|
1101
|
+
timeout;
|
|
1102
|
+
flowControl;
|
|
1103
|
+
stepType = "Call";
|
|
1104
|
+
allowUndefinedOut = false;
|
|
1105
|
+
constructor(stepName, url, method, body, headers, retries, timeout, flowControl) {
|
|
1106
|
+
super(stepName);
|
|
1107
|
+
this.url = url;
|
|
1108
|
+
this.method = method;
|
|
1109
|
+
this.body = body;
|
|
1110
|
+
this.headers = headers;
|
|
1111
|
+
this.retries = retries;
|
|
1112
|
+
this.timeout = timeout;
|
|
1113
|
+
this.flowControl = flowControl;
|
|
1114
|
+
}
|
|
1115
|
+
getPlanStep(concurrent, targetStep) {
|
|
1116
|
+
return {
|
|
1117
|
+
stepId: 0,
|
|
1118
|
+
stepName: this.stepName,
|
|
1119
|
+
stepType: this.stepType,
|
|
1120
|
+
concurrent,
|
|
1121
|
+
targetStep
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1124
|
+
async getResultStep(concurrent, stepId) {
|
|
1125
|
+
return await Promise.resolve({
|
|
1126
|
+
stepId,
|
|
1127
|
+
stepName: this.stepName,
|
|
1128
|
+
stepType: this.stepType,
|
|
1129
|
+
concurrent,
|
|
1130
|
+
callUrl: this.url,
|
|
1131
|
+
callMethod: this.method,
|
|
1132
|
+
callBody: this.body,
|
|
1133
|
+
callHeaders: this.headers
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
safeParseOut(out) {
|
|
1137
|
+
const { header, status, body } = JSON.parse(out);
|
|
1138
|
+
const responseHeaders = new Headers(header);
|
|
1139
|
+
if (_LazyCallStep.isText(responseHeaders.get("content-type"))) {
|
|
1140
|
+
const bytes = new Uint8Array(out.length);
|
|
1141
|
+
for (let i = 0; i < out.length; i++) {
|
|
1142
|
+
bytes[i] = out.charCodeAt(i);
|
|
1143
|
+
}
|
|
1144
|
+
const processedResult = new TextDecoder().decode(bytes);
|
|
1145
|
+
const newBody = JSON.parse(processedResult).body;
|
|
1146
|
+
return {
|
|
1147
|
+
status,
|
|
1148
|
+
header,
|
|
1149
|
+
body: BaseLazyStep.tryParsing(newBody)
|
|
1150
|
+
};
|
|
1151
|
+
} else {
|
|
1152
|
+
return { header, status, body };
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
static applicationContentTypes = [
|
|
1156
|
+
"application/json",
|
|
1157
|
+
"application/xml",
|
|
1158
|
+
"application/javascript",
|
|
1159
|
+
"application/x-www-form-urlencoded",
|
|
1160
|
+
"application/xhtml+xml",
|
|
1161
|
+
"application/ld+json",
|
|
1162
|
+
"application/rss+xml",
|
|
1163
|
+
"application/atom+xml"
|
|
1164
|
+
];
|
|
1165
|
+
static isText = (contentTypeHeader) => {
|
|
1166
|
+
if (!contentTypeHeader) {
|
|
1167
|
+
return false;
|
|
1168
|
+
}
|
|
1169
|
+
if (_LazyCallStep.applicationContentTypes.some((type) => contentTypeHeader.includes(type))) {
|
|
1170
|
+
return true;
|
|
1171
|
+
}
|
|
1172
|
+
if (contentTypeHeader.startsWith("text/")) {
|
|
1173
|
+
return true;
|
|
1174
|
+
}
|
|
1175
|
+
return false;
|
|
1176
|
+
};
|
|
1177
|
+
getBody({ step }) {
|
|
1178
|
+
if (!step.callUrl) {
|
|
1179
|
+
throw new WorkflowError("Incompatible step received in LazyCallStep.getBody");
|
|
1180
|
+
}
|
|
1181
|
+
return JSON.stringify(step.callBody);
|
|
1182
|
+
}
|
|
1183
|
+
getHeaders({ context, telemetry, invokeCount, step }) {
|
|
1184
|
+
const { headers, contentType } = super.getHeaders({ context, telemetry, invokeCount, step });
|
|
1185
|
+
headers["Upstash-Retries"] = this.retries.toString();
|
|
1186
|
+
headers[WORKFLOW_FEATURE_HEADER] = "WF_NoDelete,InitialBody";
|
|
1187
|
+
if (this.flowControl) {
|
|
1188
|
+
const { flowControlKey, flowControlValue } = prepareFlowControl(this.flowControl);
|
|
1189
|
+
headers["Upstash-Flow-Control-Key"] = flowControlKey;
|
|
1190
|
+
headers["Upstash-Flow-Control-Value"] = flowControlValue;
|
|
1191
|
+
}
|
|
1192
|
+
if (this.timeout) {
|
|
1193
|
+
headers["Upstash-Timeout"] = this.timeout.toString();
|
|
1194
|
+
}
|
|
1195
|
+
const forwardedHeaders = Object.fromEntries(
|
|
1196
|
+
Object.entries(this.headers).map(([header, value]) => [`Upstash-Forward-${header}`, value])
|
|
1197
|
+
);
|
|
1198
|
+
return {
|
|
1199
|
+
headers: {
|
|
1200
|
+
...headers,
|
|
1201
|
+
...forwardedHeaders,
|
|
1202
|
+
"Upstash-Callback": context.url,
|
|
1203
|
+
"Upstash-Callback-Workflow-RunId": context.workflowRunId,
|
|
1204
|
+
"Upstash-Callback-Workflow-CallType": "fromCallback",
|
|
1205
|
+
"Upstash-Callback-Workflow-Init": "false",
|
|
1206
|
+
"Upstash-Callback-Workflow-Url": context.url,
|
|
1207
|
+
"Upstash-Callback-Feature-Set": "LazyFetch,InitialBody",
|
|
1208
|
+
"Upstash-Callback-Forward-Upstash-Workflow-Callback": "true",
|
|
1209
|
+
"Upstash-Callback-Forward-Upstash-Workflow-StepId": step.stepId.toString(),
|
|
1210
|
+
"Upstash-Callback-Forward-Upstash-Workflow-StepName": this.stepName,
|
|
1211
|
+
"Upstash-Callback-Forward-Upstash-Workflow-StepType": this.stepType,
|
|
1212
|
+
"Upstash-Callback-Forward-Upstash-Workflow-Concurrent": step.concurrent.toString(),
|
|
1213
|
+
"Upstash-Callback-Forward-Upstash-Workflow-ContentType": contentType,
|
|
1214
|
+
"Upstash-Workflow-CallType": "toCallback"
|
|
1215
|
+
},
|
|
1216
|
+
contentType
|
|
1217
|
+
};
|
|
1218
|
+
}
|
|
1219
|
+
async submitStep({ context, headers }) {
|
|
1220
|
+
return await context.qstashClient.batch([
|
|
1221
|
+
{
|
|
1222
|
+
headers,
|
|
1223
|
+
body: JSON.stringify(this.body),
|
|
1224
|
+
method: this.method,
|
|
1225
|
+
url: this.url
|
|
1226
|
+
}
|
|
1227
|
+
]);
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
1231
|
+
eventId;
|
|
1232
|
+
timeout;
|
|
1233
|
+
stepType = "Wait";
|
|
1234
|
+
allowUndefinedOut = false;
|
|
1235
|
+
constructor(stepName, eventId, timeout) {
|
|
1236
|
+
super(stepName);
|
|
1237
|
+
this.eventId = eventId;
|
|
1238
|
+
this.timeout = timeout;
|
|
1239
|
+
}
|
|
1240
|
+
getPlanStep(concurrent, targetStep) {
|
|
1241
|
+
return {
|
|
1242
|
+
stepId: 0,
|
|
1243
|
+
stepName: this.stepName,
|
|
1244
|
+
stepType: this.stepType,
|
|
1245
|
+
waitEventId: this.eventId,
|
|
1246
|
+
timeout: this.timeout,
|
|
1247
|
+
concurrent,
|
|
1248
|
+
targetStep
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
async getResultStep(concurrent, stepId) {
|
|
1252
|
+
return await Promise.resolve({
|
|
1253
|
+
stepId,
|
|
1254
|
+
stepName: this.stepName,
|
|
1255
|
+
stepType: this.stepType,
|
|
1256
|
+
waitEventId: this.eventId,
|
|
1257
|
+
timeout: this.timeout,
|
|
1258
|
+
concurrent
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
safeParseOut(out) {
|
|
1262
|
+
const result = JSON.parse(out);
|
|
1263
|
+
return {
|
|
1264
|
+
...result,
|
|
1265
|
+
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1268
|
+
getHeaders({ context, telemetry, invokeCount, step }) {
|
|
1269
|
+
const headers = super.getHeaders({ context, telemetry, invokeCount, step });
|
|
1270
|
+
headers.headers["Upstash-Workflow-CallType"] = "step";
|
|
1271
|
+
return headers;
|
|
1272
|
+
}
|
|
1273
|
+
getBody({ context, step, headers, telemetry }) {
|
|
1274
|
+
if (!step.waitEventId) {
|
|
1275
|
+
throw new WorkflowError("Incompatible step received in LazyWaitForEventStep.getBody");
|
|
1276
|
+
}
|
|
1277
|
+
const timeoutHeaders = {
|
|
1278
|
+
// to include user headers:
|
|
1279
|
+
...Object.fromEntries(Object.entries(headers).map(([header, value]) => [header, [value]])),
|
|
1280
|
+
// to include telemetry headers:
|
|
1281
|
+
...telemetry ? Object.fromEntries(
|
|
1282
|
+
Object.entries(getTelemetryHeaders(telemetry)).map(([header, value]) => [
|
|
1283
|
+
header,
|
|
1284
|
+
[value]
|
|
1285
|
+
])
|
|
1286
|
+
) : {},
|
|
1287
|
+
// note: using WORKFLOW_ID_HEADER doesn't work, because Runid -> RunId:
|
|
1288
|
+
"Upstash-Workflow-Runid": [context.workflowRunId],
|
|
1289
|
+
[WORKFLOW_INIT_HEADER]: ["false"],
|
|
1290
|
+
[WORKFLOW_URL_HEADER]: [context.url],
|
|
1291
|
+
"Upstash-Workflow-CallType": ["step"]
|
|
1292
|
+
};
|
|
1293
|
+
const waitBody = {
|
|
1294
|
+
url: context.url,
|
|
1295
|
+
timeout: step.timeout,
|
|
1296
|
+
timeoutBody: void 0,
|
|
1297
|
+
timeoutUrl: context.url,
|
|
1298
|
+
timeoutHeaders,
|
|
1299
|
+
step: {
|
|
1300
|
+
stepId: step.stepId,
|
|
1301
|
+
stepType: "Wait",
|
|
1302
|
+
stepName: step.stepName,
|
|
1303
|
+
concurrent: step.concurrent,
|
|
1304
|
+
targetStep: step.targetStep
|
|
1305
|
+
}
|
|
1306
|
+
};
|
|
1307
|
+
return JSON.stringify(waitBody);
|
|
1308
|
+
}
|
|
1309
|
+
async submitStep({ context, body, headers }) {
|
|
1310
|
+
const result = await context.qstashClient.http.request({
|
|
1311
|
+
path: ["v2", "wait", this.eventId],
|
|
1312
|
+
body,
|
|
1313
|
+
headers,
|
|
1314
|
+
method: "POST",
|
|
1315
|
+
parseResponseAsJson: false
|
|
1316
|
+
});
|
|
1317
|
+
return [result];
|
|
1318
|
+
}
|
|
1319
|
+
};
|
|
1320
|
+
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1321
|
+
stepType = "Notify";
|
|
1322
|
+
constructor(stepName, eventId, eventData, requester) {
|
|
1323
|
+
super(stepName, async () => {
|
|
1324
|
+
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
1325
|
+
return {
|
|
1326
|
+
eventId,
|
|
1327
|
+
eventData,
|
|
1328
|
+
notifyResponse
|
|
1329
|
+
};
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
safeParseOut(out) {
|
|
1333
|
+
const result = JSON.parse(out);
|
|
1334
|
+
return {
|
|
1335
|
+
...result,
|
|
1336
|
+
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1339
|
+
};
|
|
1340
|
+
var LazyInvokeStep = class extends BaseLazyStep {
|
|
1341
|
+
stepType = "Invoke";
|
|
1342
|
+
params;
|
|
1343
|
+
allowUndefinedOut = false;
|
|
1344
|
+
/**
|
|
1345
|
+
* workflow id of the invoked workflow
|
|
1346
|
+
*/
|
|
1347
|
+
workflowId;
|
|
1348
|
+
constructor(stepName, {
|
|
1349
|
+
workflow,
|
|
1350
|
+
body,
|
|
1351
|
+
headers = {},
|
|
1352
|
+
workflowRunId,
|
|
1353
|
+
retries,
|
|
1354
|
+
flowControl
|
|
1355
|
+
}) {
|
|
1356
|
+
super(stepName);
|
|
1357
|
+
this.params = {
|
|
1358
|
+
workflow,
|
|
1359
|
+
body,
|
|
1360
|
+
headers,
|
|
1361
|
+
workflowRunId: getWorkflowRunId(workflowRunId),
|
|
1362
|
+
retries,
|
|
1363
|
+
flowControl
|
|
1364
|
+
};
|
|
1365
|
+
const { workflowId } = workflow;
|
|
1366
|
+
if (!workflowId) {
|
|
1367
|
+
throw new WorkflowError("You can only invoke workflow which has a workflowId");
|
|
1368
|
+
}
|
|
1369
|
+
this.workflowId = workflowId;
|
|
1370
|
+
}
|
|
1371
|
+
getPlanStep(concurrent, targetStep) {
|
|
1372
|
+
return {
|
|
1373
|
+
stepId: 0,
|
|
1374
|
+
stepName: this.stepName,
|
|
1375
|
+
stepType: this.stepType,
|
|
1376
|
+
concurrent,
|
|
1377
|
+
targetStep
|
|
1378
|
+
};
|
|
1379
|
+
}
|
|
1380
|
+
/**
|
|
1381
|
+
* won't be used as it's the server who will add the result step
|
|
1382
|
+
* in Invoke step.
|
|
1383
|
+
*/
|
|
1384
|
+
getResultStep(concurrent, stepId) {
|
|
1385
|
+
return Promise.resolve({
|
|
1386
|
+
stepId,
|
|
1387
|
+
stepName: this.stepName,
|
|
1388
|
+
stepType: this.stepType,
|
|
1389
|
+
concurrent
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
safeParseOut(out) {
|
|
1393
|
+
const result = JSON.parse(out);
|
|
1394
|
+
return {
|
|
1395
|
+
...result,
|
|
1396
|
+
body: BaseLazyStep.tryParsing(result.body)
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
getBody({ context, step, telemetry, invokeCount }) {
|
|
1400
|
+
const { headers: invokerHeaders } = getHeaders({
|
|
1401
|
+
initHeaderValue: "false",
|
|
1402
|
+
workflowConfig: {
|
|
1403
|
+
workflowRunId: context.workflowRunId,
|
|
1404
|
+
workflowUrl: context.url,
|
|
1405
|
+
failureUrl: context.failureUrl,
|
|
1406
|
+
retries: context.retries,
|
|
1407
|
+
telemetry,
|
|
1408
|
+
flowControl: context.flowControl,
|
|
1409
|
+
useJSONContent: false
|
|
1410
|
+
},
|
|
1411
|
+
userHeaders: context.headers,
|
|
1412
|
+
invokeCount
|
|
1413
|
+
});
|
|
1414
|
+
invokerHeaders["Upstash-Workflow-Runid"] = context.workflowRunId;
|
|
1415
|
+
const request = {
|
|
1416
|
+
body: JSON.stringify(this.params.body),
|
|
1417
|
+
headers: Object.fromEntries(
|
|
1418
|
+
Object.entries(invokerHeaders).map((pairs) => [pairs[0], [pairs[1]]])
|
|
1419
|
+
),
|
|
1420
|
+
workflowRunId: context.workflowRunId,
|
|
1421
|
+
workflowUrl: context.url,
|
|
1422
|
+
step
|
|
1423
|
+
};
|
|
1424
|
+
return JSON.stringify(request);
|
|
1425
|
+
}
|
|
1426
|
+
getHeaders({ context, telemetry, invokeCount }) {
|
|
1427
|
+
const {
|
|
1428
|
+
workflow,
|
|
1429
|
+
headers = {},
|
|
1430
|
+
workflowRunId = getWorkflowRunId(),
|
|
1431
|
+
retries,
|
|
1432
|
+
flowControl
|
|
1433
|
+
} = this.params;
|
|
1434
|
+
const newUrl = context.url.replace(/[^/]+$/, this.workflowId);
|
|
1435
|
+
const {
|
|
1436
|
+
retries: workflowRetries,
|
|
1437
|
+
failureFunction,
|
|
1438
|
+
failureUrl,
|
|
1439
|
+
useJSONContent,
|
|
1440
|
+
flowControl: workflowFlowControl
|
|
1441
|
+
} = workflow.options;
|
|
1442
|
+
const { headers: triggerHeaders, contentType } = getHeaders({
|
|
1443
|
+
initHeaderValue: "true",
|
|
1444
|
+
workflowConfig: {
|
|
1445
|
+
workflowRunId,
|
|
1446
|
+
workflowUrl: newUrl,
|
|
1447
|
+
retries: retries ?? workflowRetries,
|
|
1448
|
+
telemetry,
|
|
1449
|
+
failureUrl: failureFunction ? newUrl : failureUrl,
|
|
1450
|
+
flowControl: flowControl ?? workflowFlowControl,
|
|
1451
|
+
useJSONContent: useJSONContent ?? false
|
|
1452
|
+
},
|
|
1453
|
+
invokeCount: invokeCount + 1,
|
|
1454
|
+
userHeaders: new Headers(headers)
|
|
1455
|
+
});
|
|
1456
|
+
triggerHeaders["Upstash-Workflow-Invoke"] = "true";
|
|
1457
|
+
return { headers: triggerHeaders, contentType };
|
|
1458
|
+
}
|
|
1459
|
+
async submitStep({ context, body, headers }) {
|
|
1460
|
+
const newUrl = context.url.replace(/[^/]+$/, this.workflowId);
|
|
1461
|
+
const result = await context.qstashClient.publish({
|
|
1462
|
+
headers,
|
|
1463
|
+
method: "POST",
|
|
1464
|
+
body,
|
|
1465
|
+
url: newUrl
|
|
1466
|
+
});
|
|
1467
|
+
return [result];
|
|
1468
|
+
}
|
|
1469
|
+
};
|
|
1470
|
+
|
|
1471
|
+
// src/agents/constants.ts
|
|
1472
|
+
var AGENT_NAME_HEADER = "upstash-agent-name";
|
|
1473
|
+
var MANAGER_AGENT_PROMPT = `You are an agent orchestrating other AI Agents.
|
|
1474
|
+
|
|
1475
|
+
These other agents have tools available to them.
|
|
1476
|
+
|
|
1477
|
+
Given a prompt, utilize these agents to address requests.
|
|
1478
|
+
|
|
1479
|
+
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.
|
|
1480
|
+
|
|
1481
|
+
Avoid calling the same agent twice in one turn. Instead, prefer to call it once but provide everything
|
|
1482
|
+
you need from that agent.
|
|
1483
|
+
`;
|
|
1484
|
+
|
|
1485
|
+
// src/qstash/headers.ts
|
|
1486
|
+
var WorkflowHeaders = class {
|
|
1487
|
+
userHeaders;
|
|
1488
|
+
workflowConfig;
|
|
1489
|
+
invokeCount;
|
|
1490
|
+
initHeaderValue;
|
|
1491
|
+
stepInfo;
|
|
1492
|
+
headers;
|
|
1493
|
+
constructor({
|
|
1494
|
+
userHeaders,
|
|
1495
|
+
workflowConfig,
|
|
1496
|
+
invokeCount,
|
|
1497
|
+
initHeaderValue,
|
|
1498
|
+
stepInfo
|
|
1499
|
+
}) {
|
|
1500
|
+
this.userHeaders = userHeaders;
|
|
1501
|
+
this.workflowConfig = workflowConfig;
|
|
1502
|
+
this.invokeCount = invokeCount;
|
|
1503
|
+
this.initHeaderValue = initHeaderValue;
|
|
1504
|
+
this.stepInfo = stepInfo;
|
|
1505
|
+
this.headers = {
|
|
1506
|
+
rawHeaders: {},
|
|
1507
|
+
workflowHeaders: {},
|
|
1508
|
+
failureHeaders: {}
|
|
1509
|
+
};
|
|
1510
|
+
}
|
|
1511
|
+
getHeaders() {
|
|
1512
|
+
this.addBaseHeaders();
|
|
1513
|
+
this.addRetries();
|
|
1514
|
+
this.addFlowControl();
|
|
1515
|
+
this.addUserHeaders();
|
|
1516
|
+
this.addInvokeCount();
|
|
1517
|
+
this.addFailureUrl();
|
|
1518
|
+
const contentType = this.addContentType();
|
|
1519
|
+
return this.prefixHeaders(contentType);
|
|
1520
|
+
}
|
|
1521
|
+
addBaseHeaders() {
|
|
1522
|
+
this.headers.rawHeaders = {
|
|
1523
|
+
...this.headers.rawHeaders,
|
|
1524
|
+
[WORKFLOW_INIT_HEADER]: this.initHeaderValue,
|
|
1525
|
+
[WORKFLOW_ID_HEADER]: this.workflowConfig.workflowRunId,
|
|
1526
|
+
[WORKFLOW_URL_HEADER]: this.workflowConfig.workflowUrl,
|
|
1527
|
+
[WORKFLOW_FEATURE_HEADER]: "LazyFetch,InitialBody",
|
|
1528
|
+
[WORKFLOW_PROTOCOL_VERSION_HEADER]: WORKFLOW_PROTOCOL_VERSION,
|
|
1529
|
+
...this.workflowConfig.telemetry ? getTelemetryHeaders(this.workflowConfig.telemetry) : {},
|
|
1530
|
+
...this.workflowConfig.telemetry && this.stepInfo?.lazyStep instanceof LazyCallStep && this.stepInfo.lazyStep.headers[AGENT_NAME_HEADER] ? { [TELEMETRY_HEADER_AGENT]: "true" } : {}
|
|
1531
|
+
};
|
|
1532
|
+
if (this.stepInfo?.lazyStep.stepType !== "Call") {
|
|
1533
|
+
this.headers.rawHeaders[`Upstash-Forward-${WORKFLOW_PROTOCOL_VERSION_HEADER}`] = WORKFLOW_PROTOCOL_VERSION;
|
|
1245
1534
|
}
|
|
1246
|
-
}
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1535
|
+
}
|
|
1536
|
+
addInvokeCount() {
|
|
1537
|
+
if (this.invokeCount === void 0 || this.invokeCount === 0) {
|
|
1538
|
+
return;
|
|
1539
|
+
}
|
|
1540
|
+
const invokeCount = this.invokeCount.toString();
|
|
1541
|
+
this.headers.workflowHeaders[`Forward-${WORKFLOW_INVOKE_COUNT_HEADER}`] = invokeCount;
|
|
1542
|
+
if (this.workflowConfig.failureUrl) {
|
|
1543
|
+
this.headers.failureHeaders[`Forward-${WORKFLOW_INVOKE_COUNT_HEADER}`] = invokeCount;
|
|
1251
1544
|
}
|
|
1252
|
-
if (
|
|
1253
|
-
|
|
1254
|
-
baseHeaders["Upstash-Failure-Callback-Retries"] = retries.toString();
|
|
1545
|
+
if (this.stepInfo?.lazyStep instanceof LazyCallStep) {
|
|
1546
|
+
this.headers.rawHeaders[`Upstash-Forward-${WORKFLOW_INVOKE_COUNT_HEADER}`] = invokeCount;
|
|
1255
1547
|
}
|
|
1256
1548
|
}
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1549
|
+
addRetries() {
|
|
1550
|
+
if (this.workflowConfig.retries === void 0 || this.workflowConfig.retries === DEFAULT_RETRIES) {
|
|
1551
|
+
return;
|
|
1552
|
+
}
|
|
1553
|
+
const retries = this.workflowConfig.retries.toString();
|
|
1554
|
+
this.headers.workflowHeaders["Retries"] = retries;
|
|
1555
|
+
if (this.workflowConfig.failureUrl) {
|
|
1556
|
+
this.headers.failureHeaders["Retries"] = retries;
|
|
1265
1557
|
}
|
|
1266
1558
|
}
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1559
|
+
addFlowControl() {
|
|
1560
|
+
if (!this.workflowConfig.flowControl) {
|
|
1561
|
+
return;
|
|
1562
|
+
}
|
|
1563
|
+
const { flowControlKey, flowControlValue } = prepareFlowControl(
|
|
1564
|
+
this.workflowConfig.flowControl
|
|
1273
1565
|
);
|
|
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"
|
|
1566
|
+
this.headers.workflowHeaders["Flow-Control-Key"] = flowControlKey;
|
|
1567
|
+
this.headers.workflowHeaders["Flow-Control-Value"] = flowControlValue;
|
|
1568
|
+
if (this.workflowConfig.failureUrl) {
|
|
1569
|
+
this.headers.failureHeaders["Flow-Control-Key"] = flowControlKey;
|
|
1570
|
+
this.headers.failureHeaders["Flow-Control-Value"] = flowControlValue;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
addUserHeaders() {
|
|
1574
|
+
for (const [key, value] of this.userHeaders.entries()) {
|
|
1575
|
+
const forwardKey = `Forward-${key}`;
|
|
1576
|
+
this.headers.workflowHeaders[forwardKey] = value;
|
|
1577
|
+
if (this.workflowConfig.failureUrl) {
|
|
1578
|
+
this.headers.failureHeaders[forwardKey] = value;
|
|
1292
1579
|
}
|
|
1293
|
-
}
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
addFailureUrl() {
|
|
1583
|
+
if (!this.workflowConfig.failureUrl) {
|
|
1584
|
+
return;
|
|
1585
|
+
}
|
|
1586
|
+
this.headers.workflowHeaders["Failure-Callback"] = this.workflowConfig.failureUrl;
|
|
1587
|
+
this.headers.failureHeaders[`Forward-${WORKFLOW_FAILURE_HEADER}`] = "true";
|
|
1588
|
+
this.headers.failureHeaders[`Forward-Upstash-Workflow-Failure-Callback`] = "true";
|
|
1589
|
+
this.headers.failureHeaders["Workflow-Runid"] = this.workflowConfig.workflowRunId;
|
|
1590
|
+
this.headers.failureHeaders["Workflow-Init"] = "false";
|
|
1591
|
+
this.headers.failureHeaders["Workflow-Url"] = this.workflowConfig.workflowUrl;
|
|
1592
|
+
this.headers.failureHeaders["Workflow-Calltype"] = "failureCall";
|
|
1593
|
+
this.headers.failureHeaders["Feature-Set"] = "LazyFetch,InitialBody";
|
|
1594
|
+
if (this.workflowConfig.retries !== void 0 && this.workflowConfig.retries !== DEFAULT_RETRIES) {
|
|
1595
|
+
this.headers.failureHeaders["Retries"] = this.workflowConfig.retries.toString();
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
addContentType() {
|
|
1599
|
+
if (this.workflowConfig.useJSONContent) {
|
|
1600
|
+
this.headers.rawHeaders["content-type"] = "application/json";
|
|
1601
|
+
return "application/json";
|
|
1602
|
+
}
|
|
1603
|
+
const callHeaders = new Headers(
|
|
1604
|
+
this.stepInfo?.lazyStep instanceof LazyCallStep ? this.stepInfo.lazyStep.headers : {}
|
|
1605
|
+
);
|
|
1606
|
+
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;
|
|
1607
|
+
this.headers.rawHeaders["content-type"] = contentType;
|
|
1608
|
+
return contentType;
|
|
1294
1609
|
}
|
|
1295
|
-
|
|
1610
|
+
prefixHeaders(contentType) {
|
|
1611
|
+
const { rawHeaders, workflowHeaders, failureHeaders } = this.headers;
|
|
1612
|
+
const isCall = this.stepInfo?.lazyStep.stepType === "Call";
|
|
1296
1613
|
return {
|
|
1297
1614
|
headers: {
|
|
1298
|
-
...
|
|
1299
|
-
"Upstash-
|
|
1615
|
+
...rawHeaders,
|
|
1616
|
+
...addPrefixToHeaders(workflowHeaders, isCall ? "Upstash-Callback-" : "Upstash-"),
|
|
1617
|
+
...addPrefixToHeaders(failureHeaders, "Upstash-Failure-Callback-"),
|
|
1618
|
+
...isCall ? addPrefixToHeaders(failureHeaders, "Upstash-Callback-Failure-Callback-") : {}
|
|
1300
1619
|
},
|
|
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
|
-
}
|
|
1620
|
+
contentType
|
|
1319
1621
|
};
|
|
1320
1622
|
}
|
|
1321
|
-
return { headers: baseHeaders };
|
|
1322
1623
|
};
|
|
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
|
-
);
|
|
1624
|
+
function addPrefixToHeaders(headers, prefix) {
|
|
1625
|
+
const prefixedHeaders = {};
|
|
1626
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
1627
|
+
prefixedHeaders[`${prefix}${key}`] = value;
|
|
1346
1628
|
}
|
|
1347
|
-
|
|
1629
|
+
return prefixedHeaders;
|
|
1630
|
+
}
|
|
1348
1631
|
var prepareFlowControl = (flowControl) => {
|
|
1349
1632
|
const parallelism = flowControl.parallelism?.toString();
|
|
1350
|
-
const rate = flowControl.ratePerSecond?.toString();
|
|
1633
|
+
const rate = (flowControl.rate ?? flowControl.ratePerSecond)?.toString();
|
|
1634
|
+
const period = typeof flowControl.period === "number" ? `${flowControl.period}s` : flowControl.period;
|
|
1351
1635
|
const controlValue = [
|
|
1352
1636
|
parallelism ? `parallelism=${parallelism}` : void 0,
|
|
1353
|
-
rate ? `rate=${rate}` : void 0
|
|
1637
|
+
rate ? `rate=${rate}` : void 0,
|
|
1638
|
+
period ? `period=${period}` : void 0
|
|
1354
1639
|
].filter(Boolean);
|
|
1355
1640
|
if (controlValue.length === 0) {
|
|
1356
|
-
throw new
|
|
1641
|
+
throw new import_qstash4.QstashError("Provide at least one of parallelism or ratePerSecond for flowControl");
|
|
1357
1642
|
}
|
|
1358
1643
|
return {
|
|
1359
1644
|
flowControlKey: flowControl.key,
|
|
1360
1645
|
flowControlValue: controlValue.join(", ")
|
|
1361
1646
|
};
|
|
1362
1647
|
};
|
|
1648
|
+
var getHeaders = (params) => {
|
|
1649
|
+
const workflowHeaders = new WorkflowHeaders(params);
|
|
1650
|
+
return workflowHeaders.getHeaders();
|
|
1651
|
+
};
|
|
1363
1652
|
|
|
1364
|
-
// src/
|
|
1365
|
-
var
|
|
1366
|
-
|
|
1367
|
-
// src/serve/serve-many.ts
|
|
1368
|
-
var invokeWorkflow = async ({
|
|
1369
|
-
settings,
|
|
1370
|
-
invokeStep,
|
|
1653
|
+
// src/qstash/submit-steps.ts
|
|
1654
|
+
var submitParallelSteps = async ({
|
|
1371
1655
|
context,
|
|
1656
|
+
steps,
|
|
1657
|
+
initialStepCount,
|
|
1372
1658
|
invokeCount,
|
|
1373
|
-
telemetry
|
|
1659
|
+
telemetry,
|
|
1660
|
+
debug
|
|
1374
1661
|
}) => {
|
|
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
|
-
|
|
1662
|
+
const planSteps = steps.map(
|
|
1663
|
+
(step, index) => step.getPlanStep(steps.length, initialStepCount + index)
|
|
1664
|
+
);
|
|
1665
|
+
await debug?.log("SUBMIT", "SUBMIT_STEP", {
|
|
1666
|
+
length: planSteps.length,
|
|
1667
|
+
steps: planSteps
|
|
1668
|
+
});
|
|
1669
|
+
const result = await context.qstashClient.batch(
|
|
1670
|
+
planSteps.map((planStep) => {
|
|
1671
|
+
const { headers } = getHeaders({
|
|
1672
|
+
initHeaderValue: "false",
|
|
1673
|
+
workflowConfig: {
|
|
1674
|
+
workflowRunId: context.workflowRunId,
|
|
1675
|
+
workflowUrl: context.url,
|
|
1676
|
+
failureUrl: context.failureUrl,
|
|
1677
|
+
retries: context.retries,
|
|
1678
|
+
flowControl: context.flowControl,
|
|
1679
|
+
telemetry
|
|
1680
|
+
},
|
|
1681
|
+
userHeaders: context.headers,
|
|
1682
|
+
invokeCount
|
|
1683
|
+
});
|
|
1684
|
+
return {
|
|
1685
|
+
headers,
|
|
1686
|
+
method: "POST",
|
|
1687
|
+
url: context.url,
|
|
1688
|
+
body: JSON.stringify(planStep),
|
|
1689
|
+
notBefore: planStep.sleepUntil,
|
|
1690
|
+
delay: planStep.sleepFor
|
|
1691
|
+
};
|
|
1692
|
+
})
|
|
1693
|
+
);
|
|
1694
|
+
await debug?.log("INFO", "SUBMIT_STEP", {
|
|
1695
|
+
messageIds: result.map((message) => {
|
|
1696
|
+
return {
|
|
1697
|
+
message: message.messageId
|
|
1698
|
+
};
|
|
1699
|
+
})
|
|
1700
|
+
});
|
|
1701
|
+
throw new WorkflowAbort(planSteps[0].stepName, planSteps[0]);
|
|
1702
|
+
};
|
|
1703
|
+
var submitSingleStep = async ({
|
|
1704
|
+
context,
|
|
1705
|
+
lazyStep,
|
|
1706
|
+
stepId,
|
|
1707
|
+
invokeCount,
|
|
1708
|
+
concurrency,
|
|
1709
|
+
telemetry,
|
|
1710
|
+
debug
|
|
1711
|
+
}) => {
|
|
1712
|
+
const resultStep = await lazyStep.getResultStep(concurrency, stepId);
|
|
1713
|
+
await debug?.log("INFO", "RUN_SINGLE", {
|
|
1714
|
+
fromRequest: false,
|
|
1715
|
+
step: resultStep,
|
|
1716
|
+
stepCount: stepId
|
|
1717
|
+
});
|
|
1718
|
+
const { headers } = lazyStep.getHeaders({
|
|
1719
|
+
context,
|
|
1720
|
+
step: resultStep,
|
|
1402
1721
|
invokeCount,
|
|
1403
|
-
|
|
1722
|
+
telemetry
|
|
1404
1723
|
});
|
|
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
|
|
1724
|
+
const body = lazyStep.getBody({
|
|
1725
|
+
context,
|
|
1726
|
+
step: resultStep,
|
|
1727
|
+
headers,
|
|
1728
|
+
invokeCount,
|
|
1729
|
+
telemetry
|
|
1417
1730
|
});
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
}
|
|
1422
|
-
const
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
};
|
|
1431
|
-
await
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1731
|
+
await debug?.log("SUBMIT", "SUBMIT_STEP", {
|
|
1732
|
+
length: 1,
|
|
1733
|
+
steps: [resultStep]
|
|
1734
|
+
});
|
|
1735
|
+
const submitResult = await lazyStep.submitStep({
|
|
1736
|
+
context,
|
|
1737
|
+
body,
|
|
1738
|
+
headers,
|
|
1739
|
+
isParallel: concurrency !== NO_CONCURRENCY,
|
|
1740
|
+
invokeCount,
|
|
1741
|
+
step: resultStep,
|
|
1742
|
+
telemetry
|
|
1743
|
+
});
|
|
1744
|
+
await debug?.log("INFO", "SUBMIT_STEP", {
|
|
1745
|
+
messageIds: submitResult.map((message) => {
|
|
1746
|
+
return {
|
|
1747
|
+
message: message.messageId
|
|
1748
|
+
};
|
|
1749
|
+
})
|
|
1436
1750
|
});
|
|
1751
|
+
return resultStep;
|
|
1437
1752
|
};
|
|
1438
1753
|
|
|
1439
1754
|
// src/context/auto-executor.ts
|
|
@@ -1540,14 +1855,16 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1540
1855
|
});
|
|
1541
1856
|
return lazyStep.parseOut(step.out);
|
|
1542
1857
|
}
|
|
1543
|
-
const resultStep = await
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1858
|
+
const resultStep = await submitSingleStep({
|
|
1859
|
+
context: this.context,
|
|
1860
|
+
lazyStep,
|
|
1861
|
+
stepId: this.stepCount,
|
|
1862
|
+
invokeCount: this.invokeCount,
|
|
1863
|
+
concurrency: 1,
|
|
1864
|
+
telemetry: this.telemetry,
|
|
1865
|
+
debug: this.debug
|
|
1548
1866
|
});
|
|
1549
|
-
|
|
1550
|
-
return resultStep.out;
|
|
1867
|
+
throw new WorkflowAbort(lazyStep.stepName, resultStep);
|
|
1551
1868
|
}
|
|
1552
1869
|
/**
|
|
1553
1870
|
* Runs steps in parallel.
|
|
@@ -1575,10 +1892,14 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1575
1892
|
});
|
|
1576
1893
|
switch (parallelCallState) {
|
|
1577
1894
|
case "first": {
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1895
|
+
await submitParallelSteps({
|
|
1896
|
+
context: this.context,
|
|
1897
|
+
steps: parallelSteps,
|
|
1898
|
+
initialStepCount,
|
|
1899
|
+
invokeCount: this.invokeCount,
|
|
1900
|
+
telemetry: this.telemetry,
|
|
1901
|
+
debug: this.debug
|
|
1902
|
+
});
|
|
1582
1903
|
break;
|
|
1583
1904
|
}
|
|
1584
1905
|
case "partial": {
|
|
@@ -1592,13 +1913,18 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1592
1913
|
validateStep(parallelSteps[stepIndex], planStep);
|
|
1593
1914
|
try {
|
|
1594
1915
|
const parallelStep = parallelSteps[stepIndex];
|
|
1595
|
-
const resultStep = await
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1916
|
+
const resultStep = await submitSingleStep({
|
|
1917
|
+
context: this.context,
|
|
1918
|
+
lazyStep: parallelStep,
|
|
1919
|
+
stepId: planStep.targetStep,
|
|
1920
|
+
invokeCount: this.invokeCount,
|
|
1921
|
+
concurrency: parallelSteps.length,
|
|
1922
|
+
telemetry: this.telemetry,
|
|
1923
|
+
debug: this.debug
|
|
1924
|
+
});
|
|
1925
|
+
throw new WorkflowAbort(parallelStep.stepName, resultStep);
|
|
1600
1926
|
} catch (error) {
|
|
1601
|
-
if (error instanceof WorkflowAbort || error instanceof
|
|
1927
|
+
if (error instanceof WorkflowAbort || error instanceof import_qstash5.QstashError && error.status === 400) {
|
|
1602
1928
|
throw error;
|
|
1603
1929
|
}
|
|
1604
1930
|
throw new WorkflowError(
|
|
@@ -1654,128 +1980,6 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1654
1980
|
return "discard";
|
|
1655
1981
|
}
|
|
1656
1982
|
}
|
|
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
1983
|
/**
|
|
1780
1984
|
* Get the promise by executing the lazt steps list. If there is a single
|
|
1781
1985
|
* step, we call `runSingle`. Otherwise `runParallel` is called.
|
|
@@ -1849,7 +2053,7 @@ var sortSteps = (steps) => {
|
|
|
1849
2053
|
};
|
|
1850
2054
|
|
|
1851
2055
|
// src/context/api/anthropic.ts
|
|
1852
|
-
var
|
|
2056
|
+
var import_qstash6 = require("@upstash/qstash");
|
|
1853
2057
|
|
|
1854
2058
|
// src/context/provider.ts
|
|
1855
2059
|
var getProviderInfo = (api) => {
|
|
@@ -1913,7 +2117,7 @@ var AnthropicAPI = class extends BaseWorkflowApi {
|
|
|
1913
2117
|
return await this.callApi(stepName, {
|
|
1914
2118
|
api: {
|
|
1915
2119
|
name: "llm",
|
|
1916
|
-
provider: (0,
|
|
2120
|
+
provider: (0, import_qstash6.anthropic)({ token })
|
|
1917
2121
|
},
|
|
1918
2122
|
...parameters
|
|
1919
2123
|
});
|
|
@@ -1921,12 +2125,12 @@ var AnthropicAPI = class extends BaseWorkflowApi {
|
|
|
1921
2125
|
};
|
|
1922
2126
|
|
|
1923
2127
|
// src/context/api/openai.ts
|
|
1924
|
-
var
|
|
2128
|
+
var import_qstash7 = require("@upstash/qstash");
|
|
1925
2129
|
var OpenAIAPI = class extends BaseWorkflowApi {
|
|
1926
2130
|
async call(stepName, settings) {
|
|
1927
2131
|
const { token, organization, operation, baseURL, ...parameters } = settings;
|
|
1928
2132
|
const useOpenAI = baseURL === void 0;
|
|
1929
|
-
const provider = useOpenAI ? (0,
|
|
2133
|
+
const provider = useOpenAI ? (0, import_qstash7.openai)({ token, organization }) : (0, import_qstash7.custom)({ baseUrl: baseURL, token });
|
|
1930
2134
|
return await this.callApi(stepName, {
|
|
1931
2135
|
api: {
|
|
1932
2136
|
name: "llm",
|
|
@@ -1938,14 +2142,14 @@ var OpenAIAPI = class extends BaseWorkflowApi {
|
|
|
1938
2142
|
};
|
|
1939
2143
|
|
|
1940
2144
|
// src/context/api/resend.ts
|
|
1941
|
-
var
|
|
2145
|
+
var import_qstash8 = require("@upstash/qstash");
|
|
1942
2146
|
var ResendAPI = class extends BaseWorkflowApi {
|
|
1943
2147
|
async call(stepName, settings) {
|
|
1944
2148
|
const { token, batch = false, ...parameters } = settings;
|
|
1945
2149
|
return await this.callApi(stepName, {
|
|
1946
2150
|
api: {
|
|
1947
2151
|
name: "email",
|
|
1948
|
-
provider: (0,
|
|
2152
|
+
provider: (0, import_qstash8.resend)({ token, batch })
|
|
1949
2153
|
},
|
|
1950
2154
|
...parameters
|
|
1951
2155
|
});
|
|
@@ -1972,28 +2176,11 @@ var WorkflowApi = class extends BaseWorkflowApi {
|
|
|
1972
2176
|
};
|
|
1973
2177
|
|
|
1974
2178
|
// src/agents/index.ts
|
|
1975
|
-
var import_openai3 = require("@ai-sdk/openai");
|
|
1976
|
-
|
|
1977
|
-
// src/agents/adapters.ts
|
|
1978
2179
|
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
2180
|
|
|
1995
2181
|
// src/agents/adapters.ts
|
|
1996
|
-
var
|
|
2182
|
+
var import_ai = require("ai");
|
|
2183
|
+
var fetchWithContextCall = async (context, agentCallParams, ...params) => {
|
|
1997
2184
|
const [input, init] = params;
|
|
1998
2185
|
try {
|
|
1999
2186
|
const headers = init?.headers ? Object.fromEntries(new Headers(init.headers).entries()) : {};
|
|
@@ -2004,7 +2191,10 @@ var fetchWithContextCall = async (context, ...params) => {
|
|
|
2004
2191
|
url: input.toString(),
|
|
2005
2192
|
method: init?.method,
|
|
2006
2193
|
headers,
|
|
2007
|
-
body
|
|
2194
|
+
body,
|
|
2195
|
+
timeout: agentCallParams?.timeout,
|
|
2196
|
+
retries: agentCallParams?.retries,
|
|
2197
|
+
flowControl: agentCallParams?.flowControl
|
|
2008
2198
|
});
|
|
2009
2199
|
const responseHeaders = new Headers(
|
|
2010
2200
|
Object.entries(responseInfo.header).reduce(
|
|
@@ -2031,10 +2221,11 @@ var fetchWithContextCall = async (context, ...params) => {
|
|
|
2031
2221
|
var createWorkflowModel = ({
|
|
2032
2222
|
context,
|
|
2033
2223
|
provider,
|
|
2034
|
-
providerParams
|
|
2224
|
+
providerParams,
|
|
2225
|
+
agentCallParams
|
|
2035
2226
|
}) => {
|
|
2036
2227
|
return provider({
|
|
2037
|
-
fetch: (...params) => fetchWithContextCall(context, ...params),
|
|
2228
|
+
fetch: (...params) => fetchWithContextCall(context, agentCallParams, ...params),
|
|
2038
2229
|
...providerParams
|
|
2039
2230
|
});
|
|
2040
2231
|
};
|
|
@@ -2274,17 +2465,26 @@ var WorkflowAgents = class {
|
|
|
2274
2465
|
*/
|
|
2275
2466
|
openai(...params) {
|
|
2276
2467
|
const [model, settings] = params;
|
|
2277
|
-
const { baseURL, apiKey, ...otherSettings } = settings ?? {};
|
|
2468
|
+
const { baseURL, apiKey, callSettings, ...otherSettings } = settings ?? {};
|
|
2278
2469
|
const openaiModel = this.AISDKModel({
|
|
2279
2470
|
context: this.context,
|
|
2280
|
-
provider:
|
|
2281
|
-
providerParams: { baseURL, apiKey, compatibility: "strict" }
|
|
2471
|
+
provider: import_openai2.createOpenAI,
|
|
2472
|
+
providerParams: { baseURL, apiKey, compatibility: "strict" },
|
|
2473
|
+
agentCallParams: callSettings
|
|
2282
2474
|
});
|
|
2283
2475
|
return openaiModel(model, otherSettings);
|
|
2284
2476
|
}
|
|
2285
2477
|
AISDKModel = createWorkflowModel;
|
|
2286
2478
|
};
|
|
2287
2479
|
|
|
2480
|
+
// src/serve/serve-many.ts
|
|
2481
|
+
var getNewUrlFromWorkflowId = (url, workflowId) => {
|
|
2482
|
+
if (!workflowId) {
|
|
2483
|
+
throw new WorkflowError("You can only call workflow which has a workflowId");
|
|
2484
|
+
}
|
|
2485
|
+
return url.replace(/[^/]+$/, workflowId);
|
|
2486
|
+
};
|
|
2487
|
+
|
|
2288
2488
|
// src/context/context.ts
|
|
2289
2489
|
var WorkflowContext = class {
|
|
2290
2490
|
executor;
|
|
@@ -2506,60 +2706,42 @@ var WorkflowContext = class {
|
|
|
2506
2706
|
}
|
|
2507
2707
|
await this.addStep(new LazySleepUntilStep(stepName, time));
|
|
2508
2708
|
}
|
|
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
2709
|
async call(stepName, settings) {
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2710
|
+
let callStep;
|
|
2711
|
+
if ("workflow" in settings) {
|
|
2712
|
+
const url = getNewUrlFromWorkflowId(this.url, settings.workflow.workflowId);
|
|
2713
|
+
callStep = new LazyCallStep(
|
|
2714
|
+
stepName,
|
|
2715
|
+
url,
|
|
2716
|
+
"POST",
|
|
2717
|
+
settings.body,
|
|
2718
|
+
settings.headers || {},
|
|
2719
|
+
settings.retries || 0,
|
|
2720
|
+
settings.timeout,
|
|
2721
|
+
settings.flowControl ?? settings.workflow.options.flowControl
|
|
2722
|
+
);
|
|
2723
|
+
} else {
|
|
2724
|
+
const {
|
|
2725
|
+
url,
|
|
2726
|
+
method = "GET",
|
|
2727
|
+
body,
|
|
2728
|
+
headers = {},
|
|
2729
|
+
retries = 0,
|
|
2730
|
+
timeout,
|
|
2731
|
+
flowControl
|
|
2732
|
+
} = settings;
|
|
2733
|
+
callStep = new LazyCallStep(
|
|
2553
2734
|
stepName,
|
|
2554
2735
|
url,
|
|
2555
2736
|
method,
|
|
2556
|
-
|
|
2737
|
+
body,
|
|
2557
2738
|
headers,
|
|
2558
2739
|
retries,
|
|
2559
2740
|
timeout,
|
|
2560
2741
|
flowControl
|
|
2561
|
-
)
|
|
2562
|
-
|
|
2742
|
+
);
|
|
2743
|
+
}
|
|
2744
|
+
return await this.addStep(callStep);
|
|
2563
2745
|
}
|
|
2564
2746
|
/**
|
|
2565
2747
|
* Pauses workflow execution until a specific event occurs or a timeout is reached.
|
|
@@ -2707,7 +2889,7 @@ var WorkflowLogger = class _WorkflowLogger {
|
|
|
2707
2889
|
};
|
|
2708
2890
|
|
|
2709
2891
|
// src/serve/authorization.ts
|
|
2710
|
-
var
|
|
2892
|
+
var import_qstash9 = require("@upstash/qstash");
|
|
2711
2893
|
var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowContext {
|
|
2712
2894
|
static disabledMessage = "disabled-qstash-worklfow-run";
|
|
2713
2895
|
disabled = true;
|
|
@@ -2739,7 +2921,7 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
|
|
|
2739
2921
|
*/
|
|
2740
2922
|
static async tryAuthentication(routeFunction, context) {
|
|
2741
2923
|
const disabledContext = new _DisabledWorkflowContext({
|
|
2742
|
-
qstashClient: new
|
|
2924
|
+
qstashClient: new import_qstash9.Client({
|
|
2743
2925
|
baseUrl: "disabled-client",
|
|
2744
2926
|
token: "disabled-client"
|
|
2745
2927
|
}),
|
|
@@ -2953,15 +3135,15 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
|
|
|
2953
3135
|
};
|
|
2954
3136
|
|
|
2955
3137
|
// src/serve/options.ts
|
|
2956
|
-
var import_qstash9 = require("@upstash/qstash");
|
|
2957
3138
|
var import_qstash10 = require("@upstash/qstash");
|
|
3139
|
+
var import_qstash11 = require("@upstash/qstash");
|
|
2958
3140
|
var processOptions = (options) => {
|
|
2959
3141
|
const environment = options?.env ?? (typeof process === "undefined" ? {} : process.env);
|
|
2960
3142
|
const receiverEnvironmentVariablesSet = Boolean(
|
|
2961
3143
|
environment.QSTASH_CURRENT_SIGNING_KEY && environment.QSTASH_NEXT_SIGNING_KEY
|
|
2962
3144
|
);
|
|
2963
3145
|
return {
|
|
2964
|
-
qstashClient: new
|
|
3146
|
+
qstashClient: new import_qstash11.Client({
|
|
2965
3147
|
baseUrl: environment.QSTASH_URL,
|
|
2966
3148
|
token: environment.QSTASH_TOKEN
|
|
2967
3149
|
}),
|
|
@@ -2996,7 +3178,7 @@ var processOptions = (options) => {
|
|
|
2996
3178
|
throw error;
|
|
2997
3179
|
}
|
|
2998
3180
|
},
|
|
2999
|
-
receiver: receiverEnvironmentVariablesSet ? new
|
|
3181
|
+
receiver: receiverEnvironmentVariablesSet ? new import_qstash10.Receiver({
|
|
3000
3182
|
currentSigningKey: environment.QSTASH_CURRENT_SIGNING_KEY,
|
|
3001
3183
|
nextSigningKey: environment.QSTASH_NEXT_SIGNING_KEY
|
|
3002
3184
|
}) : void 0,
|