@hsafa/ui-sdk 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
- import {jsxs,jsx,Fragment}from'react/jsx-runtime';import ot,{createContext,useRef,useEffect,useState,useCallback,useMemo,useContext}from'react';import {createPortal}from'react-dom';import {useChat}from'@ai-sdk/react';import {DefaultChatTransport,lastAssistantMessageIsCompleteWithToolCalls}from'ai';import {Plus,History,ChevronRight,Trash2,File as File$1,Eye,X,Download}from'lucide-react';import {createRoot}from'react-dom/client';var Me={};var wo=({variant:e="primary",size:t="md",loading:n=false,disabled:o,children:r,className:l,...u})=>{let c=[Me.button,Me[e],Me[t],n&&Me.loading,l].filter(Boolean).join(" ");return jsxs("button",{className:c,disabled:o||n,...u,children:[n&&jsx("span",{className:Me.spinner}),jsx("span",{className:n?Me.hiddenText:void 0,children:r})]})};function Yt({show:e,onClick:t,resolvedColors:n,floatingButtonPosition:o}){if(!e)return null;let r={position:"fixed",bottom:typeof o.bottom=="number"?`${o.bottom}px`:o.bottom,right:o.right?typeof o.right=="number"?`${o.right}px`:o.right:void 0,top:o.top?typeof o.top=="number"?`${o.top}px`:o.top:void 0,left:o.left?typeof o.left=="number"?`${o.left}px`:o.left:void 0,zIndex:1e3};return jsx("button",{"aria-label":"Open chat",onClick:t,style:{...r,borderColor:n.borderColor,backgroundColor:n.accentColor,color:n.textColor,borderRadius:"50%",border:`1px solid ${n.borderColor}`,padding:"12px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)",transition:"all 0.2s",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:l=>{l.currentTarget.style.borderColor=n.primaryColor,l.currentTarget.style.backgroundColor=`${n.accentColor}dd`;},onMouseLeave:l=>{l.currentTarget.style.borderColor=n.borderColor,l.currentTarget.style.backgroundColor=n.accentColor;},children:jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})})}function Qt(e=true){let t=useRef(null),n=useRef(e);return useEffect(()=>{n.current=e;},[e]),useEffect(()=>{let o=t.current;if(!o)return;let r=new MutationObserver(()=>{n.current&&(o.scrollTop=o.scrollHeight);});return r.observe(o,{childList:true,subtree:true}),n.current&&(o.scrollTop=o.scrollHeight),()=>r.disconnect()},[]),t}function en(e,t){if(!e)return t;let n=e.endsWith("/")?e.slice(0,-1):e,o=t.startsWith("/")?t:`/${t}`;return `${n}${o}`}var It=25*1024*1024;function nn(e){let[t,n]=useState([]),[o,r]=useState(false),l=useRef(null),u=useCallback(f=>{if(!f||Number.isNaN(f))return "0 B";let b=["B","KB","MB","GB","TB"],g=Math.min(b.length-1,Math.floor(Math.log(f)/Math.log(1024)));return `${(f/Math.pow(1024,g)).toFixed(g===0?0:1)} ${b[g]}`},[]),c=useCallback(async f=>{let b=new FormData;b.append("file",f);let g=await fetch(en(e,"/api/uploads"),{method:"POST",body:b});if(!g.ok){let i=await g.text().catch(()=>"");throw new Error(i||`Failed to upload ${f.name}`)}let k=await g.json();return {id:k.id,name:k.name||f.name,url:k.url,mimeType:k.mimeType||f.type||"application/octet-stream",size:typeof k.size=="number"?k.size:f.size}},[e]),v=useCallback(f=>{n(b=>b.filter(g=>g.id!==f));},[]),S=useCallback(async(f,b)=>{if(!f)return;let g=Array.isArray(f)?f:Array.from(f);b(null),r(true);let k=[];try{for(let i of g){if(i.size>It){b(`"${i.name}" exceeds the ${u(It)} limit.`);continue}try{let m=await c(i);k.push(m);}catch(m){console.error("Failed to upload attachment:",m),b(String(m?.message??`Failed to upload ${i.name}`));}}k.length&&n(i=>[...i,...k]);}finally{r(false);}},[c,u]),a=useCallback((f,b)=>{let g=[],k=(f||"").trim();k&&g.push({type:"text",text:k});for(let i of b||[]){let m=i.mimeType||"application/octet-stream";m.startsWith("image/")?g.push({type:"image",image:new URL(i.url),mediaType:m}):g.push({type:"file",data:i.url,mediaType:m,name:i.name});}return g},[]),T=useCallback(()=>{n([]);},[]);return {attachments:t,uploading:o,fileInputRef:l,formatBytes:u,handleRemoveAttachment:v,handleFileSelection:S,buildUserContent:a,clearAttachments:T,MAX_UPLOAD_SIZE:It}}var rn=createContext(void 0);function lr({baseUrl:e,dir:t="ltr",theme:n="dark",children:o}){let[r,l]=useState(new Map),[u,c]=useState(new Map),[v,S]=useState(new Map),[a,T]=useState(new Map),f=useCallback((M,w)=>(l(y=>{let p=new Map(y);return p.set(String(M),w),p}),()=>{l(y=>{let p=new Map(y),F=p.get(String(M));return (!w||F===w)&&p.delete(String(M)),p});}),[]),b=useCallback((M,w)=>{l(y=>{let p=new Map(y),F=p.get(String(M));return (!w||F===w)&&p.delete(String(M)),p});},[]),g=useCallback((M,w)=>(c(y=>{let p=new Map(y);return p.set(String(M),w),p}),()=>{c(y=>{let p=new Map(y),F=p.get(String(M));return (!w||F===w)&&p.delete(String(M)),p});}),[]),k=useCallback((M,w)=>{c(y=>{let p=new Map(y),F=p.get(String(M));return (!w||F===w)&&p.delete(String(M)),p});},[]),i=useCallback((M,w)=>{S(y=>{let p=new Map(y);return w?p.set(M,true):p.delete(M),p});},[]),m=useCallback((M,w)=>{T(y=>{let p=new Map(y);return w?p.set(M,true):p.delete(M),p});},[]),h=useMemo(()=>Array.from(v.values()).some(M=>M),[v]),C=useMemo(()=>Array.from(a.values()).some(M=>M),[a]),E=useMemo(()=>({baseUrl:e,dir:t,theme:n,actions:r,components:u,registerAction:f,unregisterAction:b,registerComponent:g,unregisterComponent:k,isAnyStreaming:h,setStreamingState:i,isAnyChatOpen:C,setChatOpenState:m}),[e,t,n,r,u,f,b,g,k,h,i,C,m]);return jsx(rn.Provider,{value:E,children:o})}function Le(){let e=useContext(rn);return e||{baseUrl:void 0,actions:new Map,components:new Map,registerAction:()=>()=>{},unregisterAction:()=>{},registerComponent:()=>()=>{},unregisterComponent:()=>{},isAnyStreaming:false,setStreamingState:()=>{},isAnyChatOpen:false,setChatOpenState:()=>{}}}function le({IconComponent:e,...t}){return ot.createElement(e,t)}function Ft({icon:e,onClick:t,ariaLabel:n,resolvedColors:o,disabled:r=false,title:l}){return jsx("button",{"aria-label":n,title:l,disabled:r,style:{backgroundColor:"transparent",color:o.mutedTextColor,border:"none",borderRadius:"8px",padding:"8px",cursor:r?"not-allowed":"pointer",opacity:r?.5:1,transition:"all 0.2s ease-out",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:u=>{r||(u.currentTarget.style.backgroundColor=o.hoverBackground,u.currentTarget.style.color=o.textColor);},onMouseLeave:u=>{u.currentTarget.style.backgroundColor="transparent",u.currentTarget.style.color=o.mutedTextColor;},onClick:t,children:e})}function an({title:e,alwaysOpen:t,streaming:n,dir:o,resolvedColors:r,onNew:l,onToggleHistory:u,onClose:c,historyBtnRef:v,t:S}){return jsxs("div",{style:{marginBottom:"24px",display:"flex",alignItems:"center",justifyContent:"space-between",direction:o==="rtl"?"rtl":"ltr"},children:[jsx("div",{style:{minWidth:"0"},children:jsx("h1",{title:e,style:{color:r.textColor,fontSize:"18px",fontWeight:"600",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",margin:"0"},children:e})}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",position:"relative",color:r.mutedTextColor},children:[jsx(Ft,{icon:jsx(le,{IconComponent:Plus,size:"20",strokeWidth:"2"}),onClick:()=>{n||l();},ariaLabel:S("header.new"),resolvedColors:r,disabled:n}),jsx("button",{ref:v,"aria-label":S("header.history"),style:{backgroundColor:"transparent",color:r.mutedTextColor,border:"none",borderRadius:"8px",padding:"8px",cursor:"pointer",transition:"all 0.2s ease-out",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:a=>{a.currentTarget.style.backgroundColor=r.hoverBackground,a.currentTarget.style.color=r.textColor;},onMouseLeave:a=>{a.currentTarget.style.backgroundColor="transparent",a.currentTarget.style.color=r.mutedTextColor;},onClick:u,children:jsx(le,{IconComponent:History,size:"20",strokeWidth:"2"})}),!t&&jsx(Ft,{icon:jsx(le,{IconComponent:ChevronRight,size:"20",strokeWidth:"2",style:{transform:o==="rtl"?"rotate(180deg)":"none"}}),onClick:c,ariaLabel:S("header.close"),resolvedColors:r})]})]})}function cn({chart:e,theme:t}){let n=useRef(null),[o,r]=useState(null),[l,u]=useState(true);useEffect(()=>{let f=true;return (async()=>{try{u(!0),r(null);let g;try{g=await import('mermaid');}catch{throw new Error("Mermaid library not available")}if(!f)return;if(g.default?.initialize({startOnLoad:!1,theme:t==="dark"?"dark":"default",themeVariables:{darkMode:t==="dark",primaryColor:t==="dark"?"#3B82F6":"#1D4ED8",primaryTextColor:t==="dark"?"#F3F4F6":"#1F2937",primaryBorderColor:t==="dark"?"#374151":"#D1D5DB"},flowchart:{useMaxWidth:!0},sequence:{useMaxWidth:!0},gantt:{useMaxWidth:!0}}),n.current&&f){let k=`mermaid-${Date.now()}-${Math.random().toString(36).slice(2)}`,{svg:i}=await g.default.render(k,e);if(n.current&&f){n.current.innerHTML=i;let m=n.current.querySelector("svg");m&&(m.style.maxWidth="100%",m.style.height="auto",m.style.display="block");}}}catch(g){f&&r(g instanceof Error?g.message:"Failed to render diagram");}finally{f&&u(false);}})(),()=>{f=false;}},[e,t]);let c=t==="dark"?"#374151":"#D1D5DB",v=t==="dark"?"#1F2937":"#F9FAFB",S=t==="dark"?"#7F1D1D":"#FEF2F2",a=t==="dark"?"#FCA5A5":"#DC2626",T=t==="dark"?"#9CA3AF":"#6B7280";return o?jsxs("div",{style:{borderRadius:"12px",border:`1px solid ${c}`,backgroundColor:S,padding:"16px",margin:"8px 0"},children:[jsx("div",{style:{fontSize:"14px",color:a,marginBottom:"8px",fontWeight:"500"},children:"Failed to render diagram"}),jsx("div",{style:{fontSize:"12px",color:a,opacity:.8},children:o})]}):jsxs("div",{style:{borderRadius:"12px",border:`1px solid ${c}`,backgroundColor:v,padding:"16px",margin:"8px 0",overflow:"hidden"},children:[l&&jsx("div",{style:{fontSize:"14px",color:T,textAlign:"center",padding:"32px"},children:"Rendering diagram..."}),jsx("div",{ref:n,style:{display:l?"none":"block",textAlign:"center",minHeight:l?"0":"50px"}})]})}function ce(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function He(e){return e=e.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer" style="text-decoration: underline; color: inherit; opacity: 0.8;">$1</a>'),e=e.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),e=e.replace(/\*([^*\n]+)\*/g,"<em>$1</em>"),e=e.replace(/`([^`]+)`/g,'<code style="padding: 2px 4px; border-radius: 4px; background-color: rgba(0,0,0,0.1); font-family: monospace;">$1</code>'),e}function xr(e,t="dark"){let n=(e||"").replace(/\r\n/g,`
1
+ import {jsxs,jsx,Fragment}from'react/jsx-runtime';import qe,{createContext,useRef,useEffect,useState,useCallback,useMemo,useContext,Component}from'react';import {createPortal}from'react-dom';import {useChat}from'@ai-sdk/react';import {lastAssistantMessageIsCompleteWithToolCalls,DefaultChatTransport}from'ai';import {Plus,History,ChevronRight,Trash2,File as File$1,Eye,X,Download}from'lucide-react';import {createRoot}from'react-dom/client';var ge={};var gr=({variant:e="primary",size:t="md",loading:n=false,disabled:r,children:o,className:a,...s})=>{let l=[ge.button,ge[e],ge[t],n&&ge.loading,a].filter(Boolean).join(" ");return jsxs("button",{className:l,disabled:r||n,...s,children:[n&&jsx("span",{className:ge.spinner}),jsx("span",{className:n?ge.hiddenText:void 0,children:o})]})};function Dt({show:e,onClick:t,resolvedColors:n,floatingButtonPosition:r}){if(!e)return null;let o={position:"fixed",bottom:typeof r.bottom=="number"?`${r.bottom}px`:r.bottom,right:r.right?typeof r.right=="number"?`${r.right}px`:r.right:void 0,top:r.top?typeof r.top=="number"?`${r.top}px`:r.top:void 0,left:r.left?typeof r.left=="number"?`${r.left}px`:r.left:void 0,zIndex:1e3};return jsx("button",{"aria-label":"Open chat",onClick:t,style:{...o,borderColor:n.borderColor,backgroundColor:n.accentColor,color:n.textColor,borderRadius:"50%",border:`1px solid ${n.borderColor}`,padding:"12px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)",transition:"all 0.2s",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:a=>{a.currentTarget.style.borderColor=n.primaryColor,a.currentTarget.style.backgroundColor=`${n.accentColor}dd`;},onMouseLeave:a=>{a.currentTarget.style.borderColor=n.borderColor,a.currentTarget.style.backgroundColor=n.accentColor;},children:jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})})}function Wt(e=true){let t=useRef(null),n=useRef(e);return useEffect(()=>{n.current=e;},[e]),useEffect(()=>{let r=t.current;if(!r)return;let o=new MutationObserver(()=>{n.current&&(r.scrollTop=r.scrollHeight);});return o.observe(r,{childList:true,subtree:true}),n.current&&(r.scrollTop=r.scrollHeight),()=>o.disconnect()},[]),t}function Nt(e,t){if(!e)return t;let n=e.endsWith("/")?e.slice(0,-1):e,r=t.startsWith("/")?t:`/${t}`;return `${n}${r}`}var gt=25*1024*1024;function Gt(e){let[t,n]=useState([]),[r,o]=useState(false),a=useRef(null),s=useCallback(x=>{if(!x||Number.isNaN(x))return "0 B";let f=["B","KB","MB","GB","TB"],u=Math.min(f.length-1,Math.floor(Math.log(x)/Math.log(1024)));return `${(x/Math.pow(1024,u)).toFixed(u===0?0:1)} ${f[u]}`},[]),l=useCallback(async x=>{let f=new FormData;f.append("file",x);let u=await fetch(Nt(e,"/api/uploads"),{method:"POST",body:f});if(!u.ok){let i=await u.text().catch(()=>"");throw new Error(i||`Failed to upload ${x.name}`)}let w=await u.json();return {id:w.id,name:w.name||x.name,url:w.url,mimeType:w.mimeType||x.type||"application/octet-stream",size:typeof w.size=="number"?w.size:x.size}},[e]),T=useCallback(x=>{n(f=>f.filter(u=>u.id!==x));},[]),I=useCallback(async(x,f)=>{if(!x)return;let u=Array.isArray(x)?x:Array.from(x);f(null),o(true);let w=[];try{for(let i of u){if(i.size>gt){f(`"${i.name}" exceeds the ${s(gt)} limit.`);continue}try{let h=await l(i);w.push(h);}catch(h){console.error("Failed to upload attachment:",h),f(String(h?.message??`Failed to upload ${i.name}`));}}w.length&&n(i=>[...i,...w]);}finally{o(false);}},[l,s]),C=useCallback((x,f)=>{let u=[],w=(x||"").trim();w&&u.push({type:"text",text:w});for(let i of f||[]){let h=i.mimeType||"application/octet-stream";h.startsWith("image/")?u.push({type:"image",image:new URL(i.url),mediaType:h}):u.push({type:"file",data:i.url,mediaType:h,name:i.name});}return u},[]),d=useCallback(()=>{n([]);},[]);return {attachments:t,uploading:r,fileInputRef:a,formatBytes:s,handleRemoveAttachment:T,handleFileSelection:I,buildUserContent:C,clearAttachments:d,MAX_UPLOAD_SIZE:gt}}var Ut=createContext(void 0);function Yn({baseUrl:e,dir:t="ltr",theme:n="dark",children:r}){let[o,a]=useState(new Map),[s,l]=useState(new Map),[T,I]=useState(new Map),[C,d]=useState(new Map),x=useCallback((v,k)=>(a(b=>{let m=new Map(b);return m.set(String(v),k),m}),()=>{a(b=>{let m=new Map(b),A=m.get(String(v));return (!k||A===k)&&m.delete(String(v)),m});}),[]),f=useCallback((v,k)=>{a(b=>{let m=new Map(b),A=m.get(String(v));return (!k||A===k)&&m.delete(String(v)),m});},[]),u=useCallback((v,k)=>(l(b=>{let m=new Map(b);return m.set(String(v),k),m}),()=>{l(b=>{let m=new Map(b),A=m.get(String(v));return (!k||A===k)&&m.delete(String(v)),m});}),[]),w=useCallback((v,k)=>{l(b=>{let m=new Map(b),A=m.get(String(v));return (!k||A===k)&&m.delete(String(v)),m});},[]),i=useCallback((v,k)=>{I(b=>{let m=new Map(b);return k?m.set(v,true):m.delete(v),m});},[]),h=useCallback((v,k)=>{d(b=>{let m=new Map(b);return k?m.set(v,true):m.delete(v),m});},[]),p=useMemo(()=>Array.from(T.values()).some(v=>v),[T]),g=useMemo(()=>Array.from(C.values()).some(v=>v),[C]),y=useMemo(()=>({baseUrl:e,dir:t,theme:n,actions:o,components:s,registerAction:x,unregisterAction:f,registerComponent:u,unregisterComponent:w,isAnyStreaming:p,setStreamingState:i,isAnyChatOpen:g,setChatOpenState:h}),[e,t,n,o,s,x,f,u,w,p,i,g,h]);return jsx(Ut.Provider,{value:y,children:r})}function ke(){let e=useContext(Ut);return e||{baseUrl:void 0,actions:new Map,components:new Map,registerAction:()=>()=>{},unregisterAction:()=>{},registerComponent:()=>()=>{},unregisterComponent:()=>{},isAnyStreaming:false,setStreamingState:()=>{},isAnyChatOpen:false,setChatOpenState:()=>{}}}function ee({IconComponent:e,...t}){return qe.createElement(e,t)}function yt({icon:e,onClick:t,ariaLabel:n,resolvedColors:r,disabled:o=false,title:a}){return jsx("button",{"aria-label":n,title:a,disabled:o,style:{backgroundColor:"transparent",color:r.mutedTextColor,border:"none",borderRadius:"8px",padding:"8px",cursor:o?"not-allowed":"pointer",opacity:o?.5:1,transition:"all 0.2s ease-out",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:s=>{o||(s.currentTarget.style.backgroundColor=r.hoverBackground,s.currentTarget.style.color=r.textColor);},onMouseLeave:s=>{s.currentTarget.style.backgroundColor="transparent",s.currentTarget.style.color=r.mutedTextColor;},onClick:t,children:e})}function qt({title:e,alwaysOpen:t,streaming:n,dir:r,resolvedColors:o,onNew:a,onToggleHistory:s,onClose:l,historyBtnRef:T,t:I}){return jsxs("div",{style:{marginBottom:"24px",display:"flex",alignItems:"center",justifyContent:"space-between",direction:r==="rtl"?"rtl":"ltr"},children:[jsx("div",{style:{minWidth:"0"},children:jsx("h1",{title:e,style:{color:o.textColor,fontSize:"18px",fontWeight:"600",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",margin:"0"},children:e})}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",position:"relative",color:o.mutedTextColor},children:[jsx(yt,{icon:jsx(ee,{IconComponent:Plus,size:"20",strokeWidth:"2"}),onClick:()=>{n||a();},ariaLabel:I("header.new"),resolvedColors:o,disabled:n}),jsx("button",{ref:T,"aria-label":I("header.history"),style:{backgroundColor:"transparent",color:o.mutedTextColor,border:"none",borderRadius:"8px",padding:"8px",cursor:"pointer",transition:"all 0.2s ease-out",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:C=>{C.currentTarget.style.backgroundColor=o.hoverBackground,C.currentTarget.style.color=o.textColor;},onMouseLeave:C=>{C.currentTarget.style.backgroundColor="transparent",C.currentTarget.style.color=o.mutedTextColor;},onClick:s,children:jsx(ee,{IconComponent:History,size:"20",strokeWidth:"2"})}),!t&&jsx(yt,{icon:jsx(ee,{IconComponent:ChevronRight,size:"20",strokeWidth:"2",style:{transform:r==="rtl"?"rotate(180deg)":"none"}}),onClick:l,ariaLabel:I("header.close"),resolvedColors:o})]})]})}function Vt({chart:e,theme:t}){let n=useRef(null),[r,o]=useState(null),[a,s]=useState(true);useEffect(()=>{let x=true;return (async()=>{try{s(!0),o(null);let u;try{u=await import('mermaid');}catch{throw new Error("Mermaid library not available")}if(!x)return;if(u.default?.initialize({startOnLoad:!1,theme:t==="dark"?"dark":"default",themeVariables:{darkMode:t==="dark",primaryColor:t==="dark"?"#3B82F6":"#1D4ED8",primaryTextColor:t==="dark"?"#F3F4F6":"#1F2937",primaryBorderColor:t==="dark"?"#374151":"#D1D5DB"},flowchart:{useMaxWidth:!0},sequence:{useMaxWidth:!0},gantt:{useMaxWidth:!0}}),n.current&&x){let w=`mermaid-${Date.now()}-${Math.random().toString(36).slice(2)}`,{svg:i}=await u.default.render(w,e);if(n.current&&x){n.current.innerHTML=i;let h=n.current.querySelector("svg");h&&(h.style.maxWidth="100%",h.style.height="auto",h.style.display="block");}}}catch(u){x&&o(u instanceof Error?u.message:"Failed to render diagram");}finally{x&&s(false);}})(),()=>{x=false;}},[e,t]);let l=t==="dark"?"#374151":"#D1D5DB",T=t==="dark"?"#1F2937":"#F9FAFB",I=t==="dark"?"#7F1D1D":"#FEF2F2",C=t==="dark"?"#FCA5A5":"#DC2626",d=t==="dark"?"#9CA3AF":"#6B7280";return r?jsxs("div",{style:{borderRadius:"12px",border:`1px solid ${l}`,backgroundColor:I,padding:"16px",margin:"8px 0"},children:[jsx("div",{style:{fontSize:"14px",color:C,marginBottom:"8px",fontWeight:"500"},children:"Failed to render diagram"}),jsx("div",{style:{fontSize:"12px",color:C,opacity:.8},children:r})]}):jsxs("div",{style:{borderRadius:"12px",border:`1px solid ${l}`,backgroundColor:T,padding:"16px",margin:"8px 0",overflow:"hidden"},children:[a&&jsx("div",{style:{fontSize:"14px",color:d,textAlign:"center",padding:"32px"},children:"Rendering diagram..."}),jsx("div",{ref:n,style:{display:a?"none":"block",textAlign:"center",minHeight:a?"0":"50px"}})]})}function te(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function ve(e){return e=e.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer" style="text-decoration: underline; color: inherit; opacity: 0.8;">$1</a>'),e=e.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),e=e.replace(/\*([^*\n]+)\*/g,"<em>$1</em>"),e=e.replace(/`([^`]+)`/g,'<code style="padding: 2px 4px; border-radius: 4px; background-color: rgba(0,0,0,0.1); font-family: monospace;">$1</code>'),e}function ao(e,t="dark"){let n=(e||"").replace(/\r\n/g,`
2
2
  `).split(`
3
- `),o="",r=false,l="",u=[],c=false,v=false,S=false,a=t==="dark"?"#374151":"#D1D5DB",f=t==="dark"?"#111827":"#F3F4F6",b=t==="dark"?"#E5E7EB":"#374151",g=t==="dark"?"#374151":"#F3F4F6",k=t==="dark"?"#F9FAFB":"#111827",i=()=>{c&&(o+="</ul>",c=false),v&&(o+="</ol>",v=false);},m=y=>{for(let p=y;p<n.length;p++)if(n[p].trim().length>0)return p;return -1},h=y=>{let p=y.trim(),F=p.startsWith("|")?p.slice(1):p;return (F.endsWith("|")?F.slice(0,-1):F).split("|").map(q=>q.trim())},C=y=>{let p=y.trim();if(!p.startsWith("|"))return false;let F=h(p);return F.length>=2&&F.some(U=>U.length>0)},E=y=>{let p=h(y);return p.length===0?false:p.every(F=>/^:?-{3,}:?$/.test(F))},M=y=>{let p=y.startsWith(":"),F=y.endsWith(":");return p&&F?"center":!p&&F?"right":"left"},w=y=>{let p=y,F=m(p+1);if(F===-1)return {tableHtml:"",endIndex:y};let U=h(n[p]),q=h(n[F]),Z=Math.max(U.length,q.length),z=[];for(let $=0;$<Z;$++){let H=q[$]||"---";z.push(M(H));}let Q=[],V=F+1;for(;V<n.length;){let $=n[V].trim();if($.length===0){V++;continue}if(!$.startsWith("|"))break;let H=h(n[V]),N=[];for(let L=0;L<Z;L++)N.push(H[L]??"");Q.push(N),V++;}let ee=`<div style="overflow: auto; max-width: 100%; max-height: 60vh; border-radius: 10px; margin: 8px 0;">
4
- <table style="width: 100%; min-width: max-content; border-collapse: separate; border-spacing: 0; margin: 0;">`;ee+="<thead><tr>";for(let $=0;$<Z;$++){let H=He(ce(U[$]??"")),N=z[$],L=$===0,ge=$===Z-1;ee+=`<th style="text-align: ${N}; padding: 10px 12px; border-bottom: 1px solid ${a}; background-color: ${g}; color: ${k}; position: sticky; top: 0; z-index: 1; ${`${L?"border-top-left-radius: 10px;":""}${ge?"border-top-right-radius: 10px;":""}`}">${H}</th>`;}ee+="</tr></thead>",ee+="<tbody>";for(let $ of Q){ee+="<tr>";for(let H=0;H<Z;H++){let N=He(ce($[H]??"")),L=z[H],ge=H===0;ee+=`<td style="text-align: ${L}; padding: 10px 12px; border-bottom: 1px solid ${a}; ${ge?`border-left: 1px solid ${a};`:""} border-right: 1px solid ${a};">${N}</td>`;}ee+="</tr>";}return ee+="</tbody></table></div>",{tableHtml:ee,endIndex:V-1}};for(let y=0;y<n.length;y++){let p=n[y],F=p.match(/^```\s*(\w+)?\s*$/);if(F){if(!r)i(),r=true,l=F[1]?String(F[1]):"",u=[];else {if(l==="mermaid"){S=true;let z=u.join(`
5
- `);o+=`<div class="mermaid-placeholder" data-mermaid="${ce(z)}"></div>`;}else {let z=ce(u.join(`
6
- `)),Q=l?`language-${l}`:"";o+=`<pre style="border-radius: 8px; padding: 12px; background-color: ${f}; color: ${b}; border: 1px solid ${a}; overflow-x: auto; white-space: pre-wrap; word-break: break-all;"><code class="${Q}">${z}</code></pre>`;}r=false,l="",u=[];}continue}if(r){u.push(p);continue}if(/^\s*(---|\*\*\*|___)\s*$/.test(p)){i(),o+='<hr style="margin: 12px 0; opacity: 0.6; border: none; border-top: 1px solid currentColor;" />';continue}let U=p.match(/^(#{1,6})\s+(.+)$/);if(U){i();let z=U[1].length,Q=He(ce(U[2].trim())),V=z<=2?"18px":z===3?"16px":"14px";o+=`<h${z} style="font-size: ${V}; font-weight: 600; margin: 8px 0 4px 0;">${Q}</h${z}>`;continue}if(C(p)){let z=m(y+1);if(z!==-1&&E(n[z])){i();let{tableHtml:Q,endIndex:V}=w(y);if(Q){o+=Q,y=V;continue}}}let q=p.match(/^\s*[-*]\s+(.+)$/),Z=p.match(/^\s*\d+\.\s+(.+)$/);if(q){c||(i(),o+='<ul style="list-style-type: disc; padding-left: 24px; margin: 4px 0;">',c=true);let z=He(ce(q[1]));o+=`<li style="margin: 2px 0;">${z}</li>`;continue}if(Z){v||(i(),o+='<ol style="list-style-type: decimal; padding-left: 24px; margin: 4px 0;">',v=true);let z=He(ce(Z[1]));o+=`<li style="margin: 2px 0;">${z}</li>`;continue}if(p.trim().length===0)i(),o+='<div style="height: 8px;"></div>';else {i();let z=He(ce(p));o+=`<p style="line-height: 1.6; margin: 4px 0; word-break: break-word;">${z}</p>`;}}if(r)if(l==="mermaid"){S=true;let y=u.join(`
7
- `);o+=`<div class="mermaid-placeholder" data-mermaid="${ce(y)}"></div>`;}else {let y=ce(u.join(`
8
- `)),p=l?`language-${l}`:"";o+=`<pre style="border-radius: 8px; padding: 12px; background-color: ${f}; color: ${b}; border: 1px solid ${a}; overflow-x: auto; white-space: pre-wrap; word-break: break-all;"><code class="${p}">${y}</code></pre>`;}return c&&(o+="</ul>"),v&&(o+="</ol>"),{html:o,hasMermaid:S}}function it({content:e,theme:t}){let{html:n,hasMermaid:o}=useMemo(()=>xr(e,t),[e,t]);if(!o)return jsx("div",{style:{fontSize:"14px",lineHeight:"1.6",wordBreak:"break-word",maxWidth:"100%",overflow:"hidden"},dangerouslySetInnerHTML:{__html:n}});let r=n.split(/(<div class="mermaid-placeholder"[^>]*><\/div>)/g),l=[];return r.forEach((u,c)=>{if(u.includes("mermaid-placeholder")){let v=u.match(/data-mermaid="([^"]*)"/);if(v){let S=v[1].replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&#39;/g,"'");l.push(ot.createElement(cn,{key:`mermaid-${c}`,chart:S,theme:t}));}}else u.trim()&&l.push(ot.createElement("div",{key:`html-${c}`,style:{fontSize:"14px",lineHeight:"1.6",wordBreak:"break-word",maxWidth:"100%",overflow:"hidden"},dangerouslySetInnerHTML:{__html:u}}));}),ot.createElement(ot.Fragment,{},...l)}var Cr=e=>{let t={"input-streaming":{color:"#eab308",text:"Inputting"},"input-available":{color:"#3b82f6",text:"Running"},error:{color:"#ef4444",text:"Error"},"output-available":{color:"#10b981",text:"Called"},finished:{color:"#10b981",text:"Called"}};return t[e||"output-available"]||t["output-available"]};function dn({parts:e,messageId:t,openReasoningIds:n,toggleReasoning:o,resolvedColors:r}){let l=[],u=[],c,v,S=false;for(let a of Array.isArray(e)?e:[]){if(!a)continue;if(a.type==="reasoning"&&typeof a.text=="string"){u.push(a.text),c||(c=a.startDate),v=a.endDate,a.state==="done"&&(S=true);continue}let T=a.type==="dynamic-tool",f=typeof a.type=="string"&&a.type.startsWith("tool-");if(T||f||a.type==="tool-call"){u.length&&(l.push({type:"reasoning",texts:u,startDate:c,endDate:v,isCompleted:S}),u=[],c=void 0,v=void 0,S=false);let b=String(T?a.toolName||"dynamic-tool":f?a.type?.slice(5)||"tool":a.toolName||"tool");b==="getFromUser"||b==="get_from_user"?l.push({type:"tool",toolName:b,status:a.state||a.status,input:a.input,output:a.output,startDate:a.startDate,endDate:a.endDate,toolCallId:a.toolCallId}):l.push({type:"tool",toolName:b,status:a.state||a.status,input:a.input,output:a.output,startDate:a.startDate,endDate:a.endDate});continue}}return u.length&&l.push({type:"reasoning",texts:u,startDate:c,endDate:v,isCompleted:S}),l.length?jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[l.map((a,T)=>{let f=`${t}-${T}`,b=n.has(f);if(a.type==="reasoning"){let h=a.isCompleted||typeof a.startDate=="number"&&typeof a.endDate=="number",C=a.texts&&a.texts.length>0&&a.texts.some(M=>M.trim().length>0),E=()=>{C&&o(f);};return h&&!C?null:jsx("div",{onClick:E,style:{cursor:C?"pointer":"default",padding:"0"},children:jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[jsxs("div",{style:{fontSize:"13px",color:r.mutedTextColor,fontWeight:500,display:"flex",alignItems:"center",gap:"6px",overflow:"hidden",maxWidth:"100%",minWidth:0,width:"100%"},children:[jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px"},children:[!h&&jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:r.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),jsx("span",{style:{color:r.textColor,fontWeight:600,opacity:.9,background:h?"none":`linear-gradient(90deg, ${r.textColor}, ${r.mutedTextColor}, ${r.mutedTextColor})`,backgroundSize:h?"auto":"200% 100%",backgroundClip:h?"unset":"text",WebkitBackgroundClip:h?"unset":"text",WebkitTextFillColor:h?r.mutedTextColor:"transparent",animation:h?void 0:"shimmer 2s ease-in-out infinite"},children:h?"Finish Thinking":"Thinking"})]}),C&&jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:b?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease-out"},children:jsx("polyline",{points:"9 18 15 12 9 6"})})]}),jsx("div",{style:{display:"grid",gridTemplateRows:b||!h?"1fr":"0fr",transition:"grid-template-rows 0.2s ease-out",overflow:"hidden"},children:jsx("div",{style:{minHeight:0},children:a.texts&&a.texts.length>0?jsx("div",{style:{fontSize:"13px",color:r.mutedTextColor,lineHeight:"1.6",maxWidth:"100%"},children:(!h&&b?a.texts:h?b?a.texts:[]:[a.texts[a.texts.length-1]]).map((M,w)=>jsx("div",{style:{marginBottom:"6px"},children:jsx(it,{content:M,theme:"dark"})},`rg-line-${T}-${w}`))}):jsxs("div",{style:{fontSize:"12px",color:r.mutedTextColor,opacity:.7,display:"flex",alignItems:"center",gap:"8px"},children:[jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:r.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),jsx("span",{style:{letterSpacing:"2px",animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"},children:"..."})]})})})]})},f)}let{color:g,text:k}=Cr(a.status),i=a.status==="input-streaming"||a.status==="input-available",m=a.toolName==="getFromUser"||a.toolName==="get_from_user";return jsx("div",{style:{display:"flex",gap:"12px",position:"relative"},children:jsxs("div",{style:{flex:1,minWidth:0},children:[jsxs("div",{style:{fontSize:"13px",color:r.mutedTextColor,display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"},children:[jsxs("span",{style:{fontWeight:600,color:g,display:"flex",alignItems:"center",gap:"6px"},children:[jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:g,animation:i?"pulse 1.5s ease-in-out infinite":void 0}}),k]}),jsx("span",{style:{fontWeight:500,color:r.textColor},children:a.toolName||"tool"})]}),m?jsx("div",{style:{marginTop:"8px"},children:jsx("div",{"data-get-from-user-host":a.toolCallId||f,style:{width:"100%"}})}):null]})},f)}),jsx("style",{children:`
3
+ `),r="",o=false,a="",s=[],l=false,T=false,I=false,C=t==="dark"?"#374151":"#D1D5DB",x=t==="dark"?"#111827":"#F3F4F6",f=t==="dark"?"#E5E7EB":"#374151",u=t==="dark"?"#374151":"#F3F4F6",w=t==="dark"?"#F9FAFB":"#111827",i=()=>{l&&(r+="</ul>",l=false),T&&(r+="</ol>",T=false);},h=b=>{for(let m=b;m<n.length;m++)if(n[m].trim().length>0)return m;return -1},p=b=>{let m=b.trim(),A=m.startsWith("|")?m.slice(1):m;return (A.endsWith("|")?A.slice(0,-1):A).split("|").map(O=>O.trim())},g=b=>{let m=b.trim();if(!m.startsWith("|"))return false;let A=p(m);return A.length>=2&&A.some(M=>M.length>0)},y=b=>{let m=p(b);return m.length===0?false:m.every(A=>/^:?-{3,}:?$/.test(A))},v=b=>{let m=b.startsWith(":"),A=b.endsWith(":");return m&&A?"center":!m&&A?"right":"left"},k=b=>{let m=b,A=h(m+1);if(A===-1)return {tableHtml:"",endIndex:b};let M=p(n[m]),O=p(n[A]),G=Math.max(M.length,O.length),D=[];for(let R=0;R<G;R++){let $=O[R]||"---";D.push(v($));}let q=[],U=A+1;for(;U<n.length;){let R=n[U].trim();if(R.length===0){U++;continue}if(!R.startsWith("|"))break;let $=p(n[U]),P=[];for(let F=0;F<G;F++)P.push($[F]??"");q.push(P),U++;}let _=`<div style="overflow: auto; max-width: 100%; max-height: 60vh; border-radius: 10px; margin: 8px 0;">
4
+ <table style="width: 100%; min-width: max-content; border-collapse: separate; border-spacing: 0; margin: 0;">`;_+="<thead><tr>";for(let R=0;R<G;R++){let $=ve(te(M[R]??"")),P=D[R],F=R===0,ie=R===G-1;_+=`<th style="text-align: ${P}; padding: 10px 12px; border-bottom: 1px solid ${C}; background-color: ${u}; color: ${w}; position: sticky; top: 0; z-index: 1; ${`${F?"border-top-left-radius: 10px;":""}${ie?"border-top-right-radius: 10px;":""}`}">${$}</th>`;}_+="</tr></thead>",_+="<tbody>";for(let R of q){_+="<tr>";for(let $=0;$<G;$++){let P=ve(te(R[$]??"")),F=D[$],ie=$===0;_+=`<td style="text-align: ${F}; padding: 10px 12px; border-bottom: 1px solid ${C}; ${ie?`border-left: 1px solid ${C};`:""} border-right: 1px solid ${C};">${P}</td>`;}_+="</tr>";}return _+="</tbody></table></div>",{tableHtml:_,endIndex:U-1}};for(let b=0;b<n.length;b++){let m=n[b],A=m.match(/^```\s*(\w+)?\s*$/);if(A){if(!o)i(),o=true,a=A[1]?String(A[1]):"",s=[];else {if(a==="mermaid"){I=true;let D=s.join(`
5
+ `);r+=`<div class="mermaid-placeholder" data-mermaid="${te(D)}"></div>`;}else {let D=te(s.join(`
6
+ `)),q=a?`language-${a}`:"";r+=`<pre style="border-radius: 8px; padding: 12px; background-color: ${x}; color: ${f}; border: 1px solid ${C}; overflow-x: auto; white-space: pre-wrap; word-break: break-all;"><code class="${q}">${D}</code></pre>`;}o=false,a="",s=[];}continue}if(o){s.push(m);continue}if(/^\s*(---|\*\*\*|___)\s*$/.test(m)){i(),r+='<hr style="margin: 12px 0; opacity: 0.6; border: none; border-top: 1px solid currentColor;" />';continue}let M=m.match(/^(#{1,6})\s+(.+)$/);if(M){i();let D=M[1].length,q=ve(te(M[2].trim())),U=D<=2?"18px":D===3?"16px":"14px";r+=`<h${D} style="font-size: ${U}; font-weight: 600; margin: 8px 0 4px 0;">${q}</h${D}>`;continue}if(g(m)){let D=h(b+1);if(D!==-1&&y(n[D])){i();let{tableHtml:q,endIndex:U}=k(b);if(q){r+=q,b=U;continue}}}let O=m.match(/^\s*[-*]\s+(.+)$/),G=m.match(/^\s*\d+\.\s+(.+)$/);if(O){l||(i(),r+='<ul style="list-style-type: disc; padding-left: 24px; margin: 4px 0;">',l=true);let D=ve(te(O[1]));r+=`<li style="margin: 2px 0;">${D}</li>`;continue}if(G){T||(i(),r+='<ol style="list-style-type: decimal; padding-left: 24px; margin: 4px 0;">',T=true);let D=ve(te(G[1]));r+=`<li style="margin: 2px 0;">${D}</li>`;continue}if(m.trim().length===0)i(),r+='<div style="height: 8px;"></div>';else {i();let D=ve(te(m));r+=`<p style="line-height: 1.6; margin: 4px 0; word-break: break-word;">${D}</p>`;}}if(o)if(a==="mermaid"){I=true;let b=s.join(`
7
+ `);r+=`<div class="mermaid-placeholder" data-mermaid="${te(b)}"></div>`;}else {let b=te(s.join(`
8
+ `)),m=a?`language-${a}`:"";r+=`<pre style="border-radius: 8px; padding: 12px; background-color: ${x}; color: ${f}; border: 1px solid ${C}; overflow-x: auto; white-space: pre-wrap; word-break: break-all;"><code class="${m}">${b}</code></pre>`;}return l&&(r+="</ul>"),T&&(r+="</ol>"),{html:r,hasMermaid:I}}function _e({content:e,theme:t}){let{html:n,hasMermaid:r}=useMemo(()=>ao(e,t),[e,t]);if(!r)return jsx("div",{style:{fontSize:"14px",lineHeight:"1.6",wordBreak:"break-word",maxWidth:"100%",overflow:"hidden"},dangerouslySetInnerHTML:{__html:n}});let o=n.split(/(<div class="mermaid-placeholder"[^>]*><\/div>)/g),a=[];return o.forEach((s,l)=>{if(s.includes("mermaid-placeholder")){let T=s.match(/data-mermaid="([^"]*)"/);if(T){let I=T[1].replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&#39;/g,"'");a.push(qe.createElement(Vt,{key:`mermaid-${l}`,chart:I,theme:t}));}}else s.trim()&&a.push(qe.createElement("div",{key:`html-${l}`,style:{fontSize:"14px",lineHeight:"1.6",wordBreak:"break-word",maxWidth:"100%",overflow:"hidden"},dangerouslySetInnerHTML:{__html:s}}));}),qe.createElement(qe.Fragment,{},...a)}var Re=class extends Component{constructor(t){super(t),this.state={hasError:false,error:null,errorInfo:null};}static getDerivedStateFromError(t){return {hasError:true,error:t,errorInfo:null}}componentDidCatch(t,n){console.error(`UI Component Error (${this.props.componentName}):`,t,n),this.setState({error:t,errorInfo:n});}render(){if(this.state.hasError&&this.state.error){let{resolvedColors:t,componentName:n}=this.props;return jsxs("div",{style:{padding:"16px",backgroundColor:"#fee2e2",border:"2px solid #ef4444",borderRadius:"12px",color:"#991b1b"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},children:[jsx("span",{style:{fontSize:"20px"},children:"\u26A0\uFE0F"}),jsxs("strong",{style:{fontSize:"16px"},children:["Component Error: ",n]})]}),jsx("div",{style:{fontSize:"14px",marginBottom:"8px",fontFamily:"monospace"},children:this.state.error.message}),this.state.errorInfo&&jsxs("details",{style:{fontSize:"12px",marginTop:"8px"},children:[jsx("summary",{style:{cursor:"pointer",fontWeight:"bold"},children:"Stack Trace"}),jsx("pre",{style:{marginTop:"8px",padding:"8px",backgroundColor:"#fef2f2",borderRadius:"4px",overflow:"auto",maxHeight:"200px",fontSize:"11px"},children:this.state.errorInfo.componentStack})]})]})}return this.props.children}};var co=e=>{let t={"input-streaming":{color:"#eab308",text:"Inputting"},"input-available":{color:"#3b82f6",text:"Running"},error:{color:"#ef4444",text:"Error"},"output-available":{color:"#10b981",text:"Called"},finished:{color:"#10b981",text:"Called"}};return t[e||"output-available"]||t["output-available"]};function Xt({parts:e,messageId:t,openReasoningIds:n,toggleReasoning:r,resolvedColors:o,HsafaUI:a}){let s=[],l=[],T,I,C=false;for(let d of Array.isArray(e)?e:[]){if(!d)continue;if(d.type==="reasoning"&&typeof d.text=="string"){l.push(d.text),T||(T=d.startDate),I=d.endDate,d.state==="done"&&(C=true);continue}let x=d.type==="dynamic-tool",f=typeof d.type=="string"&&d.type.startsWith("tool-");if(x||f||d.type==="tool-call"){l.length&&(s.push({type:"reasoning",texts:l,startDate:T,endDate:I,isCompleted:C}),l=[],T=void 0,I=void 0,C=false);let u=String(x?d.toolName||"dynamic-tool":f?d.type?.slice(5)||"tool":d.toolName||"tool");u==="requestInput"?s.push({type:"tool",toolName:u,status:d.state||d.status,input:d.input,output:d.output,startDate:d.startDate,endDate:d.endDate,toolCallId:d.toolCallId}):s.push({type:"tool",toolName:u,status:d.state||d.status,input:d.input,output:d.output,startDate:d.startDate,endDate:d.endDate});continue}}return l.length&&s.push({type:"reasoning",texts:l,startDate:T,endDate:I,isCompleted:C}),s.length?jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[s.map((d,x)=>{let f=`${t}-${x}`,u=n.has(f);if(d.type==="reasoning"){let p=d.isCompleted||typeof d.startDate=="number"&&typeof d.endDate=="number",g=d.texts&&d.texts.length>0&&d.texts.some(v=>v.trim().length>0),y=()=>{g&&r(f);};return p&&!g?null:jsx("div",{onClick:y,style:{cursor:g?"pointer":"default",padding:"0"},children:jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[jsxs("div",{style:{fontSize:"13px",color:o.mutedTextColor,fontWeight:500,display:"flex",alignItems:"center",gap:"6px",overflow:"hidden",maxWidth:"100%",minWidth:0,width:"100%"},children:[jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px"},children:[!p&&jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),jsx("span",{style:{color:o.textColor,fontWeight:600,opacity:.9,background:p?"none":`linear-gradient(90deg, ${o.textColor}, ${o.mutedTextColor}, ${o.mutedTextColor})`,backgroundSize:p?"auto":"200% 100%",backgroundClip:p?"unset":"text",WebkitBackgroundClip:p?"unset":"text",WebkitTextFillColor:p?o.mutedTextColor:"transparent",animation:p?void 0:"shimmer 2s ease-in-out infinite"},children:p?"Finish Thinking":"Thinking"})]}),g&&jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:u?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease-out"},children:jsx("polyline",{points:"9 18 15 12 9 6"})})]}),jsx("div",{style:{display:"grid",gridTemplateRows:u||!p?"1fr":"0fr",transition:"grid-template-rows 0.2s ease-out",overflow:"hidden"},children:jsx("div",{style:{minHeight:0},children:d.texts&&d.texts.length>0?jsx("div",{style:{fontSize:"13px",color:o.mutedTextColor,lineHeight:"1.6",maxWidth:"100%"},children:(!p&&u?d.texts:p?u?d.texts:[]:[d.texts[d.texts.length-1]]).map((v,k)=>jsx("div",{style:{marginBottom:"6px"},children:jsx(_e,{content:v,theme:"dark"})},`rg-line-${x}-${k}`))}):jsxs("div",{style:{fontSize:"12px",color:o.mutedTextColor,opacity:.7,display:"flex",alignItems:"center",gap:"8px"},children:[jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),jsx("span",{style:{letterSpacing:"2px",animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"},children:"..."})]})})})]})},f)}let{color:w,text:i}=co(d.status),h=d.status==="input-streaming"||d.status==="input-available";switch(d.toolName){case "requestInput":return jsx("div",{style:{display:"block",position:"relative"},children:jsx("div",{"data-get-from-user-host":d.toolCallId||f,style:{width:"100%"}})},f);case "ui":{let p=d.input?.component||d.input?.componentName,g=a?.[p];return g?jsx("div",{style:{display:"block",position:"relative",padding:"12px",backgroundColor:o.inputBackground,borderRadius:"12px",border:`1px solid ${o.borderColor}`},children:jsx(Re,{componentName:p,resolvedColors:o,children:jsx(g,{...d.input||{}})})},f):jsx("div",{style:{display:"flex",gap:"12px",position:"relative"},children:jsx("div",{style:{flex:1,minWidth:0},children:jsxs("div",{style:{fontSize:"13px",color:o.mutedTextColor,display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"},children:[jsxs("span",{style:{fontWeight:600,color:"#ef4444",display:"flex",alignItems:"center",gap:"6px"},children:[jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:"#ef4444"}}),"Error"]}),jsxs("span",{style:{fontWeight:500,color:o.textColor},children:['UI component "',p,'" not found']})]})})},f)}default:{let p=a?.[d.toolName||""];return p?jsx("div",{style:{display:"block",position:"relative",padding:"12px",backgroundColor:o.inputBackground,borderRadius:"12px",border:`1px solid ${o.borderColor}`},children:jsx(Re,{componentName:d.toolName||"Unknown",resolvedColors:o,children:jsx(p,{...d.input||{}})})},f):jsx("div",{style:{display:"flex",gap:"12px",position:"relative"},children:jsx("div",{style:{flex:1,minWidth:0},children:jsxs("div",{style:{fontSize:"13px",color:o.mutedTextColor,display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"},children:[jsxs("span",{style:{fontWeight:600,color:w,display:"flex",alignItems:"center",gap:"6px"},children:[jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:w,animation:h?"pulse 1.5s ease-in-out infinite":void 0}}),i]}),jsx("span",{style:{fontWeight:500,color:o.textColor},children:d.toolName||"tool"})]})})},f)}}}),jsx("style",{children:`
9
9
  @keyframes shimmer {
10
10
  0% { background-position: -200% 0; }
11
11
  100% { background-position: 200% 0; }
12
12
  }
13
- `})]}):null}function un({items:e,resolvedColors:t,UIComponents:n={}}){return !Array.isArray(e)||e.length===0?null:jsx("div",{style:{},children:jsx("div",{style:{margin:0,color:t.textColor,display:"flex",flexDirection:"column",gap:"12px"},children:e.map((o,r)=>{if(typeof o=="object"&&o!==null&&o.type==="ui"){let{component:u,props:c}=o,v=n[u];return v?jsx("div",{style:{padding:"16px",borderRadius:"12px",backgroundColor:t.cardBackground,border:`1px solid ${t.borderColor}`},children:jsx(v,{props:c,resolvedColors:t})},r):jsx("div",{})}let l=typeof o=="string"?o:JSON.stringify(o);return jsx("div",{style:{whiteSpace:"pre-wrap",lineHeight:1.6},children:jsx(it,{content:l,theme:"dark"})},r)})})})}function pn(e){if(!e||Number.isNaN(e))return "0 B";let t=["B","KB","MB","GB","TB"],n=Math.min(t.length-1,Math.floor(Math.log(e)/Math.log(1024)));return `${(e/Math.pow(1024,n)).toFixed(n===0?0:1)} ${t[n]}`}function mn({attachment:e,resolvedColors:t,mode:n,onRemove:o,maxWidth:r="200px"}){let l=e.mimeType?.startsWith("image/"),u=n==="editable"||n==="input",c=n==="viewable",v={display:"flex",alignItems:"center",gap:n==="input"?"8px":"6px",padding:n==="input"?"8px 12px":"6px 10px",backgroundColor:t.inputBackground,borderRadius:n==="input"?"10px":"8px",border:`1px solid ${t.borderColor}`,fontSize:n==="input"?"12px":"11px",color:t.textColor,transition:"all 0.2s ease-out",cursor:c?"pointer":"default",maxWidth:n==="input"?"140px":r,position:"relative"},S=jsxs(Fragment,{children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:n==="input"?"20px":"16px",height:n==="input"?"20px":"16px",borderRadius:n==="input"?"4px":"3px",backgroundColor:l?"transparent":t.accentColor,flexShrink:0},children:[l?jsx("img",{src:e.url,alt:e.name,style:{width:n==="input"?"20px":"16px",height:n==="input"?"20px":"16px",borderRadius:n==="input"?"4px":"3px",objectFit:"cover"},onError:a=>{a.target.style.display="none";let T=a.target.nextElementSibling;T&&(T.style.display="block");}}):null,jsx(le,{IconComponent:File$1,size:n==="input"?14:10,strokeWidth:"2",style:{display:l?"none":"block",color:t.mutedTextColor}})]}),jsxs("div",{style:{minWidth:"0",flex:"1",display:"flex",flexDirection:"column"},children:[jsx("span",{title:e.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:"500"},children:e.name}),jsx("span",{style:{fontSize:n==="input"?"10px":"9px",color:t.mutedTextColor,marginTop:n==="input"?"2px":"1px"},children:pn(e.size)})]}),n==="input"&&l&&jsx("button",{onClick:a=>{a.stopPropagation(),window.open(e.url,"_blank");},style:{background:"none",border:"none",color:t.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px",transition:"all 0.2s"},title:"Preview image",onMouseEnter:a=>{a.currentTarget.style.backgroundColor=t.hoverBackground,a.currentTarget.style.color=t.textColor;},onMouseLeave:a=>{a.currentTarget.style.backgroundColor="transparent",a.currentTarget.style.color=t.mutedTextColor;},children:jsx(le,{IconComponent:Eye,size:"12",strokeWidth:"2"})}),u&&o&&jsx("button",{onClick:a=>{a.stopPropagation(),o(e.id);},style:{display:"flex",alignItems:"center",justifyContent:"center",width:n==="input"?"auto":"16px",height:n==="input"?"auto":"16px",padding:n==="input"?"2px":"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",color:t.mutedTextColor,cursor:"pointer",transition:"all 0.2s",flexShrink:0},onMouseEnter:a=>{a.currentTarget.style.backgroundColor="#ef444420",a.currentTarget.style.color="#ef4444";},onMouseLeave:a=>{a.currentTarget.style.backgroundColor="transparent",a.currentTarget.style.color=t.mutedTextColor;},children:jsx(le,{IconComponent:X,size:"12",strokeWidth:"2"})}),c&&jsx(le,{IconComponent:Download,size:"10",strokeWidth:"2",style:{color:t.mutedTextColor,flexShrink:0}})]});return c?jsx("a",{href:e.url,target:"_blank",rel:"noreferrer",style:{...v,textDecoration:"none"},onMouseEnter:a=>{a.currentTarget.style.backgroundColor=t.hoverBackground,a.currentTarget.style.borderColor=t.primaryColor;},onMouseLeave:a=>{a.currentTarget.style.backgroundColor=t.inputBackground,a.currentTarget.style.borderColor=t.borderColor;},children:S}):jsx("div",{style:v,children:S})}function at({attachments:e,resolvedColors:t,onRemove:n}){if(!Array.isArray(e)||e.length===0)return null;let o=typeof n=="function"?"editable":"viewable";return jsx("div",{style:{marginTop:"12px",display:"flex",flexWrap:"wrap",gap:"8px"},children:e.map(r=>jsx(mn,{attachment:r,resolvedColors:t,mode:o,onRemove:n},r.id))})}function fn({messageId:e,initialText:t,editingText:n,onEditingTextChange:o,onCancel:r,onSave:l,streaming:u,resolvedColors:c,attachments:v,onRemoveAttachment:S,onAddAttachments:a,uploading:T,t:f}){let b=ot.useRef(null),g=i=>{i.key==="Escape"?r():i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),u||l(e,n||t));},k=i=>{let m=i.target.files;m&&m.length>0&&a&&a(m),b.current&&(b.current.value="");};return jsxs("div",{style:{maxWidth:"720px",borderRadius:"16px",padding:"8px",fontSize:"15px",border:`2px solid ${c.primaryColor}`,backgroundColor:c.accentColor,color:c.textColor,marginBottom:"16px",marginTop:"16px"},children:[jsx("textarea",{autoFocus:true,style:{width:"100%",resize:"none",backgroundColor:"transparent",padding:"8px",lineHeight:"1.6",outline:"none",border:"none",color:"inherit",fontFamily:"inherit",fontSize:"inherit"},rows:Math.max(2,Math.min(10,Math.ceil((n||t).length/60))),value:n,onChange:i=>o(i.target.value),onKeyDown:g}),v&&v.length>0&&jsx("div",{style:{padding:"8px"},children:jsx(at,{attachments:v,resolvedColors:c,onRemove:S})}),T&&jsxs("div",{style:{padding:"8px 16px",display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:c.mutedTextColor},children:[jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"spin 1s linear infinite"},children:jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsx("span",{children:f("input.uploadingFiles")})]}),jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"8px",padding:"8px 8px 8px 0"},children:[a&&jsxs("div",{children:[jsx("input",{ref:b,type:"file",multiple:true,onChange:k,style:{display:"none"}}),jsx("button",{onClick:()=>b.current?.click(),disabled:T||u,title:f(T?"input.uploadingFiles":"input.attachFiles"),style:{display:"flex",margin:"0 10px",alignItems:"center",justifyContent:"center",borderRadius:"50%",width:"28px",height:"28px",transition:"all 0.2s",border:`1px solid ${c.borderColor}`,color:c.mutedTextColor,backgroundColor:"transparent",cursor:T||u?"not-allowed":"pointer",opacity:T||u?.5:1},onMouseEnter:i=>{!T&&!u&&(i.currentTarget.style.backgroundColor=c.inputBackground,i.currentTarget.style.borderColor=c.primaryColor);},onMouseLeave:i=>{i.currentTarget.style.backgroundColor="transparent",i.currentTarget.style.borderColor=c.borderColor;},children:jsx(Plus,{size:16,strokeWidth:2})})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsx("button",{style:{borderRadius:"8px",padding:"4px 12px",fontSize:"14px",transition:"background-color 0.2s",border:`1px solid ${c.borderColor}`,color:c.mutedTextColor,backgroundColor:"transparent",cursor:"pointer"},onMouseEnter:i=>i.currentTarget.style.backgroundColor=c.inputBackground,onMouseLeave:i=>i.currentTarget.style.backgroundColor="transparent",onClick:r,children:f("editor.cancel")}),jsx("button",{style:{borderRadius:"8px",padding:"4px 12px",fontSize:"14px",transition:"border-color 0.2s",border:`1px solid ${c.borderColor}`,backgroundColor:c.cardBackground,color:c.textColor,cursor:"pointer"},onMouseEnter:i=>i.currentTarget.style.borderColor=c.primaryColor,onMouseLeave:i=>i.currentTarget.style.borderColor=c.borderColor,onClick:()=>{u||l(e,n||t);},children:f("editor.saveAndRegenerate")})]})]})]})}function yn({chatMessages:e,isLoading:t,openReasoningIds:n,toggleReasoning:o,resolvedColors:r,t:l,onUserMessageClick:u,editingMessageId:c,editingText:v,onEditingTextChange:S,onCancelEdit:a,onSaveEdit:T,editAttachments:f,onRemoveEditAttachment:b,onAddEditAttachments:g,editUploading:k,UIComponents:i={}}){return jsxs(Fragment,{children:[jsx("style",{children:`
13
+ `})]}):null}function Yt(e){if(!e||Number.isNaN(e))return "0 B";let t=["B","KB","MB","GB","TB"],n=Math.min(t.length-1,Math.floor(Math.log(e)/Math.log(1024)));return `${(e/Math.pow(1024,n)).toFixed(n===0?0:1)} ${t[n]}`}function Jt({attachment:e,resolvedColors:t,mode:n,onRemove:r,maxWidth:o="200px"}){let a=e.mimeType?.startsWith("image/"),s=n==="editable"||n==="input",l=n==="viewable",T={display:"flex",alignItems:"center",gap:n==="input"?"8px":"6px",padding:n==="input"?"8px 12px":"6px 10px",backgroundColor:t.inputBackground,borderRadius:n==="input"?"10px":"8px",border:`1px solid ${t.borderColor}`,fontSize:n==="input"?"12px":"11px",color:t.textColor,transition:"all 0.2s ease-out",cursor:l?"pointer":"default",maxWidth:n==="input"?"140px":o,position:"relative"},I=jsxs(Fragment,{children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:n==="input"?"20px":"16px",height:n==="input"?"20px":"16px",borderRadius:n==="input"?"4px":"3px",backgroundColor:a?"transparent":t.accentColor,flexShrink:0},children:[a?jsx("img",{src:e.url,alt:e.name,style:{width:n==="input"?"20px":"16px",height:n==="input"?"20px":"16px",borderRadius:n==="input"?"4px":"3px",objectFit:"cover"},onError:C=>{C.target.style.display="none";let d=C.target.nextElementSibling;d&&(d.style.display="block");}}):null,jsx(ee,{IconComponent:File$1,size:n==="input"?14:10,strokeWidth:"2",style:{display:a?"none":"block",color:t.mutedTextColor}})]}),jsxs("div",{style:{minWidth:"0",flex:"1",display:"flex",flexDirection:"column"},children:[jsx("span",{title:e.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:"500"},children:e.name}),jsx("span",{style:{fontSize:n==="input"?"10px":"9px",color:t.mutedTextColor,marginTop:n==="input"?"2px":"1px"},children:Yt(e.size)})]}),n==="input"&&a&&jsx("button",{onClick:C=>{C.stopPropagation(),window.open(e.url,"_blank");},style:{background:"none",border:"none",color:t.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px",transition:"all 0.2s"},title:"Preview image",onMouseEnter:C=>{C.currentTarget.style.backgroundColor=t.hoverBackground,C.currentTarget.style.color=t.textColor;},onMouseLeave:C=>{C.currentTarget.style.backgroundColor="transparent",C.currentTarget.style.color=t.mutedTextColor;},children:jsx(ee,{IconComponent:Eye,size:"12",strokeWidth:"2"})}),s&&r&&jsx("button",{onClick:C=>{C.stopPropagation(),r(e.id);},style:{display:"flex",alignItems:"center",justifyContent:"center",width:n==="input"?"auto":"16px",height:n==="input"?"auto":"16px",padding:n==="input"?"2px":"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",color:t.mutedTextColor,cursor:"pointer",transition:"all 0.2s",flexShrink:0},onMouseEnter:C=>{C.currentTarget.style.backgroundColor="#ef444420",C.currentTarget.style.color="#ef4444";},onMouseLeave:C=>{C.currentTarget.style.backgroundColor="transparent",C.currentTarget.style.color=t.mutedTextColor;},children:jsx(ee,{IconComponent:X,size:"12",strokeWidth:"2"})}),l&&jsx(ee,{IconComponent:Download,size:"10",strokeWidth:"2",style:{color:t.mutedTextColor,flexShrink:0}})]});return l?jsx("a",{href:e.url,target:"_blank",rel:"noreferrer",style:{...T,textDecoration:"none"},onMouseEnter:C=>{C.currentTarget.style.backgroundColor=t.hoverBackground,C.currentTarget.style.borderColor=t.primaryColor;},onMouseLeave:C=>{C.currentTarget.style.backgroundColor=t.inputBackground,C.currentTarget.style.borderColor=t.borderColor;},children:I}):jsx("div",{style:T,children:I})}function Xe({attachments:e,resolvedColors:t,onRemove:n}){if(!Array.isArray(e)||e.length===0)return null;let r=typeof n=="function"?"editable":"viewable";return jsx("div",{style:{marginTop:"12px",display:"flex",flexWrap:"wrap",gap:"8px"},children:e.map(o=>jsx(Jt,{attachment:o,resolvedColors:t,mode:r,onRemove:n},o.id))})}function Qt({messageId:e,initialText:t,editingText:n,onEditingTextChange:r,onCancel:o,onSave:a,streaming:s,resolvedColors:l,attachments:T,onRemoveAttachment:I,onAddAttachments:C,uploading:d,t:x}){let f=qe.useRef(null),u=i=>{i.key==="Escape"?o():i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),s||a(e,n||t));},w=i=>{let h=i.target.files;h&&h.length>0&&C&&C(h),f.current&&(f.current.value="");};return jsxs("div",{style:{maxWidth:"720px",borderRadius:"16px",padding:"8px",fontSize:"15px",border:`2px solid ${l.primaryColor}`,backgroundColor:l.accentColor,color:l.textColor,marginBottom:"16px",marginTop:"16px"},children:[jsx("textarea",{autoFocus:true,style:{width:"100%",resize:"none",backgroundColor:"transparent",padding:"8px",lineHeight:"1.6",outline:"none",border:"none",color:"inherit",fontFamily:"inherit",fontSize:"inherit"},rows:Math.max(2,Math.min(10,Math.ceil((n||t).length/60))),value:n,onChange:i=>r(i.target.value),onKeyDown:u}),T&&T.length>0&&jsx("div",{style:{padding:"8px"},children:jsx(Xe,{attachments:T,resolvedColors:l,onRemove:I})}),d&&jsxs("div",{style:{padding:"8px 16px",display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:l.mutedTextColor},children:[jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"spin 1s linear infinite"},children:jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsx("span",{children:x("input.uploadingFiles")})]}),jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"8px",padding:"8px 8px 8px 0"},children:[C&&jsxs("div",{children:[jsx("input",{ref:f,type:"file",multiple:true,onChange:w,style:{display:"none"}}),jsx("button",{onClick:()=>f.current?.click(),disabled:d||s,title:x(d?"input.uploadingFiles":"input.attachFiles"),style:{display:"flex",margin:"0 10px",alignItems:"center",justifyContent:"center",borderRadius:"50%",width:"28px",height:"28px",transition:"all 0.2s",border:`1px solid ${l.borderColor}`,color:l.mutedTextColor,backgroundColor:"transparent",cursor:d||s?"not-allowed":"pointer",opacity:d||s?.5:1},onMouseEnter:i=>{!d&&!s&&(i.currentTarget.style.backgroundColor=l.inputBackground,i.currentTarget.style.borderColor=l.primaryColor);},onMouseLeave:i=>{i.currentTarget.style.backgroundColor="transparent",i.currentTarget.style.borderColor=l.borderColor;},children:jsx(Plus,{size:16,strokeWidth:2})})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsx("button",{style:{borderRadius:"8px",padding:"4px 12px",fontSize:"14px",transition:"background-color 0.2s",border:`1px solid ${l.borderColor}`,color:l.mutedTextColor,backgroundColor:"transparent",cursor:"pointer"},onMouseEnter:i=>i.currentTarget.style.backgroundColor=l.inputBackground,onMouseLeave:i=>i.currentTarget.style.backgroundColor="transparent",onClick:o,children:x("editor.cancel")}),jsx("button",{style:{borderRadius:"8px",padding:"4px 12px",fontSize:"14px",transition:"border-color 0.2s",border:`1px solid ${l.borderColor}`,backgroundColor:l.cardBackground,color:l.textColor,cursor:"pointer"},onMouseEnter:i=>i.currentTarget.style.borderColor=l.primaryColor,onMouseLeave:i=>i.currentTarget.style.borderColor=l.borderColor,onClick:()=>{s||a(e,n||t);},children:x("editor.saveAndRegenerate")})]})]})]})}function en({chatMessages:e,isLoading:t,openReasoningIds:n,toggleReasoning:r,resolvedColors:o,t:a,onUserMessageClick:s,editingMessageId:l,editingText:T,onEditingTextChange:I,onCancelEdit:C,onSaveEdit:d,editAttachments:x,onRemoveEditAttachment:f,onAddEditAttachments:u,editUploading:w,HsafaUI:i}){return jsxs(Fragment,{children:[jsx("style",{children:`
14
14
  @keyframes jumpingDots {
15
15
  0%, 80%, 100% {
16
16
  transform: translateY(0);
@@ -19,8 +19,8 @@ import {jsxs,jsx,Fragment}from'react/jsx-runtime';import ot,{createContext,useRe
19
19
  transform: translateY(-5px);
20
20
  }
21
21
  }
22
- `}),jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[e.map((m,h)=>{let C=Array.isArray(m.parts)?m.parts:[],E=C.filter(w=>w.type==="text").map(w=>w&&typeof w.text=="string"?w.text:"").join(`
23
- `),M=C.filter(w=>w.type==="file"||w.type==="image").map(w=>{if(w.type==="image"){let y=typeof w.image=="string"?w.image:w.image?.toString?.()||"";return {id:y||`${m.id}-img-${Date.now()}`,name:w.name||"image",url:y,mimeType:w.mediaType||"image/jpeg",size:w.size||0}}else return {id:w.url||`${m.id}-file-${Date.now()}`,name:w.name||"file",url:w.url||"",mimeType:w.mediaType||"application/octet-stream",size:w.size||0}});return jsx("div",{style:{padding:"0 4px"},children:m.role==="user"?c===m.id?jsx(fn,{messageId:m.id,initialText:E,editingText:v,onEditingTextChange:S,onCancel:a,onSave:T,streaming:t,resolvedColors:r,attachments:f,onRemoveAttachment:b,onAddAttachments:g,uploading:k,t:l}):jsx("div",{children:jsxs("div",{title:l("editor.clickToEdit"),onClick:()=>u(m.id,E,M),style:{maxWidth:"720px",borderRadius:"16px",padding:"16px",fontSize:"15px",lineHeight:"1.6",whiteSpace:"pre-wrap",cursor:"pointer",transition:"background-color 0.2s",backgroundColor:r.accentColor,color:r.textColor,marginBottom:"16px",marginTop:"16px"},onMouseEnter:w=>w.currentTarget.style.backgroundColor=r.hoverBackground,onMouseLeave:w=>w.currentTarget.style.backgroundColor=r.accentColor,children:[E,M.length>0&&jsx(at,{attachments:M,resolvedColors:r})]})}):jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[jsx(dn,{parts:C,messageId:m.id,openReasoningIds:n,toggleReasoning:o,resolvedColors:r}),(()=>{let w=C.find(y=>y.type==="data-final-response"&&y.data&&Array.isArray(y.data.items));return w?jsx(un,{items:w.data.items,resolvedColors:r,UIComponents:i}):null})()]})},m.id)}),t&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",padding:"0 4px",height:"20px"},children:[jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:r.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0s"}}),jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:r.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0.2s"}}),jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:r.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0.4s"}})]})]})]})}function hn({input:e,setInput:t,textareaRef:n,fileInputRef:o,isLoading:r,uploading:l,attachments:u,formatBytes:c,handleRemoveAttachment:v,onFileInputChange:S,onSend:a,onStop:T,status:f,t:b,resolvedColors:g}){let k=f==="streaming"||f==="submitted",i=u.length>0||e.trim().length>0;return jsx("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px",paddingTop:"4px"},children:jsx("div",{style:{position:"relative",flex:1},children:jsxs("div",{style:{position:"relative",width:"100%",borderRadius:"16px",paddingBottom:"48px",paddingTop:"16px",border:`1px solid ${g.borderColor}`,backgroundColor:g.cardBackground},children:[u.length>0&&jsx("div",{style:{padding:"0px 16px 12px 16px",display:"flex",flexWrap:"wrap",gap:"10px"},children:u.map(m=>{let h=m.mimeType.startsWith("image/");return jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",backgroundColor:g.inputBackground,borderRadius:"10px",border:`1px solid ${g.borderColor}`,fontSize:"12px",color:g.textColor,position:"relative"},children:[jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",borderRadius:"4px",backgroundColor:h?"transparent":g.cardBackground},children:h?jsx("img",{src:m.url,alt:m.name,style:{width:"20px",height:"20px",borderRadius:"4px",objectFit:"cover"}}):jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("rect",{x:"4",y:"4",width:"16",height:"20",rx:"2",ry:"2"})})}),jsxs("div",{style:{display:"flex",flexDirection:"column",minWidth:0,flex:1},children:[jsx("span",{title:m.name,style:{maxWidth:"140px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:m.name}),jsx("span",{style:{color:g.mutedTextColor,fontSize:"10px",marginTop:"2px"},children:c(m.size)})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginLeft:"8px"},children:[h&&jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",style:{background:"none",border:"none",color:g.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px",textDecoration:"none"},title:b("input.previewImage"),children:jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),jsx("button",{onClick:()=>v(m.id),style:{background:"none",border:"none",color:g.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px"},title:b("input.removeFile"),children:jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]},m.id)})}),l&&jsxs("div",{style:{padding:"0px 16px 12px 16px",display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:g.mutedTextColor},children:[jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"spin 1s linear infinite"},children:jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsx("span",{children:b("input.uploadingFiles")})]}),jsx("div",{style:{padding:"0 16px"},children:jsx("textarea",{ref:n,"aria-label":"Prompt",rows:1,placeholder:b("input.placeholder"),value:e,onChange:m=>t(m.target.value),onKeyDown:m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),a());},disabled:r||l,style:{height:"24px",maxHeight:"200px",width:"100%",resize:"none",backgroundColor:"transparent",fontSize:"15px",lineHeight:"1.6",outline:"none",border:"none",color:g.textColor,fontFamily:"inherit",overflow:"auto"}})}),jsx("input",{ref:o,type:"file",multiple:true,onChange:S,style:{display:"none"},accept:"*/*"}),jsx("div",{style:{position:"absolute",bottom:"8px",left:"8px",display:"flex",alignItems:"center",gap:"4px",color:g.mutedTextColor},children:jsx("button",{onClick:()=>o.current?.click(),disabled:r||l,style:{borderRadius:"8px",padding:"8px",transition:"all 0.2s",backgroundColor:"transparent",border:"none",cursor:r||l?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"inherit",opacity:r||l?.5:1},"aria-label":b("input.attachFiles"),children:jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 1 1 5.66 5.66l-9.2 9.19a2 2 0 1 1-2.83-2.83l8.49-8.49"})})})}),jsx("div",{style:{position:"absolute",bottom:"8px",right:"8px"},children:r?jsx("button",{onClick:T,disabled:!k,"aria-label":b("input.stop"),title:"Stop generation",style:{borderRadius:"12px",padding:"12px",transition:"all 0.2s ease-out",border:"1px solid #ef4444",backgroundColor:"#ef444420",color:"#ef4444",opacity:k?1:.4,cursor:k?"pointer":"not-allowed",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:m=>{k&&(m.currentTarget.style.backgroundColor="#ef444430",m.currentTarget.style.transform="scale(1.02)");},onMouseLeave:m=>{m.currentTarget.style.backgroundColor="#ef444420",m.currentTarget.style.transform="scale(1)";},children:jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"})})}):jsx("button",{onClick:a,disabled:!i||l,"aria-label":b("input.send"),title:"Send message",style:{borderRadius:"12px",padding:"12px",transition:"all 0.2s ease-out",border:`1px solid ${g.borderColor}`,backgroundColor:g.cardBackground,color:!i||l?g.mutedTextColor:g.primaryColor,cursor:!i||l?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",opacity:!i||l?.5:1},onMouseEnter:m=>{i&&!l&&(m.currentTarget.style.borderColor=g.primaryColor,m.currentTarget.style.transform="scale(1.02)");},onMouseLeave:m=>{m.currentTarget.style.borderColor=g.borderColor,m.currentTarget.style.transform="scale(1)";},children:jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"m5 12 7-7 7 7"}),jsx("path",{d:"M12 19V5"})]})})})]})})})}function Lt(e){let t=`hsafaChat_${e}`,n=`${t}.chats`,o=C=>`${t}.chat.${C}`,r=`${t}.currentChatId`,l=`${t}.showChat`,u=()=>{try{let C=localStorage.getItem(n);return C?JSON.parse(C):[]}catch{return []}},c=C=>{try{localStorage.setItem(n,JSON.stringify(C));}catch{}},v=C=>{try{let E=localStorage.getItem(o(C));return E?JSON.parse(E):null}catch{return null}},S=C=>{try{localStorage.setItem(o(C.id),JSON.stringify(C));}catch{}},a=C=>{let E=u(),M=E.findIndex(w=>w.id===C.id);M>=0?E[M]=C:E.unshift(C),c(E);},T=C=>{let M=u().filter(w=>w.id!==C);c(M);},f=C=>{try{localStorage.removeItem(o(C));}catch{}};return {loadChatsIndex:u,saveChatsIndex:c,loadChat:v,saveChat:S,upsertChatMeta:a,deleteChatMeta:T,deleteChatData:f,deleteChat:C=>{f(C),T(C);},loadShowChatPreference:C=>{try{let E=localStorage.getItem(l);return E!==null?E==="true":C}catch{return C}},saveShowChatPreference:C=>{try{localStorage.setItem(l,String(C));}catch{}},loadCurrentChatId:()=>{try{return localStorage.getItem(r)}catch{return null}},saveCurrentChatId:C=>{try{localStorage.setItem(r,C);}catch{}},removeCurrentChatId:()=>{try{localStorage.removeItem(r);}catch{}}}}function xn(e){let t=Date.now()-e,n=Math.max(1,Math.floor(t/1e3));if(n<60)return `${n}s`;let o=Math.floor(n/60);if(o<60)return `${o}m`;let r=Math.floor(o/60);if(r<24)return `${r}h`;let l=Math.floor(r/24);if(l<7)return `${l}d`;let u=Math.floor(l/7);if(u<4)return `${u}w`;let c=Math.floor(l/30);return c<12?`${c}mo`:`${Math.floor(c/12)}y`}function bn({historyOpen:e,historySearch:t,currentChatId:n,refreshKey:o,resolvedColors:r,onClose:l,onSearchChange:u,onChatSelect:c,onChatDelete:v,loadChatsIndex:S,historyPopupRef:a}){if(!e)return null;let T=jsxs(Fragment,{children:[jsx("div",{style:{position:"fixed",inset:"0",zIndex:1100,backgroundColor:"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)"},onClick:l}),jsxs("div",{ref:a,style:{position:"fixed",left:"50%",top:"64px",transform:"translateX(-50%)",zIndex:1101,width:"680px",maxWidth:"94vw",overflow:"hidden",borderRadius:"16px",border:`1px solid ${r.borderColor}`,backgroundColor:`${r.backgroundColor}f0`,boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)"},children:[jsx("div",{style:{display:"flex",alignItems:"center",gap:"12px",borderBottom:`1px solid ${r.borderColor}`,padding:"12px 16px"},children:jsx("div",{style:{flex:"1"},children:jsx("input",{autoFocus:true,value:t,onChange:f=>u(f.target.value),placeholder:"Search",style:{width:"100%",borderRadius:"8px",backgroundColor:r.inputBackground,padding:"8px 12px",fontSize:"14px",color:r.textColor,border:`1px solid ${r.borderColor}`,outline:"none"},onFocus:f=>f.currentTarget.style.borderColor=r.primaryColor,onBlur:f=>f.currentTarget.style.borderColor=r.borderColor})})}),jsx("div",{style:{maxHeight:"60vh",overflowY:"auto"},children:(()=>{let f=t.toLowerCase().trim(),b=S();return f&&(b=b.filter(g=>(g.title||"").toLowerCase().includes(f))),!b||b.length===0?jsx("div",{style:{padding:"24px",color:r.mutedTextColor,textAlign:"center"},children:"No chats found."}):jsx("div",{children:b.map((g,k)=>jsx("div",{style:{borderTop:k>0?`1px solid ${r.borderColor}`:"none"},children:jsxs("div",{style:{display:"flex",width:"100%",alignItems:"center",justifyContent:"space-between",gap:"12px",padding:"12px",backgroundColor:g.id===n?r.cardBackground:"transparent"},children:[jsx("button",{style:{flex:"1",textAlign:"left",transition:"background-color 0.2s",borderRadius:"8px",padding:"8px",border:"none",backgroundColor:"transparent",cursor:"pointer",color:r.textColor},onMouseEnter:i=>i.currentTarget.style.backgroundColor=r.hoverBackground,onMouseLeave:i=>i.currentTarget.style.backgroundColor="transparent",onClick:()=>c(g.id),children:jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"12px"},children:[jsx("div",{style:{minWidth:"0",flex:"1"},children:jsx("div",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"14px",color:r.textColor},children:g.title||"Untitled chat"})}),jsx("div",{style:{flexShrink:0,fontSize:"12px",color:r.mutedTextColor},children:xn(g.updatedAt)})]})}),jsx("button",{style:{flexShrink:0,borderRadius:"6px",padding:"8px",color:r.mutedTextColor,border:"1px solid transparent",backgroundColor:"transparent",cursor:"pointer",transition:"all 0.2s"},title:"Delete chat",onMouseEnter:i=>{i.currentTarget.style.color="#ef4444",i.currentTarget.style.backgroundColor="rgba(239, 68, 68, 0.1)",i.currentTarget.style.borderColor="rgba(239, 68, 68, 0.3)";},onMouseLeave:i=>{i.currentTarget.style.color=r.mutedTextColor,i.currentTarget.style.backgroundColor="transparent",i.currentTarget.style.borderColor="transparent";},onClick:i=>{i.stopPropagation(),v(g.id);},children:jsx(le,{IconComponent:Trash2,size:"16",strokeWidth:"2"})})]})},g.id))})})()})]})]});return typeof document<"u"&&document.body?createPortal(T,document.body):T}function $r(e){if(!(e instanceof HTMLElement))return true;let t=window.getComputedStyle(e);return t.display!=="none"&&t.visibility!=="hidden"&&t.opacity!=="0"&&e.offsetParent!==null}function Lr(e){if(e.id){let n=document.querySelector(`label[for="${e.id}"]`);if(n)return n.textContent?.trim()}let t=e.closest("label");if(t){let n=t.cloneNode(true),o=n.querySelector("input, select, textarea");return o&&o.remove(),n.textContent?.trim()}}function Ht(e){if(e.textContent&&e.textContent.trim())return e.textContent.trim().slice(0,100)}function Bt(e){if(e instanceof HTMLInputElement){let t=e.type.toLowerCase();return t==="checkbox"||t==="radio"?e.checked:e.value}if(e instanceof HTMLTextAreaElement)return e.value;if(e instanceof HTMLSelectElement)return e.multiple?Array.from(e.selectedOptions).map(t=>t.value):e.value;if(e instanceof HTMLElement&&e.isContentEditable)return e.textContent||void 0}function Hr(e){if(e.id)return `#${e.id}`;let t=[],n=e;for(;n&&n!==document.body;){let o=n.tagName.toLowerCase();if(n.className&&typeof n.className=="string"){let l=n.className.split(" ").filter(u=>u.trim()).slice(0,2);l.length>0&&(o+="."+l.join("."));}let r=n.parentElement;if(r){let l=Array.from(r.children).filter(u=>u.tagName===n.tagName);if(l.length>1){let u=l.indexOf(n)+1;o+=`:nth-child(${u})`;}}t.unshift(o),n=r;}return t.slice(-3).join(" > ")}async function je(e={}){try{let{includeHidden:t=!1,selector:n,what:o="content",limit:r}=e,l=document.querySelector(".hsafa-content-container");if(!l)return {ok:!1,components:[],count:0,total:0,containerFound:!1,error:"ContentContainer not found on page. Make sure you have wrapped your app with <ContentContainer>."};let u=n&&l.querySelector(n)||l,c=[],v=[];o==="inputs"?v=["input","textarea","select",'[contenteditable="true"]','[contenteditable=""]']:v=["header","nav","main","section","article","aside","footer","h1","h2","h3","h4","h5","h6","p","img[alt]","ul","ol","li","table","thead","tbody","tr","td","th","form","label","input","textarea","select",'[contenteditable="true"]','[contenteditable=""]',"a[href]","button",'[role="button"]','[role="link"]',"[onclick]","[tabindex]","div"],u.querySelectorAll(v.join(", ")).forEach(i=>{let m=$r(i);if(!m&&!t)return;let h={id:i.id||null,tag:i.tagName.toLowerCase(),className:i.className&&typeof i.className=="string"?i.className:void 0,isVisible:m,isInteractive:!0,selector:Hr(i)};i instanceof HTMLInputElement?(h.type=i.type,h.name=i.name||void 0,h.placeholder=i.placeholder||void 0,h.value=Bt(i),h.checked=i.type==="checkbox"||i.type==="radio"?i.checked:void 0,h.disabled=i.disabled,h.required=i.required):i instanceof HTMLTextAreaElement?(h.name=i.name||void 0,h.placeholder=i.placeholder||void 0,h.value=Bt(i),h.disabled=i.disabled,h.required=i.required):i instanceof HTMLSelectElement?(h.name=i.name||void 0,h.value=Bt(i),h.disabled=i.disabled,h.required=i.required,h.options=Array.from(i.options).map(C=>({value:C.value,label:C.text,selected:C.selected,disabled:C.disabled}))):i instanceof HTMLButtonElement?(h.type=i.type,h.disabled=i.disabled,h.text=Ht(i)):i instanceof HTMLAnchorElement?(h.href=i.href,h.text=Ht(i)):i instanceof HTMLImageElement?(h.text=i.alt||void 0,h.label=i.alt||h.label):h.text=Ht(i),h.label=Lr(i),h.role=i.getAttribute("role")||void 0,h.ariaLabel=i.getAttribute("aria-label")||void 0,c.push(h);});let a=i=>i.isVisible?o==="inputs"?i.tag==="input"||i.tag==="textarea"||i.tag==="select"||i.role==="textbox"?3:i.tag==="button"||i.tag==="a"?2:1:["header","nav","main","footer"].includes(i.tag)?5:["section","article","aside"].includes(i.tag)||["h1","h2","h3"].includes(i.tag)?4:["h4","h5","h6"].includes(i.tag)?3:i.tag==="form"?4:i.tag==="label"?3:i.tag==="input"||i.tag==="textarea"||i.tag==="select"?4:i.tag==="p"||i.tag==="img"||i.tag==="button"||i.tag==="a"?3:1:0;c.sort((i,m)=>a(m)-a(i));let T=c.length,b=Math.max(1,Math.min(200,typeof r=="number"?Math.floor(r):o==="inputs"?100:150)),g=T>b,k=g?c.slice(0,b):c;return {ok:!0,components:k,count:k.length,total:T,truncated:g,containerFound:!0}}catch(t){return {ok:false,components:[],count:0,total:0,containerFound:false,error:t?.message||String(t)}}}typeof window<"u"&&(window.getDomComponents=je);async function Ee(e,t={}){if(typeof window>"u")return {ok:false,steps:[{ok:false,action:"none",targetKind:"position",durationMs:0,error:"guideCursor only works in browser environment"}]};let n=window.__cursorGuide;if(!n)return {ok:false,steps:[{ok:false,action:"none",targetKind:"position",durationMs:0,error:"CursorController not initialized. Make sure to mount <CursorController /> component."}]};try{return await n(e,t)}catch(o){return {ok:false,steps:[{ok:false,action:t.action||"none",targetKind:"position",durationMs:0,error:o?.message||String(o)}]}}}typeof window<"u"&&(window.guideCursor=Ee);function Cn(e){return !!e&&e.nodeType===1}function pe(e,t){e.dispatchEvent(new Event(t,{bubbles:true}));}function kn(e,t){let n=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(e),"value")?.set;n?n.call(e,t):e.value=t,pe(e,"input");}function Br(e,t){e.checked!==t&&e.click();}function Dr(e,t){if(typeof t=="object"&&t&&"index"in t&&typeof t.index=="number")e.selectedIndex=Math.max(0,Math.min(e.options.length-1,t.index));else if(typeof t=="object"&&t&&"label"in t&&typeof t.label=="string"){let n=Array.from(e.options).findIndex(o=>o.text===t.label);e.selectedIndex=n>=0?n:0;}else e.value=String(t);pe(e,"input"),pe(e,"change");}function Pr(e,t){let n=new Set(t.map(String));Array.from(e.options).forEach(o=>{o.selected=n.has(o.value)||n.has(o.text);}),pe(e,"input"),pe(e,"change");}function zr(e){return e?e instanceof Date?e.toISOString().slice(0,10):String(e):""}function Wr(e,t){let n=Array.isArray(t)?t:[t],o=new DataTransfer;for(let r of n)o.items.add(r);Object.defineProperty(e,"files",{value:o.files,configurable:true}),pe(e,"input"),pe(e,"change");}async function Ue(e,t={}){let n=document.activeElement||null;if(n&&Cn(n)){let o=n.closest('[contenteditable="true"], [contenteditable=""]');o&&(n=o);}if(!n||n===document.body)return {ok:false,filled:[{key:"active",status:"skipped",message:"No active input element"}],errors:["No active input element"]};try{let o=n.tagName.toLowerCase();if(o==="input"){let r=n,l=(r.type||"text").toLowerCase();if(l==="checkbox")Br(r,!!e);else if(l==="radio"){let u=r.name;if(u&&e!=null&&String(r.value)!==String(e)){let c=document.querySelector(`input[type="radio"][name="${CSS.escape(u)}"][value="${CSS.escape(String(e))}"]`);c?c.click():r.click();}else r.click();}else if(l==="file")if(e instanceof File||Array.isArray(e)&&e.every(u=>u instanceof File))Wr(r,e);else return {ok:!1,filled:[{key:"active",status:"skipped",message:"Provide File or File[] for file input"}],errors:["Provide File or File[] for file input"]};else {let u=l==="date"?zr(e):String(e??"");kn(r,u),pe(r,"change");}return {ok:!0,filled:[{key:"active",status:"ok"}]}}if(o==="textarea"){let r=n,l=String(e??"");return kn(r,l),pe(r,"change"),{ok:!0,filled:[{key:"active",status:"ok"}]}}if(o==="select"){let r=n;return r.multiple?Pr(r,Array.isArray(e)?e:[e]):Dr(r,e),{ok:!0,filled:[{key:"active",status:"ok"}]}}if(Cn(n)&&n.isContentEditable){let r=n;return r.focus(),r.textContent=String(e??""),pe(r,"input"),pe(r,"change"),r.blur?.(),{ok:!0,filled:[{key:"active",status:"ok"}]}}return {ok:!1,filled:[{key:"active",status:"skipped",message:`Unsupported active element: ${o}`}],errors:[`Unsupported active element: ${o}`]}}catch(o){return {ok:false,filled:[{key:"active",status:"error",message:o?.message??String(o)}],errors:[o?.message??String(o)]}}}typeof window<"u"&&(window.FillActiveInput=Ue);var qe=null,lt={},wn=false,Be=null,dt=false;function Dt(e){e.classList.add("visible");}function In(){dt=true,Be!=null&&(clearTimeout(Be),Be=null);}function Nr(e,t=1500){dt||(Be!=null&&clearTimeout(Be),Be=window.setTimeout(()=>{dt||e.classList.remove("visible");},t));}function Gr(e,t=1200){dt=false,Nr(e,t);}function _r(e){let t=[],n=e?.parentElement;for(;n;){let o=getComputedStyle(n),r=o.overflow+o.overflowY+o.overflowX;/(auto|scroll)/.test(r)&&t.push(n),n=n.parentElement;}return t}async function jr(e,t=1500,n=160){let o=performance.now(),r=e?_r(e):[],l=()=>{let a=[window.scrollX||document.documentElement.scrollLeft||0,window.scrollY||document.documentElement.scrollTop||0];return r.forEach(T=>{a.push(T.scrollLeft,T.scrollTop);}),a},u=()=>{if(!e)return {x:0,y:0};let a=e.getBoundingClientRect();return {x:a.left,y:a.top}},c=l(),v=u(),S=performance.now();return new Promise(a=>{function T(f){let b=l(),g=u(),k=false;for(let i=0;i<b.length;i++)if(b[i]!==c[i]){k=true;break}if(!k&&e&&(g.x!==v.x||g.y!==v.y)&&(k=true),k&&(c=b,v=g,S=f),f-S>=n||f-o>=t){a();return}requestAnimationFrame(T);}requestAnimationFrame(T);})}var Ur='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="32px" height="32px"><path d="M 7.2304688 4.9863281 C 5.9215232 4.8276681 4.8053213 6.0177722 5.0234375 7.3066406 A 1.0001 1.0001 0 0 0 5.0253906 7.3085938 C 5.9996339 12.981516 7.7205826 18.716222 10 24.515625 A 1.0001 1.0001 0 0 0 10 24.517578 C 10.26886 25.199332 10.914322 25.653844 11.5625 25.738281 C 12.210678 25.822721 12.879213 25.592031 13.359375 25.09375 C 14.505165 23.921134 15.214424 22.695429 15.90625 21.498047 C 17.56565 23.217848 19.256845 24.909775 21.0625 26.484375 L 21.060547 26.480469 C 21.799528 27.12933 22.841378 27.205969 23.673828 26.78125 A 1.0001 1.0001 0 0 0 23.691406 26.771484 C 24.987999 26.077693 26.028685 25.052256 26.71875 23.746094 L 26.71875 23.744141 C 27.174557 22.900924 27.06954 21.854242 26.439453 21.119141 A 1.0001 1.0001 0 0 0 26.433594 21.113281 C 24.867416 19.313474 23.193611 17.633865 21.488281 15.986328 C 22.714141 15.237691 23.933938 14.51508 25.158203 13.414062 A 1.0001 1.0001 0 0 0 25.162109 13.410156 C 26.052979 12.600274 25.977319 11.169141 25.101562 10.404297 A 1.0001 1.0001 0 0 0 24.669922 10.042969 C 18.793373 7.4738953 12.973806 5.6931843 7.2324219 4.9882812 A 1.0001 1.0001 0 0 0 7.2304688 4.9863281 z M 6.9960938 6.9746094 C 12.468883 7.6474978 18.081513 9.3573116 23.796875 11.849609 A 1.0001 1.0001 0 0 0 23.867188 11.884766 C 23.901248 11.899796 23.884276 11.867987 23.816406 11.929688 C 22.403891 13.198979 20.999383 14.076858 19.457031 14.976562 A 1.0001 1.0001 0 0 0 19.275391 16.568359 C 21.250864 18.425305 23.134972 20.36916 24.919922 22.419922 C 25.009402 22.524309 25.024026 22.676488 24.960938 22.792969 A 1.0001 1.0001 0 0 0 24.955078 22.804688 C 24.446951 23.770198 23.730542 24.476149 22.755859 25 C 22.611605 25.06851 22.457885 25.047856 22.378906 24.978516 A 1.0001 1.0001 0 0 0 22.376953 24.976562 C 20.293628 23.159824 18.307991 21.233373 16.419922 19.216797 A 1.0001 1.0001 0 0 0 14.835938 19.378906 C 13.841812 21.004716 13.152668 22.447221 11.925781 23.701172 A 1.0001 1.0001 0 0 0 11.919922 23.707031 C 11.883822 23.744501 11.865156 23.739957 11.847656 23.742188 C 9.6161121 18.057657 7.9395914 12.46667 6.9960938 6.9746094 z"/></svg>',qr='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="32px" height="32px"><path d="M 22.5 3 C 19.480226 3 17 5.4802259 17 8.5 L 17 23.412109 L 14.871094 22.697266 C 13.308963 22.172461 11.892528 22 10.703125 22 C 9.5908429 22 8.5540295 22.197475 7.640625 22.65625 C 5.2906802 23.831199 3.9427678 26.197397 4.0019531 28.90625 C 4.0019531 28.90625 4.0019531 28.908203 4.0019531 28.908203 C 4.0019531 28.908203 4.0019531 28.910156 4.0019531 28.910156 C 4.0184171 29.660452 4.4596385 30.354695 5.1328125 30.6875 A 1.50015 1.50015 0 0 0 5.1367188 30.689453 C 5.1367188 30.689453 9.4097266 32.789754 11.599609 33.949219 C 12.445613 34.397848 13.696939 34.926046 15.210938 36.09375 C 16.724935 37.261454 18.423179 39.012543 19.826172 41.792969 C 21.023611 44.165544 23.672779 45.195669 26.144531 44.955078 A 1.50015 1.50015 0 0 0 26.146484 44.955078 C 31.427085 44.439215 32.081856 44.381732 35.59375 44.023438 C 37.044229 43.875625 38.276993 43.213524 39.111328 42.289062 C 39.945663 41.364602 40.422895 40.257718 40.798828 39.125 C 41.561218 36.826116 42.933037 33.169846 43.671875 30.599609 C 45.018525 25.913269 41.884024 21.194549 37.246094 19.953125 L 37.242188 19.951172 C 36.99827 19.885452 36.756736 19.832884 36.521484 19.789062 A 1.50015 1.50015 0 0 0 36.513672 19.787109 L 28 18.248047 L 28 8.5 C 28 5.4802259 25.519774 3 22.5 3 z M 22.5 6 C 23.898226 6 25 7.1017741 25 8.5 L 25 19.5 A 1.50015 1.50015 0 0 0 26.232422 20.976562 L 35.980469 22.740234 C 36.14895 22.771804 36.312663 22.808524 36.464844 22.849609 A 1.50015 1.50015 0 0 0 36.46875 22.849609 C 39.614436 23.689967 41.641993 26.803286 40.789062 29.771484 C 40.115901 32.113248 38.752735 35.768572 37.953125 38.179688 C 37.641059 39.119968 37.279727 39.837554 36.882812 40.277344 C 36.485898 40.717133 36.095584 40.956874 35.289062 41.039062 C 31.783676 41.396695 31.135884 41.452908 25.855469 41.96875 C 24.423221 42.108159 23.024467 41.472831 22.503906 40.441406 C 20.887905 37.238832 18.854971 35.116296 17.042969 33.71875 C 15.230967 32.321204 13.560902 31.594199 13.003906 31.298828 C 10.939171 30.205625 7.8041786 28.665144 7.1035156 28.320312 C 7.1954033 26.8809 7.6810328 25.989859 8.9824219 25.339844 A 1.50015 1.50015 0 0 0 8.9863281 25.337891 C 9.3949198 25.132713 9.9434071 25 10.703125 25 C 11.605722 25 12.680146 25.12582 13.916016 25.541016 L 18.021484 26.921875 A 1.50015 1.50015 0 0 0 20 25.5 L 20 8.5 C 20 7.1017741 21.101774 6 22.5 6 z"/></svg>';async function Vr(){if(!lt.arrow)try{lt.arrow=Ur,lt.pointer=qr;}catch(e){console.warn("Failed to set cursor SVGs",e);}return lt}function Tn({arrowSvg:e,pointerSvg:t}){return jsxs(Fragment,{children:[e&&jsx("div",{className:"arrow",dangerouslySetInnerHTML:{__html:e}}),t&&jsx("div",{className:"pointer",dangerouslySetInnerHTML:{__html:t}})]})}async function Kr(){let e="demo-fake-cursor",t=document.getElementById(e),n=await Vr();if(!wn){let o="cursor-controller-styles";if(!document.getElementById(o)){let r=document.createElement("style");r.id=o,r.textContent=`
22
+ `}),jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[e.map((h,p)=>{let g=Array.isArray(h.parts)?h.parts:[],y=g.filter(k=>k.type==="text").map(k=>k&&typeof k.text=="string"?k.text:"").join(`
23
+ `),v=g.filter(k=>k.type==="file"||k.type==="image").map(k=>{if(k.type==="image"){let b=typeof k.image=="string"?k.image:k.image?.toString?.()||"";return {id:b||`${h.id}-img-${Date.now()}`,name:k.name||"image",url:b,mimeType:k.mediaType||"image/jpeg",size:k.size||0}}else return {id:k.url||`${h.id}-file-${Date.now()}`,name:k.name||"file",url:k.url||"",mimeType:k.mediaType||"application/octet-stream",size:k.size||0}});return jsx("div",{style:{padding:"0 4px"},children:h.role==="user"?l===h.id?jsx(Qt,{messageId:h.id,initialText:y,editingText:T,onEditingTextChange:I,onCancel:C,onSave:d,streaming:t,resolvedColors:o,attachments:x,onRemoveAttachment:f,onAddAttachments:u,uploading:w,t:a}):jsx("div",{children:jsxs("div",{title:a("editor.clickToEdit"),onClick:()=>s(h.id,y,v),style:{maxWidth:"720px",borderRadius:"16px",padding:"16px",fontSize:"15px",lineHeight:"1.6",whiteSpace:"pre-wrap",cursor:"pointer",transition:"background-color 0.2s",backgroundColor:o.accentColor,color:o.textColor,marginBottom:"16px",marginTop:"16px"},onMouseEnter:k=>k.currentTarget.style.backgroundColor=o.hoverBackground,onMouseLeave:k=>k.currentTarget.style.backgroundColor=o.accentColor,children:[y,v.length>0&&jsx(Xe,{attachments:v,resolvedColors:o})]})}):jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[jsx(Xt,{parts:g,messageId:h.id,openReasoningIds:n,toggleReasoning:r,resolvedColors:o,HsafaUI:i}),(()=>{let k=g.find(b=>b.type==="text"&&b.text);return k?jsx(_e,{content:k.text,theme:"dark"}):null})()]})},h.id)}),t&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",padding:"0 4px",height:"20px"},children:[jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0s"}}),jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0.2s"}}),jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0.4s"}})]})]})]})}function tn({input:e,setInput:t,textareaRef:n,fileInputRef:r,isLoading:o,uploading:a,attachments:s,formatBytes:l,handleRemoveAttachment:T,onFileInputChange:I,onSend:C,onStop:d,status:x,t:f,resolvedColors:u}){let w=x==="streaming"||x==="submitted",i=s.length>0||e.trim().length>0;return jsx("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px",paddingTop:"4px"},children:jsx("div",{style:{position:"relative",flex:1},children:jsxs("div",{style:{position:"relative",width:"100%",borderRadius:"16px",paddingBottom:"48px",paddingTop:"16px",border:`1px solid ${u.borderColor}`,backgroundColor:u.cardBackground},children:[s.length>0&&jsx("div",{style:{padding:"0px 16px 12px 16px",display:"flex",flexWrap:"wrap",gap:"10px"},children:s.map(h=>{let p=h.mimeType.startsWith("image/");return jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",backgroundColor:u.inputBackground,borderRadius:"10px",border:`1px solid ${u.borderColor}`,fontSize:"12px",color:u.textColor,position:"relative"},children:[jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",borderRadius:"4px",backgroundColor:p?"transparent":u.cardBackground},children:p?jsx("img",{src:h.url,alt:h.name,style:{width:"20px",height:"20px",borderRadius:"4px",objectFit:"cover"}}):jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("rect",{x:"4",y:"4",width:"16",height:"20",rx:"2",ry:"2"})})}),jsxs("div",{style:{display:"flex",flexDirection:"column",minWidth:0,flex:1},children:[jsx("span",{title:h.name,style:{maxWidth:"140px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:h.name}),jsx("span",{style:{color:u.mutedTextColor,fontSize:"10px",marginTop:"2px"},children:l(h.size)})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginLeft:"8px"},children:[p&&jsx("a",{href:h.url,target:"_blank",rel:"noopener noreferrer",style:{background:"none",border:"none",color:u.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px",textDecoration:"none"},title:f("input.previewImage"),children:jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),jsx("button",{onClick:()=>T(h.id),style:{background:"none",border:"none",color:u.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px"},title:f("input.removeFile"),children:jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]},h.id)})}),a&&jsxs("div",{style:{padding:"0px 16px 12px 16px",display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:u.mutedTextColor},children:[jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"spin 1s linear infinite"},children:jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsx("span",{children:f("input.uploadingFiles")})]}),jsx("div",{style:{padding:"0 16px"},children:jsx("textarea",{ref:n,"aria-label":"Prompt",rows:1,placeholder:f("input.placeholder"),value:e,onChange:h=>t(h.target.value),onKeyDown:h=>{h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),C());},disabled:o||a,style:{height:"24px",maxHeight:"200px",width:"100%",resize:"none",backgroundColor:"transparent",fontSize:"15px",lineHeight:"1.6",outline:"none",border:"none",color:u.textColor,fontFamily:"inherit",overflow:"auto"}})}),jsx("input",{ref:r,type:"file",multiple:true,onChange:I,style:{display:"none"},accept:"*/*"}),jsx("div",{style:{position:"absolute",bottom:"8px",left:"8px",display:"flex",alignItems:"center",gap:"4px",color:u.mutedTextColor},children:jsx("button",{onClick:()=>r.current?.click(),disabled:o||a,style:{borderRadius:"8px",padding:"8px",transition:"all 0.2s",backgroundColor:"transparent",border:"none",cursor:o||a?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"inherit",opacity:o||a?.5:1},"aria-label":f("input.attachFiles"),children:jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 1 1 5.66 5.66l-9.2 9.19a2 2 0 1 1-2.83-2.83l8.49-8.49"})})})}),jsx("div",{style:{position:"absolute",bottom:"8px",right:"8px"},children:o?jsx("button",{onClick:d,disabled:!w,"aria-label":f("input.stop"),title:"Stop generation",style:{borderRadius:"12px",padding:"12px",transition:"all 0.2s ease-out",border:"1px solid #ef4444",backgroundColor:"#ef444420",color:"#ef4444",opacity:w?1:.4,cursor:w?"pointer":"not-allowed",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:h=>{w&&(h.currentTarget.style.backgroundColor="#ef444430",h.currentTarget.style.transform="scale(1.02)");},onMouseLeave:h=>{h.currentTarget.style.backgroundColor="#ef444420",h.currentTarget.style.transform="scale(1)";},children:jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"})})}):jsx("button",{onClick:C,disabled:!i||a,"aria-label":f("input.send"),title:"Send message",style:{borderRadius:"12px",padding:"12px",transition:"all 0.2s ease-out",border:`1px solid ${u.borderColor}`,backgroundColor:u.cardBackground,color:!i||a?u.mutedTextColor:u.primaryColor,cursor:!i||a?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",opacity:!i||a?.5:1},onMouseEnter:h=>{i&&!a&&(h.currentTarget.style.borderColor=u.primaryColor,h.currentTarget.style.transform="scale(1.02)");},onMouseLeave:h=>{h.currentTarget.style.borderColor=u.borderColor,h.currentTarget.style.transform="scale(1)";},children:jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"m5 12 7-7 7 7"}),jsx("path",{d:"M12 19V5"})]})})})]})})})}function xt(e){let t=`hsafaChat_${e}`,n=`${t}.chats`,r=g=>`${t}.chat.${g}`,o=`${t}.currentChatId`,a=`${t}.showChat`,s=()=>{try{let g=localStorage.getItem(n);return g?JSON.parse(g):[]}catch{return []}},l=g=>{try{localStorage.setItem(n,JSON.stringify(g));}catch{}},T=g=>{try{let y=localStorage.getItem(r(g));return y?JSON.parse(y):null}catch{return null}},I=g=>{try{localStorage.setItem(r(g.id),JSON.stringify(g));}catch{}},C=g=>{let y=s(),v=y.findIndex(k=>k.id===g.id);v>=0?y[v]=g:y.unshift(g),l(y);},d=g=>{let v=s().filter(k=>k.id!==g);l(v);},x=g=>{try{localStorage.removeItem(r(g));}catch{}};return {loadChatsIndex:s,saveChatsIndex:l,loadChat:T,saveChat:I,upsertChatMeta:C,deleteChatMeta:d,deleteChatData:x,deleteChat:g=>{x(g),d(g);},loadShowChatPreference:g=>{try{let y=localStorage.getItem(a);return y!==null?y==="true":g}catch{return g}},saveShowChatPreference:g=>{try{localStorage.setItem(a,String(g));}catch{}},loadCurrentChatId:()=>{try{return localStorage.getItem(o)}catch{return null}},saveCurrentChatId:g=>{try{localStorage.setItem(o,g);}catch{}},removeCurrentChatId:()=>{try{localStorage.removeItem(o);}catch{}}}}function nn(e){let t=Date.now()-e,n=Math.max(1,Math.floor(t/1e3));if(n<60)return `${n}s`;let r=Math.floor(n/60);if(r<60)return `${r}m`;let o=Math.floor(r/60);if(o<24)return `${o}h`;let a=Math.floor(o/24);if(a<7)return `${a}d`;let s=Math.floor(a/7);if(s<4)return `${s}w`;let l=Math.floor(a/30);return l<12?`${l}mo`:`${Math.floor(l/12)}y`}function on({historyOpen:e,historySearch:t,currentChatId:n,refreshKey:r,resolvedColors:o,onClose:a,onSearchChange:s,onChatSelect:l,onChatDelete:T,loadChatsIndex:I,historyPopupRef:C}){if(!e)return null;let d=jsxs(Fragment,{children:[jsx("div",{style:{position:"fixed",inset:"0",zIndex:1100,backgroundColor:"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)"},onClick:a}),jsxs("div",{ref:C,style:{position:"fixed",left:"50%",top:"64px",transform:"translateX(-50%)",zIndex:1101,width:"680px",maxWidth:"94vw",overflow:"hidden",borderRadius:"16px",border:`1px solid ${o.borderColor}`,backgroundColor:`${o.backgroundColor}f0`,boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)"},children:[jsx("div",{style:{display:"flex",alignItems:"center",gap:"12px",borderBottom:`1px solid ${o.borderColor}`,padding:"12px 16px"},children:jsx("div",{style:{flex:"1"},children:jsx("input",{autoFocus:true,value:t,onChange:x=>s(x.target.value),placeholder:"Search",style:{width:"100%",borderRadius:"8px",backgroundColor:o.inputBackground,padding:"8px 12px",fontSize:"14px",color:o.textColor,border:`1px solid ${o.borderColor}`,outline:"none"},onFocus:x=>x.currentTarget.style.borderColor=o.primaryColor,onBlur:x=>x.currentTarget.style.borderColor=o.borderColor})})}),jsx("div",{style:{maxHeight:"60vh",overflowY:"auto"},children:(()=>{let x=t.toLowerCase().trim(),f=I();return x&&(f=f.filter(u=>(u.title||"").toLowerCase().includes(x))),!f||f.length===0?jsx("div",{style:{padding:"24px",color:o.mutedTextColor,textAlign:"center"},children:"No chats found."}):jsx("div",{children:f.map((u,w)=>jsx("div",{style:{borderTop:w>0?`1px solid ${o.borderColor}`:"none"},children:jsxs("div",{style:{display:"flex",width:"100%",alignItems:"center",justifyContent:"space-between",gap:"12px",padding:"12px",backgroundColor:u.id===n?o.cardBackground:"transparent"},children:[jsx("button",{style:{flex:"1",textAlign:"left",transition:"background-color 0.2s",borderRadius:"8px",padding:"8px",border:"none",backgroundColor:"transparent",cursor:"pointer",color:o.textColor},onMouseEnter:i=>i.currentTarget.style.backgroundColor=o.hoverBackground,onMouseLeave:i=>i.currentTarget.style.backgroundColor="transparent",onClick:()=>l(u.id),children:jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"12px"},children:[jsx("div",{style:{minWidth:"0",flex:"1"},children:jsx("div",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"14px",color:o.textColor},children:u.title||"Untitled chat"})}),jsx("div",{style:{flexShrink:0,fontSize:"12px",color:o.mutedTextColor},children:nn(u.updatedAt)})]})}),jsx("button",{style:{flexShrink:0,borderRadius:"6px",padding:"8px",color:o.mutedTextColor,border:"1px solid transparent",backgroundColor:"transparent",cursor:"pointer",transition:"all 0.2s"},title:"Delete chat",onMouseEnter:i=>{i.currentTarget.style.color="#ef4444",i.currentTarget.style.backgroundColor="rgba(239, 68, 68, 0.1)",i.currentTarget.style.borderColor="rgba(239, 68, 68, 0.3)";},onMouseLeave:i=>{i.currentTarget.style.color=o.mutedTextColor,i.currentTarget.style.backgroundColor="transparent",i.currentTarget.style.borderColor="transparent";},onClick:i=>{i.stopPropagation(),T(u.id);},children:jsx(ee,{IconComponent:Trash2,size:"16",strokeWidth:"2"})})]})},u.id))})})()})]})]});return typeof document<"u"&&document.body?createPortal(d,document.body):d}function rn(e,t,n){return new DefaultChatTransport({api:`${e}/api/run/${t}`,fetch:async(r,o)=>{let s={...o?.body?JSON.parse(o.body):{},chatId:n};return fetch(r,{...o,body:JSON.stringify(s)})}})}function wo(e){if(!(e instanceof HTMLElement))return true;let t=window.getComputedStyle(e);return t.display!=="none"&&t.visibility!=="hidden"&&t.opacity!=="0"&&e.offsetParent!==null}function To(e){if(e.id){let n=document.querySelector(`label[for="${e.id}"]`);if(n)return n.textContent?.trim()}let t=e.closest("label");if(t){let n=t.cloneNode(true),r=n.querySelector("input, select, textarea");return r&&r.remove(),n.textContent?.trim()}}function bt(e){if(e.textContent&&e.textContent.trim())return e.textContent.trim().slice(0,100)}function Ct(e){if(e instanceof HTMLInputElement){let t=e.type.toLowerCase();return t==="checkbox"||t==="radio"?e.checked:e.value}if(e instanceof HTMLTextAreaElement)return e.value;if(e instanceof HTMLSelectElement)return e.multiple?Array.from(e.selectedOptions).map(t=>t.value):e.value;if(e instanceof HTMLElement&&e.isContentEditable)return e.textContent||void 0}function So(e){if(e.id)return `#${e.id}`;let t=[],n=e;for(;n&&n!==document.body;){let r=n.tagName.toLowerCase();if(n.className&&typeof n.className=="string"){let a=n.className.split(" ").filter(s=>s.trim()).slice(0,2);a.length>0&&(r+="."+a.join("."));}let o=n.parentElement;if(o){let a=Array.from(o.children).filter(s=>s.tagName===n.tagName);if(a.length>1){let s=a.indexOf(n)+1;r+=`:nth-child(${s})`;}}t.unshift(r),n=o;}return t.slice(-3).join(" > ")}async function Le(e={}){try{let{includeHidden:t=!1,selector:n,what:r="content",limit:o}=e,a=document.querySelector(".hsafa-content-container");if(!a)return {ok:!1,components:[],count:0,total:0,containerFound:!1,error:"ContentContainer not found on page. Make sure you have wrapped your app with <ContentContainer>."};let s=n&&a.querySelector(n)||a,l=[],T=[];r==="inputs"?T=["input","textarea","select",'[contenteditable="true"]','[contenteditable=""]']:T=["header","nav","main","section","article","aside","footer","h1","h2","h3","h4","h5","h6","p","img[alt]","ul","ol","li","table","thead","tbody","tr","td","th","form","label","input","textarea","select",'[contenteditable="true"]','[contenteditable=""]',"a[href]","button",'[role="button"]','[role="link"]',"[onclick]","[tabindex]","div"],s.querySelectorAll(T.join(", ")).forEach(i=>{let h=wo(i);if(!h&&!t)return;let p={id:i.id||null,tag:i.tagName.toLowerCase(),className:i.className&&typeof i.className=="string"?i.className:void 0,isVisible:h,isInteractive:!0,selector:So(i)};i instanceof HTMLInputElement?(p.type=i.type,p.name=i.name||void 0,p.placeholder=i.placeholder||void 0,p.value=Ct(i),p.checked=i.type==="checkbox"||i.type==="radio"?i.checked:void 0,p.disabled=i.disabled,p.required=i.required):i instanceof HTMLTextAreaElement?(p.name=i.name||void 0,p.placeholder=i.placeholder||void 0,p.value=Ct(i),p.disabled=i.disabled,p.required=i.required):i instanceof HTMLSelectElement?(p.name=i.name||void 0,p.value=Ct(i),p.disabled=i.disabled,p.required=i.required,p.options=Array.from(i.options).map(g=>({value:g.value,label:g.text,selected:g.selected,disabled:g.disabled}))):i instanceof HTMLButtonElement?(p.type=i.type,p.disabled=i.disabled,p.text=bt(i)):i instanceof HTMLAnchorElement?(p.href=i.href,p.text=bt(i)):i instanceof HTMLImageElement?(p.text=i.alt||void 0,p.label=i.alt||p.label):p.text=bt(i),p.label=To(i),p.role=i.getAttribute("role")||void 0,p.ariaLabel=i.getAttribute("aria-label")||void 0,l.push(p);});let C=i=>i.isVisible?r==="inputs"?i.tag==="input"||i.tag==="textarea"||i.tag==="select"||i.role==="textbox"?3:i.tag==="button"||i.tag==="a"?2:1:["header","nav","main","footer"].includes(i.tag)?5:["section","article","aside"].includes(i.tag)||["h1","h2","h3"].includes(i.tag)?4:["h4","h5","h6"].includes(i.tag)?3:i.tag==="form"?4:i.tag==="label"?3:i.tag==="input"||i.tag==="textarea"||i.tag==="select"?4:i.tag==="p"||i.tag==="img"||i.tag==="button"||i.tag==="a"?3:1:0;l.sort((i,h)=>C(h)-C(i));let d=l.length,f=Math.max(1,Math.min(200,typeof o=="number"?Math.floor(o):r==="inputs"?100:150)),u=d>f,w=u?l.slice(0,f):l;return {ok:!0,components:w,count:w.length,total:d,truncated:u,containerFound:!0}}catch(t){return {ok:false,components:[],count:0,total:0,containerFound:false,error:t?.message||String(t)}}}typeof window<"u"&&(window.getDomComponents=Le);async function fe(e,t={}){if(typeof window>"u")return {ok:false,steps:[{ok:false,action:"none",targetKind:"position",durationMs:0,error:"guideCursor only works in browser environment"}]};let n=window.__cursorGuide;if(!n)return {ok:false,steps:[{ok:false,action:"none",targetKind:"position",durationMs:0,error:"CursorController not initialized. Make sure to mount <CursorController /> component."}]};try{return await n(e,t)}catch(r){return {ok:false,steps:[{ok:false,action:t.action||"none",targetKind:"position",durationMs:0,error:r?.message||String(r)}]}}}typeof window<"u"&&(window.guideCursor=fe);function an(e){return !!e&&e.nodeType===1}function re(e,t){e.dispatchEvent(new Event(t,{bubbles:true}));}function sn(e,t){let n=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(e),"value")?.set;n?n.call(e,t):e.value=t,re(e,"input");}function Mo(e,t){e.checked!==t&&e.click();}function Eo(e,t){if(typeof t=="object"&&t&&"index"in t&&typeof t.index=="number")e.selectedIndex=Math.max(0,Math.min(e.options.length-1,t.index));else if(typeof t=="object"&&t&&"label"in t&&typeof t.label=="string"){let n=Array.from(e.options).findIndex(r=>r.text===t.label);e.selectedIndex=n>=0?n:0;}else e.value=String(t);re(e,"input"),re(e,"change");}function Io(e,t){let n=new Set(t.map(String));Array.from(e.options).forEach(r=>{r.selected=n.has(r.value)||n.has(r.text);}),re(e,"input"),re(e,"change");}function Ao(e){return e?e instanceof Date?e.toISOString().slice(0,10):String(e):""}function Ro(e,t){let n=Array.isArray(t)?t:[t],r=new DataTransfer;for(let o of n)r.items.add(o);Object.defineProperty(e,"files",{value:r.files,configurable:true}),re(e,"input"),re(e,"change");}async function He(e,t={}){let n=document.activeElement||null;if(n&&an(n)){let r=n.closest('[contenteditable="true"], [contenteditable=""]');r&&(n=r);}if(!n||n===document.body)return {ok:false,filled:[{key:"active",status:"skipped",message:"No active input element"}],errors:["No active input element"]};try{let r=n.tagName.toLowerCase();if(r==="input"){let o=n,a=(o.type||"text").toLowerCase();if(a==="checkbox")Mo(o,!!e);else if(a==="radio"){let s=o.name;if(s&&e!=null&&String(o.value)!==String(e)){let l=document.querySelector(`input[type="radio"][name="${CSS.escape(s)}"][value="${CSS.escape(String(e))}"]`);l?l.click():o.click();}else o.click();}else if(a==="file")if(e instanceof File||Array.isArray(e)&&e.every(s=>s instanceof File))Ro(o,e);else return {ok:!1,filled:[{key:"active",status:"skipped",message:"Provide File or File[] for file input"}],errors:["Provide File or File[] for file input"]};else {let s=a==="date"?Ao(e):String(e??"");sn(o,s),re(o,"change");}return {ok:!0,filled:[{key:"active",status:"ok"}]}}if(r==="textarea"){let o=n,a=String(e??"");return sn(o,a),re(o,"change"),{ok:!0,filled:[{key:"active",status:"ok"}]}}if(r==="select"){let o=n;return o.multiple?Io(o,Array.isArray(e)?e:[e]):Eo(o,e),{ok:!0,filled:[{key:"active",status:"ok"}]}}if(an(n)&&n.isContentEditable){let o=n;return o.focus(),o.textContent=String(e??""),re(o,"input"),re(o,"change"),o.blur?.(),{ok:!0,filled:[{key:"active",status:"ok"}]}}return {ok:!1,filled:[{key:"active",status:"skipped",message:`Unsupported active element: ${r}`}],errors:[`Unsupported active element: ${r}`]}}catch(r){return {ok:false,filled:[{key:"active",status:"error",message:r?.message??String(r)}],errors:[r?.message??String(r)]}}}typeof window<"u"&&(window.FillActiveInput=He);var Be=null,Je={},cn=false,we=null,Qe=false;function kt(e){e.classList.add("visible");}function fn(){Qe=true,we!=null&&(clearTimeout(we),we=null);}function $o(e,t=1500){Qe||(we!=null&&clearTimeout(we),we=window.setTimeout(()=>{Qe||e.classList.remove("visible");},t));}function Lo(e,t=1200){Qe=false,$o(e,t);}function Ho(e){let t=[],n=e?.parentElement;for(;n;){let r=getComputedStyle(n),o=r.overflow+r.overflowY+r.overflowX;/(auto|scroll)/.test(o)&&t.push(n),n=n.parentElement;}return t}async function Bo(e,t=1500,n=160){let r=performance.now(),o=e?Ho(e):[],a=()=>{let C=[window.scrollX||document.documentElement.scrollLeft||0,window.scrollY||document.documentElement.scrollTop||0];return o.forEach(d=>{C.push(d.scrollLeft,d.scrollTop);}),C},s=()=>{if(!e)return {x:0,y:0};let C=e.getBoundingClientRect();return {x:C.left,y:C.top}},l=a(),T=s(),I=performance.now();return new Promise(C=>{function d(x){let f=a(),u=s(),w=false;for(let i=0;i<f.length;i++)if(f[i]!==l[i]){w=true;break}if(!w&&e&&(u.x!==T.x||u.y!==T.y)&&(w=true),w&&(l=f,T=u,I=x),x-I>=n||x-r>=t){C();return}requestAnimationFrame(d);}requestAnimationFrame(d);})}var Do='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="32px" height="32px"><path d="M 7.2304688 4.9863281 C 5.9215232 4.8276681 4.8053213 6.0177722 5.0234375 7.3066406 A 1.0001 1.0001 0 0 0 5.0253906 7.3085938 C 5.9996339 12.981516 7.7205826 18.716222 10 24.515625 A 1.0001 1.0001 0 0 0 10 24.517578 C 10.26886 25.199332 10.914322 25.653844 11.5625 25.738281 C 12.210678 25.822721 12.879213 25.592031 13.359375 25.09375 C 14.505165 23.921134 15.214424 22.695429 15.90625 21.498047 C 17.56565 23.217848 19.256845 24.909775 21.0625 26.484375 L 21.060547 26.480469 C 21.799528 27.12933 22.841378 27.205969 23.673828 26.78125 A 1.0001 1.0001 0 0 0 23.691406 26.771484 C 24.987999 26.077693 26.028685 25.052256 26.71875 23.746094 L 26.71875 23.744141 C 27.174557 22.900924 27.06954 21.854242 26.439453 21.119141 A 1.0001 1.0001 0 0 0 26.433594 21.113281 C 24.867416 19.313474 23.193611 17.633865 21.488281 15.986328 C 22.714141 15.237691 23.933938 14.51508 25.158203 13.414062 A 1.0001 1.0001 0 0 0 25.162109 13.410156 C 26.052979 12.600274 25.977319 11.169141 25.101562 10.404297 A 1.0001 1.0001 0 0 0 24.669922 10.042969 C 18.793373 7.4738953 12.973806 5.6931843 7.2324219 4.9882812 A 1.0001 1.0001 0 0 0 7.2304688 4.9863281 z M 6.9960938 6.9746094 C 12.468883 7.6474978 18.081513 9.3573116 23.796875 11.849609 A 1.0001 1.0001 0 0 0 23.867188 11.884766 C 23.901248 11.899796 23.884276 11.867987 23.816406 11.929688 C 22.403891 13.198979 20.999383 14.076858 19.457031 14.976562 A 1.0001 1.0001 0 0 0 19.275391 16.568359 C 21.250864 18.425305 23.134972 20.36916 24.919922 22.419922 C 25.009402 22.524309 25.024026 22.676488 24.960938 22.792969 A 1.0001 1.0001 0 0 0 24.955078 22.804688 C 24.446951 23.770198 23.730542 24.476149 22.755859 25 C 22.611605 25.06851 22.457885 25.047856 22.378906 24.978516 A 1.0001 1.0001 0 0 0 22.376953 24.976562 C 20.293628 23.159824 18.307991 21.233373 16.419922 19.216797 A 1.0001 1.0001 0 0 0 14.835938 19.378906 C 13.841812 21.004716 13.152668 22.447221 11.925781 23.701172 A 1.0001 1.0001 0 0 0 11.919922 23.707031 C 11.883822 23.744501 11.865156 23.739957 11.847656 23.742188 C 9.6161121 18.057657 7.9395914 12.46667 6.9960938 6.9746094 z"/></svg>',Po='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="32px" height="32px"><path d="M 22.5 3 C 19.480226 3 17 5.4802259 17 8.5 L 17 23.412109 L 14.871094 22.697266 C 13.308963 22.172461 11.892528 22 10.703125 22 C 9.5908429 22 8.5540295 22.197475 7.640625 22.65625 C 5.2906802 23.831199 3.9427678 26.197397 4.0019531 28.90625 C 4.0019531 28.90625 4.0019531 28.908203 4.0019531 28.908203 C 4.0019531 28.908203 4.0019531 28.910156 4.0019531 28.910156 C 4.0184171 29.660452 4.4596385 30.354695 5.1328125 30.6875 A 1.50015 1.50015 0 0 0 5.1367188 30.689453 C 5.1367188 30.689453 9.4097266 32.789754 11.599609 33.949219 C 12.445613 34.397848 13.696939 34.926046 15.210938 36.09375 C 16.724935 37.261454 18.423179 39.012543 19.826172 41.792969 C 21.023611 44.165544 23.672779 45.195669 26.144531 44.955078 A 1.50015 1.50015 0 0 0 26.146484 44.955078 C 31.427085 44.439215 32.081856 44.381732 35.59375 44.023438 C 37.044229 43.875625 38.276993 43.213524 39.111328 42.289062 C 39.945663 41.364602 40.422895 40.257718 40.798828 39.125 C 41.561218 36.826116 42.933037 33.169846 43.671875 30.599609 C 45.018525 25.913269 41.884024 21.194549 37.246094 19.953125 L 37.242188 19.951172 C 36.99827 19.885452 36.756736 19.832884 36.521484 19.789062 A 1.50015 1.50015 0 0 0 36.513672 19.787109 L 28 18.248047 L 28 8.5 C 28 5.4802259 25.519774 3 22.5 3 z M 22.5 6 C 23.898226 6 25 7.1017741 25 8.5 L 25 19.5 A 1.50015 1.50015 0 0 0 26.232422 20.976562 L 35.980469 22.740234 C 36.14895 22.771804 36.312663 22.808524 36.464844 22.849609 A 1.50015 1.50015 0 0 0 36.46875 22.849609 C 39.614436 23.689967 41.641993 26.803286 40.789062 29.771484 C 40.115901 32.113248 38.752735 35.768572 37.953125 38.179688 C 37.641059 39.119968 37.279727 39.837554 36.882812 40.277344 C 36.485898 40.717133 36.095584 40.956874 35.289062 41.039062 C 31.783676 41.396695 31.135884 41.452908 25.855469 41.96875 C 24.423221 42.108159 23.024467 41.472831 22.503906 40.441406 C 20.887905 37.238832 18.854971 35.116296 17.042969 33.71875 C 15.230967 32.321204 13.560902 31.594199 13.003906 31.298828 C 10.939171 30.205625 7.8041786 28.665144 7.1035156 28.320312 C 7.1954033 26.8809 7.6810328 25.989859 8.9824219 25.339844 A 1.50015 1.50015 0 0 0 8.9863281 25.337891 C 9.3949198 25.132713 9.9434071 25 10.703125 25 C 11.605722 25 12.680146 25.12582 13.916016 25.541016 L 18.021484 26.921875 A 1.50015 1.50015 0 0 0 20 25.5 L 20 8.5 C 20 7.1017741 21.101774 6 22.5 6 z"/></svg>';async function zo(){if(!Je.arrow)try{Je.arrow=Do,Je.pointer=Po;}catch(e){console.warn("Failed to set cursor SVGs",e);}return Je}function dn({arrowSvg:e,pointerSvg:t}){return jsxs(Fragment,{children:[e&&jsx("div",{className:"arrow",dangerouslySetInnerHTML:{__html:e}}),t&&jsx("div",{className:"pointer",dangerouslySetInnerHTML:{__html:t}})]})}async function Wo(){let e="demo-fake-cursor",t=document.getElementById(e),n=await zo();if(!cn){let r="cursor-controller-styles";if(!document.getElementById(r)){let o=document.createElement("style");o.id=r,o.textContent=`
24
24
  .fake-cursor { pointer-events: none; opacity: 0; transition: opacity 0.2s ease; z-index: 2147483647; }
25
25
  .fake-cursor.visible { opacity: 1; }
26
26
  .fake-cursor .arrow { display: none; }
@@ -30,14 +30,14 @@ import {jsxs,jsx,Fragment}from'react/jsx-runtime';import ot,{createContext,useRe
30
30
  .fake-cursor.as-pointer .arrow { display: none; }
31
31
  .fake-cursor.as-pointer .pointer { display: block; }
32
32
  .fake-cursor.pressing .pointer svg path { filter: brightness(0.9); }
33
- `,document.head.appendChild(r);}wn=true;}return t?(t.classList.add("as-arrow"),qe||(qe=createRoot(t),qe.render(jsx(Tn,{arrowSvg:n.arrow,pointerSvg:n.pointer})))):(t=document.createElement("div"),t.id=e,t.className="fake-cursor as-arrow",t.style.position="fixed",t.style.left="20px",t.style.top="20px",document.body.appendChild(t),qe=createRoot(t),qe.render(jsx(Tn,{arrowSvg:n.arrow,pointerSvg:n.pointer}))),t}function De(e,t,n){return Math.max(t,Math.min(n,e))}function Xr(e){return e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2}function Rn(e){if(!e)return null;let t=document.createElement("canvas").getContext("2d");if(!t)return null;t.fillStyle="#000",t.fillStyle=e;let o=t.fillStyle.match(/rgba?\(([^)]+)\)/i);if(!o)return null;let r=o[1].split(/\s*,\s*/).map(Number),[l,u,c,v=1]=r;return {r:l,g:u,b:c,a:v}}function Yr({r:e,g:t,b:n}){let o=[e,t,n].map(r=>r/255).map(r=>r<=.03928?r/12.92:Math.pow((r+.055)/1.055,2.4));return .2126*o[0]+.7152*o[1]+.0722*o[2]}function Jr(e){let t=e?Rn(e):null;return !t||t.a===0?false:Yr(t)<.5}function Zr(e,t){let n=document.elementFromPoint(e,t),o=new Set;for(;n&&!o.has(n);){o.add(n);let u=getComputedStyle(n).backgroundColor,c=Rn(u);if(c&&c.a>0)return u;n=n.parentElement;}return getComputedStyle(document.body).backgroundColor||"rgb(255,255,255)"}function Pt(e,t,n){let o=Zr(t,n),r=Jr(o),l=r?"#ffffff":"#000000";e.querySelectorAll("svg path").forEach(c=>{c.style.fill="white",c.style.stroke=l,c.style.strokeWidth="1";}),e.style.filter=r?"drop-shadow(0 1px 2px rgba(0,0,0,0.8))":"drop-shadow(0 1px 2px rgba(255,255,255,0.9))";}async function ct(e,t,n,o,r="ease-in-out",l="curve",u=.25,c="auto",v){In(),Dt(e);let S=performance.now(),a=r==="linear"?b=>b:Xr,T=l!=="straight",f={x:0,y:0};if(T){let b=n.x-t.x,g=n.y-t.y,k=Math.hypot(b,g)||1,i=(t.x+n.x)/2,m=(t.y+n.y)/2,h=-g/k,C=b/k,E=1;c==="left"?E=-1:c==="right"?E=1:E=Math.random()<.5?-1:1;let M=De(u,0,1)*k;f={x:i+E*h*M,y:m+E*C*M};}return new Promise(b=>{function g(k){let i=De((k-S)/o,0,1),m=a(i),h,C;if(T){let p=1-m;h=p*p*t.x+2*p*m*f.x+m*m*n.x,C=p*p*t.y+2*p*m*f.y+m*m*n.y;}else h=t.x+(n.x-t.x)*m,C=t.y+(n.y-t.y)*m;let M=.35*(1-m),w=Math.sin(k*.02)*M,y=Math.cos(k*.018)*M;e.style.left=`${h+w}px`,e.style.top=`${C+y}px`,Pt(e,h+w,C+y),v&&v({x:h+w,y:C+y,t:i,now:k}),i<1?requestAnimationFrame(g):b();}requestAnimationFrame(g);})}function Mn(e,t){return {x:e.x+(t?.x??0),y:e.y+(t?.y??0)}}function he(e,t,n,o){let r={bubbles:true,cancelable:true,view:window,clientX:n.x,clientY:n.y,...o};try{let l=t==="pointerdown"||t==="mousedown",u=t==="pointerup"||t==="mouseup",c={button:0,buttons:l?1:0,isPrimary:!0,...r};if("PointerEvent"in window){let v=new PointerEvent(t,{pointerId:1,pointerType:"mouse",...c});e.dispatchEvent(v);}else {let v=new MouseEvent(t,c);e.dispatchEvent(v);}}catch{let l=new MouseEvent(t,r);e.dispatchEvent(l);}}function Fn(e){return e&&typeof e=="object"&&e.nodeType===1}function Qr(e){if(!e)return document;if(Fn(e))return e;if(typeof e=="string"){let t=document.getElementById(e);if(t)return t;let n=document.querySelector(e);if(n)return n}return document}function Sn(e){if(Fn(e))return {kind:"element",element:e};if(typeof e=="string"){let t=document.getElementById(e);if(t)return {kind:"element",element:t};let n=document.querySelector(e);return {kind:n?"element":"position",element:n??null}}if(typeof e=="object"&&"position"in e)return {kind:"position",point:e.position};if(typeof e=="object"&&"selector"in e){let n=Qr(e.within??null).querySelectorAll(e.selector),o=Math.max(0,Math.min(n.length-1,e.nth??0)),r=n[o]??null;return {kind:r?"element":"position",element:r}}return {kind:"position",point:{x:0,y:0}}}function En(e,t){let n=e.getBoundingClientRect();if(!t||t==="center")return {x:n.left+n.width/2,y:n.top+n.height/2};if(t==="top-left")return {x:n.left,y:n.top};if(t==="bottom-right")return {x:n.right,y:n.bottom};let o=De(t.x,0,1),r=De(t.y,0,1);return {x:n.left+n.width*o,y:n.top+n.height*r}}function An(e){return {x:De(e.x,0,window.innerWidth),y:De(e.y,0,window.innerHeight)}}function eo(){return useEffect(()=>(window.__cursorGuide=async(e,t={})=>{let n=Array.isArray(e)?e:[{target:e,action:t.action??"none",options:t}],o=[],r=await Kr();r.classList.add("visible","as-arrow"),r.classList.remove("as-pointer","pressing"),Dt(r),In();let l=parseFloat(r.style.left||"20")||20,u=parseFloat(r.style.top||"20")||20;Pt(r,l,u);for(let c of n){let{durationMs:v=800,easing:S="ease-in-out",offset:a,highlight:T=true,path:f="curve",curveStrength:b=.25,curveDirection:g="auto",anchor:k,cursorHotspot:i,dragTo:m}=c.options??{},h=c.action??c.options?.action??"none",C=performance.now(),E=Sn(c.target),M=null,w=null;if(E.kind==="element"&&E.element?(w=E.element,r.classList.remove("visible"),w.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),await jr(w,1500,180),Dt(r),M=En(w,k)):E.kind==="position"&&E.point&&(M=E.point),!M){o.push({ok:false,action:h,targetKind:E.kind,durationMs:Math.round(performance.now()-C),error:"Target not found"});continue}let y={x:parseFloat(r.style.left||"20")||20,y:parseFloat(r.style.top||"20")||20},p=An(Mn(M,a));await ct(r,y,p,v,S,f,b,g);let F=p.x-y.x,U=p.y-y.y,q=Math.hypot(F,U)||1,Z=F/q,z=U/q,Q=Math.min(6,Math.max(3,q*.02)),V={x:p.x+Z*Q,y:p.y+z*Q};await ct(r,p,V,Math.max(70,v*.1),"ease-out","straight",0,"right"),await ct(r,V,p,120,"ease-out","straight",0,"left"),T&&(r.classList?.add("click"),setTimeout(()=>r.classList?.remove("click"),180));let ee=null;try{if(h==="click"){r.classList.remove("as-arrow"),r.classList.add("as-pointer","pressing");let $={x:i?.x??0,y:i?.y??0},H={x:p.x+$.x,y:p.y+$.y};r.style.left=`${H.x}px`,r.style.top=`${H.y}px`,Pt(r,H.x,H.y);let N=w??document.elementFromPoint(H.x,H.y)??document.body;he(N,"pointerdown",H),he(N,"mousedown",H),await new Promise(L=>setTimeout(L,90)),r.classList.remove("pressing"),he(N,"mouseup",H),he(N,"click",H),setTimeout(()=>{r.classList.remove("as-pointer"),r.classList.add("as-arrow");},140),N instanceof HTMLElement&&N.focus?.(),ee=N?.id??null;}else if(h==="drag"){if(!m)throw new Error("dragTo is required for action 'drag'");let $=Sn(m),H=null;if($.kind==="element"&&$.element&&(H=En($.element,k)),$.kind==="position"&&$.point&&(H=$.point),!H)throw new Error("dragTo target not found");let N=An(Mn(H,a)),L={x:p.x,y:p.y},ge=w??document.elementFromPoint(L.x,L.y)??document.body;r.classList.remove("as-arrow"),r.classList.add("as-pointer","pressing"),he(ge,"pointerdown",L),he(ge,"mousedown",L),await ct(r,L,N,Math.max(200,v),S,f,b,g,({x:Ve,y:Ke})=>{let ze=document.elementFromPoint(Ve,Ke)??document.body,ke={x:Ve,y:Ke};he(ze,"pointermove",ke),he(ze,"mousemove",ke);});let Ae=document.elementFromPoint(N.x,N.y)??document.body;r.classList.remove("pressing"),he(Ae,"pointerup",N),he(Ae,"mouseup",N);}o.push({ok:!0,action:h,targetKind:E.kind,durationMs:Math.round(performance.now()-C),clickedElementId:ee});}catch($){o.push({ok:false,action:h,targetKind:E.kind,durationMs:Math.round(performance.now()-C),error:$?.message??String($)});}}return Gr(r,2e3),{ok:o.every(c=>c.ok),steps:o}},()=>{try{delete window.__cursorGuide;}catch{window.__cursorGuide=void 0;}}),[]),null}var pt=eo;function lo({agentId:e,theme:t,primaryColor:n,primaryColorDark:o,primaryColorLight:r,backgroundColor:l,borderColor:u,textColor:c,accentColor:v,baseUrl:S="",initialMessages:a=[],onMessagesChange:T,defaultOpen:f=true,floatingButtonPosition:b={bottom:24,right:24},UIComponents:g={},HsafaTools:k={}}){let{dir:i,theme:m,baseUrl:h}=Le(),C=t||m||"dark",E=S&&S.length>0?S:h||"",y={primaryColor:C==="dark"?o||n||"#ffffff":r||n||"#000000",backgroundColor:l||(C==="dark"?"#0B0B0F":"#FFFFFF"),borderColor:u||(C==="dark"?"#2A2C33":"#E5E7EB"),textColor:c||(C==="dark"?"#EDEEF0":"#111827"),accentColor:v||(C==="dark"?"#17181C":"#F9FAFB"),mutedTextColor:C==="dark"?"#9AA0A6":"#6B7280",inputBackground:C==="dark"?"#17181C":"#F3F4F6",cardBackground:C==="dark"?"#121318":"#FFFFFF",hoverBackground:C==="dark"?"#1c1e25":"#F3F4F6"},p=s=>({"header.new":"New","header.history":"History","header.close":"Close chat","input.placeholder":"Ask your question...","input.attachFiles":"Attach files","input.insertLink":"Insert link","input.send":"Send","input.stop":"Stop","input.uploadingFiles":"Uploading files...","input.previewImage":"Preview image","input.removeFile":"Remove file","messages.empty":"Start by sending a message to the agent.","general.agent":"Agent","editor.cancel":"Cancel","editor.saveAndRegenerate":"Save & Regenerate","editor.clickToEdit":"Click to edit"})[s]||s,{attachments:F,uploading:U,fileInputRef:q,formatBytes:Z,handleRemoveAttachment:z,handleFileSelection:Q,clearAttachments:V}=nn(E),[ee,$]=useState(null),[H,N]=useState(""),[L,ge]=useState(()=>`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`),Ae=useMemo(()=>new DefaultChatTransport({api:`${E}/api/run/${e}`,fetch:async(s,d)=>{let R={...d?.body?JSON.parse(d.body):{},chatId:L};return fetch(s,{...d,body:JSON.stringify(R)})}}),[h,S,e,L]),Ve=useCallback(s=>{console.log("Message finished:",s);},[]),Ke=useCallback(s=>{console.error("Chat error:",s);},[]),ze=useMemo(()=>({getDomComponents:{tool:async({includeHidden:s,selector:d})=>await je({includeHidden:s,selector:d}),executeEachToken:false},controlCursor:{tool:async({target:s,action:d,anchor:x,durationMs:R,dragTo:B})=>{let O=await Ee(s,{action:d,anchor:x,durationMs:R,dragTo:B});if(O&&O.ok){let te=Array.isArray(O.steps)&&O.steps.length?O.steps[O.steps.length-1]:void 0,we=te?.clickedElementId?` (clicked element id: ${te.clickedElementId})`:"",ne=d||te?.action||"none";return {success:true,message:ne==="click"?`Cursor moved and clicked successfully${we}`:ne==="drag"?"Cursor dragged successfully":"Cursor moved successfully",details:O}}return {success:false,message:"Cursor action failed",details:O}},executeEachToken:false},fillActiveInput:{tool:async({value:s})=>{let d=await Ue(s);return {success:!!d?.ok,message:d?.ok?"Active input filled successfully":d?.errors?.[0]||"Failed to fill active input",details:d}},executeEachToken:true},getFromUser:{tool:async s=>({ok:true}),executeEachToken:true}}),[]),ke=useMemo(()=>({...ze,...k}),[ze,k]),ve=useRef(new Map),Ie=useRef(new Map),ft=useCallback(()=>{try{ve.current.forEach(s=>{try{s.remove();}catch{}}),ve.current.clear(),Ie.current.clear();}catch{}},[]),Xe=useCallback((s,d)=>{let x=ve.current.get(d);if(x){let A=x.parentElement,P=document.querySelector(`[data-get-from-user-host="${d}"]`);if(P&&A!==P){try{A?.removeChild(x);}catch{}P.innerHTML="",P.appendChild(x);}}else {x=document.createElement("div"),x.className="hsafa-inline-form";let A=document.querySelector(`[data-get-from-user-host="${d}"]`);A?(A.innerHTML="",A.appendChild(x)):(document.querySelector(".chat-scroll-container")||document.body).appendChild(x),ve.current.set(d,x);}let R=s?.title||"Provide input",B=s?.description||"",O=s?.submitLabel||"Submit",te=s?.skipLabel||"Skip",we=Array.isArray(s?.fields)?s.fields:s?.label||s?.placeholder?[{id:"value",label:s?.label||"Value",type:"text",placeholder:s?.placeholder||""}]:[],ne=Ie.current.get(d)||{submitted:false,skipped:false,values:void 0};x.innerHTML="";let X=document.createElement("form");X.style.margin="12px 0",X.style.padding="14px",X.style.border="1px solid var(--hsafa-border, #2A2C33)",X.style.borderRadius="12px",X.style.background="var(--hsafa-card, #121318)",X.style.color="var(--hsafa-text, #EDEEF0)",X.style.boxShadow="0 6px 20px rgba(0,0,0,0.25)";let Qe=document.createElement("div");if(Qe.style.fontWeight="600",Qe.style.marginBottom="6px",Qe.textContent=R,X.appendChild(Qe),B){let A=document.createElement("div");A.style.fontSize="12px",A.style.opacity="0.8",A.style.marginBottom="10px",A.textContent=B,X.appendChild(A);}we.forEach(A=>{let P=document.createElement("div");if(P.style.margin="10px 0",A.label){let I=document.createElement("label");I.style.display="block",I.style.fontSize="12px",I.style.marginBottom="6px",I.style.opacity="0.9",I.textContent=A.label,P.appendChild(I);}let j,Te=(A.type||"text").toLowerCase();if(Te==="textarea"){let I=document.createElement("textarea");I.placeholder=A.placeholder||"",I.value=A.value??"",I.style.width="100%",I.style.minHeight="72px",I.style.padding="10px 12px",I.style.border="1px solid var(--hsafa-border, #2A2C33)",I.style.borderRadius="10px",I.style.background="var(--hsafa-input-bg, #17181C)",I.style.color="inherit",j=I;}else if(Te==="select"&&Array.isArray(A.options)){let I=document.createElement("select");I.style.width="100%",I.style.padding="10px 12px",I.style.border="1px solid var(--hsafa-border, #2A2C33)",I.style.borderRadius="10px",I.style.background="var(--hsafa-input-bg, #17181C)",I.style.color="inherit",A.options.forEach(St=>{let Et=document.createElement("option");Et.value=String(St.value),Et.text=String(St.label??St.value),I.appendChild(Et);}),I.value=A.value??"",j=I;}else if(Te==="checkbox"){let I=document.createElement("input");I.type="checkbox",I.checked=!!A.value,I.style.transform="scale(1.1)",j=I;}else {let I=document.createElement("input");I.type=Te,I.placeholder=A.placeholder||"",I.value=A.value??"",I.style.width="100%",I.style.padding="10px 12px",I.style.border="1px solid var(--hsafa-border, #2A2C33)",I.style.borderRadius="10px",I.style.background="var(--hsafa-input-bg, #17181C)",I.style.color="inherit",j=I;}let Tt=A.id||"value";j.dataset.fieldId=Tt;let Mt=ne.values&&Object.prototype.hasOwnProperty.call(ne.values,Tt)?ne.values[Tt]:void 0;typeof Mt<"u"&&(j.type==="checkbox"?j.checked=!!Mt:j.value=String(Mt)),(ne.submitted||ne.skipped)&&(j.setAttribute("disabled","true"),j.style.opacity="0.7"),P.appendChild(j),X.appendChild(P);});let et=String(O).trim(),tt=String(te).trim(),nr=!!(et||tt),Y=null,_=null;if(nr){let A=document.createElement("div");A.style.display="flex",A.style.gap="8px",A.style.marginTop="10px",Y=document.createElement("button"),Y.type="submit",Y.textContent=et||"Submit",Y.style.padding="6px 10px",Y.style.borderRadius="8px",Y.style.background="var(--hsafa-button-bg, var(--hsafa-primary, #2563eb))",Y.style.color="#000000",_=document.createElement("button"),_.type="button",_.textContent=tt||"Skip",_.style.padding="6px 10px",_.style.borderRadius="8px",_.style.background="transparent",_.style.border="1px solid var(--hsafa-border, #2A2C33)",_.style.color="inherit",ne.submitted&&(Y.textContent=`${et||"Submit"} \u2713`,Y.style.opacity="0.8",Y.disabled=true),ne.skipped&&(_.textContent=`${tt||"Skip"} \u2713`,_.style.opacity="0.8",_.disabled=true),A.appendChild(Y),A.appendChild(_),X.appendChild(A);}if(X.onsubmit=A=>{A.preventDefault();let P={};X.querySelectorAll("[data-field-id]").forEach(j=>{let Te=j.dataset.fieldId||"value";j.type==="checkbox"?P[Te]=j.checked:P[Te]=j.value??"";}),Ie.current.set(d,{submitted:true,skipped:false,values:P}),yt.current.addToolResult({tool:"getFromUser",toolCallId:d,output:{success:true,submitted:true,values:P}}),X.querySelectorAll("[data-field-id]").forEach(j=>{j.disabled=true,j.style.opacity="0.7";}),Y&&(Y.textContent=`${et||"Submit"} \u2713`,Y.style.opacity="0.8",Y.disabled=true),_&&(_.disabled=true);},_&&(_.onclick=()=>{Ie.current.set(d,{submitted:false,skipped:true,values:void 0}),yt.current.addToolResult({tool:"getFromUser",toolCallId:d,output:{success:true,submitted:false,skipped:true}}),X.querySelectorAll("[data-field-id]").forEach(A=>{A.disabled=true,A.style.opacity="0.7";}),_&&(_.textContent=`${tt||"Skip"} \u2713`,_.style.opacity="0.8",_.disabled=true),Y&&(Y.disabled=true);}),ne.submitted||ne.skipped){let A=document.createElement("div");A.style.marginTop="10px",A.style.fontSize="12px",A.style.display="flex",A.style.alignItems="center",A.style.gap="8px";let P=document.createElement("span");P.style.display="inline-flex",P.style.alignItems="center",P.style.padding="2px 8px",P.style.borderRadius="999px",P.style.fontWeight="600",P.style.fontSize="11px",ne.submitted?(P.style.background="rgba(16,185,129,0.15)",P.style.color="#10b981",P.textContent="Submitted"):(P.style.background="rgba(234,179,8,0.15)",P.style.color="#eab308",P.textContent="Skipped"),A.appendChild(P),X.appendChild(A);}x.appendChild(X);},[]),yt=useRef(null),Ln=useCallback(s=>{let d=ke[s];return d?typeof d=="object"&&"tool"in d?d.tool:typeof d=="function"?d:null:null},[ke]),fe=useChat({transport:Ae,onFinish:Ve,onError:Ke,experimental_throttle:10,sendAutomaticallyWhen:lastAssistantMessageIsCompleteWithToolCalls,async onToolCall({toolCall:s}){let d=Ln(s.toolName);if(s.toolName==="getFromUser"||s.toolName==="get_from_user"){try{Xe(s.input,s.toolCallId);}catch(x){console.error("get_from_user render error",x);}return}if(d)try{let x=await d(s.input);fe.addToolResult({tool:s.toolName,toolCallId:s.toolCallId,output:x});}catch(x){fe.addToolResult({tool:s.toolName,toolCallId:s.toolCallId,state:"output-error",errorText:x?.message||String(x)});}}}),{messages:W,sendMessage:Ye,status:ht,stop:Hn,error:Wt}=fe;yt.current=fe;let Ot=useRef(new Map);useEffect(()=>{W.forEach(s=>{s.role==="assistant"&&s.parts?.forEach(d=>{if(!d.toolCallId)return;let x=d.toolName;if(!x&&d.type?.startsWith("tool-")&&(x=d.type.replace(/^tool-/,"")),!x)return;let R=ke[x];if(R&&typeof R=="object"&&R.executeEachToken&&R.tool){let B=d.input||d.args||{},O=JSON.stringify(B),te=Ot.current.get(d.toolCallId);if(O!==te&&O!=="{}"){Ot.current.set(d.toolCallId,O);try{x==="getFromUser"||x==="get_from_user"?Xe(B,d.toolCallId):R.tool(B);}catch(we){console.error(`Error executing streaming tool ${x}:`,we);}}}});});},[W,ke]),useEffect(()=>{try{let s=new Set,d=[];if(W.forEach(x=>{x.role==="assistant"&&(x.parts||[]).forEach(R=>{let B=R?.toolName||(typeof R?.type=="string"&&R.type.startsWith("tool-")?String(R.type.replace(/^tool-/,"")):void 0);if(B!=="getFromUser"&&B!=="get_from_user")return;let O=R?.toolCallId||"";if(!O)return;s.add(O);let te=R?.output;if(te&&(te.submitted||te.skipped||te.values)){let ne={submitted:!!te.submitted,skipped:!!te.skipped,values:te.values||void 0};Ie.current.set(O,ne);}let we=R?.input||R?.args||{};d.push({input:we,toolCallId:O});});}),ve.current.forEach((x,R)=>{if(!s.has(R)){let B=ve.current.get(R);try{B?.remove();}catch{}ve.current.delete(R),Ie.current.delete(R);}}),d.length>0){let x=requestAnimationFrame(()=>{d.forEach(({input:R,toolCallId:B})=>{try{Xe(R,B);}catch{}});});return ()=>cancelAnimationFrame(x)}}catch{}},[W,Xe]),useEffect(()=>{a&&a.length>0&&W.length===0&&console.log("Initial messages:",a);},[a,W.length]);let xt=useRef(T);useEffect(()=>{xt.current=T;},[T]);let We=useRef([]);useEffect(()=>{(W.length!==We.current.length||W.length>0&&We.current.length>0&&W[W.length-1]?.id!==We.current[We.current.length-1]?.id)&&xt.current&&(We.current=W,xt.current(W));},[W]);let J=ht==="submitted"||ht==="streaming",{setStreamingState:bt,setChatOpenState:Ct}=Le(),[Je,Nt]=useState(()=>{try{return Lt(e).loadShowChatPreference(!!f)}catch{return !!f}}),[Bn,kt]=useState(false),[Dn,Pn]=useState(""),[zn,Wn]=useState(0),On=useRef(null),Nn=useRef(null),[Gn,Gt]=useState(new Set),[_n,Ze]=useState(null),[_t,Oe]=useState(""),[vt,Re]=useState([]),[jn,jt]=useState(false),Ut=useRef(null),Un=useRef(null),qn=Qt(J),G=useMemo(()=>Lt(e),[e]),Ne=useRef(false),qt=useRef(false);useEffect(()=>{if(!qt.current){try{let s=G.loadCurrentChatId();if(s){Ne.current=!0,ge(s);let d=G.loadChat(s),x=d&&Array.isArray(d.messages)?d.messages:[];try{fe?.setMessages?.(x);}catch{}}}catch{}qt.current=true;}},[G]),useEffect(()=>{if(W.length!==0)if(Ne.current){if(!J){let s=Date.now();G.saveChat({id:L,messages:W,agentId:e});let x=G.loadChatsIndex().find(R=>R.id===L);x&&G.upsertChatMeta({...x,updatedAt:s});}}else {let s=W.find(d=>d.role==="user");if(s){let d="";if(Array.isArray(s.parts)){let B=s.parts.find(O=>O&&O.type==="text");d=B&&typeof B.text=="string"?B.text:"";}let x=(d||"New chat").slice(0,80),R=Date.now();G.upsertChatMeta({id:L,title:x,createdAt:R,updatedAt:R}),G.saveChat({id:L,messages:W,agentId:e}),G.saveCurrentChatId(L),Ne.current=true;}}},[W,e,L,G,J]);let wt=useRef(false);useEffect(()=>{if(J){wt.current=true;return}if(wt.current){wt.current=false;try{let s=Date.now();G.saveChat({id:L,messages:W,agentId:e});let x=G.loadChatsIndex().find(R=>R.id===L);x&&G.upsertChatMeta({...x,updatedAt:s});}catch{}}},[J,W,L,e,G]),useEffect(()=>{try{bt(L,J);}catch{}return ()=>{try{bt(L,!1);}catch{}}},[L,J,bt]),useEffect(()=>{try{Ct(L,Je);}catch{}return ()=>{try{Ct(L,!1);}catch{}}},[L,Je,Ct]);let Vn=useCallback(async()=>{let s=H.trim();if(!(!s&&F.length===0)&&!J)try{await Ye({text:s,files:F.map(d=>({type:"file",url:d.url,mediaType:d.mimeType||"application/octet-stream",...d.name?{name:d.name}:{},...d.size?{size:d.size}:{}}))}),N(""),V(),$(null);}catch(d){console.error("Failed to send message:",d),$("Failed to send message. Please try again.");}},[H,F,J,Ye,V]),Vt=useCallback(()=>{if(J)return;ft(),N(""),V(),$(null),Ze(null),Oe(""),Re([]);try{fe?.setMessages?.([]);}catch{}Ne.current=false;let s=`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`;ge(s);try{G.saveCurrentChatId(s);}catch{}},[J,V,G,fe,ft]),Kn=useCallback(()=>{kt(s=>!s);},[]),Xn=useCallback(()=>{Nt(false);try{G.saveShowChatPreference(!1);}catch{}},[G]),Yn=useCallback(async s=>{let d=s.target.files;d&&await Q(d,$),q.current&&(q.current.value="");},[Q,q]);useEffect(()=>{let s=Ut.current;if(!s)return;s.style.height="24px",s.offsetHeight,s.style.height="auto";let d=Math.min(s.scrollHeight,200);s.style.height=`${d}px`;},[H]),ot.useEffect(()=>{let s=Un.current;if(!s)return;s.style.height="auto",s.offsetHeight;let d=Math.min(Math.max(s.scrollHeight,48),300);s.style.height=`${d}px`;},[_t]);let Jn=useCallback(async s=>{jt(true);try{let d=await Promise.all(Array.from(s).map(async x=>{let R=new FormData;R.append("file",x);let B=await fetch(`${E}/api/upload`,{method:"POST",body:R});if(!B.ok)throw new Error(`Upload failed: ${B.statusText}`);let O=await B.json();return {id:O.url||`${Date.now()}-${Math.random()}`,name:x.name,url:O.url,mimeType:x.type,size:x.size}}));Re(x=>[...x,...d]);}catch(d){console.error("Failed to upload files:",d),$("Failed to upload files. Please try again.");}finally{jt(false);}},[E]),Zn=useCallback(s=>{Re(d=>d.filter(x=>x.id!==s));},[]),Qn=useCallback((s,d,x)=>{Ze(s),Oe(d),Re(x||[]);},[]),er=useCallback(()=>{Ze(null),Oe(""),Re([]);},[]),tr=useCallback(async(s,d)=>{if(!J)try{let x=W.findIndex(B=>B.id===s);if(x===-1)return;let R=W.slice(0,x);try{fe?.setMessages?.(R);}catch{}await Ye({text:d.trim(),files:vt.map(B=>({type:"file",url:B.url,mediaType:B.mimeType||"application/octet-stream",...B.name?{name:B.name}:{},...B.size?{size:B.size}:{}}))}),Ze(null),Oe(""),Re([]);}catch(x){console.error("Failed to save edit:",x),$("Failed to save message. Please try again.");}},[J,W,Ye,fe,vt]),Kt=jsxs("div",{style:{position:"fixed",right:0,top:0,bottom:0,width:"420px",display:"flex",flexDirection:"column",padding:"24px 16px",color:y.textColor,gap:"16px",zIndex:1e3,transform:Je?"translateX(0)":"translateX(100%)",transition:"transform 0.25s ease-out, width 0.2s ease-out"},children:[jsx(an,{title:p("general.agent"),alwaysOpen:false,streaming:J,dir:i||"ltr",resolvedColors:y,onNew:Vt,onToggleHistory:Kn,onClose:Xn,historyBtnRef:On,t:p}),jsx("div",{ref:qn,className:"chat-scroll-container",style:{flex:"1",overflowY:"auto",overflowX:"hidden",padding:"16px 4px 16px 4px",display:"flex",flexDirection:"column",gap:"16px",scrollBehavior:"smooth","--hsafa-primary":y.primaryColor,"--hsafa-border":y.borderColor,"--hsafa-card":y.cardBackground,"--hsafa-text":y.textColor,"--hsafa-muted":y.mutedTextColor,"--hsafa-bg":y.backgroundColor,"--hsafa-hover":y.hoverBackground,"--hsafa-input-bg":y.inputBackground,"--hsafa-accent":y.accentColor},children:W.length===0?jsx("div",{style:{padding:"32px",textAlign:"center",color:y.mutedTextColor,fontSize:"14px"},children:p("messages.empty")}):jsx(yn,{chatMessages:W,isLoading:J,openReasoningIds:Gn,toggleReasoning:s=>Gt(d=>{let x=new Set(d);return x.has(s)?x.delete(s):x.add(s),x}),resolvedColors:y,t:p,onUserMessageClick:Qn,editingMessageId:_n,editingText:_t,onEditingTextChange:Oe,onCancelEdit:er,onSaveEdit:tr,editAttachments:vt,onRemoveEditAttachment:Zn,onAddEditAttachments:Jn,editUploading:jn,UIComponents:g})}),jsxs("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px"},children:[ee&&jsxs("div",{style:{padding:"8px 12px",marginBottom:"8px",backgroundColor:"#ef4444",color:"#fff",borderRadius:"8px",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsx("span",{children:ee}),jsx("button",{onClick:()=>$(null),style:{background:"none",border:"none",color:"#fff",cursor:"pointer",padding:"2px"},children:"\xD7"})]}),Wt&&jsxs("div",{style:{padding:"8px 12px",marginBottom:"8px",backgroundColor:"#ef4444",color:"#fff",borderRadius:"8px",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxs("span",{children:["An error occurred: ",Wt.message||"Please try again."]}),jsx("button",{onClick:()=>window.location.reload(),style:{background:"none",border:"1px solid #fff",color:"#fff",cursor:"pointer",padding:"4px 8px",borderRadius:"4px",fontSize:"12px"},children:"Refresh"})]}),jsx(hn,{input:H,setInput:N,textareaRef:Ut,fileInputRef:q,isLoading:J,uploading:U,attachments:F,formatBytes:Z,handleRemoveAttachment:z,onFileInputChange:Yn,onSend:Vn,onStop:()=>Hn(),status:ht,t:p,resolvedColors:y})]}),jsx(bn,{historyOpen:Bn,historySearch:Dn,currentChatId:L,refreshKey:zn,resolvedColors:y,onClose:()=>kt(false),onSearchChange:Pn,onChatSelect:s=>{if(kt(false),s&&s!==L){Ne.current=true,ft(),ge(s);try{G.saveCurrentChatId(s);}catch{}try{let d=G.loadChat(s),x=d&&Array.isArray(d.messages)?d.messages:[];try{fe?.setMessages?.(x);}catch{}}catch{}}},onChatDelete:s=>{try{G.deleteChat(s),Wn(d=>d+1),s===L&&Vt();}catch{}},loadChatsIndex:()=>G.loadChatsIndex(),historyPopupRef:Nn}),jsx("style",{children:`
33
+ `,document.head.appendChild(o);}cn=true;}return t?(t.classList.add("as-arrow"),Be||(Be=createRoot(t),Be.render(jsx(dn,{arrowSvg:n.arrow,pointerSvg:n.pointer})))):(t=document.createElement("div"),t.id=e,t.className="fake-cursor as-arrow",t.style.position="fixed",t.style.left="20px",t.style.top="20px",document.body.appendChild(t),Be=createRoot(t),Be.render(jsx(dn,{arrowSvg:n.arrow,pointerSvg:n.pointer}))),t}function Te(e,t,n){return Math.max(t,Math.min(n,e))}function No(e){return e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2}function yn(e){if(!e)return null;let t=document.createElement("canvas").getContext("2d");if(!t)return null;t.fillStyle="#000",t.fillStyle=e;let r=t.fillStyle.match(/rgba?\(([^)]+)\)/i);if(!r)return null;let o=r[1].split(/\s*,\s*/).map(Number),[a,s,l,T=1]=o;return {r:a,g:s,b:l,a:T}}function Oo({r:e,g:t,b:n}){let r=[e,t,n].map(o=>o/255).map(o=>o<=.03928?o/12.92:Math.pow((o+.055)/1.055,2.4));return .2126*r[0]+.7152*r[1]+.0722*r[2]}function Go(e){let t=e?yn(e):null;return !t||t.a===0?false:Oo(t)<.5}function Uo(e,t){let n=document.elementFromPoint(e,t),r=new Set;for(;n&&!r.has(n);){r.add(n);let s=getComputedStyle(n).backgroundColor,l=yn(s);if(l&&l.a>0)return s;n=n.parentElement;}return getComputedStyle(document.body).backgroundColor||"rgb(255,255,255)"}function vt(e,t,n){let r=Uo(t,n),o=Go(r),a=o?"#ffffff":"#000000";e.querySelectorAll("svg path").forEach(l=>{l.style.fill="white",l.style.stroke=a,l.style.strokeWidth="1";}),e.style.filter=o?"drop-shadow(0 1px 2px rgba(0,0,0,0.8))":"drop-shadow(0 1px 2px rgba(255,255,255,0.9))";}async function Ze(e,t,n,r,o="ease-in-out",a="curve",s=.25,l="auto",T){fn(),kt(e);let I=performance.now(),C=o==="linear"?f=>f:No,d=a!=="straight",x={x:0,y:0};if(d){let f=n.x-t.x,u=n.y-t.y,w=Math.hypot(f,u)||1,i=(t.x+n.x)/2,h=(t.y+n.y)/2,p=-u/w,g=f/w,y=1;l==="left"?y=-1:l==="right"?y=1:y=Math.random()<.5?-1:1;let v=Te(s,0,1)*w;x={x:i+y*p*v,y:h+y*g*v};}return new Promise(f=>{function u(w){let i=Te((w-I)/r,0,1),h=C(i),p,g;if(d){let m=1-h;p=m*m*t.x+2*m*h*x.x+h*h*n.x,g=m*m*t.y+2*m*h*x.y+h*h*n.y;}else p=t.x+(n.x-t.x)*h,g=t.y+(n.y-t.y)*h;let v=.35*(1-h),k=Math.sin(w*.02)*v,b=Math.cos(w*.018)*v;e.style.left=`${p+k}px`,e.style.top=`${g+b}px`,vt(e,p+k,g+b),T&&T({x:p+k,y:g+b,t:i,now:w}),i<1?requestAnimationFrame(u):f();}requestAnimationFrame(u);})}function un(e,t){return {x:e.x+(t?.x??0),y:e.y+(t?.y??0)}}function ce(e,t,n,r){let o={bubbles:true,cancelable:true,view:window,clientX:n.x,clientY:n.y,...r};try{let a=t==="pointerdown"||t==="mousedown",s=t==="pointerup"||t==="mouseup",l={button:0,buttons:a?1:0,isPrimary:!0,...o};if("PointerEvent"in window){let T=new PointerEvent(t,{pointerId:1,pointerType:"mouse",...l});e.dispatchEvent(T);}else {let T=new MouseEvent(t,l);e.dispatchEvent(T);}}catch{let a=new MouseEvent(t,o);e.dispatchEvent(a);}}function hn(e){return e&&typeof e=="object"&&e.nodeType===1}function jo(e){if(!e)return document;if(hn(e))return e;if(typeof e=="string"){let t=document.getElementById(e);if(t)return t;let n=document.querySelector(e);if(n)return n}return document}function pn(e){if(hn(e))return {kind:"element",element:e};if(typeof e=="string"){let t=document.getElementById(e);if(t)return {kind:"element",element:t};let n=document.querySelector(e);return {kind:n?"element":"position",element:n??null}}if(typeof e=="object"&&"position"in e)return {kind:"position",point:e.position};if(typeof e=="object"&&"selector"in e){let n=jo(e.within??null).querySelectorAll(e.selector),r=Math.max(0,Math.min(n.length-1,e.nth??0)),o=n[r]??null;return {kind:o?"element":"position",element:o}}return {kind:"position",point:{x:0,y:0}}}function mn(e,t){let n=e.getBoundingClientRect();if(!t||t==="center")return {x:n.left+n.width/2,y:n.top+n.height/2};if(t==="top-left")return {x:n.left,y:n.top};if(t==="bottom-right")return {x:n.right,y:n.bottom};let r=Te(t.x,0,1),o=Te(t.y,0,1);return {x:n.left+n.width*r,y:n.top+n.height*o}}function gn(e){return {x:Te(e.x,0,window.innerWidth),y:Te(e.y,0,window.innerHeight)}}function qo(){return useEffect(()=>(window.__cursorGuide=async(e,t={})=>{let n=Array.isArray(e)?e:[{target:e,action:t.action??"none",options:t}],r=[],o=await Wo();o.classList.add("visible","as-arrow"),o.classList.remove("as-pointer","pressing"),kt(o),fn();let a=parseFloat(o.style.left||"20")||20,s=parseFloat(o.style.top||"20")||20;vt(o,a,s);for(let l of n){let{durationMs:T=800,easing:I="ease-in-out",offset:C,highlight:d=true,path:x="curve",curveStrength:f=.25,curveDirection:u="auto",anchor:w,cursorHotspot:i,dragTo:h}=l.options??{},p=l.action??l.options?.action??"none",g=performance.now(),y=pn(l.target),v=null,k=null;if(y.kind==="element"&&y.element?(k=y.element,o.classList.remove("visible"),k.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),await Bo(k,1500,180),kt(o),v=mn(k,w)):y.kind==="position"&&y.point&&(v=y.point),!v){r.push({ok:false,action:p,targetKind:y.kind,durationMs:Math.round(performance.now()-g),error:"Target not found"});continue}let b={x:parseFloat(o.style.left||"20")||20,y:parseFloat(o.style.top||"20")||20},m=gn(un(v,C));await Ze(o,b,m,T,I,x,f,u);let A=m.x-b.x,M=m.y-b.y,O=Math.hypot(A,M)||1,G=A/O,D=M/O,q=Math.min(6,Math.max(3,O*.02)),U={x:m.x+G*q,y:m.y+D*q};await Ze(o,m,U,Math.max(70,T*.1),"ease-out","straight",0,"right"),await Ze(o,U,m,120,"ease-out","straight",0,"left"),d&&(o.classList?.add("click"),setTimeout(()=>o.classList?.remove("click"),180));let _=null;try{if(p==="click"){o.classList.remove("as-arrow"),o.classList.add("as-pointer","pressing");let R={x:i?.x??0,y:i?.y??0},$={x:m.x+R.x,y:m.y+R.y};o.style.left=`${$.x}px`,o.style.top=`${$.y}px`,vt(o,$.x,$.y);let P=k??document.elementFromPoint($.x,$.y)??document.body;ce(P,"pointerdown",$),ce(P,"mousedown",$),await new Promise(F=>setTimeout(F,90)),o.classList.remove("pressing"),ce(P,"mouseup",$),ce(P,"click",$),setTimeout(()=>{o.classList.remove("as-pointer"),o.classList.add("as-arrow");},140),P instanceof HTMLElement&&P.focus?.(),_=P?.id??null;}else if(p==="drag"){if(!h)throw new Error("dragTo is required for action 'drag'");let R=pn(h),$=null;if(R.kind==="element"&&R.element&&($=mn(R.element,w)),R.kind==="position"&&R.point&&($=R.point),!$)throw new Error("dragTo target not found");let P=gn(un($,C)),F={x:m.x,y:m.y},ie=k??document.elementFromPoint(F.x,F.y)??document.body;o.classList.remove("as-arrow"),o.classList.add("as-pointer","pressing"),ce(ie,"pointerdown",F),ce(ie,"mousedown",F),await Ze(o,F,P,Math.max(200,T),I,x,f,u,({x:De,y:Pe})=>{let Me=document.elementFromPoint(De,Pe)??document.body,ue={x:De,y:Pe};ce(Me,"pointermove",ue),ce(Me,"mousemove",ue);});let ye=document.elementFromPoint(P.x,P.y)??document.body;o.classList.remove("pressing"),ce(ye,"pointerup",P),ce(ye,"mouseup",P);}r.push({ok:!0,action:p,targetKind:y.kind,durationMs:Math.round(performance.now()-g),clickedElementId:_});}catch(R){r.push({ok:false,action:p,targetKind:y.kind,durationMs:Math.round(performance.now()-g),error:R?.message??String(R)});}}return Lo(o,2e3),{ok:r.every(l=>l.ok),steps:r}},()=>{try{delete window.__cursorGuide;}catch{window.__cursorGuide=void 0;}}),[]),null}var tt=qo;function xn(){return {getDomComponents:{tool:async({includeHidden:e,selector:t})=>await Le({includeHidden:e,selector:t}),executeEachToken:false},controlCursor:{tool:async({target:e,action:t,anchor:n,durationMs:r,dragTo:o})=>{let a=await fe(e,{action:t,anchor:n,durationMs:r,dragTo:o});if(a&&a.ok){let s=Array.isArray(a.steps)&&a.steps.length?a.steps[a.steps.length-1]:void 0,l=s?.clickedElementId?` (clicked element id: ${s.clickedElementId})`:"",T=t||s?.action||"none";return {success:true,message:T==="click"?`Cursor moved and clicked successfully${l}`:T==="drag"?"Cursor dragged successfully":"Cursor moved successfully",details:a}}return {success:false,message:"Cursor action failed",details:a}},executeEachToken:false},fillActiveInput:{tool:async({value:e})=>{let t=await He(e);return {success:!!t?.ok,message:t?.ok?"Active input filled successfully":t?.errors?.[0]||"Failed to fill active input",details:t}},executeEachToken:true},requestInput:{tool:async e=>({ok:true}),executeEachToken:true}}}function bn(e,t,n,r,o,a){let s=n.get(t);if(s){let y=s.parentElement,v=document.querySelector(`[data-get-from-user-host="${t}"]`);if(v&&y!==v){try{y?.removeChild(s);}catch{}v.innerHTML="",v.appendChild(s);}}else {s=document.createElement("div"),s.className="hsafa-inline-form";let y=document.querySelector(`[data-get-from-user-host="${t}"]`);y?(y.innerHTML="",y.appendChild(s)):(document.querySelector(".chat-scroll-container")||document.body).appendChild(s),n.set(t,s);}let l=e?.title||"Provide input",T=e?.description||"",I=e?.submitLabel||"Submit",C=e?.skipLabel||"Skip",d=Array.isArray(e?.fields)?e.fields:e?.label||e?.placeholder?[{id:"value",label:e?.label||"Value",type:"text",placeholder:e?.placeholder||""}]:[],x=r.get(t)||{submitted:false,skipped:false,values:void 0};s.innerHTML="";let f=document.createElement("form");f.style.margin="12px 0",f.style.padding="14px",f.style.border="1px solid var(--hsafa-border, #2A2C33)",f.style.borderRadius="12px",f.style.background="var(--hsafa-card, #121318)",f.style.color="var(--hsafa-text, #EDEEF0)",f.style.boxShadow="0 6px 20px rgba(0,0,0,0.25)";let u=document.createElement("div");if(u.style.fontWeight="600",u.style.marginBottom="6px",u.textContent=l,f.appendChild(u),T){let y=document.createElement("div");y.style.fontSize="12px",y.style.opacity="0.8",y.style.marginBottom="10px",y.textContent=T,f.appendChild(y);}d.forEach(y=>{let v=document.createElement("div");if(v.style.margin="10px 0",y.label){let M=document.createElement("label");M.style.display="block",M.style.fontSize="12px",M.style.marginBottom="6px",M.style.opacity="0.9",M.textContent=y.label,v.appendChild(M);}let k,b=(y.type||"text").toLowerCase();if(b==="textarea"){let M=document.createElement("textarea");M.placeholder=y.placeholder||"",M.value=y.value??"",M.style.width="100%",M.style.minHeight="72px",M.style.padding="10px 12px",M.style.border="1px solid var(--hsafa-border, #2A2C33)",M.style.borderRadius="10px",M.style.background="var(--hsafa-input-bg, #17181C)",M.style.color="inherit",k=M;}else if(b==="select"&&Array.isArray(y.options)){let M=document.createElement("select");M.style.width="100%",M.style.padding="10px 12px",M.style.border="1px solid var(--hsafa-border, #2A2C33)",M.style.borderRadius="10px",M.style.background="var(--hsafa-input-bg, #17181C)",M.style.color="inherit",y.options.forEach(O=>{let G=document.createElement("option");G.value=String(O.value),G.text=String(O.label??O.value),M.appendChild(G);}),M.value=y.value??"",k=M;}else if(b==="checkbox"){let M=document.createElement("input");M.type="checkbox",M.checked=!!y.value,M.style.transform="scale(1.1)",k=M;}else {let M=document.createElement("input");M.type=b,M.placeholder=y.placeholder||"",M.value=y.value??"",M.style.width="100%",M.style.padding="10px 12px",M.style.border="1px solid var(--hsafa-border, #2A2C33)",M.style.borderRadius="10px",M.style.background="var(--hsafa-input-bg, #17181C)",M.style.color="inherit",k=M;}let m=y.id||"value";k.dataset.fieldId=m;let A=x.values&&Object.prototype.hasOwnProperty.call(x.values,m)?x.values[m]:void 0;typeof A<"u"&&(k.type==="checkbox"?k.checked=!!A:k.value=String(A)),(x.submitted||x.skipped)&&(k.setAttribute("disabled","true"),k.style.opacity="0.7"),v.appendChild(k),f.appendChild(v);});let w=String(I).trim(),i=String(C).trim(),h=!!(w||i),p=null,g=null;if(h){let y=document.createElement("div");y.style.display="flex",y.style.gap="8px",y.style.marginTop="10px",p=document.createElement("button"),p.type="submit",p.textContent=w||"Submit",p.style.padding="6px 10px",p.style.borderRadius="8px",p.style.background="var(--hsafa-button-bg, var(--hsafa-primary, #2563eb))",p.style.color="#000000",g=document.createElement("button"),g.type="button",g.textContent=i||"Skip",g.style.padding="6px 10px",g.style.borderRadius="8px",g.style.background="transparent",g.style.border="1px solid var(--hsafa-border, #2A2C33)",g.style.color="inherit",y.appendChild(p),y.appendChild(g),f.appendChild(y);}if(f.onsubmit=y=>{y.preventDefault();let v={};f.querySelectorAll("[data-field-id]").forEach(k=>{let b=k.dataset.fieldId||"value";k.type==="checkbox"?v[b]=k.checked:v[b]=k.value??"";}),r.set(t,{submitted:true,skipped:false,values:v}),o({tool:"requestInput",toolCallId:t,output:{success:true,submitted:true,values:v}}),f.querySelectorAll("[data-field-id]").forEach(k=>{k.disabled=true,k.style.opacity="0.7";}),p&&(p.textContent=`${w||"Submit"} \u2713`,p.style.opacity="0.8",p.disabled=true),g&&(g.disabled=true);},g&&(g.onclick=()=>{r.set(t,{submitted:false,skipped:true,values:void 0}),o({tool:"requestInput",toolCallId:t,output:{success:true,submitted:false,skipped:true}}),f.querySelectorAll("[data-field-id]").forEach(y=>{y.disabled=true,y.style.opacity="0.7";}),g&&(g.textContent=`${i||"Skip"} \u2713`,g.style.opacity="0.8",g.disabled=true),p&&(p.disabled=true);}),x.submitted||x.skipped){let y=document.createElement("div");y.style.marginTop="10px",y.style.fontSize="12px",y.style.display="flex",y.style.alignItems="center",y.style.gap="8px";let v=document.createElement("span");v.style.display="inline-flex",v.style.alignItems="center",v.style.padding="2px 8px",v.style.borderRadius="999px",v.style.fontWeight="600",v.style.fontSize="11px",x.submitted?(v.style.background="rgba(16,185,129,0.15)",v.style.color="#10b981",v.textContent="Submitted"):(v.style.background="rgba(234,179,8,0.15)",v.style.color="#eab308",v.textContent="Skipped"),y.appendChild(v),f.appendChild(y);try{p&&(p.disabled=!0,p.style.opacity="0.8",x.submitted&&(p.textContent=`${w||"Submit"} \u2713`)),g&&(g.disabled=!0,g.style.opacity="0.8",x.skipped&&(g.textContent=`${i||"Skip"} \u2713`));}catch{}}s.appendChild(f);}function Cn(e,t,n){let r=useRef(new Map);useEffect(()=>{e.forEach(o=>{o.role==="assistant"&&o.parts?.forEach(a=>{if(!a.toolCallId)return;let s=a.toolName;if(!s&&a.type?.startsWith("tool-")&&(s=a.type.replace(/^tool-/,"")),!s)return;let l=t[s];if(l&&typeof l=="object"&&l.executeEachToken&&l.tool){let T=a.input||a.args||{},I=JSON.stringify(T),C=r.current.get(a.toolCallId);if(I!==C&&I!=="{}"){r.current.set(a.toolCallId,I);try{s==="requestInput"?n(T,a.toolCallId):l.tool(T);}catch{}}}});});},[e,t,n]);}function er({agentId:e,theme:t,primaryColor:n,primaryColorDark:r,primaryColorLight:o,backgroundColor:a,borderColor:s,textColor:l,accentColor:T,baseUrl:I="",initialMessages:C=[],onMessagesChange:d,defaultOpen:x=true,floatingButtonPosition:f={bottom:24,right:24},HsafaTools:u={},HsafaUI:w={}}){let{dir:i,theme:h,baseUrl:p}=ke(),g=t||h||"dark",y=I&&I.length>0?I:p||"",b={primaryColor:g==="dark"?r||n||"#ffffff":o||n||"#000000",backgroundColor:a||(g==="dark"?"#0B0B0F":"#FFFFFF"),borderColor:s||(g==="dark"?"#2A2C33":"#E5E7EB"),textColor:l||(g==="dark"?"#EDEEF0":"#111827"),accentColor:T||(g==="dark"?"#17181C":"#F9FAFB"),mutedTextColor:g==="dark"?"#9AA0A6":"#6B7280",inputBackground:g==="dark"?"#17181C":"#F3F4F6",cardBackground:g==="dark"?"#121318":"#FFFFFF",hoverBackground:g==="dark"?"#1c1e25":"#F3F4F6"},m=c=>({"header.new":"New","header.history":"History","header.close":"Close chat","input.placeholder":"Ask your question...","input.attachFiles":"Attach files","input.insertLink":"Insert link","input.send":"Send","input.stop":"Stop","input.uploadingFiles":"Uploading files...","input.previewImage":"Preview image","input.removeFile":"Remove file","messages.empty":"Start by sending a message to the agent.","general.agent":"Agent","editor.cancel":"Cancel","editor.saveAndRegenerate":"Save & Regenerate","editor.clickToEdit":"Click to edit"})[c]||c,{attachments:A,uploading:M,fileInputRef:O,formatBytes:G,handleRemoveAttachment:D,handleFileSelection:q,clearAttachments:U}=Gt(y),[_,R]=useState(null),[$,P]=useState(""),[F,ie]=useState(()=>`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`),ye=useMemo(()=>rn(y,e,F),[y,e,F]),De=useCallback(c=>{console.log("Message finished:",c);},[]),Pe=useCallback(c=>{console.error("Chat error:",c);},[]),Me=useMemo(()=>xn(),[]),ue=useMemo(()=>({...Me,...u}),[Me,u]),he=useRef(new Map),ze=useRef(new Map),rt=useCallback(()=>{try{he.current.forEach(c=>{try{c.remove();}catch{}}),he.current.clear(),ze.current.clear();}catch{}},[]),We=useCallback((c,S)=>{bn(c,S,he.current,ze.current,E=>Tt.current.addToolResult(E));},[b]),Tt=useRef(null),vn=useCallback(c=>{let S=ue[c];return S?typeof S=="object"&&"tool"in S?S.tool:typeof S=="function"?S:null:null},[ue]),X=useChat({transport:ye,onFinish:De,onError:Pe,experimental_throttle:10,sendAutomaticallyWhen:lastAssistantMessageIsCompleteWithToolCalls,async onToolCall({toolCall:c}){let S=vn(c.toolName);if(c.toolName==="requestInput"){try{We(c.input,c.toolCallId);}catch(E){console.error("requestInput render error",E);}return}try{let E=c.toolName==="ui",H=c?.input,W=H&&(H.component||H.componentName),Q=!1,ae=W||c.toolName,Ht=!!(u&&!1);if(E||typeof ae=="string"&&ae.length>0){let pt={status:"ok",rendered:!0,component:W||c.toolName,logs:[]};X.addToolResult({tool:c.toolName,toolCallId:c.toolCallId,output:pt});}}catch(E){X.addToolResult({tool:c.toolName,toolCallId:c.toolCallId,state:"output-error",errorText:E?.message||String(E)});return}if(S)try{let E=await S(c.input);X.addToolResult({tool:c.toolName,toolCallId:c.toolCallId,output:E});}catch(E){X.addToolResult({tool:c.toolName,toolCallId:c.toolCallId,state:"output-error",errorText:E?.message||String(E)});}}}),{messages:z,sendMessage:Ne,status:it,stop:wn,error:St}=X;Tt.current=X,Cn(z,ue,We),useEffect(()=>{try{let c=new Set,S=[];if(z.forEach(E=>{E.role==="assistant"&&(E.parts||[]).forEach(H=>{if((H?.toolName||(typeof H?.type=="string"&&H.type.startsWith("tool-")?String(H.type.replace(/^tool-/,"")):void 0))!=="requestInput")return;let Q=H?.toolCallId||"";if(!Q)return;c.add(Q);let ae=H?.output;if(ae&&(ae.submitted||ae.skipped||ae.values)){let pt={submitted:!!ae.submitted,skipped:!!ae.skipped,values:ae.values||void 0};ze.current.set(Q,pt);}let Ht=H?.input||H?.args||{};S.push({input:Ht,toolCallId:Q});});}),he.current.forEach((E,H)=>{if(!c.has(H)){let W=he.current.get(H);try{W?.remove();}catch{}he.current.delete(H),ze.current.delete(H);}}),S.length>0){let E=requestAnimationFrame(()=>{S.forEach(({input:H,toolCallId:W})=>{try{We(H,W);}catch{}});});return ()=>cancelAnimationFrame(E)}}catch{}},[z,We]),useEffect(()=>{C&&C.length>0&&z.length===0&&console.log("Initial messages:",C);},[C,z.length]);let at=useRef(d);useEffect(()=>{at.current=d;},[d]);let Ee=useRef([]);useEffect(()=>{(z.length!==Ee.current.length||z.length>0&&Ee.current.length>0&&z[z.length-1]?.id!==Ee.current[Ee.current.length-1]?.id)&&at.current&&(Ee.current=z,at.current(z));},[z]);let j=it==="submitted"||it==="streaming",{setStreamingState:st,setChatOpenState:lt}=ke(),[Oe,Mt]=useState(()=>{try{return xt(e).loadShowChatPreference(!!x)}catch{return !!x}}),[Tn,ct]=useState(false),[Sn,Mn]=useState(""),[En,In]=useState(0),An=useRef(null),Rn=useRef(null),[Fn,Et]=useState(new Set),[$n,Ge]=useState(null),[It,Ie]=useState(""),[dt,xe]=useState([]),[Ln,At]=useState(false),Rt=useRef(null),Hn=useRef(null),Bn=Wt(j),N=useMemo(()=>xt(e),[e]),Ae=useRef(false),Ft=useRef(false);useEffect(()=>{if(!Ft.current){try{let c=N.loadCurrentChatId();if(c){Ae.current=!0,ie(c);let S=N.loadChat(c),E=S&&Array.isArray(S.messages)?S.messages:[];try{X?.setMessages?.(E);}catch{}}}catch{}Ft.current=true;}},[N]),useEffect(()=>{if(z.length!==0)if(Ae.current){if(!j){let c=Date.now();N.saveChat({id:F,messages:z,agentId:e});let E=N.loadChatsIndex().find(H=>H.id===F);E&&N.upsertChatMeta({...E,updatedAt:c});}}else {let c=z.find(S=>S.role==="user");if(c){let S="";if(Array.isArray(c.parts)){let W=c.parts.find(Q=>Q&&Q.type==="text");S=W&&typeof W.text=="string"?W.text:"";}let E=(S||"New chat").slice(0,80),H=Date.now();N.upsertChatMeta({id:F,title:E,createdAt:H,updatedAt:H}),N.saveChat({id:F,messages:z,agentId:e}),N.saveCurrentChatId(F),Ae.current=true;}}},[z,e,F,N,j]);let ut=useRef(false);useEffect(()=>{if(j){ut.current=true;return}if(ut.current){ut.current=false;try{let c=Date.now();N.saveChat({id:F,messages:z,agentId:e});let E=N.loadChatsIndex().find(H=>H.id===F);E&&N.upsertChatMeta({...E,updatedAt:c});}catch{}}},[j,z,F,e,N]),useEffect(()=>{try{st(F,j);}catch{}return ()=>{try{st(F,!1);}catch{}}},[F,j,st]),useEffect(()=>{try{lt(F,Oe);}catch{}return ()=>{try{lt(F,!1);}catch{}}},[F,Oe,lt]);let Dn=useCallback(async()=>{let c=$.trim();if(!(!c&&A.length===0)&&!j)try{await Ne({text:c,files:A.map(S=>({type:"file",url:S.url,mediaType:S.mimeType||"application/octet-stream",...S.name?{name:S.name}:{},...S.size?{size:S.size}:{}}))}),P(""),U(),R(null);}catch(S){console.error("Failed to send message:",S),R("Failed to send message. Please try again.");}},[$,A,j,Ne,U]),$t=useCallback(()=>{if(j)return;rt(),P(""),U(),R(null),Ge(null),Ie(""),xe([]);try{X?.setMessages?.([]);}catch{}Ae.current=false;let c=`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`;ie(c);try{N.saveCurrentChatId(c);}catch{}},[j,U,N,X,rt]),Pn=useCallback(()=>{ct(c=>!c);},[]),zn=useCallback(()=>{Mt(false);try{N.saveShowChatPreference(!1);}catch{}},[N]),Wn=useCallback(async c=>{let S=c.target.files;S&&await q(S,R),O.current&&(O.current.value="");},[q,O]);useEffect(()=>{let c=Rt.current;if(!c)return;c.style.height="24px",c.offsetHeight,c.style.height="auto";let S=Math.min(c.scrollHeight,200);c.style.height=`${S}px`;},[$]),qe.useEffect(()=>{let c=Hn.current;if(!c)return;c.style.height="auto",c.offsetHeight;let S=Math.min(Math.max(c.scrollHeight,48),300);c.style.height=`${S}px`;},[It]);let Nn=useCallback(async c=>{At(true);try{let S=await Promise.all(Array.from(c).map(async E=>{let H=new FormData;H.append("file",E);let W=await fetch(`${y}/api/upload`,{method:"POST",body:H});if(!W.ok)throw new Error(`Upload failed: ${W.statusText}`);let Q=await W.json();return {id:Q.url||`${Date.now()}-${Math.random()}`,name:E.name,url:Q.url,mimeType:E.type,size:E.size}}));xe(E=>[...E,...S]);}catch(S){console.error("Failed to upload files:",S),R("Failed to upload files. Please try again.");}finally{At(false);}},[y]),On=useCallback(c=>{xe(S=>S.filter(E=>E.id!==c));},[]),Gn=useCallback((c,S,E)=>{Ge(c),Ie(S),xe(E||[]);},[]),Un=useCallback(()=>{Ge(null),Ie(""),xe([]);},[]),jn=useCallback(async(c,S)=>{if(!j)try{let E=z.findIndex(W=>W.id===c);if(E===-1)return;let H=z.slice(0,E);try{X?.setMessages?.(H);}catch{}await Ne({text:S.trim(),files:dt.map(W=>({type:"file",url:W.url,mediaType:W.mimeType||"application/octet-stream",...W.name?{name:W.name}:{},...W.size?{size:W.size}:{}}))}),Ge(null),Ie(""),xe([]);}catch(E){console.error("Failed to save edit:",E),R("Failed to save message. Please try again.");}},[j,z,Ne,X,dt]),Lt=jsxs("div",{style:{position:"fixed",right:0,top:0,bottom:0,width:"420px",display:"flex",flexDirection:"column",padding:"24px 16px",color:b.textColor,gap:"16px",zIndex:1e3,transform:Oe?"translateX(0)":"translateX(100%)",transition:"transform 0.25s ease-out, width 0.2s ease-out"},children:[jsx(qt,{title:m("general.agent"),alwaysOpen:false,streaming:j,dir:i||"ltr",resolvedColors:b,onNew:$t,onToggleHistory:Pn,onClose:zn,historyBtnRef:An,t:m}),jsx("div",{ref:Bn,className:"chat-scroll-container",style:{flex:"1",overflowY:"auto",overflowX:"hidden",padding:"16px 4px 16px 4px",display:"flex",flexDirection:"column",gap:"16px",scrollBehavior:"smooth","--hsafa-primary":b.primaryColor,"--hsafa-border":b.borderColor,"--hsafa-card":b.cardBackground,"--hsafa-text":b.textColor,"--hsafa-muted":b.mutedTextColor,"--hsafa-bg":b.backgroundColor,"--hsafa-hover":b.hoverBackground,"--hsafa-input-bg":b.inputBackground,"--hsafa-accent":b.accentColor},children:z.length===0?jsx("div",{style:{padding:"32px",textAlign:"center",color:b.mutedTextColor,fontSize:"14px"},children:m("messages.empty")}):jsx(en,{chatMessages:z,isLoading:j,openReasoningIds:Fn,toggleReasoning:c=>Et(S=>{let E=new Set(S);return E.has(c)?E.delete(c):E.add(c),E}),resolvedColors:b,t:m,onUserMessageClick:Gn,editingMessageId:$n,editingText:It,onEditingTextChange:Ie,onCancelEdit:Un,onSaveEdit:jn,editAttachments:dt,onRemoveEditAttachment:On,onAddEditAttachments:Nn,editUploading:Ln,HsafaUI:w})}),jsxs("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px"},children:[_&&jsxs("div",{style:{padding:"8px 12px",marginBottom:"8px",backgroundColor:"#ef4444",color:"#fff",borderRadius:"8px",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsx("span",{children:_}),jsx("button",{onClick:()=>R(null),style:{background:"none",border:"none",color:"#fff",cursor:"pointer",padding:"2px"},children:"\xD7"})]}),St&&jsxs("div",{style:{padding:"8px 12px",marginBottom:"8px",backgroundColor:"#ef4444",color:"#fff",borderRadius:"8px",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxs("span",{children:["An error occurred: ",St.message||"Please try again."]}),jsx("button",{onClick:()=>window.location.reload(),style:{background:"none",border:"1px solid #fff",color:"#fff",cursor:"pointer",padding:"4px 8px",borderRadius:"4px",fontSize:"12px"},children:"Refresh"})]}),jsx(tn,{input:$,setInput:P,textareaRef:Rt,fileInputRef:O,isLoading:j,uploading:M,attachments:A,formatBytes:G,handleRemoveAttachment:D,onFileInputChange:Wn,onSend:Dn,onStop:()=>wn(),status:it,t:m,resolvedColors:b})]}),jsx(on,{historyOpen:Tn,historySearch:Sn,currentChatId:F,refreshKey:En,resolvedColors:b,onClose:()=>ct(false),onSearchChange:Mn,onChatSelect:c=>{if(ct(false),c&&c!==F){Ae.current=true,rt(),ie(c);try{N.saveCurrentChatId(c);}catch{}try{let S=N.loadChat(c),E=S&&Array.isArray(S.messages)?S.messages:[];try{X?.setMessages?.(E);}catch{}}catch{}}},onChatDelete:c=>{try{N.deleteChat(c),In(S=>S+1),c===F&&$t();}catch{}},loadChatsIndex:()=>N.loadChatsIndex(),historyPopupRef:Rn}),jsx("style",{children:`
34
34
  @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
35
35
  @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
36
- `})]});return typeof document<"u"&&document.body?jsxs(Fragment,{children:[jsx(pt,{}),createPortal(Kt,document.body),jsx(Yt,{show:!Je,onClick:()=>{Nt(true);try{G.saveShowChatPreference(!0);}catch{}},resolvedColors:y,floatingButtonPosition:b})]}):Kt}var $n={dark:{primaryColor:"#4D78FF",backgroundColor:"#0B0B0F",borderColor:"#2A2C33",textColor:"#EDEEF0",accentColor:"#17181C",mutedTextColor:"#9AA0A6",inputBackground:"#17181C",cardBackground:"#121318",hoverBackground:"#1c1e25"},light:{primaryColor:"#2563EB",backgroundColor:"#FFFFFF",borderColor:"#E5E7EB",textColor:"#111827",accentColor:"#F9FAFB",mutedTextColor:"#6B7280",inputBackground:"#F9FAFB",cardBackground:"#F3F4F6",hoverBackground:"#F3F4F6"}};function go({children:e,theme:t="dark",primaryColor:n,backgroundColor:o,borderColor:r,textColor:l,mutedTextColor:u,enableBorderAnimation:c=true,borderRadius:v=16,enableContentBorder:S=true,className:a="",enableMargin:T=true,chatWidth:f=420,dir:b="ltr"}){let{isAnyStreaming:g,isAnyChatOpen:k,dir:i,theme:m}=Le(),h=(b??i)||"ltr",C=(t??m)||"dark",E=useRef(`content-container-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),[M,w]=useState(false);useEffect(()=>{let z=setTimeout(()=>w(true),50);return ()=>clearTimeout(z)},[]);let y=$n[C],p={primaryColor:n||y.primaryColor,backgroundColor:o||y.backgroundColor,borderColor:r||y.borderColor,textColor:l||y.textColor,accentColor:y.accentColor,mutedTextColor:u||y.mutedTextColor,inputBackground:y.inputBackground,cardBackground:y.cardBackground,hoverBackground:y.hoverBackground},F=typeof v=="number"?`${v}px`:v,U=typeof f=="number"?`${f}px`:f,q=T&&k?h==="rtl"?{marginLeft:U}:{marginRight:U}:{},Z=T&&k?`calc(100% - ${U})`:"100%";return jsxs(Fragment,{children:[jsx("div",{className:a,style:{width:Z,height:"100%",transition:M?"all 0.2s ease-out":"none",padding:k&&S?"16px":"0",...q},children:jsx("div",{style:{position:"relative",width:"100%",height:"100%",transition:M?"all 0.2s ease-out":"none",borderRadius:k?F:"0",border:k&&g&&c?"none":k?`1px solid ${p.borderColor}`:"none",padding:k&&g&&c?"1.5px":"0",background:k&&g&&c?`linear-gradient(120deg, ${p.primaryColor}dd 0%, ${p.primaryColor}88 25%, ${p.primaryColor}00 50%, ${p.primaryColor}88 75%, ${p.primaryColor}dd 100%)`:"transparent",backgroundSize:k&&g&&c?"300% 300%":"auto",animation:k&&g&&c?`${E.current}-border-flow 3s ease-in-out infinite`:"none",filter:k&&g&&c?`drop-shadow(0 0 10px ${p.primaryColor}40)`:"none"},children:jsx("div",{className:"hsafa-content-container",style:{width:"100%",height:"100%",borderRadius:k&&S?F:"0",backgroundColor:k&&S?p.backgroundColor:"transparent",overflow:"auto",position:"relative",isolation:"isolate",contain:"layout style paint",transform:"translateZ(0)",scrollbarWidth:"thin",scrollbarColor:`${p.mutedTextColor}40 transparent`},children:e})})}),jsx("style",{children:`
37
- @keyframes ${E.current}-border-flow {
36
+ `})]});return typeof document<"u"&&document.body?jsxs(Fragment,{children:[jsx(tt,{}),createPortal(Lt,document.body),jsx(Dt,{show:!Oe,onClick:()=>{Mt(true);try{N.saveShowChatPreference(!0);}catch{}},resolvedColors:b,floatingButtonPosition:f})]}):Lt}var kn={dark:{primaryColor:"#4D78FF",backgroundColor:"#0B0B0F",borderColor:"#2A2C33",textColor:"#EDEEF0",accentColor:"#17181C",mutedTextColor:"#9AA0A6",inputBackground:"#17181C",cardBackground:"#121318",hoverBackground:"#1c1e25"},light:{primaryColor:"#2563EB",backgroundColor:"#FFFFFF",borderColor:"#E5E7EB",textColor:"#111827",accentColor:"#F9FAFB",mutedTextColor:"#6B7280",inputBackground:"#F9FAFB",cardBackground:"#F3F4F6",hoverBackground:"#F3F4F6"}};function ir({children:e,theme:t="dark",primaryColor:n,backgroundColor:r,borderColor:o,textColor:a,mutedTextColor:s,enableBorderAnimation:l=true,borderRadius:T=16,enableContentBorder:I=true,className:C="",enableMargin:d=true,chatWidth:x=420,dir:f="ltr"}){let{isAnyStreaming:u,isAnyChatOpen:w,dir:i,theme:h}=ke(),p=(f??i)||"ltr",g=(t??h)||"dark",y=useRef(`content-container-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),[v,k]=useState(false);useEffect(()=>{let D=setTimeout(()=>k(true),50);return ()=>clearTimeout(D)},[]);let b=kn[g],m={primaryColor:n||b.primaryColor,backgroundColor:r||b.backgroundColor,borderColor:o||b.borderColor,textColor:a||b.textColor,accentColor:b.accentColor,mutedTextColor:s||b.mutedTextColor,inputBackground:b.inputBackground,cardBackground:b.cardBackground,hoverBackground:b.hoverBackground},A=typeof T=="number"?`${T}px`:T,M=typeof x=="number"?`${x}px`:x,O=d&&w?p==="rtl"?{marginLeft:M}:{marginRight:M}:{},G=d&&w?`calc(100% - ${M})`:"100%";return jsxs(Fragment,{children:[jsx("div",{className:C,style:{width:G,height:"100%",transition:v?"all 0.2s ease-out":"none",padding:w&&I?"16px":"0",...O},children:jsx("div",{style:{position:"relative",width:"100%",height:"100%",transition:v?"all 0.2s ease-out":"none",borderRadius:w?A:"0",border:w&&u&&l?"none":w?`1px solid ${m.borderColor}`:"none",padding:w&&u&&l?"1.5px":"0",background:w&&u&&l?`linear-gradient(120deg, ${m.primaryColor}dd 0%, ${m.primaryColor}88 25%, ${m.primaryColor}00 50%, ${m.primaryColor}88 75%, ${m.primaryColor}dd 100%)`:"transparent",backgroundSize:w&&u&&l?"300% 300%":"auto",animation:w&&u&&l?`${y.current}-border-flow 3s ease-in-out infinite`:"none",filter:w&&u&&l?`drop-shadow(0 0 10px ${m.primaryColor}40)`:"none"},children:jsx("div",{className:"hsafa-content-container",style:{width:"100%",height:"100%",borderRadius:w&&I?A:"0",backgroundColor:w&&I?m.backgroundColor:"transparent",overflow:"auto",position:"relative",isolation:"isolate",contain:"layout style paint",transform:"translateZ(0)",scrollbarWidth:"thin",scrollbarColor:`${m.mutedTextColor}40 transparent`},children:e})})}),jsx("style",{children:`
37
+ @keyframes ${y.current}-border-flow {
38
38
  0% { background-position: 0% 50%; }
39
39
  50% { background-position: 100% 50%; }
40
40
  100% { background-position: 0% 50%; }
41
41
  }
42
- `})," "]})}var zt=class{constructor(){this.components=new Map;}register(t,n){this.components.set(t,n);}unregister(t){this.components.delete(t);}get(t){return this.components.get(t)}has(t){return this.components.has(t)}clear(){this.components.clear();}getRegisteredNames(){return Array.from(this.components.keys())}},ho=new zt;export{wo as Button,go as ContentContainer,pt as CursorController,Ue as FillActiveInput,Yt as FloatingChatButton,lo as HsafaChat,lr as HsafaProvider,ho as componentRegistry,Ee as controlCursor,je as getDomComponents,Ee as guideCursor,Qt as useAutoScroll,nn as useFileUpload,Le as useHsafa};//# sourceMappingURL=index.js.map
42
+ `})," "]})}var wt=class{constructor(){this.components=new Map;}register(t,n){this.components.set(t,n);}unregister(t){this.components.delete(t);}get(t){return this.components.get(t)}has(t){return this.components.has(t)}clear(){this.components.clear();}getRegisteredNames(){return Array.from(this.components.keys())}},lr=new wt;export{gr as Button,ir as ContentContainer,tt as CursorController,He as FillActiveInput,Dt as FloatingChatButton,er as HsafaChat,Yn as HsafaProvider,lr as componentRegistry,fe as controlCursor,Le as getDomComponents,fe as guideCursor,Wt as useAutoScroll,Gt as useFileUpload,ke as useHsafa};//# sourceMappingURL=index.js.map
43
43
  //# sourceMappingURL=index.js.map