claudius-chat-widget 1.12.0 → 1.13.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 Se = Object.defineProperty;
2
- var Ce = (t, e, r) => e in t ? Se(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var q = (t, e, r) => Ce(t, typeof e != "symbol" ? e + "" : e, r);
4
- import { jsx as a, jsxs as b, Fragment as Ne } from "react/jsx-runtime";
5
- import { useMemo as ne, useState as A, useRef as O, useCallback as L, useEffect as U, forwardRef as ke, memo as ue, useId as Le } from "react";
6
- class H extends Error {
1
+ var Ce = Object.defineProperty;
2
+ var Ne = (e, t, r) => t in e ? Ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var X = (e, t, r) => Ne(e, typeof t != "symbol" ? t + "" : t, r);
4
+ import { jsx as a, jsxs as g, Fragment as xe } from "react/jsx-runtime";
5
+ import { useMemo as se, useState as L, useRef as I, useCallback as O, useEffect as z, forwardRef as ke, memo as de, useId as Le } from "react";
6
+ class j extends Error {
7
7
  /**
8
8
  * Create a {@link ChatApiError}.
9
9
  *
@@ -12,11 +12,11 @@ class H extends Error {
12
12
  * @param code - Optional machine-readable error code (e.g. `"TIMEOUT"`, `"NETWORK_ERROR"`).
13
13
  * @param retryAfter - Seconds to wait before retrying, from the `Retry-After` header.
14
14
  */
15
- constructor(e, r, n, s) {
16
- super(e), this.status = r, this.code = n, this.retryAfter = s, this.name = "ChatApiError";
15
+ constructor(t, r, n, s) {
16
+ super(t), this.status = r, this.code = n, this.retryAfter = s, this.name = "ChatApiError";
17
17
  }
18
18
  }
19
- class ae extends Error {
19
+ class le extends Error {
20
20
  /** Creates a `DebounceError` with a fixed message. */
21
21
  constructor() {
22
22
  super("Request debounced"), this.name = "DebounceError";
@@ -30,13 +30,13 @@ class Oe {
30
30
  * @param baseUrl - Base URL of the Worker. Requests post to `${baseUrl}/api/chat`.
31
31
  * @param options - Optional retry, debounce, and timeout settings.
32
32
  */
33
- constructor(e, r) {
34
- q(this, "baseUrl");
35
- q(this, "maxRetries");
36
- q(this, "debounceMs");
37
- q(this, "timeoutMs");
38
- q(this, "lastSendTime", 0);
39
- this.baseUrl = e, this.maxRetries = (r == null ? void 0 : r.maxRetries) ?? 2, this.debounceMs = (r == null ? void 0 : r.debounceMs) ?? 300, this.timeoutMs = (r == null ? void 0 : r.timeoutMs) ?? Ae;
33
+ constructor(t, r) {
34
+ X(this, "baseUrl");
35
+ X(this, "maxRetries");
36
+ X(this, "debounceMs");
37
+ X(this, "timeoutMs");
38
+ X(this, "lastSendTime", 0);
39
+ this.baseUrl = t, this.maxRetries = (r == null ? void 0 : r.maxRetries) ?? 2, this.debounceMs = (r == null ? void 0 : r.debounceMs) ?? 300, this.timeoutMs = (r == null ? void 0 : r.timeoutMs) ?? Ae;
40
40
  }
41
41
  /**
42
42
  * Send the conversation to the chat endpoint and return the assistant's
@@ -48,22 +48,22 @@ class Oe {
48
48
  * @throws {@link DebounceError} when called within the debounce window.
49
49
  * @throws {@link ChatApiError} when the request fails after all retries.
50
50
  */
51
- async sendMessage(e) {
51
+ async sendMessage(t) {
52
52
  if (this.debounceMs > 0 && Date.now() - this.lastSendTime < this.debounceMs)
53
- throw new ae();
53
+ throw new le();
54
54
  this.lastSendTime = Date.now();
55
55
  let r;
56
56
  for (let n = 0; n <= this.maxRetries; n++)
57
57
  try {
58
- const s = await this.fetchWithTimeout(e);
58
+ const s = await this.fetchWithTimeout(t);
59
59
  if (s.ok)
60
60
  return await s.json();
61
- const o = await s.json().catch(() => ({})), i = s.headers.get("Retry-After"), u = i ? Number(i) : void 0;
62
- if (r = new H(
61
+ const o = await s.json().catch(() => ({})), i = s.headers.get("Retry-After"), l = i ? Number(i) : void 0;
62
+ if (r = new j(
63
63
  o.error ?? `Request failed with status ${s.status}`,
64
64
  s.status,
65
65
  o.code,
66
- u
66
+ l
67
67
  ), !this.isRetryable(s.status))
68
68
  throw r;
69
69
  if (n < this.maxRetries) {
@@ -71,14 +71,14 @@ class Oe {
71
71
  await this.delay(c);
72
72
  }
73
73
  } catch (s) {
74
- if (s instanceof H) {
74
+ if (s instanceof j) {
75
75
  if (!this.isRetryable(s.status, s.code))
76
76
  throw s;
77
77
  if (r = s, n < this.maxRetries) {
78
78
  const o = this.getRetryDelay(null, n);
79
79
  await this.delay(o);
80
80
  }
81
- } else if (r = new H(
81
+ } else if (r = new j(
82
82
  "Failed to connect. Please try again.",
83
83
  0,
84
84
  "NETWORK_ERROR"
@@ -109,22 +109,22 @@ class Oe {
109
109
  * @throws {@link ChatApiError} when the request fails after all retries, or
110
110
  * the stream errors or is interrupted mid-reply (code `"STREAM_ERROR"`).
111
111
  */
112
- async streamMessage(e, r = {}) {
112
+ async streamMessage(t, r = {}) {
113
113
  var s;
114
114
  if (typeof ReadableStream > "u")
115
- return this.sendMessage(e);
115
+ return this.sendMessage(t);
116
116
  if (this.debounceMs > 0 && Date.now() - this.lastSendTime < this.debounceMs)
117
- throw new ae();
117
+ throw new le();
118
118
  this.lastSendTime = Date.now();
119
119
  let n;
120
120
  for (let o = 0; o <= this.maxRetries; o++) {
121
121
  let i;
122
122
  try {
123
- i = await this.fetchStream(e, r.signal);
123
+ i = await this.fetchStream(t, r.signal);
124
124
  } catch (c) {
125
125
  if ((s = r.signal) != null && s.aborted)
126
126
  return { reply: "", aborted: !0 };
127
- if (n = c instanceof H ? c : new H(
127
+ if (n = c instanceof j ? c : new j(
128
128
  "Failed to connect. Please try again.",
129
129
  0,
130
130
  "NETWORK_ERROR"
@@ -134,14 +134,14 @@ class Oe {
134
134
  continue;
135
135
  }
136
136
  if (i.status === 404 || i.status === 405)
137
- return this.lastSendTime = 0, this.sendMessage(e);
137
+ return this.lastSendTime = 0, this.sendMessage(t);
138
138
  if (!i.ok) {
139
- const c = await i.json().catch(() => ({})), l = i.headers.get("Retry-After");
140
- if (n = new H(
139
+ const c = await i.json().catch(() => ({})), u = i.headers.get("Retry-After");
140
+ if (n = new j(
141
141
  c.error ?? `Request failed with status ${i.status}`,
142
142
  i.status,
143
143
  c.code,
144
- l ? Number(l) : void 0
144
+ u ? Number(u) : void 0
145
145
  ), !this.isRetryable(i.status))
146
146
  throw n;
147
147
  o < this.maxRetries && await this.delay(this.getRetryDelay(i, o));
@@ -151,9 +151,9 @@ class Oe {
151
151
  try {
152
152
  return await i.json();
153
153
  } catch {
154
- return this.lastSendTime = 0, this.sendMessage(e);
154
+ return this.lastSendTime = 0, this.sendMessage(t);
155
155
  }
156
- return i.body ? this.readSseStream(i.body, r) : (this.lastSendTime = 0, this.sendMessage(e));
156
+ return i.body ? this.readSseStream(i.body, r) : (this.lastSendTime = 0, this.sendMessage(t));
157
157
  }
158
158
  throw n;
159
159
  }
@@ -162,45 +162,54 @@ class Oe {
162
162
  * `done`, throwing on `error` events or an interrupted connection, and
163
163
  * resolving with the partial text when the caller aborts.
164
164
  */
165
- async readSseStream(e, r) {
166
- var l, f, y, I, E, T;
167
- const n = e.getReader(), s = new TextDecoder();
168
- let o = "", i = "", u;
169
- const c = () => {
165
+ async readSseStream(t, r) {
166
+ var d, x, N, R, T, p, v;
167
+ const n = t.getReader(), s = new TextDecoder();
168
+ let o = "", i = "";
169
+ const l = [];
170
+ let c;
171
+ const u = () => {
170
172
  n.cancel().catch(() => {
171
173
  });
172
174
  };
173
- (l = r.signal) == null || l.addEventListener("abort", c, { once: !0 });
175
+ (d = r.signal) == null || d.addEventListener("abort", u, { once: !0 });
174
176
  try {
175
177
  for (; ; ) {
176
- let x;
178
+ let k;
177
179
  try {
178
- x = await n.read();
179
- } catch (C) {
180
- if ((f = r.signal) != null && f.aborted) break;
181
- throw C;
180
+ k = await n.read();
181
+ } catch (w) {
182
+ if ((x = r.signal) != null && x.aborted) break;
183
+ throw w;
182
184
  }
183
- if ((y = r.signal) != null && y.aborted || x.done) break;
184
- o += s.decode(x.value, { stream: !0 });
185
- let w;
186
- for (; (w = o.indexOf(`
185
+ if ((N = r.signal) != null && N.aborted || k.done) break;
186
+ o += s.decode(k.value, { stream: !0 });
187
+ let H;
188
+ for (; (H = o.indexOf(`
187
189
 
188
190
  `)) !== -1; ) {
189
- const C = o.slice(0, w);
190
- o = o.slice(w + 2);
191
- const v = Ie(C);
192
- if (v) {
193
- if (v.event === "chunk") {
194
- const g = typeof v.data.text == "string" ? v.data.text : "";
195
- g && (i += g, (I = r.onChunk) == null || I.call(r, g, i));
196
- } else if (v.event === "done")
197
- u = {
198
- reply: typeof v.data.reply == "string" ? v.data.reply : i,
199
- sources: v.data.sources
191
+ const w = o.slice(0, H);
192
+ o = o.slice(H + 2);
193
+ const f = Ie(w);
194
+ if (f) {
195
+ if (f.event === "chunk") {
196
+ const E = typeof f.data.text == "string" ? f.data.text : "";
197
+ E && (i += E, (R = r.onChunk) == null || R.call(r, E, i));
198
+ } else if (f.event === "tool") {
199
+ if (typeof f.data.name == "string") {
200
+ const E = f.data;
201
+ l.push(E), (T = r.onToolUse) == null || T.call(r, E, l);
202
+ }
203
+ } else if (f.event === "done") {
204
+ const E = Array.isArray(f.data.toolUses) ? f.data.toolUses : l;
205
+ c = {
206
+ reply: typeof f.data.reply == "string" ? f.data.reply : i,
207
+ sources: f.data.sources,
208
+ ...E.length > 0 ? { toolUses: E } : {}
200
209
  };
201
- else if (v.event === "error")
202
- throw new H(
203
- typeof v.data.error == "string" ? v.data.error : "Something went wrong. Please try again.",
210
+ } else if (f.event === "error")
211
+ throw new j(
212
+ typeof f.data.error == "string" ? f.data.error : "Something went wrong. Please try again.",
204
213
  0,
205
214
  "STREAM_ERROR"
206
215
  );
@@ -208,18 +217,22 @@ class Oe {
208
217
  }
209
218
  }
210
219
  } finally {
211
- (E = r.signal) == null || E.removeEventListener("abort", c), n.releaseLock();
220
+ (p = r.signal) == null || p.removeEventListener("abort", u), n.releaseLock();
212
221
  }
213
- if ((T = r.signal) != null && T.aborted)
214
- return { reply: i, aborted: !0 };
215
- if (u) return u;
216
- throw new H(
222
+ if ((v = r.signal) != null && v.aborted)
223
+ return {
224
+ reply: i,
225
+ aborted: !0,
226
+ ...l.length > 0 ? { toolUses: l } : {}
227
+ };
228
+ if (c) return c;
229
+ throw new j(
217
230
  "Connection interrupted. Please try again.",
218
231
  0,
219
232
  "STREAM_ERROR"
220
233
  );
221
234
  }
222
- async fetchStream(e, r) {
235
+ async fetchStream(t, r) {
223
236
  const n = new AbortController(), s = () => n.abort();
224
237
  r == null || r.addEventListener("abort", s, { once: !0 });
225
238
  let o = !1;
@@ -230,36 +243,36 @@ class Oe {
230
243
  return await fetch(`${this.baseUrl}/api/chat/stream`, {
231
244
  method: "POST",
232
245
  headers: { "Content-Type": "application/json" },
233
- body: JSON.stringify({ messages: e }),
246
+ body: JSON.stringify({ messages: t }),
234
247
  signal: n.signal
235
248
  });
236
- } catch (u) {
237
- throw o ? new H(
249
+ } catch (l) {
250
+ throw o ? new j(
238
251
  "Request timed out. Please try again.",
239
252
  0,
240
253
  "TIMEOUT"
241
- ) : u;
254
+ ) : l;
242
255
  } finally {
243
256
  i !== void 0 && clearTimeout(i), r == null || r.removeEventListener("abort", s);
244
257
  }
245
258
  }
246
- async fetchWithTimeout(e) {
259
+ async fetchWithTimeout(t) {
247
260
  if (this.timeoutMs <= 0)
248
261
  return fetch(`${this.baseUrl}/api/chat`, {
249
262
  method: "POST",
250
263
  headers: { "Content-Type": "application/json" },
251
- body: JSON.stringify({ messages: e })
264
+ body: JSON.stringify({ messages: t })
252
265
  });
253
266
  const r = new AbortController(), n = setTimeout(() => r.abort(), this.timeoutMs);
254
267
  try {
255
268
  return await fetch(`${this.baseUrl}/api/chat`, {
256
269
  method: "POST",
257
270
  headers: { "Content-Type": "application/json" },
258
- body: JSON.stringify({ messages: e }),
271
+ body: JSON.stringify({ messages: t }),
259
272
  signal: r.signal
260
273
  });
261
274
  } catch (s) {
262
- throw r.signal.aborted ? new H(
275
+ throw r.signal.aborted ? new j(
263
276
  "Request timed out. Please try again.",
264
277
  0,
265
278
  "TIMEOUT"
@@ -268,12 +281,12 @@ class Oe {
268
281
  clearTimeout(n);
269
282
  }
270
283
  }
271
- isRetryable(e, r) {
272
- return r === "TIMEOUT" || r === "NETWORK_ERROR" ? !0 : e === 429 || e === 503;
284
+ isRetryable(t, r) {
285
+ return r === "TIMEOUT" || r === "NETWORK_ERROR" ? !0 : t === 429 || t === 503;
273
286
  }
274
- getRetryDelay(e, r) {
275
- if (e && e.status === 429) {
276
- const n = e.headers.get("Retry-After");
287
+ getRetryDelay(t, r) {
288
+ if (t && t.status === 429) {
289
+ const n = t.headers.get("Retry-After");
277
290
  if (n) {
278
291
  const s = Number(n);
279
292
  return Math.min(s * 1e3, 6e4);
@@ -281,111 +294,111 @@ class Oe {
281
294
  }
282
295
  return r === 0 ? 1e3 : 3e3;
283
296
  }
284
- delay(e) {
285
- return new Promise((r) => setTimeout(r, e));
297
+ delay(t) {
298
+ return new Promise((r) => setTimeout(r, t));
286
299
  }
287
300
  }
288
- function Ie(t) {
289
- let e = "message";
301
+ function Ie(e) {
302
+ let t = "message";
290
303
  const r = [];
291
- for (const n of t.split(`
304
+ for (const n of e.split(`
292
305
  `))
293
- n.startsWith("event:") ? e = n.slice(6).trim() : n.startsWith("data:") && r.push(n.slice(5).trimStart());
306
+ n.startsWith("event:") ? t = n.slice(6).trim() : n.startsWith("data:") && r.push(n.slice(5).trimStart());
294
307
  if (r.length === 0) return null;
295
308
  try {
296
309
  const n = JSON.parse(r.join(`
297
310
  `));
298
- return typeof n != "object" || n === null ? null : { event: e, data: n };
311
+ return typeof n != "object" || n === null ? null : { event: t, data: n };
299
312
  } catch {
300
313
  return null;
301
314
  }
302
315
  }
303
- function ye(t) {
304
- return typeof t == "string" ? { content: t } : t;
316
+ function we(e) {
317
+ return typeof e == "string" ? { content: e } : e;
305
318
  }
306
- function le(t, e, r) {
307
- console.error(`[claudius] plugin "${t.name}" failed in ${e}:`, r);
319
+ function fe(e, t, r) {
320
+ console.error(`[claudius] plugin "${e.name}" failed in ${t}:`, r);
308
321
  }
309
- async function De(t, e, r) {
310
- let n = e;
311
- for (const s of t) {
322
+ async function De(e, t, r) {
323
+ let n = t;
324
+ for (const s of e) {
312
325
  if (!s.onBeforeSend) continue;
313
326
  let o = null;
314
327
  const i = {
315
328
  ...r,
316
- respondWith(u) {
329
+ respondWith(l) {
317
330
  o = {
318
331
  type: "respond",
319
332
  message: n,
320
- reply: ye(u)
333
+ reply: we(l)
321
334
  };
322
335
  },
323
- abort(u) {
324
- o = { type: "abort", reason: u };
336
+ abort(l) {
337
+ o = { type: "abort", reason: l };
325
338
  }
326
339
  };
327
340
  try {
328
- const u = await s.onBeforeSend(n, i);
341
+ const l = await s.onBeforeSend(n, i);
329
342
  if (o) return o;
330
- u && (n = u);
331
- } catch (u) {
332
- le(s, "onBeforeSend", u);
343
+ l && (n = l);
344
+ } catch (l) {
345
+ fe(s, "onBeforeSend", l);
333
346
  }
334
347
  }
335
348
  return { type: "send", message: n };
336
349
  }
337
- async function _e(t, e, r) {
338
- let n = e;
339
- for (const s of t)
350
+ async function _e(e, t, r) {
351
+ let n = t;
352
+ for (const s of e)
340
353
  if (s.onAfterReceive)
341
354
  try {
342
355
  const o = await s.onAfterReceive(n, r);
343
356
  o && (n = o);
344
357
  } catch (o) {
345
- le(s, "onAfterReceive", o);
358
+ fe(s, "onAfterReceive", o);
346
359
  }
347
360
  return n;
348
361
  }
349
- async function He(t, e, r) {
350
- for (const n of t) {
362
+ async function je(e, t, r) {
363
+ for (const n of e) {
351
364
  if (!n.onError) continue;
352
365
  let s = null;
353
366
  const o = {
354
367
  ...r,
355
368
  respondWith(i) {
356
- s = ye(i);
369
+ s = we(i);
357
370
  }
358
371
  };
359
372
  try {
360
- if (await n.onError(e, o), s) return s;
373
+ if (await n.onError(t, o), s) return s;
361
374
  } catch (i) {
362
- le(n, "onError", i);
375
+ fe(n, "onError", i);
363
376
  }
364
377
  }
365
378
  return null;
366
379
  }
367
- const je = 200, Be = "claudius:messages";
368
- function $e(t, e) {
380
+ const He = 200, Be = "claudius:messages";
381
+ function $e(e, t) {
369
382
  let r;
370
383
  try {
371
- r = new URL(e).host;
384
+ r = new URL(t).host;
372
385
  } catch {
373
- r = e;
386
+ r = t;
374
387
  }
375
- return `${t}:${r}`;
388
+ return `${e}:${r}`;
376
389
  }
377
- function ce() {
390
+ function ue() {
378
391
  try {
379
392
  return typeof sessionStorage < "u" ? sessionStorage : null;
380
393
  } catch {
381
394
  return null;
382
395
  }
383
396
  }
384
- function Pe(t) {
385
- const e = ce();
386
- if (!e) return [];
397
+ function Pe(e) {
398
+ const t = ue();
399
+ if (!t) return [];
387
400
  try {
388
- const r = e.getItem(t);
401
+ const r = t.getItem(e);
389
402
  if (!r) return [];
390
403
  const n = JSON.parse(r);
391
404
  return Array.isArray(n) ? n : [];
@@ -393,270 +406,279 @@ function Pe(t) {
393
406
  return [];
394
407
  }
395
408
  }
396
- function Ge({
397
- apiUrl: t,
398
- persistMessages: e = !0,
409
+ function Ue({
410
+ apiUrl: e,
411
+ persistMessages: t = !0,
399
412
  storageKeyPrefix: r = Be,
400
413
  timeoutMs: n,
401
414
  translations: s,
402
415
  plugins: o,
403
416
  streaming: i = !0
404
417
  }) {
405
- const u = ne(
406
- () => new Oe(t, { debounceMs: 0, timeoutMs: n }),
407
- [t, n]
408
- ), c = $e(r, t), l = e ? Pe(c) : [], [f, y] = A(l), [I, E] = A(!1), [T, x] = A(!1), [w, C] = A(
418
+ const l = se(
419
+ () => new Oe(e, { debounceMs: 0, timeoutMs: n }),
420
+ [e, n]
421
+ ), c = $e(r, e), u = t ? Pe(c) : [], [d, x] = L(u), [N, R] = L(!1), [T, p] = L(!1), [v, k] = L(
409
422
  null
410
- ), [v, g] = A(null), [S, j] = A(!1), W = O(l.length), $ = O(!1), p = O(l), Y = O(null), B = O(o ?? []);
423
+ ), [H, w] = L(null), [f, E] = L(!1), F = I(u.length), W = I(!1), y = I(u), K = I(null), B = I(o ?? []);
411
424
  B.current = o ?? [];
412
- const _ = L(
413
- (d) => {
414
- if (!e) return;
415
- const N = ce();
416
- if (N)
425
+ const _ = O(
426
+ (h) => {
427
+ if (!t) return;
428
+ const A = ue();
429
+ if (A)
417
430
  try {
418
- const k = d.slice(-je);
419
- N.setItem(c, JSON.stringify(k));
431
+ const S = h.slice(-He);
432
+ A.setItem(c, JSON.stringify(S));
420
433
  } catch {
421
434
  }
422
435
  },
423
- [e, c]
424
- ), h = () => (W.current += 1, `msg-${W.current}`), F = L(
425
- (d, N) => {
436
+ [t, c]
437
+ ), m = () => (F.current += 1, `msg-${F.current}`), V = O(
438
+ (h, A) => {
426
439
  if (!s)
427
- return N ?? "Something went wrong. Please try again.";
428
- switch (d) {
440
+ return A ?? "Something went wrong. Please try again.";
441
+ switch (h) {
429
442
  case "TIMEOUT":
430
443
  return s.errorTimeout;
431
444
  case "NETWORK_ERROR":
432
445
  return s.errorConnection;
433
446
  case "RATE_LIMITED":
434
- return N != null && N.includes("minute") ? s.errorRateLimitMinute : s.errorRateLimitHour;
447
+ return A != null && A.includes("minute") ? s.errorRateLimitMinute : s.errorRateLimitHour;
435
448
  case "VALIDATION_ERROR":
436
449
  case "CONFIG_ERROR":
437
450
  case "SERVICE_ERROR":
438
451
  case "UNKNOWN_ERROR":
439
452
  default:
440
- return N ?? s.errorGeneric;
453
+ return A ?? s.errorGeneric;
441
454
  }
442
455
  },
443
456
  [s]
444
- ), Z = L((d) => !(d instanceof H) || d.code === "TIMEOUT" || d.code === "NETWORK_ERROR" || d.code === "RATE_LIMITED" || d.code === "SERVICE_ERROR" || d.code === "UNKNOWN_ERROR" || d.status >= 500 || d.status === 0, []), K = L(
445
- async (d) => {
446
- E(!0), $.current = !0, g(null), j(!1);
447
- const N = i && typeof u.streamMessage == "function";
448
- let k = null;
449
- const V = (m) => {
450
- if (k === null) {
451
- k = h(), C(k);
452
- const R = [
453
- ...p.current,
454
- { id: k, role: "assistant", content: m }
457
+ ), ee = O((h) => !(h instanceof j) || 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, []), J = O(
458
+ async (h) => {
459
+ R(!0), W.current = !0, w(null), E(!1);
460
+ const A = i && typeof l.streamMessage == "function";
461
+ let S = null;
462
+ const Y = (b) => {
463
+ if (S === null) {
464
+ S = m(), k(S);
465
+ const C = [
466
+ ...y.current,
467
+ { id: S, role: "assistant", content: "", ...b }
455
468
  ];
456
- p.current = R, y(R);
469
+ y.current = C, x(C);
457
470
  } else {
458
- const R = k, D = p.current.map(
459
- (M) => M.id === R ? { ...M, content: m } : M
471
+ const C = S, M = y.current.map(
472
+ (P) => P.id === C ? { ...P, ...b } : P
460
473
  );
461
- p.current = D, y(D);
474
+ y.current = M, x(M);
462
475
  }
476
+ }, $ = () => {
477
+ if (S === null) return;
478
+ const b = S, C = y.current.filter((M) => M.id !== b);
479
+ y.current = C, x(C);
463
480
  };
464
481
  try {
465
- let m, R, D = !1;
466
- if (N) {
467
- const P = new AbortController();
468
- Y.current = P, x(!0);
469
- const J = await u.streamMessage(d, {
470
- signal: P.signal,
471
- onChunk: (de, te) => V(te)
482
+ let b, C, M, P = !1;
483
+ if (A) {
484
+ const G = new AbortController();
485
+ K.current = G, p(!0);
486
+ const q = await l.streamMessage(h, {
487
+ signal: G.signal,
488
+ onChunk: (ae, D) => Y({ content: D }),
489
+ onToolUse: (ae, D) => Y({ toolUses: [...D] })
472
490
  });
473
- m = J.reply, R = J.sources, D = J.aborted ?? !1;
491
+ b = q.reply, C = q.sources, M = q.toolUses, P = q.aborted ?? !1;
474
492
  } else {
475
- const P = await u.sendMessage(d);
476
- m = P.reply, R = P.sources;
493
+ const G = await l.sendMessage(h);
494
+ b = G.reply, C = G.sources, M = G.toolUses;
495
+ }
496
+ if (P && !b) {
497
+ $();
498
+ return;
477
499
  }
478
- if (D && !m) return;
479
- let M = {
480
- id: k ?? h(),
500
+ let U = {
501
+ id: S ?? m(),
481
502
  role: "assistant",
482
- content: m,
483
- sources: R
503
+ content: b,
504
+ sources: C,
505
+ toolUses: M
484
506
  };
485
- B.current.length > 0 && !D && (M = await _e(
507
+ B.current.length > 0 && !P && (U = await _e(
486
508
  B.current,
487
- M,
488
- { messages: d, apiUrl: t }
509
+ U,
510
+ { messages: h, apiUrl: e }
489
511
  ));
490
- const z = k !== null ? p.current.map(
491
- (P) => P.id === M.id ? M : P
492
- ) : [...d, M];
493
- p.current = z, y(z), _(z);
494
- } catch (m) {
495
- if (m instanceof ae) return;
496
- if (k !== null) {
497
- _(p.current), m instanceof H ? g(F(m.code, m.message)) : g(
512
+ const Z = S !== null ? y.current.map(
513
+ (G) => G.id === U.id ? U : G
514
+ ) : [...h, U];
515
+ y.current = Z, x(Z), _(Z);
516
+ } catch (b) {
517
+ if (b instanceof le) return;
518
+ if (S !== null) {
519
+ _(y.current), b instanceof j ? w(V(b.code, b.message)) : w(
498
520
  (s == null ? void 0 : s.errorConnection) ?? "Failed to connect. Please try again."
499
- ), j(!1);
521
+ ), E(!1);
500
522
  return;
501
523
  }
502
524
  if (B.current.length > 0) {
503
- const R = m instanceof Error ? m : new Error(String(m)), D = await He(B.current, R, {
504
- messages: d,
505
- apiUrl: t
525
+ const C = b instanceof Error ? b : new Error(String(b)), M = await je(B.current, C, {
526
+ messages: h,
527
+ apiUrl: e
506
528
  });
507
- if (D) {
508
- const M = {
509
- id: h(),
529
+ if (M) {
530
+ const P = {
531
+ id: m(),
510
532
  role: "assistant",
511
- content: D.content,
512
- sources: D.sources
513
- }, z = [...d, M];
514
- p.current = z, y(z), _(z), g(null), j(!1);
533
+ content: M.content,
534
+ sources: M.sources
535
+ }, U = [...h, P];
536
+ y.current = U, x(U), _(U), w(null), E(!1);
515
537
  return;
516
538
  }
517
539
  }
518
- m instanceof H ? g(F(m.code, m.message)) : g(
540
+ b instanceof j ? w(V(b.code, b.message)) : w(
519
541
  (s == null ? void 0 : s.errorConnection) ?? "Failed to connect. Please try again."
520
- ), j(Z(m));
542
+ ), E(ee(b));
521
543
  } finally {
522
- E(!1), $.current = !1, x(!1), C(null), Y.current = null;
544
+ R(!1), W.current = !1, p(!1), k(null), K.current = null;
523
545
  }
524
546
  },
525
547
  [
526
- t,
527
- u,
528
- F,
529
- Z,
548
+ e,
549
+ l,
550
+ V,
551
+ ee,
530
552
  _,
531
553
  i,
532
554
  s
533
555
  ]
534
- ), se = L(() => {
535
- var d;
536
- (d = Y.current) == null || d.abort();
537
- }, []), oe = L(
538
- async (d) => {
539
- const N = d.trim();
540
- if (!N || $.current) return;
541
- const k = {
542
- id: h(),
556
+ ), oe = O(() => {
557
+ var h;
558
+ (h = K.current) == null || h.abort();
559
+ }, []), ie = O(
560
+ async (h) => {
561
+ const A = h.trim();
562
+ if (!A || W.current) return;
563
+ const S = {
564
+ id: m(),
543
565
  role: "user",
544
- content: N
566
+ content: A
545
567
  };
546
- let V = k;
568
+ let Y = S;
547
569
  if (B.current.length > 0) {
548
- const R = await De(B.current, k, {
549
- messages: p.current,
550
- apiUrl: t
570
+ const b = await De(B.current, S, {
571
+ messages: y.current,
572
+ apiUrl: e
551
573
  });
552
- if (R.type === "abort") return;
553
- if (R.type === "respond") {
554
- const D = {
555
- id: h(),
574
+ if (b.type === "abort") return;
575
+ if (b.type === "respond") {
576
+ const C = {
577
+ id: m(),
556
578
  role: "assistant",
557
- content: R.reply.content,
558
- sources: R.reply.sources
579
+ content: b.reply.content,
580
+ sources: b.reply.sources
559
581
  }, M = [
560
- ...p.current,
561
- R.message,
562
- D
582
+ ...y.current,
583
+ b.message,
584
+ C
563
585
  ];
564
- p.current = M, y(M), _(M), g(null), j(!1);
586
+ y.current = M, x(M), _(M), w(null), E(!1);
565
587
  return;
566
588
  }
567
- V = R.message;
589
+ Y = b.message;
568
590
  }
569
- const m = [...p.current, V];
570
- p.current = m, y(m), _(m), await K(m);
591
+ const $ = [...y.current, Y];
592
+ y.current = $, x($), _($), await J($);
571
593
  },
572
- [t, _, K]
573
- ), Q = L(async () => {
574
- if ($.current) return;
575
- const d = p.current[p.current.length - 1];
576
- !d || d.role !== "user" || await K(p.current);
577
- }, [K]), ee = L(() => {
578
- if (p.current = [], y([]), g(null), j(!1), e) {
579
- const d = ce();
580
- if (!d) return;
594
+ [e, _, J]
595
+ ), te = O(async () => {
596
+ if (W.current) return;
597
+ const h = y.current[y.current.length - 1];
598
+ !h || h.role !== "user" || await J(y.current);
599
+ }, [J]), re = O(() => {
600
+ if (y.current = [], x([]), w(null), E(!1), t) {
601
+ const h = ue();
602
+ if (!h) return;
581
603
  try {
582
- d.removeItem(c);
604
+ h.removeItem(c);
583
605
  } catch {
584
606
  }
585
607
  }
586
- }, [e, c]);
608
+ }, [t, c]);
587
609
  return {
588
- messages: f,
589
- isLoading: I,
610
+ messages: d,
611
+ isLoading: N,
590
612
  isStreaming: T,
591
- streamingMessageId: w,
592
- error: v,
593
- canRetry: S,
594
- sendMessage: oe,
595
- stop: se,
596
- retry: Q,
597
- clearMessages: ee
613
+ streamingMessageId: v,
614
+ error: H,
615
+ canRetry: f,
616
+ sendMessage: ie,
617
+ stop: oe,
618
+ retry: te,
619
+ clearMessages: re
598
620
  };
599
621
  }
600
- function Ue(t) {
601
- const [e, r] = A(() => typeof window > "u" ? !1 : window.matchMedia(t).matches);
602
- return U(() => {
603
- const n = window.matchMedia(t);
622
+ function Ge(e) {
623
+ const [t, r] = L(() => typeof window > "u" ? !1 : window.matchMedia(e).matches);
624
+ return z(() => {
625
+ const n = window.matchMedia(e);
604
626
  r(n.matches);
605
627
  const s = (o) => r(o.matches);
606
628
  return n.addEventListener("change", s), () => n.removeEventListener("change", s);
607
- }, [t]), e;
629
+ }, [e]), t;
608
630
  }
609
- function re(t, e) {
610
- return t instanceof RegExp ? t.test(e) : e.toLowerCase().includes(t.toLowerCase());
631
+ function ne(e, t) {
632
+ return e instanceof RegExp ? e.test(t) : t.toLowerCase().includes(e.toLowerCase());
611
633
  }
612
634
  function We() {
613
- const t = document.documentElement, e = document.body, r = t.scrollTop || e.scrollTop || 0, n = Math.max(t.scrollHeight, e.scrollHeight), s = t.clientHeight || window.innerHeight, o = n - s;
635
+ const e = document.documentElement, t = document.body, r = e.scrollTop || t.scrollTop || 0, n = Math.max(e.scrollHeight, t.scrollHeight), s = e.clientHeight || window.innerHeight, o = n - s;
614
636
  return o <= 0 ? 100 : r / o * 100;
615
637
  }
616
638
  function ze({
617
- triggers: t,
618
- enabled: e,
639
+ triggers: e,
640
+ enabled: t,
619
641
  onOpen: r,
620
642
  onGreeting: n
621
643
  }) {
622
- U(() => {
623
- if (!e || !t || t.length === 0) return;
624
- const s = /* @__PURE__ */ new Set(), o = [], i = typeof window < "u" ? window.location.href : "", u = (c, l) => {
625
- s.has(c) || (s.add(c), l === "open" ? r() : n(l.greeting));
644
+ z(() => {
645
+ if (!t || !e || e.length === 0) return;
646
+ const s = /* @__PURE__ */ new Set(), o = [], i = typeof window < "u" ? window.location.href : "", l = (c, u) => {
647
+ s.has(c) || (s.add(c), u === "open" ? r() : n(u.greeting));
626
648
  };
627
- return t.forEach((c, l) => {
649
+ return e.forEach((c, u) => {
628
650
  switch (c.on) {
629
651
  case "url": {
630
- re(c.pattern, i) && u(l, c.action);
652
+ ne(c.pattern, i) && l(u, c.action);
631
653
  break;
632
654
  }
633
655
  case "time": {
634
- if (c.matchUrl && !re(c.matchUrl, i))
656
+ if (c.matchUrl && !ne(c.matchUrl, i))
635
657
  return;
636
- const f = window.setTimeout(
637
- () => u(l, c.action),
658
+ const d = window.setTimeout(
659
+ () => l(u, c.action),
638
660
  Math.max(0, c.seconds * 1e3)
639
661
  );
640
- o.push(() => window.clearTimeout(f));
662
+ o.push(() => window.clearTimeout(d));
641
663
  break;
642
664
  }
643
665
  case "scroll": {
644
- if (c.matchUrl && !re(c.matchUrl, i))
666
+ if (c.matchUrl && !ne(c.matchUrl, i))
645
667
  return;
646
- const f = () => {
647
- We() >= c.percent && u(l, c.action);
668
+ const d = () => {
669
+ We() >= c.percent && l(u, c.action);
648
670
  };
649
- f(), window.addEventListener("scroll", f, { passive: !0 }), o.push(() => window.removeEventListener("scroll", f));
671
+ d(), window.addEventListener("scroll", d, { passive: !0 }), o.push(() => window.removeEventListener("scroll", d));
650
672
  break;
651
673
  }
652
674
  case "exit-intent": {
653
- if (c.matchUrl && !re(c.matchUrl, i))
675
+ if (c.matchUrl && !ne(c.matchUrl, i))
654
676
  return;
655
- const f = (y) => {
656
- y.clientY <= 0 && u(l, c.action);
677
+ const d = (x) => {
678
+ x.clientY <= 0 && l(u, c.action);
657
679
  };
658
- document.addEventListener("mouseleave", f), o.push(
659
- () => document.removeEventListener("mouseleave", f)
680
+ document.addEventListener("mouseleave", d), o.push(
681
+ () => document.removeEventListener("mouseleave", d)
660
682
  );
661
683
  break;
662
684
  }
@@ -664,15 +686,15 @@ function ze({
664
686
  }), () => {
665
687
  o.forEach((c) => c());
666
688
  };
667
- }, [t, e, r, n]);
689
+ }, [e, t, r, n]);
668
690
  }
669
691
  const Fe = {
670
692
  "bottom-right": "bottom-6 right-6",
671
693
  "bottom-left": "bottom-6 left-6",
672
694
  "top-right": "top-6 right-6",
673
695
  "top-left": "top-6 left-6"
674
- }, Ye = ke(function({ isOpen: e, onClick: r, position: n = "bottom-right", translations: s }, o) {
675
- const i = e ? (s == null ? void 0 : s.closeChat) ?? "Close chat" : (s == null ? void 0 : s.openChat) ?? "Open chat";
696
+ }, Ve = ke(function({ isOpen: t, onClick: r, position: n = "bottom-right", translations: s }, o) {
697
+ const i = t ? (s == null ? void 0 : s.closeChat) ?? "Close chat" : (s == null ? void 0 : s.openChat) ?? "Open chat";
676
698
  return /* @__PURE__ */ a(
677
699
  "button",
678
700
  {
@@ -680,7 +702,7 @@ const Fe = {
680
702
  onClick: r,
681
703
  "aria-label": i,
682
704
  className: `fixed ${Fe[n]} 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`,
683
- children: e ? /* @__PURE__ */ b(
705
+ children: t ? /* @__PURE__ */ g(
684
706
  "svg",
685
707
  {
686
708
  width: "24",
@@ -714,12 +736,12 @@ const Fe = {
714
736
  )
715
737
  }
716
738
  );
717
- }), Ve = ue(function({
718
- count: e,
739
+ }), Ye = de(function({
740
+ count: t,
719
741
  isActive: r,
720
742
  onClick: n
721
743
  }) {
722
- return /* @__PURE__ */ b(
744
+ return /* @__PURE__ */ g(
723
745
  "button",
724
746
  {
725
747
  onClick: n,
@@ -727,7 +749,7 @@ const Fe = {
727
749
  title: "View sources",
728
750
  className: `group relative flex h-7 w-7 items-center justify-center rounded-claudius-full transition-colors ${r ? "bg-claudius-accent text-claudius-accent-text" : "text-claudius-text-muted hover:bg-claudius-surface-muted hover:text-claudius-text"}`,
729
751
  children: [
730
- /* @__PURE__ */ b(
752
+ /* @__PURE__ */ g(
731
753
  "svg",
732
754
  {
733
755
  width: "14",
@@ -747,65 +769,130 @@ const Fe = {
747
769
  ]
748
770
  }
749
771
  ),
750
- /* @__PURE__ */ a("span", { className: "absolute -right-1 -top-1 flex h-4 min-w-4 items-center justify-center rounded-claudius-full bg-claudius-accent px-1 text-[10px] font-bold text-claudius-accent-text", children: e })
772
+ /* @__PURE__ */ a("span", { className: "absolute -right-1 -top-1 flex h-4 min-w-4 items-center justify-center rounded-claudius-full bg-claudius-accent px-1 text-[10px] font-bold text-claudius-accent-text", children: t })
751
773
  ]
752
774
  }
753
775
  );
754
776
  }), Ke = ["http:", "https:"];
755
- function xe(t) {
756
- if (!t || typeof t != "string")
777
+ function ve(e) {
778
+ if (!e || typeof e != "string")
757
779
  return null;
758
- const e = t.trim();
759
- if (!e)
780
+ const t = e.trim();
781
+ if (!t)
760
782
  return null;
761
783
  try {
762
- const r = new URL(e);
763
- return Ke.includes(r.protocol) ? e : null;
784
+ const r = new URL(t);
785
+ return Ke.includes(r.protocol) ? t : null;
764
786
  } catch {
765
787
  return null;
766
788
  }
767
789
  }
768
- function qe(t) {
769
- const e = t.lastIndexOf(`
770
- `), r = e === -1 ? "" : t.slice(0, e + 1);
771
- let n = e === -1 ? t : t.slice(e + 1);
790
+ function qe(e) {
791
+ const t = e.lastIndexOf(`
792
+ `), r = t === -1 ? "" : e.slice(0, t + 1);
793
+ let n = t === -1 ? e : e.slice(t + 1);
772
794
  return n = Ze(n), n = Qe(n), r + n;
773
795
  }
774
- function Je(t) {
775
- const e = [];
776
- for (let r = 0; r < t.length - 1; r++)
777
- t[r] === "*" && t[r + 1] === "*" && (e.push(r), r++);
778
- return e;
796
+ function Je(e) {
797
+ const t = [];
798
+ for (let r = 0; r < e.length - 1; r++)
799
+ e[r] === "*" && e[r + 1] === "*" && (t.push(r), r++);
800
+ return t;
779
801
  }
780
- function Xe(t) {
781
- const e = [];
782
- for (let r = 0; r < t.length; r++)
783
- if (t[r] === "*") {
784
- if (t[r + 1] === "*") {
802
+ function Xe(e) {
803
+ const t = [];
804
+ for (let r = 0; r < e.length; r++)
805
+ if (e[r] === "*") {
806
+ if (e[r + 1] === "*") {
785
807
  r++;
786
808
  continue;
787
809
  }
788
- e.push(r);
810
+ t.push(r);
789
811
  }
790
- return e;
812
+ return t;
791
813
  }
792
- function Ze(t) {
793
- const e = Je(t);
794
- if (e.length % 2 === 0) return t;
795
- const r = e[e.length - 1], n = t.slice(r + 2);
796
- return n.trim() === "" ? t.slice(0, r) + n : t + "**";
814
+ function Ze(e) {
815
+ const t = Je(e);
816
+ if (t.length % 2 === 0) return e;
817
+ const r = t[t.length - 1], n = e.slice(r + 2);
818
+ return n.trim() === "" ? e.slice(0, r) + n : e + "**";
797
819
  }
798
- function Qe(t) {
799
- const e = Xe(t);
800
- if (e.length % 2 === 0) return t;
801
- const r = e[e.length - 1], n = t.slice(r + 1);
802
- return n.trim() === "" ? t.slice(0, r) + n : t + "*";
820
+ function Qe(e) {
821
+ const t = Xe(e);
822
+ if (t.length % 2 === 0) return e;
823
+ const r = t[t.length - 1], n = e.slice(r + 1);
824
+ return n.trim() === "" ? e.slice(0, r) + n : e + "*";
825
+ }
826
+ function et({
827
+ toolUse: e,
828
+ usedLabel: t,
829
+ detailsLabel: r
830
+ }) {
831
+ const [n, s] = L(!1), o = e.input !== void 0 || e.result !== void 0;
832
+ return /* @__PURE__ */ g("div", { className: "text-xs text-claudius-text-muted", children: [
833
+ /* @__PURE__ */ g(
834
+ "button",
835
+ {
836
+ type: "button",
837
+ disabled: !o,
838
+ onClick: () => s((i) => !i),
839
+ "aria-expanded": o ? n : void 0,
840
+ 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 disabled:cursor-default disabled:hover:opacity-100",
841
+ children: [
842
+ /* @__PURE__ */ a(
843
+ "svg",
844
+ {
845
+ width: "11",
846
+ height: "11",
847
+ viewBox: "0 0 24 24",
848
+ fill: "none",
849
+ stroke: "currentColor",
850
+ strokeWidth: "2",
851
+ strokeLinecap: "round",
852
+ strokeLinejoin: "round",
853
+ "aria-hidden": "true",
854
+ children: /* @__PURE__ */ a("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" })
855
+ }
856
+ ),
857
+ /* @__PURE__ */ g("span", { children: [
858
+ t,
859
+ " ",
860
+ /* @__PURE__ */ a("span", { className: "font-mono text-claudius-text", children: e.name }),
861
+ e.isError && /* @__PURE__ */ a("span", { className: "text-claudius-error", children: " ✕" })
862
+ ] }),
863
+ o && /* @__PURE__ */ g(xe, { children: [
864
+ /* @__PURE__ */ a("span", { className: "sr-only", children: r }),
865
+ /* @__PURE__ */ a(
866
+ "svg",
867
+ {
868
+ width: "10",
869
+ height: "10",
870
+ viewBox: "0 0 24 24",
871
+ fill: "none",
872
+ stroke: "currentColor",
873
+ strokeWidth: "2",
874
+ strokeLinecap: "round",
875
+ strokeLinejoin: "round",
876
+ "aria-hidden": "true",
877
+ className: n ? "rotate-180" : void 0,
878
+ children: /* @__PURE__ */ a("polyline", { points: "6 9 12 15 18 9" })
879
+ }
880
+ )
881
+ ] })
882
+ ]
883
+ }
884
+ ),
885
+ n && o && /* @__PURE__ */ g("div", { className: "mt-1 overflow-x-auto rounded-claudius-sm border border-claudius-border bg-claudius-field p-2 font-mono", children: [
886
+ e.input !== void 0 && /* @__PURE__ */ a("pre", { className: "whitespace-pre-wrap break-all", children: JSON.stringify(e.input, null, 2) }),
887
+ e.result !== void 0 && /* @__PURE__ */ a("pre", { className: "mt-1 whitespace-pre-wrap break-all border-t border-claudius-border pt-1", children: e.result })
888
+ ] })
889
+ ] });
803
890
  }
804
- const he = /(https?:\/\/[^\s)]+)/, me = /(\*\*[^*]+\*\*)/, ge = /(\*[^*]+\*)/;
805
- function et(t, e) {
806
- const r = t.match(/[.,;:!?'"]+$/), n = r ? t.slice(0, -r[0].length) : t, s = r ? r[0] : "", o = xe(n);
807
- return o ? /* @__PURE__ */ b(Ne, { children: [
808
- /* @__PURE__ */ b(
891
+ const me = /(https?:\/\/[^\s)]+)/, ge = /(\*\*[^*]+\*\*)/, pe = /(\*[^*]+\*)/;
892
+ function tt(e, t) {
893
+ const r = e.match(/[.,;:!?'"]+$/), n = r ? e.slice(0, -r[0].length) : e, s = r ? r[0] : "", o = ve(n);
894
+ return o ? /* @__PURE__ */ g(xe, { children: [
895
+ /* @__PURE__ */ g(
809
896
  "a",
810
897
  {
811
898
  href: o,
@@ -817,107 +904,119 @@ function et(t, e) {
817
904
  /* @__PURE__ */ a("span", { className: "sr-only", children: " (opens in a new tab)" })
818
905
  ]
819
906
  },
820
- e
907
+ t
821
908
  ),
822
909
  s
823
- ] }) : t;
910
+ ] }) : e;
824
911
  }
825
- function tt(t, e) {
826
- const r = t.split(me), n = [];
912
+ function rt(e, t) {
913
+ const r = e.split(ge), n = [];
827
914
  return r.forEach((s, o) => {
828
- if (me.test(s)) {
915
+ if (ge.test(s)) {
829
916
  const i = s.slice(2, -2);
830
- n.push(/* @__PURE__ */ a("strong", { children: i }, `${e}-b${o}`));
917
+ n.push(/* @__PURE__ */ a("strong", { children: i }, `${t}-b${o}`));
831
918
  } else
832
- s.split(ge).forEach((u, c) => {
833
- if (ge.test(u)) {
834
- const l = u.slice(1, -1);
835
- n.push(/* @__PURE__ */ a("em", { children: l }, `${e}-b${o}-i${c}`));
919
+ s.split(pe).forEach((l, c) => {
920
+ if (pe.test(l)) {
921
+ const u = l.slice(1, -1);
922
+ n.push(/* @__PURE__ */ a("em", { children: u }, `${t}-b${o}-i${c}`));
836
923
  } else
837
- u.split(he).forEach((f, y) => {
838
- he.test(f) ? n.push(
839
- et(f, `${e}-b${o}-i${c}-u${y}`)
840
- ) : f && n.push(f);
924
+ l.split(me).forEach((d, x) => {
925
+ me.test(d) ? n.push(
926
+ tt(d, `${t}-b${o}-i${c}-u${x}`)
927
+ ) : d && n.push(d);
841
928
  });
842
929
  });
843
930
  }), n;
844
931
  }
845
- function rt(t) {
846
- const e = t.split(`
932
+ function nt(e) {
933
+ const t = e.split(`
847
934
  `);
848
- return e.map((r, n) => /* @__PURE__ */ b("span", { children: [
849
- tt(r, `l${n}`),
850
- n < e.length - 1 && /* @__PURE__ */ a("br", {})
935
+ return t.map((r, n) => /* @__PURE__ */ g("span", { children: [
936
+ rt(r, `l${n}`),
937
+ n < t.length - 1 && /* @__PURE__ */ a("br", {})
851
938
  ] }, n));
852
939
  }
853
- const nt = ue(function({
854
- role: e,
940
+ const st = de(function({
941
+ role: t,
855
942
  content: r,
856
943
  isStreaming: n = !1,
857
944
  sources: s,
858
- onSourceClick: o,
859
- isSourceActive: i
945
+ toolUses: o,
946
+ toolUsedLabel: i = "Used tool:",
947
+ toolDetailsLabel: l = "Tool details",
948
+ onSourceClick: c,
949
+ isSourceActive: u
860
950
  }) {
861
- const u = e === "user", c = n ? qe(r) : r;
862
- return /* @__PURE__ */ b("div", { className: `${u ? "ml-auto" : "mr-auto"} max-w-[85%]`, children: [
863
- /* @__PURE__ */ a(
951
+ const d = t === "user", x = n ? qe(r) : r, N = d || r !== "" || !(o != null && o.length);
952
+ return /* @__PURE__ */ g("div", { className: `${d ? "ml-auto" : "mr-auto"} max-w-[85%]`, children: [
953
+ N && /* @__PURE__ */ a(
864
954
  "div",
865
955
  {
866
- className: `rounded-claudius-bubble px-4 py-2.5 text-sm leading-relaxed font-body ${u ? "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"}`,
867
- children: rt(c)
956
+ className: `rounded-claudius-bubble px-4 py-2.5 text-sm leading-relaxed font-body ${d ? "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"}`,
957
+ children: nt(x)
868
958
  }
869
959
  ),
870
- !u && s && s.length > 0 && o && /* @__PURE__ */ a("div", { className: "mt-1", children: /* @__PURE__ */ a(
871
- Ve,
960
+ !d && o && o.length > 0 && /* @__PURE__ */ a("div", { className: "mt-1 space-y-1", children: o.map((R, T) => /* @__PURE__ */ a(
961
+ et,
962
+ {
963
+ toolUse: R,
964
+ usedLabel: i,
965
+ detailsLabel: l
966
+ },
967
+ `${R.name}-${T}`
968
+ )) }),
969
+ !d && s && s.length > 0 && c && /* @__PURE__ */ a("div", { className: "mt-1", children: /* @__PURE__ */ a(
970
+ Ye,
872
971
  {
873
972
  count: s.length,
874
- isActive: i ?? !1,
875
- onClick: o
973
+ isActive: u ?? !1,
974
+ onClick: c
876
975
  }
877
976
  ) })
878
977
  ] });
879
- }), ie = 2e3, st = 1800;
880
- function ot({
881
- onSend: t,
882
- isLoading: e,
978
+ }), ce = 2e3, ot = 1800;
979
+ function it({
980
+ onSend: e,
981
+ isLoading: t,
883
982
  isStreaming: r = !1,
884
983
  onStop: n,
885
984
  placeholder: s,
886
985
  translations: o
887
986
  }) {
888
- const [i, u] = A(""), c = O(null), l = i.length, f = l >= st, y = l >= ie, I = s ?? (o == null ? void 0 : o.placeholder) ?? "Type your message...", E = (o == null ? void 0 : o.sendMessage) ?? "Send message", T = (o == null ? void 0 : o.stopGenerating) ?? "Stop generating", x = (o == null ? void 0 : o.typeYourMessage) ?? "Type your message", w = r && !!n;
889
- return U(() => {
890
- var g;
891
- e || (g = c.current) == null || g.focus();
892
- }, [e]), /* @__PURE__ */ b(
987
+ const [i, l] = L(""), c = I(null), u = i.length, d = u >= ot, x = u >= ce, N = s ?? (o == null ? void 0 : o.placeholder) ?? "Type your message...", R = (o == null ? void 0 : o.sendMessage) ?? "Send message", T = (o == null ? void 0 : o.stopGenerating) ?? "Stop generating", p = (o == null ? void 0 : o.typeYourMessage) ?? "Type your message", v = r && !!n;
988
+ return z(() => {
989
+ var w;
990
+ t || (w = c.current) == null || w.focus();
991
+ }, [t]), /* @__PURE__ */ g(
893
992
  "form",
894
993
  {
895
- onSubmit: (g) => {
896
- g.preventDefault();
897
- const S = i.trim();
898
- !S || y || (t(S), u(""));
994
+ onSubmit: (w) => {
995
+ w.preventDefault();
996
+ const f = i.trim();
997
+ !f || x || (e(f), l(""));
899
998
  },
900
999
  className: "border-t border-claudius-border bg-claudius-surface p-3",
901
1000
  children: [
902
- /* @__PURE__ */ b("div", { className: "flex gap-2", children: [
1001
+ /* @__PURE__ */ g("div", { className: "flex gap-2", children: [
903
1002
  /* @__PURE__ */ a(
904
1003
  "input",
905
1004
  {
906
1005
  ref: c,
907
1006
  type: "text",
908
1007
  value: i,
909
- onChange: (g) => {
910
- const S = g.target.value;
911
- S.length <= ie && u(S);
1008
+ onChange: (w) => {
1009
+ const f = w.target.value;
1010
+ f.length <= ce && l(f);
912
1011
  },
913
- placeholder: I,
914
- disabled: e,
915
- "aria-label": x,
916
- "aria-describedby": f ? "char-count" : void 0,
1012
+ placeholder: N,
1013
+ disabled: t,
1014
+ "aria-label": p,
1015
+ "aria-describedby": d ? "char-count" : void 0,
917
1016
  className: "flex-1 rounded-claudius-sm border border-claudius-border bg-claudius-field px-3 py-2 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"
918
1017
  }
919
1018
  ),
920
- w ? /* @__PURE__ */ a(
1019
+ v ? /* @__PURE__ */ a(
921
1020
  "button",
922
1021
  {
923
1022
  type: "button",
@@ -940,10 +1039,10 @@ function ot({
940
1039
  "button",
941
1040
  {
942
1041
  type: "submit",
943
- disabled: e || y,
944
- "aria-label": E,
1042
+ disabled: t || x,
1043
+ "aria-label": R,
945
1044
  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",
946
- children: /* @__PURE__ */ b(
1045
+ children: /* @__PURE__ */ g(
947
1046
  "svg",
948
1047
  {
949
1048
  width: "16",
@@ -964,16 +1063,16 @@ function ot({
964
1063
  }
965
1064
  )
966
1065
  ] }),
967
- f && /* @__PURE__ */ b(
1066
+ d && /* @__PURE__ */ g(
968
1067
  "div",
969
1068
  {
970
1069
  id: "char-count",
971
- className: `mt-1 text-xs text-right ${y ? "text-claudius-error" : "text-claudius-text-muted"}`,
1070
+ className: `mt-1 text-xs text-right ${x ? "text-claudius-error" : "text-claudius-text-muted"}`,
972
1071
  "aria-live": "polite",
973
1072
  children: [
974
- l,
1073
+ u,
975
1074
  "/",
976
- ie
1075
+ ce
977
1076
  ]
978
1077
  }
979
1078
  )
@@ -981,30 +1080,30 @@ function ot({
981
1080
  }
982
1081
  );
983
1082
  }
984
- const it = ["blog", "page", "external"], at = {
1083
+ const at = ["blog", "page", "external"], ct = {
985
1084
  blog: "Blog",
986
1085
  page: "Page",
987
1086
  external: "External"
988
1087
  };
989
- function ct(t) {
1088
+ function lt(e) {
990
1089
  try {
991
- return new URL(t).hostname;
1090
+ return new URL(e).hostname;
992
1091
  } catch {
993
- return t;
1092
+ return e;
994
1093
  }
995
1094
  }
996
- const ut = ue(function({
997
- sources: e,
1095
+ const ut = de(function({
1096
+ sources: t,
998
1097
  onClose: r
999
1098
  }) {
1000
- const n = it.map((o) => ({
1099
+ const n = at.map((o) => ({
1001
1100
  type: o,
1002
- label: at[o],
1003
- items: e.filter((i) => i.type === o)
1004
- })).filter((o) => o.items.length > 0), s = e.length === 1 ? "1 source found" : `${e.length} sources found`;
1005
- return /* @__PURE__ */ b("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: [
1006
- /* @__PURE__ */ b("div", { className: "flex items-center justify-between border-b border-claudius-border px-4 py-3", children: [
1007
- /* @__PURE__ */ b("div", { children: [
1101
+ label: ct[o],
1102
+ items: t.filter((i) => i.type === o)
1103
+ })).filter((o) => o.items.length > 0), s = t.length === 1 ? "1 source found" : `${t.length} sources found`;
1104
+ 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: [
1105
+ /* @__PURE__ */ g("div", { className: "flex items-center justify-between border-b border-claudius-border px-4 py-3", children: [
1106
+ /* @__PURE__ */ g("div", { children: [
1008
1107
  /* @__PURE__ */ a("h3", { className: "text-sm font-heading font-semibold text-claudius-text", children: "Sources" }),
1009
1108
  /* @__PURE__ */ a("p", { className: "text-xs text-claudius-text-muted", children: s })
1010
1109
  ] }),
@@ -1014,7 +1113,7 @@ const ut = ue(function({
1014
1113
  onClick: r,
1015
1114
  "aria-label": "Close sources",
1016
1115
  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",
1017
- children: /* @__PURE__ */ b(
1116
+ children: /* @__PURE__ */ g(
1018
1117
  "svg",
1019
1118
  {
1020
1119
  width: "14",
@@ -1035,54 +1134,54 @@ const ut = ue(function({
1035
1134
  }
1036
1135
  )
1037
1136
  ] }),
1038
- /* @__PURE__ */ a("div", { className: "flex-1 overflow-y-auto px-3 py-3 space-y-4", children: n.map((o) => /* @__PURE__ */ b("div", { children: [
1137
+ /* @__PURE__ */ a("div", { className: "flex-1 overflow-y-auto px-3 py-3 space-y-4", children: n.map((o) => /* @__PURE__ */ g("div", { children: [
1039
1138
  /* @__PURE__ */ a("h4", { className: "mb-2 text-xs font-semibold uppercase tracking-wide text-claudius-text-muted", children: o.label }),
1040
1139
  /* @__PURE__ */ a("div", { className: "space-y-2", children: o.items.map((i) => {
1041
- const u = xe(i.url);
1042
- return u ? /* @__PURE__ */ b(
1140
+ const l = ve(i.url);
1141
+ return l ? /* @__PURE__ */ g(
1043
1142
  "a",
1044
1143
  {
1045
- href: u,
1144
+ href: l,
1046
1145
  target: "_blank",
1047
1146
  rel: "noopener noreferrer",
1048
1147
  className: "block rounded-claudius-md border-2 border-claudius-border bg-claudius-surface-muted p-3 transition-colors hover:bg-claudius-border",
1049
1148
  children: [
1050
1149
  /* @__PURE__ */ a("p", { className: "truncate text-sm font-medium text-claudius-text", children: i.title }),
1051
- /* @__PURE__ */ a("p", { className: "mt-0.5 text-xs text-claudius-text-muted", children: ct(u) })
1150
+ /* @__PURE__ */ a("p", { className: "mt-0.5 text-xs text-claudius-text-muted", children: lt(l) })
1052
1151
  ]
1053
1152
  },
1054
- u
1153
+ l
1055
1154
  ) : null;
1056
1155
  }) })
1057
1156
  ] }, o.type)) })
1058
1157
  ] });
1059
1158
  });
1060
- function lt({
1061
- title: t,
1062
- subtitle: e,
1159
+ function dt({
1160
+ title: e,
1161
+ subtitle: t,
1063
1162
  titleId: r,
1064
1163
  closeLabel: n,
1065
1164
  onClose: s
1066
1165
  }) {
1067
- return /* @__PURE__ */ b("div", { className: "flex items-center gap-3 bg-claudius-accent px-5 py-4", children: [
1166
+ return /* @__PURE__ */ g("div", { className: "flex items-center gap-3 bg-claudius-accent px-5 py-4", children: [
1068
1167
  /* @__PURE__ */ a(
1069
1168
  "div",
1070
1169
  {
1071
1170
  "aria-hidden": "true",
1072
1171
  className: "flex h-8 w-8 items-center justify-center rounded-claudius-full bg-claudius-accent-soft text-sm font-bold text-claudius-accent-text",
1073
- children: t.charAt(0).toUpperCase()
1172
+ children: e.charAt(0).toUpperCase()
1074
1173
  }
1075
1174
  ),
1076
- /* @__PURE__ */ b("div", { className: "flex-1", children: [
1175
+ /* @__PURE__ */ g("div", { className: "flex-1", children: [
1077
1176
  /* @__PURE__ */ a(
1078
1177
  "h2",
1079
1178
  {
1080
1179
  id: r,
1081
1180
  className: "text-sm font-heading font-semibold text-claudius-accent-text",
1082
- children: t
1181
+ children: e
1083
1182
  }
1084
1183
  ),
1085
- /* @__PURE__ */ a("p", { className: "text-xs text-claudius-accent-text", children: e })
1184
+ /* @__PURE__ */ a("p", { className: "text-xs text-claudius-accent-text", children: t })
1086
1185
  ] }),
1087
1186
  /* @__PURE__ */ a(
1088
1187
  "button",
@@ -1090,7 +1189,7 @@ function lt({
1090
1189
  onClick: s,
1091
1190
  "aria-label": n,
1092
1191
  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",
1093
- children: /* @__PURE__ */ b(
1192
+ children: /* @__PURE__ */ g(
1094
1193
  "svg",
1095
1194
  {
1096
1195
  width: "18",
@@ -1112,40 +1211,40 @@ function lt({
1112
1211
  )
1113
1212
  ] });
1114
1213
  }
1115
- function dt({
1116
- message: t,
1117
- retryLabel: e,
1214
+ function ft({
1215
+ message: e,
1216
+ retryLabel: t,
1118
1217
  onRetry: r
1119
1218
  }) {
1120
- return /* @__PURE__ */ b(
1219
+ return /* @__PURE__ */ g(
1121
1220
  "div",
1122
1221
  {
1123
1222
  role: "alert",
1124
1223
  className: "mx-auto flex max-w-[90%] flex-col items-center gap-2 rounded-claudius-sm bg-claudius-error-surface px-3 py-2 text-center text-xs text-claudius-error",
1125
1224
  children: [
1126
- /* @__PURE__ */ a("span", { children: t }),
1225
+ /* @__PURE__ */ a("span", { children: e }),
1127
1226
  r && /* @__PURE__ */ a(
1128
1227
  "button",
1129
1228
  {
1130
1229
  type: "button",
1131
1230
  onClick: r,
1132
1231
  className: "rounded-claudius-md bg-claudius-error px-3 py-1 text-xs font-semibold text-claudius-error-text transition-opacity hover:opacity-90 focus:outline-none focus-visible:ring-2 focus-visible:ring-claudius-error focus-visible:ring-offset-1",
1133
- children: e
1232
+ children: t
1134
1233
  }
1135
1234
  )
1136
1235
  ]
1137
1236
  }
1138
1237
  );
1139
1238
  }
1140
- function ft({ label: t }) {
1239
+ function ht({ label: e }) {
1141
1240
  return /* @__PURE__ */ a(
1142
1241
  "div",
1143
1242
  {
1144
1243
  role: "status",
1145
1244
  "aria-live": "polite",
1146
- "aria-label": t,
1245
+ "aria-label": e,
1147
1246
  className: "mr-auto flex max-w-[85%]",
1148
- children: /* @__PURE__ */ b("div", { className: "flex gap-1 rounded-claudius-bubble rounded-bl-claudius-tail bg-claudius-assistant-bubble px-4 py-3", children: [
1247
+ children: /* @__PURE__ */ g("div", { className: "flex gap-1 rounded-claudius-bubble rounded-bl-claudius-tail bg-claudius-assistant-bubble px-4 py-3", children: [
1149
1248
  /* @__PURE__ */ a("span", { className: "h-2 w-2 motion-safe:animate-bounce rounded-claudius-full bg-claudius-text-muted [animation-delay:0ms]" }),
1150
1249
  /* @__PURE__ */ a("span", { className: "h-2 w-2 motion-safe:animate-bounce rounded-claudius-full bg-claudius-text-muted [animation-delay:150ms]" }),
1151
1250
  /* @__PURE__ */ a("span", { className: "h-2 w-2 motion-safe:animate-bounce rounded-claudius-full bg-claudius-text-muted [animation-delay:300ms]" })
@@ -1153,168 +1252,174 @@ function ft({ label: t }) {
1153
1252
  }
1154
1253
  );
1155
1254
  }
1156
- function ht(t, e, r) {
1157
- const [n, s] = A(0), o = O(0), i = O(0), u = O(0), c = O(!1);
1158
- return U(() => {
1159
- const l = t.current;
1160
- if (!r || !l) return;
1161
- const f = (E) => {
1162
- if (l.scrollTop > 0) {
1255
+ function mt(e, t, r) {
1256
+ const [n, s] = L(0), o = I(0), i = I(0), l = I(0), c = I(!1);
1257
+ return z(() => {
1258
+ const u = e.current;
1259
+ if (!r || !u) return;
1260
+ const d = (R) => {
1261
+ if (u.scrollTop > 0) {
1163
1262
  c.current = !1;
1164
1263
  return;
1165
1264
  }
1166
- c.current = !0, i.current = E.touches[0].clientY, u.current = Date.now();
1167
- }, y = (E) => {
1265
+ c.current = !0, i.current = R.touches[0].clientY, l.current = Date.now();
1266
+ }, x = (R) => {
1168
1267
  if (!c.current) return;
1169
- let T = E.touches[0].clientY - i.current;
1268
+ let T = R.touches[0].clientY - i.current;
1170
1269
  T < 0 && (T = T * 0.3), o.current = T, s(T);
1171
- }, I = () => {
1270
+ }, N = () => {
1172
1271
  if (!c.current) return;
1173
1272
  c.current = !1;
1174
- const E = o.current, T = (Date.now() - u.current) / 1e3, x = l.getBoundingClientRect().height, w = T > 0.05 && E > 0 && E / T > 500, C = E > x * 0.3;
1175
- w || C ? e() : (o.current = 0, s(0));
1273
+ const R = o.current, T = (Date.now() - l.current) / 1e3, p = u.getBoundingClientRect().height, v = T > 0.05 && R > 0 && R / T > 500, k = R > p * 0.3;
1274
+ v || k ? t() : (o.current = 0, s(0));
1176
1275
  };
1177
- return l.addEventListener("touchstart", f, { passive: !0 }), l.addEventListener("touchmove", y, { passive: !0 }), l.addEventListener("touchend", I), () => {
1178
- l.removeEventListener("touchstart", f), l.removeEventListener("touchmove", y), l.removeEventListener("touchend", I);
1276
+ return u.addEventListener("touchstart", d, { passive: !0 }), u.addEventListener("touchmove", x, { passive: !0 }), u.addEventListener("touchend", N), () => {
1277
+ u.removeEventListener("touchstart", d), u.removeEventListener("touchmove", x), u.removeEventListener("touchend", N);
1179
1278
  };
1180
- }, [t, e, r]), { offsetY: n };
1279
+ }, [e, t, r]), { offsetY: n };
1181
1280
  }
1182
- const mt = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
1183
- function gt(t, e) {
1184
- U(() => {
1185
- const r = t.current;
1281
+ const gt = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
1282
+ function pt(e, t) {
1283
+ z(() => {
1284
+ const r = e.current;
1186
1285
  if (!r) return;
1187
1286
  const n = (s) => {
1188
1287
  if (s.key !== "Tab") return;
1189
1288
  const o = Array.from(
1190
- r.querySelectorAll(mt)
1191
- ).filter((l) => !l.hasAttribute("aria-hidden"));
1289
+ r.querySelectorAll(gt)
1290
+ ).filter((u) => !u.hasAttribute("aria-hidden"));
1192
1291
  if (o.length === 0) return;
1193
- const i = o[0], u = o[o.length - 1], c = document.activeElement;
1194
- s.shiftKey && c === i ? (s.preventDefault(), u.focus()) : !s.shiftKey && c === u && (s.preventDefault(), i.focus());
1292
+ const i = o[0], l = o[o.length - 1], c = document.activeElement;
1293
+ s.shiftKey && c === i ? (s.preventDefault(), l.focus()) : !s.shiftKey && c === l && (s.preventDefault(), i.focus());
1195
1294
  };
1196
1295
  return r.addEventListener("keydown", n), () => r.removeEventListener("keydown", n);
1197
- }, [t, e]);
1296
+ }, [e, t]);
1198
1297
  }
1199
- const pt = /\*\*([^*]+)\*\*/g, bt = /\*([^*]+)\*/g, yt = /https?:\/\/[^\s)]+/g;
1200
- function xt(t) {
1201
- return t.replace(pt, "$1").replace(bt, "$1").replace(yt, (e) => {
1298
+ const bt = /\*\*([^*]+)\*\*/g, yt = /\*([^*]+)\*/g, xt = /https?:\/\/[^\s)]+/g;
1299
+ function wt(e) {
1300
+ return e.replace(bt, "$1").replace(yt, "$1").replace(xt, (t) => {
1202
1301
  try {
1203
- return new URL(e).hostname;
1302
+ return new URL(t).hostname;
1204
1303
  } catch {
1205
- return e;
1304
+ return t;
1206
1305
  }
1207
1306
  });
1208
1307
  }
1209
- const wt = {
1308
+ const vt = {
1210
1309
  "bottom-right": "bottom-24 right-3 sm:right-6",
1211
1310
  "bottom-left": "bottom-24 left-3 sm:left-6",
1212
1311
  "top-right": "top-24 right-3 sm:right-6",
1213
1312
  "top-left": "top-24 left-3 sm:left-6"
1214
1313
  };
1215
- function vt({
1216
- messages: t,
1217
- isLoading: e,
1314
+ function Rt({
1315
+ messages: e,
1316
+ isLoading: t,
1218
1317
  isStreaming: r = !1,
1219
1318
  streamingMessageId: n = null,
1220
1319
  error: s,
1221
1320
  canRetry: o = !1,
1222
1321
  onSend: i,
1223
- onStop: u,
1322
+ onStop: l,
1224
1323
  onRetry: c,
1225
- onClose: l,
1226
- title: f = "Chat",
1227
- subtitle: y = "Ask me anything",
1228
- welcomeMessage: I = "Hi! How can I help you today?",
1229
- placeholder: E,
1324
+ onClose: u,
1325
+ title: d = "Chat",
1326
+ subtitle: x = "Ask me anything",
1327
+ welcomeMessage: N = "Hi! How can I help you today?",
1328
+ placeholder: R,
1230
1329
  position: T = "bottom-right",
1231
- translations: x,
1232
- isMobile: w = !1
1330
+ translations: p,
1331
+ isMobile: v = !1
1233
1332
  }) {
1234
- const C = Le(), v = O(null), g = O(null), [S, j] = A(null);
1235
- gt(v, !0);
1236
- const { offsetY: W } = ht(
1237
- g,
1238
- l,
1239
- w
1240
- ), $ = W !== 0, p = typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(prefers-reduced-motion: reduce)").matches : !1;
1241
- U(() => {
1242
- const h = g.current;
1243
- h && (h.scrollTop = h.scrollHeight);
1244
- }, [t, e]), U(() => {
1245
- const h = (F) => {
1246
- F.key === "Escape" && !F.isComposing && l();
1333
+ const k = Le(), H = I(null), w = I(null), [f, E] = L(null);
1334
+ pt(H, !0);
1335
+ const { offsetY: F } = mt(
1336
+ w,
1337
+ u,
1338
+ v
1339
+ ), W = F !== 0, y = typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(prefers-reduced-motion: reduce)").matches : !1;
1340
+ z(() => {
1341
+ const m = w.current;
1342
+ m && (m.scrollTop = m.scrollHeight);
1343
+ }, [e, t]), z(() => {
1344
+ const m = (V) => {
1345
+ V.key === "Escape" && !V.isComposing && u();
1247
1346
  };
1248
- return document.addEventListener("keydown", h), () => document.removeEventListener("keydown", h);
1249
- }, [l]);
1250
- const Y = (x == null ? void 0 : x.closeChat) ?? "Close chat", B = (x == null ? void 0 : x.chatMessages) ?? "Chat messages", _ = [...t].reverse().find((h) => h.role === "assistant");
1251
- return /* @__PURE__ */ b(
1347
+ return document.addEventListener("keydown", m), () => document.removeEventListener("keydown", m);
1348
+ }, [u]);
1349
+ const K = (p == null ? void 0 : p.closeChat) ?? "Close chat", B = (p == null ? void 0 : p.chatMessages) ?? "Chat messages", _ = [...e].reverse().find((m) => m.role === "assistant");
1350
+ return /* @__PURE__ */ g(
1252
1351
  "div",
1253
1352
  {
1254
- ref: v,
1353
+ ref: H,
1255
1354
  role: "dialog",
1256
- "aria-modal": w ? "true" : void 0,
1257
- "aria-labelledby": C,
1258
- className: w ? "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 ${wt[T]} 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`,
1259
- style: w && !p ? { transform: `translateY(${Math.max(0, W)}px)` } : void 0,
1260
- "data-dragging": $ || void 0,
1355
+ "aria-modal": v ? "true" : void 0,
1356
+ "aria-labelledby": k,
1357
+ className: v ? "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 ${vt[T]} 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`,
1358
+ style: v && !y ? { transform: `translateY(${Math.max(0, F)}px)` } : void 0,
1359
+ "data-dragging": W || void 0,
1261
1360
  children: [
1262
- w && /* @__PURE__ */ a("div", { className: "flex justify-center py-2", "aria-hidden": "true", children: /* @__PURE__ */ a("div", { className: "h-1 w-8 rounded-claudius-full bg-claudius-border" }) }),
1361
+ v && /* @__PURE__ */ a("div", { className: "flex justify-center py-2", "aria-hidden": "true", children: /* @__PURE__ */ a("div", { className: "h-1 w-8 rounded-claudius-full bg-claudius-border" }) }),
1263
1362
  /* @__PURE__ */ a(
1264
- lt,
1363
+ dt,
1265
1364
  {
1266
- title: f,
1267
- subtitle: y,
1268
- titleId: C,
1269
- closeLabel: Y,
1270
- onClose: l
1365
+ title: d,
1366
+ subtitle: x,
1367
+ titleId: k,
1368
+ closeLabel: K,
1369
+ onClose: u
1271
1370
  }
1272
1371
  ),
1273
- /* @__PURE__ */ b("div", { className: "relative flex-1 overflow-hidden", children: [
1274
- S && /* @__PURE__ */ a(
1372
+ /* @__PURE__ */ g("div", { className: "relative flex-1 overflow-hidden", children: [
1373
+ f && /* @__PURE__ */ a(
1275
1374
  ut,
1276
1375
  {
1277
- sources: S.sources,
1278
- onClose: () => j(null)
1376
+ sources: f.sources,
1377
+ onClose: () => E(null)
1279
1378
  }
1280
1379
  ),
1281
- /* @__PURE__ */ b(
1380
+ /* @__PURE__ */ g(
1282
1381
  "div",
1283
1382
  {
1284
- ref: g,
1383
+ ref: w,
1285
1384
  role: "log",
1286
1385
  "aria-label": B,
1287
1386
  className: "h-full space-y-3 overflow-y-auto px-4 py-4",
1288
1387
  children: [
1289
- t.length === 0 && !s && /* @__PURE__ */ a("div", { className: "mr-auto flex max-w-[85%]", children: /* @__PURE__ */ a("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: I }) }),
1290
- t.map((h) => /* @__PURE__ */ a(
1291
- nt,
1388
+ e.length === 0 && !s && /* @__PURE__ */ a("div", { className: "mr-auto flex max-w-[85%]", children: /* @__PURE__ */ a("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: N }) }),
1389
+ e.map((m) => /* @__PURE__ */ a(
1390
+ st,
1292
1391
  {
1293
- role: h.role,
1294
- content: h.content,
1295
- isStreaming: h.id === n,
1296
- sources: h.sources,
1297
- isSourceActive: (S == null ? void 0 : S.messageId) === h.id,
1392
+ role: m.role,
1393
+ content: m.content,
1394
+ isStreaming: m.id === n,
1395
+ sources: m.sources,
1396
+ toolUses: m.toolUses,
1397
+ toolUsedLabel: p == null ? void 0 : p.toolUsed,
1398
+ toolDetailsLabel: p == null ? void 0 : p.toolDetails,
1399
+ isSourceActive: (f == null ? void 0 : f.messageId) === m.id,
1298
1400
  onSourceClick: () => {
1299
- (S == null ? void 0 : S.messageId) === h.id ? j(null) : h.sources && h.sources.length > 0 && j({ messageId: h.id, sources: h.sources });
1401
+ (f == null ? void 0 : f.messageId) === m.id ? E(null) : m.sources && m.sources.length > 0 && E({ messageId: m.id, sources: m.sources });
1300
1402
  }
1301
1403
  },
1302
- h.id
1404
+ m.id
1303
1405
  )),
1304
- e && /* Once streamed tokens are rendering in a bubble, the typing
1305
- indicator is redundant — show it only until the first token. */
1306
- !(n !== null && t.some((h) => h.id === n)) && /* @__PURE__ */ a(
1307
- ft,
1406
+ t && /* Once streamed tokens are rendering in a bubble, the typing
1407
+ indicator is redundant — show it only until the first token.
1408
+ A tool-only placeholder (no text yet) keeps the indicator. */
1409
+ !(n !== null && e.some(
1410
+ (m) => m.id === n && m.content.length > 0
1411
+ )) && /* @__PURE__ */ a(
1412
+ ht,
1308
1413
  {
1309
- label: (x == null ? void 0 : x.typingIndicator) ?? "Assistant is typing"
1414
+ label: (p == null ? void 0 : p.typingIndicator) ?? "Assistant is typing"
1310
1415
  }
1311
1416
  ),
1312
1417
  s && /* @__PURE__ */ a(
1313
- dt,
1418
+ ft,
1314
1419
  {
1315
1420
  message: s,
1316
- retryLabel: (x == null ? void 0 : x.errorRetry) ?? "Retry",
1317
- onRetry: o && c && !e ? c : void 0
1421
+ retryLabel: (p == null ? void 0 : p.errorRetry) ?? "Retry",
1422
+ onRetry: o && c && !t ? c : void 0
1318
1423
  }
1319
1424
  )
1320
1425
  ]
@@ -1328,45 +1433,45 @@ function vt({
1328
1433
  "aria-live": "polite",
1329
1434
  "aria-atomic": "true",
1330
1435
  className: "sr-only",
1331
- children: _ && _.id !== n ? xt(_.content) : ""
1436
+ children: _ && _.id !== n ? wt(_.content) : ""
1332
1437
  }
1333
1438
  ),
1334
1439
  /* @__PURE__ */ a(
1335
- ot,
1440
+ it,
1336
1441
  {
1337
1442
  onSend: i,
1338
- isLoading: e,
1443
+ isLoading: t,
1339
1444
  isStreaming: r,
1340
- onStop: u,
1341
- placeholder: E,
1342
- translations: x
1445
+ onStop: l,
1446
+ placeholder: R,
1447
+ translations: p
1343
1448
  }
1344
1449
  )
1345
1450
  ]
1346
1451
  }
1347
1452
  );
1348
1453
  }
1349
- function Rt({
1350
- message: t,
1351
- position: e,
1454
+ function Et({
1455
+ message: e,
1456
+ position: t,
1352
1457
  onOpen: r,
1353
1458
  onDismiss: n,
1354
1459
  dismissLabel: s
1355
1460
  }) {
1356
- const o = e.startsWith("bottom"), i = e.endsWith("right"), u = [
1461
+ const o = t.startsWith("bottom"), i = t.endsWith("right"), l = [
1357
1462
  "claudius-greeting-bubble",
1358
1463
  "fixed z-40 max-w-xs",
1359
1464
  o ? "bottom-20" : "top-20",
1360
1465
  i ? "right-4" : "left-4"
1361
1466
  ].join(" ");
1362
- return /* @__PURE__ */ b("div", { className: u, role: "status", "aria-live": "polite", children: [
1467
+ return /* @__PURE__ */ g("div", { className: l, role: "status", "aria-live": "polite", children: [
1363
1468
  /* @__PURE__ */ a(
1364
1469
  "button",
1365
1470
  {
1366
1471
  type: "button",
1367
1472
  onClick: r,
1368
1473
  className: "block w-full rounded-claudius-lg bg-claudius-surface p-4 pr-8 text-left text-sm font-body text-claudius-text shadow-claudius-floating ring-1 ring-claudius-border transition hover:shadow-claudius-floating-hover focus:outline-none focus:ring-2 focus:ring-claudius-accent",
1369
- children: t
1474
+ children: e
1370
1475
  }
1371
1476
  ),
1372
1477
  /* @__PURE__ */ a(
@@ -1383,7 +1488,7 @@ function Rt({
1383
1488
  )
1384
1489
  ] });
1385
1490
  }
1386
- const we = {
1491
+ const Re = {
1387
1492
  // ChatWindow
1388
1493
  title: "Chat",
1389
1494
  subtitle: "Ask me anything",
@@ -1395,6 +1500,8 @@ const we = {
1395
1500
  placeholder: "Type your message...",
1396
1501
  sendMessage: "Send message",
1397
1502
  stopGenerating: "Stop generating",
1503
+ toolUsed: "Used tool:",
1504
+ toolDetails: "Tool details",
1398
1505
  typeYourMessage: "Type your message",
1399
1506
  // ChatToggleButton
1400
1507
  openChat: "Open chat",
@@ -1407,11 +1514,11 @@ const we = {
1407
1514
  errorRateLimitMinute: "Too many requests. Please wait a minute.",
1408
1515
  errorRateLimitHour: "Hourly limit reached. Please try again later.",
1409
1516
  errorRetry: "Retry"
1410
- }, Et = we;
1411
- function Kt(t) {
1412
- return { ...Et, ...t };
1517
+ }, Tt = Re;
1518
+ function qt(e) {
1519
+ return { ...Tt, ...e };
1413
1520
  }
1414
- const Tt = {
1521
+ const Mt = {
1415
1522
  // ChatWindow
1416
1523
  title: "Chat",
1417
1524
  subtitle: "Pregúntame lo que quieras",
@@ -1423,6 +1530,8 @@ const Tt = {
1423
1530
  placeholder: "Escribe tu mensaje...",
1424
1531
  sendMessage: "Enviar mensaje",
1425
1532
  stopGenerating: "Detener la respuesta",
1533
+ toolUsed: "Herramienta usada:",
1534
+ toolDetails: "Detalles de la herramienta",
1426
1535
  typeYourMessage: "Escribe tu mensaje",
1427
1536
  // ChatToggleButton
1428
1537
  openChat: "Abrir chat",
@@ -1435,7 +1544,7 @@ const Tt = {
1435
1544
  errorRateLimitMinute: "Demasiadas solicitudes. Espera un minuto.",
1436
1545
  errorRateLimitHour: "Has alcanzado el límite por hora. Inténtalo más tarde.",
1437
1546
  errorRetry: "Reintentar"
1438
- }, Mt = {
1547
+ }, St = {
1439
1548
  // ChatWindow
1440
1549
  title: "Chat",
1441
1550
  subtitle: "Posez-moi vos questions",
@@ -1447,6 +1556,8 @@ const Tt = {
1447
1556
  placeholder: "Saisissez votre message...",
1448
1557
  sendMessage: "Envoyer le message",
1449
1558
  stopGenerating: "Arrêter la génération",
1559
+ toolUsed: "Outil utilisé :",
1560
+ toolDetails: "Détails de l'outil",
1450
1561
  typeYourMessage: "Saisissez votre message",
1451
1562
  // ChatToggleButton
1452
1563
  openChat: "Ouvrir le chat",
@@ -1459,7 +1570,7 @@ const Tt = {
1459
1570
  errorRateLimitMinute: "Trop de requêtes. Veuillez patienter une minute.",
1460
1571
  errorRateLimitHour: "Limite horaire atteinte. Veuillez réessayer plus tard.",
1461
1572
  errorRetry: "Réessayer"
1462
- }, St = {
1573
+ }, Ct = {
1463
1574
  // ChatWindow
1464
1575
  title: "Chat",
1465
1576
  subtitle: "Fragen Sie mich alles",
@@ -1471,6 +1582,8 @@ const Tt = {
1471
1582
  placeholder: "Geben Sie Ihre Nachricht ein...",
1472
1583
  sendMessage: "Nachricht senden",
1473
1584
  stopGenerating: "Generierung stoppen",
1585
+ toolUsed: "Verwendetes Tool:",
1586
+ toolDetails: "Tool-Details",
1474
1587
  typeYourMessage: "Geben Sie Ihre Nachricht ein",
1475
1588
  // ChatToggleButton
1476
1589
  openChat: "Chat öffnen",
@@ -1483,28 +1596,28 @@ const Tt = {
1483
1596
  errorRateLimitMinute: "Zu viele Anfragen. Bitte warten Sie eine Minute.",
1484
1597
  errorRateLimitHour: "Stündliches Limit erreicht. Bitte versuchen Sie es später erneut.",
1485
1598
  errorRetry: "Erneut versuchen"
1486
- }, ve = {
1487
- en: we,
1488
- es: Tt,
1489
- fr: Mt,
1490
- de: St
1599
+ }, Ee = {
1600
+ en: Re,
1601
+ es: Mt,
1602
+ fr: St,
1603
+ de: Ct
1491
1604
  };
1492
- function pe(t) {
1493
- if (!t) return;
1494
- const e = t.toLowerCase().split("-")[0];
1495
- return Object.prototype.hasOwnProperty.call(ve, e) ? e : void 0;
1605
+ function be(e) {
1606
+ if (!e) return;
1607
+ const t = e.toLowerCase().split("-")[0];
1608
+ return Object.prototype.hasOwnProperty.call(Ee, t) ? t : void 0;
1496
1609
  }
1497
- function Ct() {
1498
- const t = typeof document < "u" ? pe(document.documentElement.lang) : void 0;
1499
- if (t) return t;
1500
- const e = typeof navigator < "u" ? pe(navigator.language) : void 0;
1501
- return e || "en";
1610
+ function Nt() {
1611
+ const e = typeof document < "u" ? be(document.documentElement.lang) : void 0;
1612
+ if (e) return e;
1613
+ const t = typeof navigator < "u" ? be(navigator.language) : void 0;
1614
+ return t || "en";
1502
1615
  }
1503
- function Nt(t = {}) {
1504
- const { locale: e, translations: r } = t, n = ve[e ?? Ct()];
1616
+ function kt(e = {}) {
1617
+ const { locale: t, translations: r } = e, n = Ee[t ?? Nt()];
1505
1618
  return r ? { ...n, ...r } : { ...n };
1506
1619
  }
1507
- const be = [
1620
+ const ye = [
1508
1621
  "accent",
1509
1622
  "accentText",
1510
1623
  "accentSoft",
@@ -1524,11 +1637,11 @@ const be = [
1524
1637
  "errorText",
1525
1638
  "link",
1526
1639
  "scrim"
1527
- ], kt = ["sm", "md", "lg", "full", "tail"], Lt = [
1640
+ ], Lt = ["sm", "md", "lg", "full", "tail"], At = [
1528
1641
  "elevated",
1529
1642
  "floating",
1530
1643
  "floatingHover"
1531
- ], At = ["heading", "body"], Re = {
1644
+ ], Ot = ["heading", "body"], Te = {
1532
1645
  default: {
1533
1646
  name: "default"
1534
1647
  },
@@ -1613,87 +1726,87 @@ const be = [
1613
1726
  }
1614
1727
  }
1615
1728
  };
1616
- function Ot(t) {
1617
- return Object.prototype.hasOwnProperty.call(Re, t);
1729
+ function It(e) {
1730
+ return Object.prototype.hasOwnProperty.call(Te, e);
1618
1731
  }
1619
- const It = /* @__PURE__ */ new Set(["light", "dark", "auto"]);
1620
- function Dt(t) {
1621
- if (t === void 0)
1732
+ const Dt = /* @__PURE__ */ new Set(["light", "dark", "auto"]);
1733
+ function _t(e) {
1734
+ if (e === void 0)
1622
1735
  return { mode: "light" };
1623
- if (typeof t == "string") {
1624
- if (It.has(t))
1625
- return { mode: t };
1626
- if (Ot(t)) {
1627
- const e = Re[t];
1628
- return { mode: e.colorScheme ?? "light", theme: e };
1736
+ if (typeof e == "string") {
1737
+ if (Dt.has(e))
1738
+ return { mode: e };
1739
+ if (It(e)) {
1740
+ const t = Te[e];
1741
+ return { mode: t.colorScheme ?? "light", theme: t };
1629
1742
  }
1630
- return { mode: "light", url: t };
1743
+ return { mode: "light", url: e };
1631
1744
  }
1632
- return { mode: t.colorScheme ?? "light", theme: t };
1745
+ return { mode: e.colorScheme ?? "light", theme: e };
1633
1746
  }
1634
- function _t(t) {
1635
- return t.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`);
1747
+ function jt(e) {
1748
+ return e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`);
1636
1749
  }
1637
- function Ht(t, e) {
1750
+ function Ht(e, t) {
1638
1751
  console.warn(
1639
- `[Claudius] Ignoring unknown theme token "${e}" in "${t}"`
1752
+ `[Claudius] Ignoring unknown theme token "${t}" in "${e}"`
1640
1753
  );
1641
1754
  }
1642
- function X(t, e, r, n, s, o = "") {
1755
+ function Q(e, t, r, n, s, o = "") {
1643
1756
  if (s)
1644
- for (const [i, u] of Object.entries(s)) {
1757
+ for (const [i, l] of Object.entries(s)) {
1645
1758
  if (!n.includes(i)) {
1646
- Ht(e, i);
1759
+ Ht(t, i);
1647
1760
  continue;
1648
1761
  }
1649
- typeof u == "string" && (t[`${r}${_t(i)}${o}`] = u);
1762
+ typeof l == "string" && (e[`${r}${jt(i)}${o}`] = l);
1650
1763
  }
1651
1764
  }
1652
- function jt(t) {
1653
- const e = {};
1654
- X(e, "colors", "--cl-color-", be, t.colors);
1655
- for (const [r, n] of Object.entries({ ...e }))
1656
- e[`${r}-dark`] = n;
1657
- return X(
1658
- e,
1765
+ function Bt(e) {
1766
+ const t = {};
1767
+ Q(t, "colors", "--cl-color-", ye, e.colors);
1768
+ for (const [r, n] of Object.entries({ ...t }))
1769
+ t[`${r}-dark`] = n;
1770
+ return Q(
1771
+ t,
1659
1772
  "colorsDark",
1660
1773
  "--cl-color-",
1661
- be,
1662
- t.colorsDark,
1774
+ ye,
1775
+ e.colorsDark,
1663
1776
  "-dark"
1664
- ), X(e, "radii", "--cl-radius-", kt, t.radii), X(e, "shadows", "--cl-shadow-", Lt, t.shadows), X(e, "fonts", "--cl-font-", At, t.fonts), e;
1777
+ ), Q(t, "radii", "--cl-radius-", Lt, e.radii), Q(t, "shadows", "--cl-shadow-", At, e.shadows), Q(t, "fonts", "--cl-font-", Ot, e.fonts), t;
1665
1778
  }
1666
- function Bt(t) {
1667
- return typeof t == "object" && t !== null && !Array.isArray(t);
1779
+ function $t(e) {
1780
+ return typeof e == "object" && e !== null && !Array.isArray(e);
1668
1781
  }
1669
- function $t(t) {
1670
- const e = ne(() => Dt(t), [t]), [r, n] = A(null), s = e.url;
1671
- U(() => {
1782
+ function Pt(e) {
1783
+ const t = se(() => _t(e), [e]), [r, n] = L(null), s = t.url;
1784
+ z(() => {
1672
1785
  if (n(null), !s) return;
1673
1786
  const c = new AbortController();
1674
- return fetch(s, { signal: c.signal }).then((l) => {
1675
- if (!l.ok)
1676
- throw new Error(`HTTP ${l.status}`);
1677
- return l.json();
1678
- }).then((l) => {
1679
- if (!Bt(l))
1787
+ return fetch(s, { signal: c.signal }).then((u) => {
1788
+ if (!u.ok)
1789
+ throw new Error(`HTTP ${u.status}`);
1790
+ return u.json();
1791
+ }).then((u) => {
1792
+ if (!$t(u))
1680
1793
  throw new Error("theme JSON must be an object");
1681
- n(l);
1682
- }).catch((l) => {
1683
- c.signal.aborted || console.error(`[Claudius] Failed to load theme from ${s}:`, l);
1794
+ n(u);
1795
+ }).catch((u) => {
1796
+ c.signal.aborted || console.error(`[Claudius] Failed to load theme from ${s}:`, u);
1684
1797
  }), () => c.abort();
1685
1798
  }, [s]);
1686
- const o = e.theme ?? r ?? null, i = (r == null ? void 0 : r.colorScheme) ?? e.mode, u = ne(
1687
- () => o ? jt(o) : {},
1799
+ const o = t.theme ?? r ?? null, i = (r == null ? void 0 : r.colorScheme) ?? t.mode, l = se(
1800
+ () => o ? Bt(o) : {},
1688
1801
  [o]
1689
1802
  );
1690
- return { mode: i, cssVars: u };
1803
+ return { mode: i, cssVars: l };
1691
1804
  }
1692
- const Ee = "claudius:triggers:dismissed";
1693
- function Pt() {
1805
+ const Me = "claudius:triggers:dismissed";
1806
+ function Ut() {
1694
1807
  if (typeof window > "u") return !1;
1695
1808
  try {
1696
- return window.sessionStorage.getItem(Ee) === "1";
1809
+ return window.sessionStorage.getItem(Me) === "1";
1697
1810
  } catch {
1698
1811
  return !1;
1699
1812
  }
@@ -1701,152 +1814,152 @@ function Pt() {
1701
1814
  function Gt() {
1702
1815
  if (!(typeof window > "u"))
1703
1816
  try {
1704
- window.sessionStorage.setItem(Ee, "1");
1817
+ window.sessionStorage.setItem(Me, "1");
1705
1818
  } catch {
1706
1819
  }
1707
1820
  }
1708
- function qt({
1709
- apiUrl: t,
1710
- title: e,
1821
+ function Jt({
1822
+ apiUrl: e,
1823
+ title: t,
1711
1824
  subtitle: r,
1712
1825
  welcomeMessage: n,
1713
1826
  placeholder: s,
1714
1827
  persistMessages: o,
1715
1828
  storageKeyPrefix: i,
1716
- requestTimeoutMs: u,
1829
+ requestTimeoutMs: l,
1717
1830
  theme: c = "light",
1718
- accentColor: l,
1719
- position: f = "bottom-right",
1720
- locale: y,
1721
- translations: I,
1722
- triggers: E,
1831
+ accentColor: u,
1832
+ position: d = "bottom-right",
1833
+ locale: x,
1834
+ translations: N,
1835
+ triggers: R,
1723
1836
  plugins: T,
1724
- streaming: x = !0
1837
+ streaming: p = !0
1725
1838
  }) {
1726
- const [w, C] = A(!1), [v, g] = A(null), [S, j] = A(Pt), W = O(!1), $ = Ue("(max-width: 639px)"), p = ne(
1727
- () => Nt({ locale: y, translations: I }),
1728
- [y, I]
1839
+ const [v, k] = L(!1), [H, w] = L(null), [f, E] = L(Ut), F = I(!1), W = Ge("(max-width: 639px)"), y = se(
1840
+ () => kt({ locale: x, translations: N }),
1841
+ [x, N]
1729
1842
  ), {
1730
- messages: Y,
1843
+ messages: K,
1731
1844
  isLoading: B,
1732
1845
  isStreaming: _,
1733
- streamingMessageId: h,
1734
- error: F,
1735
- canRetry: Z,
1736
- sendMessage: K,
1737
- stop: se,
1738
- retry: oe
1739
- } = Ge({
1740
- apiUrl: t,
1846
+ streamingMessageId: m,
1847
+ error: V,
1848
+ canRetry: ee,
1849
+ sendMessage: J,
1850
+ stop: oe,
1851
+ retry: ie
1852
+ } = Ue({
1853
+ apiUrl: e,
1741
1854
  persistMessages: o,
1742
1855
  storageKeyPrefix: i,
1743
- timeoutMs: u,
1744
- translations: p,
1856
+ timeoutMs: l,
1857
+ translations: y,
1745
1858
  plugins: T,
1746
- streaming: x
1747
- }), Q = O(null), ee = O(w), { mode: d, cssVars: N } = $t(c), [k, V] = A(!1);
1748
- U(() => {
1749
- if (d !== "auto") return;
1750
- const G = window.matchMedia("(prefers-color-scheme: dark)");
1751
- V(G.matches);
1752
- const fe = (Me) => V(Me.matches);
1753
- return G.addEventListener("change", fe), () => G.removeEventListener("change", fe);
1754
- }, [d]), U(() => {
1755
- var G;
1756
- ee.current && !w && ((G = Q.current) == null || G.focus()), ee.current = w;
1757
- }, [w]);
1758
- const m = L(() => {
1759
- j(!0), Gt();
1760
- }, []), R = L(() => {
1761
- C(!1), W.current && (W.current = !1, m());
1762
- }, [m]), D = L(() => {
1763
- C((G) => !G);
1764
- }, []), M = L(() => {
1765
- W.current = !0, g(null), C(!0);
1766
- }, []), z = L((G) => {
1767
- g(G);
1768
- }, []), P = L(() => {
1769
- g(null), M();
1770
- }, [M]), J = L(() => {
1771
- g(null), m();
1772
- }, [m]);
1859
+ streaming: p
1860
+ }), te = I(null), re = I(v), { mode: h, cssVars: A } = Pt(c), [S, Y] = L(!1);
1861
+ z(() => {
1862
+ if (h !== "auto") return;
1863
+ const D = window.matchMedia("(prefers-color-scheme: dark)");
1864
+ Y(D.matches);
1865
+ const he = (Se) => Y(Se.matches);
1866
+ return D.addEventListener("change", he), () => D.removeEventListener("change", he);
1867
+ }, [h]), z(() => {
1868
+ var D;
1869
+ re.current && !v && ((D = te.current) == null || D.focus()), re.current = v;
1870
+ }, [v]);
1871
+ const $ = O(() => {
1872
+ E(!0), Gt();
1873
+ }, []), b = O(() => {
1874
+ k(!1), F.current && (F.current = !1, $());
1875
+ }, [$]), C = O(() => {
1876
+ k((D) => !D);
1877
+ }, []), M = O(() => {
1878
+ F.current = !0, w(null), k(!0);
1879
+ }, []), P = O((D) => {
1880
+ w(D);
1881
+ }, []), U = O(() => {
1882
+ w(null), M();
1883
+ }, [M]), Z = O(() => {
1884
+ w(null), $();
1885
+ }, [$]);
1773
1886
  ze({
1774
- triggers: E,
1775
- enabled: !S && !w,
1887
+ triggers: R,
1888
+ enabled: !f && !v,
1776
1889
  onOpen: M,
1777
- onGreeting: z
1890
+ onGreeting: P
1778
1891
  });
1779
- const de = d === "dark" || d === "auto" && k, te = {
1780
- ...N,
1781
- ...l ? {
1782
- "--cl-color-accent": l,
1783
- "--cl-color-accent-dark": l
1892
+ const G = h === "dark" || h === "auto" && S, q = {
1893
+ ...A,
1894
+ ...u ? {
1895
+ "--cl-color-accent": u,
1896
+ "--cl-color-accent-dark": u
1784
1897
  } : {}
1785
- }, Te = Object.keys(te).length > 0 ? te : void 0;
1898
+ }, ae = Object.keys(q).length > 0 ? q : void 0;
1786
1899
  return (
1787
1900
  // Outer div carries theme token vars; the inner div carries the dark-mode
1788
1901
  // attribute so the [data-claudius-dark] token reassignments in styles.css
1789
1902
  // beat inherited (inline) light values.
1790
- /* @__PURE__ */ a("div", { className: "claudius-root", style: Te, children: /* @__PURE__ */ b("div", { "data-claudius-dark": de ? "true" : "false", children: [
1791
- w && $ && /* @__PURE__ */ a(
1903
+ /* @__PURE__ */ a("div", { className: "claudius-root", style: ae, children: /* @__PURE__ */ g("div", { "data-claudius-dark": G ? "true" : "false", children: [
1904
+ v && W && /* @__PURE__ */ a(
1792
1905
  "div",
1793
1906
  {
1794
1907
  className: "claudius-scrim fixed inset-0 z-40 bg-claudius-scrim",
1795
- onClick: R,
1908
+ onClick: b,
1796
1909
  "aria-hidden": "true"
1797
1910
  }
1798
1911
  ),
1799
- w && /* @__PURE__ */ a(
1800
- vt,
1912
+ v && /* @__PURE__ */ a(
1913
+ Rt,
1801
1914
  {
1802
- messages: Y,
1915
+ messages: K,
1803
1916
  isLoading: B,
1804
1917
  isStreaming: _,
1805
- streamingMessageId: h,
1806
- error: F,
1807
- canRetry: Z,
1808
- onSend: K,
1809
- onStop: se,
1810
- onRetry: oe,
1811
- onClose: R,
1812
- title: e ?? p.title,
1813
- subtitle: r ?? p.subtitle,
1814
- welcomeMessage: n ?? p.welcomeMessage,
1815
- placeholder: s ?? p.placeholder,
1816
- position: f,
1817
- translations: p,
1818
- isMobile: $
1918
+ streamingMessageId: m,
1919
+ error: V,
1920
+ canRetry: ee,
1921
+ onSend: J,
1922
+ onStop: oe,
1923
+ onRetry: ie,
1924
+ onClose: b,
1925
+ title: t ?? y.title,
1926
+ subtitle: r ?? y.subtitle,
1927
+ welcomeMessage: n ?? y.welcomeMessage,
1928
+ placeholder: s ?? y.placeholder,
1929
+ position: d,
1930
+ translations: y,
1931
+ isMobile: W
1819
1932
  }
1820
1933
  ),
1821
- !(w && $) && /* @__PURE__ */ a(
1822
- Ye,
1934
+ !(v && W) && /* @__PURE__ */ a(
1935
+ Ve,
1823
1936
  {
1824
- ref: Q,
1825
- isOpen: w,
1826
- onClick: D,
1827
- position: f,
1828
- translations: p
1937
+ ref: te,
1938
+ isOpen: v,
1939
+ onClick: C,
1940
+ position: d,
1941
+ translations: y
1829
1942
  }
1830
1943
  ),
1831
- !w && v && /* @__PURE__ */ a(
1832
- Rt,
1944
+ !v && H && /* @__PURE__ */ a(
1945
+ Et,
1833
1946
  {
1834
- message: v,
1835
- position: f,
1836
- onOpen: P,
1837
- onDismiss: J,
1838
- dismissLabel: p.dismissGreeting
1947
+ message: H,
1948
+ position: d,
1949
+ onOpen: U,
1950
+ onDismiss: Z,
1951
+ dismissLabel: y.dismissGreeting
1839
1952
  }
1840
1953
  )
1841
1954
  ] }) })
1842
1955
  );
1843
1956
  }
1844
- function Jt(t) {
1845
- const { onEvent: e, includeContent: r = !0 } = t, n = (s) => r ? s : "";
1957
+ function Xt(e) {
1958
+ const { onEvent: t, includeContent: r = !0 } = e, n = (s) => r ? s : "";
1846
1959
  return {
1847
1960
  name: "analytics",
1848
1961
  onBeforeSend(s) {
1849
- e({
1962
+ t({
1850
1963
  type: "message_sent",
1851
1964
  role: "user",
1852
1965
  content: n(s.content),
@@ -1854,7 +1967,7 @@ function Jt(t) {
1854
1967
  });
1855
1968
  },
1856
1969
  onAfterReceive(s) {
1857
- e({
1970
+ t({
1858
1971
  type: "message_received",
1859
1972
  role: "assistant",
1860
1973
  content: n(s.content),
@@ -1862,7 +1975,7 @@ function Jt(t) {
1862
1975
  });
1863
1976
  },
1864
1977
  onError(s) {
1865
- e({
1978
+ t({
1866
1979
  type: "chat_error",
1867
1980
  message: s.message,
1868
1981
  code: s.code
@@ -1870,7 +1983,7 @@ function Jt(t) {
1870
1983
  }
1871
1984
  };
1872
1985
  }
1873
- const Ut = [
1986
+ const Wt = [
1874
1987
  // Email
1875
1988
  /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g,
1876
1989
  // US SSN (before the looser card pattern so it wins on 9-digit groups)
@@ -1880,20 +1993,20 @@ const Ut = [
1880
1993
  // Phone: optional +1, area code, 7 digits with common separators
1881
1994
  /\b(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b/g
1882
1995
  ];
1883
- function Wt(t, e, r) {
1884
- return e.reduce(
1996
+ function zt(e, t, r) {
1997
+ return t.reduce(
1885
1998
  // Reset lastIndex defensively: a shared global regex is stateful.
1886
1999
  (n, s) => (s.lastIndex = 0, n.replace(s, r)),
1887
- t
2000
+ e
1888
2001
  );
1889
2002
  }
1890
- function Xt(t = {}) {
2003
+ function Zt(e = {}) {
1891
2004
  const {
1892
- patterns: e = Ut,
2005
+ patterns: t = Wt,
1893
2006
  replacement: r = "[redacted]",
1894
2007
  redactReplies: n = !1
1895
- } = t, s = (o) => {
1896
- const i = Wt(o.content, e, r);
2008
+ } = e, s = (o) => {
2009
+ const i = zt(o.content, t, r);
1897
2010
  if (i !== o.content)
1898
2011
  return { ...o, content: i };
1899
2012
  };
@@ -1903,16 +2016,16 @@ function Xt(t = {}) {
1903
2016
  onAfterReceive: n ? s : void 0
1904
2017
  };
1905
2018
  }
1906
- function zt(t, e, r) {
1907
- return typeof t == "function" ? t(e) : t instanceof RegExp ? t.test(e) : r ? e.includes(t) : e.toLowerCase().includes(t.toLowerCase());
2019
+ function Ft(e, t, r) {
2020
+ return typeof e == "function" ? e(t) : e instanceof RegExp ? e.test(t) : r ? t.includes(e) : t.toLowerCase().includes(e.toLowerCase());
1908
2021
  }
1909
- function Zt(t) {
1910
- const { rules: e, caseSensitive: r = !1 } = t;
2022
+ function Qt(e) {
2023
+ const { rules: t, caseSensitive: r = !1 } = e;
1911
2024
  return {
1912
2025
  name: "canned-responses",
1913
2026
  onBeforeSend(n, s) {
1914
- for (const o of e)
1915
- if (zt(o.match, n.content, r)) {
2027
+ for (const o of t)
2028
+ if (Ft(o.match, n.content, r)) {
1916
2029
  s.respondWith(o.reply);
1917
2030
  return;
1918
2031
  }
@@ -1921,18 +2034,18 @@ function Zt(t) {
1921
2034
  }
1922
2035
  export {
1923
2036
  Oe as ChatApiClient,
1924
- H as ChatApiError,
1925
- qt as ChatWidget,
1926
- Ut as DEFAULT_PII_PATTERNS,
1927
- ae as DebounceError,
1928
- Re as builtinThemes,
1929
- Kt as createTranslations,
1930
- Et as defaultTranslations,
1931
- Ct as detectLocale,
1932
- ve as locales,
1933
- Jt as pluginAnalytics,
1934
- Zt as pluginCannedResponses,
1935
- Xt as pluginRedactPII,
1936
- Wt as redactText,
1937
- Nt as resolveTranslations
2037
+ j as ChatApiError,
2038
+ Jt as ChatWidget,
2039
+ Wt as DEFAULT_PII_PATTERNS,
2040
+ le as DebounceError,
2041
+ Te as builtinThemes,
2042
+ qt as createTranslations,
2043
+ Tt as defaultTranslations,
2044
+ Nt as detectLocale,
2045
+ Ee as locales,
2046
+ Xt as pluginAnalytics,
2047
+ Qt as pluginCannedResponses,
2048
+ Zt as pluginRedactPII,
2049
+ zt as redactText,
2050
+ kt as resolveTranslations
1938
2051
  };