@oomol-lab/open-flow 0.1.0-beta.2 → 0.1.0-beta.4

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