@nightzeros/chatai-widget 1.0.0 → 1.1.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/index.js CHANGED
@@ -2,9 +2,317 @@
2
2
  import { render } from "preact";
3
3
 
4
4
  // src/app.tsx
5
- import { useEffect, useMemo, useRef, useState } from "preact/hooks";
6
- import { createWidgetController } from "@nightzeros/chatai-widget-core";
5
+ import { useEffect as useEffect2, useMemo, useRef as useRef2, useState } from "preact/hooks";
6
+ import { createWidgetController, isVoiceActive as isVoiceActive2 } from "@nightzeros/chatai-widget-core";
7
+
8
+ // src/markdown-message.tsx
7
9
  import { jsx, jsxs } from "preact/jsx-runtime";
10
+ function isSafeHref(href) {
11
+ return href.startsWith("http://") || href.startsWith("https://") || href.startsWith("mailto:");
12
+ }
13
+ var AUTOLINK_RE = /(https?:\/\/[^\s<>()]+|mailto:[^\s<>()]+)/g;
14
+ var MD_LINK_RE = /\[([^\]]+)\]\(([^)\s]+)\)/;
15
+ var INLINE_CODE_RE = /`([^`]+)`/;
16
+ var STRONG_RE = /\*\*([^*]+)\*\*|__([^_]+)__/;
17
+ var EM_RE = /\*([^*]+)\*|_([^_]+)_/;
18
+ function pushText(tokens, value) {
19
+ if (!value) return;
20
+ AUTOLINK_RE.lastIndex = 0;
21
+ let last = 0;
22
+ let match;
23
+ while (match = AUTOLINK_RE.exec(value)) {
24
+ const raw = match[1] ?? "";
25
+ if (match.index > last) {
26
+ tokens.push({ type: "text", value: value.slice(last, match.index) });
27
+ }
28
+ const href = raw.replace(/[.,;:!?)]+$/, "");
29
+ const trailing = raw.slice(href.length);
30
+ if (isSafeHref(href)) {
31
+ tokens.push({ type: "link", href, children: [{ type: "text", value: href }] });
32
+ } else {
33
+ tokens.push({ type: "text", value: raw });
34
+ }
35
+ if (trailing) tokens.push({ type: "text", value: trailing });
36
+ last = match.index + match[0].length;
37
+ }
38
+ if (last < value.length) {
39
+ tokens.push({ type: "text", value: value.slice(last) });
40
+ }
41
+ }
42
+ function parseInline(input) {
43
+ const tokens = [];
44
+ let rest = input;
45
+ while (rest.length > 0) {
46
+ const code = INLINE_CODE_RE.exec(rest);
47
+ const link = MD_LINK_RE.exec(rest);
48
+ const strong = STRONG_RE.exec(rest);
49
+ const em = EM_RE.exec(rest);
50
+ const candidates = [
51
+ code ? { kind: "code", index: code.index, match: code } : null,
52
+ link ? { kind: "link", index: link.index, match: link } : null,
53
+ strong ? { kind: "strong", index: strong.index, match: strong } : null,
54
+ em ? { kind: "em", index: em.index, match: em } : null
55
+ ].filter((c) => c != null);
56
+ if (candidates.length === 0) {
57
+ pushText(tokens, rest);
58
+ break;
59
+ }
60
+ candidates.sort((a, b) => a.index - b.index || a.match[0].length - b.match[0].length);
61
+ const next = candidates[0];
62
+ if (!next) break;
63
+ if (next.index > 0) {
64
+ pushText(tokens, rest.slice(0, next.index));
65
+ }
66
+ if (next.kind === "code") {
67
+ tokens.push({ type: "code", value: next.match[1] ?? "" });
68
+ } else if (next.kind === "link") {
69
+ const href = next.match[2] ?? "";
70
+ const label = next.match[1] ?? "";
71
+ if (isSafeHref(href)) {
72
+ tokens.push({ type: "link", href, children: parseInline(label) });
73
+ } else {
74
+ pushText(tokens, next.match[0]);
75
+ }
76
+ } else if (next.kind === "strong") {
77
+ const inner = next.match[1] ?? next.match[2] ?? "";
78
+ tokens.push({ type: "strong", children: parseInline(inner) });
79
+ } else {
80
+ const inner = next.match[1] ?? next.match[2] ?? "";
81
+ tokens.push({ type: "em", children: parseInline(inner) });
82
+ }
83
+ rest = rest.slice(next.index + next.match[0].length);
84
+ }
85
+ return tokens;
86
+ }
87
+ function isUnorderedItem(line) {
88
+ return /^[-*+]\s+/.test(line);
89
+ }
90
+ function isOrderedItem(line) {
91
+ return /^\d+\.\s+/.test(line);
92
+ }
93
+ function parseMarkdownBlocks(content) {
94
+ const lines = content.replace(/\r\n/g, "\n").split("\n");
95
+ const blocks = [];
96
+ let i = 0;
97
+ while (i < lines.length) {
98
+ const line = lines[i] ?? "";
99
+ if (line.trim() === "") {
100
+ i += 1;
101
+ continue;
102
+ }
103
+ if (line.startsWith("```")) {
104
+ const language = line.slice(3).trim() || void 0;
105
+ i += 1;
106
+ const body = [];
107
+ while (i < lines.length && !(lines[i] ?? "").startsWith("```")) {
108
+ body.push(lines[i] ?? "");
109
+ i += 1;
110
+ }
111
+ if (i < lines.length) i += 1;
112
+ blocks.push({ type: "code", value: body.join("\n"), language });
113
+ continue;
114
+ }
115
+ if (isUnorderedItem(line) || isOrderedItem(line)) {
116
+ const ordered = isOrderedItem(line);
117
+ const items = [];
118
+ while (i < lines.length) {
119
+ const itemLine = lines[i] ?? "";
120
+ if (!(ordered ? isOrderedItem(itemLine) : isUnorderedItem(itemLine))) break;
121
+ const text = itemLine.replace(ordered ? /^\d+\.\s+/ : /^[-*+]\s+/, "");
122
+ items.push(parseInline(text));
123
+ i += 1;
124
+ }
125
+ blocks.push({ type: ordered ? "ol" : "ul", items });
126
+ continue;
127
+ }
128
+ const para = [line];
129
+ i += 1;
130
+ while (i < lines.length) {
131
+ const next = lines[i] ?? "";
132
+ if (next.trim() === "" || next.startsWith("```") || isUnorderedItem(next) || isOrderedItem(next)) {
133
+ break;
134
+ }
135
+ para.push(next);
136
+ i += 1;
137
+ }
138
+ blocks.push({ type: "paragraph", children: parseInline(para.join("\n")) });
139
+ }
140
+ return blocks;
141
+ }
142
+ function renderInline(tokens, keyPrefix) {
143
+ return tokens.map((token, index) => {
144
+ const key = `${keyPrefix}-${index}`;
145
+ switch (token.type) {
146
+ case "text":
147
+ return token.value;
148
+ case "code":
149
+ return /* @__PURE__ */ jsx("code", { className: "chatai-md-code", children: token.value }, key);
150
+ case "link":
151
+ return /* @__PURE__ */ jsx("a", { href: token.href, target: "_blank", rel: "noreferrer", className: "chatai-md-link", children: renderInline(token.children, key) }, key);
152
+ case "strong":
153
+ return /* @__PURE__ */ jsx("strong", { children: renderInline(token.children, key) }, key);
154
+ case "em":
155
+ return /* @__PURE__ */ jsx("em", { children: renderInline(token.children, key) }, key);
156
+ default:
157
+ return null;
158
+ }
159
+ });
160
+ }
161
+ function renderBlocks(blocks) {
162
+ return blocks.map((block, index) => {
163
+ const key = `b-${index}`;
164
+ if (block.type === "paragraph") {
165
+ return /* @__PURE__ */ jsx("p", { className: "chatai-md-p", children: renderInline(block.children, key) }, key);
166
+ }
167
+ if (block.type === "code") {
168
+ return /* @__PURE__ */ jsx("pre", { className: "chatai-md-pre", children: /* @__PURE__ */ jsx("code", { className: block.language ? `language-${block.language}` : void 0, children: block.value }) }, key);
169
+ }
170
+ const ListTag = block.type === "ol" ? "ol" : "ul";
171
+ return /* @__PURE__ */ jsx(ListTag, { className: block.type === "ol" ? "chatai-md-ol" : "chatai-md-ul", children: block.items.map((item, itemIndex) => /* @__PURE__ */ jsx("li", { children: renderInline(item, `${key}-${itemIndex}`) }, `${key}-${itemIndex}`)) }, key);
172
+ });
173
+ }
174
+ function MarkdownMessage({
175
+ content,
176
+ streaming
177
+ }) {
178
+ const blocks = content ? parseMarkdownBlocks(content) : [];
179
+ return /* @__PURE__ */ jsxs("div", { className: "chatai-md", children: [
180
+ blocks.length > 0 ? renderBlocks(blocks) : null,
181
+ streaming ? /* @__PURE__ */ jsx("span", { className: "chatai-md-caret", "aria-hidden": true }) : null
182
+ ] });
183
+ }
184
+
185
+ // src/voice-ui.tsx
186
+ import { useEffect, useRef } from "preact/hooks";
187
+ import {
188
+ isVoiceActive,
189
+ VOICE_PHASE_LABELS
190
+ } from "@nightzeros/chatai-widget-core";
191
+ import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "preact/jsx-runtime";
192
+ var BAR_WEIGHTS = [0.55, 0.85, 1, 0.8, 0.5];
193
+ function MicGlyph({ off = false }) {
194
+ return /* @__PURE__ */ jsx2("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", fill: "none", stroke: "currentColor", "stroke-width": "2", children: off ? /* @__PURE__ */ jsx2("rect", { x: "7", y: "7", width: "10", height: "10", rx: "2", fill: "currentColor", stroke: "none" }) : /* @__PURE__ */ jsxs2(Fragment, { children: [
195
+ /* @__PURE__ */ jsx2("rect", { x: "9", y: "3", width: "6", height: "11", rx: "3" }),
196
+ /* @__PURE__ */ jsx2("path", { d: "M5 11a7 7 0 0 0 14 0M12 18v3", "stroke-linecap": "round" })
197
+ ] }) });
198
+ }
199
+ function VoiceGlyph() {
200
+ return /* @__PURE__ */ jsx2("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", fill: "none", stroke: "currentColor", "stroke-width": "2.4", children: /* @__PURE__ */ jsx2("path", { d: "M5 10v4M9 7v10M13 4v16M17 8v8M21 11v2", "stroke-linecap": "round" }) });
201
+ }
202
+ function prefersReducedMotion() {
203
+ return typeof window !== "undefined" && Boolean(window.matchMedia?.("(prefers-reduced-motion: reduce)").matches);
204
+ }
205
+ function Waveform({
206
+ phase,
207
+ active,
208
+ levels
209
+ }) {
210
+ const bars = useRef([]);
211
+ const phaseRef = useRef(phase);
212
+ phaseRef.current = phase;
213
+ useEffect(() => {
214
+ if (!active || prefersReducedMotion() || typeof requestAnimationFrame === "undefined") return;
215
+ let frame = 0;
216
+ const draw = () => {
217
+ const { input, output } = levels();
218
+ const current = phaseRef.current;
219
+ const level = current === "user_speaking" ? input : current === "assistant_speaking" ? output : 0;
220
+ const energy = Math.min(1, level * 8);
221
+ bars.current.forEach((bar, index) => {
222
+ if (!bar) return;
223
+ const weight = BAR_WEIGHTS[index] ?? 0.6;
224
+ bar.style.transform = `scaleY(${(0.22 + energy * weight * 0.78).toFixed(3)})`;
225
+ });
226
+ frame = requestAnimationFrame(draw);
227
+ };
228
+ frame = requestAnimationFrame(draw);
229
+ return () => {
230
+ cancelAnimationFrame(frame);
231
+ bars.current.forEach((bar) => bar?.style.removeProperty("transform"));
232
+ };
233
+ }, [active, levels]);
234
+ return /* @__PURE__ */ jsx2("span", { className: "chatai-wave", "aria-hidden": "true", children: BAR_WEIGHTS.map((_, index) => /* @__PURE__ */ jsx2(
235
+ "span",
236
+ {
237
+ ref: (el) => {
238
+ bars.current[index] = el;
239
+ }
240
+ },
241
+ index
242
+ )) });
243
+ }
244
+ function voiceMeta(voice) {
245
+ if (voice.mock) return "Test mode \xB7 no audio";
246
+ if (voice.ephemeral) return "Not saved";
247
+ const parts = [
248
+ voice.recording ? "Recording" : "",
249
+ voice.transcriptSaved === false ? "Voice transcript not saved" : ""
250
+ ];
251
+ return parts.filter(Boolean).join(" \xB7 ");
252
+ }
253
+ function VoiceConsent({ onAccept, onCancel }) {
254
+ const ref = useRef(null);
255
+ useEffect(() => {
256
+ ref.current?.focus();
257
+ }, []);
258
+ return /* @__PURE__ */ jsxs2(
259
+ "div",
260
+ {
261
+ ref,
262
+ className: "chatai-voice-consent",
263
+ role: "group",
264
+ tabIndex: -1,
265
+ "aria-labelledby": "chatai-voice-consent-title",
266
+ "aria-describedby": "chatai-voice-consent-text",
267
+ onKeyDown: (event) => {
268
+ if (event.key !== "Escape") return;
269
+ event.preventDefault();
270
+ event.stopPropagation();
271
+ onCancel();
272
+ },
273
+ children: [
274
+ /* @__PURE__ */ jsx2("p", { id: "chatai-voice-consent-title", className: "chatai-voice-consent-title", children: "This voice conversation is recorded" }),
275
+ /* @__PURE__ */ jsx2("p", { id: "chatai-voice-consent-text", className: "chatai-voice-consent-text", children: "Audio of the call, your voice and the assistant's, is saved for the site owner to review. Your microphone turns on only after you agree." }),
276
+ /* @__PURE__ */ jsxs2("div", { className: "chatai-voice-actions", children: [
277
+ /* @__PURE__ */ jsx2("button", { type: "button", className: "chatai-consent-accept", onClick: onAccept, children: "Agree and start" }),
278
+ /* @__PURE__ */ jsx2("button", { type: "button", className: "chatai-consent-cancel", onClick: onCancel, children: "Cancel" })
279
+ ] })
280
+ ]
281
+ }
282
+ );
283
+ }
284
+ function VoiceBar({
285
+ voice,
286
+ levels,
287
+ onRetry,
288
+ onDismiss
289
+ }) {
290
+ const active = isVoiceActive(voice.connection);
291
+ const failed = voice.connection === "failed";
292
+ const label = VOICE_PHASE_LABELS[voice.phase];
293
+ const notice = voice.connection === "ended" ? voice.notice : void 0;
294
+ const status = failed && voice.error ? `${label}. ${voice.error.message}` : active ? label : notice ?? "";
295
+ return /* @__PURE__ */ jsxs2(Fragment, { children: [
296
+ /* @__PURE__ */ jsx2("p", { className: "chatai-visually-hidden", role: "status", "aria-live": "polite", children: status }),
297
+ active || failed ? /* @__PURE__ */ jsx2("div", { className: `chatai-voice-bar${failed ? " is-error" : ""}`, "data-phase": voice.phase, children: failed ? /* @__PURE__ */ jsxs2(Fragment, { children: [
298
+ /* @__PURE__ */ jsx2("p", { className: "chatai-voice-error", children: voice.error?.message ?? label }),
299
+ /* @__PURE__ */ jsxs2("div", { className: "chatai-voice-actions", children: [
300
+ voice.error?.code !== "unsupported" ? /* @__PURE__ */ jsx2("button", { type: "button", className: "chatai-retry", onClick: onRetry, children: "Try again" }) : null,
301
+ /* @__PURE__ */ jsx2("button", { type: "button", className: "chatai-retry", onClick: onDismiss, children: "Keep typing" })
302
+ ] })
303
+ ] }) : /* @__PURE__ */ jsxs2(Fragment, { children: [
304
+ /* @__PURE__ */ jsx2(Waveform, { phase: voice.phase, active, levels }),
305
+ /* @__PURE__ */ jsx2("span", { className: "chatai-voice-label", children: label }),
306
+ /* @__PURE__ */ jsx2("span", { className: "chatai-voice-meta", children: voiceMeta(voice) })
307
+ ] }) }) : notice ? /* @__PURE__ */ jsxs2("div", { className: "chatai-voice-bar is-notice", "data-phase": voice.phase, children: [
308
+ /* @__PURE__ */ jsx2("p", { className: "chatai-voice-error", children: notice }),
309
+ /* @__PURE__ */ jsx2("div", { className: "chatai-voice-actions", children: /* @__PURE__ */ jsx2("button", { type: "button", className: "chatai-retry", onClick: onDismiss, children: "OK" }) })
310
+ ] }) : null
311
+ ] });
312
+ }
313
+
314
+ // src/app.tsx
315
+ import { jsx as jsx3, jsxs as jsxs3 } from "preact/jsx-runtime";
8
316
  var FOCUSABLE = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
9
317
  function settingOverrides(props) {
10
318
  return {
@@ -16,7 +324,11 @@ function settingOverrides(props) {
16
324
  showSources: props.showSources
17
325
  };
18
326
  }
19
- var EMPTY_STATE = { status: "loading", messages: [] };
327
+ var EMPTY_STATE = {
328
+ status: "loading",
329
+ messages: [],
330
+ voice: { connection: "idle", phase: "idle" }
331
+ };
20
332
  function settingsFrom(state, props) {
21
333
  const settings = state.config?.settings ?? {};
22
334
  return {
@@ -27,16 +339,42 @@ function settingsFrom(state, props) {
27
339
  };
28
340
  }
29
341
  function ChatGlyph() {
30
- return /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", fill: "none", stroke: "currentColor", "stroke-width": "2", children: [
31
- /* @__PURE__ */ jsx("path", { d: "M20 11.5a7.5 7.5 0 0 1-9.4 7.3L5 21l1.4-4.2A7.5 7.5 0 1 1 20 11.5Z" }),
32
- /* @__PURE__ */ jsx("path", { d: "M8.5 11.5h.01M12 11.5h.01M15.5 11.5h.01", "stroke-linecap": "round" })
342
+ return /* @__PURE__ */ jsxs3("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", fill: "none", stroke: "currentColor", "stroke-width": "2", children: [
343
+ /* @__PURE__ */ jsx3("path", { d: "M20 11.5a7.5 7.5 0 0 1-9.4 7.3L5 21l1.4-4.2A7.5 7.5 0 1 1 20 11.5Z" }),
344
+ /* @__PURE__ */ jsx3("path", { d: "M8.5 11.5h.01M12 11.5h.01M15.5 11.5h.01", "stroke-linecap": "round" })
345
+ ] });
346
+ }
347
+ function ThumbUpGlyph() {
348
+ return /* @__PURE__ */ jsxs3("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", fill: "none", stroke: "currentColor", "stroke-width": "2", children: [
349
+ /* @__PURE__ */ jsx3("path", { d: "M7 10v12", "stroke-linecap": "round", "stroke-linejoin": "round" }),
350
+ /* @__PURE__ */ jsx3(
351
+ "path",
352
+ {
353
+ d: "M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z",
354
+ "stroke-linecap": "round",
355
+ "stroke-linejoin": "round"
356
+ }
357
+ )
358
+ ] });
359
+ }
360
+ function ThumbDownGlyph() {
361
+ return /* @__PURE__ */ jsxs3("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", fill: "none", stroke: "currentColor", "stroke-width": "2", children: [
362
+ /* @__PURE__ */ jsx3("path", { d: "M17 14V2", "stroke-linecap": "round", "stroke-linejoin": "round" }),
363
+ /* @__PURE__ */ jsx3(
364
+ "path",
365
+ {
366
+ d: "M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z",
367
+ "stroke-linecap": "round",
368
+ "stroke-linejoin": "round"
369
+ }
370
+ )
33
371
  ] });
34
372
  }
35
373
  function TypingIndicator() {
36
- return /* @__PURE__ */ jsxs("div", { className: "chatai-typing", "aria-label": "Assistant is typing", role: "status", children: [
37
- /* @__PURE__ */ jsx("span", {}),
38
- /* @__PURE__ */ jsx("span", {}),
39
- /* @__PURE__ */ jsx("span", {})
374
+ return /* @__PURE__ */ jsxs3("div", { className: "chatai-typing", "aria-label": "Assistant is typing", role: "status", children: [
375
+ /* @__PURE__ */ jsx3("span", {}),
376
+ /* @__PURE__ */ jsx3("span", {}),
377
+ /* @__PURE__ */ jsx3("span", {})
40
378
  ] });
41
379
  }
42
380
  function WidgetApp(props) {
@@ -47,19 +385,28 @@ function WidgetApp(props) {
47
385
  fetch: props.fetch,
48
386
  storage: props.storage,
49
387
  createId: props.createId,
50
- signEndpoint: props.signEndpoint
388
+ signEndpoint: props.signEndpoint,
389
+ voiceMedia: props.voiceMedia
51
390
  }),
52
- [props.assistantId, props.apiUrl, props.fetch, props.storage, props.createId, props.signEndpoint]
391
+ [
392
+ props.assistantId,
393
+ props.apiUrl,
394
+ props.fetch,
395
+ props.storage,
396
+ props.createId,
397
+ props.signEndpoint,
398
+ props.voiceMedia
399
+ ]
53
400
  );
54
401
  const [state, setState] = useState(EMPTY_STATE);
55
402
  const [open, setOpen] = useState(false);
56
403
  const [closing, setClosing] = useState(false);
57
404
  const [draft, setDraft] = useState("");
58
- const launcherRef = useRef(null);
59
- const panelRef = useRef(null);
60
- const transcriptRef = useRef(null);
61
- const wasOpenRef = useRef(false);
62
- useEffect(() => {
405
+ const launcherRef = useRef2(null);
406
+ const panelRef = useRef2(null);
407
+ const transcriptRef = useRef2(null);
408
+ const wasOpenRef = useRef2(false);
409
+ useEffect2(() => {
63
410
  const unsubscribe = controller.subscribe(setState);
64
411
  void controller.load();
65
412
  return () => {
@@ -69,11 +416,14 @@ function WidgetApp(props) {
69
416
  }, [controller]);
70
417
  const settings = settingsFrom(state, props);
71
418
  const questions = settings.suggestedQuestions?.filter(Boolean) ?? [];
72
- const busy = state.status === "streaming";
419
+ const voiceOn = isVoiceActive2(state.voice.connection);
420
+ const voiceOffered = props.voice !== false && Boolean(state.config?.voice?.enabled);
421
+ const streaming = state.status === "streaming";
422
+ const busy = streaming || voiceOn;
73
423
  const panelShown = open || closing;
74
424
  const isDark = settings.theme === "dark" || settings.theme === "system" && typeof window !== "undefined" && window.matchMedia?.("(prefers-color-scheme: dark)").matches;
75
425
  const lastMessage = state.messages[state.messages.length - 1];
76
- const showTyping = busy && lastMessage?.role === "assistant" && !lastMessage.content;
426
+ const showTyping = streaming && lastMessage?.role === "assistant" && !lastMessage.content;
77
427
  function reduceMotion() {
78
428
  return typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
79
429
  }
@@ -83,6 +433,7 @@ function WidgetApp(props) {
83
433
  }
84
434
  function closePanel() {
85
435
  if (!open) return;
436
+ void controller.endVoice();
86
437
  if (reduceMotion()) {
87
438
  setOpen(false);
88
439
  setClosing(false);
@@ -106,7 +457,11 @@ function WidgetApp(props) {
106
457
  function retry() {
107
458
  void controller.load();
108
459
  }
109
- useEffect(() => {
460
+ function toggleVoice() {
461
+ if (voiceOn) void controller.endVoice();
462
+ else void controller.startVoice();
463
+ }
464
+ useEffect2(() => {
110
465
  if (!panelShown) return;
111
466
  const panel = panelRef.current;
112
467
  if (!panel) return;
@@ -135,24 +490,24 @@ function WidgetApp(props) {
135
490
  panel.addEventListener("keydown", onKeyDown);
136
491
  return () => panel.removeEventListener("keydown", onKeyDown);
137
492
  }, [panelShown]);
138
- useEffect(() => {
493
+ useEffect2(() => {
139
494
  if (wasOpenRef.current && !open && !closing) {
140
495
  launcherRef.current?.focus();
141
496
  }
142
497
  wasOpenRef.current = open || closing;
143
498
  }, [open, closing]);
144
- useEffect(() => {
499
+ useEffect2(() => {
145
500
  const el = transcriptRef.current;
146
501
  if (!el) return;
147
502
  el.scrollTop = el.scrollHeight;
148
503
  }, [state.messages, state.error, showTyping, panelShown]);
149
- return /* @__PURE__ */ jsxs(
504
+ return /* @__PURE__ */ jsxs3(
150
505
  "div",
151
506
  {
152
507
  className: `chatai-widget ${isDark ? "theme-dark" : "theme-light"} ${settings.position === "bottom-left" ? "position-left" : "position-right"} ${props.layout === "contained" ? "layout-contained" : ""}`,
153
508
  style: { "--chatai-accent": settings.primaryColor ?? "#0F766E" },
154
509
  children: [
155
- panelShown ? /* @__PURE__ */ jsxs(
510
+ panelShown ? /* @__PURE__ */ jsxs3(
156
511
  "section",
157
512
  {
158
513
  ref: panelRef,
@@ -164,55 +519,85 @@ function WidgetApp(props) {
164
519
  if (closing) setClosing(false);
165
520
  },
166
521
  children: [
167
- /* @__PURE__ */ jsxs("header", { className: "chatai-header", children: [
168
- /* @__PURE__ */ jsxs("div", { children: [
169
- /* @__PURE__ */ jsx("p", { className: "chatai-kicker", children: "Knowledge assistant" }),
170
- /* @__PURE__ */ jsx("h2", { children: state.config?.name ?? "Loading assistant\u2026" })
522
+ /* @__PURE__ */ jsxs3("header", { className: "chatai-header", children: [
523
+ /* @__PURE__ */ jsxs3("div", { children: [
524
+ /* @__PURE__ */ jsx3("p", { className: "chatai-kicker", children: "Knowledge assistant" }),
525
+ /* @__PURE__ */ jsx3("h2", { children: state.config?.name ?? "Loading assistant\u2026" })
171
526
  ] }),
172
- /* @__PURE__ */ jsx("button", { type: "button", className: "chatai-close", onClick: closePanel, "aria-label": "Close chat", children: "\xD7" })
527
+ /* @__PURE__ */ jsx3("button", { type: "button", className: "chatai-close", onClick: closePanel, "aria-label": "Close chat", children: "\xD7" })
173
528
  ] }),
174
- /* @__PURE__ */ jsxs("div", { ref: transcriptRef, className: "chatai-transcript", "aria-live": "polite", children: [
175
- state.config?.welcomeMessage ? /* @__PURE__ */ jsx("article", { className: "chatai-message assistant", children: /* @__PURE__ */ jsx("p", { children: state.config.welcomeMessage }) }) : null,
176
- questions.length > 0 && state.messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "chatai-prompts", children: questions.map((question) => /* @__PURE__ */ jsx("button", { type: "button", onClick: () => send(question), disabled: busy, children: question }, question)) }) : null,
529
+ /* @__PURE__ */ jsxs3("div", { ref: transcriptRef, className: "chatai-transcript", "aria-live": voiceOn ? "off" : "polite", children: [
530
+ state.config?.welcomeMessage ? /* @__PURE__ */ jsx3("article", { className: "chatai-message assistant", children: /* @__PURE__ */ jsx3(MarkdownMessage, { content: state.config.welcomeMessage }) }) : null,
531
+ questions.length > 0 && state.messages.length === 0 ? /* @__PURE__ */ jsx3("div", { className: "chatai-prompts", children: questions.map((question) => /* @__PURE__ */ jsx3("button", { type: "button", onClick: () => send(question), disabled: busy, children: question }, question)) }) : null,
177
532
  state.messages.map((message, index) => {
178
- const isStreamingPlaceholder = showTyping && index === state.messages.length - 1 && message.role === "assistant";
179
- return /* @__PURE__ */ jsxs("article", { className: `chatai-message ${message.role}`, children: [
180
- isStreamingPlaceholder ? /* @__PURE__ */ jsx(TypingIndicator, {}) : /* @__PURE__ */ jsx("p", { children: message.content || (busy && message.role === "assistant" ? "Thinking\u2026" : "") }),
181
- settings.showSources !== false && message.sources?.length ? /* @__PURE__ */ jsx("ul", { className: "chatai-sources", "aria-label": "Sources", children: message.sources.map((source) => /* @__PURE__ */ jsxs("li", { children: [
182
- /* @__PURE__ */ jsx("strong", { children: source.documentName }),
183
- source.page != null ? ` \xB7 p. ${source.page}` : ""
184
- ] }, `${source.documentId}-${source.chunkId ?? source.page ?? source.documentName}`)) }) : null,
185
- message.role === "assistant" && message.id ? /* @__PURE__ */ jsxs("div", { className: "chatai-feedback", children: [
186
- /* @__PURE__ */ jsx("span", { children: "Was this helpful?" }),
187
- /* @__PURE__ */ jsx(
188
- "button",
189
- {
190
- type: "button",
191
- "aria-label": "Mark response helpful",
192
- "aria-pressed": message.feedback === "positive",
193
- onClick: () => rate(message.id, "positive"),
194
- children: "\u2191"
195
- }
196
- ),
197
- /* @__PURE__ */ jsx(
198
- "button",
199
- {
200
- type: "button",
201
- "aria-label": "Mark response not helpful",
202
- "aria-pressed": message.feedback === "negative",
203
- onClick: () => rate(message.id, "negative"),
204
- children: "\u2193"
205
- }
206
- )
207
- ] }) : null
208
- ] }, `${message.role}-${index}`);
533
+ const isLast = index === state.messages.length - 1;
534
+ const isStreamingPlaceholder = showTyping && isLast && message.role === "assistant";
535
+ const isStreamingContent = streaming && isLast && message.role === "assistant" && Boolean(message.content);
536
+ const isVoice = message.modality === "voice";
537
+ return /* @__PURE__ */ jsxs3(
538
+ "article",
539
+ {
540
+ className: `chatai-message ${message.role}${isVoice ? " is-voice" : ""}${message.live ? " is-live" : ""}`,
541
+ children: [
542
+ isVoice ? /* @__PURE__ */ jsxs3("span", { className: "chatai-voice-tag", children: [
543
+ /* @__PURE__ */ jsx3(VoiceGlyph, {}),
544
+ /* @__PURE__ */ jsx3("span", { className: "chatai-visually-hidden", children: message.role === "user" ? "You said:" : "Assistant said:" })
545
+ ] }) : null,
546
+ isStreamingPlaceholder ? /* @__PURE__ */ jsx3(TypingIndicator, {}) : message.role === "assistant" && !isVoice ? message.content ? /* @__PURE__ */ jsx3(MarkdownMessage, { content: message.content, streaming: isStreamingContent }) : /* @__PURE__ */ jsx3("p", { children: streaming ? "Thinking\u2026" : "" }) : /* @__PURE__ */ jsx3("p", { className: "chatai-user-text", children: message.content }),
547
+ message.interrupted ? /* @__PURE__ */ jsx3("p", { className: "chatai-voice-note", children: "Interrupted" }) : null,
548
+ message.role === "assistant" && message.id ? /* @__PURE__ */ jsxs3("div", { className: "chatai-feedback", children: [
549
+ /* @__PURE__ */ jsx3("span", { children: "Was this helpful?" }),
550
+ /* @__PURE__ */ jsx3(
551
+ "button",
552
+ {
553
+ type: "button",
554
+ "aria-label": "Mark response helpful",
555
+ "aria-pressed": message.feedback === "positive",
556
+ onClick: () => rate(message.id, "positive"),
557
+ children: /* @__PURE__ */ jsx3(ThumbUpGlyph, {})
558
+ }
559
+ ),
560
+ /* @__PURE__ */ jsx3(
561
+ "button",
562
+ {
563
+ type: "button",
564
+ "aria-label": "Mark response not helpful",
565
+ "aria-pressed": message.feedback === "negative",
566
+ onClick: () => rate(message.id, "negative"),
567
+ children: /* @__PURE__ */ jsx3(ThumbDownGlyph, {})
568
+ }
569
+ )
570
+ ] }) : null
571
+ ]
572
+ },
573
+ `${message.role}-${index}`
574
+ );
209
575
  }),
210
- state.error ? /* @__PURE__ */ jsxs("div", { className: "chatai-error", role: "alert", children: [
211
- /* @__PURE__ */ jsx("p", { children: state.error }),
212
- /* @__PURE__ */ jsx("button", { type: "button", className: "chatai-retry", onClick: retry, disabled: busy, children: "Retry" })
576
+ state.error ? /* @__PURE__ */ jsxs3("div", { className: "chatai-error", role: "alert", children: [
577
+ /* @__PURE__ */ jsx3("p", { children: state.error }),
578
+ /* @__PURE__ */ jsx3("button", { type: "button", className: "chatai-retry", onClick: retry, disabled: busy, children: "Retry" })
213
579
  ] }) : null
214
580
  ] }),
215
- /* @__PURE__ */ jsxs(
581
+ voiceOffered && state.voice.consentPending ? /* @__PURE__ */ jsx3(
582
+ VoiceConsent,
583
+ {
584
+ onAccept: () => void controller.acceptRecordingConsent(),
585
+ onCancel: () => {
586
+ controller.declineRecordingConsent();
587
+ panelRef.current?.querySelector("#chatai-message-input")?.focus();
588
+ }
589
+ }
590
+ ) : null,
591
+ voiceOffered ? /* @__PURE__ */ jsx3(
592
+ VoiceBar,
593
+ {
594
+ voice: state.voice,
595
+ levels: () => controller.voiceLevels(),
596
+ onRetry: () => void controller.startVoice(),
597
+ onDismiss: () => controller.dismissVoiceError()
598
+ }
599
+ ) : null,
600
+ /* @__PURE__ */ jsxs3(
216
601
  "form",
217
602
  {
218
603
  className: "chatai-composer",
@@ -221,26 +606,39 @@ function WidgetApp(props) {
221
606
  send(draft);
222
607
  },
223
608
  children: [
224
- /* @__PURE__ */ jsx("label", { className: "chatai-visually-hidden", htmlFor: "chatai-message-input", children: "Message" }),
225
- /* @__PURE__ */ jsx(
609
+ /* @__PURE__ */ jsx3("label", { className: "chatai-visually-hidden", htmlFor: "chatai-message-input", children: "Message" }),
610
+ /* @__PURE__ */ jsx3(
226
611
  "input",
227
612
  {
228
613
  id: "chatai-message-input",
229
614
  value: draft,
230
615
  onInput: (event) => setDraft(event.currentTarget.value),
231
- placeholder: "Ask a question\u2026",
616
+ placeholder: voiceOn ? "Voice is on \u2014 end it to type" : "Ask a question\u2026",
232
617
  maxLength: 4e3,
233
618
  disabled: busy
234
619
  }
235
620
  ),
236
- /* @__PURE__ */ jsx("button", { type: "submit", disabled: busy || !draft.trim(), "aria-label": "Send message", children: "\u2191" })
621
+ voiceOffered ? /* @__PURE__ */ jsx3(
622
+ "button",
623
+ {
624
+ type: "button",
625
+ className: `chatai-mic${voiceOn ? " is-active" : ""}`,
626
+ onClick: toggleVoice,
627
+ disabled: streaming,
628
+ "aria-pressed": voiceOn,
629
+ "aria-label": voiceOn ? "End voice conversation" : "Start voice conversation",
630
+ title: voiceOn ? "End voice" : "Talk instead",
631
+ children: /* @__PURE__ */ jsx3(MicGlyph, { off: voiceOn })
632
+ }
633
+ ) : null,
634
+ /* @__PURE__ */ jsx3("button", { type: "submit", disabled: busy || !draft.trim(), "aria-label": "Send message", children: "\u2191" })
237
635
  ]
238
636
  }
239
637
  )
240
638
  ]
241
639
  }
242
640
  ) : null,
243
- /* @__PURE__ */ jsx(
641
+ /* @__PURE__ */ jsx3(
244
642
  "button",
245
643
  {
246
644
  ref: launcherRef,
@@ -250,7 +648,7 @@ function WidgetApp(props) {
250
648
  "aria-label": open || closing ? "Close chat" : "Open chat",
251
649
  "aria-expanded": open && !closing,
252
650
  "aria-haspopup": "dialog",
253
- children: settings.iconUrl ? /* @__PURE__ */ jsx("img", { src: settings.iconUrl, alt: "" }) : /* @__PURE__ */ jsx(ChatGlyph, {})
651
+ children: settings.iconUrl ? /* @__PURE__ */ jsx3("img", { src: settings.iconUrl, alt: "" }) : /* @__PURE__ */ jsx3(ChatGlyph, {})
254
652
  }
255
653
  )
256
654
  ]
@@ -259,11 +657,11 @@ function WidgetApp(props) {
259
657
  }
260
658
 
261
659
  // src/styles.generated.ts
262
- var styles = ':host {\n all: initial;\n}\n\n.chatai-widget {\n --chatai-accent: #0f766e;\n --chatai-ink: #14241e;\n --chatai-surface: #f6f6f0;\n --chatai-panel: #fffef9;\n --chatai-muted: #6d766f;\n --chatai-border: #d9ddd7;\n display: flex;\n width: fit-content;\n max-width: calc(100vw - 32px);\n flex-direction: column;\n align-items: flex-end;\n position: fixed;\n z-index: 2147483647;\n bottom: 20px;\n font-family: ui-rounded, "SF Pro Rounded", "Avenir Next", sans-serif;\n color: var(--chatai-ink);\n}\n\n.chatai-widget.position-right {\n right: 20px;\n align-items: flex-end;\n}\n\n.chatai-widget.position-left {\n left: 20px;\n align-items: flex-start;\n}\n\n.chatai-widget.layout-contained {\n position: absolute;\n z-index: 1;\n max-width: 100%;\n}\n\n.chatai-widget-host-contained {\n position: relative;\n display: block;\n width: 100%;\n height: 100%;\n}\n\n.chatai-widget.layout-contained .chatai-panel {\n width: min(380px, 100%);\n height: min(570px, calc(100% - 70px));\n}\n\n.chatai-widget.layout-contained.position-right {\n right: 12px;\n}\n\n.chatai-widget.layout-contained.position-left {\n left: 12px;\n}\n\n.chatai-widget.theme-dark {\n --chatai-ink: #ecf4ec;\n --chatai-surface: #17231d;\n --chatai-panel: #101a14;\n --chatai-muted: #a9b8ad;\n --chatai-border: #2d4135;\n}\n\n.chatai-widget *,\n.chatai-widget *::before,\n.chatai-widget *::after {\n box-sizing: border-box;\n}\n\n.chatai-launcher {\n display: grid;\n flex-shrink: 0;\n width: 56px;\n height: 56px;\n padding: 0;\n place-items: center;\n border: 0;\n border-radius: 50% 50% 14% 50%;\n background: var(--chatai-accent);\n color: white;\n cursor: pointer;\n box-shadow: 0 12px 28px rgb(20 36 30 / 26%);\n transition: transform 160ms ease, box-shadow 160ms ease;\n}\n\n.chatai-widget.position-left .chatai-launcher {\n border-radius: 50% 50% 50% 14%;\n}\n\n.chatai-launcher[aria-expanded="true"] {\n transform: rotate(8deg) scale(0.96);\n}\n\n.chatai-launcher:hover {\n transform: translateY(-2px) rotate(-3deg);\n box-shadow: 0 16px 32px rgb(20 36 30 / 34%);\n}\n\n.chatai-launcher:focus-visible,\n.chatai-close:focus-visible,\n.chatai-prompts button:focus-visible,\n.chatai-composer input:focus-visible,\n.chatai-composer button:focus-visible {\n outline: 3px solid color-mix(in srgb, var(--chatai-accent), white 55%);\n outline-offset: 2px;\n}\n\n.chatai-launcher svg,\n.chatai-launcher img {\n width: 24px;\n height: 24px;\n}\n\n.chatai-launcher img {\n border-radius: 50%;\n object-fit: cover;\n}\n\n.chatai-panel {\n display: flex;\n width: min(380px, calc(100vw - 32px));\n height: min(570px, calc(100dvh - 104px));\n margin-bottom: 14px;\n flex-direction: column;\n flex-shrink: 0;\n overflow: hidden;\n border: 1px solid var(--chatai-border);\n border-radius: 24px 24px 8px 24px;\n background: var(--chatai-panel);\n box-shadow: 0 24px 70px rgb(20 36 30 / 24%);\n transform-origin: bottom right;\n animation: chatai-panel-in 180ms ease-out;\n}\n\n.chatai-widget.position-left .chatai-panel {\n border-radius: 24px 24px 24px 8px;\n transform-origin: bottom left;\n}\n\n.chatai-panel.is-closing {\n animation: chatai-panel-out 140ms ease-in forwards;\n}\n\n@keyframes chatai-panel-in {\n from {\n opacity: 0;\n transform: translateY(10px) scale(0.98);\n }\n\n to {\n opacity: 1;\n transform: none;\n }\n}\n\n@keyframes chatai-panel-out {\n from {\n opacity: 1;\n transform: none;\n }\n\n to {\n opacity: 0;\n transform: translateY(8px) scale(0.98);\n }\n}\n\n.chatai-header {\n display: flex;\n align-items: flex-start;\n justify-content: space-between;\n padding: 20px 20px 16px;\n border-bottom: 1px solid var(--chatai-border);\n background: linear-gradient(135deg, color-mix(in srgb, var(--chatai-accent), var(--chatai-panel) 90%), var(--chatai-panel));\n}\n\n.chatai-widget.position-left .chatai-header {\n background: linear-gradient(225deg, color-mix(in srgb, var(--chatai-accent), var(--chatai-panel) 90%), var(--chatai-panel));\n}\n\n.chatai-kicker {\n margin: 0 0 5px;\n color: var(--chatai-muted);\n font-size: 10px;\n font-weight: 750;\n letter-spacing: 0.14em;\n text-transform: uppercase;\n}\n\n.chatai-header h2 {\n margin: 0;\n font-size: 18px;\n letter-spacing: -0.03em;\n}\n\n.chatai-close {\n display: grid;\n width: 30px;\n height: 30px;\n place-items: center;\n border: 1px solid var(--chatai-border);\n border-radius: 50%;\n background: transparent;\n color: var(--chatai-ink);\n cursor: pointer;\n font-size: 22px;\n line-height: 1;\n}\n\n.chatai-transcript {\n display: flex;\n flex: 1;\n flex-direction: column;\n gap: 12px;\n overflow-y: auto;\n padding: 18px;\n background:\n radial-gradient(circle at 95% 4%, color-mix(in srgb, var(--chatai-accent), transparent 90%), transparent 30%),\n var(--chatai-surface);\n}\n\n.chatai-widget.position-left .chatai-transcript {\n background:\n radial-gradient(circle at 5% 4%, color-mix(in srgb, var(--chatai-accent), transparent 90%), transparent 30%),\n var(--chatai-surface);\n}\n\n.chatai-message {\n max-width: 87%;\n padding: 12px 13px;\n border-radius: 15px;\n font-size: 14px;\n line-height: 1.45;\n}\n\n.chatai-message p {\n margin: 0;\n white-space: pre-wrap;\n}\n\n.chatai-message.assistant {\n align-self: flex-start;\n border: 1px solid var(--chatai-border);\n border-radius: 5px 15px 15px;\n background: var(--chatai-panel);\n}\n\n.chatai-message.user {\n align-self: flex-end;\n border-radius: 15px 5px 15px 15px;\n background: var(--chatai-accent);\n color: #fff;\n}\n\n.chatai-prompts {\n display: flex;\n flex-wrap: wrap;\n gap: 7px;\n}\n\n.chatai-prompts button {\n border: 1px solid color-mix(in srgb, var(--chatai-accent), var(--chatai-border) 60%);\n border-radius: 999px;\n background: transparent;\n color: var(--chatai-ink);\n cursor: pointer;\n font: inherit;\n font-size: 12px;\n line-height: 1.25;\n padding: 8px 10px;\n text-align: left;\n}\n\n.chatai-sources {\n display: flex;\n margin: 10px 0 0;\n padding: 9px 0 0;\n flex-direction: column;\n gap: 4px;\n border-top: 1px solid var(--chatai-border);\n color: var(--chatai-muted);\n font-size: 11px;\n list-style: none;\n}\n\n.chatai-feedback {\n display: flex;\n align-items: center;\n gap: 5px;\n margin-top: 10px;\n padding-top: 9px;\n border-top: 1px solid var(--chatai-border);\n color: var(--chatai-muted);\n font-size: 11px;\n}\n\n.chatai-feedback span {\n margin-right: 2px;\n}\n\n.chatai-feedback button {\n width: 25px;\n height: 25px;\n border: 1px solid var(--chatai-border);\n border-radius: 6px;\n background: transparent;\n color: var(--chatai-ink);\n cursor: pointer;\n font: inherit;\n line-height: 1;\n}\n\n.chatai-feedback button[aria-pressed="true"] {\n border-color: var(--chatai-accent);\n background: color-mix(in srgb, var(--chatai-accent), transparent 90%);\n color: var(--chatai-accent);\n}\n\n.chatai-error {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 8px;\n margin: 0;\n padding: 10px 12px;\n border: 1px solid color-mix(in srgb, #b42318, var(--chatai-border) 55%);\n border-radius: 12px;\n background: color-mix(in srgb, #b42318, transparent 92%);\n color: #b42318;\n font-size: 12px;\n text-align: center;\n}\n\n.chatai-error p {\n margin: 0;\n line-height: 1.4;\n}\n\n.chatai-retry {\n border: 1px solid color-mix(in srgb, #b42318, var(--chatai-border) 40%);\n border-radius: 8px;\n background: var(--chatai-panel);\n color: #b42318;\n cursor: pointer;\n font: inherit;\n font-size: 12px;\n font-weight: 600;\n padding: 6px 12px;\n}\n\n.chatai-retry:disabled {\n cursor: not-allowed;\n opacity: 0.48;\n}\n\n.chatai-typing {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n min-height: 1.2em;\n}\n\n.chatai-typing span {\n width: 6px;\n height: 6px;\n border-radius: 50%;\n background: var(--chatai-muted);\n animation: chatai-typing-dot 1s ease-in-out infinite;\n}\n\n.chatai-typing span:nth-child(2) {\n animation-delay: 0.15s;\n}\n\n.chatai-typing span:nth-child(3) {\n animation-delay: 0.3s;\n}\n\n@keyframes chatai-typing-dot {\n 0%,\n 80%,\n 100% {\n opacity: 0.35;\n transform: translateY(0);\n }\n\n 40% {\n opacity: 1;\n transform: translateY(-2px);\n }\n}\n\n.chatai-composer {\n display: flex;\n gap: 8px;\n padding: 12px;\n border-top: 1px solid var(--chatai-border);\n background: var(--chatai-panel);\n}\n\n.chatai-composer input {\n min-width: 0;\n flex: 1;\n border: 1px solid var(--chatai-border);\n border-radius: 10px;\n background: transparent;\n color: var(--chatai-ink);\n font: inherit;\n font-size: 14px;\n padding: 10px 11px;\n}\n\n.chatai-composer button {\n width: 40px;\n border: 0;\n border-radius: 10px;\n background: var(--chatai-accent);\n color: white;\n cursor: pointer;\n font-size: 18px;\n}\n\n.chatai-composer button:disabled,\n.chatai-prompts button:disabled {\n cursor: not-allowed;\n opacity: 0.48;\n}\n\n.chatai-visually-hidden {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip: rect(0 0 0 0);\n white-space: nowrap;\n}\n\n@media (max-width: 480px) {\n .chatai-widget {\n bottom: 12px;\n }\n\n .chatai-widget.position-right {\n right: 12px;\n }\n\n .chatai-widget.position-left {\n left: 12px;\n }\n\n .chatai-panel {\n width: calc(100vw - 24px);\n height: min(600px, calc(100dvh - 88px));\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .chatai-launcher,\n .chatai-launcher:hover,\n .chatai-launcher[aria-expanded="true"] {\n transition: none;\n transform: none;\n }\n\n .chatai-panel,\n .chatai-panel.is-closing {\n animation: none;\n }\n\n .chatai-typing span {\n animation: none;\n opacity: 0.7;\n }\n}\n';
660
+ var styles = ':host {\n all: initial;\n}\n\n.chatai-widget {\n --chatai-accent: #0f766e;\n --chatai-ink: #14241e;\n --chatai-surface: #f6f6f0;\n --chatai-panel: #fffef9;\n --chatai-muted: #6d766f;\n --chatai-border: #d9ddd7;\n display: flex;\n width: fit-content;\n max-width: calc(100vw - 32px);\n flex-direction: column;\n align-items: flex-end;\n position: fixed;\n z-index: 2147483647;\n bottom: 20px;\n font-family: ui-rounded, "SF Pro Rounded", "Avenir Next", sans-serif;\n color: var(--chatai-ink);\n}\n\n.chatai-widget.position-right {\n right: 20px;\n align-items: flex-end;\n}\n\n.chatai-widget.position-left {\n left: 20px;\n align-items: flex-start;\n}\n\n.chatai-widget.layout-contained {\n position: absolute;\n z-index: 1;\n max-width: 100%;\n}\n\n.chatai-widget-host-contained {\n position: relative;\n display: block;\n width: 100%;\n height: 100%;\n}\n\n.chatai-widget.layout-contained .chatai-panel {\n width: min(380px, 100%);\n height: min(570px, calc(100% - 70px));\n}\n\n.chatai-widget.layout-contained.position-right {\n right: 12px;\n}\n\n.chatai-widget.layout-contained.position-left {\n left: 12px;\n}\n\n.chatai-widget.theme-dark {\n --chatai-ink: #ecf4ec;\n --chatai-surface: #17231d;\n --chatai-panel: #101a14;\n --chatai-muted: #a9b8ad;\n --chatai-border: #2d4135;\n}\n\n.chatai-widget *,\n.chatai-widget *::before,\n.chatai-widget *::after {\n box-sizing: border-box;\n}\n\n.chatai-launcher {\n display: grid;\n flex-shrink: 0;\n width: 56px;\n height: 56px;\n padding: 0;\n place-items: center;\n border: 0;\n border-radius: 50% 50% 14% 50%;\n background: var(--chatai-accent);\n color: white;\n cursor: pointer;\n box-shadow: 0 12px 28px rgb(20 36 30 / 26%);\n transition: transform 160ms ease, box-shadow 160ms ease;\n}\n\n.chatai-widget.position-left .chatai-launcher {\n border-radius: 50% 50% 50% 14%;\n}\n\n.chatai-launcher[aria-expanded="true"] {\n transform: rotate(8deg) scale(0.96);\n}\n\n.chatai-launcher:hover {\n transform: translateY(-2px) rotate(-3deg);\n box-shadow: 0 16px 32px rgb(20 36 30 / 34%);\n}\n\n.chatai-launcher:focus-visible,\n.chatai-close:focus-visible,\n.chatai-prompts button:focus-visible,\n.chatai-composer input:focus-visible,\n.chatai-composer button:focus-visible,\n.chatai-retry:focus-visible {\n outline: 3px solid color-mix(in srgb, var(--chatai-accent), white 55%);\n outline-offset: 2px;\n}\n\n.chatai-launcher svg,\n.chatai-launcher img {\n width: 24px;\n height: 24px;\n}\n\n.chatai-launcher img {\n border-radius: 50%;\n object-fit: cover;\n}\n\n.chatai-panel {\n display: flex;\n width: min(380px, calc(100vw - 32px));\n height: min(570px, calc(100dvh - 104px));\n margin-bottom: 14px;\n flex-direction: column;\n flex-shrink: 0;\n overflow: hidden;\n border: 1px solid var(--chatai-border);\n border-radius: 24px 24px 8px 24px;\n background: var(--chatai-panel);\n box-shadow: 0 24px 70px rgb(20 36 30 / 24%);\n transform-origin: bottom right;\n animation: chatai-panel-in 180ms ease-out;\n}\n\n.chatai-widget.position-left .chatai-panel {\n border-radius: 24px 24px 24px 8px;\n transform-origin: bottom left;\n}\n\n.chatai-panel.is-closing {\n animation: chatai-panel-out 140ms ease-in forwards;\n}\n\n@keyframes chatai-panel-in {\n from {\n opacity: 0;\n transform: translateY(10px) scale(0.98);\n }\n\n to {\n opacity: 1;\n transform: none;\n }\n}\n\n@keyframes chatai-panel-out {\n from {\n opacity: 1;\n transform: none;\n }\n\n to {\n opacity: 0;\n transform: translateY(8px) scale(0.98);\n }\n}\n\n.chatai-header {\n display: flex;\n align-items: flex-start;\n justify-content: space-between;\n padding: 20px 20px 16px;\n border-bottom: 1px solid var(--chatai-border);\n background: linear-gradient(135deg, color-mix(in srgb, var(--chatai-accent), var(--chatai-panel) 90%), var(--chatai-panel));\n}\n\n.chatai-widget.position-left .chatai-header {\n background: linear-gradient(225deg, color-mix(in srgb, var(--chatai-accent), var(--chatai-panel) 90%), var(--chatai-panel));\n}\n\n.chatai-kicker {\n margin: 0 0 5px;\n color: var(--chatai-muted);\n font-size: 10px;\n font-weight: 750;\n letter-spacing: 0.14em;\n text-transform: uppercase;\n}\n\n.chatai-header h2 {\n margin: 0;\n font-size: 18px;\n letter-spacing: -0.03em;\n}\n\n.chatai-close {\n display: grid;\n width: 30px;\n height: 30px;\n place-items: center;\n border: 1px solid var(--chatai-border);\n border-radius: 50%;\n background: transparent;\n color: var(--chatai-ink);\n cursor: pointer;\n font-size: 22px;\n line-height: 1;\n}\n\n.chatai-transcript {\n display: flex;\n flex: 1;\n flex-direction: column;\n gap: 12px;\n overflow-y: auto;\n padding: 18px;\n background:\n radial-gradient(circle at 95% 4%, color-mix(in srgb, var(--chatai-accent), transparent 90%), transparent 30%),\n var(--chatai-surface);\n}\n\n.chatai-widget.position-left .chatai-transcript {\n background:\n radial-gradient(circle at 5% 4%, color-mix(in srgb, var(--chatai-accent), transparent 90%), transparent 30%),\n var(--chatai-surface);\n}\n\n.chatai-message {\n max-width: 87%;\n padding: 12px 13px;\n border-radius: 15px;\n font-size: 14px;\n line-height: 1.45;\n}\n\n.chatai-message p,\n.chatai-user-text {\n margin: 0;\n white-space: pre-wrap;\n}\n\n.chatai-message.assistant {\n align-self: flex-start;\n border: 1px solid var(--chatai-border);\n border-radius: 5px 15px 15px;\n background: var(--chatai-panel);\n}\n\n.chatai-message.user {\n align-self: flex-end;\n border-radius: 15px 5px 15px 15px;\n background: var(--chatai-accent);\n color: #fff;\n}\n\n.chatai-md {\n font-size: 14px;\n line-height: 1.5;\n}\n\n.chatai-md-p {\n margin: 0;\n white-space: pre-wrap;\n}\n\n.chatai-md-p + .chatai-md-p,\n.chatai-md-p + .chatai-md-ul,\n.chatai-md-p + .chatai-md-ol,\n.chatai-md-p + .chatai-md-pre,\n.chatai-md-ul + .chatai-md-p,\n.chatai-md-ol + .chatai-md-p,\n.chatai-md-pre + .chatai-md-p {\n margin-top: 0.55em;\n}\n\n.chatai-md-ul,\n.chatai-md-ol {\n margin: 0.45em 0;\n padding-left: 1.25em;\n}\n\n.chatai-md-ul {\n list-style: disc;\n}\n\n.chatai-md-ol {\n list-style: decimal;\n}\n\n.chatai-md-link {\n color: var(--chatai-accent);\n text-decoration: underline;\n text-underline-offset: 2px;\n}\n\n.chatai-md-link:focus-visible {\n outline: 2px solid var(--chatai-accent);\n outline-offset: 2px;\n border-radius: 2px;\n}\n\n.chatai-md-code {\n border-radius: 4px;\n background: color-mix(in srgb, var(--chatai-border), transparent 55%);\n padding: 0.1em 0.35em;\n font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n font-size: 0.85em;\n}\n\n.chatai-md-pre {\n margin: 0.55em 0;\n overflow-x: auto;\n border-radius: 8px;\n background: color-mix(in srgb, var(--chatai-border), transparent 55%);\n padding: 0.65em 0.75em;\n font-size: 0.85em;\n}\n\n.chatai-md-pre code {\n font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n white-space: pre;\n}\n\n.chatai-md-caret {\n display: inline-block;\n width: 2px;\n height: 0.9em;\n margin-left: 2px;\n vertical-align: middle;\n background: var(--chatai-ink);\n animation: chatai-caret-pulse 1s ease-in-out infinite;\n}\n\n@keyframes chatai-caret-pulse {\n 0%,\n 100% {\n opacity: 1;\n }\n 50% {\n opacity: 0.2;\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .chatai-md-caret {\n animation: none;\n opacity: 0.7;\n }\n}\n\n.chatai-prompts {\n display: flex;\n flex-wrap: wrap;\n gap: 7px;\n}\n\n.chatai-prompts button {\n border: 1px solid color-mix(in srgb, var(--chatai-accent), var(--chatai-border) 60%);\n border-radius: 999px;\n background: transparent;\n color: var(--chatai-ink);\n cursor: pointer;\n font: inherit;\n font-size: 12px;\n line-height: 1.25;\n padding: 8px 10px;\n text-align: left;\n}\n\n.chatai-feedback {\n display: flex;\n align-items: center;\n gap: 5px;\n margin-top: 10px;\n padding-top: 9px;\n border-top: 1px solid var(--chatai-border);\n color: var(--chatai-muted);\n font-size: 11px;\n}\n\n.chatai-feedback span {\n margin-right: 2px;\n}\n\n.chatai-feedback button {\n display: inline-grid;\n place-items: center;\n width: 25px;\n height: 25px;\n border: 1px solid var(--chatai-border);\n border-radius: 6px;\n background: transparent;\n color: var(--chatai-ink);\n cursor: pointer;\n font: inherit;\n line-height: 1;\n padding: 0;\n}\n\n.chatai-feedback button svg {\n width: 13px;\n height: 13px;\n}\n\n.chatai-feedback button[aria-pressed="true"] {\n border-color: var(--chatai-accent);\n background: color-mix(in srgb, var(--chatai-accent), transparent 90%);\n color: var(--chatai-accent);\n}\n\n.chatai-error {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 8px;\n margin: 0;\n padding: 10px 12px;\n border: 1px solid color-mix(in srgb, #b42318, var(--chatai-border) 55%);\n border-radius: 12px;\n background: color-mix(in srgb, #b42318, transparent 92%);\n color: #b42318;\n font-size: 12px;\n text-align: center;\n}\n\n.chatai-error p {\n margin: 0;\n line-height: 1.4;\n}\n\n.chatai-retry {\n border: 1px solid color-mix(in srgb, #b42318, var(--chatai-border) 40%);\n border-radius: 8px;\n background: var(--chatai-panel);\n color: #b42318;\n cursor: pointer;\n font: inherit;\n font-size: 12px;\n font-weight: 600;\n padding: 6px 12px;\n}\n\n.chatai-retry:disabled {\n cursor: not-allowed;\n opacity: 0.48;\n}\n\n.chatai-typing {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n min-height: 1.2em;\n}\n\n.chatai-typing span {\n width: 6px;\n height: 6px;\n border-radius: 50%;\n background: var(--chatai-muted);\n animation: chatai-typing-dot 1s ease-in-out infinite;\n}\n\n.chatai-typing span:nth-child(2) {\n animation-delay: 0.15s;\n}\n\n.chatai-typing span:nth-child(3) {\n animation-delay: 0.3s;\n}\n\n@keyframes chatai-typing-dot {\n 0%,\n 80%,\n 100% {\n opacity: 0.35;\n transform: translateY(0);\n }\n\n 40% {\n opacity: 1;\n transform: translateY(-2px);\n }\n}\n\n.chatai-composer {\n display: flex;\n gap: 8px;\n padding: 12px;\n border-top: 1px solid var(--chatai-border);\n background: var(--chatai-panel);\n}\n\n.chatai-composer input {\n min-width: 0;\n flex: 1;\n border: 1px solid var(--chatai-border);\n border-radius: 10px;\n background: transparent;\n color: var(--chatai-ink);\n font: inherit;\n font-size: 14px;\n padding: 10px 11px;\n}\n\n.chatai-composer button {\n width: 40px;\n border: 0;\n border-radius: 10px;\n background: var(--chatai-accent);\n color: white;\n cursor: pointer;\n font-size: 18px;\n}\n\n.chatai-composer button:disabled,\n.chatai-prompts button:disabled {\n cursor: not-allowed;\n opacity: 0.48;\n}\n\n.chatai-composer input:disabled {\n cursor: not-allowed;\n opacity: 0.7;\n}\n\n.chatai-composer .chatai-mic {\n display: grid;\n place-items: center;\n border: 1px solid var(--chatai-border);\n background: transparent;\n color: var(--chatai-ink);\n}\n\n.chatai-composer .chatai-mic svg {\n width: 18px;\n height: 18px;\n}\n\n.chatai-composer .chatai-mic.is-active {\n border-color: #b42318;\n background: #b42318;\n color: #fff;\n}\n\n.chatai-voice-bar {\n display: flex;\n align-items: center;\n gap: 10px;\n min-height: 44px;\n padding: 8px 14px;\n border-top: 1px solid var(--chatai-border);\n background: color-mix(in srgb, var(--chatai-accent), var(--chatai-panel) 92%);\n font-size: 13px;\n}\n\n.chatai-voice-bar.is-error {\n flex-wrap: wrap;\n justify-content: center;\n background: color-mix(in srgb, #b42318, transparent 92%);\n color: #b42318;\n text-align: center;\n}\n\n.chatai-voice-bar.is-notice {\n flex-wrap: wrap;\n justify-content: center;\n text-align: center;\n}\n\n.chatai-voice-error {\n width: 100%;\n margin: 0;\n font-size: 12px;\n line-height: 1.4;\n}\n\n.chatai-voice-actions {\n display: flex;\n gap: 8px;\n}\n\n.chatai-voice-consent {\n display: flex;\n flex-direction: column;\n gap: 8px;\n padding: 12px 14px;\n border-top: 1px solid var(--chatai-border);\n background: color-mix(in srgb, var(--chatai-accent), var(--chatai-panel) 92%);\n font-size: 13px;\n line-height: 1.45;\n}\n\n.chatai-voice-consent:focus-visible {\n outline: 2px solid var(--chatai-accent);\n outline-offset: -2px;\n}\n\n.chatai-voice-consent-title {\n margin: 0;\n font-weight: 650;\n}\n\n.chatai-voice-consent-text {\n margin: 0;\n color: var(--chatai-muted);\n font-size: 12px;\n}\n\n.chatai-consent-accept,\n.chatai-consent-cancel {\n min-height: 36px;\n padding: 0 14px;\n border-radius: 8px;\n font: inherit;\n font-size: 12px;\n font-weight: 600;\n cursor: pointer;\n}\n\n.chatai-consent-accept {\n border: 0;\n background: var(--chatai-accent);\n color: #fff;\n}\n\n.chatai-consent-cancel {\n border: 1px solid var(--chatai-border);\n background: var(--chatai-panel);\n color: var(--chatai-ink);\n}\n\n.chatai-voice-label {\n font-weight: 650;\n}\n\n.chatai-voice-meta {\n margin-left: auto;\n color: var(--chatai-muted);\n font-size: 11px;\n}\n\n.chatai-wave {\n display: inline-flex;\n align-items: center;\n gap: 3px;\n height: 22px;\n}\n\n.chatai-wave span {\n display: block;\n width: 4px;\n height: 22px;\n border-radius: 2px;\n background: var(--chatai-accent);\n transform: scaleY(0.22);\n transition: transform 80ms linear;\n}\n\n.chatai-voice-bar[data-phase="requesting_mic"] .chatai-wave span,\n.chatai-voice-bar[data-phase="connecting"] .chatai-wave span,\n.chatai-voice-bar[data-phase="processing"] .chatai-wave span {\n animation: chatai-wave-idle 1.1s ease-in-out infinite;\n}\n\n.chatai-wave span:nth-child(2) {\n animation-delay: 0.1s;\n}\n\n.chatai-wave span:nth-child(3) {\n animation-delay: 0.2s;\n}\n\n.chatai-wave span:nth-child(4) {\n animation-delay: 0.3s;\n}\n\n.chatai-wave span:nth-child(5) {\n animation-delay: 0.4s;\n}\n\n.chatai-voice-bar[data-phase="interrupted"] .chatai-wave span {\n background: #b54708;\n}\n\n.chatai-voice-bar[data-phase="reconnecting"] .chatai-wave span {\n background: var(--chatai-muted);\n}\n\n@keyframes chatai-wave-idle {\n 0%,\n 100% {\n transform: scaleY(0.22);\n }\n\n 50% {\n transform: scaleY(0.6);\n }\n}\n\n.chatai-voice-tag {\n display: inline-flex;\n float: right;\n margin: -2px -3px 2px 8px;\n opacity: 0.65;\n}\n\n.chatai-voice-tag svg {\n width: 13px;\n height: 13px;\n}\n\n.chatai-message.is-live {\n opacity: 0.85;\n}\n\n.chatai-message.is-live .chatai-user-text::after {\n content: "\u2026";\n}\n\n.chatai-voice-note {\n margin-top: 6px;\n color: var(--chatai-muted);\n font-size: 11px;\n font-style: italic;\n}\n\n.chatai-message.user .chatai-voice-note {\n color: rgb(255 255 255 / 80%);\n}\n\n.chatai-visually-hidden {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip: rect(0 0 0 0);\n white-space: nowrap;\n}\n\n@media (max-width: 480px) {\n .chatai-widget {\n bottom: 12px;\n }\n\n .chatai-widget.position-right {\n right: 12px;\n }\n\n .chatai-widget.position-left {\n left: 12px;\n }\n\n .chatai-panel {\n width: calc(100vw - 24px);\n height: min(600px, calc(100dvh - 88px));\n }\n\n .chatai-composer button {\n min-width: 44px;\n min-height: 44px;\n }\n\n .chatai-composer input {\n font-size: 16px;\n }\n\n .chatai-retry {\n min-height: 40px;\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .chatai-launcher,\n .chatai-launcher:hover,\n .chatai-launcher[aria-expanded="true"] {\n transition: none;\n transform: none;\n }\n\n .chatai-panel,\n .chatai-panel.is-closing {\n animation: none;\n }\n\n .chatai-typing span {\n animation: none;\n opacity: 0.7;\n }\n\n .chatai-wave span,\n .chatai-voice-bar .chatai-wave span {\n animation: none;\n transition: none;\n transform: scaleY(0.45);\n }\n}\n';
263
661
  var styles_generated_default = styles;
264
662
 
265
663
  // src/mount.tsx
266
- import { jsx as jsx2 } from "preact/jsx-runtime";
664
+ import { jsx as jsx4 } from "preact/jsx-runtime";
267
665
  function mountWidget(target, options) {
268
666
  const root = target.shadowRoot ?? target.attachShadow({ mode: "open" });
269
667
  const style = document.createElement("style");
@@ -271,7 +669,7 @@ function mountWidget(target, options) {
271
669
  const host = document.createElement("div");
272
670
  host.className = options.layout === "contained" ? "chatai-widget-host-contained" : "";
273
671
  root.replaceChildren(style, host);
274
- render(/* @__PURE__ */ jsx2(WidgetApp, { ...options }), host);
672
+ render(/* @__PURE__ */ jsx4(WidgetApp, { ...options }), host);
275
673
  return {
276
674
  destroy() {
277
675
  render(null, host);
@@ -297,7 +695,8 @@ function optionsFromScript(script) {
297
695
  apiUrl,
298
696
  ...signEndpoint ? { signEndpoint } : {},
299
697
  theme: option(script.dataset.theme, ["light", "dark", "system"]),
300
- position: option(script.dataset.position, ["bottom-left", "bottom-right"])
698
+ position: option(script.dataset.position, ["bottom-left", "bottom-right"]),
699
+ ...script.dataset.voice === "off" ? { voice: false } : {}
301
700
  };
302
701
  }
303
702
  export {