@hollis-labs/surface-page 0.2.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/chunks/chunk-LODRWYOW.js +2060 -0
  2. package/dist/gallery.js +491 -310
  3. package/dist/index.js +385 -387
  4. package/dist/registry-items.json +3 -0
  5. package/dist/sdk.js +13 -1
  6. package/dist/types/agent/api.d.ts +34 -2
  7. package/dist/types/agent/session.d.ts +2 -5
  8. package/dist/types/cards/store.d.ts +13 -1
  9. package/dist/types/cards/views.d.ts +3 -2
  10. package/dist/types/cite/core/detect.d.ts +26 -0
  11. package/dist/types/cite/core/index.d.ts +17 -0
  12. package/dist/types/cite/core/kinds/caster.d.ts +3 -0
  13. package/dist/types/cite/core/kinds/fragment.d.ts +3 -0
  14. package/dist/types/cite/core/kinds/ops.d.ts +3 -0
  15. package/dist/types/cite/core/kinds/path.d.ts +8 -0
  16. package/dist/types/cite/core/kinds/registry.d.ts +3 -0
  17. package/dist/types/cite/core/kinds/tesseract.d.ts +11 -0
  18. package/dist/types/cite/core/kinds/tether.d.ts +4 -0
  19. package/dist/types/cite/core/kinds/torque.d.ts +11 -0
  20. package/dist/types/cite/core/kinds/url.d.ts +2 -0
  21. package/dist/types/cite/core/kinds/work.d.ts +3 -0
  22. package/dist/types/cite/core/preview.d.ts +8 -0
  23. package/dist/types/cite/core/registry.d.ts +19 -0
  24. package/dist/types/cite/core/resolver.d.ts +34 -0
  25. package/dist/types/cite/core/scan-utils.d.ts +9 -0
  26. package/dist/types/cite/core/tach.d.ts +3 -0
  27. package/dist/types/cite/core/types.d.ts +161 -0
  28. package/dist/types/cite/record.d.ts +11 -0
  29. package/dist/types/cite/remark.d.ts +32 -0
  30. package/dist/types/cite/store.d.ts +35 -0
  31. package/dist/types/cite/structured-view.d.ts +9 -0
  32. package/dist/types/cite/structured.d.ts +90 -0
  33. package/dist/types/cite/terminal.d.ts +15 -0
  34. package/dist/types/cite/ui.d.ts +52 -0
  35. package/dist/types/gallery/Gallery.d.ts +5 -0
  36. package/dist/types/gallery/cite.d.ts +1 -0
  37. package/dist/types/sdk/index.d.ts +3 -0
  38. package/dist/types/sdk/types.d.ts +37 -0
  39. package/package.json +5 -5
  40. package/dist/chunks/chunk-ZT6LTRMY.js +0 -220
@@ -0,0 +1,2060 @@
1
+ // ../../web/src/cite/record.tsx
2
+ import { Braces, ExternalLink as ExternalLink2, ListTree, RefreshCw, SquareArrowOutUpRight } from "lucide-react";
3
+ import { useCallback, useEffect, useMemo, useState as useState3 } from "react";
4
+ import { Button as Button3 } from "@/components/ui/button";
5
+ import { CiteRecordHeader } from "@/components/ui/cite-card";
6
+ import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
7
+ import { Markdown as Markdown2 } from "@/components/ui/markdown";
8
+ import { Spinner } from "@/components/ui/spinner";
9
+ import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
10
+
11
+ // ../../web/src/cite/store.ts
12
+ import { useSyncExternalStore as useSyncExternalStore2 } from "react";
13
+
14
+ // ../../web/src/desk/store.ts
15
+ import { useSyncExternalStore } from "react";
16
+
17
+ // ../../web/src/sdk/runtime.ts
18
+ var ApiError = class extends Error {
19
+ status;
20
+ body;
21
+ constructor(message, status, body) {
22
+ super(message);
23
+ this.status = status;
24
+ this.body = body;
25
+ }
26
+ };
27
+ async function call(method, path, body) {
28
+ const res = await fetch(path, {
29
+ method,
30
+ headers: body === void 0 ? void 0 : { "Content-Type": "application/json" },
31
+ body: body === void 0 ? void 0 : JSON.stringify(body)
32
+ });
33
+ const text = await res.text();
34
+ let data = null;
35
+ try {
36
+ data = text ? JSON.parse(text) : null;
37
+ } catch {
38
+ data = text;
39
+ }
40
+ if (!res.ok) {
41
+ const msg = data?.error ?? `${res.status} ${res.statusText}`;
42
+ throw new ApiError(msg, res.status, data);
43
+ }
44
+ return data;
45
+ }
46
+ var listeners = /* @__PURE__ */ new Set();
47
+ var matches = (prefix, topic) => prefix === "" || topic === prefix || topic.startsWith(`${prefix}.`);
48
+ function onEvent(prefix, fn) {
49
+ const entry = { prefix, fn };
50
+ listeners.add(entry);
51
+ return () => {
52
+ listeners.delete(entry);
53
+ };
54
+ }
55
+ function dispatch(ev) {
56
+ for (const l of [...listeners]) {
57
+ if (!matches(l.prefix, ev.topic)) continue;
58
+ try {
59
+ l.fn(ev);
60
+ } catch (err) {
61
+ console.error("surface: an event listener failed", ev.topic, err);
62
+ }
63
+ }
64
+ }
65
+ var source = null;
66
+ var connected = false;
67
+ var connectionListeners = /* @__PURE__ */ new Set();
68
+ var isConnected = () => connected;
69
+ function onConnection(fn) {
70
+ connectionListeners.add(fn);
71
+ return () => {
72
+ connectionListeners.delete(fn);
73
+ };
74
+ }
75
+ function connect() {
76
+ if (source) return;
77
+ source = new EventSource("/api/events");
78
+ source.addEventListener("surface", (e) => {
79
+ if (!connected) {
80
+ connected = true;
81
+ for (const fn of connectionListeners) fn(true);
82
+ }
83
+ try {
84
+ dispatch(JSON.parse(e.data));
85
+ } catch (err) {
86
+ console.error("surface: bad event", err);
87
+ }
88
+ });
89
+ source.onopen = () => {
90
+ connected = true;
91
+ for (const fn of connectionListeners) fn(true);
92
+ };
93
+ source.onerror = () => {
94
+ connected = false;
95
+ for (const fn of connectionListeners) fn(false);
96
+ };
97
+ }
98
+ var settings = /* @__PURE__ */ new Map();
99
+ async function loadSettings() {
100
+ const list = await call("GET", "/api/settings");
101
+ settings.clear();
102
+ for (const s of list) settings.set(s.full_key, s);
103
+ return list;
104
+ }
105
+ var getSetting = (fullKey) => settings.get(fullKey)?.value;
106
+ var allSettings = () => [...settings.values()];
107
+ onEvent("config.changed", (ev) => {
108
+ const d = ev.data;
109
+ const s = settings.get(d.key);
110
+ if (s) settings.set(d.key, { ...s, value: d.value, set: true });
111
+ });
112
+ async function setSetting(fullKey, value) {
113
+ await call("PUT", `/api/settings/${encodeURIComponent(fullKey)}`, { value });
114
+ }
115
+ var listMarks = (ref) => call("GET", `/api/marks?ref=${encodeURIComponent(ref)}`);
116
+
117
+ // ../../web/src/desk/store.ts
118
+ var notYetKept = (w) => !!w.opened_by && w.opened_by !== "owner" && !w.kept;
119
+ var manifest = null;
120
+ var state = { wins: [], focus: "", tree: { root: { type: "row" } }, layout: "tile", ratio: 0.56, rev: -1 };
121
+ var subs = /* @__PURE__ */ new Set();
122
+ var emit = () => {
123
+ for (const fn of subs) fn();
124
+ };
125
+ onEvent("desk.changed", (ev) => {
126
+ const next = ev.data;
127
+ if (next && next.rev >= state.rev) {
128
+ state = next;
129
+ emit();
130
+ }
131
+ });
132
+ async function loadManifest() {
133
+ manifest = await call("GET", "/api/app");
134
+ return manifest;
135
+ }
136
+ var app = () => {
137
+ if (!manifest) throw new Error("the app manifest is not loaded yet");
138
+ return manifest;
139
+ };
140
+ var viewById = (id) => manifest?.views.find((v) => v.id === id);
141
+ function viewForFile(name) {
142
+ const base = name.toLowerCase().split("/").pop() ?? "";
143
+ const matches3 = (pattern) => {
144
+ const p = pattern.toLowerCase();
145
+ if (p.startsWith("*")) return base.endsWith(p.slice(1));
146
+ return base === p;
147
+ };
148
+ return manifest?.views.find((v) => v.opens?.some(matches3));
149
+ }
150
+ var deskState = () => state;
151
+ var subscribe = (fn) => {
152
+ subs.add(fn);
153
+ return () => {
154
+ subs.delete(fn);
155
+ };
156
+ };
157
+ function useDeskState() {
158
+ return useSyncExternalStore(subscribe, deskState);
159
+ }
160
+ async function act(action) {
161
+ const res = await call("POST", "/api/desk/actions", action);
162
+ return res.window;
163
+ }
164
+ var toWin = (w, focus) => ({
165
+ id: w.id,
166
+ view: w.view,
167
+ module: w.module,
168
+ title: w.title,
169
+ key: w.key,
170
+ args: w.args ?? {},
171
+ state: w.state,
172
+ focused: w.id === focus
173
+ });
174
+ var pendingReports = /* @__PURE__ */ new Map();
175
+ var reportTimer;
176
+ function flushReports() {
177
+ reportTimer = void 0;
178
+ for (const [id, st] of pendingReports) {
179
+ void act({ type: "state", id, state: st }).catch(() => {
180
+ });
181
+ }
182
+ pendingReports.clear();
183
+ }
184
+ var confirmImpl = async (q) => window.confirm(q.title);
185
+ var setConfirm = (fn) => {
186
+ confirmImpl = fn;
187
+ };
188
+ var clientRunner = () => void 0;
189
+ var setClientRunner = (fn) => {
190
+ clientRunner = fn;
191
+ };
192
+ async function runCommand(id, args) {
193
+ const local = clientRunner(id, args);
194
+ if (local !== void 0) return await local;
195
+ const res = await call("POST", `/api/commands/${encodeURIComponent(id)}`, { args: args ?? {} });
196
+ return res.result;
197
+ }
198
+ async function closeWindow(id) {
199
+ const w = state.wins.find((x) => x.id === id);
200
+ if (w?.dirty && getSetting("surface.confirm_close_dirty") === false) {
201
+ await act({ type: "close", id, force: true });
202
+ return;
203
+ }
204
+ if (w?.dirty) {
205
+ const yes = await confirmImpl({
206
+ title: `Close \u201C${w.title}\u201D?`,
207
+ message: "It holds unsaved work.",
208
+ confirmLabel: "Close anyway",
209
+ danger: true
210
+ });
211
+ if (!yes) return;
212
+ await act({ type: "close", id, force: true });
213
+ return;
214
+ }
215
+ await act({ type: "close", id });
216
+ }
217
+ function unlessGone(err) {
218
+ if (err instanceof ApiError && /no window/.test(err.message)) return void 0;
219
+ throw err;
220
+ }
221
+ var desk = {
222
+ async open(view, opts) {
223
+ const w = await act({ type: "open", view, ...opts });
224
+ if (!w) throw new Error(`could not open ${view}`);
225
+ return toWin(w, w.id);
226
+ },
227
+ async openFile(name, opts) {
228
+ const view = viewForFile(name);
229
+ return view ? desk.open(view.id, opts) : null;
230
+ },
231
+ close: closeWindow,
232
+ async focus(id) {
233
+ await act({ type: "focus", id }).catch(unlessGone);
234
+ },
235
+ async setTitle(id, title) {
236
+ await act({ type: "title", id, title }).catch(unlessGone);
237
+ },
238
+ async setArgs(id, args) {
239
+ await act({ type: "args", id, args }).catch(unlessGone);
240
+ },
241
+ report(id, st) {
242
+ pendingReports.set(id, st);
243
+ if (reportTimer === void 0) reportTimer = window.setTimeout(flushReports, 250);
244
+ },
245
+ setDirty(id, dirty) {
246
+ const w = state.wins.find((x) => x.id === id);
247
+ if (w && !!w.dirty !== dirty) void act({ type: "dirty", id, dirty }).catch(() => {
248
+ });
249
+ },
250
+ run: runCommand,
251
+ confirm: (q) => confirmImpl(q),
252
+ windows: () => state.wins.map((w) => toWin(w, state.focus))
253
+ };
254
+ var listLayouts = () => call("GET", "/api/layouts");
255
+ var saveLayout = (name, about) => call("POST", "/api/layouts", { name, about });
256
+ var loadLayout = (name) => call("POST", `/api/layouts/${encodeURIComponent(name)}/load`);
257
+ var deleteLayout = (name) => call("DELETE", `/api/layouts/${encodeURIComponent(name)}`);
258
+
259
+ // ../../web/src/cite/core/scan-utils.ts
260
+ var TRAILING_DROP = /* @__PURE__ */ new Set([".", ",", ";", ":", "!", "?", "'", '"', "*"]);
261
+ var PAIRS = { ")": "(", "]": "[", "}": "{", ">": "<" };
262
+ function trimTrailing(text, start, end) {
263
+ let e = end;
264
+ while (e > start) {
265
+ const c = text[e - 1];
266
+ if (TRAILING_DROP.has(c)) {
267
+ e--;
268
+ continue;
269
+ }
270
+ const open = PAIRS[c];
271
+ if (open) {
272
+ let opens = 0;
273
+ let closes = 0;
274
+ for (let i = start; i < e; i++) {
275
+ if (text[i] === open) opens++;
276
+ else if (text[i] === c) closes++;
277
+ }
278
+ if (closes > opens) {
279
+ e--;
280
+ continue;
281
+ }
282
+ }
283
+ break;
284
+ }
285
+ return e;
286
+ }
287
+ var WORD = /[A-Za-z0-9_]/;
288
+ function isWordChar(c) {
289
+ return c !== void 0 && WORD.test(c);
290
+ }
291
+ function* matches2(re, text) {
292
+ const g = new RegExp(re.source, re.flags.includes("g") ? re.flags : `${re.flags}g`);
293
+ for (let m = g.exec(text); m !== null; m = g.exec(text)) {
294
+ if (m[0].length === 0) {
295
+ g.lastIndex++;
296
+ continue;
297
+ }
298
+ yield m;
299
+ }
300
+ }
301
+
302
+ // ../../web/src/cite/core/kinds/caster.ts
303
+ var CASTER = /caster:\/\/[A-Za-z0-9_.-]{1,128}\/[A-Za-z0-9_.:-]{1,256}/g;
304
+ var CASTER_KIND = "caster.doc";
305
+ function createCasterKind() {
306
+ return {
307
+ id: CASTER_KIND,
308
+ label: "Caster document",
309
+ icon: "document",
310
+ priority: 88,
311
+ chipLabel: (ref) => ref.canonical.slice("caster://".length),
312
+ open: () => ({ type: "none" }),
313
+ scan(text) {
314
+ const hits = [];
315
+ for (const m of matches2(CASTER, text)) {
316
+ if (isWordChar(text[m.index - 1])) continue;
317
+ const end = trimTrailing(text, m.index, m.index + m[0].length);
318
+ hits.push({ start: m.index, end, canonical: text.slice(m.index, end) });
319
+ }
320
+ return hits;
321
+ }
322
+ };
323
+ }
324
+
325
+ // ../../web/src/cite/core/kinds/fragment.ts
326
+ var FRAGMENT_KIND = "fragments.fragment";
327
+ var ID = "[0-9a-f]{64}";
328
+ var TACH = new RegExp(`tach:/{0,2}(?:fragment|frag|fe)/(${ID})`, "gi");
329
+ var READER = new RegExp(`https?://[^\\s/]+(?::\\d+)?/sysop/reader/(${ID})`, "gi");
330
+ function createFragmentKind() {
331
+ return {
332
+ id: FRAGMENT_KIND,
333
+ label: "Fragment",
334
+ icon: "fragment",
335
+ // Above URLs, so a reader link becomes the fragment rather than a bare link.
336
+ priority: 110,
337
+ chipLabel: (ref) => `fragment ${ref.canonical.slice(0, 8)}`,
338
+ open: () => ({ type: "none" }),
339
+ scan(text) {
340
+ const hits = [];
341
+ for (const re of [TACH, READER]) {
342
+ for (const m of matches2(re, text)) {
343
+ if (isWordChar(text[m.index - 1])) continue;
344
+ const end = trimTrailing(text, m.index, m.index + m[0].length);
345
+ hits.push({ start: m.index, end, canonical: m[1].toLowerCase() });
346
+ }
347
+ }
348
+ return hits;
349
+ }
350
+ };
351
+ }
352
+
353
+ // ../../web/src/cite/core/kinds/ops.ts
354
+ var OPS = /ops:([a-z0-9][a-z0-9-]{2,63})/g;
355
+ var OPS_WORKSTREAM_KIND = "ops.workstream";
356
+ function createOpsKind() {
357
+ return {
358
+ id: OPS_WORKSTREAM_KIND,
359
+ label: "Workstream",
360
+ icon: "radar",
361
+ priority: 88,
362
+ chipLabel: (ref) => `ops:${ref.canonical}`,
363
+ open: () => ({ type: "none" }),
364
+ scan(text) {
365
+ const hits = [];
366
+ for (const m of matches2(OPS, text)) {
367
+ const before = text[m.index - 1];
368
+ if (isWordChar(before) || before === "/" || before === "." || before === "-") continue;
369
+ let end = m.index + m[0].length;
370
+ while (text[end - 1] === "-") end--;
371
+ const id = text.slice(m.index + "ops:".length, end);
372
+ if (id.length < 3 || isWordChar(text[end]) || text[end] === "/") continue;
373
+ hits.push({ start: m.index, end, canonical: id });
374
+ }
375
+ return hits;
376
+ }
377
+ };
378
+ }
379
+
380
+ // ../../web/src/cite/core/kinds/path.ts
381
+ var PATH = /^(?:~|\.{1,2})?\/?[A-Za-z0-9_.@+%-]+(?:\/[A-Za-z0-9_.@+%-]+)+\/?(?::\d{1,6}(?::\d{1,4})?)?/;
382
+ var REMOTE = /^remote:[a-z0-9][a-z0-9-]{0,39}(?:\/[A-Za-z0-9_.@+%-]+)+\/?(?::\d{1,6}(?::\d{1,4})?)?/;
383
+ var TOKEN = /[A-Za-z0-9_.@+%~/:-]+/g;
384
+ var ABS_ROOTS = /* @__PURE__ */ new Set([
385
+ "home",
386
+ "srv",
387
+ "tmp",
388
+ "etc",
389
+ "var",
390
+ "usr",
391
+ "opt",
392
+ "mnt",
393
+ "Users",
394
+ "root",
395
+ "bin",
396
+ "dev",
397
+ "proc",
398
+ "run",
399
+ "workspace",
400
+ "workspaces",
401
+ "app",
402
+ "data",
403
+ "Volumes"
404
+ ]);
405
+ var REPO_DIRS = /* @__PURE__ */ new Set([
406
+ "apps",
407
+ "src",
408
+ "lib",
409
+ "libs",
410
+ "cmd",
411
+ "internal",
412
+ "pkg",
413
+ "docs",
414
+ "plugins",
415
+ "packages",
416
+ "scripts",
417
+ "test",
418
+ "tests",
419
+ "components",
420
+ "pages",
421
+ "hooks",
422
+ "public",
423
+ "config",
424
+ "migrations",
425
+ "web",
426
+ "gui",
427
+ "server",
428
+ "api",
429
+ "modules",
430
+ "core",
431
+ "registry"
432
+ ]);
433
+ var EXT = /\.[A-Za-z][A-Za-z0-9]{0,7}$/;
434
+ var DOMAIN_FIRST = /^[A-Za-z0-9-]+\.(com|org|net|io|dev|ai|app|co|me|sh|gg)$/i;
435
+ var PATH_KIND = "path";
436
+ var RELATIVE_PATH_KIND = "path.relative";
437
+ function classify(body) {
438
+ const trimmedSlash = body.replace(/\/$/, "");
439
+ const dir = body.endsWith("/");
440
+ const segs = trimmedSlash.split("/");
441
+ const hasExt = EXT.test(segs[segs.length - 1]);
442
+ if (segs.some((s) => s === "")) {
443
+ if (!(segs[0] === "" && segs.slice(1).every((s) => s !== ""))) return null;
444
+ }
445
+ if (body.startsWith("~")) {
446
+ return body.startsWith("~/") && segs.length >= 2 ? "home" : null;
447
+ }
448
+ if (body.startsWith("/")) {
449
+ const parts = segs.slice(1);
450
+ if (parts.length < 2) return null;
451
+ return ABS_ROOTS.has(parts[0]) || hasExt ? "absolute" : null;
452
+ }
453
+ if (body.startsWith("./") || body.startsWith("../")) {
454
+ const parts = segs.filter((s) => s !== "." && s !== "..");
455
+ return parts.length >= 1 && (hasExt || dir || parts.length >= 2) ? "relative" : null;
456
+ }
457
+ if (DOMAIN_FIRST.test(segs[0])) return null;
458
+ if (hasExt && !/^\d+\.\d+/.test(segs[segs.length - 1])) return "repo";
459
+ if (segs.length >= 2 && REPO_DIRS.has(segs[0]) && !/^\d+$/.test(segs[segs.length - 1])) return "repo";
460
+ return null;
461
+ }
462
+ function scanPaths(text) {
463
+ const hits = [];
464
+ for (const tok of matches2(TOKEN, text)) {
465
+ if (!tok[0].includes("/")) continue;
466
+ const remote = tok[0].startsWith("remote:");
467
+ const m = (remote ? REMOTE : PATH).exec(tok[0]);
468
+ if (!m) continue;
469
+ const start = tok.index;
470
+ const before = text[start - 1];
471
+ if (isWordChar(before) || before === "/" || before === "." || before === ":" || before === "@" || before === "~" || before === "-" || before === "#")
472
+ continue;
473
+ const end = trimTrailing(text, start, start + m[0].length);
474
+ const raw = text.slice(start, end);
475
+ const loc = /^(.*?)(?::(\d{1,6})(?::(\d{1,4}))?)?$/.exec(raw.slice(remote ? "remote:".length : 0));
476
+ const body = (remote ? "remote:" : "") + (loc ? loc[1] : raw);
477
+ const style = remote ? "remote" : classify(body);
478
+ if (!style) continue;
479
+ const meta = { style };
480
+ if (loc?.[2]) meta.line = Number(loc[2]);
481
+ if (loc?.[3]) meta.col = Number(loc[3]);
482
+ hits.push({ start, end, canonical: body.replace(/\/$/, "") || body, meta, style });
483
+ }
484
+ return hits;
485
+ }
486
+ var chipLabel = (ref, raw) => {
487
+ const base = ref.canonical.split("/").pop() || ref.canonical;
488
+ const line = ref.meta?.line;
489
+ return line !== void 0 ? `${base}:${line}` : base || raw;
490
+ };
491
+ function createPathKinds() {
492
+ const kind = (id, label, keep, priority) => ({
493
+ id,
494
+ label,
495
+ icon: "file",
496
+ priority,
497
+ scan: (text) => scanPaths(text).filter((h) => keep(h.style)).map(({ style: _style, ...h }) => h),
498
+ chipLabel,
499
+ open: (ref) => ({ type: "copy", text: ref.canonical })
500
+ });
501
+ return [
502
+ kind(PATH_KIND, "File path", (s) => s === "home" || s === "absolute" || s === "remote", 40),
503
+ kind(RELATIVE_PATH_KIND, "Relative path", (s) => s === "relative" || s === "repo", 39)
504
+ ];
505
+ }
506
+
507
+ // ../../web/src/cite/core/kinds/registry.ts
508
+ var REGISTRY = /registry:([a-z][a-z0-9_]{0,40}):([A-Za-z0-9][A-Za-z0-9._/:@+-]{0,400})/g;
509
+ var REGISTRY_RECORD_KIND = "registry.record";
510
+ function createRegistryKind() {
511
+ return {
512
+ id: REGISTRY_RECORD_KIND,
513
+ label: "Registry record",
514
+ icon: "registry",
515
+ priority: 88,
516
+ chipLabel: (ref) => ref.canonical,
517
+ open: () => ({ type: "none" }),
518
+ scan(text) {
519
+ const hits = [];
520
+ for (const m of matches2(REGISTRY, text)) {
521
+ if (isWordChar(text[m.index - 1]) || text[m.index - 1] === "/" || text[m.index - 1] === ".") continue;
522
+ const end = trimTrailing(text, m.index, m.index + m[0].length);
523
+ const canonical = text.slice(m.index + "registry:".length, end);
524
+ if (!/^[a-z][a-z0-9_]*:[A-Za-z0-9]/.test(canonical)) continue;
525
+ hits.push({ start: m.index, end, canonical });
526
+ }
527
+ return hits;
528
+ }
529
+ };
530
+ }
531
+
532
+ // ../../web/src/cite/core/kinds/tesseract.ts
533
+ var ULID = /[0-7][0-9A-HJKMNP-TV-Z]{25}/g;
534
+ var KEY_BODY = "([a-z][a-z0-9_.-]{0,63}(?:\\/[A-Za-z0-9_.-]{1,64}){0,10})#([A-Za-z0-9_.:-]{1,160})";
535
+ var EXPLICIT = new RegExp(`tesseract:(?:([a-z]{3,16})@)?${KEY_BODY}`, "g");
536
+ var BARE = /(?:project|user|agent|shared|global|system)\/[A-Za-z0-9_.-]{1,64}(?:\/[A-Za-z0-9_.-]{1,64}){0,9}#[A-Za-z0-9_.:-]{1,160}/g;
537
+ var EXPLICIT_ULID = /tesseract:([0-7][0-9A-HJKMNP-TV-Z]{25})/g;
538
+ function isUlid(s) {
539
+ return /\d/.test(s) && /[A-Z]/.test(s);
540
+ }
541
+ var TESSERACT_ITEM_KIND = "tesseract.item";
542
+ var TESSERACT_KEY_KIND = "tesseract.key";
543
+ function parseTesseractKey(canonical) {
544
+ const m = /^(?:([a-z]{3,16})@)?([^#@]+)#(.+)$/.exec(canonical);
545
+ return m ? { domain: m[1], namespace: m[2], key: m[3] } : null;
546
+ }
547
+ function keyHit(text, start, end) {
548
+ const before = text[start - 1];
549
+ if (isWordChar(before) || before === "/" || before === "." || before === "-") return null;
550
+ const e = trimTrailing(text, start, end);
551
+ const raw = text.slice(start, e).replace(/^tesseract:/, "");
552
+ if (!parseTesseractKey(raw)) return null;
553
+ return { start, end: e, canonical: raw };
554
+ }
555
+ function createTesseractKinds() {
556
+ const item = {
557
+ id: TESSERACT_ITEM_KIND,
558
+ label: "Tesseract item",
559
+ icon: "memory",
560
+ priority: 70,
561
+ scan(text) {
562
+ const hits = [];
563
+ for (const m of matches2(EXPLICIT_ULID, text)) {
564
+ const before = text[m.index - 1];
565
+ if (isWordChar(before)) continue;
566
+ if (isWordChar(text[m.index + m[0].length])) continue;
567
+ hits.push({ start: m.index, end: m.index + m[0].length, canonical: m[1] });
568
+ }
569
+ for (const m of matches2(ULID, text)) {
570
+ const start = m.index;
571
+ const end = start + m[0].length;
572
+ const before = text[start - 1];
573
+ const after = text[end];
574
+ if (isWordChar(before) || before === "-" || before === "/" || before === ":") continue;
575
+ if (isWordChar(after) || after === "-" || after === "/") continue;
576
+ if (!isUlid(m[0])) continue;
577
+ hits.push({ start, end, canonical: m[0] });
578
+ }
579
+ return hits;
580
+ },
581
+ chipLabel: (ref) => `${ref.canonical.slice(0, 4)}\u2026${ref.canonical.slice(-4)}`,
582
+ open: () => ({ type: "none" })
583
+ };
584
+ const key = {
585
+ id: TESSERACT_KEY_KIND,
586
+ label: "Tesseract key",
587
+ icon: "memory",
588
+ priority: 90,
589
+ scan(text) {
590
+ const hits = [];
591
+ for (const m of matches2(EXPLICIT, text)) {
592
+ const h = keyHit(text, m.index, m.index + m[0].length);
593
+ if (h) hits.push(h);
594
+ }
595
+ for (const m of matches2(BARE, text)) {
596
+ const h = keyHit(text, m.index, m.index + m[0].length);
597
+ if (h) hits.push(h);
598
+ }
599
+ return hits;
600
+ },
601
+ chipLabel: (ref) => parseTesseractKey(ref.canonical)?.key ?? ref.canonical,
602
+ open: () => ({ type: "none" })
603
+ };
604
+ return [item, key];
605
+ }
606
+
607
+ // ../../web/src/cite/core/kinds/tether.ts
608
+ var URN = /msg:\/\/[a-z][a-z0-9-]{0,31}\/[A-Za-z0-9_.@:/-]{1,300}/g;
609
+ var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
610
+ var MESSAGE = new RegExp(`tach:/{0,2}(?:message|msg)/(${UUID})`, "gi");
611
+ var TETHER_AGENT_KIND = "tether.agent";
612
+ var TETHER_MESSAGE_KIND = "tether.message";
613
+ function createTetherKinds() {
614
+ const agent = {
615
+ id: TETHER_AGENT_KIND,
616
+ label: "Tether agent",
617
+ icon: "agent",
618
+ priority: 85,
619
+ scan(text) {
620
+ const hits = [];
621
+ for (const m of matches2(URN, text)) {
622
+ if (isWordChar(text[m.index - 1])) continue;
623
+ const end = trimTrailing(text, m.index, m.index + m[0].length);
624
+ hits.push({ start: m.index, end, canonical: text.slice(m.index, end) });
625
+ }
626
+ return hits;
627
+ },
628
+ chipLabel: (ref) => ref.canonical.split("/").pop() || ref.canonical,
629
+ open: () => ({ type: "none" })
630
+ };
631
+ const message = {
632
+ id: TETHER_MESSAGE_KIND,
633
+ label: "Tether message",
634
+ icon: "message",
635
+ priority: 95,
636
+ scan(text) {
637
+ const hits = [];
638
+ for (const m of matches2(MESSAGE, text)) {
639
+ if (isWordChar(text[m.index - 1])) continue;
640
+ hits.push({ start: m.index, end: m.index + m[0].length, canonical: m[1].toLowerCase() });
641
+ }
642
+ return hits;
643
+ },
644
+ chipLabel: (ref) => `message ${ref.canonical.slice(0, 8)}`,
645
+ open: () => ({ type: "none" })
646
+ };
647
+ return [agent, message];
648
+ }
649
+
650
+ // ../../web/src/cite/core/kinds/torque.ts
651
+ var ID2 = /(CW|EP|PRJ|SP|PL)-\d{8}-\d{4}/g;
652
+ var TORQUE_ENTITIES = [
653
+ { id: "torque.task", prefix: "CW", label: "Torque task", icon: "task" },
654
+ { id: "torque.epic", prefix: "EP", label: "Torque epic", icon: "epic" },
655
+ { id: "torque.project", prefix: "PRJ", label: "Torque project", icon: "project" },
656
+ { id: "torque.sprint", prefix: "SP", label: "Torque sprint", icon: "sprint" },
657
+ { id: "torque.plan", prefix: "PL", label: "Torque plan", icon: "plan" }
658
+ ];
659
+ function standalone(text, start, end) {
660
+ const before = text[start - 1];
661
+ if (isWordChar(before) || before === "-" || before === "/" || before === "\\" || before === "." || before === "#")
662
+ return false;
663
+ const after = text[end];
664
+ if (isWordChar(after) || after === "/" || after === "\\") return false;
665
+ if ((after === "-" || after === ".") && isWordChar(text[end + 1])) return false;
666
+ return true;
667
+ }
668
+ function createTorqueKinds() {
669
+ return TORQUE_ENTITIES.map((e) => ({
670
+ id: e.id,
671
+ label: e.label,
672
+ icon: e.icon,
673
+ priority: 80,
674
+ // Tasks resolve in one batch; a container is one read each, so it waits for hover, focus or a click.
675
+ ...e.id === "torque.task" ? {} : { resolveOn: "hover" },
676
+ scan(text) {
677
+ const hits = [];
678
+ for (const m of matches2(ID2, text)) {
679
+ if (m[1] !== e.prefix) continue;
680
+ const start = m.index;
681
+ const end = start + m[0].length;
682
+ if (!standalone(text, start, end)) continue;
683
+ hits.push({ start, end, canonical: m[0] });
684
+ }
685
+ return hits;
686
+ },
687
+ // The record window shows it (the server has the record; Torque has no page here).
688
+ open: () => ({ type: "none" })
689
+ }));
690
+ }
691
+
692
+ // ../../web/src/cite/core/kinds/url.ts
693
+ var URL_RE = /https?:\/\/[^\s<>"`]{1,2048}/g;
694
+ function createUrlKind() {
695
+ return {
696
+ id: "url",
697
+ label: "Link",
698
+ icon: "link",
699
+ priority: 100,
700
+ scan(text) {
701
+ const hits = [];
702
+ for (const m of matches2(URL_RE, text)) {
703
+ const start = m.index;
704
+ if (isWordChar(text[start - 1])) continue;
705
+ const end = trimTrailing(text, start, start + m[0].length);
706
+ const raw = text.slice(start, end);
707
+ let u;
708
+ try {
709
+ u = new URL(raw);
710
+ } catch {
711
+ continue;
712
+ }
713
+ const host = u.hostname;
714
+ if (!host || !(host.includes(".") || host === "localhost" || host.includes(":"))) continue;
715
+ hits.push({ start, end, canonical: raw, meta: { host } });
716
+ }
717
+ return hits;
718
+ },
719
+ chipLabel: (ref) => {
720
+ try {
721
+ const u = new URL(ref.canonical);
722
+ const path = u.pathname === "/" ? "" : u.pathname;
723
+ const s = `${u.host}${path}`;
724
+ return s.length > 48 ? `${s.slice(0, 47)}\u2026` : s;
725
+ } catch {
726
+ return ref.canonical;
727
+ }
728
+ },
729
+ open: (ref) => ({ type: "external", href: ref.canonical })
730
+ };
731
+ }
732
+
733
+ // ../../web/src/cite/core/kinds/work.ts
734
+ var WORK = /work:([a-z0-9][a-z0-9-]{0,47})\/([a-z0-9]{8})/g;
735
+ var WORK_ITEM_KIND = "work.item";
736
+ function createWorkKind() {
737
+ return {
738
+ id: WORK_ITEM_KIND,
739
+ label: "Work item",
740
+ icon: "target",
741
+ priority: 88,
742
+ chipLabel: (ref) => ref.canonical,
743
+ open: () => ({ type: "none" }),
744
+ scan(text) {
745
+ const hits = [];
746
+ for (const m of matches2(WORK, text)) {
747
+ const end = m.index + m[0].length;
748
+ if (isWordChar(text[m.index - 1]) || isWordChar(text[end]) || text[end] === "/" || text[end] === "-") continue;
749
+ hits.push({ start: m.index, end, canonical: `${m[1]}/${m[2]}` });
750
+ }
751
+ return hits;
752
+ }
753
+ };
754
+ }
755
+
756
+ // ../../web/src/cite/core/registry.ts
757
+ var ID_RE = /^[a-z][a-z0-9]*(\.[a-z0-9]+)*$/;
758
+ function createRefRegistry() {
759
+ const kinds2 = /* @__PURE__ */ new Map();
760
+ let version2 = 0;
761
+ const registry2 = {
762
+ register(kind, opts) {
763
+ if (!ID_RE.test(kind.id)) throw new Error(`invalid ref kind id: ${JSON.stringify(kind.id)}`);
764
+ if (!Number.isFinite(kind.priority)) throw new Error(`ref kind ${kind.id}: priority must be a finite number`);
765
+ if (kinds2.has(kind.id) && !opts?.replace) throw new Error(`ref kind already registered: ${kind.id}`);
766
+ kinds2.set(kind.id, kind);
767
+ version2++;
768
+ return () => {
769
+ if (kinds2.get(kind.id) === kind) registry2.unregister(kind.id);
770
+ };
771
+ },
772
+ unregister(id) {
773
+ const had = kinds2.delete(id);
774
+ if (had) version2++;
775
+ return had;
776
+ },
777
+ get: (id) => kinds2.get(id),
778
+ has: (id) => kinds2.has(id),
779
+ list: () => [...kinds2.values()].sort((a, b) => b.priority - a.priority),
780
+ get version() {
781
+ return version2;
782
+ }
783
+ };
784
+ return registry2;
785
+ }
786
+
787
+ // ../../web/src/cite/core/detect.ts
788
+ function fencedRanges(text) {
789
+ const out = [];
790
+ let pos = 0;
791
+ let open = null;
792
+ while (pos <= text.length) {
793
+ let eol = text.indexOf("\n", pos);
794
+ if (eol === -1) eol = text.length;
795
+ const line = text.slice(pos, eol);
796
+ const m = /^ {0,3}(`{3,}|~{3,})/.exec(line);
797
+ if (m) {
798
+ const ch = m[1][0];
799
+ const len = m[1].length;
800
+ if (!open) {
801
+ if (!(ch === "`" && line.slice(m[0].length).includes("`"))) open = { start: pos, ch, len };
802
+ } else if (ch === open.ch && len >= open.len && line.slice(m[0].length).trim() === "") {
803
+ out.push([open.start, Math.min(eol + 1, text.length)]);
804
+ open = null;
805
+ }
806
+ }
807
+ pos = eol + 1;
808
+ }
809
+ if (open) out.push([open.start, text.length]);
810
+ return out;
811
+ }
812
+ function inlineCodeRanges(text, skip) {
813
+ const runs = [];
814
+ let k = 0;
815
+ for (let i = 0; i < text.length; i++) {
816
+ if (text[i] !== "`") continue;
817
+ while (k < skip.length && skip[k][1] <= i) k++;
818
+ if (k < skip.length && skip[k][0] <= i) {
819
+ i = skip[k][1] - 1;
820
+ continue;
821
+ }
822
+ let j = i;
823
+ while (j < text.length && text[j] === "`") j++;
824
+ runs.push({ start: i, len: j - i });
825
+ i = j - 1;
826
+ }
827
+ const nextSame = new Array(runs.length).fill(-1);
828
+ const lastByLen = /* @__PURE__ */ new Map();
829
+ for (let i = runs.length - 1; i >= 0; i--) {
830
+ nextSame[i] = lastByLen.get(runs[i].len) ?? -1;
831
+ lastByLen.set(runs[i].len, i);
832
+ }
833
+ const out = [];
834
+ for (let i = 0; i < runs.length; i++) {
835
+ const j = nextSame[i];
836
+ if (j === -1) continue;
837
+ out.push([runs[i].start, runs[j].start + runs[j].len]);
838
+ while (i + 1 < runs.length && runs[i + 1].start < runs[j].start + runs[j].len) i++;
839
+ }
840
+ return out;
841
+ }
842
+ function codeRanges(text) {
843
+ const fences = fencedRanges(text);
844
+ return [...fences, ...inlineCodeRanges(text, fences)].sort((a, b) => a[0] - b[0]);
845
+ }
846
+ function intersects(ranges, start, end) {
847
+ let lo = 0;
848
+ let hi = ranges.length;
849
+ while (lo < hi) {
850
+ const mid = lo + hi >> 1;
851
+ if (ranges[mid][1] <= start) lo = mid + 1;
852
+ else hi = mid;
853
+ }
854
+ return lo < ranges.length && ranges[lo][0] < end;
855
+ }
856
+ function valid(h, len) {
857
+ return Number.isInteger(h.start) && Number.isInteger(h.end) && h.start >= 0 && h.end <= len && h.start < h.end && typeof h.canonical === "string" && h.canonical.length > 0;
858
+ }
859
+ function better(a, b) {
860
+ return b.kind.priority - a.kind.priority || b.end - b.start - (a.end - a.start) || a.start - b.start;
861
+ }
862
+ function detectRefs(text, registry2, opts = {}) {
863
+ if (!text) return [];
864
+ const skipCode = opts.skipCode ?? true;
865
+ const code = skipCode ? codeRanges(text) : [];
866
+ const wanted = opts.kinds ? new Set(opts.kinds) : null;
867
+ const cands = [];
868
+ for (const kind of registry2.list()) {
869
+ if (wanted && !wanted.has(kind.id)) continue;
870
+ let hits;
871
+ try {
872
+ hits = kind.scan(text);
873
+ } catch (err) {
874
+ opts.onError?.(kind.id, err);
875
+ continue;
876
+ }
877
+ for (const h of hits) {
878
+ if (!valid(h, text.length)) {
879
+ opts.onError?.(kind.id, new Error(`invalid hit ${JSON.stringify([h.start, h.end])}`));
880
+ continue;
881
+ }
882
+ if (code.length && intersects(code, h.start, h.end)) continue;
883
+ cands.push({ ...h, kind });
884
+ }
885
+ }
886
+ const ranked = [...cands].sort(better);
887
+ const taken = [];
888
+ for (const c of ranked) {
889
+ let lo = 0;
890
+ let hi = taken.length;
891
+ while (lo < hi) {
892
+ const mid = lo + hi >> 1;
893
+ if (taken[mid].start < c.start) lo = mid + 1;
894
+ else hi = mid;
895
+ }
896
+ const prev = taken[lo - 1];
897
+ const next = taken[lo];
898
+ if (prev && prev.end > c.start || next && next.start < c.end) continue;
899
+ taken.splice(lo, 0, c);
900
+ }
901
+ return taken.map((c) => ({
902
+ type: "ref",
903
+ kind: c.kind.id,
904
+ canonical: c.canonical,
905
+ raw: text.slice(c.start, c.end),
906
+ start: c.start,
907
+ end: c.end,
908
+ ...c.meta ? { meta: c.meta } : {}
909
+ }));
910
+ }
911
+ function detect(text, registry2, opts = {}) {
912
+ const refs = detectRefs(text, registry2, opts);
913
+ const out = [];
914
+ let at = 0;
915
+ for (const r of refs) {
916
+ if (r.start > at) out.push({ type: "text", text: text.slice(at, r.start), start: at, end: r.start });
917
+ out.push(r);
918
+ at = r.end;
919
+ }
920
+ if (at < text.length) out.push({ type: "text", text: text.slice(at), start: at, end: text.length });
921
+ return out;
922
+ }
923
+ function refKey(kind, canonical) {
924
+ return `${kind}\0${canonical}`;
925
+ }
926
+
927
+ // ../../web/src/cite/core/preview.ts
928
+ function buildPreviewCard(registry2, ref, state2) {
929
+ const kind = registry2.get(ref.kind);
930
+ const base = {
931
+ kind: ref.kind,
932
+ kindLabel: kind?.label ?? ref.kind,
933
+ icon: kind?.icon ?? "link",
934
+ canonical: ref.canonical,
935
+ fields: [],
936
+ open: kind ? kind.open(ref) : { type: "none" },
937
+ ...kind?.openLabel ? { openLabel: kind.openLabel } : {}
938
+ };
939
+ const title = kind?.chipLabel?.(ref, ref.canonical) ?? ref.canonical;
940
+ switch (state2.status) {
941
+ case "found":
942
+ return {
943
+ ...base,
944
+ phase: "ready",
945
+ title: state2.entity.title,
946
+ subtitle: state2.entity.subtitle,
947
+ description: state2.entity.description,
948
+ status: state2.entity.status,
949
+ fields: state2.entity.fields ?? [],
950
+ updatedAt: state2.entity.updatedAt
951
+ };
952
+ case "loading":
953
+ return state2.stale ? {
954
+ ...base,
955
+ phase: "loading",
956
+ title: state2.stale.title,
957
+ subtitle: state2.stale.subtitle,
958
+ status: state2.stale.status,
959
+ fields: state2.stale.fields ?? []
960
+ } : { ...base, phase: "loading", title };
961
+ case "not-found":
962
+ return { ...base, phase: "not-found", title, subtitle: `${base.kindLabel} not found` };
963
+ case "error":
964
+ return {
965
+ ...base,
966
+ phase: "error",
967
+ title: state2.stale?.title ?? title,
968
+ error: state2.message,
969
+ fields: state2.stale?.fields ?? []
970
+ };
971
+ case "unsupported":
972
+ return { ...base, phase: "unresolved", title };
973
+ default:
974
+ return { ...base, phase: "loading", title };
975
+ }
976
+ }
977
+
978
+ // ../../web/src/cite/core/resolver.ts
979
+ var IDLE = { status: "idle" };
980
+ var UNSUPPORTED = { status: "unsupported" };
981
+ function createRefResolverClient(opts) {
982
+ const ttl = opts.ttlMs ?? 6e4;
983
+ const notFoundTtl = opts.notFoundTtlMs ?? 15e3;
984
+ const errorRetry = opts.errorRetryMs ?? 5e3;
985
+ const window2 = opts.batchWindowMs ?? 10;
986
+ const maxBatch = Math.max(1, opts.maxBatch ?? 50);
987
+ const now = opts.now ?? Date.now;
988
+ const states = /* @__PURE__ */ new Map();
989
+ const queue = /* @__PURE__ */ new Map();
990
+ const listeners4 = /* @__PURE__ */ new Set();
991
+ const aborter = new AbortController();
992
+ let timer = null;
993
+ let disposed = false;
994
+ const emit4 = () => {
995
+ for (const l of listeners4) l();
996
+ };
997
+ function fresh(s) {
998
+ const t = now();
999
+ switch (s.status) {
1000
+ case "loading":
1001
+ case "unsupported":
1002
+ return true;
1003
+ case "found":
1004
+ return t - s.fetchedAt < ttl;
1005
+ case "not-found":
1006
+ return t - s.fetchedAt < notFoundTtl;
1007
+ case "error":
1008
+ return t - s.fetchedAt < errorRetry;
1009
+ default:
1010
+ return false;
1011
+ }
1012
+ }
1013
+ function staleOf(s) {
1014
+ if (!s) return void 0;
1015
+ return s.status === "found" ? s.entity : s.status === "loading" || s.status === "error" ? s.stale : void 0;
1016
+ }
1017
+ async function runBatch(kind, canonicals) {
1018
+ const resolver = opts.resolvers[kind];
1019
+ if (!resolver) return;
1020
+ let result;
1021
+ let failure = null;
1022
+ try {
1023
+ result = await resolver.resolveMany(canonicals, { signal: aborter.signal });
1024
+ } catch (err) {
1025
+ if (disposed) return;
1026
+ result = {};
1027
+ failure = err instanceof Error ? err.message : String(err);
1028
+ }
1029
+ if (disposed) return;
1030
+ const at = now();
1031
+ for (const c of canonicals) {
1032
+ const key = refKey(kind, c);
1033
+ const prior = states.get(key);
1034
+ if (prior?.status !== "loading") continue;
1035
+ const stale = staleOf(prior);
1036
+ if (failure !== null) {
1037
+ states.set(key, { status: "error", message: failure, fetchedAt: at, ...stale ? { stale } : {} });
1038
+ continue;
1039
+ }
1040
+ const out = result[c];
1041
+ states.set(
1042
+ key,
1043
+ out?.status === "found" ? { status: "found", entity: out.entity, fetchedAt: at } : { status: "not-found", fetchedAt: at }
1044
+ );
1045
+ }
1046
+ emit4();
1047
+ }
1048
+ function flush() {
1049
+ timer = null;
1050
+ if (disposed) return;
1051
+ const byKind = /* @__PURE__ */ new Map();
1052
+ for (const { kind, canonical } of queue.values()) {
1053
+ const list = byKind.get(kind) ?? [];
1054
+ list.push(canonical);
1055
+ byKind.set(kind, list);
1056
+ }
1057
+ queue.clear();
1058
+ for (const [kind, list] of byKind) {
1059
+ for (let i = 0; i < list.length; i += maxBatch) void runBatch(kind, list.slice(i, i + maxBatch));
1060
+ }
1061
+ }
1062
+ return {
1063
+ get: (kind, canonical) => states.get(refKey(kind, canonical)) ?? IDLE,
1064
+ request(refs) {
1065
+ if (disposed) return;
1066
+ let changed = false;
1067
+ for (const { kind, canonical } of refs) {
1068
+ const key = refKey(kind, canonical);
1069
+ if (!opts.resolvers[kind]) {
1070
+ if (states.get(key)?.status !== "unsupported") {
1071
+ states.set(key, UNSUPPORTED);
1072
+ changed = true;
1073
+ }
1074
+ continue;
1075
+ }
1076
+ const prior = states.get(key);
1077
+ if (prior && fresh(prior)) continue;
1078
+ const stale = staleOf(prior);
1079
+ states.set(key, { status: "loading", ...stale ? { stale } : {} });
1080
+ queue.set(key, { kind, canonical });
1081
+ changed = true;
1082
+ }
1083
+ if (queue.size && timer === null) timer = setTimeout(flush, window2);
1084
+ if (changed) emit4();
1085
+ },
1086
+ invalidate(kind, canonical) {
1087
+ const again = [];
1088
+ for (const [key, s] of [...states]) {
1089
+ const [k, c] = key.split("\0");
1090
+ if (kind && k !== kind || canonical && c !== canonical) continue;
1091
+ if (s.status === "found" || s.status === "not-found" || s.status === "error") {
1092
+ states.set(key, { ...s, fetchedAt: -Infinity });
1093
+ again.push({ kind: k, canonical: c });
1094
+ }
1095
+ }
1096
+ this.request(again);
1097
+ },
1098
+ subscribe(listener) {
1099
+ listeners4.add(listener);
1100
+ return () => listeners4.delete(listener);
1101
+ },
1102
+ dispose() {
1103
+ disposed = true;
1104
+ if (timer !== null) clearTimeout(timer);
1105
+ timer = null;
1106
+ queue.clear();
1107
+ listeners4.clear();
1108
+ aborter.abort();
1109
+ }
1110
+ };
1111
+ }
1112
+
1113
+ // ../../web/src/cite/core/tach.ts
1114
+ var ULID2 = /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/;
1115
+ var TESSERACT = /* @__PURE__ */ new Set(["tesseract", "tess", "memory"]);
1116
+ var TORQUE = /* @__PURE__ */ new Set(["torque", "task", "tasks"]);
1117
+ var FRAGMENT = /* @__PURE__ */ new Set(["fragment", "frag", "fe"]);
1118
+ var MESSAGE2 = /* @__PURE__ */ new Set(["message", "msg"]);
1119
+ function parseTachHref(href) {
1120
+ const m = /^tach:\/{0,2}([A-Za-z][A-Za-z0-9_-]{0,31})\/(.+)$/i.exec((href ?? "").trim());
1121
+ if (!m) return null;
1122
+ const service = m[1].toLowerCase();
1123
+ let rest;
1124
+ try {
1125
+ rest = decodeURIComponent(m[2]).trim();
1126
+ } catch {
1127
+ return null;
1128
+ }
1129
+ if (!rest) return null;
1130
+ if (TESSERACT.has(service)) {
1131
+ const id = rest.toUpperCase();
1132
+ if (ULID2.test(id)) return { kind: TESSERACT_ITEM_KIND, canonical: id };
1133
+ return parseTesseractKey(rest) ? { kind: TESSERACT_KEY_KIND, canonical: rest } : null;
1134
+ }
1135
+ if (TORQUE.has(service)) {
1136
+ const id = rest.toUpperCase();
1137
+ const entity = TORQUE_ENTITIES.find((e) => new RegExp(`^${e.prefix}-\\d{8}-\\d{4}$`).test(id));
1138
+ return entity ? { kind: entity.id, canonical: id } : null;
1139
+ }
1140
+ if (FRAGMENT.has(service)) {
1141
+ return /^[0-9a-f]{64}$/i.test(rest) ? { kind: FRAGMENT_KIND, canonical: rest.toLowerCase() } : null;
1142
+ }
1143
+ if (MESSAGE2.has(service)) {
1144
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(rest) ? { kind: TETHER_MESSAGE_KIND, canonical: rest.toLowerCase() } : null;
1145
+ }
1146
+ if (service === "caster") {
1147
+ const ref = rest.startsWith("caster://") ? rest : `caster://${rest}`;
1148
+ return /^caster:\/\/[A-Za-z0-9_.-]{1,128}\/[A-Za-z0-9_.:-]{1,256}$/.test(ref) ? { kind: CASTER_KIND, canonical: ref } : null;
1149
+ }
1150
+ if (service === "work") {
1151
+ return /^[a-z0-9][a-z0-9-]{0,47}\/[a-z0-9]{8}$/.test(rest) ? { kind: WORK_ITEM_KIND, canonical: rest } : null;
1152
+ }
1153
+ return null;
1154
+ }
1155
+
1156
+ // ../../web/src/cite/core/index.ts
1157
+ function createDefaultRefRegistry() {
1158
+ const r = createRefRegistry();
1159
+ for (const k of [
1160
+ createUrlKind(),
1161
+ createFragmentKind(),
1162
+ ...createTesseractKinds(),
1163
+ ...createTorqueKinds(),
1164
+ ...createTetherKinds(),
1165
+ createCasterKind(),
1166
+ createWorkKind(),
1167
+ createRegistryKind(),
1168
+ createOpsKind(),
1169
+ ...createPathKinds()
1170
+ ]) {
1171
+ r.register(k);
1172
+ }
1173
+ return r;
1174
+ }
1175
+
1176
+ // ../../web/src/cite/store.ts
1177
+ var registry = createDefaultRefRegistry();
1178
+ function serverResolver(kind) {
1179
+ return {
1180
+ async resolveMany(canonicals) {
1181
+ const ids = canonicals.map(encodeURIComponent).join(",");
1182
+ const out = await call(
1183
+ "GET",
1184
+ `/api/cite/resolve?kind=${encodeURIComponent(kind)}&ids=${ids}`
1185
+ );
1186
+ const mapped = {};
1187
+ for (const id of canonicals) {
1188
+ const e = out.results[id];
1189
+ mapped[id] = e ? { status: "found", entity: e } : { status: "not-found" };
1190
+ }
1191
+ return mapped;
1192
+ }
1193
+ };
1194
+ }
1195
+ var client = createRefResolverClient({ resolvers: {} });
1196
+ var kinds = /* @__PURE__ */ new Map();
1197
+ var version = 0;
1198
+ var listeners2 = /* @__PURE__ */ new Set();
1199
+ var emit2 = () => {
1200
+ version++;
1201
+ for (const fn of listeners2) fn();
1202
+ };
1203
+ var unsubscribe = client.subscribe(emit2);
1204
+ var started = null;
1205
+ function initCite() {
1206
+ started ??= call("GET", "/api/cite").then((state2) => {
1207
+ kinds = new Map(state2.kinds.map((k) => [k.kind, k]));
1208
+ unsubscribe();
1209
+ client.dispose();
1210
+ client = createRefResolverClient({
1211
+ resolvers: Object.fromEntries(state2.kinds.map((k) => [k.kind, serverResolver(k.kind)]))
1212
+ });
1213
+ unsubscribe = client.subscribe(emit2);
1214
+ emit2();
1215
+ }).catch(() => {
1216
+ started = null;
1217
+ });
1218
+ return started ?? Promise.resolve();
1219
+ }
1220
+ var canResolve = (kind) => kinds.has(kind);
1221
+ var kindLabel = (kind) => kinds.get(kind)?.label ?? registry.get(kind)?.label ?? kind;
1222
+ var subscribe2 = (fn) => {
1223
+ listeners2.add(fn);
1224
+ return () => {
1225
+ listeners2.delete(fn);
1226
+ };
1227
+ };
1228
+ function useRefState(kind, canonical, fetch2) {
1229
+ useSyncExternalStore2(subscribe2, () => version);
1230
+ const state2 = client.get(kind, canonical);
1231
+ if (fetch2 && state2.status === "idle") queueMicrotask(() => client.request([{ kind, canonical }]));
1232
+ return state2;
1233
+ }
1234
+ var requestRef = (ref) => client.request([{ kind: ref.kind, canonical: ref.canonical }]);
1235
+ var segments = (text) => detect(text, registry);
1236
+ var loadRecord = (ref) => call(
1237
+ "GET",
1238
+ `/api/cite/record?kind=${encodeURIComponent(ref.kind)}&id=${encodeURIComponent(ref.canonical)}`
1239
+ );
1240
+ var hasCommand = (id) => app().commands.some((c) => c.id === id);
1241
+ function openURL(url) {
1242
+ if (hasCommand("browser.open"))
1243
+ void desk.run("browser.open", { url }).catch(() => window.open(url, "_blank", "noopener"));
1244
+ else window.open(url, "_blank", "noopener");
1245
+ }
1246
+ var openRecord = (ref) => desk.open("surface.cite", {
1247
+ key: `${ref.kind}:${ref.canonical}`,
1248
+ args: { kind: ref.kind, id: ref.canonical }
1249
+ });
1250
+ function openCite(ref) {
1251
+ const state2 = client.get(ref.kind, ref.canonical);
1252
+ const entity = state2.status === "found" ? state2.entity : void 0;
1253
+ if (entity?.open && hasCommand(entity.open.command)) {
1254
+ void desk.run(entity.open.command, entity.open.args ?? {}).catch(() => openRecord(ref));
1255
+ return;
1256
+ }
1257
+ if (ref.kind === "url") {
1258
+ openURL(ref.canonical);
1259
+ return;
1260
+ }
1261
+ if (canResolve(ref.kind)) {
1262
+ void openRecord(ref);
1263
+ return;
1264
+ }
1265
+ void navigator.clipboard?.writeText(ref.canonical).catch(() => void 0);
1266
+ }
1267
+
1268
+ // ../../web/src/cite/structured.ts
1269
+ function parseJSONDocument(text) {
1270
+ const t = text?.trim() ?? "";
1271
+ if (!(t.startsWith("{") && t.endsWith("}")) && !(t.startsWith("[") && t.endsWith("]"))) return void 0;
1272
+ try {
1273
+ const exact = (_key, v2, ctx) => typeof v2 === "number" && ctx?.source !== void 0 && String(v2) !== ctx.source ? ctx.source : v2;
1274
+ const v = JSON.parse(t, exact);
1275
+ return v && typeof v === "object" ? v : void 0;
1276
+ } catch {
1277
+ return void 0;
1278
+ }
1279
+ }
1280
+ function humanize(key) {
1281
+ const words = key.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").trim().toLowerCase();
1282
+ return words ? words[0].toUpperCase() + words.slice(1) : key;
1283
+ }
1284
+ var ISO = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?$/;
1285
+ var IDLIKE = /^(?:[0-9A-HJKMNP-TV-Z]{26}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9a-f]{16,64}|[a-z][a-z0-9+.-]*:\/\/\S+|[A-Z]{2,4}-\d{8}-\d{4})$/;
1286
+ var LONG_TEXT = 120;
1287
+ function looksLikeMarkdown(s) {
1288
+ return /^(#{1,6} |[-*+] |\d+\. |```|> |\|.*\|\s*$)/m.test(s) || /\*\*[^*]+\*\*|\[[^\]]+\]\([^)]+\)/.test(s);
1289
+ }
1290
+ var TITLE_KEYS = ["title", "subject", "name", "label", "heading", "summary"];
1291
+ var ID_KEYS = ["id", "key", "ref", "slug", "uuid"];
1292
+ function scalar(v) {
1293
+ if (v === null || v === void 0) return { type: "scalar", text: "none", empty: true };
1294
+ if (typeof v === "boolean") return { type: "scalar", text: v ? "yes" : "no" };
1295
+ if (typeof v === "number") return { type: "scalar", text: String(v) };
1296
+ const s = String(v);
1297
+ if (s === "") return { type: "scalar", text: "empty", empty: true };
1298
+ if (ISO.test(s) && !Number.isNaN(Date.parse(s))) return { type: "scalar", text: s, iso: s };
1299
+ return { type: "scalar", text: s, mono: IDLIKE.test(s) };
1300
+ }
1301
+ var isObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
1302
+ var isScalar = (v) => v === null || typeof v !== "object";
1303
+ function shortText(v) {
1304
+ if (typeof v === "string" && v.trim() && v.length <= LONG_TEXT && !v.includes("\n")) return v.trim();
1305
+ if (typeof v === "number") return String(v);
1306
+ return void 0;
1307
+ }
1308
+ function titleOf(o, index) {
1309
+ const id = ID_KEYS.find((k) => shortText(o[k]));
1310
+ const named = TITLE_KEYS.find((k) => shortText(o[k]));
1311
+ if (named) {
1312
+ const title = shortText(o[named]);
1313
+ return id ? { title, subtitle: shortText(o[id]), used: [named, id] } : { title, used: [named] };
1314
+ }
1315
+ if (id) return { title: shortText(o[id]), used: [id] };
1316
+ return { title: `Item ${index + 1}`, used: [] };
1317
+ }
1318
+ var isInline = (f) => f.node.type === "scalar" || f.node.type === "values" && f.node.values.length <= 8;
1319
+ var MAX_DEPTH = 5;
1320
+ function toDocNode(v, depth = 0) {
1321
+ if (isScalar(v)) {
1322
+ if (typeof v === "string" && (v.length > LONG_TEXT || v.includes("\n")))
1323
+ return { type: "text", text: v, markdown: looksLikeMarkdown(v) };
1324
+ return scalar(v);
1325
+ }
1326
+ if (depth >= MAX_DEPTH) return { type: "json", text: JSON.stringify(v, null, 2) };
1327
+ if (Array.isArray(v)) {
1328
+ if (v.length > 0 && v.every(isObject))
1329
+ return {
1330
+ type: "list",
1331
+ items: v.map((o, i) => {
1332
+ const { title, subtitle, used } = titleOf(o, i);
1333
+ const rest = Object.fromEntries(Object.entries(o).filter(([k]) => !used.includes(k)));
1334
+ return { title, ...subtitle ? { subtitle } : {}, fields: fieldsOf(rest, depth + 1) };
1335
+ })
1336
+ };
1337
+ if (v.every(isScalar) && v.every((x) => typeof x !== "string" || x.length <= LONG_TEXT && !x.includes("\n")))
1338
+ return { type: "values", values: v.map((x) => scalar(x).text) };
1339
+ return {
1340
+ type: "fields",
1341
+ fields: v.map((x, i) => ({ key: String(i), label: `${i + 1}`, node: toDocNode(x, depth + 1) }))
1342
+ };
1343
+ }
1344
+ return { type: "fields", fields: fieldsOf(v, depth) };
1345
+ }
1346
+ function fieldsOf(o, depth = 0) {
1347
+ const all = Object.entries(o).map(([key, val]) => ({ key, label: humanize(key), node: toDocNode(val, depth + 1) }));
1348
+ return [...all.filter(isInline), ...all.filter((f) => !isInline(f))];
1349
+ }
1350
+ function splitFrontMatter(text) {
1351
+ const m = /^\s*---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/.exec(text);
1352
+ if (!m) return void 0;
1353
+ const fields = [];
1354
+ for (const line of m[1].split(/\r?\n/)) {
1355
+ const kv = /^([A-Za-z0-9_.-]+):[ \t]*(.*)$/.exec(line);
1356
+ if (!kv) continue;
1357
+ const value = kv[2].trim().replace(/^(["'])(.*)\1$/, "$2");
1358
+ if (value) fields.push({ key: kv[1], label: humanize(kv[1]), node: scalar(value) });
1359
+ }
1360
+ return { fields, rest: text.slice(m[0].length) };
1361
+ }
1362
+ var LIST_PAGE = 50;
1363
+ var MAX_LAYOUT_BYTES = 512 << 10;
1364
+ var MAX_LAYOUT_VALUES = 5e3;
1365
+ function fitsLayout(text, doc) {
1366
+ if (text.length > MAX_LAYOUT_BYTES) return false;
1367
+ let n = 0;
1368
+ const walk = (v) => {
1369
+ if (++n > MAX_LAYOUT_VALUES) return false;
1370
+ if (v && typeof v === "object") {
1371
+ for (const x of Object.values(v)) if (!walk(x)) return false;
1372
+ }
1373
+ return true;
1374
+ };
1375
+ return walk(doc);
1376
+ }
1377
+ function fenced(text, lang) {
1378
+ let ticks = "```";
1379
+ while (text.includes(ticks)) ticks += "`";
1380
+ return `${ticks}${lang}
1381
+ ${text}
1382
+ ${ticks}`;
1383
+ }
1384
+
1385
+ // ../../web/src/cite/structured-view.tsx
1386
+ import { useState as useState2 } from "react";
1387
+ import { Badge } from "@/components/ui/badge";
1388
+ import { Button as Button2 } from "@/components/ui/button";
1389
+ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
1390
+ import { Markdown } from "@/components/ui/markdown";
1391
+
1392
+ // ../../web/src/cite/ui.tsx
1393
+ import {
1394
+ Bot,
1395
+ Boxes,
1396
+ Brain,
1397
+ Copy,
1398
+ ExternalLink,
1399
+ FileText,
1400
+ Folder,
1401
+ Layers,
1402
+ Link2,
1403
+ ListChecks,
1404
+ Mail,
1405
+ Maximize2,
1406
+ NotebookText,
1407
+ Radar,
1408
+ Target,
1409
+ Zap
1410
+ } from "lucide-react";
1411
+ import { useState } from "react";
1412
+ import { Button } from "@/components/ui/button";
1413
+ import { CiteCard } from "@/components/ui/cite-card";
1414
+ import { CiteChip } from "@/components/ui/cite-chip";
1415
+ import { HoverCard, HoverCardContent, HoverCardTrigger } from "@/components/ui/hover-card";
1416
+
1417
+ // ../../web/src/cite/remark.ts
1418
+ var CITE_ELEMENT = "cite";
1419
+ var CITE_ATTR = {
1420
+ kind: "data-cite-kind",
1421
+ id: "data-cite-id",
1422
+ label: "data-cite-label",
1423
+ mono: "data-cite-mono"
1424
+ };
1425
+ function citeNode(kind, canonical, raw, label, mono) {
1426
+ const props = { dataCiteKind: kind, dataCiteId: canonical };
1427
+ if (label) props.dataCiteLabel = label;
1428
+ if (mono) props.dataCiteMono = "true";
1429
+ return { type: "cite", data: { hName: CITE_ELEMENT, hProperties: props }, children: [{ type: "text", value: raw }] };
1430
+ }
1431
+ function textOf(n) {
1432
+ if (typeof n.value === "string") return n.value;
1433
+ return (n.children ?? []).map(textOf).join("");
1434
+ }
1435
+ var SKIP = /* @__PURE__ */ new Set(["code", "inlineCode", "html", "definition", "linkReference", "imageReference", "image", "cite"]);
1436
+ function citeTransform(registry2, tree) {
1437
+ const walk = (parent) => {
1438
+ const kids = parent.children;
1439
+ if (!kids) return;
1440
+ const out = [];
1441
+ for (const n of kids) {
1442
+ if (SKIP.has(n.type)) {
1443
+ out.push(n);
1444
+ continue;
1445
+ }
1446
+ if (n.type === "text" && n.value) {
1447
+ for (const s of detect(n.value, registry2, { skipCode: false })) {
1448
+ out.push(s.type === "text" ? { type: "text", value: s.text } : citeNode(s.kind, s.canonical, s.raw));
1449
+ }
1450
+ continue;
1451
+ }
1452
+ if (n.type === "link") {
1453
+ const label = textOf(n).trim();
1454
+ const tach = parseTachHref(n.url);
1455
+ if (tach) {
1456
+ out.push(citeNode(tach.kind, tach.canonical, label || tach.canonical, label || void 0));
1457
+ continue;
1458
+ }
1459
+ const url = n.url ?? "";
1460
+ const refs = url ? detectRefs(url, registry2, { skipCode: false }) : [];
1461
+ const whole = refs.length === 1 && refs[0].start === 0 && refs[0].end === url.length ? refs[0] : null;
1462
+ const bare = label === url || label === url.replace(/^mailto:/, "") || `https://${label}` === url || `http://${label}` === url;
1463
+ if (whole && (whole.kind !== "url" || bare)) {
1464
+ out.push(citeNode(whole.kind, whole.canonical, label || whole.raw, bare ? void 0 : label));
1465
+ continue;
1466
+ }
1467
+ out.push(n);
1468
+ continue;
1469
+ }
1470
+ walk(n);
1471
+ out.push(n);
1472
+ }
1473
+ parent.children = out;
1474
+ };
1475
+ walk(tree);
1476
+ }
1477
+ function createRemarkCite(registry2) {
1478
+ return function remarkCite2() {
1479
+ return (tree) => citeTransform(registry2, tree);
1480
+ };
1481
+ }
1482
+
1483
+ // ../../web/src/cite/ui.tsx
1484
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
1485
+ var ICONS = {
1486
+ "torque.task": ListChecks,
1487
+ "torque.epic": Layers,
1488
+ "torque.project": Layers,
1489
+ "torque.sprint": Layers,
1490
+ "torque.plan": Layers,
1491
+ "tesseract.item": Brain,
1492
+ "tesseract.key": Brain,
1493
+ "tether.agent": Bot,
1494
+ "tether.message": Mail,
1495
+ "caster.doc": NotebookText,
1496
+ "work.item": Target,
1497
+ "registry.record": Boxes,
1498
+ "ops.workstream": Radar,
1499
+ path: FileText,
1500
+ "path.relative": FileText,
1501
+ url: Link2,
1502
+ "fragments.fragment": Zap
1503
+ };
1504
+ var iconFor = (kind) => ICONS[kind] ?? Link2;
1505
+ var clip = (s, n) => s.length > n ? `${s.slice(0, n - 1)}\u2026` : s;
1506
+ function ago(iso) {
1507
+ if (!iso) return void 0;
1508
+ const ms = Date.now() - new Date(iso).getTime();
1509
+ if (Number.isNaN(ms)) return void 0;
1510
+ const m = Math.round(ms / 6e4);
1511
+ if (m < 1) return "just now";
1512
+ if (m < 60) return `${m}m ago`;
1513
+ const h = Math.round(m / 60);
1514
+ if (h < 48) return `${h}h ago`;
1515
+ return `${Math.round(h / 24)}d ago`;
1516
+ }
1517
+ var updatedAgo = (iso) => {
1518
+ const a = ago(iso);
1519
+ return a ? `updated ${a}` : void 0;
1520
+ };
1521
+ var subtitleFor = (kind, subtitle) => subtitle && subtitle.trim().toLowerCase() !== kindLabel(kind).toLowerCase() ? subtitle : void 0;
1522
+ function hostOf(url) {
1523
+ try {
1524
+ return new URL(url).host;
1525
+ } catch {
1526
+ return url;
1527
+ }
1528
+ }
1529
+ var NOTES = {
1530
+ "not-found": "It may have been deleted, or it may not be readable.",
1531
+ unresolved: "No preview for this kind yet."
1532
+ };
1533
+ function RefCard({ refId }) {
1534
+ const state2 = useRefState(refId.kind, refId.canonical, canResolve(refId.kind));
1535
+ const card = buildPreviewCard(registry, refId, state2);
1536
+ const Icon2 = refId.kind === "path" && state2.status === "found" && state2.entity.subtitle?.startsWith("Folder") ? Folder : iconFor(refId.kind);
1537
+ const entity = state2.status === "found" ? state2.entity : void 0;
1538
+ const isURL = refId.kind === "url";
1539
+ const [copied, setCopied] = useState(false);
1540
+ const copy = () => void navigator.clipboard?.writeText(refId.canonical).then(() => setCopied(true)).catch(() => void 0);
1541
+ const openable = (isURL || canResolve(refId.kind)) && card.phase !== "not-found";
1542
+ const title = card.phase === "not-found" ? "Not found" : card.phase === "error" ? "Could not be looked up" : isURL ? hostOf(refId.canonical) : card.title;
1543
+ return /* @__PURE__ */ jsx(
1544
+ CiteCard,
1545
+ {
1546
+ phase: card.phase,
1547
+ icon: /* @__PURE__ */ jsx(Icon2, {}),
1548
+ kindLabel: kindLabel(refId.kind),
1549
+ canonical: refId.canonical,
1550
+ title,
1551
+ subtitle: isURL ? "A web page. Its address is shown as written; nothing is fetched to preview it." : card.phase === "ready" ? subtitleFor(refId.kind, card.subtitle) : void 0,
1552
+ note: isURL ? void 0 : NOTES[card.phase],
1553
+ description: card.description,
1554
+ status: card.status ? { label: card.status.label, tone: card.status.tone } : void 0,
1555
+ fields: card.fields,
1556
+ updated: updatedAgo(card.updatedAt),
1557
+ error: card.phase === "error" ? card.error : void 0,
1558
+ actions: /* @__PURE__ */ jsxs(Fragment, { children: [
1559
+ /* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "xs", onClick: copy, children: [
1560
+ /* @__PURE__ */ jsx(Copy, {}),
1561
+ copied ? "Copied" : "Copy id"
1562
+ ] }),
1563
+ entity?.url ? /* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "xs", onClick: () => openURL(entity.url), children: [
1564
+ /* @__PURE__ */ jsx(ExternalLink, {}),
1565
+ hostOf(entity.url)
1566
+ ] }) : null,
1567
+ entity?.open && canResolve(refId.kind) ? /* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "xs", onClick: () => void openRecord(refId), children: [
1568
+ /* @__PURE__ */ jsx(Maximize2, {}),
1569
+ "Record"
1570
+ ] }) : null,
1571
+ openable ? /* @__PURE__ */ jsxs(Button, { variant: "outline", size: "xs", onClick: () => openCite(refId), children: [
1572
+ isURL ? /* @__PURE__ */ jsx(ExternalLink, {}) : /* @__PURE__ */ jsx(Maximize2, {}),
1573
+ "Open"
1574
+ ] }) : null
1575
+ ] })
1576
+ }
1577
+ );
1578
+ }
1579
+ var chipState = (s) => s === "found" || s === "not-found" || s === "error" || s === "loading" || s === "unsupported" ? s : "idle";
1580
+ function CiteRef({
1581
+ refId,
1582
+ raw,
1583
+ label,
1584
+ mono
1585
+ }) {
1586
+ const resolvable = canResolve(refId.kind);
1587
+ const state2 = useRefState(refId.kind, refId.canonical, resolvable);
1588
+ const Icon2 = iconFor(refId.kind);
1589
+ const kind = registry.get(refId.kind);
1590
+ const written = label ?? kind?.chipLabel?.(refId, raw ?? refId.canonical) ?? raw ?? refId.canonical;
1591
+ const text = state2.status === "found" && state2.entity.chipLabel && !label ? state2.entity.chipLabel : written;
1592
+ return /* @__PURE__ */ jsxs(HoverCard, { onOpenChange: (open) => open && resolvable && requestRef(refId), children: [
1593
+ /* @__PURE__ */ jsx(
1594
+ HoverCardTrigger,
1595
+ {
1596
+ delay: 300,
1597
+ closeDelay: 150,
1598
+ render: /* @__PURE__ */ jsx(
1599
+ CiteChip,
1600
+ {
1601
+ icon: /* @__PURE__ */ jsx(Icon2, { "aria-hidden": "true" }),
1602
+ label: clip(text, 56),
1603
+ state: resolvable ? chipState(state2.status) : "unsupported",
1604
+ mono: mono && text === written,
1605
+ "data-kind": refId.kind,
1606
+ "aria-label": `${kindLabel(refId.kind)}: ${text}`,
1607
+ onClick: (e) => {
1608
+ e.preventDefault();
1609
+ e.stopPropagation();
1610
+ openCite(refId);
1611
+ }
1612
+ }
1613
+ )
1614
+ }
1615
+ ),
1616
+ /* @__PURE__ */ jsx(HoverCardContent, { className: "w-92", align: "start", children: /* @__PURE__ */ jsx(RefCard, { refId }) })
1617
+ ] });
1618
+ }
1619
+ function CiteText({ text }) {
1620
+ return /* @__PURE__ */ jsx(Fragment, { children: segments(text).map(
1621
+ (s) => s.type === "text" ? s.text : /* @__PURE__ */ jsx(
1622
+ CiteRef,
1623
+ {
1624
+ refId: { kind: s.kind, canonical: s.canonical, meta: s.meta },
1625
+ raw: s.raw
1626
+ },
1627
+ `${s.start}:${s.kind}`
1628
+ )
1629
+ ) });
1630
+ }
1631
+ var remarkCite = createRemarkCite(registry);
1632
+ function CiteElement({
1633
+ node: _node,
1634
+ children,
1635
+ ...props
1636
+ }) {
1637
+ const p = props;
1638
+ const kind = p[CITE_ATTR.kind];
1639
+ const id = p[CITE_ATTR.id];
1640
+ if (!kind || !id) return /* @__PURE__ */ jsx("cite", { ...props, children });
1641
+ const raw = typeof children === "string" ? children : Array.isArray(children) ? children.join("") : id;
1642
+ return /* @__PURE__ */ jsx(CiteRef, { refId: { kind, canonical: id }, raw, label: p[CITE_ATTR.label], mono: p[CITE_ATTR.mono] === "true" });
1643
+ }
1644
+ var citeMarkdownExtensions = {
1645
+ remarkPlugins: [remarkCite],
1646
+ components: { [CITE_ELEMENT]: CiteElement }
1647
+ };
1648
+
1649
+ // ../../web/src/cite/structured-view.tsx
1650
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
1651
+ function Scalar({ node }) {
1652
+ if (node.iso)
1653
+ return /* @__PURE__ */ jsx2("time", { dateTime: node.iso, title: node.iso, children: ago(node.iso) ?? node.text });
1654
+ if (node.empty) return /* @__PURE__ */ jsx2("span", { className: "text-muted-foreground italic", children: node.text });
1655
+ return /* @__PURE__ */ jsx2("span", { className: node.mono ? "font-mono text-xs break-all" : "break-words", children: /* @__PURE__ */ jsx2(CiteText, { text: node.text }) });
1656
+ }
1657
+ function Values({ values }) {
1658
+ if (values.length === 0) return /* @__PURE__ */ jsx2("span", { className: "text-muted-foreground italic", children: "none" });
1659
+ return /* @__PURE__ */ jsx2("span", { className: "flex flex-wrap gap-1", children: values.map((v, i) => (
1660
+ // biome-ignore lint/suspicious/noArrayIndexKey: values of one fixed document, in order
1661
+ /* @__PURE__ */ jsx2(Badge, { variant: "secondary", children: v }, i)
1662
+ )) });
1663
+ }
1664
+ function Text({ node }) {
1665
+ return node.markdown ? /* @__PURE__ */ jsx2(Markdown, { children: node.text }) : /* @__PURE__ */ jsx2("p", { className: "text-sm leading-relaxed break-words whitespace-pre-wrap", children: /* @__PURE__ */ jsx2(CiteText, { text: node.text }) });
1666
+ }
1667
+ function DocFields({ fields }) {
1668
+ const inline = fields.filter(isInline);
1669
+ const blocks = fields.filter((f) => !isInline(f));
1670
+ return /* @__PURE__ */ jsxs2("div", { className: "flex min-w-0 flex-col gap-4", children: [
1671
+ inline.length > 0 ? /* @__PURE__ */ jsx2("dl", { className: "grid grid-cols-[minmax(5.5rem,max-content)_minmax(0,1fr)] gap-x-4 gap-y-1 text-sm", children: inline.map((f) => /* @__PURE__ */ jsxs2("div", { className: "contents", children: [
1672
+ /* @__PURE__ */ jsx2("dt", { className: "text-muted-foreground", children: f.label }),
1673
+ /* @__PURE__ */ jsx2("dd", { className: "min-w-0", children: /* @__PURE__ */ jsx2(DocValue, { node: f.node }) })
1674
+ ] }, f.key)) }) : null,
1675
+ blocks.map((f) => /* @__PURE__ */ jsxs2("section", { className: "flex min-w-0 flex-col gap-2", children: [
1676
+ /* @__PURE__ */ jsxs2("h3", { className: "flex items-center gap-2 text-xs font-medium tracking-wider text-muted-foreground uppercase", children: [
1677
+ f.label,
1678
+ f.node.type === "list" ? /* @__PURE__ */ jsx2(Badge, { variant: "secondary", children: f.node.items.length }) : null
1679
+ ] }),
1680
+ /* @__PURE__ */ jsx2(DocValue, { node: f.node })
1681
+ ] }, f.key))
1682
+ ] });
1683
+ }
1684
+ function DocValue({ node }) {
1685
+ switch (node.type) {
1686
+ case "scalar":
1687
+ return /* @__PURE__ */ jsx2(Scalar, { node });
1688
+ case "values":
1689
+ return /* @__PURE__ */ jsx2(Values, { values: node.values });
1690
+ case "text":
1691
+ return /* @__PURE__ */ jsx2(Text, { node });
1692
+ case "fields":
1693
+ return node.fields.length ? /* @__PURE__ */ jsx2("div", { className: "border-l border-border pl-3", children: /* @__PURE__ */ jsx2(DocFields, { fields: node.fields }) }) : /* @__PURE__ */ jsx2("span", { className: "text-muted-foreground italic", children: "empty" });
1694
+ case "list":
1695
+ return /* @__PURE__ */ jsx2(DocList, { items: node.items });
1696
+ case "json":
1697
+ return /* @__PURE__ */ jsx2(Markdown, { children: `\`\`\`json
1698
+ ${node.text}
1699
+ \`\`\`` });
1700
+ }
1701
+ }
1702
+ function DocList({ items }) {
1703
+ const [shown, setShown] = useState2(LIST_PAGE);
1704
+ const left = items.length - shown;
1705
+ return /* @__PURE__ */ jsxs2("div", { className: "flex min-w-0 flex-col gap-2", children: [
1706
+ items.slice(0, shown).map((item, i) => (
1707
+ // biome-ignore lint/suspicious/noArrayIndexKey: items of one fixed document, in order
1708
+ /* @__PURE__ */ jsxs2(Card, { size: "sm", children: [
1709
+ /* @__PURE__ */ jsxs2(CardHeader, { children: [
1710
+ /* @__PURE__ */ jsx2(CardTitle, { children: item.title }),
1711
+ item.subtitle ? /* @__PURE__ */ jsx2(CardDescription, { children: /* @__PURE__ */ jsx2("code", { className: "font-mono text-xs break-all", children: item.subtitle }) }) : null
1712
+ ] }),
1713
+ item.fields.length ? /* @__PURE__ */ jsx2(CardContent, { children: /* @__PURE__ */ jsx2(DocFields, { fields: item.fields }) }) : null
1714
+ ] }, i)
1715
+ )),
1716
+ left > 0 ? /* @__PURE__ */ jsxs2(Button2, { variant: "outline", size: "sm", className: "self-start", onClick: () => setShown((n) => n + LIST_PAGE), children: [
1717
+ "Show ",
1718
+ Math.min(left, LIST_PAGE),
1719
+ " more of ",
1720
+ left
1721
+ ] }) : null
1722
+ ] });
1723
+ }
1724
+
1725
+ // ../../web/src/cite/record.tsx
1726
+ import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
1727
+ function RecordBody({ body }) {
1728
+ const front = useMemo(() => parseJSONDocument(body) ? void 0 : splitFrontMatter(body), [body]);
1729
+ const json = front ? front.rest : body;
1730
+ const doc = useMemo(() => parseJSONDocument(json), [json]);
1731
+ const fits = useMemo(() => doc ? fitsLayout(json, doc) : false, [json, doc]);
1732
+ const node = useMemo(() => doc && fits ? toDocNode(doc) : void 0, [doc, fits]);
1733
+ const [mode, setMode] = useState3("fields");
1734
+ const head = front?.fields.length ? /* @__PURE__ */ jsx3(DocFields, { fields: front.fields }) : null;
1735
+ if (doc && !fits)
1736
+ return /* @__PURE__ */ jsxs3("div", { className: "flex min-w-0 flex-col gap-3", children: [
1737
+ head,
1738
+ /* @__PURE__ */ jsx3("p", { className: "text-xs text-muted-foreground", children: "This JSON document is too large to lay out; it is shown as it is." }),
1739
+ /* @__PURE__ */ jsx3("pre", { className: "font-mono text-xs break-all whitespace-pre-wrap", children: json })
1740
+ ] });
1741
+ if (!node)
1742
+ return front ? /* @__PURE__ */ jsxs3("div", { className: "flex min-w-0 flex-col gap-4", children: [
1743
+ head,
1744
+ /* @__PURE__ */ jsx3(Markdown2, { children: front.rest })
1745
+ ] }) : /* @__PURE__ */ jsx3(Markdown2, { children: body });
1746
+ return /* @__PURE__ */ jsxs3("div", { className: "flex min-w-0 flex-col gap-3", children: [
1747
+ head,
1748
+ /* @__PURE__ */ jsxs3(
1749
+ ToggleGroup,
1750
+ {
1751
+ variant: "outline",
1752
+ size: "sm",
1753
+ spacing: 0,
1754
+ value: [mode],
1755
+ onValueChange: (v) => v[0] && setMode(v[0]),
1756
+ "aria-label": "How the document is shown",
1757
+ children: [
1758
+ /* @__PURE__ */ jsxs3(ToggleGroupItem, { value: "fields", "aria-label": "As fields", children: [
1759
+ /* @__PURE__ */ jsx3(ListTree, {}),
1760
+ "Fields"
1761
+ ] }),
1762
+ /* @__PURE__ */ jsxs3(ToggleGroupItem, { value: "raw", "aria-label": "As raw JSON", children: [
1763
+ /* @__PURE__ */ jsx3(Braces, {}),
1764
+ "JSON"
1765
+ ] })
1766
+ ]
1767
+ }
1768
+ ),
1769
+ mode === "fields" ? /* @__PURE__ */ jsx3(DocValue, { node }) : /* @__PURE__ */ jsx3(Markdown2, { children: fenced(json.trim(), "json") })
1770
+ ] });
1771
+ }
1772
+ function CiteRecordView({ win, desk: desk2 }) {
1773
+ const kind = String(win.args?.kind ?? "");
1774
+ const id = String(win.args?.id ?? "");
1775
+ const [rec, setRec] = useState3(null);
1776
+ const [error, setError] = useState3("");
1777
+ const [busy, setBusy] = useState3(false);
1778
+ const load = useCallback(() => {
1779
+ if (!kind || !id) return;
1780
+ setBusy(true);
1781
+ setError("");
1782
+ loadRecord({ kind, canonical: id }).then((r) => {
1783
+ setRec(r);
1784
+ void desk2.setTitle(win.id, r.chipLabel || r.title);
1785
+ }).catch((err) => setError(err.message)).finally(() => setBusy(false));
1786
+ }, [kind, id, desk2, win.id]);
1787
+ useEffect(load, [load]);
1788
+ useEffect(() => desk2.report(win.id, { kind: "record", ref: `cite:${kind}:${id}` }), [desk2, win.id, kind, id]);
1789
+ const Icon2 = iconFor(kind);
1790
+ if (!rec && error)
1791
+ return /* @__PURE__ */ jsxs3(Empty, { className: "h-full", children: [
1792
+ /* @__PURE__ */ jsxs3(EmptyHeader, { children: [
1793
+ /* @__PURE__ */ jsx3(EmptyTitle, { children: kindLabel(kind) }),
1794
+ /* @__PURE__ */ jsx3(EmptyDescription, { children: error })
1795
+ ] }),
1796
+ /* @__PURE__ */ jsxs3(Button3, { variant: "outline", size: "sm", onClick: load, children: [
1797
+ /* @__PURE__ */ jsx3(RefreshCw, {}),
1798
+ "Try again"
1799
+ ] })
1800
+ ] });
1801
+ if (!rec)
1802
+ return /* @__PURE__ */ jsx3("div", { className: "grid h-full place-items-center", children: /* @__PURE__ */ jsx3(Spinner, {}) });
1803
+ return /* @__PURE__ */ jsxs3("div", { className: "flex h-full min-h-0 flex-col", children: [
1804
+ /* @__PURE__ */ jsx3("div", { className: "border-b border-border p-4", children: /* @__PURE__ */ jsx3(
1805
+ CiteRecordHeader,
1806
+ {
1807
+ icon: /* @__PURE__ */ jsx3(Icon2, {}),
1808
+ kindLabel: kindLabel(kind),
1809
+ canonical: id,
1810
+ title: rec.title,
1811
+ subtitle: subtitleFor(kind, rec.subtitle),
1812
+ status: rec.status ? { label: rec.status.label, tone: rec.status.tone } : void 0,
1813
+ fields: rec.fields,
1814
+ renderValue: (f) => f.mono ? /* @__PURE__ */ jsx3(CiteText, { text: f.value }) : f.value,
1815
+ updated: updatedAgo(rec.updatedAt),
1816
+ error: error || void 0,
1817
+ actions: /* @__PURE__ */ jsxs3(Fragment2, { children: [
1818
+ /* @__PURE__ */ jsxs3(Button3, { variant: "ghost", size: "xs", onClick: load, disabled: busy, children: [
1819
+ /* @__PURE__ */ jsx3(RefreshCw, {}),
1820
+ "Reload"
1821
+ ] }),
1822
+ rec.url ? /* @__PURE__ */ jsxs3(Button3, { variant: "ghost", size: "xs", onClick: () => openURL(rec.url), children: [
1823
+ /* @__PURE__ */ jsx3(ExternalLink2, {}),
1824
+ "Open the source"
1825
+ ] }) : null,
1826
+ rec.open ? /* @__PURE__ */ jsxs3(
1827
+ Button3,
1828
+ {
1829
+ variant: "outline",
1830
+ size: "xs",
1831
+ onClick: () => void desk2.run(rec.open?.command ?? "", rec.open?.args ?? {}),
1832
+ children: [
1833
+ /* @__PURE__ */ jsx3(SquareArrowOutUpRight, {}),
1834
+ "Open in its window"
1835
+ ]
1836
+ }
1837
+ ) : null
1838
+ ] })
1839
+ }
1840
+ ) }),
1841
+ /* @__PURE__ */ jsx3("div", { className: "min-h-0 flex-1 overflow-auto p-4", children: rec.body ? /* @__PURE__ */ jsx3(RecordBody, { body: rec.body }) : /* @__PURE__ */ jsx3("p", { className: "text-muted-foreground", children: rec.description || "Nothing more to show." }) })
1842
+ ] });
1843
+ }
1844
+
1845
+ // ../../web/src/cite/terminal.tsx
1846
+ import { useSyncExternalStore as useSyncExternalStore3 } from "react";
1847
+ import { jsx as jsx4 } from "react/jsx-runtime";
1848
+ var current = null;
1849
+ var hideTimer = 0;
1850
+ var listeners3 = /* @__PURE__ */ new Set();
1851
+ var emit3 = () => {
1852
+ for (const l of listeners3) l();
1853
+ };
1854
+ function show(ref, x, y) {
1855
+ window.clearTimeout(hideTimer);
1856
+ requestRef(ref);
1857
+ current = { ref, x, y };
1858
+ emit3();
1859
+ }
1860
+ function hideSoon() {
1861
+ window.clearTimeout(hideTimer);
1862
+ hideTimer = window.setTimeout(() => {
1863
+ current = null;
1864
+ emit3();
1865
+ }, 250);
1866
+ }
1867
+ var unlinked = /* @__PURE__ */ new Set(["url", "path"]);
1868
+ function citeTerminalLinks(term) {
1869
+ return {
1870
+ provideLinks(y, callback) {
1871
+ const line = term.buffer.active.getLine(y - 1);
1872
+ if (!line) {
1873
+ callback(void 0);
1874
+ return;
1875
+ }
1876
+ const links = [];
1877
+ for (const s of segments(line.translateToString(true))) {
1878
+ if (s.type !== "ref" || unlinked.has(s.kind) || !canResolve(s.kind)) continue;
1879
+ const ref = { kind: s.kind, canonical: s.canonical, meta: s.meta };
1880
+ links.push({
1881
+ range: { start: { x: s.start + 1, y }, end: { x: s.end, y } },
1882
+ text: s.raw,
1883
+ activate: () => openCite(ref),
1884
+ hover: (e) => show(ref, e.clientX, e.clientY),
1885
+ leave: hideSoon
1886
+ });
1887
+ }
1888
+ callback(links.length ? links : void 0);
1889
+ }
1890
+ };
1891
+ }
1892
+ function CiteFloat() {
1893
+ const f = useSyncExternalStore3(
1894
+ (l) => {
1895
+ listeners3.add(l);
1896
+ return () => listeners3.delete(l);
1897
+ },
1898
+ () => current
1899
+ );
1900
+ if (!f) return null;
1901
+ const left = Math.max(8, Math.min(f.x - 12, window.innerWidth - 336));
1902
+ const below = f.y + 16 + 260 < window.innerHeight;
1903
+ return /* @__PURE__ */ jsx4(
1904
+ "div",
1905
+ {
1906
+ role: "dialog",
1907
+ "aria-label": "Reference",
1908
+ className: "fixed z-50 w-92 rounded-lg border bg-popover p-3 text-popover-foreground shadow-md",
1909
+ style: below ? { left, top: f.y + 14 } : { left, bottom: window.innerHeight - f.y + 14 },
1910
+ onMouseEnter: () => window.clearTimeout(hideTimer),
1911
+ onMouseLeave: hideSoon,
1912
+ children: /* @__PURE__ */ jsx4(RefCard, { refId: f.ref })
1913
+ }
1914
+ );
1915
+ }
1916
+
1917
+ // ../../web/src/sdk/anchors.ts
1918
+ import { useCallback as useCallback2 } from "react";
1919
+ var byWindow = /* @__PURE__ */ new Map();
1920
+ var pending = /* @__PURE__ */ new Map();
1921
+ function report(win) {
1922
+ clearTimeout(pending.get(win));
1923
+ pending.set(
1924
+ win,
1925
+ setTimeout(() => {
1926
+ pending.delete(win);
1927
+ const list = [...byWindow.get(win)?.entries() ?? []].map(([name, e]) => ({ name, label: e.label }));
1928
+ void call("PUT", `/api/ade/anchors/${encodeURIComponent(win)}`, list).catch(() => {
1929
+ });
1930
+ }, 150)
1931
+ );
1932
+ }
1933
+ function useAnchor(win, name, label) {
1934
+ const id = typeof win === "string" ? win : win.id;
1935
+ return useCallback2(
1936
+ (el) => {
1937
+ if (!el) return;
1938
+ let m = byWindow.get(id);
1939
+ if (!m) {
1940
+ m = /* @__PURE__ */ new Map();
1941
+ byWindow.set(id, m);
1942
+ }
1943
+ m.set(name, { el, label });
1944
+ report(id);
1945
+ return () => {
1946
+ const now = byWindow.get(id);
1947
+ if (now?.get(name)?.el !== el) return;
1948
+ now.delete(name);
1949
+ if (!now.size) byWindow.delete(id);
1950
+ report(id);
1951
+ };
1952
+ },
1953
+ [id, name, label]
1954
+ );
1955
+ }
1956
+ var anchorElement = (win, name) => byWindow.get(win)?.get(name)?.el ?? null;
1957
+
1958
+ // ../../web/src/sdk/hooks.ts
1959
+ import { useEffect as useEffect2, useRef, useState as useState4 } from "react";
1960
+ function useEvent(prefix, fn) {
1961
+ const ref = useRef(fn);
1962
+ ref.current = fn;
1963
+ useEffect2(() => onEvent(prefix, (ev) => ref.current(ev)), [prefix]);
1964
+ }
1965
+ function useSetting(fullKey) {
1966
+ const [value, setValue] = useState4(() => getSetting(fullKey));
1967
+ useEffect2(() => {
1968
+ setValue(getSetting(fullKey));
1969
+ return onEvent("config.changed", (ev) => {
1970
+ const d = ev.data;
1971
+ if (d?.key === fullKey) setValue(d.value);
1972
+ });
1973
+ }, [fullKey]);
1974
+ return value;
1975
+ }
1976
+ function useMarks(ref) {
1977
+ const [marks, setMarks] = useState4([]);
1978
+ useEffect2(() => {
1979
+ if (!ref) {
1980
+ setMarks([]);
1981
+ return;
1982
+ }
1983
+ let live = true;
1984
+ const load = () => listMarks(ref).then((m) => {
1985
+ if (live) setMarks(m);
1986
+ });
1987
+ void load();
1988
+ const off = onEvent("marks.changed", (ev) => {
1989
+ if (ev.data?.ref === ref) void load();
1990
+ });
1991
+ return () => {
1992
+ live = false;
1993
+ off();
1994
+ };
1995
+ }, [ref]);
1996
+ return marks;
1997
+ }
1998
+
1999
+ // ../../web/src/sdk/icon.tsx
2000
+ import { icons } from "lucide-react";
2001
+ import { jsx as jsx5 } from "react/jsx-runtime";
2002
+ var pascal = (name) => name.split("-").map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join("");
2003
+ function Icon({ name, ...props }) {
2004
+ const Cmp = name ? icons[pascal(name)] : void 0;
2005
+ if (!Cmp) return /* @__PURE__ */ jsx5(icons.Dot, { ...props });
2006
+ return /* @__PURE__ */ jsx5(Cmp, { ...props });
2007
+ }
2008
+
2009
+ // ../../web/src/sdk/marks.ts
2010
+ var addMark = (m) => call("POST", "/api/marks", m);
2011
+ var replyMark = (id, body) => call("POST", `/api/marks/${encodeURIComponent(id)}/replies`, { body });
2012
+ var resolveMark = (id) => call("POST", `/api/marks/${encodeURIComponent(id)}/resolve`);
2013
+
2014
+ export {
2015
+ ApiError,
2016
+ call,
2017
+ onEvent,
2018
+ isConnected,
2019
+ onConnection,
2020
+ connect,
2021
+ loadSettings,
2022
+ getSetting,
2023
+ allSettings,
2024
+ setSetting,
2025
+ notYetKept,
2026
+ loadManifest,
2027
+ app,
2028
+ viewById,
2029
+ deskState,
2030
+ useDeskState,
2031
+ act,
2032
+ toWin,
2033
+ setConfirm,
2034
+ setClientRunner,
2035
+ runCommand,
2036
+ closeWindow,
2037
+ desk,
2038
+ listLayouts,
2039
+ saveLayout,
2040
+ loadLayout,
2041
+ deleteLayout,
2042
+ initCite,
2043
+ CiteRef,
2044
+ CiteText,
2045
+ remarkCite,
2046
+ citeMarkdownExtensions,
2047
+ RecordBody,
2048
+ CiteRecordView,
2049
+ citeTerminalLinks,
2050
+ CiteFloat,
2051
+ useAnchor,
2052
+ anchorElement,
2053
+ useEvent,
2054
+ useSetting,
2055
+ useMarks,
2056
+ Icon,
2057
+ addMark,
2058
+ replyMark,
2059
+ resolveMark
2060
+ };