sagedesk 1.0.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.
@@ -0,0 +1,1402 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/react/index.ts
31
+ var react_exports = {};
32
+ __export(react_exports, {
33
+ SageDeskWidget: () => SageDeskWidget,
34
+ useSageDesk: () => useSageDesk
35
+ });
36
+ module.exports = __toCommonJS(react_exports);
37
+
38
+ // src/react/SageDeskWidget.tsx
39
+ var import_react2 = require("react");
40
+ var import_react_dom = require("react-dom");
41
+
42
+ // src/react/useSageDesk.ts
43
+ var import_react = require("react");
44
+
45
+ // src/core/embedder.ts
46
+ var XENOVA_IDS = {
47
+ "all-MiniLM-L6-v2": "Xenova/all-MiniLM-L6-v2",
48
+ "bge-small-en-v1-5": "Xenova/bge-small-en-v1.5",
49
+ "paraphrase-multilingual-MiniLM-L12-v2": "Xenova/paraphrase-multilingual-MiniLM-L12-v2",
50
+ "all-mpnet-base-v2": "Xenova/all-mpnet-base-v2"
51
+ };
52
+ var _EmbedderRuntime = class _EmbedderRuntime {
53
+ constructor() {
54
+ this._ready = false;
55
+ this._failed = false;
56
+ }
57
+ async load(model = "all-MiniLM-L6-v2") {
58
+ if (this._ready) return;
59
+ if (this._failed) throw new Error("EmbedderRuntime previously failed to load");
60
+ if (_EmbedderRuntime._loadingPromise) {
61
+ await _EmbedderRuntime._loadingPromise;
62
+ this._ready = true;
63
+ return;
64
+ }
65
+ const modelId = XENOVA_IDS[model];
66
+ _EmbedderRuntime._loadingPromise = (async () => {
67
+ try {
68
+ const { pipeline } = await import("@huggingface/transformers");
69
+ _EmbedderRuntime._pipelineInstance = await pipeline(
70
+ "feature-extraction",
71
+ modelId,
72
+ { dtype: "q8" }
73
+ );
74
+ } catch (err) {
75
+ _EmbedderRuntime._loadingPromise = null;
76
+ _EmbedderRuntime._pipelineInstance = null;
77
+ throw err;
78
+ }
79
+ })();
80
+ try {
81
+ await _EmbedderRuntime._loadingPromise;
82
+ this._ready = true;
83
+ } catch (err) {
84
+ this._failed = true;
85
+ throw err;
86
+ }
87
+ }
88
+ async embed(text) {
89
+ if (!_EmbedderRuntime._pipelineInstance) {
90
+ await this.load();
91
+ }
92
+ try {
93
+ const output = await _EmbedderRuntime._pipelineInstance(text, {
94
+ pooling: "mean",
95
+ normalize: true
96
+ });
97
+ return output.data;
98
+ } catch (err) {
99
+ throw new Error(`Embedding failed: ${String(err)}`);
100
+ }
101
+ }
102
+ get isReady() {
103
+ return this._ready;
104
+ }
105
+ get hasFailed() {
106
+ return this._failed;
107
+ }
108
+ /** @internal */
109
+ static _reset() {
110
+ _EmbedderRuntime._pipelineInstance = null;
111
+ _EmbedderRuntime._loadingPromise = null;
112
+ }
113
+ };
114
+ // Module-level singleton so the WASM model is loaded at most once per page,
115
+ // regardless of how many widget instances exist.
116
+ _EmbedderRuntime._pipelineInstance = null;
117
+ _EmbedderRuntime._loadingPromise = null;
118
+ var EmbedderRuntime = _EmbedderRuntime;
119
+
120
+ // src/core/search.ts
121
+ function dotProduct(a, b) {
122
+ if (a.length !== b.length) {
123
+ throw new Error(`Vector dimension mismatch: query(${a.length}) vs index(${b.length})`);
124
+ }
125
+ let dot = 0;
126
+ for (let i = 0; i < a.length; i++) dot += a[i] * b[i];
127
+ return dot;
128
+ }
129
+ function search(queryVector, index, topK = 3, minScore = 0.42) {
130
+ const results = [];
131
+ for (const chunk of index) {
132
+ const score = dotProduct(queryVector, chunk.vector384);
133
+ if (score < minScore) continue;
134
+ if (results.length < topK) {
135
+ results.push({ chunk, score });
136
+ results.sort((a, b) => b.score - a.score);
137
+ } else if (score > results[topK - 1].score) {
138
+ results[topK - 1] = { chunk, score };
139
+ results.sort((a, b) => b.score - a.score);
140
+ }
141
+ }
142
+ return results;
143
+ }
144
+ function keywordSearch(query, index, topK = 3) {
145
+ const terms = query.toLowerCase().split(/\s+/).filter((w) => w.length > 2).map((w) => w.replace(/[^a-z0-9]/g, ""));
146
+ if (terms.length === 0) return [];
147
+ const results = [];
148
+ for (const chunk of index) {
149
+ const chunkLower = chunk.textLower || chunk.text.toLowerCase();
150
+ const matchCount = terms.filter((t) => chunkLower.includes(t)).length;
151
+ const score = matchCount / terms.length;
152
+ if (score <= 0) continue;
153
+ if (results.length < topK) {
154
+ results.push({ chunk, score });
155
+ results.sort((a, b) => b.score - a.score);
156
+ } else if (score > results[topK - 1].score) {
157
+ results[topK - 1] = { chunk, score };
158
+ results.sort((a, b) => b.score - a.score);
159
+ }
160
+ }
161
+ return results;
162
+ }
163
+ async function loadIndex(url) {
164
+ const res = await fetch(url);
165
+ if (!res.ok) {
166
+ throw new Error(`Failed to fetch index (HTTP ${res.status}): ${url}`);
167
+ }
168
+ const data = await res.json();
169
+ const chunks = Array.isArray(data) ? data : data.chunks;
170
+ for (const chunk of chunks) {
171
+ chunk.textLower = chunk.text.toLowerCase();
172
+ if (Array.isArray(chunk.vector384)) {
173
+ chunk.vector384 = new Float32Array(chunk.vector384);
174
+ }
175
+ if (Array.isArray(chunk.vector768)) {
176
+ chunk.vector768 = new Float32Array(chunk.vector768);
177
+ }
178
+ }
179
+ return chunks;
180
+ }
181
+
182
+ // src/core/retriever.ts
183
+ async function fetchIndex(url) {
184
+ try {
185
+ return await loadIndex(url);
186
+ } catch (err) {
187
+ throw new Error(`Could not load knowledge index: ${String(err)}`);
188
+ }
189
+ }
190
+ async function retrieve(text, index, embedder, config) {
191
+ const topK = config?.topK ?? 3;
192
+ const minScore = config?.minScore ?? 0.42;
193
+ if (embedder.isReady) {
194
+ try {
195
+ const vector = await embedder.embed(text);
196
+ const results2 = search(vector, index, topK, minScore);
197
+ return { results: results2, mode: "vector" };
198
+ } catch {
199
+ }
200
+ }
201
+ const results = keywordSearch(text, index, topK);
202
+ return { results, mode: "keyword" };
203
+ }
204
+
205
+ // src/core/renderer.ts
206
+ function buildAnswer(results) {
207
+ if (results.length === 0) return "";
208
+ const seen = /* @__PURE__ */ new Set();
209
+ const parts = [];
210
+ for (const r of results) {
211
+ if (!seen.has(r.chunk.sourceId)) {
212
+ seen.add(r.chunk.sourceId);
213
+ parts.push(r.chunk.text);
214
+ }
215
+ }
216
+ return parts.join("\n\n");
217
+ }
218
+ function extractChips(index, override) {
219
+ if (override && override.length > 0) return override.slice(0, 5);
220
+ const chips = [];
221
+ const seenText = /* @__PURE__ */ new Set();
222
+ const seenSource = /* @__PURE__ */ new Set();
223
+ for (const chunk of index) {
224
+ if (chips.length >= 5) break;
225
+ if (chunk.sourceId) {
226
+ if (seenSource.has(chunk.sourceId)) continue;
227
+ seenSource.add(chunk.sourceId);
228
+ }
229
+ const candidate = chunk.question ?? extractFirstSentence(chunk.text);
230
+ if (candidate && !seenText.has(candidate)) {
231
+ seenText.add(candidate);
232
+ chips.push(candidate);
233
+ }
234
+ }
235
+ return chips;
236
+ }
237
+ function extractFirstSentence(text) {
238
+ const match = text.match(/^[^\n.!?]{10,80}[.!?\n]?/);
239
+ if (!match) return text.slice(0, 60);
240
+ return match[0].trim();
241
+ }
242
+
243
+ // src/core/fallback.ts
244
+ var DEFAULT_POOL = [
245
+ "That one's a bit outside what I have notes on right now. Feel free to reach out directly and I'll make sure you get a proper answer.",
246
+ "Hmm, I don't have a great answer for that one yet. You're welcome to get in touch and a real person will help.",
247
+ "I want to give you the right answer, not a guess. If you reach out through the contact page someone will follow up with you."
248
+ ];
249
+ var rotationIndex = 0;
250
+ function getFallback(config) {
251
+ const pool = config.fallbackPool && config.fallbackPool.length > 0 ? config.fallbackPool : config.fallback ? [config.fallback] : DEFAULT_POOL;
252
+ const message = pool[rotationIndex % pool.length];
253
+ rotationIndex = (rotationIndex + 1) % pool.length;
254
+ if (config.contactUrl) {
255
+ return `${message} You can reach us at: ${config.contactUrl}`;
256
+ }
257
+ return message;
258
+ }
259
+
260
+ // src/react/useSageDesk.ts
261
+ var initialState = {
262
+ messages: [],
263
+ isOpen: false,
264
+ isTyping: false,
265
+ engineStatus: "idle",
266
+ engineError: null,
267
+ hasSentMessage: false
268
+ };
269
+ function reducer(state, action) {
270
+ switch (action.type) {
271
+ case "OPEN":
272
+ return { ...state, isOpen: true };
273
+ case "CLOSE":
274
+ return { ...state, isOpen: false };
275
+ case "ADD_MESSAGE":
276
+ return { ...state, messages: [...state.messages, action.payload] };
277
+ case "SET_TYPING":
278
+ return { ...state, isTyping: action.payload };
279
+ case "SET_ENGINE_STATUS":
280
+ return {
281
+ ...state,
282
+ engineStatus: action.payload.status,
283
+ engineError: action.payload.error ?? null
284
+ };
285
+ case "MARK_SENT":
286
+ return { ...state, hasSentMessage: true };
287
+ default:
288
+ return state;
289
+ }
290
+ }
291
+ function useSageDesk(config) {
292
+ const [state, dispatch] = (0, import_react.useReducer)(reducer, initialState);
293
+ const engineStatusRef = (0, import_react.useRef)("idle");
294
+ engineStatusRef.current = state.engineStatus;
295
+ const indexRef = (0, import_react.useRef)(null);
296
+ const embedderRef = (0, import_react.useRef)(null);
297
+ const engineStartedRef = (0, import_react.useRef)(false);
298
+ const msgCounterRef = (0, import_react.useRef)(0);
299
+ const [chips, setChips] = (0, import_react.useState)([]);
300
+ const makeId = () => `msg-${++msgCounterRef.current}`;
301
+ const addMessage = (0, import_react.useCallback)(
302
+ (msg) => {
303
+ dispatch({
304
+ type: "ADD_MESSAGE",
305
+ payload: { ...msg, id: makeId(), timestamp: /* @__PURE__ */ new Date() }
306
+ });
307
+ },
308
+ []
309
+ );
310
+ const startEngine = (0, import_react.useCallback)(async () => {
311
+ if (engineStartedRef.current) return;
312
+ engineStartedRef.current = true;
313
+ dispatch({ type: "SET_ENGINE_STATUS", payload: { status: "loading-index" } });
314
+ try {
315
+ indexRef.current = await fetchIndex(config.indexUrl);
316
+ } catch (err) {
317
+ console.warn("[sagedesk] Failed to load knowledge index from", config.indexUrl, "-", err);
318
+ dispatch({
319
+ type: "SET_ENGINE_STATUS",
320
+ payload: { status: "error-index", error: String(err) }
321
+ });
322
+ addMessage({
323
+ role: "bot",
324
+ text: "I'm having trouble loading right now. Please try again in a moment."
325
+ });
326
+ return;
327
+ }
328
+ setChips(extractChips(indexRef.current, config.agent.suggestedChips));
329
+ dispatch({ type: "SET_ENGINE_STATUS", payload: { status: "loading-model" } });
330
+ try {
331
+ embedderRef.current = new EmbedderRuntime();
332
+ await embedderRef.current.load(config.agent.model);
333
+ dispatch({ type: "SET_ENGINE_STATUS", payload: { status: "ready" } });
334
+ } catch (err) {
335
+ console.warn("[sagedesk] WASM model failed to load, falling back to keyword search -", err);
336
+ embedderRef.current = new EmbedderRuntime();
337
+ dispatch({ type: "SET_ENGINE_STATUS", payload: { status: "degraded" } });
338
+ }
339
+ }, [config.indexUrl, config.agent.suggestedChips, addMessage]);
340
+ const greetingShownRef = (0, import_react.useRef)(false);
341
+ const open = (0, import_react.useCallback)(() => {
342
+ dispatch({ type: "OPEN" });
343
+ if (!greetingShownRef.current) {
344
+ greetingShownRef.current = true;
345
+ addMessage({
346
+ role: "bot",
347
+ text: config.agent.greeting ?? "Hey, how can I help you today?"
348
+ });
349
+ }
350
+ startEngine();
351
+ }, [config.agent.greeting, addMessage, startEngine]);
352
+ const close = (0, import_react.useCallback)(() => {
353
+ dispatch({ type: "CLOSE" });
354
+ }, []);
355
+ const waitForEngine = (0, import_react.useCallback)(() => {
356
+ return new Promise((resolve) => {
357
+ const check = () => {
358
+ const s = engineStatusRef.current;
359
+ if (s === "ready" || s === "degraded" || s === "error-index" || s === "error-model") {
360
+ resolve();
361
+ } else {
362
+ setTimeout(check, 100);
363
+ }
364
+ };
365
+ check();
366
+ });
367
+ }, []);
368
+ const submit = (0, import_react.useCallback)(
369
+ async (text) => {
370
+ const trimmed = text.trim();
371
+ if (!trimmed) return;
372
+ const typingStart = Date.now();
373
+ dispatch({ type: "MARK_SENT" });
374
+ addMessage({ role: "user", text: trimmed });
375
+ dispatch({ type: "SET_TYPING", payload: true });
376
+ const currentStatus = engineStatusRef.current;
377
+ if (currentStatus !== "ready" && currentStatus !== "degraded" && currentStatus !== "error-index" && currentStatus !== "error-model") {
378
+ await waitForEngine();
379
+ }
380
+ let botText;
381
+ let isFallback = false;
382
+ let mode = "keyword";
383
+ if (!indexRef.current) {
384
+ botText = getFallback(config.agent);
385
+ isFallback = true;
386
+ } else {
387
+ try {
388
+ const res = await retrieve(
389
+ trimmed,
390
+ indexRef.current,
391
+ embedderRef.current,
392
+ config.search
393
+ );
394
+ mode = res.mode;
395
+ if (res.results.length > 0) {
396
+ botText = buildAnswer(res.results);
397
+ } else {
398
+ botText = getFallback(config.agent);
399
+ isFallback = true;
400
+ }
401
+ } catch (err) {
402
+ console.warn("[sagedesk] Query failed, showing fallback -", err);
403
+ botText = getFallback(config.agent);
404
+ isFallback = true;
405
+ }
406
+ }
407
+ const elapsed = Date.now() - typingStart;
408
+ const delayBase = mode === "keyword" || isFallback ? 800 : 3e3;
409
+ const minTypingMs = delayBase + Math.random() * 2e3;
410
+ const remaining = minTypingMs - elapsed;
411
+ if (remaining > 0) await new Promise((r) => setTimeout(r, remaining));
412
+ dispatch({ type: "SET_TYPING", payload: false });
413
+ addMessage({ role: "bot", text: botText, isFallback });
414
+ },
415
+ [addMessage, waitForEngine, config.agent, config.search]
416
+ );
417
+ (0, import_react.useEffect)(() => {
418
+ if (!state.isOpen) return;
419
+ const handler = (e) => {
420
+ if (e.key === "Escape") close();
421
+ };
422
+ document.addEventListener("keydown", handler);
423
+ return () => document.removeEventListener("keydown", handler);
424
+ }, [state.isOpen, close]);
425
+ const activeChips = (0, import_react.useMemo)(() => {
426
+ const askedTexts = new Set(
427
+ state.messages.filter((m) => m.role === "user").map((m) => m.text.toLowerCase().trim())
428
+ );
429
+ return chips.filter((chip) => !askedTexts.has(chip.toLowerCase().trim()));
430
+ }, [chips, state.messages]);
431
+ return { state, chips: activeChips, open, close, submit };
432
+ }
433
+
434
+ // src/react/SageDeskWidget.tsx
435
+ var import_jsx_runtime = require("react/jsx-runtime");
436
+ var STYLE_ID = "sagedesk-widget-styles";
437
+ var SHARED = `
438
+ @keyframes sd-bounce {
439
+ 0%, 60%, 100% { transform: translateY(0); }
440
+ 30% { transform: translateY(-5px); }
441
+ }
442
+ @keyframes sd-panel-open {
443
+ from { transform: scale(0.94) translateY(6px); opacity: 0; }
444
+ to { transform: scale(1) translateY(0); opacity: 1; }
445
+ }
446
+ @keyframes sd-panel-close {
447
+ from { transform: scale(1) translateY(0); opacity: 1; }
448
+ to { transform: scale(0.94) translateY(6px); opacity: 0; }
449
+ }
450
+ .sd-r-opening { animation: sd-panel-open 200ms cubic-bezier(0.34,1.56,0.64,1) both; }
451
+ .sd-r-closing { animation: sd-panel-close 150ms ease-in both; }
452
+ .sd-r-dot-1 { animation: sd-bounce 1.2s ease-in-out infinite; }
453
+ .sd-r-dot-2 { animation: sd-bounce 1.2s ease-in-out 0.2s infinite; }
454
+ .sd-r-dot-3 { animation: sd-bounce 1.2s ease-in-out 0.4s infinite; }
455
+ .sd-r-scrollable {
456
+ flex-wrap: nowrap !important;
457
+ overflow-x: auto !important;
458
+ scrollbar-width: none !important;
459
+ -ms-overflow-style: none !important;
460
+ }
461
+ .sd-r-scrollable::-webkit-scrollbar { display: none !important; }
462
+ .sd-r-scrollable > * { flex-shrink: 0 !important; }
463
+ @media (max-width: 420px) {
464
+ .sd-r-panel {
465
+ bottom: 0 !important; right: 0 !important; left: 0 !important;
466
+ width: auto !important; max-width: 100% !important;
467
+ border-radius: 20px 20px 0 0 !important;
468
+ max-height: 85vh !important;
469
+ transform-origin: bottom center !important;
470
+ }
471
+ }
472
+ `;
473
+ var THEME_CSS = {
474
+ classic: `${SHARED}
475
+ .sd-r-trigger:hover { transform: scale(1.06) !important; }
476
+ .sd-r-close-btn:hover { background: rgba(255,255,255,0.22) !important; }
477
+ .sd-r-chip:hover { opacity: 0.8; }
478
+ .sd-r-send:hover { opacity: 0.85; }
479
+ .sd-r-send:active { transform: scale(0.95); }
480
+ .sd-r-input:focus { outline: none; }
481
+ .sd-r-input::placeholder { color: #a8a8b0; }
482
+ `,
483
+ light: `${SHARED}
484
+ .sd-r-trigger-light:hover { box-shadow: 0 16px 32px -10px rgba(40,30,90,0.24),0 2px 10px rgba(40,30,90,0.08) !important; }
485
+ .sd-r-chip-light:hover { opacity: 0.75; }
486
+ .sd-r-send:hover { opacity: 0.85; }
487
+ .sd-r-send:active { transform: scale(0.95); }
488
+ .sd-r-input:focus { outline: none; }
489
+ .sd-r-input::placeholder { color: #a8a89e; }
490
+ `,
491
+ dark: `${SHARED}
492
+ @keyframes sd-blink { 0%,100%{opacity:1} 50%{opacity:0} }
493
+ .sd-r-cursor { animation: sd-blink 1s infinite; }
494
+ .sd-r-trigger:hover { transform: scale(1.04) !important; }
495
+ .sd-r-prompt:hover { background: rgba(255,255,255,0.07) !important; }
496
+ .sd-r-send:hover { opacity: 0.85; }
497
+ .sd-r-send:active { transform: scale(0.95); }
498
+ .sd-r-input:focus { outline: none; }
499
+ .sd-r-input::placeholder { color: rgba(255,255,255,0.35); }
500
+ `
501
+ };
502
+ function injectStyles(theme) {
503
+ if (typeof document === "undefined") return;
504
+ const id = `${STYLE_ID}-${theme}`;
505
+ if (document.getElementById(id)) return;
506
+ const style = document.createElement("style");
507
+ style.id = id;
508
+ style.textContent = THEME_CSS[theme];
509
+ document.head.prepend(style);
510
+ }
511
+ var IconChat = ({ size = 22 }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
512
+ "path",
513
+ {
514
+ d: "M5 6.5A2.5 2.5 0 017.5 4h9A2.5 2.5 0 0119 6.5v7A2.5 2.5 0 0116.5 16H11l-4 3.5V16H7.5A2.5 2.5 0 015 13.5v-7z",
515
+ stroke: "currentColor",
516
+ strokeWidth: "1.6",
517
+ strokeLinejoin: "round"
518
+ }
519
+ ) });
520
+ var IconSend = ({ size = 14 }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M4 12L20 4l-4 16-4-7-8-1z", stroke: "currentColor", strokeWidth: "1.6", strokeLinejoin: "round" }) });
521
+ var IconClose = ({ size = 14 }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 6l12 12M18 6L6 18", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" }) });
522
+ var IconBot = ({ size = 22 }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: [
523
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "4", y: "8", width: "16", height: "12", rx: "3", stroke: "currentColor", strokeWidth: "1.6" }),
524
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "9", cy: "13.5", r: "1.5", fill: "currentColor" }),
525
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "15", cy: "13.5", r: "1.5", fill: "currentColor" }),
526
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M9.5 16.5h5", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" }),
527
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 8V5", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" }),
528
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "4", r: "1.2", fill: "currentColor" })
529
+ ] });
530
+ var IconPerson = ({ size = 18 }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [
531
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 12.5a4 4 0 100-8 4 4 0 000 8z" }),
532
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M5 20.5c0-3.5 3.13-6 7-6s7 2.5 7 6" })
533
+ ] });
534
+ var PoweredBy = ({ dark = false }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
535
+ fontSize: "11px",
536
+ color: dark ? "rgba(255,255,255,0.35)" : "#a8a8b0",
537
+ display: "flex",
538
+ alignItems: "center",
539
+ justifyContent: "center",
540
+ gap: "4px"
541
+ }, children: [
542
+ "Powered by",
543
+ " ",
544
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
545
+ "a",
546
+ {
547
+ href: "https://github.com/mzeeshanwahid/sagedesk",
548
+ target: "_blank",
549
+ rel: "noopener noreferrer",
550
+ style: {
551
+ color: dark ? "rgba(255,255,255,0.7)" : "#5a5a64",
552
+ fontWeight: 500,
553
+ textDecoration: "none"
554
+ },
555
+ children: "sagedesk"
556
+ }
557
+ )
558
+ ] });
559
+ function ClassicMessageBubble({ msg, accent }) {
560
+ const isBot = msg.role === "bot";
561
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", flexDirection: "column", alignItems: isBot ? "flex-start" : "flex-end", gap: "4px" }, children: [
562
+ msg.isFallback && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: { fontSize: "11px", fontWeight: 500, color: "#9b9aa3", margin: 0, padding: "0 4px", fontFamily: "inherit" }, children: "Not sure about that one" }),
563
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
564
+ maxWidth: "82%",
565
+ padding: "10px 14px",
566
+ fontSize: "14px",
567
+ lineHeight: 1.5,
568
+ borderRadius: isBot ? "16px 16px 16px 6px" : "16px 16px 6px 16px",
569
+ background: isBot ? "#fff" : accent,
570
+ color: isBot ? "#1a1a2e" : "#fff",
571
+ border: isBot ? "1px solid rgba(20,20,40,0.06)" : "none",
572
+ boxShadow: isBot ? "0 1px 2px rgba(20,20,40,0.04)" : `0 6px 16px -6px color-mix(in oklab, ${accent} 60%, transparent)`,
573
+ whiteSpace: "pre-wrap",
574
+ wordBreak: "break-word",
575
+ fontFamily: "inherit"
576
+ }, children: msg.text }),
577
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: {
578
+ fontSize: "11px",
579
+ color: "#a8a8b0",
580
+ marginTop: "2px",
581
+ padding: isBot ? "0 0 0 4px" : "0 4px 0 0",
582
+ fontVariantNumeric: "tabular-nums",
583
+ fontFamily: "inherit"
584
+ }, children: "just now" })
585
+ ] });
586
+ }
587
+ function ClassicTypingIndicator() {
588
+ const dot = { width: 6, height: 6, borderRadius: "50%", background: "#c8c8ce", display: "inline-block" };
589
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "flex", flexDirection: "column", alignItems: "flex-start", gap: "4px" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
590
+ padding: "10px 14px",
591
+ borderRadius: "16px 16px 16px 6px",
592
+ background: "#fff",
593
+ border: "1px solid rgba(20,20,40,0.06)",
594
+ boxShadow: "0 1px 2px rgba(20,20,40,0.04)",
595
+ display: "flex",
596
+ alignItems: "center",
597
+ gap: "4px"
598
+ }, children: [
599
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: dot, className: "sd-r-dot-1" }),
600
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: dot, className: "sd-r-dot-2" }),
601
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: dot, className: "sd-r-dot-3" })
602
+ ] }) });
603
+ }
604
+ function LightMessageBubble({ msg, accent, agentName }) {
605
+ const isBot = msg.role === "bot";
606
+ if (isBot) {
607
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", gap: "10px" }, children: [
608
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
609
+ width: 28,
610
+ height: 28,
611
+ borderRadius: "50%",
612
+ background: `linear-gradient(135deg, ${accent}, color-mix(in oklab, ${accent} 60%, #fff))`,
613
+ flexShrink: 0,
614
+ marginTop: "2px"
615
+ } }),
616
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { flex: 1, minWidth: 0 }, children: [
617
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "baseline", gap: "8px", marginBottom: "4px" }, children: [
618
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: "13px", fontWeight: 600, color: "#1a1a2e", fontFamily: "inherit" }, children: agentName }),
619
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: "11px", color: "#a8a89e", fontVariantNumeric: "tabular-nums", fontFamily: "inherit" }, children: "just now" })
620
+ ] }),
621
+ msg.isFallback && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: { fontSize: "11px", color: "#9b9aa3", margin: "0 0 4px", fontFamily: "inherit" }, children: "Not sure about that one" }),
622
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontSize: "14px", lineHeight: 1.55, color: "#2a2a36", fontFamily: "inherit", whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: msg.text })
623
+ ] })
624
+ ] });
625
+ }
626
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "flex", justifyContent: "flex-end" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
627
+ maxWidth: "78%",
628
+ padding: "11px 15px",
629
+ fontSize: "14px",
630
+ lineHeight: 1.5,
631
+ borderRadius: "16px 16px 4px 16px",
632
+ background: `color-mix(in oklab, ${accent} 10%, white)`,
633
+ color: accent,
634
+ border: `1px solid color-mix(in oklab, ${accent} 22%, transparent)`,
635
+ fontWeight: 500,
636
+ whiteSpace: "pre-wrap",
637
+ wordBreak: "break-word",
638
+ fontFamily: "inherit"
639
+ }, children: msg.text }) });
640
+ }
641
+ function LightTypingIndicator({ accent }) {
642
+ const dot = { width: 6, height: 6, borderRadius: "50%", background: "#c4c4be", display: "inline-block" };
643
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", gap: "10px" }, children: [
644
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
645
+ width: 28,
646
+ height: 28,
647
+ borderRadius: "50%",
648
+ background: `linear-gradient(135deg, ${accent}, color-mix(in oklab, ${accent} 60%, #fff))`,
649
+ flexShrink: 0,
650
+ marginTop: "2px"
651
+ } }),
652
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
653
+ padding: "10px 14px",
654
+ borderRadius: "16px 16px 16px 4px",
655
+ background: "#fff",
656
+ border: "1px solid rgba(20,20,40,0.07)",
657
+ boxShadow: "0 1px 2px rgba(20,20,40,0.04)",
658
+ display: "inline-flex",
659
+ alignItems: "center",
660
+ gap: "4px"
661
+ }, children: [
662
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: dot, className: "sd-r-dot-1" }),
663
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: dot, className: "sd-r-dot-2" }),
664
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: dot, className: "sd-r-dot-3" })
665
+ ] })
666
+ ] });
667
+ }
668
+ function DarkMessageBubble({ msg, accent }) {
669
+ const isBot = msg.role === "bot";
670
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
671
+ maxWidth: "85%",
672
+ padding: "12px 14px",
673
+ fontSize: "14px",
674
+ lineHeight: isBot ? 1.6 : 1.5,
675
+ borderRadius: isBot ? "14px 14px 14px 6px" : "14px 14px 6px 14px",
676
+ background: isBot ? "rgba(255,255,255,0.05)" : `linear-gradient(135deg, ${accent}, color-mix(in oklab, ${accent} 75%, #1a1340))`,
677
+ border: isBot ? "1px solid rgba(255,255,255,0.06)" : "none",
678
+ color: isBot ? "rgba(255,255,255,0.92)" : "#fff",
679
+ alignSelf: isBot ? "flex-start" : "flex-end",
680
+ boxShadow: isBot ? "none" : `0 8px 20px -8px color-mix(in oklab, ${accent} 70%, transparent)`,
681
+ whiteSpace: "pre-wrap",
682
+ wordBreak: "break-word",
683
+ fontFamily: "inherit"
684
+ }, children: [
685
+ msg.isFallback && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: "11px", color: "rgba(255,255,255,0.5)", display: "block", marginBottom: "4px" }, children: "Not sure about that one" }),
686
+ msg.text
687
+ ] });
688
+ }
689
+ function DarkTypingIndicator() {
690
+ const dot = { width: 6, height: 6, borderRadius: "50%", background: "rgba(255,255,255,0.4)", display: "inline-block" };
691
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
692
+ maxWidth: "85%",
693
+ padding: "12px 14px",
694
+ borderRadius: "14px 14px 14px 6px",
695
+ background: "rgba(255,255,255,0.05)",
696
+ border: "1px solid rgba(255,255,255,0.06)",
697
+ alignSelf: "flex-start",
698
+ display: "flex",
699
+ alignItems: "center",
700
+ gap: "4px"
701
+ }, children: [
702
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: dot, className: "sd-r-dot-1" }),
703
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: dot, className: "sd-r-dot-2" }),
704
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: dot, className: "sd-r-dot-3" })
705
+ ] });
706
+ }
707
+ function renderClassic(p) {
708
+ const {
709
+ agent,
710
+ state,
711
+ chips,
712
+ accent,
713
+ isLeft,
714
+ inputValue,
715
+ setInputValue,
716
+ handleClose,
717
+ handleSubmit,
718
+ handleKeyDown,
719
+ isClosing,
720
+ panelClass,
721
+ showChips,
722
+ showPoweredBy,
723
+ threadRef,
724
+ inputRef,
725
+ triggerRef,
726
+ open,
727
+ submit
728
+ } = p;
729
+ const side = isLeft ? "left" : "right";
730
+ const triggerStyle = {
731
+ position: "fixed",
732
+ bottom: "28px",
733
+ [side]: "28px",
734
+ width: "56px",
735
+ height: "56px",
736
+ borderRadius: "50%",
737
+ background: `linear-gradient(135deg, ${accent} 0%, color-mix(in oklab, ${accent} 78%, #1a1340) 100%)`,
738
+ border: "none",
739
+ color: "#fff",
740
+ cursor: "pointer",
741
+ display: "grid",
742
+ placeItems: "center",
743
+ zIndex: 9999,
744
+ padding: 0,
745
+ transition: "transform 150ms ease",
746
+ boxShadow: `0 14px 28px -6px color-mix(in oklab, ${accent} 55%, transparent), 0 4px 10px rgba(40,30,90,0.15)`
747
+ };
748
+ const panelStyle = {
749
+ position: "fixed",
750
+ bottom: "96px",
751
+ [side]: "28px",
752
+ width: "380px",
753
+ height: "580px",
754
+ maxHeight: "580px",
755
+ borderRadius: "20px",
756
+ background: "#ffffff",
757
+ boxShadow: "0 1px 0 rgba(20,20,40,0.04), 0 24px 48px -16px rgba(40,30,90,0.22), 0 4px 14px rgba(40,30,90,0.08)",
758
+ border: "1px solid rgba(20,20,40,0.04)",
759
+ display: "flex",
760
+ flexDirection: "column",
761
+ overflow: "hidden",
762
+ zIndex: 9999,
763
+ transformOrigin: isLeft ? "bottom left" : "bottom right"
764
+ };
765
+ const headerGrad = `linear-gradient(135deg, ${accent} 0%, color-mix(in oklab, ${accent} 78%, #1a1340) 100%)`;
766
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
767
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
768
+ "button",
769
+ {
770
+ ref: triggerRef,
771
+ style: triggerStyle,
772
+ className: "sd-r-trigger",
773
+ onClick: state.isOpen ? handleClose : open,
774
+ "aria-label": "Open support chat",
775
+ "aria-expanded": state.isOpen,
776
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconChat, { size: 22 })
777
+ }
778
+ ),
779
+ (state.isOpen || isClosing) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: panelStyle, className: `sd-r-panel ${panelClass}`, role: "dialog", "aria-label": agent.name, children: [
780
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { padding: "18px 20px", background: headerGrad, color: "#fff", display: "flex", alignItems: "center", gap: "12px", flexShrink: 0 }, children: [
781
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { position: "relative", width: 40, height: 40 }, children: [
782
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { width: 40, height: 40, borderRadius: "50%", background: "rgba(255,255,255,0.18)", display: "grid", placeItems: "center", overflow: "hidden" }, children: agent.avatarUrl ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: agent.avatarUrl, alt: agent.name, style: { width: "100%", height: "100%", objectFit: "cover" } }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconPerson, { size: 20 }) }),
783
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { position: "absolute", right: -1, bottom: -1, width: 12, height: 12, borderRadius: "50%", background: "#22c55e", boxShadow: `0 0 0 2.5px ${accent}` } })
784
+ ] }),
785
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { flex: 1, minWidth: 0 }, children: [
786
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontSize: "15px", fontWeight: 600, letterSpacing: "-0.01em" }, children: agent.name }),
787
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { fontSize: "12px", opacity: 0.85, display: "flex", alignItems: "center", gap: "6px", marginTop: "3px" }, children: [
788
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { width: 6, height: 6, borderRadius: "50%", background: "#4ade80", boxShadow: "0 0 0 2px rgba(74,222,128,0.25)" } }),
789
+ "Typically replies in under a minute"
790
+ ] })
791
+ ] }),
792
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "sd-r-close-btn", onClick: handleClose, "aria-label": "Close chat", style: {
793
+ background: "rgba(255,255,255,0.14)",
794
+ border: "none",
795
+ color: "#fff",
796
+ width: 30,
797
+ height: 30,
798
+ borderRadius: 8,
799
+ cursor: "pointer",
800
+ display: "grid",
801
+ placeItems: "center",
802
+ padding: 0,
803
+ transition: "background 120ms"
804
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconClose, { size: 14 }) })
805
+ ] }),
806
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ref: threadRef, role: "log", "aria-live": "polite", "aria-label": "Chat messages", style: {
807
+ flex: 1,
808
+ padding: "22px 18px 18px",
809
+ overflowY: "auto",
810
+ background: "#fbfbfa",
811
+ display: "flex",
812
+ flexDirection: "column",
813
+ gap: "18px",
814
+ scrollbarWidth: "thin",
815
+ overscrollBehavior: "contain"
816
+ }, children: [
817
+ state.messages.map((msg) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ClassicMessageBubble, { msg, accent }, msg.id)),
818
+ state.isTyping && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ClassicTypingIndicator, {})
819
+ ] }),
820
+ showChips && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { padding: state.hasSentMessage ? "0 0 16px" : "0 18px 16px", background: "#fbfbfa", flexShrink: 0 }, children: [
821
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
822
+ fontSize: "11px",
823
+ color: "#9b9aa3",
824
+ letterSpacing: "0.06em",
825
+ textTransform: "uppercase",
826
+ fontWeight: 500,
827
+ paddingLeft: state.hasSentMessage ? 18 : 4,
828
+ marginBottom: "6px"
829
+ }, children: "Suggested" }),
830
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: state.hasSentMessage ? "sd-r-scrollable" : "", style: {
831
+ display: "flex",
832
+ gap: "6px",
833
+ flexWrap: state.hasSentMessage ? "nowrap" : "wrap",
834
+ padding: state.hasSentMessage ? "0 18px" : 0
835
+ }, children: chips.map((chip) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "sd-r-chip", onClick: () => {
836
+ setInputValue("");
837
+ submit(chip);
838
+ }, style: {
839
+ fontSize: "12.5px",
840
+ padding: "7px 12px",
841
+ borderRadius: "999px",
842
+ background: "#fff",
843
+ border: `1px solid color-mix(in oklab, ${accent} 24%, transparent)`,
844
+ color: accent,
845
+ cursor: "pointer",
846
+ fontWeight: 500,
847
+ fontFamily: "inherit",
848
+ letterSpacing: "-0.005em"
849
+ }, children: chip }, chip)) })
850
+ ] }),
851
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { padding: "14px 14px 16px", borderTop: "1px solid rgba(20,20,40,0.06)", background: "#fff", flexShrink: 0 }, children: [
852
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
853
+ display: "flex",
854
+ alignItems: "center",
855
+ gap: "6px",
856
+ background: "#f5f4f0",
857
+ borderRadius: "12px",
858
+ padding: "5px 6px 5px 14px",
859
+ border: `1px solid ${inputValue ? `color-mix(in oklab, ${accent} 30%, transparent)` : "transparent"}`,
860
+ boxShadow: inputValue ? `0 0 0 4px color-mix(in oklab, ${accent} 12%, transparent)` : "none",
861
+ transition: "border-color .15s, box-shadow .15s"
862
+ }, children: [
863
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
864
+ "input",
865
+ {
866
+ ref: inputRef,
867
+ value: inputValue,
868
+ onChange: (e) => setInputValue(e.target.value),
869
+ onKeyDown: handleKeyDown,
870
+ placeholder: "Write a message\u2026",
871
+ className: "sd-r-input",
872
+ "aria-label": "Type your question",
873
+ autoComplete: "off",
874
+ style: { flex: 1, background: "transparent", border: "none", outline: "none", fontSize: "14px", padding: "8px 0", fontFamily: "inherit", color: "#1a1a2e" }
875
+ }
876
+ ),
877
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "sd-r-send", onClick: handleSubmit, "aria-label": "Send message", style: {
878
+ width: 32,
879
+ height: 32,
880
+ borderRadius: 8,
881
+ padding: 0,
882
+ background: inputValue ? accent : `color-mix(in oklab, ${accent} 22%, #e5e3dc)`,
883
+ border: "none",
884
+ color: "#fff",
885
+ cursor: "pointer",
886
+ display: "grid",
887
+ placeItems: "center",
888
+ transition: "background .15s"
889
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconSend, { size: 14 }) })
890
+ ] }),
891
+ showPoweredBy && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { marginTop: "10px" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PoweredBy, {}) })
892
+ ] })
893
+ ] })
894
+ ] });
895
+ }
896
+ function renderLight(p) {
897
+ const {
898
+ agent,
899
+ state,
900
+ chips,
901
+ accent,
902
+ isLeft,
903
+ inputValue,
904
+ setInputValue,
905
+ handleClose,
906
+ handleSubmit,
907
+ handleKeyDown,
908
+ isClosing,
909
+ panelClass,
910
+ showChips,
911
+ showPoweredBy,
912
+ threadRef,
913
+ inputRef,
914
+ triggerRef,
915
+ open,
916
+ submit
917
+ } = p;
918
+ const side = isLeft ? "left" : "right";
919
+ const triggerStyle = {
920
+ position: "fixed",
921
+ bottom: "28px",
922
+ [side]: "28px",
923
+ height: "52px",
924
+ padding: "0 8px 0 20px",
925
+ borderRadius: "999px",
926
+ background: "#fdfcf9",
927
+ border: "1px solid rgba(20,20,40,0.08)",
928
+ cursor: "pointer",
929
+ display: "flex",
930
+ alignItems: "center",
931
+ gap: "14px",
932
+ boxShadow: "0 12px 26px -8px rgba(40,30,90,0.18), 0 2px 8px rgba(40,30,90,0.06)",
933
+ zIndex: 9999,
934
+ fontFamily: "inherit",
935
+ transition: "box-shadow 150ms ease"
936
+ };
937
+ const panelStyle = {
938
+ position: "fixed",
939
+ bottom: "92px",
940
+ [side]: "28px",
941
+ width: "400px",
942
+ height: "580px",
943
+ maxHeight: "580px",
944
+ borderRadius: "22px",
945
+ background: "#fdfcf9",
946
+ boxShadow: "0 1px 0 rgba(20,20,40,0.04), 0 30px 60px -20px rgba(40,30,90,0.18), 0 6px 16px rgba(40,30,90,0.06)",
947
+ border: "1px solid rgba(20,20,40,0.05)",
948
+ display: "flex",
949
+ flexDirection: "column",
950
+ overflow: "hidden",
951
+ zIndex: 9999,
952
+ transformOrigin: isLeft ? "bottom left" : "bottom right"
953
+ };
954
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
955
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
956
+ "button",
957
+ {
958
+ ref: triggerRef,
959
+ style: triggerStyle,
960
+ className: "sd-r-trigger-light",
961
+ onClick: state.isOpen ? handleClose : open,
962
+ "aria-label": "Open support chat",
963
+ "aria-expanded": state.isOpen,
964
+ children: [
965
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: { display: "flex", flexDirection: "column", alignItems: "flex-start", lineHeight: 1.2 }, children: [
966
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: "14px", fontWeight: 600, color: "#1a1a2e" }, children: "Chat with us" }),
967
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: "11px", color: "#9b9aa3", marginTop: "2px" }, children: "We typically reply in 1m" })
968
+ ] }),
969
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { width: "36px", height: "36px", borderRadius: "50%", background: accent, color: "#fff", display: "grid", placeItems: "center", flexShrink: 0 }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconChat, { size: 18 }) })
970
+ ]
971
+ }
972
+ ),
973
+ (state.isOpen || isClosing) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: panelStyle, className: `sd-r-panel ${panelClass}`, role: "dialog", "aria-label": agent.name, children: [
974
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { padding: "18px 20px 14px", borderBottom: "1px solid rgba(20,20,40,0.05)", display: "flex", alignItems: "center", gap: "12px", background: "#fdfcf9", flexShrink: 0 }, children: [
975
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
976
+ width: 36,
977
+ height: 36,
978
+ borderRadius: "50%",
979
+ flexShrink: 0,
980
+ background: `linear-gradient(135deg, ${accent}, color-mix(in oklab, ${accent} 55%, #fff))`,
981
+ display: "grid",
982
+ placeItems: "center",
983
+ overflow: "hidden",
984
+ color: "#fff"
985
+ }, children: agent.avatarUrl ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: agent.avatarUrl, alt: agent.name, style: { width: "100%", height: "100%", objectFit: "cover" } }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconPerson, { size: 16 }) }),
986
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { flex: 1, minWidth: 0 }, children: [
987
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontSize: "14.5px", fontWeight: 600, color: "#1a1a2e", letterSpacing: "-0.01em" }, children: agent.name }),
988
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { fontSize: "12px", color: "#7a7a82", display: "flex", alignItems: "center", gap: "6px", marginTop: "2px" }, children: [
989
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { width: 6, height: 6, borderRadius: "50%", background: "#22c55e" } }),
990
+ "Online \xB7 replies in under a minute"
991
+ ] })
992
+ ] }),
993
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { onClick: handleClose, "aria-label": "Close chat", style: {
994
+ background: "transparent",
995
+ border: "none",
996
+ color: "#9b9aa3",
997
+ width: 30,
998
+ height: 30,
999
+ borderRadius: 8,
1000
+ cursor: "pointer",
1001
+ display: "grid",
1002
+ placeItems: "center",
1003
+ padding: 0
1004
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconClose, { size: 16 }) })
1005
+ ] }),
1006
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ref: threadRef, role: "log", "aria-live": "polite", "aria-label": "Chat messages", style: {
1007
+ flex: 1,
1008
+ padding: "22px 20px 16px",
1009
+ overflowY: "auto",
1010
+ display: "flex",
1011
+ flexDirection: "column",
1012
+ gap: "22px",
1013
+ scrollbarWidth: "thin",
1014
+ overscrollBehavior: "contain"
1015
+ }, children: [
1016
+ state.messages.map((msg) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LightMessageBubble, { msg, accent, agentName: agent.name }, msg.id)),
1017
+ state.isTyping && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LightTypingIndicator, { accent })
1018
+ ] }),
1019
+ showChips && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: state.hasSentMessage ? "sd-r-scrollable" : "", style: {
1020
+ padding: "0 20px 14px",
1021
+ display: "flex",
1022
+ flexWrap: state.hasSentMessage ? "nowrap" : "wrap",
1023
+ gap: "6px",
1024
+ flexShrink: 0
1025
+ }, children: chips.map((chip) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "sd-r-chip-light", onClick: () => {
1026
+ setInputValue("");
1027
+ submit(chip);
1028
+ }, style: {
1029
+ fontSize: "12px",
1030
+ padding: "5px 10px",
1031
+ borderRadius: "6px",
1032
+ background: "#f4f3ee",
1033
+ border: "none",
1034
+ color: "#5a5a64",
1035
+ cursor: "pointer",
1036
+ fontFamily: "inherit",
1037
+ fontWeight: 500
1038
+ }, children: chip }, chip)) }),
1039
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { padding: "14px", borderTop: "1px solid rgba(20,20,40,0.05)", background: "#fdfcf9", flexShrink: 0 }, children: [
1040
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
1041
+ background: "#fff",
1042
+ border: `1px solid ${inputValue ? `color-mix(in oklab, ${accent} 40%, transparent)` : "rgba(20,20,40,0.1)"}`,
1043
+ borderRadius: "14px",
1044
+ padding: "10px 12px",
1045
+ transition: "border-color .15s, box-shadow .15s",
1046
+ boxShadow: inputValue ? `0 0 0 4px color-mix(in oklab, ${accent} 12%, transparent)` : "none"
1047
+ }, children: [
1048
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1049
+ "input",
1050
+ {
1051
+ ref: inputRef,
1052
+ value: inputValue,
1053
+ onChange: (e) => setInputValue(e.target.value),
1054
+ onKeyDown: handleKeyDown,
1055
+ placeholder: "Write a message\u2026",
1056
+ className: "sd-r-input",
1057
+ "aria-label": "Type your question",
1058
+ autoComplete: "off",
1059
+ style: { width: "100%", background: "transparent", border: "none", outline: "none", fontSize: "14px", fontFamily: "inherit", color: "#1a1a2e" }
1060
+ }
1061
+ ),
1062
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", marginTop: "8px", gap: "6px" }, children: [
1063
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { flex: 1 } }),
1064
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "sd-r-send", onClick: handleSubmit, "aria-label": "Send message", style: {
1065
+ width: 28,
1066
+ height: 28,
1067
+ borderRadius: 7,
1068
+ padding: 0,
1069
+ background: inputValue ? accent : "#e8e7e0",
1070
+ color: inputValue ? "#fff" : "#a8a89e",
1071
+ border: "none",
1072
+ cursor: "pointer",
1073
+ display: "grid",
1074
+ placeItems: "center",
1075
+ transition: "background .15s"
1076
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconSend, { size: 13 }) })
1077
+ ] })
1078
+ ] }),
1079
+ showPoweredBy && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { marginTop: "10px" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PoweredBy, {}) })
1080
+ ] })
1081
+ ] })
1082
+ ] });
1083
+ }
1084
+ function renderDark(p) {
1085
+ const {
1086
+ agent,
1087
+ state,
1088
+ chips,
1089
+ accent,
1090
+ isLeft,
1091
+ inputValue,
1092
+ setInputValue,
1093
+ handleClose,
1094
+ handleSubmit,
1095
+ handleKeyDown,
1096
+ isClosing,
1097
+ panelClass,
1098
+ showChips,
1099
+ showPoweredBy,
1100
+ threadRef,
1101
+ inputRef,
1102
+ triggerRef,
1103
+ open,
1104
+ submit
1105
+ } = p;
1106
+ const side = isLeft ? "left" : "right";
1107
+ const triggerStyle = {
1108
+ position: "fixed",
1109
+ bottom: "28px",
1110
+ [side]: "28px",
1111
+ width: "60px",
1112
+ height: "60px",
1113
+ borderRadius: "50%",
1114
+ background: `linear-gradient(135deg, color-mix(in oklab, ${accent} 70%, #1a1340), #1a1a2e)`,
1115
+ border: "1px solid rgba(255,255,255,0.12)",
1116
+ color: "#fff",
1117
+ cursor: "pointer",
1118
+ display: "grid",
1119
+ placeItems: "center",
1120
+ zIndex: 9999,
1121
+ padding: 0,
1122
+ transition: "transform 150ms ease",
1123
+ boxShadow: "0 16px 32px -8px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.1)"
1124
+ };
1125
+ const glowStyle = {
1126
+ position: "fixed",
1127
+ bottom: "18px",
1128
+ [side]: "18px",
1129
+ width: "80px",
1130
+ height: "80px",
1131
+ borderRadius: "50%",
1132
+ background: `radial-gradient(circle, color-mix(in oklab, ${accent} 50%, transparent), transparent 70%)`,
1133
+ filter: "blur(10px)",
1134
+ pointerEvents: "none",
1135
+ zIndex: 9998
1136
+ };
1137
+ const panelStyle = {
1138
+ position: "fixed",
1139
+ bottom: "100px",
1140
+ [side]: "28px",
1141
+ width: "380px",
1142
+ height: "580px",
1143
+ maxHeight: "580px",
1144
+ borderRadius: "22px",
1145
+ background: "rgba(18, 16, 32, 0.86)",
1146
+ backdropFilter: "blur(40px) saturate(180%)",
1147
+ WebkitBackdropFilter: "blur(40px) saturate(180%)",
1148
+ boxShadow: "0 30px 60px -20px rgba(0,0,0,0.4), 0 4px 14px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.06)",
1149
+ border: "1px solid rgba(255,255,255,0.08)",
1150
+ display: "flex",
1151
+ flexDirection: "column",
1152
+ overflow: "hidden",
1153
+ zIndex: 9999,
1154
+ color: "#fff",
1155
+ transformOrigin: isLeft ? "bottom left" : "bottom right"
1156
+ };
1157
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1158
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: glowStyle, "aria-hidden": "true" }),
1159
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1160
+ "button",
1161
+ {
1162
+ ref: triggerRef,
1163
+ style: triggerStyle,
1164
+ className: "sd-r-trigger",
1165
+ onClick: state.isOpen ? handleClose : open,
1166
+ "aria-label": "Open support chat",
1167
+ "aria-expanded": state.isOpen,
1168
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconBot, { size: 22 })
1169
+ }
1170
+ ),
1171
+ (state.isOpen || isClosing) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: panelStyle, className: `sd-r-panel ${panelClass}`, role: "dialog", "aria-label": agent.name, children: [
1172
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { "aria-hidden": "true", style: {
1173
+ position: "absolute",
1174
+ top: 0,
1175
+ left: 0,
1176
+ right: 0,
1177
+ height: 200,
1178
+ pointerEvents: "none",
1179
+ background: `radial-gradient(ellipse 80% 100% at 50% 0%, color-mix(in oklab, ${accent} 40%, transparent) 0%, transparent 70%)`
1180
+ } }),
1181
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { padding: "20px 20px 16px", display: "flex", alignItems: "center", gap: "12px", position: "relative", zIndex: 1, flexShrink: 0 }, children: [
1182
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { position: "relative" }, children: [
1183
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
1184
+ width: 38,
1185
+ height: 38,
1186
+ borderRadius: "50%",
1187
+ display: "grid",
1188
+ placeItems: "center",
1189
+ overflow: "hidden",
1190
+ background: `linear-gradient(135deg, ${accent}, color-mix(in oklab, ${accent} 50%, #fff))`,
1191
+ boxShadow: `0 0 24px color-mix(in oklab, ${accent} 50%, transparent)`
1192
+ }, children: agent.avatarUrl ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: agent.avatarUrl, alt: agent.name, style: { width: "100%", height: "100%", objectFit: "cover" } }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconBot, { size: 16 }) }),
1193
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { position: "absolute", right: -2, bottom: -2, width: 12, height: 12, borderRadius: "50%", background: "#22c55e", boxShadow: "0 0 0 2.5px rgba(18,16,32,1)" } })
1194
+ ] }),
1195
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { flex: 1 }, children: [
1196
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontSize: "15px", fontWeight: 600, letterSpacing: "-0.01em" }, children: agent.name }),
1197
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { fontSize: "12px", color: "rgba(255,255,255,0.55)", marginTop: "3px", display: "flex", alignItems: "center", gap: "6px" }, children: [
1198
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { width: 5, height: 5, borderRadius: "50%", background: "#4ade80", boxShadow: "0 0 6px #4ade80" } }),
1199
+ "Trained on this site \xB7 always on"
1200
+ ] })
1201
+ ] }),
1202
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { onClick: handleClose, "aria-label": "Close chat", style: {
1203
+ background: "rgba(255,255,255,0.06)",
1204
+ border: "1px solid rgba(255,255,255,0.08)",
1205
+ color: "rgba(255,255,255,0.7)",
1206
+ width: 30,
1207
+ height: 30,
1208
+ borderRadius: 8,
1209
+ cursor: "pointer",
1210
+ display: "grid",
1211
+ placeItems: "center",
1212
+ padding: 0
1213
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconClose, { size: 14 }) })
1214
+ ] }),
1215
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ref: threadRef, role: "log", "aria-live": "polite", "aria-label": "Chat messages", style: {
1216
+ flex: 1,
1217
+ padding: "8px 20px 16px",
1218
+ overflowY: "auto",
1219
+ display: "flex",
1220
+ flexDirection: "column",
1221
+ gap: "14px",
1222
+ position: "relative",
1223
+ zIndex: 1,
1224
+ scrollbarWidth: "thin",
1225
+ overscrollBehavior: "contain"
1226
+ }, children: [
1227
+ state.messages.map((msg) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DarkMessageBubble, { msg, accent }, msg.id)),
1228
+ state.isTyping && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DarkTypingIndicator, {})
1229
+ ] }),
1230
+ showChips && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { padding: state.hasSentMessage ? "0 0 16px" : "0 20px 16px", position: "relative", zIndex: 1, flexShrink: 0 }, children: [
1231
+ !state.hasSentMessage && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { fontSize: "11px", color: "rgba(255,255,255,0.4)", letterSpacing: "0.08em", textTransform: "uppercase", fontWeight: 500, marginBottom: "8px" }, children: "Try asking" }),
1232
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: state.hasSentMessage ? "sd-r-scrollable" : "", style: {
1233
+ display: "flex",
1234
+ flexDirection: state.hasSentMessage ? "row" : "column",
1235
+ gap: "6px",
1236
+ padding: state.hasSentMessage ? "0 20px" : 0
1237
+ }, children: chips.map((chip) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", { className: "sd-r-prompt", onClick: () => {
1238
+ setInputValue("");
1239
+ submit(chip);
1240
+ }, style: {
1241
+ textAlign: "left",
1242
+ padding: "10px 14px",
1243
+ borderRadius: "10px",
1244
+ background: "rgba(255,255,255,0.04)",
1245
+ border: "1px solid rgba(255,255,255,0.07)",
1246
+ color: "rgba(255,255,255,0.85)",
1247
+ cursor: "pointer",
1248
+ fontSize: "13px",
1249
+ fontFamily: "inherit",
1250
+ display: "flex",
1251
+ alignItems: "center",
1252
+ gap: "8px",
1253
+ transition: "background .12s",
1254
+ width: state.hasSentMessage ? "auto" : "100%",
1255
+ whiteSpace: state.hasSentMessage ? "nowrap" : "normal"
1256
+ }, children: [
1257
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M9 6l6 6-6 6", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round" }) }),
1258
+ chip
1259
+ ] }, chip)) })
1260
+ ] }),
1261
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { padding: "14px", borderTop: "1px solid rgba(255,255,255,0.06)", position: "relative", zIndex: 1, flexShrink: 0 }, children: [
1262
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
1263
+ display: "flex",
1264
+ alignItems: "center",
1265
+ gap: "8px",
1266
+ background: "rgba(255,255,255,0.05)",
1267
+ border: `1px solid ${inputValue ? `color-mix(in oklab, ${accent} 60%, transparent)` : "rgba(255,255,255,0.08)"}`,
1268
+ borderRadius: "12px",
1269
+ padding: "4px 4px 4px 14px",
1270
+ transition: "border-color .15s"
1271
+ }, children: [
1272
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1273
+ "input",
1274
+ {
1275
+ ref: inputRef,
1276
+ value: inputValue,
1277
+ onChange: (e) => setInputValue(e.target.value),
1278
+ onKeyDown: handleKeyDown,
1279
+ placeholder: "Write a message\u2026",
1280
+ className: "sd-r-input",
1281
+ "aria-label": "Type your question",
1282
+ autoComplete: "off",
1283
+ style: { flex: 1, background: "transparent", border: "none", outline: "none", fontSize: "14px", padding: "9px 0", fontFamily: "inherit", color: "#fff" }
1284
+ }
1285
+ ),
1286
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "sd-r-send", onClick: handleSubmit, "aria-label": "Send message", style: {
1287
+ width: 32,
1288
+ height: 32,
1289
+ borderRadius: 9,
1290
+ padding: 0,
1291
+ border: "none",
1292
+ cursor: "pointer",
1293
+ background: inputValue ? `linear-gradient(135deg, ${accent}, color-mix(in oklab, ${accent} 60%, #fff))` : "rgba(255,255,255,0.08)",
1294
+ color: inputValue ? "#fff" : "rgba(255,255,255,0.4)",
1295
+ display: "grid",
1296
+ placeItems: "center",
1297
+ transition: "background .15s",
1298
+ boxShadow: inputValue ? `0 4px 12px -2px color-mix(in oklab, ${accent} 60%, transparent)` : "none"
1299
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconSend, { size: 14 }) })
1300
+ ] }),
1301
+ showPoweredBy && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { marginTop: "10px" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PoweredBy, { dark: true }) })
1302
+ ] })
1303
+ ] })
1304
+ ] });
1305
+ }
1306
+ function SageDeskWidget({ indexUrl, agent, search: search2 }) {
1307
+ if (!indexUrl) {
1308
+ throw new Error(
1309
+ '[sagedesk] Required prop "indexUrl" is missing. Run `npx sagedesk build` and pass the output path, e.g. indexUrl="/support-index.json".'
1310
+ );
1311
+ }
1312
+ if (!agent?.name) {
1313
+ throw new Error('[sagedesk] Required prop "agent.name" is missing.');
1314
+ }
1315
+ const config = { indexUrl, agent, search: search2 };
1316
+ const { state, chips, open, close, submit } = useSageDesk(config);
1317
+ const theme = agent.theme ?? "classic";
1318
+ const accent = agent.accentColor ?? "#534AB7";
1319
+ const position = agent.position ?? "bottom-right";
1320
+ const isLeft = position === "bottom-left";
1321
+ const [inputValue, setInputValue] = (0, import_react2.useState)("");
1322
+ const [isClosing, setIsClosing] = (0, import_react2.useState)(false);
1323
+ const threadRef = (0, import_react2.useRef)(null);
1324
+ const inputRef = (0, import_react2.useRef)(null);
1325
+ const triggerRef = (0, import_react2.useRef)(null);
1326
+ const [mounted, setMounted] = (0, import_react2.useState)(false);
1327
+ (0, import_react2.useEffect)(() => {
1328
+ if (!indexUrl.startsWith("/") && !indexUrl.startsWith("http")) {
1329
+ console.warn(
1330
+ `[sagedesk] indexUrl "${indexUrl}" looks like a relative path. It should start with "/" so it resolves correctly from any page.`
1331
+ );
1332
+ }
1333
+ setMounted(true);
1334
+ injectStyles(theme);
1335
+ }, []);
1336
+ (0, import_react2.useEffect)(() => {
1337
+ if (threadRef.current) {
1338
+ threadRef.current.scrollTop = threadRef.current.scrollHeight;
1339
+ }
1340
+ }, [state.messages, state.isTyping]);
1341
+ (0, import_react2.useEffect)(() => {
1342
+ if (state.isOpen) {
1343
+ setTimeout(() => inputRef.current?.focus(), 50);
1344
+ }
1345
+ }, [state.isOpen]);
1346
+ const handleClose = (0, import_react2.useCallback)(() => {
1347
+ setIsClosing(true);
1348
+ setTimeout(() => {
1349
+ setIsClosing(false);
1350
+ close();
1351
+ triggerRef.current?.focus();
1352
+ }, 150);
1353
+ }, [close]);
1354
+ const handleSubmit = (0, import_react2.useCallback)(() => {
1355
+ const text = inputValue.trim();
1356
+ if (!text) return;
1357
+ setInputValue("");
1358
+ submit(text);
1359
+ }, [inputValue, submit]);
1360
+ const handleKeyDown = (0, import_react2.useCallback)(
1361
+ (e) => {
1362
+ if (e.key === "Enter" && !e.shiftKey) {
1363
+ e.preventDefault();
1364
+ handleSubmit();
1365
+ }
1366
+ },
1367
+ [handleSubmit]
1368
+ );
1369
+ if (!mounted || typeof document === "undefined") return null;
1370
+ const showPoweredBy = agent.poweredBy !== false;
1371
+ const showChips = chips.length > 0;
1372
+ const panelClass = isClosing ? "sd-r-closing" : state.isOpen ? "sd-r-opening" : "";
1373
+ const props = {
1374
+ agent,
1375
+ state,
1376
+ chips,
1377
+ accent,
1378
+ isLeft,
1379
+ inputValue,
1380
+ setInputValue,
1381
+ handleClose,
1382
+ handleSubmit,
1383
+ handleKeyDown,
1384
+ isClosing,
1385
+ panelClass,
1386
+ showChips,
1387
+ showPoweredBy,
1388
+ threadRef,
1389
+ inputRef,
1390
+ triggerRef,
1391
+ open,
1392
+ submit
1393
+ };
1394
+ const content = theme === "dark" ? renderDark(props) : theme === "light" ? renderLight(props) : renderClassic(props);
1395
+ return (0, import_react_dom.createPortal)(content, document.body);
1396
+ }
1397
+ // Annotate the CommonJS export names for ESM import in node:
1398
+ 0 && (module.exports = {
1399
+ SageDeskWidget,
1400
+ useSageDesk
1401
+ });
1402
+ //# sourceMappingURL=index.cjs.map