@singlebase/elements 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/{authui-display-BCZBP7HR.js → authui-display-BM_F3-5e.js} +426 -436
  2. package/dist/authui-display-BM_F3-5e.js.map +1 -0
  3. package/dist/{authui-display-CLGFSqRi.cjs → authui-display-CMVHTNFz.cjs} +45 -65
  4. package/dist/authui-display-CMVHTNFz.cjs.map +1 -0
  5. package/dist/authui.cjs +1 -1
  6. package/dist/authui.js +2 -2
  7. package/dist/{chat-bXaRWel7.js → chat-BH_3e1jT.js} +2081 -1121
  8. package/dist/chat-BH_3e1jT.js.map +1 -0
  9. package/dist/chat-ezUmd9II.cjs +3281 -0
  10. package/dist/chat-ezUmd9II.cjs.map +1 -0
  11. package/dist/chat-messages.d.ts +19 -6
  12. package/dist/chat.cjs +1 -1
  13. package/dist/chat.d.ts +4 -3
  14. package/dist/chat.js +8 -6
  15. package/dist/elements/authui-base.d.ts +2 -0
  16. package/dist/elements/authui-buttons.d.ts +1 -1
  17. package/dist/elements/authui-display.d.ts +1 -1
  18. package/dist/elements/authui.d.ts +1 -1
  19. package/dist/elements/chat.d.ts +192 -11
  20. package/dist/elements/uploader.d.ts +8 -0
  21. package/dist/files-4T62wkwj.cjs +77 -0
  22. package/dist/files-4T62wkwj.cjs.map +1 -0
  23. package/dist/{files-BOwtpYyQ.js → files-DS-H-3yN.js} +93 -47
  24. package/dist/files-DS-H-3yN.js.map +1 -0
  25. package/dist/index.cjs +1 -1
  26. package/dist/index.js +24 -22
  27. package/dist/messages.d.ts +0 -2
  28. package/dist/singlebase-elements.min.js +3838 -2844
  29. package/dist/singlebase-elements.min.js.map +1 -1
  30. package/dist/styles/branding.d.ts +5 -0
  31. package/dist/styles/tokens.d.ts +2 -0
  32. package/dist/upload-messages.d.ts +0 -1
  33. package/dist/{uploader-DGV2y9uT.cjs → uploader-COP8PkJ6.cjs} +53 -76
  34. package/dist/uploader-COP8PkJ6.cjs.map +1 -0
  35. package/dist/{uploader-abQoem5q.js → uploader-tdMU9Gxv.js} +249 -253
  36. package/dist/uploader-tdMU9Gxv.js.map +1 -0
  37. package/dist/uploader.cjs +1 -1
  38. package/dist/uploader.js +2 -2
  39. package/dist/utils/branding.d.ts +8 -0
  40. package/dist/utils/markdown.d.ts +69 -12
  41. package/dist/utils/svg.d.ts +10 -0
  42. package/package.json +3 -3
  43. package/dist/authui-display-BCZBP7HR.js.map +0 -1
  44. package/dist/authui-display-CLGFSqRi.cjs.map +0 -1
  45. package/dist/chat-DRenTJlI.cjs +0 -3001
  46. package/dist/chat-DRenTJlI.cjs.map +0 -1
  47. package/dist/chat-bXaRWel7.js.map +0 -1
  48. package/dist/files-BOwtpYyQ.js.map +0 -1
  49. package/dist/files-DW8A4Jl-.cjs +0 -38
  50. package/dist/files-DW8A4Jl-.cjs.map +0 -1
  51. package/dist/uploader-DGV2y9uT.cjs.map +0 -1
  52. package/dist/uploader-abQoem5q.js.map +0 -1
@@ -1,15 +1,15 @@
1
- var gt = Object.defineProperty;
2
- var qe = (n) => {
1
+ var Ut = Object.defineProperty;
2
+ var wt = (n) => {
3
3
  throw TypeError(n);
4
4
  };
5
- var mt = (n, e, t) => e in n ? gt(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
6
- var T = (n, e, t) => mt(n, typeof e != "symbol" ? e + "" : e, t), Ge = (n, e, t) => e.has(n) || qe("Cannot " + t);
7
- var p = (n, e, t) => (Ge(n, e, "read from private field"), t ? t.call(n) : e.get(n)), h = (n, e, t) => e.has(n) ? qe("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), u = (n, e, t, i) => (Ge(n, e, "write to private field"), i ? i.call(n, t) : e.set(n, t), t);
8
- import { css as bt, LitElement as ft, html as r, nothing as m, svg as $ } from "lit";
9
- import { property as w, state as v, customElement as xt } from "lit/decorators.js";
10
- import { repeat as vt } from "lit/directives/repeat.js";
11
- import { getDefaultClient as yt } from "@singlebase/core";
12
- import { f as z, a as Ve, t as kt } from "./files-BOwtpYyQ.js";
5
+ var Wt = (n, e, t) => e in n ? Ut(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
6
+ var M = (n, e, t) => Wt(n, typeof e != "symbol" ? e + "" : e, t), yt = (n, e, t) => e.has(n) || wt("Cannot " + t);
7
+ var p = (n, e, t) => (yt(n, e, "read from private field"), t ? t.call(n) : e.get(n)), h = (n, e, t) => e.has(n) ? wt("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), u = (n, e, t, s) => (yt(n, e, "write to private field"), s ? s.call(n, t) : e.set(n, t), t);
8
+ import { css as Ht, LitElement as Jt, html as o, nothing as m, svg as O } from "lit";
9
+ import { property as v, state as y, customElement as Gt } from "lit/decorators.js";
10
+ import { repeat as qt } from "lit/directives/repeat.js";
11
+ import { getDefaultClient as Vt } from "@singlebase/core";
12
+ import { a as _, e as kt, j as Xt, t as Yt, b as Qt } from "./files-DS-H-3yN.js";
13
13
  if (typeof CSS < "u" && "registerProperty" in CSS)
14
14
  try {
15
15
  CSS.registerProperty({
@@ -20,7 +20,7 @@ if (typeof CSS < "u" && "registerProperty" in CSS)
20
20
  });
21
21
  } catch {
22
22
  }
23
- const wt = bt`
23
+ const Zt = Ht`
24
24
  :host {
25
25
  --c-ink: var(--sb-ink, #16181a);
26
26
  --c-ink2: var(--sb-ink-2, #41464b);
@@ -37,7 +37,7 @@ const wt = bt`
37
37
  --c-danger: var(--sb-danger, #b4231a);
38
38
  --c-ok: var(--sb-ok, #0f6b4a);
39
39
  --c-mono: var(--sb-mono, "Geist Mono", ui-monospace, monospace);
40
- --c-r: var(--sb-radius, 4px);
40
+ --c-r: calc(var(--sb-radius, 4px) * var(--sb-radius-scale, 1));
41
41
  --c-r2: calc(var(--c-r) * 1.5);
42
42
  --c-r3: calc(var(--c-r) * 2);
43
43
  --c-r4: calc(var(--c-r) * 3);
@@ -482,6 +482,17 @@ const wt = bt`
482
482
  outline: none;
483
483
  }
484
484
 
485
+ .side-extra {
486
+ display: none;
487
+ }
488
+
489
+ .side-extra.filled {
490
+ display: block;
491
+ padding: 12px 16px;
492
+ border-top: 1px solid var(--c-line);
493
+ font-size: 12.5px;
494
+ }
495
+
485
496
  .side-note {
486
497
  font-size: 12.5px;
487
498
  color: var(--c-muted);
@@ -654,6 +665,21 @@ const wt = bt`
654
665
 
655
666
  /* ── welcome ──────────────────────────────────────────── */
656
667
 
668
+ .welcome-slot {
669
+ min-height: 100%;
670
+ display: flex;
671
+ flex-direction: column;
672
+ justify-content: center;
673
+ }
674
+
675
+ ::slotted([slot="welcome"]) {
676
+ box-sizing: border-box;
677
+ width: 100%;
678
+ max-width: 640px;
679
+ margin: 0 auto;
680
+ padding: 28px 18px;
681
+ }
682
+
657
683
  .welcome {
658
684
  max-width: 640px;
659
685
  min-height: 100%;
@@ -1050,6 +1076,168 @@ const wt = bt`
1050
1076
  padding: 1px 5px;
1051
1077
  }
1052
1078
 
1079
+ .answer h3.h1 {
1080
+ font-size: 18px;
1081
+ }
1082
+
1083
+ .answer h3.h2 {
1084
+ font-size: 16.5px;
1085
+ }
1086
+
1087
+ .answer h3.h4 {
1088
+ font-size: 14.5px;
1089
+ }
1090
+
1091
+ .answer hr {
1092
+ width: 100%;
1093
+ border: none;
1094
+ border-top: 1px solid var(--c-line);
1095
+ margin: 4px 0;
1096
+ }
1097
+
1098
+ .answer li.task {
1099
+ list-style: none;
1100
+ margin-left: -18px;
1101
+ }
1102
+
1103
+ .answer li.task input {
1104
+ margin: 0 6px 0 0;
1105
+ vertical-align: -1px;
1106
+ accent-color: var(--c-brand);
1107
+ }
1108
+
1109
+ .callout {
1110
+ display: flex;
1111
+ flex-direction: column;
1112
+ gap: 4px;
1113
+ font-size: 13.5px;
1114
+ line-height: 1.6;
1115
+ padding: 10px 14px;
1116
+ border: 1px solid var(--c-line);
1117
+ border-left: 3px solid var(--callout, var(--c-ink));
1118
+ border-radius: var(--c-r2);
1119
+ background: color-mix(in srgb, var(--callout, var(--c-ink)) 7%, var(--c-bg));
1120
+ }
1121
+
1122
+ .callout-title {
1123
+ font-weight: 600;
1124
+ color: var(--callout, var(--c-ink));
1125
+ }
1126
+
1127
+ .callout.note {
1128
+ --callout: oklch(0.55 0.15 255);
1129
+ }
1130
+
1131
+ .callout.tip {
1132
+ --callout: oklch(0.55 0.12 160);
1133
+ }
1134
+
1135
+ .callout.important {
1136
+ --callout: oklch(0.52 0.17 300);
1137
+ }
1138
+
1139
+ .callout.warning {
1140
+ --callout: oklch(0.6 0.14 70);
1141
+ }
1142
+
1143
+ .callout.caution {
1144
+ --callout: var(--c-danger);
1145
+ }
1146
+
1147
+ .jtree {
1148
+ padding: 10px 14px;
1149
+ overflow-x: auto;
1150
+ font-family: var(--c-mono);
1151
+ font-size: 12.5px;
1152
+ line-height: 1.7;
1153
+ }
1154
+
1155
+ .jtree summary {
1156
+ cursor: pointer;
1157
+ list-style-position: outside;
1158
+ }
1159
+
1160
+ .jkids {
1161
+ padding-left: 16px;
1162
+ border-left: 1px solid var(--c-line);
1163
+ margin-left: 4px;
1164
+ }
1165
+
1166
+ .jkey {
1167
+ color: var(--c-ink2);
1168
+ }
1169
+
1170
+ .jmeta {
1171
+ color: var(--c-muted);
1172
+ }
1173
+
1174
+ .jv.string {
1175
+ color: oklch(0.52 0.12 160);
1176
+ }
1177
+
1178
+ .jv.number {
1179
+ color: oklch(0.55 0.15 255);
1180
+ }
1181
+
1182
+ .jv.boolean,
1183
+ .jv.null {
1184
+ color: oklch(0.52 0.17 300);
1185
+ }
1186
+
1187
+ .table th button.sort {
1188
+ display: inline-flex;
1189
+ align-items: center;
1190
+ gap: 4px;
1191
+ font: inherit;
1192
+ color: inherit;
1193
+ background: none;
1194
+ border: none;
1195
+ padding: 0;
1196
+ cursor: pointer;
1197
+ }
1198
+
1199
+ .table th .arrow {
1200
+ font-size: 10px;
1201
+ opacity: 0.5;
1202
+ }
1203
+
1204
+ .table th[aria-sort="ascending"] .arrow,
1205
+ .table th[aria-sort="descending"] .arrow {
1206
+ opacity: 1;
1207
+ }
1208
+
1209
+ .table-note {
1210
+ padding: 7px 12px;
1211
+ font-size: 12px;
1212
+ color: var(--c-muted);
1213
+ border-top: 1px solid var(--c-line2);
1214
+ background: var(--c-bg2);
1215
+ }
1216
+
1217
+ figure.svg {
1218
+ margin: 0;
1219
+ display: flex;
1220
+ flex-direction: column;
1221
+ gap: 6px;
1222
+ align-items: flex-start;
1223
+ }
1224
+
1225
+ figure.svg img {
1226
+ display: block;
1227
+ width: min(100%, 480px);
1228
+ height: auto;
1229
+ max-height: 420px;
1230
+ object-fit: contain;
1231
+ padding: 12px;
1232
+ border: 1px solid var(--c-line);
1233
+ border-radius: var(--c-r2);
1234
+ background: #ffffff;
1235
+ }
1236
+
1237
+ .custom-block {
1238
+ min-width: 0;
1239
+ }
1240
+
1053
1241
  .quote {
1054
1242
  font-size: 13.5px;
1055
1243
  line-height: 1.6;
@@ -1707,6 +1895,10 @@ const wt = bt`
1707
1895
  padding: 0 12px 12px;
1708
1896
  }
1709
1897
 
1898
+ .composer-wrap.reader {
1899
+ padding-top: 10px;
1900
+ }
1901
+
1710
1902
  .composer-col {
1711
1903
  max-width: 760px;
1712
1904
  margin: 0 auto;
@@ -1864,6 +2056,11 @@ const wt = bt`
1864
2056
  min-width: 0;
1865
2057
  }
1866
2058
 
2059
+ .pending-file.kept {
2060
+ background: var(--c-bg);
2061
+ border-style: dashed;
2062
+ }
2063
+
1867
2064
  .pending-file .name {
1868
2065
  max-width: 160px;
1869
2066
  overflow: hidden;
@@ -1891,8 +2088,7 @@ const wt = bt`
1891
2088
  color: var(--c-danger);
1892
2089
  }
1893
2090
 
1894
- .footnote,
1895
- .branding {
2091
+ .footnote {
1896
2092
  text-align: center;
1897
2093
  font-size: 11.5px;
1898
2094
  color: var(--c-muted);
@@ -1903,19 +2099,6 @@ const wt = bt`
1903
2099
  margin-top: -4px;
1904
2100
  }
1905
2101
 
1906
- .branding a {
1907
- font-family: var(--c-mono);
1908
- font-size: 10.5px;
1909
- letter-spacing: 0.06em;
1910
- text-transform: uppercase;
1911
- color: var(--c-muted);
1912
- text-decoration: none;
1913
- }
1914
-
1915
- .branding a:hover {
1916
- color: var(--c-ink);
1917
- }
1918
-
1919
2102
  .toast {
1920
2103
  position: absolute;
1921
2104
  left: 50%;
@@ -2273,29 +2456,31 @@ const wt = bt`
2273
2456
  height: auto;
2274
2457
  }
2275
2458
  }
2276
- `, $t = {
2459
+ `, es = {
2277
2460
  eyebrowChat: "Chat",
2278
2461
  eyebrowRag: "Grounded answers",
2279
- eyebrowRich: "Charts · tables · images",
2280
2462
  headingChat: "What can I help with?",
2281
2463
  headingRag: "Ask your knowledge base",
2282
- headingRich: "Ask for a chart or a table",
2283
2464
  descriptionChat: "Ask anything. Attach text files to give it more context.",
2284
2465
  descriptionRag: "Answers are grounded in your sources, with a citation for every claim. Attach text files to search them too.",
2285
- descriptionRich: "Answers come back with charts, tables and images when they help. Attach CSV or JSON files to use your own data.",
2466
+ eyebrowKb: "Knowledge base",
2467
+ headingKb: "Ask the knowledge base",
2468
+ descriptionKb: "Answers come only from the knowledge base, with a citation for every claim.",
2286
2469
  placeholderChat: "Message {name}…",
2287
2470
  placeholderRag: "Ask about your sources…",
2288
- placeholderRich: "Ask for a chart, table or breakdown…",
2471
+ placeholderKb: "Ask the knowledge base…",
2289
2472
  footnote: "{name} can make mistakes. Check important details.",
2290
2473
  attach: "Attach files",
2291
2474
  send: "Send message",
2292
2475
  stop: "Stop generating",
2293
2476
  removeFile: "Remove file",
2477
+ inThisChat: "In this chat",
2478
+ removeFromChat: "Remove from this chat",
2479
+ attachmentFailed: "Couldn't read {name}.",
2294
2480
  dropTitle: "Drop files to attach",
2295
2481
  dropSub: "Text, Markdown, CSV and JSON files are added as context.",
2296
2482
  thinking: "Thinking",
2297
2483
  searching: "Searching sources",
2298
- building: "Building charts and tables",
2299
2484
  chats: "Chats",
2300
2485
  newChat: "New chat",
2301
2486
  searchChats: "Search chats",
@@ -2350,6 +2535,17 @@ const wt = bt`
2350
2535
  copyReference: "Copy passage with reference",
2351
2536
  alsoCited: "Also cited",
2352
2537
  close: "Close",
2538
+ renderingChart: "Rendering chart",
2539
+ renderingSvg: "Rendering drawing",
2540
+ copySvg: "Copy SVG",
2541
+ showRaw: "View raw",
2542
+ showFormatted: "View formatted",
2543
+ showingRows: "Showing {n} of {total} rows",
2544
+ calloutNote: "Note",
2545
+ calloutTip: "Tip",
2546
+ calloutImportant: "Important",
2547
+ calloutWarning: "Warning",
2548
+ calloutCaution: "Caution",
2353
2549
  undo: "Undo",
2354
2550
  chatDeleted: "Chat deleted",
2355
2551
  messageDeleted: "Message deleted",
@@ -2364,6 +2560,7 @@ const wt = bt`
2364
2560
  tooManyFiles: "Attach up to {n} files at a time.",
2365
2561
  errGeneric: "Something went wrong.",
2366
2562
  errNotFound: "This chat no longer exists. Retry to start a new one.",
2563
+ errKbSource: "No knowledge base is set up for this chat.",
2367
2564
  errNoClient: "Chat isn't connected. Create a SinglebaseClient() on this page.",
2368
2565
  errLoad: "Couldn't load this chat.",
2369
2566
  retry: "Retry",
@@ -2371,73 +2568,130 @@ const wt = bt`
2371
2568
  bubbleText: "Hi! Questions? Ask me here.",
2372
2569
  openChat: "Open chat",
2373
2570
  closeChat: "Close chat",
2374
- dismiss: "Dismiss",
2375
- brandingLabel: "Chat by Singlebase"
2571
+ dismiss: "Dismiss"
2376
2572
  };
2377
- function Tt(n) {
2378
- return { ...$t, ...n ?? {} };
2573
+ function ts(n) {
2574
+ return { ...es, ...n ?? {} };
2379
2575
  }
2380
- const Ct = /^\|.*\|$/, St = /^\|[\s:|-]+\|$/, Xe = /^!\[([^\]]*)\]\(([^)]*)\)$/, Ye = /^([-*]|\d+\.)\s+/;
2381
- function zt(n) {
2576
+ const ss = /^\|.*\|$/, $t = /^\|[\s:|-]+\|$/, Ct = /^!\[([^\]]*)\]\(([^)]*)\)$/, Tt = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/, St = /^\[( |x|X)\]\s+/, is = /^(-{3,}|\*{3,}|_{3,})$/, as = /^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i, rs = ["note", "tip", "important", "warning", "caution"];
2577
+ function os(n) {
2382
2578
  const e = [], t = (n ?? "").replace(/\r/g, "").split("```");
2383
- return t.forEach((i, s) => {
2384
- if (s % 2 === 1) {
2385
- const a = i.indexOf(`
2386
- `), o = (a > -1 ? i.slice(0, a) : i).trim().toLowerCase(), l = (a > -1 ? i.slice(a + 1) : "").replace(/\n$/, ""), c = s === t.length - 1;
2387
- if (o === "chart") {
2388
- const x = c ? null : Ot(l);
2389
- e.push(x ? { type: "chart", spec: x } : { type: "chartPending" });
2390
- } else
2391
- e.push({ type: "code", lang: o || "code", text: l });
2579
+ return t.forEach((s, i) => {
2580
+ if (i % 2 === 1) {
2581
+ const a = s.indexOf(`
2582
+ `), r = (a > -1 ? s.slice(0, a) : s).trim(), c = (a > -1 ? s.slice(a + 1) : "").replace(/\n$/, "");
2583
+ e.push(ns(r, c, i === t.length - 1));
2392
2584
  return;
2393
2585
  }
2394
- for (const a of i.split(/\n{2,}/)) {
2395
- const o = a.trim();
2396
- o && e.push(...pt(o));
2397
- }
2586
+ for (const a of s.split(/\n{2,}/))
2587
+ a.trim() && e.push(...Kt(a));
2398
2588
  }), e;
2399
2589
  }
2400
- function pt(n) {
2590
+ function ns(n, e, t) {
2591
+ const [s = "", ...i] = n.split(/\s+/), a = s.toLowerCase();
2592
+ if (a === "chart") {
2593
+ const r = t ? null : cs(e);
2594
+ return r ? { type: "chart", spec: r } : { type: "pending", kind: "chart" };
2595
+ }
2596
+ if (a === "svg")
2597
+ return t || !/<svg[\s>]/i.test(e) ? { type: "pending", kind: "svg" } : { type: "svg", source: e.trim() };
2598
+ if (!t && (a === "csv" || a === "tsv")) {
2599
+ const r = ls(e, a === "tsv" ? " " : ",");
2600
+ if (r.length > 1)
2601
+ return { type: "table", head: r[0], rows: r.slice(1), align: r[0].map(() => null) };
2602
+ }
2603
+ if (!t && a === "json")
2604
+ try {
2605
+ return { type: "json", value: JSON.parse(e), source: e };
2606
+ } catch {
2607
+ }
2608
+ if (a === "callout") {
2609
+ const r = (i[0] ?? "").toLowerCase(), c = rs.includes(r);
2610
+ return {
2611
+ type: "callout",
2612
+ kind: c ? r : "note",
2613
+ title: (c ? i.slice(1) : i).join(" "),
2614
+ text: e.trim()
2615
+ };
2616
+ }
2617
+ return { type: "code", lang: a || "code", text: e };
2618
+ }
2619
+ function Kt(n) {
2401
2620
  const e = n.split(`
2402
- `).map((i) => i.trim()).filter(Boolean);
2403
- if (e.length > 1 && e.every((i) => Ct.test(i))) {
2404
- const i = e.filter((s) => !St.test(s)).map(
2405
- (s) => s.replace(/^\||\|$/g, "").split("|").map((a) => a.trim())
2406
- );
2407
- return [{ type: "table", head: i[0] ?? [], rows: i.slice(1) }];
2621
+ `).filter((i) => i.trim()), t = e.map((i) => i.trim());
2622
+ if (t.length > 1 && t.every((i) => ss.test(i))) {
2623
+ const i = (f) => f.replace(/^\||\|$/g, "").split("|").map((b) => b.trim()), a = t.findIndex((f) => $t.test(f)), r = a > -1 ? i(t[a]).map(
2624
+ (f) => /^:-+:$/.test(f) ? "center" : /^-+:$/.test(f) ? "right" : /^:-+$/.test(f) ? "left" : null
2625
+ ) : [], c = t.filter((f) => !$t.test(f)).map(i), l = c[0] ?? [];
2626
+ return [
2627
+ { type: "table", head: l, rows: c.slice(1), align: l.map((f, b) => r[b] ?? null) }
2628
+ ];
2408
2629
  }
2409
- if (e.every((i) => Xe.test(i)))
2630
+ if (t.length === 1 && is.test(t[0])) return [{ type: "hr" }];
2631
+ if (t.every((i) => Ct.test(i)))
2410
2632
  return [
2411
2633
  {
2412
2634
  type: "img",
2413
- images: e.map((i) => {
2414
- const s = i.match(Xe);
2415
- return { alt: s[1], src: s[2] };
2635
+ images: t.map((i) => {
2636
+ const a = i.match(Ct);
2637
+ return { alt: a[1], src: a[2] };
2416
2638
  })
2417
2639
  }
2418
2640
  ];
2419
- if (e.every((i) => i.startsWith(">")))
2420
- return [{ type: "quote", text: e.map((i) => i.replace(/^>\s?/, "")).join(" ") }];
2421
- if (e.every((i) => Ye.test(i)))
2422
- return [
2641
+ if (t.every((i) => i.startsWith(">"))) {
2642
+ const i = t.map((r) => r.replace(/^>\s?/, "")), a = i[0].match(as);
2643
+ return a ? [
2423
2644
  {
2424
- type: "list",
2425
- ordered: /^\d+\./.test(e[0]),
2426
- items: e.map((i) => i.replace(Ye, ""))
2645
+ type: "callout",
2646
+ kind: a[1].toLowerCase(),
2647
+ title: a[2].trim(),
2648
+ text: i.slice(1).join(`
2649
+ `).trim()
2427
2650
  }
2428
- ];
2429
- const t = e[0].match(/^(#{1,4})\s+(.*)$/);
2430
- if (t) {
2651
+ ] : [{ type: "quote", text: i.join(" ") }];
2652
+ }
2653
+ if (Tt.test(e[0])) {
2654
+ const i = [];
2655
+ for (const a of e) {
2656
+ const r = a.match(Tt);
2657
+ if (r) {
2658
+ const c = r[3].match(St);
2659
+ i.push({
2660
+ text: c ? r[3].replace(St, "") : r[3],
2661
+ depth: Math.min(3, Math.floor(r[1].replace(/\t/g, " ").length / 2)),
2662
+ checked: c ? c[1] !== " " : null
2663
+ });
2664
+ } else
2665
+ i[i.length - 1].text += ` ${a.trim()}`;
2666
+ }
2667
+ return [{ type: "list", ordered: /^\s*\d/.test(e[0]), items: i }];
2668
+ }
2669
+ const s = t[0].match(/^(#{1,4})\s+(.*)$/);
2670
+ if (s) {
2431
2671
  const i = e.slice(1).join(`
2432
2672
  `);
2433
2673
  return [
2434
- { type: "h", level: t[1].length, text: t[2] },
2435
- ...i ? pt(i) : []
2674
+ { type: "h", level: s[1].length, text: s[2] },
2675
+ ...i ? Kt(i) : []
2436
2676
  ];
2437
2677
  }
2438
- return [{ type: "p", text: e.join(" ") }];
2678
+ return [{ type: "p", text: t.join(" ") }];
2439
2679
  }
2440
- function Ot(n) {
2680
+ function ls(n, e = ",") {
2681
+ var l;
2682
+ const t = [];
2683
+ let s = [], i = "", a = !1;
2684
+ const r = n.replace(/\r/g, "");
2685
+ for (let f = 0; f < r.length; f++) {
2686
+ const b = r[f];
2687
+ a ? b === '"' && r[f + 1] === '"' ? (i += '"', f++) : b === '"' ? a = !1 : i += b : b === '"' && i === "" ? a = !0 : b === e ? (s.push(i.trim()), i = "") : b === `
2688
+ ` ? (s.push(i.trim()), s.some(Boolean) && t.push(s), s = [], i = "") : i += b;
2689
+ }
2690
+ s.push(i.trim()), s.some(Boolean) && t.push(s);
2691
+ const c = ((l = t[0]) == null ? void 0 : l.length) ?? 0;
2692
+ return t.map((f) => f.length < c ? [...f, ...Array(c - f.length).fill("")] : f);
2693
+ }
2694
+ function cs(n) {
2441
2695
  let e;
2442
2696
  try {
2443
2697
  e = JSON.parse(n);
@@ -2445,136 +2699,226 @@ function Ot(n) {
2445
2699
  return null;
2446
2700
  }
2447
2701
  if (!e || typeof e != "object") return null;
2448
- const t = (Array.isArray(e.series) ? e.series : []).filter((s) => s && Array.isArray(s.values)).map((s, a) => ({
2449
- name: String(s.name ?? `Series ${a + 1}`),
2450
- values: s.values.map((o) => Number(o) || 0)
2702
+ const t = (Array.isArray(e.series) ? e.series : []).filter((i) => i && Array.isArray(i.values)).map((i, a) => ({
2703
+ name: String(i.name ?? `Series ${a + 1}`),
2704
+ values: i.values.map((r) => Number(r) || 0)
2451
2705
  }));
2452
2706
  if (!t.length) return null;
2453
- const i = Array.isArray(e.labels) ? e.labels.map(String) : t[0].values.map((s, a) => String(a + 1));
2707
+ const s = Array.isArray(e.labels) ? e.labels.map(String) : t[0].values.map((i, a) => String(a + 1));
2454
2708
  return {
2455
2709
  type: e.type === "line" ? "line" : "bar",
2456
2710
  title: String(e.title ?? ""),
2457
2711
  unit: String(e.unit ?? ""),
2458
- labels: i,
2712
+ labels: s,
2459
2713
  series: t
2460
2714
  };
2461
2715
  }
2462
- const Qe = /\*\*([^*]+)\*\*|`([^`]+)`|\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)|\s?\[(\d+(?:\s*,\s*\d+)*)\]/g;
2463
- function Mt(n, e = 0) {
2716
+ const It = new RegExp(
2717
+ [
2718
+ /\*\*([^*]+)\*\*/.source,
2719
+ // 1 bold
2720
+ /~~([^~]+)~~/.source,
2721
+ // 2 strike
2722
+ /`([^`]+)`/.source,
2723
+ // 3 code
2724
+ /\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/.source,
2725
+ // 4, 5 link
2726
+ /(https?:\/\/[^\s<>()]*[^\s<>().,;:!?'"\]])/.source,
2727
+ // 6 bare link
2728
+ new RegExp("(?<![\\w*])\\*(?![\\s*])([^*\\n]+?)\\*(?![\\w*])").source,
2729
+ // 7 *italic*
2730
+ new RegExp("(?<![\\w_])_(?![\\s_])([^_\\n]+?)_(?![\\w_])").source,
2731
+ // 8 _italic_
2732
+ /\s?\[(\d+(?:\s*,\s*\d+)*)\]/.source
2733
+ // 9 citation
2734
+ ].join("|"),
2735
+ "g"
2736
+ );
2737
+ function ds(n, e = 0) {
2464
2738
  const t = [];
2465
- let i = 0, s;
2466
- Qe.lastIndex = 0;
2467
- const a = (o) => {
2468
- if (!o) return;
2469
- const l = t[t.length - 1];
2470
- (l == null ? void 0 : l.type) === "text" ? l.text += o : t.push({ type: "text", text: o });
2739
+ let s = 0, i;
2740
+ It.lastIndex = 0;
2741
+ const a = (r) => {
2742
+ if (!r) return;
2743
+ const c = t[t.length - 1];
2744
+ (c == null ? void 0 : c.type) === "text" ? c.text += r : t.push({ type: "text", text: r });
2471
2745
  };
2472
- for (; s = Qe.exec(n); ) {
2473
- if (a(n.slice(i, s.index)), s[1] !== void 0) t.push({ type: "bold", text: s[1] });
2474
- else if (s[2] !== void 0) t.push({ type: "code", text: s[2] });
2475
- else if (s[3] !== void 0) t.push({ type: "link", text: s[3], href: s[4] });
2746
+ for (; i = It.exec(n); ) {
2747
+ if (a(n.slice(s, i.index)), i[1] !== void 0) t.push({ type: "bold", text: i[1] });
2748
+ else if (i[2] !== void 0) t.push({ type: "strike", text: i[2] });
2749
+ else if (i[3] !== void 0) t.push({ type: "code", text: i[3] });
2750
+ else if (i[4] !== void 0) t.push({ type: "link", text: i[4], href: i[5] });
2751
+ else if (i[6] !== void 0) t.push({ type: "link", text: i[6], href: i[6] });
2752
+ else if (i[7] !== void 0) t.push({ type: "italic", text: i[7] });
2753
+ else if (i[8] !== void 0) t.push({ type: "italic", text: i[8] });
2476
2754
  else {
2477
- const l = s[5].split(",").map((c) => Number(c.trim())).filter((c) => c >= 1 && c <= e);
2478
- e ? l.forEach((c) => t.push({ type: "cite", n: c })) : a(s[0]);
2755
+ const c = i[9].split(",").map((l) => Number(l.trim())).filter((l) => l >= 1 && l <= e);
2756
+ e ? c.forEach((l) => t.push({ type: "cite", n: l })) : a(i[0]);
2479
2757
  }
2480
- i = s.index + s[0].length;
2758
+ s = i.index + i[0].length;
2481
2759
  }
2482
- return a(n.slice(i)), t;
2760
+ return a(n.slice(s)), t;
2761
+ }
2762
+ function ps(n) {
2763
+ if (((n ?? "").match(/```/g) ?? []).length % 2 === 1) return n;
2764
+ const e = n.lastIndexOf(`
2765
+
2766
+ `), t = e > -1 ? n.slice(0, e + 2) : "";
2767
+ let s = e > -1 ? n.slice(e + 2) : n;
2768
+ const i = s.split(`
2769
+ `), a = i[i.length - 1];
2770
+ a.trimStart().startsWith("|") && !a.trimEnd().endsWith("|") && i.pop(), s = i.join(`
2771
+ `), s = s.replace(/!?\[[^\]\n]*(\]\([^)\n]*)?$/, "");
2772
+ for (const r of ["**", "~~", "`"])
2773
+ if ((s.split(r).length - 1) % 2 === 1) {
2774
+ const l = s.lastIndexOf(r);
2775
+ s = s.slice(0, l) + s.slice(l + r.length);
2776
+ }
2777
+ return t + s;
2483
2778
  }
2484
- function Ze(n) {
2779
+ function Ot(n) {
2485
2780
  const e = /* @__PURE__ */ new Set();
2486
2781
  for (const t of (n ?? "").match(/\[(\d+(?:\s*,\s*\d+)*)\]/g) ?? [])
2487
- t.replace(/[[\]]/g, "").split(",").forEach((i) => e.add(Number(i.trim())));
2782
+ t.replace(/[[\]]/g, "").split(",").forEach((s) => e.add(Number(s.trim())));
2488
2783
  return e;
2489
2784
  }
2490
- function et(n) {
2491
- return {
2492
- head: ["", ...n.series.map((e) => e.name)],
2493
- rows: n.labels.map((e, t) => [
2785
+ function hs(n) {
2786
+ return [
2787
+ ["", ...n.series.map((e) => e.name)],
2788
+ ...n.labels.map((e, t) => [
2494
2789
  e,
2495
- ...n.series.map((i) => i.values[t] === void 0 ? "" : `${i.values[t]}${n.unit}`)
2790
+ ...n.series.map((s) => s.values[t] === void 0 ? "" : `${s.values[t]}${n.unit}`)
2496
2791
  ])
2497
- };
2792
+ ];
2498
2793
  }
2499
- const He = (n) => n.replace(/\*\*/g, "").replace(/`/g, "").replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, "$1");
2500
- function _t(n, e) {
2501
- if (e === "markdown")
2502
- return n.flatMap((t) => {
2503
- if (t.type === "chart") {
2504
- const i = et(t.spec);
2505
- return [
2506
- ...t.spec.title ? [{ type: "p", text: `**${t.spec.title}**` }] : [],
2507
- { type: "table", ...i }
2508
- ];
2509
- }
2510
- return t.type === "img" ? t.images.map((i) => ({
2511
- type: "p",
2512
- text: `Image: ${i.alt || "untitled"}`
2513
- })) : [t];
2514
- });
2515
- if (e === "text") {
2516
- const t = n.map((i) => {
2517
- switch (i.type) {
2518
- case "chart": {
2519
- const s = et(i.spec);
2520
- return [i.spec.title, ...[s.head, ...s.rows].map((a) => a.join(" · "))].filter(Boolean).join(`
2521
- `);
2522
- }
2523
- case "chartPending":
2524
- return "";
2525
- case "img":
2526
- return i.images.map((s) => `Image: ${s.alt || "untitled"}`).join(`
2527
- `);
2528
- case "table":
2529
- return [i.head, ...i.rows].map((s) => s.map(He).join(" · ")).join(`
2530
- `);
2531
- case "list":
2532
- return i.items.map((s) => `- ${He(s)}`).join(`
2533
- `);
2534
- case "code":
2535
- case "raw":
2536
- return i.text;
2537
- default:
2538
- return He(i.text);
2794
+ const Mt = (n) => n.map((e) => e.join(" · ")).join(`
2795
+ `), us = {
2796
+ note: "Note",
2797
+ tip: "Tip",
2798
+ important: "Important",
2799
+ warning: "Warning",
2800
+ caution: "Caution"
2801
+ };
2802
+ function gs(n, e) {
2803
+ if (e === "rich") return n;
2804
+ const t = e === "plain";
2805
+ return n.map((s) => {
2806
+ switch (s.type) {
2807
+ case "chart": {
2808
+ const [i, ...a] = hs(s.spec);
2809
+ return t ? {
2810
+ type: "raw",
2811
+ text: [s.spec.title, Mt([i, ...a])].filter(Boolean).join(`
2812
+ `)
2813
+ } : {
2814
+ type: "table",
2815
+ head: s.spec.title ? [s.spec.title, ...i.slice(1)] : i,
2816
+ rows: a,
2817
+ align: i.map(() => null)
2818
+ };
2539
2819
  }
2540
- }).filter(Boolean).join(`
2541
-
2542
- `);
2543
- return t ? [{ type: "raw", text: t }] : [];
2544
- }
2545
- return n;
2820
+ case "pending":
2821
+ return s.kind === "svg" && !t ? s : { type: "raw", text: "" };
2822
+ case "callout":
2823
+ return {
2824
+ type: "quote",
2825
+ text: `**${s.title || us[s.kind]}** ${s.text}`.trim()
2826
+ };
2827
+ case "img":
2828
+ return {
2829
+ type: "p",
2830
+ text: s.images.map((i) => `Image: ${i.alt || "untitled"}`).join(" · ")
2831
+ };
2832
+ case "table":
2833
+ return t ? { type: "raw", text: Mt([s.head, ...s.rows]) } : s;
2834
+ case "json":
2835
+ return t ? { type: "code", lang: "json", text: s.source } : s;
2836
+ case "svg":
2837
+ return t ? { type: "code", lang: "svg", text: s.source } : s;
2838
+ default:
2839
+ return s;
2840
+ }
2841
+ });
2546
2842
  }
2547
- function tt(n) {
2843
+ function zt(n) {
2548
2844
  const e = n ?? "", t = e.search(/FOLLOWUPS:/i);
2549
2845
  if (t < 0) return { text: e.trim(), followups: [] };
2550
- const s = e.slice(t).replace(/^FOLLOWUPS:/i, "").split(/\||\n/).map((a) => a.replace(/^\s*(?:[-*↳→]|\d+[.)])\s*/, "").trim()).filter(Boolean).slice(0, 3);
2551
- return { text: e.slice(0, t).trim(), followups: s };
2846
+ const i = e.slice(t).replace(/^FOLLOWUPS:/i, "").split(/\||\n/).map((a) => a.replace(/^\s*(?:[-*↳→]|\d+[.)])\s*/, "").trim()).filter(Boolean).slice(0, 3);
2847
+ return { text: e.slice(0, t).trim(), followups: i };
2552
2848
  }
2553
- function It(n) {
2554
- return (n ?? "").replace(/```(\w*)[\s\S]*?(```|$)/g, (e, t) => t === "chart" ? "[Chart] " : "[Code] ").replace(/!\[([^\]]*)\]\([^)]*\)/g, "[Image: $1]").replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, "$1").replace(/[*#>`]/g, "").replace(/\|/g, " ").replace(/\s?\[\d+(?:\s*,\s*\d+)*\]/g, "").replace(/\s+/g, " ").trim();
2849
+ function ms(n) {
2850
+ return (n ?? "").replace(
2851
+ /```(\w*)[\s\S]*?(```|$)/g,
2852
+ (e, t) => t === "chart" ? "[Chart] " : t === "svg" ? "[Drawing] " : "[Code] "
2853
+ ).replace(/!\[([^\]]*)\]\([^)]*\)/g, "[Image: $1]").replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, "$1").replace(/\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]/gi, "").replace(/[*#>`~]/g, "").replace(/\|/g, " ").replace(/\s?\[\d+(?:\s*,\s*\d+)*\]/g, "").replace(/\s+/g, " ").trim();
2555
2854
  }
2556
- function Lt(n, e = 48) {
2557
- const t = It(n);
2855
+ function fs(n, e = 48) {
2856
+ const t = ms(n);
2558
2857
  if (t.length <= e) return t;
2559
- const i = t.slice(0, e), s = i.lastIndexOf(" ");
2560
- return (s > e / 2 ? i.slice(0, s) : i).trim();
2858
+ const s = t.slice(0, e), i = s.lastIndexOf(" ");
2859
+ return (i > e / 2 ? s.slice(0, i) : s).trim();
2561
2860
  }
2562
- function jt(n) {
2861
+ function bs(n) {
2563
2862
  return String(n ?? "").split(`
2564
2863
  `)[0].trim().replace(/^["'“”‘’]+|["'“”‘’]+$/g, "").replace(/^title:\s*/i, "").replace(/[.!?:;,]+$/, "").trim().slice(0, 80);
2565
2864
  }
2566
- function it(n, e = !1) {
2865
+ function _t(n, e = !1) {
2567
2866
  return /^https?:\/\//i.test(n) ? !0 : e && /^(blob:|data:image\/)/i.test(n);
2568
2867
  }
2569
- var ht = Object.defineProperty, At = Object.getOwnPropertyDescriptor, Et = (n, e, t) => e in n ? ht(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, g = (n, e, t, i) => {
2570
- for (var s = i > 1 ? void 0 : i ? At(e, t) : e, a = n.length - 1, o; a >= 0; a--)
2571
- (o = n[a]) && (s = (i ? o(e, t, s) : o(s)) || s);
2572
- return i && s && ht(e, t, s), s;
2573
- }, Nt = (n, e, t) => Et(n, e + "", t);
2574
- const st = [
2868
+ const xs = 2e5, vs = /* @__PURE__ */ new Set([
2869
+ "script",
2870
+ "foreignobject",
2871
+ "iframe",
2872
+ "object",
2873
+ "embed",
2874
+ "image",
2875
+ "audio",
2876
+ "video",
2877
+ "animate",
2878
+ "set",
2879
+ "animatemotion",
2880
+ "animatetransform",
2881
+ "handler",
2882
+ "listener"
2883
+ ]);
2884
+ function ws(n) {
2885
+ if (!n || n.length > xs || typeof DOMParser > "u") return null;
2886
+ const e = new DOMParser().parseFromString(n, "image/svg+xml"), t = e.documentElement;
2887
+ if (!t || t.nodeName.toLowerCase() !== "svg" || e.querySelector("parsererror"))
2888
+ return null;
2889
+ const s = (a) => {
2890
+ for (const r of Array.from(a.children)) {
2891
+ const c = r.nodeName.toLowerCase();
2892
+ if (vs.has(c)) r.remove();
2893
+ else if (c === "a") {
2894
+ const l = Array.from(r.childNodes);
2895
+ r.replaceWith(...l), l.forEach((f) => f instanceof Element && s(f));
2896
+ } else s(r);
2897
+ }
2898
+ for (const r of Array.from(a.attributes)) {
2899
+ const c = r.name.toLowerCase(), l = r.value.trim().toLowerCase(), f = (c === "href" || c.endsWith(":href")) && !l.startsWith("#"), b = l.includes("javascript:") || /url\(\s*['"]?(?!#)/.test(l);
2900
+ (c.startsWith("on") || f || b) && a.removeAttribute(r.name);
2901
+ }
2902
+ };
2903
+ s(t);
2904
+ for (const a of Array.from(t.querySelectorAll("style")))
2905
+ a.textContent = (a.textContent ?? "").replace(/@import[^;]*;?/gi, "").replace(/url\(\s*['"]?(?!#)[^)]*\)/gi, "none");
2906
+ t.setAttribute("xmlns", "http://www.w3.org/2000/svg");
2907
+ const i = new XMLSerializer().serializeToString(t);
2908
+ return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(i)}`;
2909
+ }
2910
+ var Pt = Object.defineProperty, ys = Object.getOwnPropertyDescriptor, ks = (n, e, t) => e in n ? Pt(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, g = (n, e, t, s) => {
2911
+ for (var i = s > 1 ? void 0 : s ? ys(e, t) : e, a = n.length - 1, r; a >= 0; a--)
2912
+ (r = n[a]) && (i = (s ? r(e, t, i) : r(i)) || i);
2913
+ return s && i && Pt(e, t, i), i;
2914
+ }, $s = (n, e, t) => ks(n, e + "", t);
2915
+ const Lt = [
2575
2916
  "embed",
2576
2917
  "mode",
2577
- "renderAs",
2918
+ "format",
2919
+ "renderers",
2920
+ "beforeSend",
2921
+ "afterParse",
2578
2922
  "glow",
2579
2923
  "position",
2580
2924
  "sidebar",
@@ -2583,14 +2927,33 @@ const st = [
2583
2927
  "logoUrl",
2584
2928
  "heading",
2585
2929
  "description",
2930
+ "eyebrow",
2586
2931
  "prompts",
2587
2932
  "bubbleText",
2588
2933
  "greetingBubble",
2589
2934
  "unreadBadge",
2590
2935
  "allowUpload",
2591
2936
  "allowExport",
2937
+ "allowRaw",
2938
+ "allowCopy",
2939
+ "allowRegenerate",
2940
+ "allowBookmark",
2941
+ "allowDelete",
2942
+ "allowRename",
2943
+ "allowFeedback",
2944
+ "showTime",
2945
+ "showComposer",
2946
+ "footnote",
2592
2947
  "branding",
2593
2948
  "followups",
2949
+ "docsets",
2950
+ "attachmentsMode",
2951
+ "saveAttachments",
2952
+ "showFollowups",
2953
+ "showSources",
2954
+ "showNewChat",
2955
+ "showBookmarked",
2956
+ "allowSearch",
2594
2957
  "autoTitle",
2595
2958
  "model",
2596
2959
  "params",
@@ -2598,8 +2961,9 @@ const st = [
2598
2961
  "retrieval",
2599
2962
  "metadata",
2600
2963
  "messages",
2601
- "theme"
2602
- ], We = {
2964
+ "theme",
2965
+ "radius"
2966
+ ], vt = {
2603
2967
  fromAttribute: (n) => {
2604
2968
  if (n)
2605
2969
  try {
@@ -2613,19 +2977,30 @@ const st = [
2613
2977
  }, I = {
2614
2978
  fromAttribute: (n) => n === null ? !0 : n !== "false",
2615
2979
  toAttribute: (n) => n ? null : "false"
2616
- }, Bt = {
2617
- fromAttribute: (n) => n === null ? void 0 : n !== "false",
2618
- toAttribute: (n) => n === void 0 ? null : String(n)
2619
- }, Dt = 272, Rt = 820, Ut = 940, at = 5, rt = 512 * 1024, Ft = /\.(md|markdown|txt|csv|tsv|json|html?|ya?ml|xml|log)$/i, Kt = 5e3, Pt = 2600, _ = [
2980
+ }, Cs = {
2981
+ fromAttribute: (n) => n === null ? "auto" : n === "" || n === "true" ? "open" : n === "false" ? "closed" : ["auto", "open", "closed", "none"].includes(n) ? n : "auto",
2982
+ toAttribute: (n) => n === "auto" ? null : n
2983
+ }, Ts = 272, Ss = 820, Is = 940, At = 5, jt = 512 * 1024, Os = /\.(md|markdown|txt|csv|tsv|json|html?|ya?ml|xml|log)$/i, Ms = 5e3, zs = 200, Nt = 2e3, _s = {
2984
+ note: "calloutNote",
2985
+ tip: "calloutTip",
2986
+ important: "calloutImportant",
2987
+ warning: "calloutWarning",
2988
+ caution: "calloutCaution"
2989
+ }, Ls = 2600, j = [
2620
2990
  "var(--c-ink)",
2621
2991
  "oklch(0.58 0.13 255)",
2622
2992
  "oklch(0.63 0.1 175)",
2623
2993
  "oklch(0.74 0.12 70)"
2624
- ], nt = {
2994
+ ], Rt = {
2625
2995
  chat: "Be helpful and concise. Use Markdown when it helps: headings, lists, **bold**, code blocks and tables.",
2626
- rag: "Answer ONLY from the sources provided with each message, numbered in the order given. Put a citation like [1] right after each claim it supports. If the sources don't cover the question, say so plainly.",
2627
- rich: 'Lead with one sentence stating the key finding, with key numbers in **bold**. For trends and comparisons, include a chart as a fenced code block with the language "chart" containing only JSON: {"type":"bar"|"line","title":string,"unit":string,"labels":[string],"series":[{"name":string,"values":[number]}]}. Use Markdown tables for exact values. Keep prose short.'
2628
- }, Ht = "After the answer, on a final line write FOLLOWUPS: followed by three short follow-up questions the user might ask next, separated by |.", ot = {
2996
+ rag: "Prefer the sources provided with each message, numbered in the order given, and put a citation like [1] right after each claim they support. If they don't cover the question, you may answer from general knowledge, but say clearly that it isn't from the sources.",
2997
+ kb: "Answer ONLY from the sources provided with each message, numbered in the order given. Put a citation like [1] right after each claim. Do not use outside knowledge. If the sources don't contain the answer, say that you can't find it in the available sources."
2998
+ }, As = {
2999
+ raw: "Reply in plain text. Don't use Markdown or any other markup.",
3000
+ plain: "Format with light Markdown only: short paragraphs, lists, **bold**, *italics*, `inline code`, code blocks and links. Don't use tables, charts, callouts, images or other special blocks.",
3001
+ advanced: `You can use Markdown: headings, lists, task lists, **bold**, *italics*, links, code blocks and pipe tables. For data, use a fenced "csv" block or a fenced "json" block. For a diagram or illustration, write a self-contained fenced "svg" block with a viewBox, and no scripts, links or external images. Don't use charts, callouts or images.`,
3002
+ rich: 'When the answer is about data, lead with one sentence stating the key finding, with key numbers in **bold**, then show the data visually. You can use Markdown: headings, lists, task lists, **bold**, *italics*, links, code blocks and pipe tables. For data, use a fenced "csv" block or a fenced "json" block. For a diagram or illustration, write a self-contained fenced "svg" block with a viewBox, and no scripts, links or external images. For trends and comparisons, use a fenced "chart" block containing only JSON: {"type":"bar"|"line","title":string,"unit":string,"labels":[string],"series":[{"name":string,"values":[number]}]}. For notes and warnings, use callouts: a quote starting with [!NOTE], [!TIP], [!IMPORTANT], [!WARNING] or [!CAUTION]. Images use ![alt](https://…).'
3003
+ }, js = "After the answer, on a final line write FOLLOWUPS: followed by three short follow-up questions the user might ask next, separated by |.", Et = {
2629
3004
  chat: [
2630
3005
  ["Write", "Draft a short welcome email for new users"],
2631
3006
  ["Explain", "Explain how refresh tokens work, simply"],
@@ -2638,26 +3013,27 @@ const st = [
2638
3013
  ["Find", "Where is the refund policy described?"],
2639
3014
  ["Explain", "Explain the setup steps in plain language"]
2640
3015
  ],
2641
- rich: [
2642
- ["Bar chart", "Compare the five most spoken languages in a bar chart"],
2643
- ["Line chart", "Show world population from 1950 to 2020"],
2644
- ["Table", "List the planets with their diameters in a table"],
2645
- ["Breakdown", "Break down a $4,000 monthly budget by category"]
3016
+ kb: [
3017
+ ["Find", "Where is the refund policy described?"],
3018
+ ["How to", "How do I reset my password?"],
3019
+ ["Limits", "What are the plan limits?"],
3020
+ ["Policy", "What happens when my account is deleted?"]
2646
3021
  ]
2647
- }, C = (n, e = "") => r`<svg class="i ${e}" viewBox="0 0 16 16" aria-hidden="true">${n}</svg>`, y = {
2648
- sidebar: () => C(
2649
- $`<rect x="2" y="2.5" width="12" height="11" rx="1.5"></rect><path d="M6 2.5v11"></path>`
3022
+ }, z = (n, e = "") => o`<svg class="i ${e}" viewBox="0 0 16 16" aria-hidden="true">${n}</svg>`, k = {
3023
+ sidebar: () => z(
3024
+ O`<rect x="2" y="2.5" width="12" height="11" rx="1.5"></rect><path d="M6 2.5v11"></path>`
2650
3025
  ),
2651
- plus: () => C($`<path d="M8 3v10M3 8h10"></path>`),
2652
- bookmark: (n = !1) => C($`<path d="M4.5 2.5h7v11L8 11l-3.5 2.5z"></path>`, n ? "filled" : ""),
2653
- download: () => C($`<path d="M8 2.5v8M4.5 7.5L8 11l3.5-3.5M2.5 13.5h11"></path>`),
2654
- trash: () => C($`<path d="M2.5 4.5h11M6.5 4.5v-2h3v2M4 4.5l.7 9h6.6l.7-9"></path>`),
2655
- pencil: () => C($`<path d="M10.5 2.5l3 3L6 13H3v-3z"></path>`),
2656
- copy: () => C(
2657
- $`<rect x="5.5" y="5.5" width="8" height="8" rx="1.5"></rect><path d="M10.5 5.5v-2a1 1 0 0 0-1-1h-6a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2"></path>`
3026
+ plus: () => z(O`<path d="M8 3v10M3 8h10"></path>`),
3027
+ bookmark: (n = !1) => z(O`<path d="M4.5 2.5h7v11L8 11l-3.5 2.5z"></path>`, n ? "filled" : ""),
3028
+ download: () => z(O`<path d="M8 2.5v8M4.5 7.5L8 11l3.5-3.5M2.5 13.5h11"></path>`),
3029
+ trash: () => z(O`<path d="M2.5 4.5h11M6.5 4.5v-2h3v2M4 4.5l.7 9h6.6l.7-9"></path>`),
3030
+ pencil: () => z(O`<path d="M10.5 2.5l3 3L6 13H3v-3z"></path>`),
3031
+ copy: () => z(
3032
+ O`<rect x="5.5" y="5.5" width="8" height="8" rx="1.5"></rect><path d="M10.5 5.5v-2a1 1 0 0 0-1-1h-6a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2"></path>`
2658
3033
  ),
2659
- refresh: () => C($`<path d="M13.5 8A5.5 5.5 0 1 1 11.9 4.1M13.5 2v3.5H10"></path>`),
2660
- thumb: (n = !1) => r`<svg
3034
+ raw: () => z(O`<path d="M5.5 4.5L2 8l3.5 3.5M10.5 4.5L14 8l-3.5 3.5"></path>`),
3035
+ refresh: () => z(O`<path d="M13.5 8A5.5 5.5 0 1 1 11.9 4.1M13.5 2v3.5H10"></path>`),
3036
+ thumb: (n = !1) => o`<svg
2661
3037
  class="i"
2662
3038
  viewBox="0 0 16 16"
2663
3039
  aria-hidden="true"
@@ -2667,16 +3043,16 @@ const st = [
2667
3043
  d="M5 7v6.5H2.5V7zM5 7l2.5-4.5a1.3 1.3 0 0 1 1.9 1.4L9 6.5h3.6a1 1 0 0 1 1 1.2l-1 4.8a1 1 0 0 1-1 .8H5"
2668
3044
  ></path>
2669
3045
  </svg>`,
2670
- expand: () => C($`<path d="M9.5 2.5h4v4M13.5 2.5L9 7M6.5 13.5h-4v-4M2.5 13.5L7 9"></path>`),
2671
- restore: () => C($`<path d="M13.5 6.5h-4v-4M9.5 6.5l4-4M2.5 9.5h4v4M6.5 9.5l-4 4"></path>`),
2672
- minimize: () => C($`<path d="M4 8h8"></path>`),
2673
- close: () => C($`<path d="M4 4l8 8M12 4l-8 8"></path>`),
2674
- clip: () => C(
2675
- $`<path d="M13 7.5l-5.3 5.3a3 3 0 0 1-4.3-4.3L9 2.9a2 2 0 0 1 2.9 2.9L6.4 11.3a1 1 0 0 1-1.4-1.4L10 5"></path>`
3046
+ expand: () => z(O`<path d="M9.5 2.5h4v4M13.5 2.5L9 7M6.5 13.5h-4v-4M2.5 13.5L7 9"></path>`),
3047
+ restore: () => z(O`<path d="M13.5 6.5h-4v-4M9.5 6.5l4-4M2.5 9.5h4v4M6.5 9.5l-4 4"></path>`),
3048
+ minimize: () => z(O`<path d="M4 8h8"></path>`),
3049
+ close: () => z(O`<path d="M4 4l8 8M12 4l-8 8"></path>`),
3050
+ clip: () => z(
3051
+ O`<path d="M13 7.5l-5.3 5.3a3 3 0 0 1-4.3-4.3L9 2.9a2 2 0 0 1 2.9 2.9L6.4 11.3a1 1 0 0 1-1.4-1.4L10 5"></path>`
2676
3052
  ),
2677
- up: () => C($`<path d="M8 13V3M3.5 7.5L8 3l4.5 4.5"></path>`),
2678
- stop: () => C($`<rect x="4.5" y="4.5" width="7" height="7" rx="1"></rect>`),
2679
- chat: () => r`<svg
3053
+ up: () => z(O`<path d="M8 13V3M3.5 7.5L8 3l4.5 4.5"></path>`),
3054
+ stop: () => z(O`<rect x="4.5" y="4.5" width="7" height="7" rx="1"></rect>`),
3055
+ chat: () => o`<svg
2680
3056
  width="22"
2681
3057
  height="22"
2682
3058
  viewBox="0 0 22 22"
@@ -2687,7 +3063,7 @@ const st = [
2687
3063
  d="M4 5.5A2.5 2.5 0 0 1 6.5 3h9A2.5 2.5 0 0 1 18 5.5v7a2.5 2.5 0 0 1-2.5 2.5H9l-4 3.5V15H6.5"
2688
3064
  ></path>
2689
3065
  </svg>`,
2690
- chevronDown: () => r`<svg
3066
+ chevronDown: () => o`<svg
2691
3067
  width="20"
2692
3068
  height="20"
2693
3069
  viewBox="0 0 20 20"
@@ -2697,150 +3073,189 @@ const st = [
2697
3073
  <path d="M5 8l5 5 5-5"></path>
2698
3074
  </svg>`
2699
3075
  };
2700
- let Jt = 0;
2701
- const Je = () => `m${Date.now().toString(36)}${(Jt++).toString(36)}`;
2702
- function lt(n) {
3076
+ let Ns = 0;
3077
+ const bt = () => `m${Date.now().toString(36)}${(Ns++).toString(36)}`;
3078
+ function Bt(n) {
2703
3079
  var t;
2704
3080
  const e = n;
2705
3081
  return (e == null ? void 0 : e.message) === "NOT_FOUND" || (e == null ? void 0 : e.code) === "NOT_FOUND" || ((t = e == null ? void 0 : e.details) == null ? void 0 : t.status) === 404;
2706
3082
  }
2707
- function Wt(n) {
3083
+ function Rs(n) {
2708
3084
  const e = n;
2709
3085
  return (e == null ? void 0 : e.code) || (e == null ? void 0 : e.message) || "UNKNOWN";
2710
3086
  }
2711
- const qt = () => typeof matchMedia < "u" && matchMedia("(prefers-reduced-motion: reduce)").matches, Fe = (n, e) => (Number.isInteger(n) ? n.toLocaleString("en-US") : n.toFixed(1)) + e, ct = (n) => {
3087
+ const Es = () => typeof matchMedia < "u" && matchMedia("(prefers-reduced-motion: reduce)").matches, mt = (n, e) => (Number.isInteger(n) ? n.toLocaleString("en-US") : n.toFixed(1)) + e, xt = (n) => {
2712
3088
  const e = n.lastIndexOf(".");
2713
3089
  return e > 0 ? n.slice(e + 1, e + 5).toUpperCase() : "FILE";
2714
3090
  };
2715
- function Ke(n, e) {
2716
- const t = n ?? {}, i = t.metadata && typeof t.metadata == "object" ? t.metadata : {}, s = (...l) => l.find((c) => typeof c == "string" && c.trim()), a = s(t.content, t.text, t.page_content, t.body, t.snippet, t.chunk, i.content) ?? JSON.stringify(t, null, 2), o = [t.score, t.relevance, t._score, i.score].find((l) => typeof l == "number");
3091
+ function ft(n, e) {
3092
+ const t = n ?? {}, s = t.metadata && typeof t.metadata == "object" ? t.metadata : {}, i = (...l) => l.find((f) => typeof f == "string" && f.trim()), a = i(t.content, t.text, t.page_content, t.body, t.snippet, t.chunk, s.content) ?? JSON.stringify(t, null, 2), r = [t.score, t.relevance, t._score, s.score].find((l) => typeof l == "number"), c = typeof t.n == "number" && t.n > 0 ? t.n : e;
2717
3093
  return {
2718
- n: e,
2719
- title: s(t.title, t.name, t.filename, i.title, i.name) ?? `Source ${e}`,
2720
- path: s(t.path, t.url, t.key, t.source, i.path, i.url) ?? "",
2721
- collection: s(t.collection, t.namespace, t.dbname, i.collection) ?? "",
2722
- updated: s(t.updated, t._modified_at, i.updated) ?? "",
3094
+ n: c,
3095
+ title: i(t.title, t.name, t.filename, s.title, s.name) ?? `Source ${c}`,
3096
+ section: i(t.section, t.heading, s.section) ?? "",
3097
+ path: i(t.path, t.url, t.key, s.path, s.url) ?? "",
3098
+ collection: i(t.collection, t.namespace, t.dbname, s.collection) ?? "",
3099
+ updated: i(t.updated, t._modified_at, s.updated) ?? "",
2723
3100
  text: a,
2724
- score: o === void 0 ? null : Math.max(0, Math.min(1, o))
3101
+ score: r === void 0 ? null : Math.max(0, Math.min(1, r))
2725
3102
  };
2726
3103
  }
2727
- function Gt(n) {
3104
+ function Dt(n) {
3105
+ return Array.isArray(n) ? n.filter((e) => e && typeof e == "object" && (e._id || e.id)).filter((e) => e.saved !== !1 && e.status !== "failed").map((e) => ({
3106
+ id: String(e._id ?? e.id),
3107
+ name: String(e.name ?? "file"),
3108
+ type: e.type,
3109
+ mime: e.mime,
3110
+ size: typeof e.size == "number" ? e.size : void 0,
3111
+ status: e.status
3112
+ })) : [];
3113
+ }
3114
+ function Bs(n) {
2728
3115
  const e = [], t = [];
2729
- for (const i of n)
2730
- if (/\.csv$/i.test(i.name)) e.push({ type: "csv", data: i.content });
2731
- else if (/\.json$/i.test(i.name))
3116
+ for (const s of n)
3117
+ if (/\.csv$/i.test(s.name)) e.push({ type: "csv", data: s.content });
3118
+ else if (/\.json$/i.test(s.name))
2732
3119
  try {
2733
- e.push({ type: "json", data: JSON.parse(i.content) });
3120
+ e.push({ type: "json", data: JSON.parse(s.content) });
2734
3121
  } catch {
2735
- t.push({ title: i.name, content: i.content });
3122
+ t.push({ title: s.name, content: s.content });
2736
3123
  }
2737
- else t.push({ title: i.name, content: i.content });
3124
+ else t.push({ title: s.name, content: s.content });
2738
3125
  return t.length && e.push({ type: "docs", payload: { documents: t } }), e;
2739
3126
  }
2740
- function Pe(n) {
3127
+ function Ds(n) {
2741
3128
  const e = n ? Date.parse(n) : NaN;
2742
3129
  if (Number.isNaN(e)) return "older";
2743
3130
  const t = /* @__PURE__ */ new Date();
2744
3131
  t.setHours(0, 0, 0, 0);
2745
- const i = 864e5;
2746
- return e >= t.getTime() ? "today" : e >= t.getTime() - i ? "yesterday" : e >= t.getTime() - 7 * i ? "week" : "older";
3132
+ const s = 864e5;
3133
+ return e >= t.getTime() ? "today" : e >= t.getTime() - s ? "yesterday" : e >= t.getTime() - 7 * s ? "week" : "older";
2747
3134
  }
2748
- var j, A, E, N, B, D, R, U, F, K, P, H, J, W, q, G, V, X, Y, Q, Z, ee, te, ie, se, ae, re, ne, oe, le, ce, de, pe, he, ue, ge, me, be, fe, xe, ve, ye, ke, we, $e, Te, Ce, Se, ze, Oe, Me, _e, Ie, Le, je, Ae, Ee, Ne, Be, De, Re, dt;
2749
- let d = (dt = class extends ft {
3135
+ var N, R, E, B, D, F, K, P, U, W, H, J, G, q, V, X, Y, Q, Z, ee, te, se, ie, ae, re, oe, ne, le, ce, de, pe, he, ue, ge, me, fe, be, xe, ve, we, ye, ke, $e, Ce, Te, Se, Ie, Oe, Me, ze, _e, Le, Ae, je, Ne, Re, Ee, Be, De, Fe, Ke, Pe, Ue, We, He, Je, Ge, qe, Ve, Xe, Ye, Qe, Ze, et, tt, st, it, at, rt, ot, nt, lt, ct, dt, pt, ht, ut, gt, Ft;
3136
+ let d = (Ft = class extends Jt {
2750
3137
  constructor() {
2751
3138
  super(...arguments);
2752
- h(this, j, null);
2753
- h(this, A, {});
3139
+ h(this, N, null);
3140
+ h(this, R, {});
2754
3141
  h(this, E);
2755
- h(this, N, "chat");
2756
- h(this, B, "rich");
2757
- h(this, D, "subtle");
2758
- h(this, R, !0);
2759
- h(this, U, !0);
2760
- h(this, F, "");
3142
+ h(this, B);
3143
+ h(this, D, "chat");
3144
+ h(this, F, "advanced");
2761
3145
  h(this, K, {});
2762
- h(this, P, "");
2763
- h(this, H, []);
2764
- h(this, J, {});
2765
- h(this, W, "page");
2766
- h(this, q, "right");
2767
- h(this, G);
3146
+ h(this, P, null);
3147
+ h(this, U, null);
3148
+ h(this, W, "subtle");
3149
+ h(this, H, "");
3150
+ h(this, J, "retrieval");
3151
+ h(this, G, !0);
3152
+ h(this, q, !0);
2768
3153
  h(this, V, !0);
2769
- h(this, X, "");
2770
- h(this, Y, "Assistant");
2771
- h(this, Q, "");
2772
- h(this, Z, "");
2773
- h(this, ee, "");
3154
+ h(this, X, !0);
3155
+ h(this, Y, !0);
3156
+ h(this, Q, !0);
3157
+ h(this, Z, !0);
3158
+ h(this, ee, !0);
2774
3159
  h(this, te, "");
3160
+ h(this, se, {});
2775
3161
  h(this, ie, "");
2776
- h(this, se, !1);
2777
- h(this, ae, !1);
2778
- h(this, re, !0);
2779
- h(this, ne, !0);
2780
- h(this, oe, !0);
2781
- h(this, le, []);
2782
- h(this, ce, "idle");
2783
- h(this, de, null);
2784
- h(this, pe, "");
2785
- h(this, he, !1);
2786
- h(this, ue, []);
2787
- h(this, ge, !1);
2788
- h(this, me, "");
2789
- h(this, be, !1);
3162
+ h(this, ae, []);
3163
+ h(this, re, {});
3164
+ h(this, oe, "page");
3165
+ h(this, ne, "right");
3166
+ h(this, le, "auto");
3167
+ h(this, ce, !0);
3168
+ h(this, de, "");
3169
+ h(this, pe, "Assistant");
3170
+ h(this, he, "");
3171
+ h(this, ue, "");
3172
+ h(this, ge, "");
3173
+ h(this, me);
2790
3174
  h(this, fe, "");
2791
- h(this, xe, []);
2792
- h(this, ve, "");
2793
- h(this, ye, null);
2794
- h(this, ke, 0);
2795
- h(this, we, null);
2796
- h(this, $e, !1);
2797
- h(this, Te, "");
2798
- h(this, Ce, "");
2799
- h(this, Se, !1);
2800
- h(this, ze, "");
2801
- h(this, Oe, null);
2802
- h(this, Me, "");
2803
- h(this, _e, /* @__PURE__ */ new Set());
2804
- h(this, Ie, "");
2805
- h(this, Le, !1);
2806
- h(this, je, !1);
2807
- h(this, Ae, !1);
3175
+ h(this, be, "");
3176
+ h(this, xe, !1);
3177
+ h(this, ve, !1);
3178
+ h(this, we, !0);
3179
+ h(this, ye, !0);
3180
+ h(this, ke, !0);
3181
+ h(this, $e, !0);
3182
+ h(this, Ce, !0);
3183
+ h(this, Te, !0);
3184
+ h(this, Se, !0);
3185
+ h(this, Ie, !0);
3186
+ h(this, Oe, !0);
3187
+ h(this, Me, !0);
3188
+ h(this, ze);
3189
+ h(this, _e, !1);
3190
+ h(this, Le, !0);
3191
+ h(this, Ae, []);
3192
+ h(this, je, "idle");
3193
+ h(this, Ne, null);
3194
+ h(this, Re, "");
2808
3195
  h(this, Ee, !1);
2809
- h(this, Ne, !1);
2810
- h(this, Be, !1);
3196
+ h(this, Be, []);
2811
3197
  h(this, De, !1);
2812
- h(this, Re, !1);
2813
- T(this, "run", 0);
2814
- T(this, "abort", null);
2815
- T(this, "revealTimer");
2816
- T(this, "timers", /* @__PURE__ */ new Set());
2817
- T(this, "toastTimer");
2818
- T(this, "stick", !0);
2819
- T(this, "renamed", /* @__PURE__ */ new Set());
2820
- T(this, "observer", null);
2821
- T(this, "observed", null);
2822
- T(this, "media", null);
2823
- T(this, "focusNext", "");
2824
- T(this, "bubbleScheduled", !1);
2825
- T(this, "onNetwork", () => {
3198
+ h(this, Fe, "");
3199
+ h(this, Ke, !1);
3200
+ h(this, Pe, "");
3201
+ h(this, Ue, []);
3202
+ h(this, We, "");
3203
+ h(this, He, null);
3204
+ h(this, Je, 0);
3205
+ h(this, Ge, null);
3206
+ h(this, qe, !1);
3207
+ h(this, Ve, "");
3208
+ h(this, Xe, "");
3209
+ h(this, Ye, !1);
3210
+ h(this, Qe, "");
3211
+ h(this, Ze, null);
3212
+ h(this, et, "");
3213
+ h(this, tt, /* @__PURE__ */ new Set());
3214
+ h(this, st, /* @__PURE__ */ new Set());
3215
+ h(this, it, []);
3216
+ h(this, at, !1);
3217
+ h(this, rt, /* @__PURE__ */ new Map());
3218
+ h(this, ot, "");
3219
+ h(this, nt, !1);
3220
+ h(this, lt, !1);
3221
+ h(this, ct, !1);
3222
+ h(this, dt, !1);
3223
+ h(this, pt, !1);
3224
+ h(this, ht, !1);
3225
+ h(this, ut, !1);
3226
+ h(this, gt, !1);
3227
+ M(this, "run", 0);
3228
+ M(this, "abort", null);
3229
+ M(this, "revealTimer");
3230
+ M(this, "timers", /* @__PURE__ */ new Set());
3231
+ M(this, "toastTimer");
3232
+ M(this, "stick", !0);
3233
+ M(this, "renamed", /* @__PURE__ */ new Set());
3234
+ M(this, "observer", null);
3235
+ M(this, "observed", null);
3236
+ M(this, "media", null);
3237
+ M(this, "focusNext", "");
3238
+ M(this, "bubbleScheduled", !1);
3239
+ M(this, "pendingChatId", "");
3240
+ M(this, "onNetwork", () => {
2826
3241
  this.offline = navigator.onLine === !1;
2827
3242
  });
2828
- T(this, "onMedia", () => {
3243
+ M(this, "onMedia", () => {
2829
3244
  var e;
2830
3245
  this.mobile = !!((e = this.media) != null && e.matches);
2831
3246
  });
2832
3247
  }
2833
3248
  get client() {
2834
- return p(this, j);
3249
+ return p(this, N);
2835
3250
  }
2836
3251
  set client(e) {
2837
- u(this, j, e);
3252
+ u(this, N, e);
2838
3253
  }
2839
3254
  get messages() {
2840
- return p(this, A);
3255
+ return p(this, R);
2841
3256
  }
2842
3257
  set messages(e) {
2843
- u(this, A, e);
3258
+ u(this, R, e);
2844
3259
  }
2845
3260
  get theme() {
2846
3261
  return p(this, E);
@@ -2848,360 +3263,522 @@ let d = (dt = class extends ft {
2848
3263
  set theme(e) {
2849
3264
  u(this, E, e);
2850
3265
  }
2851
- get mode() {
2852
- return p(this, N);
2853
- }
2854
- set mode(e) {
2855
- u(this, N, e);
2856
- }
2857
- get renderAs() {
3266
+ get radius() {
2858
3267
  return p(this, B);
2859
3268
  }
2860
- set renderAs(e) {
3269
+ set radius(e) {
2861
3270
  u(this, B, e);
2862
3271
  }
2863
- get glow() {
3272
+ get mode() {
2864
3273
  return p(this, D);
2865
3274
  }
2866
- set glow(e) {
3275
+ set mode(e) {
2867
3276
  u(this, D, e);
2868
3277
  }
2869
- get followups() {
2870
- return p(this, R);
2871
- }
2872
- set followups(e) {
2873
- u(this, R, e);
2874
- }
2875
- get autoTitle() {
2876
- return p(this, U);
2877
- }
2878
- set autoTitle(e) {
2879
- u(this, U, e);
2880
- }
2881
- get model() {
3278
+ get format() {
2882
3279
  return p(this, F);
2883
3280
  }
2884
- set model(e) {
3281
+ set format(e) {
2885
3282
  u(this, F, e);
2886
3283
  }
2887
- get params() {
3284
+ get renderers() {
2888
3285
  return p(this, K);
2889
3286
  }
2890
- set params(e) {
3287
+ set renderers(e) {
2891
3288
  u(this, K, e);
2892
3289
  }
2893
- get systemMessage() {
3290
+ get beforeSend() {
2894
3291
  return p(this, P);
2895
3292
  }
2896
- set systemMessage(e) {
3293
+ set beforeSend(e) {
2897
3294
  u(this, P, e);
2898
3295
  }
2899
- get retrieval() {
3296
+ get afterParse() {
3297
+ return p(this, U);
3298
+ }
3299
+ set afterParse(e) {
3300
+ u(this, U, e);
3301
+ }
3302
+ get glow() {
3303
+ return p(this, W);
3304
+ }
3305
+ set glow(e) {
3306
+ u(this, W, e);
3307
+ }
3308
+ get docsets() {
2900
3309
  return p(this, H);
2901
3310
  }
2902
- set retrieval(e) {
3311
+ set docsets(e) {
2903
3312
  u(this, H, e);
2904
3313
  }
2905
- get metadata() {
3314
+ get attachmentsMode() {
2906
3315
  return p(this, J);
2907
3316
  }
2908
- set metadata(e) {
3317
+ set attachmentsMode(e) {
2909
3318
  u(this, J, e);
2910
3319
  }
2911
- get embed() {
2912
- return p(this, W);
3320
+ get saveAttachments() {
3321
+ return p(this, G);
2913
3322
  }
2914
- set embed(e) {
2915
- u(this, W, e);
3323
+ set saveAttachments(e) {
3324
+ u(this, G, e);
2916
3325
  }
2917
- get position() {
3326
+ get followups() {
2918
3327
  return p(this, q);
2919
3328
  }
2920
- set position(e) {
3329
+ set followups(e) {
2921
3330
  u(this, q, e);
2922
3331
  }
3332
+ get showSources() {
3333
+ return p(this, V);
3334
+ }
3335
+ set showSources(e) {
3336
+ u(this, V, e);
3337
+ }
3338
+ get showNewChat() {
3339
+ return p(this, X);
3340
+ }
3341
+ set showNewChat(e) {
3342
+ u(this, X, e);
3343
+ }
3344
+ get showBookmarked() {
3345
+ return p(this, Y);
3346
+ }
3347
+ set showBookmarked(e) {
3348
+ u(this, Y, e);
3349
+ }
3350
+ get showFollowups() {
3351
+ return p(this, Q);
3352
+ }
3353
+ set showFollowups(e) {
3354
+ u(this, Q, e);
3355
+ }
3356
+ get allowSearch() {
3357
+ return p(this, Z);
3358
+ }
3359
+ set allowSearch(e) {
3360
+ u(this, Z, e);
3361
+ }
3362
+ get autoTitle() {
3363
+ return p(this, ee);
3364
+ }
3365
+ set autoTitle(e) {
3366
+ u(this, ee, e);
3367
+ }
3368
+ get model() {
3369
+ return p(this, te);
3370
+ }
3371
+ set model(e) {
3372
+ u(this, te, e);
3373
+ }
3374
+ get params() {
3375
+ return p(this, se);
3376
+ }
3377
+ set params(e) {
3378
+ u(this, se, e);
3379
+ }
3380
+ get systemMessage() {
3381
+ return p(this, ie);
3382
+ }
3383
+ set systemMessage(e) {
3384
+ u(this, ie, e);
3385
+ }
3386
+ get retrieval() {
3387
+ return p(this, ae);
3388
+ }
3389
+ set retrieval(e) {
3390
+ u(this, ae, e);
3391
+ }
3392
+ get metadata() {
3393
+ return p(this, re);
3394
+ }
3395
+ set metadata(e) {
3396
+ u(this, re, e);
3397
+ }
3398
+ get embed() {
3399
+ return p(this, oe);
3400
+ }
3401
+ set embed(e) {
3402
+ u(this, oe, e);
3403
+ }
3404
+ get position() {
3405
+ return p(this, ne);
3406
+ }
3407
+ set position(e) {
3408
+ u(this, ne, e);
3409
+ }
2923
3410
  get sidebar() {
2924
- return p(this, G);
3411
+ return p(this, le);
2925
3412
  }
2926
3413
  set sidebar(e) {
2927
- u(this, G, e);
3414
+ u(this, le, e);
2928
3415
  }
2929
3416
  get showTitle() {
2930
- return p(this, V);
3417
+ return p(this, ce);
2931
3418
  }
2932
3419
  set showTitle(e) {
2933
- u(this, V, e);
3420
+ u(this, ce, e);
2934
3421
  }
2935
3422
  get chatIdAttr() {
2936
- return p(this, X);
3423
+ return p(this, de);
2937
3424
  }
2938
3425
  set chatIdAttr(e) {
2939
- u(this, X, e);
3426
+ u(this, de, e);
2940
3427
  }
2941
3428
  get assistantName() {
2942
- return p(this, Y);
3429
+ return p(this, pe);
2943
3430
  }
2944
3431
  set assistantName(e) {
2945
- u(this, Y, e);
3432
+ u(this, pe, e);
2946
3433
  }
2947
3434
  get logoUrl() {
2948
- return p(this, Q);
3435
+ return p(this, he);
2949
3436
  }
2950
3437
  set logoUrl(e) {
2951
- u(this, Q, e);
3438
+ u(this, he, e);
2952
3439
  }
2953
3440
  get heading() {
2954
- return p(this, Z);
3441
+ return p(this, ue);
2955
3442
  }
2956
3443
  set heading(e) {
2957
- u(this, Z, e);
3444
+ u(this, ue, e);
2958
3445
  }
2959
3446
  get description() {
2960
- return p(this, ee);
3447
+ return p(this, ge);
2961
3448
  }
2962
3449
  set description(e) {
2963
- u(this, ee, e);
3450
+ u(this, ge, e);
3451
+ }
3452
+ get eyebrow() {
3453
+ return p(this, me);
3454
+ }
3455
+ set eyebrow(e) {
3456
+ u(this, me, e);
2964
3457
  }
2965
3458
  get prompts() {
2966
- return p(this, te);
3459
+ return p(this, fe);
2967
3460
  }
2968
3461
  set prompts(e) {
2969
- u(this, te, e);
3462
+ u(this, fe, e);
2970
3463
  }
2971
3464
  get bubbleText() {
2972
- return p(this, ie);
3465
+ return p(this, be);
2973
3466
  }
2974
3467
  set bubbleText(e) {
2975
- u(this, ie, e);
3468
+ u(this, be, e);
2976
3469
  }
2977
3470
  get greetingBubble() {
2978
- return p(this, se);
3471
+ return p(this, xe);
2979
3472
  }
2980
3473
  set greetingBubble(e) {
2981
- u(this, se, e);
3474
+ u(this, xe, e);
2982
3475
  }
2983
3476
  get unreadBadge() {
2984
- return p(this, ae);
3477
+ return p(this, ve);
2985
3478
  }
2986
3479
  set unreadBadge(e) {
2987
- u(this, ae, e);
3480
+ u(this, ve, e);
2988
3481
  }
2989
3482
  get allowUpload() {
2990
- return p(this, re);
3483
+ return p(this, we);
2991
3484
  }
2992
3485
  set allowUpload(e) {
2993
- u(this, re, e);
3486
+ u(this, we, e);
2994
3487
  }
2995
3488
  get allowExport() {
2996
- return p(this, ne);
3489
+ return p(this, ye);
2997
3490
  }
2998
3491
  set allowExport(e) {
2999
- u(this, ne, e);
3492
+ u(this, ye, e);
3493
+ }
3494
+ get allowCopy() {
3495
+ return p(this, ke);
3496
+ }
3497
+ set allowCopy(e) {
3498
+ u(this, ke, e);
3499
+ }
3500
+ get allowRegenerate() {
3501
+ return p(this, $e);
3502
+ }
3503
+ set allowRegenerate(e) {
3504
+ u(this, $e, e);
3505
+ }
3506
+ get allowBookmark() {
3507
+ return p(this, Ce);
3508
+ }
3509
+ set allowBookmark(e) {
3510
+ u(this, Ce, e);
3511
+ }
3512
+ get allowDelete() {
3513
+ return p(this, Te);
3514
+ }
3515
+ set allowDelete(e) {
3516
+ u(this, Te, e);
3517
+ }
3518
+ get allowRename() {
3519
+ return p(this, Se);
3520
+ }
3521
+ set allowRename(e) {
3522
+ u(this, Se, e);
3523
+ }
3524
+ get allowFeedback() {
3525
+ return p(this, Ie);
3526
+ }
3527
+ set allowFeedback(e) {
3528
+ u(this, Ie, e);
3529
+ }
3530
+ get showComposer() {
3531
+ return p(this, Oe);
3532
+ }
3533
+ set showComposer(e) {
3534
+ u(this, Oe, e);
3535
+ }
3536
+ get showTime() {
3537
+ return p(this, Me);
3538
+ }
3539
+ set showTime(e) {
3540
+ u(this, Me, e);
3541
+ }
3542
+ get footnote() {
3543
+ return p(this, ze);
3544
+ }
3545
+ set footnote(e) {
3546
+ u(this, ze, e);
3547
+ }
3548
+ get allowRaw() {
3549
+ return p(this, _e);
3550
+ }
3551
+ set allowRaw(e) {
3552
+ u(this, _e, e);
3000
3553
  }
3001
3554
  get branding() {
3002
- return p(this, oe);
3555
+ return p(this, Le);
3003
3556
  }
3004
3557
  set branding(e) {
3005
- u(this, oe, e);
3558
+ u(this, Le, e);
3006
3559
  }
3007
3560
  get chatList() {
3008
- return p(this, le);
3561
+ return p(this, Ae);
3009
3562
  }
3010
3563
  set chatList(e) {
3011
- u(this, le, e);
3564
+ u(this, Ae, e);
3012
3565
  }
3013
3566
  get listState() {
3014
- return p(this, ce);
3567
+ return p(this, je);
3015
3568
  }
3016
3569
  set listState(e) {
3017
- u(this, ce, e);
3570
+ u(this, je, e);
3018
3571
  }
3019
3572
  get activeId() {
3020
- return p(this, de);
3573
+ return p(this, Ne);
3021
3574
  }
3022
3575
  set activeId(e) {
3023
- u(this, de, e);
3576
+ u(this, Ne, e);
3024
3577
  }
3025
3578
  get chatTitle() {
3026
- return p(this, pe);
3579
+ return p(this, Re);
3027
3580
  }
3028
3581
  set chatTitle(e) {
3029
- u(this, pe, e);
3582
+ u(this, Re, e);
3030
3583
  }
3031
3584
  get bookmarked() {
3032
- return p(this, he);
3585
+ return p(this, Ee);
3033
3586
  }
3034
3587
  set bookmarked(e) {
3035
- u(this, he, e);
3588
+ u(this, Ee, e);
3036
3589
  }
3037
3590
  get msgs() {
3038
- return p(this, ue);
3591
+ return p(this, Be);
3039
3592
  }
3040
3593
  set msgs(e) {
3041
- u(this, ue, e);
3594
+ u(this, Be, e);
3042
3595
  }
3043
3596
  get loadingThread() {
3044
- return p(this, ge);
3597
+ return p(this, De);
3045
3598
  }
3046
3599
  set loadingThread(e) {
3047
- u(this, ge, e);
3600
+ u(this, De, e);
3048
3601
  }
3049
3602
  get threadError() {
3050
- return p(this, me);
3603
+ return p(this, Fe);
3051
3604
  }
3052
3605
  set threadError(e) {
3053
- u(this, me, e);
3606
+ u(this, Fe, e);
3054
3607
  }
3055
3608
  get busy() {
3056
- return p(this, be);
3609
+ return p(this, Ke);
3057
3610
  }
3058
3611
  set busy(e) {
3059
- u(this, be, e);
3612
+ u(this, Ke, e);
3060
3613
  }
3061
3614
  get draft() {
3062
- return p(this, fe);
3615
+ return p(this, Pe);
3063
3616
  }
3064
3617
  set draft(e) {
3065
- u(this, fe, e);
3618
+ u(this, Pe, e);
3066
3619
  }
3067
3620
  get files() {
3068
- return p(this, xe);
3621
+ return p(this, Ue);
3069
3622
  }
3070
3623
  set files(e) {
3071
- u(this, xe, e);
3624
+ u(this, Ue, e);
3072
3625
  }
3073
3626
  get search() {
3074
- return p(this, ve);
3627
+ return p(this, We);
3075
3628
  }
3076
3629
  set search(e) {
3077
- u(this, ve, e);
3630
+ u(this, We, e);
3078
3631
  }
3079
3632
  get sidebarOpen() {
3080
- return p(this, ye);
3633
+ return p(this, He);
3081
3634
  }
3082
3635
  set sidebarOpen(e) {
3083
- u(this, ye, e);
3636
+ u(this, He, e);
3084
3637
  }
3085
3638
  get width() {
3086
- return p(this, ke);
3639
+ return p(this, Je);
3087
3640
  }
3088
3641
  set width(e) {
3089
- u(this, ke, e);
3642
+ u(this, Je, e);
3090
3643
  }
3091
3644
  get panel() {
3092
- return p(this, we);
3645
+ return p(this, Ge);
3093
3646
  }
3094
3647
  set panel(e) {
3095
- u(this, we, e);
3648
+ u(this, Ge, e);
3096
3649
  }
3097
3650
  get menuOpen() {
3098
- return p(this, $e);
3651
+ return p(this, qe);
3099
3652
  }
3100
3653
  set menuOpen(e) {
3101
- u(this, $e, e);
3654
+ u(this, qe, e);
3102
3655
  }
3103
3656
  get editingKey() {
3104
- return p(this, Te);
3657
+ return p(this, Ve);
3105
3658
  }
3106
3659
  set editingKey(e) {
3107
- u(this, Te, e);
3660
+ u(this, Ve, e);
3108
3661
  }
3109
3662
  get editDraft() {
3110
- return p(this, Ce);
3663
+ return p(this, Xe);
3111
3664
  }
3112
3665
  set editDraft(e) {
3113
- u(this, Ce, e);
3666
+ u(this, Xe, e);
3114
3667
  }
3115
3668
  get editingTitle() {
3116
- return p(this, Se);
3669
+ return p(this, Ye);
3117
3670
  }
3118
3671
  set editingTitle(e) {
3119
- u(this, Se, e);
3672
+ u(this, Ye, e);
3120
3673
  }
3121
3674
  get renamingId() {
3122
- return p(this, ze);
3675
+ return p(this, Qe);
3123
3676
  }
3124
3677
  set renamingId(e) {
3125
- u(this, ze, e);
3678
+ u(this, Qe, e);
3126
3679
  }
3127
3680
  get toast() {
3128
- return p(this, Oe);
3681
+ return p(this, Ze);
3129
3682
  }
3130
3683
  set toast(e) {
3131
- u(this, Oe, e);
3684
+ u(this, Ze, e);
3132
3685
  }
3133
3686
  get copiedKey() {
3134
- return p(this, Me);
3687
+ return p(this, et);
3135
3688
  }
3136
3689
  set copiedKey(e) {
3137
- u(this, Me, e);
3690
+ u(this, et, e);
3138
3691
  }
3139
3692
  get retrievalOpen() {
3140
- return p(this, _e);
3693
+ return p(this, tt);
3141
3694
  }
3142
3695
  set retrievalOpen(e) {
3143
- u(this, _e, e);
3696
+ u(this, tt, e);
3697
+ }
3698
+ get rawKeys() {
3699
+ return p(this, st);
3700
+ }
3701
+ set rawKeys(e) {
3702
+ u(this, st, e);
3703
+ }
3704
+ get savedFiles() {
3705
+ return p(this, it);
3706
+ }
3707
+ set savedFiles(e) {
3708
+ u(this, it, e);
3709
+ }
3710
+ get hasSidebarContent() {
3711
+ return p(this, at);
3712
+ }
3713
+ set hasSidebarContent(e) {
3714
+ u(this, at, e);
3715
+ }
3716
+ get sorts() {
3717
+ return p(this, rt);
3718
+ }
3719
+ set sorts(e) {
3720
+ u(this, rt, e);
3144
3721
  }
3145
3722
  get arrivedKey() {
3146
- return p(this, Ie);
3723
+ return p(this, ot);
3147
3724
  }
3148
3725
  set arrivedKey(e) {
3149
- u(this, Ie, e);
3726
+ u(this, ot, e);
3150
3727
  }
3151
3728
  get dragging() {
3152
- return p(this, Le);
3729
+ return p(this, nt);
3153
3730
  }
3154
3731
  set dragging(e) {
3155
- u(this, Le, e);
3732
+ u(this, nt, e);
3156
3733
  }
3157
3734
  get showJump() {
3158
- return p(this, je);
3735
+ return p(this, lt);
3159
3736
  }
3160
3737
  set showJump(e) {
3161
- u(this, je, e);
3738
+ u(this, lt, e);
3162
3739
  }
3163
3740
  get offline() {
3164
- return p(this, Ae);
3741
+ return p(this, ct);
3165
3742
  }
3166
3743
  set offline(e) {
3167
- u(this, Ae, e);
3744
+ u(this, ct, e);
3168
3745
  }
3169
3746
  get isOpen() {
3170
- return p(this, Ee);
3747
+ return p(this, dt);
3171
3748
  }
3172
3749
  set isOpen(e) {
3173
- u(this, Ee, e);
3750
+ u(this, dt, e);
3174
3751
  }
3175
3752
  get expanded() {
3176
- return p(this, Ne);
3753
+ return p(this, pt);
3177
3754
  }
3178
3755
  set expanded(e) {
3179
- u(this, Ne, e);
3756
+ u(this, pt, e);
3180
3757
  }
3181
3758
  get bubble() {
3182
- return p(this, Be);
3759
+ return p(this, ht);
3183
3760
  }
3184
3761
  set bubble(e) {
3185
- u(this, Be, e);
3762
+ u(this, ht, e);
3186
3763
  }
3187
3764
  get seen() {
3188
- return p(this, De);
3765
+ return p(this, ut);
3189
3766
  }
3190
3767
  set seen(e) {
3191
- u(this, De, e);
3768
+ u(this, ut, e);
3192
3769
  }
3193
3770
  get mobile() {
3194
- return p(this, Re);
3771
+ return p(this, gt);
3195
3772
  }
3196
3773
  set mobile(e) {
3197
- u(this, Re, e);
3774
+ u(this, gt, e);
3198
3775
  }
3199
3776
  get msg() {
3200
- return Tt(this.messages);
3777
+ return ts(this.messages);
3201
3778
  }
3202
3779
  /** An explicit `.client`, else the page default. */
3203
3780
  get resolvedClient() {
3204
- return this.client ?? yt() ?? null;
3781
+ return this.client ?? Vt() ?? null;
3205
3782
  }
3206
3783
  /** The open conversation's id, or null for a new chat. */
3207
3784
  get chatId() {
@@ -3211,18 +3788,55 @@ let d = (dt = class extends ft {
3211
3788
  get thread() {
3212
3789
  return this.msgs;
3213
3790
  }
3791
+ /** `format`, falling back to the default for anything unknown. */
3792
+ /** `docsets` as a clean list of ids. */
3793
+ get docsetIds() {
3794
+ const e = this.docsets, t = Array.isArray(e) ? e : String(e ?? "").split(/[\s,]+/);
3795
+ return [...new Set(t.map((s) => String(s).trim()).filter(Boolean))];
3796
+ }
3797
+ /** The files this chat keeps on the service. */
3798
+ get attachments() {
3799
+ return this.savedFiles;
3800
+ }
3801
+ get formatLevel() {
3802
+ return ["raw", "plain", "advanced", "rich"].includes(this.format) ? this.format : "advanced";
3803
+ }
3214
3804
  /** The loaded chat list. */
3215
3805
  get chats() {
3216
3806
  return this.chatList;
3217
3807
  }
3808
+ /**
3809
+ * Every setting in one object, keyed by property name:
3810
+ *
3811
+ * chat.config = { client, mode: "rag", format: "rich", retrieval: [...], chatId: "…" };
3812
+ *
3813
+ * Unknown keys are ignored. `chatId` opens that chat; reading `config`
3814
+ * returns the current settings with `chatId` as the open chat.
3815
+ */
3218
3816
  set config(e) {
3817
+ if (!e) return;
3219
3818
  const t = this;
3220
- for (const i of st)
3221
- e && i in e && (t[i] = e[i]);
3819
+ "client" in e && (this.client = e.client ?? null);
3820
+ for (const s of Lt)
3821
+ s in e && (t[s] = e[s]);
3822
+ e.chatId && e.chatId !== this.activeId && (this.hasUpdated ? this.openChat(e.chatId) : this.chatIdAttr = e.chatId);
3823
+ }
3824
+ /**
3825
+ * Changes settings on the fly. Only the keys you pass change; the chat keeps
3826
+ * its conversation and re-renders in place. Returns the element, so calls chain.
3827
+ *
3828
+ * chat.configure({ format: "rich" }).configure({ theme: "dark" });
3829
+ */
3830
+ configure(e) {
3831
+ return this.config = e, this;
3222
3832
  }
3223
3833
  get config() {
3224
3834
  const e = this;
3225
- return Object.fromEntries(st.map((t) => [t, e[t]]));
3835
+ return {
3836
+ client: this.client,
3837
+ chatId: this.activeId ?? "",
3838
+ ...Object.fromEntries(Lt.map((t) => [t, e[t]]))
3839
+ };
3226
3840
  }
3227
3841
  // ── lifecycle ─────────────────────────────────────────────
3228
3842
  connectedCallback() {
@@ -3238,7 +3852,7 @@ let d = (dt = class extends ft {
3238
3852
  const t = this.retrieval;
3239
3853
  this.retrieval = t && typeof t == "object" ? [t] : [];
3240
3854
  }
3241
- e.has("params") && (!this.params || typeof this.params != "object") && (this.params = {}), e.has("metadata") && (!this.metadata || typeof this.metadata != "object") && (this.metadata = {}), e.has("sidebar") && this.sidebar !== void 0 && (this.sidebarOpen = this.sidebar), this.embed === "launcher" && this.greetingBubble && !this.bubbleScheduled && (this.bubbleScheduled = !0, this.later(() => {
3855
+ e.has("params") && (!this.params || typeof this.params != "object") && (this.params = {}), e.has("metadata") && (!this.metadata || typeof this.metadata != "object") && (this.metadata = {}), e.has("sidebar") && (this.sidebar === "open" ? this.sidebarOpen = !0 : this.sidebar === "closed" || this.sidebar === "none" ? this.sidebarOpen = !1 : this.width && (this.sidebarOpen = this.docked)), this.embed === "launcher" && this.greetingBubble && !this.bubbleScheduled && (this.bubbleScheduled = !0, this.later(() => {
3242
3856
  !this.isOpen && !this.seen && (this.bubble = !0);
3243
3857
  }, 1200));
3244
3858
  }
@@ -3248,70 +3862,70 @@ let d = (dt = class extends ft {
3248
3862
  updated() {
3249
3863
  var t;
3250
3864
  const e = this.renderRoot.querySelector(".root");
3251
- if (e !== this.observed && ((t = this.observer) == null || t.disconnect(), this.observed = e, e && typeof ResizeObserver < "u" && (this.observer ?? (this.observer = new ResizeObserver(([i]) => {
3252
- const s = Math.round(i.contentRect.width);
3253
- s !== this.width && (this.width = s, this.sidebarOpen === null && (this.sidebarOpen = this.sidebar ?? this.docked));
3254
- })), this.observer.observe(e))), this.sidebarOpen && this.listState === "idle" && this.resolvedClient && this.loadChats(), this.focusNext) {
3255
- const i = this.renderRoot.querySelector(
3865
+ if (e !== this.observed && ((t = this.observer) == null || t.disconnect(), this.observed = e, e && typeof ResizeObserver < "u" && (this.observer ?? (this.observer = new ResizeObserver(([s]) => {
3866
+ const i = Math.round(s.contentRect.width);
3867
+ i !== this.width && (this.width = i, this.sidebarOpen === null && (this.sidebarOpen = this.sidebar === "auto" && this.docked));
3868
+ })), this.observer.observe(e))), this.sidebarOpen && this.listState === "idle" && this.resolvedClient && this.loadChats(), this.pendingChatId && this.resolvedClient && this.openChat(this.pendingChatId), this.focusNext) {
3869
+ const s = this.renderRoot.querySelector(
3256
3870
  this.focusNext
3257
3871
  );
3258
- this.focusNext = "", i && (i.focus(), "select" in i && i.tagName === "INPUT" && i.select());
3872
+ this.focusNext = "", s && (s.focus(), "select" in s && s.tagName === "INPUT" && s.select());
3259
3873
  }
3260
3874
  }
3261
3875
  later(e, t) {
3262
- const i = setTimeout(() => {
3263
- this.timers.delete(i), e();
3876
+ const s = setTimeout(() => {
3877
+ this.timers.delete(s), e();
3264
3878
  }, t);
3265
- this.timers.add(i);
3879
+ this.timers.add(s);
3266
3880
  }
3267
3881
  emit(e, t) {
3268
3882
  this.dispatchEvent(new CustomEvent(e, { detail: t, bubbles: !0, composed: !0 }));
3269
3883
  }
3270
3884
  get docked() {
3271
- return this.embed === "page" && this.width >= Rt;
3885
+ return this.embed === "page" && this.width >= Ss;
3272
3886
  }
3273
3887
  get panelDocked() {
3274
- const e = this.docked && this.sidebarOpen ? Dt : 0;
3275
- return this.width - e >= Ut;
3888
+ const e = this.docked && this.sidebarOpen ? Ts : 0;
3889
+ return this.width - e >= Is;
3276
3890
  }
3277
3891
  // ── public API ────────────────────────────────────────────
3278
3892
  /** Starts a new, empty conversation. */
3279
3893
  newChat() {
3280
- this.halt(), this.activeId = null, this.chatTitle = "", this.bookmarked = !1, this.msgs = [], this.threadError = "", this.resetViewState(), this.focusNext = "textarea.input";
3894
+ this.halt(), this.pendingChatId = "", this.savedFiles = [], this.loadingThread = !1, this.activeId = null, this.chatTitle = "", this.bookmarked = !1, this.msgs = [], this.threadError = "", this.resetViewState(), this.focusNext = "textarea.input";
3281
3895
  }
3282
3896
  /** Opens a saved conversation. */
3283
3897
  async openChat(e) {
3284
3898
  const t = this.resolvedClient;
3285
3899
  if (!e) return;
3286
- this.halt();
3287
- const i = this.chatList.find((a) => a._id === e);
3288
- if (this.activeId = e, this.chatTitle = (i == null ? void 0 : i.title) ?? "", this.bookmarked = !!(i != null && i.bookmarked), this.msgs = [], this.threadError = "", this.resetViewState(), !t) {
3289
- this.threadError = this.msg.errNoClient;
3900
+ this.halt(), this.savedFiles = [];
3901
+ const s = this.chatList.find((a) => a._id === e);
3902
+ if (this.activeId = e, this.chatTitle = (s == null ? void 0 : s.title) ?? "", this.bookmarked = !!(s != null && s.bookmarked), this.msgs = [], this.threadError = "", this.resetViewState(), !t) {
3903
+ this.pendingChatId = e, this.loadingThread = !0;
3290
3904
  return;
3291
3905
  }
3292
- const s = ++this.run;
3293
- this.loadingThread = !0;
3906
+ const i = ++this.run;
3907
+ this.pendingChatId = "", this.loadingThread = !0;
3294
3908
  try {
3295
3909
  const a = await t.llm.call("get_chat", {
3296
3910
  _id: e
3297
3911
  });
3298
- if (s !== this.run) return;
3299
- this.chatTitle = (a == null ? void 0 : a.title) ?? "", this.bookmarked = !!(a != null && a.bookmarked), this.msgs = ((a == null ? void 0 : a.messages) ?? []).filter((o) => o && (o.role === "user" || o.role === "assistant")).map((o) => this.fromServer(o)), this.upsertChat({ ...i, ...a, _id: e }), this.stick = !0, this.scrollToBottom();
3912
+ if (i !== this.run) return;
3913
+ this.chatTitle = (a == null ? void 0 : a.title) ?? "", this.bookmarked = !!(a != null && a.bookmarked), this.msgs = ((a == null ? void 0 : a.messages) ?? []).filter((r) => r && (r.role === "user" || r.role === "assistant")).map((r) => this.fromServer(r)), this.savedFiles = Dt(a == null ? void 0 : a.attachments), this.upsertChat({ ...s, ...a, _id: e }), this.stick = !0, this.scrollToBottom();
3300
3914
  } catch (a) {
3301
- if (s !== this.run) return;
3302
- lt(a) ? (this.chatList = this.chatList.filter((o) => o._id !== e), this.newChat(), this.showToast(this.msg.errNotFound)) : this.threadError = this.msg.errLoad;
3915
+ if (i !== this.run) return;
3916
+ Bt(a) ? (this.chatList = this.chatList.filter((r) => r._id !== e), this.newChat(), this.showToast(this.msg.errNotFound)) : this.threadError = this.msg.errLoad;
3303
3917
  } finally {
3304
- s === this.run && (this.loadingThread = !1);
3918
+ i === this.run && (this.loadingThread = !1);
3305
3919
  }
3306
3920
  }
3307
3921
  /** Sends a message; with no argument, sends the composer's text. */
3308
3922
  async send(e) {
3309
3923
  const t = (typeof e == "string" ? e : this.draft).trim();
3310
3924
  if (!t || this.busy) return;
3311
- const i = this.files;
3925
+ const s = this.files;
3312
3926
  this.draft = "", this.files = [];
3313
- const s = this.renderRoot.querySelector("textarea.input");
3314
- s && (s.style.height = "auto"), await this.runTurn(this.userMessage(t, i));
3927
+ const i = this.renderRoot.querySelector("textarea.input");
3928
+ i && (i.style.height = "auto"), await this.runTurn(this.userMessage(t, s));
3315
3929
  }
3316
3930
  /** Stops waiting for, or revealing, the current reply. */
3317
3931
  stop() {
@@ -3321,57 +3935,57 @@ let d = (dt = class extends ft {
3321
3935
  }
3322
3936
  /** Downloads the open conversation, or copies it as Markdown. */
3323
3937
  exportChat(e = "md") {
3324
- var M;
3938
+ var L;
3325
3939
  if (!this.msgs.length) return;
3326
3940
  this.menuOpen = !1;
3327
- const t = this.chatTitle || this.msg.untitled, i = (k) => k.role === "user" ? this.msg.you : this.assistantName, s = (k) => new Date(k || Date.now()).toLocaleString(), a = (k) => k.sources.map((L, ut) => {
3328
- const Ue = Ke(L, ut + 1);
3329
- return `[${Ue.n}] ${Ue.title}${Ue.path ? ` — ${Ue.path}` : ""}`;
3330
- }), o = (k) => (k.attachments ?? []).map((L) => L.name);
3331
- let l, c = "text/markdown", x = "md";
3332
- if (e === "json" ? (l = JSON.stringify(
3941
+ const t = this.chatTitle || this.msg.untitled, s = (x) => x.role === "user" ? this.msg.you : this.assistantName, i = (x) => new Date(x || Date.now()).toLocaleString(), a = (x) => x.sources.map((S, $) => {
3942
+ const A = ft(S, $ + 1);
3943
+ return `[${A.n}] ${A.title}${A.path ? ` — ${A.path}` : ""}`;
3944
+ }), r = (x) => (x.attachments ?? []).map((S) => S.name);
3945
+ let c, l = "text/markdown", f = "md";
3946
+ if (e === "json" ? (c = JSON.stringify(
3333
3947
  {
3334
3948
  exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
3335
3949
  id: this.activeId,
3336
3950
  title: t,
3337
3951
  mode: this.mode,
3338
3952
  bookmarked: this.bookmarked,
3339
- messages: this.msgs.map((k) => ({
3340
- role: k.role,
3341
- text: k.content,
3342
- at: new Date(k.at || Date.now()).toISOString(),
3343
- bookmarked: k.bookmarked,
3344
- attachments: o(k),
3345
- sources: a(k)
3953
+ messages: this.msgs.map((x) => ({
3954
+ role: x.role,
3955
+ text: x.content,
3956
+ at: new Date(x.at || Date.now()).toISOString(),
3957
+ bookmarked: x.bookmarked,
3958
+ attachments: r(x),
3959
+ sources: a(x)
3346
3960
  }))
3347
3961
  },
3348
3962
  null,
3349
3963
  2
3350
- ), c = "application/json", x = "json") : e === "txt" ? (l = `${t}
3964
+ ), l = "application/json", f = "json") : e === "txt" ? (c = `${t}
3351
3965
  ${"=".repeat(t.length)}
3352
3966
 
3353
3967
  ` + this.msgs.map(
3354
- (k) => [
3355
- `${i(k)} · ${s(k.at)}`,
3356
- o(k).length ? `Attachments: ${o(k).join(", ")}` : "",
3357
- k.content,
3358
- a(k).length ? `Sources:
3359
- ${a(k).join(`
3968
+ (x) => [
3969
+ `${s(x)} · ${i(x.at)}`,
3970
+ r(x).length ? `Attachments: ${r(x).join(", ")}` : "",
3971
+ x.content,
3972
+ a(x).length ? `Sources:
3973
+ ${a(x).join(`
3360
3974
  `)}` : ""
3361
3975
  ].filter(Boolean).join(`
3362
3976
  `)
3363
3977
  ).join(`
3364
3978
 
3365
- `), c = "text/plain", x = "txt") : l = `# ${t}
3979
+ `), l = "text/plain", f = "txt") : c = `# ${t}
3366
3980
 
3367
3981
  ` + this.msgs.map(
3368
- (k) => [
3369
- `### ${i(k)} · ${s(k.at)}`,
3370
- o(k).length ? `Attachments: ${o(k).join(", ")}` : "",
3371
- k.content,
3372
- a(k).length ? `**Sources**
3982
+ (x) => [
3983
+ `### ${s(x)} · ${i(x.at)}`,
3984
+ r(x).length ? `Attachments: ${r(x).join(", ")}` : "",
3985
+ x.content,
3986
+ a(x).length ? `**Sources**
3373
3987
 
3374
- ${a(k).map((L) => `- ${L}`).join(`
3988
+ ${a(x).map((S) => `- ${S}`).join(`
3375
3989
  `)}` : ""
3376
3990
  ].filter(Boolean).join(`
3377
3991
 
@@ -3382,12 +3996,12 @@ ${a(k).map((L) => `- ${L}`).join(`
3382
3996
 
3383
3997
  `) + `
3384
3998
  `, this.emit("singlebase-chat-export", { chatId: this.activeId, format: e }), e === "copy") {
3385
- (M = navigator.clipboard) == null || M.writeText(l).catch(() => {
3999
+ (L = navigator.clipboard) == null || L.writeText(c).catch(() => {
3386
4000
  }), this.showToast(this.msg.copiedMarkdown);
3387
4001
  return;
3388
4002
  }
3389
- const O = `${t.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "chat"}-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.${x}`, S = URL.createObjectURL(new Blob([l], { type: c })), b = document.createElement("a");
3390
- b.href = S, b.download = O, document.body.appendChild(b), b.click(), b.remove(), setTimeout(() => URL.revokeObjectURL(S), 2e3), this.showToast(z(this.msg.exported, { name: O }));
4003
+ const C = `${t.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "chat"}-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.${f}`, T = URL.createObjectURL(new Blob([c], { type: l })), w = document.createElement("a");
4004
+ w.href = T, w.download = C, document.body.appendChild(w), w.click(), w.remove(), setTimeout(() => URL.revokeObjectURL(T), 2e3), this.showToast(_(this.msg.exported, { name: C }));
3391
4005
  }
3392
4006
  /** Inline and launcher: fill the window. */
3393
4007
  expand() {
@@ -3407,7 +4021,7 @@ ${a(k).map((L) => `- ${L}`).join(`
3407
4021
  // ── turns ─────────────────────────────────────────────────
3408
4022
  userMessage(e, t = []) {
3409
4023
  return {
3410
- key: Je(),
4024
+ key: bt(),
3411
4025
  id: null,
3412
4026
  role: "user",
3413
4027
  content: e,
@@ -3422,23 +4036,37 @@ ${a(k).map((L) => `- ${L}`).join(`
3422
4036
  systemPrompt() {
3423
4037
  return [
3424
4038
  this.systemMessage,
3425
- nt[this.mode] ?? nt.chat,
3426
- this.followups ? Ht : ""
4039
+ Rt[this.mode] ?? Rt.chat,
4040
+ As[this.formatLevel],
4041
+ this.followups ? js : ""
3427
4042
  ].filter(Boolean).join(`
3428
4043
 
3429
4044
  `);
3430
4045
  }
3431
4046
  payloadFor(e) {
3432
4047
  const t = { message: e.content, format: "markdown" };
3433
- this.activeId ? t._id = this.activeId : (t.title = Lt(e.content), t.system_message = this.systemPrompt()), this.model && (t.model = this.model), Object.keys(this.params ?? {}).length && (t.params = this.params);
3434
- const i = (e.attachments ?? []).map((a) => a.name);
3435
- (Object.keys(this.metadata ?? {}).length || i.length) && (t.metadata = { ...this.metadata, ...i.length ? { attachments: i } : {} });
3436
- const s = [...this.retrieval ?? [], ...Gt(e.attachments ?? [])];
3437
- return s.length && (t.retrieval = s), t;
4048
+ this.activeId ? t._id = this.activeId : (t.title = fs(e.content), t.system_message = this.systemPrompt()), t.mode = this.mode, this.model && (t.model = this.model), Object.keys(this.params ?? {}).length && (t.params = this.params);
4049
+ const s = e.attachments ?? [], i = this.attachmentsMode === "payload";
4050
+ i && s.length && (t.attachments = s.map((l) => ({
4051
+ type: "content",
4052
+ content: l.content,
4053
+ name: l.name,
4054
+ ...l.mime ? { mime: l.mime } : {},
4055
+ size: l.size,
4056
+ save_attachment: this.saveAttachments
4057
+ })));
4058
+ const a = i ? [] : s.map((l) => l.name);
4059
+ (Object.keys(this.metadata ?? {}).length || a.length) && (t.metadata = { ...this.metadata, ...a.length ? { attachments: a } : {} });
4060
+ const r = this.docsetIds, c = [
4061
+ ...r.length ? [{ source: "docset", ids: r }] : [],
4062
+ ...this.retrieval ?? [],
4063
+ ...i ? [] : Bs(s)
4064
+ ];
4065
+ return c.length && (t.retrieval = c), t;
3438
4066
  }
3439
4067
  async runTurn(e) {
3440
4068
  const t = {
3441
- key: Je(),
4069
+ key: bt(),
3442
4070
  id: null,
3443
4071
  role: "assistant",
3444
4072
  content: "",
@@ -3449,66 +4077,90 @@ ${a(k).map((L) => `- ${L}`).join(`
3449
4077
  phase: "pending"
3450
4078
  };
3451
4079
  this.msgs = [...this.msgs, e, t], this.busy = !0, this.panel = null, this.stick = !0, this.scrollToBottom(), this.emit("singlebase-chat-send", { chatId: this.activeId, text: e.content });
3452
- const i = this.resolvedClient;
3453
- if (!i) {
4080
+ const s = this.resolvedClient;
4081
+ if (!s) {
3454
4082
  this.failTurn(t, this.msg.errNoClient, "NO_CLIENT"), this.busy = !1;
3455
4083
  return;
3456
4084
  }
3457
- const s = ++this.run, a = new AbortController();
4085
+ const i = ++this.run, a = new AbortController();
3458
4086
  this.abort = a;
3459
- const o = !this.activeId, l = this.payloadFor(e);
4087
+ const r = !this.activeId;
4088
+ let c = this.payloadFor(e);
4089
+ if (this.beforeSend) {
4090
+ let l;
4091
+ try {
4092
+ l = await this.beforeSend(c, { chatId: this.activeId, isNew: r, message: e });
4093
+ } catch (b) {
4094
+ l = b;
4095
+ }
4096
+ if (i !== this.run) return;
4097
+ if (l === !1) {
4098
+ this.msgs = this.msgs.filter((b) => b !== e && b !== t), this.draft = e.content, this.busy = !1, this.abort = null;
4099
+ return;
4100
+ }
4101
+ if (!(!!l && typeof l == "object" && typeof l.message == "string") || !l.message.trim()) {
4102
+ console.error(
4103
+ "[singlebase-chat] beforeSend must return the request object (with a message) or false to cancel; the message was not sent.",
4104
+ l
4105
+ ), this.failTurn(t, this.msg.errGeneric, "BEFORE_SEND_INVALID"), this.busy = !1, this.abort = null;
4106
+ return;
4107
+ }
4108
+ c = l;
4109
+ }
3460
4110
  try {
3461
- const c = await i.llm.call("chat", l, { signal: a.signal }), x = (c == null ? void 0 : c._id) || (c == null ? void 0 : c.chat_id) || this.activeId;
3462
- if (o && x && this.upsertChat({
3463
- _id: x,
3464
- title: (c == null ? void 0 : c.title) || l.title,
3465
- bookmarked: !!(c != null && c.bookmarked),
4111
+ const l = await s.llm.call("chat", c, { signal: a.signal }), f = (l == null ? void 0 : l._id) || (l == null ? void 0 : l.chat_id) || this.activeId;
4112
+ if (r && f && this.upsertChat({
4113
+ _id: f,
4114
+ title: (l == null ? void 0 : l.title) || c.title,
4115
+ bookmarked: !!(l != null && l.bookmarked),
3466
4116
  _modified_at: (/* @__PURE__ */ new Date()).toISOString()
3467
- }), s !== this.run) return;
3468
- x && (this.activeId = x), o ? (this.chatTitle = (c == null ? void 0 : c.title) || l.title, this.bookmarked = !!(c != null && c.bookmarked)) : x && this.touchChat(x);
3469
- const f = (c == null ? void 0 : c.message) ?? {}, O = typeof f.content == "string" ? f.content : (c == null ? void 0 : c.json) !== void 0 ? JSON.stringify(c.json, null, 2) : "", { text: S, followups: b } = tt(O);
3470
- e.id = f.reply_to ?? null, Object.assign(t, {
3471
- id: f._id ?? null,
3472
- content: S,
3473
- sources: Array.isArray(f.sources) ? f.sources : [],
3474
- followups: this.followups ? b : [],
3475
- execTime: typeof f.exec_time == "number" ? f.exec_time : void 0,
3476
- model: f.model,
4117
+ }), i !== this.run) return;
4118
+ f && (this.activeId = f), r && (this.chatTitle = (l == null ? void 0 : l.title) || c.title, this.bookmarked = !!(l != null && l.bookmarked));
4119
+ const b = (l == null ? void 0 : l.message) ?? {}, C = typeof b.content == "string" ? b.content : (l == null ? void 0 : l.json) !== void 0 ? JSON.stringify(l.json, null, 2) : "", { text: T, followups: w } = zt(C);
4120
+ e.id = b.reply_to ?? null, this.applyAttachmentResults(l == null ? void 0 : l.attachments), Object.assign(t, {
4121
+ id: b._id ?? null,
4122
+ content: T,
4123
+ sources: Array.isArray(b.sources) ? b.sources : [],
4124
+ followups: w,
4125
+ execTime: typeof b.exec_time == "number" ? b.exec_time : void 0,
4126
+ model: b.model,
3477
4127
  at: Date.now()
3478
- }), this.emit("singlebase-chat-response", { chatId: x, message: t }), await this.reveal(t, s), o && x && this.autoTitle && this.retitle(x, e.content, t.content);
3479
- } catch (c) {
3480
- if (s !== this.run) return;
3481
- const x = lt(c);
3482
- x && (this.chatList = this.chatList.filter((f) => f._id !== this.activeId), this.activeId = null), this.failTurn(t, x ? this.msg.errNotFound : this.msg.errGeneric, Wt(c));
4128
+ }), this.emit("singlebase-chat-response", { chatId: f, message: t }), await this.reveal(t, i), r && f && this.autoTitle && this.retitle(f, e.content, t.content);
4129
+ } catch (l) {
4130
+ if (i !== this.run) return;
4131
+ const f = Bt(l);
4132
+ f && (this.chatList = this.chatList.filter((T) => T._id !== this.activeId), this.activeId = null);
4133
+ const b = Rs(l), C = f ? this.msg.errNotFound : b === "KB_SOURCE_REQUIRED" ? this.msg.errKbSource : this.msg.errGeneric;
4134
+ this.failTurn(t, C, b);
3483
4135
  } finally {
3484
- s === this.run && (this.busy = !1, this.abort = null, this.stick && this.scrollToBottom());
4136
+ i === this.run && (this.busy = !1, this.abort = null, this.stick && this.scrollToBottom());
3485
4137
  }
3486
4138
  }
3487
- failTurn(e, t, i) {
3488
- e.phase = "error", e.error = t, this.msgs = [...this.msgs], this.emit("singlebase-chat-error", { chatId: this.activeId, code: i, message: t });
4139
+ failTurn(e, t, s) {
4140
+ e.phase = "error", e.error = t, this.msgs = [...this.msgs], this.emit("singlebase-chat-error", { chatId: this.activeId, code: s, message: t });
3489
4141
  }
3490
4142
  /**
3491
4143
  * The service answers in one piece; this reveals it progressively so it
3492
4144
  * reads like a stream. Capped at about a second and a half.
3493
4145
  */
3494
4146
  reveal(e, t) {
3495
- const i = e.content.length, s = () => {
4147
+ const s = e.content.length, i = () => {
3496
4148
  e.phase = "done", this.msgs = [...this.msgs], this.arrivedKey = e.key, this.later(() => {
3497
4149
  this.arrivedKey === e.key && (this.arrivedKey = "");
3498
- }, Pt), this.stick ? this.scrollToBottom() : this.showJump = !0;
4150
+ }, Ls), this.stick ? this.scrollToBottom() : this.showJump = !0;
3499
4151
  };
3500
- if (!i || qt())
3501
- return s(), Promise.resolve();
3502
- const a = e.content, o = Math.max(4, Math.ceil(i / 90));
3503
- let l = 0;
3504
- return e.phase = "streaming", e.content = "", new Promise((c) => {
4152
+ if (!s || Es())
4153
+ return i(), Promise.resolve();
4154
+ const a = e.content, r = Math.max(4, Math.ceil(s / 90));
4155
+ let c = 0;
4156
+ return e.phase = "streaming", e.content = "", new Promise((l) => {
3505
4157
  this.revealTimer = setInterval(() => {
3506
4158
  if (t !== this.run) {
3507
- clearInterval(this.revealTimer), c();
4159
+ clearInterval(this.revealTimer), l();
3508
4160
  return;
3509
4161
  }
3510
- if (l = Math.min(i, l + o), e.content = a.slice(0, l), l >= i) {
3511
- clearInterval(this.revealTimer), s(), c();
4162
+ if (c = Math.min(s, c + r), e.content = a.slice(0, c), c >= s) {
4163
+ clearInterval(this.revealTimer), i(), l();
3512
4164
  return;
3513
4165
  }
3514
4166
  this.msgs = [...this.msgs], this.stick && this.scrollToBottom();
@@ -3520,23 +4172,23 @@ ${a(k).map((L) => `- ${L}`).join(`
3520
4172
  var e;
3521
4173
  this.run++, (e = this.abort) == null || e.abort(), this.abort = null, clearInterval(this.revealTimer), this.busy = !1;
3522
4174
  }
3523
- async retitle(e, t, i) {
3524
- const s = this.resolvedClient;
3525
- if (!(!s || this.renamed.has(e)))
4175
+ async retitle(e, t, s) {
4176
+ const i = this.resolvedClient;
4177
+ if (!(!i || this.renamed.has(e)))
3526
4178
  try {
3527
- const a = await s.llm.call("generate", {
4179
+ const a = await i.llm.call("generate", {
3528
4180
  user_input: `user: ${t}
3529
- assistant: ${i.slice(0, 1500)}`,
4181
+ assistant: ${s.slice(0, 1500)}`,
3530
4182
  custom_instructions: "Write a concise title (3–6 words, sentence case, no quotes, no trailing punctuation) for this conversation.",
3531
4183
  format: "text"
3532
- }), o = jt(a == null ? void 0 : a.result);
3533
- if (!o || this.renamed.has(e)) return;
3534
- await s.llm.call("update_chat", { _id: e, title: o }), this.applyTitle(e, o, !0);
4184
+ }), r = bs(a == null ? void 0 : a.result);
4185
+ if (!r || this.renamed.has(e)) return;
4186
+ await i.llm.call("update_chat", { _id: e, title: r }), this.applyTitle(e, r, !0);
3535
4187
  } catch {
3536
4188
  }
3537
4189
  }
3538
- applyTitle(e, t, i) {
3539
- this.chatList = this.chatList.map((s) => s._id === e ? { ...s, title: t } : s), this.activeId === e && (this.chatTitle = t), this.emit("singlebase-chat-title", { chatId: e, title: t, auto: i });
4190
+ applyTitle(e, t, s) {
4191
+ this.chatList = this.chatList.map((i) => i._id === e ? { ...i, title: t } : i), this.activeId === e && (this.chatTitle = t), this.emit("singlebase-chat-title", { chatId: e, title: t, auto: s });
3540
4192
  }
3541
4193
  /**
3542
4194
  * Enter and blur both land here. Saving on Enter directly (not via blur())
@@ -3549,28 +4201,28 @@ assistant: ${i.slice(0, 1500)}`,
3549
4201
  this.renamingId === e && (this.renamingId = "", this.renameChat(e, t));
3550
4202
  }
3551
4203
  async renameChat(e, t) {
3552
- var a, o;
3553
- const i = t.trim().slice(0, 80), s = ((a = this.chatList.find((l) => l._id === e)) == null ? void 0 : a.title) ?? this.chatTitle;
3554
- if (!(!i || i === s)) {
3555
- this.renamed.add(e), this.applyTitle(e, i, !1);
4204
+ var a, r;
4205
+ const s = t.trim().slice(0, 80), i = ((a = this.chatList.find((c) => c._id === e)) == null ? void 0 : a.title) ?? this.chatTitle;
4206
+ if (!(!s || s === i)) {
4207
+ this.renamed.add(e), this.applyTitle(e, s, !1);
3556
4208
  try {
3557
- await ((o = this.resolvedClient) == null ? void 0 : o.llm.call("update_chat", { _id: e, title: i }));
4209
+ await ((r = this.resolvedClient) == null ? void 0 : r.llm.call("update_chat", { _id: e, title: s }));
3558
4210
  } catch {
3559
- this.applyTitle(e, s ?? "", !1), this.showToast(this.msg.errGeneric);
4211
+ this.applyTitle(e, i ?? "", !1), this.showToast(this.msg.errGeneric);
3560
4212
  }
3561
4213
  }
3562
4214
  }
3563
4215
  fromServer(e) {
3564
- const t = e.role === "assistant", { text: i, followups: s } = t ? tt(String(e.content ?? "")) : { text: String(e.content ?? ""), followups: [] };
4216
+ const t = e.role === "assistant", { text: s, followups: i } = t ? zt(String(e.content ?? "")) : { text: String(e.content ?? ""), followups: [] };
3565
4217
  return {
3566
- key: Je(),
4218
+ key: bt(),
3567
4219
  id: e._id ?? null,
3568
4220
  role: t ? "assistant" : "user",
3569
- content: i,
4221
+ content: s,
3570
4222
  at: Date.parse(e._created_at ?? "") || 0,
3571
4223
  bookmarked: !!e.bookmarked,
3572
4224
  sources: Array.isArray(e.sources) ? e.sources : [],
3573
- followups: this.followups ? s : [],
4225
+ followups: i,
3574
4226
  phase: "done",
3575
4227
  execTime: typeof e.exec_time == "number" ? e.exec_time : void 0,
3576
4228
  model: e.model
@@ -3589,57 +4241,96 @@ assistant: ${i.slice(0, 1500)}`,
3589
4241
  }
3590
4242
  }
3591
4243
  }
4244
+ /**
4245
+ * A new chat goes on top. A chat already in the list is updated where it is,
4246
+ * keeping its dates, so opening or using a chat never reorders the list; the
4247
+ * next load from the server brings the fresh order.
4248
+ */
3592
4249
  upsertChat(e) {
3593
- const t = this.chatList.filter((s) => s._id !== e._id), i = this.chatList.find((s) => s._id === e._id);
3594
- this.chatList = [{ ...i, ...e }, ...t];
3595
- }
3596
- touchChat(e) {
3597
- const t = this.chatList.find((i) => i._id === e);
3598
- t && this.upsertChat({ ...t, _modified_at: (/* @__PURE__ */ new Date()).toISOString() });
4250
+ const t = this.chatList.findIndex((a) => a._id === e._id);
4251
+ if (t < 0) {
4252
+ this.chatList = [e, ...this.chatList];
4253
+ return;
4254
+ }
4255
+ const s = this.chatList[t], i = [...this.chatList];
4256
+ i[t] = {
4257
+ ...s,
4258
+ ...e,
4259
+ _created_at: s._created_at ?? e._created_at,
4260
+ _modified_at: s._modified_at ?? e._modified_at
4261
+ }, this.chatList = i;
3599
4262
  }
3600
4263
  // ── actions ───────────────────────────────────────────────
3601
4264
  resetViewState() {
3602
4265
  this.panel = null, this.menuOpen = !1, this.editingKey = "", this.editingTitle = !1, this.showJump = !1, this.retrievalOpen = /* @__PURE__ */ new Set(), this.sidebarOpen && !this.docked && (this.sidebarOpen = !1);
3603
4266
  }
3604
4267
  async deleteOnServer(e) {
3605
- const t = this.resolvedClient, i = this.activeId;
3606
- if (!(!t || !i))
3607
- for (const s of e)
3608
- s && await t.llm.call("delete_chat_message", { _id: i, message_id: s }).catch(() => {
4268
+ const t = this.resolvedClient, s = this.activeId;
4269
+ if (!(!t || !s))
4270
+ for (const i of e)
4271
+ i && await t.llm.call("delete_chat_message", { _id: s, message_id: i }).catch(() => {
3609
4272
  });
3610
4273
  }
3611
4274
  async regenerate() {
3612
4275
  if (this.busy) return;
3613
- const e = this.msgs.map((s) => s.role).lastIndexOf("assistant"), t = this.msgs[e - 1];
4276
+ const e = this.msgs.map((i) => i.role).lastIndexOf("assistant"), t = this.msgs[e - 1];
3614
4277
  if (e < 1 || (t == null ? void 0 : t.role) !== "user") return;
3615
- const i = this.msgs.slice(e - 1);
3616
- this.msgs = this.msgs.slice(0, e - 1), await this.deleteOnServer(i.map((s) => s.id)), await this.runTurn(this.userMessage(t.content, t.attachments));
4278
+ const s = this.msgs.slice(e - 1);
4279
+ this.msgs = this.msgs.slice(0, e - 1), await this.deleteOnServer(s.map((i) => i.id)), await this.runTurn(this.userMessage(t.content, t.attachments));
3617
4280
  }
3618
4281
  async retry(e) {
3619
4282
  if (this.busy) return;
3620
- const t = this.msgs.indexOf(e), i = this.msgs[t - 1];
3621
- (i == null ? void 0 : i.role) === "user" && (this.msgs = this.msgs.slice(0, t - 1), await this.runTurn(this.userMessage(i.content, i.attachments)));
4283
+ const t = this.msgs.indexOf(e), s = this.msgs[t - 1];
4284
+ (s == null ? void 0 : s.role) === "user" && (this.msgs = this.msgs.slice(0, t - 1), await this.runTurn(this.userMessage(s.content, s.attachments)));
3622
4285
  }
3623
4286
  async saveEdit(e) {
3624
- const t = this.editDraft.trim(), i = this.msgs.indexOf(e);
3625
- if (this.editingKey = "", !t || i < 0 || this.busy) return;
3626
- const s = this.msgs.slice(i);
3627
- this.msgs = this.msgs.slice(0, i), await this.deleteOnServer(s.map((a) => a.id)), await this.runTurn(this.userMessage(t, e.attachments));
4287
+ const t = this.editDraft.trim(), s = this.msgs.indexOf(e);
4288
+ if (this.editingKey = "", !t || s < 0 || this.busy) return;
4289
+ const i = this.msgs.slice(s);
4290
+ this.msgs = this.msgs.slice(0, s), await this.deleteOnServer(i.map((a) => a.id)), await this.runTurn(this.userMessage(t, e.attachments));
4291
+ }
4292
+ toggleRaw(e) {
4293
+ const t = new Set(this.rawKeys);
4294
+ t.has(e) ? t.delete(e) : t.add(e), this.rawKeys = t;
4295
+ }
4296
+ /** Adds newly saved files, and says which ones the service couldn't read. */
4297
+ applyAttachmentResults(e) {
4298
+ if (!Array.isArray(e)) return;
4299
+ const t = Dt(e).filter((i) => !this.savedFiles.some((a) => a.id === i.id));
4300
+ t.length && (this.savedFiles = [...this.savedFiles, ...t]);
4301
+ const s = e.filter((i) => (i == null ? void 0 : i.status) === "failed").map((i) => String(i.name ?? "file"));
4302
+ s.length && this.showToast(_(this.msg.attachmentFailed, { name: s.join(", ") }));
4303
+ }
4304
+ /** Removes a file the service keeps on this chat. */
4305
+ async removeSavedFile(e) {
4306
+ var i;
4307
+ const t = this.activeId;
4308
+ if (!t) return;
4309
+ const s = this.savedFiles;
4310
+ this.savedFiles = s.filter((a) => a !== e);
4311
+ try {
4312
+ await ((i = this.resolvedClient) == null ? void 0 : i.llm.call("remove_chat_attachment", {
4313
+ _id: t,
4314
+ attachment_id: e.id
4315
+ }));
4316
+ } catch {
4317
+ this.activeId === t && (this.savedFiles = s), this.showToast(this.msg.errGeneric);
4318
+ }
3628
4319
  }
3629
4320
  copy(e, t) {
3630
- var i;
3631
- (i = navigator.clipboard) == null || i.writeText(t).catch(() => {
4321
+ var s;
4322
+ (s = navigator.clipboard) == null || s.writeText(t).catch(() => {
3632
4323
  }), this.copiedKey = e, this.later(() => {
3633
4324
  this.copiedKey === e && (this.copiedKey = "");
3634
4325
  }, 1400);
3635
4326
  }
3636
4327
  async toggleMessageBookmark(e) {
3637
- var i;
4328
+ var s;
3638
4329
  const t = this.activeId;
3639
4330
  if (!(!t || !e.id)) {
3640
4331
  e.bookmarked = !e.bookmarked, this.msgs = [...this.msgs], this.showToast(e.bookmarked ? this.msg.messageBookmarked : this.msg.bookmarkRemoved), this.emit("singlebase-chat-bookmark", { chatId: t, messageId: e.id, bookmarked: e.bookmarked });
3641
4332
  try {
3642
- await ((i = this.resolvedClient) == null ? void 0 : i.llm.call("bookmark_chat_message", {
4333
+ await ((s = this.resolvedClient) == null ? void 0 : s.llm.call("bookmark_chat_message", {
3643
4334
  _id: t,
3644
4335
  message_id: e.id,
3645
4336
  bookmarked: e.bookmarked
@@ -3650,28 +4341,28 @@ assistant: ${i.slice(0, 1500)}`,
3650
4341
  }
3651
4342
  }
3652
4343
  async toggleChatBookmark(e) {
3653
- var a, o;
3654
- const t = ((a = this.chatList.find((l) => l._id === e)) == null ? void 0 : a.bookmarked) ?? (e === this.activeId ? this.bookmarked : !1), i = !t, s = (l) => {
4344
+ var a, r;
4345
+ const t = ((a = this.chatList.find((c) => c._id === e)) == null ? void 0 : a.bookmarked) ?? (e === this.activeId ? this.bookmarked : !1), s = !t, i = (c) => {
3655
4346
  this.chatList = this.chatList.map(
3656
- (c) => c._id === e ? { ...c, bookmarked: l } : c
3657
- ), e === this.activeId && (this.bookmarked = l);
4347
+ (l) => l._id === e ? { ...l, bookmarked: c } : l
4348
+ ), e === this.activeId && (this.bookmarked = c);
3658
4349
  };
3659
- s(i), this.showToast(i ? this.msg.chatBookmarked : this.msg.chatUnbookmarked), this.emit("singlebase-chat-bookmark", { chatId: e, bookmarked: i });
4350
+ i(s), this.showToast(s ? this.msg.chatBookmarked : this.msg.chatUnbookmarked), this.emit("singlebase-chat-bookmark", { chatId: e, bookmarked: s });
3660
4351
  try {
3661
- await ((o = this.resolvedClient) == null ? void 0 : o.llm.call("bookmark_chat", { _id: e, bookmarked: i }));
4352
+ await ((r = this.resolvedClient) == null ? void 0 : r.llm.call("bookmark_chat", { _id: e, bookmarked: s }));
3662
4353
  } catch {
3663
- s(t), this.showToast(this.msg.errGeneric);
4354
+ i(t), this.showToast(this.msg.errGeneric);
3664
4355
  }
3665
4356
  }
3666
4357
  /** Removed at once; the server call waits out the undo window. */
3667
4358
  deleteMessage(e) {
3668
- var s;
3669
- const t = this.activeId, i = this.msgs.indexOf(e);
3670
- i < 0 || (this.msgs = this.msgs.filter((a) => a !== e), ((s = this.panel) == null ? void 0 : s.key) === e.key && (this.panel = null), this.showToast(this.msg.messageDeleted, {
4359
+ var i;
4360
+ const t = this.activeId, s = this.msgs.indexOf(e);
4361
+ s < 0 || (this.msgs = this.msgs.filter((a) => a !== e), ((i = this.panel) == null ? void 0 : i.key) === e.key && (this.panel = null), this.showToast(this.msg.messageDeleted, {
3671
4362
  undo: () => {
3672
4363
  if (this.activeId !== t) return;
3673
4364
  const a = [...this.msgs];
3674
- a.splice(i, 0, e), this.msgs = a;
4365
+ a.splice(s, 0, e), this.msgs = a;
3675
4366
  },
3676
4367
  commit: () => {
3677
4368
  var a;
@@ -3681,19 +4372,19 @@ assistant: ${i.slice(0, 1500)}`,
3681
4372
  }));
3682
4373
  }
3683
4374
  deleteChat(e) {
3684
- const t = this.chatList.findIndex((o) => o._id === e), i = this.chatList[t] ?? {
4375
+ const t = this.chatList.findIndex((r) => r._id === e), s = this.chatList[t] ?? {
3685
4376
  _id: e,
3686
4377
  title: this.chatTitle,
3687
4378
  bookmarked: this.bookmarked
3688
- }, s = e === this.activeId, a = s ? { title: this.chatTitle, bookmarked: this.bookmarked, msgs: this.msgs } : null;
3689
- this.chatList = this.chatList.filter((o) => o._id !== e), s && this.newChat(), this.showToast(this.msg.chatDeleted, {
4379
+ }, i = e === this.activeId, a = i ? { title: this.chatTitle, bookmarked: this.bookmarked, msgs: this.msgs } : null;
4380
+ this.chatList = this.chatList.filter((r) => r._id !== e), i && this.newChat(), this.showToast(this.msg.chatDeleted, {
3690
4381
  undo: () => {
3691
- const o = [...this.chatList];
3692
- o.splice(Math.max(0, t), 0, i), this.chatList = o, a && !this.activeId && !this.msgs.length && (this.activeId = e, this.chatTitle = a.title, this.bookmarked = a.bookmarked, this.msgs = a.msgs);
4382
+ const r = [...this.chatList];
4383
+ r.splice(Math.max(0, t), 0, s), this.chatList = r, a && !this.activeId && !this.msgs.length && (this.activeId = e, this.chatTitle = a.title, this.bookmarked = a.bookmarked, this.msgs = a.msgs);
3693
4384
  },
3694
4385
  commit: () => {
3695
- var o;
3696
- this.emit("singlebase-chat-delete", { chatId: e }), (o = this.resolvedClient) == null || o.llm.call("delete_chat", { _id: e }).catch(() => {
4386
+ var r;
4387
+ this.emit("singlebase-chat-delete", { chatId: e }), (r = this.resolvedClient) == null || r.llm.call("delete_chat", { _id: e }).catch(() => {
3697
4388
  });
3698
4389
  }
3699
4390
  });
@@ -3709,10 +4400,10 @@ assistant: ${i.slice(0, 1500)}`,
3709
4400
  // ── toasts ────────────────────────────────────────────────
3710
4401
  showToast(e, t = {}) {
3711
4402
  this.flushToast();
3712
- const i = { key: Date.now(), text: e, ...t };
3713
- this.toast = i, this.toastTimer = setTimeout(() => {
3714
- this.toast === i && this.flushToast();
3715
- }, Kt);
4403
+ const s = { key: Date.now(), text: e, ...t };
4404
+ this.toast = s, this.toastTimer = setTimeout(() => {
4405
+ this.toast === s && this.flushToast();
4406
+ }, Ms);
3716
4407
  }
3717
4408
  /** Ends the current toast, committing whatever it was holding back. */
3718
4409
  flushToast() {
@@ -3729,26 +4420,31 @@ assistant: ${i.slice(0, 1500)}`,
3729
4420
  async addFiles(e) {
3730
4421
  const t = Array.from(e ?? []);
3731
4422
  if (!t.length) return;
3732
- const i = [];
3733
- for (const s of t) {
3734
- if (this.files.length + i.length >= at) {
3735
- this.showToast(z(this.msg.tooManyFiles, { n: at }));
4423
+ const s = [];
4424
+ for (const i of t) {
4425
+ if (this.files.length + s.length >= At) {
4426
+ this.showToast(_(this.msg.tooManyFiles, { n: At }));
3736
4427
  break;
3737
4428
  }
3738
- if (!Ft.test(s.name) && !s.type.startsWith("text/")) {
3739
- this.showToast(z(this.msg.fileType, { name: s.name }));
4429
+ if (!Os.test(i.name) && !i.type.startsWith("text/")) {
4430
+ this.showToast(_(this.msg.fileType, { name: i.name }));
3740
4431
  continue;
3741
4432
  }
3742
- if (s.size > rt) {
4433
+ if (i.size > jt) {
3743
4434
  this.showToast(
3744
- z(this.msg.fileTooLarge, { name: s.name, size: Ve(rt) })
4435
+ _(this.msg.fileTooLarge, { name: i.name, size: kt(jt) })
3745
4436
  );
3746
4437
  continue;
3747
4438
  }
3748
- i.push({ name: s.name, size: s.size, content: await s.text() });
4439
+ s.push({
4440
+ name: i.name,
4441
+ size: i.size,
4442
+ content: await i.text(),
4443
+ ...i.type ? { mime: i.type } : {}
4444
+ });
3749
4445
  }
3750
- i.length && (this.files = [...this.files, ...i], this.emit("singlebase-chat-files", {
3751
- files: i.map(({ name: s, size: a }) => ({ name: s, size: a }))
4446
+ s.length && (this.files = [...this.files, ...s], this.emit("singlebase-chat-files", {
4447
+ files: s.map(({ name: i, size: a }) => ({ name: i, size: a }))
3752
4448
  }));
3753
4449
  }
3754
4450
  // ── scrolling ─────────────────────────────────────────────
@@ -3786,7 +4482,7 @@ assistant: ${i.slice(0, 1500)}`,
3786
4482
  // ── drag and drop ─────────────────────────────────────────
3787
4483
  onDragEnter(e) {
3788
4484
  var t;
3789
- !this.allowUpload || !Array.from(((t = e.dataTransfer) == null ? void 0 : t.types) ?? []).includes("Files") || (e.preventDefault(), this.dragging = !0);
4485
+ !this.allowUpload || !this.showComposer || Array.from(((t = e.dataTransfer) == null ? void 0 : t.types) ?? []).includes("Files") && (e.preventDefault(), this.dragging = !0);
3790
4486
  }
3791
4487
  onDragLeave(e) {
3792
4488
  e.currentTarget.contains(e.relatedTarget) || (this.dragging = !1);
@@ -3803,16 +4499,16 @@ assistant: ${i.slice(0, 1500)}`,
3803
4499
  this.embed === "inline" ? "inline boxed" : "",
3804
4500
  this.expanded ? "expanded boxed" : ""
3805
4501
  ].join(" ");
3806
- return r`<div class=${e} part="frame">${this.renderWorkspace()}</div>`;
4502
+ return o`<div class=${e} part="frame">${this.renderWorkspace()}</div>`;
3807
4503
  }
3808
4504
  renderLauncher() {
3809
4505
  const e = this.msg, t = [
3810
4506
  "frame launcher boxed",
3811
4507
  this.expanded ? "expanded" : "",
3812
4508
  this.mobile ? "full" : ""
3813
- ].join(" "), i = this.isOpen ? r`<div class=${t} role="dialog" aria-label=${this.assistantName} part="frame">
4509
+ ].join(" "), s = this.isOpen ? o`<div class=${t} role="dialog" aria-label=${this.assistantName} part="frame">
3814
4510
  ${this.renderWorkspace()}
3815
- </div>` : m, s = this.bubble && !this.isOpen ? r`<div class="bubble" part="bubble">
4511
+ </div>` : m, i = this.bubble && !this.isOpen ? o`<div class="bubble" part="bubble">
3816
4512
  <button type="button" class="bubble-text" @click=${() => this.open()}>
3817
4513
  ${this.bubbleText || e.bubbleText}
3818
4514
  </button>
@@ -3823,9 +4519,9 @@ assistant: ${i.slice(0, 1500)}`,
3823
4519
  title=${e.dismiss}
3824
4520
  @click=${() => this.bubble = !1}
3825
4521
  >
3826
- ${y.close()}
4522
+ ${k.close()}
3827
4523
  </button>
3828
- </div>` : m, o = this.isOpen && (this.expanded || this.mobile) ? m : r`<button
4524
+ </div>` : m, r = this.isOpen && (this.expanded || this.mobile) ? m : o`<button
3829
4525
  type="button"
3830
4526
  class="launcher-btn"
3831
4527
  part="launcher"
@@ -3833,23 +4529,23 @@ assistant: ${i.slice(0, 1500)}`,
3833
4529
  aria-expanded=${this.isOpen ? "true" : "false"}
3834
4530
  @click=${() => this.isOpen ? this.close() : this.open()}
3835
4531
  >
3836
- ${this.isOpen ? y.chevronDown() : y.chat()}
3837
- ${this.unreadBadge && !this.seen && !this.isOpen ? r`<span class="badge"></span>` : m}
4532
+ ${this.isOpen ? k.chevronDown() : k.chat()}
4533
+ ${this.unreadBadge && !this.seen && !this.isOpen ? o`<span class="badge"></span>` : m}
3838
4534
  </button>`;
3839
- return r`${i}${s}${o}`;
4535
+ return o`${s}${i}${r}`;
3840
4536
  }
3841
4537
  renderWorkspace() {
3842
4538
  const e = !this.docked;
3843
- return r`<div class="root" @keydown=${this.onKeydown}>
3844
- ${this.sidebarOpen && e ? r`<div class="scrim" @click=${() => this.sidebarOpen = !1}></div>` : m}
3845
- ${this.sidebarOpen ? this.renderSidebar(e) : m}
4539
+ return o`<div class="root" @keydown=${this.onKeydown}>
4540
+ ${this.sidebarOpen && e ? o`<div class="scrim" @click=${() => this.sidebarOpen = !1}></div>` : m}
4541
+ ${this.sidebarOpen && this.sidebar !== "none" ? this.renderSidebar(e) : m}
3846
4542
  <main
3847
4543
  class="main"
3848
4544
  @dragenter=${this.onDragEnter}
3849
4545
  @dragover=${(t) => t.preventDefault()}
3850
4546
  >
3851
4547
  ${this.renderHeader()}
3852
- ${this.offline ? r`<div class="banner" role="status">${this.msg.offline}</div>` : m}
4548
+ ${this.offline ? o`<div class="banner" role="status">${this.msg.offline}</div>` : m}
3853
4549
  <div
3854
4550
  class="scroller"
3855
4551
  role="log"
@@ -3860,20 +4556,15 @@ assistant: ${i.slice(0, 1500)}`,
3860
4556
  >
3861
4557
  ${this.msgs.length || this.loadingThread || this.threadError ? this.renderThread() : this.renderWelcome()}
3862
4558
  </div>
3863
- ${this.showJump ? r`<button type="button" class="jump" @click=${this.jumpToLatest}>
4559
+ ${this.showJump ? o`<button type="button" class="jump" @click=${this.jumpToLatest}>
3864
4560
  ↓ ${this.msg.newReply}
3865
4561
  </button>` : m}
3866
- ${this.renderComposer()}
3867
- ${this.branding ? r`<div class="branding" part="branding">
3868
- <a href="https://singlebase.cloud" target="_blank" rel="noopener noreferrer"
3869
- >${this.msg.brandingLabel}</a
3870
- >
3871
- </div>` : m}
3872
- ${this.toast ? r`<div class="toast" role="status">
4562
+ ${this.renderComposer()} ${Xt(this.branding, "Chat")}
4563
+ ${this.toast ? o`<div class="toast" role="status">
3873
4564
  <span>${this.toast.text}</span>
3874
- ${this.toast.undo ? r`<button type="button" @click=${this.undo}>${this.msg.undo}</button>` : m}
4565
+ ${this.toast.undo ? o`<button type="button" @click=${this.undo}>${this.msg.undo}</button>` : m}
3875
4566
  </div>` : m}
3876
- ${this.dragging ? r`<div
4567
+ ${this.dragging ? o`<div
3877
4568
  class="drop"
3878
4569
  @dragover=${(t) => t.preventDefault()}
3879
4570
  @dragleave=${this.onDragLeave}
@@ -3886,38 +4577,24 @@ assistant: ${i.slice(0, 1500)}`,
3886
4577
  </div>`;
3887
4578
  }
3888
4579
  renderSidebar(e) {
3889
- const t = this.msg, i = this.search.trim().toLowerCase(), s = this.chatList.filter(
3890
- (l) => !i || (l.title ?? "").toLowerCase().includes(i)
3891
- ), a = [
3892
- [t.groupBookmarked, s.filter((l) => l.bookmarked)],
3893
- [
3894
- t.groupToday,
3895
- s.filter((l) => !l.bookmarked && Pe(l._modified_at ?? l._created_at) === "today")
3896
- ],
3897
- [
3898
- t.groupYesterday,
3899
- s.filter(
3900
- (l) => !l.bookmarked && Pe(l._modified_at ?? l._created_at) === "yesterday"
3901
- )
3902
- ],
3903
- [
3904
- t.groupWeek,
3905
- s.filter((l) => !l.bookmarked && Pe(l._modified_at ?? l._created_at) === "week")
3906
- ],
3907
- [
3908
- t.groupOlder,
3909
- s.filter((l) => !l.bookmarked && Pe(l._modified_at ?? l._created_at) === "older")
3910
- ]
4580
+ const t = this.msg, s = this.allowSearch ? this.search.trim().toLowerCase() : "", i = this.chatList.filter(
4581
+ (f) => !s || (f.title ?? "").toLowerCase().includes(s)
4582
+ ), a = (f) => this.showBookmarked && !!f.bookmarked, r = (f) => i.filter((b) => !a(b) && Ds(b._modified_at ?? b._created_at) === f), c = [
4583
+ [t.groupBookmarked, i.filter(a)],
4584
+ [t.groupToday, r("today")],
4585
+ [t.groupYesterday, r("yesterday")],
4586
+ [t.groupWeek, r("week")],
4587
+ [t.groupOlder, r("older")]
3911
4588
  ];
3912
- let o;
3913
- return this.listState === "loading" && !this.chatList.length ? o = r`<div aria-label=${t.loadingChats}>
3914
- ${[1, 2, 3, 4].map(() => r`<div class="skeleton"></div>`)}
3915
- </div>` : s.length ? o = a.filter(([, l]) => l.length).map(
3916
- ([l, c]) => r`<div class="group">${l}</div>
3917
- ${c.map((x) => this.renderThreadRow(x))}`
3918
- ) : o = r`<span class="side-note"
3919
- >${i ? z(t.noMatch, { query: this.search.trim() }) : t.noChats}</span
3920
- >`, r`<aside
4589
+ let l;
4590
+ return this.listState === "loading" && !this.chatList.length ? l = o`<div aria-label=${t.loadingChats}>
4591
+ ${[1, 2, 3, 4].map(() => o`<div class="skeleton"></div>`)}
4592
+ </div>` : i.length ? l = c.filter(([, f]) => f.length).map(
4593
+ ([f, b]) => o`<div class="group">${f}</div>
4594
+ ${b.map((C) => this.renderThreadRow(C))}`
4595
+ ) : l = o`<span class="side-note"
4596
+ >${s ? _(t.noMatch, { query: this.search.trim() }) : t.noChats}</span
4597
+ >`, o`<aside
3921
4598
  class="sidebar ${e ? "overlay" : "docked"}"
3922
4599
  part="sidebar"
3923
4600
  aria-label=${t.chats}
@@ -3931,133 +4608,149 @@ assistant: ${i.slice(0, 1500)}`,
3931
4608
  aria-label=${t.hideSidebar}
3932
4609
  @click=${() => this.sidebarOpen = !1}
3933
4610
  >
3934
- ${y.sidebar()}
4611
+ ${k.sidebar()}
3935
4612
  </button>
3936
4613
  </div>
3937
4614
  <div class="side-tools">
3938
- <button type="button" class="new-chat" @click=${() => this.newChat()}>
3939
- ${y.plus()}<span>${t.newChat}</span>
3940
- </button>
3941
- <input
3942
- class="search"
3943
- type="search"
3944
- placeholder=${t.searchChats}
3945
- aria-label=${t.searchChats}
3946
- .value=${this.search}
3947
- @input=${(l) => this.search = l.target.value}
3948
- />
4615
+ ${this.showNewChat ? o`<button type="button" class="new-chat" @click=${() => this.newChat()}>
4616
+ ${k.plus()}<span>${t.newChat}</span>
4617
+ </button>` : m}
4618
+ ${this.allowSearch ? o`<input
4619
+ class="search"
4620
+ type="search"
4621
+ placeholder=${t.searchChats}
4622
+ aria-label=${t.searchChats}
4623
+ .value=${this.search}
4624
+ @input=${(f) => this.search = f.target.value}
4625
+ />` : m}
4626
+ </div>
4627
+ <div class="threads">${l}</div>
4628
+ <div class="side-extra ${this.hasSidebarContent ? "filled" : ""}" part="sidebar-extra">
4629
+ <slot
4630
+ name="sidebar"
4631
+ @slotchange=${(f) => this.hasSidebarContent = f.target.assignedNodes().length > 0}
4632
+ ></slot>
3949
4633
  </div>
3950
- <div class="threads">${o}</div>
3951
4634
  </aside>`;
3952
4635
  }
3953
4636
  renderThreadRow(e) {
3954
- const t = this.msg, i = e._id === this.activeId, s = e.title || t.untitled;
4637
+ const t = this.msg, s = e._id === this.activeId, i = e.title || t.untitled;
3955
4638
  if (this.renamingId === e._id)
3956
- return r`<div class="thread active">
4639
+ return o`<div class="thread active">
3957
4640
  <input
3958
4641
  class="thread-rename"
3959
4642
  maxlength="80"
3960
- .value=${s}
4643
+ .value=${i}
3961
4644
  aria-label=${t.renameChat}
3962
- @keydown=${(o) => {
3963
- o.key === "Enter" && this.commitRename(e._id, o.target.value), o.key === "Escape" && (o.stopPropagation(), this.renamingId = "");
4645
+ @keydown=${(r) => {
4646
+ r.key === "Enter" && this.commitRename(e._id, r.target.value), r.key === "Escape" && (r.stopPropagation(), this.renamingId = "");
3964
4647
  }}
3965
- @blur=${(o) => this.commitRename(e._id, o.target.value)}
4648
+ @blur=${(r) => this.commitRename(e._id, r.target.value)}
3966
4649
  />
3967
4650
  </div>`;
3968
- const a = (o) => (l) => {
3969
- l.stopPropagation(), o();
4651
+ const a = (r) => (c) => {
4652
+ c.stopPropagation(), r();
3970
4653
  };
3971
- return r`<div
3972
- class="thread ${i ? "active" : ""}"
4654
+ return o`<div
4655
+ class="thread ${s ? "active" : ""}"
3973
4656
  role="button"
3974
4657
  tabindex="0"
3975
- aria-current=${i ? "true" : "false"}
4658
+ aria-current=${s ? "true" : "false"}
3976
4659
  @click=${() => this.openChat(e._id)}
3977
- @keydown=${(o) => o.key === "Enter" && this.openChat(e._id)}
4660
+ @keydown=${(r) => r.key === "Enter" && this.openChat(e._id)}
3978
4661
  >
3979
- <span class="thread-title">${s}</span>
4662
+ <span class="thread-title">${i}</span>
3980
4663
  <span class="thread-actions">
3981
- <button
3982
- type="button"
3983
- class="icon sm ${e.bookmarked ? "on" : ""}"
3984
- title=${e.bookmarked ? t.unbookmarkChat : t.bookmarkChat}
3985
- aria-label=${e.bookmarked ? t.unbookmarkChat : t.bookmarkChat}
3986
- @click=${a(() => this.toggleChatBookmark(e._id))}
3987
- >
3988
- ${y.bookmark(!!e.bookmarked)}
3989
- </button>
3990
- <button
3991
- type="button"
3992
- class="icon sm"
3993
- title=${t.renameChat}
3994
- aria-label=${t.renameChat}
3995
- @click=${a(() => {
4664
+ ${this.allowBookmark ? o`<button
4665
+ type="button"
4666
+ class="icon sm ${e.bookmarked ? "on" : ""}"
4667
+ title=${e.bookmarked ? t.unbookmarkChat : t.bookmarkChat}
4668
+ aria-label=${e.bookmarked ? t.unbookmarkChat : t.bookmarkChat}
4669
+ @click=${a(() => this.toggleChatBookmark(e._id))}
4670
+ >
4671
+ ${k.bookmark(!!e.bookmarked)}
4672
+ </button>` : m}
4673
+ ${this.allowRename ? o`<button
4674
+ type="button"
4675
+ class="icon sm"
4676
+ title=${t.renameChat}
4677
+ aria-label=${t.renameChat}
4678
+ @click=${a(() => {
3996
4679
  this.renamingId = e._id, this.focusNext = "input.thread-rename";
3997
4680
  })}
3998
- >
3999
- ${y.pencil()}
4000
- </button>
4001
- <button
4002
- type="button"
4003
- class="icon sm danger"
4004
- title=${t.deleteChat}
4005
- aria-label=${t.deleteChat}
4006
- @click=${a(() => this.deleteChat(e._id))}
4007
- >
4008
- ${y.trash()}
4009
- </button>
4681
+ >
4682
+ ${k.pencil()}
4683
+ </button>` : m}
4684
+ ${this.allowDelete ? o`<button
4685
+ type="button"
4686
+ class="icon sm danger"
4687
+ title=${t.deleteChat}
4688
+ aria-label=${t.deleteChat}
4689
+ @click=${a(() => this.deleteChat(e._id))}
4690
+ >
4691
+ ${k.trash()}
4692
+ </button>` : m}
4010
4693
  </span>
4011
4694
  </div>`;
4012
4695
  }
4013
4696
  renderHeader() {
4014
- const e = this.msg, t = !!this.activeId, i = (this.embed === "inline" || this.embed === "launcher") && !this.mobile, s = this.embed === "launcher" ? () => this.close() : this.expanded ? () => this.collapse() : null;
4697
+ const e = this.msg, t = !!this.activeId, s = (this.embed === "inline" || this.embed === "launcher") && !this.mobile, i = this.embed === "launcher" ? () => this.close() : this.expanded ? () => this.collapse() : null;
4015
4698
  let a = m;
4016
- return this.showTitle && (a = this.editingTitle ? r`<input
4699
+ return this.showTitle && (a = this.editingTitle ? o`<input
4017
4700
  class="title-input"
4018
4701
  maxlength="80"
4019
4702
  .value=${this.chatTitle}
4020
4703
  aria-label=${e.renameChat}
4021
- @keydown=${(o) => {
4022
- o.key === "Enter" && this.commitTitle(o.target.value), o.key === "Escape" && (o.stopPropagation(), this.editingTitle = !1);
4704
+ @keydown=${(r) => {
4705
+ r.key === "Enter" && this.commitTitle(r.target.value), r.key === "Escape" && (r.stopPropagation(), this.editingTitle = !1);
4023
4706
  }}
4024
- @blur=${(o) => this.commitTitle(o.target.value)}
4025
- />` : r`<button
4707
+ @blur=${(r) => this.commitTitle(r.target.value)}
4708
+ />` : o`<button
4026
4709
  type="button"
4027
4710
  class="title"
4028
4711
  part="title"
4029
- ?disabled=${!t}
4030
- title=${t ? e.renameChat : ""}
4712
+ ?disabled=${!t || !this.allowRename}
4713
+ title=${t && this.allowRename ? e.renameChat : ""}
4031
4714
  @click=${() => {
4032
4715
  this.editingTitle = !0, this.focusNext = "input.title-input";
4033
4716
  }}
4034
4717
  >
4035
4718
  ${this.chatTitle || e.untitled}
4036
- </button>`), r`<header class="header" part="header">
4719
+ </button>`), o`<header class="header" part="header">
4037
4720
  <div class="header-left">
4038
- ${this.sidebarOpen && this.docked ? m : r`<button
4721
+ ${this.sidebar === "none" || this.sidebarOpen && this.docked ? m : o`<button
4039
4722
  type="button"
4040
4723
  class="icon"
4041
4724
  title=${e.showChats}
4042
4725
  aria-label=${e.showChats}
4043
4726
  @click=${() => this.sidebarOpen = !0}
4044
4727
  >
4045
- ${y.sidebar()}
4728
+ ${k.sidebar()}
4046
4729
  </button>`}
4047
4730
  ${a}
4048
4731
  </div>
4049
4732
  <div class="header-right">
4050
- <button
4051
- type="button"
4052
- class="icon ${this.bookmarked ? "on" : ""}"
4053
- ?disabled=${!t}
4054
- title=${this.bookmarked ? e.unbookmarkChat : e.bookmarkChat}
4055
- aria-label=${this.bookmarked ? e.unbookmarkChat : e.bookmarkChat}
4056
- @click=${() => this.activeId && this.toggleChatBookmark(this.activeId)}
4057
- >
4058
- ${y.bookmark(this.bookmarked)}
4059
- </button>
4060
- ${this.allowExport ? r`<div class="menu-wrap">
4733
+ ${this.sidebar === "none" && this.showNewChat ? o`<button
4734
+ type="button"
4735
+ class="icon"
4736
+ ?disabled=${!this.msgs.length && !t}
4737
+ title=${e.newChat}
4738
+ aria-label=${e.newChat}
4739
+ @click=${() => this.newChat()}
4740
+ >
4741
+ ${k.plus()}
4742
+ </button>` : m}
4743
+ ${this.allowBookmark ? o`<button
4744
+ type="button"
4745
+ class="icon ${this.bookmarked ? "on" : ""}"
4746
+ ?disabled=${!t}
4747
+ title=${this.bookmarked ? e.unbookmarkChat : e.bookmarkChat}
4748
+ aria-label=${this.bookmarked ? e.unbookmarkChat : e.bookmarkChat}
4749
+ @click=${() => this.activeId && this.toggleChatBookmark(this.activeId)}
4750
+ >
4751
+ ${k.bookmark(this.bookmarked)}
4752
+ </button>` : m}
4753
+ ${this.allowExport ? o`<div class="menu-wrap">
4061
4754
  <button
4062
4755
  type="button"
4063
4756
  class="icon ${this.menuOpen ? "on" : ""}"
@@ -4068,37 +4761,37 @@ assistant: ${i.slice(0, 1500)}`,
4068
4761
  aria-expanded=${this.menuOpen ? "true" : "false"}
4069
4762
  @click=${() => this.menuOpen = !this.menuOpen}
4070
4763
  >
4071
- ${y.download()}
4764
+ ${k.download()}
4072
4765
  </button>
4073
4766
  ${this.menuOpen ? this.renderExportMenu() : m}
4074
4767
  </div>` : m}
4075
- <button
4076
- type="button"
4077
- class="icon danger"
4078
- ?disabled=${!t}
4079
- title=${e.deleteChat}
4080
- aria-label=${e.deleteChat}
4081
- @click=${() => this.activeId && this.deleteChat(this.activeId)}
4082
- >
4083
- ${y.trash()}
4084
- </button>
4085
- ${i || s ? r`<span class="divider"></span> ${i ? r`<button
4768
+ ${this.allowDelete ? o`<button
4769
+ type="button"
4770
+ class="icon danger"
4771
+ ?disabled=${!t}
4772
+ title=${e.deleteChat}
4773
+ aria-label=${e.deleteChat}
4774
+ @click=${() => this.activeId && this.deleteChat(this.activeId)}
4775
+ >
4776
+ ${k.trash()}
4777
+ </button>` : m}
4778
+ ${s || i ? o`<span class="divider"></span> ${s ? o`<button
4086
4779
  type="button"
4087
4780
  class="icon"
4088
4781
  title=${this.expanded ? e.restore : e.expand}
4089
4782
  aria-label=${this.expanded ? e.restore : e.expand}
4090
4783
  @click=${() => this.expanded ? this.collapse() : this.expand()}
4091
4784
  >
4092
- ${this.expanded ? y.restore() : y.expand()}
4785
+ ${this.expanded ? k.restore() : k.expand()}
4093
4786
  </button>` : m}
4094
- ${s ? r`<button
4787
+ ${i ? o`<button
4095
4788
  type="button"
4096
4789
  class="icon"
4097
4790
  title=${e.minimize}
4098
4791
  aria-label=${e.minimize}
4099
- @click=${s}
4792
+ @click=${i}
4100
4793
  >
4101
- ${y.minimize()}
4794
+ ${k.minimize()}
4102
4795
  </button>` : m}` : m}
4103
4796
  </div>
4104
4797
  </header>`;
@@ -4110,58 +4803,63 @@ assistant: ${i.slice(0, 1500)}`,
4110
4803
  [e.exportText, ".txt", "txt"],
4111
4804
  [e.exportCopy, "", "copy"]
4112
4805
  ];
4113
- return r`<div class="menu-scrim" @click=${() => this.menuOpen = !1}></div>
4806
+ return o`<div class="menu-scrim" @click=${() => this.menuOpen = !1}></div>
4114
4807
  <div class="menu" role="menu">
4115
4808
  <span class="label">${e.exportHeading}</span>
4116
4809
  ${t.map(
4117
- ([i, s, a]) => r`<button
4810
+ ([s, i, a]) => o`<button
4118
4811
  type="button"
4119
4812
  role="menuitem"
4120
4813
  class="menu-item"
4121
4814
  @click=${() => this.exportChat(a)}
4122
4815
  >
4123
- <span>${i}</span><span class="ext">${s}</span>
4816
+ <span>${s}</span><span class="ext">${i}</span>
4124
4817
  </button>`
4125
4818
  )}
4126
4819
  </div>`;
4127
4820
  }
4821
+ /** The suggestion cards. `[]` or `"none"` shows none; unset uses the mode's. */
4128
4822
  promptList() {
4129
4823
  const e = this.prompts;
4130
- return Array.isArray(e) && e.length ? e.map((t) => typeof t == "string" ? { text: t } : t).filter((t) => t == null ? void 0 : t.text).slice(0, 4) : typeof e == "string" && e.trim() ? e.split("|").map((t) => t.trim()).filter(Boolean).slice(0, 4).map((t) => ({ text: t })) : (ot[this.mode] ?? ot.chat).map(([t, i]) => ({
4824
+ return Array.isArray(e) ? e.map((t) => typeof t == "string" ? { text: t } : t).filter((t) => t == null ? void 0 : t.text).slice(0, 4) : typeof e == "string" && e.trim().toLowerCase() === "none" ? [] : typeof e == "string" && e.trim() ? e.split("|").map((t) => t.trim()).filter(Boolean).slice(0, 4).map((t) => ({ text: t })) : (Et[this.mode] ?? Et.chat).map(([t, s]) => ({
4131
4825
  label: t,
4132
- text: i
4826
+ text: s
4133
4827
  }));
4134
4828
  }
4135
4829
  renderWelcome() {
4136
- const e = this.msg, t = this.mode === "rag" ? "Rag" : this.mode === "rich" ? "Rich" : "Chat", i = (s) => e[`${s}${t}`];
4137
- return r`<div class="welcome" part="welcome">
4138
- <div class="welcome-head">
4139
- ${this.logoUrl && it(this.logoUrl, !0) ? r`<img class="welcome-logo" src=${this.logoUrl} alt="" />` : m}
4140
- <span class="label">${i("eyebrow")}</span>
4141
- <h2>${this.heading || i("heading")}</h2>
4142
- <p>${this.description || i("description")}</p>
4143
- </div>
4144
- <div class="prompts">
4145
- ${this.promptList().map(
4146
- (s) => r`<button
4147
- type="button"
4148
- class="prompt"
4149
- part="prompt"
4150
- @click=${() => this.send(s.text)}
4151
- >
4152
- <span class="label">${s.label || "Suggested"}</span>
4153
- <span class="prompt-text">${s.text}</span>
4154
- </button>`
4830
+ const e = this.msg, t = this.mode === "rag" ? "Rag" : this.mode === "kb" ? "Kb" : "Chat", s = (r) => e[`${r}${t}`], i = this.eyebrow ?? s("eyebrow"), a = this.promptList();
4831
+ return o`<div class="welcome-slot">
4832
+ <slot name="welcome"
4833
+ ><div class="welcome" part="welcome">
4834
+ <div class="welcome-head">
4835
+ ${this.logoUrl && _t(this.logoUrl, !0) ? o`<img class="welcome-logo" src=${this.logoUrl} alt="" />` : m}
4836
+ ${i ? o`<span class="label">${i}</span>` : m}
4837
+ <h2>${this.heading || s("heading")}</h2>
4838
+ <p>${this.description || s("description")}</p>
4839
+ </div>
4840
+ ${a.length ? o`<div class="prompts">
4841
+ ${a.map(
4842
+ (r) => o`<button
4843
+ type="button"
4844
+ class="prompt"
4845
+ part="prompt"
4846
+ @click=${() => this.send(r.text)}
4847
+ >
4848
+ <span class="label">${r.label || "Suggested"}</span>
4849
+ <span class="prompt-text">${r.text}</span>
4850
+ </button>`
4155
4851
  )}
4156
- </div>
4852
+ </div>` : m}
4853
+ </div></slot
4854
+ >
4157
4855
  </div>`;
4158
4856
  }
4159
4857
  renderThread() {
4160
4858
  const e = this.msgs.map((t) => t.role).lastIndexOf("assistant");
4161
- return r`<div class="thread-view">
4162
- ${this.threadError ? r`<div class="error-card" role="alert">
4859
+ return o`<div class="thread-view">
4860
+ ${this.threadError ? o`<div class="error-card" role="alert">
4163
4861
  <span>${this.threadError}</span>
4164
- ${this.activeId ? r`<button
4862
+ ${this.activeId ? o`<button
4165
4863
  type="button"
4166
4864
  class="btn"
4167
4865
  @click=${() => this.openChat(this.activeId)}
@@ -4169,21 +4867,21 @@ assistant: ${i.slice(0, 1500)}`,
4169
4867
  ${this.msg.retry}
4170
4868
  </button>` : m}
4171
4869
  </div>` : m}
4172
- ${this.loadingThread ? r`${[1, 2].map(() => r`<div class="skeleton" style="height:48px"></div>`)}` : m}
4173
- ${vt(
4870
+ ${this.loadingThread ? o`${[1, 2].map(() => o`<div class="skeleton" style="height:48px"></div>`)}` : m}
4871
+ ${qt(
4174
4872
  this.msgs,
4175
4873
  (t) => t.key,
4176
- (t, i) => t.role === "user" ? this.renderUser(t) : this.renderBot(t, i === e)
4874
+ (t, s) => t.role === "user" ? this.renderUser(t) : this.renderBot(t, s === e)
4177
4875
  )}
4178
4876
  </div>`;
4179
4877
  }
4180
4878
  renderUser(e) {
4181
- const t = this.msg, i = e.at ? new Date(e.at).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" }) : "", s = e.attachments ?? [];
4182
- return r`<div class="msg user" part="message user">
4183
- ${s.length ? r`<div class="attachments">
4184
- ${s.map((a) => r`<span class="doc-chip"><span class="ext">${ct(a.name)}</span><span class="name">${a.name}</span></span>`)}
4879
+ const t = this.msg, s = e.at ? new Date(e.at).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" }) : "", i = e.attachments ?? [];
4880
+ return o`<div class="msg user" part="message user">
4881
+ ${i.length ? o`<div class="attachments">
4882
+ ${i.map((a) => o`<span class="doc-chip"><span class="ext">${xt(a.name)}</span><span class="name">${a.name}</span></span>`)}
4185
4883
  </div>` : m}
4186
- ${this.editingKey === e.key ? r`<div class="edit-box">
4884
+ ${this.editingKey === e.key ? o`<div class="edit-box">
4187
4885
  <textarea
4188
4886
  rows="3"
4189
4887
  class="edit-input"
@@ -4201,11 +4899,11 @@ assistant: ${i.slice(0, 1500)}`,
4201
4899
  ${t.saveResend}
4202
4900
  </button>
4203
4901
  </div>
4204
- </div>` : r`<div class="bubble-user">${e.content}</div>
4902
+ </div>` : o`<div class="bubble-user">${e.content}</div>
4205
4903
  <div class="toolbar">
4206
- ${e.bookmarked ? r`<span class="saved">${y.bookmark(!0)}${t.saved}</span>` : m}
4207
- <span class="time">${i}</span>
4208
- ${this.busy ? m : r`<button
4904
+ ${this.allowBookmark && e.bookmarked ? o`<span class="saved">${k.bookmark(!0)}${t.saved}</span>` : m}
4905
+ ${this.showTime ? o`<span class="time">${s}</span>` : m}
4906
+ ${this.busy ? m : o`<button
4209
4907
  type="button"
4210
4908
  class="icon"
4211
4909
  title=${t.edit}
@@ -4214,192 +4912,203 @@ assistant: ${i.slice(0, 1500)}`,
4214
4912
  this.editingKey = e.key, this.editDraft = e.content, this.focusNext = "textarea.edit-input";
4215
4913
  }}
4216
4914
  >
4217
- ${y.pencil()}
4915
+ ${k.pencil()}
4218
4916
  </button>`}
4219
- <button
4220
- type="button"
4221
- class="icon"
4222
- title=${this.copiedKey === e.key ? t.copied : t.copy}
4223
- aria-label=${t.copy}
4224
- @click=${() => this.copy(e.key, e.content)}
4225
- >
4226
- ${y.copy()}
4227
- </button>
4228
- ${e.id ? r`<button
4917
+ ${this.allowCopy ? o`<button
4918
+ type="button"
4919
+ class="icon"
4920
+ title=${this.copiedKey === e.key ? t.copied : t.copy}
4921
+ aria-label=${t.copy}
4922
+ @click=${() => this.copy(e.key, e.content)}
4923
+ >
4924
+ ${k.copy()}
4925
+ </button>` : m}
4926
+ ${this.allowBookmark && e.id ? o`<button
4229
4927
  type="button"
4230
4928
  class="icon ${e.bookmarked ? "on" : ""}"
4231
4929
  title=${e.bookmarked ? t.unbookmarkMessage : t.bookmarkMessage}
4232
4930
  aria-label=${e.bookmarked ? t.unbookmarkMessage : t.bookmarkMessage}
4233
4931
  @click=${() => this.toggleMessageBookmark(e)}
4234
4932
  >
4235
- ${y.bookmark(e.bookmarked)}
4933
+ ${k.bookmark(e.bookmarked)}
4934
+ </button>` : m}
4935
+ ${this.allowDelete ? o`<button
4936
+ type="button"
4937
+ class="icon danger"
4938
+ title=${t.deleteMessage}
4939
+ aria-label=${t.deleteMessage}
4940
+ @click=${() => this.deleteMessage(e)}
4941
+ >
4942
+ ${k.trash()}
4236
4943
  </button>` : m}
4237
- <button
4238
- type="button"
4239
- class="icon danger"
4240
- title=${t.deleteMessage}
4241
- aria-label=${t.deleteMessage}
4242
- @click=${() => this.deleteMessage(e)}
4243
- >
4244
- ${y.trash()}
4245
- </button>
4246
4944
  </div>`}
4247
4945
  </div>`;
4248
4946
  }
4249
4947
  pillLabel() {
4250
- return this.mode === "rag" ? this.msg.searching : this.mode === "rich" ? this.msg.building : this.msg.thinking;
4948
+ return this.mode === "rag" || this.mode === "kb" ? this.msg.searching : this.msg.thinking;
4251
4949
  }
4252
4950
  renderBot(e, t) {
4253
- const i = this.msg, s = e.phase === "pending", a = e.phase === "done", o = e.sources.length, l = Ze(e.content), c = e.sources.map((b, M) => Ke(b, M + 1)), x = l.size ? c.filter((b) => l.has(b.n)) : c, f = e.at ? new Date(e.at).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" }) : "", O = e.content + (x.length ? `
4951
+ const s = this.msg, i = e.phase === "pending", a = e.phase === "done", r = e.sources.length, c = Ot(e.content), l = e.sources.map((w, L) => ft(w, L + 1)), f = c.size ? l.filter((w) => c.has(w.n)) : l, b = e.at ? new Date(e.at).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" }) : "", C = e.content + (f.length ? `
4254
4952
 
4255
4953
  Sources:
4256
- ${x.map((b) => `[${b.n}] ${b.title}`).join(`
4257
- `)}` : ""), S = this.retrievalOpen.has(e.key);
4258
- return r`<div class="msg bot" part="message assistant">
4259
- ${s ? r`<div class="halo"></div>` : m}
4260
- ${this.arrivedKey === e.key ? r`<div class="arrived">
4954
+ ${f.map((w) => `[${w.n}] ${w.title}`).join(`
4955
+ `)}` : ""), T = this.retrievalOpen.has(e.key);
4956
+ return o`<div class="msg bot" part="message assistant">
4957
+ ${i ? o`<div class="halo"></div>` : m}
4958
+ ${this.arrivedKey === e.key ? o`<div class="arrived">
4261
4959
  <div class="wash"></div>
4262
4960
  <div class="ring"></div>
4263
4961
  <div class="sweep"></div>
4264
4962
  </div>` : m}
4265
4963
  <div class="bot-body">
4266
- ${e.bookmarked ? r`<span class="saved">${y.bookmark(!0)}${i.saved}</span>` : m}
4267
- ${s ? r`<div class="pill" role="status">
4964
+ ${this.allowBookmark && e.bookmarked ? o`<span class="saved">${k.bookmark(!0)}${s.saved}</span>` : m}
4965
+ ${i ? o`<div class="pill" role="status">
4268
4966
  <span class="ring"></span><span class="dot"></span>
4269
4967
  <span class="shimmer">${this.pillLabel()}</span>
4270
4968
  </div>` : m}
4271
- ${o && !s ? r`<div class="retrieval">
4969
+ ${this.showSources && r && !i ? o`<div class="retrieval">
4272
4970
  <button
4273
4971
  type="button"
4274
4972
  class="retrieval-toggle"
4275
- aria-expanded=${S ? "true" : "false"}
4973
+ aria-expanded=${T ? "true" : "false"}
4276
4974
  @click=${() => {
4277
- const b = new Set(this.retrievalOpen);
4278
- b.has(e.key) ? b.delete(e.key) : b.add(e.key), this.retrievalOpen = b;
4975
+ const w = new Set(this.retrievalOpen);
4976
+ w.has(e.key) ? w.delete(e.key) : w.add(e.key), this.retrievalOpen = w;
4279
4977
  }}
4280
4978
  >
4281
- <span class="chev">${S ? "▾" : "▸"}</span>
4282
- <span style="flex:1">${z(i.searchedSources, { n: o })}</span>
4283
- ${e.execTime !== void 0 ? r`<span class="ms">${e.execTime.toFixed(1)}s</span>` : m}
4979
+ <span class="chev">${T ? "▾" : "▸"}</span>
4980
+ <span style="flex:1">${_(s.searchedSources, { n: r })}</span>
4981
+ ${e.execTime !== void 0 ? o`<span class="ms">${e.execTime.toFixed(1)}s</span>` : m}
4284
4982
  </button>
4285
- ${S ? r`<div class="retrieval-list">
4286
- ${c.map(
4287
- (b) => r`<button
4983
+ ${T ? o`<div class="retrieval-list">
4984
+ ${l.map(
4985
+ (w) => o`<button
4288
4986
  type="button"
4289
4987
  class="passage"
4290
- @click=${() => this.panel = { key: e.key, n: b.n }}
4988
+ @click=${() => this.panel = { key: e.key, n: w.n }}
4291
4989
  >
4292
- <span class="n">${b.n}</span>
4990
+ <span class="n">${w.n}</span>
4293
4991
  <span class="what"
4294
- ><span>${b.title}</span><span>${b.collection || b.path}</span></span
4992
+ ><span>${w.title}${w.section ? ` · ${w.section}` : ""}</span
4993
+ ><span>${w.collection || w.path}</span></span
4295
4994
  >
4296
- ${b.score !== null ? r`<span class="relevance"
4297
- ><span class="score">${b.score.toFixed(2)}</span>
4995
+ ${w.score !== null ? o`<span class="relevance"
4996
+ ><span class="score">${w.score.toFixed(2)}</span>
4298
4997
  <span class="relevance-track"
4299
4998
  ><span
4300
4999
  class="relevance-fill"
4301
- style="width:${Math.round(b.score * 100)}%"
5000
+ style="width:${Math.round(w.score * 100)}%"
4302
5001
  ></span></span
4303
- ></span>` : r`<span></span>`}
5002
+ ></span>` : o`<span></span>`}
4304
5003
  </button>`
4305
5004
  )}
4306
5005
  </div>` : m}
4307
5006
  </div>` : m}
4308
- ${s ? m : this.renderAnswer(e)}
4309
- ${e.phase === "streaming" ? r`<span class="caret"></span>` : m}
4310
- ${e.phase === "error" ? r`<div class="error-card" role="alert">
5007
+ ${i ? m : this.renderAnswer(e)}
5008
+ ${e.phase === "streaming" ? o`<span class="caret"></span>` : m}
5009
+ ${e.phase === "error" ? o`<div class="error-card" role="alert">
4311
5010
  <span>${e.error}</span>
4312
5011
  <button type="button" class="btn" @click=${() => this.retry(e)}>
4313
- ${i.retry}
5012
+ ${s.retry}
4314
5013
  </button>
4315
5014
  </div>` : m}
4316
- ${a && x.length ? r`<div class="cards">
4317
- <span class="label">${l.size ? i.sourcesCited : i.sourcesRetrieved}</span>
5015
+ ${this.showSources && a && f.length ? o`<div class="cards">
5016
+ <span class="label">${c.size ? s.sourcesCited : s.sourcesRetrieved}</span>
4318
5017
  <div class="card-grid">
4319
- ${x.map(
4320
- (b) => {
4321
- var M;
4322
- return r`<button
5018
+ ${f.map(
5019
+ (w) => {
5020
+ var L;
5021
+ return o`<button
4323
5022
  type="button"
4324
- class="source-card ${((M = this.panel) == null ? void 0 : M.key) === e.key && this.panel.n === b.n ? "active" : ""}"
4325
- @click=${() => this.panel = { key: e.key, n: b.n }}
5023
+ class="source-card ${((L = this.panel) == null ? void 0 : L.key) === e.key && this.panel.n === w.n ? "active" : ""}"
5024
+ @click=${() => this.panel = { key: e.key, n: w.n }}
4326
5025
  >
4327
5026
  <span class="top"
4328
- ><span class="num">${b.n}</span
4329
- >${b.collection ? r`<span class="label">${b.collection}</span>` : m}</span
5027
+ ><span class="num">${w.n}</span
5028
+ >${w.collection ? o`<span class="label">${w.collection}</span>` : m}</span
4330
5029
  >
4331
- <span class="t">${b.title}</span>
4332
- <span class="s">${b.text}</span>
5030
+ <span class="t">${w.title}${w.section ? ` · ${w.section}` : ""}</span>
5031
+ <span class="s">${w.text}</span>
4333
5032
  </button>`;
4334
5033
  }
4335
5034
  )}
4336
5035
  </div>
4337
5036
  </div>` : m}
4338
- ${a ? r`<div class="toolbar ${t ? "pinned" : ""}">
4339
- <button
4340
- type="button"
4341
- class="icon"
4342
- title=${this.copiedKey === e.key ? i.copied : i.copy}
4343
- aria-label=${i.copy}
4344
- @click=${() => this.copy(e.key, O)}
4345
- >
4346
- ${y.copy()}
4347
- </button>
4348
- ${t && !this.busy ? r`<button
5037
+ ${a ? o`<div class="toolbar ${t ? "pinned" : ""}">
5038
+ ${this.allowCopy ? o`<button
5039
+ type="button"
5040
+ class="icon"
5041
+ title=${this.copiedKey === e.key ? s.copied : s.copy}
5042
+ aria-label=${s.copy}
5043
+ @click=${() => this.copy(e.key, C)}
5044
+ >
5045
+ ${k.copy()}
5046
+ </button>` : m}
5047
+ ${this.allowRaw && this.formatLevel !== "raw" && e.content ? o`<button
5048
+ type="button"
5049
+ class="icon ${this.rawKeys.has(e.key) ? "on" : ""}"
5050
+ title=${this.rawKeys.has(e.key) ? s.showFormatted : s.showRaw}
5051
+ aria-label=${s.showRaw}
5052
+ aria-pressed=${this.rawKeys.has(e.key) ? "true" : "false"}
5053
+ @click=${() => this.toggleRaw(e.key)}
5054
+ >
5055
+ ${k.raw()}
5056
+ </button>` : m}
5057
+ ${this.allowRegenerate && t && !this.busy ? o`<button
4349
5058
  type="button"
4350
5059
  class="icon"
4351
- title=${i.regenerate}
4352
- aria-label=${i.regenerate}
5060
+ title=${s.regenerate}
5061
+ aria-label=${s.regenerate}
4353
5062
  @click=${() => this.regenerate()}
4354
5063
  >
4355
- ${y.refresh()}
5064
+ ${k.refresh()}
4356
5065
  </button>` : m}
4357
- ${e.id ? r`<button
5066
+ ${this.allowBookmark && e.id ? o`<button
4358
5067
  type="button"
4359
5068
  class="icon ${e.bookmarked ? "on" : ""}"
4360
- title=${e.bookmarked ? i.unbookmarkMessage : i.bookmarkMessage}
4361
- aria-label=${e.bookmarked ? i.unbookmarkMessage : i.bookmarkMessage}
5069
+ title=${e.bookmarked ? s.unbookmarkMessage : s.bookmarkMessage}
5070
+ aria-label=${e.bookmarked ? s.unbookmarkMessage : s.bookmarkMessage}
4362
5071
  @click=${() => this.toggleMessageBookmark(e)}
4363
5072
  >
4364
- ${y.bookmark(e.bookmarked)}
5073
+ ${k.bookmark(e.bookmarked)}
4365
5074
  </button>` : m}
4366
- <button
4367
- type="button"
4368
- class="icon danger"
4369
- title=${i.deleteMessage}
4370
- aria-label=${i.deleteMessage}
4371
- @click=${() => this.deleteMessage(e)}
4372
- >
4373
- ${y.trash()}
4374
- </button>
4375
- <span class="time">${f}</span>
4376
- ${e.stopped ? r`<span class="note">${i.stopped}</span>` : m}
5075
+ ${this.allowDelete ? o`<button
5076
+ type="button"
5077
+ class="icon danger"
5078
+ title=${s.deleteMessage}
5079
+ aria-label=${s.deleteMessage}
5080
+ @click=${() => this.deleteMessage(e)}
5081
+ >
5082
+ ${k.trash()}
5083
+ </button>` : m}
5084
+ ${this.showTime ? o`<span class="time">${b}</span>` : m}
5085
+ ${e.stopped ? o`<span class="note">${s.stopped}</span>` : m}
4377
5086
  <span class="spacer"></span>
4378
- ${e.feedback ? r`<span class="note"
4379
- >${e.feedback === "up" ? i.markedHelpful : i.thanksFeedback}</span
4380
- >` : r`<button
4381
- type="button"
4382
- class="icon"
4383
- title=${i.helpful}
4384
- aria-label=${i.helpful}
4385
- @click=${() => this.feedback(e, "up")}
4386
- >
4387
- ${y.thumb()}
4388
- </button>
4389
- <button
4390
- type="button"
4391
- class="icon"
4392
- title=${i.notHelpful}
4393
- aria-label=${i.notHelpful}
4394
- @click=${() => this.feedback(e, "down")}
4395
- >
4396
- ${y.thumb(!0)}
4397
- </button>`}
5087
+ ${this.allowFeedback ? e.feedback ? o`<span class="note"
5088
+ >${e.feedback === "up" ? s.markedHelpful : s.thanksFeedback}</span
5089
+ >` : o`<button
5090
+ type="button"
5091
+ class="icon"
5092
+ title=${s.helpful}
5093
+ aria-label=${s.helpful}
5094
+ @click=${() => this.feedback(e, "up")}
5095
+ >
5096
+ ${k.thumb()}
5097
+ </button>
5098
+ <button
5099
+ type="button"
5100
+ class="icon"
5101
+ title=${s.notHelpful}
5102
+ aria-label=${s.notHelpful}
5103
+ @click=${() => this.feedback(e, "down")}
5104
+ >
5105
+ ${k.thumb(!0)}
5106
+ </button>` : m}
4398
5107
  </div>` : m}
4399
- ${a && t && !this.busy && e.followups.length ? r`<div class="followups">
5108
+ ${this.showFollowups && a && t && !this.busy && e.followups.length ? o`<div class="followups">
4400
5109
  ${e.followups.map(
4401
- (b) => r`<button type="button" class="followup" @click=${() => this.send(b)}>
4402
- <span class="arrow">↳</span><span>${b}</span>
5110
+ (w) => o`<button type="button" class="followup" @click=${() => this.send(w)}>
5111
+ <span class="arrow">↳</span><span>${w}</span>
4403
5112
  </button>`
4404
5113
  )}
4405
5114
  </div>` : m}
@@ -4409,97 +5118,121 @@ ${x.map((b) => `[${b.n}] ${b.title}`).join(`
4409
5118
  renderAnswer(e) {
4410
5119
  if (e.phase === "error" && !e.content) return m;
4411
5120
  if (e.phase === "done" && !e.content)
4412
- return e.stopped ? m : r`<div class="answer"><p class="note">${this.msg.emptyReply}</p></div>`;
4413
- const t = _t(zt(e.content), this.renderAs), i = this.renderAs === "text" ? 0 : e.sources.length;
4414
- return r`<div class="answer" part="answer">
4415
- ${t.map((s, a) => this.renderBlock(s, e, i, a))}
5121
+ return e.stopped ? m : o`<div class="answer"><p class="note">${this.msg.emptyReply}</p></div>`;
5122
+ const t = this.formatLevel;
5123
+ if (t === "raw" || this.allowRaw && this.rawKeys.has(e.key))
5124
+ return o`<div class="answer" part="answer"><p class="raw">${e.content}</p></div>`;
5125
+ const s = e.phase === "streaming" ? ps(e.content) : e.content;
5126
+ let i = gs(os(s), t);
5127
+ if (this.afterParse)
5128
+ try {
5129
+ const r = this.afterParse(i, { message: e, format: t });
5130
+ Array.isArray(r) ? i = r : console.warn(
5131
+ "[singlebase-chat] afterParse must return an array of blocks; showing the original."
5132
+ );
5133
+ } catch (r) {
5134
+ console.warn("[singlebase-chat] afterParse failed; showing the original.", r);
5135
+ }
5136
+ const a = e.sources.reduce(
5137
+ (r, c, l) => Math.max(r, ft(c, l + 1).n),
5138
+ 0
5139
+ );
5140
+ return o`<div class="answer" part="answer">
5141
+ ${i.map((r, c) => this.renderBlock(r, e, a, c))}
4416
5142
  </div>`;
4417
5143
  }
4418
- renderInline(e, t, i) {
4419
- return Mt(e, i).map((s) => {
5144
+ renderInline(e, t, s) {
5145
+ return ds(e, s).map((i) => {
4420
5146
  var a;
4421
- switch (s.type) {
5147
+ switch (i.type) {
4422
5148
  case "bold":
4423
- return r`<strong>${s.text}</strong>`;
5149
+ return o`<strong>${i.text}</strong>`;
5150
+ case "italic":
5151
+ return o`<em>${i.text}</em>`;
5152
+ case "strike":
5153
+ return o`<s>${i.text}</s>`;
4424
5154
  case "code":
4425
- return r`<code class="inline">${s.text}</code>`;
5155
+ return o`<code class="inline">${i.text}</code>`;
4426
5156
  case "link":
4427
- return r`<a href=${s.href} target="_blank" rel="noopener noreferrer nofollow"
4428
- >${s.text}</a
5157
+ return o`<a href=${i.href} target="_blank" rel="noopener noreferrer nofollow"
5158
+ >${i.text}</a
4429
5159
  >`;
4430
5160
  case "cite": {
4431
- const o = ((a = this.panel) == null ? void 0 : a.key) === t.key && this.panel.n === s.n ? "cite active" : "cite", l = z(this.msg.openSource, { n: s.n });
4432
- return r`<button type="button" class=${o} aria-label=${l} @click=${() => this.panel = { key: t.key, n: s.n }}>${s.n}</button>`;
5161
+ const r = ((a = this.panel) == null ? void 0 : a.key) === t.key && this.panel.n === i.n ? "cite active" : "cite", c = _(this.msg.openSource, { n: i.n });
5162
+ return o`<button type="button" class=${r} aria-label=${c} @click=${() => this.panel = { key: t.key, n: i.n }}>${i.n}</button>`;
4433
5163
  }
4434
5164
  default:
4435
- return s.text;
5165
+ return i.text;
4436
5166
  }
4437
5167
  });
4438
5168
  }
4439
- renderBlock(e, t, i, s) {
5169
+ renderBlock(e, t, s, i) {
4440
5170
  switch (e.type) {
4441
5171
  case "p":
4442
- return r`<p>${this.renderInline(e.text, t, i)}</p>`;
5172
+ return o`<p>${this.renderInline(e.text, t, s)}</p>`;
4443
5173
  case "raw":
4444
- return r`<p class="raw">${e.text}</p>`;
5174
+ return o`<p class="raw">${e.text}</p>`;
4445
5175
  case "h":
4446
- return r`<h3>${this.renderInline(e.text, t, i)}</h3>`;
4447
- case "list": {
4448
- const a = e.items.map(
4449
- (o) => r`<li>${this.renderInline(o, t, i)}</li>`
4450
- );
4451
- return e.ordered ? r`<ol>
4452
- ${a}
4453
- </ol>` : r`<ul>
4454
- ${a}
4455
- </ul>`;
4456
- }
5176
+ return o`<h3 class="h${e.level}">${this.renderInline(e.text, t, s)}</h3>`;
5177
+ case "hr":
5178
+ return o`<hr />`;
5179
+ case "list":
5180
+ return this.renderList(e.ordered, e.items, t, s);
4457
5181
  case "quote":
4458
- return r`<div class="quote">${this.renderInline(e.text, t, i)}</div>`;
4459
- case "code": {
4460
- const a = `${t.key}:${s}`;
4461
- return r`<div class="code">
4462
- <div class="code-head">
4463
- <span class="label">${e.lang}</span>
4464
- <button type="button" class="text-btn" @click=${() => this.copy(a, e.text)}>
4465
- ${this.copiedKey === a ? this.msg.copied : this.msg.copy}
4466
- </button>
4467
- </div>
4468
- <pre><code>${e.text}</code></pre>
5182
+ return o`<div class="quote">${this.renderInline(e.text, t, s)}</div>`;
5183
+ case "callout":
5184
+ return o`<div class="callout ${e.kind}" role="note" part="callout">
5185
+ <strong class="callout-title"
5186
+ >${e.title || this.msg[_s[e.kind]]}</strong
5187
+ >
5188
+ ${e.text.split(`
5189
+ `).filter((a) => a.trim()).map((a) => o`<p>${this.renderInline(a, t, s)}</p>`)}
4469
5190
  </div>`;
4470
- }
5191
+ case "code":
5192
+ return this.renderCustom(e.lang, e.text, t) ?? this.renderCode(e.lang, e.text, `${t.key}:${i}`);
4471
5193
  case "table":
4472
- return r`<div class="table">
4473
- <table>
4474
- <thead>
4475
- <tr>
4476
- ${e.head.map((a) => r`<th>${this.renderInline(a, t, i)}</th>`)}
4477
- </tr>
4478
- </thead>
4479
- <tbody>
4480
- ${e.rows.map(
4481
- (a) => r`<tr>
4482
- ${a.map((o) => r`<td>${this.renderInline(o, t, i)}</td>`)}
4483
- </tr>`
4484
- )}
4485
- </tbody>
4486
- </table>
5194
+ return this.renderTable(
5195
+ e.head,
5196
+ e.rows,
5197
+ e.align,
5198
+ t,
5199
+ s,
5200
+ `${t.key}:${i}`
5201
+ );
5202
+ case "json":
5203
+ return this.renderJsonBlock(e.value, e.source, `${t.key}:${i}`);
5204
+ case "svg": {
5205
+ const a = ws(e.source);
5206
+ if (!a) return this.renderCode("svg", e.source, `${t.key}:${i}`);
5207
+ const r = `${t.key}:${i}`;
5208
+ return o`<figure class="svg" part="svg">
5209
+ <img src=${a} alt="Drawing" />
5210
+ <figcaption>
5211
+ <button type="button" class="text-btn" @click=${() => this.copy(r, e.source)}>
5212
+ ${this.copiedKey === r ? this.msg.copied : this.msg.copySvg}
5213
+ </button>
5214
+ </figcaption>
5215
+ </figure>`;
5216
+ }
5217
+ case "pending":
5218
+ return o`<div class="chart-pending">
5219
+ <span class="label"
5220
+ >${e.kind === "svg" ? this.msg.renderingSvg : this.msg.renderingChart}</span
5221
+ >
4487
5222
  </div>`;
4488
5223
  case "chart":
4489
5224
  return this.renderChart(e.spec);
4490
- case "chartPending":
4491
- return r`<div class="chart-pending"><span class="label">Rendering chart</span></div>`;
4492
5225
  case "img":
4493
- return r`<div class="gallery ${e.images.length > 1 ? "many" : ""}">
5226
+ return o`<div class="gallery ${e.images.length > 1 ? "many" : ""}">
4494
5227
  ${e.images.map(
4495
- (a) => r`<figure>
4496
- ${a.src && it(a.src, !0) ? r`<img
5228
+ (a) => o`<figure>
5229
+ ${a.src && _t(a.src, !0) ? o`<img
4497
5230
  src=${a.src}
4498
5231
  alt=${a.alt}
4499
5232
  loading="lazy"
4500
5233
  referrerpolicy="no-referrer"
4501
- />` : r`<div class="img-missing"><span class="label">Image</span></div>`}
4502
- ${a.alt ? r`<figcaption>${a.alt}</figcaption>` : m}
5234
+ />` : o`<div class="img-missing"><span class="label">Image</span></div>`}
5235
+ ${a.alt ? o`<figcaption>${a.alt}</figcaption>` : m}
4503
5236
  </figure>`
4504
5237
  )}
4505
5238
  </div>`;
@@ -4507,29 +5240,147 @@ ${x.map((b) => `[${b.n}] ${b.title}`).join(`
4507
5240
  return m;
4508
5241
  }
4509
5242
  }
5243
+ renderList(e, t, s, i) {
5244
+ const a = t.map(
5245
+ (r) => o`<li
5246
+ class=${r.checked === null ? "" : "task"}
5247
+ style=${r.depth ? `margin-left:${r.depth * 20}px` : ""}
5248
+ >
5249
+ ${r.checked === null ? m : o`<input type="checkbox" disabled .checked=${r.checked} aria-hidden="true" />`}
5250
+ ${this.renderInline(r.text, s, i)}
5251
+ </li>`
5252
+ );
5253
+ return e ? o`<ol>
5254
+ ${a}
5255
+ </ol>` : o`<ul>
5256
+ ${a}
5257
+ </ul>`;
5258
+ }
5259
+ renderCode(e, t, s) {
5260
+ return o`<div class="code">
5261
+ <div class="code-head">
5262
+ <span class="label">${e}</span>
5263
+ <button type="button" class="text-btn" @click=${() => this.copy(s, t)}>
5264
+ ${this.copiedKey === s ? this.msg.copied : this.msg.copy}
5265
+ </button>
5266
+ </div>
5267
+ <pre><code>${t}</code></pre>
5268
+ </div>`;
5269
+ }
5270
+ /** A host renderer for this language, at the rich level only. */
5271
+ renderCustom(e, t, s) {
5272
+ var a;
5273
+ const i = this.formatLevel === "rich" ? (a = this.renderers) == null ? void 0 : a[e] : void 0;
5274
+ if (typeof i != "function" || s.phase === "streaming") return null;
5275
+ try {
5276
+ const r = i(t, { lang: e, message: s });
5277
+ return r == null ? null : o`<div class="custom-block">${r}</div>`;
5278
+ } catch (r) {
5279
+ return console.warn(`[singlebase-chat] the "${e}" renderer failed; showing the source`, r), null;
5280
+ }
5281
+ }
5282
+ renderTable(e, t, s, i, a, r) {
5283
+ const c = (x) => /^[-+]?[$€£¥]?\s?[\d,.]+\s?%?$/.test(x.trim()) && /\d/.test(x), l = (x) => Number(x.replace(/[^\d.+-]/g, "")), f = e.map((x, S) => {
5284
+ if (s[S]) return s[S];
5285
+ const $ = t.map((A) => A[S] ?? "").filter(Boolean);
5286
+ return $.length && $.filter(c).length / $.length >= 0.8 ? "right" : null;
5287
+ }), b = this.sorts.get(r);
5288
+ let C = t;
5289
+ b && (C = [...t].sort((x, S) => {
5290
+ const $ = x[b.col] ?? "", A = S[b.col] ?? "";
5291
+ return (c($) && c(A) ? l($) - l(A) : $.localeCompare(A, void 0, { numeric: !0 })) * b.dir;
5292
+ }));
5293
+ const T = C.length;
5294
+ C = C.slice(0, zs);
5295
+ const w = (x) => {
5296
+ const S = new Map(this.sorts), $ = S.get(r);
5297
+ ($ == null ? void 0 : $.col) === x && $.dir === -1 ? S.delete(r) : S.set(r, { col: x, dir: ($ == null ? void 0 : $.col) === x ? -1 : 1 }), this.sorts = S;
5298
+ }, L = (x) => f[x] ? `text-align:${f[x]}` : "";
5299
+ return o`<div class="table" part="table">
5300
+ <table>
5301
+ <thead>
5302
+ <tr>
5303
+ ${e.map((x, S) => {
5304
+ const $ = (b == null ? void 0 : b.col) === S ? b.dir === 1 ? "ascending" : "descending" : "none";
5305
+ return o`<th style=${L(S)} aria-sort=${$}>
5306
+ ${t.length > 1 ? o`<button type="button" class="sort" @click=${() => w(S)}>
5307
+ ${this.renderInline(x, i, a)}<span class="arrow"
5308
+ >${$ === "ascending" ? "↑" : $ === "descending" ? "↓" : "↕"}</span
5309
+ >
5310
+ </button>` : this.renderInline(x, i, a)}
5311
+ </th>`;
5312
+ })}
5313
+ </tr>
5314
+ </thead>
5315
+ <tbody>
5316
+ ${C.map(
5317
+ (x) => o`<tr>
5318
+ ${e.map(
5319
+ (S, $) => o`<td style=${L($)}>
5320
+ ${this.renderInline(x[$] ?? "", i, a)}
5321
+ </td>`
5322
+ )}
5323
+ </tr>`
5324
+ )}
5325
+ </tbody>
5326
+ </table>
5327
+ ${T > C.length ? o`<div class="table-note">
5328
+ ${_(this.msg.showingRows, { n: C.length, total: T })}
5329
+ </div>` : m}
5330
+ </div>`;
5331
+ }
5332
+ renderJsonBlock(e, t, s) {
5333
+ let i = 0;
5334
+ const a = (c) => {
5335
+ i++, i <= Nt && c && typeof c == "object" && Object.values(c).forEach(a);
5336
+ };
5337
+ if (a(e), i > Nt) return this.renderCode("json", t, s);
5338
+ const r = (c, l, f) => {
5339
+ const b = f === void 0 ? m : o`<span class="jkey">${f}</span>: `;
5340
+ if (c && typeof c == "object") {
5341
+ const T = Object.entries(c), w = Array.isArray(c) ? `[${T.length}]` : `{${T.length}}`;
5342
+ return o`<details class="jnode" ?open=${l < 2}>
5343
+ <summary>${b}<span class="jmeta">${w}</span></summary>
5344
+ <div class="jkids">${T.map(([L, x]) => r(x, l + 1, L))}</div>
5345
+ </details>`;
5346
+ }
5347
+ return o`<div class="jleaf">
5348
+ ${b}<span class="jv ${c === null ? "null" : typeof c}">${JSON.stringify(c)}</span>
5349
+ </div>`;
5350
+ };
5351
+ return o`<div class="code json" part="json">
5352
+ <div class="code-head">
5353
+ <span class="label">json</span>
5354
+ <button type="button" class="text-btn" @click=${() => this.copy(s, t)}>
5355
+ ${this.copiedKey === s ? this.msg.copied : this.msg.copy}
5356
+ </button>
5357
+ </div>
5358
+ <div class="jtree">${r(e, 0)}</div>
5359
+ </div>`;
5360
+ }
4510
5361
  renderChart(e) {
4511
- const t = e.series.length > 1 ? r`<span class="legend">
5362
+ const t = e.series.length > 1 ? o`<span class="legend">
4512
5363
  ${e.series.map(
4513
- (o, l) => r`<span
5364
+ (r, c) => o`<span
4514
5365
  ><span
4515
5366
  class="swatch"
4516
- style="background:${_[l % _.length]}"
5367
+ style="background:${j[c % j.length]}"
4517
5368
  ></span
4518
- >${o.name}</span
5369
+ >${r.name}</span
4519
5370
  >`
4520
5371
  )}
4521
- </span>` : m, i = r`<div class="chart-head">
5372
+ </span>` : m, s = o`<div class="chart-head">
4522
5373
  <span class="chart-title">${e.title}</span>${t}
4523
5374
  </div>`;
4524
5375
  if (e.type === "line") {
4525
- const o = Math.max(0, ...e.series.flatMap((f) => f.values)), l = Math.pow(10, Math.floor(Math.log10(o || 1))), c = Math.ceil(o / l * 2) / 2 * l || 1, x = Math.max(e.labels.length, ...e.series.map((f) => f.values.length));
4526
- return r`<figure class="chart" part="chart" aria-label=${e.title}>
4527
- ${i}
5376
+ const r = Math.max(0, ...e.series.flatMap((b) => b.values)), c = Math.pow(10, Math.floor(Math.log10(r || 1))), l = Math.ceil(r / c * 2) / 2 * c || 1, f = Math.max(e.labels.length, ...e.series.map((b) => b.values.length));
5377
+ return o`<figure class="chart" part="chart" aria-label=${e.title}>
5378
+ ${s}
4528
5379
  <div class="line-chart">
4529
5380
  <div class="plot">
4530
5381
  ${[1, 0.5, 0].map(
4531
- (f) => r`<div class="tick ${f === 0 ? "base" : ""}" style="top:${(1 - f) * 100}%">
4532
- <span>${Fe(Math.round(c * f), e.unit)}</span>
5382
+ (b) => o`<div class="tick ${b === 0 ? "base" : ""}" style="top:${(1 - b) * 100}%">
5383
+ <span>${mt(Math.round(l * b), e.unit)}</span>
4533
5384
  </div>`
4534
5385
  )}
4535
5386
  <svg
@@ -4539,38 +5390,38 @@ ${x.map((b) => `[${b.n}] ${b.title}`).join(`
4539
5390
  aria-label=${e.title}
4540
5391
  >
4541
5392
  ${e.series.map(
4542
- (f, O) => $`<polyline pathLength="1" stroke=${_[O % _.length]}
4543
- points=${f.values.map(
4544
- (S, b) => `${(x > 1 ? b / (x - 1) * 600 : 300).toFixed(1)},${(170 - S / c * 170).toFixed(1)}`
5393
+ (b, C) => O`<polyline pathLength="1" stroke=${j[C % j.length]}
5394
+ points=${b.values.map(
5395
+ (T, w) => `${(f > 1 ? w / (f - 1) * 600 : 300).toFixed(1)},${(170 - T / l * 170).toFixed(1)}`
4545
5396
  ).join(
4546
5397
  " "
4547
- )}><title>${f.name}: ${f.values.map((S) => Fe(S, e.unit)).join(", ")}</title></polyline>`
5398
+ )}><title>${b.name}: ${b.values.map((T) => mt(T, e.unit)).join(", ")}</title></polyline>`
4548
5399
  )}
4549
5400
  </svg>
4550
5401
  </div>
4551
- <div class="x-labels">${e.labels.map((f) => r`<span>${f}</span>`)}</div>
5402
+ <div class="x-labels">${e.labels.map((b) => o`<span>${b}</span>`)}</div>
4552
5403
  </div>
4553
5404
  </figure>`;
4554
5405
  }
4555
- const s = e.labels.map(
4556
- (o, l) => e.series.reduce((c, x) => c + (x.values[l] || 0), 0)
4557
- ), a = Math.max(0, ...s) || 1;
4558
- return r`<figure class="chart" part="chart" aria-label=${e.title}>
4559
- ${i}
5406
+ const i = e.labels.map(
5407
+ (r, c) => e.series.reduce((l, f) => l + (f.values[c] || 0), 0)
5408
+ ), a = Math.max(0, ...i) || 1;
5409
+ return o`<figure class="chart" part="chart" aria-label=${e.title}>
5410
+ ${s}
4560
5411
  <div class="bars">
4561
5412
  ${e.labels.map(
4562
- (o, l) => r`<div class="bar-row" title="${o}: ${Fe(s[l], e.unit)}">
4563
- <span class="bar-label">${o}</span>
5413
+ (r, c) => o`<div class="bar-row" title="${r}: ${mt(i[c], e.unit)}">
5414
+ <span class="bar-label">${r}</span>
4564
5415
  <span class="bar-track"
4565
- ><span class="bar-fill" style="width:${Math.max(0, s[l]) / a * 100}%">
5416
+ ><span class="bar-fill" style="width:${Math.max(0, i[c]) / a * 100}%">
4566
5417
  ${e.series.map(
4567
- (c, x) => r`<span
4568
- style="flex:${Math.max(0, c.values[l] || 0)};background:${e.series.length > 1 ? _[x % _.length] : "var(--c-ink)"}"
5418
+ (l, f) => o`<span
5419
+ style="flex:${Math.max(0, l.values[c] || 0)};background:${e.series.length > 1 ? j[f % j.length] : "var(--c-ink)"}"
4569
5420
  ></span>`
4570
5421
  )}
4571
5422
  </span></span
4572
5423
  >
4573
- <span class="bar-value">${Fe(s[l], e.unit)}</span>
5424
+ <span class="bar-value">${mt(i[c], e.unit)}</span>
4574
5425
  </div>`
4575
5426
  )}
4576
5427
  </div>
@@ -4578,23 +5429,25 @@ ${x.map((b) => `[${b.n}] ${b.title}`).join(`
4578
5429
  }
4579
5430
  renderPanel() {
4580
5431
  if (!this.panel) return m;
4581
- const e = this.msgs.find((f) => f.key === this.panel.key), t = e == null ? void 0 : e.sources[this.panel.n - 1];
4582
- if (!e || !t) return m;
4583
- const i = this.msg, s = Ke(t, this.panel.n), a = Ze(e.content), o = e.sources.map((f, O) => Ke(f, O + 1)).filter((f) => f.n !== s.n && (!a.size || a.has(f.n))), l = `ref:${e.key}:${s.n}`, c = `"${s.text}"
5432
+ const e = this.msgs.find((b) => b.key === this.panel.key);
5433
+ if (!e) return m;
5434
+ const t = e.sources.map((b, C) => ft(b, C + 1)), s = t.find((b) => b.n === this.panel.n);
5435
+ if (!s) return m;
5436
+ const i = this.msg, a = Ot(e.content), r = t.filter((b) => b.n !== s.n && (!a.size || a.has(b.n))), c = `ref:${e.key}:${s.n}`, l = `"${s.text}"
4584
5437
  — ${s.title} [${s.n}]${s.path ? `
4585
- ${s.path}` : ""}${s.updated ? ` · Updated ${s.updated}` : ""}`, x = [
5438
+ ${s.path}` : ""}${s.updated ? ` · Updated ${s.updated}` : ""}`, f = [
4586
5439
  s.updated ? `Updated ${s.updated}` : "",
4587
5440
  s.score !== null ? `Relevance ${s.score.toFixed(2)}` : ""
4588
5441
  ].filter(Boolean).join(" · ");
4589
- return r`<aside
5442
+ return o`<aside
4590
5443
  class="panel ${this.panelDocked ? "docked" : "overlay"}"
4591
5444
  part="panel"
4592
5445
  role="region"
4593
- aria-label=${z(i.sourceLabel, { n: s.n })}
5446
+ aria-label=${_(i.sourceLabel, { n: s.n })}
4594
5447
  >
4595
5448
  <div class="panel-head">
4596
5449
  <span class="label"
4597
- >${z(i.sourceLabel, { n: s.n })}${s.collection ? ` · ${s.collection}` : ""}</span
5450
+ >${_(i.sourceLabel, { n: s.n })}${s.collection ? ` · ${s.collection}` : ""}</span
4598
5451
  >
4599
5452
  <button type="button" class="text-btn underline" @click=${() => this.panel = null}>
4600
5453
  ${i.close}
@@ -4603,8 +5456,9 @@ ${s.path}` : ""}${s.updated ? ` · Updated ${s.updated}` : ""}`, x = [
4603
5456
  <div class="panel-body">
4604
5457
  <div class="panel-meta">
4605
5458
  <h3>${s.title}</h3>
4606
- ${s.path ? r`<span class="path">${s.path}</span>` : m}
4607
- ${x ? r`<span class="meta">${x}</span>` : m}
5459
+ ${s.section ? o`<span class="meta">${s.section}</span>` : m}
5460
+ ${s.path ? o`<span class="path">${s.path}</span>` : m}
5461
+ ${f ? o`<span class="meta">${f}</span>` : m}
4608
5462
  </div>
4609
5463
  <div class="passage-box">
4610
5464
  <span class="text">${s.text}</span>
@@ -4615,23 +5469,23 @@ ${s.path}` : ""}${s.updated ? ` · Updated ${s.updated}` : ""}`, x = [
4615
5469
  class="copy-ref"
4616
5470
  title=${i.copyReference}
4617
5471
  aria-label=${i.copyReference}
4618
- @click=${() => this.copy(l, c)}
5472
+ @click=${() => this.copy(c, l)}
4619
5473
  >
4620
- ${y.copy()}<span>${this.copiedKey === l ? i.copied : i.copy}</span>
5474
+ ${k.copy()}<span>${this.copiedKey === c ? i.copied : i.copy}</span>
4621
5475
  </button>
4622
5476
  </div>
4623
5477
  </div>
4624
5478
  </div>
4625
- ${o.length ? r`<div class="panel-foot">
5479
+ ${r.length ? o`<div class="panel-foot">
4626
5480
  <span class="label">${i.alsoCited}</span>
4627
5481
  <div class="chips">
4628
- ${o.map(
4629
- (f) => r`<button
5482
+ ${r.map(
5483
+ (b) => o`<button
4630
5484
  type="button"
4631
5485
  class="chip"
4632
- @click=${() => this.panel = { key: e.key, n: f.n }}
5486
+ @click=${() => this.panel = { key: e.key, n: b.n }}
4633
5487
  >
4634
- ${f.n} · ${f.title}
5488
+ ${b.n} · ${b.title}
4635
5489
  </button>`
4636
5490
  )}
4637
5491
  </div>
@@ -4639,35 +5493,56 @@ ${s.path}` : ""}${s.updated ? ` · Updated ${s.updated}` : ""}`, x = [
4639
5493
  </aside>`;
4640
5494
  }
4641
5495
  renderComposer() {
4642
- const e = this.msg, t = this.mode === "rag" ? e.placeholderRag : this.mode === "rich" ? e.placeholderRich : z(e.placeholderChat, { name: this.assistantName }), i = !this.draft.trim();
4643
- return r`<div class="composer-wrap">
5496
+ const e = this.msg, t = this.mode === "rag" ? e.placeholderRag : this.mode === "kb" ? e.placeholderKb : _(e.placeholderChat, { name: this.assistantName }), s = !this.draft.trim(), i = this.footnote === "" ? m : o`<span class="footnote" part="footnote"
5497
+ >${this.footnote ?? _(e.footnote, { name: this.assistantName })}</span
5498
+ >`;
5499
+ return this.showComposer ? o`<div class="composer-wrap">
4644
5500
  <div class="composer-col">
4645
5501
  <input
4646
5502
  type="file"
4647
5503
  multiple
4648
5504
  hidden
4649
5505
  accept=".md,.markdown,.txt,.csv,.tsv,.json,.html,.htm,.yaml,.yml,.xml,.log,text/*"
4650
- @change=${(s) => {
4651
- const a = s.target;
4652
- this.addFiles(a.files).then(() => a.value = "");
5506
+ @change=${(a) => {
5507
+ const r = a.target;
5508
+ this.addFiles(r.files).then(() => r.value = "");
4653
5509
  }}
4654
5510
  />
4655
5511
  <div class="composer-box">
4656
- ${this.busy ? r`<div class="composer-glow"></div>` : m}
5512
+ ${this.busy ? o`<div class="composer-glow"></div>` : m}
4657
5513
  <div class="composer ${this.busy ? "busy" : ""}" part="composer">
4658
- ${this.files.length ? r`<div class="pending-files">
5514
+ ${this.savedFiles.length ? o`<div class="pending-files" part="saved-files">
5515
+ ${this.savedFiles.map(
5516
+ (a) => o`<div class="pending-file kept">
5517
+ <span class="ext">${xt(a.name)}</span>
5518
+ <span class="meta"
5519
+ ><span class="name">${a.name}</span
5520
+ ><span class="size">${e.inThisChat}</span></span
5521
+ >
5522
+ <button
5523
+ type="button"
5524
+ aria-label=${e.removeFromChat}
5525
+ title=${e.removeFromChat}
5526
+ @click=${() => this.removeSavedFile(a)}
5527
+ >
5528
+ ×
5529
+ </button>
5530
+ </div>`
5531
+ )}
5532
+ </div>` : m}
5533
+ ${this.files.length ? o`<div class="pending-files">
4659
5534
  ${this.files.map(
4660
- (s) => r`<div class="pending-file">
4661
- <span class="ext">${ct(s.name)}</span>
5535
+ (a) => o`<div class="pending-file">
5536
+ <span class="ext">${xt(a.name)}</span>
4662
5537
  <span class="meta"
4663
- ><span class="name">${s.name}</span
4664
- ><span class="size">${Ve(s.size)}</span></span
5538
+ ><span class="name">${a.name}</span
5539
+ ><span class="size">${kt(a.size)}</span></span
4665
5540
  >
4666
5541
  <button
4667
5542
  type="button"
4668
5543
  aria-label=${e.removeFile}
4669
5544
  title=${e.removeFile}
4670
- @click=${() => this.files = this.files.filter((a) => a !== s)}
5545
+ @click=${() => this.files = this.files.filter((r) => r !== a)}
4671
5546
  >
4672
5547
  ×
4673
5548
  </button>
@@ -4685,242 +5560,327 @@ ${s.path}` : ""}${s.updated ? ` · Updated ${s.updated}` : ""}`, x = [
4685
5560
  ></textarea>
4686
5561
  <div class="composer-row">
4687
5562
  <div>
4688
- ${this.allowUpload ? r`<button
5563
+ ${this.allowUpload ? o`<button
4689
5564
  type="button"
4690
5565
  class="attach"
4691
5566
  title=${e.attach}
4692
5567
  aria-label=${e.attach}
4693
5568
  @click=${() => {
4694
- var s;
4695
- return (s = this.renderRoot.querySelector("input[type=file]")) == null ? void 0 : s.click();
5569
+ var a;
5570
+ return (a = this.renderRoot.querySelector("input[type=file]")) == null ? void 0 : a.click();
4696
5571
  }}
4697
5572
  >
4698
- ${y.clip()}
5573
+ ${k.clip()}
4699
5574
  </button>` : m}
4700
5575
  </div>
4701
- ${this.busy ? r`<button
5576
+ ${this.busy ? o`<button
4702
5577
  type="button"
4703
5578
  class="send stop"
4704
5579
  title=${e.stop}
4705
5580
  aria-label=${e.stop}
4706
5581
  @click=${() => this.stop()}
4707
5582
  >
4708
- ${y.stop()}
4709
- </button>` : r`<button
5583
+ ${k.stop()}
5584
+ </button>` : o`<button
4710
5585
  type="button"
4711
5586
  class="send"
4712
5587
  title=${e.send}
4713
5588
  aria-label=${e.send}
4714
- ?disabled=${i}
5589
+ ?disabled=${s}
4715
5590
  @click=${() => this.send()}
4716
5591
  >
4717
- ${y.up()}
5592
+ ${k.up()}
4718
5593
  </button>`}
4719
5594
  </div>
4720
5595
  </div>
4721
- ${this.busy ? r`<div class="composer-ring"><div class="ring"></div></div>` : m}
5596
+ ${this.busy ? o`<div class="composer-ring"><div class="ring"></div></div>` : m}
4722
5597
  </div>
4723
- <span class="footnote">${z(e.footnote, { name: this.assistantName })}</span>
5598
+ ${i}
4724
5599
  </div>
4725
- </div>`;
5600
+ </div>` : o`<div class="composer-wrap reader">
5601
+ <div class="composer-col">${i}</div>
5602
+ </div>`;
4726
5603
  }
4727
- }, j = new WeakMap(), A = new WeakMap(), E = new WeakMap(), N = new WeakMap(), B = new WeakMap(), D = new WeakMap(), R = new WeakMap(), U = new WeakMap(), F = new WeakMap(), K = new WeakMap(), P = new WeakMap(), H = new WeakMap(), J = new WeakMap(), W = new WeakMap(), q = new WeakMap(), G = new WeakMap(), V = new WeakMap(), X = new WeakMap(), Y = new WeakMap(), Q = new WeakMap(), Z = new WeakMap(), ee = new WeakMap(), te = new WeakMap(), ie = new WeakMap(), se = new WeakMap(), ae = new WeakMap(), re = new WeakMap(), ne = new WeakMap(), oe = new WeakMap(), le = new WeakMap(), ce = new WeakMap(), de = new WeakMap(), pe = new WeakMap(), he = new WeakMap(), ue = new WeakMap(), ge = new WeakMap(), me = new WeakMap(), be = new WeakMap(), fe = new WeakMap(), xe = new WeakMap(), ve = new WeakMap(), ye = new WeakMap(), ke = new WeakMap(), we = new WeakMap(), $e = new WeakMap(), Te = new WeakMap(), Ce = new WeakMap(), Se = new WeakMap(), ze = new WeakMap(), Oe = new WeakMap(), Me = new WeakMap(), _e = new WeakMap(), Ie = new WeakMap(), Le = new WeakMap(), je = new WeakMap(), Ae = new WeakMap(), Ee = new WeakMap(), Ne = new WeakMap(), Be = new WeakMap(), De = new WeakMap(), Re = new WeakMap(), dt);
4728
- Nt(d, "styles", [kt, wt]);
5604
+ }, N = new WeakMap(), R = new WeakMap(), E = new WeakMap(), B = new WeakMap(), D = new WeakMap(), F = new WeakMap(), K = new WeakMap(), P = new WeakMap(), U = new WeakMap(), W = new WeakMap(), H = new WeakMap(), J = new WeakMap(), G = new WeakMap(), q = new WeakMap(), V = new WeakMap(), X = new WeakMap(), Y = new WeakMap(), Q = new WeakMap(), Z = new WeakMap(), ee = new WeakMap(), te = new WeakMap(), se = new WeakMap(), ie = new WeakMap(), ae = new WeakMap(), re = new WeakMap(), oe = new WeakMap(), ne = new WeakMap(), le = new WeakMap(), ce = new WeakMap(), de = new WeakMap(), pe = new WeakMap(), he = new WeakMap(), ue = new WeakMap(), ge = new WeakMap(), me = new WeakMap(), fe = new WeakMap(), be = new WeakMap(), xe = new WeakMap(), ve = new WeakMap(), we = new WeakMap(), ye = new WeakMap(), ke = new WeakMap(), $e = new WeakMap(), Ce = new WeakMap(), Te = new WeakMap(), Se = new WeakMap(), Ie = new WeakMap(), Oe = new WeakMap(), Me = new WeakMap(), ze = new WeakMap(), _e = new WeakMap(), Le = new WeakMap(), Ae = new WeakMap(), je = new WeakMap(), Ne = new WeakMap(), Re = new WeakMap(), Ee = new WeakMap(), Be = new WeakMap(), De = new WeakMap(), Fe = new WeakMap(), Ke = new WeakMap(), Pe = new WeakMap(), Ue = new WeakMap(), We = new WeakMap(), He = new WeakMap(), Je = new WeakMap(), Ge = new WeakMap(), qe = new WeakMap(), Ve = new WeakMap(), Xe = new WeakMap(), Ye = new WeakMap(), Qe = new WeakMap(), Ze = new WeakMap(), et = new WeakMap(), tt = new WeakMap(), st = new WeakMap(), it = new WeakMap(), at = new WeakMap(), rt = new WeakMap(), ot = new WeakMap(), nt = new WeakMap(), lt = new WeakMap(), ct = new WeakMap(), dt = new WeakMap(), pt = new WeakMap(), ht = new WeakMap(), ut = new WeakMap(), gt = new WeakMap(), Ft);
5605
+ $s(d, "styles", [Yt, Qt, Zt]);
4729
5606
  g([
4730
- w({ attribute: !1 })
5607
+ v({ attribute: !1 })
4731
5608
  ], d.prototype, "client", 1);
4732
5609
  g([
4733
- w({ attribute: !1 })
5610
+ v({ attribute: !1 })
4734
5611
  ], d.prototype, "messages", 1);
4735
5612
  g([
4736
- w({ reflect: !0 })
5613
+ v({ reflect: !0 })
4737
5614
  ], d.prototype, "theme", 1);
4738
5615
  g([
4739
- w({ reflect: !0 })
5616
+ v({ reflect: !0 })
5617
+ ], d.prototype, "radius", 1);
5618
+ g([
5619
+ v({ reflect: !0 })
4740
5620
  ], d.prototype, "mode", 1);
4741
5621
  g([
4742
- w({ attribute: "render-as" })
4743
- ], d.prototype, "renderAs", 1);
5622
+ v({ reflect: !0 })
5623
+ ], d.prototype, "format", 1);
5624
+ g([
5625
+ v({ attribute: !1 })
5626
+ ], d.prototype, "renderers", 1);
4744
5627
  g([
4745
- w({ reflect: !0 })
5628
+ v({ attribute: !1 })
5629
+ ], d.prototype, "beforeSend", 1);
5630
+ g([
5631
+ v({ attribute: !1 })
5632
+ ], d.prototype, "afterParse", 1);
5633
+ g([
5634
+ v({ reflect: !0 })
4746
5635
  ], d.prototype, "glow", 1);
4747
5636
  g([
4748
- w({ converter: I })
5637
+ v()
5638
+ ], d.prototype, "docsets", 1);
5639
+ g([
5640
+ v({ attribute: "attachments-mode" })
5641
+ ], d.prototype, "attachmentsMode", 1);
5642
+ g([
5643
+ v({ converter: I, attribute: "save-attachments" })
5644
+ ], d.prototype, "saveAttachments", 1);
5645
+ g([
5646
+ v({ converter: I })
4749
5647
  ], d.prototype, "followups", 1);
4750
5648
  g([
4751
- w({ converter: I, attribute: "auto-title" })
5649
+ v({ converter: I, attribute: "show-sources" })
5650
+ ], d.prototype, "showSources", 1);
5651
+ g([
5652
+ v({ converter: I, attribute: "show-new-chat" })
5653
+ ], d.prototype, "showNewChat", 1);
5654
+ g([
5655
+ v({ converter: I, attribute: "show-bookmarked" })
5656
+ ], d.prototype, "showBookmarked", 1);
5657
+ g([
5658
+ v({ converter: I, attribute: "show-followups" })
5659
+ ], d.prototype, "showFollowups", 1);
5660
+ g([
5661
+ v({ converter: I, attribute: "allow-search" })
5662
+ ], d.prototype, "allowSearch", 1);
5663
+ g([
5664
+ v({ converter: I, attribute: "auto-title" })
4752
5665
  ], d.prototype, "autoTitle", 1);
4753
5666
  g([
4754
- w()
5667
+ v()
4755
5668
  ], d.prototype, "model", 1);
4756
5669
  g([
4757
- w({ converter: We })
5670
+ v({ converter: vt })
4758
5671
  ], d.prototype, "params", 1);
4759
5672
  g([
4760
- w({ attribute: "system-message" })
5673
+ v({ attribute: "system-message" })
4761
5674
  ], d.prototype, "systemMessage", 1);
4762
5675
  g([
4763
- w({ converter: We })
5676
+ v({ converter: vt })
4764
5677
  ], d.prototype, "retrieval", 1);
4765
5678
  g([
4766
- w({ converter: We })
5679
+ v({ converter: vt })
4767
5680
  ], d.prototype, "metadata", 1);
4768
5681
  g([
4769
- w({ reflect: !0 })
5682
+ v({ reflect: !0 })
4770
5683
  ], d.prototype, "embed", 1);
4771
5684
  g([
4772
- w({ reflect: !0 })
5685
+ v({ reflect: !0 })
4773
5686
  ], d.prototype, "position", 1);
4774
5687
  g([
4775
- w({ converter: Bt })
5688
+ v({ converter: Cs })
4776
5689
  ], d.prototype, "sidebar", 1);
4777
5690
  g([
4778
- w({ converter: I, attribute: "show-title" })
5691
+ v({ converter: I, attribute: "show-title" })
4779
5692
  ], d.prototype, "showTitle", 1);
4780
5693
  g([
4781
- w({ attribute: "chat-id" })
5694
+ v({ attribute: "chat-id" })
4782
5695
  ], d.prototype, "chatIdAttr", 1);
4783
5696
  g([
4784
- w({ attribute: "assistant-name" })
5697
+ v({ attribute: "assistant-name" })
4785
5698
  ], d.prototype, "assistantName", 1);
4786
5699
  g([
4787
- w({ attribute: "logo-url" })
5700
+ v({ attribute: "logo-url" })
4788
5701
  ], d.prototype, "logoUrl", 1);
4789
5702
  g([
4790
- w()
5703
+ v()
4791
5704
  ], d.prototype, "heading", 1);
4792
5705
  g([
4793
- w()
5706
+ v()
4794
5707
  ], d.prototype, "description", 1);
4795
5708
  g([
4796
- w()
5709
+ v()
5710
+ ], d.prototype, "eyebrow", 1);
5711
+ g([
5712
+ v()
4797
5713
  ], d.prototype, "prompts", 1);
4798
5714
  g([
4799
- w({ attribute: "bubble-text" })
5715
+ v({ attribute: "bubble-text" })
4800
5716
  ], d.prototype, "bubbleText", 1);
4801
5717
  g([
4802
- w({ type: Boolean, attribute: "greeting-bubble" })
5718
+ v({ type: Boolean, attribute: "greeting-bubble" })
4803
5719
  ], d.prototype, "greetingBubble", 1);
4804
5720
  g([
4805
- w({ type: Boolean, attribute: "unread-badge" })
5721
+ v({ type: Boolean, attribute: "unread-badge" })
4806
5722
  ], d.prototype, "unreadBadge", 1);
4807
5723
  g([
4808
- w({ converter: I, attribute: "allow-upload" })
5724
+ v({ converter: I, attribute: "allow-upload" })
4809
5725
  ], d.prototype, "allowUpload", 1);
4810
5726
  g([
4811
- w({ converter: I, attribute: "allow-export" })
5727
+ v({ converter: I, attribute: "allow-export" })
4812
5728
  ], d.prototype, "allowExport", 1);
4813
5729
  g([
4814
- w({ converter: I })
4815
- ], d.prototype, "branding", 1);
5730
+ v({ converter: I, attribute: "allow-copy" })
5731
+ ], d.prototype, "allowCopy", 1);
5732
+ g([
5733
+ v({ converter: I, attribute: "allow-regenerate" })
5734
+ ], d.prototype, "allowRegenerate", 1);
5735
+ g([
5736
+ v({ converter: I, attribute: "allow-bookmark" })
5737
+ ], d.prototype, "allowBookmark", 1);
5738
+ g([
5739
+ v({ converter: I, attribute: "allow-delete" })
5740
+ ], d.prototype, "allowDelete", 1);
5741
+ g([
5742
+ v({ converter: I, attribute: "allow-rename" })
5743
+ ], d.prototype, "allowRename", 1);
5744
+ g([
5745
+ v({ converter: I, attribute: "allow-feedback" })
5746
+ ], d.prototype, "allowFeedback", 1);
5747
+ g([
5748
+ v({ converter: I, attribute: "show-composer" })
5749
+ ], d.prototype, "showComposer", 1);
5750
+ g([
5751
+ v({ converter: I, attribute: "show-time" })
5752
+ ], d.prototype, "showTime", 1);
4816
5753
  g([
4817
5754
  v()
5755
+ ], d.prototype, "footnote", 1);
5756
+ g([
5757
+ v({ type: Boolean, attribute: "allow-raw" })
5758
+ ], d.prototype, "allowRaw", 1);
5759
+ g([
5760
+ v({ converter: I })
5761
+ ], d.prototype, "branding", 1);
5762
+ g([
5763
+ y()
4818
5764
  ], d.prototype, "chatList", 1);
4819
5765
  g([
4820
- v()
5766
+ y()
4821
5767
  ], d.prototype, "listState", 1);
4822
5768
  g([
4823
- v()
5769
+ y()
4824
5770
  ], d.prototype, "activeId", 1);
4825
5771
  g([
4826
- v()
5772
+ y()
4827
5773
  ], d.prototype, "chatTitle", 1);
4828
5774
  g([
4829
- v()
5775
+ y()
4830
5776
  ], d.prototype, "bookmarked", 1);
4831
5777
  g([
4832
- v()
5778
+ y()
4833
5779
  ], d.prototype, "msgs", 1);
4834
5780
  g([
4835
- v()
5781
+ y()
4836
5782
  ], d.prototype, "loadingThread", 1);
4837
5783
  g([
4838
- v()
5784
+ y()
4839
5785
  ], d.prototype, "threadError", 1);
4840
5786
  g([
4841
- v()
5787
+ y()
4842
5788
  ], d.prototype, "busy", 1);
4843
5789
  g([
4844
- v()
5790
+ y()
4845
5791
  ], d.prototype, "draft", 1);
4846
5792
  g([
4847
- v()
5793
+ y()
4848
5794
  ], d.prototype, "files", 1);
4849
5795
  g([
4850
- v()
5796
+ y()
4851
5797
  ], d.prototype, "search", 1);
4852
5798
  g([
4853
- v()
5799
+ y()
4854
5800
  ], d.prototype, "sidebarOpen", 1);
4855
5801
  g([
4856
- v()
5802
+ y()
4857
5803
  ], d.prototype, "width", 1);
4858
5804
  g([
4859
- v()
5805
+ y()
4860
5806
  ], d.prototype, "panel", 1);
4861
5807
  g([
4862
- v()
5808
+ y()
4863
5809
  ], d.prototype, "menuOpen", 1);
4864
5810
  g([
4865
- v()
5811
+ y()
4866
5812
  ], d.prototype, "editingKey", 1);
4867
5813
  g([
4868
- v()
5814
+ y()
4869
5815
  ], d.prototype, "editDraft", 1);
4870
5816
  g([
4871
- v()
5817
+ y()
4872
5818
  ], d.prototype, "editingTitle", 1);
4873
5819
  g([
4874
- v()
5820
+ y()
4875
5821
  ], d.prototype, "renamingId", 1);
4876
5822
  g([
4877
- v()
5823
+ y()
4878
5824
  ], d.prototype, "toast", 1);
4879
5825
  g([
4880
- v()
5826
+ y()
4881
5827
  ], d.prototype, "copiedKey", 1);
4882
5828
  g([
4883
- v()
5829
+ y()
4884
5830
  ], d.prototype, "retrievalOpen", 1);
4885
5831
  g([
4886
- v()
5832
+ y()
5833
+ ], d.prototype, "rawKeys", 1);
5834
+ g([
5835
+ y()
5836
+ ], d.prototype, "savedFiles", 1);
5837
+ g([
5838
+ y()
5839
+ ], d.prototype, "hasSidebarContent", 1);
5840
+ g([
5841
+ y()
5842
+ ], d.prototype, "sorts", 1);
5843
+ g([
5844
+ y()
4887
5845
  ], d.prototype, "arrivedKey", 1);
4888
5846
  g([
4889
- v()
5847
+ y()
4890
5848
  ], d.prototype, "dragging", 1);
4891
5849
  g([
4892
- v()
5850
+ y()
4893
5851
  ], d.prototype, "showJump", 1);
4894
5852
  g([
4895
- v()
5853
+ y()
4896
5854
  ], d.prototype, "offline", 1);
4897
5855
  g([
4898
- v()
5856
+ y()
4899
5857
  ], d.prototype, "isOpen", 1);
4900
5858
  g([
4901
- v()
5859
+ y()
4902
5860
  ], d.prototype, "expanded", 1);
4903
5861
  g([
4904
- v()
5862
+ y()
4905
5863
  ], d.prototype, "bubble", 1);
4906
5864
  g([
4907
- v()
5865
+ y()
4908
5866
  ], d.prototype, "seen", 1);
4909
5867
  g([
4910
- v()
5868
+ y()
4911
5869
  ], d.prototype, "mobile", 1);
4912
5870
  d = g([
4913
- xt("singlebase-chat")
5871
+ Gt("singlebase-chat")
4914
5872
  ], d);
4915
5873
  export {
4916
5874
  d as S,
4917
- _t as a,
4918
- Ke as b,
4919
- Ze as c,
4920
- $t as d,
4921
- zt as e,
4922
- Mt as p,
4923
- Tt as r,
4924
- tt as s
5875
+ gs as a,
5876
+ ft as b,
5877
+ Ot as c,
5878
+ es as d,
5879
+ os as e,
5880
+ zt as f,
5881
+ ws as g,
5882
+ ds as p,
5883
+ ts as r,
5884
+ ps as s
4925
5885
  };
4926
- //# sourceMappingURL=chat-bXaRWel7.js.map
5886
+ //# sourceMappingURL=chat-BH_3e1jT.js.map