@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.
Files changed (133) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +47 -0
  3. package/README.md +18 -0
  4. package/dist/browser/_virtual_open-flow-twemoji-DJwKsM_w.js +5067 -0
  5. package/dist/browser/addNodeOptions-DqoIueCR.js +33746 -0
  6. package/dist/browser/assets/font-00b26ac825e20950.woff2 +0 -0
  7. package/dist/browser/assets/font-036d4e95149b69ff.woff2 +0 -0
  8. package/dist/browser/assets/font-07d8e303ce4fc12b.ttf +0 -0
  9. package/dist/browser/assets/font-08ce98e51b04d589.ttf +0 -0
  10. package/dist/browser/assets/font-0cdd387c9590a1a9.woff2 +0 -0
  11. package/dist/browser/assets/font-0d85ae7cc30f2379.ttf +0 -0
  12. package/dist/browser/assets/font-0f60d1b897938ec9.woff2 +0 -0
  13. package/dist/browser/assets/font-11e4dc8a6471ff6d.woff +0 -0
  14. package/dist/browser/assets/font-138ac28d1663b303.ttf +0 -0
  15. package/dist/browser/assets/font-1ae6bd7475590e97.woff +0 -0
  16. package/dist/browser/assets/font-1c67f068fea8bb09.ttf +0 -0
  17. package/dist/browser/assets/font-1e6f9579e90e2cac.ttf +0 -0
  18. package/dist/browser/assets/font-1ece03f79f95277d.ttf +0 -0
  19. package/dist/browser/assets/font-2014c523c3210bcc.woff +0 -0
  20. package/dist/browser/assets/font-30da91e84c893f87.woff +0 -0
  21. package/dist/browser/assets/font-3398dd02302557a7.woff +0 -0
  22. package/dist/browser/assets/font-3931dd81faed86ba.ttf +0 -0
  23. package/dist/browser/assets/font-500e04d54f0d5166.ttf +0 -0
  24. package/dist/browser/assets/font-51814d270d06ff02.woff2 +0 -0
  25. package/dist/browser/assets/font-5d53e70ad607c235.woff2 +0 -0
  26. package/dist/browser/assets/font-5e28753be717dac9.woff +0 -0
  27. package/dist/browser/assets/font-68534840bcfdd2bf.ttf +0 -0
  28. package/dist/browser/assets/font-68e8c73ef42afd3c.woff2 +0 -0
  29. package/dist/browser/assets/font-6ab6b62e9b62dae2.woff +0 -0
  30. package/dist/browser/assets/font-6b47c40166b6dbe2.woff2 +0 -0
  31. package/dist/browser/assets/font-70ee1f64a20f2048.ttf +0 -0
  32. package/dist/browser/assets/font-71d517d67827787c.woff2 +0 -0
  33. package/dist/browser/assets/font-73d591271b160496.woff2 +0 -0
  34. package/dist/browser/assets/font-74444efd593c005e.woff2 +0 -0
  35. package/dist/browser/assets/font-7af58c5ec8f132a2.woff2 +0 -0
  36. package/dist/browser/assets/font-850c0af5c2238497.woff +0 -0
  37. package/dist/browser/assets/font-8a8d244581371912.woff +0 -0
  38. package/dist/browser/assets/font-9163df9c7122432e.ttf +0 -0
  39. package/dist/browser/assets/font-91ee67500cc0129a.woff +0 -0
  40. package/dist/browser/assets/font-95b6d2f1a50173bf.ttf +0 -0
  41. package/dist/browser/assets/font-97479ca6cce906ab.woff2 +0 -0
  42. package/dist/browser/assets/font-99cd42a3c072d918.woff2 +0 -0
  43. package/dist/browser/assets/font-99f9c6750b489c94.woff +0 -0
  44. package/dist/browser/assets/font-9be7ceb88004ab8a.woff +0 -0
  45. package/dist/browser/assets/font-a4af7d414440a1c1.woff2 +0 -0
  46. package/dist/browser/assets/font-a6b2099fb555c60e.ttf +0 -0
  47. package/dist/browser/assets/font-a6f7ec0d846ac7ad.woff +0 -0
  48. package/dist/browser/assets/font-c2342cd8b869e017.woff2 +0 -0
  49. package/dist/browser/assets/font-c6368d87e8a1a3a5.woff +0 -0
  50. package/dist/browser/assets/font-c647367d1dd4e162.ttf +0 -0
  51. package/dist/browser/assets/font-c76c5d696297d51b.woff +0 -0
  52. package/dist/browser/assets/font-c943cc986384f59e.woff +0 -0
  53. package/dist/browser/assets/font-d0332f52868370fd.ttf +0 -0
  54. package/dist/browser/assets/font-d04c54219f9eaec6.woff2 +0 -0
  55. package/dist/browser/assets/font-d96cdf2b3bdd4d64.woff +0 -0
  56. package/dist/browser/assets/font-dc47344dbb6cb5b6.woff2 +0 -0
  57. package/dist/browser/assets/font-de7701e42cf1f4cf.woff2 +0 -0
  58. package/dist/browser/assets/font-e14fed02b1aba7ce.woff +0 -0
  59. package/dist/browser/assets/font-e99ae51144bf1232.woff2 +0 -0
  60. package/dist/browser/assets/font-ece03cfd83e22c21.woff +0 -0
  61. package/dist/browser/assets/font-ed0b74372feefcbb.ttf +0 -0
  62. package/dist/browser/assets/font-f01f3e87d9c6a61c.ttf +0 -0
  63. package/dist/browser/assets/font-f1d6ef86f3b11a52.woff +0 -0
  64. package/dist/browser/assets/font-f36ea897e19f4a2e.ttf +0 -0
  65. package/dist/browser/assets/font-f9377ab0271cda59.ttf +0 -0
  66. package/dist/browser/carbon-nMY84Amv.js +53 -0
  67. package/dist/browser/composite-7VwgfnXx.js +6088 -0
  68. package/dist/browser/createResourceDialog-ByuJWdSL.js +439 -0
  69. package/dist/browser/dist-7oZK9QXZ.js +50088 -0
  70. package/dist/browser/dist-B9OV3YTx.js +881 -0
  71. package/dist/browser/dist-BLk5M0uK.js +1816 -0
  72. package/dist/browser/dist-BbyiRq3c.js +3285 -0
  73. package/dist/browser/dist-CIq6ue3I.js +6646 -0
  74. package/dist/browser/dist-CLZJNoWB.js +89 -0
  75. package/dist/browser/dist-CvcmLAMW.js +1620 -0
  76. package/dist/browser/dist-DL0SDskM.js +2327 -0
  77. package/dist/browser/dist-Djd02JSy.js +1247 -0
  78. package/dist/browser/dist-aWSZx4q1.js +850 -0
  79. package/dist/browser/dist-n-z5HtaO.js +4 -0
  80. package/dist/browser/dist-o4dBuwiG.js +320 -0
  81. package/dist/browser/dist-zyY--HOV.js +1543 -0
  82. package/dist/browser/esm-DXw7EADW.js +218 -0
  83. package/dist/browser/favicon.svg +7 -0
  84. package/dist/browser/flowWorkspace-DwVMpcar.js +22092 -0
  85. package/dist/browser/lib-S4ccuMeT.js +7857 -0
  86. package/dist/browser/licenses.md +4973 -0
  87. package/dist/browser/markdownContent-ZZFfSRqO.js +44545 -0
  88. package/dist/browser/project-change.d.ts +311 -0
  89. package/dist/browser/project-change.js +259 -0
  90. package/dist/browser/project-notifications.d.ts +12 -0
  91. package/dist/browser/rolldown-runtime-CEFd7nDs.js +30 -0
  92. package/dist/browser/workbench-contract.d.ts +28 -0
  93. package/dist/browser/workbench.css +2 -0
  94. package/dist/browser/workbench.css.d.ts +1 -0
  95. package/dist/browser/workbench.d.ts +14 -0
  96. package/dist/browser/workbench.js +3364 -0
  97. package/dist/common/connector-action.d.ts +20 -0
  98. package/dist/common/connector-action.js +106 -0
  99. package/dist/common/connector-proxy.d.ts +14 -0
  100. package/dist/common/connector-proxy.js +0 -0
  101. package/dist/common/control-api-conformance.d.ts +13 -0
  102. package/dist/common/control-api-conformance.js +518 -0
  103. package/dist/common/control-api-errors.d.ts +121 -0
  104. package/dist/common/control-api.d.ts +349 -0
  105. package/dist/common/control-api.js +884 -0
  106. package/dist/common/cron-trigger.d.ts +21 -0
  107. package/dist/common/cron-trigger.js +834 -0
  108. package/dist/common/engine-contract.d.ts +7 -0
  109. package/dist/common/favicon.svg +7 -0
  110. package/dist/common/integration-trigger.d.ts +111 -0
  111. package/dist/common/integration-trigger.js +290 -0
  112. package/dist/common/licenses.md +27 -0
  113. package/dist/common/poll-trigger.d.ts +69 -0
  114. package/dist/common/poll-trigger.js +155 -0
  115. package/dist/common/project-encoding.d.ts +11 -0
  116. package/dist/common/project-encoding.js +242 -0
  117. package/dist/common/project-notifications.d.ts +12 -0
  118. package/dist/common/project-semantics.d.ts +55 -0
  119. package/dist/common/project-semantics.js +8687 -0
  120. package/dist/common/provider-triggers.d.ts +6 -0
  121. package/dist/common/provider-triggers.js +4614 -0
  122. package/dist/common/run-events.d.ts +9 -0
  123. package/dist/common/run-events.js +192 -0
  124. package/dist/common/run-lifecycle.d.ts +69 -0
  125. package/dist/common/run-lifecycle.js +169 -0
  126. package/dist/common/runtime-contract.d.ts +53 -0
  127. package/dist/common/runtime-contract.js +151 -0
  128. package/dist/common/scheduler.d.ts +99 -0
  129. package/dist/common/scheduler.js +379 -0
  130. package/dist/common/webhook-trigger.d.ts +22 -0
  131. package/dist/common/webhook-trigger.js +270 -0
  132. package/dist/index.d.ts +66 -0
  133. package/package.json +102 -0
@@ -0,0 +1,9 @@
1
+ export type ProjectedRunEvent = {
2
+ readonly kind: 'node.output';
3
+ readonly payload: Readonly<Record<string, unknown>>;
4
+ readonly value: unknown;
5
+ } | {
6
+ readonly kind: 'node.artifact' | 'node.completed' | 'node.failed' | 'node.log' | 'node.progress' | 'node.started' | 'run.progress' | 'run.started';
7
+ readonly payload: Readonly<Record<string, unknown>>;
8
+ };
9
+ export declare function createEventProjector(platformRunId: string, nodeFailureCodes: ReadonlySet<string>): (event: unknown) => Promise<ProjectedRunEvent | undefined>;
@@ -0,0 +1,192 @@
1
+ //#region src/execution/common/events.ts
2
+ var e = new TextEncoder(), t = /* @__PURE__ */ new Set([
3
+ "condition",
4
+ "connector",
5
+ "javascript",
6
+ "llm",
7
+ "subflow",
8
+ "value"
9
+ ]);
10
+ function n(e, t) {
11
+ if (typeof e != "object" || !e || Array.isArray(e)) throw TypeError(`${t} must be an object.`);
12
+ return e;
13
+ }
14
+ function r(e, t) {
15
+ if (typeof e != "string" || e.length == 0) throw TypeError(`${t} must be a non-empty string.`);
16
+ return e;
17
+ }
18
+ function i(e, t) {
19
+ return e === void 0 ? void 0 : r(e, t);
20
+ }
21
+ function a(e) {
22
+ if (e !== void 0) {
23
+ if (!t.has(e)) throw TypeError("Runtime node.started nodeKind is invalid.");
24
+ return e;
25
+ }
26
+ }
27
+ function o(e) {
28
+ return r(e.runId, "Runtime event runId");
29
+ }
30
+ function s(e, t, n) {
31
+ let i = o(e), a = t.get(i);
32
+ if (a == null) throw TypeError("Runtime node event preceded its run.started event.");
33
+ return {
34
+ executionId: c("execution", n, i, r(e.jobId, "Runtime node event jobId")),
35
+ flowId: a,
36
+ nodeId: r(e.nodeId, "Runtime node event nodeId"),
37
+ rawRunId: i
38
+ };
39
+ }
40
+ async function c(t, ...n) {
41
+ let r = e.encode(JSON.stringify([
42
+ 1,
43
+ t,
44
+ ...n
45
+ ])), i = new Uint8Array(r.byteLength);
46
+ return i.set(r), `${t}_${[...new Uint8Array(await crypto.subtle.digest("SHA-256", i))].slice(0, 16).map((e) => e.toString(16).padStart(2, "0")).join("")}`;
47
+ }
48
+ function l(e) {
49
+ return r(e, "Runtime event message").replace(/Bearer\s+\S+/gi, "Bearer [REDACTED]").replace(/\b(api[-_ ]?key|authorization|password|secret|token)\s*[:=]\s*\S+/gi, "$1=[REDACTED]");
50
+ }
51
+ function u(e, t) {
52
+ let n = r(e, "Runtime node.failed code");
53
+ if (!t.has(n)) throw TypeError("Runtime node.failed code is invalid.");
54
+ return n;
55
+ }
56
+ function d(e) {
57
+ let t = n(e, "Runtime ArtifactRef");
58
+ if (Object.keys(t).some((e) => ![
59
+ "kind",
60
+ "id",
61
+ "name",
62
+ "mediaType",
63
+ "size",
64
+ "digest"
65
+ ].includes(e)) || t.kind != "artifact" || typeof t.id != "string" || t.id.length == 0 || typeof t.name != "string" || t.name.length == 0 || t.mediaType !== void 0 && (typeof t.mediaType != "string" || t.mediaType.length == 0) || typeof t.size != "number" || !Number.isSafeInteger(t.size) || t.size < 0 || typeof t.digest != "string" || !/^sha256:[0-9a-f]{64}$/.test(t.digest)) throw TypeError("Runtime ArtifactRef is invalid.");
66
+ return {
67
+ digest: t.digest,
68
+ id: t.id,
69
+ kind: "artifact",
70
+ ...t.mediaType === void 0 ? {} : { mediaType: t.mediaType },
71
+ name: t.name,
72
+ size: t.size
73
+ };
74
+ }
75
+ function f(e, t) {
76
+ let f = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
77
+ return async (h) => {
78
+ let g = n(h, "Runtime event"), _ = r(g.type, "Runtime event type");
79
+ if (_ == "run.started") {
80
+ let t = o(g), n = r(g.flowId, "Runtime run.started flowId"), i = f.get(t);
81
+ if (i != null && i != n) throw TypeError("Runtime run identity changed its flowId.");
82
+ f.set(t, n);
83
+ let a = g.parentRunId;
84
+ if (a !== void 0 && (typeof a != "string" || a.length == 0)) throw TypeError("Runtime run.started parentRunId must be a non-empty string when present.");
85
+ return {
86
+ kind: "run.started",
87
+ payload: {
88
+ flowId: n,
89
+ ...a === void 0 ? {} : { parentScopeId: await c("scope", e, a) },
90
+ scopeId: await c("scope", e, t)
91
+ }
92
+ };
93
+ }
94
+ if (_ == "run.progress") {
95
+ let t = o(g), n = f.get(t);
96
+ if (n == null) throw TypeError("Runtime run.progress event preceded its run.started event.");
97
+ if (typeof g.progress != "number" || !Number.isFinite(g.progress) || g.progress < 0 || g.progress > 100) throw TypeError("Runtime run.progress value must be between 0 and 100.");
98
+ let r = Math.floor(g.progress);
99
+ return (m.get(t) ?? -1) >= r ? void 0 : (m.set(t, r), {
100
+ kind: "run.progress",
101
+ payload: {
102
+ flowId: n,
103
+ progress: g.progress,
104
+ scopeId: await c("scope", e, t)
105
+ }
106
+ });
107
+ }
108
+ if (_ == "node.cache-hit" || _ == "node.preview" || _ == "run.completed" || _ == "run.failed" || _ == "run.output") {
109
+ o(g);
110
+ return;
111
+ }
112
+ if (_ == "node.started" || _ == "node.output" || _ == "node.progress" || _ == "node.artifact" || _ == "node.log" || _ == "node.completed" || _ == "node.failed") {
113
+ let n = s(g, f, e), o = await n.executionId, m = {
114
+ executionId: o,
115
+ flowId: n.flowId,
116
+ nodeId: n.nodeId,
117
+ scopeId: await c("scope", e, n.rawRunId)
118
+ };
119
+ switch (_) {
120
+ case "node.output": return {
121
+ kind: _,
122
+ payload: {
123
+ ...m,
124
+ handle: r(g.handle, "Runtime node.output handle")
125
+ },
126
+ value: g.value
127
+ };
128
+ case "node.started": {
129
+ let e = a(g.nodeKind), t = i(g.nodeTitle, "Runtime node.started nodeTitle"), n = i(g.operation, "Runtime node.started operation");
130
+ return {
131
+ kind: _,
132
+ payload: {
133
+ ...m,
134
+ ...e === void 0 ? {} : { nodeKind: e },
135
+ ...t === void 0 ? {} : { nodeTitle: t },
136
+ ...n === void 0 ? {} : { operation: n }
137
+ }
138
+ };
139
+ }
140
+ case "node.progress":
141
+ if (typeof g.progress != "number" || !Number.isFinite(g.progress) || g.progress < 0 || g.progress > 100) throw TypeError("Runtime node.progress value must be between 0 and 100.");
142
+ let e = Math.floor(g.progress);
143
+ return (p.get(o) ?? -1) >= e ? void 0 : (p.set(o, e), {
144
+ kind: _,
145
+ payload: {
146
+ ...m,
147
+ progress: g.progress
148
+ }
149
+ });
150
+ case "node.artifact": return {
151
+ kind: _,
152
+ payload: {
153
+ ...m,
154
+ artifact: d(g.artifact)
155
+ }
156
+ };
157
+ case "node.log":
158
+ if (![
159
+ "debug",
160
+ "info",
161
+ "warn",
162
+ "error"
163
+ ].includes(g.level)) throw TypeError("Runtime node.log level is invalid.");
164
+ return {
165
+ kind: _,
166
+ payload: {
167
+ ...m,
168
+ level: g.level,
169
+ message: l(g.message)
170
+ }
171
+ };
172
+ case "node.completed": return {
173
+ kind: _,
174
+ payload: m
175
+ };
176
+ case "node.failed": return {
177
+ kind: _,
178
+ payload: {
179
+ ...m,
180
+ error: {
181
+ code: u(g.code, t),
182
+ message: l(g.message)
183
+ }
184
+ }
185
+ };
186
+ }
187
+ }
188
+ throw TypeError(`Runtime event type ${JSON.stringify(_)} is not supported.`);
189
+ };
190
+ }
191
+ //#endregion
192
+ export { f as createEventProjector };
@@ -0,0 +1,69 @@
1
+ export declare const runTerminalStatuses: readonly ['canceled', 'completed', 'failed', 'indeterminate'];
2
+ export declare const runStatuses: readonly ["canceled", "completed", "failed", "indeterminate", "queued", "running", "starting"];
3
+ export type RunStatus = (typeof runStatuses)[number];
4
+ export type RunTerminalStatus = (typeof runTerminalStatuses)[number];
5
+ export type RunOperation = {
6
+ readonly kind: 'claim';
7
+ } | {
8
+ readonly kind: 'start';
9
+ } | {
10
+ readonly kind: 'commit';
11
+ readonly status: RunTerminalStatus;
12
+ };
13
+ export type RunTransition = {
14
+ readonly kind: 'ready';
15
+ readonly status: 'starting';
16
+ } | {
17
+ readonly kind: 'running';
18
+ readonly status: 'running';
19
+ } | {
20
+ readonly kind: 'terminal';
21
+ readonly status: RunTerminalStatus;
22
+ } | {
23
+ readonly kind: 'started';
24
+ readonly status: 'running';
25
+ } | {
26
+ readonly kind: 'already-started';
27
+ readonly status: 'running';
28
+ } | {
29
+ readonly kind: 'committed';
30
+ readonly status: RunTerminalStatus;
31
+ } | {
32
+ readonly kind: 'stale';
33
+ readonly status: RunStatus;
34
+ };
35
+ export type RunClaim = Extract<RunTransition, {
36
+ readonly kind: 'ready' | 'running' | 'terminal';
37
+ }>;
38
+ export type RunStart = Extract<RunTransition, {
39
+ readonly kind: 'already-started' | 'started' | 'stale';
40
+ }>;
41
+ export declare function isRunTerminal(status: RunStatus): status is RunTerminalStatus;
42
+ export declare function transitionRun(status: RunStatus, operation: RunOperation): RunTransition;
43
+ export type RunAcceptance = {
44
+ readonly created: boolean;
45
+ readonly kind: 'accepted';
46
+ readonly runId: string;
47
+ readonly status: RunStatus;
48
+ } | {
49
+ readonly kind: 'conflict';
50
+ };
51
+ export interface RunObservation {
52
+ readonly status: RunStatus;
53
+ readonly terminalEvents: readonly RunTerminalStatus[];
54
+ }
55
+ export interface RunLifecycleHarness {
56
+ accept(input: {
57
+ readonly idempotencyKey: string;
58
+ readonly requestDigest: string;
59
+ }): Promise<RunAcceptance>;
60
+ claim(runId: string): Promise<RunClaim>;
61
+ commit(runId: string, status: RunTerminalStatus): Promise<boolean>;
62
+ observe(runId: string): Promise<RunObservation>;
63
+ start(runId: string): Promise<RunStart>;
64
+ }
65
+ export interface RunLifecycleConformanceCase {
66
+ readonly name: string;
67
+ verify(harness: RunLifecycleHarness): Promise<void>;
68
+ }
69
+ export declare const runLifecycleConformanceCases: readonly RunLifecycleConformanceCase[];
@@ -0,0 +1,169 @@
1
+ //#region ../../node_modules/dequal/lite/index.mjs
2
+ var e = Object.prototype.hasOwnProperty;
3
+ function t(n, r) {
4
+ var i, a;
5
+ if (n === r) return !0;
6
+ if (n && r && (i = n.constructor) === r.constructor) {
7
+ if (i === Date) return n.getTime() === r.getTime();
8
+ if (i === RegExp) return n.toString() === r.toString();
9
+ if (i === Array) {
10
+ if ((a = n.length) === r.length) for (; a-- && t(n[a], r[a]););
11
+ return a === -1;
12
+ }
13
+ if (!i || typeof n == "object") {
14
+ for (i in a = 0, n) if (e.call(n, i) && ++a && !e.call(r, i) || !(i in r) || !t(n[i], r[i])) return !1;
15
+ return Object.keys(r).length === a;
16
+ }
17
+ }
18
+ return n !== n && r !== r;
19
+ }
20
+ //#endregion
21
+ //#region src/execution/common/runLifecycle.ts
22
+ var n = [
23
+ "canceled",
24
+ "completed",
25
+ "failed",
26
+ "indeterminate"
27
+ ], r = [
28
+ ...n,
29
+ "queued",
30
+ "running",
31
+ "starting"
32
+ ];
33
+ function i(e) {
34
+ return e == "canceled" || e == "completed" || e == "failed" || e == "indeterminate";
35
+ }
36
+ function a(e, t) {
37
+ switch (t.kind) {
38
+ case "claim": switch (e) {
39
+ case "queued":
40
+ case "starting": return {
41
+ kind: "ready",
42
+ status: "starting"
43
+ };
44
+ case "running": return {
45
+ kind: "running",
46
+ status: e
47
+ };
48
+ case "canceled":
49
+ case "completed":
50
+ case "failed":
51
+ case "indeterminate": return {
52
+ kind: "terminal",
53
+ status: e
54
+ };
55
+ }
56
+ case "start": switch (e) {
57
+ case "starting": return {
58
+ kind: "started",
59
+ status: "running"
60
+ };
61
+ case "running": return {
62
+ kind: "already-started",
63
+ status: e
64
+ };
65
+ case "queued":
66
+ case "canceled":
67
+ case "completed":
68
+ case "failed":
69
+ case "indeterminate": return {
70
+ kind: "stale",
71
+ status: e
72
+ };
73
+ }
74
+ case "commit": return i(e) ? {
75
+ kind: "stale",
76
+ status: e
77
+ } : t.status == "canceled" || e == "running" ? {
78
+ kind: "committed",
79
+ status: t.status
80
+ } : {
81
+ kind: "stale",
82
+ status: e
83
+ };
84
+ }
85
+ }
86
+ function o(e, n, r) {
87
+ if (!t(e, n)) throw Error(`${r}: expected ${JSON.stringify(n)}, received ${JSON.stringify(e)}.`);
88
+ }
89
+ async function s(e, t = "request", n = "request-a") {
90
+ let r = await e.accept({
91
+ idempotencyKey: t,
92
+ requestDigest: n
93
+ });
94
+ if (r.kind != "accepted") throw Error("Run acceptance unexpectedly conflicted.");
95
+ return r.runId;
96
+ }
97
+ var c = [
98
+ {
99
+ name: "replays idempotent acceptance and rejects a conflicting request",
100
+ async verify(e) {
101
+ let t = await e.accept({
102
+ idempotencyKey: "same-key",
103
+ requestDigest: "request-a"
104
+ });
105
+ if (t.kind != "accepted") throw Error("Initial Run acceptance unexpectedly conflicted.");
106
+ o(t.created, !0, "Initial acceptance creation"), o(t.status, "queued", "Initial acceptance status"), o(await e.accept({
107
+ idempotencyKey: "same-key",
108
+ requestDigest: "request-a"
109
+ }), {
110
+ ...t,
111
+ created: !1
112
+ }, "Idempotent replay"), o(await e.accept({
113
+ idempotencyKey: "same-key",
114
+ requestDigest: "request-b"
115
+ }), { kind: "conflict" }, "Conflicting replay"), o(await e.observe(t.runId), {
116
+ status: "queued",
117
+ terminalEvents: []
118
+ }, "Accepted Run observation");
119
+ }
120
+ },
121
+ {
122
+ name: "cancels before the start barrier and preserves one terminal",
123
+ async verify(e) {
124
+ let t = await s(e);
125
+ o(await e.commit(t, "canceled"), !0, "Cancellation commit"), o(await e.claim(t), a("canceled", { kind: "claim" }), "Claim after cancellation"), o(await e.commit(t, "completed"), !1, "Completion after cancellation"), o(await e.observe(t), {
126
+ status: "canceled",
127
+ terminalEvents: ["canceled"]
128
+ }, "Canceled Run observation");
129
+ }
130
+ },
131
+ {
132
+ name: "recovers before the start barrier without creating another Run",
133
+ async verify(e) {
134
+ let t = await s(e), n = a("queued", { kind: "claim" });
135
+ o(await e.claim(t), n, "Initial claim");
136
+ let r = a(n.status, { kind: "claim" });
137
+ o(await e.claim(t), r, "Recovered claim");
138
+ let i = a(r.status, { kind: "start" });
139
+ o(await e.start(t), i, "Start after recovery"), o(await e.commit(t, "completed"), !0, "Completion after recovery"), o(await e.observe(t), {
140
+ status: "completed",
141
+ terminalEvents: ["completed"]
142
+ }, "Recovered Run observation");
143
+ }
144
+ },
145
+ {
146
+ name: "marks recovery after the start barrier indeterminate",
147
+ async verify(e) {
148
+ let t = await s(e), n = a("queued", { kind: "claim" });
149
+ o(await e.claim(t), n, "Initial claim");
150
+ let r = a(n.status, { kind: "start" });
151
+ o(await e.start(t), r, "Start barrier"), o(await e.claim(t), a(r.status, { kind: "claim" }), "Claim after start barrier"), o(await e.commit(t, "indeterminate"), !0, "Indeterminate commit"), o(await e.commit(t, "completed"), !1, "Completion after indeterminate"), o(await e.observe(t), {
152
+ status: "indeterminate",
153
+ terminalEvents: ["indeterminate"]
154
+ }, "Indeterminate Run observation");
155
+ }
156
+ },
157
+ {
158
+ name: "allows exactly one terminal to win cancellation and completion",
159
+ async verify(e) {
160
+ let t = await s(e), n = a("queued", { kind: "claim" });
161
+ o(await e.claim(t), n, "Initial claim"), o(await e.start(t), a(n.status, { kind: "start" }), "Start barrier"), o((await Promise.all([e.commit(t, "canceled"), e.commit(t, "completed")])).filter(Boolean).length, 1, "Accepted terminal count");
162
+ let r = await e.observe(t);
163
+ if (r.status != "canceled" && r.status != "completed") throw Error(`Terminal race produced ${r.status}.`);
164
+ o(r.terminalEvents, [r.status], "Terminal race events");
165
+ }
166
+ }
167
+ ];
168
+ //#endregion
169
+ export { i as isRunTerminal, c as runLifecycleConformanceCases, r as runStatuses, n as runTerminalStatuses, a as transitionRun };
@@ -0,0 +1,53 @@
1
+ import type { CodeModule, JsonValue } from '../browser/project-change.js';
2
+ export { currentEngineContract, findEngineContract, type EngineContract } from './engine-contract.js';
3
+ export type RuntimeModule = Pick<CodeModule, 'imports' | 'source'>;
4
+ export interface RuntimeProgram {
5
+ readonly engineContract: string;
6
+ readonly engineDigest: string;
7
+ readonly entryModuleId: string;
8
+ readonly modules: Readonly<Record<string, RuntimeModule>>;
9
+ }
10
+ export interface RuntimeCapabilityCall {
11
+ readonly invocationId: string;
12
+ readonly kind: string;
13
+ readonly payload: JsonValue;
14
+ readonly signal: AbortSignal;
15
+ }
16
+ export interface RuntimeCapabilityResponse {
17
+ readonly body: JsonValue;
18
+ readonly status: number;
19
+ }
20
+ export interface LlmTaskInvocation {
21
+ readonly input: Readonly<Record<string, JsonValue>>;
22
+ readonly invocationId: string;
23
+ readonly mode: 'chat' | 'json';
24
+ readonly signal: AbortSignal;
25
+ readonly version: 1;
26
+ }
27
+ export type LlmTaskResult = {
28
+ readonly kind: 'completed';
29
+ readonly value: JsonValue;
30
+ readonly version: 1;
31
+ } | {
32
+ readonly code: 'llm.output-invalid' | 'llm.unavailable';
33
+ readonly kind: 'failed';
34
+ readonly message: string;
35
+ readonly version: 1;
36
+ };
37
+ export type InvokeLlmTask = (invocation: LlmTaskInvocation) => Promise<LlmTaskResult>;
38
+ export interface RuntimeInvocation {
39
+ readonly capability: (call: RuntimeCapabilityCall) => Promise<RuntimeCapabilityResponse>;
40
+ readonly input: JsonValue;
41
+ readonly invocationId: string;
42
+ readonly program: RuntimeProgram;
43
+ readonly signal?: AbortSignal;
44
+ }
45
+ export interface RuntimeHarness {
46
+ readonly engineDigest: string;
47
+ invoke(invocation: RuntimeInvocation): Promise<JsonValue>;
48
+ }
49
+ export interface RuntimeConformanceCase {
50
+ readonly name: string;
51
+ verify(harness: RuntimeHarness): Promise<void>;
52
+ }
53
+ export declare const runtimeConformanceCases: readonly RuntimeConformanceCase[];
@@ -0,0 +1,151 @@
1
+ //#region ../../node_modules/dequal/lite/index.mjs
2
+ var e = Object.prototype.hasOwnProperty;
3
+ function t(n, r) {
4
+ var i, a;
5
+ if (n === r) return !0;
6
+ if (n && r && (i = n.constructor) === r.constructor) {
7
+ if (i === Date) return n.getTime() === r.getTime();
8
+ if (i === RegExp) return n.toString() === r.toString();
9
+ if (i === Array) {
10
+ if ((a = n.length) === r.length) for (; a-- && t(n[a], r[a]););
11
+ return a === -1;
12
+ }
13
+ if (!i || typeof n == "object") {
14
+ for (i in a = 0, n) if (e.call(n, i) && ++a && !e.call(r, i) || !(i in r) || !t(n[i], r[i])) return !1;
15
+ return Object.keys(r).length === a;
16
+ }
17
+ }
18
+ return n !== n && r !== r;
19
+ }
20
+ //#endregion
21
+ //#region src/execution/common/engineContract.ts
22
+ var n = "open-flow-engine/v1", r = {
23
+ platformExports: /* @__PURE__ */ new Set(["engineContract", "identity"]),
24
+ platformModule: "open-flow:platform",
25
+ platformSource: `export const engineContract = ${JSON.stringify(n)}
26
+ export function identity(value) { return value }
27
+ `
28
+ };
29
+ function i(e) {
30
+ return e == "open-flow-engine/v1" ? r : void 0;
31
+ }
32
+ //#endregion
33
+ //#region src/execution/common/runtime.ts
34
+ function a(e, t, r = {}) {
35
+ return {
36
+ engineContract: n,
37
+ engineDigest: e.engineDigest,
38
+ entryModuleId: "main",
39
+ modules: {
40
+ ...r,
41
+ main: {
42
+ imports: Object.keys(r),
43
+ source: t
44
+ }
45
+ }
46
+ };
47
+ }
48
+ function o(e, n, r) {
49
+ if (!t(e, n)) throw Error(`${r}: expected ${JSON.stringify(n)}, received ${JSON.stringify(e)}.`);
50
+ }
51
+ async function s(e, t, n) {
52
+ try {
53
+ await e;
54
+ } catch (e) {
55
+ if (t.test(e instanceof Error ? e.message : String(e))) return;
56
+ throw Error(`${n}: received ${e instanceof Error ? e.message : String(e)}.`, { cause: e });
57
+ }
58
+ throw Error(`${n}: operation unexpectedly succeeded.`);
59
+ }
60
+ var c = [
61
+ {
62
+ name: "loads the fixed ESM closure and platform module",
63
+ async verify(e) {
64
+ o(await e.invoke({
65
+ capability: async () => {
66
+ throw Error("Capability must not be called.");
67
+ },
68
+ input: { value: 6 },
69
+ invocationId: "module-closure",
70
+ program: a(e, "import { double } from './helper.mjs'\nimport { engineContract, identity } from 'open-flow:platform'\nexport default (input) => ({ engineContract, value: identity(double(input.value)) })", { helper: {
71
+ imports: [],
72
+ source: "export const double = (value) => value * 2"
73
+ } })
74
+ }), {
75
+ engineContract: n,
76
+ value: 12
77
+ }, "ESM closure result");
78
+ }
79
+ },
80
+ {
81
+ name: "rejects modules outside the fixed closure",
82
+ async verify(e) {
83
+ await s(e.invoke({
84
+ capability: async () => ({
85
+ body: null,
86
+ status: 200
87
+ }),
88
+ input: null,
89
+ invocationId: "closed-linker",
90
+ program: a(e, "import fs from 'node:fs'\nexport default () => fs.readFileSync('/etc/passwd', 'utf8')")
91
+ }), /invalid|unsupported|cannot import|not part of/i, "Closed linker");
92
+ }
93
+ },
94
+ {
95
+ name: "copies asynchronous Capability requests and responses",
96
+ async verify(e) {
97
+ let t = [];
98
+ o(await e.invoke({
99
+ capability: async (e) => (t.push(e), {
100
+ body: {
101
+ accepted: !0,
102
+ echoed: e.payload
103
+ },
104
+ status: 200
105
+ }),
106
+ input: { issue: 42 },
107
+ invocationId: "async-capability",
108
+ program: a(e, "export default async (input, capability) => capability.connector({ action: 'read', input })")
109
+ }), {
110
+ body: {
111
+ accepted: !0,
112
+ echoed: {
113
+ action: "read",
114
+ input: { issue: 42 }
115
+ }
116
+ },
117
+ status: 200
118
+ }, "Capability result"), o(t.map(({ invocationId: e, kind: t, payload: n }) => ({
119
+ invocationId: e,
120
+ kind: t,
121
+ payload: n
122
+ })), [{
123
+ invocationId: "async-capability",
124
+ kind: "connector",
125
+ payload: {
126
+ action: "read",
127
+ input: { issue: 42 }
128
+ }
129
+ }], "Capability request");
130
+ }
131
+ },
132
+ {
133
+ name: "cancels a pending Capability and the user invocation",
134
+ async verify(e) {
135
+ let t = new AbortController(), n = !1, r, i = new Promise((e) => {
136
+ r = e;
137
+ }), c = e.invoke({
138
+ capability: async ({ signal: e }) => (r(), await new Promise((t, r) => e.addEventListener("abort", () => {
139
+ n = !0, r(e.reason);
140
+ }, { once: !0 }))),
141
+ input: null,
142
+ invocationId: "canceled-capability",
143
+ program: a(e, "export default async (_input, capability) => capability.connector({ action: 'wait' })"),
144
+ signal: t.signal
145
+ });
146
+ await i, t.abort(/* @__PURE__ */ Error("Invocation canceled.")), await s(c, /cancel|abort|disposed/i, "Canceled invocation"), o(n, !0, "Capability cancellation");
147
+ }
148
+ }
149
+ ];
150
+ //#endregion
151
+ export { n as currentEngineContract, i as findEngineContract, c as runtimeConformanceCases };