@w6w/embed 0.2.31 → 0.2.32

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.
@@ -0,0 +1,1169 @@
1
+ import { jsxs as y, jsx as a, Fragment as G } from "react/jsx-runtime";
2
+ import { useQueryClient as Dt, useQueries as Te } from "@tanstack/react-query";
3
+ import { ApiError as je } from "@w6w/sdk";
4
+ import { Modal as wn, IconButton as ce, JsonEditor as Sn, useExpressionOptions as kn, ExpressionEditorModal as Nn, useW6WApi as Jt, W6WUIProvider as Rn, isTestRequired as Ot, requiredParamsFilled as En, ExecutionLogDock as Cn, ExecutionLogView as An, testInputSavesSettled as Pn, StepStatusPill as On, formatDurationMs as Tn } from "@w6w/ui";
5
+ import { useState as v, useMemo as w, createElement as D, useId as jn, useCallback as E, useContext as In, useRef as S, useEffect as A, Suspense as Ln, lazy as Fn } from "react";
6
+ import { E as Mn, $ as Dn, W as Jn, Q as Wn, V as $n, q as xn, X as Bn, v as Kn, B as Qn, A as _n, N as qn, a as Vn, z as Hn, n as zn, y as Gn, t as Yn, b as Un } from "./workflows-Dz8LMjnt.js";
7
+ import { H as Xn, a as Zn } from "./editor-apps-HEOclsxL.js";
8
+ import { M as ue } from "./ConfirmModal-WqBfWftD.js";
9
+ import { d as es, W as ts, e as ns, R as ss, P as os, b as is, c as rs } from "./editor-tools-Dn7TgCP4.js";
10
+ import { u as as } from "./client-context-CX61Bgw-.js";
11
+ import { u as ls } from "./use-workflow-draft-l3P5KZzw.js";
12
+ import { r as cs, h as us, e as ds, f as fs, a as ps, d as hs, b as ms, p as gs, i as bs, g as ys } from "./setup-incomplete-BHs3Lpfy.js";
13
+ import { g as Tt, r as vs, c as ws, v as Ss } from "./document-sources-Khcw2zB5.js";
14
+ import { n as jt } from "./import-bindings-EUtxZ9Ti.js";
15
+ import { p as ks, d as Ns } from "./settings-rail-gUU2ZbSw.js";
16
+ import { u as Rs, b as Es } from "./project-context-Tvp-La7A.js";
17
+ import { i as Cs, d as It } from "./connections-CzsCyIxY.js";
18
+ import { r as As, m as Ps, q as Os, n as Ts, o as js } from "./spec-import-CGPqUUjN.js";
19
+ import { l as Lt, a as Ie, w as Is } from "./step-tests-B4E4W3ly.js";
20
+ import { u as Ls } from "./spec-export-BtnoV0ex.js";
21
+ import { i as Fs, f as Ms } from "./vault-BSEWhMYC.js";
22
+ import { i as Ds } from "./data-stores-UeQvwVCa.js";
23
+ import { e as Js } from "./apps-FMcQfyL2.js";
24
+ import { E as Ws } from "./theme-context-E2ZhlXDX.js";
25
+ import { validateInitialState as $s } from "@w6w/expr";
26
+ function xs({ title: n }) {
27
+ const { value: e, placeholder: o, maxLength: s, ariaLabel: r, onChange: l, onBlur: u } = n;
28
+ return /* @__PURE__ */ a(
29
+ "input",
30
+ {
31
+ className: "wf-title-input",
32
+ value: e,
33
+ placeholder: o,
34
+ maxLength: s,
35
+ size: Math.min(Math.max(e.length, o.length), 80),
36
+ "aria-label": r,
37
+ onChange: (d) => l(d.target.value),
38
+ onBlur: u
39
+ }
40
+ );
41
+ }
42
+ function Bs({
43
+ onBack: n,
44
+ backLabel: e,
45
+ title: o,
46
+ titleAdornment: s,
47
+ actions: r
48
+ }) {
49
+ return /* @__PURE__ */ y("div", { className: "wf-fullbleed-head", children: [
50
+ e !== null && /* @__PURE__ */ a(
51
+ "button",
52
+ {
53
+ type: "button",
54
+ className: "muted wf-back-btn",
55
+ "data-testid": "wf-editor-back",
56
+ onClick: n,
57
+ children: e
58
+ }
59
+ ),
60
+ o.editable ? /* @__PURE__ */ a(xs, { title: o }) : /* @__PURE__ */ y("h2", { className: "exec-profile-title", children: [
61
+ o.value,
62
+ " ",
63
+ s
64
+ ] }),
65
+ /* @__PURE__ */ y("div", { className: "wf-head-actions", style: { marginLeft: "auto" }, children: [
66
+ o.editable && s,
67
+ r
68
+ ] })
69
+ ] });
70
+ }
71
+ function Ks(n, e, o) {
72
+ if (!(n !== "workflow" || e === void 0))
73
+ return (s) => {
74
+ o(), e(s.id);
75
+ };
76
+ }
77
+ function Qs(n) {
78
+ const { kind: e, id: o, onClose: s, onOpenRun: r } = n, [l, u] = v(Mn), d = Ks(e, r, s);
79
+ return /* @__PURE__ */ a(
80
+ wn,
81
+ {
82
+ size: "full",
83
+ title: "History",
84
+ subtitle: o,
85
+ onClose: s,
86
+ headerRight: /* @__PURE__ */ a(ce, { icon: "close", label: "Close", onClick: s }),
87
+ children: /* @__PURE__ */ a("div", { className: "w6w-modal-body", children: /* @__PURE__ */ a(
88
+ Xn,
89
+ {
90
+ scope: { callable: o },
91
+ showKind: !1,
92
+ filters: l,
93
+ onFiltersChange: u,
94
+ onOpenInEditor: d
95
+ }
96
+ ) })
97
+ }
98
+ );
99
+ }
100
+ function _s(n) {
101
+ return /* @__PURE__ */ a(ce, { icon: "json", onClick: n.onClick, label: "Edit raw JSON definition" });
102
+ }
103
+ function qs(n) {
104
+ return n.open ? n.mode === "apply" ? /* @__PURE__ */ a(Vs, { ...n }) : /* @__PURE__ */ a(Hs, { ...n }) : null;
105
+ }
106
+ function Wt(n) {
107
+ return /* @__PURE__ */ a("div", { className: "json-toggle-editor", children: /* @__PURE__ */ a(
108
+ Sn,
109
+ {
110
+ value: n.value,
111
+ onChange: n.onChange,
112
+ minHeight: "120px",
113
+ "aria-label": n.label
114
+ }
115
+ ) });
116
+ }
117
+ function Vs(n) {
118
+ const { onClose: e, title: o, value: s, prepareApply: r, onApply: l, editorLabel: u } = n, [d, m] = v(s), [h, g] = v(s), [j, Y] = v([]), [fe, I] = v(!1), P = w(
119
+ () => (r == null ? void 0 : r(d)) ?? { ok: !0, text: d, restored: [] },
120
+ [r, d]
121
+ ), J = d !== h, U = () => J ? I(!0) : e(), X = () => {
122
+ !P.ok || !J || (l == null || l(P.text), m(P.text), g(P.text), Y(P.restored), I(!1));
123
+ };
124
+ return /* @__PURE__ */ y(ue, { title: o, onClose: U, wide: !0, className: "modal-json", children: [
125
+ /* @__PURE__ */ y("div", { className: "modal-body", children: [
126
+ /* @__PURE__ */ y("p", { className: "muted small", children: [
127
+ "Edit the raw definition (",
128
+ /* @__PURE__ */ a("code", { children: 'manifestVersion: "2"' }),
129
+ "). Apply updates the visual editor; Save stores it."
130
+ ] }),
131
+ /* @__PURE__ */ a(
132
+ Wt,
133
+ {
134
+ value: d,
135
+ onChange: (Z) => {
136
+ m(Z), I(!1);
137
+ },
138
+ label: u
139
+ }
140
+ ),
141
+ !P.ok && /* @__PURE__ */ a("p", { className: "error small", role: "alert", "data-testid": "json-toggle-error", children: P.error }),
142
+ j.length > 0 && /* @__PURE__ */ y("p", { className: "muted small", "data-testid": "json-toggle-restored", children: [
143
+ "Restored ",
144
+ j.join(", "),
145
+ ": ",
146
+ j.length > 1 ? "these fields" : "this field",
147
+ " ",
148
+ "can't be changed in JSON."
149
+ ] })
150
+ ] }),
151
+ /* @__PURE__ */ a("div", { className: "modal-actions", children: fe ? /* @__PURE__ */ y(G, { children: [
152
+ /* @__PURE__ */ a("span", { className: "muted small json-toggle-confirm", children: "Discard unapplied changes?" }),
153
+ /* @__PURE__ */ a("button", { type: "button", className: "btn ghost", onClick: () => I(!1), children: "Keep editing" }),
154
+ /* @__PURE__ */ a(
155
+ "button",
156
+ {
157
+ type: "button",
158
+ className: "btn danger",
159
+ "data-testid": "json-toggle-discard",
160
+ onClick: e,
161
+ children: "Discard"
162
+ }
163
+ )
164
+ ] }) : /* @__PURE__ */ y(G, { children: [
165
+ /* @__PURE__ */ a(
166
+ "button",
167
+ {
168
+ type: "button",
169
+ className: "btn ghost",
170
+ "data-testid": "json-toggle-close",
171
+ onClick: U,
172
+ children: "Close"
173
+ }
174
+ ),
175
+ /* @__PURE__ */ a(
176
+ "button",
177
+ {
178
+ type: "button",
179
+ className: "btn",
180
+ "data-testid": "json-toggle-apply",
181
+ disabled: !P.ok || !J,
182
+ onClick: X,
183
+ children: "Apply"
184
+ }
185
+ )
186
+ ] }) })
187
+ ] });
188
+ }
189
+ function Hs(n) {
190
+ const { onClose: e, title: o, value: s, onChange: r, guard: l, onSave: u, saving: d, error: m, editorLabel: h } = n, g = (l == null ? void 0 : l(s)) ?? null;
191
+ return /* @__PURE__ */ y(ue, { title: o, onClose: e, wide: !0, className: "modal-json", children: [
192
+ /* @__PURE__ */ y("div", { className: "modal-body", children: [
193
+ /* @__PURE__ */ a("p", { className: "muted small", children: "Save replaces the stored definition." }),
194
+ /* @__PURE__ */ a(Wt, { value: s, onChange: (j) => r == null ? void 0 : r(j), label: h }),
195
+ g && /* @__PURE__ */ a("p", { className: "muted small", "data-testid": "json-toggle-reason", children: g }),
196
+ m && /* @__PURE__ */ a("div", { className: "error", children: m })
197
+ ] }),
198
+ /* @__PURE__ */ y("div", { className: "modal-actions", children: [
199
+ /* @__PURE__ */ a("button", { type: "button", className: "btn ghost", onClick: e, children: "Cancel" }),
200
+ /* @__PURE__ */ a(
201
+ "button",
202
+ {
203
+ type: "button",
204
+ className: "btn",
205
+ "data-testid": "json-toggle-save",
206
+ disabled: g != null || !!d,
207
+ onClick: u,
208
+ children: d ? "Saving…" : "Save"
209
+ }
210
+ )
211
+ ] })
212
+ ] });
213
+ }
214
+ function Ft(n, e, o = {}) {
215
+ const s = (l) => Array.isArray(l) ? l.map(s) : l !== null && typeof l == "object" ? Object.fromEntries(
216
+ Object.entries(l).sort(([u], [d]) => u.localeCompare(d)).map(([u, d]) => [u, s(d)])
217
+ ) : l, r = (l) => {
218
+ if (!de(l)) return l;
219
+ const { status: u, ...d } = l, m = { ...d, key: d.key ?? null, tags: d.tags ?? [] };
220
+ return o.presentation ? m : zs(m);
221
+ };
222
+ return JSON.stringify(s(r(n))) === JSON.stringify(s(r(e)));
223
+ }
224
+ const de = (n) => n !== null && typeof n == "object" && !Array.isArray(n), $t = (n, e) => {
225
+ if (!de(n)) return n;
226
+ const o = { ...n };
227
+ for (const s of e) delete o[s];
228
+ return o;
229
+ }, Mt = (n, e) => Array.isArray(n) ? n.map((o) => $t(o, e)) : n;
230
+ function zs(n) {
231
+ const e = { ...n };
232
+ for (const o of ["nodes", "steps"])
233
+ o in e && (e[o] = Mt(e[o], ["position"]));
234
+ if (de(e.settings)) {
235
+ const o = $t(e.settings, ["viewport", "autoSave", "savePosition"]);
236
+ e.settings = Object.keys(o).length === 0 ? void 0 : o;
237
+ }
238
+ if (de(e.canvas)) {
239
+ const o = { ...e.canvas };
240
+ for (const s of ["notes", "sections"])
241
+ s in o && (o[s] = Mt(o[s], ["position", "size"]));
242
+ e.canvas = o;
243
+ }
244
+ return e;
245
+ }
246
+ function Gs(n) {
247
+ const { kind: e, problemCount: o, canEnable: s, onEnable: r, pending: l } = n, u = o > 0 ? `This ${e} is disabled and ${o} ${o === 1 ? "step uses" : "steps use"} a connection that no longer exists. Choose another connection, save, then Enable.` : "Connections fixed. Enable to run again.";
248
+ return D(
249
+ "div",
250
+ { role: "alert", className: "error", "data-testid": "binding-disabled-banner" },
251
+ D("span", null, u),
252
+ " ",
253
+ D(
254
+ "button",
255
+ {
256
+ type: "button",
257
+ "data-testid": "binding-enable",
258
+ disabled: !s || l === !0,
259
+ onClick: r
260
+ },
261
+ "Enable"
262
+ )
263
+ );
264
+ }
265
+ function Ys({
266
+ project: n,
267
+ onNavigate: e,
268
+ rail: o = !0,
269
+ storageKey: s,
270
+ tools: r = ns,
271
+ children: l
272
+ }) {
273
+ const u = es(), d = /* @__PURE__ */ a(ss, { project: n, onNavigate: e, children: /* @__PURE__ */ y(os, { project: n, children: [
274
+ l,
275
+ o && /* @__PURE__ */ a(is, { tools: r, storageKey: s })
276
+ ] }) });
277
+ return o || !u ? /* @__PURE__ */ a(ts, { children: d }) : d;
278
+ }
279
+ function Us({
280
+ message: n,
281
+ disabled: e = !1,
282
+ children: o
283
+ }) {
284
+ const s = jn(), [r, l] = v(!1);
285
+ return /* @__PURE__ */ y(
286
+ "fieldset",
287
+ {
288
+ className: "wf-publish-tooltip",
289
+ "aria-label": "Publish workflow",
290
+ "aria-describedby": s,
291
+ tabIndex: e ? 0 : void 0,
292
+ onMouseEnter: () => l(!0),
293
+ onMouseLeave: () => l(!1),
294
+ onFocus: () => l(!0),
295
+ onBlur: (u) => {
296
+ u.currentTarget.contains(u.relatedTarget) || l(!1);
297
+ },
298
+ onKeyDown: (u) => {
299
+ u.key === "Escape" && l(!1);
300
+ },
301
+ children: [
302
+ o(s),
303
+ r && /* @__PURE__ */ a("span", { id: s, role: "tooltip", className: "wf-publish-hint", children: n })
304
+ ]
305
+ }
306
+ );
307
+ }
308
+ function Xs(n) {
309
+ const { problems: e, nodeLabel: o } = n, s = Object.entries(e).filter(([, l]) => l.length > 0);
310
+ if (s.length === 0) return null;
311
+ const r = s.length;
312
+ return D(
313
+ "div",
314
+ { role: "status", className: "error", "data-testid": "setup-incomplete-banner" },
315
+ D(
316
+ "span",
317
+ null,
318
+ `Setup incomplete: ${r} ${r === 1 ? "step needs" : "steps need"} attention. The workflow can still run.`
319
+ ),
320
+ D(
321
+ "ul",
322
+ { "data-testid": "setup-incomplete-list" },
323
+ ...s.map(
324
+ ([l, u]) => D("li", { key: l }, `${o ? o(l) : l}: ${u.join(", ")}`)
325
+ )
326
+ )
327
+ );
328
+ }
329
+ const Zs = {
330
+ invalid_json: "This isn't valid JSON yet, so it isn't saved. Fix it to save.",
331
+ not_object: 'Starting state must be a JSON object, like {"region": "us"}. Not saved.',
332
+ too_large: "Starting state is over the 64 KiB limit. Not saved."
333
+ };
334
+ function eo(n) {
335
+ const e = kn();
336
+ return /* @__PURE__ */ a(
337
+ Nn,
338
+ {
339
+ mode: "json-binding",
340
+ startingState: !0,
341
+ title: "Starting state",
342
+ fieldLabel: "initialState",
343
+ value: void 0,
344
+ options: e,
345
+ jsonValue: n.initialState,
346
+ jsonProblem: (o) => {
347
+ const s = Tt(o);
348
+ if (!s.ok) return Zs[s.reason];
349
+ const r = s.value === void 0 ? void 0 : $s(s.value)[0];
350
+ return r ? `${r.message} Not saved.` : null;
351
+ },
352
+ onSaveJson: (o) => {
353
+ const s = Tt(o === void 0 ? "" : JSON.stringify(o));
354
+ s.ok && n.onChange(s.value);
355
+ },
356
+ onClose: n.onClose
357
+ }
358
+ );
359
+ }
360
+ const xt = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/, to = "Untitled workflow", no = ["id", "key", "manifestVersion"];
361
+ function so(n) {
362
+ let e = 0;
363
+ const o = () => {
364
+ for (; e < n.length && `
365
+ \r`.includes(n[e]); ) e++;
366
+ }, s = () => {
367
+ throw e;
368
+ }, r = (h) => {
369
+ for (const g of h)
370
+ n[e] !== g && s(), e++;
371
+ }, l = () => {
372
+ for (e++; n[e] !== '"'; ) {
373
+ const h = n[e];
374
+ if ((h === void 0 || h < " ") && s(), h === "\\")
375
+ if (e++, n[e] === "u")
376
+ for (let g = 0; g < 4; g++)
377
+ e++, /[0-9a-fA-F]/.test(n[e] ?? "") || s();
378
+ else '"\\/bfnrt'.includes(n[e] ?? "x") || s();
379
+ e++;
380
+ }
381
+ e++;
382
+ }, u = /-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/y, d = () => {
383
+ u.lastIndex = e, u.test(n) || s(), e = u.lastIndex;
384
+ }, m = () => {
385
+ o();
386
+ const h = n[e];
387
+ if (h === "{" || h === "[") {
388
+ const g = h === "{" ? "}" : "]";
389
+ if (e++, o(), n[e] === g) {
390
+ e++;
391
+ return;
392
+ }
393
+ for (; ; )
394
+ if (g === "}" && (o(), n[e] !== '"' && s(), l(), o(), n[e] !== ":" && s(), e++), m(), o(), n[e] === ",") e++;
395
+ else if (n[e] === g) {
396
+ e++;
397
+ return;
398
+ } else s();
399
+ }
400
+ h === '"' ? l() : h === "t" ? r("true") : h === "f" ? r("false") : h === "n" ? r("null") : d();
401
+ };
402
+ try {
403
+ return m(), o(), e < n.length ? e : null;
404
+ } catch (h) {
405
+ return typeof h == "number" ? Math.min(h, n.length) : 0;
406
+ }
407
+ }
408
+ function oo(n, e) {
409
+ const o = e instanceof Error ? e.message : String(e), s = so(n);
410
+ if (s === null) return o;
411
+ const r = n.slice(0, s), l = r.split(`
412
+ `).length, u = s - r.lastIndexOf(`
413
+ `);
414
+ return `Line ${l}, column ${u}: ${o}`;
415
+ }
416
+ const le = (n) => typeof n == "object" && n !== null && !Array.isArray(n);
417
+ function io(n) {
418
+ if (typeof n.name != "string" || n.name.length === 0) return "`name` is required.";
419
+ const e = n.nodes ?? n.steps;
420
+ if (!Array.isArray(e)) return "`nodes` must be an array.";
421
+ const o = /* @__PURE__ */ new Set();
422
+ for (let s = 0; s < e.length; s++) {
423
+ const r = e[s];
424
+ if (!le(r)) return `\`nodes[${s}]\` must be an object.`;
425
+ if (typeof r.id != "string" || r.id.length === 0)
426
+ return `\`nodes[${s}].id\` must be a non-empty string.`;
427
+ if (r.id.includes(".")) return `Node id "${r.id}" may not contain ".".`;
428
+ if (o.has(r.id)) return `Node id "${r.id}" is used twice.`;
429
+ o.add(r.id);
430
+ const l = r.position;
431
+ if (l !== void 0 && (!le(l) || !Number.isFinite(l.x) || !Number.isFinite(l.y)))
432
+ return `\`nodes[${s}].position\` must be { "x": number, "y": number }.`;
433
+ }
434
+ if (n.edges !== void 0) {
435
+ if (!Array.isArray(n.edges)) return "`edges` must be an array.";
436
+ for (let s = 0; s < n.edges.length; s++) {
437
+ const r = n.edges[s];
438
+ if (!le(r)) return `\`edges[${s}]\` must be an object.`;
439
+ for (const l of ["from", "to"])
440
+ if (typeof r[l] != "string" || !o.has(r[l]))
441
+ return `\`edges[${s}].${l}\` does not name an existing node.`;
442
+ }
443
+ }
444
+ return null;
445
+ }
446
+ function ro(n, e) {
447
+ let o;
448
+ try {
449
+ o = JSON.parse(n);
450
+ } catch (d) {
451
+ return { ok: !1, error: oo(n, d) };
452
+ }
453
+ if (!le(o)) return { ok: !1, error: "The definition must be a JSON object." };
454
+ const s = [];
455
+ let r = o;
456
+ const l = {};
457
+ if (e) {
458
+ for (const d of no) {
459
+ const m = Object.hasOwn(e, d), h = Object.hasOwn(r, d);
460
+ if (!(m === h && JSON.stringify(e[d]) === JSON.stringify(r[d])))
461
+ if (s.push(d), m)
462
+ h ? r = { ...r, [d]: e[d] } : l[d] = e[d];
463
+ else {
464
+ const { [d]: g, ...j } = r;
465
+ r = j;
466
+ }
467
+ }
468
+ r = { ...l, ...r };
469
+ }
470
+ if (typeof r.id == "string" && !xt.test(r.id))
471
+ return { ok: !1, error: "Invalid workflow id." };
472
+ const u = io(r);
473
+ return u !== null ? { ok: !1, error: u } : { ok: !0, text: s.length > 0 ? JSON.stringify(r, null, 2) : n, restored: s };
474
+ }
475
+ function ao(n, e, o, s) {
476
+ const r = {};
477
+ for (const l of n) {
478
+ const u = { code: l.code, connection: l.connection };
479
+ r[l.siteId] = [...Object.hasOwn(r, l.siteId) ? r[l.siteId] : [], u];
480
+ }
481
+ for (const l of [e, o, s])
482
+ for (const [u, d] of Object.entries(l ?? {}))
483
+ d.length > 0 && (r[u] = [...Object.hasOwn(r, u) ? r[u] : [], ...d]);
484
+ return r;
485
+ }
486
+ const lo = Fn(
487
+ () => import("@w6w/ui/flow").then((n) => ({ default: n.WorkflowFlowEditor }))
488
+ );
489
+ function co(n) {
490
+ var kt, Nt, Rt, Et, Ct, At;
491
+ const { workflowId: e, project: o, projectPending: s, initialRunId: r, onNavigate: l, slots: u } = n, d = as(), m = Jt(), [h, g] = v(null), [j, Y] = v(!1), [fe, I] = v(0), [P, J] = v(!1), [U, X] = v(!1), [Z, Le] = v(!1), [ee, Fe] = v(void 0), Me = S(!0), De = S(() => null), Bt = E(
492
+ (t) => {
493
+ const i = t;
494
+ return xt.test(typeof i.id == "string" ? i.id : "") ? jt(ee, i.key).reason : "Invalid workflow id.";
495
+ },
496
+ [ee]
497
+ ), f = ls({
498
+ workflowId: e,
499
+ project: o,
500
+ autoSave: Me.current,
501
+ // The expression editor holds uncommitted parts in its own local state until its Save
502
+ // button, so saving from under it would persist a workflow without the expression the user
503
+ // is looking at. Read at fire time (opening it changes neither the buffer nor `canSave`).
504
+ canAutoSave: () => !document.querySelector(".w6w-exprmodal"),
505
+ saveGuard: Bt,
506
+ publishBlockedReason: (t) => De.current(t)
507
+ }), Je = f.json, c = f.parsed, W = f.canSave, Kt = f.dirty;
508
+ A(() => {
509
+ if (f.loading || f.loadError !== null) {
510
+ Fe(void 0);
511
+ return;
512
+ }
513
+ !f.dirty && c && Fe(c.key ?? null);
514
+ }, [f.loading, f.loadError, f.dirty, c]);
515
+ const [Qt, pe] = v(!1);
516
+ A(() => {
517
+ f.stale || pe(!1);
518
+ }, [f.stale]);
519
+ const [_t, We] = v(!1), $e = S(!1);
520
+ A(() => {
521
+ f.saving ? We(!1) : $e.current && f.error === null && We(!0), $e.current = f.saving;
522
+ }, [f.saving, f.error]);
523
+ const [N, R] = v(null), xe = Dn(), Be = Jn(), Ke = Wn(), O = $n(N), $ = (kt = O.data) == null ? void 0 : kt.status, Qe = O.isError, _ = xn($, Qe), qt = Bn(N, $), he = Kn(
524
+ Qn(O.data),
525
+ (Nt = qt.data) == null ? void 0 : Nt.writes
526
+ ), _e = _n(O.data, he), [Vt, qe] = v(!1);
527
+ A(() => {
528
+ N && qe(!0);
529
+ }, [N]);
530
+ const me = S(!1), [Ht, Ve] = v(!1);
531
+ A(() => {
532
+ R(null);
533
+ }, [e]), A(() => {
534
+ r && R(r);
535
+ }, [e, r]), A(() => {
536
+ O.data && O.data.workflowId !== e && R(null);
537
+ }, [O.data, e]);
538
+ async function He(t) {
539
+ try {
540
+ const i = await f.flushThen(t);
541
+ !i.ok && i.outcome.status === "blocked" && g(i.outcome.reason);
542
+ } catch (i) {
543
+ g(i instanceof je ? i.message : String(i));
544
+ }
545
+ }
546
+ async function zt() {
547
+ if (!(!e || _ || me.current)) {
548
+ g(null), me.current = !0, Ve(!0);
549
+ try {
550
+ const t = b ? zn(C, b.isManualTrigger, b.isEntryTrigger) : (q == null ? void 0 : q[0]) && { id: q[0].id, manual: !0 };
551
+ await Pn();
552
+ const i = await Gn(
553
+ t == null ? void 0 : t.id,
554
+ (p) => Lt(d, e, p),
555
+ () => Yn(d, e)
556
+ );
557
+ await He(
558
+ () => t && !t.manual ? (
559
+ // A webhook / schedule / app trigger entry runs FROM that trigger: the server takes
560
+ // the payload as the event that fired it (its output and `trigger.event`), which a
561
+ // plain run's `input` — the Manual trigger's slot — never reaches.
562
+ Be.mutateAsync({
563
+ id: e,
564
+ nodeId: t.id,
565
+ body: { stopAt: [], ...i ? { input: i } : {} }
566
+ }).then((p) => R(p.runId))
567
+ ) : xe.mutateAsync({
568
+ id: e,
569
+ variables: {},
570
+ ...i ? { input: i } : {}
571
+ }).then((p) => R(p.runId))
572
+ );
573
+ } finally {
574
+ me.current = !1, Ve(!1);
575
+ }
576
+ }
577
+ }
578
+ async function Gt(t, i) {
579
+ if (!e) return;
580
+ g(null);
581
+ const p = await f.flushThen(
582
+ () => {
583
+ var k;
584
+ return Be.mutateAsync({
585
+ id: e,
586
+ nodeId: t,
587
+ body: {
588
+ stopAt: i.stopAt,
589
+ ...(k = i.state) != null && k.steps ? { nodes: i.state.steps } : {},
590
+ ...i.input ? { input: i.input } : {}
591
+ }
592
+ });
593
+ }
594
+ );
595
+ if (!p.ok)
596
+ throw new Error(
597
+ p.outcome.status === "blocked" ? p.outcome.reason : "The workflow could not be saved, so it was not run."
598
+ );
599
+ R(p.value.runId);
600
+ }
601
+ function Yt() {
602
+ N && (Ke.mutate(N, {
603
+ onError: (t) => {
604
+ const i = t instanceof je ? t.code : "";
605
+ Un(i) === "surface" && g(t instanceof je ? t.message : String(t));
606
+ }
607
+ }), R(null));
608
+ }
609
+ async function Ut() {
610
+ Le(!0);
611
+ try {
612
+ await f.reload(), I((t) => t + 1), g(null);
613
+ } finally {
614
+ Le(!1);
615
+ }
616
+ }
617
+ const te = f.stale ? null : f.error ?? f.loadError, ge = h ?? (te === null ? null : te instanceof Error ? te.message : String(te)), Xt = c !== null && (Array.isArray(c.nodes) || Array.isArray(c.steps)), ze = (c == null ? void 0 : c.displayName) ?? "", be = cs(c == null ? void 0 : c.settings), ne = vs(c == null ? void 0 : c.initialState), Zt = w(() => ws(c == null ? void 0 : c.variables), [c == null ? void 0 : c.variables]), Ge = jt(ee, c == null ? void 0 : c.key), ye = c !== null && ee !== void 0 && !Ge.allowed ? Ge.reason : null, C = w(
618
+ () => us(c),
619
+ [c]
620
+ ), [b, en] = v(null);
621
+ A(() => {
622
+ let t = !1;
623
+ return import("@w6w/ui/flow").then((i) => {
624
+ t || en({
625
+ internalNodes: i.INTERNAL_NODES,
626
+ isInternalApp: i.isInternalApp,
627
+ internalNodeParams: i.internalNodeParams,
628
+ isManualTrigger: (p) => p === i.TRIGGER_APP,
629
+ isEntryTrigger: i.isTriggerStep,
630
+ asFieldDefs: i.asFieldDefs,
631
+ findLoopProblems: i.findLoopProblems,
632
+ findStateWriteProblems: i.findStateWriteProblems
633
+ });
634
+ }), () => {
635
+ t = !0;
636
+ };
637
+ }, []);
638
+ const q = w(() => {
639
+ if (b)
640
+ return ds(
641
+ { steps: C },
642
+ {
643
+ isManualTrigger: b.isManualTrigger,
644
+ asFieldDefs: b.asFieldDefs
645
+ }
646
+ );
647
+ }, [b, C]), L = w(() => {
648
+ if (!b) return [];
649
+ const t = /* @__PURE__ */ new Set();
650
+ for (const i of C) {
651
+ const { app: p, action: k } = i.uses ?? {};
652
+ p && k && !b.isInternalApp(p) && t.add(p);
653
+ }
654
+ return [...t];
655
+ }, [b, C]), { byId: se } = Zn(L), tn = w(() => [...se.values()], [se]), Ye = Te({
656
+ queries: L.map((t) => ({
657
+ queryKey: Js(t),
658
+ queryFn: () => m.getAppActions(t)
659
+ }))
660
+ }), Ue = w(() => {
661
+ var i, p;
662
+ const t = {};
663
+ if (!b) return t;
664
+ for (const k of C) {
665
+ const { app: T, action: Q } = k.uses ?? {};
666
+ if (!T || !Q) continue;
667
+ const Pe = `${T}::${Q}`;
668
+ if (!(Pe in t))
669
+ if (b.isInternalApp(T))
670
+ t[Pe] = b.internalNodeParams(T, Q);
671
+ else {
672
+ const Pt = L.indexOf(T), Oe = Pt >= 0 ? (i = Ye[Pt]) == null ? void 0 : i.data : void 0;
673
+ t[Pe] = ((p = Oe == null ? void 0 : Oe.find((vn) => vn.key === Q)) == null ? void 0 : p.params) ?? [];
674
+ }
675
+ }
676
+ return t;
677
+ }, [b, C, L, Ye]), V = w(() => {
678
+ const t = {};
679
+ for (const [i, p] of se) t[i] = p;
680
+ return t;
681
+ }, [se]), ve = w(
682
+ () => C.filter((t) => {
683
+ var p;
684
+ const i = (p = t.uses) == null ? void 0 : p.app;
685
+ return !!i && i in V && Ot(V[i]);
686
+ }),
687
+ [C, V]
688
+ ), Xe = Te({
689
+ queries: ve.map((t) => ({
690
+ queryKey: Ie(e, t.id),
691
+ queryFn: () => Lt(d, e, t.id),
692
+ enabled: !!e
693
+ }))
694
+ }), Ze = w(() => {
695
+ const t = {};
696
+ return ve.forEach((i, p) => {
697
+ var k, T;
698
+ t[i.id] = !!((T = (k = Xe[p]) == null ? void 0 : k.data) != null && T.some((Q) => Q.lastRunStatus === "succeeded"));
699
+ }), t;
700
+ }, [ve, Xe]), H = As("workflow", e, !!e), we = Ps("workflow"), F = ((Rt = H.data) == null ? void 0 : Rt.currentPublishedVersion) ?? null, x = Os("workflow", e, F, !!e), Se = x.data !== void 0 && c !== null && Ft(c, x.data.definition), nn = Se && !Ft(c, (Et = x.data) == null ? void 0 : Et.definition, { presentation: !0 }), M = H.data === void 0 ? void 0 : F === null ? "unpublished" : x.data === void 0 || f.loading ? void 0 : Se ? "published" : "draft", [sn, et] = v(!1), on = Ts("workflow");
701
+ async function tt(t) {
702
+ et(!0), g(null);
703
+ try {
704
+ await f.discardThen(() => on.mutateAsync({ id: e, versionNumber: t })), I((i) => i + 1), R(null);
705
+ } finally {
706
+ et(!1);
707
+ }
708
+ }
709
+ const oe = Dt(), nt = S(null);
710
+ A(() => {
711
+ var t;
712
+ if (!(!e || !N || nt.current === N) && qn($, (t = O.data) == null ? void 0 : t.workflowId, e)) {
713
+ nt.current = N;
714
+ for (const i of Vn)
715
+ setTimeout(
716
+ () => void oe.invalidateQueries({ queryKey: Is(e) }),
717
+ i
718
+ );
719
+ }
720
+ }, [e, N, $, (Ct = O.data) == null ? void 0 : Ct.workflowId, oe]);
721
+ const st = Te({
722
+ queries: L.map((t) => ({
723
+ queryKey: It(t),
724
+ queryFn: () => Cs(d, t)
725
+ }))
726
+ }), ot = w(() => {
727
+ const t = /* @__PURE__ */ new Map();
728
+ return L.forEach((i, p) => {
729
+ const k = st[p];
730
+ k && (k.isError ? t.set(i, { state: "error" }) : k.isSuccess && !k.isFetching ? t.set(i, { state: "ready", ids: new Set((k.data ?? []).map((T) => T.id)) }) : t.set(i, { state: "loading" }));
731
+ }), t;
732
+ }, [L, st]), B = w(
733
+ () => fs(C, (t) => ot.get(t), c == null ? void 0 : c.connections),
734
+ [C, ot, c == null ? void 0 : c.connections]
735
+ ), it = Fs(o ?? void 0, o !== null), rt = Ms(), at = Ls(), lt = Ds(o ?? void 0), ke = w(() => {
736
+ if (!c) return {};
737
+ const t = (i) => ({
738
+ names: (i.data ?? []).map((p) => p.name),
739
+ ready: i.isSuccess
740
+ });
741
+ return ps({
742
+ workflow: c,
743
+ lists: {
744
+ vars: t(it),
745
+ secrets: t(rt),
746
+ constants: t(at),
747
+ stores: t(lt)
748
+ }
749
+ });
750
+ }, [c, it, rt, at, lt]), ct = w(() => {
751
+ const t = {};
752
+ for (const [i, p] of Object.entries(ke))
753
+ t[i] = [{ code: "setup_incomplete", items: p }];
754
+ return t;
755
+ }, [ke]), rn = w(
756
+ () => ao(
757
+ B,
758
+ b == null ? void 0 : b.findLoopProblems(c),
759
+ c ? b == null ? void 0 : b.findStateWriteProblems(c) : void 0,
760
+ ct
761
+ ),
762
+ [B, b, c, ct]
763
+ ), ut = S(/* @__PURE__ */ new Set());
764
+ A(() => {
765
+ for (const t of B) {
766
+ const i = `${t.app}|${t.connection}`;
767
+ ut.current.has(i) || (ut.current.add(i), oe.invalidateQueries({ queryKey: It(t.app) }));
768
+ }
769
+ }, [B, oe]);
770
+ const ie = S({ id: e, had: !1 });
771
+ ie.current.id !== e && (ie.current = { id: e, had: !1 }), B.length > 0 && (ie.current.had = !0);
772
+ const dt = js("workflow"), Ne = hs({
773
+ enabled: (At = H.data) == null ? void 0 : At.enabled,
774
+ problemCount: B.length,
775
+ dirty: f.dirty,
776
+ hadProblems: ie.current.had
777
+ }), Re = w(
778
+ () => ({
779
+ actionParamsByKey: Ue,
780
+ appsById: V,
781
+ testStatus: Ze,
782
+ requiredParamsFilled: En,
783
+ isTestRequired: Ot
784
+ }),
785
+ [Ue, V, Ze]
786
+ ), an = w(
787
+ () => c !== null && b !== null ? ms(c, Re) : [],
788
+ [c, b, Re]
789
+ ), [ft, pt] = v(!1), Ee = S(!1), z = gs({
790
+ projectMissing: o === null,
791
+ loading: !W,
792
+ saveBlockedReason: f.saveBlockedReason ?? (W && c === null ? "the workflow JSON does not parse." : null),
793
+ catalogLoading: c !== null && b === null,
794
+ problems: an,
795
+ publishing: ft || we.isPending
796
+ }) ?? (H.isPending || F !== null && x.isPending ? "Checking the published version…" : H.isError || F !== null && x.isError ? "Can't check the published version. Reload to try again." : Se ? nn ? "Already published. Moving things on the canvas doesn't need a new version." : "Already published. Make a change before publishing again." : null);
797
+ async function Ce() {
798
+ if (!(!e || z !== null || Ee.current)) {
799
+ Ee.current = !0, pt(!0), g(null);
800
+ try {
801
+ await He(() => we.mutateAsync(e));
802
+ } finally {
803
+ Ee.current = !1, pt(!1);
804
+ }
805
+ }
806
+ }
807
+ De.current = (t) => t !== null && typeof t == "object" ? bs(t, Re) : null, Me.current = be.autoSave;
808
+ const ln = E(
809
+ (t) => ro(t, ae.current),
810
+ []
811
+ );
812
+ function re(t) {
813
+ if (!c) return;
814
+ const i = { ...c, ...t };
815
+ f.setJson(JSON.stringify(i, null, 2));
816
+ }
817
+ function ht(t) {
818
+ if (!c) return;
819
+ const i = { ...c, ...t };
820
+ g(null), f.commit(JSON.stringify(i, null, 2));
821
+ }
822
+ const ae = S(c);
823
+ ae.current = c;
824
+ const mt = S(f.commit);
825
+ mt.current = f.commit;
826
+ const gt = S(f.saveNow);
827
+ gt.current = f.saveNow, A(() => {
828
+ const t = (i) => {
829
+ i.altKey || !(i.metaKey || i.ctrlKey) || i.key.toLowerCase() !== "s" || (i.preventDefault(), !document.querySelector(".w6w-exprmodal") && W && gt.current());
830
+ };
831
+ return document.addEventListener("keydown", t), () => {
832
+ document.removeEventListener("keydown", t);
833
+ };
834
+ }, [W]);
835
+ const cn = w(
836
+ () => c ? ks(c) : {},
837
+ [c]
838
+ ), un = E((t) => {
839
+ const i = ae.current;
840
+ if (!i) return;
841
+ const p = Ns(i, t);
842
+ g(null), mt.current(JSON.stringify(p, null, 2));
843
+ }, []), dn = E(() => X(!0), []), bt = S(() => {
844
+ });
845
+ bt.current = (t) => {
846
+ R(t), l({ type: "run", id: e, runId: t });
847
+ };
848
+ const yt = E((t) => bt.current(t), []), vt = S(tt);
849
+ vt.current = tt;
850
+ const fn = E((t) => vt.current(t), []), wt = S(Ce);
851
+ wt.current = Ce;
852
+ const pn = E(() => wt.current(), []), Ae = S({ saveMeta: ht, patchMeta: re });
853
+ Ae.current = { saveMeta: ht, patchMeta: re };
854
+ const hn = E(
855
+ (t, i) => {
856
+ var p;
857
+ Ae.current.saveMeta({
858
+ settings: ys((p = ae.current) == null ? void 0 : p.settings, t, i)
859
+ });
860
+ },
861
+ []
862
+ ), mn = E((t) => {
863
+ Ae.current.patchMeta({ variables: Ss(t) });
864
+ }, []), [K, gn] = v(null), St = S(K);
865
+ St.current = K;
866
+ const bn = E(
867
+ (t) => {
868
+ var i;
869
+ (i = St.current) == null || i.edit(t);
870
+ },
871
+ []
872
+ ), yn = E(() => J(!0), []);
873
+ return rs({
874
+ kind: "workflow",
875
+ id: e,
876
+ connectionResources: (K == null ? void 0 : K.workflowId) === e ? { ...K, edit: bn } : void 0,
877
+ label: ze,
878
+ key: (c == null ? void 0 : c.key) ?? void 0,
879
+ triggers: q,
880
+ onRestoreVersion: fn,
881
+ definitionStatus: M,
882
+ onPublish: pn,
883
+ publishDisabled: z !== null,
884
+ policy: cn,
885
+ onPolicyChange: un,
886
+ hasStartingState: ne !== void 0 && Object.keys(ne).length > 0,
887
+ startingState: ne,
888
+ onOpenStartingState: dn,
889
+ onOpenRun: yt,
890
+ authoringSettings: { autoSave: be.autoSave, savePosition: be.savePosition },
891
+ onAuthoringSettingChange: hn,
892
+ variables: Zt,
893
+ onVariablesChange: mn,
894
+ onOpenHistory: yn
895
+ }), /* @__PURE__ */ y("div", { className: "wf-fullbleed", style: { height: "100%", minWidth: 0, flex: 1 }, children: [
896
+ (u == null ? void 0 : u.header) ?? /* @__PURE__ */ a(
897
+ Bs,
898
+ {
899
+ onBack: () => l({ type: "list" }),
900
+ backLabel: (u == null ? void 0 : u.backLabel) === null ? null : (u == null ? void 0 : u.backLabel) ?? "← Workflows",
901
+ title: {
902
+ editable: !0,
903
+ value: ze,
904
+ placeholder: to,
905
+ maxLength: 80,
906
+ ariaLabel: "Workflow name",
907
+ onChange: (t) => re({ displayName: t }),
908
+ onBlur: () => {
909
+ W && f.saveNow();
910
+ }
911
+ },
912
+ titleAdornment: M && /* @__PURE__ */ a(
913
+ "span",
914
+ {
915
+ className: `badge wf-definition-status ${M}`,
916
+ "data-testid": "wf-definition-status",
917
+ "aria-live": "polite",
918
+ title: M === "published" ? "This workflow matches the published version. Edits create a separate draft." : M === "draft" ? "You are editing a draft. The published version stays unchanged until you publish." : "You are editing a draft. This workflow has not been published.",
919
+ children: M === "published" ? "Live" : "Draft"
920
+ }
921
+ ),
922
+ actions: /* @__PURE__ */ y(G, { children: [
923
+ /* @__PURE__ */ a(
924
+ ce,
925
+ {
926
+ icon: "play",
927
+ label: Hn($, Qe),
928
+ "data-testid": "wf-run-start",
929
+ onClick: zt,
930
+ disabled: !e || _ || Ht || xe.isPending
931
+ }
932
+ ),
933
+ _ && /* @__PURE__ */ a(
934
+ ce,
935
+ {
936
+ icon: "stop",
937
+ label: "Stop this run",
938
+ "data-testid": "wf-run-stop",
939
+ onClick: Yt,
940
+ disabled: Ke.isPending
941
+ }
942
+ ),
943
+ /* @__PURE__ */ a(
944
+ "button",
945
+ {
946
+ type: "button",
947
+ className: "btn ghost",
948
+ "data-testid": "wf-save",
949
+ disabled: o === null || !W || !Kt,
950
+ onClick: f.saveNow,
951
+ children: f.saving ? "Saving…" : "Save"
952
+ }
953
+ ),
954
+ _t && /* @__PURE__ */ a("span", { className: "ok wf-saved", "aria-live": "polite", children: "Saved." }),
955
+ /* @__PURE__ */ a(
956
+ Us,
957
+ {
958
+ disabled: z !== null,
959
+ message: z ?? (F !== null ? "Republish this draft as a new live version" : "Publish this draft as a new live version"),
960
+ children: (t) => /* @__PURE__ */ a(G, { children: /* @__PURE__ */ a(
961
+ "button",
962
+ {
963
+ type: "button",
964
+ className: "btn ghost wf-publish",
965
+ "data-testid": "wf-publish",
966
+ onClick: () => void Ce(),
967
+ disabled: z !== null,
968
+ "aria-describedby": t,
969
+ children: ft || we.isPending ? F !== null ? "Republishing…" : "Publishing…" : F !== null ? M === "draft" ? "Republish" : "Published" : "Publish"
970
+ }
971
+ ) })
972
+ }
973
+ ),
974
+ /* @__PURE__ */ a(_s, { onClick: () => Y(!0) }),
975
+ u == null ? void 0 : u.headerActions
976
+ ] })
977
+ }
978
+ ),
979
+ /* @__PURE__ */ a(Xs, { problems: ke }),
980
+ Ne.show && /* @__PURE__ */ a(
981
+ Gs,
982
+ {
983
+ kind: "workflow",
984
+ problemCount: Ne.problemCount,
985
+ canEnable: Ne.canEnable,
986
+ pending: dt.isPending,
987
+ onEnable: () => dt.mutate({ id: e, enabled: !0 })
988
+ }
989
+ ),
990
+ /* @__PURE__ */ a("div", { className: "wf-fullbleed-canvas", children: /* @__PURE__ */ a("div", { className: "wf-run-area", children: /* @__PURE__ */ a("div", { className: "wf-run-canvas", children: /* @__PURE__ */ a(Ln, { fallback: /* @__PURE__ */ a("p", { className: "muted", children: "Loading visual editor…" }), children: Xt && c ? /* @__PURE__ */ a(
991
+ lo,
992
+ {
993
+ onConnectionResourcesChange: gn,
994
+ value: c,
995
+ onChange: (t, i) => {
996
+ f.setJson(JSON.stringify(t, null, 2)), i != null && i.viewportOnly || R(null);
997
+ },
998
+ apps: tn,
999
+ project: o ?? void 0,
1000
+ height: "100%",
1001
+ readOnly: _,
1002
+ stepProblems: rn,
1003
+ runState: O.data,
1004
+ onTestRun: () => R(null),
1005
+ onRunFromNode: Gt
1006
+ },
1007
+ fe
1008
+ ) : Je === "" ? /* @__PURE__ */ a("p", { className: "muted", children: "Loading…" }) : /* @__PURE__ */ a("p", { className: "muted", children: "Fix the JSON to render the visual editor." }) }) }) }) }),
1009
+ o === null && !s && /* @__PURE__ */ y("div", { role: "alert", className: "error", "data-testid": "wf-project-required", children: [
1010
+ "No project selected — pass a ",
1011
+ /* @__PURE__ */ a("code", { children: "project" }),
1012
+ " prop (or set the provider's project) to edit and save this workflow."
1013
+ ] }),
1014
+ (ge || ye) && /* @__PURE__ */ y("div", { className: "wf-fullbleed-alerts", children: [
1015
+ ge && /* @__PURE__ */ a("div", { className: "error", children: ge }),
1016
+ ye && /* @__PURE__ */ a("div", { className: "error", "data-testid": "wf-key-guard", children: ye })
1017
+ ] }),
1018
+ /* @__PURE__ */ a(
1019
+ Cn,
1020
+ {
1021
+ open: Vt,
1022
+ onOpenChange: qe,
1023
+ windowClassName: "w6w-embed-root",
1024
+ windowTitle: `Logs · ${(c == null ? void 0 : c.displayName) || "Workflow"}`,
1025
+ summary: /* @__PURE__ */ a(po, { active: !!N, status: $, steps: he }),
1026
+ onClear: N ? () => R(null) : void 0,
1027
+ children: N ? /* @__PURE__ */ a("div", { className: "wf-run-log", "data-testid": "wf-run-log", children: /* @__PURE__ */ a(
1028
+ An,
1029
+ {
1030
+ steps: he,
1031
+ runError: _e.runError,
1032
+ stepErrors: _e.stepErrors,
1033
+ emptyLabel: _ ? "Waiting for the first step…" : void 0
1034
+ }
1035
+ ) }) : /* @__PURE__ */ a("p", { className: "muted wf-run-log-idle", children: "Run the workflow to see each step's input, output and timing here." })
1036
+ }
1037
+ ),
1038
+ sn && /* @__PURE__ */ a(ue, { title: "Restoring version…", onClose: () => {
1039
+ }, children: /* @__PURE__ */ a("div", { className: "modal-body", children: "Replacing the draft…" }) }),
1040
+ /* @__PURE__ */ a(
1041
+ qs,
1042
+ {
1043
+ open: j,
1044
+ onClose: () => Y(!1),
1045
+ title: `JSON — ${(c == null ? void 0 : c.displayName) || "workflow"}`,
1046
+ mode: "apply",
1047
+ value: Je,
1048
+ prepareApply: ln,
1049
+ onApply: (t) => {
1050
+ f.setJson(t), I((i) => i + 1), R(null);
1051
+ },
1052
+ editorLabel: "Workflow definition JSON"
1053
+ }
1054
+ ),
1055
+ f.stale && !Qt && /* @__PURE__ */ y(ue, { title: "This workflow changed on the server", onClose: () => pe(!0), children: [
1056
+ /* @__PURE__ */ y("div", { className: "modal-body", children: [
1057
+ /* @__PURE__ */ a("p", { className: "muted small", children: "Someone else — another tab, another session — saved this workflow after you opened it. Your save was refused rather than applied, so their work is still intact." }),
1058
+ /* @__PURE__ */ y("p", { className: "muted small", children: [
1059
+ /* @__PURE__ */ a("strong", { children: "Reload from server" }),
1060
+ " replaces what is on this canvas with the saved copy; anything you changed here and have not saved is lost.",
1061
+ " ",
1062
+ /* @__PURE__ */ a("strong", { children: "Keep editing" }),
1063
+ " leaves your version exactly as it is — but every save will be refused the same way until you reload, so copy out anything you need first."
1064
+ ] })
1065
+ ] }),
1066
+ /* @__PURE__ */ y("div", { className: "modal-actions", children: [
1067
+ /* @__PURE__ */ a("button", { type: "button", className: "btn ghost", onClick: () => pe(!0), children: "Keep editing" }),
1068
+ /* @__PURE__ */ a("button", { type: "button", className: "btn", disabled: Z, onClick: Ut, children: Z ? "Reloading…" : "Reload from server" })
1069
+ ] })
1070
+ ] }),
1071
+ P && /* @__PURE__ */ a(
1072
+ Qs,
1073
+ {
1074
+ kind: "workflow",
1075
+ id: e,
1076
+ onClose: () => J(!1),
1077
+ onOpenRun: yt
1078
+ }
1079
+ ),
1080
+ U && /* @__PURE__ */ a(
1081
+ eo,
1082
+ {
1083
+ initialState: ne,
1084
+ onChange: (t) => re({ initialState: t }),
1085
+ onClose: () => X(!1)
1086
+ }
1087
+ )
1088
+ ] });
1089
+ }
1090
+ function uo({
1091
+ children: n,
1092
+ callableHref: e
1093
+ }) {
1094
+ const o = Jt(), s = Dt(), r = In(Ws), l = w(() => ({
1095
+ ...o,
1096
+ saveStepTest: (...m) => o.saveStepTest(...m).finally(() => {
1097
+ s.invalidateQueries({ queryKey: Ie(m[0], m[1]) });
1098
+ }),
1099
+ recordStepTestRun: (...m) => o.recordStepTestRun(...m).finally(() => {
1100
+ s.invalidateQueries({ queryKey: Ie(m[0], m[1]) });
1101
+ }),
1102
+ callableHref: e ?? o.callableHref
1103
+ }), [o, s, e]);
1104
+ return /* @__PURE__ */ a(Rn, { api: l, theme: r, children: n });
1105
+ }
1106
+ const fo = () => {
1107
+ };
1108
+ function po({
1109
+ active: n,
1110
+ status: e,
1111
+ steps: o
1112
+ }) {
1113
+ if (!n) return /* @__PURE__ */ a("span", { children: "No run yet" });
1114
+ const s = o.filter((d) => d.startedAt), r = s.map((d) => Date.parse(d.startedAt)).filter(Number.isFinite), l = o.map((d) => d.finishedAt ? Date.parse(d.finishedAt) : Number.NaN).filter(Number.isFinite), u = r.length > 0 && l.length > 0 ? Math.max(...l) - Math.min(...r) : null;
1115
+ return /* @__PURE__ */ y(G, { children: [
1116
+ /* @__PURE__ */ a(On, { state: e ?? "queued" }),
1117
+ /* @__PURE__ */ y("span", { children: [
1118
+ s.length,
1119
+ " ",
1120
+ s.length === 1 ? "step" : "steps"
1121
+ ] }),
1122
+ u !== null && u >= 0 && /* @__PURE__ */ a("span", { children: Tn(u) })
1123
+ ] });
1124
+ }
1125
+ function xo(n) {
1126
+ const { workflowId: e, initialRunId: o, onNavigate: s = fo, slots: r } = n, l = Rs(n.project), u = Es().status, d = n.project === void 0 && u === "resolving", m = E(
1127
+ (h) => {
1128
+ h.type === "list" ? s({ type: "list" }) : h.kind === "workflow" && s({ type: "workflow", id: h.id });
1129
+ },
1130
+ [s]
1131
+ );
1132
+ return /* @__PURE__ */ a(
1133
+ "div",
1134
+ {
1135
+ className: "w6w-embed-root",
1136
+ style: { display: "flex", width: "100%", height: "100%", minHeight: 0 },
1137
+ children: /* @__PURE__ */ a(
1138
+ Ys,
1139
+ {
1140
+ project: l,
1141
+ onNavigate: m,
1142
+ rail: n.rail,
1143
+ storageKey: l === null ? null : `w6w.rail.embed.${l}`,
1144
+ children: /* @__PURE__ */ a(uo, { callableHref: n.callableHref, children: /* @__PURE__ */ a(
1145
+ co,
1146
+ {
1147
+ workflowId: e,
1148
+ project: l,
1149
+ projectPending: d,
1150
+ initialRunId: o,
1151
+ onNavigate: s,
1152
+ slots: r
1153
+ }
1154
+ ) })
1155
+ }
1156
+ )
1157
+ }
1158
+ );
1159
+ }
1160
+ export {
1161
+ Gs as B,
1162
+ Bs as E,
1163
+ Qs as H,
1164
+ qs as J,
1165
+ xo as W,
1166
+ Ys as a,
1167
+ _s as b
1168
+ };
1169
+ //# sourceMappingURL=WorkflowEditor-C7oudiIb.js.map