@oomol-lab/open-flow 0.1.0-alpha.0
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.
- package/LICENSE +201 -0
- package/NOTICE +47 -0
- package/README.md +18 -0
- package/dist/browser/_virtual_open-flow-twemoji-DJwKsM_w.js +5067 -0
- package/dist/browser/addNodeOptions-DqoIueCR.js +33746 -0
- package/dist/browser/assets/font-00b26ac825e20950.woff2 +0 -0
- package/dist/browser/assets/font-036d4e95149b69ff.woff2 +0 -0
- package/dist/browser/assets/font-07d8e303ce4fc12b.ttf +0 -0
- package/dist/browser/assets/font-08ce98e51b04d589.ttf +0 -0
- package/dist/browser/assets/font-0cdd387c9590a1a9.woff2 +0 -0
- package/dist/browser/assets/font-0d85ae7cc30f2379.ttf +0 -0
- package/dist/browser/assets/font-0f60d1b897938ec9.woff2 +0 -0
- package/dist/browser/assets/font-11e4dc8a6471ff6d.woff +0 -0
- package/dist/browser/assets/font-138ac28d1663b303.ttf +0 -0
- package/dist/browser/assets/font-1ae6bd7475590e97.woff +0 -0
- package/dist/browser/assets/font-1c67f068fea8bb09.ttf +0 -0
- package/dist/browser/assets/font-1e6f9579e90e2cac.ttf +0 -0
- package/dist/browser/assets/font-1ece03f79f95277d.ttf +0 -0
- package/dist/browser/assets/font-2014c523c3210bcc.woff +0 -0
- package/dist/browser/assets/font-30da91e84c893f87.woff +0 -0
- package/dist/browser/assets/font-3398dd02302557a7.woff +0 -0
- package/dist/browser/assets/font-3931dd81faed86ba.ttf +0 -0
- package/dist/browser/assets/font-500e04d54f0d5166.ttf +0 -0
- package/dist/browser/assets/font-51814d270d06ff02.woff2 +0 -0
- package/dist/browser/assets/font-5d53e70ad607c235.woff2 +0 -0
- package/dist/browser/assets/font-5e28753be717dac9.woff +0 -0
- package/dist/browser/assets/font-68534840bcfdd2bf.ttf +0 -0
- package/dist/browser/assets/font-68e8c73ef42afd3c.woff2 +0 -0
- package/dist/browser/assets/font-6ab6b62e9b62dae2.woff +0 -0
- package/dist/browser/assets/font-6b47c40166b6dbe2.woff2 +0 -0
- package/dist/browser/assets/font-70ee1f64a20f2048.ttf +0 -0
- package/dist/browser/assets/font-71d517d67827787c.woff2 +0 -0
- package/dist/browser/assets/font-73d591271b160496.woff2 +0 -0
- package/dist/browser/assets/font-74444efd593c005e.woff2 +0 -0
- package/dist/browser/assets/font-7af58c5ec8f132a2.woff2 +0 -0
- package/dist/browser/assets/font-850c0af5c2238497.woff +0 -0
- package/dist/browser/assets/font-8a8d244581371912.woff +0 -0
- package/dist/browser/assets/font-9163df9c7122432e.ttf +0 -0
- package/dist/browser/assets/font-91ee67500cc0129a.woff +0 -0
- package/dist/browser/assets/font-95b6d2f1a50173bf.ttf +0 -0
- package/dist/browser/assets/font-97479ca6cce906ab.woff2 +0 -0
- package/dist/browser/assets/font-99cd42a3c072d918.woff2 +0 -0
- package/dist/browser/assets/font-99f9c6750b489c94.woff +0 -0
- package/dist/browser/assets/font-9be7ceb88004ab8a.woff +0 -0
- package/dist/browser/assets/font-a4af7d414440a1c1.woff2 +0 -0
- package/dist/browser/assets/font-a6b2099fb555c60e.ttf +0 -0
- package/dist/browser/assets/font-a6f7ec0d846ac7ad.woff +0 -0
- package/dist/browser/assets/font-c2342cd8b869e017.woff2 +0 -0
- package/dist/browser/assets/font-c6368d87e8a1a3a5.woff +0 -0
- package/dist/browser/assets/font-c647367d1dd4e162.ttf +0 -0
- package/dist/browser/assets/font-c76c5d696297d51b.woff +0 -0
- package/dist/browser/assets/font-c943cc986384f59e.woff +0 -0
- package/dist/browser/assets/font-d0332f52868370fd.ttf +0 -0
- package/dist/browser/assets/font-d04c54219f9eaec6.woff2 +0 -0
- package/dist/browser/assets/font-d96cdf2b3bdd4d64.woff +0 -0
- package/dist/browser/assets/font-dc47344dbb6cb5b6.woff2 +0 -0
- package/dist/browser/assets/font-de7701e42cf1f4cf.woff2 +0 -0
- package/dist/browser/assets/font-e14fed02b1aba7ce.woff +0 -0
- package/dist/browser/assets/font-e99ae51144bf1232.woff2 +0 -0
- package/dist/browser/assets/font-ece03cfd83e22c21.woff +0 -0
- package/dist/browser/assets/font-ed0b74372feefcbb.ttf +0 -0
- package/dist/browser/assets/font-f01f3e87d9c6a61c.ttf +0 -0
- package/dist/browser/assets/font-f1d6ef86f3b11a52.woff +0 -0
- package/dist/browser/assets/font-f36ea897e19f4a2e.ttf +0 -0
- package/dist/browser/assets/font-f9377ab0271cda59.ttf +0 -0
- package/dist/browser/carbon-nMY84Amv.js +53 -0
- package/dist/browser/composite-7VwgfnXx.js +6088 -0
- package/dist/browser/createResourceDialog-ByuJWdSL.js +439 -0
- package/dist/browser/dist-7oZK9QXZ.js +50088 -0
- package/dist/browser/dist-B9OV3YTx.js +881 -0
- package/dist/browser/dist-BLk5M0uK.js +1816 -0
- package/dist/browser/dist-BbyiRq3c.js +3285 -0
- package/dist/browser/dist-CIq6ue3I.js +6646 -0
- package/dist/browser/dist-CLZJNoWB.js +89 -0
- package/dist/browser/dist-CvcmLAMW.js +1620 -0
- package/dist/browser/dist-DL0SDskM.js +2327 -0
- package/dist/browser/dist-Djd02JSy.js +1247 -0
- package/dist/browser/dist-aWSZx4q1.js +850 -0
- package/dist/browser/dist-n-z5HtaO.js +4 -0
- package/dist/browser/dist-o4dBuwiG.js +320 -0
- package/dist/browser/dist-zyY--HOV.js +1543 -0
- package/dist/browser/esm-DXw7EADW.js +218 -0
- package/dist/browser/favicon.svg +7 -0
- package/dist/browser/flowWorkspace-DwVMpcar.js +22092 -0
- package/dist/browser/lib-S4ccuMeT.js +7857 -0
- package/dist/browser/licenses.md +4973 -0
- package/dist/browser/markdownContent-ZZFfSRqO.js +44545 -0
- package/dist/browser/project-change.d.ts +311 -0
- package/dist/browser/project-change.js +259 -0
- package/dist/browser/project-notifications.d.ts +12 -0
- package/dist/browser/rolldown-runtime-CEFd7nDs.js +30 -0
- package/dist/browser/workbench-contract.d.ts +28 -0
- package/dist/browser/workbench.css +2 -0
- package/dist/browser/workbench.css.d.ts +1 -0
- package/dist/browser/workbench.d.ts +14 -0
- package/dist/browser/workbench.js +3364 -0
- package/dist/common/connector-action.d.ts +20 -0
- package/dist/common/connector-action.js +106 -0
- package/dist/common/connector-proxy.d.ts +14 -0
- package/dist/common/connector-proxy.js +0 -0
- package/dist/common/control-api-conformance.d.ts +13 -0
- package/dist/common/control-api-conformance.js +518 -0
- package/dist/common/control-api-errors.d.ts +121 -0
- package/dist/common/control-api.d.ts +349 -0
- package/dist/common/control-api.js +884 -0
- package/dist/common/cron-trigger.d.ts +21 -0
- package/dist/common/cron-trigger.js +834 -0
- package/dist/common/engine-contract.d.ts +7 -0
- package/dist/common/favicon.svg +7 -0
- package/dist/common/integration-trigger.d.ts +111 -0
- package/dist/common/integration-trigger.js +290 -0
- package/dist/common/licenses.md +27 -0
- package/dist/common/poll-trigger.d.ts +69 -0
- package/dist/common/poll-trigger.js +155 -0
- package/dist/common/project-encoding.d.ts +11 -0
- package/dist/common/project-encoding.js +242 -0
- package/dist/common/project-notifications.d.ts +12 -0
- package/dist/common/project-semantics.d.ts +55 -0
- package/dist/common/project-semantics.js +8687 -0
- package/dist/common/provider-triggers.d.ts +6 -0
- package/dist/common/provider-triggers.js +4614 -0
- package/dist/common/run-events.d.ts +9 -0
- package/dist/common/run-events.js +192 -0
- package/dist/common/run-lifecycle.d.ts +69 -0
- package/dist/common/run-lifecycle.js +169 -0
- package/dist/common/runtime-contract.d.ts +53 -0
- package/dist/common/runtime-contract.js +151 -0
- package/dist/common/scheduler.d.ts +99 -0
- package/dist/common/scheduler.js +379 -0
- package/dist/common/webhook-trigger.d.ts +22 -0
- package/dist/common/webhook-trigger.js +270 -0
- package/dist/index.d.ts +66 -0
- package/package.json +102 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { ConnectorCapability, JsonValue } from '../browser/project-change.js';
|
|
2
|
+
import type { PreparedFlow } from './project-semantics.js';
|
|
3
|
+
export type SchedulerEvent = {
|
|
4
|
+
readonly flowId: string;
|
|
5
|
+
readonly parentJobId?: string;
|
|
6
|
+
readonly parentRunId?: string;
|
|
7
|
+
readonly runId: string;
|
|
8
|
+
readonly type: 'run.started';
|
|
9
|
+
} | {
|
|
10
|
+
readonly parentJobId?: string;
|
|
11
|
+
readonly parentRunId?: string;
|
|
12
|
+
readonly progress: number;
|
|
13
|
+
readonly runId: string;
|
|
14
|
+
readonly type: 'run.progress';
|
|
15
|
+
} | {
|
|
16
|
+
readonly inputs: Readonly<Record<string, JsonValue>>;
|
|
17
|
+
readonly jobId: string;
|
|
18
|
+
readonly nodeId: string;
|
|
19
|
+
readonly nodeKind: 'condition' | 'connector' | 'javascript' | 'llm' | 'subflow' | 'value';
|
|
20
|
+
readonly nodeTitle?: string;
|
|
21
|
+
readonly runId: string;
|
|
22
|
+
readonly type: 'node.started';
|
|
23
|
+
} | {
|
|
24
|
+
readonly handle: string;
|
|
25
|
+
readonly jobId: string;
|
|
26
|
+
readonly nodeId: string;
|
|
27
|
+
readonly runId: string;
|
|
28
|
+
readonly type: 'node.output';
|
|
29
|
+
readonly value: JsonValue;
|
|
30
|
+
} | {
|
|
31
|
+
readonly jobId: string;
|
|
32
|
+
readonly nodeId: string;
|
|
33
|
+
readonly runId: string;
|
|
34
|
+
readonly type: 'node.completed';
|
|
35
|
+
} | {
|
|
36
|
+
readonly code: string;
|
|
37
|
+
readonly jobId: string;
|
|
38
|
+
readonly message: string;
|
|
39
|
+
readonly nodeId: string;
|
|
40
|
+
readonly runId: string;
|
|
41
|
+
readonly type: 'node.failed';
|
|
42
|
+
} | {
|
|
43
|
+
readonly result: FlowRunResult | SubflowRunResult;
|
|
44
|
+
readonly runId: string;
|
|
45
|
+
readonly type: 'run.completed';
|
|
46
|
+
} | {
|
|
47
|
+
readonly message: string;
|
|
48
|
+
readonly runId: string;
|
|
49
|
+
readonly type: 'run.failed';
|
|
50
|
+
};
|
|
51
|
+
export interface FlowRunResult {
|
|
52
|
+
readonly kind: 'node-results';
|
|
53
|
+
readonly nodes: readonly {
|
|
54
|
+
readonly jobs: readonly {
|
|
55
|
+
readonly jobId: string;
|
|
56
|
+
readonly outputs: Readonly<Record<string, JsonValue>>;
|
|
57
|
+
}[];
|
|
58
|
+
readonly nodeId: string;
|
|
59
|
+
}[];
|
|
60
|
+
}
|
|
61
|
+
export interface SubflowRunResult {
|
|
62
|
+
readonly kind: 'function-outputs';
|
|
63
|
+
readonly outputs: Readonly<Record<string, JsonValue>>;
|
|
64
|
+
readonly target: 'subflow';
|
|
65
|
+
}
|
|
66
|
+
interface TaskInvocationBase {
|
|
67
|
+
readonly input: Readonly<Record<string, JsonValue>>;
|
|
68
|
+
readonly invocationId: string;
|
|
69
|
+
readonly jobId: string;
|
|
70
|
+
readonly nodeId: string;
|
|
71
|
+
readonly runId: string;
|
|
72
|
+
readonly signal: AbortSignal;
|
|
73
|
+
}
|
|
74
|
+
export type TaskInvocation = TaskInvocationBase & ({
|
|
75
|
+
readonly capabilities: readonly ConnectorCapability[];
|
|
76
|
+
readonly moduleId: string;
|
|
77
|
+
} | {
|
|
78
|
+
readonly taskId: string;
|
|
79
|
+
});
|
|
80
|
+
export interface TriggerSeed {
|
|
81
|
+
readonly nodeId: string;
|
|
82
|
+
readonly payload: JsonValue;
|
|
83
|
+
}
|
|
84
|
+
export interface SchedulerFailure {
|
|
85
|
+
readonly code: string;
|
|
86
|
+
readonly message: string;
|
|
87
|
+
}
|
|
88
|
+
export interface FlowRunOptions {
|
|
89
|
+
readonly createId: () => string;
|
|
90
|
+
readonly emit?: (event: SchedulerEvent) => void | Promise<void>;
|
|
91
|
+
readonly inputs?: Readonly<Record<string, Readonly<Record<string, JsonValue>>>>;
|
|
92
|
+
readonly invokeTask: (invocation: TaskInvocation) => Promise<unknown>;
|
|
93
|
+
readonly projectFailure?: (error: unknown) => SchedulerFailure;
|
|
94
|
+
readonly runId: string;
|
|
95
|
+
readonly signal?: AbortSignal;
|
|
96
|
+
readonly trigger?: TriggerSeed;
|
|
97
|
+
}
|
|
98
|
+
export declare function runFlow(prepared: PreparedFlow, options: FlowRunOptions): Promise<FlowRunResult>;
|
|
99
|
+
export {};
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
//#region src/execution/common/scheduler.ts
|
|
2
|
+
function e(e, t) {
|
|
3
|
+
return t?.(e) ?? {
|
|
4
|
+
code: "node.failed",
|
|
5
|
+
message: e instanceof Error ? e.message : String(e)
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
var t = class {
|
|
9
|
+
#e = [];
|
|
10
|
+
#t = 0;
|
|
11
|
+
get length() {
|
|
12
|
+
return this.#e.length - this.#t;
|
|
13
|
+
}
|
|
14
|
+
push(e) {
|
|
15
|
+
this.#e.push(e);
|
|
16
|
+
}
|
|
17
|
+
shift() {
|
|
18
|
+
let e = this.#e[this.#t];
|
|
19
|
+
return this.#t += 1, this.#t >= 64 && this.#t * 2 >= this.#e.length && (this.#e.splice(0, this.#t), this.#t = 0), e;
|
|
20
|
+
}
|
|
21
|
+
}, n = class {
|
|
22
|
+
#e;
|
|
23
|
+
#t = new t();
|
|
24
|
+
#n;
|
|
25
|
+
#r;
|
|
26
|
+
constructor(e, t, n) {
|
|
27
|
+
let r = e.inputs[t];
|
|
28
|
+
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;
|
|
29
|
+
}
|
|
30
|
+
get ready() {
|
|
31
|
+
return this.#t.length > 0 || this.#n;
|
|
32
|
+
}
|
|
33
|
+
get dynamic() {
|
|
34
|
+
return this.#e;
|
|
35
|
+
}
|
|
36
|
+
provide(e) {
|
|
37
|
+
this.#e || (this.#n = !0, this.#r = e);
|
|
38
|
+
}
|
|
39
|
+
push(e) {
|
|
40
|
+
this.#t.push(e);
|
|
41
|
+
}
|
|
42
|
+
take() {
|
|
43
|
+
return this.#t.length > 0 ? this.#t.shift() : this.#r;
|
|
44
|
+
}
|
|
45
|
+
}, r = class {
|
|
46
|
+
#e;
|
|
47
|
+
#t;
|
|
48
|
+
#n;
|
|
49
|
+
#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);
|
|
52
|
+
}
|
|
53
|
+
get ready() {
|
|
54
|
+
return (!this.#r || this.#e) && [...this.#n.values()].every((e) => e.ready);
|
|
55
|
+
}
|
|
56
|
+
launch(e, t) {
|
|
57
|
+
let n = this.#n.get(e);
|
|
58
|
+
n?.dynamic ? n.push(t) : n?.provide(t);
|
|
59
|
+
}
|
|
60
|
+
push(e, t) {
|
|
61
|
+
let n = this.#n.get(e);
|
|
62
|
+
if (n == null) throw Error(`Node "${this.#t}" has no input "${e}".`);
|
|
63
|
+
n.push(t);
|
|
64
|
+
}
|
|
65
|
+
take() {
|
|
66
|
+
if (!this.ready) throw Error(`Node "${this.#t}" inputs are not ready.`);
|
|
67
|
+
return this.#e || (this.#r = !0), Object.fromEntries([...this.#n].map(([e, t]) => [e, t.take()]));
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
function i(e, t) {
|
|
71
|
+
switch (t.kind) {
|
|
72
|
+
case "condition": return { [t.input.handle]: t.input };
|
|
73
|
+
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;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function a(e, t) {
|
|
79
|
+
if (t.name != null) return t.name;
|
|
80
|
+
switch (t.kind) {
|
|
81
|
+
case "condition": return;
|
|
82
|
+
case "value": return "Value";
|
|
83
|
+
case "subflow": return e.subflows[t.subflowId].name;
|
|
84
|
+
case "task": return t.task == null ? e.tasks[t.taskId].name : t.task.name;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function o(e, t) {
|
|
88
|
+
return t.kind == "task" ? t.task == null ? e.tasks[t.taskId].executor.kind : "javascript" : t.kind;
|
|
89
|
+
}
|
|
90
|
+
function s(e, t, n, r) {
|
|
91
|
+
let i = e.get(t) ?? /* @__PURE__ */ new Map(), a = i.get(n) ?? [];
|
|
92
|
+
a.push(r), i.set(n, a), e.set(t, i);
|
|
93
|
+
}
|
|
94
|
+
function c(e, t, n) {
|
|
95
|
+
return e.get(t)?.get(n) ?? [];
|
|
96
|
+
}
|
|
97
|
+
function l(e) {
|
|
98
|
+
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
|
+
for (; t.size > 0;) {
|
|
100
|
+
let e = [...t].filter(([, e]) => e.size == 0).map(([e]) => e).toSorted();
|
|
101
|
+
if (e.length == 0) throw Error("Prepared graph contains a dependency cycle.");
|
|
102
|
+
for (let r of e) t.delete(r), n.push(r);
|
|
103
|
+
for (let n of t.values()) for (let t of e) n.delete(t);
|
|
104
|
+
}
|
|
105
|
+
return n;
|
|
106
|
+
}
|
|
107
|
+
function u(e, t) {
|
|
108
|
+
if (e === t) return !0;
|
|
109
|
+
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]));
|
|
111
|
+
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]));
|
|
113
|
+
}
|
|
114
|
+
function d(e, t, n) {
|
|
115
|
+
let r = Object.hasOwn(n, t.input) ? n[t.input] : null, i = t.value;
|
|
116
|
+
switch (t.operator) {
|
|
117
|
+
case "==": return i !== void 0 && u(r, i);
|
|
118
|
+
case "!=": return i !== void 0 && !u(r, i);
|
|
119
|
+
case ">": return typeof r == "number" && typeof i == "number" && r > i;
|
|
120
|
+
case ">=": return typeof r == "number" && typeof i == "number" && r >= i;
|
|
121
|
+
case "<": return typeof r == "number" && typeof i == "number" && r < i;
|
|
122
|
+
case "<=": return typeof r == "number" && typeof i == "number" && r <= i;
|
|
123
|
+
case "contains":
|
|
124
|
+
case "notContains": {
|
|
125
|
+
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;
|
|
127
|
+
}
|
|
128
|
+
case "startsWith": return typeof r == "string" && typeof i == "string" && r.startsWith(i);
|
|
129
|
+
case "endsWith": return typeof r == "string" && typeof i == "string" && r.endsWith(i);
|
|
130
|
+
case "hasKey":
|
|
131
|
+
case "notHasKey": {
|
|
132
|
+
if (r == null || Array.isArray(r) || typeof r != "object" || typeof i != "string") return !1;
|
|
133
|
+
let e = Object.hasOwn(r, i);
|
|
134
|
+
return t.operator == "hasKey" ? e : !e;
|
|
135
|
+
}
|
|
136
|
+
case "hasValue":
|
|
137
|
+
case "notHasValue": {
|
|
138
|
+
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));
|
|
140
|
+
return t.operator == "hasValue" ? e : !e;
|
|
141
|
+
}
|
|
142
|
+
case "isEmpty":
|
|
143
|
+
case "isNotEmpty": {
|
|
144
|
+
let e = r === null || typeof r == "string" && r.length == 0 || Array.isArray(r) && r.length == 0 || typeof r == "object" && !Array.isArray(r) && Object.keys(r).length == 0;
|
|
145
|
+
return (r === null || typeof r == "string" || typeof r == "object") && (t.operator == "isEmpty" ? e : !e);
|
|
146
|
+
}
|
|
147
|
+
case "isNull": return r === null;
|
|
148
|
+
case "isNotNull": return r !== null;
|
|
149
|
+
case "isTrue": return r === !0;
|
|
150
|
+
case "isFalse": return r === !1;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function f(e, t) {
|
|
154
|
+
if (typeof e != "object" || !e || Array.isArray(e)) throw Error(`Node "${t}" must return an object.`);
|
|
155
|
+
return e;
|
|
156
|
+
}
|
|
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);
|
|
169
|
+
});
|
|
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({
|
|
186
|
+
handle: n,
|
|
187
|
+
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
|
+
});
|
|
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;
|
|
248
|
+
}
|
|
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);
|
|
263
|
+
}
|
|
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
|
+
}
|
|
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
|
|
287
|
+
},
|
|
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);
|
|
320
|
+
}
|
|
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,
|
|
339
|
+
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;
|
|
357
|
+
}
|
|
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
|
+
}
|
|
375
|
+
function _(e) {
|
|
376
|
+
return { nodes: Object.fromEntries(Object.entries(e.nodes).filter((e) => "inputs" in e[1])) };
|
|
377
|
+
}
|
|
378
|
+
//#endregion
|
|
379
|
+
export { g as runFlow };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { JsonValue, WebhookInputDefinition, WebhookOptions } from '../browser/project-change.js';
|
|
2
|
+
export declare const maximumWebhookBodyBytes: number;
|
|
3
|
+
export declare function webhookEndpointId(url: URL): string | undefined;
|
|
4
|
+
export declare function webhookOccurrenceId(endpointId: string, runtimeVersion: number, key: string | null): Promise<string | undefined>;
|
|
5
|
+
export interface WebhookConformanceFixture {
|
|
6
|
+
readonly inputsDef: readonly WebhookInputDefinition[];
|
|
7
|
+
readonly options?: WebhookOptions;
|
|
8
|
+
}
|
|
9
|
+
export interface WebhookConformanceHarness {
|
|
10
|
+
readonly endpointUrl: string;
|
|
11
|
+
dispose(): Promise<void>;
|
|
12
|
+
payloads(): Promise<readonly JsonValue[]>;
|
|
13
|
+
republish(): Promise<void>;
|
|
14
|
+
request(request: Request): Promise<Response>;
|
|
15
|
+
retire(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export interface WebhookConformanceCase {
|
|
18
|
+
readonly fixture: WebhookConformanceFixture;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
verify(harness: WebhookConformanceHarness): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export declare const webhookConformanceCases: readonly WebhookConformanceCase[];
|