@hsafa/ui-sdk 0.1.0 → 0.1.2

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 CHANGED
@@ -1,30 +1,87 @@
1
- 'use strict';var jsxRuntime=require('react/jsx-runtime'),react=require('react'),reactDom=require('react-dom'),iconsReact=require('@tabler/icons-react');var Z={};var er=({variant:a="primary",size:u="md",loading:p=false,disabled:m,children:A,className:T,...z})=>{let j=[Z.button,Z[a],Z[u],p&&Z.loading,T].filter(Boolean).join(" ");return jsxRuntime.jsxs("button",{className:j,disabled:m||p,...z,children:[p&&jsxRuntime.jsx("span",{className:Z.spinner}),jsxRuntime.jsx("span",{className:p?Z.hiddenText:void 0,children:A})]})};function nr(a=false){let[u,p]=react.useState(a),m=react.useCallback(()=>p(z=>!z),[]),A=react.useCallback(()=>p(true),[]),T=react.useCallback(()=>p(false),[]);return {on:u,toggle:m,setOn:p,setTrue:A,setFalse:T}}function lr(){let a=react.useRef(null);return react.useEffect(()=>{let u=a.current;if(!u)return;let p=new MutationObserver(()=>{u.scrollTop=u.scrollHeight;});return p.observe(u,{childList:true,subtree:true}),u.scrollTop=u.scrollHeight,()=>p.disconnect()},[]),a}var We=react.createContext(void 0);function Et({baseUrl:a,children:u}){let[p,m]=react.useState(new Map),[A,T]=react.useState(new Map),z=react.useCallback((M,v)=>(m($=>{let g=new Map($);return g.set(String(M),v),g}),()=>{m($=>{let g=new Map($),y=g.get(String(M));return (!v||y===v)&&g.delete(String(M)),g});}),[]),j=react.useCallback((M,v)=>{m($=>{let g=new Map($),y=g.get(String(M));return (!v||y===v)&&g.delete(String(M)),g});},[]),Y=react.useCallback((M,v)=>(T($=>{let g=new Map($);return g.set(String(M),v),g}),()=>{T($=>{let g=new Map($),y=g.get(String(M));return (!v||y===v)&&g.delete(String(M)),g});}),[]),te=react.useCallback((M,v)=>{T($=>{let g=new Map($),y=g.get(String(M));return (!v||y===v)&&g.delete(String(M)),g});},[]),ce=react.useMemo(()=>({baseUrl:a,actions:p,components:A,registerAction:z,unregisterAction:j,registerComponent:Y,unregisterComponent:te}),[a,p,A,z,j,Y,te]);return jsxRuntime.jsx(We.Provider,{value:ce,children:u})}function ee(){let a=react.useContext(We);return a||{baseUrl:void 0,actions:new Map,components:new Map,registerAction:()=>()=>{},unregisterAction:()=>{},registerComponent:()=>()=>{},unregisterComponent:()=>{}}}function mr(a,u){let{registerAction:p}=ee(),m=react.useRef(u);react.useEffect(()=>{m.current=u;},[u]),react.useEffect(()=>!a||typeof m.current!="function"?void 0:p(a,(T,z)=>m.current(T,z)),[a,p]);}function Cr(a,u){let{registerComponent:p}=ee(),m=react.useRef(u);react.useEffect(()=>{m.current=u;},[u]),react.useEffect(()=>!a||typeof m.current!="function"?void 0:p(a,m.current),[a,p]);}function _t(a){let u=Date.now()-a,p=Math.max(1,Math.floor(u/1e3));if(p<60)return `${p}s`;let m=Math.floor(p/60);if(m<60)return `${m}m`;let A=Math.floor(m/60);if(A<24)return `${A}h`;let T=Math.floor(A/24);if(T<7)return `${T}d`;let z=Math.floor(T/7);if(z<4)return `${z}w`;let j=Math.floor(T/30);return j<12?`${j}mo`:`${Math.floor(j/12)}y`}function Qe(a,u){if(!a)return u;let p=a.endsWith("/")?a.slice(0,-1):a,m=u.startsWith("/")?u:`/${u}`;return `${p}${m}`}var Wt={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 Xt({agentId:a,children:u,theme:p="dark",primaryColor:m,backgroundColor:A,borderColor:T,textColor:z,accentColor:j,width:Y=420,maxWidth:te=420,height:ce="100vh",expandable:M=true,alwaysOpen:v=false,defaultOpen:$=true,dir:g="ltr",floatingButtonPosition:y=g==="rtl"?{bottom:16,left:16}:{bottom:16,right:16},enableBorderAnimation:Ae=true,enableContentPadding:Ze=true,borderRadius:Ce=16,enableContentBorder:$e=true,placeholder:et="Ask your question...",title:He="Agent",className:tt="",chatContainerClassName:rt=""}){let{baseUrl:Ie,actions:Ee,components:ot}=ee(),ue="hsafaChat",Re=`${ue}.chats`,he=e=>`${ue}.chat.${e}`,V=`${ue}.currentChatId`,Be=`${ue}.showChat`,[de,Fe]=react.useState(""),[_,pe]=react.useState(()=>{if(v)return true;try{let e=localStorage.getItem(Be);return e!==null?e==="true":$}catch{return $}});async function ze(e,n){if(!a)return;let r=n.trim();if(!r)return;U(null),re(true);let s=N.findIndex(d=>d.id===e);if(s===-1||N[s].role!=="user"){re(false);return}let c=N.slice(0,s),H={id:e,role:"user",text:r},O=ie(),C=[...c,H,{id:O,role:"assistant",items:[],reasoning:"",reasoningOpen:false}];w(C),ge(null);try{let d=[...c.map(E=>E.role==="user"?{role:"user",content:E.text}:{role:"assistant",items:Array.isArray(E.items)?E.items:[]}),{role:"user",content:r}],I={prompt:r,chatId:k??void 0,messages:d};w(E=>E.map(q=>q.id===O||q.id===e?{...q,requestParams:I}:q));let S=await fetch(Qe(Ie,`/api/run/${a}`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(I)});if(!S.ok||!S.body){let E=await S.text().catch(()=>"");throw new Error(E||`Request failed with ${S.status}`)}let P=S.body.getReader(),Q=new TextDecoder,D="";for(;;){let{done:E,value:q}=await P.read();if(E)break;D+=Q.decode(q,{stream:!0});let f;for(;(f=D.indexOf(`
2
- `))!==-1;){let R=D.slice(0,f).trim();if(D=D.slice(f+1),!!R)try{let i=JSON.parse(R);if(i?.type==="meta"){if(i.actionExecuteMap&&typeof i.actionExecuteMap=="object"&&(Te.current=i.actionExecuteMap),i.assistantMessageId&&(oe.current=String(i.assistantMessageId),me.current.clear(),ye.current.clear(),G.current.clear(),ne(new Map)),i.chatId&&!k){W(i.chatId),L.current=!0;let l=r,K=(X.current||l||"New chat").slice(0,80),b=Date.now();le({id:i.chatId,title:K,createdAt:b,updatedAt:b}),se({id:i.chatId,messages:C,agentId:a});try{localStorage.setItem(V,i.chatId);}catch{}}continue}if(i?.type==="reasoning"){let l=String(i.text??"");w(K=>K.map(b=>b.id===O&&b.role==="assistant"?{...b,reasoning:(b.reasoning??"")+l}:b));continue}if(i?.type==="partial"||i?.type==="final"){let l=i.value;l&&Array.isArray(l.items)&&(w(K=>K.map(b=>b.id===O&&b.role==="assistant"?{...b,items:l.items}:b)),Ue(l.items,i.type==="partial"?"partial":"final")),i?.type==="final"&&w(K=>K.map(b=>b.id===O&&b.role==="assistant"?{...b,reasoningOpen:!1}:b));continue}if(i?.type==="usage"){let l=i?.value?.reasoningTokens;typeof l=="number"&&w(K=>K.map(b=>b.id===O&&b.role==="assistant"?{...b,reasoningTokens:l}:b));continue}if(i?.type==="error"){U(String(i.error??"Unknown error"));continue}}catch{}}}}catch(d){U(String(d?.message??d));}finally{if(re(false),!k&&!L.current){let d=`local-${ie()}`;W(d),L.current=true;let I=(X.current||"New chat").slice(0,80),S=Date.now();le({id:d,title:I,createdAt:S,updatedAt:S}),se({id:d,messages:N,agentId:a});try{localStorage.setItem(V,d);}catch{}}}}let[N,w]=react.useState([]),[h,re]=react.useState(false),[Oe,U]=react.useState(null),ae=react.useRef(null),[k,W]=react.useState(null),[nt,ve]=react.useState(false),[De,at]=react.useState(""),[Gt,st]=react.useState(0),[lt,it]=react.useState(false),[ct,ge]=react.useState(null),[fe,Le]=react.useState(""),ut=react.useRef(null),Pe=react.useRef(null),dt=react.useRef(null),[ke,pt]=react.useState(true),we=react.useRef(false),L=react.useRef(false),X=react.useRef(null),gt=react.useRef(null),ft=react.useRef(null),Te=react.useRef({}),oe=react.useRef(void 0),me=react.useRef(new Set),ye=react.useRef(new Map),G=react.useRef(new Map),[mt,ne]=react.useState(new Map),je=react.useCallback((e,n)=>{let r=ye.current.get(e)||[],s=JSON.stringify(n);if(r.push(s),r.length>3&&r.shift(),ye.current.set(e,r),r.length>=2){let c=r.slice(-2);return c[0]===c[1]}return false},[]),Ue=react.useCallback((e,n)=>{!Array.isArray(e)||e.length===0||e.forEach((r,s)=>{if(!(!r||typeof r!="object")&&r.type==="action"){let c=String(r.name??"").trim();if(!c)return;let H=Ee.get(c);if(!H)return;let O=!!Te.current[c],C=`${oe.current||"assist"}:${c}:${s}`,d=`${c}:${s}`;try{if(n==="partial"&&O)ne(I=>new Map(I).set(d,"executing")),Promise.resolve(H(r.params,{name:c,trigger:n,index:s,assistantMessageId:oe.current,chatId:k||void 0})).catch(()=>{});else if(n==="partial"&&!O){let I=je(d,r.params),S=G.current.get(d);I&&S!=="executed"?(G.current.set(d,"executed"),ne(P=>new Map(P).set(d,"executed")),Promise.resolve(H(r.params,{name:c,trigger:"params_complete",index:s,assistantMessageId:oe.current,chatId:k||void 0})).catch(()=>{})):S||(G.current.set(d,"executing"),ne(P=>new Map(P).set(d,"executing")));}else n==="final"&&G.current.get(d)!=="executed"&&!me.current.has(C)&&(me.current.add(C),G.current.set(d,"executed"),ne(S=>new Map(S).set(d,"executed")),Promise.resolve(H(r.params,{name:c,trigger:O?"final":"params_complete",index:s,assistantMessageId:oe.current,chatId:k||void 0})).catch(()=>{}));}catch{}}});},[Ee,k,je]),Me=()=>{try{let e=localStorage.getItem(Re);return e?JSON.parse(e):[]}catch{return []}},Je=e=>{try{localStorage.setItem(Re,JSON.stringify(e));}catch{}},qe=e=>{try{let n=localStorage.getItem(he(e));return n?JSON.parse(n):null}catch{return null}},se=e=>{try{localStorage.setItem(he(e.id),JSON.stringify(e));}catch{}},le=e=>{let n=Me(),r=n.findIndex(s=>s.id===e.id);r>=0?n[r]=e:n.unshift(e),Je(n);},yt=e=>{let r=Me().filter(s=>s.id!==e);Je(r);},bt=e=>{try{localStorage.removeItem(he(e));}catch{}},xt=e=>{if(bt(e),yt(e),k===e){w([]),U(null),W(null),L.current=false,X.current=null;try{localStorage.removeItem(V);}catch{}}};react.useEffect(()=>{if(we.current){we.current=false;return}ke&&Pe.current?.scrollIntoView({behavior:"smooth",block:"end"});},[N,h,ke]),react.useEffect(()=>{try{let e=localStorage.getItem(V);if(e){let n=qe(e);n&&(W(n.id),L.current=!0,w(n.messages||[]));}}catch{}},[]),react.useEffect(()=>{try{localStorage.setItem(Be,String(_));}catch{}},[_]),react.useEffect(()=>{if(!k||!L.current)return;se({id:k,messages:N,agentId:a});let n=N.find(c=>c.role==="user"),r=(X.current||(n?.text??"New chat")).slice(0,80),s={id:k,title:r,createdAt:Date.now(),updatedAt:Date.now()};le(s);try{localStorage.setItem(V,k);}catch{}},[N,k,a]);let ie=()=>`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;function Ct(){ae.current&&(ae.current.abort(),ae.current=null),re(false),U("Request stopped by user");}async function Ke(){if(!a)return;let e=de.trim();if(!e)return;U(null),re(true),!k&&N.length===0&&(X.current=e);let n=ie(),r=ie(),s={id:n,role:"user",text:e},c={id:r,role:"assistant",items:[],reasoning:"",reasoningOpen:false},H=[...N,s,c],O=[...N.map(C=>C.role==="user"?{role:"user",content:C.text}:{role:"assistant",items:Array.isArray(C.items)?C.items:[]}),{role:"user",content:e}];w(H),Fe("");try{ae.current=new AbortController;let C={prompt:e,chatId:k??void 0,messages:O};w(Q=>Q.map(D=>D.id===r||D.id===n?{...D,requestParams:C}:D));let d=await fetch(Qe(Ie,`/api/run/${a}`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(C),signal:ae.current.signal});if(!d.ok||!d.body){let Q=await d.text().catch(()=>"");throw new Error(Q||`Request failed with ${d.status}`)}let I=d.body.getReader(),S=new TextDecoder,P="";for(;;){let{done:Q,value:D}=await I.read();if(Q)break;P+=S.decode(D,{stream:!0});let E;for(;(E=P.indexOf(`
3
- `))!==-1;){let q=P.slice(0,E).trim();if(P=P.slice(E+1),!!q)try{let f=JSON.parse(q);if(f?.type==="meta"){if(f.actionExecuteMap&&typeof f.actionExecuteMap=="object"&&(Te.current=f.actionExecuteMap),f.assistantMessageId&&(oe.current=String(f.assistantMessageId),me.current.clear(),ye.current.clear(),G.current.clear(),ne(new Map)),f.chatId&&!k){W(f.chatId),L.current=!0;let R=e,i=(X.current||R||"New chat").slice(0,80),l=Date.now();le({id:f.chatId,title:i,createdAt:l,updatedAt:l}),se({id:f.chatId,messages:H,agentId:a});try{localStorage.setItem(V,f.chatId);}catch{}}continue}if(f?.type==="reasoning"){let R=String(f.text??"");w(i=>i.map(l=>l.id===r&&l.role==="assistant"?{...l,reasoning:(l.reasoning??"")+R}:l));continue}if(f?.type==="partial"||f?.type==="final"){let R=f.value;R&&Array.isArray(R.items)&&(w(i=>i.map(l=>l.id===r&&l.role==="assistant"?{...l,items:R.items}:l)),Ue(R.items,f.type==="partial"?"partial":"final")),f?.type==="final"&&w(i=>i.map(l=>l.id===r&&l.role==="assistant"?{...l,reasoningOpen:!1}:l));continue}if(f?.type==="usage"){let R=f?.value?.reasoningTokens;typeof R=="number"&&w(i=>i.map(l=>l.id===r&&l.role==="assistant"?{...l,reasoningTokens:R}:l));continue}if(f?.type==="error"){U(String(f.error??"Unknown error"));continue}}catch{}}}}catch(C){U(String(C?.message??C));}finally{if(re(false),!k&&!L.current){let C=`local-${ie()}`;W(C),L.current=true;let d=(X.current||"New chat").slice(0,80),I=Date.now();le({id:C,title:d,createdAt:I,updatedAt:I}),se({id:C,messages:N,agentId:a});try{localStorage.setItem(V,C);}catch{}}}}function ht(e){return !Array.isArray(e)||e.length===0?null:jsxRuntime.jsx("div",{className:"space-y-3",children:e.map((n,r)=>{let s=`it-${r}`;if(typeof n=="string")return jsxRuntime.jsx("div",{className:"rounded-xl p-4 text-[14px] whitespace-pre-wrap",children:n},s);if(n&&typeof n=="object"){if(n.type==="action"){let c=`${String(n.name??"action")}:${r}`,H=mt.get(c);return jsxRuntime.jsx("div",{className:"space-y-2",children:jsxRuntime.jsx("div",{className:"px-2 py-1 text-xs",style:{color:t.mutedTextColor},children:H==="executing"?jsxRuntime.jsxs("span",{className:"flex items-center gap-2",children:[jsxRuntime.jsxs("svg",{className:"animate-spin h-3 w-3",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[jsxRuntime.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsxRuntime.jsx("path",{className:"opacity-75",fill:"currentColor",d:"m4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),String(n.name??"action")," is executing"]}):jsxRuntime.jsxs("span",{className:"flex items-center gap-1",children:[jsxRuntime.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full",style:{backgroundColor:"#10b981"}}),String(n.name??"action")," has executed"]})})},s)}if(n.type==="ui-component"||n.type==="ui"){let c=String(n.name??n.component??"").trim(),H=c?ot.get(c):void 0;return H?jsxRuntime.jsx(H,{...n.props||{}}):jsxRuntime.jsxs("div",{className:"rounded-xl p-4",style:{backgroundColor:t.inputBackground,border:`1px solid ${t.borderColor}`},children:[jsxRuntime.jsxs("div",{className:"inline-flex items-center gap-2 text-xs mb-2",style:{color:t.mutedTextColor},children:[jsxRuntime.jsx("span",{className:"px-2 py-0.5 rounded",style:{backgroundColor:t.accentColor,border:`1px solid ${t.borderColor}`},children:"UI"}),jsxRuntime.jsx("span",{children:c||"component"}),jsxRuntime.jsx("span",{className:"ml-2 opacity-70",children:"(unregistered)"})]}),jsxRuntime.jsx("pre",{className:"text-xs overflow-auto",style:{color:t.mutedTextColor},children:JSON.stringify(n.props??{},null,2)})]},s)}return jsxRuntime.jsx("div",{className:"rounded-xl p-4 text-[14px]",style:{backgroundColor:t.cardBackground,border:`1px solid ${t.borderColor}`},children:jsxRuntime.jsx("pre",{className:"text-xs overflow-auto",style:{color:t.mutedTextColor},children:JSON.stringify(n,null,2)})},s)}return null})})}let J=Wt[p],t={primaryColor:m||J.primaryColor,backgroundColor:A||J.backgroundColor,borderColor:T||J.borderColor,textColor:z||J.textColor,accentColor:j||J.accentColor,mutedTextColor:J.mutedTextColor,inputBackground:J.inputBackground,cardBackground:J.cardBackground,hoverBackground:J.hoverBackground},vt={backgroundColor:t.backgroundColor,color:t.textColor,height:ce},kt={width:typeof Y=="number"?`${Y}px`:Y,maxWidth:typeof te=="number"?`${te}px`:te},wt={position:"fixed",bottom:typeof y.bottom=="number"?`${y.bottom}px`:y.bottom,right:y.right?typeof y.right=="number"?`${y.right}px`:y.right:void 0,top:y.top?typeof y.top=="number"?`${y.top}px`:y.top:void 0,left:y.left?typeof y.left=="number"?`${y.left}px`:y.left:void 0},Ne=typeof Ce=="number"?`${Ce}px`:Ce;return jsxRuntime.jsxs("div",{className:`flex h-full w-full ${tt}`,style:vt,dir:g,children:[jsxRuntime.jsx("div",{className:`flex items-stretch transition-all duration-1000 justify-stretch w-full h-full ${_&&Ze?"p-4":"p-0"}`,children:jsxRuntime.jsx("div",{className:"relative flex w-full h-full transition-all duration-1000 ease-out",style:{borderRadius:_&&$e?Ne:"0"},children:_&&$e?jsxRuntime.jsx("div",{className:`w-full h-full transition-all duration-600 ease-out ${h&&Ae?"tc-animated-border p-[1.5px]":"border p-0"}`,style:{borderRadius:Ne,borderColor:!h||!Ae?t.borderColor:"transparent"},children:jsxRuntime.jsx("div",{className:"w-full h-full",style:{borderRadius:Ne,backgroundColor:t.backgroundColor},children:u})}):jsxRuntime.jsx("div",{className:"w-full h-full",children:u})})}),jsxRuntime.jsxs("div",{className:`${rt} flex flex-col transition-all duration-300 ease-out overflow-hidden ${_||v?lt&&M?"fixed inset-0 z-50 w-full max-w-full px-6 py-6":"px-4 py-6 opacity-100 translate-x-0":`w-0 max-w-0 px-0 py-6 opacity-0 ${g==="rtl"?"translate-x-2":"-translate-x-2"} pointer-events-none`}`,style:{...kt,height:ce,backgroundColor:_||v?t.backgroundColor:"transparent"},children:[jsxRuntime.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[jsxRuntime.jsx("div",{className:"min-w-0",children:jsxRuntime.jsx("h1",{title:He,className:"truncate text-[18px] font-semibold",style:{color:t.textColor},children:He})}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 relative",style:{color:t.mutedTextColor},children:[M&&jsxRuntime.jsx("button",{"aria-label":"Pop out",className:"rounded-lg p-2 transition-all duration-200 ease-out",style:{backgroundColor:"transparent",color:t.mutedTextColor},onMouseEnter:e=>{e.currentTarget.style.backgroundColor=t.hoverBackground,e.currentTarget.style.color=t.textColor;},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="transparent",e.currentTarget.style.color=t.mutedTextColor;},onClick:()=>{pe(true),it(e=>!e);},children:jsxRuntime.jsx(iconsReact.IconArrowsMaximize,{size:20,stroke:2})}),jsxRuntime.jsx("button",{"aria-label":"New",className:"rounded-lg p-2 transition-all duration-200 ease-out",style:{backgroundColor:"transparent",color:t.mutedTextColor},onMouseEnter:e=>{e.currentTarget.style.backgroundColor=t.hoverBackground,e.currentTarget.style.color=t.textColor;},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="transparent",e.currentTarget.style.color=t.mutedTextColor;},onClick:()=>{h||(w([]),U(null),W(null),L.current=false,X.current=null);},children:jsxRuntime.jsx(iconsReact.IconPlus,{size:20,stroke:2})}),jsxRuntime.jsx("button",{"aria-label":"History",className:"rounded-lg p-2 transition-all duration-200 ease-out",style:{backgroundColor:"transparent",color:t.mutedTextColor},onMouseEnter:e=>{e.currentTarget.style.backgroundColor=t.hoverBackground,e.currentTarget.style.color=t.textColor;},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="transparent",e.currentTarget.style.color=t.mutedTextColor;},onClick:()=>ve(e=>!e),ref:gt,children:jsxRuntime.jsx(iconsReact.IconHistory,{size:20,stroke:2})}),nt&&reactDom.createPortal(jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"fixed inset-0 z-[900] bg-black/40 backdrop-blur-sm",onClick:()=>ve(false)}),jsxRuntime.jsxs("div",{ref:ft,className:"fixed left-1/2 top-16 -translate-x-1/2 z-[1000] w-[680px] max-w-[94vw] overflow-hidden rounded-2xl border border-[#2A2C33] bg-[#0F1116]/95 shadow-2xl ring-1 ring-black/10",children:[jsxRuntime.jsx("div",{className:"flex items-center gap-3 border-b border-[#2A2C33] px-4 py-3",children:jsxRuntime.jsx("div",{className:"flex-1",children:jsxRuntime.jsx("input",{autoFocus:true,value:De,onChange:e=>at(e.target.value),placeholder:"Search",className:"w-full rounded-lg bg-[#0B0B0F] px-3 py-2 text-sm text-[#EDEEF0] placeholder:text-[#9AA0A6] outline-none border border-[#2A2C33] focus:border-[#3a3d46]"})})}),jsxRuntime.jsx("div",{className:"max-h-[60vh] overflow-y-auto",children:(()=>{let e=De.toLowerCase().trim(),n=Me();return e&&(n=n.filter(r=>(r.title||"").toLowerCase().includes(e))),!n||n.length===0?jsxRuntime.jsx("div",{className:"p-6 text-[#9AA0A6]",children:"No chats found."}):jsxRuntime.jsx("ul",{className:"divide-y divide-[#2A2C33]",children:n.map(r=>jsxRuntime.jsx("li",{children:jsxRuntime.jsxs("div",{className:`flex w-full items-center justify-between gap-3 p-3 ${r.id===k?"bg-[#121318]":""}`,children:[jsxRuntime.jsx("button",{className:"flex-1 text-left transition-colors hover:bg-[#17181C] rounded-lg px-2 py-2",onClick:()=>{let s=qe(r.id);if(s){W(r.id),L.current=true,w(s.messages||[]);try{localStorage.setItem(V,r.id);}catch{}ve(false),pe(true);}},children:jsxRuntime.jsxs("div",{className:"flex items-center justify-between gap-3",children:[jsxRuntime.jsx("div",{className:"min-w-0",children:jsxRuntime.jsx("div",{className:"truncate text-[14px] text-[#EDEEF0]",children:r.title||"Untitled chat"})}),jsxRuntime.jsx("div",{className:"shrink-0 text-[12px] text-[#9AA0A6]",children:_t(r.updatedAt)})]})}),jsxRuntime.jsx("button",{className:"shrink-0 rounded-md p-2 text-[#9AA0A6] hover:text-red-300 hover:bg-red-500/10 border border-transparent hover:border-red-500/30",title:"Delete chat",onClick:s=>{s.stopPropagation(),xt(r.id),st(c=>c+1);},children:jsxRuntime.jsx(iconsReact.IconTrash,{size:16,stroke:2})})]})},r.id))})})()})]})]}),document.body),!v&&jsxRuntime.jsx("button",{"aria-label":"Close chat",className:"rounded-lg p-2 transition-all duration-200 ease-out",style:{backgroundColor:"transparent",color:t.mutedTextColor},onMouseEnter:e=>{e.currentTarget.style.backgroundColor=t.hoverBackground,e.currentTarget.style.color=t.textColor;},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="transparent",e.currentTarget.style.color=t.mutedTextColor;},onClick:()=>pe(false),children:jsxRuntime.jsx(iconsReact.IconChevronRight,{size:20,stroke:2,style:{transform:g==="rtl"?"rotate(180deg)":"none"}})})]})]}),jsxRuntime.jsxs("div",{className:"flex-1 overflow-y-auto space-y-4 px-1 pb-4 pt-4",ref:dt,onScroll:e=>{let n=e.currentTarget,c=n.scrollHeight-(n.scrollTop+n.clientHeight)<=64;c!==ke&&pt(c);},children:[Oe&&jsxRuntime.jsx("div",{className:"mx-2 rounded-xl bg-red-500/10 text-red-300 border border-red-500/30 p-3 text-sm",children:Oe}),N.length===0&&!h&&jsxRuntime.jsx("div",{className:"mx-2 rounded-xl p-4",style:{border:`1px solid ${t.borderColor}`,backgroundColor:t.accentColor,color:t.mutedTextColor},children:"Start by sending a message to the agent."}),jsxRuntime.jsx("ul",{className:"space-y-4",children:N.map((e,n)=>jsxRuntime.jsx("li",{className:"px-1",children:e.role==="user"?ct===e.id?jsxRuntime.jsxs("div",{className:"max-w-[720px] rounded-2xl p-2 text-[15px] ring-2",style:{backgroundColor:t.accentColor,color:t.textColor,borderColor:t.primaryColor},children:[jsxRuntime.jsx("textarea",{autoFocus:true,className:"w-full resize-none bg-transparent p-2 leading-relaxed outline-none",rows:Math.max(2,Math.min(10,Math.ceil((fe||e.text).length/60))),value:fe,onChange:r=>Le(r.target.value),onKeyDown:r=>{r.key==="Escape"?ge(null):r.key==="Enter"&&!r.shiftKey&&(r.preventDefault(),h||ze(e.id,fe||e.text));}}),jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-2 px-2 pb-2",children:[jsxRuntime.jsx("button",{className:"rounded-lg px-3 py-1 text-sm transition-colors",style:{border:`1px solid ${t.borderColor}`,color:t.mutedTextColor,backgroundColor:"transparent"},onMouseEnter:r=>r.currentTarget.style.backgroundColor=t.inputBackground,onMouseLeave:r=>r.currentTarget.style.backgroundColor="transparent",onClick:()=>ge(null),children:"Cancel"}),jsxRuntime.jsx("button",{className:"rounded-lg px-3 py-1 text-sm transition-colors",style:{border:`1px solid ${t.borderColor}`,backgroundColor:t.cardBackground,color:t.textColor},onMouseEnter:r=>r.currentTarget.style.borderColor=t.primaryColor,onMouseLeave:r=>r.currentTarget.style.borderColor=t.borderColor,onClick:()=>{h||ze(e.id,fe||e.text);},children:"Save"})]})]}):jsxRuntime.jsx("div",{title:"Click to edit",onClick:()=>{h||(ge(e.id),Le(e.text));},className:"max-w-[720px] rounded-2xl p-4 text-[15px] leading-relaxed whitespace-pre-wrap cursor-pointer transition",style:{backgroundColor:t.accentColor,color:t.textColor},onMouseEnter:r=>r.currentTarget.style.backgroundColor=t.hoverBackground,onMouseLeave:r=>r.currentTarget.style.backgroundColor=t.accentColor,children:e.text}):jsxRuntime.jsxs("div",{className:"space-y-3",children:[e.reasoning&&jsxRuntime.jsxs("div",{className:"rounded-xl p-3 cursor-pointer",style:{backgroundColor:t.inputBackground,border:`1px solid ${t.borderColor}`},onClick:()=>{we.current=true,w(r=>r.map(s=>s.id===e.id&&s.role==="assistant"?{...s,reasoningOpen:!s.reasoningOpen}:s));},children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between mb-1",children:[jsxRuntime.jsx("div",{className:"text-xs",style:{color:t.mutedTextColor},children:"Reasoning"}),jsxRuntime.jsx("button",{type:"button",className:"text-xs transition-colors",style:{color:t.mutedTextColor},onMouseEnter:r=>r.currentTarget.style.color=t.textColor,onMouseLeave:r=>r.currentTarget.style.color=t.mutedTextColor,children:e.reasoningOpen?"Hide":"Show full"})]}),e.reasoningOpen?jsxRuntime.jsx("pre",{className:"text-xs whitespace-pre-wrap break-words",style:{color:t.mutedTextColor},children:e.reasoning}):(()=>{let r=(e.reasoning||"").trim().split(`
4
- `).filter(c=>c.trim()),s=r.length>0?r[r.length-1]:"";return jsxRuntime.jsx("pre",{className:"text-xs whitespace-pre-wrap break-words",style:{color:t.mutedTextColor},children:s||"\u2026"})})()]}),ht(e.items),h&&n===N.length-1&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2 text-xs",style:{color:t.mutedTextColor},children:[jsxRuntime.jsx("span",{className:"inline-block h-2 w-2 rounded-full animate-pulse",style:{backgroundColor:t.mutedTextColor}}),jsxRuntime.jsx("span",{children:"Working\u2026"})]})]})},e.id))}),jsxRuntime.jsx("div",{ref:Pe})]}),jsxRuntime.jsx("div",{className:"sticky bottom-0 mt-auto space-y-2 pb-2 pt-1",style:{backgroundColor:t.backgroundColor},children:jsxRuntime.jsx("div",{className:"relative flex-1",children:jsxRuntime.jsxs("div",{className:"relative w-full rounded-2xl pb-12 pt-4",style:{border:`1px solid ${t.borderColor}`,backgroundColor:t.accentColor},children:[jsxRuntime.jsx("div",{className:"px-4",children:jsxRuntime.jsx("textarea",{"aria-label":"Prompt",rows:2,className:"h-auto w-full resize-none bg-transparent text-[15px] leading-relaxed focus:outline-none hsafa-chat-textarea",style:{color:t.textColor},placeholder:et,value:de,onChange:e=>Fe(e.target.value),onKeyDown:e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),h||Ke());},ref:ut})}),jsxRuntime.jsxs("div",{className:"absolute bottom-2 left-2 flex items-center gap-1",style:{color:t.mutedTextColor},children:[jsxRuntime.jsx("button",{className:"rounded-lg p-2 transition-colors",style:{backgroundColor:"transparent"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor=`${t.backgroundColor}99`,e.currentTarget.style.color=t.textColor;},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="transparent",e.currentTarget.style.color=t.mutedTextColor;},"aria-label":"Attach files",children:jsxRuntime.jsx(iconsReact.IconPaperclip,{size:18,stroke:2})}),jsxRuntime.jsx("button",{className:"rounded-lg p-2 transition-colors",style:{backgroundColor:"transparent"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor=`${t.backgroundColor}99`,e.currentTarget.style.color=t.textColor;},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="transparent",e.currentTarget.style.color=t.mutedTextColor;},"aria-label":"Insert link",children:jsxRuntime.jsx(iconsReact.IconLink,{size:18,stroke:2})})]}),jsxRuntime.jsx("div",{className:"absolute bottom-2 right-2",children:jsxRuntime.jsx("button",{"aria-label":h?"Stop":"Send",disabled:!h&&!de.trim(),className:"rounded-xl p-3 transition-all duration-200 ease-out",style:{border:`1px solid ${h?"#ef4444":t.borderColor}`,backgroundColor:h?"#ef444420":t.cardBackground,color:h?"#ef4444":t.mutedTextColor,opacity:!h&&!de.trim()?.4:1},onMouseEnter:e=>{e.currentTarget.disabled||(h?(e.currentTarget.style.borderColor="#dc2626",e.currentTarget.style.backgroundColor="#dc262630",e.currentTarget.style.color="#dc2626"):(e.currentTarget.style.borderColor=t.primaryColor,e.currentTarget.style.backgroundColor=t.hoverBackground,e.currentTarget.style.color=t.textColor));},onMouseLeave:e=>{e.currentTarget.disabled||(h?(e.currentTarget.style.borderColor="#ef4444",e.currentTarget.style.backgroundColor="#ef444420",e.currentTarget.style.color="#ef4444"):(e.currentTarget.style.borderColor=t.borderColor,e.currentTarget.style.backgroundColor=t.cardBackground,e.currentTarget.style.color=t.mutedTextColor));},onClick:()=>{h?Ct():Ke();},children:h?jsxRuntime.jsx(iconsReact.IconPlayerStop,{size:18,stroke:2}):jsxRuntime.jsx(iconsReact.IconArrowUp,{size:18,stroke:2})})})]})})})]}),!_&&!v&&jsxRuntime.jsx("button",{"aria-label":"Open chat",onClick:()=>pe(true),className:"rounded-full border p-3 shadow-md transition-colors",style:{...wt,borderColor:t.borderColor,backgroundColor:t.accentColor,color:t.textColor,borderRadius:"50%"},onMouseEnter:e=>{e.currentTarget.style.borderColor=t.primaryColor,e.currentTarget.style.backgroundColor=`${t.accentColor}dd`;},onMouseLeave:e=>{e.currentTarget.style.borderColor=t.borderColor,e.currentTarget.style.backgroundColor=t.accentColor;},children:jsxRuntime.jsx(iconsReact.IconMessage,{size:20,stroke:2})}),jsxRuntime.jsx("style",{children:`
5
- @keyframes tc-border-flow {
1
+ 'use strict';var jsxRuntime=require('react/jsx-runtime'),react=require('react'),reactDom=require('react-dom'),iconsReact=require('@tabler/icons-react');var te={};var tr=({variant:s="primary",size:p="md",loading:g=false,disabled:b,children:z,className:$,...O})=>{let U=[te.button,te[s],te[p],g&&te.loading,$].filter(Boolean).join(" ");return jsxRuntime.jsxs("button",{className:U,disabled:b||g,...O,children:[g&&jsxRuntime.jsx("span",{className:te.spinner}),jsxRuntime.jsx("span",{className:g?te.hiddenText:void 0,children:z})]})};function ar(s=false){let[p,g]=react.useState(s),b=react.useCallback(()=>g(O=>!O),[]),z=react.useCallback(()=>g(true),[]),$=react.useCallback(()=>g(false),[]);return {on:p,toggle:b,setOn:g,setTrue:z,setFalse:$}}function lr(){let s=react.useRef(null);return react.useEffect(()=>{let p=s.current;if(!p)return;let g=new MutationObserver(()=>{p.scrollTop=p.scrollHeight;});return g.observe(p,{childList:true,subtree:true}),p.scrollTop=p.scrollHeight,()=>g.disconnect()},[]),s}var Ye=react.createContext(void 0);function zt({baseUrl:s,children:p}){let[g,b]=react.useState(new Map),[z,$]=react.useState(new Map),O=react.useCallback((I,w)=>(b(F=>{let f=new Map(F);return f.set(String(I),w),f}),()=>{b(F=>{let f=new Map(F),m=f.get(String(I));return (!w||m===w)&&f.delete(String(I)),f});}),[]),U=react.useCallback((I,w)=>{b(F=>{let f=new Map(F),m=f.get(String(I));return (!w||m===w)&&f.delete(String(I)),f});},[]),G=react.useCallback((I,w)=>($(F=>{let f=new Map(F);return f.set(String(I),w),f}),()=>{$(F=>{let f=new Map(F),m=f.get(String(I));return (!w||m===w)&&f.delete(String(I)),f});}),[]),oe=react.useCallback((I,w)=>{$(F=>{let f=new Map(F),m=f.get(String(I));return (!w||m===w)&&f.delete(String(I)),f});},[]),ge=react.useMemo(()=>({baseUrl:s,actions:g,components:z,registerAction:O,unregisterAction:U,registerComponent:G,unregisterComponent:oe}),[s,g,z,O,U,G,oe]);return jsxRuntime.jsx(Ye.Provider,{value:ge,children:p})}function re(){let s=react.useContext(Ye);return s||{baseUrl:void 0,actions:new Map,components:new Map,registerAction:()=>()=>{},unregisterAction:()=>{},registerComponent:()=>()=>{},unregisterComponent:()=>{}}}function yr(s,p){let{registerAction:g}=re(),b=react.useRef(p);react.useEffect(()=>{b.current=p;},[p]),react.useEffect(()=>!s||typeof b.current!="function"?void 0:g(s,($,O)=>b.current($,O)),[s,g]);}function Cr(s,p){let{registerComponent:g}=re(),b=react.useRef(p);react.useEffect(()=>{b.current=p;},[p]),react.useEffect(()=>!s||typeof b.current!="function"?void 0:g(s,b.current),[s,g]);}function Xt(s){let p=Date.now()-s,g=Math.max(1,Math.floor(p/1e3));if(g<60)return `${g}s`;let b=Math.floor(g/60);if(b<60)return `${b}m`;let z=Math.floor(b/60);if(z<24)return `${z}h`;let $=Math.floor(z/24);if($<7)return `${$}d`;let O=Math.floor($/7);if(O<4)return `${O}w`;let U=Math.floor($/30);return U<12?`${U}mo`:`${Math.floor(U/12)}y`}function et(s,p){if(!s)return p;let g=s.endsWith("/")?s.slice(0,-1):s,b=p.startsWith("/")?p:`/${p}`;return `${g}${b}`}var Vt={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 Yt({agentId:s,children:p,theme:g="dark",primaryColor:b,backgroundColor:z,borderColor:$,textColor:O,accentColor:U,width:G=420,maxWidth:oe=420,height:ge="100vh",expandable:I=true,alwaysOpen:w=false,defaultOpen:F=true,dir:f="ltr",floatingButtonPosition:m=f==="rtl"?{bottom:16,left:16}:{bottom:16,right:16},enableBorderAnimation:ne=true,enableContentPadding:tt=true,borderRadius:ke=16,enableContentBorder:Ae=true,placeholder:rt="Ask your question...",title:He="Agent",className:ot="",chatContainerClassName:nt=""}){let{baseUrl:Ee,actions:ze,components:at}=re(),fe=`hsafaChat_${s}`,Fe=`${fe}.chats`,ve=e=>`${fe}.chat.${e}`,J=`${fe}.currentChatId`,Be=`${fe}.showChat`,[ie,Ne]=react.useState(""),[V,xe]=react.useState(()=>{if(w)return true;try{let e=localStorage.getItem(Be);return e!==null?e==="true":F}catch{return F}});async function Le(e,n){if(!s)return;let r=n.trim();if(!r)return;_(null),ae(true);let a=A.findIndex(c=>c.id===e);if(a===-1||A[a].role!=="user"){ae(false);return}let i=A.slice(0,a),d={id:e,role:"user",text:r},B=ue(),k=[...i,d,{id:B,role:"assistant",items:[],reasoning:"",reasoningOpen:false}];M(k),ye(null);try{let c=[...i.map(N=>N.role==="user"?{role:"user",content:N.text}:{role:"assistant",items:Array.isArray(N.items)?N.items:[]}),{role:"user",content:r}],R={prompt:r,chatId:S??void 0,messages:c};M(N=>N.map(K=>K.id===B||K.id===e?{...K,requestParams:R}:K));let v=await fetch(et(Ee,`/api/run/${s}`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(R)});if(!v.ok||!v.body){let N=await v.text().catch(()=>"");throw new Error(N||`Request failed with ${v.status}`)}let T=v.body.getReader(),ee=new TextDecoder,P="";for(;;){let{done:N,value:K}=await T.read();if(N)break;P+=ee.decode(K,{stream:!0});let x;for(;(x=P.indexOf(`
2
+ `))!==-1;){let L=P.slice(0,x).trim();if(P=P.slice(x+1),!!L)try{let u=JSON.parse(L);if(u?.type==="meta"){if(u.actionExecuteMap&&typeof u.actionExecuteMap=="object"&&(Me.current=u.actionExecuteMap),u.assistantMessageId&&(se.current=String(u.assistantMessageId),me.current.clear(),he.current.clear(),W.current.clear(),Q(new Map)),u.chatId&&!S){Y(u.chatId),j.current=!0;let l=r,X=(Z.current||l||"New chat").slice(0,80),h=Date.now();de({id:u.chatId,title:X,createdAt:h,updatedAt:h}),ce({id:u.chatId,messages:k,agentId:s});try{localStorage.setItem(J,u.chatId);}catch{}}continue}if(u?.type==="reasoning"){let l=String(u.text??"");M(X=>X.map(h=>h.id===B&&h.role==="assistant"?{...h,reasoning:(h.reasoning??"")+l}:h));continue}if(u?.type==="partial"||u?.type==="final"){let l=u.value;l&&Array.isArray(l.items)&&(M(X=>X.map(h=>h.id===B&&h.role==="assistant"?{...h,items:l.items}:h)),Je(l.items,u.type==="partial"?"partial":"final")),u?.type==="final"&&M(X=>X.map(h=>h.id===B&&h.role==="assistant"?{...h,reasoningOpen:!1}:h));continue}if(u?.type==="usage"){let l=u?.value?.reasoningTokens;typeof l=="number"&&M(X=>X.map(h=>h.id===B&&h.role==="assistant"?{...h,reasoningTokens:l}:h));continue}if(u?.type==="error"){_(String(u.error??"Unknown error"));continue}}catch{}}}}catch(c){_(String(c?.message??c));}finally{if(ae(false),!S&&!j.current){let c=`local-${ue()}`;Y(c),j.current=true;let R=(Z.current||"New chat").slice(0,80),v=Date.now();de({id:c,title:R,createdAt:v,updatedAt:v}),ce({id:c,messages:A,agentId:s});try{localStorage.setItem(J,c);}catch{}}}}let[A,M]=react.useState([]),[y,ae]=react.useState(false),[De,_]=react.useState(null),le=react.useRef(null),[S,Y]=react.useState(null),[st,we]=react.useState(false),[Oe,it]=react.useState(""),[Gt,lt]=react.useState(0),[Pe,ct]=react.useState(false),[dt,ye]=react.useState(null),[be,je]=react.useState(""),ut=react.useRef(null),We=react.useRef(null),pt=react.useRef(null),[Te,gt]=react.useState(true),Se=react.useRef(false),j=react.useRef(false),Z=react.useRef(null),ft=react.useRef(null),xt=react.useRef(null),Me=react.useRef({}),se=react.useRef(void 0),me=react.useRef(new Set),he=react.useRef(new Map),W=react.useRef(new Map),[yt,Q]=react.useState(new Map),Ue=react.useCallback((e,n)=>{let r=he.current.get(e)||[],a=JSON.stringify(n);if(r.push(a),r.length>5&&r.shift(),he.current.set(e,r),r.length>=3){let i=r.slice(-3);return i.every(d=>d===i[0])}return false},[]),Je=react.useCallback((e,n)=>{!Array.isArray(e)||e.length===0||e.forEach((r,a)=>{if(!(!r||typeof r!="object")&&r.type==="action"){let i=String(r.name??"").trim();if(!i)return;let d=ze.get(i);if(!d){console.warn(`Action handler not found for: ${i}`);return}let B=!!Me.current[i],k=`${se.current||"assist"}:${i}:${a}`,c=`${i}:${a}`;try{if(n==="partial"&&B){Q(v=>new Map(v).set(c,"executing"));let R=setTimeout(()=>{Promise.resolve(d(r.params,{name:i,trigger:n,index:a,assistantMessageId:se.current,chatId:S||void 0})).catch(v=>{console.error(`Error executing streaming action ${i}:`,v),Q(T=>new Map(T).set(c,"executed"));});},50);W.current.set(`${c}_timeout`,R);}else if(n==="partial"&&!B){let R=Ue(c,r.params),v=W.current.get(c);R&&v!=="executed"?(W.current.set(c,"executed"),Q(T=>new Map(T).set(c,"executed")),Promise.resolve(d(r.params,{name:i,trigger:"params_complete",index:a,assistantMessageId:se.current,chatId:S||void 0})).catch(T=>{console.error(`Error executing stabilized action ${i}:`,T);})):v||(W.current.set(c,"executing"),Q(T=>new Map(T).set(c,"executing")));}else if(n==="final"&&W.current.get(c)!=="executed"&&!me.current.has(k)){me.current.add(k);let v=W.current.get(`${c}_timeout`);v&&(clearTimeout(v),W.current.delete(`${c}_timeout`)),W.current.set(c,"executed"),Q(T=>new Map(T).set(c,"executed")),Promise.resolve(d(r.params,{name:i,trigger:B?"final":"params_complete",index:a,assistantMessageId:se.current,chatId:S||void 0})).catch(T=>{console.error(`Error executing final action ${i}:`,T);});}}catch(R){console.error(`Error processing action ${i}:`,R);}}});},[ze,S,Ue]),$e=()=>{try{let e=localStorage.getItem(Fe);return e?JSON.parse(e):[]}catch{return []}},_e=e=>{try{localStorage.setItem(Fe,JSON.stringify(e));}catch{}},qe=e=>{try{let n=localStorage.getItem(ve(e));return n?JSON.parse(n):null}catch{return null}},ce=e=>{try{localStorage.setItem(ve(e.id),JSON.stringify(e));}catch{}},de=e=>{let n=$e(),r=n.findIndex(a=>a.id===e.id);r>=0?n[r]=e:n.unshift(e),_e(n);},bt=e=>{let r=$e().filter(a=>a.id!==e);_e(r);},mt=e=>{try{localStorage.removeItem(ve(e));}catch{}},ht=e=>{if(mt(e),bt(e),S===e){M([]),_(null),Y(null),j.current=false,Z.current=null;try{localStorage.removeItem(J);}catch{}}};react.useEffect(()=>{if(Se.current){Se.current=false;return}Te&&We.current?.scrollIntoView({behavior:"smooth",block:"end"});},[A,y,Te]),react.useEffect(()=>{try{let e=localStorage.getItem(J);if(e){let n=qe(e);n&&(Y(n.id),j.current=!0,M(n.messages||[]));}}catch{}},[]),react.useEffect(()=>{try{localStorage.setItem(Be,String(V));}catch{}},[V]),react.useEffect(()=>()=>{W.current.forEach((e,n)=>{n.endsWith("_timeout")&&clearTimeout(e);});},[]),react.useEffect(()=>{if(!S||!j.current)return;ce({id:S,messages:A,agentId:s});let n=A.find(i=>i.role==="user"),r=(Z.current||(n?.text??"New chat")).slice(0,80),a={id:S,title:r,createdAt:Date.now(),updatedAt:Date.now()};de(a);try{localStorage.setItem(J,S);}catch{}},[A,S,s]);let ue=()=>`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;function Ct(){le.current&&(le.current.abort(),le.current=null),ae(false),_("Request stopped by user");}async function Ke(){if(!s)return;let e=ie.trim();if(!e)return;_(null),ae(true),!S&&A.length===0&&(Z.current=e);let n=ue(),r=ue(),a={id:n,role:"user",text:e},i={id:r,role:"assistant",items:[],reasoning:"",reasoningOpen:false},d=[...A,a,i],B=[...A.map(k=>k.role==="user"?{role:"user",content:k.text}:{role:"assistant",items:Array.isArray(k.items)?k.items:[]}),{role:"user",content:e}];M(d),Ne("");try{le.current=new AbortController;let k={prompt:e,chatId:S??void 0,messages:B};M(ee=>ee.map(P=>P.id===r||P.id===n?{...P,requestParams:k}:P));let c=await fetch(et(Ee,`/api/run/${s}`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(k),signal:le.current.signal});if(!c.ok||!c.body){let ee=await c.text().catch(()=>"");throw new Error(ee||`Request failed with ${c.status}`)}let R=c.body.getReader(),v=new TextDecoder,T="";for(;;){let{done:ee,value:P}=await R.read();if(ee)break;T+=v.decode(P,{stream:!0});let N;for(;(N=T.indexOf(`
3
+ `))!==-1;){let K=T.slice(0,N).trim();if(T=T.slice(N+1),!!K)try{let x=JSON.parse(K);if(x?.type==="meta"){if(x.actionExecuteMap&&typeof x.actionExecuteMap=="object"&&(Me.current=x.actionExecuteMap),x.assistantMessageId&&(se.current=String(x.assistantMessageId),me.current.clear(),he.current.clear(),W.current.clear(),Q(new Map)),x.chatId&&!S){Y(x.chatId),j.current=!0;let L=e,u=(Z.current||L||"New chat").slice(0,80),l=Date.now();de({id:x.chatId,title:u,createdAt:l,updatedAt:l}),ce({id:x.chatId,messages:d,agentId:s});try{localStorage.setItem(J,x.chatId);}catch{}}continue}if(x?.type==="reasoning"){let L=String(x.text??"");M(u=>u.map(l=>l.id===r&&l.role==="assistant"?{...l,reasoning:(l.reasoning??"")+L}:l));continue}if(x?.type==="partial"||x?.type==="final"){let L=x.value;L&&Array.isArray(L.items)&&(M(u=>u.map(l=>l.id===r&&l.role==="assistant"?{...l,items:L.items}:l)),Je(L.items,x.type==="partial"?"partial":"final")),x?.type==="final"&&M(u=>u.map(l=>l.id===r&&l.role==="assistant"?{...l,reasoningOpen:!1}:l));continue}if(x?.type==="usage"){let L=x?.value?.reasoningTokens;typeof L=="number"&&M(u=>u.map(l=>l.id===r&&l.role==="assistant"?{...l,reasoningTokens:L}:l));continue}if(x?.type==="error"){_(String(x.error??"Unknown error"));continue}}catch{}}}}catch(k){_(String(k?.message??k));}finally{if(ae(false),!S&&!j.current){let k=`local-${ue()}`;Y(k),j.current=true;let c=(Z.current||"New chat").slice(0,80),R=Date.now();de({id:k,title:c,createdAt:R,updatedAt:R}),ce({id:k,messages:A,agentId:s});try{localStorage.setItem(J,k);}catch{}}}}function kt(e){return !Array.isArray(e)||e.length===0?null:jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map((n,r)=>{let a=`it-${r}`;if(typeof n=="string")return jsxRuntime.jsx("div",{style:{borderRadius:"12px",padding:"16px",fontSize:"14px",whiteSpace:"pre-wrap",backgroundColor:t.cardBackground,border:`1px solid ${t.borderColor}`,color:t.textColor},children:n},a);if(n&&typeof n=="object"){if(n.type==="action"){let i=`${String(n.name??"action")}:${r}`,d=yt.get(i);return jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:jsxRuntime.jsx("div",{style:{padding:"8px",fontSize:"12px",color:t.mutedTextColor},children:d==="executing"?jsxRuntime.jsxs("span",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[jsxRuntime.jsxs("svg",{style:{animation:"spin 1s linear infinite",height:"12px",width:"12px"},xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[jsxRuntime.jsx("circle",{style:{opacity:.25},cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),jsxRuntime.jsx("path",{style:{opacity:.75},fill:"currentColor",d:"m4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),String(n.name??"action")," is executing"]}):jsxRuntime.jsxs("span",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:"#10b981"}}),String(n.name??"action")," has executed"]})})},a)}if(n.type==="ui-component"||n.type==="ui"){let i=String(n.name??n.component??"").trim(),d=i?at.get(i):void 0;return d?jsxRuntime.jsx("div",{style:{borderRadius:"12px",padding:"12px",backgroundColor:t.inputBackground,border:`1px solid ${t.borderColor}`},children:jsxRuntime.jsx(d,{...n.props||{}})},a):jsxRuntime.jsxs("div",{style:{borderRadius:"12px",padding:"16px",backgroundColor:t.inputBackground,border:`1px solid ${t.borderColor}`},children:[jsxRuntime.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:"8px",fontSize:"12px",marginBottom:"8px",color:t.mutedTextColor},children:[jsxRuntime.jsx("span",{style:{padding:"2px 8px",borderRadius:"4px",backgroundColor:t.accentColor,border:`1px solid ${t.borderColor}`},children:"UI"}),jsxRuntime.jsx("span",{children:i||"component"}),jsxRuntime.jsx("span",{style:{marginLeft:"8px",opacity:.7},children:"(unregistered)"})]}),jsxRuntime.jsx("pre",{style:{fontSize:"12px",overflow:"auto",color:t.mutedTextColor,margin:"0",fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace'},children:JSON.stringify(n.props??{},null,2)})]},a)}return jsxRuntime.jsx("div",{style:{borderRadius:"12px",padding:"16px",fontSize:"14px",backgroundColor:t.cardBackground,border:`1px solid ${t.borderColor}`},children:jsxRuntime.jsx("pre",{style:{fontSize:"12px",overflow:"auto",color:t.mutedTextColor,margin:"0",fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace'},children:JSON.stringify(n,null,2)})},a)}return null})})}let q=Vt[g],t={primaryColor:b||q.primaryColor,backgroundColor:z||q.backgroundColor,borderColor:$||q.borderColor,textColor:O||q.textColor,accentColor:U||q.accentColor,mutedTextColor:q.mutedTextColor,inputBackground:q.inputBackground,cardBackground:q.cardBackground,hoverBackground:q.hoverBackground},vt={backgroundColor:t.backgroundColor,color:t.textColor,height:ge,display:"flex",width:"100%",fontFamily:'Rubik, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif'},wt={width:typeof G=="number"?`${G}px`:G,maxWidth:typeof oe=="number"?`${oe}px`:oe,display:"flex",flexDirection:"column",transition:"all 0.3s ease-out",overflow:"hidden"},Tt={position:"fixed",bottom:typeof m.bottom=="number"?`${m.bottom}px`:m.bottom,right:m.right?typeof m.right=="number"?`${m.right}px`:m.right:void 0,top:m.top?typeof m.top=="number"?`${m.top}px`:m.top:void 0,left:m.left?typeof m.left=="number"?`${m.left}px`:m.left:void 0,zIndex:1e3},Ie=typeof ke=="number"?`${ke}px`:ke,H=react.useRef(`hsafa-chat-${Date.now()}-${Math.random().toString(36).slice(2,8)}`);return jsxRuntime.jsxs("div",{className:ot,style:vt,dir:f,"data-hsafa-chat":H.current,children:[jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"stretch",justifyContent:"stretch",width:"100%",height:"100%",transition:"all 0.3s ease-out",padding:V&&tt?"16px":"0"},children:jsxRuntime.jsx("div",{style:{position:"relative",display:"flex",width:"100%",height:"100%",transition:"all 0.3s ease-out",borderRadius:V&&Ae?Ie:"0"},children:V&&Ae?jsxRuntime.jsx("div",{style:{width:"100%",height:"100%",transition:"all 0.3s ease-out",borderRadius:Ie,border:y&&ne?"none":`1px solid ${t.borderColor}`,padding:y&&ne?"1.5px":"0",background:y&&ne?`linear-gradient(120deg, ${t.primaryColor}dd 0%, ${t.primaryColor}88 25%, ${t.primaryColor}00 50%, ${t.primaryColor}88 75%, ${t.primaryColor}dd 100%)`:"transparent",backgroundSize:y&&ne?"300% 300%":"auto",animation:y&&ne?`${H.current}-border-flow 3s ease-in-out infinite`:"none",filter:y&&ne?`drop-shadow(0 0 10px ${t.primaryColor}40)`:"none"},children:jsxRuntime.jsx("div",{className:"content-container",style:{width:"100%",height:"100%",borderRadius:Ie,backgroundColor:t.backgroundColor,overflowY:"auto",overflowX:"hidden",position:"relative",isolation:"isolate",contain:"layout style paint",transform:"translateZ(0)",scrollbarWidth:"thin",scrollbarColor:`${t.mutedTextColor}40 transparent`},children:p})}):jsxRuntime.jsx("div",{className:"content-container",style:{width:"100%",height:"100%",position:"relative",isolation:"isolate",contain:"layout style paint",transform:"translateZ(0)",overflowY:"auto",overflowX:"hidden",scrollbarWidth:"thin",scrollbarColor:`${t.mutedTextColor}40 transparent`},children:p})})}),jsxRuntime.jsxs("div",{className:nt,style:{...wt,height:ge,backgroundColor:V||w?t.backgroundColor:"transparent",...V||w?Pe&&I?{position:"fixed",inset:"0",zIndex:1050,width:"100%",maxWidth:"100%",padding:"24px"}:{padding:"24px 16px",opacity:1,transform:"translateX(0)",pointerEvents:"auto"}:{width:"0",maxWidth:"0",padding:"24px 0",opacity:0,transform:f==="rtl"?"translateX(8px)":"translateX(-8px)",pointerEvents:"none"}},children:[jsxRuntime.jsxs("div",{style:{marginBottom:"24px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxRuntime.jsx("div",{style:{minWidth:"0"},children:jsxRuntime.jsx("h1",{title:He,style:{color:t.textColor,fontSize:"18px",fontWeight:"600",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",margin:"0"},children:He})}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",position:"relative",color:t.mutedTextColor},children:[I&&jsxRuntime.jsx("button",{"aria-label":Pe?"Minimize":"Maximize",style:{backgroundColor:"transparent",color:t.mutedTextColor,border:"none",borderRadius:"8px",padding:"8px",cursor:"pointer",transition:"all 0.2s ease-out",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor=t.hoverBackground,e.currentTarget.style.color=t.textColor;},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="transparent",e.currentTarget.style.color=t.mutedTextColor;},onClick:()=>{xe(true),ct(e=>!e);},children:jsxRuntime.jsx(iconsReact.IconArrowsMaximize,{size:20,stroke:2})}),jsxRuntime.jsx("button",{"aria-label":"New",style:{backgroundColor:"transparent",color:t.mutedTextColor,border:"none",borderRadius:"8px",padding:"8px",cursor:"pointer",transition:"all 0.2s ease-out",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor=t.hoverBackground,e.currentTarget.style.color=t.textColor;},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="transparent",e.currentTarget.style.color=t.mutedTextColor;},onClick:()=>{if(!y){M([]),_(null),Y(null),j.current=false,Z.current=null;try{localStorage.removeItem(J);}catch{}}},children:jsxRuntime.jsx(iconsReact.IconPlus,{size:20,stroke:2})}),jsxRuntime.jsx("button",{"aria-label":"History",style:{backgroundColor:"transparent",color:t.mutedTextColor,border:"none",borderRadius:"8px",padding:"8px",cursor:"pointer",transition:"all 0.2s ease-out",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor=t.hoverBackground,e.currentTarget.style.color=t.textColor;},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="transparent",e.currentTarget.style.color=t.mutedTextColor;},onClick:()=>we(e=>!e),ref:ft,children:jsxRuntime.jsx(iconsReact.IconHistory,{size:20,stroke:2})}),st&&(()=>{let e=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:()=>we(false)}),jsxRuntime.jsxs("div",{ref:xt,style:{position:"fixed",left:"50%",top:"64px",transform:"translateX(-50%)",zIndex:1101,width:"680px",maxWidth:"94vw",overflow:"hidden",borderRadius:"16px",border:`1px solid ${t.borderColor}`,backgroundColor:`${t.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 ${t.borderColor}`,padding:"12px 16px"},children:jsxRuntime.jsx("div",{style:{flex:"1"},children:jsxRuntime.jsx("input",{autoFocus:true,value:Oe,onChange:n=>it(n.target.value),placeholder:"Search",style:{width:"100%",borderRadius:"8px",backgroundColor:t.inputBackground,padding:"8px 12px",fontSize:"14px",color:t.textColor,border:`1px solid ${t.borderColor}`,outline:"none"},onFocus:n=>n.currentTarget.style.borderColor=t.primaryColor,onBlur:n=>n.currentTarget.style.borderColor=t.borderColor})})}),jsxRuntime.jsx("div",{style:{maxHeight:"60vh",overflowY:"auto"},children:(()=>{let n=Oe.toLowerCase().trim(),r=$e();return n&&(r=r.filter(a=>(a.title||"").toLowerCase().includes(n))),!r||r.length===0?jsxRuntime.jsx("div",{style:{padding:"24px",color:t.mutedTextColor,textAlign:"center"},children:"No chats found."}):jsxRuntime.jsx("div",{children:r.map((a,i)=>jsxRuntime.jsx("div",{style:{borderTop:i>0?`1px solid ${t.borderColor}`:"none"},children:jsxRuntime.jsxs("div",{style:{display:"flex",width:"100%",alignItems:"center",justifyContent:"space-between",gap:"12px",padding:"12px",backgroundColor:a.id===S?t.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:t.textColor},onMouseEnter:d=>d.currentTarget.style.backgroundColor=t.hoverBackground,onMouseLeave:d=>d.currentTarget.style.backgroundColor="transparent",onClick:()=>{let d=qe(a.id);if(d){Y(a.id),j.current=true,M(d.messages||[]);try{localStorage.setItem(J,a.id);}catch{}we(false),xe(true);}},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:t.textColor},children:a.title||"Untitled chat"})}),jsxRuntime.jsx("div",{style:{flexShrink:0,fontSize:"12px",color:t.mutedTextColor},children:Xt(a.updatedAt)})]})}),jsxRuntime.jsx("button",{style:{flexShrink:0,borderRadius:"6px",padding:"8px",color:t.mutedTextColor,border:"1px solid transparent",backgroundColor:"transparent",cursor:"pointer",transition:"all 0.2s"},title:"Delete chat",onMouseEnter:d=>{d.currentTarget.style.color="#ef4444",d.currentTarget.style.backgroundColor="rgba(239, 68, 68, 0.1)",d.currentTarget.style.borderColor="rgba(239, 68, 68, 0.3)";},onMouseLeave:d=>{d.currentTarget.style.color=t.mutedTextColor,d.currentTarget.style.backgroundColor="transparent",d.currentTarget.style.borderColor="transparent";},onClick:d=>{d.stopPropagation(),ht(a.id),lt(B=>B+1);},children:jsxRuntime.jsx(iconsReact.IconTrash,{size:16,stroke:2})})]})},a.id))})})()})]})]});return typeof document<"u"&&document.body?reactDom.createPortal(e,document.body):e})(),!w&&jsxRuntime.jsx("button",{"aria-label":"Close chat",style:{backgroundColor:"transparent",color:t.mutedTextColor,border:"none",borderRadius:"8px",padding:"8px",cursor:"pointer",transition:"all 0.2s ease-out",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor=t.hoverBackground,e.currentTarget.style.color=t.textColor;},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="transparent",e.currentTarget.style.color=t.mutedTextColor;},onClick:()=>xe(false),children:jsxRuntime.jsx(iconsReact.IconChevronRight,{size:20,stroke:2,style:{transform:f==="rtl"?"rotate(180deg)":"none"}})})]})]}),jsxRuntime.jsxs("div",{className:"chat-scroll-container",style:{flex:"1",overflowY:"auto",overflowX:"hidden",padding:"16px 4px 16px 4px",display:"flex",flexDirection:"column",gap:"16px",scrollBehavior:"smooth"},ref:pt,onScroll:e=>{let n=e.currentTarget,i=n.scrollHeight-(n.scrollTop+n.clientHeight)<=64;i!==Te&&gt(i);},children:[De&&jsxRuntime.jsx("div",{style:{margin:"0 8px",borderRadius:"12px",backgroundColor:"rgba(239, 68, 68, 0.1)",color:"#fca5a5",border:"1px solid rgba(239, 68, 68, 0.3)",padding:"12px",fontSize:"14px"},children:De}),A.length===0&&!y&&jsxRuntime.jsx("div",{style:{margin:"0 8px",borderRadius:"12px",padding:"16px",border:`1px solid ${t.borderColor}`,backgroundColor:t.accentColor,color:t.mutedTextColor},children:"Start by sending a message to the agent."}),jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:A.map((e,n)=>jsxRuntime.jsx("div",{style:{padding:"0 4px"},children:e.role==="user"?dt===e.id?jsxRuntime.jsxs("div",{style:{maxWidth:"720px",borderRadius:"16px",padding:"8px",fontSize:"15px",border:`2px solid ${t.primaryColor}`,backgroundColor:t.accentColor,color:t.textColor},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((be||e.text).length/60))),value:be,onChange:r=>je(r.target.value),onKeyDown:r=>{r.key==="Escape"?ye(null):r.key==="Enter"&&!r.shiftKey&&(r.preventDefault(),y||Le(e.id,be||e.text));}}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:"8px",padding:"8px 8px 8px 0"},children:[jsxRuntime.jsx("button",{style:{borderRadius:"8px",padding:"4px 12px",fontSize:"14px",transition:"background-color 0.2s",border:`1px solid ${t.borderColor}`,color:t.mutedTextColor,backgroundColor:"transparent",cursor:"pointer"},onMouseEnter:r=>r.currentTarget.style.backgroundColor=t.inputBackground,onMouseLeave:r=>r.currentTarget.style.backgroundColor="transparent",onClick:()=>ye(null),children:"Cancel"}),jsxRuntime.jsx("button",{style:{borderRadius:"8px",padding:"4px 12px",fontSize:"14px",transition:"border-color 0.2s",border:`1px solid ${t.borderColor}`,backgroundColor:t.cardBackground,color:t.textColor,cursor:"pointer"},onMouseEnter:r=>r.currentTarget.style.borderColor=t.primaryColor,onMouseLeave:r=>r.currentTarget.style.borderColor=t.borderColor,onClick:()=>{y||Le(e.id,be||e.text);},children:"Save"})]})]}):jsxRuntime.jsx("div",{title:"Click to edit",onClick:()=>{y||(ye(e.id),je(e.text));},style:{maxWidth:"720px",borderRadius:"16px",padding:"16px",fontSize:"15px",lineHeight:"1.6",whiteSpace:"pre-wrap",cursor:"pointer",transition:"background-color 0.2s",backgroundColor:t.accentColor,color:t.textColor},onMouseEnter:r=>r.currentTarget.style.backgroundColor=t.hoverBackground,onMouseLeave:r=>r.currentTarget.style.backgroundColor=t.accentColor,children:e.text}):jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e.reasoning&&jsxRuntime.jsxs("div",{style:{borderRadius:"12px",padding:"12px",cursor:"pointer",backgroundColor:t.inputBackground,border:`1px solid ${t.borderColor}`},onClick:()=>{Se.current=true,M(r=>r.map(a=>a.id===e.id&&a.role==="assistant"?{...a,reasoningOpen:!a.reasoningOpen}:a));},children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"4px"},children:[jsxRuntime.jsx("div",{style:{fontSize:"12px",color:t.mutedTextColor},children:"Reasoning"}),jsxRuntime.jsx("button",{type:"button",style:{fontSize:"12px",transition:"color 0.2s",color:t.mutedTextColor,background:"none",border:"none",cursor:"pointer"},onMouseEnter:r=>r.currentTarget.style.color=t.textColor,onMouseLeave:r=>r.currentTarget.style.color=t.mutedTextColor,children:e.reasoningOpen?"Hide":"Show full"})]}),e.reasoningOpen?jsxRuntime.jsx("pre",{style:{fontSize:"12px",whiteSpace:"pre-wrap",wordBreak:"break-word",color:t.mutedTextColor,margin:"0",fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace'},children:e.reasoning}):(()=>{let r=(e.reasoning||"").trim().split(`
4
+ `).filter(i=>i.trim()),a=r.length>0?r[r.length-1]:"";return jsxRuntime.jsx("pre",{style:{fontSize:"12px",whiteSpace:"pre-wrap",wordBreak:"break-word",color:t.mutedTextColor,margin:"0",fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace'},children:a||"\u2026"})})()]}),kt(e.items),y&&n===A.length-1&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"12px",color:t.mutedTextColor},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",height:"8px",width:"8px",borderRadius:"50%",backgroundColor:t.mutedTextColor,animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"}}),jsxRuntime.jsx("span",{children:"Working\u2026"})]})]})},e.id))}),jsxRuntime.jsx("div",{ref:We})]}),jsxRuntime.jsx("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px",paddingTop:"4px",backgroundColor:t.backgroundColor},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 ${t.borderColor}`,backgroundColor:t.accentColor},children:[jsxRuntime.jsx("div",{style:{padding:"0 16px"},children:jsxRuntime.jsx("textarea",{"aria-label":"Prompt",rows:2,style:{height:"auto",width:"100%",resize:"none",backgroundColor:"transparent",fontSize:"15px",lineHeight:"1.6",outline:"none",border:"none",color:t.textColor,fontFamily:"inherit"},placeholder:rt,value:ie,onChange:e=>Ne(e.target.value),onKeyDown:e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),y||Ke());},ref:ut})}),jsxRuntime.jsxs("div",{style:{position:"absolute",bottom:"8px",left:"8px",display:"flex",alignItems:"center",gap:"4px",color:t.mutedTextColor},children:[jsxRuntime.jsx("button",{style:{borderRadius:"8px",padding:"8px",transition:"all 0.2s",backgroundColor:"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"inherit"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor=`${t.backgroundColor}99`,e.currentTarget.style.color=t.textColor;},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="transparent",e.currentTarget.style.color=t.mutedTextColor;},"aria-label":"Attach files",children:jsxRuntime.jsx(iconsReact.IconPaperclip,{size:18,stroke:2})}),jsxRuntime.jsx("button",{style:{borderRadius:"8px",padding:"8px",transition:"all 0.2s",backgroundColor:"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"inherit"},onMouseEnter:e=>{e.currentTarget.style.backgroundColor=`${t.backgroundColor}99`,e.currentTarget.style.color=t.textColor;},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="transparent",e.currentTarget.style.color=t.mutedTextColor;},"aria-label":"Insert link",children:jsxRuntime.jsx(iconsReact.IconLink,{size:18,stroke:2})})]}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"8px",right:"8px"},children:jsxRuntime.jsx("button",{"aria-label":y?"Stop":"Send",disabled:!y&&!ie.trim(),style:{borderRadius:"12px",padding:"12px",transition:"all 0.2s ease-out",border:`1px solid ${y?"#ef4444":t.borderColor}`,backgroundColor:y?"#ef444420":t.cardBackground,color:y?"#ef4444":t.mutedTextColor,opacity:!y&&!ie.trim()?.4:1,cursor:!y&&!ie.trim()?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:e=>{e.currentTarget.disabled||(y?(e.currentTarget.style.borderColor="#dc2626",e.currentTarget.style.backgroundColor="#dc262630",e.currentTarget.style.color="#dc2626"):(e.currentTarget.style.borderColor=t.primaryColor,e.currentTarget.style.backgroundColor=t.hoverBackground,e.currentTarget.style.color=t.textColor));},onMouseLeave:e=>{e.currentTarget.disabled||(y?(e.currentTarget.style.borderColor="#ef4444",e.currentTarget.style.backgroundColor="#ef444420",e.currentTarget.style.color="#ef4444"):(e.currentTarget.style.borderColor=t.borderColor,e.currentTarget.style.backgroundColor=t.cardBackground,e.currentTarget.style.color=t.mutedTextColor));},onClick:()=>{y?Ct():Ke();},children:y?jsxRuntime.jsx(iconsReact.IconPlayerStop,{size:18,stroke:2}):jsxRuntime.jsx(iconsReact.IconArrowUp,{size:18,stroke:2})})})]})})})]}),!V&&!w&&jsxRuntime.jsx("button",{"aria-label":"Open chat",onClick:()=>xe(true),style:{...Tt,borderColor:t.borderColor,backgroundColor:t.accentColor,color:t.textColor,borderRadius:"50%",border:`1px solid ${t.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:e=>{e.currentTarget.style.borderColor=t.primaryColor,e.currentTarget.style.backgroundColor=`${t.accentColor}dd`;},onMouseLeave:e=>{e.currentTarget.style.borderColor=t.borderColor,e.currentTarget.style.backgroundColor=t.accentColor;},children:jsxRuntime.jsx(iconsReact.IconMessage,{size:20,stroke:2})}),jsxRuntime.jsx("style",{children:`
5
+ /* Import Rubik font from Google Fonts */
6
+ @import url('https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300..900;1,300..900&display=swap');
7
+
8
+ @keyframes ${H.current}-border-flow {
6
9
  0% { background-position: 0% 50%; }
7
10
  50% { background-position: 100% 50%; }
8
11
  100% { background-position: 0% 50%; }
9
12
  }
10
-
11
- .tc-animated-border {
12
- position: relative;
13
- /* Animated shimmer border using primary color */
14
- background: linear-gradient(120deg,
15
- ${t.primaryColor}dd 0%,
16
- ${t.primaryColor}88 25%,
17
- ${t.primaryColor}00 50%,
18
- ${t.primaryColor}88 75%,
19
- ${t.primaryColor}dd 100%
20
- );
21
- background-size: 300% 300%;
22
- animation: tc-border-flow 3s ease-in-out infinite;
23
- filter: drop-shadow(0 0 10px ${t.primaryColor}40);
24
- }
25
-
26
- .hsafa-chat-textarea::placeholder {
13
+
14
+ @keyframes pulse {
15
+ 0%, 100% { opacity: 1; }
16
+ 50% { opacity: 0.5; }
17
+ }
18
+
19
+ @keyframes spin {
20
+ from { transform: rotate(0deg); }
21
+ to { transform: rotate(360deg); }
22
+ }
23
+
24
+ /* Scoped placeholder styles */
25
+ [data-hsafa-chat="${H.current}"] textarea::placeholder {
27
26
  color: ${t.mutedTextColor};
28
27
  }
29
- `})]})}exports.Button=er;exports.HsafaChat=Xt;exports.HsafaProvider=Et;exports.useAutoScroll=lr;exports.useHsafa=ee;exports.useHsafaAction=mr;exports.useHsafaComponent=Cr;exports.useToggle=nr;//# sourceMappingURL=index.cjs.map
28
+
29
+ /* Ensure textarea styles work in all environments */
30
+ [data-hsafa-chat="${H.current}"] textarea {
31
+ background: transparent !important;
32
+ border: none !important;
33
+ outline: none !important;
34
+ resize: none !important;
35
+ font-family: inherit !important;
36
+ }
37
+
38
+ /* Custom scrollbar styles for content container */
39
+ [data-hsafa-chat="${H.current}"] .content-container::-webkit-scrollbar {
40
+ width: 6px;
41
+ }
42
+
43
+ [data-hsafa-chat="${H.current}"] .content-container::-webkit-scrollbar-track {
44
+ background: transparent;
45
+ border-radius: 3px;
46
+ }
47
+
48
+ [data-hsafa-chat="${H.current}"] .content-container::-webkit-scrollbar-thumb {
49
+ background: ${t.mutedTextColor}40;
50
+ border-radius: 3px;
51
+ border: 1px solid transparent;
52
+ }
53
+
54
+ [data-hsafa-chat="${H.current}"] .content-container::-webkit-scrollbar-thumb:hover {
55
+ background: ${t.mutedTextColor}60;
56
+ }
57
+
58
+ /* Chat scrollbar styles */
59
+ [data-hsafa-chat="${H.current}"] .chat-scroll-container::-webkit-scrollbar {
60
+ width: 4px;
61
+ }
62
+
63
+ [data-hsafa-chat="${H.current}"] .chat-scroll-container::-webkit-scrollbar-track {
64
+ background: transparent;
65
+ }
66
+
67
+ [data-hsafa-chat="${H.current}"] .chat-scroll-container::-webkit-scrollbar-thumb {
68
+ background: ${t.borderColor};
69
+ border-radius: 2px;
70
+ }
71
+
72
+ [data-hsafa-chat="${H.current}"] .chat-scroll-container::-webkit-scrollbar-thumb:hover {
73
+ background: ${t.mutedTextColor};
74
+ }
75
+
76
+ /* Ensure all fixed positioned elements stay within content box */
77
+ [data-hsafa-chat="${H.current}"] * {
78
+ /* Prevent any child from breaking out of the content container */
79
+ }
80
+
81
+ /* Force fixed elements to be contained within the content box */
82
+ [data-hsafa-chat="${H.current}"] .content-container * {
83
+ /* Any fixed, absolute, or sticky elements will be contained */
84
+ max-width: 100% !important;
85
+ }
86
+ `})]})}exports.Button=tr;exports.HsafaChat=Yt;exports.HsafaProvider=zt;exports.useAutoScroll=lr;exports.useHsafa=re;exports.useHsafaAction=yr;exports.useHsafaComponent=Cr;exports.useToggle=ar;//# sourceMappingURL=index.cjs.map
30
87
  //# sourceMappingURL=index.cjs.map