@paramms/chat-widget 1.0.44 → 1.0.45

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/react.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"react.js","sources":["../src/react.tsx"],"sourcesContent":["// react.tsx — React wrapper around mount().\n//\n// Next.js App Router: add 'use client' to whichever file imports these.\n// The widget needs WebSocket + DOM — it cannot render on the server.\n//\n// Import path: '@paramms/chat-widget/react'\n//\n// Two components:\n// ChatWidget — general support chat (hotel, SaaS, helpdesk, etc.)\n// MarketplaceChat — one thread per listing (used cars, rentals, etc.)\n//\n// Both: only url + profileId are required. userId is always optional —\n// anonymous guests are handled automatically via localStorage.\n\nimport { useEffect, useRef, useState } from 'react'\nimport { mount, type MountOptions, type WidgetHandle } from './index.js'\n\n// Inline SVG launcher glyphs — emoji ('💬'/'✕') render differently on every\n// OS and clash with brand accents; these are crisp and consistent everywhere.\nfunction ChatGlyph({ size = 26 }: { size?: number }): JSX.Element {\n return (\n <svg viewBox=\"0 0 24 24\" width={size} height={size} fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\" aria-hidden=\"true\">\n <path\n d=\"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z\"\n fill=\"currentColor\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\"\n />\n </svg>\n )\n}\nfunction CloseGlyph({ size = 22 }: { size?: number }): JSX.Element {\n return (\n <svg viewBox=\"0 0 24 24\" width={size} height={size} fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\" aria-hidden=\"true\">\n <path d=\"M18 6 6 18M6 6l12 12\" stroke=\"currentColor\" strokeWidth=\"2.5\" strokeLinecap=\"round\" />\n </svg>\n )\n}\n\n// ── Shared base props ─────────────────────────────────────────────────────────\n\ninterface BaseProps {\n /** Relay URL — set as NEXT_PUBLIC_RELAY_URL in .env. Any scheme works:\n * `https://api.example.com` is fine. The WebSocket URL and REST base are\n * derived automatically — you do NOT need to pass `wss://` or `/ws`. */\n url: string\n /** HTTP(S) base for REST calls — only when the REST API is on a different\n * origin than the socket. Normally omit. */\n apiUrl?: string\n /** Your Relay profile ID — set as NEXT_PUBLIC_RELAY_PROFILE_ID in .env — required */\n profileId: string\n\n /** A signed identity token — an ES256 JWT `{sub,iat,exp}` minted by YOUR\n * backend for chatrooms with signed identity (guestPublicKey) enabled.\n * This is the production identity tier; wins over `userId`. */\n token?: string\n /** Called when a signed token expires: return a fresh token from your\n * backend to renew the session without a reload. */\n refreshToken?: () => Promise<string | null>\n /** Your logged-in user's stable ID. When omitted the widget automatically\n * assigns a persistent anonymous ID from localStorage — no login required. */\n userId?: string\n /** Shown to agents instead of the raw user ID */\n userName?: string\n /** Shown to agents so they can follow up by email */\n userEmail?: string\n /** Avatar URL shown in the widget header and dashboard */\n userAvatar?: string\n\n /** Brand colour hex, e.g. \"#1a56db\". Defaults to the profile theme colour. */\n accent?: string\n /** Render as a floating launcher button instead of inline */\n launcher?: boolean\n /** Launcher position — default 'bottom-right' */\n position?: 'bottom-right' | 'bottom-left'\n /** Launcher teaser (\"optional message\" above the bubble). String or\n * { title, subtitle }. Omit to use the chatroom's manifest value. */\n launcherMessage?: string | { title: string; subtitle?: string }\n /** Pre-set reply chips shown above the input */\n quickReplies?: string[]\n /** Container height when rendered inline. Default: '100%' */\n height?: string\n /** i18n string overrides for non-English sites */\n i18n?: MountOptions['i18n']\n /** ISO language code for auto-translating incoming messages */\n translateLang?: string\n /** Show a back chevron in the chatroom header that opens the full conversation\n * list (`ChatApp`) — turns a single-thread widget into a Channel.io-style app\n * where you can jump to any of the user's other conversations and back. */\n inbox?: boolean\n /** Inbox scope when `inbox` is set: 'tenant' (default) lists the user's threads\n * across ALL your chatrooms; 'profile' limits it to this one. */\n inboxScope?: 'tenant' | 'profile'\n}\n\n// ── ChatWidget ────────────────────────────────────────────────────────────────\n\nexport interface ChatWidgetProps extends BaseProps {\n /** Optional context card shown at the top of the chat\n * (e.g. the support ticket, booking, or order being discussed) */\n contextTitle?: string\n contextSubtitle?: string\n contextStatus?: string\n\n /** Stable item ID — pins this conversation to a specific item/thread. */\n subjectId?: string\n}\n\n/**\n * General-purpose support chat widget. Only `url` and `profileId` are required.\n * All other props are optional — anonymous guests work without any configuration.\n *\n * @example Basic support chat\n * ```tsx\n * <ChatWidget\n * url={process.env.NEXT_PUBLIC_RELAY_URL}\n * profileId={process.env.NEXT_PUBLIC_RELAY_PROFILE_ID}\n * userId={session?.user.id}\n * userName={session?.user.name}\n * userEmail={session?.user.email}\n * />\n * ```\n *\n * @example Multi-thread (tickets, bookings, orders) — one thread per subjectId\n * ```tsx\n * <ChatWidget\n * url={...} profileId={...}\n * subjectId={`ticket_${ticket.id}`}\n * contextTitle={ticket.title}\n * contextStatus={ticket.status}\n * userId={session?.user.id}\n * />\n * ```\n *\n * Need a list of the user's threads with tap-to-open? That's `<ChatApp />`\n * (inline) or `<ChatAppLauncher />` (floating bubble) — this component renders\n * a single conversation.\n */\nexport function ChatWidget({\n url, apiUrl, profileId,\n token, refreshToken,\n userId, userName, userEmail, userAvatar,\n contextTitle, contextSubtitle, contextStatus,\n subjectId,\n accent, launcher, position, launcherMessage, quickReplies, height = '100%',\n i18n, translateLang, inbox, inboxScope,\n}: ChatWidgetProps): JSX.Element {\n const ref = useRef<HTMLDivElement>(null)\n const handleRef = useRef<WidgetHandle | null>(null)\n // When `inbox` is enabled, the header back chevron swaps this single thread\n // for the full conversation list (ChatApp). Tapping a row there opens that\n // thread in ChatApp's own stack; the widget becomes a mini messaging app.\n const [showInbox, setShowInbox] = useState(false)\n\n useEffect(() => {\n if (showInbox) return // showing the list, not the single thread\n if (!ref.current) return\n handleRef.current?.close()\n handleRef.current = mount({\n el: ref.current,\n url,\n ...(apiUrl ? { apiUrl } : {}),\n profileId,\n ...(subjectId ? { subjectId } : {}),\n ...(token ? { token } : {}),\n ...(refreshToken ? { refreshToken } : {}),\n ...(userId ? { userId } : {}),\n ...(userId || userName || userEmail || userAvatar ? {\n user: {\n ...(userName ? { name: userName } : {}),\n ...(userEmail ? { email: userEmail } : {}),\n ...(userAvatar ? { avatar: userAvatar } : {}),\n },\n } : {}),\n ...(contextTitle ? {\n subject: {\n title: contextTitle,\n ...(contextSubtitle ? { subtitle: contextSubtitle } : {}),\n ...(contextStatus ? { status: contextStatus } : {}),\n },\n } : {}),\n ...(quickReplies ? { quickReplies } : {}),\n ...(accent ? { accent } : {}),\n ...(translateLang ? { translateLang } : {}),\n ...(i18n ? { i18n } : {}),\n ...(inbox && !launcher ? { onBack: () => setShowInbox(true) } : {}),\n ...(launcher ? { launcher, position: position ?? 'bottom-right', ...(launcherMessage ? { launcherMessage } : {}) } : {}),\n })\n return () => { handleRef.current?.close(); handleRef.current = null }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [url, apiUrl, profileId, subjectId, token, userId, userName, userEmail, accent, launcher, position, launcherMessage, translateLang, inbox, showInbox])\n\n // Inbox view: the full conversation list (its own list↔room stack). Inline\n // only — in launcher mode the chat lives in a fixed panel that mount() owns,\n // so use <ChatAppLauncher> for a launcher-with-inbox experience instead.\n if (inbox && !launcher && showInbox) {\n return (\n <ChatApp\n url={url} {...(apiUrl ? { apiUrl } : {})} profileId={profileId}\n {...(token ? { token } : {})} {...(refreshToken ? { refreshToken } : {})}\n {...(userId ? { userId } : {})} {...(userName ? { userName } : {})} {...(userEmail ? { userEmail } : {})}\n {...(accent ? { accent } : {})} scope={inboxScope ?? 'tenant'} height={height}\n onClose={() => setShowInbox(false)}\n />\n )\n }\n\n // When launcher=true, still render the div — mount() moves it inside the\n // fixed panel above the bubble. Zero size so it doesn't affect page layout.\n return (\n <div\n ref={ref}\n style={launcher ? { width: 0, height: 0, overflow: 'hidden' } : { width: '100%', height, minHeight: height === '100%' ? '480px' : undefined }}\n />\n )\n}\n\n// ── MarketplaceChat ───────────────────────────────────────────────────────────\n\nexport interface MarketplaceChatProps extends BaseProps {\n /** Unique ID for this listing — each listing gets its own thread.\n * Omit for a general (non-item-specific) conversation. */\n listingId?: string\n /** Shown at the top of the chat — e.g. \"2019 Toyota Camry SE\" */\n listingTitle?: string\n /** One-line detail — e.g. \"45,000 km · Automatic\" */\n listingMeta?: string\n /** Price shown as a tag — e.g. 12500 → \"$12,500\" */\n listingPrice?: number\n /** Status badge — e.g. \"Available\", \"Sold\", \"Pending\" */\n listingStatus?: string\n}\n\nconst DEFAULT_MARKETPLACE_REPLIES = [\n 'Is this still available?',\n 'Can I schedule a viewing?',\n 'What is your best price?',\n]\n\n/**\n * Marketplace chat widget. Two modes depending on whether `listingId` is provided:\n *\n * **With `listingId` (listing page)** — opens that listing's chat immediately.\n * No list screen. The buyer is already looking at the item so context is clear.\n * ```tsx\n * // On your listing detail page:\n * <MarketplaceChat\n * url={process.env.NEXT_PUBLIC_RELAY_URL}\n * profileId={process.env.NEXT_PUBLIC_RELAY_PROFILE_ID}\n * listingId={car.id}\n * listingTitle={car.title}\n * listingPrice={car.price}\n * listingMeta={`${car.mileage.toLocaleString()} km · ${car.gearbox}`}\n * listingStatus=\"Available\"\n * userId={session?.user.id}\n * userName={session?.user.name}\n * userEmail={session?.user.email}\n * />\n * ```\n *\n * **Without `listingId`** — opens the buyer's single general (non-listing)\n * thread with this chatroom. For a \"My Messages\" / inbox page with the\n * WhatsApp-style thread list and tap-to-open, use `<ChatApp />` (or\n * `<ChatAppLauncher />` for a floating bubble):\n * ```tsx\n * // On your /messages page:\n * <ChatApp\n * url={process.env.NEXT_PUBLIC_RELAY_URL}\n * profileId={process.env.NEXT_PUBLIC_RELAY_PROFILE_ID}\n * userId={session?.user.id}\n * />\n * ```\n *\n * Only `url` and `profileId` are required. All other props are optional.\n */\nexport function MarketplaceChat({\n url, apiUrl, profileId,\n token, refreshToken,\n listingId, listingTitle, listingMeta, listingPrice, listingStatus,\n userId, userName, userEmail, userAvatar,\n accent, launcher, position, launcherMessage, quickReplies, height = '100%',\n i18n, translateLang, inbox, inboxScope,\n}: MarketplaceChatProps): JSX.Element {\n const ref = useRef<HTMLDivElement>(null)\n const handleRef = useRef<WidgetHandle | null>(null)\n const [showInbox, setShowInbox] = useState(false)\n\n useEffect(() => {\n if (showInbox) return\n if (!ref.current) return\n // Coalesce rapid identity changes into a SINGLE mount. NextAuth's\n // `session?.user.id` is undefined on first render and resolves a tick later,\n // which would otherwise open an anonymous conversation and immediately\n // orphan it when the real id arrives — surfacing as \"a new chat every time\".\n // Deferring the mount lets a same-tick id change settle first. For a slower\n // (network) session fetch, gate rendering on the session status host-side\n // (e.g. NextAuth: don't render until `status !== 'loading'`).\n let cancelled = false\n const timer = setTimeout(() => {\n if (cancelled || !ref.current) return\n handleRef.current?.close()\n handleRef.current = mount({\n el: ref.current,\n url,\n ...(apiUrl ? { apiUrl } : {}),\n profileId,\n ...(listingId ? { subjectId: `listing_${listingId}` } : {}),\n ...(token ? { token } : {}),\n ...(refreshToken ? { refreshToken } : {}),\n ...(userId ? { userId } : {}),\n ...(userId || userName || userEmail || userAvatar ? {\n user: {\n ...(userName ? { name: userName } : {}),\n ...(userEmail ? { email: userEmail } : {}),\n ...(userAvatar ? { avatar: userAvatar } : {}),\n ...(listingId ? { meta: { listingId } } : {}),\n },\n } : {}),\n ...(listingTitle ? {\n subject: {\n title: listingTitle,\n ...(listingMeta ? { subtitle: listingMeta } : {}),\n ...(listingPrice ? { tags: [`$${listingPrice.toLocaleString()}`] } : {}),\n ...(listingStatus ? { status: listingStatus } : {}),\n },\n } : {}),\n quickReplies: quickReplies ?? DEFAULT_MARKETPLACE_REPLIES,\n ...(accent ? { accent } : {}),\n ...(translateLang ? { translateLang } : {}),\n ...(i18n ? { i18n } : {}),\n ...(inbox && !launcher ? { onBack: () => setShowInbox(true) } : {}),\n ...(launcher ? { launcher, position: position ?? 'bottom-right', ...(launcherMessage ? { launcherMessage } : {}) } : {}),\n })\n }, 0)\n return () => { cancelled = true; clearTimeout(timer); handleRef.current?.close(); handleRef.current = null }\n // Only identity/target-affecting props trigger a remount — metadata like\n // userName/userEmail is sent once at mount and must NOT churn the connection.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [url, apiUrl, profileId, listingId, token, userId, accent, launcher, position, launcherMessage, translateLang, inbox, showInbox])\n\n if (inbox && !launcher && showInbox) {\n return (\n <ChatApp\n url={url} {...(apiUrl ? { apiUrl } : {})} profileId={profileId}\n {...(token ? { token } : {})} {...(refreshToken ? { refreshToken } : {})}\n {...(userId ? { userId } : {})} {...(userName ? { userName } : {})} {...(userEmail ? { userEmail } : {})}\n {...(accent ? { accent } : {})} scope={inboxScope ?? 'tenant'} height={height}\n onClose={() => setShowInbox(false)}\n />\n )\n }\n\n // When launcher=true, still render the div — mount() moves it inside the\n // fixed panel above the bubble. Zero size so it doesn't affect page layout.\n return (\n <div\n ref={ref}\n style={launcher ? { width: 0, height: 0, overflow: 'hidden' } : { width: '100%', height, minHeight: height === '100%' ? '480px' : undefined }}\n />\n )\n}\n\n// ── ChatList ──────────────────────────────────────────────────────────────────\n\n/** Live viewport breakpoint — updates on resize/rotation via matchMedia,\n * never a one-shot read (a one-shot read leaves layouts stuck after the\n * user rotates their phone or resizes across the breakpoint). SSR-safe. */\nfunction useIsMobile(maxWidthPx: number): boolean {\n const [mobile, setMobile] = useState(\n typeof window !== 'undefined' && window.innerWidth <= maxWidthPx,\n )\n useEffect(() => {\n if (typeof window === 'undefined' || !window.matchMedia) return\n const mq = window.matchMedia(`(max-width: ${maxWidthPx}px)`)\n const onChange = (e: MediaQueryListEvent): void => setMobile(e.matches)\n setMobile(mq.matches)\n mq.addEventListener('change', onChange)\n return () => mq.removeEventListener('change', onChange)\n }, [maxWidthPx])\n return mobile\n}\n\nexport interface ChatAppProps {\n /** Relay URL — ONE url, any scheme; `https://api.relay.paramms.com` is the\n * recommended form. The WebSocket URL and REST base are derived from it —\n * you do NOT need to pass `wss://` or `/ws`. */\n url: string\n /** HTTP(S) base for REST calls — only when the REST API is on a different\n * origin than the socket. Normally omit.\n * @deprecated pass a single `url`; kept for back-compat. */\n apiUrl?: string\n /** A chatroom id. Provide `profileId` OR `tenantId` (see below). When both\n * are given, profileId also fixes where the ✎ \"new conversation\" opens. */\n profileId?: string\n /** Tenant-level identification — the natural fit for a chat app: lists\n * EVERY conversation this user has with your business across ALL of its\n * chatrooms, without naming one. Use this when the platform runs several\n * chatrooms under one tenant (e.g. a marketplace chatroom for\n * `<MarketplaceChat/>` pages PLUS a general-support chatroom) — the inbox\n * shows both, and each row opens against its own chatroom. The ✎ compose\n * button opens the tenant's default chatroom (its oldest, as reported by\n * the server). */\n tenantId?: string\n /** A signed identity token (ES256 JWT) for chatrooms with signed identity\n * enabled — the production tier. Wins over `userId`. */\n token?: string\n /** Return a fresh token when a signed token expires. */\n refreshToken?: () => Promise<string | null>\n /** Your logged-in user's stable ID. Omit for anonymous (uses localStorage UID) */\n userId?: string\n /** Optional: shown to agents in the dashboard */\n userName?: string\n /** Optional: shown to agents in the dashboard */\n userEmail?: string\n /** Which conversations the list shows when configured with a profileId\n * (default 'tenant'; irrelevant with `tenantId`, which is always\n * tenant-wide):\n * 'tenant' — every conversation this user has with the business that\n * owns `profileId`, across ALL of its chatrooms — like a real\n * messaging app. Each row opens against its own chatroom.\n * 'profile' — only this chatroom's threads (the pre-1.0.30 behaviour).\n * Tenancy note: guests never see or send tenant ids — the server resolves\n * the tenant FROM the profileId, so `profileId` stays the only id you\n * configure. */\n scope?: 'profile' | 'tenant'\n /** Brand colour hex — default '#4F63F5' */\n accent?: string\n /** Container height. Default: '100%' */\n height?: string\n /** When provided, ChatApp renders an always-visible close (✕) control in the\n * top-right corner of its container. Pass this whenever ChatApp is shown in\n * an overlay/panel or as a mobile-fullscreen surface (ChatAppLauncher wires\n * it automatically) so there is a reliable way OUT — without it, an inline\n * fullscreen panel on a phone (no Escape key, no reachable backdrop) traps\n * the user. Omit for a bare inline embed the host chromes itself. */\n onClose?: () => void\n /** i18n overrides */\n i18n?: import('./chatlist.js').ChatListOptions['i18n']\n}\n\n/**\n * Full chat-app component: conversation list on the left (or full screen on\n * mobile), chat room on the right when a thread is selected — like a\n * standalone messaging app. Tapping a thread opens the chat inline; the ✎\n * button starts a new conversation with the business.\n *\n * By default (`scope=\"tenant\"`) the list shows EVERY conversation this user\n * has with the business that owns `profileId` — across all of its chatrooms —\n * and each row opens against its own chatroom. Pass `scope=\"profile\"` to\n * limit it to one chatroom's threads.\n *\n * Identify at either level:\n * • `tenantId` — the natural fit for a chat app. A platform often runs\n * SEVERAL chatrooms under one business (a marketplace chatroom for\n * `<MarketplaceChat/>` pages plus a general-support chatroom, …); with\n * `tenantId` the inbox shows the user's chats with all of them, no\n * profileId needed. Compose opens the tenant's default chatroom.\n * • `profileId` — any one of the business's chatrooms; still lists\n * tenant-wide by default (`scope=\"tenant\"`), and fixes where compose\n * opens.\n *\n * @example\n * ```tsx\n * 'use client'\n * import { ChatApp } from '@paramms/chat-widget/react'\n *\n * export default function MessagesPage({ session }) {\n * return (\n * <div style={{ height: '100vh' }}>\n * <ChatApp\n * url={process.env.NEXT_PUBLIC_RELAY_URL}\n * tenantId={process.env.NEXT_PUBLIC_RELAY_TENANT_ID} // or profileId={…}\n * userId={session?.user.id}\n * userName={session?.user.name}\n * userEmail={session?.user.email}\n * />\n * </div>\n * )\n * }\n * ```\n */\nexport function ChatApp({\n url, apiUrl, profileId, tenantId, token, refreshToken, userId, userName, userEmail,\n accent, height = '100%', i18n, onClose,\n scope = 'tenant',\n}: ChatAppProps): JSX.Element {\n const misconfigured = !profileId && !tenantId\n type Entry = import('./chatlist.js').ChatListEntry\n const [selected, setSelected] = useState<Entry | null>(null)\n /** The conversation-list module failed to load — show why instead of an\n * empty panel. */\n const [listError, setListError] = useState(false)\n const listRef = useRef<HTMLDivElement>(null)\n const chatRef = useRef<HTMLDivElement>(null)\n const handleRef = useRef<import('./chatlist.js').ChatListHandle | null>(null)\n const chatHandle = useRef<WidgetHandle | null>(null)\n\n // Build the chat list\n useEffect(() => {\n if (!listRef.current) return\n let cancelled = false\n import('./chatlist.js').catch((e: unknown) => {\n // This promise had no rejection handler at all: if the chunk failed to\n // load (CSP, a 404 on the split chunk, an offline navigation) the list\n // silently never mounted and the host saw an empty white panel with\n // nothing but an unhandled rejection in the console.\n console.error('[relay] could not load the conversation list module.', e)\n if (!cancelled) setListError(true)\n return null\n }).then((mod) => {\n if (!mod) return\n const { mountChatList } = mod\n // The dynamic import is async: if the effect was cleaned up (unmount,\n // dep change, or StrictMode's double-invoke) before it resolved, or the\n // ref is gone, don't mount a phantom list that never gets closed.\n if (cancelled || !listRef.current) return\n handleRef.current = mountChatList({\n el: listRef.current,\n url,\n ...(apiUrl ? { apiUrl } : {}),\n ...(profileId ? { profileId } : {}),\n ...(tenantId ? { tenantId } : {}),\n scope,\n // We overlay a ✕ at top-right when `onClose` is given — tell the list to\n // keep its header clear so the ✕ doesn't land on the ✎ compose button.\n ...(onClose ? { reserveCloseSpace: true } : {}),\n onSelect: (entry) => setSelected(entry),\n // Compose (✎) opens the chatroom's general support thread — without\n // this a user with no conversations yet had an empty list and no way\n // to ever start one, which is what made ChatApp feel broken.\n // Compose target: the configured chatroom, else the tenant's default\n // (oldest chatroom, reported by the server on the first list fetch).\n onNewChat: () => {\n const target = handleRef.current?.defaultProfileId()\n if (!target) return // list hasn't loaded yet — nothing sane to open\n setSelected({ id: '__new__', profileId: target, state: 'open', updatedAt: Date.now() })\n },\n ...(token ? { token } : {}),\n ...(userId ? { userId } : {}),\n ...(accent ? { accent } : {}),\n ...(i18n ? { i18n } : {}),\n })\n })\n return () => { cancelled = true; handleRef.current?.close(); handleRef.current = null }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [url, apiUrl, profileId, tenantId, token, userId, scope])\n\n // Open a ChatWidget when a thread is selected.\n //\n // Two correctness details here:\n // • identity: `userId` goes through as userId (the host-vouched tier) and\n // signed JWTs as `token` — the same tiers as every other component. It\n // used to conflate them (`token: userId`), which worked only by the\n // accident that mount() folds userId into the token, and left no way to\n // pass a REAL signed token at all.\n // • chatroom: the row's OWN profileId wins. With scope='tenant' the list\n // spans every chatroom of the business, so opening against the mounted\n // profileId would find-or-create a DIFFERENT conversation.\n useEffect(() => {\n if (!chatRef.current || !selected) return\n chatHandle.current?.close()\n chatHandle.current = mount({\n el: chatRef.current,\n url,\n ...(apiUrl ? { apiUrl } : {}),\n profileId: (selected.profileId ?? profileId)!, // rows always carry theirs; compose sets one explicitly\n // DM rows open as direct conversations (kind + peer). Opening them via\n // their dm:… subjectId only works for the participant that OWNS the\n // thread key — the other side would silently fork a duplicate.\n ...(selected.kind === 'direct' && selected.peerId\n ? { kind: 'direct' as const, peerId: selected.peerId }\n : selected.subjectId ? { subjectId: selected.subjectId } : {}),\n ...(token ? { token } : {}),\n ...(refreshToken ? { refreshToken } : {}),\n ...(userId ? { userId } : {}),\n ...(userId || userName || userEmail ? {\n user: {\n ...(userName ? { name: userName } : {}),\n ...(userEmail ? { email: userEmail } : {}),\n },\n } : {}),\n ...(selected.subjectTitle ? {\n subject: {\n title: selected.subjectTitle,\n ...(selected.subjectMeta ? { subtitle: selected.subjectMeta } : {}),\n },\n } : {}),\n ...(accent ? { accent } : {}),\n // Stack navigation: the chatroom's back chevron returns to the list.\n onBack: () => setSelected(null),\n })\n // Keep the list fresh: opening a chat marks it read, and replies received\n // while a chat is open should update its row's preview/ordering.\n const listTimer = setInterval(() => handleRef.current?.refresh(), 20_000)\n return () => {\n clearInterval(listTimer)\n chatHandle.current?.close(); chatHandle.current = null\n // Refresh once on the way out so the row reflects what just happened.\n handleRef.current?.refresh()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [selected?.id])\n\n // (After all hooks — React requires unconditional hook order.)\n if (misconfigured) {\n return (\n <div style={{ padding: 16, font: '13px system-ui', color: '#b91c1c', background: '#fef2f2', borderRadius: 8 }}>\n [relay] &lt;ChatApp/&gt; needs a <code>profileId</code> or a <code>tenantId</code>.\n </div>\n )\n }\n\n // Stack navigation, like a native messaging app: show the LIST, and when a\n // conversation is tapped, push the CHATROOM over it (full surface); the\n // chatroom's own header carries the back chevron (wired via mount's onBack)\n // that pops back to the list. No two-pane \"select a conversation\" dead space —\n // that only ever made sense on a very wide desktop inbox, and read as broken\n // in the launcher panel / on mobile, which is how this is actually used.\n return (\n <div style={{ position: 'relative', width: '100%', height, minHeight: '400px', overflow: 'hidden', background: '#fff' }}>\n {onClose && !selected && (\n <button\n onClick={onClose}\n aria-label={i18n?.close ?? 'Close'}\n style={{\n position: 'absolute', top: 8, right: 8, zIndex: 20,\n width: 32, height: 32, borderRadius: '50%',\n display: 'flex', alignItems: 'center', justifyContent: 'center',\n background: 'rgba(0,0,0,.05)', border: 'none', color: '#1c1b1a',\n fontSize: 18, lineHeight: 1, cursor: 'pointer',\n }}\n >\n <CloseGlyph size={18} />\n </button>\n )}\n\n {/* List — kept mounted (just hidden) so its scroll position, search text\n and live unread counts survive a round-trip into a chatroom. */}\n <div style={{\n position: 'absolute', inset: 0,\n display: selected ? 'none' : 'flex', flexDirection: 'column',\n }}>\n {listError\n ? (\n <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', width: '100%', height: '100%', padding: 16, font: '13px system-ui', color: '#b91c1c', textAlign: 'center' }}>\n {i18n?.error ?? 'Could not load conversations.'}\n </div>\n )\n : <div ref={listRef} style={{ width: '100%', height: '100%' }} />}\n </div>\n\n {/* Chatroom — only present while a conversation is selected. */}\n {selected && (\n <div style={{ position: 'absolute', inset: 0, display: 'flex', flexDirection: 'column' }}>\n <div ref={chatRef} style={{ width: '100%', height: '100%' }} />\n </div>\n )}\n </div>\n )\n}\n\n// ── ChatAppLauncher ───────────────────────────────────────────────────────────\n\nexport interface ChatAppLauncherProps {\n /** Relay URL — ONE url, any scheme; `https://api.relay.paramms.com` is the\n * recommended form. The WebSocket URL and REST base are derived from it. */\n url: string\n /** HTTP(S) base for REST calls — only when REST is on a different origin.\n * @deprecated pass a single `url`; kept for back-compat. */\n apiUrl?: string\n /** A chatroom id. Provide `profileId` OR `tenantId`. */\n profileId?: string\n /** Tenant-level identification — the panel lists EVERY conversation this\n * user has with your business across ALL of its chatrooms (see\n * ChatAppProps.tenantId). The ✎ compose opens the tenant's default\n * chatroom. */\n tenantId?: string\n /** A signed identity token (ES256 JWT) for chatrooms with signed identity\n * enabled — the production tier. Wins over `userId`. */\n token?: string\n /** Return a fresh token when a signed token expires. */\n refreshToken?: () => Promise<string | null>\n /** Your logged-in user's stable ID */\n userId?: string\n userName?: string\n userEmail?: string\n /** Which conversations the panel's list shows — see ChatAppProps.scope.\n * Default 'tenant': every conversation this user has with the business. */\n scope?: 'profile' | 'tenant'\n /** Brand colour hex — default '#4F63F5' */\n accent?: string\n\n /** true → floating bubble fixed to the corner of the screen (like Intercom)\n * false → an inline \"Messages\" button that expands a panel below it\n * Default: true */\n floating?: boolean\n /** Only used when floating=true. Default: 'bottom-right' */\n position?: 'bottom-right' | 'bottom-left'\n /** Label shown on the button. Default: a chat-bubble icon for floating,\n * 'Messages' for inline. */\n label?: string\n /** Width of the chat panel. Default: '420px' (floating) or '100%' (inline) */\n panelWidth?: string\n /** Height of the chat panel. Default: '600px' */\n panelHeight?: string\n}\n\n/**\n * A button that opens the full ChatApp (list → chat) in a panel.\n *\n * floating=true → fixed bubble in the corner of the screen, like WhatsApp Web's\n * chat button or Intercom.\n * floating=false → an inline button (e.g. in your nav bar) that expands a panel\n * below it.\n *\n * @example Floating bubble (bottom-right)\n * ```tsx\n * <ChatAppLauncher\n * url={process.env.NEXT_PUBLIC_RELAY_URL}\n * profileId={process.env.NEXT_PUBLIC_RELAY_PROFILE_ID}\n * userId={session?.user.id}\n * floating\n * position=\"bottom-right\"\n * />\n * ```\n *\n * @example Inline nav button\n * ```tsx\n * <ChatAppLauncher\n * url={process.env.NEXT_PUBLIC_RELAY_URL}\n * profileId={process.env.NEXT_PUBLIC_RELAY_PROFILE_ID}\n * userId={session?.user.id}\n * floating={false}\n * label=\"Messages\"\n * />\n * ```\n */\nexport function ChatAppLauncher({\n url, apiUrl, profileId, tenantId, token, refreshToken, userId, userName, userEmail,\n scope,\n accent = '#4F63F5',\n floating = true,\n position = 'bottom-right',\n label,\n panelWidth,\n panelHeight = '600px',\n}: ChatAppLauncherProps): JSX.Element {\n const [open, setOpen] = useState(false)\n const btnRef = useRef<HTMLButtonElement>(null)\n\n const isRight = position === 'bottom-right'\n // Floating default is the inline SVG chat glyph (see ChatGlyph note); a\n // custom `label` string still wins. Inline mode defaults to a text label.\n const btnLabel = label ?? (floating ? undefined : 'Messages')\n const isMobile = useIsMobile(479)\n\n // Close on Escape\n useEffect(() => {\n const handler = (e: KeyboardEvent) => { if (e.key === 'Escape') setOpen(false) }\n document.addEventListener('keydown', handler)\n return () => document.removeEventListener('keydown', handler)\n }, [])\n\n // ── Floating mode ──────────────────────────────────────────────────────────\n if (floating) {\n // Mobile (<480px): the panel must be its OWN fixed fullscreen layer\n // (inset:0). Sizing it 100vw INSIDE the bottom-right wrapper — as it used\n // to — anchored its right edge 20px in from the viewport, pushing the\n // whole app 20px off-screen. The bubble wrapper stays above it (z 9999\n // vs 9998) so the ✕ keeps working as the close control. Live breakpoint:\n // rotating the phone re-lays-out.\n return (\n <div style={{\n position: 'fixed',\n [isRight ? 'right' : 'left']: '20px',\n bottom: '20px',\n zIndex: 9999,\n display: 'flex',\n flexDirection: 'column',\n alignItems: isRight ? 'flex-end' : 'flex-start',\n gap: '12px',\n }}>\n {/* Panel */}\n <div style={{\n ...(isMobile ? {\n position: 'fixed' as const, inset: 0,\n width: '100%', height: '100dvh', borderRadius: '0', zIndex: 9998,\n } : {\n width: `min(${panelWidth ?? '420px'}, calc(100vw - 40px))`,\n height: `min(${panelHeight}, calc(100dvh - 108px))`,\n borderRadius: '16px',\n }),\n overflow: 'hidden',\n boxShadow: isMobile ? 'none' : '0 8px 40px rgba(0,0,0,.18)',\n background: '#fff',\n display: open ? 'flex' : 'none',\n flexDirection: 'column',\n transformOrigin: `bottom ${isRight ? 'right' : 'left'}`,\n animation: open ? 'ocl-pop-in .18s ease' : 'none',\n }}>\n <ChatApp\n url={url} {...(apiUrl ? { apiUrl } : {})}\n {...(profileId ? { profileId } : {})}\n {...(tenantId ? { tenantId } : {})}\n {...(token ? { token } : {})}\n {...(refreshToken ? { refreshToken } : {})}\n {...(userId ? { userId } : {})}\n {...(userName ? { userName } : {})}\n {...(userEmail ? { userEmail } : {})}\n {...(scope ? { scope } : {})}\n accent={accent} height=\"100%\"\n onClose={() => setOpen(false)}\n />\n </div>\n\n {/* Bubble button. On a fullscreen mobile panel the bubble sits at\n bottom-right ON TOP of the message composer/send button, so hide it\n while open on mobile — the in-panel top-right ✕ is the close there. */}\n <button\n ref={btnRef}\n onClick={() => setOpen(o => !o)}\n aria-label={open ? 'Close chat' : (typeof btnLabel === 'string' ? btnLabel : 'Open chat')}\n aria-expanded={open}\n style={{\n width: '56px', height: '56px', borderRadius: '50%',\n background: accent, color: '#fff', border: 'none',\n fontSize: '20px', cursor: 'pointer', flexShrink: 0,\n boxShadow: '0 4px 16px rgba(0,0,0,.25)',\n transition: 'transform .15s',\n alignItems: 'center', justifyContent: 'center',\n display: (open && isMobile) ? 'none' : 'flex',\n }}\n onMouseEnter={e => { (e.currentTarget as HTMLElement).style.transform = 'scale(1.08)' }}\n onMouseLeave={e => { (e.currentTarget as HTMLElement).style.transform = 'scale(1)' }}\n >\n {open ? <CloseGlyph /> : (label ?? <ChatGlyph />)}\n </button>\n\n <style>{`@keyframes ocl-pop-in { from { opacity:0; transform:scale(.95) } to { opacity:1; transform:scale(1) } }`}</style>\n </div>\n )\n }\n\n // ── Inline mode ────────────────────────────────────────────────────────────\n // The panel is rendered via a fixed overlay anchored to the button position.\n // This prevents clipping from parent overflow:hidden containers (e.g. nav bars).\n // On mobile the anchored popover can't fit — it goes fullscreen instead\n // (the backdrop still closes it).\n const pWidth = `min(${panelWidth ?? '420px'}, calc(100vw - 16px))`\n\n // Track button position for panel anchor\n const [btnRect, setBtnRect] = useState<DOMRect | null>(null)\n\n const handleBtnClick = () => {\n if (!open && btnRef.current) setBtnRect(btnRef.current.getBoundingClientRect())\n setOpen(o => !o)\n }\n\n const panelTop = btnRect ? btnRect.bottom + 8 : 0\n // Clamp so a button near the left edge can't push the panel off-screen.\n const panelRight = btnRect ? Math.max(8, window.innerWidth - btnRect.right) : 0\n\n return (\n <>\n {/* Trigger button */}\n <button\n ref={btnRef}\n onClick={handleBtnClick}\n style={{\n display: 'inline-flex', alignItems: 'center', gap: '6px',\n padding: '8px 16px', borderRadius: '8px',\n background: open ? accent : 'transparent',\n color: open ? '#fff' : accent,\n border: `2px solid ${accent}`,\n fontSize: '14px', fontWeight: 600, cursor: 'pointer',\n transition: 'background .15s, color .15s',\n }}\n >\n <ChatGlyph size={16} /> {btnLabel}\n </button>\n\n {/* Fixed panel — rendered at document root level via CSS fixed positioning */}\n {open && btnRect && (\n <>\n {/* Backdrop */}\n <div\n onClick={() => setOpen(false)}\n style={{ position: 'fixed', inset: 0, zIndex: 9998 }}\n />\n <div style={{\n position: 'fixed',\n ...(isMobile ? {\n inset: 0, width: '100%', height: '100dvh', borderRadius: '0',\n } : {\n top: panelTop,\n right: panelRight,\n width: pWidth,\n height: `min(${panelHeight}, calc(100dvh - ${panelTop}px - 12px))`,\n borderRadius: '16px',\n }),\n overflow: 'hidden',\n boxShadow: isMobile ? 'none' : '0 8px 40px rgba(0,0,0,.2)',\n background: '#fff',\n zIndex: 9999,\n animation: 'ocl-slide-in .18s ease',\n }}>\n <ChatApp\n url={url} {...(apiUrl ? { apiUrl } : {})}\n {...(profileId ? { profileId } : {})}\n {...(tenantId ? { tenantId } : {})}\n {...(token ? { token } : {})}\n {...(refreshToken ? { refreshToken } : {})}\n {...(userId ? { userId } : {})}\n {...(userName ? { userName } : {})}\n {...(userEmail ? { userEmail } : {})}\n {...(scope ? { scope } : {})}\n accent={accent} height=\"100%\"\n onClose={() => setOpen(false)}\n />\n </div>\n <style>{`@keyframes ocl-slide-in { from { opacity:0; transform:translateY(-8px) } to { opacity:1; transform:translateY(0) } }`}</style>\n </>\n )}\n </>\n )\n}\n"],"names":["ChatGlyph","size","jsx","CloseGlyph","ChatWidget","url","apiUrl","profileId","token","refreshToken","userId","userName","userEmail","userAvatar","contextTitle","contextSubtitle","contextStatus","subjectId","accent","launcher","position","launcherMessage","quickReplies","height","i18n","translateLang","inbox","inboxScope","ref","useRef","handleRef","showInbox","setShowInbox","useState","useEffect","_a","mount","ChatApp","DEFAULT_MARKETPLACE_REPLIES","MarketplaceChat","listingId","listingTitle","listingMeta","listingPrice","listingStatus","cancelled","timer","useIsMobile","maxWidthPx","mobile","setMobile","mq","onChange","e","tenantId","onClose","scope","misconfigured","selected","setSelected","listError","setListError","listRef","chatRef","chatHandle","mod","mountChatList","entry","target","listTimer","_b","jsxs","ChatAppLauncher","floating","label","panelWidth","panelHeight","open","setOpen","btnRef","isRight","btnLabel","isMobile","handler","o","pWidth","btnRect","setBtnRect","handleBtnClick","panelTop","panelRight","Fragment"],"mappings":";;;AAmBA,SAASA,EAAU,EAAE,MAAAC,IAAO,MAAsC;AAChE,SACE,gBAAAC,EAAC,OAAA,EAAI,SAAQ,aAAY,OAAOD,GAAM,QAAQA,GAAM,MAAK,QAAO,OAAM,8BAA6B,eAAY,QAC7G,UAAA,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,GAAE;AAAA,MACF,MAAK;AAAA,MAAe,QAAO;AAAA,MAAe,aAAY;AAAA,MAAI,eAAc;AAAA,MAAQ,gBAAe;AAAA,IAAA;AAAA,EAAA,GAEnG;AAEJ;AACA,SAASC,EAAW,EAAE,MAAAF,IAAO,MAAsC;AACjE,SACE,gBAAAC,EAAC,OAAA,EAAI,SAAQ,aAAY,OAAOD,GAAM,QAAQA,GAAM,MAAK,QAAO,OAA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AY,EAAE,QAAAA,EAAA,IAAc,CAAA;AAAA,UAChC,GAAIC,IAAY,EAAE,UAAAA,EAAA,IAAc,CAAA;AAAA,UAChC,GAAIC,IAAY,EAAE,WAAAA,EAAA,IAAc,CAAA;AAAA,UAChC,GAAI4C,IAAY,EAAE,OAAAA,EAAA,IAAc,CAAA;AAAA,UACjC,QAAAtC;AAAA,UAAgB,QAAO;AAAA,UACvB,SAAS,MAAM4D,EAAQ,EAAK;AAAA,QAAA;AAAA,MAAA,GAEhC;AAAA,MACA,gBAAA5E,EAAC,WAAO,UAAA,uHAAA,CAAuH;AAAA,IAAA,EAAA,CACjI;AAAA,EAAA,GAEJ;AAEJ;"}
1
+ {"version":3,"file":"react.js","sources":["../src/react.tsx"],"sourcesContent":["// react.tsx — React wrapper around mount().\n//\n// Next.js App Router: add 'use client' to whichever file imports these.\n// The widget needs WebSocket + DOM — it cannot render on the server.\n//\n// Import path: '@paramms/chat-widget/react'\n//\n// Two components:\n// ChatWidget — general support chat (hotel, SaaS, helpdesk, etc.)\n// MarketplaceChat — one thread per listing (used cars, rentals, etc.)\n//\n// Both: only url + profileId are required. userId is always optional —\n// anonymous guests are handled automatically via localStorage.\n\nimport { useEffect, useRef, useState } from 'react'\nimport { mount, type MountOptions, type WidgetHandle } from './index.js'\n\n// Inline SVG launcher glyphs — emoji ('💬'/'✕') render differently on every\n// OS and clash with brand accents; these are crisp and consistent everywhere.\nfunction ChatGlyph({ size = 26 }: { size?: number }): JSX.Element {\n return (\n <svg viewBox=\"0 0 24 24\" width={size} height={size} fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\" aria-hidden=\"true\">\n <path\n d=\"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z\"\n fill=\"currentColor\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\"\n />\n </svg>\n )\n}\nfunction CloseGlyph({ size = 22 }: { size?: number }): JSX.Element {\n return (\n <svg viewBox=\"0 0 24 24\" width={size} height={size} fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\" aria-hidden=\"true\">\n <path d=\"M18 6 6 18M6 6l12 12\" stroke=\"currentColor\" strokeWidth=\"2.5\" strokeLinecap=\"round\" />\n </svg>\n )\n}\n\n// ── Shared base props ─────────────────────────────────────────────────────────\n\ninterface BaseProps {\n /** Relay URL — set as NEXT_PUBLIC_RELAY_URL in .env. Any scheme works:\n * `https://api.example.com` is fine. The WebSocket URL and REST base are\n * derived automatically — you do NOT need to pass `wss://` or `/ws`. */\n url: string\n /** HTTP(S) base for REST calls — only when the REST API is on a different\n * origin than the socket. Normally omit. */\n apiUrl?: string\n /** Your Relay profile ID — set as NEXT_PUBLIC_RELAY_PROFILE_ID in .env — required */\n profileId: string\n\n /** A signed identity token — an ES256 JWT `{sub,iat,exp}` minted by YOUR\n * backend for chatrooms with signed identity (guestPublicKey) enabled.\n * This is the production identity tier; wins over `userId`. */\n token?: string\n /** Called when a signed token expires: return a fresh token from your\n * backend to renew the session without a reload. */\n refreshToken?: () => Promise<string | null>\n /** Your logged-in user's stable ID. When omitted the widget automatically\n * assigns a persistent anonymous ID from localStorage — no login required. */\n userId?: string\n /** Shown to agents instead of the raw user ID */\n userName?: string\n /** Shown to agents so they can follow up by email */\n userEmail?: string\n /** Avatar URL shown in the widget header and dashboard */\n userAvatar?: string\n\n /** Brand colour hex, e.g. \"#1a56db\". Defaults to the profile theme colour. */\n accent?: string\n /** Secondary accent (guest bubble + send button); follows `accent` when omitted. */\n accent2?: string\n /** Colour scheme: 'auto'|'light'|'dark'. */\n theme?: 'auto' | 'light' | 'dark'\n /** Render as a floating launcher button instead of inline */\n launcher?: boolean\n /** Launcher position — default 'bottom-right' */\n position?: 'bottom-right' | 'bottom-left'\n /** Launcher teaser (\"optional message\" above the bubble). String or\n * { title, subtitle }. Omit to use the chatroom's manifest value. */\n launcherMessage?: string | { title: string; subtitle?: string }\n /** Pre-set reply chips shown above the input */\n quickReplies?: string[]\n /** Container height when rendered inline. Default: '100%' */\n height?: string\n /** i18n string overrides for non-English sites */\n i18n?: MountOptions['i18n']\n /** Per-tenant feature switches (default all ON). Set a flag false to disable\n * reactions, CSAT, or KB deflection. */\n features?: MountOptions['features']\n /** ISO language code for auto-translating incoming messages */\n translateLang?: string\n /** Show a back chevron in the chatroom header that opens the full conversation\n * list (`ChatApp`) — turns a single-thread widget into a Channel.io-style app\n * where you can jump to any of the user's other conversations and back. */\n inbox?: boolean\n /** Inbox scope when `inbox` is set: 'tenant' (default) lists the user's threads\n * across ALL your chatrooms; 'profile' limits it to this one. */\n inboxScope?: 'tenant' | 'profile'\n}\n\n// ── ChatWidget ────────────────────────────────────────────────────────────────\n\nexport interface ChatWidgetProps extends BaseProps {\n /** Optional context card shown at the top of the chat\n * (e.g. the support ticket, booking, or order being discussed) */\n contextTitle?: string\n contextSubtitle?: string\n contextStatus?: string\n\n /** Stable item ID — pins this conversation to a specific item/thread. */\n subjectId?: string\n}\n\n/**\n * General-purpose support chat widget. Only `url` and `profileId` are required.\n * All other props are optional — anonymous guests work without any configuration.\n *\n * @example Basic support chat\n * ```tsx\n * <ChatWidget\n * url={process.env.NEXT_PUBLIC_RELAY_URL}\n * profileId={process.env.NEXT_PUBLIC_RELAY_PROFILE_ID}\n * userId={session?.user.id}\n * userName={session?.user.name}\n * userEmail={session?.user.email}\n * />\n * ```\n *\n * @example Multi-thread (tickets, bookings, orders) — one thread per subjectId\n * ```tsx\n * <ChatWidget\n * url={...} profileId={...}\n * subjectId={`ticket_${ticket.id}`}\n * contextTitle={ticket.title}\n * contextStatus={ticket.status}\n * userId={session?.user.id}\n * />\n * ```\n *\n * Need a list of the user's threads with tap-to-open? That's `<ChatApp />`\n * (inline) or `<ChatAppLauncher />` (floating bubble) — this component renders\n * a single conversation.\n */\nexport function ChatWidget({\n url, apiUrl, profileId,\n token, refreshToken,\n userId, userName, userEmail, userAvatar,\n contextTitle, contextSubtitle, contextStatus,\n subjectId,\n accent, accent2, theme, launcher, position, launcherMessage, quickReplies, height = '100%',\n i18n, features, translateLang, inbox, inboxScope,\n}: ChatWidgetProps): JSX.Element {\n const ref = useRef<HTMLDivElement>(null)\n const handleRef = useRef<WidgetHandle | null>(null)\n // When `inbox` is enabled, the header back chevron swaps this single thread\n // for the full conversation list (ChatApp). Tapping a row there opens that\n // thread in ChatApp's own stack; the widget becomes a mini messaging app.\n const [showInbox, setShowInbox] = useState(false)\n\n useEffect(() => {\n if (showInbox) return // showing the list, not the single thread\n if (!ref.current) return\n handleRef.current?.close()\n handleRef.current = mount({\n el: ref.current,\n url,\n ...(apiUrl ? { apiUrl } : {}),\n profileId,\n ...(subjectId ? { subjectId } : {}),\n ...(token ? { token } : {}),\n ...(refreshToken ? { refreshToken } : {}),\n ...(userId ? { userId } : {}),\n ...(userId || userName || userEmail || userAvatar ? {\n user: {\n ...(userName ? { name: userName } : {}),\n ...(userEmail ? { email: userEmail } : {}),\n ...(userAvatar ? { avatar: userAvatar } : {}),\n },\n } : {}),\n ...(contextTitle ? {\n subject: {\n title: contextTitle,\n ...(contextSubtitle ? { subtitle: contextSubtitle } : {}),\n ...(contextStatus ? { status: contextStatus } : {}),\n },\n } : {}),\n ...(quickReplies ? { quickReplies } : {}),\n ...(accent ? { accent } : {}),\n ...(accent2 ? { accent2 } : {}),\n ...(theme ? { theme } : {}),\n ...(translateLang ? { translateLang } : {}),\n ...(i18n ? { i18n } : {}),\n ...(features ? { features } : {}),\n ...(inbox && !launcher ? { onBack: () => setShowInbox(true) } : {}),\n ...(launcher ? { launcher, position: position ?? 'bottom-right', ...(launcherMessage ? { launcherMessage } : {}) } : {}),\n })\n return () => { handleRef.current?.close(); handleRef.current = null }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [url, apiUrl, profileId, subjectId, token, userId, userName, userEmail, accent, launcher, position, launcherMessage, translateLang, inbox, showInbox])\n\n // Inbox view: the full conversation list (its own list↔room stack). Inline\n // only — in launcher mode the chat lives in a fixed panel that mount() owns,\n // so use <ChatAppLauncher> for a launcher-with-inbox experience instead.\n if (inbox && !launcher && showInbox) {\n return (\n <ChatApp\n url={url} {...(apiUrl ? { apiUrl } : {})} profileId={profileId}\n {...(token ? { token } : {})} {...(refreshToken ? { refreshToken } : {})}\n {...(userId ? { userId } : {})} {...(userName ? { userName } : {})} {...(userEmail ? { userEmail } : {})}\n {...(accent ? { accent } : {})} scope={inboxScope ?? 'tenant'} height={height}\n onClose={() => setShowInbox(false)}\n />\n )\n }\n\n // When launcher=true, still render the div — mount() moves it inside the\n // fixed panel above the bubble. Zero size so it doesn't affect page layout.\n return (\n <div\n ref={ref}\n style={launcher ? { width: 0, height: 0, overflow: 'hidden' } : { width: '100%', height, minHeight: height === '100%' ? '480px' : undefined }}\n />\n )\n}\n\n// ── MarketplaceChat ───────────────────────────────────────────────────────────\n\nexport interface MarketplaceChatProps extends BaseProps {\n /** Unique ID for this listing — each listing gets its own thread.\n * Omit for a general (non-item-specific) conversation. */\n listingId?: string\n /** Shown at the top of the chat — e.g. \"2019 Toyota Camry SE\" */\n listingTitle?: string\n /** One-line detail — e.g. \"45,000 km · Automatic\" */\n listingMeta?: string\n /** Price shown as a tag — e.g. 12500 → \"$12,500\" */\n listingPrice?: number\n /** Status badge — e.g. \"Available\", \"Sold\", \"Pending\" */\n listingStatus?: string\n}\n\nconst DEFAULT_MARKETPLACE_REPLIES = [\n 'Is this still available?',\n 'Can I schedule a viewing?',\n 'What is your best price?',\n]\n\n/**\n * Marketplace chat widget. Two modes depending on whether `listingId` is provided:\n *\n * **With `listingId` (listing page)** — opens that listing's chat immediately.\n * No list screen. The buyer is already looking at the item so context is clear.\n * ```tsx\n * // On your listing detail page:\n * <MarketplaceChat\n * url={process.env.NEXT_PUBLIC_RELAY_URL}\n * profileId={process.env.NEXT_PUBLIC_RELAY_PROFILE_ID}\n * listingId={car.id}\n * listingTitle={car.title}\n * listingPrice={car.price}\n * listingMeta={`${car.mileage.toLocaleString()} km · ${car.gearbox}`}\n * listingStatus=\"Available\"\n * userId={session?.user.id}\n * userName={session?.user.name}\n * userEmail={session?.user.email}\n * />\n * ```\n *\n * **Without `listingId`** — opens the buyer's single general (non-listing)\n * thread with this chatroom. For a \"My Messages\" / inbox page with the\n * WhatsApp-style thread list and tap-to-open, use `<ChatApp />` (or\n * `<ChatAppLauncher />` for a floating bubble):\n * ```tsx\n * // On your /messages page:\n * <ChatApp\n * url={process.env.NEXT_PUBLIC_RELAY_URL}\n * profileId={process.env.NEXT_PUBLIC_RELAY_PROFILE_ID}\n * userId={session?.user.id}\n * />\n * ```\n *\n * Only `url` and `profileId` are required. All other props are optional.\n */\nexport function MarketplaceChat({\n url, apiUrl, profileId,\n token, refreshToken,\n listingId, listingTitle, listingMeta, listingPrice, listingStatus,\n userId, userName, userEmail, userAvatar,\n accent, accent2, theme, launcher, position, launcherMessage, quickReplies, height = '100%',\n i18n, features, translateLang, inbox, inboxScope,\n}: MarketplaceChatProps): JSX.Element {\n const ref = useRef<HTMLDivElement>(null)\n const handleRef = useRef<WidgetHandle | null>(null)\n const [showInbox, setShowInbox] = useState(false)\n\n useEffect(() => {\n if (showInbox) return\n if (!ref.current) return\n // Coalesce rapid identity changes into a SINGLE mount. NextAuth's\n // `session?.user.id` is undefined on first render and resolves a tick later,\n // which would otherwise open an anonymous conversation and immediately\n // orphan it when the real id arrives — surfacing as \"a new chat every time\".\n // Deferring the mount lets a same-tick id change settle first. For a slower\n // (network) session fetch, gate rendering on the session status host-side\n // (e.g. NextAuth: don't render until `status !== 'loading'`).\n let cancelled = false\n const timer = setTimeout(() => {\n if (cancelled || !ref.current) return\n handleRef.current?.close()\n handleRef.current = mount({\n el: ref.current,\n url,\n ...(apiUrl ? { apiUrl } : {}),\n profileId,\n ...(listingId ? { subjectId: `listing_${listingId}` } : {}),\n ...(token ? { token } : {}),\n ...(refreshToken ? { refreshToken } : {}),\n ...(userId ? { userId } : {}),\n ...(userId || userName || userEmail || userAvatar ? {\n user: {\n ...(userName ? { name: userName } : {}),\n ...(userEmail ? { email: userEmail } : {}),\n ...(userAvatar ? { avatar: userAvatar } : {}),\n ...(listingId ? { meta: { listingId } } : {}),\n },\n } : {}),\n ...(listingTitle ? {\n subject: {\n title: listingTitle,\n ...(listingMeta ? { subtitle: listingMeta } : {}),\n ...(listingPrice ? { tags: [`$${listingPrice.toLocaleString()}`] } : {}),\n ...(listingStatus ? { status: listingStatus } : {}),\n },\n } : {}),\n quickReplies: quickReplies ?? DEFAULT_MARKETPLACE_REPLIES,\n ...(accent ? { accent } : {}),\n ...(accent2 ? { accent2 } : {}),\n ...(theme ? { theme } : {}),\n ...(translateLang ? { translateLang } : {}),\n ...(i18n ? { i18n } : {}),\n ...(features ? { features } : {}),\n ...(inbox && !launcher ? { onBack: () => setShowInbox(true) } : {}),\n ...(launcher ? { launcher, position: position ?? 'bottom-right', ...(launcherMessage ? { launcherMessage } : {}) } : {}),\n })\n }, 0)\n return () => { cancelled = true; clearTimeout(timer); handleRef.current?.close(); handleRef.current = null }\n // Only identity/target-affecting props trigger a remount — metadata like\n // userName/userEmail is sent once at mount and must NOT churn the connection.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [url, apiUrl, profileId, listingId, token, userId, accent, launcher, position, launcherMessage, translateLang, inbox, showInbox])\n\n if (inbox && !launcher && showInbox) {\n return (\n <ChatApp\n url={url} {...(apiUrl ? { apiUrl } : {})} profileId={profileId}\n {...(token ? { token } : {})} {...(refreshToken ? { refreshToken } : {})}\n {...(userId ? { userId } : {})} {...(userName ? { userName } : {})} {...(userEmail ? { userEmail } : {})}\n {...(accent ? { accent } : {})} scope={inboxScope ?? 'tenant'} height={height}\n onClose={() => setShowInbox(false)}\n />\n )\n }\n\n // When launcher=true, still render the div — mount() moves it inside the\n // fixed panel above the bubble. Zero size so it doesn't affect page layout.\n return (\n <div\n ref={ref}\n style={launcher ? { width: 0, height: 0, overflow: 'hidden' } : { width: '100%', height, minHeight: height === '100%' ? '480px' : undefined }}\n />\n )\n}\n\n// ── ChatList ──────────────────────────────────────────────────────────────────\n\n/** Live viewport breakpoint — updates on resize/rotation via matchMedia,\n * never a one-shot read (a one-shot read leaves layouts stuck after the\n * user rotates their phone or resizes across the breakpoint). SSR-safe. */\nfunction useIsMobile(maxWidthPx: number): boolean {\n const [mobile, setMobile] = useState(\n typeof window !== 'undefined' && window.innerWidth <= maxWidthPx,\n )\n useEffect(() => {\n if (typeof window === 'undefined' || !window.matchMedia) return\n const mq = window.matchMedia(`(max-width: ${maxWidthPx}px)`)\n const onChange = (e: MediaQueryListEvent): void => setMobile(e.matches)\n setMobile(mq.matches)\n mq.addEventListener('change', onChange)\n return () => mq.removeEventListener('change', onChange)\n }, [maxWidthPx])\n return mobile\n}\n\nexport interface ChatAppProps {\n /** Relay URL — ONE url, any scheme; `https://api.relay.paramms.com` is the\n * recommended form. The WebSocket URL and REST base are derived from it —\n * you do NOT need to pass `wss://` or `/ws`. */\n url: string\n /** HTTP(S) base for REST calls — only when the REST API is on a different\n * origin than the socket. Normally omit.\n * @deprecated pass a single `url`; kept for back-compat. */\n apiUrl?: string\n /** A chatroom id. Provide `profileId` OR `tenantId` (see below). When both\n * are given, profileId also fixes where the ✎ \"new conversation\" opens. */\n profileId?: string\n /** Tenant-level identification — the natural fit for a chat app: lists\n * EVERY conversation this user has with your business across ALL of its\n * chatrooms, without naming one. Use this when the platform runs several\n * chatrooms under one tenant (e.g. a marketplace chatroom for\n * `<MarketplaceChat/>` pages PLUS a general-support chatroom) — the inbox\n * shows both, and each row opens against its own chatroom. The ✎ compose\n * button opens the tenant's default chatroom (its oldest, as reported by\n * the server). */\n tenantId?: string\n /** A signed identity token (ES256 JWT) for chatrooms with signed identity\n * enabled — the production tier. Wins over `userId`. */\n token?: string\n /** Return a fresh token when a signed token expires. */\n refreshToken?: () => Promise<string | null>\n /** Your logged-in user's stable ID. Omit for anonymous (uses localStorage UID) */\n userId?: string\n /** Optional: shown to agents in the dashboard */\n userName?: string\n /** Optional: shown to agents in the dashboard */\n userEmail?: string\n /** Which conversations the list shows when configured with a profileId\n * (default 'tenant'; irrelevant with `tenantId`, which is always\n * tenant-wide):\n * 'tenant' — every conversation this user has with the business that\n * owns `profileId`, across ALL of its chatrooms — like a real\n * messaging app. Each row opens against its own chatroom.\n * 'profile' — only this chatroom's threads (the pre-1.0.30 behaviour).\n * Tenancy note: guests never see or send tenant ids — the server resolves\n * the tenant FROM the profileId, so `profileId` stays the only id you\n * configure. */\n scope?: 'profile' | 'tenant'\n /** Brand colour hex — default '#6c5ce7' */\n accent?: string\n theme?: 'auto' | 'light' | 'dark'\n /** Container height. Default: '100%' */\n height?: string\n /** When provided, ChatApp renders an always-visible close (✕) control in the\n * top-right corner of its container. Pass this whenever ChatApp is shown in\n * an overlay/panel or as a mobile-fullscreen surface (ChatAppLauncher wires\n * it automatically) so there is a reliable way OUT — without it, an inline\n * fullscreen panel on a phone (no Escape key, no reachable backdrop) traps\n * the user. Omit for a bare inline embed the host chromes itself. */\n onClose?: () => void\n /** i18n overrides */\n i18n?: import('./chatlist.js').ChatListOptions['i18n']\n}\n\n/**\n * Full chat-app component: conversation list on the left (or full screen on\n * mobile), chat room on the right when a thread is selected — like a\n * standalone messaging app. Tapping a thread opens the chat inline; the ✎\n * button starts a new conversation with the business.\n *\n * By default (`scope=\"tenant\"`) the list shows EVERY conversation this user\n * has with the business that owns `profileId` — across all of its chatrooms —\n * and each row opens against its own chatroom. Pass `scope=\"profile\"` to\n * limit it to one chatroom's threads.\n *\n * Identify at either level:\n * • `tenantId` — the natural fit for a chat app. A platform often runs\n * SEVERAL chatrooms under one business (a marketplace chatroom for\n * `<MarketplaceChat/>` pages plus a general-support chatroom, …); with\n * `tenantId` the inbox shows the user's chats with all of them, no\n * profileId needed. Compose opens the tenant's default chatroom.\n * • `profileId` — any one of the business's chatrooms; still lists\n * tenant-wide by default (`scope=\"tenant\"`), and fixes where compose\n * opens.\n *\n * @example\n * ```tsx\n * 'use client'\n * import { ChatApp } from '@paramms/chat-widget/react'\n *\n * export default function MessagesPage({ session }) {\n * return (\n * <div style={{ height: '100vh' }}>\n * <ChatApp\n * url={process.env.NEXT_PUBLIC_RELAY_URL}\n * tenantId={process.env.NEXT_PUBLIC_RELAY_TENANT_ID} // or profileId={…}\n * userId={session?.user.id}\n * userName={session?.user.name}\n * userEmail={session?.user.email}\n * />\n * </div>\n * )\n * }\n * ```\n */\nexport function ChatApp({\n url, apiUrl, profileId, tenantId, token, refreshToken, userId, userName, userEmail,\n accent, theme, height = '100%', i18n, onClose,\n scope = 'tenant',\n}: ChatAppProps): JSX.Element {\n const misconfigured = !profileId && !tenantId\n type Entry = import('./chatlist.js').ChatListEntry\n const [selected, setSelected] = useState<Entry | null>(null)\n /** The conversation-list module failed to load — show why instead of an\n * empty panel. */\n const [listError, setListError] = useState(false)\n const listRef = useRef<HTMLDivElement>(null)\n const chatRef = useRef<HTMLDivElement>(null)\n const handleRef = useRef<import('./chatlist.js').ChatListHandle | null>(null)\n const chatHandle = useRef<WidgetHandle | null>(null)\n\n // Build the chat list\n useEffect(() => {\n if (!listRef.current) return\n let cancelled = false\n import('./chatlist.js').catch((e: unknown) => {\n // This promise had no rejection handler at all: if the chunk failed to\n // load (CSP, a 404 on the split chunk, an offline navigation) the list\n // silently never mounted and the host saw an empty white panel with\n // nothing but an unhandled rejection in the console.\n console.error('[relay] could not load the conversation list module.', e)\n if (!cancelled) setListError(true)\n return null\n }).then((mod) => {\n if (!mod) return\n const { mountChatList } = mod\n // The dynamic import is async: if the effect was cleaned up (unmount,\n // dep change, or StrictMode's double-invoke) before it resolved, or the\n // ref is gone, don't mount a phantom list that never gets closed.\n if (cancelled || !listRef.current) return\n handleRef.current = mountChatList({\n el: listRef.current,\n url,\n ...(apiUrl ? { apiUrl } : {}),\n ...(profileId ? { profileId } : {}),\n ...(tenantId ? { tenantId } : {}),\n ...(theme ? { theme } : {}),\n scope,\n // We overlay a ✕ at top-right when `onClose` is given — tell the list to\n // keep its header clear so the ✕ doesn't land on the ✎ compose button.\n ...(onClose ? { reserveCloseSpace: true } : {}),\n onSelect: (entry) => setSelected(entry),\n // Compose (✎) opens the chatroom's general support thread — without\n // this a user with no conversations yet had an empty list and no way\n // to ever start one, which is what made ChatApp feel broken.\n // Compose target: the configured chatroom, else the tenant's default\n // (oldest chatroom, reported by the server on the first list fetch).\n onNewChat: () => {\n const target = handleRef.current?.defaultProfileId()\n if (!target) return // list hasn't loaded yet — nothing sane to open\n setSelected({ id: '__new__', profileId: target, state: 'open', updatedAt: Date.now() })\n },\n ...(token ? { token } : {}),\n ...(userId ? { userId } : {}),\n ...(accent ? { accent } : {}),\n ...(i18n ? { i18n } : {}),\n })\n })\n return () => { cancelled = true; handleRef.current?.close(); handleRef.current = null }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [url, apiUrl, profileId, tenantId, token, userId, scope])\n\n // Open a ChatWidget when a thread is selected.\n //\n // Two correctness details here:\n // • identity: `userId` goes through as userId (the host-vouched tier) and\n // signed JWTs as `token` — the same tiers as every other component. It\n // used to conflate them (`token: userId`), which worked only by the\n // accident that mount() folds userId into the token, and left no way to\n // pass a REAL signed token at all.\n // • chatroom: the row's OWN profileId wins. With scope='tenant' the list\n // spans every chatroom of the business, so opening against the mounted\n // profileId would find-or-create a DIFFERENT conversation.\n useEffect(() => {\n if (!chatRef.current || !selected) return\n chatHandle.current?.close()\n chatHandle.current = mount({\n el: chatRef.current,\n url,\n ...(apiUrl ? { apiUrl } : {}),\n profileId: (selected.profileId ?? profileId)!, // rows always carry theirs; compose sets one explicitly\n // DM rows open as direct conversations (kind + peer). Opening them via\n // their dm:… subjectId only works for the participant that OWNS the\n // thread key — the other side would silently fork a duplicate.\n ...(selected.kind === 'direct' && selected.peerId\n ? { kind: 'direct' as const, peerId: selected.peerId }\n : selected.subjectId ? { subjectId: selected.subjectId } : {}),\n ...(token ? { token } : {}),\n ...(refreshToken ? { refreshToken } : {}),\n ...(userId ? { userId } : {}),\n ...(userId || userName || userEmail ? {\n user: {\n ...(userName ? { name: userName } : {}),\n ...(userEmail ? { email: userEmail } : {}),\n },\n } : {}),\n ...(selected.subjectTitle ? {\n subject: {\n title: selected.subjectTitle,\n ...(selected.subjectMeta ? { subtitle: selected.subjectMeta } : {}),\n },\n } : {}),\n ...(accent ? { accent } : {}),\n // Stack navigation: the chatroom's back chevron returns to the list.\n onBack: () => setSelected(null),\n })\n // Keep the list fresh: opening a chat marks it read, and replies received\n // while a chat is open should update its row's preview/ordering.\n const listTimer = setInterval(() => handleRef.current?.refresh(), 20_000)\n return () => {\n clearInterval(listTimer)\n chatHandle.current?.close(); chatHandle.current = null\n // Refresh once on the way out so the row reflects what just happened.\n handleRef.current?.refresh()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [selected?.id])\n\n // (After all hooks — React requires unconditional hook order.)\n if (misconfigured) {\n return (\n <div style={{ padding: 16, font: '13px system-ui', color: '#b91c1c', background: '#fef2f2', borderRadius: 8 }}>\n [relay] &lt;ChatApp/&gt; needs a <code>profileId</code> or a <code>tenantId</code>.\n </div>\n )\n }\n\n // Stack navigation, like a native messaging app: show the LIST, and when a\n // conversation is tapped, push the CHATROOM over it (full surface); the\n // chatroom's own header carries the back chevron (wired via mount's onBack)\n // that pops back to the list. No two-pane \"select a conversation\" dead space —\n // that only ever made sense on a very wide desktop inbox, and read as broken\n // in the launcher panel / on mobile, which is how this is actually used.\n return (\n <div style={{ position: 'relative', width: '100%', height, minHeight: '400px', overflow: 'hidden', background: '#fff' }}>\n {onClose && !selected && (\n <button\n onClick={onClose}\n aria-label={i18n?.close ?? 'Close'}\n style={{\n position: 'absolute', top: 8, right: 8, zIndex: 20,\n width: 32, height: 32, borderRadius: '50%',\n display: 'flex', alignItems: 'center', justifyContent: 'center',\n background: 'rgba(0,0,0,.05)', border: 'none', color: '#1c1b1a',\n fontSize: 18, lineHeight: 1, cursor: 'pointer',\n }}\n >\n <CloseGlyph size={18} />\n </button>\n )}\n\n {/* List — kept mounted (just hidden) so its scroll position, search text\n and live unread counts survive a round-trip into a chatroom. */}\n <div style={{\n position: 'absolute', inset: 0,\n display: selected ? 'none' : 'flex', flexDirection: 'column',\n }}>\n {listError\n ? (\n <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', width: '100%', height: '100%', padding: 16, font: '13px system-ui', color: '#b91c1c', textAlign: 'center' }}>\n {i18n?.error ?? 'Could not load conversations.'}\n </div>\n )\n : <div ref={listRef} style={{ width: '100%', height: '100%' }} />}\n </div>\n\n {/* Chatroom — only present while a conversation is selected. */}\n {selected && (\n <div style={{ position: 'absolute', inset: 0, display: 'flex', flexDirection: 'column' }}>\n <div ref={chatRef} style={{ width: '100%', height: '100%' }} />\n </div>\n )}\n </div>\n )\n}\n\n// ── ChatAppLauncher ───────────────────────────────────────────────────────────\n\nexport interface ChatAppLauncherProps {\n /** Relay URL — ONE url, any scheme; `https://api.relay.paramms.com` is the\n * recommended form. The WebSocket URL and REST base are derived from it. */\n url: string\n /** HTTP(S) base for REST calls — only when REST is on a different origin.\n * @deprecated pass a single `url`; kept for back-compat. */\n apiUrl?: string\n /** A chatroom id. Provide `profileId` OR `tenantId`. */\n profileId?: string\n /** Tenant-level identification — the panel lists EVERY conversation this\n * user has with your business across ALL of its chatrooms (see\n * ChatAppProps.tenantId). The ✎ compose opens the tenant's default\n * chatroom. */\n tenantId?: string\n /** A signed identity token (ES256 JWT) for chatrooms with signed identity\n * enabled — the production tier. Wins over `userId`. */\n token?: string\n /** Return a fresh token when a signed token expires. */\n refreshToken?: () => Promise<string | null>\n /** Your logged-in user's stable ID */\n userId?: string\n userName?: string\n userEmail?: string\n /** Which conversations the panel's list shows — see ChatAppProps.scope.\n * Default 'tenant': every conversation this user has with the business. */\n scope?: 'profile' | 'tenant'\n /** Brand colour hex — default '#6c5ce7' */\n accent?: string\n\n /** true → floating bubble fixed to the corner of the screen (like Intercom)\n * false → an inline \"Messages\" button that expands a panel below it\n * Default: true */\n floating?: boolean\n /** Only used when floating=true. Default: 'bottom-right' */\n position?: 'bottom-right' | 'bottom-left'\n /** Label shown on the button. Default: a chat-bubble icon for floating,\n * 'Messages' for inline. */\n label?: string\n /** Width of the chat panel. Default: '420px' (floating) or '100%' (inline) */\n panelWidth?: string\n /** Height of the chat panel. Default: '600px' */\n panelHeight?: string\n}\n\n/**\n * A button that opens the full ChatApp (list → chat) in a panel.\n *\n * floating=true → fixed bubble in the corner of the screen, like WhatsApp Web's\n * chat button or Intercom.\n * floating=false → an inline button (e.g. in your nav bar) that expands a panel\n * below it.\n *\n * @example Floating bubble (bottom-right)\n * ```tsx\n * <ChatAppLauncher\n * url={process.env.NEXT_PUBLIC_RELAY_URL}\n * profileId={process.env.NEXT_PUBLIC_RELAY_PROFILE_ID}\n * userId={session?.user.id}\n * floating\n * position=\"bottom-right\"\n * />\n * ```\n *\n * @example Inline nav button\n * ```tsx\n * <ChatAppLauncher\n * url={process.env.NEXT_PUBLIC_RELAY_URL}\n * profileId={process.env.NEXT_PUBLIC_RELAY_PROFILE_ID}\n * userId={session?.user.id}\n * floating={false}\n * label=\"Messages\"\n * />\n * ```\n */\nexport function ChatAppLauncher({\n url, apiUrl, profileId, tenantId, token, refreshToken, userId, userName, userEmail,\n scope,\n accent = '#6c5ce7',\n floating = true,\n position = 'bottom-right',\n label,\n panelWidth,\n panelHeight = '600px',\n}: ChatAppLauncherProps): JSX.Element {\n const [open, setOpen] = useState(false)\n const btnRef = useRef<HTMLButtonElement>(null)\n\n const isRight = position === 'bottom-right'\n // Floating default is the inline SVG chat glyph (see ChatGlyph note); a\n // custom `label` string still wins. Inline mode defaults to a text label.\n const btnLabel = label ?? (floating ? undefined : 'Messages')\n const isMobile = useIsMobile(479)\n\n // Close on Escape\n useEffect(() => {\n const handler = (e: KeyboardEvent) => { if (e.key === 'Escape') setOpen(false) }\n document.addEventListener('keydown', handler)\n return () => document.removeEventListener('keydown', handler)\n }, [])\n\n // ── Floating mode ──────────────────────────────────────────────────────────\n if (floating) {\n // Mobile (<480px): the panel must be its OWN fixed fullscreen layer\n // (inset:0). Sizing it 100vw INSIDE the bottom-right wrapper — as it used\n // to — anchored its right edge 20px in from the viewport, pushing the\n // whole app 20px off-screen. The bubble wrapper stays above it (z 9999\n // vs 9998) so the ✕ keeps working as the close control. Live breakpoint:\n // rotating the phone re-lays-out.\n return (\n <div style={{\n position: 'fixed',\n [isRight ? 'right' : 'left']: '20px',\n bottom: '20px',\n zIndex: 9999,\n display: 'flex',\n flexDirection: 'column',\n alignItems: isRight ? 'flex-end' : 'flex-start',\n gap: '12px',\n }}>\n {/* Panel */}\n <div style={{\n ...(isMobile ? {\n position: 'fixed' as const, inset: 0,\n width: '100%', height: '100dvh', borderRadius: '0', zIndex: 9998,\n } : {\n width: `min(${panelWidth ?? '420px'}, calc(100vw - 40px))`,\n height: `min(${panelHeight}, calc(100dvh - 108px))`,\n borderRadius: '28px',\n }),\n overflow: 'hidden',\n boxShadow: isMobile ? 'none' : '0 12px 32px rgba(108,92,231,.14)',\n background: '#fff',\n display: open ? 'flex' : 'none',\n flexDirection: 'column',\n transformOrigin: `bottom ${isRight ? 'right' : 'left'}`,\n animation: open ? 'ocl-pop-in .18s ease' : 'none',\n }}>\n <ChatApp\n url={url} {...(apiUrl ? { apiUrl } : {})}\n {...(profileId ? { profileId } : {})}\n {...(tenantId ? { tenantId } : {})}\n {...(token ? { token } : {})}\n {...(refreshToken ? { refreshToken } : {})}\n {...(userId ? { userId } : {})}\n {...(userName ? { userName } : {})}\n {...(userEmail ? { userEmail } : {})}\n {...(scope ? { scope } : {})}\n accent={accent} height=\"100%\"\n onClose={() => setOpen(false)}\n />\n </div>\n\n {/* Bubble button. On a fullscreen mobile panel the bubble sits at\n bottom-right ON TOP of the message composer/send button, so hide it\n while open on mobile — the in-panel top-right ✕ is the close there. */}\n <button\n ref={btnRef}\n onClick={() => setOpen(o => !o)}\n aria-label={open ? 'Close chat' : (typeof btnLabel === 'string' ? btnLabel : 'Open chat')}\n aria-expanded={open}\n style={{\n width: '56px', height: '56px', borderRadius: '50%',\n background: accent, color: '#fff', border: 'none',\n fontSize: '20px', cursor: 'pointer', flexShrink: 0,\n boxShadow: '0 12px 32px rgba(108,92,231,.14)',\n transition: 'transform .15s',\n alignItems: 'center', justifyContent: 'center',\n display: (open && isMobile) ? 'none' : 'flex',\n }}\n onMouseEnter={e => { (e.currentTarget as HTMLElement).style.transform = 'scale(1.08)' }}\n onMouseLeave={e => { (e.currentTarget as HTMLElement).style.transform = 'scale(1)' }}\n >\n {open ? <CloseGlyph /> : (label ?? <ChatGlyph />)}\n </button>\n\n <style>{`@keyframes ocl-pop-in { from { opacity:0; transform:scale(.95) } to { opacity:1; transform:scale(1) } }`}</style>\n </div>\n )\n }\n\n // ── Inline mode ────────────────────────────────────────────────────────────\n // The panel is rendered via a fixed overlay anchored to the button position.\n // This prevents clipping from parent overflow:hidden containers (e.g. nav bars).\n // On mobile the anchored popover can't fit — it goes fullscreen instead\n // (the backdrop still closes it).\n const pWidth = `min(${panelWidth ?? '420px'}, calc(100vw - 16px))`\n\n // Track button position for panel anchor\n const [btnRect, setBtnRect] = useState<DOMRect | null>(null)\n\n const handleBtnClick = () => {\n if (!open && btnRef.current) setBtnRect(btnRef.current.getBoundingClientRect())\n setOpen(o => !o)\n }\n\n const panelTop = btnRect ? btnRect.bottom + 8 : 0\n // Clamp so a button near the left edge can't push the panel off-screen.\n const panelRight = btnRect ? Math.max(8, window.innerWidth - btnRect.right) : 0\n\n return (\n <>\n {/* Trigger button */}\n <button\n ref={btnRef}\n onClick={handleBtnClick}\n style={{\n display: 'inline-flex', alignItems: 'center', gap: '6px',\n padding: '8px 16px', borderRadius: '8px',\n background: open ? accent : 'transparent',\n color: open ? '#fff' : accent,\n border: `2px solid ${accent}`,\n fontSize: '14px', fontWeight: 600, cursor: 'pointer',\n transition: 'background .15s, color .15s',\n }}\n >\n <ChatGlyph size={16} /> {btnLabel}\n </button>\n\n {/* Fixed panel — rendered at document root level via CSS fixed positioning */}\n {open && btnRect && (\n <>\n {/* Backdrop */}\n <div\n onClick={() => setOpen(false)}\n style={{ position: 'fixed', inset: 0, zIndex: 9998 }}\n />\n <div style={{\n position: 'fixed',\n ...(isMobile ? {\n inset: 0, width: '100%', height: '100dvh', borderRadius: '0',\n } : {\n top: panelTop,\n right: panelRight,\n width: pWidth,\n height: `min(${panelHeight}, calc(100dvh - ${panelTop}px - 12px))`,\n borderRadius: '28px',\n }),\n overflow: 'hidden',\n boxShadow: isMobile ? 'none' : '0 12px 32px rgba(108,92,231,.14)',\n background: '#fff',\n zIndex: 9999,\n animation: 'ocl-slide-in .18s ease',\n }}>\n <ChatApp\n url={url} {...(apiUrl ? { apiUrl } : {})}\n {...(profileId ? { profileId } : {})}\n {...(tenantId ? { tenantId } : {})}\n {...(token ? { token } : {})}\n {...(refreshToken ? { refreshToken } : {})}\n {...(userId ? { userId } : {})}\n {...(userName ? { userName } : {})}\n {...(userEmail ? { userEmail } : {})}\n {...(scope ? { scope } : {})}\n accent={accent} height=\"100%\"\n onClose={() => setOpen(false)}\n />\n </div>\n <style>{`@keyframes ocl-slide-in { from { opacity:0; transform:translateY(-8px) } to { opacity:1; transform:translateY(0) } }`}</style>\n </>\n )}\n </>\n )\n}\n"],"names":["ChatGlyph","size","jsx","CloseGlyph","ChatWidget","url","apiUrl","profileId","token","refreshToken","userId","userName","userEmail","userAvatar","contextTitle","contextSubtitle","contextStatus","subjectId","accent","accent2","theme","launcher","position","launcherMessage","quickReplies","height","i18n","features","translateLang","inbox","inboxScope","ref","useRef","handleRef","showInbox","setShowInbox","useState","useEffect","_a","mount","ChatApp","DEFAULT_MARKETPLACE_REPLIES","MarketplaceChat","listingId","listingTitle","listingMeta","listingPrice","listingStatus","cancelled","timer","useIsMobile","maxWidthPx","mobile","setMobile","mq","onChange","e","tenantId","onClose","scope","misconfigured","selected","setSelected","listError","setListError","listRef","chatRef","chatHandle","mod","mountChatList","entry","target","listTimer","_b","jsxs","ChatAppLauncher","floating","label","panelWidth","panelHeight","open","setOpen","btnRef","isRight","btnLabel","isMobile","handler","o","pWidth","btnRect","setBtnRect","handleBtnClick","panelTop","panelRight","Fragment"],"mappings":";;;AAmBA,SAASA,EAAU,EAAE,MAAAC,IAAO,MAAsC;AAChE,SACE,gBAAAC,EAAC,OAAA,EAAI,SAAQ,aAAY,OAAOD,GAAM,QAAQA,GAAM,MAAK,QAAO,OAAM,8BAA6B,eAAY,QAC7G,UAAA,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,GAAE;AAAA,MACF,MAAK;AAAA,MAAe,QAAO;AAAA,MAAe,aAAY;AAAA,MAAI,eAAc;AAAA,MAAQ,gBAAe;AAAA,IAAA;AAAA,EAAA,GAEnG;AAEJ;AACA,SAASC,EAAW,EAAE,MAAAF,IAAO,MAAsC;AACjE,SACE,gBAAAC,EAAC,OAAA,EAAI,SAAQ,aAAY,OAAOD,GAAM,QAAQA,GAAM,MAAK,QAAO,OAAM,8BAA6B,eAAY,QAC7G,UAAA,gBAAAC,EAAC,QAAA,EAAK,GAAE,wBAAuB,QAAO,gBAAe,aAAY,OAAM,eAAc,QAAA,CAAQ,EAAA,CAC/F;AAEJ;AA4GO,SAASE,EAAW;AAAA,EACzB,KAAAC;AAAA,EAAK,QAAAC;AAAA,EAAQ,WAAAC;AAAA,EACb,OAAAC;AAAA,EAAO,cAAAC;AAAA,EACP,QAAAC;AAAA,EAAQ,UAAAC;AAAA,EAAU,WAAAC;AAAA,EAAW,YAAAC;AAAA,EAC7B,cAAAC;AAAA,EAAc,iBAAAC;AAAA,EAAiB,eAAAC;AAAA,EAC/B,WAAAC;AAAA,EACA,QAAAC;AAAA,EAAQ,SAAAC;AAAA,EAAS,OAAAC;AAAA,EAAO,UAAAC;AAAA,EAAU,UAAAC;AAAA,EAAU,iBAAAC;AAAA,EAAiB,cAAAC;AAAA,EAAc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,QAAAA,EAAA,IAAc,CAAA;AAAA,UAChC,GAAIC,IAAY,EAAE,UAAAA,EAAA,IAAc,CAAA;AAAA,UAChC,GAAIC,IAAY,EAAE,WAAAA,EAAA,IAAc,CAAA;AAAA,UAChC,GAAI+C,IAAY,EAAE,OAAAA,EAAA,IAAc,CAAA;AAAA,UACjC,QAAAzC;AAAA,UAAgB,QAAO;AAAA,UACvB,SAAS,MAAM+D,EAAQ,EAAK;AAAA,QAAA;AAAA,MAAA,GAEhC;AAAA,MACA,gBAAA/E,EAAC,WAAO,UAAA,uHAAA,CAAuH;AAAA,IAAA,EAAA,CACjI;AAAA,EAAA,GAEJ;AAEJ;"}
@@ -1,4 +1,3 @@
1
- import type { AnnotationStroke } from './protocol/index.js';
2
1
  import type { ChatStore } from './store.js';
3
2
  export interface WidgetConfig {
4
3
  subject?: {
@@ -10,6 +9,12 @@ export interface WidgetConfig {
10
9
  };
11
10
  quickReplies?: string[];
12
11
  accent?: string;
12
+ /** Secondary accent — the guest's OWN bubble + send button. Defaults to the
13
+ * design blue; if omitted while `accent` is set, follows `accent` so a single
14
+ * accent override re-themes cohesively. */
15
+ accent2?: string;
16
+ /** Colour scheme: auto (follow OS, default), or force light/dark. */
17
+ theme?: 'auto' | 'light' | 'dark';
13
18
  /** Identified user info — shown as the guest avatar/name in the widget header. */
14
19
  userInfo?: {
15
20
  name?: string;
@@ -21,6 +26,11 @@ export interface WidgetConfig {
21
26
  send?: string;
22
27
  offline?: string;
23
28
  poweredBy?: string;
29
+ online?: string;
30
+ away?: string;
31
+ aiAssistant?: string;
32
+ resolved?: string;
33
+ reopen?: string;
24
34
  };
25
35
  }
26
36
  export interface RendererHandlers {
@@ -34,8 +44,6 @@ export interface RendererHandlers {
34
44
  onLoadMore?(): void;
35
45
  onEdit?(messageId: string, newText: string): void;
36
46
  onDelete?(messageId: string): void;
37
- /** Co-browsing: a freehand stroke was completed on the shared whiteboard. */
38
- onAnnotate?(stroke: Omit<AnnotationStroke, 'by'>): void;
39
47
  /** Pre-chat qualification submitted (values keyed by field; topic/callback included). */
40
48
  onPreChat?(values: {
41
49
  name?: string;
@@ -46,8 +54,6 @@ export interface RendererHandlers {
46
54
  }): void;
47
55
  /** KB deflection: the guest is typing their FIRST message — look up articles. */
48
56
  onDeflectQuery?(q: string): void;
49
- /** Co-browsing: clear the shared whiteboard for everyone. */
50
- onAnnotateClear?(): void;
51
57
  /** Translate a message's text for display. Return null if unavailable —
52
58
  * the renderer shows a brief "unavailable" hint and leaves the original. */
53
59
  onTranslate?(text: string): Promise<string | null>;
@@ -73,6 +79,8 @@ export declare class Renderer {
73
79
  private readonly formHost;
74
80
  private readonly csatPanel;
75
81
  private readonly awayNotice;
82
+ private readonly headStatus;
83
+ private readonly reopenBtn;
76
84
  private readonly preChatPanel;
77
85
  private readonly deflectPanel;
78
86
  private preChatBuilt;
@@ -89,14 +97,8 @@ export declare class Renderer {
89
97
  private readonly sendBtn;
90
98
  /** Container-driven responsive sizing — toggles .ocw-compact (see CSS note). */
91
99
  private compactObserver;
92
- private readonly cobrowseBtn;
93
- private readonly cobrowseCanvas;
94
- private readonly cobrowseToolbar;
95
- private readonly cobrowseHint;
96
- private cobrowseActive;
97
- private cobrowseColor;
98
- private lastAnnotationVersion;
99
100
  private storeRef;
101
+ private readonly cfgAccent2;
100
102
  private scrollCleanup;
101
103
  /** Returns the scroll container so history.ts can attach scroll listeners. */
102
104
  getScrollEl(): HTMLElement | null;
@@ -130,13 +132,6 @@ export declare class Renderer {
130
132
  /** Whether the subject card (server Subject entity, mount config fallback)
131
133
  * has been built — built once when data first arrives. */
132
134
  private subjectBuilt;
133
- private updateCobrowseUI;
134
- private resizeCobrowseCanvas;
135
- /** Draw a stroke whose points are normalized to 0..1, scaled to the current
136
- * canvas size — so strokes line up across different viewport sizes. */
137
- private drawStroke;
138
- private redrawCobrowse;
139
- private bindCobrowsePointerEvents;
140
135
  private buildSubjectCard;
141
136
  private chipEl;
142
137
  /** In-widget confirmation modal (replaces window.confirm). */
@@ -0,0 +1 @@
1
+ export declare const CSS: string;
package/dist/store.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ServerFrame, Message, ManifestAction, MessageContent, ConversationId, UserId, Subject, AnnotationStroke } from './protocol/index.js';
1
+ import type { ServerFrame, Message, ManifestAction, MessageContent, ConversationId, UserId, Subject } from './protocol/index.js';
2
2
  export type SendStatus = 'pending' | 'sent' | 'delivered' | 'read';
3
3
  export interface RenderMessage extends Message {
4
4
  clientMsgId?: string;
@@ -30,10 +30,6 @@ export declare class ChatStore {
30
30
  whiteLabel: boolean;
31
31
  readonly typing: Set<string>;
32
32
  readonly online: Set<string>;
33
- /** Co-browsing: shared whiteboard strokes for this conversation. */
34
- annotations: AnnotationStroke[];
35
- /** Bumped on any annotation change so the renderer can cheaply detect updates. */
36
- annotationVersion: number;
37
33
  /** Live sentiment of the guest's latest message (agent-side only). */
38
34
  sentiment: 'positive' | 'neutral' | 'frustrated' | undefined;
39
35
  sentimentScore: number | undefined;
@@ -0,0 +1,4 @@
1
+ /** Light-mode token declarations for a prefix ('ocw' | 'ocl'), incl. font tokens. */
2
+ export declare function lightTokens(prefix: string): string;
3
+ /** Dark-mode token overrides for a prefix (fonts are unchanged in dark). */
4
+ export declare function darkTokens(prefix: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paramms/chat-widget",
3
- "version": "1.0.44",
3
+ "version": "1.0.45",
4
4
  "description": "Embeddable real-time chat widget for the Relay platform",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "type": "module",
21
21
  "scripts": {
22
- "build": "vite build && vite build --config vite.embed.config.ts && tsc -p tsconfig.json --emitDeclarationOnly && node build-preview.js && node scripts/verify-pack.mjs",
22
+ "build": "vite build && vite build --config vite.embed.config.ts && vite build --config vite.embed-lite.config.ts && tsc -p tsconfig.json --emitDeclarationOnly && node build-preview.js && node scripts/verify-pack.mjs",
23
23
  "typecheck": "tsc -p tsconfig.json --noEmit",
24
24
  "test": "vitest run",
25
25
  "dev": "vite",
@@ -1,11 +0,0 @@
1
- import type { ServerFrame } from './protocol/index.js';
2
- export declare class AnnotationOverlay {
3
- private svg;
4
- private readonly timers;
5
- /** Feed every server frame; the overlay reacts to annotation frames only. */
6
- apply(frame: ServerFrame): void;
7
- private ensureSvg;
8
- private draw;
9
- clear(): void;
10
- destroy(): void;
11
- }