@codemation/core 0.0.7 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -1
- package/dist/EngineExecutionLimitsPolicy-8MEFIYx1.d.cts +0 -160
- package/dist/EngineExecutionLimitsPolicy-BWAXW9D6.d.cts +0 -160
- package/dist/EngineExecutionLimitsPolicy-Bp8PS1Ss.d.cts +0 -159
- package/dist/EngineExecutionLimitsPolicy-CLxcN-D2.d.ts +0 -159
- package/dist/EngineExecutionLimitsPolicy-DZXuix51.d.ts +0 -160
- package/dist/EngineExecutionLimitsPolicy-Gfz6ngFd.d.ts +0 -160
- package/dist/EngineFactory-CBnntY3J.cjs +0 -3152
- package/dist/EngineFactory-CBnntY3J.cjs.map +0 -1
- package/dist/EngineFactory-Cwn3R2YA.js +0 -3087
- package/dist/EngineFactory-Cwn3R2YA.js.map +0 -1
- package/dist/EngineFactory-DWCnNocp.js +0 -3063
- package/dist/EngineFactory-DWCnNocp.js.map +0 -1
- package/dist/EngineFactory-DhPFou4p.cjs +0 -3188
- package/dist/EngineFactory-DhPFou4p.cjs.map +0 -1
- package/dist/EngineFactory-l_9xmBtv.cjs +0 -3190
- package/dist/EngineFactory-l_9xmBtv.cjs.map +0 -1
- package/dist/EngineFactory-w-aOWuqh.js +0 -3089
- package/dist/EngineFactory-w-aOWuqh.js.map +0 -1
- package/dist/InMemoryLiveWorkflowRepository-1J9MHN_I.js +0 -18
- package/dist/InMemoryLiveWorkflowRepository-1J9MHN_I.js.map +0 -1
- package/dist/InMemoryLiveWorkflowRepository-CULNqv96.d.ts +0 -1300
- package/dist/InMemoryLiveWorkflowRepository-D6eiiXxF.d.cts +0 -1168
- package/dist/InMemoryLiveWorkflowRepository-D7l8cjdZ.d.cts +0 -1130
- package/dist/InMemoryLiveWorkflowRepository-DL7LmC9S.d.ts +0 -1340
- package/dist/InMemoryLiveWorkflowRepository-jnv-OnOP.d.ts +0 -1300
- package/dist/InMemoryLiveWorkflowRepository-xny1_Z6i.cjs +0 -24
- package/dist/InMemoryLiveWorkflowRepository-xny1_Z6i.cjs.map +0 -1
- package/dist/InMemoryLiveWorkflowRepository-xr7b4kvi.d.ts +0 -1338
- package/dist/InMemoryWorkflowCatalog-BIdFpwbK.d.ts +0 -1205
- package/dist/InMemoryWorkflowCatalog-BW00_3N3.d.cts +0 -12
- package/dist/InMemoryWorkflowCatalog-BiYHGoPw.cjs +0 -24
- package/dist/InMemoryWorkflowCatalog-BiYHGoPw.cjs.map +0 -1
- package/dist/InMemoryWorkflowCatalog-BrG0ApMO.d.cts +0 -1115
- package/dist/InMemoryWorkflowCatalog-BzrAr--Y.js +0 -139
- package/dist/InMemoryWorkflowCatalog-BzrAr--Y.js.map +0 -1
- package/dist/InMemoryWorkflowCatalog-C-EJlJ7y.d.cts +0 -1120
- package/dist/InMemoryWorkflowCatalog-C4482bpw.cjs +0 -24
- package/dist/InMemoryWorkflowCatalog-C4482bpw.cjs.map +0 -1
- package/dist/InMemoryWorkflowCatalog-CZ0kZpOv.d.ts +0 -1289
- package/dist/InMemoryWorkflowCatalog-C_ACeLyW.d.cts +0 -1119
- package/dist/InMemoryWorkflowCatalog-CiHWIu5E.d.cts +0 -12
- package/dist/InMemoryWorkflowCatalog-CkH7gkya.js +0 -18
- package/dist/InMemoryWorkflowCatalog-CkH7gkya.js.map +0 -1
- package/dist/InMemoryWorkflowCatalog-CnpZVJM9.d.ts +0 -1205
- package/dist/InMemoryWorkflowCatalog-Cu68S8YR.js +0 -18
- package/dist/InMemoryWorkflowCatalog-Cu68S8YR.js.map +0 -1
- package/dist/InMemoryWorkflowCatalog-D2w9nMj2.cjs +0 -151
- package/dist/InMemoryWorkflowCatalog-D2w9nMj2.cjs.map +0 -1
- package/dist/InMemoryWorkflowCatalog-D5eMxEf7.js +0 -18
- package/dist/InMemoryWorkflowCatalog-D5eMxEf7.js.map +0 -1
- package/dist/InMemoryWorkflowCatalog-D5nCp2yZ.d.ts +0 -1267
- package/dist/InMemoryWorkflowCatalog-DIq0bjqN.d.ts +0 -12
- package/dist/InMemoryWorkflowCatalog-DLgaEaw_.d.ts +0 -1288
- package/dist/InMemoryWorkflowCatalog-DNBFdK-x.d.cts +0 -1120
- package/dist/InMemoryWorkflowCatalog-DQBkCzb7.cjs +0 -24
- package/dist/InMemoryWorkflowCatalog-DQBkCzb7.cjs.map +0 -1
- package/dist/InMemoryWorkflowCatalog-DS4-eX6i.d.cts +0 -1118
- package/dist/InMemoryWorkflowCatalog-DdVfy8MY.d.ts +0 -12
- package/dist/InMemoryWorkflowCatalog-DeVZu3g8.d.ts +0 -12
- package/dist/InMemoryWorkflowCatalog-GxkQjvt5.d.ts +0 -1200
- package/dist/InMemoryWorkflowCatalog-qaVRn1Lc.d.cts +0 -1115
- package/dist/InMemoryWorkflowCatalog-z1aIT4TC.d.cts +0 -12
- package/dist/InMemoryWorkflowRegistry-BBuOovLL.d.ts +0 -1007
- package/dist/InMemoryWorkflowRegistry-BIFnSl3k.d.ts +0 -1201
- package/dist/InMemoryWorkflowRegistry-BnGilthz.d.ts +0 -1137
- package/dist/InMemoryWorkflowRegistry-CEp5I8No.d.ts +0 -1146
- package/dist/InMemoryWorkflowRegistry-CHyMB9jW.d.cts +0 -976
- package/dist/InMemoryWorkflowRegistry-CUN7K86m.d.cts +0 -1061
- package/dist/InMemoryWorkflowRegistry-CVfHyELh.d.cts +0 -971
- package/dist/InMemoryWorkflowRegistry-CXXJrwAr.d.cts +0 -1052
- package/dist/InMemoryWorkflowRegistry-DDGfPTJy.d.ts +0 -1013
- package/dist/InMemoryWorkflowRegistry-DnYSOoT5.d.ts +0 -1120
- package/dist/InMemoryWorkflowRegistry-Dp5GiFF2.d.cts +0 -1035
- package/dist/InMemoryWorkflowRegistry-DypDBeOw.d.cts +0 -1116
- package/dist/InMemoryWorkflowRegistry-SzwJCAxT.d.ts +0 -1012
- package/dist/InMemoryWorkflowRegistry-jupvqyGc.d.cts +0 -977
- package/dist/InMemoryWorkflowRegistry-rAdKVWYT.d.ts +0 -1117
- package/dist/InProcessRetryRunner-BBNPkXjy.d.cts +0 -292
- package/dist/PersistedWorkflowSnapshotFactory-7RkOL3Kg.d.ts +0 -14
- package/dist/PersistedWorkflowSnapshotFactory-BmANa46W.cjs +0 -141
- package/dist/PersistedWorkflowSnapshotFactory-BmANa46W.cjs.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-Bwb_etSt.js +0 -118
- package/dist/PersistedWorkflowSnapshotFactory-Bwb_etSt.js.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-CRkKGNV6.js +0 -123
- package/dist/PersistedWorkflowSnapshotFactory-CRkKGNV6.js.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-CZolnGy5.js +0 -101
- package/dist/PersistedWorkflowSnapshotFactory-CZolnGy5.js.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-Ca_oysOv.cjs +0 -131
- package/dist/PersistedWorkflowSnapshotFactory-Ca_oysOv.cjs.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-CqIcShnX.js +0 -103
- package/dist/PersistedWorkflowSnapshotFactory-CqIcShnX.js.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-D-tBk4_G.js +0 -119
- package/dist/PersistedWorkflowSnapshotFactory-D-tBk4_G.js.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-D4cXl2e2.cjs +0 -131
- package/dist/PersistedWorkflowSnapshotFactory-D4cXl2e2.cjs.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-DINoP12r.cjs +0 -131
- package/dist/PersistedWorkflowSnapshotFactory-DINoP12r.cjs.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-DJAwSuHU.js +0 -103
- package/dist/PersistedWorkflowSnapshotFactory-DJAwSuHU.js.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-DSUjVCcf.cjs +0 -131
- package/dist/PersistedWorkflowSnapshotFactory-DSUjVCcf.cjs.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-DdHuhkDb.cjs +0 -107
- package/dist/PersistedWorkflowSnapshotFactory-DdHuhkDb.cjs.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-Dqc6NHis.js +0 -119
- package/dist/PersistedWorkflowSnapshotFactory-Dqc6NHis.js.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-Dxa2dSrw.cjs +0 -130
- package/dist/PersistedWorkflowSnapshotFactory-Dxa2dSrw.cjs.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-Ep79Ah1G.js +0 -123
- package/dist/PersistedWorkflowSnapshotFactory-Ep79Ah1G.js.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-GyLfRuiJ.js +0 -119
- package/dist/PersistedWorkflowSnapshotFactory-GyLfRuiJ.js.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-HTpBsBzn.js +0 -102
- package/dist/PersistedWorkflowSnapshotFactory-HTpBsBzn.js.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-LVmaaf3t.cjs +0 -141
- package/dist/PersistedWorkflowSnapshotFactory-LVmaaf3t.cjs.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-PZCpo2ZS.js +0 -119
- package/dist/PersistedWorkflowSnapshotFactory-PZCpo2ZS.js.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-UjQ1SJev.cjs +0 -109
- package/dist/PersistedWorkflowSnapshotFactory-UjQ1SJev.cjs.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-Y8kCrhcy.cjs +0 -109
- package/dist/PersistedWorkflowSnapshotFactory-Y8kCrhcy.cjs.map +0 -1
- package/dist/PersistedWorkflowSnapshotFactory-Z_nB-fmB.cjs +0 -108
- package/dist/PersistedWorkflowSnapshotFactory-Z_nB-fmB.cjs.map +0 -1
- package/dist/RunIntentService-1EE6N8ZL.cjs +0 -963
- package/dist/RunIntentService-1EE6N8ZL.cjs.map +0 -1
- package/dist/RunIntentService-2ivFmNQh.cjs +0 -3462
- package/dist/RunIntentService-2ivFmNQh.cjs.map +0 -1
- package/dist/RunIntentService-B0sUL5q-.js +0 -761
- package/dist/RunIntentService-B0sUL5q-.js.map +0 -1
- package/dist/RunIntentService-BFVbsOcg.js +0 -3131
- package/dist/RunIntentService-BFVbsOcg.js.map +0 -1
- package/dist/RunIntentService-BsBOwpVN.cjs +0 -1051
- package/dist/RunIntentService-BsBOwpVN.cjs.map +0 -1
- package/dist/RunIntentService-CSk3ETyn.js +0 -858
- package/dist/RunIntentService-CSk3ETyn.js.map +0 -1
- package/dist/RunIntentService-Ckn3u3tA.d.cts +0 -326
- package/dist/RunIntentService-DEo6GTTo.d.cts +0 -289
- package/dist/RunIntentService-DKrGtL0B.js +0 -782
- package/dist/RunIntentService-DKrGtL0B.js.map +0 -1
- package/dist/RunIntentService-DNOJc1R7.cjs +0 -942
- package/dist/RunIntentService-DNOJc1R7.cjs.map +0 -1
- package/dist/RunIntentService-Dq3pV53j.d.cts +0 -289
- package/dist/RunIntentService-NKobsfMQ.d.cts +0 -274
- package/dist/WorkflowSnapshotCodec-C3fuuS_R.d.cts +0 -22
- package/dist/WorkflowSnapshotCodec-CUudUo6f.js +0 -123
- package/dist/WorkflowSnapshotCodec-CUudUo6f.js.map +0 -1
- package/dist/WorkflowSnapshotCodec-CuCPQZTc.cjs +0 -129
- package/dist/WorkflowSnapshotCodec-CuCPQZTc.cjs.map +0 -1
- package/dist/WorkflowSnapshotCodec-DLiXQNvV.d.cts +0 -22
- package/dist/WorkflowSnapshotCodec-DNtdrZ7l.d.cts +0 -22
- package/dist/WorkflowSnapshotCodec-DTdWkoW_.d.cts +0 -22
- package/dist/credentialTypes-B5h3dI7r.d.cts +0 -1107
- package/dist/credentialTypes-B9okPCVo.d.cts +0 -963
- package/dist/credentialTypes-BFL70rgZ.d.cts +0 -964
- package/dist/credentialTypes-BGkh1O07.d.ts +0 -1010
- package/dist/credentialTypes-BNLi4Q7u.d.ts +0 -1030
- package/dist/credentialTypes-CeSoZGj3.d.cts +0 -994
- package/dist/credentialTypes-CpHc32Ig.d.cts +0 -984
- package/dist/credentialTypes-D0m7MQQl.d.cts +0 -1107
- package/dist/credentialTypes-D4nL2sUd.d.ts +0 -1000
- package/dist/credentialTypes-DBYK2Qbu.d.ts +0 -999
- package/dist/credentialTypes-DMJVy0r1.d.ts +0 -1000
- package/dist/credentialTypes-DhUAjYQp.d.ts +0 -1020
- package/dist/credentialTypes-gGITj5KL.d.cts +0 -964
- package/dist/credentialTypes-r3KVBJBE.d.cts +0 -974
- package/dist/diTokens-ClO27tjK.cjs +0 -34
- package/dist/diTokens-ClO27tjK.cjs.map +0 -1
- package/dist/diTokens-CoHBkwG6.js +0 -28
- package/dist/diTokens-CoHBkwG6.js.map +0 -1
- package/dist/index-6Doxmfnd.d.ts +0 -857
- package/dist/index-9g6Pfe9Z.d.ts +0 -689
- package/dist/index-AZ72Ej-K.d.ts +0 -920
- package/dist/index-BEk9V-q-.d.ts +0 -667
- package/dist/index-Bjt7_7oS.d.ts +0 -1192
- package/dist/index-CFGxsYXy.d.ts +0 -708
- package/dist/index-C_u8xFgn.d.ts +0 -690
- package/dist/index-CpbfsvOJ.d.ts +0 -1192
- package/dist/index-CsReNJN_.d.ts +0 -859
- package/dist/index-D5iNnXaW.d.ts +0 -667
- package/dist/index-DD_Eft1q.d.ts +0 -708
- package/dist/index-DiSYUe0G.d.ts +0 -1192
- package/dist/index-gIcH60sp.d.ts +0 -674
- package/dist/runtime-BIvd-1JA.cjs +0 -4112
- package/dist/runtime-BIvd-1JA.cjs.map +0 -1
- package/dist/runtime-D3eWKSQK.cjs +0 -3986
- package/dist/runtime-D3eWKSQK.cjs.map +0 -1
- package/dist/runtime-Dvp4xAjg.js +0 -3799
- package/dist/runtime-Dvp4xAjg.js.map +0 -1
- package/dist/runtime-vc76SSAa.js +0 -3685
- package/dist/runtime-vc76SSAa.js.map +0 -1
- package/dist/runtimeTypes-BK0b8SaG.d.cts +0 -884
- package/dist/runtimeTypes-CoYZkYQq.d.cts +0 -851
- package/dist/runtimeTypes-D-Pm0Uas.d.cts +0 -849
- package/dist/types-Cb5UK7Y6.d.ts +0 -857
|
@@ -1,3986 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
const require_InMemoryWorkflowCatalog = require('./InMemoryWorkflowCatalog-D2w9nMj2.cjs');
|
|
25
|
-
let node_crypto = require("node:crypto");
|
|
26
|
-
node_crypto = __toESM(node_crypto);
|
|
27
|
-
require("reflect-metadata");
|
|
28
|
-
let tsyringe = require("tsyringe");
|
|
29
|
-
tsyringe = __toESM(tsyringe);
|
|
30
|
-
let node_stream_web = require("node:stream/web");
|
|
31
|
-
node_stream_web = __toESM(node_stream_web);
|
|
32
|
-
|
|
33
|
-
//#region src/workflow/definition/ConnectionNodeIdFactory.ts
|
|
34
|
-
/**
|
|
35
|
-
* Deterministic ids for workflow connection-owned child nodes (LLM slot, tools, etc.).
|
|
36
|
-
* These are stable across loads.
|
|
37
|
-
*/
|
|
38
|
-
var ConnectionNodeIdFactory = class {
|
|
39
|
-
static connectionSegment = "__conn__";
|
|
40
|
-
static languageModelConnectionNodeId(parentNodeId) {
|
|
41
|
-
return `${parentNodeId}${this.connectionSegment}llm`;
|
|
42
|
-
}
|
|
43
|
-
static toolConnectionNodeId(parentNodeId, toolName) {
|
|
44
|
-
const normalized = this.normalizeToolName(toolName);
|
|
45
|
-
return `${parentNodeId}${this.connectionSegment}tool${this.connectionSegment}${normalized}`;
|
|
46
|
-
}
|
|
47
|
-
static isLanguageModelConnectionNodeId(nodeId) {
|
|
48
|
-
return nodeId.endsWith(`${this.connectionSegment}llm`);
|
|
49
|
-
}
|
|
50
|
-
static isToolConnectionNodeId(nodeId) {
|
|
51
|
-
return nodeId.includes(`${this.connectionSegment}tool${this.connectionSegment}`);
|
|
52
|
-
}
|
|
53
|
-
/** True when `nodeId` is a connection-owned child of `parentNodeId` (LLM or tool slot). */
|
|
54
|
-
static isConnectionOwnedDescendantOf(parentNodeId, nodeId) {
|
|
55
|
-
return nodeId.startsWith(`${parentNodeId}${this.connectionSegment}`);
|
|
56
|
-
}
|
|
57
|
-
/** Normalizes a tool display name to a stable id segment. */
|
|
58
|
-
static normalizeToolName(toolName) {
|
|
59
|
-
return toolName.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "") || "tool";
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
//#endregion
|
|
64
|
-
//#region src/workflow/definition/WorkflowExecutableNodeClassifier.ts
|
|
65
|
-
/**
|
|
66
|
-
* Derives which workflow nodes participate in the main execution graph vs connection-only children.
|
|
67
|
-
*/
|
|
68
|
-
var WorkflowExecutableNodeClassifier = class {
|
|
69
|
-
connectionOwnedIds;
|
|
70
|
-
constructor(workflow) {
|
|
71
|
-
this.connectionOwnedIds = this.collectConnectionOwnedIds(workflow);
|
|
72
|
-
}
|
|
73
|
-
isConnectionOwnedNodeId(nodeId) {
|
|
74
|
-
return this.connectionOwnedIds.has(nodeId);
|
|
75
|
-
}
|
|
76
|
-
isExecutableNodeId(nodeId) {
|
|
77
|
-
return !this.connectionOwnedIds.has(nodeId);
|
|
78
|
-
}
|
|
79
|
-
filterExecutableNodeDefinitions(nodes) {
|
|
80
|
-
return nodes.filter((n) => this.isExecutableNodeId(n.id));
|
|
81
|
-
}
|
|
82
|
-
collectConnectionOwnedIds(workflow) {
|
|
83
|
-
const ids = /* @__PURE__ */ new Set();
|
|
84
|
-
for (const connection of workflow.connections ?? []) for (const childId of connection.childNodeIds) ids.add(childId);
|
|
85
|
-
return ids;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Resolves the default start node: first trigger, else first executable node with no incoming edges from executable nodes.
|
|
89
|
-
*/
|
|
90
|
-
findDefaultExecutableStartNodeId(workflow) {
|
|
91
|
-
const firstTrigger = workflow.nodes.find((n) => n.kind === "trigger" && this.isExecutableNodeId(n.id))?.id;
|
|
92
|
-
if (firstTrigger) return firstTrigger;
|
|
93
|
-
const incoming = /* @__PURE__ */ new Map();
|
|
94
|
-
for (const n of workflow.nodes) if (this.isExecutableNodeId(n.id)) incoming.set(n.id, 0);
|
|
95
|
-
for (const e of workflow.edges) {
|
|
96
|
-
if (!this.isExecutableNodeId(e.from.nodeId) || !this.isExecutableNodeId(e.to.nodeId)) continue;
|
|
97
|
-
incoming.set(e.to.nodeId, (incoming.get(e.to.nodeId) ?? 0) + 1);
|
|
98
|
-
}
|
|
99
|
-
return workflow.nodes.find((n) => this.isExecutableNodeId(n.id) && (incoming.get(n.id) ?? 0) === 0)?.id ?? workflow.nodes.find((n) => this.isExecutableNodeId(n.id))?.id ?? (() => {
|
|
100
|
-
throw new Error(`Workflow ${workflow.id} has no executable nodes`);
|
|
101
|
-
})();
|
|
102
|
-
}
|
|
103
|
-
firstExecutableNodeIdInDefinitionOrder(workflow) {
|
|
104
|
-
return workflow.nodes.find((n) => this.isExecutableNodeId(n.id))?.id;
|
|
105
|
-
}
|
|
106
|
-
lastExecutableNodeIdInDefinitionOrder(workflow) {
|
|
107
|
-
for (let i = workflow.nodes.length - 1; i >= 0; i--) {
|
|
108
|
-
const n = workflow.nodes[i];
|
|
109
|
-
if (this.isExecutableNodeId(n.id)) return n.id;
|
|
110
|
-
}
|
|
111
|
-
throw new Error(`Workflow ${workflow.id} has no executable nodes`);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
//#endregion
|
|
116
|
-
//#region src/workflow/definition/WorkflowExecutableNodeClassifierFactory.ts
|
|
117
|
-
function createWorkflowExecutableNodeClassifier(workflow) {
|
|
118
|
-
return new WorkflowExecutableNodeClassifier(workflow);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
//#endregion
|
|
122
|
-
//#region src/diTokens/index.ts
|
|
123
|
-
const CoreTokens = {
|
|
124
|
-
PersistedWorkflowTokenRegistry: Symbol.for("codemation.core.PersistedWorkflowTokenRegistry"),
|
|
125
|
-
CredentialSessionService: Symbol.for("codemation.core.CredentialSessionService"),
|
|
126
|
-
CredentialTypeRegistry: Symbol.for("codemation.core.CredentialTypeRegistry"),
|
|
127
|
-
WorkflowRunnerService: Symbol.for("codemation.core.WorkflowRunnerService"),
|
|
128
|
-
WorkflowCatalog: Symbol.for("codemation.core.WorkflowCatalog"),
|
|
129
|
-
WorkflowRepository: Symbol.for("codemation.core.WorkflowRepository"),
|
|
130
|
-
ServiceContainer: Symbol.for("codemation.core.ServiceContainer"),
|
|
131
|
-
NodeResolver: Symbol.for("codemation.core.NodeResolver"),
|
|
132
|
-
WorkflowNodeInstanceFactory: Symbol.for("codemation.core.WorkflowNodeInstanceFactory"),
|
|
133
|
-
RunIdFactory: Symbol.for("codemation.core.RunIdFactory"),
|
|
134
|
-
ActivationIdFactory: Symbol.for("codemation.core.ActivationIdFactory"),
|
|
135
|
-
RunStateStore: Symbol.for("codemation.core.RunStateStore"),
|
|
136
|
-
TriggerSetupStateStore: Symbol.for("codemation.core.TriggerSetupStateStore"),
|
|
137
|
-
NodeActivationScheduler: Symbol.for("codemation.core.NodeActivationScheduler"),
|
|
138
|
-
RunDataFactory: Symbol.for("codemation.core.RunDataFactory"),
|
|
139
|
-
ExecutionContextFactory: Symbol.for("codemation.core.ExecutionContextFactory"),
|
|
140
|
-
RunEventBus: Symbol.for("codemation.core.RunEventBus"),
|
|
141
|
-
BinaryStorage: Symbol.for("codemation.core.BinaryStorage"),
|
|
142
|
-
WebhookBasePath: Symbol.for("codemation.core.WebhookBasePath"),
|
|
143
|
-
EngineExecutionLimitsPolicy: Symbol.for("codemation.core.EngineExecutionLimitsPolicy"),
|
|
144
|
-
WorkflowActivationPolicy: Symbol.for("codemation.core.WorkflowActivationPolicy")
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
//#endregion
|
|
148
|
-
//#region src/events/NodeEventPublisher.ts
|
|
149
|
-
/** Publishes node lifecycle snapshots onto the run {@link RunEventBus}. */
|
|
150
|
-
var NodeEventPublisher = class {
|
|
151
|
-
constructor(eventBus) {
|
|
152
|
-
this.eventBus = eventBus;
|
|
153
|
-
}
|
|
154
|
-
async publish(kind, snapshot) {
|
|
155
|
-
if (!this.eventBus) return;
|
|
156
|
-
await this.eventBus.publish({
|
|
157
|
-
kind,
|
|
158
|
-
runId: snapshot.runId,
|
|
159
|
-
workflowId: snapshot.workflowId,
|
|
160
|
-
parent: snapshot.parent,
|
|
161
|
-
at: snapshot.updatedAt,
|
|
162
|
-
snapshot
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
//#endregion
|
|
168
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/decorate.js
|
|
169
|
-
function __decorate(decorators, target, key, desc) {
|
|
170
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
171
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
172
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
173
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
//#endregion
|
|
177
|
-
//#region src/runtime-types/persistedRuntimeTypeModelRegistry.ts
|
|
178
|
-
const persistedRuntimeTypeMetadataKey = Symbol.for("codemation.core.persistedRuntimeTypeMetadata");
|
|
179
|
-
var PersistedRuntimeTypeDecoratorDefaults = class {
|
|
180
|
-
static appPackageName = "app";
|
|
181
|
-
static apply(options) {
|
|
182
|
-
return {
|
|
183
|
-
...options,
|
|
184
|
-
packageName: options.packageName ?? this.appPackageName
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
//#endregion
|
|
190
|
-
//#region src/runtime-types/PersistedRuntimeTypeNameResolver.ts
|
|
191
|
-
var PersistedRuntimeTypeNameResolver = class {
|
|
192
|
-
static resolve(target, override) {
|
|
193
|
-
const resolved = override ?? target.name;
|
|
194
|
-
if (!resolved) throw new Error("Persisted runtime token metadata requires a named class or an explicit decorator name override.");
|
|
195
|
-
return resolved;
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
//#endregion
|
|
200
|
-
//#region src/runtime-types/StackTraceCallSitePathResolver.ts
|
|
201
|
-
var StackTraceCallSitePathResolver = class {
|
|
202
|
-
static resolve(decoratorFileUrl) {
|
|
203
|
-
const stack = (/* @__PURE__ */ new Error()).stack ?? "";
|
|
204
|
-
for (const line of stack.split("\n")) {
|
|
205
|
-
const candidate = this.extractPath(line.trim());
|
|
206
|
-
if (!candidate) continue;
|
|
207
|
-
if (candidate === decoratorFileUrl || candidate.includes("runtimeTypeDecorators")) continue;
|
|
208
|
-
return candidate;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
static extractPath(line) {
|
|
212
|
-
const fileUrlMatch = line.match(/file:\/\/[^\s)]+/);
|
|
213
|
-
if (fileUrlMatch) return fileUrlMatch[0];
|
|
214
|
-
const parenMatch = line.match(/\((\/[^)]+)\)/);
|
|
215
|
-
if (parenMatch) return parenMatch[1];
|
|
216
|
-
return line.match(/at (\/[^\s]+)/)?.[1];
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
//#endregion
|
|
221
|
-
//#region src/runtime-types/PersistedRuntimeTypeMetadataStoreRegistry.ts
|
|
222
|
-
var PersistedRuntimeTypeMetadataStore = class {
|
|
223
|
-
static define(target, kind, options, decoratorFileUrl) {
|
|
224
|
-
const normalizedOptions = PersistedRuntimeTypeDecoratorDefaults.apply(options);
|
|
225
|
-
const metadata = {
|
|
226
|
-
persistedName: PersistedRuntimeTypeNameResolver.resolve(target, normalizedOptions.name),
|
|
227
|
-
kind,
|
|
228
|
-
packageName: normalizedOptions.packageName ?? PersistedRuntimeTypeDecoratorDefaults.appPackageName,
|
|
229
|
-
sourceHint: normalizedOptions.moduleUrl ?? StackTraceCallSitePathResolver.resolve(decoratorFileUrl)
|
|
230
|
-
};
|
|
231
|
-
Object.defineProperty(target, persistedRuntimeTypeMetadataKey, {
|
|
232
|
-
configurable: false,
|
|
233
|
-
enumerable: false,
|
|
234
|
-
writable: false,
|
|
235
|
-
value: metadata
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
static get(target) {
|
|
239
|
-
if (!target || typeof target !== "function" && typeof target !== "object") return;
|
|
240
|
-
return target[persistedRuntimeTypeMetadataKey];
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
//#endregion
|
|
245
|
-
//#region src/runtime-types/InjectableRuntimeDecoratorComposerRegistry.ts
|
|
246
|
-
var InjectableRuntimeDecoratorComposer = class {
|
|
247
|
-
static compose(kind, options, decoratorFileUrl) {
|
|
248
|
-
return (target) => {
|
|
249
|
-
(0, tsyringe.injectable)()(target);
|
|
250
|
-
PersistedRuntimeTypeMetadataStore.define(target, kind, options, decoratorFileUrl);
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
//#endregion
|
|
256
|
-
//#region src/runtime-types/runtimeTypeDecorators.types.ts
|
|
257
|
-
function getPersistedRuntimeTypeMetadata(target) {
|
|
258
|
-
return PersistedRuntimeTypeMetadataStore.get(target);
|
|
259
|
-
}
|
|
260
|
-
function node(options = {}) {
|
|
261
|
-
return InjectableRuntimeDecoratorComposer.compose("node", options, require("url").pathToFileURL(__filename).href);
|
|
262
|
-
}
|
|
263
|
-
function tool(options = {}) {
|
|
264
|
-
return InjectableRuntimeDecoratorComposer.compose("tool", options, require("url").pathToFileURL(__filename).href);
|
|
265
|
-
}
|
|
266
|
-
function chatModel(options = {}) {
|
|
267
|
-
return InjectableRuntimeDecoratorComposer.compose("chatModel", options, require("url").pathToFileURL(__filename).href);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
//#endregion
|
|
271
|
-
//#region src/binaries/DefaultNodeBinaryAttachmentServiceFactory.ts
|
|
272
|
-
var DefaultNodeBinaryAttachmentService = class DefaultNodeBinaryAttachmentService {
|
|
273
|
-
constructor(storage, workflowId, runId, nodeId, activationId, now) {
|
|
274
|
-
this.storage = storage;
|
|
275
|
-
this.workflowId = workflowId;
|
|
276
|
-
this.runId = runId;
|
|
277
|
-
this.nodeId = nodeId;
|
|
278
|
-
this.activationId = activationId;
|
|
279
|
-
this.now = now;
|
|
280
|
-
}
|
|
281
|
-
async attach(args) {
|
|
282
|
-
const attachmentId = this.createAttachmentId();
|
|
283
|
-
const createdAt = this.now().toISOString();
|
|
284
|
-
const storageKey = this.createStorageKey(args, attachmentId);
|
|
285
|
-
const stored = await this.storage.write({
|
|
286
|
-
storageKey,
|
|
287
|
-
body: args.body
|
|
288
|
-
});
|
|
289
|
-
return {
|
|
290
|
-
id: attachmentId,
|
|
291
|
-
storageKey: stored.storageKey,
|
|
292
|
-
mimeType: args.mimeType,
|
|
293
|
-
size: stored.size,
|
|
294
|
-
storageDriver: this.storage.driverName,
|
|
295
|
-
previewKind: args.previewKind ?? this.resolvePreviewKind(args.mimeType),
|
|
296
|
-
createdAt,
|
|
297
|
-
runId: this.runId,
|
|
298
|
-
workflowId: this.workflowId,
|
|
299
|
-
nodeId: this.nodeId,
|
|
300
|
-
activationId: this.activationId,
|
|
301
|
-
filename: args.filename,
|
|
302
|
-
sha256: stored.sha256
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
withAttachment(item, name, attachment) {
|
|
306
|
-
return {
|
|
307
|
-
...item,
|
|
308
|
-
binary: {
|
|
309
|
-
...item.binary ?? {},
|
|
310
|
-
[name]: attachment
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
forNode(args) {
|
|
315
|
-
return new DefaultNodeBinaryAttachmentService(this.storage, this.workflowId, this.runId, args.nodeId, args.activationId, this.now);
|
|
316
|
-
}
|
|
317
|
-
async openReadStream(attachment) {
|
|
318
|
-
return await this.storage.openReadStream(attachment.storageKey);
|
|
319
|
-
}
|
|
320
|
-
createAttachmentId() {
|
|
321
|
-
return DefaultNodeBinaryAttachmentService.createAttachmentIdValue(`${this.activationId}-${this.now().getTime()}`);
|
|
322
|
-
}
|
|
323
|
-
static createAttachmentIdValue(fallbackValue) {
|
|
324
|
-
const cryptoObject = globalThis.crypto;
|
|
325
|
-
if (cryptoObject && typeof cryptoObject.randomUUID === "function") return cryptoObject.randomUUID();
|
|
326
|
-
return fallbackValue;
|
|
327
|
-
}
|
|
328
|
-
createStorageKey(args, attachmentId) {
|
|
329
|
-
const safeName = this.sanitizeSegment(args.name);
|
|
330
|
-
const safeFilename = this.sanitizeFilename(args.filename);
|
|
331
|
-
const filenameSuffix = safeFilename ? `-${safeFilename}` : "";
|
|
332
|
-
return `${this.sanitizeSegment(this.workflowId)}/${this.sanitizeSegment(this.runId)}/${this.sanitizeSegment(this.nodeId)}/${this.sanitizeSegment(this.activationId)}/${attachmentId}-${safeName}${filenameSuffix}`;
|
|
333
|
-
}
|
|
334
|
-
sanitizeSegment(value) {
|
|
335
|
-
const normalized = value.trim();
|
|
336
|
-
if (!normalized) return "item";
|
|
337
|
-
return normalized.replace(/[^a-zA-Z0-9._-]+/g, "_");
|
|
338
|
-
}
|
|
339
|
-
sanitizeFilename(value) {
|
|
340
|
-
if (!value) return;
|
|
341
|
-
const normalized = value.trim().split("/").at(-1)?.split("\\").at(-1) ?? value.trim();
|
|
342
|
-
if (!normalized) return;
|
|
343
|
-
return normalized.replace(/[^a-zA-Z0-9._-]+/g, "_");
|
|
344
|
-
}
|
|
345
|
-
resolvePreviewKind(mimeType) {
|
|
346
|
-
if (mimeType.startsWith("image/")) return "image";
|
|
347
|
-
if (mimeType.startsWith("audio/")) return "audio";
|
|
348
|
-
if (mimeType.startsWith("video/")) return "video";
|
|
349
|
-
return "download";
|
|
350
|
-
}
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
//#endregion
|
|
354
|
-
//#region src/binaries/UnavailableBinaryStorage.ts
|
|
355
|
-
var UnavailableBinaryStorage = class {
|
|
356
|
-
driverName = "unavailable";
|
|
357
|
-
async write() {
|
|
358
|
-
throw new Error("Binary storage is not configured for this runtime.");
|
|
359
|
-
}
|
|
360
|
-
async openReadStream() {}
|
|
361
|
-
async stat() {
|
|
362
|
-
return { exists: false };
|
|
363
|
-
}
|
|
364
|
-
async delete() {}
|
|
365
|
-
};
|
|
366
|
-
|
|
367
|
-
//#endregion
|
|
368
|
-
//#region src/binaries/DefaultExecutionBinaryServiceFactory.ts
|
|
369
|
-
var DefaultExecutionBinaryService = class {
|
|
370
|
-
constructor(storage, workflowId, runId, now) {
|
|
371
|
-
this.storage = storage;
|
|
372
|
-
this.workflowId = workflowId;
|
|
373
|
-
this.runId = runId;
|
|
374
|
-
this.now = now;
|
|
375
|
-
}
|
|
376
|
-
forNode(args) {
|
|
377
|
-
return new DefaultNodeBinaryAttachmentService(this.storage, this.workflowId, this.runId, args.nodeId, args.activationId, this.now);
|
|
378
|
-
}
|
|
379
|
-
async openReadStream(attachment) {
|
|
380
|
-
return await this.storage.openReadStream(attachment.storageKey);
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
//#endregion
|
|
385
|
-
//#region src/observability/InputPortMapFactory.ts
|
|
386
|
-
var InputPortMap = class {
|
|
387
|
-
static empty() {
|
|
388
|
-
return {};
|
|
389
|
-
}
|
|
390
|
-
static fromRequest(request) {
|
|
391
|
-
if (request.kind === "multi") return request.inputsByPort;
|
|
392
|
-
return { in: request.input };
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
|
|
396
|
-
//#endregion
|
|
397
|
-
//#region src/observability/NodeSnapshotFactory.ts
|
|
398
|
-
var NodeSnapshotFactory = class {
|
|
399
|
-
static queued(args) {
|
|
400
|
-
return {
|
|
401
|
-
runId: args.runId,
|
|
402
|
-
workflowId: args.workflowId,
|
|
403
|
-
nodeId: args.nodeId,
|
|
404
|
-
activationId: args.activationId,
|
|
405
|
-
parent: args.parent,
|
|
406
|
-
status: "queued",
|
|
407
|
-
queuedAt: args.queuedAt,
|
|
408
|
-
updatedAt: args.queuedAt,
|
|
409
|
-
inputsByPort: args.inputsByPort
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
static running(args) {
|
|
413
|
-
return {
|
|
414
|
-
runId: args.runId,
|
|
415
|
-
workflowId: args.workflowId,
|
|
416
|
-
nodeId: args.nodeId,
|
|
417
|
-
activationId: args.activationId,
|
|
418
|
-
parent: args.parent,
|
|
419
|
-
status: "running",
|
|
420
|
-
queuedAt: args.previous?.queuedAt,
|
|
421
|
-
startedAt: args.startedAt,
|
|
422
|
-
updatedAt: args.startedAt,
|
|
423
|
-
inputsByPort: args.inputsByPort,
|
|
424
|
-
outputs: args.previous?.outputs,
|
|
425
|
-
error: void 0
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
static completed(args) {
|
|
429
|
-
const fromPinnedOutput = args.fromPinnedOutput ?? false;
|
|
430
|
-
const startedAt = fromPinnedOutput ? args.previous?.startedAt ?? args.finishedAt : args.previous?.startedAt;
|
|
431
|
-
return {
|
|
432
|
-
runId: args.runId,
|
|
433
|
-
workflowId: args.workflowId,
|
|
434
|
-
nodeId: args.nodeId,
|
|
435
|
-
activationId: args.activationId,
|
|
436
|
-
parent: args.parent,
|
|
437
|
-
status: "completed",
|
|
438
|
-
queuedAt: args.previous?.queuedAt,
|
|
439
|
-
startedAt,
|
|
440
|
-
finishedAt: args.finishedAt,
|
|
441
|
-
updatedAt: args.finishedAt,
|
|
442
|
-
inputsByPort: args.inputsByPort,
|
|
443
|
-
outputs: args.outputs,
|
|
444
|
-
usedPinnedOutput: fromPinnedOutput,
|
|
445
|
-
error: void 0
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
static skipped(args) {
|
|
449
|
-
return {
|
|
450
|
-
runId: args.runId,
|
|
451
|
-
workflowId: args.workflowId,
|
|
452
|
-
nodeId: args.nodeId,
|
|
453
|
-
activationId: args.activationId,
|
|
454
|
-
parent: args.parent,
|
|
455
|
-
status: "skipped",
|
|
456
|
-
queuedAt: args.previous?.queuedAt,
|
|
457
|
-
startedAt: args.previous?.startedAt,
|
|
458
|
-
finishedAt: args.finishedAt,
|
|
459
|
-
updatedAt: args.finishedAt,
|
|
460
|
-
inputsByPort: args.inputsByPort,
|
|
461
|
-
outputs: args.outputs,
|
|
462
|
-
error: void 0
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
static failed(args) {
|
|
466
|
-
return {
|
|
467
|
-
runId: args.runId,
|
|
468
|
-
workflowId: args.workflowId,
|
|
469
|
-
nodeId: args.nodeId,
|
|
470
|
-
activationId: args.activationId,
|
|
471
|
-
parent: args.parent,
|
|
472
|
-
status: "failed",
|
|
473
|
-
queuedAt: args.previous?.queuedAt,
|
|
474
|
-
startedAt: args.previous?.startedAt,
|
|
475
|
-
finishedAt: args.finishedAt,
|
|
476
|
-
updatedAt: args.finishedAt,
|
|
477
|
-
inputsByPort: args.inputsByPort,
|
|
478
|
-
outputs: void 0,
|
|
479
|
-
error: {
|
|
480
|
-
message: args.error.message,
|
|
481
|
-
name: args.error.name,
|
|
482
|
-
stack: args.error.stack
|
|
483
|
-
}
|
|
484
|
-
};
|
|
485
|
-
}
|
|
486
|
-
};
|
|
487
|
-
|
|
488
|
-
//#endregion
|
|
489
|
-
//#region src/execution/ActivationEnqueueService.ts
|
|
490
|
-
var ActivationEnqueueService = class {
|
|
491
|
-
constructor(activationScheduler, runStore, nodeEventPublisher) {
|
|
492
|
-
this.activationScheduler = activationScheduler;
|
|
493
|
-
this.runStore = runStore;
|
|
494
|
-
this.nodeEventPublisher = nodeEventPublisher;
|
|
495
|
-
}
|
|
496
|
-
async enqueueActivation(args) {
|
|
497
|
-
const { result, queuedSnapshot } = await this.enqueueActivationWithSnapshot(args);
|
|
498
|
-
await this.nodeEventPublisher.publish("nodeQueued", queuedSnapshot);
|
|
499
|
-
return result;
|
|
500
|
-
}
|
|
501
|
-
async enqueueActivationWithSnapshot(args) {
|
|
502
|
-
const receipt = await this.activationScheduler.enqueue(args.request);
|
|
503
|
-
const inputsByPort = InputPortMap.fromRequest(args.request);
|
|
504
|
-
const itemsIn = args.request.kind === "multi" ? args.planner.sumItemsByPort(args.request.inputsByPort) : args.request.input.length;
|
|
505
|
-
const enqueuedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
506
|
-
const pending = {
|
|
507
|
-
runId: args.runId,
|
|
508
|
-
activationId: args.request.activationId,
|
|
509
|
-
workflowId: args.workflowId,
|
|
510
|
-
nodeId: args.request.nodeId,
|
|
511
|
-
itemsIn,
|
|
512
|
-
inputsByPort,
|
|
513
|
-
receiptId: receipt.receiptId,
|
|
514
|
-
queue: receipt.queue,
|
|
515
|
-
batchId: args.request.batchId,
|
|
516
|
-
enqueuedAt
|
|
517
|
-
};
|
|
518
|
-
const queuedSnapshot = NodeSnapshotFactory.queued({
|
|
519
|
-
runId: args.runId,
|
|
520
|
-
workflowId: args.workflowId,
|
|
521
|
-
nodeId: args.request.nodeId,
|
|
522
|
-
activationId: args.request.activationId,
|
|
523
|
-
parent: args.parent,
|
|
524
|
-
queuedAt: enqueuedAt,
|
|
525
|
-
inputsByPort
|
|
526
|
-
});
|
|
527
|
-
await this.runStore.save({
|
|
528
|
-
runId: args.runId,
|
|
529
|
-
workflowId: args.workflowId,
|
|
530
|
-
startedAt: args.startedAt,
|
|
531
|
-
parent: args.parent,
|
|
532
|
-
executionOptions: args.executionOptions,
|
|
533
|
-
control: args.control,
|
|
534
|
-
workflowSnapshot: args.workflowSnapshot,
|
|
535
|
-
mutableState: args.mutableState,
|
|
536
|
-
policySnapshot: args.policySnapshot,
|
|
537
|
-
engineCounters: args.engineCounters,
|
|
538
|
-
connectionInvocations: args.connectionInvocations ? [...args.connectionInvocations] : [],
|
|
539
|
-
status: "pending",
|
|
540
|
-
pending,
|
|
541
|
-
queue: args.pendingQueue.map((entry) => ({ ...entry })),
|
|
542
|
-
outputsByNode: args.request.ctx.data.dump(),
|
|
543
|
-
nodeSnapshotsByNodeId: {
|
|
544
|
-
...args.previousNodeSnapshotsByNodeId,
|
|
545
|
-
[args.request.nodeId]: queuedSnapshot
|
|
546
|
-
}
|
|
547
|
-
});
|
|
548
|
-
this.notifyPendingStatePersisted(args.runId);
|
|
549
|
-
return {
|
|
550
|
-
result: {
|
|
551
|
-
runId: args.runId,
|
|
552
|
-
workflowId: args.workflowId,
|
|
553
|
-
startedAt: args.startedAt,
|
|
554
|
-
status: "pending",
|
|
555
|
-
pending
|
|
556
|
-
},
|
|
557
|
-
queuedSnapshot
|
|
558
|
-
};
|
|
559
|
-
}
|
|
560
|
-
notifyPendingStatePersisted(runId) {
|
|
561
|
-
this.activationScheduler.notifyPendingStatePersisted?.(runId);
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
|
|
565
|
-
//#endregion
|
|
566
|
-
//#region src/execution/DefaultAsyncSleeper.ts
|
|
567
|
-
var DefaultAsyncSleeper = class {
|
|
568
|
-
sleep(ms) {
|
|
569
|
-
return new Promise((resolve) => {
|
|
570
|
-
setTimeout(resolve, ms);
|
|
571
|
-
});
|
|
572
|
-
}
|
|
573
|
-
};
|
|
574
|
-
|
|
575
|
-
//#endregion
|
|
576
|
-
//#region src/execution/InProcessRetryRunner.ts
|
|
577
|
-
var InProcessRetryRunner = class InProcessRetryRunner {
|
|
578
|
-
constructor(sleeper) {
|
|
579
|
-
this.sleeper = sleeper;
|
|
580
|
-
}
|
|
581
|
-
async run(policy, work) {
|
|
582
|
-
const spec = InProcessRetryRunner.normalizePolicy(policy);
|
|
583
|
-
let lastError;
|
|
584
|
-
for (let attempt = 1; attempt <= spec.maxAttempts; attempt++) try {
|
|
585
|
-
return await work();
|
|
586
|
-
} catch (error) {
|
|
587
|
-
lastError = error;
|
|
588
|
-
if (attempt >= spec.maxAttempts) break;
|
|
589
|
-
const delayMs = InProcessRetryRunner.delayAfterFailureMs(spec, attempt);
|
|
590
|
-
await this.sleeper.sleep(delayMs);
|
|
591
|
-
}
|
|
592
|
-
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
593
|
-
}
|
|
594
|
-
static delayAfterFailureMs(spec, failedAttempt) {
|
|
595
|
-
if (spec.kind === "none") return 0;
|
|
596
|
-
if (spec.kind === "fixed") return spec.delayMs;
|
|
597
|
-
const exponent = failedAttempt - 1;
|
|
598
|
-
let ms = spec.initialDelayMs * Math.pow(spec.multiplier, exponent);
|
|
599
|
-
if (spec.jitter === true) ms *= 1 + Math.random() * .2;
|
|
600
|
-
if (spec.maxDelayMs !== void 0 && ms > spec.maxDelayMs) ms = spec.maxDelayMs;
|
|
601
|
-
return Math.max(0, Math.floor(ms));
|
|
602
|
-
}
|
|
603
|
-
static normalizePolicy(policy) {
|
|
604
|
-
if (policy === void 0) return {
|
|
605
|
-
kind: "none",
|
|
606
|
-
maxAttempts: 1
|
|
607
|
-
};
|
|
608
|
-
if (typeof policy !== "object" || policy === null) return {
|
|
609
|
-
kind: "none",
|
|
610
|
-
maxAttempts: 1
|
|
611
|
-
};
|
|
612
|
-
const kind = policy.kind;
|
|
613
|
-
if (kind === "none") return {
|
|
614
|
-
kind: "none",
|
|
615
|
-
maxAttempts: 1
|
|
616
|
-
};
|
|
617
|
-
if (kind === "fixed") {
|
|
618
|
-
const p = policy;
|
|
619
|
-
return {
|
|
620
|
-
kind: "fixed",
|
|
621
|
-
maxAttempts: InProcessRetryRunner.assertPositiveInt(p.maxAttempts, "fixed.maxAttempts"),
|
|
622
|
-
delayMs: InProcessRetryRunner.assertNonNegativeFinite(p.delayMs, "fixed.delayMs")
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
if (kind === "exponential") {
|
|
626
|
-
const p = policy;
|
|
627
|
-
return {
|
|
628
|
-
kind: "exponential",
|
|
629
|
-
maxAttempts: InProcessRetryRunner.assertPositiveInt(p.maxAttempts, "exponential.maxAttempts"),
|
|
630
|
-
initialDelayMs: InProcessRetryRunner.assertNonNegativeFinite(p.initialDelayMs, "exponential.initialDelayMs"),
|
|
631
|
-
multiplier: InProcessRetryRunner.assertMultiplier(p.multiplier),
|
|
632
|
-
maxDelayMs: p.maxDelayMs === void 0 ? void 0 : InProcessRetryRunner.assertNonNegativeFinite(p.maxDelayMs, "exponential.maxDelayMs"),
|
|
633
|
-
jitter: p.jitter === true
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
|
-
return {
|
|
637
|
-
kind: "none",
|
|
638
|
-
maxAttempts: 1
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
static assertPositiveInt(value, label) {
|
|
642
|
-
if (typeof value !== "number" || !Number.isFinite(value) || value < 1 || !Number.isInteger(value)) throw new Error(`Retry policy ${label} must be a positive integer`);
|
|
643
|
-
return value;
|
|
644
|
-
}
|
|
645
|
-
static assertNonNegativeFinite(value, label) {
|
|
646
|
-
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) throw new Error(`Retry policy ${label} must be a non-negative finite number`);
|
|
647
|
-
return value;
|
|
648
|
-
}
|
|
649
|
-
static assertMultiplier(value) {
|
|
650
|
-
if (typeof value !== "number" || !Number.isFinite(value) || value < 1) throw new Error(`Retry policy exponential.multiplier must be >= 1`);
|
|
651
|
-
return value;
|
|
652
|
-
}
|
|
653
|
-
};
|
|
654
|
-
|
|
655
|
-
//#endregion
|
|
656
|
-
//#region src/execution/NodeActivationRequestComposer.ts
|
|
657
|
-
/**
|
|
658
|
-
* Builds {@link NodeActivationRequest} values shared by workflow starters and continuation.
|
|
659
|
-
*/
|
|
660
|
-
var NodeActivationRequestComposer = class {
|
|
661
|
-
constructor(activationIdFactory, credentialResolverFactory) {
|
|
662
|
-
this.activationIdFactory = activationIdFactory;
|
|
663
|
-
this.credentialResolverFactory = credentialResolverFactory;
|
|
664
|
-
}
|
|
665
|
-
createSingleFromDefinition(args) {
|
|
666
|
-
const activationId = this.activationIdFactory.makeActivationId();
|
|
667
|
-
const ctx = {
|
|
668
|
-
...args.base,
|
|
669
|
-
data: args.data,
|
|
670
|
-
nodeId: args.definition.id,
|
|
671
|
-
activationId,
|
|
672
|
-
config: args.definition.config,
|
|
673
|
-
binary: args.base.binary.forNode({
|
|
674
|
-
nodeId: args.definition.id,
|
|
675
|
-
activationId
|
|
676
|
-
}),
|
|
677
|
-
getCredential: this.credentialResolverFactory.create(args.workflowId, args.definition.id, args.definition.config)
|
|
678
|
-
};
|
|
679
|
-
return {
|
|
680
|
-
kind: "single",
|
|
681
|
-
runId: args.runId,
|
|
682
|
-
activationId,
|
|
683
|
-
workflowId: args.workflowId,
|
|
684
|
-
nodeId: args.definition.id,
|
|
685
|
-
parent: args.parent,
|
|
686
|
-
executionOptions: args.executionOptions,
|
|
687
|
-
batchId: args.batchId,
|
|
688
|
-
input: args.input,
|
|
689
|
-
ctx
|
|
690
|
-
};
|
|
691
|
-
}
|
|
692
|
-
createFromPlannedActivation(args) {
|
|
693
|
-
const activationId = this.activationIdFactory.makeActivationId();
|
|
694
|
-
const ctx = {
|
|
695
|
-
...args.base,
|
|
696
|
-
data: args.data,
|
|
697
|
-
nodeId: args.nodeDefinition.id,
|
|
698
|
-
activationId,
|
|
699
|
-
config: args.nodeDefinition.config,
|
|
700
|
-
binary: args.base.binary.forNode({
|
|
701
|
-
nodeId: args.nodeDefinition.id,
|
|
702
|
-
activationId
|
|
703
|
-
}),
|
|
704
|
-
getCredential: this.credentialResolverFactory.create(args.workflowId, args.nodeDefinition.id, args.nodeDefinition.config)
|
|
705
|
-
};
|
|
706
|
-
if (args.next.kind === "multi") return {
|
|
707
|
-
kind: "multi",
|
|
708
|
-
runId: args.runId,
|
|
709
|
-
activationId,
|
|
710
|
-
workflowId: args.workflowId,
|
|
711
|
-
nodeId: args.nodeDefinition.id,
|
|
712
|
-
parent: args.parent,
|
|
713
|
-
executionOptions: args.executionOptions,
|
|
714
|
-
batchId: args.next.batchId,
|
|
715
|
-
inputsByPort: args.next.inputsByPort,
|
|
716
|
-
ctx
|
|
717
|
-
};
|
|
718
|
-
return {
|
|
719
|
-
kind: "single",
|
|
720
|
-
runId: args.runId,
|
|
721
|
-
activationId,
|
|
722
|
-
workflowId: args.workflowId,
|
|
723
|
-
nodeId: args.nodeDefinition.id,
|
|
724
|
-
parent: args.parent,
|
|
725
|
-
executionOptions: args.executionOptions,
|
|
726
|
-
batchId: args.next.batchId,
|
|
727
|
-
input: args.next.input,
|
|
728
|
-
ctx
|
|
729
|
-
};
|
|
730
|
-
}
|
|
731
|
-
};
|
|
732
|
-
|
|
733
|
-
//#endregion
|
|
734
|
-
//#region src/execution/PersistedRunStateTerminalBuilder.ts
|
|
735
|
-
/**
|
|
736
|
-
* Merges common terminal-run fields onto a loaded {@link PersistedRunState} without repeating object literals.
|
|
737
|
-
*/
|
|
738
|
-
var PersistedRunStateTerminalBuilder = class {
|
|
739
|
-
mergeTerminal(args) {
|
|
740
|
-
return {
|
|
741
|
-
...args.state,
|
|
742
|
-
engineCounters: args.engineCounters,
|
|
743
|
-
status: args.status,
|
|
744
|
-
pending: void 0,
|
|
745
|
-
queue: args.queue,
|
|
746
|
-
outputsByNode: args.outputsByNode,
|
|
747
|
-
nodeSnapshotsByNodeId: args.nodeSnapshotsByNodeId
|
|
748
|
-
};
|
|
749
|
-
}
|
|
750
|
-
};
|
|
751
|
-
|
|
752
|
-
//#endregion
|
|
753
|
-
//#region src/workflowSnapshots/MissingRuntimeFallbacks.ts
|
|
754
|
-
var MissingRuntimeNodeToken = class {};
|
|
755
|
-
var MissingRuntimeTriggerToken = class {};
|
|
756
|
-
var MissingRuntimeNodeConfig = class {
|
|
757
|
-
kind = "node";
|
|
758
|
-
type = MissingRuntimeNodeToken;
|
|
759
|
-
constructor(name, missingTokenId, missingRuntime = true) {
|
|
760
|
-
this.name = name;
|
|
761
|
-
this.missingTokenId = missingTokenId;
|
|
762
|
-
this.missingRuntime = missingRuntime;
|
|
763
|
-
}
|
|
764
|
-
};
|
|
765
|
-
var MissingRuntimeTriggerConfig = class {
|
|
766
|
-
kind = "trigger";
|
|
767
|
-
type = MissingRuntimeTriggerToken;
|
|
768
|
-
constructor(name, missingTokenId, missingRuntime = true) {
|
|
769
|
-
this.name = name;
|
|
770
|
-
this.missingTokenId = missingTokenId;
|
|
771
|
-
this.missingRuntime = missingRuntime;
|
|
772
|
-
}
|
|
773
|
-
};
|
|
774
|
-
var MissingRuntimeNode = class {
|
|
775
|
-
kind = "node";
|
|
776
|
-
outputPorts = ["main"];
|
|
777
|
-
async execute(items) {
|
|
778
|
-
return { main: items };
|
|
779
|
-
}
|
|
780
|
-
};
|
|
781
|
-
var MissingRuntimeTrigger = class {
|
|
782
|
-
kind = "trigger";
|
|
783
|
-
outputPorts = ["main"];
|
|
784
|
-
async setup(_ctx) {}
|
|
785
|
-
async execute(items) {
|
|
786
|
-
return { main: items };
|
|
787
|
-
}
|
|
788
|
-
};
|
|
789
|
-
var MissingRuntimeExecutionMarker = class {
|
|
790
|
-
static isMarked(config) {
|
|
791
|
-
return Boolean(config?.missingRuntime);
|
|
792
|
-
}
|
|
793
|
-
};
|
|
794
|
-
var MissingRuntimeFallbacks = class {
|
|
795
|
-
createDefinition(snapshotNode) {
|
|
796
|
-
if (snapshotNode.kind === "trigger") return {
|
|
797
|
-
id: snapshotNode.id,
|
|
798
|
-
kind: "trigger",
|
|
799
|
-
name: snapshotNode.name,
|
|
800
|
-
type: MissingRuntimeTriggerToken,
|
|
801
|
-
config: new MissingRuntimeTriggerConfig(snapshotNode.name ?? snapshotNode.id, snapshotNode.nodeTokenId)
|
|
802
|
-
};
|
|
803
|
-
return {
|
|
804
|
-
id: snapshotNode.id,
|
|
805
|
-
kind: "node",
|
|
806
|
-
name: snapshotNode.name,
|
|
807
|
-
type: MissingRuntimeNodeToken,
|
|
808
|
-
config: new MissingRuntimeNodeConfig(snapshotNode.name ?? snapshotNode.id, snapshotNode.nodeTokenId)
|
|
809
|
-
};
|
|
810
|
-
}
|
|
811
|
-
};
|
|
812
|
-
|
|
813
|
-
//#endregion
|
|
814
|
-
//#region src/execution/RunStateSemantics.ts
|
|
815
|
-
var RunStateSemantics = class {
|
|
816
|
-
isStopConditionSatisfied(stopCondition, nodeId) {
|
|
817
|
-
if (!stopCondition || stopCondition.kind === "workflowCompleted") return false;
|
|
818
|
-
return stopCondition.nodeId === nodeId;
|
|
819
|
-
}
|
|
820
|
-
resolveResultOutputs(workflow, stopCondition, outputsByNode) {
|
|
821
|
-
if (stopCondition?.kind === "nodeCompleted") return outputsByNode[stopCondition.nodeId]?.main ?? [];
|
|
822
|
-
return outputsByNode[createWorkflowExecutableNodeClassifier(workflow).lastExecutableNodeIdInDefinitionOrder(workflow)]?.main ?? [];
|
|
823
|
-
}
|
|
824
|
-
applySkippedSnapshots(args) {
|
|
825
|
-
const snapshots = { ...args.currentState.nodeSnapshotsByNodeId };
|
|
826
|
-
const skippedPinnedNodeIds = new Set(args.preservedPinnedNodeIds.filter((nodeId) => args.skippedNodeIds.includes(nodeId)));
|
|
827
|
-
for (const nodeId of args.skippedNodeIds) if (args.currentState.mutableState?.nodesById?.[nodeId]?.pinnedOutputsByPort) skippedPinnedNodeIds.add(nodeId);
|
|
828
|
-
for (const nodeId of skippedPinnedNodeIds) {
|
|
829
|
-
const previous = snapshots[nodeId];
|
|
830
|
-
snapshots[nodeId] = NodeSnapshotFactory.completed({
|
|
831
|
-
previous,
|
|
832
|
-
runId: args.runId,
|
|
833
|
-
workflowId: args.workflowId,
|
|
834
|
-
nodeId,
|
|
835
|
-
activationId: previous?.activationId ?? `synthetic_${nodeId}`,
|
|
836
|
-
parent: args.parent,
|
|
837
|
-
finishedAt: args.finishedAt,
|
|
838
|
-
inputsByPort: previous?.inputsByPort ?? InputPortMap.empty(),
|
|
839
|
-
outputs: args.currentState.outputsByNode[nodeId] ?? {},
|
|
840
|
-
fromPinnedOutput: true
|
|
841
|
-
});
|
|
842
|
-
}
|
|
843
|
-
return snapshots;
|
|
844
|
-
}
|
|
845
|
-
applyPinnedQueueSkips(args) {
|
|
846
|
-
let changed = true;
|
|
847
|
-
while (changed) {
|
|
848
|
-
changed = false;
|
|
849
|
-
for (let index = 0; index < args.queue.length; index += 1) {
|
|
850
|
-
const queueEntry = args.queue[index];
|
|
851
|
-
const pinnedOutputs = args.mutableState?.nodesById?.[queueEntry.nodeId]?.pinnedOutputsByPort;
|
|
852
|
-
if (!pinnedOutputs) continue;
|
|
853
|
-
args.queue.splice(index, 1);
|
|
854
|
-
const previous = args.nodeSnapshotsByNodeId[queueEntry.nodeId];
|
|
855
|
-
args.nodeSnapshotsByNodeId[queueEntry.nodeId] = NodeSnapshotFactory.completed({
|
|
856
|
-
previous,
|
|
857
|
-
runId: args.runId,
|
|
858
|
-
workflowId: args.workflowId,
|
|
859
|
-
nodeId: queueEntry.nodeId,
|
|
860
|
-
activationId: previous?.activationId ?? `synthetic_${queueEntry.nodeId}`,
|
|
861
|
-
parent: args.parent,
|
|
862
|
-
finishedAt: args.finishedAt,
|
|
863
|
-
inputsByPort: this.resolveQueueEntryInputsByPort(queueEntry),
|
|
864
|
-
outputs: pinnedOutputs,
|
|
865
|
-
fromPinnedOutput: true
|
|
866
|
-
});
|
|
867
|
-
args.data.setOutputs(queueEntry.nodeId, pinnedOutputs);
|
|
868
|
-
args.planner.applyOutputs(args.queue, {
|
|
869
|
-
fromNodeId: queueEntry.nodeId,
|
|
870
|
-
outputs: pinnedOutputs,
|
|
871
|
-
batchId: queueEntry.batchId ?? "batch_1"
|
|
872
|
-
});
|
|
873
|
-
changed = true;
|
|
874
|
-
break;
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
createFinishedSnapshot(args) {
|
|
879
|
-
const definition = args.workflow.nodes.find((node$1) => node$1.id === args.nodeId);
|
|
880
|
-
if (MissingRuntimeExecutionMarker.isMarked(definition?.config)) return NodeSnapshotFactory.skipped(args);
|
|
881
|
-
return NodeSnapshotFactory.completed(args);
|
|
882
|
-
}
|
|
883
|
-
resolveQueueEntryInputsByPort(queueEntry) {
|
|
884
|
-
if (queueEntry.collect) return queueEntry.collect.received;
|
|
885
|
-
return { [queueEntry.toInput ?? "in"]: queueEntry.input };
|
|
886
|
-
}
|
|
887
|
-
};
|
|
888
|
-
|
|
889
|
-
//#endregion
|
|
890
|
-
//#region src/execution/WorkflowRunExecutionContextFactory.ts
|
|
891
|
-
/**
|
|
892
|
-
* Shared {@link ExecutionContextFactory#create} wiring for workflow runners (base context before node-specific fields).
|
|
893
|
-
*/
|
|
894
|
-
var WorkflowRunExecutionContextFactory = class {
|
|
895
|
-
constructor(executionContextFactory, credentialResolverFactory) {
|
|
896
|
-
this.executionContextFactory = executionContextFactory;
|
|
897
|
-
this.credentialResolverFactory = credentialResolverFactory;
|
|
898
|
-
}
|
|
899
|
-
create(args) {
|
|
900
|
-
return this.executionContextFactory.create({
|
|
901
|
-
runId: args.runId,
|
|
902
|
-
workflowId: args.workflowId,
|
|
903
|
-
parent: args.parent,
|
|
904
|
-
subworkflowDepth: args.subworkflowDepth,
|
|
905
|
-
engineMaxNodeActivations: args.engineMaxNodeActivations,
|
|
906
|
-
engineMaxSubworkflowDepth: args.engineMaxSubworkflowDepth,
|
|
907
|
-
data: args.data,
|
|
908
|
-
nodeState: args.nodeState,
|
|
909
|
-
getCredential: this.credentialResolverFactory.create(args.workflowId, args.nodeId)
|
|
910
|
-
});
|
|
911
|
-
}
|
|
912
|
-
};
|
|
913
|
-
|
|
914
|
-
//#endregion
|
|
915
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/decorateMetadata.js
|
|
916
|
-
function __decorateMetadata(k, v) {
|
|
917
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
//#endregion
|
|
921
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/decorateParam.js
|
|
922
|
-
function __decorateParam(paramIndex, decorator) {
|
|
923
|
-
return function(target, key) {
|
|
924
|
-
decorator(target, key, paramIndex);
|
|
925
|
-
};
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
//#endregion
|
|
929
|
-
//#region src/executor/NodeExecutor.ts
|
|
930
|
-
let NodeExecutor = class NodeExecutor$1 {
|
|
931
|
-
retryRunner = new InProcessRetryRunner(new DefaultAsyncSleeper());
|
|
932
|
-
constructor(nodeInstanceFactory) {
|
|
933
|
-
this.nodeInstanceFactory = nodeInstanceFactory;
|
|
934
|
-
}
|
|
935
|
-
async execute(request) {
|
|
936
|
-
const policy = request.ctx.config.retryPolicy;
|
|
937
|
-
return await this.retryRunner.run(policy, async () => {
|
|
938
|
-
const nodeInstance = this.nodeInstanceFactory.createByType(request.ctx.config.type);
|
|
939
|
-
if (request.kind === "multi") return await this.executeMultiInputNode(request, nodeInstance);
|
|
940
|
-
return await this.executeSingleInputNode(request, nodeInstance);
|
|
941
|
-
});
|
|
942
|
-
}
|
|
943
|
-
async executeMultiInputNode(request, node$1) {
|
|
944
|
-
const multiInputNode = node$1;
|
|
945
|
-
if (typeof multiInputNode.executeMulti !== "function") throw new Error(`Node ${request.nodeId} does not support executeMulti but received multi-input activation`);
|
|
946
|
-
return await multiInputNode.executeMulti(request.inputsByPort, request.ctx);
|
|
947
|
-
}
|
|
948
|
-
async executeSingleInputNode(request, node$1) {
|
|
949
|
-
const singleInputNode = node$1;
|
|
950
|
-
if (typeof singleInputNode.execute !== "function") throw new Error(`Node ${request.nodeId} does not support execute but received single-input activation`);
|
|
951
|
-
return await singleInputNode.execute(request.input, request.ctx);
|
|
952
|
-
}
|
|
953
|
-
};
|
|
954
|
-
NodeExecutor = __decorate([
|
|
955
|
-
(0, tsyringe.injectable)(),
|
|
956
|
-
__decorateParam(0, (0, tsyringe.inject)(CoreTokens.WorkflowNodeInstanceFactory)),
|
|
957
|
-
__decorateMetadata("design:paramtypes", [Object])
|
|
958
|
-
], NodeExecutor);
|
|
959
|
-
|
|
960
|
-
//#endregion
|
|
961
|
-
//#region src/planning/WorkflowTopologyPlanner.ts
|
|
962
|
-
var WorkflowTopology = class WorkflowTopology {
|
|
963
|
-
constructor(defsById, outgoingByNode, incomingByNode, expectedInputsByNode, rootNodeIds) {
|
|
964
|
-
this.defsById = defsById;
|
|
965
|
-
this.outgoingByNode = outgoingByNode;
|
|
966
|
-
this.incomingByNode = incomingByNode;
|
|
967
|
-
this.expectedInputsByNode = expectedInputsByNode;
|
|
968
|
-
this.rootNodeIds = rootNodeIds;
|
|
969
|
-
}
|
|
970
|
-
static fromWorkflow(wf) {
|
|
971
|
-
const classifier = createWorkflowExecutableNodeClassifier(wf);
|
|
972
|
-
const defs = /* @__PURE__ */ new Map();
|
|
973
|
-
for (const n of wf.nodes) if (classifier.isExecutableNodeId(n.id)) defs.set(n.id, n);
|
|
974
|
-
const outgoing = /* @__PURE__ */ new Map();
|
|
975
|
-
for (const e of wf.edges) {
|
|
976
|
-
if (!classifier.isExecutableNodeId(e.from.nodeId) || !classifier.isExecutableNodeId(e.to.nodeId)) continue;
|
|
977
|
-
const list = outgoing.get(e.from.nodeId) ?? [];
|
|
978
|
-
list.push({
|
|
979
|
-
output: e.from.output,
|
|
980
|
-
to: {
|
|
981
|
-
nodeId: e.to.nodeId,
|
|
982
|
-
input: e.to.input
|
|
983
|
-
}
|
|
984
|
-
});
|
|
985
|
-
outgoing.set(e.from.nodeId, list);
|
|
986
|
-
}
|
|
987
|
-
const incomingByNode = /* @__PURE__ */ new Map();
|
|
988
|
-
for (const e of wf.edges) {
|
|
989
|
-
if (!classifier.isExecutableNodeId(e.from.nodeId) || !classifier.isExecutableNodeId(e.to.nodeId)) continue;
|
|
990
|
-
const list = incomingByNode.get(e.to.nodeId) ?? [];
|
|
991
|
-
list.push({
|
|
992
|
-
from: {
|
|
993
|
-
nodeId: e.from.nodeId,
|
|
994
|
-
output: e.from.output
|
|
995
|
-
},
|
|
996
|
-
input: e.to.input
|
|
997
|
-
});
|
|
998
|
-
incomingByNode.set(e.to.nodeId, list);
|
|
999
|
-
}
|
|
1000
|
-
const expected = /* @__PURE__ */ new Map();
|
|
1001
|
-
for (const [toNodeId, inputs] of incomingByNode.entries()) {
|
|
1002
|
-
const counts = /* @__PURE__ */ new Map();
|
|
1003
|
-
for (const edge of inputs) counts.set(edge.input, (counts.get(edge.input) ?? 0) + 1);
|
|
1004
|
-
for (const [k, n] of counts.entries()) if (n > 1) throw new Error(`Node ${toNodeId} has multiple edges into input '${k}'. Use a Merge node upstream.`);
|
|
1005
|
-
const order = [];
|
|
1006
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1007
|
-
for (const edge of inputs) {
|
|
1008
|
-
if (seen.has(edge.input)) continue;
|
|
1009
|
-
seen.add(edge.input);
|
|
1010
|
-
order.push(edge.input);
|
|
1011
|
-
}
|
|
1012
|
-
expected.set(toNodeId, order);
|
|
1013
|
-
}
|
|
1014
|
-
return new WorkflowTopology(defs, outgoing, incomingByNode, expected, wf.nodes.filter((node$1) => classifier.isExecutableNodeId(node$1.id) && !incomingByNode.has(node$1.id)).map((node$1) => node$1.id));
|
|
1015
|
-
}
|
|
1016
|
-
};
|
|
1017
|
-
|
|
1018
|
-
//#endregion
|
|
1019
|
-
//#region src/observability/RuntimeContinuationDiagnosticsReporter.ts
|
|
1020
|
-
var RuntimeContinuationDiagnostics = class {
|
|
1021
|
-
static formatNodeLabel(args) {
|
|
1022
|
-
const tokenName = typeof args.definition?.type === "function" ? args.definition.type.name : "Node";
|
|
1023
|
-
return args.definition?.name ? `"${args.definition.name}" (${tokenName}:${args.nodeId})` : `${tokenName}:${args.nodeId}`;
|
|
1024
|
-
}
|
|
1025
|
-
static formatOutputCounts(outputs) {
|
|
1026
|
-
const entries = Object.entries(outputs ?? {});
|
|
1027
|
-
if (entries.length === 0) return "no outputs";
|
|
1028
|
-
return entries.map(([port, items]) => `${port}=${items?.length ?? 0}`).join(", ");
|
|
1029
|
-
}
|
|
1030
|
-
};
|
|
1031
|
-
|
|
1032
|
-
//#endregion
|
|
1033
|
-
//#region src/orchestration/RunContinuationService.ts
|
|
1034
|
-
var RunContinuationService = class {
|
|
1035
|
-
constructor(activationIdFactory, runStore, runDataFactory, runExecutionContextFactory, workflowSnapshotResolver, planningFactory, nodeStatePublisherFactory, credentialResolverFactory, nodeActivationRequestComposer, persistedRunStateTerminalBuilder, activationEnqueueService, nodeEventPublisher, semantics, waiters, policyErrorServices, terminalPersistence, executionLimitsPolicy) {
|
|
1036
|
-
this.activationIdFactory = activationIdFactory;
|
|
1037
|
-
this.runStore = runStore;
|
|
1038
|
-
this.runDataFactory = runDataFactory;
|
|
1039
|
-
this.runExecutionContextFactory = runExecutionContextFactory;
|
|
1040
|
-
this.workflowSnapshotResolver = workflowSnapshotResolver;
|
|
1041
|
-
this.planningFactory = planningFactory;
|
|
1042
|
-
this.nodeStatePublisherFactory = nodeStatePublisherFactory;
|
|
1043
|
-
this.credentialResolverFactory = credentialResolverFactory;
|
|
1044
|
-
this.nodeActivationRequestComposer = nodeActivationRequestComposer;
|
|
1045
|
-
this.persistedRunStateTerminalBuilder = persistedRunStateTerminalBuilder;
|
|
1046
|
-
this.activationEnqueueService = activationEnqueueService;
|
|
1047
|
-
this.nodeEventPublisher = nodeEventPublisher;
|
|
1048
|
-
this.semantics = semantics;
|
|
1049
|
-
this.waiters = waiters;
|
|
1050
|
-
this.policyErrorServices = policyErrorServices;
|
|
1051
|
-
this.terminalPersistence = terminalPersistence;
|
|
1052
|
-
this.executionLimitsPolicy = executionLimitsPolicy;
|
|
1053
|
-
}
|
|
1054
|
-
async markNodeRunning(args) {
|
|
1055
|
-
const state = await this.runStore.load(args.runId);
|
|
1056
|
-
if (!state?.pending) return;
|
|
1057
|
-
if (state.pending.activationId !== args.activationId || state.pending.nodeId !== args.nodeId) return;
|
|
1058
|
-
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1059
|
-
const previous = state.nodeSnapshotsByNodeId?.[args.nodeId];
|
|
1060
|
-
const snapshot = NodeSnapshotFactory.running({
|
|
1061
|
-
previous,
|
|
1062
|
-
runId: state.runId,
|
|
1063
|
-
workflowId: state.workflowId,
|
|
1064
|
-
nodeId: args.nodeId,
|
|
1065
|
-
activationId: args.activationId,
|
|
1066
|
-
parent: state.parent,
|
|
1067
|
-
startedAt,
|
|
1068
|
-
inputsByPort: args.inputsByPort
|
|
1069
|
-
});
|
|
1070
|
-
await this.runStore.save({
|
|
1071
|
-
...state,
|
|
1072
|
-
nodeSnapshotsByNodeId: {
|
|
1073
|
-
...state.nodeSnapshotsByNodeId ?? {},
|
|
1074
|
-
[args.nodeId]: snapshot
|
|
1075
|
-
}
|
|
1076
|
-
});
|
|
1077
|
-
await this.nodeEventPublisher.publish("nodeStarted", snapshot);
|
|
1078
|
-
}
|
|
1079
|
-
async resumeFromNodeResult(args) {
|
|
1080
|
-
const state = await this.runStore.load(args.runId);
|
|
1081
|
-
if (!state) throw new Error(`Unknown runId: ${args.runId}`);
|
|
1082
|
-
if (state.status !== "pending" || !state.pending) throw new Error(`Run ${args.runId} is not pending`);
|
|
1083
|
-
if (state.pending.activationId !== args.activationId) throw new Error(`activationId mismatch for run ${args.runId}`);
|
|
1084
|
-
if (state.pending.nodeId !== args.nodeId) throw new Error(`nodeId mismatch for run ${args.runId}`);
|
|
1085
|
-
const wf = this.resolvePersistedWorkflow(state);
|
|
1086
|
-
if (!wf) throw new Error(`Unknown workflowId: ${state.workflowId}`);
|
|
1087
|
-
const { topology, planner } = this.planningFactory.create(wf);
|
|
1088
|
-
const data = this.runDataFactory.create(state.outputsByNode);
|
|
1089
|
-
const limits = this.resolveEngineLimitsFromState(state);
|
|
1090
|
-
const base = this.runExecutionContextFactory.create({
|
|
1091
|
-
runId: state.runId,
|
|
1092
|
-
workflowId: state.workflowId,
|
|
1093
|
-
nodeId: args.nodeId,
|
|
1094
|
-
parent: state.parent,
|
|
1095
|
-
subworkflowDepth: state.executionOptions?.subworkflowDepth ?? 0,
|
|
1096
|
-
engineMaxNodeActivations: limits.engineMaxNodeActivations,
|
|
1097
|
-
engineMaxSubworkflowDepth: limits.engineMaxSubworkflowDepth,
|
|
1098
|
-
data,
|
|
1099
|
-
nodeState: this.nodeStatePublisherFactory.create(state.runId, state.workflowId, state.parent)
|
|
1100
|
-
});
|
|
1101
|
-
data.setOutputs(args.nodeId, args.outputs);
|
|
1102
|
-
const completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1103
|
-
const completedSnapshot = this.semantics.createFinishedSnapshot({
|
|
1104
|
-
workflow: wf,
|
|
1105
|
-
previous: state.nodeSnapshotsByNodeId?.[args.nodeId],
|
|
1106
|
-
runId: state.runId,
|
|
1107
|
-
workflowId: state.workflowId,
|
|
1108
|
-
nodeId: args.nodeId,
|
|
1109
|
-
activationId: args.activationId,
|
|
1110
|
-
parent: state.parent,
|
|
1111
|
-
finishedAt: completedAt,
|
|
1112
|
-
inputsByPort: state.pending.inputsByPort,
|
|
1113
|
-
outputs: args.outputs
|
|
1114
|
-
});
|
|
1115
|
-
const completedActivations = (state.engineCounters?.completedNodeActivations ?? 0) + 1;
|
|
1116
|
-
const engineCounters = { completedNodeActivations: completedActivations };
|
|
1117
|
-
const maxNodeActivations = state.executionOptions?.maxNodeActivations ?? Number.MAX_SAFE_INTEGER;
|
|
1118
|
-
if (this.semantics.isStopConditionSatisfied(state.control?.stopCondition, args.nodeId)) {
|
|
1119
|
-
const completedState = this.persistedRunStateTerminalBuilder.mergeTerminal({
|
|
1120
|
-
state,
|
|
1121
|
-
engineCounters,
|
|
1122
|
-
status: "completed",
|
|
1123
|
-
queue: [],
|
|
1124
|
-
outputsByNode: data.dump(),
|
|
1125
|
-
nodeSnapshotsByNodeId: {
|
|
1126
|
-
...state.nodeSnapshotsByNodeId ?? {},
|
|
1127
|
-
[args.nodeId]: completedSnapshot
|
|
1128
|
-
}
|
|
1129
|
-
});
|
|
1130
|
-
await this.runStore.save(completedState);
|
|
1131
|
-
await this.nodeEventPublisher.publish("nodeCompleted", completedSnapshot);
|
|
1132
|
-
await this.terminalPersistence.maybeDeleteAfterTerminalState({
|
|
1133
|
-
workflow: wf,
|
|
1134
|
-
state: completedState,
|
|
1135
|
-
finalStatus: "completed",
|
|
1136
|
-
finishedAt: completedAt
|
|
1137
|
-
});
|
|
1138
|
-
const result$1 = {
|
|
1139
|
-
runId: state.runId,
|
|
1140
|
-
workflowId: state.workflowId,
|
|
1141
|
-
startedAt: state.startedAt,
|
|
1142
|
-
status: "completed",
|
|
1143
|
-
outputs: this.semantics.resolveResultOutputs(wf, state.control?.stopCondition, data.dump())
|
|
1144
|
-
};
|
|
1145
|
-
this.waiters.resolveRunCompletion(result$1);
|
|
1146
|
-
return result$1;
|
|
1147
|
-
}
|
|
1148
|
-
const batchId = state.pending.batchId ?? "batch_1";
|
|
1149
|
-
const queue = (state.queue ?? []).map((q) => ({
|
|
1150
|
-
...q,
|
|
1151
|
-
batchId: q.batchId ?? batchId
|
|
1152
|
-
}));
|
|
1153
|
-
const nextNodeSnapshotsByNodeId = {
|
|
1154
|
-
...state.nodeSnapshotsByNodeId ?? {},
|
|
1155
|
-
[args.nodeId]: completedSnapshot
|
|
1156
|
-
};
|
|
1157
|
-
planner.applyOutputs(queue, {
|
|
1158
|
-
fromNodeId: args.nodeId,
|
|
1159
|
-
outputs: args.outputs,
|
|
1160
|
-
batchId
|
|
1161
|
-
});
|
|
1162
|
-
this.semantics.applyPinnedQueueSkips({
|
|
1163
|
-
runId: state.runId,
|
|
1164
|
-
workflowId: state.workflowId,
|
|
1165
|
-
parent: state.parent,
|
|
1166
|
-
mutableState: state.mutableState,
|
|
1167
|
-
planner,
|
|
1168
|
-
queue,
|
|
1169
|
-
data,
|
|
1170
|
-
nodeSnapshotsByNodeId: nextNodeSnapshotsByNodeId,
|
|
1171
|
-
finishedAt: completedAt
|
|
1172
|
-
});
|
|
1173
|
-
let next;
|
|
1174
|
-
try {
|
|
1175
|
-
next = planner.nextActivation(queue);
|
|
1176
|
-
} catch (cause) {
|
|
1177
|
-
const completedDefinition = topology.defsById.get(args.nodeId);
|
|
1178
|
-
const completedNodeLabel = RuntimeContinuationDiagnostics.formatNodeLabel({
|
|
1179
|
-
definition: completedDefinition,
|
|
1180
|
-
nodeId: args.nodeId
|
|
1181
|
-
});
|
|
1182
|
-
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
1183
|
-
throw new Error(`After completing ${completedNodeLabel}, the engine could not plan the next activation. ${reason} Outputs: ${RuntimeContinuationDiagnostics.formatOutputCounts(args.outputs)}.`, { cause });
|
|
1184
|
-
}
|
|
1185
|
-
if (!next) {
|
|
1186
|
-
const lastNodeId = createWorkflowExecutableNodeClassifier(wf).lastExecutableNodeIdInDefinitionOrder(wf);
|
|
1187
|
-
const outputs = data.getOutputItems(lastNodeId, "main");
|
|
1188
|
-
const completedState = this.persistedRunStateTerminalBuilder.mergeTerminal({
|
|
1189
|
-
state,
|
|
1190
|
-
engineCounters,
|
|
1191
|
-
status: "completed",
|
|
1192
|
-
queue: [],
|
|
1193
|
-
outputsByNode: data.dump(),
|
|
1194
|
-
nodeSnapshotsByNodeId: nextNodeSnapshotsByNodeId
|
|
1195
|
-
});
|
|
1196
|
-
await this.runStore.save(completedState);
|
|
1197
|
-
await this.nodeEventPublisher.publish("nodeCompleted", completedSnapshot);
|
|
1198
|
-
await this.terminalPersistence.maybeDeleteAfterTerminalState({
|
|
1199
|
-
workflow: wf,
|
|
1200
|
-
state: completedState,
|
|
1201
|
-
finalStatus: "completed",
|
|
1202
|
-
finishedAt: completedAt
|
|
1203
|
-
});
|
|
1204
|
-
const result$1 = {
|
|
1205
|
-
runId: state.runId,
|
|
1206
|
-
workflowId: state.workflowId,
|
|
1207
|
-
startedAt: state.startedAt,
|
|
1208
|
-
status: "completed",
|
|
1209
|
-
outputs
|
|
1210
|
-
};
|
|
1211
|
-
this.waiters.resolveRunCompletion(result$1);
|
|
1212
|
-
return result$1;
|
|
1213
|
-
}
|
|
1214
|
-
if (completedActivations >= maxNodeActivations) {
|
|
1215
|
-
const message = `Run exceeded maxNodeActivations (${maxNodeActivations}) after ${completedActivations} completed node activations (next would be ${next.nodeId}).`;
|
|
1216
|
-
const failedState = this.persistedRunStateTerminalBuilder.mergeTerminal({
|
|
1217
|
-
state,
|
|
1218
|
-
engineCounters,
|
|
1219
|
-
status: "failed",
|
|
1220
|
-
queue: queue.map((q) => ({ ...q })),
|
|
1221
|
-
outputsByNode: data.dump(),
|
|
1222
|
-
nodeSnapshotsByNodeId: nextNodeSnapshotsByNodeId
|
|
1223
|
-
});
|
|
1224
|
-
await this.runStore.save(failedState);
|
|
1225
|
-
await this.nodeEventPublisher.publish("nodeCompleted", completedSnapshot);
|
|
1226
|
-
await this.terminalPersistence.maybeDeleteAfterTerminalState({
|
|
1227
|
-
workflow: wf,
|
|
1228
|
-
state: failedState,
|
|
1229
|
-
finalStatus: "failed",
|
|
1230
|
-
finishedAt: completedAt
|
|
1231
|
-
});
|
|
1232
|
-
const result$1 = {
|
|
1233
|
-
runId: state.runId,
|
|
1234
|
-
workflowId: state.workflowId,
|
|
1235
|
-
startedAt: state.startedAt,
|
|
1236
|
-
status: "failed",
|
|
1237
|
-
error: { message }
|
|
1238
|
-
};
|
|
1239
|
-
this.waiters.resolveRunCompletion(result$1);
|
|
1240
|
-
return result$1;
|
|
1241
|
-
}
|
|
1242
|
-
const def = topology.defsById.get(next.nodeId);
|
|
1243
|
-
if (!def || def.kind !== "node") throw new Error(`Node ${next.nodeId} is not a runnable node`);
|
|
1244
|
-
const request = this.nodeActivationRequestComposer.createFromPlannedActivation({
|
|
1245
|
-
next,
|
|
1246
|
-
base,
|
|
1247
|
-
data,
|
|
1248
|
-
runId: state.runId,
|
|
1249
|
-
workflowId: state.workflowId,
|
|
1250
|
-
parent: state.parent,
|
|
1251
|
-
executionOptions: state.executionOptions,
|
|
1252
|
-
nodeDefinition: def
|
|
1253
|
-
});
|
|
1254
|
-
const { queuedSnapshot, result } = await this.activationEnqueueService.enqueueActivationWithSnapshot({
|
|
1255
|
-
runId: state.runId,
|
|
1256
|
-
workflowId: state.workflowId,
|
|
1257
|
-
startedAt: state.startedAt,
|
|
1258
|
-
parent: state.parent,
|
|
1259
|
-
executionOptions: state.executionOptions,
|
|
1260
|
-
control: state.control,
|
|
1261
|
-
workflowSnapshot: state.workflowSnapshot,
|
|
1262
|
-
mutableState: state.mutableState,
|
|
1263
|
-
policySnapshot: state.policySnapshot,
|
|
1264
|
-
pendingQueue: queue,
|
|
1265
|
-
request,
|
|
1266
|
-
previousNodeSnapshotsByNodeId: nextNodeSnapshotsByNodeId,
|
|
1267
|
-
planner,
|
|
1268
|
-
engineCounters,
|
|
1269
|
-
connectionInvocations: state.connectionInvocations ?? []
|
|
1270
|
-
});
|
|
1271
|
-
await this.nodeEventPublisher.publish("nodeCompleted", completedSnapshot);
|
|
1272
|
-
await this.nodeEventPublisher.publish("nodeQueued", queuedSnapshot);
|
|
1273
|
-
return result;
|
|
1274
|
-
}
|
|
1275
|
-
async resumeFromNodeError(args) {
|
|
1276
|
-
const state = await this.runStore.load(args.runId);
|
|
1277
|
-
if (!state) throw new Error(`Unknown runId: ${args.runId}`);
|
|
1278
|
-
if (state.status !== "pending" || !state.pending) throw new Error(`Run ${args.runId} is not pending`);
|
|
1279
|
-
if (state.pending.activationId !== args.activationId) throw new Error(`activationId mismatch for run ${args.runId}`);
|
|
1280
|
-
if (state.pending.nodeId !== args.nodeId) throw new Error(`nodeId mismatch for run ${args.runId}`);
|
|
1281
|
-
const wf = this.resolvePersistedWorkflow(state);
|
|
1282
|
-
if (!wf) throw new Error(`Unknown workflowId: ${state.workflowId}`);
|
|
1283
|
-
const failedDefinition = WorkflowTopology.fromWorkflow(wf).defsById.get(args.nodeId);
|
|
1284
|
-
const webhookControlSignal = state.executionOptions?.webhook && failedDefinition?.kind === "trigger" ? this.asWebhookControlSignal(args.error) : void 0;
|
|
1285
|
-
if (webhookControlSignal) return await this.resumeFromWebhookControl({
|
|
1286
|
-
state,
|
|
1287
|
-
workflow: wf,
|
|
1288
|
-
args,
|
|
1289
|
-
signal: webhookControlSignal
|
|
1290
|
-
});
|
|
1291
|
-
if (failedDefinition && failedDefinition.kind === "node") {
|
|
1292
|
-
const nodeHandler = this.policyErrorServices.resolveNodeErrorHandler(failedDefinition.config.nodeErrorHandler);
|
|
1293
|
-
if (nodeHandler) try {
|
|
1294
|
-
const ctx = this.buildNodeExecutionContextForPending(state, wf, failedDefinition, args.nodeId);
|
|
1295
|
-
const inputsByPort = state.pending.inputsByPort;
|
|
1296
|
-
const portKeys = Object.keys(inputsByPort);
|
|
1297
|
-
const kind = portKeys.length === 1 && portKeys[0] === "in" ? "single" : "multi";
|
|
1298
|
-
const items = inputsByPort.in ?? [];
|
|
1299
|
-
const recovered = await nodeHandler.handle({
|
|
1300
|
-
kind,
|
|
1301
|
-
items,
|
|
1302
|
-
inputsByPort: kind === "multi" ? inputsByPort : void 0,
|
|
1303
|
-
ctx,
|
|
1304
|
-
error: args.error
|
|
1305
|
-
});
|
|
1306
|
-
return await this.resumeFromNodeResult({
|
|
1307
|
-
runId: args.runId,
|
|
1308
|
-
activationId: args.activationId,
|
|
1309
|
-
nodeId: args.nodeId,
|
|
1310
|
-
outputs: recovered
|
|
1311
|
-
});
|
|
1312
|
-
} catch {}
|
|
1313
|
-
}
|
|
1314
|
-
const finishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1315
|
-
const message = args.error?.message ?? String(args.error);
|
|
1316
|
-
const failedSnapshot = NodeSnapshotFactory.failed({
|
|
1317
|
-
previous: state.nodeSnapshotsByNodeId?.[args.nodeId],
|
|
1318
|
-
runId: state.runId,
|
|
1319
|
-
workflowId: state.workflowId,
|
|
1320
|
-
nodeId: args.nodeId,
|
|
1321
|
-
activationId: args.activationId,
|
|
1322
|
-
parent: state.parent,
|
|
1323
|
-
finishedAt,
|
|
1324
|
-
inputsByPort: state.pending.inputsByPort,
|
|
1325
|
-
error: args.error
|
|
1326
|
-
});
|
|
1327
|
-
const failedState = this.persistedRunStateTerminalBuilder.mergeTerminal({
|
|
1328
|
-
state,
|
|
1329
|
-
engineCounters: state.engineCounters ?? { completedNodeActivations: 0 },
|
|
1330
|
-
status: "failed",
|
|
1331
|
-
queue: (state.queue ?? []).map((q) => ({ ...q })),
|
|
1332
|
-
outputsByNode: state.outputsByNode,
|
|
1333
|
-
nodeSnapshotsByNodeId: {
|
|
1334
|
-
...state.nodeSnapshotsByNodeId ?? {},
|
|
1335
|
-
[args.nodeId]: failedSnapshot
|
|
1336
|
-
}
|
|
1337
|
-
});
|
|
1338
|
-
await this.runStore.save(failedState);
|
|
1339
|
-
await this.nodeEventPublisher.publish("nodeFailed", failedSnapshot);
|
|
1340
|
-
const wfErr = this.policyErrorServices.resolveWorkflowErrorHandler(wf.workflowErrorHandler);
|
|
1341
|
-
if (wfErr) await Promise.resolve(wfErr.onError({
|
|
1342
|
-
runId: state.runId,
|
|
1343
|
-
workflowId: state.workflowId,
|
|
1344
|
-
workflow: wf,
|
|
1345
|
-
failedNodeId: args.nodeId,
|
|
1346
|
-
error: args.error,
|
|
1347
|
-
startedAt: state.startedAt,
|
|
1348
|
-
finishedAt
|
|
1349
|
-
}));
|
|
1350
|
-
await this.terminalPersistence.maybeDeleteAfterTerminalState({
|
|
1351
|
-
workflow: wf,
|
|
1352
|
-
state: failedState,
|
|
1353
|
-
finalStatus: "failed",
|
|
1354
|
-
finishedAt
|
|
1355
|
-
});
|
|
1356
|
-
const result = {
|
|
1357
|
-
runId: state.runId,
|
|
1358
|
-
workflowId: state.workflowId,
|
|
1359
|
-
startedAt: state.startedAt,
|
|
1360
|
-
status: "failed",
|
|
1361
|
-
error: { message }
|
|
1362
|
-
};
|
|
1363
|
-
this.waiters.resolveRunCompletion(result);
|
|
1364
|
-
return result;
|
|
1365
|
-
}
|
|
1366
|
-
async resumeFromStepResult(args) {
|
|
1367
|
-
return await this.resumeFromNodeResult(args);
|
|
1368
|
-
}
|
|
1369
|
-
async resumeFromStepError(args) {
|
|
1370
|
-
return await this.resumeFromNodeError(args);
|
|
1371
|
-
}
|
|
1372
|
-
async waitForCompletion(runId) {
|
|
1373
|
-
const existing = await this.runStore.load(runId);
|
|
1374
|
-
if (existing?.status === "completed") {
|
|
1375
|
-
const wf = this.resolvePersistedWorkflow(existing);
|
|
1376
|
-
const outputs = wf ? this.semantics.resolveResultOutputs(wf, existing.control?.stopCondition, existing.outputsByNode) : [];
|
|
1377
|
-
return {
|
|
1378
|
-
runId: existing.runId,
|
|
1379
|
-
workflowId: existing.workflowId,
|
|
1380
|
-
startedAt: existing.startedAt,
|
|
1381
|
-
status: "completed",
|
|
1382
|
-
outputs
|
|
1383
|
-
};
|
|
1384
|
-
}
|
|
1385
|
-
if (existing?.status === "failed") return {
|
|
1386
|
-
runId: existing.runId,
|
|
1387
|
-
workflowId: existing.workflowId,
|
|
1388
|
-
startedAt: existing.startedAt,
|
|
1389
|
-
status: "failed",
|
|
1390
|
-
error: { message: "Run failed" }
|
|
1391
|
-
};
|
|
1392
|
-
const result = await this.waiters.waitForCompletion(runId);
|
|
1393
|
-
if (result.status !== "completed" && result.status !== "failed") throw new Error(`Unexpected run completion status: ${result.status}`);
|
|
1394
|
-
return result;
|
|
1395
|
-
}
|
|
1396
|
-
async waitForWebhookResponse(runId) {
|
|
1397
|
-
return await this.waiters.waitForWebhookResponse(runId);
|
|
1398
|
-
}
|
|
1399
|
-
async resumeFromWebhookControl(args) {
|
|
1400
|
-
const data = this.runDataFactory.create(args.state.outputsByNode);
|
|
1401
|
-
const { topology, planner } = this.planningFactory.create(args.workflow);
|
|
1402
|
-
const triggerOutputs = { main: args.signal.kind === "respondNowAndContinue" ? args.signal.continueItems ?? [] : args.signal.responseItems };
|
|
1403
|
-
data.setOutputs(args.args.nodeId, triggerOutputs);
|
|
1404
|
-
const completedSnapshot = this.semantics.createFinishedSnapshot({
|
|
1405
|
-
workflow: args.workflow,
|
|
1406
|
-
previous: args.state.nodeSnapshotsByNodeId?.[args.args.nodeId],
|
|
1407
|
-
runId: args.state.runId,
|
|
1408
|
-
workflowId: args.state.workflowId,
|
|
1409
|
-
nodeId: args.args.nodeId,
|
|
1410
|
-
activationId: args.args.activationId,
|
|
1411
|
-
parent: args.state.parent,
|
|
1412
|
-
finishedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1413
|
-
inputsByPort: args.state.pending?.inputsByPort ?? InputPortMap.empty(),
|
|
1414
|
-
outputs: triggerOutputs
|
|
1415
|
-
});
|
|
1416
|
-
const completedActivations = (args.state.engineCounters?.completedNodeActivations ?? 0) + 1;
|
|
1417
|
-
const engineCounters = { completedNodeActivations: completedActivations };
|
|
1418
|
-
const maxNodeActivations = args.state.executionOptions?.maxNodeActivations ?? Number.MAX_SAFE_INTEGER;
|
|
1419
|
-
if (this.semantics.isStopConditionSatisfied(args.state.control?.stopCondition, args.args.nodeId)) {
|
|
1420
|
-
const completedState = this.persistedRunStateTerminalBuilder.mergeTerminal({
|
|
1421
|
-
state: args.state,
|
|
1422
|
-
engineCounters,
|
|
1423
|
-
status: "completed",
|
|
1424
|
-
queue: [],
|
|
1425
|
-
outputsByNode: data.dump(),
|
|
1426
|
-
nodeSnapshotsByNodeId: {
|
|
1427
|
-
...args.state.nodeSnapshotsByNodeId ?? {},
|
|
1428
|
-
[args.args.nodeId]: completedSnapshot
|
|
1429
|
-
}
|
|
1430
|
-
});
|
|
1431
|
-
await this.runStore.save(completedState);
|
|
1432
|
-
await this.nodeEventPublisher.publish("nodeCompleted", completedSnapshot);
|
|
1433
|
-
await this.terminalPersistence.maybeDeleteAfterTerminalState({
|
|
1434
|
-
workflow: args.workflow,
|
|
1435
|
-
state: completedState,
|
|
1436
|
-
finalStatus: "completed",
|
|
1437
|
-
finishedAt: completedSnapshot.finishedAt ?? completedSnapshot.updatedAt
|
|
1438
|
-
});
|
|
1439
|
-
this.waiters.resolveWebhookResponse({
|
|
1440
|
-
runId: args.state.runId,
|
|
1441
|
-
workflowId: args.state.workflowId,
|
|
1442
|
-
startedAt: args.state.startedAt,
|
|
1443
|
-
runStatus: "completed",
|
|
1444
|
-
response: args.signal.responseItems
|
|
1445
|
-
});
|
|
1446
|
-
const result$1 = {
|
|
1447
|
-
runId: args.state.runId,
|
|
1448
|
-
workflowId: args.state.workflowId,
|
|
1449
|
-
startedAt: args.state.startedAt,
|
|
1450
|
-
status: "completed",
|
|
1451
|
-
outputs: this.semantics.resolveResultOutputs(args.workflow, args.state.control?.stopCondition, data.dump())
|
|
1452
|
-
};
|
|
1453
|
-
this.waiters.resolveRunCompletion(result$1);
|
|
1454
|
-
return result$1;
|
|
1455
|
-
}
|
|
1456
|
-
if (args.signal.kind === "respondNow") {
|
|
1457
|
-
const completedState = this.persistedRunStateTerminalBuilder.mergeTerminal({
|
|
1458
|
-
state: args.state,
|
|
1459
|
-
engineCounters,
|
|
1460
|
-
status: "completed",
|
|
1461
|
-
queue: [],
|
|
1462
|
-
outputsByNode: data.dump(),
|
|
1463
|
-
nodeSnapshotsByNodeId: {
|
|
1464
|
-
...args.state.nodeSnapshotsByNodeId ?? {},
|
|
1465
|
-
[args.args.nodeId]: completedSnapshot
|
|
1466
|
-
}
|
|
1467
|
-
});
|
|
1468
|
-
await this.runStore.save(completedState);
|
|
1469
|
-
await this.nodeEventPublisher.publish("nodeCompleted", completedSnapshot);
|
|
1470
|
-
await this.terminalPersistence.maybeDeleteAfterTerminalState({
|
|
1471
|
-
workflow: args.workflow,
|
|
1472
|
-
state: completedState,
|
|
1473
|
-
finalStatus: "completed",
|
|
1474
|
-
finishedAt: completedSnapshot.finishedAt ?? completedSnapshot.updatedAt
|
|
1475
|
-
});
|
|
1476
|
-
const result$1 = {
|
|
1477
|
-
runId: args.state.runId,
|
|
1478
|
-
workflowId: args.state.workflowId,
|
|
1479
|
-
startedAt: args.state.startedAt,
|
|
1480
|
-
status: "completed",
|
|
1481
|
-
outputs: args.signal.responseItems
|
|
1482
|
-
};
|
|
1483
|
-
this.waiters.resolveWebhookResponse({
|
|
1484
|
-
runId: args.state.runId,
|
|
1485
|
-
workflowId: args.state.workflowId,
|
|
1486
|
-
startedAt: args.state.startedAt,
|
|
1487
|
-
runStatus: "completed",
|
|
1488
|
-
response: args.signal.responseItems
|
|
1489
|
-
});
|
|
1490
|
-
this.waiters.resolveRunCompletion(result$1);
|
|
1491
|
-
return result$1;
|
|
1492
|
-
}
|
|
1493
|
-
const batchId = args.state.pending?.batchId ?? "batch_1";
|
|
1494
|
-
const queue = (args.state.queue ?? []).map((entry) => ({
|
|
1495
|
-
...entry,
|
|
1496
|
-
batchId: entry.batchId ?? batchId
|
|
1497
|
-
}));
|
|
1498
|
-
planner.applyOutputs(queue, {
|
|
1499
|
-
fromNodeId: args.args.nodeId,
|
|
1500
|
-
outputs: triggerOutputs,
|
|
1501
|
-
batchId
|
|
1502
|
-
});
|
|
1503
|
-
const next = planner.nextActivation(queue);
|
|
1504
|
-
if (!next) {
|
|
1505
|
-
const lastNodeId = createWorkflowExecutableNodeClassifier(args.workflow).lastExecutableNodeIdInDefinitionOrder(args.workflow);
|
|
1506
|
-
const outputs = data.getOutputItems(lastNodeId, "main");
|
|
1507
|
-
const completedState = this.persistedRunStateTerminalBuilder.mergeTerminal({
|
|
1508
|
-
state: args.state,
|
|
1509
|
-
engineCounters,
|
|
1510
|
-
status: "completed",
|
|
1511
|
-
queue: [],
|
|
1512
|
-
outputsByNode: data.dump(),
|
|
1513
|
-
nodeSnapshotsByNodeId: {
|
|
1514
|
-
...args.state.nodeSnapshotsByNodeId ?? {},
|
|
1515
|
-
[args.args.nodeId]: completedSnapshot
|
|
1516
|
-
}
|
|
1517
|
-
});
|
|
1518
|
-
await this.runStore.save(completedState);
|
|
1519
|
-
await this.nodeEventPublisher.publish("nodeCompleted", completedSnapshot);
|
|
1520
|
-
await this.terminalPersistence.maybeDeleteAfterTerminalState({
|
|
1521
|
-
workflow: args.workflow,
|
|
1522
|
-
state: completedState,
|
|
1523
|
-
finalStatus: "completed",
|
|
1524
|
-
finishedAt: completedSnapshot.finishedAt ?? completedSnapshot.updatedAt
|
|
1525
|
-
});
|
|
1526
|
-
const result$1 = {
|
|
1527
|
-
runId: args.state.runId,
|
|
1528
|
-
workflowId: args.state.workflowId,
|
|
1529
|
-
startedAt: args.state.startedAt,
|
|
1530
|
-
status: "completed",
|
|
1531
|
-
outputs
|
|
1532
|
-
};
|
|
1533
|
-
this.waiters.resolveWebhookResponse({
|
|
1534
|
-
runId: args.state.runId,
|
|
1535
|
-
workflowId: args.state.workflowId,
|
|
1536
|
-
startedAt: args.state.startedAt,
|
|
1537
|
-
runStatus: "completed",
|
|
1538
|
-
response: args.signal.responseItems
|
|
1539
|
-
});
|
|
1540
|
-
this.waiters.resolveRunCompletion(result$1);
|
|
1541
|
-
return result$1;
|
|
1542
|
-
}
|
|
1543
|
-
if (completedActivations >= maxNodeActivations) {
|
|
1544
|
-
const message = `Run exceeded maxNodeActivations (${maxNodeActivations}) after ${completedActivations} completed node activations (next would be ${next.nodeId}).`;
|
|
1545
|
-
const failedState = this.persistedRunStateTerminalBuilder.mergeTerminal({
|
|
1546
|
-
state: args.state,
|
|
1547
|
-
engineCounters,
|
|
1548
|
-
status: "failed",
|
|
1549
|
-
queue: queue.map((q) => ({ ...q })),
|
|
1550
|
-
outputsByNode: data.dump(),
|
|
1551
|
-
nodeSnapshotsByNodeId: {
|
|
1552
|
-
...args.state.nodeSnapshotsByNodeId ?? {},
|
|
1553
|
-
[args.args.nodeId]: completedSnapshot
|
|
1554
|
-
}
|
|
1555
|
-
});
|
|
1556
|
-
await this.runStore.save(failedState);
|
|
1557
|
-
await this.nodeEventPublisher.publish("nodeCompleted", completedSnapshot);
|
|
1558
|
-
await this.terminalPersistence.maybeDeleteAfterTerminalState({
|
|
1559
|
-
workflow: args.workflow,
|
|
1560
|
-
state: failedState,
|
|
1561
|
-
finalStatus: "failed",
|
|
1562
|
-
finishedAt: completedSnapshot.finishedAt ?? completedSnapshot.updatedAt
|
|
1563
|
-
});
|
|
1564
|
-
const result$1 = {
|
|
1565
|
-
runId: args.state.runId,
|
|
1566
|
-
workflowId: args.state.workflowId,
|
|
1567
|
-
startedAt: args.state.startedAt,
|
|
1568
|
-
status: "failed",
|
|
1569
|
-
error: { message }
|
|
1570
|
-
};
|
|
1571
|
-
this.waiters.resolveWebhookResponse({
|
|
1572
|
-
runId: args.state.runId,
|
|
1573
|
-
workflowId: args.state.workflowId,
|
|
1574
|
-
startedAt: args.state.startedAt,
|
|
1575
|
-
runStatus: "pending",
|
|
1576
|
-
response: args.signal.responseItems
|
|
1577
|
-
});
|
|
1578
|
-
this.waiters.resolveRunCompletion(result$1);
|
|
1579
|
-
return result$1;
|
|
1580
|
-
}
|
|
1581
|
-
const nextDefinition = topology.defsById.get(next.nodeId);
|
|
1582
|
-
if (!nextDefinition || nextDefinition.kind !== "node") throw new Error(`Node ${next.nodeId} is not a runnable node`);
|
|
1583
|
-
const webhookLimits = this.resolveEngineLimitsFromState(args.state);
|
|
1584
|
-
const base = this.runExecutionContextFactory.create({
|
|
1585
|
-
runId: args.state.runId,
|
|
1586
|
-
workflowId: args.state.workflowId,
|
|
1587
|
-
nodeId: nextDefinition.id,
|
|
1588
|
-
parent: args.state.parent,
|
|
1589
|
-
subworkflowDepth: args.state.executionOptions?.subworkflowDepth ?? 0,
|
|
1590
|
-
engineMaxNodeActivations: webhookLimits.engineMaxNodeActivations,
|
|
1591
|
-
engineMaxSubworkflowDepth: webhookLimits.engineMaxSubworkflowDepth,
|
|
1592
|
-
data,
|
|
1593
|
-
nodeState: this.nodeStatePublisherFactory.create(args.state.runId, args.state.workflowId, args.state.parent)
|
|
1594
|
-
});
|
|
1595
|
-
const request = this.nodeActivationRequestComposer.createFromPlannedActivation({
|
|
1596
|
-
next,
|
|
1597
|
-
base,
|
|
1598
|
-
data,
|
|
1599
|
-
runId: args.state.runId,
|
|
1600
|
-
workflowId: args.state.workflowId,
|
|
1601
|
-
parent: args.state.parent,
|
|
1602
|
-
executionOptions: args.state.executionOptions,
|
|
1603
|
-
nodeDefinition: nextDefinition
|
|
1604
|
-
});
|
|
1605
|
-
const { queuedSnapshot, result } = await this.activationEnqueueService.enqueueActivationWithSnapshot({
|
|
1606
|
-
runId: args.state.runId,
|
|
1607
|
-
workflowId: args.state.workflowId,
|
|
1608
|
-
startedAt: args.state.startedAt,
|
|
1609
|
-
parent: args.state.parent,
|
|
1610
|
-
executionOptions: args.state.executionOptions,
|
|
1611
|
-
control: args.state.control,
|
|
1612
|
-
workflowSnapshot: args.state.workflowSnapshot,
|
|
1613
|
-
mutableState: args.state.mutableState,
|
|
1614
|
-
policySnapshot: args.state.policySnapshot,
|
|
1615
|
-
pendingQueue: queue,
|
|
1616
|
-
request,
|
|
1617
|
-
previousNodeSnapshotsByNodeId: {
|
|
1618
|
-
...args.state.nodeSnapshotsByNodeId ?? {},
|
|
1619
|
-
[args.args.nodeId]: completedSnapshot
|
|
1620
|
-
},
|
|
1621
|
-
planner,
|
|
1622
|
-
engineCounters,
|
|
1623
|
-
connectionInvocations: args.state.connectionInvocations ?? []
|
|
1624
|
-
});
|
|
1625
|
-
await this.nodeEventPublisher.publish("nodeCompleted", completedSnapshot);
|
|
1626
|
-
await this.nodeEventPublisher.publish("nodeQueued", queuedSnapshot);
|
|
1627
|
-
this.waiters.resolveWebhookResponse({
|
|
1628
|
-
runId: args.state.runId,
|
|
1629
|
-
workflowId: args.state.workflowId,
|
|
1630
|
-
startedAt: args.state.startedAt,
|
|
1631
|
-
runStatus: "pending",
|
|
1632
|
-
response: args.signal.responseItems
|
|
1633
|
-
});
|
|
1634
|
-
return result;
|
|
1635
|
-
}
|
|
1636
|
-
asWebhookControlSignal(error) {
|
|
1637
|
-
const candidate = error;
|
|
1638
|
-
if (!candidate || candidate.__webhookControl !== true) return void 0;
|
|
1639
|
-
if (candidate.kind !== "respondNow" && candidate.kind !== "respondNowAndContinue") return void 0;
|
|
1640
|
-
if (!Array.isArray(candidate.responseItems)) return void 0;
|
|
1641
|
-
return candidate;
|
|
1642
|
-
}
|
|
1643
|
-
resolvePersistedWorkflow(state) {
|
|
1644
|
-
return this.workflowSnapshotResolver.resolve({
|
|
1645
|
-
workflowId: state.workflowId,
|
|
1646
|
-
workflowSnapshot: state.workflowSnapshot
|
|
1647
|
-
});
|
|
1648
|
-
}
|
|
1649
|
-
buildNodeExecutionContextForPending(state, wf, def, nodeId) {
|
|
1650
|
-
const data = this.runDataFactory.create(state.outputsByNode);
|
|
1651
|
-
const limits = this.resolveEngineLimitsFromState(state);
|
|
1652
|
-
const base = this.runExecutionContextFactory.create({
|
|
1653
|
-
runId: state.runId,
|
|
1654
|
-
workflowId: state.workflowId,
|
|
1655
|
-
nodeId,
|
|
1656
|
-
parent: state.parent,
|
|
1657
|
-
subworkflowDepth: state.executionOptions?.subworkflowDepth ?? 0,
|
|
1658
|
-
engineMaxNodeActivations: limits.engineMaxNodeActivations,
|
|
1659
|
-
engineMaxSubworkflowDepth: limits.engineMaxSubworkflowDepth,
|
|
1660
|
-
data,
|
|
1661
|
-
nodeState: this.nodeStatePublisherFactory.create(state.runId, state.workflowId, state.parent)
|
|
1662
|
-
});
|
|
1663
|
-
const activationId = state.pending.activationId;
|
|
1664
|
-
return {
|
|
1665
|
-
...base,
|
|
1666
|
-
data,
|
|
1667
|
-
nodeId,
|
|
1668
|
-
activationId,
|
|
1669
|
-
config: def.config,
|
|
1670
|
-
binary: base.binary.forNode({
|
|
1671
|
-
nodeId,
|
|
1672
|
-
activationId
|
|
1673
|
-
}),
|
|
1674
|
-
getCredential: this.credentialResolverFactory.create(wf.id, nodeId, def.config)
|
|
1675
|
-
};
|
|
1676
|
-
}
|
|
1677
|
-
resolveEngineLimitsFromState(state) {
|
|
1678
|
-
const fb = this.executionLimitsPolicy.createRootExecutionOptions();
|
|
1679
|
-
return {
|
|
1680
|
-
engineMaxNodeActivations: state.executionOptions?.maxNodeActivations ?? fb.maxNodeActivations,
|
|
1681
|
-
engineMaxSubworkflowDepth: state.executionOptions?.maxSubworkflowDepth ?? fb.maxSubworkflowDepth
|
|
1682
|
-
};
|
|
1683
|
-
}
|
|
1684
|
-
};
|
|
1685
|
-
|
|
1686
|
-
//#endregion
|
|
1687
|
-
//#region src/planning/CurrentStateFrontierPlanner.ts
|
|
1688
|
-
var CurrentStateFrontierPlanner = class CurrentStateFrontierPlanner {
|
|
1689
|
-
constructor(topology) {
|
|
1690
|
-
this.topology = topology;
|
|
1691
|
-
}
|
|
1692
|
-
/** Composition-root-friendly factory (avoids `new` at orchestration call sites under ESLint manual-DI rules). */
|
|
1693
|
-
static createFromTopology(topology) {
|
|
1694
|
-
return new CurrentStateFrontierPlanner(topology);
|
|
1695
|
-
}
|
|
1696
|
-
plan(args) {
|
|
1697
|
-
const stopCondition = args.stopCondition ?? { kind: "workflowCompleted" };
|
|
1698
|
-
const baseState = this.cloneCurrentState(args.currentState);
|
|
1699
|
-
const normalizedState = this.overlayPinnedOutputs(baseState);
|
|
1700
|
-
const resetResult = this.applyReset({
|
|
1701
|
-
currentState: normalizedState,
|
|
1702
|
-
reset: args.reset
|
|
1703
|
-
});
|
|
1704
|
-
const requiredNodeIds = this.collectRequiredNodeIds(stopCondition, resetResult.currentState);
|
|
1705
|
-
const satisfiedNodeIds = this.collectSatisfiedNodeIds(resetResult.currentState);
|
|
1706
|
-
const skippedNodeIds = [...new Set([...[...requiredNodeIds].filter((nodeId) => this.isNodeSatisfied(resetResult.currentState, nodeId)), ...resetResult.preservedPinnedNodeIds.filter((nodeId) => requiredNodeIds.has(nodeId))])];
|
|
1707
|
-
const frontierNodeIds = this.collectFrontierNodeIds(requiredNodeIds, resetResult.currentState);
|
|
1708
|
-
const rootNodeIds = frontierNodeIds.filter((nodeId) => (this.topology.incomingByNode.get(nodeId) ?? []).length === 0);
|
|
1709
|
-
if (rootNodeIds.length > 1) throw new Error(`Ambiguous execution frontier. Multiple root nodes require input: ${rootNodeIds.join(", ")}`);
|
|
1710
|
-
if (frontierNodeIds.length === 0) return {
|
|
1711
|
-
queue: [],
|
|
1712
|
-
currentState: resetResult.currentState,
|
|
1713
|
-
stopCondition,
|
|
1714
|
-
satisfiedNodeIds,
|
|
1715
|
-
skippedNodeIds,
|
|
1716
|
-
clearedNodeIds: resetResult.clearedNodeIds,
|
|
1717
|
-
preservedPinnedNodeIds: resetResult.preservedPinnedNodeIds
|
|
1718
|
-
};
|
|
1719
|
-
if (rootNodeIds.length === 1) {
|
|
1720
|
-
const rootNodeId = rootNodeIds[0];
|
|
1721
|
-
const definition = this.topology.defsById.get(rootNodeId);
|
|
1722
|
-
if (!definition) throw new Error(`Unknown frontier nodeId: ${rootNodeId}`);
|
|
1723
|
-
return {
|
|
1724
|
-
rootNodeId,
|
|
1725
|
-
rootNodeInput: this.resolveRootNodeInput({
|
|
1726
|
-
nodeKind: definition.kind,
|
|
1727
|
-
items: args.items
|
|
1728
|
-
}),
|
|
1729
|
-
queue: [],
|
|
1730
|
-
currentState: resetResult.currentState,
|
|
1731
|
-
stopCondition,
|
|
1732
|
-
satisfiedNodeIds,
|
|
1733
|
-
skippedNodeIds,
|
|
1734
|
-
clearedNodeIds: resetResult.clearedNodeIds,
|
|
1735
|
-
preservedPinnedNodeIds: resetResult.preservedPinnedNodeIds
|
|
1736
|
-
};
|
|
1737
|
-
}
|
|
1738
|
-
const queue = [];
|
|
1739
|
-
for (const nodeId of frontierNodeIds) queue.push(...this.buildFrontierQueue(nodeId, resetResult.currentState));
|
|
1740
|
-
return {
|
|
1741
|
-
queue,
|
|
1742
|
-
currentState: resetResult.currentState,
|
|
1743
|
-
stopCondition,
|
|
1744
|
-
satisfiedNodeIds,
|
|
1745
|
-
skippedNodeIds,
|
|
1746
|
-
clearedNodeIds: resetResult.clearedNodeIds,
|
|
1747
|
-
preservedPinnedNodeIds: resetResult.preservedPinnedNodeIds
|
|
1748
|
-
};
|
|
1749
|
-
}
|
|
1750
|
-
cloneCurrentState(currentState) {
|
|
1751
|
-
if (!currentState) return {
|
|
1752
|
-
outputsByNode: {},
|
|
1753
|
-
nodeSnapshotsByNodeId: {},
|
|
1754
|
-
connectionInvocations: [],
|
|
1755
|
-
mutableState: void 0
|
|
1756
|
-
};
|
|
1757
|
-
return {
|
|
1758
|
-
outputsByNode: { ...currentState.outputsByNode },
|
|
1759
|
-
nodeSnapshotsByNodeId: { ...currentState.nodeSnapshotsByNodeId },
|
|
1760
|
-
connectionInvocations: currentState.connectionInvocations ? [...currentState.connectionInvocations] : void 0,
|
|
1761
|
-
mutableState: currentState.mutableState
|
|
1762
|
-
};
|
|
1763
|
-
}
|
|
1764
|
-
overlayPinnedOutputs(currentState) {
|
|
1765
|
-
const outputsByNode = { ...currentState.outputsByNode };
|
|
1766
|
-
for (const [nodeId, nodeState] of Object.entries(currentState.mutableState?.nodesById ?? {})) {
|
|
1767
|
-
const pinnedOutputs = nodeState.pinnedOutputsByPort;
|
|
1768
|
-
if (!pinnedOutputs) continue;
|
|
1769
|
-
outputsByNode[nodeId] = pinnedOutputs;
|
|
1770
|
-
}
|
|
1771
|
-
return {
|
|
1772
|
-
outputsByNode,
|
|
1773
|
-
nodeSnapshotsByNodeId: { ...currentState.nodeSnapshotsByNodeId },
|
|
1774
|
-
connectionInvocations: currentState.connectionInvocations,
|
|
1775
|
-
mutableState: currentState.mutableState
|
|
1776
|
-
};
|
|
1777
|
-
}
|
|
1778
|
-
applyReset(args) {
|
|
1779
|
-
if (!args.reset) return {
|
|
1780
|
-
currentState: args.currentState,
|
|
1781
|
-
clearedNodeIds: [],
|
|
1782
|
-
preservedPinnedNodeIds: []
|
|
1783
|
-
};
|
|
1784
|
-
const outputsByNode = { ...args.currentState.outputsByNode };
|
|
1785
|
-
const nodeSnapshotsByNodeId = { ...args.currentState.nodeSnapshotsByNodeId };
|
|
1786
|
-
const clearedNodeIds = [];
|
|
1787
|
-
const preservedPinnedNodeIds = [];
|
|
1788
|
-
const descendants = this.collectDescendants(args.reset.clearFromNodeId);
|
|
1789
|
-
const runtimeDescendants = this.collectRuntimeDescendants(args.currentState, descendants);
|
|
1790
|
-
const clearedIdSet = new Set([...descendants, ...runtimeDescendants]);
|
|
1791
|
-
for (const nodeId of [...descendants, ...runtimeDescendants]) {
|
|
1792
|
-
const pinnedOutputs = this.getPinnedOutputs(args.currentState, nodeId);
|
|
1793
|
-
if (pinnedOutputs) {
|
|
1794
|
-
outputsByNode[nodeId] = pinnedOutputs;
|
|
1795
|
-
delete nodeSnapshotsByNodeId[nodeId];
|
|
1796
|
-
preservedPinnedNodeIds.push(nodeId);
|
|
1797
|
-
continue;
|
|
1798
|
-
}
|
|
1799
|
-
delete outputsByNode[nodeId];
|
|
1800
|
-
delete nodeSnapshotsByNodeId[nodeId];
|
|
1801
|
-
clearedNodeIds.push(nodeId);
|
|
1802
|
-
}
|
|
1803
|
-
return {
|
|
1804
|
-
currentState: {
|
|
1805
|
-
outputsByNode,
|
|
1806
|
-
nodeSnapshotsByNodeId,
|
|
1807
|
-
connectionInvocations: this.filterConnectionInvocations(args.currentState.connectionInvocations, clearedIdSet),
|
|
1808
|
-
mutableState: args.currentState.mutableState
|
|
1809
|
-
},
|
|
1810
|
-
clearedNodeIds,
|
|
1811
|
-
preservedPinnedNodeIds
|
|
1812
|
-
};
|
|
1813
|
-
}
|
|
1814
|
-
collectSatisfiedNodeIds(currentState) {
|
|
1815
|
-
const satisfiedNodeIds = [];
|
|
1816
|
-
for (const nodeId of this.topology.defsById.keys()) if (this.isNodeSatisfied(currentState, nodeId)) satisfiedNodeIds.push(nodeId);
|
|
1817
|
-
return satisfiedNodeIds;
|
|
1818
|
-
}
|
|
1819
|
-
collectFrontierNodeIds(requiredNodeIds, currentState) {
|
|
1820
|
-
const frontierNodeIds = [];
|
|
1821
|
-
for (const nodeId of this.topology.defsById.keys()) {
|
|
1822
|
-
if (!requiredNodeIds.has(nodeId) || this.isNodeSatisfied(currentState, nodeId)) continue;
|
|
1823
|
-
if ((this.topology.incomingByNode.get(nodeId) ?? []).every((edge) => this.isEdgeSatisfied(currentState, nodeId, edge.input))) frontierNodeIds.push(nodeId);
|
|
1824
|
-
}
|
|
1825
|
-
return frontierNodeIds;
|
|
1826
|
-
}
|
|
1827
|
-
collectRequiredNodeIds(stopCondition, currentState) {
|
|
1828
|
-
const requiredNodeIds = /* @__PURE__ */ new Set();
|
|
1829
|
-
if (stopCondition.kind === "workflowCompleted") {
|
|
1830
|
-
for (const nodeId of this.topology.defsById.keys()) if (!this.isNodeSatisfied(currentState, nodeId)) this.collectRequiredNode(requiredNodeIds, currentState, nodeId);
|
|
1831
|
-
return requiredNodeIds;
|
|
1832
|
-
}
|
|
1833
|
-
if (!this.topology.defsById.has(stopCondition.nodeId)) throw new Error(`Unknown stop nodeId: ${stopCondition.nodeId}`);
|
|
1834
|
-
this.collectRequiredNode(requiredNodeIds, currentState, stopCondition.nodeId);
|
|
1835
|
-
return requiredNodeIds;
|
|
1836
|
-
}
|
|
1837
|
-
collectRequiredNode(requiredNodeIds, currentState, nodeId) {
|
|
1838
|
-
if (requiredNodeIds.has(nodeId)) return;
|
|
1839
|
-
if (this.isNodeSatisfied(currentState, nodeId) && !this.isNodeSatisfiedByOutputsOnly(currentState, nodeId)) return;
|
|
1840
|
-
requiredNodeIds.add(nodeId);
|
|
1841
|
-
for (const edge of this.topology.incomingByNode.get(nodeId) ?? []) if (!this.isEdgeSatisfied(currentState, nodeId, edge.input) || this.isNodeSatisfiedByOutputsOnly(currentState, edge.from.nodeId)) this.collectRequiredNode(requiredNodeIds, currentState, edge.from.nodeId);
|
|
1842
|
-
}
|
|
1843
|
-
buildFrontierQueue(nodeId, currentState) {
|
|
1844
|
-
const incomingEdges = this.topology.incomingByNode.get(nodeId) ?? [];
|
|
1845
|
-
if (incomingEdges.length === 0) return [];
|
|
1846
|
-
const expectedInputs = this.topology.expectedInputsByNode.get(nodeId) ?? [];
|
|
1847
|
-
if (expectedInputs.length !== 1 || expectedInputs[0] !== "in") {
|
|
1848
|
-
const received = {};
|
|
1849
|
-
for (const input$1 of expectedInputs) received[input$1] = this.resolveInput(currentState, nodeId, input$1);
|
|
1850
|
-
return [{
|
|
1851
|
-
nodeId,
|
|
1852
|
-
input: [],
|
|
1853
|
-
batchId: "batch_1",
|
|
1854
|
-
collect: {
|
|
1855
|
-
expectedInputs,
|
|
1856
|
-
received
|
|
1857
|
-
}
|
|
1858
|
-
}];
|
|
1859
|
-
}
|
|
1860
|
-
const input = expectedInputs[0] ?? "in";
|
|
1861
|
-
const incomingEdge = incomingEdges.find((edge) => edge.input === input);
|
|
1862
|
-
return [{
|
|
1863
|
-
nodeId,
|
|
1864
|
-
input: this.resolveInput(currentState, nodeId, input),
|
|
1865
|
-
toInput: input,
|
|
1866
|
-
batchId: "batch_1",
|
|
1867
|
-
from: incomingEdge?.from
|
|
1868
|
-
}];
|
|
1869
|
-
}
|
|
1870
|
-
resolveRootNodeInput(args) {
|
|
1871
|
-
if (args.items) return args.items;
|
|
1872
|
-
if (args.nodeKind === "trigger") return [];
|
|
1873
|
-
return [{ json: {} }];
|
|
1874
|
-
}
|
|
1875
|
-
isNodeSatisfied(currentState, nodeId) {
|
|
1876
|
-
return this.hasOutputs(currentState, nodeId) || this.hasCompletedSnapshot(currentState, nodeId);
|
|
1877
|
-
}
|
|
1878
|
-
isNodeSatisfiedByOutputsOnly(currentState, nodeId) {
|
|
1879
|
-
return this.hasOutputs(currentState, nodeId) && !this.hasCompletedSnapshot(currentState, nodeId);
|
|
1880
|
-
}
|
|
1881
|
-
isEdgeSatisfied(currentState, nodeId, input) {
|
|
1882
|
-
const incomingEdge = (this.topology.incomingByNode.get(nodeId) ?? []).find((edge) => edge.input === input);
|
|
1883
|
-
if (!incomingEdge) return false;
|
|
1884
|
-
return this.hasOutputPort(currentState, incomingEdge.from.nodeId, incomingEdge.from.output);
|
|
1885
|
-
}
|
|
1886
|
-
resolveInput(currentState, nodeId, input) {
|
|
1887
|
-
const incomingEdge = (this.topology.incomingByNode.get(nodeId) ?? []).find((edge) => edge.input === input);
|
|
1888
|
-
if (!incomingEdge) return [];
|
|
1889
|
-
return this.resolveOutputItems(currentState, incomingEdge.from.nodeId, incomingEdge.from.output);
|
|
1890
|
-
}
|
|
1891
|
-
hasOutputs(currentState, nodeId) {
|
|
1892
|
-
return Object.prototype.hasOwnProperty.call(currentState.outputsByNode, nodeId);
|
|
1893
|
-
}
|
|
1894
|
-
hasCompletedSnapshot(currentState, nodeId) {
|
|
1895
|
-
const snapshot = currentState.nodeSnapshotsByNodeId[nodeId];
|
|
1896
|
-
return snapshot?.status === "completed" || snapshot?.status === "skipped";
|
|
1897
|
-
}
|
|
1898
|
-
hasOutputPort(currentState, nodeId, output) {
|
|
1899
|
-
const outputs = currentState.outputsByNode[nodeId];
|
|
1900
|
-
if (!outputs) return false;
|
|
1901
|
-
return Object.prototype.hasOwnProperty.call(outputs, output);
|
|
1902
|
-
}
|
|
1903
|
-
resolveOutputItems(currentState, nodeId, output) {
|
|
1904
|
-
return currentState.outputsByNode[nodeId]?.[output] ?? [];
|
|
1905
|
-
}
|
|
1906
|
-
getPinnedOutputs(currentState, nodeId) {
|
|
1907
|
-
return currentState.mutableState?.nodesById?.[nodeId]?.pinnedOutputsByPort;
|
|
1908
|
-
}
|
|
1909
|
-
filterConnectionInvocations(invocations, clearedIdSet) {
|
|
1910
|
-
if (!invocations || invocations.length === 0) return invocations;
|
|
1911
|
-
const kept = invocations.filter((invocation) => !clearedIdSet.has(invocation.parentAgentNodeId) && !clearedIdSet.has(invocation.connectionNodeId));
|
|
1912
|
-
return kept.length === invocations.length ? invocations : kept;
|
|
1913
|
-
}
|
|
1914
|
-
collectDescendants(startNodeId) {
|
|
1915
|
-
const pendingNodeIds = [startNodeId];
|
|
1916
|
-
const descendants = /* @__PURE__ */ new Set();
|
|
1917
|
-
while (pendingNodeIds.length > 0) {
|
|
1918
|
-
const nodeId = pendingNodeIds.pop();
|
|
1919
|
-
if (!nodeId || descendants.has(nodeId)) continue;
|
|
1920
|
-
descendants.add(nodeId);
|
|
1921
|
-
for (const edge of this.topology.outgoingByNode.get(nodeId) ?? []) pendingNodeIds.push(edge.to.nodeId);
|
|
1922
|
-
}
|
|
1923
|
-
return [...descendants];
|
|
1924
|
-
}
|
|
1925
|
-
collectRuntimeDescendants(currentState, descendantNodeIds) {
|
|
1926
|
-
const descendantSet = new Set(descendantNodeIds);
|
|
1927
|
-
const runtimeNodeIds = /* @__PURE__ */ new Set();
|
|
1928
|
-
for (const nodeId of [
|
|
1929
|
-
...Object.keys(currentState.outputsByNode),
|
|
1930
|
-
...Object.keys(currentState.nodeSnapshotsByNodeId),
|
|
1931
|
-
...Object.keys(currentState.mutableState?.nodesById ?? {})
|
|
1932
|
-
]) if (this.isRuntimeDescendant(nodeId, descendantSet)) runtimeNodeIds.add(nodeId);
|
|
1933
|
-
return [...runtimeNodeIds];
|
|
1934
|
-
}
|
|
1935
|
-
isRuntimeDescendant(nodeId, descendantNodeIds) {
|
|
1936
|
-
for (const descendantNodeId of descendantNodeIds) {
|
|
1937
|
-
if (nodeId === descendantNodeId) return false;
|
|
1938
|
-
if (ConnectionNodeIdFactory.isConnectionOwnedDescendantOf(descendantNodeId, nodeId)) return true;
|
|
1939
|
-
}
|
|
1940
|
-
return false;
|
|
1941
|
-
}
|
|
1942
|
-
};
|
|
1943
|
-
|
|
1944
|
-
//#endregion
|
|
1945
|
-
//#region src/policies/RunPolicySnapshotFactory.ts
|
|
1946
|
-
var RunPolicySnapshotFactory = class {
|
|
1947
|
-
static create(workflow, defaults) {
|
|
1948
|
-
const prune = workflow.prunePolicy;
|
|
1949
|
-
return {
|
|
1950
|
-
retentionSeconds: prune?.runDataRetentionSeconds ?? defaults?.retentionSeconds,
|
|
1951
|
-
binaryRetentionSeconds: prune?.binaryRetentionSeconds ?? defaults?.binaryRetentionSeconds,
|
|
1952
|
-
storagePolicy: typeof workflow.storagePolicy === "string" ? workflow.storagePolicy : defaults?.storagePolicy ?? "ALL"
|
|
1953
|
-
};
|
|
1954
|
-
}
|
|
1955
|
-
};
|
|
1956
|
-
|
|
1957
|
-
//#endregion
|
|
1958
|
-
//#region src/orchestration/RunStartService.ts
|
|
1959
|
-
var RunStartService = class {
|
|
1960
|
-
constructor(runIdFactory, runStore, runDataFactory, workflowSnapshotFactory, planningFactory, nodeStatePublisherFactory, runExecutionContextFactory, nodeActivationRequestComposer, activationEnqueueService, semantics, waiters, workflowPolicyRuntimeDefaults, executionLimitsPolicy) {
|
|
1961
|
-
this.runIdFactory = runIdFactory;
|
|
1962
|
-
this.runStore = runStore;
|
|
1963
|
-
this.runDataFactory = runDataFactory;
|
|
1964
|
-
this.workflowSnapshotFactory = workflowSnapshotFactory;
|
|
1965
|
-
this.planningFactory = planningFactory;
|
|
1966
|
-
this.nodeStatePublisherFactory = nodeStatePublisherFactory;
|
|
1967
|
-
this.runExecutionContextFactory = runExecutionContextFactory;
|
|
1968
|
-
this.nodeActivationRequestComposer = nodeActivationRequestComposer;
|
|
1969
|
-
this.activationEnqueueService = activationEnqueueService;
|
|
1970
|
-
this.semantics = semantics;
|
|
1971
|
-
this.waiters = waiters;
|
|
1972
|
-
this.workflowPolicyRuntimeDefaults = workflowPolicyRuntimeDefaults;
|
|
1973
|
-
this.executionLimitsPolicy = executionLimitsPolicy;
|
|
1974
|
-
}
|
|
1975
|
-
async runWorkflow(workflow, startAt, items, parent, executionOptions, persistedStateOverrides) {
|
|
1976
|
-
const runId = this.runIdFactory.makeRunId();
|
|
1977
|
-
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1978
|
-
const workflowSnapshot = persistedStateOverrides?.workflowSnapshot ?? this.workflowSnapshotFactory.create(workflow);
|
|
1979
|
-
const mutableState = persistedStateOverrides?.mutableState;
|
|
1980
|
-
const policySnapshot = RunPolicySnapshotFactory.create(workflow, this.workflowPolicyRuntimeDefaults);
|
|
1981
|
-
const mergedExecutionOptions = this.executionLimitsPolicy.mergeExecutionOptionsForNewRun(parent, executionOptions);
|
|
1982
|
-
await this.runStore.createRun({
|
|
1983
|
-
runId,
|
|
1984
|
-
workflowId: workflow.id,
|
|
1985
|
-
startedAt,
|
|
1986
|
-
parent,
|
|
1987
|
-
executionOptions: mergedExecutionOptions,
|
|
1988
|
-
workflowSnapshot,
|
|
1989
|
-
mutableState,
|
|
1990
|
-
policySnapshot,
|
|
1991
|
-
engineCounters: { completedNodeActivations: 0 }
|
|
1992
|
-
});
|
|
1993
|
-
const data = this.runDataFactory.create();
|
|
1994
|
-
const base = this.runExecutionContextFactory.create({
|
|
1995
|
-
runId,
|
|
1996
|
-
workflowId: workflow.id,
|
|
1997
|
-
nodeId: startAt,
|
|
1998
|
-
parent,
|
|
1999
|
-
subworkflowDepth: mergedExecutionOptions.subworkflowDepth ?? 0,
|
|
2000
|
-
engineMaxNodeActivations: mergedExecutionOptions.maxNodeActivations,
|
|
2001
|
-
engineMaxSubworkflowDepth: mergedExecutionOptions.maxSubworkflowDepth,
|
|
2002
|
-
data,
|
|
2003
|
-
nodeState: this.nodeStatePublisherFactory.create(runId, workflow.id, parent)
|
|
2004
|
-
});
|
|
2005
|
-
const { topology, planner } = this.planningFactory.create(workflow);
|
|
2006
|
-
const startDefinition = topology.defsById.get(startAt);
|
|
2007
|
-
if (!startDefinition) throw new Error(`Unknown start nodeId: ${startAt}`);
|
|
2008
|
-
const initialNodeSnapshotsByNodeId = {};
|
|
2009
|
-
if (startDefinition.kind === "trigger") {
|
|
2010
|
-
const request = this.nodeActivationRequestComposer.createSingleFromDefinition({
|
|
2011
|
-
runId,
|
|
2012
|
-
workflowId: workflow.id,
|
|
2013
|
-
definition: startDefinition,
|
|
2014
|
-
parent,
|
|
2015
|
-
executionOptions: mergedExecutionOptions,
|
|
2016
|
-
batchId: "batch_1",
|
|
2017
|
-
input: items,
|
|
2018
|
-
base,
|
|
2019
|
-
data
|
|
2020
|
-
});
|
|
2021
|
-
return await this.activationEnqueueService.enqueueActivation({
|
|
2022
|
-
runId,
|
|
2023
|
-
workflowId: workflow.id,
|
|
2024
|
-
startedAt,
|
|
2025
|
-
parent,
|
|
2026
|
-
executionOptions: mergedExecutionOptions,
|
|
2027
|
-
workflowSnapshot,
|
|
2028
|
-
mutableState,
|
|
2029
|
-
policySnapshot,
|
|
2030
|
-
control: void 0,
|
|
2031
|
-
pendingQueue: [],
|
|
2032
|
-
request,
|
|
2033
|
-
previousNodeSnapshotsByNodeId: initialNodeSnapshotsByNodeId,
|
|
2034
|
-
planner,
|
|
2035
|
-
engineCounters: { completedNodeActivations: 0 },
|
|
2036
|
-
connectionInvocations: []
|
|
2037
|
-
});
|
|
2038
|
-
}
|
|
2039
|
-
const queue = [{
|
|
2040
|
-
nodeId: startAt,
|
|
2041
|
-
input: items,
|
|
2042
|
-
toInput: "in",
|
|
2043
|
-
batchId: "batch_1"
|
|
2044
|
-
}];
|
|
2045
|
-
return await this.scheduleQueuedPlan({
|
|
2046
|
-
runId,
|
|
2047
|
-
workflowId: workflow.id,
|
|
2048
|
-
startedAt,
|
|
2049
|
-
parent,
|
|
2050
|
-
executionOptions: mergedExecutionOptions,
|
|
2051
|
-
control: void 0,
|
|
2052
|
-
workflowSnapshot,
|
|
2053
|
-
mutableState,
|
|
2054
|
-
policySnapshot,
|
|
2055
|
-
workflow,
|
|
2056
|
-
planner,
|
|
2057
|
-
queue,
|
|
2058
|
-
base,
|
|
2059
|
-
data,
|
|
2060
|
-
nodeSnapshotsByNodeId: initialNodeSnapshotsByNodeId,
|
|
2061
|
-
connectionInvocations: []
|
|
2062
|
-
});
|
|
2063
|
-
}
|
|
2064
|
-
async runWorkflowFromState(request) {
|
|
2065
|
-
const runId = this.runIdFactory.makeRunId();
|
|
2066
|
-
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2067
|
-
const workflowSnapshot = request.workflowSnapshot ?? this.workflowSnapshotFactory.create(request.workflow);
|
|
2068
|
-
const mutableState = request.mutableState ?? request.currentState?.mutableState;
|
|
2069
|
-
const policySnapshot = RunPolicySnapshotFactory.create(request.workflow, this.workflowPolicyRuntimeDefaults);
|
|
2070
|
-
const control = { stopCondition: request.stopCondition ?? { kind: "workflowCompleted" } };
|
|
2071
|
-
const mergedExecutionOptions = this.executionLimitsPolicy.mergeExecutionOptionsForNewRun(request.parent, request.executionOptions);
|
|
2072
|
-
await this.runStore.createRun({
|
|
2073
|
-
runId,
|
|
2074
|
-
workflowId: request.workflow.id,
|
|
2075
|
-
startedAt,
|
|
2076
|
-
parent: request.parent,
|
|
2077
|
-
executionOptions: mergedExecutionOptions,
|
|
2078
|
-
control,
|
|
2079
|
-
workflowSnapshot,
|
|
2080
|
-
mutableState,
|
|
2081
|
-
policySnapshot,
|
|
2082
|
-
engineCounters: { completedNodeActivations: 0 }
|
|
2083
|
-
});
|
|
2084
|
-
const { topology, planner } = this.planningFactory.create(request.workflow);
|
|
2085
|
-
const plan = CurrentStateFrontierPlanner.createFromTopology(topology).plan({
|
|
2086
|
-
currentState: this.createRunCurrentState(request.currentState, mutableState),
|
|
2087
|
-
stopCondition: control.stopCondition,
|
|
2088
|
-
reset: request.reset,
|
|
2089
|
-
items: request.items
|
|
2090
|
-
});
|
|
2091
|
-
const data = this.runDataFactory.create(plan.currentState.outputsByNode);
|
|
2092
|
-
const base = this.runExecutionContextFactory.create({
|
|
2093
|
-
runId,
|
|
2094
|
-
workflowId: request.workflow.id,
|
|
2095
|
-
nodeId: createWorkflowExecutableNodeClassifier(request.workflow).firstExecutableNodeIdInDefinitionOrder(request.workflow) ?? "unknown_node",
|
|
2096
|
-
parent: request.parent,
|
|
2097
|
-
subworkflowDepth: mergedExecutionOptions.subworkflowDepth ?? 0,
|
|
2098
|
-
engineMaxNodeActivations: mergedExecutionOptions.maxNodeActivations,
|
|
2099
|
-
engineMaxSubworkflowDepth: mergedExecutionOptions.maxSubworkflowDepth,
|
|
2100
|
-
data,
|
|
2101
|
-
nodeState: this.nodeStatePublisherFactory.create(runId, request.workflow.id, request.parent)
|
|
2102
|
-
});
|
|
2103
|
-
return await this.scheduleInitialPlan({
|
|
2104
|
-
runId,
|
|
2105
|
-
startedAt,
|
|
2106
|
-
workflow: request.workflow,
|
|
2107
|
-
workflowSnapshot,
|
|
2108
|
-
mutableState,
|
|
2109
|
-
policySnapshot,
|
|
2110
|
-
executionOptions: mergedExecutionOptions,
|
|
2111
|
-
control,
|
|
2112
|
-
parent: request.parent,
|
|
2113
|
-
planner,
|
|
2114
|
-
plan,
|
|
2115
|
-
base,
|
|
2116
|
-
data
|
|
2117
|
-
});
|
|
2118
|
-
}
|
|
2119
|
-
createRunCurrentState(currentState, mutableState) {
|
|
2120
|
-
return {
|
|
2121
|
-
outputsByNode: { ...currentState?.outputsByNode ?? {} },
|
|
2122
|
-
nodeSnapshotsByNodeId: { ...currentState?.nodeSnapshotsByNodeId ?? {} },
|
|
2123
|
-
connectionInvocations: currentState?.connectionInvocations ? [...currentState.connectionInvocations] : void 0,
|
|
2124
|
-
mutableState: mutableState ?? currentState?.mutableState
|
|
2125
|
-
};
|
|
2126
|
-
}
|
|
2127
|
-
async scheduleInitialPlan(args) {
|
|
2128
|
-
const initialNodeSnapshotsByNodeId = this.semantics.applySkippedSnapshots({
|
|
2129
|
-
runId: args.runId,
|
|
2130
|
-
workflowId: args.workflow.id,
|
|
2131
|
-
parent: args.parent,
|
|
2132
|
-
currentState: args.plan.currentState,
|
|
2133
|
-
skippedNodeIds: args.plan.skippedNodeIds,
|
|
2134
|
-
preservedPinnedNodeIds: args.plan.preservedPinnedNodeIds,
|
|
2135
|
-
finishedAt: args.startedAt
|
|
2136
|
-
});
|
|
2137
|
-
if (args.plan.rootNodeId) {
|
|
2138
|
-
const startDef = WorkflowTopology.fromWorkflow(args.workflow).defsById.get(args.plan.rootNodeId);
|
|
2139
|
-
if (!startDef) throw new Error(`Unknown frontier nodeId: ${args.plan.rootNodeId}`);
|
|
2140
|
-
const startItems = args.plan.rootNodeInput ?? [];
|
|
2141
|
-
const request = this.nodeActivationRequestComposer.createSingleFromDefinition({
|
|
2142
|
-
runId: args.runId,
|
|
2143
|
-
workflowId: args.workflow.id,
|
|
2144
|
-
definition: startDef,
|
|
2145
|
-
parent: args.parent,
|
|
2146
|
-
executionOptions: args.executionOptions,
|
|
2147
|
-
batchId: "batch_1",
|
|
2148
|
-
input: startItems,
|
|
2149
|
-
base: args.base,
|
|
2150
|
-
data: args.data
|
|
2151
|
-
});
|
|
2152
|
-
return await this.activationEnqueueService.enqueueActivation({
|
|
2153
|
-
runId: args.runId,
|
|
2154
|
-
workflowId: args.workflow.id,
|
|
2155
|
-
startedAt: args.startedAt,
|
|
2156
|
-
parent: args.parent,
|
|
2157
|
-
executionOptions: args.executionOptions,
|
|
2158
|
-
control: args.control,
|
|
2159
|
-
workflowSnapshot: args.workflowSnapshot,
|
|
2160
|
-
mutableState: args.mutableState,
|
|
2161
|
-
policySnapshot: args.policySnapshot,
|
|
2162
|
-
pendingQueue: [],
|
|
2163
|
-
request,
|
|
2164
|
-
previousNodeSnapshotsByNodeId: initialNodeSnapshotsByNodeId,
|
|
2165
|
-
planner: args.planner,
|
|
2166
|
-
engineCounters: { completedNodeActivations: 0 },
|
|
2167
|
-
connectionInvocations: args.plan.currentState.connectionInvocations ?? []
|
|
2168
|
-
});
|
|
2169
|
-
}
|
|
2170
|
-
return await this.scheduleQueuedPlan({
|
|
2171
|
-
runId: args.runId,
|
|
2172
|
-
workflowId: args.workflow.id,
|
|
2173
|
-
startedAt: args.startedAt,
|
|
2174
|
-
parent: args.parent,
|
|
2175
|
-
executionOptions: args.executionOptions,
|
|
2176
|
-
control: args.control,
|
|
2177
|
-
workflowSnapshot: args.workflowSnapshot,
|
|
2178
|
-
mutableState: args.mutableState,
|
|
2179
|
-
policySnapshot: args.policySnapshot,
|
|
2180
|
-
workflow: args.workflow,
|
|
2181
|
-
planner: args.planner,
|
|
2182
|
-
queue: [...args.plan.queue],
|
|
2183
|
-
base: args.base,
|
|
2184
|
-
data: args.data,
|
|
2185
|
-
nodeSnapshotsByNodeId: initialNodeSnapshotsByNodeId,
|
|
2186
|
-
connectionInvocations: args.plan.currentState.connectionInvocations ?? []
|
|
2187
|
-
});
|
|
2188
|
-
}
|
|
2189
|
-
async scheduleQueuedPlan(args) {
|
|
2190
|
-
this.semantics.applyPinnedQueueSkips({
|
|
2191
|
-
runId: args.runId,
|
|
2192
|
-
workflowId: args.workflowId,
|
|
2193
|
-
parent: args.parent,
|
|
2194
|
-
mutableState: args.mutableState,
|
|
2195
|
-
planner: args.planner,
|
|
2196
|
-
queue: args.queue,
|
|
2197
|
-
data: args.data,
|
|
2198
|
-
nodeSnapshotsByNodeId: args.nodeSnapshotsByNodeId,
|
|
2199
|
-
finishedAt: args.startedAt
|
|
2200
|
-
});
|
|
2201
|
-
const next = args.planner.nextActivation(args.queue);
|
|
2202
|
-
if (!next) return await this.completeRun({
|
|
2203
|
-
runId: args.runId,
|
|
2204
|
-
workflowId: args.workflowId,
|
|
2205
|
-
startedAt: args.startedAt,
|
|
2206
|
-
parent: args.parent,
|
|
2207
|
-
executionOptions: args.executionOptions,
|
|
2208
|
-
control: args.control,
|
|
2209
|
-
workflowSnapshot: args.workflowSnapshot,
|
|
2210
|
-
mutableState: args.mutableState,
|
|
2211
|
-
policySnapshot: args.policySnapshot,
|
|
2212
|
-
workflow: args.workflow,
|
|
2213
|
-
data: args.data,
|
|
2214
|
-
nodeSnapshotsByNodeId: args.nodeSnapshotsByNodeId,
|
|
2215
|
-
connectionInvocations: args.connectionInvocations
|
|
2216
|
-
});
|
|
2217
|
-
const definition = WorkflowTopology.fromWorkflow(args.workflow).defsById.get(next.nodeId);
|
|
2218
|
-
if (!definition || definition.kind !== "node") throw new Error(`Node ${next.nodeId} is not a runnable node`);
|
|
2219
|
-
const request = this.nodeActivationRequestComposer.createFromPlannedActivation({
|
|
2220
|
-
next,
|
|
2221
|
-
base: args.base,
|
|
2222
|
-
data: args.data,
|
|
2223
|
-
runId: args.runId,
|
|
2224
|
-
workflowId: args.workflowId,
|
|
2225
|
-
parent: args.parent,
|
|
2226
|
-
executionOptions: args.executionOptions,
|
|
2227
|
-
nodeDefinition: definition
|
|
2228
|
-
});
|
|
2229
|
-
return await this.activationEnqueueService.enqueueActivation({
|
|
2230
|
-
runId: args.runId,
|
|
2231
|
-
workflowId: args.workflowId,
|
|
2232
|
-
startedAt: args.startedAt,
|
|
2233
|
-
parent: args.parent,
|
|
2234
|
-
executionOptions: args.executionOptions,
|
|
2235
|
-
control: args.control,
|
|
2236
|
-
workflowSnapshot: args.workflowSnapshot,
|
|
2237
|
-
mutableState: args.mutableState,
|
|
2238
|
-
policySnapshot: args.policySnapshot,
|
|
2239
|
-
pendingQueue: args.queue,
|
|
2240
|
-
request,
|
|
2241
|
-
previousNodeSnapshotsByNodeId: args.nodeSnapshotsByNodeId,
|
|
2242
|
-
planner: args.planner,
|
|
2243
|
-
engineCounters: { completedNodeActivations: 0 },
|
|
2244
|
-
connectionInvocations: args.connectionInvocations ?? []
|
|
2245
|
-
});
|
|
2246
|
-
}
|
|
2247
|
-
async completeRun(args) {
|
|
2248
|
-
await this.runStore.save({
|
|
2249
|
-
runId: args.runId,
|
|
2250
|
-
workflowId: args.workflowId,
|
|
2251
|
-
startedAt: args.startedAt,
|
|
2252
|
-
parent: args.parent,
|
|
2253
|
-
executionOptions: args.executionOptions,
|
|
2254
|
-
control: args.control,
|
|
2255
|
-
workflowSnapshot: args.workflowSnapshot,
|
|
2256
|
-
mutableState: args.mutableState,
|
|
2257
|
-
policySnapshot: args.policySnapshot,
|
|
2258
|
-
engineCounters: { completedNodeActivations: 0 },
|
|
2259
|
-
connectionInvocations: args.connectionInvocations ? [...args.connectionInvocations] : [],
|
|
2260
|
-
status: "completed",
|
|
2261
|
-
pending: void 0,
|
|
2262
|
-
queue: [],
|
|
2263
|
-
outputsByNode: args.data.dump(),
|
|
2264
|
-
nodeSnapshotsByNodeId: args.nodeSnapshotsByNodeId
|
|
2265
|
-
});
|
|
2266
|
-
const result = {
|
|
2267
|
-
runId: args.runId,
|
|
2268
|
-
workflowId: args.workflowId,
|
|
2269
|
-
startedAt: args.startedAt,
|
|
2270
|
-
status: "completed",
|
|
2271
|
-
outputs: this.semantics.resolveResultOutputs(args.workflow, args.control?.stopCondition, args.data.dump())
|
|
2272
|
-
};
|
|
2273
|
-
this.waiters.resolveRunCompletion(result);
|
|
2274
|
-
return result;
|
|
2275
|
-
}
|
|
2276
|
-
};
|
|
2277
|
-
|
|
2278
|
-
//#endregion
|
|
2279
|
-
//#region src/scheduler/ConfigDrivenOffloadPolicy.ts
|
|
2280
|
-
var ConfigDrivenOffloadPolicy = class {
|
|
2281
|
-
defaultMode;
|
|
2282
|
-
constructor(defaultMode = "worker") {
|
|
2283
|
-
this.defaultMode = defaultMode;
|
|
2284
|
-
}
|
|
2285
|
-
decide(args) {
|
|
2286
|
-
const hint = args.config.execution?.hint;
|
|
2287
|
-
const queue = args.config.execution?.queue;
|
|
2288
|
-
if (hint === "local") return { mode: "local" };
|
|
2289
|
-
if (hint === "worker") return {
|
|
2290
|
-
mode: "worker",
|
|
2291
|
-
queue
|
|
2292
|
-
};
|
|
2293
|
-
if (queue) return {
|
|
2294
|
-
mode: "worker",
|
|
2295
|
-
queue
|
|
2296
|
-
};
|
|
2297
|
-
return { mode: this.defaultMode };
|
|
2298
|
-
}
|
|
2299
|
-
};
|
|
2300
|
-
|
|
2301
|
-
//#endregion
|
|
2302
|
-
//#region src/scheduler/DefaultDrivingScheduler.ts
|
|
2303
|
-
var DefaultDrivingScheduler = class {
|
|
2304
|
-
constructor(offloadPolicy, workerScheduler, inline) {
|
|
2305
|
-
this.offloadPolicy = offloadPolicy;
|
|
2306
|
-
this.workerScheduler = workerScheduler;
|
|
2307
|
-
this.inline = inline;
|
|
2308
|
-
}
|
|
2309
|
-
setContinuation(continuation) {
|
|
2310
|
-
this.inline.setContinuation(continuation);
|
|
2311
|
-
}
|
|
2312
|
-
async enqueue(request) {
|
|
2313
|
-
if (request.executionOptions?.localOnly) return {
|
|
2314
|
-
...await this.inline.enqueue(request),
|
|
2315
|
-
mode: "local"
|
|
2316
|
-
};
|
|
2317
|
-
const decision = this.offloadPolicy.decide({
|
|
2318
|
-
workflowId: request.workflowId,
|
|
2319
|
-
nodeId: request.nodeId,
|
|
2320
|
-
config: request.ctx.config
|
|
2321
|
-
});
|
|
2322
|
-
if (decision.mode === "worker") {
|
|
2323
|
-
if (request.kind === "multi") throw new Error(`Multi-input node ${request.nodeId} cannot be scheduled to worker (insert local placement)`);
|
|
2324
|
-
const workerRequest = {
|
|
2325
|
-
runId: request.runId,
|
|
2326
|
-
activationId: request.activationId,
|
|
2327
|
-
workflowId: request.workflowId,
|
|
2328
|
-
nodeId: request.nodeId,
|
|
2329
|
-
input: request.input,
|
|
2330
|
-
parent: request.parent,
|
|
2331
|
-
queue: decision.queue,
|
|
2332
|
-
executionOptions: request.executionOptions
|
|
2333
|
-
};
|
|
2334
|
-
return {
|
|
2335
|
-
receiptId: (await this.workerScheduler.enqueue(workerRequest)).receiptId,
|
|
2336
|
-
mode: "worker",
|
|
2337
|
-
queue: decision.queue
|
|
2338
|
-
};
|
|
2339
|
-
}
|
|
2340
|
-
return {
|
|
2341
|
-
...await this.inline.enqueue(request),
|
|
2342
|
-
mode: "local"
|
|
2343
|
-
};
|
|
2344
|
-
}
|
|
2345
|
-
notifyPendingStatePersisted(runId) {
|
|
2346
|
-
this.inline.notifyPendingStatePersisted(runId);
|
|
2347
|
-
}
|
|
2348
|
-
};
|
|
2349
|
-
|
|
2350
|
-
//#endregion
|
|
2351
|
-
//#region src/scheduler/HintOnlyOffloadPolicy.ts
|
|
2352
|
-
var HintOnlyOffloadPolicy = class {
|
|
2353
|
-
decide(args) {
|
|
2354
|
-
if (args.config.execution?.hint === "worker") return {
|
|
2355
|
-
mode: "worker",
|
|
2356
|
-
queue: args.config.execution?.queue
|
|
2357
|
-
};
|
|
2358
|
-
return { mode: "local" };
|
|
2359
|
-
}
|
|
2360
|
-
};
|
|
2361
|
-
|
|
2362
|
-
//#endregion
|
|
2363
|
-
//#region src/scheduler/InlineDrivingScheduler.ts
|
|
2364
|
-
var _ref$2;
|
|
2365
|
-
let InlineDrivingScheduler = class InlineDrivingScheduler$1 {
|
|
2366
|
-
continuation;
|
|
2367
|
-
drainingRuns = /* @__PURE__ */ new Set();
|
|
2368
|
-
queuesByRunId = /* @__PURE__ */ new Map();
|
|
2369
|
-
scheduledRuns = /* @__PURE__ */ new Set();
|
|
2370
|
-
seq = 0;
|
|
2371
|
-
constructor(nodeExecutor) {
|
|
2372
|
-
this.nodeExecutor = nodeExecutor;
|
|
2373
|
-
}
|
|
2374
|
-
setContinuation(continuation) {
|
|
2375
|
-
this.continuation = continuation;
|
|
2376
|
-
}
|
|
2377
|
-
async enqueue(request) {
|
|
2378
|
-
const receipt = {
|
|
2379
|
-
receiptId: `inline_${++this.seq}`,
|
|
2380
|
-
mode: "local"
|
|
2381
|
-
};
|
|
2382
|
-
const q = this.queuesByRunId.get(request.runId) ?? [];
|
|
2383
|
-
q.push({
|
|
2384
|
-
request,
|
|
2385
|
-
receipt
|
|
2386
|
-
});
|
|
2387
|
-
this.queuesByRunId.set(request.runId, q);
|
|
2388
|
-
return receipt;
|
|
2389
|
-
}
|
|
2390
|
-
notifyPendingStatePersisted(runId) {
|
|
2391
|
-
if ((this.queuesByRunId.get(runId)?.length ?? 0) === 0) return;
|
|
2392
|
-
this.scheduleDrain(runId);
|
|
2393
|
-
}
|
|
2394
|
-
async drainRun(runId) {
|
|
2395
|
-
if (this.drainingRuns.has(runId)) return;
|
|
2396
|
-
this.drainingRuns.add(runId);
|
|
2397
|
-
this.scheduledRuns.delete(runId);
|
|
2398
|
-
try {
|
|
2399
|
-
const q = this.queuesByRunId.get(runId) ?? [];
|
|
2400
|
-
while (q.length > 0) {
|
|
2401
|
-
const { request } = q.shift();
|
|
2402
|
-
const cont = this.continuation;
|
|
2403
|
-
if (!cont) throw new Error("InlineDrivingScheduler is missing a continuation (setContinuation was not called)");
|
|
2404
|
-
await cont.markNodeRunning({
|
|
2405
|
-
runId: request.runId,
|
|
2406
|
-
activationId: request.activationId,
|
|
2407
|
-
nodeId: request.nodeId,
|
|
2408
|
-
inputsByPort: request.kind === "multi" ? request.inputsByPort : { in: request.input }
|
|
2409
|
-
});
|
|
2410
|
-
let outputs;
|
|
2411
|
-
try {
|
|
2412
|
-
outputs = await this.nodeExecutor.execute(request);
|
|
2413
|
-
} catch (e) {
|
|
2414
|
-
await this.resumeAfterExecutionError(cont, request, this.asError(e));
|
|
2415
|
-
continue;
|
|
2416
|
-
}
|
|
2417
|
-
await this.resumeAfterExecutionResult(cont, request, outputs ?? {});
|
|
2418
|
-
}
|
|
2419
|
-
} finally {
|
|
2420
|
-
if ((this.queuesByRunId.get(runId)?.length ?? 0) === 0) this.queuesByRunId.delete(runId);
|
|
2421
|
-
this.drainingRuns.delete(runId);
|
|
2422
|
-
if ((this.queuesByRunId.get(runId)?.length ?? 0) > 0) this.scheduleDrain(runId);
|
|
2423
|
-
}
|
|
2424
|
-
}
|
|
2425
|
-
scheduleDrain(runId) {
|
|
2426
|
-
if (this.drainingRuns.has(runId) || this.scheduledRuns.has(runId)) return;
|
|
2427
|
-
this.scheduledRuns.add(runId);
|
|
2428
|
-
setTimeout(() => {
|
|
2429
|
-
this.scheduledRuns.delete(runId);
|
|
2430
|
-
this.drainRun(runId);
|
|
2431
|
-
}, 0);
|
|
2432
|
-
}
|
|
2433
|
-
async resumeAfterExecutionResult(continuation, request, outputs) {
|
|
2434
|
-
try {
|
|
2435
|
-
await continuation.resumeFromNodeResult({
|
|
2436
|
-
runId: request.runId,
|
|
2437
|
-
activationId: request.activationId,
|
|
2438
|
-
nodeId: request.nodeId,
|
|
2439
|
-
outputs
|
|
2440
|
-
});
|
|
2441
|
-
} catch (e) {
|
|
2442
|
-
this.rethrowUnlessIgnorableContinuationError(e);
|
|
2443
|
-
}
|
|
2444
|
-
}
|
|
2445
|
-
async resumeAfterExecutionError(continuation, request, error) {
|
|
2446
|
-
try {
|
|
2447
|
-
await continuation.resumeFromNodeError({
|
|
2448
|
-
runId: request.runId,
|
|
2449
|
-
activationId: request.activationId,
|
|
2450
|
-
nodeId: request.nodeId,
|
|
2451
|
-
error
|
|
2452
|
-
});
|
|
2453
|
-
} catch (e) {
|
|
2454
|
-
this.rethrowUnlessIgnorableContinuationError(e);
|
|
2455
|
-
}
|
|
2456
|
-
}
|
|
2457
|
-
asError(e) {
|
|
2458
|
-
return e instanceof Error ? e : new Error(String(e));
|
|
2459
|
-
}
|
|
2460
|
-
rethrowUnlessIgnorableContinuationError(e) {
|
|
2461
|
-
if (this.isIgnorableContinuationError(e)) return;
|
|
2462
|
-
throw this.asError(e);
|
|
2463
|
-
}
|
|
2464
|
-
isIgnorableContinuationError(e) {
|
|
2465
|
-
const message = this.asError(e).message;
|
|
2466
|
-
return message.includes(" is not pending") || message.includes("activationId mismatch") || message.includes("nodeId mismatch");
|
|
2467
|
-
}
|
|
2468
|
-
};
|
|
2469
|
-
InlineDrivingScheduler = __decorate([
|
|
2470
|
-
(0, tsyringe.injectable)(),
|
|
2471
|
-
__decorateParam(0, (0, tsyringe.inject)(NodeExecutor)),
|
|
2472
|
-
__decorateMetadata("design:paramtypes", [typeof (_ref$2 = typeof NodeExecutor !== "undefined" && NodeExecutor) === "function" ? _ref$2 : Object])
|
|
2473
|
-
], InlineDrivingScheduler);
|
|
2474
|
-
|
|
2475
|
-
//#endregion
|
|
2476
|
-
//#region src/scheduler/LocalOnlyScheduler.ts
|
|
2477
|
-
var LocalOnlyScheduler = class {
|
|
2478
|
-
async enqueue(_request) {
|
|
2479
|
-
throw new Error("No worker scheduler configured");
|
|
2480
|
-
}
|
|
2481
|
-
};
|
|
2482
|
-
|
|
2483
|
-
//#endregion
|
|
2484
|
-
//#region src/executionContext/CredentialResolverFactory.ts
|
|
2485
|
-
var CredentialResolverFactory = class {
|
|
2486
|
-
constructor(credentialSessions) {
|
|
2487
|
-
this.credentialSessions = credentialSessions;
|
|
2488
|
-
}
|
|
2489
|
-
create(workflowId, nodeId, config) {
|
|
2490
|
-
const acceptedTypesBySlot = /* @__PURE__ */ new Map();
|
|
2491
|
-
for (const requirement of config?.getCredentialRequirements?.() ?? []) acceptedTypesBySlot.set(requirement.slotKey, requirement.acceptedTypes);
|
|
2492
|
-
return async (slotKey) => {
|
|
2493
|
-
try {
|
|
2494
|
-
return await this.credentialSessions.getSession({
|
|
2495
|
-
workflowId,
|
|
2496
|
-
nodeId,
|
|
2497
|
-
slotKey
|
|
2498
|
-
});
|
|
2499
|
-
} catch (error) {
|
|
2500
|
-
const acceptedTypes = acceptedTypesBySlot.get(slotKey) ?? [];
|
|
2501
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2502
|
-
const alreadyListsAcceptedTypes = message.includes("Accepted types:") || message.includes("Accepted credential types:") || message.includes("binding points at an unknown type");
|
|
2503
|
-
const acceptedTypesSuffix = acceptedTypes.length > 0 && !alreadyListsAcceptedTypes ? ` Accepted types: ${acceptedTypes.join(", ")}.` : "";
|
|
2504
|
-
throw new Error(`Failed to resolve credential for workflow ${workflowId} node ${nodeId} slot "${slotKey}". ${message}${acceptedTypesSuffix}`, { cause: error });
|
|
2505
|
-
}
|
|
2506
|
-
};
|
|
2507
|
-
}
|
|
2508
|
-
};
|
|
2509
|
-
|
|
2510
|
-
//#endregion
|
|
2511
|
-
//#region src/executionContext/DefaultExecutionContextFactory.ts
|
|
2512
|
-
var DefaultExecutionContextFactory = class {
|
|
2513
|
-
constructor(binaryStorage = new UnavailableBinaryStorage(), currentDate = () => /* @__PURE__ */ new Date()) {
|
|
2514
|
-
this.binaryStorage = binaryStorage;
|
|
2515
|
-
this.currentDate = currentDate;
|
|
2516
|
-
}
|
|
2517
|
-
create(args) {
|
|
2518
|
-
return {
|
|
2519
|
-
runId: args.runId,
|
|
2520
|
-
workflowId: args.workflowId,
|
|
2521
|
-
parent: args.parent,
|
|
2522
|
-
subworkflowDepth: args.subworkflowDepth,
|
|
2523
|
-
engineMaxNodeActivations: args.engineMaxNodeActivations,
|
|
2524
|
-
engineMaxSubworkflowDepth: args.engineMaxSubworkflowDepth,
|
|
2525
|
-
now: this.currentDate,
|
|
2526
|
-
data: args.data,
|
|
2527
|
-
nodeState: args.nodeState,
|
|
2528
|
-
binary: new DefaultExecutionBinaryService(this.binaryStorage, args.workflowId, args.runId, this.currentDate),
|
|
2529
|
-
getCredential: args.getCredential
|
|
2530
|
-
};
|
|
2531
|
-
}
|
|
2532
|
-
};
|
|
2533
|
-
|
|
2534
|
-
//#endregion
|
|
2535
|
-
//#region src/policies/EngineExecutionLimitsPolicy.ts
|
|
2536
|
-
/** Framework defaults for {@link EngineExecutionLimitsPolicy} (merged with host `runtime.engineExecutionLimits`). */
|
|
2537
|
-
const ENGINE_EXECUTION_LIMITS_DEFAULTS = {
|
|
2538
|
-
defaultMaxNodeActivations: 1e5,
|
|
2539
|
-
hardMaxNodeActivations: 1e5,
|
|
2540
|
-
defaultMaxSubworkflowDepth: 32,
|
|
2541
|
-
hardMaxSubworkflowDepth: 32
|
|
2542
|
-
};
|
|
2543
|
-
/**
|
|
2544
|
-
* Resolves per-run execution limits: defaults, hard ceilings, and subworkflow depth for new runs.
|
|
2545
|
-
*/
|
|
2546
|
-
var EngineExecutionLimitsPolicy = class {
|
|
2547
|
-
constructor(config = ENGINE_EXECUTION_LIMITS_DEFAULTS) {
|
|
2548
|
-
this.config = config;
|
|
2549
|
-
}
|
|
2550
|
-
/**
|
|
2551
|
-
* Effective options for a new root run (depth 0): defaults merged with engine ceilings.
|
|
2552
|
-
* Replaces a separate one-method factory for root-run bootstrap.
|
|
2553
|
-
*/
|
|
2554
|
-
createRootExecutionOptions() {
|
|
2555
|
-
return this.mergeExecutionOptionsForNewRun(void 0, void 0);
|
|
2556
|
-
}
|
|
2557
|
-
mergeExecutionOptionsForNewRun(parent, user) {
|
|
2558
|
-
const subworkflowDepth = parent === void 0 ? 0 : (parent.subworkflowDepth ?? 0) + 1;
|
|
2559
|
-
const inheritedMaxNode = parent?.engineMaxNodeActivations;
|
|
2560
|
-
const inheritedMaxSub = parent?.engineMaxSubworkflowDepth;
|
|
2561
|
-
const maxNodeActivations = this.capNumber(user?.maxNodeActivations ?? inheritedMaxNode, this.config.defaultMaxNodeActivations, this.config.hardMaxNodeActivations);
|
|
2562
|
-
const maxSubworkflowDepth = this.capNumber(user?.maxSubworkflowDepth ?? inheritedMaxSub, this.config.defaultMaxSubworkflowDepth, this.config.hardMaxSubworkflowDepth);
|
|
2563
|
-
if (subworkflowDepth > maxSubworkflowDepth) throw new Error(`Subworkflow nesting depth ${subworkflowDepth} exceeds maxSubworkflowDepth ${maxSubworkflowDepth} (run would be a child of parent run).`);
|
|
2564
|
-
return {
|
|
2565
|
-
...user,
|
|
2566
|
-
subworkflowDepth,
|
|
2567
|
-
maxNodeActivations,
|
|
2568
|
-
maxSubworkflowDepth
|
|
2569
|
-
};
|
|
2570
|
-
}
|
|
2571
|
-
capNumber(requested, defaultValue, hardCeiling) {
|
|
2572
|
-
const base = requested === void 0 ? defaultValue : requested;
|
|
2573
|
-
return Math.min(base, hardCeiling);
|
|
2574
|
-
}
|
|
2575
|
-
};
|
|
2576
|
-
|
|
2577
|
-
//#endregion
|
|
2578
|
-
//#region src/policies/RunTerminalPersistenceCoordinator.ts
|
|
2579
|
-
var RunTerminalPersistenceCoordinator = class {
|
|
2580
|
-
constructor(runStore, storageEvaluator) {
|
|
2581
|
-
this.runStore = runStore;
|
|
2582
|
-
this.storageEvaluator = storageEvaluator;
|
|
2583
|
-
}
|
|
2584
|
-
async maybeDeleteAfterTerminalState(args) {
|
|
2585
|
-
if (await this.storageEvaluator.shouldPersist(args.workflow, args.state.policySnapshot, {
|
|
2586
|
-
runId: args.state.runId,
|
|
2587
|
-
workflowId: args.state.workflowId,
|
|
2588
|
-
workflow: args.workflow,
|
|
2589
|
-
finalStatus: args.finalStatus,
|
|
2590
|
-
startedAt: args.state.startedAt,
|
|
2591
|
-
finishedAt: args.finishedAt
|
|
2592
|
-
})) return;
|
|
2593
|
-
if (!this.runStore.deleteRun) return;
|
|
2594
|
-
await this.runStore.deleteRun(args.state.runId);
|
|
2595
|
-
}
|
|
2596
|
-
};
|
|
2597
|
-
|
|
2598
|
-
//#endregion
|
|
2599
|
-
//#region src/policies/WorkflowPolicyErrorServices.ts
|
|
2600
|
-
var WorkflowPolicyErrorServices = class {
|
|
2601
|
-
constructor(nodeResolver) {
|
|
2602
|
-
this.nodeResolver = nodeResolver;
|
|
2603
|
-
}
|
|
2604
|
-
resolveNodeErrorHandler(spec) {
|
|
2605
|
-
if (!spec) return void 0;
|
|
2606
|
-
if (typeof spec === "object" && spec !== null && "handle" in spec && typeof spec.handle === "function") return spec;
|
|
2607
|
-
return this.nodeResolver.resolve(spec);
|
|
2608
|
-
}
|
|
2609
|
-
resolveWorkflowErrorHandler(spec) {
|
|
2610
|
-
if (!spec) return void 0;
|
|
2611
|
-
if (typeof spec === "object" && spec !== null && "onError" in spec && typeof spec.onError === "function") return spec;
|
|
2612
|
-
return this.nodeResolver.resolve(spec);
|
|
2613
|
-
}
|
|
2614
|
-
};
|
|
2615
|
-
|
|
2616
|
-
//#endregion
|
|
2617
|
-
//#region src/policies/WorkflowStoragePolicyEvaluator.ts
|
|
2618
|
-
var WorkflowStoragePolicyEvaluator = class {
|
|
2619
|
-
constructor(nodeResolver) {
|
|
2620
|
-
this.nodeResolver = nodeResolver;
|
|
2621
|
-
}
|
|
2622
|
-
async shouldPersist(workflow, snapshot, args) {
|
|
2623
|
-
const spec = workflow.storagePolicy;
|
|
2624
|
-
if (spec === void 0) return this.modeMatches(snapshot?.storagePolicy ?? "ALL", args);
|
|
2625
|
-
if (typeof spec === "string") return this.modeMatches(spec, args);
|
|
2626
|
-
const resolver = this.nodeResolver.resolve(spec);
|
|
2627
|
-
return Boolean(await resolver.shouldPersist(args));
|
|
2628
|
-
}
|
|
2629
|
-
modeMatches(mode, args) {
|
|
2630
|
-
if (mode === "ALL") return true;
|
|
2631
|
-
if (mode === "NEVER") return false;
|
|
2632
|
-
if (mode === "SUCCESS") return args.finalStatus === "completed";
|
|
2633
|
-
if (mode === "ERROR") return args.finalStatus === "failed";
|
|
2634
|
-
return true;
|
|
2635
|
-
}
|
|
2636
|
-
};
|
|
2637
|
-
|
|
2638
|
-
//#endregion
|
|
2639
|
-
//#region src/runStorage/BinaryBodyBufferReader.ts
|
|
2640
|
-
var BinaryBodyBufferReader = class {
|
|
2641
|
-
async read(body) {
|
|
2642
|
-
if (body instanceof Uint8Array) return body;
|
|
2643
|
-
if (body instanceof ArrayBuffer) return new Uint8Array(body);
|
|
2644
|
-
if (body instanceof node_stream_web.ReadableStream) return await this.readReadableStream(body);
|
|
2645
|
-
return await this.readAsyncIterable(body);
|
|
2646
|
-
}
|
|
2647
|
-
async readReadableStream(body) {
|
|
2648
|
-
const reader = body.getReader();
|
|
2649
|
-
const chunks = [];
|
|
2650
|
-
let totalSize = 0;
|
|
2651
|
-
try {
|
|
2652
|
-
while (true) {
|
|
2653
|
-
const result = await reader.read();
|
|
2654
|
-
if (result.done) break;
|
|
2655
|
-
chunks.push(result.value);
|
|
2656
|
-
totalSize += result.value.byteLength;
|
|
2657
|
-
}
|
|
2658
|
-
} finally {
|
|
2659
|
-
reader.releaseLock();
|
|
2660
|
-
}
|
|
2661
|
-
return this.joinChunks(chunks, totalSize);
|
|
2662
|
-
}
|
|
2663
|
-
async readAsyncIterable(body) {
|
|
2664
|
-
const chunks = [];
|
|
2665
|
-
let totalSize = 0;
|
|
2666
|
-
for await (const chunk of body) {
|
|
2667
|
-
chunks.push(chunk);
|
|
2668
|
-
totalSize += chunk.byteLength;
|
|
2669
|
-
}
|
|
2670
|
-
return this.joinChunks(chunks, totalSize);
|
|
2671
|
-
}
|
|
2672
|
-
joinChunks(chunks, totalSize) {
|
|
2673
|
-
const bytes = new Uint8Array(totalSize);
|
|
2674
|
-
let offset = 0;
|
|
2675
|
-
for (const chunk of chunks) {
|
|
2676
|
-
bytes.set(chunk, offset);
|
|
2677
|
-
offset += chunk.byteLength;
|
|
2678
|
-
}
|
|
2679
|
-
return bytes;
|
|
2680
|
-
}
|
|
2681
|
-
};
|
|
2682
|
-
|
|
2683
|
-
//#endregion
|
|
2684
|
-
//#region src/runStorage/BinaryBodyReadableStreamFactory.ts
|
|
2685
|
-
var BinaryBodyReadableStreamFactory = class {
|
|
2686
|
-
constructor(bytes) {
|
|
2687
|
-
this.bytes = bytes;
|
|
2688
|
-
}
|
|
2689
|
-
create() {
|
|
2690
|
-
const value = this.bytes;
|
|
2691
|
-
let consumed = false;
|
|
2692
|
-
return new node_stream_web.ReadableStream({ pull(controller) {
|
|
2693
|
-
if (consumed) {
|
|
2694
|
-
controller.close();
|
|
2695
|
-
return;
|
|
2696
|
-
}
|
|
2697
|
-
consumed = true;
|
|
2698
|
-
controller.enqueue(value);
|
|
2699
|
-
controller.close();
|
|
2700
|
-
} });
|
|
2701
|
-
}
|
|
2702
|
-
};
|
|
2703
|
-
|
|
2704
|
-
//#endregion
|
|
2705
|
-
//#region src/runStorage/InMemoryBinaryStorageRegistry.ts
|
|
2706
|
-
var InMemoryBinaryStorage = class {
|
|
2707
|
-
driverName = "memory";
|
|
2708
|
-
values = /* @__PURE__ */ new Map();
|
|
2709
|
-
async write(args) {
|
|
2710
|
-
const bytes = await new BinaryBodyBufferReader().read(args.body);
|
|
2711
|
-
this.values.set(args.storageKey, bytes);
|
|
2712
|
-
return {
|
|
2713
|
-
storageKey: args.storageKey,
|
|
2714
|
-
size: bytes.byteLength,
|
|
2715
|
-
sha256: (0, node_crypto.createHash)("sha256").update(bytes).digest("hex")
|
|
2716
|
-
};
|
|
2717
|
-
}
|
|
2718
|
-
async openReadStream(storageKey) {
|
|
2719
|
-
const bytes = this.values.get(storageKey);
|
|
2720
|
-
if (!bytes) return;
|
|
2721
|
-
return {
|
|
2722
|
-
body: new BinaryBodyReadableStreamFactory(bytes).create(),
|
|
2723
|
-
size: bytes.byteLength
|
|
2724
|
-
};
|
|
2725
|
-
}
|
|
2726
|
-
async stat(storageKey) {
|
|
2727
|
-
const bytes = this.values.get(storageKey);
|
|
2728
|
-
if (!bytes) return { exists: false };
|
|
2729
|
-
return {
|
|
2730
|
-
exists: true,
|
|
2731
|
-
size: bytes.byteLength
|
|
2732
|
-
};
|
|
2733
|
-
}
|
|
2734
|
-
async delete(storageKey) {
|
|
2735
|
-
this.values.delete(storageKey);
|
|
2736
|
-
}
|
|
2737
|
-
};
|
|
2738
|
-
|
|
2739
|
-
//#endregion
|
|
2740
|
-
//#region src/runStorage/InMemoryRunData.ts
|
|
2741
|
-
var InMemoryRunData = class {
|
|
2742
|
-
byNode = /* @__PURE__ */ new Map();
|
|
2743
|
-
constructor(initial) {
|
|
2744
|
-
if (initial) for (const [nodeId, outputs] of Object.entries(initial)) this.byNode.set(nodeId, outputs);
|
|
2745
|
-
}
|
|
2746
|
-
setOutputs(nodeId, outputs) {
|
|
2747
|
-
this.byNode.set(nodeId, outputs);
|
|
2748
|
-
}
|
|
2749
|
-
getOutputs(nodeId) {
|
|
2750
|
-
return this.byNode.get(nodeId);
|
|
2751
|
-
}
|
|
2752
|
-
getOutputItems(nodeId, output = "main") {
|
|
2753
|
-
return this.byNode.get(nodeId)?.[output] ?? [];
|
|
2754
|
-
}
|
|
2755
|
-
getOutputItem(nodeId, itemIndex, output = "main") {
|
|
2756
|
-
return this.getOutputItems(nodeId, output)[itemIndex];
|
|
2757
|
-
}
|
|
2758
|
-
dump() {
|
|
2759
|
-
const out = {};
|
|
2760
|
-
for (const [nodeId, outputs] of this.byNode.entries()) out[nodeId] = outputs;
|
|
2761
|
-
return out;
|
|
2762
|
-
}
|
|
2763
|
-
};
|
|
2764
|
-
|
|
2765
|
-
//#endregion
|
|
2766
|
-
//#region src/runStorage/InMemoryRunDataFactory.ts
|
|
2767
|
-
var InMemoryRunDataFactory = class {
|
|
2768
|
-
create(initial) {
|
|
2769
|
-
return new InMemoryRunData(initial);
|
|
2770
|
-
}
|
|
2771
|
-
};
|
|
2772
|
-
|
|
2773
|
-
//#endregion
|
|
2774
|
-
//#region src/contracts/runFinishedAtFactory.ts
|
|
2775
|
-
/** Derives workflow end time from node snapshots for run listings. */
|
|
2776
|
-
var RunFinishedAtFactory = class {
|
|
2777
|
-
static resolveIso(state) {
|
|
2778
|
-
if (state.status === "running" || state.status === "pending") return;
|
|
2779
|
-
let max;
|
|
2780
|
-
for (const snap of Object.values(state.nodeSnapshotsByNodeId)) if (snap?.finishedAt && (!max || snap.finishedAt > max)) max = snap.finishedAt;
|
|
2781
|
-
return max;
|
|
2782
|
-
}
|
|
2783
|
-
};
|
|
2784
|
-
|
|
2785
|
-
//#endregion
|
|
2786
|
-
//#region src/workflowSnapshots/WorkflowSnapshotResolver.ts
|
|
2787
|
-
var WorkflowSnapshotResolver = class {
|
|
2788
|
-
constructor(workflowRepository, tokenRegistry, codec, missingRuntimeFallbacks) {
|
|
2789
|
-
this.workflowRepository = workflowRepository;
|
|
2790
|
-
this.tokenRegistry = tokenRegistry;
|
|
2791
|
-
this.codec = codec;
|
|
2792
|
-
this.missingRuntimeFallbacks = missingRuntimeFallbacks;
|
|
2793
|
-
}
|
|
2794
|
-
resolve(args) {
|
|
2795
|
-
const liveWorkflow = this.workflowRepository.get(args.workflowId);
|
|
2796
|
-
if (!args.workflowSnapshot) return liveWorkflow;
|
|
2797
|
-
if (!liveWorkflow) return this.rebuildWorkflow(args.workflowSnapshot, void 0);
|
|
2798
|
-
return this.rebuildWorkflow(args.workflowSnapshot, liveWorkflow);
|
|
2799
|
-
}
|
|
2800
|
-
rebuildWorkflow(snapshot, liveWorkflow) {
|
|
2801
|
-
const liveNodesById = new Map((liveWorkflow?.nodes ?? []).map((node$1) => [node$1.id, node$1]));
|
|
2802
|
-
const nodes = snapshot.nodes.map((snapshotNode) => {
|
|
2803
|
-
const liveNode = liveNodesById.get(snapshotNode.id);
|
|
2804
|
-
if (!this.isCompatibleLiveNode(liveNode, snapshotNode)) return this.missingRuntimeFallbacks.createDefinition(snapshotNode);
|
|
2805
|
-
return {
|
|
2806
|
-
id: snapshotNode.id,
|
|
2807
|
-
kind: snapshotNode.kind,
|
|
2808
|
-
name: snapshotNode.name ?? liveNode.name,
|
|
2809
|
-
type: liveNode.type,
|
|
2810
|
-
config: this.codec.hydrate(snapshotNode, liveNode.config)
|
|
2811
|
-
};
|
|
2812
|
-
});
|
|
2813
|
-
const nodeIds = new Set(nodes.map((node$1) => node$1.id));
|
|
2814
|
-
const connectionsFromSnapshot = snapshot.connections?.map((connection) => ({
|
|
2815
|
-
...connection,
|
|
2816
|
-
childNodeIds: connection.childNodeIds.filter((childId) => nodeIds.has(childId))
|
|
2817
|
-
})).filter((connection) => connection.childNodeIds.length > 0) ?? [];
|
|
2818
|
-
return {
|
|
2819
|
-
id: snapshot.id,
|
|
2820
|
-
name: snapshot.name,
|
|
2821
|
-
nodes,
|
|
2822
|
-
edges: snapshot.edges.filter((edge) => nodeIds.has(edge.from.nodeId) && nodeIds.has(edge.to.nodeId)),
|
|
2823
|
-
...connectionsFromSnapshot.length > 0 ? { connections: connectionsFromSnapshot } : {},
|
|
2824
|
-
...liveWorkflow?.discoveryPathSegments !== void 0 ? { discoveryPathSegments: liveWorkflow.discoveryPathSegments } : {}
|
|
2825
|
-
};
|
|
2826
|
-
}
|
|
2827
|
-
isCompatibleLiveNode(liveNode, snapshotNode) {
|
|
2828
|
-
if (!liveNode || liveNode.kind !== snapshotNode.kind) return false;
|
|
2829
|
-
if (!snapshotNode.nodeTokenId || !snapshotNode.configTokenId) throw new Error(`Persisted workflow snapshot node "${snapshotNode.id}" is missing stable token ids.`);
|
|
2830
|
-
const liveNodeTokenId = this.resolveLiveTokenId(liveNode.type);
|
|
2831
|
-
const liveConfigTokenId = this.resolveLiveTokenId(liveNode.config.type);
|
|
2832
|
-
return liveNodeTokenId === snapshotNode.nodeTokenId && liveConfigTokenId === snapshotNode.configTokenId;
|
|
2833
|
-
}
|
|
2834
|
-
resolveLiveTokenId(type) {
|
|
2835
|
-
const registeredTokenId = this.tokenRegistry.getTokenId(type);
|
|
2836
|
-
if (registeredTokenId) return registeredTokenId;
|
|
2837
|
-
if (typeof type === "function" && type.name) return type.name;
|
|
2838
|
-
if (typeof type === "string") return type;
|
|
2839
|
-
}
|
|
2840
|
-
};
|
|
2841
|
-
|
|
2842
|
-
//#endregion
|
|
2843
|
-
//#region src/planning/RunQueuePlanner.ts
|
|
2844
|
-
var RunQueuePlanner = class {
|
|
2845
|
-
constructor(topology, nodeInstances) {
|
|
2846
|
-
this.topology = topology;
|
|
2847
|
-
this.nodeInstances = nodeInstances;
|
|
2848
|
-
}
|
|
2849
|
-
validateNodeKinds() {
|
|
2850
|
-
for (const [toNodeId, inputs] of this.topology.expectedInputsByNode.entries()) {
|
|
2851
|
-
if (inputs.length <= 1) {
|
|
2852
|
-
const only = inputs[0];
|
|
2853
|
-
if (only && only !== "in") {
|
|
2854
|
-
const inst$1 = this.nodeInstances.get(toNodeId);
|
|
2855
|
-
if (!this.isMultiInputNode(inst$1)) throw new Error(`Node ${toNodeId} only supports input 'in' (got '${only}').`);
|
|
2856
|
-
}
|
|
2857
|
-
continue;
|
|
2858
|
-
}
|
|
2859
|
-
const inst = this.nodeInstances.get(toNodeId);
|
|
2860
|
-
if (!this.isMultiInputNode(inst)) throw new Error(`Node ${toNodeId} has ${inputs.length} inbound edges. Insert a Merge node to combine branches.`);
|
|
2861
|
-
}
|
|
2862
|
-
}
|
|
2863
|
-
seedFromTrigger(args) {
|
|
2864
|
-
const queue = [];
|
|
2865
|
-
for (const e of this.topology.outgoingByNode.get(args.startNodeId) ?? []) {
|
|
2866
|
-
if (e.output !== "main") continue;
|
|
2867
|
-
this.enqueueEdge(queue, {
|
|
2868
|
-
batchId: args.batchId,
|
|
2869
|
-
to: e.to,
|
|
2870
|
-
from: {
|
|
2871
|
-
nodeId: args.startNodeId,
|
|
2872
|
-
output: "main"
|
|
2873
|
-
},
|
|
2874
|
-
items: args.items
|
|
2875
|
-
});
|
|
2876
|
-
}
|
|
2877
|
-
return queue;
|
|
2878
|
-
}
|
|
2879
|
-
applyOutputs(queue, args) {
|
|
2880
|
-
for (const e of this.topology.outgoingByNode.get(args.fromNodeId) ?? []) {
|
|
2881
|
-
const outItems = args.outputs[e.output] ?? [];
|
|
2882
|
-
this.enqueueEdge(queue, {
|
|
2883
|
-
batchId: args.batchId,
|
|
2884
|
-
to: e.to,
|
|
2885
|
-
from: {
|
|
2886
|
-
nodeId: args.fromNodeId,
|
|
2887
|
-
output: e.output
|
|
2888
|
-
},
|
|
2889
|
-
items: outItems
|
|
2890
|
-
});
|
|
2891
|
-
}
|
|
2892
|
-
}
|
|
2893
|
-
nextActivation(queue) {
|
|
2894
|
-
const readyCollect = this.resolveReadyCollect(queue);
|
|
2895
|
-
if (readyCollect) return readyCollect;
|
|
2896
|
-
const jobIdx = queue.findIndex((q) => !q.collect);
|
|
2897
|
-
if (jobIdx === -1) {
|
|
2898
|
-
if (queue.length === 0) return null;
|
|
2899
|
-
const sealedCollect = this.resolveSealedCollect(queue);
|
|
2900
|
-
if (sealedCollect) return sealedCollect;
|
|
2901
|
-
const stuck = queue[0];
|
|
2902
|
-
throw new Error(this.describeUnsatisfiedCollect(stuck));
|
|
2903
|
-
}
|
|
2904
|
-
const job = queue.splice(jobIdx, 1)[0];
|
|
2905
|
-
const def = this.topology.defsById.get(job.nodeId);
|
|
2906
|
-
if (!def || def.kind !== "node") return this.nextActivation(queue);
|
|
2907
|
-
return {
|
|
2908
|
-
kind: "single",
|
|
2909
|
-
nodeId: job.nodeId,
|
|
2910
|
-
input: job.input,
|
|
2911
|
-
batchId: job.batchId ?? "batch_1"
|
|
2912
|
-
};
|
|
2913
|
-
}
|
|
2914
|
-
sumItemsByPort(inputsByPort) {
|
|
2915
|
-
let n = 0;
|
|
2916
|
-
for (const v of Object.values(inputsByPort)) n += v?.length ?? 0;
|
|
2917
|
-
return n;
|
|
2918
|
-
}
|
|
2919
|
-
resolveReadyCollect(queue) {
|
|
2920
|
-
for (let i = 0; i < queue.length; i++) {
|
|
2921
|
-
const ready = this.tryDequeueCollect(queue, i);
|
|
2922
|
-
if (ready) return ready;
|
|
2923
|
-
}
|
|
2924
|
-
return null;
|
|
2925
|
-
}
|
|
2926
|
-
resolveSealedCollect(queue) {
|
|
2927
|
-
for (let i = 0; i < queue.length; i++) {
|
|
2928
|
-
const queueEntry = queue[i];
|
|
2929
|
-
if (!queueEntry.collect) continue;
|
|
2930
|
-
const received = queueEntry.collect.received;
|
|
2931
|
-
if (Object.keys(received).length === 0) continue;
|
|
2932
|
-
this.fillMissingCollectInputs(queueEntry);
|
|
2933
|
-
const ready = this.tryDequeueCollect(queue, i);
|
|
2934
|
-
if (ready) return ready;
|
|
2935
|
-
}
|
|
2936
|
-
return null;
|
|
2937
|
-
}
|
|
2938
|
-
tryDequeueCollect(queue, index) {
|
|
2939
|
-
const queueEntry = queue[index];
|
|
2940
|
-
if (!queueEntry.collect) return null;
|
|
2941
|
-
const batchId = queueEntry.batchId ?? "batch_1";
|
|
2942
|
-
const expected = queueEntry.collect.expectedInputs ?? [];
|
|
2943
|
-
const received = queueEntry.collect.received;
|
|
2944
|
-
for (const input of expected) if (!(input in received)) return null;
|
|
2945
|
-
queue.splice(index, 1);
|
|
2946
|
-
return {
|
|
2947
|
-
kind: "multi",
|
|
2948
|
-
nodeId: queueEntry.nodeId,
|
|
2949
|
-
inputsByPort: received,
|
|
2950
|
-
batchId
|
|
2951
|
-
};
|
|
2952
|
-
}
|
|
2953
|
-
fillMissingCollectInputs(queueEntry) {
|
|
2954
|
-
if (!queueEntry.collect) return;
|
|
2955
|
-
const received = queueEntry.collect.received;
|
|
2956
|
-
for (const input of queueEntry.collect.expectedInputs ?? []) if (!(input in received)) received[input] = [];
|
|
2957
|
-
}
|
|
2958
|
-
enqueueEdge(queue, args) {
|
|
2959
|
-
const target = this.nodeInstances.get(args.to.nodeId);
|
|
2960
|
-
if (!this.isMultiInputNode(target)) {
|
|
2961
|
-
if (args.items.length === 0) {
|
|
2962
|
-
if (this.shouldContinueAfterEmptyOutputFromSource(args.from.nodeId)) {
|
|
2963
|
-
queue.push({
|
|
2964
|
-
nodeId: args.to.nodeId,
|
|
2965
|
-
input: args.items,
|
|
2966
|
-
toInput: args.to.input,
|
|
2967
|
-
batchId: args.batchId,
|
|
2968
|
-
from: args.from
|
|
2969
|
-
});
|
|
2970
|
-
return;
|
|
2971
|
-
}
|
|
2972
|
-
this.propagateEmptyPath(queue, args.to.nodeId, args.batchId);
|
|
2973
|
-
return;
|
|
2974
|
-
}
|
|
2975
|
-
queue.push({
|
|
2976
|
-
nodeId: args.to.nodeId,
|
|
2977
|
-
input: args.items,
|
|
2978
|
-
toInput: args.to.input,
|
|
2979
|
-
batchId: args.batchId,
|
|
2980
|
-
from: args.from
|
|
2981
|
-
});
|
|
2982
|
-
return;
|
|
2983
|
-
}
|
|
2984
|
-
const expected = this.topology.expectedInputsByNode.get(args.to.nodeId) ?? [];
|
|
2985
|
-
let collect = queue.find((q) => q.nodeId === args.to.nodeId && (q.batchId ?? "batch_1") === args.batchId && !!q.collect);
|
|
2986
|
-
if (!collect) {
|
|
2987
|
-
collect = {
|
|
2988
|
-
nodeId: args.to.nodeId,
|
|
2989
|
-
input: [],
|
|
2990
|
-
batchId: args.batchId,
|
|
2991
|
-
collect: {
|
|
2992
|
-
expectedInputs: expected,
|
|
2993
|
-
received: {}
|
|
2994
|
-
}
|
|
2995
|
-
};
|
|
2996
|
-
queue.push(collect);
|
|
2997
|
-
}
|
|
2998
|
-
const received = collect.collect.received;
|
|
2999
|
-
received[args.to.input] = args.items;
|
|
3000
|
-
}
|
|
3001
|
-
shouldContinueAfterEmptyOutputFromSource(fromNodeId) {
|
|
3002
|
-
const def = this.topology.defsById.get(fromNodeId);
|
|
3003
|
-
if (!def) return false;
|
|
3004
|
-
return def.config.continueWhenEmptyOutput === true;
|
|
3005
|
-
}
|
|
3006
|
-
propagateEmptyPath(queue, nodeId, batchId) {
|
|
3007
|
-
for (const edge of this.topology.outgoingByNode.get(nodeId) ?? []) this.enqueueEdge(queue, {
|
|
3008
|
-
batchId,
|
|
3009
|
-
to: edge.to,
|
|
3010
|
-
from: {
|
|
3011
|
-
nodeId,
|
|
3012
|
-
output: edge.output
|
|
3013
|
-
},
|
|
3014
|
-
items: []
|
|
3015
|
-
});
|
|
3016
|
-
}
|
|
3017
|
-
isMultiInputNode(n) {
|
|
3018
|
-
return typeof n?.executeMulti === "function";
|
|
3019
|
-
}
|
|
3020
|
-
describeUnsatisfiedCollect(queueEntry) {
|
|
3021
|
-
const batchId = queueEntry.batchId ?? "batch_1";
|
|
3022
|
-
const expectedInputs = queueEntry.collect?.expectedInputs ?? [];
|
|
3023
|
-
const receivedInputs = Object.keys(queueEntry.collect?.received ?? {});
|
|
3024
|
-
const missingInputs = expectedInputs.filter((input) => !receivedInputs.includes(input));
|
|
3025
|
-
const mergeNodeLabel = this.formatNodeLabel(queueEntry.nodeId);
|
|
3026
|
-
const receivedSummary = this.describeReceivedInputs(queueEntry);
|
|
3027
|
-
const missingSummary = this.describeMissingInputs(queueEntry.nodeId, missingInputs);
|
|
3028
|
-
return [
|
|
3029
|
-
`Multi-input collect is stuck at ${mergeNodeLabel} (batchId=${batchId}).`,
|
|
3030
|
-
`Expected inputs: ${this.formatInputList(expectedInputs)}.`,
|
|
3031
|
-
`Received inputs: ${receivedSummary}.`,
|
|
3032
|
-
`Missing inputs: ${missingSummary}.`
|
|
3033
|
-
].join(" ");
|
|
3034
|
-
}
|
|
3035
|
-
describeReceivedInputs(queueEntry) {
|
|
3036
|
-
const received = queueEntry.collect?.received ?? {};
|
|
3037
|
-
const receivedEntries = Object.entries(received);
|
|
3038
|
-
if (receivedEntries.length === 0) return "none";
|
|
3039
|
-
return receivedEntries.map(([input, items]) => `${input} (${items.length} item${items.length === 1 ? "" : "s"})`).join(", ");
|
|
3040
|
-
}
|
|
3041
|
-
describeMissingInputs(nodeId, missingInputs) {
|
|
3042
|
-
if (missingInputs.length === 0) return "none";
|
|
3043
|
-
return missingInputs.map((input) => {
|
|
3044
|
-
const sources = this.findSources(nodeId, input);
|
|
3045
|
-
if (sources.length === 0) return input;
|
|
3046
|
-
return `${input} from ${sources.join(" or ")}`;
|
|
3047
|
-
}).join(", ");
|
|
3048
|
-
}
|
|
3049
|
-
findSources(nodeId, input) {
|
|
3050
|
-
const matches = [];
|
|
3051
|
-
for (const [sourceNodeId, edges] of this.topology.outgoingByNode.entries()) for (const edge of edges) if (edge.to.nodeId === nodeId && edge.to.input === input) matches.push(this.formatNodeLabel(sourceNodeId));
|
|
3052
|
-
return matches;
|
|
3053
|
-
}
|
|
3054
|
-
formatInputList(inputs) {
|
|
3055
|
-
return inputs.length > 0 ? `[${inputs.join(", ")}]` : "[]";
|
|
3056
|
-
}
|
|
3057
|
-
formatNodeLabel(nodeId) {
|
|
3058
|
-
const definition = this.topology.defsById.get(nodeId);
|
|
3059
|
-
const instance = this.nodeInstances.get(nodeId);
|
|
3060
|
-
const typeName = definition?.type && typeof definition.type === "function" ? definition.type.name : instance && typeof instance === "object" && "constructor" in instance ? instance.constructor.name ?? "Node" : "Node";
|
|
3061
|
-
return definition?.name ? `"${definition.name}" (${typeName}:${nodeId})` : `${typeName}:${nodeId}`;
|
|
3062
|
-
}
|
|
3063
|
-
};
|
|
3064
|
-
|
|
3065
|
-
//#endregion
|
|
3066
|
-
//#region src/planning/EngineWorkflowPlanningFactory.ts
|
|
3067
|
-
var EngineWorkflowPlanningFactory = class {
|
|
3068
|
-
constructor(workflowNodeInstanceFactory) {
|
|
3069
|
-
this.workflowNodeInstanceFactory = workflowNodeInstanceFactory;
|
|
3070
|
-
}
|
|
3071
|
-
create(workflow) {
|
|
3072
|
-
this.validateAcyclic(workflow);
|
|
3073
|
-
const topology = WorkflowTopology.fromWorkflow(workflow);
|
|
3074
|
-
const planner = new RunQueuePlanner(topology, this.workflowNodeInstanceFactory.createNodes(workflow));
|
|
3075
|
-
planner.validateNodeKinds();
|
|
3076
|
-
return {
|
|
3077
|
-
topology,
|
|
3078
|
-
planner
|
|
3079
|
-
};
|
|
3080
|
-
}
|
|
3081
|
-
validateAcyclic(workflow) {
|
|
3082
|
-
const classifier = createWorkflowExecutableNodeClassifier(workflow);
|
|
3083
|
-
const outgoing = /* @__PURE__ */ new Map();
|
|
3084
|
-
const visitState = /* @__PURE__ */ new Map();
|
|
3085
|
-
for (const node$1 of workflow.nodes) if (classifier.isExecutableNodeId(node$1.id)) visitState.set(node$1.id, "unvisited");
|
|
3086
|
-
for (const edge of workflow.edges) {
|
|
3087
|
-
if (!classifier.isExecutableNodeId(edge.from.nodeId) || !classifier.isExecutableNodeId(edge.to.nodeId)) continue;
|
|
3088
|
-
const destinations = outgoing.get(edge.from.nodeId) ?? [];
|
|
3089
|
-
destinations.push(edge.to.nodeId);
|
|
3090
|
-
outgoing.set(edge.from.nodeId, destinations);
|
|
3091
|
-
}
|
|
3092
|
-
for (const node$1 of workflow.nodes) if (classifier.isExecutableNodeId(node$1.id) && visitState.get(node$1.id) === "unvisited") this.depthFirstSearch(node$1.id, outgoing, visitState);
|
|
3093
|
-
}
|
|
3094
|
-
depthFirstSearch(nodeId, outgoing, visitState) {
|
|
3095
|
-
visitState.set(nodeId, "visiting");
|
|
3096
|
-
for (const toNodeId of outgoing.get(nodeId) ?? []) {
|
|
3097
|
-
const state = visitState.get(toNodeId);
|
|
3098
|
-
if (state === "visiting") throw new Error(`Workflow graph contains a directed cycle (edge ${nodeId} -> ${toNodeId}).`);
|
|
3099
|
-
if (state === "unvisited") this.depthFirstSearch(toNodeId, outgoing, visitState);
|
|
3100
|
-
}
|
|
3101
|
-
visitState.set(nodeId, "done");
|
|
3102
|
-
}
|
|
3103
|
-
};
|
|
3104
|
-
|
|
3105
|
-
//#endregion
|
|
3106
|
-
//#region src/observability/BoundNodeExecutionStatePublisher.ts
|
|
3107
|
-
var BoundNodeExecutionStatePublisher = class {
|
|
3108
|
-
chain = Promise.resolve();
|
|
3109
|
-
constructor(runStore, runId, workflowId, parent, publishNodeEvent) {
|
|
3110
|
-
this.runStore = runStore;
|
|
3111
|
-
this.runId = runId;
|
|
3112
|
-
this.workflowId = workflowId;
|
|
3113
|
-
this.parent = parent;
|
|
3114
|
-
this.publishNodeEvent = publishNodeEvent;
|
|
3115
|
-
}
|
|
3116
|
-
markQueued(args) {
|
|
3117
|
-
return this.enqueue(async () => {
|
|
3118
|
-
const state = await this.loadState();
|
|
3119
|
-
const previous = state.nodeSnapshotsByNodeId?.[args.nodeId];
|
|
3120
|
-
const queuedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3121
|
-
const snapshot = NodeSnapshotFactory.queued({
|
|
3122
|
-
runId: this.runId,
|
|
3123
|
-
workflowId: this.workflowId,
|
|
3124
|
-
nodeId: args.nodeId,
|
|
3125
|
-
activationId: args.activationId ?? previous?.activationId ?? `synthetic_${args.nodeId}`,
|
|
3126
|
-
parent: this.parent,
|
|
3127
|
-
queuedAt,
|
|
3128
|
-
inputsByPort: args.inputsByPort ?? previous?.inputsByPort ?? InputPortMap.empty()
|
|
3129
|
-
});
|
|
3130
|
-
await this.saveSnapshot(state, snapshot);
|
|
3131
|
-
await this.publishNodeEvent("nodeQueued", snapshot);
|
|
3132
|
-
});
|
|
3133
|
-
}
|
|
3134
|
-
markRunning(args) {
|
|
3135
|
-
return this.enqueue(async () => {
|
|
3136
|
-
const state = await this.loadState();
|
|
3137
|
-
const previous = state.nodeSnapshotsByNodeId?.[args.nodeId];
|
|
3138
|
-
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3139
|
-
const snapshot = NodeSnapshotFactory.running({
|
|
3140
|
-
previous,
|
|
3141
|
-
runId: this.runId,
|
|
3142
|
-
workflowId: this.workflowId,
|
|
3143
|
-
nodeId: args.nodeId,
|
|
3144
|
-
activationId: args.activationId ?? previous?.activationId ?? `synthetic_${args.nodeId}`,
|
|
3145
|
-
parent: this.parent,
|
|
3146
|
-
startedAt,
|
|
3147
|
-
inputsByPort: args.inputsByPort ?? previous?.inputsByPort ?? InputPortMap.empty()
|
|
3148
|
-
});
|
|
3149
|
-
await this.saveSnapshot(state, snapshot);
|
|
3150
|
-
await this.publishNodeEvent("nodeStarted", snapshot);
|
|
3151
|
-
});
|
|
3152
|
-
}
|
|
3153
|
-
markCompleted(args) {
|
|
3154
|
-
return this.enqueue(async () => {
|
|
3155
|
-
const state = await this.loadState();
|
|
3156
|
-
const previous = state.nodeSnapshotsByNodeId?.[args.nodeId];
|
|
3157
|
-
const finishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3158
|
-
const snapshot = NodeSnapshotFactory.completed({
|
|
3159
|
-
previous,
|
|
3160
|
-
runId: this.runId,
|
|
3161
|
-
workflowId: this.workflowId,
|
|
3162
|
-
nodeId: args.nodeId,
|
|
3163
|
-
activationId: args.activationId ?? previous?.activationId ?? `synthetic_${args.nodeId}`,
|
|
3164
|
-
parent: this.parent,
|
|
3165
|
-
finishedAt,
|
|
3166
|
-
inputsByPort: args.inputsByPort ?? previous?.inputsByPort ?? InputPortMap.empty(),
|
|
3167
|
-
outputs: args.outputs ?? previous?.outputs ?? {}
|
|
3168
|
-
});
|
|
3169
|
-
await this.saveSnapshot(state, snapshot);
|
|
3170
|
-
await this.publishNodeEvent("nodeCompleted", snapshot);
|
|
3171
|
-
});
|
|
3172
|
-
}
|
|
3173
|
-
markFailed(args) {
|
|
3174
|
-
return this.enqueue(async () => {
|
|
3175
|
-
const state = await this.loadState();
|
|
3176
|
-
const previous = state.nodeSnapshotsByNodeId?.[args.nodeId];
|
|
3177
|
-
const finishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3178
|
-
const snapshot = NodeSnapshotFactory.failed({
|
|
3179
|
-
previous,
|
|
3180
|
-
runId: this.runId,
|
|
3181
|
-
workflowId: this.workflowId,
|
|
3182
|
-
nodeId: args.nodeId,
|
|
3183
|
-
activationId: args.activationId ?? previous?.activationId ?? `synthetic_${args.nodeId}`,
|
|
3184
|
-
parent: this.parent,
|
|
3185
|
-
finishedAt,
|
|
3186
|
-
inputsByPort: args.inputsByPort ?? previous?.inputsByPort ?? InputPortMap.empty(),
|
|
3187
|
-
error: args.error
|
|
3188
|
-
});
|
|
3189
|
-
await this.saveSnapshot(state, snapshot);
|
|
3190
|
-
await this.publishNodeEvent("nodeFailed", snapshot);
|
|
3191
|
-
});
|
|
3192
|
-
}
|
|
3193
|
-
appendConnectionInvocation(args) {
|
|
3194
|
-
return this.enqueue(async () => {
|
|
3195
|
-
const state = await this.loadState();
|
|
3196
|
-
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3197
|
-
const record = {
|
|
3198
|
-
invocationId: args.invocationId,
|
|
3199
|
-
runId: this.runId,
|
|
3200
|
-
workflowId: this.workflowId,
|
|
3201
|
-
connectionNodeId: args.connectionNodeId,
|
|
3202
|
-
parentAgentNodeId: args.parentAgentNodeId,
|
|
3203
|
-
parentAgentActivationId: args.parentAgentActivationId,
|
|
3204
|
-
status: args.status,
|
|
3205
|
-
managedInput: args.managedInput,
|
|
3206
|
-
managedOutput: args.managedOutput,
|
|
3207
|
-
error: args.error,
|
|
3208
|
-
queuedAt: args.queuedAt,
|
|
3209
|
-
startedAt: args.startedAt,
|
|
3210
|
-
finishedAt: args.finishedAt,
|
|
3211
|
-
updatedAt
|
|
3212
|
-
};
|
|
3213
|
-
await this.runStore.save({
|
|
3214
|
-
...state,
|
|
3215
|
-
connectionInvocations: [...state.connectionInvocations ?? [], record]
|
|
3216
|
-
});
|
|
3217
|
-
});
|
|
3218
|
-
}
|
|
3219
|
-
enqueue(work) {
|
|
3220
|
-
const next = this.chain.then(work);
|
|
3221
|
-
this.chain = next.catch(() => void 0);
|
|
3222
|
-
return next;
|
|
3223
|
-
}
|
|
3224
|
-
async loadState() {
|
|
3225
|
-
const state = await this.runStore.load(this.runId);
|
|
3226
|
-
if (!state) throw new Error(`Unknown runId: ${this.runId}`);
|
|
3227
|
-
return state;
|
|
3228
|
-
}
|
|
3229
|
-
async saveSnapshot(state, snapshot) {
|
|
3230
|
-
await this.runStore.save({
|
|
3231
|
-
...state,
|
|
3232
|
-
nodeSnapshotsByNodeId: {
|
|
3233
|
-
...state.nodeSnapshotsByNodeId ?? {},
|
|
3234
|
-
[snapshot.nodeId]: snapshot
|
|
3235
|
-
}
|
|
3236
|
-
});
|
|
3237
|
-
}
|
|
3238
|
-
};
|
|
3239
|
-
|
|
3240
|
-
//#endregion
|
|
3241
|
-
//#region src/observability/NodeExecutionStatePublisherFactory.ts
|
|
3242
|
-
var NodeExecutionStatePublisherFactory = class {
|
|
3243
|
-
constructor(runStore, nodeEventPublisher) {
|
|
3244
|
-
this.runStore = runStore;
|
|
3245
|
-
this.nodeEventPublisher = nodeEventPublisher;
|
|
3246
|
-
}
|
|
3247
|
-
create(runId, workflowId, parent) {
|
|
3248
|
-
return new BoundNodeExecutionStatePublisher(this.runStore, runId, workflowId, parent, async (kind, snapshot) => {
|
|
3249
|
-
await this.nodeEventPublisher.publish(kind, snapshot);
|
|
3250
|
-
});
|
|
3251
|
-
}
|
|
3252
|
-
};
|
|
3253
|
-
|
|
3254
|
-
//#endregion
|
|
3255
|
-
//#region src/orchestration/TriggerRuntimeService.ts
|
|
3256
|
-
var TriggerRuntimeService = class {
|
|
3257
|
-
credentialResolverFactory;
|
|
3258
|
-
triggerCleanupHandlesByKey = /* @__PURE__ */ new Map();
|
|
3259
|
-
constructor(workflowRepository, workflowActivationPolicy, runIdFactory, runDataFactory, executionContextFactory, credentialResolverFactory, nodeExecutionStatePublisherFactory, nodeResolver, triggerSetupStateStore, emitHandler, executionLimitsPolicy, diagnostics) {
|
|
3260
|
-
this.workflowRepository = workflowRepository;
|
|
3261
|
-
this.workflowActivationPolicy = workflowActivationPolicy;
|
|
3262
|
-
this.runIdFactory = runIdFactory;
|
|
3263
|
-
this.runDataFactory = runDataFactory;
|
|
3264
|
-
this.executionContextFactory = executionContextFactory;
|
|
3265
|
-
this.nodeExecutionStatePublisherFactory = nodeExecutionStatePublisherFactory;
|
|
3266
|
-
this.nodeResolver = nodeResolver;
|
|
3267
|
-
this.triggerSetupStateStore = triggerSetupStateStore;
|
|
3268
|
-
this.emitHandler = emitHandler;
|
|
3269
|
-
this.executionLimitsPolicy = executionLimitsPolicy;
|
|
3270
|
-
this.diagnostics = diagnostics;
|
|
3271
|
-
this.credentialResolverFactory = credentialResolverFactory;
|
|
3272
|
-
}
|
|
3273
|
-
async startTriggers() {
|
|
3274
|
-
for (const wf of this.workflowRepository.list()) {
|
|
3275
|
-
if (!this.workflowActivationPolicy.isActive(wf.id)) {
|
|
3276
|
-
const summaries = this.formatTriggerSummaries(wf);
|
|
3277
|
-
if (summaries.length > 0) this.logInfo(`Workflow "${wf.name}" (${wf.id}) is inactive; skipping trigger setup — ${summaries.join("; ")}.`);
|
|
3278
|
-
continue;
|
|
3279
|
-
}
|
|
3280
|
-
await this.startTriggersForWorkflow(wf);
|
|
3281
|
-
}
|
|
3282
|
-
}
|
|
3283
|
-
async syncWorkflowTriggersForActivation(workflowId) {
|
|
3284
|
-
const wf = this.workflowRepository.get(workflowId);
|
|
3285
|
-
if (!wf) return;
|
|
3286
|
-
const summaries = this.formatTriggerSummaries(wf);
|
|
3287
|
-
if (summaries.length > 0) this.logInfo(`Workflow "${wf.name}" (${wf.id}): stopping triggers — ${summaries.join("; ")}.`);
|
|
3288
|
-
await this.stopTriggersForWorkflow(wf);
|
|
3289
|
-
if (this.workflowActivationPolicy.isActive(workflowId)) {
|
|
3290
|
-
if (summaries.length > 0) this.logInfo(`Workflow "${wf.name}" (${wf.id}): activation on; starting triggers — ${summaries.join("; ")}.`);
|
|
3291
|
-
await this.startTriggersForWorkflow(wf);
|
|
3292
|
-
} else this.logInfo(`Workflow "${wf.name}" (${wf.id}): activation off; triggers not started.`);
|
|
3293
|
-
}
|
|
3294
|
-
async stop() {
|
|
3295
|
-
for (const workflow of this.workflowRepository.list()) await this.stopTriggersForWorkflow(workflow);
|
|
3296
|
-
}
|
|
3297
|
-
async createTriggerTestItems(args) {
|
|
3298
|
-
const definition = args.workflow.nodes.find((node$2) => node$2.id === args.nodeId);
|
|
3299
|
-
if (!definition) throw new Error(`Unknown trigger nodeId: ${args.nodeId}`);
|
|
3300
|
-
if (definition.kind !== "trigger") throw new Error(`Node ${args.nodeId} is not a trigger`);
|
|
3301
|
-
const node$1 = this.nodeResolver.resolve(definition.type);
|
|
3302
|
-
if (!this.isTestableTriggerNode(node$1)) return;
|
|
3303
|
-
const data = this.runDataFactory.create();
|
|
3304
|
-
const runId = this.runIdFactory.makeRunId();
|
|
3305
|
-
const trigger = {
|
|
3306
|
-
workflowId: args.workflow.id,
|
|
3307
|
-
nodeId: definition.id
|
|
3308
|
-
};
|
|
3309
|
-
const previousState = await this.triggerSetupStateStore.load(trigger);
|
|
3310
|
-
return await node$1.getTestItems({
|
|
3311
|
-
...this.createExecutionContext({
|
|
3312
|
-
runId,
|
|
3313
|
-
workflowId: args.workflow.id,
|
|
3314
|
-
nodeId: definition.id,
|
|
3315
|
-
data
|
|
3316
|
-
}),
|
|
3317
|
-
trigger,
|
|
3318
|
-
nodeId: definition.id,
|
|
3319
|
-
config: definition.config,
|
|
3320
|
-
previousState: previousState?.state
|
|
3321
|
-
});
|
|
3322
|
-
}
|
|
3323
|
-
async startTriggersForWorkflow(wf) {
|
|
3324
|
-
for (const def of wf.nodes) {
|
|
3325
|
-
if (def.kind !== "trigger") continue;
|
|
3326
|
-
const node$1 = this.nodeResolver.resolve(def.type);
|
|
3327
|
-
const data = this.runDataFactory.create();
|
|
3328
|
-
const triggerRunId = this.runIdFactory.makeRunId();
|
|
3329
|
-
const trigger = {
|
|
3330
|
-
workflowId: wf.id,
|
|
3331
|
-
nodeId: def.id
|
|
3332
|
-
};
|
|
3333
|
-
await this.stopTrigger(trigger);
|
|
3334
|
-
const previousState = await this.triggerSetupStateStore.load(trigger);
|
|
3335
|
-
let nextState;
|
|
3336
|
-
try {
|
|
3337
|
-
nextState = await node$1.setup({
|
|
3338
|
-
...this.createExecutionContext({
|
|
3339
|
-
runId: triggerRunId,
|
|
3340
|
-
workflowId: wf.id,
|
|
3341
|
-
nodeId: def.id,
|
|
3342
|
-
data
|
|
3343
|
-
}),
|
|
3344
|
-
trigger,
|
|
3345
|
-
config: def.config,
|
|
3346
|
-
previousState: previousState?.state,
|
|
3347
|
-
registerCleanup: (cleanup) => {
|
|
3348
|
-
this.registerTriggerCleanupHandle(trigger, cleanup);
|
|
3349
|
-
},
|
|
3350
|
-
emit: async (items) => {
|
|
3351
|
-
await this.emitHandler.emit(wf, def.id, items);
|
|
3352
|
-
}
|
|
3353
|
-
});
|
|
3354
|
-
} catch (triggerError) {
|
|
3355
|
-
await this.stopTrigger(trigger);
|
|
3356
|
-
const message = triggerError instanceof Error ? triggerError.message : String(triggerError);
|
|
3357
|
-
this.logWarn(`Skipping trigger setup for workflow ${wf.id} node ${def.id}: ${message}`);
|
|
3358
|
-
continue;
|
|
3359
|
-
}
|
|
3360
|
-
if (nextState === void 0) await this.triggerSetupStateStore.delete(trigger);
|
|
3361
|
-
else await this.triggerSetupStateStore.save({
|
|
3362
|
-
trigger,
|
|
3363
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3364
|
-
state: nextState
|
|
3365
|
-
});
|
|
3366
|
-
}
|
|
3367
|
-
}
|
|
3368
|
-
async stopTriggersForWorkflow(workflow) {
|
|
3369
|
-
for (const node$1 of workflow.nodes) {
|
|
3370
|
-
if (node$1.kind !== "trigger") continue;
|
|
3371
|
-
await this.stopTrigger({
|
|
3372
|
-
workflowId: workflow.id,
|
|
3373
|
-
nodeId: node$1.id
|
|
3374
|
-
});
|
|
3375
|
-
}
|
|
3376
|
-
}
|
|
3377
|
-
createExecutionContext(args) {
|
|
3378
|
-
const nodeState = this.nodeExecutionStatePublisherFactory.create(args.runId, args.workflowId, void 0);
|
|
3379
|
-
const rootLimits = this.executionLimitsPolicy.createRootExecutionOptions();
|
|
3380
|
-
return this.executionContextFactory.create({
|
|
3381
|
-
runId: args.runId,
|
|
3382
|
-
workflowId: args.workflowId,
|
|
3383
|
-
parent: void 0,
|
|
3384
|
-
subworkflowDepth: rootLimits.subworkflowDepth ?? 0,
|
|
3385
|
-
engineMaxNodeActivations: rootLimits.maxNodeActivations,
|
|
3386
|
-
engineMaxSubworkflowDepth: rootLimits.maxSubworkflowDepth,
|
|
3387
|
-
data: args.data,
|
|
3388
|
-
nodeState,
|
|
3389
|
-
getCredential: this.credentialResolverFactory.create(args.workflowId, args.nodeId)
|
|
3390
|
-
});
|
|
3391
|
-
}
|
|
3392
|
-
registerTriggerCleanupHandle(trigger, cleanup) {
|
|
3393
|
-
const key = this.toTriggerKey(trigger);
|
|
3394
|
-
const cleanups = this.triggerCleanupHandlesByKey.get(key) ?? [];
|
|
3395
|
-
cleanups.push(cleanup);
|
|
3396
|
-
this.triggerCleanupHandlesByKey.set(key, cleanups);
|
|
3397
|
-
}
|
|
3398
|
-
async stopTrigger(trigger) {
|
|
3399
|
-
const key = this.toTriggerKey(trigger);
|
|
3400
|
-
const cleanups = this.triggerCleanupHandlesByKey.get(key) ?? [];
|
|
3401
|
-
this.triggerCleanupHandlesByKey.delete(key);
|
|
3402
|
-
for (const cleanup of [...cleanups].reverse()) await cleanup.stop();
|
|
3403
|
-
}
|
|
3404
|
-
toTriggerKey(trigger) {
|
|
3405
|
-
return `${trigger.workflowId}:${trigger.nodeId}`;
|
|
3406
|
-
}
|
|
3407
|
-
formatTriggerSummaries(wf) {
|
|
3408
|
-
const out = [];
|
|
3409
|
-
for (const def of wf.nodes) {
|
|
3410
|
-
if (def.kind !== "trigger") continue;
|
|
3411
|
-
out.push(this.describeTriggerNode(def));
|
|
3412
|
-
}
|
|
3413
|
-
return out;
|
|
3414
|
-
}
|
|
3415
|
-
describeTriggerNode(def) {
|
|
3416
|
-
const label = def.name !== void 0 && def.name.trim().length > 0 ? def.name.trim() : String(def.id);
|
|
3417
|
-
const cfg = def.config;
|
|
3418
|
-
if (typeof cfg.endpointKey === "string" && cfg.endpointKey.trim().length > 0) return `${label} (webhook "${cfg.endpointKey.trim()}")`;
|
|
3419
|
-
return label;
|
|
3420
|
-
}
|
|
3421
|
-
logInfo(message) {
|
|
3422
|
-
if (this.diagnostics) this.diagnostics.info(message);
|
|
3423
|
-
}
|
|
3424
|
-
logWarn(message) {
|
|
3425
|
-
if (this.diagnostics) this.diagnostics.warn(message);
|
|
3426
|
-
else console.warn(`[engine] ${message}`);
|
|
3427
|
-
}
|
|
3428
|
-
isTestableTriggerNode(node$1) {
|
|
3429
|
-
return typeof node$1.getTestItems === "function";
|
|
3430
|
-
}
|
|
3431
|
-
};
|
|
3432
|
-
|
|
3433
|
-
//#endregion
|
|
3434
|
-
//#region src/orchestration/EngineWaiters.ts
|
|
3435
|
-
var EngineWaiters = class {
|
|
3436
|
-
completionWaiters = /* @__PURE__ */ new Map();
|
|
3437
|
-
webhookResponseWaiters = /* @__PURE__ */ new Map();
|
|
3438
|
-
waitForCompletion(runId) {
|
|
3439
|
-
return new Promise((resolve) => {
|
|
3440
|
-
const list = this.completionWaiters.get(runId) ?? [];
|
|
3441
|
-
list.push(resolve);
|
|
3442
|
-
this.completionWaiters.set(runId, list);
|
|
3443
|
-
});
|
|
3444
|
-
}
|
|
3445
|
-
waitForWebhookResponse(runId) {
|
|
3446
|
-
return new Promise((resolve) => {
|
|
3447
|
-
const list = this.webhookResponseWaiters.get(runId) ?? [];
|
|
3448
|
-
list.push(resolve);
|
|
3449
|
-
this.webhookResponseWaiters.set(runId, list);
|
|
3450
|
-
});
|
|
3451
|
-
}
|
|
3452
|
-
resolveRunCompletion(result) {
|
|
3453
|
-
if (result.status !== "completed" && result.status !== "failed") return;
|
|
3454
|
-
const list = this.completionWaiters.get(result.runId);
|
|
3455
|
-
if (!list || list.length === 0) return;
|
|
3456
|
-
this.completionWaiters.delete(result.runId);
|
|
3457
|
-
for (const r of list) r(result);
|
|
3458
|
-
}
|
|
3459
|
-
resolveWebhookResponse(result) {
|
|
3460
|
-
const list = this.webhookResponseWaiters.get(result.runId);
|
|
3461
|
-
if (!list || list.length === 0) return;
|
|
3462
|
-
this.webhookResponseWaiters.delete(result.runId);
|
|
3463
|
-
for (const resolve of list) resolve(result);
|
|
3464
|
-
}
|
|
3465
|
-
};
|
|
3466
|
-
|
|
3467
|
-
//#endregion
|
|
3468
|
-
//#region src/orchestration/Engine.ts
|
|
3469
|
-
/**
|
|
3470
|
-
* Runtime facade for orchestration, continuation, triggers, and webhook routing.
|
|
3471
|
-
* Prefer {@link import("../intents/RunIntentService").RunIntentService} for host/HTTP invocation boundaries.
|
|
3472
|
-
* The class token is exported from `@codemation/core/bootstrap` (not the main `@codemation/core` barrel).
|
|
3473
|
-
*/
|
|
3474
|
-
var Engine = class {
|
|
3475
|
-
constructor(deps) {
|
|
3476
|
-
this.deps = deps;
|
|
3477
|
-
}
|
|
3478
|
-
loadWorkflows(workflows) {
|
|
3479
|
-
this.deps.tokenRegistry.registerFromWorkflows?.(workflows);
|
|
3480
|
-
this.deps.workflowCatalog.setWorkflows(workflows);
|
|
3481
|
-
this.deps.webhookTriggerMatcher.onEngineWorkflowsLoaded?.();
|
|
3482
|
-
}
|
|
3483
|
-
getTokenRegistry() {
|
|
3484
|
-
return this.deps.tokenRegistry;
|
|
3485
|
-
}
|
|
3486
|
-
resolveWorkflowSnapshot(args) {
|
|
3487
|
-
return this.deps.workflowSnapshotResolver.resolve(args);
|
|
3488
|
-
}
|
|
3489
|
-
async startTriggers() {
|
|
3490
|
-
return await this.deps.triggerRuntime.startTriggers();
|
|
3491
|
-
}
|
|
3492
|
-
async syncWorkflowTriggersForActivation(workflowId) {
|
|
3493
|
-
await this.deps.triggerRuntime.syncWorkflowTriggersForActivation(workflowId);
|
|
3494
|
-
this.deps.webhookTriggerMatcher.reloadWebhookRoutes?.();
|
|
3495
|
-
}
|
|
3496
|
-
async start(workflows) {
|
|
3497
|
-
await this.stop();
|
|
3498
|
-
this.loadWorkflows(workflows);
|
|
3499
|
-
await this.startTriggers();
|
|
3500
|
-
}
|
|
3501
|
-
async stop() {
|
|
3502
|
-
await this.deps.triggerRuntime.stop();
|
|
3503
|
-
this.deps.webhookTriggerMatcher.onEngineStopped?.();
|
|
3504
|
-
}
|
|
3505
|
-
resolveWebhookTrigger(args) {
|
|
3506
|
-
const entry = this.deps.webhookTriggerMatcher.lookup(args.endpointPath);
|
|
3507
|
-
if (!entry) return { status: "notFound" };
|
|
3508
|
-
if (!entry.methods.includes(args.method)) return {
|
|
3509
|
-
status: "methodNotAllowed",
|
|
3510
|
-
match: entry
|
|
3511
|
-
};
|
|
3512
|
-
return {
|
|
3513
|
-
status: "ok",
|
|
3514
|
-
match: entry
|
|
3515
|
-
};
|
|
3516
|
-
}
|
|
3517
|
-
async createTriggerTestItems(args) {
|
|
3518
|
-
return await this.deps.triggerRuntime.createTriggerTestItems(args);
|
|
3519
|
-
}
|
|
3520
|
-
async runWorkflow(wf, startAt, items, parent, executionOptions, persistedStateOverrides) {
|
|
3521
|
-
return await this.deps.runStartService.runWorkflow(wf, startAt, items, parent, executionOptions, persistedStateOverrides);
|
|
3522
|
-
}
|
|
3523
|
-
async runWorkflowFromState(request) {
|
|
3524
|
-
return await this.deps.runStartService.runWorkflowFromState(request);
|
|
3525
|
-
}
|
|
3526
|
-
async markNodeRunning(args) {
|
|
3527
|
-
return await this.deps.runContinuationService.markNodeRunning(args);
|
|
3528
|
-
}
|
|
3529
|
-
async resumeFromNodeResult(args) {
|
|
3530
|
-
return await this.deps.runContinuationService.resumeFromNodeResult(args);
|
|
3531
|
-
}
|
|
3532
|
-
async resumeFromNodeError(args) {
|
|
3533
|
-
return await this.deps.runContinuationService.resumeFromNodeError(args);
|
|
3534
|
-
}
|
|
3535
|
-
async resumeFromStepResult(args) {
|
|
3536
|
-
return await this.deps.runContinuationService.resumeFromStepResult(args);
|
|
3537
|
-
}
|
|
3538
|
-
async resumeFromStepError(args) {
|
|
3539
|
-
return await this.deps.runContinuationService.resumeFromStepError(args);
|
|
3540
|
-
}
|
|
3541
|
-
async waitForCompletion(runId) {
|
|
3542
|
-
return await this.deps.runContinuationService.waitForCompletion(runId);
|
|
3543
|
-
}
|
|
3544
|
-
async waitForWebhookResponse(runId) {
|
|
3545
|
-
return await this.deps.runContinuationService.waitForWebhookResponse(runId);
|
|
3546
|
-
}
|
|
3547
|
-
};
|
|
3548
|
-
|
|
3549
|
-
//#endregion
|
|
3550
|
-
//#region src/runtime/EngineFactory.ts
|
|
3551
|
-
/**
|
|
3552
|
-
* Composes the {@link Engine} graph from {@link EngineCompositionDeps}. Production wiring usually goes through
|
|
3553
|
-
* {@link import("../bootstrap/runtime/EngineRuntimeRegistrar").EngineRuntimeRegistrar}; this factory remains for tests and custom composition.
|
|
3554
|
-
* Exported from `@codemation/core/bootstrap` (not the main `@codemation/core` barrel).
|
|
3555
|
-
*/
|
|
3556
|
-
var EngineFactory = class {
|
|
3557
|
-
create(deps) {
|
|
3558
|
-
const waiters = new EngineWaiters();
|
|
3559
|
-
const credentialResolverFactory = new CredentialResolverFactory(deps.credentialSessions);
|
|
3560
|
-
const nodeEventPublisher = new NodeEventPublisher(deps.eventBus);
|
|
3561
|
-
const nodeStatePublisherFactory = new NodeExecutionStatePublisherFactory(deps.runStore, nodeEventPublisher);
|
|
3562
|
-
const planningFactory = new EngineWorkflowPlanningFactory(deps.workflowNodeInstanceFactory);
|
|
3563
|
-
const executionLimitsPolicy = deps.executionLimitsPolicy ?? new EngineExecutionLimitsPolicy();
|
|
3564
|
-
const workflowSnapshotCodec = deps.workflowSnapshotCodec ?? new require_InMemoryWorkflowCatalog.WorkflowSnapshotCodec(deps.tokenRegistry);
|
|
3565
|
-
const missingRuntimeFallbacks = deps.missingRuntimeFallbacks ?? new MissingRuntimeFallbacks();
|
|
3566
|
-
const workflowSnapshotResolver = new WorkflowSnapshotResolver(deps.workflowRepository, deps.tokenRegistry, workflowSnapshotCodec, missingRuntimeFallbacks);
|
|
3567
|
-
const semantics = new RunStateSemantics();
|
|
3568
|
-
const activationEnqueueService = new ActivationEnqueueService(deps.activationScheduler, deps.runStore, nodeEventPublisher);
|
|
3569
|
-
const runExecutionContextFactory = new WorkflowRunExecutionContextFactory(deps.executionContextFactory, credentialResolverFactory);
|
|
3570
|
-
const nodeActivationRequestComposer = new NodeActivationRequestComposer(deps.activationIdFactory, credentialResolverFactory);
|
|
3571
|
-
const persistedRunStateTerminalBuilder = new PersistedRunStateTerminalBuilder();
|
|
3572
|
-
const storagePolicyEvaluator = new WorkflowStoragePolicyEvaluator(deps.nodeResolver);
|
|
3573
|
-
const terminalPersistence = new RunTerminalPersistenceCoordinator(deps.runStore, storagePolicyEvaluator);
|
|
3574
|
-
const policyErrorServices = new WorkflowPolicyErrorServices(deps.nodeResolver);
|
|
3575
|
-
const runStartService = new RunStartService(deps.runIdFactory, deps.runStore, deps.runDataFactory, workflowSnapshotCodec, planningFactory, nodeStatePublisherFactory, runExecutionContextFactory, nodeActivationRequestComposer, activationEnqueueService, semantics, waiters, deps.workflowPolicyRuntimeDefaults, executionLimitsPolicy);
|
|
3576
|
-
const runContinuationService = new RunContinuationService(deps.activationIdFactory, deps.runStore, deps.runDataFactory, runExecutionContextFactory, workflowSnapshotResolver, planningFactory, nodeStatePublisherFactory, credentialResolverFactory, nodeActivationRequestComposer, persistedRunStateTerminalBuilder, activationEnqueueService, nodeEventPublisher, semantics, waiters, policyErrorServices, terminalPersistence, executionLimitsPolicy);
|
|
3577
|
-
const triggerRuntime = new TriggerRuntimeService(deps.workflowRepository, deps.workflowActivationPolicy, deps.runIdFactory, deps.runDataFactory, deps.executionContextFactory, credentialResolverFactory, nodeStatePublisherFactory, deps.nodeResolver, deps.triggerSetupStateStore, { emit: async (workflow, triggerNodeId, items) => {
|
|
3578
|
-
await runStartService.runWorkflow(workflow, triggerNodeId, items, void 0);
|
|
3579
|
-
} }, executionLimitsPolicy, deps.triggerRuntimeDiagnostics);
|
|
3580
|
-
const engine = new Engine({
|
|
3581
|
-
workflowCatalog: deps.workflowCatalog,
|
|
3582
|
-
tokenRegistry: deps.tokenRegistry,
|
|
3583
|
-
webhookTriggerMatcher: deps.webhookTriggerMatcher,
|
|
3584
|
-
workflowSnapshotResolver,
|
|
3585
|
-
triggerRuntime,
|
|
3586
|
-
runStartService,
|
|
3587
|
-
runContinuationService
|
|
3588
|
-
});
|
|
3589
|
-
deps.activationScheduler.setContinuation?.(engine);
|
|
3590
|
-
return engine;
|
|
3591
|
-
}
|
|
3592
|
-
};
|
|
3593
|
-
|
|
3594
|
-
//#endregion
|
|
3595
|
-
//#region src/runtime/EngineWorkflowRunnerService.ts
|
|
3596
|
-
var _ref$1;
|
|
3597
|
-
let EngineWorkflowRunnerService = class EngineWorkflowRunnerService$1 {
|
|
3598
|
-
constructor(engine, workflowRepository) {
|
|
3599
|
-
this.engine = engine;
|
|
3600
|
-
this.workflowRepository = workflowRepository;
|
|
3601
|
-
}
|
|
3602
|
-
async runById(args) {
|
|
3603
|
-
const { workflowId, startAt, items, parent } = args;
|
|
3604
|
-
const wf = this.workflowRepository.get(workflowId);
|
|
3605
|
-
if (!wf) throw new Error(`Unknown workflowId: ${workflowId}`);
|
|
3606
|
-
const startNodeId = startAt ?? this.findDefaultStartNodeId(wf);
|
|
3607
|
-
const scheduled = await this.engine.runWorkflow(wf, startNodeId, items, parent);
|
|
3608
|
-
if (scheduled.status !== "pending") return scheduled;
|
|
3609
|
-
return await this.engine.waitForCompletion(scheduled.runId);
|
|
3610
|
-
}
|
|
3611
|
-
findDefaultStartNodeId(wf) {
|
|
3612
|
-
return createWorkflowExecutableNodeClassifier(wf).findDefaultExecutableStartNodeId(wf);
|
|
3613
|
-
}
|
|
3614
|
-
};
|
|
3615
|
-
EngineWorkflowRunnerService = __decorate([
|
|
3616
|
-
(0, tsyringe.injectable)(),
|
|
3617
|
-
__decorateParam(0, (0, tsyringe.inject)(Engine)),
|
|
3618
|
-
__decorateParam(1, (0, tsyringe.inject)(CoreTokens.WorkflowRepository)),
|
|
3619
|
-
__decorateMetadata("design:paramtypes", [typeof (_ref$1 = typeof Engine !== "undefined" && Engine) === "function" ? _ref$1 : Object, Object])
|
|
3620
|
-
], EngineWorkflowRunnerService);
|
|
3621
|
-
|
|
3622
|
-
//#endregion
|
|
3623
|
-
//#region src/runtime/RunIntentService.ts
|
|
3624
|
-
var _ref;
|
|
3625
|
-
let RunIntentService = class RunIntentService$1 {
|
|
3626
|
-
constructor(engine, workflowRepository) {
|
|
3627
|
-
this.engine = engine;
|
|
3628
|
-
this.workflowRepository = workflowRepository;
|
|
3629
|
-
}
|
|
3630
|
-
async startWorkflow(args) {
|
|
3631
|
-
if (args.startAt && !args.currentState && !args.stopCondition && !args.reset) return await this.engine.runWorkflow(args.workflow, args.startAt, args.items, args.parent, args.executionOptions, {
|
|
3632
|
-
workflowSnapshot: args.workflowSnapshot,
|
|
3633
|
-
mutableState: args.mutableState
|
|
3634
|
-
});
|
|
3635
|
-
return await this.engine.runWorkflowFromState({
|
|
3636
|
-
workflow: args.workflow,
|
|
3637
|
-
items: args.items,
|
|
3638
|
-
parent: args.parent,
|
|
3639
|
-
executionOptions: args.executionOptions,
|
|
3640
|
-
workflowSnapshot: args.workflowSnapshot,
|
|
3641
|
-
mutableState: args.mutableState,
|
|
3642
|
-
currentState: args.currentState,
|
|
3643
|
-
stopCondition: args.stopCondition ?? { kind: "workflowCompleted" },
|
|
3644
|
-
reset: args.reset
|
|
3645
|
-
});
|
|
3646
|
-
}
|
|
3647
|
-
async rerunFromNode(args) {
|
|
3648
|
-
if (args.items) return await this.engine.runWorkflow(args.workflow, args.nodeId, args.items, args.parent, args.executionOptions, {
|
|
3649
|
-
workflowSnapshot: args.workflowSnapshot,
|
|
3650
|
-
mutableState: args.mutableState
|
|
3651
|
-
});
|
|
3652
|
-
return await this.engine.runWorkflowFromState({
|
|
3653
|
-
workflow: args.workflow,
|
|
3654
|
-
parent: args.parent,
|
|
3655
|
-
executionOptions: args.executionOptions,
|
|
3656
|
-
workflowSnapshot: args.workflowSnapshot,
|
|
3657
|
-
mutableState: args.mutableState,
|
|
3658
|
-
currentState: args.currentState,
|
|
3659
|
-
stopCondition: { kind: "workflowCompleted" },
|
|
3660
|
-
reset: { clearFromNodeId: args.nodeId }
|
|
3661
|
-
});
|
|
3662
|
-
}
|
|
3663
|
-
resolveWebhookTrigger(args) {
|
|
3664
|
-
return this.engine.resolveWebhookTrigger(args);
|
|
3665
|
-
}
|
|
3666
|
-
async runMatchedWebhook(args) {
|
|
3667
|
-
const resolution = this.resolveWebhookTrigger(args);
|
|
3668
|
-
if (resolution.status === "notFound") throw new Error("Unknown webhook endpoint");
|
|
3669
|
-
if (resolution.status === "methodNotAllowed") throw new Error("Method not allowed");
|
|
3670
|
-
return await this.runWebhookMatch({
|
|
3671
|
-
match: resolution.match,
|
|
3672
|
-
requestItem: args.requestItem
|
|
3673
|
-
});
|
|
3674
|
-
}
|
|
3675
|
-
async runWebhookMatch(args) {
|
|
3676
|
-
const workflow = this.workflowRepository.get(args.match.workflowId);
|
|
3677
|
-
if (!workflow) throw new Error(`Unknown workflowId: ${args.match.workflowId}`);
|
|
3678
|
-
const scheduled = await this.engine.runWorkflow(workflow, args.match.nodeId, [args.requestItem], void 0, {
|
|
3679
|
-
localOnly: true,
|
|
3680
|
-
webhook: true
|
|
3681
|
-
});
|
|
3682
|
-
if (scheduled.status === "failed") throw new Error(scheduled.error.message);
|
|
3683
|
-
if (scheduled.status === "completed") return {
|
|
3684
|
-
runId: scheduled.runId,
|
|
3685
|
-
workflowId: scheduled.workflowId,
|
|
3686
|
-
startedAt: scheduled.startedAt,
|
|
3687
|
-
runStatus: "completed",
|
|
3688
|
-
response: scheduled.outputs
|
|
3689
|
-
};
|
|
3690
|
-
return await Promise.race([this.engine.waitForWebhookResponse(scheduled.runId), this.engine.waitForCompletion(scheduled.runId).then((completed) => {
|
|
3691
|
-
if (completed.status === "failed") throw new Error(completed.error.message);
|
|
3692
|
-
return {
|
|
3693
|
-
runId: completed.runId,
|
|
3694
|
-
workflowId: completed.workflowId,
|
|
3695
|
-
startedAt: completed.startedAt,
|
|
3696
|
-
runStatus: "completed",
|
|
3697
|
-
response: completed.outputs
|
|
3698
|
-
};
|
|
3699
|
-
})]);
|
|
3700
|
-
}
|
|
3701
|
-
};
|
|
3702
|
-
RunIntentService = __decorate([
|
|
3703
|
-
(0, tsyringe.injectable)(),
|
|
3704
|
-
__decorateParam(0, (0, tsyringe.inject)(Engine)),
|
|
3705
|
-
__decorateParam(1, (0, tsyringe.inject)(CoreTokens.WorkflowRepository)),
|
|
3706
|
-
__decorateMetadata("design:paramtypes", [typeof (_ref = typeof Engine !== "undefined" && Engine) === "function" ? _ref : Object, Object])
|
|
3707
|
-
], RunIntentService);
|
|
3708
|
-
|
|
3709
|
-
//#endregion
|
|
3710
|
-
Object.defineProperty(exports, 'ConfigDrivenOffloadPolicy', {
|
|
3711
|
-
enumerable: true,
|
|
3712
|
-
get: function () {
|
|
3713
|
-
return ConfigDrivenOffloadPolicy;
|
|
3714
|
-
}
|
|
3715
|
-
});
|
|
3716
|
-
Object.defineProperty(exports, 'ConnectionNodeIdFactory', {
|
|
3717
|
-
enumerable: true,
|
|
3718
|
-
get: function () {
|
|
3719
|
-
return ConnectionNodeIdFactory;
|
|
3720
|
-
}
|
|
3721
|
-
});
|
|
3722
|
-
Object.defineProperty(exports, 'CoreTokens', {
|
|
3723
|
-
enumerable: true,
|
|
3724
|
-
get: function () {
|
|
3725
|
-
return CoreTokens;
|
|
3726
|
-
}
|
|
3727
|
-
});
|
|
3728
|
-
Object.defineProperty(exports, 'CredentialResolverFactory', {
|
|
3729
|
-
enumerable: true,
|
|
3730
|
-
get: function () {
|
|
3731
|
-
return CredentialResolverFactory;
|
|
3732
|
-
}
|
|
3733
|
-
});
|
|
3734
|
-
Object.defineProperty(exports, 'DefaultAsyncSleeper', {
|
|
3735
|
-
enumerable: true,
|
|
3736
|
-
get: function () {
|
|
3737
|
-
return DefaultAsyncSleeper;
|
|
3738
|
-
}
|
|
3739
|
-
});
|
|
3740
|
-
Object.defineProperty(exports, 'DefaultDrivingScheduler', {
|
|
3741
|
-
enumerable: true,
|
|
3742
|
-
get: function () {
|
|
3743
|
-
return DefaultDrivingScheduler;
|
|
3744
|
-
}
|
|
3745
|
-
});
|
|
3746
|
-
Object.defineProperty(exports, 'DefaultExecutionBinaryService', {
|
|
3747
|
-
enumerable: true,
|
|
3748
|
-
get: function () {
|
|
3749
|
-
return DefaultExecutionBinaryService;
|
|
3750
|
-
}
|
|
3751
|
-
});
|
|
3752
|
-
Object.defineProperty(exports, 'DefaultExecutionContextFactory', {
|
|
3753
|
-
enumerable: true,
|
|
3754
|
-
get: function () {
|
|
3755
|
-
return DefaultExecutionContextFactory;
|
|
3756
|
-
}
|
|
3757
|
-
});
|
|
3758
|
-
Object.defineProperty(exports, 'ENGINE_EXECUTION_LIMITS_DEFAULTS', {
|
|
3759
|
-
enumerable: true,
|
|
3760
|
-
get: function () {
|
|
3761
|
-
return ENGINE_EXECUTION_LIMITS_DEFAULTS;
|
|
3762
|
-
}
|
|
3763
|
-
});
|
|
3764
|
-
Object.defineProperty(exports, 'Engine', {
|
|
3765
|
-
enumerable: true,
|
|
3766
|
-
get: function () {
|
|
3767
|
-
return Engine;
|
|
3768
|
-
}
|
|
3769
|
-
});
|
|
3770
|
-
Object.defineProperty(exports, 'EngineExecutionLimitsPolicy', {
|
|
3771
|
-
enumerable: true,
|
|
3772
|
-
get: function () {
|
|
3773
|
-
return EngineExecutionLimitsPolicy;
|
|
3774
|
-
}
|
|
3775
|
-
});
|
|
3776
|
-
Object.defineProperty(exports, 'EngineFactory', {
|
|
3777
|
-
enumerable: true,
|
|
3778
|
-
get: function () {
|
|
3779
|
-
return EngineFactory;
|
|
3780
|
-
}
|
|
3781
|
-
});
|
|
3782
|
-
Object.defineProperty(exports, 'EngineWorkflowRunnerService', {
|
|
3783
|
-
enumerable: true,
|
|
3784
|
-
get: function () {
|
|
3785
|
-
return EngineWorkflowRunnerService;
|
|
3786
|
-
}
|
|
3787
|
-
});
|
|
3788
|
-
Object.defineProperty(exports, 'HintOnlyOffloadPolicy', {
|
|
3789
|
-
enumerable: true,
|
|
3790
|
-
get: function () {
|
|
3791
|
-
return HintOnlyOffloadPolicy;
|
|
3792
|
-
}
|
|
3793
|
-
});
|
|
3794
|
-
Object.defineProperty(exports, 'InMemoryBinaryStorage', {
|
|
3795
|
-
enumerable: true,
|
|
3796
|
-
get: function () {
|
|
3797
|
-
return InMemoryBinaryStorage;
|
|
3798
|
-
}
|
|
3799
|
-
});
|
|
3800
|
-
Object.defineProperty(exports, 'InMemoryRunDataFactory', {
|
|
3801
|
-
enumerable: true,
|
|
3802
|
-
get: function () {
|
|
3803
|
-
return InMemoryRunDataFactory;
|
|
3804
|
-
}
|
|
3805
|
-
});
|
|
3806
|
-
Object.defineProperty(exports, 'InProcessRetryRunner', {
|
|
3807
|
-
enumerable: true,
|
|
3808
|
-
get: function () {
|
|
3809
|
-
return InProcessRetryRunner;
|
|
3810
|
-
}
|
|
3811
|
-
});
|
|
3812
|
-
Object.defineProperty(exports, 'InjectableRuntimeDecoratorComposer', {
|
|
3813
|
-
enumerable: true,
|
|
3814
|
-
get: function () {
|
|
3815
|
-
return InjectableRuntimeDecoratorComposer;
|
|
3816
|
-
}
|
|
3817
|
-
});
|
|
3818
|
-
Object.defineProperty(exports, 'InlineDrivingScheduler', {
|
|
3819
|
-
enumerable: true,
|
|
3820
|
-
get: function () {
|
|
3821
|
-
return InlineDrivingScheduler;
|
|
3822
|
-
}
|
|
3823
|
-
});
|
|
3824
|
-
Object.defineProperty(exports, 'LocalOnlyScheduler', {
|
|
3825
|
-
enumerable: true,
|
|
3826
|
-
get: function () {
|
|
3827
|
-
return LocalOnlyScheduler;
|
|
3828
|
-
}
|
|
3829
|
-
});
|
|
3830
|
-
Object.defineProperty(exports, 'MissingRuntimeNode', {
|
|
3831
|
-
enumerable: true,
|
|
3832
|
-
get: function () {
|
|
3833
|
-
return MissingRuntimeNode;
|
|
3834
|
-
}
|
|
3835
|
-
});
|
|
3836
|
-
Object.defineProperty(exports, 'MissingRuntimeNodeToken', {
|
|
3837
|
-
enumerable: true,
|
|
3838
|
-
get: function () {
|
|
3839
|
-
return MissingRuntimeNodeToken;
|
|
3840
|
-
}
|
|
3841
|
-
});
|
|
3842
|
-
Object.defineProperty(exports, 'MissingRuntimeTrigger', {
|
|
3843
|
-
enumerable: true,
|
|
3844
|
-
get: function () {
|
|
3845
|
-
return MissingRuntimeTrigger;
|
|
3846
|
-
}
|
|
3847
|
-
});
|
|
3848
|
-
Object.defineProperty(exports, 'MissingRuntimeTriggerToken', {
|
|
3849
|
-
enumerable: true,
|
|
3850
|
-
get: function () {
|
|
3851
|
-
return MissingRuntimeTriggerToken;
|
|
3852
|
-
}
|
|
3853
|
-
});
|
|
3854
|
-
Object.defineProperty(exports, 'NodeEventPublisher', {
|
|
3855
|
-
enumerable: true,
|
|
3856
|
-
get: function () {
|
|
3857
|
-
return NodeEventPublisher;
|
|
3858
|
-
}
|
|
3859
|
-
});
|
|
3860
|
-
Object.defineProperty(exports, 'NodeExecutor', {
|
|
3861
|
-
enumerable: true,
|
|
3862
|
-
get: function () {
|
|
3863
|
-
return NodeExecutor;
|
|
3864
|
-
}
|
|
3865
|
-
});
|
|
3866
|
-
Object.defineProperty(exports, 'PersistedRuntimeTypeMetadataStore', {
|
|
3867
|
-
enumerable: true,
|
|
3868
|
-
get: function () {
|
|
3869
|
-
return PersistedRuntimeTypeMetadataStore;
|
|
3870
|
-
}
|
|
3871
|
-
});
|
|
3872
|
-
Object.defineProperty(exports, 'PersistedRuntimeTypeNameResolver', {
|
|
3873
|
-
enumerable: true,
|
|
3874
|
-
get: function () {
|
|
3875
|
-
return PersistedRuntimeTypeNameResolver;
|
|
3876
|
-
}
|
|
3877
|
-
});
|
|
3878
|
-
Object.defineProperty(exports, 'RunFinishedAtFactory', {
|
|
3879
|
-
enumerable: true,
|
|
3880
|
-
get: function () {
|
|
3881
|
-
return RunFinishedAtFactory;
|
|
3882
|
-
}
|
|
3883
|
-
});
|
|
3884
|
-
Object.defineProperty(exports, 'RunIntentService', {
|
|
3885
|
-
enumerable: true,
|
|
3886
|
-
get: function () {
|
|
3887
|
-
return RunIntentService;
|
|
3888
|
-
}
|
|
3889
|
-
});
|
|
3890
|
-
Object.defineProperty(exports, 'RunPolicySnapshotFactory', {
|
|
3891
|
-
enumerable: true,
|
|
3892
|
-
get: function () {
|
|
3893
|
-
return RunPolicySnapshotFactory;
|
|
3894
|
-
}
|
|
3895
|
-
});
|
|
3896
|
-
Object.defineProperty(exports, 'RunTerminalPersistenceCoordinator', {
|
|
3897
|
-
enumerable: true,
|
|
3898
|
-
get: function () {
|
|
3899
|
-
return RunTerminalPersistenceCoordinator;
|
|
3900
|
-
}
|
|
3901
|
-
});
|
|
3902
|
-
Object.defineProperty(exports, 'StackTraceCallSitePathResolver', {
|
|
3903
|
-
enumerable: true,
|
|
3904
|
-
get: function () {
|
|
3905
|
-
return StackTraceCallSitePathResolver;
|
|
3906
|
-
}
|
|
3907
|
-
});
|
|
3908
|
-
Object.defineProperty(exports, 'UnavailableBinaryStorage', {
|
|
3909
|
-
enumerable: true,
|
|
3910
|
-
get: function () {
|
|
3911
|
-
return UnavailableBinaryStorage;
|
|
3912
|
-
}
|
|
3913
|
-
});
|
|
3914
|
-
Object.defineProperty(exports, 'WorkflowExecutableNodeClassifier', {
|
|
3915
|
-
enumerable: true,
|
|
3916
|
-
get: function () {
|
|
3917
|
-
return WorkflowExecutableNodeClassifier;
|
|
3918
|
-
}
|
|
3919
|
-
});
|
|
3920
|
-
Object.defineProperty(exports, 'WorkflowPolicyErrorServices', {
|
|
3921
|
-
enumerable: true,
|
|
3922
|
-
get: function () {
|
|
3923
|
-
return WorkflowPolicyErrorServices;
|
|
3924
|
-
}
|
|
3925
|
-
});
|
|
3926
|
-
Object.defineProperty(exports, 'WorkflowStoragePolicyEvaluator', {
|
|
3927
|
-
enumerable: true,
|
|
3928
|
-
get: function () {
|
|
3929
|
-
return WorkflowStoragePolicyEvaluator;
|
|
3930
|
-
}
|
|
3931
|
-
});
|
|
3932
|
-
Object.defineProperty(exports, '__decorate', {
|
|
3933
|
-
enumerable: true,
|
|
3934
|
-
get: function () {
|
|
3935
|
-
return __decorate;
|
|
3936
|
-
}
|
|
3937
|
-
});
|
|
3938
|
-
Object.defineProperty(exports, '__decorateMetadata', {
|
|
3939
|
-
enumerable: true,
|
|
3940
|
-
get: function () {
|
|
3941
|
-
return __decorateMetadata;
|
|
3942
|
-
}
|
|
3943
|
-
});
|
|
3944
|
-
Object.defineProperty(exports, '__decorateParam', {
|
|
3945
|
-
enumerable: true,
|
|
3946
|
-
get: function () {
|
|
3947
|
-
return __decorateParam;
|
|
3948
|
-
}
|
|
3949
|
-
});
|
|
3950
|
-
Object.defineProperty(exports, '__toESM', {
|
|
3951
|
-
enumerable: true,
|
|
3952
|
-
get: function () {
|
|
3953
|
-
return __toESM;
|
|
3954
|
-
}
|
|
3955
|
-
});
|
|
3956
|
-
Object.defineProperty(exports, 'chatModel', {
|
|
3957
|
-
enumerable: true,
|
|
3958
|
-
get: function () {
|
|
3959
|
-
return chatModel;
|
|
3960
|
-
}
|
|
3961
|
-
});
|
|
3962
|
-
Object.defineProperty(exports, 'createWorkflowExecutableNodeClassifier', {
|
|
3963
|
-
enumerable: true,
|
|
3964
|
-
get: function () {
|
|
3965
|
-
return createWorkflowExecutableNodeClassifier;
|
|
3966
|
-
}
|
|
3967
|
-
});
|
|
3968
|
-
Object.defineProperty(exports, 'getPersistedRuntimeTypeMetadata', {
|
|
3969
|
-
enumerable: true,
|
|
3970
|
-
get: function () {
|
|
3971
|
-
return getPersistedRuntimeTypeMetadata;
|
|
3972
|
-
}
|
|
3973
|
-
});
|
|
3974
|
-
Object.defineProperty(exports, 'node', {
|
|
3975
|
-
enumerable: true,
|
|
3976
|
-
get: function () {
|
|
3977
|
-
return node;
|
|
3978
|
-
}
|
|
3979
|
-
});
|
|
3980
|
-
Object.defineProperty(exports, 'tool', {
|
|
3981
|
-
enumerable: true,
|
|
3982
|
-
get: function () {
|
|
3983
|
-
return tool;
|
|
3984
|
-
}
|
|
3985
|
-
});
|
|
3986
|
-
//# sourceMappingURL=runtime-D3eWKSQK.cjs.map
|