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
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
// Realtime collaboration for a graph canvas: one Yjs doc per graph
|
|
2
|
+
// ("cg-schema:{kb}") on the platform collab sidecar, reached with a
|
|
3
|
+
// short-lived per-doc ticket the HOST fetches (the ContextualGraph app and
|
|
4
|
+
// the studio's Spaces authenticate differently, so the ticket fetch is
|
|
5
|
+
// injected, the way the sheet hook takes it). Built on the shared
|
|
6
|
+
// live-document core; a person's color is the shared palette's.
|
|
7
|
+
//
|
|
8
|
+
// The doc has two shared structures:
|
|
9
|
+
// meta (server-written) — schema: the full graph JSON pushed after every
|
|
10
|
+
// mutation (copilot tools, inspector edits, saves), version, actor,
|
|
11
|
+
// copilot {building, at}, explorer, connect. Clients render
|
|
12
|
+
// meta.schema directly, so a copilot build animates on every open
|
|
13
|
+
// canvas without polling.
|
|
14
|
+
// draft (client-written) — the SHARED edit-mode draft. Keys mirror the
|
|
15
|
+
// graph view's local draft shapes: "t:vertex:User" -> type draft,
|
|
16
|
+
// "p:User" -> {x,y}. Values are plain JSON; per-key last-writer-wins,
|
|
17
|
+
// so two editors converge (edits to different types always merge).
|
|
18
|
+
//
|
|
19
|
+
// Presence rides Yjs awareness: every client publishes
|
|
20
|
+
// {id, name, mode: viewing|editing, drag}; the copilot appears via meta.copilot.
|
|
21
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
22
|
+
import { useLiveDoc } from '../collab/useLiveDoc.js';
|
|
23
|
+
import { peerColor } from '../collab/colors.js';
|
|
24
|
+
|
|
25
|
+
const T_PREFIX = 't:';
|
|
26
|
+
const P_PREFIX = 'p:';
|
|
27
|
+
const COPILOT_STALE_MS = 15 * 60 * 1000; // ignore a building flag this old
|
|
28
|
+
|
|
29
|
+
function readDrafts(map) {
|
|
30
|
+
const typeDrafts = {};
|
|
31
|
+
const positionDrafts = {};
|
|
32
|
+
map.forEach((v, k) => {
|
|
33
|
+
if (k.startsWith(T_PREFIX)) typeDrafts[k.slice(T_PREFIX.length)] = v;
|
|
34
|
+
else if (k.startsWith(P_PREFIX)) positionDrafts[k.slice(P_PREFIX.length)] = v;
|
|
35
|
+
});
|
|
36
|
+
return { typeDrafts, positionDrafts };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function readPeers(states, selfClientId) {
|
|
40
|
+
const byId = new Map();
|
|
41
|
+
for (const st of states || []) {
|
|
42
|
+
const clientId = st.clientId;
|
|
43
|
+
const u = st.user;
|
|
44
|
+
if (!u || !u.id) continue;
|
|
45
|
+
const cur = byId.get(u.id);
|
|
46
|
+
// Prefer the editing entry when one person has several tabs open; a live
|
|
47
|
+
// drag (u.drag = {label, x, y}) wins over everything (it implies action).
|
|
48
|
+
if (!cur || (u.drag && !cur.drag) || (u.mode === 'editing' && cur.mode !== 'editing' && !cur.drag)) {
|
|
49
|
+
byId.set(u.id, { id: u.id, name: u.name || 'User', mode: u.mode || 'viewing',
|
|
50
|
+
drag: u.drag || null, self: clientId === selfClientId });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return [...byId.values()].sort((a, b) => (a.self === b.self ? a.name.localeCompare(b.name) : a.self ? -1 : 1));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Strictly-newer check for published schema stamps — (schema_version,
|
|
57
|
+
* capture ts) lexicographic; mirrors the sidecar's write guard so a late
|
|
58
|
+
* stale push can never revert a client's canvas. */
|
|
59
|
+
function newerStamp(last, sv, ts) {
|
|
60
|
+
return sv > last.sv || (sv === last.sv && ts > last.ts);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Live channel for one graph. Returns:
|
|
65
|
+
* ready — connected to the doc (false = fall back to refresh-based UX)
|
|
66
|
+
* liveGraph — the latest server-published schema JSON (null until one arrives)
|
|
67
|
+
* peers — [{id, name, mode, self}] awareness roster
|
|
68
|
+
* copilotBuilding— the copilot is running a turn right now
|
|
69
|
+
* draftStore — shared edit draft: {typeDrafts, positionDrafts, setTypeDrafts,
|
|
70
|
+
* setPositionDrafts} (drop-in for the graph view's local state)
|
|
71
|
+
* setEditing — publish viewing/editing presence mode
|
|
72
|
+
*/
|
|
73
|
+
export function useGraphCollab(graphId, user, { fetchTicket } = {}) {
|
|
74
|
+
const live = useLiveDoc(graphId, { fetchTicket, field: 'user' });
|
|
75
|
+
const ready = live.ready;
|
|
76
|
+
const [liveGraph, setLiveGraph] = useState(null);
|
|
77
|
+
const [copilotBuilding, setCopilotBuilding] = useState(false);
|
|
78
|
+
const [explorer, setExplorer] = useState(null); // {query, note, requested_by, version}
|
|
79
|
+
const [connect, setConnect] = useState(null); // latest published Connect tool registry
|
|
80
|
+
const [drafts, setDrafts] = useState({ typeDrafts: {}, positionDrafts: {} });
|
|
81
|
+
const providerRef = useRef(null);
|
|
82
|
+
providerRef.current = live.provider;
|
|
83
|
+
const draftsRef = useRef(drafts);
|
|
84
|
+
const modeRef = useRef('viewing');
|
|
85
|
+
const dragRef = useRef(null);
|
|
86
|
+
const stampRef = useRef({ sv: -1, ts: -1 }); // last APPLIED schema stamp
|
|
87
|
+
// Explorer channel stamp. null = unbaselined: the FIRST observed value (the
|
|
88
|
+
// doc's history on connect) only sets the baseline — a query the copilot ran
|
|
89
|
+
// before this window opened must not replay on load. Only strictly-newer
|
|
90
|
+
// pushes that arrive while connected reach the consumer.
|
|
91
|
+
const explorerStampRef = useRef(null);
|
|
92
|
+
// Connect registry channel is STATE, not an event stream: the latest
|
|
93
|
+
// observed value is simply the truth, so the doc's history on connect
|
|
94
|
+
// applies too (the Connect pane reconciles it with its own REST fetch).
|
|
95
|
+
// Dedup on serialized value to keep renders quiet across meta churn.
|
|
96
|
+
const connectJsonRef = useRef('');
|
|
97
|
+
const userRef = useRef(user);
|
|
98
|
+
userRef.current = user;
|
|
99
|
+
|
|
100
|
+
// What this canvas reads from the document, attached once the core has
|
|
101
|
+
// synced it and detached when the graph changes.
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
const ydoc = live.doc;
|
|
104
|
+
if (!ydoc) {
|
|
105
|
+
setLiveGraph(null); setCopilotBuilding(false); setExplorer(null); setConnect(null);
|
|
106
|
+
stampRef.current = { sv: -1, ts: -1 };
|
|
107
|
+
explorerStampRef.current = null;
|
|
108
|
+
connectJsonRef.current = '';
|
|
109
|
+
draftsRef.current = { typeDrafts: {}, positionDrafts: {} };
|
|
110
|
+
setDrafts(draftsRef.current);
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
let dead = false;
|
|
114
|
+
const meta = ydoc.getMap('meta');
|
|
115
|
+
const draft = ydoc.getMap('draft');
|
|
116
|
+
const onMeta = () => {
|
|
117
|
+
if (dead) return;
|
|
118
|
+
const schema = meta.get('schema');
|
|
119
|
+
if (schema) {
|
|
120
|
+
// Apply only strictly-newer states (same discipline as the sidecar
|
|
121
|
+
// write guard) — Yjs LWW plus racing publishers means an older
|
|
122
|
+
// serialization CAN be observed after a newer one.
|
|
123
|
+
const sv = Number(meta.get('schema_version') || 0);
|
|
124
|
+
const ts = Number(meta.get('version') || 0);
|
|
125
|
+
if (newerStamp(stampRef.current, sv, ts)) {
|
|
126
|
+
stampRef.current = { sv, ts };
|
|
127
|
+
setLiveGraph(schema);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const cop = meta.get('copilot');
|
|
131
|
+
setCopilotBuilding(!!(cop && cop.building && (!cop.at || Date.now() - cop.at < COPILOT_STALE_MS)));
|
|
132
|
+
// Explorer channel: the copilot ran a query it wants shown. Strictly-
|
|
133
|
+
// newer gating like the schema stamp; the first observation after
|
|
134
|
+
// connect is the baseline only (never replayed).
|
|
135
|
+
const ex = meta.get('explorer');
|
|
136
|
+
const exVer = Number((ex && ex.version) || 0);
|
|
137
|
+
if (explorerStampRef.current === null) {
|
|
138
|
+
explorerStampRef.current = exVer;
|
|
139
|
+
} else if (ex && ex.query && exVer > explorerStampRef.current) {
|
|
140
|
+
explorerStampRef.current = exVer;
|
|
141
|
+
setExplorer({ query: String(ex.query), note: String(ex.note || ''),
|
|
142
|
+
requested_by: String(ex.requested_by || ''), version: exVer });
|
|
143
|
+
}
|
|
144
|
+
// Connect tool registry: the server republishes the full registry
|
|
145
|
+
// after every mutation (copilot meta-tools, REST saves) so open
|
|
146
|
+
// Connect tabs converge without polling.
|
|
147
|
+
const cn = meta.get('connect');
|
|
148
|
+
if (cn) {
|
|
149
|
+
let json = '';
|
|
150
|
+
try { json = JSON.stringify(cn); } catch { /* unserializable — skip */ }
|
|
151
|
+
if (json && json !== connectJsonRef.current) {
|
|
152
|
+
connectJsonRef.current = json;
|
|
153
|
+
setConnect(cn);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const onDraft = () => {
|
|
158
|
+
if (dead) return;
|
|
159
|
+
const next = readDrafts(draft);
|
|
160
|
+
draftsRef.current = next;
|
|
161
|
+
setDrafts(next);
|
|
162
|
+
};
|
|
163
|
+
meta.observe(onMeta);
|
|
164
|
+
draft.observe(onDraft);
|
|
165
|
+
onMeta();
|
|
166
|
+
onDraft();
|
|
167
|
+
return () => { dead = true; meta.unobserve(onMeta); draft.unobserve(onDraft); };
|
|
168
|
+
}, [live.doc]);
|
|
169
|
+
|
|
170
|
+
// Announce this person on join.
|
|
171
|
+
useEffect(() => {
|
|
172
|
+
const u = userRef.current || {};
|
|
173
|
+
live.setAwareness({ id: u.id || 'me', name: u.name || 'User', mode: modeRef.current, drag: null });
|
|
174
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
175
|
+
}, [graphId, live.setAwareness]);
|
|
176
|
+
|
|
177
|
+
const peers = useMemo(() => readPeers(live.states, live.selfClientId), [live.states, live.selfClientId]);
|
|
178
|
+
|
|
179
|
+
const pushAwareness = useCallback(() => {
|
|
180
|
+
const u = userRef.current || {};
|
|
181
|
+
live.setAwareness({ id: u.id || 'me', name: u.name || 'User', mode: modeRef.current, drag: dragRef.current });
|
|
182
|
+
}, [live.setAwareness]);
|
|
183
|
+
|
|
184
|
+
const setEditing = useCallback((editing) => {
|
|
185
|
+
modeRef.current = editing ? 'editing' : 'viewing';
|
|
186
|
+
pushAwareness();
|
|
187
|
+
}, [pushAwareness]);
|
|
188
|
+
|
|
189
|
+
// Live drag presence: while this user drags a node type, peers see
|
|
190
|
+
// {label, x, y} on the awareness roster (coarse — callers throttle).
|
|
191
|
+
// null clears it (mouse up).
|
|
192
|
+
const setDrag = useCallback((label, pos) => {
|
|
193
|
+
dragRef.current = label
|
|
194
|
+
? { label, x: Math.round((pos && pos.x) || 0), y: Math.round((pos && pos.y) || 0) }
|
|
195
|
+
: null;
|
|
196
|
+
pushAwareness();
|
|
197
|
+
}, [pushAwareness]);
|
|
198
|
+
|
|
199
|
+
// Shared draft setters — same call shapes as React state setters, mirrored
|
|
200
|
+
// into the Y.Map so every editor sees the draft (and its live preview).
|
|
201
|
+
const writeDrafts = useCallback((prefix, field, updater) => {
|
|
202
|
+
const cur = draftsRef.current[field];
|
|
203
|
+
const next = typeof updater === 'function' ? updater(cur) : updater;
|
|
204
|
+
const p = providerRef.current;
|
|
205
|
+
if (!p) { // offline fallback: keep drafts local so edit mode still works
|
|
206
|
+
draftsRef.current = { ...draftsRef.current, [field]: next };
|
|
207
|
+
setDrafts(draftsRef.current);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const map = p.document.getMap('draft');
|
|
211
|
+
p.document.transact(() => {
|
|
212
|
+
for (const [k, v] of Object.entries(next || {})) {
|
|
213
|
+
if (cur[k] !== v) map.set(prefix + k, v);
|
|
214
|
+
}
|
|
215
|
+
for (const k of Object.keys(cur || {})) {
|
|
216
|
+
if (!(k in (next || {}))) map.delete(prefix + k);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}, []);
|
|
220
|
+
const setTypeDrafts = useCallback((u) => writeDrafts(T_PREFIX, 'typeDrafts', u), [writeDrafts]);
|
|
221
|
+
const setPositionDrafts = useCallback((u) => writeDrafts(P_PREFIX, 'positionDrafts', u), [writeDrafts]);
|
|
222
|
+
|
|
223
|
+
// Snapshot of the CURRENT shared draft (raw doc keys -> values). Taken right
|
|
224
|
+
// before a save materializes, so the post-save cleanup can remove exactly
|
|
225
|
+
// what the save consumed.
|
|
226
|
+
const snapshotDraft = useCallback(() => {
|
|
227
|
+
const { typeDrafts, positionDrafts } = draftsRef.current;
|
|
228
|
+
const raw = {};
|
|
229
|
+
for (const [k, v] of Object.entries(typeDrafts || {})) raw[T_PREFIX + k] = v;
|
|
230
|
+
for (const [k, v] of Object.entries(positionDrafts || {})) raw[P_PREFIX + k] = v;
|
|
231
|
+
return raw;
|
|
232
|
+
}, []);
|
|
233
|
+
|
|
234
|
+
// Conditional post-save cleanup: delete ONLY entries still equal to the
|
|
235
|
+
// consumed snapshot. A key a peer (re)wrote while the save was in flight
|
|
236
|
+
// compares unequal — or was never seen by this replica at all — and
|
|
237
|
+
// SURVIVES as a pending draft instead of being wiped ("no operation lost").
|
|
238
|
+
// This replaces the server's blanket draft clear, which nuked every entry
|
|
239
|
+
// including ones written after the save's diff base was captured.
|
|
240
|
+
const clearDraftEntries = useCallback((consumed) => {
|
|
241
|
+
const entries = Object.entries(consumed || {});
|
|
242
|
+
if (!entries.length) return;
|
|
243
|
+
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
244
|
+
const p = providerRef.current;
|
|
245
|
+
if (!p) { // offline fallback — drafts are local state
|
|
246
|
+
const next = { typeDrafts: { ...draftsRef.current.typeDrafts },
|
|
247
|
+
positionDrafts: { ...draftsRef.current.positionDrafts } };
|
|
248
|
+
for (const [k, v] of entries) {
|
|
249
|
+
if (k.startsWith(T_PREFIX) && same(next.typeDrafts[k.slice(T_PREFIX.length)], v)) {
|
|
250
|
+
delete next.typeDrafts[k.slice(T_PREFIX.length)];
|
|
251
|
+
} else if (k.startsWith(P_PREFIX) && same(next.positionDrafts[k.slice(P_PREFIX.length)], v)) {
|
|
252
|
+
delete next.positionDrafts[k.slice(P_PREFIX.length)];
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
draftsRef.current = next;
|
|
256
|
+
setDrafts(next);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const map = p.document.getMap('draft');
|
|
260
|
+
p.document.transact(() => {
|
|
261
|
+
for (const [k, v] of entries) {
|
|
262
|
+
if (map.has(k) && same(map.get(k), v)) map.delete(k);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}, []);
|
|
266
|
+
|
|
267
|
+
return {
|
|
268
|
+
ready,
|
|
269
|
+
liveGraph,
|
|
270
|
+
peers,
|
|
271
|
+
copilotBuilding,
|
|
272
|
+
// Latest copilot-shown query (show_query_results): {query, note,
|
|
273
|
+
// requested_by, version}. Strictly-newer only; null until one arrives
|
|
274
|
+
// while this window is connected.
|
|
275
|
+
explorer,
|
|
276
|
+
// Latest published Connect tool registry ({raw_enabled, tools}) — null
|
|
277
|
+
// until the doc carries one; the Connect pane treats it as fresher truth
|
|
278
|
+
// than its REST fetch.
|
|
279
|
+
connect,
|
|
280
|
+
setEditing,
|
|
281
|
+
setDrag,
|
|
282
|
+
snapshotDraft,
|
|
283
|
+
clearDraftEntries,
|
|
284
|
+
// Other people's in-flight node drags: [{id, name, color, label, x, y}] —
|
|
285
|
+
// the canvas shows their indicator glued to the node they are moving,
|
|
286
|
+
// in the same color as their presence avatar.
|
|
287
|
+
dragPeers: peers.filter((p) => !p.self && p.drag)
|
|
288
|
+
.map((p) => ({ id: p.id, name: p.name, color: peerColor(p.id),
|
|
289
|
+
label: p.drag.label, x: p.drag.x, y: p.drag.y })),
|
|
290
|
+
draftStore: {
|
|
291
|
+
typeDrafts: drafts.typeDrafts,
|
|
292
|
+
positionDrafts: drafts.positionDrafts,
|
|
293
|
+
setTypeDrafts,
|
|
294
|
+
setPositionDrafts,
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// ── draft materialization + save ─────────────────────────────────────────────
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// vg-gateway client — talks to the same-origin Next BFF (/api/vg/*), which
|
|
2
|
+
// forwards to the AgentStudio VectorGraph Gateway server-side. The graph schema
|
|
3
|
+
// is authoritative in the VectorGraph management Cosmos; this is how the Spaces
|
|
4
|
+
// Graph asset reads it. Mirrors admin.js's shape so the GraphPage schema view
|
|
5
|
+
// can be pointed here with minimal change.
|
|
6
|
+
|
|
7
|
+
// Transport override — lets a non-studio consumer (ContextualGraph's Vite SPA)
|
|
8
|
+
// point this client at its own vg passthrough with its own auth headers. The
|
|
9
|
+
// studio never calls configureVgraph and keeps the same-origin BFF default.
|
|
10
|
+
let _transport = null;
|
|
11
|
+
export function configureVgraph(t) { _transport = t; }
|
|
12
|
+
|
|
13
|
+
async function send(method, path, body) {
|
|
14
|
+
const opts = { method, headers: _transport && _transport.headers ? { ..._transport.headers() } : {} };
|
|
15
|
+
if (body !== undefined) {
|
|
16
|
+
opts.headers['Content-Type'] = 'application/json';
|
|
17
|
+
opts.body = JSON.stringify(body);
|
|
18
|
+
}
|
|
19
|
+
const base = (_transport && _transport.base) || '/api/vg';
|
|
20
|
+
const res = await fetch(base + path, opts);
|
|
21
|
+
if (!res.ok) {
|
|
22
|
+
const text = await res.text().catch(() => '');
|
|
23
|
+
const err = new Error(`vg-gateway ${res.status} on ${method} ${path}: ${text || res.statusText}`);
|
|
24
|
+
// Callers branch on the status (409 = label fenced by a running schema
|
|
25
|
+
// change job; 404/405 = route not shipped on this deployment yet).
|
|
26
|
+
err.status = res.status;
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
if (res.status === 204) return null;
|
|
30
|
+
return res.json();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// A Graph asset binds to "<kb_uuid>#<subgraph>".
|
|
34
|
+
export function parseAssetRef(ref) {
|
|
35
|
+
const [kb, subgraph] = String(ref || '').split('#');
|
|
36
|
+
return { kb: kb || '', subgraph: subgraph || '' };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// schema_version ("major.minor", INTEGER minor: "2.9" -> "2.10") as a
|
|
40
|
+
// comparable number. Number("2.10") === 2.1 < 2.9, so a naive cast inverts
|
|
41
|
+
// the ordering the moment minor hits double digits — live pushes then look
|
|
42
|
+
// stale, clients pin on old truth, and saves persist the stale render (the
|
|
43
|
+
// lost-color/position bug). major*1e6+minor keeps it monotonic and larger
|
|
44
|
+
// than any legacy float stamp.
|
|
45
|
+
export function schemaVersionNum(v) {
|
|
46
|
+
const s = String(v == null ? '' : v);
|
|
47
|
+
const m = s.match(/^(\d+)\.(\d+)$/);
|
|
48
|
+
if (m) return Number(m[1]) * 1e6 + Number(m[2]);
|
|
49
|
+
const n = Number(s);
|
|
50
|
+
return Number.isFinite(n) ? n * 1e6 : 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const vgraph = {
|
|
54
|
+
// Adapted KnowledgeBaseSchema → GraphPage shape (vertex_types/edge_types).
|
|
55
|
+
getGraph(kb, subgraph) {
|
|
56
|
+
const q = subgraph ? `?subgraph=${encodeURIComponent(subgraph)}` : '';
|
|
57
|
+
return send('GET', `/v1/graphs/${encodeURIComponent(kb)}${q}`);
|
|
58
|
+
},
|
|
59
|
+
health() {
|
|
60
|
+
return send('GET', '/healthz');
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
// ── Mutations (each returns the re-adapted graph for the subgraph) ──────
|
|
64
|
+
patchUi(kb, subgraph, kind, label, ui) {
|
|
65
|
+
return send('PATCH', `/v1/graphs/${encodeURIComponent(kb)}/ui`, { subgraph, kind, label, ui });
|
|
66
|
+
},
|
|
67
|
+
addVertexType(kb, subgraph, label, description, ui) {
|
|
68
|
+
return send('POST', `/v1/graphs/${encodeURIComponent(kb)}/vertex-types`, { subgraph, label, description, ui });
|
|
69
|
+
},
|
|
70
|
+
addEdgeType(kb, subgraph, label, description, connections, ui) {
|
|
71
|
+
return send('POST', `/v1/graphs/${encodeURIComponent(kb)}/edge-types`, { subgraph, label, description, connections, ui });
|
|
72
|
+
},
|
|
73
|
+
// Type meta (description). The label itself is immutable identity.
|
|
74
|
+
patchTypeMeta(kb, subgraph, kind, label, description) {
|
|
75
|
+
const seg = kind === 'edge' ? 'edge-types' : 'vertex-types';
|
|
76
|
+
return send('PATCH', `/v1/graphs/${encodeURIComponent(kb)}/${seg}/${encodeURIComponent(label)}`, { subgraph, description });
|
|
77
|
+
},
|
|
78
|
+
addVertexProperty(kb, subgraph, label, prop) {
|
|
79
|
+
return send('POST', `/v1/graphs/${encodeURIComponent(kb)}/vertex-types/${encodeURIComponent(label)}/properties`, { subgraph, ...prop });
|
|
80
|
+
},
|
|
81
|
+
addEdgeProperty(kb, subgraph, label, prop) {
|
|
82
|
+
return send('POST', `/v1/graphs/${encodeURIComponent(kb)}/edge-types/${encodeURIComponent(label)}/properties`, { subgraph, ...prop });
|
|
83
|
+
},
|
|
84
|
+
// Property PATCH: attribute updates (default/description/ui) and/or a rename
|
|
85
|
+
// via new_name — schema-doc level; stored values are not migrated.
|
|
86
|
+
patchProperty(kb, subgraph, kind, label, name, patch) {
|
|
87
|
+
const seg = kind === 'edge' ? 'edge-types' : 'vertex-types';
|
|
88
|
+
return send('PATCH', `/v1/graphs/${encodeURIComponent(kb)}/${seg}/${encodeURIComponent(label)}/properties/${encodeURIComponent(name)}`, { subgraph, ...patch });
|
|
89
|
+
},
|
|
90
|
+
// Property DELETE: schema-doc level — values already stored on records stay
|
|
91
|
+
// in place but are no longer read or written. Indexed properties 400.
|
|
92
|
+
deleteProperty(kb, subgraph, kind, label, name) {
|
|
93
|
+
const seg = kind === 'edge' ? 'edge-types' : 'vertex-types';
|
|
94
|
+
return send('DELETE', `/v1/graphs/${encodeURIComponent(kb)}/${seg}/${encodeURIComponent(label)}/properties/${encodeURIComponent(name)}?subgraph=${encodeURIComponent(subgraph)}`);
|
|
95
|
+
},
|
|
96
|
+
// Indices. A semantic index on a string property makes the write path
|
|
97
|
+
// auto-embed the value into the d{dimensions} vector slot.
|
|
98
|
+
addIndex(kb, subgraph, kind, label, index) {
|
|
99
|
+
const seg = kind === 'edge' ? 'edge-types' : 'vertex-types';
|
|
100
|
+
return send('POST', `/v1/graphs/${encodeURIComponent(kb)}/${seg}/${encodeURIComponent(label)}/indices`, { subgraph, ...index });
|
|
101
|
+
},
|
|
102
|
+
removeIndex(kb, subgraph, kind, label, indexName) {
|
|
103
|
+
const seg = kind === 'edge' ? 'edge-types' : 'vertex-types';
|
|
104
|
+
return send('DELETE', `/v1/graphs/${encodeURIComponent(kb)}/${seg}/${encodeURIComponent(label)}/indices/${encodeURIComponent(indexName)}?subgraph=${encodeURIComponent(subgraph)}`);
|
|
105
|
+
},
|
|
106
|
+
// Schema-change jobs — mutations WITH data sync (drop a type incl. its
|
|
107
|
+
// records, drop/rename/retype a property incl. per-record migration). POST
|
|
108
|
+
// returns { job_id, status }; poll getSchemaChange until done|failed. While
|
|
109
|
+
// a job runs its labels are fenced: writes to them 409.
|
|
110
|
+
scheduleSchemaChange(kb, op, params) {
|
|
111
|
+
return send('POST', `/v1/graphs/${encodeURIComponent(kb)}/schema-changes`, { op, params, created_at: new Date().toISOString() });
|
|
112
|
+
},
|
|
113
|
+
getSchemaChange(kb, jobId) {
|
|
114
|
+
return send('GET', `/v1/graphs/${encodeURIComponent(kb)}/schema-changes/${encodeURIComponent(jobId)}`);
|
|
115
|
+
},
|
|
116
|
+
addConnection(kb, subgraph, label, from_type, to_type) {
|
|
117
|
+
return send('POST', `/v1/graphs/${encodeURIComponent(kb)}/edge-types/${encodeURIComponent(label)}/connections`, { subgraph, from_type, to_type });
|
|
118
|
+
},
|
|
119
|
+
removeConnection(kb, subgraph, label, from_type, to_type) {
|
|
120
|
+
const q = `subgraph=${encodeURIComponent(subgraph)}&from_type=${encodeURIComponent(from_type)}&to_type=${encodeURIComponent(to_type)}`;
|
|
121
|
+
return send('DELETE', `/v1/graphs/${encodeURIComponent(kb)}/edge-types/${encodeURIComponent(label)}/connections?${q}`);
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
// ── Instance data plane (vertices). Edges/neighbors deferred (lib gap). ──
|
|
125
|
+
listInstances(kb, label, limit = 50) {
|
|
126
|
+
return send('GET', `/v1/graphs/${encodeURIComponent(kb)}/instances?label=${encodeURIComponent(label)}&limit=${limit}`);
|
|
127
|
+
},
|
|
128
|
+
createInstance(kb, label, properties) {
|
|
129
|
+
return send('POST', `/v1/graphs/${encodeURIComponent(kb)}/instances`, { label, properties });
|
|
130
|
+
},
|
|
131
|
+
neighbors(kb, vertexId, limit = 50) {
|
|
132
|
+
return send('GET', `/v1/graphs/${encodeURIComponent(kb)}/instances/${encodeURIComponent(vertexId)}/neighbors?limit=${limit}`);
|
|
133
|
+
},
|
|
134
|
+
// Free-text search across all vertices (semantic + fulltext where available;
|
|
135
|
+
// substring today). Returns { results: [{id,label,title,fields}] }.
|
|
136
|
+
searchAll(kb, q, limit = 20) {
|
|
137
|
+
return send('GET', `/v1/graphs/${encodeURIComponent(kb)}/search?q=${encodeURIComponent(q || '')}&limit=${limit}`);
|
|
138
|
+
},
|
|
139
|
+
// Raw Gremlin++ over the tenant. Rejects (throws) on syntax/other errors so the
|
|
140
|
+
// caller can tell a valid query from free text. Returns { data, vertex_ids, … }.
|
|
141
|
+
gremlin(kb, query) {
|
|
142
|
+
return send('POST', '/v1/gremlin', { query, tenant_id: kb });
|
|
143
|
+
},
|
|
144
|
+
// Indexed full-text search (case-insensitive substring) via the textSearch step,
|
|
145
|
+
// across common text properties, merged + de-duped. The gateway rejects MULTIPLE
|
|
146
|
+
// textSearch steps in one query, so fire one per property in parallel; a property
|
|
147
|
+
// that isn't FTS-indexed just returns nothing (harmless). Returns { data: [rows] }
|
|
148
|
+
// of valueMap(true) vertex rows. Callers fall back to searchAll on empty/error.
|
|
149
|
+
async searchFts(kb, q, props = ['name', 'email', 'title', 'body', 'slug', 'display_name']) {
|
|
150
|
+
const esc = String(q || '').replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
151
|
+
if (!esc.trim()) return { data: [] };
|
|
152
|
+
const settled = await Promise.allSettled(props.map((p) =>
|
|
153
|
+
send('POST', '/v1/gremlin', {
|
|
154
|
+
query: `g.V().textSearch('${p}', '${esc}').limit(20).valueMap(true)`, tenant_id: kb,
|
|
155
|
+
})));
|
|
156
|
+
const byId = new Map();
|
|
157
|
+
for (const s of settled) {
|
|
158
|
+
if (s.status !== 'fulfilled') continue;
|
|
159
|
+
for (const row of (s.value.data || [])) {
|
|
160
|
+
if (row && row.id != null && !byId.has(row.id)) byId.set(row.id, row);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return { data: [...byId.values()] };
|
|
164
|
+
},
|
|
165
|
+
createEdge(kb, label, from_id, to_id, properties = {}) {
|
|
166
|
+
return send('POST', `/v1/graphs/${encodeURIComponent(kb)}/edges`, { label, from_id, to_id, properties });
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// TODO(schema-batch): a batched mutation route (POST /v1/graphs/{kb}/schema-batch)
|
|
171
|
+
// is being built in parallel. Once it ships, add `schemaBatch(kb, subgraph, ops)`
|
|
172
|
+
// here and swap SpacesGraphView's saveChanges per-op loop to ONE call — the op
|
|
173
|
+
// list construction stays, only the transport changes.
|
|
174
|
+
|
|
175
|
+
// VectorGraph DataType enum — drives the property type dropdown. Used directly
|
|
176
|
+
// (no SQL→type mapping); mirrors schema_manager/models.py:DataType.
|
|
177
|
+
export const DATA_TYPES = ['string', 'integer', 'double', 'boolean', 'datetime', 'json', 'file', 'vector'];
|
|
178
|
+
|
|
179
|
+
// ── Semantic search helpers ─────────────────────────────────────────────────
|
|
180
|
+
// The platform embeds with ONE flexible-dims Azure OpenAI model; the "@<dims>"
|
|
181
|
+
// suffix pins an index's vectors to a fixed DiskANN slot (384/768/1536/3072).
|
|
182
|
+
// Mirrors backend/contextualgraph/app/templates.py:DIM_EMBEDDERS.
|
|
183
|
+
const EMBEDDER_BASE = 'azure/text-embedding-3-large';
|
|
184
|
+
|
|
185
|
+
// Fields that read as long-form prose get the wider 1536-dim slot; everything
|
|
186
|
+
// else (names, titles, tags, short labels) does fine at 384.
|
|
187
|
+
const LONG_TEXT_NAME = /(body|content|description|summary|note|text|bio|about|detail|transcript|comment|review|message|abstract|story)/i;
|
|
188
|
+
|
|
189
|
+
export function semanticDimsFor(propName) {
|
|
190
|
+
return LONG_TEXT_NAME.test(String(propName || '')) ? 1536 : 384;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** IndexDefinition body for turning semantic search on for a string property. */
|
|
194
|
+
export function semanticIndexFor(propName, dims) {
|
|
195
|
+
const d = dims || semanticDimsFor(propName);
|
|
196
|
+
return { name: `${propName}_semantic`, property: propName, type: 'semantic', embedder: `${EMBEDDER_BASE}@${d}`, dimensions: d };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** The semantic index covering `propName`, if the type has one. */
|
|
200
|
+
export function semanticIndexOn(type, propName) {
|
|
201
|
+
return ((type && type.indices) || []).find((i) => i.type === 'semantic' && i.property === propName) || null;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Poll a schema-change job until it leaves pending/running. onTick gets each
|
|
205
|
+
* job doc (progress.step etc). Resolves the final doc; rejects on timeout. */
|
|
206
|
+
export async function pollSchemaChange(kb, jobId, { intervalMs = 1200, timeoutMs = 180000, onTick } = {}) {
|
|
207
|
+
const t0 = Date.now();
|
|
208
|
+
for (;;) {
|
|
209
|
+
const job = await vgraph.getSchemaChange(kb, jobId);
|
|
210
|
+
if (onTick) onTick(job);
|
|
211
|
+
if (job.status === 'done' || job.status === 'failed') return job;
|
|
212
|
+
if (Date.now() - t0 > timeoutMs) throw new Error(`schema change ${jobId} still ${job.status} after ${timeoutMs}ms`);
|
|
213
|
+
await new Promise((r) => setTimeout(r, intervalMs));
|
|
214
|
+
}
|
|
215
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -167,6 +167,9 @@ export const AssistantTurn: ComponentType<Record<string, unknown>>;
|
|
|
167
167
|
export const DEFAULT_STATUS_LABELS: Record<string, string>;
|
|
168
168
|
|
|
169
169
|
export interface ComposerProps {
|
|
170
|
+
/** files dropped on the composer, or on dropTargetRef's element */
|
|
171
|
+
onFiles?: (files: FileList) => void;
|
|
172
|
+
dropTargetRef?: { current: HTMLElement | null };
|
|
170
173
|
value: string;
|
|
171
174
|
onChange: (value: string) => void;
|
|
172
175
|
onSend: () => void;
|
package/src/index.js
CHANGED
|
@@ -44,7 +44,7 @@ export {
|
|
|
44
44
|
export { AuthForm } from './auth/AuthForm.jsx';
|
|
45
45
|
export { GoogleButton, GOOGLE_ENABLED } from './auth/GoogleButton.jsx';
|
|
46
46
|
// Shared AI-spreadsheet grid (reusable in the Sheets product AND studio Spaces).
|
|
47
|
-
export { SheetGrid, sheetToDelimited, sheetToAoA
|
|
47
|
+
export { SheetGrid, sheetToDelimited, sheetToAoA } from './sheet/SheetGrid.jsx';
|
|
48
48
|
// Files, drawn the same wherever they appear. FileTypeIcon uses react-file-icon when it is
|
|
49
49
|
// installed (an optional peer) and falls back to an extension badge when it is not.
|
|
50
50
|
export { FileTypeIcon, extOf } from './components/FileTypeIcon.jsx';
|
|
@@ -85,3 +85,6 @@ export {
|
|
|
85
85
|
Timeline, majorTickStep, tickLabel, durationLabel as timelineDurationLabel,
|
|
86
86
|
TL_MIN_PPS, TL_MAX_PPS, TL_DEFAULT_PPS, TL_HEAD_W,
|
|
87
87
|
} from './timeline/Timeline.jsx';
|
|
88
|
+
// Mentions: a field that holds people, columns, files as pills; the menu at the caret; the
|
|
89
|
+
// read-only renderer; and the token model ({{Name}} / @Name) hosts serialize through.
|
|
90
|
+
export { MentionInput, MentionText } from './mention/MentionInput.jsx';
|