@oomol-lab/open-flow 0.1.0-beta.1 → 0.1.0-beta.10

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 (54) hide show
  1. package/dist/browser/DesignerIcon-DjgOMYI5.js +2065 -0
  2. package/dist/browser/{createResourceDialog-DXQz0thK.js → createResourceDialog-DNBueSYZ.js} +161 -160
  3. package/dist/browser/{dist-BMqL-qR5.js → dist-BMRLCebL.js} +291 -292
  4. package/dist/browser/{dist-DWADUsVB.js → dist-By46o5UV.js} +47 -47
  5. package/dist/browser/dist-CP0883sY.js +4 -0
  6. package/dist/browser/{dist-CJpzJrLM.js → dist-Cc0y2Pli.js} +811 -812
  7. package/dist/browser/{dist-DUzA0Ukh.js → dist-Dg_VXC8f.js} +134 -135
  8. package/dist/browser/{dist-3Mj8q8Pr.js → dist-DmuE3M0R.js} +53 -54
  9. package/dist/browser/{dist-BN4ZCyOB.js → dist-DpDLsYtO.js} +14 -15
  10. package/dist/browser/dist-DxahK_I8.js +2688 -0
  11. package/dist/browser/{dist-CPuF50D9.js → dist-meg_oHVR.js} +335 -335
  12. package/dist/browser/{esm-DGQbgYoJ.js → esm-yhVU_KbQ.js} +5 -6
  13. package/dist/browser/flow-authoring-module.d.ts +2 -2
  14. package/dist/browser/flow-authoring-node.d.ts +6 -3
  15. package/dist/browser/flow-authoring.d.ts +1 -1
  16. package/dist/browser/flow-authoring.js +509 -209
  17. package/dist/browser/flow-change.d.ts +113 -9
  18. package/dist/browser/flow-change.js +323 -96
  19. package/dist/browser/flow-notifications.d.ts +5 -0
  20. package/dist/browser/flowChanges-B2ttnaj9.js +12265 -0
  21. package/dist/browser/{flowRunInputEditorStore-BeyUSWpO.js → flowRunInputEditorStore-DDidwd8h.js} +728 -719
  22. package/dist/browser/{flowWorkspace-DwyxAOBH.js → flowWorkspace-Dr8-Hut9.js} +40821 -42895
  23. package/dist/browser/{getPseudoElementBounds-ESJExRFX.js → getPseudoElementBounds-5LArT6Xc.js} +1827 -2322
  24. package/dist/browser/icons-KIOgjHpD.js +730 -0
  25. package/dist/browser/{markdownContent-DdlIRN3_.js → markdownContent-DUfLdnUt.js} +1 -1
  26. package/dist/browser/{typeScriptSession-mPCiA9sV.js → typeScriptSession-_TgJ_7Oq.js} +256 -257
  27. package/dist/browser/waitNotificationInputs-BPulOxYt.js +26 -0
  28. package/dist/browser/workbench.css +1 -1
  29. package/dist/browser/workbench.d.ts +3 -1
  30. package/dist/browser/workbench.js +1136 -1038
  31. package/dist/browser/{workbenchSelect-B2s1HV-Y.js → workbenchSelect-CbXrdwxW.js} +479 -478
  32. package/dist/common/control-api-conformance.d.ts +1 -0
  33. package/dist/common/control-api-conformance.js +126 -47
  34. package/dist/common/control-api-errors.d.ts +12 -0
  35. package/dist/common/control-api.d.ts +60 -15
  36. package/dist/common/control-api.js +225 -101
  37. package/dist/common/flow-encoding.js +24 -8
  38. package/dist/common/flow-notifications.d.ts +5 -0
  39. package/dist/common/flow-semantics.d.ts +1 -0
  40. package/dist/common/flow-semantics.js +3464 -1113
  41. package/dist/common/integration-trigger.d.ts +1 -0
  42. package/dist/common/provider-triggers.js +4 -1
  43. package/dist/common/run-events.js +2 -1
  44. package/dist/common/run-lifecycle.d.ts +17 -2
  45. package/dist/common/run-lifecycle.js +53 -2
  46. package/dist/common/runtime-contract.d.ts +1 -1
  47. package/dist/common/runtime-contract.js +27 -0
  48. package/dist/common/scheduler.d.ts +65 -4
  49. package/dist/common/scheduler.js +420 -146
  50. package/dist/index.d.ts +2 -1
  51. package/package.json +1 -1
  52. package/dist/browser/diagnostics-BGoGFvHA.js +0 -9237
  53. package/dist/browser/dist-BpopSHwP.js +0 -1543
  54. package/dist/browser/dist-CUSrALSX.js +0 -1620
@@ -1,19 +1,26 @@
1
1
  import * as e from "effect/Effect";
2
2
  import * as t from "effect/Exit";
3
3
  import * as n from "effect/FiberSet";
4
+ //#region ../../node_modules/.bun/nanoid@6.0.1/node_modules/nanoid/url-alphabet/index.js
5
+ var r = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", i = (e = 21) => {
6
+ let t = "", n = crypto.getRandomValues(new Uint8Array(e |= 0));
7
+ for (; e--;) t += r[n[e] & 63];
8
+ return t;
9
+ };
10
+ //#endregion
4
11
  //#region src/flow/common/change.ts
5
- function r(e) {
12
+ function a(e) {
6
13
  return Object.fromEntries(e.flatMap((e) => "handle" in e ? [[e.handle, e]] : []));
7
14
  }
8
15
  //#endregion
9
16
  //#region src/execution/common/scheduler.ts
10
- function i(e, t) {
17
+ function o(e, t) {
11
18
  return t?.(e) ?? {
12
19
  code: "node.failed",
13
20
  message: e instanceof Error ? e.message : String(e)
14
21
  };
15
22
  }
16
- var a = class {
23
+ var s = class {
17
24
  #e = [];
18
25
  #t = 0;
19
26
  get length() {
@@ -26,14 +33,19 @@ var a = class {
26
33
  let e = this.#e[this.#t];
27
34
  return this.#t += 1, this.#t >= 64 && this.#t * 2 >= this.#e.length && (this.#e.splice(0, this.#t), this.#t = 0), e;
28
35
  }
29
- }, o = class {
36
+ restore(e) {
37
+ this.#e.push(...e);
38
+ }
39
+ snapshot() {
40
+ return this.#e.slice(this.#t);
41
+ }
42
+ }, c = class {
30
43
  #e;
31
- #t = new a();
44
+ #t = new s();
32
45
  #n;
33
46
  #r;
34
- constructor(e, t, n) {
35
- let r = e.inputs[t];
36
- this.#e = r?.kind == "sources", this.#n = !this.#e && (r?.kind == "value" || Object.hasOwn(n, "value")), this.#r = r?.kind == "value" ? r.value : n.value ?? null;
47
+ constructor(e, t) {
48
+ this.#e = e?.kind == "sources", this.#n = !this.#e && (e?.kind == "value" || Object.hasOwn(t, "value")), this.#r = e?.kind == "value" ? e.value : t.value ?? null;
37
49
  }
38
50
  get ready() {
39
51
  return this.#t.length > 0 || this.#n;
@@ -50,13 +62,26 @@ var a = class {
50
62
  take() {
51
63
  return this.#t.length > 0 ? this.#t.shift() : this.#r;
52
64
  }
53
- }, s = class {
65
+ restore(e) {
66
+ this.#n = e.provided, this.#r = e.value, this.#t.restore(e.queue);
67
+ }
68
+ snapshot() {
69
+ return {
70
+ provided: this.#n,
71
+ queue: this.#t.snapshot(),
72
+ value: this.#r
73
+ };
74
+ }
75
+ }, l = class {
54
76
  #e;
55
77
  #t;
56
78
  #n;
57
79
  #r = !1;
58
- constructor(e, t, n) {
59
- this.#t = e, this.#n = new Map(Object.entries(n).map(([e, n]) => [e, new o(t, e, n)])), this.#e = [...this.#n.values()].some((e) => e.dynamic);
80
+ constructor(e, t, n, r) {
81
+ this.#t = e, this.#n = new Map(Object.entries(n).map(([e, n]) => {
82
+ let i = new c(t[e], n), a = r?.slots[e];
83
+ return a != null && i.restore(a), [e, i];
84
+ })), this.#e = [...this.#n.values()].some((e) => e.dynamic), this.#r = r?.staticTaken ?? !1;
60
85
  }
61
86
  get ready() {
62
87
  return (!this.#r || this.#e) && [...this.#n.values()].every((e) => e.ready);
@@ -74,36 +99,59 @@ var a = class {
74
99
  if (!this.ready) throw Error(`Node "${this.#t}" inputs are not ready.`);
75
100
  return this.#e || (this.#r = !0), Object.fromEntries([...this.#n].map(([e, t]) => [e, t.take()]));
76
101
  }
77
- };
78
- function c(e, t) {
102
+ snapshot() {
103
+ return {
104
+ slots: Object.fromEntries([...this.#n].map(([e, t]) => [e, t.snapshot()])),
105
+ staticTaken: this.#r
106
+ };
107
+ }
108
+ }, u = "notification:";
109
+ function d(e) {
110
+ return `${u}${e}`;
111
+ }
112
+ function f(e) {
113
+ return e.kind != "wait" || e.notification == null ? e.inputs : {
114
+ ...e.inputs,
115
+ ...Object.fromEntries(Object.entries(e.notification.inputs).map(([e, t]) => [d(e), t]))
116
+ };
117
+ }
118
+ function p(e, t) {
79
119
  switch (t.kind) {
80
120
  case "condition": return { [t.input.handle]: t.input };
81
121
  case "value": return {};
82
- case "subflow": return r(e.subflows[t.subflowId].inputs);
83
- case "task": return r(t.task == null ? e.tasks[t.taskId].inputs : t.task.inputs);
122
+ case "subflow": return a(e.subflows[t.subflowId].inputs);
123
+ case "task": return a([...t.task == null ? e.tasks[t.taskId].inputs : t.task.inputs, ...t.additionalInputs ?? []]);
124
+ case "wait": {
125
+ let n = t.notification, r = n == null ? void 0 : e.tasks[n.taskId];
126
+ return {
127
+ [t.input.handle]: t.input,
128
+ ...n == null || r == null ? {} : Object.fromEntries(r.inputs.flatMap((e) => "handle" in e && e.handle != n.messageHandle ? [[d(e.handle), e]] : []))
129
+ };
130
+ }
84
131
  }
85
132
  }
86
- function l(e, t) {
133
+ function m(e, t) {
87
134
  if (t.name != null) return t.name;
88
135
  switch (t.kind) {
89
136
  case "condition": return;
90
137
  case "value": return "Value";
91
138
  case "subflow": return e.subflows[t.subflowId].name;
92
139
  case "task": return t.task == null ? e.tasks[t.taskId].name : t.task.name;
140
+ case "wait": return "Wait";
93
141
  }
94
142
  }
95
- function u(e, t) {
143
+ function h(e, t) {
96
144
  return t.kind == "task" ? t.task == null ? e.tasks[t.taskId].executor.kind : "javascript" : t.kind;
97
145
  }
98
- function d(e, t, n, r) {
146
+ function g(e, t, n, r) {
99
147
  let i = e.get(t) ?? /* @__PURE__ */ new Map(), a = i.get(n) ?? [];
100
148
  a.push(r), i.set(n, a), e.set(t, i);
101
149
  }
102
- function f(e, t, n) {
150
+ function _(e, t, n) {
103
151
  return e.get(t)?.get(n) ?? [];
104
152
  }
105
- function p(e) {
106
- let t = new Map(Object.entries(e.nodes).map(([t, n]) => [t, new Set(Object.values(n.inputs).flatMap((t) => t.kind == "sources" ? t.sources.flatMap((t) => t.kind == "node" && e.nodes[t.nodeId] != null ? [t.nodeId] : []) : []))])), n = [];
153
+ function v(e) {
154
+ let t = new Map(Object.entries(e.nodes).map(([t, n]) => [t, new Set(Object.values(f(n)).flatMap((t) => t.kind == "sources" ? t.sources.flatMap((t) => t.kind == "node" && e.nodes[t.nodeId] != null ? [t.nodeId] : []) : []))])), n = [];
107
155
  for (; t.size > 0;) {
108
156
  let e = [...t].filter(([, e]) => e.size == 0).map(([e]) => e).toSorted();
109
157
  if (e.length == 0) throw Error("Prepared graph contains a dependency cycle.");
@@ -112,18 +160,124 @@ function p(e) {
112
160
  }
113
161
  return n;
114
162
  }
115
- function m(e, t) {
163
+ function y(e, t) {
164
+ let n = new Set(Object.values(e.nodes).flatMap((e) => Object.values(f(e)).flatMap((e) => e.kind == "sources" ? e.sources.filter((e) => e.kind == "node").map((e) => e.nodeId) : [])));
165
+ return t.filter((e) => !n.has(e));
166
+ }
167
+ function b(e, t) {
168
+ if (typeof e != "object" || !e || Array.isArray(e)) throw Error(`${t} must be an object.`);
169
+ return e;
170
+ }
171
+ function x(e, t, n) {
172
+ let r = Object.keys(e);
173
+ if (r.length != t.length || r.some((e) => !t.includes(e))) throw Error(`${n} contains unsupported fields.`);
174
+ }
175
+ function S(e, t) {
176
+ if (typeof e != "string" || e.length == 0) throw Error(`${t} must be a non-empty string.`);
177
+ return e;
178
+ }
179
+ function C(e, t) {
180
+ if (!Number.isSafeInteger(e) || Number(e) < 0) throw Error(`${t} must be a non-negative integer.`);
181
+ return Number(e);
182
+ }
183
+ function w(e, t, n = 0) {
184
+ if (n > 64) throw Error(`${t} exceeds the maximum JSON depth.`);
185
+ if (e === null || typeof e == "boolean" || typeof e == "string" || typeof e == "number" && Number.isFinite(e)) return e;
186
+ if (Array.isArray(e)) return e.map((e) => w(e, t, n + 1));
187
+ let r = b(e, t);
188
+ return Object.fromEntries(Object.entries(r).map(([e, r]) => [e, w(r, t, n + 1)]));
189
+ }
190
+ function T(e) {
191
+ let t = b(e, "Flow Run checkpoint");
192
+ if (x(t, [
193
+ "bindingValues",
194
+ "buffers",
195
+ "completedNodes",
196
+ "nextJobs",
197
+ "outputs",
198
+ "results",
199
+ "version",
200
+ "wait"
201
+ ], "Flow Run checkpoint"), t.version != 1) throw Error("Flow Run checkpoint version is unsupported.");
202
+ let n = b(t.bindingValues, "Flow Run checkpoint bindings"), r = Object.fromEntries(Object.entries(n).map(([e, t]) => {
203
+ if (typeof t != "string") throw Error(`Flow Run checkpoint binding "${e}" must be a string.`);
204
+ return [e, t];
205
+ })), i = b(t.buffers, "Flow Run checkpoint buffers"), a = Object.fromEntries(Object.entries(i).map(([e, t]) => {
206
+ let n = b(t, `Flow Run checkpoint buffer "${e}"`);
207
+ if (x(n, ["slots", "staticTaken"], `Flow Run checkpoint buffer "${e}"`), typeof n.staticTaken != "boolean") throw Error(`Flow Run checkpoint buffer "${e}" staticTaken must be boolean.`);
208
+ let r = b(n.slots, `Flow Run checkpoint buffer "${e}" slots`);
209
+ return [e, {
210
+ slots: Object.fromEntries(Object.entries(r).map(([t, n]) => {
211
+ let r = b(n, `Flow Run checkpoint slot "${e}/${t}"`);
212
+ if (x(r, [
213
+ "provided",
214
+ "queue",
215
+ "value"
216
+ ], `Flow Run checkpoint slot "${e}/${t}"`), typeof r.provided != "boolean" || !Array.isArray(r.queue)) throw Error(`Flow Run checkpoint slot "${e}/${t}" is invalid.`);
217
+ return [t, {
218
+ provided: r.provided,
219
+ queue: r.queue.map((n) => w(n, `Flow Run checkpoint slot "${e}/${t}" queue`)),
220
+ value: w(r.value, `Flow Run checkpoint slot "${e}/${t}" value`)
221
+ }];
222
+ })),
223
+ staticTaken: n.staticTaken
224
+ }];
225
+ }));
226
+ if (!Array.isArray(t.completedNodes) || !Array.isArray(t.results)) throw Error("Flow Run checkpoint result state is invalid.");
227
+ let o = t.completedNodes.map((e) => S(e, "Flow Run checkpoint completed node")), s = Object.fromEntries(Object.entries(b(t.nextJobs, "Flow Run checkpoint next jobs")).map(([e, t]) => [e, C(t, `Flow Run checkpoint next job "${e}"`)])), c = Object.fromEntries(Object.entries(b(t.outputs, "Flow Run checkpoint outputs")).map(([e, t]) => [e, w(t, `Flow Run checkpoint output "${e}"`)])), l = t.results.map((e, t) => {
228
+ let n = b(e, `Flow Run checkpoint result ${t}`);
229
+ if (x(n, ["jobs", "nodeId"], `Flow Run checkpoint result ${t}`), !Array.isArray(n.jobs)) throw Error(`Flow Run checkpoint result ${t} jobs must be an array.`);
230
+ return {
231
+ jobs: n.jobs.map((e, n) => {
232
+ let r = b(e, `Flow Run checkpoint result ${t} job ${n}`);
233
+ return x(r, [
234
+ "jobId",
235
+ "order",
236
+ "outputs"
237
+ ], `Flow Run checkpoint result ${t} job ${n}`), {
238
+ jobId: S(r.jobId, `Flow Run checkpoint result ${t} job ${n} ID`),
239
+ order: C(r.order, `Flow Run checkpoint result ${t} job ${n} order`),
240
+ outputs: Object.fromEntries(Object.entries(b(r.outputs, `Flow Run checkpoint result ${t} job ${n} outputs`)).map(([e, r]) => [e, w(r, `Flow Run checkpoint result ${t} job ${n} output "${e}"`)]))
241
+ };
242
+ }),
243
+ nodeId: S(n.nodeId, `Flow Run checkpoint result ${t} node ID`)
244
+ };
245
+ }), u = b(t.wait, "Flow Run checkpoint wait");
246
+ return x(u, [
247
+ "jobId",
248
+ "nodeId",
249
+ "order",
250
+ "value",
251
+ "waitId"
252
+ ], "Flow Run checkpoint wait"), {
253
+ bindingValues: r,
254
+ buffers: a,
255
+ completedNodes: o,
256
+ nextJobs: s,
257
+ outputs: c,
258
+ results: l,
259
+ version: 1,
260
+ wait: {
261
+ jobId: S(u.jobId, "Flow Run checkpoint wait job ID"),
262
+ nodeId: S(u.nodeId, "Flow Run checkpoint wait node ID"),
263
+ order: C(u.order, "Flow Run checkpoint wait order"),
264
+ value: w(u.value, "Flow Run checkpoint wait value"),
265
+ waitId: S(u.waitId, "Flow Run checkpoint wait ID")
266
+ }
267
+ };
268
+ }
269
+ function E(e, t) {
116
270
  if (e === t) return !0;
117
271
  if (e == null || t == null || typeof e != "object" || typeof t != "object") return !1;
118
- if (Array.isArray(e) || Array.isArray(t)) return Array.isArray(e) && Array.isArray(t) && e.length == t.length && e.every((e, n) => m(e, t[n]));
272
+ if (Array.isArray(e) || Array.isArray(t)) return Array.isArray(e) && Array.isArray(t) && e.length == t.length && e.every((e, n) => E(e, t[n]));
119
273
  let n = Object.entries(e), r = Object.entries(t), i = t;
120
- return n.length == r.length && n.every(([e, t]) => Object.hasOwn(i, e) && m(t, i[e]));
274
+ return n.length == r.length && n.every(([e, t]) => Object.hasOwn(i, e) && E(t, i[e]));
121
275
  }
122
- function h(e, t, n) {
276
+ function D(e, t, n) {
123
277
  let r = Object.hasOwn(n, t.input) ? n[t.input] : null, i = t.value;
124
278
  switch (t.operator) {
125
- case "==": return i !== void 0 && m(r, i);
126
- case "!=": return i !== void 0 && !m(r, i);
279
+ case "==": return i !== void 0 && E(r, i);
280
+ case "!=": return i !== void 0 && !E(r, i);
127
281
  case ">": return typeof r == "number" && typeof i == "number" && r > i;
128
282
  case ">=": return typeof r == "number" && typeof i == "number" && r >= i;
129
283
  case "<": return typeof r == "number" && typeof i == "number" && r < i;
@@ -131,7 +285,7 @@ function h(e, t, n) {
131
285
  case "contains":
132
286
  case "notContains": {
133
287
  let e;
134
- return typeof r == "string" && typeof i == "string" ? e = r.includes(i) : Array.isArray(r) && i !== void 0 && (e = r.some((e) => m(e, i))), e == null ? !1 : t.operator == "contains" ? e : !e;
288
+ return typeof r == "string" && typeof i == "string" ? e = r.includes(i) : Array.isArray(r) && i !== void 0 && (e = r.some((e) => E(e, i))), e == null ? !1 : t.operator == "contains" ? e : !e;
135
289
  }
136
290
  case "startsWith": return typeof r == "string" && typeof i == "string" && r.startsWith(i);
137
291
  case "endsWith": return typeof r == "string" && typeof i == "string" && r.endsWith(i);
@@ -144,7 +298,7 @@ function h(e, t, n) {
144
298
  case "hasValue":
145
299
  case "notHasValue": {
146
300
  if (r == null || Array.isArray(r) || typeof r != "object" || i === void 0) return !1;
147
- let e = Object.values(r).some((e) => m(e, i));
301
+ let e = Object.values(r).some((e) => E(e, i));
148
302
  return t.operator == "hasValue" ? e : !e;
149
303
  }
150
304
  case "isEmpty":
@@ -158,65 +312,76 @@ function h(e, t, n) {
158
312
  case "isFalse": return r === !1;
159
313
  }
160
314
  }
161
- function g(e, t) {
315
+ function O(e, t) {
316
+ if (e === void 0) return {};
162
317
  if (typeof e != "object" || !e || Array.isArray(e)) throw Error(`Node "${t}" must return an object.`);
163
318
  return e;
164
319
  }
165
- function _(a, o, m, v, b, x = {}, S, C) {
320
+ function k(r, s, c, d, b, x = {}, S, C, w) {
166
321
  return e.scoped(e.gen(function* () {
167
- yield* a.emit({
168
- flowId: o.flowId,
322
+ w ?? (yield* r.emit({
323
+ flowId: s.flowId,
169
324
  ...b == null ? {} : {
170
325
  parentJobId: b.jobId,
171
326
  parentRunId: b.runId
172
327
  },
173
- runId: m,
328
+ runId: c,
174
329
  type: "run.started"
175
- });
176
- let w = p(o.graph), T = w.length, E = new Map(Object.entries(o.graph.nodes).map(([e, t]) => [e, new s(e, t, c(a.prepared, t))])), D = /* @__PURE__ */ new Map(), O = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Map(), A = /* @__PURE__ */ new Map();
177
- for (let [e, t] of Object.entries(o.graph.nodes)) for (let [n, r] of Object.entries(t.inputs)) if (r.kind == "sources") for (let t of r.sources) if (t.kind == "binding") {
178
- let r = O.get(t.bindingId) ?? [];
330
+ }));
331
+ let E = v(s.graph), A = y(s.graph, E), M = E.length, N = new Map(Object.entries(s.graph.nodes).map(([e, t]) => [e, new l(e, f(t), p(r.prepared, t), w?.checkpoint.buffers[e])]));
332
+ if (w != null) {
333
+ let t = Object.keys(w.checkpoint.buffers).toSorted();
334
+ if (t.length != E.length || t.some((e, t) => e != [...E].toSorted()[t])) return yield* e.fail(/* @__PURE__ */ Error("Flow Run checkpoint buffers do not match the prepared graph."));
335
+ for (let [t, n] of Object.entries(s.graph.nodes)) {
336
+ let i = Object.keys(p(r.prepared, n)).toSorted(), a = Object.keys(w.checkpoint.buffers[t].slots).toSorted();
337
+ if (i.length != a.length || i.some((e, t) => e != a[t])) return yield* e.fail(/* @__PURE__ */ Error(`Flow Run checkpoint inputs do not match node "${t}".`));
338
+ }
339
+ }
340
+ let P = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new Map(), L = /* @__PURE__ */ new Map();
341
+ for (let [e, t] of Object.entries(s.graph.nodes)) for (let [n, r] of Object.entries(f(t))) if (r.kind == "sources") for (let t of r.sources) if (t.kind == "binding") {
342
+ let r = F.get(t.bindingId) ?? [];
179
343
  r.push({
180
344
  handle: n,
181
345
  nodeId: e
182
- }), O.set(t.bindingId, r);
346
+ }), F.set(t.bindingId, r);
183
347
  } else if (t.kind == "flow") {
184
- let r = D.get(t.input) ?? [];
348
+ let r = P.get(t.input) ?? [];
185
349
  r.push({
186
350
  handle: n,
187
351
  nodeId: e
188
- }), D.set(t.input, r);
189
- } else t.kind == "node" && d(k, t.nodeId, t.output, {
352
+ }), P.set(t.input, r);
353
+ } else t.kind == "node" && g(I, t.nodeId, t.output, {
190
354
  handle: n,
191
355
  nodeId: e
192
356
  });
193
- for (let [e, t] of Object.entries(o.outputs)) for (let n of t.sources) n.kind == "node" && d(A, n.nodeId, n.output, e);
194
- let j = /* @__PURE__ */ new Map(), M = yield* n.make(), N = yield* n.runtime(M)(), P = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new Map(), L = /* @__PURE__ */ new Set(), R, z, B, V = (e, t) => {
195
- R ?? (E.get(e.nodeId).push(e.handle, t), B(e.nodeId));
196
- }, H = (t, n, r, i) => e.gen(function* () {
197
- yield* a.emit({
198
- handle: r,
357
+ for (let [e, t] of Object.entries(s.outputs)) for (let n of t.sources) n.kind == "node" && g(L, n.nodeId, n.output, e);
358
+ let R = /* @__PURE__ */ new Map(), z = yield* n.make(), B = yield* n.runtime(z)(), V = new Map(w?.checkpoint.results.map((e) => [e.nodeId, [...e.jobs]]) ?? []), H = new Map(Object.entries(w?.checkpoint.nextJobs ?? {})), U = new Map(Object.entries(w?.checkpoint.outputs ?? {})), W = new Set(w?.checkpoint.completedNodes ?? []), G, K, q = w != null, J, Y, X = (e, t) => {
359
+ G ?? (N.get(e.nodeId).push(e.handle, t), Y(e.nodeId));
360
+ }, Z = (t, n, i, a) => e.gen(function* () {
361
+ yield* r.emit({
362
+ handle: i,
199
363
  jobId: n,
200
364
  nodeId: t,
201
- runId: m,
365
+ runId: c,
202
366
  type: "node.output",
203
- value: i
367
+ value: a
204
368
  });
205
- for (let e of f(k, t, r)) V(e, i);
206
- for (let e of f(A, t, r)) I.set(e, i), S != null && (yield* S(e, i));
207
- }), U = (t, n, i, o) => {
208
- let s = e.gen(function* () {
209
- let s = u(a.prepared, n), c = l(a.prepared, n), d = Object.fromEntries(Object.entries(o).filter(([e]) => {
369
+ for (let e of _(I, t, i)) X(e, a);
370
+ for (let e of _(L, t, i)) U.set(e, a), S != null && (yield* S(e, a));
371
+ }), ee = (t, n, i, o) => {
372
+ let l = e.gen(function* () {
373
+ let l = h(r.prepared, n), u = m(r.prepared, n), d = Object.fromEntries(Object.entries(o).filter(([e]) => {
374
+ if (n.kind == "wait") return e == n.input.handle;
210
375
  let t = n.inputs[e];
211
376
  return t?.kind != "sources" || t.sources.every((e) => e.kind != "binding");
212
377
  }));
213
- yield* a.emit({
378
+ yield* r.emit({
214
379
  inputs: d,
215
380
  jobId: i,
216
381
  nodeId: t,
217
- nodeKind: s,
218
- ...c == null ? {} : { nodeTitle: c },
219
- runId: m,
382
+ nodeKind: l,
383
+ ...u == null ? {} : { nodeTitle: u },
384
+ runId: c,
220
385
  type: "node.started"
221
386
  });
222
387
  let f;
@@ -224,159 +389,265 @@ function _(a, o, m, v, b, x = {}, S, C) {
224
389
  case "condition": {
225
390
  let e = n.cases.find((e) => {
226
391
  if (e.expressions.length == 0) return !1;
227
- let t = e.expressions.map((e) => h(n, e, o));
392
+ let t = e.expressions.map((e) => D(n, e, o));
228
393
  return e.relation == "all" ? t.every(Boolean) : t.some(Boolean);
229
394
  })?.output ?? n.defaultOutput;
230
- f = e == null ? {} : { [e]: o[n.input.handle] ?? null }, e != null && (yield* H(t, i, e, f[e]));
395
+ f = e == null ? {} : { [e]: o[n.input.handle] ?? null }, e != null && (yield* Z(t, i, e, f[e]));
231
396
  break;
232
397
  }
233
398
  case "value":
234
399
  f = Object.fromEntries(n.values.map((e) => [e.handle, e.value ?? null]));
235
- for (let [e, n] of Object.entries(f)) yield* H(t, i, e, n);
400
+ for (let [e, n] of Object.entries(f)) yield* Z(t, i, e, n);
236
401
  break;
237
402
  case "subflow": {
238
- let e = a.prepared.subflows[n.subflowId];
239
- f = yield* _(a, {
403
+ let e = r.prepared.subflows[n.subflowId];
404
+ f = yield* k(r, {
240
405
  flowId: n.subflowId,
241
- graph: y(e.graph),
242
- inputs: r(e.inputs),
406
+ graph: j(e.graph),
407
+ inputs: a(e.inputs),
243
408
  kind: "subflow",
244
- outputs: r(e.outputs)
245
- }, a.createId(), o, {
409
+ outputs: a(e.outputs)
410
+ }, r.createId(), o, {
246
411
  jobId: i,
247
- runId: m
248
- }, {}, (e, n) => H(t, i, e, n));
412
+ runId: c
413
+ }, {}, (e, n) => Z(t, i, e, n));
249
414
  break;
250
415
  }
251
416
  case "task": {
252
- let r = yield* a.invokeTask({
253
- input: o,
254
- invocationId: a.createId(),
417
+ let a = new Set((n.additionalInputs ?? []).map((e) => e.handle)), l = /* @__PURE__ */ new Map(), u = (n) => e.gen(function* () {
418
+ let r = yield* e.try({
419
+ try: () => O(n, t),
420
+ catch: (e) => e instanceof Error ? e : Error(String(e))
421
+ });
422
+ for (let [e, n] of Object.entries(r)) yield* Z(t, i, e, n), l.set(e, n);
423
+ });
424
+ yield* u(yield* r.invokeTask({
425
+ additionalInputs: Object.fromEntries(Object.entries(o).filter(([e]) => a.has(e))),
426
+ blockId: n.task == null ? n.taskId : n.task.moduleId,
427
+ flowId: s.flowId,
428
+ input: Object.fromEntries(Object.entries(o).filter(([e]) => !a.has(e))),
429
+ invocationId: r.createId(),
255
430
  jobId: i,
256
431
  nodeId: t,
257
- runId: m,
432
+ runId: c,
258
433
  ...n.task == null ? { taskId: n.taskId } : {
259
434
  capabilities: n.task.capabilities ?? [],
260
435
  moduleId: n.task.moduleId
261
436
  }
262
- });
263
- f = yield* e.try({
264
- try: () => g(r, t),
265
- catch: (e) => e instanceof Error ? e : Error(String(e))
266
- });
267
- for (let [e, n] of Object.entries(f)) yield* H(t, i, e, n);
437
+ }, u)), f = Object.fromEntries(l);
268
438
  break;
269
439
  }
440
+ case "wait": return yield* e.fail(/* @__PURE__ */ Error("Wait jobs are handled by the Scheduler suspension boundary."));
270
441
  }
271
- return yield* a.emit({
442
+ return yield* r.emit({
272
443
  jobId: i,
273
444
  nodeId: t,
274
- runId: m,
445
+ runId: c,
275
446
  type: "node.completed"
276
447
  }), f;
277
448
  });
278
- return n.timeoutMs == null ? s : s.pipe(e.timeoutOrElse({
449
+ return n.timeoutMs == null ? l : l.pipe(e.timeoutOrElse({
279
450
  duration: n.timeoutMs,
280
451
  orElse: () => e.fail(/* @__PURE__ */ Error(`Node "${t}" timed out.`))
281
452
  }));
282
- }, W = (t) => {
283
- let n = o.graph.nodes[t], r = E.get(t).take(), s = a.createId(), c = F.get(t) ?? 0;
284
- F.set(t, c + 1), j.set(t, (j.get(t) ?? 0) + 1), N(U(t, n, s, r).pipe(e.tap((n) => e.gen(function* () {
285
- let e = P.get(t) ?? [];
453
+ }, te = (t) => {
454
+ let n = s.graph.nodes[t], a = N.get(t).take(), l = r.createId(), d = H.get(t) ?? 0;
455
+ if (H.set(t, d + 1), n.kind == "wait") {
456
+ q = !0, J = {
457
+ actions: n.actions,
458
+ jobId: l,
459
+ nodeId: t,
460
+ ...n.notification == null ? {} : { notification: {
461
+ input: Object.fromEntries(Object.entries(a).flatMap(([e, t]) => e.startsWith(u) ? [[e.slice(13), t]] : [])),
462
+ messageHandle: n.notification.messageHandle,
463
+ taskId: n.notification.taskId
464
+ } },
465
+ order: d,
466
+ value: a[n.input.handle] ?? null,
467
+ waitId: i()
468
+ };
469
+ let e = n.inputs[n.input.handle], o = e?.kind == "sources" && e.sources.some((e) => e.kind == "binding") ? {} : { [n.input.handle]: a[n.input.handle] ?? null };
470
+ B(r.emit({
471
+ inputs: o,
472
+ jobId: l,
473
+ nodeId: t,
474
+ nodeKind: "wait",
475
+ ...n.name == null ? {} : { nodeTitle: n.name },
476
+ runId: c,
477
+ type: "node.started"
478
+ }));
479
+ return;
480
+ }
481
+ R.set(t, (R.get(t) ?? 0) + 1), B(ee(t, n, l, a).pipe(e.tap((n) => e.gen(function* () {
482
+ let e = V.get(t) ?? [];
286
483
  e.push({
287
- jobId: s,
288
- order: c,
484
+ jobId: l,
485
+ order: d,
289
486
  outputs: n
290
- }), P.set(t, e), L.has(t) || (L.add(t), yield* a.emit({
487
+ }), V.set(t, e), W.has(t) || (W.add(t), yield* r.emit({
291
488
  ...b == null ? {} : {
292
489
  parentJobId: b.jobId,
293
490
  parentRunId: b.runId
294
491
  },
295
- progress: L.size / T * 100,
296
- runId: m,
492
+ progress: W.size / M * 100,
493
+ runId: c,
297
494
  type: "run.progress"
298
495
  }));
299
496
  })), e.tapError((n) => e.gen(function* () {
300
- R ?? (z ??= n);
301
- let r = i(n, a.projectFailure);
302
- yield* a.emit({
303
- ...r,
304
- jobId: s,
497
+ G ?? (K ??= n);
498
+ let i = o(n, r.projectFailure);
499
+ yield* r.emit({
500
+ ...i,
501
+ jobId: l,
305
502
  nodeId: t,
306
- runId: m,
503
+ runId: c,
307
504
  type: "node.failed"
308
505
  }).pipe(e.ignore);
309
506
  })), e.tapCause((t) => e.sync(() => {
310
- R ??= t;
507
+ G ??= t;
311
508
  })), e.ensuring(e.sync(() => {
312
- j.set(t, (j.get(t) ?? 1) - 1), B(t);
509
+ R.set(t, (R.get(t) ?? 1) - 1), Y(t);
313
510
  }))));
314
511
  };
315
- B = (e) => {
316
- if (R != null) return;
317
- let t = o.graph.nodes[e], n = E.get(e);
318
- for (; n.ready && (j.get(e) ?? 0) < t.concurrency;) W(e);
319
- };
320
- for (let [e, t] of Object.entries(x)) {
321
- let n = E.get(e);
322
- if (n != null) for (let [e, r] of Object.entries(t)) n.launch(e, r);
323
- }
324
- for (let [t, n] of O) {
325
- if (!Object.hasOwn(a.bindingValues, t)) return yield* e.fail(/* @__PURE__ */ Error(`Variable binding "${t}" is unresolved.`));
326
- for (let e of n) V(e, a.bindingValues[t]);
327
- }
328
- for (let [e, t] of Object.entries(o.inputs)) {
329
- let n = Object.hasOwn(v, e) ? v[e] : t.value;
330
- if (n !== void 0) {
331
- for (let t of Object.entries(o.outputs)) t[1].sources.some((t) => t.kind == "flow" && t.input == e) && (I.set(t[0], n), S != null && (yield* S(t[0], n)));
332
- for (let t of D.get(e) ?? []) V(t, n);
512
+ if (Y = (e) => {
513
+ if (G != null || q) return;
514
+ let t = s.graph.nodes[e], n = N.get(e);
515
+ for (; n.ready && (R.get(e) ?? 0) < t.concurrency;) if (te(e), q) return;
516
+ }, w == null) {
517
+ for (let [e, t] of Object.entries(x)) {
518
+ let n = N.get(e);
519
+ if (n != null) for (let [e, r] of Object.entries(t)) n.launch(e, r);
520
+ }
521
+ for (let [t, n] of F) {
522
+ if (!Object.hasOwn(r.bindingValues, t)) return yield* e.fail(/* @__PURE__ */ Error(`Variable binding "${t}" is unresolved.`));
523
+ for (let e of n) X(e, r.bindingValues[t]);
333
524
  }
525
+ for (let [e, t] of Object.entries(s.inputs)) {
526
+ let n = Object.hasOwn(d, e) ? d[e] : t.value;
527
+ if (n !== void 0) {
528
+ for (let t of Object.entries(s.outputs)) t[1].sources.some((t) => t.kind == "flow" && t.input == e) && (U.set(t[0], n), S != null && (yield* S(t[0], n)));
529
+ for (let t of P.get(e) ?? []) X(t, n);
530
+ }
531
+ }
532
+ if (C != null) for (let e of _(I, C.nodeId, "payload")) X(e, C.payload);
533
+ } else {
534
+ let t = w.checkpoint.wait, n = s.graph.nodes[t.nodeId];
535
+ if (n?.kind != "wait" || !n.actions.some((e) => e == w.action)) return yield* e.fail(/* @__PURE__ */ Error("Flow Run checkpoint resolution does not match the prepared Wait node."));
536
+ if (Object.keys(w.checkpoint.nextJobs).some((e) => s.graph.nodes[e] == null)) return yield* e.fail(/* @__PURE__ */ Error("Flow Run checkpoint job state does not match the prepared graph."));
537
+ let i = { [w.action]: t.value };
538
+ yield* Z(t.nodeId, t.jobId, w.action, t.value);
539
+ let a = V.get(t.nodeId) ?? [];
540
+ a.push({
541
+ jobId: t.jobId,
542
+ order: t.order,
543
+ outputs: i
544
+ }), V.set(t.nodeId, a), W.has(t.nodeId) || (W.add(t.nodeId), yield* r.emit({
545
+ progress: W.size / M * 100,
546
+ runId: c,
547
+ type: "run.progress"
548
+ })), yield* r.emit({
549
+ jobId: t.jobId,
550
+ nodeId: t.nodeId,
551
+ runId: c,
552
+ type: "node.completed"
553
+ }), q = !1;
334
554
  }
335
- if (C != null) for (let e of f(k, C.nodeId, "payload")) V(e, C.payload);
336
- for (let e of w) B(e);
337
- let G = yield* e.raceFirst(n.awaitEmpty(M), n.join(M)).pipe(e.exit);
338
- if (z != null) return yield* n.clear(M), yield* a.emit({
339
- message: z.message,
340
- runId: m,
555
+ for (let e of E) Y(e);
556
+ let Q = yield* e.raceFirst(n.awaitEmpty(z), n.join(z)).pipe(e.exit);
557
+ if (K != null) return yield* n.clear(z), yield* r.emit({
558
+ message: K.message,
559
+ runId: c,
341
560
  type: "run.failed"
342
- }).pipe(e.ignore), yield* e.fail(z);
343
- if (R != null) return yield* n.clear(M), yield* e.failCause(R);
344
- if (t.isFailure(G)) return yield* e.failCause(G.cause);
345
- if (o.kind == "subflow") {
346
- let e = Object.fromEntries(I);
347
- return yield* a.emit({
561
+ }).pipe(e.ignore), yield* e.fail(K);
562
+ if (G != null) return yield* n.clear(z), yield* e.failCause(G);
563
+ if (t.isFailure(Q)) return yield* e.failCause(Q.cause);
564
+ if (J != null) {
565
+ if (s.kind != "flow") return yield* e.fail(/* @__PURE__ */ Error("Subflow Wait is not supported."));
566
+ let t = {
567
+ bindingValues: r.bindingValues,
568
+ buffers: Object.fromEntries([...N].map(([e, t]) => [e, t.snapshot()])),
569
+ completedNodes: [...W].toSorted(),
570
+ nextJobs: Object.fromEntries(H),
571
+ outputs: Object.fromEntries(U),
572
+ results: A.map((e) => ({
573
+ jobs: (V.get(e) ?? []).toSorted((e, t) => e.order - t.order),
574
+ nodeId: e
575
+ })),
576
+ version: 1,
577
+ wait: {
578
+ jobId: J.jobId,
579
+ nodeId: J.nodeId,
580
+ order: J.order,
581
+ value: J.value,
582
+ waitId: J.waitId
583
+ }
584
+ }, n = JSON.stringify(t);
585
+ if (new TextEncoder().encode(n).byteLength > 16777216) {
586
+ let t = "Flow Run checkpoint exceeds 16 MiB.";
587
+ return yield* r.emit({
588
+ code: "run.checkpoint-too-large",
589
+ jobId: J.jobId,
590
+ message: t,
591
+ nodeId: J.nodeId,
592
+ runId: c,
593
+ type: "node.failed"
594
+ }), yield* r.emit({
595
+ message: t,
596
+ runId: c,
597
+ type: "run.failed"
598
+ }), yield* e.fail(/* @__PURE__ */ Error(`run.checkpoint-too-large: ${t}`));
599
+ }
600
+ return {
601
+ checkpoint: T(JSON.parse(n)),
602
+ kind: "waiting",
603
+ ...J.notification == null ? {} : { notification: J.notification },
604
+ wait: {
605
+ actions: J.actions,
606
+ jobId: J.jobId,
607
+ nodeId: J.nodeId,
608
+ order: J.order,
609
+ waitId: J.waitId
610
+ }
611
+ };
612
+ }
613
+ if (s.kind == "subflow") {
614
+ let e = Object.fromEntries(U);
615
+ return yield* r.emit({
348
616
  result: {
349
617
  kind: "function-outputs",
350
618
  outputs: e,
351
619
  target: "subflow"
352
620
  },
353
- runId: m,
621
+ runId: c,
354
622
  type: "run.completed"
355
623
  }), e;
356
624
  }
357
- let K = new Set(Object.values(o.graph.nodes).flatMap((e) => Object.values(e.inputs).flatMap((e) => e.kind == "sources" ? e.sources.filter((e) => e.kind == "node").map((e) => e.nodeId) : []))), q = {
625
+ let $ = {
358
626
  kind: "node-results",
359
- nodes: w.filter((e) => !K.has(e)).map((e) => ({
360
- jobs: (P.get(e) ?? []).toSorted((e, t) => e.order - t.order).map(({ jobId: e, outputs: t }) => ({
627
+ nodes: A.map((e) => ({
628
+ jobs: (V.get(e) ?? []).toSorted((e, t) => e.order - t.order).map(({ jobId: e, outputs: t }) => ({
361
629
  jobId: e,
362
630
  outputs: t
363
631
  })),
364
632
  nodeId: e
365
633
  }))
366
634
  };
367
- return yield* a.emit({
368
- result: q,
369
- runId: m,
635
+ return yield* r.emit({
636
+ result: $,
637
+ runId: c,
370
638
  type: "run.completed"
371
- }), q;
639
+ }), $;
372
640
  }));
373
641
  }
374
- function v(t, n) {
642
+ function A(t, n) {
375
643
  let r = n.emit ?? (() => e.void);
376
644
  return e.gen(function* () {
377
- let i = n.trigger == null ? void 0 : t.graph.nodes[n.trigger.nodeId];
378
- return n.trigger != null && (i == null || "inputs" in i) ? yield* e.fail(/* @__PURE__ */ Error(`Node "${n.trigger.nodeId}" is not a TriggerNode in Flow "${n.flowId}".`)) : yield* _({
379
- bindingValues: n.bindingValues ?? {},
645
+ if (n.resume != null && (n.inputs != null || n.trigger != null)) return yield* e.fail(/* @__PURE__ */ Error("A resumed Flow Run cannot accept launch inputs or a Trigger seed."));
646
+ let i = n.resume == null ? void 0 : T(n.resume.checkpoint);
647
+ if (i != null && new TextEncoder().encode(JSON.stringify(i)).byteLength > 16777216) return yield* e.fail(/* @__PURE__ */ Error("Flow Run checkpoint exceeds 16 MiB."));
648
+ let a = n.trigger == null ? void 0 : t.graph.nodes[n.trigger.nodeId];
649
+ return n.trigger != null && (a == null || "inputs" in a) ? yield* e.fail(/* @__PURE__ */ Error(`Node "${n.trigger.nodeId}" is not a TriggerNode in Flow "${n.flowId}".`)) : yield* k({
650
+ bindingValues: i?.bindingValues ?? n.bindingValues ?? {},
380
651
  createId: n.createId,
381
652
  emit: r,
382
653
  invokeTask: n.invokeTask,
@@ -384,15 +655,18 @@ function v(t, n) {
384
655
  projectFailure: n.projectFailure
385
656
  }, {
386
657
  flowId: n.flowId,
387
- graph: y(t.graph),
658
+ graph: j(t.graph),
388
659
  inputs: {},
389
660
  kind: "flow",
390
661
  outputs: {}
391
- }, n.runId, {}, void 0, n.inputs, void 0, n.trigger);
662
+ }, n.runId, {}, void 0, n.inputs, void 0, n.trigger, i == null ? void 0 : {
663
+ action: n.resume.action,
664
+ checkpoint: i
665
+ });
392
666
  });
393
667
  }
394
- function y(e) {
668
+ function j(e) {
395
669
  return { nodes: Object.fromEntries(Object.entries(e.nodes).filter((e) => "inputs" in e[1])) };
396
670
  }
397
671
  //#endregion
398
- export { v as runFlow };
672
+ export { T as decodeFlowRunCheckpoint, A as runFlow };