reifyui 0.12.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +29 -0
  2. package/dist/chart.js +2 -0
  3. package/dist/chart.js.map +1 -1
  4. package/dist/chunk-EL2DHWOH.js +1710 -0
  5. package/dist/chunk-EL2DHWOH.js.map +1 -0
  6. package/dist/chunk-J633KV57.js +41 -0
  7. package/dist/chunk-J633KV57.js.map +1 -0
  8. package/dist/chunk-J7SECRIG.js +295 -0
  9. package/dist/chunk-J7SECRIG.js.map +1 -0
  10. package/dist/chunk-PIRPLH2Z.js +231 -0
  11. package/dist/chunk-PIRPLH2Z.js.map +1 -0
  12. package/dist/chunk-PZ5AY32C.js +10 -0
  13. package/dist/chunk-PZ5AY32C.js.map +1 -0
  14. package/dist/chunk-UKG4Z6QK.js +130 -0
  15. package/dist/chunk-UKG4Z6QK.js.map +1 -0
  16. package/dist/chunk-ZYWE47EO.js +19 -0
  17. package/dist/chunk-ZYWE47EO.js.map +1 -0
  18. package/dist/collab.cjs +169 -0
  19. package/dist/collab.cjs.map +1 -0
  20. package/dist/collab.d.ts +30 -0
  21. package/dist/collab.js +18 -0
  22. package/dist/collab.js.map +1 -0
  23. package/dist/graph.cjs +2244 -0
  24. package/dist/graph.cjs.map +1 -0
  25. package/dist/graph.d.ts +41 -0
  26. package/dist/graph.js +1870 -0
  27. package/dist/graph.js.map +1 -0
  28. package/dist/harness.js +1 -0
  29. package/dist/harness.js.map +1 -1
  30. package/dist/index.cjs +1699 -817
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.ts +3 -0
  33. package/dist/index.js +680 -1769
  34. package/dist/index.js.map +1 -1
  35. package/dist/sheet-doc.cjs +235 -0
  36. package/dist/sheet-doc.cjs.map +1 -0
  37. package/dist/sheet-doc.d.ts +16 -0
  38. package/dist/sheet-doc.js +20 -0
  39. package/dist/sheet-doc.js.map +1 -0
  40. package/dist/sheet.cjs +2322 -0
  41. package/dist/sheet.cjs.map +1 -0
  42. package/dist/sheet.d.ts +23 -0
  43. package/dist/sheet.js +237 -0
  44. package/dist/sheet.js.map +1 -0
  45. package/dist/slides.js +2 -0
  46. package/dist/slides.js.map +1 -1
  47. package/package.json +34 -2
  48. package/src/auth/client.js +4 -2
  49. package/src/collab/colors.js +18 -0
  50. package/src/collab/index.d.ts +30 -0
  51. package/src/collab/index.js +8 -0
  52. package/src/collab/keepAlive.js +34 -0
  53. package/src/collab/useLiveDoc.js +76 -0
  54. package/src/components/CascadeMenu.jsx +9 -3
  55. package/src/components/Composer.jsx +37 -3
  56. package/src/components/resizable.jsx +82 -12
  57. package/src/graph/ConnectPane.jsx +634 -0
  58. package/src/graph/ConnectToolDetail.jsx +565 -0
  59. package/src/graph/LogsPane.jsx +328 -0
  60. package/src/graph/Skeleton.jsx +13 -0
  61. package/src/graph/draft.js +108 -0
  62. package/src/graph/format.js +37 -0
  63. package/src/graph/index.d.ts +41 -0
  64. package/src/graph/index.js +14 -0
  65. package/src/graph/useGraphCollab.js +299 -0
  66. package/src/graph/vgraph.js +215 -0
  67. package/src/index.d.ts +3 -0
  68. package/src/index.js +4 -1
  69. package/src/mention/MentionInput.jsx +420 -0
  70. package/src/mention/mentionModel.js +177 -0
  71. package/src/sheet/RunStrip.jsx +57 -0
  72. package/src/sheet/SheetGrid.jsx +448 -423
  73. package/src/sheet/doc.d.ts +16 -0
  74. package/src/sheet/index.d.ts +23 -0
  75. package/src/sheet/index.js +10 -0
  76. package/src/sheet/sheetDoc.js +203 -0
  77. package/src/sheet/useSheetCollab.js +102 -0
  78. package/src/sheet/useSheetRun.js +80 -0
  79. package/styles/chat.css +2 -0
  80. package/styles/graph.css +395 -0
  81. package/styles/mention.css +79 -0
  82. package/styles/sheet.css +156 -112
@@ -0,0 +1,328 @@
1
+ // LogsPane — the graph's activity trail (the Logs tab). Every operation on the
2
+ // graph (copilot tool calls, canvas/inspector edits, schema saves, lifecycle)
3
+ // is one row, newest first. Pagination AND search are server-side: the list
4
+ // only ever holds the pages the user actually walked, and typing in the search
5
+ // box re-queries the store (debounced), never filters a local copy.
6
+ //
7
+ // Design language lifted from the HarnessRouter Traces list (row grid, kind
8
+ // badges, mono stats column, expandable detail, skeleton loading) and restyled
9
+ // with the ContextualGraph tokens. JSON detail renders through the shared
10
+ // UI Core CodeBlock.
11
+ import { useCallback, useEffect, useRef, useState } from 'react';
12
+ import { Bot, ChevronDown, ChevronRight, KeyRound, ScrollText, Search, X } from 'lucide-react';
13
+ import { CodeBlock } from '../components/CodeBlock.jsx';
14
+ import { fmtUnits, relativeTime } from './format.js';
15
+ import { Skeleton } from './Skeleton.jsx';
16
+
17
+ const PAGE = 25;
18
+
19
+ // op -> short display label, always the user's vocabulary.
20
+ const OP_LABEL = {
21
+ get_schema: 'Read design',
22
+ add_vertex_type: 'Add node type',
23
+ add_node_type: 'Add node type',
24
+ update_node_type: 'Update node type',
25
+ delete_vertex_type: 'Delete node type',
26
+ delete_node_type: 'Delete node type',
27
+ add_edge_type: 'Add relationship',
28
+ add_relationship_type: 'Add relationship',
29
+ update_relationship_type: 'Update relationship',
30
+ delete_edge_type: 'Delete relationship',
31
+ delete_relationship_type: 'Delete relationship',
32
+ add_property: 'Add field',
33
+ add_field: 'Add field',
34
+ update_field: 'Update field',
35
+ rename_property: 'Rename field',
36
+ rename_field: 'Rename field',
37
+ delete_property: 'Delete field',
38
+ delete_field: 'Delete field',
39
+ add_semantic_index: 'Add search index',
40
+ add_search_index: 'Add search index',
41
+ delete_search_index: 'Delete search index',
42
+ add_connection: 'Add connection',
43
+ delete_connection: 'Delete connection',
44
+ update_ui: 'Update style',
45
+ update_style: 'Update style',
46
+ batch_schema: 'Schema changes',
47
+ schema_batch: 'Schema changes',
48
+ schema_change: 'Schema change',
49
+ get_schema_job: 'Check change',
50
+ save_design: 'Save design',
51
+ query: 'Query',
52
+ semantic_search: 'Search',
53
+ upsert_vertex: 'Save record',
54
+ add_record: 'Add record',
55
+ delete_vertex: 'Delete record',
56
+ upsert_edge: 'Link records',
57
+ link_records: 'Link records',
58
+ delete_edge: 'Unlink records',
59
+ edit_records: 'Edit records',
60
+ copilot_turn: 'Chat',
61
+ create_graph: 'Create graph',
62
+ rename_graph: 'Rename graph',
63
+ delete_graph: 'Delete graph',
64
+ update_thumbnail: 'Preview image',
65
+ // Connect: tool registry, API keys, external agent calls
66
+ connect_list_tools: 'Read tools',
67
+ connect_save_tool: 'Save tool',
68
+ connect_delete_tool: 'Delete tool',
69
+ connect_set_enabled: 'Toggle tool',
70
+ connect_test_tool: 'Test tool',
71
+ connect_list_keys: 'Read API keys',
72
+ create_key: 'Create API key',
73
+ create_api_key: 'Create API key',
74
+ delete_key: 'Revoke API key',
75
+ delete_api_key: 'Revoke API key',
76
+ revoke_key: 'Revoke API key',
77
+ external_call: 'Agent call',
78
+ mcp_call: 'Agent call',
79
+ tool_call: 'Agent call',
80
+ };
81
+ const opLabel = (op) =>
82
+ OP_LABEL[op] || String(op || '').replace(/_/g, ' ').replace(/^./, (c) => c.toUpperCase());
83
+
84
+ // Connect ops whose family the prefix rules below would misread
85
+ // (connect_delete_tool starts with "connect", not "delete"; an external
86
+ // agent call is its own family with its own tint).
87
+ const OP_KIND = {
88
+ connect_save_tool: 'add',
89
+ connect_delete_tool: 'del',
90
+ connect_set_enabled: 'edit',
91
+ connect_test_tool: 'read',
92
+ connect_list_tools: 'read',
93
+ connect_list_keys: 'read',
94
+ external_call: 'ext',
95
+ mcp_call: 'ext',
96
+ tool_call: 'ext',
97
+ };
98
+
99
+ // badge tint by operation family (mirrors the Traces kind palette, CG tones)
100
+ function opKind(op = '', status = '') {
101
+ if (status === 'error') return 'err';
102
+ if (OP_KIND[op]) return OP_KIND[op];
103
+ if (op === 'copilot_turn') return 'chat';
104
+ if (/^(delete|drop|unlink)/.test(op)) return 'del';
105
+ if (/^(add|create|link|upsert|save)/.test(op)) return 'add';
106
+ if (/^(query|semantic_search|get|read|check)/.test(op)) return 'read';
107
+ return 'edit';
108
+ }
109
+
110
+ const fmtDur = (ms) => {
111
+ if (ms == null) return '';
112
+ const n = Number(ms);
113
+ if (!isFinite(n)) return '';
114
+ if (n < 1000) return `${Math.round(n)}ms`;
115
+ if (n < 60000) return `${(n / 1000).toFixed(1)}s`;
116
+ return `${Math.floor(n / 60000)}m ${Math.round((n % 60000) / 1000)}s`;
117
+ };
118
+
119
+ function ActorChip({ actor, copilotMark }) {
120
+ const copilot = actor?.kind === 'copilot';
121
+ // An external agent call is attributed to the API key it presented —
122
+ // a distinct chip so third-party access reads differently from people.
123
+ if (actor?.kind === 'api_key' || actor?.type === 'api_key') {
124
+ const keyName = actor.name || 'API key';
125
+ return (
126
+ <span className="lg-actor lg-actor-key" title={`API key: ${keyName}`}>
127
+ <KeyRound size={11} aria-hidden="true" />
128
+ <span className="lg-actor-name">{keyName}</span>
129
+ </span>
130
+ );
131
+ }
132
+ const name = copilot ? 'Copilot' : (actor?.name || 'Someone');
133
+ return (
134
+ <span className="lg-actor" title={name}>
135
+ {copilot
136
+ ? <span className="lg-actor-mark">{copilotMark ?? <Bot size={14} />}</span>
137
+ : <span className="lg-actor-av">{(name[0] || '?').toUpperCase()}</span>}
138
+ <span className="lg-actor-name">{name}</span>
139
+ </span>
140
+ );
141
+ }
142
+
143
+ function DetailBlock({ entry }) {
144
+ const when = entry.ts ? new Date(entry.ts).toLocaleString() : '';
145
+ const hasArgs = entry.args != null &&
146
+ !(typeof entry.args === 'object' && Object.keys(entry.args).length === 0);
147
+ let argsText = '';
148
+ if (hasArgs) {
149
+ try { argsText = JSON.stringify(entry.args, null, 2); } catch { argsText = String(entry.args); }
150
+ }
151
+ // Consumption envelope from the execution response: real units only,
152
+ // spelled out ("12.4 read units"), nothing shown when the entry has none.
153
+ const units = fmtUnits(entry.consumption);
154
+ return (
155
+ <div className="lg-detail">
156
+ <div className="lg-detail-meta mono">
157
+ {when}
158
+ {entry.duration_ms != null && <span> · {fmtDur(entry.duration_ms)}</span>}
159
+ {units && <span> · {units}</span>}
160
+ </div>
161
+ {entry.error && <div className="lg-detail-err">{entry.error}</div>}
162
+ {hasArgs
163
+ ? <CodeBlock code={argsText} language="json" className="lg-json" />
164
+ : (!entry.error && <div className="lg-detail-none">No further detail for this action.</div>)}
165
+ </div>
166
+ );
167
+ }
168
+
169
+ function Row({ entry, open, onToggle }) {
170
+ const kind = opKind(entry.op, entry.status);
171
+ return (
172
+ <div className={'lg-row-wrap' + (open ? ' open' : '')}>
173
+ <button type="button" className="lg-row" onClick={onToggle} aria-expanded={open}>
174
+ <span className="lg-caret">{open ? <ChevronDown size={14} /> : <ChevronRight size={14} />}</span>
175
+ <span className={`lg-dot lg-${entry.status === 'error' ? 'error' : 'ok'}`} aria-hidden="true" />
176
+ <span className={`lg-badge lg-k-${kind}`}>{opLabel(entry.op)}</span>
177
+ <span className="lg-sum">{entry.summary || opLabel(entry.op)}</span>
178
+ <span className="lg-side">
179
+ <ActorChip actor={entry.actor} copilotMark={copilotMark} />
180
+ {entry.duration_ms != null && <span className="lg-dur mono">{fmtDur(entry.duration_ms)}</span>}
181
+ <span className="lg-ago mono">{relativeTime(Date.parse(entry.ts)) || ''}</span>
182
+ </span>
183
+ </button>
184
+ {open && <DetailBlock entry={entry} />}
185
+ </div>
186
+ );
187
+ }
188
+
189
+ function LogsSkeleton() {
190
+ return (
191
+ <div className="lg-list" aria-busy="true" aria-label="Loading activity">
192
+ {Array.from({ length: 8 }).map((_, i) => (
193
+ <div key={i} className="lg-skel-row">
194
+ <Skeleton w={8} h={8} radius={999} />
195
+ <Skeleton w={86} h={18} radius={999} />
196
+ <Skeleton w={`${34 + ((i * 13) % 40)}%`} h={12} />
197
+ <span className="lg-skel-right"><Skeleton w={90} h={12} /></span>
198
+ </div>
199
+ ))}
200
+ </div>
201
+ );
202
+ }
203
+
204
+ /** `client`: {fetchAudit(graphId, {limit, cursor, q})} bound to the host's API and auth. */
205
+ export function LogsPane({ graphId, client, copilotMark }) {
206
+ const [entries, setEntries] = useState([]);
207
+ const [nextCursor, setNextCursor] = useState(null);
208
+ const [loading, setLoading] = useState(true); // first page for the current q
209
+ const [loadingMore, setLoadingMore] = useState(false);
210
+ const [error, setError] = useState('');
211
+ const [qInput, setQInput] = useState('');
212
+ const [q, setQ] = useState('');
213
+ const [open, setOpen] = useState(() => new Set());
214
+ const genRef = useRef(0); // drop stale responses
215
+
216
+ // Debounce the search box into the server-side q (fresh first page each time).
217
+ useEffect(() => {
218
+ const t = setTimeout(() => setQ(qInput.trim()), 300);
219
+ return () => clearTimeout(t);
220
+ }, [qInput]);
221
+
222
+ const loadFirst = useCallback(async () => {
223
+ const gen = ++genRef.current;
224
+ setLoading(true); setError('');
225
+ try {
226
+ const body = await client.fetchAudit(graphId, { limit: PAGE, q });
227
+ if (genRef.current !== gen) return;
228
+ setEntries(body.entries || []);
229
+ setNextCursor(body.next_cursor || null);
230
+ setOpen(new Set());
231
+ } catch (e) {
232
+ if (genRef.current !== gen) return;
233
+ // The raw error goes to the console for debugging; the user gets a
234
+ // friendly line plus a Try again control, never server detail.
235
+ console.warn('Activity load failed:', e);
236
+ setEntries([]); setNextCursor(null);
237
+ setError(true);
238
+ } finally {
239
+ if (genRef.current === gen) setLoading(false);
240
+ }
241
+ }, [graphId, q, client]);
242
+
243
+ useEffect(() => { loadFirst(); }, [loadFirst]);
244
+
245
+ const loadMore = useCallback(async () => {
246
+ if (!nextCursor || loadingMore) return;
247
+ const gen = genRef.current;
248
+ setLoadingMore(true);
249
+ try {
250
+ const body = await client.fetchAudit(graphId, { limit: PAGE, cursor: nextCursor, q });
251
+ if (genRef.current !== gen) return;
252
+ setEntries((prev) => [...prev, ...(body.entries || [])]);
253
+ setNextCursor(body.next_cursor || null);
254
+ } catch (e) {
255
+ // Keep the already-loaded rows on screen; the Load more button stays
256
+ // for another attempt. Raw error to the console only.
257
+ if (genRef.current === gen) console.warn('Activity load-more failed:', e);
258
+ } finally {
259
+ if (genRef.current === gen) setLoadingMore(false);
260
+ }
261
+ }, [graphId, nextCursor, loadingMore, q, client]);
262
+
263
+ const toggle = (id) => setOpen((prev) => {
264
+ const next = new Set(prev);
265
+ if (next.has(id)) next.delete(id); else next.add(id);
266
+ return next;
267
+ });
268
+
269
+ const empty = !loading && !error && entries.length === 0;
270
+
271
+ return (
272
+ <div className="gp-placeholder lg-root">
273
+ <div className="pane" style={{ flex: 1 }}>
274
+ <div className="lg-head">
275
+ <div className="lg-title">Logs</div>
276
+ <div className="lg-search">
277
+ <Search size={14} aria-hidden="true" />
278
+ <input
279
+ value={qInput}
280
+ onChange={(e) => setQInput(e.target.value)}
281
+ placeholder="Search activity"
282
+ aria-label="Search activity"
283
+ />
284
+ {qInput && (
285
+ <button type="button" className="lg-search-x" onClick={() => setQInput('')} aria-label="Clear search">
286
+ <X size={13} />
287
+ </button>
288
+ )}
289
+ </div>
290
+ </div>
291
+
292
+ {loading ? (
293
+ <LogsSkeleton />
294
+ ) : error ? (
295
+ <div className="pane-empty">
296
+ <div className="big">Could not load activity</div>
297
+ <div>Please try again.</div>
298
+ <button type="button" className="btn sm" onClick={loadFirst}>Try again</button>
299
+ </div>
300
+ ) : empty ? (
301
+ <div className="pane-empty">
302
+ <ScrollText size={28} />
303
+ <div className="big">{q ? 'No matching activity' : 'No activity yet'}</div>
304
+ <div style={{ maxWidth: 420 }}>
305
+ {q ? 'Nothing in this graph’s history matches your search.'
306
+ : 'Actions on this graph will appear here.'}
307
+ </div>
308
+ </div>
309
+ ) : (
310
+ <>
311
+ <div className="lg-list scroll">
312
+ {entries.map((e) => (
313
+ <Row key={e.id} entry={e} open={open.has(e.id)} onToggle={() => toggle(e.id)} />
314
+ ))}
315
+ {nextCursor && (
316
+ <div className="lg-more">
317
+ <button type="button" className="btn sm" onClick={loadMore} disabled={loadingMore}>
318
+ {loadingMore ? 'Loading…' : 'Load more'}
319
+ </button>
320
+ </div>
321
+ )}
322
+ </div>
323
+ </>
324
+ )}
325
+ </div>
326
+ </div>
327
+ );
328
+ }
@@ -0,0 +1,13 @@
1
+ // Skeleton — a pulsing placeholder shaped like the eventual content so data
2
+ // arriving causes no layout shift (styles in panes.css; respects
3
+ // prefers-reduced-motion). Hosts compose their own layouts from it.
4
+ import React from 'react';
5
+
6
+ export function Skeleton({ variant = 'line', w, h, radius, className = '', style }) {
7
+ const cls = `sk sk-${variant}${className ? ' ' + className : ''}`;
8
+ const s = { ...(style || {}) };
9
+ if (w != null) s.width = typeof w === 'number' ? `${w}px` : w;
10
+ if (h != null) s.height = typeof h === 'number' ? `${h}px` : h;
11
+ if (radius != null) s.borderRadius = typeof radius === 'number' ? `${radius}px` : radius;
12
+ return <span className={cls} style={s} aria-hidden="true" />;
13
+ }
@@ -0,0 +1,108 @@
1
+ // The graph canvas's edit draft: how a shared draft (type edits, positions)
2
+ // materializes onto the published schema for rendering, and how a save turns
3
+ // it into a schema job through the ContextualGraph service. Hosts differ in
4
+ // how they reach the service, so saveDraft takes `request(path, init)`, a
5
+ // fetch bound to the host's base and auth (the CG app: its API host; the
6
+ // studio: its same-origin BFF). Schema jobs and graph reads come from the
7
+ // shared studio lib in both hosts.
8
+ import { semanticIndexFor, pollSchemaChange, vgraph } from './vgraph.js';
9
+
10
+ function applyTypeDraft(t, d, isVertex) {
11
+ t.ui = { ...(t.ui || {}) };
12
+ if (d.color != null) t.ui.color = d.color;
13
+ if (d.icon != null) t.ui.icon = d.icon;
14
+ if (d.labelProps != null) t.ui.labelProps = d.labelProps;
15
+ if (d.description != null) t.description = d.description;
16
+ for (const raw of d.props || []) {
17
+ if (!raw.name || !raw.name.trim()) continue;
18
+ const name = raw.name.trim();
19
+ if ((t.properties || []).some((p) => p.name === name)) continue;
20
+ const p = { name, type: raw.type || 'string' };
21
+ if (p.type === 'vector') p.dimensions = Number(raw.dimensions) || null;
22
+ t.properties = [...(t.properties || []), p];
23
+ if (isVertex && p.type === 'string' && raw.semantic) {
24
+ t.indices = [...(t.indices || []), semanticIndexFor(name)];
25
+ }
26
+ }
27
+ if (!isVertex) {
28
+ let conns = (t.connections || []).slice();
29
+ for (const c of d.addConns || []) {
30
+ if (!conns.some((x) => x.from_type === c.from_type && x.to_type === c.to_type)) {
31
+ conns.push({ from_type: c.from_type, to_type: c.to_type });
32
+ }
33
+ }
34
+ for (const c of d.removeConns || []) {
35
+ conns = conns.filter((x) => !(x.from_type === c.from_type && x.to_type === c.to_type));
36
+ }
37
+ t.connections = conns;
38
+ }
39
+ }
40
+
41
+ /** The draft as a FULL graph JSON: current truth + the pending edits, the
42
+ * shape POST /schema/save diffs against the DB. `positions` overrides
43
+ * ui.position per label (the rendered layout when a drag is pending). */
44
+ export function materializeDraft(graph, { typeDrafts = {}, positions = {} }) {
45
+ const clone = JSON.parse(JSON.stringify(graph || {}));
46
+ for (const vt of clone.vertex_types || []) {
47
+ const label = vt.label || vt.name;
48
+ vt.ui = { ...(vt.ui || {}) };
49
+ if (positions[label]) vt.ui.position = { x: Math.round(positions[label].x), y: Math.round(positions[label].y) };
50
+ const d = typeDrafts[`vertex:${label}`];
51
+ if (d) applyTypeDraft(vt, d, true);
52
+ }
53
+ if (clone.node_types) clone.node_types = clone.vertex_types;
54
+ for (const et of clone.edge_types || []) {
55
+ const d = typeDrafts[`edge:${et.label || et.name}`];
56
+ if (d) applyTypeDraft(et, d, false);
57
+ }
58
+ return clone;
59
+ }
60
+
61
+ /** The save endpoint's structured 400/409 details, in user language. */
62
+ function friendlyDetail(status, detail) {
63
+ if (status === 409) {
64
+ return 'Part of this schema is still being updated by an earlier change. Please try again in a moment.';
65
+ }
66
+ if (typeof detail === 'string' && detail) return detail;
67
+ if (detail && typeof detail === 'object') {
68
+ const items = (detail.problems || detail.violations || [])
69
+ .map((v) => (v.where ? `${v.where}: ${v.error}` : v.error))
70
+ .filter(Boolean)
71
+ .slice(0, 6);
72
+ return [detail.message || 'Some changes could not be applied.', ...items].join('\n');
73
+ }
74
+ return 'Your changes could not be saved. Please try again.';
75
+ }
76
+
77
+ /** Post the materialized draft; resolves to the post-save graph JSON.
78
+ * Destructive parts run as a background job — this waits for it, so the
79
+ * resolved graph is the settled truth. Throws Error with .friendly = true
80
+ * and a user-language message on the conflict contract.
81
+ * `client_clears_draft: true` tells the server NOT to blanket-clear the
82
+ * shared draft — the caller removes exactly the entries it consumed (see
83
+ * clearDraftEntries), so edits made during the save survive. */
84
+ export async function saveDraft(graphId, kb, draftGraph, { request }) {
85
+ const res = await request(`/v1/cg/graphs/${encodeURIComponent(graphId)}/schema/save`, {
86
+ method: 'POST',
87
+ headers: { 'content-type': 'application/json' },
88
+ body: JSON.stringify({ draft: draftGraph, client_clears_draft: true }),
89
+ });
90
+ let body = null;
91
+ try { body = await res.json(); } catch { /* non-JSON error body */ }
92
+ if (!res.ok) {
93
+ const err = new Error(friendlyDetail(res.status, body && body.detail));
94
+ err.friendly = true;
95
+ err.status = res.status;
96
+ throw err;
97
+ }
98
+ if (body && body.job_id) {
99
+ const job = await pollSchemaChange(kb, body.job_id);
100
+ if (job.status === 'failed') {
101
+ const err = new Error('Part of this change could not be applied. The schema was reloaded; please review and try again.');
102
+ err.friendly = true;
103
+ throw err;
104
+ }
105
+ return vgraph.getGraph(kb, 'default');
106
+ }
107
+ return body && body.graph;
108
+ }
@@ -0,0 +1,37 @@
1
+ // Display helpers shared by the graph panes (Connect, Logs) in every host.
2
+
3
+ /** "12.4 read units · 0 write units" from a consumption envelope; null when
4
+ * the envelope is absent so callers render an honest dash, never a made-up
5
+ * number. */
6
+ export function fmtUnits(c) {
7
+ const num = (v) => (typeof v === 'number' && isFinite(v) ? (Math.round(v * 10) / 10).toString() : null);
8
+ if (!c) return null;
9
+ const r = num(c.read_units);
10
+ const w = num(c.write_units);
11
+ if (r == null && w == null) return null;
12
+ return `${r ?? '—'} read units · ${w ?? '—'} write units`;
13
+ }
14
+
15
+ /** Relative age at every scale ("2 h ago", "3 mo ago") so the Last viewed
16
+ * column stays one consistent format; pair with absoluteTime in the cell
17
+ * title for the precise date. */
18
+ export function relativeTime(ts) {
19
+ if (!ts) return null;
20
+ const delta = Date.now() - ts;
21
+ const m = Math.floor(delta / 60000);
22
+ if (m < 1) return 'just now';
23
+ if (m < 60) return `${m} min ago`;
24
+ const h = Math.floor(m / 60);
25
+ if (h < 24) return `${h} h ago`;
26
+ const d = Math.floor(h / 24);
27
+ if (d < 30) return `${d} d ago`;
28
+ const mo = Math.floor(d / 30);
29
+ if (mo < 12) return `${mo} mo ago`;
30
+ return `${Math.floor(d / 365)} y ago`;
31
+ }
32
+
33
+ /** Full local date + time for tooltips; null when the stamp is unset. */
34
+ export function absoluteTime(ts) {
35
+ if (!ts) return null;
36
+ return new Date(ts).toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' });
37
+ }
@@ -0,0 +1,41 @@
1
+ // reifyui/graph — public type surface (hand-authored; the source is plain-ESM React).
2
+ import type { ComponentType, ReactNode } from 'react';
3
+
4
+ /** Everything the panes ask a host for, bound to the host's API base and auth. */
5
+ export interface GraphClient {
6
+ getConnect(graphId: string): Promise<unknown>;
7
+ putConnect(graphId: string, registry: unknown): Promise<unknown>;
8
+ testConnectTool(graphId: string, tool: string, args: Record<string, unknown>): Promise<unknown>;
9
+ listConnectKeys(graphId: string): Promise<unknown[]>;
10
+ createConnectKey(graphId: string, name: string): Promise<unknown>;
11
+ revokeConnectKey(graphId: string, keyId: string): Promise<unknown>;
12
+ fetchAudit(graphId: string, params: { limit?: number; cursor?: string | null; q?: string }): Promise<unknown>;
13
+ /** Absolute URL for a gateway path (the MCP endpoint shown to the user). */
14
+ endpointUrl(path: string): string;
15
+ }
16
+ export interface ConnectPaneProps { graphId: string; client: GraphClient; liveRegistry?: unknown; }
17
+ export interface LogsPaneProps {
18
+ graphId: string;
19
+ client: GraphClient;
20
+ /** The mark shown for entries the product's own copilot wrote; a generic icon when absent. */
21
+ copilotMark?: ReactNode;
22
+ }
23
+ export const ConnectPane: ComponentType<ConnectPaneProps>;
24
+ export const LogsPane: ComponentType<LogsPaneProps>;
25
+ export const Skeleton: ComponentType<Record<string, unknown>>;
26
+ export function fmtUnits(consumption: unknown): string | null;
27
+ export function relativeTime(ts: number | string | null | undefined): string | null;
28
+ export function absoluteTime(ts: number | string | null | undefined): string | null;
29
+ export function useGraphCollab(options: Record<string, unknown>): Record<string, unknown>;
30
+ export function materializeDraft(...args: any[]): Promise<unknown>;
31
+ export function saveDraft(...args: any[]): Promise<unknown>;
32
+ /** Configure the graph transport once at boot: (path, init) => Promise<Response-like>. */
33
+ export function configureVgraph(transport: (...args: any[]) => Promise<unknown>): void;
34
+ export const vgraph: Record<string, (...args: any[]) => Promise<unknown>>;
35
+ export const DATA_TYPES: readonly string[];
36
+ export function parseAssetRef(ref: string): unknown;
37
+ export function schemaVersionNum(v: unknown): number;
38
+ export function semanticDimsFor(propName: string): number;
39
+ export function semanticIndexFor(propName: string, dims?: number): unknown;
40
+ export function semanticIndexOn(type: unknown, propName: string): unknown;
41
+ export function pollSchemaChange(...args: any[]): Promise<unknown>;
@@ -0,0 +1,14 @@
1
+ // reifyui/graph — a graph resource as a shared surface: the canvas hook that makes it live,
2
+ // the draft flow, the Connect and Logs panes, and the schema helpers they speak through.
3
+ //
4
+ // Every request the panes make goes through the client the host injects
5
+ // ({getConnect, putConnect, testConnectTool, listConnectKeys, createConnectKey,
6
+ // revokeConnectKey, fetchAudit, endpointUrl(path)}); the graph transport is configured once
7
+ // with configureVgraph(transport). Nothing here knows a host's API base or auth.
8
+ export { useGraphCollab } from './useGraphCollab.js';
9
+ export { materializeDraft, saveDraft } from './draft.js';
10
+ export { ConnectPane } from './ConnectPane.jsx';
11
+ export { LogsPane } from './LogsPane.jsx';
12
+ export { Skeleton } from './Skeleton.jsx';
13
+ export { fmtUnits, relativeTime, absoluteTime } from './format.js';
14
+ export * from './vgraph.js';