@oomol-lab/open-flow 0.1.0-alpha.0 → 0.1.0-alpha.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 (72) hide show
  1. package/dist/browser/addNodeOptions-BwrMvPQC.js +5230 -0
  2. package/dist/browser/assets/typeScriptWorker-CaA4llbX.js +59850 -0
  3. package/dist/browser/carbon-DMCVsjHo.js +53 -0
  4. package/dist/browser/{project-change.js → change-Cu6pQIit.js} +15 -45
  5. package/dist/browser/createLucideIcon-COMgwa_u.js +5317 -0
  6. package/dist/browser/createResourceDialog-YgMLylQz.js +467 -0
  7. package/dist/browser/{dist-o4dBuwiG.js → dist-3Mj8q8Pr.js} +28 -28
  8. package/dist/browser/{dist-CIq6ue3I.js → dist-BKuSVKCC.js} +1115 -1103
  9. package/dist/browser/{dist-DL0SDskM.js → dist-BMqL-qR5.js} +473 -906
  10. package/dist/browser/{dist-CLZJNoWB.js → dist-BN4ZCyOB.js} +10 -10
  11. package/dist/browser/{dist-zyY--HOV.js → dist-BpopSHwP.js} +3 -3
  12. package/dist/browser/dist-C46JByB-.js +252 -0
  13. package/dist/browser/{dist-BbyiRq3c.js → dist-CJpzJrLM.js} +294 -284
  14. package/dist/browser/{dist-Djd02JSy.js → dist-CPuF50D9.js} +198 -198
  15. package/dist/browser/{dist-CvcmLAMW.js → dist-CUSrALSX.js} +115 -115
  16. package/dist/browser/dist-CeSZ2xSM.js +444 -0
  17. package/dist/browser/{dist-7oZK9QXZ.js → dist-DMi8_lU3.js} +5 -5
  18. package/dist/browser/{dist-B9OV3YTx.js → dist-DUzA0Ukh.js} +22 -22
  19. package/dist/browser/{dist-aWSZx4q1.js → dist-DWADUsVB.js} +75 -75
  20. package/dist/browser/{dist-BLk5M0uK.js → dist-Mecbzdl2.js} +3 -3
  21. package/dist/browser/{esm-DXw7EADW.js → esm-CvAs_mAS.js} +14 -24
  22. package/dist/browser/field-BrEG-7ap.js +312 -0
  23. package/dist/browser/flow-authoring-edge.d.ts +3 -0
  24. package/dist/browser/flow-authoring-module.d.ts +4 -0
  25. package/dist/browser/flow-authoring-node.d.ts +84 -0
  26. package/dist/browser/flow-authoring.d.ts +4 -0
  27. package/dist/browser/flow-authoring.js +522 -0
  28. package/dist/browser/{project-change.d.ts → flow-change.d.ts} +27 -36
  29. package/dist/browser/flow-change.js +231 -0
  30. package/dist/browser/{project-notifications.d.ts → flow-notifications.d.ts} +6 -3
  31. package/dist/browser/flowRunInputEditorStore-DXOyyY7o.js +8219 -0
  32. package/dist/browser/flowWorkspace-X_T_DcQf.js +46003 -0
  33. package/dist/browser/{lib-S4ccuMeT.js → lib-GrGxYjsJ.js} +3 -5
  34. package/dist/browser/licenses.md +620 -12
  35. package/dist/browser/{markdownContent-ZZFfSRqO.js → markdownContent-BI-2PmDX.js} +4071 -4035
  36. package/dist/browser/typeScriptSession-Dagu_tRs.js +2549 -0
  37. package/dist/browser/workbench-contract.d.ts +4 -5
  38. package/dist/browser/workbench.css +1 -1
  39. package/dist/browser/workbench.d.ts +2 -1
  40. package/dist/browser/workbench.js +3920 -2138
  41. package/dist/common/connector-action.d.ts +6 -0
  42. package/dist/common/connector-action.js +38 -30
  43. package/dist/common/control-api-conformance.js +223 -359
  44. package/dist/common/control-api-errors.d.ts +20 -24
  45. package/dist/common/control-api.d.ts +44 -73
  46. package/dist/common/control-api.js +150 -203
  47. package/dist/common/cron-trigger.d.ts +1 -1
  48. package/dist/common/cron-trigger.js +1 -1
  49. package/dist/common/flow-encoding.d.ts +11 -0
  50. package/dist/common/{project-encoding.js → flow-encoding.js} +14 -13
  51. package/dist/common/{project-notifications.d.ts → flow-notifications.d.ts} +6 -3
  52. package/dist/common/{project-semantics.d.ts → flow-semantics.d.ts} +9 -12
  53. package/dist/common/{project-semantics.js → flow-semantics.js} +594 -597
  54. package/dist/common/integration-trigger.d.ts +2 -1
  55. package/dist/common/integration-trigger.js +1 -1
  56. package/dist/common/poll-trigger.d.ts +1 -1
  57. package/dist/common/provider-triggers.js +1057 -948
  58. package/dist/common/run-lifecycle.js +1 -1
  59. package/dist/common/runtime-contract.d.ts +1 -1
  60. package/dist/common/runtime-contract.js +1 -1
  61. package/dist/common/scheduler.d.ts +7 -7
  62. package/dist/common/scheduler.js +237 -232
  63. package/dist/common/webhook-trigger.d.ts +1 -1
  64. package/dist/common/webhook-trigger.js +35 -1
  65. package/package.json +20 -10
  66. package/dist/browser/addNodeOptions-DqoIueCR.js +0 -33746
  67. package/dist/browser/carbon-nMY84Amv.js +0 -53
  68. package/dist/browser/composite-7VwgfnXx.js +0 -6088
  69. package/dist/browser/createResourceDialog-ByuJWdSL.js +0 -439
  70. package/dist/browser/dist-n-z5HtaO.js +0 -4
  71. package/dist/browser/flowWorkspace-DwVMpcar.js +0 -22092
  72. package/dist/common/project-encoding.d.ts +0 -11
@@ -1,4 +1,4 @@
1
- //#region ../../node_modules/dequal/lite/index.mjs
1
+ //#region ../../node_modules/.bun/dequal@2.0.3/node_modules/dequal/lite/index.mjs
2
2
  var e = Object.prototype.hasOwnProperty;
3
3
  function t(n, r) {
4
4
  var i, a;
@@ -1,4 +1,4 @@
1
- import type { CodeModule, JsonValue } from '../browser/project-change.js';
1
+ import type { CodeModule, JsonValue } from '../browser/flow-change.js';
2
2
  export { currentEngineContract, findEngineContract, type EngineContract } from './engine-contract.js';
3
3
  export type RuntimeModule = Pick<CodeModule, 'imports' | 'source'>;
4
4
  export interface RuntimeProgram {
@@ -1,4 +1,4 @@
1
- //#region ../../node_modules/dequal/lite/index.mjs
1
+ //#region ../../node_modules/.bun/dequal@2.0.3/node_modules/dequal/lite/index.mjs
2
2
  var e = Object.prototype.hasOwnProperty;
3
3
  function t(n, r) {
4
4
  var i, a;
@@ -1,5 +1,6 @@
1
- import type { ConnectorCapability, JsonValue } from '../browser/project-change.js';
2
- import type { PreparedFlow } from './project-semantics.js';
1
+ import type { ConnectorCapability, JsonValue } from '../browser/flow-change.js';
2
+ import type { PreparedFlow } from './flow-semantics.js';
3
+ import * as Effect from 'effect/Effect';
3
4
  export type SchedulerEvent = {
4
5
  readonly flowId: string;
5
6
  readonly parentJobId?: string;
@@ -69,7 +70,6 @@ interface TaskInvocationBase {
69
70
  readonly jobId: string;
70
71
  readonly nodeId: string;
71
72
  readonly runId: string;
72
- readonly signal: AbortSignal;
73
73
  }
74
74
  export type TaskInvocation = TaskInvocationBase & ({
75
75
  readonly capabilities: readonly ConnectorCapability[];
@@ -87,13 +87,13 @@ export interface SchedulerFailure {
87
87
  }
88
88
  export interface FlowRunOptions {
89
89
  readonly createId: () => string;
90
- readonly emit?: (event: SchedulerEvent) => void | Promise<void>;
90
+ readonly emit?: (event: SchedulerEvent) => Effect.Effect<void, Error>;
91
+ readonly flowId: string;
91
92
  readonly inputs?: Readonly<Record<string, Readonly<Record<string, JsonValue>>>>;
92
- readonly invokeTask: (invocation: TaskInvocation) => Promise<unknown>;
93
+ readonly invokeTask: (invocation: TaskInvocation) => Effect.Effect<unknown, Error>;
93
94
  readonly projectFailure?: (error: unknown) => SchedulerFailure;
94
95
  readonly runId: string;
95
- readonly signal?: AbortSignal;
96
96
  readonly trigger?: TriggerSeed;
97
97
  }
98
- export declare function runFlow(prepared: PreparedFlow, options: FlowRunOptions): Promise<FlowRunResult>;
98
+ export declare function runFlow(prepared: PreparedFlow, options: FlowRunOptions): Effect.Effect<FlowRunResult, Error>;
99
99
  export {};
@@ -1,11 +1,19 @@
1
+ import * as e from "effect/Effect";
2
+ import * as t from "effect/Exit";
3
+ import * as n from "effect/FiberSet";
4
+ //#region src/flow/common/change.ts
5
+ function r(e) {
6
+ return Object.fromEntries(e.map((e) => [e.handle, e]));
7
+ }
8
+ //#endregion
1
9
  //#region src/execution/common/scheduler.ts
2
- function e(e, t) {
10
+ function i(e, t) {
3
11
  return t?.(e) ?? {
4
12
  code: "node.failed",
5
13
  message: e instanceof Error ? e.message : String(e)
6
14
  };
7
15
  }
8
- var t = class {
16
+ var a = class {
9
17
  #e = [];
10
18
  #t = 0;
11
19
  get length() {
@@ -18,9 +26,9 @@ var t = class {
18
26
  let e = this.#e[this.#t];
19
27
  return this.#t += 1, this.#t >= 64 && this.#t * 2 >= this.#e.length && (this.#e.splice(0, this.#t), this.#t = 0), e;
20
28
  }
21
- }, n = class {
29
+ }, o = class {
22
30
  #e;
23
- #t = new t();
31
+ #t = new a();
24
32
  #n;
25
33
  #r;
26
34
  constructor(e, t, n) {
@@ -42,13 +50,13 @@ var t = class {
42
50
  take() {
43
51
  return this.#t.length > 0 ? this.#t.shift() : this.#r;
44
52
  }
45
- }, r = class {
53
+ }, s = class {
46
54
  #e;
47
55
  #t;
48
56
  #n;
49
57
  #r = !1;
50
- constructor(e, t, r) {
51
- this.#t = e, this.#n = new Map(Object.entries(r).map(([e, r]) => [e, new n(t, e, r)])), this.#e = [...this.#n.values()].some((e) => e.dynamic);
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);
52
60
  }
53
61
  get ready() {
54
62
  return (!this.#r || this.#e) && [...this.#n.values()].every((e) => e.ready);
@@ -67,15 +75,15 @@ var t = class {
67
75
  return this.#e || (this.#r = !0), Object.fromEntries([...this.#n].map(([e, t]) => [e, t.take()]));
68
76
  }
69
77
  };
70
- function i(e, t) {
78
+ function c(e, t) {
71
79
  switch (t.kind) {
72
80
  case "condition": return { [t.input.handle]: t.input };
73
81
  case "value": return {};
74
- case "subflow": return e.subflows[t.subflowId].inputs;
75
- case "task": return t.task == null ? e.tasks[t.taskId].inputs : t.task.inputs;
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);
76
84
  }
77
85
  }
78
- function a(e, t) {
86
+ function l(e, t) {
79
87
  if (t.name != null) return t.name;
80
88
  switch (t.kind) {
81
89
  case "condition": return;
@@ -84,17 +92,17 @@ function a(e, t) {
84
92
  case "task": return t.task == null ? e.tasks[t.taskId].name : t.task.name;
85
93
  }
86
94
  }
87
- function o(e, t) {
95
+ function u(e, t) {
88
96
  return t.kind == "task" ? t.task == null ? e.tasks[t.taskId].executor.kind : "javascript" : t.kind;
89
97
  }
90
- function s(e, t, n, r) {
98
+ function d(e, t, n, r) {
91
99
  let i = e.get(t) ?? /* @__PURE__ */ new Map(), a = i.get(n) ?? [];
92
100
  a.push(r), i.set(n, a), e.set(t, i);
93
101
  }
94
- function c(e, t, n) {
102
+ function f(e, t, n) {
95
103
  return e.get(t)?.get(n) ?? [];
96
104
  }
97
- function l(e) {
105
+ function p(e) {
98
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 = [];
99
107
  for (; t.size > 0;) {
100
108
  let e = [...t].filter(([, e]) => e.size == 0).map(([e]) => e).toSorted();
@@ -104,18 +112,18 @@ function l(e) {
104
112
  }
105
113
  return n;
106
114
  }
107
- function u(e, t) {
115
+ function m(e, t) {
108
116
  if (e === t) return !0;
109
117
  if (e == null || t == null || typeof e != "object" || typeof t != "object") return !1;
110
- if (Array.isArray(e) || Array.isArray(t)) return Array.isArray(e) && Array.isArray(t) && e.length == t.length && e.every((e, n) => u(e, t[n]));
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]));
111
119
  let n = Object.entries(e), r = Object.entries(t), i = t;
112
- return n.length == r.length && n.every(([e, t]) => Object.hasOwn(i, e) && u(t, i[e]));
120
+ return n.length == r.length && n.every(([e, t]) => Object.hasOwn(i, e) && m(t, i[e]));
113
121
  }
114
- function d(e, t, n) {
122
+ function h(e, t, n) {
115
123
  let r = Object.hasOwn(n, t.input) ? n[t.input] : null, i = t.value;
116
124
  switch (t.operator) {
117
- case "==": return i !== void 0 && u(r, i);
118
- case "!=": return i !== void 0 && !u(r, i);
125
+ case "==": return i !== void 0 && m(r, i);
126
+ case "!=": return i !== void 0 && !m(r, i);
119
127
  case ">": return typeof r == "number" && typeof i == "number" && r > i;
120
128
  case ">=": return typeof r == "number" && typeof i == "number" && r >= i;
121
129
  case "<": return typeof r == "number" && typeof i == "number" && r < i;
@@ -123,7 +131,7 @@ function d(e, t, n) {
123
131
  case "contains":
124
132
  case "notContains": {
125
133
  let e;
126
- return typeof r == "string" && typeof i == "string" ? e = r.includes(i) : Array.isArray(r) && i !== void 0 && (e = r.some((e) => u(e, i))), e == null ? !1 : t.operator == "contains" ? e : !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;
127
135
  }
128
136
  case "startsWith": return typeof r == "string" && typeof i == "string" && r.startsWith(i);
129
137
  case "endsWith": return typeof r == "string" && typeof i == "string" && r.endsWith(i);
@@ -136,7 +144,7 @@ function d(e, t, n) {
136
144
  case "hasValue":
137
145
  case "notHasValue": {
138
146
  if (r == null || Array.isArray(r) || typeof r != "object" || i === void 0) return !1;
139
- let e = Object.values(r).some((e) => u(e, i));
147
+ let e = Object.values(r).some((e) => m(e, i));
140
148
  return t.operator == "hasValue" ? e : !e;
141
149
  }
142
150
  case "isEmpty":
@@ -150,230 +158,227 @@ function d(e, t, n) {
150
158
  case "isFalse": return r === !1;
151
159
  }
152
160
  }
153
- function f(e, t) {
161
+ function g(e, t) {
154
162
  if (typeof e != "object" || !e || Array.isArray(e)) throw Error(`Node "${t}" must return an object.`);
155
163
  return e;
156
164
  }
157
- function p(e) {
158
- return e.reason instanceof Error ? e.reason : /* @__PURE__ */ Error("Run canceled.");
159
- }
160
- function m(e, t) {
161
- return t.aborted ? Promise.reject(p(t)) : new Promise((n, r) => {
162
- let i = () => {
163
- t.removeEventListener("abort", i), r(p(t));
164
- };
165
- t.addEventListener("abort", i, { once: !0 }), e.then((e) => {
166
- t.removeEventListener("abort", i), n(e);
167
- }, (e) => {
168
- t.removeEventListener("abort", i), r(e);
165
+ function _(a, o, m, v, b, x = {}, S, C) {
166
+ return e.scoped(e.gen(function* () {
167
+ yield* a.emit({
168
+ flowId: o.flowId,
169
+ ...b == null ? {} : {
170
+ parentJobId: b.jobId,
171
+ parentRunId: b.runId
172
+ },
173
+ runId: m,
174
+ type: "run.started"
169
175
  });
170
- });
171
- }
172
- async function h(t, n, u, p, g, v, y = {}, b, x) {
173
- g.throwIfAborted(), await t.emit({
174
- flowId: n.flowId,
175
- ...v == null ? {} : {
176
- parentJobId: v.jobId,
177
- parentRunId: v.runId
178
- },
179
- runId: u,
180
- type: "run.started"
181
- });
182
- let S = l(n.graph), C = S.length, w = new Map(Object.entries(n.graph.nodes).map(([e, n]) => [e, new r(e, n, i(t.prepared, n))])), T = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map();
183
- for (let [e, t] of Object.entries(n.graph.nodes)) for (let [n, r] of Object.entries(t.inputs)) if (r.kind == "sources") for (let t of r.sources) if (t.kind == "flow") {
184
- let r = T.get(t.input) ?? [];
185
- r.push({
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();
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 == "flow") {
178
+ let r = D.get(t.input) ?? [];
179
+ r.push({
180
+ handle: n,
181
+ nodeId: e
182
+ }), D.set(t.input, r);
183
+ } else t.kind == "node" && d(O, t.nodeId, t.output, {
186
184
  handle: n,
187
185
  nodeId: e
188
- }), T.set(t.input, r);
189
- } else t.kind == "node" && s(E, t.nodeId, t.output, {
190
- handle: n,
191
- nodeId: e
192
- });
193
- for (let [e, t] of Object.entries(n.outputs)) for (let n of t.sources) n.kind == "node" && s(D, n.nodeId, n.output, e);
194
- let O = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Set(), A = /* @__PURE__ */ new Map(), j = /* @__PURE__ */ new Map(), M = /* @__PURE__ */ new Map(), N = /* @__PURE__ */ new Set(), P = new AbortController(), F = AbortSignal.any([g, P.signal]), I, L = !1, R, z = (e, t) => {
195
- P.signal.aborted || (w.get(e.nodeId).push(e.handle, t), R(e.nodeId));
196
- }, B = async (e, n, r, i) => {
197
- await t.emit({
198
- handle: r,
199
- jobId: n,
200
- nodeId: e,
201
- runId: u,
202
- type: "node.output",
203
- value: i
204
186
  });
205
- for (let t of c(E, e, r)) z(t, i);
206
- for (let t of c(D, e, r)) M.set(t, i), await b?.(t, i);
207
- }, V = async (e, n, r, i) => {
208
- let s = o(t.prepared, n), c = a(t.prepared, n);
209
- await t.emit({
210
- inputs: i,
211
- jobId: r,
212
- nodeId: e,
213
- nodeKind: s,
214
- ...c == null ? {} : { nodeTitle: c },
215
- runId: u,
216
- type: "node.started"
217
- });
218
- let l = n.timeoutMs == null ? void 0 : new AbortController(), p = l == null ? void 0 : setTimeout(() => l.abort(/* @__PURE__ */ Error(`Node "${e}" timed out.`)), n.timeoutMs), g = l == null ? F : AbortSignal.any([F, l.signal]);
219
- try {
220
- let a;
221
- switch (n.kind) {
222
- case "condition": {
223
- let t = n.cases.find((e) => {
224
- if (e.expressions.length == 0) return !1;
225
- let t = e.expressions.map((e) => d(n, e, i));
226
- return e.relation == "all" ? t.every(Boolean) : t.some(Boolean);
227
- })?.output ?? n.defaultOutput;
228
- a = t == null ? {} : { [t]: i[n.input.handle] ?? null }, t != null && await B(e, r, t, a[t]);
229
- break;
230
- }
231
- case "value":
232
- a = Object.fromEntries(Object.entries(n.values).map(([e, t]) => [e, t.value ?? null]));
233
- for (let [t, n] of Object.entries(a)) await B(e, r, t, n);
234
- break;
235
- case "subflow": {
236
- let o = t.prepared.subflows[n.subflowId];
237
- a = await m(h(t, {
238
- flowId: n.subflowId,
239
- graph: _(o.graph),
240
- inputs: o.inputs,
241
- kind: "subflow",
242
- outputs: o.outputs
243
- }, t.createId(), i, g, {
244
- jobId: r,
245
- runId: u
246
- }, {}, (t, n) => B(e, r, t, n)), g);
247
- break;
187
+ for (let [e, t] of Object.entries(o.outputs)) for (let n of t.sources) n.kind == "node" && d(k, n.nodeId, n.output, e);
188
+ let A = /* @__PURE__ */ new Map(), j = yield* n.make(), M = yield* n.runtime(j)(), N = /* @__PURE__ */ new Map(), P = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new Set(), L, R, z, B = (e, t) => {
189
+ L ?? (E.get(e.nodeId).push(e.handle, t), z(e.nodeId));
190
+ }, V = (t, n, r, i) => e.gen(function* () {
191
+ yield* a.emit({
192
+ handle: r,
193
+ jobId: n,
194
+ nodeId: t,
195
+ runId: m,
196
+ type: "node.output",
197
+ value: i
198
+ });
199
+ for (let e of f(O, t, r)) B(e, i);
200
+ for (let e of f(k, t, r)) F.set(e, i), S != null && (yield* S(e, i));
201
+ }), H = (t, n, i, o) => {
202
+ let s = e.gen(function* () {
203
+ let s = u(a.prepared, n), c = l(a.prepared, n);
204
+ yield* a.emit({
205
+ inputs: o,
206
+ jobId: i,
207
+ nodeId: t,
208
+ nodeKind: s,
209
+ ...c == null ? {} : { nodeTitle: c },
210
+ runId: m,
211
+ type: "node.started"
212
+ });
213
+ let d;
214
+ switch (n.kind) {
215
+ case "condition": {
216
+ let e = n.cases.find((e) => {
217
+ if (e.expressions.length == 0) return !1;
218
+ let t = e.expressions.map((e) => h(n, e, o));
219
+ return e.relation == "all" ? t.every(Boolean) : t.some(Boolean);
220
+ })?.output ?? n.defaultOutput;
221
+ d = e == null ? {} : { [e]: o[n.input.handle] ?? null }, e != null && (yield* V(t, i, e, d[e]));
222
+ break;
223
+ }
224
+ case "value":
225
+ d = Object.fromEntries(n.values.map((e) => [e.handle, e.value ?? null]));
226
+ for (let [e, n] of Object.entries(d)) yield* V(t, i, e, n);
227
+ break;
228
+ case "subflow": {
229
+ let e = a.prepared.subflows[n.subflowId];
230
+ d = yield* _(a, {
231
+ flowId: n.subflowId,
232
+ graph: y(e.graph),
233
+ inputs: r(e.inputs),
234
+ kind: "subflow",
235
+ outputs: r(e.outputs)
236
+ }, a.createId(), o, {
237
+ jobId: i,
238
+ runId: m
239
+ }, {}, (e, n) => V(t, i, e, n));
240
+ break;
241
+ }
242
+ case "task": {
243
+ let r = yield* a.invokeTask({
244
+ input: o,
245
+ invocationId: a.createId(),
246
+ jobId: i,
247
+ nodeId: t,
248
+ runId: m,
249
+ ...n.task == null ? { taskId: n.taskId } : {
250
+ capabilities: n.task.capabilities ?? [],
251
+ moduleId: n.task.moduleId
252
+ }
253
+ });
254
+ d = yield* e.try({
255
+ try: () => g(r, t),
256
+ catch: (e) => e instanceof Error ? e : Error(String(e))
257
+ });
258
+ for (let [e, n] of Object.entries(d)) yield* V(t, i, e, n);
259
+ break;
260
+ }
248
261
  }
249
- case "task":
250
- a = f(await m(t.invokeTask({
251
- input: i,
252
- invocationId: t.createId(),
253
- jobId: r,
254
- nodeId: e,
255
- runId: u,
256
- signal: g,
257
- ...n.task == null ? { taskId: n.taskId } : {
258
- capabilities: n.task.capabilities ?? [],
259
- moduleId: n.task.moduleId
260
- }
261
- }), g), e);
262
- for (let [t, n] of Object.entries(a)) await B(e, r, t, n);
262
+ return yield* a.emit({
263
+ jobId: i,
264
+ nodeId: t,
265
+ runId: m,
266
+ type: "node.completed"
267
+ }), d;
268
+ });
269
+ return n.timeoutMs == null ? s : s.pipe(e.timeoutOrElse({
270
+ duration: n.timeoutMs,
271
+ orElse: () => e.fail(/* @__PURE__ */ Error(`Node "${t}" timed out.`))
272
+ }));
273
+ }, U = (t) => {
274
+ let n = o.graph.nodes[t], r = E.get(t).take(), s = a.createId(), c = P.get(t) ?? 0;
275
+ P.set(t, c + 1), A.set(t, (A.get(t) ?? 0) + 1), M(H(t, n, s, r).pipe(e.tap((n) => e.gen(function* () {
276
+ let e = N.get(t) ?? [];
277
+ e.push({
278
+ jobId: s,
279
+ order: c,
280
+ outputs: n
281
+ }), N.set(t, e), I.has(t) || (I.add(t), yield* a.emit({
282
+ ...b == null ? {} : {
283
+ parentJobId: b.jobId,
284
+ parentRunId: b.runId
285
+ },
286
+ progress: I.size / T * 100,
287
+ runId: m,
288
+ type: "run.progress"
289
+ }));
290
+ })), e.tapError((n) => e.gen(function* () {
291
+ L ?? (R ??= n);
292
+ let r = i(n, a.projectFailure);
293
+ yield* a.emit({
294
+ ...r,
295
+ jobId: s,
296
+ nodeId: t,
297
+ runId: m,
298
+ type: "node.failed"
299
+ }).pipe(e.ignore);
300
+ })), e.tapCause((t) => e.sync(() => {
301
+ L ??= t;
302
+ })), e.ensuring(e.sync(() => {
303
+ A.set(t, (A.get(t) ?? 1) - 1), z(t);
304
+ }))));
305
+ };
306
+ z = (e) => {
307
+ if (L != null) return;
308
+ let t = o.graph.nodes[e], n = E.get(e);
309
+ for (; n.ready && (A.get(e) ?? 0) < t.concurrency;) U(e);
310
+ };
311
+ for (let [e, t] of Object.entries(x)) {
312
+ let n = E.get(e);
313
+ if (n != null) for (let [e, r] of Object.entries(t)) n.launch(e, r);
314
+ }
315
+ for (let [e, t] of Object.entries(o.inputs)) {
316
+ let n = Object.hasOwn(v, e) ? v[e] : t.value;
317
+ if (n !== void 0) {
318
+ for (let t of Object.entries(o.outputs)) t[1].sources.some((t) => t.kind == "flow" && t.input == e) && (F.set(t[0], n), S != null && (yield* S(t[0], n)));
319
+ for (let t of D.get(e) ?? []) B(t, n);
263
320
  }
264
- return await t.emit({
265
- jobId: r,
266
- nodeId: e,
267
- runId: u,
268
- type: "node.completed"
269
- }), a;
270
- } finally {
271
- p != null && clearTimeout(p);
272
321
  }
273
- }, H = (r) => {
274
- let i = n.graph.nodes[r], a = w.get(r).take(), o = t.createId(), s = j.get(r) ?? 0;
275
- j.set(r, s + 1), O.set(r, (O.get(r) ?? 0) + 1);
276
- let c = Promise.resolve();
277
- c = V(r, i, o, a).then(async (e) => {
278
- let n = A.get(r) ?? [];
279
- n.push({
280
- jobId: o,
281
- order: s,
282
- outputs: e
283
- }), A.set(r, n), N.has(r) || (N.add(r), await t.emit({
284
- ...v == null ? {} : {
285
- parentJobId: v.jobId,
286
- parentRunId: v.runId
322
+ if (C != null) for (let e of f(O, C.nodeId, "payload")) B(e, C.payload);
323
+ for (let e of w) z(e);
324
+ let W = yield* e.raceFirst(n.awaitEmpty(j), n.join(j)).pipe(e.exit);
325
+ if (R != null) return yield* n.clear(j), yield* a.emit({
326
+ message: R.message,
327
+ runId: m,
328
+ type: "run.failed"
329
+ }).pipe(e.ignore), yield* e.fail(R);
330
+ if (L != null) return yield* n.clear(j), yield* e.failCause(L);
331
+ if (t.isFailure(W)) return yield* e.failCause(W.cause);
332
+ if (o.kind == "subflow") {
333
+ let e = Object.fromEntries(F);
334
+ return yield* a.emit({
335
+ result: {
336
+ kind: "function-outputs",
337
+ outputs: e,
338
+ target: "subflow"
287
339
  },
288
- progress: N.size / C * 100,
289
- runId: u,
290
- type: "run.progress"
291
- }));
292
- }).catch(async (n) => {
293
- L || (L = !0, I = n, P.abort(n));
294
- let i = e(n, t.projectFailure);
295
- await t.emit({
296
- ...i,
297
- jobId: o,
298
- nodeId: r,
299
- runId: u,
300
- type: "node.failed"
301
- }).catch(() => void 0);
302
- }).finally(() => {
303
- k.delete(c), O.set(r, (O.get(r) ?? 1) - 1), R(r);
304
- }), k.add(c);
305
- };
306
- R = (e) => {
307
- if (P.signal.aborted) return;
308
- let t = n.graph.nodes[e], r = w.get(e);
309
- for (; r.ready && (O.get(e) ?? 0) < t.concurrency;) H(e);
310
- };
311
- for (let [e, t] of Object.entries(y)) {
312
- let n = w.get(e);
313
- if (n != null) for (let [e, r] of Object.entries(t)) n.launch(e, r);
314
- }
315
- for (let [e, t] of Object.entries(n.inputs)) {
316
- let r = Object.hasOwn(p, e) ? p[e] : t.value;
317
- if (r !== void 0) {
318
- for (let t of Object.entries(n.outputs)) t[1].sources.some((t) => t.kind == "flow" && t.input == e) && (M.set(t[0], r), await b?.(t[0], r));
319
- for (let t of T.get(e) ?? []) z(t, r);
340
+ runId: m,
341
+ type: "run.completed"
342
+ }), e;
320
343
  }
321
- }
322
- if (x != null) for (let e of c(E, x.nodeId, "payload")) z(e, x.payload);
323
- for (let e of S) R(e);
324
- for (; k.size > 0;) await Promise.race(k);
325
- if (L) throw await t.emit({
326
- message: I instanceof Error ? I.message : String(I),
327
- runId: u,
328
- type: "run.failed"
329
- }).catch(() => void 0), I;
330
- if (F.throwIfAborted(), n.kind == "subflow") {
331
- let e = Object.fromEntries(M);
332
- return await t.emit({
333
- result: {
334
- kind: "function-outputs",
335
- outputs: e,
336
- target: "subflow"
337
- },
338
- runId: u,
344
+ let G = 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) : []))), K = {
345
+ kind: "node-results",
346
+ nodes: w.filter((e) => !G.has(e)).map((e) => ({
347
+ jobs: (N.get(e) ?? []).toSorted((e, t) => e.order - t.order).map(({ jobId: e, outputs: t }) => ({
348
+ jobId: e,
349
+ outputs: t
350
+ })),
351
+ nodeId: e
352
+ }))
353
+ };
354
+ return yield* a.emit({
355
+ result: K,
356
+ runId: m,
339
357
  type: "run.completed"
340
- }), e;
341
- }
342
- let U = new Set(Object.values(n.graph.nodes).flatMap((e) => Object.values(e.inputs).flatMap((e) => e.kind == "sources" ? e.sources.filter((e) => e.kind == "node").map((e) => e.nodeId) : []))), W = {
343
- kind: "node-results",
344
- nodes: S.filter((e) => !U.has(e)).map((e) => ({
345
- jobs: (A.get(e) ?? []).toSorted((e, t) => e.order - t.order).map(({ jobId: e, outputs: t }) => ({
346
- jobId: e,
347
- outputs: t
348
- })),
349
- nodeId: e
350
- }))
351
- };
352
- return await t.emit({
353
- result: W,
354
- runId: u,
355
- type: "run.completed"
356
- }), W;
358
+ }), K;
359
+ }));
357
360
  }
358
- async function g(e, t) {
359
- let n = async (e) => await t.emit?.(e), r = t.signal ?? new AbortController().signal, i = t.trigger == null ? void 0 : e.flow.graph.nodes[t.trigger.nodeId];
360
- if (t.trigger != null && (i == null || "inputs" in i)) throw Error(`Node "${t.trigger.nodeId}" is not a TriggerNode in Flow "${e.flowId}".`);
361
- return await h({
362
- createId: t.createId,
363
- emit: n,
364
- invokeTask: t.invokeTask,
365
- prepared: e,
366
- projectFailure: t.projectFailure
367
- }, {
368
- flowId: e.flowId,
369
- graph: _(e.flow.graph),
370
- inputs: {},
371
- kind: "flow",
372
- outputs: {}
373
- }, t.runId, {}, r, void 0, t.inputs, void 0, t.trigger);
361
+ function v(t, n) {
362
+ let r = n.emit ?? (() => e.void);
363
+ return e.gen(function* () {
364
+ let i = n.trigger == null ? void 0 : t.graph.nodes[n.trigger.nodeId];
365
+ 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* _({
366
+ createId: n.createId,
367
+ emit: r,
368
+ invokeTask: n.invokeTask,
369
+ prepared: t,
370
+ projectFailure: n.projectFailure
371
+ }, {
372
+ flowId: n.flowId,
373
+ graph: y(t.graph),
374
+ inputs: {},
375
+ kind: "flow",
376
+ outputs: {}
377
+ }, n.runId, {}, void 0, n.inputs, void 0, n.trigger);
378
+ });
374
379
  }
375
- function _(e) {
380
+ function y(e) {
376
381
  return { nodes: Object.fromEntries(Object.entries(e.nodes).filter((e) => "inputs" in e[1])) };
377
382
  }
378
383
  //#endregion
379
- export { g as runFlow };
384
+ export { v as runFlow };
@@ -1,4 +1,4 @@
1
- import type { JsonValue, WebhookInputDefinition, WebhookOptions } from '../browser/project-change.js';
1
+ import type { JsonValue, WebhookInputDefinition, WebhookOptions } from '../browser/flow-change.js';
2
2
  export declare const maximumWebhookBodyBytes: number;
3
3
  export declare function webhookEndpointId(url: URL): string | undefined;
4
4
  export declare function webhookOccurrenceId(endpointId: string, runtimeVersion: number, key: string | null): Promise<string | undefined>;