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