@codemation/core 0.0.7 → 0.0.11

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