claudius-chat-widget 1.6.0 → 1.8.2
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.cjs +1 -1
- package/dist/claudius.iife.js +11 -11
- package/dist/claudius.js +210 -153
- package/dist/index.d.cts +422 -0
- package/dist/index.d.ts +422 -12
- package/package.json +19 -6
- package/dist/api/client.d.ts +0 -24
- package/dist/api/errors.d.ts +0 -9
- package/dist/api/index.d.ts +0 -4
- package/dist/api/types.d.ts +0 -22
- package/dist/components/ChatInput.d.ts +0 -9
- package/dist/components/ChatMessage.d.ts +0 -10
- package/dist/components/ChatSources.d.ts +0 -7
- package/dist/components/ChatToggleButton.d.ts +0 -10
- package/dist/components/ChatWidget.d.ts +0 -29
- package/dist/components/ChatWindow.d.ts +0 -21
- package/dist/components/GreetingBubble.d.ts +0 -10
- package/dist/components/SourceIcon.d.ts +0 -7
- package/dist/embed.d.ts +0 -38
- package/dist/hooks/useChat.d.ts +0 -20
- package/dist/hooks/useFocusTrap.d.ts +0 -2
- package/dist/hooks/useMediaQuery.d.ts +0 -1
- package/dist/hooks/useSwipeToDismiss.d.ts +0 -4
- package/dist/hooks/useTriggers.d.ts +0 -32
- package/dist/i18n.d.ts +0 -21
- package/dist/locales/de.d.ts +0 -2
- package/dist/locales/en.d.ts +0 -2
- package/dist/locales/es.d.ts +0 -2
- package/dist/locales/fr.d.ts +0 -2
- package/dist/locales/index.d.ts +0 -9
- package/dist/main.d.ts +0 -1
- package/dist/test-utils/MockChatApiClient.d.ts +0 -64
- package/dist/theme/index.d.ts +0 -4
- package/dist/theme/resolve.d.ts +0 -19
- package/dist/theme/themes.d.ts +0 -8
- package/dist/theme/types.d.ts +0 -34
- package/dist/theme/useTheme.d.ts +0 -14
- package/dist/utils/sanitize.d.ts +0 -36
- package/dist/utils/stripAnnouncementFormatting.d.ts +0 -1
package/dist/claudius.js
CHANGED
|
@@ -4,17 +4,32 @@ var $ = (t, e, r) => we(t, typeof e != "symbol" ? e + "" : e, r);
|
|
|
4
4
|
import { jsx as i, jsxs as d, Fragment as ve } from "react/jsx-runtime";
|
|
5
5
|
import { useMemo as F, useState as C, useRef as N, useCallback as R, useEffect as k, forwardRef as Ee, memo as K, useId as Re } from "react";
|
|
6
6
|
class U extends Error {
|
|
7
|
+
/**
|
|
8
|
+
* Create a {@link ChatApiError}.
|
|
9
|
+
*
|
|
10
|
+
* @param message - Human-readable error message.
|
|
11
|
+
* @param status - HTTP status code, or `0` for network and timeout failures.
|
|
12
|
+
* @param code - Optional machine-readable error code (e.g. `"TIMEOUT"`, `"NETWORK_ERROR"`).
|
|
13
|
+
* @param retryAfter - Seconds to wait before retrying, from the `Retry-After` header.
|
|
14
|
+
*/
|
|
7
15
|
constructor(e, r, s, n) {
|
|
8
16
|
super(e), this.status = r, this.code = s, this.retryAfter = n, this.name = "ChatApiError";
|
|
9
17
|
}
|
|
10
18
|
}
|
|
11
19
|
class se extends Error {
|
|
20
|
+
/** Creates a `DebounceError` with a fixed message. */
|
|
12
21
|
constructor() {
|
|
13
22
|
super("Request debounced"), this.name = "DebounceError";
|
|
14
23
|
}
|
|
15
24
|
}
|
|
16
25
|
const Te = 3e4;
|
|
17
26
|
class Me {
|
|
27
|
+
/**
|
|
28
|
+
* Create a chat client for the given Worker base URL.
|
|
29
|
+
*
|
|
30
|
+
* @param baseUrl - Base URL of the Worker. Requests post to `${baseUrl}/api/chat`.
|
|
31
|
+
* @param options - Optional retry, debounce, and timeout settings.
|
|
32
|
+
*/
|
|
18
33
|
constructor(e, r) {
|
|
19
34
|
$(this, "baseUrl");
|
|
20
35
|
$(this, "maxRetries");
|
|
@@ -23,6 +38,16 @@ class Me {
|
|
|
23
38
|
$(this, "lastSendTime", 0);
|
|
24
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) ?? Te;
|
|
25
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Send the conversation to the chat endpoint and return the assistant's
|
|
43
|
+
* reply, retrying transient failures with backoff up to
|
|
44
|
+
* {@link ChatApiClientOptions.maxRetries} times.
|
|
45
|
+
*
|
|
46
|
+
* @param messages - The full conversation so far, oldest message first.
|
|
47
|
+
* @returns The assistant's reply and any cited sources.
|
|
48
|
+
* @throws {@link DebounceError} when called within the debounce window.
|
|
49
|
+
* @throws {@link ChatApiError} when the request fails after all retries.
|
|
50
|
+
*/
|
|
26
51
|
async sendMessage(e) {
|
|
27
52
|
if (this.debounceMs > 0 && Date.now() - this.lastSendTime < this.debounceMs)
|
|
28
53
|
throw new se();
|
|
@@ -107,7 +132,7 @@ class Me {
|
|
|
107
132
|
}
|
|
108
133
|
}
|
|
109
134
|
const Ce = 200, Ne = "claudius:messages";
|
|
110
|
-
function
|
|
135
|
+
function Le(t, e) {
|
|
111
136
|
let r;
|
|
112
137
|
try {
|
|
113
138
|
r = new URL(e).host;
|
|
@@ -123,7 +148,7 @@ function V() {
|
|
|
123
148
|
return null;
|
|
124
149
|
}
|
|
125
150
|
}
|
|
126
|
-
function
|
|
151
|
+
function Se(t) {
|
|
127
152
|
const e = V();
|
|
128
153
|
if (!e) return [];
|
|
129
154
|
try {
|
|
@@ -145,7 +170,7 @@ function ke({
|
|
|
145
170
|
const o = F(
|
|
146
171
|
() => new Me(t, { debounceMs: 0, timeoutMs: s }),
|
|
147
172
|
[t, s]
|
|
148
|
-
), a =
|
|
173
|
+
), a = Le(r, t), l = e ? Se(a) : [], [c, u] = C(l), [h, E] = C(!1), [g, x] = C(null), [f, w] = C(!1), v = N(l.length), y = N(!1), T = N(l), O = R(
|
|
149
174
|
(m) => {
|
|
150
175
|
if (!e) return;
|
|
151
176
|
const p = V();
|
|
@@ -186,8 +211,8 @@ function ke({
|
|
|
186
211
|
role: "assistant",
|
|
187
212
|
content: p.reply,
|
|
188
213
|
sources: p.sources
|
|
189
|
-
},
|
|
190
|
-
T.current =
|
|
214
|
+
}, L = [...m, H];
|
|
215
|
+
T.current = L, u(L), O(L);
|
|
191
216
|
} catch (p) {
|
|
192
217
|
if (p instanceof se) return;
|
|
193
218
|
p instanceof U ? x(I(p.code, p.message)) : x(
|
|
@@ -206,8 +231,8 @@ function ke({
|
|
|
206
231
|
id: A(),
|
|
207
232
|
role: "user",
|
|
208
233
|
content: p
|
|
209
|
-
},
|
|
210
|
-
T.current =
|
|
234
|
+
}, L = [...T.current, H];
|
|
235
|
+
T.current = L, u(L), O(L), await D(L);
|
|
211
236
|
},
|
|
212
237
|
[O, D]
|
|
213
238
|
), b = R(async () => {
|
|
@@ -636,7 +661,103 @@ const Ve = K(function({
|
|
|
636
661
|
] }, o.type)) })
|
|
637
662
|
] });
|
|
638
663
|
});
|
|
639
|
-
function Ke(
|
|
664
|
+
function Ke({
|
|
665
|
+
title: t,
|
|
666
|
+
subtitle: e,
|
|
667
|
+
titleId: r,
|
|
668
|
+
closeLabel: s,
|
|
669
|
+
onClose: n
|
|
670
|
+
}) {
|
|
671
|
+
return /* @__PURE__ */ d("div", { className: "flex items-center gap-3 bg-claudius-accent px-5 py-4", children: [
|
|
672
|
+
/* @__PURE__ */ i(
|
|
673
|
+
"div",
|
|
674
|
+
{
|
|
675
|
+
"aria-hidden": "true",
|
|
676
|
+
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",
|
|
677
|
+
children: t.charAt(0).toUpperCase()
|
|
678
|
+
}
|
|
679
|
+
),
|
|
680
|
+
/* @__PURE__ */ d("div", { className: "flex-1", children: [
|
|
681
|
+
/* @__PURE__ */ i(
|
|
682
|
+
"h2",
|
|
683
|
+
{
|
|
684
|
+
id: r,
|
|
685
|
+
className: "text-sm font-heading font-semibold text-claudius-accent-text",
|
|
686
|
+
children: t
|
|
687
|
+
}
|
|
688
|
+
),
|
|
689
|
+
/* @__PURE__ */ i("p", { className: "text-xs text-claudius-accent-text", children: e })
|
|
690
|
+
] }),
|
|
691
|
+
/* @__PURE__ */ i(
|
|
692
|
+
"button",
|
|
693
|
+
{
|
|
694
|
+
onClick: n,
|
|
695
|
+
"aria-label": s,
|
|
696
|
+
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",
|
|
697
|
+
children: /* @__PURE__ */ d(
|
|
698
|
+
"svg",
|
|
699
|
+
{
|
|
700
|
+
width: "18",
|
|
701
|
+
height: "18",
|
|
702
|
+
viewBox: "0 0 24 24",
|
|
703
|
+
fill: "none",
|
|
704
|
+
stroke: "currentColor",
|
|
705
|
+
strokeWidth: "2",
|
|
706
|
+
strokeLinecap: "round",
|
|
707
|
+
strokeLinejoin: "round",
|
|
708
|
+
"aria-hidden": "true",
|
|
709
|
+
children: [
|
|
710
|
+
/* @__PURE__ */ i("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
711
|
+
/* @__PURE__ */ i("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
712
|
+
]
|
|
713
|
+
}
|
|
714
|
+
)
|
|
715
|
+
}
|
|
716
|
+
)
|
|
717
|
+
] });
|
|
718
|
+
}
|
|
719
|
+
function qe({
|
|
720
|
+
message: t,
|
|
721
|
+
retryLabel: e,
|
|
722
|
+
onRetry: r
|
|
723
|
+
}) {
|
|
724
|
+
return /* @__PURE__ */ d(
|
|
725
|
+
"div",
|
|
726
|
+
{
|
|
727
|
+
role: "alert",
|
|
728
|
+
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",
|
|
729
|
+
children: [
|
|
730
|
+
/* @__PURE__ */ i("span", { children: t }),
|
|
731
|
+
r && /* @__PURE__ */ i(
|
|
732
|
+
"button",
|
|
733
|
+
{
|
|
734
|
+
type: "button",
|
|
735
|
+
onClick: r,
|
|
736
|
+
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",
|
|
737
|
+
children: e
|
|
738
|
+
}
|
|
739
|
+
)
|
|
740
|
+
]
|
|
741
|
+
}
|
|
742
|
+
);
|
|
743
|
+
}
|
|
744
|
+
function Xe({ label: t }) {
|
|
745
|
+
return /* @__PURE__ */ i(
|
|
746
|
+
"div",
|
|
747
|
+
{
|
|
748
|
+
role: "status",
|
|
749
|
+
"aria-live": "polite",
|
|
750
|
+
"aria-label": t,
|
|
751
|
+
className: "mr-auto flex max-w-[85%]",
|
|
752
|
+
children: /* @__PURE__ */ d("div", { className: "flex gap-1 rounded-claudius-bubble rounded-bl-claudius-tail bg-claudius-assistant-bubble px-4 py-3", children: [
|
|
753
|
+
/* @__PURE__ */ i("span", { className: "h-2 w-2 motion-safe:animate-bounce rounded-claudius-full bg-claudius-text-muted [animation-delay:0ms]" }),
|
|
754
|
+
/* @__PURE__ */ i("span", { className: "h-2 w-2 motion-safe:animate-bounce rounded-claudius-full bg-claudius-text-muted [animation-delay:150ms]" }),
|
|
755
|
+
/* @__PURE__ */ i("span", { className: "h-2 w-2 motion-safe:animate-bounce rounded-claudius-full bg-claudius-text-muted [animation-delay:300ms]" })
|
|
756
|
+
] })
|
|
757
|
+
}
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
function Je(t, e, r) {
|
|
640
761
|
const [s, n] = C(0), o = N(0), a = N(0), l = N(0), c = N(!1);
|
|
641
762
|
return k(() => {
|
|
642
763
|
const u = t.current;
|
|
@@ -662,15 +783,15 @@ function Ke(t, e, r) {
|
|
|
662
783
|
};
|
|
663
784
|
}, [t, e, r]), { offsetY: s };
|
|
664
785
|
}
|
|
665
|
-
const
|
|
666
|
-
function
|
|
786
|
+
const Ze = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
787
|
+
function Qe(t, e) {
|
|
667
788
|
k(() => {
|
|
668
789
|
const r = t.current;
|
|
669
790
|
if (!r) return;
|
|
670
791
|
const s = (n) => {
|
|
671
792
|
if (n.key !== "Tab") return;
|
|
672
793
|
const o = Array.from(
|
|
673
|
-
r.querySelectorAll(
|
|
794
|
+
r.querySelectorAll(Ze)
|
|
674
795
|
).filter((u) => !u.hasAttribute("aria-hidden"));
|
|
675
796
|
if (o.length === 0) return;
|
|
676
797
|
const a = o[0], l = o[o.length - 1], c = document.activeElement;
|
|
@@ -679,9 +800,9 @@ function Xe(t, e) {
|
|
|
679
800
|
return r.addEventListener("keydown", s), () => r.removeEventListener("keydown", s);
|
|
680
801
|
}, [t, e]);
|
|
681
802
|
}
|
|
682
|
-
const
|
|
683
|
-
function
|
|
684
|
-
return t.replace(
|
|
803
|
+
const et = /\*\*([^*]+)\*\*/g, tt = /\*([^*]+)\*/g, rt = /https?:\/\/[^\s)]+/g;
|
|
804
|
+
function nt(t) {
|
|
805
|
+
return t.replace(et, "$1").replace(tt, "$1").replace(rt, (e) => {
|
|
685
806
|
try {
|
|
686
807
|
return new URL(e).hostname;
|
|
687
808
|
} catch {
|
|
@@ -689,29 +810,13 @@ function et(t) {
|
|
|
689
810
|
}
|
|
690
811
|
});
|
|
691
812
|
}
|
|
692
|
-
|
|
693
|
-
return /* @__PURE__ */ i(
|
|
694
|
-
"div",
|
|
695
|
-
{
|
|
696
|
-
role: "status",
|
|
697
|
-
"aria-live": "polite",
|
|
698
|
-
"aria-label": t,
|
|
699
|
-
className: "mr-auto flex max-w-[85%]",
|
|
700
|
-
children: /* @__PURE__ */ d("div", { className: "flex gap-1 rounded-claudius-bubble rounded-bl-claudius-tail bg-claudius-assistant-bubble px-4 py-3", children: [
|
|
701
|
-
/* @__PURE__ */ i("span", { className: "h-2 w-2 motion-safe:animate-bounce rounded-claudius-full bg-claudius-text-muted [animation-delay:0ms]" }),
|
|
702
|
-
/* @__PURE__ */ i("span", { className: "h-2 w-2 motion-safe:animate-bounce rounded-claudius-full bg-claudius-text-muted [animation-delay:150ms]" }),
|
|
703
|
-
/* @__PURE__ */ i("span", { className: "h-2 w-2 motion-safe:animate-bounce rounded-claudius-full bg-claudius-text-muted [animation-delay:300ms]" })
|
|
704
|
-
] })
|
|
705
|
-
}
|
|
706
|
-
);
|
|
707
|
-
}
|
|
708
|
-
const rt = {
|
|
813
|
+
const st = {
|
|
709
814
|
"bottom-right": "bottom-24 right-3 sm:right-6",
|
|
710
815
|
"bottom-left": "bottom-24 left-3 sm:left-6",
|
|
711
816
|
"top-right": "top-24 right-3 sm:right-6",
|
|
712
817
|
"top-left": "top-24 left-3 sm:left-6"
|
|
713
818
|
};
|
|
714
|
-
function
|
|
819
|
+
function ot({
|
|
715
820
|
messages: t,
|
|
716
821
|
isLoading: e,
|
|
717
822
|
error: r,
|
|
@@ -728,8 +833,8 @@ function nt({
|
|
|
728
833
|
isMobile: x = !1
|
|
729
834
|
}) {
|
|
730
835
|
const f = Re(), w = N(null), v = N(null), [y, T] = C(null);
|
|
731
|
-
|
|
732
|
-
const { offsetY: O } =
|
|
836
|
+
Qe(w, !0);
|
|
837
|
+
const { offsetY: O } = Je(
|
|
733
838
|
v,
|
|
734
839
|
a,
|
|
735
840
|
x
|
|
@@ -751,58 +856,21 @@ function nt({
|
|
|
751
856
|
role: "dialog",
|
|
752
857
|
"aria-modal": x ? "true" : void 0,
|
|
753
858
|
"aria-labelledby": f,
|
|
754
|
-
className: x ? "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 ${
|
|
859
|
+
className: x ? "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 ${st[E]} 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`,
|
|
755
860
|
style: x && !I ? { transform: `translateY(${Math.max(0, O)}px)` } : void 0,
|
|
756
861
|
"data-dragging": A || void 0,
|
|
757
862
|
children: [
|
|
758
863
|
x && /* @__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" }) }),
|
|
759
|
-
/* @__PURE__ */
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
/* @__PURE__ */ i(
|
|
770
|
-
"h2",
|
|
771
|
-
{
|
|
772
|
-
id: f,
|
|
773
|
-
className: "text-sm font-heading font-semibold text-claudius-accent-text",
|
|
774
|
-
children: l
|
|
775
|
-
}
|
|
776
|
-
),
|
|
777
|
-
/* @__PURE__ */ i("p", { className: "text-xs text-claudius-accent-text", children: c })
|
|
778
|
-
] }),
|
|
779
|
-
/* @__PURE__ */ i(
|
|
780
|
-
"button",
|
|
781
|
-
{
|
|
782
|
-
onClick: a,
|
|
783
|
-
"aria-label": M,
|
|
784
|
-
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",
|
|
785
|
-
children: /* @__PURE__ */ d(
|
|
786
|
-
"svg",
|
|
787
|
-
{
|
|
788
|
-
width: "18",
|
|
789
|
-
height: "18",
|
|
790
|
-
viewBox: "0 0 24 24",
|
|
791
|
-
fill: "none",
|
|
792
|
-
stroke: "currentColor",
|
|
793
|
-
strokeWidth: "2",
|
|
794
|
-
strokeLinecap: "round",
|
|
795
|
-
strokeLinejoin: "round",
|
|
796
|
-
"aria-hidden": "true",
|
|
797
|
-
children: [
|
|
798
|
-
/* @__PURE__ */ i("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
799
|
-
/* @__PURE__ */ i("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
800
|
-
]
|
|
801
|
-
}
|
|
802
|
-
)
|
|
803
|
-
}
|
|
804
|
-
)
|
|
805
|
-
] }),
|
|
864
|
+
/* @__PURE__ */ i(
|
|
865
|
+
Ke,
|
|
866
|
+
{
|
|
867
|
+
title: l,
|
|
868
|
+
subtitle: c,
|
|
869
|
+
titleId: f,
|
|
870
|
+
closeLabel: M,
|
|
871
|
+
onClose: a
|
|
872
|
+
}
|
|
873
|
+
),
|
|
806
874
|
/* @__PURE__ */ d("div", { className: "relative flex-1 overflow-hidden", children: [
|
|
807
875
|
y && /* @__PURE__ */ i(
|
|
808
876
|
Ve,
|
|
@@ -834,28 +902,17 @@ function nt({
|
|
|
834
902
|
b.id
|
|
835
903
|
)),
|
|
836
904
|
e && /* @__PURE__ */ i(
|
|
837
|
-
|
|
905
|
+
Xe,
|
|
838
906
|
{
|
|
839
907
|
label: (g == null ? void 0 : g.typingIndicator) ?? "Assistant is typing"
|
|
840
908
|
}
|
|
841
909
|
),
|
|
842
|
-
r && /* @__PURE__ */
|
|
843
|
-
|
|
910
|
+
r && /* @__PURE__ */ i(
|
|
911
|
+
qe,
|
|
844
912
|
{
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
/* @__PURE__ */ i("span", { children: r }),
|
|
849
|
-
s && o && !e && /* @__PURE__ */ i(
|
|
850
|
-
"button",
|
|
851
|
-
{
|
|
852
|
-
type: "button",
|
|
853
|
-
onClick: o,
|
|
854
|
-
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",
|
|
855
|
-
children: (g == null ? void 0 : g.errorRetry) ?? "Retry"
|
|
856
|
-
}
|
|
857
|
-
)
|
|
858
|
-
]
|
|
913
|
+
message: r,
|
|
914
|
+
retryLabel: (g == null ? void 0 : g.errorRetry) ?? "Retry",
|
|
915
|
+
onRetry: s && o && !e ? o : void 0
|
|
859
916
|
}
|
|
860
917
|
)
|
|
861
918
|
]
|
|
@@ -869,7 +926,7 @@ function nt({
|
|
|
869
926
|
"aria-live": "polite",
|
|
870
927
|
"aria-atomic": "true",
|
|
871
928
|
className: "sr-only",
|
|
872
|
-
children: _ ?
|
|
929
|
+
children: _ ? nt(_.content) : ""
|
|
873
930
|
}
|
|
874
931
|
),
|
|
875
932
|
/* @__PURE__ */ i(
|
|
@@ -885,7 +942,7 @@ function nt({
|
|
|
885
942
|
}
|
|
886
943
|
);
|
|
887
944
|
}
|
|
888
|
-
function
|
|
945
|
+
function it({
|
|
889
946
|
message: t,
|
|
890
947
|
position: e,
|
|
891
948
|
onOpen: r,
|
|
@@ -945,11 +1002,11 @@ const ie = {
|
|
|
945
1002
|
errorRateLimitMinute: "Too many requests. Please wait a minute.",
|
|
946
1003
|
errorRateLimitHour: "Hourly limit reached. Please try again later.",
|
|
947
1004
|
errorRetry: "Retry"
|
|
948
|
-
},
|
|
949
|
-
function
|
|
950
|
-
return { ...
|
|
1005
|
+
}, at = ie;
|
|
1006
|
+
function St(t) {
|
|
1007
|
+
return { ...at, ...t };
|
|
951
1008
|
}
|
|
952
|
-
const
|
|
1009
|
+
const ct = {
|
|
953
1010
|
// ChatWindow
|
|
954
1011
|
title: "Chat",
|
|
955
1012
|
subtitle: "Pregúntame lo que quieras",
|
|
@@ -972,7 +1029,7 @@ const it = {
|
|
|
972
1029
|
errorRateLimitMinute: "Demasiadas solicitudes. Espera un minuto.",
|
|
973
1030
|
errorRateLimitHour: "Has alcanzado el límite por hora. Inténtalo más tarde.",
|
|
974
1031
|
errorRetry: "Reintentar"
|
|
975
|
-
},
|
|
1032
|
+
}, ut = {
|
|
976
1033
|
// ChatWindow
|
|
977
1034
|
title: "Chat",
|
|
978
1035
|
subtitle: "Posez-moi vos questions",
|
|
@@ -995,7 +1052,7 @@ const it = {
|
|
|
995
1052
|
errorRateLimitMinute: "Trop de requêtes. Veuillez patienter une minute.",
|
|
996
1053
|
errorRateLimitHour: "Limite horaire atteinte. Veuillez réessayer plus tard.",
|
|
997
1054
|
errorRetry: "Réessayer"
|
|
998
|
-
},
|
|
1055
|
+
}, lt = {
|
|
999
1056
|
// ChatWindow
|
|
1000
1057
|
title: "Chat",
|
|
1001
1058
|
subtitle: "Fragen Sie mich alles",
|
|
@@ -1020,23 +1077,23 @@ const it = {
|
|
|
1020
1077
|
errorRetry: "Erneut versuchen"
|
|
1021
1078
|
}, ae = {
|
|
1022
1079
|
en: ie,
|
|
1023
|
-
es:
|
|
1024
|
-
fr:
|
|
1025
|
-
de:
|
|
1080
|
+
es: ct,
|
|
1081
|
+
fr: ut,
|
|
1082
|
+
de: lt
|
|
1026
1083
|
};
|
|
1027
1084
|
function re(t) {
|
|
1028
1085
|
if (!t) return;
|
|
1029
1086
|
const e = t.toLowerCase().split("-")[0];
|
|
1030
1087
|
return Object.prototype.hasOwnProperty.call(ae, e) ? e : void 0;
|
|
1031
1088
|
}
|
|
1032
|
-
function
|
|
1089
|
+
function dt() {
|
|
1033
1090
|
const t = typeof document < "u" ? re(document.documentElement.lang) : void 0;
|
|
1034
1091
|
if (t) return t;
|
|
1035
1092
|
const e = typeof navigator < "u" ? re(navigator.language) : void 0;
|
|
1036
1093
|
return e || "en";
|
|
1037
1094
|
}
|
|
1038
|
-
function
|
|
1039
|
-
const { locale: e, translations: r } = t, s = ae[e ??
|
|
1095
|
+
function ht(t = {}) {
|
|
1096
|
+
const { locale: e, translations: r } = t, s = ae[e ?? dt()];
|
|
1040
1097
|
return r ? { ...s, ...r } : { ...s };
|
|
1041
1098
|
}
|
|
1042
1099
|
const ne = [
|
|
@@ -1059,11 +1116,11 @@ const ne = [
|
|
|
1059
1116
|
"errorText",
|
|
1060
1117
|
"link",
|
|
1061
1118
|
"scrim"
|
|
1062
|
-
],
|
|
1119
|
+
], ft = ["sm", "md", "lg", "full", "tail"], mt = [
|
|
1063
1120
|
"elevated",
|
|
1064
1121
|
"floating",
|
|
1065
1122
|
"floatingHover"
|
|
1066
|
-
],
|
|
1123
|
+
], gt = ["heading", "body"], ce = {
|
|
1067
1124
|
default: {
|
|
1068
1125
|
name: "default"
|
|
1069
1126
|
},
|
|
@@ -1148,17 +1205,17 @@ const ne = [
|
|
|
1148
1205
|
}
|
|
1149
1206
|
}
|
|
1150
1207
|
};
|
|
1151
|
-
function
|
|
1208
|
+
function bt(t) {
|
|
1152
1209
|
return Object.prototype.hasOwnProperty.call(ce, t);
|
|
1153
1210
|
}
|
|
1154
|
-
const
|
|
1155
|
-
function
|
|
1211
|
+
const pt = /* @__PURE__ */ new Set(["light", "dark", "auto"]);
|
|
1212
|
+
function xt(t) {
|
|
1156
1213
|
if (t === void 0)
|
|
1157
1214
|
return { mode: "light" };
|
|
1158
1215
|
if (typeof t == "string") {
|
|
1159
|
-
if (
|
|
1216
|
+
if (pt.has(t))
|
|
1160
1217
|
return { mode: t };
|
|
1161
|
-
if (
|
|
1218
|
+
if (bt(t)) {
|
|
1162
1219
|
const e = ce[t];
|
|
1163
1220
|
return { mode: e.colorScheme ?? "light", theme: e };
|
|
1164
1221
|
}
|
|
@@ -1166,10 +1223,10 @@ function bt(t) {
|
|
|
1166
1223
|
}
|
|
1167
1224
|
return { mode: t.colorScheme ?? "light", theme: t };
|
|
1168
1225
|
}
|
|
1169
|
-
function
|
|
1226
|
+
function yt(t) {
|
|
1170
1227
|
return t.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`);
|
|
1171
1228
|
}
|
|
1172
|
-
function
|
|
1229
|
+
function wt(t, e) {
|
|
1173
1230
|
console.warn(
|
|
1174
1231
|
`[Claudius] Ignoring unknown theme token "${e}" in "${t}"`
|
|
1175
1232
|
);
|
|
@@ -1178,13 +1235,13 @@ function B(t, e, r, s, n, o = "") {
|
|
|
1178
1235
|
if (n)
|
|
1179
1236
|
for (const [a, l] of Object.entries(n)) {
|
|
1180
1237
|
if (!s.includes(a)) {
|
|
1181
|
-
|
|
1238
|
+
wt(e, a);
|
|
1182
1239
|
continue;
|
|
1183
1240
|
}
|
|
1184
|
-
typeof l == "string" && (t[`${r}${
|
|
1241
|
+
typeof l == "string" && (t[`${r}${yt(a)}${o}`] = l);
|
|
1185
1242
|
}
|
|
1186
1243
|
}
|
|
1187
|
-
function
|
|
1244
|
+
function vt(t) {
|
|
1188
1245
|
const e = {};
|
|
1189
1246
|
B(e, "colors", "--cl-color-", ne, t.colors);
|
|
1190
1247
|
for (const [r, s] of Object.entries({ ...e }))
|
|
@@ -1196,13 +1253,13 @@ function yt(t) {
|
|
|
1196
1253
|
ne,
|
|
1197
1254
|
t.colorsDark,
|
|
1198
1255
|
"-dark"
|
|
1199
|
-
), B(e, "radii", "--cl-radius-",
|
|
1256
|
+
), B(e, "radii", "--cl-radius-", ft, t.radii), B(e, "shadows", "--cl-shadow-", mt, t.shadows), B(e, "fonts", "--cl-font-", gt, t.fonts), e;
|
|
1200
1257
|
}
|
|
1201
|
-
function
|
|
1258
|
+
function Et(t) {
|
|
1202
1259
|
return typeof t == "object" && t !== null && !Array.isArray(t);
|
|
1203
1260
|
}
|
|
1204
|
-
function
|
|
1205
|
-
const e = F(() =>
|
|
1261
|
+
function Rt(t) {
|
|
1262
|
+
const e = F(() => xt(t), [t]), [r, s] = C(null), n = e.url;
|
|
1206
1263
|
k(() => {
|
|
1207
1264
|
if (s(null), !n) return;
|
|
1208
1265
|
const c = new AbortController();
|
|
@@ -1211,7 +1268,7 @@ function vt(t) {
|
|
|
1211
1268
|
throw new Error(`HTTP ${u.status}`);
|
|
1212
1269
|
return u.json();
|
|
1213
1270
|
}).then((u) => {
|
|
1214
|
-
if (!
|
|
1271
|
+
if (!Et(u))
|
|
1215
1272
|
throw new Error("theme JSON must be an object");
|
|
1216
1273
|
s(u);
|
|
1217
1274
|
}).catch((u) => {
|
|
@@ -1219,13 +1276,13 @@ function vt(t) {
|
|
|
1219
1276
|
}), () => c.abort();
|
|
1220
1277
|
}, [n]);
|
|
1221
1278
|
const o = e.theme ?? r ?? null, a = (r == null ? void 0 : r.colorScheme) ?? e.mode, l = F(
|
|
1222
|
-
() => o ?
|
|
1279
|
+
() => o ? vt(o) : {},
|
|
1223
1280
|
[o]
|
|
1224
1281
|
);
|
|
1225
1282
|
return { mode: a, cssVars: l };
|
|
1226
1283
|
}
|
|
1227
1284
|
const ue = "claudius:triggers:dismissed";
|
|
1228
|
-
function
|
|
1285
|
+
function Tt() {
|
|
1229
1286
|
if (typeof window > "u") return !1;
|
|
1230
1287
|
try {
|
|
1231
1288
|
return window.sessionStorage.getItem(ue) === "1";
|
|
@@ -1233,14 +1290,14 @@ function Et() {
|
|
|
1233
1290
|
return !1;
|
|
1234
1291
|
}
|
|
1235
1292
|
}
|
|
1236
|
-
function
|
|
1293
|
+
function Mt() {
|
|
1237
1294
|
if (!(typeof window > "u"))
|
|
1238
1295
|
try {
|
|
1239
1296
|
window.sessionStorage.setItem(ue, "1");
|
|
1240
1297
|
} catch {
|
|
1241
1298
|
}
|
|
1242
1299
|
}
|
|
1243
|
-
function
|
|
1300
|
+
function kt({
|
|
1244
1301
|
apiUrl: t,
|
|
1245
1302
|
title: e,
|
|
1246
1303
|
subtitle: r,
|
|
@@ -1256,8 +1313,8 @@ function St({
|
|
|
1256
1313
|
translations: g,
|
|
1257
1314
|
triggers: x
|
|
1258
1315
|
}) {
|
|
1259
|
-
const [f, w] = C(!1), [v, y] = C(null), [T, O] = C(
|
|
1260
|
-
() =>
|
|
1316
|
+
const [f, w] = C(!1), [v, y] = C(null), [T, O] = C(Tt), A = N(!1), I = Oe("(max-width: 639px)"), M = F(
|
|
1317
|
+
() => ht({ locale: E, translations: g }),
|
|
1261
1318
|
[E, g]
|
|
1262
1319
|
), { messages: D, isLoading: _, error: b, canRetry: j, sendMessage: m, retry: p } = ke({
|
|
1263
1320
|
apiUrl: t,
|
|
@@ -1265,27 +1322,27 @@ function St({
|
|
|
1265
1322
|
storageKeyPrefix: a,
|
|
1266
1323
|
timeoutMs: l,
|
|
1267
1324
|
translations: M
|
|
1268
|
-
}), H = N(null),
|
|
1325
|
+
}), H = N(null), L = N(f), { mode: G, cssVars: le } = Rt(c), [de, q] = C(!1);
|
|
1269
1326
|
k(() => {
|
|
1270
1327
|
if (G !== "auto") return;
|
|
1271
|
-
const
|
|
1272
|
-
q(
|
|
1328
|
+
const S = window.matchMedia("(prefers-color-scheme: dark)");
|
|
1329
|
+
q(S.matches);
|
|
1273
1330
|
const Z = (xe) => q(xe.matches);
|
|
1274
|
-
return
|
|
1331
|
+
return S.addEventListener("change", Z), () => S.removeEventListener("change", Z);
|
|
1275
1332
|
}, [G]), k(() => {
|
|
1276
|
-
var
|
|
1277
|
-
|
|
1333
|
+
var S;
|
|
1334
|
+
L.current && !f && ((S = H.current) == null || S.focus()), L.current = f;
|
|
1278
1335
|
}, [f]);
|
|
1279
1336
|
const P = R(() => {
|
|
1280
|
-
O(!0),
|
|
1337
|
+
O(!0), Mt();
|
|
1281
1338
|
}, []), X = R(() => {
|
|
1282
1339
|
w(!1), A.current && (A.current = !1, P());
|
|
1283
1340
|
}, [P]), he = R(() => {
|
|
1284
|
-
w((
|
|
1341
|
+
w((S) => !S);
|
|
1285
1342
|
}, []), Y = R(() => {
|
|
1286
1343
|
A.current = !0, y(null), w(!0);
|
|
1287
|
-
}, []), fe = R((
|
|
1288
|
-
y(
|
|
1344
|
+
}, []), fe = R((S) => {
|
|
1345
|
+
y(S);
|
|
1289
1346
|
}, []), me = R(() => {
|
|
1290
1347
|
y(null), Y();
|
|
1291
1348
|
}, [Y]), ge = R(() => {
|
|
@@ -1318,7 +1375,7 @@ function St({
|
|
|
1318
1375
|
}
|
|
1319
1376
|
),
|
|
1320
1377
|
f && /* @__PURE__ */ i(
|
|
1321
|
-
|
|
1378
|
+
ot,
|
|
1322
1379
|
{
|
|
1323
1380
|
messages: D,
|
|
1324
1381
|
isLoading: _,
|
|
@@ -1347,7 +1404,7 @@ function St({
|
|
|
1347
1404
|
}
|
|
1348
1405
|
),
|
|
1349
1406
|
!f && v && /* @__PURE__ */ i(
|
|
1350
|
-
|
|
1407
|
+
it,
|
|
1351
1408
|
{
|
|
1352
1409
|
message: v,
|
|
1353
1410
|
position: h,
|
|
@@ -1362,12 +1419,12 @@ function St({
|
|
|
1362
1419
|
export {
|
|
1363
1420
|
Me as ChatApiClient,
|
|
1364
1421
|
U as ChatApiError,
|
|
1365
|
-
|
|
1422
|
+
kt as ChatWidget,
|
|
1366
1423
|
se as DebounceError,
|
|
1367
1424
|
ce as builtinThemes,
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1425
|
+
St as createTranslations,
|
|
1426
|
+
at as defaultTranslations,
|
|
1427
|
+
dt as detectLocale,
|
|
1371
1428
|
ae as locales,
|
|
1372
|
-
|
|
1429
|
+
ht as resolveTranslations
|
|
1373
1430
|
};
|