@hsafa/ui-sdk 0.1.1 → 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 +51 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +51 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
'use strict';var jsxRuntime=require('react/jsx-runtime'),react=require('react'),reactDom=require('react-dom'),iconsReact=require('@tabler/icons-react');var
|
|
2
|
-
`))!==-1;){let
|
|
3
|
-
`))!==-1;){let q=P.slice(0,F).trim();if(P=P.slice(F+1),!!q)try{let x=JSON.parse(q);if(x?.type==="meta"){if(x.actionExecuteMap&&typeof x.actionExecuteMap=="object"&&(Me.current=x.actionExecuteMap),x.assistantMessageId&&(ae.current=String(x.assistantMessageId),be.current.clear(),me.current.clear(),Z.current.clear(),se(new Map)),x.chatId&&!w){_(x.chatId),O.current=!0;let B=e,l=(X.current||B||"New chat").slice(0,80),i=Date.now();de({id:x.chatId,title:l,createdAt:i,updatedAt:i}),ce({id:x.chatId,messages:d,agentId:s});try{localStorage.setItem(W,x.chatId);}catch{}}continue}if(x?.type==="reasoning"){let B=String(x.text??"");T(l=>l.map(i=>i.id===r&&i.role==="assistant"?{...i,reasoning:(i.reasoning??"")+B}:i));continue}if(x?.type==="partial"||x?.type==="final"){let B=x.value;B&&Array.isArray(B.items)&&(T(l=>l.map(i=>i.id===r&&i.role==="assistant"?{...i,items:B.items}:i)),Je(B.items,x.type==="partial"?"partial":"final")),x?.type==="final"&&T(l=>l.map(i=>i.id===r&&i.role==="assistant"?{...i,reasoningOpen:!1}:i));continue}if(x?.type==="usage"){let B=x?.value?.reasoningTokens;typeof B=="number"&&T(l=>l.map(i=>i.id===r&&i.role==="assistant"?{...i,reasoningTokens:B}:i));continue}if(x?.type==="error"){U(String(x.error??"Unknown error"));continue}}catch{}}}}catch(v){U(String(v?.message??v));}finally{if(ne(false),!w&&!O.current){let v=`local-${ue()}`;_(v),O.current=true;let p=(X.current||"New chat").slice(0,80),E=Date.now();de({id:v,title:p,createdAt:E,updatedAt:E}),ce({id:v,messages:I,agentId:s});try{localStorage.setItem(W,v);}catch{}}}}function vt(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 c=`${String(n.name??"action")}:${r}`,d=yt.get(c);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 c=String(n.name??n.component??"").trim(),d=c?at.get(c):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:c||"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 J=Xt[g],t={primaryColor:b||J.primaryColor,backgroundColor:A||J.backgroundColor,borderColor:S||J.borderColor,textColor:L||J.textColor,accentColor:j||J.accentColor,mutedTextColor:J.mutedTextColor,inputBackground:J.inputBackground,cardBackground:J.cardBackground,hoverBackground:J.hoverBackground},kt={backgroundColor:t.backgroundColor,color:t.textColor,height:pe,display:"flex",width:"100%",fontFamily:'ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif'},wt={width:typeof Y=="number"?`${Y}px`:Y,maxWidth:typeof re=="number"?`${re}px`:re,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},Re=typeof ve=="number"?`${ve}px`:ve,G=react.useRef(`hsafa-chat-${Date.now()}-${Math.random().toString(36).slice(2,8)}`);return jsxRuntime.jsxs("div",{className:ot,style:kt,dir:f,"data-hsafa-chat":G.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?Re:"0"},children:V&&Ae?jsxRuntime.jsx("div",{style:{width:"100%",height:"100%",transition:"all 0.3s ease-out",borderRadius:Re,border:y&&oe?"none":`1px solid ${t.borderColor}`,padding:y&&oe?"1.5px":"0",background:y&&oe?`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&&oe?"300% 300%":"auto",animation:y&&oe?`${G.current}-border-flow 3s ease-in-out infinite`:"none",filter:y&&oe?`drop-shadow(0 0 10px ${t.primaryColor}40)`:"none"},children:jsxRuntime.jsx("div",{className:"content-container",style:{width:"100%",height:"100%",borderRadius:Re,backgroundColor:t.backgroundColor,overflow:"hidden",position:"relative",isolation:"isolate",contain:"layout style paint",transform:"translateZ(0)"},children:u})}):jsxRuntime.jsx("div",{className:"content-container",style:{width:"100%",height:"100%",position:"relative",isolation:"isolate",contain:"layout style paint",transform:"translateZ(0)",overflow:"hidden"},children:u})})}),jsxRuntime.jsxs("div",{className:nt,style:{...wt,height:pe,backgroundColor:V||k?t.backgroundColor:"transparent",...V||k?Pe&&M?{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:[M&&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:()=>{fe(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){T([]),U(null),_(null),O.current=false,X.current=null;try{localStorage.removeItem(W);}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=Ie();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,c)=>jsxRuntime.jsx("div",{style:{borderTop:c>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===w?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=Ke(a.id);if(d){_(a.id),O.current=true,T(d.messages||[]);try{localStorage.setItem(W,a.id);}catch{}we(false),fe(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:_t(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(z=>z+1);},children:jsxRuntime.jsx(iconsReact.IconTrash,{size:16,stroke:2})})]})},a.id))})})()})]})]});return typeof document<"u"&&document.body?reactDom.createPortal(e,document.body):e})(),!k&&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:()=>fe(false),children:jsxRuntime.jsx(iconsReact.IconChevronRight,{size:20,stroke:2,style:{transform:f==="rtl"?"rotate(180deg)":"none"}})})]})]}),jsxRuntime.jsxs("div",{style:{flex:"1",overflowY:"auto",padding:"16px 4px 16px 4px",display:"flex",flexDirection:"column",gap:"16px"},ref:pt,onScroll:e=>{let n=e.currentTarget,c=n.scrollHeight-(n.scrollTop+n.clientHeight)<=64;c!==Te&>(c);},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}),I.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:I.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((ye||e.text).length/60))),value:ye,onChange:r=>je(r.target.value),onKeyDown:r=>{r.key==="Escape"?xe(null):r.key==="Enter"&&!r.shiftKey&&(r.preventDefault(),y||Le(e.id,ye||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:()=>xe(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,ye||e.text);},children:"Save"})]})]}):jsxRuntime.jsx("div",{title:"Click to edit",onClick:()=>{y||(xe(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,T(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(
|
|
5
|
-
|
|
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&>(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%; }
|
|
@@ -19,12 +22,12 @@
|
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
/* Scoped placeholder styles */
|
|
22
|
-
[data-hsafa-chat="${
|
|
25
|
+
[data-hsafa-chat="${H.current}"] textarea::placeholder {
|
|
23
26
|
color: ${t.mutedTextColor};
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
/* Ensure textarea styles work in all environments */
|
|
27
|
-
[data-hsafa-chat="${
|
|
30
|
+
[data-hsafa-chat="${H.current}"] textarea {
|
|
28
31
|
background: transparent !important;
|
|
29
32
|
border: none !important;
|
|
30
33
|
outline: none !important;
|
|
@@ -32,15 +35,53 @@
|
|
|
32
35
|
font-family: inherit !important;
|
|
33
36
|
}
|
|
34
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
|
+
|
|
35
76
|
/* Ensure all fixed positioned elements stay within content box */
|
|
36
|
-
[data-hsafa-chat="${
|
|
77
|
+
[data-hsafa-chat="${H.current}"] * {
|
|
37
78
|
/* Prevent any child from breaking out of the content container */
|
|
38
79
|
}
|
|
39
80
|
|
|
40
81
|
/* Force fixed elements to be contained within the content box */
|
|
41
|
-
[data-hsafa-chat="${
|
|
82
|
+
[data-hsafa-chat="${H.current}"] .content-container * {
|
|
42
83
|
/* Any fixed, absolute, or sticky elements will be contained */
|
|
43
84
|
max-width: 100% !important;
|
|
44
85
|
}
|
|
45
|
-
`})]})}exports.Button=tr;exports.HsafaChat=Yt;exports.HsafaProvider=
|
|
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
|
|
46
87
|
//# sourceMappingURL=index.cjs.map
|