@upstash/workflow 0.2.10 → 0.2.12
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 +217 -112
- package/astro.mjs +1 -1
- package/{chunk-GFNR743S.mjs → chunk-4GTHIL7S.mjs} +217 -112
- package/cloudflare.d.mts +2 -2
- package/cloudflare.d.ts +2 -2
- package/cloudflare.js +217 -112
- package/cloudflare.mjs +1 -1
- package/express.d.mts +2 -2
- package/express.d.ts +2 -2
- package/express.js +217 -112
- package/express.mjs +1 -1
- package/h3.d.mts +2 -2
- package/h3.d.ts +2 -2
- package/h3.js +217 -112
- package/h3.mjs +1 -1
- package/hono.d.mts +2 -2
- package/hono.d.ts +2 -2
- package/hono.js +217 -112
- package/hono.mjs +1 -1
- package/index.d.mts +34 -4
- package/index.d.ts +34 -4
- package/index.js +217 -112
- package/index.mjs +1 -1
- package/nextjs.d.mts +2 -2
- package/nextjs.d.ts +2 -2
- package/nextjs.js +217 -112
- package/nextjs.mjs +1 -1
- package/package.json +1 -1
- package/{serve-many-e4zufyXN.d.ts → serve-many-BdMq5rFX.d.ts} +1 -1
- package/{serve-many-BVDpPsF-.d.mts → serve-many-DLguU9iR.d.mts} +1 -1
- package/solidjs.d.mts +1 -1
- package/solidjs.d.ts +1 -1
- package/solidjs.js +217 -112
- package/solidjs.mjs +1 -1
- package/svelte.d.mts +2 -2
- package/svelte.d.ts +2 -2
- package/svelte.js +217 -112
- package/svelte.mjs +1 -1
- package/{types-CYhDXnf8.d.ts → types-D1W0VOpy.d.mts} +70 -46
- package/{types-CYhDXnf8.d.mts → types-D1W0VOpy.d.ts} +70 -46
package/h3.js
CHANGED
|
@@ -446,7 +446,7 @@ var formatWorkflowError = (error) => {
|
|
|
446
446
|
message: error.message
|
|
447
447
|
} : {
|
|
448
448
|
error: "Error",
|
|
449
|
-
message:
|
|
449
|
+
message: `An error occured while executing workflow: '${typeof error === "string" ? error : JSON.stringify(error)}'`
|
|
450
450
|
};
|
|
451
451
|
};
|
|
452
452
|
|
|
@@ -463,22 +463,21 @@ function getWorkflowRunId(id) {
|
|
|
463
463
|
return `wfr_${id ?? nanoid()}`;
|
|
464
464
|
}
|
|
465
465
|
function decodeBase64(base64) {
|
|
466
|
+
const binString = atob(base64);
|
|
466
467
|
try {
|
|
467
|
-
const binString = atob(base64);
|
|
468
468
|
const intArray = Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
469
469
|
return new TextDecoder().decode(intArray);
|
|
470
470
|
} catch (error) {
|
|
471
471
|
console.warn(
|
|
472
472
|
`Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
|
|
473
473
|
);
|
|
474
|
-
return
|
|
474
|
+
return binString;
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
477
|
|
|
478
478
|
// src/context/steps.ts
|
|
479
|
-
var BaseLazyStep = class {
|
|
479
|
+
var BaseLazyStep = class _BaseLazyStep {
|
|
480
480
|
stepName;
|
|
481
|
-
// will be set in the subclasses
|
|
482
481
|
constructor(stepName) {
|
|
483
482
|
if (!stepName) {
|
|
484
483
|
throw new WorkflowError(
|
|
@@ -487,10 +486,58 @@ var BaseLazyStep = class {
|
|
|
487
486
|
}
|
|
488
487
|
this.stepName = stepName;
|
|
489
488
|
}
|
|
489
|
+
/**
|
|
490
|
+
* parse the out field of a step result.
|
|
491
|
+
*
|
|
492
|
+
* will be called when returning the steps to the context from auto executor
|
|
493
|
+
*
|
|
494
|
+
* @param out field of the step
|
|
495
|
+
* @returns parsed out field
|
|
496
|
+
*/
|
|
497
|
+
parseOut(out) {
|
|
498
|
+
if (out === void 0) {
|
|
499
|
+
if (this.allowUndefinedOut) {
|
|
500
|
+
return void 0;
|
|
501
|
+
} else {
|
|
502
|
+
throw new WorkflowError(
|
|
503
|
+
`Error while parsing output of ${this.stepType} step. Expected a string, but got: undefined`
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
if (typeof out === "object") {
|
|
508
|
+
if (this.stepType !== "Wait") {
|
|
509
|
+
console.warn(
|
|
510
|
+
`Error while parsing ${this.stepType} step output. Expected a string, but got object. Please reach out to Upstash Support.`
|
|
511
|
+
);
|
|
512
|
+
return out;
|
|
513
|
+
}
|
|
514
|
+
return {
|
|
515
|
+
...out,
|
|
516
|
+
eventData: _BaseLazyStep.tryParsing(out.eventData)
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
if (typeof out !== "string") {
|
|
520
|
+
throw new WorkflowError(
|
|
521
|
+
`Error while parsing output of ${this.stepType} step. Expected a string or undefined, but got: ${typeof out}`
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
return this.safeParseOut(out);
|
|
525
|
+
}
|
|
526
|
+
safeParseOut(out) {
|
|
527
|
+
return _BaseLazyStep.tryParsing(out);
|
|
528
|
+
}
|
|
529
|
+
static tryParsing(stepOut) {
|
|
530
|
+
try {
|
|
531
|
+
return JSON.parse(stepOut);
|
|
532
|
+
} catch {
|
|
533
|
+
return stepOut;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
490
536
|
};
|
|
491
537
|
var LazyFunctionStep = class extends BaseLazyStep {
|
|
492
538
|
stepFunction;
|
|
493
539
|
stepType = "Run";
|
|
540
|
+
allowUndefinedOut = true;
|
|
494
541
|
constructor(stepName, stepFunction) {
|
|
495
542
|
super(stepName);
|
|
496
543
|
this.stepFunction = stepFunction;
|
|
@@ -521,6 +568,7 @@ var LazyFunctionStep = class extends BaseLazyStep {
|
|
|
521
568
|
var LazySleepStep = class extends BaseLazyStep {
|
|
522
569
|
sleep;
|
|
523
570
|
stepType = "SleepFor";
|
|
571
|
+
allowUndefinedOut = true;
|
|
524
572
|
constructor(stepName, sleep) {
|
|
525
573
|
super(stepName);
|
|
526
574
|
this.sleep = sleep;
|
|
@@ -548,6 +596,7 @@ var LazySleepStep = class extends BaseLazyStep {
|
|
|
548
596
|
var LazySleepUntilStep = class extends BaseLazyStep {
|
|
549
597
|
sleepUntil;
|
|
550
598
|
stepType = "SleepUntil";
|
|
599
|
+
allowUndefinedOut = true;
|
|
551
600
|
constructor(stepName, sleepUntil) {
|
|
552
601
|
super(stepName);
|
|
553
602
|
this.sleepUntil = sleepUntil;
|
|
@@ -571,8 +620,11 @@ var LazySleepUntilStep = class extends BaseLazyStep {
|
|
|
571
620
|
concurrent
|
|
572
621
|
});
|
|
573
622
|
}
|
|
623
|
+
safeParseOut() {
|
|
624
|
+
return void 0;
|
|
625
|
+
}
|
|
574
626
|
};
|
|
575
|
-
var LazyCallStep = class extends BaseLazyStep {
|
|
627
|
+
var LazyCallStep = class _LazyCallStep extends BaseLazyStep {
|
|
576
628
|
url;
|
|
577
629
|
method;
|
|
578
630
|
body;
|
|
@@ -581,6 +633,7 @@ var LazyCallStep = class extends BaseLazyStep {
|
|
|
581
633
|
timeout;
|
|
582
634
|
flowControl;
|
|
583
635
|
stepType = "Call";
|
|
636
|
+
allowUndefinedOut = false;
|
|
584
637
|
constructor(stepName, url, method, body, headers, retries, timeout, flowControl) {
|
|
585
638
|
super(stepName);
|
|
586
639
|
this.url = url;
|
|
@@ -612,11 +665,53 @@ var LazyCallStep = class extends BaseLazyStep {
|
|
|
612
665
|
callHeaders: this.headers
|
|
613
666
|
});
|
|
614
667
|
}
|
|
668
|
+
safeParseOut(out) {
|
|
669
|
+
const { header, status, body } = JSON.parse(out);
|
|
670
|
+
const responseHeaders = new Headers(header);
|
|
671
|
+
if (_LazyCallStep.isText(responseHeaders.get("content-type"))) {
|
|
672
|
+
const bytes = new Uint8Array(out.length);
|
|
673
|
+
for (let i = 0; i < out.length; i++) {
|
|
674
|
+
bytes[i] = out.charCodeAt(i);
|
|
675
|
+
}
|
|
676
|
+
const processedResult = new TextDecoder().decode(bytes);
|
|
677
|
+
const newBody = JSON.parse(processedResult).body;
|
|
678
|
+
return {
|
|
679
|
+
status,
|
|
680
|
+
header,
|
|
681
|
+
body: BaseLazyStep.tryParsing(newBody)
|
|
682
|
+
};
|
|
683
|
+
} else {
|
|
684
|
+
return { header, status, body };
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
static applicationHeaders = /* @__PURE__ */ new Set([
|
|
688
|
+
"application/json",
|
|
689
|
+
"application/xml",
|
|
690
|
+
"application/javascript",
|
|
691
|
+
"application/x-www-form-urlencoded",
|
|
692
|
+
"application/xhtml+xml",
|
|
693
|
+
"application/ld+json",
|
|
694
|
+
"application/rss+xml",
|
|
695
|
+
"application/atom+xml"
|
|
696
|
+
]);
|
|
697
|
+
static isText = (contentTypeHeader) => {
|
|
698
|
+
if (!contentTypeHeader) {
|
|
699
|
+
return false;
|
|
700
|
+
}
|
|
701
|
+
if (_LazyCallStep.applicationHeaders.has(contentTypeHeader)) {
|
|
702
|
+
return true;
|
|
703
|
+
}
|
|
704
|
+
if (contentTypeHeader.startsWith("text/")) {
|
|
705
|
+
return true;
|
|
706
|
+
}
|
|
707
|
+
return false;
|
|
708
|
+
};
|
|
615
709
|
};
|
|
616
710
|
var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
617
711
|
eventId;
|
|
618
712
|
timeout;
|
|
619
713
|
stepType = "Wait";
|
|
714
|
+
allowUndefinedOut = false;
|
|
620
715
|
constructor(stepName, eventId, timeout) {
|
|
621
716
|
super(stepName);
|
|
622
717
|
this.eventId = eventId;
|
|
@@ -643,6 +738,13 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
643
738
|
concurrent
|
|
644
739
|
});
|
|
645
740
|
}
|
|
741
|
+
safeParseOut(out) {
|
|
742
|
+
const result = JSON.parse(out);
|
|
743
|
+
return {
|
|
744
|
+
...result,
|
|
745
|
+
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
746
|
+
};
|
|
747
|
+
}
|
|
646
748
|
};
|
|
647
749
|
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
648
750
|
stepType = "Notify";
|
|
@@ -656,10 +758,18 @@ var LazyNotifyStep = class extends LazyFunctionStep {
|
|
|
656
758
|
};
|
|
657
759
|
});
|
|
658
760
|
}
|
|
761
|
+
safeParseOut(out) {
|
|
762
|
+
const result = JSON.parse(out);
|
|
763
|
+
return {
|
|
764
|
+
...result,
|
|
765
|
+
eventData: BaseLazyStep.tryParsing(result.eventData)
|
|
766
|
+
};
|
|
767
|
+
}
|
|
659
768
|
};
|
|
660
769
|
var LazyInvokeStep = class extends BaseLazyStep {
|
|
661
770
|
stepType = "Invoke";
|
|
662
771
|
params;
|
|
772
|
+
allowUndefinedOut = false;
|
|
663
773
|
constructor(stepName, {
|
|
664
774
|
workflow,
|
|
665
775
|
body,
|
|
@@ -699,6 +809,13 @@ var LazyInvokeStep = class extends BaseLazyStep {
|
|
|
699
809
|
concurrent
|
|
700
810
|
});
|
|
701
811
|
}
|
|
812
|
+
safeParseOut(out) {
|
|
813
|
+
const result = JSON.parse(out);
|
|
814
|
+
return {
|
|
815
|
+
...result,
|
|
816
|
+
body: BaseLazyStep.tryParsing(result.body)
|
|
817
|
+
};
|
|
818
|
+
}
|
|
702
819
|
};
|
|
703
820
|
|
|
704
821
|
// node_modules/neverthrow/dist/index.es.js
|
|
@@ -1384,7 +1501,8 @@ var getHeaders = ({
|
|
|
1384
1501
|
flowControl,
|
|
1385
1502
|
callFlowControl
|
|
1386
1503
|
}) => {
|
|
1387
|
-
const
|
|
1504
|
+
const callHeaders = new Headers(step?.callHeaders);
|
|
1505
|
+
const contentType = (callHeaders.get("content-type") ? callHeaders.get("content-type") : userHeaders?.get("Content-Type") ? userHeaders.get("Content-Type") : void 0) ?? DEFAULT_CONTENT_TYPE;
|
|
1388
1506
|
const baseHeaders = {
|
|
1389
1507
|
[WORKFLOW_INIT_HEADER]: initHeaderValue,
|
|
1390
1508
|
[WORKFLOW_ID_HEADER]: workflowRunId,
|
|
@@ -1795,7 +1913,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1795
1913
|
step,
|
|
1796
1914
|
stepCount: this.stepCount
|
|
1797
1915
|
});
|
|
1798
|
-
return step.out;
|
|
1916
|
+
return lazyStep.parseOut(step.out);
|
|
1799
1917
|
}
|
|
1800
1918
|
const resultStep = await lazyStep.getResultStep(NO_CONCURRENCY, this.stepCount);
|
|
1801
1919
|
await this.debug?.log("INFO", "RUN_SINGLE", {
|
|
@@ -1870,7 +1988,9 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1870
1988
|
case "last": {
|
|
1871
1989
|
const parallelResultSteps = sortedSteps.filter((step) => step.stepId >= initialStepCount).slice(0, parallelSteps.length);
|
|
1872
1990
|
validateParallelSteps(parallelSteps, parallelResultSteps);
|
|
1873
|
-
return parallelResultSteps.map(
|
|
1991
|
+
return parallelResultSteps.map(
|
|
1992
|
+
(step, index) => parallelSteps[index].parseOut(step.out)
|
|
1993
|
+
);
|
|
1874
1994
|
}
|
|
1875
1995
|
}
|
|
1876
1996
|
const fillValue = void 0;
|
|
@@ -1973,7 +2093,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
1973
2093
|
});
|
|
1974
2094
|
throw new WorkflowAbort(invokeStep.stepName, invokeStep);
|
|
1975
2095
|
}
|
|
1976
|
-
const result = await this.context.qstashClient.
|
|
2096
|
+
const result = await this.context.qstashClient.batch(
|
|
1977
2097
|
steps.map((singleStep, index) => {
|
|
1978
2098
|
const lazyStep = lazySteps[index];
|
|
1979
2099
|
const { headers } = getHeaders({
|
|
@@ -2003,7 +2123,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
2003
2123
|
{
|
|
2004
2124
|
headers,
|
|
2005
2125
|
method: singleStep.callMethod,
|
|
2006
|
-
body: singleStep.callBody,
|
|
2126
|
+
body: JSON.stringify(singleStep.callBody),
|
|
2007
2127
|
url: singleStep.callUrl
|
|
2008
2128
|
}
|
|
2009
2129
|
) : (
|
|
@@ -2013,7 +2133,7 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
2013
2133
|
{
|
|
2014
2134
|
headers,
|
|
2015
2135
|
method: "POST",
|
|
2016
|
-
body: singleStep,
|
|
2136
|
+
body: JSON.stringify(singleStep),
|
|
2017
2137
|
url: this.context.url,
|
|
2018
2138
|
notBefore: willWait ? singleStep.sleepUntil : void 0,
|
|
2019
2139
|
delay: willWait ? singleStep.sleepFor : void 0
|
|
@@ -2021,8 +2141,9 @@ var AutoExecutor = class _AutoExecutor {
|
|
|
2021
2141
|
);
|
|
2022
2142
|
})
|
|
2023
2143
|
);
|
|
2144
|
+
const _result = result;
|
|
2024
2145
|
await this.debug?.log("INFO", "SUBMIT_STEP", {
|
|
2025
|
-
messageIds:
|
|
2146
|
+
messageIds: _result.map((message) => {
|
|
2026
2147
|
return {
|
|
2027
2148
|
message: message.messageId
|
|
2028
2149
|
};
|
|
@@ -2225,6 +2346,9 @@ var WorkflowApi = class extends BaseWorkflowApi {
|
|
|
2225
2346
|
}
|
|
2226
2347
|
};
|
|
2227
2348
|
|
|
2349
|
+
// src/agents/index.ts
|
|
2350
|
+
var import_openai3 = require("@ai-sdk/openai");
|
|
2351
|
+
|
|
2228
2352
|
// src/agents/adapters.ts
|
|
2229
2353
|
var import_openai2 = require("@ai-sdk/openai");
|
|
2230
2354
|
var import_ai = require("ai");
|
|
@@ -2244,46 +2368,49 @@ you need from that agent.
|
|
|
2244
2368
|
`;
|
|
2245
2369
|
|
|
2246
2370
|
// src/agents/adapters.ts
|
|
2247
|
-
var
|
|
2248
|
-
const
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
if (error instanceof Error && error.name === "WorkflowAbort") {
|
|
2280
|
-
throw error;
|
|
2281
|
-
} else {
|
|
2282
|
-
console.error("Error in fetch implementation:", error);
|
|
2283
|
-
throw error;
|
|
2284
|
-
}
|
|
2285
|
-
}
|
|
2371
|
+
var fetchWithContextCall = async (context, ...params) => {
|
|
2372
|
+
const [input, init] = params;
|
|
2373
|
+
try {
|
|
2374
|
+
const headers = init?.headers ? Object.fromEntries(new Headers(init.headers).entries()) : {};
|
|
2375
|
+
const body = init?.body ? JSON.parse(init.body) : void 0;
|
|
2376
|
+
const agentName = headers[AGENT_NAME_HEADER];
|
|
2377
|
+
const stepName = agentName ? `Call Agent ${agentName}` : "Call Agent";
|
|
2378
|
+
const responseInfo = await context.call(stepName, {
|
|
2379
|
+
url: input.toString(),
|
|
2380
|
+
method: init?.method,
|
|
2381
|
+
headers,
|
|
2382
|
+
body
|
|
2383
|
+
});
|
|
2384
|
+
const responseHeaders = new Headers(
|
|
2385
|
+
Object.entries(responseInfo.header).reduce(
|
|
2386
|
+
(acc, [key, values]) => {
|
|
2387
|
+
acc[key] = values.join(", ");
|
|
2388
|
+
return acc;
|
|
2389
|
+
},
|
|
2390
|
+
{}
|
|
2391
|
+
)
|
|
2392
|
+
);
|
|
2393
|
+
return new Response(JSON.stringify(responseInfo.body), {
|
|
2394
|
+
status: responseInfo.status,
|
|
2395
|
+
headers: responseHeaders
|
|
2396
|
+
});
|
|
2397
|
+
} catch (error) {
|
|
2398
|
+
if (error instanceof Error && error.name === "WorkflowAbort") {
|
|
2399
|
+
throw error;
|
|
2400
|
+
} else {
|
|
2401
|
+
console.error("Error in fetch implementation:", error);
|
|
2402
|
+
throw error;
|
|
2286
2403
|
}
|
|
2404
|
+
}
|
|
2405
|
+
};
|
|
2406
|
+
var createWorkflowModel = ({
|
|
2407
|
+
context,
|
|
2408
|
+
provider,
|
|
2409
|
+
providerParams
|
|
2410
|
+
}) => {
|
|
2411
|
+
return provider({
|
|
2412
|
+
fetch: (...params) => fetchWithContextCall(context, ...params),
|
|
2413
|
+
...providerParams
|
|
2287
2414
|
});
|
|
2288
2415
|
};
|
|
2289
2416
|
var wrapTools = ({
|
|
@@ -2523,9 +2650,14 @@ var WorkflowAgents = class {
|
|
|
2523
2650
|
openai(...params) {
|
|
2524
2651
|
const [model, settings] = params;
|
|
2525
2652
|
const { baseURL, apiKey, ...otherSettings } = settings ?? {};
|
|
2526
|
-
const
|
|
2527
|
-
|
|
2653
|
+
const openaiModel = this.AISDKModel({
|
|
2654
|
+
context: this.context,
|
|
2655
|
+
provider: import_openai3.createOpenAI,
|
|
2656
|
+
providerParams: { baseURL, apiKey, compatibility: "strict" }
|
|
2657
|
+
});
|
|
2658
|
+
return openaiModel(model, otherSettings);
|
|
2528
2659
|
}
|
|
2660
|
+
AISDKModel = createWorkflowModel;
|
|
2529
2661
|
};
|
|
2530
2662
|
|
|
2531
2663
|
// src/context/context.ts
|
|
@@ -2711,7 +2843,7 @@ var WorkflowContext = class {
|
|
|
2711
2843
|
*/
|
|
2712
2844
|
async run(stepName, stepFunction) {
|
|
2713
2845
|
const wrappedStepFunction = () => this.executor.wrapStep(stepName, stepFunction);
|
|
2714
|
-
return this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
|
|
2846
|
+
return await this.addStep(new LazyFunctionStep(stepName, wrappedStepFunction));
|
|
2715
2847
|
}
|
|
2716
2848
|
/**
|
|
2717
2849
|
* Stops the execution for the duration provided.
|
|
@@ -2782,43 +2914,27 @@ var WorkflowContext = class {
|
|
|
2782
2914
|
* }
|
|
2783
2915
|
*/
|
|
2784
2916
|
async call(stepName, settings) {
|
|
2785
|
-
const {
|
|
2786
|
-
|
|
2917
|
+
const {
|
|
2918
|
+
url,
|
|
2919
|
+
method = "GET",
|
|
2920
|
+
body: requestBody,
|
|
2921
|
+
headers = {},
|
|
2922
|
+
retries = 0,
|
|
2923
|
+
timeout,
|
|
2924
|
+
flowControl
|
|
2925
|
+
} = settings;
|
|
2926
|
+
return await this.addStep(
|
|
2787
2927
|
new LazyCallStep(
|
|
2788
2928
|
stepName,
|
|
2789
2929
|
url,
|
|
2790
2930
|
method,
|
|
2791
|
-
|
|
2931
|
+
requestBody,
|
|
2792
2932
|
headers,
|
|
2793
2933
|
retries,
|
|
2794
2934
|
timeout,
|
|
2795
2935
|
flowControl
|
|
2796
2936
|
)
|
|
2797
2937
|
);
|
|
2798
|
-
if (typeof result === "string") {
|
|
2799
|
-
try {
|
|
2800
|
-
const body2 = JSON.parse(result);
|
|
2801
|
-
return {
|
|
2802
|
-
status: 200,
|
|
2803
|
-
header: {},
|
|
2804
|
-
body: body2
|
|
2805
|
-
};
|
|
2806
|
-
} catch {
|
|
2807
|
-
return {
|
|
2808
|
-
status: 200,
|
|
2809
|
-
header: {},
|
|
2810
|
-
body: result
|
|
2811
|
-
};
|
|
2812
|
-
}
|
|
2813
|
-
}
|
|
2814
|
-
try {
|
|
2815
|
-
return {
|
|
2816
|
-
...result,
|
|
2817
|
-
body: JSON.parse(result.body)
|
|
2818
|
-
};
|
|
2819
|
-
} catch {
|
|
2820
|
-
return result;
|
|
2821
|
-
}
|
|
2822
2938
|
}
|
|
2823
2939
|
/**
|
|
2824
2940
|
* Pauses workflow execution until a specific event occurs or a timeout is reached.
|
|
@@ -2857,15 +2973,7 @@ var WorkflowContext = class {
|
|
|
2857
2973
|
async waitForEvent(stepName, eventId, options = {}) {
|
|
2858
2974
|
const { timeout = "7d" } = options;
|
|
2859
2975
|
const timeoutStr = typeof timeout === "string" ? timeout : `${timeout}s`;
|
|
2860
|
-
|
|
2861
|
-
try {
|
|
2862
|
-
return {
|
|
2863
|
-
...result,
|
|
2864
|
-
eventData: JSON.parse(result.eventData)
|
|
2865
|
-
};
|
|
2866
|
-
} catch {
|
|
2867
|
-
return result;
|
|
2868
|
-
}
|
|
2976
|
+
return await this.addStep(new LazyWaitForEventStep(stepName, eventId, timeoutStr));
|
|
2869
2977
|
}
|
|
2870
2978
|
/**
|
|
2871
2979
|
* Notify workflow runs waiting for an event
|
|
@@ -2889,24 +2997,12 @@ var WorkflowContext = class {
|
|
|
2889
2997
|
* @returns notify response which has event id, event data and list of waiters which were notified
|
|
2890
2998
|
*/
|
|
2891
2999
|
async notify(stepName, eventId, eventData) {
|
|
2892
|
-
|
|
3000
|
+
return await this.addStep(
|
|
2893
3001
|
new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
|
|
2894
3002
|
);
|
|
2895
|
-
try {
|
|
2896
|
-
return {
|
|
2897
|
-
...result,
|
|
2898
|
-
eventData: JSON.parse(result.eventData)
|
|
2899
|
-
};
|
|
2900
|
-
} catch {
|
|
2901
|
-
return result;
|
|
2902
|
-
}
|
|
2903
3003
|
}
|
|
2904
3004
|
async invoke(stepName, settings) {
|
|
2905
|
-
|
|
2906
|
-
return {
|
|
2907
|
-
...result,
|
|
2908
|
-
body: result.body ? JSON.parse(result.body) : void 0
|
|
2909
|
-
};
|
|
3005
|
+
return await this.addStep(new LazyInvokeStep(stepName, settings));
|
|
2910
3006
|
}
|
|
2911
3007
|
/**
|
|
2912
3008
|
* Cancel the current workflow run
|
|
@@ -3065,10 +3161,6 @@ var processRawSteps = (rawSteps) => {
|
|
|
3065
3161
|
const stepsToDecode = encodedSteps.filter((step) => step.callType === "step");
|
|
3066
3162
|
const otherSteps = stepsToDecode.map((rawStep) => {
|
|
3067
3163
|
const step = JSON.parse(decodeBase64(rawStep.body));
|
|
3068
|
-
try {
|
|
3069
|
-
step.out = JSON.parse(step.out);
|
|
3070
|
-
} catch {
|
|
3071
|
-
}
|
|
3072
3164
|
if (step.waitEventId) {
|
|
3073
3165
|
const newOut = {
|
|
3074
3166
|
eventData: step.out ? decodeBase64(step.out) : void 0,
|
|
@@ -3288,6 +3380,7 @@ var processOptions = (options) => {
|
|
|
3288
3380
|
retries: DEFAULT_RETRIES,
|
|
3289
3381
|
useJSONContent: false,
|
|
3290
3382
|
disableTelemetry: false,
|
|
3383
|
+
onError: console.error,
|
|
3291
3384
|
...options
|
|
3292
3385
|
};
|
|
3293
3386
|
};
|
|
@@ -3337,7 +3430,8 @@ var serveBase = (routeFunction, telemetry2, options) => {
|
|
|
3337
3430
|
retries,
|
|
3338
3431
|
useJSONContent,
|
|
3339
3432
|
disableTelemetry,
|
|
3340
|
-
flowControl
|
|
3433
|
+
flowControl,
|
|
3434
|
+
onError
|
|
3341
3435
|
} = processOptions(options);
|
|
3342
3436
|
telemetry2 = disableTelemetry ? void 0 : telemetry2;
|
|
3343
3437
|
const debug = WorkflowLogger.getLogger(verbose);
|
|
@@ -3466,8 +3560,19 @@ var serveBase = (routeFunction, telemetry2, options) => {
|
|
|
3466
3560
|
try {
|
|
3467
3561
|
return await handler(request);
|
|
3468
3562
|
} catch (error) {
|
|
3469
|
-
|
|
3470
|
-
|
|
3563
|
+
const formattedError = formatWorkflowError(error);
|
|
3564
|
+
try {
|
|
3565
|
+
onError?.(error);
|
|
3566
|
+
} catch (onErrorError) {
|
|
3567
|
+
const formattedOnErrorError = formatWorkflowError(onErrorError);
|
|
3568
|
+
const errorMessage = `Error while running onError callback: '${formattedOnErrorError.message}'.
|
|
3569
|
+
Original error: '${formattedError.message}'`;
|
|
3570
|
+
console.error(errorMessage);
|
|
3571
|
+
return new Response(errorMessage, {
|
|
3572
|
+
status: 500
|
|
3573
|
+
});
|
|
3574
|
+
}
|
|
3575
|
+
return new Response(JSON.stringify(formattedError), {
|
|
3471
3576
|
status: 500
|
|
3472
3577
|
});
|
|
3473
3578
|
}
|
package/h3.mjs
CHANGED
package/hono.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context } from 'hono';
|
|
2
|
-
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-
|
|
2
|
+
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-D1W0VOpy.mjs';
|
|
3
3
|
import { Variables } from 'hono/types';
|
|
4
|
-
import { s as serveManyBase } from './serve-many-
|
|
4
|
+
import { s as serveManyBase } from './serve-many-DLguU9iR.mjs';
|
|
5
5
|
import '@upstash/qstash';
|
|
6
6
|
import 'zod';
|
|
7
7
|
import 'ai';
|
package/hono.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context } from 'hono';
|
|
2
|
-
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-
|
|
2
|
+
import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-D1W0VOpy.js';
|
|
3
3
|
import { Variables } from 'hono/types';
|
|
4
|
-
import { s as serveManyBase } from './serve-many-
|
|
4
|
+
import { s as serveManyBase } from './serve-many-BdMq5rFX.js';
|
|
5
5
|
import '@upstash/qstash';
|
|
6
6
|
import 'zod';
|
|
7
7
|
import 'ai';
|