claudius-chat-widget 1.17.0 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/claudius.js CHANGED
@@ -1,9 +1,9 @@
1
- var dt = Object.defineProperty;
2
- var ft = (e, t, n) => t in e ? dt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var he = (e, t, n) => ft(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { jsx as i, jsxs as w, Fragment as ve } from "react/jsx-runtime";
5
- import { useMemo as se, useState as N, useRef as S, useCallback as M, useEffect as W, forwardRef as Je, memo as ke, useId as Ne } from "react";
6
- class Z extends Error {
1
+ var pt = Object.defineProperty;
2
+ var mt = (e, t, n) => t in e ? pt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var pe = (e, t, n) => mt(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { jsx as i, jsxs as g, Fragment as Te } from "react/jsx-runtime";
5
+ import { useMemo as ae, useState as M, useRef as C, useCallback as O, useEffect as H, forwardRef as Oe, memo as Ae, useId as Ne, Fragment as gt } from "react";
6
+ class Q extends Error {
7
7
  /**
8
8
  * Create a {@link ChatApiError}.
9
9
  *
@@ -22,13 +22,13 @@ class De extends Error {
22
22
  super("Request debounced"), this.name = "DebounceError";
23
23
  }
24
24
  }
25
- const ht = 3e4;
26
- function pt(e, t) {
25
+ const bt = 3e4;
26
+ function yt(e, t) {
27
27
  const n = atob(e), r = new Uint8Array(n.length);
28
28
  for (let o = 0; o < n.length; o++) r[o] = n.charCodeAt(o);
29
29
  return new Blob([r], { type: t });
30
30
  }
31
- class mt {
31
+ class wt {
32
32
  /**
33
33
  * Create a chat client for the given Worker base URL.
34
34
  *
@@ -36,12 +36,13 @@ class mt {
36
36
  * @param options - Optional retry, debounce, and timeout settings.
37
37
  */
38
38
  constructor(t, n) {
39
- he(this, "baseUrl");
40
- he(this, "maxRetries");
41
- he(this, "debounceMs");
42
- he(this, "timeoutMs");
43
- he(this, "lastSendTime", 0);
44
- this.baseUrl = t, this.maxRetries = (n == null ? void 0 : n.maxRetries) ?? 2, this.debounceMs = (n == null ? void 0 : n.debounceMs) ?? 300, this.timeoutMs = (n == null ? void 0 : n.timeoutMs) ?? ht;
39
+ pe(this, "baseUrl");
40
+ pe(this, "maxRetries");
41
+ pe(this, "debounceMs");
42
+ pe(this, "timeoutMs");
43
+ pe(this, "citations");
44
+ pe(this, "lastSendTime", 0);
45
+ this.baseUrl = t, this.maxRetries = (n == null ? void 0 : n.maxRetries) ?? 2, this.debounceMs = (n == null ? void 0 : n.debounceMs) ?? 300, this.timeoutMs = (n == null ? void 0 : n.timeoutMs) ?? bt, this.citations = (n == null ? void 0 : n.citations) ?? !1;
45
46
  }
46
47
  /**
47
48
  * Send the conversation to the chat endpoint and return the assistant's
@@ -64,7 +65,7 @@ class mt {
64
65
  if (o.ok)
65
66
  return await o.json();
66
67
  const s = await o.json().catch(() => ({})), a = o.headers.get("Retry-After"), c = a ? Number(a) : void 0;
67
- if (n = new Z(
68
+ if (n = new Q(
68
69
  s.error ?? `Request failed with status ${o.status}`,
69
70
  o.status,
70
71
  s.code,
@@ -76,14 +77,14 @@ class mt {
76
77
  await this.delay(l);
77
78
  }
78
79
  } catch (o) {
79
- if (o instanceof Z) {
80
+ if (o instanceof Q) {
80
81
  if (!this.isRetryable(o.status, o.code))
81
82
  throw o;
82
83
  if (n = o, r < this.maxRetries) {
83
84
  const s = this.getRetryDelay(null, r);
84
85
  await this.delay(s);
85
86
  }
86
- } else if (n = new Z(
87
+ } else if (n = new Q(
87
88
  "Failed to connect. Please try again.",
88
89
  0,
89
90
  "NETWORK_ERROR"
@@ -100,28 +101,32 @@ class mt {
100
101
  * never reuse a consumed stream.
101
102
  */
102
103
  buildRequest(t) {
103
- if (!t.some(
104
- (s) => {
105
- var a;
106
- return (a = s.attachments) == null ? void 0 : a.some((c) => !!c.data);
104
+ const n = t.some(
105
+ (a) => {
106
+ var c;
107
+ return (c = a.attachments) == null ? void 0 : c.some((l) => !!l.data);
107
108
  }
108
- ))
109
+ ), r = this.citations ? { citations: !0 } : {};
110
+ if (!n)
109
111
  return {
110
112
  headers: { "Content-Type": "application/json" },
111
- body: JSON.stringify({ messages: t })
113
+ body: JSON.stringify({ messages: t, ...r })
112
114
  };
113
- const r = new FormData(), o = t.map((s) => s.attachments ? {
114
- ...s,
115
- attachments: s.attachments.map((a) => {
116
- const c = { ...a };
117
- return delete c.data, c;
115
+ const o = new FormData(), s = t.map((a) => a.attachments ? {
116
+ ...a,
117
+ attachments: a.attachments.map((c) => {
118
+ const l = { ...c };
119
+ return delete l.data, l;
118
120
  })
119
- } : s);
120
- r.append("payload", JSON.stringify({ messages: o }));
121
- for (const s of t)
122
- for (const a of s.attachments ?? [])
123
- a.data && r.append(a.id, pt(a.data, a.mediaType), a.name);
124
- return { body: r };
121
+ } : a);
122
+ o.append(
123
+ "payload",
124
+ JSON.stringify({ messages: s, ...r })
125
+ );
126
+ for (const a of t)
127
+ for (const c of a.attachments ?? [])
128
+ c.data && o.append(c.id, yt(c.data, c.mediaType), c.name);
129
+ return { body: o };
125
130
  }
126
131
  /**
127
132
  * Send the conversation to the streaming chat endpoint and resolve with the
@@ -158,7 +163,7 @@ class mt {
158
163
  } catch (l) {
159
164
  if ((o = n.signal) != null && o.aborted)
160
165
  return { reply: "", aborted: !0 };
161
- if (r = l instanceof Z ? l : new Z(
166
+ if (r = l instanceof Q ? l : new Q(
162
167
  "Failed to connect. Please try again.",
163
168
  0,
164
169
  "NETWORK_ERROR"
@@ -171,7 +176,7 @@ class mt {
171
176
  return this.lastSendTime = 0, this.sendMessage(t);
172
177
  if (!a.ok) {
173
178
  const l = await a.json().catch(() => ({})), u = a.headers.get("Retry-After");
174
- if (r = new Z(
179
+ if (r = new Q(
175
180
  l.error ?? `Request failed with status ${a.status}`,
176
181
  a.status,
177
182
  l.code,
@@ -197,56 +202,58 @@ class mt {
197
202
  * resolving with the partial text when the caller aborts.
198
203
  */
199
204
  async readSseStream(t, n) {
200
- var d, x, A, g, f, p, T;
205
+ var T, A, m, h, d, k, b, x;
201
206
  const r = t.getReader(), o = new TextDecoder();
202
207
  let s = "", a = "";
203
208
  const c = [];
204
- let l;
205
- const u = () => {
209
+ let l, u;
210
+ const f = () => {
206
211
  r.cancel().catch(() => {
207
212
  });
208
213
  };
209
- (d = n.signal) == null || d.addEventListener("abort", u, { once: !0 });
214
+ (T = n.signal) == null || T.addEventListener("abort", f, { once: !0 });
210
215
  try {
211
216
  for (; ; ) {
212
- let b;
217
+ let y;
213
218
  try {
214
- b = await r.read();
215
- } catch (y) {
216
- if ((x = n.signal) != null && x.aborted) break;
217
- throw y;
219
+ y = await r.read();
220
+ } catch (D) {
221
+ if ((A = n.signal) != null && A.aborted) break;
222
+ throw D;
218
223
  }
219
- if ((A = n.signal) != null && A.aborted || b.done) break;
220
- s += o.decode(b.value, { stream: !0 });
221
- let R;
222
- for (; (R = s.indexOf(`
224
+ if ((m = n.signal) != null && m.aborted || y.done) break;
225
+ s += o.decode(y.value, { stream: !0 });
226
+ let w;
227
+ for (; (w = s.indexOf(`
223
228
 
224
229
  `)) !== -1; ) {
225
- const y = s.slice(0, R);
226
- s = s.slice(R + 2);
227
- const v = gt(y);
228
- if (v) {
229
- if (v.event === "chunk") {
230
- const C = typeof v.data.text == "string" ? v.data.text : "";
231
- C && (a += C, (g = n.onChunk) == null || g.call(n, C, a));
232
- } else if (v.event === "tool") {
233
- if (typeof v.data.name == "string") {
234
- const C = v.data;
235
- c.push(C), (f = n.onToolUse) == null || f.call(n, C, c);
230
+ const D = s.slice(0, w);
231
+ s = s.slice(w + 2);
232
+ const S = xt(D);
233
+ if (S) {
234
+ if (S.event === "chunk") {
235
+ const N = typeof S.data.text == "string" ? S.data.text : "";
236
+ N && (a += N, (h = n.onChunk) == null || h.call(n, N, a));
237
+ } else if (S.event === "tool") {
238
+ if (typeof S.data.name == "string") {
239
+ const N = S.data;
240
+ c.push(N), (d = n.onToolUse) == null || d.call(n, N, c);
236
241
  }
237
- } else if (v.event === "done") {
238
- const C = Array.isArray(v.data.toolUses) ? v.data.toolUses : c;
239
- l = {
240
- reply: typeof v.data.reply == "string" ? v.data.reply : a,
241
- sources: v.data.sources,
242
- ...C.length > 0 ? { toolUses: C } : {},
243
- ...Array.isArray(v.data.attachments) ? {
244
- attachments: v.data.attachments
242
+ } else if (S.event === "sources")
243
+ Array.isArray(S.data.sources) && (l = S.data.sources, (k = n.onSources) == null || k.call(n, l));
244
+ else if (S.event === "done") {
245
+ const N = Array.isArray(S.data.toolUses) ? S.data.toolUses : c;
246
+ u = {
247
+ reply: typeof S.data.reply == "string" ? S.data.reply : a,
248
+ sources: Array.isArray(S.data.sources) ? S.data.sources : l,
249
+ ...N.length > 0 ? { toolUses: N } : {},
250
+ ...Array.isArray(S.data.attachments) ? {
251
+ attachments: S.data.attachments
245
252
  } : {}
246
253
  };
247
- } else if (v.event === "error")
248
- throw new Z(
249
- typeof v.data.error == "string" ? v.data.error : "Something went wrong. Please try again.",
254
+ } else if (S.event === "error")
255
+ throw new Q(
256
+ typeof S.data.error == "string" ? S.data.error : "Something went wrong. Please try again.",
250
257
  0,
251
258
  "STREAM_ERROR"
252
259
  );
@@ -254,16 +261,17 @@ class mt {
254
261
  }
255
262
  }
256
263
  } finally {
257
- (p = n.signal) == null || p.removeEventListener("abort", u), r.releaseLock();
264
+ (b = n.signal) == null || b.removeEventListener("abort", f), r.releaseLock();
258
265
  }
259
- if ((T = n.signal) != null && T.aborted)
266
+ if ((x = n.signal) != null && x.aborted)
260
267
  return {
261
268
  reply: a,
262
269
  aborted: !0,
263
- ...c.length > 0 ? { toolUses: c } : {}
270
+ ...c.length > 0 ? { toolUses: c } : {},
271
+ ...l ? { sources: l } : {}
264
272
  };
265
- if (l) return l;
266
- throw new Z(
273
+ if (u) return u;
274
+ throw new Q(
267
275
  "Connection interrupted. Please try again.",
268
276
  0,
269
277
  "STREAM_ERROR"
@@ -284,7 +292,7 @@ class mt {
284
292
  signal: r.signal
285
293
  });
286
294
  } catch (u) {
287
- throw s ? new Z(
295
+ throw s ? new Q(
288
296
  "Request timed out. Please try again.",
289
297
  0,
290
298
  "TIMEOUT"
@@ -310,7 +318,7 @@ class mt {
310
318
  signal: o.signal
311
319
  });
312
320
  } catch (a) {
313
- throw o.signal.aborted ? new Z(
321
+ throw o.signal.aborted ? new Q(
314
322
  "Request timed out. Please try again.",
315
323
  0,
316
324
  "TIMEOUT"
@@ -336,7 +344,7 @@ class mt {
336
344
  return new Promise((n) => setTimeout(n, t));
337
345
  }
338
346
  }
339
- function gt(e) {
347
+ function xt(e) {
340
348
  let t = "message";
341
349
  const n = [];
342
350
  for (const r of e.split(`
@@ -354,10 +362,10 @@ function gt(e) {
354
362
  function Qe(e) {
355
363
  return typeof e == "string" ? { content: e } : e;
356
364
  }
357
- function Ie(e, t, n) {
365
+ function $e(e, t, n) {
358
366
  console.error(`[claudius] plugin "${e.name}" failed in ${t}:`, n);
359
367
  }
360
- async function bt(e, t, n) {
368
+ async function vt(e, t, n) {
361
369
  let r = t;
362
370
  for (const o of e) {
363
371
  if (!o.onBeforeSend) continue;
@@ -380,12 +388,12 @@ async function bt(e, t, n) {
380
388
  if (s) return s;
381
389
  c && (r = c);
382
390
  } catch (c) {
383
- Ie(o, "onBeforeSend", c);
391
+ $e(o, "onBeforeSend", c);
384
392
  }
385
393
  }
386
394
  return { type: "send", message: r };
387
395
  }
388
- async function yt(e, t, n) {
396
+ async function St(e, t, n) {
389
397
  let r = t;
390
398
  for (const o of e)
391
399
  if (o.onAfterReceive)
@@ -393,11 +401,11 @@ async function yt(e, t, n) {
393
401
  const s = await o.onAfterReceive(r, n);
394
402
  s && (r = s);
395
403
  } catch (s) {
396
- Ie(o, "onAfterReceive", s);
404
+ $e(o, "onAfterReceive", s);
397
405
  }
398
406
  return r;
399
407
  }
400
- async function xt(e, t, n) {
408
+ async function Tt(e, t, n) {
401
409
  for (const r of e) {
402
410
  if (!r.onError) continue;
403
411
  let o = null;
@@ -410,12 +418,12 @@ async function xt(e, t, n) {
410
418
  try {
411
419
  if (await r.onError(t, s), o) return o;
412
420
  } catch (a) {
413
- Ie(r, "onError", a);
421
+ $e(r, "onError", a);
414
422
  }
415
423
  }
416
424
  return null;
417
425
  }
418
- const Te = {
426
+ const Re = {
419
427
  maxSizeBytes: 5 * 1024 * 1024,
420
428
  maxCount: 5,
421
429
  allowedTypes: [
@@ -426,14 +434,14 @@ const Te = {
426
434
  "application/pdf"
427
435
  ]
428
436
  };
429
- function wt(e) {
430
- return e ? e === !0 ? Te : {
431
- maxSizeBytes: e.maxSizeBytes ?? Te.maxSizeBytes,
432
- maxCount: e.maxCount ?? Te.maxCount,
433
- allowedTypes: (e.allowedTypes ?? Te.allowedTypes).map((t) => t.trim().toLowerCase()).filter(Boolean)
437
+ function At(e) {
438
+ return e ? e === !0 ? Re : {
439
+ maxSizeBytes: e.maxSizeBytes ?? Re.maxSizeBytes,
440
+ maxCount: e.maxCount ?? Re.maxCount,
441
+ allowedTypes: (e.allowedTypes ?? Re.allowedTypes).map((t) => t.trim().toLowerCase()).filter(Boolean)
434
442
  } : null;
435
443
  }
436
- function Se(e) {
444
+ function Me(e) {
437
445
  if (!Number.isFinite(e) || e < 0) return "0 B";
438
446
  if (e < 1024) return `${e} B`;
439
447
  const t = e / 1024;
@@ -441,7 +449,7 @@ function Se(e) {
441
449
  const n = t / 1024;
442
450
  return `${Number.isInteger(n) ? n : n.toFixed(1)} MB`;
443
451
  }
444
- const vt = {
452
+ const kt = {
445
453
  png: "image/png",
446
454
  jpg: "image/jpeg",
447
455
  jpeg: "image/jpeg",
@@ -454,13 +462,13 @@ function Xe(e) {
454
462
  const t = (e.type || "").trim().toLowerCase();
455
463
  if (t) return t;
456
464
  const n = ((r = e.name.split(".").pop()) == null ? void 0 : r.toLowerCase()) ?? "";
457
- return vt[n] ?? "";
465
+ return kt[n] ?? "";
458
466
  }
459
- function Tt(e) {
467
+ function Rt(e) {
460
468
  return e.startsWith("image/");
461
469
  }
462
470
  function Et(e) {
463
- if (Tt(e.mediaType)) {
471
+ if (Rt(e.mediaType)) {
464
472
  if (e.url)
465
473
  try {
466
474
  const t = new URL(e.url);
@@ -471,7 +479,7 @@ function Et(e) {
471
479
  if (e.data) return `data:${e.mediaType};base64,${e.data}`;
472
480
  }
473
481
  }
474
- function Rt(e, t, n) {
482
+ function Ct(e, t, n) {
475
483
  const r = [], o = [];
476
484
  let s = Math.max(0, n.maxCount - t);
477
485
  for (const a of e) {
@@ -480,7 +488,7 @@ function Rt(e, t, n) {
480
488
  }
481
489
  return { accepted: r, rejected: o };
482
490
  }
483
- function At(e) {
491
+ function Nt(e) {
484
492
  return new Promise((t, n) => {
485
493
  const r = new FileReader();
486
494
  r.onerror = () => n(r.error ?? new Error("Failed to read file")), r.onload = () => {
@@ -489,14 +497,14 @@ function At(e) {
489
497
  }, r.readAsDataURL(e);
490
498
  });
491
499
  }
492
- let je = 0;
493
- function St() {
494
- return je += 1, `att-${Date.now().toString(36)}-${je}`;
500
+ let Pe = 0;
501
+ function Mt() {
502
+ return Pe += 1, `att-${Date.now().toString(36)}-${Pe}`;
495
503
  }
496
- async function kt(e) {
497
- const t = await At(e);
504
+ async function Lt(e) {
505
+ const t = await Nt(e);
498
506
  return {
499
- id: St(),
507
+ id: Mt(),
500
508
  name: e.name || "attachment",
501
509
  mediaType: Xe(e),
502
510
  size: e.size,
@@ -516,7 +524,7 @@ function et(e) {
516
524
  } : t;
517
525
  });
518
526
  }
519
- function Ct(e, t) {
527
+ function Dt(e, t) {
520
528
  if (!t || t.length === 0) return e;
521
529
  const n = new Map(t.map((r) => [r.id, r]));
522
530
  return e.map((r) => {
@@ -537,8 +545,8 @@ function Ct(e, t) {
537
545
  } : r;
538
546
  });
539
547
  }
540
- const Mt = 200, Nt = "claudius:messages", be = () => (/* @__PURE__ */ new Date()).toISOString();
541
- function Dt(e, t) {
548
+ const It = 200, Ot = "claudius:messages", we = () => (/* @__PURE__ */ new Date()).toISOString();
549
+ function $t(e, t) {
542
550
  let n;
543
551
  try {
544
552
  n = new URL(t).host;
@@ -547,15 +555,15 @@ function Dt(e, t) {
547
555
  }
548
556
  return `${e}:${n}`;
549
557
  }
550
- function Le() {
558
+ function Ie() {
551
559
  try {
552
560
  return typeof sessionStorage < "u" ? sessionStorage : null;
553
561
  } catch {
554
562
  return null;
555
563
  }
556
564
  }
557
- function Lt(e) {
558
- const t = Le();
565
+ function jt(e) {
566
+ const t = Ie();
559
567
  if (!t) return [];
560
568
  try {
561
569
  const n = t.getItem(e);
@@ -566,45 +574,46 @@ function Lt(e) {
566
574
  return [];
567
575
  }
568
576
  }
569
- function It({
577
+ function Pt({
570
578
  apiUrl: e,
571
579
  persistMessages: t = !0,
572
- storageKeyPrefix: n = Nt,
580
+ storageKeyPrefix: n = Ot,
573
581
  timeoutMs: r,
574
582
  translations: o,
575
583
  plugins: s,
576
- streaming: a = !0
584
+ streaming: a = !0,
585
+ citations: c = !1
577
586
  }) {
578
- const c = se(
579
- () => new mt(e, { debounceMs: 0, timeoutMs: r }),
580
- [e, r]
581
- ), l = Dt(n, e), u = t ? Lt(l) : [], [d, x] = N(u), [A, g] = N(!1), [f, p] = N(!1), [T, b] = N(
587
+ const l = ae(
588
+ () => new wt(e, { debounceMs: 0, timeoutMs: r, citations: c }),
589
+ [e, r, c]
590
+ ), u = $t(n, e), f = t ? jt(u) : [], [T, A] = M(f), [m, h] = M(!1), [d, k] = M(!1), [b, x] = M(
582
591
  null
583
- ), [R, y] = N(null), [v, C] = N(!1), $ = S(u.length), L = S(!1), E = S(u), B = S(null), O = S(s ?? []);
584
- O.current = s ?? [];
585
- const _ = M(
586
- (h) => {
592
+ ), [y, w] = M(null), [D, S] = M(!1), N = C(f.length), I = C(!1), R = C(f), ne = C(null), $ = C(s ?? []);
593
+ $.current = s ?? [];
594
+ const z = O(
595
+ (E) => {
587
596
  if (!t) return;
588
- const P = Le();
589
- if (P)
597
+ const B = Ie();
598
+ if (B)
590
599
  try {
591
- const U = et(h.slice(-Mt));
592
- P.setItem(l, JSON.stringify(U));
600
+ const P = et(E.slice(-It));
601
+ B.setItem(u, JSON.stringify(P));
593
602
  } catch {
594
603
  }
595
604
  },
596
- [t, l]
597
- ), q = () => ($.current += 1, `msg-${$.current}`), G = M(
598
- (h, P) => {
605
+ [t, u]
606
+ ), X = () => (N.current += 1, `msg-${N.current}`), Z = O(
607
+ (E, B) => {
599
608
  if (!o)
600
- return P ?? "Something went wrong. Please try again.";
601
- switch (h) {
609
+ return B ?? "Something went wrong. Please try again.";
610
+ switch (E) {
602
611
  case "TIMEOUT":
603
612
  return o.errorTimeout;
604
613
  case "NETWORK_ERROR":
605
614
  return o.errorConnection;
606
615
  case "RATE_LIMITED":
607
- return P != null && P.includes("minute") ? o.errorRateLimitMinute : o.errorRateLimitHour;
616
+ return B != null && B.includes("minute") ? o.errorRateLimitMinute : o.errorRateLimitHour;
608
617
  case "ATTACHMENT_QUOTA_EXCEEDED":
609
618
  return o.errorAttachmentQuota;
610
619
  case "ATTACHMENTS_DISABLED":
@@ -616,199 +625,204 @@ function It({
616
625
  case "SERVICE_ERROR":
617
626
  case "UNKNOWN_ERROR":
618
627
  default:
619
- return P ?? o.errorGeneric;
628
+ return B ?? o.errorGeneric;
620
629
  }
621
630
  },
622
631
  [o]
623
- ), J = M((h) => !(h instanceof Z) || h.code === "TIMEOUT" || h.code === "NETWORK_ERROR" || h.code === "RATE_LIMITED" || h.code === "SERVICE_ERROR" || h.code === "UNKNOWN_ERROR" || h.status >= 500 || h.status === 0, []), z = M(
624
- async (h) => {
625
- var ne, F, H;
626
- g(!0), L.current = !0, y(null), C(!1);
627
- const P = a && typeof c.streamMessage == "function";
628
- let U = null;
629
- const ee = (k) => {
630
- if (U === null) {
631
- U = q(), b(U);
632
- const D = [
633
- ...E.current,
632
+ ), J = O((E) => !(E instanceof Q) || E.code === "TIMEOUT" || E.code === "NETWORK_ERROR" || E.code === "RATE_LIMITED" || E.code === "SERVICE_ERROR" || E.code === "UNKNOWN_ERROR" || E.status >= 500 || E.status === 0, []), W = O(
633
+ async (E) => {
634
+ var F, ee, te;
635
+ h(!0), I.current = !0, w(null), S(!1);
636
+ const B = a && typeof l.streamMessage == "function";
637
+ let P = null, v;
638
+ const V = () => c ? v : void 0, K = (L) => {
639
+ if (P === null) {
640
+ P = X(), x(P);
641
+ const _ = [
642
+ ...R.current,
634
643
  {
635
- id: U,
644
+ id: P,
636
645
  role: "assistant",
637
646
  content: "",
638
- createdAt: be(),
639
- ...k
647
+ createdAt: we(),
648
+ ...V() ? { sources: v } : {},
649
+ ...L
640
650
  }
641
651
  ];
642
- E.current = D, x(D);
652
+ R.current = _, A(_);
643
653
  } else {
644
- const D = U, I = E.current.map(
645
- (K) => K.id === D ? { ...K, ...k } : K
654
+ const _ = P, U = R.current.map(
655
+ (Y) => Y.id === _ ? { ...Y, ...L } : Y
646
656
  );
647
- E.current = I, x(I);
657
+ R.current = U, A(U);
648
658
  }
649
- }, te = () => {
650
- if (U === null) return;
651
- const k = U, D = E.current.filter((I) => I.id !== k);
652
- E.current = D, x(D);
659
+ }, oe = () => {
660
+ if (P === null) return;
661
+ const L = P, _ = R.current.filter((U) => U.id !== L);
662
+ R.current = _, A(_);
653
663
  };
654
664
  try {
655
- let k, D, I, K, Q = !1;
656
- if (P) {
657
- const V = new AbortController();
658
- B.current = V, p(!0);
659
- const oe = await c.streamMessage(h, {
660
- signal: V.signal,
661
- onChunk: (ge, de) => ee({ content: de }),
662
- onToolUse: (ge, de) => ee({ toolUses: [...de] })
665
+ let L, _, U, Y, se = !1;
666
+ if (B) {
667
+ const q = new AbortController();
668
+ ne.current = q, k(!0);
669
+ const ie = await l.streamMessage(E, {
670
+ signal: q.signal,
671
+ onChunk: (he, p) => K({ content: p }),
672
+ onToolUse: (he, p) => K({ toolUses: [...p] }),
673
+ onSources: (he) => {
674
+ v = he, c && P !== null && K({ sources: he });
675
+ }
663
676
  });
664
- k = oe.reply, D = oe.sources, I = oe.toolUses, K = oe.attachments, Q = oe.aborted ?? !1;
677
+ L = ie.reply, _ = ie.sources ?? v, U = ie.toolUses, Y = ie.attachments, se = ie.aborted ?? !1;
665
678
  } else {
666
- const V = await c.sendMessage(h);
667
- k = V.reply, D = V.sources, I = V.toolUses, K = V.attachments;
679
+ const q = await l.sendMessage(E);
680
+ L = q.reply, _ = q.sources, U = q.toolUses, Y = q.attachments;
668
681
  }
669
- if (Q && !k) {
670
- te();
682
+ if (se && !L) {
683
+ oe();
671
684
  return;
672
685
  }
673
- const le = ((ne = E.current.find((V) => V.id === U)) == null ? void 0 : ne.createdAt) ?? be();
674
- let Y = {
675
- id: U ?? q(),
686
+ const le = ((F = R.current.find((q) => q.id === P)) == null ? void 0 : F.createdAt) ?? we();
687
+ let re = {
688
+ id: P ?? X(),
676
689
  role: "assistant",
677
- content: k,
690
+ content: L,
678
691
  createdAt: le,
679
- sources: D,
680
- toolUses: I
692
+ sources: _,
693
+ toolUses: U
681
694
  };
682
- O.current.length > 0 && !Q && (Y = await yt(
683
- O.current,
684
- Y,
685
- { messages: h, apiUrl: e }
686
- ), Y.createdAt || (Y = { ...Y, createdAt: le }));
687
- const me = U !== null ? E.current.map(
688
- (V) => V.id === Y.id ? Y : V
689
- ) : [...h, Y], ue = Ct(me, K);
690
- E.current = ue, x(ue), _(ue);
691
- } catch (k) {
692
- if (k instanceof De) return;
693
- if (k instanceof Z && ((F = k.code) != null && F.startsWith("ATTACHMENT")) && h.length > 0) {
694
- const D = h[h.length - 1];
695
- if (D.role === "user" && ((H = D.attachments) != null && H.length)) {
696
- const I = h.slice(0, -1);
697
- E.current = I, x(I), _(I);
695
+ $.current.length > 0 && !se && (re = await St(
696
+ $.current,
697
+ re,
698
+ { messages: E, apiUrl: e }
699
+ ), re.createdAt || (re = { ...re, createdAt: le }));
700
+ const ye = P !== null ? R.current.map(
701
+ (q) => q.id === re.id ? re : q
702
+ ) : [...E, re], me = Dt(ye, Y);
703
+ R.current = me, A(me), z(me);
704
+ } catch (L) {
705
+ if (L instanceof De) return;
706
+ if (L instanceof Q && ((ee = L.code) != null && ee.startsWith("ATTACHMENT")) && E.length > 0) {
707
+ const _ = E[E.length - 1];
708
+ if (_.role === "user" && ((te = _.attachments) != null && te.length)) {
709
+ const U = E.slice(0, -1);
710
+ R.current = U, A(U), z(U);
698
711
  }
699
712
  }
700
- if (U !== null) {
701
- _(E.current), k instanceof Z ? y(G(k.code, k.message)) : y(
713
+ if (P !== null) {
714
+ z(R.current), L instanceof Q ? w(Z(L.code, L.message)) : w(
702
715
  (o == null ? void 0 : o.errorConnection) ?? "Failed to connect. Please try again."
703
- ), C(!1);
716
+ ), S(!1);
704
717
  return;
705
718
  }
706
- if (O.current.length > 0) {
707
- const D = k instanceof Error ? k : new Error(String(k)), I = await xt(O.current, D, {
708
- messages: h,
719
+ if ($.current.length > 0) {
720
+ const _ = L instanceof Error ? L : new Error(String(L)), U = await Tt($.current, _, {
721
+ messages: E,
709
722
  apiUrl: e
710
723
  });
711
- if (I) {
712
- const K = {
713
- id: q(),
724
+ if (U) {
725
+ const Y = {
726
+ id: X(),
714
727
  role: "assistant",
715
- content: I.content,
716
- createdAt: be(),
717
- sources: I.sources
718
- }, Q = [...h, K];
719
- E.current = Q, x(Q), _(Q), y(null), C(!1);
728
+ content: U.content,
729
+ createdAt: we(),
730
+ sources: U.sources
731
+ }, se = [...E, Y];
732
+ R.current = se, A(se), z(se), w(null), S(!1);
720
733
  return;
721
734
  }
722
735
  }
723
- k instanceof Z ? y(G(k.code, k.message)) : y(
736
+ L instanceof Q ? w(Z(L.code, L.message)) : w(
724
737
  (o == null ? void 0 : o.errorConnection) ?? "Failed to connect. Please try again."
725
- ), C(J(k));
738
+ ), S(J(L));
726
739
  } finally {
727
- g(!1), L.current = !1, p(!1), b(null), B.current = null;
740
+ h(!1), I.current = !1, k(!1), x(null), ne.current = null;
728
741
  }
729
742
  },
730
743
  [
731
744
  e,
732
745
  c,
733
- G,
746
+ l,
747
+ Z,
734
748
  J,
735
- _,
749
+ z,
736
750
  a,
737
751
  o
738
752
  ]
739
- ), ae = M(() => {
740
- var h;
741
- (h = B.current) == null || h.abort();
742
- }, []), ie = M(
743
- async (h, P) => {
744
- const U = h.trim(), ee = (P == null ? void 0 : P.filter((H) => H && H.id)) ?? [];
745
- if (!U && ee.length === 0 || L.current) return;
746
- const te = {
747
- id: q(),
753
+ ), G = O(() => {
754
+ var E;
755
+ (E = ne.current) == null || E.abort();
756
+ }, []), ce = O(
757
+ async (E, B) => {
758
+ const P = E.trim(), v = (B == null ? void 0 : B.filter((F) => F && F.id)) ?? [];
759
+ if (!P && v.length === 0 || I.current) return;
760
+ const V = {
761
+ id: X(),
748
762
  role: "user",
749
- content: U,
750
- createdAt: be(),
751
- ...ee.length > 0 ? { attachments: ee } : {}
763
+ content: P,
764
+ createdAt: we(),
765
+ ...v.length > 0 ? { attachments: v } : {}
752
766
  };
753
- let ne = te;
754
- if (O.current.length > 0) {
755
- const H = await bt(O.current, te, {
756
- messages: E.current,
767
+ let K = V;
768
+ if ($.current.length > 0) {
769
+ const F = await vt($.current, V, {
770
+ messages: R.current,
757
771
  apiUrl: e
758
772
  });
759
- if (H.type === "abort") return;
760
- const k = (D) => D.createdAt ? D : { ...D, createdAt: te.createdAt };
761
- if (H.type === "respond") {
762
- const D = {
763
- id: q(),
773
+ if (F.type === "abort") return;
774
+ const ee = (te) => te.createdAt ? te : { ...te, createdAt: V.createdAt };
775
+ if (F.type === "respond") {
776
+ const te = {
777
+ id: X(),
764
778
  role: "assistant",
765
- content: H.reply.content,
766
- createdAt: be(),
767
- sources: H.reply.sources
768
- }, I = [
769
- ...E.current,
770
- k(H.message),
771
- D
779
+ content: F.reply.content,
780
+ createdAt: we(),
781
+ sources: F.reply.sources
782
+ }, L = [
783
+ ...R.current,
784
+ ee(F.message),
785
+ te
772
786
  ];
773
- E.current = I, x(I), _(I), y(null), C(!1);
787
+ R.current = L, A(L), z(L), w(null), S(!1);
774
788
  return;
775
789
  }
776
- ne = k(H.message);
790
+ K = ee(F.message);
777
791
  }
778
- const F = [...E.current, ne];
779
- E.current = F, x(F), _(F), await z(F);
792
+ const oe = [...R.current, K];
793
+ R.current = oe, A(oe), z(oe), await W(oe);
780
794
  },
781
- [e, _, z]
782
- ), ce = M(async () => {
783
- if (L.current) return;
784
- const h = E.current[E.current.length - 1];
785
- !h || h.role !== "user" || await z(E.current);
786
- }, [z]), re = M(() => {
787
- if (E.current = [], x([]), y(null), C(!1), t) {
788
- const h = Le();
789
- if (!h) return;
795
+ [e, z, W]
796
+ ), de = O(async () => {
797
+ if (I.current) return;
798
+ const E = R.current[R.current.length - 1];
799
+ !E || E.role !== "user" || await W(R.current);
800
+ }, [W]), fe = O(() => {
801
+ if (R.current = [], A([]), w(null), S(!1), t) {
802
+ const E = Ie();
803
+ if (!E) return;
790
804
  try {
791
- h.removeItem(l);
805
+ E.removeItem(u);
792
806
  } catch {
793
807
  }
794
808
  }
795
- }, [t, l]);
809
+ }, [t, u]);
796
810
  return {
797
- messages: d,
798
- isLoading: A,
799
- isStreaming: f,
800
- streamingMessageId: T,
801
- error: R,
802
- canRetry: v,
803
- sendMessage: ie,
804
- stop: ae,
805
- retry: ce,
806
- clearMessages: re
811
+ messages: T,
812
+ isLoading: m,
813
+ isStreaming: d,
814
+ streamingMessageId: b,
815
+ error: y,
816
+ canRetry: D,
817
+ sendMessage: ce,
818
+ stop: G,
819
+ retry: de,
820
+ clearMessages: fe
807
821
  };
808
822
  }
809
- function Ot(e) {
810
- const [t, n] = N(() => typeof window > "u" ? !1 : window.matchMedia(e).matches);
811
- return W(() => {
823
+ function Ut(e) {
824
+ const [t, n] = M(() => typeof window > "u" ? !1 : window.matchMedia(e).matches);
825
+ return H(() => {
812
826
  const r = window.matchMedia(e);
813
827
  n(r.matches);
814
828
  const o = (s) => n(s.matches);
@@ -818,17 +832,17 @@ function Ot(e) {
818
832
  function Ee(e, t) {
819
833
  return e instanceof RegExp ? e.test(t) : t.toLowerCase().includes(e.toLowerCase());
820
834
  }
821
- function jt() {
835
+ function Bt() {
822
836
  const e = document.documentElement, t = document.body, n = e.scrollTop || t.scrollTop || 0, r = Math.max(e.scrollHeight, t.scrollHeight), o = e.clientHeight || window.innerHeight, s = r - o;
823
837
  return s <= 0 ? 100 : n / s * 100;
824
838
  }
825
- function $t({
839
+ function Ft({
826
840
  triggers: e,
827
841
  enabled: t,
828
842
  onOpen: n,
829
843
  onGreeting: r
830
844
  }) {
831
- W(() => {
845
+ H(() => {
832
846
  if (!t || !e || e.length === 0) return;
833
847
  const o = /* @__PURE__ */ new Set(), s = [], a = typeof window < "u" ? window.location.href : "", c = (l, u) => {
834
848
  o.has(l) || (o.add(l), u === "open" ? n() : r(u.greeting));
@@ -842,30 +856,30 @@ function $t({
842
856
  case "time": {
843
857
  if (l.matchUrl && !Ee(l.matchUrl, a))
844
858
  return;
845
- const d = window.setTimeout(
859
+ const f = window.setTimeout(
846
860
  () => c(u, l.action),
847
861
  Math.max(0, l.seconds * 1e3)
848
862
  );
849
- s.push(() => window.clearTimeout(d));
863
+ s.push(() => window.clearTimeout(f));
850
864
  break;
851
865
  }
852
866
  case "scroll": {
853
867
  if (l.matchUrl && !Ee(l.matchUrl, a))
854
868
  return;
855
- const d = () => {
856
- jt() >= l.percent && c(u, l.action);
869
+ const f = () => {
870
+ Bt() >= l.percent && c(u, l.action);
857
871
  };
858
- d(), window.addEventListener("scroll", d, { passive: !0 }), s.push(() => window.removeEventListener("scroll", d));
872
+ f(), window.addEventListener("scroll", f, { passive: !0 }), s.push(() => window.removeEventListener("scroll", f));
859
873
  break;
860
874
  }
861
875
  case "exit-intent": {
862
876
  if (l.matchUrl && !Ee(l.matchUrl, a))
863
877
  return;
864
- const d = (x) => {
865
- x.clientY <= 0 && c(u, l.action);
878
+ const f = (T) => {
879
+ T.clientY <= 0 && c(u, l.action);
866
880
  };
867
- document.addEventListener("mouseleave", d), s.push(
868
- () => document.removeEventListener("mouseleave", d)
881
+ document.addEventListener("mouseleave", f), s.push(
882
+ () => document.removeEventListener("mouseleave", f)
869
883
  );
870
884
  break;
871
885
  }
@@ -875,12 +889,12 @@ function $t({
875
889
  };
876
890
  }, [e, t, n, r]);
877
891
  }
878
- const Pt = {
892
+ const _t = {
879
893
  "bottom-right": "bottom-6 right-6",
880
894
  "bottom-left": "bottom-6 left-6",
881
895
  "top-right": "top-6 right-6",
882
896
  "top-left": "top-6 left-6"
883
- }, Ut = Je(function({ isOpen: t, onClick: n, position: r = "bottom-right", translations: o }, s) {
897
+ }, Ht = Oe(function({ isOpen: t, onClick: n, position: r = "bottom-right", translations: o }, s) {
884
898
  const a = t ? (o == null ? void 0 : o.closeChat) ?? "Close chat" : (o == null ? void 0 : o.openChat) ?? "Open chat";
885
899
  return /* @__PURE__ */ i(
886
900
  "button",
@@ -888,8 +902,8 @@ const Pt = {
888
902
  ref: s,
889
903
  onClick: n,
890
904
  "aria-label": a,
891
- className: `fixed ${Pt[r]} z-50 flex h-14 w-14 items-center justify-center rounded-claudius-full bg-claudius-accent text-claudius-accent-text shadow-claudius-floating transition-transform hover:scale-105 focus:outline-none focus:ring-2 focus:ring-claudius-accent focus:ring-offset-2`,
892
- children: t ? /* @__PURE__ */ w(
905
+ className: `fixed ${_t[r]} z-50 flex h-14 w-14 items-center justify-center rounded-claudius-full bg-claudius-accent text-claudius-accent-text shadow-claudius-floating transition-transform hover:scale-105 focus:outline-none focus:ring-2 focus:ring-claudius-accent focus:ring-offset-2`,
906
+ children: t ? /* @__PURE__ */ g(
893
907
  "svg",
894
908
  {
895
909
  width: "24",
@@ -923,12 +937,12 @@ const Pt = {
923
937
  )
924
938
  }
925
939
  );
926
- }), Bt = ke(function({
940
+ }), zt = Ae(function({
927
941
  count: t,
928
942
  isActive: n,
929
943
  onClick: r
930
944
  }) {
931
- return /* @__PURE__ */ w(
945
+ return /* @__PURE__ */ g(
932
946
  "button",
933
947
  {
934
948
  onClick: r,
@@ -936,7 +950,7 @@ const Pt = {
936
950
  title: "View sources",
937
951
  className: `group relative flex h-7 w-7 items-center justify-center rounded-claudius-full transition-colors ${n ? "bg-claudius-accent text-claudius-accent-text" : "text-claudius-text-muted hover:bg-claudius-surface-muted hover:text-claudius-text"}`,
938
952
  children: [
939
- /* @__PURE__ */ w(
953
+ /* @__PURE__ */ g(
940
954
  "svg",
941
955
  {
942
956
  width: "14",
@@ -960,8 +974,8 @@ const Pt = {
960
974
  ]
961
975
  }
962
976
  );
963
- }), _t = ["http:", "https:"];
964
- function Ce(e) {
977
+ }), Wt = ["http:", "https:"];
978
+ function ke(e) {
965
979
  if (!e || typeof e != "string")
966
980
  return null;
967
981
  const t = e.trim();
@@ -969,13 +983,290 @@ function Ce(e) {
969
983
  return null;
970
984
  try {
971
985
  const n = new URL(t);
972
- return _t.includes(n.protocol) ? t : null;
986
+ return Wt.includes(n.protocol) ? t : null;
987
+ } catch {
988
+ return null;
989
+ }
990
+ }
991
+ function ge(e, t) {
992
+ return e.replace(
993
+ /\{(\w+)\}/g,
994
+ (n, r) => r in t ? String(t[r]) : n
995
+ );
996
+ }
997
+ const Gt = {
998
+ maxSources: 5,
999
+ favicons: !0
1000
+ };
1001
+ function Vt(e) {
1002
+ const t = typeof e == "object" && e !== null && !Array.isArray(e);
1003
+ if (e !== !0 && !t) return null;
1004
+ const n = e === !0 ? {} : e, r = n.maxSources;
1005
+ return {
1006
+ maxSources: typeof r == "number" && Number.isInteger(r) && r >= 1 ? r : Gt.maxSources,
1007
+ favicons: n.favicons !== !1
1008
+ };
1009
+ }
1010
+ const Kt = /\[([1-9]\d{0,2}(?:\s*,\s*[1-9]\d{0,2})*)\]/g;
1011
+ function tt(e, t) {
1012
+ if (!e) return [];
1013
+ if (t <= 0 || !e.includes("["))
1014
+ return [{ type: "text", value: e }];
1015
+ const n = [];
1016
+ let r = 0;
1017
+ for (const o of e.matchAll(Kt)) {
1018
+ const s = o[1].split(",").map((c) => Number(c.trim()));
1019
+ if (s.some((c) => c > t)) continue;
1020
+ const a = o.index ?? 0;
1021
+ a > r && n.push({ type: "text", value: e.slice(r, a) }), n.push({
1022
+ type: "cite",
1023
+ indexes: [...new Set(s)].map((c) => c - 1),
1024
+ raw: o[0]
1025
+ }), r = a + o[0].length;
1026
+ }
1027
+ return r < e.length && n.push({ type: "text", value: e.slice(r) }), n;
1028
+ }
1029
+ function Yt(e, t) {
1030
+ let n = "";
1031
+ for (const r of tt(e, t))
1032
+ r.type === "text" ? n += r.value : n = n.replace(/[ \t]+$/, "");
1033
+ return n;
1034
+ }
1035
+ function qt(e) {
1036
+ return e.replace(/[ \t]?\[[\d,\s]*$/, "");
1037
+ }
1038
+ const Zt = 200;
1039
+ function Jt(e, t = Zt) {
1040
+ const n = e.replace(/\s+/g, " ").trim();
1041
+ if (n.length <= t) return n;
1042
+ const r = n.slice(0, t), o = r.lastIndexOf(" ");
1043
+ return `${(o > 0 ? r.slice(0, o) : r).replace(
1044
+ /[\s,;:]+$/,
1045
+ ""
1046
+ )}…`;
1047
+ }
1048
+ function Qt(e) {
1049
+ try {
1050
+ const t = new URL(e);
1051
+ return t.protocol !== "http:" && t.protocol !== "https:" ? null : `${t.origin}/favicon.ico`;
973
1052
  } catch {
974
1053
  return null;
975
1054
  }
976
1055
  }
977
- function zt() {
978
- return /* @__PURE__ */ w(
1056
+ function Xt(e) {
1057
+ try {
1058
+ return new URL(e).hostname;
1059
+ } catch {
1060
+ return e;
1061
+ }
1062
+ }
1063
+ const en = 1500;
1064
+ function tn() {
1065
+ return typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(prefers-reduced-motion: reduce)").matches : !1;
1066
+ }
1067
+ const nt = "flex h-4 min-w-4 shrink-0 items-center justify-center rounded-claudius-full bg-claudius-accent px-1 text-[10px] font-bold leading-none text-claudius-accent-text", nn = Oe(
1068
+ function({ source: t, number: n, favicons: r, labels: o, highlighted: s }, a) {
1069
+ const c = ke(t.url), [l, u] = M(!1), f = r && c ? Qt(c) : null, T = t.snippet ? Jt(t.snippet) : "";
1070
+ return /* @__PURE__ */ g(
1071
+ "li",
1072
+ {
1073
+ ref: a,
1074
+ tabIndex: -1,
1075
+ "data-highlight": s || void 0,
1076
+ className: `flex gap-2 rounded-claudius-md border bg-claudius-surface-muted p-2 focus:outline-none focus-visible:ring-2 focus-visible:ring-claudius-accent ${s ? "border-claudius-accent ring-2 ring-claudius-accent" : "border-claudius-border"}`,
1077
+ children: [
1078
+ /* @__PURE__ */ i("span", { "aria-hidden": "true", className: `mt-0.5 ${nt}`, children: n }),
1079
+ /* @__PURE__ */ g("div", { className: "min-w-0 flex-1", children: [
1080
+ /* @__PURE__ */ g("div", { className: "flex items-center gap-1.5", children: [
1081
+ f && !l ? /* @__PURE__ */ i(
1082
+ "img",
1083
+ {
1084
+ src: f,
1085
+ alt: "",
1086
+ width: 14,
1087
+ height: 14,
1088
+ loading: "lazy",
1089
+ decoding: "async",
1090
+ referrerPolicy: "no-referrer",
1091
+ onError: () => u(!0),
1092
+ className: "h-3.5 w-3.5 shrink-0 rounded-sm"
1093
+ }
1094
+ ) : /* @__PURE__ */ g(
1095
+ "svg",
1096
+ {
1097
+ width: "14",
1098
+ height: "14",
1099
+ viewBox: "0 0 24 24",
1100
+ fill: "none",
1101
+ stroke: "currentColor",
1102
+ strokeWidth: "2",
1103
+ strokeLinecap: "round",
1104
+ strokeLinejoin: "round",
1105
+ "aria-hidden": "true",
1106
+ className: "shrink-0",
1107
+ children: [
1108
+ /* @__PURE__ */ i("circle", { cx: "12", cy: "12", r: "10" }),
1109
+ /* @__PURE__ */ i("path", { d: "M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20" }),
1110
+ /* @__PURE__ */ i("path", { d: "M2 12h20" })
1111
+ ]
1112
+ }
1113
+ ),
1114
+ c ? /* @__PURE__ */ g(
1115
+ "a",
1116
+ {
1117
+ href: c,
1118
+ target: "_blank",
1119
+ rel: "noopener noreferrer",
1120
+ className: "truncate font-medium text-claudius-text hover:underline",
1121
+ children: [
1122
+ t.title,
1123
+ /* @__PURE__ */ g("span", { className: "sr-only", children: [
1124
+ " ",
1125
+ o.opensInNewTab
1126
+ ] })
1127
+ ]
1128
+ }
1129
+ ) : /* @__PURE__ */ i("span", { className: "truncate font-medium text-claudius-text", children: t.title }),
1130
+ c && /* @__PURE__ */ g(
1131
+ "svg",
1132
+ {
1133
+ width: "12",
1134
+ height: "12",
1135
+ viewBox: "0 0 24 24",
1136
+ fill: "none",
1137
+ stroke: "currentColor",
1138
+ strokeWidth: "2",
1139
+ strokeLinecap: "round",
1140
+ strokeLinejoin: "round",
1141
+ "aria-hidden": "true",
1142
+ className: "shrink-0",
1143
+ children: [
1144
+ /* @__PURE__ */ i("path", { d: "M15 3h6v6" }),
1145
+ /* @__PURE__ */ i("path", { d: "M10 14 21 3" }),
1146
+ /* @__PURE__ */ i("path", { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" })
1147
+ ]
1148
+ }
1149
+ )
1150
+ ] }),
1151
+ T && /* @__PURE__ */ i("p", { className: "mt-0.5 break-words", children: T }),
1152
+ c && /* @__PURE__ */ i("p", { className: "mt-0.5 truncate", children: Xt(c) })
1153
+ ] })
1154
+ ]
1155
+ }
1156
+ );
1157
+ }
1158
+ ), rn = Ae(function({
1159
+ sources: t,
1160
+ maxSources: n,
1161
+ favicons: r,
1162
+ labels: o,
1163
+ reveal: s = null
1164
+ }) {
1165
+ const a = Ne(), [c, l] = M(!1), [u, f] = M(!1), [T, A] = M(null), [m, h] = M(null), d = C(/* @__PURE__ */ new Map()), k = C(n);
1166
+ k.current = n, H(() => {
1167
+ s && (A(s), l(!0), s.index >= k.current && f(!0));
1168
+ }, [s]), H(() => {
1169
+ if (!T) return;
1170
+ const y = d.current.get(T.index);
1171
+ y && (typeof y.scrollIntoView == "function" && y.scrollIntoView({
1172
+ block: "nearest",
1173
+ behavior: tn() ? "auto" : "smooth"
1174
+ }), y.focus({ preventScroll: !0 }), h(T), A(null));
1175
+ }, [T]), H(() => {
1176
+ if (!m) return;
1177
+ const y = setTimeout(() => h(null), en);
1178
+ return () => clearTimeout(y);
1179
+ }, [m]);
1180
+ const b = t.length, x = u ? t : t.slice(0, n);
1181
+ return /* @__PURE__ */ g("div", { className: "mt-1 text-xs text-claudius-text-muted", children: [
1182
+ /* @__PURE__ */ g(
1183
+ "button",
1184
+ {
1185
+ type: "button",
1186
+ onClick: () => l((y) => !y),
1187
+ "aria-expanded": c,
1188
+ "aria-controls": c ? a : void 0,
1189
+ className: "flex items-center gap-1.5 rounded-claudius-full border border-claudius-border bg-claudius-surface px-2 py-0.5 hover:opacity-80 focus:outline-none focus-visible:ring-2 focus-visible:ring-claudius-accent",
1190
+ children: [
1191
+ /* @__PURE__ */ g(
1192
+ "svg",
1193
+ {
1194
+ width: "11",
1195
+ height: "11",
1196
+ viewBox: "0 0 24 24",
1197
+ fill: "none",
1198
+ stroke: "currentColor",
1199
+ strokeWidth: "2",
1200
+ strokeLinecap: "round",
1201
+ strokeLinejoin: "round",
1202
+ "aria-hidden": "true",
1203
+ children: [
1204
+ /* @__PURE__ */ i("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
1205
+ /* @__PURE__ */ i("polyline", { points: "14 2 14 8 20 8" }),
1206
+ /* @__PURE__ */ i("line", { x1: "16", y1: "13", x2: "8", y2: "13" }),
1207
+ /* @__PURE__ */ i("line", { x1: "16", y1: "17", x2: "8", y2: "17" })
1208
+ ]
1209
+ }
1210
+ ),
1211
+ /* @__PURE__ */ i("span", { children: o.sources }),
1212
+ /* @__PURE__ */ i("span", { className: nt, children: b }),
1213
+ /* @__PURE__ */ i(
1214
+ "svg",
1215
+ {
1216
+ width: "10",
1217
+ height: "10",
1218
+ viewBox: "0 0 24 24",
1219
+ fill: "none",
1220
+ stroke: "currentColor",
1221
+ strokeWidth: "2",
1222
+ strokeLinecap: "round",
1223
+ strokeLinejoin: "round",
1224
+ "aria-hidden": "true",
1225
+ className: c ? "rotate-180" : void 0,
1226
+ children: /* @__PURE__ */ i("polyline", { points: "6 9 12 15 18 9" })
1227
+ }
1228
+ )
1229
+ ]
1230
+ }
1231
+ ),
1232
+ c && /* @__PURE__ */ g(Te, { children: [
1233
+ /* @__PURE__ */ i(
1234
+ "ol",
1235
+ {
1236
+ id: a,
1237
+ "aria-label": o.sources,
1238
+ className: "mt-1 space-y-1.5",
1239
+ children: x.map((y, w) => /* @__PURE__ */ i(
1240
+ nn,
1241
+ {
1242
+ ref: (D) => {
1243
+ D ? d.current.set(w, D) : d.current.delete(w);
1244
+ },
1245
+ source: y,
1246
+ number: w + 1,
1247
+ favicons: r,
1248
+ labels: o,
1249
+ highlighted: (m == null ? void 0 : m.index) === w
1250
+ },
1251
+ `${w}-${y.url}`
1252
+ ))
1253
+ }
1254
+ ),
1255
+ b > n && /* @__PURE__ */ i(
1256
+ "button",
1257
+ {
1258
+ type: "button",
1259
+ onClick: () => f((y) => !y),
1260
+ "aria-expanded": u,
1261
+ className: "mt-1 font-medium text-claudius-link underline hover:opacity-80 focus:outline-none focus-visible:ring-2 focus-visible:ring-claudius-accent",
1262
+ children: u ? o.showFewerSources : ge(o.showAllSources, { count: b })
1263
+ }
1264
+ )
1265
+ ] })
1266
+ ] });
1267
+ });
1268
+ function on() {
1269
+ return /* @__PURE__ */ g(
979
1270
  "svg",
980
1271
  {
981
1272
  width: "14",
@@ -994,7 +1285,7 @@ function zt() {
994
1285
  }
995
1286
  );
996
1287
  }
997
- function $e({
1288
+ function Ue({
998
1289
  label: e,
999
1290
  onClick: t
1000
1291
  }) {
@@ -1005,7 +1296,7 @@ function $e({
1005
1296
  onClick: t,
1006
1297
  "aria-label": e,
1007
1298
  className: "absolute -right-1.5 -top-1.5 flex h-5 w-5 items-center justify-center rounded-claudius-full bg-claudius-text text-claudius-surface shadow-claudius-floating hover:opacity-90 focus:outline-none focus-visible:ring-2 focus-visible:ring-claudius-accent",
1008
- children: /* @__PURE__ */ w(
1299
+ children: /* @__PURE__ */ g(
1009
1300
  "svg",
1010
1301
  {
1011
1302
  width: "10",
@@ -1025,15 +1316,15 @@ function $e({
1025
1316
  }
1026
1317
  );
1027
1318
  }
1028
- const tt = ke(function({
1319
+ const rt = Ae(function({
1029
1320
  attachment: t,
1030
1321
  variant: n,
1031
1322
  onRemove: r,
1032
1323
  removeLabel: o
1033
1324
  }) {
1034
- const s = Et(t), a = n === "composer", c = `${t.name} (${Se(t.size)})`, l = t.url ? Ce(t.url) : null;
1325
+ const s = Et(t), a = n === "composer", c = `${t.name} (${Me(t.size)})`, l = t.url ? ke(t.url) : null;
1035
1326
  if (s) {
1036
- const d = /* @__PURE__ */ i(
1327
+ const f = /* @__PURE__ */ i(
1037
1328
  "img",
1038
1329
  {
1039
1330
  src: s,
@@ -1043,31 +1334,31 @@ const tt = ke(function({
1043
1334
  className: a ? "h-12 w-12 rounded-claudius-sm border border-claudius-border object-cover" : "max-h-48 max-w-full rounded-claudius-sm object-contain"
1044
1335
  }
1045
1336
  );
1046
- return /* @__PURE__ */ w("div", { className: "relative inline-block", children: [
1047
- !a && l ? /* @__PURE__ */ w("a", { href: l, target: "_blank", rel: "noopener noreferrer", children: [
1048
- d,
1049
- /* @__PURE__ */ w("span", { className: "sr-only", children: [
1337
+ return /* @__PURE__ */ g("div", { className: "relative inline-block", children: [
1338
+ !a && l ? /* @__PURE__ */ g("a", { href: l, target: "_blank", rel: "noopener noreferrer", children: [
1339
+ f,
1340
+ /* @__PURE__ */ g("span", { className: "sr-only", children: [
1050
1341
  c,
1051
1342
  " (opens in a new tab)"
1052
1343
  ] })
1053
- ] }) : d,
1054
- r && o && /* @__PURE__ */ i($e, { label: o, onClick: r })
1344
+ ] }) : f,
1345
+ r && o && /* @__PURE__ */ i(Ue, { label: o, onClick: r })
1055
1346
  ] });
1056
1347
  }
1057
- const u = /* @__PURE__ */ w(
1348
+ const u = /* @__PURE__ */ g(
1058
1349
  "span",
1059
1350
  {
1060
1351
  title: c,
1061
1352
  className: `inline-flex max-w-[220px] items-center gap-1.5 rounded-claudius-sm border px-2 py-1 text-xs ${a ? "border-claudius-border bg-claudius-field text-claudius-text" : "border-current/30 bg-transparent"}`,
1062
1353
  children: [
1063
- /* @__PURE__ */ i(zt, {}),
1354
+ /* @__PURE__ */ i(on, {}),
1064
1355
  /* @__PURE__ */ i("span", { className: "truncate", children: t.name }),
1065
- /* @__PURE__ */ i("span", { className: "shrink-0 opacity-70", children: Se(t.size) })
1356
+ /* @__PURE__ */ i("span", { className: "shrink-0 opacity-70", children: Me(t.size) })
1066
1357
  ]
1067
1358
  }
1068
1359
  );
1069
- return /* @__PURE__ */ w("div", { className: "relative inline-block", children: [
1070
- !a && l ? /* @__PURE__ */ w(
1360
+ return /* @__PURE__ */ g("div", { className: "relative inline-block", children: [
1361
+ !a && l ? /* @__PURE__ */ g(
1071
1362
  "a",
1072
1363
  {
1073
1364
  href: l,
@@ -1080,9 +1371,9 @@ const tt = ke(function({
1080
1371
  ]
1081
1372
  }
1082
1373
  ) : u,
1083
- r && o && /* @__PURE__ */ i($e, { label: o, onClick: r })
1374
+ r && o && /* @__PURE__ */ i(Ue, { label: o, onClick: r })
1084
1375
  ] });
1085
- }), Pe = Je(function({ label: t, onClick: n, children: r }, o) {
1376
+ }), Be = Oe(function({ label: t, onClick: n, children: r }, o) {
1086
1377
  return /* @__PURE__ */ i(
1087
1378
  "button",
1088
1379
  {
@@ -1110,7 +1401,7 @@ const tt = ke(function({
1110
1401
  }
1111
1402
  );
1112
1403
  });
1113
- function Ht({
1404
+ function sn({
1114
1405
  state: e,
1115
1406
  labels: t,
1116
1407
  onPlay: n,
@@ -1118,38 +1409,38 @@ function Ht({
1118
1409
  onResume: o,
1119
1410
  onStop: s
1120
1411
  }) {
1121
- var d;
1122
- const a = S(null), c = S(null), l = !!((d = a.current) != null && d.contains(document.activeElement));
1123
- W(() => {
1124
- var x, A;
1125
- e === "idle" && l && !((x = a.current) != null && x.contains(document.activeElement)) && ((A = c.current) == null || A.focus());
1412
+ var f;
1413
+ const a = C(null), c = C(null), l = !!((f = a.current) != null && f.contains(document.activeElement));
1414
+ H(() => {
1415
+ var T, A;
1416
+ e === "idle" && l && !((T = a.current) != null && T.contains(document.activeElement)) && ((A = c.current) == null || A.focus());
1126
1417
  }, [e, l]);
1127
1418
  const u = e === "idle" ? { label: t.play, onClick: n } : e === "paused" ? { label: t.resume, onClick: o } : { label: t.pause, onClick: r };
1128
- return /* @__PURE__ */ w("div", { ref: a, className: "flex items-center gap-1", children: [
1129
- /* @__PURE__ */ i(Pe, { ref: c, ...u, children: e === "idle" ? /* @__PURE__ */ w(ve, { children: [
1419
+ return /* @__PURE__ */ g("div", { ref: a, className: "flex items-center gap-1", children: [
1420
+ /* @__PURE__ */ i(Be, { ref: c, ...u, children: e === "idle" ? /* @__PURE__ */ g(Te, { children: [
1130
1421
  /* @__PURE__ */ i("polygon", { points: "11 5 6 9 2 9 2 15 6 15 11 19 11 5" }),
1131
1422
  /* @__PURE__ */ i("path", { d: "M15.54 8.46a5 5 0 0 1 0 7.07", fill: "none" }),
1132
1423
  /* @__PURE__ */ i("path", { d: "M19.07 4.93a10 10 0 0 1 0 14.14", fill: "none" })
1133
- ] }) : e === "paused" ? /* @__PURE__ */ i("polygon", { points: "6 3 20 12 6 21 6 3" }) : /* @__PURE__ */ w(ve, { children: [
1424
+ ] }) : e === "paused" ? /* @__PURE__ */ i("polygon", { points: "6 3 20 12 6 21 6 3" }) : /* @__PURE__ */ g(Te, { children: [
1134
1425
  /* @__PURE__ */ i("rect", { x: "6", y: "4", width: "4", height: "16", rx: "1" }),
1135
1426
  /* @__PURE__ */ i("rect", { x: "14", y: "4", width: "4", height: "16", rx: "1" })
1136
1427
  ] }) }),
1137
- e !== "idle" && /* @__PURE__ */ i(Pe, { label: t.stop, onClick: s, children: /* @__PURE__ */ i("rect", { x: "6", y: "6", width: "12", height: "12", rx: "1.5" }) })
1428
+ e !== "idle" && /* @__PURE__ */ i(Be, { label: t.stop, onClick: s, children: /* @__PURE__ */ i("rect", { x: "6", y: "6", width: "12", height: "12", rx: "1.5" }) })
1138
1429
  ] });
1139
1430
  }
1140
- function Ft(e) {
1431
+ function an(e) {
1141
1432
  const t = e.lastIndexOf(`
1142
1433
  `), n = t === -1 ? "" : e.slice(0, t + 1);
1143
1434
  let r = t === -1 ? e : e.slice(t + 1);
1144
- return r = Kt(r), r = Vt(r), n + r;
1435
+ return r = un(r), r = dn(r), n + r;
1145
1436
  }
1146
- function Wt(e) {
1437
+ function cn(e) {
1147
1438
  const t = [];
1148
1439
  for (let n = 0; n < e.length - 1; n++)
1149
1440
  e[n] === "*" && e[n + 1] === "*" && (t.push(n), n++);
1150
1441
  return t;
1151
1442
  }
1152
- function Gt(e) {
1443
+ function ln(e) {
1153
1444
  const t = [];
1154
1445
  for (let n = 0; n < e.length; n++)
1155
1446
  if (e[n] === "*") {
@@ -1161,26 +1452,26 @@ function Gt(e) {
1161
1452
  }
1162
1453
  return t;
1163
1454
  }
1164
- function Kt(e) {
1165
- const t = Wt(e);
1455
+ function un(e) {
1456
+ const t = cn(e);
1166
1457
  if (t.length % 2 === 0) return e;
1167
1458
  const n = t[t.length - 1], r = e.slice(n + 2);
1168
1459
  return r.trim() === "" ? e.slice(0, n) + r : e + "**";
1169
1460
  }
1170
- function Vt(e) {
1171
- const t = Gt(e);
1461
+ function dn(e) {
1462
+ const t = ln(e);
1172
1463
  if (t.length % 2 === 0) return e;
1173
1464
  const n = t[t.length - 1], r = e.slice(n + 1);
1174
1465
  return r.trim() === "" ? e.slice(0, n) + r : e + "*";
1175
1466
  }
1176
- function Yt({
1467
+ function fn({
1177
1468
  toolUse: e,
1178
1469
  usedLabel: t,
1179
1470
  detailsLabel: n
1180
1471
  }) {
1181
- const [r, o] = N(!1), s = e.input !== void 0 || e.result !== void 0;
1182
- return /* @__PURE__ */ w("div", { className: "text-xs text-claudius-text-muted", children: [
1183
- /* @__PURE__ */ w(
1472
+ const [r, o] = M(!1), s = e.input !== void 0 || e.result !== void 0;
1473
+ return /* @__PURE__ */ g("div", { className: "text-xs text-claudius-text-muted", children: [
1474
+ /* @__PURE__ */ g(
1184
1475
  "button",
1185
1476
  {
1186
1477
  type: "button",
@@ -1204,13 +1495,13 @@ function Yt({
1204
1495
  children: /* @__PURE__ */ i("path", { d: "M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z" })
1205
1496
  }
1206
1497
  ),
1207
- /* @__PURE__ */ w("span", { children: [
1498
+ /* @__PURE__ */ g("span", { children: [
1208
1499
  t,
1209
1500
  " ",
1210
1501
  /* @__PURE__ */ i("span", { className: "font-mono text-claudius-text", children: e.name }),
1211
1502
  e.isError && /* @__PURE__ */ i("span", { className: "text-claudius-error", children: " ✕" })
1212
1503
  ] }),
1213
- s && /* @__PURE__ */ w(ve, { children: [
1504
+ s && /* @__PURE__ */ g(Te, { children: [
1214
1505
  /* @__PURE__ */ i("span", { className: "sr-only", children: n }),
1215
1506
  /* @__PURE__ */ i(
1216
1507
  "svg",
@@ -1232,62 +1523,93 @@ function Yt({
1232
1523
  ]
1233
1524
  }
1234
1525
  ),
1235
- r && s && /* @__PURE__ */ w("div", { className: "mt-1 overflow-x-auto rounded-claudius-sm border border-claudius-border bg-claudius-field p-2 font-mono", children: [
1526
+ r && s && /* @__PURE__ */ g("div", { className: "mt-1 overflow-x-auto rounded-claudius-sm border border-claudius-border bg-claudius-field p-2 font-mono", children: [
1236
1527
  e.input !== void 0 && /* @__PURE__ */ i("pre", { className: "whitespace-pre-wrap break-all", children: JSON.stringify(e.input, null, 2) }),
1237
1528
  e.result !== void 0 && /* @__PURE__ */ i("pre", { className: "mt-1 whitespace-pre-wrap break-all border-t border-claudius-border pt-1", children: e.result })
1238
1529
  ] })
1239
1530
  ] });
1240
1531
  }
1241
- const Ue = /(https?:\/\/[^\s)]+)/, Be = /(\*\*[^*]+\*\*)/, _e = /(\*[^*]+\*)/;
1242
- function qt(e, t) {
1243
- const n = e.match(/[.,;:!?'"]+$/), r = n ? e.slice(0, -n[0].length) : e, o = n ? n[0] : "", s = Ce(r);
1244
- return s ? /* @__PURE__ */ w(ve, { children: [
1245
- /* @__PURE__ */ w(
1532
+ const Fe = /(https?:\/\/[^\s)]+)/, _e = /(\*\*[^*]+\*\*)/, He = /(\*[^*]+\*)/, hn = /(?:\[[1-9]\d{0,2}(?:\s*,\s*[1-9]\d{0,2})*\])+$/;
1533
+ function pn(e, t, n) {
1534
+ const r = e.match(/[.,;:!?'"]+$/), o = r ? e.slice(0, -r[0].length) : e, s = r ? r[0] : "", a = n.citations ? o.match(hn) : null, c = a ? o.slice(0, -a[0].length) : o, l = ke(c);
1535
+ return l ? /* @__PURE__ */ g(gt, { children: [
1536
+ /* @__PURE__ */ g(
1246
1537
  "a",
1247
1538
  {
1248
- href: s,
1539
+ href: l,
1249
1540
  target: "_blank",
1250
1541
  rel: "noopener noreferrer",
1251
1542
  className: "underline font-medium hover:opacity-80 text-claudius-link",
1252
1543
  children: [
1253
- s.replace(/^https?:\/\//, ""),
1254
- /* @__PURE__ */ i("span", { className: "sr-only", children: " (opens in a new tab)" })
1544
+ l.replace(/^https?:\/\//, ""),
1545
+ /* @__PURE__ */ g("span", { className: "sr-only", children: [
1546
+ " ",
1547
+ n.newTabLabel
1548
+ ] })
1255
1549
  ]
1256
- },
1257
- t
1550
+ }
1258
1551
  ),
1259
- o
1260
- ] }) : e;
1261
- }
1262
- function Zt(e, t) {
1263
- const n = e.split(Be), r = [];
1264
- return n.forEach((o, s) => {
1265
- if (Be.test(o)) {
1266
- const a = o.slice(2, -2);
1267
- r.push(/* @__PURE__ */ i("strong", { children: a }, `${t}-b${s}`));
1268
- } else
1269
- o.split(_e).forEach((c, l) => {
1270
- if (_e.test(c)) {
1271
- const u = c.slice(1, -1);
1272
- r.push(/* @__PURE__ */ i("em", { children: u }, `${t}-b${s}-i${l}`));
1273
- } else
1274
- c.split(Ue).forEach((d, x) => {
1275
- Ue.test(d) ? r.push(
1276
- qt(d, `${t}-b${s}-i${l}-u${x}`)
1277
- ) : d && r.push(d);
1278
- });
1279
- });
1552
+ a && ot(a[0], `${t}-m`, n),
1553
+ s
1554
+ ] }, t) : e;
1555
+ }
1556
+ function ot(e, t, n) {
1557
+ const r = n.citations;
1558
+ return r ? tt(e, r.sources.length).map((o, s) => o.type === "text" ? o.value : /* @__PURE__ */ i(
1559
+ "span",
1560
+ {
1561
+ className: "inline-flex gap-0.5 align-super",
1562
+ children: o.indexes.map((a) => /* @__PURE__ */ i(
1563
+ "button",
1564
+ {
1565
+ type: "button",
1566
+ onClick: () => r.onCite(a),
1567
+ "aria-label": ge(r.label, {
1568
+ n: a + 1,
1569
+ title: r.sources[a].title
1570
+ }),
1571
+ title: r.sources[a].title,
1572
+ className: "inline-flex h-4 min-w-4 items-center justify-center rounded-claudius-full bg-claudius-accent px-1 text-[10px] font-semibold leading-none text-claudius-accent-text hover:opacity-80 focus:outline-none focus-visible:ring-2 focus-visible:ring-claudius-accent focus-visible:ring-offset-1",
1573
+ children: a + 1
1574
+ },
1575
+ a
1576
+ ))
1577
+ },
1578
+ `${t}-c${s}`
1579
+ )) : e ? [e] : [];
1580
+ }
1581
+ function Le(e, t, n) {
1582
+ const r = [];
1583
+ return e.split(Fe).forEach((o, s) => {
1584
+ Fe.test(o) ? r.push(pn(o, `${t}-u${s}`, n)) : o && r.push(...ot(o, `${t}-u${s}`, n));
1585
+ }), r;
1586
+ }
1587
+ function mn(e, t, n) {
1588
+ const r = [];
1589
+ return e.split(_e).forEach((o, s) => {
1590
+ if (_e.test(o)) {
1591
+ r.push(
1592
+ /* @__PURE__ */ i("strong", { children: Le(o.slice(2, -2), `${t}-b${s}`, n) }, `${t}-b${s}`)
1593
+ );
1594
+ return;
1595
+ }
1596
+ o.split(He).forEach((a, c) => {
1597
+ const l = `${t}-b${s}-i${c}`;
1598
+ He.test(a) ? r.push(
1599
+ /* @__PURE__ */ i("em", { children: Le(a.slice(1, -1), l, n) }, l)
1600
+ ) : r.push(...Le(a, l, n));
1601
+ });
1280
1602
  }), r;
1281
1603
  }
1282
- function Jt(e) {
1283
- const t = e.split(`
1604
+ function gn(e, t) {
1605
+ const n = e.split(`
1284
1606
  `);
1285
- return t.map((n, r) => /* @__PURE__ */ w("span", { children: [
1286
- Zt(n, `l${r}`),
1287
- r < t.length - 1 && /* @__PURE__ */ i("br", {})
1288
- ] }, r));
1607
+ return n.map((r, o) => /* @__PURE__ */ g("span", { children: [
1608
+ mn(r, `l${o}`, t),
1609
+ o < n.length - 1 && /* @__PURE__ */ i("br", {})
1610
+ ] }, o));
1289
1611
  }
1290
- const Qt = ke(function({
1612
+ const bn = Ae(function({
1291
1613
  role: t,
1292
1614
  content: n,
1293
1615
  isStreaming: r = !1,
@@ -1297,48 +1619,68 @@ const Qt = ke(function({
1297
1619
  toolUsedLabel: c = "Used tool:",
1298
1620
  toolDetailsLabel: l = "Tool details",
1299
1621
  onSourceClick: u,
1300
- isSourceActive: d,
1301
- speech: x
1622
+ isSourceActive: f,
1623
+ speech: T,
1624
+ citations: A,
1625
+ linkNewTabLabel: m = "(opens in a new tab)"
1302
1626
  }) {
1303
- const A = t === "user", g = !!s && s.length > 0, f = r ? Ft(n) : n, p = A || n !== "" || !(a != null && a.length);
1304
- return /* @__PURE__ */ w("div", { className: `${A ? "ml-auto" : "mr-auto"} max-w-[85%]`, children: [
1305
- p && /* @__PURE__ */ w(
1627
+ const h = t === "user", [d, k] = M(null), b = C(0), x = !h && A && o && o.length > 0 ? { config: A, sources: o } : null, y = !!s && s.length > 0, w = r && x ? qt(n) : n, D = r ? an(w) : w, S = {
1628
+ newTabLabel: m,
1629
+ citations: x ? {
1630
+ sources: x.sources,
1631
+ label: x.config.labels.citation,
1632
+ onCite: (I) => {
1633
+ b.current += 1, k({ index: I, key: b.current });
1634
+ }
1635
+ } : void 0
1636
+ }, N = h || n !== "" || !(a != null && a.length);
1637
+ return /* @__PURE__ */ g("div", { className: `${h ? "ml-auto" : "mr-auto"} max-w-[85%]`, children: [
1638
+ N && /* @__PURE__ */ g(
1306
1639
  "div",
1307
1640
  {
1308
- className: `rounded-claudius-bubble px-4 py-2.5 text-sm leading-relaxed font-body ${A ? "bg-claudius-user-bubble text-claudius-user-bubble-text rounded-br-claudius-tail" : "bg-claudius-assistant-bubble text-claudius-assistant-bubble-text rounded-bl-claudius-tail"}`,
1641
+ className: `rounded-claudius-bubble px-4 py-2.5 text-sm leading-relaxed font-body ${h ? "bg-claudius-user-bubble text-claudius-user-bubble-text rounded-br-claudius-tail" : "bg-claudius-assistant-bubble text-claudius-assistant-bubble-text rounded-bl-claudius-tail"}`,
1309
1642
  children: [
1310
- g && /* @__PURE__ */ i(
1643
+ y && /* @__PURE__ */ i(
1311
1644
  "ul",
1312
1645
  {
1313
1646
  className: `flex flex-wrap gap-2 ${n ? "mb-2" : ""}`,
1314
1647
  "aria-label": "Attachments",
1315
- children: s.map((T) => /* @__PURE__ */ i("li", { children: /* @__PURE__ */ i(tt, { attachment: T, variant: "message" }) }, T.id))
1648
+ children: s.map((I) => /* @__PURE__ */ i("li", { children: /* @__PURE__ */ i(rt, { attachment: I, variant: "message" }) }, I.id))
1316
1649
  }
1317
1650
  ),
1318
- (n !== "" || !g) && Jt(f)
1651
+ (n !== "" || !y) && gn(D, S)
1319
1652
  ]
1320
1653
  }
1321
1654
  ),
1322
- !A && a && a.length > 0 && /* @__PURE__ */ i("div", { className: "mt-1 space-y-1", children: a.map((T, b) => /* @__PURE__ */ i(
1323
- Yt,
1655
+ !h && a && a.length > 0 && /* @__PURE__ */ i("div", { className: "mt-1 space-y-1", children: a.map((I, R) => /* @__PURE__ */ i(
1656
+ fn,
1324
1657
  {
1325
- toolUse: T,
1658
+ toolUse: I,
1326
1659
  usedLabel: c,
1327
1660
  detailsLabel: l
1328
1661
  },
1329
- `${T.name}-${b}`
1662
+ `${I.name}-${R}`
1330
1663
  )) }),
1331
- !A && o && o.length > 0 && u && /* @__PURE__ */ i("div", { className: "mt-1", children: /* @__PURE__ */ i(
1332
- Bt,
1664
+ x ? /* @__PURE__ */ i(
1665
+ rn,
1666
+ {
1667
+ sources: x.sources,
1668
+ maxSources: x.config.maxSources,
1669
+ favicons: x.config.favicons,
1670
+ labels: x.config.labels,
1671
+ reveal: d
1672
+ }
1673
+ ) : !h && o && o.length > 0 && u && /* @__PURE__ */ i("div", { className: "mt-1", children: /* @__PURE__ */ i(
1674
+ zt,
1333
1675
  {
1334
1676
  count: o.length,
1335
- isActive: d ?? !1,
1677
+ isActive: f ?? !1,
1336
1678
  onClick: u
1337
1679
  }
1338
1680
  ) }),
1339
- !A && x && /* @__PURE__ */ i("div", { className: "mt-1", children: /* @__PURE__ */ i(Ht, { ...x }) })
1681
+ !h && T && /* @__PURE__ */ i("div", { className: "mt-1", children: /* @__PURE__ */ i(sn, { ...T }) })
1340
1682
  ] });
1341
- }), nt = {
1683
+ }), st = {
1342
1684
  // ChatWindow
1343
1685
  title: "Chat",
1344
1686
  subtitle: "Ask me anything",
@@ -1390,6 +1732,12 @@ const Qt = ke(function({
1390
1732
  transcriptAssistant: "Assistant",
1391
1733
  transcriptAttachments: "Attachments:",
1392
1734
  transcriptSources: "Sources:",
1735
+ // Citations
1736
+ sources: "Sources",
1737
+ showAllSources: "Show all ({count})",
1738
+ showFewerSources: "Show fewer",
1739
+ citation: "Source {n}: {title}",
1740
+ opensInNewTab: "(opens in a new tab)",
1393
1741
  // Errors
1394
1742
  errorGeneric: "Something went wrong. Please try again.",
1395
1743
  errorConnection: "Failed to connect. Please try again.",
@@ -1399,14 +1747,14 @@ const Qt = ke(function({
1399
1747
  errorAttachmentRejected: "An attachment was rejected. Please remove it and try again.",
1400
1748
  errorAttachmentQuota: "Upload limit reached. Please try again later.",
1401
1749
  errorRetry: "Retry"
1402
- }, Oe = nt;
1403
- function xr(e) {
1404
- return { ...Oe, ...e };
1750
+ }, je = st;
1751
+ function Ur(e) {
1752
+ return { ...je, ...e };
1405
1753
  }
1406
1754
  function ze(e) {
1407
1755
  return e.key === " " || e.key === "Enter";
1408
1756
  }
1409
- function Xt({
1757
+ function yn({
1410
1758
  mode: e,
1411
1759
  isListening: t,
1412
1760
  disabled: n = !1,
@@ -1414,7 +1762,7 @@ function Xt({
1414
1762
  onStop: o,
1415
1763
  label: s
1416
1764
  }) {
1417
- const a = e === "hold", c = S(!1), l = () => {
1765
+ const a = e === "hold", c = C(!1), l = () => {
1418
1766
  n || c.current || (c.current = !0, r({ held: !0 }));
1419
1767
  }, u = () => {
1420
1768
  c.current && (c.current = !1, o());
@@ -1427,24 +1775,24 @@ function Xt({
1427
1775
  "aria-label": s,
1428
1776
  "aria-pressed": t,
1429
1777
  title: s,
1430
- onClick: (f) => {
1431
- a && f.detail !== 0 || (t ? o() : r({ held: !1 }));
1778
+ onClick: (h) => {
1779
+ a && h.detail !== 0 || (t ? o() : r({ held: !1 }));
1432
1780
  },
1433
- onPointerDown: (f) => {
1434
- var p, T;
1435
- !a || f.button !== 0 || ((T = (p = f.currentTarget).setPointerCapture) == null || T.call(p, f.pointerId), l());
1781
+ onPointerDown: (h) => {
1782
+ var d, k;
1783
+ !a || h.button !== 0 || ((k = (d = h.currentTarget).setPointerCapture) == null || k.call(d, h.pointerId), l());
1436
1784
  },
1437
1785
  onPointerUp: u,
1438
1786
  onPointerCancel: u,
1439
1787
  onLostPointerCapture: u,
1440
- onKeyDown: (f) => {
1441
- !a || !ze(f) || (f.preventDefault(), f.repeat || l());
1788
+ onKeyDown: (h) => {
1789
+ !a || !ze(h) || (h.preventDefault(), h.repeat || l());
1442
1790
  },
1443
- onKeyUp: (f) => {
1444
- !a || !ze(f) || (f.preventDefault(), u());
1791
+ onKeyUp: (h) => {
1792
+ !a || !ze(h) || (h.preventDefault(), u());
1445
1793
  },
1446
1794
  onBlur: u,
1447
- onContextMenu: a ? (f) => f.preventDefault() : void 0,
1795
+ onContextMenu: a ? (h) => h.preventDefault() : void 0,
1448
1796
  style: a ? { WebkitTouchCallout: "none" } : void 0,
1449
1797
  className: `flex h-11 w-11 shrink-0 items-center justify-center rounded-claudius-sm border transition-colors focus:outline-none focus:ring-1 focus:ring-claudius-accent disabled:opacity-50 ${t ? (
1450
1798
  // An accent ring on an accent fill is invisible; offset it so
@@ -1466,7 +1814,7 @@ function Xt({
1466
1814
  children: /* @__PURE__ */ i("rect", { x: "6", y: "6", width: "12", height: "12", rx: "1.5" })
1467
1815
  }
1468
1816
  )
1469
- ) : /* @__PURE__ */ w(
1817
+ ) : /* @__PURE__ */ g(
1470
1818
  "svg",
1471
1819
  {
1472
1820
  width: "16",
@@ -1488,8 +1836,8 @@ function Xt({
1488
1836
  }
1489
1837
  );
1490
1838
  }
1491
- function en({ active: e }) {
1492
- return /* @__PURE__ */ w(
1839
+ function wn({ active: e }) {
1840
+ return /* @__PURE__ */ g(
1493
1841
  "span",
1494
1842
  {
1495
1843
  "aria-hidden": "true",
@@ -1504,50 +1852,44 @@ function en({ active: e }) {
1504
1852
  }
1505
1853
  );
1506
1854
  }
1507
- function Re(e, t) {
1508
- return e.replace(
1509
- /\{(\w+)\}/g,
1510
- (n, r) => r in t ? String(t[r]) : n
1511
- );
1512
- }
1513
- const tn = {
1855
+ const xn = {
1514
1856
  en: "en-US",
1515
1857
  es: "es-ES",
1516
1858
  fr: "fr-FR",
1517
1859
  de: "de-DE"
1518
- }, nn = ["toggle", "hold"];
1519
- function He(e, t) {
1860
+ }, vn = ["toggle", "hold"];
1861
+ function We(e, t) {
1520
1862
  if (!(!e || !e.includes("-")))
1521
1863
  return e.toLowerCase().split("-")[0] === t ? e : void 0;
1522
1864
  }
1523
- function rt(e, t) {
1865
+ function at(e, t) {
1524
1866
  const n = t == null ? void 0 : t.trim();
1525
1867
  if (n) return n;
1526
- const r = typeof document < "u" ? He(document.documentElement.lang, e) : void 0;
1868
+ const r = typeof document < "u" ? We(document.documentElement.lang, e) : void 0;
1527
1869
  if (r) return r;
1528
- const o = typeof navigator < "u" ? He(navigator.language, e) : void 0;
1529
- return o || tn[e];
1870
+ const o = typeof navigator < "u" ? We(navigator.language, e) : void 0;
1871
+ return o || xn[e];
1530
1872
  }
1531
- function rn(e, t) {
1873
+ function Sn(e, t) {
1532
1874
  const n = typeof e == "object" && e !== null && !Array.isArray(e);
1533
1875
  if (e !== !0 && !n) return null;
1534
1876
  const r = e === !0 ? {} : e, o = {
1535
1877
  input: r.input ?? !0,
1536
1878
  output: r.output ?? !0,
1537
1879
  // `mode` can arrive from an HTML attribute, so tolerate junk.
1538
- mode: nn.includes(r.mode) ? r.mode : "toggle",
1880
+ mode: vn.includes(r.mode) ? r.mode : "toggle",
1539
1881
  autoSubmit: r.autoSubmit ?? !1,
1540
- lang: rt(t, r.lang)
1882
+ lang: at(t, r.lang)
1541
1883
  };
1542
1884
  return o.input || o.output ? o : null;
1543
1885
  }
1544
- function on(e, t, n) {
1886
+ function Tn(e, t, n) {
1545
1887
  const r = t.trim();
1546
1888
  if (!r) return e;
1547
1889
  const o = e.trimEnd();
1548
1890
  return (o ? `${o} ${r}` : r).slice(0, n);
1549
1891
  }
1550
- function sn(e) {
1892
+ function An(e) {
1551
1893
  const t = [];
1552
1894
  let n = 0;
1553
1895
  for (let r = 0; r < e.length; r++) {
@@ -1557,14 +1899,14 @@ function sn(e) {
1557
1899
  }
1558
1900
  return n < e.length && t.push(e.slice(n)), t;
1559
1901
  }
1560
- function an(e, t = 150) {
1902
+ function kn(e, t = 150) {
1561
1903
  const n = [];
1562
1904
  let r = "";
1563
1905
  const o = () => {
1564
1906
  const s = r.trim();
1565
1907
  s && n.push(s), r = "";
1566
1908
  };
1567
- for (const s of sn(e)) {
1909
+ for (const s of An(e)) {
1568
1910
  if ((r + s).trim().length <= t) {
1569
1911
  r += s;
1570
1912
  continue;
@@ -1581,12 +1923,12 @@ function an(e, t = 150) {
1581
1923
  }
1582
1924
  return o(), n;
1583
1925
  }
1584
- function Fe() {
1926
+ function Ge() {
1585
1927
  if (typeof window > "u") return;
1586
1928
  const e = window;
1587
1929
  return e.SpeechRecognition ?? e.webkitSpeechRecognition;
1588
1930
  }
1589
- function cn(e) {
1931
+ function Rn(e) {
1590
1932
  switch (e) {
1591
1933
  case "not-allowed":
1592
1934
  case "service-not-allowed":
@@ -1599,62 +1941,62 @@ function cn(e) {
1599
1941
  return "unavailable";
1600
1942
  }
1601
1943
  }
1602
- function ln(e) {
1603
- const [t] = N(() => Fe() !== void 0), [n, r] = N(!1), [o, s] = N(!1), a = S(null), c = S(!1), l = S(e);
1604
- W(() => {
1944
+ function En(e) {
1945
+ const [t] = M(() => Ge() !== void 0), [n, r] = M(!1), [o, s] = M(!1), a = C(null), c = C(!1), l = C(e);
1946
+ H(() => {
1605
1947
  l.current = e;
1606
1948
  });
1607
- const u = M((g) => {
1608
- g.onstart = null, g.onend = null, g.onerror = null, g.onresult = null, g.onspeechstart = null, g.onspeechend = null, a.current === g && (a.current = null), r(!1), s(!1);
1609
- }, []), d = M(() => {
1610
- const g = a.current;
1611
- g && (u(g), g.abort());
1612
- }, [u]), x = M(() => {
1613
- const g = a.current;
1614
- return g ? (c.current ? g.stop() : d(), !0) : !1;
1615
- }, [d]), A = M(() => {
1616
- var b, R;
1617
- const g = Fe();
1618
- if (!g || a.current) return !1;
1619
- const f = new g();
1620
- f.lang = l.current.lang, f.interimResults = !0, f.continuous = !1;
1621
- let p = "";
1622
- const T = () => {
1949
+ const u = O((m) => {
1950
+ m.onstart = null, m.onend = null, m.onerror = null, m.onresult = null, m.onspeechstart = null, m.onspeechend = null, a.current === m && (a.current = null), r(!1), s(!1);
1951
+ }, []), f = O(() => {
1952
+ const m = a.current;
1953
+ m && (u(m), m.abort());
1954
+ }, [u]), T = O(() => {
1955
+ const m = a.current;
1956
+ return m ? (c.current ? m.stop() : f(), !0) : !1;
1957
+ }, [f]), A = O(() => {
1958
+ var b, x;
1959
+ const m = Ge();
1960
+ if (!m || a.current) return !1;
1961
+ const h = new m();
1962
+ h.lang = l.current.lang, h.interimResults = !0, h.continuous = !1;
1963
+ let d = "";
1964
+ const k = () => {
1623
1965
  c.current = !0;
1624
1966
  };
1625
- f.onstart = T, f.onspeechstart = () => {
1626
- T(), s(!0);
1627
- }, f.onspeechend = () => s(!1), f.onresult = (y) => {
1628
- var $, L;
1629
- let v = "", C = "";
1630
- for (let E = 0; E < y.results.length; E++) {
1631
- const B = y.results[E];
1632
- B.isFinal ? v += B[0].transcript : C += B[0].transcript;
1967
+ h.onstart = k, h.onspeechstart = () => {
1968
+ k(), s(!0);
1969
+ }, h.onspeechend = () => s(!1), h.onresult = (y) => {
1970
+ var S, N;
1971
+ let w = "", D = "";
1972
+ for (let I = 0; I < y.results.length; I++) {
1973
+ const R = y.results[I];
1974
+ R.isFinal ? w += R[0].transcript : D += R[0].transcript;
1633
1975
  }
1634
- p = v, T(), s(!0), (L = ($ = l.current).onTranscript) == null || L.call($, v + C);
1635
- }, f.onerror = (y) => {
1636
- var v, C;
1637
- y.error !== "aborted" && ((C = (v = l.current).onError) == null || C.call(v, cn(y.error))), u(f), f.abort();
1638
- }, f.onend = () => {
1639
- var y, v;
1640
- u(f), (v = (y = l.current).onEnd) == null || v.call(y, p);
1641
- }, a.current = f, c.current = !1, r(!0);
1976
+ d = w, k(), s(!0), (N = (S = l.current).onTranscript) == null || N.call(S, w + D);
1977
+ }, h.onerror = (y) => {
1978
+ var w, D;
1979
+ y.error !== "aborted" && ((D = (w = l.current).onError) == null || D.call(w, Rn(y.error))), u(h), h.abort();
1980
+ }, h.onend = () => {
1981
+ var y, w;
1982
+ u(h), (w = (y = l.current).onEnd) == null || w.call(y, d);
1983
+ }, a.current = h, c.current = !1, r(!0);
1642
1984
  try {
1643
- f.start();
1985
+ h.start();
1644
1986
  } catch {
1645
- return u(f), (R = (b = l.current).onError) == null || R.call(b, "unavailable"), !1;
1987
+ return u(h), (x = (b = l.current).onError) == null || x.call(b, "unavailable"), !1;
1646
1988
  }
1647
1989
  return !0;
1648
1990
  }, [u]);
1649
- return W(() => d, [d]), { isSupported: t, isListening: n, isSpeechDetected: o, start: A, stop: x, abort: d };
1991
+ return H(() => f, [f]), { isSupported: t, isListening: n, isSpeechDetected: o, start: A, stop: T, abort: f };
1650
1992
  }
1651
- const ye = 2e3, un = 1800;
1652
- function We(e) {
1993
+ const xe = 2e3, Cn = 1800;
1994
+ function Ve(e) {
1653
1995
  var n;
1654
1996
  const t = (n = e.dataTransfer) == null ? void 0 : n.types;
1655
1997
  return !!t && Array.from(t).includes("Files");
1656
1998
  }
1657
- function dn({
1999
+ function Nn({
1658
2000
  onSend: e,
1659
2001
  isLoading: t,
1660
2002
  isStreaming: n = !1,
@@ -1666,129 +2008,129 @@ function dn({
1666
2008
  onVoiceStart: l,
1667
2009
  isReadingAloud: u = !1
1668
2010
  }) {
1669
- const d = s ?? Oe, [x, A] = N(""), [g, f] = N([]), [p, T] = N(null), [b, R] = N(!1), [y, v] = N(null), C = S(null), $ = S(null), L = S([]), E = S(0), B = S(""), O = S(""), _ = S(!1), q = S(!1), G = S(!1), J = (m) => {
1670
- B.current = m, A(m);
1671
- }, z = x.length, ae = z >= un, ie = z >= ye, ce = o ?? d.placeholder, re = !!a && g.length < a.maxCount, h = n && !!r;
1672
- W(() => {
1673
- var m;
1674
- t || (m = C.current) == null || m.focus();
2011
+ const f = s ?? je, [T, A] = M(""), [m, h] = M([]), [d, k] = M(null), [b, x] = M(!1), [y, w] = M(null), D = C(null), S = C(null), N = C([]), I = C(0), R = C(""), ne = C(""), $ = C(!1), z = C(!1), X = C(!1), Z = (p) => {
2012
+ R.current = p, A(p);
2013
+ }, J = T.length, W = J >= Cn, G = J >= xe, ce = o ?? f.placeholder, de = !!a && m.length < a.maxCount, fe = n && !!r;
2014
+ H(() => {
2015
+ var p;
2016
+ t || (p = D.current) == null || p.focus();
1675
2017
  }, [t]);
1676
- const P = M(
1677
- (m, j) => {
2018
+ const E = O(
2019
+ (p, j) => {
1678
2020
  if (!a) return "";
1679
2021
  switch (j) {
1680
2022
  case "size":
1681
- return Re(d.attachmentTooLarge, {
1682
- name: m,
1683
- max: Se(a.maxSizeBytes)
2023
+ return ge(f.attachmentTooLarge, {
2024
+ name: p,
2025
+ max: Me(a.maxSizeBytes)
1684
2026
  });
1685
2027
  case "type":
1686
- return Re(d.attachmentTypeNotAllowed, { name: m });
2028
+ return ge(f.attachmentTypeNotAllowed, { name: p });
1687
2029
  case "count":
1688
- return Re(d.attachmentTooMany, {
2030
+ return ge(f.attachmentTooMany, {
1689
2031
  max: a.maxCount
1690
2032
  });
1691
2033
  }
1692
2034
  },
1693
- [a, d]
1694
- ), U = M(
1695
- async (m) => {
1696
- if (!a || m.length === 0) return;
1697
- const { accepted: j, rejected: fe } = Rt(
1698
- m,
1699
- L.current.length,
2035
+ [a, f]
2036
+ ), B = O(
2037
+ async (p) => {
2038
+ if (!a || p.length === 0) return;
2039
+ const { accepted: j, rejected: ue } = Ct(
2040
+ p,
2041
+ N.current.length,
1700
2042
  a
1701
2043
  );
1702
- if (T(
1703
- fe.length > 0 ? P(fe[0].file.name, fe[0].reason) : null
2044
+ if (k(
2045
+ ue.length > 0 ? E(ue[0].file.name, ue[0].reason) : null
1704
2046
  ), j.length === 0) return;
1705
- const ut = await Promise.all(j.map(kt));
1706
- L.current = [...L.current, ...ut], f(L.current);
2047
+ const ht = await Promise.all(j.map(Lt));
2048
+ N.current = [...N.current, ...ht], h(N.current);
1707
2049
  },
1708
- [a, P]
1709
- ), ee = M((m) => {
1710
- L.current = L.current.filter((j) => j.id !== m), f(L.current), T(null);
1711
- }, []), te = () => {
1712
- const m = B.current.trim(), j = L.current;
1713
- !m && j.length === 0 || B.current.length >= ye || (j.length > 0 ? e(m, j) : e(m), J(""), L.current = [], f([]), T(null), v(null));
1714
- }, ne = (m) => {
1715
- switch (m) {
2050
+ [a, E]
2051
+ ), P = O((p) => {
2052
+ N.current = N.current.filter((j) => j.id !== p), h(N.current), k(null);
2053
+ }, []), v = () => {
2054
+ const p = R.current.trim(), j = N.current;
2055
+ !p && j.length === 0 || R.current.length >= xe || (j.length > 0 ? e(p, j) : e(p), Z(""), N.current = [], h([]), k(null), w(null));
2056
+ }, V = (p) => {
2057
+ switch (p) {
1716
2058
  case "permission":
1717
- return d.voicePermissionDenied;
2059
+ return f.voicePermissionDenied;
1718
2060
  case "no-speech":
1719
- return d.voiceNoSpeech;
2061
+ return f.voiceNoSpeech;
1720
2062
  case "no-microphone":
1721
- return d.voiceNoMicrophone;
2063
+ return f.voiceNoMicrophone;
1722
2064
  case "unavailable":
1723
- return d.voiceUnavailable;
2065
+ return f.voiceUnavailable;
1724
2066
  }
1725
- }, F = ln({
2067
+ }, K = En({
1726
2068
  lang: (c == null ? void 0 : c.lang) ?? "en-US",
1727
- onTranscript: (m) => J(
1728
- on(O.current, m, ye)
2069
+ onTranscript: (p) => Z(
2070
+ Tn(ne.current, p, xe)
1729
2071
  ),
1730
- onEnd: (m) => {
1731
- const j = m.trim() !== "";
1732
- if (j && (q.current = !0), !_.current) {
1733
- D();
2072
+ onEnd: (p) => {
2073
+ const j = p.trim() !== "";
2074
+ if (j && (z.current = !0), !$.current) {
2075
+ ee();
1734
2076
  return;
1735
2077
  }
1736
- j && I();
2078
+ j && te();
1737
2079
  },
1738
- onError: (m) => {
1739
- m === "no-speech" && q.current || (G.current = !0, v(ne(m)));
2080
+ onError: (p) => {
2081
+ p === "no-speech" && z.current || (X.current = !0, w(V(p)));
1740
2082
  }
1741
- }), H = !!(c != null && c.input) && F.isSupported, k = F.isListening;
1742
- W(() => {
1743
- const m = C.current;
1744
- k && m && (m.scrollLeft = m.scrollWidth);
1745
- }, [k, x]);
1746
- const D = () => {
1747
- c != null && c.autoSubmit && q.current && !G.current && te();
1748
- }, I = () => {
1749
- const m = B.current;
1750
- F.start() && (O.current = m);
1751
- }, K = ({ held: m }) => {
1752
- v(null), _.current = m, q.current = !1, G.current = !1, l == null || l(), I();
1753
- }, Q = () => {
1754
- const m = _.current;
1755
- _.current = !1, !F.stop() && m && D();
1756
- }, le = () => {
1757
- _.current = !1, F.abort();
1758
- }, { abort: Y } = F;
1759
- W(() => {
1760
- !t && !u || (_.current = !1, Y());
2083
+ }), oe = !!(c != null && c.input) && K.isSupported, F = K.isListening;
2084
+ H(() => {
2085
+ const p = D.current;
2086
+ F && p && (p.scrollLeft = p.scrollWidth);
2087
+ }, [F, T]);
2088
+ const ee = () => {
2089
+ c != null && c.autoSubmit && z.current && !X.current && v();
2090
+ }, te = () => {
2091
+ const p = R.current;
2092
+ K.start() && (ne.current = p);
2093
+ }, L = ({ held: p }) => {
2094
+ w(null), $.current = p, z.current = !1, X.current = !1, l == null || l(), te();
2095
+ }, _ = () => {
2096
+ const p = $.current;
2097
+ $.current = !1, !K.stop() && p && ee();
2098
+ }, U = () => {
2099
+ $.current = !1, K.abort();
2100
+ }, { abort: Y } = K;
2101
+ H(() => {
2102
+ !t && !u || ($.current = !1, Y());
1761
2103
  }, [t, u, Y]);
1762
- const me = (m) => {
1763
- m.preventDefault(), le(), te();
1764
- }, ue = (m) => {
1765
- const j = m.target.value;
1766
- j.length <= ye && (le(), v(null), J(j));
1767
- }, V = (m) => {
1768
- const j = Array.from(m.target.files ?? []);
1769
- m.target.value = "", U(j);
1770
- }, oe = (m) => {
1771
- var fe;
2104
+ const se = (p) => {
2105
+ p.preventDefault(), U(), v();
2106
+ }, le = (p) => {
2107
+ const j = p.target.value;
2108
+ j.length <= xe && (U(), w(null), Z(j));
2109
+ }, re = (p) => {
2110
+ const j = Array.from(p.target.files ?? []);
2111
+ p.target.value = "", B(j);
2112
+ }, ye = (p) => {
2113
+ var ue;
1772
2114
  if (!a) return;
1773
- const j = Array.from(((fe = m.clipboardData) == null ? void 0 : fe.files) ?? []);
1774
- j.length !== 0 && (m.preventDefault(), U(j));
2115
+ const j = Array.from(((ue = p.clipboardData) == null ? void 0 : ue.files) ?? []);
2116
+ j.length !== 0 && (p.preventDefault(), B(j));
1775
2117
  };
1776
- return /* @__PURE__ */ w(
2118
+ return /* @__PURE__ */ g(
1777
2119
  "form",
1778
2120
  {
1779
- onSubmit: me,
1780
- onDragEnter: (m) => {
1781
- !a || !We(m) || (m.preventDefault(), E.current += 1, R(!0));
2121
+ onSubmit: se,
2122
+ onDragEnter: (p) => {
2123
+ !a || !Ve(p) || (p.preventDefault(), I.current += 1, x(!0));
1782
2124
  },
1783
- onDragOver: (m) => {
1784
- !a || !We(m) || m.preventDefault();
2125
+ onDragOver: (p) => {
2126
+ !a || !Ve(p) || p.preventDefault();
1785
2127
  },
1786
2128
  onDragLeave: () => {
1787
- a && (E.current = Math.max(0, E.current - 1), E.current === 0 && R(!1));
2129
+ a && (I.current = Math.max(0, I.current - 1), I.current === 0 && x(!1));
1788
2130
  },
1789
- onDrop: (m) => {
2131
+ onDrop: (p) => {
1790
2132
  var j;
1791
- a && (m.preventDefault(), E.current = 0, R(!1), U(Array.from(((j = m.dataTransfer) == null ? void 0 : j.files) ?? [])));
2133
+ a && (p.preventDefault(), I.current = 0, x(!1), B(Array.from(((j = p.dataTransfer) == null ? void 0 : j.files) ?? [])));
1792
2134
  },
1793
2135
  "data-drag-over": b || void 0,
1794
2136
  className: `relative border-t border-claudius-border bg-claudius-surface p-3 ${b ? "ring-2 ring-inset ring-claudius-accent" : ""}`,
@@ -1798,38 +2140,38 @@ function dn({
1798
2140
  {
1799
2141
  "aria-hidden": "true",
1800
2142
  className: "pointer-events-none absolute inset-0 z-10 flex items-center justify-center bg-claudius-surface text-sm font-medium text-claudius-accent",
1801
- children: d.dropFilesHint
2143
+ children: f.dropFilesHint
1802
2144
  }
1803
2145
  ),
1804
- a && g.length > 0 && /* @__PURE__ */ i(
2146
+ a && m.length > 0 && /* @__PURE__ */ i(
1805
2147
  "ul",
1806
2148
  {
1807
- "aria-label": d.attachmentsLabel,
2149
+ "aria-label": f.attachmentsLabel,
1808
2150
  className: "mb-2 flex flex-wrap gap-3 pt-1",
1809
- children: g.map((m) => /* @__PURE__ */ i("li", { children: /* @__PURE__ */ i(
1810
- tt,
2151
+ children: m.map((p) => /* @__PURE__ */ i("li", { children: /* @__PURE__ */ i(
2152
+ rt,
1811
2153
  {
1812
- attachment: m,
2154
+ attachment: p,
1813
2155
  variant: "composer",
1814
- onRemove: () => ee(m.id),
1815
- removeLabel: `${d.removeAttachment}: ${m.name}`
2156
+ onRemove: () => P(p.id),
2157
+ removeLabel: `${f.removeAttachment}: ${p.name}`
1816
2158
  }
1817
- ) }, m.id))
2159
+ ) }, p.id))
1818
2160
  }
1819
2161
  ),
1820
- /* @__PURE__ */ w("div", { className: "flex gap-2", children: [
1821
- a && /* @__PURE__ */ w(ve, { children: [
2162
+ /* @__PURE__ */ g("div", { className: "flex gap-2", children: [
2163
+ a && /* @__PURE__ */ g(Te, { children: [
1822
2164
  /* @__PURE__ */ i(
1823
2165
  "input",
1824
2166
  {
1825
- ref: $,
2167
+ ref: S,
1826
2168
  type: "file",
1827
2169
  multiple: !0,
1828
2170
  hidden: !0,
1829
2171
  tabIndex: -1,
1830
2172
  accept: a.allowedTypes.join(","),
1831
- onChange: V,
1832
- "aria-label": d.attachFile
2173
+ onChange: re,
2174
+ "aria-label": f.attachFile
1833
2175
  }
1834
2176
  ),
1835
2177
  /* @__PURE__ */ i(
@@ -1837,12 +2179,12 @@ function dn({
1837
2179
  {
1838
2180
  type: "button",
1839
2181
  onClick: () => {
1840
- var m;
1841
- return (m = $.current) == null ? void 0 : m.click();
2182
+ var p;
2183
+ return (p = S.current) == null ? void 0 : p.click();
1842
2184
  },
1843
- disabled: t || !re,
1844
- "aria-label": d.attachFile,
1845
- title: d.attachFile,
2185
+ disabled: t || !de,
2186
+ "aria-label": f.attachFile,
2187
+ title: f.attachFile,
1846
2188
  className: "flex h-11 w-11 shrink-0 items-center justify-center rounded-claudius-sm border border-claudius-border bg-claudius-field text-claudius-text-muted transition-colors hover:text-claudius-text focus:border-claudius-accent focus:outline-none focus:ring-1 focus:ring-claudius-accent disabled:opacity-50",
1847
2189
  children: /* @__PURE__ */ i(
1848
2190
  "svg",
@@ -1862,41 +2204,41 @@ function dn({
1862
2204
  }
1863
2205
  )
1864
2206
  ] }),
1865
- /* @__PURE__ */ w("div", { className: "relative min-w-0 flex-1", children: [
2207
+ /* @__PURE__ */ g("div", { className: "relative min-w-0 flex-1", children: [
1866
2208
  /* @__PURE__ */ i(
1867
2209
  "input",
1868
2210
  {
1869
- ref: C,
2211
+ ref: D,
1870
2212
  type: "text",
1871
- value: x,
1872
- onChange: ue,
1873
- onPaste: oe,
1874
- placeholder: k ? d.voiceListening : ce,
2213
+ value: T,
2214
+ onChange: le,
2215
+ onPaste: ye,
2216
+ placeholder: F ? f.voiceListening : ce,
1875
2217
  disabled: t,
1876
- "aria-label": d.typeYourMessage,
1877
- "aria-describedby": ae ? "char-count" : void 0,
1878
- className: `h-full w-full rounded-claudius-sm border border-claudius-border bg-claudius-field py-2 pl-3 text-sm font-body text-claudius-text placeholder:text-claudius-text-muted focus:border-claudius-accent focus:outline-none focus:ring-1 focus:ring-claudius-accent disabled:opacity-50 ${k ? "pr-10" : "pr-3"}`
2218
+ "aria-label": f.typeYourMessage,
2219
+ "aria-describedby": W ? "char-count" : void 0,
2220
+ className: `h-full w-full rounded-claudius-sm border border-claudius-border bg-claudius-field py-2 pl-3 text-sm font-body text-claudius-text placeholder:text-claudius-text-muted focus:border-claudius-accent focus:outline-none focus:ring-1 focus:ring-claudius-accent disabled:opacity-50 ${F ? "pr-10" : "pr-3"}`
1879
2221
  }
1880
2222
  ),
1881
- k && /* @__PURE__ */ i(en, { active: F.isSpeechDetected })
2223
+ F && /* @__PURE__ */ i(wn, { active: K.isSpeechDetected })
1882
2224
  ] }),
1883
- H && c && /* @__PURE__ */ i(
1884
- Xt,
2225
+ oe && c && /* @__PURE__ */ i(
2226
+ yn,
1885
2227
  {
1886
2228
  mode: c.mode,
1887
- isListening: k,
2229
+ isListening: F,
1888
2230
  disabled: t,
1889
- onStart: K,
1890
- onStop: Q,
1891
- label: c.mode === "hold" ? d.voiceInputHold : d.voiceInput
2231
+ onStart: L,
2232
+ onStop: _,
2233
+ label: c.mode === "hold" ? f.voiceInputHold : f.voiceInput
1892
2234
  }
1893
2235
  ),
1894
- h ? /* @__PURE__ */ i(
2236
+ fe ? /* @__PURE__ */ i(
1895
2237
  "button",
1896
2238
  {
1897
2239
  type: "button",
1898
2240
  onClick: r,
1899
- "aria-label": d.stopGenerating,
2241
+ "aria-label": f.stopGenerating,
1900
2242
  className: "flex h-11 w-11 shrink-0 items-center justify-center rounded-claudius-sm bg-claudius-accent text-claudius-accent-text transition-colors hover:opacity-90",
1901
2243
  children: /* @__PURE__ */ i(
1902
2244
  "svg",
@@ -1914,10 +2256,10 @@ function dn({
1914
2256
  "button",
1915
2257
  {
1916
2258
  type: "submit",
1917
- disabled: t || ie,
1918
- "aria-label": d.sendMessage,
2259
+ disabled: t || G,
2260
+ "aria-label": f.sendMessage,
1919
2261
  className: "flex h-11 w-11 shrink-0 items-center justify-center rounded-claudius-sm bg-claudius-accent text-claudius-accent-text transition-colors hover:opacity-90 disabled:opacity-50",
1920
- children: /* @__PURE__ */ w(
2262
+ children: /* @__PURE__ */ g(
1921
2263
  "svg",
1922
2264
  {
1923
2265
  width: "16",
@@ -1938,17 +2280,17 @@ function dn({
1938
2280
  }
1939
2281
  )
1940
2282
  ] }),
1941
- (p ?? y) && /* @__PURE__ */ i("div", { role: "alert", className: "mt-1 text-xs text-claudius-error", children: p ?? y }),
1942
- ae && /* @__PURE__ */ w(
2283
+ (d ?? y) && /* @__PURE__ */ i("div", { role: "alert", className: "mt-1 text-xs text-claudius-error", children: d ?? y }),
2284
+ W && /* @__PURE__ */ g(
1943
2285
  "div",
1944
2286
  {
1945
2287
  id: "char-count",
1946
- className: `mt-1 text-xs text-right ${ie ? "text-claudius-error" : "text-claudius-text-muted"}`,
2288
+ className: `mt-1 text-xs text-right ${G ? "text-claudius-error" : "text-claudius-text-muted"}`,
1947
2289
  "aria-live": "polite",
1948
2290
  children: [
1949
- z,
2291
+ J,
1950
2292
  "/",
1951
- ye
2293
+ xe
1952
2294
  ]
1953
2295
  }
1954
2296
  )
@@ -1956,30 +2298,30 @@ function dn({
1956
2298
  }
1957
2299
  );
1958
2300
  }
1959
- const fn = ["blog", "page", "external"], hn = {
2301
+ const Mn = ["blog", "page", "external"], Ln = {
1960
2302
  blog: "Blog",
1961
2303
  page: "Page",
1962
2304
  external: "External"
1963
2305
  };
1964
- function pn(e) {
2306
+ function Dn(e) {
1965
2307
  try {
1966
2308
  return new URL(e).hostname;
1967
2309
  } catch {
1968
2310
  return e;
1969
2311
  }
1970
2312
  }
1971
- const mn = ke(function({
2313
+ const In = Ae(function({
1972
2314
  sources: t,
1973
2315
  onClose: n
1974
2316
  }) {
1975
- const r = fn.map((s) => ({
2317
+ const r = Mn.map((s) => ({
1976
2318
  type: s,
1977
- label: hn[s],
2319
+ label: Ln[s],
1978
2320
  items: t.filter((a) => a.type === s)
1979
2321
  })).filter((s) => s.items.length > 0), o = t.length === 1 ? "1 source found" : `${t.length} sources found`;
1980
- return /* @__PURE__ */ w("div", { className: "absolute inset-y-0 left-0 z-10 flex w-[280px] flex-col border-r-2 border-claudius-border bg-claudius-surface rounded-r-claudius-lg transition-transform duration-200 ease-out", children: [
1981
- /* @__PURE__ */ w("div", { className: "flex items-center justify-between border-b border-claudius-border px-4 py-3", children: [
1982
- /* @__PURE__ */ w("div", { children: [
2322
+ return /* @__PURE__ */ g("div", { className: "absolute inset-y-0 left-0 z-10 flex w-[280px] flex-col border-r-2 border-claudius-border bg-claudius-surface rounded-r-claudius-lg transition-transform duration-200 ease-out", children: [
2323
+ /* @__PURE__ */ g("div", { className: "flex items-center justify-between border-b border-claudius-border px-4 py-3", children: [
2324
+ /* @__PURE__ */ g("div", { children: [
1983
2325
  /* @__PURE__ */ i("h3", { className: "text-sm font-heading font-semibold text-claudius-text", children: "Sources" }),
1984
2326
  /* @__PURE__ */ i("p", { className: "text-xs text-claudius-text-muted", children: o })
1985
2327
  ] }),
@@ -1989,7 +2331,7 @@ const mn = ke(function({
1989
2331
  onClick: n,
1990
2332
  "aria-label": "Close sources",
1991
2333
  className: "flex h-7 w-7 items-center justify-center rounded-claudius-full text-claudius-text-muted transition-colors hover:bg-claudius-surface-muted hover:text-claudius-text",
1992
- children: /* @__PURE__ */ w(
2334
+ children: /* @__PURE__ */ g(
1993
2335
  "svg",
1994
2336
  {
1995
2337
  width: "14",
@@ -2010,11 +2352,11 @@ const mn = ke(function({
2010
2352
  }
2011
2353
  )
2012
2354
  ] }),
2013
- /* @__PURE__ */ i("div", { className: "flex-1 overflow-y-auto px-3 py-3 space-y-4", children: r.map((s) => /* @__PURE__ */ w("div", { children: [
2355
+ /* @__PURE__ */ i("div", { className: "flex-1 overflow-y-auto px-3 py-3 space-y-4", children: r.map((s) => /* @__PURE__ */ g("div", { children: [
2014
2356
  /* @__PURE__ */ i("h4", { className: "mb-2 text-xs font-semibold uppercase tracking-wide text-claudius-text-muted", children: s.label }),
2015
2357
  /* @__PURE__ */ i("div", { className: "space-y-2", children: s.items.map((a) => {
2016
- const c = Ce(a.url);
2017
- return c ? /* @__PURE__ */ w(
2358
+ const c = ke(a.url);
2359
+ return c ? /* @__PURE__ */ g(
2018
2360
  "a",
2019
2361
  {
2020
2362
  href: c,
@@ -2023,7 +2365,7 @@ const mn = ke(function({
2023
2365
  className: "block rounded-claudius-md border-2 border-claudius-border bg-claudius-surface-muted p-3 transition-colors hover:bg-claudius-border",
2024
2366
  children: [
2025
2367
  /* @__PURE__ */ i("p", { className: "truncate text-sm font-medium text-claudius-text", children: a.title }),
2026
- /* @__PURE__ */ i("p", { className: "mt-0.5 text-xs text-claudius-text-muted", children: pn(c) })
2368
+ /* @__PURE__ */ i("p", { className: "mt-0.5 text-xs text-claudius-text-muted", children: Dn(c) })
2027
2369
  ]
2028
2370
  },
2029
2371
  c
@@ -2032,7 +2374,7 @@ const mn = ke(function({
2032
2374
  ] }, s.type)) })
2033
2375
  ] });
2034
2376
  });
2035
- function gn({
2377
+ function On({
2036
2378
  title: e,
2037
2379
  subtitle: t,
2038
2380
  titleId: n,
@@ -2040,7 +2382,7 @@ function gn({
2040
2382
  onClose: o,
2041
2383
  actions: s
2042
2384
  }) {
2043
- return /* @__PURE__ */ w("div", { className: "flex items-center gap-3 bg-claudius-accent px-5 py-4", children: [
2385
+ return /* @__PURE__ */ g("div", { className: "flex items-center gap-3 bg-claudius-accent px-5 py-4", children: [
2044
2386
  /* @__PURE__ */ i(
2045
2387
  "div",
2046
2388
  {
@@ -2049,7 +2391,7 @@ function gn({
2049
2391
  children: e.charAt(0).toUpperCase()
2050
2392
  }
2051
2393
  ),
2052
- /* @__PURE__ */ w("div", { className: "flex-1", children: [
2394
+ /* @__PURE__ */ g("div", { className: "flex-1", children: [
2053
2395
  /* @__PURE__ */ i(
2054
2396
  "h2",
2055
2397
  {
@@ -2067,7 +2409,7 @@ function gn({
2067
2409
  onClick: o,
2068
2410
  "aria-label": r,
2069
2411
  className: "flex h-10 w-10 items-center justify-center rounded-claudius-full text-claudius-accent-text-muted transition-colors hover:bg-claudius-accent-soft hover:text-claudius-accent-text",
2070
- children: /* @__PURE__ */ w(
2412
+ children: /* @__PURE__ */ g(
2071
2413
  "svg",
2072
2414
  {
2073
2415
  width: "18",
@@ -2089,12 +2431,12 @@ function gn({
2089
2431
  )
2090
2432
  ] });
2091
2433
  }
2092
- function bn({
2434
+ function $n({
2093
2435
  message: e,
2094
2436
  retryLabel: t,
2095
2437
  onRetry: n
2096
2438
  }) {
2097
- return /* @__PURE__ */ w(
2439
+ return /* @__PURE__ */ g(
2098
2440
  "div",
2099
2441
  {
2100
2442
  role: "alert",
@@ -2114,7 +2456,7 @@ function bn({
2114
2456
  }
2115
2457
  );
2116
2458
  }
2117
- function yn({ label: e }) {
2459
+ function jn({ label: e }) {
2118
2460
  return /* @__PURE__ */ i(
2119
2461
  "div",
2120
2462
  {
@@ -2122,7 +2464,7 @@ function yn({ label: e }) {
2122
2464
  "aria-live": "polite",
2123
2465
  "aria-label": e,
2124
2466
  className: "mr-auto flex max-w-[85%]",
2125
- children: /* @__PURE__ */ w("div", { className: "flex gap-1 rounded-claudius-bubble rounded-bl-claudius-tail bg-claudius-assistant-bubble px-4 py-3", children: [
2467
+ children: /* @__PURE__ */ g("div", { className: "flex gap-1 rounded-claudius-bubble rounded-bl-claudius-tail bg-claudius-assistant-bubble px-4 py-3", children: [
2126
2468
  /* @__PURE__ */ i("span", { className: "h-2 w-2 motion-safe:animate-bounce rounded-claudius-full bg-claudius-text-muted [animation-delay:0ms]" }),
2127
2469
  /* @__PURE__ */ i("span", { className: "h-2 w-2 motion-safe:animate-bounce rounded-claudius-full bg-claudius-text-muted [animation-delay:150ms]" }),
2128
2470
  /* @__PURE__ */ i("span", { className: "h-2 w-2 motion-safe:animate-bounce rounded-claudius-full bg-claudius-text-muted [animation-delay:300ms]" })
@@ -2130,29 +2472,29 @@ function yn({ label: e }) {
2130
2472
  }
2131
2473
  );
2132
2474
  }
2133
- function xn({ label: e, items: t, onOpen: n }) {
2134
- const [r, o] = N(!1), s = Ne(), a = Ne(), c = S(null), l = S(null), u = S([]), d = S(null), x = (b) => {
2135
- d.current = b, o(!0), n == null || n();
2475
+ function Pn({ label: e, items: t, onOpen: n }) {
2476
+ const [r, o] = M(!1), s = Ne(), a = Ne(), c = C(null), l = C(null), u = C([]), f = C(null), T = (b) => {
2477
+ f.current = b, o(!0), n == null || n();
2136
2478
  }, A = (b) => {
2137
- var R;
2138
- o(!1), (R = l.current) == null || R.focus();
2479
+ var x;
2480
+ o(!1), (x = l.current) == null || x.focus();
2139
2481
  };
2140
- W(() => {
2141
- var R;
2482
+ H(() => {
2483
+ var x;
2142
2484
  if (!r) return;
2143
- d.current !== null && ((R = u.current[d.current]) == null || R.focus(), d.current = null);
2485
+ f.current !== null && ((x = u.current[f.current]) == null || x.focus(), f.current = null);
2144
2486
  const b = (y) => {
2145
- var v;
2146
- (v = c.current) != null && v.contains(y.target) || o(!1);
2487
+ var w;
2488
+ (w = c.current) != null && w.contains(y.target) || o(!1);
2147
2489
  };
2148
2490
  return document.addEventListener("pointerdown", b), () => document.removeEventListener("pointerdown", b);
2149
2491
  }, [r]);
2150
- const g = (b) => {
2492
+ const m = (b) => {
2151
2493
  var y;
2152
- const R = t.length;
2153
- (y = u.current[(b + R) % R]) == null || y.focus();
2494
+ const x = t.length;
2495
+ (y = u.current[(b + x) % x]) == null || y.focus();
2154
2496
  };
2155
- return /* @__PURE__ */ w("div", { ref: c, className: "relative", children: [
2497
+ return /* @__PURE__ */ g("div", { ref: c, className: "relative", children: [
2156
2498
  /* @__PURE__ */ i(
2157
2499
  "button",
2158
2500
  {
@@ -2163,12 +2505,12 @@ function xn({ label: e, items: t, onOpen: n }) {
2163
2505
  "aria-haspopup": "menu",
2164
2506
  "aria-expanded": r,
2165
2507
  "aria-controls": r ? a : void 0,
2166
- onClick: () => r ? A() : x(0),
2508
+ onClick: () => r ? A() : T(0),
2167
2509
  onKeyDown: (b) => {
2168
- b.key === "ArrowDown" ? (b.preventDefault(), x(0)) : b.key === "ArrowUp" && (b.preventDefault(), x(t.length - 1));
2510
+ b.key === "ArrowDown" ? (b.preventDefault(), T(0)) : b.key === "ArrowUp" && (b.preventDefault(), T(t.length - 1));
2169
2511
  },
2170
2512
  className: "flex h-10 w-10 items-center justify-center rounded-claudius-full text-claudius-accent-text-muted transition-colors hover:bg-claudius-accent-soft hover:text-claudius-accent-text",
2171
- children: /* @__PURE__ */ w(
2513
+ children: /* @__PURE__ */ g(
2172
2514
  "svg",
2173
2515
  {
2174
2516
  width: "18",
@@ -2193,21 +2535,21 @@ function xn({ label: e, items: t, onOpen: n }) {
2193
2535
  "aria-labelledby": s,
2194
2536
  tabIndex: -1,
2195
2537
  onKeyDown: (b) => {
2196
- const R = u.current.findIndex(
2538
+ const x = u.current.findIndex(
2197
2539
  (y) => y === document.activeElement
2198
2540
  );
2199
2541
  switch (b.key) {
2200
2542
  case "ArrowDown":
2201
- b.preventDefault(), g(R + 1);
2543
+ b.preventDefault(), m(x + 1);
2202
2544
  break;
2203
2545
  case "ArrowUp":
2204
- b.preventDefault(), g(R === -1 ? t.length - 1 : R - 1);
2546
+ b.preventDefault(), m(x === -1 ? t.length - 1 : x - 1);
2205
2547
  break;
2206
2548
  case "Home":
2207
- b.preventDefault(), g(0);
2549
+ b.preventDefault(), m(0);
2208
2550
  break;
2209
2551
  case "End":
2210
- b.preventDefault(), g(t.length - 1);
2552
+ b.preventDefault(), m(t.length - 1);
2211
2553
  break;
2212
2554
  case "Escape":
2213
2555
  b.preventDefault(), b.stopPropagation(), A();
@@ -2219,15 +2561,15 @@ function xn({ label: e, items: t, onOpen: n }) {
2219
2561
  },
2220
2562
  onBlur: (b) => {
2221
2563
  var y;
2222
- const R = b.relatedTarget;
2223
- R && ((y = c.current) != null && y.contains(R) || o(!1));
2564
+ const x = b.relatedTarget;
2565
+ x && ((y = c.current) != null && y.contains(x) || o(!1));
2224
2566
  },
2225
2567
  className: "absolute right-0 top-full z-20 mt-1 min-w-[12rem] rounded-claudius-md border border-claudius-border bg-claudius-surface py-1 shadow-claudius-elevated",
2226
- children: t.map((b, R) => /* @__PURE__ */ i(
2568
+ children: t.map((b, x) => /* @__PURE__ */ i(
2227
2569
  "button",
2228
2570
  {
2229
2571
  ref: (y) => {
2230
- u.current[R] = y;
2572
+ u.current[x] = y;
2231
2573
  },
2232
2574
  type: "button",
2233
2575
  role: "menuitem",
@@ -2245,41 +2587,41 @@ function xn({ label: e, items: t, onOpen: n }) {
2245
2587
  )
2246
2588
  ] });
2247
2589
  }
2248
- function wn(e, t, n) {
2249
- const [r, o] = N(0), s = S(0), a = S(0), c = S(0), l = S(!1);
2250
- return W(() => {
2590
+ function Un(e, t, n) {
2591
+ const [r, o] = M(0), s = C(0), a = C(0), c = C(0), l = C(!1);
2592
+ return H(() => {
2251
2593
  const u = e.current;
2252
2594
  if (!n || !u) return;
2253
- const d = (g) => {
2595
+ const f = (m) => {
2254
2596
  if (u.scrollTop > 0) {
2255
2597
  l.current = !1;
2256
2598
  return;
2257
2599
  }
2258
- l.current = !0, a.current = g.touches[0].clientY, c.current = Date.now();
2259
- }, x = (g) => {
2600
+ l.current = !0, a.current = m.touches[0].clientY, c.current = Date.now();
2601
+ }, T = (m) => {
2260
2602
  if (!l.current) return;
2261
- let f = g.touches[0].clientY - a.current;
2262
- f < 0 && (f = f * 0.3), s.current = f, o(f);
2603
+ let h = m.touches[0].clientY - a.current;
2604
+ h < 0 && (h = h * 0.3), s.current = h, o(h);
2263
2605
  }, A = () => {
2264
2606
  if (!l.current) return;
2265
2607
  l.current = !1;
2266
- const g = s.current, f = (Date.now() - c.current) / 1e3, p = u.getBoundingClientRect().height, T = f > 0.05 && g > 0 && g / f > 500, b = g > p * 0.3;
2267
- T || b ? t() : (s.current = 0, o(0));
2608
+ const m = s.current, h = (Date.now() - c.current) / 1e3, d = u.getBoundingClientRect().height, k = h > 0.05 && m > 0 && m / h > 500, b = m > d * 0.3;
2609
+ k || b ? t() : (s.current = 0, o(0));
2268
2610
  };
2269
- return u.addEventListener("touchstart", d, { passive: !0 }), u.addEventListener("touchmove", x, { passive: !0 }), u.addEventListener("touchend", A), () => {
2270
- u.removeEventListener("touchstart", d), u.removeEventListener("touchmove", x), u.removeEventListener("touchend", A);
2611
+ return u.addEventListener("touchstart", f, { passive: !0 }), u.addEventListener("touchmove", T, { passive: !0 }), u.addEventListener("touchend", A), () => {
2612
+ u.removeEventListener("touchstart", f), u.removeEventListener("touchmove", T), u.removeEventListener("touchend", A);
2271
2613
  };
2272
2614
  }, [e, t, n]), { offsetY: r };
2273
2615
  }
2274
- const vn = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
2275
- function Tn(e, t) {
2276
- W(() => {
2616
+ const Bn = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
2617
+ function Fn(e, t) {
2618
+ H(() => {
2277
2619
  const n = e.current;
2278
2620
  if (!n) return;
2279
2621
  const r = (o) => {
2280
2622
  if (o.key !== "Tab") return;
2281
2623
  const s = Array.from(
2282
- n.querySelectorAll(vn)
2624
+ n.querySelectorAll(Bn)
2283
2625
  ).filter((u) => !u.hasAttribute("aria-hidden"));
2284
2626
  if (s.length === 0) return;
2285
2627
  const a = s[0], c = s[s.length - 1], l = document.activeElement;
@@ -2288,53 +2630,53 @@ function Tn(e, t) {
2288
2630
  return n.addEventListener("keydown", r), () => n.removeEventListener("keydown", r);
2289
2631
  }, [e, t]);
2290
2632
  }
2291
- function xe() {
2633
+ function ve() {
2292
2634
  if (!(typeof window > "u") && !(typeof window.SpeechSynthesisUtterance > "u"))
2293
2635
  return window.speechSynthesis ?? void 0;
2294
2636
  }
2295
- function En(e) {
2296
- const [t] = N(() => xe() !== void 0), [n, r] = N(null), [o, s] = N(!1), a = S(0), c = S(!1), l = S([]), u = M(() => {
2637
+ function _n(e) {
2638
+ const [t] = M(() => ve() !== void 0), [n, r] = M(null), [o, s] = M(!1), a = C(0), c = C(!1), l = C([]), u = O(() => {
2297
2639
  a.current += 1, c.current = !1, l.current = [], r(null), s(!1);
2298
- }, []), d = M(() => {
2299
- const f = l.current.length > 0;
2640
+ }, []), f = O(() => {
2641
+ const h = l.current.length > 0;
2300
2642
  u();
2301
- const p = xe();
2302
- !f || !p || (p.cancel(), p.paused && p.resume());
2303
- }, [u]), x = M(
2304
- (f, p) => {
2305
- const T = xe();
2306
- if (!T) return;
2307
- u(), (T.speaking || T.pending) && T.cancel(), T.paused && T.resume();
2308
- const b = an(p);
2643
+ const d = ve();
2644
+ !h || !d || (d.cancel(), d.paused && d.resume());
2645
+ }, [u]), T = O(
2646
+ (h, d) => {
2647
+ const k = ve();
2648
+ if (!k) return;
2649
+ u(), (k.speaking || k.pending) && k.cancel(), k.paused && k.resume();
2650
+ const b = kn(d);
2309
2651
  if (b.length === 0) return;
2310
- const R = a.current, y = () => a.current === R;
2311
- l.current = b.map((v, C) => {
2312
- const $ = new SpeechSynthesisUtterance(v);
2313
- return $.lang = e, $.onerror = (L) => {
2652
+ const x = a.current, y = () => a.current === x;
2653
+ l.current = b.map((w, D) => {
2654
+ const S = new SpeechSynthesisUtterance(w);
2655
+ return S.lang = e, S.onerror = (N) => {
2314
2656
  if (!y()) return;
2315
- (L.error === "interrupted" || L.error === "canceled") && !c.current ? u() : d();
2316
- }, $.onpause = () => {
2657
+ (N.error === "interrupted" || N.error === "canceled") && !c.current ? u() : f();
2658
+ }, S.onpause = () => {
2317
2659
  y() && s(!0);
2318
- }, $.onresume = () => {
2660
+ }, S.onresume = () => {
2319
2661
  y() && s(!1);
2320
- }, $.onend = () => {
2321
- y() && (c.current && !T.paused ? d() : C === b.length - 1 && u());
2322
- }, $;
2323
- }), r(f);
2324
- for (const v of l.current) T.speak(v);
2662
+ }, S.onend = () => {
2663
+ y() && (c.current && !k.paused ? f() : D === b.length - 1 && u());
2664
+ }, S;
2665
+ }), r(h);
2666
+ for (const w of l.current) k.speak(w);
2325
2667
  },
2326
- [e, d, u]
2327
- ), A = M(() => {
2328
- const f = xe();
2329
- f && (c.current = !0, f.pause(), f.paused && s(!0));
2330
- }, []), g = M(() => {
2331
- const f = xe();
2332
- f && (c.current = !1, f.resume(), s(!1));
2668
+ [e, f, u]
2669
+ ), A = O(() => {
2670
+ const h = ve();
2671
+ h && (c.current = !0, h.pause(), h.paused && s(!0));
2672
+ }, []), m = O(() => {
2673
+ const h = ve();
2674
+ h && (c.current = !1, h.resume(), s(!1));
2333
2675
  }, []);
2334
- return W(() => d, [d]), { isSupported: t, activeId: n, isPaused: o, speak: x, pause: A, resume: g, cancel: d };
2676
+ return H(() => f, [f]), { isSupported: t, activeId: n, isPaused: o, speak: T, pause: A, resume: m, cancel: f };
2335
2677
  }
2336
- const Rn = /^([ \t]*)(`{3,}|~{3,})(.*)$/, An = /^( {0,3})<(?![A-Za-z][A-Za-z0-9+.-]{1,31}:[^<>\s]*>|[^\s<>@]+@[^\s<>]+>)(?=[A-Za-z!?/])/, Sn = /^(?: {4}|\t)/;
2337
- function ot(e) {
2678
+ const Hn = /^([ \t]*)(`{3,}|~{3,})(.*)$/, zn = /^( {0,3})<(?![A-Za-z][A-Za-z0-9+.-]{1,31}:[^<>\s]*>|[A-Za-z0-9][^\s<>@]*@[^\s<>]+>)(?=[A-Za-z!?/])/, Wn = /^(?: {4}|\t)/;
2679
+ function it(e) {
2338
2680
  let t = 0;
2339
2681
  for (const n of e)
2340
2682
  if (n === " ") t += 1;
@@ -2342,30 +2684,30 @@ function ot(e) {
2342
2684
  else break;
2343
2685
  return t;
2344
2686
  }
2345
- function Ge(e) {
2687
+ function Ke(e) {
2346
2688
  let t = e.length;
2347
2689
  for (; t > 0 && (e[t - 1] === " " || e[t - 1] === " "); ) t -= 1;
2348
2690
  return t === e.length ? e : e.slice(0, t);
2349
2691
  }
2350
- function kn(e) {
2351
- const t = Rn.exec(e);
2692
+ function Gn(e) {
2693
+ const t = Hn.exec(e);
2352
2694
  if (!t) return null;
2353
2695
  const [, n, r, o] = t;
2354
2696
  return r[0] === "`" && o.includes("`") ? null : {
2355
2697
  indent: n,
2356
- indentColumns: ot(n),
2698
+ indentColumns: it(n),
2357
2699
  char: r[0],
2358
2700
  length: r.length
2359
2701
  };
2360
2702
  }
2361
- function Cn(e, t) {
2703
+ function Vn(e, t) {
2362
2704
  const n = e.trim();
2363
2705
  if (n.length < t.length) return !1;
2364
2706
  for (const r of n)
2365
2707
  if (r !== t.char) return !1;
2366
- return ot(e) <= t.indentColumns + 3;
2708
+ return it(e) <= t.indentColumns + 3;
2367
2709
  }
2368
- function Mn(e) {
2710
+ function Kn(e) {
2369
2711
  const t = e.replace(/\r\n?/g, `
2370
2712
  `).split(`
2371
2713
  `), n = [];
@@ -2373,31 +2715,31 @@ function Mn(e) {
2373
2715
  for (let o = 0; o < t.length; o++) {
2374
2716
  const s = t[o];
2375
2717
  if (r) {
2376
- n.push(s), Cn(s, r) && (r = null);
2718
+ n.push(s), Vn(s, r) && (r = null);
2377
2719
  continue;
2378
2720
  }
2379
- const a = kn(s);
2721
+ const a = Gn(s);
2380
2722
  if (a) {
2381
2723
  r = a, n.push(s);
2382
2724
  continue;
2383
2725
  }
2384
- let c = s.replace(An, "$1\\<");
2726
+ let c = s.replace(zn, "$1\\<");
2385
2727
  const l = t[o + 1];
2386
2728
  s.trim() !== "" && l !== void 0 && l.trim() !== "" && // Possibly indented code, where trailing spaces would be content.
2387
- !Sn.test(s) && // Already a hard break.
2388
- !s.endsWith("\\") && (c = Ge(c) + " "), n.push(c);
2729
+ !Wn.test(s) && // Already a hard break.
2730
+ !s.endsWith("\\") && (c = Ke(c) + " "), n.push(c);
2389
2731
  }
2390
2732
  if (r)
2391
2733
  n[n.length - 1] === "" && n.pop(), n.push(r.indent + r.char.repeat(r.length));
2392
2734
  else {
2393
2735
  for (; n.length > 0 && n[n.length - 1].trim() === ""; ) n.pop();
2394
- n.length > 0 && (n[n.length - 1] = Ge(n[n.length - 1]));
2736
+ n.length > 0 && (n[n.length - 1] = Ke(n[n.length - 1]));
2395
2737
  }
2396
2738
  return n.join(`
2397
2739
  `);
2398
2740
  }
2399
- const Nn = /[\u00a0\u202f]/g;
2400
- function Dn(e) {
2741
+ const Yn = /[\u00a0\u202f]/g;
2742
+ function qn(e) {
2401
2743
  if (e.formatDate) return e.formatDate;
2402
2744
  const t = (o) => new Intl.DateTimeFormat(o, {
2403
2745
  dateStyle: "medium",
@@ -2417,11 +2759,11 @@ function Dn(e) {
2417
2759
  const r = n;
2418
2760
  return r ? (o) => r.format(o) : (o) => o.toISOString();
2419
2761
  }
2420
- function Ln(e) {
2421
- const t = Dn(e);
2422
- return (n) => t(n).replace(Nn, " ");
2762
+ function Zn(e) {
2763
+ const t = qn(e);
2764
+ return (n) => t(n).replace(Yn, " ");
2423
2765
  }
2424
- function In(e, t) {
2766
+ function Jn(e, t) {
2425
2767
  var n;
2426
2768
  try {
2427
2769
  return ((n = new Intl.DateTimeFormat("en", {
@@ -2432,7 +2774,7 @@ function In(e, t) {
2432
2774
  return "";
2433
2775
  }
2434
2776
  }
2435
- function st(e) {
2777
+ function ct(e) {
2436
2778
  const t = e.replace(/\s+/g, " ").trim();
2437
2779
  if (t === "") return "";
2438
2780
  const n = Math.max(
@@ -2441,57 +2783,57 @@ function st(e) {
2441
2783
  ), r = "`".repeat(n + 1), o = t.startsWith("`") || t.endsWith("`") ? " " : "";
2442
2784
  return `${r}${o}${t}${o}${r}`;
2443
2785
  }
2444
- const On = {
2786
+ const Qn = {
2445
2787
  "(": "%28",
2446
2788
  ")": "%29",
2447
2789
  "<": "%3C",
2448
2790
  ">": "%3E",
2449
2791
  "\\": "%5C"
2450
2792
  };
2451
- function jn(e, t) {
2452
- const n = pe(e.title || e.url).replace(/\s+/g, " ").trim().replace(/[\\[\]<]/g, "\\$&"), r = Ce(pe(e.url));
2793
+ function Xn(e, t) {
2794
+ const n = be(e.title || e.url).replace(/\s+/g, " ").trim().replace(/[\\[\]<]/g, "\\$&"), r = ke(be(e.url));
2453
2795
  if (!r) return `${t + 1}. ${n}`;
2454
- const o = r.replace(/[()<>\\]/g, (s) => On[s]).replace(/\s/g, "%20");
2796
+ const o = r.replace(/[()<>\\]/g, (s) => Qn[s]).replace(/\s/g, "%20");
2455
2797
  return `${t + 1}. [${n}](${o})`;
2456
2798
  }
2457
- function $n(e) {
2458
- const t = st(pe(e.name)), n = Se(Number(e.size));
2459
- return `- ${t} (${pe(e.mediaType)}, ${n})`;
2799
+ function er(e) {
2800
+ const t = ct(be(e.name)), n = Me(Number(e.size));
2801
+ return `- ${t} (${be(e.mediaType)}, ${n})`;
2460
2802
  }
2461
- function pe(e) {
2803
+ function be(e) {
2462
2804
  return typeof e == "string" ? e : String(e ?? "");
2463
2805
  }
2464
- function Ae(e) {
2806
+ function Ce(e) {
2465
2807
  return Array.isArray(e) ? e.filter(
2466
2808
  (t) => t !== null && typeof t == "object"
2467
2809
  ) : [];
2468
2810
  }
2469
- function Pn(e, t) {
2470
- const { labels: n } = t, r = Ln(t), o = t.now ?? /* @__PURE__ */ new Date(), s = In(o, t.timeZone), a = r(o) + (s ? ` (${s})` : ""), c = [
2811
+ function tr(e, t) {
2812
+ const { labels: n } = t, r = Zn(t), o = t.now ?? /* @__PURE__ */ new Date(), s = Jn(o, t.timeZone), a = r(o) + (s ? ` (${s})` : ""), c = [
2471
2813
  `# ${n.title}`,
2472
- Re(n.exported, { date: a })
2814
+ ge(n.exported, { date: a })
2473
2815
  ];
2474
2816
  for (const l of e) {
2475
2817
  if (l === null || typeof l != "object") continue;
2476
- const u = l.role === "user" ? n.user : n.assistant, d = l.createdAt ? new Date(l.createdAt) : null, x = d && !Number.isNaN(d.getTime()) ? ` · ${r(d)}` : "";
2477
- c.push(`## ${u}${x}`);
2478
- const A = Mn(pe(l.content));
2818
+ const u = l.role === "user" ? n.user : n.assistant, f = l.createdAt ? new Date(l.createdAt) : null, T = f && !Number.isNaN(f.getTime()) ? ` · ${r(f)}` : "";
2819
+ c.push(`## ${u}${T}`);
2820
+ const A = Kn(be(l.content));
2479
2821
  A && c.push(A);
2480
- const g = Ae(l.attachments);
2481
- g.length && c.push(
2822
+ const m = Ce(l.attachments);
2823
+ m.length && c.push(
2482
2824
  n.attachments,
2483
- g.map($n).join(`
2825
+ m.map(er).join(`
2484
2826
  `)
2485
2827
  );
2486
- const f = Ae(l.toolUses);
2487
- f.length && c.push(
2488
- f.map(
2489
- (T) => `${n.toolUsed} ${st(pe(T.name))}`
2828
+ const h = Ce(l.toolUses);
2829
+ h.length && c.push(
2830
+ h.map(
2831
+ (k) => `${n.toolUsed} ${ct(be(k.name))}`
2490
2832
  ).join(`
2491
2833
  `)
2492
2834
  );
2493
- const p = Ae(l.sources);
2494
- p.length && c.push(n.sources, p.map(jn).join(`
2835
+ const d = Ce(l.sources);
2836
+ d.length && c.push(n.sources, d.map(Xn).join(`
2495
2837
  `));
2496
2838
  }
2497
2839
  return c.join(`
@@ -2499,17 +2841,17 @@ function Pn(e, t) {
2499
2841
  `) + `
2500
2842
  `;
2501
2843
  }
2502
- function Un(e) {
2844
+ function nr(e) {
2503
2845
  const t = e.filter((n) => n !== null && typeof n == "object").map(
2504
2846
  (n) => n.attachments === void 0 ? n : {
2505
2847
  ...n,
2506
- attachments: Ae(n.attachments)
2848
+ attachments: Ce(n.attachments)
2507
2849
  }
2508
2850
  );
2509
2851
  return JSON.stringify(et(t), null, 2) + `
2510
2852
  `;
2511
2853
  }
2512
- function Ke(e, t = {}) {
2854
+ function Ye(e, t = {}) {
2513
2855
  const n = t.now ?? /* @__PURE__ */ new Date();
2514
2856
  let r;
2515
2857
  try {
@@ -2528,53 +2870,64 @@ function Ke(e, t = {}) {
2528
2870
  }
2529
2871
  return `chat-transcript-${r}.${e}`;
2530
2872
  }
2531
- function Bn(e) {
2873
+ function rr(e) {
2532
2874
  const t = document.activeElement;
2533
2875
  let n = null;
2534
2876
  try {
2535
- return n = document.createElement("textarea"), n.value = e, n.setAttribute("readonly", ""), n.setAttribute("aria-hidden", "true"), n.style.position = "fixed", n.style.top = "0", n.style.left = "0", n.style.opacity = "0", document.body.appendChild(n), n.focus({ preventScroll: !0 }), n.select(), document.execCommand("copy");
2877
+ return n = document.createElement("textarea"), n.value = e, n.setAttribute("readonly", ""), n.setAttribute("aria-hidden", "true"), n.tabIndex = -1, n.style.position = "fixed", n.style.top = "0", n.style.left = "0", n.style.opacity = "0", document.body.appendChild(n), n.focus({ preventScroll: !0 }), n.select(), document.execCommand("copy");
2536
2878
  } catch {
2537
2879
  return !1;
2538
2880
  } finally {
2539
- n == null || n.remove(), t == null || t.focus();
2881
+ try {
2882
+ n == null || n.remove();
2883
+ } catch {
2884
+ }
2885
+ try {
2886
+ t == null || t.focus();
2887
+ } catch {
2888
+ }
2540
2889
  }
2541
2890
  }
2542
- async function _n(e) {
2891
+ async function or(e) {
2543
2892
  var t;
2544
2893
  try {
2545
2894
  if ((t = navigator.clipboard) != null && t.writeText)
2546
2895
  return await navigator.clipboard.writeText(e), !0;
2547
2896
  } catch {
2548
2897
  }
2549
- return Bn(e);
2898
+ try {
2899
+ return rr(e);
2900
+ } catch {
2901
+ return !1;
2902
+ }
2550
2903
  }
2551
- const zn = 4e4;
2552
- function Ve(e, t, n) {
2904
+ const sr = 4e4;
2905
+ function qe(e, t, n) {
2553
2906
  const r = URL.createObjectURL(new Blob([t], { type: n })), o = document.createElement("a");
2554
- o.href = r, o.download = e, o.style.display = "none", document.body.appendChild(o), o.click(), o.remove(), setTimeout(() => URL.revokeObjectURL(r), zn);
2907
+ o.href = r, o.download = e, o.style.display = "none", document.body.appendChild(o), o.click(), o.remove(), setTimeout(() => URL.revokeObjectURL(r), sr);
2555
2908
  }
2556
- const Hn = 4e3;
2557
- function Fn({
2909
+ const ar = 4e3;
2910
+ function ir({
2558
2911
  enabled: e,
2559
2912
  messages: t,
2560
2913
  busy: n,
2561
2914
  locale: r,
2562
2915
  translations: o
2563
2916
  }) {
2564
- const s = o ?? Oe, [a, c] = N(null), l = S(null), u = S(!0);
2565
- W(() => (u.current = !0, () => {
2917
+ const s = o ?? je, [a, c] = M(null), l = C(null), u = C(!0);
2918
+ H(() => (u.current = !0, () => {
2566
2919
  u.current = !1, l.current && clearTimeout(l.current);
2567
2920
  }), []);
2568
- const d = M(() => {
2921
+ const f = O(() => {
2569
2922
  l.current && clearTimeout(l.current), l.current = null, c(null);
2570
- }, []), x = M((g) => {
2571
- u.current && (l.current && clearTimeout(l.current), c(g), l.current = setTimeout(() => {
2923
+ }, []), T = O((m) => {
2924
+ u.current && (l.current && clearTimeout(l.current), c(m), l.current = setTimeout(() => {
2572
2925
  l.current = null, c(null);
2573
- }, Hn));
2926
+ }, ar));
2574
2927
  }, []);
2575
- return { items: se(() => {
2928
+ return { items: ae(() => {
2576
2929
  if (!e) return [];
2577
- const g = n || t.length === 0, f = () => Pn(t, {
2930
+ const m = n || t.length === 0, h = () => tr(t, {
2578
2931
  locale: r,
2579
2932
  labels: {
2580
2933
  title: s.transcriptTitle,
@@ -2590,39 +2943,39 @@ function Fn({
2590
2943
  {
2591
2944
  id: "copy-markdown",
2592
2945
  label: s.copyAsMarkdown,
2593
- disabled: g,
2946
+ disabled: m,
2594
2947
  onSelect: () => {
2595
- _n(f()).then(
2596
- (p) => x(p ? s.copiedToClipboard : s.copyFailed)
2948
+ or(h()).then(
2949
+ (d) => T(d ? s.copiedToClipboard : s.copyFailed)
2597
2950
  );
2598
2951
  }
2599
2952
  },
2600
2953
  {
2601
2954
  id: "download-markdown",
2602
2955
  label: s.downloadAsMarkdown,
2603
- disabled: g,
2604
- onSelect: () => Ve(
2605
- Ke("md"),
2606
- f(),
2956
+ disabled: m,
2957
+ onSelect: () => qe(
2958
+ Ye("md"),
2959
+ h(),
2607
2960
  "text/markdown;charset=utf-8"
2608
2961
  )
2609
2962
  },
2610
2963
  {
2611
2964
  id: "download-json",
2612
2965
  label: s.downloadAsJson,
2613
- disabled: g,
2614
- onSelect: () => Ve(
2615
- Ke("json"),
2616
- Un(t),
2966
+ disabled: m,
2967
+ onSelect: () => qe(
2968
+ Ye("json"),
2969
+ nr(t),
2617
2970
  "application/json"
2618
2971
  )
2619
2972
  }
2620
2973
  ];
2621
- }, [e, n, t, r, s, x]), status: a, clearStatus: d };
2974
+ }, [e, n, t, r, s, T]), status: a, clearStatus: f };
2622
2975
  }
2623
- const Wn = /\*\*([^*]+)\*\*/g, Gn = /\*([^*]+)\*/g, Kn = /https?:\/\/[^\s)]+/g;
2624
- function Ye(e) {
2625
- return e.replace(Wn, "$1").replace(Gn, "$1").replace(Kn, (t) => {
2976
+ const cr = /\*\*([^*]+)\*\*/g, lr = /\*([^*]+)\*/g, ur = /https?:\/\/[^\s)]+/g;
2977
+ function dr(e) {
2978
+ return e.replace(cr, "$1").replace(lr, "$1").replace(ur, (t) => {
2626
2979
  var o;
2627
2980
  const n = ((o = t.match(/[.,;:!?'"]+$/)) == null ? void 0 : o[0]) ?? "", r = n ? t.slice(0, -n.length) : t;
2628
2981
  try {
@@ -2632,13 +2985,13 @@ function Ye(e) {
2632
2985
  }
2633
2986
  });
2634
2987
  }
2635
- const Vn = {
2988
+ const fr = {
2636
2989
  "bottom-right": "bottom-24 right-3 sm:right-6",
2637
2990
  "bottom-left": "bottom-24 left-3 sm:left-6",
2638
2991
  "top-right": "top-24 right-3 sm:right-6",
2639
2992
  "top-left": "top-24 left-3 sm:left-6"
2640
2993
  };
2641
- function Yn({
2994
+ function hr({
2642
2995
  messages: e,
2643
2996
  isLoading: t,
2644
2997
  isStreaming: n = !1,
@@ -2649,82 +3002,100 @@ function Yn({
2649
3002
  onStop: c,
2650
3003
  onRetry: l,
2651
3004
  onClose: u,
2652
- title: d = "Chat",
2653
- subtitle: x = "Ask me anything",
3005
+ title: f = "Chat",
3006
+ subtitle: T = "Ask me anything",
2654
3007
  welcomeMessage: A = "Hi! How can I help you today?",
2655
- placeholder: g,
2656
- position: f = "bottom-right",
2657
- translations: p,
2658
- isMobile: T = !1,
3008
+ placeholder: m,
3009
+ position: h = "bottom-right",
3010
+ translations: d,
3011
+ isMobile: k = !1,
2659
3012
  attachments: b = null,
2660
- voice: R = null,
3013
+ voice: x = null,
2661
3014
  conversationExport: y = !1,
2662
- locale: v = "en-US"
3015
+ locale: w = "en-US",
3016
+ citations: D = null
2663
3017
  }) {
2664
- const C = Ne(), $ = S(null), L = S(null), [E, B] = N(null);
2665
- Tn($, !0);
2666
- const O = En((R == null ? void 0 : R.lang) ?? "en-US"), _ = !!(R != null && R.output) && O.isSupported, q = {
2667
- play: (p == null ? void 0 : p.readAloud) ?? "Read aloud",
2668
- pause: (p == null ? void 0 : p.pauseReading) ?? "Pause reading",
2669
- resume: (p == null ? void 0 : p.resumeReading) ?? "Resume reading",
2670
- stop: (p == null ? void 0 : p.stopReading) ?? "Stop reading"
2671
- }, G = Fn({
3018
+ const S = Ne(), N = C(null), I = C(null), [R, ne] = M(null);
3019
+ Fn(N, !0);
3020
+ const $ = _n((x == null ? void 0 : x.lang) ?? "en-US"), z = !!(x != null && x.output) && $.isSupported, X = {
3021
+ play: (d == null ? void 0 : d.readAloud) ?? "Read aloud",
3022
+ pause: (d == null ? void 0 : d.pauseReading) ?? "Pause reading",
3023
+ resume: (d == null ? void 0 : d.resumeReading) ?? "Resume reading",
3024
+ stop: (d == null ? void 0 : d.stopReading) ?? "Stop reading"
3025
+ }, Z = ir({
2672
3026
  enabled: y,
2673
3027
  messages: e,
2674
3028
  busy: t,
2675
- locale: v,
2676
- translations: p
2677
- }), { offsetY: J } = wn(
2678
- L,
3029
+ locale: w,
3030
+ translations: d
3031
+ }), J = (d == null ? void 0 : d.opensInNewTab) ?? "(opens in a new tab)", W = ae(
3032
+ () => D ? {
3033
+ ...D,
3034
+ labels: {
3035
+ sources: (d == null ? void 0 : d.sources) ?? "Sources",
3036
+ showAllSources: (d == null ? void 0 : d.showAllSources) ?? "Show all ({count})",
3037
+ showFewerSources: (d == null ? void 0 : d.showFewerSources) ?? "Show fewer",
3038
+ citation: (d == null ? void 0 : d.citation) ?? "Source {n}: {title}",
3039
+ opensInNewTab: J
3040
+ }
3041
+ } : void 0,
3042
+ [D, d, J]
3043
+ ), G = (v) => {
3044
+ var V;
3045
+ return dr(
3046
+ W && ((V = v.sources) != null && V.length) ? Yt(v.content, v.sources.length) : v.content
3047
+ );
3048
+ }, { offsetY: ce } = Un(
3049
+ I,
2679
3050
  u,
2680
- T
2681
- ), z = J !== 0, ae = typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(prefers-reduced-motion: reduce)").matches : !1;
2682
- W(() => {
2683
- const h = L.current;
2684
- h && (h.scrollTop = h.scrollHeight);
2685
- }, [e, t]), W(() => {
2686
- const h = (P) => {
2687
- P.key === "Escape" && !P.isComposing && !P.defaultPrevented && u();
3051
+ k
3052
+ ), de = ce !== 0, fe = typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(prefers-reduced-motion: reduce)").matches : !1;
3053
+ H(() => {
3054
+ const v = I.current;
3055
+ v && (v.scrollTop = v.scrollHeight);
3056
+ }, [e, t]), H(() => {
3057
+ const v = (V) => {
3058
+ V.key === "Escape" && !V.isComposing && !V.defaultPrevented && u();
2688
3059
  };
2689
- return document.addEventListener("keydown", h), () => document.removeEventListener("keydown", h);
3060
+ return document.addEventListener("keydown", v), () => document.removeEventListener("keydown", v);
2690
3061
  }, [u]);
2691
- const ie = (p == null ? void 0 : p.closeChat) ?? "Close chat", ce = (p == null ? void 0 : p.chatMessages) ?? "Chat messages", re = [...e].reverse().find((h) => h.role === "assistant");
2692
- return /* @__PURE__ */ w(
3062
+ const E = (d == null ? void 0 : d.closeChat) ?? "Close chat", B = (d == null ? void 0 : d.chatMessages) ?? "Chat messages", P = [...e].reverse().find((v) => v.role === "assistant");
3063
+ return /* @__PURE__ */ g(
2693
3064
  "div",
2694
3065
  {
2695
- ref: $,
3066
+ ref: N,
2696
3067
  role: "dialog",
2697
- "aria-modal": T ? "true" : void 0,
2698
- "aria-labelledby": C,
2699
- className: T ? "claudius-bottom-sheet fixed inset-x-0 bottom-0 z-50 flex h-[90vh] w-full flex-col overflow-hidden rounded-t-claudius-lg bg-claudius-surface shadow-claudius-elevated font-body" : `fixed ${Vn[f]} z-50 flex h-[min(500px,calc(100vh-7rem))] w-[calc(100vw-1.5rem)] max-w-[380px] sm:max-w-[400px] md:max-w-[440px] flex-col overflow-hidden rounded-claudius-lg bg-claudius-surface shadow-claudius-elevated font-body`,
2700
- style: T && !ae ? { transform: `translateY(${Math.max(0, J)}px)` } : void 0,
2701
- "data-dragging": z || void 0,
3068
+ "aria-modal": k ? "true" : void 0,
3069
+ "aria-labelledby": S,
3070
+ className: k ? "claudius-bottom-sheet fixed inset-x-0 bottom-0 z-50 flex h-[90vh] w-full flex-col overflow-hidden rounded-t-claudius-lg bg-claudius-surface shadow-claudius-elevated font-body" : `fixed ${fr[h]} z-50 flex h-[min(500px,calc(100vh-7rem))] w-[calc(100vw-1.5rem)] max-w-[380px] sm:max-w-[400px] md:max-w-[440px] flex-col overflow-hidden rounded-claudius-lg bg-claudius-surface shadow-claudius-elevated font-body`,
3071
+ style: k && !fe ? { transform: `translateY(${Math.max(0, ce)}px)` } : void 0,
3072
+ "data-dragging": de || void 0,
2702
3073
  children: [
2703
- T && /* @__PURE__ */ i("div", { className: "flex justify-center py-2", "aria-hidden": "true", children: /* @__PURE__ */ i("div", { className: "h-1 w-8 rounded-claudius-full bg-claudius-border" }) }),
3074
+ k && /* @__PURE__ */ i("div", { className: "flex justify-center py-2", "aria-hidden": "true", children: /* @__PURE__ */ i("div", { className: "h-1 w-8 rounded-claudius-full bg-claudius-border" }) }),
2704
3075
  /* @__PURE__ */ i(
2705
- gn,
3076
+ On,
2706
3077
  {
2707
- title: d,
2708
- subtitle: x,
2709
- titleId: C,
2710
- closeLabel: ie,
3078
+ title: f,
3079
+ subtitle: T,
3080
+ titleId: S,
3081
+ closeLabel: E,
2711
3082
  onClose: u,
2712
3083
  actions: y ? /* @__PURE__ */ i(
2713
- xn,
3084
+ Pn,
2714
3085
  {
2715
- label: (p == null ? void 0 : p.moreOptions) ?? "More options",
2716
- items: G.items,
2717
- onOpen: G.clearStatus
3086
+ label: (d == null ? void 0 : d.moreOptions) ?? "More options",
3087
+ items: Z.items,
3088
+ onOpen: Z.clearStatus
2718
3089
  }
2719
3090
  ) : void 0
2720
3091
  }
2721
3092
  ),
2722
- /* @__PURE__ */ w("div", { className: "relative flex-1 overflow-hidden", children: [
2723
- E && /* @__PURE__ */ i(
2724
- mn,
3093
+ /* @__PURE__ */ g("div", { className: "relative flex-1 overflow-hidden", children: [
3094
+ R && /* @__PURE__ */ i(
3095
+ In,
2725
3096
  {
2726
- sources: E.sources,
2727
- onClose: () => B(null)
3097
+ sources: R.sources,
3098
+ onClose: () => ne(null)
2728
3099
  }
2729
3100
  ),
2730
3101
  y && /* @__PURE__ */ i(
@@ -2732,69 +3103,71 @@ function Yn({
2732
3103
  {
2733
3104
  role: "status",
2734
3105
  className: "pointer-events-none absolute inset-x-0 top-2 z-10 flex justify-center px-4",
2735
- children: G.status && /* @__PURE__ */ i("span", { className: "rounded-claudius-full bg-claudius-text px-3 py-1 text-xs text-claudius-surface shadow-claudius-elevated", children: G.status })
3106
+ children: Z.status && /* @__PURE__ */ i("span", { className: "rounded-claudius-full bg-claudius-text px-3 py-1 text-xs text-claudius-surface shadow-claudius-elevated", children: Z.status })
2736
3107
  }
2737
3108
  ),
2738
- /* @__PURE__ */ w(
3109
+ /* @__PURE__ */ g(
2739
3110
  "div",
2740
3111
  {
2741
- ref: L,
3112
+ ref: I,
2742
3113
  role: "log",
2743
- "aria-label": ce,
3114
+ "aria-label": B,
2744
3115
  className: "h-full space-y-3 overflow-y-auto px-4 py-4",
2745
3116
  children: [
2746
3117
  e.length === 0 && !o && /* @__PURE__ */ i("div", { className: "mr-auto flex max-w-[85%]", children: /* @__PURE__ */ i("div", { className: "rounded-claudius-bubble rounded-bl-claudius-tail bg-claudius-assistant-bubble px-4 py-2.5 text-sm leading-relaxed text-claudius-assistant-bubble-text", children: A }) }),
2747
- e.map((h) => /* @__PURE__ */ i(
2748
- Qt,
3118
+ e.map((v) => /* @__PURE__ */ i(
3119
+ bn,
2749
3120
  {
2750
- role: h.role,
2751
- content: h.content,
2752
- isStreaming: h.id === r,
2753
- sources: h.sources,
2754
- attachments: h.attachments,
2755
- toolUses: h.toolUses,
2756
- toolUsedLabel: p == null ? void 0 : p.toolUsed,
2757
- toolDetailsLabel: p == null ? void 0 : p.toolDetails,
2758
- isSourceActive: (E == null ? void 0 : E.messageId) === h.id,
2759
- onSourceClick: () => {
2760
- (E == null ? void 0 : E.messageId) === h.id ? B(null) : h.sources && h.sources.length > 0 && B({ messageId: h.id, sources: h.sources });
3121
+ role: v.role,
3122
+ content: v.content,
3123
+ isStreaming: v.id === r,
3124
+ sources: v.sources,
3125
+ attachments: v.attachments,
3126
+ toolUses: v.toolUses,
3127
+ toolUsedLabel: d == null ? void 0 : d.toolUsed,
3128
+ toolDetailsLabel: d == null ? void 0 : d.toolDetails,
3129
+ citations: W,
3130
+ linkNewTabLabel: J,
3131
+ isSourceActive: W ? void 0 : (R == null ? void 0 : R.messageId) === v.id,
3132
+ onSourceClick: W ? void 0 : () => {
3133
+ (R == null ? void 0 : R.messageId) === v.id ? ne(null) : v.sources && v.sources.length > 0 && ne({
3134
+ messageId: v.id,
3135
+ sources: v.sources
3136
+ });
2761
3137
  },
2762
3138
  speech: (
2763
3139
  // Only settled replies with something to say: reading a
2764
3140
  // message that is still streaming would stop mid-sentence.
2765
- _ && h.role === "assistant" && h.id !== r && h.content.trim() !== "" ? {
2766
- state: O.activeId !== h.id ? "idle" : O.isPaused ? "paused" : "speaking",
2767
- labels: q,
3141
+ z && v.role === "assistant" && v.id !== r && v.content.trim() !== "" ? {
3142
+ state: $.activeId !== v.id ? "idle" : $.isPaused ? "paused" : "speaking",
3143
+ labels: X,
2768
3144
  // Same cleanup as the screen-reader announcement:
2769
3145
  // no literal asterisks, URLs shortened to hostnames.
2770
- onPlay: () => O.speak(
2771
- h.id,
2772
- Ye(h.content)
2773
- ),
2774
- onPause: O.pause,
2775
- onResume: O.resume,
2776
- onStop: O.cancel
3146
+ onPlay: () => $.speak(v.id, G(v)),
3147
+ onPause: $.pause,
3148
+ onResume: $.resume,
3149
+ onStop: $.cancel
2777
3150
  } : void 0
2778
3151
  )
2779
3152
  },
2780
- h.id
3153
+ v.id
2781
3154
  )),
2782
3155
  t && /* Once streamed tokens are rendering in a bubble, the typing
2783
3156
  indicator is redundant — show it only until the first token.
2784
3157
  A tool-only placeholder (no text yet) keeps the indicator. */
2785
3158
  !(r !== null && e.some(
2786
- (h) => h.id === r && h.content.length > 0
3159
+ (v) => v.id === r && v.content.length > 0
2787
3160
  )) && /* @__PURE__ */ i(
2788
- yn,
3161
+ jn,
2789
3162
  {
2790
- label: (p == null ? void 0 : p.typingIndicator) ?? "Assistant is typing"
3163
+ label: (d == null ? void 0 : d.typingIndicator) ?? "Assistant is typing"
2791
3164
  }
2792
3165
  ),
2793
3166
  o && /* @__PURE__ */ i(
2794
- bn,
3167
+ $n,
2795
3168
  {
2796
3169
  message: o,
2797
- retryLabel: (p == null ? void 0 : p.errorRetry) ?? "Retry",
3170
+ retryLabel: (d == null ? void 0 : d.errorRetry) ?? "Retry",
2798
3171
  onRetry: s && l && !t ? l : void 0
2799
3172
  }
2800
3173
  )
@@ -2809,29 +3182,29 @@ function Yn({
2809
3182
  "aria-live": "polite",
2810
3183
  "aria-atomic": "true",
2811
3184
  className: "sr-only",
2812
- children: re && re.id !== r ? Ye(re.content) : ""
3185
+ children: P && P.id !== r ? G(P) : ""
2813
3186
  }
2814
3187
  ),
2815
3188
  /* @__PURE__ */ i(
2816
- dn,
3189
+ Nn,
2817
3190
  {
2818
3191
  onSend: a,
2819
3192
  isLoading: t,
2820
3193
  isStreaming: n,
2821
3194
  onStop: c,
2822
- placeholder: g,
2823
- translations: p,
3195
+ placeholder: m,
3196
+ translations: d,
2824
3197
  attachments: b,
2825
- voice: R,
2826
- onVoiceStart: O.cancel,
2827
- isReadingAloud: O.activeId !== null
3198
+ voice: x,
3199
+ onVoiceStart: $.cancel,
3200
+ isReadingAloud: $.activeId !== null
2828
3201
  }
2829
3202
  )
2830
3203
  ]
2831
3204
  }
2832
3205
  );
2833
3206
  }
2834
- function qn({
3207
+ function pr({
2835
3208
  message: e,
2836
3209
  position: t,
2837
3210
  onOpen: n,
@@ -2844,7 +3217,7 @@ function qn({
2844
3217
  s ? "bottom-20" : "top-20",
2845
3218
  a ? "right-4" : "left-4"
2846
3219
  ].join(" ");
2847
- return /* @__PURE__ */ w("div", { className: c, role: "status", "aria-live": "polite", children: [
3220
+ return /* @__PURE__ */ g("div", { className: c, role: "status", "aria-live": "polite", children: [
2848
3221
  /* @__PURE__ */ i(
2849
3222
  "button",
2850
3223
  {
@@ -2868,7 +3241,7 @@ function qn({
2868
3241
  )
2869
3242
  ] });
2870
3243
  }
2871
- const Zn = {
3244
+ const mr = {
2872
3245
  // ChatWindow
2873
3246
  title: "Chat",
2874
3247
  subtitle: "Pregúntame lo que quieras",
@@ -2920,6 +3293,12 @@ const Zn = {
2920
3293
  transcriptAssistant: "Asistente",
2921
3294
  transcriptAttachments: "Adjuntos:",
2922
3295
  transcriptSources: "Fuentes:",
3296
+ // Citations
3297
+ sources: "Fuentes",
3298
+ showAllSources: "Mostrar todas ({count})",
3299
+ showFewerSources: "Mostrar menos",
3300
+ citation: "Fuente {n}: {title}",
3301
+ opensInNewTab: "(se abre en una pestaña nueva)",
2923
3302
  // Errors
2924
3303
  errorGeneric: "Algo salió mal. Inténtalo de nuevo.",
2925
3304
  errorConnection: "No se pudo conectar. Inténtalo de nuevo.",
@@ -2929,7 +3308,7 @@ const Zn = {
2929
3308
  errorAttachmentRejected: "Se rechazó un adjunto. Quítalo e inténtalo de nuevo.",
2930
3309
  errorAttachmentQuota: "Límite de subida alcanzado. Inténtalo más tarde.",
2931
3310
  errorRetry: "Reintentar"
2932
- }, Jn = {
3311
+ }, gr = {
2933
3312
  // ChatWindow
2934
3313
  title: "Chat",
2935
3314
  subtitle: "Posez-moi vos questions",
@@ -2981,6 +3360,12 @@ const Zn = {
2981
3360
  transcriptAssistant: "Assistant",
2982
3361
  transcriptAttachments: "Pièces jointes :",
2983
3362
  transcriptSources: "Sources :",
3363
+ // Citations
3364
+ sources: "Sources",
3365
+ showAllSources: "Tout afficher ({count})",
3366
+ showFewerSources: "Afficher moins",
3367
+ citation: "Source {n} : {title}",
3368
+ opensInNewTab: "(s'ouvre dans un nouvel onglet)",
2984
3369
  // Errors
2985
3370
  errorGeneric: "Une erreur s'est produite. Veuillez réessayer.",
2986
3371
  errorConnection: "Échec de la connexion. Veuillez réessayer.",
@@ -2990,7 +3375,7 @@ const Zn = {
2990
3375
  errorAttachmentRejected: "Une pièce jointe a été refusée. Retirez-la et réessayez.",
2991
3376
  errorAttachmentQuota: "Limite d'envoi atteinte. Veuillez réessayer plus tard.",
2992
3377
  errorRetry: "Réessayer"
2993
- }, Qn = {
3378
+ }, br = {
2994
3379
  // ChatWindow
2995
3380
  title: "Chat",
2996
3381
  subtitle: "Fragen Sie mich alles",
@@ -3042,6 +3427,12 @@ const Zn = {
3042
3427
  transcriptAssistant: "Assistent",
3043
3428
  transcriptAttachments: "Anhänge:",
3044
3429
  transcriptSources: "Quellen:",
3430
+ // Citations
3431
+ sources: "Quellen",
3432
+ showAllSources: "Alle anzeigen ({count})",
3433
+ showFewerSources: "Weniger anzeigen",
3434
+ citation: "Quelle {n}: {title}",
3435
+ opensInNewTab: "(öffnet in einem neuen Tab)",
3045
3436
  // Errors
3046
3437
  errorGeneric: "Etwas ist schiefgelaufen. Bitte versuchen Sie es erneut.",
3047
3438
  errorConnection: "Verbindung fehlgeschlagen. Bitte versuchen Sie es erneut.",
@@ -3051,28 +3442,28 @@ const Zn = {
3051
3442
  errorAttachmentRejected: "Ein Anhang wurde abgelehnt. Bitte entfernen Sie ihn und versuchen Sie es erneut.",
3052
3443
  errorAttachmentQuota: "Upload-Limit erreicht. Bitte versuchen Sie es später erneut.",
3053
3444
  errorRetry: "Erneut versuchen"
3054
- }, at = {
3055
- en: nt,
3056
- es: Zn,
3057
- fr: Jn,
3058
- de: Qn
3445
+ }, lt = {
3446
+ en: st,
3447
+ es: mr,
3448
+ fr: gr,
3449
+ de: br
3059
3450
  };
3060
- function qe(e) {
3451
+ function Ze(e) {
3061
3452
  if (!e) return;
3062
3453
  const t = e.toLowerCase().split("-")[0];
3063
- return Object.prototype.hasOwnProperty.call(at, t) ? t : void 0;
3454
+ return Object.prototype.hasOwnProperty.call(lt, t) ? t : void 0;
3064
3455
  }
3065
- function it() {
3066
- const e = typeof document < "u" ? qe(document.documentElement.lang) : void 0;
3456
+ function ut() {
3457
+ const e = typeof document < "u" ? Ze(document.documentElement.lang) : void 0;
3067
3458
  if (e) return e;
3068
- const t = typeof navigator < "u" ? qe(navigator.language) : void 0;
3459
+ const t = typeof navigator < "u" ? Ze(navigator.language) : void 0;
3069
3460
  return t || "en";
3070
3461
  }
3071
- function Xn(e = {}) {
3072
- const { locale: t, translations: n } = e, r = at[t ?? it()];
3462
+ function yr(e = {}) {
3463
+ const { locale: t, translations: n } = e, r = lt[t ?? ut()];
3073
3464
  return n ? { ...r, ...n } : { ...r };
3074
3465
  }
3075
- const Ze = [
3466
+ const Je = [
3076
3467
  "accent",
3077
3468
  "accentText",
3078
3469
  "accentSoft",
@@ -3092,11 +3483,11 @@ const Ze = [
3092
3483
  "errorText",
3093
3484
  "link",
3094
3485
  "scrim"
3095
- ], er = ["sm", "md", "lg", "full", "tail"], tr = [
3486
+ ], wr = ["sm", "md", "lg", "full", "tail"], xr = [
3096
3487
  "elevated",
3097
3488
  "floating",
3098
3489
  "floatingHover"
3099
- ], nr = ["heading", "body"], ct = {
3490
+ ], vr = ["heading", "body"], dt = {
3100
3491
  default: {
3101
3492
  name: "default"
3102
3493
  },
@@ -3181,62 +3572,62 @@ const Ze = [
3181
3572
  }
3182
3573
  }
3183
3574
  };
3184
- function rr(e) {
3185
- return Object.prototype.hasOwnProperty.call(ct, e);
3575
+ function Sr(e) {
3576
+ return Object.prototype.hasOwnProperty.call(dt, e);
3186
3577
  }
3187
- const or = /* @__PURE__ */ new Set(["light", "dark", "auto"]);
3188
- function sr(e) {
3578
+ const Tr = /* @__PURE__ */ new Set(["light", "dark", "auto"]);
3579
+ function Ar(e) {
3189
3580
  if (e === void 0)
3190
3581
  return { mode: "light" };
3191
3582
  if (typeof e == "string") {
3192
- if (or.has(e))
3583
+ if (Tr.has(e))
3193
3584
  return { mode: e };
3194
- if (rr(e)) {
3195
- const t = ct[e];
3585
+ if (Sr(e)) {
3586
+ const t = dt[e];
3196
3587
  return { mode: t.colorScheme ?? "light", theme: t };
3197
3588
  }
3198
3589
  return { mode: "light", url: e };
3199
3590
  }
3200
3591
  return { mode: e.colorScheme ?? "light", theme: e };
3201
3592
  }
3202
- function ar(e) {
3593
+ function kr(e) {
3203
3594
  return e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`);
3204
3595
  }
3205
- function ir(e, t) {
3596
+ function Rr(e, t) {
3206
3597
  console.warn(
3207
3598
  `[Claudius] Ignoring unknown theme token "${t}" in "${e}"`
3208
3599
  );
3209
3600
  }
3210
- function we(e, t, n, r, o, s = "") {
3601
+ function Se(e, t, n, r, o, s = "") {
3211
3602
  if (o)
3212
3603
  for (const [a, c] of Object.entries(o)) {
3213
3604
  if (!r.includes(a)) {
3214
- ir(t, a);
3605
+ Rr(t, a);
3215
3606
  continue;
3216
3607
  }
3217
- typeof c == "string" && (e[`${n}${ar(a)}${s}`] = c);
3608
+ typeof c == "string" && (e[`${n}${kr(a)}${s}`] = c);
3218
3609
  }
3219
3610
  }
3220
- function cr(e) {
3611
+ function Er(e) {
3221
3612
  const t = {};
3222
- we(t, "colors", "--cl-color-", Ze, e.colors);
3613
+ Se(t, "colors", "--cl-color-", Je, e.colors);
3223
3614
  for (const [n, r] of Object.entries({ ...t }))
3224
3615
  t[`${n}-dark`] = r;
3225
- return we(
3616
+ return Se(
3226
3617
  t,
3227
3618
  "colorsDark",
3228
3619
  "--cl-color-",
3229
- Ze,
3620
+ Je,
3230
3621
  e.colorsDark,
3231
3622
  "-dark"
3232
- ), we(t, "radii", "--cl-radius-", er, e.radii), we(t, "shadows", "--cl-shadow-", tr, e.shadows), we(t, "fonts", "--cl-font-", nr, e.fonts), t;
3623
+ ), Se(t, "radii", "--cl-radius-", wr, e.radii), Se(t, "shadows", "--cl-shadow-", xr, e.shadows), Se(t, "fonts", "--cl-font-", vr, e.fonts), t;
3233
3624
  }
3234
- function lr(e) {
3625
+ function Cr(e) {
3235
3626
  return typeof e == "object" && e !== null && !Array.isArray(e);
3236
3627
  }
3237
- function ur(e) {
3238
- const t = se(() => sr(e), [e]), [n, r] = N(null), o = t.url;
3239
- W(() => {
3628
+ function Nr(e) {
3629
+ const t = ae(() => Ar(e), [e]), [n, r] = M(null), o = t.url;
3630
+ H(() => {
3240
3631
  if (r(null), !o) return;
3241
3632
  const l = new AbortController();
3242
3633
  return fetch(o, { signal: l.signal }).then((u) => {
@@ -3244,36 +3635,36 @@ function ur(e) {
3244
3635
  throw new Error(`HTTP ${u.status}`);
3245
3636
  return u.json();
3246
3637
  }).then((u) => {
3247
- if (!lr(u))
3638
+ if (!Cr(u))
3248
3639
  throw new Error("theme JSON must be an object");
3249
3640
  r(u);
3250
3641
  }).catch((u) => {
3251
3642
  l.signal.aborted || console.error(`[Claudius] Failed to load theme from ${o}:`, u);
3252
3643
  }), () => l.abort();
3253
3644
  }, [o]);
3254
- const s = t.theme ?? n ?? null, a = (n == null ? void 0 : n.colorScheme) ?? t.mode, c = se(
3255
- () => s ? cr(s) : {},
3645
+ const s = t.theme ?? n ?? null, a = (n == null ? void 0 : n.colorScheme) ?? t.mode, c = ae(
3646
+ () => s ? Er(s) : {},
3256
3647
  [s]
3257
3648
  );
3258
3649
  return { mode: a, cssVars: c };
3259
3650
  }
3260
- const lt = "claudius:triggers:dismissed";
3261
- function dr() {
3651
+ const ft = "claudius:triggers:dismissed";
3652
+ function Mr() {
3262
3653
  if (typeof window > "u") return !1;
3263
3654
  try {
3264
- return window.sessionStorage.getItem(lt) === "1";
3655
+ return window.sessionStorage.getItem(ft) === "1";
3265
3656
  } catch {
3266
3657
  return !1;
3267
3658
  }
3268
3659
  }
3269
- function fr() {
3660
+ function Lr() {
3270
3661
  if (!(typeof window > "u"))
3271
3662
  try {
3272
- window.sessionStorage.setItem(lt, "1");
3663
+ window.sessionStorage.setItem(ft, "1");
3273
3664
  } catch {
3274
3665
  }
3275
3666
  }
3276
- function wr({
3667
+ function Br({
3277
3668
  apiUrl: e,
3278
3669
  title: t,
3279
3670
  subtitle: n,
@@ -3284,148 +3675,154 @@ function wr({
3284
3675
  requestTimeoutMs: c,
3285
3676
  theme: l = "light",
3286
3677
  accentColor: u,
3287
- position: d = "bottom-right",
3288
- locale: x,
3678
+ position: f = "bottom-right",
3679
+ locale: T,
3289
3680
  translations: A,
3290
- triggers: g,
3291
- plugins: f,
3292
- streaming: p = !0,
3293
- attachments: T = !1,
3681
+ triggers: m,
3682
+ plugins: h,
3683
+ streaming: d = !0,
3684
+ attachments: k = !1,
3294
3685
  voice: b = !1,
3295
- conversationExport: R = !1
3686
+ conversationExport: x = !1,
3687
+ citations: y = !1
3296
3688
  }) {
3297
- const [y, v] = N(!1), C = se(
3298
- () => wt(T),
3299
- [T]
3300
- ), $ = se(() => x ?? it(), [x]), L = se(
3301
- () => rn(b, $),
3302
- [b, $]
3303
- ), E = se(
3304
- () => rt($),
3305
- [$]
3306
- ), [B, O] = N(null), [_, q] = N(dr), G = S(!1), J = Ot("(max-width: 639px)"), z = se(
3307
- () => Xn({ locale: x, translations: A }),
3308
- [x, A]
3689
+ const [w, D] = M(!1), S = ae(
3690
+ () => At(k),
3691
+ [k]
3692
+ ), N = ae(() => T ?? ut(), [T]), I = ae(
3693
+ () => Sn(b, N),
3694
+ [b, N]
3695
+ ), R = ae(
3696
+ () => Vt(y),
3697
+ [y]
3698
+ ), ne = ae(
3699
+ () => at(N),
3700
+ [N]
3701
+ ), [$, z] = M(null), [X, Z] = M(Mr), J = C(!1), W = Ut("(max-width: 639px)"), G = ae(
3702
+ () => yr({ locale: T, translations: A }),
3703
+ [T, A]
3309
3704
  ), {
3310
- messages: ae,
3311
- isLoading: ie,
3312
- isStreaming: ce,
3313
- streamingMessageId: re,
3314
- error: h,
3705
+ messages: ce,
3706
+ isLoading: de,
3707
+ isStreaming: fe,
3708
+ streamingMessageId: E,
3709
+ error: B,
3315
3710
  canRetry: P,
3316
- sendMessage: U,
3317
- stop: ee,
3318
- retry: te
3319
- } = It({
3711
+ sendMessage: v,
3712
+ stop: V,
3713
+ retry: K
3714
+ } = Pt({
3320
3715
  apiUrl: e,
3321
3716
  persistMessages: s,
3322
3717
  storageKeyPrefix: a,
3323
3718
  timeoutMs: c,
3324
- translations: z,
3325
- plugins: f,
3326
- streaming: p
3327
- }), ne = S(null), F = S(y), { mode: H, cssVars: k } = ur(l), [D, I] = N(!1);
3328
- W(() => {
3329
- if (H !== "auto") return;
3330
- const X = window.matchMedia("(prefers-color-scheme: dark)");
3331
- I(X.matches);
3332
- const Me = (m) => I(m.matches);
3333
- return X.addEventListener("change", Me), () => X.removeEventListener("change", Me);
3334
- }, [H]), W(() => {
3335
- var X;
3336
- F.current && !y && ((X = ne.current) == null || X.focus()), F.current = y;
3337
- }, [y]);
3338
- const K = M(() => {
3339
- q(!0), fr();
3340
- }, []), Q = M(() => {
3341
- v(!1), G.current && (G.current = !1, K());
3342
- }, [K]), le = M(() => {
3343
- v((X) => !X);
3344
- }, []), Y = M(() => {
3345
- G.current = !0, O(null), v(!0);
3346
- }, []), me = M((X) => {
3347
- O(X);
3348
- }, []), ue = M(() => {
3349
- O(null), Y();
3350
- }, [Y]), V = M(() => {
3351
- O(null), K();
3352
- }, [K]);
3353
- $t({
3354
- triggers: g,
3355
- enabled: !_ && !y,
3356
- onOpen: Y,
3357
- onGreeting: me
3719
+ translations: G,
3720
+ plugins: h,
3721
+ streaming: d,
3722
+ citations: R !== null
3723
+ }), oe = C(null), F = C(w), { mode: ee, cssVars: te } = Nr(l), [L, _] = M(!1);
3724
+ H(() => {
3725
+ if (ee !== "auto") return;
3726
+ const p = window.matchMedia("(prefers-color-scheme: dark)");
3727
+ _(p.matches);
3728
+ const j = (ue) => _(ue.matches);
3729
+ return p.addEventListener("change", j), () => p.removeEventListener("change", j);
3730
+ }, [ee]), H(() => {
3731
+ var p;
3732
+ F.current && !w && ((p = oe.current) == null || p.focus()), F.current = w;
3733
+ }, [w]);
3734
+ const U = O(() => {
3735
+ Z(!0), Lr();
3736
+ }, []), Y = O(() => {
3737
+ D(!1), J.current && (J.current = !1, U());
3738
+ }, [U]), se = O(() => {
3739
+ D((p) => !p);
3740
+ }, []), le = O(() => {
3741
+ J.current = !0, z(null), D(!0);
3742
+ }, []), re = O((p) => {
3743
+ z(p);
3744
+ }, []), ye = O(() => {
3745
+ z(null), le();
3746
+ }, [le]), me = O(() => {
3747
+ z(null), U();
3748
+ }, [U]);
3749
+ Ft({
3750
+ triggers: m,
3751
+ enabled: !X && !w,
3752
+ onOpen: le,
3753
+ onGreeting: re
3358
3754
  });
3359
- const oe = H === "dark" || H === "auto" && D, ge = {
3360
- ...k,
3755
+ const q = ee === "dark" || ee === "auto" && L, ie = {
3756
+ ...te,
3361
3757
  ...u ? {
3362
3758
  "--cl-color-accent": u,
3363
3759
  "--cl-color-accent-dark": u
3364
3760
  } : {}
3365
- }, de = Object.keys(ge).length > 0 ? ge : void 0;
3761
+ }, he = Object.keys(ie).length > 0 ? ie : void 0;
3366
3762
  return (
3367
3763
  // Outer div carries theme token vars; the inner div carries the dark-mode
3368
3764
  // attribute so the [data-claudius-dark] token reassignments in styles.css
3369
3765
  // beat inherited (inline) light values.
3370
- /* @__PURE__ */ i("div", { className: "claudius-root", style: de, children: /* @__PURE__ */ w("div", { "data-claudius-dark": oe ? "true" : "false", children: [
3371
- y && J && /* @__PURE__ */ i(
3766
+ /* @__PURE__ */ i("div", { className: "claudius-root", style: he, children: /* @__PURE__ */ g("div", { "data-claudius-dark": q ? "true" : "false", children: [
3767
+ w && W && /* @__PURE__ */ i(
3372
3768
  "div",
3373
3769
  {
3374
3770
  className: "claudius-scrim fixed inset-0 z-40 bg-claudius-scrim",
3375
- onClick: Q,
3771
+ onClick: Y,
3376
3772
  "aria-hidden": "true"
3377
3773
  }
3378
3774
  ),
3379
- y && /* @__PURE__ */ i(
3380
- Yn,
3775
+ w && /* @__PURE__ */ i(
3776
+ hr,
3381
3777
  {
3382
- messages: ae,
3383
- isLoading: ie,
3384
- isStreaming: ce,
3385
- streamingMessageId: re,
3386
- error: h,
3778
+ messages: ce,
3779
+ isLoading: de,
3780
+ isStreaming: fe,
3781
+ streamingMessageId: E,
3782
+ error: B,
3387
3783
  canRetry: P,
3388
- onSend: U,
3389
- onStop: ee,
3390
- onRetry: te,
3391
- onClose: Q,
3392
- title: t ?? z.title,
3393
- subtitle: n ?? z.subtitle,
3394
- welcomeMessage: r ?? z.welcomeMessage,
3395
- placeholder: o ?? z.placeholder,
3396
- position: d,
3397
- translations: z,
3398
- isMobile: J,
3399
- attachments: C,
3400
- voice: L,
3401
- conversationExport: R === !0,
3402
- locale: E
3784
+ onSend: v,
3785
+ onStop: V,
3786
+ onRetry: K,
3787
+ onClose: Y,
3788
+ title: t ?? G.title,
3789
+ subtitle: n ?? G.subtitle,
3790
+ welcomeMessage: r ?? G.welcomeMessage,
3791
+ placeholder: o ?? G.placeholder,
3792
+ position: f,
3793
+ translations: G,
3794
+ isMobile: W,
3795
+ attachments: S,
3796
+ voice: I,
3797
+ conversationExport: x === !0,
3798
+ locale: ne,
3799
+ citations: R
3403
3800
  }
3404
3801
  ),
3405
- !(y && J) && /* @__PURE__ */ i(
3406
- Ut,
3802
+ !(w && W) && /* @__PURE__ */ i(
3803
+ Ht,
3407
3804
  {
3408
- ref: ne,
3409
- isOpen: y,
3410
- onClick: le,
3411
- position: d,
3412
- translations: z
3805
+ ref: oe,
3806
+ isOpen: w,
3807
+ onClick: se,
3808
+ position: f,
3809
+ translations: G
3413
3810
  }
3414
3811
  ),
3415
- !y && B && /* @__PURE__ */ i(
3416
- qn,
3812
+ !w && $ && /* @__PURE__ */ i(
3813
+ pr,
3417
3814
  {
3418
- message: B,
3419
- position: d,
3420
- onOpen: ue,
3421
- onDismiss: V,
3422
- dismissLabel: z.dismissGreeting
3815
+ message: $,
3816
+ position: f,
3817
+ onOpen: ye,
3818
+ onDismiss: me,
3819
+ dismissLabel: G.dismissGreeting
3423
3820
  }
3424
3821
  )
3425
3822
  ] }) })
3426
3823
  );
3427
3824
  }
3428
- function vr(e) {
3825
+ function Fr(e) {
3429
3826
  const { onEvent: t, includeContent: n = !0 } = e, r = (o) => n ? o : "";
3430
3827
  return {
3431
3828
  name: "analytics",
@@ -3454,7 +3851,7 @@ function vr(e) {
3454
3851
  }
3455
3852
  };
3456
3853
  }
3457
- const hr = [
3854
+ const Dr = [
3458
3855
  // Email
3459
3856
  /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g,
3460
3857
  // US SSN (before the looser card pattern so it wins on 9-digit groups)
@@ -3464,20 +3861,20 @@ const hr = [
3464
3861
  // Phone: optional +1, area code, 7 digits with common separators
3465
3862
  /\b(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b/g
3466
3863
  ];
3467
- function pr(e, t, n) {
3864
+ function Ir(e, t, n) {
3468
3865
  return t.reduce(
3469
3866
  // Reset lastIndex defensively: a shared global regex is stateful.
3470
3867
  (r, o) => (o.lastIndex = 0, r.replace(o, n)),
3471
3868
  e
3472
3869
  );
3473
3870
  }
3474
- function Tr(e = {}) {
3871
+ function _r(e = {}) {
3475
3872
  const {
3476
- patterns: t = hr,
3873
+ patterns: t = Dr,
3477
3874
  replacement: n = "[redacted]",
3478
3875
  redactReplies: r = !1
3479
3876
  } = e, o = (s) => {
3480
- const a = pr(s.content, t, n);
3877
+ const a = Ir(s.content, t, n);
3481
3878
  if (a !== s.content)
3482
3879
  return { ...s, content: a };
3483
3880
  };
@@ -3487,16 +3884,16 @@ function Tr(e = {}) {
3487
3884
  onAfterReceive: r ? o : void 0
3488
3885
  };
3489
3886
  }
3490
- function mr(e, t, n) {
3887
+ function Or(e, t, n) {
3491
3888
  return typeof e == "function" ? e(t) : e instanceof RegExp ? e.test(t) : n ? t.includes(e) : t.toLowerCase().includes(e.toLowerCase());
3492
3889
  }
3493
- function Er(e) {
3890
+ function Hr(e) {
3494
3891
  const { rules: t, caseSensitive: n = !1 } = e;
3495
3892
  return {
3496
3893
  name: "canned-responses",
3497
3894
  onBeforeSend(r, o) {
3498
3895
  for (const s of t)
3499
- if (mr(s.match, r.content, n)) {
3896
+ if (Or(s.match, r.content, n)) {
3500
3897
  o.respondWith(s.reply);
3501
3898
  return;
3502
3899
  }
@@ -3504,20 +3901,21 @@ function Er(e) {
3504
3901
  };
3505
3902
  }
3506
3903
  export {
3507
- mt as ChatApiClient,
3508
- Z as ChatApiError,
3509
- wr as ChatWidget,
3510
- Te as DEFAULT_ATTACHMENT_OPTIONS,
3511
- hr as DEFAULT_PII_PATTERNS,
3904
+ wt as ChatApiClient,
3905
+ Q as ChatApiError,
3906
+ Br as ChatWidget,
3907
+ Re as DEFAULT_ATTACHMENT_OPTIONS,
3908
+ Gt as DEFAULT_CITATIONS_OPTIONS,
3909
+ Dr as DEFAULT_PII_PATTERNS,
3512
3910
  De as DebounceError,
3513
- ct as builtinThemes,
3514
- xr as createTranslations,
3515
- Oe as defaultTranslations,
3516
- it as detectLocale,
3517
- at as locales,
3518
- vr as pluginAnalytics,
3519
- Er as pluginCannedResponses,
3520
- Tr as pluginRedactPII,
3521
- pr as redactText,
3522
- Xn as resolveTranslations
3911
+ dt as builtinThemes,
3912
+ Ur as createTranslations,
3913
+ je as defaultTranslations,
3914
+ ut as detectLocale,
3915
+ lt as locales,
3916
+ Fr as pluginAnalytics,
3917
+ Hr as pluginCannedResponses,
3918
+ _r as pluginRedactPII,
3919
+ Ir as redactText,
3920
+ yr as resolveTranslations
3523
3921
  };