@loomcycle/explorer 0.4.0 → 0.7.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,394 +1,464 @@
1
- import { jsx as n, jsxs as l, Fragment as q } from "react/jsx-runtime";
2
- import { createContext as Ye, useContext as Ke, useMemo as G, useState as k, useRef as ne, useEffect as U, useCallback as A } from "react";
3
- import { LoomcycleClient as et } from "@loomcycle/client";
4
- import tt from "react-markdown";
5
- import nt from "remark-gfm";
6
- function Ne(e, a) {
1
+ import { jsx as t, jsxs as l, Fragment as Y } from "react/jsx-runtime";
2
+ import { createContext as at, useContext as rt, useMemo as q, useState as f, useRef as ne, useEffect as B, useCallback as O } from "react";
3
+ import { LoomcycleClient as ot } from "@loomcycle/client";
4
+ import ct from "react-markdown";
5
+ import it from "remark-gfm";
6
+ function _e(e, r) {
7
7
  return {
8
- pathLs: (t, r, o, s) => e.path(
9
- { op: "ls", path: t, scope: r, recursive: o },
10
- s
8
+ pathLs: (n, a, o, i) => e.path(
9
+ { op: "ls", path: n, scope: a, recursive: o },
10
+ i
11
11
  ),
12
- pathMkdir: (t, r, o) => e.path({ op: "mkdir", path: t, scope: r }, o),
13
- pathMv: (t, r, o, s) => e.path({ op: "mv", path: t, to: r, scope: o }, s),
14
- pathRm: (t, r, o, s) => e.path({ op: "rm", path: t, scope: r, recursive: o }, s),
15
- documentCreate: (t, r, o, s) => e.document(
16
- { op: "create_document", title: t, path: r, scope: o },
17
- s
12
+ pathMkdir: (n, a, o) => e.path({ op: "mkdir", path: n, scope: a }, o),
13
+ pathMv: (n, a, o, i) => e.path({ op: "mv", path: n, to: a, scope: o }, i),
14
+ pathRm: (n, a, o, i) => e.path({ op: "rm", path: n, scope: a, recursive: o }, i),
15
+ // The `as unknown as DocumentToolInput` casts below are the same pinned-SDK
16
+ // workaround documentReorderChunk already uses, for a different reason: the
17
+ // published @loomcycle/client still types `scope` as "agent" | "user", from
18
+ // when Documents refused tenant scope. The runtime has accepted tenant since
19
+ // v1.41.0 and adapters/ts is fixed at source, so these casts come out on the
20
+ // next client publish — they are not papering over a wire mismatch, they are
21
+ // waiting for a version bump.
22
+ documentCreate: (n, a, o, i) => e.document(
23
+ { op: "create_document", title: n, path: a, scope: o },
24
+ i
18
25
  ),
19
- documentDelete: (t, r, o) => e.document({ op: "delete_document", id: t, scope: r }, o),
20
- documentGet: (t, r, o) => e.document({ op: "get_document", id: t, scope: r }, o),
21
- documentsSummary: (t, r, o) => e.document(
26
+ documentDelete: (n, a, o) => e.document({ op: "delete_document", id: n, scope: a }, o),
27
+ documentGet: (n, a, o) => e.document({ op: "get_document", id: n, scope: a }, o),
28
+ documentsSummary: (n, a, o) => e.document(
22
29
  // documents_summary + document_ids are RFC BN wire additions the pinned
23
30
  // SDK type doesn't enumerate; the /v1/_document passthrough accepts them
24
31
  // verbatim, so cast past DocumentToolInput (same pattern as update_chunk).
25
32
  {
26
33
  op: "documents_summary",
27
- scope: r,
28
- ...t.documentIds ? { document_ids: t.documentIds } : {},
29
- ...t.underPath ? { under_path: t.underPath } : {}
34
+ scope: a,
35
+ ...n.documentIds ? { document_ids: n.documentIds } : {},
36
+ ...n.underPath ? { under_path: n.underPath } : {}
30
37
  },
31
38
  o
32
39
  ),
33
- documentQueryChunks: (t, r, o) => e.document(
34
- { op: "query_chunks", document_id: t, scope: r, limit: 1e3 },
40
+ documentQueryChunks: (n, a, o) => e.document(
41
+ { op: "query_chunks", document_id: n, scope: a, limit: 1e3 },
35
42
  o
36
43
  ),
37
- documentGetChunk: (t, r, o) => e.document({ op: "get_chunk", id: t, scope: r }, o),
38
- documentCreateChunk: (t, r, o, s, c, i) => e.document(
44
+ documentGetChunk: (n, a, o) => e.document({ op: "get_chunk", id: n, scope: a }, o),
45
+ documentCreateChunk: (n, a, o, i, c, s) => e.document(
39
46
  {
40
47
  op: "create_chunk",
41
- document_id: t,
42
- parent_id: r,
43
- scope: s,
44
- ...i ? { after_id: i } : {},
48
+ document_id: n,
49
+ parent_id: a,
50
+ scope: i,
51
+ ...s ? { after_id: s } : {},
45
52
  ...o
46
53
  },
47
54
  c
48
55
  ),
49
- documentReorderChunk: (t, r, o, s) => e.document(
56
+ documentReorderChunk: (n, a, o, i) => e.document(
50
57
  // reorder_chunk is an RFC BP wire op the pinned SDK type doesn't
51
58
  // enumerate; the /v1/_document passthrough accepts it verbatim.
52
- { op: "reorder_chunk", id: t, direction: r, scope: o },
53
- s
59
+ { op: "reorder_chunk", id: n, direction: a, scope: o },
60
+ i
54
61
  ),
55
- documentDeleteChunk: (t, r, o) => e.document({ op: "delete_chunk", id: t, scope: r }, o),
56
- documentSetAsset: (t, r, o, s, c, i) => e.document(
62
+ documentDeleteChunk: (n, a, o) => e.document({ op: "delete_chunk", id: n, scope: a }, o),
63
+ documentSetAsset: (n, a, o, i, c, s) => e.document(
57
64
  // set_asset is an RFC BO wire op the pinned SDK type doesn't enumerate;
58
65
  // the /v1/_document passthrough accepts it verbatim.
59
66
  {
60
67
  op: "set_asset",
61
- id: t,
62
- media_type: r,
68
+ id: n,
69
+ media_type: a,
63
70
  data: o,
64
- ...s ? { filename: s } : {},
71
+ ...i ? { filename: i } : {},
65
72
  scope: c
66
73
  },
67
- i
74
+ s
68
75
  ),
69
- documentGetEdges: (t, r, o) => e.document(
76
+ documentGetEdges: (n, a, o) => e.document(
70
77
  // get_edges is an RFC BN P4 wire op the pinned SDK type doesn't
71
78
  // enumerate; the /v1/_document passthrough accepts it verbatim.
72
- { op: "get_edges", document_id: t, scope: r },
79
+ { op: "get_edges", document_id: n, scope: a },
73
80
  o
74
81
  ),
75
- documentUpdateChunk: (t, r, o, s, c) => e.document(
82
+ documentUpdateChunk: (n, a, o, i, c) => e.document(
76
83
  // `patch.fields` is unknown but DocumentToolInput.fields is a typed
77
84
  // Record; the cast reconciles the spread (the server accepts arbitrary
78
85
  // JSON there). Op order + arg names mirror the wire contract exactly.
79
86
  {
80
87
  op: "update_chunk",
81
- id: t,
82
- revision: r,
83
- scope: s,
88
+ id: n,
89
+ revision: a,
90
+ scope: i,
84
91
  ...o
85
92
  },
86
93
  c
87
94
  ),
88
- documentExportMd: (t, r, o, s) => e.document(
95
+ documentExportMd: (n, a, o, i) => e.document(
89
96
  {
90
97
  op: "export_md",
91
- document_id: t,
92
- scope: r,
98
+ document_id: n,
99
+ scope: a,
93
100
  include_metadata: o
94
101
  },
95
- s
102
+ i
103
+ ),
104
+ // RFC BS document-connections + history + canvas ops. Same `as unknown as
105
+ // DocumentToolInput` passthrough as documentGetEdges — new wire ops the pinned
106
+ // SDK type doesn't enumerate; the /v1/_document passthrough accepts them
107
+ // verbatim (adapters/ts is fixed at source, so the casts come out on the next
108
+ // client publish).
109
+ documentBacklinks: (n, a, o) => e.document(
110
+ { op: "backlinks", id: n, scope: a },
111
+ o
112
+ ),
113
+ documentRelated: (n, a, o, i) => e.document(
114
+ {
115
+ op: "related",
116
+ id: n,
117
+ scope: a,
118
+ ...i ? { limit: i } : {}
119
+ },
120
+ o
121
+ ),
122
+ documentUnlinkedMentions: (n, a, o, i) => e.document(
123
+ {
124
+ op: "unlinked_mentions",
125
+ id: n,
126
+ scope: a,
127
+ ...i ? { limit: i } : {}
128
+ },
129
+ o
130
+ ),
131
+ documentHistory: (n, a, o, i) => e.document(
132
+ {
133
+ op: "history",
134
+ id: n,
135
+ scope: a,
136
+ ...i ? { limit: i } : {}
137
+ },
138
+ o
139
+ ),
140
+ documentGetVersion: (n, a, o, i) => e.document(
141
+ { op: "get_version", id: n, revision: a, scope: o },
142
+ i
143
+ ),
144
+ documentDiff: (n, a, o, i, c) => e.document(
145
+ {
146
+ op: "diff",
147
+ id: n,
148
+ from_revision: a,
149
+ to_revision: o,
150
+ scope: i
151
+ },
152
+ c
153
+ ),
154
+ documentExportCanvas: (n, a, o) => e.document(
155
+ { op: "export_canvas", document_id: n, scope: a },
156
+ o
96
157
  ),
97
158
  // Present only when an AssetFetch was supplied (the connection path); a bare
98
159
  // client can't do the raw binary GET, so the op is omitted and the viewer
99
160
  // shows a placeholder.
100
- ...a ? {
101
- documentAssetObjectUrl: async (t, r, o) => {
102
- const s = new URLSearchParams({ scope: r });
103
- o?.scopeId && s.set("scope_id", o.scopeId), o?.tenant && s.set("tenant", o.tenant);
104
- const c = await a(
105
- `/v1/_document/asset/${encodeURIComponent(t)}?${s.toString()}`
161
+ ...r ? {
162
+ documentAssetObjectUrl: async (n, a, o) => {
163
+ const i = new URLSearchParams({ scope: a });
164
+ o?.scopeId && i.set("scope_id", o.scopeId), o?.tenant && i.set("tenant", o.tenant);
165
+ const c = await r(
166
+ `/v1/_document/asset/${encodeURIComponent(n)}?${i.toString()}`
106
167
  );
107
168
  if (!c.ok) throw new Error(`asset fetch failed: ${c.status}`);
108
- const i = await c.blob();
109
- return URL.createObjectURL(i);
169
+ const s = await c.blob();
170
+ return URL.createObjectURL(s);
110
171
  }
111
172
  } : {}
112
173
  };
113
174
  }
114
- const Me = Ye(null);
115
- function at({
175
+ const Te = at(null);
176
+ function st({
116
177
  value: e,
117
- children: a
178
+ children: r
118
179
  }) {
119
- return /* @__PURE__ */ n(Me.Provider, { value: e, children: a });
180
+ return /* @__PURE__ */ t(Te.Provider, { value: e, children: r });
120
181
  }
121
- function se() {
122
- const e = Ke(Me);
182
+ function ae() {
183
+ const e = rt(Te);
123
184
  if (!e)
124
185
  throw new Error(
125
186
  "useExplorerData must be used within <PathExplorer> or <DocumentViewer> (no ExplorerDataLayer in context)"
126
187
  );
127
188
  return e;
128
189
  }
129
- function rt(e) {
130
- const a = e.fetch;
131
- return new et({
190
+ function lt(e) {
191
+ const r = e.fetch;
192
+ return new ot({
132
193
  baseUrl: e.baseUrl,
133
194
  authToken: e.token || void 0,
134
- fetch: (t, r) => a ? a(t, r) : fetch(t, r)
195
+ fetch: (n, a) => r ? r(n, a) : fetch(n, a)
135
196
  });
136
197
  }
137
- function ot(e) {
138
- const a = e.fetch, t = (r, o) => a ? a(r, o) : fetch(r, o);
139
- return (r) => {
198
+ function dt(e) {
199
+ const r = e.fetch, n = (a, o) => r ? r(a, o) : fetch(a, o);
200
+ return (a) => {
140
201
  const o = {};
141
- return e.token && (o.Authorization = `Bearer ${e.token}`), t(e.baseUrl + r, { headers: o });
202
+ return e.token && (o.Authorization = `Bearer ${e.token}`), n(e.baseUrl + a, { headers: o });
142
203
  };
143
204
  }
144
- function Le(e) {
145
- const { dataLayer: a, client: t, connection: r } = e;
146
- return G(() => a || (t ? Ne(t) : r ? Ne(
147
- rt(r),
148
- ot(r)
205
+ function Ae(e) {
206
+ const { dataLayer: r, client: n, connection: a } = e;
207
+ return q(() => r || (n ? _e(n) : a ? _e(
208
+ lt(a),
209
+ dt(a)
149
210
  // RFC BO — binary image-asset GET
150
- ) : null), [a, t, r?.baseUrl, r?.token, r?.fetch]);
211
+ ) : null), [r, n, a?.baseUrl, a?.token, a?.fetch]);
151
212
  }
152
- function Re({
213
+ function Pe({
153
214
  theme: e,
154
- dataLayer: a,
155
- children: t
215
+ dataLayer: r,
216
+ children: n
156
217
  }) {
157
- const r = e ? { "data-theme": e } : {};
158
- return a ? /* @__PURE__ */ n("div", { className: "loomcycle-explorer", ...r, children: /* @__PURE__ */ n(at, { value: a, children: t }) }) : /* @__PURE__ */ n("div", { className: "loomcycle-explorer", ...r, children: /* @__PURE__ */ l("div", { className: "error-banner", children: [
218
+ const a = e ? { "data-theme": e } : {};
219
+ return r ? /* @__PURE__ */ t("div", { className: "loomcycle-explorer", ...a, children: /* @__PURE__ */ t(st, { value: r, children: n }) }) : /* @__PURE__ */ t("div", { className: "loomcycle-explorer", ...a, children: /* @__PURE__ */ l("div", { className: "error-banner", children: [
159
220
  "@loomcycle/explorer: provide a ",
160
- /* @__PURE__ */ n("code", { children: "connection" }),
221
+ /* @__PURE__ */ t("code", { children: "connection" }),
161
222
  ", ",
162
- /* @__PURE__ */ n("code", { children: "client" }),
223
+ /* @__PURE__ */ t("code", { children: "client" }),
163
224
  ", or",
164
225
  " ",
165
- /* @__PURE__ */ n("code", { children: "dataLayer" }),
226
+ /* @__PURE__ */ t("code", { children: "dataLayer" }),
166
227
  " prop."
167
228
  ] }) });
168
229
  }
169
- const we = 6;
170
- function ct({
230
+ const Se = 6;
231
+ function ut({
171
232
  children: e,
172
- defaultLeftWidth: a = 380,
173
- minLeftWidth: t = 180,
174
- minRightWidth: r = 240,
233
+ defaultLeftWidth: r = 380,
234
+ minLeftWidth: n = 180,
235
+ minRightWidth: a = 240,
175
236
  storageKey: o,
176
- className: s
237
+ className: i
177
238
  }) {
178
- const [c, i] = k(() => {
239
+ const [c, s] = f(() => {
179
240
  if (o) {
180
- const N = localStorage.getItem(o), T = N ? parseInt(N, 10) : NaN;
181
- if (Number.isFinite(T) && T >= t) return T;
241
+ const C = localStorage.getItem(o), L = C ? parseInt(C, 10) : NaN;
242
+ if (Number.isFinite(L) && L >= n) return L;
182
243
  }
183
- return a;
184
- }), d = ne(null), [g, m] = k(!1);
185
- U(() => {
244
+ return r;
245
+ }), u = ne(null), [g, h] = f(!1);
246
+ B(() => {
186
247
  !o || g || localStorage.setItem(o, String(Math.round(c)));
187
248
  }, [o, c, g]);
188
- const b = A((N) => {
189
- N.preventDefault(), m(!0), N.target.setPointerCapture(N.pointerId);
190
- }, []), p = A(
191
- (N) => {
192
- if (!g || !d.current) return;
193
- const T = d.current.getBoundingClientRect(), j = N.clientX - T.left, P = T.width - r - we, W = Math.max(t, Math.min(j, P));
194
- i(W);
249
+ const v = O((C) => {
250
+ C.preventDefault(), h(!0), C.target.setPointerCapture(C.pointerId);
251
+ }, []), m = O(
252
+ (C) => {
253
+ if (!g || !u.current) return;
254
+ const L = u.current.getBoundingClientRect(), F = C.clientX - L.left, I = L.width - a - Se, P = Math.max(n, Math.min(F, I));
255
+ s(P);
195
256
  },
196
- [g, t, r]
197
- ), O = A((N) => {
198
- m(!1);
257
+ [g, n, a]
258
+ ), A = O((C) => {
259
+ h(!1);
199
260
  try {
200
- N.target.releasePointerCapture(N.pointerId);
261
+ C.target.releasePointerCapture(C.pointerId);
201
262
  } catch {
202
263
  }
203
264
  }, []);
204
265
  return /* @__PURE__ */ l(
205
266
  "div",
206
267
  {
207
- ref: d,
208
- className: `splitter ${s ?? ""} ${g ? "dragging" : ""}`,
268
+ ref: u,
269
+ className: `splitter ${i ?? ""} ${g ? "dragging" : ""}`,
209
270
  style: {
210
- gridTemplateColumns: `${c}px ${we}px 1fr`
271
+ gridTemplateColumns: `${c}px ${Se}px 1fr`
211
272
  },
212
273
  children: [
213
- /* @__PURE__ */ n("div", { className: "splitter-pane splitter-left", children: e[0] }),
214
- /* @__PURE__ */ n(
274
+ /* @__PURE__ */ t("div", { className: "splitter-pane splitter-left", children: e[0] }),
275
+ /* @__PURE__ */ t(
215
276
  "div",
216
277
  {
217
278
  className: "splitter-handle",
218
279
  role: "separator",
219
280
  "aria-orientation": "vertical",
220
281
  "aria-valuenow": Math.round(c),
221
- onPointerDown: b,
222
- onPointerMove: p,
223
- onPointerUp: O,
224
- onPointerCancel: O
282
+ onPointerDown: v,
283
+ onPointerMove: m,
284
+ onPointerUp: A,
285
+ onPointerCancel: A
225
286
  }
226
287
  ),
227
- /* @__PURE__ */ n("div", { className: "splitter-pane splitter-right", children: e[1] })
288
+ /* @__PURE__ */ t("div", { className: "splitter-pane splitter-right", children: e[1] })
228
289
  ]
229
290
  }
230
291
  );
231
292
  }
232
- const it = ["image/png", "image/jpeg", "image/gif", "image/webp"];
233
- function Ae(e) {
234
- return it.includes(e);
293
+ const ht = ["image/png", "image/jpeg", "image/gif", "image/webp"];
294
+ function Ue(e) {
295
+ return ht.includes(e);
235
296
  }
236
- function Te(e) {
237
- return new Promise((a, t) => {
238
- if (!Ae(e.type)) {
239
- t(new Error(`unsupported image type "${e.type || "unknown"}" (png, jpeg, gif, webp only)`));
297
+ function Oe(e) {
298
+ return new Promise((r, n) => {
299
+ if (!Ue(e.type)) {
300
+ n(new Error(`unsupported image type "${e.type || "unknown"}" (png, jpeg, gif, webp only)`));
240
301
  return;
241
302
  }
242
- const r = new FileReader();
243
- r.onerror = () => t(r.error ?? new Error("failed to read file")), r.onload = () => {
244
- const o = String(r.result ?? ""), s = o.indexOf(",");
245
- if (s < 0) {
246
- t(new Error("could not decode image data"));
303
+ const a = new FileReader();
304
+ a.onerror = () => n(a.error ?? new Error("failed to read file")), a.onload = () => {
305
+ const o = String(a.result ?? ""), i = o.indexOf(",");
306
+ if (i < 0) {
307
+ n(new Error("could not decode image data"));
247
308
  return;
248
309
  }
249
- a({ mediaType: e.type, data: o.slice(s + 1) });
250
- }, r.readAsDataURL(e);
310
+ r({ mediaType: e.type, data: o.slice(i + 1) });
311
+ }, a.readAsDataURL(e);
251
312
  });
252
313
  }
253
- function st(e) {
314
+ function mt(e) {
254
315
  if (!e) return null;
255
- for (let a = 0; a < e.length; a++) {
256
- const t = e[a];
257
- if (t.kind === "file" && Ae(t.type)) {
258
- const r = t.getAsFile();
259
- if (r) return r;
316
+ for (let r = 0; r < e.length; r++) {
317
+ const n = e[r];
318
+ if (n.kind === "file" && Ue(n.type)) {
319
+ const a = n.getAsFile();
320
+ if (a) return a;
260
321
  }
261
322
  }
262
323
  return null;
263
324
  }
264
- const fe = {
325
+ const be = {
265
326
  "doc.rfc.draft": "#c99a3a",
266
327
  "doc.rfc.review": "#6a7bd6",
267
328
  "doc.rfc.confirmed": "#3a9ad6",
268
329
  "doc.rfc.done": "#3aa06a",
330
+ // plan documents share the RFC lifecycle vocabulary (draft→review→confirmed→done).
331
+ "doc.plan.draft": "#c99a3a",
332
+ "doc.plan.review": "#6a7bd6",
333
+ "doc.plan.confirmed": "#3a9ad6",
334
+ "doc.plan.done": "#3aa06a",
269
335
  "doc.document.done": "#3aa06a",
270
336
  "doc.research.done": "#8a6ad6",
271
337
  "doc.publication.draft": "#c99a3a",
272
338
  "chunk.draft": "#c99a3a",
273
339
  "chunk.review": "#6a7bd6",
274
340
  "chunk.confirmed": "#3a9ad6",
275
- "chunk.done": "#3aa06a"
276
- }, lt = 0.16;
277
- function ye(e) {
278
- return e && Object.keys(e).length > 0 ? e : fe;
341
+ "chunk.done": "#3aa06a",
342
+ // PR-workflow chunk statuses (a plan document's PR chunks): queued → active → done.
343
+ "chunk.backlog": "#8a8f98",
344
+ "chunk.implementation": "#d1863a",
345
+ "chunk.merged": "#3aa06a"
346
+ }, pt = 0.16;
347
+ function ve(e) {
348
+ return e && Object.keys(e).length > 0 ? e : be;
279
349
  }
280
- function Pe(e, a, t) {
281
- const r = e ?? "", o = a ?? "";
282
- if (r && o && t[`doc.${r}.${o}`]) return t[`doc.${r}.${o}`];
283
- if (r && t[`doc.${r}`]) return t[`doc.${r}`];
350
+ function Ie(e, r, n) {
351
+ const a = e ?? "", o = r ?? "";
352
+ if (a && o && n[`doc.${a}.${o}`]) return n[`doc.${a}.${o}`];
353
+ if (a && n[`doc.${a}`]) return n[`doc.${a}`];
284
354
  }
285
- function dt(e, a) {
286
- const t = e ?? "";
287
- return t ? a[`chunk.${t}`] : void 0;
355
+ function ft(e, r) {
356
+ const n = e ?? "";
357
+ return n ? r[`chunk.${n}`] : void 0;
288
358
  }
289
- function ut(e) {
290
- const a = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());
291
- if (!a) return;
292
- let t = a[1];
293
- t.length === 3 && (t = t[0] + t[0] + t[1] + t[1] + t[2] + t[2]);
294
- const r = parseInt(t.slice(0, 2), 16), o = parseInt(t.slice(2, 4), 16), s = parseInt(t.slice(4, 6), 16);
295
- return `rgba(${r}, ${o}, ${s}, ${lt})`;
359
+ function gt(e) {
360
+ const r = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());
361
+ if (!r) return;
362
+ let n = r[1];
363
+ n.length === 3 && (n = n[0] + n[0] + n[1] + n[1] + n[2] + n[2]);
364
+ const a = parseInt(n.slice(0, 2), 16), o = parseInt(n.slice(2, 4), 16), i = parseInt(n.slice(4, 6), 16);
365
+ return `rgba(${a}, ${o}, ${i}, ${pt})`;
296
366
  }
297
- function be(e) {
367
+ function Ne(e) {
298
368
  if (!e) return;
299
- const a = ut(e);
300
- if (a)
301
- return { background: a, borderLeft: `3px solid ${e}` };
369
+ const r = gt(e);
370
+ if (r)
371
+ return { background: r, borderLeft: `3px solid ${e}` };
302
372
  }
303
- function ht(e) {
304
- const a = /* @__PURE__ */ new Map();
305
- e.forEach((o) => a.set(o.id, { row: o, children: [] }));
306
- const t = [];
373
+ function yt(e) {
374
+ const r = /* @__PURE__ */ new Map();
375
+ e.forEach((o) => r.set(o.id, { row: o, children: [] }));
376
+ const n = [];
307
377
  e.forEach((o) => {
308
- const s = a.get(o.id);
309
- o.parent_id && a.has(o.parent_id) ? a.get(o.parent_id).children.push(s) : t.push(s);
378
+ const i = r.get(o.id);
379
+ o.parent_id && r.has(o.parent_id) ? r.get(o.parent_id).children.push(i) : n.push(i);
310
380
  });
311
- const r = (o) => {
312
- o.sort((s, c) => s.row.position - c.row.position), o.forEach((s) => r(s.children));
381
+ const a = (o) => {
382
+ o.sort((i, c) => i.row.position - c.row.position), o.forEach((i) => a(i.children));
313
383
  };
314
- return r(t), t;
384
+ return a(n), n;
315
385
  }
316
- function Ce(e) {
386
+ function Ee(e) {
317
387
  return e === "image" ? "🖼" : e === "mermaid" ? "📊" : "";
318
388
  }
319
- function Ie(e, a) {
320
- for (const t of e) {
321
- if (t.row.id === a) return t;
322
- const r = Ie(t.children, a);
323
- if (r) return r;
389
+ function je(e, r) {
390
+ for (const n of e) {
391
+ if (n.row.id === r) return n;
392
+ const a = je(n.children, r);
393
+ if (a) return a;
324
394
  }
325
395
  }
326
- function mt({
396
+ function bt({
327
397
  tree: e,
328
- selectedId: a,
329
- onSelect: t,
330
- colorEnabled: r,
398
+ selectedId: r,
399
+ onSelect: n,
400
+ colorEnabled: a,
331
401
  scheme: o,
332
- linkedIds: s
402
+ linkedIds: i
333
403
  }) {
334
- const [c, i] = k(() => /* @__PURE__ */ new Map()), d = A((m) => {
335
- i((b) => {
336
- const p = new Map(b);
337
- return p.set(m, b.get(m) === !1), p;
404
+ const [c, s] = f(() => /* @__PURE__ */ new Map()), u = O((h) => {
405
+ s((v) => {
406
+ const m = new Map(v);
407
+ return m.set(h, v.get(h) === !1), m;
338
408
  });
339
409
  }, []);
340
- U(() => {
341
- if (!a) return;
342
- const m = pt(e, a);
343
- m.length !== 0 && i((b) => {
344
- let p = !1;
345
- const O = new Map(b);
346
- for (const N of m)
347
- O.get(N) === !1 && (O.set(N, !0), p = !0);
348
- return p ? O : b;
410
+ B(() => {
411
+ if (!r) return;
412
+ const h = kt(e, r);
413
+ h.length !== 0 && s((v) => {
414
+ let m = !1;
415
+ const A = new Map(v);
416
+ for (const C of h)
417
+ A.get(C) === !1 && (A.set(C, !0), m = !0);
418
+ return m ? A : v;
349
419
  });
350
- }, [e, a]);
351
- const g = r ? ye(o) : null;
352
- 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((m) => /* @__PURE__ */ n(
353
- Ue,
420
+ }, [e, r]);
421
+ const g = a ? ve(o) : null;
422
+ return e.length === 0 ? /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "No chunks." }) }) : /* @__PURE__ */ t("ul", { className: "tree chunk-tree", children: e.map((h) => /* @__PURE__ */ t(
423
+ Be,
354
424
  {
355
- node: m,
425
+ node: h,
356
426
  expanded: c,
357
- toggle: d,
358
- selectedId: a,
359
- onSelect: t,
427
+ toggle: u,
428
+ selectedId: r,
429
+ onSelect: n,
360
430
  tintScheme: g,
361
- linkedIds: s
431
+ linkedIds: i
362
432
  },
363
- m.row.id
433
+ h.row.id
364
434
  )) });
365
435
  }
366
- function pt(e, a) {
367
- const t = [], r = (o, s) => {
436
+ function kt(e, r) {
437
+ const n = [], a = (o, i) => {
368
438
  for (const c of o) {
369
- if (c.row.id === a)
370
- return t.push(...s), !0;
371
- if (r(c.children, [...s, c.row.id])) return !0;
439
+ if (c.row.id === r)
440
+ return n.push(...i), !0;
441
+ if (a(c.children, [...i, c.row.id])) return !0;
372
442
  }
373
443
  return !1;
374
444
  };
375
- return r(e, []), t;
445
+ return a(e, []), n;
376
446
  }
377
- function Ue({ node: e, expanded: a, toggle: t, selectedId: r, onSelect: o, tintScheme: s, linkedIds: c }) {
378
- const i = e.children.length > 0, d = a.get(e.row.id) !== !1, g = r === e.row.id, m = s ? be(dt(e.row.status, s)) : void 0, b = c?.has(e.row.id);
447
+ function Be({ node: e, expanded: r, toggle: n, selectedId: a, onSelect: o, tintScheme: i, linkedIds: c }) {
448
+ const s = e.children.length > 0, u = r.get(e.row.id) !== !1, g = a === e.row.id, h = i ? Ne(ft(e.row.status, i)) : void 0, v = c?.has(e.row.id);
379
449
  return /* @__PURE__ */ l("li", { className: `node chunk-node ${g ? "selected" : ""}`, children: [
380
- /* @__PURE__ */ l("div", { className: "row chunk-row", style: m, children: [
381
- /* @__PURE__ */ n(
450
+ /* @__PURE__ */ l("div", { className: "row chunk-row", style: h, children: [
451
+ /* @__PURE__ */ t(
382
452
  "button",
383
453
  {
384
454
  type: "button",
385
455
  className: "tree-caret",
386
- "aria-label": d ? "collapse" : "expand",
387
- disabled: !i,
388
- onClick: (p) => {
389
- p.stopPropagation(), i && t(e.row.id);
456
+ "aria-label": u ? "collapse" : "expand",
457
+ disabled: !s,
458
+ onClick: (m) => {
459
+ m.stopPropagation(), s && n(e.row.id);
390
460
  },
391
- children: i ? d ? "▼" : "▶" : "·"
461
+ children: s ? u ? "▼" : "▶" : "·"
392
462
  }
393
463
  ),
394
464
  /* @__PURE__ */ l(
@@ -399,961 +469,1298 @@ function Ue({ node: e, expanded: a, toggle: t, selectedId: r, onSelect: o, tintS
399
469
  onClick: () => o(e),
400
470
  title: e.row.title,
401
471
  children: [
402
- Ce(e.row.type) && /* @__PURE__ */ n("span", { className: "chunk-type-icon", "aria-hidden": !0, children: Ce(e.row.type) }),
403
- /* @__PURE__ */ n("span", { className: "chunk-title", children: e.row.title || "(untitled)" }),
404
- e.row.type && /* @__PURE__ */ n("span", { className: "chunk-badge", children: e.row.type }),
405
- e.row.status && /* @__PURE__ */ n("span", { className: "chunk-badge chunk-status", children: e.row.status }),
406
- b && /* @__PURE__ */ n("span", { className: "chunk-link-badge", title: "Has cross-reference links", "aria-label": "linked", children: "🔗" })
472
+ Ee(e.row.type) && /* @__PURE__ */ t("span", { className: "chunk-type-icon", "aria-hidden": !0, children: Ee(e.row.type) }),
473
+ /* @__PURE__ */ t("span", { className: "chunk-title", children: e.row.title || "(untitled)" }),
474
+ e.row.type && /* @__PURE__ */ t("span", { className: "chunk-badge", children: e.row.type }),
475
+ e.row.status && /* @__PURE__ */ t("span", { className: "chunk-badge chunk-status", children: e.row.status }),
476
+ v && /* @__PURE__ */ t("span", { className: "chunk-link-badge", title: "Has cross-reference links", "aria-label": "linked", children: "🔗" })
407
477
  ]
408
478
  }
409
479
  )
410
480
  ] }),
411
- i && d && /* @__PURE__ */ n("ul", { className: "children chunk-children", children: e.children.map((p) => /* @__PURE__ */ n(
412
- Ue,
481
+ s && u && /* @__PURE__ */ t("ul", { className: "children chunk-children", children: e.children.map((m) => /* @__PURE__ */ t(
482
+ Be,
413
483
  {
414
- node: p,
415
- expanded: a,
416
- toggle: t,
417
- selectedId: r,
484
+ node: m,
485
+ expanded: r,
486
+ toggle: n,
487
+ selectedId: a,
418
488
  onSelect: o,
419
- tintScheme: s,
489
+ tintScheme: i,
420
490
  linkedIds: c
421
491
  },
422
- p.row.id
492
+ m.row.id
423
493
  )) })
424
494
  ] });
425
495
  }
426
- let ft = 0;
427
- function le({ code: e }) {
428
- const a = ne(null), [t, r] = k({});
429
- return U(() => {
496
+ let vt = 0;
497
+ function ue({ code: e }) {
498
+ const r = ne(null), [n, a] = f({});
499
+ return B(() => {
430
500
  let o = !1;
431
501
  return (async () => {
432
502
  try {
433
- const s = (await import("mermaid")).default, c = a.current?.closest("[data-theme]")?.getAttribute("data-theme"), i = c ? c === "dark" : !0;
434
- s.initialize({ startOnLoad: !1, theme: i ? "dark" : "default", securityLevel: "strict" });
435
- const { svg: d } = await s.render(`lc-mmd-${ft++}`, e);
436
- o || r({ svg: d });
503
+ const i = (await import("mermaid")).default, c = r.current?.closest("[data-theme]")?.getAttribute("data-theme"), s = c ? c === "dark" : !0;
504
+ i.initialize({ startOnLoad: !1, theme: s ? "dark" : "default", securityLevel: "strict" });
505
+ const { svg: u } = await i.render(`lc-mmd-${vt++}`, e);
506
+ o || a({ svg: u });
437
507
  } catch {
438
- o || r({ err: !0 });
508
+ o || a({ err: !0 });
439
509
  }
440
510
  })(), () => {
441
511
  o = !0;
442
512
  };
443
- }, [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: a, className: "md-mermaid", dangerouslySetInnerHTML: { __html: t.svg } }) : /* @__PURE__ */ n("div", { ref: a, className: "md-mermaid md-mermaid-loading", children: "rendering diagram…" });
513
+ }, [e]), n.err ? /* @__PURE__ */ t("pre", { className: "md-pre md-mermaid-error", title: "diagram failed to render", children: /* @__PURE__ */ t("code", { children: e }) }) : n.svg ? /* @__PURE__ */ t("div", { ref: r, className: "md-mermaid", dangerouslySetInnerHTML: { __html: n.svg } }) : /* @__PURE__ */ t("div", { ref: r, className: "md-mermaid md-mermaid-loading", children: "rendering diagram…" });
444
514
  }
445
- function gt({ chunk: e, scope: a, browse: t, onClose: r, onSaved: o }) {
446
- const s = se(), [c, i] = k(e.title), [d, g] = k(e.type ?? ""), [m, b] = k(e.status ?? ""), [p, O] = k(e.body ?? ""), [N, T] = k(
515
+ function Nt({ chunk: e, scope: r, browse: n, onClose: a, onSaved: o }) {
516
+ const i = ae(), [c, s] = f(e.title), [u, g] = f(e.type ?? ""), [h, v] = f(e.status ?? ""), [m, A] = f(e.body ?? ""), [C, L] = f(
447
517
  e.fields ? JSON.stringify(e.fields, null, 2) : ""
448
- ), [j, P] = k(!1), [W, R] = k(null), [z, F] = k(!1), B = d === "mermaid", x = d === "image" || !!e.asset, [C, I] = k(p);
449
- U(() => {
450
- if (!B) return;
451
- const h = setTimeout(() => I(p), 400);
452
- return () => clearTimeout(h);
453
- }, [p, B]);
454
- const J = async (h) => {
455
- R(null), P(!0);
518
+ ), [F, I] = f((e.tags ?? []).join(", ")), [P, M] = f(!1), [j, $] = f(null), [G, R] = f(!1), y = u === "mermaid", D = u === "image" || !!e.asset, [J, z] = f(m);
519
+ B(() => {
520
+ if (!y) return;
521
+ const w = setTimeout(() => z(m), 400);
522
+ return () => clearTimeout(w);
523
+ }, [m, y]);
524
+ const N = async (w) => {
525
+ $(null), M(!0);
456
526
  try {
457
- const { mediaType: f, data: E } = await Te(h), D = await s.documentSetAsset(e.id, f, E, h.name, a, t);
458
- o(D), r();
459
- } catch (f) {
460
- R(f instanceof Error ? f.message : String(f)), P(!1);
527
+ const { mediaType: S, data: T } = await Oe(w), ee = await i.documentSetAsset(e.id, S, T, w.name, r, n);
528
+ o(ee), a();
529
+ } catch (S) {
530
+ $(S instanceof Error ? S.message : String(S)), M(!1);
461
531
  }
462
532
  };
463
- return /* @__PURE__ */ n("div", { className: "modal-overlay", onClick: r, children: /* @__PURE__ */ l("form", { className: "modal chunk-editor", onClick: (h) => h.stopPropagation(), onSubmit: async (h) => {
464
- h.preventDefault(), R(null), F(!1);
465
- const f = {
466
- body: p,
533
+ return /* @__PURE__ */ t("div", { className: "modal-overlay", onClick: a, children: /* @__PURE__ */ l("form", { className: "modal chunk-editor", onClick: (w) => w.stopPropagation(), onSubmit: async (w) => {
534
+ w.preventDefault(), $(null), R(!1);
535
+ const S = {
536
+ body: m,
467
537
  title: c,
468
- type: d,
469
- status: m
538
+ type: u,
539
+ status: h,
540
+ // Parse the comma-separated list; replace-set is intentional (the box shows
541
+ // the chunk's tags, so saving makes it exactly what's in the box).
542
+ tags: F.split(",").map((T) => T.trim()).filter((T) => T !== "")
470
543
  };
471
- if (N.trim() !== "")
544
+ if (C.trim() !== "")
472
545
  try {
473
- f.fields = JSON.parse(N);
546
+ S.fields = JSON.parse(C);
474
547
  } catch {
475
- R("fields must be valid JSON");
548
+ $("fields must be valid JSON");
476
549
  return;
477
550
  }
478
- P(!0);
551
+ M(!0);
479
552
  try {
480
- const E = await s.documentUpdateChunk(e.id, e.revision, f, a, t);
481
- o(E), r();
482
- } catch (E) {
483
- const D = E instanceof Error ? E.message : String(E);
484
- R(D), F(/revision conflict/i.test(D)), P(!1);
553
+ const T = await i.documentUpdateChunk(e.id, e.revision, S, r, n);
554
+ o(T), a();
555
+ } catch (T) {
556
+ const ee = T instanceof Error ? T.message : String(T);
557
+ $(ee), R(/revision conflict/i.test(ee)), M(!1);
485
558
  }
486
559
  }, children: [
487
560
  /* @__PURE__ */ l("div", { className: "modal-header sticky-top", children: [
488
- /* @__PURE__ */ n("h3", { children: "Edit chunk" }),
561
+ /* @__PURE__ */ t("h3", { children: "Edit chunk" }),
489
562
  /* @__PURE__ */ l("div", { className: "modal-buttons modal-buttons-top", children: [
490
- /* @__PURE__ */ n("button", { type: "button", onClick: r, disabled: j, children: "cancel" }),
491
- /* @__PURE__ */ n("button", { type: "submit", className: "primary", disabled: j, children: j ? "saving…" : "save" })
563
+ /* @__PURE__ */ t("button", { type: "button", onClick: a, disabled: P, children: "cancel" }),
564
+ /* @__PURE__ */ t("button", { type: "submit", className: "primary", disabled: P, children: P ? "saving…" : "save" })
492
565
  ] })
493
566
  ] }),
494
- W && /* @__PURE__ */ l("div", { className: "modal-err", children: [
495
- W,
496
- z && " — reopen the chunk to load the latest, then reapply your edit."
567
+ j && /* @__PURE__ */ l("div", { className: "modal-err", children: [
568
+ j,
569
+ G && " — reopen the chunk to load the latest, then reapply your edit."
497
570
  ] }),
498
571
  /* @__PURE__ */ l("label", { className: "path-field", children: [
499
- /* @__PURE__ */ n("span", { children: "Title" }),
500
- /* @__PURE__ */ n("input", { className: "path-modal-input", value: c, onChange: (h) => i(h.target.value) })
572
+ /* @__PURE__ */ t("span", { children: "Title" }),
573
+ /* @__PURE__ */ t("input", { className: "path-modal-input", value: c, onChange: (w) => s(w.target.value) })
501
574
  ] }),
502
575
  /* @__PURE__ */ l("div", { className: "chunk-editor-row", children: [
503
576
  /* @__PURE__ */ l("label", { className: "path-field", children: [
504
- /* @__PURE__ */ n("span", { children: "Type" }),
505
- /* @__PURE__ */ n(
577
+ /* @__PURE__ */ t("span", { children: "Type" }),
578
+ /* @__PURE__ */ t(
506
579
  "input",
507
580
  {
508
581
  className: "path-modal-input",
509
- value: d,
582
+ value: u,
510
583
  placeholder: "(none)",
511
- onChange: (h) => g(h.target.value)
584
+ onChange: (w) => g(w.target.value)
512
585
  }
513
586
  )
514
587
  ] }),
515
588
  /* @__PURE__ */ l("label", { className: "path-field", children: [
516
- /* @__PURE__ */ n("span", { children: "Status" }),
517
- /* @__PURE__ */ n(
589
+ /* @__PURE__ */ t("span", { children: "Status" }),
590
+ /* @__PURE__ */ t(
518
591
  "input",
519
592
  {
520
593
  className: "path-modal-input",
521
- value: m,
594
+ value: h,
522
595
  placeholder: "(none)",
523
- onChange: (h) => b(h.target.value)
596
+ onChange: (w) => v(w.target.value)
524
597
  }
525
598
  )
526
599
  ] })
527
600
  ] }),
528
- x && /* @__PURE__ */ l("label", { className: "path-field", children: [
529
- /* @__PURE__ */ n("span", { children: "Replace image" }),
530
- /* @__PURE__ */ n(
601
+ /* @__PURE__ */ l("label", { className: "path-field", children: [
602
+ /* @__PURE__ */ t("span", { children: "Tags" }),
603
+ /* @__PURE__ */ t(
604
+ "input",
605
+ {
606
+ className: "path-modal-input",
607
+ value: F,
608
+ placeholder: "comma-separated, nest with a slash: area/sub, priority/high",
609
+ onChange: (w) => I(w.target.value)
610
+ }
611
+ )
612
+ ] }),
613
+ D && /* @__PURE__ */ l("label", { className: "path-field", children: [
614
+ /* @__PURE__ */ t("span", { children: "Replace image" }),
615
+ /* @__PURE__ */ t(
531
616
  "input",
532
617
  {
533
618
  type: "file",
534
619
  accept: "image/png,image/jpeg,image/gif,image/webp",
535
- disabled: j,
536
- onChange: (h) => {
537
- const f = h.target.files?.[0];
538
- f && J(f);
620
+ disabled: P,
621
+ onChange: (w) => {
622
+ const S = w.target.files?.[0];
623
+ S && N(S);
539
624
  }
540
625
  }
541
626
  )
542
627
  ] }),
543
628
  /* @__PURE__ */ l("label", { className: "path-field", children: [
544
- /* @__PURE__ */ n("span", { children: B ? "Mermaid source" : x ? "Caption (optional)" : "Body (Markdown)" }),
545
- /* @__PURE__ */ n(
629
+ /* @__PURE__ */ t("span", { children: y ? "Mermaid source" : D ? "Caption (optional)" : "Body (Markdown)" }),
630
+ /* @__PURE__ */ t(
546
631
  "textarea",
547
632
  {
548
633
  className: "modal-textarea chunk-body-input",
549
- rows: B ? 8 : 12,
550
- value: p,
551
- onChange: (h) => O(h.target.value)
634
+ rows: y ? 8 : 12,
635
+ value: m,
636
+ onChange: (w) => A(w.target.value)
552
637
  }
553
638
  )
554
639
  ] }),
555
- B && /* @__PURE__ */ l("div", { className: "path-field", children: [
556
- /* @__PURE__ */ n("span", { children: "Preview" }),
557
- /* @__PURE__ */ n("div", { className: "chunk-mermaid-preview", children: C.trim() ? /* @__PURE__ */ n(le, { code: C }) : /* @__PURE__ */ n("p", { className: "doc-empty-body", children: "(enter Mermaid source above)" }) })
640
+ y && /* @__PURE__ */ l("div", { className: "path-field", children: [
641
+ /* @__PURE__ */ t("span", { children: "Preview" }),
642
+ /* @__PURE__ */ t("div", { className: "chunk-mermaid-preview", children: J.trim() ? /* @__PURE__ */ t(ue, { code: J }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "(enter Mermaid source above)" }) })
558
643
  ] }),
559
644
  /* @__PURE__ */ l("label", { className: "path-field", children: [
560
- /* @__PURE__ */ n("span", { children: "Fields (JSON, optional)" }),
561
- /* @__PURE__ */ n(
645
+ /* @__PURE__ */ t("span", { children: "Fields (JSON, optional)" }),
646
+ /* @__PURE__ */ t(
562
647
  "textarea",
563
648
  {
564
649
  className: "modal-textarea chunk-fields-input",
565
650
  rows: 4,
566
- value: N,
651
+ value: C,
567
652
  placeholder: "{}",
568
- onChange: (h) => T(h.target.value)
653
+ onChange: (w) => L(w.target.value)
569
654
  }
570
655
  )
571
656
  ] })
572
657
  ] }) });
573
658
  }
574
- function yt(e) {
575
- const a = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec((e ?? "").trim());
576
- if (!a) return "#888888";
577
- let t = a[1];
578
- return t.length === 3 && (t = t[0] + t[0] + t[1] + t[1] + t[2] + t[2]), "#" + t.toLowerCase();
659
+ function wt(e) {
660
+ const r = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec((e ?? "").trim());
661
+ if (!r) return "#888888";
662
+ let n = r[1];
663
+ return n.length === 3 && (n = n[0] + n[0] + n[1] + n[1] + n[2] + n[2]), "#" + n.toLowerCase();
579
664
  }
580
- function bt({
665
+ function Ct({
581
666
  documentId: e,
582
- rootChunkId: a,
583
- docType: t,
584
- docStatus: r,
667
+ rootChunkId: r,
668
+ docType: n,
669
+ docStatus: a,
585
670
  chunkStatuses: o,
586
- scope: s,
671
+ scope: i,
587
672
  browse: c,
588
- onClose: i,
589
- onSaved: d
673
+ onClose: s,
674
+ onSaved: u
590
675
  }) {
591
- const g = se(), [m, b] = k(null), [p, O] = k(!1), [N, T] = k({}), [j, P] = k(!1), [W, R] = k(null), [z, F] = k(null), B = G(() => {
592
- const h = new Set(Object.keys(fe));
593
- t && h.add(`doc.${t}.${r || "draft"}`);
594
- for (const f of o) f && h.add(`chunk.${f}`);
595
- return [...h].sort();
596
- }, [t, r, o]);
597
- U(() => {
598
- let h = !1;
599
- return g.documentGetChunk(a, s, c).then((f) => {
600
- if (h) return;
601
- b(f);
602
- const E = f.fields ?? {};
603
- O(E.color_enabled === !0);
604
- const D = E.color_scheme ?? {};
605
- T({ ...fe, ...D });
606
- }).catch((f) => !h && F(f instanceof Error ? f.message : String(f))), () => {
607
- h = !0;
676
+ const g = ae(), [h, v] = f(null), [m, A] = f(!1), [C, L] = f({}), [F, I] = f(!1), [P, M] = f(null), [j, $] = f(null), G = q(() => {
677
+ const b = new Set(Object.keys(be));
678
+ n && b.add(`doc.${n}.${a || "draft"}`);
679
+ for (const p of o) p && b.add(`chunk.${p}`);
680
+ return [...b].sort();
681
+ }, [n, a, o]);
682
+ B(() => {
683
+ let b = !1;
684
+ return g.documentGetChunk(r, i, c).then((p) => {
685
+ if (b) return;
686
+ v(p);
687
+ const w = p.fields ?? {};
688
+ A(w.color_enabled === !0);
689
+ const S = w.color_scheme ?? {};
690
+ L({ ...be, ...S });
691
+ }).catch((p) => !b && $(p instanceof Error ? p.message : String(p))), () => {
692
+ b = !0;
608
693
  };
609
- }, [g, a, s, c]);
610
- const x = (h, f) => T((E) => ({ ...E, [h]: f })), C = (h) => ({
611
- ...h ?? {},
612
- color_enabled: p,
613
- color_scheme: N
614
- }), I = async () => {
615
- if (m) {
616
- P(!0), F(null), R(null);
694
+ }, [g, r, i, c]);
695
+ const R = (b, p) => L((w) => ({ ...w, [b]: p })), y = (b) => ({
696
+ ...b ?? {},
697
+ color_enabled: m,
698
+ color_scheme: C
699
+ }), D = async () => {
700
+ if (h) {
701
+ I(!0), $(null), M(null);
617
702
  try {
618
703
  await g.documentUpdateChunk(
619
- a,
620
- m.revision,
621
- { fields: C(m.fields) },
622
- s,
704
+ r,
705
+ h.revision,
706
+ { fields: y(h.fields) },
707
+ i,
623
708
  c
624
- ), d(), i();
625
- } catch (h) {
626
- F(h instanceof Error ? h.message : String(h)), P(!1);
709
+ ), u(), s();
710
+ } catch (b) {
711
+ $(b instanceof Error ? b.message : String(b)), I(!1);
627
712
  }
628
713
  }
629
714
  }, J = async () => {
630
- if (!t) {
631
- F("this document has no type to match");
715
+ if (!n) {
716
+ $("this document has no type to match");
632
717
  return;
633
718
  }
634
- P(!0), F(null), R(null);
719
+ I(!0), $(null), M(null);
635
720
  try {
636
- const { documents: h } = await g.documentsSummary({ underPath: "/" }, s, c), f = (h ?? []).filter(
637
- (D) => D.type === t && D.document_id !== e && D.root_chunk_id
721
+ const { documents: b } = await g.documentsSummary({ underPath: "/" }, i, c), p = (b ?? []).filter(
722
+ (S) => S.type === n && S.document_id !== e && S.root_chunk_id
638
723
  );
639
- let E = 0;
640
- for (const D of f)
724
+ let w = 0;
725
+ for (const S of p)
641
726
  try {
642
- const Y = await g.documentGetChunk(D.root_chunk_id, s, c);
727
+ const T = await g.documentGetChunk(S.root_chunk_id, i, c);
643
728
  await g.documentUpdateChunk(
644
- D.root_chunk_id,
645
- Y.revision,
646
- { fields: C(Y.fields) },
647
- s,
729
+ S.root_chunk_id,
730
+ T.revision,
731
+ { fields: y(T.fields) },
732
+ i,
648
733
  c
649
- ), E++;
734
+ ), w++;
650
735
  } catch {
651
736
  }
652
- R(`Applied to ${E} other ${t} document(s).`), d();
653
- } catch (h) {
654
- F(h instanceof Error ? h.message : String(h));
737
+ M(`Applied to ${w} other ${n} document(s).`), u();
738
+ } catch (b) {
739
+ $(b instanceof Error ? b.message : String(b));
655
740
  } finally {
656
- P(!1);
741
+ I(!1);
657
742
  }
658
- }, Q = B.filter((h) => h.startsWith("doc.")), M = B.filter((h) => h.startsWith("chunk."));
659
- return /* @__PURE__ */ n("div", { className: "modal-overlay", onClick: i, children: /* @__PURE__ */ l("div", { className: "modal scheme-editor", onClick: (h) => h.stopPropagation(), children: [
743
+ }, z = G.filter((b) => b.startsWith("doc.")), N = G.filter((b) => b.startsWith("chunk."));
744
+ return /* @__PURE__ */ t("div", { className: "modal-overlay", onClick: s, children: /* @__PURE__ */ l("div", { className: "modal scheme-editor", onClick: (b) => b.stopPropagation(), children: [
660
745
  /* @__PURE__ */ l("div", { className: "scheme-editor-head", children: [
661
- /* @__PURE__ */ n("h3", { children: "Document colors" }),
746
+ /* @__PURE__ */ t("h3", { children: "Document colors" }),
662
747
  /* @__PURE__ */ l("div", { className: "scheme-editor-actions", children: [
663
- /* @__PURE__ */ n("button", { type: "button", onClick: i, disabled: j, children: "cancel" }),
664
- /* @__PURE__ */ n("button", { type: "button", className: "primary", onClick: () => {
665
- I();
666
- }, disabled: j || !m, children: j ? "saving…" : "save" })
748
+ /* @__PURE__ */ t("button", { type: "button", onClick: s, disabled: F, children: "cancel" }),
749
+ /* @__PURE__ */ t("button", { type: "button", className: "primary", onClick: () => {
750
+ D();
751
+ }, disabled: F || !h, children: F ? "saving…" : "save" })
667
752
  ] })
668
753
  ] }),
669
- z && /* @__PURE__ */ n("div", { className: "modal-err", children: z }),
670
- m ? /* @__PURE__ */ l(q, { children: [
754
+ j && /* @__PURE__ */ t("div", { className: "modal-err", children: j }),
755
+ h ? /* @__PURE__ */ l(Y, { children: [
671
756
  /* @__PURE__ */ l("label", { className: "scheme-toggle", children: [
672
- /* @__PURE__ */ n(
757
+ /* @__PURE__ */ t(
673
758
  "input",
674
759
  {
675
760
  type: "checkbox",
676
- checked: p,
677
- onChange: (h) => O(h.target.checked)
761
+ checked: m,
762
+ onChange: (b) => A(b.target.checked)
678
763
  }
679
764
  ),
680
- /* @__PURE__ */ n("span", { children: "Enable coloring for this document" })
765
+ /* @__PURE__ */ t("span", { children: "Enable coloring for this document" })
681
766
  ] }),
682
- /* @__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." }),
767
+ /* @__PURE__ */ t("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." }),
683
768
  /* @__PURE__ */ l("div", { className: "scheme-group", children: [
684
- /* @__PURE__ */ n("h4", { children: "Document (type · status)" }),
685
- Q.map((h) => /* @__PURE__ */ n(_e, { label: h.slice(4), value: N[h], onChange: (f) => x(h, f) }, h))
769
+ /* @__PURE__ */ t("h4", { children: "Document (type · status)" }),
770
+ z.map((b) => /* @__PURE__ */ t(xe, { label: b.slice(4), value: C[b], onChange: (p) => R(b, p) }, b))
686
771
  ] }),
687
772
  /* @__PURE__ */ l("div", { className: "scheme-group", children: [
688
- /* @__PURE__ */ n("h4", { children: "Chunks (status)" }),
689
- M.map((h) => /* @__PURE__ */ n(_e, { label: h.slice(6), value: N[h], onChange: (f) => x(h, f) }, h))
773
+ /* @__PURE__ */ t("h4", { children: "Chunks (status)" }),
774
+ N.map((b) => /* @__PURE__ */ t(xe, { label: b.slice(6), value: C[b], onChange: (p) => R(b, p) }, b))
690
775
  ] }),
691
776
  /* @__PURE__ */ l("div", { className: "scheme-editor-foot", children: [
692
777
  /* @__PURE__ */ l("button", { type: "button", onClick: () => {
693
778
  J();
694
- }, disabled: j || !t, title: t ? `Apply this palette to every other ${t} document` : "This document has no type", children: [
779
+ }, disabled: F || !n, title: n ? `Apply this palette to every other ${n} document` : "This document has no type", children: [
695
780
  "copy to all ",
696
- t || "same-type",
781
+ n || "same-type",
697
782
  " documents"
698
783
  ] }),
699
- W && /* @__PURE__ */ n("span", { className: "scheme-status", children: W })
784
+ P && /* @__PURE__ */ t("span", { className: "scheme-status", children: P })
700
785
  ] })
701
- ] }) : /* @__PURE__ */ n("p", { className: "modal-context", children: "Loading…" })
786
+ ] }) : /* @__PURE__ */ t("p", { className: "modal-context", children: "Loading…" })
702
787
  ] }) });
703
788
  }
704
- function _e({ label: e, value: a, onChange: t }) {
705
- const r = yt(a);
789
+ function xe({ label: e, value: r, onChange: n }) {
790
+ const a = wt(r);
706
791
  return /* @__PURE__ */ l("label", { className: "scheme-row", children: [
707
- /* @__PURE__ */ n("input", { type: "color", value: r, onChange: (o) => t(o.target.value) }),
708
- /* @__PURE__ */ n("span", { className: "scheme-key", children: e }),
709
- /* @__PURE__ */ n("code", { className: "scheme-hex", children: r })
792
+ /* @__PURE__ */ t("input", { type: "color", value: a, onChange: (o) => n(o.target.value) }),
793
+ /* @__PURE__ */ t("span", { className: "scheme-key", children: e }),
794
+ /* @__PURE__ */ t("code", { className: "scheme-hex", children: a })
710
795
  ] });
711
796
  }
712
- const pe = 24;
713
- function kt({
797
+ const _t = 8, St = 20;
798
+ function Et(e) {
799
+ return /embedder|embedding|vector|semantic|not configured/i.test(e);
800
+ }
801
+ function xt({
802
+ documentId: e,
803
+ selectedId: r,
804
+ scope: n,
805
+ browse: a,
806
+ onSelectChunk: o
807
+ }) {
808
+ const i = ae(), [c, s] = f(!1), [u, g] = f(!1), [h, v] = f(void 0), [m, A] = f([]), [C, L] = f([]), [F, I] = f(null), [P, M] = f([]), [j, $] = f(!1);
809
+ B(() => {
810
+ if (!c || !r) return;
811
+ const y = r;
812
+ let D = !1;
813
+ return g(!0), Promise.allSettled([
814
+ i.documentBacklinks(y, n, a),
815
+ i.documentRelated(y, n, a, _t),
816
+ i.documentUnlinkedMentions(y, n, a, St)
817
+ ]).then(([J, z, N]) => {
818
+ if (!D) {
819
+ if (A(J.status === "fulfilled" ? J.value.backlinks ?? [] : []), z.status === "fulfilled")
820
+ L(z.value.related ?? []), I(null);
821
+ else {
822
+ L([]);
823
+ const b = z.reason instanceof Error ? z.reason.message : String(z.reason);
824
+ I(Et(b) ? "semantic search not configured" : b);
825
+ }
826
+ N.status === "fulfilled" ? (M(N.value.unlinked_mentions ?? []), $(!!N.value.truncated)) : (M([]), $(!1)), v(y), g(!1);
827
+ }
828
+ }), () => {
829
+ D = !0;
830
+ };
831
+ }, [i, c, r, n, a]);
832
+ const G = (y) => !!y && y !== e;
833
+ return /* @__PURE__ */ l("div", { className: "doc-conn", children: [
834
+ /* @__PURE__ */ l(
835
+ "button",
836
+ {
837
+ type: "button",
838
+ className: "doc-conn-toggle",
839
+ onClick: () => s((y) => !y),
840
+ children: [
841
+ c ? "▼" : "▶",
842
+ " Connections"
843
+ ]
844
+ }
845
+ ),
846
+ c && /* @__PURE__ */ t("div", { className: "doc-conn-body", children: r ? !!(c && r && !u && h === r) ? /* @__PURE__ */ l(Y, { children: [
847
+ /* @__PURE__ */ l("div", { className: "doc-conn-group", children: [
848
+ /* @__PURE__ */ t("h5", { children: "Backlinks" }),
849
+ m.length === 0 ? /* @__PURE__ */ t("p", { className: "doc-conn-empty", children: "none" }) : /* @__PURE__ */ t("ul", { className: "doc-conn-list", children: m.map((y, D) => /* @__PURE__ */ l("li", { className: "doc-conn-row", children: [
850
+ /* @__PURE__ */ t(
851
+ ge,
852
+ {
853
+ id: y.from_id,
854
+ title: y.from_title,
855
+ crossDoc: G(y.from_document_id),
856
+ onSelect: o
857
+ }
858
+ ),
859
+ /* @__PURE__ */ t("span", { className: "doc-ref-kind", children: y.kind }),
860
+ y.auto && /* @__PURE__ */ t("span", { className: "doc-conn-auto", title: "Auto-linked from a [[wikilink]]", children: "auto" })
861
+ ] }, `${y.from_id}-${y.kind}-${D}`)) })
862
+ ] }),
863
+ /* @__PURE__ */ l("div", { className: "doc-conn-group", children: [
864
+ /* @__PURE__ */ t("h5", { children: "Related" }),
865
+ F ? /* @__PURE__ */ t("p", { className: "doc-conn-empty", children: F }) : C.length === 0 ? /* @__PURE__ */ t("p", { className: "doc-conn-empty", children: "none" }) : /* @__PURE__ */ t("ul", { className: "doc-conn-list", children: C.map((y, D) => /* @__PURE__ */ l("li", { className: "doc-conn-row", children: [
866
+ /* @__PURE__ */ t(
867
+ ge,
868
+ {
869
+ id: y.chunk_id,
870
+ title: y.title,
871
+ crossDoc: G(y.document_id),
872
+ onSelect: o
873
+ }
874
+ ),
875
+ /* @__PURE__ */ t("span", { className: "doc-conn-score", title: "similarity score", children: y.score.toFixed(2) })
876
+ ] }, `${y.chunk_id}-${D}`)) })
877
+ ] }),
878
+ /* @__PURE__ */ l("div", { className: "doc-conn-group", children: [
879
+ /* @__PURE__ */ t("h5", { children: "Unlinked mentions" }),
880
+ P.length === 0 ? /* @__PURE__ */ t("p", { className: "doc-conn-empty", children: "none" }) : /* @__PURE__ */ l("ul", { className: "doc-conn-list", children: [
881
+ P.map((y, D) => /* @__PURE__ */ t("li", { className: "doc-conn-row", children: /* @__PURE__ */ t(
882
+ ge,
883
+ {
884
+ id: y.chunk_id,
885
+ title: y.title,
886
+ crossDoc: G(y.document_id),
887
+ onSelect: o
888
+ }
889
+ ) }, `${y.chunk_id}-${D}`)),
890
+ j && /* @__PURE__ */ t("li", { className: "doc-conn-more", "aria-hidden": !0, children: "(more…)" })
891
+ ] })
892
+ ] })
893
+ ] }) : /* @__PURE__ */ t("p", { className: "doc-conn-empty", children: "loading…" }) : /* @__PURE__ */ t("p", { className: "doc-conn-empty", children: "Select a chunk." }) })
894
+ ] });
895
+ }
896
+ function ge({
897
+ id: e,
898
+ title: r,
899
+ crossDoc: n,
900
+ onSelect: a
901
+ }) {
902
+ const o = r || e.slice(0, 8);
903
+ return n ? /* @__PURE__ */ l("span", { className: "doc-ref-target external", title: "In another document", children: [
904
+ o,
905
+ " ↗"
906
+ ] }) : /* @__PURE__ */ t("button", { type: "button", className: "doc-ref-target", onClick: () => a(e), children: o });
907
+ }
908
+ const ye = 24;
909
+ function Dt({
714
910
  edges: e,
715
- documentId: a,
716
- selectedId: t,
717
- onSelectChunk: r
911
+ documentId: r,
912
+ selectedId: n,
913
+ onSelectChunk: a
718
914
  }) {
719
- const [o, s] = k(!1), [c, i] = k(!1);
915
+ const [o, i] = f(!1), [c, s] = f(!1);
720
916
  if (e.length === 0) return null;
721
- const d = t ? e.filter((b) => b.from_id === t || b.to_id === t) : [], g = c ? e : e.slice(0, pe), m = Nt(g);
917
+ const u = n ? e.filter((v) => v.from_id === n || v.to_id === n) : [], g = c ? e : e.slice(0, ye), h = Mt(g);
722
918
  return /* @__PURE__ */ l("div", { className: "doc-refs", children: [
723
- t && /* @__PURE__ */ l("div", { className: "doc-refs-list-wrap", children: [
724
- /* @__PURE__ */ n("h4", { children: "References" }),
725
- d.length === 0 ? /* @__PURE__ */ n("p", { className: "doc-refs-empty", children: "This chunk has no links." }) : /* @__PURE__ */ n("ul", { className: "doc-refs-list", children: d.map((b, p) => /* @__PURE__ */ n(
726
- vt,
919
+ n && /* @__PURE__ */ l("div", { className: "doc-refs-list-wrap", children: [
920
+ /* @__PURE__ */ t("h4", { children: "References" }),
921
+ u.length === 0 ? /* @__PURE__ */ t("p", { className: "doc-refs-empty", children: "This chunk has no links." }) : /* @__PURE__ */ t("ul", { className: "doc-refs-list", children: u.map((v, m) => /* @__PURE__ */ t(
922
+ Rt,
727
923
  {
728
- edge: b,
729
- selectedId: t,
730
- documentId: a,
731
- onSelectChunk: r
924
+ edge: v,
925
+ selectedId: n,
926
+ documentId: r,
927
+ onSelectChunk: a
732
928
  },
733
- `${b.from_id}-${b.to_id}-${b.kind}-${p}`
929
+ `${v.from_id}-${v.to_id}-${v.kind}-${m}`
734
930
  )) })
735
931
  ] }),
736
932
  /* @__PURE__ */ l("div", { className: "doc-graph", children: [
737
- /* @__PURE__ */ l("button", { type: "button", className: "doc-graph-toggle", onClick: () => s((b) => !b), children: [
933
+ /* @__PURE__ */ l("button", { type: "button", className: "doc-graph-toggle", onClick: () => i((v) => !v), children: [
738
934
  o ? "▼" : "▶",
739
935
  " relationship graph (",
740
936
  e.length,
741
937
  ")"
742
938
  ] }),
743
- o && /* @__PURE__ */ l(q, { children: [
744
- /* @__PURE__ */ n(le, { code: m }),
745
- e.length > pe && /* @__PURE__ */ n("button", { type: "button", className: "doc-graph-more", onClick: () => i((b) => !b), children: c ? `show top ${pe}` : `show all ${e.length}` })
939
+ o && /* @__PURE__ */ l(Y, { children: [
940
+ /* @__PURE__ */ t(ue, { code: h }),
941
+ e.length > ye && /* @__PURE__ */ t("button", { type: "button", className: "doc-graph-more", onClick: () => s((v) => !v), children: c ? `show top ${ye}` : `show all ${e.length}` })
746
942
  ] })
747
943
  ] })
748
944
  ] });
749
945
  }
750
- function vt({
946
+ function Rt({
751
947
  edge: e,
752
- selectedId: a,
753
- documentId: t,
754
- onSelectChunk: r
948
+ selectedId: r,
949
+ documentId: n,
950
+ onSelectChunk: a
755
951
  }) {
756
- const o = e.from_id === a, s = o ? e.to_id : e.from_id, c = (o ? e.to_title : e.from_title) || s.slice(0, 8), i = o ? e.to_document_id : e.from_document_id, d = !i || i === t;
952
+ const o = e.from_id === r, i = o ? e.to_id : e.from_id, c = (o ? e.to_title : e.from_title) || i.slice(0, 8), s = o ? e.to_document_id : e.from_document_id, u = !s || s === n;
757
953
  return /* @__PURE__ */ l("li", { className: "doc-ref", children: [
758
- /* @__PURE__ */ n("span", { className: "doc-ref-kind", children: e.kind }),
759
- /* @__PURE__ */ n("span", { className: "doc-ref-arrow", "aria-hidden": !0, children: o ? "→" : "←" }),
760
- d ? /* @__PURE__ */ n("button", { type: "button", className: "doc-ref-target", onClick: () => r(s), children: c }) : /* @__PURE__ */ l("span", { className: "doc-ref-target external", title: "In another document", children: [
954
+ /* @__PURE__ */ t("span", { className: "doc-ref-kind", children: e.kind }),
955
+ /* @__PURE__ */ t("span", { className: "doc-ref-arrow", "aria-hidden": !0, children: o ? "→" : "←" }),
956
+ u ? /* @__PURE__ */ t("button", { type: "button", className: "doc-ref-target", onClick: () => a(i), children: c }) : /* @__PURE__ */ l("span", { className: "doc-ref-target external", title: "In another document", children: [
761
957
  c,
762
958
  " ↗"
763
959
  ] })
764
960
  ] });
765
961
  }
766
- function Nt(e) {
767
- const a = ["graph LR"];
768
- for (const t of e) {
769
- const r = `${Se(t.from_id)}["${Ee(t.from_title, t.from_id)}"]`, o = `${Se(t.to_id)}["${Ee(t.to_title, t.to_id)}"]`, s = (t.kind || "link").replace(/[|"]/g, " ");
770
- a.push(` ${r} -->|${s}| ${o}`);
962
+ function Mt(e) {
963
+ const r = ["graph LR"];
964
+ for (const n of e) {
965
+ const a = `${De(n.from_id)}["${Re(n.from_title, n.from_id)}"]`, o = `${De(n.to_id)}["${Re(n.to_title, n.to_id)}"]`, i = (n.kind || "link").replace(/[|"]/g, " ");
966
+ r.push(` ${a} -->|${i}| ${o}`);
771
967
  }
772
- return a.join(`
968
+ return r.join(`
773
969
  `);
774
970
  }
775
- function Se(e) {
971
+ function De(e) {
776
972
  return "n" + e.replace(/[^a-zA-Z0-9]/g, "");
777
973
  }
778
- function Ee(e, a) {
779
- const r = (e ?? "").replace(/["[\]{}|<>]/g, " ").replace(/\s+/g, " ").trim() || a.slice(0, 6);
780
- return r.length > 30 ? r.slice(0, 29) + "…" : r;
974
+ function Re(e, r) {
975
+ const a = (e ?? "").replace(/["[\]{}|<>]/g, " ").replace(/\s+/g, " ").trim() || r.slice(0, 6);
976
+ return a.length > 30 ? a.slice(0, 29) + "…" : a;
977
+ }
978
+ function $t(e) {
979
+ const r = typeof e == "number" ? e / 1e6 : Date.parse(String(e));
980
+ return !Number.isFinite(r) || r <= 0 ? String(e ?? "") : new Date(r).toLocaleString();
981
+ }
982
+ function Lt({
983
+ chunkId: e,
984
+ chunkTitle: r,
985
+ scope: n,
986
+ browse: a,
987
+ onClose: o
988
+ }) {
989
+ const i = ae(), [c, s] = f([]), [u, g] = f(!0), [h, v] = f(null), [m, A] = f("none"), [C, L] = f(null), [F, I] = f(""), [P, M] = f(!1), [j, $] = f(null), [G, R] = f(null), [y, D] = f("");
990
+ B(() => {
991
+ let N = !1;
992
+ return g(!0), v(null), i.documentHistory(e, n, a).then((b) => {
993
+ if (N) return;
994
+ const p = b.revisions ?? [];
995
+ if (s(p), p.length >= 2) {
996
+ const w = p.map((S) => S.revision);
997
+ $(Math.min(...w)), R(Math.max(...w));
998
+ }
999
+ }).catch((b) => !N && v(b instanceof Error ? b.message : String(b))).finally(() => !N && g(!1)), () => {
1000
+ N = !0;
1001
+ };
1002
+ }, [i, e, n, a]);
1003
+ const J = async (N) => {
1004
+ v(null), M(!0), L(N), A("version");
1005
+ try {
1006
+ const b = await i.documentGetVersion(e, N, n, a);
1007
+ I(b.body ?? "");
1008
+ } catch (b) {
1009
+ v(b instanceof Error ? b.message : String(b));
1010
+ } finally {
1011
+ M(!1);
1012
+ }
1013
+ }, z = async () => {
1014
+ if (!(j === null || G === null)) {
1015
+ v(null), M(!0), A("diff");
1016
+ try {
1017
+ const N = await i.documentDiff(e, j, G, n, a);
1018
+ D(N.diff ?? "");
1019
+ } catch (N) {
1020
+ v(N instanceof Error ? N.message : String(N));
1021
+ } finally {
1022
+ M(!1);
1023
+ }
1024
+ }
1025
+ };
1026
+ return /* @__PURE__ */ t("div", { className: "modal-overlay", onClick: o, children: /* @__PURE__ */ l("div", { className: "modal history-modal", onClick: (N) => N.stopPropagation(), children: [
1027
+ /* @__PURE__ */ l("div", { className: "modal-header sticky-top", children: [
1028
+ /* @__PURE__ */ l("h3", { children: [
1029
+ "History",
1030
+ r ? ` — ${r}` : ""
1031
+ ] }),
1032
+ /* @__PURE__ */ t("div", { className: "modal-buttons modal-buttons-top", children: /* @__PURE__ */ t("button", { type: "button", onClick: o, children: "close" }) })
1033
+ ] }),
1034
+ h && /* @__PURE__ */ t("div", { className: "modal-err", children: h }),
1035
+ u ? /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "loading…" }) : c.length === 0 ? /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "No history recorded for this chunk." }) : /* @__PURE__ */ l(Y, { children: [
1036
+ /* @__PURE__ */ t("div", { className: "doc-hist-revs", children: c.map((N) => /* @__PURE__ */ l(
1037
+ "button",
1038
+ {
1039
+ type: "button",
1040
+ className: "doc-hist-rev" + (m === "version" && C === N.revision ? " active" : ""),
1041
+ onClick: () => {
1042
+ J(N.revision);
1043
+ },
1044
+ children: [
1045
+ /* @__PURE__ */ l("span", { className: "doc-hist-rev-num", children: [
1046
+ "rev ",
1047
+ N.revision
1048
+ ] }),
1049
+ /* @__PURE__ */ t("span", { className: "doc-hist-rev-time", children: $t(N.created_at) }),
1050
+ /* @__PURE__ */ t("span", { className: "doc-hist-rev-actor", children: N.actor || "unknown" })
1051
+ ]
1052
+ },
1053
+ N.revision
1054
+ )) }),
1055
+ c.length >= 2 && /* @__PURE__ */ l("div", { className: "doc-hist-diffbar", children: [
1056
+ /* @__PURE__ */ t("span", { children: "Compare" }),
1057
+ /* @__PURE__ */ t(
1058
+ "select",
1059
+ {
1060
+ value: j ?? "",
1061
+ onChange: (N) => $(N.target.value === "" ? null : Number(N.target.value)),
1062
+ "aria-label": "diff from revision",
1063
+ children: c.map((N) => /* @__PURE__ */ l("option", { value: N.revision, children: [
1064
+ "rev ",
1065
+ N.revision
1066
+ ] }, N.revision))
1067
+ }
1068
+ ),
1069
+ /* @__PURE__ */ t("span", { "aria-hidden": !0, children: "→" }),
1070
+ /* @__PURE__ */ t(
1071
+ "select",
1072
+ {
1073
+ value: G ?? "",
1074
+ onChange: (N) => R(N.target.value === "" ? null : Number(N.target.value)),
1075
+ "aria-label": "diff to revision",
1076
+ children: c.map((N) => /* @__PURE__ */ l("option", { value: N.revision, children: [
1077
+ "rev ",
1078
+ N.revision
1079
+ ] }, N.revision))
1080
+ }
1081
+ ),
1082
+ /* @__PURE__ */ t(
1083
+ "button",
1084
+ {
1085
+ type: "button",
1086
+ onClick: () => {
1087
+ z();
1088
+ },
1089
+ disabled: P || j === null || G === null,
1090
+ children: "diff"
1091
+ }
1092
+ )
1093
+ ] }),
1094
+ /* @__PURE__ */ t("div", { className: "doc-hist-output", children: P ? /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "loading…" }) : m === "diff" ? /* @__PURE__ */ t(Tt, { text: y }) : m === "version" ? /* @__PURE__ */ t("pre", { className: "md-pre doc-hist-version", children: /* @__PURE__ */ t("code", { children: F || "(empty)" }) }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "Select a revision to view it, or compare two." }) })
1095
+ ] })
1096
+ ] }) });
1097
+ }
1098
+ function Tt({ text: e }) {
1099
+ if (!e.trim()) return /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "(no differences)" });
1100
+ const r = e.split(`
1101
+ `);
1102
+ return /* @__PURE__ */ t("pre", { className: "md-pre doc-hist-diff", children: r.map((n, a) => {
1103
+ const o = n.startsWith("+") && !n.startsWith("+++") ? "diff-add" : n.startsWith("-") && !n.startsWith("---") ? "diff-del" : n.startsWith("@@") ? "diff-hunk" : "";
1104
+ return /* @__PURE__ */ l("span", { className: o, children: [
1105
+ n,
1106
+ `
1107
+ `
1108
+ ] }, a);
1109
+ }) });
781
1110
  }
782
- function xe({ source: e }) {
783
- return /* @__PURE__ */ n("div", { className: "md", children: /* @__PURE__ */ n(tt, { remarkPlugins: [nt], components: wt, children: e }) });
1111
+ function Me({ source: e }) {
1112
+ return /* @__PURE__ */ t("div", { className: "md", children: /* @__PURE__ */ t(ct, { remarkPlugins: [it], components: At, children: e }) });
784
1113
  }
785
- const wt = {
1114
+ const At = {
786
1115
  // react-markdown already sanitized the href; add target/rel for external links.
787
- a({ href: e, children: a }) {
788
- const t = e ?? "", r = /^https?:\/\//i.test(t);
789
- return /* @__PURE__ */ n("a", { href: t, target: r ? "_blank" : void 0, rel: r ? "noopener noreferrer" : void 0, children: a });
1116
+ a({ href: e, children: r }) {
1117
+ const n = e ?? "", a = /^https?:\/\//i.test(n);
1118
+ return /* @__PURE__ */ t("a", { href: n, target: a ? "_blank" : void 0, rel: a ? "noopener noreferrer" : void 0, children: r });
790
1119
  },
791
1120
  // Let the code renderer own the block wrapper so a mermaid fence isn't wrapped
792
1121
  // in a <pre> (and a normal code block gets exactly one <pre>).
793
1122
  pre({ children: e }) {
794
- return /* @__PURE__ */ n(q, { children: e });
1123
+ return /* @__PURE__ */ t(Y, { children: e });
795
1124
  },
796
- code({ className: e, children: a }) {
797
- const t = /language-(\w+)/.exec(e ?? "")?.[1], r = String(a ?? "");
798
- return t === "mermaid" ? /* @__PURE__ */ n(le, { code: r.replace(/\n$/, "") }) : t || r.includes(`
799
- `) ? /* @__PURE__ */ n("pre", { className: "md-pre", children: /* @__PURE__ */ n("code", { className: e, children: a }) }) : /* @__PURE__ */ n("code", { children: a });
1125
+ code({ className: e, children: r }) {
1126
+ const n = /language-(\w+)/.exec(e ?? "")?.[1], a = String(r ?? "");
1127
+ return n === "mermaid" ? /* @__PURE__ */ t(ue, { code: a.replace(/\n$/, "") }) : n || a.includes(`
1128
+ `) ? /* @__PURE__ */ t("pre", { className: "md-pre", children: /* @__PURE__ */ t("code", { className: e, children: r }) }) : /* @__PURE__ */ t("code", { children: r });
800
1129
  }
801
1130
  };
802
- function Ct(e) {
803
- const a = e.fields ?? {};
804
- return typeof a.alt == "string" && a.alt.trim() !== "" ? a.alt : e.title || "image";
1131
+ function Pt(e) {
1132
+ const r = e.fields ?? {};
1133
+ return typeof r.alt == "string" && r.alt.trim() !== "" ? r.alt : e.title || "image";
805
1134
  }
806
- function Oe({
1135
+ function Fe({
807
1136
  documentId: e,
808
- scope: a,
809
- titleHint: t,
810
- browse: r,
1137
+ scope: r,
1138
+ titleHint: n,
1139
+ browse: a,
811
1140
  principal: o,
812
- renderAssistant: s
1141
+ renderAssistant: i
813
1142
  }) {
814
- const c = se(), i = G(
815
- () => r && (r.scopeId || r.tenant) ? { scopeId: r.scopeId, tenant: r.tenant } : void 0,
816
- [r?.scopeId, r?.tenant]
817
- ), [d, g] = k([]), [m, b] = k(void 0), [p, O] = k(null), [N, T] = k("chunks"), [j, P] = k(null), [W, R] = k(null), [z, F] = k(null), B = ne(null), [x, C] = k(null), [I, J] = k(!1), [Q, M] = k(null), [h, f] = k(!1), [E, D] = k(0), [Y, de] = k(!1), [H, ee] = k(null), [te, re] = k(!1), [w, L] = k([]), _ = A(() => D((u) => u + 1), []), V = G(() => ht(d), [d]), ae = G(() => d.find((y) => !y.parent_id)?.title || t || "document", [d, t]), K = G(
818
- () => !!p && !p.parent_id,
819
- [p]
820
- ), Z = G(
821
- () => H?.root_chunk_id ?? d.find((u) => !u.parent_id)?.id,
822
- [H, d]
823
- ), Ge = G(
824
- () => [...new Set(d.map((u) => u.status).filter((u) => !!u))],
825
- [d]
826
- ), oe = !!H?.color_enabled, Be = G(() => {
827
- const u = /* @__PURE__ */ new Set();
828
- for (const y of w)
829
- u.add(y.from_id), u.add(y.to_id);
830
- return u;
831
- }, [w]), He = G(
832
- () => oe ? be(Pe(H?.type, H?.status, ye(H?.color_scheme))) : void 0,
833
- [oe, H?.type, H?.status, H?.color_scheme]
1143
+ const c = ae(), s = q(
1144
+ () => a && (a.scopeId || a.tenant) ? { scopeId: a.scopeId, tenant: a.tenant } : void 0,
1145
+ [a?.scopeId, a?.tenant]
1146
+ ), [u, g] = f([]), [h, v] = f(void 0), [m, A] = f(null), [C, L] = f("chunks"), [F, I] = f(null), [P, M] = f(null), [j, $] = f(null), G = ne(null), [R, y] = f(null), [D, J] = f(!1), [z, N] = f(!1), [b, p] = f(null), [w, S] = f(!1), [T, ee] = f(0), [oe, ce] = f(!1), [Z, re] = f(null), [x, H] = f(!1), [W, Q] = f([]), V = O(() => ee((d) => d + 1), []), he = q(() => yt(u), [u]), ie = q(() => u.find((k) => !k.parent_id)?.title || n || "document", [u, n]), te = q(
1147
+ () => !!m && !m.parent_id,
1148
+ [m]
1149
+ ), X = q(
1150
+ () => Z?.root_chunk_id ?? u.find((d) => !d.parent_id)?.id,
1151
+ [Z, u]
1152
+ ), We = q(
1153
+ () => [...new Set(u.map((d) => d.status).filter((d) => !!d))],
1154
+ [u]
1155
+ ), se = !!Z?.color_enabled, Ve = q(() => {
1156
+ const d = /* @__PURE__ */ new Set();
1157
+ for (const k of W)
1158
+ d.add(k.from_id), d.add(k.to_id);
1159
+ return d;
1160
+ }, [W]), ze = q(
1161
+ () => se ? Ne(Ie(Z?.type, Z?.status, ve(Z?.color_scheme))) : void 0,
1162
+ [se, Z?.type, Z?.status, Z?.color_scheme]
834
1163
  );
835
- U(() => {
836
- let u = !1;
837
- return f(!0), M(null), c.documentQueryChunks(e, a, i).then((y) => {
838
- if (u) return;
839
- const v = y.chunks ?? [];
840
- g(v), b((S) => S ?? v.find(($) => !$.parent_id)?.id);
841
- }).catch((y) => !u && M(y instanceof Error ? y.message : String(y))).finally(() => !u && f(!1)), () => {
842
- u = !0;
1164
+ B(() => {
1165
+ let d = !1;
1166
+ return S(!0), p(null), c.documentQueryChunks(e, r, s).then((k) => {
1167
+ if (d) return;
1168
+ const _ = k.chunks ?? [];
1169
+ g(_), v((E) => E ?? _.find((U) => !U.parent_id)?.id);
1170
+ }).catch((k) => !d && p(k instanceof Error ? k.message : String(k))).finally(() => !d && S(!1)), () => {
1171
+ d = !0;
843
1172
  };
844
- }, [c, e, a, E, i]), U(() => {
845
- let u = !1;
846
- return c.documentGet(e, a, i).then((y) => !u && ee(y)).catch(() => !u && ee(null)), () => {
847
- u = !0;
1173
+ }, [c, e, r, T, s]), B(() => {
1174
+ let d = !1;
1175
+ return c.documentGet(e, r, s).then((k) => !d && re(k)).catch(() => !d && re(null)), () => {
1176
+ d = !0;
848
1177
  };
849
- }, [c, e, a, E, i]), U(() => {
850
- let u = !1;
851
- return c.documentGetEdges(e, a, i).then((y) => !u && L(y.edges ?? [])).catch(() => !u && L([])), () => {
852
- u = !0;
1178
+ }, [c, e, r, T, s]), B(() => {
1179
+ let d = !1;
1180
+ return c.documentGetEdges(e, r, s).then((k) => !d && Q(k.edges ?? [])).catch(() => !d && Q([])), () => {
1181
+ d = !0;
853
1182
  };
854
- }, [c, e, a, E, i]), U(() => {
855
- b(void 0), O(null), P(null), T("chunks"), ee(null), L([]);
856
- }, [e, a]), U(() => {
857
- if (!m) {
858
- O(null);
1183
+ }, [c, e, r, T, s]), B(() => {
1184
+ v(void 0), A(null), I(null), L("chunks"), re(null), Q([]);
1185
+ }, [e, r]), B(() => {
1186
+ if (!h) {
1187
+ A(null);
859
1188
  return;
860
1189
  }
861
- let u = !1;
862
- return c.documentGetChunk(m, a, i).then((y) => !u && O(y)).catch((y) => !u && M(y instanceof Error ? y.message : String(y))), () => {
863
- u = !0;
1190
+ let d = !1;
1191
+ return c.documentGetChunk(h, r, s).then((k) => !d && A(k)).catch((k) => !d && p(k instanceof Error ? k.message : String(k))), () => {
1192
+ d = !0;
864
1193
  };
865
- }, [c, m, a, E, i]), U(() => {
866
- const u = p?.type === "image" || !!p?.asset;
867
- if (!p || !u || !c.documentAssetObjectUrl) {
868
- R(null), F(null);
1194
+ }, [c, h, r, T, s]), B(() => {
1195
+ const d = m?.type === "image" || !!m?.asset;
1196
+ if (!m || !d || !c.documentAssetObjectUrl) {
1197
+ M(null), $(null);
869
1198
  return;
870
1199
  }
871
- let y = !1, v = null;
872
- return F(null), c.documentAssetObjectUrl(p.id, a, i).then((S) => {
873
- if (y) {
874
- URL.revokeObjectURL(S);
1200
+ let k = !1, _ = null;
1201
+ return $(null), c.documentAssetObjectUrl(m.id, r, s).then((E) => {
1202
+ if (k) {
1203
+ URL.revokeObjectURL(E);
875
1204
  return;
876
1205
  }
877
- v = S, R(S);
878
- }).catch((S) => !y && F(S instanceof Error ? S.message : String(S))), () => {
879
- y = !0, v && URL.revokeObjectURL(v);
1206
+ _ = E, M(E);
1207
+ }).catch((E) => !k && $(E instanceof Error ? E.message : String(E))), () => {
1208
+ k = !0, _ && URL.revokeObjectURL(_);
880
1209
  };
881
- }, [c, p, a, i]), U(() => {
882
- if (N !== "markdown" || !m) {
883
- P(null);
1210
+ }, [c, m, r, s]), B(() => {
1211
+ if (C !== "markdown" || !h) {
1212
+ I(null);
884
1213
  return;
885
1214
  }
886
- const u = Ie(V, m);
887
- if (!u) return;
888
- let y = !1;
889
- const v = [], S = ($, ce) => {
890
- v.push({ node: $, depth: ce }), $.children.forEach((ie) => S(ie, ce + 1));
1215
+ const d = je(he, h);
1216
+ if (!d) return;
1217
+ let k = !1;
1218
+ const _ = [], E = (U, le) => {
1219
+ _.push({ node: U, depth: le }), U.children.forEach((de) => E(de, le + 1));
891
1220
  };
892
- return S(u, 0), Promise.all(v.map(($) => c.documentGetChunk($.node.row.id, a, i))).then(($) => {
893
- if (y) return;
894
- const ce = v.map((ie, qe) => {
895
- const Qe = Math.min(ie.depth + 1, 6), X = $[qe], me = "#".repeat(Qe) + " " + ie.node.row.title;
896
- if (X.type === "mermaid" && X.body)
897
- return me + "\n\n```mermaid\n" + X.body + "\n```\n";
898
- if (X.type === "image" || X.asset) {
899
- const Xe = X.body ? " — " + X.body : "";
900
- return me + `
1221
+ return E(d, 0), Promise.all(_.map((U) => c.documentGetChunk(U.node.row.id, r, s))).then((U) => {
1222
+ if (k) return;
1223
+ const le = _.map((de, et) => {
1224
+ const tt = Math.min(de.depth + 1, 6), K = U[et], fe = "#".repeat(tt) + " " + de.node.row.title;
1225
+ if (K.type === "mermaid" && K.body)
1226
+ return fe + "\n\n```mermaid\n" + K.body + "\n```\n";
1227
+ if (K.type === "image" || K.asset) {
1228
+ const nt = K.body ? " — " + K.body : "";
1229
+ return fe + `
901
1230
 
902
- _🖼 image chunk_` + Xe + `
1231
+ _🖼 image chunk_` + nt + `
903
1232
  `;
904
1233
  }
905
- return me + (X.body ? `
1234
+ return fe + (K.body ? `
906
1235
 
907
- ` + X.body : "") + `
1236
+ ` + K.body : "") + `
908
1237
  `;
909
1238
  }).join(`
910
1239
  `);
911
- P(ce);
912
- }).catch(($) => !y && M($ instanceof Error ? $.message : String($))), () => {
913
- y = !0;
1240
+ I(le);
1241
+ }).catch((U) => !k && p(U instanceof Error ? U.message : String(U))), () => {
1242
+ k = !0;
914
1243
  };
915
- }, [c, N, m, V, a, E, i]);
916
- const We = A((u) => b(u.row.id), []), ze = A(async () => {
1244
+ }, [c, C, h, he, r, T, s]);
1245
+ const Je = O((d) => v(d.row.id), []), Ze = O(async () => {
917
1246
  try {
918
- const u = await c.documentExportMd(e, a, !0, i), y = new Blob([u.markdown], { type: "text/markdown" }), v = URL.createObjectURL(y), S = document.createElement("a");
919
- S.href = v, S.download = (u.title || "document").replace(/[^\w.-]+/g, "_") + ".md", S.click(), URL.revokeObjectURL(v);
920
- } catch (u) {
921
- M(u instanceof Error ? u.message : String(u));
1247
+ const d = await c.documentExportMd(e, r, !0, s), k = new Blob([d.markdown], { type: "text/markdown" }), _ = URL.createObjectURL(k), E = document.createElement("a");
1248
+ E.href = _, E.download = (d.title || "document").replace(/[^\w.-]+/g, "_") + ".md", E.click(), URL.revokeObjectURL(_);
1249
+ } catch (d) {
1250
+ p(d instanceof Error ? d.message : String(d));
922
1251
  }
923
- }, [c, e, a, i]), ue = !!c.documentCreateChunk && !!Z, he = A(
924
- async (u) => {
1252
+ }, [c, e, r, s]), qe = O(async () => {
1253
+ try {
1254
+ const d = await c.documentExportCanvas(e, r, s), k = new Blob([JSON.stringify(d.canvas, null, 2)], {
1255
+ type: "application/json"
1256
+ }), _ = URL.createObjectURL(k), E = document.createElement("a");
1257
+ E.href = _, E.download = (ie || "document").replace(/[^\w.-]+/g, "_") + ".canvas", E.click(), URL.revokeObjectURL(_);
1258
+ } catch (d) {
1259
+ p(d instanceof Error ? d.message : String(d));
1260
+ }
1261
+ }, [c, e, r, s, ie]), me = !!c.documentCreateChunk && !!X, pe = O(
1262
+ async (d) => {
925
1263
  if (!c.documentCreateChunk || !c.documentSetAsset) return;
926
- const y = m || Z;
927
- if (y) {
928
- M(null);
1264
+ const k = h || X;
1265
+ if (k) {
1266
+ p(null);
929
1267
  try {
930
- const { mediaType: v, data: S } = await Te(u), $ = await c.documentCreateChunk(
1268
+ const { mediaType: _, data: E } = await Oe(d), U = await c.documentCreateChunk(
931
1269
  e,
932
- y,
933
- { title: u.name || "image", type: "image" },
934
- a,
935
- i
1270
+ k,
1271
+ { title: d.name || "image", type: "image" },
1272
+ r,
1273
+ s
936
1274
  );
937
- await c.documentSetAsset($.id, v, S, u.name, a, i), _(), b($.id);
938
- } catch (v) {
939
- M(v instanceof Error ? v.message : String(v));
1275
+ await c.documentSetAsset(U.id, _, E, d.name, r, s), V(), v(U.id);
1276
+ } catch (_) {
1277
+ p(_ instanceof Error ? _.message : String(_));
940
1278
  }
941
1279
  }
942
1280
  },
943
- [c, e, a, i, m, Z, _]
944
- ), Je = A(async () => {
1281
+ [c, e, r, s, h, X, V]
1282
+ ), Qe = O(async () => {
945
1283
  if (!c.documentCreateChunk) return;
946
- const u = m || Z;
947
- if (u) {
948
- M(null);
1284
+ const d = h || X;
1285
+ if (d) {
1286
+ p(null);
949
1287
  try {
950
- const y = await c.documentCreateChunk(
1288
+ const k = await c.documentCreateChunk(
951
1289
  e,
952
- u,
1290
+ d,
953
1291
  { title: "Diagram", type: "mermaid", body: `graph TD
954
1292
  A[Start] --> B[End]` },
955
- a,
956
- i
1293
+ r,
1294
+ s
957
1295
  );
958
- _(), b(y.id), C(y);
959
- } catch (y) {
960
- M(y instanceof Error ? y.message : String(y));
1296
+ V(), v(k.id), y(k);
1297
+ } catch (k) {
1298
+ p(k instanceof Error ? k.message : String(k));
961
1299
  }
962
1300
  }
963
- }, [c, e, a, i, m, Z, _]), Ve = A(async () => {
1301
+ }, [c, e, r, s, h, X, V]), Xe = O(async () => {
964
1302
  if (!c.documentCreateChunk) return;
965
- const u = m && !K ? m : void 0, y = m || Z;
966
- if (y) {
967
- M(null);
1303
+ const d = h && !te ? h : void 0, k = h || X;
1304
+ if (k) {
1305
+ p(null);
968
1306
  try {
969
- const v = await c.documentCreateChunk(
1307
+ const _ = await c.documentCreateChunk(
970
1308
  e,
971
- u ? "" : y,
1309
+ d ? "" : k,
972
1310
  // after_id resolves the parent server-side
973
1311
  { title: "Text", body: "" },
974
- a,
975
- i,
976
- u
1312
+ r,
1313
+ s,
1314
+ d
977
1315
  );
978
- _(), b(v.id), C(v);
979
- } catch (v) {
980
- M(v instanceof Error ? v.message : String(v));
1316
+ V(), v(_.id), y(_);
1317
+ } catch (_) {
1318
+ p(_ instanceof Error ? _.message : String(_));
981
1319
  }
982
1320
  }
983
- }, [c, e, a, i, m, K, Z, _]), ke = G(() => {
984
- if (!p || K) return { canUp: !1, canDown: !1 };
985
- const u = p.parent_id ?? "", y = d.filter((S) => (S.parent_id ?? "") === u).sort((S, $) => S.position - $.position || S.id.localeCompare($.id)), v = y.findIndex((S) => S.id === p.id);
986
- return { canUp: v > 0, canDown: v >= 0 && v < y.length - 1 };
987
- }, [d, p, K]), ve = A(
988
- async (u) => {
989
- if (!(!c.documentReorderChunk || !m)) {
990
- M(null);
1321
+ }, [c, e, r, s, h, te, X, V]), Ye = O(async () => {
1322
+ if (!(!c.documentCreateChunk || !h)) {
1323
+ p(null);
1324
+ try {
1325
+ const d = await c.documentCreateChunk(
1326
+ e,
1327
+ h,
1328
+ { title: "Text", body: "" },
1329
+ r,
1330
+ s
1331
+ );
1332
+ V(), v(d.id), y(d);
1333
+ } catch (d) {
1334
+ p(d instanceof Error ? d.message : String(d));
1335
+ }
1336
+ }
1337
+ }, [c, e, r, s, h, V]), we = q(() => {
1338
+ if (!m || te) return { canUp: !1, canDown: !1 };
1339
+ const d = m.parent_id ?? "", k = u.filter((E) => (E.parent_id ?? "") === d).sort((E, U) => E.position - U.position || E.id.localeCompare(U.id)), _ = k.findIndex((E) => E.id === m.id);
1340
+ return { canUp: _ > 0, canDown: _ >= 0 && _ < k.length - 1 };
1341
+ }, [u, m, te]), Ce = O(
1342
+ async (d) => {
1343
+ if (!(!c.documentReorderChunk || !h)) {
1344
+ p(null);
991
1345
  try {
992
- await c.documentReorderChunk(m, u, a, i), _();
993
- } catch (y) {
994
- M(y instanceof Error ? y.message : String(y));
1346
+ await c.documentReorderChunk(h, d, r, s), V();
1347
+ } catch (k) {
1348
+ p(k instanceof Error ? k.message : String(k));
995
1349
  }
996
1350
  }
997
1351
  },
998
- [c, m, a, i, _]
999
- ), Ze = A(async () => {
1000
- if (!c.documentDeleteChunk || !p) return;
1001
- M(null);
1002
- const u = p.parent_id;
1352
+ [c, h, r, s, V]
1353
+ ), Ke = O(async () => {
1354
+ if (!c.documentDeleteChunk || !m) return;
1355
+ p(null);
1356
+ const d = m.parent_id;
1003
1357
  try {
1004
- await c.documentDeleteChunk(p.id, a, i), J(!1), b(u || Z), _();
1005
- } catch (y) {
1006
- M(y instanceof Error ? y.message : String(y)), J(!1);
1358
+ await c.documentDeleteChunk(m.id, r, s), N(!1), v(d || X), V();
1359
+ } catch (k) {
1360
+ p(k instanceof Error ? k.message : String(k)), N(!1);
1007
1361
  }
1008
- }, [c, p, a, i, Z, _]);
1009
- return U(() => {
1010
- if (!ue) return;
1011
- const u = (y) => {
1012
- if (x || te) return;
1013
- const v = document.activeElement, S = v?.tagName;
1014
- if (S === "INPUT" || S === "TEXTAREA" || v?.isContentEditable) return;
1015
- const $ = st(y.clipboardData?.items);
1016
- $ && (y.preventDefault(), he($));
1362
+ }, [c, m, r, s, X, V]);
1363
+ return B(() => {
1364
+ if (!me) return;
1365
+ const d = (k) => {
1366
+ if (R || x) return;
1367
+ const _ = document.activeElement, E = _?.tagName;
1368
+ if (E === "INPUT" || E === "TEXTAREA" || _?.isContentEditable) return;
1369
+ const U = mt(k.clipboardData?.items);
1370
+ U && (k.preventDefault(), pe(U));
1017
1371
  };
1018
- return window.addEventListener("paste", u), () => window.removeEventListener("paste", u);
1019
- }, [ue, x, te, he]), /* @__PURE__ */ l("div", { className: "doc-viewer", children: [
1020
- /* @__PURE__ */ n(
1372
+ return window.addEventListener("paste", d), () => window.removeEventListener("paste", d);
1373
+ }, [me, R, x, pe]), /* @__PURE__ */ l("div", { className: "doc-viewer", children: [
1374
+ /* @__PURE__ */ t(
1021
1375
  "input",
1022
1376
  {
1023
- ref: B,
1377
+ ref: G,
1024
1378
  type: "file",
1025
1379
  accept: "image/png,image/jpeg,image/gif,image/webp",
1026
1380
  style: { display: "none" },
1027
- onChange: (u) => {
1028
- const y = u.target.files?.[0];
1029
- u.target.value = "", y && he(y);
1381
+ onChange: (d) => {
1382
+ const k = d.target.files?.[0];
1383
+ d.target.value = "", k && pe(k);
1030
1384
  }
1031
1385
  }
1032
1386
  ),
1033
- /* @__PURE__ */ l("div", { className: "doc-toolbar", style: He, children: [
1034
- /* @__PURE__ */ n("strong", { className: "doc-title", title: ae, children: ae }),
1387
+ /* @__PURE__ */ l("div", { className: "doc-toolbar", style: ze, children: [
1388
+ /* @__PURE__ */ t("strong", { className: "doc-title", title: ie, children: ie }),
1035
1389
  /* @__PURE__ */ l("div", { className: "doc-toolbar-actions", children: [
1036
- ue && /* @__PURE__ */ l(q, { children: [
1037
- /* @__PURE__ */ n(
1390
+ me && /* @__PURE__ */ l(Y, { children: [
1391
+ /* @__PURE__ */ t(
1038
1392
  "button",
1039
1393
  {
1040
1394
  type: "button",
1041
1395
  onClick: () => {
1042
- Ve();
1396
+ Xe();
1043
1397
  },
1044
- title: "Add a text chunk after the selected chunk",
1398
+ title: "Add a text chunk AFTER the selected chunk, at the same level",
1045
1399
  children: "+ text"
1046
1400
  }
1047
1401
  ),
1048
- /* @__PURE__ */ n(
1402
+ /* @__PURE__ */ t(
1403
+ "button",
1404
+ {
1405
+ type: "button",
1406
+ onClick: () => {
1407
+ Ye();
1408
+ },
1409
+ disabled: !h,
1410
+ title: h ? "Add a chunk NESTED UNDER the selected chunk (in the ontology, a child is a subclass)" : "Select a chunk first — this nests a new chunk under it",
1411
+ children: "+ child"
1412
+ }
1413
+ ),
1414
+ /* @__PURE__ */ t(
1049
1415
  "button",
1050
1416
  {
1051
1417
  type: "button",
1052
- onClick: () => B.current?.click(),
1418
+ onClick: () => G.current?.click(),
1053
1419
  title: "Add an image chunk (upload — or paste a screenshot into the view)",
1054
1420
  children: "+ image"
1055
1421
  }
1056
1422
  ),
1057
- /* @__PURE__ */ n(
1423
+ /* @__PURE__ */ t(
1058
1424
  "button",
1059
1425
  {
1060
1426
  type: "button",
1061
1427
  onClick: () => {
1062
- Je();
1428
+ Qe();
1063
1429
  },
1064
1430
  title: "Add a Mermaid diagram chunk",
1065
1431
  children: "+ diagram"
1066
1432
  }
1067
1433
  )
1068
1434
  ] }),
1069
- /* @__PURE__ */ n(
1435
+ /* @__PURE__ */ t(
1070
1436
  "button",
1071
1437
  {
1072
1438
  type: "button",
1073
- className: oe ? "active" : "",
1074
- onClick: () => re(!0),
1075
- disabled: !Z,
1439
+ className: se ? "active" : "",
1440
+ onClick: () => H(!0),
1441
+ disabled: !X,
1076
1442
  title: "Colors — tint chunk tiles + the Path tree by type/status",
1077
1443
  children: "colors"
1078
1444
  }
1079
1445
  ),
1080
- /* @__PURE__ */ n("button", { type: "button", onClick: () => {
1081
- ze();
1446
+ /* @__PURE__ */ t("button", { type: "button", onClick: () => {
1447
+ Ze();
1082
1448
  }, title: "Download the whole document as Markdown (.md)", children: "↓ .md" }),
1083
- s && /* @__PURE__ */ n(
1449
+ /* @__PURE__ */ t(
1084
1450
  "button",
1085
1451
  {
1086
1452
  type: "button",
1087
- className: Y ? "active" : "",
1088
- onClick: () => de((u) => !u),
1453
+ onClick: () => {
1454
+ qe();
1455
+ },
1456
+ title: "Download the whole document as a node/edge canvas graph (.canvas)",
1457
+ children: "↓ .canvas"
1458
+ }
1459
+ ),
1460
+ i && /* @__PURE__ */ t(
1461
+ "button",
1462
+ {
1463
+ type: "button",
1464
+ className: oe ? "active" : "",
1465
+ onClick: () => ce((d) => !d),
1089
1466
  title: "Document Assistant — instruct an agent to restructure/import/link chunks",
1090
1467
  children: "assistant"
1091
1468
  }
1092
1469
  ),
1093
- /* @__PURE__ */ n("button", { type: "button", onClick: _, title: "Reload", children: "↻" })
1470
+ /* @__PURE__ */ t("button", { type: "button", onClick: V, title: "Reload", children: "↻" })
1094
1471
  ] })
1095
1472
  ] }),
1096
- Q && /* @__PURE__ */ n("div", { className: "paths-err", children: Q }),
1473
+ b && /* @__PURE__ */ t("div", { className: "paths-err", children: b }),
1097
1474
  /* @__PURE__ */ l("div", { className: "doc-split", children: [
1098
- /* @__PURE__ */ n("div", { className: "doc-chunktree", children: h && d.length === 0 ? /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "Loading…" }) }) : /* @__PURE__ */ n(
1099
- mt,
1475
+ /* @__PURE__ */ t("div", { className: "doc-chunktree", children: w && u.length === 0 ? /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Loading…" }) }) : /* @__PURE__ */ t(
1476
+ bt,
1100
1477
  {
1101
- tree: V,
1102
- selectedId: m,
1103
- onSelect: We,
1104
- colorEnabled: oe,
1105
- scheme: H?.color_scheme,
1106
- linkedIds: Be
1478
+ tree: he,
1479
+ selectedId: h,
1480
+ onSelect: Je,
1481
+ colorEnabled: se,
1482
+ scheme: Z?.color_scheme,
1483
+ linkedIds: Ve
1107
1484
  }
1108
1485
  ) }),
1109
- /* @__PURE__ */ n("div", { className: "doc-content", children: p ? /* @__PURE__ */ l(q, { children: [
1486
+ /* @__PURE__ */ t("div", { className: "doc-content", children: m ? /* @__PURE__ */ l(Y, { children: [
1110
1487
  /* @__PURE__ */ l("div", { className: "doc-content-head", children: [
1111
- /* @__PURE__ */ n("h3", { children: p.title || "(untitled)" }),
1488
+ /* @__PURE__ */ t("h3", { children: m.title || "(untitled)" }),
1112
1489
  /* @__PURE__ */ l("div", { className: "doc-content-meta", children: [
1113
- p.type && /* @__PURE__ */ n("span", { className: "chunk-badge", children: p.type }),
1114
- p.status && /* @__PURE__ */ n("span", { className: "chunk-badge chunk-status", children: p.status }),
1490
+ m.type && /* @__PURE__ */ t("span", { className: "chunk-badge", children: m.type }),
1491
+ m.status && /* @__PURE__ */ t("span", { className: "chunk-badge chunk-status", children: m.status }),
1115
1492
  /* @__PURE__ */ l("span", { className: "chunk-rev", children: [
1116
1493
  "rev ",
1117
- p.revision
1118
- ] })
1494
+ m.revision
1495
+ ] }),
1496
+ m.tags?.map((d) => /* @__PURE__ */ t("span", { className: "chunk-tag", children: d }, d))
1119
1497
  ] }),
1120
1498
  /* @__PURE__ */ l("div", { className: "doc-content-controls", children: [
1121
1499
  /* @__PURE__ */ l("div", { className: "doc-mode-toggle", children: [
1122
- /* @__PURE__ */ n(
1500
+ /* @__PURE__ */ t(
1123
1501
  "button",
1124
1502
  {
1125
1503
  type: "button",
1126
- className: N === "chunks" ? "active" : "",
1127
- onClick: () => T("chunks"),
1504
+ className: C === "chunks" ? "active" : "",
1505
+ onClick: () => L("chunks"),
1128
1506
  title: "This chunk's own content",
1129
1507
  children: "chunk"
1130
1508
  }
1131
1509
  ),
1132
- /* @__PURE__ */ n(
1510
+ /* @__PURE__ */ t(
1133
1511
  "button",
1134
1512
  {
1135
1513
  type: "button",
1136
- className: N === "markdown" ? "active" : "",
1137
- onClick: () => T("markdown"),
1138
- title: K ? "Whole document as Markdown" : "This chunk + its sub-chunks as Markdown",
1514
+ className: C === "markdown" ? "active" : "",
1515
+ onClick: () => L("markdown"),
1516
+ title: te ? "Whole document as Markdown" : "This chunk + its sub-chunks as Markdown",
1139
1517
  children: "markdown"
1140
1518
  }
1141
1519
  )
1142
1520
  ] }),
1143
- /* @__PURE__ */ n("button", { type: "button", onClick: () => C(p), children: "edit" }),
1144
- !K && /* @__PURE__ */ l(q, { children: [
1145
- /* @__PURE__ */ n(
1521
+ /* @__PURE__ */ t("button", { type: "button", onClick: () => y(m), children: "edit" }),
1522
+ /* @__PURE__ */ t(
1523
+ "button",
1524
+ {
1525
+ type: "button",
1526
+ onClick: () => J(!0),
1527
+ title: "View this chunk's edit history + diffs",
1528
+ children: "history"
1529
+ }
1530
+ ),
1531
+ !te && /* @__PURE__ */ l(Y, { children: [
1532
+ /* @__PURE__ */ t(
1146
1533
  "button",
1147
1534
  {
1148
1535
  type: "button",
1149
1536
  onClick: () => {
1150
- ve("up");
1537
+ Ce("up");
1151
1538
  },
1152
- disabled: !ke.canUp,
1539
+ disabled: !we.canUp,
1153
1540
  title: "Move this chunk up within its level",
1154
1541
  children: "↑"
1155
1542
  }
1156
1543
  ),
1157
- /* @__PURE__ */ n(
1544
+ /* @__PURE__ */ t(
1158
1545
  "button",
1159
1546
  {
1160
1547
  type: "button",
1161
1548
  onClick: () => {
1162
- ve("down");
1549
+ Ce("down");
1163
1550
  },
1164
- disabled: !ke.canDown,
1551
+ disabled: !we.canDown,
1165
1552
  title: "Move this chunk down within its level",
1166
1553
  children: "↓"
1167
1554
  }
1168
1555
  )
1169
1556
  ] }),
1170
- !K && /* @__PURE__ */ n(
1557
+ !te && /* @__PURE__ */ t(
1171
1558
  "button",
1172
1559
  {
1173
1560
  type: "button",
1174
1561
  className: "danger",
1175
- onClick: () => J(!0),
1562
+ onClick: () => N(!0),
1176
1563
  title: "Delete this chunk and its sub-chunks",
1177
1564
  children: "delete"
1178
1565
  }
1179
1566
  )
1180
1567
  ] })
1181
1568
  ] }),
1182
- /* @__PURE__ */ n("div", { className: "doc-content-body", children: p.type === "mermaid" ? (
1569
+ /* @__PURE__ */ t("div", { className: "doc-content-body", children: m.type === "mermaid" ? (
1183
1570
  // RFC BO — a diagram chunk: body IS the Mermaid source.
1184
- p.body ? /* @__PURE__ */ l(q, { children: [
1185
- /* @__PURE__ */ n(le, { code: p.body }),
1186
- N === "markdown" && /* @__PURE__ */ n("pre", { className: "md-pre doc-mermaid-source", children: /* @__PURE__ */ n("code", { children: p.body }) })
1187
- ] }) : /* @__PURE__ */ n("p", { className: "doc-empty-body", children: "(empty diagram)" })
1188
- ) : p.type === "image" || p.asset ? (
1571
+ m.body ? /* @__PURE__ */ l(Y, { children: [
1572
+ /* @__PURE__ */ t(ue, { code: m.body }),
1573
+ C === "markdown" && /* @__PURE__ */ t("pre", { className: "md-pre doc-mermaid-source", children: /* @__PURE__ */ t("code", { children: m.body }) })
1574
+ ] }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "(empty diagram)" })
1575
+ ) : m.type === "image" || m.asset ? (
1189
1576
  // RFC BO — an image chunk: bytes come from the auth'd asset GET.
1190
- z ? /* @__PURE__ */ l("p", { className: "doc-empty-body", children: [
1577
+ j ? /* @__PURE__ */ l("p", { className: "doc-empty-body", children: [
1191
1578
  "Image failed to load: ",
1192
- z
1193
- ] }) : W ? /* @__PURE__ */ l("figure", { className: "doc-image", children: [
1194
- /* @__PURE__ */ n("img", { src: W, alt: Ct(p) }),
1195
- p.body && /* @__PURE__ */ n("figcaption", { children: p.body })
1196
- ] }) : /* @__PURE__ */ n("p", { className: "doc-empty-body", children: "Loading image…" })
1197
- ) : N === "markdown" ? j !== null ? /* @__PURE__ */ n(xe, { source: j }) : /* @__PURE__ */ n("p", { className: "doc-empty-body", children: "Assembling Markdown…" }) : p.body ? /* @__PURE__ */ n(xe, { source: p.body }) : /* @__PURE__ */ n("p", { className: "doc-empty-body", children: "(empty chunk)" }) }),
1198
- /* @__PURE__ */ n(
1199
- kt,
1579
+ j
1580
+ ] }) : P ? /* @__PURE__ */ l("figure", { className: "doc-image", children: [
1581
+ /* @__PURE__ */ t("img", { src: P, alt: Pt(m) }),
1582
+ m.body && /* @__PURE__ */ t("figcaption", { children: m.body })
1583
+ ] }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "Loading image…" })
1584
+ ) : C === "markdown" ? F !== null ? /* @__PURE__ */ t(Me, { source: F }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "Assembling Markdown…" }) : m.body ? /* @__PURE__ */ t(Me, { source: m.body }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "(empty chunk)" }) }),
1585
+ /* @__PURE__ */ t(
1586
+ Dt,
1200
1587
  {
1201
- edges: w,
1588
+ edges: W,
1202
1589
  documentId: e,
1203
- selectedId: m,
1204
- onSelectChunk: b
1590
+ selectedId: h,
1591
+ onSelectChunk: v
1592
+ }
1593
+ ),
1594
+ /* @__PURE__ */ t(
1595
+ xt,
1596
+ {
1597
+ documentId: e,
1598
+ selectedId: h,
1599
+ scope: r,
1600
+ browse: s,
1601
+ onSelectChunk: v
1205
1602
  }
1206
1603
  )
1207
- ] }) : /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "Select a chunk on the left." }) }) })
1604
+ ] }) : /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Select a chunk on the left." }) }) })
1208
1605
  ] }),
1209
- Y && s && /* @__PURE__ */ n("div", { className: "doc-assistant", children: s({
1606
+ oe && i && /* @__PURE__ */ t("div", { className: "doc-assistant", children: i({
1210
1607
  documentId: e,
1211
- scope: a,
1608
+ scope: r,
1212
1609
  subject: o?.subject,
1213
1610
  // Pass the viewer's own reload so the injected assistant can refresh
1214
1611
  // the tree + selected chunk after a turn mutates the document.
1215
- onChanged: _
1612
+ onChanged: V
1216
1613
  }) }),
1217
- x && /* @__PURE__ */ n(
1218
- gt,
1614
+ R && /* @__PURE__ */ t(
1615
+ Nt,
1219
1616
  {
1220
- chunk: x,
1221
- scope: a,
1222
- browse: i,
1223
- onClose: () => C(null),
1224
- onSaved: _
1617
+ chunk: R,
1618
+ scope: r,
1619
+ browse: s,
1620
+ onClose: () => y(null),
1621
+ onSaved: V
1225
1622
  }
1226
1623
  ),
1227
- te && Z && /* @__PURE__ */ n(
1228
- bt,
1624
+ D && m && /* @__PURE__ */ t(
1625
+ Lt,
1626
+ {
1627
+ chunkId: m.id,
1628
+ chunkTitle: m.title,
1629
+ scope: r,
1630
+ browse: s,
1631
+ onClose: () => J(!1)
1632
+ }
1633
+ ),
1634
+ x && X && /* @__PURE__ */ t(
1635
+ Ct,
1229
1636
  {
1230
1637
  documentId: e,
1231
- rootChunkId: Z,
1232
- docType: H?.type,
1233
- docStatus: H?.status,
1234
- chunkStatuses: Ge,
1235
- scope: a,
1236
- browse: i,
1237
- onClose: () => re(!1),
1238
- onSaved: _
1638
+ rootChunkId: X,
1639
+ docType: Z?.type,
1640
+ docStatus: Z?.status,
1641
+ chunkStatuses: We,
1642
+ scope: r,
1643
+ browse: s,
1644
+ onClose: () => H(!1),
1645
+ onSaved: V
1239
1646
  }
1240
1647
  ),
1241
- I && p && /* @__PURE__ */ n("div", { className: "modal-overlay", onClick: () => J(!1), children: /* @__PURE__ */ l("div", { className: "modal chunk-delete-confirm", onClick: (u) => u.stopPropagation(), children: [
1242
- /* @__PURE__ */ n("h3", { children: "Delete chunk" }),
1648
+ z && m && /* @__PURE__ */ t("div", { className: "modal-overlay", onClick: () => N(!1), children: /* @__PURE__ */ l("div", { className: "modal chunk-delete-confirm", onClick: (d) => d.stopPropagation(), children: [
1649
+ /* @__PURE__ */ t("h3", { children: "Delete chunk" }),
1243
1650
  /* @__PURE__ */ l("p", { className: "modal-context", children: [
1244
1651
  "Delete “",
1245
- p.title || "(untitled)",
1652
+ m.title || "(untitled)",
1246
1653
  "” and all of its sub-chunks? This cannot be undone."
1247
1654
  ] }),
1248
1655
  /* @__PURE__ */ l("div", { className: "modal-buttons", children: [
1249
- /* @__PURE__ */ n("button", { type: "button", onClick: () => J(!1), children: "cancel" }),
1250
- /* @__PURE__ */ n("button", { type: "button", className: "danger", onClick: () => {
1251
- Ze();
1656
+ /* @__PURE__ */ t("button", { type: "button", onClick: () => N(!1), children: "cancel" }),
1657
+ /* @__PURE__ */ t("button", { type: "button", className: "danger", onClick: () => {
1658
+ Ke();
1252
1659
  }, children: "delete" })
1253
1660
  ] })
1254
1661
  ] }) })
1255
1662
  ] });
1256
1663
  }
1257
- function _t(e) {
1258
- const a = {
1664
+ function Ut(e) {
1665
+ const r = {
1259
1666
  name: "",
1260
1667
  fullPath: "",
1261
1668
  kind: "directory",
1262
1669
  explicit: !0,
1263
1670
  children: []
1264
- }, t = /* @__PURE__ */ new Map([["", a]]), r = (s) => {
1265
- const c = t.get(s);
1671
+ }, n = /* @__PURE__ */ new Map([["", r]]), a = (i) => {
1672
+ const c = n.get(i);
1266
1673
  if (c) return c;
1267
- const i = s.lastIndexOf("/"), d = i <= 0 ? "" : s.slice(0, i), g = s.slice(i + 1), m = r(d), b = {
1674
+ const s = i.lastIndexOf("/"), u = s <= 0 ? "" : i.slice(0, s), g = i.slice(s + 1), h = a(u), v = {
1268
1675
  name: g,
1269
- fullPath: s,
1676
+ fullPath: i,
1270
1677
  kind: "directory",
1271
1678
  explicit: !1,
1272
1679
  children: []
1273
1680
  };
1274
- return m.children.push(b), t.set(s, b), b;
1681
+ return h.children.push(v), n.set(i, v), v;
1275
1682
  };
1276
- for (const s of e) {
1277
- const c = r(s.full_path);
1278
- c.kind = s.kind, c.explicit = !0, c.resourceRef = s.resource_ref;
1683
+ for (const i of e) {
1684
+ const c = a(i.full_path);
1685
+ c.kind = i.kind, c.explicit = !0, c.resourceRef = i.resource_ref;
1279
1686
  }
1280
- const o = (s) => {
1281
- s.sort((c, i) => {
1282
- const d = c.kind === "directory", g = i.kind === "directory";
1283
- return d !== g ? d ? -1 : 1 : c.name.localeCompare(i.name);
1284
- }), s.forEach((c) => o(c.children));
1687
+ const o = (i) => {
1688
+ i.sort((c, s) => {
1689
+ const u = c.kind === "directory", g = s.kind === "directory";
1690
+ return u !== g ? u ? -1 : 1 : c.name.localeCompare(s.name);
1691
+ }), i.forEach((c) => o(c.children));
1285
1692
  };
1286
- return o(a.children), a.children;
1693
+ return o(r.children), r.children;
1287
1694
  }
1288
- function ge(e) {
1289
- const a = e.lastIndexOf("/");
1290
- return a <= 0 ? "" : e.slice(0, a);
1695
+ function ke(e) {
1696
+ const r = e.lastIndexOf("/");
1697
+ return r <= 0 ? "" : e.slice(0, r);
1291
1698
  }
1292
- function St(e) {
1293
- const a = [], t = (r) => {
1294
- if (r.kind === "document") {
1295
- const o = r.resourceRef;
1296
- o?.document_id && a.push(o.document_id);
1699
+ function Ot(e) {
1700
+ const r = [], n = (a) => {
1701
+ if (a.kind === "document") {
1702
+ const o = a.resourceRef;
1703
+ o?.document_id && r.push(o.document_id);
1297
1704
  }
1298
- r.children.forEach(t);
1705
+ a.children.forEach(n);
1299
1706
  };
1300
- return t(e), a;
1707
+ return n(e), r;
1301
1708
  }
1302
- const Et = {
1709
+ const It = {
1303
1710
  directory: "📁",
1304
1711
  document: "📄",
1305
1712
  volume_mount: "💾",
1306
1713
  memory_entry: "🧠"
1307
1714
  };
1308
- function xt({ tree: e, selectedPath: a, onSelect: t, summaries: r }) {
1309
- const [o, s] = k(() => /* @__PURE__ */ new Map()), c = A((i) => {
1310
- s((d) => {
1311
- const g = new Map(d);
1312
- return g.set(i, d.get(i) === !1), g;
1715
+ function jt({ tree: e, selectedPath: r, onSelect: n, summaries: a }) {
1716
+ const [o, i] = f(() => /* @__PURE__ */ new Map()), c = O((s) => {
1717
+ i((u) => {
1718
+ const g = new Map(u);
1719
+ return g.set(s, u.get(s) === !1), g;
1313
1720
  });
1314
1721
  }, []);
1315
- return U(() => {
1316
- a && s((i) => {
1317
- let d = !1;
1318
- const g = new Map(i);
1319
- let m = ge(a);
1320
- for (; m !== ""; )
1321
- g.get(m) === !1 && (g.set(m, !0), d = !0), m = ge(m);
1322
- return d ? g : i;
1722
+ return B(() => {
1723
+ r && i((s) => {
1724
+ let u = !1;
1725
+ const g = new Map(s);
1726
+ let h = ke(r);
1727
+ for (; h !== ""; )
1728
+ g.get(h) === !1 && (g.set(h, !0), u = !0), h = ke(h);
1729
+ return u ? g : s;
1323
1730
  });
1324
- }, [a]), 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(
1325
- je,
1731
+ }, [r]), e.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: e.map((s) => /* @__PURE__ */ t(
1732
+ Ge,
1326
1733
  {
1327
- node: i,
1734
+ node: s,
1328
1735
  expanded: o,
1329
1736
  toggle: c,
1330
- selectedPath: a,
1331
- onSelect: t,
1332
- summaries: r
1737
+ selectedPath: r,
1738
+ onSelect: n,
1739
+ summaries: a
1333
1740
  },
1334
- i.fullPath
1741
+ s.fullPath
1335
1742
  )) });
1336
1743
  }
1337
- function Dt(e, a) {
1338
- if (e.kind !== "document" || !a) return;
1339
- const t = e.resourceRef;
1340
- return t?.document_id ? a.get(t.document_id) : void 0;
1744
+ function Bt(e, r) {
1745
+ if (e.kind !== "document" || !r) return;
1746
+ const n = e.resourceRef;
1747
+ return n?.document_id ? r.get(n.document_id) : void 0;
1341
1748
  }
1342
- function je({ node: e, expanded: a, toggle: t, selectedPath: r, onSelect: o, summaries: s }) {
1343
- const c = e.children.length > 0, i = a.get(e.fullPath) !== !1, d = r === e.fullPath, g = Dt(e, s), m = g && g.color_enabled ? be(Pe(g.type, g.status, ye(g.color_scheme))) : void 0;
1344
- return /* @__PURE__ */ l("li", { className: `node path-node kind-${e.kind} ${d ? "selected" : ""}`, children: [
1345
- /* @__PURE__ */ l("div", { className: "row path-row", style: m, children: [
1346
- /* @__PURE__ */ n(
1749
+ function Ge({ node: e, expanded: r, toggle: n, selectedPath: a, onSelect: o, summaries: i }) {
1750
+ const c = e.children.length > 0, s = r.get(e.fullPath) !== !1, u = a === e.fullPath, g = Bt(e, i), h = g && g.color_enabled ? Ne(Ie(g.type, g.status, ve(g.color_scheme))) : void 0;
1751
+ return /* @__PURE__ */ l("li", { className: `node path-node kind-${e.kind} ${u ? "selected" : ""}`, children: [
1752
+ /* @__PURE__ */ l("div", { className: "row path-row", style: h, children: [
1753
+ /* @__PURE__ */ t(
1347
1754
  "button",
1348
1755
  {
1349
1756
  type: "button",
1350
1757
  className: "tree-caret",
1351
- "aria-label": i ? "collapse" : "expand",
1758
+ "aria-label": s ? "collapse" : "expand",
1352
1759
  disabled: !c,
1353
- onClick: (b) => {
1354
- b.stopPropagation(), c && t(e.fullPath);
1760
+ onClick: (v) => {
1761
+ v.stopPropagation(), c && n(e.fullPath);
1355
1762
  },
1356
- children: c ? i ? "▼" : "▶" : "·"
1763
+ children: c ? s ? "▼" : "▶" : "·"
1357
1764
  }
1358
1765
  ),
1359
1766
  /* @__PURE__ */ l(
@@ -1364,189 +1771,189 @@ function je({ node: e, expanded: a, toggle: t, selectedPath: r, onSelect: o, sum
1364
1771
  onClick: () => o(e),
1365
1772
  title: e.fullPath,
1366
1773
  children: [
1367
- /* @__PURE__ */ n("span", { className: "path-kind-icon", "aria-hidden": !0, children: Et[e.kind] ?? "•" }),
1368
- /* @__PURE__ */ n("span", { className: "path-name", children: e.name }),
1369
- g?.type && /* @__PURE__ */ n("span", { className: "chunk-badge", children: g.type }),
1370
- g?.status && /* @__PURE__ */ n("span", { className: "chunk-badge chunk-status", children: g.status }),
1371
- !e.explicit && /* @__PURE__ */ n("span", { className: "path-implicit", title: "Implicit directory (no stored entry)", children: "implicit" })
1774
+ /* @__PURE__ */ t("span", { className: "path-kind-icon", "aria-hidden": !0, children: It[e.kind] ?? "•" }),
1775
+ /* @__PURE__ */ t("span", { className: "path-name", children: e.name }),
1776
+ g?.type && /* @__PURE__ */ t("span", { className: "chunk-badge", children: g.type }),
1777
+ g?.status && /* @__PURE__ */ t("span", { className: "chunk-badge chunk-status", children: g.status }),
1778
+ !e.explicit && /* @__PURE__ */ t("span", { className: "path-implicit", title: "Implicit directory (no stored entry)", children: "implicit" })
1372
1779
  ]
1373
1780
  }
1374
1781
  )
1375
1782
  ] }),
1376
- c && i && /* @__PURE__ */ n("ul", { className: "children path-children", children: e.children.map((b) => /* @__PURE__ */ n(
1377
- je,
1783
+ c && s && /* @__PURE__ */ t("ul", { className: "children path-children", children: e.children.map((v) => /* @__PURE__ */ t(
1784
+ Ge,
1378
1785
  {
1379
- node: b,
1380
- expanded: a,
1381
- toggle: t,
1382
- selectedPath: r,
1786
+ node: v,
1787
+ expanded: r,
1788
+ toggle: n,
1789
+ selectedPath: a,
1383
1790
  onSelect: o,
1384
- summaries: s
1791
+ summaries: i
1385
1792
  },
1386
- b.fullPath
1793
+ v.fullPath
1387
1794
  )) })
1388
1795
  ] });
1389
1796
  }
1390
- const De = /^[A-Za-z0-9._-]+$/;
1391
- function $e(e, a) {
1392
- return `${e}/${a}`;
1797
+ const $e = /^[A-Za-z0-9._-]+$/;
1798
+ function Le(e, r) {
1799
+ return `${e}/${r}`;
1393
1800
  }
1394
- function Fe(e, a) {
1395
- for (const t of e) {
1396
- if (t.fullPath === a) return t;
1397
- const r = Fe(t.children, a);
1398
- if (r) return r;
1801
+ function He(e, r) {
1802
+ for (const n of e) {
1803
+ if (n.fullPath === r) return n;
1804
+ const a = He(n.children, r);
1805
+ if (a) return a;
1399
1806
  }
1400
1807
  }
1401
- function It(e) {
1402
- const { theme: a, defaultScope: t, path: r, onPathChange: o, browse: s, principal: c, renderAssistant: i, onError: d } = e, g = Le(e);
1403
- return /* @__PURE__ */ n(Re, { theme: a, dataLayer: g, children: /* @__PURE__ */ n(
1404
- $t,
1808
+ function Zt(e) {
1809
+ const { theme: r, defaultScope: n, path: a, onPathChange: o, browse: i, principal: c, renderAssistant: s, onError: u } = e, g = Ae(e);
1810
+ return /* @__PURE__ */ t(Pe, { theme: r, dataLayer: g, children: /* @__PURE__ */ t(
1811
+ Ft,
1405
1812
  {
1406
- defaultScope: t,
1407
- path: r,
1813
+ defaultScope: n,
1814
+ path: a,
1408
1815
  onPathChange: o,
1409
- browse: s,
1816
+ browse: i,
1410
1817
  principal: c,
1411
- renderAssistant: i,
1412
- onError: d
1818
+ renderAssistant: s,
1819
+ onError: u
1413
1820
  }
1414
1821
  ) });
1415
1822
  }
1416
- function $t({
1823
+ function Ft({
1417
1824
  defaultScope: e,
1418
- path: a,
1419
- onPathChange: t,
1420
- browse: r,
1825
+ path: r,
1826
+ onPathChange: n,
1827
+ browse: a,
1421
1828
  principal: o,
1422
- renderAssistant: s,
1829
+ renderAssistant: i,
1423
1830
  onError: c
1424
1831
  }) {
1425
- const i = se(), [d, g] = k(e ?? "user"), [m, b] = k([]), [p, O] = k(void 0), [N, T] = k(null), [j, P] = k(!1), [W, R] = k(null), z = a !== void 0 ? a : p, F = ne(t);
1426
- U(() => {
1427
- F.current = t;
1428
- }, [t]);
1429
- const B = ne(c);
1430
- U(() => {
1431
- B.current = c;
1832
+ const s = ae(), [u, g] = f(e ?? "user"), [h, v] = f([]), [m, A] = f(void 0), [C, L] = f(null), [F, I] = f(!1), [P, M] = f(null), j = r !== void 0 ? r : m, $ = ne(n);
1833
+ B(() => {
1834
+ $.current = n;
1835
+ }, [n]);
1836
+ const G = ne(c);
1837
+ B(() => {
1838
+ G.current = c;
1432
1839
  }, [c]);
1433
- const x = A((w) => {
1434
- F.current?.(w), O(w);
1435
- }, []), C = G(
1436
- () => r && (r.scopeId || r.tenant) ? { scopeId: r.scopeId, tenant: r.tenant } : void 0,
1437
- [r?.scopeId, r?.tenant]
1438
- ), I = A(async () => {
1439
- P(!0), T(null);
1840
+ const R = O((x) => {
1841
+ $.current?.(x), A(x);
1842
+ }, []), y = q(
1843
+ () => a && (a.scopeId || a.tenant) ? { scopeId: a.scopeId, tenant: a.tenant } : void 0,
1844
+ [a?.scopeId, a?.tenant]
1845
+ ), D = O(async () => {
1846
+ I(!0), L(null);
1440
1847
  try {
1441
- const w = await i.pathLs("/", d, !0, C);
1442
- b(w.entries ?? []);
1443
- } catch (w) {
1444
- T(w instanceof Error ? w.message : String(w)), b([]), B.current?.(w);
1848
+ const x = await s.pathLs("/", u, !0, y);
1849
+ v(x.entries ?? []);
1850
+ } catch (x) {
1851
+ L(x instanceof Error ? x.message : String(x)), v([]), G.current?.(x);
1445
1852
  } finally {
1446
- P(!1);
1853
+ I(!1);
1447
1854
  }
1448
- }, [i, d, C]), J = ne(!0);
1449
- U(() => {
1450
- J.current ? J.current = !1 : x(void 0), I();
1451
- }, [I, x]);
1452
- const Q = G(() => _t(m), [m]), [M, h] = k(() => /* @__PURE__ */ new Map());
1453
- U(() => {
1454
- if (d === "tenant") {
1455
- h(/* @__PURE__ */ new Map());
1855
+ }, [s, u, y]), J = ne(!0);
1856
+ B(() => {
1857
+ J.current ? J.current = !1 : R(void 0), D();
1858
+ }, [D, R]);
1859
+ const z = q(() => Ut(h), [h]), [N, b] = f(() => /* @__PURE__ */ new Map());
1860
+ B(() => {
1861
+ if (u === "tenant") {
1862
+ b(/* @__PURE__ */ new Map());
1456
1863
  return;
1457
1864
  }
1458
- const w = m.filter((_) => _.kind === "document").map((_) => _.resource_ref?.document_id).filter((_) => !!_);
1459
- if (w.length === 0) {
1460
- h(/* @__PURE__ */ new Map());
1865
+ const x = h.filter((W) => W.kind === "document").map((W) => W.resource_ref?.document_id).filter((W) => !!W);
1866
+ if (x.length === 0) {
1867
+ b(/* @__PURE__ */ new Map());
1461
1868
  return;
1462
1869
  }
1463
- let L = !1;
1464
- return i.documentsSummary({ documentIds: w }, d, C).then((_) => {
1465
- if (L) return;
1466
- const V = /* @__PURE__ */ new Map();
1467
- for (const ae of _.documents ?? []) V.set(ae.document_id, ae);
1468
- h(V);
1870
+ let H = !1;
1871
+ return s.documentsSummary({ documentIds: x }, u, y).then((W) => {
1872
+ if (H) return;
1873
+ const Q = /* @__PURE__ */ new Map();
1874
+ for (const V of W.documents ?? []) Q.set(V.document_id, V);
1875
+ b(Q);
1469
1876
  }).catch(() => {
1470
- L || h(/* @__PURE__ */ new Map());
1877
+ H || b(/* @__PURE__ */ new Map());
1471
1878
  }), () => {
1472
- L = !0;
1879
+ H = !0;
1473
1880
  };
1474
- }, [i, m, d, C]);
1475
- const f = G(
1476
- () => z ? Fe(Q, z) : void 0,
1477
- [Q, z]
1478
- ), E = G(() => f ? f.kind === "directory" ? f.fullPath : ge(f.fullPath) : "", [f]), D = E || "/", Y = d !== "tenant", de = A(() => {
1479
- R({
1480
- title: `New folder in ${D}`,
1881
+ }, [s, h, u, y]);
1882
+ const p = q(
1883
+ () => j ? He(z, j) : void 0,
1884
+ [z, j]
1885
+ ), w = q(() => p ? p.kind === "directory" ? p.fullPath : ke(p.fullPath) : "", [p]), S = w || "/", T = u !== "tenant", ee = O(() => {
1886
+ M({
1887
+ title: `New folder in ${S}`,
1481
1888
  fields: [{ key: "name", label: "Folder name", placeholder: "e.g. launches" }],
1482
1889
  submitLabel: "Create",
1483
- onSubmit: async (w) => {
1484
- const L = w.name.trim();
1485
- if (!De.test(L)) throw new Error("name may contain only [A-Za-z0-9._-]");
1486
- const _ = $e(E, L);
1487
- await i.pathMkdir(_, d, C), await I(), x(_);
1890
+ onSubmit: async (x) => {
1891
+ const H = x.name.trim();
1892
+ if (!$e.test(H)) throw new Error("name may contain only [A-Za-z0-9._-]");
1893
+ const W = Le(w, H);
1894
+ await s.pathMkdir(W, u, y), await D(), R(W);
1488
1895
  }
1489
1896
  });
1490
- }, [i, E, D, d, C, I, x]), H = A(() => {
1491
- R({
1492
- title: `New document in ${D}`,
1897
+ }, [s, w, S, u, y, D, R]), oe = O(() => {
1898
+ M({
1899
+ title: `New document in ${S}`,
1493
1900
  fields: [
1494
1901
  { key: "name", label: "Path name", placeholder: "e.g. launch-plan" },
1495
1902
  { key: "title", label: "Title", placeholder: "e.g. Launch Plan" }
1496
1903
  ],
1497
1904
  submitLabel: "Create",
1498
- onSubmit: async (w) => {
1499
- const L = w.name.trim();
1500
- if (!De.test(L)) throw new Error("name may contain only [A-Za-z0-9._-]");
1501
- const _ = w.title.trim() || L, V = $e(E, L);
1502
- await i.documentCreate(_, V, d, C), await I(), x(V);
1905
+ onSubmit: async (x) => {
1906
+ const H = x.name.trim();
1907
+ if (!$e.test(H)) throw new Error("name may contain only [A-Za-z0-9._-]");
1908
+ const W = x.title.trim() || H, Q = Le(w, H);
1909
+ await s.documentCreate(W, Q, u, y), await D(), R(Q);
1503
1910
  }
1504
1911
  });
1505
- }, [i, E, D, d, C, I, x]), ee = A(() => {
1506
- f && R({
1507
- title: `Rename / move ${f.fullPath}`,
1508
- fields: [{ key: "to", label: "New path", value: f.fullPath }],
1912
+ }, [s, w, S, u, y, D, R]), ce = O(() => {
1913
+ p && M({
1914
+ title: `Rename / move ${p.fullPath}`,
1915
+ fields: [{ key: "to", label: "New path", value: p.fullPath }],
1509
1916
  submitLabel: "Move",
1510
- onSubmit: async (w) => {
1511
- const L = w.to.trim();
1512
- if (!L.startsWith("/")) throw new Error("path must start with /");
1513
- await i.pathMv(f.fullPath, L, d, C), await I(), x(L);
1917
+ onSubmit: async (x) => {
1918
+ const H = x.to.trim();
1919
+ if (!H.startsWith("/")) throw new Error("path must start with /");
1920
+ await s.pathMv(p.fullPath, H, u, y), await D(), R(H);
1514
1921
  }
1515
1922
  });
1516
- }, [i, f, d, C, I, x]), te = A(() => {
1517
- if (!f) return;
1518
- if (f.kind === "document") {
1519
- const V = f.resourceRef?.document_id;
1520
- R({
1521
- title: `Delete document ${f.fullPath}`,
1923
+ }, [s, p, u, y, D, R]), Z = O(() => {
1924
+ if (!p) return;
1925
+ if (p.kind === "document") {
1926
+ const Q = p.resourceRef?.document_id;
1927
+ M({
1928
+ title: `Delete document ${p.fullPath}`,
1522
1929
  message: "This deletes the document, all its chunks, and its path entry. This cannot be undone.",
1523
1930
  fields: [],
1524
1931
  submitLabel: "Delete",
1525
1932
  danger: !0,
1526
1933
  onSubmit: async () => {
1527
- if (!V) throw new Error("this document dirent has no document_id");
1528
- await i.documentDelete(V, d, C), await I(), x(void 0);
1934
+ if (!Q) throw new Error("this document dirent has no document_id");
1935
+ await s.documentDelete(Q, u, y), await D(), R(void 0);
1529
1936
  }
1530
1937
  });
1531
1938
  return;
1532
1939
  }
1533
- const w = d === "tenant" ? [] : St(f), L = f.children.length;
1534
- R({
1535
- title: `Delete branch ${f.fullPath}`,
1536
- message: L === 0 ? "This removes the (empty) folder." : "This removes the folder and everything under it" + (w.length > 0 ? ` — including ${w.length} document(s), whose chunks are deleted.` : "."),
1940
+ const x = u === "tenant" ? [] : Ot(p), H = p.children.length;
1941
+ M({
1942
+ title: `Delete branch ${p.fullPath}`,
1943
+ message: H === 0 ? "This removes the (empty) folder." : "This removes the folder and everything under it" + (x.length > 0 ? ` — including ${x.length} document(s), whose chunks are deleted.` : "."),
1537
1944
  fields: [],
1538
1945
  submitLabel: "Delete",
1539
1946
  danger: !0,
1540
1947
  onSubmit: async () => {
1541
- for (const _ of w)
1542
- await i.documentDelete(_, d, C);
1543
- await i.pathRm(f.fullPath, d, !0, C), await I(), x(void 0);
1948
+ for (const W of x)
1949
+ await s.documentDelete(W, u, y);
1950
+ await s.pathRm(p.fullPath, u, !0, y), await D(), R(void 0);
1544
1951
  }
1545
1952
  });
1546
- }, [i, f, d, C, I, x]), re = f && (f.kind === "directory" || f.kind === "document");
1547
- return /* @__PURE__ */ l(q, { children: [
1953
+ }, [s, p, u, y, D, R]), re = p && (p.kind === "directory" || p.kind === "document");
1954
+ return /* @__PURE__ */ l(Y, { children: [
1548
1955
  /* @__PURE__ */ l(
1549
- ct,
1956
+ ut,
1550
1957
  {
1551
1958
  className: "paths-view",
1552
1959
  defaultLeftWidth: 420,
@@ -1557,161 +1964,161 @@ function $t({
1557
1964
  /* @__PURE__ */ l("div", { className: "left", children: [
1558
1965
  /* @__PURE__ */ l("div", { className: "paths-toolbar", children: [
1559
1966
  /* @__PURE__ */ l("label", { className: "paths-scope", children: [
1560
- /* @__PURE__ */ n("span", { children: "scope" }),
1561
- /* @__PURE__ */ l("select", { value: d, onChange: (w) => g(w.target.value), children: [
1562
- /* @__PURE__ */ n("option", { value: "user", children: "user" }),
1563
- /* @__PURE__ */ n("option", { value: "agent", children: "agent" }),
1564
- /* @__PURE__ */ n("option", { value: "tenant", children: "tenant" })
1967
+ /* @__PURE__ */ t("span", { children: "scope" }),
1968
+ /* @__PURE__ */ l("select", { value: u, onChange: (x) => g(x.target.value), children: [
1969
+ /* @__PURE__ */ t("option", { value: "user", children: "user" }),
1970
+ /* @__PURE__ */ t("option", { value: "agent", children: "agent" }),
1971
+ /* @__PURE__ */ t("option", { value: "tenant", children: "tenant" })
1565
1972
  ] })
1566
1973
  ] }),
1567
1974
  /* @__PURE__ */ l("div", { className: "paths-toolbar-actions", children: [
1568
- /* @__PURE__ */ n("button", { type: "button", onClick: de, title: `New folder in ${D}`, children: "+ folder" }),
1569
- /* @__PURE__ */ n(
1975
+ /* @__PURE__ */ t("button", { type: "button", onClick: ee, title: `New folder in ${S}`, children: "+ folder" }),
1976
+ /* @__PURE__ */ t(
1570
1977
  "button",
1571
1978
  {
1572
1979
  type: "button",
1573
- onClick: H,
1574
- disabled: !Y,
1575
- title: Y ? `New document in ${D}` : "Documents are agent/user scope only",
1980
+ onClick: oe,
1981
+ disabled: !T,
1982
+ title: T ? `New document in ${S}` : "Documents are agent/user scope only",
1576
1983
  children: "+ document"
1577
1984
  }
1578
1985
  ),
1579
- /* @__PURE__ */ n("button", { type: "button", onClick: () => {
1580
- I();
1986
+ /* @__PURE__ */ t("button", { type: "button", onClick: () => {
1987
+ D();
1581
1988
  }, title: "Reload the tree", children: "↻" })
1582
1989
  ] })
1583
1990
  ] }),
1584
1991
  /* @__PURE__ */ l("p", { className: "paths-context", children: [
1585
1992
  "new items → ",
1586
- /* @__PURE__ */ n("code", { children: D }),
1587
- C?.scopeId && /* @__PURE__ */ l(q, { children: [
1993
+ /* @__PURE__ */ t("code", { children: S }),
1994
+ y?.scopeId && /* @__PURE__ */ l(Y, { children: [
1588
1995
  " · ",
1589
1996
  "subject ",
1590
- /* @__PURE__ */ n("code", { children: C.scopeId })
1997
+ /* @__PURE__ */ t("code", { children: y.scopeId })
1591
1998
  ] }),
1592
- C?.tenant && /* @__PURE__ */ l(q, { children: [
1999
+ y?.tenant && /* @__PURE__ */ l(Y, { children: [
1593
2000
  " · ",
1594
2001
  "tenant ",
1595
- /* @__PURE__ */ n("code", { children: C.tenant })
2002
+ /* @__PURE__ */ t("code", { children: y.tenant })
1596
2003
  ] })
1597
2004
  ] }),
1598
- N && /* @__PURE__ */ n("div", { className: "paths-err", children: N }),
1599
- j && m.length === 0 ? /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "Loading…" }) }) : /* @__PURE__ */ n(
1600
- xt,
2005
+ C && /* @__PURE__ */ t("div", { className: "paths-err", children: C }),
2006
+ F && h.length === 0 ? /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Loading…" }) }) : /* @__PURE__ */ t(
2007
+ jt,
1601
2008
  {
1602
- tree: Q,
1603
- selectedPath: z,
1604
- onSelect: (w) => x(w.fullPath),
1605
- summaries: M
2009
+ tree: z,
2010
+ selectedPath: j,
2011
+ onSelect: (x) => R(x.fullPath),
2012
+ summaries: N
1606
2013
  }
1607
2014
  )
1608
2015
  ] }),
1609
- /* @__PURE__ */ n("div", { className: "right", children: f ? f.kind === "document" ? /* @__PURE__ */ l("div", { className: "paths-doc", children: [
2016
+ /* @__PURE__ */ t("div", { className: "right", children: p ? p.kind === "document" ? /* @__PURE__ */ l("div", { className: "paths-doc", children: [
1610
2017
  /* @__PURE__ */ l("div", { className: "paths-doc-head", children: [
1611
- /* @__PURE__ */ n("code", { className: "paths-doc-path", children: f.fullPath }),
2018
+ /* @__PURE__ */ t("code", { className: "paths-doc-path", children: p.fullPath }),
1612
2019
  /* @__PURE__ */ l("div", { className: "paths-detail-actions", children: [
1613
- /* @__PURE__ */ n("button", { type: "button", onClick: ee, children: "rename / move" }),
1614
- /* @__PURE__ */ n("button", { type: "button", className: "danger", onClick: te, children: "delete" })
2020
+ /* @__PURE__ */ t("button", { type: "button", onClick: ce, children: "rename / move" }),
2021
+ /* @__PURE__ */ t("button", { type: "button", className: "danger", onClick: Z, children: "delete" })
1615
2022
  ] })
1616
2023
  ] }),
1617
- /* @__PURE__ */ n(
1618
- Oe,
2024
+ /* @__PURE__ */ t(
2025
+ Fe,
1619
2026
  {
1620
- documentId: f.resourceRef?.document_id ?? "",
1621
- scope: d === "agent" ? "agent" : "user",
1622
- titleHint: f.name,
1623
- browse: C,
2027
+ documentId: p.resourceRef?.document_id ?? "",
2028
+ scope: u,
2029
+ titleHint: p.name,
2030
+ browse: y,
1624
2031
  principal: o,
1625
- renderAssistant: s
2032
+ renderAssistant: i
1626
2033
  }
1627
2034
  )
1628
2035
  ] }) : /* @__PURE__ */ l("div", { className: "paths-detail", children: [
1629
2036
  /* @__PURE__ */ l("h2", { children: [
1630
- /* @__PURE__ */ n("span", { className: "paths-detail-kind", children: f.kind }),
1631
- /* @__PURE__ */ n("code", { children: f.fullPath })
2037
+ /* @__PURE__ */ t("span", { className: "paths-detail-kind", children: p.kind }),
2038
+ /* @__PURE__ */ t("code", { children: p.fullPath })
1632
2039
  ] }),
1633
2040
  /* @__PURE__ */ l("dl", { className: "paths-detail-meta", children: [
1634
- /* @__PURE__ */ n("dt", { children: "scope" }),
1635
- /* @__PURE__ */ n("dd", { children: d }),
1636
- /* @__PURE__ */ n("dt", { children: "stored" }),
1637
- /* @__PURE__ */ n("dd", { children: f.explicit ? "yes" : "implicit (no entry)" })
2041
+ /* @__PURE__ */ t("dt", { children: "scope" }),
2042
+ /* @__PURE__ */ t("dd", { children: u }),
2043
+ /* @__PURE__ */ t("dt", { children: "stored" }),
2044
+ /* @__PURE__ */ t("dd", { children: p.explicit ? "yes" : "implicit (no entry)" })
1638
2045
  ] }),
1639
2046
  re ? /* @__PURE__ */ l("div", { className: "paths-detail-actions", children: [
1640
- /* @__PURE__ */ n("button", { type: "button", onClick: ee, children: "rename / move" }),
1641
- /* @__PURE__ */ n("button", { type: "button", className: "danger", onClick: te, children: "delete" })
2047
+ /* @__PURE__ */ t("button", { type: "button", onClick: ce, children: "rename / move" }),
2048
+ /* @__PURE__ */ t("button", { type: "button", className: "danger", onClick: Z, children: "delete" })
1642
2049
  ] }) : /* @__PURE__ */ l("p", { className: "paths-readonly", children: [
1643
2050
  "Read-only — ",
1644
- f.kind,
2051
+ p.kind,
1645
2052
  " entries are managed by their own tool."
1646
2053
  ] })
1647
- ] }) : /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "Select a path on the left, or create a folder / document." }) }) })
2054
+ ] }) : /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Select a path on the left, or create a folder / document." }) }) })
1648
2055
  ]
1649
2056
  }
1650
2057
  ),
1651
- W && /* @__PURE__ */ n(Mt, { state: W, onClose: () => R(null) })
2058
+ P && /* @__PURE__ */ t(Gt, { state: P, onClose: () => M(null) })
1652
2059
  ] });
1653
2060
  }
1654
- function Mt({ state: e, onClose: a }) {
1655
- const [t, r] = k(
2061
+ function Gt({ state: e, onClose: r }) {
2062
+ const [n, a] = f(
1656
2063
  () => Object.fromEntries(e.fields.map((g) => [g.key, g.value ?? ""]))
1657
- ), [o, s] = k(!1), [c, i] = k(null);
1658
- return /* @__PURE__ */ n("div", { className: "modal-overlay", onClick: a, children: /* @__PURE__ */ l("form", { className: "modal", onClick: (g) => g.stopPropagation(), onSubmit: async (g) => {
1659
- g.preventDefault(), s(!0), i(null);
2064
+ ), [o, i] = f(!1), [c, s] = f(null);
2065
+ return /* @__PURE__ */ t("div", { className: "modal-overlay", onClick: r, children: /* @__PURE__ */ l("form", { className: "modal", onClick: (g) => g.stopPropagation(), onSubmit: async (g) => {
2066
+ g.preventDefault(), i(!0), s(null);
1660
2067
  try {
1661
- await e.onSubmit(t), a();
1662
- } catch (m) {
1663
- i(m instanceof Error ? m.message : String(m)), s(!1);
2068
+ await e.onSubmit(n), r();
2069
+ } catch (h) {
2070
+ s(h instanceof Error ? h.message : String(h)), i(!1);
1664
2071
  }
1665
2072
  }, children: [
1666
2073
  /* @__PURE__ */ l("div", { className: "modal-header sticky-top", children: [
1667
- /* @__PURE__ */ n("h3", { children: e.title }),
2074
+ /* @__PURE__ */ t("h3", { children: e.title }),
1668
2075
  /* @__PURE__ */ l("div", { className: "modal-buttons modal-buttons-top", children: [
1669
- /* @__PURE__ */ n("button", { type: "button", onClick: a, disabled: o, children: "cancel" }),
1670
- /* @__PURE__ */ n("button", { type: "submit", className: e.danger ? "danger" : "primary", disabled: o, children: o ? "working…" : e.submitLabel })
2076
+ /* @__PURE__ */ t("button", { type: "button", onClick: r, disabled: o, children: "cancel" }),
2077
+ /* @__PURE__ */ t("button", { type: "submit", className: e.danger ? "danger" : "primary", disabled: o, children: o ? "working…" : e.submitLabel })
1671
2078
  ] })
1672
2079
  ] }),
1673
- e.message && /* @__PURE__ */ n("p", { className: "modal-context", children: e.message }),
1674
- e.fields.map((g, m) => /* @__PURE__ */ l("label", { className: "path-field", children: [
1675
- /* @__PURE__ */ n("span", { children: g.label }),
1676
- /* @__PURE__ */ n(
2080
+ e.message && /* @__PURE__ */ t("p", { className: "modal-context", children: e.message }),
2081
+ e.fields.map((g, h) => /* @__PURE__ */ l("label", { className: "path-field", children: [
2082
+ /* @__PURE__ */ t("span", { children: g.label }),
2083
+ /* @__PURE__ */ t(
1677
2084
  "input",
1678
2085
  {
1679
2086
  className: "path-modal-input",
1680
- value: t[g.key],
2087
+ value: n[g.key],
1681
2088
  placeholder: g.placeholder,
1682
- autoFocus: m === 0,
1683
- onChange: (b) => r((p) => ({ ...p, [g.key]: b.target.value }))
2089
+ autoFocus: h === 0,
2090
+ onChange: (v) => a((m) => ({ ...m, [g.key]: v.target.value }))
1684
2091
  }
1685
2092
  )
1686
2093
  ] }, g.key)),
1687
- c && /* @__PURE__ */ n("div", { className: "modal-err", children: c })
2094
+ c && /* @__PURE__ */ t("div", { className: "modal-err", children: c })
1688
2095
  ] }) });
1689
2096
  }
1690
- function Ut(e) {
1691
- const { documentId: a, scope: t, titleHint: r, browse: o, theme: s, principal: c, renderAssistant: i } = e, d = Le(e);
1692
- return /* @__PURE__ */ n(Re, { theme: s, dataLayer: d, children: /* @__PURE__ */ n(
1693
- Oe,
2097
+ function qt(e) {
2098
+ const { documentId: r, scope: n, titleHint: a, browse: o, theme: i, principal: c, renderAssistant: s } = e, u = Ae(e);
2099
+ return /* @__PURE__ */ t(Pe, { theme: i, dataLayer: u, children: /* @__PURE__ */ t(
2100
+ Fe,
1694
2101
  {
1695
- documentId: a,
1696
- scope: t,
1697
- titleHint: r,
2102
+ documentId: r,
2103
+ scope: n,
2104
+ titleHint: a,
1698
2105
  browse: o,
1699
2106
  principal: c,
1700
- renderAssistant: i
2107
+ renderAssistant: s
1701
2108
  }
1702
2109
  ) });
1703
2110
  }
1704
2111
  export {
1705
- fe as DEFAULT_SCHEME,
1706
- Ut as DocumentViewer,
1707
- It as PathExplorer,
1708
- ot as assetFetchFromConnection,
1709
- dt as chunkColor,
1710
- rt as createLoomcycleClient,
1711
- Ne as dataLayerFromClient,
1712
- Pe as docColor,
1713
- ye as effectiveScheme,
1714
- ut as hexToTint,
1715
- be as tintStyle
2112
+ be as DEFAULT_SCHEME,
2113
+ qt as DocumentViewer,
2114
+ Zt as PathExplorer,
2115
+ dt as assetFetchFromConnection,
2116
+ ft as chunkColor,
2117
+ lt as createLoomcycleClient,
2118
+ _e as dataLayerFromClient,
2119
+ Ie as docColor,
2120
+ ve as effectiveScheme,
2121
+ gt as hexToTint,
2122
+ Ne as tintStyle
1716
2123
  };
1717
2124
  //# sourceMappingURL=index.js.map