@galaxy-stack/blackhole-cli 2.0.2 → 2.0.3

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 (58) hide show
  1. package/dist/cli.js +24 -0
  2. package/dist/cli.js.map +1 -1
  3. package/dist/commands.d.ts.map +1 -1
  4. package/dist/commands.js +2 -0
  5. package/dist/commands.js.map +1 -1
  6. package/dist/config-command.d.ts +35 -0
  7. package/dist/config-command.d.ts.map +1 -0
  8. package/dist/config-command.js +273 -0
  9. package/dist/config-command.js.map +1 -0
  10. package/dist/info.d.ts +21 -0
  11. package/dist/info.d.ts.map +1 -0
  12. package/dist/info.js +33 -0
  13. package/dist/info.js.map +1 -0
  14. package/dist/logs.d.ts.map +1 -1
  15. package/dist/logs.js +10 -2
  16. package/dist/logs.js.map +1 -1
  17. package/dist/manual-config.d.ts +17 -0
  18. package/dist/manual-config.d.ts.map +1 -1
  19. package/dist/manual-config.js +35 -0
  20. package/dist/manual-config.js.map +1 -1
  21. package/dist/options.d.ts +2 -2
  22. package/dist/options.d.ts.map +1 -1
  23. package/dist/options.js +5 -1
  24. package/dist/options.js.map +1 -1
  25. package/dist/tui.d.ts.map +1 -1
  26. package/dist/tui.js +39 -1
  27. package/dist/tui.js.map +1 -1
  28. package/dist/update.d.ts +45 -0
  29. package/dist/update.d.ts.map +1 -0
  30. package/dist/update.js +158 -0
  31. package/dist/update.js.map +1 -0
  32. package/dist/web/web.d.ts.map +1 -1
  33. package/dist/web/web.js +16 -5
  34. package/dist/web/web.js.map +1 -1
  35. package/package.json +3 -2
  36. package/skills/galaxy-ui/SKILL.md +18 -0
  37. package/skills/orbit-framework/SKILL.md +18 -0
  38. package/web/brand/app-icon-192.png +0 -0
  39. package/web/brand/app-icon-512.png +0 -0
  40. package/web/brand/client.template.js +581 -79
  41. package/web/brand/dsh-locale-keys.json +2020 -0
  42. package/web/brand/favicon.png +0 -0
  43. package/web/brand/favicon.svg +12 -0
  44. package/web/brand/lib/app-icons.js +3 -0
  45. package/web/brand/lib/client.js +2303 -88
  46. package/web/brand/lib/favicon.js +1 -1
  47. package/web/brand/lib/index.js +618 -18
  48. package/web/brand/lib/journey-host.js +282 -0
  49. package/web/brand/lib/journey-run.d.ts +66 -0
  50. package/web/brand/lib/journey-run.js +315 -0
  51. package/web/brand/lib/journey-store.d.ts +61 -0
  52. package/web/brand/lib/journey-store.js +177 -0
  53. package/web/brand/logo.png +0 -0
  54. package/web/brand/logo.svg +20 -0
  55. package/web/brand/panel/journey-panel.js +884 -0
  56. package/web/brand/vi.locales.json +838 -8
  57. package/web/brand/zalo.jpg +0 -0
  58. package/web/patches/gbh-web.patch.yml +51 -2
@@ -0,0 +1,884 @@
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
+ function createJourneyPanel(runtime) {
10
+ const react = runtime.react;
11
+ const jsx = runtime.jsx;
12
+ const jsxs = runtime.jsxs;
13
+ const t = runtime.t;
14
+ const api = runtime.api;
15
+
16
+ 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" };
17
+ const KIND_COLOR = { trigger: "#4f7cff", gate: "#e0a92b", action: "#2fa36b", approval: "#b06bd6", join: "#5a6472", notify: "#3aa0c9", rollback: "#e5484d" };
18
+ const WHEN_LABEL = { success: "thành công", failure: "thất bại", always: "luôn" };
19
+ const GRID = 10;
20
+ const NODE_W = 190;
21
+ const NODE_H = 62;
22
+
23
+ const snap = value => Math.round(value / GRID) * GRID;
24
+ const clone = value => JSON.parse(JSON.stringify(value));
25
+ const nextId = (prefix, taken) => {
26
+ let index = 1;
27
+ while (taken.indexOf(prefix + index) !== -1) index += 1;
28
+ return prefix + index;
29
+ };
30
+
31
+ /** Client-side mirror of the host validator, so badges appear while editing. */
32
+ function issuesOf(doc) {
33
+ const list = [];
34
+ if (doc === null || typeof doc !== "object") return [{ code: "document", message: "Blueprint must be an object." }];
35
+ const ids = new Set();
36
+ for (const node of Array.isArray(doc.nodes) ? doc.nodes : []) {
37
+ if (typeof node.id !== "string" || node.id.length === 0) list.push({ code: "node.id", nodeId: node.id, message: "Node cần id" });
38
+ else if (ids.has(node.id)) list.push({ code: "node.id", nodeId: node.id, message: "Trùng id node: " + node.id });
39
+ else ids.add(node.id);
40
+ 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" });
41
+ }
42
+ for (const edge of Array.isArray(doc.edges) ? doc.edges : []) {
43
+ 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" });
44
+ }
45
+ return list;
46
+ }
47
+
48
+ /** Colour one run state the way the canvas badge shows it. */
49
+ const RUN_COLOR = { done: "#2fa36b", failed: "#e5484d", running: "#4f7cff", awaiting_approval: "#e0a92b", blocked: "#8b93a1", skipped: "#5a6472", pending: "transparent" };
50
+ 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ờ" };
51
+
52
+ /** Bounding box of a node list, used by the minimap and fit. */
53
+ function boundsOf(nodes) {
54
+ if (nodes.length === 0) return { minX: 0, minY: 0, maxX: NODE_W, maxY: NODE_H };
55
+ return nodes.reduce((box, node) => ({
56
+ minX: Math.min(box.minX, node.x ?? 0),
57
+ minY: Math.min(box.minY, node.y ?? 0),
58
+ maxX: Math.max(box.maxX, (node.x ?? 0) + NODE_W),
59
+ maxY: Math.max(box.maxY, (node.y ?? 0) + NODE_H),
60
+ }), { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity });
61
+ }
62
+
63
+ function nodeCenter(node) {
64
+ return { x: (node.x ?? 0) + NODE_W, y: (node.y ?? 0) + NODE_H / 2 };
65
+ }
66
+
67
+ function edgePath(fromNode, toNode) {
68
+ const a = nodeCenter(fromNode);
69
+ const b = { x: (toNode.x ?? 0), y: (toNode.y ?? 0) + NODE_H / 2 };
70
+ const bend = Math.max(40, Math.abs(b.x - a.x) / 2);
71
+ return "M " + a.x + " " + a.y + " C " + (a.x + bend) + " " + a.y + ", " + (b.x - bend) + " " + b.y + ", " + b.x + " " + b.y;
72
+ }
73
+
74
+ function Toolbar(props) {
75
+ const { doc, dirty, status, path, view, run, mode, onSave, onReload, onZoom, onFit, onLayout, onAdd, onUndo, onRedo, onRun, onMode } = props;
76
+ const button = (label, onClick, options) => jsx("button", {
77
+ type: "button",
78
+ onClick,
79
+ ...(options && options.hook ? { "data-gbh-action": options.hook } : {}),
80
+ ...(options && options.add ? { "data-gbh-add": options.add } : {}),
81
+ title: options && options.title ? options.title : label,
82
+ disabled: Boolean(options && options.disabled),
83
+ style: {
84
+ height: "30px", padding: "0 10px", borderRadius: "8px",
85
+ border: options && options.primary ? "none" : "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35))",
86
+ background: options && options.primary ? "#4f7cff" : "transparent",
87
+ color: options && options.primary ? "#fff" : "inherit",
88
+ cursor: options && options.disabled ? "default" : "pointer",
89
+ fontSize: "12px", fontWeight: options && options.primary ? 600 : 400,
90
+ opacity: options && options.disabled ? 0.5 : 1,
91
+ },
92
+ children: label,
93
+ });
94
+ return jsxs("div", {
95
+ 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))" },
96
+ children: [
97
+ jsx("span", {
98
+ title: path || t("toolbar.path"),
99
+ style: { fontSize: "12px", opacity: 0.7, fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace", maxWidth: "320px", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
100
+ children: path || t("toolbar.path"),
101
+ }),
102
+ jsx("span", { style: { fontSize: "12px", padding: "2px 8px", borderRadius: "999px", border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35))" }, children: "rev " + String(doc && typeof doc.revision === "number" ? doc.revision : 0) }),
103
+ button(t("toolbar.save") + (dirty ? " •" : ""), onSave, { primary: true, disabled: dirty === false, hook: "save" }),
104
+ button(t("toolbar.reload"), onReload),
105
+ button("↶", onUndo, { title: t("toolbar.undo") }),
106
+ button("↷", onRedo, { title: t("toolbar.redo") }),
107
+ jsx("span", { style: { width: "1px", height: "18px", background: "var(--dsw-alias-border-l2, rgba(127,127,127,.3))" } }),
108
+ button("−", () => onZoom(1 / 1.15), { title: t("toolbar.zoomOut") }),
109
+ jsx("span", { style: { fontSize: "12px", minWidth: "42px", textAlign: "center" }, children: Math.round((view.z || 1) * 100) + "%" }),
110
+ button("+", () => onZoom(1.15), { title: t("toolbar.zoomIn") }),
111
+ button(t("toolbar.fit"), onFit),
112
+ button(t("toolbar.layout"), onLayout),
113
+ jsx("span", { style: { width: "1px", height: "18px", background: "var(--dsw-alias-border-l2, rgba(127,127,127,.3))" } }),
114
+ button(t("toolbar.diagram"), () => onMode("canvas"), { hook: "mode-canvas", primary: mode === "canvas" }),
115
+ button(t("toolbar.spec"), () => onMode("spec"), { hook: "mode-spec", primary: mode === "spec" }),
116
+ jsx("span", { style: { width: "1px", height: "18px", background: "var(--dsw-alias-border-l2, rgba(127,127,127,.3))" } }),
117
+ button(run === null ? t("run.start") : t("run.advance"), onRun, { hook: "run", primary: true }),
118
+ run === null ? null : button(t("run.cancel"), () => onRun("cancel"), { hook: "run-cancel" }),
119
+ run === null ? null : jsx("span", {
120
+ "data-gbh-run-status": run.status,
121
+ style: { fontSize: "11.5px", padding: "2px 8px", borderRadius: "999px", border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35))" },
122
+ children: t("run.status") + ": " + run.status,
123
+ }),
124
+ button("+ " + KIND_LABEL.gate, () => onAdd("gate"), { add: "gate" }),
125
+ button("+ " + KIND_LABEL.action, () => onAdd("action"), { add: "action" }),
126
+ button("+ " + KIND_LABEL.approval, () => onAdd("approval"), { add: "approval" }),
127
+ button("+ " + KIND_LABEL.join, () => onAdd("join"), { add: "join" }),
128
+ button("+ " + KIND_LABEL.notify, () => onAdd("notify"), { add: "notify" }),
129
+ jsx("span", { style: { marginLeft: "auto", fontSize: "12px", opacity: 0.75 }, children: status }),
130
+ ],
131
+ });
132
+ }
133
+
134
+ function NodeCard(props) {
135
+ const { node, selected, issue, runState, onPointerDown, onPortDown, onPortUp, onSelect } = props;
136
+ const color = KIND_COLOR[node.kind] || "#5a6472";
137
+ const badgeColor = RUN_COLOR[runState] || "transparent";
138
+ return jsxs("div", {
139
+ "data-gbh-node": node.id,
140
+ onPointerDown: event => { onSelect(node.id, event.shiftKey); onPointerDown(event, node); },
141
+ style: {
142
+ position: "absolute", left: node.x ?? 0, top: node.y ?? 0, width: NODE_W + "px", minHeight: NODE_H + "px",
143
+ borderRadius: "10px", background: "var(--dsw-alias-bg-module-platform, #23232a)",
144
+ border: "1px solid " + (selected ? "#4f7cff" : "var(--dsw-alias-border-l2, rgba(127,127,127,.4))"),
145
+ boxShadow: selected ? "0 0 0 2px rgba(79,124,255,.35)" : "0 6px 18px rgba(0,0,0,.25)",
146
+ cursor: "grab", userSelect: "none", overflow: "visible",
147
+ },
148
+ children: [
149
+ jsxs("div", {
150
+ style: { display: "flex", alignItems: "center", gap: "6px", padding: "8px 10px", borderBottom: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.22))" },
151
+ children: [
152
+ jsx("span", { style: { width: "8px", height: "8px", borderRadius: "50%", background: color, flex: "0 0 auto" } }),
153
+ jsx("span", { style: { fontSize: "12.5px", fontWeight: 600, flex: "1 1 auto", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: node.label || node.id }),
154
+ runState === undefined ? null : jsx("span", {
155
+ title: RUN_LABEL[runState] || runState,
156
+ style: { flex: "0 0 auto", fontSize: "10.5px", padding: "1px 6px", borderRadius: "999px", background: badgeColor, color: runState === "pending" ? "inherit" : "#101014" },
157
+ children: RUN_LABEL[runState] || runState,
158
+ }),
159
+ ],
160
+ }),
161
+ jsxs("div", {
162
+ style: { padding: "6px 10px 8px", fontSize: "11px", opacity: 0.72, display: "flex", flexDirection: "column", gap: "2px" },
163
+ children: [
164
+ jsx("span", { children: KIND_LABEL[node.kind] || node.kind }),
165
+ node.kind === "action" ? jsx("span", { children: (node.actions || []).map(a => a.kind).join(", ") || "—" }) : null,
166
+ issue ? jsx("span", { style: { color: "#ff8a8a" }, children: "⚠ " + issue.message }) : null,
167
+ ],
168
+ }),
169
+ jsx("span", {
170
+ onPointerDown: event => { event.stopPropagation(); onPortDown(event, node, "out"); },
171
+ title: t("node.outPort"),
172
+ 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" },
173
+ }),
174
+ jsx("span", {
175
+ onPointerUp: event => { event.stopPropagation(); onPortUp(event, node); },
176
+ title: t("node.inPort"),
177
+ 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" },
178
+ }),
179
+ ],
180
+ });
181
+ }
182
+
183
+ function Inspector(props) {
184
+ const { doc, selection, onPatchNode, onDeleteNode, onPatchEdge, onDeleteEdge, issues, run, onDecide } = props;
185
+ if (selection === null) {
186
+ 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") });
187
+ }
188
+ 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" };
189
+ const label = { display: "block", fontSize: "11px", opacity: 0.65, margin: "2px 0 4px" };
190
+ const node = selection.kind === "node" ? (doc.nodes || []).find(n => n.id === selection.id) : undefined;
191
+ const edge = selection.kind === "edge" ? (doc.edges || []).find(e => e.id === selection.id) : undefined;
192
+ const nodeIssues = issues.filter(i => i.nodeId === (node && node.id));
193
+ const nodeRun = node !== undefined && run !== null && Array.isArray(run.nodes) ? run.nodes.find(entry => entry.nodeId === node.id) : undefined;
194
+ return jsxs("div", {
195
+ style: { width: "280px", flex: "0 0 auto", borderLeft: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.25))", padding: "12px", overflowY: "auto" },
196
+ children: [
197
+ jsx("div", { style: { fontSize: "12px", fontWeight: 600, marginBottom: "10px" }, children: node ? t("inspector.node") : t("inspector.edge") }),
198
+ node ? jsxs("div", { children: [
199
+ jsx("span", { style: label, children: t("inspector.id") }),
200
+ jsx("input", { style: field, value: node.id, disabled: true }),
201
+ jsx("span", { style: label, children: t("inspector.label") }),
202
+ jsx("input", { style: field, value: node.label || "", onChange: event => onPatchNode(node.id, { label: event.target.value }) }),
203
+ jsx("span", { style: label, children: t("inspector.kind") }),
204
+ jsx("select", {
205
+ style: field, value: node.kind, onChange: event => onPatchNode(node.id, { kind: event.target.value }),
206
+ children: Object.keys(KIND_LABEL).map(kind => jsx("option", { value: kind, children: KIND_LABEL[kind] }, kind)),
207
+ }),
208
+ node.kind === "gate" ? jsxs("div", { children: [
209
+ jsx("span", { style: label, children: t("inspector.workflow") }),
210
+ jsx("input", { style: field, value: (node.gate && node.gate.workflow) || "", onChange: event => onPatchNode(node.id, { gate: { ...(node.gate || { kind: "ci" }), workflow: event.target.value } }) }),
211
+ ] }) : null,
212
+ node.kind === "action" ? jsxs("div", { children: [
213
+ jsx("span", { style: label, children: t("inspector.actions") }),
214
+ jsx("textarea", {
215
+ style: { ...field, height: "96px", padding: "6px 8px", fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace", resize: "vertical" },
216
+ value: JSON.stringify(node.actions || [], null, 1),
217
+ onChange: event => {
218
+ try { onPatchNode(node.id, { actions: JSON.parse(event.target.value) }); } catch (error) { /* keep typing */ }
219
+ },
220
+ }),
221
+ ] }) : null,
222
+ nodeIssues.length > 0 ? jsx("div", { style: { fontSize: "11px", color: "#ff8a8a", marginBottom: "8px" }, children: nodeIssues.map(i => i.message).join(" · ") }) : null,
223
+ nodeRun !== undefined && (nodeRun.state === "awaiting_approval" || nodeRun.state === "blocked") ? jsxs("div", { style: { marginBottom: "10px" }, children: [
224
+ jsx("div", { style: { fontSize: "11.5px", marginBottom: "6px" }, children: t("run.waiting") + ": " + String(nodeRun.last?.note ?? nodeRun.state) }),
225
+ jsxs("div", { style: { display: "flex", gap: "8px" }, children: [
226
+ jsx("button", {
227
+ type: "button", "data-gbh-decide": "approve", onClick: () => onDecide(node.id, "approve"),
228
+ style: { ...field, marginBottom: 0, flex: "1 1 auto", cursor: "pointer", border: "none", background: "#2fa36b", color: "#08110c", fontWeight: 600 },
229
+ children: t("run.approve"),
230
+ }),
231
+ jsx("button", {
232
+ type: "button", "data-gbh-decide": "reject", onClick: () => onDecide(node.id, "reject"),
233
+ style: { ...field, marginBottom: 0, flex: "1 1 auto", cursor: "pointer", border: "1px solid rgba(229,72,77,.6)", background: "transparent", color: "#ff8a8a" },
234
+ children: t("run.reject"),
235
+ }),
236
+ jsx("button", {
237
+ type: "button", "data-gbh-decide": "retry", onClick: () => onDecide(node.id, "retry"),
238
+ style: { ...field, marginBottom: 0, flex: "0 0 auto", cursor: "pointer" },
239
+ children: t("run.retry"),
240
+ }),
241
+ ] }),
242
+ ] }) : null,
243
+ jsx("button", { type: "button", onClick: () => onDeleteNode(node.id), style: { ...field, cursor: "pointer", color: "#ff8a8a" }, children: t("inspector.deleteNode") }),
244
+ ] }) : null,
245
+ edge ? jsxs("div", { children: [
246
+ jsx("span", { style: label, children: t("inspector.from") }),
247
+ jsx("input", { style: field, value: edge.from, disabled: true }),
248
+ jsx("span", { style: label, children: t("inspector.to") }),
249
+ jsx("input", { style: field, value: edge.to, disabled: true }),
250
+ jsx("span", { style: label, children: t("inspector.when") }),
251
+ jsx("select", {
252
+ style: field, value: edge.when || "success", onChange: event => onPatchEdge(edge.id, { when: event.target.value }),
253
+ children: ["success", "failure", "always"].map(when => jsx("option", { value: when, children: WHEN_LABEL[when] }, when)),
254
+ }),
255
+ jsx("button", { type: "button", onClick: () => onDeleteEdge(edge.id), style: { ...field, cursor: "pointer", color: "#ff8a8a" }, children: t("inspector.deleteEdge") }),
256
+ ] }) : null,
257
+ ],
258
+ });
259
+ }
260
+
261
+ /** The panel root: loads the blueprint, edits it in memory, and saves it back. */
262
+ function JourneyPanel(props) {
263
+ const sessionId = props.sessionId;
264
+ const [doc, setDoc] = react.useState(null);
265
+ const [view, setView] = react.useState({ tx: 40, ty: 20, z: 0.9 });
266
+ const [selection, setSelection] = react.useState(null);
267
+ const [picked, setPicked] = react.useState([]);
268
+ const [run, setRun] = react.useState(null);
269
+ const [mode, setMode] = react.useState("canvas");
270
+ const [specText, setSpecText] = react.useState("");
271
+ const [specError, setSpecError] = react.useState(null);
272
+ const [box, setBox] = react.useState(null);
273
+ const [canvasSize, setCanvasSize] = react.useState({ width: 900, height: 520 });
274
+ const clipboard = react.useRef(null);
275
+ const [status, setStatus] = react.useState(t("status.loading"));
276
+ const [path, setPath] = react.useState("");
277
+ const [dirty, setDirty] = react.useState(false);
278
+ const [conflict, setConflict] = react.useState(null);
279
+ const [pending, setPending] = react.useState(null);
280
+ const history = react.useRef({ past: [], future: [] });
281
+ const drag = react.useRef(null);
282
+ const canvasRef = react.useRef(null);
283
+
284
+ const load = react.useCallback(() => {
285
+ setStatus(t("status.loading"));
286
+ api.load(sessionId).then(result => {
287
+ if (result.ok !== true) { setStatus(result.message || t("status.loadFailed")); return; }
288
+ setDoc(result.document);
289
+ setDirty(false);
290
+ setConflict(null);
291
+ setPath(typeof result.path === "string" ? result.path : "");
292
+ history.current = { past: [], future: [] };
293
+ setStatus(result.exists ? t("status.loaded") : t("status.newBlueprint"));
294
+ });
295
+ }, [sessionId]);
296
+
297
+ react.useEffect(() => { load(); }, [load]);
298
+
299
+ /* Keep the minimap's viewport rectangle honest. */
300
+ react.useEffect(() => {
301
+ const measure = () => {
302
+ const element = canvasRef.current;
303
+ if (element === null) return;
304
+ setCanvasSize({ width: element.clientWidth, height: element.clientHeight });
305
+ };
306
+ measure();
307
+ window.addEventListener("resize", measure);
308
+ return () => window.removeEventListener("resize", measure);
309
+ }, []);
310
+
311
+ /* Poll the active run so the canvas tracks what the agent (or another tab) does. */
312
+ react.useEffect(() => {
313
+ let stopped = false;
314
+ const tick = () => {
315
+ if (stopped) return;
316
+ api.run(sessionId, { op: "status", runId: "latest" }).then(result => {
317
+ if (stopped) return;
318
+ if (result.ok === true && result.run !== undefined) setRun(result.run);
319
+ else if (result.ok === true && Array.isArray(result.runs)) setRun(result.runs[0] ?? null);
320
+ });
321
+ };
322
+ tick();
323
+ const timer = setInterval(tick, 2500);
324
+ return () => { stopped = true; clearInterval(timer); };
325
+ }, [sessionId, run === null ? "" : run.id]);
326
+
327
+ /* Notice blueprint edits made elsewhere: silent reload when clean, banner when dirty. */
328
+ react.useEffect(() => {
329
+ let stopped = false;
330
+ const timer = setInterval(() => {
331
+ api.load(sessionId).then(result => {
332
+ if (stopped || result.ok !== true) return;
333
+ const live = typeof result.revision === "number" ? result.revision : 0;
334
+ const mine = doc === null ? 0 : (typeof doc.revision === "number" ? doc.revision : 0);
335
+ if (live === mine) return;
336
+ if (dirty) { setConflict({ revision: live, document: result.document }); return; }
337
+ setDoc(result.document);
338
+ setStatus(t("status.reloaded"));
339
+ });
340
+ }, 4000);
341
+ return () => { stopped = true; clearInterval(timer); };
342
+ }, [sessionId, doc, dirty]);
343
+
344
+ const remember = react.useCallback(() => {
345
+ if (doc === null) return;
346
+ history.current.past.push(JSON.stringify(doc));
347
+ if (history.current.past.length > 50) history.current.past.shift();
348
+ history.current.future = [];
349
+ }, [doc]);
350
+
351
+ const mutate = react.useCallback(updater => {
352
+ setDoc(current => {
353
+ if (current === null) return current;
354
+ const next = updater(clone(current));
355
+ setDirty(true);
356
+ return next;
357
+ });
358
+ }, []);
359
+
360
+ const issues = react.useMemo(() => (doc === null ? [] : issuesOf(doc)), [doc]);
361
+
362
+ const addNode = react.useCallback(kind => {
363
+ remember();
364
+ mutate(current => {
365
+ const taken = (current.nodes || []).map(n => n.id);
366
+ const id = nextId(kind + "-", taken);
367
+ const maxY = (current.nodes || []).reduce((top, n) => Math.max(top, n.y ?? 0), 0);
368
+ const node = { id, kind, label: KIND_LABEL[kind] + " " + id.split("-")[1], x: 120, y: snap(maxY + 110) };
369
+ if (kind === "action") node.actions = [{ kind: "command", run: "echo TODO" }];
370
+ if (kind === "gate") node.gate = { kind: "ci", workflow: "ci.yml", ref: "main" };
371
+ current.nodes = [...(current.nodes || []), node];
372
+ return current;
373
+ });
374
+ }, [mutate, remember]);
375
+
376
+ const patchNode = react.useCallback((id, patch) => {
377
+ remember();
378
+ mutate(current => {
379
+ current.nodes = (current.nodes || []).map(node => (node.id === id ? { ...node, ...patch } : node));
380
+ return current;
381
+ });
382
+ }, [mutate, remember]);
383
+
384
+ const deleteNode = react.useCallback(id => {
385
+ remember();
386
+ mutate(current => {
387
+ current.nodes = (current.nodes || []).filter(node => node.id !== id);
388
+ current.edges = (current.edges || []).filter(edge => edge.from !== id && edge.to !== id);
389
+ return current;
390
+ });
391
+ setSelection(null);
392
+ }, [mutate, remember]);
393
+
394
+ const patchEdge = react.useCallback((id, patch) => {
395
+ remember();
396
+ mutate(current => {
397
+ current.edges = (current.edges || []).map(edge => (edge.id === id ? { ...edge, ...patch } : edge));
398
+ return current;
399
+ });
400
+ }, [mutate, remember]);
401
+
402
+ const deleteEdge = react.useCallback(id => {
403
+ remember();
404
+ mutate(current => {
405
+ current.edges = (current.edges || []).filter(edge => edge.id !== id);
406
+ return current;
407
+ });
408
+ setSelection(null);
409
+ }, [mutate, remember]);
410
+
411
+ const addEdge = react.useCallback((from, to) => {
412
+ if (from === to) return;
413
+ remember();
414
+ mutate(current => {
415
+ const exists = (current.edges || []).some(edge => edge.from === from && edge.to === to);
416
+ if (exists) return current;
417
+ const taken = (current.edges || []).map(edge => edge.id);
418
+ current.edges = [...(current.edges || []), { id: nextId("e", taken), from, to, when: "success" }];
419
+ return current;
420
+ });
421
+ }, [mutate, remember]);
422
+
423
+ const save = react.useCallback(() => {
424
+ if (doc === null) return;
425
+ setStatus(t("status.saving"));
426
+ api.save(sessionId, doc, typeof doc.revision === "number" ? doc.revision : 0).then(result => {
427
+ if (result.ok === true) {
428
+ setDoc(current => ({ ...current, revision: result.revision }));
429
+ setDirty(false);
430
+ setConflict(null);
431
+ setStatus(t("status.saved") + " · rev " + result.revision);
432
+ return;
433
+ }
434
+ if (result.code === "journey/conflict") { setConflict(result.current || null); setStatus(t("status.conflict")); return; }
435
+ setStatus((result.message || t("status.saveFailed")) + (result.issues ? " · " + result.issues.map(i => i.message).join("; ") : ""));
436
+ });
437
+ }, [doc, sessionId]);
438
+
439
+ const pointerToCanvas = event => {
440
+ const rect = canvasRef.current ? canvasRef.current.getBoundingClientRect() : { left: 0, top: 0 };
441
+ return { x: (event.clientX - rect.left - view.tx) / view.z, y: (event.clientY - rect.top - view.ty) / view.z };
442
+ };
443
+
444
+ const startNodeDrag = (event, node) => {
445
+ if (event.button !== 0) return;
446
+ const start = pointerToCanvas(event);
447
+ drag.current = { type: "node", id: node.id, dx: start.x - (node.x ?? 0), dy: start.y - (node.y ?? 0) };
448
+ remember();
449
+ try { event.currentTarget.setPointerCapture(event.pointerId); } catch (error) { /* ignore */ }
450
+ };
451
+
452
+ const startPan = event => {
453
+ if (event.button !== 0 || event.target !== event.currentTarget) return;
454
+ if (event.shiftKey) {
455
+ const point = pointerToCanvas(event);
456
+ drag.current = { type: "box", start: point };
457
+ setBox({ x: point.x, y: point.y, w: 0, h: 0 });
458
+ try { event.currentTarget.setPointerCapture(event.pointerId); } catch (error) { /* ignore */ }
459
+ return;
460
+ }
461
+ drag.current = { type: "pan", x: event.clientX, y: event.clientY, tx: view.tx, ty: view.ty };
462
+ setSelection(null);
463
+ setPicked([]);
464
+ try { event.currentTarget.setPointerCapture(event.pointerId); } catch (error) { /* ignore */ }
465
+ };
466
+
467
+ const onPointerMove = event => {
468
+ const state = drag.current;
469
+ if (state === null || state === undefined) return;
470
+ if (state.type === "pan") {
471
+ setView(current => ({ ...current, tx: state.tx + (event.clientX - state.x), ty: state.ty + (event.clientY - state.y) }));
472
+ return;
473
+ }
474
+ if (state.type === "node") {
475
+ const point = pointerToCanvas(event);
476
+ mutate(current => {
477
+ current.nodes = (current.nodes || []).map(node => (node.id === state.id ? { ...node, x: snap(point.x - state.dx), y: snap(point.y - state.dy) } : node));
478
+ return current;
479
+ });
480
+ return;
481
+ }
482
+ if (state.type === "edge") {
483
+ const point = pointerToCanvas(event);
484
+ setPending({ from: state.from, x: point.x, y: point.y });
485
+ return;
486
+ }
487
+ if (state.type === "box") {
488
+ const point = pointerToCanvas(event);
489
+ setBox({
490
+ x: Math.min(state.start.x, point.x),
491
+ y: Math.min(state.start.y, point.y),
492
+ w: Math.abs(point.x - state.start.x),
493
+ h: Math.abs(point.y - state.start.y),
494
+ });
495
+ }
496
+ };
497
+
498
+ const endDrag = () => {
499
+ const state = drag.current;
500
+ drag.current = null;
501
+ if (state === null || state === undefined || state.type !== "box") return;
502
+ setBox(current => {
503
+ if (current !== null && doc !== null) {
504
+ const inside = (doc.nodes || []).filter(node => {
505
+ const x = node.x ?? 0;
506
+ const y = node.y ?? 0;
507
+ return x + NODE_W >= current.x && x <= current.x + current.w && y + NODE_H >= current.y && y <= current.y + current.h;
508
+ });
509
+ setPicked(inside.map(node => "node:" + node.id));
510
+ if (inside.length > 0) setSelection({ kind: "node", id: inside[inside.length - 1].id });
511
+ }
512
+ return null;
513
+ });
514
+ };
515
+
516
+ const startEdge = (event, node, side) => {
517
+ const point = pointerToCanvas(event);
518
+ drag.current = { type: "edge", from: node.id };
519
+ setPending({ from: node.id, x: point.x, y: point.y });
520
+ try { event.currentTarget.setPointerCapture(event.pointerId); } catch (error) { /* ignore */ }
521
+ };
522
+
523
+ const endEdge = (event, node) => {
524
+ const state = drag.current;
525
+ setPending(null);
526
+ drag.current = null;
527
+ if (state !== null && state !== undefined && state.type === "edge") addEdge(state.from, node.id);
528
+ };
529
+
530
+ const onWheel = event => {
531
+ const factor = event.deltaY < 0 ? 1.08 : 1 / 1.08;
532
+ setView(current => ({ ...current, z: Math.min(1.8, Math.max(0.4, current.z * factor)) }));
533
+ };
534
+
535
+ const fit = () => {
536
+ const nodes = (doc && doc.nodes) || [];
537
+ if (nodes.length === 0) return;
538
+ const maxX = nodes.reduce((value, node) => Math.max(value, (node.x ?? 0) + NODE_W), 0);
539
+ const maxY = nodes.reduce((value, node) => Math.max(value, (node.y ?? 0) + NODE_H), 0);
540
+ const width = canvasRef.current ? canvasRef.current.clientWidth : 900;
541
+ const height = canvasRef.current ? canvasRef.current.clientHeight : 500;
542
+ const z = Math.min(1.2, Math.max(0.4, Math.min(width / (maxX + 80), height / (maxY + 80))));
543
+ setView({ tx: 30, ty: 20, z });
544
+ };
545
+
546
+ /** Layered left-to-right placement: depth = longest path from a source node. */
547
+ const autoLayout = () => {
548
+ remember();
549
+ mutate(current => {
550
+ const nodes = current.nodes || [];
551
+ const edges = current.edges || [];
552
+ const depth = new Map(nodes.map(node => [node.id, 0]));
553
+ for (let pass = 0; pass < nodes.length; pass += 1) {
554
+ for (const edge of edges) {
555
+ const from = depth.get(edge.from) ?? 0;
556
+ const to = depth.get(edge.to) ?? 0;
557
+ if (to < from + 1) depth.set(edge.to, from + 1);
558
+ }
559
+ }
560
+ const rows = new Map();
561
+ for (const node of nodes) {
562
+ const column = depth.get(node.id) ?? 0;
563
+ const row = rows.get(column) ?? 0;
564
+ rows.set(column, row + 1);
565
+ node.x = 80 + column * 260;
566
+ node.y = 60 + row * 120;
567
+ }
568
+ return current;
569
+ });
570
+ };
571
+
572
+ const undo = () => {
573
+ const past = history.current.past;
574
+ if (past.length === 0) return;
575
+ const snapshot = past.pop();
576
+ history.current.future.push(JSON.stringify(doc));
577
+ setDoc(JSON.parse(snapshot));
578
+ setDirty(true);
579
+ };
580
+
581
+ const redo = () => {
582
+ const future = history.current.future;
583
+ if (future.length === 0) return;
584
+ const snapshot = future.pop();
585
+ history.current.past.push(JSON.stringify(doc));
586
+ setDoc(JSON.parse(snapshot));
587
+ setDirty(true);
588
+ };
589
+
590
+ const pickKey = item => item.kind + ":" + item.id;
591
+ const isPicked = item => picked.indexOf(pickKey(item)) !== -1;
592
+
593
+ const pick = (item, additive) => {
594
+ setSelection(item);
595
+ const key = pickKey(item);
596
+ if (additive === true) setPicked(current => (current.indexOf(key) === -1 ? [...current, key] : current.filter(entry => entry !== key)));
597
+ else setPicked([key]);
598
+ };
599
+
600
+ const pickEdge = (id, additive) => pick({ kind: "edge", id: id }, additive);
601
+
602
+ const pickedNodes = () => picked.filter(key => key.indexOf("node:") === 0).map(key => key.slice(5));
603
+ const pickedEdges = () => picked.filter(key => key.indexOf("edge:") === 0).map(key => key.slice(5));
604
+
605
+ const deleteSelected = () => {
606
+ const nodes = pickedNodes();
607
+ const edges = pickedEdges();
608
+ if (nodes.length === 0 && edges.length === 0) return;
609
+ remember();
610
+ mutate(current => {
611
+ current.nodes = (current.nodes || []).filter(node => nodes.indexOf(node.id) === -1);
612
+ current.edges = (current.edges || []).filter(edge => edges.indexOf(edge.id) === -1 && nodes.indexOf(edge.from) === -1 && nodes.indexOf(edge.to) === -1);
613
+ return current;
614
+ });
615
+ setPicked([]);
616
+ setSelection(null);
617
+ };
618
+
619
+ const copySelection = () => {
620
+ const nodes = (doc.nodes || []).filter(node => pickedNodes().indexOf(node.id) !== -1);
621
+ if (nodes.length === 0) return;
622
+ const ids = nodes.map(node => node.id);
623
+ clipboard.current = {
624
+ nodes: clone(nodes),
625
+ edges: clone((doc.edges || []).filter(edge => ids.indexOf(edge.from) !== -1 && ids.indexOf(edge.to) !== -1)),
626
+ };
627
+ };
628
+
629
+ const pasteSelection = () => {
630
+ const clip = clipboard.current;
631
+ if (clip === null) return;
632
+ remember();
633
+ const mapping = new Map();
634
+ mutate(current => {
635
+ const taken = (current.nodes || []).map(node => node.id);
636
+ for (const node of clip.nodes) {
637
+ const id = nextId(node.kind + "-", taken);
638
+ taken.push(id);
639
+ mapping.set(node.id, id);
640
+ 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 }];
641
+ }
642
+ const edgeTaken = (current.edges || []).map(edge => edge.id);
643
+ for (const edge of clip.edges) {
644
+ const id = nextId("e", edgeTaken);
645
+ edgeTaken.push(id);
646
+ current.edges = [...(current.edges || []), { ...clone(edge), id, from: mapping.get(edge.from), to: mapping.get(edge.to) }];
647
+ }
648
+ return current;
649
+ });
650
+ setPicked([...mapping.values()].map(id => "node:" + id));
651
+ };
652
+
653
+ /** Drive the run: start, advance, cancel, or decide a waiting node. */
654
+ const runAction = (op, extra) => {
655
+ setStatus(t("run.working"));
656
+ api.run(sessionId, { op: op, ...(run === null || run.id === undefined ? {} : { runId: run.id }), ...(extra || {}) }).then(result => {
657
+ if (result.ok === true && result.run !== undefined) {
658
+ setRun(result.run);
659
+ setStatus(t("run.status") + ": " + result.run.status);
660
+ return;
661
+ }
662
+ setStatus((result.message || t("run.failed")) + (result.code === undefined ? "" : " (" + result.code + ")"));
663
+ });
664
+ };
665
+
666
+ const decide = (nodeId, decision) => runAction("decide", { nodeId: nodeId, decision: decision });
667
+
668
+ /** Entering spec mode seeds the editor from the live document. */
669
+ const switchMode = next => {
670
+ if (next === "spec" && doc !== null) {
671
+ setSpecText(JSON.stringify(doc, null, 2));
672
+ setSpecError(null);
673
+ }
674
+ setMode(next);
675
+ };
676
+
677
+ const applySpec = () => {
678
+ try {
679
+ const parsed = JSON.parse(specText);
680
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error(t("spec.notObject"));
681
+ remember();
682
+ setDoc({ ...parsed, revision: doc === null ? 0 : doc.revision });
683
+ setDirty(true);
684
+ setSpecError(null);
685
+ setStatus(t("spec.applied"));
686
+ } catch (error) {
687
+ setSpecError(error instanceof Error ? error.message : String(error));
688
+ }
689
+ };
690
+
691
+ const onKeyDown = event => {
692
+ if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "z") {
693
+ event.preventDefault();
694
+ if (event.shiftKey) redo(); else undo();
695
+ return;
696
+ }
697
+ if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "c") { event.preventDefault(); copySelection(); return; }
698
+ if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "v") { event.preventDefault(); pasteSelection(); return; }
699
+ if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "a") {
700
+ event.preventDefault();
701
+ setPicked((doc && doc.nodes ? doc.nodes : []).map(node => "node:" + node.id));
702
+ return;
703
+ }
704
+ if (event.key === "Delete" || event.key === "Backspace") {
705
+ if (picked.length > 0) { event.preventDefault(); deleteSelected(); return; }
706
+ if (selection === null) return;
707
+ event.preventDefault();
708
+ if (selection.kind === "node") deleteNode(selection.id); else deleteEdge(selection.id);
709
+ }
710
+ };
711
+
712
+ if (doc === null) {
713
+ return jsx("div", { style: { padding: "18px", fontSize: "13px", opacity: 0.8 }, children: status });
714
+ }
715
+
716
+ const nodes = doc.nodes || [];
717
+ const edges = doc.edges || [];
718
+ const byId = new Map(nodes.map(node => [node.id, node]));
719
+ const issueByNode = new Map();
720
+ for (const issue of issues) if (issue.nodeId !== undefined && !issueByNode.has(issue.nodeId)) issueByNode.set(issue.nodeId, issue);
721
+
722
+ return jsxs("div", {
723
+ onKeyDown,
724
+ tabIndex: 0,
725
+ style: { display: "flex", flexDirection: "column", height: "100%", outline: "none", background: "var(--dsw-alias-bg-base, #1b1b20)", color: "var(--dsw-alias-label-primary, #f2f2f2)" },
726
+ children: [
727
+ jsx(Toolbar, {
728
+ doc, dirty, status: conflict === null ? status : t("status.conflict"), path,
729
+ view, onSave: save, onReload: load,
730
+ onZoom: factor => setView(current => ({ ...current, z: Math.min(1.8, Math.max(0.4, current.z * factor)) })),
731
+ onFit: fit, onLayout: autoLayout, onAdd: addNode, onUndo: undo, onRedo: redo,
732
+ run, mode, onMode: switchMode,
733
+ onRun: op => runAction(typeof op === "string" ? op : (run === null ? "start" : "advance")),
734
+ }),
735
+ conflict === null ? null : jsxs("div", {
736
+ 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" },
737
+ children: [
738
+ jsx("span", { children: t("conflict.banner") }),
739
+ 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") }),
740
+ ],
741
+ }),
742
+ mode === "spec" ? jsx(SpecEditor, {
743
+ doc, text: specText, error: specError,
744
+ onChange: setSpecText, onApply: applySpec,
745
+ onReset: () => { setSpecText(doc === null ? "" : JSON.stringify(doc, null, 2)); setSpecError(null); },
746
+ }) : jsxs("div", { style: { display: "flex", flex: "1 1 auto", minHeight: 0 }, children: [
747
+ jsxs("div", {
748
+ ref: canvasRef,
749
+ "data-gbh-journey": "canvas",
750
+ onPointerDown: startPan,
751
+ onPointerMove,
752
+ onPointerUp: endDrag,
753
+ onPointerLeave: endDrag,
754
+ onWheel,
755
+ style: {
756
+ position: "relative", flex: "1 1 auto", overflow: "hidden", cursor: "grab",
757
+ backgroundImage: "radial-gradient(var(--dsw-alias-border-l2, rgba(127,127,127,.35)) 1px, transparent 1px)",
758
+ backgroundSize: (22 * view.z) + "px " + (22 * view.z) + "px",
759
+ backgroundPosition: view.tx + "px " + view.ty + "px",
760
+ },
761
+ children: [
762
+ jsxs("div", {
763
+ style: { position: "absolute", left: 0, top: 0, transform: "translate(" + view.tx + "px," + view.ty + "px) scale(" + view.z + ")", transformOrigin: "0 0" },
764
+ children: [
765
+ jsx("svg", {
766
+ width: "6000", height: "4000",
767
+ style: { position: "absolute", left: 0, top: 0, pointerEvents: "none", overflow: "visible" },
768
+ children: [
769
+ ...edges.map(edge => {
770
+ const from = byId.get(edge.from);
771
+ const to = byId.get(edge.to);
772
+ if (from === undefined || to === undefined) return null;
773
+ const selected = picked.indexOf("edge:" + edge.id) !== -1;
774
+ const color = edge.when === "failure" ? "#e5484d" : edge.when === "always" ? "#8b93a1" : "#4f7cff";
775
+ return jsx("path", {
776
+ "data-gbh-edge": edge.id,
777
+ d: edgePath(from, to), fill: "none", stroke: color,
778
+ strokeWidth: selected ? 3 : 2,
779
+ strokeDasharray: edge.when === "failure" ? "6 5" : undefined,
780
+ style: { pointerEvents: "stroke", cursor: "pointer" },
781
+ onPointerDown: event => { event.stopPropagation(); pickEdge(edge.id, event.shiftKey); },
782
+ }, edge.id);
783
+ }),
784
+ pending === null ? null : jsx("path", {
785
+ d: "M " + ((byId.get(pending.from)?.x ?? 0) + NODE_W) + " " + ((byId.get(pending.from)?.y ?? 0) + NODE_H / 2) + " L " + pending.x + " " + pending.y,
786
+ fill: "none", stroke: "#4f7cff", strokeWidth: 2, strokeDasharray: "5 4",
787
+ }),
788
+ ],
789
+ }),
790
+ box === null ? null : jsx("div", {
791
+ 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" },
792
+ }),
793
+ ...nodes.map(node => jsx(NodeCard, {
794
+ node, selected: isPicked({ kind: "node", id: node.id }),
795
+ issue: issueByNode.get(node.id),
796
+ runState: run !== null && run.nodes !== undefined ? (run.nodes.find(entry => entry.nodeId === node.id) || {}).state : undefined,
797
+ onPointerDown: startNodeDrag, onPortDown: startEdge, onPortUp: endEdge,
798
+ onSelect: (id, additive) => pick({ kind: "node", id: id }, additive),
799
+ }, node.id)),
800
+ ],
801
+ }),
802
+ issues.length === 0 ? null : jsx("div", {
803
+ 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" },
804
+ children: issues.slice(0, 4).map(issue => issue.message).join(" · "),
805
+ }),
806
+ jsx(Minimap, {
807
+ doc, view, canvasSize,
808
+ onJump: point => setView(current => ({ ...current, tx: -point.x * current.z + 120, ty: -point.y * current.z + 80 })),
809
+ }),
810
+ ],
811
+ }),
812
+ jsx(Inspector, {
813
+ doc, selection, issues, run, onDecide: decide,
814
+ onPatchNode: patchNode, onDeleteNode: deleteNode, onPatchEdge: patchEdge, onDeleteEdge: deleteEdge,
815
+ }),
816
+ ]}),
817
+ ],
818
+ });
819
+ }
820
+
821
+ /** Small overview of the graph with the current viewport, for quick navigation. */
822
+ function Minimap(props) {
823
+ const { doc, view, canvasSize, onJump } = props;
824
+ const WIDTH = 170;
825
+ const HEIGHT = 120;
826
+ const nodes = (doc && doc.nodes) || [];
827
+ const box = boundsOf(nodes);
828
+ const spanX = Math.max(1, box.maxX - box.minX);
829
+ const spanY = Math.max(1, box.maxY - box.minY);
830
+ const scale = Math.min(WIDTH / spanX, HEIGHT / spanY) * 0.85;
831
+ const left = 10;
832
+ const top = 10;
833
+ const toMini = node => ({ x: left + ((node.x ?? 0) - box.minX) * scale, y: top + ((node.y ?? 0) - box.minY) * scale });
834
+ const viewRect = {
835
+ x: left + (-view.tx / view.z - box.minX) * scale,
836
+ y: top + (-view.ty / view.z - box.minY) * scale,
837
+ w: (canvasSize.width / view.z) * scale,
838
+ h: (canvasSize.height / view.z) * scale,
839
+ };
840
+ return jsx("div", {
841
+ "data-gbh-minimap": "1",
842
+ onClick: event => {
843
+ const rect = event.currentTarget.getBoundingClientRect();
844
+ onJump({ x: (event.clientX - rect.left - left) / scale + box.minX, y: (event.clientY - rect.top - top) / scale + box.minY });
845
+ },
846
+ 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" },
847
+ children: jsxs("svg", {
848
+ width: WIDTH, height: HEIGHT,
849
+ children: [
850
+ ...nodes.map(node => {
851
+ const point = toMini(node);
852
+ 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);
853
+ }),
854
+ 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 }),
855
+ ],
856
+ }),
857
+ });
858
+ }
859
+
860
+ /** JSON view of the same document: the agent-readable face of the canvas. */
861
+ function SpecEditor(props) {
862
+ const { doc, text, onChange, onApply, onReset, error } = props;
863
+ return jsxs("div", {
864
+ style: { flex: "1 1 auto", display: "flex", flexDirection: "column", padding: "12px", gap: "8px", minHeight: 0 },
865
+ children: [
866
+ jsxs("div", { style: { display: "flex", gap: "8px", alignItems: "center" }, children: [
867
+ jsx("span", { style: { fontSize: "12px", opacity: 0.7 }, children: t("spec.hint") }),
868
+ 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") }),
869
+ 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") }),
870
+ ] }),
871
+ jsx("textarea", {
872
+ "data-gbh-spec": "1",
873
+ value: text,
874
+ spellCheck: false,
875
+ onChange: event => onChange(event.target.value),
876
+ 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" },
877
+ }),
878
+ error === null ? null : jsx("div", { style: { color: "#ff8a8a", fontSize: "12px" }, children: error }),
879
+ ],
880
+ });
881
+ }
882
+
883
+ return { JourneyPanel };
884
+ }