reifyui 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +29 -0
  2. package/dist/chart.js +2 -0
  3. package/dist/chart.js.map +1 -1
  4. package/dist/chunk-EL2DHWOH.js +1710 -0
  5. package/dist/chunk-EL2DHWOH.js.map +1 -0
  6. package/dist/chunk-J633KV57.js +41 -0
  7. package/dist/chunk-J633KV57.js.map +1 -0
  8. package/dist/chunk-J7SECRIG.js +295 -0
  9. package/dist/chunk-J7SECRIG.js.map +1 -0
  10. package/dist/chunk-PIRPLH2Z.js +231 -0
  11. package/dist/chunk-PIRPLH2Z.js.map +1 -0
  12. package/dist/chunk-PZ5AY32C.js +10 -0
  13. package/dist/chunk-PZ5AY32C.js.map +1 -0
  14. package/dist/chunk-UKG4Z6QK.js +130 -0
  15. package/dist/chunk-UKG4Z6QK.js.map +1 -0
  16. package/dist/chunk-ZYWE47EO.js +19 -0
  17. package/dist/chunk-ZYWE47EO.js.map +1 -0
  18. package/dist/collab.cjs +169 -0
  19. package/dist/collab.cjs.map +1 -0
  20. package/dist/collab.d.ts +30 -0
  21. package/dist/collab.js +18 -0
  22. package/dist/collab.js.map +1 -0
  23. package/dist/graph.cjs +2244 -0
  24. package/dist/graph.cjs.map +1 -0
  25. package/dist/graph.d.ts +41 -0
  26. package/dist/graph.js +1870 -0
  27. package/dist/graph.js.map +1 -0
  28. package/dist/harness.js +1 -0
  29. package/dist/harness.js.map +1 -1
  30. package/dist/index.cjs +1699 -817
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.ts +3 -0
  33. package/dist/index.js +680 -1769
  34. package/dist/index.js.map +1 -1
  35. package/dist/sheet-doc.cjs +235 -0
  36. package/dist/sheet-doc.cjs.map +1 -0
  37. package/dist/sheet-doc.d.ts +16 -0
  38. package/dist/sheet-doc.js +20 -0
  39. package/dist/sheet-doc.js.map +1 -0
  40. package/dist/sheet.cjs +2322 -0
  41. package/dist/sheet.cjs.map +1 -0
  42. package/dist/sheet.d.ts +23 -0
  43. package/dist/sheet.js +237 -0
  44. package/dist/sheet.js.map +1 -0
  45. package/dist/slides.js +2 -0
  46. package/dist/slides.js.map +1 -1
  47. package/package.json +34 -2
  48. package/src/auth/client.js +4 -2
  49. package/src/collab/colors.js +18 -0
  50. package/src/collab/index.d.ts +30 -0
  51. package/src/collab/index.js +8 -0
  52. package/src/collab/keepAlive.js +34 -0
  53. package/src/collab/useLiveDoc.js +76 -0
  54. package/src/components/CascadeMenu.jsx +9 -3
  55. package/src/components/Composer.jsx +37 -3
  56. package/src/components/resizable.jsx +82 -12
  57. package/src/graph/ConnectPane.jsx +634 -0
  58. package/src/graph/ConnectToolDetail.jsx +565 -0
  59. package/src/graph/LogsPane.jsx +328 -0
  60. package/src/graph/Skeleton.jsx +13 -0
  61. package/src/graph/draft.js +108 -0
  62. package/src/graph/format.js +37 -0
  63. package/src/graph/index.d.ts +41 -0
  64. package/src/graph/index.js +14 -0
  65. package/src/graph/useGraphCollab.js +299 -0
  66. package/src/graph/vgraph.js +215 -0
  67. package/src/index.d.ts +3 -0
  68. package/src/index.js +4 -1
  69. package/src/mention/MentionInput.jsx +420 -0
  70. package/src/mention/mentionModel.js +177 -0
  71. package/src/sheet/RunStrip.jsx +57 -0
  72. package/src/sheet/SheetGrid.jsx +448 -423
  73. package/src/sheet/doc.d.ts +16 -0
  74. package/src/sheet/index.d.ts +23 -0
  75. package/src/sheet/index.js +10 -0
  76. package/src/sheet/sheetDoc.js +203 -0
  77. package/src/sheet/useSheetCollab.js +102 -0
  78. package/src/sheet/useSheetRun.js +80 -0
  79. package/styles/chat.css +2 -0
  80. package/styles/graph.css +395 -0
  81. package/styles/mention.css +79 -0
  82. package/styles/sheet.css +156 -112
package/dist/graph.cjs ADDED
@@ -0,0 +1,2244 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/graph/index.js
30
+ var graph_exports = {};
31
+ __export(graph_exports, {
32
+ ConnectPane: () => ConnectPane,
33
+ DATA_TYPES: () => DATA_TYPES,
34
+ LogsPane: () => LogsPane,
35
+ Skeleton: () => Skeleton,
36
+ absoluteTime: () => absoluteTime,
37
+ configureVgraph: () => configureVgraph,
38
+ fmtUnits: () => fmtUnits,
39
+ materializeDraft: () => materializeDraft,
40
+ parseAssetRef: () => parseAssetRef,
41
+ pollSchemaChange: () => pollSchemaChange,
42
+ relativeTime: () => relativeTime,
43
+ saveDraft: () => saveDraft,
44
+ schemaVersionNum: () => schemaVersionNum,
45
+ semanticDimsFor: () => semanticDimsFor,
46
+ semanticIndexFor: () => semanticIndexFor,
47
+ semanticIndexOn: () => semanticIndexOn,
48
+ useGraphCollab: () => useGraphCollab,
49
+ vgraph: () => vgraph
50
+ });
51
+ module.exports = __toCommonJS(graph_exports);
52
+
53
+ // src/graph/useGraphCollab.js
54
+ var import_react2 = require("react");
55
+
56
+ // src/collab/useLiveDoc.js
57
+ var import_react = require("react");
58
+ var import_provider = require("@hocuspocus/provider");
59
+
60
+ // src/collab/keepAlive.js
61
+ var TICK_MS = 1e4;
62
+ function keepPresenceAlive(awareness, intervalMs = TICK_MS) {
63
+ if (!awareness || typeof Worker === "undefined" || typeof Blob === "undefined") return () => {
64
+ };
65
+ let url = "";
66
+ let worker = null;
67
+ try {
68
+ url = URL.createObjectURL(new Blob(
69
+ [`setInterval(() => postMessage(0), ${Math.max(1e3, intervalMs)});`],
70
+ { type: "text/javascript" }
71
+ ));
72
+ worker = new Worker(url);
73
+ } catch {
74
+ if (url) URL.revokeObjectURL(url);
75
+ return () => {
76
+ };
77
+ }
78
+ worker.onmessage = () => {
79
+ const state = awareness.getLocalState();
80
+ if (state !== null && state !== void 0) awareness.setLocalState(state);
81
+ };
82
+ return () => {
83
+ worker.terminate();
84
+ URL.revokeObjectURL(url);
85
+ };
86
+ }
87
+
88
+ // src/collab/useLiveDoc.js
89
+ function useLiveDoc(resourceId, { fetchTicket, field = "presence" } = {}) {
90
+ const [doc, setDoc] = (0, import_react.useState)(null);
91
+ const [provider, setProvider] = (0, import_react.useState)(null);
92
+ const [ready, setReady] = (0, import_react.useState)(false);
93
+ const [states, setStates] = (0, import_react.useState)([]);
94
+ const [selfClientId, setSelfClientId] = (0, import_react.useState)(null);
95
+ const providerRef = (0, import_react.useRef)(null);
96
+ const lastRef = (0, import_react.useRef)(null);
97
+ (0, import_react.useEffect)(() => {
98
+ if (!resourceId || typeof fetchTicket !== "function") return void 0;
99
+ let dead = false;
100
+ let current = null;
101
+ let retry = null;
102
+ let stopKeepAlive = () => {
103
+ };
104
+ async function connect() {
105
+ let ticket = null;
106
+ try {
107
+ ticket = await fetchTicket(resourceId);
108
+ } catch {
109
+ ticket = null;
110
+ }
111
+ if (dead) return;
112
+ if (!ticket) {
113
+ retry = window.setTimeout(connect, 6e4);
114
+ return;
115
+ }
116
+ current = new import_provider.HocuspocusProvider({
117
+ url: ticket.url,
118
+ name: ticket.doc,
119
+ parameters: { cg_token: ticket.token },
120
+ onAuthenticationFailed: () => {
121
+ stopKeepAlive();
122
+ try {
123
+ current.destroy();
124
+ } catch {
125
+ }
126
+ if (!dead) retry = window.setTimeout(connect, 5e3);
127
+ }
128
+ });
129
+ stopKeepAlive = keepPresenceAlive(current.awareness);
130
+ providerRef.current = current;
131
+ setProvider(current);
132
+ if (lastRef.current) {
133
+ try {
134
+ current.setAwarenessField(field, lastRef.current);
135
+ } catch {
136
+ }
137
+ }
138
+ current.on("awarenessUpdate", ({ states: next }) => {
139
+ if (!dead) setStates(next || []);
140
+ });
141
+ current.on("synced", () => {
142
+ if (dead) return;
143
+ setSelfClientId(current.awareness ? current.awareness.clientID : null);
144
+ setDoc(current.document);
145
+ setReady(true);
146
+ });
147
+ current.on("status", ({ status }) => {
148
+ if (!dead && status === "disconnected") setReady(false);
149
+ });
150
+ }
151
+ connect();
152
+ return () => {
153
+ dead = true;
154
+ window.clearTimeout(retry);
155
+ stopKeepAlive();
156
+ if (current) {
157
+ try {
158
+ current.destroy();
159
+ } catch {
160
+ }
161
+ }
162
+ providerRef.current = null;
163
+ setProvider(null);
164
+ setDoc(null);
165
+ setReady(false);
166
+ setStates([]);
167
+ setSelfClientId(null);
168
+ };
169
+ }, [resourceId]);
170
+ const setAwareness = (0, import_react.useCallback)((value) => {
171
+ lastRef.current = value;
172
+ const p = providerRef.current;
173
+ if (p) {
174
+ try {
175
+ p.setAwarenessField(field, value);
176
+ } catch {
177
+ }
178
+ }
179
+ }, [field]);
180
+ return { doc, provider, ready, states, selfClientId, setAwareness };
181
+ }
182
+
183
+ // src/collab/colors.js
184
+ var PEER_PALETTE = ["#1e40af", "#c2410c", "#15803d", "#6d28d9", "#be123c", "#0e7490", "#a16207", "#4338ca"];
185
+ function peerColor(key) {
186
+ let h = 0;
187
+ for (const ch of String(key || "")) h = h * 31 + ch.charCodeAt(0) >>> 0;
188
+ return PEER_PALETTE[h % PEER_PALETTE.length];
189
+ }
190
+
191
+ // src/graph/useGraphCollab.js
192
+ var T_PREFIX = "t:";
193
+ var P_PREFIX = "p:";
194
+ var COPILOT_STALE_MS = 15 * 60 * 1e3;
195
+ function readDrafts(map) {
196
+ const typeDrafts = {};
197
+ const positionDrafts = {};
198
+ map.forEach((v, k) => {
199
+ if (k.startsWith(T_PREFIX)) typeDrafts[k.slice(T_PREFIX.length)] = v;
200
+ else if (k.startsWith(P_PREFIX)) positionDrafts[k.slice(P_PREFIX.length)] = v;
201
+ });
202
+ return { typeDrafts, positionDrafts };
203
+ }
204
+ function readPeers(states, selfClientId) {
205
+ const byId = /* @__PURE__ */ new Map();
206
+ for (const st of states || []) {
207
+ const clientId = st.clientId;
208
+ const u = st.user;
209
+ if (!u || !u.id) continue;
210
+ const cur = byId.get(u.id);
211
+ if (!cur || u.drag && !cur.drag || u.mode === "editing" && cur.mode !== "editing" && !cur.drag) {
212
+ byId.set(u.id, {
213
+ id: u.id,
214
+ name: u.name || "User",
215
+ mode: u.mode || "viewing",
216
+ drag: u.drag || null,
217
+ self: clientId === selfClientId
218
+ });
219
+ }
220
+ }
221
+ return [...byId.values()].sort((a, b) => a.self === b.self ? a.name.localeCompare(b.name) : a.self ? -1 : 1);
222
+ }
223
+ function newerStamp(last, sv, ts) {
224
+ return sv > last.sv || sv === last.sv && ts > last.ts;
225
+ }
226
+ function useGraphCollab(graphId, user, { fetchTicket } = {}) {
227
+ const live = useLiveDoc(graphId, { fetchTicket, field: "user" });
228
+ const ready = live.ready;
229
+ const [liveGraph, setLiveGraph] = (0, import_react2.useState)(null);
230
+ const [copilotBuilding, setCopilotBuilding] = (0, import_react2.useState)(false);
231
+ const [explorer, setExplorer] = (0, import_react2.useState)(null);
232
+ const [connect, setConnect] = (0, import_react2.useState)(null);
233
+ const [drafts, setDrafts] = (0, import_react2.useState)({ typeDrafts: {}, positionDrafts: {} });
234
+ const providerRef = (0, import_react2.useRef)(null);
235
+ providerRef.current = live.provider;
236
+ const draftsRef = (0, import_react2.useRef)(drafts);
237
+ const modeRef = (0, import_react2.useRef)("viewing");
238
+ const dragRef = (0, import_react2.useRef)(null);
239
+ const stampRef = (0, import_react2.useRef)({ sv: -1, ts: -1 });
240
+ const explorerStampRef = (0, import_react2.useRef)(null);
241
+ const connectJsonRef = (0, import_react2.useRef)("");
242
+ const userRef = (0, import_react2.useRef)(user);
243
+ userRef.current = user;
244
+ (0, import_react2.useEffect)(() => {
245
+ const ydoc = live.doc;
246
+ if (!ydoc) {
247
+ setLiveGraph(null);
248
+ setCopilotBuilding(false);
249
+ setExplorer(null);
250
+ setConnect(null);
251
+ stampRef.current = { sv: -1, ts: -1 };
252
+ explorerStampRef.current = null;
253
+ connectJsonRef.current = "";
254
+ draftsRef.current = { typeDrafts: {}, positionDrafts: {} };
255
+ setDrafts(draftsRef.current);
256
+ return void 0;
257
+ }
258
+ let dead = false;
259
+ const meta = ydoc.getMap("meta");
260
+ const draft = ydoc.getMap("draft");
261
+ const onMeta = () => {
262
+ if (dead) return;
263
+ const schema = meta.get("schema");
264
+ if (schema) {
265
+ const sv = Number(meta.get("schema_version") || 0);
266
+ const ts = Number(meta.get("version") || 0);
267
+ if (newerStamp(stampRef.current, sv, ts)) {
268
+ stampRef.current = { sv, ts };
269
+ setLiveGraph(schema);
270
+ }
271
+ }
272
+ const cop = meta.get("copilot");
273
+ setCopilotBuilding(!!(cop && cop.building && (!cop.at || Date.now() - cop.at < COPILOT_STALE_MS)));
274
+ const ex = meta.get("explorer");
275
+ const exVer = Number(ex && ex.version || 0);
276
+ if (explorerStampRef.current === null) {
277
+ explorerStampRef.current = exVer;
278
+ } else if (ex && ex.query && exVer > explorerStampRef.current) {
279
+ explorerStampRef.current = exVer;
280
+ setExplorer({
281
+ query: String(ex.query),
282
+ note: String(ex.note || ""),
283
+ requested_by: String(ex.requested_by || ""),
284
+ version: exVer
285
+ });
286
+ }
287
+ const cn = meta.get("connect");
288
+ if (cn) {
289
+ let json = "";
290
+ try {
291
+ json = JSON.stringify(cn);
292
+ } catch {
293
+ }
294
+ if (json && json !== connectJsonRef.current) {
295
+ connectJsonRef.current = json;
296
+ setConnect(cn);
297
+ }
298
+ }
299
+ };
300
+ const onDraft = () => {
301
+ if (dead) return;
302
+ const next = readDrafts(draft);
303
+ draftsRef.current = next;
304
+ setDrafts(next);
305
+ };
306
+ meta.observe(onMeta);
307
+ draft.observe(onDraft);
308
+ onMeta();
309
+ onDraft();
310
+ return () => {
311
+ dead = true;
312
+ meta.unobserve(onMeta);
313
+ draft.unobserve(onDraft);
314
+ };
315
+ }, [live.doc]);
316
+ (0, import_react2.useEffect)(() => {
317
+ const u = userRef.current || {};
318
+ live.setAwareness({ id: u.id || "me", name: u.name || "User", mode: modeRef.current, drag: null });
319
+ }, [graphId, live.setAwareness]);
320
+ const peers = (0, import_react2.useMemo)(() => readPeers(live.states, live.selfClientId), [live.states, live.selfClientId]);
321
+ const pushAwareness = (0, import_react2.useCallback)(() => {
322
+ const u = userRef.current || {};
323
+ live.setAwareness({ id: u.id || "me", name: u.name || "User", mode: modeRef.current, drag: dragRef.current });
324
+ }, [live.setAwareness]);
325
+ const setEditing = (0, import_react2.useCallback)((editing) => {
326
+ modeRef.current = editing ? "editing" : "viewing";
327
+ pushAwareness();
328
+ }, [pushAwareness]);
329
+ const setDrag = (0, import_react2.useCallback)((label, pos) => {
330
+ dragRef.current = label ? { label, x: Math.round(pos && pos.x || 0), y: Math.round(pos && pos.y || 0) } : null;
331
+ pushAwareness();
332
+ }, [pushAwareness]);
333
+ const writeDrafts = (0, import_react2.useCallback)((prefix, field, updater) => {
334
+ const cur = draftsRef.current[field];
335
+ const next = typeof updater === "function" ? updater(cur) : updater;
336
+ const p = providerRef.current;
337
+ if (!p) {
338
+ draftsRef.current = { ...draftsRef.current, [field]: next };
339
+ setDrafts(draftsRef.current);
340
+ return;
341
+ }
342
+ const map = p.document.getMap("draft");
343
+ p.document.transact(() => {
344
+ for (const [k, v] of Object.entries(next || {})) {
345
+ if (cur[k] !== v) map.set(prefix + k, v);
346
+ }
347
+ for (const k of Object.keys(cur || {})) {
348
+ if (!(k in (next || {}))) map.delete(prefix + k);
349
+ }
350
+ });
351
+ }, []);
352
+ const setTypeDrafts = (0, import_react2.useCallback)((u) => writeDrafts(T_PREFIX, "typeDrafts", u), [writeDrafts]);
353
+ const setPositionDrafts = (0, import_react2.useCallback)((u) => writeDrafts(P_PREFIX, "positionDrafts", u), [writeDrafts]);
354
+ const snapshotDraft = (0, import_react2.useCallback)(() => {
355
+ const { typeDrafts, positionDrafts } = draftsRef.current;
356
+ const raw = {};
357
+ for (const [k, v] of Object.entries(typeDrafts || {})) raw[T_PREFIX + k] = v;
358
+ for (const [k, v] of Object.entries(positionDrafts || {})) raw[P_PREFIX + k] = v;
359
+ return raw;
360
+ }, []);
361
+ const clearDraftEntries = (0, import_react2.useCallback)((consumed) => {
362
+ const entries = Object.entries(consumed || {});
363
+ if (!entries.length) return;
364
+ const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
365
+ const p = providerRef.current;
366
+ if (!p) {
367
+ const next = {
368
+ typeDrafts: { ...draftsRef.current.typeDrafts },
369
+ positionDrafts: { ...draftsRef.current.positionDrafts }
370
+ };
371
+ for (const [k, v] of entries) {
372
+ if (k.startsWith(T_PREFIX) && same(next.typeDrafts[k.slice(T_PREFIX.length)], v)) {
373
+ delete next.typeDrafts[k.slice(T_PREFIX.length)];
374
+ } else if (k.startsWith(P_PREFIX) && same(next.positionDrafts[k.slice(P_PREFIX.length)], v)) {
375
+ delete next.positionDrafts[k.slice(P_PREFIX.length)];
376
+ }
377
+ }
378
+ draftsRef.current = next;
379
+ setDrafts(next);
380
+ return;
381
+ }
382
+ const map = p.document.getMap("draft");
383
+ p.document.transact(() => {
384
+ for (const [k, v] of entries) {
385
+ if (map.has(k) && same(map.get(k), v)) map.delete(k);
386
+ }
387
+ });
388
+ }, []);
389
+ return {
390
+ ready,
391
+ liveGraph,
392
+ peers,
393
+ copilotBuilding,
394
+ // Latest copilot-shown query (show_query_results): {query, note,
395
+ // requested_by, version}. Strictly-newer only; null until one arrives
396
+ // while this window is connected.
397
+ explorer,
398
+ // Latest published Connect tool registry ({raw_enabled, tools}) — null
399
+ // until the doc carries one; the Connect pane treats it as fresher truth
400
+ // than its REST fetch.
401
+ connect,
402
+ setEditing,
403
+ setDrag,
404
+ snapshotDraft,
405
+ clearDraftEntries,
406
+ // Other people's in-flight node drags: [{id, name, color, label, x, y}] —
407
+ // the canvas shows their indicator glued to the node they are moving,
408
+ // in the same color as their presence avatar.
409
+ dragPeers: peers.filter((p) => !p.self && p.drag).map((p) => ({
410
+ id: p.id,
411
+ name: p.name,
412
+ color: peerColor(p.id),
413
+ label: p.drag.label,
414
+ x: p.drag.x,
415
+ y: p.drag.y
416
+ })),
417
+ draftStore: {
418
+ typeDrafts: drafts.typeDrafts,
419
+ positionDrafts: drafts.positionDrafts,
420
+ setTypeDrafts,
421
+ setPositionDrafts
422
+ }
423
+ };
424
+ }
425
+
426
+ // src/graph/vgraph.js
427
+ var _transport = null;
428
+ function configureVgraph(t) {
429
+ _transport = t;
430
+ }
431
+ async function send(method, path, body) {
432
+ const opts = { method, headers: _transport && _transport.headers ? { ..._transport.headers() } : {} };
433
+ if (body !== void 0) {
434
+ opts.headers["Content-Type"] = "application/json";
435
+ opts.body = JSON.stringify(body);
436
+ }
437
+ const base = _transport && _transport.base || "/api/vg";
438
+ const res = await fetch(base + path, opts);
439
+ if (!res.ok) {
440
+ const text = await res.text().catch(() => "");
441
+ const err = new Error(`vg-gateway ${res.status} on ${method} ${path}: ${text || res.statusText}`);
442
+ err.status = res.status;
443
+ throw err;
444
+ }
445
+ if (res.status === 204) return null;
446
+ return res.json();
447
+ }
448
+ function parseAssetRef(ref) {
449
+ const [kb, subgraph] = String(ref || "").split("#");
450
+ return { kb: kb || "", subgraph: subgraph || "" };
451
+ }
452
+ function schemaVersionNum(v) {
453
+ const s = String(v == null ? "" : v);
454
+ const m = s.match(/^(\d+)\.(\d+)$/);
455
+ if (m) return Number(m[1]) * 1e6 + Number(m[2]);
456
+ const n = Number(s);
457
+ return Number.isFinite(n) ? n * 1e6 : 0;
458
+ }
459
+ var vgraph = {
460
+ // Adapted KnowledgeBaseSchema → GraphPage shape (vertex_types/edge_types).
461
+ getGraph(kb, subgraph) {
462
+ const q = subgraph ? `?subgraph=${encodeURIComponent(subgraph)}` : "";
463
+ return send("GET", `/v1/graphs/${encodeURIComponent(kb)}${q}`);
464
+ },
465
+ health() {
466
+ return send("GET", "/healthz");
467
+ },
468
+ // ── Mutations (each returns the re-adapted graph for the subgraph) ──────
469
+ patchUi(kb, subgraph, kind, label, ui) {
470
+ return send("PATCH", `/v1/graphs/${encodeURIComponent(kb)}/ui`, { subgraph, kind, label, ui });
471
+ },
472
+ addVertexType(kb, subgraph, label, description, ui) {
473
+ return send("POST", `/v1/graphs/${encodeURIComponent(kb)}/vertex-types`, { subgraph, label, description, ui });
474
+ },
475
+ addEdgeType(kb, subgraph, label, description, connections, ui) {
476
+ return send("POST", `/v1/graphs/${encodeURIComponent(kb)}/edge-types`, { subgraph, label, description, connections, ui });
477
+ },
478
+ // Type meta (description). The label itself is immutable identity.
479
+ patchTypeMeta(kb, subgraph, kind, label, description) {
480
+ const seg = kind === "edge" ? "edge-types" : "vertex-types";
481
+ return send("PATCH", `/v1/graphs/${encodeURIComponent(kb)}/${seg}/${encodeURIComponent(label)}`, { subgraph, description });
482
+ },
483
+ addVertexProperty(kb, subgraph, label, prop) {
484
+ return send("POST", `/v1/graphs/${encodeURIComponent(kb)}/vertex-types/${encodeURIComponent(label)}/properties`, { subgraph, ...prop });
485
+ },
486
+ addEdgeProperty(kb, subgraph, label, prop) {
487
+ return send("POST", `/v1/graphs/${encodeURIComponent(kb)}/edge-types/${encodeURIComponent(label)}/properties`, { subgraph, ...prop });
488
+ },
489
+ // Property PATCH: attribute updates (default/description/ui) and/or a rename
490
+ // via new_name — schema-doc level; stored values are not migrated.
491
+ patchProperty(kb, subgraph, kind, label, name, patch) {
492
+ const seg = kind === "edge" ? "edge-types" : "vertex-types";
493
+ return send("PATCH", `/v1/graphs/${encodeURIComponent(kb)}/${seg}/${encodeURIComponent(label)}/properties/${encodeURIComponent(name)}`, { subgraph, ...patch });
494
+ },
495
+ // Property DELETE: schema-doc level — values already stored on records stay
496
+ // in place but are no longer read or written. Indexed properties 400.
497
+ deleteProperty(kb, subgraph, kind, label, name) {
498
+ const seg = kind === "edge" ? "edge-types" : "vertex-types";
499
+ return send("DELETE", `/v1/graphs/${encodeURIComponent(kb)}/${seg}/${encodeURIComponent(label)}/properties/${encodeURIComponent(name)}?subgraph=${encodeURIComponent(subgraph)}`);
500
+ },
501
+ // Indices. A semantic index on a string property makes the write path
502
+ // auto-embed the value into the d{dimensions} vector slot.
503
+ addIndex(kb, subgraph, kind, label, index) {
504
+ const seg = kind === "edge" ? "edge-types" : "vertex-types";
505
+ return send("POST", `/v1/graphs/${encodeURIComponent(kb)}/${seg}/${encodeURIComponent(label)}/indices`, { subgraph, ...index });
506
+ },
507
+ removeIndex(kb, subgraph, kind, label, indexName) {
508
+ const seg = kind === "edge" ? "edge-types" : "vertex-types";
509
+ return send("DELETE", `/v1/graphs/${encodeURIComponent(kb)}/${seg}/${encodeURIComponent(label)}/indices/${encodeURIComponent(indexName)}?subgraph=${encodeURIComponent(subgraph)}`);
510
+ },
511
+ // Schema-change jobs — mutations WITH data sync (drop a type incl. its
512
+ // records, drop/rename/retype a property incl. per-record migration). POST
513
+ // returns { job_id, status }; poll getSchemaChange until done|failed. While
514
+ // a job runs its labels are fenced: writes to them 409.
515
+ scheduleSchemaChange(kb, op, params) {
516
+ return send("POST", `/v1/graphs/${encodeURIComponent(kb)}/schema-changes`, { op, params, created_at: (/* @__PURE__ */ new Date()).toISOString() });
517
+ },
518
+ getSchemaChange(kb, jobId) {
519
+ return send("GET", `/v1/graphs/${encodeURIComponent(kb)}/schema-changes/${encodeURIComponent(jobId)}`);
520
+ },
521
+ addConnection(kb, subgraph, label, from_type, to_type) {
522
+ return send("POST", `/v1/graphs/${encodeURIComponent(kb)}/edge-types/${encodeURIComponent(label)}/connections`, { subgraph, from_type, to_type });
523
+ },
524
+ removeConnection(kb, subgraph, label, from_type, to_type) {
525
+ const q = `subgraph=${encodeURIComponent(subgraph)}&from_type=${encodeURIComponent(from_type)}&to_type=${encodeURIComponent(to_type)}`;
526
+ return send("DELETE", `/v1/graphs/${encodeURIComponent(kb)}/edge-types/${encodeURIComponent(label)}/connections?${q}`);
527
+ },
528
+ // ── Instance data plane (vertices). Edges/neighbors deferred (lib gap). ──
529
+ listInstances(kb, label, limit = 50) {
530
+ return send("GET", `/v1/graphs/${encodeURIComponent(kb)}/instances?label=${encodeURIComponent(label)}&limit=${limit}`);
531
+ },
532
+ createInstance(kb, label, properties) {
533
+ return send("POST", `/v1/graphs/${encodeURIComponent(kb)}/instances`, { label, properties });
534
+ },
535
+ neighbors(kb, vertexId, limit = 50) {
536
+ return send("GET", `/v1/graphs/${encodeURIComponent(kb)}/instances/${encodeURIComponent(vertexId)}/neighbors?limit=${limit}`);
537
+ },
538
+ // Free-text search across all vertices (semantic + fulltext where available;
539
+ // substring today). Returns { results: [{id,label,title,fields}] }.
540
+ searchAll(kb, q, limit = 20) {
541
+ return send("GET", `/v1/graphs/${encodeURIComponent(kb)}/search?q=${encodeURIComponent(q || "")}&limit=${limit}`);
542
+ },
543
+ // Raw Gremlin++ over the tenant. Rejects (throws) on syntax/other errors so the
544
+ // caller can tell a valid query from free text. Returns { data, vertex_ids, … }.
545
+ gremlin(kb, query) {
546
+ return send("POST", "/v1/gremlin", { query, tenant_id: kb });
547
+ },
548
+ // Indexed full-text search (case-insensitive substring) via the textSearch step,
549
+ // across common text properties, merged + de-duped. The gateway rejects MULTIPLE
550
+ // textSearch steps in one query, so fire one per property in parallel; a property
551
+ // that isn't FTS-indexed just returns nothing (harmless). Returns { data: [rows] }
552
+ // of valueMap(true) vertex rows. Callers fall back to searchAll on empty/error.
553
+ async searchFts(kb, q, props = ["name", "email", "title", "body", "slug", "display_name"]) {
554
+ const esc = String(q || "").replace(/\\/g, "\\\\").replace(/'/g, "\\'");
555
+ if (!esc.trim()) return { data: [] };
556
+ const settled = await Promise.allSettled(props.map((p) => send("POST", "/v1/gremlin", {
557
+ query: `g.V().textSearch('${p}', '${esc}').limit(20).valueMap(true)`,
558
+ tenant_id: kb
559
+ })));
560
+ const byId = /* @__PURE__ */ new Map();
561
+ for (const s of settled) {
562
+ if (s.status !== "fulfilled") continue;
563
+ for (const row of s.value.data || []) {
564
+ if (row && row.id != null && !byId.has(row.id)) byId.set(row.id, row);
565
+ }
566
+ }
567
+ return { data: [...byId.values()] };
568
+ },
569
+ createEdge(kb, label, from_id, to_id, properties = {}) {
570
+ return send("POST", `/v1/graphs/${encodeURIComponent(kb)}/edges`, { label, from_id, to_id, properties });
571
+ }
572
+ };
573
+ var DATA_TYPES = ["string", "integer", "double", "boolean", "datetime", "json", "file", "vector"];
574
+ var EMBEDDER_BASE = "azure/text-embedding-3-large";
575
+ var LONG_TEXT_NAME = /(body|content|description|summary|note|text|bio|about|detail|transcript|comment|review|message|abstract|story)/i;
576
+ function semanticDimsFor(propName) {
577
+ return LONG_TEXT_NAME.test(String(propName || "")) ? 1536 : 384;
578
+ }
579
+ function semanticIndexFor(propName, dims) {
580
+ const d = dims || semanticDimsFor(propName);
581
+ return { name: `${propName}_semantic`, property: propName, type: "semantic", embedder: `${EMBEDDER_BASE}@${d}`, dimensions: d };
582
+ }
583
+ function semanticIndexOn(type, propName) {
584
+ return (type && type.indices || []).find((i) => i.type === "semantic" && i.property === propName) || null;
585
+ }
586
+ async function pollSchemaChange(kb, jobId, { intervalMs = 1200, timeoutMs = 18e4, onTick } = {}) {
587
+ const t0 = Date.now();
588
+ for (; ; ) {
589
+ const job = await vgraph.getSchemaChange(kb, jobId);
590
+ if (onTick) onTick(job);
591
+ if (job.status === "done" || job.status === "failed") return job;
592
+ if (Date.now() - t0 > timeoutMs) throw new Error(`schema change ${jobId} still ${job.status} after ${timeoutMs}ms`);
593
+ await new Promise((r) => setTimeout(r, intervalMs));
594
+ }
595
+ }
596
+
597
+ // src/graph/draft.js
598
+ function applyTypeDraft(t, d, isVertex) {
599
+ t.ui = { ...t.ui || {} };
600
+ if (d.color != null) t.ui.color = d.color;
601
+ if (d.icon != null) t.ui.icon = d.icon;
602
+ if (d.labelProps != null) t.ui.labelProps = d.labelProps;
603
+ if (d.description != null) t.description = d.description;
604
+ for (const raw of d.props || []) {
605
+ if (!raw.name || !raw.name.trim()) continue;
606
+ const name = raw.name.trim();
607
+ if ((t.properties || []).some((p2) => p2.name === name)) continue;
608
+ const p = { name, type: raw.type || "string" };
609
+ if (p.type === "vector") p.dimensions = Number(raw.dimensions) || null;
610
+ t.properties = [...t.properties || [], p];
611
+ if (isVertex && p.type === "string" && raw.semantic) {
612
+ t.indices = [...t.indices || [], semanticIndexFor(name)];
613
+ }
614
+ }
615
+ if (!isVertex) {
616
+ let conns = (t.connections || []).slice();
617
+ for (const c of d.addConns || []) {
618
+ if (!conns.some((x) => x.from_type === c.from_type && x.to_type === c.to_type)) {
619
+ conns.push({ from_type: c.from_type, to_type: c.to_type });
620
+ }
621
+ }
622
+ for (const c of d.removeConns || []) {
623
+ conns = conns.filter((x) => !(x.from_type === c.from_type && x.to_type === c.to_type));
624
+ }
625
+ t.connections = conns;
626
+ }
627
+ }
628
+ function materializeDraft(graph, { typeDrafts = {}, positions = {} }) {
629
+ const clone = JSON.parse(JSON.stringify(graph || {}));
630
+ for (const vt of clone.vertex_types || []) {
631
+ const label = vt.label || vt.name;
632
+ vt.ui = { ...vt.ui || {} };
633
+ if (positions[label]) vt.ui.position = { x: Math.round(positions[label].x), y: Math.round(positions[label].y) };
634
+ const d = typeDrafts[`vertex:${label}`];
635
+ if (d) applyTypeDraft(vt, d, true);
636
+ }
637
+ if (clone.node_types) clone.node_types = clone.vertex_types;
638
+ for (const et of clone.edge_types || []) {
639
+ const d = typeDrafts[`edge:${et.label || et.name}`];
640
+ if (d) applyTypeDraft(et, d, false);
641
+ }
642
+ return clone;
643
+ }
644
+ function friendlyDetail(status, detail) {
645
+ if (status === 409) {
646
+ return "Part of this schema is still being updated by an earlier change. Please try again in a moment.";
647
+ }
648
+ if (typeof detail === "string" && detail) return detail;
649
+ if (detail && typeof detail === "object") {
650
+ const items = (detail.problems || detail.violations || []).map((v) => v.where ? `${v.where}: ${v.error}` : v.error).filter(Boolean).slice(0, 6);
651
+ return [detail.message || "Some changes could not be applied.", ...items].join("\n");
652
+ }
653
+ return "Your changes could not be saved. Please try again.";
654
+ }
655
+ async function saveDraft(graphId, kb, draftGraph, { request }) {
656
+ const res = await request(`/v1/cg/graphs/${encodeURIComponent(graphId)}/schema/save`, {
657
+ method: "POST",
658
+ headers: { "content-type": "application/json" },
659
+ body: JSON.stringify({ draft: draftGraph, client_clears_draft: true })
660
+ });
661
+ let body = null;
662
+ try {
663
+ body = await res.json();
664
+ } catch {
665
+ }
666
+ if (!res.ok) {
667
+ const err = new Error(friendlyDetail(res.status, body && body.detail));
668
+ err.friendly = true;
669
+ err.status = res.status;
670
+ throw err;
671
+ }
672
+ if (body && body.job_id) {
673
+ const job = await pollSchemaChange(kb, body.job_id);
674
+ if (job.status === "failed") {
675
+ const err = new Error("Part of this change could not be applied. The schema was reloaded; please review and try again.");
676
+ err.friendly = true;
677
+ throw err;
678
+ }
679
+ return vgraph.getGraph(kb, "default");
680
+ }
681
+ return body && body.graph;
682
+ }
683
+
684
+ // src/graph/ConnectPane.jsx
685
+ var import_react9 = require("react");
686
+ var import_lucide_react2 = require("lucide-react");
687
+
688
+ // src/components/CodeBlock.jsx
689
+ var import_react3 = __toESM(require("react"), 1);
690
+ var import_jsx_runtime = require("react/jsx-runtime");
691
+ var _hljsPromise = null;
692
+ function loadHljs() {
693
+ if (!_hljsPromise) {
694
+ _hljsPromise = import("highlight.js/lib/core").then((m) => m.default || m);
695
+ }
696
+ return _hljsPromise;
697
+ }
698
+ var GRAMMARS = {
699
+ javascript: () => import("highlight.js/lib/languages/javascript"),
700
+ typescript: () => import("highlight.js/lib/languages/typescript"),
701
+ python: () => import("highlight.js/lib/languages/python"),
702
+ json: () => import("highlight.js/lib/languages/json"),
703
+ bash: () => import("highlight.js/lib/languages/bash"),
704
+ sql: () => import("highlight.js/lib/languages/sql"),
705
+ java: () => import("highlight.js/lib/languages/java"),
706
+ go: () => import("highlight.js/lib/languages/go"),
707
+ rust: () => import("highlight.js/lib/languages/rust"),
708
+ xml: () => import("highlight.js/lib/languages/xml"),
709
+ css: () => import("highlight.js/lib/languages/css"),
710
+ yaml: () => import("highlight.js/lib/languages/yaml"),
711
+ groovy: () => import("highlight.js/lib/languages/groovy")
712
+ };
713
+ var ALIASES = {
714
+ js: "javascript",
715
+ jsx: "javascript",
716
+ mjs: "javascript",
717
+ cjs: "javascript",
718
+ node: "javascript",
719
+ ts: "typescript",
720
+ tsx: "typescript",
721
+ py: "python",
722
+ python3: "python",
723
+ sh: "bash",
724
+ shell: "bash",
725
+ zsh: "bash",
726
+ console: "bash",
727
+ html: "xml",
728
+ xhtml: "xml",
729
+ svg: "xml",
730
+ yml: "yaml",
731
+ golang: "go",
732
+ rs: "rust",
733
+ jsonc: "json",
734
+ postgres: "sql",
735
+ postgresql: "sql",
736
+ mysql: "sql",
737
+ plsql: "sql",
738
+ gremlin: "groovy"
739
+ };
740
+ function canonicalLang(tag) {
741
+ const t = String(tag || "").toLowerCase();
742
+ if (!t) return null;
743
+ const name = ALIASES[t] || t;
744
+ return GRAMMARS[name] ? name : null;
745
+ }
746
+ var _ready = /* @__PURE__ */ new Map();
747
+ function ensureLanguage(name) {
748
+ if (!_ready.has(name)) {
749
+ const p = Promise.all([loadHljs(), GRAMMARS[name]()]).then(([hljs, mod]) => {
750
+ if (!hljs.getLanguage(name)) hljs.registerLanguage(name, mod.default || mod);
751
+ return hljs;
752
+ }).catch(() => null);
753
+ _ready.set(name, p);
754
+ }
755
+ return _ready.get(name);
756
+ }
757
+ function CodeBlock(props) {
758
+ const { code, language, className } = props;
759
+ const src = String(code || "");
760
+ const lang = canonicalLang(language);
761
+ const [hl, setHl] = import_react3.default.useState(null);
762
+ import_react3.default.useEffect(() => {
763
+ if (!lang || !src) return void 0;
764
+ let cancelled = false;
765
+ const timer = setTimeout(() => {
766
+ ensureLanguage(lang).then((hljs) => {
767
+ if (!hljs || cancelled) return;
768
+ try {
769
+ const out = hljs.highlight(src, { language: lang, ignoreIllegals: true });
770
+ if (!cancelled) setHl({ src, html: out.value });
771
+ } catch {
772
+ }
773
+ });
774
+ }, 200);
775
+ return () => {
776
+ cancelled = true;
777
+ clearTimeout(timer);
778
+ };
779
+ }, [src, lang]);
780
+ const html = hl && hl.src === src ? hl.html : null;
781
+ const label = String(language || "").toLowerCase();
782
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("pre", { className: "wbx-code" + (className ? " " + className : ""), children: [
783
+ label ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "wbx-code-lang", "aria-hidden": "true", children: label }) : null,
784
+ html != null ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { className: "hljs language-" + label, dangerouslySetInnerHTML: { __html: html } }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { className: label ? "language-" + label : void 0, children: src })
785
+ ] });
786
+ }
787
+
788
+ // src/graph/format.js
789
+ function fmtUnits(c) {
790
+ const num = (v) => typeof v === "number" && isFinite(v) ? (Math.round(v * 10) / 10).toString() : null;
791
+ if (!c) return null;
792
+ const r = num(c.read_units);
793
+ const w = num(c.write_units);
794
+ if (r == null && w == null) return null;
795
+ return `${r ?? "\u2014"} read units \xB7 ${w ?? "\u2014"} write units`;
796
+ }
797
+ function relativeTime(ts) {
798
+ if (!ts) return null;
799
+ const delta = Date.now() - ts;
800
+ const m = Math.floor(delta / 6e4);
801
+ if (m < 1) return "just now";
802
+ if (m < 60) return `${m} min ago`;
803
+ const h = Math.floor(m / 60);
804
+ if (h < 24) return `${h} h ago`;
805
+ const d = Math.floor(h / 24);
806
+ if (d < 30) return `${d} d ago`;
807
+ const mo = Math.floor(d / 30);
808
+ if (mo < 12) return `${mo} mo ago`;
809
+ return `${Math.floor(d / 365)} y ago`;
810
+ }
811
+ function absoluteTime(ts) {
812
+ if (!ts) return null;
813
+ return new Date(ts).toLocaleString(void 0, { dateStyle: "medium", timeStyle: "short" });
814
+ }
815
+
816
+ // src/components/Modal.jsx
817
+ var import_react6 = __toESM(require("react"), 1);
818
+ var import_react_dom = require("react-dom");
819
+
820
+ // src/components/icons.jsx
821
+ var import_react4 = __toESM(require("react"), 1);
822
+ var import_jsx_runtime2 = require("react/jsx-runtime");
823
+ function Svg({ children, s = 16 }) {
824
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
825
+ "svg",
826
+ {
827
+ width: s,
828
+ height: s,
829
+ viewBox: "0 0 24 24",
830
+ fill: "none",
831
+ stroke: "currentColor",
832
+ strokeWidth: "1.8",
833
+ strokeLinecap: "round",
834
+ strokeLinejoin: "round",
835
+ children
836
+ }
837
+ );
838
+ }
839
+ var IcX = ({ size = 14 }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Svg, { s: size, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M18 6 6 18M6 6l12 12" }) });
840
+
841
+ // src/components/overlay.js
842
+ var import_react5 = require("react");
843
+ var stack = [];
844
+ var listening = false;
845
+ function onKey(e) {
846
+ if (e.key !== "Escape") return;
847
+ const top = stack[stack.length - 1];
848
+ if (!top) return;
849
+ e.preventDefault();
850
+ top.onEscape?.();
851
+ }
852
+ function listen() {
853
+ if (listening || typeof document === "undefined") return;
854
+ document.addEventListener("keydown", onKey);
855
+ listening = true;
856
+ }
857
+ function unlisten() {
858
+ if (!listening || stack.length) return;
859
+ document.removeEventListener("keydown", onKey);
860
+ listening = false;
861
+ }
862
+ function pushOverlay(entry) {
863
+ stack.push(entry);
864
+ listen();
865
+ return () => {
866
+ const i = stack.indexOf(entry);
867
+ if (i >= 0) stack.splice(i, 1);
868
+ unlisten();
869
+ };
870
+ }
871
+ function useOverlayEscape(active, onEscape) {
872
+ (0, import_react5.useEffect)(() => {
873
+ if (!active) return void 0;
874
+ return pushOverlay({ onEscape });
875
+ }, [active, onEscape]);
876
+ }
877
+
878
+ // src/components/Modal.jsx
879
+ var import_jsx_runtime3 = require("react/jsx-runtime");
880
+ function Modal(props) {
881
+ const {
882
+ open,
883
+ onClose,
884
+ title,
885
+ description,
886
+ actions,
887
+ size = "md",
888
+ width,
889
+ labelledBy,
890
+ children,
891
+ classNames = {}
892
+ } = props;
893
+ const titleId = (0, import_react6.useId)();
894
+ const escape = (0, import_react6.useCallback)(() => onClose?.(), [onClose]);
895
+ useOverlayEscape(open, escape);
896
+ (0, import_react6.useEffect)(() => {
897
+ if (!open || typeof document === "undefined") return void 0;
898
+ const prev = document.body.style.overflow;
899
+ document.body.style.overflow = "hidden";
900
+ return () => {
901
+ document.body.style.overflow = prev;
902
+ };
903
+ }, [open]);
904
+ if (!open || typeof document === "undefined") return null;
905
+ const onBackdrop = (e) => {
906
+ if (e.target === e.currentTarget) onClose?.();
907
+ };
908
+ return (0, import_react_dom.createPortal)(
909
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
910
+ "div",
911
+ {
912
+ className: ["uic-modal-backdrop", classNames.backdrop || ""].filter(Boolean).join(" "),
913
+ onMouseDown: onBackdrop,
914
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
915
+ "div",
916
+ {
917
+ className: ["uic-modal", `is-${size}`, classNames.root || ""].filter(Boolean).join(" "),
918
+ style: width ? { width } : void 0,
919
+ role: "dialog",
920
+ "aria-modal": "true",
921
+ "aria-labelledby": labelledBy || (title ? titleId : void 0),
922
+ children: [
923
+ title || actions ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "uic-modal-h", children: [
924
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "uic-modal-title", children: [
925
+ title ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { id: titleId, children: title }) : null,
926
+ description ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { children: description }) : null
927
+ ] }),
928
+ actions,
929
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: "uic-modal-x", "aria-label": "Close", onClick: onClose, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(IcX, { size: 18 }) })
930
+ ] }) : null,
931
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: ["uic-modal-b", classNames.body || ""].filter(Boolean).join(" "), children })
932
+ ]
933
+ }
934
+ )
935
+ }
936
+ ),
937
+ document.body
938
+ );
939
+ }
940
+
941
+ // src/graph/Skeleton.jsx
942
+ var import_react7 = __toESM(require("react"), 1);
943
+ var import_jsx_runtime4 = require("react/jsx-runtime");
944
+ function Skeleton({ variant = "line", w, h, radius, className = "", style }) {
945
+ const cls = `sk sk-${variant}${className ? " " + className : ""}`;
946
+ const s = { ...style || {} };
947
+ if (w != null) s.width = typeof w === "number" ? `${w}px` : w;
948
+ if (h != null) s.height = typeof h === "number" ? `${h}px` : h;
949
+ if (radius != null) s.borderRadius = typeof radius === "number" ? `${radius}px` : radius;
950
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: cls, style: s, "aria-hidden": "true" });
951
+ }
952
+
953
+ // src/graph/ConnectToolDetail.jsx
954
+ var import_react8 = require("react");
955
+ var import_lucide_react = require("lucide-react");
956
+ var import_jsx_runtime5 = require("react/jsx-runtime");
957
+ var RUN_QUERY_TOOL = "run_query";
958
+ var RUN_QUERY_DESCRIPTION = "Run any query. Lets a connected agent read and change anything in this graph with free-form queries. Turn it off to limit agents to the tools you define.";
959
+ var NAME_RE = /^[a-z][a-z0-9_]{0,63}$/;
960
+ var NAME_HINT = "Lowercase letters, digits and underscores, starting with a letter.";
961
+ var PARAM_TYPES = ["string", "number", "boolean"];
962
+ function Switch({ checked, onChange, disabled, label }) {
963
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "switch", children: [
964
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
965
+ "input",
966
+ {
967
+ type: "checkbox",
968
+ checked,
969
+ disabled,
970
+ onChange: (e) => onChange(e.target.checked),
971
+ "aria-label": label
972
+ }
973
+ ),
974
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "slider" })
975
+ ] });
976
+ }
977
+ var rowSeq = 0;
978
+ var newRow = (p = {}) => ({
979
+ key: `r${rowSeq++}`,
980
+ name: p.name || "",
981
+ type: PARAM_TYPES.includes(p.type) ? p.type : "string",
982
+ description: p.description || "",
983
+ required: p.required !== false,
984
+ default: p.default == null ? "" : String(p.default)
985
+ });
986
+ var initRows = (tool) => (tool?.params || []).map(newRow);
987
+ var normRows = (rows) => rows.map((r) => ({ name: r.name, type: r.type, description: r.description, required: !!r.required, default: r.default }));
988
+ function TypeSelect({ value, onChange, disabled }) {
989
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "select-wrap cn-type-sel", children: [
990
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("select", { className: "select", value, disabled, onChange: (e) => onChange(e.target.value), "aria-label": "Parameter type", children: PARAM_TYPES.map((t) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: t, children: t }, t)) }),
991
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "chev", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react.ChevronDown, { size: 13 }) })
992
+ ] });
993
+ }
994
+ function parseDefault(row) {
995
+ const raw = row.default.trim();
996
+ if (!raw) return { value: void 0 };
997
+ if (row.type === "number") {
998
+ const n = Number(raw);
999
+ return isFinite(n) ? { value: n } : { error: "Default must be a number." };
1000
+ }
1001
+ if (row.type === "boolean") {
1002
+ if (raw === "true") return { value: true };
1003
+ if (raw === "false") return { value: false };
1004
+ return { error: "Default must be true or false." };
1005
+ }
1006
+ return { value: raw };
1007
+ }
1008
+ function mapServerErrors(detail, rows) {
1009
+ const out = { fields: {}, params: {}, general: [] };
1010
+ if (typeof detail === "string" && detail) {
1011
+ out.general.push(detail);
1012
+ return out;
1013
+ }
1014
+ if (!detail || typeof detail !== "object") {
1015
+ out.general.push("Your changes could not be saved.");
1016
+ return out;
1017
+ }
1018
+ const items = detail.problems || detail.violations || detail.errors || [];
1019
+ if (detail.message) out.general.push(detail.message);
1020
+ for (const it of items) {
1021
+ const where = String(it?.where || it?.field || "").toLowerCase();
1022
+ const msg = it?.error || it?.message || String(it);
1023
+ if (["name", "description", "query"].includes(where)) out.fields[where] = msg;
1024
+ else if (rows.some((r) => r.name === where)) out.params[where] = msg;
1025
+ else out.general.push(where ? `${where}: ${msg}` : msg);
1026
+ }
1027
+ if (!out.general.length && !items.length && !detail.message) out.general.push("Your changes could not be saved.");
1028
+ return out;
1029
+ }
1030
+ function initialValues(params) {
1031
+ const v = {};
1032
+ for (const p of params || []) v[p.name] = p.default == null ? "" : String(p.default);
1033
+ return v;
1034
+ }
1035
+ function BoolSelect({ value, onChange, disabled, label, id }) {
1036
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "select-wrap cn-type-sel", children: [
1037
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("select", { id, className: "select", value, onChange: (e) => onChange(e.target.value), disabled, "aria-label": label, children: [
1038
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "", children: "not set" }),
1039
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "true", children: "true" }),
1040
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "false", children: "false" })
1041
+ ] }),
1042
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "chev", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react.ChevronDown, { size: 13 }) })
1043
+ ] });
1044
+ }
1045
+ function TryIt({ client, graphId, tool, builtin, dirty }) {
1046
+ const params = tool?.params || [];
1047
+ const [values, setValues] = (0, import_react8.useState)(() => initialValues(params));
1048
+ const [query, setQuery] = (0, import_react8.useState)("");
1049
+ const [errors, setErrors] = (0, import_react8.useState)({});
1050
+ const [runError, setRunError] = (0, import_react8.useState)("");
1051
+ const [result, setResult] = (0, import_react8.useState)(null);
1052
+ const [busy, setBusy] = (0, import_react8.useState)(false);
1053
+ const run = async () => {
1054
+ const errs = {};
1055
+ const args = {};
1056
+ if (builtin) {
1057
+ if (!query.trim()) {
1058
+ setRunError("Enter a query to run.");
1059
+ return;
1060
+ }
1061
+ args.query = query;
1062
+ } else {
1063
+ for (const p of params) {
1064
+ const raw = String(values[p.name] ?? "").trim();
1065
+ if (!raw) {
1066
+ if (p.required && p.default == null) errs[p.name] = "Required.";
1067
+ continue;
1068
+ }
1069
+ if (p.type === "number") {
1070
+ const n = Number(raw);
1071
+ if (!isFinite(n)) {
1072
+ errs[p.name] = "Must be a number.";
1073
+ continue;
1074
+ }
1075
+ args[p.name] = n;
1076
+ } else if (p.type === "boolean") {
1077
+ args[p.name] = raw === "true";
1078
+ } else {
1079
+ args[p.name] = raw;
1080
+ }
1081
+ }
1082
+ }
1083
+ setErrors(errs);
1084
+ setRunError("");
1085
+ if (Object.keys(errs).length) return;
1086
+ setBusy(true);
1087
+ setResult(null);
1088
+ try {
1089
+ const body = await client.testConnectTool(graphId, builtin ? RUN_QUERY_TOOL : tool.name, args);
1090
+ setResult(body);
1091
+ } catch (e) {
1092
+ setRunError(e?.message || "The test run failed.");
1093
+ } finally {
1094
+ setBusy(false);
1095
+ }
1096
+ };
1097
+ const units = result ? fmtUnits(result.consumption) : null;
1098
+ let dataText = "";
1099
+ if (result) {
1100
+ try {
1101
+ dataText = JSON.stringify(result.data ?? null, null, 2);
1102
+ } catch {
1103
+ dataText = String(result.data);
1104
+ }
1105
+ }
1106
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: "cn-dsec", children: [
1107
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h4", { className: "cn-dsec-h", children: "Try it" }),
1108
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "cn-hint cn-dsec-sub", children: "Runs this tool exactly as a connected agent would, without needing an API key." }),
1109
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("form", { className: "cn-try", onSubmit: (e) => {
1110
+ e.preventDefault();
1111
+ if (!busy) run();
1112
+ }, children: [
1113
+ builtin ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "field", children: [
1114
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: "cn-try-q", children: "Query" }),
1115
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1116
+ "textarea",
1117
+ {
1118
+ id: "cn-try-q",
1119
+ className: "textarea mono cn-ed-query",
1120
+ value: query,
1121
+ onChange: (e) => setQuery(e.target.value),
1122
+ rows: 4,
1123
+ placeholder: "g.V().limit(5)",
1124
+ spellCheck: false,
1125
+ disabled: busy
1126
+ }
1127
+ )
1128
+ ] }) : params.length ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cn-test-params", children: params.map((p) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "field cn-test-field", children: [
1129
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { htmlFor: `cn-try-${p.name}`, children: [
1130
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "mono", children: p.name }),
1131
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "cn-hint", children: [
1132
+ " ",
1133
+ p.type,
1134
+ p.required ? ", required" : ""
1135
+ ] })
1136
+ ] }),
1137
+ p.type === "boolean" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1138
+ BoolSelect,
1139
+ {
1140
+ id: `cn-try-${p.name}`,
1141
+ value: String(values[p.name] ?? ""),
1142
+ onChange: (v) => setValues((s) => ({ ...s, [p.name]: v })),
1143
+ disabled: busy,
1144
+ label: p.name
1145
+ }
1146
+ ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1147
+ "input",
1148
+ {
1149
+ id: `cn-try-${p.name}`,
1150
+ className: "input sm" + (p.type === "number" ? " mono" : ""),
1151
+ inputMode: p.type === "number" ? "decimal" : void 0,
1152
+ value: values[p.name] ?? "",
1153
+ onChange: (e) => setValues((s) => ({ ...s, [p.name]: e.target.value })),
1154
+ placeholder: p.description || p.name,
1155
+ disabled: busy
1156
+ }
1157
+ ),
1158
+ errors[p.name] && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cn-err", children: errors[p.name] })
1159
+ ] }, p.name)) }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cn-hint", children: "This tool takes no parameters." }),
1160
+ runError && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cn-err", children: runError }),
1161
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cn-try-run", children: [
1162
+ dirty && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "cn-hint cn-try-note", children: "Testing the last saved version" }),
1163
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { type: "submit", className: "btn sm", disabled: busy, children: [
1164
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react.Play, { size: 13 }),
1165
+ " ",
1166
+ busy ? "Running\u2026" : "Run"
1167
+ ] })
1168
+ ] })
1169
+ ] }),
1170
+ result && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cn-test-result", children: [
1171
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cn-test-units mono", children: units || "\u2014" }),
1172
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CodeBlock, { code: dataText, language: "json", className: "cn-test-json" })
1173
+ ] })
1174
+ ] });
1175
+ }
1176
+ function ConnectToolDetail({
1177
+ client,
1178
+ graphId,
1179
+ tool,
1180
+ builtin,
1181
+ isDraft,
1182
+ enabled,
1183
+ busy,
1184
+ takenNames,
1185
+ narrow,
1186
+ onBack,
1187
+ onToggle,
1188
+ onSave,
1189
+ onDelete,
1190
+ onDirtyChange
1191
+ }) {
1192
+ const [name, setName] = (0, import_react8.useState)(tool?.name || "");
1193
+ const [description, setDescription] = (0, import_react8.useState)(tool?.description || "");
1194
+ const [query, setQuery] = (0, import_react8.useState)(tool?.query || "");
1195
+ const [rows, setRows] = (0, import_react8.useState)(() => initRows(tool));
1196
+ const [fieldErrors, setFieldErrors] = (0, import_react8.useState)({});
1197
+ const [paramErrors, setParamErrors] = (0, import_react8.useState)({});
1198
+ const [general, setGeneral] = (0, import_react8.useState)([]);
1199
+ const [saving, setSaving] = (0, import_react8.useState)(false);
1200
+ const baselineRef = (0, import_react8.useRef)(tool || null);
1201
+ const setRow = (key, patch) => setRows((rs) => rs.map((r) => r.key === key ? { ...r, ...patch } : r));
1202
+ const dirty = (0, import_react8.useMemo)(() => {
1203
+ if (builtin) return false;
1204
+ const b = baselineRef.current;
1205
+ return name !== (b?.name || "") || description !== (b?.description || "") || query !== (b?.query || "") || JSON.stringify(normRows(rows)) !== JSON.stringify(normRows(initRows(b)));
1206
+ }, [builtin, name, description, query, rows]);
1207
+ const onDirtyRef = (0, import_react8.useRef)(onDirtyChange);
1208
+ onDirtyRef.current = onDirtyChange;
1209
+ (0, import_react8.useEffect)(() => {
1210
+ onDirtyRef.current?.(dirty, baselineRef.current?.name || name.trim() || "new tool");
1211
+ }, [dirty, name]);
1212
+ (0, import_react8.useEffect)(() => () => {
1213
+ onDirtyRef.current?.(false, "");
1214
+ }, []);
1215
+ (0, import_react8.useEffect)(() => {
1216
+ if (builtin || isDraft || !tool || tool === baselineRef.current || dirty) return;
1217
+ baselineRef.current = tool;
1218
+ setName(tool.name || "");
1219
+ setDescription(tool.description || "");
1220
+ setQuery(tool.query || "");
1221
+ setRows(initRows(tool));
1222
+ }, [tool, dirty, builtin, isDraft]);
1223
+ const placeholderHint = (0, import_react8.useMemo)(() => {
1224
+ if (builtin) return "";
1225
+ const used = new Set((query.match(/\$[a-z][a-z0-9_]*/g) || []).map((s) => s.slice(1)));
1226
+ const declared = new Set(rows.map((r) => r.name).filter(Boolean));
1227
+ const undeclared = [...used].filter((n) => !declared.has(n));
1228
+ const unused = [...declared].filter((n) => !used.has(n));
1229
+ const bits = [];
1230
+ if (undeclared.length) bits.push(`$${undeclared.join(", $")} in the query has no matching parameter`);
1231
+ if (unused.length) bits.push(`parameter ${unused.join(", ")} is never used in the query`);
1232
+ return bits.join("; ");
1233
+ }, [builtin, query, rows]);
1234
+ const submit = async () => {
1235
+ const fe = {};
1236
+ const pe = {};
1237
+ const nm = name.trim();
1238
+ if (!NAME_RE.test(nm)) fe.name = NAME_HINT;
1239
+ else if (nm !== baselineRef.current?.name && takenNames.has(nm)) fe.name = "A tool with this name already exists.";
1240
+ if (!query.trim()) fe.query = "The query cannot be empty.";
1241
+ const seen = /* @__PURE__ */ new Set();
1242
+ const params = [];
1243
+ for (const r of rows) {
1244
+ const pn = r.name.trim();
1245
+ if (!NAME_RE.test(pn)) {
1246
+ pe[r.key] = NAME_HINT;
1247
+ continue;
1248
+ }
1249
+ if (seen.has(pn)) {
1250
+ pe[r.key] = "Duplicate parameter name.";
1251
+ continue;
1252
+ }
1253
+ seen.add(pn);
1254
+ const def2 = parseDefault(r);
1255
+ if (def2.error) {
1256
+ pe[r.key] = def2.error;
1257
+ continue;
1258
+ }
1259
+ const p = { name: pn, type: r.type, description: r.description.trim(), required: !!r.required };
1260
+ if (def2.value !== void 0) p.default = def2.value;
1261
+ params.push(p);
1262
+ }
1263
+ setFieldErrors(fe);
1264
+ setParamErrors(pe);
1265
+ setGeneral([]);
1266
+ if (Object.keys(fe).length || Object.keys(pe).length) return;
1267
+ const def = {
1268
+ name: nm,
1269
+ description: description.trim(),
1270
+ query,
1271
+ params,
1272
+ enabled: baselineRef.current?.enabled !== false
1273
+ };
1274
+ setSaving(true);
1275
+ try {
1276
+ await onSave(def, isDraft ? null : baselineRef.current?.name || null);
1277
+ baselineRef.current = def;
1278
+ setName(def.name);
1279
+ setDescription(def.description);
1280
+ setQuery(def.query);
1281
+ setRows(initRows(def));
1282
+ } catch (e) {
1283
+ const mapped = mapServerErrors(e?.detail ?? e?.message, rows.map((r) => ({ ...r, name: r.name.trim() })));
1284
+ setFieldErrors(mapped.fields);
1285
+ const byKey = {};
1286
+ for (const r of rows) {
1287
+ if (mapped.params[r.name.trim()]) byKey[r.key] = mapped.params[r.name.trim()];
1288
+ }
1289
+ setParamErrors(byKey);
1290
+ setGeneral(mapped.general);
1291
+ } finally {
1292
+ setSaving(false);
1293
+ }
1294
+ };
1295
+ const headName = builtin ? RUN_QUERY_TOOL : isDraft ? name.trim() || "New tool" : baselineRef.current?.name || name;
1296
+ const disabledForms = saving;
1297
+ const savedParamsKey = JSON.stringify((tool?.params || []).map((p) => [p.name, p.type, p.default ?? null]));
1298
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cn-detail", children: [
1299
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cn-dhead", children: [
1300
+ narrow && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { type: "button", className: "btn sm ghost cn-dback", onClick: onBack, children: [
1301
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react.ArrowLeft, { size: 14 }),
1302
+ " Tools"
1303
+ ] }),
1304
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("code", { className: "mono cn-dname", title: headName, children: headName }),
1305
+ builtin && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "pill brand", children: "Built in" }),
1306
+ !isDraft && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1307
+ Switch,
1308
+ {
1309
+ checked: !!enabled,
1310
+ disabled: busy,
1311
+ onChange: onToggle,
1312
+ label: `Enable ${headName}`
1313
+ }
1314
+ )
1315
+ ] }),
1316
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cn-dscroll scroll", children: [
1317
+ builtin ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "cn-ddesc", children: RUN_QUERY_DESCRIPTION }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: "cn-dsec", children: [
1318
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h4", { className: "cn-dsec-h", children: "Definition" }),
1319
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "cn-hint cn-dsec-sub", children: "A tool is a named query agents can call with typed parameters. Keep the description specific; it is what agents read to decide when to use it." }),
1320
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("form", { className: "cn-ed", onSubmit: (e) => {
1321
+ e.preventDefault();
1322
+ if (!saving) submit();
1323
+ }, children: [
1324
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "field", children: [
1325
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: "cn-ed-name", children: "Name" }),
1326
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1327
+ "input",
1328
+ {
1329
+ id: "cn-ed-name",
1330
+ className: "input mono",
1331
+ value: name,
1332
+ onChange: (e) => setName(e.target.value),
1333
+ placeholder: "overdue_tickets",
1334
+ maxLength: 64,
1335
+ disabled: disabledForms,
1336
+ autoFocus: isDraft
1337
+ }
1338
+ ),
1339
+ fieldErrors.name && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cn-err", children: fieldErrors.name })
1340
+ ] }),
1341
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "field", children: [
1342
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: "cn-ed-desc", children: "Description" }),
1343
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1344
+ "input",
1345
+ {
1346
+ id: "cn-ed-desc",
1347
+ className: "input",
1348
+ value: description,
1349
+ onChange: (e) => setDescription(e.target.value),
1350
+ placeholder: "What this tool returns and when to use it",
1351
+ disabled: disabledForms
1352
+ }
1353
+ ),
1354
+ fieldErrors.description && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cn-err", children: fieldErrors.description })
1355
+ ] }),
1356
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "field", children: [
1357
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cn-ed-params-h", children: [
1358
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { children: "Parameters" }),
1359
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { type: "button", className: "btn sm", onClick: () => setRows((rs) => [...rs, newRow()]), disabled: disabledForms, children: [
1360
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react.Plus, { size: 13 }),
1361
+ " Add parameter"
1362
+ ] })
1363
+ ] }),
1364
+ rows.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cn-ed-params", children: [
1365
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cn-ed-prow cn-ed-phead", "aria-hidden": "true", children: [
1366
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "Name" }),
1367
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "Type" }),
1368
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "Description" }),
1369
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "Required" }),
1370
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "Default" }),
1371
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", {})
1372
+ ] }),
1373
+ rows.map((r) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cn-ed-prow-wrap", children: [
1374
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "cn-ed-prow", children: [
1375
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1376
+ "input",
1377
+ {
1378
+ className: "input sm mono",
1379
+ value: r.name,
1380
+ onChange: (e) => setRow(r.key, { name: e.target.value }),
1381
+ placeholder: "name",
1382
+ "aria-label": "Parameter name",
1383
+ maxLength: 64,
1384
+ disabled: disabledForms
1385
+ }
1386
+ ),
1387
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(TypeSelect, { value: r.type, onChange: (t) => setRow(r.key, { type: t }), disabled: disabledForms }),
1388
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1389
+ "input",
1390
+ {
1391
+ className: "input sm",
1392
+ value: r.description,
1393
+ onChange: (e) => setRow(r.key, { description: e.target.value }),
1394
+ placeholder: "What it means",
1395
+ "aria-label": "Parameter description",
1396
+ disabled: disabledForms
1397
+ }
1398
+ ),
1399
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "cn-ed-req", children: [
1400
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1401
+ "input",
1402
+ {
1403
+ type: "checkbox",
1404
+ checked: r.required,
1405
+ onChange: (e) => setRow(r.key, { required: e.target.checked }),
1406
+ disabled: disabledForms
1407
+ }
1408
+ ),
1409
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "Required" })
1410
+ ] }),
1411
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1412
+ "input",
1413
+ {
1414
+ className: "input sm mono",
1415
+ value: r.default,
1416
+ onChange: (e) => setRow(r.key, { default: e.target.value }),
1417
+ placeholder: r.type === "boolean" ? "true / false" : "none",
1418
+ "aria-label": "Default value",
1419
+ disabled: disabledForms
1420
+ }
1421
+ ),
1422
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1423
+ "button",
1424
+ {
1425
+ type: "button",
1426
+ className: "iconbtn danger",
1427
+ title: "Remove parameter",
1428
+ "aria-label": "Remove parameter",
1429
+ onClick: () => setRows((rs) => rs.filter((x) => x.key !== r.key)),
1430
+ disabled: disabledForms,
1431
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react.Trash2, { size: 14 })
1432
+ }
1433
+ )
1434
+ ] }),
1435
+ paramErrors[r.key] && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cn-err", children: paramErrors[r.key] })
1436
+ ] }, r.key))
1437
+ ] })
1438
+ ] }),
1439
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "field", children: [
1440
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: "cn-ed-query", children: "Query" }),
1441
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1442
+ "textarea",
1443
+ {
1444
+ id: "cn-ed-query",
1445
+ className: "textarea mono cn-ed-query",
1446
+ value: query,
1447
+ onChange: (e) => setQuery(e.target.value),
1448
+ rows: 5,
1449
+ placeholder: "g.V().hasLabel('Customer').has('name', $customer).limit($limit)",
1450
+ spellCheck: false,
1451
+ disabled: disabledForms
1452
+ }
1453
+ ),
1454
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cn-hint", children: "Use $name placeholders for parameters. Values are always inserted as safe typed literals, never as raw text." }),
1455
+ placeholderHint && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cn-warn", children: placeholderHint }),
1456
+ fieldErrors.query && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cn-err", children: fieldErrors.query })
1457
+ ] }),
1458
+ general.map((g, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cn-err", children: g }, i)),
1459
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cn-ed-save", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "submit", className: "btn primary", disabled: saving || !dirty, children: saving ? "Saving\u2026" : "Save" }) })
1460
+ ] })
1461
+ ] }),
1462
+ !isDraft && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(TryIt, { client, graphId, tool, builtin, dirty }, savedParamsKey),
1463
+ !builtin && !isDraft && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "cn-dfoot", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: "cn-del", onClick: onDelete, children: "Delete tool" }) })
1464
+ ] })
1465
+ ] });
1466
+ }
1467
+
1468
+ // src/graph/ConnectPane.jsx
1469
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1470
+ var NARROW_PX = 720;
1471
+ function normalizeRegistry(reg) {
1472
+ return {
1473
+ raw_enabled: !!reg?.raw_enabled,
1474
+ tools: Array.isArray(reg?.tools) ? reg.tools : []
1475
+ };
1476
+ }
1477
+ function mcpConfigJson(url) {
1478
+ return JSON.stringify({
1479
+ mcpServers: {
1480
+ graph: {
1481
+ command: "npx",
1482
+ args: ["-y", "mcp-remote", url, "--header", "Authorization: Bearer YOUR_KEY"]
1483
+ }
1484
+ }
1485
+ }, null, 2);
1486
+ }
1487
+ function truncateMiddle(s, max = 52) {
1488
+ if (!s || s.length <= max) return s;
1489
+ const head = Math.ceil((max - 1) * 0.6);
1490
+ const tail = max - 1 - head;
1491
+ return `${s.slice(0, head)}\u2026${s.slice(s.length - tail)}`;
1492
+ }
1493
+ function CopyButton({ text, label = "Copy", sm = true }) {
1494
+ const [done, setDone] = (0, import_react9.useState)(false);
1495
+ const timer = (0, import_react9.useRef)(null);
1496
+ (0, import_react9.useEffect)(() => () => window.clearTimeout(timer.current), []);
1497
+ const copy = async () => {
1498
+ try {
1499
+ await navigator.clipboard.writeText(text);
1500
+ } catch {
1501
+ const ta = document.createElement("textarea");
1502
+ ta.value = text;
1503
+ ta.style.position = "fixed";
1504
+ ta.style.opacity = "0";
1505
+ document.body.appendChild(ta);
1506
+ ta.select();
1507
+ try {
1508
+ document.execCommand("copy");
1509
+ } catch {
1510
+ }
1511
+ ta.remove();
1512
+ }
1513
+ setDone(true);
1514
+ window.clearTimeout(timer.current);
1515
+ timer.current = window.setTimeout(() => setDone(false), 1600);
1516
+ };
1517
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("button", { type: "button", className: "btn" + (sm ? " sm" : ""), onClick: copy, children: [
1518
+ done ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.Check, { size: 13 }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.Copy, { size: 13 }),
1519
+ done ? "Copied" : label
1520
+ ] });
1521
+ }
1522
+ function KeyRow({ k, onRevoke }) {
1523
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-key-row", children: [
1524
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "cn-key-name", title: k.name, children: [
1525
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.KeyRound, { size: 13, "aria-hidden": "true" }),
1526
+ k.name || "\u2014"
1527
+ ] }),
1528
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("code", { className: "mono cn-key-prefix", children: k.prefix ? `${k.prefix}\u2026` : "\u2014" }),
1529
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "cn-key-meta", children: [
1530
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "cn-key-lbl", children: "Created" }),
1531
+ " ",
1532
+ relativeTime(k.created_at) || "\u2014"
1533
+ ] }),
1534
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "cn-key-meta", children: [
1535
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "cn-key-lbl", children: "Last used" }),
1536
+ " ",
1537
+ relativeTime(k.last_used) || "\u2014"
1538
+ ] }),
1539
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "btn sm danger cn-key-revoke", onClick: onRevoke, children: "Revoke" })
1540
+ ] });
1541
+ }
1542
+ function ConnectionCard({ url, keys, expanded, onToggle, onCreateKey, onRevoke }) {
1543
+ const hasKeys = keys.length > 0;
1544
+ const config = url ? mcpConfigJson(url) : "";
1545
+ const keyCount = `${keys.length} ${keys.length === 1 ? "key" : "keys"}`;
1546
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("section", { className: "cn-conn", children: [
1547
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-conn-bar", children: [
1548
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1549
+ "button",
1550
+ {
1551
+ type: "button",
1552
+ className: "cn-conn-toggle",
1553
+ "aria-expanded": expanded,
1554
+ onClick: onToggle,
1555
+ children: [
1556
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "cn-conn-chev" + (expanded ? " open" : ""), "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.ChevronDown, { size: 15 }) }),
1557
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.Cable, { size: 14, "aria-hidden": "true" }),
1558
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("code", { className: "mono cn-conn-url", title: url || void 0, children: url ? truncateMiddle(url) : "\u2014" }),
1559
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "cn-conn-count num", children: keyCount })
1560
+ ]
1561
+ }
1562
+ ),
1563
+ url && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopyButton, { text: config, label: "Copy config" })
1564
+ ] }),
1565
+ expanded && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-conn-body", children: [
1566
+ url ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CodeBlock, { code: config, language: "json", className: "cn-code" }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "cn-hint", children: "\u2014" }),
1567
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "cn-caption", children: "Works with Claude Desktop, Claude Code, and any MCP client. Replace YOUR_KEY with an API key." }),
1568
+ hasKeys ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
1569
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-keys-h", children: [
1570
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h4", { children: "API keys" }),
1571
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("button", { type: "button", className: "btn sm", onClick: onCreateKey, children: [
1572
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.Plus, { size: 13 }),
1573
+ " Create key"
1574
+ ] })
1575
+ ] }),
1576
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "cn-keys", children: keys.map((k) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(KeyRow, { k, onRevoke: () => onRevoke(k) }, k.id)) })
1577
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-callout", children: [
1578
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.KeyRound, { size: 14, "aria-hidden": "true" }),
1579
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: "Agents need an API key to connect. Create your first key to get started." }),
1580
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "btn sm primary", onClick: onCreateKey, children: "Create key" })
1581
+ ] })
1582
+ ] })
1583
+ ] });
1584
+ }
1585
+ function CreateKeyDialog({ busy, error, onSubmit, onClose }) {
1586
+ const [name, setName] = (0, import_react9.useState)("");
1587
+ const ref = (0, import_react9.useRef)(null);
1588
+ (0, import_react9.useEffect)(() => {
1589
+ ref.current?.focus();
1590
+ }, []);
1591
+ const ok = name.trim().length > 0;
1592
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Modal, { open: true, onClose: busy ? void 0 : onClose, title: "Create API key", width: 420, classNames: { root: "cn-dlg" }, children: [
1593
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "cn-dlg-body", children: "Name the key after the agent or place that will use it, so you can tell keys apart later." }),
1594
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("form", { onSubmit: (e) => {
1595
+ e.preventDefault();
1596
+ if (ok && !busy) onSubmit(name.trim());
1597
+ }, children: [
1598
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1599
+ "input",
1600
+ {
1601
+ ref,
1602
+ className: "input",
1603
+ value: name,
1604
+ onChange: (e) => setName(e.target.value),
1605
+ placeholder: "e.g. claude-desktop",
1606
+ maxLength: 80
1607
+ }
1608
+ ),
1609
+ error && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "cn-err", children: error }),
1610
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-dlg-foot", children: [
1611
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "btn", onClick: onClose, disabled: busy, children: "Cancel" }),
1612
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "submit", className: "btn primary", disabled: !ok || busy, children: busy ? "Creating\u2026" : "Create key" })
1613
+ ] })
1614
+ ] })
1615
+ ] });
1616
+ }
1617
+ function SecretDialog({ secret, onClose }) {
1618
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Modal, { open: true, onClose, title: "Your new API key", width: 480, classNames: { root: "cn-dlg" }, children: [
1619
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "cn-dlg-body", children: "Copy this key now and store it somewhere safe. For your security, it will not be shown again." }),
1620
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "cn-secret", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("code", { className: "mono", children: secret.key }) }),
1621
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-dlg-foot", children: [
1622
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopyButton, { text: secret.key, label: "Copy key", sm: false }),
1623
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "btn primary", onClick: onClose, children: "Done" })
1624
+ ] })
1625
+ ] });
1626
+ }
1627
+ function ConfirmModal({ title, body, confirmLabel = "Delete", busy, onConfirm, onClose }) {
1628
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Modal, { open: true, onClose: busy ? void 0 : onClose, title, width: 420, classNames: { root: "cn-dlg" }, children: [
1629
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "cn-dlg-body", children: body }),
1630
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-dlg-foot", children: [
1631
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "btn", onClick: onClose, disabled: busy, children: "Cancel" }),
1632
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "btn danger", onClick: onConfirm, disabled: busy, children: busy ? `${confirmLabel}\u2026` : confirmLabel })
1633
+ ] })
1634
+ ] });
1635
+ }
1636
+ function ToolListRow({ name, builtin, enabled, selected, busy, onSelect, onToggle }) {
1637
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1638
+ "div",
1639
+ {
1640
+ role: "option",
1641
+ "aria-selected": selected,
1642
+ tabIndex: 0,
1643
+ className: "cn-lrow" + (selected ? " sel" : "") + (enabled ? "" : " off"),
1644
+ onClick: onSelect,
1645
+ onKeyDown: (e) => {
1646
+ if (e.key === "Enter" || e.key === " ") {
1647
+ e.preventDefault();
1648
+ onSelect();
1649
+ }
1650
+ },
1651
+ children: [
1652
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("code", { className: "mono cn-lrow-name", title: name, children: name }),
1653
+ builtin && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "pill brand", children: "Built in" }),
1654
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1655
+ "span",
1656
+ {
1657
+ className: "cn-lrow-toggle",
1658
+ onClick: (e) => e.stopPropagation(),
1659
+ onKeyDown: (e) => e.stopPropagation(),
1660
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Switch, { checked: !!enabled, disabled: busy, onChange: onToggle, label: `Enable ${name}` })
1661
+ }
1662
+ )
1663
+ ]
1664
+ }
1665
+ );
1666
+ }
1667
+ function ToolList({ registry, sel, busy, onSelect, onToggleRaw, onToggleTool, onNew }) {
1668
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-list", children: [
1669
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "cn-list-h", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("button", { type: "button", className: "btn sm primary cn-new-tool", onClick: onNew, children: [
1670
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.Plus, { size: 13 }),
1671
+ " New tool"
1672
+ ] }) }),
1673
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-list-scroll scroll", role: "listbox", "aria-label": "Tools", children: [
1674
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1675
+ ToolListRow,
1676
+ {
1677
+ name: RUN_QUERY_TOOL,
1678
+ builtin: true,
1679
+ enabled: registry.raw_enabled,
1680
+ selected: sel.type === "builtin",
1681
+ busy,
1682
+ onSelect: () => onSelect({ type: "builtin" }),
1683
+ onToggle: onToggleRaw
1684
+ }
1685
+ ),
1686
+ registry.tools.map((t) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1687
+ ToolListRow,
1688
+ {
1689
+ name: t.name,
1690
+ enabled: !!t.enabled,
1691
+ selected: sel.type === "tool" && sel.name === t.name,
1692
+ busy,
1693
+ onSelect: () => onSelect({ type: "tool", name: t.name }),
1694
+ onToggle: (v) => onToggleTool(t.name, v)
1695
+ },
1696
+ t.name
1697
+ )),
1698
+ sel.type === "draft" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { role: "option", "aria-selected": "true", className: "cn-lrow sel cn-lrow-draft", tabIndex: 0, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "cn-lrow-name", children: "New tool" }) }),
1699
+ registry.tools.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "cn-list-empty", children: "A tool is a named, parameterized query agents can call safely. Define one here, or ask your copilot to create it for you." })
1700
+ ] })
1701
+ ] });
1702
+ }
1703
+ function ConnectSkeleton() {
1704
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-skel", "aria-busy": "true", "aria-label": "Loading Connect", children: [
1705
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Skeleton, { w: "100%", h: 38, radius: 9 }),
1706
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-skel-split", children: [
1707
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-skel-col", children: [
1708
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Skeleton, { w: "100%", h: 30, radius: 9, style: { marginBottom: 8 } }),
1709
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Skeleton, { w: "100%", h: 30, radius: 9, style: { marginBottom: 8 } }),
1710
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Skeleton, { w: "100%", h: 30, radius: 9 })
1711
+ ] }),
1712
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-skel-col", children: [
1713
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Skeleton, { w: "42%", h: 16, style: { marginBottom: 12 } }),
1714
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Skeleton, { w: "100%", h: 90, radius: 9, style: { marginBottom: 10 } }),
1715
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Skeleton, { w: "100%", h: 90, radius: 9 })
1716
+ ] })
1717
+ ] })
1718
+ ] });
1719
+ }
1720
+ function ConnectPane({ graphId, liveRegistry, client }) {
1721
+ const [registry, setRegistry] = (0, import_react9.useState)(null);
1722
+ const [keys, setKeys] = (0, import_react9.useState)(null);
1723
+ const [loading, setLoading] = (0, import_react9.useState)(true);
1724
+ const [error, setError] = (0, import_react9.useState)("");
1725
+ const [saveError, setSaveError] = (0, import_react9.useState)("");
1726
+ const [busy, setBusy] = (0, import_react9.useState)(false);
1727
+ const [sel, setSel] = (0, import_react9.useState)({ type: "builtin" });
1728
+ const [showDetail, setShowDetail] = (0, import_react9.useState)(false);
1729
+ const [narrow, setNarrow] = (0, import_react9.useState)(false);
1730
+ const dirtyRef = (0, import_react9.useRef)({ dirty: false, label: "" });
1731
+ const [cardExpanded, setCardExpanded] = (0, import_react9.useState)(false);
1732
+ const cardInitRef = (0, import_react9.useRef)(false);
1733
+ const [confirm, setConfirm] = (0, import_react9.useState)(null);
1734
+ const [confirmBusy, setConfirmBusy] = (0, import_react9.useState)(false);
1735
+ const [confirmError, setConfirmError] = (0, import_react9.useState)("");
1736
+ const [creatingKey, setCreatingKey] = (0, import_react9.useState)(false);
1737
+ const [createBusy, setCreateBusy] = (0, import_react9.useState)(false);
1738
+ const [createError, setCreateError] = (0, import_react9.useState)("");
1739
+ const [secret, setSecret] = (0, import_react9.useState)(null);
1740
+ const [endpoint, setEndpoint] = (0, import_react9.useState)("");
1741
+ const registryRef = (0, import_react9.useRef)(null);
1742
+ registryRef.current = registry;
1743
+ const paneRef = (0, import_react9.useRef)(null);
1744
+ const load = (0, import_react9.useCallback)(async () => {
1745
+ try {
1746
+ const [reg, ks] = await Promise.all([client.getConnect(graphId), client.listConnectKeys(graphId)]);
1747
+ if (reg && typeof reg.endpoint === "string") setEndpoint(reg.endpoint);
1748
+ setRegistry(normalizeRegistry(reg));
1749
+ setKeys(ks);
1750
+ if (!cardInitRef.current) {
1751
+ cardInitRef.current = true;
1752
+ setCardExpanded((ks || []).length === 0);
1753
+ }
1754
+ setError("");
1755
+ } catch (e) {
1756
+ setError(e?.message || "Could not load Connect settings.");
1757
+ } finally {
1758
+ setLoading(false);
1759
+ }
1760
+ }, [graphId, client]);
1761
+ (0, import_react9.useEffect)(() => {
1762
+ load();
1763
+ }, [load]);
1764
+ (0, import_react9.useEffect)(() => {
1765
+ const onVis = () => {
1766
+ if (document.visibilityState !== "hidden") load();
1767
+ };
1768
+ window.addEventListener("focus", onVis);
1769
+ document.addEventListener("visibilitychange", onVis);
1770
+ return () => {
1771
+ window.removeEventListener("focus", onVis);
1772
+ document.removeEventListener("visibilitychange", onVis);
1773
+ };
1774
+ }, [load]);
1775
+ (0, import_react9.useEffect)(() => {
1776
+ if (liveRegistry && (Array.isArray(liveRegistry.tools) || "raw_enabled" in liveRegistry)) {
1777
+ setRegistry(normalizeRegistry(liveRegistry));
1778
+ }
1779
+ }, [liveRegistry]);
1780
+ (0, import_react9.useEffect)(() => {
1781
+ const el = paneRef.current;
1782
+ if (!el || typeof ResizeObserver === "undefined") return void 0;
1783
+ const ro = new ResizeObserver((entries) => {
1784
+ const w = entries[0]?.contentRect?.width;
1785
+ if (typeof w === "number") setNarrow(w < NARROW_PX);
1786
+ });
1787
+ ro.observe(el);
1788
+ return () => ro.disconnect();
1789
+ }, []);
1790
+ (0, import_react9.useEffect)(() => {
1791
+ if (!registry || sel.type !== "tool") return;
1792
+ if (!registry.tools.some((t) => t.name === sel.name) && !dirtyRef.current.dirty) {
1793
+ setSel({ type: "builtin" });
1794
+ }
1795
+ }, [registry, sel]);
1796
+ const saveRegistry = (0, import_react9.useCallback)(async (next) => {
1797
+ const prev = registryRef.current;
1798
+ setRegistry(next);
1799
+ setSaveError("");
1800
+ setBusy(true);
1801
+ try {
1802
+ const saved = await client.putConnect(graphId, next);
1803
+ if (saved && (Array.isArray(saved.tools) || "raw_enabled" in saved)) {
1804
+ setRegistry(normalizeRegistry(saved));
1805
+ }
1806
+ return true;
1807
+ } catch (e) {
1808
+ setRegistry(prev);
1809
+ setSaveError(e?.message || "Could not save your change.");
1810
+ return false;
1811
+ } finally {
1812
+ setBusy(false);
1813
+ }
1814
+ }, [graphId, client]);
1815
+ const toggleRaw = (v) => saveRegistry({ ...registryRef.current, raw_enabled: v });
1816
+ const toggleTool = (name, v) => saveRegistry({
1817
+ ...registryRef.current,
1818
+ tools: registryRef.current.tools.map((t) => t.name === name ? { ...t, enabled: v } : t)
1819
+ });
1820
+ const saveTool = (0, import_react9.useCallback)(async (def, prevName) => {
1821
+ const cur = registryRef.current;
1822
+ const rest = cur.tools.filter((t) => t.name !== prevName && t.name !== def.name);
1823
+ const kept = cur.tools.find((t) => t.name === prevName);
1824
+ const idx = cur.tools.findIndex((t) => t.name === prevName);
1825
+ const tools = [...rest];
1826
+ tools.splice(idx >= 0 ? idx : tools.length, 0, { ...kept, ...def });
1827
+ const saved = await client.putConnect(graphId, { ...cur, tools });
1828
+ setRegistry(saved && (Array.isArray(saved.tools) || "raw_enabled" in saved) ? normalizeRegistry(saved) : { ...cur, tools });
1829
+ setSaveError("");
1830
+ setSel({ type: "tool", name: def.name });
1831
+ }, [graphId, client]);
1832
+ const sameSel = (a, b) => a.type === b.type && (a.type !== "tool" || a.name === b.name) && (a.type !== "draft" || a.nonce === b.nonce);
1833
+ const applySelect = (0, import_react9.useCallback)((next) => {
1834
+ setSel(next);
1835
+ setShowDetail(true);
1836
+ }, []);
1837
+ const requestSelect = (0, import_react9.useCallback)((next) => {
1838
+ if (sameSel(next, sel)) {
1839
+ setShowDetail(true);
1840
+ return;
1841
+ }
1842
+ if (dirtyRef.current.dirty) {
1843
+ setConfirmError("");
1844
+ setConfirm({ kind: "discard", next, label: dirtyRef.current.label });
1845
+ return;
1846
+ }
1847
+ applySelect(next);
1848
+ }, [sel, applySelect]);
1849
+ const onDirtyChange = (0, import_react9.useCallback)((dirty, label) => {
1850
+ dirtyRef.current = { dirty, label };
1851
+ }, []);
1852
+ const doConfirm = async () => {
1853
+ if (!confirm) return;
1854
+ if (confirm.kind === "discard") {
1855
+ applySelect(confirm.next);
1856
+ setConfirm(null);
1857
+ return;
1858
+ }
1859
+ setConfirmBusy(true);
1860
+ setConfirmError("");
1861
+ try {
1862
+ if (confirm.kind === "revoke") {
1863
+ await client.revokeConnectKey(graphId, confirm.key.id);
1864
+ setKeys(await client.listConnectKeys(graphId));
1865
+ } else {
1866
+ const cur = registryRef.current;
1867
+ const ok = await saveRegistry({ ...cur, tools: cur.tools.filter((t) => t.name !== confirm.tool.name) });
1868
+ if (!ok) throw new Error("Could not delete this tool. Please try again.");
1869
+ if (sel.type === "tool" && sel.name === confirm.tool.name) {
1870
+ setSel({ type: "builtin" });
1871
+ setShowDetail(false);
1872
+ }
1873
+ }
1874
+ setConfirm(null);
1875
+ } catch (e) {
1876
+ setConfirmError(e?.message || "Something went wrong. Please try again.");
1877
+ } finally {
1878
+ setConfirmBusy(false);
1879
+ }
1880
+ };
1881
+ const doCreateKey = async (name) => {
1882
+ setCreateBusy(true);
1883
+ setCreateError("");
1884
+ try {
1885
+ const minted = await client.createConnectKey(graphId, name);
1886
+ setCreatingKey(false);
1887
+ setSecret(minted);
1888
+ setKeys(await client.listConnectKeys(graphId));
1889
+ } catch (e) {
1890
+ setCreateError(e?.message || "Could not create the key. Please try again.");
1891
+ } finally {
1892
+ setCreateBusy(false);
1893
+ }
1894
+ };
1895
+ const url = endpoint ? client.endpointUrl(endpoint) : "";
1896
+ const selTool = sel.type === "tool" ? (registry?.tools || []).find((t) => t.name === sel.name) || null : null;
1897
+ const detailKey = sel.type === "draft" ? `draft:${sel.nonce}` : sel.type === "builtin" ? "builtin" : `tool:${sel.name}`;
1898
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "gp-placeholder cn-root", children: [
1899
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "pane", style: { flex: 1 }, ref: paneRef, children: loading ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ConnectSkeleton, {}) : error ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "pane-empty", children: [
1900
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.Cable, { size: 28 }),
1901
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "big", children: "Could not load Connect" }),
1902
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { children: error }),
1903
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "btn sm", onClick: () => {
1904
+ setLoading(true);
1905
+ load();
1906
+ }, children: "Try again" })
1907
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-body scroll", children: [
1908
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1909
+ ConnectionCard,
1910
+ {
1911
+ url,
1912
+ keys: keys || [],
1913
+ expanded: cardExpanded,
1914
+ onToggle: () => setCardExpanded((v) => !v),
1915
+ onCreateKey: () => {
1916
+ setCreateError("");
1917
+ setCreatingKey(true);
1918
+ },
1919
+ onRevoke: (k) => {
1920
+ setConfirmError("");
1921
+ setConfirm({ kind: "revoke", key: k });
1922
+ }
1923
+ }
1924
+ ),
1925
+ saveError && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "cn-err cn-err-top", children: saveError }),
1926
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "cn-split" + (narrow ? " narrow" : "") + (narrow && showDetail ? " show-detail" : ""), children: [
1927
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1928
+ ToolList,
1929
+ {
1930
+ registry,
1931
+ sel,
1932
+ busy,
1933
+ onSelect: requestSelect,
1934
+ onToggleRaw: toggleRaw,
1935
+ onToggleTool: toggleTool,
1936
+ onNew: () => requestSelect({ type: "draft", nonce: Date.now() })
1937
+ }
1938
+ ),
1939
+ sel.type === "builtin" || sel.type === "draft" || selTool || dirtyRef.current.dirty ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1940
+ ConnectToolDetail,
1941
+ {
1942
+ client,
1943
+ graphId,
1944
+ tool: selTool,
1945
+ builtin: sel.type === "builtin",
1946
+ isDraft: sel.type === "draft",
1947
+ enabled: sel.type === "builtin" ? registry.raw_enabled : !!selTool?.enabled,
1948
+ busy,
1949
+ takenNames: /* @__PURE__ */ new Set([RUN_QUERY_TOOL, ...(registry?.tools || []).map((t) => t.name)]),
1950
+ narrow,
1951
+ onBack: () => setShowDetail(false),
1952
+ onToggle: sel.type === "builtin" ? toggleRaw : (v) => toggleTool(sel.name, v),
1953
+ onSave: saveTool,
1954
+ onDelete: () => {
1955
+ setConfirmError("");
1956
+ setConfirm({ kind: "delete", tool: selTool });
1957
+ },
1958
+ onDirtyChange
1959
+ },
1960
+ detailKey
1961
+ ) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "cn-detail", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "pane-empty", children: "Select a tool to edit and test it." }) })
1962
+ ] })
1963
+ ] }) }),
1964
+ confirm && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1965
+ ConfirmModal,
1966
+ {
1967
+ title: confirm.kind === "revoke" ? `Revoke "${confirm.key.name}"?` : confirm.kind === "delete" ? `Delete "${confirm.tool.name}"?` : `Discard unsaved changes to "${confirm.label}"?`,
1968
+ body: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
1969
+ confirm.kind === "revoke" ? "Agents using this key will lose access immediately. This cannot be undone." : confirm.kind === "delete" ? "Agents will no longer be able to call this tool. This cannot be undone." : "Your edits have not been saved and will be lost.",
1970
+ confirmError && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "cn-err", children: confirmError })
1971
+ ] }),
1972
+ confirmLabel: confirm.kind === "revoke" ? "Revoke" : confirm.kind === "delete" ? "Delete" : "Discard",
1973
+ busy: confirmBusy,
1974
+ onConfirm: doConfirm,
1975
+ onClose: () => setConfirm(null)
1976
+ }
1977
+ ),
1978
+ creatingKey && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1979
+ CreateKeyDialog,
1980
+ {
1981
+ busy: createBusy,
1982
+ error: createError,
1983
+ onSubmit: doCreateKey,
1984
+ onClose: () => setCreatingKey(false)
1985
+ }
1986
+ ),
1987
+ secret && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SecretDialog, { secret, onClose: () => setSecret(null) })
1988
+ ] });
1989
+ }
1990
+
1991
+ // src/graph/LogsPane.jsx
1992
+ var import_react10 = require("react");
1993
+ var import_lucide_react3 = require("lucide-react");
1994
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1995
+ var PAGE = 25;
1996
+ var OP_LABEL = {
1997
+ get_schema: "Read design",
1998
+ add_vertex_type: "Add node type",
1999
+ add_node_type: "Add node type",
2000
+ update_node_type: "Update node type",
2001
+ delete_vertex_type: "Delete node type",
2002
+ delete_node_type: "Delete node type",
2003
+ add_edge_type: "Add relationship",
2004
+ add_relationship_type: "Add relationship",
2005
+ update_relationship_type: "Update relationship",
2006
+ delete_edge_type: "Delete relationship",
2007
+ delete_relationship_type: "Delete relationship",
2008
+ add_property: "Add field",
2009
+ add_field: "Add field",
2010
+ update_field: "Update field",
2011
+ rename_property: "Rename field",
2012
+ rename_field: "Rename field",
2013
+ delete_property: "Delete field",
2014
+ delete_field: "Delete field",
2015
+ add_semantic_index: "Add search index",
2016
+ add_search_index: "Add search index",
2017
+ delete_search_index: "Delete search index",
2018
+ add_connection: "Add connection",
2019
+ delete_connection: "Delete connection",
2020
+ update_ui: "Update style",
2021
+ update_style: "Update style",
2022
+ batch_schema: "Schema changes",
2023
+ schema_batch: "Schema changes",
2024
+ schema_change: "Schema change",
2025
+ get_schema_job: "Check change",
2026
+ save_design: "Save design",
2027
+ query: "Query",
2028
+ semantic_search: "Search",
2029
+ upsert_vertex: "Save record",
2030
+ add_record: "Add record",
2031
+ delete_vertex: "Delete record",
2032
+ upsert_edge: "Link records",
2033
+ link_records: "Link records",
2034
+ delete_edge: "Unlink records",
2035
+ edit_records: "Edit records",
2036
+ copilot_turn: "Chat",
2037
+ create_graph: "Create graph",
2038
+ rename_graph: "Rename graph",
2039
+ delete_graph: "Delete graph",
2040
+ update_thumbnail: "Preview image",
2041
+ // Connect: tool registry, API keys, external agent calls
2042
+ connect_list_tools: "Read tools",
2043
+ connect_save_tool: "Save tool",
2044
+ connect_delete_tool: "Delete tool",
2045
+ connect_set_enabled: "Toggle tool",
2046
+ connect_test_tool: "Test tool",
2047
+ connect_list_keys: "Read API keys",
2048
+ create_key: "Create API key",
2049
+ create_api_key: "Create API key",
2050
+ delete_key: "Revoke API key",
2051
+ delete_api_key: "Revoke API key",
2052
+ revoke_key: "Revoke API key",
2053
+ external_call: "Agent call",
2054
+ mcp_call: "Agent call",
2055
+ tool_call: "Agent call"
2056
+ };
2057
+ var opLabel = (op) => OP_LABEL[op] || String(op || "").replace(/_/g, " ").replace(/^./, (c) => c.toUpperCase());
2058
+ var OP_KIND = {
2059
+ connect_save_tool: "add",
2060
+ connect_delete_tool: "del",
2061
+ connect_set_enabled: "edit",
2062
+ connect_test_tool: "read",
2063
+ connect_list_tools: "read",
2064
+ connect_list_keys: "read",
2065
+ external_call: "ext",
2066
+ mcp_call: "ext",
2067
+ tool_call: "ext"
2068
+ };
2069
+ function opKind(op = "", status = "") {
2070
+ if (status === "error") return "err";
2071
+ if (OP_KIND[op]) return OP_KIND[op];
2072
+ if (op === "copilot_turn") return "chat";
2073
+ if (/^(delete|drop|unlink)/.test(op)) return "del";
2074
+ if (/^(add|create|link|upsert|save)/.test(op)) return "add";
2075
+ if (/^(query|semantic_search|get|read|check)/.test(op)) return "read";
2076
+ return "edit";
2077
+ }
2078
+ var fmtDur = (ms) => {
2079
+ if (ms == null) return "";
2080
+ const n = Number(ms);
2081
+ if (!isFinite(n)) return "";
2082
+ if (n < 1e3) return `${Math.round(n)}ms`;
2083
+ if (n < 6e4) return `${(n / 1e3).toFixed(1)}s`;
2084
+ return `${Math.floor(n / 6e4)}m ${Math.round(n % 6e4 / 1e3)}s`;
2085
+ };
2086
+ function ActorChip({ actor, copilotMark: copilotMark2 }) {
2087
+ const copilot = actor?.kind === "copilot";
2088
+ if (actor?.kind === "api_key" || actor?.type === "api_key") {
2089
+ const keyName = actor.name || "API key";
2090
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "lg-actor lg-actor-key", title: `API key: ${keyName}`, children: [
2091
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_lucide_react3.KeyRound, { size: 11, "aria-hidden": "true" }),
2092
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "lg-actor-name", children: keyName })
2093
+ ] });
2094
+ }
2095
+ const name = copilot ? "Copilot" : actor?.name || "Someone";
2096
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "lg-actor", title: name, children: [
2097
+ copilot ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "lg-actor-mark", children: copilotMark2 ?? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_lucide_react3.Bot, { size: 14 }) }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "lg-actor-av", children: (name[0] || "?").toUpperCase() }),
2098
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "lg-actor-name", children: name })
2099
+ ] });
2100
+ }
2101
+ function DetailBlock({ entry }) {
2102
+ const when = entry.ts ? new Date(entry.ts).toLocaleString() : "";
2103
+ const hasArgs = entry.args != null && !(typeof entry.args === "object" && Object.keys(entry.args).length === 0);
2104
+ let argsText = "";
2105
+ if (hasArgs) {
2106
+ try {
2107
+ argsText = JSON.stringify(entry.args, null, 2);
2108
+ } catch {
2109
+ argsText = String(entry.args);
2110
+ }
2111
+ }
2112
+ const units = fmtUnits(entry.consumption);
2113
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "lg-detail", children: [
2114
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "lg-detail-meta mono", children: [
2115
+ when,
2116
+ entry.duration_ms != null && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
2117
+ " \xB7 ",
2118
+ fmtDur(entry.duration_ms)
2119
+ ] }),
2120
+ units && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
2121
+ " \xB7 ",
2122
+ units
2123
+ ] })
2124
+ ] }),
2125
+ entry.error && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "lg-detail-err", children: entry.error }),
2126
+ hasArgs ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CodeBlock, { code: argsText, language: "json", className: "lg-json" }) : !entry.error && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "lg-detail-none", children: "No further detail for this action." })
2127
+ ] });
2128
+ }
2129
+ function Row({ entry, open, onToggle }) {
2130
+ const kind = opKind(entry.op, entry.status);
2131
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "lg-row-wrap" + (open ? " open" : ""), children: [
2132
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("button", { type: "button", className: "lg-row", onClick: onToggle, "aria-expanded": open, children: [
2133
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "lg-caret", children: open ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_lucide_react3.ChevronDown, { size: 14 }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_lucide_react3.ChevronRight, { size: 14 }) }),
2134
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: `lg-dot lg-${entry.status === "error" ? "error" : "ok"}`, "aria-hidden": "true" }),
2135
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: `lg-badge lg-k-${kind}`, children: opLabel(entry.op) }),
2136
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "lg-sum", children: entry.summary || opLabel(entry.op) }),
2137
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "lg-side", children: [
2138
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ActorChip, { actor: entry.actor, copilotMark }),
2139
+ entry.duration_ms != null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "lg-dur mono", children: fmtDur(entry.duration_ms) }),
2140
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "lg-ago mono", children: relativeTime(Date.parse(entry.ts)) || "" })
2141
+ ] })
2142
+ ] }),
2143
+ open && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(DetailBlock, { entry })
2144
+ ] });
2145
+ }
2146
+ function LogsSkeleton() {
2147
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "lg-list", "aria-busy": "true", "aria-label": "Loading activity", children: Array.from({ length: 8 }).map((_, i) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "lg-skel-row", children: [
2148
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Skeleton, { w: 8, h: 8, radius: 999 }),
2149
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Skeleton, { w: 86, h: 18, radius: 999 }),
2150
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Skeleton, { w: `${34 + i * 13 % 40}%`, h: 12 }),
2151
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "lg-skel-right", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Skeleton, { w: 90, h: 12 }) })
2152
+ ] }, i)) });
2153
+ }
2154
+ function LogsPane({ graphId, client, copilotMark: copilotMark2 }) {
2155
+ const [entries, setEntries] = (0, import_react10.useState)([]);
2156
+ const [nextCursor, setNextCursor] = (0, import_react10.useState)(null);
2157
+ const [loading, setLoading] = (0, import_react10.useState)(true);
2158
+ const [loadingMore, setLoadingMore] = (0, import_react10.useState)(false);
2159
+ const [error, setError] = (0, import_react10.useState)("");
2160
+ const [qInput, setQInput] = (0, import_react10.useState)("");
2161
+ const [q, setQ] = (0, import_react10.useState)("");
2162
+ const [open, setOpen] = (0, import_react10.useState)(() => /* @__PURE__ */ new Set());
2163
+ const genRef = (0, import_react10.useRef)(0);
2164
+ (0, import_react10.useEffect)(() => {
2165
+ const t = setTimeout(() => setQ(qInput.trim()), 300);
2166
+ return () => clearTimeout(t);
2167
+ }, [qInput]);
2168
+ const loadFirst = (0, import_react10.useCallback)(async () => {
2169
+ const gen = ++genRef.current;
2170
+ setLoading(true);
2171
+ setError("");
2172
+ try {
2173
+ const body = await client.fetchAudit(graphId, { limit: PAGE, q });
2174
+ if (genRef.current !== gen) return;
2175
+ setEntries(body.entries || []);
2176
+ setNextCursor(body.next_cursor || null);
2177
+ setOpen(/* @__PURE__ */ new Set());
2178
+ } catch (e) {
2179
+ if (genRef.current !== gen) return;
2180
+ console.warn("Activity load failed:", e);
2181
+ setEntries([]);
2182
+ setNextCursor(null);
2183
+ setError(true);
2184
+ } finally {
2185
+ if (genRef.current === gen) setLoading(false);
2186
+ }
2187
+ }, [graphId, q, client]);
2188
+ (0, import_react10.useEffect)(() => {
2189
+ loadFirst();
2190
+ }, [loadFirst]);
2191
+ const loadMore = (0, import_react10.useCallback)(async () => {
2192
+ if (!nextCursor || loadingMore) return;
2193
+ const gen = genRef.current;
2194
+ setLoadingMore(true);
2195
+ try {
2196
+ const body = await client.fetchAudit(graphId, { limit: PAGE, cursor: nextCursor, q });
2197
+ if (genRef.current !== gen) return;
2198
+ setEntries((prev) => [...prev, ...body.entries || []]);
2199
+ setNextCursor(body.next_cursor || null);
2200
+ } catch (e) {
2201
+ if (genRef.current === gen) console.warn("Activity load-more failed:", e);
2202
+ } finally {
2203
+ if (genRef.current === gen) setLoadingMore(false);
2204
+ }
2205
+ }, [graphId, nextCursor, loadingMore, q, client]);
2206
+ const toggle = (id) => setOpen((prev) => {
2207
+ const next = new Set(prev);
2208
+ if (next.has(id)) next.delete(id);
2209
+ else next.add(id);
2210
+ return next;
2211
+ });
2212
+ const empty = !loading && !error && entries.length === 0;
2213
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "gp-placeholder lg-root", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "pane", style: { flex: 1 }, children: [
2214
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "lg-head", children: [
2215
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "lg-title", children: "Logs" }),
2216
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "lg-search", children: [
2217
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_lucide_react3.Search, { size: 14, "aria-hidden": "true" }),
2218
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2219
+ "input",
2220
+ {
2221
+ value: qInput,
2222
+ onChange: (e) => setQInput(e.target.value),
2223
+ placeholder: "Search activity",
2224
+ "aria-label": "Search activity"
2225
+ }
2226
+ ),
2227
+ qInput && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "button", className: "lg-search-x", onClick: () => setQInput(""), "aria-label": "Clear search", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_lucide_react3.X, { size: 13 }) })
2228
+ ] })
2229
+ ] }),
2230
+ loading ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(LogsSkeleton, {}) : error ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "pane-empty", children: [
2231
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "big", children: "Could not load activity" }),
2232
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { children: "Please try again." }),
2233
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "button", className: "btn sm", onClick: loadFirst, children: "Try again" })
2234
+ ] }) : empty ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "pane-empty", children: [
2235
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_lucide_react3.ScrollText, { size: 28 }),
2236
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "big", children: q ? "No matching activity" : "No activity yet" }),
2237
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { style: { maxWidth: 420 }, children: q ? "Nothing in this graph\u2019s history matches your search." : "Actions on this graph will appear here." })
2238
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "lg-list scroll", children: [
2239
+ entries.map((e) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Row, { entry: e, open: open.has(e.id), onToggle: () => toggle(e.id) }, e.id)),
2240
+ nextCursor && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "lg-more", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "button", className: "btn sm", onClick: loadMore, disabled: loadingMore, children: loadingMore ? "Loading\u2026" : "Load more" }) })
2241
+ ] }) })
2242
+ ] }) });
2243
+ }
2244
+ //# sourceMappingURL=graph.cjs.map