@agentforge-io/chat-sdk 2.0.1 → 2.0.3

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.
Files changed (2) hide show
  1. package/dist/react.js +34 -3
  2. package/package.json +1 -1
package/dist/react.js CHANGED
@@ -26,6 +26,30 @@ const session_1 = require("./session");
26
26
  // headings, lists, blockquotes, fenced code, inline code, links, bold,
27
27
  // italic. Input is HTML-escaped first so the resulting markup is safe to
28
28
  // drop into dangerouslySetInnerHTML.
29
+ /**
30
+ * Convert a CSS color to `rgba(...)` with the given alpha. Accepts 3/4/6/8-hex
31
+ * (`#abc`, `#abcd`, `#aabbcc`, `#aabbccdd`) and also tolerates already-rgba/rgb
32
+ * inputs by returning them verbatim — those have their own alpha story and
33
+ * shouldn't be silently overwritten.
34
+ */
35
+ function hexToRgba(color, alpha) {
36
+ const trimmed = color.trim();
37
+ if (trimmed.startsWith('rgb'))
38
+ return trimmed;
39
+ const m = trimmed.match(/^#?([0-9a-fA-F]{3,8})$/);
40
+ if (!m)
41
+ return `rgba(124, 92, 255, ${alpha})`;
42
+ let h = m[1];
43
+ if (h.length === 3 || h.length === 4) {
44
+ h = h.split('').map((c) => c + c).join('');
45
+ }
46
+ if (h.length !== 6 && h.length !== 8)
47
+ return `rgba(124, 92, 255, ${alpha})`;
48
+ const r = parseInt(h.slice(0, 2), 16);
49
+ const g = parseInt(h.slice(2, 4), 16);
50
+ const b = parseInt(h.slice(4, 6), 16);
51
+ return `rgba(${r}, ${g}, ${b}, ${alpha})`;
52
+ }
29
53
  function escapeHtml(s) {
30
54
  return s.replace(/[&<>"']/g, (c) => c === '&'
31
55
  ? '&amp;'
@@ -240,9 +264,16 @@ function ChatWidget(props) {
240
264
  .join(' ');
241
265
  const rootStyle = {
242
266
  ...style,
243
- // Surface the theme primary color so the bubble + accents follow it.
267
+ // Surface the theme primary color so the bubble, header, focus rings,
268
+ // and send button all follow it. We derive a soft variant for shadows
269
+ // and a "header" variant (same color, used in lieu of the default slate
270
+ // header background) so branding actually reads at a glance.
244
271
  ...(theme?.primaryColor
245
- ? { ['--af-primary']: theme.primaryColor }
272
+ ? {
273
+ ['--af-primary']: theme.primaryColor,
274
+ ['--af-primary-soft']: hexToRgba(theme.primaryColor, 0.35),
275
+ ['--af-header-bg']: theme.primaryColor,
276
+ }
246
277
  : {}),
247
278
  };
248
279
  return ((0, jsx_runtime_1.jsxs)("div", { className: rootClass, style: rootStyle, "data-style-id": styleId, children: [!inline && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "af-toggle", "aria-label": open ? 'Close chat' : 'Open chat', "aria-expanded": open, onClick: () => setOpen((v) => !v), children: open ? (0, jsx_runtime_1.jsx)(CloseIcon, {}) : (0, jsx_runtime_1.jsx)(ChatIcon, {}) })), (0, jsx_runtime_1.jsxs)("div", { className: `af-panel ${open ? 'af-open' : ''}`, children: [(0, jsx_runtime_1.jsxs)("div", { className: "af-header", children: [theme?.avatarUrl ? (
@@ -315,7 +346,7 @@ const WIDGET_CSS = `
315
346
  .af-widget-root.af-pos-top-left .af-panel { left: 0; }
316
347
  .af-widget-root.af-inline .af-panel { position: relative; top: auto; bottom: auto; left: auto; right: auto; width: 100%; height: 540px; box-shadow: 0 1px 3px rgba(15,23,42,0.08); display: flex; }
317
348
  .af-panel.af-open { display: flex; }
318
- .af-header { padding: 14px 16px; background: var(--af-fg); color: white; display: flex; align-items: center; gap: 10px; }
349
+ .af-header { padding: 14px 16px; background: var(--af-header-bg, var(--af-fg)); color: white; display: flex; align-items: center; gap: 10px; }
319
350
  .af-header-info { flex: 1; min-width: 0; }
320
351
  .af-header-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: rgba(255,255,255,0.1); }
321
352
  .af-header-title { font-weight: 600; font-size: 14px; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentforge-io/chat-sdk",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "Framework-free chat session SDK for AgentForge public chat tokens. Headless — no DOM. Drop into any frontend (React, Vue, Svelte, vanilla) and listen for events.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",