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.
- 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,634 @@
|
|
|
1
|
+
// ConnectPane — the Connect tab: this graph as an MCP server for external
|
|
2
|
+
// agents. Two stacked regions in one pane:
|
|
3
|
+
// 1. The connection card: ONE connection method (the MCP client JSON with
|
|
4
|
+
// the graph's real endpoint substituted) + the API keys as compact rows
|
|
5
|
+
// inside the same card. Progressive disclosure: with >=1 key the card
|
|
6
|
+
// collapses to a slim summary bar (endpoint, Copy config, key count,
|
|
7
|
+
// chevron); with no keys it starts expanded with the create-key callout.
|
|
8
|
+
// 2. The tools master/detail split: a slim list on the left (mono name +
|
|
9
|
+
// enabled toggle, run_query pinned first) and the modeless editor /
|
|
10
|
+
// test bench on the right (ConnectToolDetail). Below ~720px of PANE
|
|
11
|
+
// width the split goes single-pane (list <-> detail with a back
|
|
12
|
+
// control), measured on the pane so the resizable chat column counts.
|
|
13
|
+
//
|
|
14
|
+
// Registry toggles PUT optimistically with rollback; copilot changes converge
|
|
15
|
+
// live through the realtime "connect" meta key (GraphPage passes it down)
|
|
16
|
+
// with a refetch-on-focus fallback.
|
|
17
|
+
//
|
|
18
|
+
// House rules honored here: no native popups (the package's Modal only),
|
|
19
|
+
// every number from live data ("—" when absent), no internal architecture in
|
|
20
|
+
// any copy.
|
|
21
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
22
|
+
import {
|
|
23
|
+
Cable, Check, ChevronDown, Copy, KeyRound, Plus,
|
|
24
|
+
} from 'lucide-react';
|
|
25
|
+
import { CodeBlock } from '../components/CodeBlock.jsx';
|
|
26
|
+
import { relativeTime } from './format.js';
|
|
27
|
+
import { Modal } from '../components/Modal.jsx';
|
|
28
|
+
import { Skeleton } from './Skeleton.jsx';
|
|
29
|
+
import { ConnectToolDetail, RUN_QUERY_TOOL, Switch } from './ConnectToolDetail.jsx';
|
|
30
|
+
|
|
31
|
+
const NARROW_PX = 720; // pane width where the split goes single-pane
|
|
32
|
+
|
|
33
|
+
function normalizeRegistry(reg) {
|
|
34
|
+
return {
|
|
35
|
+
raw_enabled: !!reg?.raw_enabled,
|
|
36
|
+
tools: Array.isArray(reg?.tools) ? reg.tools : [],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The one connection method: MCP client JSON with the real endpoint URL. */
|
|
41
|
+
function mcpConfigJson(url) {
|
|
42
|
+
return JSON.stringify({
|
|
43
|
+
mcpServers: {
|
|
44
|
+
graph: {
|
|
45
|
+
command: 'npx',
|
|
46
|
+
args: ['-y', 'mcp-remote', url, '--header', 'Authorization: Bearer YOUR_KEY'],
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
}, null, 2);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Middle truncation for the summary bar (full URL rides in title). */
|
|
53
|
+
function truncateMiddle(s, max = 52) {
|
|
54
|
+
if (!s || s.length <= max) return s;
|
|
55
|
+
const head = Math.ceil((max - 1) * 0.6);
|
|
56
|
+
const tail = (max - 1) - head;
|
|
57
|
+
return `${s.slice(0, head)}…${s.slice(s.length - tail)}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ── small shared control ────────────────────────────────────────────────────
|
|
61
|
+
|
|
62
|
+
function CopyButton({ text, label = 'Copy', sm = true }) {
|
|
63
|
+
const [done, setDone] = useState(false);
|
|
64
|
+
const timer = useRef(null);
|
|
65
|
+
useEffect(() => () => window.clearTimeout(timer.current), []);
|
|
66
|
+
const copy = async () => {
|
|
67
|
+
try {
|
|
68
|
+
await navigator.clipboard.writeText(text);
|
|
69
|
+
} catch {
|
|
70
|
+
// Clipboard API unavailable (insecure context): selection fallback.
|
|
71
|
+
const ta = document.createElement('textarea');
|
|
72
|
+
ta.value = text;
|
|
73
|
+
ta.style.position = 'fixed';
|
|
74
|
+
ta.style.opacity = '0';
|
|
75
|
+
document.body.appendChild(ta);
|
|
76
|
+
ta.select();
|
|
77
|
+
try { document.execCommand('copy'); } catch { /* nothing more we can do */ }
|
|
78
|
+
ta.remove();
|
|
79
|
+
}
|
|
80
|
+
setDone(true);
|
|
81
|
+
window.clearTimeout(timer.current);
|
|
82
|
+
timer.current = window.setTimeout(() => setDone(false), 1600);
|
|
83
|
+
};
|
|
84
|
+
return (
|
|
85
|
+
<button type="button" className={'btn' + (sm ? ' sm' : '')} onClick={copy}>
|
|
86
|
+
{done ? <Check size={13} /> : <Copy size={13} />}
|
|
87
|
+
{done ? 'Copied' : label}
|
|
88
|
+
</button>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ── connection card ─────────────────────────────────────────────────────────
|
|
93
|
+
|
|
94
|
+
function KeyRow({ k, onRevoke }) {
|
|
95
|
+
return (
|
|
96
|
+
<div className="cn-key-row">
|
|
97
|
+
<span className="cn-key-name" title={k.name}><KeyRound size={13} aria-hidden="true" />{k.name || '—'}</span>
|
|
98
|
+
<code className="mono cn-key-prefix">{k.prefix ? `${k.prefix}…` : '—'}</code>
|
|
99
|
+
<span className="cn-key-meta">
|
|
100
|
+
<span className="cn-key-lbl">Created</span> {relativeTime(k.created_at) || '—'}
|
|
101
|
+
</span>
|
|
102
|
+
<span className="cn-key-meta">
|
|
103
|
+
<span className="cn-key-lbl">Last used</span> {relativeTime(k.last_used) || '—'}
|
|
104
|
+
</span>
|
|
105
|
+
<button type="button" className="btn sm danger cn-key-revoke" onClick={onRevoke}>Revoke</button>
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function ConnectionCard({ url, keys, expanded, onToggle, onCreateKey, onRevoke }) {
|
|
111
|
+
const hasKeys = keys.length > 0;
|
|
112
|
+
const config = url ? mcpConfigJson(url) : '';
|
|
113
|
+
const keyCount = `${keys.length} ${keys.length === 1 ? 'key' : 'keys'}`;
|
|
114
|
+
return (
|
|
115
|
+
<section className="cn-conn">
|
|
116
|
+
<div className="cn-conn-bar">
|
|
117
|
+
<button
|
|
118
|
+
type="button"
|
|
119
|
+
className="cn-conn-toggle"
|
|
120
|
+
aria-expanded={expanded}
|
|
121
|
+
onClick={onToggle}
|
|
122
|
+
>
|
|
123
|
+
<span className={'cn-conn-chev' + (expanded ? ' open' : '')} aria-hidden="true"><ChevronDown size={15} /></span>
|
|
124
|
+
<Cable size={14} aria-hidden="true" />
|
|
125
|
+
<code className="mono cn-conn-url" title={url || undefined}>{url ? truncateMiddle(url) : '—'}</code>
|
|
126
|
+
<span className="cn-conn-count num">{keyCount}</span>
|
|
127
|
+
</button>
|
|
128
|
+
{url && <CopyButton text={config} label="Copy config" />}
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
{expanded && (
|
|
132
|
+
<div className="cn-conn-body">
|
|
133
|
+
{url ? <CodeBlock code={config} language="json" className="cn-code" /> : <div className="cn-hint">—</div>}
|
|
134
|
+
<p className="cn-caption">
|
|
135
|
+
Works with Claude Desktop, Claude Code, and any MCP client. Replace YOUR_KEY with an API key.
|
|
136
|
+
</p>
|
|
137
|
+
{hasKeys ? (
|
|
138
|
+
<>
|
|
139
|
+
<div className="cn-keys-h">
|
|
140
|
+
<h4>API keys</h4>
|
|
141
|
+
<button type="button" className="btn sm" onClick={onCreateKey}>
|
|
142
|
+
<Plus size={13} /> Create key
|
|
143
|
+
</button>
|
|
144
|
+
</div>
|
|
145
|
+
<div className="cn-keys">
|
|
146
|
+
{keys.map((k) => <KeyRow key={k.id} k={k} onRevoke={() => onRevoke(k)} />)}
|
|
147
|
+
</div>
|
|
148
|
+
</>
|
|
149
|
+
) : (
|
|
150
|
+
<div className="cn-callout">
|
|
151
|
+
<KeyRound size={14} aria-hidden="true" />
|
|
152
|
+
<span>Agents need an API key to connect. Create your first key to get started.</span>
|
|
153
|
+
<button type="button" className="btn sm primary" onClick={onCreateKey}>Create key</button>
|
|
154
|
+
</div>
|
|
155
|
+
)}
|
|
156
|
+
</div>
|
|
157
|
+
)}
|
|
158
|
+
</section>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ── key dialogs (flow unchanged: name -> POST -> secret shown ONCE) ─────────
|
|
163
|
+
|
|
164
|
+
function CreateKeyDialog({ busy, error, onSubmit, onClose }) {
|
|
165
|
+
const [name, setName] = useState('');
|
|
166
|
+
const ref = useRef(null);
|
|
167
|
+
useEffect(() => { ref.current?.focus(); }, []);
|
|
168
|
+
const ok = name.trim().length > 0;
|
|
169
|
+
return (
|
|
170
|
+
<Modal open onClose={busy ? undefined : onClose} title="Create API key" width={420} classNames={{ root: 'cn-dlg' }}>
|
|
171
|
+
<div className="cn-dlg-body">Name the key after the agent or place that will use it, so you can tell keys apart later.</div>
|
|
172
|
+
<form onSubmit={(e) => { e.preventDefault(); if (ok && !busy) onSubmit(name.trim()); }}>
|
|
173
|
+
<input
|
|
174
|
+
ref={ref}
|
|
175
|
+
className="input"
|
|
176
|
+
value={name}
|
|
177
|
+
onChange={(e) => setName(e.target.value)}
|
|
178
|
+
placeholder="e.g. claude-desktop"
|
|
179
|
+
maxLength={80}
|
|
180
|
+
/>
|
|
181
|
+
{error && <div className="cn-err">{error}</div>}
|
|
182
|
+
<div className="cn-dlg-foot">
|
|
183
|
+
<button type="button" className="btn" onClick={onClose} disabled={busy}>Cancel</button>
|
|
184
|
+
<button type="submit" className="btn primary" disabled={!ok || busy}>
|
|
185
|
+
{busy ? 'Creating…' : 'Create key'}
|
|
186
|
+
</button>
|
|
187
|
+
</div>
|
|
188
|
+
</form>
|
|
189
|
+
</Modal>
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function SecretDialog({ secret, onClose }) {
|
|
194
|
+
return (
|
|
195
|
+
<Modal open onClose={onClose} title="Your new API key" width={480} classNames={{ root: 'cn-dlg' }}>
|
|
196
|
+
<div className="cn-dlg-body">
|
|
197
|
+
Copy this key now and store it somewhere safe. For your security, it will not be shown again.
|
|
198
|
+
</div>
|
|
199
|
+
<div className="cn-secret">
|
|
200
|
+
<code className="mono">{secret.key}</code>
|
|
201
|
+
</div>
|
|
202
|
+
<div className="cn-dlg-foot">
|
|
203
|
+
<CopyButton text={secret.key} label="Copy key" sm={false} />
|
|
204
|
+
<button type="button" className="btn primary" onClick={onClose}>Done</button>
|
|
205
|
+
</div>
|
|
206
|
+
</Modal>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// A confirmation whose action runs while it stays open (revoke, delete, discard): the body
|
|
211
|
+
// is the pane's own, so a failed action is reported right there.
|
|
212
|
+
function ConfirmModal({ title, body, confirmLabel = 'Delete', busy, onConfirm, onClose }) {
|
|
213
|
+
return (
|
|
214
|
+
<Modal open onClose={busy ? undefined : onClose} title={title} width={420} classNames={{ root: 'cn-dlg' }}>
|
|
215
|
+
<div className="cn-dlg-body">{body}</div>
|
|
216
|
+
<div className="cn-dlg-foot">
|
|
217
|
+
<button type="button" className="btn" onClick={onClose} disabled={busy}>Cancel</button>
|
|
218
|
+
<button type="button" className="btn danger" onClick={onConfirm} disabled={busy}>
|
|
219
|
+
{busy ? `${confirmLabel}…` : confirmLabel}
|
|
220
|
+
</button>
|
|
221
|
+
</div>
|
|
222
|
+
</Modal>
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// ── tools list (master side) ────────────────────────────────────────────────
|
|
227
|
+
|
|
228
|
+
function ToolListRow({ name, builtin, enabled, selected, busy, onSelect, onToggle }) {
|
|
229
|
+
return (
|
|
230
|
+
<div
|
|
231
|
+
role="option"
|
|
232
|
+
aria-selected={selected}
|
|
233
|
+
tabIndex={0}
|
|
234
|
+
className={'cn-lrow' + (selected ? ' sel' : '') + (enabled ? '' : ' off')}
|
|
235
|
+
onClick={onSelect}
|
|
236
|
+
onKeyDown={(e) => {
|
|
237
|
+
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onSelect(); }
|
|
238
|
+
}}
|
|
239
|
+
>
|
|
240
|
+
<code className="mono cn-lrow-name" title={name}>{name}</code>
|
|
241
|
+
{builtin && <span className="pill brand">Built in</span>}
|
|
242
|
+
{/* Toggle clicks must not change the selection. */}
|
|
243
|
+
<span
|
|
244
|
+
className="cn-lrow-toggle"
|
|
245
|
+
onClick={(e) => e.stopPropagation()}
|
|
246
|
+
onKeyDown={(e) => e.stopPropagation()}
|
|
247
|
+
>
|
|
248
|
+
<Switch checked={!!enabled} disabled={busy} onChange={onToggle} label={`Enable ${name}`} />
|
|
249
|
+
</span>
|
|
250
|
+
</div>
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function ToolList({ registry, sel, busy, onSelect, onToggleRaw, onToggleTool, onNew }) {
|
|
255
|
+
return (
|
|
256
|
+
<div className="cn-list">
|
|
257
|
+
<div className="cn-list-h">
|
|
258
|
+
<button type="button" className="btn sm primary cn-new-tool" onClick={onNew}>
|
|
259
|
+
<Plus size={13} /> New tool
|
|
260
|
+
</button>
|
|
261
|
+
</div>
|
|
262
|
+
<div className="cn-list-scroll scroll" role="listbox" aria-label="Tools">
|
|
263
|
+
<ToolListRow
|
|
264
|
+
name={RUN_QUERY_TOOL}
|
|
265
|
+
builtin
|
|
266
|
+
enabled={registry.raw_enabled}
|
|
267
|
+
selected={sel.type === 'builtin'}
|
|
268
|
+
busy={busy}
|
|
269
|
+
onSelect={() => onSelect({ type: 'builtin' })}
|
|
270
|
+
onToggle={onToggleRaw}
|
|
271
|
+
/>
|
|
272
|
+
{registry.tools.map((t) => (
|
|
273
|
+
<ToolListRow
|
|
274
|
+
key={t.name}
|
|
275
|
+
name={t.name}
|
|
276
|
+
enabled={!!t.enabled}
|
|
277
|
+
selected={sel.type === 'tool' && sel.name === t.name}
|
|
278
|
+
busy={busy}
|
|
279
|
+
onSelect={() => onSelect({ type: 'tool', name: t.name })}
|
|
280
|
+
onToggle={(v) => onToggleTool(t.name, v)}
|
|
281
|
+
/>
|
|
282
|
+
))}
|
|
283
|
+
{sel.type === 'draft' && (
|
|
284
|
+
<div role="option" aria-selected="true" className="cn-lrow sel cn-lrow-draft" tabIndex={0}>
|
|
285
|
+
<span className="cn-lrow-name">New tool</span>
|
|
286
|
+
</div>
|
|
287
|
+
)}
|
|
288
|
+
{registry.tools.length === 0 && (
|
|
289
|
+
<div className="cn-list-empty">
|
|
290
|
+
A tool is a named, parameterized query agents can call safely. Define one
|
|
291
|
+
here, or ask your copilot to create it for you.
|
|
292
|
+
</div>
|
|
293
|
+
)}
|
|
294
|
+
</div>
|
|
295
|
+
</div>
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function ConnectSkeleton() {
|
|
300
|
+
return (
|
|
301
|
+
<div className="cn-skel" aria-busy="true" aria-label="Loading Connect">
|
|
302
|
+
<Skeleton w="100%" h={38} radius={9} />
|
|
303
|
+
<div className="cn-skel-split">
|
|
304
|
+
<div className="cn-skel-col">
|
|
305
|
+
<Skeleton w="100%" h={30} radius={9} style={{ marginBottom: 8 }} />
|
|
306
|
+
<Skeleton w="100%" h={30} radius={9} style={{ marginBottom: 8 }} />
|
|
307
|
+
<Skeleton w="100%" h={30} radius={9} />
|
|
308
|
+
</div>
|
|
309
|
+
<div className="cn-skel-col">
|
|
310
|
+
<Skeleton w="42%" h={16} style={{ marginBottom: 12 }} />
|
|
311
|
+
<Skeleton w="100%" h={90} radius={9} style={{ marginBottom: 10 }} />
|
|
312
|
+
<Skeleton w="100%" h={90} radius={9} />
|
|
313
|
+
</div>
|
|
314
|
+
</div>
|
|
315
|
+
</div>
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// ── the pane ────────────────────────────────────────────────────────────────
|
|
320
|
+
|
|
321
|
+
/** `client`: {getConnect, putConnect, listConnectKeys, createConnectKey, revokeConnectKey,
|
|
322
|
+
* testConnectTool, endpointUrl(path)} bound to the host's API and auth. */
|
|
323
|
+
export function ConnectPane({ graphId, liveRegistry, client }) {
|
|
324
|
+
const [registry, setRegistry] = useState(null);
|
|
325
|
+
const [keys, setKeys] = useState(null);
|
|
326
|
+
const [loading, setLoading] = useState(true);
|
|
327
|
+
const [error, setError] = useState('');
|
|
328
|
+
const [saveError, setSaveError] = useState('');
|
|
329
|
+
const [busy, setBusy] = useState(false); // a registry PUT in flight
|
|
330
|
+
|
|
331
|
+
// Selection: builtin run_query (pinned first, the on-load default), one
|
|
332
|
+
// defined tool by name, or an unsaved draft.
|
|
333
|
+
const [sel, setSel] = useState({ type: 'builtin' });
|
|
334
|
+
const [showDetail, setShowDetail] = useState(false); // narrow single-pane: list <-> detail
|
|
335
|
+
const [narrow, setNarrow] = useState(false);
|
|
336
|
+
const dirtyRef = useRef({ dirty: false, label: '' }); // the detail form's unsaved-edit state
|
|
337
|
+
|
|
338
|
+
// Connection card disclosure: collapsed by default once keys exist,
|
|
339
|
+
// expanded when there are none (component state, not persisted).
|
|
340
|
+
const [cardExpanded, setCardExpanded] = useState(false);
|
|
341
|
+
const cardInitRef = useRef(false);
|
|
342
|
+
|
|
343
|
+
const [confirm, setConfirm] = useState(null); // {kind:'revoke',key} | {kind:'delete',tool} | {kind:'discard',next,label}
|
|
344
|
+
const [confirmBusy, setConfirmBusy] = useState(false);
|
|
345
|
+
const [confirmError, setConfirmError] = useState('');
|
|
346
|
+
const [creatingKey, setCreatingKey] = useState(false);
|
|
347
|
+
const [createBusy, setCreateBusy] = useState(false);
|
|
348
|
+
const [createError, setCreateError] = useState('');
|
|
349
|
+
const [secret, setSecret] = useState(null); // {id, name, key} shown ONCE
|
|
350
|
+
// The endpoint PATH comes from the server (it names the graph's data-plane
|
|
351
|
+
// id, which the client must not derive) — realtime registry pushes never
|
|
352
|
+
// carry it, so it lives outside the registry state.
|
|
353
|
+
const [endpoint, setEndpoint] = useState('');
|
|
354
|
+
|
|
355
|
+
const registryRef = useRef(null);
|
|
356
|
+
registryRef.current = registry;
|
|
357
|
+
const paneRef = useRef(null);
|
|
358
|
+
|
|
359
|
+
const load = useCallback(async () => {
|
|
360
|
+
try {
|
|
361
|
+
const [reg, ks] = await Promise.all([client.getConnect(graphId), client.listConnectKeys(graphId)]);
|
|
362
|
+
if (reg && typeof reg.endpoint === 'string') setEndpoint(reg.endpoint);
|
|
363
|
+
setRegistry(normalizeRegistry(reg));
|
|
364
|
+
setKeys(ks);
|
|
365
|
+
if (!cardInitRef.current) {
|
|
366
|
+
cardInitRef.current = true;
|
|
367
|
+
setCardExpanded((ks || []).length === 0);
|
|
368
|
+
}
|
|
369
|
+
setError('');
|
|
370
|
+
} catch (e) {
|
|
371
|
+
setError(e?.message || 'Could not load Connect settings.');
|
|
372
|
+
} finally {
|
|
373
|
+
setLoading(false);
|
|
374
|
+
}
|
|
375
|
+
}, [graphId, client]);
|
|
376
|
+
|
|
377
|
+
useEffect(() => { load(); }, [load]);
|
|
378
|
+
|
|
379
|
+
// Fallback convergence: refetch when the tab regains visibility/focus.
|
|
380
|
+
useEffect(() => {
|
|
381
|
+
const onVis = () => { if (document.visibilityState !== 'hidden') load(); };
|
|
382
|
+
window.addEventListener('focus', onVis);
|
|
383
|
+
document.addEventListener('visibilitychange', onVis);
|
|
384
|
+
return () => {
|
|
385
|
+
window.removeEventListener('focus', onVis);
|
|
386
|
+
document.removeEventListener('visibilitychange', onVis);
|
|
387
|
+
};
|
|
388
|
+
}, [load]);
|
|
389
|
+
|
|
390
|
+
// Live convergence: a registry published on the graph's realtime channel
|
|
391
|
+
// (copilot connect_* tools, another member's save) is fresher truth.
|
|
392
|
+
useEffect(() => {
|
|
393
|
+
if (liveRegistry && (Array.isArray(liveRegistry.tools) || 'raw_enabled' in liveRegistry)) {
|
|
394
|
+
setRegistry(normalizeRegistry(liveRegistry));
|
|
395
|
+
}
|
|
396
|
+
}, [liveRegistry]);
|
|
397
|
+
|
|
398
|
+
// Single-pane threshold, measured on the PANE (the resizable chat column
|
|
399
|
+
// changes pane width without a viewport resize; 200% zoom halves it too).
|
|
400
|
+
useEffect(() => {
|
|
401
|
+
const el = paneRef.current;
|
|
402
|
+
if (!el || typeof ResizeObserver === 'undefined') return undefined;
|
|
403
|
+
const ro = new ResizeObserver((entries) => {
|
|
404
|
+
const w = entries[0]?.contentRect?.width;
|
|
405
|
+
if (typeof w === 'number') setNarrow(w < NARROW_PX);
|
|
406
|
+
});
|
|
407
|
+
ro.observe(el);
|
|
408
|
+
return () => ro.disconnect();
|
|
409
|
+
}, []);
|
|
410
|
+
|
|
411
|
+
// A selected tool deleted elsewhere (realtime push) falls back to the
|
|
412
|
+
// pinned built-in — unless the form holds unsaved edits.
|
|
413
|
+
useEffect(() => {
|
|
414
|
+
if (!registry || sel.type !== 'tool') return;
|
|
415
|
+
if (!registry.tools.some((t) => t.name === sel.name) && !dirtyRef.current.dirty) {
|
|
416
|
+
setSel({ type: 'builtin' });
|
|
417
|
+
}
|
|
418
|
+
}, [registry, sel]);
|
|
419
|
+
|
|
420
|
+
/** Optimistic whole-registry save with rollback (toggles, deletes). */
|
|
421
|
+
const saveRegistry = useCallback(async (next) => {
|
|
422
|
+
const prev = registryRef.current;
|
|
423
|
+
setRegistry(next);
|
|
424
|
+
setSaveError('');
|
|
425
|
+
setBusy(true);
|
|
426
|
+
try {
|
|
427
|
+
const saved = await client.putConnect(graphId, next);
|
|
428
|
+
if (saved && (Array.isArray(saved.tools) || 'raw_enabled' in saved)) {
|
|
429
|
+
setRegistry(normalizeRegistry(saved));
|
|
430
|
+
}
|
|
431
|
+
return true;
|
|
432
|
+
} catch (e) {
|
|
433
|
+
setRegistry(prev);
|
|
434
|
+
setSaveError(e?.message || 'Could not save your change.');
|
|
435
|
+
return false;
|
|
436
|
+
} finally {
|
|
437
|
+
setBusy(false);
|
|
438
|
+
}
|
|
439
|
+
}, [graphId, client]);
|
|
440
|
+
|
|
441
|
+
const toggleRaw = (v) => saveRegistry({ ...registryRef.current, raw_enabled: v });
|
|
442
|
+
const toggleTool = (name, v) => saveRegistry({
|
|
443
|
+
...registryRef.current,
|
|
444
|
+
tools: registryRef.current.tools.map((t) => (t.name === name ? { ...t, enabled: v } : t)),
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
/** Detail save: NOT optimistic — awaited so validation errors land back in
|
|
448
|
+
* the form per-field. prevName is null on create, ≠ def.name on rename.
|
|
449
|
+
* The selection follows the saved (possibly renamed) tool. */
|
|
450
|
+
const saveTool = useCallback(async (def, prevName) => {
|
|
451
|
+
const cur = registryRef.current;
|
|
452
|
+
const rest = cur.tools.filter((t) => t.name !== prevName && t.name !== def.name);
|
|
453
|
+
const kept = cur.tools.find((t) => t.name === prevName);
|
|
454
|
+
const idx = cur.tools.findIndex((t) => t.name === prevName);
|
|
455
|
+
const tools = [...rest];
|
|
456
|
+
tools.splice(idx >= 0 ? idx : tools.length, 0, { ...kept, ...def });
|
|
457
|
+
const saved = await client.putConnect(graphId, { ...cur, tools });
|
|
458
|
+
setRegistry(saved && (Array.isArray(saved.tools) || 'raw_enabled' in saved)
|
|
459
|
+
? normalizeRegistry(saved)
|
|
460
|
+
: { ...cur, tools });
|
|
461
|
+
setSaveError('');
|
|
462
|
+
setSel({ type: 'tool', name: def.name });
|
|
463
|
+
}, [graphId, client]);
|
|
464
|
+
|
|
465
|
+
// ── selection with an unsaved-edits guard ────────────────────────────────
|
|
466
|
+
const sameSel = (a, b) => a.type === b.type
|
|
467
|
+
&& (a.type !== 'tool' || a.name === b.name)
|
|
468
|
+
&& (a.type !== 'draft' || a.nonce === b.nonce);
|
|
469
|
+
const applySelect = useCallback((next) => {
|
|
470
|
+
setSel(next);
|
|
471
|
+
setShowDetail(true);
|
|
472
|
+
}, []);
|
|
473
|
+
const requestSelect = useCallback((next) => {
|
|
474
|
+
if (sameSel(next, sel)) { setShowDetail(true); return; }
|
|
475
|
+
if (dirtyRef.current.dirty) {
|
|
476
|
+
setConfirmError('');
|
|
477
|
+
setConfirm({ kind: 'discard', next, label: dirtyRef.current.label });
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
applySelect(next);
|
|
481
|
+
}, [sel, applySelect]);
|
|
482
|
+
const onDirtyChange = useCallback((dirty, label) => {
|
|
483
|
+
dirtyRef.current = { dirty, label };
|
|
484
|
+
}, []);
|
|
485
|
+
|
|
486
|
+
const doConfirm = async () => {
|
|
487
|
+
if (!confirm) return;
|
|
488
|
+
if (confirm.kind === 'discard') {
|
|
489
|
+
applySelect(confirm.next);
|
|
490
|
+
setConfirm(null);
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
setConfirmBusy(true);
|
|
494
|
+
setConfirmError('');
|
|
495
|
+
try {
|
|
496
|
+
if (confirm.kind === 'revoke') {
|
|
497
|
+
await client.revokeConnectKey(graphId, confirm.key.id);
|
|
498
|
+
setKeys(await client.listConnectKeys(graphId));
|
|
499
|
+
} else {
|
|
500
|
+
const cur = registryRef.current;
|
|
501
|
+
const ok = await saveRegistry({ ...cur, tools: cur.tools.filter((t) => t.name !== confirm.tool.name) });
|
|
502
|
+
if (!ok) throw new Error('Could not delete this tool. Please try again.');
|
|
503
|
+
if (sel.type === 'tool' && sel.name === confirm.tool.name) {
|
|
504
|
+
setSel({ type: 'builtin' });
|
|
505
|
+
setShowDetail(false);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
setConfirm(null);
|
|
509
|
+
} catch (e) {
|
|
510
|
+
setConfirmError(e?.message || 'Something went wrong. Please try again.');
|
|
511
|
+
} finally {
|
|
512
|
+
setConfirmBusy(false);
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
const doCreateKey = async (name) => {
|
|
517
|
+
setCreateBusy(true);
|
|
518
|
+
setCreateError('');
|
|
519
|
+
try {
|
|
520
|
+
const minted = await client.createConnectKey(graphId, name);
|
|
521
|
+
setCreatingKey(false);
|
|
522
|
+
setSecret(minted);
|
|
523
|
+
setKeys(await client.listConnectKeys(graphId));
|
|
524
|
+
} catch (e) {
|
|
525
|
+
setCreateError(e?.message || 'Could not create the key. Please try again.');
|
|
526
|
+
} finally {
|
|
527
|
+
setCreateBusy(false);
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
const url = endpoint ? client.endpointUrl(endpoint) : '';
|
|
532
|
+
const selTool = sel.type === 'tool'
|
|
533
|
+
? (registry?.tools || []).find((t) => t.name === sel.name) || null
|
|
534
|
+
: null;
|
|
535
|
+
const detailKey = sel.type === 'draft' ? `draft:${sel.nonce}`
|
|
536
|
+
: sel.type === 'builtin' ? 'builtin'
|
|
537
|
+
: `tool:${sel.name}`;
|
|
538
|
+
|
|
539
|
+
return (
|
|
540
|
+
<div className="gp-placeholder cn-root">
|
|
541
|
+
<div className="pane" style={{ flex: 1 }} ref={paneRef}>
|
|
542
|
+
{loading ? (
|
|
543
|
+
<ConnectSkeleton />
|
|
544
|
+
) : error ? (
|
|
545
|
+
<div className="pane-empty">
|
|
546
|
+
<Cable size={28} />
|
|
547
|
+
<div className="big">Could not load Connect</div>
|
|
548
|
+
<div>{error}</div>
|
|
549
|
+
<button type="button" className="btn sm" onClick={() => { setLoading(true); load(); }}>Try again</button>
|
|
550
|
+
</div>
|
|
551
|
+
) : (
|
|
552
|
+
<div className="cn-body scroll">
|
|
553
|
+
<ConnectionCard
|
|
554
|
+
url={url}
|
|
555
|
+
keys={keys || []}
|
|
556
|
+
expanded={cardExpanded}
|
|
557
|
+
onToggle={() => setCardExpanded((v) => !v)}
|
|
558
|
+
onCreateKey={() => { setCreateError(''); setCreatingKey(true); }}
|
|
559
|
+
onRevoke={(k) => { setConfirmError(''); setConfirm({ kind: 'revoke', key: k }); }}
|
|
560
|
+
/>
|
|
561
|
+
|
|
562
|
+
{saveError && <div className="cn-err cn-err-top">{saveError}</div>}
|
|
563
|
+
|
|
564
|
+
<div className={'cn-split' + (narrow ? ' narrow' : '') + (narrow && showDetail ? ' show-detail' : '')}>
|
|
565
|
+
<ToolList
|
|
566
|
+
registry={registry}
|
|
567
|
+
sel={sel}
|
|
568
|
+
busy={busy}
|
|
569
|
+
onSelect={requestSelect}
|
|
570
|
+
onToggleRaw={toggleRaw}
|
|
571
|
+
onToggleTool={toggleTool}
|
|
572
|
+
onNew={() => requestSelect({ type: 'draft', nonce: Date.now() })}
|
|
573
|
+
/>
|
|
574
|
+
{(sel.type === 'builtin' || sel.type === 'draft' || selTool || dirtyRef.current.dirty) ? (
|
|
575
|
+
<ConnectToolDetail
|
|
576
|
+
key={detailKey}
|
|
577
|
+
client={client}
|
|
578
|
+
graphId={graphId}
|
|
579
|
+
tool={selTool}
|
|
580
|
+
builtin={sel.type === 'builtin'}
|
|
581
|
+
isDraft={sel.type === 'draft'}
|
|
582
|
+
enabled={sel.type === 'builtin' ? registry.raw_enabled : !!selTool?.enabled}
|
|
583
|
+
busy={busy}
|
|
584
|
+
takenNames={new Set([RUN_QUERY_TOOL, ...(registry?.tools || []).map((t) => t.name)])}
|
|
585
|
+
narrow={narrow}
|
|
586
|
+
onBack={() => setShowDetail(false)}
|
|
587
|
+
onToggle={sel.type === 'builtin' ? toggleRaw : (v) => toggleTool(sel.name, v)}
|
|
588
|
+
onSave={saveTool}
|
|
589
|
+
onDelete={() => { setConfirmError(''); setConfirm({ kind: 'delete', tool: selTool }); }}
|
|
590
|
+
onDirtyChange={onDirtyChange}
|
|
591
|
+
/>
|
|
592
|
+
) : (
|
|
593
|
+
<div className="cn-detail">
|
|
594
|
+
<div className="pane-empty">Select a tool to edit and test it.</div>
|
|
595
|
+
</div>
|
|
596
|
+
)}
|
|
597
|
+
</div>
|
|
598
|
+
</div>
|
|
599
|
+
)}
|
|
600
|
+
</div>
|
|
601
|
+
|
|
602
|
+
{confirm && (
|
|
603
|
+
<ConfirmModal
|
|
604
|
+
title={confirm.kind === 'revoke' ? `Revoke "${confirm.key.name}"?`
|
|
605
|
+
: confirm.kind === 'delete' ? `Delete "${confirm.tool.name}"?`
|
|
606
|
+
: `Discard unsaved changes to "${confirm.label}"?`}
|
|
607
|
+
body={(
|
|
608
|
+
<>
|
|
609
|
+
{confirm.kind === 'revoke'
|
|
610
|
+
? 'Agents using this key will lose access immediately. This cannot be undone.'
|
|
611
|
+
: confirm.kind === 'delete'
|
|
612
|
+
? 'Agents will no longer be able to call this tool. This cannot be undone.'
|
|
613
|
+
: 'Your edits have not been saved and will be lost.'}
|
|
614
|
+
{confirmError && <div className="cn-err">{confirmError}</div>}
|
|
615
|
+
</>
|
|
616
|
+
)}
|
|
617
|
+
confirmLabel={confirm.kind === 'revoke' ? 'Revoke' : confirm.kind === 'delete' ? 'Delete' : 'Discard'}
|
|
618
|
+
busy={confirmBusy}
|
|
619
|
+
onConfirm={doConfirm}
|
|
620
|
+
onClose={() => setConfirm(null)}
|
|
621
|
+
/>
|
|
622
|
+
)}
|
|
623
|
+
{creatingKey && (
|
|
624
|
+
<CreateKeyDialog
|
|
625
|
+
busy={createBusy}
|
|
626
|
+
error={createError}
|
|
627
|
+
onSubmit={doCreateKey}
|
|
628
|
+
onClose={() => setCreatingKey(false)}
|
|
629
|
+
/>
|
|
630
|
+
)}
|
|
631
|
+
{secret && <SecretDialog secret={secret} onClose={() => setSecret(null)} />}
|
|
632
|
+
</div>
|
|
633
|
+
);
|
|
634
|
+
}
|