@zenera/chat-widget 0.1.5 → 0.1.6

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 (34) hide show
  1. package/README.md +45 -1
  2. package/dist/catalog-BYJPdVB0.js +358 -0
  3. package/dist/index-Dw5Lv6cs.js +3151 -0
  4. package/dist/index.js +22 -14
  5. package/dist/shadow-CEK6vAGQ.js +4 -0
  6. package/dist/styles.css +1 -1
  7. package/dist/types/packages/chat-widget/src/index.d.ts +4 -2
  8. package/dist/types/packages/chat-widget/src/interceptors.d.ts +50 -0
  9. package/dist/types/packages/chat-widget/src/reducer.d.ts +14 -0
  10. package/dist/types/packages/chat-widget/src/transport.d.ts +32 -2
  11. package/dist/types/packages/chat-widget/src/ui/ChatThreadView.d.ts +22 -2
  12. package/dist/types/packages/chat-widget/src/ui/ZeneraChat.d.ts +8 -2
  13. package/dist/types/packages/chat-widget/src/useAttachments.d.ts +32 -0
  14. package/dist/types/packages/chat-widget/src/useChatThread.d.ts +3 -2
  15. package/dist/types/packages/chat-widget/src/widget.d.ts +8 -2
  16. package/dist/types/shared/components/A2uiSurface.d.ts +3 -0
  17. package/dist/types/shared/components/a2ui/Chart.d.ts +2 -0
  18. package/dist/types/shared/components/a2ui/ChartView.d.ts +3 -0
  19. package/dist/types/shared/components/a2ui/DataTable.d.ts +2 -0
  20. package/dist/types/shared/components/a2ui/Notice.d.ts +6 -0
  21. package/dist/types/shared/components/a2ui/catalog.d.ts +2 -0
  22. package/dist/types/shared/components/a2ui/catalogApi.d.ts +16 -0
  23. package/dist/types/shared/components/a2ui/chartData.d.ts +8 -0
  24. package/dist/types/shared/components/a2ui/tableData.d.ts +21 -0
  25. package/dist/types/shared/components/a2ui/useChartPayload.d.ts +9 -0
  26. package/dist/types/shared/lib/a2ui.d.ts +22 -0
  27. package/dist/types/shared/lib/a2uiData.d.ts +2 -0
  28. package/dist/types/shared/lib/a2uiFeed.d.ts +40 -0
  29. package/dist/ui.js +15 -2822
  30. package/dist/useThreadList-BbWSgDw_.js +899 -0
  31. package/dist/widget/chat-widget.iife.js +6179 -88
  32. package/package.json +7 -9
  33. package/dist/shadow-BRAwePHz.js +0 -4
  34. package/dist/useThreadList-Pg29akQ4.js +0 -576
package/dist/ui.js CHANGED
@@ -1,2824 +1,17 @@
1
- import { jsx as n, jsxs as d, Fragment as _e } from "react/jsx-runtime";
2
- import * as Ae from "react";
3
- import { useSyncExternalStore as Rt, useState as O, useRef as $, useId as It, useLayoutEffect as Se, useEffect as P, useContext as it, createContext as st, useMemo as de, useCallback as ue, Fragment as $t } from "react";
4
- import { clsx as Pt } from "clsx";
5
- import { twMerge as Mt } from "tailwind-merge";
6
- import { ChevronDown as at, Check as Te, Copy as Dt, PauseCircle as Wt, Wrench as Ht, Plug as qt, Users as Bt, Globe as Ft, Terminal as Ut, Files as Kt, Brain as ot, LoaderCircle as ge, ChevronRight as lt, MessageSquarePlus as Jt, Square as Xt, SendHorizontal as Zt, Trash2 as Gt, PanelRightOpen as Yt, PanelRightClose as Vt, PanelLeftOpen as Qt, PanelLeftClose as er, Plus as tr, SquarePen as rr } from "lucide-react";
7
- import { u as nr, j as ir } from "./useThreadList-Pg29akQ4.js";
8
- import { Slot as sr } from "@radix-ui/react-slot";
9
- import { cva as ar } from "class-variance-authority";
10
- import * as pe from "@radix-ui/react-tooltip";
11
- import or from "react-markdown";
12
- import lr from "rehype-sanitize";
13
- import cr from "remark-gfm";
14
- import M from "highlight.js/lib/core";
15
- import dr from "highlight.js/lib/languages/bash";
16
- import ur from "highlight.js/lib/languages/css";
17
- import mr from "highlight.js/lib/languages/dockerfile";
18
- import fr from "highlight.js/lib/languages/diff";
19
- import pr from "highlight.js/lib/languages/ini";
20
- import hr from "highlight.js/lib/languages/javascript";
21
- import gr from "highlight.js/lib/languages/json";
22
- import br from "highlight.js/lib/languages/markdown";
23
- import xr from "highlight.js/lib/languages/python";
24
- import yr from "highlight.js/lib/languages/sql";
25
- import vr from "highlight.js/lib/languages/typescript";
26
- import wr from "highlight.js/lib/languages/xml";
27
- import Nr from "highlight.js/lib/languages/yaml";
28
- import { createPortal as ct } from "react-dom";
29
- function kr(e) {
30
- const t = new MutationObserver(e);
31
- return t.observe(document.documentElement, { attributes: !0, attributeFilter: ["class"] }), () => t.disconnect();
32
- }
33
- function je() {
34
- return Rt(
35
- kr,
36
- () => document.documentElement.classList.contains("dark") ? "dark" : "light",
37
- () => "light"
38
- );
39
- }
40
- function k(...e) {
41
- return Mt(Pt(e));
42
- }
43
- const _r = ar(
44
- "inline-flex shrink-0 cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:size-4 [&_svg]:shrink-0",
45
- {
46
- variants: {
47
- variant: {
48
- default: "bg-primary text-primary-foreground hover:bg-primary/90",
49
- secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
50
- outline: "border border-input bg-transparent hover:bg-accent",
51
- ghost: "hover:bg-accent hover:text-accent-foreground",
52
- destructive: "bg-destructive text-white hover:bg-destructive/90",
53
- link: "text-primary underline-offset-4 hover:underline"
54
- },
55
- size: {
56
- default: "h-9 px-4 py-2",
57
- sm: "h-8 px-3 text-xs",
58
- lg: "h-10 px-6",
59
- icon: "size-9"
60
- }
61
- },
62
- defaultVariants: { variant: "default", size: "default" }
63
- }
64
- ), re = Ae.forwardRef(
65
- ({ className: e, variant: t, size: i, asChild: s = !1, ...a }, r) => /* @__PURE__ */ n(
66
- s ? sr : "button",
67
- {
68
- ref: r,
69
- className: k(_r({ variant: t, size: i, className: e })),
70
- ...a
71
- }
72
- )
73
- );
74
- re.displayName = "Button";
75
- const dt = 240, Sr = 48, Cr = (e) => e > dt + Sr;
76
- function Er({
77
- children: e,
78
- className: t
79
- }) {
80
- const [i, s] = O(!1), [a, r] = O(!1), o = $(null), l = It();
81
- Se(() => {
82
- const p = o.current;
83
- if (!p) return;
84
- const h = () => r(Cr(p.offsetHeight));
85
- h();
86
- const u = new ResizeObserver(h);
87
- return u.observe(p), () => u.disconnect();
88
- }, []);
89
- const c = a && !i;
90
- return /* @__PURE__ */ d("div", { className: t, children: [
91
- /* @__PURE__ */ n(
92
- "div",
93
- {
94
- id: l,
95
- style: c ? { maxHeight: dt } : void 0,
96
- className: k(
97
- c && "overflow-hidden [mask-image:linear-gradient(to_bottom,black_70%,transparent)]"
98
- ),
99
- children: /* @__PURE__ */ n("div", { ref: o, children: e })
100
- }
101
- ),
102
- a && /* @__PURE__ */ d(
103
- "button",
104
- {
105
- type: "button",
106
- "aria-expanded": i,
107
- "aria-controls": l,
108
- onClick: () => s((p) => !p),
109
- className: "mt-1 flex cursor-pointer items-center gap-1 rounded-sm text-xs text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-3.5",
110
- children: [
111
- i ? "Show less" : "Show more",
112
- /* @__PURE__ */ n(at, { className: k("transition-transform", i && "rotate-180") })
113
- ]
114
- }
115
- )
116
- ] });
117
- }
118
- async function zr(e) {
119
- var i;
120
- if ((i = navigator.clipboard) != null && i.writeText)
121
- try {
122
- await navigator.clipboard.writeText(e);
123
- return;
124
- } catch {
125
- }
126
- const t = document.createElement("textarea");
127
- t.value = e, t.setAttribute("readonly", ""), t.style.position = "fixed", t.style.opacity = "0", document.body.append(t), t.select();
128
- try {
129
- if (!document.execCommand("copy")) throw new Error("copy was refused");
130
- } finally {
131
- t.remove();
132
- }
133
- }
134
- const ut = (e) => e.replace(/[\r\n]+$/, "");
135
- function He(e) {
136
- var s;
137
- const t = ((s = window.getSelection()) == null ? void 0 : s.toString()) ?? "", i = ut(t);
138
- !t || i === t || (e.clipboardData.setData("text/plain", i), e.preventDefault());
139
- }
140
- const Lr = 1500, qe = "opacity-0 group-hover/msg:opacity-100 [@media(hover:none)]:opacity-100";
141
- function ze({
142
- text: e,
143
- label: t = "Copy",
144
- className: i
145
- }) {
146
- const [s, a] = O("idle"), r = $(void 0);
147
- P(() => () => clearTimeout(r.current), []);
148
- const o = async () => {
149
- try {
150
- await zr(ut(e)), a("copied");
151
- } catch {
152
- a("failed");
153
- }
154
- clearTimeout(r.current), r.current = setTimeout(() => a("idle"), Lr);
155
- }, l = s === "copied" ? "Copied" : s === "failed" ? "Copy failed" : t;
156
- return /* @__PURE__ */ d(
157
- "button",
158
- {
159
- type: "button",
160
- title: l,
161
- "aria-label": l,
162
- onClick: () => void o(),
163
- className: k(
164
- // `relative` anchors the absolutely positioned sr-only status: without it the status
165
- // is placed against the page, outside the scrolling panes, and makes the page scroll.
166
- "relative inline-flex size-6 cursor-pointer select-none items-center justify-center rounded-md text-muted-foreground outline-none hover:bg-accent hover:text-foreground focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-3.5",
167
- s === "failed" && "text-danger",
168
- i
169
- ),
170
- children: [
171
- s === "copied" ? /* @__PURE__ */ n(Te, {}) : /* @__PURE__ */ n(Dt, {}),
172
- /* @__PURE__ */ n("span", { role: "status", className: "sr-only", children: s === "idle" ? "" : l })
173
- ]
174
- }
175
- );
176
- }
177
- const mt = st(null), Or = () => it(mt);
178
- function ye({
179
- label: e,
180
- side: t,
181
- className: i,
182
- children: s
183
- }) {
184
- const a = Or();
185
- return /* @__PURE__ */ n(pe.Provider, { delayDuration: 300, children: /* @__PURE__ */ d(pe.Root, { children: [
186
- /* @__PURE__ */ n(pe.Trigger, { asChild: !0, children: s }),
187
- /* @__PURE__ */ n(pe.Portal, { container: a, children: /* @__PURE__ */ n(
188
- pe.Content,
189
- {
190
- side: t,
191
- sideOffset: 6,
192
- className: k(
193
- "z-50 max-w-sm rounded-md border border-border bg-popover px-3 py-1.5 text-xs whitespace-pre-line text-popover-foreground shadow-md",
194
- i
195
- ),
196
- children: e
197
- }
198
- ) })
199
- ] }) });
200
- }
201
- M.registerLanguage("bash", dr);
202
- M.registerLanguage("css", ur);
203
- M.registerLanguage("dockerfile", mr);
204
- M.registerLanguage("diff", fr);
205
- M.registerLanguage("ini", pr);
206
- M.registerLanguage("javascript", hr);
207
- M.registerLanguage("json", gr);
208
- M.registerLanguage("markdown", br);
209
- M.registerLanguage("python", xr);
210
- M.registerLanguage("sql", yr);
211
- M.registerLanguage("typescript", vr);
212
- M.registerLanguage("xml", wr);
213
- M.registerLanguage("yaml", Nr);
214
- M.registerAliases(["jsonl", "ndjson"], { languageName: "json" });
215
- const Ar = 5e5, Tr = /(^|\/)(docker|container)file(\.[^/]+)?$|\.(docker|container)file$/i;
216
- function jr(e) {
217
- if (Tr.test(e)) return "dockerfile";
218
- const t = e.slice(e.lastIndexOf(".") + 1).toLowerCase();
219
- return M.getLanguage(t) ? t : void 0;
220
- }
221
- function Rr(e, t) {
222
- return !t || !M.getLanguage(t) || e.length > Ar ? null : M.highlight(e, { language: t, ignoreIllegals: !0 }).value;
223
- }
224
- function Z({
225
- code: e,
226
- lang: t,
227
- className: i
228
- }) {
229
- const s = de(() => Rr(e, t), [e, t]);
230
- return /* @__PURE__ */ d("div", { className: "group/code relative min-w-0", children: [
231
- /* @__PURE__ */ n("pre", { className: k("overflow-x-auto font-mono text-xs", i), children: s === null ? /* @__PURE__ */ n("code", { children: e }) : /* @__PURE__ */ n("code", { dangerouslySetInnerHTML: { __html: s } }) }),
232
- e && /* @__PURE__ */ n(
233
- ze,
234
- {
235
- text: e,
236
- label: "Copy code",
237
- className: "absolute top-1.5 right-1.5 bg-surface-code/80 opacity-0 group-hover/code:opacity-100 [@media(hover:none)]:opacity-100"
238
- }
239
- )
240
- ] });
241
- }
242
- let Ir, $r = 0;
243
- const Pr = () => Ir ?? (Ir = import("mermaid").then(({ default: e }) => e));
244
- function Mr({ code: e, natural: t = !1 }) {
245
- const [i, s] = O(null), [a, r] = O(null), o = je();
246
- return P(() => {
247
- let l = !0;
248
- return Pr().then((c) => (c.initialize({
249
- startOnLoad: !1,
250
- theme: o === "dark" ? "dark" : "default",
251
- securityLevel: "strict",
252
- suppressErrorRendering: !0,
253
- flowchart: { useMaxWidth: !t },
254
- state: { useMaxWidth: !t },
255
- themeVariables: { fontSize: "14px" }
256
- }), c.render(`mermaid-${++$r}`, e))).then(
257
- (c) => {
258
- l && (s(c.svg), r(null));
259
- },
260
- (c) => {
261
- l && (s(null), r(c instanceof Error ? c.message : String(c)));
262
- }
263
- ), () => {
264
- l = !1;
265
- };
266
- }, [e, o, t]), i === null ? /* @__PURE__ */ d("div", { children: [
267
- a && /* @__PURE__ */ d("p", { className: "mb-1 text-xs text-danger", children: [
268
- "Mermaid: ",
269
- a
270
- ] }),
271
- /* @__PURE__ */ n(Z, { code: e })
272
- ] }) : t ? /* @__PURE__ */ n("div", { className: "overflow-x-auto", children: /* @__PURE__ */ n("div", { className: "mx-auto w-max", dangerouslySetInnerHTML: { __html: i } }) }) : /* @__PURE__ */ n(
273
- "div",
274
- {
275
- className: "flex justify-center overflow-x-auto",
276
- dangerouslySetInnerHTML: { __html: i }
277
- }
278
- );
279
- }
280
- const Dr = [
281
- "p",
282
- "h1",
283
- "h2",
284
- "h3",
285
- "h4",
286
- "h5",
287
- "h6",
288
- "ul",
289
- "ol",
290
- "li",
291
- "blockquote",
292
- "table"
293
- ];
294
- function Wr(e) {
295
- return function({ node: i, ...s }) {
296
- var r;
297
- return /* @__PURE__ */ n(e, { ...s, "data-line": (r = i == null ? void 0 : i.position) == null ? void 0 : r.start.line });
298
- };
299
- }
300
- function ie({
301
- children: e,
302
- className: t,
303
- lines: i,
304
- linkAction: s
305
- }) {
306
- const a = de(
307
- () => ({
308
- ...i ? Object.fromEntries(Dr.map((r) => [r, Wr(r)])) : void 0,
309
- a: ({ href: r, children: o }) => {
310
- if (r && /^https?:\/\//.test(r))
311
- return /* @__PURE__ */ n("a", { href: r, target: "_blank", rel: "noreferrer", children: o });
312
- const l = r ? s == null ? void 0 : s(r) : void 0;
313
- return l ? /* @__PURE__ */ n(
314
- "button",
315
- {
316
- type: "button",
317
- className: "cursor-pointer text-primary underline-offset-2 hover:underline",
318
- onClick: l,
319
- children: o
320
- }
321
- ) : /* @__PURE__ */ n("span", { className: "text-primary", children: o });
322
- },
323
- pre: ({ node: r, children: o }) => {
324
- var f, m;
325
- const l = r == null ? void 0 : r.children[0];
326
- if ((l == null ? void 0 : l.type) !== "element" || l.tagName !== "code")
327
- return /* @__PURE__ */ n("pre", { children: o });
328
- const c = l.properties.className, p = (f = (Array.isArray(c) ? c.map(String) : []).find((x) => x.startsWith("language-"))) == null ? void 0 : f.slice(9), h = l.children.map((x) => x.type === "text" ? x.value : "").join("").replace(/\n$/, ""), u = p === "mermaid" ? /* @__PURE__ */ n(Mr, { code: h }) : /* @__PURE__ */ n(Z, { code: h, lang: p });
329
- return i ? /* @__PURE__ */ n("div", { "data-line": (m = r == null ? void 0 : r.position) == null ? void 0 : m.start.line, children: u }) : u;
330
- }
331
- }),
332
- [i, s]
333
- );
334
- return /* @__PURE__ */ n("div", { className: k("markdown", t), children: /* @__PURE__ */ n(
335
- or,
336
- {
337
- remarkPlugins: [cr],
338
- rehypePlugins: [lr],
339
- components: a,
340
- children: e
341
- }
342
- ) });
343
- }
344
- const ft = Ae.forwardRef(({ className: e, ...t }, i) => /* @__PURE__ */ n(
345
- "textarea",
346
- {
347
- ref: i,
348
- className: k(
349
- "w-full rounded-md border border-input bg-surface-input px-3 py-2 text-sm outline-none placeholder:text-muted-foreground focus-visible:border-ring disabled:opacity-50",
350
- e
351
- ),
352
- ...t
353
- }
354
- ));
355
- ft.displayName = "Textarea";
356
- function Hr() {
357
- var t;
358
- let e = document.activeElement;
359
- for (; (t = e == null ? void 0 : e.shadowRoot) != null && t.activeElement; ) e = e.shadowRoot.activeElement;
360
- return e;
361
- }
362
- function qr(e) {
363
- var s;
364
- if ((s = window.matchMedia) != null && s.call(window, "(pointer: coarse)").matches) return !1;
365
- const t = Hr();
366
- return !t || t === document.body ? !0 : t.closest('[role="dialog"], [role="menu"], [role="listbox"]') || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName) || t.isContentEditable === !0 ? !1 : e === void 0 || !!(e != null && e.contains(t));
367
- }
368
- function Br(e, t) {
369
- !e || e.disabled || !qr(t) || (e.focus({ preventScroll: !0 }), e.setSelectionRange(e.value.length, e.value.length));
370
- }
371
- const Fr = 30, Ur = 1e4, Ni = (e, t, i) => `zenera.history.${e}.${t}.${i}`;
372
- function pt(e) {
373
- try {
374
- const t = JSON.parse(localStorage.getItem(e) ?? "[]");
375
- return Array.isArray(t) ? t.filter((i) => typeof i == "string") : [];
376
- } catch {
377
- return [];
378
- }
379
- }
380
- function Kr(e, t) {
381
- const i = t.trim();
382
- if (!(!i || i.length > Ur))
383
- try {
384
- const s = [...pt(e).filter((a) => a !== i), i];
385
- localStorage.setItem(e, JSON.stringify(s.slice(-Fr)));
386
- } catch {
387
- }
388
- }
389
- function Jr(e) {
390
- const t = /* @__PURE__ */ new Set(), i = [];
391
- for (let s = e.length - 1; s >= 0; s--)
392
- !e[s].trim() || t.has(e[s]) || (t.add(e[s]), i.unshift(e[s]));
393
- return i;
394
- }
395
- function Xr(e, t, i, s) {
396
- if (i === "up") {
397
- if (!e.length) return null;
398
- const r = t ? t.draft : s, o = t ? Math.max(0, t.index - 1) : e.length - 1;
399
- return { value: e[o], browsing: { index: o, draft: r, shown: e[o] } };
400
- }
401
- if (!t) return null;
402
- const a = t.index + 1;
403
- return a >= e.length ? { value: t.draft, browsing: null } : {
404
- value: e[a],
405
- browsing: { index: a, draft: t.draft, shown: e[a] }
406
- };
407
- }
408
- const Zr = (e, t, i) => t === i && !e.slice(0, t).includes(`
409
- `);
410
- function Gr(e) {
411
- const t = $(null), i = $(e);
412
- P(() => {
413
- i.current = e;
414
- });
415
- const s = ue(() => {
416
- t.current = null;
417
- }, []);
418
- return { onKeyDown: ue(
419
- (r, o, l) => {
420
- if (r.key !== "ArrowUp" && r.key !== "ArrowDown" || r.shiftKey || r.altKey || r.ctrlKey || r.metaKey || r.nativeEvent.isComposing)
421
- return;
422
- const c = r.currentTarget, p = t.current !== null && t.current.shown === o;
423
- p || (t.current = null);
424
- const h = r.key === "ArrowUp" ? "up" : "down";
425
- if (h === "up" && !p && !Zr(o, c.selectionStart, c.selectionEnd))
426
- return;
427
- const u = Xr(
428
- Jr(i.current()),
429
- t.current,
430
- h,
431
- o
432
- );
433
- u && (r.preventDefault(), t.current = u.browsing, l(u.value), requestAnimationFrame(
434
- () => c.setSelectionRange(u.value.length, u.value.length)
435
- ));
436
- },
437
- []
438
- ), reset: s };
439
- }
440
- const Yr = "zenera.draft.chat", ki = (e, t, i, s) => `${Yr}.${e}.${t}.${i}.${s ?? "new"}`;
441
- function Vr(e) {
442
- try {
443
- return localStorage.getItem(e) ?? "";
444
- } catch {
445
- return "";
446
- }
447
- }
448
- function Be(e, t) {
449
- try {
450
- t ? localStorage.setItem(e, t) : localStorage.removeItem(e);
451
- } catch {
452
- }
453
- }
454
- const ht = st(null);
455
- function Qr(e, t) {
456
- return e.ended ? e.ended : !t || t.status === "pending" ? "waiting" : t.status === "superseded" || t.resumeState === "stale" ? "superseded" : t.resumeState === "failed" ? "failed" : t.resumeState === "queued" ? "resuming" : t.status;
457
- }
458
- function Fe({
459
- icon: e,
460
- title: t,
461
- text: i,
462
- tone: s,
463
- children: a
464
- }) {
465
- return /* @__PURE__ */ d(
466
- "div",
467
- {
468
- role: "group",
469
- "aria-label": "The agent is waiting for you",
470
- className: k(
471
- "my-1 flex flex-col gap-2 rounded-lg border px-3 py-2.5 text-sm sm:flex-row sm:items-center",
472
- s === "active" && "border-primary/40 bg-primary/5",
473
- s === "done" && "border-border bg-secondary/40",
474
- s === "muted" && "border-border bg-transparent text-muted-foreground",
475
- s === "danger" && "border-danger/40 text-danger"
476
- ),
477
- children: [
478
- /* @__PURE__ */ d("div", { className: "flex min-w-0 flex-1 items-center gap-3", children: [
479
- e,
480
- /* @__PURE__ */ d("div", { className: "min-w-0", children: [
481
- /* @__PURE__ */ n("div", { className: "font-medium", children: t }),
482
- i && /* @__PURE__ */ n("div", { className: "text-xs text-muted-foreground", children: i })
483
- ] })
484
- ] }),
485
- a && /* @__PURE__ */ n("div", { className: "flex shrink-0 items-center gap-2", children: a })
486
- ]
487
- }
488
- );
489
- }
490
- function en({ interrupt: e, info: t, actions: i }) {
491
- const s = Qr(e, t);
492
- return s !== "waiting" ? /* @__PURE__ */ n(
493
- Fe,
494
- {
495
- tone: "muted",
496
- icon: /* @__PURE__ */ n(Te, { className: "size-4" }),
497
- title: s === "cancelled" || s === "superseded" ? "Skipped" : "Done - continuing"
498
- }
499
- ) : /* @__PURE__ */ n(
500
- Fe,
501
- {
502
- tone: "active",
503
- icon: /* @__PURE__ */ n(Wt, { className: "size-4 text-primary" }),
504
- title: e.message ?? "The agent is waiting for you",
505
- children: t && /* @__PURE__ */ n(
506
- re,
507
- {
508
- type: "button",
509
- size: "sm",
510
- variant: "ghost",
511
- onClick: () => void i.cancel(e.id),
512
- children: "Skip"
513
- }
514
- )
515
- }
516
- );
517
- }
518
- function tn({ interrupt: e }) {
519
- var a, r;
520
- const t = it(ht);
521
- if (!t) return null;
522
- const i = typeof ((a = e.metadata) == null ? void 0 : a.kind) == "string" ? e.metadata.kind : e.reason, s = ((r = t.cards) == null ? void 0 : r[i]) ?? en;
523
- return /* @__PURE__ */ n(s, { interrupt: e, info: t.info[e.id], actions: t });
524
- }
525
- const Ue = {
526
- stdout: "Output",
527
- stderr: "Standard error",
528
- cwd: "Working directory",
529
- ids: "Memory IDs",
530
- job_id: "Job ID",
531
- url: "URL",
532
- urls: "URLs",
533
- duration_ms: "Duration (ms)",
534
- start_line: "Start line",
535
- end_line: "End line"
536
- };
537
- function gt(e) {
538
- return Object.hasOwn(Ue, e) ? Ue[e] : e.replace(/_/g, " ").replace(/^./, (t) => t.toUpperCase());
539
- }
540
- function me({ url: e, children: t }) {
541
- return /^https?:\/\//i.test(e) ? /* @__PURE__ */ n("a", { className: "break-all text-primary underline", href: e, target: "_blank", rel: "noreferrer", children: t ?? e }) : /* @__PURE__ */ n("span", { className: "break-all", children: t ?? e });
542
- }
543
- function bt({ text: e, path: t }) {
544
- return e === "" ? /* @__PURE__ */ n("span", { className: "text-muted-foreground", children: "(empty)" }) : t && /\.(md|markdown)$/i.test(t) ? /* @__PURE__ */ n(ie, { className: "text-xs [overflow-wrap:anywhere]", children: e }) : /* @__PURE__ */ n(Z, { code: e, lang: t ? jr(t) : void 0 });
545
- }
546
- function I({
547
- value: e,
548
- field: t = "",
549
- depth: i = 0
550
- }) {
551
- if (typeof e == "string")
552
- return t === "url" || t === "urls" ? /* @__PURE__ */ n(me, { url: e }) : ["command", "stdout", "stderr", "content", "patch", "output"].includes(t) ? /* @__PURE__ */ n(
553
- Z,
554
- {
555
- className: k(t === "stderr" && "text-danger"),
556
- code: e || "(empty)",
557
- lang: t === "patch" ? "diff" : t === "command" ? "bash" : void 0
558
- }
559
- ) : /* @__PURE__ */ n("div", { className: "whitespace-pre-wrap break-words [overflow-wrap:anywhere]", children: e || "(empty)" });
560
- if (e === null || typeof e != "object")
561
- return /* @__PURE__ */ n("span", { className: "font-mono", children: String(e) });
562
- if (i >= 3) return /* @__PURE__ */ n(Z, { code: JSON.stringify(e, null, 2), lang: "json" });
563
- if (Array.isArray(e))
564
- return e.length ? /* @__PURE__ */ n("div", { className: "space-y-2", children: e.map((a, r) => /* @__PURE__ */ n(I, { value: a, field: t, depth: i + 1 }, r)) }) : /* @__PURE__ */ n("span", { className: "text-muted-foreground", children: "None" });
565
- const s = Object.entries(e);
566
- return s.length ? /* @__PURE__ */ n("dl", { className: "grid min-w-0 grid-cols-[minmax(0,6rem)_minmax(0,1fr)] items-start gap-x-3 gap-y-2", children: s.map(([a, r]) => /* @__PURE__ */ d($t, { children: [
567
- /* @__PURE__ */ n(
568
- "dt",
569
- {
570
- className: k(
571
- "break-words text-[11px] text-muted-foreground",
572
- (a === "error" || a === "failed") && "text-danger"
573
- ),
574
- children: gt(a)
575
- }
576
- ),
577
- /* @__PURE__ */ n("dd", { className: "min-w-0", children: /* @__PURE__ */ n(I, { value: r, field: a, depth: i + 1 }) })
578
- ] }, a)) }) : /* @__PURE__ */ n("span", { className: "text-muted-foreground", children: "No fields" });
579
- }
580
- function be({ value: e }) {
581
- return /* @__PURE__ */ n("dl", { className: "flex min-w-0 flex-wrap gap-x-4 gap-y-1 text-[11px] text-muted-foreground", children: Object.entries(e).map(([t, i]) => /* @__PURE__ */ d("div", { className: "flex min-w-0 max-w-full items-baseline gap-1", children: [
582
- /* @__PURE__ */ d("dt", { className: "shrink-0", children: [
583
- gt(t),
584
- ":"
585
- ] }),
586
- /* @__PURE__ */ n("dd", { className: "min-w-0 break-all", children: /* @__PURE__ */ n(I, { value: i }) })
587
- ] }, t)) });
588
- }
589
- function K({
590
- value: e,
591
- omit: t,
592
- renderValue: i = (s) => /* @__PURE__ */ n(I, { value: s })
593
- }) {
594
- const s = Object.fromEntries(Object.entries(e).filter(([a]) => !t.includes(a)));
595
- return Object.keys(s).length ? /* @__PURE__ */ d("details", { className: "mt-2 text-muted-foreground", children: [
596
- /* @__PURE__ */ n("summary", { className: "w-fit cursor-pointer rounded-sm text-[11px] outline-none hover:text-foreground focus-visible:bg-accent focus-visible:text-foreground", children: "Details" }),
597
- /* @__PURE__ */ n("div", { className: "mt-2", children: i(s) })
598
- ] }) : null;
599
- }
600
- function A(e) {
601
- return e !== null && typeof e == "object" && !Array.isArray(e) ? Object.fromEntries(Object.entries(e)) : void 0;
602
- }
603
- function xe(e) {
604
- try {
605
- return { value: JSON.parse(e) };
606
- } catch (t) {
607
- if (!(t instanceof SyntaxError)) throw t;
608
- return;
609
- }
610
- }
611
- function rn(e) {
612
- let t = "", i = 0, s = !1, a = !1;
613
- const r = () => {
614
- t = t.trimEnd() + `
615
- ` + " ".repeat(i);
616
- };
617
- for (const o of e) {
618
- if (s) {
619
- t += o, a ? a = !1 : o === "\\" ? a = !0 : o === '"' && (s = !1);
620
- continue;
621
- }
622
- o === '"' ? (s = !0, t += o) : o === "{" || o === "[" ? (t += o, i++, r()) : o === "}" || o === "]" ? (i = Math.max(0, i - 1), r(), t += o) : o === "," ? (t += o, r()) : o === ":" ? t += ": " : /\s/.test(o) ? t && !/\s$/.test(t) && (t += " ") : t += o;
623
- }
624
- return t;
625
- }
626
- function nn(e) {
627
- var s;
628
- let t = 1;
629
- for (; t < e.length; ) {
630
- const a = e[t];
631
- if (a === '"' || a.charCodeAt(0) < 32) break;
632
- if (a === "\\") {
633
- const r = e[t + 1];
634
- if (!r) break;
635
- if (r === "u") {
636
- if (!/^[\da-f]{4}$/i.test(e.slice(t + 2, t + 6))) break;
637
- t += 6;
638
- continue;
639
- }
640
- if (!'"\\/bfnrt'.includes(r)) break;
641
- t += 2;
642
- } else
643
- t++;
644
- }
645
- const i = (s = xe(e.slice(0, t) + '"')) == null ? void 0 : s.value;
646
- return typeof i == "string" ? i : void 0;
647
- }
648
- function sn(e) {
649
- var c, p, h;
650
- if (!e.startsWith("{")) return;
651
- const t = [];
652
- let i = 1, s = 1, a = !1, r = !1;
653
- for (let u = 1; u < e.length; u++) {
654
- const f = e[u];
655
- if (a)
656
- r ? r = !1 : f === "\\" ? r = !0 : f === '"' && (a = !1);
657
- else if (f === '"')
658
- a = !0;
659
- else if (f === "{" || f === "[")
660
- s++;
661
- else if (f === "}" || f === "]")
662
- s--;
663
- else if (f === "," && s === 1) {
664
- const m = A((c = xe("{" + e.slice(i, u) + "}")) == null ? void 0 : c.value);
665
- if (!m) return t.length ? Object.fromEntries(t) : void 0;
666
- t.push(...Object.entries(m)), i = u + 1;
667
- }
668
- }
669
- const o = e.slice(i), l = A((p = xe("{" + o + "}")) == null ? void 0 : p.value);
670
- if (l && /(?:true|false|null|["}\]])\s*$/.test(o))
671
- t.push(...Object.entries(l));
672
- else {
673
- const u = /^\s*("(?:[^"\\]|\\.)*")\s*:\s*(".*)$/s.exec(o);
674
- if (u) {
675
- const f = (h = xe(u[1])) == null ? void 0 : h.value, m = nn(u[2]);
676
- typeof f == "string" && m !== void 0 && t.push([f, m]);
677
- }
678
- }
679
- return t.length ? Object.fromEntries(t) : void 0;
680
- }
681
- function Ke(e) {
682
- const t = /\n\u2026 (\d+) more characters$/.exec(e), i = (t ? e.slice(0, t.index) : e).trimStart(), s = xe(i), a = t ? Number(t[1]) : void 0;
683
- if (s)
684
- return {
685
- value: s.value,
686
- raw: JSON.stringify(s.value, null, 2) + (t ? t[0] : ""),
687
- incomplete: !1,
688
- omitted: a
689
- };
690
- const r = /^[{["]/.test(i);
691
- return {
692
- value: r ? sn(i) : void 0,
693
- raw: r ? rn(i) + (t ? t[0] : "") : e,
694
- incomplete: r,
695
- omitted: a
696
- };
697
- }
698
- const Je = {
699
- memory_search: { title: "Memory search", family: "memory" },
700
- memory_grep: { title: "Search memory text", family: "memory" },
701
- memory_load: { title: "Load memories", family: "memory" },
702
- memory_commit: { title: "Remember", family: "memory" },
703
- memory_forget: { title: "Forget memories", family: "memory" },
704
- read_file: { title: "Read file", family: "file" },
705
- list_dir: { title: "List directory", family: "file" },
706
- find_files: { title: "Find files", family: "file" },
707
- write_file: { title: "Write file", family: "file" },
708
- apply_patch: { title: "Apply patch", family: "file" },
709
- move_file: { title: "Move file", family: "file" },
710
- copy_file: { title: "Copy file", family: "file" },
711
- delete_file: { title: "Delete file", family: "file" },
712
- run_command: { title: "Run command", family: "command" },
713
- run_command_background: { title: "Start command", family: "command" },
714
- read_command_output: { title: "Read command output", family: "command" },
715
- stop_command: { title: "Stop command", family: "command" },
716
- web_search: { title: "Web search", family: "web" },
717
- web_answer: { title: "Web answer", family: "web" },
718
- web_read: { title: "Read web pages", family: "web" },
719
- fork: { title: "Parallel agents", family: "agent" },
720
- compact: { title: "Summarize context", family: "agent" },
721
- mcp_servers: { title: "Connected services", family: "mcp" },
722
- mcp_tools: { title: "List service tools", family: "mcp" },
723
- mcp_describe: { title: "Read tool", family: "mcp" },
724
- mcp_call: { title: "Service call", family: "mcp" }
725
- };
726
- function ne(e) {
727
- return e.replace(/[_-]+/g, " ").trim();
728
- }
729
- function an(e) {
730
- return Object.values(A(e) ?? {}).filter(
731
- (t) => ["string", "number", "boolean"].includes(typeof t) && String(t).length <= 80
732
- ).slice(0, 3).map(String).join(" · ");
733
- }
734
- function ee(e, t) {
735
- const i = t === "memory" ? "memories" : `${t}s`;
736
- return Array.isArray(e) ? `${e.length} ${e.length === 1 ? t : i}` : void 0;
737
- }
738
- function T(e) {
739
- return typeof e == "string" ? e : "";
740
- }
741
- function on(e, t, i) {
742
- var p, h;
743
- const s = e.startsWith("transfer_to_") ? e.slice(12) : "", a = Object.hasOwn(Je, e) ? Je[e] : void 0, r = A(t.value) ?? {}, o = s ? "Transfer to agent" : e === "mcp_call" && T(r.tool) ? T(r.tool) : (a == null ? void 0 : a.title) ?? e, l = s ? "agent" : (a == null ? void 0 : a.family) ?? "other";
744
- let c = "";
745
- switch (e) {
746
- case "memory_search":
747
- case "web_search":
748
- case "web_answer":
749
- c = T(r.query);
750
- break;
751
- case "memory_grep":
752
- c = T(r.pattern);
753
- break;
754
- case "memory_load":
755
- case "memory_forget":
756
- c = [ee(r.ids, "memory"), T(r.reason)].filter(Boolean).join(" - ");
757
- break;
758
- case "memory_commit":
759
- c = [ee(r.nodes, "node"), ee(r.edges, "link")].filter(Boolean).join(" - ");
760
- break;
761
- case "run_command":
762
- case "run_command_background":
763
- c = T(r.command);
764
- break;
765
- case "read_command_output":
766
- case "stop_command":
767
- c = T(r.job_id), typeof r.start_line == "number" && (c += ` from line ${r.start_line}`);
768
- break;
769
- case "read_file":
770
- c = T(r.path), typeof r.start_line == "number" ? (c += `:${r.start_line}`, typeof r.end_line == "number" && (c += `-${r.end_line}`)) : typeof r.end_line == "number" && (c += `:1-${r.end_line}`);
771
- break;
772
- case "write_file":
773
- case "delete_file":
774
- c = T(r.path);
775
- break;
776
- case "list_dir":
777
- c = T(r.path) || (t.incomplete ? "" : "/");
778
- break;
779
- case "find_files":
780
- c = [T(r.pattern), T(r.path)].filter(Boolean).join(" in ");
781
- break;
782
- case "move_file":
783
- case "copy_file":
784
- c = [T(r.from), T(r.to)].filter(Boolean).join(" -> ");
785
- break;
786
- case "apply_patch": {
787
- const u = [
788
- ...T(r.patch).matchAll(/^\*\*\* (?:Update|Add|Delete) File: (.+)$/gm)
789
- ].map((f) => f[1]);
790
- c = u.length ? `${u[0]}${u.length > 1 ? ` +${ee(u.slice(1), "file")}` : ""}` : "";
791
- break;
792
- }
793
- case "web_read": {
794
- const u = Array.isArray(r.urls) ? r.urls : [];
795
- c = T(u[0]), u.length > 1 && (c += ` +${u.length - 1} URLs`);
796
- break;
797
- }
798
- case "mcp_servers": {
799
- const u = (p = A(i == null ? void 0 : i.value)) == null ? void 0 : p.servers;
800
- c = ee(u, "service") ?? "";
801
- break;
802
- }
803
- case "mcp_tools": {
804
- const u = (h = A(i == null ? void 0 : i.value)) == null ? void 0 : h.tools;
805
- c = [ne(T(r.server)), ee(u, "tool")].filter(Boolean).join(" · ");
806
- break;
807
- }
808
- case "mcp_describe":
809
- c = [ne(T(r.server)), T(r.tool)].filter(Boolean).join(" · ");
810
- break;
811
- case "mcp_call":
812
- c = [ne(T(r.server)), an(r.arguments)].filter(Boolean).join(" · ");
813
- break;
814
- default:
815
- c = s ? [s, T(r.reason)].filter(Boolean).join(" - ") : T(r.reason) || T(Object.values(r).find((u) => typeof u == "string"));
816
- }
817
- return !c && typeof t.value == "string" && (c = t.value), !c && l === "other" && Object.keys(r).length && (c = ee(Object.keys(r), "argument") ?? ""), { title: o, family: l, preview: c.replace(/\s+/g, " ").trim() };
818
- }
819
- function ln(e, t, i) {
820
- if (!e)
821
- return i ? { label: "Running", tone: "muted", pending: !0 } : { label: "No result", tone: "muted" };
822
- const s = A(e.value);
823
- return t || s != null && s.error || (s == null ? void 0 : s.isError) === !0 || (s == null ? void 0 : s.stopped) === !1 ? { label: "Failed", tone: "danger" } : (s == null ? void 0 : s.auth_required) === !0 ? { label: "Needs connection", tone: "warning" } : (s == null ? void 0 : s.timed_out) === !0 ? { label: "Timed out", tone: "danger" } : typeof (s == null ? void 0 : s.exit_code) == "number" && s.exit_code !== 0 ? { label: `Exit ${s.exit_code}`, tone: "danger" } : e.omitted !== void 0 ? { label: "Truncated", tone: "warning" } : e.incomplete ? { label: "Invalid JSON", tone: "warning" } : s != null && s.truncated ? { label: "Truncated", tone: "warning" } : Array.isArray(s == null ? void 0 : s.failed) && s.failed.length ? { label: "Partial failure", tone: "warning" } : (s == null ? void 0 : s.running) === !0 ? { label: "Job running", tone: "muted" } : (s == null ? void 0 : s.started) === !0 ? { label: "Started", tone: "success" } : typeof (s == null ? void 0 : s.exit_code) == "number" ? { label: `Exit ${s.exit_code}`, tone: "success" } : { label: "Done", tone: "success" };
824
- }
825
- function Ne(e, t) {
826
- return Object.fromEntries(Object.entries(e).filter(([i]) => t.includes(i)));
827
- }
828
- function te(e) {
829
- if (!Array.isArray(e)) return;
830
- const t = e.map(A);
831
- return t.every((i) => i !== void 0) ? t : void 0;
832
- }
833
- function cn({ value: e }) {
834
- return /* @__PURE__ */ n("div", { className: "space-y-4", children: e.map((t, i) => /* @__PURE__ */ d("article", { className: "min-w-0 space-y-2 [overflow-wrap:anywhere]", children: [
835
- typeof t.url == "string" ? /* @__PURE__ */ n(me, { url: t.url, children: typeof t.title == "string" ? t.title : t.url }) : t.title !== void 0 ? /* @__PURE__ */ n(I, { value: t.title }) : null,
836
- t.error !== void 0 && /* @__PURE__ */ n("div", { className: "text-danger", children: /* @__PURE__ */ n(I, { value: t.error }) }),
837
- typeof t.text == "string" && /* @__PURE__ */ n("div", { className: "whitespace-pre-wrap", children: t.text }),
838
- typeof t.excerpt == "string" && /* @__PURE__ */ n("p", { className: "whitespace-pre-wrap", children: t.excerpt }),
839
- t.truncated === !0 && /* @__PURE__ */ n("p", { className: "text-warning", children: "Page content is truncated." }),
840
- /* @__PURE__ */ n(be, { value: Ne(t, ["author", "published_date", "status"]) }),
841
- /* @__PURE__ */ n(
842
- K,
843
- {
844
- value: t,
845
- omit: [
846
- "error",
847
- "author",
848
- "published_date",
849
- "status",
850
- ...typeof t.url == "string" ? ["url", ...typeof t.title == "string" ? ["title"] : []] : ["title"],
851
- ...typeof t.text == "string" ? ["text"] : [],
852
- ...typeof t.excerpt == "string" ? ["excerpt"] : [],
853
- ...typeof t.truncated == "boolean" ? ["truncated"] : []
854
- ]
855
- }
856
- )
857
- ] }, i)) });
858
- }
859
- function xt({
860
- name: e,
861
- input: t,
862
- value: i,
863
- args: s,
864
- partial: a
865
- }) {
866
- var h;
867
- const r = A(i);
868
- if (!r) return /* @__PURE__ */ n(I, { value: i });
869
- const o = A(s), l = (u, f, m = []) => /* @__PURE__ */ d("div", { className: "min-w-0 space-y-2 [overflow-wrap:anywhere]", children: [
870
- r.error !== void 0 && /* @__PURE__ */ n("div", { className: "text-danger", children: /* @__PURE__ */ n(I, { value: r.error }) }),
871
- r.hint !== void 0 && /* @__PURE__ */ n("div", { className: "text-muted-foreground", children: /* @__PURE__ */ n(I, { value: r.hint }) }),
872
- u,
873
- !t && (r.truncated === !0 || typeof r.truncated == "number" && r.truncated > 0) && /* @__PURE__ */ n("p", { className: "text-warning", children: e === "list_dir" && typeof r.truncated == "number" ? `${r.truncated} total entries; this listing is limited.` : "Only part of the available output is included." }),
874
- r.out_of_memory !== void 0 && /* @__PURE__ */ d("div", { className: "text-danger", children: [
875
- /* @__PURE__ */ n("p", { className: "mb-1", children: "Out of memory" }),
876
- /* @__PURE__ */ n(I, { value: r.out_of_memory })
877
- ] }),
878
- /* @__PURE__ */ n(be, { value: Ne(r, m) }),
879
- /* @__PURE__ */ n(
880
- K,
881
- {
882
- value: r,
883
- omit: [
884
- ...f,
885
- ...m,
886
- "error",
887
- "hint",
888
- "out_of_memory",
889
- ...!t && (typeof r.truncated == "boolean" || typeof r.truncated == "number") ? ["truncated"] : []
890
- ]
891
- }
892
- )
893
- ] }), c = typeof r.path == "string" ? r.path : typeof (o == null ? void 0 : o.path) == "string" ? o.path : void 0, p = ["path", "start_line", "end_line", "lines", "bytes"];
894
- switch (e) {
895
- case "read_file":
896
- case "write_file":
897
- if (typeof r.content == "string")
898
- return l(
899
- /* @__PURE__ */ n(bt, { text: r.content, path: c }),
900
- ["content"],
901
- p
902
- );
903
- if (t && typeof r.path == "string")
904
- return l(
905
- /* @__PURE__ */ n("code", { className: "block break-all", children: r.path }),
906
- ["path"],
907
- ["start_line", "end_line"]
908
- );
909
- if (!t && e === "write_file" && r.written === !0)
910
- return l(
911
- /* @__PURE__ */ d("p", { children: [
912
- "Wrote ",
913
- /* @__PURE__ */ n("code", { className: "break-all", children: c })
914
- ] }),
915
- ["written", "path"],
916
- ["lines", "bytes"]
917
- );
918
- break;
919
- case "list_dir":
920
- if (t)
921
- return l(/* @__PURE__ */ n("code", { className: "block break-all", children: c ?? "/" }), ["path"]);
922
- if ((h = te(r.entries)) != null && h.every((u) => typeof u.name == "string")) {
923
- const u = te(r.entries) ?? [];
924
- return l(
925
- u.length ? /* @__PURE__ */ n("ul", { className: "space-y-1", children: u.map((f, m) => /* @__PURE__ */ d("li", { className: "min-w-0", children: [
926
- /* @__PURE__ */ d("div", { className: "flex flex-wrap items-baseline gap-x-3 gap-y-1", children: [
927
- /* @__PURE__ */ d("code", { className: "break-all", children: [
928
- String(f.name),
929
- f.kind === "dir" ? "/" : ""
930
- ] }),
931
- /* @__PURE__ */ n(
932
- be,
933
- {
934
- value: Ne(f, [
935
- "kind",
936
- "format",
937
- "bytes",
938
- "lines"
939
- ])
940
- }
941
- )
942
- ] }),
943
- /* @__PURE__ */ n(
944
- K,
945
- {
946
- value: f,
947
- omit: ["name", "kind", "format", "bytes", "lines"]
948
- }
949
- )
950
- ] }, m)) }) : /* @__PURE__ */ n("p", { className: "text-muted-foreground", children: "Directory is empty" }),
951
- ["entries"],
952
- ["path"]
953
- );
954
- }
955
- break;
956
- case "find_files":
957
- if (t && typeof r.pattern == "string")
958
- return l(
959
- /* @__PURE__ */ n("code", { className: "block break-all", children: r.pattern }),
960
- ["pattern"],
961
- ["path"]
962
- );
963
- if (Array.isArray(r.matches) && r.matches.every((u) => typeof u == "string"))
964
- return l(
965
- r.matches.length ? /* @__PURE__ */ n("ul", { className: "space-y-1", children: r.matches.map((u, f) => /* @__PURE__ */ n("li", { children: /* @__PURE__ */ n("code", { className: "break-all", children: u }) }, f)) }) : /* @__PURE__ */ n("p", { className: "text-muted-foreground", children: "No matching files" }),
966
- ["matches"],
967
- ["pattern"]
968
- );
969
- break;
970
- case "apply_patch": {
971
- if (t && typeof r.patch == "string")
972
- return l(/* @__PURE__ */ n(Z, { code: r.patch, lang: "diff" }), ["patch"]);
973
- const u = te(r.files);
974
- if (!t && (u != null && u.every((f) => typeof f.path == "string")))
975
- return l(
976
- /* @__PURE__ */ d(_e, { children: [
977
- /* @__PURE__ */ n("ul", { className: "space-y-1", children: u.map((f, m) => /* @__PURE__ */ d("li", { children: [
978
- /* @__PURE__ */ d("div", { className: "flex flex-wrap gap-x-2", children: [
979
- /* @__PURE__ */ n("code", { className: "break-all", children: String(f.path) }),
980
- /* @__PURE__ */ n(be, { value: Ne(f, ["action", "to"]) })
981
- ] }),
982
- /* @__PURE__ */ n(K, { value: f, omit: ["path", "action", "to"] })
983
- ] }, m)) }),
984
- r.fuzzy !== void 0 && /* @__PURE__ */ d("p", { className: "text-warning", children: [
985
- "Whitespace-tolerant matches: ",
986
- String(r.fuzzy)
987
- ] }),
988
- r.ignoredHeadings !== void 0 && /* @__PURE__ */ d("p", { className: "text-warning", children: [
989
- "Ignored patch headings: ",
990
- String(r.ignoredHeadings)
991
- ] })
992
- ] }),
993
- ["files", "fuzzy", "ignoredHeadings"],
994
- ["applied"]
995
- );
996
- break;
997
- }
998
- case "move_file":
999
- case "copy_file":
1000
- if (typeof r.from == "string" && typeof r.to == "string")
1001
- return l(
1002
- /* @__PURE__ */ d("code", { className: "block break-all", children: [
1003
- r.from,
1004
- " ",
1005
- "->",
1006
- " ",
1007
- r.to
1008
- ] }),
1009
- ["from", "to"],
1010
- ["moved", "copied", "bytes", "directory", "overwrite", "recursive"]
1011
- );
1012
- break;
1013
- case "delete_file":
1014
- if (typeof r.path == "string")
1015
- return l(
1016
- /* @__PURE__ */ n("code", { className: "block break-all", children: r.path }),
1017
- ["path"],
1018
- ["deleted", "directory", "recursive"]
1019
- );
1020
- break;
1021
- case "run_command":
1022
- case "run_command_background":
1023
- case "read_command_output":
1024
- case "stop_command":
1025
- if (t) {
1026
- if (typeof r.command == "string")
1027
- return l(
1028
- /* @__PURE__ */ n(Z, { code: r.command, lang: "bash" }),
1029
- ["command"],
1030
- ["cwd", "timeout"]
1031
- );
1032
- if (typeof r.job_id == "string")
1033
- return l(
1034
- /* @__PURE__ */ n("code", { className: "break-all", children: r.job_id }),
1035
- ["job_id"],
1036
- ["start_line"]
1037
- );
1038
- } else {
1039
- const u = ["stdout", "output", "stderr"].filter(
1040
- (f) => typeof r[f] == "string"
1041
- );
1042
- if (u.length)
1043
- return l(
1044
- /* @__PURE__ */ d("div", { className: "space-y-2", children: [
1045
- u.every((f) => r[f] === "") && /* @__PURE__ */ n("p", { className: "text-muted-foreground", children: a ? "No output in the received prefix" : "No output" }),
1046
- u.filter((f) => r[f] !== "").map((f) => /* @__PURE__ */ d(
1047
- "div",
1048
- {
1049
- className: f === "stderr" ? "text-danger" : void 0,
1050
- children: [
1051
- f === "stderr" && /* @__PURE__ */ n("p", { className: "mb-1 text-[11px]", children: "Standard error" }),
1052
- /* @__PURE__ */ n(Z, { code: String(r[f]) })
1053
- ]
1054
- },
1055
- f
1056
- ))
1057
- ] }),
1058
- u,
1059
- [
1060
- "exit_code",
1061
- "duration_ms",
1062
- "job_id",
1063
- "command",
1064
- "running",
1065
- "start_line",
1066
- "end_line",
1067
- "lines",
1068
- "timed_out"
1069
- ]
1070
- );
1071
- if (typeof r.job_id == "string")
1072
- return l(
1073
- /* @__PURE__ */ n("code", { className: "break-all", children: r.job_id }),
1074
- ["job_id"],
1075
- ["started", "stopped"]
1076
- );
1077
- }
1078
- break;
1079
- case "web_search":
1080
- case "web_read":
1081
- case "web_answer":
1082
- if (t) {
1083
- if (typeof r.query == "string")
1084
- return l(/* @__PURE__ */ n("p", { className: "whitespace-pre-wrap", children: r.query }), ["query"]);
1085
- if (Array.isArray(r.urls) && r.urls.every((u) => typeof u == "string"))
1086
- return l(
1087
- /* @__PURE__ */ n("ul", { className: "space-y-1", children: r.urls.map((u, f) => /* @__PURE__ */ n("li", { children: /* @__PURE__ */ n(me, { url: u }) }, f)) }),
1088
- ["urls"]
1089
- );
1090
- } else {
1091
- const f = ["results", "pages", "sources", "failed"].filter((m) => te(r[m]) !== void 0);
1092
- if (f.length || typeof r.answer == "string")
1093
- return l(
1094
- /* @__PURE__ */ d("div", { className: "space-y-4", children: [
1095
- typeof r.answer == "string" && /* @__PURE__ */ n(ie, { className: "text-xs", children: r.answer }),
1096
- f.map((m) => {
1097
- var x, v;
1098
- return /* @__PURE__ */ d("div", { children: [
1099
- m === "failed" && (((x = te(r[m])) == null ? void 0 : x.length) ?? 0) > 0 && /* @__PURE__ */ n("p", { className: "mb-2 text-danger", children: "Some pages could not be fetched." }),
1100
- m !== "failed" && ((v = te(r[m])) == null ? void 0 : v.length) === 0 && /* @__PURE__ */ n("p", { className: "text-muted-foreground", children: "No sources returned" }),
1101
- /* @__PURE__ */ n(cn, { value: te(r[m]) ?? [] })
1102
- ] }, m);
1103
- }),
1104
- Array.isArray(r.skipped) && r.skipped.length > 0 && /* @__PURE__ */ d("div", { className: "text-warning", children: [
1105
- /* @__PURE__ */ n("p", { className: "mb-1", children: "Some URLs were skipped." }),
1106
- /* @__PURE__ */ n(I, { value: r.skipped, field: "urls" })
1107
- ] })
1108
- ] }),
1109
- [
1110
- ...f,
1111
- ...typeof r.answer == "string" ? ["answer"] : [],
1112
- ...Array.isArray(r.skipped) ? ["skipped"] : []
1113
- ],
1114
- ["query", "found", "cost_usd"]
1115
- );
1116
- }
1117
- break;
1118
- case "compact":
1119
- if (t && typeof r.reason == "string")
1120
- return l(
1121
- /* @__PURE__ */ n("p", { className: "whitespace-pre-wrap", children: r.reason }),
1122
- ["reason"],
1123
- ["nodes"]
1124
- );
1125
- break;
1126
- default:
1127
- if (t && e.startsWith("transfer_to_"))
1128
- return l(
1129
- r.reason !== void 0 ? /* @__PURE__ */ n(I, { value: r.reason }) : /* @__PURE__ */ n("p", { className: "text-muted-foreground", children: "No additional arguments" }),
1130
- ["reason"]
1131
- );
1132
- }
1133
- return r.error !== void 0 ? l(null, []) : /* @__PURE__ */ n(I, { value: i });
1134
- }
1135
- const yt = Ae.forwardRef(({ className: e, ...t }, i) => /* @__PURE__ */ n(
1136
- "input",
1137
- {
1138
- ref: i,
1139
- className: k(
1140
- "h-9 w-full rounded-md border border-input bg-surface-input px-3 text-sm outline-none placeholder:text-muted-foreground focus-visible:border-ring disabled:opacity-50",
1141
- e
1142
- ),
1143
- ...t
1144
- }
1145
- ));
1146
- yt.displayName = "Input";
1147
- function Le(e) {
1148
- if (!Array.isArray(e)) return;
1149
- const t = e.map(A);
1150
- return t.every((i) => i !== void 0) ? t : void 0;
1151
- }
1152
- const _ = (e) => typeof e == "string" ? e : void 0;
1153
- function V({ children: e }) {
1154
- return /* @__PURE__ */ n("p", { className: "text-muted-foreground", children: e });
1155
- }
1156
- function dn({ tools: e }) {
1157
- const [t, i] = O(""), s = t.trim().toLowerCase(), a = s ? e.filter(
1158
- (r) => `${_(r.name) ?? ""} ${_(r.description) ?? ""}`.toLowerCase().includes(s)
1159
- ) : e;
1160
- return e.length ? /* @__PURE__ */ d("div", { className: "space-y-2", children: [
1161
- e.length > 12 && /* @__PURE__ */ n(
1162
- yt,
1163
- {
1164
- className: "h-7 text-xs",
1165
- placeholder: `Filter ${e.length} tools`,
1166
- "aria-label": "Filter tools",
1167
- value: t,
1168
- onChange: (r) => i(r.target.value)
1169
- }
1170
- ),
1171
- /* @__PURE__ */ n("ul", { className: "space-y-1.5", children: a.map((r, o) => /* @__PURE__ */ d("li", { className: "min-w-0", children: [
1172
- /* @__PURE__ */ n("code", { className: "break-all text-foreground", children: _(r.name) ?? "?" }),
1173
- _(r.description) && /* @__PURE__ */ n(
1174
- "p",
1175
- {
1176
- className: "line-clamp-2 text-muted-foreground",
1177
- title: _(r.description),
1178
- children: _(r.description)
1179
- }
1180
- )
1181
- ] }, o)) }),
1182
- s && !a.length && /* @__PURE__ */ n(V, { children: "No matching tools" })
1183
- ] }) : /* @__PURE__ */ n(V, { children: "No tools" });
1184
- }
1185
- function un({ schema: e }) {
1186
- const t = A(e), i = Object.entries(A(t == null ? void 0 : t.properties) ?? {}), s = Array.isArray(t == null ? void 0 : t.required) ? t.required : [];
1187
- return i.length ? /* @__PURE__ */ n("ul", { className: "space-y-1.5", children: i.map(([a, r]) => {
1188
- var c;
1189
- const o = A(r) ?? {}, l = Array.isArray(o.enum) ? o.enum.map(String).join(" | ") : o.type === "array" ? `${_((c = A(o.items)) == null ? void 0 : c.type) ?? "any"}[]` : Array.isArray(o.type) ? o.type.join(" | ") : _(o.type) ?? "";
1190
- return /* @__PURE__ */ d("li", { className: "min-w-0", children: [
1191
- /* @__PURE__ */ d("div", { className: "flex flex-wrap items-baseline gap-x-2", children: [
1192
- /* @__PURE__ */ n("code", { className: "break-all text-foreground", children: a }),
1193
- l && /* @__PURE__ */ n("span", { className: "text-muted-foreground", children: l }),
1194
- s.includes(a) && /* @__PURE__ */ n("span", { className: "text-[11px] text-warning", children: "required" })
1195
- ] }),
1196
- _(o.description) && /* @__PURE__ */ n("p", { className: "text-muted-foreground", children: _(o.description) })
1197
- ] }, a);
1198
- }) }) : /* @__PURE__ */ n(V, { children: "Takes no arguments" });
1199
- }
1200
- function mn(e) {
1201
- if (/^\s*[{[]/.test(e))
1202
- try {
1203
- return { value: JSON.parse(e) };
1204
- } catch {
1205
- return;
1206
- }
1207
- }
1208
- function vt({ part: e }) {
1209
- switch (e.type) {
1210
- case "text": {
1211
- const t = _(e.text) ?? "", i = mn(t);
1212
- return i ? /* @__PURE__ */ n(I, { value: i.value }) : t ? /* @__PURE__ */ n(ie, { className: "text-xs [overflow-wrap:anywhere]", children: t }) : /* @__PURE__ */ n(V, { children: "(empty)" });
1213
- }
1214
- case "image": {
1215
- const t = _(e.mimeType) ?? "", i = _(e.data);
1216
- return /^image\/[\w.+-]+$/.test(t) && i ? /* @__PURE__ */ n(
1217
- "img",
1218
- {
1219
- className: "max-h-64 max-w-full rounded border border-border",
1220
- src: `data:${t};base64,${i}`,
1221
- alt: ""
1222
- }
1223
- ) : /* @__PURE__ */ n(V, { children: `Image (${t || "unknown type"})` });
1224
- }
1225
- case "resource_link": {
1226
- const t = _(e.uri);
1227
- return t ? /* @__PURE__ */ n(me, { url: t, children: _(e.name) ?? _(e.title) ?? t }) : null;
1228
- }
1229
- case "resource": {
1230
- const t = A(e.resource) ?? {}, i = _(t.uri);
1231
- return /* @__PURE__ */ d("div", { className: "space-y-1", children: [
1232
- i && /* @__PURE__ */ n(me, { url: i }),
1233
- _(t.text) !== void 0 && /* @__PURE__ */ n(vt, { part: { type: "text", text: t.text } })
1234
- ] });
1235
- }
1236
- default:
1237
- return /* @__PURE__ */ n(I, { value: e });
1238
- }
1239
- }
1240
- function fn({ object: e }) {
1241
- if (e.auth_required === !0) {
1242
- const a = _(e.connect_url);
1243
- return /* @__PURE__ */ d("div", { className: "space-y-1 text-warning", children: [
1244
- /* @__PURE__ */ n("p", { children: _(e.message) ?? "This service needs a connected account." }),
1245
- a && /* @__PURE__ */ d(me, { url: a, children: [
1246
- "Connect ",
1247
- ne(_(e.server) ?? "")
1248
- ] })
1249
- ] });
1250
- }
1251
- const t = Le(e.content) ?? [], i = e.structuredContent, s = i !== void 0 ? t.filter((a) => a.type !== "text") : t;
1252
- return /* @__PURE__ */ d("div", { className: "min-w-0 space-y-2 [overflow-wrap:anywhere]", children: [
1253
- e.isError === !0 && /* @__PURE__ */ n("p", { className: "text-danger", children: "The service returned an error." }),
1254
- /* @__PURE__ */ d("div", { className: k("space-y-2", e.isError === !0 && "text-danger"), children: [
1255
- i !== void 0 && /* @__PURE__ */ n(I, { value: i }),
1256
- s.map((a, r) => /* @__PURE__ */ n(vt, { part: a }, r)),
1257
- i === void 0 && !t.length && /* @__PURE__ */ n(V, { children: "No content" })
1258
- ] }),
1259
- e.truncated === !0 && /* @__PURE__ */ n("p", { className: "text-warning", children: _(e.note) ?? "Only part of the result is included." })
1260
- ] });
1261
- }
1262
- function pn({
1263
- name: e,
1264
- input: t,
1265
- value: i,
1266
- args: s,
1267
- partial: a
1268
- }) {
1269
- const r = A(i), o = /* @__PURE__ */ n(xt, { name: e, input: t, value: i, args: s, partial: a });
1270
- if (!r || r.error !== void 0) return o;
1271
- if (t) {
1272
- const l = _(r.server);
1273
- switch (e) {
1274
- case "mcp_servers":
1275
- return Object.keys(r).length ? o : /* @__PURE__ */ n(V, { children: "No arguments" });
1276
- case "mcp_tools":
1277
- case "mcp_describe":
1278
- if (!l) break;
1279
- return /* @__PURE__ */ d("p", { children: [
1280
- ne(l),
1281
- _(r.tool) && /* @__PURE__ */ d(_e, { children: [
1282
- " · ",
1283
- /* @__PURE__ */ n("code", { className: "break-all", children: _(r.tool) })
1284
- ] })
1285
- ] });
1286
- case "mcp_call": {
1287
- if (!l) break;
1288
- const c = A(r.arguments);
1289
- return /* @__PURE__ */ d("div", { className: "space-y-2", children: [
1290
- c && Object.keys(c).length ? /* @__PURE__ */ n(I, { value: c }) : r.arguments === void 0 || c ? /* @__PURE__ */ n(V, { children: "No arguments" }) : /* @__PURE__ */ n(I, { value: r.arguments }),
1291
- /* @__PURE__ */ n(
1292
- be,
1293
- {
1294
- value: {
1295
- service: ne(l),
1296
- ..._(r.tool) ? { tool: r.tool } : {}
1297
- }
1298
- }
1299
- )
1300
- ] });
1301
- }
1302
- }
1303
- return o;
1304
- }
1305
- switch (e) {
1306
- case "mcp_servers": {
1307
- const l = Le(r.servers);
1308
- if (!l) break;
1309
- return l.length ? /* @__PURE__ */ n("ul", { className: "space-y-1", children: l.map((c, p) => /* @__PURE__ */ d("li", { className: "flex flex-wrap items-baseline gap-x-2", children: [
1310
- /* @__PURE__ */ n("span", { className: "text-foreground", title: _(c.server), children: ne(_(c.server) ?? "?") }),
1311
- typeof c.tools == "number" && /* @__PURE__ */ d("span", { className: "text-muted-foreground", children: [
1312
- c.tools,
1313
- " ",
1314
- c.tools === 1 ? "tool" : "tools"
1315
- ] })
1316
- ] }, p)) }) : /* @__PURE__ */ n(V, { children: "No services are enabled for this chat" });
1317
- }
1318
- case "mcp_tools": {
1319
- const l = Le(r.tools);
1320
- if (!l) break;
1321
- return /* @__PURE__ */ n(dn, { tools: l });
1322
- }
1323
- case "mcp_describe":
1324
- if (r.inputSchema === void 0 && _(r.description) === void 0) break;
1325
- return /* @__PURE__ */ d("div", { className: "min-w-0 space-y-3 [overflow-wrap:anywhere]", children: [
1326
- _(r.description) && /* @__PURE__ */ n(ie, { className: "text-xs", children: _(r.description) ?? "" }),
1327
- /* @__PURE__ */ d("div", { children: [
1328
- /* @__PURE__ */ n("p", { className: "mb-1 text-[11px] font-semibold text-muted-foreground", children: "Parameters" }),
1329
- /* @__PURE__ */ n(un, { schema: r.inputSchema })
1330
- ] })
1331
- ] });
1332
- case "mcp_call":
1333
- if (r.auth_required !== !0 && r.content === void 0 && r.structuredContent === void 0)
1334
- break;
1335
- return /* @__PURE__ */ n(fn, { object: r });
1336
- }
1337
- return o;
1338
- }
1339
- function hn(e) {
1340
- const t = [], i = [];
1341
- for (const s of e.split(/\r?\n/)) {
1342
- const a = s.trim();
1343
- if (!a || /^<\/?memory-recollection>$/.test(s)) continue;
1344
- const r = /^( *)(?:(\d+\.\d+|--) {2,}|([\u2190\u2192][\w-]+) {2,}(?:(\d+\.\d+) {2,})?)([A-Za-z0-9_ -]+?) {2,}(\S+)\s*$/.exec(
1345
- s
1346
- );
1347
- if (r && (r[3] || r[1].length <= 2))
1348
- t.push({
1349
- id: r[6],
1350
- kind: r[5],
1351
- depth: r[3] ? Math.floor(r[1].length / 2) : 0,
1352
- score: r[2] === "--" ? void 0 : r[2] ?? r[4],
1353
- relation: r[3],
1354
- lines: []
1355
- });
1356
- else if (a.startsWith("(more memory matched than fits;") || /^\u2026 \d+ more characters$/.test(a))
1357
- i.push(a);
1358
- else if (t.length && /^ {6,}\S/.test(s))
1359
- t[t.length - 1].lines.push(a);
1360
- else
1361
- return;
1362
- }
1363
- return t.length ? { entries: t, notes: i } : void 0;
1364
- }
1365
- function wt({ node: e }) {
1366
- return /* @__PURE__ */ d("div", { className: "flex flex-wrap items-baseline gap-x-2 gap-y-1 text-[11px] text-muted-foreground", children: [
1367
- typeof e.kind == "string" && /* @__PURE__ */ n("span", { className: "font-medium capitalize", children: e.kind }),
1368
- e.stale === !0 && /* @__PURE__ */ n("span", { className: "text-warning", children: "Superseded" }),
1369
- typeof e.id == "string" && /* @__PURE__ */ n("code", { className: "break-all", children: e.id }),
1370
- typeof e.ref == "string" && /* @__PURE__ */ d("code", { className: "break-all", children: [
1371
- "Ref: ",
1372
- e.ref
1373
- ] })
1374
- ] });
1375
- }
1376
- function Xe({
1377
- nodes: e,
1378
- renderValue: t
1379
- }) {
1380
- return e.length ? /* @__PURE__ */ n("div", { className: "space-y-4", children: e.map((i, s) => {
1381
- const a = A(i.file), r = typeof i.file == "string" ? i.file : a == null ? void 0 : a.path;
1382
- return /* @__PURE__ */ d("article", { className: "min-w-0 space-y-2 [overflow-wrap:anywhere]", children: [
1383
- /* @__PURE__ */ n(wt, { node: i }),
1384
- typeof i.text == "string" && /* @__PURE__ */ n(ie, { className: "text-xs", children: i.text }),
1385
- typeof r == "string" && /* @__PURE__ */ d("div", { className: "text-[11px] text-muted-foreground", children: [
1386
- /* @__PURE__ */ n("code", { className: "break-all", children: r }),
1387
- typeof (a == null ? void 0 : a.bytes) == "number" && /* @__PURE__ */ d("span", { children: [
1388
- " (",
1389
- a.bytes.toLocaleString(),
1390
- " bytes)"
1391
- ] })
1392
- ] }),
1393
- typeof i.content == "string" && /* @__PURE__ */ n(
1394
- bt,
1395
- {
1396
- text: i.content,
1397
- path: typeof r == "string" ? r : void 0
1398
- }
1399
- ),
1400
- /* @__PURE__ */ n(
1401
- K,
1402
- {
1403
- value: i,
1404
- omit: [
1405
- "id",
1406
- "ref",
1407
- "kind",
1408
- "text",
1409
- "content",
1410
- ...typeof i.file == "string" ? ["file"] : []
1411
- ],
1412
- renderValue: t
1413
- }
1414
- )
1415
- ] }, s);
1416
- }) }) : /* @__PURE__ */ n("p", { className: "text-muted-foreground", children: "No memories" });
1417
- }
1418
- function Ze(e) {
1419
- if (!Array.isArray(e)) return;
1420
- const t = e.map(A);
1421
- if (t.every(
1422
- (i) => i !== void 0 && ["id", "ref", "kind", "text", "content"].every(
1423
- (s) => i[s] === void 0 || typeof i[s] == "string"
1424
- ) && ["id", "ref", "text", "file"].some((s) => i[s] !== void 0)
1425
- ))
1426
- return t;
1427
- }
1428
- function gn({ value: e, renderValue: t }) {
1429
- const i = Array.isArray(e) ? e.map(A) : void 0;
1430
- return !i || !i.every(
1431
- (s) => s !== void 0 && typeof s.in == "string" && typeof s.line == "number" && typeof s.text == "string"
1432
- ) ? /* @__PURE__ */ n(_e, { children: t({ hits: e }) }) : /* @__PURE__ */ n("div", { className: "space-y-2", children: i.map((s, a) => /* @__PURE__ */ d("div", { children: [
1433
- /* @__PURE__ */ d("div", { className: "mb-1 text-[11px] text-muted-foreground", children: [
1434
- String(s.in),
1435
- ":",
1436
- String(s.line)
1437
- ] }),
1438
- /* @__PURE__ */ n("pre", { className: "whitespace-pre-wrap break-words font-mono text-xs", children: String(s.text) }),
1439
- /* @__PURE__ */ n(K, { value: s, omit: ["in", "line", "text"], renderValue: t })
1440
- ] }, a)) });
1441
- }
1442
- function bn({
1443
- name: e,
1444
- input: t,
1445
- value: i,
1446
- text: s,
1447
- renderValue: a
1448
- }) {
1449
- const r = A(i), o = typeof i == "string" ? i : s;
1450
- if (!t && e === "memory_search" && (i === void 0 || typeof i == "string")) {
1451
- const l = hn(o);
1452
- return l ? /* @__PURE__ */ d("div", { className: "space-y-3", children: [
1453
- l.entries.map((c, p) => /* @__PURE__ */ d(
1454
- "article",
1455
- {
1456
- className: "min-w-0 space-y-1 [overflow-wrap:anywhere]",
1457
- style: { marginLeft: `${Math.min(c.depth, 6) * 0.75}rem` },
1458
- children: [
1459
- /* @__PURE__ */ d("div", { className: "flex flex-wrap items-baseline gap-x-2 gap-y-1 text-[11px] text-muted-foreground", children: [
1460
- c.relation && /* @__PURE__ */ n("span", { children: c.relation }),
1461
- /* @__PURE__ */ n("span", { className: "font-medium capitalize", children: c.kind }),
1462
- c.score && /* @__PURE__ */ d("span", { children: [
1463
- "Score ",
1464
- c.score
1465
- ] }),
1466
- /* @__PURE__ */ n("code", { className: "break-all", children: c.id })
1467
- ] }),
1468
- c.lines.map((h, u) => /* @__PURE__ */ n(
1469
- "div",
1470
- {
1471
- className: h.startsWith("/memory/") || h.startsWith("+ ") ? "whitespace-pre-wrap font-mono text-[11px] text-muted-foreground" : "whitespace-pre-wrap",
1472
- children: h
1473
- },
1474
- u
1475
- ))
1476
- ]
1477
- },
1478
- p
1479
- )),
1480
- l.notes.map((c, p) => /* @__PURE__ */ n("p", { className: "text-warning", children: c }, p))
1481
- ] }) : /* @__PURE__ */ n("div", { className: "whitespace-pre-wrap [overflow-wrap:anywhere]", children: o || "(empty)" });
1482
- }
1483
- if (!t && e === "memory_load") {
1484
- const l = Ze(i);
1485
- if (l) return /* @__PURE__ */ n(Xe, { nodes: l, renderValue: a });
1486
- }
1487
- if (t && e === "memory_commit" && r) {
1488
- const l = Ze(r.nodes);
1489
- if (l)
1490
- return /* @__PURE__ */ d("div", { children: [
1491
- /* @__PURE__ */ n(Xe, { nodes: l, renderValue: a }),
1492
- r.edges !== void 0 && /* @__PURE__ */ n("div", { className: "mt-3", children: a({ links: r.edges }) }),
1493
- /* @__PURE__ */ n(K, { value: r, omit: ["nodes", "edges"], renderValue: a })
1494
- ] });
1495
- }
1496
- if (t && r && (e === "memory_load" || e === "memory_forget") && Array.isArray(r.ids) && r.ids.every((l) => typeof l == "string"))
1497
- return /* @__PURE__ */ d("div", { children: [
1498
- /* @__PURE__ */ n("div", { className: "flex flex-wrap gap-x-3 gap-y-1 font-mono text-[11px]", children: r.ids.map((l, c) => /* @__PURE__ */ n("code", { className: "break-all", children: l }, c)) }),
1499
- r.reason !== void 0 && /* @__PURE__ */ n("div", { className: "mt-2", children: a({ reason: r.reason }) }),
1500
- /* @__PURE__ */ n(K, { value: r, omit: ["ids", "reason"], renderValue: a })
1501
- ] });
1502
- if (!t && e === "memory_grep" && r && Array.isArray(r.matches)) {
1503
- const l = r.matches.map(A);
1504
- if (l.every(
1505
- (c) => c !== void 0 && typeof c.id == "string" && Array.isArray(c.hits)
1506
- ))
1507
- return /* @__PURE__ */ d("div", { className: "space-y-3", children: [
1508
- typeof r.found == "number" && /* @__PURE__ */ d("p", { className: "text-muted-foreground", children: [
1509
- r.found,
1510
- " ",
1511
- r.found === 1 ? "match" : "matches"
1512
- ] }),
1513
- r.truncated === !0 && /* @__PURE__ */ n("p", { className: "text-warning", children: "More matches are available." }),
1514
- l.map((c, p) => /* @__PURE__ */ d("article", { className: "min-w-0 space-y-2 [overflow-wrap:anywhere]", children: [
1515
- /* @__PURE__ */ n(wt, { node: c }),
1516
- typeof c.file == "string" && /* @__PURE__ */ n("code", { className: "block break-all text-[11px] text-muted-foreground", children: c.file }),
1517
- /* @__PURE__ */ n(gn, { value: c.hits, renderValue: a }),
1518
- typeof c.more == "number" && c.more > 0 && /* @__PURE__ */ d("p", { className: "text-warning", children: [
1519
- c.more,
1520
- " additional hits"
1521
- ] }),
1522
- /* @__PURE__ */ n(
1523
- K,
1524
- {
1525
- value: c,
1526
- omit: [
1527
- "id",
1528
- "hits",
1529
- ...typeof c.kind == "string" ? ["kind"] : [],
1530
- ...typeof c.stale == "boolean" ? ["stale"] : [],
1531
- ...typeof c.file == "string" ? ["file"] : [],
1532
- ...typeof c.more == "number" ? ["more"] : []
1533
- ],
1534
- renderValue: a
1535
- }
1536
- )
1537
- ] }, p)),
1538
- r.unsearched !== void 0 && /* @__PURE__ */ d("div", { className: "text-warning", children: [
1539
- /* @__PURE__ */ n("p", { className: "mb-1", children: "Some memories were not searched." }),
1540
- a({ unsearched: r.unsearched })
1541
- ] }),
1542
- /* @__PURE__ */ n(
1543
- K,
1544
- {
1545
- value: r,
1546
- omit: [
1547
- "matches",
1548
- "unsearched",
1549
- ...typeof r.found == "number" ? ["found"] : [],
1550
- ...typeof r.truncated == "boolean" ? ["truncated"] : []
1551
- ],
1552
- renderValue: a
1553
- }
1554
- )
1555
- ] });
1556
- }
1557
- return !t && e === "memory_commit" && r && typeof r.summary == "string" ? /* @__PURE__ */ d("div", { className: "space-y-2", children: [
1558
- /* @__PURE__ */ n("p", { children: r.summary.replace(/^memory_commit /, "Remembered ") }),
1559
- r.ids !== void 0 && a({ "Memory IDs": r.ids }),
1560
- /* @__PURE__ */ n(K, { value: r, omit: ["summary", "ids"], renderValue: a })
1561
- ] }) : i !== void 0 ? a(i) : /* @__PURE__ */ n("div", { className: "whitespace-pre-wrap [overflow-wrap:anywhere]", children: o || "(empty)" });
1562
- }
1563
- const xn = {
1564
- memory: ot,
1565
- file: Kt,
1566
- command: Ut,
1567
- web: Ft,
1568
- agent: Bt,
1569
- mcp: qt,
1570
- other: Ht
1571
- };
1572
- function Nt({
1573
- className: e,
1574
- children: t
1575
- }) {
1576
- return /* @__PURE__ */ d("div", { className: k("relative ml-[7px] pl-2", e), children: [
1577
- /* @__PURE__ */ n(
1578
- "span",
1579
- {
1580
- "aria-hidden": !0,
1581
- className: "absolute -top-1 left-0 h-4 w-3 rounded-bl-lg border-b border-l border-border"
1582
- }
1583
- ),
1584
- t
1585
- ] });
1586
- }
1587
- function Ge({
1588
- payload: e,
1589
- raw: t,
1590
- markdown: i,
1591
- receiving: s,
1592
- tool: a
1593
- }) {
1594
- return /* @__PURE__ */ d(_e, { children: [
1595
- e.omitted !== void 0 ? /* @__PURE__ */ d("p", { className: "mb-2 text-warning", children: [
1596
- "Output truncated: ",
1597
- e.omitted.toLocaleString(),
1598
- " more characters were not sent.",
1599
- e.incomplete && " Showing only the available prefix."
1600
- ] }) : e.incomplete ? /* @__PURE__ */ n("p", { className: "mb-2 text-muted-foreground", children: s ? "Receiving arguments..." : "Incomplete or invalid JSON. Only the available content is shown." }) : null,
1601
- t ? /* @__PURE__ */ n(
1602
- Z,
1603
- {
1604
- code: e.raw || "(empty)",
1605
- lang: e.incomplete ? void 0 : "json"
1606
- }
1607
- ) : (a == null ? void 0 : a.family) === "memory" && !e.incomplete ? /* @__PURE__ */ n(
1608
- bn,
1609
- {
1610
- name: a.name,
1611
- input: a.input,
1612
- value: e.value,
1613
- text: e.raw,
1614
- renderValue: (r) => /* @__PURE__ */ n(I, { value: r })
1615
- }
1616
- ) : (a == null ? void 0 : a.family) === "mcp" && e.value !== void 0 ? /* @__PURE__ */ n(
1617
- pn,
1618
- {
1619
- name: a.name,
1620
- input: a.input,
1621
- value: e.value,
1622
- args: a.args,
1623
- partial: e.incomplete || e.omitted !== void 0
1624
- }
1625
- ) : a && e.value !== void 0 ? /* @__PURE__ */ n(
1626
- xt,
1627
- {
1628
- name: a.name,
1629
- input: a.input,
1630
- value: e.value,
1631
- args: a.args,
1632
- partial: e.incomplete || e.omitted !== void 0
1633
- }
1634
- ) : e.value !== void 0 ? /* @__PURE__ */ n(I, { value: e.value }) : e.incomplete ? /* @__PURE__ */ n(Z, { code: e.raw }) : i ? /* @__PURE__ */ n(ie, { children: e.raw }) : /* @__PURE__ */ n("div", { className: "whitespace-pre-wrap break-words [overflow-wrap:anywhere]", children: e.raw || "(empty)" })
1635
- ] });
1636
- }
1637
- function yn({
1638
- item: e,
1639
- running: t
1640
- }) {
1641
- const [i, s] = O(!1), [a, r] = O(!1), o = de(() => Ke(e.args), [e.args]), l = de(
1642
- () => e.result === void 0 ? void 0 : Ke(e.result),
1643
- [e.result]
1644
- ), { title: c, family: p, preview: h } = on(e.name, o, l), u = t && l === void 0 && (o.incomplete || !e.args.trim()), f = A(o.value), m = !u && !o.incomplete && (!e.args.trim() || f !== void 0 && !Object.keys(f).length), x = ln(l, e.isError, t), v = xn[p], g = e.interrupt && !e.interrupt.ended && l === void 0, y = /* @__PURE__ */ d(
1645
- "details",
1646
- {
1647
- className: "group min-w-0 text-xs",
1648
- onToggle: (C) => s(C.currentTarget.open),
1649
- children: [
1650
- /* @__PURE__ */ d("summary", { className: "group/row flex min-w-0 cursor-pointer list-none items-center gap-2 -mx-1.5 rounded-sm px-1.5 py-1.5 text-muted-foreground outline-none hover:text-foreground focus-visible:bg-accent focus-visible:text-foreground [&::-webkit-details-marker]:hidden", children: [
1651
- /* @__PURE__ */ n(v, { className: "size-3.5 shrink-0 text-muted-foreground" }),
1652
- /* @__PURE__ */ n("span", { className: "max-w-[40%] shrink-0 truncate", title: e.name, children: c }),
1653
- /* @__PURE__ */ n(
1654
- "span",
1655
- {
1656
- className: k(
1657
- "min-w-0 flex-1 truncate text-muted-foreground",
1658
- (p === "command" || p === "file") && "font-mono"
1659
- ),
1660
- title: h,
1661
- children: h || (u ? "Receiving arguments..." : "")
1662
- }
1663
- ),
1664
- /* @__PURE__ */ d(
1665
- "span",
1666
- {
1667
- className: k(
1668
- "ml-auto flex shrink-0 items-center gap-1 text-[11px]",
1669
- x.tone === "danger" ? "text-danger" : x.tone === "warning" ? "text-warning" : "text-muted-foreground"
1670
- ),
1671
- children: [
1672
- g ? null : x.pending ? /* @__PURE__ */ n(ge, { className: "size-3 animate-spin" }) : x.tone === "success" ? /* @__PURE__ */ n(Te, { className: "size-3" }) : null,
1673
- /* @__PURE__ */ n("span", { children: g ? "Paused" : x.label })
1674
- ]
1675
- }
1676
- ),
1677
- /* @__PURE__ */ n(lt, { className: "size-3.5 shrink-0 text-muted-foreground opacity-0 transition group-open:rotate-90 group-open:opacity-100 group-hover/row:opacity-100 group-focus-visible/row:opacity-100" })
1678
- ] }),
1679
- i && /* @__PURE__ */ d(Nt, { className: "my-1", children: [
1680
- /* @__PURE__ */ d("div", { className: "flex items-center justify-between gap-2 py-1.5 pl-3 text-[11px] text-muted-foreground", children: [
1681
- /* @__PURE__ */ n("span", { className: "min-w-0 truncate font-mono", children: e.name }),
1682
- /* @__PURE__ */ n(
1683
- "button",
1684
- {
1685
- type: "button",
1686
- "aria-label": "Show raw arguments and result",
1687
- "aria-pressed": a,
1688
- className: k("shrink-0 cursor-pointer rounded-sm outline-none"),
1689
- onClick: () => r(!a),
1690
- children: "Raw"
1691
- }
1692
- )
1693
- ] }),
1694
- !m && /* @__PURE__ */ d("section", { className: "px-3 pb-3", "aria-label": "Arguments", children: [
1695
- /* @__PURE__ */ n("h4", { className: "mb-2 text-[11px] font-semibold text-muted-foreground", children: "Arguments" }),
1696
- /* @__PURE__ */ n("div", { className: "max-h-64 overflow-auto", children: /* @__PURE__ */ n(
1697
- Ge,
1698
- {
1699
- payload: o,
1700
- raw: a,
1701
- receiving: t && l === void 0,
1702
- tool: {
1703
- name: e.name,
1704
- family: p,
1705
- input: !0,
1706
- args: o.value
1707
- }
1708
- }
1709
- ) })
1710
- ] }),
1711
- /* @__PURE__ */ d("section", { className: "px-3 pb-3", "aria-label": "Result", children: [
1712
- /* @__PURE__ */ n("h4", { className: "mb-2 text-[11px] font-semibold text-muted-foreground", children: "Result" }),
1713
- /* @__PURE__ */ n("div", { className: "max-h-80 overflow-auto", children: l ? /* @__PURE__ */ n(
1714
- Ge,
1715
- {
1716
- payload: l,
1717
- raw: a,
1718
- markdown: e.name === "fork",
1719
- tool: {
1720
- name: e.name,
1721
- family: p,
1722
- input: !1,
1723
- args: o.value
1724
- }
1725
- }
1726
- ) : /* @__PURE__ */ n("p", { className: "text-muted-foreground", children: t ? "Waiting for result..." : "No result was received." }) })
1727
- ] })
1728
- ] })
1729
- ]
1730
- }
1731
- );
1732
- return e.interrupt ? /* @__PURE__ */ d("div", { className: "min-w-0", children: [
1733
- y,
1734
- /* @__PURE__ */ n(tn, { interrupt: e.interrupt })
1735
- ] }) : y;
1736
- }
1737
- function vn(e) {
1738
- const t = /* @__PURE__ */ new Map();
1739
- let i, s;
1740
- for (const a of e)
1741
- if (a.kind === "assistant") {
1742
- if (a.subagent) {
1743
- const r = [a.agent, a.branch].filter((o, l, c) => o && c.indexOf(o) === l).join(" · ");
1744
- s !== a.subagent && t.set(a.id, r || "Subagent");
1745
- } else a.agent && ((i && i !== a.agent || s && i) && t.set(a.id, a.agent), i = a.agent);
1746
- s = a.subagent;
1747
- }
1748
- return t;
1749
- }
1750
- function Ye(e, t) {
1751
- const i = (s) => s.kind === "tool" || s.kind === "reasoning";
1752
- return i(e) && i(t) ? "" : "mt-3";
1753
- }
1754
- const kt = (e) => e.kind === "tool" || e.kind === "reasoning";
1755
- function wn(e) {
1756
- let t = e.length;
1757
- for (; t > 0 && e[t - 1].item.kind === "assistant"; ) t--;
1758
- const i = e.slice(t), s = e.findIndex(({ item: o }) => o.kind !== "user"), a = s < 0 ? [] : e.slice(s, t);
1759
- return a.some(({ item: o }) => kt(o)) && i.some(({ item: o }) => o.kind === "assistant" && o.text.trim() !== "") && !a.some(({ item: o }) => o.kind === "tool" && o.interrupt && !o.interrupt.ended) ? { before: e.slice(0, s), steps: a, answer: i } : { before: e, steps: [], answer: [] };
1760
- }
1761
- function Nn({
1762
- count: e,
1763
- className: t,
1764
- children: i
1765
- }) {
1766
- const [s, a] = O(!1);
1767
- return /* @__PURE__ */ d("div", { className: t, children: [
1768
- /* @__PURE__ */ d(
1769
- "button",
1770
- {
1771
- type: "button",
1772
- "aria-expanded": s,
1773
- onClick: () => a(!s),
1774
- className: k(
1775
- "-mx-1.5 flex cursor-pointer items-center gap-1.5 rounded-sm px-1.5 py-1.5 text-sm outline-none hover:text-foreground focus-visible:bg-accent focus-visible:text-foreground",
1776
- s ? "text-foreground" : "text-muted-foreground"
1777
- ),
1778
- children: [
1779
- "Completed ",
1780
- e,
1781
- " ",
1782
- e === 1 ? "step" : "steps",
1783
- s ? /* @__PURE__ */ n(at, { className: "size-4" }) : /* @__PURE__ */ n(lt, { className: "size-4" })
1784
- ]
1785
- }
1786
- ),
1787
- s && /* @__PURE__ */ n("div", { className: "mb-1 ml-1.5 border-l border-border pl-3", children: i })
1788
- ] });
1789
- }
1790
- function kn({ item: e, running: t, agent: i }) {
1791
- switch (e.kind) {
1792
- case "user":
1793
- return /* @__PURE__ */ d(
1794
- "div",
1795
- {
1796
- className: "group/msg relative ml-auto flex w-fit max-w-[80%] flex-col items-end",
1797
- onCopy: He,
1798
- children: [
1799
- /* @__PURE__ */ n(Er, { className: "max-w-full rounded-xl bg-accent px-3 py-2 text-sm whitespace-pre-wrap [overflow-wrap:anywhere]", children: e.text }),
1800
- e.text && /* @__PURE__ */ n(
1801
- ze,
1802
- {
1803
- text: e.text,
1804
- label: "Copy message",
1805
- className: k("absolute bottom-1 right-full mr-1", qe)
1806
- }
1807
- )
1808
- ]
1809
- }
1810
- );
1811
- case "assistant":
1812
- return /* @__PURE__ */ d("div", { className: "group/msg relative min-w-0", onCopy: He, children: [
1813
- i && /* @__PURE__ */ n("div", { className: "mb-1 text-xs text-muted-foreground", children: i }),
1814
- /* @__PURE__ */ n(ie, { className: "text-sm", children: e.text }),
1815
- e.text && // Over the end of the last line, so it takes no height of its own.
1816
- /* @__PURE__ */ n(
1817
- ze,
1818
- {
1819
- text: e.text,
1820
- label: "Copy message",
1821
- className: k(
1822
- "absolute bottom-0 right-0 bg-background",
1823
- qe
1824
- )
1825
- }
1826
- )
1827
- ] });
1828
- case "reasoning":
1829
- return /* @__PURE__ */ d("details", { className: "group text-xs text-muted-foreground", children: [
1830
- /* @__PURE__ */ d("summary", { className: "-mx-1.5 flex cursor-pointer list-none items-center gap-1.5 rounded-sm px-1.5 py-1.5 outline-none hover:text-foreground focus-visible:bg-accent focus-visible:text-foreground [&::-webkit-details-marker]:hidden", children: [
1831
- /* @__PURE__ */ n(ot, { className: "size-3.5" }),
1832
- "Thinking"
1833
- ] }),
1834
- /* @__PURE__ */ n(Nt, { className: "mb-1", children: /* @__PURE__ */ n("div", { className: "whitespace-pre-wrap pl-3", children: e.text }) })
1835
- ] });
1836
- case "error":
1837
- return /* @__PURE__ */ n("div", { className: "rounded-md border border-danger/40 px-3 py-2 text-sm text-danger", children: e.text });
1838
- case "tool":
1839
- return /* @__PURE__ */ n(yn, { item: e, running: t });
1840
- }
1841
- }
1842
- function _n({
1843
- items: e,
1844
- running: t,
1845
- interrupts: i
1846
- }) {
1847
- var u, f;
1848
- const s = de(() => vn(e), [e]), a = de(() => {
1849
- const m = [];
1850
- return e.forEach((x, v) => {
1851
- (x.kind === "user" || m.length === 0) && m.push({ key: x.kind === "user" ? x.id : "head", rows: [] }), m.at(-1).rows.push({ item: x, index: v });
1852
- }), m;
1853
- }, [e]), r = (u = e.findLast((m) => m.kind === "user")) == null ? void 0 : u.id, o = $(null), l = $(null), c = $(void 0), p = $(void 0), h = (f = e[0]) == null ? void 0 : f.id;
1854
- return Se(() => {
1855
- var x, v, g;
1856
- const m = c.current;
1857
- c.current = r, h !== p.current ? (p.current = h, t && r ? (x = o.current) == null || x.scrollIntoView({ block: "start", behavior: "instant" }) : (v = l.current) == null || v.scrollIntoView({ block: "end", behavior: "instant" })) : t && r && r !== m && ((g = o.current) == null || g.scrollIntoView({ block: "start", behavior: "smooth" }));
1858
- }, [h, r, t]), /* @__PURE__ */ n(ht.Provider, { value: i ?? null, children: /* @__PURE__ */ d("div", { className: "mx-auto flex w-full max-w-5xl flex-col p-4", children: [
1859
- a.map((m, x) => {
1860
- var C;
1861
- const v = x === a.length - 1, g = v && t ? { before: m.rows, steps: [], answer: [] } : wn(m.rows), y = (w, j = !1) => w.map(({ item: L, index: E }) => /* @__PURE__ */ n(
1862
- "div",
1863
- {
1864
- className: k(
1865
- "min-w-0",
1866
- E > 0 && !j && L.kind !== "user" && Ye(e[E - 1], L),
1867
- // Folded steps are evenly spaced, remarks as tall as a step row.
1868
- j && L.kind === "assistant" && "py-1.5"
1869
- ),
1870
- children: /* @__PURE__ */ n(kn, { item: L, running: t, agent: s.get(L.id) })
1871
- },
1872
- `${L.kind}:${L.id}`
1873
- ));
1874
- return (
1875
- // The last turn is tall enough to scroll its message up to the top.
1876
- /* @__PURE__ */ d(
1877
- "div",
1878
- {
1879
- ref: v && m.rows[0].item.kind === "user" ? o : void 0,
1880
- className: k(
1881
- "flex flex-col scroll-mt-4",
1882
- x > 0 && "mt-6",
1883
- v && "min-h-[var(--chat-turn-min,calc(100cqh-var(--chat-turn-gap,2rem)))]"
1884
- ),
1885
- children: [
1886
- y(g.before),
1887
- g.steps.length > 0 && /* @__PURE__ */ n(
1888
- Nn,
1889
- {
1890
- count: g.steps.filter(({ item: w }) => kt(w)).length,
1891
- className: g.steps[0].index > 0 ? Ye(
1892
- e[g.steps[0].index - 1],
1893
- g.steps[0].item
1894
- ) : void 0,
1895
- children: y(g.steps, !0)
1896
- },
1897
- `steps:${g.steps[0].item.id}`
1898
- ),
1899
- y(g.answer),
1900
- v && t && ((C = e.at(-1)) == null ? void 0 : C.kind) === "user" && /* @__PURE__ */ n(ge, { className: "mt-4 size-4 animate-spin text-muted-foreground" })
1901
- ]
1902
- },
1903
- m.key
1904
- )
1905
- );
1906
- }),
1907
- /* @__PURE__ */ n("div", { ref: l })
1908
- ] }) });
1909
- }
1910
- function Sn({
1911
- title: e,
1912
- nudge: t = 0,
1913
- variants: i
1914
- }) {
1915
- const s = i != null && i.length ? Cn(i, t) : void 0, a = (s == null ? void 0 : s.title) ?? "Start your chat here", r = s ? s.subtitle : e;
1916
- return /* @__PURE__ */ n("div", { className: "flex flex-1 flex-col items-center justify-center gap-2 p-6 text-center", children: /* @__PURE__ */ d("div", { className: "empty-chat-nudge flex flex-col items-center gap-2", children: [
1917
- /* @__PURE__ */ n(Jt, { className: "size-8 text-muted-foreground" }),
1918
- /* @__PURE__ */ n("h2", { className: "text-xl font-semibold", children: a }),
1919
- r && /* @__PURE__ */ n("p", { className: "text-sm text-muted-foreground", children: r })
1920
- ] }, t) });
1921
- }
1922
- function Cn(e, t) {
1923
- const i = e[(t % e.length + e.length) % e.length];
1924
- return typeof i == "string" ? { title: i } : i;
1925
- }
1926
- function En(e) {
1927
- return /* @__PURE__ */ n(zn, { ...e }, e.draftKey ?? "");
1928
- }
1929
- function zn({
1930
- disabled: e,
1931
- running: t,
1932
- placeholder: i,
1933
- historyKey: s,
1934
- draftKey: a,
1935
- focusSignal: r,
1936
- onSend: o,
1937
- onStop: l
1938
- }) {
1939
- const [c, p] = O(() => a ? Vr(a) : "");
1940
- P(() => {
1941
- a && Be(a, c);
1942
- }, [a, c]);
1943
- const h = Gr(() => s ? pt(s) : []), u = $(null), f = $(null), m = ue(
1944
- (y) => Br(u.current, y),
1945
- []
1946
- );
1947
- P(() => {
1948
- e || m();
1949
- }, [e, m]), P(() => {
1950
- r && m();
1951
- }, [r, m]);
1952
- const x = $(t);
1953
- P(() => {
1954
- x.current && !t && m(f.current), x.current = t;
1955
- }, [t, m]), Se(() => {
1956
- const y = u.current;
1957
- y && (y.style.height = "auto", y.style.height = `${y.scrollHeight}px`);
1958
- }, [c]);
1959
- const v = (y) => {
1960
- y == null || y.preventDefault(), !(e || t || !c.trim()) && (o(c), s && Kr(s, c), h.reset(), a && Be(a, ""), p(""), m(f.current));
1961
- };
1962
- return /* @__PURE__ */ n("form", { ref: f, onSubmit: v, className: "mx-auto w-full max-w-5xl p-4", children: /* @__PURE__ */ d(
1963
- "div",
1964
- {
1965
- className: "thinking-border flex items-end gap-2 rounded-xl border border-input bg-surface-input p-2",
1966
- "data-thinking": t,
1967
- children: [
1968
- /* @__PURE__ */ n(
1969
- ft,
1970
- {
1971
- ref: u,
1972
- disabled: e,
1973
- rows: 1,
1974
- value: c,
1975
- onChange: (y) => p(y.target.value),
1976
- onKeyDown: (y) => {
1977
- y.key === "Enter" && !y.shiftKey && !y.nativeEvent.isComposing ? v(y) : s && h.onKeyDown(y, c, p);
1978
- },
1979
- placeholder: i,
1980
- className: "max-h-60 min-h-9 resize-none overflow-y-auto border-0 bg-transparent leading-5 focus-visible:ring-0"
1981
- }
1982
- ),
1983
- t ? /* @__PURE__ */ n(ye, { label: "Stop", className: "zenera-chat", children: /* @__PURE__ */ n(
1984
- re,
1985
- {
1986
- type: "button",
1987
- size: "icon",
1988
- variant: "outline",
1989
- onClick: () => {
1990
- l(), m(f.current);
1991
- },
1992
- "aria-label": "Stop",
1993
- children: /* @__PURE__ */ n(Xt, {})
1994
- }
1995
- ) }) : /* @__PURE__ */ n(ye, { label: "Send (Enter)", className: "zenera-chat", children: /* @__PURE__ */ n(
1996
- re,
1997
- {
1998
- type: "submit",
1999
- size: "icon",
2000
- disabled: e || !c.trim(),
2001
- "aria-label": "Send",
2002
- className: k(!c.trim() && "opacity-60"),
2003
- children: /* @__PURE__ */ n(Zt, {})
2004
- }
2005
- ) })
2006
- ]
2007
- }
2008
- ) });
2009
- }
2010
- let Ln;
2011
- const On = () => Ln ?? (Ln = import("./shadow-BRAwePHz.js").then((e) => e.default));
2012
- function An(e) {
2013
- if (document.querySelector("style[data-zenera-chat-properties]")) return;
2014
- const t = e.match(/@property\s+[^{]+\{[^}]*\}/g);
2015
- if (!t) return;
2016
- const i = document.createElement("style");
2017
- i.dataset.zeneraChatProperties = "", i.textContent = t.join(`
2018
- `), document.head.append(i);
2019
- }
2020
- function _t({
2021
- children: e,
2022
- className: t,
2023
- style: i
2024
- }) {
2025
- const s = $(null), [a, r] = O(null);
2026
- return Se(() => {
2027
- const o = s.current;
2028
- if (!o) return;
2029
- const l = o.shadowRoot ?? o.attachShadow({ mode: "open" }), c = document.createElement("style"), p = document.createElement("div");
2030
- p.style.height = "100%", l.append(c, p);
2031
- let h = !0;
2032
- return On().then((u) => {
2033
- h && (An(u), c.textContent = u, r(p));
2034
- }), () => {
2035
- h = !1, c.remove(), p.remove(), r(null);
2036
- };
2037
- }, []), /* @__PURE__ */ n(
2038
- "div",
2039
- {
2040
- ref: s,
2041
- className: t,
2042
- style: { display: "block", height: "100%", ...i },
2043
- children: a && ct(
2044
- /* @__PURE__ */ n(mt.Provider, { value: a, children: e }),
2045
- a
2046
- )
2047
- }
2048
- );
2049
- }
2050
- const ke = (e) => e && Object.fromEntries(
2051
- Object.entries(e).map(([t, i]) => [`--${t}`, i])
2052
- );
2053
- function _i({ isolate: e = !0, className: t, style: i, theme: s, ...a }) {
2054
- const r = je();
2055
- return e ? /* @__PURE__ */ n(_t, { className: t, style: i, children: /* @__PURE__ */ n(Oe, { ...a, dark: r === "dark", rootStyle: ke(s) }) }) : /* @__PURE__ */ n(
2056
- Oe,
2057
- {
2058
- ...a,
2059
- rootClassName: t,
2060
- rootStyle: { ...ke(s), ...i }
2061
- }
2062
- );
2063
- }
2064
- function Oe({
2065
- transport: e,
2066
- threadId: t,
2067
- onThreadChange: i,
2068
- onTurnEnd: s,
2069
- placeholder: a = "Message…",
2070
- starterMessages: r,
2071
- newChatSignal: o = 0,
2072
- historyKey: l,
2073
- draftKey: c,
2074
- rootClassName: p,
2075
- rootStyle: h,
2076
- dark: u,
2077
- nested: f
2078
- }) {
2079
- const [m, x] = O(null), v = t ?? m;
2080
- P(() => x(null), [t]);
2081
- const g = nr(e, v), [y, C] = O(null), [w, j] = O(!1);
2082
- P(() => {
2083
- y && v && (C(null), g.send(y));
2084
- }, [y, v, g]);
2085
- const L = g.status === "running", [E, q] = O(!1);
2086
- P(() => {
2087
- E && !L && (s == null || s()), q(L);
2088
- }, [L, E, s]);
2089
- const D = ue(
2090
- (se) => {
2091
- if (v) {
2092
- g.send(se);
2093
- return;
2094
- }
2095
- e && (j(!0), e.createThread().then(({ thread: B }) => {
2096
- C(se), x(B.id), i == null || i(B.id);
2097
- }).catch(() => {
2098
- }).finally(() => j(!1)));
2099
- },
2100
- [v, g, e, i]
2101
- ), J = !!(v && g.status === "idle" && !g.items.length && g.error);
2102
- return /* @__PURE__ */ d(
2103
- "div",
2104
- {
2105
- className: k(
2106
- !f && "zenera-chat",
2107
- "flex h-full min-h-0 flex-col text-foreground",
2108
- u && "dark",
2109
- p
2110
- ),
2111
- style: h,
2112
- children: [
2113
- J ? /* @__PURE__ */ n("div", { className: "flex flex-1 items-center justify-center p-6 text-center", children: /* @__PURE__ */ n("h2", { className: "text-xl font-semibold", children: g.error }) }) : !v && !g.items.length && (r != null && r.length) ? /* @__PURE__ */ n(Sn, { nudge: o, variants: r }) : /* @__PURE__ */ d("div", { className: "min-h-0 flex-1 overflow-y-auto [container-type:size]", children: [
2114
- /* @__PURE__ */ n(
2115
- _n,
2116
- {
2117
- items: g.items,
2118
- running: L,
2119
- interrupts: {
2120
- info: g.interruptInfo,
2121
- cancel: g.cancelInterrupt,
2122
- refresh: g.refreshInterrupts
2123
- }
2124
- }
2125
- ),
2126
- v && g.status === "loading" && !g.starting && /* @__PURE__ */ n(ge, { className: "mx-auto size-4 animate-spin text-muted-foreground" })
2127
- ] }),
2128
- g.starting && /* @__PURE__ */ d("p", { className: "mx-auto flex items-center gap-2 text-sm text-muted-foreground", children: [
2129
- /* @__PURE__ */ n(ge, { className: "size-3.5 animate-spin" }),
2130
- "Starting the project (",
2131
- g.starting,
2132
- ")…"
2133
- ] }),
2134
- g.reconnecting && !g.starting && /* @__PURE__ */ d("p", { className: "mx-auto flex items-center gap-2 text-sm text-muted-foreground", children: [
2135
- /* @__PURE__ */ n(ge, { className: "size-3.5 animate-spin" }),
2136
- "Connection lost, reconnecting… the answer goes on meanwhile."
2137
- ] }),
2138
- g.error && !J && /* @__PURE__ */ n("p", { className: "mx-auto w-full max-w-5xl px-4 text-sm text-danger", children: g.error }),
2139
- /* @__PURE__ */ n(
2140
- En,
2141
- {
2142
- disabled: !e || !!g.starting || w,
2143
- running: L,
2144
- placeholder: a,
2145
- historyKey: l,
2146
- draftKey: c,
2147
- onSend: D,
2148
- onStop: g.cancel
2149
- }
2150
- )
2151
- ]
2152
- }
2153
- );
2154
- }
2155
- function Tn(e, t = 4e3) {
2156
- const [i, s] = O(null), a = $(void 0);
2157
- P(() => () => clearTimeout(a.current), []);
2158
- const r = ue(() => {
2159
- clearTimeout(a.current), s(null);
2160
- }, []);
2161
- return { armed: i, request: (l) => {
2162
- if (clearTimeout(a.current), i !== l) {
2163
- s(l), a.current = setTimeout(() => s(null), t);
2164
- return;
2165
- }
2166
- s(null), e(l);
2167
- }, disarm: r };
2168
- }
2169
- function jn({
2170
- armed: e,
2171
- onClick: t,
2172
- disabled: i,
2173
- label: s = "Delete",
2174
- alwaysShown: a,
2175
- className: r
2176
- }) {
2177
- const o = e ? "Click again to delete" : s;
2178
- return /* @__PURE__ */ n(ye, { label: o, children: /* @__PURE__ */ d(
2179
- "button",
2180
- {
2181
- type: "button",
2182
- "aria-label": o,
2183
- disabled: i,
2184
- onClick: (l) => {
2185
- l.stopPropagation(), t();
2186
- },
2187
- className: k(
2188
- "cursor-pointer items-center gap-1 rounded p-1 text-xs text-muted-foreground hover:text-danger disabled:opacity-50",
2189
- e ? "flex bg-danger/15 px-1.5 text-danger" : a ? "flex" : "hidden group-focus-within:flex group-hover:flex [@media(hover:none)]:flex",
2190
- r
2191
- ),
2192
- children: [
2193
- /* @__PURE__ */ n(Gt, { className: "size-3.5" }),
2194
- e && "Delete"
2195
- ]
2196
- }
2197
- ) });
2198
- }
2199
- const Rn = 45, In = 256, Ee = 192, Ve = 480, St = 300, $n = 140, Qe = (e) => typeof localStorage > "u" ? null : localStorage.getItem(e);
2200
- function Pn(e, t, i) {
2201
- return e === "right" ? i.right - t : t - i.left;
2202
- }
2203
- function Mn(e = "zenera.chatSidebar", t = "left", i) {
2204
- const s = `${e}Collapsed`, a = `${e}Width`, [r, o] = O(() => {
2205
- if (i !== void 0) return i;
2206
- const m = Qe(s);
2207
- return m !== null ? m === "1" : typeof window < "u" && window.matchMedia("(max-width: 767px)").matches;
2208
- }), [l, c] = O(() => {
2209
- const m = Number(Qe(a));
2210
- return m >= Ee && m <= Ve ? m : In;
2211
- }), [p, h] = O(!1);
2212
- return { collapsed: r, width: l, resizing: p, toggle: () => o((m) => (localStorage.setItem(s, m ? "0" : "1"), !m)), setCollapsed: o, startResize: (m) => {
2213
- var q;
2214
- const x = m.currentTarget.parentElement;
2215
- if (!x) return;
2216
- const v = (((q = x.parentElement) == null ? void 0 : q.clientWidth) ?? 1 / 0) - St, g = Math.min(Ve, v);
2217
- if (g < Ee) return;
2218
- m.preventDefault();
2219
- const y = m.currentTarget;
2220
- y.setPointerCapture(m.pointerId);
2221
- const C = x.getBoundingClientRect();
2222
- let w = r, j = l;
2223
- h(!0);
2224
- const L = (D) => {
2225
- const J = Pn(t, D.clientX, C);
2226
- w = J < $n, o(w), w || (j = Math.round(Math.min(Math.max(J, Ee), g)), c(j));
2227
- }, E = () => {
2228
- y.removeEventListener("pointermove", L), y.removeEventListener("lostpointercapture", E), h(!1), localStorage.setItem(s, w ? "1" : "0"), localStorage.setItem(a, String(j));
2229
- };
2230
- y.addEventListener("pointermove", L), y.addEventListener("lostpointercapture", E);
2231
- } };
2232
- }
2233
- function Dn({
2234
- transport: e,
2235
- layout: t,
2236
- activeThreadId: i,
2237
- onSelect: s,
2238
- onNew: a,
2239
- onDelete: r,
2240
- renderLink: o,
2241
- newDisabled: l,
2242
- refreshKey: c,
2243
- footer: p,
2244
- side: h = "left",
2245
- showToggle: u = !1,
2246
- className: f
2247
- }) {
2248
- const { collapsed: m, width: x, resizing: v, startResize: g } = t, y = ir(e, c), C = Tn((E) => {
2249
- y.remove(E).then(() => r == null ? void 0 : r(E)).catch(() => {
2250
- });
2251
- }), w = !e || l, j = h === "right" ? "left" : "right", L = h === "right" ? m ? Yt : Vt : m ? Qt : er;
2252
- return /* @__PURE__ */ d(
2253
- "aside",
2254
- {
2255
- style: { width: m ? Rn : x },
2256
- className: k(
2257
- "relative flex shrink-0 flex-col gap-2 border-border",
2258
- h === "right" ? "border-l" : "border-r",
2259
- m ? "items-center p-1 pt-3" : "p-3",
2260
- !v && "transition-[width] duration-150",
2261
- f
2262
- ),
2263
- children: [
2264
- /* @__PURE__ */ n(
2265
- "div",
2266
- {
2267
- className: k(
2268
- "group absolute inset-y-0 z-10 w-2 cursor-col-resize touch-none",
2269
- h === "right" ? "-left-1" : "-right-1"
2270
- ),
2271
- title: "Drag to resize",
2272
- onPointerDown: g,
2273
- children: /* @__PURE__ */ n("div", { className: "mx-auto h-full w-px group-hover:w-0.5 group-hover:bg-primary/60" })
2274
- }
2275
- ),
2276
- /* @__PURE__ */ d(
2277
- "div",
2278
- {
2279
- className: k(
2280
- "flex gap-2",
2281
- m ? "flex-col items-center" : h === "right" ? "flex-row-reverse" : "flex-row"
2282
- ),
2283
- children: [
2284
- u && /* @__PURE__ */ n(
2285
- ye,
2286
- {
2287
- label: m ? "Expand sidebar" : "Collapse sidebar",
2288
- side: m ? j : "bottom",
2289
- children: /* @__PURE__ */ n(
2290
- re,
2291
- {
2292
- variant: "outline",
2293
- size: "icon",
2294
- "aria-label": m ? "Expand sidebar" : "Collapse sidebar",
2295
- "aria-expanded": !m,
2296
- onClick: t.toggle,
2297
- children: /* @__PURE__ */ n(L, {})
2298
- }
2299
- )
2300
- }
2301
- ),
2302
- m ? /* @__PURE__ */ n(ye, { label: "New chat", side: j, children: /* @__PURE__ */ n(
2303
- re,
2304
- {
2305
- variant: "outline",
2306
- size: "icon",
2307
- "aria-label": "New chat",
2308
- disabled: w,
2309
- onClick: a,
2310
- children: /* @__PURE__ */ n(tr, {})
2311
- }
2312
- ) }) : /* @__PURE__ */ d(
2313
- re,
2314
- {
2315
- variant: "outline",
2316
- className: "min-w-0 flex-1 justify-start overflow",
2317
- disabled: w,
2318
- onClick: a,
2319
- children: [
2320
- /* @__PURE__ */ n(rr, {}),
2321
- "New chat"
2322
- ]
2323
- }
2324
- )
2325
- ]
2326
- }
2327
- ),
2328
- /* @__PURE__ */ n(
2329
- "div",
2330
- {
2331
- className: k(
2332
- "flex min-h-0 flex-1 flex-col gap-1.5 overflow-y-auto",
2333
- m && "hidden"
2334
- ),
2335
- children: y.threads.map((E) => {
2336
- const q = E.id === i, D = {
2337
- className: k(
2338
- "flex min-w-0 flex-1 cursor-pointer items-center gap-2 px-2 py-1.5 text-left text-sm text-muted-foreground hover:text-foreground",
2339
- q && "text-foreground"
2340
- ),
2341
- children: /* @__PURE__ */ n("span", { className: "truncate", children: E.title })
2342
- };
2343
- return /* @__PURE__ */ d(
2344
- "div",
2345
- {
2346
- className: k(
2347
- "group flex items-center rounded-md hover:bg-accent",
2348
- q && "bg-accent"
2349
- ),
2350
- children: [
2351
- o ? o(E, D) : /* @__PURE__ */ n(
2352
- "button",
2353
- {
2354
- type: "button",
2355
- className: D.className,
2356
- onClick: () => s == null ? void 0 : s(E.id),
2357
- children: D.children
2358
- }
2359
- ),
2360
- /* @__PURE__ */ n(
2361
- jn,
2362
- {
2363
- armed: C.armed === E.id,
2364
- disabled: y.removing,
2365
- label: "Delete chat",
2366
- onClick: () => C.request(E.id),
2367
- className: "mr-1"
2368
- }
2369
- )
2370
- ]
2371
- },
2372
- E.id
2373
- );
2374
- })
2375
- }
2376
- ),
2377
- p
2378
- ]
2379
- }
2380
- );
2381
- }
2382
- function Si({
2383
- isolate: e = !0,
2384
- className: t,
2385
- style: i,
2386
- theme: s,
2387
- ...a
2388
- }) {
2389
- const r = je();
2390
- return e ? /* @__PURE__ */ n(_t, { className: t, style: i, children: /* @__PURE__ */ n(et, { ...a, dark: r === "dark", rootStyle: ke(s) }) }) : /* @__PURE__ */ n(
2391
- et,
2392
- {
2393
- ...a,
2394
- rootClassName: t,
2395
- rootStyle: { ...ke(s), ...i }
2396
- }
2397
- );
2398
- }
2399
- function et({
2400
- transport: e,
2401
- threadId: t,
2402
- onThreadChange: i,
2403
- onTurnEnd: s,
2404
- renderLink: a,
2405
- sidebarStorageKey: r,
2406
- sidebarSide: o = "left",
2407
- sidebarCollapsed: l,
2408
- onSidebarCollapsedChange: c,
2409
- sidebarToggle: p = !1,
2410
- sidebarClassName: h,
2411
- rootClassName: u,
2412
- rootStyle: f,
2413
- dark: m,
2414
- ...x
2415
- }) {
2416
- const v = Mn(r, o, l), { collapsed: g, setCollapsed: y } = v, C = $(null), [w, j] = O(null);
2417
- P(() => {
2418
- const R = C.current;
2419
- if (!R || typeof ResizeObserver > "u") return;
2420
- const Q = new ResizeObserver(() => j(R.clientWidth));
2421
- return Q.observe(R), () => Q.disconnect();
2422
- }, []);
2423
- const E = w !== null && w - v.width < St && !g ? { ...v, collapsed: !0 } : v, q = $(!1);
2424
- P(() => {
2425
- q.current ? l !== void 0 && y(l) : q.current = !0;
2426
- }, [l, y]);
2427
- const D = $(c);
2428
- D.current = c, P(() => {
2429
- var R;
2430
- return (R = D.current) == null ? void 0 : R.call(D, g);
2431
- }, [g]);
2432
- const [J, se] = O(null), [B, ve] = O(0), ae = t === void 0 ? J : t, [Ce, we] = O(0), H = ue(
2433
- (R) => {
2434
- se(R), i == null || i(R);
2435
- },
2436
- [i]
2437
- ), G = /* @__PURE__ */ n(
2438
- Dn,
2439
- {
2440
- transport: e,
2441
- layout: E,
2442
- side: o,
2443
- showToggle: p,
2444
- activeThreadId: ae,
2445
- onSelect: H,
2446
- onNew: () => {
2447
- ve((R) => R + 1), H(null);
2448
- },
2449
- onDelete: (R) => R === ae && H(null),
2450
- renderLink: a,
2451
- refreshKey: Ce,
2452
- className: h
2453
- }
2454
- );
2455
- return /* @__PURE__ */ d(
2456
- "div",
2457
- {
2458
- ref: C,
2459
- className: k(
2460
- "zenera-chat flex h-full min-h-0 text-foreground",
2461
- m && "dark",
2462
- u
2463
- ),
2464
- style: f,
2465
- children: [
2466
- o === "left" && G,
2467
- /* @__PURE__ */ n("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ n(
2468
- Oe,
2469
- {
2470
- ...x,
2471
- nested: !0,
2472
- newChatSignal: B,
2473
- transport: e,
2474
- threadId: ae,
2475
- onThreadChange: (R) => {
2476
- we((Q) => Q + 1), H(R);
2477
- },
2478
- onTurnEnd: () => {
2479
- we((R) => R + 1), s == null || s();
2480
- }
2481
- }
2482
- ) }),
2483
- o === "right" && G
2484
- ]
2485
- }
2486
- );
2487
- }
2488
- const Ct = 360, Et = 320, zt = 360, Wn = 240, Y = (e, t, i) => Math.min(Math.max(e, t), i), fe = (e, t) => Math.min(e, t);
2489
- function Lt(e, t) {
2490
- const i = Y(
2491
- e.width,
2492
- fe(Ct, t.width),
2493
- Math.max(t.width, 0)
2494
- ), s = Y(
2495
- e.height,
2496
- fe(Et, t.height),
2497
- Math.max(t.height, 0)
2498
- );
2499
- return {
2500
- width: i,
2501
- height: s,
2502
- left: Y(e.left, 0, t.width - i),
2503
- top: Y(e.top, 0, t.height - s)
2504
- };
2505
- }
2506
- function Hn(e, t, i, s) {
2507
- return Lt({ ...e, left: e.left + t, top: e.top + i }, s);
2508
- }
2509
- function qn(e, t, i, s, a) {
2510
- const r = fe(Ct, a.width), o = fe(Et, a.height);
2511
- let l = e.left, c = e.top, p = e.left + e.width, h = e.top + e.height;
2512
- return t.includes("w") && (l = Y(l + i, 0, p - r)), t.includes("e") && (p = Y(p + i, l + r, a.width)), t.includes("n") && (c = Y(c + s, 0, h - o)), t.includes("s") && (h = Y(h + s, c + o, a.height)), { left: l, top: c, width: p - l, height: h - c };
2513
- }
2514
- function Bn(e, t) {
2515
- const i = t ? e - Wn : e;
2516
- return Math.max(i, fe(zt, e));
2517
- }
2518
- function Ot(e, t, i) {
2519
- return Y(
2520
- e,
2521
- fe(zt, t),
2522
- Bn(t, i)
2523
- );
2524
- }
2525
- function tt(e, t, i, s, a) {
2526
- const r = t === "right" ? e - i : e + i;
2527
- return Ot(r, s, a);
2528
- }
2529
- const he = (e) => {
2530
- throw new Error(`ZeneraChatLauncher: ${e}`);
2531
- };
2532
- function rt(e, t) {
2533
- const { mode: i, side: s = "right", width: a, resizable: r = !0, defaultOpen: o = !1 } = e, { placement: l, height: c, contentTarget: p, draggable: h = !0 } = e;
2534
- i !== "popup" && i !== "sidebar" && he(`presentation.mode must be 'popup' or 'sidebar', not ${String(i)}`), s !== "left" && s !== "right" && he(`presentation.side must be 'left' or 'right', not ${String(s)}`);
2535
- let u = null;
2536
- return i === "sidebar" && (l !== "overlay" && l !== "docked" && he("a sidebar needs presentation.placement: 'overlay' or 'docked'"), l === "docked" && (p || he("a docked sidebar needs presentation.contentTarget"), u = typeof p == "string" ? t(p) : p, u || he(`contentTarget ${String(p)} matches no element`))), {
2537
- mode: i,
2538
- docked: i === "sidebar" && l === "docked",
2539
- side: s,
2540
- width: a ?? (i === "popup" ? "380px" : "820px"),
2541
- height: c ?? "600px",
2542
- contentTarget: u,
2543
- resizable: r,
2544
- draggable: h,
2545
- defaultOpen: o
2546
- };
2547
- }
2548
- const Fn = "(max-width: 767px)", Un = ["n", "s", "e", "w", "ne", "nw", "se", "sw"], nt = 16, Kn = `
2549
- :host { display: contents; }
2550
- * { box-sizing: border-box; }
2551
- .button {
2552
- position: fixed; bottom: 24px; z-index: 2147483000;
2553
- width: 56px; height: 56px; padding: 0; border: 0; border-radius: 50%;
2554
- display: flex; align-items: center; justify-content: center; cursor: pointer;
2555
- background: var(--zenera-launcher-accent, #4f46e5); color: #fff;
2556
- box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
2557
- }
2558
- .button[hidden] { display: none; }
2559
- .button:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }
2560
- .button[data-side='right'] { right: 24px; }
2561
- .button[data-side='left'] { left: 24px; }
2562
- .panel {
2563
- position: fixed; z-index: 2147483001; display: flex; flex-direction: column;
2564
- background: #fff; color: #111827; border: 0 solid #e5e7eb;
2565
- font: 14px/1.4 system-ui, -apple-system, 'Segoe UI', sans-serif;
2566
- }
2567
- .panel[hidden] { display: none; }
2568
- .panel:focus { outline: none; }
2569
- .panel[data-mode='popup'] {
2570
- bottom: 96px; max-width: calc(100vw - 32px); max-height: calc(100vh - 120px);
2571
- border-width: 1px; border-radius: 12px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
2572
- }
2573
- .panel[data-mode='popup'][data-side='right'] { right: 24px; }
2574
- .panel[data-mode='popup'][data-side='left'] { left: 24px; }
2575
- .panel[data-mode='sidebar'] { top: 0; bottom: 0; max-width: 100vw; }
2576
- .panel[data-mode='sidebar'][data-side='right'] { right: 0; border-left-width: 1px; }
2577
- .panel[data-mode='sidebar'][data-side='left'] { left: 0; border-right-width: 1px; }
2578
- .panel[data-mode='sidebar'][data-overlay] { box-shadow: 0 0 32px rgba(0, 0, 0, 0.2); }
2579
- .header {
2580
- display: flex; align-items: center; justify-content: space-between; flex: none;
2581
- height: 44px; padding: 0 8px 0 16px; border-bottom: 1px solid #e5e7eb; font-weight: 600;
2582
- }
2583
- .close {
2584
- width: 32px; height: 32px; padding: 0; border: 0; border-radius: 6px;
2585
- background: transparent; color: inherit; cursor: pointer; font-size: 20px; line-height: 1;
2586
- }
2587
- .close:hover { background: rgba(127, 127, 127, 0.2); }
2588
- .close:focus-visible { outline: 2px solid #93c5fd; }
2589
- .header[data-draggable] { cursor: grab; touch-action: none; user-select: none; }
2590
- .panel[data-gesture] .header[data-draggable] { cursor: grabbing; }
2591
- .panel[data-gesture], .panel[data-gesture] ::slotted(*) { user-select: none; }
2592
- .handle { position: absolute; z-index: 1; touch-action: none; }
2593
- .handle[hidden] { display: none; }
2594
- .handle[data-edge='n'] { top: -3px; left: 14px; right: 14px; height: 6px; cursor: ns-resize; }
2595
- .handle[data-edge='s'] { bottom: -3px; left: 14px; right: 14px; height: 6px; cursor: ns-resize; }
2596
- .handle[data-edge='e'] { right: -3px; top: 14px; bottom: 14px; width: 6px; cursor: ew-resize; }
2597
- .handle[data-edge='w'] { left: -3px; top: 14px; bottom: 14px; width: 6px; cursor: ew-resize; }
2598
- .handle[data-edge='ne'] { top: -4px; right: -4px; width: 14px; height: 14px; cursor: nesw-resize; }
2599
- .handle[data-edge='nw'] { top: -4px; left: -4px; width: 14px; height: 14px; cursor: nwse-resize; }
2600
- .handle[data-edge='se'] { bottom: -4px; right: -4px; width: 14px; height: 14px; cursor: nwse-resize; }
2601
- .handle[data-edge='sw'] { bottom: -4px; left: -4px; width: 14px; height: 14px; cursor: nesw-resize; }
2602
- .panel[data-mode='sidebar'] .handle { top: 0; bottom: 0; }
2603
- .handle:focus-visible { outline: 2px solid #93c5fd; outline-offset: -2px; }
2604
- .body { flex: 1; min-height: 0; }
2605
- slot { display: block; height: 100%; }
2606
- :host([data-scheme='dark']) .panel { background: #111827; color: #f9fafb; border-color: #374151; }
2607
- :host([data-scheme='dark']) .header { border-color: #374151; }
2608
- `, Jn = '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>', U = (e, t = {}) => {
2609
- const i = document.createElement(e);
2610
- for (const [s, a] of Object.entries(t)) i.setAttribute(s, a);
2611
- return i;
2612
- };
2613
- function Xn(e) {
2614
- var De;
2615
- const { chatId: t, onOpenChange: i } = e;
2616
- if (!t) throw new Error("ZeneraChatLauncher: chatId is required");
2617
- if (document.getElementById(t))
2618
- throw new Error(`ZeneraChatLauncher: the page already has an element with id "${t}"`);
2619
- const s = (b) => document.querySelector(b), a = (De = window.matchMedia) == null ? void 0 : De.call(window, Fn);
2620
- let r = e.presentation, o = rt(r, s), l = o.defaultOpen, c = !1, p = (a == null ? void 0 : a.matches) ?? !1, h = null, u = null, f = null, m = null;
2621
- const x = U("div", { "data-zenera-chat-launcher": "" }), v = U("div", { id: t });
2622
- v.style.cssText = "display:block;height:100%", x.append(v);
2623
- const g = x.attachShadow({ mode: "open" }), y = U("style");
2624
- y.textContent = Kn;
2625
- const C = U("button", { type: "button", class: "button" });
2626
- C.innerHTML = Jn;
2627
- const w = U("div", {
2628
- class: "panel",
2629
- role: "dialog",
2630
- "aria-modal": "false",
2631
- "aria-label": "Chat",
2632
- tabindex: "-1"
2633
- }), j = U("div", { class: "header" }), L = U("span");
2634
- L.textContent = "Chat";
2635
- const E = U("button", { type: "button", class: "close", "aria-label": "Close chat" });
2636
- E.textContent = "×", j.append(L, E);
2637
- const q = U("div", { class: "body" });
2638
- q.append(U("slot")), w.append(j, q);
2639
- const D = /* @__PURE__ */ new Map();
2640
- for (const b of Un) {
2641
- const S = U("div", { class: "handle", "data-edge": b });
2642
- D.set(b, S), w.append(S);
2643
- }
2644
- g.append(y, C, w);
2645
- const J = () => {
2646
- if (!h) return;
2647
- const { target: b, property: S, value: N, priority: z } = h;
2648
- N ? b.style.setProperty(S, N, z) : b.style.removeProperty(S), h = null;
2649
- }, se = (b, S) => {
2650
- const N = b.contentTarget, z = b.side === "left" ? "margin-left" : "margin-right";
2651
- h = {
2652
- target: N,
2653
- property: z,
2654
- value: N.style.getPropertyValue(z),
2655
- priority: N.style.getPropertyPriority(z)
2656
- }, N.style.setProperty(z, S);
2657
- }, B = () => ({
2658
- width: document.documentElement.clientWidth || window.innerWidth,
2659
- height: window.innerHeight
2660
- }), ve = () => {
2661
- const { left: b, top: S, width: N, height: z } = w.getBoundingClientRect();
2662
- return { left: b, top: S, width: N, height: z };
2663
- }, ae = () => l && o.docked && !p, Ce = (b) => {
2664
- const { mode: S, side: N, width: z, height: F, resizable: X, draggable: oe } = o, le = S === "popup", W = w.style;
2665
- le && f ? (f = Lt(f, B()), W.left = `${f.left}px`, W.top = `${f.top}px`, W.width = `${f.width}px`, W.height = `${f.height}px`, W.right = W.bottom = "auto", W.maxWidth = W.maxHeight = "none") : (W.left = W.top = W.right = W.bottom = "", W.maxWidth = W.maxHeight = "", W.width = le ? z : we(b), W.height = le ? F : ""), j.toggleAttribute("data-draggable", le && oe);
2666
- const At = N === "right" ? "w" : "e";
2667
- for (const [Tt, ce] of D) {
2668
- const We = X && (le || Tt === At);
2669
- if (ce.hidden = !We, We && !le)
2670
- ce.setAttribute("role", "separator"), ce.setAttribute("aria-orientation", "vertical"), ce.setAttribute("aria-label", "Resize chat"), ce.tabIndex = 0;
2671
- else
2672
- for (const jt of ["role", "aria-orientation", "aria-label", "tabindex"])
2673
- ce.removeAttribute(jt);
2674
- }
2675
- }, we = (b) => m === null ? o.width : `${Ot(m, B().width, b)}px`, H = () => {
2676
- const { mode: b, side: S, docked: N } = o, z = l && N && !p;
2677
- w.dataset.mode = b, w.dataset.side = S, C.dataset.side = S, w.toggleAttribute("data-overlay", b === "sidebar" && !z), w.hidden = !l, C.hidden = l && b === "sidebar", C.setAttribute("aria-expanded", String(l)), C.setAttribute("aria-label", l ? "Close chat" : "Open chat"), Ce(z), J(), z && se(o, w.style.width);
2678
- }, G = (b) => {
2679
- if (b === l) return;
2680
- b && (u = document.activeElement);
2681
- const S = !b && x.contains(document.activeElement);
2682
- l = b, H(), b ? w.focus() : S && (u instanceof HTMLElement && u.isConnected ? u : C).focus(), i == null || i(l);
2683
- }, R = () => {
2684
- if (c) throw new Error("ZeneraChatLauncher: already unmounted");
2685
- }, Q = (b) => {
2686
- b.key === "Escape" && l && !b.defaultPrevented && G(!1);
2687
- }, Re = (b) => {
2688
- p = b.matches, H();
2689
- }, Ie = () => {
2690
- l && (f || m !== null) && H();
2691
- }, $e = (b, S) => {
2692
- b.addEventListener("pointerdown", (N) => {
2693
- if (N.button !== 0 || !N.isPrimary) return;
2694
- const z = S(N);
2695
- if (!z) return;
2696
- N.preventDefault(), b.setPointerCapture(N.pointerId), w.setAttribute("data-gesture", "");
2697
- const F = (oe) => z(oe.clientX - N.clientX, oe.clientY - N.clientY), X = () => {
2698
- w.removeAttribute("data-gesture"), b.removeEventListener("pointermove", F), b.removeEventListener("pointerup", X), b.removeEventListener("pointercancel", X);
2699
- };
2700
- b.addEventListener("pointermove", F), b.addEventListener("pointerup", X), b.addEventListener("pointercancel", X);
2701
- });
2702
- };
2703
- for (const [b, S] of D)
2704
- $e(S, () => {
2705
- if (!o.resizable) return null;
2706
- if (o.mode === "popup") {
2707
- const F = ve();
2708
- return (X, oe) => {
2709
- f = qn(F, b, X, oe, B()), H();
2710
- };
2711
- }
2712
- const N = w.getBoundingClientRect().width, z = ae();
2713
- return (F) => {
2714
- m = tt(
2715
- N,
2716
- o.side,
2717
- F,
2718
- B().width,
2719
- z
2720
- ), H();
2721
- };
2722
- });
2723
- $e(j, (b) => {
2724
- if (o.mode !== "popup" || !o.draggable || b.target instanceof Node && E.contains(b.target)) return null;
2725
- const S = ve();
2726
- return (N, z) => {
2727
- f = Hn(S, N, z, B()), H();
2728
- };
2729
- }), g.addEventListener("keydown", (b) => {
2730
- const { key: S, target: N } = b;
2731
- !(N instanceof HTMLElement) || !N.classList.contains("handle") || S !== "ArrowLeft" && S !== "ArrowRight" || o.mode !== "sidebar" || !o.resizable || (b.preventDefault(), m = tt(
2732
- w.getBoundingClientRect().width,
2733
- o.side,
2734
- S === "ArrowLeft" ? -nt : nt,
2735
- B().width,
2736
- ae()
2737
- ), H());
2738
- });
2739
- const Pe = () => x.setAttribute(
2740
- "data-scheme",
2741
- document.documentElement.classList.contains("dark") ? "dark" : "light"
2742
- ), Me = new MutationObserver(Pe);
2743
- return Me.observe(document.documentElement, {
2744
- attributes: !0,
2745
- attributeFilter: ["class"]
2746
- }), C.addEventListener("click", () => G(!l)), E.addEventListener("click", () => G(!1)), document.addEventListener("keydown", Q), a == null || a.addEventListener("change", Re), window.addEventListener("resize", Ie), Pe(), H(), document.body.append(x), {
2747
- container: v,
2748
- get isOpen() {
2749
- return l;
2750
- },
2751
- open() {
2752
- R(), G(!0);
2753
- },
2754
- close() {
2755
- R(), G(!1);
2756
- },
2757
- toggle() {
2758
- R(), G(!l);
2759
- },
2760
- update(b) {
2761
- R();
2762
- const S = Object.fromEntries(
2763
- Object.entries(b).filter(([, X]) => X !== void 0)
2764
- ), N = { ...r, ...S }, z = rt(N, s), F = z.width !== o.width;
2765
- (F || z.side !== o.side || z.height !== o.height) && (f = null), F && (m = null), o = z, r = N, H();
2766
- },
2767
- unmount() {
2768
- c || (c = !0, J(), document.removeEventListener("keydown", Q), a == null || a.removeEventListener("change", Re), window.removeEventListener("resize", Ie), Me.disconnect(), x.remove());
2769
- }
2770
- };
2771
- }
2772
- function Ci({
2773
- chatId: e,
2774
- presentation: t,
2775
- open: i,
2776
- onOpenChange: s,
2777
- children: a
2778
- }) {
2779
- const [r, o] = O(null), l = $({ presentation: t, open: i, onOpenChange: s });
2780
- l.current = { presentation: t, open: i, onOpenChange: s }, P(() => {
2781
- const { presentation: g, open: y } = l.current, C = Xn({
2782
- chatId: e,
2783
- presentation: { ...g, defaultOpen: y ?? g.defaultOpen },
2784
- onOpenChange: (w) => {
2785
- var j, L;
2786
- return (L = (j = l.current).onOpenChange) == null ? void 0 : L.call(j, w);
2787
- }
2788
- });
2789
- return o(C), () => {
2790
- C.unmount(), o(null);
2791
- };
2792
- }, [e]);
2793
- const { mode: c, side: p, width: h } = t, u = "placement" in t ? t.placement : void 0, f = "height" in t ? t.height : void 0, m = "contentTarget" in t ? t.contentTarget : void 0, x = "draggable" in t ? t.draggable : void 0, { resizable: v } = t;
2794
- return P(() => {
2795
- r == null || r.update({
2796
- mode: c,
2797
- placement: u,
2798
- side: p,
2799
- width: h,
2800
- height: f,
2801
- contentTarget: m,
2802
- resizable: v,
2803
- draggable: x
2804
- });
2805
- }, [r, c, u, p, h, f, m, v, x]), P(() => {
2806
- !r || i === void 0 || i === r.isOpen || (i ? r.open() : r.close());
2807
- }, [r, i]), r ? ct(a, r.container) : null;
2808
- }
1
+ import { C as s, a as t, b as r, E as h, I as C, d as o, S as n, Z as p, e as i, f as u, g as d, h as y, i as m, j as S } from "./index-Dw5Lv6cs.js";
2809
2
  export {
2810
- _n as ChatMessages,
2811
- Dn as ChatSidebar,
2812
- En as Composer,
2813
- Sn as EmptyChat,
2814
- tn as InterruptCard,
2815
- ht as InterruptsContext,
2816
- Fe as Shell,
2817
- _i as ZeneraChat,
2818
- Ci as ZeneraChatLauncher,
2819
- Si as ZeneraChatWidget,
2820
- ki as composerDraftKey,
2821
- Ni as historyKey,
2822
- Qr as interruptPhase,
2823
- Mn as useSidebarLayout
3
+ s as ChatMessages,
4
+ t as ChatSidebar,
5
+ r as Composer,
6
+ h as EmptyChat,
7
+ C as InterruptCard,
8
+ o as InterruptsContext,
9
+ n as Shell,
10
+ p as ZeneraChat,
11
+ i as ZeneraChatLauncher,
12
+ u as ZeneraChatWidget,
13
+ d as composerDraftKey,
14
+ y as historyKey,
15
+ m as interruptPhase,
16
+ S as useSidebarLayout
2824
17
  };