@loomcycle/explorer 0.4.0 → 0.6.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,203 +1,264 @@
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 nt, useContext as at, useMemo as q, useState as f, useRef as ne, useEffect as B, useCallback as j } from "react";
3
+ import { LoomcycleClient as rt } from "@loomcycle/client";
4
+ import ot from "react-markdown";
5
+ import ct 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 = nt(null);
176
+ function it({
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 = at(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 st(e) {
191
+ const r = e.fetch;
192
+ return new rt({
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 lt(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 Pe(e) {
206
+ const { dataLayer: r, client: n, connection: a } = e;
207
+ return q(() => r || (n ? _e(n) : a ? _e(
208
+ st(a),
209
+ lt(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 Ae({
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(it, { 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 dt({
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
+ }), d = ne(null), [g, m] = 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) => {
249
+ const k = j((C) => {
250
+ C.preventDefault(), m(!0), C.target.setPointerCapture(C.pointerId);
251
+ }, []), h = j(
252
+ (C) => {
192
253
  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);
254
+ const L = d.current.getBoundingClientRect(), F = C.clientX - L.left, O = L.width - a - Se, A = Math.max(n, Math.min(F, O));
255
+ s(A);
195
256
  },
196
- [g, t, r]
197
- ), O = A((N) => {
257
+ [g, n, a]
258
+ ), P = j((C) => {
198
259
  m(!1);
199
260
  try {
200
- N.target.releasePointerCapture(N.pointerId);
261
+ C.target.releasePointerCapture(C.pointerId);
201
262
  } catch {
202
263
  }
203
264
  }, []);
@@ -205,190 +266,199 @@ function ct({
205
266
  "div",
206
267
  {
207
268
  ref: d,
208
- className: `splitter ${s ?? ""} ${g ? "dragging" : ""}`,
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: k,
283
+ onPointerMove: h,
284
+ onPointerUp: P,
285
+ onPointerCancel: P
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 ut = ["image/png", "image/jpeg", "image/gif", "image/webp"];
294
+ function Ue(e) {
295
+ return ut.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 ht(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
+ }, mt = 0.16;
347
+ function ke(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 pt(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 ft(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}, ${mt})`;
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 = ft(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 gt(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 yt({
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()), d = j((m) => {
405
+ s((k) => {
406
+ const h = new Map(k);
407
+ return h.set(m, k.get(m) === !1), h;
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 m = bt(e, r);
413
+ m.length !== 0 && s((k) => {
414
+ let h = !1;
415
+ const P = new Map(k);
416
+ for (const C of m)
417
+ P.get(C) === !1 && (P.set(C, !0), h = !0);
418
+ return h ? P : k;
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 ? ke(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((m) => /* @__PURE__ */ t(
423
+ Be,
354
424
  {
355
425
  node: m,
356
426
  expanded: c,
357
427
  toggle: d,
358
- selectedId: a,
359
- onSelect: t,
428
+ selectedId: r,
429
+ onSelect: n,
360
430
  tintScheme: g,
361
- linkedIds: s
431
+ linkedIds: i
362
432
  },
363
433
  m.row.id
364
434
  )) });
365
435
  }
366
- function pt(e, a) {
367
- const t = [], r = (o, s) => {
436
+ function bt(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, d = r.get(e.row.id) !== !1, g = a === e.row.id, m = i ? Ne(pt(e.row.status, i)) : void 0, k = c?.has(e.row.id);
379
449
  return /* @__PURE__ */ l("li", { className: `node chunk-node ${g ? "selected" : ""}`, children: [
380
450
  /* @__PURE__ */ l("div", { className: "row chunk-row", style: m, children: [
381
- /* @__PURE__ */ n(
451
+ /* @__PURE__ */ t(
382
452
  "button",
383
453
  {
384
454
  type: "button",
385
455
  className: "tree-caret",
386
456
  "aria-label": d ? "collapse" : "expand",
387
- disabled: !i,
388
- onClick: (p) => {
389
- p.stopPropagation(), i && t(e.row.id);
457
+ disabled: !s,
458
+ onClick: (h) => {
459
+ h.stopPropagation(), s && n(e.row.id);
390
460
  },
391
- children: i ? d ? "▼" : "▶" : "·"
461
+ children: s ? d ? "▼" : "▶" : "·"
392
462
  }
393
463
  ),
394
464
  /* @__PURE__ */ l(
@@ -399,961 +469,1270 @@ 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
+ k && /* @__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 && d && /* @__PURE__ */ t("ul", { className: "children chunk-children", children: e.children.map((h) => /* @__PURE__ */ t(
482
+ Be,
413
483
  {
414
- node: p,
415
- expanded: a,
416
- toggle: t,
417
- selectedId: r,
484
+ node: h,
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
+ h.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: d } = await i.render(`lc-mmd-${vt++}`, e);
506
+ o || a({ svg: d });
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 kt({ chunk: e, scope: r, browse: n, onClose: a, onSaved: o }) {
516
+ const i = ae(), [c, s] = f(e.title), [d, g] = f(e.type ?? ""), [m, k] = f(e.status ?? ""), [h, P] = 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, O] = f((e.tags ?? []).join(", ")), [A, M] = f(!1), [I, $] = f(null), [G, R] = f(!1), y = d === "mermaid", D = d === "image" || !!e.asset, [J, V] = f(h);
519
+ B(() => {
520
+ if (!y) return;
521
+ const w = setTimeout(() => V(h), 400);
522
+ return () => clearTimeout(w);
523
+ }, [h, 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: h,
467
537
  title: c,
468
538
  type: d,
469
- status: m
539
+ status: m,
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: A, children: "cancel" }),
564
+ /* @__PURE__ */ t("button", { type: "submit", className: "primary", disabled: A, children: A ? "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
+ I && /* @__PURE__ */ l("div", { className: "modal-err", children: [
568
+ I,
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
582
  value: d,
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
594
  value: m,
522
595
  placeholder: "(none)",
523
- onChange: (h) => b(h.target.value)
596
+ onChange: (w) => k(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) => O(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: A,
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: h,
636
+ onChange: (w) => P(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 Nt(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 wt({
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,
673
+ onClose: s,
589
674
  onSaved: d
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(), [m, k] = f(null), [h, P] = f(!1), [C, L] = f({}), [F, O] = f(!1), [A, M] = f(null), [I, $] = 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
+ k(p);
687
+ const w = p.fields ?? {};
688
+ P(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 () => {
694
+ }, [g, r, i, c]);
695
+ const R = (b, p) => L((w) => ({ ...w, [b]: p })), y = (b) => ({
696
+ ...b ?? {},
697
+ color_enabled: h,
698
+ color_scheme: C
699
+ }), D = async () => {
615
700
  if (m) {
616
- P(!0), F(null), R(null);
701
+ O(!0), $(null), M(null);
617
702
  try {
618
703
  await g.documentUpdateChunk(
619
- a,
704
+ r,
620
705
  m.revision,
621
- { fields: C(m.fields) },
622
- s,
706
+ { fields: y(m.fields) },
707
+ i,
623
708
  c
624
- ), d(), i();
625
- } catch (h) {
626
- F(h instanceof Error ? h.message : String(h)), P(!1);
709
+ ), d(), s();
710
+ } catch (b) {
711
+ $(b instanceof Error ? b.message : String(b)), O(!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
+ O(!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).`), d();
738
+ } catch (b) {
739
+ $(b instanceof Error ? b.message : String(b));
655
740
  } finally {
656
- P(!1);
741
+ O(!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
+ }, V = 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 || !m, 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
+ I && /* @__PURE__ */ t("div", { className: "modal-err", children: I }),
755
+ m ? /* @__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: h,
762
+ onChange: (b) => P(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
+ V.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
+ A && /* @__PURE__ */ t("span", { className: "scheme-status", children: A })
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 = Nt(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 })
795
+ ] });
796
+ }
797
+ const Ct = 8, _t = 20;
798
+ function St(e) {
799
+ return /embedder|embedding|vector|semantic|not configured/i.test(e);
800
+ }
801
+ function Et({
802
+ documentId: e,
803
+ selectedId: r,
804
+ scope: n,
805
+ browse: a,
806
+ onSelectChunk: o
807
+ }) {
808
+ const i = ae(), [c, s] = f(!1), [d, g] = f(!1), [m, k] = f(void 0), [h, P] = f([]), [C, L] = f([]), [F, O] = f(null), [A, M] = f([]), [I, $] = 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, Ct),
816
+ i.documentUnlinkedMentions(y, n, a, _t)
817
+ ]).then(([J, V, N]) => {
818
+ if (!D) {
819
+ if (P(J.status === "fulfilled" ? J.value.backlinks ?? [] : []), V.status === "fulfilled")
820
+ L(V.value.related ?? []), O(null);
821
+ else {
822
+ L([]);
823
+ const b = V.reason instanceof Error ? V.reason.message : String(V.reason);
824
+ O(St(b) ? "semantic search not configured" : b);
825
+ }
826
+ N.status === "fulfilled" ? (M(N.value.unlinked_mentions ?? []), $(!!N.value.truncated)) : (M([]), $(!1)), k(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 && !d && m === r) ? /* @__PURE__ */ l(Y, { children: [
847
+ /* @__PURE__ */ l("div", { className: "doc-conn-group", children: [
848
+ /* @__PURE__ */ t("h5", { children: "Backlinks" }),
849
+ h.length === 0 ? /* @__PURE__ */ t("p", { className: "doc-conn-empty", children: "none" }) : /* @__PURE__ */ t("ul", { className: "doc-conn-list", children: h.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
+ A.length === 0 ? /* @__PURE__ */ t("p", { className: "doc-conn-empty", children: "none" }) : /* @__PURE__ */ l("ul", { className: "doc-conn-list", children: [
881
+ A.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
+ I && /* @__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." }) })
710
894
  ] });
711
895
  }
712
- const pe = 24;
713
- function kt({
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 xt({
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 d = n ? e.filter((k) => k.from_id === n || k.to_id === n) : [], g = c ? e : e.slice(0, ye), m = Rt(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
+ d.length === 0 ? /* @__PURE__ */ t("p", { className: "doc-refs-empty", children: "This chunk has no links." }) : /* @__PURE__ */ t("ul", { className: "doc-refs-list", children: d.map((k, h) => /* @__PURE__ */ t(
922
+ Dt,
727
923
  {
728
- edge: b,
729
- selectedId: t,
730
- documentId: a,
731
- onSelectChunk: r
924
+ edge: k,
925
+ selectedId: n,
926
+ documentId: r,
927
+ onSelectChunk: a
732
928
  },
733
- `${b.from_id}-${b.to_id}-${b.kind}-${p}`
929
+ `${k.from_id}-${k.to_id}-${k.kind}-${h}`
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((k) => !k), 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: m }),
941
+ e.length > ye && /* @__PURE__ */ t("button", { type: "button", className: "doc-graph-more", onClick: () => s((k) => !k), children: c ? `show top ${ye}` : `show all ${e.length}` })
746
942
  ] })
747
943
  ] })
748
944
  ] });
749
945
  }
750
- function vt({
946
+ function Dt({
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, d = !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
+ d ? /* @__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 Rt(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;
781
977
  }
782
- function xe({ source: e }) {
783
- return /* @__PURE__ */ n("div", { className: "md", children: /* @__PURE__ */ n(tt, { remarkPlugins: [nt], components: wt, children: e }) });
978
+ function Mt(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();
784
981
  }
785
- const wt = {
982
+ function $t({
983
+ chunkId: e,
984
+ chunkTitle: r,
985
+ scope: n,
986
+ browse: a,
987
+ onClose: o
988
+ }) {
989
+ const i = ae(), [c, s] = f([]), [d, g] = f(!0), [m, k] = f(null), [h, P] = f("none"), [C, L] = f(null), [F, O] = f(""), [A, M] = f(!1), [I, $] = f(null), [G, R] = f(null), [y, D] = f("");
990
+ B(() => {
991
+ let N = !1;
992
+ return g(!0), k(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 && k(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
+ k(null), M(!0), L(N), P("version");
1005
+ try {
1006
+ const b = await i.documentGetVersion(e, N, n, a);
1007
+ O(b.body ?? "");
1008
+ } catch (b) {
1009
+ k(b instanceof Error ? b.message : String(b));
1010
+ } finally {
1011
+ M(!1);
1012
+ }
1013
+ }, V = async () => {
1014
+ if (!(I === null || G === null)) {
1015
+ k(null), M(!0), P("diff");
1016
+ try {
1017
+ const N = await i.documentDiff(e, I, G, n, a);
1018
+ D(N.diff ?? "");
1019
+ } catch (N) {
1020
+ k(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
+ m && /* @__PURE__ */ t("div", { className: "modal-err", children: m }),
1035
+ d ? /* @__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" + (h === "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: Mt(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: I ?? "",
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
+ V();
1088
+ },
1089
+ disabled: A || I === null || G === null,
1090
+ children: "diff"
1091
+ }
1092
+ )
1093
+ ] }),
1094
+ /* @__PURE__ */ t("div", { className: "doc-hist-output", children: A ? /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "loading…" }) : h === "diff" ? /* @__PURE__ */ t(Lt, { text: y }) : h === "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 Lt({ 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
+ }) });
1110
+ }
1111
+ function Me({ source: e }) {
1112
+ return /* @__PURE__ */ t("div", { className: "md", children: /* @__PURE__ */ t(ot, { remarkPlugins: [ct], components: Tt, children: e }) });
1113
+ }
1114
+ const Tt = {
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(
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
+ ), [d, g] = f([]), [m, k] = f(void 0), [h, P] = f(null), [C, L] = f("chunks"), [F, O] = f(null), [A, M] = f(null), [I, $] = f(null), G = ne(null), [R, y] = f(null), [D, J] = f(!1), [V, 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([]), z = j(() => ee((u) => u + 1), []), he = q(() => gt(d), [d]), ie = q(() => d.find((v) => !v.parent_id)?.title || n || "document", [d, n]), te = q(
1147
+ () => !!h && !h.parent_id,
1148
+ [h]
1149
+ ), X = q(
1150
+ () => Z?.root_chunk_id ?? d.find((u) => !u.parent_id)?.id,
1151
+ [Z, d]
1152
+ ), We = q(
824
1153
  () => [...new Set(d.map((u) => u.status).filter((u) => !!u))],
825
1154
  [d]
826
- ), oe = !!H?.color_enabled, Be = G(() => {
1155
+ ), se = !!Z?.color_enabled, Ve = q(() => {
827
1156
  const u = /* @__PURE__ */ new Set();
828
- for (const y of w)
829
- u.add(y.from_id), u.add(y.to_id);
1157
+ for (const v of W)
1158
+ u.add(v.from_id), u.add(v.to_id);
830
1159
  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]
1160
+ }, [W]), ze = q(
1161
+ () => se ? Ne(Ie(Z?.type, Z?.status, ke(Z?.color_scheme))) : void 0,
1162
+ [se, Z?.type, Z?.status, Z?.color_scheme]
834
1163
  );
835
- U(() => {
1164
+ B(() => {
836
1165
  let u = !1;
837
- return f(!0), M(null), c.documentQueryChunks(e, a, i).then((y) => {
1166
+ return S(!0), p(null), c.documentQueryChunks(e, r, s).then((v) => {
838
1167
  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)), () => {
1168
+ const _ = v.chunks ?? [];
1169
+ g(_), k((E) => E ?? _.find((U) => !U.parent_id)?.id);
1170
+ }).catch((v) => !u && p(v instanceof Error ? v.message : String(v))).finally(() => !u && S(!1)), () => {
842
1171
  u = !0;
843
1172
  };
844
- }, [c, e, a, E, i]), U(() => {
1173
+ }, [c, e, r, T, s]), B(() => {
845
1174
  let u = !1;
846
- return c.documentGet(e, a, i).then((y) => !u && ee(y)).catch(() => !u && ee(null)), () => {
1175
+ return c.documentGet(e, r, s).then((v) => !u && re(v)).catch(() => !u && re(null)), () => {
847
1176
  u = !0;
848
1177
  };
849
- }, [c, e, a, E, i]), U(() => {
1178
+ }, [c, e, r, T, s]), B(() => {
850
1179
  let u = !1;
851
- return c.documentGetEdges(e, a, i).then((y) => !u && L(y.edges ?? [])).catch(() => !u && L([])), () => {
1180
+ return c.documentGetEdges(e, r, s).then((v) => !u && Q(v.edges ?? [])).catch(() => !u && Q([])), () => {
852
1181
  u = !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(() => {
1183
+ }, [c, e, r, T, s]), B(() => {
1184
+ k(void 0), P(null), O(null), L("chunks"), re(null), Q([]);
1185
+ }, [e, r]), B(() => {
857
1186
  if (!m) {
858
- O(null);
1187
+ P(null);
859
1188
  return;
860
1189
  }
861
1190
  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))), () => {
1191
+ return c.documentGetChunk(m, r, s).then((v) => !u && P(v)).catch((v) => !u && p(v instanceof Error ? v.message : String(v))), () => {
863
1192
  u = !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, m, r, T, s]), B(() => {
1195
+ const u = h?.type === "image" || !!h?.asset;
1196
+ if (!h || !u || !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 v = !1, _ = null;
1201
+ return $(null), c.documentAssetObjectUrl(h.id, r, s).then((E) => {
1202
+ if (v) {
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) => !v && $(E instanceof Error ? E.message : String(E))), () => {
1208
+ v = !0, _ && URL.revokeObjectURL(_);
880
1209
  };
881
- }, [c, p, a, i]), U(() => {
882
- if (N !== "markdown" || !m) {
883
- P(null);
1210
+ }, [c, h, r, s]), B(() => {
1211
+ if (C !== "markdown" || !m) {
1212
+ O(null);
884
1213
  return;
885
1214
  }
886
- const u = Ie(V, m);
1215
+ const u = je(he, m);
887
1216
  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));
1217
+ let v = !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(u, 0), Promise.all(_.map((U) => c.documentGetChunk(U.node.row.id, r, s))).then((U) => {
1222
+ if (v) return;
1223
+ const le = _.map((de, Ke) => {
1224
+ const et = Math.min(de.depth + 1, 6), K = U[Ke], fe = "#".repeat(et) + " " + 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 tt = K.body ? " — " + K.body : "";
1229
+ return fe + `
901
1230
 
902
- _🖼 image chunk_` + Xe + `
1231
+ _🖼 image chunk_` + tt + `
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
+ O(le);
1241
+ }).catch((U) => !v && p(U instanceof Error ? U.message : String(U))), () => {
1242
+ v = !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, m, he, r, T, s]);
1245
+ const Je = j((u) => k(u.row.id), []), Ze = j(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);
1247
+ const u = await c.documentExportMd(e, r, !0, s), v = new Blob([u.markdown], { type: "text/markdown" }), _ = URL.createObjectURL(v), E = document.createElement("a");
1248
+ E.href = _, E.download = (u.title || "document").replace(/[^\w.-]+/g, "_") + ".md", E.click(), URL.revokeObjectURL(_);
920
1249
  } catch (u) {
921
- M(u instanceof Error ? u.message : String(u));
1250
+ p(u instanceof Error ? u.message : String(u));
922
1251
  }
923
- }, [c, e, a, i]), ue = !!c.documentCreateChunk && !!Z, he = A(
1252
+ }, [c, e, r, s]), qe = j(async () => {
1253
+ try {
1254
+ const u = await c.documentExportCanvas(e, r, s), v = new Blob([JSON.stringify(u.canvas, null, 2)], {
1255
+ type: "application/json"
1256
+ }), _ = URL.createObjectURL(v), E = document.createElement("a");
1257
+ E.href = _, E.download = (ie || "document").replace(/[^\w.-]+/g, "_") + ".canvas", E.click(), URL.revokeObjectURL(_);
1258
+ } catch (u) {
1259
+ p(u instanceof Error ? u.message : String(u));
1260
+ }
1261
+ }, [c, e, r, s, ie]), me = !!c.documentCreateChunk && !!X, pe = j(
924
1262
  async (u) => {
925
1263
  if (!c.documentCreateChunk || !c.documentSetAsset) return;
926
- const y = m || Z;
927
- if (y) {
928
- M(null);
1264
+ const v = m || X;
1265
+ if (v) {
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(u), U = await c.documentCreateChunk(
931
1269
  e,
932
- y,
1270
+ v,
933
1271
  { title: u.name || "image", type: "image" },
934
- a,
935
- i
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, u.name, r, s), z(), k(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, m, X, z]
1282
+ ), Qe = j(async () => {
945
1283
  if (!c.documentCreateChunk) return;
946
- const u = m || Z;
1284
+ const u = m || X;
947
1285
  if (u) {
948
- M(null);
1286
+ p(null);
949
1287
  try {
950
- const y = await c.documentCreateChunk(
1288
+ const v = await c.documentCreateChunk(
951
1289
  e,
952
1290
  u,
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
+ z(), k(v.id), y(v);
1297
+ } catch (v) {
1298
+ p(v instanceof Error ? v.message : String(v));
961
1299
  }
962
1300
  }
963
- }, [c, e, a, i, m, Z, _]), Ve = A(async () => {
1301
+ }, [c, e, r, s, m, X, z]), Xe = j(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 u = m && !te ? m : void 0, v = m || X;
1304
+ if (v) {
1305
+ p(null);
968
1306
  try {
969
- const v = await c.documentCreateChunk(
1307
+ const _ = await c.documentCreateChunk(
970
1308
  e,
971
- u ? "" : y,
1309
+ u ? "" : v,
972
1310
  // after_id resolves the parent server-side
973
1311
  { title: "Text", body: "" },
974
- a,
975
- i,
1312
+ r,
1313
+ s,
976
1314
  u
977
1315
  );
978
- _(), b(v.id), C(v);
979
- } catch (v) {
980
- M(v instanceof Error ? v.message : String(v));
1316
+ z(), k(_.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(
1321
+ }, [c, e, r, s, m, te, X, z]), we = q(() => {
1322
+ if (!h || te) return { canUp: !1, canDown: !1 };
1323
+ const u = h.parent_id ?? "", v = d.filter((E) => (E.parent_id ?? "") === u).sort((E, U) => E.position - U.position || E.id.localeCompare(U.id)), _ = v.findIndex((E) => E.id === h.id);
1324
+ return { canUp: _ > 0, canDown: _ >= 0 && _ < v.length - 1 };
1325
+ }, [d, h, te]), Ce = j(
988
1326
  async (u) => {
989
1327
  if (!(!c.documentReorderChunk || !m)) {
990
- M(null);
1328
+ p(null);
991
1329
  try {
992
- await c.documentReorderChunk(m, u, a, i), _();
993
- } catch (y) {
994
- M(y instanceof Error ? y.message : String(y));
1330
+ await c.documentReorderChunk(m, u, r, s), z();
1331
+ } catch (v) {
1332
+ p(v instanceof Error ? v.message : String(v));
995
1333
  }
996
1334
  }
997
1335
  },
998
- [c, m, a, i, _]
999
- ), Ze = A(async () => {
1000
- if (!c.documentDeleteChunk || !p) return;
1001
- M(null);
1002
- const u = p.parent_id;
1336
+ [c, m, r, s, z]
1337
+ ), Ye = j(async () => {
1338
+ if (!c.documentDeleteChunk || !h) return;
1339
+ p(null);
1340
+ const u = h.parent_id;
1003
1341
  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);
1342
+ await c.documentDeleteChunk(h.id, r, s), N(!1), k(u || X), z();
1343
+ } catch (v) {
1344
+ p(v instanceof Error ? v.message : String(v)), N(!1);
1007
1345
  }
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($));
1346
+ }, [c, h, r, s, X, z]);
1347
+ return B(() => {
1348
+ if (!me) return;
1349
+ const u = (v) => {
1350
+ if (R || x) return;
1351
+ const _ = document.activeElement, E = _?.tagName;
1352
+ if (E === "INPUT" || E === "TEXTAREA" || _?.isContentEditable) return;
1353
+ const U = ht(v.clipboardData?.items);
1354
+ U && (v.preventDefault(), pe(U));
1017
1355
  };
1018
1356
  return window.addEventListener("paste", u), () => window.removeEventListener("paste", u);
1019
- }, [ue, x, te, he]), /* @__PURE__ */ l("div", { className: "doc-viewer", children: [
1020
- /* @__PURE__ */ n(
1357
+ }, [me, R, x, pe]), /* @__PURE__ */ l("div", { className: "doc-viewer", children: [
1358
+ /* @__PURE__ */ t(
1021
1359
  "input",
1022
1360
  {
1023
- ref: B,
1361
+ ref: G,
1024
1362
  type: "file",
1025
1363
  accept: "image/png,image/jpeg,image/gif,image/webp",
1026
1364
  style: { display: "none" },
1027
1365
  onChange: (u) => {
1028
- const y = u.target.files?.[0];
1029
- u.target.value = "", y && he(y);
1366
+ const v = u.target.files?.[0];
1367
+ u.target.value = "", v && pe(v);
1030
1368
  }
1031
1369
  }
1032
1370
  ),
1033
- /* @__PURE__ */ l("div", { className: "doc-toolbar", style: He, children: [
1034
- /* @__PURE__ */ n("strong", { className: "doc-title", title: ae, children: ae }),
1371
+ /* @__PURE__ */ l("div", { className: "doc-toolbar", style: ze, children: [
1372
+ /* @__PURE__ */ t("strong", { className: "doc-title", title: ie, children: ie }),
1035
1373
  /* @__PURE__ */ l("div", { className: "doc-toolbar-actions", children: [
1036
- ue && /* @__PURE__ */ l(q, { children: [
1037
- /* @__PURE__ */ n(
1374
+ me && /* @__PURE__ */ l(Y, { children: [
1375
+ /* @__PURE__ */ t(
1038
1376
  "button",
1039
1377
  {
1040
1378
  type: "button",
1041
1379
  onClick: () => {
1042
- Ve();
1380
+ Xe();
1043
1381
  },
1044
1382
  title: "Add a text chunk after the selected chunk",
1045
1383
  children: "+ text"
1046
1384
  }
1047
1385
  ),
1048
- /* @__PURE__ */ n(
1386
+ /* @__PURE__ */ t(
1049
1387
  "button",
1050
1388
  {
1051
1389
  type: "button",
1052
- onClick: () => B.current?.click(),
1390
+ onClick: () => G.current?.click(),
1053
1391
  title: "Add an image chunk (upload — or paste a screenshot into the view)",
1054
1392
  children: "+ image"
1055
1393
  }
1056
1394
  ),
1057
- /* @__PURE__ */ n(
1395
+ /* @__PURE__ */ t(
1058
1396
  "button",
1059
1397
  {
1060
1398
  type: "button",
1061
1399
  onClick: () => {
1062
- Je();
1400
+ Qe();
1063
1401
  },
1064
1402
  title: "Add a Mermaid diagram chunk",
1065
1403
  children: "+ diagram"
1066
1404
  }
1067
1405
  )
1068
1406
  ] }),
1069
- /* @__PURE__ */ n(
1407
+ /* @__PURE__ */ t(
1070
1408
  "button",
1071
1409
  {
1072
1410
  type: "button",
1073
- className: oe ? "active" : "",
1074
- onClick: () => re(!0),
1075
- disabled: !Z,
1411
+ className: se ? "active" : "",
1412
+ onClick: () => H(!0),
1413
+ disabled: !X,
1076
1414
  title: "Colors — tint chunk tiles + the Path tree by type/status",
1077
1415
  children: "colors"
1078
1416
  }
1079
1417
  ),
1080
- /* @__PURE__ */ n("button", { type: "button", onClick: () => {
1081
- ze();
1418
+ /* @__PURE__ */ t("button", { type: "button", onClick: () => {
1419
+ Ze();
1082
1420
  }, title: "Download the whole document as Markdown (.md)", children: "↓ .md" }),
1083
- s && /* @__PURE__ */ n(
1421
+ /* @__PURE__ */ t(
1084
1422
  "button",
1085
1423
  {
1086
1424
  type: "button",
1087
- className: Y ? "active" : "",
1088
- onClick: () => de((u) => !u),
1425
+ onClick: () => {
1426
+ qe();
1427
+ },
1428
+ title: "Download the whole document as a node/edge canvas graph (.canvas)",
1429
+ children: "↓ .canvas"
1430
+ }
1431
+ ),
1432
+ i && /* @__PURE__ */ t(
1433
+ "button",
1434
+ {
1435
+ type: "button",
1436
+ className: oe ? "active" : "",
1437
+ onClick: () => ce((u) => !u),
1089
1438
  title: "Document Assistant — instruct an agent to restructure/import/link chunks",
1090
1439
  children: "assistant"
1091
1440
  }
1092
1441
  ),
1093
- /* @__PURE__ */ n("button", { type: "button", onClick: _, title: "Reload", children: "↻" })
1442
+ /* @__PURE__ */ t("button", { type: "button", onClick: z, title: "Reload", children: "↻" })
1094
1443
  ] })
1095
1444
  ] }),
1096
- Q && /* @__PURE__ */ n("div", { className: "paths-err", children: Q }),
1445
+ b && /* @__PURE__ */ t("div", { className: "paths-err", children: b }),
1097
1446
  /* @__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,
1447
+ /* @__PURE__ */ t("div", { className: "doc-chunktree", children: w && d.length === 0 ? /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Loading…" }) }) : /* @__PURE__ */ t(
1448
+ yt,
1100
1449
  {
1101
- tree: V,
1450
+ tree: he,
1102
1451
  selectedId: m,
1103
- onSelect: We,
1104
- colorEnabled: oe,
1105
- scheme: H?.color_scheme,
1106
- linkedIds: Be
1452
+ onSelect: Je,
1453
+ colorEnabled: se,
1454
+ scheme: Z?.color_scheme,
1455
+ linkedIds: Ve
1107
1456
  }
1108
1457
  ) }),
1109
- /* @__PURE__ */ n("div", { className: "doc-content", children: p ? /* @__PURE__ */ l(q, { children: [
1458
+ /* @__PURE__ */ t("div", { className: "doc-content", children: h ? /* @__PURE__ */ l(Y, { children: [
1110
1459
  /* @__PURE__ */ l("div", { className: "doc-content-head", children: [
1111
- /* @__PURE__ */ n("h3", { children: p.title || "(untitled)" }),
1460
+ /* @__PURE__ */ t("h3", { children: h.title || "(untitled)" }),
1112
1461
  /* @__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 }),
1462
+ h.type && /* @__PURE__ */ t("span", { className: "chunk-badge", children: h.type }),
1463
+ h.status && /* @__PURE__ */ t("span", { className: "chunk-badge chunk-status", children: h.status }),
1115
1464
  /* @__PURE__ */ l("span", { className: "chunk-rev", children: [
1116
1465
  "rev ",
1117
- p.revision
1118
- ] })
1466
+ h.revision
1467
+ ] }),
1468
+ h.tags?.map((u) => /* @__PURE__ */ t("span", { className: "chunk-tag", children: u }, u))
1119
1469
  ] }),
1120
1470
  /* @__PURE__ */ l("div", { className: "doc-content-controls", children: [
1121
1471
  /* @__PURE__ */ l("div", { className: "doc-mode-toggle", children: [
1122
- /* @__PURE__ */ n(
1472
+ /* @__PURE__ */ t(
1123
1473
  "button",
1124
1474
  {
1125
1475
  type: "button",
1126
- className: N === "chunks" ? "active" : "",
1127
- onClick: () => T("chunks"),
1476
+ className: C === "chunks" ? "active" : "",
1477
+ onClick: () => L("chunks"),
1128
1478
  title: "This chunk's own content",
1129
1479
  children: "chunk"
1130
1480
  }
1131
1481
  ),
1132
- /* @__PURE__ */ n(
1482
+ /* @__PURE__ */ t(
1133
1483
  "button",
1134
1484
  {
1135
1485
  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",
1486
+ className: C === "markdown" ? "active" : "",
1487
+ onClick: () => L("markdown"),
1488
+ title: te ? "Whole document as Markdown" : "This chunk + its sub-chunks as Markdown",
1139
1489
  children: "markdown"
1140
1490
  }
1141
1491
  )
1142
1492
  ] }),
1143
- /* @__PURE__ */ n("button", { type: "button", onClick: () => C(p), children: "edit" }),
1144
- !K && /* @__PURE__ */ l(q, { children: [
1145
- /* @__PURE__ */ n(
1493
+ /* @__PURE__ */ t("button", { type: "button", onClick: () => y(h), children: "edit" }),
1494
+ /* @__PURE__ */ t(
1495
+ "button",
1496
+ {
1497
+ type: "button",
1498
+ onClick: () => J(!0),
1499
+ title: "View this chunk's edit history + diffs",
1500
+ children: "history"
1501
+ }
1502
+ ),
1503
+ !te && /* @__PURE__ */ l(Y, { children: [
1504
+ /* @__PURE__ */ t(
1146
1505
  "button",
1147
1506
  {
1148
1507
  type: "button",
1149
1508
  onClick: () => {
1150
- ve("up");
1509
+ Ce("up");
1151
1510
  },
1152
- disabled: !ke.canUp,
1511
+ disabled: !we.canUp,
1153
1512
  title: "Move this chunk up within its level",
1154
1513
  children: "↑"
1155
1514
  }
1156
1515
  ),
1157
- /* @__PURE__ */ n(
1516
+ /* @__PURE__ */ t(
1158
1517
  "button",
1159
1518
  {
1160
1519
  type: "button",
1161
1520
  onClick: () => {
1162
- ve("down");
1521
+ Ce("down");
1163
1522
  },
1164
- disabled: !ke.canDown,
1523
+ disabled: !we.canDown,
1165
1524
  title: "Move this chunk down within its level",
1166
1525
  children: "↓"
1167
1526
  }
1168
1527
  )
1169
1528
  ] }),
1170
- !K && /* @__PURE__ */ n(
1529
+ !te && /* @__PURE__ */ t(
1171
1530
  "button",
1172
1531
  {
1173
1532
  type: "button",
1174
1533
  className: "danger",
1175
- onClick: () => J(!0),
1534
+ onClick: () => N(!0),
1176
1535
  title: "Delete this chunk and its sub-chunks",
1177
1536
  children: "delete"
1178
1537
  }
1179
1538
  )
1180
1539
  ] })
1181
1540
  ] }),
1182
- /* @__PURE__ */ n("div", { className: "doc-content-body", children: p.type === "mermaid" ? (
1541
+ /* @__PURE__ */ t("div", { className: "doc-content-body", children: h.type === "mermaid" ? (
1183
1542
  // 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 ? (
1543
+ h.body ? /* @__PURE__ */ l(Y, { children: [
1544
+ /* @__PURE__ */ t(ue, { code: h.body }),
1545
+ C === "markdown" && /* @__PURE__ */ t("pre", { className: "md-pre doc-mermaid-source", children: /* @__PURE__ */ t("code", { children: h.body }) })
1546
+ ] }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "(empty diagram)" })
1547
+ ) : h.type === "image" || h.asset ? (
1189
1548
  // RFC BO — an image chunk: bytes come from the auth'd asset GET.
1190
- z ? /* @__PURE__ */ l("p", { className: "doc-empty-body", children: [
1549
+ I ? /* @__PURE__ */ l("p", { className: "doc-empty-body", children: [
1191
1550
  "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,
1551
+ I
1552
+ ] }) : A ? /* @__PURE__ */ l("figure", { className: "doc-image", children: [
1553
+ /* @__PURE__ */ t("img", { src: A, alt: Pt(h) }),
1554
+ h.body && /* @__PURE__ */ t("figcaption", { children: h.body })
1555
+ ] }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "Loading image…" })
1556
+ ) : C === "markdown" ? F !== null ? /* @__PURE__ */ t(Me, { source: F }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "Assembling Markdown…" }) : h.body ? /* @__PURE__ */ t(Me, { source: h.body }) : /* @__PURE__ */ t("p", { className: "doc-empty-body", children: "(empty chunk)" }) }),
1557
+ /* @__PURE__ */ t(
1558
+ xt,
1200
1559
  {
1201
- edges: w,
1560
+ edges: W,
1202
1561
  documentId: e,
1203
1562
  selectedId: m,
1204
- onSelectChunk: b
1563
+ onSelectChunk: k
1564
+ }
1565
+ ),
1566
+ /* @__PURE__ */ t(
1567
+ Et,
1568
+ {
1569
+ documentId: e,
1570
+ selectedId: m,
1571
+ scope: r,
1572
+ browse: s,
1573
+ onSelectChunk: k
1205
1574
  }
1206
1575
  )
1207
- ] }) : /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "Select a chunk on the left." }) }) })
1576
+ ] }) : /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Select a chunk on the left." }) }) })
1208
1577
  ] }),
1209
- Y && s && /* @__PURE__ */ n("div", { className: "doc-assistant", children: s({
1578
+ oe && i && /* @__PURE__ */ t("div", { className: "doc-assistant", children: i({
1210
1579
  documentId: e,
1211
- scope: a,
1580
+ scope: r,
1212
1581
  subject: o?.subject,
1213
1582
  // Pass the viewer's own reload so the injected assistant can refresh
1214
1583
  // the tree + selected chunk after a turn mutates the document.
1215
- onChanged: _
1584
+ onChanged: z
1216
1585
  }) }),
1217
- x && /* @__PURE__ */ n(
1218
- gt,
1586
+ R && /* @__PURE__ */ t(
1587
+ kt,
1219
1588
  {
1220
- chunk: x,
1221
- scope: a,
1222
- browse: i,
1223
- onClose: () => C(null),
1224
- onSaved: _
1589
+ chunk: R,
1590
+ scope: r,
1591
+ browse: s,
1592
+ onClose: () => y(null),
1593
+ onSaved: z
1225
1594
  }
1226
1595
  ),
1227
- te && Z && /* @__PURE__ */ n(
1228
- bt,
1596
+ D && h && /* @__PURE__ */ t(
1597
+ $t,
1598
+ {
1599
+ chunkId: h.id,
1600
+ chunkTitle: h.title,
1601
+ scope: r,
1602
+ browse: s,
1603
+ onClose: () => J(!1)
1604
+ }
1605
+ ),
1606
+ x && X && /* @__PURE__ */ t(
1607
+ wt,
1229
1608
  {
1230
1609
  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: _
1610
+ rootChunkId: X,
1611
+ docType: Z?.type,
1612
+ docStatus: Z?.status,
1613
+ chunkStatuses: We,
1614
+ scope: r,
1615
+ browse: s,
1616
+ onClose: () => H(!1),
1617
+ onSaved: z
1239
1618
  }
1240
1619
  ),
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" }),
1620
+ V && h && /* @__PURE__ */ t("div", { className: "modal-overlay", onClick: () => N(!1), children: /* @__PURE__ */ l("div", { className: "modal chunk-delete-confirm", onClick: (u) => u.stopPropagation(), children: [
1621
+ /* @__PURE__ */ t("h3", { children: "Delete chunk" }),
1243
1622
  /* @__PURE__ */ l("p", { className: "modal-context", children: [
1244
1623
  "Delete “",
1245
- p.title || "(untitled)",
1624
+ h.title || "(untitled)",
1246
1625
  "” and all of its sub-chunks? This cannot be undone."
1247
1626
  ] }),
1248
1627
  /* @__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();
1628
+ /* @__PURE__ */ t("button", { type: "button", onClick: () => N(!1), children: "cancel" }),
1629
+ /* @__PURE__ */ t("button", { type: "button", className: "danger", onClick: () => {
1630
+ Ye();
1252
1631
  }, children: "delete" })
1253
1632
  ] })
1254
1633
  ] }) })
1255
1634
  ] });
1256
1635
  }
1257
- function _t(e) {
1258
- const a = {
1636
+ function At(e) {
1637
+ const r = {
1259
1638
  name: "",
1260
1639
  fullPath: "",
1261
1640
  kind: "directory",
1262
1641
  explicit: !0,
1263
1642
  children: []
1264
- }, t = /* @__PURE__ */ new Map([["", a]]), r = (s) => {
1265
- const c = t.get(s);
1643
+ }, n = /* @__PURE__ */ new Map([["", r]]), a = (i) => {
1644
+ const c = n.get(i);
1266
1645
  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 = {
1646
+ const s = i.lastIndexOf("/"), d = s <= 0 ? "" : i.slice(0, s), g = i.slice(s + 1), m = a(d), k = {
1268
1647
  name: g,
1269
- fullPath: s,
1648
+ fullPath: i,
1270
1649
  kind: "directory",
1271
1650
  explicit: !1,
1272
1651
  children: []
1273
1652
  };
1274
- return m.children.push(b), t.set(s, b), b;
1653
+ return m.children.push(k), n.set(i, k), k;
1275
1654
  };
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;
1655
+ for (const i of e) {
1656
+ const c = a(i.full_path);
1657
+ c.kind = i.kind, c.explicit = !0, c.resourceRef = i.resource_ref;
1279
1658
  }
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));
1659
+ const o = (i) => {
1660
+ i.sort((c, s) => {
1661
+ const d = c.kind === "directory", g = s.kind === "directory";
1662
+ return d !== g ? d ? -1 : 1 : c.name.localeCompare(s.name);
1663
+ }), i.forEach((c) => o(c.children));
1285
1664
  };
1286
- return o(a.children), a.children;
1665
+ return o(r.children), r.children;
1287
1666
  }
1288
- function ge(e) {
1289
- const a = e.lastIndexOf("/");
1290
- return a <= 0 ? "" : e.slice(0, a);
1667
+ function ve(e) {
1668
+ const r = e.lastIndexOf("/");
1669
+ return r <= 0 ? "" : e.slice(0, r);
1291
1670
  }
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);
1671
+ function Ut(e) {
1672
+ const r = [], n = (a) => {
1673
+ if (a.kind === "document") {
1674
+ const o = a.resourceRef;
1675
+ o?.document_id && r.push(o.document_id);
1297
1676
  }
1298
- r.children.forEach(t);
1677
+ a.children.forEach(n);
1299
1678
  };
1300
- return t(e), a;
1679
+ return n(e), r;
1301
1680
  }
1302
- const Et = {
1681
+ const Ot = {
1303
1682
  directory: "📁",
1304
1683
  document: "📄",
1305
1684
  volume_mount: "💾",
1306
1685
  memory_entry: "🧠"
1307
1686
  };
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) => {
1687
+ function It({ tree: e, selectedPath: r, onSelect: n, summaries: a }) {
1688
+ const [o, i] = f(() => /* @__PURE__ */ new Map()), c = j((s) => {
1689
+ i((d) => {
1311
1690
  const g = new Map(d);
1312
- return g.set(i, d.get(i) === !1), g;
1691
+ return g.set(s, d.get(s) === !1), g;
1313
1692
  });
1314
1693
  }, []);
1315
- return U(() => {
1316
- a && s((i) => {
1694
+ return B(() => {
1695
+ r && i((s) => {
1317
1696
  let d = !1;
1318
- const g = new Map(i);
1319
- let m = ge(a);
1697
+ const g = new Map(s);
1698
+ let m = ve(r);
1320
1699
  for (; m !== ""; )
1321
- g.get(m) === !1 && (g.set(m, !0), d = !0), m = ge(m);
1322
- return d ? g : i;
1700
+ g.get(m) === !1 && (g.set(m, !0), d = !0), m = ve(m);
1701
+ return d ? g : s;
1323
1702
  });
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,
1703
+ }, [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(
1704
+ Ge,
1326
1705
  {
1327
- node: i,
1706
+ node: s,
1328
1707
  expanded: o,
1329
1708
  toggle: c,
1330
- selectedPath: a,
1331
- onSelect: t,
1332
- summaries: r
1709
+ selectedPath: r,
1710
+ onSelect: n,
1711
+ summaries: a
1333
1712
  },
1334
- i.fullPath
1713
+ s.fullPath
1335
1714
  )) });
1336
1715
  }
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;
1716
+ function jt(e, r) {
1717
+ if (e.kind !== "document" || !r) return;
1718
+ const n = e.resourceRef;
1719
+ return n?.document_id ? r.get(n.document_id) : void 0;
1341
1720
  }
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;
1721
+ function Ge({ node: e, expanded: r, toggle: n, selectedPath: a, onSelect: o, summaries: i }) {
1722
+ const c = e.children.length > 0, s = r.get(e.fullPath) !== !1, d = a === e.fullPath, g = jt(e, i), m = g && g.color_enabled ? Ne(Ie(g.type, g.status, ke(g.color_scheme))) : void 0;
1344
1723
  return /* @__PURE__ */ l("li", { className: `node path-node kind-${e.kind} ${d ? "selected" : ""}`, children: [
1345
1724
  /* @__PURE__ */ l("div", { className: "row path-row", style: m, children: [
1346
- /* @__PURE__ */ n(
1725
+ /* @__PURE__ */ t(
1347
1726
  "button",
1348
1727
  {
1349
1728
  type: "button",
1350
1729
  className: "tree-caret",
1351
- "aria-label": i ? "collapse" : "expand",
1730
+ "aria-label": s ? "collapse" : "expand",
1352
1731
  disabled: !c,
1353
- onClick: (b) => {
1354
- b.stopPropagation(), c && t(e.fullPath);
1732
+ onClick: (k) => {
1733
+ k.stopPropagation(), c && n(e.fullPath);
1355
1734
  },
1356
- children: c ? i ? "▼" : "▶" : "·"
1735
+ children: c ? s ? "▼" : "▶" : "·"
1357
1736
  }
1358
1737
  ),
1359
1738
  /* @__PURE__ */ l(
@@ -1364,189 +1743,189 @@ function je({ node: e, expanded: a, toggle: t, selectedPath: r, onSelect: o, sum
1364
1743
  onClick: () => o(e),
1365
1744
  title: e.fullPath,
1366
1745
  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" })
1746
+ /* @__PURE__ */ t("span", { className: "path-kind-icon", "aria-hidden": !0, children: Ot[e.kind] ?? "•" }),
1747
+ /* @__PURE__ */ t("span", { className: "path-name", children: e.name }),
1748
+ g?.type && /* @__PURE__ */ t("span", { className: "chunk-badge", children: g.type }),
1749
+ g?.status && /* @__PURE__ */ t("span", { className: "chunk-badge chunk-status", children: g.status }),
1750
+ !e.explicit && /* @__PURE__ */ t("span", { className: "path-implicit", title: "Implicit directory (no stored entry)", children: "implicit" })
1372
1751
  ]
1373
1752
  }
1374
1753
  )
1375
1754
  ] }),
1376
- c && i && /* @__PURE__ */ n("ul", { className: "children path-children", children: e.children.map((b) => /* @__PURE__ */ n(
1377
- je,
1755
+ c && s && /* @__PURE__ */ t("ul", { className: "children path-children", children: e.children.map((k) => /* @__PURE__ */ t(
1756
+ Ge,
1378
1757
  {
1379
- node: b,
1380
- expanded: a,
1381
- toggle: t,
1382
- selectedPath: r,
1758
+ node: k,
1759
+ expanded: r,
1760
+ toggle: n,
1761
+ selectedPath: a,
1383
1762
  onSelect: o,
1384
- summaries: s
1763
+ summaries: i
1385
1764
  },
1386
- b.fullPath
1765
+ k.fullPath
1387
1766
  )) })
1388
1767
  ] });
1389
1768
  }
1390
- const De = /^[A-Za-z0-9._-]+$/;
1391
- function $e(e, a) {
1392
- return `${e}/${a}`;
1769
+ const $e = /^[A-Za-z0-9._-]+$/;
1770
+ function Le(e, r) {
1771
+ return `${e}/${r}`;
1393
1772
  }
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;
1773
+ function He(e, r) {
1774
+ for (const n of e) {
1775
+ if (n.fullPath === r) return n;
1776
+ const a = He(n.children, r);
1777
+ if (a) return a;
1399
1778
  }
1400
1779
  }
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,
1780
+ function Jt(e) {
1781
+ const { theme: r, defaultScope: n, path: a, onPathChange: o, browse: i, principal: c, renderAssistant: s, onError: d } = e, g = Pe(e);
1782
+ return /* @__PURE__ */ t(Ae, { theme: r, dataLayer: g, children: /* @__PURE__ */ t(
1783
+ Bt,
1405
1784
  {
1406
- defaultScope: t,
1407
- path: r,
1785
+ defaultScope: n,
1786
+ path: a,
1408
1787
  onPathChange: o,
1409
- browse: s,
1788
+ browse: i,
1410
1789
  principal: c,
1411
- renderAssistant: i,
1790
+ renderAssistant: s,
1412
1791
  onError: d
1413
1792
  }
1414
1793
  ) });
1415
1794
  }
1416
- function $t({
1795
+ function Bt({
1417
1796
  defaultScope: e,
1418
- path: a,
1419
- onPathChange: t,
1420
- browse: r,
1797
+ path: r,
1798
+ onPathChange: n,
1799
+ browse: a,
1421
1800
  principal: o,
1422
- renderAssistant: s,
1801
+ renderAssistant: i,
1423
1802
  onError: c
1424
1803
  }) {
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;
1804
+ const s = ae(), [d, g] = f(e ?? "user"), [m, k] = f([]), [h, P] = f(void 0), [C, L] = f(null), [F, O] = f(!1), [A, M] = f(null), I = r !== void 0 ? r : h, $ = ne(n);
1805
+ B(() => {
1806
+ $.current = n;
1807
+ }, [n]);
1808
+ const G = ne(c);
1809
+ B(() => {
1810
+ G.current = c;
1432
1811
  }, [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);
1812
+ const R = j((x) => {
1813
+ $.current?.(x), P(x);
1814
+ }, []), y = q(
1815
+ () => a && (a.scopeId || a.tenant) ? { scopeId: a.scopeId, tenant: a.tenant } : void 0,
1816
+ [a?.scopeId, a?.tenant]
1817
+ ), D = j(async () => {
1818
+ O(!0), L(null);
1440
1819
  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);
1820
+ const x = await s.pathLs("/", d, !0, y);
1821
+ k(x.entries ?? []);
1822
+ } catch (x) {
1823
+ L(x instanceof Error ? x.message : String(x)), k([]), G.current?.(x);
1445
1824
  } finally {
1446
- P(!1);
1825
+ O(!1);
1447
1826
  }
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(() => {
1827
+ }, [s, d, y]), J = ne(!0);
1828
+ B(() => {
1829
+ J.current ? J.current = !1 : R(void 0), D();
1830
+ }, [D, R]);
1831
+ const V = q(() => At(m), [m]), [N, b] = f(() => /* @__PURE__ */ new Map());
1832
+ B(() => {
1454
1833
  if (d === "tenant") {
1455
- h(/* @__PURE__ */ new Map());
1834
+ b(/* @__PURE__ */ new Map());
1456
1835
  return;
1457
1836
  }
1458
- const w = m.filter((_) => _.kind === "document").map((_) => _.resource_ref?.document_id).filter((_) => !!_);
1459
- if (w.length === 0) {
1460
- h(/* @__PURE__ */ new Map());
1837
+ const x = m.filter((W) => W.kind === "document").map((W) => W.resource_ref?.document_id).filter((W) => !!W);
1838
+ if (x.length === 0) {
1839
+ b(/* @__PURE__ */ new Map());
1461
1840
  return;
1462
1841
  }
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);
1842
+ let H = !1;
1843
+ return s.documentsSummary({ documentIds: x }, d, y).then((W) => {
1844
+ if (H) return;
1845
+ const Q = /* @__PURE__ */ new Map();
1846
+ for (const z of W.documents ?? []) Q.set(z.document_id, z);
1847
+ b(Q);
1469
1848
  }).catch(() => {
1470
- L || h(/* @__PURE__ */ new Map());
1849
+ H || b(/* @__PURE__ */ new Map());
1471
1850
  }), () => {
1472
- L = !0;
1851
+ H = !0;
1473
1852
  };
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}`,
1853
+ }, [s, m, d, y]);
1854
+ const p = q(
1855
+ () => I ? He(V, I) : void 0,
1856
+ [V, I]
1857
+ ), w = q(() => p ? p.kind === "directory" ? p.fullPath : ve(p.fullPath) : "", [p]), S = w || "/", T = d !== "tenant", ee = j(() => {
1858
+ M({
1859
+ title: `New folder in ${S}`,
1481
1860
  fields: [{ key: "name", label: "Folder name", placeholder: "e.g. launches" }],
1482
1861
  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(_);
1862
+ onSubmit: async (x) => {
1863
+ const H = x.name.trim();
1864
+ if (!$e.test(H)) throw new Error("name may contain only [A-Za-z0-9._-]");
1865
+ const W = Le(w, H);
1866
+ await s.pathMkdir(W, d, y), await D(), R(W);
1488
1867
  }
1489
1868
  });
1490
- }, [i, E, D, d, C, I, x]), H = A(() => {
1491
- R({
1492
- title: `New document in ${D}`,
1869
+ }, [s, w, S, d, y, D, R]), oe = j(() => {
1870
+ M({
1871
+ title: `New document in ${S}`,
1493
1872
  fields: [
1494
1873
  { key: "name", label: "Path name", placeholder: "e.g. launch-plan" },
1495
1874
  { key: "title", label: "Title", placeholder: "e.g. Launch Plan" }
1496
1875
  ],
1497
1876
  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);
1877
+ onSubmit: async (x) => {
1878
+ const H = x.name.trim();
1879
+ if (!$e.test(H)) throw new Error("name may contain only [A-Za-z0-9._-]");
1880
+ const W = x.title.trim() || H, Q = Le(w, H);
1881
+ await s.documentCreate(W, Q, d, y), await D(), R(Q);
1503
1882
  }
1504
1883
  });
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 }],
1884
+ }, [s, w, S, d, y, D, R]), ce = j(() => {
1885
+ p && M({
1886
+ title: `Rename / move ${p.fullPath}`,
1887
+ fields: [{ key: "to", label: "New path", value: p.fullPath }],
1509
1888
  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);
1889
+ onSubmit: async (x) => {
1890
+ const H = x.to.trim();
1891
+ if (!H.startsWith("/")) throw new Error("path must start with /");
1892
+ await s.pathMv(p.fullPath, H, d, y), await D(), R(H);
1514
1893
  }
1515
1894
  });
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}`,
1895
+ }, [s, p, d, y, D, R]), Z = j(() => {
1896
+ if (!p) return;
1897
+ if (p.kind === "document") {
1898
+ const Q = p.resourceRef?.document_id;
1899
+ M({
1900
+ title: `Delete document ${p.fullPath}`,
1522
1901
  message: "This deletes the document, all its chunks, and its path entry. This cannot be undone.",
1523
1902
  fields: [],
1524
1903
  submitLabel: "Delete",
1525
1904
  danger: !0,
1526
1905
  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);
1906
+ if (!Q) throw new Error("this document dirent has no document_id");
1907
+ await s.documentDelete(Q, d, y), await D(), R(void 0);
1529
1908
  }
1530
1909
  });
1531
1910
  return;
1532
1911
  }
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.` : "."),
1912
+ const x = d === "tenant" ? [] : Ut(p), H = p.children.length;
1913
+ M({
1914
+ title: `Delete branch ${p.fullPath}`,
1915
+ 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
1916
  fields: [],
1538
1917
  submitLabel: "Delete",
1539
1918
  danger: !0,
1540
1919
  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);
1920
+ for (const W of x)
1921
+ await s.documentDelete(W, d, y);
1922
+ await s.pathRm(p.fullPath, d, !0, y), await D(), R(void 0);
1544
1923
  }
1545
1924
  });
1546
- }, [i, f, d, C, I, x]), re = f && (f.kind === "directory" || f.kind === "document");
1547
- return /* @__PURE__ */ l(q, { children: [
1925
+ }, [s, p, d, y, D, R]), re = p && (p.kind === "directory" || p.kind === "document");
1926
+ return /* @__PURE__ */ l(Y, { children: [
1548
1927
  /* @__PURE__ */ l(
1549
- ct,
1928
+ dt,
1550
1929
  {
1551
1930
  className: "paths-view",
1552
1931
  defaultLeftWidth: 420,
@@ -1557,161 +1936,161 @@ function $t({
1557
1936
  /* @__PURE__ */ l("div", { className: "left", children: [
1558
1937
  /* @__PURE__ */ l("div", { className: "paths-toolbar", children: [
1559
1938
  /* @__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" })
1939
+ /* @__PURE__ */ t("span", { children: "scope" }),
1940
+ /* @__PURE__ */ l("select", { value: d, onChange: (x) => g(x.target.value), children: [
1941
+ /* @__PURE__ */ t("option", { value: "user", children: "user" }),
1942
+ /* @__PURE__ */ t("option", { value: "agent", children: "agent" }),
1943
+ /* @__PURE__ */ t("option", { value: "tenant", children: "tenant" })
1565
1944
  ] })
1566
1945
  ] }),
1567
1946
  /* @__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(
1947
+ /* @__PURE__ */ t("button", { type: "button", onClick: ee, title: `New folder in ${S}`, children: "+ folder" }),
1948
+ /* @__PURE__ */ t(
1570
1949
  "button",
1571
1950
  {
1572
1951
  type: "button",
1573
- onClick: H,
1574
- disabled: !Y,
1575
- title: Y ? `New document in ${D}` : "Documents are agent/user scope only",
1952
+ onClick: oe,
1953
+ disabled: !T,
1954
+ title: T ? `New document in ${S}` : "Documents are agent/user scope only",
1576
1955
  children: "+ document"
1577
1956
  }
1578
1957
  ),
1579
- /* @__PURE__ */ n("button", { type: "button", onClick: () => {
1580
- I();
1958
+ /* @__PURE__ */ t("button", { type: "button", onClick: () => {
1959
+ D();
1581
1960
  }, title: "Reload the tree", children: "↻" })
1582
1961
  ] })
1583
1962
  ] }),
1584
1963
  /* @__PURE__ */ l("p", { className: "paths-context", children: [
1585
1964
  "new items → ",
1586
- /* @__PURE__ */ n("code", { children: D }),
1587
- C?.scopeId && /* @__PURE__ */ l(q, { children: [
1965
+ /* @__PURE__ */ t("code", { children: S }),
1966
+ y?.scopeId && /* @__PURE__ */ l(Y, { children: [
1588
1967
  " · ",
1589
1968
  "subject ",
1590
- /* @__PURE__ */ n("code", { children: C.scopeId })
1969
+ /* @__PURE__ */ t("code", { children: y.scopeId })
1591
1970
  ] }),
1592
- C?.tenant && /* @__PURE__ */ l(q, { children: [
1971
+ y?.tenant && /* @__PURE__ */ l(Y, { children: [
1593
1972
  " · ",
1594
1973
  "tenant ",
1595
- /* @__PURE__ */ n("code", { children: C.tenant })
1974
+ /* @__PURE__ */ t("code", { children: y.tenant })
1596
1975
  ] })
1597
1976
  ] }),
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,
1977
+ C && /* @__PURE__ */ t("div", { className: "paths-err", children: C }),
1978
+ F && m.length === 0 ? /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Loading…" }) }) : /* @__PURE__ */ t(
1979
+ It,
1601
1980
  {
1602
- tree: Q,
1603
- selectedPath: z,
1604
- onSelect: (w) => x(w.fullPath),
1605
- summaries: M
1981
+ tree: V,
1982
+ selectedPath: I,
1983
+ onSelect: (x) => R(x.fullPath),
1984
+ summaries: N
1606
1985
  }
1607
1986
  )
1608
1987
  ] }),
1609
- /* @__PURE__ */ n("div", { className: "right", children: f ? f.kind === "document" ? /* @__PURE__ */ l("div", { className: "paths-doc", children: [
1988
+ /* @__PURE__ */ t("div", { className: "right", children: p ? p.kind === "document" ? /* @__PURE__ */ l("div", { className: "paths-doc", children: [
1610
1989
  /* @__PURE__ */ l("div", { className: "paths-doc-head", children: [
1611
- /* @__PURE__ */ n("code", { className: "paths-doc-path", children: f.fullPath }),
1990
+ /* @__PURE__ */ t("code", { className: "paths-doc-path", children: p.fullPath }),
1612
1991
  /* @__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" })
1992
+ /* @__PURE__ */ t("button", { type: "button", onClick: ce, children: "rename / move" }),
1993
+ /* @__PURE__ */ t("button", { type: "button", className: "danger", onClick: Z, children: "delete" })
1615
1994
  ] })
1616
1995
  ] }),
1617
- /* @__PURE__ */ n(
1618
- Oe,
1996
+ /* @__PURE__ */ t(
1997
+ Fe,
1619
1998
  {
1620
- documentId: f.resourceRef?.document_id ?? "",
1621
- scope: d === "agent" ? "agent" : "user",
1622
- titleHint: f.name,
1623
- browse: C,
1999
+ documentId: p.resourceRef?.document_id ?? "",
2000
+ scope: d,
2001
+ titleHint: p.name,
2002
+ browse: y,
1624
2003
  principal: o,
1625
- renderAssistant: s
2004
+ renderAssistant: i
1626
2005
  }
1627
2006
  )
1628
2007
  ] }) : /* @__PURE__ */ l("div", { className: "paths-detail", children: [
1629
2008
  /* @__PURE__ */ l("h2", { children: [
1630
- /* @__PURE__ */ n("span", { className: "paths-detail-kind", children: f.kind }),
1631
- /* @__PURE__ */ n("code", { children: f.fullPath })
2009
+ /* @__PURE__ */ t("span", { className: "paths-detail-kind", children: p.kind }),
2010
+ /* @__PURE__ */ t("code", { children: p.fullPath })
1632
2011
  ] }),
1633
2012
  /* @__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)" })
2013
+ /* @__PURE__ */ t("dt", { children: "scope" }),
2014
+ /* @__PURE__ */ t("dd", { children: d }),
2015
+ /* @__PURE__ */ t("dt", { children: "stored" }),
2016
+ /* @__PURE__ */ t("dd", { children: p.explicit ? "yes" : "implicit (no entry)" })
1638
2017
  ] }),
1639
2018
  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" })
2019
+ /* @__PURE__ */ t("button", { type: "button", onClick: ce, children: "rename / move" }),
2020
+ /* @__PURE__ */ t("button", { type: "button", className: "danger", onClick: Z, children: "delete" })
1642
2021
  ] }) : /* @__PURE__ */ l("p", { className: "paths-readonly", children: [
1643
2022
  "Read-only — ",
1644
- f.kind,
2023
+ p.kind,
1645
2024
  " entries are managed by their own tool."
1646
2025
  ] })
1647
- ] }) : /* @__PURE__ */ n("div", { className: "empty", children: /* @__PURE__ */ n("p", { children: "Select a path on the left, or create a folder / document." }) }) })
2026
+ ] }) : /* @__PURE__ */ t("div", { className: "empty", children: /* @__PURE__ */ t("p", { children: "Select a path on the left, or create a folder / document." }) }) })
1648
2027
  ]
1649
2028
  }
1650
2029
  ),
1651
- W && /* @__PURE__ */ n(Mt, { state: W, onClose: () => R(null) })
2030
+ A && /* @__PURE__ */ t(Ft, { state: A, onClose: () => M(null) })
1652
2031
  ] });
1653
2032
  }
1654
- function Mt({ state: e, onClose: a }) {
1655
- const [t, r] = k(
2033
+ function Ft({ state: e, onClose: r }) {
2034
+ const [n, a] = f(
1656
2035
  () => 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);
2036
+ ), [o, i] = f(!1), [c, s] = f(null);
2037
+ return /* @__PURE__ */ t("div", { className: "modal-overlay", onClick: r, children: /* @__PURE__ */ l("form", { className: "modal", onClick: (g) => g.stopPropagation(), onSubmit: async (g) => {
2038
+ g.preventDefault(), i(!0), s(null);
1660
2039
  try {
1661
- await e.onSubmit(t), a();
2040
+ await e.onSubmit(n), r();
1662
2041
  } catch (m) {
1663
- i(m instanceof Error ? m.message : String(m)), s(!1);
2042
+ s(m instanceof Error ? m.message : String(m)), i(!1);
1664
2043
  }
1665
2044
  }, children: [
1666
2045
  /* @__PURE__ */ l("div", { className: "modal-header sticky-top", children: [
1667
- /* @__PURE__ */ n("h3", { children: e.title }),
2046
+ /* @__PURE__ */ t("h3", { children: e.title }),
1668
2047
  /* @__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 })
2048
+ /* @__PURE__ */ t("button", { type: "button", onClick: r, disabled: o, children: "cancel" }),
2049
+ /* @__PURE__ */ t("button", { type: "submit", className: e.danger ? "danger" : "primary", disabled: o, children: o ? "working…" : e.submitLabel })
1671
2050
  ] })
1672
2051
  ] }),
1673
- e.message && /* @__PURE__ */ n("p", { className: "modal-context", children: e.message }),
2052
+ e.message && /* @__PURE__ */ t("p", { className: "modal-context", children: e.message }),
1674
2053
  e.fields.map((g, m) => /* @__PURE__ */ l("label", { className: "path-field", children: [
1675
- /* @__PURE__ */ n("span", { children: g.label }),
1676
- /* @__PURE__ */ n(
2054
+ /* @__PURE__ */ t("span", { children: g.label }),
2055
+ /* @__PURE__ */ t(
1677
2056
  "input",
1678
2057
  {
1679
2058
  className: "path-modal-input",
1680
- value: t[g.key],
2059
+ value: n[g.key],
1681
2060
  placeholder: g.placeholder,
1682
2061
  autoFocus: m === 0,
1683
- onChange: (b) => r((p) => ({ ...p, [g.key]: b.target.value }))
2062
+ onChange: (k) => a((h) => ({ ...h, [g.key]: k.target.value }))
1684
2063
  }
1685
2064
  )
1686
2065
  ] }, g.key)),
1687
- c && /* @__PURE__ */ n("div", { className: "modal-err", children: c })
2066
+ c && /* @__PURE__ */ t("div", { className: "modal-err", children: c })
1688
2067
  ] }) });
1689
2068
  }
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,
2069
+ function Zt(e) {
2070
+ const { documentId: r, scope: n, titleHint: a, browse: o, theme: i, principal: c, renderAssistant: s } = e, d = Pe(e);
2071
+ return /* @__PURE__ */ t(Ae, { theme: i, dataLayer: d, children: /* @__PURE__ */ t(
2072
+ Fe,
1694
2073
  {
1695
- documentId: a,
1696
- scope: t,
1697
- titleHint: r,
2074
+ documentId: r,
2075
+ scope: n,
2076
+ titleHint: a,
1698
2077
  browse: o,
1699
2078
  principal: c,
1700
- renderAssistant: i
2079
+ renderAssistant: s
1701
2080
  }
1702
2081
  ) });
1703
2082
  }
1704
2083
  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
2084
+ be as DEFAULT_SCHEME,
2085
+ Zt as DocumentViewer,
2086
+ Jt as PathExplorer,
2087
+ lt as assetFetchFromConnection,
2088
+ pt as chunkColor,
2089
+ st as createLoomcycleClient,
2090
+ _e as dataLayerFromClient,
2091
+ Ie as docColor,
2092
+ ke as effectiveScheme,
2093
+ ft as hexToTint,
2094
+ Ne as tintStyle
1716
2095
  };
1717
2096
  //# sourceMappingURL=index.js.map