reifyui 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +29 -0
  2. package/dist/chart.js +2 -0
  3. package/dist/chart.js.map +1 -1
  4. package/dist/chunk-EL2DHWOH.js +1710 -0
  5. package/dist/chunk-EL2DHWOH.js.map +1 -0
  6. package/dist/chunk-J633KV57.js +41 -0
  7. package/dist/chunk-J633KV57.js.map +1 -0
  8. package/dist/chunk-J7SECRIG.js +295 -0
  9. package/dist/chunk-J7SECRIG.js.map +1 -0
  10. package/dist/chunk-PIRPLH2Z.js +231 -0
  11. package/dist/chunk-PIRPLH2Z.js.map +1 -0
  12. package/dist/chunk-PZ5AY32C.js +10 -0
  13. package/dist/chunk-PZ5AY32C.js.map +1 -0
  14. package/dist/chunk-UKG4Z6QK.js +130 -0
  15. package/dist/chunk-UKG4Z6QK.js.map +1 -0
  16. package/dist/chunk-ZYWE47EO.js +19 -0
  17. package/dist/chunk-ZYWE47EO.js.map +1 -0
  18. package/dist/collab.cjs +169 -0
  19. package/dist/collab.cjs.map +1 -0
  20. package/dist/collab.d.ts +30 -0
  21. package/dist/collab.js +18 -0
  22. package/dist/collab.js.map +1 -0
  23. package/dist/graph.cjs +2244 -0
  24. package/dist/graph.cjs.map +1 -0
  25. package/dist/graph.d.ts +41 -0
  26. package/dist/graph.js +1870 -0
  27. package/dist/graph.js.map +1 -0
  28. package/dist/harness.js +1 -0
  29. package/dist/harness.js.map +1 -1
  30. package/dist/index.cjs +1699 -817
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.ts +3 -0
  33. package/dist/index.js +680 -1769
  34. package/dist/index.js.map +1 -1
  35. package/dist/sheet-doc.cjs +235 -0
  36. package/dist/sheet-doc.cjs.map +1 -0
  37. package/dist/sheet-doc.d.ts +16 -0
  38. package/dist/sheet-doc.js +20 -0
  39. package/dist/sheet-doc.js.map +1 -0
  40. package/dist/sheet.cjs +2322 -0
  41. package/dist/sheet.cjs.map +1 -0
  42. package/dist/sheet.d.ts +23 -0
  43. package/dist/sheet.js +237 -0
  44. package/dist/sheet.js.map +1 -0
  45. package/dist/slides.js +2 -0
  46. package/dist/slides.js.map +1 -1
  47. package/package.json +34 -2
  48. package/src/auth/client.js +4 -2
  49. package/src/collab/colors.js +18 -0
  50. package/src/collab/index.d.ts +30 -0
  51. package/src/collab/index.js +8 -0
  52. package/src/collab/keepAlive.js +34 -0
  53. package/src/collab/useLiveDoc.js +76 -0
  54. package/src/components/CascadeMenu.jsx +9 -3
  55. package/src/components/Composer.jsx +37 -3
  56. package/src/components/resizable.jsx +82 -12
  57. package/src/graph/ConnectPane.jsx +634 -0
  58. package/src/graph/ConnectToolDetail.jsx +565 -0
  59. package/src/graph/LogsPane.jsx +328 -0
  60. package/src/graph/Skeleton.jsx +13 -0
  61. package/src/graph/draft.js +108 -0
  62. package/src/graph/format.js +37 -0
  63. package/src/graph/index.d.ts +41 -0
  64. package/src/graph/index.js +14 -0
  65. package/src/graph/useGraphCollab.js +299 -0
  66. package/src/graph/vgraph.js +215 -0
  67. package/src/index.d.ts +3 -0
  68. package/src/index.js +4 -1
  69. package/src/mention/MentionInput.jsx +420 -0
  70. package/src/mention/mentionModel.js +177 -0
  71. package/src/sheet/RunStrip.jsx +57 -0
  72. package/src/sheet/SheetGrid.jsx +448 -423
  73. package/src/sheet/doc.d.ts +16 -0
  74. package/src/sheet/index.d.ts +23 -0
  75. package/src/sheet/index.js +10 -0
  76. package/src/sheet/sheetDoc.js +203 -0
  77. package/src/sheet/useSheetCollab.js +102 -0
  78. package/src/sheet/useSheetRun.js +80 -0
  79. package/styles/chat.css +2 -0
  80. package/styles/graph.css +395 -0
  81. package/styles/mention.css +79 -0
  82. package/styles/sheet.css +156 -112
@@ -0,0 +1,565 @@
1
+ // ConnectToolDetail — the modeless right-hand pane of the Connect tab's tools
2
+ // (host-agnostic: the graph service is reached through the injected `client`).
3
+ // split: one tool's definition editor and an always-visible "Try it" bench.
4
+ // Replaces the old ConnectToolEditor + ConnectTestRunner dialogs; the form,
5
+ // validation and test logic carried over intact, only the modality changed.
6
+ //
7
+ // Three shapes:
8
+ // - defined tool: Definition section (name, description, params table,
9
+ // query) with per-field validation mapped from PUT 400 problems, one
10
+ // primary Save (disabled until dirty), then Try it, then a quiet
11
+ // destructive "Delete tool" text button.
12
+ // - built-in run_query: fixed description + Try it with a query textarea
13
+ // (no Definition, no delete).
14
+ // - draft (new tool): empty Definition, focus in name, Save creates.
15
+ // Nothing saved yet, so no Try it and no delete.
16
+ //
17
+ // Dirty tracking: the form is compared against the saved baseline; the parent
18
+ // hears about it (onDirtyChange) to guard selection switches. Realtime
19
+ // registry pushes re-sync a CLEAN form to the fresh tool; a dirty form keeps
20
+ // the user's edits. "Try it" always runs the SAVED tool (POST /connect/test
21
+ // by name) — a dirty form shows a quiet note next to Run.
22
+ import { useEffect, useMemo, useRef, useState } from 'react';
23
+ import { ArrowLeft, ChevronDown, Play, Plus, Trash2 } from 'lucide-react';
24
+ import { CodeBlock } from '../components/CodeBlock.jsx';
25
+ import { fmtUnits } from './format.js';
26
+
27
+ export const RUN_QUERY_TOOL = 'run_query';
28
+ export const RUN_QUERY_DESCRIPTION =
29
+ 'Run any query. Lets a connected agent read and change anything in this graph '
30
+ + 'with free-form queries. Turn it off to limit agents to the tools you define.';
31
+
32
+ const NAME_RE = /^[a-z][a-z0-9_]{0,63}$/;
33
+ const NAME_HINT = 'Lowercase letters, digits and underscores, starting with a letter.';
34
+ const PARAM_TYPES = ['string', 'number', 'boolean'];
35
+
36
+ // ── shared toggle (list rows + detail header import it from here) ──────────
37
+ export function Switch({ checked, onChange, disabled, label }) {
38
+ return (
39
+ <label className="switch">
40
+ <input
41
+ type="checkbox"
42
+ checked={checked}
43
+ disabled={disabled}
44
+ onChange={(e) => onChange(e.target.checked)}
45
+ aria-label={label}
46
+ />
47
+ <span className="slider" />
48
+ </label>
49
+ );
50
+ }
51
+
52
+ let rowSeq = 0;
53
+ const newRow = (p = {}) => ({
54
+ key: `r${rowSeq++}`,
55
+ name: p.name || '',
56
+ type: PARAM_TYPES.includes(p.type) ? p.type : 'string',
57
+ description: p.description || '',
58
+ required: p.required !== false,
59
+ default: p.default == null ? '' : String(p.default),
60
+ });
61
+ const initRows = (tool) => (tool?.params || []).map(newRow);
62
+ // Comparable shape (row keys dropped) for the dirty check.
63
+ const normRows = (rows) => rows.map((r) => (
64
+ { name: r.name, type: r.type, description: r.description, required: !!r.required, default: r.default }
65
+ ));
66
+
67
+ function TypeSelect({ value, onChange, disabled }) {
68
+ return (
69
+ <span className="select-wrap cn-type-sel">
70
+ <select className="select" value={value} disabled={disabled} onChange={(e) => onChange(e.target.value)} aria-label="Parameter type">
71
+ {PARAM_TYPES.map((t) => <option key={t} value={t}>{t}</option>)}
72
+ </select>
73
+ <span className="chev"><ChevronDown size={13} /></span>
74
+ </span>
75
+ );
76
+ }
77
+
78
+ /** Typed default from the row's raw text; {value} on success, {error} on a
79
+ * value that does not fit the declared type. Empty text = no default. */
80
+ function parseDefault(row) {
81
+ const raw = row.default.trim();
82
+ if (!raw) return { value: undefined };
83
+ if (row.type === 'number') {
84
+ const n = Number(raw);
85
+ return isFinite(n) ? { value: n } : { error: 'Default must be a number.' };
86
+ }
87
+ if (row.type === 'boolean') {
88
+ if (raw === 'true') return { value: true };
89
+ if (raw === 'false') return { value: false };
90
+ return { error: 'Default must be true or false.' };
91
+ }
92
+ return { value: raw };
93
+ }
94
+
95
+ /** Map the server's structured validation problems onto editor fields.
96
+ * Anything we cannot place lands in the general error list. */
97
+ function mapServerErrors(detail, rows) {
98
+ const out = { fields: {}, params: {}, general: [] };
99
+ if (typeof detail === 'string' && detail) { out.general.push(detail); return out; }
100
+ if (!detail || typeof detail !== 'object') { out.general.push('Your changes could not be saved.'); return out; }
101
+ const items = detail.problems || detail.violations || detail.errors || [];
102
+ if (detail.message) out.general.push(detail.message);
103
+ for (const it of items) {
104
+ const where = String(it?.where || it?.field || '').toLowerCase();
105
+ const msg = it?.error || it?.message || String(it);
106
+ if (['name', 'description', 'query'].includes(where)) out.fields[where] = msg;
107
+ else if (rows.some((r) => r.name === where)) out.params[where] = msg;
108
+ else out.general.push(where ? `${where}: ${msg}` : msg);
109
+ }
110
+ if (!out.general.length && !items.length && !detail.message) out.general.push('Your changes could not be saved.');
111
+ return out;
112
+ }
113
+
114
+ // ── Try it — always-visible test bench for the SAVED tool ───────────────────
115
+
116
+ function initialValues(params) {
117
+ const v = {};
118
+ for (const p of params || []) v[p.name] = p.default == null ? '' : String(p.default);
119
+ return v;
120
+ }
121
+
122
+ function BoolSelect({ value, onChange, disabled, label, id }) {
123
+ return (
124
+ <span className="select-wrap cn-type-sel">
125
+ <select id={id} className="select" value={value} onChange={(e) => onChange(e.target.value)} disabled={disabled} aria-label={label}>
126
+ <option value="">not set</option>
127
+ <option value="true">true</option>
128
+ <option value="false">false</option>
129
+ </select>
130
+ <span className="chev"><ChevronDown size={13} /></span>
131
+ </span>
132
+ );
133
+ }
134
+
135
+ function TryIt({ client, graphId, tool, builtin, dirty }) {
136
+ const params = tool?.params || [];
137
+ const [values, setValues] = useState(() => initialValues(params));
138
+ const [query, setQuery] = useState('');
139
+ const [errors, setErrors] = useState({}); // param name -> msg
140
+ const [runError, setRunError] = useState('');
141
+ const [result, setResult] = useState(null); // {data, consumption}
142
+ const [busy, setBusy] = useState(false);
143
+
144
+ const run = async () => {
145
+ const errs = {};
146
+ const args = {};
147
+ if (builtin) {
148
+ if (!query.trim()) { setRunError('Enter a query to run.'); return; }
149
+ args.query = query;
150
+ } else {
151
+ for (const p of params) {
152
+ const raw = String(values[p.name] ?? '').trim();
153
+ if (!raw) {
154
+ // Empty and optional: leave it out; the tool's own default applies.
155
+ if (p.required && p.default == null) errs[p.name] = 'Required.';
156
+ continue;
157
+ }
158
+ if (p.type === 'number') {
159
+ const n = Number(raw);
160
+ if (!isFinite(n)) { errs[p.name] = 'Must be a number.'; continue; }
161
+ args[p.name] = n;
162
+ } else if (p.type === 'boolean') {
163
+ args[p.name] = raw === 'true';
164
+ } else {
165
+ args[p.name] = raw;
166
+ }
167
+ }
168
+ }
169
+ setErrors(errs);
170
+ setRunError('');
171
+ if (Object.keys(errs).length) return;
172
+ setBusy(true);
173
+ setResult(null);
174
+ try {
175
+ const body = await client.testConnectTool(graphId, builtin ? RUN_QUERY_TOOL : tool.name, args);
176
+ setResult(body);
177
+ } catch (e) {
178
+ setRunError(e?.message || 'The test run failed.');
179
+ } finally {
180
+ setBusy(false);
181
+ }
182
+ };
183
+
184
+ const units = result ? fmtUnits(result.consumption) : null;
185
+ let dataText = '';
186
+ if (result) {
187
+ try { dataText = JSON.stringify(result.data ?? null, null, 2); } catch { dataText = String(result.data); }
188
+ }
189
+
190
+ return (
191
+ <section className="cn-dsec">
192
+ <h4 className="cn-dsec-h">Try it</h4>
193
+ <p className="cn-hint cn-dsec-sub">Runs this tool exactly as a connected agent would, without needing an API key.</p>
194
+ <form className="cn-try" onSubmit={(e) => { e.preventDefault(); if (!busy) run(); }}>
195
+ {builtin ? (
196
+ <div className="field">
197
+ <label htmlFor="cn-try-q">Query</label>
198
+ <textarea
199
+ id="cn-try-q"
200
+ className="textarea mono cn-ed-query"
201
+ value={query}
202
+ onChange={(e) => setQuery(e.target.value)}
203
+ rows={4}
204
+ placeholder="g.V().limit(5)"
205
+ spellCheck={false}
206
+ disabled={busy}
207
+ />
208
+ </div>
209
+ ) : params.length ? (
210
+ <div className="cn-test-params">
211
+ {params.map((p) => (
212
+ <div key={p.name} className="field cn-test-field">
213
+ <label htmlFor={`cn-try-${p.name}`}>
214
+ <span className="mono">{p.name}</span>
215
+ <span className="cn-hint"> {p.type}{p.required ? ', required' : ''}</span>
216
+ </label>
217
+ {p.type === 'boolean' ? (
218
+ <BoolSelect
219
+ id={`cn-try-${p.name}`}
220
+ value={String(values[p.name] ?? '')}
221
+ onChange={(v) => setValues((s) => ({ ...s, [p.name]: v }))}
222
+ disabled={busy}
223
+ label={p.name}
224
+ />
225
+ ) : (
226
+ <input
227
+ id={`cn-try-${p.name}`}
228
+ className={'input sm' + (p.type === 'number' ? ' mono' : '')}
229
+ inputMode={p.type === 'number' ? 'decimal' : undefined}
230
+ value={values[p.name] ?? ''}
231
+ onChange={(e) => setValues((s) => ({ ...s, [p.name]: e.target.value }))}
232
+ placeholder={p.description || p.name}
233
+ disabled={busy}
234
+ />
235
+ )}
236
+ {errors[p.name] && <div className="cn-err">{errors[p.name]}</div>}
237
+ </div>
238
+ ))}
239
+ </div>
240
+ ) : (
241
+ <div className="cn-hint">This tool takes no parameters.</div>
242
+ )}
243
+
244
+ {runError && <div className="cn-err">{runError}</div>}
245
+
246
+ <div className="cn-try-run">
247
+ {dirty && <span className="cn-hint cn-try-note">Testing the last saved version</span>}
248
+ <button type="submit" className="btn sm" disabled={busy}>
249
+ <Play size={13} /> {busy ? 'Running…' : 'Run'}
250
+ </button>
251
+ </div>
252
+ </form>
253
+
254
+ {result && (
255
+ <div className="cn-test-result">
256
+ <div className="cn-test-units mono">{units || '—'}</div>
257
+ <CodeBlock code={dataText} language="json" className="cn-test-json" />
258
+ </div>
259
+ )}
260
+ </section>
261
+ );
262
+ }
263
+
264
+ // ── the detail pane ─────────────────────────────────────────────────────────
265
+
266
+ export function ConnectToolDetail({
267
+ client, graphId, tool, builtin, isDraft, enabled, busy, takenNames, narrow,
268
+ onBack, onToggle, onSave, onDelete, onDirtyChange,
269
+ }) {
270
+ const [name, setName] = useState(tool?.name || '');
271
+ const [description, setDescription] = useState(tool?.description || '');
272
+ const [query, setQuery] = useState(tool?.query || '');
273
+ const [rows, setRows] = useState(() => initRows(tool));
274
+ const [fieldErrors, setFieldErrors] = useState({}); // name/description/query -> msg
275
+ const [paramErrors, setParamErrors] = useState({}); // row key -> msg
276
+ const [general, setGeneral] = useState([]);
277
+ const [saving, setSaving] = useState(false);
278
+ const baselineRef = useRef(tool || null); // last SAVED definition
279
+
280
+ const setRow = (key, patch) => setRows((rs) => rs.map((r) => (r.key === key ? { ...r, ...patch } : r)));
281
+
282
+ const dirty = useMemo(() => {
283
+ if (builtin) return false;
284
+ const b = baselineRef.current;
285
+ return name !== (b?.name || '')
286
+ || description !== (b?.description || '')
287
+ || query !== (b?.query || '')
288
+ || JSON.stringify(normRows(rows)) !== JSON.stringify(normRows(initRows(b)));
289
+ }, [builtin, name, description, query, rows]);
290
+
291
+ // Parent hears about dirtiness (it guards selection switches with a
292
+ // discard confirm); a labeled name makes the confirm copy specific.
293
+ const onDirtyRef = useRef(onDirtyChange);
294
+ onDirtyRef.current = onDirtyChange;
295
+ useEffect(() => {
296
+ onDirtyRef.current?.(dirty, baselineRef.current?.name || name.trim() || 'new tool');
297
+ }, [dirty, name]);
298
+ useEffect(() => () => { onDirtyRef.current?.(false, ''); }, []);
299
+
300
+ // Realtime convergence: a fresh registry push re-syncs a CLEAN form; a
301
+ // dirty form keeps the user's edits (the list still updates around it).
302
+ useEffect(() => {
303
+ if (builtin || isDraft || !tool || tool === baselineRef.current || dirty) return;
304
+ baselineRef.current = tool;
305
+ setName(tool.name || '');
306
+ setDescription(tool.description || '');
307
+ setQuery(tool.query || '');
308
+ setRows(initRows(tool));
309
+ }, [tool, dirty, builtin, isDraft]);
310
+
311
+ // Soft placeholder cross-check: never blocks (the server is the authority),
312
+ // just points out likely mistakes before a failed save.
313
+ const placeholderHint = useMemo(() => {
314
+ if (builtin) return '';
315
+ const used = new Set((query.match(/\$[a-z][a-z0-9_]*/g) || []).map((s) => s.slice(1)));
316
+ const declared = new Set(rows.map((r) => r.name).filter(Boolean));
317
+ const undeclared = [...used].filter((n) => !declared.has(n));
318
+ const unused = [...declared].filter((n) => !used.has(n));
319
+ const bits = [];
320
+ if (undeclared.length) bits.push(`$${undeclared.join(', $')} in the query has no matching parameter`);
321
+ if (unused.length) bits.push(`parameter ${unused.join(', ')} is never used in the query`);
322
+ return bits.join('; ');
323
+ }, [builtin, query, rows]);
324
+
325
+ /** Save: client-side validation, then the awaited parent save; server 400
326
+ * problems come back per-field. NOT optimistic — errors keep the edits. */
327
+ const submit = async () => {
328
+ const fe = {};
329
+ const pe = {};
330
+
331
+ const nm = name.trim();
332
+ if (!NAME_RE.test(nm)) fe.name = NAME_HINT;
333
+ else if (nm !== baselineRef.current?.name && takenNames.has(nm)) fe.name = 'A tool with this name already exists.';
334
+ if (!query.trim()) fe.query = 'The query cannot be empty.';
335
+
336
+ const seen = new Set();
337
+ const params = [];
338
+ for (const r of rows) {
339
+ const pn = r.name.trim();
340
+ if (!NAME_RE.test(pn)) { pe[r.key] = NAME_HINT; continue; }
341
+ if (seen.has(pn)) { pe[r.key] = 'Duplicate parameter name.'; continue; }
342
+ seen.add(pn);
343
+ const def = parseDefault(r);
344
+ if (def.error) { pe[r.key] = def.error; continue; }
345
+ const p = { name: pn, type: r.type, description: r.description.trim(), required: !!r.required };
346
+ if (def.value !== undefined) p.default = def.value;
347
+ params.push(p);
348
+ }
349
+
350
+ setFieldErrors(fe);
351
+ setParamErrors(pe);
352
+ setGeneral([]);
353
+ if (Object.keys(fe).length || Object.keys(pe).length) return;
354
+
355
+ const def = {
356
+ name: nm,
357
+ description: description.trim(),
358
+ query,
359
+ params,
360
+ enabled: baselineRef.current?.enabled !== false,
361
+ };
362
+ setSaving(true);
363
+ try {
364
+ await onSave(def, isDraft ? null : baselineRef.current?.name || null);
365
+ // Clean baseline = what we just saved (a rename/create remounts this
366
+ // component through the parent's selection follow; harmless here).
367
+ baselineRef.current = def;
368
+ setName(def.name);
369
+ setDescription(def.description);
370
+ setQuery(def.query);
371
+ setRows(initRows(def));
372
+ } catch (e) {
373
+ const mapped = mapServerErrors(e?.detail ?? e?.message, rows.map((r) => ({ ...r, name: r.name.trim() })));
374
+ setFieldErrors(mapped.fields);
375
+ // Server problems name params by param name; translate to row keys.
376
+ const byKey = {};
377
+ for (const r of rows) {
378
+ if (mapped.params[r.name.trim()]) byKey[r.key] = mapped.params[r.name.trim()];
379
+ }
380
+ setParamErrors(byKey);
381
+ setGeneral(mapped.general);
382
+ } finally {
383
+ setSaving(false);
384
+ }
385
+ };
386
+
387
+ const headName = builtin ? RUN_QUERY_TOOL
388
+ : isDraft ? (name.trim() || 'New tool')
389
+ : (baselineRef.current?.name || name);
390
+ const disabledForms = saving;
391
+ // The saved definition drives Try it (POST /connect/test runs by name);
392
+ // key resets its inputs when the saved params actually change.
393
+ const savedParamsKey = JSON.stringify((tool?.params || []).map((p) => [p.name, p.type, p.default ?? null]));
394
+
395
+ return (
396
+ <div className="cn-detail">
397
+ <div className="cn-dhead">
398
+ {narrow && (
399
+ <button type="button" className="btn sm ghost cn-dback" onClick={onBack}>
400
+ <ArrowLeft size={14} /> Tools
401
+ </button>
402
+ )}
403
+ <code className="mono cn-dname" title={headName}>{headName}</code>
404
+ {builtin && <span className="pill brand">Built in</span>}
405
+ {!isDraft && (
406
+ <Switch
407
+ checked={!!enabled}
408
+ disabled={busy}
409
+ onChange={onToggle}
410
+ label={`Enable ${headName}`}
411
+ />
412
+ )}
413
+ </div>
414
+
415
+ <div className="cn-dscroll scroll">
416
+ {builtin ? (
417
+ <p className="cn-ddesc">{RUN_QUERY_DESCRIPTION}</p>
418
+ ) : (
419
+ <section className="cn-dsec">
420
+ <h4 className="cn-dsec-h">Definition</h4>
421
+ <p className="cn-hint cn-dsec-sub">
422
+ A tool is a named query agents can call with typed parameters. Keep the
423
+ description specific; it is what agents read to decide when to use it.
424
+ </p>
425
+ <form className="cn-ed" onSubmit={(e) => { e.preventDefault(); if (!saving) submit(); }}>
426
+ <div className="field">
427
+ <label htmlFor="cn-ed-name">Name</label>
428
+ <input
429
+ id="cn-ed-name"
430
+ className="input mono"
431
+ value={name}
432
+ onChange={(e) => setName(e.target.value)}
433
+ placeholder="overdue_tickets"
434
+ maxLength={64}
435
+ disabled={disabledForms}
436
+ autoFocus={isDraft}
437
+ />
438
+ {fieldErrors.name && <div className="cn-err">{fieldErrors.name}</div>}
439
+ </div>
440
+
441
+ <div className="field">
442
+ <label htmlFor="cn-ed-desc">Description</label>
443
+ <input
444
+ id="cn-ed-desc"
445
+ className="input"
446
+ value={description}
447
+ onChange={(e) => setDescription(e.target.value)}
448
+ placeholder="What this tool returns and when to use it"
449
+ disabled={disabledForms}
450
+ />
451
+ {fieldErrors.description && <div className="cn-err">{fieldErrors.description}</div>}
452
+ </div>
453
+
454
+ <div className="field">
455
+ <div className="cn-ed-params-h">
456
+ <label>Parameters</label>
457
+ <button type="button" className="btn sm" onClick={() => setRows((rs) => [...rs, newRow()])} disabled={disabledForms}>
458
+ <Plus size={13} /> Add parameter
459
+ </button>
460
+ </div>
461
+ {rows.length > 0 && (
462
+ <div className="cn-ed-params">
463
+ <div className="cn-ed-prow cn-ed-phead" aria-hidden="true">
464
+ <span>Name</span><span>Type</span><span>Description</span><span>Required</span><span>Default</span><span />
465
+ </div>
466
+ {rows.map((r) => (
467
+ <div key={r.key} className="cn-ed-prow-wrap">
468
+ <div className="cn-ed-prow">
469
+ <input
470
+ className="input sm mono"
471
+ value={r.name}
472
+ onChange={(e) => setRow(r.key, { name: e.target.value })}
473
+ placeholder="name"
474
+ aria-label="Parameter name"
475
+ maxLength={64}
476
+ disabled={disabledForms}
477
+ />
478
+ <TypeSelect value={r.type} onChange={(t) => setRow(r.key, { type: t })} disabled={disabledForms} />
479
+ <input
480
+ className="input sm"
481
+ value={r.description}
482
+ onChange={(e) => setRow(r.key, { description: e.target.value })}
483
+ placeholder="What it means"
484
+ aria-label="Parameter description"
485
+ disabled={disabledForms}
486
+ />
487
+ <label className="cn-ed-req">
488
+ <input
489
+ type="checkbox"
490
+ checked={r.required}
491
+ onChange={(e) => setRow(r.key, { required: e.target.checked })}
492
+ disabled={disabledForms}
493
+ />
494
+ <span>Required</span>
495
+ </label>
496
+ <input
497
+ className="input sm mono"
498
+ value={r.default}
499
+ onChange={(e) => setRow(r.key, { default: e.target.value })}
500
+ placeholder={r.type === 'boolean' ? 'true / false' : 'none'}
501
+ aria-label="Default value"
502
+ disabled={disabledForms}
503
+ />
504
+ <button
505
+ type="button"
506
+ className="iconbtn danger"
507
+ title="Remove parameter"
508
+ aria-label="Remove parameter"
509
+ onClick={() => setRows((rs) => rs.filter((x) => x.key !== r.key))}
510
+ disabled={disabledForms}
511
+ >
512
+ <Trash2 size={14} />
513
+ </button>
514
+ </div>
515
+ {paramErrors[r.key] && <div className="cn-err">{paramErrors[r.key]}</div>}
516
+ </div>
517
+ ))}
518
+ </div>
519
+ )}
520
+ </div>
521
+
522
+ <div className="field">
523
+ <label htmlFor="cn-ed-query">Query</label>
524
+ <textarea
525
+ id="cn-ed-query"
526
+ className="textarea mono cn-ed-query"
527
+ value={query}
528
+ onChange={(e) => setQuery(e.target.value)}
529
+ rows={5}
530
+ placeholder={"g.V().hasLabel('Customer').has('name', $customer).limit($limit)"}
531
+ spellCheck={false}
532
+ disabled={disabledForms}
533
+ />
534
+ <div className="cn-hint">
535
+ Use $name placeholders for parameters. Values are always inserted as safe typed
536
+ literals, never as raw text.
537
+ </div>
538
+ {placeholderHint && <div className="cn-warn">{placeholderHint}</div>}
539
+ {fieldErrors.query && <div className="cn-err">{fieldErrors.query}</div>}
540
+ </div>
541
+
542
+ {general.map((g, i) => <div key={i} className="cn-err">{g}</div>)}
543
+
544
+ <div className="cn-ed-save">
545
+ <button type="submit" className="btn primary" disabled={saving || !dirty}>
546
+ {saving ? 'Saving…' : 'Save'}
547
+ </button>
548
+ </div>
549
+ </form>
550
+ </section>
551
+ )}
552
+
553
+ {!isDraft && (
554
+ <TryIt key={savedParamsKey} client={client} graphId={graphId} tool={tool} builtin={builtin} dirty={dirty} />
555
+ )}
556
+
557
+ {!builtin && !isDraft && (
558
+ <div className="cn-dfoot">
559
+ <button type="button" className="cn-del" onClick={onDelete}>Delete tool</button>
560
+ </div>
561
+ )}
562
+ </div>
563
+ </div>
564
+ );
565
+ }