@oomol-lab/open-flow 0.1.0-alpha.1 → 0.1.0-alpha.12

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 (78) hide show
  1. package/README.md +5 -1
  2. package/dist/browser/addNodeOptions-BYQXyUmQ.js +9571 -0
  3. package/dist/browser/carbon-DMCVsjHo.js +53 -0
  4. package/dist/browser/{project-change.js → change-7rp2OZLm.js} +16 -46
  5. package/dist/browser/createResourceDialog-CWD62rU0.js +467 -0
  6. package/dist/browser/{dist-o4dBuwiG.js → dist-3Mj8q8Pr.js} +28 -28
  7. package/dist/browser/{dist-CIq6ue3I.js → dist-BKuSVKCC.js} +1115 -1103
  8. package/dist/browser/{dist-DL0SDskM.js → dist-BMqL-qR5.js} +473 -906
  9. package/dist/browser/{dist-CLZJNoWB.js → dist-BN4ZCyOB.js} +10 -10
  10. package/dist/browser/{dist-zyY--HOV.js → dist-BpopSHwP.js} +3 -3
  11. package/dist/browser/dist-C46JByB-.js +252 -0
  12. package/dist/browser/{dist-BbyiRq3c.js → dist-CJpzJrLM.js} +294 -284
  13. package/dist/browser/{dist-Djd02JSy.js → dist-CPuF50D9.js} +198 -198
  14. package/dist/browser/{dist-CvcmLAMW.js → dist-CUSrALSX.js} +115 -115
  15. package/dist/browser/dist-CeSZ2xSM.js +444 -0
  16. package/dist/browser/{dist-7oZK9QXZ.js → dist-DMi8_lU3.js} +5 -5
  17. package/dist/browser/{dist-B9OV3YTx.js → dist-DUzA0Ukh.js} +22 -22
  18. package/dist/browser/{dist-aWSZx4q1.js → dist-DWADUsVB.js} +75 -75
  19. package/dist/browser/{dist-BLk5M0uK.js → dist-Mecbzdl2.js} +3 -3
  20. package/dist/browser/{esm-DXw7EADW.js → esm-DmVDlOEJ.js} +14 -24
  21. package/dist/browser/flow-authoring-edge.d.ts +3 -0
  22. package/dist/browser/flow-authoring-module.d.ts +4 -0
  23. package/dist/browser/flow-authoring-node.d.ts +86 -0
  24. package/dist/browser/flow-authoring.d.ts +4 -0
  25. package/dist/browser/flow-authoring.js +783 -0
  26. package/dist/browser/{project-change.d.ts → flow-change.d.ts} +29 -37
  27. package/dist/browser/flow-change.js +234 -0
  28. package/dist/browser/{project-notifications.d.ts → flow-notifications.d.ts} +6 -3
  29. package/dist/browser/flowRunInputEditorStore-BYxwvHZl.js +8952 -0
  30. package/dist/browser/flowWorkspace-Bwqmoq-c.js +47439 -0
  31. package/dist/browser/languages-DgJehE1g.js +62 -0
  32. package/dist/browser/lib-C5Ipyfps.js +7856 -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/main-DmjVyuWr.js +76 -0
  36. package/dist/browser/{markdownContent-ZZFfSRqO.js → markdownContent-0teWaxq8.js} +5188 -5144
  37. package/dist/browser/theme.css +63 -0
  38. package/dist/browser/theme.css.d.ts +1 -0
  39. package/dist/browser/typeScriptSession-D5neIpug.js +2560 -0
  40. package/dist/browser/{composite-7VwgfnXx.js → useOpenInteractionType-CRgOHg5M.js} +2209 -2750
  41. package/dist/browser/workbench-contract.d.ts +6 -6
  42. package/dist/browser/workbench.css +1 -1
  43. package/dist/browser/workbench.d.ts +18 -2
  44. package/dist/browser/workbench.js +4200 -2233
  45. package/dist/common/connector-action.d.ts +6 -0
  46. package/dist/common/connector-action.js +38 -30
  47. package/dist/common/control-api-conformance.js +262 -359
  48. package/dist/common/control-api-errors.d.ts +32 -24
  49. package/dist/common/control-api.d.ts +57 -73
  50. package/dist/common/control-api.js +199 -205
  51. package/dist/common/cron-trigger.d.ts +1 -1
  52. package/dist/common/cron-trigger.js +1 -1
  53. package/dist/common/flow-encoding.d.ts +11 -0
  54. package/dist/common/{project-encoding.js → flow-encoding.js} +14 -13
  55. package/dist/common/{project-notifications.d.ts → flow-notifications.d.ts} +6 -3
  56. package/dist/common/{project-semantics.d.ts → flow-semantics.d.ts} +11 -12
  57. package/dist/common/{project-semantics.js → flow-semantics.js} +959 -934
  58. package/dist/common/integration-trigger.d.ts +2 -1
  59. package/dist/common/integration-trigger.js +1 -1
  60. package/dist/common/licenses.md +1 -25
  61. package/dist/common/localization.d.ts +21 -0
  62. package/dist/common/localization.js +62 -0
  63. package/dist/common/poll-trigger.d.ts +1 -1
  64. package/dist/common/provider-triggers.js +1057 -948
  65. package/dist/common/run-lifecycle.js +1 -1
  66. package/dist/common/runtime-contract.d.ts +1 -1
  67. package/dist/common/runtime-contract.js +1 -1
  68. package/dist/common/scheduler.d.ts +8 -7
  69. package/dist/common/scheduler.js +251 -232
  70. package/dist/common/webhook-trigger.d.ts +1 -1
  71. package/dist/common/webhook-trigger.js +35 -1
  72. package/package.json +23 -10
  73. package/dist/browser/addNodeOptions-DqoIueCR.js +0 -33746
  74. package/dist/browser/carbon-nMY84Amv.js +0 -53
  75. package/dist/browser/createResourceDialog-ByuJWdSL.js +0 -439
  76. package/dist/browser/dist-n-z5HtaO.js +0 -4
  77. package/dist/browser/flowWorkspace-DwVMpcar.js +0 -22092
  78. 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[];
@@ -86,14 +86,15 @@ export interface SchedulerFailure {
86
86
  readonly message: string;
87
87
  }
88
88
  export interface FlowRunOptions {
89
+ readonly bindingValues?: Readonly<Record<string, string>>;
89
90
  readonly createId: () => string;
90
- readonly emit?: (event: SchedulerEvent) => void | Promise<void>;
91
+ readonly emit?: (event: SchedulerEvent) => Effect.Effect<void, Error>;
92
+ readonly flowId: string;
91
93
  readonly inputs?: Readonly<Record<string, Readonly<Record<string, JsonValue>>>>;
92
- readonly invokeTask: (invocation: TaskInvocation) => Promise<unknown>;
94
+ readonly invokeTask: (invocation: TaskInvocation) => Effect.Effect<unknown, Error>;
93
95
  readonly projectFailure?: (error: unknown) => SchedulerFailure;
94
96
  readonly runId: string;
95
- readonly signal?: AbortSignal;
96
97
  readonly trigger?: TriggerSeed;
97
98
  }
98
- export declare function runFlow(prepared: PreparedFlow, options: FlowRunOptions): Promise<FlowRunResult>;
99
+ export declare function runFlow(prepared: PreparedFlow, options: FlowRunOptions): Effect.Effect<FlowRunResult, Error>;
99
100
  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,241 @@ 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(), 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) ?? [];
179
+ r.push({
180
+ handle: n,
181
+ nodeId: e
182
+ }), O.set(t.bindingId, r);
183
+ } else if (t.kind == "flow") {
184
+ let r = D.get(t.input) ?? [];
185
+ r.push({
186
+ handle: n,
187
+ nodeId: e
188
+ }), D.set(t.input, r);
189
+ } else t.kind == "node" && d(k, t.nodeId, t.output, {
186
190
  handle: n,
187
191
  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
192
  });
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;
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,
199
+ jobId: n,
200
+ nodeId: t,
201
+ runId: m,
202
+ type: "node.output",
203
+ value: i
204
+ });
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]) => {
210
+ let t = n.inputs[e];
211
+ return t?.kind != "sources" || t.sources.every((e) => e.kind != "binding");
212
+ }));
213
+ yield* a.emit({
214
+ inputs: d,
215
+ jobId: i,
216
+ nodeId: t,
217
+ nodeKind: s,
218
+ ...c == null ? {} : { nodeTitle: c },
219
+ runId: m,
220
+ type: "node.started"
221
+ });
222
+ let f;
223
+ switch (n.kind) {
224
+ case "condition": {
225
+ let e = n.cases.find((e) => {
226
+ if (e.expressions.length == 0) return !1;
227
+ let t = e.expressions.map((e) => h(n, e, o));
228
+ return e.relation == "all" ? t.every(Boolean) : t.some(Boolean);
229
+ })?.output ?? n.defaultOutput;
230
+ f = e == null ? {} : { [e]: o[n.input.handle] ?? null }, e != null && (yield* H(t, i, e, f[e]));
231
+ break;
232
+ }
233
+ case "value":
234
+ 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);
236
+ break;
237
+ case "subflow": {
238
+ let e = a.prepared.subflows[n.subflowId];
239
+ f = yield* _(a, {
240
+ flowId: n.subflowId,
241
+ graph: y(e.graph),
242
+ inputs: r(e.inputs),
243
+ kind: "subflow",
244
+ outputs: r(e.outputs)
245
+ }, a.createId(), o, {
246
+ jobId: i,
247
+ runId: m
248
+ }, {}, (e, n) => H(t, i, e, n));
249
+ break;
250
+ }
251
+ case "task": {
252
+ let r = yield* a.invokeTask({
253
+ input: o,
254
+ invocationId: a.createId(),
255
+ jobId: i,
256
+ nodeId: t,
257
+ runId: m,
258
+ ...n.task == null ? { taskId: n.taskId } : {
259
+ capabilities: n.task.capabilities ?? [],
260
+ moduleId: n.task.moduleId
261
+ }
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);
268
+ break;
269
+ }
248
270
  }
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);
271
+ return yield* a.emit({
272
+ jobId: i,
273
+ nodeId: t,
274
+ runId: m,
275
+ type: "node.completed"
276
+ }), f;
277
+ });
278
+ return n.timeoutMs == null ? s : s.pipe(e.timeoutOrElse({
279
+ duration: n.timeoutMs,
280
+ orElse: () => e.fail(/* @__PURE__ */ Error(`Node "${t}" timed out.`))
281
+ }));
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) ?? [];
286
+ e.push({
287
+ jobId: s,
288
+ order: c,
289
+ outputs: n
290
+ }), P.set(t, e), L.has(t) || (L.add(t), yield* a.emit({
291
+ ...b == null ? {} : {
292
+ parentJobId: b.jobId,
293
+ parentRunId: b.runId
294
+ },
295
+ progress: L.size / T * 100,
296
+ runId: m,
297
+ type: "run.progress"
298
+ }));
299
+ })), 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,
305
+ nodeId: t,
306
+ runId: m,
307
+ type: "node.failed"
308
+ }).pipe(e.ignore);
309
+ })), e.tapCause((t) => e.sync(() => {
310
+ R ??= t;
311
+ })), e.ensuring(e.sync(() => {
312
+ j.set(t, (j.get(t) ?? 1) - 1), B(t);
313
+ }))));
314
+ };
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);
263
333
  }
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
334
  }
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
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,
341
+ 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({
348
+ result: {
349
+ kind: "function-outputs",
350
+ outputs: e,
351
+ target: "subflow"
287
352
  },
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);
353
+ runId: m,
354
+ type: "run.completed"
355
+ }), e;
320
356
  }
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,
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 = {
358
+ 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 }) => ({
361
+ jobId: e,
362
+ outputs: t
363
+ })),
364
+ nodeId: e
365
+ }))
366
+ };
367
+ return yield* a.emit({
368
+ result: q,
369
+ runId: m,
339
370
  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;
371
+ }), q;
372
+ }));
357
373
  }
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);
374
+ function v(t, n) {
375
+ let r = n.emit ?? (() => e.void);
376
+ 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 ?? {},
380
+ createId: n.createId,
381
+ emit: r,
382
+ invokeTask: n.invokeTask,
383
+ prepared: t,
384
+ projectFailure: n.projectFailure
385
+ }, {
386
+ flowId: n.flowId,
387
+ graph: y(t.graph),
388
+ inputs: {},
389
+ kind: "flow",
390
+ outputs: {}
391
+ }, n.runId, {}, void 0, n.inputs, void 0, n.trigger);
392
+ });
374
393
  }
375
- function _(e) {
394
+ function y(e) {
376
395
  return { nodes: Object.fromEntries(Object.entries(e.nodes).filter((e) => "inputs" in e[1])) };
377
396
  }
378
397
  //#endregion
379
- export { g as runFlow };
398
+ 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>;