chatbotlite 0.0.1 → 0.2.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,657 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+
6
+ // src/react/ChatWidget.tsx
7
+
8
+ // src/core/prompts.ts
9
+ function buildSystemPrompt(business) {
10
+ const parts = [];
11
+ parts.push(`You are an AI receptionist for ${business.name}.`);
12
+ if (business.description) parts.push(business.description);
13
+ parts.push("");
14
+ if (business.services && business.services.length > 0) {
15
+ parts.push("Services offered (only these \u2014 do not invent others):");
16
+ for (const s of business.services) {
17
+ const price = s.price ? ` \u2014 ${s.price}` : "";
18
+ const notes = s.notes ? ` (${s.notes})` : "";
19
+ parts.push(`- ${s.name}${price}${notes}`);
20
+ }
21
+ parts.push("");
22
+ }
23
+ if (business.hours) {
24
+ parts.push(`Hours: ${business.hours}`);
25
+ }
26
+ if (business.serviceArea && business.serviceArea.length > 0) {
27
+ parts.push(`Service area: ${business.serviceArea.join(", ")}.`);
28
+ parts.push("If the caller is outside this area, say so and recommend owner review.");
29
+ }
30
+ if (business.policies && business.policies.length > 0) {
31
+ parts.push("");
32
+ parts.push("Known policies (use these exact answers when asked):");
33
+ for (const p of business.policies) {
34
+ parts.push(`- ${p.topic}: ${p.answer}`);
35
+ }
36
+ }
37
+ parts.push("");
38
+ parts.push("Rules:");
39
+ parts.push("- Reply in 1-2 short sentences, conversational tone.");
40
+ parts.push("- NEVER invent prices, availability, dispatch times, or appointment confirmations.");
41
+ parts.push("- For anything not covered in the setup above, say it needs owner review.");
42
+ parts.push('- If the caller is clearly a vendor/sales pitch, say: "This does not look like a customer service request, so we will not continue this thread."');
43
+ parts.push(`- If wrong number or asked to stop, say: "Sorry about that. We won't text again."`);
44
+ if (business.doNotPromise && business.doNotPromise.length > 0) {
45
+ parts.push("");
46
+ parts.push("Never promise:");
47
+ for (const p of business.doNotPromise) parts.push(`- ${p}`);
48
+ }
49
+ if (business.customInstructions) {
50
+ parts.push("");
51
+ parts.push("Additional instructions:");
52
+ parts.push(business.customInstructions);
53
+ }
54
+ if (business.language && business.language !== "en") {
55
+ parts.push("");
56
+ parts.push(`Reply in ${business.language}.`);
57
+ }
58
+ return parts.join("\n");
59
+ }
60
+
61
+ // src/core/guards.ts
62
+ var FORBIDDEN_PHRASES = [
63
+ "help is coming",
64
+ "someone is on the way",
65
+ "technician is on the way",
66
+ "provider is on the way",
67
+ "dispatching someone",
68
+ "i've booked",
69
+ "i have booked",
70
+ "reservation confirmed",
71
+ "your appointment is confirmed",
72
+ "i've scheduled",
73
+ "i have scheduled",
74
+ "we've dispatched",
75
+ "we have dispatched",
76
+ "i can confirm",
77
+ "i guarantee",
78
+ "guaranteed delivery",
79
+ "guaranteed arrival",
80
+ "will arrive at",
81
+ "arriving at",
82
+ "i'll send",
83
+ "i will send"
84
+ ];
85
+ function checkForbiddenPhrases(reply) {
86
+ const lower = reply.toLowerCase();
87
+ const violations = [];
88
+ for (const phrase of FORBIDDEN_PHRASES) {
89
+ if (lower.includes(phrase)) {
90
+ violations.push(`Forbidden phrase: "${phrase}"`);
91
+ }
92
+ }
93
+ return { ok: violations.length === 0, violations };
94
+ }
95
+ function stripForbidden(reply) {
96
+ const sentences = reply.split(/(?<=[.!?])\s+/);
97
+ const kept = sentences.filter((s) => {
98
+ const lower = s.toLowerCase();
99
+ return !FORBIDDEN_PHRASES.some((p) => lower.includes(p));
100
+ });
101
+ const trimmed = kept.join(" ").trim();
102
+ if (trimmed.length < 10) {
103
+ return "Thanks for reaching out \u2014 let me check with the owner and get back to you.";
104
+ }
105
+ return trimmed;
106
+ }
107
+
108
+ // src/client/types.ts
109
+ var PROVIDER_NAMES = /* @__PURE__ */ new Set([
110
+ "openai",
111
+ "deepseek",
112
+ "groq",
113
+ "gemini",
114
+ "anthropic",
115
+ "cerebras",
116
+ "sambanova",
117
+ "fireworks",
118
+ "mistral",
119
+ "openrouter",
120
+ "moonshot"
121
+ ]);
122
+ function parseChainSpec(spec) {
123
+ const slash = spec.indexOf("/");
124
+ if (slash === -1) {
125
+ if (!PROVIDER_NAMES.has(spec)) {
126
+ throw new Error(`chatbotlite: unknown provider "${spec}". Use "provider/model" or a known provider name.`);
127
+ }
128
+ return { provider: spec, model: null };
129
+ }
130
+ const provider = spec.slice(0, slash);
131
+ const model = spec.slice(slash + 1);
132
+ if (!PROVIDER_NAMES.has(provider)) {
133
+ throw new Error(`chatbotlite: unknown provider "${provider}" in chain spec "${spec}".`);
134
+ }
135
+ if (!model) {
136
+ throw new Error(`chatbotlite: empty model name in chain spec "${spec}".`);
137
+ }
138
+ return { provider, model };
139
+ }
140
+ function isKnownProvider(name) {
141
+ return PROVIDER_NAMES.has(name);
142
+ }
143
+
144
+ // src/client/providers.ts
145
+ var PROVIDER_ENDPOINTS = {
146
+ openai: { baseUrl: "https://api.openai.com/v1", defaultModel: "gpt-4o-mini" },
147
+ deepseek: { baseUrl: "https://api.deepseek.com/v1", defaultModel: "deepseek-chat" },
148
+ groq: { baseUrl: "https://api.groq.com/openai/v1", defaultModel: "llama-3.3-70b-versatile" },
149
+ gemini: { baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai", defaultModel: "gemini-2.5-flash" },
150
+ anthropic: { baseUrl: "https://api.anthropic.com/v1", defaultModel: "claude-haiku-4-5" },
151
+ cerebras: { baseUrl: "https://api.cerebras.ai/v1", defaultModel: "qwen-3-235b-a22b-instruct-2507" },
152
+ sambanova: { baseUrl: "https://api.sambanova.ai/v1", defaultModel: "Meta-Llama-3.3-70B-Instruct" },
153
+ fireworks: { baseUrl: "https://api.fireworks.ai/inference/v1", defaultModel: "accounts/fireworks/models/llama-v3p3-70b-instruct" },
154
+ mistral: { baseUrl: "https://api.mistral.ai/v1", defaultModel: "mistral-small-latest" },
155
+ openrouter: { baseUrl: "https://openrouter.ai/api/v1", defaultModel: "deepseek/deepseek-chat" },
156
+ moonshot: { baseUrl: "https://api.moonshot.ai/v1", defaultModel: "moonshot-v1-32k" }
157
+ };
158
+ function isRetryableError(err) {
159
+ const msg = err instanceof Error ? err.message : String(err);
160
+ return /\b(429|rate.?limit|quota|exceed|5\d\d|timeout|ECONNRESET|fetch failed)\b/i.test(msg);
161
+ }
162
+
163
+ // src/client/chatbot.ts
164
+ var ChatBot = class {
165
+ business;
166
+ steps;
167
+ keys;
168
+ fetcher;
169
+ timeoutMs;
170
+ cachedSystemPrompt;
171
+ constructor(init) {
172
+ this.business = init.business;
173
+ this.keys = init.providers.keys ?? {};
174
+ this.steps = resolveChain(init.providers);
175
+ this.fetcher = init.options?.fetch ?? globalThis.fetch.bind(globalThis);
176
+ this.timeoutMs = init.options?.timeoutMs ?? 3e4;
177
+ this.cachedSystemPrompt = buildSystemPrompt(this.business);
178
+ }
179
+ async reply(message, opts = {}) {
180
+ const systemPrompt = opts.systemPrompt ?? this.cachedSystemPrompt;
181
+ const messages = [
182
+ { role: "system", content: systemPrompt },
183
+ ...opts.history ?? [],
184
+ { role: "user", content: message }
185
+ ];
186
+ const attempts = [];
187
+ let lastError;
188
+ for (const step of this.steps) {
189
+ const t0 = Date.now();
190
+ try {
191
+ const result = await this.callProvider(step, messages);
192
+ attempts.push({ provider: step.provider, model: step.model, status: "ok", latencyMs: Date.now() - t0 });
193
+ const guard = checkForbiddenPhrases(result.reply);
194
+ const finalReply = guard.ok ? result.reply : stripForbidden(result.reply);
195
+ return {
196
+ reply: finalReply,
197
+ usedProvider: step.provider,
198
+ usedModel: step.model,
199
+ ...result.usage ? { usage: result.usage } : {},
200
+ guardWarnings: guard.violations,
201
+ attempts
202
+ };
203
+ } catch (err) {
204
+ lastError = err;
205
+ const errMsg = err instanceof Error ? err.message : String(err);
206
+ attempts.push({
207
+ provider: step.provider,
208
+ model: step.model,
209
+ status: "error",
210
+ error: errMsg,
211
+ latencyMs: Date.now() - t0
212
+ });
213
+ if (!isRetryableError(err)) {
214
+ throw new Error(`chatbotlite: ${step.provider}/${step.model} failed (non-retryable). ${errMsg}`);
215
+ }
216
+ }
217
+ }
218
+ const summary = attempts.map((a) => `${a.provider}/${a.model}:${a.error ?? "ok"}`).join(" \u2192 ");
219
+ throw new Error(`chatbotlite: all chain steps failed. Trace: ${summary}. Last error: ${lastError instanceof Error ? lastError.message : String(lastError)}`);
220
+ }
221
+ async callProvider(step, messages) {
222
+ const endpoint = PROVIDER_ENDPOINTS[step.provider];
223
+ const key = this.keys[step.provider];
224
+ if (!key) throw new Error(`Missing API key for provider: ${step.provider}`);
225
+ const controller = new AbortController();
226
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
227
+ try {
228
+ const res = await this.fetcher(`${endpoint.baseUrl}/chat/completions`, {
229
+ method: "POST",
230
+ headers: {
231
+ "Authorization": `Bearer ${key}`,
232
+ "Content-Type": "application/json"
233
+ },
234
+ body: JSON.stringify({
235
+ model: step.model,
236
+ messages,
237
+ temperature: 0.3,
238
+ max_tokens: 300
239
+ }),
240
+ signal: controller.signal
241
+ });
242
+ if (!res.ok) {
243
+ const body = await res.text();
244
+ throw new Error(`${res.status}: ${body.slice(0, 200)}`);
245
+ }
246
+ const data = await res.json();
247
+ const msg = data.choices?.[0]?.message;
248
+ const reply = (msg?.content?.trim() || msg?.reasoning_content?.trim()) ?? "";
249
+ if (!reply) throw new Error("empty reply from provider");
250
+ const result = { reply };
251
+ if (data.usage) result.usage = data.usage;
252
+ return result;
253
+ } finally {
254
+ clearTimeout(timer);
255
+ }
256
+ }
257
+ };
258
+ function resolveChain(providers) {
259
+ const keys = providers.keys ?? {};
260
+ const explicit = providers.chain;
261
+ if (explicit && explicit.length > 0) {
262
+ return explicit.map((entry) => normalizeChainEntry(entry, keys));
263
+ }
264
+ const orderedProviders = Object.keys(keys).filter((k) => isKnownProvider(k) && keys[k]);
265
+ if (orderedProviders.length === 0) {
266
+ throw new Error("chatbotlite: at least one provider key is required.");
267
+ }
268
+ return orderedProviders.map((provider) => ({
269
+ provider,
270
+ model: PROVIDER_ENDPOINTS[provider].defaultModel,
271
+ spec: `${provider}/${PROVIDER_ENDPOINTS[provider].defaultModel}`
272
+ }));
273
+ }
274
+ function normalizeChainEntry(entry, keys) {
275
+ let provider;
276
+ let model;
277
+ let spec;
278
+ if (typeof entry === "string") {
279
+ const parsed = parseChainSpec(entry);
280
+ provider = parsed.provider;
281
+ model = parsed.model ?? PROVIDER_ENDPOINTS[provider].defaultModel;
282
+ spec = entry;
283
+ } else {
284
+ if (!isKnownProvider(entry.provider)) {
285
+ throw new Error(`chatbotlite: unknown provider "${entry.provider}" in chain entry.`);
286
+ }
287
+ provider = entry.provider;
288
+ model = entry.model ?? PROVIDER_ENDPOINTS[provider].defaultModel;
289
+ spec = `${provider}/${model}`;
290
+ }
291
+ if (!keys[provider]) {
292
+ throw new Error(`chatbotlite: chain step "${spec}" needs a key for provider "${provider}" but none was provided.`);
293
+ }
294
+ return { provider, model, spec };
295
+ }
296
+ var BOLT = "\u26A1";
297
+ var DEFAULT_PRIMARY = "#0f172a";
298
+ var DEFAULT_ON_PRIMARY = "#ffffff";
299
+ var SURFACE = "#ffffff";
300
+ var SURFACE_MUTED = "#fafbfc";
301
+ var BORDER = "#e5e7eb";
302
+ var TEXT_BODY = "#0f172a";
303
+ var TEXT_MUTED = "#64748b";
304
+ var TEXT_FAINT = "#94a3b8";
305
+ var FONT_STACK = `'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif`;
306
+ var STYLE_TAG_ID = "chatbotlite-widget-styles";
307
+ var KEYFRAMES = `
308
+ @keyframes chatbotlite-pop { 0% { opacity: 0; transform: scale(0.6); } 100% { opacity: 1; transform: scale(1); } }
309
+ @keyframes chatbotlite-slide { 0% { opacity: 0; transform: translateY(16px) scale(0.98); } 100% { opacity: 1; transform: translateY(0) scale(1); } }
310
+ @keyframes chatbotlite-fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
311
+ @keyframes chatbotlite-dot { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-4px); opacity: 1; } }
312
+ .chatbotlite-launcher { transition: transform 180ms cubic-bezier(0.4, 0, 0.2, 1), box-shadow 180ms cubic-bezier(0.4, 0, 0.2, 1); }
313
+ .chatbotlite-launcher:hover { transform: translateY(-2px) scale(1.04); }
314
+ .chatbotlite-launcher:active { transform: translateY(0) scale(0.98); }
315
+ .chatbotlite-close { transition: background 120ms ease; }
316
+ .chatbotlite-close:hover { background: rgba(255,255,255,0.16); }
317
+ .chatbotlite-send { transition: transform 120ms ease, opacity 120ms ease, box-shadow 120ms ease; }
318
+ .chatbotlite-send:not(:disabled):hover { transform: translateY(-1px); }
319
+ .chatbotlite-send:not(:disabled):active { transform: translateY(0); }
320
+ .chatbotlite-input:focus { box-shadow: 0 0 0 3px rgba(15,23,42,0.06); }
321
+ .chatbotlite-msg { animation: chatbotlite-fade-in 220ms cubic-bezier(0.4, 0, 0.2, 1); }
322
+ .chatbotlite-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: ${TEXT_FAINT}; margin-right: 4px; animation: chatbotlite-dot 1.2s ease-in-out infinite; }
323
+ .chatbotlite-dot:nth-child(2) { animation-delay: 0.15s; }
324
+ .chatbotlite-dot:nth-child(3) { animation-delay: 0.3s; margin-right: 0; }
325
+ .chatbotlite-brand:hover { color: ${TEXT_MUTED} !important; }
326
+ `;
327
+ function ensureStyles() {
328
+ if (typeof document === "undefined") return;
329
+ if (document.getElementById(STYLE_TAG_ID)) return;
330
+ const style = document.createElement("style");
331
+ style.id = STYLE_TAG_ID;
332
+ style.textContent = KEYFRAMES;
333
+ document.head.appendChild(style);
334
+ }
335
+ function ChatWidget(props) {
336
+ const {
337
+ theme: themeOverrides,
338
+ title,
339
+ subtitle,
340
+ greeting,
341
+ showBranding = true,
342
+ position = "bottom-right"
343
+ } = props;
344
+ const isEndpointMode = "endpoint" in props && typeof props.endpoint === "string";
345
+ const resolvedTitle = title ?? props.business?.name ?? "Chat";
346
+ const resolvedGreeting = greeting ?? (props.business ? `Hi! I'm here for ${props.business.name}. How can we help?` : "Hi! How can we help?");
347
+ const primary = themeOverrides?.primary ?? DEFAULT_PRIMARY;
348
+ const onPrimary = themeOverrides?.onPrimary ?? DEFAULT_ON_PRIMARY;
349
+ const [open, setOpen] = react.useState(false);
350
+ const [messages, setMessages] = react.useState([
351
+ { id: "g0", role: "assistant", content: resolvedGreeting, ts: Date.now() }
352
+ ]);
353
+ const [input, setInput] = react.useState("");
354
+ const [sending, setSending] = react.useState(false);
355
+ const scrollRef = react.useRef(null);
356
+ const inputRef = react.useRef(null);
357
+ react.useEffect(() => {
358
+ ensureStyles();
359
+ }, []);
360
+ const bot = react.useMemo(() => {
361
+ if (isEndpointMode) return null;
362
+ if (!props.business || !props.providers) return null;
363
+ return new ChatBot({ business: props.business, providers: props.providers });
364
+ }, [isEndpointMode, props.business, props.providers]);
365
+ react.useEffect(() => {
366
+ if (scrollRef.current) {
367
+ scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
368
+ }
369
+ }, [messages, sending, open]);
370
+ react.useEffect(() => {
371
+ if (open && inputRef.current) {
372
+ const t = setTimeout(() => inputRef.current?.focus(), 240);
373
+ return () => clearTimeout(t);
374
+ }
375
+ return void 0;
376
+ }, [open]);
377
+ async function fetchReplyFromEndpoint(text, history) {
378
+ const res = await fetch(props.endpoint, {
379
+ method: "POST",
380
+ headers: { "Content-Type": "application/json" },
381
+ body: JSON.stringify({ message: text, transcript: history })
382
+ });
383
+ if (!res.ok) throw new Error(`Endpoint ${res.status}: ${await res.text().catch(() => "")}`);
384
+ const data = await res.json();
385
+ if (data.error) throw new Error(data.error);
386
+ if (!data.reply) throw new Error("Endpoint returned no reply.");
387
+ return data.reply;
388
+ }
389
+ async function send() {
390
+ const text = input.trim();
391
+ if (!text || sending) return;
392
+ setInput("");
393
+ const userMsg = { id: `u${Date.now()}`, role: "user", content: text, ts: Date.now() };
394
+ setMessages((prev) => [...prev, userMsg]);
395
+ setSending(true);
396
+ try {
397
+ const history = messages.filter((m) => m.role !== "system").map((m) => ({ role: m.role, content: m.content }));
398
+ const reply = isEndpointMode ? await fetchReplyFromEndpoint(text, history) : (await bot.reply(text, { history })).reply;
399
+ setMessages((prev) => [...prev, { id: `a${Date.now()}`, role: "assistant", content: reply, ts: Date.now() }]);
400
+ } catch (err) {
401
+ const errMsg = err instanceof Error ? err.message : String(err);
402
+ setMessages((prev) => [...prev, { id: `e${Date.now()}`, role: "assistant", content: `Sorry \u2014 something went wrong. (${errMsg})`, ts: Date.now() }]);
403
+ } finally {
404
+ setSending(false);
405
+ }
406
+ }
407
+ const launcherPos = position === "bottom-left" ? { left: 20 } : { right: 20 };
408
+ const panelPos = position === "bottom-left" ? { left: 20 } : { right: 20 };
409
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
410
+ !open && /* @__PURE__ */ jsxRuntime.jsx(
411
+ "button",
412
+ {
413
+ className: "chatbotlite-launcher",
414
+ onClick: () => setOpen(true),
415
+ "aria-label": "Open chat",
416
+ style: {
417
+ position: "fixed",
418
+ bottom: 20,
419
+ ...launcherPos,
420
+ width: 60,
421
+ height: 60,
422
+ borderRadius: 18,
423
+ background: primary,
424
+ color: onPrimary,
425
+ border: "none",
426
+ fontSize: 28,
427
+ lineHeight: 1,
428
+ cursor: "pointer",
429
+ boxShadow: "0 12px 28px -8px rgba(15,23,42,0.32), 0 4px 8px -2px rgba(15,23,42,0.12)",
430
+ zIndex: 99999,
431
+ animation: "chatbotlite-pop 320ms cubic-bezier(0.34, 1.56, 0.64, 1)",
432
+ display: "flex",
433
+ alignItems: "center",
434
+ justifyContent: "center"
435
+ },
436
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { style: { filter: "drop-shadow(0 1px 2px rgba(0,0,0,0.2))" }, children: BOLT })
437
+ }
438
+ ),
439
+ open && /* @__PURE__ */ jsxRuntime.jsxs(
440
+ "div",
441
+ {
442
+ role: "dialog",
443
+ "aria-label": "Chat",
444
+ style: {
445
+ position: "fixed",
446
+ bottom: 20,
447
+ ...panelPos,
448
+ width: 380,
449
+ maxWidth: "calc(100vw - 40px)",
450
+ height: 580,
451
+ maxHeight: "calc(100vh - 40px)",
452
+ background: SURFACE,
453
+ color: TEXT_BODY,
454
+ borderRadius: 20,
455
+ boxShadow: "0 24px 60px -16px rgba(15,23,42,0.32), 0 8px 24px -8px rgba(15,23,42,0.12), 0 0 0 1px rgba(15,23,42,0.04)",
456
+ display: "flex",
457
+ flexDirection: "column",
458
+ overflow: "hidden",
459
+ fontFamily: FONT_STACK,
460
+ zIndex: 99999,
461
+ animation: "chatbotlite-slide 280ms cubic-bezier(0.16, 1, 0.3, 1)"
462
+ },
463
+ children: [
464
+ /* @__PURE__ */ jsxRuntime.jsxs("header", { style: {
465
+ padding: "16px 18px",
466
+ background: primary,
467
+ color: onPrimary,
468
+ display: "flex",
469
+ justifyContent: "space-between",
470
+ alignItems: "center",
471
+ gap: 12
472
+ }, children: [
473
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "column", lineHeight: 1.2, minWidth: 0 }, children: [
474
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontWeight: 600, fontSize: 15, letterSpacing: "-0.01em", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: resolvedTitle }),
475
+ subtitle && /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: 12, opacity: 0.7, marginTop: 2, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: subtitle })
476
+ ] }),
477
+ /* @__PURE__ */ jsxRuntime.jsx(
478
+ "button",
479
+ {
480
+ className: "chatbotlite-close",
481
+ onClick: () => setOpen(false),
482
+ "aria-label": "Close chat",
483
+ style: {
484
+ background: "transparent",
485
+ border: "none",
486
+ color: onPrimary,
487
+ width: 32,
488
+ height: 32,
489
+ borderRadius: 10,
490
+ fontSize: 22,
491
+ lineHeight: 1,
492
+ cursor: "pointer",
493
+ display: "flex",
494
+ alignItems: "center",
495
+ justifyContent: "center",
496
+ flexShrink: 0
497
+ },
498
+ children: "\xD7"
499
+ }
500
+ )
501
+ ] }),
502
+ /* @__PURE__ */ jsxRuntime.jsxs(
503
+ "div",
504
+ {
505
+ ref: scrollRef,
506
+ style: {
507
+ flex: 1,
508
+ overflowY: "auto",
509
+ padding: "16px 14px",
510
+ display: "flex",
511
+ flexDirection: "column",
512
+ gap: 8,
513
+ background: SURFACE_MUTED
514
+ },
515
+ children: [
516
+ messages.map((m) => /* @__PURE__ */ jsxRuntime.jsx(
517
+ "div",
518
+ {
519
+ className: "chatbotlite-msg",
520
+ style: {
521
+ alignSelf: m.role === "user" ? "flex-end" : "flex-start",
522
+ maxWidth: "82%",
523
+ padding: "9px 13px",
524
+ borderRadius: m.role === "user" ? "18px 18px 4px 18px" : "18px 18px 18px 4px",
525
+ background: m.role === "user" ? primary : SURFACE,
526
+ color: m.role === "user" ? onPrimary : TEXT_BODY,
527
+ border: m.role === "user" ? "none" : `1px solid ${BORDER}`,
528
+ fontSize: 14,
529
+ lineHeight: 1.5,
530
+ letterSpacing: "-0.005em",
531
+ whiteSpace: "pre-wrap",
532
+ wordBreak: "break-word",
533
+ boxShadow: m.role === "user" ? "0 1px 2px rgba(15,23,42,0.12)" : "0 1px 2px rgba(15,23,42,0.04)"
534
+ },
535
+ children: m.content
536
+ },
537
+ m.id
538
+ )),
539
+ sending && /* @__PURE__ */ jsxRuntime.jsxs(
540
+ "div",
541
+ {
542
+ className: "chatbotlite-msg",
543
+ style: {
544
+ alignSelf: "flex-start",
545
+ padding: "12px 14px",
546
+ borderRadius: "18px 18px 18px 4px",
547
+ background: SURFACE,
548
+ border: `1px solid ${BORDER}`,
549
+ boxShadow: "0 1px 2px rgba(15,23,42,0.04)"
550
+ },
551
+ children: [
552
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "chatbotlite-dot" }),
553
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "chatbotlite-dot" }),
554
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "chatbotlite-dot" })
555
+ ]
556
+ }
557
+ )
558
+ ]
559
+ }
560
+ ),
561
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
562
+ display: "flex",
563
+ padding: 12,
564
+ gap: 8,
565
+ background: SURFACE,
566
+ borderTop: `1px solid ${BORDER}`
567
+ }, children: [
568
+ /* @__PURE__ */ jsxRuntime.jsx(
569
+ "input",
570
+ {
571
+ ref: inputRef,
572
+ className: "chatbotlite-input",
573
+ type: "text",
574
+ value: input,
575
+ onChange: (e) => setInput(e.target.value),
576
+ onKeyDown: (e) => {
577
+ if (e.key === "Enter" && !e.shiftKey) {
578
+ e.preventDefault();
579
+ void send();
580
+ }
581
+ },
582
+ placeholder: "Type a message\u2026",
583
+ disabled: sending,
584
+ style: {
585
+ flex: 1,
586
+ padding: "10px 14px",
587
+ borderRadius: 12,
588
+ border: `1px solid ${BORDER}`,
589
+ background: SURFACE_MUTED,
590
+ fontSize: 14,
591
+ fontFamily: FONT_STACK,
592
+ color: TEXT_BODY,
593
+ outline: "none",
594
+ transition: "box-shadow 120ms ease, border-color 120ms ease"
595
+ }
596
+ }
597
+ ),
598
+ /* @__PURE__ */ jsxRuntime.jsx(
599
+ "button",
600
+ {
601
+ className: "chatbotlite-send",
602
+ onClick: () => void send(),
603
+ disabled: sending || !input.trim(),
604
+ "aria-label": "Send message",
605
+ style: {
606
+ padding: "0 16px",
607
+ height: 40,
608
+ minWidth: 64,
609
+ borderRadius: 12,
610
+ background: primary,
611
+ color: onPrimary,
612
+ border: "none",
613
+ fontSize: 14,
614
+ fontWeight: 600,
615
+ fontFamily: FONT_STACK,
616
+ cursor: sending || !input.trim() ? "default" : "pointer",
617
+ opacity: sending || !input.trim() ? 0.4 : 1,
618
+ boxShadow: "0 2px 6px -1px rgba(15,23,42,0.18)"
619
+ },
620
+ children: "Send"
621
+ }
622
+ )
623
+ ] }),
624
+ showBranding && /* @__PURE__ */ jsxRuntime.jsxs(
625
+ "a",
626
+ {
627
+ className: "chatbotlite-brand",
628
+ href: "https://github.com/agents-io/chatbotlite",
629
+ target: "_blank",
630
+ rel: "noreferrer",
631
+ style: {
632
+ padding: "8px 12px",
633
+ fontSize: 11,
634
+ fontWeight: 500,
635
+ color: TEXT_FAINT,
636
+ textAlign: "center",
637
+ textDecoration: "none",
638
+ background: SURFACE,
639
+ borderTop: `1px solid ${BORDER}`,
640
+ letterSpacing: "0.01em",
641
+ transition: "color 120ms ease"
642
+ },
643
+ children: [
644
+ BOLT,
645
+ " Powered by chatbotlite"
646
+ ]
647
+ }
648
+ )
649
+ ]
650
+ }
651
+ )
652
+ ] });
653
+ }
654
+
655
+ exports.ChatWidget = ChatWidget;
656
+ //# sourceMappingURL=index.cjs.map
657
+ //# sourceMappingURL=index.cjs.map