@loomcycle/explorer 0.1.0 → 0.3.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/dist/index.js CHANGED
@@ -1,231 +1,386 @@
1
- import { jsx as t, jsxs as d, Fragment as G } from "react/jsx-runtime";
2
- import { createContext as pe, useContext as fe, useMemo as U, useState as f, useRef as H, useEffect as j, useCallback as S } from "react";
3
- import { LoomcycleClient as be } from "@loomcycle/client";
4
- function K(a) {
1
+ import { jsx as n, jsxs as d, Fragment as q } from "react/jsx-runtime";
2
+ import { createContext as Je, useContext as Ve, useMemo as H, useState as y, useRef as K, useEffect as I, useCallback as G } from "react";
3
+ import { LoomcycleClient as Ze } from "@loomcycle/client";
4
+ import qe from "react-markdown";
5
+ import Qe from "remark-gfm";
6
+ function ye(e, r) {
5
7
  return {
6
- pathLs: (e, r, n, s) => a.path(
7
- { op: "ls", path: e, scope: r, recursive: n },
8
+ pathLs: (t, a, c, s) => e.path(
9
+ { op: "ls", path: t, scope: a, recursive: c },
8
10
  s
9
11
  ),
10
- pathMkdir: (e, r, n) => a.path({ op: "mkdir", path: e, scope: r }, n),
11
- pathMv: (e, r, n, s) => a.path({ op: "mv", path: e, to: r, scope: n }, s),
12
- pathRm: (e, r, n, s) => a.path({ op: "rm", path: e, scope: r, recursive: n }, s),
13
- documentCreate: (e, r, n, s) => a.document(
14
- { op: "create_document", title: e, path: r, scope: n },
12
+ pathMkdir: (t, a, c) => e.path({ op: "mkdir", path: t, scope: a }, c),
13
+ pathMv: (t, a, c, s) => e.path({ op: "mv", path: t, to: a, scope: c }, s),
14
+ pathRm: (t, a, c, s) => e.path({ op: "rm", path: t, scope: a, recursive: c }, s),
15
+ documentCreate: (t, a, c, s) => e.document(
16
+ { op: "create_document", title: t, path: a, scope: c },
15
17
  s
16
18
  ),
17
- documentDelete: (e, r, n) => a.document({ op: "delete_document", id: e, scope: r }, n),
18
- documentQueryChunks: (e, r, n) => a.document(
19
- { op: "query_chunks", document_id: e, scope: r, limit: 1e3 },
20
- n
19
+ documentDelete: (t, a, c) => e.document({ op: "delete_document", id: t, scope: a }, c),
20
+ documentGet: (t, a, c) => e.document({ op: "get_document", id: t, scope: a }, c),
21
+ documentsSummary: (t, a, c) => e.document(
22
+ // documents_summary + document_ids are RFC BN wire additions the pinned
23
+ // SDK type doesn't enumerate; the /v1/_document passthrough accepts them
24
+ // verbatim, so cast past DocumentToolInput (same pattern as update_chunk).
25
+ {
26
+ op: "documents_summary",
27
+ scope: a,
28
+ ...t.documentIds ? { document_ids: t.documentIds } : {},
29
+ ...t.underPath ? { under_path: t.underPath } : {}
30
+ },
31
+ c
32
+ ),
33
+ documentQueryChunks: (t, a, c) => e.document(
34
+ { op: "query_chunks", document_id: t, scope: a, limit: 1e3 },
35
+ c
36
+ ),
37
+ documentGetChunk: (t, a, c) => e.document({ op: "get_chunk", id: t, scope: a }, c),
38
+ documentCreateChunk: (t, a, c, s, o) => e.document(
39
+ {
40
+ op: "create_chunk",
41
+ document_id: t,
42
+ parent_id: a,
43
+ scope: s,
44
+ ...c
45
+ },
46
+ o
47
+ ),
48
+ documentSetAsset: (t, a, c, s, o, i) => e.document(
49
+ // set_asset is an RFC BO wire op the pinned SDK type doesn't enumerate;
50
+ // the /v1/_document passthrough accepts it verbatim.
51
+ {
52
+ op: "set_asset",
53
+ id: t,
54
+ media_type: a,
55
+ data: c,
56
+ ...s ? { filename: s } : {},
57
+ scope: o
58
+ },
59
+ i
60
+ ),
61
+ documentGetEdges: (t, a, c) => e.document(
62
+ // get_edges is an RFC BN P4 wire op the pinned SDK type doesn't
63
+ // enumerate; the /v1/_document passthrough accepts it verbatim.
64
+ { op: "get_edges", document_id: t, scope: a },
65
+ c
21
66
  ),
22
- documentGetChunk: (e, r, n) => a.document({ op: "get_chunk", id: e, scope: r }, n),
23
- documentUpdateChunk: (e, r, n, s, c) => a.document(
67
+ documentUpdateChunk: (t, a, c, s, o) => e.document(
24
68
  // `patch.fields` is unknown but DocumentToolInput.fields is a typed
25
69
  // Record; the cast reconciles the spread (the server accepts arbitrary
26
70
  // JSON there). Op order + arg names mirror the wire contract exactly.
27
71
  {
28
72
  op: "update_chunk",
29
- id: e,
30
- revision: r,
73
+ id: t,
74
+ revision: a,
31
75
  scope: s,
32
- ...n
76
+ ...c
33
77
  },
34
- c
78
+ o
35
79
  ),
36
- documentExportMd: (e, r, n, s) => a.document(
80
+ documentExportMd: (t, a, c, s) => e.document(
37
81
  {
38
82
  op: "export_md",
39
- document_id: e,
40
- scope: r,
41
- include_metadata: n
83
+ document_id: t,
84
+ scope: a,
85
+ include_metadata: c
42
86
  },
43
87
  s
44
- )
88
+ ),
89
+ // Present only when an AssetFetch was supplied (the connection path); a bare
90
+ // client can't do the raw binary GET, so the op is omitted and the viewer
91
+ // shows a placeholder.
92
+ ...r ? {
93
+ documentAssetObjectUrl: async (t, a, c) => {
94
+ const s = new URLSearchParams({ scope: a });
95
+ c?.scopeId && s.set("scope_id", c.scopeId), c?.tenant && s.set("tenant", c.tenant);
96
+ const o = await r(
97
+ `/v1/_document/asset/${encodeURIComponent(t)}?${s.toString()}`
98
+ );
99
+ if (!o.ok) throw new Error(`asset fetch failed: ${o.status}`);
100
+ const i = await o.blob();
101
+ return URL.createObjectURL(i);
102
+ }
103
+ } : {}
45
104
  };
46
105
  }
47
- const re = pe(null);
48
- function ge({
49
- value: a,
50
- children: e
106
+ const Se = Je(null);
107
+ function Xe({
108
+ value: e,
109
+ children: r
51
110
  }) {
52
- return /* @__PURE__ */ t(re.Provider, { value: a, children: e });
111
+ return /* @__PURE__ */ n(Se.Provider, { value: e, children: r });
53
112
  }
54
- function X() {
55
- const a = fe(re);
56
- if (!a)
113
+ function se() {
114
+ const e = Ve(Se);
115
+ if (!e)
57
116
  throw new Error(
58
117
  "useExplorerData must be used within <PathExplorer> or <DocumentViewer> (no ExplorerDataLayer in context)"
59
118
  );
60
- return a;
61
- }
62
- function ke(a) {
63
- const e = a.fetch;
64
- return new be({
65
- baseUrl: a.baseUrl,
66
- authToken: a.token || void 0,
67
- fetch: (r, n) => e ? e(r, n) : fetch(r, n)
119
+ return e;
120
+ }
121
+ function Ye(e) {
122
+ const r = e.fetch;
123
+ return new Ze({
124
+ baseUrl: e.baseUrl,
125
+ authToken: e.token || void 0,
126
+ fetch: (t, a) => r ? r(t, a) : fetch(t, a)
68
127
  });
69
128
  }
70
- function le(a) {
71
- const { dataLayer: e, client: r, connection: n } = a;
72
- return U(() => e || (r ? K(r) : n ? K(ke(n)) : null), [e, r, n?.baseUrl, n?.token, n?.fetch]);
129
+ function Ke(e) {
130
+ const r = e.fetch, t = (a, c) => r ? r(a, c) : fetch(a, c);
131
+ return (a) => {
132
+ const c = {};
133
+ return e.token && (c.Authorization = `Bearer ${e.token}`), t(e.baseUrl + a, { headers: c });
134
+ };
73
135
  }
74
- function se({
75
- theme: a,
76
- dataLayer: e,
77
- children: r
136
+ function xe(e) {
137
+ const { dataLayer: r, client: t, connection: a } = e;
138
+ return H(() => r || (t ? ye(t) : a ? ye(
139
+ Ye(a),
140
+ Ke(a)
141
+ // RFC BO — binary image-asset GET
142
+ ) : null), [r, t, a?.baseUrl, a?.token, a?.fetch]);
143
+ }
144
+ function $e({
145
+ theme: e,
146
+ dataLayer: r,
147
+ children: t
78
148
  }) {
79
- const n = a ? { "data-theme": a } : {};
80
- return e ? /* @__PURE__ */ t("div", { className: "loomcycle-explorer", ...n, children: /* @__PURE__ */ t(ge, { value: e, children: r }) }) : /* @__PURE__ */ t("div", { className: "loomcycle-explorer", ...n, children: /* @__PURE__ */ d("div", { className: "error-banner", children: [
149
+ const a = e ? { "data-theme": e } : {};
150
+ return r ? /* @__PURE__ */ n("div", { className: "loomcycle-explorer", ...a, children: /* @__PURE__ */ n(Xe, { value: r, children: t }) }) : /* @__PURE__ */ n("div", { className: "loomcycle-explorer", ...a, children: /* @__PURE__ */ d("div", { className: "error-banner", children: [
81
151
  "@loomcycle/explorer: provide a ",
82
- /* @__PURE__ */ t("code", { children: "connection" }),
152
+ /* @__PURE__ */ n("code", { children: "connection" }),
83
153
  ", ",
84
- /* @__PURE__ */ t("code", { children: "client" }),
154
+ /* @__PURE__ */ n("code", { children: "client" }),
85
155
  ", or",
86
156
  " ",
87
- /* @__PURE__ */ t("code", { children: "dataLayer" }),
157
+ /* @__PURE__ */ n("code", { children: "dataLayer" }),
88
158
  " prop."
89
159
  ] }) });
90
160
  }
91
- const ee = 6;
92
- function ye({
93
- children: a,
94
- defaultLeftWidth: e = 380,
95
- minLeftWidth: r = 180,
96
- minRightWidth: n = 240,
97
- storageKey: s,
98
- className: c
161
+ const be = 6;
162
+ function et({
163
+ children: e,
164
+ defaultLeftWidth: r = 380,
165
+ minLeftWidth: t = 180,
166
+ minRightWidth: a = 240,
167
+ storageKey: c,
168
+ className: s
99
169
  }) {
100
- const [l, i] = f(() => {
101
- if (s) {
102
- const y = localStorage.getItem(s), E = y ? parseInt(y, 10) : NaN;
103
- if (Number.isFinite(E) && E >= r) return E;
170
+ const [o, i] = y(() => {
171
+ if (c) {
172
+ const N = localStorage.getItem(c), D = N ? parseInt(N, 10) : NaN;
173
+ if (Number.isFinite(D) && D >= t) return D;
104
174
  }
105
- return e;
106
- }), o = H(null), [u, h] = f(!1);
107
- j(() => {
108
- !s || u || localStorage.setItem(s, String(Math.round(l)));
109
- }, [s, l, u]);
110
- const x = S((y) => {
111
- y.preventDefault(), h(!0), y.target.setPointerCapture(y.pointerId);
112
- }, []), k = S(
113
- (y) => {
114
- if (!u || !o.current) return;
115
- const E = o.current.getBoundingClientRect(), T = y.clientX - E.left, L = E.width - n - ee, P = Math.max(r, Math.min(T, L));
116
- i(P);
175
+ return r;
176
+ }), l = K(null), [m, p] = y(!1);
177
+ I(() => {
178
+ !c || m || localStorage.setItem(c, String(Math.round(o)));
179
+ }, [c, o, m]);
180
+ const b = G((N) => {
181
+ N.preventDefault(), p(!0), N.target.setPointerCapture(N.pointerId);
182
+ }, []), g = G(
183
+ (N) => {
184
+ if (!m || !l.current) return;
185
+ const D = l.current.getBoundingClientRect(), U = N.clientX - D.left, R = D.width - a - be, W = Math.max(t, Math.min(U, R));
186
+ i(W);
117
187
  },
118
- [u, r, n]
119
- ), M = S((y) => {
120
- h(!1);
188
+ [m, t, a]
189
+ ), O = G((N) => {
190
+ p(!1);
121
191
  try {
122
- y.target.releasePointerCapture(y.pointerId);
192
+ N.target.releasePointerCapture(N.pointerId);
123
193
  } catch {
124
194
  }
125
195
  }, []);
126
196
  return /* @__PURE__ */ d(
127
197
  "div",
128
198
  {
129
- ref: o,
130
- className: `splitter ${c ?? ""} ${u ? "dragging" : ""}`,
199
+ ref: l,
200
+ className: `splitter ${s ?? ""} ${m ? "dragging" : ""}`,
131
201
  style: {
132
- gridTemplateColumns: `${l}px ${ee}px 1fr`
202
+ gridTemplateColumns: `${o}px ${be}px 1fr`
133
203
  },
134
204
  children: [
135
- /* @__PURE__ */ t("div", { className: "splitter-pane splitter-left", children: a[0] }),
136
- /* @__PURE__ */ t(
205
+ /* @__PURE__ */ n("div", { className: "splitter-pane splitter-left", children: e[0] }),
206
+ /* @__PURE__ */ n(
137
207
  "div",
138
208
  {
139
209
  className: "splitter-handle",
140
210
  role: "separator",
141
211
  "aria-orientation": "vertical",
142
- "aria-valuenow": Math.round(l),
143
- onPointerDown: x,
144
- onPointerMove: k,
145
- onPointerUp: M,
146
- onPointerCancel: M
212
+ "aria-valuenow": Math.round(o),
213
+ onPointerDown: b,
214
+ onPointerMove: g,
215
+ onPointerUp: O,
216
+ onPointerCancel: O
147
217
  }
148
218
  ),
149
- /* @__PURE__ */ t("div", { className: "splitter-pane splitter-right", children: a[1] })
219
+ /* @__PURE__ */ n("div", { className: "splitter-pane splitter-right", children: e[1] })
150
220
  ]
151
221
  }
152
222
  );
153
223
  }
154
- function ve(a) {
155
- const e = /* @__PURE__ */ new Map();
156
- a.forEach((s) => e.set(s.id, { row: s, children: [] }));
157
- const r = [];
158
- a.forEach((s) => {
159
- const c = e.get(s.id);
160
- s.parent_id && e.has(s.parent_id) ? e.get(s.parent_id).children.push(c) : r.push(c);
224
+ const tt = ["image/png", "image/jpeg", "image/gif", "image/webp"];
225
+ function Me(e) {
226
+ return tt.includes(e);
227
+ }
228
+ function Le(e) {
229
+ return new Promise((r, t) => {
230
+ if (!Me(e.type)) {
231
+ t(new Error(`unsupported image type "${e.type || "unknown"}" (png, jpeg, gif, webp only)`));
232
+ return;
233
+ }
234
+ const a = new FileReader();
235
+ a.onerror = () => t(a.error ?? new Error("failed to read file")), a.onload = () => {
236
+ const c = String(a.result ?? ""), s = c.indexOf(",");
237
+ if (s < 0) {
238
+ t(new Error("could not decode image data"));
239
+ return;
240
+ }
241
+ r({ mediaType: e.type, data: c.slice(s + 1) });
242
+ }, a.readAsDataURL(e);
161
243
  });
162
- const n = (s) => {
163
- s.sort((c, l) => c.row.position - l.row.position), s.forEach((c) => n(c.children));
244
+ }
245
+ function nt(e) {
246
+ if (!e) return null;
247
+ for (let r = 0; r < e.length; r++) {
248
+ const t = e[r];
249
+ if (t.kind === "file" && Me(t.type)) {
250
+ const a = t.getAsFile();
251
+ if (a) return a;
252
+ }
253
+ }
254
+ return null;
255
+ }
256
+ const me = {
257
+ "doc.rfc.draft": "#c99a3a",
258
+ "doc.rfc.review": "#6a7bd6",
259
+ "doc.rfc.confirmed": "#3a9ad6",
260
+ "doc.rfc.done": "#3aa06a",
261
+ "doc.document.done": "#3aa06a",
262
+ "doc.research.done": "#8a6ad6",
263
+ "doc.publication.draft": "#c99a3a",
264
+ "chunk.draft": "#c99a3a",
265
+ "chunk.review": "#6a7bd6",
266
+ "chunk.confirmed": "#3a9ad6",
267
+ "chunk.done": "#3aa06a"
268
+ }, at = 0.16;
269
+ function fe(e) {
270
+ return e && Object.keys(e).length > 0 ? e : me;
271
+ }
272
+ function De(e, r, t) {
273
+ const a = e ?? "", c = r ?? "";
274
+ if (a && c && t[`doc.${a}.${c}`]) return t[`doc.${a}.${c}`];
275
+ if (a && t[`doc.${a}`]) return t[`doc.${a}`];
276
+ }
277
+ function rt(e, r) {
278
+ const t = e ?? "";
279
+ return t ? r[`chunk.${t}`] : void 0;
280
+ }
281
+ function ct(e) {
282
+ const r = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());
283
+ if (!r) return;
284
+ let t = r[1];
285
+ t.length === 3 && (t = t[0] + t[0] + t[1] + t[1] + t[2] + t[2]);
286
+ const a = parseInt(t.slice(0, 2), 16), c = parseInt(t.slice(2, 4), 16), s = parseInt(t.slice(4, 6), 16);
287
+ return `rgba(${a}, ${c}, ${s}, ${at})`;
288
+ }
289
+ function ge(e) {
290
+ if (!e) return;
291
+ const r = ct(e);
292
+ if (r)
293
+ return { background: r, borderLeft: `3px solid ${e}` };
294
+ }
295
+ function ot(e) {
296
+ const r = /* @__PURE__ */ new Map();
297
+ e.forEach((c) => r.set(c.id, { row: c, children: [] }));
298
+ const t = [];
299
+ e.forEach((c) => {
300
+ const s = r.get(c.id);
301
+ c.parent_id && r.has(c.parent_id) ? r.get(c.parent_id).children.push(s) : t.push(s);
302
+ });
303
+ const a = (c) => {
304
+ c.sort((s, o) => s.row.position - o.row.position), c.forEach((s) => a(s.children));
164
305
  };
165
- return n(r), r;
306
+ return a(t), t;
307
+ }
308
+ function ke(e) {
309
+ return e === "image" ? "🖼" : e === "mermaid" ? "📊" : "";
166
310
  }
167
- function ce(a, e) {
168
- for (const r of a) {
169
- if (r.row.id === e) return r;
170
- const n = ce(r.children, e);
171
- if (n) return n;
311
+ function Re(e, r) {
312
+ for (const t of e) {
313
+ if (t.row.id === r) return t;
314
+ const a = Re(t.children, r);
315
+ if (a) return a;
172
316
  }
173
317
  }
174
- function Ne({ tree: a, selectedId: e, onSelect: r }) {
175
- const [n, s] = f(() => /* @__PURE__ */ new Map()), c = S((l) => {
176
- s((i) => {
177
- const o = new Map(i);
178
- return o.set(l, i.get(l) === !1), o;
318
+ function st({
319
+ tree: e,
320
+ selectedId: r,
321
+ onSelect: t,
322
+ colorEnabled: a,
323
+ scheme: c,
324
+ linkedIds: s
325
+ }) {
326
+ const [o, i] = y(() => /* @__PURE__ */ new Map()), l = G((p) => {
327
+ i((b) => {
328
+ const g = new Map(b);
329
+ return g.set(p, b.get(p) === !1), g;
179
330
  });
180
331
  }, []);
181
- return j(() => {
182
- if (!e) return;
183
- const l = we(a, e);
184
- l.length !== 0 && s((i) => {
185
- let o = !1;
186
- const u = new Map(i);
187
- for (const h of l)
188
- u.get(h) === !1 && (u.set(h, !0), o = !0);
189
- return o ? u : i;
332
+ I(() => {
333
+ if (!r) return;
334
+ const p = it(e, r);
335
+ p.length !== 0 && i((b) => {
336
+ let g = !1;
337
+ const O = new Map(b);
338
+ for (const N of p)
339
+ O.get(N) === !1 && (O.set(N, !0), g = !0);
340
+ return g ? O : b;
190
341
  });
191
- }, [a, e]), a.length === 0 ? /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "No chunks." }) }) : /* @__PURE__ */ t("ul", { className: "tree chunk-tree", children: a.map((l) => /* @__PURE__ */ t(
192
- oe,
342
+ }, [e, r]);
343
+ const m = a ? fe(c) : null;
344
+ return e.length === 0 ? /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "No chunks." }) }) : /* @__PURE__ */ n("ul", { className: "tree chunk-tree", children: e.map((p) => /* @__PURE__ */ n(
345
+ Ae,
193
346
  {
194
- node: l,
195
- expanded: n,
196
- toggle: c,
197
- selectedId: e,
198
- onSelect: r
347
+ node: p,
348
+ expanded: o,
349
+ toggle: l,
350
+ selectedId: r,
351
+ onSelect: t,
352
+ tintScheme: m,
353
+ linkedIds: s
199
354
  },
200
- l.row.id
355
+ p.row.id
201
356
  )) });
202
357
  }
203
- function we(a, e) {
204
- const r = [], n = (s, c) => {
205
- for (const l of s) {
206
- if (l.row.id === e)
207
- return r.push(...c), !0;
208
- if (n(l.children, [...c, l.row.id])) return !0;
358
+ function it(e, r) {
359
+ const t = [], a = (c, s) => {
360
+ for (const o of c) {
361
+ if (o.row.id === r)
362
+ return t.push(...s), !0;
363
+ if (a(o.children, [...s, o.row.id])) return !0;
209
364
  }
210
365
  return !1;
211
366
  };
212
- return n(a, []), r;
367
+ return a(e, []), t;
213
368
  }
214
- function oe({ node: a, expanded: e, toggle: r, selectedId: n, onSelect: s }) {
215
- const c = a.children.length > 0, l = e.get(a.row.id) !== !1, i = n === a.row.id;
216
- return /* @__PURE__ */ d("li", { className: `node chunk-node ${i ? "selected" : ""}`, children: [
217
- /* @__PURE__ */ d("div", { className: "row chunk-row", children: [
218
- /* @__PURE__ */ t(
369
+ function Ae({ node: e, expanded: r, toggle: t, selectedId: a, onSelect: c, tintScheme: s, linkedIds: o }) {
370
+ const i = e.children.length > 0, l = r.get(e.row.id) !== !1, m = a === e.row.id, p = s ? ge(rt(e.row.status, s)) : void 0, b = o?.has(e.row.id);
371
+ return /* @__PURE__ */ d("li", { className: `node chunk-node ${m ? "selected" : ""}`, children: [
372
+ /* @__PURE__ */ d("div", { className: "row chunk-row", style: p, children: [
373
+ /* @__PURE__ */ n(
219
374
  "button",
220
375
  {
221
376
  type: "button",
222
377
  className: "tree-caret",
223
378
  "aria-label": l ? "collapse" : "expand",
224
- disabled: !c,
225
- onClick: (o) => {
226
- o.stopPropagation(), c && r(a.row.id);
379
+ disabled: !i,
380
+ onClick: (g) => {
381
+ g.stopPropagation(), i && t(e.row.id);
227
382
  },
228
- children: c ? l ? "▼" : "▶" : "·"
383
+ children: i ? l ? "▼" : "▶" : "·"
229
384
  }
230
385
  ),
231
386
  /* @__PURE__ */ d(
@@ -233,469 +388,858 @@ function oe({ node: a, expanded: e, toggle: r, selectedId: n, onSelect: s }) {
233
388
  {
234
389
  type: "button",
235
390
  className: "chunk-link",
236
- onClick: () => s(a),
237
- title: a.row.title,
391
+ onClick: () => c(e),
392
+ title: e.row.title,
238
393
  children: [
239
- /* @__PURE__ */ t("span", { className: "chunk-title", children: a.row.title || "(untitled)" }),
240
- a.row.type && /* @__PURE__ */ t("span", { className: "chunk-badge", children: a.row.type }),
241
- a.row.status && /* @__PURE__ */ t("span", { className: "chunk-badge chunk-status", children: a.row.status })
394
+ ke(e.row.type) && /* @__PURE__ */ n("span", { className: "chunk-type-icon", "aria-hidden": !0, children: ke(e.row.type) }),
395
+ /* @__PURE__ */ n("span", { className: "chunk-title", children: e.row.title || "(untitled)" }),
396
+ e.row.type && /* @__PURE__ */ n("span", { className: "chunk-badge", children: e.row.type }),
397
+ e.row.status && /* @__PURE__ */ n("span", { className: "chunk-badge chunk-status", children: e.row.status }),
398
+ b && /* @__PURE__ */ n("span", { className: "chunk-link-badge", title: "Has cross-reference links", "aria-label": "linked", children: "🔗" })
242
399
  ]
243
400
  }
244
401
  )
245
402
  ] }),
246
- c && l && /* @__PURE__ */ t("ul", { className: "children chunk-children", children: a.children.map((o) => /* @__PURE__ */ t(
247
- oe,
403
+ i && l && /* @__PURE__ */ n("ul", { className: "children chunk-children", children: e.children.map((g) => /* @__PURE__ */ n(
404
+ Ae,
248
405
  {
249
- node: o,
250
- expanded: e,
251
- toggle: r,
252
- selectedId: n,
253
- onSelect: s
406
+ node: g,
407
+ expanded: r,
408
+ toggle: t,
409
+ selectedId: a,
410
+ onSelect: c,
411
+ tintScheme: s,
412
+ linkedIds: o
254
413
  },
255
- o.row.id
414
+ g.row.id
256
415
  )) })
257
416
  ] });
258
417
  }
259
- function Ce({ chunk: a, scope: e, browse: r, onClose: n, onSaved: s }) {
260
- const c = X(), [l, i] = f(a.title), [o, u] = f(a.type ?? ""), [h, x] = f(a.status ?? ""), [k, M] = f(a.body ?? ""), [y, E] = f(
261
- a.fields ? JSON.stringify(a.fields, null, 2) : ""
262
- ), [T, L] = f(!1), [P, D] = f(null), [W, R] = f(!1);
263
- return /* @__PURE__ */ t("div", { className: "modal-overlay", onClick: n, children: /* @__PURE__ */ d("form", { className: "modal chunk-editor", onClick: (b) => b.stopPropagation(), onSubmit: async (b) => {
264
- b.preventDefault(), D(null), R(!1);
265
- const N = {
266
- body: k,
267
- title: l,
268
- type: o,
269
- status: h
418
+ let lt = 0;
419
+ function ie({ code: e }) {
420
+ const r = K(null), [t, a] = y({});
421
+ return I(() => {
422
+ let c = !1;
423
+ return (async () => {
424
+ try {
425
+ const s = (await import("mermaid")).default, o = r.current?.closest("[data-theme]")?.getAttribute("data-theme"), i = o ? o === "dark" : !0;
426
+ s.initialize({ startOnLoad: !1, theme: i ? "dark" : "default", securityLevel: "strict" });
427
+ const { svg: l } = await s.render(`lc-mmd-${lt++}`, e);
428
+ c || a({ svg: l });
429
+ } catch {
430
+ c || a({ err: !0 });
431
+ }
432
+ })(), () => {
433
+ c = !0;
434
+ };
435
+ }, [e]), t.err ? /* @__PURE__ */ n("pre", { className: "md-pre md-mermaid-error", title: "diagram failed to render", children: /* @__PURE__ */ n("code", { children: e }) }) : t.svg ? /* @__PURE__ */ n("div", { ref: r, className: "md-mermaid", dangerouslySetInnerHTML: { __html: t.svg } }) : /* @__PURE__ */ n("div", { ref: r, className: "md-mermaid md-mermaid-loading", children: "rendering diagram…" });
436
+ }
437
+ function dt({ chunk: e, scope: r, browse: t, onClose: a, onSaved: c }) {
438
+ const s = se(), [o, i] = y(e.title), [l, m] = y(e.type ?? ""), [p, b] = y(e.status ?? ""), [g, O] = y(e.body ?? ""), [N, D] = y(
439
+ e.fields ? JSON.stringify(e.fields, null, 2) : ""
440
+ ), [U, R] = y(!1), [W, M] = y(null), [z, j] = y(!1), B = l === "mermaid", _ = l === "image" || !!e.asset, [w, L] = y(g);
441
+ I(() => {
442
+ if (!B) return;
443
+ const u = setTimeout(() => L(g), 400);
444
+ return () => clearTimeout(u);
445
+ }, [g, B]);
446
+ const F = async (u) => {
447
+ M(null), R(!0);
448
+ try {
449
+ const { mediaType: h, data: C } = await Le(u), E = await s.documentSetAsset(e.id, h, C, u.name, r, t);
450
+ c(E), a();
451
+ } catch (h) {
452
+ M(h instanceof Error ? h.message : String(h)), R(!1);
453
+ }
454
+ };
455
+ return /* @__PURE__ */ n("div", { className: "modal-overlay", onClick: a, children: /* @__PURE__ */ d("form", { className: "modal chunk-editor", onClick: (u) => u.stopPropagation(), onSubmit: async (u) => {
456
+ u.preventDefault(), M(null), j(!1);
457
+ const h = {
458
+ body: g,
459
+ title: o,
460
+ type: l,
461
+ status: p
270
462
  };
271
- if (y.trim() !== "")
463
+ if (N.trim() !== "")
272
464
  try {
273
- N.fields = JSON.parse(y);
465
+ h.fields = JSON.parse(N);
274
466
  } catch {
275
- D("fields must be valid JSON");
467
+ M("fields must be valid JSON");
276
468
  return;
277
469
  }
278
- L(!0);
470
+ R(!0);
279
471
  try {
280
- const C = await c.documentUpdateChunk(a.id, a.revision, N, e, r);
281
- s(C), n();
472
+ const C = await s.documentUpdateChunk(e.id, e.revision, h, r, t);
473
+ c(C), a();
282
474
  } catch (C) {
283
- const B = C instanceof Error ? C.message : String(C);
284
- D(B), R(/revision conflict/i.test(B)), L(!1);
475
+ const E = C instanceof Error ? C.message : String(C);
476
+ M(E), j(/revision conflict/i.test(E)), R(!1);
285
477
  }
286
478
  }, children: [
287
- /* @__PURE__ */ t("h3", { children: "Edit chunk" }),
479
+ /* @__PURE__ */ d("div", { className: "modal-header sticky-top", children: [
480
+ /* @__PURE__ */ n("h3", { children: "Edit chunk" }),
481
+ /* @__PURE__ */ d("div", { className: "modal-buttons modal-buttons-top", children: [
482
+ /* @__PURE__ */ n("button", { type: "button", onClick: a, disabled: U, children: "cancel" }),
483
+ /* @__PURE__ */ n("button", { type: "submit", className: "primary", disabled: U, children: U ? "saving…" : "save" })
484
+ ] })
485
+ ] }),
486
+ W && /* @__PURE__ */ d("div", { className: "modal-err", children: [
487
+ W,
488
+ z && " — reopen the chunk to load the latest, then reapply your edit."
489
+ ] }),
288
490
  /* @__PURE__ */ d("label", { className: "path-field", children: [
289
- /* @__PURE__ */ t("span", { children: "Title" }),
290
- /* @__PURE__ */ t("input", { className: "path-modal-input", value: l, onChange: (b) => i(b.target.value) })
491
+ /* @__PURE__ */ n("span", { children: "Title" }),
492
+ /* @__PURE__ */ n("input", { className: "path-modal-input", value: o, onChange: (u) => i(u.target.value) })
291
493
  ] }),
292
494
  /* @__PURE__ */ d("div", { className: "chunk-editor-row", children: [
293
495
  /* @__PURE__ */ d("label", { className: "path-field", children: [
294
- /* @__PURE__ */ t("span", { children: "Type" }),
295
- /* @__PURE__ */ t(
496
+ /* @__PURE__ */ n("span", { children: "Type" }),
497
+ /* @__PURE__ */ n(
296
498
  "input",
297
499
  {
298
500
  className: "path-modal-input",
299
- value: o,
501
+ value: l,
300
502
  placeholder: "(none)",
301
- onChange: (b) => u(b.target.value)
503
+ onChange: (u) => m(u.target.value)
302
504
  }
303
505
  )
304
506
  ] }),
305
507
  /* @__PURE__ */ d("label", { className: "path-field", children: [
306
- /* @__PURE__ */ t("span", { children: "Status" }),
307
- /* @__PURE__ */ t(
508
+ /* @__PURE__ */ n("span", { children: "Status" }),
509
+ /* @__PURE__ */ n(
308
510
  "input",
309
511
  {
310
512
  className: "path-modal-input",
311
- value: h,
513
+ value: p,
312
514
  placeholder: "(none)",
313
- onChange: (b) => x(b.target.value)
515
+ onChange: (u) => b(u.target.value)
314
516
  }
315
517
  )
316
518
  ] })
317
519
  ] }),
520
+ _ && /* @__PURE__ */ d("label", { className: "path-field", children: [
521
+ /* @__PURE__ */ n("span", { children: "Replace image" }),
522
+ /* @__PURE__ */ n(
523
+ "input",
524
+ {
525
+ type: "file",
526
+ accept: "image/png,image/jpeg,image/gif,image/webp",
527
+ disabled: U,
528
+ onChange: (u) => {
529
+ const h = u.target.files?.[0];
530
+ h && F(h);
531
+ }
532
+ }
533
+ )
534
+ ] }),
318
535
  /* @__PURE__ */ d("label", { className: "path-field", children: [
319
- /* @__PURE__ */ t("span", { children: "Body (Markdown)" }),
320
- /* @__PURE__ */ t(
536
+ /* @__PURE__ */ n("span", { children: B ? "Mermaid source" : _ ? "Caption (optional)" : "Body (Markdown)" }),
537
+ /* @__PURE__ */ n(
321
538
  "textarea",
322
539
  {
323
540
  className: "modal-textarea chunk-body-input",
324
- rows: 12,
325
- value: k,
326
- onChange: (b) => M(b.target.value)
541
+ rows: B ? 8 : 12,
542
+ value: g,
543
+ onChange: (u) => O(u.target.value)
327
544
  }
328
545
  )
329
546
  ] }),
547
+ B && /* @__PURE__ */ d("div", { className: "path-field", children: [
548
+ /* @__PURE__ */ n("span", { children: "Preview" }),
549
+ /* @__PURE__ */ n("div", { className: "chunk-mermaid-preview", children: w.trim() ? /* @__PURE__ */ n(ie, { code: w }) : /* @__PURE__ */ n("p", { className: "doc-empty-body", children: "(enter Mermaid source above)" }) })
550
+ ] }),
330
551
  /* @__PURE__ */ d("label", { className: "path-field", children: [
331
- /* @__PURE__ */ t("span", { children: "Fields (JSON, optional)" }),
332
- /* @__PURE__ */ t(
552
+ /* @__PURE__ */ n("span", { children: "Fields (JSON, optional)" }),
553
+ /* @__PURE__ */ n(
333
554
  "textarea",
334
555
  {
335
556
  className: "modal-textarea chunk-fields-input",
336
557
  rows: 4,
337
- value: y,
558
+ value: N,
338
559
  placeholder: "{}",
339
- onChange: (b) => E(b.target.value)
560
+ onChange: (u) => D(u.target.value)
340
561
  }
341
562
  )
342
- ] }),
343
- P && /* @__PURE__ */ d("div", { className: "modal-err", children: [
344
- P,
345
- W && " — reopen the chunk to load the latest, then reapply your edit."
346
- ] }),
347
- /* @__PURE__ */ d("div", { className: "modal-buttons", children: [
348
- /* @__PURE__ */ t("button", { type: "button", onClick: n, disabled: T, children: "cancel" }),
349
- /* @__PURE__ */ t("button", { type: "submit", className: "primary", disabled: T, children: T ? "saving…" : "save" })
350
563
  ] })
351
564
  ] }) });
352
565
  }
353
- function te({ source: a }) {
354
- return /* @__PURE__ */ t("div", { className: "md", children: xe(a) });
355
- }
356
- function xe(a) {
357
- const e = a.replace(/\r\n/g, `
358
- `).split(`
359
- `), r = [];
360
- let n = 0, s = 0;
361
- for (; n < e.length; ) {
362
- const c = e[n];
363
- if (c.trim() === "") {
364
- n++;
365
- continue;
366
- }
367
- if (c.startsWith("```")) {
368
- const h = [];
369
- for (n++; n < e.length && !e[n].startsWith("```"); )
370
- h.push(e[n]), n++;
371
- n++, r.push(
372
- /* @__PURE__ */ t("pre", { className: "md-pre", children: /* @__PURE__ */ t("code", { children: h.join(`
373
- `) }) }, s++)
374
- );
375
- continue;
566
+ function ut(e) {
567
+ const r = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec((e ?? "").trim());
568
+ if (!r) return "#888888";
569
+ let t = r[1];
570
+ return t.length === 3 && (t = t[0] + t[0] + t[1] + t[1] + t[2] + t[2]), "#" + t.toLowerCase();
571
+ }
572
+ function ht({
573
+ documentId: e,
574
+ rootChunkId: r,
575
+ docType: t,
576
+ docStatus: a,
577
+ chunkStatuses: c,
578
+ scope: s,
579
+ browse: o,
580
+ onClose: i,
581
+ onSaved: l
582
+ }) {
583
+ const m = se(), [p, b] = y(null), [g, O] = y(!1), [N, D] = y({}), [U, R] = y(!1), [W, M] = y(null), [z, j] = y(null), B = H(() => {
584
+ const u = new Set(Object.keys(me));
585
+ t && u.add(`doc.${t}.${a || "draft"}`);
586
+ for (const h of c) h && u.add(`chunk.${h}`);
587
+ return [...u].sort();
588
+ }, [t, a, c]);
589
+ I(() => {
590
+ let u = !1;
591
+ return m.documentGetChunk(r, s, o).then((h) => {
592
+ if (u) return;
593
+ b(h);
594
+ const C = h.fields ?? {};
595
+ O(C.color_enabled === !0);
596
+ const E = C.color_scheme ?? {};
597
+ D({ ...me, ...E });
598
+ }).catch((h) => !u && j(h instanceof Error ? h.message : String(h))), () => {
599
+ u = !0;
600
+ };
601
+ }, [m, r, s, o]);
602
+ const _ = (u, h) => D((C) => ({ ...C, [u]: h })), w = (u) => ({
603
+ ...u ?? {},
604
+ color_enabled: g,
605
+ color_scheme: N
606
+ }), L = async () => {
607
+ if (p) {
608
+ R(!0), j(null), M(null);
609
+ try {
610
+ await m.documentUpdateChunk(
611
+ r,
612
+ p.revision,
613
+ { fields: w(p.fields) },
614
+ s,
615
+ o
616
+ ), l(), i();
617
+ } catch (u) {
618
+ j(u instanceof Error ? u.message : String(u)), R(!1);
619
+ }
376
620
  }
377
- const l = /^(#{1,6})\s+(.*)$/.exec(c);
378
- if (l) {
379
- r.push(Ee(l[1].length, z(l[2]), s++)), n++;
380
- continue;
621
+ }, F = async () => {
622
+ if (!t) {
623
+ j("this document has no type to match");
624
+ return;
381
625
  }
382
- if (/^>\s?/.test(c)) {
383
- const h = [];
384
- for (; n < e.length && /^>\s?/.test(e[n]); )
385
- h.push(e[n].replace(/^>\s?/, "")), n++;
386
- r.push(
387
- /* @__PURE__ */ t("blockquote", { children: z(h.join(" ")) }, s++)
626
+ R(!0), j(null), M(null);
627
+ try {
628
+ const { documents: u } = await m.documentsSummary({ underPath: "/" }, s, o), h = (u ?? []).filter(
629
+ (E) => E.type === t && E.document_id !== e && E.root_chunk_id
388
630
  );
389
- continue;
390
- }
391
- const i = /^[-*]\s+(.*)$/, o = /^\d+\.\s+(.*)$/;
392
- if (i.test(c) || o.test(c)) {
393
- const h = o.test(c), x = h ? o : i, k = [];
394
- let M = 0;
395
- for (; n < e.length && x.test(e[n]); ) {
396
- const y = x.exec(e[n]);
397
- k.push(/* @__PURE__ */ t("li", { children: z(y[1]) }, M++)), n++;
398
- }
399
- r.push(h ? /* @__PURE__ */ t("ol", { children: k }, s++) : /* @__PURE__ */ t("ul", { children: k }, s++));
400
- continue;
631
+ let C = 0;
632
+ for (const E of h)
633
+ try {
634
+ const A = await m.documentGetChunk(E.root_chunk_id, s, o);
635
+ await m.documentUpdateChunk(
636
+ E.root_chunk_id,
637
+ A.revision,
638
+ { fields: w(A.fields) },
639
+ s,
640
+ o
641
+ ), C++;
642
+ } catch {
643
+ }
644
+ M(`Applied to ${C} other ${t} document(s).`), l();
645
+ } catch (u) {
646
+ j(u instanceof Error ? u.message : String(u));
647
+ } finally {
648
+ R(!1);
401
649
  }
402
- const u = [];
403
- for (; n < e.length && e[n].trim() !== "" && !e[n].startsWith("```") && !/^(#{1,6})\s+/.test(e[n]) && !/^>\s?/.test(e[n]) && !i.test(e[n]) && !o.test(e[n]); )
404
- u.push(e[n]), n++;
405
- r.push(/* @__PURE__ */ t("p", { children: z(u.join(" ")) }, s++));
406
- }
407
- return r;
408
- }
409
- function Ee(a, e, r) {
410
- switch (a) {
411
- case 1:
412
- return /* @__PURE__ */ t("h1", { children: e }, r);
413
- case 2:
414
- return /* @__PURE__ */ t("h2", { children: e }, r);
415
- case 3:
416
- return /* @__PURE__ */ t("h3", { children: e }, r);
417
- case 4:
418
- return /* @__PURE__ */ t("h4", { children: e }, r);
419
- case 5:
420
- return /* @__PURE__ */ t("h5", { children: e }, r);
421
- default:
422
- return /* @__PURE__ */ t("h6", { children: e }, r);
650
+ }, Q = B.filter((u) => u.startsWith("doc.")), X = B.filter((u) => u.startsWith("chunk."));
651
+ return /* @__PURE__ */ n("div", { className: "modal-overlay", onClick: i, children: /* @__PURE__ */ d("div", { className: "modal scheme-editor", onClick: (u) => u.stopPropagation(), children: [
652
+ /* @__PURE__ */ d("div", { className: "scheme-editor-head", children: [
653
+ /* @__PURE__ */ n("h3", { children: "Document colors" }),
654
+ /* @__PURE__ */ d("div", { className: "scheme-editor-actions", children: [
655
+ /* @__PURE__ */ n("button", { type: "button", onClick: i, disabled: U, children: "cancel" }),
656
+ /* @__PURE__ */ n("button", { type: "button", className: "primary", onClick: () => {
657
+ L();
658
+ }, disabled: U || !p, children: U ? "saving…" : "save" })
659
+ ] })
660
+ ] }),
661
+ z && /* @__PURE__ */ n("div", { className: "modal-err", children: z }),
662
+ p ? /* @__PURE__ */ d(q, { children: [
663
+ /* @__PURE__ */ d("label", { className: "scheme-toggle", children: [
664
+ /* @__PURE__ */ n(
665
+ "input",
666
+ {
667
+ type: "checkbox",
668
+ checked: g,
669
+ onChange: (u) => O(u.target.checked)
670
+ }
671
+ ),
672
+ /* @__PURE__ */ n("span", { children: "Enable coloring for this document" })
673
+ ] }),
674
+ /* @__PURE__ */ n("p", { className: "modal-context", children: "Document rows are tinted by type + status; chunk tiles by status. Colors apply as a semi-transparent wash so text stays readable." }),
675
+ /* @__PURE__ */ d("div", { className: "scheme-group", children: [
676
+ /* @__PURE__ */ n("h4", { children: "Document (type · status)" }),
677
+ Q.map((u) => /* @__PURE__ */ n(ve, { label: u.slice(4), value: N[u], onChange: (h) => _(u, h) }, u))
678
+ ] }),
679
+ /* @__PURE__ */ d("div", { className: "scheme-group", children: [
680
+ /* @__PURE__ */ n("h4", { children: "Chunks (status)" }),
681
+ X.map((u) => /* @__PURE__ */ n(ve, { label: u.slice(6), value: N[u], onChange: (h) => _(u, h) }, u))
682
+ ] }),
683
+ /* @__PURE__ */ d("div", { className: "scheme-editor-foot", children: [
684
+ /* @__PURE__ */ d("button", { type: "button", onClick: () => {
685
+ F();
686
+ }, disabled: U || !t, title: t ? `Apply this palette to every other ${t} document` : "This document has no type", children: [
687
+ "copy to all ",
688
+ t || "same-type",
689
+ " documents"
690
+ ] }),
691
+ W && /* @__PURE__ */ n("span", { className: "scheme-status", children: W })
692
+ ] })
693
+ ] }) : /* @__PURE__ */ n("p", { className: "modal-context", children: "Loading…" })
694
+ ] }) });
695
+ }
696
+ function ve({ label: e, value: r, onChange: t }) {
697
+ const a = ut(r);
698
+ return /* @__PURE__ */ d("label", { className: "scheme-row", children: [
699
+ /* @__PURE__ */ n("input", { type: "color", value: a, onChange: (c) => t(c.target.value) }),
700
+ /* @__PURE__ */ n("span", { className: "scheme-key", children: e }),
701
+ /* @__PURE__ */ n("code", { className: "scheme-hex", children: a })
702
+ ] });
703
+ }
704
+ const he = 24;
705
+ function mt({
706
+ edges: e,
707
+ documentId: r,
708
+ selectedId: t,
709
+ onSelectChunk: a
710
+ }) {
711
+ const [c, s] = y(!1), [o, i] = y(!1);
712
+ if (e.length === 0) return null;
713
+ const l = t ? e.filter((b) => b.from_id === t || b.to_id === t) : [], m = o ? e : e.slice(0, he), p = ft(m);
714
+ return /* @__PURE__ */ d("div", { className: "doc-refs", children: [
715
+ t && /* @__PURE__ */ d("div", { className: "doc-refs-list-wrap", children: [
716
+ /* @__PURE__ */ n("h4", { children: "References" }),
717
+ l.length === 0 ? /* @__PURE__ */ n("p", { className: "doc-refs-empty", children: "This chunk has no links." }) : /* @__PURE__ */ n("ul", { className: "doc-refs-list", children: l.map((b, g) => /* @__PURE__ */ n(
718
+ pt,
719
+ {
720
+ edge: b,
721
+ selectedId: t,
722
+ documentId: r,
723
+ onSelectChunk: a
724
+ },
725
+ `${b.from_id}-${b.to_id}-${b.kind}-${g}`
726
+ )) })
727
+ ] }),
728
+ /* @__PURE__ */ d("div", { className: "doc-graph", children: [
729
+ /* @__PURE__ */ d("button", { type: "button", className: "doc-graph-toggle", onClick: () => s((b) => !b), children: [
730
+ c ? "▼" : "▶",
731
+ " relationship graph (",
732
+ e.length,
733
+ ")"
734
+ ] }),
735
+ c && /* @__PURE__ */ d(q, { children: [
736
+ /* @__PURE__ */ n(ie, { code: p }),
737
+ e.length > he && /* @__PURE__ */ n("button", { type: "button", className: "doc-graph-more", onClick: () => i((b) => !b), children: o ? `show top ${he}` : `show all ${e.length}` })
738
+ ] })
739
+ ] })
740
+ ] });
741
+ }
742
+ function pt({
743
+ edge: e,
744
+ selectedId: r,
745
+ documentId: t,
746
+ onSelectChunk: a
747
+ }) {
748
+ const c = e.from_id === r, s = c ? e.to_id : e.from_id, o = (c ? e.to_title : e.from_title) || s.slice(0, 8), i = c ? e.to_document_id : e.from_document_id, l = !i || i === t;
749
+ return /* @__PURE__ */ d("li", { className: "doc-ref", children: [
750
+ /* @__PURE__ */ n("span", { className: "doc-ref-kind", children: e.kind }),
751
+ /* @__PURE__ */ n("span", { className: "doc-ref-arrow", "aria-hidden": !0, children: c ? "→" : "←" }),
752
+ l ? /* @__PURE__ */ n("button", { type: "button", className: "doc-ref-target", onClick: () => a(s), children: o }) : /* @__PURE__ */ d("span", { className: "doc-ref-target external", title: "In another document", children: [
753
+ o,
754
+ " ↗"
755
+ ] })
756
+ ] });
757
+ }
758
+ function ft(e) {
759
+ const r = ["graph LR"];
760
+ for (const t of e) {
761
+ const a = `${Ne(t.from_id)}["${we(t.from_title, t.from_id)}"]`, c = `${Ne(t.to_id)}["${we(t.to_title, t.to_id)}"]`, s = (t.kind || "link").replace(/[|"]/g, " ");
762
+ r.push(` ${a} -->|${s}| ${c}`);
423
763
  }
764
+ return r.join(`
765
+ `);
424
766
  }
425
- const Se = /(`[^`]+`)|(\*\*[^*]+?\*\*)|(\*[^*]+?\*)|(\[[^\]]+\]\([^)]+\))/;
426
- function z(a) {
427
- const e = [];
428
- let r = a, n = 0;
429
- for (; r.length > 0; ) {
430
- const s = Se.exec(r);
431
- if (!s) {
432
- e.push(r);
433
- break;
434
- }
435
- s.index > 0 && e.push(r.slice(0, s.index));
436
- const c = s[0];
437
- if (c.startsWith("`"))
438
- e.push(/* @__PURE__ */ t("code", { children: c.slice(1, -1) }, n++));
439
- else if (c.startsWith("**"))
440
- e.push(/* @__PURE__ */ t("strong", { children: c.slice(2, -2) }, n++));
441
- else if (c.startsWith("*"))
442
- e.push(/* @__PURE__ */ t("em", { children: c.slice(1, -1) }, n++));
443
- else {
444
- const l = /^\[([^\]]+)\]\(([^)]+)\)$/.exec(c), i = l[1], o = l[2], u = o.startsWith("/") && !o.startsWith("//");
445
- /^https?:\/\//i.test(o) || u ? e.push(
446
- /* @__PURE__ */ t("a", { href: o, target: "_blank", rel: "noopener noreferrer", children: i }, n++)
447
- ) : e.push(i);
448
- }
449
- r = r.slice(s.index + c.length);
767
+ function Ne(e) {
768
+ return "n" + e.replace(/[^a-zA-Z0-9]/g, "");
769
+ }
770
+ function we(e, r) {
771
+ const a = (e ?? "").replace(/["[\]{}|<>]/g, " ").replace(/\s+/g, " ").trim() || r.slice(0, 6);
772
+ return a.length > 30 ? a.slice(0, 29) + "…" : a;
773
+ }
774
+ function Ce({ source: e }) {
775
+ return /* @__PURE__ */ n("div", { className: "md", children: /* @__PURE__ */ n(qe, { remarkPlugins: [Qe], components: gt, children: e }) });
776
+ }
777
+ const gt = {
778
+ // react-markdown already sanitized the href; add target/rel for external links.
779
+ a({ href: e, children: r }) {
780
+ const t = e ?? "", a = /^https?:\/\//i.test(t);
781
+ return /* @__PURE__ */ n("a", { href: t, target: a ? "_blank" : void 0, rel: a ? "noopener noreferrer" : void 0, children: r });
782
+ },
783
+ // Let the code renderer own the block wrapper so a mermaid fence isn't wrapped
784
+ // in a <pre> (and a normal code block gets exactly one <pre>).
785
+ pre({ children: e }) {
786
+ return /* @__PURE__ */ n(q, { children: e });
787
+ },
788
+ code({ className: e, children: r }) {
789
+ const t = /language-(\w+)/.exec(e ?? "")?.[1], a = String(r ?? "");
790
+ return t === "mermaid" ? /* @__PURE__ */ n(ie, { code: a.replace(/\n$/, "") }) : t || a.includes(`
791
+ `) ? /* @__PURE__ */ n("pre", { className: "md-pre", children: /* @__PURE__ */ n("code", { className: e, children: r }) }) : /* @__PURE__ */ n("code", { children: r });
450
792
  }
451
- return e;
793
+ };
794
+ function yt(e) {
795
+ const r = e.fields ?? {};
796
+ return typeof r.alt == "string" && r.alt.trim() !== "" ? r.alt : e.title || "image";
452
797
  }
453
- function ie({
454
- documentId: a,
455
- scope: e,
456
- titleHint: r,
457
- browse: n,
458
- principal: s,
459
- renderAssistant: c
798
+ function Pe({
799
+ documentId: e,
800
+ scope: r,
801
+ titleHint: t,
802
+ browse: a,
803
+ principal: c,
804
+ renderAssistant: s
460
805
  }) {
461
- const l = X(), i = U(
462
- () => n && (n.scopeId || n.tenant) ? { scopeId: n.scopeId, tenant: n.tenant } : void 0,
463
- [n?.scopeId, n?.tenant]
464
- ), [o, u] = f([]), [h, x] = f(void 0), [k, M] = f(null), [y, E] = f("chunks"), [T, L] = f(null), [P, D] = f(null), [W, R] = f(null), [F, b] = f(!1), [N, C] = f(0), [B, J] = f(!1), m = S(() => C((g) => g + 1), []), A = U(() => ve(o), [o]), $ = U(() => o.find((w) => !w.parent_id)?.title || r || "document", [o, r]), V = U(
465
- () => !!k && !k.parent_id,
466
- [k]
806
+ const o = se(), i = H(
807
+ () => a && (a.scopeId || a.tenant) ? { scopeId: a.scopeId, tenant: a.tenant } : void 0,
808
+ [a?.scopeId, a?.tenant]
809
+ ), [l, m] = y([]), [p, b] = y(void 0), [g, O] = y(null), [N, D] = y("chunks"), [U, R] = y(null), [W, M] = y(null), [z, j] = y(null), B = K(null), [_, w] = y(null), [L, F] = y(null), [Q, X] = y(!1), [u, h] = y(0), [C, E] = y(!1), [A, ee] = y(null), [te, ne] = y(!1), [Y, ae] = y([]), v = G(() => h((f) => f + 1), []), $ = H(() => ot(l), [l]), P = H(() => l.find((k) => !k.parent_id)?.title || t || "document", [l, t]), V = H(
810
+ () => !!g && !g.parent_id,
811
+ [g]
812
+ ), J = H(
813
+ () => A?.root_chunk_id ?? l.find((f) => !f.parent_id)?.id,
814
+ [A, l]
815
+ ), Oe = H(
816
+ () => [...new Set(l.map((f) => f.status).filter((f) => !!f))],
817
+ [l]
818
+ ), re = !!A?.color_enabled, Ue = H(() => {
819
+ const f = /* @__PURE__ */ new Set();
820
+ for (const k of Y)
821
+ f.add(k.from_id), f.add(k.to_id);
822
+ return f;
823
+ }, [Y]), je = H(
824
+ () => re ? ge(De(A?.type, A?.status, fe(A?.color_scheme))) : void 0,
825
+ [re, A?.type, A?.status, A?.color_scheme]
467
826
  );
468
- j(() => {
469
- let g = !1;
470
- return b(!0), R(null), l.documentQueryChunks(a, e, i).then((w) => {
471
- if (g) return;
472
- const I = w.chunks ?? [];
473
- u(I), x((p) => p ?? I.find((v) => !v.parent_id)?.id);
474
- }).catch((w) => !g && R(w instanceof Error ? w.message : String(w))).finally(() => !g && b(!1)), () => {
475
- g = !0;
827
+ I(() => {
828
+ let f = !1;
829
+ return X(!0), F(null), o.documentQueryChunks(e, r, i).then((k) => {
830
+ if (f) return;
831
+ const S = k.chunks ?? [];
832
+ m(S), b((x) => x ?? S.find((T) => !T.parent_id)?.id);
833
+ }).catch((k) => !f && F(k instanceof Error ? k.message : String(k))).finally(() => !f && X(!1)), () => {
834
+ f = !0;
835
+ };
836
+ }, [o, e, r, u, i]), I(() => {
837
+ let f = !1;
838
+ return o.documentGet(e, r, i).then((k) => !f && ee(k)).catch(() => !f && ee(null)), () => {
839
+ f = !0;
840
+ };
841
+ }, [o, e, r, u, i]), I(() => {
842
+ let f = !1;
843
+ return o.documentGetEdges(e, r, i).then((k) => !f && ae(k.edges ?? [])).catch(() => !f && ae([])), () => {
844
+ f = !0;
476
845
  };
477
- }, [l, a, e, N, i]), j(() => {
478
- x(void 0), M(null), L(null), E("chunks");
479
- }, [a, e]), j(() => {
480
- if (!h) {
481
- M(null);
846
+ }, [o, e, r, u, i]), I(() => {
847
+ b(void 0), O(null), R(null), D("chunks"), ee(null), ae([]);
848
+ }, [e, r]), I(() => {
849
+ if (!p) {
850
+ O(null);
482
851
  return;
483
852
  }
484
- let g = !1;
485
- return l.documentGetChunk(h, e, i).then((w) => !g && M(w)).catch((w) => !g && R(w instanceof Error ? w.message : String(w))), () => {
486
- g = !0;
853
+ let f = !1;
854
+ return o.documentGetChunk(p, r, i).then((k) => !f && O(k)).catch((k) => !f && F(k instanceof Error ? k.message : String(k))), () => {
855
+ f = !0;
856
+ };
857
+ }, [o, p, r, u, i]), I(() => {
858
+ const f = g?.type === "image" || !!g?.asset;
859
+ if (!g || !f || !o.documentAssetObjectUrl) {
860
+ M(null), j(null);
861
+ return;
862
+ }
863
+ let k = !1, S = null;
864
+ return j(null), o.documentAssetObjectUrl(g.id, r, i).then((x) => {
865
+ if (k) {
866
+ URL.revokeObjectURL(x);
867
+ return;
868
+ }
869
+ S = x, M(x);
870
+ }).catch((x) => !k && j(x instanceof Error ? x.message : String(x))), () => {
871
+ k = !0, S && URL.revokeObjectURL(S);
487
872
  };
488
- }, [l, h, e, N, i]), j(() => {
489
- if (y !== "markdown" || !h) {
490
- L(null);
873
+ }, [o, g, r, i]), I(() => {
874
+ if (N !== "markdown" || !p) {
875
+ R(null);
491
876
  return;
492
877
  }
493
- const g = ce(A, h);
494
- if (!g) return;
495
- let w = !1;
496
- const I = [], p = (v, _) => {
497
- I.push({ node: v, depth: _ }), v.children.forEach((O) => p(O, _ + 1));
878
+ const f = Re($, p);
879
+ if (!f) return;
880
+ let k = !1;
881
+ const S = [], x = (T, ce) => {
882
+ S.push({ node: T, depth: ce }), T.children.forEach((oe) => x(oe, ce + 1));
498
883
  };
499
- return p(g, 0), Promise.all(I.map((v) => l.documentGetChunk(v.node.row.id, e, i))).then((v) => {
500
- if (w) return;
501
- const _ = I.map((O, he) => {
502
- const me = Math.min(O.depth + 1, 6), Y = v[he];
503
- return "#".repeat(me) + " " + O.node.row.title + (Y.body ? `
884
+ return x(f, 0), Promise.all(S.map((T) => o.documentGetChunk(T.node.row.id, r, i))).then((T) => {
885
+ if (k) return;
886
+ const ce = S.map((oe, He) => {
887
+ const We = Math.min(oe.depth + 1, 6), Z = T[He], ue = "#".repeat(We) + " " + oe.node.row.title;
888
+ if (Z.type === "mermaid" && Z.body)
889
+ return ue + "\n\n```mermaid\n" + Z.body + "\n```\n";
890
+ if (Z.type === "image" || Z.asset) {
891
+ const ze = Z.body ? " — " + Z.body : "";
892
+ return ue + `
504
893
 
505
- ` + Y.body : "") + `
894
+ _🖼 image chunk_` + ze + `
895
+ `;
896
+ }
897
+ return ue + (Z.body ? `
898
+
899
+ ` + Z.body : "") + `
506
900
  `;
507
901
  }).join(`
508
902
  `);
509
- L(_);
510
- }).catch((v) => !w && R(v instanceof Error ? v.message : String(v))), () => {
511
- w = !0;
903
+ R(ce);
904
+ }).catch((T) => !k && F(T instanceof Error ? T.message : String(T))), () => {
905
+ k = !0;
512
906
  };
513
- }, [l, y, h, A, e, N, i]);
514
- const Z = S((g) => x(g.row.id), []), q = S(async () => {
907
+ }, [o, N, p, $, r, u, i]);
908
+ const Fe = G((f) => b(f.row.id), []), Ge = G(async () => {
515
909
  try {
516
- const g = await l.documentExportMd(a, e, !0, i), w = new Blob([g.markdown], { type: "text/markdown" }), I = URL.createObjectURL(w), p = document.createElement("a");
517
- p.href = I, p.download = (g.title || "document").replace(/[^\w.-]+/g, "_") + ".md", p.click(), URL.revokeObjectURL(I);
518
- } catch (g) {
519
- R(g instanceof Error ? g.message : String(g));
910
+ const f = await o.documentExportMd(e, r, !0, i), k = new Blob([f.markdown], { type: "text/markdown" }), S = URL.createObjectURL(k), x = document.createElement("a");
911
+ x.href = S, x.download = (f.title || "document").replace(/[^\w.-]+/g, "_") + ".md", x.click(), URL.revokeObjectURL(S);
912
+ } catch (f) {
913
+ F(f instanceof Error ? f.message : String(f));
914
+ }
915
+ }, [o, e, r, i]), le = !!o.documentCreateChunk && !!J, de = G(
916
+ async (f) => {
917
+ if (!o.documentCreateChunk || !o.documentSetAsset) return;
918
+ const k = p || J;
919
+ if (k) {
920
+ F(null);
921
+ try {
922
+ const { mediaType: S, data: x } = await Le(f), T = await o.documentCreateChunk(
923
+ e,
924
+ k,
925
+ { title: f.name || "image", type: "image" },
926
+ r,
927
+ i
928
+ );
929
+ await o.documentSetAsset(T.id, S, x, f.name, r, i), v(), b(T.id);
930
+ } catch (S) {
931
+ F(S instanceof Error ? S.message : String(S));
932
+ }
933
+ }
934
+ },
935
+ [o, e, r, i, p, J, v]
936
+ ), Be = G(async () => {
937
+ if (!o.documentCreateChunk) return;
938
+ const f = p || J;
939
+ if (f) {
940
+ F(null);
941
+ try {
942
+ const k = await o.documentCreateChunk(
943
+ e,
944
+ f,
945
+ { title: "Diagram", type: "mermaid", body: `graph TD
946
+ A[Start] --> B[End]` },
947
+ r,
948
+ i
949
+ );
950
+ v(), b(k.id), w(k);
951
+ } catch (k) {
952
+ F(k instanceof Error ? k.message : String(k));
953
+ }
520
954
  }
521
- }, [l, a, e, i]);
522
- return /* @__PURE__ */ d("div", { className: "doc-viewer", children: [
523
- /* @__PURE__ */ d("div", { className: "doc-toolbar", children: [
524
- /* @__PURE__ */ t("strong", { className: "doc-title", title: $, children: $ }),
955
+ }, [o, e, r, i, p, J, v]);
956
+ return I(() => {
957
+ if (!le) return;
958
+ const f = (k) => {
959
+ if (_ || te) return;
960
+ const S = document.activeElement, x = S?.tagName;
961
+ if (x === "INPUT" || x === "TEXTAREA" || S?.isContentEditable) return;
962
+ const T = nt(k.clipboardData?.items);
963
+ T && (k.preventDefault(), de(T));
964
+ };
965
+ return window.addEventListener("paste", f), () => window.removeEventListener("paste", f);
966
+ }, [le, _, te, de]), /* @__PURE__ */ d("div", { className: "doc-viewer", children: [
967
+ /* @__PURE__ */ n(
968
+ "input",
969
+ {
970
+ ref: B,
971
+ type: "file",
972
+ accept: "image/png,image/jpeg,image/gif,image/webp",
973
+ style: { display: "none" },
974
+ onChange: (f) => {
975
+ const k = f.target.files?.[0];
976
+ f.target.value = "", k && de(k);
977
+ }
978
+ }
979
+ ),
980
+ /* @__PURE__ */ d("div", { className: "doc-toolbar", style: je, children: [
981
+ /* @__PURE__ */ n("strong", { className: "doc-title", title: P, children: P }),
525
982
  /* @__PURE__ */ d("div", { className: "doc-toolbar-actions", children: [
526
- /* @__PURE__ */ t("button", { type: "button", onClick: () => {
527
- q();
983
+ le && /* @__PURE__ */ d(q, { children: [
984
+ /* @__PURE__ */ n(
985
+ "button",
986
+ {
987
+ type: "button",
988
+ onClick: () => B.current?.click(),
989
+ title: "Add an image chunk (upload — or paste a screenshot into the view)",
990
+ children: "+ image"
991
+ }
992
+ ),
993
+ /* @__PURE__ */ n(
994
+ "button",
995
+ {
996
+ type: "button",
997
+ onClick: () => {
998
+ Be();
999
+ },
1000
+ title: "Add a Mermaid diagram chunk",
1001
+ children: "+ diagram"
1002
+ }
1003
+ )
1004
+ ] }),
1005
+ /* @__PURE__ */ n(
1006
+ "button",
1007
+ {
1008
+ type: "button",
1009
+ className: re ? "active" : "",
1010
+ onClick: () => ne(!0),
1011
+ disabled: !J,
1012
+ title: "Colors — tint chunk tiles + the Path tree by type/status",
1013
+ children: "colors"
1014
+ }
1015
+ ),
1016
+ /* @__PURE__ */ n("button", { type: "button", onClick: () => {
1017
+ Ge();
528
1018
  }, title: "Download the whole document as Markdown (.md)", children: "↓ .md" }),
529
- c && /* @__PURE__ */ t(
1019
+ s && /* @__PURE__ */ n(
530
1020
  "button",
531
1021
  {
532
1022
  type: "button",
533
- className: B ? "active" : "",
534
- onClick: () => J((g) => !g),
1023
+ className: C ? "active" : "",
1024
+ onClick: () => E((f) => !f),
535
1025
  title: "Document Assistant — instruct an agent to restructure/import/link chunks",
536
1026
  children: "assistant"
537
1027
  }
538
1028
  ),
539
- /* @__PURE__ */ t("button", { type: "button", onClick: m, title: "Reload", children: "↻" })
1029
+ /* @__PURE__ */ n("button", { type: "button", onClick: v, title: "Reload", children: "↻" })
540
1030
  ] })
541
1031
  ] }),
542
- W && /* @__PURE__ */ t("div", { className: "paths-err", children: W }),
1032
+ L && /* @__PURE__ */ n("div", { className: "paths-err", children: L }),
543
1033
  /* @__PURE__ */ d("div", { className: "doc-split", children: [
544
- /* @__PURE__ */ t("div", { className: "doc-chunktree", children: F && o.length === 0 ? /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Loading…" }) }) : /* @__PURE__ */ t(Ne, { tree: A, selectedId: h, onSelect: Z }) }),
545
- /* @__PURE__ */ t("div", { className: "doc-content", children: k ? /* @__PURE__ */ d(G, { children: [
1034
+ /* @__PURE__ */ n("div", { className: "doc-chunktree", children: Q && l.length === 0 ? /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "Loading…" }) }) : /* @__PURE__ */ n(
1035
+ st,
1036
+ {
1037
+ tree: $,
1038
+ selectedId: p,
1039
+ onSelect: Fe,
1040
+ colorEnabled: re,
1041
+ scheme: A?.color_scheme,
1042
+ linkedIds: Ue
1043
+ }
1044
+ ) }),
1045
+ /* @__PURE__ */ n("div", { className: "doc-content", children: g ? /* @__PURE__ */ d(q, { children: [
546
1046
  /* @__PURE__ */ d("div", { className: "doc-content-head", children: [
547
- /* @__PURE__ */ t("h3", { children: k.title || "(untitled)" }),
1047
+ /* @__PURE__ */ n("h3", { children: g.title || "(untitled)" }),
548
1048
  /* @__PURE__ */ d("div", { className: "doc-content-meta", children: [
549
- k.type && /* @__PURE__ */ t("span", { className: "chunk-badge", children: k.type }),
550
- k.status && /* @__PURE__ */ t("span", { className: "chunk-badge chunk-status", children: k.status }),
1049
+ g.type && /* @__PURE__ */ n("span", { className: "chunk-badge", children: g.type }),
1050
+ g.status && /* @__PURE__ */ n("span", { className: "chunk-badge chunk-status", children: g.status }),
551
1051
  /* @__PURE__ */ d("span", { className: "chunk-rev", children: [
552
1052
  "rev ",
553
- k.revision
1053
+ g.revision
554
1054
  ] })
555
1055
  ] }),
556
1056
  /* @__PURE__ */ d("div", { className: "doc-content-controls", children: [
557
1057
  /* @__PURE__ */ d("div", { className: "doc-mode-toggle", children: [
558
- /* @__PURE__ */ t(
1058
+ /* @__PURE__ */ n(
559
1059
  "button",
560
1060
  {
561
1061
  type: "button",
562
- className: y === "chunks" ? "active" : "",
563
- onClick: () => E("chunks"),
1062
+ className: N === "chunks" ? "active" : "",
1063
+ onClick: () => D("chunks"),
564
1064
  title: "This chunk's own content",
565
1065
  children: "chunk"
566
1066
  }
567
1067
  ),
568
- /* @__PURE__ */ t(
1068
+ /* @__PURE__ */ n(
569
1069
  "button",
570
1070
  {
571
1071
  type: "button",
572
- className: y === "markdown" ? "active" : "",
573
- onClick: () => E("markdown"),
1072
+ className: N === "markdown" ? "active" : "",
1073
+ onClick: () => D("markdown"),
574
1074
  title: V ? "Whole document as Markdown" : "This chunk + its sub-chunks as Markdown",
575
1075
  children: "markdown"
576
1076
  }
577
1077
  )
578
1078
  ] }),
579
- /* @__PURE__ */ t("button", { type: "button", onClick: () => D(k), children: "edit" })
1079
+ /* @__PURE__ */ n("button", { type: "button", onClick: () => w(g), children: "edit" })
580
1080
  ] })
581
1081
  ] }),
582
- /* @__PURE__ */ t("div", { className: "doc-content-body", children: y === "markdown" ? T !== null ? /* @__PURE__ */ t(te, { source: T }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "Assembling Markdown…" }) : k.body ? /* @__PURE__ */ t(te, { source: k.body }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "(empty chunk)" }) })
583
- ] }) : /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Select a chunk on the left." }) }) })
1082
+ /* @__PURE__ */ n("div", { className: "doc-content-body", children: g.type === "mermaid" ? (
1083
+ // RFC BO — a diagram chunk: body IS the Mermaid source.
1084
+ g.body ? /* @__PURE__ */ d(q, { children: [
1085
+ /* @__PURE__ */ n(ie, { code: g.body }),
1086
+ N === "markdown" && /* @__PURE__ */ n("pre", { className: "md-pre doc-mermaid-source", children: /* @__PURE__ */ n("code", { children: g.body }) })
1087
+ ] }) : /* @__PURE__ */ n("p", { className: "doc-empty-body", children: "(empty diagram)" })
1088
+ ) : g.type === "image" || g.asset ? (
1089
+ // RFC BO — an image chunk: bytes come from the auth'd asset GET.
1090
+ z ? /* @__PURE__ */ d("p", { className: "doc-empty-body", children: [
1091
+ "Image failed to load: ",
1092
+ z
1093
+ ] }) : W ? /* @__PURE__ */ d("figure", { className: "doc-image", children: [
1094
+ /* @__PURE__ */ n("img", { src: W, alt: yt(g) }),
1095
+ g.body && /* @__PURE__ */ n("figcaption", { children: g.body })
1096
+ ] }) : /* @__PURE__ */ n("p", { className: "doc-empty-body", children: "Loading image…" })
1097
+ ) : N === "markdown" ? U !== null ? /* @__PURE__ */ n(Ce, { source: U }) : /* @__PURE__ */ n("p", { className: "doc-empty-body", children: "Assembling Markdown…" }) : g.body ? /* @__PURE__ */ n(Ce, { source: g.body }) : /* @__PURE__ */ n("p", { className: "doc-empty-body", children: "(empty chunk)" }) }),
1098
+ /* @__PURE__ */ n(
1099
+ mt,
1100
+ {
1101
+ edges: Y,
1102
+ documentId: e,
1103
+ selectedId: p,
1104
+ onSelectChunk: b
1105
+ }
1106
+ )
1107
+ ] }) : /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "Select a chunk on the left." }) }) })
584
1108
  ] }),
585
- B && c && /* @__PURE__ */ t("div", { className: "doc-assistant", children: c({
586
- documentId: a,
587
- scope: e,
588
- subject: s?.subject,
1109
+ C && s && /* @__PURE__ */ n("div", { className: "doc-assistant", children: s({
1110
+ documentId: e,
1111
+ scope: r,
1112
+ subject: c?.subject,
589
1113
  // Pass the viewer's own reload so the injected assistant can refresh
590
1114
  // the tree + selected chunk after a turn mutates the document.
591
- onChanged: m
1115
+ onChanged: v
592
1116
  }) }),
593
- P && /* @__PURE__ */ t(
594
- Ce,
1117
+ _ && /* @__PURE__ */ n(
1118
+ dt,
1119
+ {
1120
+ chunk: _,
1121
+ scope: r,
1122
+ browse: i,
1123
+ onClose: () => w(null),
1124
+ onSaved: v
1125
+ }
1126
+ ),
1127
+ te && J && /* @__PURE__ */ n(
1128
+ ht,
595
1129
  {
596
- chunk: P,
597
- scope: e,
1130
+ documentId: e,
1131
+ rootChunkId: J,
1132
+ docType: A?.type,
1133
+ docStatus: A?.status,
1134
+ chunkStatuses: Oe,
1135
+ scope: r,
598
1136
  browse: i,
599
- onClose: () => D(null),
600
- onSaved: m
1137
+ onClose: () => ne(!1),
1138
+ onSaved: v
601
1139
  }
602
1140
  )
603
1141
  ] });
604
1142
  }
605
- function De(a) {
606
- const e = {
1143
+ function bt(e) {
1144
+ const r = {
607
1145
  name: "",
608
1146
  fullPath: "",
609
1147
  kind: "directory",
610
1148
  explicit: !0,
611
1149
  children: []
612
- }, r = /* @__PURE__ */ new Map([["", e]]), n = (c) => {
613
- const l = r.get(c);
614
- if (l) return l;
615
- const i = c.lastIndexOf("/"), o = i <= 0 ? "" : c.slice(0, i), u = c.slice(i + 1), h = n(o), x = {
616
- name: u,
617
- fullPath: c,
1150
+ }, t = /* @__PURE__ */ new Map([["", r]]), a = (s) => {
1151
+ const o = t.get(s);
1152
+ if (o) return o;
1153
+ const i = s.lastIndexOf("/"), l = i <= 0 ? "" : s.slice(0, i), m = s.slice(i + 1), p = a(l), b = {
1154
+ name: m,
1155
+ fullPath: s,
618
1156
  kind: "directory",
619
1157
  explicit: !1,
620
1158
  children: []
621
1159
  };
622
- return h.children.push(x), r.set(c, x), x;
1160
+ return p.children.push(b), t.set(s, b), b;
623
1161
  };
624
- for (const c of a) {
625
- const l = n(c.full_path);
626
- l.kind = c.kind, l.explicit = !0, l.resourceRef = c.resource_ref;
1162
+ for (const s of e) {
1163
+ const o = a(s.full_path);
1164
+ o.kind = s.kind, o.explicit = !0, o.resourceRef = s.resource_ref;
627
1165
  }
628
- const s = (c) => {
629
- c.sort((l, i) => {
630
- const o = l.kind === "directory", u = i.kind === "directory";
631
- return o !== u ? o ? -1 : 1 : l.name.localeCompare(i.name);
632
- }), c.forEach((l) => s(l.children));
1166
+ const c = (s) => {
1167
+ s.sort((o, i) => {
1168
+ const l = o.kind === "directory", m = i.kind === "directory";
1169
+ return l !== m ? l ? -1 : 1 : o.name.localeCompare(i.name);
1170
+ }), s.forEach((o) => c(o.children));
633
1171
  };
634
- return s(e.children), e.children;
1172
+ return c(r.children), r.children;
635
1173
  }
636
- function Q(a) {
637
- const e = a.lastIndexOf("/");
638
- return e <= 0 ? "" : a.slice(0, e);
1174
+ function pe(e) {
1175
+ const r = e.lastIndexOf("/");
1176
+ return r <= 0 ? "" : e.slice(0, r);
639
1177
  }
640
- function Me(a) {
641
- const e = [], r = (n) => {
642
- if (n.kind === "document") {
643
- const s = n.resourceRef;
644
- s?.document_id && e.push(s.document_id);
1178
+ function kt(e) {
1179
+ const r = [], t = (a) => {
1180
+ if (a.kind === "document") {
1181
+ const c = a.resourceRef;
1182
+ c?.document_id && r.push(c.document_id);
645
1183
  }
646
- n.children.forEach(r);
1184
+ a.children.forEach(t);
647
1185
  };
648
- return r(a), e;
1186
+ return t(e), r;
649
1187
  }
650
- const _e = {
1188
+ const vt = {
651
1189
  directory: "📁",
652
1190
  document: "📄",
653
1191
  volume_mount: "💾",
654
1192
  memory_entry: "🧠"
655
1193
  };
656
- function Le({ tree: a, selectedPath: e, onSelect: r }) {
657
- const [n, s] = f(() => /* @__PURE__ */ new Map()), c = S((l) => {
658
- s((i) => {
659
- const o = new Map(i);
660
- return o.set(l, i.get(l) === !1), o;
1194
+ function Nt({ tree: e, selectedPath: r, onSelect: t, summaries: a }) {
1195
+ const [c, s] = y(() => /* @__PURE__ */ new Map()), o = G((i) => {
1196
+ s((l) => {
1197
+ const m = new Map(l);
1198
+ return m.set(i, l.get(i) === !1), m;
661
1199
  });
662
1200
  }, []);
663
- return j(() => {
664
- e && s((l) => {
665
- let i = !1;
666
- const o = new Map(l);
667
- let u = Q(e);
668
- for (; u !== ""; )
669
- o.get(u) === !1 && (o.set(u, !0), i = !0), u = Q(u);
670
- return i ? o : l;
1201
+ return I(() => {
1202
+ r && s((i) => {
1203
+ let l = !1;
1204
+ const m = new Map(i);
1205
+ let p = pe(r);
1206
+ for (; p !== ""; )
1207
+ m.get(p) === !1 && (m.set(p, !0), l = !0), p = pe(p);
1208
+ return l ? m : i;
671
1209
  });
672
- }, [e]), a.length === 0 ? /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "This tree is empty. Create a folder or document to begin." }) }) : /* @__PURE__ */ t("ul", { className: "tree path-tree", children: a.map((l) => /* @__PURE__ */ t(
673
- de,
1210
+ }, [r]), e.length === 0 ? /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "This tree is empty. Create a folder or document to begin." }) }) : /* @__PURE__ */ n("ul", { className: "tree path-tree", children: e.map((i) => /* @__PURE__ */ n(
1211
+ Te,
674
1212
  {
675
- node: l,
676
- expanded: n,
677
- toggle: c,
678
- selectedPath: e,
679
- onSelect: r
1213
+ node: i,
1214
+ expanded: c,
1215
+ toggle: o,
1216
+ selectedPath: r,
1217
+ onSelect: t,
1218
+ summaries: a
680
1219
  },
681
- l.fullPath
1220
+ i.fullPath
682
1221
  )) });
683
1222
  }
684
- function de({ node: a, expanded: e, toggle: r, selectedPath: n, onSelect: s }) {
685
- const c = a.children.length > 0, l = e.get(a.fullPath) !== !1, i = n === a.fullPath;
686
- return /* @__PURE__ */ d("li", { className: `node path-node kind-${a.kind} ${i ? "selected" : ""}`, children: [
687
- /* @__PURE__ */ d("div", { className: "row path-row", children: [
688
- /* @__PURE__ */ t(
1223
+ function wt(e, r) {
1224
+ if (e.kind !== "document" || !r) return;
1225
+ const t = e.resourceRef;
1226
+ return t?.document_id ? r.get(t.document_id) : void 0;
1227
+ }
1228
+ function Te({ node: e, expanded: r, toggle: t, selectedPath: a, onSelect: c, summaries: s }) {
1229
+ const o = e.children.length > 0, i = r.get(e.fullPath) !== !1, l = a === e.fullPath, m = wt(e, s), p = m && m.color_enabled ? ge(De(m.type, m.status, fe(m.color_scheme))) : void 0;
1230
+ return /* @__PURE__ */ d("li", { className: `node path-node kind-${e.kind} ${l ? "selected" : ""}`, children: [
1231
+ /* @__PURE__ */ d("div", { className: "row path-row", style: p, children: [
1232
+ /* @__PURE__ */ n(
689
1233
  "button",
690
1234
  {
691
1235
  type: "button",
692
1236
  className: "tree-caret",
693
- "aria-label": l ? "collapse" : "expand",
694
- disabled: !c,
695
- onClick: (o) => {
696
- o.stopPropagation(), c && r(a.fullPath);
1237
+ "aria-label": i ? "collapse" : "expand",
1238
+ disabled: !o,
1239
+ onClick: (b) => {
1240
+ b.stopPropagation(), o && t(e.fullPath);
697
1241
  },
698
- children: c ? l ? "▼" : "▶" : "·"
1242
+ children: o ? i ? "▼" : "▶" : "·"
699
1243
  }
700
1244
  ),
701
1245
  /* @__PURE__ */ d(
@@ -703,166 +1247,192 @@ function de({ node: a, expanded: e, toggle: r, selectedPath: n, onSelect: s }) {
703
1247
  {
704
1248
  type: "button",
705
1249
  className: "path-link",
706
- onClick: () => s(a),
707
- title: a.fullPath,
1250
+ onClick: () => c(e),
1251
+ title: e.fullPath,
708
1252
  children: [
709
- /* @__PURE__ */ t("span", { className: "path-kind-icon", "aria-hidden": !0, children: _e[a.kind] ?? "•" }),
710
- /* @__PURE__ */ t("span", { className: "path-name", children: a.name }),
711
- !a.explicit && /* @__PURE__ */ t("span", { className: "path-implicit", title: "Implicit directory (no stored entry)", children: "implicit" })
1253
+ /* @__PURE__ */ n("span", { className: "path-kind-icon", "aria-hidden": !0, children: vt[e.kind] ?? "•" }),
1254
+ /* @__PURE__ */ n("span", { className: "path-name", children: e.name }),
1255
+ m?.type && /* @__PURE__ */ n("span", { className: "chunk-badge", children: m.type }),
1256
+ m?.status && /* @__PURE__ */ n("span", { className: "chunk-badge chunk-status", children: m.status }),
1257
+ !e.explicit && /* @__PURE__ */ n("span", { className: "path-implicit", title: "Implicit directory (no stored entry)", children: "implicit" })
712
1258
  ]
713
1259
  }
714
1260
  )
715
1261
  ] }),
716
- c && l && /* @__PURE__ */ t("ul", { className: "children path-children", children: a.children.map((o) => /* @__PURE__ */ t(
717
- de,
1262
+ o && i && /* @__PURE__ */ n("ul", { className: "children path-children", children: e.children.map((b) => /* @__PURE__ */ n(
1263
+ Te,
718
1264
  {
719
- node: o,
720
- expanded: e,
721
- toggle: r,
722
- selectedPath: n,
723
- onSelect: s
1265
+ node: b,
1266
+ expanded: r,
1267
+ toggle: t,
1268
+ selectedPath: a,
1269
+ onSelect: c,
1270
+ summaries: s
724
1271
  },
725
- o.fullPath
1272
+ b.fullPath
726
1273
  )) })
727
1274
  ] });
728
1275
  }
729
- const ne = /^[A-Za-z0-9._-]+$/;
730
- function ae(a, e) {
731
- return `${a}/${e}`;
1276
+ const _e = /^[A-Za-z0-9._-]+$/;
1277
+ function Ee(e, r) {
1278
+ return `${e}/${r}`;
732
1279
  }
733
- function ue(a, e) {
734
- for (const r of a) {
735
- if (r.fullPath === e) return r;
736
- const n = ue(r.children, e);
737
- if (n) return n;
1280
+ function Ie(e, r) {
1281
+ for (const t of e) {
1282
+ if (t.fullPath === r) return t;
1283
+ const a = Ie(t.children, r);
1284
+ if (a) return a;
738
1285
  }
739
1286
  }
740
- function Oe(a) {
741
- const { theme: e, defaultScope: r, path: n, onPathChange: s, browse: c, principal: l, renderAssistant: i, onError: o } = a, u = le(a);
742
- return /* @__PURE__ */ t(se, { theme: e, dataLayer: u, children: /* @__PURE__ */ t(
743
- Re,
1287
+ function Lt(e) {
1288
+ const { theme: r, defaultScope: t, path: a, onPathChange: c, browse: s, principal: o, renderAssistant: i, onError: l } = e, m = xe(e);
1289
+ return /* @__PURE__ */ n($e, { theme: r, dataLayer: m, children: /* @__PURE__ */ n(
1290
+ Ct,
744
1291
  {
745
- defaultScope: r,
746
- path: n,
747
- onPathChange: s,
748
- browse: c,
749
- principal: l,
1292
+ defaultScope: t,
1293
+ path: a,
1294
+ onPathChange: c,
1295
+ browse: s,
1296
+ principal: o,
750
1297
  renderAssistant: i,
751
- onError: o
1298
+ onError: l
752
1299
  }
753
1300
  ) });
754
1301
  }
755
- function Re({
756
- defaultScope: a,
757
- path: e,
758
- onPathChange: r,
759
- browse: n,
760
- principal: s,
761
- renderAssistant: c,
762
- onError: l
1302
+ function Ct({
1303
+ defaultScope: e,
1304
+ path: r,
1305
+ onPathChange: t,
1306
+ browse: a,
1307
+ principal: c,
1308
+ renderAssistant: s,
1309
+ onError: o
763
1310
  }) {
764
- const i = X(), [o, u] = f(a ?? "user"), [h, x] = f([]), [k, M] = f(void 0), [y, E] = f(null), [T, L] = f(!1), [P, D] = f(null), W = e !== void 0 ? e : k, R = H(r);
765
- j(() => {
766
- R.current = r;
767
- }, [r]);
768
- const F = H(l);
769
- j(() => {
770
- F.current = l;
771
- }, [l]);
772
- const b = S((p) => {
773
- R.current?.(p), M(p);
774
- }, []), N = U(
775
- () => n && (n.scopeId || n.tenant) ? { scopeId: n.scopeId, tenant: n.tenant } : void 0,
776
- [n?.scopeId, n?.tenant]
777
- ), C = S(async () => {
778
- L(!0), E(null);
1311
+ const i = se(), [l, m] = y(e ?? "user"), [p, b] = y([]), [g, O] = y(void 0), [N, D] = y(null), [U, R] = y(!1), [W, M] = y(null), z = r !== void 0 ? r : g, j = K(t);
1312
+ I(() => {
1313
+ j.current = t;
1314
+ }, [t]);
1315
+ const B = K(o);
1316
+ I(() => {
1317
+ B.current = o;
1318
+ }, [o]);
1319
+ const _ = G((v) => {
1320
+ j.current?.(v), O(v);
1321
+ }, []), w = H(
1322
+ () => a && (a.scopeId || a.tenant) ? { scopeId: a.scopeId, tenant: a.tenant } : void 0,
1323
+ [a?.scopeId, a?.tenant]
1324
+ ), L = G(async () => {
1325
+ R(!0), D(null);
779
1326
  try {
780
- const p = await i.pathLs("/", o, !0, N);
781
- x(p.entries ?? []);
782
- } catch (p) {
783
- E(p instanceof Error ? p.message : String(p)), x([]), F.current?.(p);
1327
+ const v = await i.pathLs("/", l, !0, w);
1328
+ b(v.entries ?? []);
1329
+ } catch (v) {
1330
+ D(v instanceof Error ? v.message : String(v)), b([]), B.current?.(v);
784
1331
  } finally {
785
- L(!1);
1332
+ R(!1);
1333
+ }
1334
+ }, [i, l, w]), F = K(!0);
1335
+ I(() => {
1336
+ F.current ? F.current = !1 : _(void 0), L();
1337
+ }, [L, _]);
1338
+ const Q = H(() => bt(p), [p]), [X, u] = y(() => /* @__PURE__ */ new Map());
1339
+ I(() => {
1340
+ if (l === "tenant") {
1341
+ u(/* @__PURE__ */ new Map());
1342
+ return;
1343
+ }
1344
+ const v = p.filter((P) => P.kind === "document").map((P) => P.resource_ref?.document_id).filter((P) => !!P);
1345
+ if (v.length === 0) {
1346
+ u(/* @__PURE__ */ new Map());
1347
+ return;
786
1348
  }
787
- }, [i, o, N]), B = H(!0);
788
- j(() => {
789
- B.current ? B.current = !1 : b(void 0), C();
790
- }, [C, b]);
791
- const J = U(() => De(h), [h]), m = U(
792
- () => W ? ue(J, W) : void 0,
793
- [J, W]
794
- ), A = U(() => m ? m.kind === "directory" ? m.fullPath : Q(m.fullPath) : "", [m]), $ = A || "/", V = o !== "tenant", Z = S(() => {
795
- D({
796
- title: `New folder in ${$}`,
1349
+ let $ = !1;
1350
+ return i.documentsSummary({ documentIds: v }, l, w).then((P) => {
1351
+ if ($) return;
1352
+ const V = /* @__PURE__ */ new Map();
1353
+ for (const J of P.documents ?? []) V.set(J.document_id, J);
1354
+ u(V);
1355
+ }).catch(() => {
1356
+ $ || u(/* @__PURE__ */ new Map());
1357
+ }), () => {
1358
+ $ = !0;
1359
+ };
1360
+ }, [i, p, l, w]);
1361
+ const h = H(
1362
+ () => z ? Ie(Q, z) : void 0,
1363
+ [Q, z]
1364
+ ), C = H(() => h ? h.kind === "directory" ? h.fullPath : pe(h.fullPath) : "", [h]), E = C || "/", A = l !== "tenant", ee = G(() => {
1365
+ M({
1366
+ title: `New folder in ${E}`,
797
1367
  fields: [{ key: "name", label: "Folder name", placeholder: "e.g. launches" }],
798
1368
  submitLabel: "Create",
799
- onSubmit: async (p) => {
800
- const v = p.name.trim();
801
- if (!ne.test(v)) throw new Error("name may contain only [A-Za-z0-9._-]");
802
- const _ = ae(A, v);
803
- await i.pathMkdir(_, o, N), await C(), b(_);
1369
+ onSubmit: async (v) => {
1370
+ const $ = v.name.trim();
1371
+ if (!_e.test($)) throw new Error("name may contain only [A-Za-z0-9._-]");
1372
+ const P = Ee(C, $);
1373
+ await i.pathMkdir(P, l, w), await L(), _(P);
804
1374
  }
805
1375
  });
806
- }, [i, A, $, o, N, C, b]), q = S(() => {
807
- D({
808
- title: `New document in ${$}`,
1376
+ }, [i, C, E, l, w, L, _]), te = G(() => {
1377
+ M({
1378
+ title: `New document in ${E}`,
809
1379
  fields: [
810
1380
  { key: "name", label: "Path name", placeholder: "e.g. launch-plan" },
811
1381
  { key: "title", label: "Title", placeholder: "e.g. Launch Plan" }
812
1382
  ],
813
1383
  submitLabel: "Create",
814
- onSubmit: async (p) => {
815
- const v = p.name.trim();
816
- if (!ne.test(v)) throw new Error("name may contain only [A-Za-z0-9._-]");
817
- const _ = p.title.trim() || v, O = ae(A, v);
818
- await i.documentCreate(_, O, o, N), await C(), b(O);
1384
+ onSubmit: async (v) => {
1385
+ const $ = v.name.trim();
1386
+ if (!_e.test($)) throw new Error("name may contain only [A-Za-z0-9._-]");
1387
+ const P = v.title.trim() || $, V = Ee(C, $);
1388
+ await i.documentCreate(P, V, l, w), await L(), _(V);
819
1389
  }
820
1390
  });
821
- }, [i, A, $, o, N, C, b]), g = S(() => {
822
- m && D({
823
- title: `Rename / move ${m.fullPath}`,
824
- fields: [{ key: "to", label: "New path", value: m.fullPath }],
1391
+ }, [i, C, E, l, w, L, _]), ne = G(() => {
1392
+ h && M({
1393
+ title: `Rename / move ${h.fullPath}`,
1394
+ fields: [{ key: "to", label: "New path", value: h.fullPath }],
825
1395
  submitLabel: "Move",
826
- onSubmit: async (p) => {
827
- const v = p.to.trim();
828
- if (!v.startsWith("/")) throw new Error("path must start with /");
829
- await i.pathMv(m.fullPath, v, o, N), await C(), b(v);
1396
+ onSubmit: async (v) => {
1397
+ const $ = v.to.trim();
1398
+ if (!$.startsWith("/")) throw new Error("path must start with /");
1399
+ await i.pathMv(h.fullPath, $, l, w), await L(), _($);
830
1400
  }
831
1401
  });
832
- }, [i, m, o, N, C, b]), w = S(() => {
833
- if (!m) return;
834
- if (m.kind === "document") {
835
- const O = m.resourceRef?.document_id;
836
- D({
837
- title: `Delete document ${m.fullPath}`,
1402
+ }, [i, h, l, w, L, _]), Y = G(() => {
1403
+ if (!h) return;
1404
+ if (h.kind === "document") {
1405
+ const V = h.resourceRef?.document_id;
1406
+ M({
1407
+ title: `Delete document ${h.fullPath}`,
838
1408
  message: "This deletes the document, all its chunks, and its path entry. This cannot be undone.",
839
1409
  fields: [],
840
1410
  submitLabel: "Delete",
841
1411
  danger: !0,
842
1412
  onSubmit: async () => {
843
- if (!O) throw new Error("this document dirent has no document_id");
844
- await i.documentDelete(O, o, N), await C(), b(void 0);
1413
+ if (!V) throw new Error("this document dirent has no document_id");
1414
+ await i.documentDelete(V, l, w), await L(), _(void 0);
845
1415
  }
846
1416
  });
847
1417
  return;
848
1418
  }
849
- const p = o === "tenant" ? [] : Me(m), v = m.children.length;
850
- D({
851
- title: `Delete branch ${m.fullPath}`,
852
- message: v === 0 ? "This removes the (empty) folder." : "This removes the folder and everything under it" + (p.length > 0 ? ` — including ${p.length} document(s), whose chunks are deleted.` : "."),
1419
+ const v = l === "tenant" ? [] : kt(h), $ = h.children.length;
1420
+ M({
1421
+ title: `Delete branch ${h.fullPath}`,
1422
+ message: $ === 0 ? "This removes the (empty) folder." : "This removes the folder and everything under it" + (v.length > 0 ? ` — including ${v.length} document(s), whose chunks are deleted.` : "."),
853
1423
  fields: [],
854
1424
  submitLabel: "Delete",
855
1425
  danger: !0,
856
1426
  onSubmit: async () => {
857
- for (const _ of p)
858
- await i.documentDelete(_, o, N);
859
- await i.pathRm(m.fullPath, o, !0, N), await C(), b(void 0);
1427
+ for (const P of v)
1428
+ await i.documentDelete(P, l, w);
1429
+ await i.pathRm(h.fullPath, l, !0, w), await L(), _(void 0);
860
1430
  }
861
1431
  });
862
- }, [i, m, o, N, C, b]), I = m && (m.kind === "directory" || m.kind === "document");
863
- return /* @__PURE__ */ d(G, { children: [
1432
+ }, [i, h, l, w, L, _]), ae = h && (h.kind === "directory" || h.kind === "document");
1433
+ return /* @__PURE__ */ d(q, { children: [
864
1434
  /* @__PURE__ */ d(
865
- ye,
1435
+ et,
866
1436
  {
867
1437
  className: "paths-view",
868
1438
  defaultLeftWidth: 420,
@@ -873,151 +1443,161 @@ function Re({
873
1443
  /* @__PURE__ */ d("div", { className: "left", children: [
874
1444
  /* @__PURE__ */ d("div", { className: "paths-toolbar", children: [
875
1445
  /* @__PURE__ */ d("label", { className: "paths-scope", children: [
876
- /* @__PURE__ */ t("span", { children: "scope" }),
877
- /* @__PURE__ */ d("select", { value: o, onChange: (p) => u(p.target.value), children: [
878
- /* @__PURE__ */ t("option", { value: "user", children: "user" }),
879
- /* @__PURE__ */ t("option", { value: "agent", children: "agent" }),
880
- /* @__PURE__ */ t("option", { value: "tenant", children: "tenant" })
1446
+ /* @__PURE__ */ n("span", { children: "scope" }),
1447
+ /* @__PURE__ */ d("select", { value: l, onChange: (v) => m(v.target.value), children: [
1448
+ /* @__PURE__ */ n("option", { value: "user", children: "user" }),
1449
+ /* @__PURE__ */ n("option", { value: "agent", children: "agent" }),
1450
+ /* @__PURE__ */ n("option", { value: "tenant", children: "tenant" })
881
1451
  ] })
882
1452
  ] }),
883
1453
  /* @__PURE__ */ d("div", { className: "paths-toolbar-actions", children: [
884
- /* @__PURE__ */ t("button", { type: "button", onClick: Z, title: `New folder in ${$}`, children: "+ folder" }),
885
- /* @__PURE__ */ t(
1454
+ /* @__PURE__ */ n("button", { type: "button", onClick: ee, title: `New folder in ${E}`, children: "+ folder" }),
1455
+ /* @__PURE__ */ n(
886
1456
  "button",
887
1457
  {
888
1458
  type: "button",
889
- onClick: q,
890
- disabled: !V,
891
- title: V ? `New document in ${$}` : "Documents are agent/user scope only",
1459
+ onClick: te,
1460
+ disabled: !A,
1461
+ title: A ? `New document in ${E}` : "Documents are agent/user scope only",
892
1462
  children: "+ document"
893
1463
  }
894
1464
  ),
895
- /* @__PURE__ */ t("button", { type: "button", onClick: () => {
896
- C();
1465
+ /* @__PURE__ */ n("button", { type: "button", onClick: () => {
1466
+ L();
897
1467
  }, title: "Reload the tree", children: "↻" })
898
1468
  ] })
899
1469
  ] }),
900
1470
  /* @__PURE__ */ d("p", { className: "paths-context", children: [
901
1471
  "new items → ",
902
- /* @__PURE__ */ t("code", { children: $ }),
903
- N?.scopeId && /* @__PURE__ */ d(G, { children: [
1472
+ /* @__PURE__ */ n("code", { children: E }),
1473
+ w?.scopeId && /* @__PURE__ */ d(q, { children: [
904
1474
  " · ",
905
1475
  "subject ",
906
- /* @__PURE__ */ t("code", { children: N.scopeId })
1476
+ /* @__PURE__ */ n("code", { children: w.scopeId })
907
1477
  ] }),
908
- N?.tenant && /* @__PURE__ */ d(G, { children: [
1478
+ w?.tenant && /* @__PURE__ */ d(q, { children: [
909
1479
  " · ",
910
1480
  "tenant ",
911
- /* @__PURE__ */ t("code", { children: N.tenant })
1481
+ /* @__PURE__ */ n("code", { children: w.tenant })
912
1482
  ] })
913
1483
  ] }),
914
- y && /* @__PURE__ */ t("div", { className: "paths-err", children: y }),
915
- T && h.length === 0 ? /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Loading…" }) }) : /* @__PURE__ */ t(
916
- Le,
1484
+ N && /* @__PURE__ */ n("div", { className: "paths-err", children: N }),
1485
+ U && p.length === 0 ? /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "Loading…" }) }) : /* @__PURE__ */ n(
1486
+ Nt,
917
1487
  {
918
- tree: J,
919
- selectedPath: W,
920
- onSelect: (p) => b(p.fullPath)
1488
+ tree: Q,
1489
+ selectedPath: z,
1490
+ onSelect: (v) => _(v.fullPath),
1491
+ summaries: X
921
1492
  }
922
1493
  )
923
1494
  ] }),
924
- /* @__PURE__ */ t("div", { className: "right", children: m ? m.kind === "document" ? /* @__PURE__ */ d("div", { className: "paths-doc", children: [
1495
+ /* @__PURE__ */ n("div", { className: "right", children: h ? h.kind === "document" ? /* @__PURE__ */ d("div", { className: "paths-doc", children: [
925
1496
  /* @__PURE__ */ d("div", { className: "paths-doc-head", children: [
926
- /* @__PURE__ */ t("code", { className: "paths-doc-path", children: m.fullPath }),
1497
+ /* @__PURE__ */ n("code", { className: "paths-doc-path", children: h.fullPath }),
927
1498
  /* @__PURE__ */ d("div", { className: "paths-detail-actions", children: [
928
- /* @__PURE__ */ t("button", { type: "button", onClick: g, children: "rename / move" }),
929
- /* @__PURE__ */ t("button", { type: "button", className: "danger", onClick: w, children: "delete" })
1499
+ /* @__PURE__ */ n("button", { type: "button", onClick: ne, children: "rename / move" }),
1500
+ /* @__PURE__ */ n("button", { type: "button", className: "danger", onClick: Y, children: "delete" })
930
1501
  ] })
931
1502
  ] }),
932
- /* @__PURE__ */ t(
933
- ie,
1503
+ /* @__PURE__ */ n(
1504
+ Pe,
934
1505
  {
935
- documentId: m.resourceRef?.document_id ?? "",
936
- scope: o === "agent" ? "agent" : "user",
937
- titleHint: m.name,
938
- browse: N,
939
- principal: s,
940
- renderAssistant: c
1506
+ documentId: h.resourceRef?.document_id ?? "",
1507
+ scope: l === "agent" ? "agent" : "user",
1508
+ titleHint: h.name,
1509
+ browse: w,
1510
+ principal: c,
1511
+ renderAssistant: s
941
1512
  }
942
1513
  )
943
1514
  ] }) : /* @__PURE__ */ d("div", { className: "paths-detail", children: [
944
1515
  /* @__PURE__ */ d("h2", { children: [
945
- /* @__PURE__ */ t("span", { className: "paths-detail-kind", children: m.kind }),
946
- /* @__PURE__ */ t("code", { children: m.fullPath })
1516
+ /* @__PURE__ */ n("span", { className: "paths-detail-kind", children: h.kind }),
1517
+ /* @__PURE__ */ n("code", { children: h.fullPath })
947
1518
  ] }),
948
1519
  /* @__PURE__ */ d("dl", { className: "paths-detail-meta", children: [
949
- /* @__PURE__ */ t("dt", { children: "scope" }),
950
- /* @__PURE__ */ t("dd", { children: o }),
951
- /* @__PURE__ */ t("dt", { children: "stored" }),
952
- /* @__PURE__ */ t("dd", { children: m.explicit ? "yes" : "implicit (no entry)" })
1520
+ /* @__PURE__ */ n("dt", { children: "scope" }),
1521
+ /* @__PURE__ */ n("dd", { children: l }),
1522
+ /* @__PURE__ */ n("dt", { children: "stored" }),
1523
+ /* @__PURE__ */ n("dd", { children: h.explicit ? "yes" : "implicit (no entry)" })
953
1524
  ] }),
954
- I ? /* @__PURE__ */ d("div", { className: "paths-detail-actions", children: [
955
- /* @__PURE__ */ t("button", { type: "button", onClick: g, children: "rename / move" }),
956
- /* @__PURE__ */ t("button", { type: "button", className: "danger", onClick: w, children: "delete" })
1525
+ ae ? /* @__PURE__ */ d("div", { className: "paths-detail-actions", children: [
1526
+ /* @__PURE__ */ n("button", { type: "button", onClick: ne, children: "rename / move" }),
1527
+ /* @__PURE__ */ n("button", { type: "button", className: "danger", onClick: Y, children: "delete" })
957
1528
  ] }) : /* @__PURE__ */ d("p", { className: "paths-readonly", children: [
958
1529
  "Read-only — ",
959
- m.kind,
1530
+ h.kind,
960
1531
  " entries are managed by their own tool."
961
1532
  ] })
962
- ] }) : /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Select a path on the left, or create a folder / document." }) }) })
1533
+ ] }) : /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "Select a path on the left, or create a folder / document." }) }) })
963
1534
  ]
964
1535
  }
965
1536
  ),
966
- P && /* @__PURE__ */ t(Ie, { state: P, onClose: () => D(null) })
1537
+ W && /* @__PURE__ */ n(_t, { state: W, onClose: () => M(null) })
967
1538
  ] });
968
1539
  }
969
- function Ie({ state: a, onClose: e }) {
970
- const [r, n] = f(
971
- () => Object.fromEntries(a.fields.map((u) => [u.key, u.value ?? ""]))
972
- ), [s, c] = f(!1), [l, i] = f(null);
973
- return /* @__PURE__ */ t("div", { className: "modal-overlay", onClick: e, children: /* @__PURE__ */ d("form", { className: "modal", onClick: (u) => u.stopPropagation(), onSubmit: async (u) => {
974
- u.preventDefault(), c(!0), i(null);
1540
+ function _t({ state: e, onClose: r }) {
1541
+ const [t, a] = y(
1542
+ () => Object.fromEntries(e.fields.map((m) => [m.key, m.value ?? ""]))
1543
+ ), [c, s] = y(!1), [o, i] = y(null);
1544
+ return /* @__PURE__ */ n("div", { className: "modal-overlay", onClick: r, children: /* @__PURE__ */ d("form", { className: "modal", onClick: (m) => m.stopPropagation(), onSubmit: async (m) => {
1545
+ m.preventDefault(), s(!0), i(null);
975
1546
  try {
976
- await a.onSubmit(r), e();
977
- } catch (h) {
978
- i(h instanceof Error ? h.message : String(h)), c(!1);
1547
+ await e.onSubmit(t), r();
1548
+ } catch (p) {
1549
+ i(p instanceof Error ? p.message : String(p)), s(!1);
979
1550
  }
980
1551
  }, children: [
981
- /* @__PURE__ */ t("h3", { children: a.title }),
982
- a.message && /* @__PURE__ */ t("p", { className: "modal-context", children: a.message }),
983
- a.fields.map((u, h) => /* @__PURE__ */ d("label", { className: "path-field", children: [
984
- /* @__PURE__ */ t("span", { children: u.label }),
985
- /* @__PURE__ */ t(
1552
+ /* @__PURE__ */ d("div", { className: "modal-header sticky-top", children: [
1553
+ /* @__PURE__ */ n("h3", { children: e.title }),
1554
+ /* @__PURE__ */ d("div", { className: "modal-buttons modal-buttons-top", children: [
1555
+ /* @__PURE__ */ n("button", { type: "button", onClick: r, disabled: c, children: "cancel" }),
1556
+ /* @__PURE__ */ n("button", { type: "submit", className: e.danger ? "danger" : "primary", disabled: c, children: c ? "working…" : e.submitLabel })
1557
+ ] })
1558
+ ] }),
1559
+ e.message && /* @__PURE__ */ n("p", { className: "modal-context", children: e.message }),
1560
+ e.fields.map((m, p) => /* @__PURE__ */ d("label", { className: "path-field", children: [
1561
+ /* @__PURE__ */ n("span", { children: m.label }),
1562
+ /* @__PURE__ */ n(
986
1563
  "input",
987
1564
  {
988
1565
  className: "path-modal-input",
989
- value: r[u.key],
990
- placeholder: u.placeholder,
991
- autoFocus: h === 0,
992
- onChange: (x) => n((k) => ({ ...k, [u.key]: x.target.value }))
1566
+ value: t[m.key],
1567
+ placeholder: m.placeholder,
1568
+ autoFocus: p === 0,
1569
+ onChange: (b) => a((g) => ({ ...g, [m.key]: b.target.value }))
993
1570
  }
994
1571
  )
995
- ] }, u.key)),
996
- l && /* @__PURE__ */ t("div", { className: "modal-err", children: l }),
997
- /* @__PURE__ */ d("div", { className: "modal-buttons", children: [
998
- /* @__PURE__ */ t("button", { type: "button", onClick: e, disabled: s, children: "cancel" }),
999
- /* @__PURE__ */ t("button", { type: "submit", className: a.danger ? "danger" : "primary", disabled: s, children: s ? "working…" : a.submitLabel })
1000
- ] })
1572
+ ] }, m.key)),
1573
+ o && /* @__PURE__ */ n("div", { className: "modal-err", children: o })
1001
1574
  ] }) });
1002
1575
  }
1003
- function je(a) {
1004
- const { documentId: e, scope: r, titleHint: n, browse: s, theme: c, principal: l, renderAssistant: i } = a, o = le(a);
1005
- return /* @__PURE__ */ t(se, { theme: c, dataLayer: o, children: /* @__PURE__ */ t(
1006
- ie,
1576
+ function Dt(e) {
1577
+ const { documentId: r, scope: t, titleHint: a, browse: c, theme: s, principal: o, renderAssistant: i } = e, l = xe(e);
1578
+ return /* @__PURE__ */ n($e, { theme: s, dataLayer: l, children: /* @__PURE__ */ n(
1579
+ Pe,
1007
1580
  {
1008
- documentId: e,
1009
- scope: r,
1010
- titleHint: n,
1011
- browse: s,
1012
- principal: l,
1581
+ documentId: r,
1582
+ scope: t,
1583
+ titleHint: a,
1584
+ browse: c,
1585
+ principal: o,
1013
1586
  renderAssistant: i
1014
1587
  }
1015
1588
  ) });
1016
1589
  }
1017
1590
  export {
1018
- je as DocumentViewer,
1019
- Oe as PathExplorer,
1020
- ke as createLoomcycleClient,
1021
- K as dataLayerFromClient
1591
+ me as DEFAULT_SCHEME,
1592
+ Dt as DocumentViewer,
1593
+ Lt as PathExplorer,
1594
+ Ke as assetFetchFromConnection,
1595
+ rt as chunkColor,
1596
+ Ye as createLoomcycleClient,
1597
+ ye as dataLayerFromClient,
1598
+ De as docColor,
1599
+ fe as effectiveScheme,
1600
+ ct as hexToTint,
1601
+ ge as tintStyle
1022
1602
  };
1023
1603
  //# sourceMappingURL=index.js.map