@galaxy-stack/blackhole-cli 3.0.13 → 3.0.14

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 (69) hide show
  1. package/CHANGELOG.md +971 -0
  2. package/README.md +12 -11
  3. package/dist/harness/install-command.js +2 -2
  4. package/dist/harness/install-command.js.map +1 -1
  5. package/dist/harness/install.d.ts +1 -1
  6. package/dist/harness/install.js +1 -1
  7. package/dist/harness/locate.d.ts +9 -3
  8. package/dist/harness/locate.d.ts.map +1 -1
  9. package/dist/harness/locate.js +39 -7
  10. package/dist/harness/locate.js.map +1 -1
  11. package/dist/harness/node-runtime.d.ts +37 -3
  12. package/dist/harness/node-runtime.d.ts.map +1 -1
  13. package/dist/harness/node-runtime.js +60 -14
  14. package/dist/harness/node-runtime.js.map +1 -1
  15. package/dist/harness/process.d.ts +1 -1
  16. package/dist/harness/process.d.ts.map +1 -1
  17. package/dist/harness/process.js +14 -5
  18. package/dist/harness/process.js.map +1 -1
  19. package/dist/migrate.d.ts +20 -12
  20. package/dist/migrate.d.ts.map +1 -1
  21. package/dist/migrate.js +39 -67
  22. package/dist/migrate.js.map +1 -1
  23. package/dist/options.d.ts +1 -1
  24. package/dist/options.d.ts.map +1 -1
  25. package/dist/options.js +1 -1
  26. package/dist/web/command.d.ts +1 -1
  27. package/dist/web/command.js +3 -3
  28. package/dist/web/command.js.map +1 -1
  29. package/dist/web/doctor.js +5 -5
  30. package/dist/web/doctor.js.map +1 -1
  31. package/dist/web/options.js +2 -2
  32. package/dist/web/options.js.map +1 -1
  33. package/dist/web/web.d.ts +6 -4
  34. package/dist/web/web.d.ts.map +1 -1
  35. package/dist/web/web.js +10 -8
  36. package/dist/web/web.js.map +1 -1
  37. package/package.json +4 -6
  38. package/dist/web/dsh.d.ts +0 -51
  39. package/dist/web/dsh.d.ts.map +0 -1
  40. package/dist/web/dsh.js +0 -149
  41. package/dist/web/dsh.js.map +0 -1
  42. package/web/brand/app-icon-192.png +0 -0
  43. package/web/brand/app-icon-512.png +0 -0
  44. package/web/brand/client.template.js +0 -1259
  45. package/web/brand/dsh-locale-keys.json +0 -8659
  46. package/web/brand/favicon.png +0 -0
  47. package/web/brand/favicon.svg +0 -12
  48. package/web/brand/lib/app-icons.js +0 -3
  49. package/web/brand/lib/client.js +0 -5161
  50. package/web/brand/lib/favicon.js +0 -1
  51. package/web/brand/lib/index.d.ts +0 -3
  52. package/web/brand/lib/index.js +0 -1068
  53. package/web/brand/lib/journey-host.js +0 -288
  54. package/web/brand/lib/journey-run.d.ts +0 -70
  55. package/web/brand/lib/journey-run.js +0 -344
  56. package/web/brand/lib/journey-store.d.ts +0 -61
  57. package/web/brand/lib/journey-store.js +0 -183
  58. package/web/brand/lib/session-store.d.ts +0 -54
  59. package/web/brand/lib/session-store.js +0 -288
  60. package/web/brand/logo.png +0 -0
  61. package/web/brand/logo.svg +0 -20
  62. package/web/brand/package.json +0 -35
  63. package/web/brand/panel/journey-panel.js +0 -1037
  64. package/web/brand/vi-same-by-design.json +0 -112
  65. package/web/brand/vi.locales.json +0 -2867
  66. package/web/brand/zalo.jpg +0 -0
  67. package/web/patches/gbh-brand.patch.yml +0 -13
  68. package/web/patches/gbh-ui.patch.yml +0 -7
  69. package/web/patches/gbh-web.patch.yml +0 -124
@@ -1,1037 +0,0 @@
1
- /**
2
- * Galaxy journey panel: an n8n-style canvas over the workspace blueprint.
3
- *
4
- * Inlined into the client bundle by scripts/build-web-brand.mjs in place of
5
- * __JOURNEY_PANEL__. The panel owns presentation only: the blueprint document it
6
- * renders comes from the Host route and every edit goes back through it, so the
7
- * agent and the canvas always share one reviewable source of truth.
8
- *
9
- * The canvas reads as a sequence: every edge leaves the out port of its source and
10
- * lands on the in port of its target with an arrowhead plus the condition it carries,
11
- * every node shows the step number of its longest path, and every node keeps a
12
- * description the agent reads before it runs that step.
13
- */
14
- function createJourneyPanel(runtime) {
15
- const react = runtime.react;
16
- const jsx = runtime.jsx;
17
- const jsxs = runtime.jsxs;
18
- const t = runtime.t;
19
- const api = runtime.api;
20
-
21
- const KIND_LABEL = { trigger: "Bắt đầu", gate: "Cổng kiểm", action: "Hành động", approval: "Phê duyệt", join: "Gộp nhánh", notify: "Thông báo", rollback: "Hoàn tác" };
22
- const KIND_COLOR = { trigger: "#4f7cff", gate: "#e0a92b", action: "#2fa36b", approval: "#b06bd6", join: "#5a6472", notify: "#3aa0c9", rollback: "#e5484d" };
23
- const WHEN_LABEL = { success: "thành công", failure: "thất bại", always: "luôn" };
24
- /** Edge colour by condition; the SVG arrowheads are keyed by the same names. */
25
- const EDGE_COLOR = { success: "#4f7cff", failure: "#e5484d", always: "#8b93a1" };
26
- const GRID = 10;
27
- const NODE_W = 190;
28
- const NODE_H = 62;
29
-
30
- const snap = value => Math.round(value / GRID) * GRID;
31
- const clone = value => JSON.parse(JSON.stringify(value));
32
- const nextId = (prefix, taken) => {
33
- let index = 1;
34
- while (taken.indexOf(prefix + index) !== -1) index += 1;
35
- return prefix + index;
36
- };
37
-
38
- /** Client-side mirror of the host validator, so badges appear while editing. */
39
- function issuesOf(doc) {
40
- const list = [];
41
- if (doc === null || typeof doc !== "object") return [{ code: "document", message: "Blueprint must be an object." }];
42
- const ids = new Set();
43
- for (const node of Array.isArray(doc.nodes) ? doc.nodes : []) {
44
- if (typeof node.id !== "string" || node.id.length === 0) list.push({ code: "node.id", nodeId: node.id, message: "Node cần id" });
45
- else if (ids.has(node.id)) list.push({ code: "node.id", nodeId: node.id, message: "Trùng id node: " + node.id });
46
- else ids.add(node.id);
47
- if (node.kind === "action" && (!Array.isArray(node.actions) || node.actions.length === 0)) list.push({ code: "node.actions", nodeId: node.id, message: "Node hành động cần ít nhất 1 action" });
48
- }
49
- for (const edge of Array.isArray(doc.edges) ? doc.edges : []) {
50
- if (!ids.has(edge.from) || !ids.has(edge.to)) list.push({ code: "edge.endpoint", edgeId: edge.id, message: "Edge trỏ tới node không tồn tại" });
51
- }
52
- return list;
53
- }
54
-
55
- /** Colour one run state the way the canvas badge shows it. */
56
- const RUN_COLOR = { done: "#2fa36b", failed: "#e5484d", running: "#4f7cff", awaiting_approval: "#e0a92b", blocked: "#8b93a1", skipped: "#5a6472", pending: "transparent" };
57
- const RUN_LABEL = { done: "xong", failed: "lỗi", running: "đang chạy", awaiting_approval: "chờ duyệt", blocked: "chặn", skipped: "bỏ qua", pending: "chờ" };
58
-
59
- /** Bounding box of a node list, used by the minimap and fit. */
60
- function boundsOf(nodes) {
61
- if (nodes.length === 0) return { minX: 0, minY: 0, maxX: NODE_W, maxY: NODE_H };
62
- return nodes.reduce((box, node) => ({
63
- minX: Math.min(box.minX, node.x ?? 0),
64
- minY: Math.min(box.minY, node.y ?? 0),
65
- maxX: Math.max(box.maxX, (node.x ?? 0) + NODE_W),
66
- maxY: Math.max(box.maxY, (node.y ?? 0) + NODE_H),
67
- }), { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity });
68
- }
69
-
70
- /** Where an edge leaves its source: the out port on the right edge. */
71
- function outAnchor(node) {
72
- return { x: (node.x ?? 0) + NODE_W + 7, y: (node.y ?? 0) + NODE_H / 2 };
73
- }
74
-
75
- /** Where an edge enters its target: the in port on the left edge. */
76
- function inAnchor(node) {
77
- return { x: (node.x ?? 0) - 7, y: (node.y ?? 0) + NODE_H / 2 };
78
- }
79
-
80
- /** The cubic one edge is drawn as, port to port. */
81
- function edgeCurve(fromNode, toNode) {
82
- const a = outAnchor(fromNode);
83
- const b = inAnchor(toNode);
84
- const bend = Math.max(40, Math.abs(b.x - a.x) / 2);
85
- return { a: a, b: b, c1: { x: a.x + bend, y: a.y }, c2: { x: b.x - bend, y: b.y } };
86
- }
87
-
88
- function edgePath(fromNode, toNode) {
89
- const curve = edgeCurve(fromNode, toNode);
90
- return "M " + curve.a.x + " " + curve.a.y + " C " + curve.c1.x + " " + curve.c1.y + ", " + curve.c2.x + " " + curve.c2.y + ", " + curve.b.x + " " + curve.b.y;
91
- }
92
-
93
- /** Midpoint of that cubic, where the condition chip sits. */
94
- function edgeMidpoint(fromNode, toNode) {
95
- const curve = edgeCurve(fromNode, toNode);
96
- return {
97
- x: (curve.a.x + 3 * curve.c1.x + 3 * curve.c2.x + curve.b.x) / 8,
98
- y: (curve.a.y + 3 * curve.c1.y + 3 * curve.c2.y + curve.b.y) / 8,
99
- };
100
- }
101
-
102
- /** Longest path from a source node: the step number the canvas reads out. */
103
- function depthMap(nodes, edges) {
104
- const depth = new Map(nodes.map(node => [node.id, 0]));
105
- for (let pass = 0; pass < nodes.length; pass += 1) {
106
- for (const edge of edges) {
107
- const from = depth.get(edge.from) ?? 0;
108
- const to = depth.get(edge.to) ?? 0;
109
- if (to < from + 1) depth.set(edge.to, from + 1);
110
- }
111
- }
112
- return depth;
113
- }
114
-
115
- function Toolbar(props) {
116
- const { doc, dirty, status, view, run, mode, onSave, onReload, onZoom, onFit, onLayout, onAdd, onUndo, onRedo, onRun, onMode } = props;
117
- const button = (label, onClick, options) => jsx("button", {
118
- type: "button",
119
- onClick,
120
- ...(options && options.hook ? { "data-gbh-action": options.hook } : {}),
121
- ...(options && options.add ? { "data-gbh-add": options.add } : {}),
122
- title: options && options.title ? options.title : label,
123
- disabled: Boolean(options && options.disabled),
124
- style: {
125
- height: "30px", padding: "0 10px", borderRadius: "8px",
126
- border: options && options.primary ? "none" : "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35))",
127
- background: options && options.primary ? "#4f7cff" : "transparent",
128
- color: options && options.primary ? "#fff" : "inherit",
129
- cursor: options && options.disabled ? "default" : "pointer",
130
- fontSize: "12px", fontWeight: options && options.primary ? 600 : 400,
131
- opacity: options && options.disabled ? 0.5 : 1,
132
- },
133
- children: label,
134
- });
135
- return jsxs("div", {
136
- style: { display: "flex", alignItems: "center", gap: "8px", flexWrap: "wrap", padding: "10px 12px", borderBottom: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.25))" },
137
- children: [
138
- jsx("span", {
139
- title: t("toolbar.revision"),
140
- style: { fontSize: "12px", padding: "2px 8px", borderRadius: "999px", border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35))" },
141
- children: "rev " + String(doc && typeof doc.revision === "number" ? doc.revision : 0),
142
- }),
143
- button(t("toolbar.save") + (dirty ? " •" : ""), onSave, { primary: true, disabled: dirty === false, hook: "save" }),
144
- button(t("toolbar.reload"), onReload),
145
- button("↶", onUndo, { title: t("toolbar.undo") }),
146
- button("↷", onRedo, { title: t("toolbar.redo") }),
147
- jsx("span", { style: { width: "1px", height: "18px", background: "var(--dsw-alias-border-l2, rgba(127,127,127,.3))" } }),
148
- button("−", () => onZoom(1 / 1.15), { title: t("toolbar.zoomOut") }),
149
- jsx("span", { style: { fontSize: "12px", minWidth: "42px", textAlign: "center" }, children: Math.round((view.z || 1) * 100) + "%" }),
150
- button("+", () => onZoom(1.15), { title: t("toolbar.zoomIn") }),
151
- button(t("toolbar.fit"), onFit),
152
- button(t("toolbar.layout"), onLayout),
153
- jsx("span", { style: { width: "1px", height: "18px", background: "var(--dsw-alias-border-l2, rgba(127,127,127,.3))" } }),
154
- button(t("toolbar.diagram"), () => onMode("canvas"), { hook: "mode-canvas", primary: mode === "canvas" }),
155
- button(t("toolbar.spec"), () => onMode("spec"), { hook: "mode-spec", primary: mode === "spec" }),
156
- jsx("span", { style: { width: "1px", height: "18px", background: "var(--dsw-alias-border-l2, rgba(127,127,127,.3))" } }),
157
- button(run === null ? t("run.start") : t("run.advance"), onRun, { hook: "run", primary: true }),
158
- run === null ? null : button(t("run.cancel"), () => onRun("cancel"), { hook: "run-cancel" }),
159
- run === null ? null : jsx("span", {
160
- "data-gbh-run-status": run.status,
161
- style: { fontSize: "11.5px", padding: "2px 8px", borderRadius: "999px", border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35))" },
162
- children: t("run.status") + ": " + run.status,
163
- }),
164
- button("+ " + KIND_LABEL.gate, () => onAdd("gate"), { add: "gate" }),
165
- button("+ " + KIND_LABEL.action, () => onAdd("action"), { add: "action" }),
166
- button("+ " + KIND_LABEL.approval, () => onAdd("approval"), { add: "approval" }),
167
- button("+ " + KIND_LABEL.join, () => onAdd("join"), { add: "join" }),
168
- button("+ " + KIND_LABEL.notify, () => onAdd("notify"), { add: "notify" }),
169
- jsx("span", { style: { marginLeft: "auto", fontSize: "12px", opacity: 0.75 }, children: status }),
170
- ],
171
- });
172
- }
173
-
174
- function NodeCard(props) {
175
- const { node, selected, issue, runState, step, dropTarget, onPointerDown, onPortDown, onSelect } = props;
176
- const color = KIND_COLOR[node.kind] || "#5a6472";
177
- const badgeColor = RUN_COLOR[runState] || "transparent";
178
- const description = typeof node.description === "string" ? node.description.trim() : "";
179
- const edgeColor = dropTarget ? "#2fa36b" : selected ? "#4f7cff" : "var(--dsw-alias-border-l2, rgba(127,127,127,.4))";
180
- return jsxs("div", {
181
- "data-gbh-node": node.id,
182
- onPointerDown: event => { onSelect(node.id, event.shiftKey); onPointerDown(event, node); },
183
- style: {
184
- position: "absolute", left: node.x ?? 0, top: node.y ?? 0, width: NODE_W + "px", minHeight: NODE_H + "px",
185
- borderRadius: "10px", background: "var(--dsw-alias-bg-module-platform, #23232a)",
186
- border: "1px solid " + edgeColor,
187
- boxShadow: dropTarget ? "0 0 0 3px rgba(47,163,107,.45)" : selected ? "0 0 0 2px rgba(79,124,255,.35)" : "0 6px 18px rgba(0,0,0,.25)",
188
- cursor: "grab", userSelect: "none", overflow: "visible",
189
- },
190
- children: [
191
- jsxs("div", {
192
- style: { display: "flex", alignItems: "center", gap: "6px", padding: "8px 10px", borderBottom: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.22))" },
193
- children: [
194
- jsx("span", { style: { width: "8px", height: "8px", borderRadius: "50%", background: color, flex: "0 0 auto" } }),
195
- step === undefined ? null : jsx("span", {
196
- title: t("node.step"),
197
- style: { flex: "0 0 auto", fontSize: "10px", opacity: 0.6, fontVariantNumeric: "tabular-nums" },
198
- children: String(step),
199
- }),
200
- jsx("span", { style: { fontSize: "12.5px", fontWeight: 600, flex: "1 1 auto", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: node.label || node.id }),
201
- description.length > 0 ? null : jsx("span", {
202
- "data-gbh-node-nodesc": "1",
203
- title: t("node.noDescription"),
204
- style: { flex: "0 0 auto", fontSize: "10.5px", color: "#e0a92b", cursor: "help" },
205
- children: "?",
206
- }),
207
- runState === undefined ? null : jsx("span", {
208
- title: RUN_LABEL[runState] || runState,
209
- style: { flex: "0 0 auto", fontSize: "10.5px", padding: "1px 6px", borderRadius: "999px", background: badgeColor, color: runState === "pending" ? "inherit" : "#101014" },
210
- children: RUN_LABEL[runState] || runState,
211
- }),
212
- ],
213
- }),
214
- jsxs("div", {
215
- style: { padding: "6px 10px 8px", fontSize: "11px", opacity: 0.72, display: "flex", flexDirection: "column", gap: "2px" },
216
- children: [
217
- jsx("span", { children: KIND_LABEL[node.kind] || node.kind }),
218
- node.kind === "action" ? jsx("span", { children: (node.actions || []).map(a => a.kind).join(", ") || "—" }) : null,
219
- description.length > 0 ? jsx("span", {
220
- title: description,
221
- style: { display: "-webkit-box", WebkitLineClamp: "3", WebkitBoxOrient: "vertical", overflow: "hidden", lineHeight: "14px", opacity: 0.95 },
222
- children: description,
223
- }) : null,
224
- issue ? jsx("span", { style: { color: "#ff8a8a" }, children: "⚠ " + issue.message }) : null,
225
- ],
226
- }),
227
- jsx("span", {
228
- onPointerDown: event => { event.stopPropagation(); onPortDown(event, node, "out"); },
229
- title: t("node.outPort"),
230
- style: { position: "absolute", right: "-7px", top: (NODE_H / 2 - 7) + "px", width: "14px", height: "14px", borderRadius: "50%", background: color, border: "2px solid var(--dsw-alias-bg-module-platform, #23232a)", cursor: "crosshair" },
231
- }),
232
- jsx("span", {
233
- "data-gbh-port-in": node.id,
234
- title: t("node.inPort"),
235
- style: { position: "absolute", left: "-7px", top: (NODE_H / 2 - 7) + "px", width: "14px", height: "14px", borderRadius: "50%", background: "var(--dsw-alias-bg-module-platform, #23232a)", border: "2px solid " + color, cursor: "crosshair" },
236
- }),
237
- ],
238
- });
239
- }
240
-
241
- function Inspector(props) {
242
- const { doc, selection, onPatchNode, onDeleteNode, onPatchEdge, onDeleteEdge, issues, run, onDecide } = props;
243
- if (selection === null) {
244
- return jsx("div", { style: { width: "280px", flex: "0 0 auto", borderLeft: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.25))", padding: "12px", fontSize: "12px", opacity: 0.7 }, children: t("inspector.empty") });
245
- }
246
- const field = { width: "100%", boxSizing: "border-box", height: "30px", borderRadius: "8px", border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35))", background: "transparent", color: "inherit", padding: "0 8px", fontSize: "12.5px", marginBottom: "8px" };
247
- const label = { display: "block", fontSize: "11px", opacity: 0.65, margin: "2px 0 4px" };
248
- const node = selection.kind === "node" ? (doc.nodes || []).find(n => n.id === selection.id) : undefined;
249
- const edge = selection.kind === "edge" ? (doc.edges || []).find(e => e.id === selection.id) : undefined;
250
- const nodeIssues = issues.filter(i => i.nodeId === (node && node.id));
251
- const nodeRun = node !== undefined && run !== null && Array.isArray(run.nodes) ? run.nodes.find(entry => entry.nodeId === node.id) : undefined;
252
- return jsxs("div", {
253
- style: { width: "280px", flex: "0 0 auto", borderLeft: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.25))", padding: "12px", overflowY: "auto" },
254
- children: [
255
- jsx("div", { style: { fontSize: "12px", fontWeight: 600, marginBottom: "10px" }, children: node ? t("inspector.node") : t("inspector.edge") }),
256
- node ? jsxs("div", { children: [
257
- jsx("span", { style: label, children: t("inspector.id") }),
258
- jsx("input", { style: field, value: node.id, disabled: true }),
259
- jsx("span", { style: label, children: t("inspector.label") }),
260
- jsx("input", { style: field, value: node.label || "", onChange: event => onPatchNode(node.id, { label: event.target.value }) }),
261
- jsx("span", { style: label, children: t("inspector.description") }),
262
- jsx("textarea", {
263
- "data-gbh-description": node.id,
264
- style: { ...field, height: "76px", padding: "6px 8px", resize: "vertical", fontFamily: "inherit" },
265
- placeholder: t("inspector.descriptionHint"),
266
- value: node.description || "",
267
- onChange: event => onPatchNode(node.id, { description: event.target.value }),
268
- }),
269
- jsx("span", { style: label, children: t("inspector.kind") }),
270
- jsx("select", {
271
- style: field, value: node.kind, onChange: event => onPatchNode(node.id, { kind: event.target.value }),
272
- children: Object.keys(KIND_LABEL).map(kind => jsx("option", { value: kind, children: KIND_LABEL[kind] }, kind)),
273
- }),
274
- node.kind === "gate" ? jsxs("div", { children: [
275
- jsx("span", { style: label, children: t("inspector.workflow") }),
276
- jsx("input", { style: field, value: (node.gate && node.gate.workflow) || "", onChange: event => onPatchNode(node.id, { gate: { ...(node.gate || { kind: "ci" }), workflow: event.target.value } }) }),
277
- ] }) : null,
278
- node.kind === "action" ? jsxs("div", { children: [
279
- jsx("span", { style: label, children: t("inspector.actions") }),
280
- jsx("textarea", {
281
- style: { ...field, height: "96px", padding: "6px 8px", fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace", resize: "vertical" },
282
- value: JSON.stringify(node.actions || [], null, 1),
283
- onChange: event => {
284
- try { onPatchNode(node.id, { actions: JSON.parse(event.target.value) }); } catch (error) { /* keep typing */ }
285
- },
286
- }),
287
- ] }) : null,
288
- nodeIssues.length > 0 ? jsx("div", { style: { fontSize: "11px", color: "#ff8a8a", marginBottom: "8px" }, children: nodeIssues.map(i => i.message).join(" · ") }) : null,
289
- nodeRun !== undefined && (nodeRun.state === "awaiting_approval" || nodeRun.state === "blocked") ? jsxs("div", { style: { marginBottom: "10px" }, children: [
290
- jsx("div", { style: { fontSize: "11.5px", marginBottom: "6px" }, children: t("run.waiting") + ": " + String(nodeRun.last?.note ?? nodeRun.state) }),
291
- jsxs("div", { style: { display: "flex", gap: "8px" }, children: [
292
- jsx("button", {
293
- type: "button", "data-gbh-decide": "approve", onClick: () => onDecide(node.id, "approve"),
294
- style: { ...field, marginBottom: 0, flex: "1 1 auto", cursor: "pointer", border: "none", background: "#2fa36b", color: "#08110c", fontWeight: 600 },
295
- children: t("run.approve"),
296
- }),
297
- jsx("button", {
298
- type: "button", "data-gbh-decide": "reject", onClick: () => onDecide(node.id, "reject"),
299
- style: { ...field, marginBottom: 0, flex: "1 1 auto", cursor: "pointer", border: "1px solid rgba(229,72,77,.6)", background: "transparent", color: "#ff8a8a" },
300
- children: t("run.reject"),
301
- }),
302
- jsx("button", {
303
- type: "button", "data-gbh-decide": "retry", onClick: () => onDecide(node.id, "retry"),
304
- style: { ...field, marginBottom: 0, flex: "0 0 auto", cursor: "pointer" },
305
- children: t("run.retry"),
306
- }),
307
- ] }),
308
- ] }) : null,
309
- jsx("button", { type: "button", onClick: () => onDeleteNode(node.id), style: { ...field, cursor: "pointer", color: "#ff8a8a" }, children: t("inspector.deleteNode") }),
310
- ] }) : null,
311
- edge ? jsxs("div", { children: [
312
- jsx("span", { style: label, children: t("inspector.from") }),
313
- jsx("input", { style: field, value: edge.from, disabled: true }),
314
- jsx("span", { style: label, children: t("inspector.to") }),
315
- jsx("input", { style: field, value: edge.to, disabled: true }),
316
- jsx("span", { style: label, children: t("inspector.when") }),
317
- jsx("select", {
318
- style: field, value: edge.when || "success", onChange: event => onPatchEdge(edge.id, { when: event.target.value }),
319
- children: ["success", "failure", "always"].map(when => jsx("option", { value: when, children: WHEN_LABEL[when] }, when)),
320
- }),
321
- jsx("button", { type: "button", onClick: () => onDeleteEdge(edge.id), style: { ...field, cursor: "pointer", color: "#ff8a8a" }, children: t("inspector.deleteEdge") }),
322
- ] }) : null,
323
- ],
324
- });
325
- }
326
-
327
- /** The panel root: loads the blueprint, edits it in memory, and saves it back. */
328
- function JourneyPanel(props) {
329
- const sessionId = props.sessionId;
330
- const [doc, setDoc] = react.useState(null);
331
- const [view, setView] = react.useState({ tx: 40, ty: 20, z: 0.9 });
332
- const [selection, setSelection] = react.useState(null);
333
- const [picked, setPicked] = react.useState([]);
334
- const [run, setRun] = react.useState(null);
335
- const [mode, setMode] = react.useState("canvas");
336
- const [specText, setSpecText] = react.useState("");
337
- const [specError, setSpecError] = react.useState(null);
338
- const [box, setBox] = react.useState(null);
339
- const [canvasSize, setCanvasSize] = react.useState({ width: 900, height: 520 });
340
- const clipboard = react.useRef(null);
341
- const [status, setStatus] = react.useState(t("status.loading"));
342
- const [dirty, setDirty] = react.useState(false);
343
- const [conflict, setConflict] = react.useState(null);
344
- const [pending, setPending] = react.useState(null);
345
- const history = react.useRef({ past: [], future: [] });
346
- const drag = react.useRef(null);
347
- const canvasRef = react.useRef(null);
348
-
349
- const load = react.useCallback(() => {
350
- setStatus(t("status.loading"));
351
- api.load(sessionId).then(result => {
352
- if (result.ok !== true) { setStatus(result.message || t("status.loadFailed")); return; }
353
- setDoc(result.document);
354
- setDirty(false);
355
- setConflict(null);
356
- history.current = { past: [], future: [] };
357
- setStatus(result.exists ? t("status.loaded") : t("status.newBlueprint"));
358
- });
359
- }, [sessionId]);
360
-
361
- react.useEffect(() => { load(); }, [load]);
362
-
363
- /* Keep the minimap's viewport rectangle honest. */
364
- react.useEffect(() => {
365
- const measure = () => {
366
- const element = canvasRef.current;
367
- if (element === null) return;
368
- setCanvasSize({ width: element.clientWidth, height: element.clientHeight });
369
- };
370
- measure();
371
- window.addEventListener("resize", measure);
372
- return () => window.removeEventListener("resize", measure);
373
- }, []);
374
-
375
- /* Poll the active run so the canvas tracks what the agent (or another tab) does. */
376
- react.useEffect(() => {
377
- let stopped = false;
378
- const tick = () => {
379
- if (stopped) return;
380
- api.run(sessionId, { op: "status", runId: "latest" }).then(result => {
381
- if (stopped) return;
382
- if (result.ok === true && result.run !== undefined) setRun(result.run);
383
- else if (result.ok === true && Array.isArray(result.runs)) setRun(result.runs[0] ?? null);
384
- });
385
- };
386
- tick();
387
- const timer = setInterval(tick, 2500);
388
- return () => { stopped = true; clearInterval(timer); };
389
- }, [sessionId, run === null ? "" : run.id]);
390
-
391
- /* Notice blueprint edits made elsewhere: silent reload when clean, banner when dirty. */
392
- react.useEffect(() => {
393
- let stopped = false;
394
- const timer = setInterval(() => {
395
- api.load(sessionId).then(result => {
396
- if (stopped || result.ok !== true) return;
397
- const live = typeof result.revision === "number" ? result.revision : 0;
398
- const mine = doc === null ? 0 : (typeof doc.revision === "number" ? doc.revision : 0);
399
- if (live === mine) return;
400
- if (dirty) { setConflict({ revision: live, document: result.document }); return; }
401
- setDoc(result.document);
402
- setStatus(t("status.reloaded"));
403
- });
404
- }, 4000);
405
- return () => { stopped = true; clearInterval(timer); };
406
- }, [sessionId, doc, dirty]);
407
-
408
- const remember = react.useCallback(() => {
409
- if (doc === null) return;
410
- history.current.past.push(JSON.stringify(doc));
411
- if (history.current.past.length > 50) history.current.past.shift();
412
- history.current.future = [];
413
- }, [doc]);
414
-
415
- const mutate = react.useCallback(updater => {
416
- setDoc(current => {
417
- if (current === null) return current;
418
- const next = updater(clone(current));
419
- setDirty(true);
420
- return next;
421
- });
422
- }, []);
423
-
424
- const issues = react.useMemo(() => (doc === null ? [] : issuesOf(doc)), [doc]);
425
-
426
- const addNode = react.useCallback(kind => {
427
- remember();
428
- mutate(current => {
429
- const taken = (current.nodes || []).map(n => n.id);
430
- const id = nextId(kind + "-", taken);
431
- const maxY = (current.nodes || []).reduce((top, n) => Math.max(top, n.y ?? 0), 0);
432
- const node = { id, kind, label: KIND_LABEL[kind] + " " + id.split("-")[1], x: 120, y: snap(maxY + 110) };
433
- if (kind === "action") node.actions = [{ kind: "command", run: "echo TODO" }];
434
- if (kind === "gate") node.gate = { kind: "ci", workflow: "ci.yml", ref: "main" };
435
- current.nodes = [...(current.nodes || []), node];
436
- return current;
437
- });
438
- }, [mutate, remember]);
439
-
440
- const patchNode = react.useCallback((id, patch) => {
441
- remember();
442
- mutate(current => {
443
- current.nodes = (current.nodes || []).map(node => (node.id === id ? { ...node, ...patch } : node));
444
- return current;
445
- });
446
- }, [mutate, remember]);
447
-
448
- const deleteNode = react.useCallback(id => {
449
- remember();
450
- mutate(current => {
451
- current.nodes = (current.nodes || []).filter(node => node.id !== id);
452
- current.edges = (current.edges || []).filter(edge => edge.from !== id && edge.to !== id);
453
- return current;
454
- });
455
- setSelection(null);
456
- }, [mutate, remember]);
457
-
458
- const patchEdge = react.useCallback((id, patch) => {
459
- remember();
460
- mutate(current => {
461
- current.edges = (current.edges || []).map(edge => (edge.id === id ? { ...edge, ...patch } : edge));
462
- return current;
463
- });
464
- }, [mutate, remember]);
465
-
466
- const deleteEdge = react.useCallback(id => {
467
- remember();
468
- mutate(current => {
469
- current.edges = (current.edges || []).filter(edge => edge.id !== id);
470
- return current;
471
- });
472
- setSelection(null);
473
- }, [mutate, remember]);
474
-
475
- const addEdge = react.useCallback((from, to) => {
476
- if (from === to) return;
477
- remember();
478
- mutate(current => {
479
- const exists = (current.edges || []).some(edge => edge.from === from && edge.to === to);
480
- if (exists) return current;
481
- const taken = (current.edges || []).map(edge => edge.id);
482
- current.edges = [...(current.edges || []), { id: nextId("e", taken), from, to, when: "success" }];
483
- return current;
484
- });
485
- }, [mutate, remember]);
486
-
487
- const save = react.useCallback(() => {
488
- if (doc === null) return;
489
- setStatus(t("status.saving"));
490
- api.save(sessionId, doc, typeof doc.revision === "number" ? doc.revision : 0).then(result => {
491
- if (result.ok === true) {
492
- setDoc(current => ({ ...current, revision: result.revision }));
493
- setDirty(false);
494
- setConflict(null);
495
- setStatus(t("status.saved") + " · rev " + result.revision);
496
- return;
497
- }
498
- if (result.code === "journey/conflict") { setConflict(result.current || null); setStatus(t("status.conflict")); return; }
499
- setStatus((result.message || t("status.saveFailed")) + (result.issues ? " · " + result.issues.map(i => i.message).join("; ") : ""));
500
- });
501
- }, [doc, sessionId]);
502
-
503
- const pointerToCanvas = event => {
504
- const rect = canvasRef.current ? canvasRef.current.getBoundingClientRect() : { left: 0, top: 0 };
505
- return { x: (event.clientX - rect.left - view.tx) / view.z, y: (event.clientY - rect.top - view.ty) / view.z };
506
- };
507
-
508
- const startNodeDrag = (event, node) => {
509
- if (event.button !== 0) return;
510
- const start = pointerToCanvas(event);
511
- drag.current = { type: "node", id: node.id, dx: start.x - (node.x ?? 0), dy: start.y - (node.y ?? 0) };
512
- remember();
513
- try { event.currentTarget.setPointerCapture(event.pointerId); } catch (error) { /* ignore */ }
514
- };
515
-
516
- const startPan = event => {
517
- if (event.button !== 0 || event.target !== event.currentTarget) return;
518
- if (event.shiftKey) {
519
- const point = pointerToCanvas(event);
520
- drag.current = { type: "box", start: point };
521
- setBox({ x: point.x, y: point.y, w: 0, h: 0 });
522
- try { event.currentTarget.setPointerCapture(event.pointerId); } catch (error) { /* ignore */ }
523
- return;
524
- }
525
- drag.current = { type: "pan", x: event.clientX, y: event.clientY, tx: view.tx, ty: view.ty };
526
- setSelection(null);
527
- setPicked([]);
528
- try { event.currentTarget.setPointerCapture(event.pointerId); } catch (error) { /* ignore */ }
529
- };
530
-
531
- const onPointerMove = event => {
532
- const state = drag.current;
533
- if (state === null || state === undefined) return;
534
- if (state.type === "pan") {
535
- setView(current => ({ ...current, tx: state.tx + (event.clientX - state.x), ty: state.ty + (event.clientY - state.y) }));
536
- return;
537
- }
538
- if (state.type === "node") {
539
- const point = pointerToCanvas(event);
540
- mutate(current => {
541
- current.nodes = (current.nodes || []).map(node => (node.id === state.id ? { ...node, x: snap(point.x - state.dx), y: snap(point.y - state.dy) } : node));
542
- return current;
543
- });
544
- return;
545
- }
546
- if (state.type === "box") {
547
- const point = pointerToCanvas(event);
548
- setBox({
549
- x: Math.min(state.start.x, point.x),
550
- y: Math.min(state.start.y, point.y),
551
- w: Math.abs(point.x - state.start.x),
552
- h: Math.abs(point.y - state.start.y),
553
- });
554
- }
555
- };
556
-
557
- const endDrag = () => {
558
- const state = drag.current;
559
- /* An edge drag is owned by the window listeners that resolve its drop, so this
560
- handler leaves it alone. Everything else — a node drag, a pan, a rubber band —
561
- is released here: forget that and the node keeps following the pointer. */
562
- if (state !== null && state !== undefined && state.type === "edge") return;
563
- drag.current = null;
564
- if (state === null || state === undefined || state.type !== "box") return;
565
- setBox(current => {
566
- if (current !== null && doc !== null) {
567
- const inside = (doc.nodes || []).filter(node => {
568
- const x = node.x ?? 0;
569
- const y = node.y ?? 0;
570
- return x + NODE_W >= current.x && x <= current.x + current.w && y + NODE_H >= current.y && y <= current.y + current.h;
571
- });
572
- setPicked(inside.map(node => "node:" + node.id));
573
- if (inside.length > 0) setSelection({ kind: "node", id: inside[inside.length - 1].id });
574
- }
575
- return null;
576
- });
577
- };
578
-
579
- /** The node under a viewport point: a connection may land anywhere on the card. */
580
- const nodeAtPoint = event => {
581
- const point = pointerToCanvas(event);
582
- const nodes = (doc && doc.nodes) || [];
583
- for (let index = nodes.length - 1; index >= 0; index -= 1) {
584
- const node = nodes[index];
585
- const x = node.x ?? 0;
586
- const y = node.y ?? 0;
587
- if (point.x >= x - 8 && point.x <= x + NODE_W + 8 && point.y >= y - 8 && point.y <= y + NODE_H + 46) return node.id;
588
- }
589
- return undefined;
590
- };
591
-
592
- /**
593
- * Drag from an out port to any other node to connect them.
594
- *
595
- * The listeners live on the window (capture) instead of a pointer capture on the
596
- * port: a capture retargets the release to the port itself, so the drop target
597
- * never hears it and no edge is ever created.
598
- */
599
- const startEdge = (event, node) => {
600
- if (event.button !== 0) return;
601
- const point = pointerToCanvas(event);
602
- drag.current = { type: "edge", from: node.id };
603
- setPending({ from: node.id, x: point.x, y: point.y, to: undefined });
604
- const move = moveEvent => {
605
- const next = pointerToCanvas(moveEvent);
606
- setPending({ from: node.id, x: next.x, y: next.y, to: nodeAtPoint(moveEvent) });
607
- };
608
- const finish = upEvent => {
609
- window.removeEventListener("pointermove", move, true);
610
- window.removeEventListener("pointerup", finish, true);
611
- const state = drag.current;
612
- drag.current = null;
613
- setPending(null);
614
- if (state === null || state === undefined || state.type !== "edge") return;
615
- const to = nodeAtPoint(upEvent);
616
- if (to !== undefined) addEdge(state.from, to);
617
- };
618
- window.addEventListener("pointermove", move, true);
619
- window.addEventListener("pointerup", finish, true);
620
- };
621
-
622
- /** Zoom so the canvas point under `anchor` (viewport pixels) stays put. */
623
- const zoomAt = react.useCallback((factor, anchor) => {
624
- setView(current => {
625
- const z = Math.min(1.8, Math.max(0.4, current.z * factor));
626
- if (z === current.z) return current;
627
- const k = z / current.z;
628
- return { z: z, tx: anchor.x - (anchor.x - current.tx) * k, ty: anchor.y - (anchor.y - current.ty) * k };
629
- });
630
- }, []);
631
-
632
- /** The toolbar buttons zoom around the middle of the canvas. */
633
- const zoomAtCenter = factor => {
634
- const element = canvasRef.current;
635
- if (element === null) { zoomAt(factor, { x: 450, y: 260 }); return; }
636
- const rect = element.getBoundingClientRect();
637
- zoomAt(factor, { x: rect.width / 2, y: rect.height / 2 });
638
- };
639
-
640
- /* The wheel zooms where the pointer is, not at the canvas origin. */
641
- const onWheel = event => {
642
- const rect = canvasRef.current ? canvasRef.current.getBoundingClientRect() : { left: 0, top: 0 };
643
- zoomAt(event.deltaY < 0 ? 1.08 : 1 / 1.08, { x: event.clientX - rect.left, y: event.clientY - rect.top });
644
- };
645
-
646
- const fit = () => {
647
- const nodes = (doc && doc.nodes) || [];
648
- if (nodes.length === 0) return;
649
- const maxX = nodes.reduce((value, node) => Math.max(value, (node.x ?? 0) + NODE_W), 0);
650
- const maxY = nodes.reduce((value, node) => Math.max(value, (node.y ?? 0) + NODE_H), 0);
651
- const width = canvasRef.current ? canvasRef.current.clientWidth : 900;
652
- const height = canvasRef.current ? canvasRef.current.clientHeight : 500;
653
- const z = Math.min(1.2, Math.max(0.4, Math.min(width / (maxX + 80), height / (maxY + 80))));
654
- setView({ tx: 30, ty: 20, z });
655
- };
656
-
657
- /** Layered left-to-right placement: depth = longest path from a source node. */
658
- const autoLayout = () => {
659
- remember();
660
- mutate(current => {
661
- const nodes = current.nodes || [];
662
- const edges = current.edges || [];
663
- const depth = new Map(nodes.map(node => [node.id, 0]));
664
- for (let pass = 0; pass < nodes.length; pass += 1) {
665
- for (const edge of edges) {
666
- const from = depth.get(edge.from) ?? 0;
667
- const to = depth.get(edge.to) ?? 0;
668
- if (to < from + 1) depth.set(edge.to, from + 1);
669
- }
670
- }
671
- const rows = new Map();
672
- for (const node of nodes) {
673
- const column = depth.get(node.id) ?? 0;
674
- const row = rows.get(column) ?? 0;
675
- rows.set(column, row + 1);
676
- node.x = 80 + column * 260;
677
- node.y = 60 + row * 120;
678
- }
679
- return current;
680
- });
681
- };
682
-
683
- const undo = () => {
684
- const past = history.current.past;
685
- if (past.length === 0) return;
686
- const snapshot = past.pop();
687
- history.current.future.push(JSON.stringify(doc));
688
- setDoc(JSON.parse(snapshot));
689
- setDirty(true);
690
- };
691
-
692
- const redo = () => {
693
- const future = history.current.future;
694
- if (future.length === 0) return;
695
- const snapshot = future.pop();
696
- history.current.past.push(JSON.stringify(doc));
697
- setDoc(JSON.parse(snapshot));
698
- setDirty(true);
699
- };
700
-
701
- const pickKey = item => item.kind + ":" + item.id;
702
- const isPicked = item => picked.indexOf(pickKey(item)) !== -1;
703
-
704
- const pick = (item, additive) => {
705
- setSelection(item);
706
- const key = pickKey(item);
707
- if (additive === true) setPicked(current => (current.indexOf(key) === -1 ? [...current, key] : current.filter(entry => entry !== key)));
708
- else setPicked([key]);
709
- };
710
-
711
- const pickEdge = (id, additive) => pick({ kind: "edge", id: id }, additive);
712
-
713
- const pickedNodes = () => picked.filter(key => key.indexOf("node:") === 0).map(key => key.slice(5));
714
- const pickedEdges = () => picked.filter(key => key.indexOf("edge:") === 0).map(key => key.slice(5));
715
-
716
- const deleteSelected = () => {
717
- const nodes = pickedNodes();
718
- const edges = pickedEdges();
719
- if (nodes.length === 0 && edges.length === 0) return;
720
- remember();
721
- mutate(current => {
722
- current.nodes = (current.nodes || []).filter(node => nodes.indexOf(node.id) === -1);
723
- current.edges = (current.edges || []).filter(edge => edges.indexOf(edge.id) === -1 && nodes.indexOf(edge.from) === -1 && nodes.indexOf(edge.to) === -1);
724
- return current;
725
- });
726
- setPicked([]);
727
- setSelection(null);
728
- };
729
-
730
- const copySelection = () => {
731
- const nodes = (doc.nodes || []).filter(node => pickedNodes().indexOf(node.id) !== -1);
732
- if (nodes.length === 0) return;
733
- const ids = nodes.map(node => node.id);
734
- clipboard.current = {
735
- nodes: clone(nodes),
736
- edges: clone((doc.edges || []).filter(edge => ids.indexOf(edge.from) !== -1 && ids.indexOf(edge.to) !== -1)),
737
- };
738
- };
739
-
740
- const pasteSelection = () => {
741
- const clip = clipboard.current;
742
- if (clip === null) return;
743
- remember();
744
- const mapping = new Map();
745
- mutate(current => {
746
- const taken = (current.nodes || []).map(node => node.id);
747
- for (const node of clip.nodes) {
748
- const id = nextId(node.kind + "-", taken);
749
- taken.push(id);
750
- mapping.set(node.id, id);
751
- current.nodes = [...(current.nodes || []), { ...clone(node), id, label: (node.label || node.id) + " (bản sao)", x: (node.x ?? 0) + 40, y: (node.y ?? 0) + 40 }];
752
- }
753
- const edgeTaken = (current.edges || []).map(edge => edge.id);
754
- for (const edge of clip.edges) {
755
- const id = nextId("e", edgeTaken);
756
- edgeTaken.push(id);
757
- current.edges = [...(current.edges || []), { ...clone(edge), id, from: mapping.get(edge.from), to: mapping.get(edge.to) }];
758
- }
759
- return current;
760
- });
761
- setPicked([...mapping.values()].map(id => "node:" + id));
762
- };
763
-
764
- /** Drive the run: start, advance, cancel, or decide a waiting node. */
765
- const runAction = (op, extra) => {
766
- setStatus(t("run.working"));
767
- api.run(sessionId, { op: op, ...(run === null || run.id === undefined ? {} : { runId: run.id }), ...(extra || {}) }).then(result => {
768
- if (result.ok === true && result.run !== undefined) {
769
- setRun(result.run);
770
- setStatus(t("run.status") + ": " + result.run.status);
771
- return;
772
- }
773
- setStatus((result.message || t("run.failed")) + (result.code === undefined ? "" : " (" + result.code + ")"));
774
- });
775
- };
776
-
777
- const decide = (nodeId, decision) => runAction("decide", { nodeId: nodeId, decision: decision });
778
-
779
- /** Entering spec mode seeds the editor from the live document. */
780
- const switchMode = next => {
781
- if (next === "spec" && doc !== null) {
782
- setSpecText(JSON.stringify(doc, null, 2));
783
- setSpecError(null);
784
- }
785
- setMode(next);
786
- };
787
-
788
- const applySpec = () => {
789
- try {
790
- const parsed = JSON.parse(specText);
791
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error(t("spec.notObject"));
792
- remember();
793
- setDoc({ ...parsed, revision: doc === null ? 0 : doc.revision });
794
- setDirty(true);
795
- setSpecError(null);
796
- setStatus(t("spec.applied"));
797
- } catch (error) {
798
- setSpecError(error instanceof Error ? error.message : String(error));
799
- }
800
- };
801
-
802
- const onKeyDown = event => {
803
- if (event.key === "Escape") {
804
- if (pending === null) return;
805
- event.preventDefault();
806
- drag.current = null;
807
- setPending(null);
808
- return;
809
- }
810
- if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "z") {
811
- event.preventDefault();
812
- if (event.shiftKey) redo(); else undo();
813
- return;
814
- }
815
- if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "c") { event.preventDefault(); copySelection(); return; }
816
- if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "v") { event.preventDefault(); pasteSelection(); return; }
817
- if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "a") {
818
- event.preventDefault();
819
- setPicked((doc && doc.nodes ? doc.nodes : []).map(node => "node:" + node.id));
820
- return;
821
- }
822
- if (event.key === "Delete" || event.key === "Backspace") {
823
- if (picked.length > 0) { event.preventDefault(); deleteSelected(); return; }
824
- if (selection === null) return;
825
- event.preventDefault();
826
- if (selection.kind === "node") deleteNode(selection.id); else deleteEdge(selection.id);
827
- }
828
- };
829
-
830
- if (doc === null) {
831
- return jsx("div", { style: { padding: "18px", fontSize: "13px", opacity: 0.8 }, children: status });
832
- }
833
-
834
- const nodes = doc.nodes || [];
835
- const edges = doc.edges || [];
836
- const byId = new Map(nodes.map(node => [node.id, node]));
837
- const issueByNode = new Map();
838
- for (const issue of issues) if (issue.nodeId !== undefined && !issueByNode.has(issue.nodeId)) issueByNode.set(issue.nodeId, issue);
839
- /* Read order of the graph, and the node(s) whose edges stay lit while inspecting. */
840
- const steps = depthMap(nodes, edges);
841
- const focusIds = pickedNodes();
842
-
843
- return jsxs("div", {
844
- onKeyDown,
845
- tabIndex: 0,
846
- style: { display: "flex", flexDirection: "column", height: "100%", outline: "none", background: "var(--dsw-alias-bg-base, #1b1b20)", color: "var(--dsw-alias-label-primary, #f2f2f2)" },
847
- children: [
848
- jsx(Toolbar, {
849
- doc, dirty, status: conflict === null ? status : t("status.conflict"),
850
- view, onSave: save, onReload: load,
851
- onZoom: zoomAtCenter,
852
- onFit: fit, onLayout: autoLayout, onAdd: addNode, onUndo: undo, onRedo: redo,
853
- run, mode, onMode: switchMode,
854
- onRun: op => runAction(typeof op === "string" ? op : (run === null ? "start" : "advance")),
855
- }),
856
- conflict === null ? null : jsxs("div", {
857
- style: { display: "flex", alignItems: "center", gap: "10px", padding: "8px 12px", background: "rgba(224,169,43,.14)", borderBottom: "1px solid rgba(224,169,43,.4)", fontSize: "12px" },
858
- children: [
859
- jsx("span", { children: t("conflict.banner") }),
860
- jsx("button", { type: "button", onClick: load, style: { height: "26px", padding: "0 10px", borderRadius: "7px", border: "1px solid rgba(127,127,127,.4)", background: "transparent", color: "inherit", cursor: "pointer" }, children: t("conflict.reload") }),
861
- ],
862
- }),
863
- mode === "spec" ? jsx(SpecEditor, {
864
- doc, text: specText, error: specError,
865
- onChange: setSpecText, onApply: applySpec,
866
- onReset: () => { setSpecText(doc === null ? "" : JSON.stringify(doc, null, 2)); setSpecError(null); },
867
- }) : jsxs("div", { style: { display: "flex", flex: "1 1 auto", minHeight: 0 }, children: [
868
- jsxs("div", {
869
- ref: canvasRef,
870
- "data-gbh-journey": "canvas",
871
- onPointerDown: startPan,
872
- onPointerMove,
873
- onPointerUp: endDrag,
874
- onPointerLeave: endDrag,
875
- onWheel,
876
- style: {
877
- position: "relative", flex: "1 1 auto", overflow: "hidden", cursor: "grab",
878
- backgroundImage: "radial-gradient(var(--dsw-alias-border-l2, rgba(127,127,127,.35)) 1px, transparent 1px)",
879
- backgroundSize: (22 * view.z) + "px " + (22 * view.z) + "px",
880
- backgroundPosition: view.tx + "px " + view.ty + "px",
881
- },
882
- children: [
883
- jsxs("div", {
884
- style: { position: "absolute", left: 0, top: 0, transform: "translate(" + view.tx + "px," + view.ty + "px) scale(" + view.z + ")", transformOrigin: "0 0" },
885
- children: [
886
- jsx("svg", {
887
- width: "6000", height: "4000",
888
- style: { position: "absolute", left: 0, top: 0, pointerEvents: "none", overflow: "visible" },
889
- children: [
890
- /* One arrowhead per condition, so an edge shows which way it runs. */
891
- jsx("defs", {
892
- children: Object.entries(EDGE_COLOR).map(entry => jsx("marker", {
893
- id: "gbh-journey-arrow-" + entry[0],
894
- viewBox: "0 0 8 8", refX: "8", refY: "4", markerWidth: "8", markerHeight: "8",
895
- markerUnits: "userSpaceOnUse", orient: "auto",
896
- children: jsx("path", { d: "M 0 0 L 8 4 L 0 8 z", fill: entry[1] }),
897
- }, entry[0])),
898
- }),
899
- ...edges.map(edge => {
900
- const from = byId.get(edge.from);
901
- const to = byId.get(edge.to);
902
- if (from === undefined || to === undefined) return null;
903
- const selected = picked.indexOf("edge:" + edge.id) !== -1;
904
- const kind = edge.when === "failure" ? "failure" : edge.when === "always" ? "always" : "success";
905
- const color = EDGE_COLOR[kind];
906
- const incident = focusIds.indexOf(edge.from) !== -1 || focusIds.indexOf(edge.to) !== -1;
907
- const mid = edgeMidpoint(from, to);
908
- return jsxs("g", {
909
- "data-gbh-edge": edge.id,
910
- "data-gbh-edge-when": kind,
911
- opacity: focusIds.length > 0 && !incident ? 0.22 : 1,
912
- children: [
913
- jsx("path", {
914
- d: edgePath(from, to), fill: "none", stroke: color,
915
- strokeWidth: selected ? 3 : 2,
916
- strokeDasharray: kind === "failure" ? "6 5" : undefined,
917
- markerEnd: "url(#gbh-journey-arrow-" + kind + ")",
918
- style: { pointerEvents: "stroke", cursor: "pointer" },
919
- onPointerDown: event => { event.stopPropagation(); pickEdge(edge.id, event.shiftKey); },
920
- }),
921
- jsx("text", {
922
- x: mid.x, y: mid.y - 7, textAnchor: "middle", fontSize: "10.5", fill: color,
923
- style: { paintOrder: "stroke", stroke: "var(--dsw-alias-bg-base, #1b1b20)", strokeWidth: "4px", pointerEvents: "none", userSelect: "none" },
924
- children: WHEN_LABEL[kind] || kind,
925
- }),
926
- ],
927
- }, edge.id);
928
- }),
929
- pending === null ? null : jsx("path", {
930
- d: (() => {
931
- const source = byId.get(pending.from);
932
- if (source === undefined) return "";
933
- const anchor = outAnchor(source);
934
- return "M " + anchor.x + " " + anchor.y + " L " + pending.x + " " + pending.y;
935
- })(),
936
- fill: "none", stroke: "#4f7cff", strokeWidth: 2, strokeDasharray: "5 4",
937
- markerEnd: "url(#gbh-journey-arrow-success)",
938
- }),
939
- ],
940
- }),
941
- box === null ? null : jsx("div", {
942
- style: { position: "absolute", left: box.x, top: box.y, width: box.w, height: box.h, border: "1px dashed #4f7cff", background: "rgba(79,124,255,.12)", pointerEvents: "none" },
943
- }),
944
- ...nodes.map(node => jsx(NodeCard, {
945
- node, selected: isPicked({ kind: "node", id: node.id }),
946
- issue: issueByNode.get(node.id),
947
- runState: run !== null && run.nodes !== undefined ? (run.nodes.find(entry => entry.nodeId === node.id) || {}).state : undefined,
948
- step: (steps.get(node.id) ?? 0) + 1,
949
- dropTarget: pending !== null && pending.to === node.id,
950
- onPointerDown: startNodeDrag, onPortDown: startEdge,
951
- onSelect: (id, additive) => pick({ kind: "node", id: id }, additive),
952
- }, node.id)),
953
- ],
954
- }),
955
- issues.length === 0 ? null : jsx("div", {
956
- style: { position: "absolute", left: "12px", bottom: "12px", maxWidth: "60%", padding: "8px 10px", borderRadius: "8px", background: "rgba(229,72,77,.16)", border: "1px solid rgba(229,72,77,.45)", fontSize: "11.5px" },
957
- children: issues.slice(0, 4).map(issue => issue.message).join(" · "),
958
- }),
959
- jsx(Minimap, {
960
- doc, view, canvasSize,
961
- onJump: point => setView(current => ({ ...current, tx: -point.x * current.z + 120, ty: -point.y * current.z + 80 })),
962
- }),
963
- ],
964
- }),
965
- jsx(Inspector, {
966
- doc, selection, issues, run, onDecide: decide,
967
- onPatchNode: patchNode, onDeleteNode: deleteNode, onPatchEdge: patchEdge, onDeleteEdge: deleteEdge,
968
- }),
969
- ]}),
970
- ],
971
- });
972
- }
973
-
974
- /** Small overview of the graph with the current viewport, for quick navigation. */
975
- function Minimap(props) {
976
- const { doc, view, canvasSize, onJump } = props;
977
- const WIDTH = 170;
978
- const HEIGHT = 120;
979
- const nodes = (doc && doc.nodes) || [];
980
- const box = boundsOf(nodes);
981
- const spanX = Math.max(1, box.maxX - box.minX);
982
- const spanY = Math.max(1, box.maxY - box.minY);
983
- const scale = Math.min(WIDTH / spanX, HEIGHT / spanY) * 0.85;
984
- const left = 10;
985
- const top = 10;
986
- const toMini = node => ({ x: left + ((node.x ?? 0) - box.minX) * scale, y: top + ((node.y ?? 0) - box.minY) * scale });
987
- const viewRect = {
988
- x: left + (-view.tx / view.z - box.minX) * scale,
989
- y: top + (-view.ty / view.z - box.minY) * scale,
990
- w: (canvasSize.width / view.z) * scale,
991
- h: (canvasSize.height / view.z) * scale,
992
- };
993
- return jsx("div", {
994
- "data-gbh-minimap": "1",
995
- onClick: event => {
996
- const rect = event.currentTarget.getBoundingClientRect();
997
- onJump({ x: (event.clientX - rect.left - left) / scale + box.minX, y: (event.clientY - rect.top - top) / scale + box.minY });
998
- },
999
- style: { position: "absolute", right: "12px", bottom: "12px", width: WIDTH + "px", height: HEIGHT + "px", borderRadius: "10px", background: "rgba(20,20,24,.85)", border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35))", cursor: "pointer", overflow: "hidden" },
1000
- children: jsxs("svg", {
1001
- width: WIDTH, height: HEIGHT,
1002
- children: [
1003
- ...nodes.map(node => {
1004
- const point = toMini(node);
1005
- return jsx("rect", { x: point.x, y: point.y, width: Math.max(6, NODE_W * scale), height: Math.max(4, NODE_H * scale), rx: 2, fill: KIND_COLOR[node.kind] || "#5a6472", opacity: 0.85 }, node.id);
1006
- }),
1007
- jsx("rect", { x: viewRect.x, y: viewRect.y, width: viewRect.w, height: viewRect.h, fill: "rgba(79,124,255,.14)", stroke: "#4f7cff", strokeWidth: 1, rx: 3 }),
1008
- ],
1009
- }),
1010
- });
1011
- }
1012
-
1013
- /** JSON view of the same document: the agent-readable face of the canvas. */
1014
- function SpecEditor(props) {
1015
- const { doc, text, onChange, onApply, onReset, error } = props;
1016
- return jsxs("div", {
1017
- style: { flex: "1 1 auto", display: "flex", flexDirection: "column", padding: "12px", gap: "8px", minHeight: 0 },
1018
- children: [
1019
- jsxs("div", { style: { display: "flex", gap: "8px", alignItems: "center" }, children: [
1020
- jsx("span", { style: { fontSize: "12px", opacity: 0.7 }, children: t("spec.hint") }),
1021
- jsx("button", { type: "button", "data-gbh-action": "spec-apply", onClick: onApply, style: { marginLeft: "auto", height: "30px", padding: "0 12px", borderRadius: "8px", border: "none", background: "#4f7cff", color: "#fff", cursor: "pointer", fontWeight: 600, fontSize: "12px" }, children: t("spec.apply") }),
1022
- jsx("button", { type: "button", onClick: onReset, style: { height: "30px", padding: "0 12px", borderRadius: "8px", border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35))", background: "transparent", color: "inherit", cursor: "pointer", fontSize: "12px" }, children: t("spec.reset") }),
1023
- ] }),
1024
- jsx("textarea", {
1025
- "data-gbh-spec": "1",
1026
- value: text,
1027
- spellCheck: false,
1028
- onChange: event => onChange(event.target.value),
1029
- style: { flex: "1 1 auto", width: "100%", boxSizing: "border-box", borderRadius: "10px", border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35))", background: "transparent", color: "inherit", padding: "10px 12px", fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace", fontSize: "12.5px", lineHeight: "18px", resize: "none", outline: "none" },
1030
- }),
1031
- error === null ? null : jsx("div", { style: { color: "#ff8a8a", fontSize: "12px" }, children: error }),
1032
- ],
1033
- });
1034
- }
1035
-
1036
- return { JourneyPanel };
1037
- }