@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.cjs +14 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +14 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
'use strict';var jsxRuntime=require('react/jsx-runtime'),ot=require('react'),reactDom=require('react-dom'),react=require('@ai-sdk/react'),ai=require('ai'),lucideReact=require('lucide-react'),client=require('react-dom/client');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var ot__default=/*#__PURE__*/_interopDefault(ot);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 jsxRuntime.jsxs("button",{className:c,disabled:o||n,...u,children:[n&&jsxRuntime.jsx("span",{className:Me.spinner}),jsxRuntime.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 jsxRuntime.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:jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.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=ot.useRef(null),n=ot.useRef(e);return ot.useEffect(()=>{n.current=e;},[e]),ot.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]=ot.useState([]),[o,r]=ot.useState(false),l=ot.useRef(null),u=ot.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=ot.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=ot.useCallback(f=>{n(b=>b.filter(g=>g.id!==f));},[]),S=ot.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=ot.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=ot.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=ot.createContext(void 0);function lr({baseUrl:e,dir:t="ltr",theme:n="dark",children:o}){let[r,l]=ot.useState(new Map),[u,c]=ot.useState(new Map),[v,S]=ot.useState(new Map),[a,T]=ot.useState(new Map),f=ot.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=ot.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=ot.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=ot.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=ot.useCallback((M,w)=>{S(y=>{let p=new Map(y);return w?p.set(M,true):p.delete(M),p});},[]),m=ot.useCallback((M,w)=>{T(y=>{let p=new Map(y);return w?p.set(M,true):p.delete(M),p});},[]),h=ot.useMemo(()=>Array.from(v.values()).some(M=>M),[v]),C=ot.useMemo(()=>Array.from(a.values()).some(M=>M),[a]),E=ot.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 jsxRuntime.jsx(rn.Provider,{value:E,children:o})}function Le(){let e=ot.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__default.default.createElement(e,t)}function Ft({icon:e,onClick:t,ariaLabel:n,resolvedColors:o,disabled:r=false,title:l}){return jsxRuntime.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 jsxRuntime.jsxs("div",{style:{marginBottom:"24px",display:"flex",alignItems:"center",justifyContent:"space-between",direction:o==="rtl"?"rtl":"ltr"},children:[jsxRuntime.jsx("div",{style:{minWidth:"0"},children:jsxRuntime.jsx("h1",{title:e,style:{color:r.textColor,fontSize:"18px",fontWeight:"600",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",margin:"0"},children:e})}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",position:"relative",color:r.mutedTextColor},children:[jsxRuntime.jsx(Ft,{icon:jsxRuntime.jsx(le,{IconComponent:lucideReact.Plus,size:"20",strokeWidth:"2"}),onClick:()=>{n||l();},ariaLabel:S("header.new"),resolvedColors:r,disabled:n}),jsxRuntime.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:jsxRuntime.jsx(le,{IconComponent:lucideReact.History,size:"20",strokeWidth:"2"})}),!t&&jsxRuntime.jsx(Ft,{icon:jsxRuntime.jsx(le,{IconComponent:lucideReact.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=ot.useRef(null),[o,r]=ot.useState(null),[l,u]=ot.useState(true);ot.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?jsxRuntime.jsxs("div",{style:{borderRadius:"12px",border:`1px solid ${c}`,backgroundColor:S,padding:"16px",margin:"8px 0"},children:[jsxRuntime.jsx("div",{style:{fontSize:"14px",color:a,marginBottom:"8px",fontWeight:"500"},children:"Failed to render diagram"}),jsxRuntime.jsx("div",{style:{fontSize:"12px",color:a,opacity:.8},children:o})]}):jsxRuntime.jsxs("div",{style:{borderRadius:"12px",border:`1px solid ${c}`,backgroundColor:v,padding:"16px",margin:"8px 0",overflow:"hidden"},children:[l&&jsxRuntime.jsx("div",{style:{fontSize:"14px",color:T,textAlign:"center",padding:"32px"},children:"Rendering diagram..."}),jsxRuntime.jsx("div",{ref:n,style:{display:l?"none":"block",textAlign:"center",minHeight:l?"0":"50px"}})]})}function ce(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}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
|
+
'use strict';var jsxRuntime=require('react/jsx-runtime'),qe=require('react'),reactDom=require('react-dom'),react=require('@ai-sdk/react'),ai=require('ai'),lucideReact=require('lucide-react'),client=require('react-dom/client');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var qe__default=/*#__PURE__*/_interopDefault(qe);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 jsxRuntime.jsxs("button",{className:l,disabled:r||n,...s,children:[n&&jsxRuntime.jsx("span",{className:ge.spinner}),jsxRuntime.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 jsxRuntime.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:jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.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=qe.useRef(null),n=qe.useRef(e);return qe.useEffect(()=>{n.current=e;},[e]),qe.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]=qe.useState([]),[r,o]=qe.useState(false),a=qe.useRef(null),s=qe.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=qe.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=qe.useCallback(x=>{n(f=>f.filter(u=>u.id!==x));},[]),I=qe.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=qe.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=qe.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=qe.createContext(void 0);function Yn({baseUrl:e,dir:t="ltr",theme:n="dark",children:r}){let[o,a]=qe.useState(new Map),[s,l]=qe.useState(new Map),[T,I]=qe.useState(new Map),[C,d]=qe.useState(new Map),x=qe.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=qe.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=qe.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=qe.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=qe.useCallback((v,k)=>{I(b=>{let m=new Map(b);return k?m.set(v,true):m.delete(v),m});},[]),h=qe.useCallback((v,k)=>{d(b=>{let m=new Map(b);return k?m.set(v,true):m.delete(v),m});},[]),p=qe.useMemo(()=>Array.from(T.values()).some(v=>v),[T]),g=qe.useMemo(()=>Array.from(C.values()).some(v=>v),[C]),y=qe.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 jsxRuntime.jsx(Ut.Provider,{value:y,children:r})}function ke(){let e=qe.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__default.default.createElement(e,t)}function yt({icon:e,onClick:t,ariaLabel:n,resolvedColors:r,disabled:o=false,title:a}){return jsxRuntime.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 jsxRuntime.jsxs("div",{style:{marginBottom:"24px",display:"flex",alignItems:"center",justifyContent:"space-between",direction:r==="rtl"?"rtl":"ltr"},children:[jsxRuntime.jsx("div",{style:{minWidth:"0"},children:jsxRuntime.jsx("h1",{title:e,style:{color:o.textColor,fontSize:"18px",fontWeight:"600",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",margin:"0"},children:e})}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",position:"relative",color:o.mutedTextColor},children:[jsxRuntime.jsx(yt,{icon:jsxRuntime.jsx(ee,{IconComponent:lucideReact.Plus,size:"20",strokeWidth:"2"}),onClick:()=>{n||a();},ariaLabel:I("header.new"),resolvedColors:o,disabled:n}),jsxRuntime.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:jsxRuntime.jsx(ee,{IconComponent:lucideReact.History,size:"20",strokeWidth:"2"})}),!t&&jsxRuntime.jsx(yt,{icon:jsxRuntime.jsx(ee,{IconComponent:lucideReact.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=qe.useRef(null),[r,o]=qe.useState(null),[a,s]=qe.useState(true);qe.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?jsxRuntime.jsxs("div",{style:{borderRadius:"12px",border:`1px solid ${l}`,backgroundColor:I,padding:"16px",margin:"8px 0"},children:[jsxRuntime.jsx("div",{style:{fontSize:"14px",color:C,marginBottom:"8px",fontWeight:"500"},children:"Failed to render diagram"}),jsxRuntime.jsx("div",{style:{fontSize:"12px",color:C,opacity:.8},children:r})]}):jsxRuntime.jsxs("div",{style:{borderRadius:"12px",border:`1px solid ${l}`,backgroundColor:T,padding:"16px",margin:"8px 0",overflow:"hidden"},children:[a&&jsxRuntime.jsx("div",{style:{fontSize:"14px",color:d,textAlign:"center",padding:"32px"},children:"Rendering diagram..."}),jsxRuntime.jsx("div",{ref:n,style:{display:a?"none":"block",textAlign:"center",minHeight:a?"0":"50px"}})]})}function te(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}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
|
-
`),
|
|
4
|
-
<table style="width: 100%; min-width: max-content; border-collapse: separate; border-spacing: 0; margin: 0;">`;
|
|
5
|
-
`);
|
|
6
|
-
`)),
|
|
7
|
-
`);
|
|
8
|
-
`)),
|
|
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}=qe.useMemo(()=>ao(e,t),[e,t]);if(!r)return jsxRuntime.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(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'");a.push(qe__default.default.createElement(Vt,{key:`mermaid-${l}`,chart:I,theme:t}));}}else s.trim()&&a.push(qe__default.default.createElement("div",{key:`html-${l}`,style:{fontSize:"14px",lineHeight:"1.6",wordBreak:"break-word",maxWidth:"100%",overflow:"hidden"},dangerouslySetInnerHTML:{__html:s}}));}),qe__default.default.createElement(qe__default.default.Fragment,{},...a)}var Re=class extends qe.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 jsxRuntime.jsxs("div",{style:{padding:"16px",backgroundColor:"#fee2e2",border:"2px solid #ef4444",borderRadius:"12px",color:"#991b1b"},children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},children:[jsxRuntime.jsx("span",{style:{fontSize:"20px"},children:"\u26A0\uFE0F"}),jsxRuntime.jsxs("strong",{style:{fontSize:"16px"},children:["Component Error: ",n]})]}),jsxRuntime.jsx("div",{style:{fontSize:"14px",marginBottom:"8px",fontFamily:"monospace"},children:this.state.error.message}),this.state.errorInfo&&jsxRuntime.jsxs("details",{style:{fontSize:"12px",marginTop:"8px"},children:[jsxRuntime.jsx("summary",{style:{cursor:"pointer",fontWeight:"bold"},children:"Stack Trace"}),jsxRuntime.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?jsxRuntime.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:jsxRuntime.jsx("div",{onClick:y,style:{cursor:g?"pointer":"default",padding:"0"},children:jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[jsxRuntime.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:[jsxRuntime.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px"},children:[!p&&jsxRuntime.jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),jsxRuntime.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&&jsxRuntime.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:jsxRuntime.jsx("polyline",{points:"9 18 15 12 9 6"})})]}),jsxRuntime.jsx("div",{style:{display:"grid",gridTemplateRows:u||!p?"1fr":"0fr",transition:"grid-template-rows 0.2s ease-out",overflow:"hidden"},children:jsxRuntime.jsx("div",{style:{minHeight:0},children:d.texts&&d.texts.length>0?jsxRuntime.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)=>jsxRuntime.jsx("div",{style:{marginBottom:"6px"},children:jsxRuntime.jsx(_e,{content:v,theme:"dark"})},`rg-line-${x}-${k}`))}):jsxRuntime.jsxs("div",{style:{fontSize:"12px",color:o.mutedTextColor,opacity:.7,display:"flex",alignItems:"center",gap:"8px"},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),jsxRuntime.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 jsxRuntime.jsx("div",{style:{display:"block",position:"relative"},children:jsxRuntime.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?jsxRuntime.jsx("div",{style:{display:"block",position:"relative",padding:"12px",backgroundColor:o.inputBackground,borderRadius:"12px",border:`1px solid ${o.borderColor}`},children:jsxRuntime.jsx(Re,{componentName:p,resolvedColors:o,children:jsxRuntime.jsx(g,{...d.input||{}})})},f):jsxRuntime.jsx("div",{style:{display:"flex",gap:"12px",position:"relative"},children:jsxRuntime.jsx("div",{style:{flex:1,minWidth:0},children:jsxRuntime.jsxs("div",{style:{fontSize:"13px",color:o.mutedTextColor,display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"},children:[jsxRuntime.jsxs("span",{style:{fontWeight:600,color:"#ef4444",display:"flex",alignItems:"center",gap:"6px"},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:"#ef4444"}}),"Error"]}),jsxRuntime.jsxs("span",{style:{fontWeight:500,color:o.textColor},children:['UI component "',p,'" not found']})]})})},f)}default:{let p=a?.[d.toolName||""];return p?jsxRuntime.jsx("div",{style:{display:"block",position:"relative",padding:"12px",backgroundColor:o.inputBackground,borderRadius:"12px",border:`1px solid ${o.borderColor}`},children:jsxRuntime.jsx(Re,{componentName:d.toolName||"Unknown",resolvedColors:o,children:jsxRuntime.jsx(p,{...d.input||{}})})},f):jsxRuntime.jsx("div",{style:{display:"flex",gap:"12px",position:"relative"},children:jsxRuntime.jsx("div",{style:{flex:1,minWidth:0},children:jsxRuntime.jsxs("div",{style:{fontSize:"13px",color:o.mutedTextColor,display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"},children:[jsxRuntime.jsxs("span",{style:{fontWeight:600,color:w,display:"flex",alignItems:"center",gap:"6px"},children:[jsxRuntime.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]}),jsxRuntime.jsx("span",{style:{fontWeight:500,color:o.textColor},children:d.toolName||"tool"})]})})},f)}}}),jsxRuntime.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
|
|
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=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.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?jsxRuntime.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,jsxRuntime.jsx(ee,{IconComponent:lucideReact.File,size:n==="input"?14:10,strokeWidth:"2",style:{display:a?"none":"block",color:t.mutedTextColor}})]}),jsxRuntime.jsxs("div",{style:{minWidth:"0",flex:"1",display:"flex",flexDirection:"column"},children:[jsxRuntime.jsx("span",{title:e.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:"500"},children:e.name}),jsxRuntime.jsx("span",{style:{fontSize:n==="input"?"10px":"9px",color:t.mutedTextColor,marginTop:n==="input"?"2px":"1px"},children:Yt(e.size)})]}),n==="input"&&a&&jsxRuntime.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:jsxRuntime.jsx(ee,{IconComponent:lucideReact.Eye,size:"12",strokeWidth:"2"})}),s&&r&&jsxRuntime.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:jsxRuntime.jsx(ee,{IconComponent:lucideReact.X,size:"12",strokeWidth:"2"})}),l&&jsxRuntime.jsx(ee,{IconComponent:lucideReact.Download,size:"10",strokeWidth:"2",style:{color:t.mutedTextColor,flexShrink:0}})]});return l?jsxRuntime.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}):jsxRuntime.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 jsxRuntime.jsx("div",{style:{marginTop:"12px",display:"flex",flexWrap:"wrap",gap:"8px"},children:e.map(o=>jsxRuntime.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__default.default.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 jsxRuntime.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:[jsxRuntime.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&&jsxRuntime.jsx("div",{style:{padding:"8px"},children:jsxRuntime.jsx(Xe,{attachments:T,resolvedColors:l,onRemove:I})}),d&&jsxRuntime.jsxs("div",{style:{padding:"8px 16px",display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:l.mutedTextColor},children:[jsxRuntime.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:jsxRuntime.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsxRuntime.jsx("span",{children:x("input.uploadingFiles")})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"8px",padding:"8px 8px 8px 0"},children:[C&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("input",{ref:f,type:"file",multiple:true,onChange:w,style:{display:"none"}}),jsxRuntime.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:jsxRuntime.jsx(lucideReact.Plus,{size:16,strokeWidth:2})})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsxRuntime.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")}),jsxRuntime.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 jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("style",{children:`
|
|
14
14
|
@keyframes jumpingDots {
|
|
15
15
|
0%, 80%, 100% {
|
|
16
16
|
transform: translateY(0);
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
transform: translateY(-5px);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
`}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[e.map((
|
|
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 jsxRuntime.jsx("div",{style:{padding:"0 4px"},children:m.role==="user"?c===m.id?jsxRuntime.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}):jsxRuntime.jsx("div",{children:jsxRuntime.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&&jsxRuntime.jsx(at,{attachments:M,resolvedColors:r})]})}):jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[jsxRuntime.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?jsxRuntime.jsx(un,{items:w.data.items,resolvedColors:r,UIComponents:i}):null})()]})},m.id)}),t&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",padding:"0 4px",height:"20px"},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:r.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0s"}}),jsxRuntime.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"}}),jsxRuntime.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 jsxRuntime.jsx("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px",paddingTop:"4px"},children:jsxRuntime.jsx("div",{style:{position:"relative",flex:1},children:jsxRuntime.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&&jsxRuntime.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 jsxRuntime.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:[jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",borderRadius:"4px",backgroundColor:h?"transparent":g.cardBackground},children:h?jsxRuntime.jsx("img",{src:m.url,alt:m.name,style:{width:"20px",height:"20px",borderRadius:"4px",objectFit:"cover"}}):jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("rect",{x:"4",y:"4",width:"16",height:"20",rx:"2",ry:"2"})})}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",minWidth:0,flex:1},children:[jsxRuntime.jsx("span",{title:m.name,style:{maxWidth:"140px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:m.name}),jsxRuntime.jsx("span",{style:{color:g.mutedTextColor,fontSize:"10px",marginTop:"2px"},children:c(m.size)})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginLeft:"8px"},children:[h&&jsxRuntime.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:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),jsxRuntime.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:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]},m.id)})}),l&&jsxRuntime.jsxs("div",{style:{padding:"0px 16px 12px 16px",display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:g.mutedTextColor},children:[jsxRuntime.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:jsxRuntime.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsxRuntime.jsx("span",{children:b("input.uploadingFiles")})]}),jsxRuntime.jsx("div",{style:{padding:"0 16px"},children:jsxRuntime.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"}})}),jsxRuntime.jsx("input",{ref:o,type:"file",multiple:true,onChange:S,style:{display:"none"},accept:"*/*"}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"8px",left:"8px",display:"flex",alignItems:"center",gap:"4px",color:g.mutedTextColor},children:jsxRuntime.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:jsxRuntime.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.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"})})})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"8px",right:"8px"},children:r?jsxRuntime.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:jsxRuntime.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:jsxRuntime.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"})})}):jsxRuntime.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:jsxRuntime.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:[jsxRuntime.jsx("path",{d:"m5 12 7-7 7 7"}),jsxRuntime.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=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{style:{position:"fixed",inset:"0",zIndex:1100,backgroundColor:"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)"},onClick:l}),jsxRuntime.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:[jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",gap:"12px",borderBottom:`1px solid ${r.borderColor}`,padding:"12px 16px"},children:jsxRuntime.jsx("div",{style:{flex:"1"},children:jsxRuntime.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})})}),jsxRuntime.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?jsxRuntime.jsx("div",{style:{padding:"24px",color:r.mutedTextColor,textAlign:"center"},children:"No chats found."}):jsxRuntime.jsx("div",{children:b.map((g,k)=>jsxRuntime.jsx("div",{style:{borderTop:k>0?`1px solid ${r.borderColor}`:"none"},children:jsxRuntime.jsxs("div",{style:{display:"flex",width:"100%",alignItems:"center",justifyContent:"space-between",gap:"12px",padding:"12px",backgroundColor:g.id===n?r.cardBackground:"transparent"},children:[jsxRuntime.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:jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"12px"},children:[jsxRuntime.jsx("div",{style:{minWidth:"0",flex:"1"},children:jsxRuntime.jsx("div",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"14px",color:r.textColor},children:g.title||"Untitled chat"})}),jsxRuntime.jsx("div",{style:{flexShrink:0,fontSize:"12px",color:r.mutedTextColor},children:xn(g.updatedAt)})]})}),jsxRuntime.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:jsxRuntime.jsx(le,{IconComponent:lucideReact.Trash2,size:"16",strokeWidth:"2"})})]})},g.id))})})()})]})]});return typeof document<"u"&&document.body?reactDom.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 jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[e&&jsxRuntime.jsx("div",{className:"arrow",dangerouslySetInnerHTML:{__html:e}}),t&&jsxRuntime.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
|
+
`}),jsxRuntime.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 jsxRuntime.jsx("div",{style:{padding:"0 4px"},children:h.role==="user"?l===h.id?jsxRuntime.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}):jsxRuntime.jsx("div",{children:jsxRuntime.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&&jsxRuntime.jsx(Xe,{attachments:v,resolvedColors:o})]})}):jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[jsxRuntime.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?jsxRuntime.jsx(_e,{content:k.text,theme:"dark"}):null})()]})},h.id)}),t&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",padding:"0 4px",height:"20px"},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0s"}}),jsxRuntime.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"}}),jsxRuntime.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 jsxRuntime.jsx("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px",paddingTop:"4px"},children:jsxRuntime.jsx("div",{style:{position:"relative",flex:1},children:jsxRuntime.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&&jsxRuntime.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 jsxRuntime.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:[jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",borderRadius:"4px",backgroundColor:p?"transparent":u.cardBackground},children:p?jsxRuntime.jsx("img",{src:h.url,alt:h.name,style:{width:"20px",height:"20px",borderRadius:"4px",objectFit:"cover"}}):jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("rect",{x:"4",y:"4",width:"16",height:"20",rx:"2",ry:"2"})})}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",minWidth:0,flex:1},children:[jsxRuntime.jsx("span",{title:h.name,style:{maxWidth:"140px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:h.name}),jsxRuntime.jsx("span",{style:{color:u.mutedTextColor,fontSize:"10px",marginTop:"2px"},children:l(h.size)})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginLeft:"8px"},children:[p&&jsxRuntime.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:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),jsxRuntime.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:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]},h.id)})}),a&&jsxRuntime.jsxs("div",{style:{padding:"0px 16px 12px 16px",display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:u.mutedTextColor},children:[jsxRuntime.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:jsxRuntime.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsxRuntime.jsx("span",{children:f("input.uploadingFiles")})]}),jsxRuntime.jsx("div",{style:{padding:"0 16px"},children:jsxRuntime.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"}})}),jsxRuntime.jsx("input",{ref:r,type:"file",multiple:true,onChange:I,style:{display:"none"},accept:"*/*"}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"8px",left:"8px",display:"flex",alignItems:"center",gap:"4px",color:u.mutedTextColor},children:jsxRuntime.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:jsxRuntime.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.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"})})})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"8px",right:"8px"},children:o?jsxRuntime.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:jsxRuntime.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:jsxRuntime.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"})})}):jsxRuntime.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:jsxRuntime.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:[jsxRuntime.jsx("path",{d:"m5 12 7-7 7 7"}),jsxRuntime.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=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{style:{position:"fixed",inset:"0",zIndex:1100,backgroundColor:"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)"},onClick:a}),jsxRuntime.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:[jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",gap:"12px",borderBottom:`1px solid ${o.borderColor}`,padding:"12px 16px"},children:jsxRuntime.jsx("div",{style:{flex:"1"},children:jsxRuntime.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})})}),jsxRuntime.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?jsxRuntime.jsx("div",{style:{padding:"24px",color:o.mutedTextColor,textAlign:"center"},children:"No chats found."}):jsxRuntime.jsx("div",{children:f.map((u,w)=>jsxRuntime.jsx("div",{style:{borderTop:w>0?`1px solid ${o.borderColor}`:"none"},children:jsxRuntime.jsxs("div",{style:{display:"flex",width:"100%",alignItems:"center",justifyContent:"space-between",gap:"12px",padding:"12px",backgroundColor:u.id===n?o.cardBackground:"transparent"},children:[jsxRuntime.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:jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"12px"},children:[jsxRuntime.jsx("div",{style:{minWidth:"0",flex:"1"},children:jsxRuntime.jsx("div",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"14px",color:o.textColor},children:u.title||"Untitled chat"})}),jsxRuntime.jsx("div",{style:{flexShrink:0,fontSize:"12px",color:o.mutedTextColor},children:nn(u.updatedAt)})]})}),jsxRuntime.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:jsxRuntime.jsx(ee,{IconComponent:lucideReact.Trash2,size:"16",strokeWidth:"2"})})]})},u.id))})})()})]})]});return typeof document<"u"&&document.body?reactDom.createPortal(d,document.body):d}function rn(e,t,n){return new ai.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 jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[e&&jsxRuntime.jsx("div",{className:"arrow",dangerouslySetInnerHTML:{__html:e}}),t&&jsxRuntime.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 @@
|
|
|
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=client.createRoot(t),qe.render(jsxRuntime.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=client.createRoot(t),qe.render(jsxRuntime.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 ot.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,$]=ot.useState(null),[H,N]=ot.useState(""),[L,ge]=ot.useState(()=>`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`),Ae=ot.useMemo(()=>new ai.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=ot.useCallback(s=>{console.log("Message finished:",s);},[]),Ke=ot.useCallback(s=>{console.error("Chat error:",s);},[]),ze=ot.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=ot.useMemo(()=>({...ze,...k}),[ze,k]),ve=ot.useRef(new Map),Ie=ot.useRef(new Map),ft=ot.useCallback(()=>{try{ve.current.forEach(s=>{try{s.remove();}catch{}}),ve.current.clear(),Ie.current.clear();}catch{}},[]),Xe=ot.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=ot.useRef(null),Ln=ot.useCallback(s=>{let d=ke[s];return d?typeof d=="object"&&"tool"in d?d.tool:typeof d=="function"?d:null:null},[ke]),fe=react.useChat({transport:Ae,onFinish:Ve,onError:Ke,experimental_throttle:10,sendAutomaticallyWhen:ai.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=ot.useRef(new Map);ot.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]),ot.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]),ot.useEffect(()=>{a&&a.length>0&&W.length===0&&console.log("Initial messages:",a);},[a,W.length]);let xt=ot.useRef(T);ot.useEffect(()=>{xt.current=T;},[T]);let We=ot.useRef([]);ot.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]=ot.useState(()=>{try{return Lt(e).loadShowChatPreference(!!f)}catch{return !!f}}),[Bn,kt]=ot.useState(false),[Dn,Pn]=ot.useState(""),[zn,Wn]=ot.useState(0),On=ot.useRef(null),Nn=ot.useRef(null),[Gn,Gt]=ot.useState(new Set),[_n,Ze]=ot.useState(null),[_t,Oe]=ot.useState(""),[vt,Re]=ot.useState([]),[jn,jt]=ot.useState(false),Ut=ot.useRef(null),Un=ot.useRef(null),qn=Qt(J),G=ot.useMemo(()=>Lt(e),[e]),Ne=ot.useRef(false),qt=ot.useRef(false);ot.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]),ot.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=ot.useRef(false);ot.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]),ot.useEffect(()=>{try{bt(L,J);}catch{}return ()=>{try{bt(L,!1);}catch{}}},[L,J,bt]),ot.useEffect(()=>{try{Ct(L,Je);}catch{}return ()=>{try{Ct(L,!1);}catch{}}},[L,Je,Ct]);let Vn=ot.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=ot.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=ot.useCallback(()=>{kt(s=>!s);},[]),Xn=ot.useCallback(()=>{Nt(false);try{G.saveShowChatPreference(!1);}catch{}},[G]),Yn=ot.useCallback(async s=>{let d=s.target.files;d&&await Q(d,$),q.current&&(q.current.value="");},[Q,q]);ot.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__default.default.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=ot.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=ot.useCallback(s=>{Re(d=>d.filter(x=>x.id!==s));},[]),Qn=ot.useCallback((s,d,x)=>{Ze(s),Oe(d),Re(x||[]);},[]),er=ot.useCallback(()=>{Ze(null),Oe(""),Re([]);},[]),tr=ot.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=jsxRuntime.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:[jsxRuntime.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}),jsxRuntime.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?jsxRuntime.jsx("div",{style:{padding:"32px",textAlign:"center",color:y.mutedTextColor,fontSize:"14px"},children:p("messages.empty")}):jsxRuntime.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})}),jsxRuntime.jsxs("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px"},children:[ee&&jsxRuntime.jsxs("div",{style:{padding:"8px 12px",marginBottom:"8px",backgroundColor:"#ef4444",color:"#fff",borderRadius:"8px",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{children:ee}),jsxRuntime.jsx("button",{onClick:()=>$(null),style:{background:"none",border:"none",color:"#fff",cursor:"pointer",padding:"2px"},children:"\xD7"})]}),Wt&&jsxRuntime.jsxs("div",{style:{padding:"8px 12px",marginBottom:"8px",backgroundColor:"#ef4444",color:"#fff",borderRadius:"8px",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxRuntime.jsxs("span",{children:["An error occurred: ",Wt.message||"Please try again."]}),jsxRuntime.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"})]}),jsxRuntime.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})]}),jsxRuntime.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}),jsxRuntime.jsx("style",{children:`
|
|
33
|
+
`,document.head.appendChild(o);}cn=true;}return t?(t.classList.add("as-arrow"),Be||(Be=client.createRoot(t),Be.render(jsxRuntime.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=client.createRoot(t),Be.render(jsxRuntime.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 qe.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=qe.useRef(new Map);qe.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]=qe.useState(null),[$,P]=qe.useState(""),[F,ie]=qe.useState(()=>`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`),ye=qe.useMemo(()=>rn(y,e,F),[y,e,F]),De=qe.useCallback(c=>{console.log("Message finished:",c);},[]),Pe=qe.useCallback(c=>{console.error("Chat error:",c);},[]),Me=qe.useMemo(()=>xn(),[]),ue=qe.useMemo(()=>({...Me,...u}),[Me,u]),he=qe.useRef(new Map),ze=qe.useRef(new Map),rt=qe.useCallback(()=>{try{he.current.forEach(c=>{try{c.remove();}catch{}}),he.current.clear(),ze.current.clear();}catch{}},[]),We=qe.useCallback((c,S)=>{bn(c,S,he.current,ze.current,E=>Tt.current.addToolResult(E));},[b]),Tt=qe.useRef(null),vn=qe.useCallback(c=>{let S=ue[c];return S?typeof S=="object"&&"tool"in S?S.tool:typeof S=="function"?S:null:null},[ue]),X=react.useChat({transport:ye,onFinish:De,onError:Pe,experimental_throttle:10,sendAutomaticallyWhen:ai.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),qe.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]),qe.useEffect(()=>{C&&C.length>0&&z.length===0&&console.log("Initial messages:",C);},[C,z.length]);let at=qe.useRef(d);qe.useEffect(()=>{at.current=d;},[d]);let Ee=qe.useRef([]);qe.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]=qe.useState(()=>{try{return xt(e).loadShowChatPreference(!!x)}catch{return !!x}}),[Tn,ct]=qe.useState(false),[Sn,Mn]=qe.useState(""),[En,In]=qe.useState(0),An=qe.useRef(null),Rn=qe.useRef(null),[Fn,Et]=qe.useState(new Set),[$n,Ge]=qe.useState(null),[It,Ie]=qe.useState(""),[dt,xe]=qe.useState([]),[Ln,At]=qe.useState(false),Rt=qe.useRef(null),Hn=qe.useRef(null),Bn=Wt(j),N=qe.useMemo(()=>xt(e),[e]),Ae=qe.useRef(false),Ft=qe.useRef(false);qe.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]),qe.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=qe.useRef(false);qe.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]),qe.useEffect(()=>{try{st(F,j);}catch{}return ()=>{try{st(F,!1);}catch{}}},[F,j,st]),qe.useEffect(()=>{try{lt(F,Oe);}catch{}return ()=>{try{lt(F,!1);}catch{}}},[F,Oe,lt]);let Dn=qe.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=qe.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=qe.useCallback(()=>{ct(c=>!c);},[]),zn=qe.useCallback(()=>{Mt(false);try{N.saveShowChatPreference(!1);}catch{}},[N]),Wn=qe.useCallback(async c=>{let S=c.target.files;S&&await q(S,R),O.current&&(O.current.value="");},[q,O]);qe.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__default.default.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=qe.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=qe.useCallback(c=>{xe(S=>S.filter(E=>E.id!==c));},[]),Gn=qe.useCallback((c,S,E)=>{Ge(c),Ie(S),xe(E||[]);},[]),Un=qe.useCallback(()=>{Ge(null),Ie(""),xe([]);},[]),jn=qe.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=jsxRuntime.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:[jsxRuntime.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}),jsxRuntime.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?jsxRuntime.jsx("div",{style:{padding:"32px",textAlign:"center",color:b.mutedTextColor,fontSize:"14px"},children:m("messages.empty")}):jsxRuntime.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})}),jsxRuntime.jsxs("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px"},children:[_&&jsxRuntime.jsxs("div",{style:{padding:"8px 12px",marginBottom:"8px",backgroundColor:"#ef4444",color:"#fff",borderRadius:"8px",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{children:_}),jsxRuntime.jsx("button",{onClick:()=>R(null),style:{background:"none",border:"none",color:"#fff",cursor:"pointer",padding:"2px"},children:"\xD7"})]}),St&&jsxRuntime.jsxs("div",{style:{padding:"8px 12px",marginBottom:"8px",backgroundColor:"#ef4444",color:"#fff",borderRadius:"8px",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxRuntime.jsxs("span",{children:["An error occurred: ",St.message||"Please try again."]}),jsxRuntime.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"})]}),jsxRuntime.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})]}),jsxRuntime.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}),jsxRuntime.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?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(
|
|
37
|
-
@keyframes ${
|
|
36
|
+
`})]});return typeof document<"u"&&document.body?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(tt,{}),reactDom.createPortal(Lt,document.body),jsxRuntime.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=qe.useRef(`content-container-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),[v,k]=qe.useState(false);qe.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 jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:C,style:{width:G,height:"100%",transition:v?"all 0.2s ease-out":"none",padding:w&&I?"16px":"0",...O},children:jsxRuntime.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:jsxRuntime.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})})}),jsxRuntime.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
|
|
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;exports.Button=gr;exports.ContentContainer=ir;exports.CursorController=tt;exports.FillActiveInput=He;exports.FloatingChatButton=Dt;exports.HsafaChat=er;exports.HsafaProvider=Yn;exports.componentRegistry=lr;exports.controlCursor=fe;exports.getDomComponents=Le;exports.guideCursor=fe;exports.useAutoScroll=Wt;exports.useFileUpload=Gt;exports.useHsafa=ke;//# sourceMappingURL=index.cjs.map
|
|
43
43
|
//# sourceMappingURL=index.cjs.map
|