@teamkeel/functions-runtime 0.413.2-next.3 → 0.413.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +61 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +61 -39
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2582,7 +2582,7 @@ function createFlowContext(runId, data, spanId) {
|
|
|
2582
2582
|
const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
|
|
2583
2583
|
const actualFn = typeof optionsOrFn === "function" ? optionsOrFn : fn;
|
|
2584
2584
|
const db = useDatabase();
|
|
2585
|
-
const past = await db.selectFrom("
|
|
2585
|
+
const past = await db.selectFrom("keel.flow_step").where("run_id", "=", runId).where("name", "=", name).selectAll().execute();
|
|
2586
2586
|
const newSteps = past.filter((step) => step.status === "NEW" /* NEW */);
|
|
2587
2587
|
const completedSteps = past.filter(
|
|
2588
2588
|
(step) => step.status === "COMPLETED" /* COMPLETED */
|
|
@@ -2606,7 +2606,7 @@ function createFlowContext(runId, data, spanId) {
|
|
|
2606
2606
|
}
|
|
2607
2607
|
if (newSteps.length === 1) {
|
|
2608
2608
|
let result = null;
|
|
2609
|
-
await db.updateTable("
|
|
2609
|
+
await db.updateTable("keel.flow_step").set({
|
|
2610
2610
|
startTime: /* @__PURE__ */ new Date()
|
|
2611
2611
|
}).where("id", "=", newSteps[0].id).returningAll().executeTakeFirst();
|
|
2612
2612
|
try {
|
|
@@ -2615,7 +2615,7 @@ function createFlowContext(runId, data, spanId) {
|
|
|
2615
2615
|
options.timeoutInMs ?? defaultOpts.timeoutInMs
|
|
2616
2616
|
);
|
|
2617
2617
|
} catch (e) {
|
|
2618
|
-
await db.updateTable("
|
|
2618
|
+
await db.updateTable("keel.flow_step").set({
|
|
2619
2619
|
status: "FAILED" /* FAILED */,
|
|
2620
2620
|
spanId,
|
|
2621
2621
|
endTime: /* @__PURE__ */ new Date(),
|
|
@@ -2624,7 +2624,7 @@ function createFlowContext(runId, data, spanId) {
|
|
|
2624
2624
|
if (failedSteps.length + 1 >= (options.maxRetries ?? defaultOpts.maxRetries)) {
|
|
2625
2625
|
throw new ExhuastedRetriesDisrupt();
|
|
2626
2626
|
}
|
|
2627
|
-
await db.insertInto("
|
|
2627
|
+
await db.insertInto("keel.flow_step").values({
|
|
2628
2628
|
run_id: runId,
|
|
2629
2629
|
name,
|
|
2630
2630
|
stage: options.stage,
|
|
@@ -2633,7 +2633,7 @@ function createFlowContext(runId, data, spanId) {
|
|
|
2633
2633
|
}).returningAll().executeTakeFirst();
|
|
2634
2634
|
throw new StepCreatedDisrupt();
|
|
2635
2635
|
}
|
|
2636
|
-
await db.updateTable("
|
|
2636
|
+
await db.updateTable("keel.flow_step").set({
|
|
2637
2637
|
status: "COMPLETED" /* COMPLETED */,
|
|
2638
2638
|
value: JSON.stringify(result),
|
|
2639
2639
|
spanId,
|
|
@@ -2641,7 +2641,7 @@ function createFlowContext(runId, data, spanId) {
|
|
|
2641
2641
|
}).where("id", "=", newSteps[0].id).returningAll().executeTakeFirst();
|
|
2642
2642
|
return result;
|
|
2643
2643
|
}
|
|
2644
|
-
await db.insertInto("
|
|
2644
|
+
await db.insertInto("keel.flow_step").values({
|
|
2645
2645
|
run_id: runId,
|
|
2646
2646
|
name,
|
|
2647
2647
|
stage: options.stage,
|
|
@@ -2653,12 +2653,12 @@ function createFlowContext(runId, data, spanId) {
|
|
|
2653
2653
|
ui: {
|
|
2654
2654
|
page: /* @__PURE__ */ __name(async (name, options) => {
|
|
2655
2655
|
const db = useDatabase();
|
|
2656
|
-
let step = await db.selectFrom("
|
|
2656
|
+
let step = await db.selectFrom("keel.flow_step").where("run_id", "=", runId).where("name", "=", name).selectAll().executeTakeFirst();
|
|
2657
2657
|
if (step && step.status === "COMPLETED" /* COMPLETED */) {
|
|
2658
2658
|
return step.value;
|
|
2659
2659
|
}
|
|
2660
2660
|
if (!step) {
|
|
2661
|
-
step = await db.insertInto("
|
|
2661
|
+
step = await db.insertInto("keel.flow_step").values({
|
|
2662
2662
|
run_id: runId,
|
|
2663
2663
|
name,
|
|
2664
2664
|
stage: options.stage,
|
|
@@ -2671,7 +2671,7 @@ function createFlowContext(runId, data, spanId) {
|
|
|
2671
2671
|
if (!data) {
|
|
2672
2672
|
throw new UIRenderDisrupt(step?.id, page(options));
|
|
2673
2673
|
}
|
|
2674
|
-
await db.updateTable("
|
|
2674
|
+
await db.updateTable("keel.flow_step").set({
|
|
2675
2675
|
status: "COMPLETED" /* COMPLETED */,
|
|
2676
2676
|
value: JSON.stringify(data),
|
|
2677
2677
|
spanId,
|
|
@@ -2747,7 +2747,7 @@ async function handleFlow(request, config) {
|
|
|
2747
2747
|
db = createDatabaseClient({
|
|
2748
2748
|
connString: request.meta?.secrets?.KEEL_DB_CONN
|
|
2749
2749
|
});
|
|
2750
|
-
const flowRun = await db.selectFrom("
|
|
2750
|
+
const flowRun = await db.selectFrom("keel.flow_run").where("id", "=", runId).selectAll().executeTakeFirst();
|
|
2751
2751
|
if (!flowRun) {
|
|
2752
2752
|
throw new Error("no flow run found");
|
|
2753
2753
|
}
|
|
@@ -2758,48 +2758,70 @@ async function handleFlow(request, config) {
|
|
|
2758
2758
|
);
|
|
2759
2759
|
const flowFunction = flows[request.method].fn;
|
|
2760
2760
|
flowConfig = flows[request.method].config;
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2761
|
+
const inputs = parseInputs(flowRun.input);
|
|
2762
|
+
try {
|
|
2763
|
+
await tryExecuteFlow(db, async () => {
|
|
2764
|
+
return flowFunction(ctx, inputs);
|
|
2765
|
+
});
|
|
2766
|
+
} catch (e) {
|
|
2767
|
+
if (e instanceof StepCreatedDisrupt) {
|
|
2768
|
+
return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, {
|
|
2769
|
+
runId,
|
|
2770
|
+
runCompleted: false,
|
|
2771
|
+
config: flowConfig
|
|
2772
|
+
});
|
|
2773
|
+
}
|
|
2774
|
+
if (e instanceof UIRenderDisrupt) {
|
|
2775
|
+
return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, {
|
|
2776
|
+
runId,
|
|
2777
|
+
stepId: e.stepId,
|
|
2778
|
+
config: flowConfig,
|
|
2779
|
+
ui: e.contents
|
|
2780
|
+
});
|
|
2781
|
+
}
|
|
2782
|
+
span.recordException(e);
|
|
2783
|
+
span.setStatus({
|
|
2784
|
+
code: opentelemetry6.SpanStatusCode.ERROR,
|
|
2785
|
+
message: e.message
|
|
2786
|
+
});
|
|
2787
|
+
if (e instanceof ExhuastedRetriesDisrupt) {
|
|
2788
|
+
return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, {
|
|
2789
|
+
runId,
|
|
2790
|
+
runCompleted: true,
|
|
2791
|
+
error: "flow failed due to exhausted step retries",
|
|
2792
|
+
config: flowConfig
|
|
2793
|
+
});
|
|
2794
|
+
}
|
|
2795
|
+
return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, {
|
|
2796
|
+
runId,
|
|
2797
|
+
runCompleted: true,
|
|
2798
|
+
error: e.message,
|
|
2799
|
+
config: flowConfig
|
|
2800
|
+
});
|
|
2801
|
+
}
|
|
2765
2802
|
return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, {
|
|
2766
2803
|
runId,
|
|
2767
2804
|
runCompleted: true,
|
|
2768
2805
|
config: flowConfig
|
|
2769
2806
|
});
|
|
2770
2807
|
} catch (e) {
|
|
2771
|
-
if (e instanceof
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
});
|
|
2777
|
-
}
|
|
2778
|
-
if (e instanceof UIRenderDisrupt) {
|
|
2779
|
-
return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, {
|
|
2780
|
-
runId,
|
|
2781
|
-
stepId: e.stepId,
|
|
2782
|
-
config: flowConfig,
|
|
2783
|
-
ui: e.contents
|
|
2808
|
+
if (e instanceof Error) {
|
|
2809
|
+
span.recordException(e);
|
|
2810
|
+
span.setStatus({
|
|
2811
|
+
code: opentelemetry6.SpanStatusCode.ERROR,
|
|
2812
|
+
message: e.message
|
|
2784
2813
|
});
|
|
2814
|
+
return errorToJSONRPCResponse(request, e);
|
|
2785
2815
|
}
|
|
2786
|
-
|
|
2816
|
+
const message = JSON.stringify(e);
|
|
2787
2817
|
span.setStatus({
|
|
2788
2818
|
code: opentelemetry6.SpanStatusCode.ERROR,
|
|
2789
|
-
message
|
|
2819
|
+
message
|
|
2790
2820
|
});
|
|
2791
|
-
if (e instanceof ExhuastedRetriesDisrupt) {
|
|
2792
|
-
return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, {
|
|
2793
|
-
runId,
|
|
2794
|
-
runCompleted: true,
|
|
2795
|
-
error: "flow failed due to exhausted step retries",
|
|
2796
|
-
config: flowConfig
|
|
2797
|
-
});
|
|
2798
|
-
}
|
|
2799
2821
|
return (0, import_json_rpc_26.createJSONRPCErrorResponse)(
|
|
2800
2822
|
request.id,
|
|
2801
|
-
|
|
2802
|
-
|
|
2823
|
+
RuntimeErrors.UnknownError,
|
|
2824
|
+
message
|
|
2803
2825
|
);
|
|
2804
2826
|
} finally {
|
|
2805
2827
|
if (db) {
|