@miiflow/assistant-ui 0.5.0 → 0.5.1
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/chunk-4WWJTYYA.js +2 -0
- package/dist/chunk-4WWJTYYA.js.map +1 -0
- package/dist/{chunk-W3HWTAF6.js → chunk-6RN7SUWT.js} +2 -2
- package/dist/{chunk-W3HWTAF6.js.map → chunk-6RN7SUWT.js.map} +1 -1
- package/dist/{chunk-DEH5ET5U.js → chunk-RZNLGXIW.js} +9 -9
- package/dist/chunk-RZNLGXIW.js.map +1 -0
- package/dist/client/index.js +3 -3
- package/dist/client/index.js.map +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/primitives/index.js +1 -1
- package/dist/styled/index.js +1 -1
- package/dist/styles-no-preflight.css +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/dist/chunk-65VDOUZG.js +0 -2
- package/dist/chunk-65VDOUZG.js.map +0 -1
- package/dist/chunk-DEH5ET5U.js.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {useRef,useState,useCallback,useEffect}from'react';function U({enabled:s=true,smooth:h=true,scrollToBottomOnMount:g=true}={}){let o=useRef(null),[p,d]=useState(true),l=useRef(0),c=useRef(null),i=useCallback(t=>{let e=o.current;if(!e)return;let f=t??(h?"smooth":"instant");c.current=f,e.scrollTo({top:e.scrollHeight,behavior:f});},[h]),a=useCallback(t=>Math.abs(t.scrollHeight-t.scrollTop-t.clientHeight)<1||t.scrollHeight<=t.clientHeight,[]),m=useCallback(()=>{let t=o.current;if(!t)return;let e=a(t);!e&&l.current<t.scrollTop||(e&&(c.current=null),(e||c.current===null)&&d(e)),l.current=t.scrollTop;},[a]),r=useCallback(()=>{let t=c.current;if(t)i(t);else if(s){let e=o.current;e&&a(e)&&i("instant");}m();},[s,i,a,m]);return useEffect(()=>{let t=o.current;if(!t||!s)return;let e=new ResizeObserver(()=>{r();});return e.observe(t),()=>e.disconnect()},[s,r]),useEffect(()=>{let t=o.current;if(!t||!s)return;let e=new MutationObserver(f=>{f.some(T=>T.type!=="attributes"||T.attributeName!=="style")&&r();});return e.observe(t,{childList:true,subtree:true,attributes:true,characterData:true}),()=>e.disconnect()},[s,r]),useEffect(()=>{let t=o.current;if(t)return t.addEventListener("scroll",m,{passive:true}),()=>t.removeEventListener("scroll",m)},[m]),useEffect(()=>{s&&g&&(c.current="instant",requestAnimationFrame(()=>{i("instant");}));},[]),{containerRef:o,scrollToBottom:i,isAtBottom:p}}function I({onSubmit:s,disabled:h=false,maxFileSize:g=10*1024*1024,allowedFileTypes:o}){let[p,d]=useState(""),[l,c]=useState([]),[i,a]=useState(false),[m,r]=useState(null),t=useRef(null),e=useRef(false),f=useCallback(n=>{d(n),r(null);},[]),M=useCallback(n=>{let b=Array.from(n),B=[];for(let u of b){if(u.size>g){r(`File "${u.name}" exceeds maximum size`);continue}if(o&&!o.includes(u.type)){r(`File type "${u.type}" is not allowed`);continue}B.push(u);}c(u=>[...u,...B]);},[g,o]),T=useCallback(n=>{c(b=>b.filter((B,u)=>u!==n));},[]),y=useCallback(async()=>{let n=p.trim();if(!(!n&&l.length===0||h||i||e.current)){e.current=true,a(true),r(null);try{await s(n,l.length>0?l:void 0),d(""),c([]),t.current?.focus();}catch(b){r(b instanceof Error?b.message:"Failed to send message");}finally{a(false),e.current=false;}}},[p,l,h,i,s]),C=useCallback(n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),y());},[y]),H=useCallback(()=>{d(""),c([]),r(null);},[]),O=(p.trim()||l.length>0)&&!h&&!i;return {content:p,attachments:l,isSubmitting:i,error:m,canSubmit:O,inputRef:t,handleContentChange:f,handleAddAttachment:M,handleRemoveAttachment:T,handleSubmit:y,handleKeyDown:C,clear:H}}export{U as a,I as b};//# sourceMappingURL=chunk-4WWJTYYA.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-4WWJTYYA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-auto-scroll.ts","../src/hooks/use-message-composer.ts"],"names":["useAutoScroll","enabled","smooth","scrollToBottomOnMount","containerRef","useRef","isAtBottom","setIsAtBottom","useState","lastScrollTopRef","scrollingToBottomBehaviorRef","scrollToBottom","useCallback","behavior","container","b","computeIsAtBottom","el","handleScroll","newIsAtBottom","handleContentResize","scrollBehavior","useEffect","resizeObserver","mutationObserver","mutations","m","useMessageComposer","onSubmit","disabled","maxFileSize","allowedFileTypes","content","setContent","attachments","setAttachments","isSubmitting","setIsSubmitting","error","setError","inputRef","isSubmittingRef","handleContentChange","value","handleAddAttachment","files","fileArray","validFiles","file","prev","handleRemoveAttachment","index","_","i","handleSubmit","trimmedContent","err","handleKeyDown","e","clear","canSubmit"],"mappings":"0DA+BO,SAASA,EAAqC,CACnD,OAAA,CAAAC,CAAAA,CAAU,IAAA,CACV,OAAAC,CAAAA,CAAS,IAAA,CACT,qBAAA,CAAAC,CAAAA,CAAwB,IAC1B,CAAA,CAA0B,EAAC,CAA2B,CACpD,IAAMC,CAAAA,CAAeC,MAAAA,CAAU,IAAI,CAAA,CAC7B,CAACC,CAAAA,CAAYC,CAAa,EAAIC,QAAAA,CAAS,IAAI,EAC3CC,CAAAA,CAAmBJ,MAAAA,CAAO,CAAC,CAAA,CAO3BK,EAA+BL,MAAAA,CAA8B,IAAI,CAAA,CAEjEM,CAAAA,CAAiBC,YACpBC,CAAAA,EAA8B,CAC7B,IAAMC,CAAAA,CAAYV,EAAa,OAAA,CAC/B,GAAI,CAACU,CAAAA,CAAW,OAEhB,IAAMC,CAAAA,CAAIF,CAAAA,GAAaX,CAAAA,CAAS,SAAW,SAAA,CAAA,CAC3CQ,CAAAA,CAA6B,OAAA,CAAUK,CAAAA,CACvCD,EAAU,QAAA,CAAS,CAAE,GAAA,CAAKA,CAAAA,CAAU,aAAc,QAAA,CAAUC,CAAE,CAAC,EACjE,CAAA,CACA,CAACb,CAAM,CACT,CAAA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ACnB8C,CAAAA,EAA0C,CAErCA,CAAAA,CAAE,GAAA,GAAQ,SAAW,CAACA,CAAAA,CAAE,QAAA,GAC1BA,CAAAA,CAAE,gBAAe,CACjBJ,CAAAA,EAAa,EAEjB,CAAA,CACA,CAACA,CAAY,CACf,CAAA,CAEMK,CAAAA,CAAQ/C,YAAY,IAAM,CAC9BqB,CAAAA,CAAW,EAAE,EACbE,CAAAA,CAAe,EAAE,CAAA,CACjBI,CAAAA,CAAS,IAAI,EACf,CAAA,CAAG,EAAE,EAECqB,CAAAA,CAAAA,CAAa5B,CAAAA,CAAQ,IAAA,EAAK,EAAKE,EAAY,MAAA,CAAS,CAAA,GAAM,CAACL,CAAAA,EAAY,CAACO,CAAAA,CAE9E,OAAO,CACL,OAAA,CAAAJ,CAAAA,CACA,YAAAE,CAAAA,CACA,YAAA,CAAAE,CAAAA,CACA,KAAA,CAAAE,EACA,SAAA,CAAAsB,CAAAA,CACA,QAAA,CAAApB,CAAAA,CACA,oBAAAE,CAAAA,CACA,mBAAA,CAAAE,CAAAA,CACA,sBAAA,CAAAM,EACA,YAAA,CAAAI,CAAAA,CACA,cAAAG,CAAAA,CACA,KAAA,CAAAE,CACF,CACF","file":"chunk-4WWJTYYA.js","sourcesContent":["import { useEffect, useRef, useCallback, useState } from \"react\";\n\nexport interface UseAutoScrollOptions {\n /** Whether auto-scroll is enabled */\n enabled?: boolean;\n /** Smooth scroll behavior */\n smooth?: boolean;\n /** Scroll to bottom when component mounts */\n scrollToBottomOnMount?: boolean;\n}\n\nexport interface UseAutoScrollReturn<T extends HTMLElement> {\n /** Ref to attach to the scrollable container */\n containerRef: React.RefObject<T | null>;\n /** Scroll to bottom programmatically (always forces scroll) */\n scrollToBottom: (behavior?: ScrollBehavior) => void;\n /** Whether the viewport is currently at the bottom */\n isAtBottom: boolean;\n}\n\n/**\n * Hook to automatically scroll to the bottom of a container\n * when new content is added, unless the user has scrolled up.\n *\n * Combines ResizeObserver + MutationObserver to catch all height changes\n * (image loads, panel expansion, streaming text, new messages).\n *\n * Uses a 1px tolerance for isAtBottom (matches assistant-ui) and\n * persists scroll behavior across content resize to prevent\n * the \"content outraces scroll\" bug.\n */\nexport function useAutoScroll<T extends HTMLElement>({\n enabled = true,\n smooth = true,\n scrollToBottomOnMount = true,\n}: UseAutoScrollOptions = {}): UseAutoScrollReturn<T> {\n const containerRef = useRef<T>(null);\n const [isAtBottom, setIsAtBottom] = useState(true);\n const lastScrollTopRef = useRef(0);\n\n // When scrollToBottom() is called, store the behavior.\n // On subsequent resize/mutation callbacks, re-scroll with the same behavior\n // until the bottom is actually reached. This prevents the \"content outraces\n // scroll\" bug where new content pushes the bottom away faster than smooth\n // scrolling can reach it.\n const scrollingToBottomBehaviorRef = useRef<ScrollBehavior | null>(null);\n\n const scrollToBottom = useCallback(\n (behavior?: ScrollBehavior) => {\n const container = containerRef.current;\n if (!container) return;\n\n const b = behavior ?? (smooth ? \"smooth\" : \"instant\");\n scrollingToBottomBehaviorRef.current = b;\n container.scrollTo({ top: container.scrollHeight, behavior: b });\n },\n [smooth],\n );\n\n // Determine if we're at the bottom (1px tolerance, or content fits without scroll)\n const computeIsAtBottom = useCallback((el: HTMLElement): boolean => {\n return (\n Math.abs(el.scrollHeight - el.scrollTop - el.clientHeight) < 1 ||\n el.scrollHeight <= el.clientHeight\n );\n }, []);\n\n // Scroll event handler — updates isAtBottom state\n const handleScroll = useCallback(() => {\n const container = containerRef.current;\n if (!container) return;\n\n const newIsAtBottom = computeIsAtBottom(container);\n\n // If user is scrolling UP while we're in the middle of a scrollToBottom,\n // don't flip isAtBottom to false (ignore scroll-down momentum).\n if (!newIsAtBottom && lastScrollTopRef.current < container.scrollTop) {\n // Scroll is moving down — likely from our scrollToBottom call, ignore\n } else {\n if (newIsAtBottom) {\n scrollingToBottomBehaviorRef.current = null;\n }\n\n // Only update state when behavior ref is cleared (i.e. not mid-scroll)\n // or when we actually reached the bottom\n const shouldUpdate =\n newIsAtBottom || scrollingToBottomBehaviorRef.current === null;\n\n if (shouldUpdate) {\n setIsAtBottom(newIsAtBottom);\n }\n }\n\n lastScrollTopRef.current = container.scrollTop;\n }, [computeIsAtBottom]);\n\n // Content resize handler — called by both ResizeObserver and MutationObserver\n const handleContentResize = useCallback(() => {\n const scrollBehavior = scrollingToBottomBehaviorRef.current;\n if (scrollBehavior) {\n // We're in the middle of a scrollToBottom — keep chasing the bottom\n scrollToBottom(scrollBehavior);\n } else if (enabled) {\n // Auto-scroll only if already at bottom\n const container = containerRef.current;\n if (container && computeIsAtBottom(container)) {\n scrollToBottom(\"instant\");\n }\n }\n\n handleScroll();\n }, [enabled, scrollToBottom, computeIsAtBottom, handleScroll]);\n\n // ResizeObserver — catches height changes from image loads, layout shifts, etc.\n useEffect(() => {\n const container = containerRef.current;\n if (!container || !enabled) return;\n\n const resizeObserver = new ResizeObserver(() => {\n handleContentResize();\n });\n\n resizeObserver.observe(container);\n return () => resizeObserver.disconnect();\n }, [enabled, handleContentResize]);\n\n // MutationObserver — catches new messages, streaming text, DOM changes\n useEffect(() => {\n const container = containerRef.current;\n if (!container || !enabled) return;\n\n const mutationObserver = new MutationObserver((mutations) => {\n // Filter out style-only attribute mutations to prevent feedback loops\n // (e.g. components that write styles in response to viewport changes)\n const hasRelevantMutation = mutations.some(\n (m) => m.type !== \"attributes\" || m.attributeName !== \"style\",\n );\n if (hasRelevantMutation) {\n handleContentResize();\n }\n });\n\n mutationObserver.observe(container, {\n childList: true,\n subtree: true,\n attributes: true,\n characterData: true,\n });\n\n return () => mutationObserver.disconnect();\n }, [enabled, handleContentResize]);\n\n // Scroll listener\n useEffect(() => {\n const container = containerRef.current;\n if (!container) return;\n\n container.addEventListener(\"scroll\", handleScroll, { passive: true });\n return () => container.removeEventListener(\"scroll\", handleScroll);\n }, [handleScroll]);\n\n // Scroll to bottom on mount\n useEffect(() => {\n if (enabled && scrollToBottomOnMount) {\n // Use instant on mount — no need for smooth animation on initial load\n scrollingToBottomBehaviorRef.current = \"instant\";\n requestAnimationFrame(() => {\n scrollToBottom(\"instant\");\n });\n }\n // Only run on mount\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return {\n containerRef,\n scrollToBottom,\n isAtBottom,\n };\n}\n","import { useState, useCallback, useRef, type KeyboardEvent } from \"react\";\n\ninterface UseMessageComposerOptions {\n /** Callback when message is submitted */\n onSubmit: (content: string, attachments?: File[]) => Promise<void>;\n /** Whether submission is disabled */\n disabled?: boolean;\n /** Maximum file size in bytes */\n maxFileSize?: number;\n /** Allowed file types (MIME types) */\n allowedFileTypes?: string[];\n}\n\n/**\n * Hook to manage message composer state and behavior.\n */\nexport function useMessageComposer({\n onSubmit,\n disabled = false,\n maxFileSize = 10 * 1024 * 1024, // 10MB\n allowedFileTypes,\n}: UseMessageComposerOptions) {\n const [content, setContent] = useState(\"\");\n const [attachments, setAttachments] = useState<File[]>([]);\n const [isSubmitting, setIsSubmitting] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const inputRef = useRef<HTMLTextAreaElement>(null);\n const isSubmittingRef = useRef(false);\n\n const handleContentChange = useCallback((value: string) => {\n setContent(value);\n setError(null);\n }, []);\n\n const handleAddAttachment = useCallback(\n (files: FileList | File[]) => {\n const fileArray = Array.from(files);\n const validFiles: File[] = [];\n\n for (const file of fileArray) {\n // Check file size\n if (file.size > maxFileSize) {\n setError(`File \"${file.name}\" exceeds maximum size`);\n continue;\n }\n\n // Check file type\n if (allowedFileTypes && !allowedFileTypes.includes(file.type)) {\n setError(`File type \"${file.type}\" is not allowed`);\n continue;\n }\n\n validFiles.push(file);\n }\n\n setAttachments((prev) => [...prev, ...validFiles]);\n },\n [maxFileSize, allowedFileTypes]\n );\n\n const handleRemoveAttachment = useCallback((index: number) => {\n setAttachments((prev) => prev.filter((_, i) => i !== index));\n }, []);\n\n const handleSubmit = useCallback(async () => {\n const trimmedContent = content.trim();\n if ((!trimmedContent && attachments.length === 0) || disabled || isSubmitting || isSubmittingRef.current) {\n return;\n }\n\n // Lock immediately to prevent double-send race condition\n isSubmittingRef.current = true;\n setIsSubmitting(true);\n setError(null);\n\n try {\n await onSubmit(trimmedContent, attachments.length > 0 ? attachments : undefined);\n setContent(\"\");\n setAttachments([]);\n inputRef.current?.focus();\n } catch (err) {\n setError(err instanceof Error ? err.message : \"Failed to send message\");\n } finally {\n setIsSubmitting(false);\n isSubmittingRef.current = false;\n }\n }, [content, attachments, disabled, isSubmitting, onSubmit]);\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent<HTMLTextAreaElement>) => {\n // Submit on Enter without Shift\n if (e.key === \"Enter\" && !e.shiftKey) {\n e.preventDefault();\n handleSubmit();\n }\n },\n [handleSubmit]\n );\n\n const clear = useCallback(() => {\n setContent(\"\");\n setAttachments([]);\n setError(null);\n }, []);\n\n const canSubmit = (content.trim() || attachments.length > 0) && !disabled && !isSubmitting;\n\n return {\n content,\n attachments,\n isSubmitting,\n error,\n canSubmit,\n inputRef,\n handleContentChange,\n handleAddAttachment,\n handleRemoveAttachment,\n handleSubmit,\n handleKeyDown,\n clear,\n };\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a,b}from'./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import {a,b}from'./chunk-4WWJTYYA.js';import {createContext,forwardRef,useContext}from'react';import {jsx,Fragment,jsxs}from'react/jsx-runtime';var d=createContext(null);function g(){let e=useContext(d);if(!e)throw new Error("useMessage must be used within a Message component");return e}var S=forwardRef(({message:e,viewerRole:t="user",children:r,...n},s)=>{let o=(e.participant?.role||"").toLowerCase()===(t||"").toLowerCase(),i=e.isStreaming??false;return jsx(d.Provider,{value:{message:e,isViewer:o,isStreaming:i},children:jsx("div",{ref:s,"data-role":e.participant?.role,"data-viewer":o,"data-streaming":i,...n,children:r})})});S.displayName="Message";var L=forwardRef(({children:e,...t},r)=>{let{message:n}=g();return jsx("div",{ref:r,...t,children:e??n.textContent})});L.displayName="MessageContent";var h=forwardRef(({format:e,...t},r)=>{let{message:n}=g(),s=typeof n.createdAt=="string"?new Date(n.createdAt):n.createdAt,o=e?e(s):s.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:true});return jsx("span",{ref:r,...t,children:o})});h.displayName="MessageTimestamp";var R=forwardRef(({children:e,autoScroll:t=true,onIsAtBottomChange:r,onScrollToBottomRef:n,...s},o)=>{let{containerRef:i,scrollToBottom:a$1,isAtBottom:p}=a({enabled:t});return {current:p}.current!==p&&r?.(p),n?.(a$1),jsx("div",{ref:c=>{i.current=c,typeof o=="function"?o(c):o&&(o.current=c);},...s,children:e})});R.displayName="MessageList";var M=createContext(null);function x(){let e=useContext(M);if(!e)throw new Error("useComposer must be used within a MessageComposer component");return e}var P=forwardRef(({onSubmit:e,disabled:t=false,children:r,className:n},s)=>{let o=b({onSubmit:e,disabled:t}),i=p=>{p.preventDefault(),o.handleSubmit();},a={...o,canSubmit:!!o.canSubmit};return jsx(M.Provider,{value:a,children:jsx("form",{ref:s,className:n,onSubmit:i,"data-submitting":o.isSubmitting,"data-can-submit":o.canSubmit,children:r})})});P.displayName="MessageComposer";var H=forwardRef((e,t)=>{let{content:r,handleContentChange:n,handleKeyDown:s,inputRef:o}=x();return jsx("textarea",{ref:a=>{o.current=a,typeof t=="function"?t(a):t&&(t.current=a);},value:r,onChange:a=>n(a.target.value),onKeyDown:s,...e})});H.displayName="ComposerInput";var E=forwardRef(({children:e,disabled:t,...r},n)=>{let{canSubmit:s,isSubmitting:o}=x();return jsx("button",{ref:n,type:"submit",disabled:t||!s,"data-submitting":o,...r,children:e})});E.displayName="ComposerSubmit";function G(e){let t=e.trim().split(/\s+/);return t.length===1?t[0].charAt(0).toUpperCase():(t[0].charAt(0)+t[t.length-1].charAt(0)).toUpperCase()}var N=forwardRef(({name:e,src:t,alt:r,role:n,fallback:s,children:o,...i},a)=>{let p=e?G(e):null;return jsx("div",{ref:a,"data-role":n,...i,children:o??jsx(Fragment,{children:t?jsx("img",{src:t,alt:r??e??n??"Avatar",style:{width:"100%",height:"100%"}}):s??p??n?.charAt(0).toUpperCase()})})});N.displayName="Avatar";var w=forwardRef(({content:e,isStreaming:t=false,showCursor:r=true,cursor:n,children:s,...o},i)=>jsxs("div",{ref:i,"data-streaming":t,...o,children:[s??e,t&&r&&(n??jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:"2px",height:"1em",backgroundColor:"currentColor",marginLeft:"2px",verticalAlign:"text-bottom",animation:"blink 1s step-end infinite"}}))]}));w.displayName="StreamingText";var T=createContext(null);function D(){let e=useContext(T);if(!e)throw new Error("useSuggestedActions must be used within a SuggestedActions component");return e}var I=forwardRef(({actions:e,onSelect:t,children:r,className:n},s)=>e.length===0?null:jsx(T.Provider,{value:{actions:e,onSelect:t},children:jsx("div",{ref:s,role:"group","aria-label":"Suggested actions",className:n,children:r})}));I.displayName="SuggestedActions";var k=forwardRef(({action:e,children:t,onClick:r,...n},s)=>{let{onSelect:o}=D();return jsx("button",{ref:s,type:"button",onClick:a=>{r?.(a),a.defaultPrevented||o(e);},...n,children:t??e.label})});k.displayName="ActionButton";var V=forwardRef(({children:e,dotCount:t=3,...r},n)=>jsx("div",{ref:n,role:"status","aria-label":"Assistant is typing",...r,children:e??jsx("span",{"aria-hidden":"true",children:Array.from({length:t}).map((s,o)=>jsx("span",{style:{display:"inline-block",width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"currentColor",marginRight:o<t-1?"4px":0,animation:"typing 1.4s infinite ease-in-out",animationDelay:`${o*.2}s`}},o))})}));V.displayName="TypingIndicator";export{d as a,g as b,S as c,L as d,h as e,R as f,M as g,x as h,P as i,H as j,E as k,N as l,w as m,T as n,D as o,I as p,k as q,V as r};//# sourceMappingURL=chunk-6RN7SUWT.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-6RN7SUWT.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/primitives/message.tsx","../src/primitives/message-list.tsx","../src/primitives/message-composer.tsx","../src/primitives/avatar.tsx","../src/primitives/streaming-text.tsx","../src/primitives/suggested-actions.tsx","../src/primitives/typing-indicator.tsx"],"names":["MessageContext","createContext","useMessage","context","useContext","Message","forwardRef","message","viewerRole","children","props","ref","isViewer","isStreaming","jsx","MessageContent","MessageTimestamp","format","date","formatted","MessageList","autoScroll","onIsAtBottomChange","onScrollToBottomRef","containerRef","scrollToBottom","isAtBottom","useAutoScroll","node","ComposerContext","useComposer","MessageComposer","onSubmit","disabled","className","composer","useMessageComposer","handleFormSubmit","e","contextValue","ComposerInput","content","handleContentChange","handleKeyDown","inputRef","ComposerSubmit","canSubmit","isSubmitting","getInitials","name","parts","Avatar","src","alt","role","fallback","initials","Fragment","StreamingText","showCursor","cursor","jsxs","SuggestedActionsContext","useSuggestedActions","SuggestedActions","actions","onSelect","ActionButton","action","onClick","TypingIndicator","dotCount","_","i"],"mappings":"gJASA,IAAMA,CAAAA,CAAiBC,cAA0C,IAAI,EAM9D,SAASC,CAAAA,EAAa,CAC5B,IAAMC,EAAUC,UAAAA,CAAWJ,CAAc,CAAA,CACzC,GAAI,CAACG,CAAAA,CACJ,MAAM,IAAI,KAAA,CAAM,oDAAoD,CAAA,CAErE,OAAOA,CACR,CAeO,IAAME,CAAAA,CAAUC,UAAAA,CACtB,CAAC,CAAE,OAAA,CAAAC,EAAS,UAAA,CAAAC,CAAAA,CAAa,MAAA,CAAQ,QAAA,CAAAC,CAAAA,CAAU,GAAGC,CAAM,CAAA,CAAGC,CAAAA,GAAQ,CAE9D,IAAMC,CAAAA,CAAAA,CAAYL,CAAAA,CAAQ,WAAA,EAAa,MAAQ,EAAA,EAAI,WAAA,EAAY,GAAA,CAAOC,CAAAA,EAAc,EAAA,EAAI,WAAA,GAClFK,CAAAA,CAAcN,CAAAA,CAAQ,WAAA,EAAe,KAAA,CAE3C,OACCO,GAAAA,CAACd,EAAe,QAAA,CAAf,CAAwB,KAAA,CAAO,CAAE,OAAA,CAAAO,CAAAA,CAAS,QAAA,CAAAK,CAAAA,CAAU,WAAA,CAAAC,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CAVKA,CAWP,CACD,CAAA,CACH,CAAA,CAEJ,CAGN,EAEAH,CAAAA,CAAgB,WAAA,CAAc,iBAAA","file":"chunk-W3HWTAF6.js","sourcesContent":["import { createContext, forwardRef, useContext, type HTMLAttributes, type ReactNode } from \"react\";\nimport type { MessageData, ParticipantRole } from \"../types\";\n\ninterface MessageContextValue {\n\tmessage: MessageData;\n\tisViewer: boolean;\n\tisStreaming: boolean;\n}\n\nconst MessageContext = createContext<MessageContextValue | null>(null);\n\n/**\n * Hook to access the current message context.\n * Must be used within a Message component.\n */\nexport function useMessage() {\n\tconst context = useContext(MessageContext);\n\tif (!context) {\n\t\tthrow new Error(\"useMessage must be used within a Message component\");\n\t}\n\treturn context;\n}\n\nexport interface MessageProps extends HTMLAttributes<HTMLDivElement> {\n\t/** The message data */\n\tmessage: MessageData;\n\t/** The viewer's role (used to determine alignment) */\n\tviewerRole?: ParticipantRole;\n\t/** Children to render inside the message */\n\tchildren: ReactNode;\n}\n\n/**\n * Headless Message primitive.\n * Provides message context to children and data attributes for styling.\n */\nexport const Message = forwardRef<HTMLDivElement, MessageProps>(\n\t({ message, viewerRole = \"user\", children, ...props }, ref) => {\n\t\t// Case-insensitive comparison for role matching\n\t\tconst isViewer = (message.participant?.role || \"\").toLowerCase() === (viewerRole || \"\").toLowerCase();\n\t\tconst isStreaming = message.isStreaming ?? false;\n\n\t\treturn (\n\t\t\t<MessageContext.Provider value={{ message, isViewer, isStreaming }}>\n\t\t\t\t<div\n\t\t\t\t\tref={ref}\n\t\t\t\t\tdata-role={message.participant?.role}\n\t\t\t\t\tdata-viewer={isViewer}\n\t\t\t\t\tdata-streaming={isStreaming}\n\t\t\t\t\t{...props}>\n\t\t\t\t\t{children}\n\t\t\t\t</div>\n\t\t\t</MessageContext.Provider>\n\t\t);\n\t},\n);\n\nMessage.displayName = \"Message\";\n\nexport interface MessageContentProps extends HTMLAttributes<HTMLDivElement> {\n\t/** Custom content to render instead of message text */\n\tchildren?: ReactNode;\n}\n\n/**\n * Renders the message content.\n * By default renders the message's textContent.\n */\nexport const MessageContent = forwardRef<HTMLDivElement, MessageContentProps>(({ children, ...props }, ref) => {\n\tconst { message } = useMessage();\n\n\treturn (\n\t\t<div ref={ref} {...props}>\n\t\t\t{children ?? message.textContent}\n\t\t</div>\n\t);\n});\n\nMessageContent.displayName = \"MessageContent\";\n\nexport interface MessageTimestampProps extends HTMLAttributes<HTMLSpanElement> {\n\t/** Custom date formatter */\n\tformat?: (date: Date) => string;\n}\n\n/**\n * Renders the message timestamp.\n */\nexport const MessageTimestamp = forwardRef<HTMLSpanElement, MessageTimestampProps>(({ format, ...props }, ref) => {\n\tconst { message } = useMessage();\n\tconst date = typeof message.createdAt === \"string\" ? new Date(message.createdAt) : message.createdAt;\n\n\tconst formatted = format\n\t\t? format(date)\n\t\t: date.toLocaleTimeString(\"en-US\", {\n\t\t\t\thour: \"numeric\",\n\t\t\t\tminute: \"2-digit\",\n\t\t\t\thour12: true,\n\t\t\t});\n\n\treturn (\n\t\t<span ref={ref} {...props}>\n\t\t\t{formatted}\n\t\t</span>\n\t);\n});\n\nMessageTimestamp.displayName = \"MessageTimestamp\";\n\nexport { MessageContext };\n","import { forwardRef, type HTMLAttributes, type ReactNode } from \"react\";\nimport { useAutoScroll } from \"../hooks/use-auto-scroll\";\n\nexport interface MessageListProps extends HTMLAttributes<HTMLDivElement> {\n\t/** Messages to render */\n\tchildren: ReactNode;\n\t/** Whether to auto-scroll to bottom on new messages */\n\tautoScroll?: boolean;\n\t/** Whether the viewport is currently at the bottom (exposed for scroll-to-bottom button) */\n\tisAtBottom?: boolean;\n\t/** Callback to receive scroll state updates */\n\tonIsAtBottomChange?: (isAtBottom: boolean) => void;\n\t/** Callback to receive scrollToBottom function */\n\tonScrollToBottomRef?: (scrollToBottom: (behavior?: ScrollBehavior) => void) => void;\n}\n\n/**\n * Headless MessageList primitive.\n * Provides a scrollable container with auto-scroll behavior.\n * Exposes isAtBottom and scrollToBottom for scroll-to-bottom button integration.\n */\nexport const MessageList = forwardRef<HTMLDivElement, MessageListProps>(\n\t({ children, autoScroll = true, onIsAtBottomChange, onScrollToBottomRef, ...props }, ref) => {\n\t\tconst { containerRef, scrollToBottom, isAtBottom } = useAutoScroll<HTMLDivElement>({\n\t\t\tenabled: autoScroll,\n\t\t});\n\n\t\t// Notify parent of scroll state changes\n\t\tconst prevIsAtBottomRef = { current: isAtBottom };\n\t\tif (prevIsAtBottomRef.current !== isAtBottom) {\n\t\t\tonIsAtBottomChange?.(isAtBottom);\n\t\t}\n\n\t\t// Expose scrollToBottom to parent\n\t\tonScrollToBottomRef?.(scrollToBottom);\n\n\t\t// Merge refs\n\t\tconst mergedRef = (node: HTMLDivElement | null) => {\n\t\t\t(containerRef as React.MutableRefObject<HTMLDivElement | null>).current = node;\n\t\t\tif (typeof ref === \"function\") {\n\t\t\t\tref(node);\n\t\t\t} else if (ref) {\n\t\t\t\tref.current = node;\n\t\t\t}\n\t\t};\n\n\t\treturn (\n\t\t\t<div ref={mergedRef} {...props}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t},\n);\n\nMessageList.displayName = \"MessageList\";\n","import {\n createContext,\n useContext,\n forwardRef,\n type ReactNode,\n type TextareaHTMLAttributes,\n type ButtonHTMLAttributes,\n} from \"react\";\nimport { useMessageComposer } from \"../hooks/use-message-composer\";\n\ninterface ComposerContextValue {\n content: string;\n isSubmitting: boolean;\n canSubmit: boolean;\n error: string | null;\n handleContentChange: (value: string) => void;\n handleSubmit: () => Promise<void>;\n handleKeyDown: (e: React.KeyboardEvent<HTMLTextAreaElement>) => void;\n inputRef: React.RefObject<HTMLTextAreaElement | null>;\n}\n\nconst ComposerContext = createContext<ComposerContextValue | null>(null);\n\n/**\n * Hook to access the composer context.\n * Must be used within a MessageComposer component.\n */\nexport function useComposer() {\n const context = useContext(ComposerContext);\n if (!context) {\n throw new Error(\"useComposer must be used within a MessageComposer component\");\n }\n return context;\n}\n\nexport interface MessageComposerProps {\n /** Callback when message is submitted */\n onSubmit: (content: string, attachments?: File[]) => Promise<void>;\n /** Whether the composer is disabled */\n disabled?: boolean;\n /** Children to render inside the composer */\n children: ReactNode;\n /** Additional CSS classes */\n className?: string;\n}\n\n/**\n * Headless MessageComposer primitive.\n * Provides composer state and behavior to children.\n */\nexport const MessageComposer = forwardRef<HTMLFormElement, MessageComposerProps>(\n ({ onSubmit, disabled = false, children, className }, ref) => {\n const composer = useMessageComposer({ onSubmit, disabled });\n\n const handleFormSubmit = (e: React.FormEvent) => {\n e.preventDefault();\n composer.handleSubmit();\n };\n\n const contextValue: ComposerContextValue = {\n ...composer,\n canSubmit: Boolean(composer.canSubmit),\n };\n\n return (\n <ComposerContext.Provider value={contextValue}>\n <form\n ref={ref}\n className={className}\n onSubmit={handleFormSubmit}\n data-submitting={composer.isSubmitting}\n data-can-submit={composer.canSubmit}\n >\n {children}\n </form>\n </ComposerContext.Provider>\n );\n }\n);\n\nMessageComposer.displayName = \"MessageComposer\";\n\nexport interface ComposerInputProps\n extends Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, \"onChange\" | \"value\"> {}\n\n/**\n * Text input for the message composer.\n */\nexport const ComposerInput = forwardRef<HTMLTextAreaElement, ComposerInputProps>(\n (props, ref) => {\n const { content, handleContentChange, handleKeyDown, inputRef } = useComposer();\n\n // Merge refs\n const mergedRef = (node: HTMLTextAreaElement | null) => {\n (inputRef as React.MutableRefObject<HTMLTextAreaElement | null>).current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n };\n\n return (\n <textarea\n ref={mergedRef}\n value={content}\n onChange={(e) => handleContentChange(e.target.value)}\n onKeyDown={handleKeyDown}\n {...props}\n />\n );\n }\n);\n\nComposerInput.displayName = \"ComposerInput\";\n\nexport interface ComposerSubmitProps extends ButtonHTMLAttributes<HTMLButtonElement> {}\n\n/**\n * Submit button for the message composer.\n */\nexport const ComposerSubmit = forwardRef<HTMLButtonElement, ComposerSubmitProps>(\n ({ children, disabled, ...props }, ref) => {\n const { canSubmit, isSubmitting } = useComposer();\n\n return (\n <button\n ref={ref}\n type=\"submit\"\n disabled={disabled || !canSubmit}\n data-submitting={isSubmitting}\n {...props}\n >\n {children}\n </button>\n );\n }\n);\n\nComposerSubmit.displayName = \"ComposerSubmit\";\n\nexport { ComposerContext };\n","import { forwardRef, type HTMLAttributes } from \"react\";\nimport type { ParticipantRole } from \"../types\";\n\nexport interface AvatarProps extends HTMLAttributes<HTMLDivElement> {\n /** Name for fallback initials */\n name?: string;\n /** Image URL */\n src?: string;\n /** Alt text for image */\n alt?: string;\n /** Participant role for styling */\n role?: ParticipantRole;\n /** Fallback content when no image or name */\n fallback?: React.ReactNode;\n}\n\n/**\n * Get initials from a name.\n */\nfunction getInitials(name: string): string {\n const parts = name.trim().split(/\\s+/);\n if (parts.length === 1) {\n return parts[0].charAt(0).toUpperCase();\n }\n return (parts[0].charAt(0) + parts[parts.length - 1].charAt(0)).toUpperCase();\n}\n\n/**\n * Headless Avatar primitive.\n * Renders an image or fallback initials.\n */\nexport const Avatar = forwardRef<HTMLDivElement, AvatarProps>(\n ({ name, src, alt, role, fallback, children, ...props }, ref) => {\n const initials = name ? getInitials(name) : null;\n const altText = alt ?? name ?? role ?? \"Avatar\";\n\n return (\n <div ref={ref} data-role={role} {...props}>\n {children ?? (\n <>\n {src ? (\n <img src={src} alt={altText} style={{ width: \"100%\", height: \"100%\" }} />\n ) : (\n fallback ?? initials ?? role?.charAt(0).toUpperCase()\n )}\n </>\n )}\n </div>\n );\n }\n);\n\nAvatar.displayName = \"Avatar\";\n","import { forwardRef, type HTMLAttributes, type ReactNode } from \"react\";\n\nexport interface StreamingTextProps extends HTMLAttributes<HTMLDivElement> {\n /** The content to display */\n content: string;\n /** Whether the text is currently streaming */\n isStreaming?: boolean;\n /** Show a cursor indicator while streaming */\n showCursor?: boolean;\n /** Custom cursor element */\n cursor?: ReactNode;\n /** Children override (takes precedence over content) */\n children?: ReactNode;\n}\n\n/**\n * Headless StreamingText primitive.\n * Renders text with streaming indicator support.\n */\nexport const StreamingText = forwardRef<HTMLDivElement, StreamingTextProps>(\n (\n { content, isStreaming = false, showCursor = true, cursor, children, ...props },\n ref\n ) => {\n const defaultCursor = (\n <span\n aria-hidden=\"true\"\n style={{\n display: \"inline-block\",\n width: \"2px\",\n height: \"1em\",\n backgroundColor: \"currentColor\",\n marginLeft: \"2px\",\n verticalAlign: \"text-bottom\",\n animation: \"blink 1s step-end infinite\",\n }}\n />\n );\n\n return (\n <div ref={ref} data-streaming={isStreaming} {...props}>\n {children ?? content}\n {isStreaming && showCursor && (cursor ?? defaultCursor)}\n </div>\n );\n }\n);\n\nStreamingText.displayName = \"StreamingText\";\n","import {\n createContext,\n useContext,\n forwardRef,\n type ReactNode,\n type ButtonHTMLAttributes,\n} from \"react\";\nimport type { SuggestedAction } from \"../types\";\n\ninterface SuggestedActionsContextValue {\n actions: SuggestedAction[];\n onSelect: (action: SuggestedAction) => void;\n}\n\nconst SuggestedActionsContext = createContext<SuggestedActionsContextValue | null>(null);\n\n/**\n * Hook to access suggested actions context.\n */\nexport function useSuggestedActions() {\n const context = useContext(SuggestedActionsContext);\n if (!context) {\n throw new Error(\n \"useSuggestedActions must be used within a SuggestedActions component\"\n );\n }\n return context;\n}\n\nexport interface SuggestedActionsProps {\n /** List of suggested actions */\n actions: SuggestedAction[];\n /** Callback when an action is selected */\n onSelect: (action: SuggestedAction) => void;\n /** Children to render */\n children: ReactNode;\n /** Additional CSS classes */\n className?: string;\n}\n\n/**\n * Headless SuggestedActions primitive.\n * Provides context for rendering action buttons.\n */\nexport const SuggestedActions = forwardRef<HTMLDivElement, SuggestedActionsProps>(\n ({ actions, onSelect, children, className }, ref) => {\n if (actions.length === 0) {\n return null;\n }\n\n return (\n <SuggestedActionsContext.Provider value={{ actions, onSelect }}>\n <div ref={ref} role=\"group\" aria-label=\"Suggested actions\" className={className}>\n {children}\n </div>\n </SuggestedActionsContext.Provider>\n );\n }\n);\n\nSuggestedActions.displayName = \"SuggestedActions\";\n\nexport interface ActionButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {\n /** The action this button represents */\n action: SuggestedAction;\n /** Children to render inside button */\n children?: ReactNode;\n}\n\n/**\n * Button for a suggested action.\n */\nexport const ActionButton = forwardRef<HTMLButtonElement, ActionButtonProps>(\n ({ action, children, onClick, ...props }, ref) => {\n const { onSelect } = useSuggestedActions();\n\n const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n if (!e.defaultPrevented) {\n onSelect(action);\n }\n };\n\n return (\n <button ref={ref} type=\"button\" onClick={handleClick} {...props}>\n {children ?? action.label}\n </button>\n );\n }\n);\n\nActionButton.displayName = \"ActionButton\";\n\nexport { SuggestedActionsContext };\n","import { forwardRef, type HTMLAttributes, type ReactNode } from \"react\";\n\nexport interface TypingIndicatorProps extends HTMLAttributes<HTMLDivElement> {\n /** Custom content to show while typing */\n children?: ReactNode;\n /** Number of dots to show */\n dotCount?: number;\n}\n\n/**\n * Headless TypingIndicator primitive.\n * Shows animated dots or custom content.\n */\nexport const TypingIndicator = forwardRef<HTMLDivElement, TypingIndicatorProps>(\n ({ children, dotCount = 3, ...props }, ref) => {\n return (\n <div ref={ref} role=\"status\" aria-label=\"Assistant is typing\" {...props}>\n {children ?? (\n <span aria-hidden=\"true\">\n {Array.from({ length: dotCount }).map((_, i) => (\n <span\n key={i}\n style={{\n display: \"inline-block\",\n width: \"6px\",\n height: \"6px\",\n borderRadius: \"50%\",\n backgroundColor: \"currentColor\",\n marginRight: i < dotCount - 1 ? \"4px\" : 0,\n animation: `typing 1.4s infinite ease-in-out`,\n animationDelay: `${i * 0.2}s`,\n }}\n />\n ))}\n </span>\n )}\n </div>\n );\n }\n);\n\nTypingIndicator.displayName = \"TypingIndicator\";\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/primitives/message.tsx","../src/primitives/message-list.tsx","../src/primitives/message-composer.tsx","../src/primitives/avatar.tsx","../src/primitives/streaming-text.tsx","../src/primitives/suggested-actions.tsx","../src/primitives/typing-indicator.tsx"],"names":["MessageContext","createContext","useMessage","context","useContext","Message","forwardRef","message","viewerRole","children","props","ref","isViewer","isStreaming","jsx","MessageContent","MessageTimestamp","format","date","formatted","MessageList","autoScroll","onIsAtBottomChange","onScrollToBottomRef","containerRef","scrollToBottom","isAtBottom","useAutoScroll","node","ComposerContext","useComposer","MessageComposer","onSubmit","disabled","className","composer","useMessageComposer","handleFormSubmit","e","contextValue","ComposerInput","content","handleContentChange","handleKeyDown","inputRef","ComposerSubmit","canSubmit","isSubmitting","getInitials","name","parts","Avatar","src","alt","role","fallback","initials","Fragment","StreamingText","showCursor","cursor","jsxs","SuggestedActionsContext","useSuggestedActions","SuggestedActions","actions","onSelect","ActionButton","action","onClick","TypingIndicator","dotCount","_","i"],"mappings":"gJASA,IAAMA,CAAAA,CAAiBC,cAA0C,IAAI,EAM9D,SAASC,CAAAA,EAAa,CAC5B,IAAMC,EAAUC,UAAAA,CAAWJ,CAAc,CAAA,CACzC,GAAI,CAACG,CAAAA,CACJ,MAAM,IAAI,KAAA,CAAM,oDAAoD,CAAA,CAErE,OAAOA,CACR,CAeO,IAAME,CAAAA,CAAUC,UAAAA,CACtB,CAAC,CAAE,OAAA,CAAAC,EAAS,UAAA,CAAAC,CAAAA,CAAa,MAAA,CAAQ,QAAA,CAAAC,CAAAA,CAAU,GAAGC,CAAM,CAAA,CAAGC,CAAAA,GAAQ,CAE9D,IAAMC,CAAAA,CAAAA,CAAYL,CAAAA,CAAQ,WAAA,EAAa,MAAQ,EAAA,EAAI,WAAA,EAAY,GAAA,CAAOC,CAAAA,EAAc,EAAA,EAAI,WAAA,GAClFK,CAAAA,CAAcN,CAAAA,CAAQ,WAAA,EAAe,KAAA,CAE3C,OACCO,GAAAA,CAACd,EAAe,QAAA,CAAf,CAAwB,KAAA,CAAO,CAAE,OAAA,CAAAO,CAAAA,CAAS,QAAA,CAAAK,CAAAA,CAAU,WAAA,CAAAC,CAAY,CAAA,CAChE,QAAA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,CACH,CAAA,CAEJ,CAGN,EAEAH,CAAAA,CAAgB,WAAA,CAAc,iBAAA","file":"chunk-6RN7SUWT.js","sourcesContent":["import { createContext, forwardRef, useContext, type HTMLAttributes, type ReactNode } from \"react\";\nimport type { MessageData, ParticipantRole } from \"../types\";\n\ninterface MessageContextValue {\n\tmessage: MessageData;\n\tisViewer: boolean;\n\tisStreaming: boolean;\n}\n\nconst MessageContext = createContext<MessageContextValue | null>(null);\n\n/**\n * Hook to access the current message context.\n * Must be used within a Message component.\n */\nexport function useMessage() {\n\tconst context = useContext(MessageContext);\n\tif (!context) {\n\t\tthrow new Error(\"useMessage must be used within a Message component\");\n\t}\n\treturn context;\n}\n\nexport interface MessageProps extends HTMLAttributes<HTMLDivElement> {\n\t/** The message data */\n\tmessage: MessageData;\n\t/** The viewer's role (used to determine alignment) */\n\tviewerRole?: ParticipantRole;\n\t/** Children to render inside the message */\n\tchildren: ReactNode;\n}\n\n/**\n * Headless Message primitive.\n * Provides message context to children and data attributes for styling.\n */\nexport const Message = forwardRef<HTMLDivElement, MessageProps>(\n\t({ message, viewerRole = \"user\", children, ...props }, ref) => {\n\t\t// Case-insensitive comparison for role matching\n\t\tconst isViewer = (message.participant?.role || \"\").toLowerCase() === (viewerRole || \"\").toLowerCase();\n\t\tconst isStreaming = message.isStreaming ?? false;\n\n\t\treturn (\n\t\t\t<MessageContext.Provider value={{ message, isViewer, isStreaming }}>\n\t\t\t\t<div\n\t\t\t\t\tref={ref}\n\t\t\t\t\tdata-role={message.participant?.role}\n\t\t\t\t\tdata-viewer={isViewer}\n\t\t\t\t\tdata-streaming={isStreaming}\n\t\t\t\t\t{...props}>\n\t\t\t\t\t{children}\n\t\t\t\t</div>\n\t\t\t</MessageContext.Provider>\n\t\t);\n\t},\n);\n\nMessage.displayName = \"Message\";\n\nexport interface MessageContentProps extends HTMLAttributes<HTMLDivElement> {\n\t/** Custom content to render instead of message text */\n\tchildren?: ReactNode;\n}\n\n/**\n * Renders the message content.\n * By default renders the message's textContent.\n */\nexport const MessageContent = forwardRef<HTMLDivElement, MessageContentProps>(({ children, ...props }, ref) => {\n\tconst { message } = useMessage();\n\n\treturn (\n\t\t<div ref={ref} {...props}>\n\t\t\t{children ?? message.textContent}\n\t\t</div>\n\t);\n});\n\nMessageContent.displayName = \"MessageContent\";\n\nexport interface MessageTimestampProps extends HTMLAttributes<HTMLSpanElement> {\n\t/** Custom date formatter */\n\tformat?: (date: Date) => string;\n}\n\n/**\n * Renders the message timestamp.\n */\nexport const MessageTimestamp = forwardRef<HTMLSpanElement, MessageTimestampProps>(({ format, ...props }, ref) => {\n\tconst { message } = useMessage();\n\tconst date = typeof message.createdAt === \"string\" ? new Date(message.createdAt) : message.createdAt;\n\n\tconst formatted = format\n\t\t? format(date)\n\t\t: date.toLocaleTimeString(\"en-US\", {\n\t\t\t\thour: \"numeric\",\n\t\t\t\tminute: \"2-digit\",\n\t\t\t\thour12: true,\n\t\t\t});\n\n\treturn (\n\t\t<span ref={ref} {...props}>\n\t\t\t{formatted}\n\t\t</span>\n\t);\n});\n\nMessageTimestamp.displayName = \"MessageTimestamp\";\n\nexport { MessageContext };\n","import { forwardRef, type HTMLAttributes, type ReactNode } from \"react\";\nimport { useAutoScroll } from \"../hooks/use-auto-scroll\";\n\nexport interface MessageListProps extends HTMLAttributes<HTMLDivElement> {\n\t/** Messages to render */\n\tchildren: ReactNode;\n\t/** Whether to auto-scroll to bottom on new messages */\n\tautoScroll?: boolean;\n\t/** Whether the viewport is currently at the bottom (exposed for scroll-to-bottom button) */\n\tisAtBottom?: boolean;\n\t/** Callback to receive scroll state updates */\n\tonIsAtBottomChange?: (isAtBottom: boolean) => void;\n\t/** Callback to receive scrollToBottom function */\n\tonScrollToBottomRef?: (scrollToBottom: (behavior?: ScrollBehavior) => void) => void;\n}\n\n/**\n * Headless MessageList primitive.\n * Provides a scrollable container with auto-scroll behavior.\n * Exposes isAtBottom and scrollToBottom for scroll-to-bottom button integration.\n */\nexport const MessageList = forwardRef<HTMLDivElement, MessageListProps>(\n\t({ children, autoScroll = true, onIsAtBottomChange, onScrollToBottomRef, ...props }, ref) => {\n\t\tconst { containerRef, scrollToBottom, isAtBottom } = useAutoScroll<HTMLDivElement>({\n\t\t\tenabled: autoScroll,\n\t\t});\n\n\t\t// Notify parent of scroll state changes\n\t\tconst prevIsAtBottomRef = { current: isAtBottom };\n\t\tif (prevIsAtBottomRef.current !== isAtBottom) {\n\t\t\tonIsAtBottomChange?.(isAtBottom);\n\t\t}\n\n\t\t// Expose scrollToBottom to parent\n\t\tonScrollToBottomRef?.(scrollToBottom);\n\n\t\t// Merge refs\n\t\tconst mergedRef = (node: HTMLDivElement | null) => {\n\t\t\t(containerRef as React.MutableRefObject<HTMLDivElement | null>).current = node;\n\t\t\tif (typeof ref === \"function\") {\n\t\t\t\tref(node);\n\t\t\t} else if (ref) {\n\t\t\t\tref.current = node;\n\t\t\t}\n\t\t};\n\n\t\treturn (\n\t\t\t<div ref={mergedRef} {...props}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t},\n);\n\nMessageList.displayName = \"MessageList\";\n","import {\n createContext,\n useContext,\n forwardRef,\n type ReactNode,\n type TextareaHTMLAttributes,\n type ButtonHTMLAttributes,\n} from \"react\";\nimport { useMessageComposer } from \"../hooks/use-message-composer\";\n\ninterface ComposerContextValue {\n content: string;\n isSubmitting: boolean;\n canSubmit: boolean;\n error: string | null;\n handleContentChange: (value: string) => void;\n handleSubmit: () => Promise<void>;\n handleKeyDown: (e: React.KeyboardEvent<HTMLTextAreaElement>) => void;\n inputRef: React.RefObject<HTMLTextAreaElement | null>;\n}\n\nconst ComposerContext = createContext<ComposerContextValue | null>(null);\n\n/**\n * Hook to access the composer context.\n * Must be used within a MessageComposer component.\n */\nexport function useComposer() {\n const context = useContext(ComposerContext);\n if (!context) {\n throw new Error(\"useComposer must be used within a MessageComposer component\");\n }\n return context;\n}\n\nexport interface MessageComposerProps {\n /** Callback when message is submitted */\n onSubmit: (content: string, attachments?: File[]) => Promise<void>;\n /** Whether the composer is disabled */\n disabled?: boolean;\n /** Children to render inside the composer */\n children: ReactNode;\n /** Additional CSS classes */\n className?: string;\n}\n\n/**\n * Headless MessageComposer primitive.\n * Provides composer state and behavior to children.\n */\nexport const MessageComposer = forwardRef<HTMLFormElement, MessageComposerProps>(\n ({ onSubmit, disabled = false, children, className }, ref) => {\n const composer = useMessageComposer({ onSubmit, disabled });\n\n const handleFormSubmit = (e: React.FormEvent) => {\n e.preventDefault();\n composer.handleSubmit();\n };\n\n const contextValue: ComposerContextValue = {\n ...composer,\n canSubmit: Boolean(composer.canSubmit),\n };\n\n return (\n <ComposerContext.Provider value={contextValue}>\n <form\n ref={ref}\n className={className}\n onSubmit={handleFormSubmit}\n data-submitting={composer.isSubmitting}\n data-can-submit={composer.canSubmit}\n >\n {children}\n </form>\n </ComposerContext.Provider>\n );\n }\n);\n\nMessageComposer.displayName = \"MessageComposer\";\n\nexport interface ComposerInputProps\n extends Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, \"onChange\" | \"value\"> {}\n\n/**\n * Text input for the message composer.\n */\nexport const ComposerInput = forwardRef<HTMLTextAreaElement, ComposerInputProps>(\n (props, ref) => {\n const { content, handleContentChange, handleKeyDown, inputRef } = useComposer();\n\n // Merge refs\n const mergedRef = (node: HTMLTextAreaElement | null) => {\n (inputRef as React.MutableRefObject<HTMLTextAreaElement | null>).current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n };\n\n return (\n <textarea\n ref={mergedRef}\n value={content}\n onChange={(e) => handleContentChange(e.target.value)}\n onKeyDown={handleKeyDown}\n {...props}\n />\n );\n }\n);\n\nComposerInput.displayName = \"ComposerInput\";\n\nexport interface ComposerSubmitProps extends ButtonHTMLAttributes<HTMLButtonElement> {}\n\n/**\n * Submit button for the message composer.\n */\nexport const ComposerSubmit = forwardRef<HTMLButtonElement, ComposerSubmitProps>(\n ({ children, disabled, ...props }, ref) => {\n const { canSubmit, isSubmitting } = useComposer();\n\n return (\n <button\n ref={ref}\n type=\"submit\"\n disabled={disabled || !canSubmit}\n data-submitting={isSubmitting}\n {...props}\n >\n {children}\n </button>\n );\n }\n);\n\nComposerSubmit.displayName = \"ComposerSubmit\";\n\nexport { ComposerContext };\n","import { forwardRef, type HTMLAttributes } from \"react\";\nimport type { ParticipantRole } from \"../types\";\n\nexport interface AvatarProps extends HTMLAttributes<HTMLDivElement> {\n /** Name for fallback initials */\n name?: string;\n /** Image URL */\n src?: string;\n /** Alt text for image */\n alt?: string;\n /** Participant role for styling */\n role?: ParticipantRole;\n /** Fallback content when no image or name */\n fallback?: React.ReactNode;\n}\n\n/**\n * Get initials from a name.\n */\nfunction getInitials(name: string): string {\n const parts = name.trim().split(/\\s+/);\n if (parts.length === 1) {\n return parts[0].charAt(0).toUpperCase();\n }\n return (parts[0].charAt(0) + parts[parts.length - 1].charAt(0)).toUpperCase();\n}\n\n/**\n * Headless Avatar primitive.\n * Renders an image or fallback initials.\n */\nexport const Avatar = forwardRef<HTMLDivElement, AvatarProps>(\n ({ name, src, alt, role, fallback, children, ...props }, ref) => {\n const initials = name ? getInitials(name) : null;\n const altText = alt ?? name ?? role ?? \"Avatar\";\n\n return (\n <div ref={ref} data-role={role} {...props}>\n {children ?? (\n <>\n {src ? (\n <img src={src} alt={altText} style={{ width: \"100%\", height: \"100%\" }} />\n ) : (\n fallback ?? initials ?? role?.charAt(0).toUpperCase()\n )}\n </>\n )}\n </div>\n );\n }\n);\n\nAvatar.displayName = \"Avatar\";\n","import { forwardRef, type HTMLAttributes, type ReactNode } from \"react\";\n\nexport interface StreamingTextProps extends HTMLAttributes<HTMLDivElement> {\n /** The content to display */\n content: string;\n /** Whether the text is currently streaming */\n isStreaming?: boolean;\n /** Show a cursor indicator while streaming */\n showCursor?: boolean;\n /** Custom cursor element */\n cursor?: ReactNode;\n /** Children override (takes precedence over content) */\n children?: ReactNode;\n}\n\n/**\n * Headless StreamingText primitive.\n * Renders text with streaming indicator support.\n */\nexport const StreamingText = forwardRef<HTMLDivElement, StreamingTextProps>(\n (\n { content, isStreaming = false, showCursor = true, cursor, children, ...props },\n ref\n ) => {\n const defaultCursor = (\n <span\n aria-hidden=\"true\"\n style={{\n display: \"inline-block\",\n width: \"2px\",\n height: \"1em\",\n backgroundColor: \"currentColor\",\n marginLeft: \"2px\",\n verticalAlign: \"text-bottom\",\n animation: \"blink 1s step-end infinite\",\n }}\n />\n );\n\n return (\n <div ref={ref} data-streaming={isStreaming} {...props}>\n {children ?? content}\n {isStreaming && showCursor && (cursor ?? defaultCursor)}\n </div>\n );\n }\n);\n\nStreamingText.displayName = \"StreamingText\";\n","import {\n createContext,\n useContext,\n forwardRef,\n type ReactNode,\n type ButtonHTMLAttributes,\n} from \"react\";\nimport type { SuggestedAction } from \"../types\";\n\ninterface SuggestedActionsContextValue {\n actions: SuggestedAction[];\n onSelect: (action: SuggestedAction) => void;\n}\n\nconst SuggestedActionsContext = createContext<SuggestedActionsContextValue | null>(null);\n\n/**\n * Hook to access suggested actions context.\n */\nexport function useSuggestedActions() {\n const context = useContext(SuggestedActionsContext);\n if (!context) {\n throw new Error(\n \"useSuggestedActions must be used within a SuggestedActions component\"\n );\n }\n return context;\n}\n\nexport interface SuggestedActionsProps {\n /** List of suggested actions */\n actions: SuggestedAction[];\n /** Callback when an action is selected */\n onSelect: (action: SuggestedAction) => void;\n /** Children to render */\n children: ReactNode;\n /** Additional CSS classes */\n className?: string;\n}\n\n/**\n * Headless SuggestedActions primitive.\n * Provides context for rendering action buttons.\n */\nexport const SuggestedActions = forwardRef<HTMLDivElement, SuggestedActionsProps>(\n ({ actions, onSelect, children, className }, ref) => {\n if (actions.length === 0) {\n return null;\n }\n\n return (\n <SuggestedActionsContext.Provider value={{ actions, onSelect }}>\n <div ref={ref} role=\"group\" aria-label=\"Suggested actions\" className={className}>\n {children}\n </div>\n </SuggestedActionsContext.Provider>\n );\n }\n);\n\nSuggestedActions.displayName = \"SuggestedActions\";\n\nexport interface ActionButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {\n /** The action this button represents */\n action: SuggestedAction;\n /** Children to render inside button */\n children?: ReactNode;\n}\n\n/**\n * Button for a suggested action.\n */\nexport const ActionButton = forwardRef<HTMLButtonElement, ActionButtonProps>(\n ({ action, children, onClick, ...props }, ref) => {\n const { onSelect } = useSuggestedActions();\n\n const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n if (!e.defaultPrevented) {\n onSelect(action);\n }\n };\n\n return (\n <button ref={ref} type=\"button\" onClick={handleClick} {...props}>\n {children ?? action.label}\n </button>\n );\n }\n);\n\nActionButton.displayName = \"ActionButton\";\n\nexport { SuggestedActionsContext };\n","import { forwardRef, type HTMLAttributes, type ReactNode } from \"react\";\n\nexport interface TypingIndicatorProps extends HTMLAttributes<HTMLDivElement> {\n /** Custom content to show while typing */\n children?: ReactNode;\n /** Number of dots to show */\n dotCount?: number;\n}\n\n/**\n * Headless TypingIndicator primitive.\n * Shows animated dots or custom content.\n */\nexport const TypingIndicator = forwardRef<HTMLDivElement, TypingIndicatorProps>(\n ({ children, dotCount = 3, ...props }, ref) => {\n return (\n <div ref={ref} role=\"status\" aria-label=\"Assistant is typing\" {...props}>\n {children ?? (\n <span aria-hidden=\"true\">\n {Array.from({ length: dotCount }).map((_, i) => (\n <span\n key={i}\n style={{\n display: \"inline-block\",\n width: \"6px\",\n height: \"6px\",\n borderRadius: \"50%\",\n backgroundColor: \"currentColor\",\n marginRight: i < dotCount - 1 ? \"4px\" : 0,\n animation: `typing 1.4s infinite ease-in-out`,\n animationDelay: `${i * 0.2}s`,\n }}\n />\n ))}\n </span>\n )}\n </div>\n );\n }\n);\n\nTypingIndicator.displayName = \"TypingIndicator\";\n"]}
|