@twentyfourg/chat-kit 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +222 -0
  3. package/dist/chat-kit.js +1914 -0
  4. package/dist/chat-kit.js.map +1 -0
  5. package/dist/components/AssistantMessage.vue.d.ts +35 -0
  6. package/dist/components/Chat.vue.d.ts +72 -0
  7. package/dist/components/CitationPopover.vue.d.ts +11 -0
  8. package/dist/components/FeedbackRow.vue.d.ts +11 -0
  9. package/dist/components/IconButton.vue.d.ts +17 -0
  10. package/dist/components/InputBar.vue.d.ts +16 -0
  11. package/dist/components/KitIcon.vue.d.ts +12 -0
  12. package/dist/components/MessageList.vue.d.ts +36 -0
  13. package/dist/components/PageImageModal.vue.d.ts +14 -0
  14. package/dist/components/SourceCard.vue.d.ts +21 -0
  15. package/dist/components/SourceList.vue.d.ts +7 -0
  16. package/dist/components/ThinkingAnimation.vue.d.ts +15 -0
  17. package/dist/components/ThinkingIndicator.vue.d.ts +13 -0
  18. package/dist/components/ThinkingProcess.vue.d.ts +8 -0
  19. package/dist/components/UserMessage.vue.d.ts +7 -0
  20. package/dist/composables/useAutoScroll.d.ts +36 -0
  21. package/dist/composables/useChatEngine.d.ts +335 -0
  22. package/dist/composables/useDictation.d.ts +29 -0
  23. package/dist/copy.d.ts +144 -0
  24. package/dist/index.css +1 -0
  25. package/dist/index.d.ts +18 -0
  26. package/dist/services/anonymous-auth.d.ts +63 -0
  27. package/dist/services/base-camp-client.d.ts +66 -0
  28. package/dist/services/citations.d.ts +18 -0
  29. package/dist/services/entities.d.ts +29 -0
  30. package/dist/services/markdown.d.ts +47 -0
  31. package/dist/services/math.d.ts +36 -0
  32. package/dist/services/streaming-message.d.ts +32 -0
  33. package/dist/services/streaming.service.d.ts +84 -0
  34. package/dist/services/typewriter.d.ts +54 -0
  35. package/dist/testing/mock-transport.d.ts +52 -0
  36. package/dist/testing/setup-tests.d.ts +8 -0
  37. package/dist/theme.css +122 -0
  38. package/dist/types.d.ts +389 -0
  39. package/package.json +76 -0
@@ -0,0 +1,1914 @@
1
+ import { Fragment as e, Teleport as t, computed as n, createBlock as r, createCommentVNode as i, createElementBlock as a, createElementVNode as o, createSlots as s, createTextVNode as c, createVNode as l, defineComponent as u, inject as d, nextTick as f, normalizeClass as p, normalizeStyle as m, onBeforeUnmount as h, onMounted as g, onScopeDispose as _, openBlock as v, provide as y, reactive as b, readonly as x, ref as S, renderList as C, renderSlot as w, shallowRef as T, toDisplayString as E, unref as D, useSlots as O, vModelText as k, watch as A, withCtx as j, withDirectives as M, withKeys as N, withModifiers as P } from "vue";
2
+ import F from "dompurify";
3
+ import { Marked as I } from "marked";
4
+ import './index.css';//#region src/copy.ts
5
+ var L = {
6
+ welcome: {
7
+ eyebrow: "",
8
+ heading: "How can I help?",
9
+ body: "Ask a question to get started."
10
+ },
11
+ roles: {
12
+ assistant: "Assistant",
13
+ user: "You"
14
+ },
15
+ composer: {
16
+ placeholder: "Ask a question...",
17
+ micUnsupported: "Voice input is not supported in this browser.",
18
+ dictateLabel: "Dictate",
19
+ sendLabel: "Send",
20
+ stopLabel: "Stop"
21
+ },
22
+ status: {
23
+ thinking: "Thinking…",
24
+ error: "Something went wrong while generating a response. Please try again.",
25
+ retryLabel: "Retry",
26
+ rateLimited: "Something went wrong while generating a response. Please try again.",
27
+ thinkingSequence: [
28
+ "Analyzing your question…",
29
+ "Working to understand your question and finding the most relevant content…",
30
+ "Processing your query…",
31
+ "Searching the knowledge base…",
32
+ "Connecting related concepts across the material…"
33
+ ]
34
+ },
35
+ feedback: { question: "Was this helpful?" },
36
+ sources: {
37
+ openSourceLabel: "Open source",
38
+ citedPassageLabel: "Cited passage",
39
+ noticeLine: "",
40
+ copyUrlLabel: "Copy URL",
41
+ copiedLabel: "Copied!",
42
+ introLine: "",
43
+ sourceLabel: "Source {n}",
44
+ referenceLabel: "References",
45
+ pageLabel: "Page {page}",
46
+ textPageLabel: "Text page {textPage}",
47
+ expandLabel: "Show source details",
48
+ collapseLabel: "Hide source details",
49
+ closeLabel: "Close"
50
+ },
51
+ outOfScope: { label: "Outside this assistant’s scope" },
52
+ reasoning: {
53
+ showLabel: "Show thinking",
54
+ hideLabel: "Hide thinking"
55
+ },
56
+ actions: {
57
+ copyLabel: "Copy answer",
58
+ copiedLabel: "Copied!"
59
+ }
60
+ };
61
+ function R(e, t) {
62
+ return e.replace(/\{(\w+)\}/g, (e, n) => n in t ? String(t[n]) : e);
63
+ }
64
+ function ee(e) {
65
+ return typeof e == "object" && !!e && !Array.isArray(e);
66
+ }
67
+ var te = /* @__PURE__ */ new Set([
68
+ "status.rateLimited",
69
+ "status.thinkingSequence",
70
+ "sources.introLine",
71
+ "sources.sourceLabel",
72
+ "sources.referenceLabel",
73
+ "sources.pageLabel",
74
+ "sources.textPageLabel",
75
+ "sources.expandLabel",
76
+ "sources.collapseLabel",
77
+ "sources.closeLabel",
78
+ "reasoning.showLabel",
79
+ "reasoning.hideLabel",
80
+ "actions.copyLabel",
81
+ "actions.copiedLabel"
82
+ ]);
83
+ function ne(e) {
84
+ let t = [];
85
+ function n(e, r, i) {
86
+ if (Array.isArray(e)) return Array.isArray(r) ? [...r] : (t.push(i), [...e]);
87
+ if (ee(e)) {
88
+ let t = {};
89
+ for (let a of Object.keys(e)) {
90
+ let o = ee(r) ? r[a] : void 0;
91
+ t[a] = n(e[a], o, i ? `${i}.${a}` : a);
92
+ }
93
+ return t;
94
+ }
95
+ return typeof r == typeof e ? r : (t.push(i), e);
96
+ }
97
+ let r = n(L, e, "");
98
+ return e?.status?.rateLimited === void 0 && (r.status.rateLimited = r.status.error), t.filter((e) => !te.has(e)).length, r;
99
+ }
100
+ var re = Symbol("chat-copy");
101
+ function ie(e) {
102
+ let t = ne(e);
103
+ return y(re, t), t;
104
+ }
105
+ function z() {
106
+ return d(re, L);
107
+ }
108
+ //#endregion
109
+ //#region src/services/anonymous-auth.ts
110
+ async function ae(e) {
111
+ let t = B(new URL(`${e.lxsApiUrl}/api/v1/directory/authentication`), e), n = await fetch(t.toString(), { headers: {
112
+ Accept: "application/json",
113
+ "x-tenant-hint": e.tenantNumber
114
+ } });
115
+ if (!n.ok) throw new V(`Could not read the login settings (${n.status}).`);
116
+ return await n.json();
117
+ }
118
+ function oe() {
119
+ let e = /* @__PURE__ */ new Uint8Array(32);
120
+ return crypto.getRandomValues(e), Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
121
+ }
122
+ async function se(e) {
123
+ let t = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(e));
124
+ return Array.from(new Uint8Array(t), (e) => e.toString(16).padStart(2, "0")).join("");
125
+ }
126
+ function B(e, t) {
127
+ return t.deployEnv && e.searchParams.set("deployEnv", t.deployEnv), t.jobNumber && e.searchParams.set("jobNumber", t.jobNumber), e;
128
+ }
129
+ var V = class extends Error {
130
+ constructor(e) {
131
+ super(e), this.name = "AnonymousAuthError";
132
+ }
133
+ };
134
+ async function H(e) {
135
+ let { lxsApiUrl: t, tenantNumber: n } = e, r = e.authConfigId;
136
+ if (!r) {
137
+ let t = await ae(e);
138
+ if (!t.authenticationStrategies?.find((e) => e.type === "anonymous")?.enabled) throw new V("This tenant does not allow guest sign-in.");
139
+ r = t.PK;
140
+ }
141
+ let i = oe(), a = await se(i), o = {
142
+ Accept: "application/json",
143
+ "Content-Type": "application/json",
144
+ "x-tenant-hint": n
145
+ }, s = B(new URL(`${t}/api/v1/directory/authentication/${r}/anonymous/login`), e);
146
+ s.searchParams.set("codeChallenge", a), s.searchParams.set("codeChallengeMethod", "S256");
147
+ let c = await fetch(s.toString(), {
148
+ method: "POST",
149
+ headers: o,
150
+ body: JSON.stringify({
151
+ codeChallenge: a,
152
+ codeChallengeMethod: "S256"
153
+ })
154
+ });
155
+ if (!c.ok) throw new V(`Anonymous sign-in failed (${c.status}).`);
156
+ let l = await c.json();
157
+ if (!l.loggingInSessionId) throw new V("Anonymous sign-in did not return a session.");
158
+ let u = B(new URL(`${t}/api/v1/directory/session/${encodeURIComponent(l.loggingInSessionId)}/sign`), e), d = await fetch(u.toString(), {
159
+ method: "POST",
160
+ headers: o,
161
+ body: JSON.stringify({ codeVerifier: i })
162
+ });
163
+ if (!d.ok) throw new V(`Could not get a chat token (${d.status}).`);
164
+ let f = await d.json(), p = f.baseCampAuthToken || f.token;
165
+ if (f.success === !1 || !p) throw new V(f.message || "No chat token was returned.");
166
+ return p;
167
+ }
168
+ function ce(e) {
169
+ let t = null, n = (() => (t ||= H(e).catch((e) => {
170
+ throw t = null, e;
171
+ }), t));
172
+ return n.prefetch = () => {
173
+ n().catch(() => {});
174
+ }, n;
175
+ }
176
+ //#endregion
177
+ //#region src/services/base-camp-client.ts
178
+ var le = class extends Error {
179
+ status;
180
+ code;
181
+ constructor(e, t, n) {
182
+ super(t), this.name = "BaseCampError", this.status = e, this.code = n;
183
+ }
184
+ }, ue = class {
185
+ options;
186
+ constructor(e) {
187
+ this.options = e;
188
+ }
189
+ getAgent(e) {
190
+ return this.request("GET", `/v1/agents/${e}`);
191
+ }
192
+ async createThread(e, t) {
193
+ let { variables: n, customData: r } = t ?? {}, i = await this.request("POST", `/v1/agents/${e}/threads`, n ? { variables: n } : {});
194
+ return r && Object.keys(r).length > 0 && await this.request("PATCH", `/v1/agents/${e}/threads/${i.id}`, { customData: r }), i;
195
+ }
196
+ async getThreads(e, t) {
197
+ return (await this.request("GET", `/v1/agents/${e}/threads?limit=${t}`)).threads;
198
+ }
199
+ getThread(e, t) {
200
+ return this.request("GET", `/v1/agents/${e}/threads/${t}`);
201
+ }
202
+ getMessages(e, t) {
203
+ return this.request("GET", `/v1/agents/${e}/threads/${t}/messages`);
204
+ }
205
+ async sendMessage(e, t, n, r) {
206
+ let i = this.options.streamBaseUrl || this.options.baseUrl, a = await fetch(`${i}/v1/agents/${e}/threads/${t}/messages`, {
207
+ method: "POST",
208
+ headers: {
209
+ "Content-Type": "application/json",
210
+ Accept: "text/event-stream",
211
+ ...await this.identityHeaders()
212
+ },
213
+ body: JSON.stringify({
214
+ ...n,
215
+ stream: !0
216
+ }),
217
+ credentials: "include",
218
+ signal: r?.signal
219
+ });
220
+ if (!a.ok) throw await de(a);
221
+ return a;
222
+ }
223
+ stopMessage(e, t, n) {
224
+ return this.request("POST", `/v1/agents/${e}/threads/${t}/stop`, { assistantMessageId: n });
225
+ }
226
+ submitFeedback(e, t, n, r) {
227
+ return this.request("POST", `/v1/agents/${e}/threads/${t}/messages/${n}/feedback`, { feedback: r });
228
+ }
229
+ clearFeedback(e, t, n) {
230
+ return this.request("POST", `/v1/agents/${e}/threads/${t}/messages/${n}/feedback`, {});
231
+ }
232
+ getQuota(e) {
233
+ return this.request("GET", `/v1/agents/${e}/quota`);
234
+ }
235
+ trackEvent(e) {
236
+ return this.request("POST", "/v1/analytics/events", e);
237
+ }
238
+ async identityHeaders() {
239
+ let { deployEnv: e, jobNumber: t, tenantHint: n, getAuthToken: r } = this.options, i = await r(), a = {
240
+ "x-24g-deploy-env": e,
241
+ "x-24g-job-number": t
242
+ };
243
+ return n && (a["x-tenant-hint"] = n), i && (a.Authorization = i.includes(" ") ? i : `Bearer ${i}`), a;
244
+ }
245
+ async request(e, t, n) {
246
+ let r = await fetch(`${this.options.baseUrl}${t}`, {
247
+ method: e,
248
+ headers: {
249
+ ...n === void 0 ? {} : { "Content-Type": "application/json" },
250
+ ...await this.identityHeaders()
251
+ },
252
+ body: n === void 0 ? void 0 : JSON.stringify(n),
253
+ credentials: "include"
254
+ });
255
+ if (!r.ok) throw await de(r);
256
+ return await r.json();
257
+ }
258
+ };
259
+ async function de(e) {
260
+ let t = `Base Camp request failed (${e.status})`, n;
261
+ try {
262
+ let r = await e.json(), i = typeof r.error == "string" ? r.error : void 0, a = typeof r.message == "string" ? r.message : void 0;
263
+ a ? (t = a, n = i) : i && (t = i, /^[A-Z0-9_]+$/.test(i) && (n = i));
264
+ } catch {}
265
+ return new le(e.status, t, n);
266
+ }
267
+ //#endregion
268
+ //#region src/services/streaming.service.ts
269
+ var fe = class extends Error {
270
+ limit;
271
+ remaining;
272
+ resetAt;
273
+ constructor(e) {
274
+ super(e.error || "Message limit reached."), this.name = "RateLimitError", this.limit = e.limit ?? 0, this.remaining = e.remaining ?? 0, this.resetAt = e.resetAt ?? "";
275
+ }
276
+ }, pe = {
277
+ "Content-Type": "application/json",
278
+ Accept: "text/event-stream"
279
+ };
280
+ function me(e) {
281
+ return typeof e == "object" && e ? e : {};
282
+ }
283
+ function he(e, t, n) {
284
+ let r = me(t);
285
+ switch (e) {
286
+ case "response_delta": return r.text !== void 0 && r.text !== null && n.onChunk(String(r.text)), !0;
287
+ case "text_complete": return n.onTextComplete?.(), r.hasSourceContext !== void 0 && n.onMetadata?.({ hasSourceContext: !!r.hasSourceContext }), !0;
288
+ case "thinking_start": return n.onThinkingStart?.(), !0;
289
+ case "thinking_delta": return r.text && n.onThinkingChunk?.(String(r.text)), !0;
290
+ case "thinking_end": return n.onThinkingEnd?.(), !0;
291
+ case "error": {
292
+ let e = "message" in r ? String(r.message) : "Unknown SSE error";
293
+ return n.onError(Error(e)), !0;
294
+ }
295
+ default: return !1;
296
+ }
297
+ }
298
+ function ge(e, t, n) {
299
+ (e === "response_delta" || e === "thinking_delta" || !e) && (e === "thinking_delta" ? n.onThinkingChunk?.(t) : n.onChunk(t));
300
+ }
301
+ function _e(e, t) {
302
+ let n = me(e);
303
+ n.type === "sources" || n.type === "USED_SOURCES" ? t.onMetadata?.({ sources: n.data }) : n.text !== void 0 && n.text !== null ? t.onChunk(String(n.text)) : n.content !== void 0 && n.content !== null && t.onChunk(String(n.content));
304
+ }
305
+ function ve(e) {
306
+ let t = e.slice(7).trim();
307
+ return t || console.warn("Empty event type received, ignoring"), t || "";
308
+ }
309
+ function ye(e, t, n, r) {
310
+ if (e === "[DONE]") return n.onComplete(), !0;
311
+ try {
312
+ let i = JSON.parse(e);
313
+ !r?.(t, i, n) && !he(t, i, n) && _e(i, n);
314
+ } catch {
315
+ t === "error" ? n.onError(Error(e || "Unknown SSE error")) : ge(t, e, n);
316
+ }
317
+ return t === "error";
318
+ }
319
+ function be(e, t, n, r) {
320
+ let i = e.trim();
321
+ return i === "" ? !1 : e.startsWith("event: ") ? (t.currentEvent = ve(e), !1) : e.startsWith("data: ") ? ye(e.slice(6), t.currentEvent, n, r) : (i.startsWith("id: ") || i.startsWith("retry: ") || console.warn("Unknown SSE line format:", e), !1);
322
+ }
323
+ async function xe(e, t, n) {
324
+ let r = new TextDecoder(), i = {
325
+ currentEvent: "",
326
+ buffer: ""
327
+ };
328
+ try {
329
+ for (;;) {
330
+ let { done: a, value: o } = await e.read();
331
+ if (a) break;
332
+ i.buffer += r.decode(o, { stream: !0 });
333
+ let s = i.buffer.split("\n");
334
+ i.buffer = s.pop() || "";
335
+ for (let e of s) if (be(e, i, t, n)) return;
336
+ }
337
+ i.buffer += r.decode(), i.buffer.trim() !== "" && be(i.buffer, i, t, n), t.onComplete();
338
+ } finally {
339
+ e.releaseLock();
340
+ }
341
+ }
342
+ async function U(e, t, n) {
343
+ try {
344
+ let r = e.headers.get("X-RateLimit-Limit");
345
+ if (r && r !== "unlimited" && t.onRateLimit) {
346
+ let n = Number(r), i = Number(e.headers.get("X-RateLimit-Remaining")), a = Number(e.headers.get("X-RateLimit-Reset"));
347
+ Number.isFinite(n) && Number.isFinite(i) && t.onRateLimit({
348
+ limit: n,
349
+ remaining: i,
350
+ resetSeconds: a
351
+ });
352
+ }
353
+ if (e.status === 429) throw new fe(await e.json().catch(() => ({})));
354
+ if (!e.ok) throw Error(`HTTP error! status: ${e.status}`);
355
+ let i = e.body?.getReader();
356
+ if (!i) throw Error("No response body reader available");
357
+ await xe(i, t, n);
358
+ } catch (e) {
359
+ if (e?.name === "AbortError") return;
360
+ console.error("SSE streaming error:", e), t.onError(e instanceof Error ? e : /* @__PURE__ */ Error("Unknown streaming error"));
361
+ }
362
+ }
363
+ async function Se(e, t, n, r, i) {
364
+ try {
365
+ await U(await fetch(e, {
366
+ method: "POST",
367
+ headers: {
368
+ ...pe,
369
+ ...i?.headers
370
+ },
371
+ body: JSON.stringify(t),
372
+ credentials: "include",
373
+ signal: i?.signal
374
+ }), n, r);
375
+ } catch (e) {
376
+ if (e?.name === "AbortError") return;
377
+ console.error("SSE streaming error:", e), n.onError(e instanceof Error ? e : /* @__PURE__ */ Error("Unknown streaming error"));
378
+ }
379
+ }
380
+ //#endregion
381
+ //#region src/services/math.ts
382
+ function Ce(e) {
383
+ return e ? e === !0 ? {} : e : null;
384
+ }
385
+ var we = null;
386
+ function Te(e) {
387
+ return we ??= import("mathlive").then((t) => (e.fontsDirectory !== void 0 && (t.MathfieldElement.fontsDirectory = e.fontsDirectory), t.convertLatexToMarkup)).catch(() => (console.warn("[chat-kit] math is on but mathlive is not installed. Run: pnpm add mathlive"), null)), we;
388
+ }
389
+ var Ee = 200, De = /[\\^_{}]/;
390
+ function Oe(e, t) {
391
+ return t ? e.trim().length > 0 : e.length === 0 || /^\s|\s$/.test(e) || e.length > Ee ? !1 : De.test(e) || !/^\d/.test(e);
392
+ }
393
+ var ke = /\$\$([^$]+)\$\$|\$([^$]+)\$/g, Ae = /^\$\$([^$]+)\$\$|^\$([^$]+)\$/;
394
+ function je(e) {
395
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
396
+ }
397
+ var Me = {
398
+ name: "mathSource",
399
+ level: "inline",
400
+ start: (e) => e.indexOf("$"),
401
+ tokenizer(e) {
402
+ let t = Ae.exec(e);
403
+ if (!t) return;
404
+ let [n, r, i] = t;
405
+ if (Oe(r ?? i ?? "", r !== void 0)) return {
406
+ type: "mathSource",
407
+ raw: n,
408
+ text: n
409
+ };
410
+ },
411
+ renderer: (e) => je(e.text)
412
+ };
413
+ function Ne(e) {
414
+ return F.sanitize(e, {
415
+ USE_PROFILES: {
416
+ html: !0,
417
+ mathMl: !0,
418
+ svg: !0
419
+ },
420
+ ADD_ATTR: [
421
+ "class",
422
+ "style",
423
+ "aria-hidden"
424
+ ]
425
+ });
426
+ }
427
+ async function Pe(e, t = {}) {
428
+ let n = e.ownerDocument.createTreeWalker(e, NodeFilter.SHOW_TEXT, { acceptNode: (e) => e.parentElement?.closest("code, pre") ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT }), r = [];
429
+ for (let e = n.nextNode(); e; e = n.nextNode()) e.nodeValue?.includes("$") && r.push(e);
430
+ let i = await Te(t);
431
+ if (i && r.length !== 0) for (let t of r) {
432
+ let n = t.nodeValue ?? "", r = e.ownerDocument.createDocumentFragment(), a = 0, o = !1;
433
+ for (let t of n.matchAll(ke)) {
434
+ let [s, c, l] = t, u = c ?? l ?? "", d = c !== void 0;
435
+ if (!Oe(u, d)) continue;
436
+ let f;
437
+ try {
438
+ f = i(d ? `\\displaystyle ${u}` : u);
439
+ } catch {
440
+ continue;
441
+ }
442
+ o = !0, r.append(n.slice(a, t.index));
443
+ let p = e.ownerDocument.createElement("span");
444
+ p.className = d ? "chat-math chat-math--display" : "chat-math", p.innerHTML = Ne(f), r.append(p), a = t.index + s.length;
445
+ }
446
+ o && (r.append(n.slice(a)), t.replaceWith(r));
447
+ }
448
+ }
449
+ //#endregion
450
+ //#region src/services/markdown.ts
451
+ var Fe = {
452
+ gfm: !0,
453
+ breaks: !0
454
+ }, Ie = new I(Fe), Le = new I(Fe).use({ extensions: [Me] }), Re = {
455
+ ALLOWED_TAGS: /* @__PURE__ */ "p.br.strong.b.em.i.code.pre.h1.h2.h3.h4.h5.h6.ul.ol.li.a.blockquote.span.table.thead.tbody.tr.td.th.s".split("."),
456
+ ALLOWED_ATTR: [
457
+ "href",
458
+ "target",
459
+ "rel",
460
+ "title",
461
+ "type"
462
+ ],
463
+ ALLOWED_URI_REGEXP: /^https?:\/\//,
464
+ KEEP_CONTENT: !0,
465
+ RETURN_DOM: !1,
466
+ RETURN_DOM_FRAGMENT: !1,
467
+ RETURN_DOM_IMPORT: !1,
468
+ ADD_TAGS: [],
469
+ ADD_ATTR: []
470
+ }, ze = (e) => {
471
+ e.querySelectorAll("a[href]").forEach((e) => {
472
+ e.setAttribute("target", "_blank"), e.setAttribute("rel", "noopener noreferrer");
473
+ });
474
+ };
475
+ async function W(e, t = {}) {
476
+ let { maxLength: n = 5e4, showMath: r = !1 } = t;
477
+ if (!e || typeof e != "string") return "";
478
+ let i = e;
479
+ e.length > n && (console.warn(`Markdown input truncated: ${e.length} chars > ${n} limit`), i = `${e.substring(0, n)}...`);
480
+ try {
481
+ i.length > 5e3 && await new Promise((e) => {
482
+ setTimeout(e, 0);
483
+ });
484
+ let e = Ce(r), t = (e ? Le : Ie).parse(i), n = typeof t == "string" ? t : await Promise.resolve(t), a = F.sanitize(n, {
485
+ ...Re,
486
+ SANITIZE_DOM: !0,
487
+ WHOLE_DOCUMENT: !1,
488
+ RETURN_DOM: !1,
489
+ CUSTOM_ELEMENT_HANDLING: {
490
+ tagNameCheck: null,
491
+ attributeNameCheck: null,
492
+ allowCustomizedBuiltInElements: !1
493
+ }
494
+ }), o = document.createElement("div");
495
+ return o.innerHTML = a, ze(o), e && await Pe(o, e), o.innerHTML;
496
+ } catch (e) {
497
+ return console.error("Markdown rendering error:", e), F.sanitize(i.replace(/\n/g, "<br>"), {
498
+ ALLOWED_TAGS: ["br"],
499
+ KEEP_CONTENT: !0
500
+ });
501
+ }
502
+ }
503
+ function Be(e) {
504
+ if (e.length === 0) return 0;
505
+ if (e.length <= 10) return e.length;
506
+ let t = e.lastIndexOf(" "), n = e.lastIndexOf("\n"), r = Math.max(t, n);
507
+ return r >= e.length - 10 ? r + 1 : e.length;
508
+ }
509
+ async function Ve(e, t = {}) {
510
+ if (!e) return {
511
+ html: "",
512
+ isComplete: !0,
513
+ hasUnsafeBreak: !1,
514
+ lastSafePoint: 0
515
+ };
516
+ if (t.forceComplete) return {
517
+ html: await W(e),
518
+ isComplete: !0,
519
+ hasUnsafeBreak: !1,
520
+ lastSafePoint: e.length
521
+ };
522
+ let n = Be(e);
523
+ return {
524
+ html: await W(e.substring(0, n)),
525
+ isComplete: n >= e.length,
526
+ hasUnsafeBreak: n < e.length,
527
+ lastSafePoint: n
528
+ };
529
+ }
530
+ //#endregion
531
+ //#region src/services/entities.ts
532
+ var He = {
533
+ amp: "&",
534
+ lt: "<",
535
+ gt: ">",
536
+ quot: "\"",
537
+ apos: "'",
538
+ nbsp: "\xA0"
539
+ }, Ue = /&(?:#(\d{1,7})|#[xX]([0-9a-fA-F]{1,6})|([a-zA-Z][a-zA-Z0-9]{1,31}));/g;
540
+ function We(e) {
541
+ return !Number.isInteger(e) || e < 0 || e > 1114111 || e >= 55296 && e <= 57343 ? null : String.fromCodePoint(e);
542
+ }
543
+ function Ge(e) {
544
+ return e.replace(/<[^>]*>/g, "");
545
+ }
546
+ function G(e) {
547
+ return e.includes("&") ? e.replace(Ue, (e, t, n, r) => t === void 0 ? n === void 0 ? He[r.toLowerCase()] ?? e : We(Number.parseInt(n, 16)) ?? e : We(Number(t)) ?? e) : e;
548
+ }
549
+ //#endregion
550
+ //#region src/services/streaming-message.ts
551
+ var Ke = class {
552
+ onUpdate;
553
+ throttleMs;
554
+ showMath;
555
+ buffer = "";
556
+ renderTimer = null;
557
+ destroyed = !1;
558
+ stopped = !1;
559
+ constructor(e, t = 25, n = !1) {
560
+ this.onUpdate = e, this.throttleMs = t, this.showMath = n;
561
+ }
562
+ addChunk(e) {
563
+ this.destroyed || this.stopped || (this.buffer += e, this.renderTimer ||= setTimeout(() => {
564
+ this.renderTimer = null, this.render(!1);
565
+ }, this.throttleMs));
566
+ }
567
+ async complete() {
568
+ this.destroyed || this.stopped || (this.renderTimer &&= (clearTimeout(this.renderTimer), null), await this.render(!0));
569
+ }
570
+ async render(e) {
571
+ if (!(this.destroyed || this.stopped)) try {
572
+ let t = await W(this.buffer, { showMath: this.showMath });
573
+ if (this.destroyed || this.stopped) return;
574
+ this.onUpdate(t, e);
575
+ } catch (e) {
576
+ console.error("Error rendering streaming markdown:", e);
577
+ }
578
+ }
579
+ getCurrentContent() {
580
+ return this.buffer;
581
+ }
582
+ stop() {
583
+ this.destroyed || this.stopped || (this.stopped = !0, this.renderTimer &&= (clearTimeout(this.renderTimer), null));
584
+ }
585
+ destroy() {
586
+ this.destroyed = !0, this.renderTimer &&= (clearTimeout(this.renderTimer), null);
587
+ }
588
+ }, qe = 4, Je = 600, Ye = class {
589
+ emit;
590
+ queue = "";
591
+ charsPerFrame;
592
+ carry = 0;
593
+ enabled;
594
+ frameHandle = null;
595
+ waiters = [];
596
+ destroyed = !1;
597
+ onVisibilityChange = () => {
598
+ document.hidden && this.flush();
599
+ };
600
+ constructor(e, t = !0) {
601
+ this.emit = e, this.enabled = t !== !1;
602
+ let n = typeof t == "object" ? t.speed : void 0, r = typeof n == "number" && Number.isFinite(n) && n > 0 ? n : 1;
603
+ this.charsPerFrame = qe * r, this.enabled && document.addEventListener("visibilitychange", this.onVisibilityChange);
604
+ }
605
+ push(e) {
606
+ if (!this.destroyed && e) {
607
+ if (this.queue += e, !this.enabled || document.hidden) {
608
+ this.flush();
609
+ return;
610
+ }
611
+ this.schedule();
612
+ }
613
+ }
614
+ flush() {
615
+ if (!this.destroyed) {
616
+ if (this.cancelFrame(), this.carry = 0, this.queue) {
617
+ let e = this.queue;
618
+ this.queue = "", this.emit(e);
619
+ }
620
+ this.resolveWaiters();
621
+ }
622
+ }
623
+ finish() {
624
+ return this.destroyed || !this.queue ? Promise.resolve() : document.hidden ? (this.flush(), Promise.resolve()) : new Promise((e) => {
625
+ this.waiters.push(e);
626
+ });
627
+ }
628
+ destroy() {
629
+ this.destroyed || (this.destroyed = !0, this.cancelFrame(), this.queue = "", document.removeEventListener("visibilitychange", this.onVisibilityChange), this.resolveWaiters());
630
+ }
631
+ schedule() {
632
+ if (this.frameHandle !== null) return;
633
+ let e = () => {
634
+ this.frameHandle = null, !this.destroyed && this.queue && (this.step(), this.queue ? this.schedule() : this.resolveWaiters());
635
+ };
636
+ this.frameHandle = requestAnimationFrame(e);
637
+ }
638
+ step() {
639
+ this.carry += this.charsPerFrame;
640
+ let e = Math.max(0, this.queue.length - Je), t = Math.min(e + Math.floor(this.carry), this.queue.length);
641
+ if (t < 1) return;
642
+ this.carry -= t - e;
643
+ let n = this.queue.charCodeAt(t - 1);
644
+ n >= 55296 && n <= 56319 && t < this.queue.length && (t += 1);
645
+ let r = this.queue.slice(0, t);
646
+ this.queue = this.queue.slice(t), this.queue || (this.carry = 0), this.emit(r);
647
+ }
648
+ cancelFrame() {
649
+ this.frameHandle !== null && (cancelAnimationFrame(this.frameHandle), this.frameHandle = null);
650
+ }
651
+ resolveWaiters() {
652
+ for (let e of this.waiters.splice(0)) e();
653
+ }
654
+ }, Xe = 20, Ze = 0;
655
+ function K() {
656
+ return Ze += 1, `local-${Ze}`;
657
+ }
658
+ function Qe(e) {
659
+ let { transport: t, agentId: r } = e, i = T(null), a = S(null), o = S([]), s = S("idle"), c = S(null), l = T(null), u = T(null);
660
+ async function d() {
661
+ if (t.getQuota) try {
662
+ u.value = await t.getQuota(r);
663
+ } catch {}
664
+ }
665
+ let f = T(null), p = n(() => s.value === "thinking" ? f.value?.thinking ?? "" : ""), m = n(() => {
666
+ let e = c.value;
667
+ return e ? e.status === 429 || e.name === "RateLimitError" ? "rate-limited" : "error" : null;
668
+ }), h = null, g = null, _ = t.getAgent(r).then((e) => (i.value = e, e)).catch(() => null);
669
+ d();
670
+ let v = n(() => s.value !== "idle");
671
+ function y(e) {
672
+ return o.value.find((t) => t.id === e);
673
+ }
674
+ function C(t) {
675
+ try {
676
+ e.onEvent?.(t);
677
+ } catch {}
678
+ }
679
+ function w(e) {
680
+ let t = o.value.indexOf(e);
681
+ return {
682
+ query: o.value.slice(0, t).reverse().find((e) => e.role === "user")?.text ?? "",
683
+ response: e.text
684
+ };
685
+ }
686
+ async function E() {
687
+ if (a.value) return a.value;
688
+ let e = await t.createThread(r);
689
+ return a.value = e.id, e.id;
690
+ }
691
+ function D(e, t = "typed") {
692
+ let n = e.trim();
693
+ if (!n || v.value) return Promise.resolve();
694
+ let r = O(n, t);
695
+ return g = r, r.finally(() => {
696
+ g === r && (g = null);
697
+ }), r;
698
+ }
699
+ async function O(n, i) {
700
+ c.value = null, s.value = "thinking";
701
+ let u = b({
702
+ id: K(),
703
+ role: "user",
704
+ text: n,
705
+ html: "",
706
+ thinking: "",
707
+ sources: [],
708
+ citations: [],
709
+ feedback: null,
710
+ isOutOfScope: !1,
711
+ isStreaming: !1,
712
+ isReceiving: !1,
713
+ failed: !1,
714
+ inputMode: i
715
+ });
716
+ o.value.push(u);
717
+ let p = b({
718
+ id: K(),
719
+ role: "assistant",
720
+ text: "",
721
+ html: "",
722
+ thinking: "",
723
+ sources: [],
724
+ citations: [],
725
+ feedback: null,
726
+ isOutOfScope: !1,
727
+ isStreaming: !1,
728
+ isReceiving: !1,
729
+ failed: !1
730
+ });
731
+ f.value = p;
732
+ let m = new AbortController();
733
+ h = m;
734
+ let g = new Ke((e) => {
735
+ p.html = e;
736
+ }, 25, e.showMath);
737
+ function _() {
738
+ s.value !== "streaming" && (s.value = "streaming", p.isStreaming = !0, p.isReceiving = !0, o.value.push(p));
739
+ }
740
+ let v = new Ye((e) => {
741
+ _(), p.text += e, g.addChunk(e);
742
+ }, e.typewriter ?? !0), y = null;
743
+ try {
744
+ let o = await E();
745
+ if (await U(await t.sendMessage(r, o, {
746
+ message: n,
747
+ stream: !0,
748
+ ...i === "voice" && { inputMode: "dictation" }
749
+ }, { signal: m.signal }), {
750
+ onChunk: (e) => {
751
+ v.push(e);
752
+ },
753
+ onComplete: () => {},
754
+ onError: (e) => {
755
+ y = e;
756
+ },
757
+ onMetadata: (e) => {
758
+ e.sources && (p.sources = e.sources);
759
+ },
760
+ onThinkingChunk: (e) => {
761
+ p.thinking += e;
762
+ }
763
+ }, (e, t) => {
764
+ if (e === "citations" && Array.isArray(t)) return p.citations = t, !0;
765
+ let n = t ?? {};
766
+ return e === "message_id" && typeof n.messageId == "string" ? (u.basecampMessageId = n.messageId, !0) : e === "assistant_message_id" && typeof n.messageId == "string" ? (p.basecampMessageId = n.messageId, !0) : e === "used_sources" && Array.isArray(t) ? (p.sources = t, !0) : e === "token_usage" && n.thread ? (l.value = n.thread, !0) : !1;
767
+ }), y) throw y;
768
+ if (m.signal.aborted) {
769
+ v.flush(), await g.complete(), p.isReceiving = !1, p.isStreaming = !1;
770
+ return;
771
+ }
772
+ if (p.isReceiving = !1, await v.finish(), !p.text) throw Error("The response ended without any content.");
773
+ await g.complete(), p.isOutOfScope = e.isOutOfScope?.(p.text) ?? !1, p.isStreaming = !1, C({
774
+ type: "turn",
775
+ query: n,
776
+ inputMode: i,
777
+ response: p.text,
778
+ isOutOfScope: p.isOutOfScope,
779
+ citations: p.citations,
780
+ sources: p.sources,
781
+ threadId: a.value,
782
+ userMessageId: u.basecampMessageId,
783
+ assistantMessageId: p.basecampMessageId
784
+ });
785
+ } catch (t) {
786
+ v.flush(), t?.name !== "AbortError" && (p.text ? p.failed = !0 : c.value = t instanceof Error ? t : Error(String(t))), g.stop(), p.isReceiving = !1, p.isStreaming = !1, p.text && (p.html = await W(p.text, { showMath: e.showMath }));
787
+ } finally {
788
+ v.destroy(), h = null, f.value = null, s.value = "idle", d();
789
+ }
790
+ }
791
+ async function k() {
792
+ let e = g;
793
+ if (!e) return;
794
+ let n = o.value.find((e) => e.isStreaming)?.basecampMessageId;
795
+ h?.abort(), n && a.value && t.stopMessage(r, a.value, n).catch(() => {}), await e;
796
+ }
797
+ async function A() {
798
+ await k(), a.value = null, o.value = [], c.value = null;
799
+ }
800
+ async function j(t) {
801
+ let n = t.role === "assistant", r = n ? t.text.replace(/\[\^\d+\]/g, "") : t.text;
802
+ return b({
803
+ id: K(),
804
+ role: t.role,
805
+ text: r,
806
+ html: n ? await W(r, { showMath: e.showMath }) : "",
807
+ thinking: t.metadata?.thinking ?? "",
808
+ basecampMessageId: t.id,
809
+ sources: t.sourceContext ?? [],
810
+ citations: [],
811
+ feedback: t.feedback ?? null,
812
+ isOutOfScope: n ? e.isOutOfScope?.(t.text) ?? !1 : !1,
813
+ isStreaming: !1,
814
+ isReceiving: !1,
815
+ failed: !1
816
+ });
817
+ }
818
+ async function M(e = Xe) {
819
+ if (!t.getThreads) throw Error("This transport does not implement getThreads, so history cannot be listed.");
820
+ let n = await t.getThreads(r, e);
821
+ return {
822
+ threads: n.filter((e) => e.status === "ACTIVE"),
823
+ mightHaveMore: n.length >= e
824
+ };
825
+ }
826
+ async function N(e) {
827
+ if (!t.getMessages) throw Error("This transport does not implement getMessages, so history cannot be loaded.");
828
+ await k();
829
+ let n = await t.getMessages(r, e), i = n.messages.filter((e) => !e.metadata?.isWelcomeMessage), s = await Promise.all(i.map((e) => j(e)));
830
+ a.value = e, o.value = s, l.value = n.tokenUsage ?? null, c.value = null;
831
+ }
832
+ async function P(e, n) {
833
+ let i = y(e);
834
+ if (!i?.basecampMessageId || !a.value) return;
835
+ let o = i.feedback, s = o === n ? null : n;
836
+ i.feedback = s;
837
+ try {
838
+ s ? await t.submitFeedback(r, a.value, i.basecampMessageId, s) : await t.clearFeedback(r, a.value, i.basecampMessageId), C({
839
+ type: "feedback",
840
+ value: s,
841
+ assistantMessageId: i.basecampMessageId,
842
+ threadId: a.value,
843
+ ...w(i)
844
+ });
845
+ } catch {
846
+ i.feedback = o;
847
+ }
848
+ }
849
+ function F(e, t) {
850
+ let n = y(e);
851
+ n && C({
852
+ type: "citation-click",
853
+ citation: t,
854
+ assistantMessageId: n.basecampMessageId,
855
+ threadId: a.value,
856
+ ...w(n)
857
+ });
858
+ }
859
+ async function I() {
860
+ let e = [...o.value].reverse().find((e) => e.role === "user");
861
+ e && !v.value && (o.value = o.value.filter((t) => t !== e && !(t.role === "assistant" && t.failed)), c.value = null, await D(e.text, e.inputMode));
862
+ }
863
+ return {
864
+ agent: x(i),
865
+ agentReady: _,
866
+ threadId: x(a),
867
+ messages: o,
868
+ status: x(s),
869
+ error: x(c),
870
+ errorKind: m,
871
+ busy: v,
872
+ tokenUsage: x(l),
873
+ quota: x(u),
874
+ liveThinking: p,
875
+ sendMessage: D,
876
+ stopGeneration: k,
877
+ newConversation: A,
878
+ listThreads: M,
879
+ loadThread: N,
880
+ setFeedback: P,
881
+ noteCitationClick: F,
882
+ retry: I
883
+ };
884
+ }
885
+ //#endregion
886
+ //#region src/testing/mock-transport.ts
887
+ var $e = {
888
+ text: [
889
+ "This is a **mock answer** from the development transport, standing in for the real backend.",
890
+ "",
891
+ "It streams a few words at a time so the interface behaves the way it will in production:",
892
+ "",
893
+ "- markdown renders as it arrives",
894
+ "- the thinking indicator shows before the first words",
895
+ "- sources attach once the answer finishes",
896
+ "",
897
+ "Send another message to see it again, or start a new chat to reset."
898
+ ].join("\n"),
899
+ sources: []
900
+ };
901
+ function q(e, t) {
902
+ return `event: ${e}\ndata: ${JSON.stringify(t)}\n\n`;
903
+ }
904
+ var J = (e) => new Promise((t) => setTimeout(t, e)), et = class {
905
+ options;
906
+ threadCount = 0;
907
+ messageCount = 0;
908
+ history = /* @__PURE__ */ new Map();
909
+ quotaResetAt = (/* @__PURE__ */ new Date("2026-01-02T00:00:00.000Z")).toISOString();
910
+ constructor(e = {}) {
911
+ this.options = e;
912
+ }
913
+ async getAgent(e) {
914
+ return {
915
+ id: e,
916
+ name: "Mock Agent",
917
+ description: "Development stand-in for a Base Camp agent.",
918
+ config: {}
919
+ };
920
+ }
921
+ async createThread(e, t) {
922
+ this.threadCount += 1;
923
+ let n = `mock-thread-${this.threadCount}`;
924
+ return this.history.set(n, []), {
925
+ id: n,
926
+ agentId: e,
927
+ status: "ACTIVE",
928
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
929
+ };
930
+ }
931
+ async getThreads(e, t) {
932
+ return [...this.history.entries()].reverse().slice(0, t).map(([t, n]) => ({
933
+ id: t,
934
+ agentId: e,
935
+ status: "ACTIVE",
936
+ messageCount: n.length,
937
+ lastMessageAt: n.at(-1)?.createdAt
938
+ }));
939
+ }
940
+ async getQuota(e) {
941
+ let t = this.options.messageLimit;
942
+ if (t === void 0) return {
943
+ limit: "unlimited",
944
+ remaining: "unlimited",
945
+ resetAt: this.quotaResetAt
946
+ };
947
+ let n = Math.ceil(this.messageCount / 2);
948
+ return {
949
+ limit: t,
950
+ remaining: Math.max(0, t - n),
951
+ resetAt: this.quotaResetAt
952
+ };
953
+ }
954
+ async getMessages(e, t) {
955
+ let n = this.history.get(t);
956
+ if (!n) throw Error(`Unknown thread: ${t}`);
957
+ return {
958
+ threadId: t,
959
+ messages: n
960
+ };
961
+ }
962
+ async sendMessage(e, t, n, r) {
963
+ let i = r?.signal, a = this.options.replyTo?.(n.message) ?? $e, o = this.options.chunkDelayMs ?? 30, s = this.options.thinkingDelayMs ?? 600;
964
+ this.messageCount += 1;
965
+ let c = `mock-msg-${this.messageCount}`;
966
+ this.messageCount += 1;
967
+ let l = `mock-msg-${this.messageCount}`, u = a.text.match(/\S+\s*/g) ?? [a.text], d = a.thinking?.match(/\S+\s*/g) ?? [], f = (/* @__PURE__ */ new Date()).toISOString();
968
+ this.history.get(t)?.push({
969
+ id: c,
970
+ role: "user",
971
+ text: n.message,
972
+ createdAt: f
973
+ }, {
974
+ id: l,
975
+ role: "assistant",
976
+ text: a.text,
977
+ createdAt: f,
978
+ sourceContext: a.sources,
979
+ metadata: a.thinking ? { thinking: a.thinking } : void 0
980
+ });
981
+ let p = new TextEncoder(), m = new ReadableStream({ async start(e) {
982
+ let t = (t) => e.enqueue(p.encode(t)), n = () => {
983
+ if (i?.aborted) throw new DOMException("The user cancelled the stream.", "AbortError");
984
+ };
985
+ try {
986
+ if (t(q("message_id", { messageId: c })), t(q("assistant_message_id", { messageId: l })), d.length > 0) {
987
+ t(q("thinking_start", {}));
988
+ for (let e of d) n(), t(q("thinking_delta", { text: e })), await J(o);
989
+ t(q("thinking_end", {}));
990
+ }
991
+ await J(s);
992
+ for (let e of u) n(), t(q("response_delta", { text: e })), await J(o);
993
+ t(q("text_complete", {})), a.citations?.length && t(q("citations", a.citations)), a.sources?.length && t(q("used_sources", a.sources)), a.tokenUsage && t(q("token_usage", {
994
+ message: {
995
+ inputTokens: 0,
996
+ outputTokens: 0,
997
+ totalTokens: 0
998
+ },
999
+ thread: a.tokenUsage
1000
+ })), t("data: [DONE]\n\n"), e.close();
1001
+ } catch (t) {
1002
+ try {
1003
+ e.error(t);
1004
+ } catch {}
1005
+ }
1006
+ } });
1007
+ return new Response(m, {
1008
+ status: 200,
1009
+ headers: { "Content-Type": "text/event-stream" }
1010
+ });
1011
+ }
1012
+ async stopMessage() {
1013
+ return {
1014
+ success: !0,
1015
+ message: "stopped"
1016
+ };
1017
+ }
1018
+ async submitFeedback(e, t, n, r) {
1019
+ return { feedback: r };
1020
+ }
1021
+ async clearFeedback() {
1022
+ return {};
1023
+ }
1024
+ };
1025
+ //#endregion
1026
+ //#region src/composables/useDictation.ts
1027
+ function tt() {
1028
+ if (typeof window > "u") return null;
1029
+ let e = window;
1030
+ return e.SpeechRecognition ?? e.webkitSpeechRecognition ?? null;
1031
+ }
1032
+ var nt = 2e3;
1033
+ function rt(e, t = {}) {
1034
+ let n = tt(), r = t.idleMs ?? nt, i = S(!1), a = null, o, s = "", c = "";
1035
+ function l() {
1036
+ r && (clearTimeout(o), o = setTimeout(f, r));
1037
+ }
1038
+ function u(n) {
1039
+ let r = new n();
1040
+ return r.continuous = !0, r.interimResults = !0, r.lang = t.lang ?? "en-US", r.onresult = (t) => {
1041
+ if (!i.value) return;
1042
+ let n = "";
1043
+ l();
1044
+ for (let e = t.resultIndex; e < t.results.length; e += 1) {
1045
+ let r = t.results[e];
1046
+ r && (r.isFinal ? c += `${r[0].transcript} ` : n += r[0].transcript);
1047
+ }
1048
+ e.value = s + c + n;
1049
+ }, r.onend = () => {
1050
+ clearTimeout(o), i.value = !1;
1051
+ }, r.onerror = () => {
1052
+ clearTimeout(o), i.value = !1;
1053
+ }, r;
1054
+ }
1055
+ function d() {
1056
+ if (n && !i.value) {
1057
+ a ??= u(n), s = e.value ? `${e.value.trim()} ` : "", c = "", i.value = !0, l();
1058
+ try {
1059
+ a.start();
1060
+ } catch {}
1061
+ }
1062
+ }
1063
+ function f() {
1064
+ clearTimeout(o), i.value = !1, a?.stop();
1065
+ }
1066
+ function p() {
1067
+ i.value ? f() : d();
1068
+ }
1069
+ return _(() => {
1070
+ clearTimeout(o), a?.abort();
1071
+ }), {
1072
+ isSupported: n !== null,
1073
+ isListening: i,
1074
+ toggle: p,
1075
+ stop: f
1076
+ };
1077
+ }
1078
+ //#endregion
1079
+ //#region src/components/IconButton.vue?vue&type=script&setup=true&lang.ts
1080
+ var it = {
1081
+ type: "button",
1082
+ class: "icon-button"
1083
+ }, at = { class: "icon-button__label" }, ot = /*@__PURE__*/ u({
1084
+ __name: "IconButton",
1085
+ props: { label: {} },
1086
+ setup(e) {
1087
+ return (t, n) => (v(), a("button", it, [w(t.$slots, "default", {}, void 0, !0), o("span", at, E(e.label), 1)]));
1088
+ }
1089
+ }), Y = (e, t) => {
1090
+ let n = e.__vccOpts || e;
1091
+ for (let [e, r] of t) n[e] = r;
1092
+ return n;
1093
+ }, X = /*#__PURE__*/ Y(ot, [["__scopeId", "data-v-ce6d8ce0"]]), st = ["width", "height"], ct = ["width", "height"], lt = ["width", "height"], ut = ["width", "height"], dt = ["width", "height"], ft = ["width", "height"], pt = ["width", "height"], mt = ["width", "height"], ht = ["width", "height"], Z = /* @__PURE__ */ u({
1094
+ __name: "KitIcon",
1095
+ props: {
1096
+ name: {},
1097
+ size: {}
1098
+ },
1099
+ setup(e) {
1100
+ return (t, n) => e.name === "send" ? (v(), a("svg", {
1101
+ key: 0,
1102
+ width: e.size ?? 16,
1103
+ height: e.size ?? 16,
1104
+ viewBox: "0 0 20 20",
1105
+ fill: "none"
1106
+ }, [...n[0] ||= [o("path", {
1107
+ d: "M4.16667 10L15.8333 10M10 15.8333L15.8333 10L10 4.16667",
1108
+ stroke: "currentColor",
1109
+ "stroke-width": "1.5",
1110
+ "stroke-linecap": "round",
1111
+ "stroke-linejoin": "round"
1112
+ }, null, -1)]], 8, st)) : e.name === "mic" ? (v(), a("svg", {
1113
+ key: 1,
1114
+ width: e.size ?? 16,
1115
+ height: e.size ?? 16,
1116
+ viewBox: "0 0 10.88 16",
1117
+ fill: "currentColor"
1118
+ }, [...n[1] ||= [o("path", { d: "M8.65 3.168C8.65 1.418 7.213 0 5.44 0C3.667 0 2.23 1.418 2.23 3.168V7.049C2.23 8.799 3.667 10.217 5.44 10.217C7.213 10.217 8.65 8.799 8.65 7.049V3.168Z" }, null, -1), o("path", { d: "M10.293 4.53C9.969 4.53 9.706 4.789 9.706 5.109V7.05C9.706 9.371 7.792 11.26 5.44 11.26C3.088 11.26 1.174 9.371 1.174 7.05V5.109C1.174 4.789 0.911 4.53 0.587 4.53C0.263 4.53 0 4.789 0 5.109V7.05C0 9.814 2.129 12.097 4.853 12.387V14.842H3.069C2.745 14.842 2.482 15.102 2.482 15.421C2.482 15.741 2.745 16 3.069 16H7.811C8.135 16 8.398 15.741 8.398 15.421C8.398 15.102 8.135 14.842 7.811 14.842H6.027V12.387C8.751 12.097 10.88 9.814 10.88 7.05V5.109C10.88 4.789 10.617 4.53 10.293 4.53Z" }, null, -1)]], 8, ct)) : e.name === "stop" ? (v(), a("svg", {
1119
+ key: 2,
1120
+ width: e.size ?? 16,
1121
+ height: e.size ?? 16,
1122
+ viewBox: "0 0 16 16",
1123
+ fill: "currentColor"
1124
+ }, [...n[2] ||= [o("rect", {
1125
+ x: "3",
1126
+ y: "3",
1127
+ width: "10",
1128
+ height: "10",
1129
+ rx: "2"
1130
+ }, null, -1)]], 8, lt)) : e.name === "thumb-up" || e.name === "thumb-down" ? (v(), a("svg", {
1131
+ key: 3,
1132
+ width: e.size ?? 20,
1133
+ height: e.size ?? 20,
1134
+ viewBox: "0 0 20.02 16.3",
1135
+ fill: "currentColor",
1136
+ style: m(e.name === "thumb-down" ? "transform: rotate(180deg)" : void 0)
1137
+ }, [...n[3] ||= [o("path", { d: "M16.29 16.3C15.95 16.3 15.6 16.3 15.26 16.29H14.48C14.09 16.28 13.69 16.28 13.3 16.28H11.72C10.95 16.27 10.17 16.26 9.4 16.29C8.72 16.31 8.21 16 7.77 15.73C7.65 15.66 7.53 15.58 7.41 15.52C7.06 15.34 7.04 14.9 7.04 14.77C7.04 12.58 7.04 10.4 7.04 8.21C7.04 7.96 7.17 7.62 7.43 7.45C9.46 6.03 10.41 4 10.33 1.25C10.32 0.86 10.3 0.42 10.6 0.17C10.91 -0.09 11.34 0 11.74 0.09C12.64 0.28 13.25 0.87 13.54 1.82C13.92 3.02 13.79 4.25 13.61 5.39C13.58 5.55 13.55 5.71 13.54 5.82C13.68 5.82 13.88 5.81 13.99 5.81C15.08 5.72 16.18 5.79 17.26 5.85L17.71 5.88C18.16 5.91 18.57 6.07 18.97 6.26C19.9 6.69 20.23 7.49 19.88 8.46C19.81 8.65 19.72 8.87 19.58 9.07C19.52 9.15 19.52 9.16 19.58 9.27C20.18 10.24 20.03 10.93 19.07 11.64C19.08 11.63 19.07 11.7 19.07 11.76C19.07 11.86 19.08 11.96 19.1 12.06C19.13 12.21 19.15 12.37 19.15 12.52C19.15 13.12 18.89 13.59 18.39 13.92C18.39 13.92 18.33 13.98 18.26 14.2C18.21 14.33 18.18 14.47 18.16 14.61C18.11 14.83 18.06 15.05 17.97 15.27C17.69 15.93 17.1 16.3 16.3 16.3H16.29ZM2.71 16.22C2.22 16.22 1.73 16.22 1.24 16.22C0.41 16.22 0.01 15.82 0 15.01C0 14.13 0 13.25 0 12.36V8.29C0 7.46 0.43 7.04 1.25 7.04C2.4 7.04 3.56 7.04 4.71 7.04C5.55 7.04 5.97 7.44 5.97 8.28C5.97 10.5 5.97 12.73 5.97 14.95C5.97 15.82 5.58 16.22 4.69 16.22C4.02 16.22 3.36 16.22 2.7 16.22H2.71Z" }, null, -1)]], 12, ut)) : e.name === "sparkle" ? (v(), a("svg", {
1138
+ key: 4,
1139
+ width: e.size ?? 16,
1140
+ height: (e.size ?? 16) * 14.7693 / 16,
1141
+ viewBox: "0 0 16.0001 14.7693",
1142
+ fill: "currentColor"
1143
+ }, [...n[4] ||= [o("path", { d: "M11.9472 8.83878C8.3169 9.81745 7.28765 10.867 6.32788 14.5687C6.25841 14.8362 5.88552 14.8362 5.81605 14.5687C4.85627 10.867 3.82703 9.81745 0.196726 8.83878C-0.0655754 8.76795 -0.0655754 8.38771 0.196726 8.31688C3.82703 7.33821 4.85627 6.2887 5.81605 2.58693C5.88552 2.31946 6.25841 2.31946 6.32788 2.58693C7.28765 6.2887 8.3169 7.33821 11.9472 8.31688C12.2095 8.38771 12.2095 8.76795 11.9472 8.83878ZM15.9001 3.0099C14.0576 2.51324 13.5354 1.98075 13.0483 0.101979C13.0132 -0.033993 12.8239 -0.033993 12.7884 0.101979C12.3013 1.98075 11.7791 2.51324 9.93662 3.0099C9.80327 3.04573 9.80327 3.23869 9.93662 3.27493C11.7791 3.77159 12.3013 4.30408 12.7884 6.18285C12.8235 6.31882 13.0128 6.31882 13.0483 6.18285C13.5354 4.30408 14.0576 3.77159 15.9001 3.27493C16.0334 3.2391 16.0334 3.04614 15.9001 3.0099Z" }, null, -1)]], 8, dt)) : e.name === "copy" ? (v(), a("svg", {
1144
+ key: 5,
1145
+ width: e.size ?? 16,
1146
+ height: e.size ?? 16,
1147
+ viewBox: "0 0 16 16",
1148
+ fill: "currentColor",
1149
+ stroke: "currentColor",
1150
+ "stroke-width": "0.5"
1151
+ }, [...n[5] ||= [o("path", { d: "M3.62712 10.4832H2.41239C1.89338 10.4832 1.47374 10.0876 1.47374 9.59831V2.30569C1.47374 1.8164 1.89338 1.42079 2.41239 1.42079H9.24246C9.76148 1.42079 10.1811 1.8164 10.1811 2.30569V3.25826C10.1811 3.47168 10.3688 3.64866 10.5952 3.64866C10.8216 3.64866 11.0093 3.47168 11.0093 3.25826V2.30569C11.0093 1.38436 10.2142 0.64 9.24246 0.64H2.40687C1.43509 0.64 0.64 1.38956 0.64 2.30569V9.59311C0.64 10.5144 1.43509 11.2588 2.40687 11.2588H3.6216C3.84798 11.2588 4.03571 11.0818 4.03571 10.8684C4.03571 10.655 3.84798 10.478 3.6216 10.478L3.62712 10.4832Z" }, null, -1), o("path", { d: "M13.5931 4.74136H6.76306C5.78576 4.74136 4.99619 5.49092 4.99619 6.40705V13.6945C4.99619 14.6158 5.79128 15.3602 6.76306 15.3602H13.5931C14.5704 15.3602 15.36 14.6106 15.36 13.6945V6.40705C15.36 5.48572 14.5649 4.74136 13.5931 4.74136ZM13.5931 14.5846H6.76306C6.24404 14.5846 5.82441 14.189 5.82441 13.6997V6.41226C5.82441 5.92296 6.24404 5.52736 6.76306 5.52736H13.5931C14.1121 5.52736 14.5318 5.92296 14.5318 6.41226V13.6997C14.5318 14.189 14.1121 14.5846 13.5931 14.5846Z" }, null, -1)]], 8, ft)) : e.name === "external-link" ? (v(), a("svg", {
1152
+ key: 6,
1153
+ width: e.size ?? 16,
1154
+ height: e.size ?? 16,
1155
+ viewBox: "0 0 16 16",
1156
+ fill: "currentColor",
1157
+ stroke: "currentColor",
1158
+ "stroke-width": "0.5"
1159
+ }, [...n[6] ||= [o("path", { d: "M13.496 8.69167C13.218 8.69167 12.992 8.9176 12.992 9.19566V12.9668C12.992 13.6359 12.4446 14.1833 11.7755 14.1833H4.22447C3.55539 14.1833 3.00797 13.6359 3.00797 12.9668V5.42448C3.00797 4.75539 3.55539 4.20797 4.22447 4.20797H7.99566C8.27371 4.20797 8.49964 3.98204 8.49964 3.70398C8.49964 3.42592 8.27371 3.2 7.99566 3.2H4.22447C2.99928 3.2 2 4.19928 2 5.42448V12.9755C2 14.2007 2.99928 15.2 4.22447 15.2H11.7755C13.0007 15.2 14 14.2007 14 12.9755V9.20435C14 8.92629 13.7741 8.70036 13.496 8.70036V8.69167Z" }, null, -1), o("path", { d: "M15.1084 1.6H10.0653C9.79408 1.6 9.57371 1.82066 9.57371 2.09225C9.57371 2.36383 9.79408 2.58449 10.0653 2.58449H13.9218L6.94621 9.56083C6.75126 9.75603 6.75126 10.0616 6.94621 10.2568C7.14115 10.452 7.45476 10.4435 7.64122 10.2568L14.6168 3.28043V7.14203C14.6168 7.41361 14.8372 7.63427 15.1084 7.63427C15.3796 7.63427 15.6 7.41361 15.6 7.14203V2.09225C15.6 1.82066 15.3796 1.6 15.1084 1.6Z" }, null, -1)]], 8, pt)) : e.name === "chevron-down" ? (v(), a("svg", {
1160
+ key: 7,
1161
+ width: e.size ?? 16,
1162
+ height: e.size ?? 16,
1163
+ viewBox: "0 0 16 16",
1164
+ fill: "none"
1165
+ }, [...n[7] ||= [o("path", {
1166
+ d: "M4 6l4 4 4-4",
1167
+ stroke: "currentColor",
1168
+ "stroke-width": "1.5",
1169
+ "stroke-linecap": "round",
1170
+ "stroke-linejoin": "round"
1171
+ }, null, -1)]], 8, mt)) : e.name === "warning" ? (v(), a("svg", {
1172
+ key: 8,
1173
+ width: e.size ?? 16,
1174
+ height: (e.size ?? 16) * 14.4 / 16,
1175
+ viewBox: "0 0 16 14.4",
1176
+ fill: "currentColor"
1177
+ }, [...n[8] ||= [o("path", { d: "M15.8568 12.7841L8.91585 0.538566C8.50877 -0.179522 7.49127 -0.179522 7.08419 0.538566L0.143286 12.7841C-0.263791 13.5022 0.244959 14.4 1.05911 14.4H14.9409C15.7551 14.4 16.2638 13.5022 15.8568 12.7841ZM7.62818 4.62113C7.871 4.47245 8.17448 4.47245 8.4173 4.62113C8.66763 4.77452 8.81032 5.05952 8.78548 5.35589L8.4329 9.54183C8.41037 9.79368 8.24188 9.95393 8.01716 9.95393C7.79244 9.95393 7.63511 9.79368 7.61258 9.54183L7.26 5.35589C7.23497 5.05952 7.37785 4.77452 7.62818 4.62113ZM8.87156 11.6941C8.87156 12.1406 8.5105 12.484 8.01716 12.484C7.52381 12.484 7.16276 12.1406 7.16276 11.6941V11.5796C7.16276 11.1332 7.53575 10.7897 8.01716 10.7897C8.49856 10.7897 8.87156 11.1332 8.87156 11.5796V11.6941Z" }, null, -1)]], 8, ht)) : i("", !0);
1178
+ }
1179
+ }), gt = { class: "input-bar" }, _t = { class: "input-bar__field" }, vt = ["placeholder"], yt = { class: "input-bar__buttons" }, bt = ["data-tooltip"], xt = /*#__PURE__*/ Y(/* @__PURE__ */ u({
1180
+ __name: "InputBar",
1181
+ props: {
1182
+ busy: { type: Boolean },
1183
+ showMic: { type: Boolean }
1184
+ },
1185
+ emits: ["send", "stop"],
1186
+ setup(e, { emit: t }) {
1187
+ let s = e, c = t, u = z(), d = S(""), f = S(null), { isSupported: m, isListening: _, toggle: y, stop: b } = rt(d), x = n(() => d.value.trim().length > 0 && !s.busy), C = S(!1);
1188
+ A(d, (e) => {
1189
+ e ? _.value && (C.value = !0) : C.value = !1;
1190
+ });
1191
+ function w() {
1192
+ let e = f.value;
1193
+ e && (e.style.height = "auto", e.style.height = `${Math.min(e.scrollHeight, 100)}px`);
1194
+ }
1195
+ A(d, w, { flush: "post" });
1196
+ let T = null;
1197
+ g(() => {
1198
+ w(), document.fonts.ready.then(w);
1199
+ let e = f.value;
1200
+ if (!e || typeof ResizeObserver > "u") return;
1201
+ let t = e.clientWidth;
1202
+ T = new ResizeObserver(() => {
1203
+ e.clientWidth !== t && (t = e.clientWidth, w());
1204
+ }), T.observe(e);
1205
+ }), h(() => T?.disconnect());
1206
+ function E() {
1207
+ if (!x.value) return;
1208
+ b();
1209
+ let e = d.value, t = C.value ? "voice" : "typed";
1210
+ d.value = "", C.value = !1, c("send", e, t);
1211
+ }
1212
+ function O(e) {
1213
+ e.key === "Enter" && !e.shiftKey && (e.preventDefault(), E());
1214
+ }
1215
+ return (t, n) => (v(), a("div", gt, [o("div", _t, [M(o("textarea", {
1216
+ ref_key: "field",
1217
+ ref: f,
1218
+ "onUpdate:modelValue": n[0] ||= (e) => d.value = e,
1219
+ class: "input-bar__textarea",
1220
+ rows: "1",
1221
+ placeholder: D(u).composer.placeholder,
1222
+ onKeydown: O
1223
+ }, null, 40, vt), [[k, d.value]]), o("div", yt, [e.showMic && D(m) ? (v(), r(X, {
1224
+ key: 0,
1225
+ label: D(u).composer.dictateLabel,
1226
+ class: p({ "input-bar__button--listening": D(_) }),
1227
+ onClick: D(y)
1228
+ }, {
1229
+ default: j(() => [l(Z, { name: "mic" })]),
1230
+ _: 1
1231
+ }, 8, [
1232
+ "label",
1233
+ "class",
1234
+ "onClick"
1235
+ ])) : e.showMic ? (v(), a("span", {
1236
+ key: 1,
1237
+ class: "input-bar__mic-unsupported",
1238
+ "data-tooltip": D(u).composer.micUnsupported
1239
+ }, [l(Z, { name: "warning" })], 8, bt)) : i("", !0), e.busy ? (v(), r(X, {
1240
+ key: 2,
1241
+ label: D(u).composer.stopLabel,
1242
+ onClick: n[1] ||= (e) => c("stop")
1243
+ }, {
1244
+ default: j(() => [l(Z, { name: "stop" })]),
1245
+ _: 1
1246
+ }, 8, ["label"])) : (v(), r(X, {
1247
+ key: 3,
1248
+ class: "input-bar__send",
1249
+ label: D(u).composer.sendLabel,
1250
+ disabled: !x.value,
1251
+ onClick: E
1252
+ }, {
1253
+ default: j(() => [l(Z, {
1254
+ name: "send",
1255
+ size: 20
1256
+ })]),
1257
+ _: 1
1258
+ }, 8, ["label", "disabled"]))])])]));
1259
+ }
1260
+ }), [["__scopeId", "data-v-752f72a0"]]), St = 20, Ct = 300, wt = .3, Tt = 12, Et = 8;
1261
+ function Dt(e, t = {}) {
1262
+ let n = S("following"), r = !1, i = 0, a = !1, o = null, s = !1, c = () => t.mode?.() ?? "reply";
1263
+ function l(e) {
1264
+ return e.scrollTop + e.clientHeight >= e.scrollHeight - St - 1;
1265
+ }
1266
+ function u() {
1267
+ let t = e.value;
1268
+ if (!t) return;
1269
+ let o = t.scrollTop, c = o < i, u = o > i;
1270
+ i = o, !r && (c ? (n.value = "manual", a = !1) : n.value === "manual" && u ? a = !0 : u && n.value === "following" && o > b(t) + Et && (n.value = "manual", a = !0), n.value === "manual" && a && l(t) && (n.value = "following", s = !0, a = !1));
1271
+ }
1272
+ function d(e) {
1273
+ e.deltaY < 0 ? (n.value = "manual", a = !1) : e.deltaY > 0 && n.value === "manual" && (a = !0);
1274
+ }
1275
+ let p = 0;
1276
+ function m(e) {
1277
+ let t = e.touches[0];
1278
+ t && (p = t.clientY);
1279
+ }
1280
+ function g(e) {
1281
+ let t = e.touches[0];
1282
+ if (!t) return;
1283
+ let r = t.clientY;
1284
+ r > p ? (n.value = "manual", a = !1) : r < p && n.value === "manual" && (a = !0);
1285
+ }
1286
+ function _(e) {
1287
+ e.addEventListener("scroll", u, { passive: !0 }), e.addEventListener("wheel", d, { passive: !0 }), e.addEventListener("touchstart", m, { passive: !0 }), e.addEventListener("touchmove", g, { passive: !0 }), i = e.scrollTop;
1288
+ }
1289
+ function v(e) {
1290
+ e.removeEventListener("scroll", u), e.removeEventListener("wheel", d), e.removeEventListener("touchstart", m), e.removeEventListener("touchmove", g);
1291
+ }
1292
+ let y = null;
1293
+ A(e, (e, t) => {
1294
+ t && v(t), e && _(e), y = e ?? null;
1295
+ }, { immediate: !0 }), h(() => {
1296
+ y && v(y), y = null, o !== null && (cancelAnimationFrame(o), o = null);
1297
+ });
1298
+ function b(e) {
1299
+ let n = e.scrollHeight - e.clientHeight;
1300
+ if (s || c() === "bottom") return n;
1301
+ let r = t.anchor?.();
1302
+ if (!r) return n;
1303
+ let i = r.getBoundingClientRect().top - e.getBoundingClientRect().top + e.scrollTop;
1304
+ return Math.min(n, i - Tt);
1305
+ }
1306
+ function x() {
1307
+ c() !== "off" && f(() => {
1308
+ if (o !== null) return;
1309
+ let t = () => {
1310
+ o = null;
1311
+ let i = e.value;
1312
+ if (!i || n.value !== "following") return;
1313
+ let a = b(i), s = a - i.scrollTop;
1314
+ s <= 0 || (r = !0, s > Ct || s <= 1 ? i.scrollTop = a : (i.scrollTop += Math.max(1, s * wt), o = requestAnimationFrame(t)), requestAnimationFrame(() => {
1315
+ r = !1;
1316
+ }));
1317
+ };
1318
+ o = requestAnimationFrame(t);
1319
+ });
1320
+ }
1321
+ function C() {
1322
+ n.value = "following", s = !1;
1323
+ }
1324
+ return {
1325
+ glideToBottom: x,
1326
+ resetToFollowing: C
1327
+ };
1328
+ }
1329
+ //#endregion
1330
+ //#region src/services/citations.ts
1331
+ var Ot = /\[\^(\d+)\]/g;
1332
+ function kt(e) {
1333
+ return e.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
1334
+ }
1335
+ var At = "<sup class=\"citation-chip citation-chip--pending\">&middot;</sup>";
1336
+ function jt(e, t, n = {}) {
1337
+ if (!e || t.length === 0 && !n.pendingMarkers) return e;
1338
+ let r = new Map(t.map((e) => [e.ref, e]));
1339
+ return e.replace(Ot, (e, t) => {
1340
+ let i = r.get(Number(t));
1341
+ if (i) {
1342
+ let e = kt(G(i.title || "Source"));
1343
+ return `<sup class="citation-chip" data-citation-ref="${i.ref}" title="${e}" tabindex="0">${i.label}</sup>`;
1344
+ }
1345
+ return n.pendingMarkers ? At : e;
1346
+ });
1347
+ }
1348
+ //#endregion
1349
+ //#region src/components/CitationPopover.vue?vue&type=script&setup=true&lang.ts
1350
+ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "citation-popover__badge" }, Ft = { class: "citation-popover__source-text" }, It = { class: "citation-popover__title" }, Lt = {
1351
+ key: 0,
1352
+ class: "citation-popover__page"
1353
+ }, Rt = { class: "citation-popover__passage-block" }, zt = { class: "citation-popover__passage-label" }, Bt = { class: "citation-popover__passage" }, Vt = {
1354
+ key: 0,
1355
+ class: "citation-popover__notice"
1356
+ }, Ht = {
1357
+ key: 1,
1358
+ class: "citation-popover__footer"
1359
+ }, Ut = ["href"], Wt = /*#__PURE__*/ Y(/* @__PURE__ */ u({
1360
+ __name: "CitationPopover",
1361
+ props: { citation: {} },
1362
+ emits: ["close"],
1363
+ setup(e, { emit: t }) {
1364
+ let r = e, s = t, u = z(), d = S(!1);
1365
+ A(() => r.citation.screenshotUrl, () => {
1366
+ d.value = !1;
1367
+ });
1368
+ let f = n(() => !!r.citation.screenshotUrl && !d.value), p = n(() => G(r.citation.passage)), m = n(() => G(r.citation.title || "Source"));
1369
+ function g() {
1370
+ let e = r.citation.textPage ?? r.citation.page;
1371
+ return e === void 0 ? null : `p. ${e}`;
1372
+ }
1373
+ let _ = n(() => r.citation.canonicalLink ?? r.citation.link), y = S(!1), b;
1374
+ async function x() {
1375
+ if (_.value) try {
1376
+ await navigator.clipboard.writeText(_.value), y.value = !0, clearTimeout(b), b = setTimeout(() => {
1377
+ y.value = !1;
1378
+ }, 2e3);
1379
+ } catch {}
1380
+ }
1381
+ return h(() => clearTimeout(b)), (t, n) => (v(), a("div", {
1382
+ class: "citation-popover",
1383
+ onKeydown: n[1] ||= N((e) => s("close"), ["esc"])
1384
+ }, [
1385
+ o("div", Mt, [
1386
+ f.value ? (v(), a("img", {
1387
+ key: 0,
1388
+ class: "citation-popover__thumb",
1389
+ src: e.citation.screenshotUrl,
1390
+ onError: n[0] ||= (e) => d.value = !0
1391
+ }, null, 40, Nt)) : i("", !0),
1392
+ o("span", Pt, E(e.citation.label), 1),
1393
+ o("div", Ft, [o("p", It, E(m.value), 1), g() ? (v(), a("p", Lt, E(g()), 1)) : i("", !0)])
1394
+ ]),
1395
+ o("div", Rt, [o("p", zt, E(D(u).sources.citedPassageLabel), 1), o("blockquote", Bt, E(p.value), 1)]),
1396
+ D(u).sources.noticeLine ? (v(), a("p", Vt, E(D(u).sources.noticeLine), 1)) : i("", !0),
1397
+ e.citation.link ? (v(), a("div", Ht, [o("button", {
1398
+ type: "button",
1399
+ class: "citation-popover__copy",
1400
+ onClick: x
1401
+ }, [c(E(y.value ? D(u).sources.copiedLabel : D(u).sources.copyUrlLabel) + " ", 1), l(Z, { name: "copy" })]), o("a", {
1402
+ class: "citation-popover__open",
1403
+ href: e.citation.link,
1404
+ target: "_blank",
1405
+ rel: "noopener noreferrer"
1406
+ }, [c(E(D(u).sources.openSourceLabel) + " ", 1), l(Z, { name: "external-link" })], 8, Ut)])) : i("", !0)
1407
+ ], 32));
1408
+ }
1409
+ }), [["__scopeId", "data-v-c713f6b3"]]), Gt = { class: "feedback" }, Kt = { class: "feedback__question" }, qt = { class: "feedback__thumbs" }, Jt = /*#__PURE__*/ Y(/* @__PURE__ */ u({
1410
+ __name: "FeedbackRow",
1411
+ props: { feedback: {} },
1412
+ emits: ["rate"],
1413
+ setup(e, { emit: t }) {
1414
+ let n = t, r = z();
1415
+ return (t, i) => (v(), a("div", Gt, [o("span", Kt, E(D(r).feedback.question), 1), o("div", qt, [o("button", {
1416
+ type: "button",
1417
+ class: p(["feedback__thumb", { "is-active": e.feedback === "POSITIVE" }]),
1418
+ onClick: i[0] ||= (e) => n("rate", "POSITIVE")
1419
+ }, [l(Z, { name: "thumb-up" })], 2), o("button", {
1420
+ type: "button",
1421
+ class: p(["feedback__thumb", { "is-active": e.feedback === "NEGATIVE" }]),
1422
+ onClick: i[1] ||= (e) => n("rate", "NEGATIVE")
1423
+ }, [l(Z, { name: "thumb-down" })], 2)])]));
1424
+ }
1425
+ }), [["__scopeId", "data-v-6aa14982"]]), Yt = { class: "page-image-modal__card" }, Xt = { class: "page-image-modal__header" }, Zt = { class: "page-image-modal__heading" }, Qt = { class: "page-image-modal__title" }, $t = {
1426
+ key: 0,
1427
+ class: "page-image-modal__detail"
1428
+ }, en = ["src"], tn = /*#__PURE__*/ Y(/* @__PURE__ */ u({
1429
+ __name: "PageImageModal",
1430
+ props: {
1431
+ url: {},
1432
+ title: {},
1433
+ detail: {}
1434
+ },
1435
+ emits: ["close"],
1436
+ setup(e, { emit: n }) {
1437
+ let s = n, c = z();
1438
+ function l(e) {
1439
+ e.key === "Escape" && s("close");
1440
+ }
1441
+ return g(() => document.addEventListener("keydown", l)), h(() => document.removeEventListener("keydown", l)), (n, l) => (v(), r(t, { to: "body" }, [o("div", {
1442
+ class: "page-image-modal",
1443
+ onClick: l[1] ||= P((e) => s("close"), ["self"])
1444
+ }, [o("div", Yt, [o("div", Xt, [o("div", Zt, [o("p", Qt, E(e.title), 1), e.detail ? (v(), a("p", $t, E(e.detail), 1)) : i("", !0)]), o("button", {
1445
+ type: "button",
1446
+ class: "page-image-modal__close",
1447
+ onClick: l[0] ||= (e) => s("close")
1448
+ }, E(D(c).sources.closeLabel), 1)]), o("img", {
1449
+ class: "page-image-modal__image",
1450
+ src: e.url
1451
+ }, null, 8, en)])])]));
1452
+ }
1453
+ }), [["__scopeId", "data-v-33820e23"]]), nn = { class: "source-card" }, rn = ["aria-expanded", "aria-label"], an = { class: "source-card__front" }, on = { class: "source-card__heading" }, sn = { class: "source-card__details" }, cn = ["src"], ln = { class: "source-card__naming" }, un = {
1454
+ key: 0,
1455
+ class: "source-card__title"
1456
+ }, dn = ["href"], fn = {
1457
+ key: 0,
1458
+ class: "source-card__body"
1459
+ }, pn = { class: "source-card__reference-heading" }, mn = ["src", "onClick"], hn = { class: "source-card__reference-text" }, gn = {
1460
+ key: 0,
1461
+ class: "source-card__page-line"
1462
+ }, _n = {
1463
+ key: 1,
1464
+ class: "source-card__passage"
1465
+ }, vn = /*#__PURE__*/ Y(/* @__PURE__ */ u({
1466
+ __name: "SourceCard",
1467
+ props: {
1468
+ source: {},
1469
+ index: {}
1470
+ },
1471
+ emits: ["viewPage"],
1472
+ setup(t, { emit: r }) {
1473
+ let s = t, u = r, d = z(), f = S(!1), m = n(() => G(s.source.metadata?.title ?? "")), h = n(() => s.source.metadata?.link || null), g = n(() => s.source.metadata?.screenshotUrl || s.source.screenshotUrl || ""), _ = S(!1);
1474
+ A(g, () => {
1475
+ _.value = !1;
1476
+ });
1477
+ let y = n(() => s.source.results.filter((e) => e.content?.trim() || e.metadata?.screenshotUrl));
1478
+ function b(e) {
1479
+ return G(Ge(e.content ?? "")).trim();
1480
+ }
1481
+ function x(e) {
1482
+ let { page: t, textPage: n } = e.metadata ?? {};
1483
+ return [t === void 0 ? "" : R(d.sources.pageLabel, { page: t }), n === void 0 ? "" : R(d.sources.textPageLabel, { textPage: n })].filter(Boolean).join(", ");
1484
+ }
1485
+ function w(e) {
1486
+ let t = e.metadata?.screenshotUrl;
1487
+ t && u("viewPage", {
1488
+ url: t,
1489
+ title: m.value || R(d.sources.sourceLabel, { n: s.index + 1 }),
1490
+ detail: x(e)
1491
+ });
1492
+ }
1493
+ return (n, r) => (v(), a("div", nn, [
1494
+ o("button", {
1495
+ type: "button",
1496
+ class: p(["source-card__toggle", { "source-card__toggle--open": f.value }]),
1497
+ "aria-expanded": f.value,
1498
+ "aria-label": f.value ? D(d).sources.collapseLabel : D(d).sources.expandLabel,
1499
+ onClick: r[0] ||= (e) => f.value = !f.value
1500
+ }, [l(Z, { name: "chevron-down" })], 10, rn),
1501
+ o("div", an, [o("p", on, E(D(R)(D(d).sources.sourceLabel, { n: t.index + 1 })), 1), o("div", sn, [g.value && !_.value ? (v(), a("img", {
1502
+ key: 0,
1503
+ class: "source-card__cover",
1504
+ src: g.value,
1505
+ onError: r[1] ||= (e) => _.value = !0
1506
+ }, null, 40, cn)) : i("", !0), o("div", ln, [m.value ? (v(), a("p", un, E(m.value), 1)) : i("", !0), h.value ? (v(), a("a", {
1507
+ key: 1,
1508
+ class: "source-card__link",
1509
+ href: h.value,
1510
+ target: "_blank",
1511
+ rel: "noopener noreferrer"
1512
+ }, [c(E(D(d).sources.openSourceLabel) + " ", 1), l(Z, { name: "external-link" })], 8, dn)) : i("", !0)])])]),
1513
+ f.value && y.value.length > 0 ? (v(), a("div", fn, [o("p", pn, E(D(d).sources.referenceLabel), 1), (v(!0), a(e, null, C(y.value, (e, t) => (v(), a("div", {
1514
+ key: t,
1515
+ class: "source-card__reference"
1516
+ }, [e.metadata?.screenshotUrl ? (v(), a("img", {
1517
+ key: 0,
1518
+ class: "source-card__page-thumb",
1519
+ src: e.metadata.screenshotUrl,
1520
+ onClick: (t) => w(e)
1521
+ }, null, 8, mn)) : i("", !0), o("div", hn, [x(e) ? (v(), a("p", gn, E(x(e)), 1)) : i("", !0), b(e) ? (v(), a("p", _n, E(b(e)), 1)) : i("", !0)])]))), 128))])) : i("", !0)
1522
+ ]));
1523
+ }
1524
+ }), [["__scopeId", "data-v-49b414a6"]]), yn = {
1525
+ key: 0,
1526
+ class: "source-list"
1527
+ }, bn = {
1528
+ key: 0,
1529
+ class: "source-list__intro"
1530
+ }, xn = {
1531
+ key: 1,
1532
+ class: "source-list__notice"
1533
+ }, Sn = /*#__PURE__*/ Y(/* @__PURE__ */ u({
1534
+ __name: "SourceList",
1535
+ props: { sources: {} },
1536
+ setup(t) {
1537
+ let n = z(), o = S(null);
1538
+ return (s, c) => t.sources.length > 0 ? (v(), a("div", yn, [
1539
+ D(n).sources.introLine ? (v(), a("p", bn, E(D(n).sources.introLine), 1)) : i("", !0),
1540
+ (v(!0), a(e, null, C(t.sources, (e, t) => (v(), r(vn, {
1541
+ key: e.entityId ?? t,
1542
+ source: e,
1543
+ index: t,
1544
+ onViewPage: c[0] ||= (e) => o.value = e
1545
+ }, null, 8, ["source", "index"]))), 128)),
1546
+ D(n).sources.noticeLine ? (v(), a("p", xn, E(D(n).sources.noticeLine), 1)) : i("", !0),
1547
+ o.value ? (v(), r(tn, {
1548
+ key: 2,
1549
+ url: o.value.url,
1550
+ title: o.value.title,
1551
+ detail: o.value.detail,
1552
+ onClose: c[1] ||= (e) => o.value = null
1553
+ }, null, 8, [
1554
+ "url",
1555
+ "title",
1556
+ "detail"
1557
+ ])) : i("", !0)
1558
+ ])) : i("", !0);
1559
+ }
1560
+ }), [["__scopeId", "data-v-124ee2ae"]]), Cn = {
1561
+ key: 0,
1562
+ class: "thinking__sparkles"
1563
+ }, wn = {
1564
+ key: 1,
1565
+ class: "thinking__dots"
1566
+ }, Tn = {
1567
+ key: 2,
1568
+ class: "thinking__spinner"
1569
+ }, En = /*#__PURE__*/ Y(/* @__PURE__ */ u({
1570
+ __name: "ThinkingAnimation",
1571
+ props: { variant: {} },
1572
+ setup(t) {
1573
+ return (n, r) => t.variant === "sparkles" ? (v(), a("span", Cn, [(v(), a(e, null, C(3, (e) => o("svg", {
1574
+ key: e,
1575
+ class: "thinking__sparkle",
1576
+ viewBox: "0 0 16 16"
1577
+ }, [...r[0] ||= [o("path", {
1578
+ d: "M8 0 Q9.4 6.6 16 8 Q9.4 9.4 8 16 Q6.6 9.4 0 8 Q6.6 6.6 8 0 Z",
1579
+ fill: "currentColor"
1580
+ }, null, -1)]])), 64))])) : t.variant === "dots" ? (v(), a("span", wn, [(v(), a(e, null, C(3, (e) => o("span", {
1581
+ key: e,
1582
+ class: "thinking__dot"
1583
+ })), 64))])) : (v(), a("span", Tn));
1584
+ }
1585
+ }), [["__scopeId", "data-v-a73d8186"]]), Dn = { class: "thinking-process" }, On = /*#__PURE__*/ Y(/* @__PURE__ */ u({
1586
+ __name: "ThinkingProcess",
1587
+ props: {
1588
+ text: {},
1589
+ streaming: { type: Boolean }
1590
+ },
1591
+ setup(e) {
1592
+ let t = e, n = z(), r = S(t.streaming === !0), s = S(null);
1593
+ return A(() => t.text, async () => {
1594
+ if (!t.streaming || !r.value) return;
1595
+ await f();
1596
+ let e = s.value;
1597
+ e && (e.scrollTop = e.scrollHeight);
1598
+ }), (t, c) => (v(), a("div", Dn, [o("button", {
1599
+ type: "button",
1600
+ class: "thinking-process__toggle",
1601
+ onClick: c[0] ||= (e) => r.value = !r.value
1602
+ }, E(r.value ? D(n).reasoning.hideLabel : D(n).reasoning.showLabel), 1), r.value ? (v(), a("div", {
1603
+ key: 0,
1604
+ ref_key: "body",
1605
+ ref: s,
1606
+ class: "thinking-process__body"
1607
+ }, E(e.text), 513)) : i("", !0)]));
1608
+ }
1609
+ }), [["__scopeId", "data-v-3dcefa4f"]]), kn = { class: "assistant-message" }, An = {
1610
+ class: "assistant-message__header",
1611
+ "data-reply-start": ""
1612
+ }, jn = { class: "assistant-message__avatar" }, Mn = { class: "assistant-message__name" }, Nn = {
1613
+ key: 0,
1614
+ class: "assistant-message__out-of-scope"
1615
+ }, Pn = { class: "assistant-message__body-wrap" }, Fn = ["innerHTML"], In = {
1616
+ key: 3,
1617
+ class: "assistant-message__error"
1618
+ }, Ln = {
1619
+ key: 4,
1620
+ class: "assistant-message__footer"
1621
+ }, Rn = {
1622
+ key: 0,
1623
+ class: "assistant-message__actions"
1624
+ }, zn = 350, Q = 12, $ = 4, Bn = 280, Vn = 160, Hn = /*#__PURE__*/ Y(/* @__PURE__ */ u({
1625
+ __name: "AssistantMessage",
1626
+ props: {
1627
+ message: {},
1628
+ citationType: {},
1629
+ showThinking: { type: Boolean },
1630
+ thinkingVariant: {},
1631
+ showCopy: { type: Boolean }
1632
+ },
1633
+ emits: [
1634
+ "rate",
1635
+ "retry",
1636
+ "citationClick"
1637
+ ],
1638
+ setup(e, { emit: s }) {
1639
+ let c = e, u = s, d = z(), f = O();
1640
+ function p() {
1641
+ return (c.showCopy === !0 || !!f["message-actions"]) && !c.message.isStreaming && !!c.message.text;
1642
+ }
1643
+ let g = S(!1), _;
1644
+ async function y() {
1645
+ try {
1646
+ await navigator.clipboard.writeText(c.message.text), g.value = !0, clearTimeout(_), _ = setTimeout(() => {
1647
+ g.value = !1;
1648
+ }, 2e3);
1649
+ } catch {}
1650
+ }
1651
+ function b() {
1652
+ let e = c.message;
1653
+ return !e.isStreaming && !e.isOutOfScope && !e.failed && !!e.basecampMessageId && !!e.text;
1654
+ }
1655
+ let x = n(() => c.citationType === "list" ? c.message.html : jt(c.message.html, c.message.citations, { pendingMarkers: c.message.isStreaming })), C = S(null), T = S({}), k = S(null);
1656
+ function A(e) {
1657
+ let t = e.getBoundingClientRect(), n = Math.min(zn, window.innerWidth - 24), r = Math.min(Math.max(Q, t.right - n), window.innerWidth - n - Q), i = window.innerHeight - t.bottom - $ - Q, a = t.top - $ - Q, o = i >= Bn || i >= a, s = Math.max(Vn, o ? i : a);
1658
+ return {
1659
+ left: `${r}px`,
1660
+ width: `${n}px`,
1661
+ maxHeight: `${s}px`,
1662
+ ...o ? { top: `${t.bottom + $}px` } : { bottom: `${window.innerHeight - t.top + $}px` }
1663
+ };
1664
+ }
1665
+ function M(e) {
1666
+ let t = e.target.closest?.(".citation-chip");
1667
+ if (!(t instanceof HTMLElement) || !k.value) return;
1668
+ let n = c.message.citations.find((e) => e.ref === Number(t.dataset.citationRef));
1669
+ if (!n || n === C.value) {
1670
+ C.value = null;
1671
+ return;
1672
+ }
1673
+ T.value = A(t), C.value = n, u("citationClick", c.message.id, n);
1674
+ }
1675
+ function N(e) {
1676
+ (e.key === "Enter" || e.key === " ") && (M(e), e.preventDefault());
1677
+ }
1678
+ function P(e) {
1679
+ let t = e.target;
1680
+ t.closest?.(".citation-chip") || t.closest?.(".citation-popover") || (C.value = null);
1681
+ }
1682
+ function F() {
1683
+ C.value = null;
1684
+ }
1685
+ function I(e) {
1686
+ let t = e.target;
1687
+ t instanceof HTMLElement && t.closest?.(".citation-popover") || F();
1688
+ }
1689
+ return document.addEventListener("click", P), window.addEventListener("scroll", I, !0), window.addEventListener("resize", F), h(() => {
1690
+ document.removeEventListener("click", P), window.removeEventListener("scroll", I, !0), window.removeEventListener("resize", F), clearTimeout(_);
1691
+ }), (n, s) => (v(), a("div", kn, [
1692
+ o("div", An, [
1693
+ o("span", jn, [l(Z, { name: "sparkle" })]),
1694
+ o("p", Mn, E(D(d).roles.assistant), 1),
1695
+ e.message.isReceiving ? (v(), r(En, {
1696
+ key: 0,
1697
+ variant: e.thinkingVariant
1698
+ }, null, 8, ["variant"])) : i("", !0)
1699
+ ]),
1700
+ e.message.isOutOfScope ? (v(), a("div", Nn, [l(Z, { name: "warning" }), o("span", null, E(D(d).outOfScope.label), 1)])) : i("", !0),
1701
+ e.showThinking && e.message.thinking ? (v(), r(On, {
1702
+ key: 1,
1703
+ text: e.message.thinking
1704
+ }, null, 8, ["text"])) : i("", !0),
1705
+ o("div", Pn, [o("div", {
1706
+ ref_key: "body",
1707
+ ref: k,
1708
+ class: "assistant-message__body",
1709
+ innerHTML: x.value,
1710
+ onClick: M,
1711
+ onKeydown: N
1712
+ }, null, 40, Fn), (v(), r(t, { to: "body" }, [C.value ? (v(), r(Wt, {
1713
+ key: 0,
1714
+ class: "assistant-message__popover",
1715
+ style: m(T.value),
1716
+ citation: C.value,
1717
+ onClose: s[0] ||= (e) => C.value = null
1718
+ }, null, 8, ["style", "citation"])) : i("", !0)]))]),
1719
+ e.citationType === "list" && !e.message.isStreaming ? (v(), r(Sn, {
1720
+ key: 2,
1721
+ sources: e.message.sources
1722
+ }, null, 8, ["sources"])) : i("", !0),
1723
+ e.message.failed ? (v(), a("div", In, [o("span", null, E(D(d).status.error), 1), o("button", {
1724
+ type: "button",
1725
+ class: "assistant-message__retry",
1726
+ onClick: s[1] ||= (e) => u("retry")
1727
+ }, E(D(d).status.retryLabel), 1)])) : i("", !0),
1728
+ p() || b() ? (v(), a("div", Ln, [p() ? (v(), a("div", Rn, [w(n.$slots, "message-actions", { message: e.message }, void 0, !0), e.showCopy ? (v(), r(X, {
1729
+ key: 0,
1730
+ label: g.value ? D(d).actions.copiedLabel : D(d).actions.copyLabel,
1731
+ class: "assistant-message__copy",
1732
+ onClick: y
1733
+ }, {
1734
+ default: j(() => [l(Z, { name: "copy" })]),
1735
+ _: 1
1736
+ }, 8, ["label"])) : i("", !0)])) : i("", !0), b() ? (v(), r(Jt, {
1737
+ key: 1,
1738
+ feedback: e.message.feedback,
1739
+ onRate: s[2] ||= (t) => u("rate", e.message.id, t)
1740
+ }, null, 8, ["feedback"])) : i("", !0)])) : i("", !0)
1741
+ ]));
1742
+ }
1743
+ }), [["__scopeId", "data-v-81f04579"]]), Un = { class: "thinking" }, Wn = {
1744
+ key: 0,
1745
+ class: "thinking__label"
1746
+ }, Gn = 2e3, Kn = /*#__PURE__*/ Y(/* @__PURE__ */ u({
1747
+ __name: "ThinkingIndicator",
1748
+ props: {
1749
+ variant: {},
1750
+ rotateLabel: { type: Boolean }
1751
+ },
1752
+ setup(e) {
1753
+ let t = e, r = z(), o = n(() => t.rotateLabel ? r.status.thinkingSequence : []), s = S(0), c = n(() => o.value[s.value] ?? r.status.thinking), u;
1754
+ return g(() => {
1755
+ if (o.value.length < 2) return;
1756
+ let e = () => {
1757
+ s.value >= o.value.length - 1 || (s.value += 1, u = setTimeout(e, Gn));
1758
+ };
1759
+ u = setTimeout(e, Gn);
1760
+ }), h(() => clearTimeout(u)), (t, n) => (v(), a("div", Un, [c.value ? (v(), a("span", Wn, E(c.value), 1)) : i("", !0), l(En, { variant: e.variant }, null, 8, ["variant"])]));
1761
+ }
1762
+ }), [["__scopeId", "data-v-c804834e"]]), qn = { class: "user-message" }, Jn = { class: "user-message__bubble" }, Yn = /*#__PURE__*/ Y(/* @__PURE__ */ u({
1763
+ __name: "UserMessage",
1764
+ props: { message: {} },
1765
+ setup(e) {
1766
+ return (t, n) => (v(), a("div", qn, [o("div", Jn, E(e.message.text), 1)]));
1767
+ }
1768
+ }), [["__scopeId", "data-v-2eb946f2"]]), Xn = {
1769
+ key: 0,
1770
+ class: "message-list__welcome"
1771
+ }, Zn = { class: "message-list__welcome-fallback" }, Qn = {
1772
+ key: 0,
1773
+ class: "message-list__welcome-eyebrow"
1774
+ }, $n = { class: "message-list__welcome-heading" }, er = { class: "message-list__welcome-body" }, tr = {
1775
+ key: 3,
1776
+ class: "message-list__error"
1777
+ }, nr = /*#__PURE__*/ Y(/* @__PURE__ */ u({
1778
+ __name: "MessageList",
1779
+ props: {
1780
+ engine: {},
1781
+ citationType: {},
1782
+ thinkingVariant: {},
1783
+ rotateThinkingLabel: { type: Boolean },
1784
+ showThinking: { type: Boolean },
1785
+ autoScroll: {},
1786
+ showCopy: { type: Boolean }
1787
+ },
1788
+ emits: ["rated"],
1789
+ setup(t, { emit: n }) {
1790
+ let c = t, l = n, u = z(), d = S(null), { glideToBottom: f, resetToFollowing: p } = Dt(d, {
1791
+ mode: () => c.autoScroll ?? "reply",
1792
+ anchor: () => {
1793
+ if (c.engine.messages.value.at(-1)?.role !== "assistant") return null;
1794
+ let e = d.value?.querySelectorAll("[data-reply-start]");
1795
+ return e?.[e.length - 1] ?? null;
1796
+ }
1797
+ });
1798
+ A(() => c.engine.messages.value.length, (e, t) => {
1799
+ e > t && c.engine.messages.value.at(-1)?.role === "user" && p();
1800
+ }), A(() => [
1801
+ c.engine.messages.value.length,
1802
+ c.engine.messages.value.at(-1)?.html,
1803
+ c.engine.status.value
1804
+ ], () => f());
1805
+ function m(e, t) {
1806
+ let n = c.engine.messages.value.find((t) => t.id === e);
1807
+ if (!n) return;
1808
+ let r = n.feedback;
1809
+ c.engine.setFeedback(e, t), n.feedback !== r && l("rated", n, n.feedback);
1810
+ }
1811
+ return (n, c) => (v(), a("div", {
1812
+ ref_key: "scroller",
1813
+ ref: d,
1814
+ class: "message-list"
1815
+ }, [
1816
+ t.engine.messages.value.length === 0 ? (v(), a("div", Xn, [w(n.$slots, "welcome", {}, () => [o("div", Zn, [
1817
+ D(u).welcome.eyebrow ? (v(), a("p", Qn, E(D(u).welcome.eyebrow), 1)) : i("", !0),
1818
+ o("h2", $n, E(D(u).welcome.heading), 1),
1819
+ o("p", er, E(D(u).welcome.body), 1)
1820
+ ])], !0)])) : i("", !0),
1821
+ (v(!0), a(e, null, C(t.engine.messages.value, (i) => (v(), a(e, { key: i.id }, [i.role === "user" ? (v(), r(Yn, {
1822
+ key: 0,
1823
+ message: i
1824
+ }, null, 8, ["message"])) : (v(), r(Hn, {
1825
+ key: 1,
1826
+ message: i,
1827
+ "citation-type": t.citationType,
1828
+ "show-thinking": t.showThinking,
1829
+ "thinking-variant": t.thinkingVariant,
1830
+ "show-copy": t.showCopy,
1831
+ onRate: m,
1832
+ onRetry: c[0] ||= () => t.engine.retry(),
1833
+ onCitationClick: c[1] ||= (e, n) => t.engine.noteCitationClick(e, n)
1834
+ }, s({ _: 2 }, [n.$slots["message-actions"] ? {
1835
+ name: "message-actions",
1836
+ fn: j(({ message: e }) => [w(n.$slots, "message-actions", { message: e }, void 0, !0)]),
1837
+ key: "0"
1838
+ } : void 0]), 1032, [
1839
+ "message",
1840
+ "citation-type",
1841
+ "show-thinking",
1842
+ "thinking-variant",
1843
+ "show-copy"
1844
+ ]))], 64))), 128)),
1845
+ t.engine.status.value === "thinking" ? (v(), r(Kn, {
1846
+ key: 1,
1847
+ variant: t.thinkingVariant,
1848
+ "rotate-label": t.rotateThinkingLabel
1849
+ }, null, 8, ["variant", "rotate-label"])) : i("", !0),
1850
+ t.showThinking && t.engine.liveThinking.value ? (v(), r(On, {
1851
+ key: 2,
1852
+ text: t.engine.liveThinking.value,
1853
+ streaming: ""
1854
+ }, null, 8, ["text"])) : i("", !0),
1855
+ t.engine.error.value ? (v(), a("div", tr, [o("span", null, E(t.engine.errorKind.value === "rate-limited" ? D(u).status.rateLimited : D(u).status.error), 1), o("button", {
1856
+ type: "button",
1857
+ class: "message-list__retry",
1858
+ onClick: c[2] ||= () => t.engine.retry()
1859
+ }, E(D(u).status.retryLabel), 1)])) : i("", !0)
1860
+ ], 512));
1861
+ }
1862
+ }), [["__scopeId", "data-v-1e679b5e"]]), rr = { class: "chat" }, ir = /*#__PURE__*/ Y(/* @__PURE__ */ u({
1863
+ __name: "Chat",
1864
+ props: {
1865
+ engine: {},
1866
+ copy: {},
1867
+ showMic: { type: Boolean },
1868
+ citationType: {},
1869
+ thinkingVariant: {},
1870
+ rotateThinkingLabel: { type: Boolean },
1871
+ showThinking: { type: Boolean },
1872
+ autoScroll: {},
1873
+ showCopy: { type: Boolean }
1874
+ },
1875
+ emits: ["rated"],
1876
+ setup(e, { emit: t }) {
1877
+ let n = e, r = t;
1878
+ return ie(n.copy), (t, n) => (v(), a("div", rr, [l(nr, {
1879
+ engine: e.engine,
1880
+ "citation-type": e.citationType ?? "inline",
1881
+ "thinking-variant": e.thinkingVariant,
1882
+ "rotate-thinking-label": e.rotateThinkingLabel,
1883
+ "show-thinking": e.showThinking,
1884
+ "auto-scroll": e.autoScroll,
1885
+ "show-copy": e.showCopy,
1886
+ onRated: n[0] ||= (e, t) => r("rated", e, t)
1887
+ }, s({ _: 2 }, [t.$slots["message-actions"] ? {
1888
+ name: "message-actions",
1889
+ fn: j(({ message: e }) => [w(t.$slots, "message-actions", { message: e }, void 0, !0)]),
1890
+ key: "0"
1891
+ } : void 0, t.$slots.welcome ? {
1892
+ name: "welcome",
1893
+ fn: j(() => [w(t.$slots, "welcome", {}, void 0, !0)]),
1894
+ key: "1"
1895
+ } : void 0]), 1032, [
1896
+ "engine",
1897
+ "citation-type",
1898
+ "thinking-variant",
1899
+ "rotate-thinking-label",
1900
+ "show-thinking",
1901
+ "auto-scroll",
1902
+ "show-copy"
1903
+ ]), l(xt, {
1904
+ busy: e.engine.busy.value,
1905
+ "show-mic": e.showMic,
1906
+ onSend: n[1] ||= (t, n) => e.engine.sendMessage(t, n),
1907
+ onStop: n[2] ||= () => e.engine.stopGeneration()
1908
+ }, null, 8, ["busy", "show-mic"])]));
1909
+ }
1910
+ }), [["__scopeId", "data-v-f63ed144"]]);
1911
+ //#endregion
1912
+ export { V as AnonymousAuthError, ue as BaseCampClient, le as BaseCampError, ir as Chat, X as IconButton, et as MockTransport, fe as RateLimitError, Ke as StreamingMessage, U as consumeSSEResponse, ce as createAnonymousTokenProvider, G as decodeHtmlEntities, L as defaultChatCopy, ae as fetchAuthConfig, R as formatCopy, ie as provideChatCopy, W as renderMarkdownSafe, Ve as renderMarkdownStreaming, ne as resolveChatCopy, H as signInAnonymously, Se as streamSSE, Ge as stripHtmlTags, z as useChatCopy, Qe as useChatEngine };
1913
+
1914
+ //# sourceMappingURL=chat-kit.js.map