@hsafa/ui-sdk 0.6.1 → 0.6.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/DOCUMENTATION.md +17 -0
- package/dist/index.cjs +9 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -1
- package/dist/index.d.ts +37 -1
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/docs/README.md +22 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var jsxRuntime=require('react/jsx-runtime'),xMarkdown=require('@ant-design/x-markdown');require('@ant-design/x-markdown/themes/light.css'),require('@ant-design/x-markdown/themes/dark.css');var
|
|
1
|
+
'use strict';var jsxRuntime=require('react/jsx-runtime'),xMarkdown=require('@ant-design/x-markdown');require('@ant-design/x-markdown/themes/light.css'),require('@ant-design/x-markdown/themes/dark.css');var To=require('react'),react=require('@ai-sdk/react'),ai=require('ai'),client=require('react-dom/client'),reactDom=require('react-dom'),lucideReact=require('lucide-react');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var To__default=/*#__PURE__*/_interopDefault(To);var Re={};var na=({variant:e="primary",size:t="md",loading:r=false,disabled:n,children:o,className:s,...g})=>{let u=[Re.button,Re[e],Re[t],r&&Re.loading,s].filter(Boolean).join(" ");return jsxRuntime.jsxs("button",{className:u,disabled:n||r,...g,children:[r&&jsxRuntime.jsx("span",{className:Re.spinner}),jsxRuntime.jsx("span",{className:r?Re.hiddenText:void 0,children:o})]})};function Nr({show:e,onClick:t,resolvedColors:r,floatingButtonPosition:n}){if(!e)return null;let o={position:"fixed",bottom:typeof n.bottom=="number"?`${n.bottom}px`:n.bottom,right:n.right?typeof n.right=="number"?`${n.right}px`:n.right:void 0,top:n.top?typeof n.top=="number"?`${n.top}px`:n.top:void 0,left:n.left?typeof n.left=="number"?`${n.left}px`:n.left:void 0,zIndex:1e3};return jsxRuntime.jsx("button",{"aria-label":"Open chat",onClick:t,style:{...o,borderColor:r.borderColor,backgroundColor:r.accentColor,color:r.textColor,borderRadius:"50%",border:`1px solid ${r.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:s=>{s.currentTarget.style.borderColor=r.primaryColor,s.currentTarget.style.backgroundColor=`${r.accentColor}dd`;},onMouseLeave:s=>{s.currentTarget.style.borderColor=r.borderColor,s.currentTarget.style.backgroundColor=r.accentColor;},children:jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})})}function Be({content:e,theme:t="dark",streaming:r=false,dir:n="ltr"}){return jsxRuntime.jsxs("div",{dir:n,className:"x-markdown-wrapper",style:{width:"100%",maxWidth:"100%"},children:[jsxRuntime.jsx(xMarkdown.XMarkdown,{content:e,className:t==="dark"?"x-markdown-dark":"x-markdown-light",streaming:{hasNextChunk:r,enableAnimation:true,animationConfig:{fadeDuration:200},incompleteMarkdownComponentMap:{html:"IncompleteBlock",link:"IncompleteBlock",image:"IncompleteBlock"}},openLinksInNewTab:true,config:{gfm:true},dompurifyConfig:{ADD_TAGS:["data-chart","welcome","user-card","mermaid"],ADD_ATTR:["data-source","data-spec","data-icon","data-description","data-raw"]},style:{fontSize:"14px",lineHeight:"1.6",wordBreak:"break-word",maxWidth:"100%",overflow:"hidden",direction:n,width:"100%"}}),jsxRuntime.jsx("style",{children:`
|
|
2
2
|
/* Ensure tables take full width */
|
|
3
3
|
.x-markdown-wrapper table,
|
|
4
4
|
.x-markdown-dark table,
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
display: table-cell !important;
|
|
31
31
|
box-sizing: border-box !important;
|
|
32
32
|
}
|
|
33
|
-
`}),
|
|
33
|
+
`}),n==="rtl"&&jsxRuntime.jsx("style",{children:`
|
|
34
34
|
/* Lists */
|
|
35
35
|
[dir="rtl"] ul,
|
|
36
36
|
[dir="rtl"] ol {
|
|
@@ -156,7 +156,7 @@
|
|
|
156
156
|
[dir="rtl"] summary {
|
|
157
157
|
text-align: right;
|
|
158
158
|
}
|
|
159
|
-
`})]})}function Ar(e=true){let t=pn.useRef(null),r=pn.useRef(e);return pn.useEffect(()=>{r.current=e;},[e]),pn.useEffect(()=>{let o=t.current;if(!o)return;let n=new MutationObserver(()=>{r.current&&(o.scrollTop=o.scrollHeight);});return n.observe(o,{childList:true,subtree:true}),r.current&&(o.scrollTop=o.scrollHeight),()=>n.disconnect()},[]),t}function Lr(e,t){if(!e)return t;let r=e.endsWith("/")?e.slice(0,-1):e,o=t.startsWith("/")?t:`/${t}`;return `${r}${o}`}var Hr=pn.createContext(void 0);function Tn({baseUrl:e,dir:t="ltr",theme:r="dark",children:o}){let[n,s]=pn.useState(new Map),[m,u]=pn.useState(new Map),[C,S]=pn.useState(new Map),[x,M]=pn.useState(new Map),[k,f]=pn.useState(void 0),i=pn.useCallback((v,y)=>(s(E=>{let p=new Map(E);return p.set(String(v),y),p}),()=>{s(E=>{let p=new Map(E),F=p.get(String(v));return (!y||F===y)&&p.delete(String(v)),p});}),[]),b=pn.useCallback((v,y)=>{s(E=>{let p=new Map(E),F=p.get(String(v));return (!y||F===y)&&p.delete(String(v)),p});},[]),c=pn.useCallback((v,y)=>(u(E=>{let p=new Map(E);return p.set(String(v),y),p}),()=>{u(E=>{let p=new Map(E),F=p.get(String(v));return (!y||F===y)&&p.delete(String(v)),p});}),[]),d=pn.useCallback((v,y)=>{u(E=>{let p=new Map(E),F=p.get(String(v));return (!y||F===y)&&p.delete(String(v)),p});},[]),h=pn.useCallback((v,y)=>{S(E=>{let p=new Map(E);return y?p.set(v,true):p.delete(v),p});},[]),l=pn.useCallback((v,y)=>{M(E=>{let p=new Map(E);return p.set(v,y),p});},[]),a=pn.useMemo(()=>Array.from(C.values()).some(v=>v),[C]),T=pn.useMemo(()=>Array.from(x.values()).some(v=>v),[x]),w=pn.useMemo(()=>({baseUrl:e,dir:t,theme:r,actions:n,components:m,registerAction:i,unregisterAction:b,registerComponent:c,unregisterComponent:d,isAnyStreaming:a,setStreamingState:h,isAnyChatOpen:T,setChatOpenState:l,currentChatId:k,setCurrentChatId:f}),[e,t,r,n,m,i,b,c,d,a,h,T,l,k]);return jsxRuntime.jsx(Hr.Provider,{value:w,children:o})}function ie(){let e=pn.useContext(Hr);return e||{baseUrl:void 0,actions:new Map,components:new Map,registerAction:()=>()=>{},unregisterAction:()=>{},registerComponent:()=>()=>{},unregisterComponent:()=>{},isAnyStreaming:false,setStreamingState:()=>{},isAnyChatOpen:false,setChatOpenState:()=>{},currentChatId:void 0,setCurrentChatId:()=>{}}}var Bt=25*1024*1024;function Br(e){let{baseUrl:t}=ie(),r=e||t||"",[o,n]=pn.useState([]),[s,m]=pn.useState(false),u=pn.useRef(null),C=pn.useCallback(i=>{if(!i||Number.isNaN(i))return "0 B";let b=["B","KB","MB","GB","TB"],c=Math.min(b.length-1,Math.floor(Math.log(i)/Math.log(1024)));return `${(i/Math.pow(1024,c)).toFixed(c===0?0:1)} ${b[c]}`},[]),S=pn.useCallback(async i=>{let b=new FormData;b.append("file",i);let c=await fetch(Lr(r,"/api/uploads"),{method:"POST",body:b});if(!c.ok){let h=await c.text().catch(()=>"");throw new Error(h||`Failed to upload ${i.name}`)}let d=await c.json();return {id:d.id,name:d.name||i.name,url:d.url,mimeType:d.mimeType||i.type||"application/octet-stream",size:typeof d.size=="number"?d.size:i.size}},[r]),x=pn.useCallback(i=>{n(b=>b.filter(c=>c.id!==i));},[]),M=pn.useCallback(async(i,b)=>{if(!i)return;let c=Array.isArray(i)?i:Array.from(i);b(null),m(true);let d=[];try{for(let h of c){if(h.size>Bt){b(`"${h.name}" exceeds the ${C(Bt)} limit.`);continue}try{let l=await S(h);d.push(l);}catch(l){console.error("Failed to upload attachment:",l),b(String(l?.message??`Failed to upload ${h.name}`));}}d.length&&n(h=>[...h,...d]);}finally{m(false);}},[S,C]),k=pn.useCallback((i,b)=>{let c=[],d=(i||"").trim();d&&c.push({type:"text",text:d});for(let h of b||[]){let l=h.mimeType||"application/octet-stream";l.startsWith("image/")?c.push({type:"image",image:new URL(h.url),mediaType:l}):c.push({type:"file",data:h.url,mediaType:l,name:h.name});}return c},[]),f=pn.useCallback(()=>{n([]);},[]);return {attachments:o,uploading:s,fileInputRef:u,formatBytes:C,handleRemoveAttachment:x,handleFileSelection:M,buildUserContent:k,clearAttachments:f,setAttachments:n,MAX_UPLOAD_SIZE:Bt}}function Dr(e,t,r,o){return console.log("\u{1F680} [SDK] createHsafaTransport called with templateParams:",o),new ai.DefaultChatTransport({api:`${e}/api/run/${t}`,fetch:async(n,s)=>{let m=s||{},u=m?.body?JSON.parse(m.body):{},C=o&&typeof o=="object"?o:{};console.log("\u{1F680} [SDK] Before merge - body:",u),console.log("\u{1F680} [SDK] Before merge - mergedParams:",C);let S={...C,...u,chatId:r};return console.log("\u{1F680} [SDK] After merge - enhancedBody:",S),fetch(n,{...s,body:JSON.stringify(S)})}})}function En(e){if(!(e instanceof HTMLElement))return true;let t=window.getComputedStyle(e);return t.display!=="none"&&t.visibility!=="hidden"&&t.opacity!=="0"&&e.offsetParent!==null}function Rn(e){if(e.id){let r=document.querySelector(`label[for="${e.id}"]`);if(r)return r.textContent?.trim()}let t=e.closest("label");if(t){let r=t.cloneNode(true),o=r.querySelector("input, select, textarea");return o&&o.remove(),r.textContent?.trim()}}function Dt(e){if(e.textContent&&e.textContent.trim())return e.textContent.trim().slice(0,100)}function Pt(e){if(e instanceof HTMLInputElement){let t=e.type.toLowerCase();return t==="checkbox"||t==="radio"?e.checked:e.value}if(e instanceof HTMLTextAreaElement)return e.value;if(e instanceof HTMLSelectElement)return e.multiple?Array.from(e.selectedOptions).map(t=>t.value):e.value;if(e instanceof HTMLElement&&e.isContentEditable)return e.textContent||void 0}function An(e){if(e.id)return `#${e.id}`;let t=[],r=e;for(;r&&r!==document.body;){let o=r.tagName.toLowerCase();if(r.className&&typeof r.className=="string"){let s=r.className.split(" ").filter(m=>m.trim()).slice(0,2);s.length>0&&(o+="."+s.join("."));}let n=r.parentElement;if(n){let s=Array.from(n.children).filter(m=>m.tagName===r.tagName);if(s.length>1){let m=s.indexOf(r)+1;o+=`:nth-child(${m})`;}}t.unshift(o),r=n;}return t.slice(-3).join(" > ")}async function Xe(e={}){try{let{includeHidden:t=!1,selector:r,what:o="content",limit:n}=e,s=document.querySelector(".hsafa-content-container");if(!s)return {ok:!1,components:[],count:0,total:0,containerFound:!1,error:"ContentContainer not found on page. Make sure you have wrapped your app with <ContentContainer>."};let m=r&&s.querySelector(r)||s,u=[],C=[];o==="inputs"?C=["input","textarea","select",'[contenteditable="true"]','[contenteditable=""]']:C=["header","nav","main","section","article","aside","footer","h1","h2","h3","h4","h5","h6","p","img[alt]","ul","ol","li","table","thead","tbody","tr","td","th","form","label","input","textarea","select",'[contenteditable="true"]','[contenteditable=""]',"a[href]","button",'[role="button"]','[role="link"]',"[onclick]","[tabindex]","div"],m.querySelectorAll(C.join(", ")).forEach(c=>{let d=En(c);if(!d&&!t)return;let h={id:c.id||null,tag:c.tagName.toLowerCase(),className:c.className&&typeof c.className=="string"?c.className:void 0,isVisible:d,isInteractive:!0,selector:An(c)};c instanceof HTMLInputElement?(h.type=c.type,h.name=c.name||void 0,h.placeholder=c.placeholder||void 0,h.value=Pt(c),h.checked=c.type==="checkbox"||c.type==="radio"?c.checked:void 0,h.disabled=c.disabled,h.required=c.required):c instanceof HTMLTextAreaElement?(h.name=c.name||void 0,h.placeholder=c.placeholder||void 0,h.value=Pt(c),h.disabled=c.disabled,h.required=c.required):c instanceof HTMLSelectElement?(h.name=c.name||void 0,h.value=Pt(c),h.disabled=c.disabled,h.required=c.required,h.options=Array.from(c.options).map(l=>({value:l.value,label:l.text,selected:l.selected,disabled:l.disabled}))):c instanceof HTMLButtonElement?(h.type=c.type,h.disabled=c.disabled,h.text=Dt(c)):c instanceof HTMLAnchorElement?(h.href=c.href,h.text=Dt(c)):c instanceof HTMLImageElement?(h.text=c.alt||void 0,h.label=c.alt||h.label):h.text=Dt(c),h.label=Rn(c),h.role=c.getAttribute("role")||void 0,h.ariaLabel=c.getAttribute("aria-label")||void 0,u.push(h);});let x=c=>c.isVisible?o==="inputs"?c.tag==="input"||c.tag==="textarea"||c.tag==="select"||c.role==="textbox"?3:c.tag==="button"||c.tag==="a"?2:1:["header","nav","main","footer"].includes(c.tag)?5:["section","article","aside"].includes(c.tag)||["h1","h2","h3"].includes(c.tag)?4:["h4","h5","h6"].includes(c.tag)?3:c.tag==="form"?4:c.tag==="label"?3:c.tag==="input"||c.tag==="textarea"||c.tag==="select"?4:c.tag==="p"||c.tag==="img"||c.tag==="button"||c.tag==="a"?3:1:0;u.sort((c,d)=>x(d)-x(c));let M=u.length,f=Math.max(1,Math.min(200,typeof n=="number"?Math.floor(n):o==="inputs"?100:150)),i=M>f,b=i?u.slice(0,f):u;return {ok:!0,components:b,count:b.length,total:M,truncated:i,containerFound:!0}}catch(t){return {ok:false,components:[],count:0,total:0,containerFound:false,error:t?.message||String(t)}}}typeof window<"u"&&(window.getDomComponents=Xe);async function Se(e,t={}){if(typeof window>"u")return {ok:false,steps:[{ok:false,action:"none",targetKind:"position",durationMs:0,error:"guideCursor only works in browser environment"}]};let r=window.__cursorGuide;if(!r)return {ok:false,steps:[{ok:false,action:"none",targetKind:"position",durationMs:0,error:"CursorController not initialized. Make sure to mount <CursorController /> component."}]};try{return await r(e,t)}catch(o){return {ok:false,steps:[{ok:false,action:t.action||"none",targetKind:"position",durationMs:0,error:o?.message||String(o)}]}}}typeof window<"u"&&(window.guideCursor=Se);function Pr(e){return !!e&&e.nodeType===1}function se(e,t){e.dispatchEvent(new Event(t,{bubbles:true}));}function zr(e,t){let r=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(e),"value")?.set;r?r.call(e,t):e.value=t,se(e,"input");}function Ln(e,t){e.checked!==t&&e.click();}function Hn(e,t){if(typeof t=="object"&&t&&"index"in t&&typeof t.index=="number")e.selectedIndex=Math.max(0,Math.min(e.options.length-1,t.index));else if(typeof t=="object"&&t&&"label"in t&&typeof t.label=="string"){let r=Array.from(e.options).findIndex(o=>o.text===t.label);e.selectedIndex=r>=0?r:0;}else e.value=String(t);se(e,"input"),se(e,"change");}function Fn(e,t){let r=new Set(t.map(String));Array.from(e.options).forEach(o=>{o.selected=r.has(o.value)||r.has(o.text);}),se(e,"input"),se(e,"change");}function Bn(e){return e?e instanceof Date?e.toISOString().slice(0,10):String(e):""}function Dn(e,t){let r=Array.isArray(t)?t:[t],o=new DataTransfer;for(let n of r)o.items.add(n);Object.defineProperty(e,"files",{value:o.files,configurable:true}),se(e,"input"),se(e,"change");}async function Ye(e,t={}){let r=document.activeElement||null;if(r&&Pr(r)){let o=r.closest('[contenteditable="true"], [contenteditable=""]');o&&(r=o);}if(!r||r===document.body)return {ok:false,filled:[{key:"active",status:"skipped",message:"No active input element"}],errors:["No active input element"]};try{let o=r.tagName.toLowerCase();if(o==="input"){let n=r,s=(n.type||"text").toLowerCase();if(s==="checkbox")Ln(n,!!e);else if(s==="radio"){let m=n.name;if(m&&e!=null&&String(n.value)!==String(e)){let u=document.querySelector(`input[type="radio"][name="${CSS.escape(m)}"][value="${CSS.escape(String(e))}"]`);u?u.click():n.click();}else n.click();}else if(s==="file")if(e instanceof File||Array.isArray(e)&&e.every(m=>m instanceof File))Dn(n,e);else return {ok:!1,filled:[{key:"active",status:"skipped",message:"Provide File or File[] for file input"}],errors:["Provide File or File[] for file input"]};else {let m=s==="date"?Bn(e):String(e??"");zr(n,m),se(n,"change");}return {ok:!0,filled:[{key:"active",status:"ok"}]}}if(o==="textarea"){let n=r,s=String(e??"");return zr(n,s),se(n,"change"),{ok:!0,filled:[{key:"active",status:"ok"}]}}if(o==="select"){let n=r;return n.multiple?Fn(n,Array.isArray(e)?e:[e]):Hn(n,e),{ok:!0,filled:[{key:"active",status:"ok"}]}}if(Pr(r)&&r.isContentEditable){let n=r;return n.focus(),n.textContent=String(e??""),se(n,"input"),se(n,"change"),n.blur?.(),{ok:!0,filled:[{key:"active",status:"ok"}]}}return {ok:!1,filled:[{key:"active",status:"skipped",message:`Unsupported active element: ${o}`}],errors:[`Unsupported active element: ${o}`]}}catch(o){return {ok:false,filled:[{key:"active",status:"error",message:o?.message??String(o)}],errors:[o?.message??String(o)]}}}typeof window<"u"&&(window.FillActiveInput=Ye);var Je=null,st={},Nr=false,De=null,dt=false;function zt(e){e.classList.add("visible");}function _r(){dt=true,De!=null&&(clearTimeout(De),De=null);}function zn(e,t=1500){dt||(De!=null&&clearTimeout(De),De=window.setTimeout(()=>{dt||e.classList.remove("visible");},t));}function $n(e,t=1200){dt=false,zn(e,t);}function Nn(e){let t=[],r=e?.parentElement;for(;r;){let o=getComputedStyle(r),n=o.overflow+o.overflowY+o.overflowX;/(auto|scroll)/.test(n)&&t.push(r),r=r.parentElement;}return t}async function Wn(e,t=1500,r=160){let o=performance.now(),n=e?Nn(e):[],s=()=>{let x=[window.scrollX||document.documentElement.scrollLeft||0,window.scrollY||document.documentElement.scrollTop||0];return n.forEach(M=>{x.push(M.scrollLeft,M.scrollTop);}),x},m=()=>{if(!e)return {x:0,y:0};let x=e.getBoundingClientRect();return {x:x.left,y:x.top}},u=s(),C=m(),S=performance.now();return new Promise(x=>{function M(k){let f=s(),i=m(),b=false;for(let c=0;c<f.length;c++)if(f[c]!==u[c]){b=true;break}if(!b&&e&&(i.x!==C.x||i.y!==C.y)&&(b=true),b&&(u=f,C=i,S=k),k-S>=r||k-o>=t){x();return}requestAnimationFrame(M);}requestAnimationFrame(M);})}var Un='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="32px" height="32px"><path d="M 7.2304688 4.9863281 C 5.9215232 4.8276681 4.8053213 6.0177722 5.0234375 7.3066406 A 1.0001 1.0001 0 0 0 5.0253906 7.3085938 C 5.9996339 12.981516 7.7205826 18.716222 10 24.515625 A 1.0001 1.0001 0 0 0 10 24.517578 C 10.26886 25.199332 10.914322 25.653844 11.5625 25.738281 C 12.210678 25.822721 12.879213 25.592031 13.359375 25.09375 C 14.505165 23.921134 15.214424 22.695429 15.90625 21.498047 C 17.56565 23.217848 19.256845 24.909775 21.0625 26.484375 L 21.060547 26.480469 C 21.799528 27.12933 22.841378 27.205969 23.673828 26.78125 A 1.0001 1.0001 0 0 0 23.691406 26.771484 C 24.987999 26.077693 26.028685 25.052256 26.71875 23.746094 L 26.71875 23.744141 C 27.174557 22.900924 27.06954 21.854242 26.439453 21.119141 A 1.0001 1.0001 0 0 0 26.433594 21.113281 C 24.867416 19.313474 23.193611 17.633865 21.488281 15.986328 C 22.714141 15.237691 23.933938 14.51508 25.158203 13.414062 A 1.0001 1.0001 0 0 0 25.162109 13.410156 C 26.052979 12.600274 25.977319 11.169141 25.101562 10.404297 A 1.0001 1.0001 0 0 0 24.669922 10.042969 C 18.793373 7.4738953 12.973806 5.6931843 7.2324219 4.9882812 A 1.0001 1.0001 0 0 0 7.2304688 4.9863281 z M 6.9960938 6.9746094 C 12.468883 7.6474978 18.081513 9.3573116 23.796875 11.849609 A 1.0001 1.0001 0 0 0 23.867188 11.884766 C 23.901248 11.899796 23.884276 11.867987 23.816406 11.929688 C 22.403891 13.198979 20.999383 14.076858 19.457031 14.976562 A 1.0001 1.0001 0 0 0 19.275391 16.568359 C 21.250864 18.425305 23.134972 20.36916 24.919922 22.419922 C 25.009402 22.524309 25.024026 22.676488 24.960938 22.792969 A 1.0001 1.0001 0 0 0 24.955078 22.804688 C 24.446951 23.770198 23.730542 24.476149 22.755859 25 C 22.611605 25.06851 22.457885 25.047856 22.378906 24.978516 A 1.0001 1.0001 0 0 0 22.376953 24.976562 C 20.293628 23.159824 18.307991 21.233373 16.419922 19.216797 A 1.0001 1.0001 0 0 0 14.835938 19.378906 C 13.841812 21.004716 13.152668 22.447221 11.925781 23.701172 A 1.0001 1.0001 0 0 0 11.919922 23.707031 C 11.883822 23.744501 11.865156 23.739957 11.847656 23.742188 C 9.6161121 18.057657 7.9395914 12.46667 6.9960938 6.9746094 z"/></svg>',On='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="32px" height="32px"><path d="M 22.5 3 C 19.480226 3 17 5.4802259 17 8.5 L 17 23.412109 L 14.871094 22.697266 C 13.308963 22.172461 11.892528 22 10.703125 22 C 9.5908429 22 8.5540295 22.197475 7.640625 22.65625 C 5.2906802 23.831199 3.9427678 26.197397 4.0019531 28.90625 C 4.0019531 28.90625 4.0019531 28.908203 4.0019531 28.908203 C 4.0019531 28.908203 4.0019531 28.910156 4.0019531 28.910156 C 4.0184171 29.660452 4.4596385 30.354695 5.1328125 30.6875 A 1.50015 1.50015 0 0 0 5.1367188 30.689453 C 5.1367188 30.689453 9.4097266 32.789754 11.599609 33.949219 C 12.445613 34.397848 13.696939 34.926046 15.210938 36.09375 C 16.724935 37.261454 18.423179 39.012543 19.826172 41.792969 C 21.023611 44.165544 23.672779 45.195669 26.144531 44.955078 A 1.50015 1.50015 0 0 0 26.146484 44.955078 C 31.427085 44.439215 32.081856 44.381732 35.59375 44.023438 C 37.044229 43.875625 38.276993 43.213524 39.111328 42.289062 C 39.945663 41.364602 40.422895 40.257718 40.798828 39.125 C 41.561218 36.826116 42.933037 33.169846 43.671875 30.599609 C 45.018525 25.913269 41.884024 21.194549 37.246094 19.953125 L 37.242188 19.951172 C 36.99827 19.885452 36.756736 19.832884 36.521484 19.789062 A 1.50015 1.50015 0 0 0 36.513672 19.787109 L 28 18.248047 L 28 8.5 C 28 5.4802259 25.519774 3 22.5 3 z M 22.5 6 C 23.898226 6 25 7.1017741 25 8.5 L 25 19.5 A 1.50015 1.50015 0 0 0 26.232422 20.976562 L 35.980469 22.740234 C 36.14895 22.771804 36.312663 22.808524 36.464844 22.849609 A 1.50015 1.50015 0 0 0 36.46875 22.849609 C 39.614436 23.689967 41.641993 26.803286 40.789062 29.771484 C 40.115901 32.113248 38.752735 35.768572 37.953125 38.179688 C 37.641059 39.119968 37.279727 39.837554 36.882812 40.277344 C 36.485898 40.717133 36.095584 40.956874 35.289062 41.039062 C 31.783676 41.396695 31.135884 41.452908 25.855469 41.96875 C 24.423221 42.108159 23.024467 41.472831 22.503906 40.441406 C 20.887905 37.238832 18.854971 35.116296 17.042969 33.71875 C 15.230967 32.321204 13.560902 31.594199 13.003906 31.298828 C 10.939171 30.205625 7.8041786 28.665144 7.1035156 28.320312 C 7.1954033 26.8809 7.6810328 25.989859 8.9824219 25.339844 A 1.50015 1.50015 0 0 0 8.9863281 25.337891 C 9.3949198 25.132713 9.9434071 25 10.703125 25 C 11.605722 25 12.680146 25.12582 13.916016 25.541016 L 18.021484 26.921875 A 1.50015 1.50015 0 0 0 20 25.5 L 20 8.5 C 20 7.1017741 21.101774 6 22.5 6 z"/></svg>';async function Gn(){if(!st.arrow)try{st.arrow=Un,st.pointer=On;}catch(e){console.warn("Failed to set cursor SVGs",e);}return st}function Wr({arrowSvg:e,pointerSvg:t}){return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[e&&jsxRuntime.jsx("div",{className:"arrow",dangerouslySetInnerHTML:{__html:e}}),t&&jsxRuntime.jsx("div",{className:"pointer",dangerouslySetInnerHTML:{__html:t}})]})}async function jn(){let e="demo-fake-cursor",t=document.getElementById(e),r=await Gn();if(!Nr){let o="cursor-controller-styles";if(!document.getElementById(o)){let n=document.createElement("style");n.id=o,n.textContent=`
|
|
159
|
+
`})]})}function Or(e=true){let t=To.useRef(null),r=To.useRef(e);return To.useEffect(()=>{r.current=e;},[e]),To.useEffect(()=>{let n=t.current;if(!n)return;let o=new MutationObserver(()=>{r.current&&(n.scrollTop=n.scrollHeight);});return o.observe(n,{childList:true,subtree:true}),r.current&&(n.scrollTop=n.scrollHeight),()=>o.disconnect()},[]),t}function Gr(e,t){if(!e)return t;let r=e.endsWith("/")?e.slice(0,-1):e,n=t.startsWith("/")?t:`/${t}`;return `${r}${n}`}var jr=To.createContext(void 0);function Po({baseUrl:e,dir:t="ltr",theme:r="dark",children:n}){let[o,s]=To.useState(new Map),[g,u]=To.useState(new Map),[C,T]=To.useState(new Map),[y,I]=To.useState(new Map),[k,f]=To.useState(void 0),i=To.useCallback((x,w)=>(s(M=>{let p=new Map(M);return p.set(String(x),w),p}),()=>{s(M=>{let p=new Map(M),F=p.get(String(x));return (!w||F===w)&&p.delete(String(x)),p});}),[]),b=To.useCallback((x,w)=>{s(M=>{let p=new Map(M),F=p.get(String(x));return (!w||F===w)&&p.delete(String(x)),p});},[]),c=To.useCallback((x,w)=>(u(M=>{let p=new Map(M);return p.set(String(x),w),p}),()=>{u(M=>{let p=new Map(M),F=p.get(String(x));return (!w||F===w)&&p.delete(String(x)),p});}),[]),d=To.useCallback((x,w)=>{u(M=>{let p=new Map(M),F=p.get(String(x));return (!w||F===w)&&p.delete(String(x)),p});},[]),h=To.useCallback((x,w)=>{T(M=>{let p=new Map(M);return w?p.set(x,true):p.delete(x),p});},[]),l=To.useCallback((x,w)=>{I(M=>{let p=new Map(M);return p.set(x,w),p});},[]),a=To.useMemo(()=>Array.from(C.values()).some(x=>x),[C]),S=To.useMemo(()=>Array.from(y.values()).some(x=>x),[y]),v=To.useMemo(()=>({baseUrl:e,dir:t,theme:r,actions:o,components:g,registerAction:i,unregisterAction:b,registerComponent:c,unregisterComponent:d,isAnyStreaming:a,setStreamingState:h,isAnyChatOpen:S,setChatOpenState:l,currentChatId:k,setCurrentChatId:f}),[e,t,r,o,g,i,b,c,d,a,h,S,l,k]);return jsxRuntime.jsx(jr.Provider,{value:v,children:n})}function ce(){let e=To.useContext(jr);return e||{baseUrl:void 0,actions:new Map,components:new Map,registerAction:()=>()=>{},unregisterAction:()=>{},registerComponent:()=>()=>{},unregisterComponent:()=>{},isAnyStreaming:false,setStreamingState:()=>{},isAnyChatOpen:false,setChatOpenState:()=>{},currentChatId:void 0,setCurrentChatId:()=>{}}}var Ot=25*1024*1024;function qr(e){let{baseUrl:t}=ce(),r=e||t||"",[n,o]=To.useState([]),[s,g]=To.useState(false),u=To.useRef(null),C=To.useCallback(i=>{if(!i||Number.isNaN(i))return "0 B";let b=["B","KB","MB","GB","TB"],c=Math.min(b.length-1,Math.floor(Math.log(i)/Math.log(1024)));return `${(i/Math.pow(1024,c)).toFixed(c===0?0:1)} ${b[c]}`},[]),T=To.useCallback(async i=>{let b=new FormData;b.append("file",i);let c=await fetch(Gr(r,"/api/uploads"),{method:"POST",body:b});if(!c.ok){let h=await c.text().catch(()=>"");throw new Error(h||`Failed to upload ${i.name}`)}let d=await c.json();return {id:d.id,name:d.name||i.name,url:d.url,mimeType:d.mimeType||i.type||"application/octet-stream",size:typeof d.size=="number"?d.size:i.size}},[r]),y=To.useCallback(i=>{o(b=>b.filter(c=>c.id!==i));},[]),I=To.useCallback(async(i,b)=>{if(!i)return;let c=Array.isArray(i)?i:Array.from(i);b(null),g(true);let d=[];try{for(let h of c){if(h.size>Ot){b(`"${h.name}" exceeds the ${C(Ot)} limit.`);continue}try{let l=await T(h);d.push(l);}catch(l){console.error("Failed to upload attachment:",l),b(String(l?.message??`Failed to upload ${h.name}`));}}d.length&&o(h=>[...h,...d]);}finally{g(false);}},[T,C]),k=To.useCallback((i,b)=>{let c=[],d=(i||"").trim();d&&c.push({type:"text",text:d});for(let h of b||[]){let l=h.mimeType||"application/octet-stream";l.startsWith("image/")?c.push({type:"image",image:new URL(h.url),mediaType:l}):c.push({type:"file",data:h.url,mediaType:l,name:h.name});}return c},[]),f=To.useCallback(()=>{o([]);},[]);return {attachments:n,uploading:s,fileInputRef:u,formatBytes:C,handleRemoveAttachment:y,handleFileSelection:I,buildUserContent:k,clearAttachments:f,setAttachments:o,MAX_UPLOAD_SIZE:Ot}}function Kr(e,t,r,n){return console.log("\u{1F680} [SDK] createHsafaTransport called with templateParams:",n),new ai.DefaultChatTransport({api:`${e}/api/run/${t}`,fetch:async(o,s)=>{let g=s||{},u=g?.body?JSON.parse(g.body):{},C=n&&typeof n=="object"?n:{};console.log("\u{1F680} [SDK] Before merge - body:",u),console.log("\u{1F680} [SDK] Before merge - mergedParams:",C);let T={...C,...u,chatId:r};return console.log("\u{1F680} [SDK] After merge - enhancedBody:",T),fetch(o,{...s,body:JSON.stringify(T)})}})}function Wo(e){if(!(e instanceof HTMLElement))return true;let t=window.getComputedStyle(e);return t.display!=="none"&&t.visibility!=="hidden"&&t.opacity!=="0"&&e.offsetParent!==null}function Uo(e){if(e.id){let r=document.querySelector(`label[for="${e.id}"]`);if(r)return r.textContent?.trim()}let t=e.closest("label");if(t){let r=t.cloneNode(true),n=r.querySelector("input, select, textarea");return n&&n.remove(),r.textContent?.trim()}}function Gt(e){if(e.textContent&&e.textContent.trim())return e.textContent.trim().slice(0,100)}function jt(e){if(e instanceof HTMLInputElement){let t=e.type.toLowerCase();return t==="checkbox"||t==="radio"?e.checked:e.value}if(e instanceof HTMLTextAreaElement)return e.value;if(e instanceof HTMLSelectElement)return e.multiple?Array.from(e.selectedOptions).map(t=>t.value):e.value;if(e instanceof HTMLElement&&e.isContentEditable)return e.textContent||void 0}function Oo(e){if(e.id)return `#${e.id}`;let t=[],r=e;for(;r&&r!==document.body;){let n=r.tagName.toLowerCase();if(r.className&&typeof r.className=="string"){let s=r.className.split(" ").filter(g=>g.trim()).slice(0,2);s.length>0&&(n+="."+s.join("."));}let o=r.parentElement;if(o){let s=Array.from(o.children).filter(g=>g.tagName===r.tagName);if(s.length>1){let g=s.indexOf(r)+1;n+=`:nth-child(${g})`;}}t.unshift(n),r=o;}return t.slice(-3).join(" > ")}async function Ze(e={}){try{let{includeHidden:t=!1,selector:r,what:n="content",limit:o}=e,s=document.querySelector(".hsafa-content-container");if(!s)return {ok:!1,components:[],count:0,total:0,containerFound:!1,error:"ContentContainer not found on page. Make sure you have wrapped your app with <ContentContainer>."};let g=r&&s.querySelector(r)||s,u=[],C=[];n==="inputs"?C=["input","textarea","select",'[contenteditable="true"]','[contenteditable=""]']:C=["header","nav","main","section","article","aside","footer","h1","h2","h3","h4","h5","h6","p","img[alt]","ul","ol","li","table","thead","tbody","tr","td","th","form","label","input","textarea","select",'[contenteditable="true"]','[contenteditable=""]',"a[href]","button",'[role="button"]','[role="link"]',"[onclick]","[tabindex]","div"],g.querySelectorAll(C.join(", ")).forEach(c=>{let d=Wo(c);if(!d&&!t)return;let h={id:c.id||null,tag:c.tagName.toLowerCase(),className:c.className&&typeof c.className=="string"?c.className:void 0,isVisible:d,isInteractive:!0,selector:Oo(c)};c instanceof HTMLInputElement?(h.type=c.type,h.name=c.name||void 0,h.placeholder=c.placeholder||void 0,h.value=jt(c),h.checked=c.type==="checkbox"||c.type==="radio"?c.checked:void 0,h.disabled=c.disabled,h.required=c.required):c instanceof HTMLTextAreaElement?(h.name=c.name||void 0,h.placeholder=c.placeholder||void 0,h.value=jt(c),h.disabled=c.disabled,h.required=c.required):c instanceof HTMLSelectElement?(h.name=c.name||void 0,h.value=jt(c),h.disabled=c.disabled,h.required=c.required,h.options=Array.from(c.options).map(l=>({value:l.value,label:l.text,selected:l.selected,disabled:l.disabled}))):c instanceof HTMLButtonElement?(h.type=c.type,h.disabled=c.disabled,h.text=Gt(c)):c instanceof HTMLAnchorElement?(h.href=c.href,h.text=Gt(c)):c instanceof HTMLImageElement?(h.text=c.alt||void 0,h.label=c.alt||h.label):h.text=Gt(c),h.label=Uo(c),h.role=c.getAttribute("role")||void 0,h.ariaLabel=c.getAttribute("aria-label")||void 0,u.push(h);});let y=c=>c.isVisible?n==="inputs"?c.tag==="input"||c.tag==="textarea"||c.tag==="select"||c.role==="textbox"?3:c.tag==="button"||c.tag==="a"?2:1:["header","nav","main","footer"].includes(c.tag)?5:["section","article","aside"].includes(c.tag)||["h1","h2","h3"].includes(c.tag)?4:["h4","h5","h6"].includes(c.tag)?3:c.tag==="form"?4:c.tag==="label"?3:c.tag==="input"||c.tag==="textarea"||c.tag==="select"?4:c.tag==="p"||c.tag==="img"||c.tag==="button"||c.tag==="a"?3:1:0;u.sort((c,d)=>y(d)-y(c));let I=u.length,f=Math.max(1,Math.min(200,typeof o=="number"?Math.floor(o):n==="inputs"?100:150)),i=I>f,b=i?u.slice(0,f):u;return {ok:!0,components:b,count:b.length,total:I,truncated:i,containerFound:!0}}catch(t){return {ok:false,components:[],count:0,total:0,containerFound:false,error:t?.message||String(t)}}}typeof window<"u"&&(window.getDomComponents=Ze);async function Ae(e,t={}){if(typeof window>"u")return {ok:false,steps:[{ok:false,action:"none",targetKind:"position",durationMs:0,error:"guideCursor only works in browser environment"}]};let r=window.__cursorGuide;if(!r)return {ok:false,steps:[{ok:false,action:"none",targetKind:"position",durationMs:0,error:"CursorController not initialized. Make sure to mount <CursorController /> component."}]};try{return await r(e,t)}catch(n){return {ok:false,steps:[{ok:false,action:t.action||"none",targetKind:"position",durationMs:0,error:n?.message||String(n)}]}}}typeof window<"u"&&(window.guideCursor=Ae);function Vr(e){return !!e&&e.nodeType===1}function ue(e,t){e.dispatchEvent(new Event(t,{bubbles:true}));}function Xr(e,t){let r=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(e),"value")?.set;r?r.call(e,t):e.value=t,ue(e,"input");}function Go(e,t){e.checked!==t&&e.click();}function jo(e,t){if(typeof t=="object"&&t&&"index"in t&&typeof t.index=="number")e.selectedIndex=Math.max(0,Math.min(e.options.length-1,t.index));else if(typeof t=="object"&&t&&"label"in t&&typeof t.label=="string"){let r=Array.from(e.options).findIndex(n=>n.text===t.label);e.selectedIndex=r>=0?r:0;}else e.value=String(t);ue(e,"input"),ue(e,"change");}function _o(e,t){let r=new Set(t.map(String));Array.from(e.options).forEach(n=>{n.selected=r.has(n.value)||r.has(n.text);}),ue(e,"input"),ue(e,"change");}function qo(e){return e?e instanceof Date?e.toISOString().slice(0,10):String(e):""}function Ko(e,t){let r=Array.isArray(t)?t:[t],n=new DataTransfer;for(let o of r)n.items.add(o);Object.defineProperty(e,"files",{value:n.files,configurable:true}),ue(e,"input"),ue(e,"change");}async function Qe(e,t={}){let r=document.activeElement||null;if(r&&Vr(r)){let n=r.closest('[contenteditable="true"], [contenteditable=""]');n&&(r=n);}if(!r||r===document.body)return {ok:false,filled:[{key:"active",status:"skipped",message:"No active input element"}],errors:["No active input element"]};try{let n=r.tagName.toLowerCase();if(n==="input"){let o=r,s=(o.type||"text").toLowerCase();if(s==="checkbox")Go(o,!!e);else if(s==="radio"){let g=o.name;if(g&&e!=null&&String(o.value)!==String(e)){let u=document.querySelector(`input[type="radio"][name="${CSS.escape(g)}"][value="${CSS.escape(String(e))}"]`);u?u.click():o.click();}else o.click();}else if(s==="file")if(e instanceof File||Array.isArray(e)&&e.every(g=>g instanceof File))Ko(o,e);else return {ok:!1,filled:[{key:"active",status:"skipped",message:"Provide File or File[] for file input"}],errors:["Provide File or File[] for file input"]};else {let g=s==="date"?qo(e):String(e??"");Xr(o,g),ue(o,"change");}return {ok:!0,filled:[{key:"active",status:"ok"}]}}if(n==="textarea"){let o=r,s=String(e??"");return Xr(o,s),ue(o,"change"),{ok:!0,filled:[{key:"active",status:"ok"}]}}if(n==="select"){let o=r;return o.multiple?_o(o,Array.isArray(e)?e:[e]):jo(o,e),{ok:!0,filled:[{key:"active",status:"ok"}]}}if(Vr(r)&&r.isContentEditable){let o=r;return o.focus(),o.textContent=String(e??""),ue(o,"input"),ue(o,"change"),o.blur?.(),{ok:!0,filled:[{key:"active",status:"ok"}]}}return {ok:!1,filled:[{key:"active",status:"skipped",message:`Unsupported active element: ${n}`}],errors:[`Unsupported active element: ${n}`]}}catch(n){return {ok:false,filled:[{key:"active",status:"error",message:n?.message??String(n)}],errors:[n?.message??String(n)]}}}typeof window<"u"&&(window.FillActiveInput=Qe);var et=null,gt={},Jr=false,ze=null,ft=false;function _t(e){e.classList.add("visible");}function oo(){ft=true,ze!=null&&(clearTimeout(ze),ze=null);}function Xo(e,t=1500){ft||(ze!=null&&clearTimeout(ze),ze=window.setTimeout(()=>{ft||e.classList.remove("visible");},t));}function Yo(e,t=1200){ft=false,Xo(e,t);}function Jo(e){let t=[],r=e?.parentElement;for(;r;){let n=getComputedStyle(r),o=n.overflow+n.overflowY+n.overflowX;/(auto|scroll)/.test(o)&&t.push(r),r=r.parentElement;}return t}async function Zo(e,t=1500,r=160){let n=performance.now(),o=e?Jo(e):[],s=()=>{let y=[window.scrollX||document.documentElement.scrollLeft||0,window.scrollY||document.documentElement.scrollTop||0];return o.forEach(I=>{y.push(I.scrollLeft,I.scrollTop);}),y},g=()=>{if(!e)return {x:0,y:0};let y=e.getBoundingClientRect();return {x:y.left,y:y.top}},u=s(),C=g(),T=performance.now();return new Promise(y=>{function I(k){let f=s(),i=g(),b=false;for(let c=0;c<f.length;c++)if(f[c]!==u[c]){b=true;break}if(!b&&e&&(i.x!==C.x||i.y!==C.y)&&(b=true),b&&(u=f,C=i,T=k),k-T>=r||k-n>=t){y();return}requestAnimationFrame(I);}requestAnimationFrame(I);})}var Qo='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="32px" height="32px"><path d="M 7.2304688 4.9863281 C 5.9215232 4.8276681 4.8053213 6.0177722 5.0234375 7.3066406 A 1.0001 1.0001 0 0 0 5.0253906 7.3085938 C 5.9996339 12.981516 7.7205826 18.716222 10 24.515625 A 1.0001 1.0001 0 0 0 10 24.517578 C 10.26886 25.199332 10.914322 25.653844 11.5625 25.738281 C 12.210678 25.822721 12.879213 25.592031 13.359375 25.09375 C 14.505165 23.921134 15.214424 22.695429 15.90625 21.498047 C 17.56565 23.217848 19.256845 24.909775 21.0625 26.484375 L 21.060547 26.480469 C 21.799528 27.12933 22.841378 27.205969 23.673828 26.78125 A 1.0001 1.0001 0 0 0 23.691406 26.771484 C 24.987999 26.077693 26.028685 25.052256 26.71875 23.746094 L 26.71875 23.744141 C 27.174557 22.900924 27.06954 21.854242 26.439453 21.119141 A 1.0001 1.0001 0 0 0 26.433594 21.113281 C 24.867416 19.313474 23.193611 17.633865 21.488281 15.986328 C 22.714141 15.237691 23.933938 14.51508 25.158203 13.414062 A 1.0001 1.0001 0 0 0 25.162109 13.410156 C 26.052979 12.600274 25.977319 11.169141 25.101562 10.404297 A 1.0001 1.0001 0 0 0 24.669922 10.042969 C 18.793373 7.4738953 12.973806 5.6931843 7.2324219 4.9882812 A 1.0001 1.0001 0 0 0 7.2304688 4.9863281 z M 6.9960938 6.9746094 C 12.468883 7.6474978 18.081513 9.3573116 23.796875 11.849609 A 1.0001 1.0001 0 0 0 23.867188 11.884766 C 23.901248 11.899796 23.884276 11.867987 23.816406 11.929688 C 22.403891 13.198979 20.999383 14.076858 19.457031 14.976562 A 1.0001 1.0001 0 0 0 19.275391 16.568359 C 21.250864 18.425305 23.134972 20.36916 24.919922 22.419922 C 25.009402 22.524309 25.024026 22.676488 24.960938 22.792969 A 1.0001 1.0001 0 0 0 24.955078 22.804688 C 24.446951 23.770198 23.730542 24.476149 22.755859 25 C 22.611605 25.06851 22.457885 25.047856 22.378906 24.978516 A 1.0001 1.0001 0 0 0 22.376953 24.976562 C 20.293628 23.159824 18.307991 21.233373 16.419922 19.216797 A 1.0001 1.0001 0 0 0 14.835938 19.378906 C 13.841812 21.004716 13.152668 22.447221 11.925781 23.701172 A 1.0001 1.0001 0 0 0 11.919922 23.707031 C 11.883822 23.744501 11.865156 23.739957 11.847656 23.742188 C 9.6161121 18.057657 7.9395914 12.46667 6.9960938 6.9746094 z"/></svg>',en='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="32px" height="32px"><path d="M 22.5 3 C 19.480226 3 17 5.4802259 17 8.5 L 17 23.412109 L 14.871094 22.697266 C 13.308963 22.172461 11.892528 22 10.703125 22 C 9.5908429 22 8.5540295 22.197475 7.640625 22.65625 C 5.2906802 23.831199 3.9427678 26.197397 4.0019531 28.90625 C 4.0019531 28.90625 4.0019531 28.908203 4.0019531 28.908203 C 4.0019531 28.908203 4.0019531 28.910156 4.0019531 28.910156 C 4.0184171 29.660452 4.4596385 30.354695 5.1328125 30.6875 A 1.50015 1.50015 0 0 0 5.1367188 30.689453 C 5.1367188 30.689453 9.4097266 32.789754 11.599609 33.949219 C 12.445613 34.397848 13.696939 34.926046 15.210938 36.09375 C 16.724935 37.261454 18.423179 39.012543 19.826172 41.792969 C 21.023611 44.165544 23.672779 45.195669 26.144531 44.955078 A 1.50015 1.50015 0 0 0 26.146484 44.955078 C 31.427085 44.439215 32.081856 44.381732 35.59375 44.023438 C 37.044229 43.875625 38.276993 43.213524 39.111328 42.289062 C 39.945663 41.364602 40.422895 40.257718 40.798828 39.125 C 41.561218 36.826116 42.933037 33.169846 43.671875 30.599609 C 45.018525 25.913269 41.884024 21.194549 37.246094 19.953125 L 37.242188 19.951172 C 36.99827 19.885452 36.756736 19.832884 36.521484 19.789062 A 1.50015 1.50015 0 0 0 36.513672 19.787109 L 28 18.248047 L 28 8.5 C 28 5.4802259 25.519774 3 22.5 3 z M 22.5 6 C 23.898226 6 25 7.1017741 25 8.5 L 25 19.5 A 1.50015 1.50015 0 0 0 26.232422 20.976562 L 35.980469 22.740234 C 36.14895 22.771804 36.312663 22.808524 36.464844 22.849609 A 1.50015 1.50015 0 0 0 36.46875 22.849609 C 39.614436 23.689967 41.641993 26.803286 40.789062 29.771484 C 40.115901 32.113248 38.752735 35.768572 37.953125 38.179688 C 37.641059 39.119968 37.279727 39.837554 36.882812 40.277344 C 36.485898 40.717133 36.095584 40.956874 35.289062 41.039062 C 31.783676 41.396695 31.135884 41.452908 25.855469 41.96875 C 24.423221 42.108159 23.024467 41.472831 22.503906 40.441406 C 20.887905 37.238832 18.854971 35.116296 17.042969 33.71875 C 15.230967 32.321204 13.560902 31.594199 13.003906 31.298828 C 10.939171 30.205625 7.8041786 28.665144 7.1035156 28.320312 C 7.1954033 26.8809 7.6810328 25.989859 8.9824219 25.339844 A 1.50015 1.50015 0 0 0 8.9863281 25.337891 C 9.3949198 25.132713 9.9434071 25 10.703125 25 C 11.605722 25 12.680146 25.12582 13.916016 25.541016 L 18.021484 26.921875 A 1.50015 1.50015 0 0 0 20 25.5 L 20 8.5 C 20 7.1017741 21.101774 6 22.5 6 z"/></svg>';async function tn(){if(!gt.arrow)try{gt.arrow=Qo,gt.pointer=en;}catch(e){console.warn("Failed to set cursor SVGs",e);}return gt}function Zr({arrowSvg:e,pointerSvg:t}){return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[e&&jsxRuntime.jsx("div",{className:"arrow",dangerouslySetInnerHTML:{__html:e}}),t&&jsxRuntime.jsx("div",{className:"pointer",dangerouslySetInnerHTML:{__html:t}})]})}async function rn(){let e="demo-fake-cursor",t=document.getElementById(e),r=await tn();if(!Jr){let n="cursor-controller-styles";if(!document.getElementById(n)){let o=document.createElement("style");o.id=n,o.textContent=`
|
|
160
160
|
.fake-cursor { pointer-events: none; opacity: 0; transition: opacity 0.2s ease; z-index: 2147483647; }
|
|
161
161
|
.fake-cursor.visible { opacity: 1; }
|
|
162
162
|
.fake-cursor .arrow { display: none; }
|
|
@@ -166,12 +166,12 @@
|
|
|
166
166
|
.fake-cursor.as-pointer .arrow { display: none; }
|
|
167
167
|
.fake-cursor.as-pointer .pointer { display: block; }
|
|
168
168
|
.fake-cursor.pressing .pointer svg path { filter: brightness(0.9); }
|
|
169
|
-
`,document.head.appendChild(n);}Nr=true;}return t?(t.classList.add("as-arrow"),Je||(Je=client.createRoot(t),Je.render(jsxRuntime.jsx(Wr,{arrowSvg:r.arrow,pointerSvg:r.pointer})))):(t=document.createElement("div"),t.id=e,t.className="fake-cursor as-arrow",t.style.position="fixed",t.style.left="20px",t.style.top="20px",document.body.appendChild(t),Je=client.createRoot(t),Je.render(jsxRuntime.jsx(Wr,{arrowSvg:r.arrow,pointerSvg:r.pointer}))),t}function Pe(e,t,r){return Math.max(t,Math.min(r,e))}function _n(e){return e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2}function qr(e){if(!e)return null;let t=document.createElement("canvas").getContext("2d");if(!t)return null;t.fillStyle="#000",t.fillStyle=e;let o=t.fillStyle.match(/rgba?\(([^)]+)\)/i);if(!o)return null;let n=o[1].split(/\s*,\s*/).map(Number),[s,m,u,C=1]=n;return {r:s,g:m,b:u,a:C}}function qn({r:e,g:t,b:r}){let o=[e,t,r].map(n=>n/255).map(n=>n<=.03928?n/12.92:Math.pow((n+.055)/1.055,2.4));return .2126*o[0]+.7152*o[1]+.0722*o[2]}function Kn(e){let t=e?qr(e):null;return !t||t.a===0?false:qn(t)<.5}function Vn(e,t){let r=document.elementFromPoint(e,t),o=new Set;for(;r&&!o.has(r);){o.add(r);let m=getComputedStyle(r).backgroundColor,u=qr(m);if(u&&u.a>0)return m;r=r.parentElement;}return getComputedStyle(document.body).backgroundColor||"rgb(255,255,255)"}function $t(e,t,r){let o=Vn(t,r),n=Kn(o),s=n?"#ffffff":"#000000";e.querySelectorAll("svg path").forEach(u=>{u.style.fill="white",u.style.stroke=s,u.style.strokeWidth="1";}),e.style.filter=n?"drop-shadow(0 1px 2px rgba(0,0,0,0.8))":"drop-shadow(0 1px 2px rgba(255,255,255,0.9))";}async function lt(e,t,r,o,n="ease-in-out",s="curve",m=.25,u="auto",C){_r(),zt(e);let S=performance.now(),x=n==="linear"?f=>f:_n,M=s!=="straight",k={x:0,y:0};if(M){let f=r.x-t.x,i=r.y-t.y,b=Math.hypot(f,i)||1,c=(t.x+r.x)/2,d=(t.y+r.y)/2,h=-i/b,l=f/b,a=1;u==="left"?a=-1:u==="right"?a=1:a=Math.random()<.5?-1:1;let T=Pe(m,0,1)*b;k={x:c+a*h*T,y:d+a*l*T};}return new Promise(f=>{function i(b){let c=Pe((b-S)/o,0,1),d=x(c),h,l;if(M){let y=1-d;h=y*y*t.x+2*y*d*k.x+d*d*r.x,l=y*y*t.y+2*y*d*k.y+d*d*r.y;}else h=t.x+(r.x-t.x)*d,l=t.y+(r.y-t.y)*d;let T=.35*(1-d),w=Math.sin(b*.02)*T,v=Math.cos(b*.018)*T;e.style.left=`${h+w}px`,e.style.top=`${l+v}px`,$t(e,h+w,l+v),C&&C({x:h+w,y:l+v,t:c,now:b}),c<1?requestAnimationFrame(i):f();}requestAnimationFrame(i);})}function Ur(e,t){return {x:e.x+(t?.x??0),y:e.y+(t?.y??0)}}function me(e,t,r,o){let n={bubbles:true,cancelable:true,view:window,clientX:r.x,clientY:r.y,...o};try{let s=t==="pointerdown"||t==="mousedown",m=t==="pointerup"||t==="mouseup",u={button:0,buttons:s?1:0,isPrimary:!0,...n};if("PointerEvent"in window){let C=new PointerEvent(t,{pointerId:1,pointerType:"mouse",...u});e.dispatchEvent(C);}else {let C=new MouseEvent(t,u);e.dispatchEvent(C);}}catch{let s=new MouseEvent(t,n);e.dispatchEvent(s);}}function Kr(e){return e&&typeof e=="object"&&e.nodeType===1}function Xn(e){if(!e)return document;if(Kr(e))return e;if(typeof e=="string"){let t=document.getElementById(e);if(t)return t;let r=document.querySelector(e);if(r)return r}return document}function Or(e){if(Kr(e))return {kind:"element",element:e};if(typeof e=="string"){let t=document.getElementById(e);if(t)return {kind:"element",element:t};let r=document.querySelector(e);return {kind:r?"element":"position",element:r??null}}if(typeof e=="object"&&"position"in e)return {kind:"position",point:e.position};if(typeof e=="object"&&"selector"in e){let r=Xn(e.within??null).querySelectorAll(e.selector),o=Math.max(0,Math.min(r.length-1,e.nth??0)),n=r[o]??null;return {kind:n?"element":"position",element:n}}return {kind:"position",point:{x:0,y:0}}}function Gr(e,t){let r=e.getBoundingClientRect();if(!t||t==="center")return {x:r.left+r.width/2,y:r.top+r.height/2};if(t==="top-left")return {x:r.left,y:r.top};if(t==="bottom-right")return {x:r.right,y:r.bottom};let o=Pe(t.x,0,1),n=Pe(t.y,0,1);return {x:r.left+r.width*o,y:r.top+r.height*n}}function jr(e){return {x:Pe(e.x,0,window.innerWidth),y:Pe(e.y,0,window.innerHeight)}}function Yn(){return pn.useEffect(()=>(window.__cursorGuide=async(e,t={})=>{let r=Array.isArray(e)?e:[{target:e,action:t.action??"none",options:t}],o=[],n=await jn();n.classList.add("visible","as-arrow"),n.classList.remove("as-pointer","pressing"),zt(n),_r();let s=parseFloat(n.style.left||"20")||20,m=parseFloat(n.style.top||"20")||20;$t(n,s,m);for(let u of r){let{durationMs:C=800,easing:S="ease-in-out",offset:x,highlight:M=true,path:k="curve",curveStrength:f=.25,curveDirection:i="auto",anchor:b,cursorHotspot:c,dragTo:d}=u.options??{},h=u.action??u.options?.action??"none",l=performance.now(),a=Or(u.target),T=null,w=null;if(a.kind==="element"&&a.element?(w=a.element,n.classList.remove("visible"),w.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),await Wn(w,1500,180),zt(n),T=Gr(w,b)):a.kind==="position"&&a.point&&(T=a.point),!T){o.push({ok:false,action:h,targetKind:a.kind,durationMs:Math.round(performance.now()-l),error:"Target not found"});continue}let v={x:parseFloat(n.style.left||"20")||20,y:parseFloat(n.style.top||"20")||20},y=jr(Ur(T,x));await lt(n,v,y,C,S,k,f,i);let E=y.x-v.x,p=y.y-v.y,F=Math.hypot(E,p)||1,W=E/F,_=p/F,te=Math.min(6,Math.max(3,F*.02)),xe={x:y.x+W*te,y:y.y+_*te};await lt(n,y,xe,Math.max(70,C*.1),"ease-out","straight",0,"right"),await lt(n,xe,y,120,"ease-out","straight",0,"left"),M&&(n.classList?.add("click"),setTimeout(()=>n.classList?.remove("click"),180));let ge=null;try{if(h==="click"){n.classList.remove("as-arrow"),n.classList.add("as-pointer","pressing");let q={x:c?.x??0,y:c?.y??0},U={x:y.x+q.x,y:y.y+q.y};n.style.left=`${U.x}px`,n.style.top=`${U.y}px`,$t(n,U.x,U.y);let K=w??document.elementFromPoint(U.x,U.y)??document.body;me(K,"pointerdown",U),me(K,"mousedown",U),await new Promise(G=>setTimeout(G,90)),n.classList.remove("pressing"),me(K,"mouseup",U),me(K,"click",U),setTimeout(()=>{n.classList.remove("as-pointer"),n.classList.add("as-arrow");},140),K instanceof HTMLElement&&K.focus?.(),ge=K?.id??null;}else if(h==="drag"){if(!d)throw new Error("dragTo is required for action 'drag'");let q=Or(d),U=null;if(q.kind==="element"&&q.element&&(U=Gr(q.element,b)),q.kind==="position"&&q.point&&(U=q.point),!U)throw new Error("dragTo target not found");let K=jr(Ur(U,x)),G={x:y.x,y:y.y},$e=w??document.elementFromPoint(G.x,G.y)??document.body;n.classList.remove("as-arrow"),n.classList.add("as-pointer","pressing"),me($e,"pointerdown",G),me($e,"mousedown",G),await lt(n,G,K,Math.max(200,C),S,k,f,i,({x:re,y:Z})=>{let fe=document.elementFromPoint(re,Z)??document.body,Ne={x:re,y:Z};me(fe,"pointermove",Ne),me(fe,"mousemove",Ne);});let V=document.elementFromPoint(K.x,K.y)??document.body;n.classList.remove("pressing"),me(V,"pointerup",K),me(V,"mouseup",K);}o.push({ok:!0,action:h,targetKind:a.kind,durationMs:Math.round(performance.now()-l),clickedElementId:ge});}catch(q){o.push({ok:false,action:h,targetKind:a.kind,durationMs:Math.round(performance.now()-l),error:q?.message??String(q)});}}return $n(n,2e3),{ok:o.every(u=>u.ok),steps:o}},()=>{try{delete window.__cursorGuide;}catch{window.__cursorGuide=void 0;}}),[]),null}var Ze=Yn;function Vr(){return {getDomComponents:{tool:async({includeHidden:e,selector:t})=>await Xe({includeHidden:e,selector:t}),executeEachToken:false},controlCursor:{tool:async({target:e,action:t,anchor:r,durationMs:o,dragTo:n})=>{let s=await Se(e,{action:t,anchor:r,durationMs:o,dragTo:n});if(s&&s.ok){let m=Array.isArray(s.steps)&&s.steps.length?s.steps[s.steps.length-1]:void 0,u=m?.clickedElementId?` (clicked element id: ${m.clickedElementId})`:"",C=t||m?.action||"none";return {success:true,message:C==="click"?`Cursor moved and clicked successfully${u}`:C==="drag"?"Cursor dragged successfully":"Cursor moved successfully",details:s}}return {success:false,message:"Cursor action failed",details:s}},executeEachToken:false},fillActiveInput:{tool:async({value:e})=>{let t=await Ye(e);return {success:!!t?.ok,message:t?.ok?"Active input filled successfully":t?.errors?.[0]||"Failed to fill active input",details:t}},executeEachToken:true},requestInput:{tool:async e=>({ok:true}),executeEachToken:true}}}function Qn({input:e}){return jsxRuntime.jsx("div",{style:{fontSize:"14px",lineHeight:"1.6",width:"100%"},children:jsxRuntime.jsx(He,{content:e?.text||"",theme:"dark"})})}function Yr(){return {plainText:Qn}}function Jr(e,t,r,o,n,s){let m=r.get(t);if(m){let a=m.parentElement,T=document.querySelector(`[data-get-from-user-host="${t}"]`);if(T&&a!==T){try{a?.removeChild(m);}catch{}T.innerHTML="",T.appendChild(m);}}else {m=document.createElement("div"),m.className="hsafa-inline-form";let a=document.querySelector(`[data-get-from-user-host="${t}"]`);a?(a.innerHTML="",a.appendChild(m)):(document.querySelector(".chat-scroll-container")||document.body).appendChild(m),r.set(t,m);}let u=e?.title||"Provide input",C=e?.description||"",S=e?.submitLabel||"Submit",x=e?.skipLabel||"Skip",M=Array.isArray(e?.fields)?e.fields:e?.label||e?.placeholder?[{id:"value",label:e?.label||"Value",type:"text",placeholder:e?.placeholder||""}]:[],k=o.get(t)||{submitted:false,skipped:false,values:void 0};m.innerHTML="";let f=document.createElement("form");f.style.margin="12px 0",f.style.padding="14px",f.style.border="1px solid var(--hsafa-border, #2A2C33)",f.style.borderRadius="12px",f.style.background="var(--hsafa-card, #121318)",f.style.color="var(--hsafa-text, #EDEEF0)",f.style.boxShadow="0 6px 20px rgba(0,0,0,0.25)";let i=document.createElement("div");if(i.style.fontWeight="600",i.style.marginBottom="6px",i.textContent=u,f.appendChild(i),C){let a=document.createElement("div");a.style.fontSize="12px",a.style.opacity="0.8",a.style.marginBottom="10px",a.textContent=C,f.appendChild(a);}M.forEach(a=>{let T=document.createElement("div");if(T.style.margin="10px 0",a.label){let p=document.createElement("label");p.style.display="block",p.style.fontSize="12px",p.style.marginBottom="6px",p.style.opacity="0.9",p.textContent=a.label,T.appendChild(p);}let w,v=(a.type||"text").toLowerCase();if(v==="textarea"){let p=document.createElement("textarea");p.placeholder=a.placeholder||"",p.value=a.value??"",p.style.width="100%",p.style.minHeight="72px",p.style.padding="10px 12px",p.style.border="1px solid var(--hsafa-border, #2A2C33)",p.style.borderRadius="10px",p.style.background="var(--hsafa-input-bg, #17181C)",p.style.color="inherit",w=p;}else if(v==="select"&&Array.isArray(a.options)){let p=document.createElement("select");p.style.width="100%",p.style.padding="10px 12px",p.style.border="1px solid var(--hsafa-border, #2A2C33)",p.style.borderRadius="10px",p.style.background="var(--hsafa-input-bg, #17181C)",p.style.color="inherit",a.options.forEach(F=>{let W=document.createElement("option");W.value=String(F.value),W.text=String(F.label??F.value),p.appendChild(W);}),p.value=a.value??"",w=p;}else if(v==="checkbox"){let p=document.createElement("input");p.type="checkbox",p.checked=!!a.value,p.style.transform="scale(1.1)",w=p;}else {let p=document.createElement("input");p.type=v,p.placeholder=a.placeholder||"",p.value=a.value??"",p.style.width="100%",p.style.padding="10px 12px",p.style.border="1px solid var(--hsafa-border, #2A2C33)",p.style.borderRadius="10px",p.style.background="var(--hsafa-input-bg, #17181C)",p.style.color="inherit",w=p;}let y=a.id||"value";w.dataset.fieldId=y;let E=k.values&&Object.prototype.hasOwnProperty.call(k.values,y)?k.values[y]:void 0;typeof E<"u"&&(w.type==="checkbox"?w.checked=!!E:w.value=String(E)),(k.submitted||k.skipped)&&(w.setAttribute("disabled","true"),w.style.opacity="0.7"),T.appendChild(w),f.appendChild(T);});let b=String(S).trim(),c=String(x).trim(),d=!!(b||c),h=null,l=null;if(d){let a=document.createElement("div");a.style.display="flex",a.style.gap="8px",a.style.marginTop="10px",h=document.createElement("button"),h.type="submit",h.textContent=b||"Submit",h.style.padding="6px 10px",h.style.borderRadius="8px",h.style.background="var(--hsafa-button-bg, var(--hsafa-primary, #2563eb))",h.style.color="#000000",l=document.createElement("button"),l.type="button",l.textContent=c||"Skip",l.style.padding="6px 10px",l.style.borderRadius="8px",l.style.background="transparent",l.style.border="1px solid var(--hsafa-border, #2A2C33)",l.style.color="inherit",a.appendChild(h),a.appendChild(l),f.appendChild(a);}if(f.onsubmit=a=>{a.preventDefault();let T={};f.querySelectorAll("[data-field-id]").forEach(w=>{let v=w.dataset.fieldId||"value";w.type==="checkbox"?T[v]=w.checked:T[v]=w.value??"";}),o.set(t,{submitted:true,skipped:false,values:T}),n({tool:"requestInput",toolCallId:t,output:{success:true,submitted:true,values:T}}),f.querySelectorAll("[data-field-id]").forEach(w=>{w.disabled=true,w.style.opacity="0.7";}),h&&(h.textContent=`${b||"Submit"} \u2713`,h.style.opacity="0.8",h.disabled=true),l&&(l.disabled=true);},l&&(l.onclick=()=>{o.set(t,{submitted:false,skipped:true,values:void 0}),n({tool:"requestInput",toolCallId:t,output:{success:true,submitted:false,skipped:true}}),f.querySelectorAll("[data-field-id]").forEach(a=>{a.disabled=true,a.style.opacity="0.7";}),l&&(l.textContent=`${c||"Skip"} \u2713`,l.style.opacity="0.8",l.disabled=true),h&&(h.disabled=true);}),k.submitted||k.skipped){let a=document.createElement("div");a.style.marginTop="10px",a.style.fontSize="12px",a.style.display="flex",a.style.alignItems="center",a.style.gap="8px";let T=document.createElement("span");T.style.display="inline-flex",T.style.alignItems="center",T.style.padding="2px 8px",T.style.borderRadius="999px",T.style.fontWeight="600",T.style.fontSize="11px",k.submitted?(T.style.background="rgba(16,185,129,0.15)",T.style.color="#10b981",T.textContent="Submitted"):(T.style.background="rgba(234,179,8,0.15)",T.style.color="#eab308",T.textContent="Skipped"),a.appendChild(T),f.appendChild(a);try{h&&(h.disabled=!0,h.style.opacity="0.8",k.submitted&&(h.textContent=`${b||"Submit"} \u2713`)),l&&(l.disabled=!0,l.style.opacity="0.8",k.skipped&&(l.textContent=`${c||"Skip"} \u2713`));}catch{}}m.appendChild(f);}function Zr(e,t,r){let o=pn.useRef(new Map),n=pn.useRef(new Map),s=pn.useRef(t),m=pn.useRef(r);s.current=t,m.current=r,pn.useEffect(()=>{e.forEach(u=>{u.role==="assistant"&&u.parts?.forEach(C=>{if(!C.toolCallId)return;let S=C.toolName;if(!S&&C.type?.startsWith("tool-")&&(S=C.type.replace(/^tool-/,"")),!S)return;let x=s.current[S];if(x&&typeof x=="object"&&x.executeEachToken&&x.tool){let M=C.input||C.args||{},k=JSON.stringify(M),f=o.current.get(C.toolCallId);if(k!==f&&k!=="{}"){o.current.set(C.toolCallId,k);try{if(S==="requestInput")m.current(M,C.toolCallId);else {let b=(n.current.get(C.toolCallId)||0)+1;n.current.set(C.toolCallId,b),b>1&&x.tool({...M,toolCallNumber:b-1});}}catch{}}}});});},[e]);}function Wt(e){let{agentId:t,baseUrl:r="",tools:o={},uiComponents:n={},onStart:s,onFinish:m,onError:u,initialMessages:C=[],onMessagesChange:S,controlledChatId:x,onChatIdChange:M,templateParams:k}=e,{baseUrl:f,setCurrentChatId:i}=ie(),b=r&&r.length>0?r:f||"",[c,d]=pn.useState(""),[h,l]=pn.useState(()=>`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`),a=x??h,T=pn.useCallback(I=>{x===void 0&&l(I),M&&M(I);},[x,M]);pn.useEffect(()=>{try{i(a);}catch{}return ()=>{try{i(void 0);}catch{}}},[a,i]);let w=pn.useMemo(()=>Dr(b,t,a,k),[b,t,a,k]),v=pn.useCallback(I=>{console.log("Message finished:",I);let P=I?.message?.id;if(!P&&Array.isArray(I?.messages))for(let O=I.messages.length-1;O>=0;O--){let z=I.messages[O];if(z&&z.role==="assistant"&&z.id){P=z.id;break}}m?.({...I,chatId:a,assistantMessageId:P});},[m,a]),y=pn.useCallback(I=>{console.error("Chat error:",I),u?.(I);},[u]),E=pn.useMemo(()=>Vr(),[]),p=pn.useMemo(()=>({...E,...o}),[E,o]),F=pn.useMemo(()=>Yr(),[]),W=pn.useMemo(()=>({...F,...n}),[F,n]),_=pn.useRef(new Map),te=pn.useRef(new Map),xe=pn.useCallback(()=>{try{_.current.forEach(I=>{try{I.remove();}catch{}}),_.current.clear(),te.current.clear();}catch{}},[]),ge=pn.useCallback((I,P)=>{Jr(I,P,_.current,te.current,O=>q.current.addToolResult(O));},[]),q=pn.useRef(null),U=pn.useRef(new Set),K=pn.useCallback((I,P,O)=>{console.error(`UI Error [${P}]:`,O),q.current&&U.current.has(I)&&(U.current.delete(I),q.current.addToolResult({tool:P,toolCallId:I,state:"output-error",errorText:O?.message||String(O)}));},[]),G=pn.useCallback((I,P)=>{q.current&&U.current.has(I)&&(U.current.delete(I),q.current.addToolResult({tool:P,toolCallId:I,output:{status:"ok",rendered:true,component:P,logs:[]}}));},[]),$e=pn.useCallback(I=>{let P=p[I];return P?typeof P=="object"&&"tool"in P?P.tool:typeof P=="function"?P:null:null},[p]),V=react.useChat({transport:w,onFinish:v,onError:y,experimental_throttle:10,sendAutomaticallyWhen:ai.lastAssistantMessageIsCompleteWithToolCalls,async onToolCall({toolCall:I}){let P=$e(I.toolName);if(I.toolName==="requestInput"){try{ge(I.input,I.toolCallId);}catch(j){console.error("requestInput render error",j);}return}let O=I.toolName==="ui";I?.input;let ee=W&&I.toolName in W;if(O||ee){U.current.add(I.toolCallId);return}if(P)try{let j=await P(I.input);V.addToolResult({tool:I.toolName,toolCallId:I.toolCallId,output:j});}catch(j){V.addToolResult({tool:I.toolName,toolCallId:I.toolCallId,state:"output-error",errorText:j?.message||String(j)});}}}),{messages:re,sendMessage:Z,status:fe,stop:Ne,error:Qt}=V;q.current=V;let A=pn.useRef(new Set);Zr(re,p,ge),pn.useEffect(()=>{try{let I=new Set,P=[];if(re.forEach(O=>{O.role==="assistant"&&(O.parts||[]).forEach(z=>{if((z?.toolName||(typeof z?.type=="string"&&z.type.startsWith("tool-")?String(z.type.replace(/^tool-/,"")):void 0))!=="requestInput")return;let j=z?.toolCallId||"";if(!j)return;I.add(j);let pe=z?.output;if(pe&&(pe.submitted||pe.skipped||pe.values)){let Re={submitted:!!pe.submitted,skipped:!!pe.skipped,values:pe.values||void 0};te.current.set(j,Re);}let We=z?.input||z?.args||{};P.push({input:We,toolCallId:j});});}),_.current.forEach((O,z)=>{if(!I.has(z)){let ee=_.current.get(z);try{ee?.remove();}catch{}_.current.delete(z),te.current.delete(z);}}),P.length>0){let O=requestAnimationFrame(()=>{P.forEach(({input:z,toolCallId:ee})=>{try{ge(z,ee);}catch{}});});return ()=>cancelAnimationFrame(O)}}catch{}},[re,ge]),pn.useEffect(()=>{if(!(!C||C.length===0)&&re.length===0&&!A.current.has(a)){A.current.add(a);try{V?.setMessages?.(C);}catch{}}},[C,re.length,a,V]);let B=fe==="submitted"||fe==="streaming",kt=pn.useCallback(()=>{S&&S(re,a);},[S,re,a]),ke=pn.useCallback(async I=>{let P=I?.text!==void 0?I.text:c,O=I?.files||[],z=P.trim();if(!(!z&&O.length===0)&&!B){I?.text===void 0&&d("");try{if(s){let ee={role:"user",content:z,createdAt:Date.now(),chatId:a};s(ee);}await Z({text:z,files:O});}catch(ee){throw console.error("Failed to send message:",ee),ee}}},[c,B,Z,s,a]),he=pn.useCallback(()=>{if(B)return;xe(),d("");try{V?.setMessages?.([]);}catch{}let I=`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`;T(I);},[B,V,xe,T]),ue=pn.useCallback(I=>{try{V?.setMessages?.(I);}catch{}},[V]);return {input:c,setInput:d,messages:re,isLoading:B,status:fe,error:Qt,sendMessage:ke,stop:Ne,newChat:he,setMessages:ue,notifyMessagesChange:kt,chatApi:V,chatId:a,setChatId:T,tools:p,uiComponents:W,formHostRef:_,formStateRef:te,cleanupForms:xe,onUISuccess:G,onUIError:K}}function pt(e){let t=`hsafaChat_${e}`,r=`${t}.chats`,o=l=>`${t}.chat.${l}`,n=`${t}.currentChatId`,s=`${t}.showChat`,m=()=>{try{let l=localStorage.getItem(r);return l?JSON.parse(l):[]}catch{return []}},u=l=>{try{localStorage.setItem(r,JSON.stringify(l));}catch{}},C=l=>{try{let a=localStorage.getItem(o(l));return a?JSON.parse(a):null}catch{return null}},S=l=>{try{localStorage.setItem(o(l.id),JSON.stringify(l));}catch{}},x=l=>{let a=m(),T=a.findIndex(w=>w.id===l.id);T>=0?a[T]=l:a.unshift(l),u(a);},M=l=>{let T=m().filter(w=>w.id!==l);u(T);},k=l=>{try{localStorage.removeItem(o(l));}catch{}};return {loadChatsIndex:m,saveChatsIndex:u,loadChat:C,saveChat:S,upsertChatMeta:x,deleteChatMeta:M,deleteChatData:k,deleteChat:l=>{k(l),M(l);},loadShowChatPreference:l=>{try{let a=localStorage.getItem(s);return a!==null?a==="true":l}catch{return l}},saveShowChatPreference:l=>{try{localStorage.setItem(s,String(l));}catch{}},loadCurrentChatId:()=>{try{return localStorage.getItem(n)}catch{return null}},saveCurrentChatId:l=>{try{localStorage.setItem(n,l);}catch{}},removeCurrentChatId:()=>{try{localStorage.removeItem(n);}catch{}}}}function Ot(e){let{agentId:t,chatId:r,messages:o,isLoading:n=false,autoSave:s=true,autoRestore:m=true}=e,u=pn.useMemo(()=>pt(t),[t]),[C,S]=pn.useState([]),[x,M]=pn.useState(null),k=pn.useRef(false),f=pn.useRef(false),i=pn.useCallback(()=>{try{let w=u.loadChatsIndex();S(w);let v=w.find(y=>y.id===r);M(v||null);}catch(w){console.error("Failed to refresh chat list:",w);}},[u,r]);pn.useEffect(()=>{i();},[i]),pn.useEffect(()=>{if(!(!m||f.current)){try{u.loadCurrentChatId()&&(k.current=!0);}catch(w){console.error("Failed to restore chat:",w);}f.current=true;}},[u,m]),pn.useEffect(()=>{if(!(!s||o.length===0))if(k.current){if(!n){let w=Date.now();try{u.saveChat({id:r,messages:o,agentId:t});let y=u.loadChatsIndex().find(E=>E.id===r);y&&(u.upsertChatMeta({...y,updatedAt:w}),i());}catch(v){console.error("Failed to save chat:",v);}}}else {let w=o.find(v=>v.role==="user");if(w){let v="";if(Array.isArray(w.parts)){let p=w.parts.find(F=>F&&F.type==="text");v=p&&typeof p.text=="string"?p.text:"";}let y=(v||"New chat").slice(0,80),E=Date.now();try{u.upsertChatMeta({id:r,title:y,createdAt:E,updatedAt:E}),u.saveChat({id:r,messages:o,agentId:t}),u.saveCurrentChatId(r),k.current=!0,i();}catch(p){console.error("Failed to create chat:",p);}}}},[]);let b=pn.useRef(false);pn.useEffect(()=>{if(n){b.current=true;return}if(b.current&&s){b.current=false;try{let w=Date.now();u.saveChat({id:r,messages:o,agentId:t});let y=u.loadChatsIndex().find(E=>E.id===r);if(y)u.upsertChatMeta({...y,updatedAt:w});else {let E="",p=Array.isArray(o)?o.find(W=>W&&W.role==="user"):void 0;if(p&&Array.isArray(p.parts)){let W=p.parts.find(_=>_&&_.type==="text");E=W&&typeof W.text=="string"?W.text:"";}let F=(E||"New chat").slice(0,80);u.upsertChatMeta({id:r,title:F,createdAt:w,updatedAt:w});try{u.saveCurrentChatId(r);}catch{}k.current=!0;}i();}catch(w){console.error("Failed to save chat on completion:",w);}}},[n,o,r,t,u,s,i]);let c=pn.useCallback(w=>{try{let v=u.loadChat(w);return v?{id:v.id,messages:v.messages,agentId:v.agentId||t}:null}catch(v){return console.error("Failed to load chat:",v),null}},[u,t]),d=pn.useCallback(()=>{if(o.length!==0)try{let w=Date.now();u.saveChat({id:r,messages:o,agentId:t});let y=u.loadChatsIndex().find(E=>E.id===r);y&&(u.upsertChatMeta({...y,updatedAt:w}),i());}catch(w){console.error("Failed to save chat:",w);}},[u,r,o,t,i]),h=pn.useCallback(w=>{try{u.deleteChat(w),i();}catch(v){console.error("Failed to delete chat:",v);}},[u,i]),l=pn.useCallback((w,v)=>{if(w!==r)try{k.current=!0,u.saveCurrentChatId(w);let y=u.loadChat(w),E=y&&Array.isArray(y.messages)?y.messages:[];v(E),i();}catch(y){console.error("Failed to switch chat:",y);}},[u,r,i]),a=pn.useCallback(w=>{k.current=false,w();},[]),T=pn.useCallback(w=>{if(!w.trim())return C;let v=w.toLowerCase();return C.filter(y=>y.title.toLowerCase().includes(v))},[C]);return {chatList:C,currentChatMeta:x,refreshChatList:i,loadChat:c,saveCurrentChat:d,deleteChat:h,switchToChat:l,createNewChat:a,searchChats:T,storage:u}}function oo(e){let{messages:t,isLoading:r,sendMessage:o,setMessages:n,baseUrl:s}=e,{baseUrl:m}=ie(),u=s||m||"",[C,S]=pn.useState(null),[x,M]=pn.useState(""),[k,f]=pn.useState([]),[i,b]=pn.useState(false),c=pn.useCallback((w,v,y=[])=>{S(w),M(v),f(y);},[]),d=pn.useCallback(()=>{S(null),M(""),f([]);},[]),h=pn.useCallback(async w=>{if(!r)try{let v=t.findIndex(E=>E.id===w);if(v===-1)return;let y=t.slice(0,v);n(y),await o({text:x.trim(),files:k.map(E=>({type:"file",url:E.url,mediaType:E.mimeType||"application/octet-stream",...E.name?{name:E.name}:{},...E.size?{size:E.size}:{}}))}),d();}catch(v){throw console.error("Failed to save edit:",v),v}},[r,t,o,x,k,n,d]),l=pn.useCallback(w=>C===w,[C]),a=pn.useCallback(async w=>{if(!u){console.warn("baseUrl not provided, cannot upload attachments");return}b(true);try{let v=Array.from(w).map(async E=>{if(E.size>26214400)throw new Error(`${E.name} is too large (max 25MB)`);let p=new FormData;p.append("file",E);let F=await fetch(`${u}/api/upload`,{method:"POST",body:p});if(!F.ok)throw new Error(`Upload failed: ${F.statusText}`);let W=await F.json();return {id:W.url||`${Date.now()}-${Math.random()}`,name:E.name,url:W.url,mimeType:E.type,size:E.size}}),y=await Promise.all(v);f(E=>[...E,...y]);}catch(v){throw console.error("Failed to upload files:",v),v}finally{b(false);}},[u]),T=pn.useCallback(w=>{f(v=>v.filter(y=>y.id!==w));},[]);return {editingMessageId:C,editingText:x,setEditingText:M,editAttachments:k,setEditAttachments:f,editUploading:i,startEdit:c,cancelEdit:d,saveEdit:h,isEditing:l,addEditAttachments:a,removeEditAttachment:T}}function Y({IconComponent:e,...t}){return pn__default.default.createElement(e,t)}function Gt({icon:e,onClick:t,ariaLabel:r,resolvedColors:o,disabled:n=false,title:s}){return jsxRuntime.jsx("button",{"aria-label":r,title:s,disabled:n,style:{backgroundColor:"transparent",color:o.mutedTextColor,border:"none",borderRadius:"8px",padding:"8px",cursor:n?"not-allowed":"pointer",opacity:n?.5:1,transition:"all 0.2s ease-out",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:m=>{n||(m.currentTarget.style.backgroundColor=o.hoverBackground,m.currentTarget.style.color=o.textColor);},onMouseLeave:m=>{m.currentTarget.style.backgroundColor="transparent",m.currentTarget.style.color=o.mutedTextColor;},onClick:t,children:e})}function rn({title:e,alwaysOpen:t,streaming:r,dir:o,resolvedColors:n,onNew:s,onToggleHistory:m,onClose:u,historyBtnRef:C,t:S}){return jsxRuntime.jsxs("div",{style:{marginBottom:"24px",display:"flex",alignItems:"center",justifyContent:"space-between",direction:o==="rtl"?"rtl":"ltr"},children:[jsxRuntime.jsx("div",{style:{minWidth:"0"},children:jsxRuntime.jsx("h1",{title:e,style:{color:n.textColor,fontSize:"18px",fontWeight:"600",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",margin:"0"},children:e})}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",position:"relative",color:n.mutedTextColor},children:[jsxRuntime.jsx(Gt,{icon:jsxRuntime.jsx(Y,{IconComponent:lucideReact.Plus,size:"20",strokeWidth:"2"}),onClick:()=>{r||s();},ariaLabel:S("header.new"),resolvedColors:n,disabled:r}),jsxRuntime.jsx("button",{ref:C,"aria-label":S("header.history"),style:{backgroundColor:"transparent",color:n.mutedTextColor,border:"none",borderRadius:"8px",padding:"8px",cursor:"pointer",transition:"all 0.2s ease-out",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:x=>{x.currentTarget.style.backgroundColor=n.hoverBackground,x.currentTarget.style.color=n.textColor;},onMouseLeave:x=>{x.currentTarget.style.backgroundColor="transparent",x.currentTarget.style.color=n.mutedTextColor;},onClick:m,children:jsxRuntime.jsx(Y,{IconComponent:lucideReact.History,size:"20",strokeWidth:"2"})}),!t&&jsxRuntime.jsx(Gt,{icon:jsxRuntime.jsx(Y,{IconComponent:lucideReact.ChevronRight,size:"20",strokeWidth:"2",style:{transform:o==="rtl"?"rotate(180deg)":"none"}}),onClick:u,ariaLabel:S("header.close"),resolvedColors:n})]})]})}var yt=class extends pn.Component{constructor(t){super(t),this.state={hasError:false,error:null,errorInfo:null};}static getDerivedStateFromError(t){return {hasError:true,error:t,errorInfo:null}}componentDidMount(){let{toolCallId:t,toolName:r,onSuccess:o}=this.props;t&&r&&o&&!this.state.hasError&&setTimeout(()=>{this.state.hasError||o(t,r);},0);}componentDidCatch(t,r){console.error(`UI Component Error (${this.props.componentName}):`,t,r),this.setState({error:t,errorInfo:r});let{toolCallId:o,toolName:n,onError:s}=this.props;o&&n&&s&&s(o,n,t);}render(){if(this.state.hasError&&this.state.error){let{resolvedColors:t,componentName:r}=this.props;return jsxRuntime.jsxs("div",{style:{padding:"16px",backgroundColor:"#fee2e2",border:"2px solid #ef4444",borderRadius:"12px",color:"#991b1b"},children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},children:[jsxRuntime.jsx("span",{style:{fontSize:"20px"},children:"\u26A0\uFE0F"}),jsxRuntime.jsxs("strong",{style:{fontSize:"16px"},children:["Component Error: ",r]})]}),jsxRuntime.jsx("div",{style:{fontSize:"14px",marginBottom:"8px",fontFamily:"monospace"},children:this.state.error.message}),this.state.errorInfo&&jsxRuntime.jsxs("details",{style:{fontSize:"12px",marginTop:"8px"},children:[jsxRuntime.jsx("summary",{style:{cursor:"pointer",fontWeight:"bold"},children:"Stack Trace"}),jsxRuntime.jsx("pre",{style:{marginTop:"8px",padding:"8px",backgroundColor:"#fef2f2",borderRadius:"4px",overflow:"auto",maxHeight:"200px",fontSize:"11px"},children:this.state.errorInfo.componentStack})]})]})}return this.props.children}};var po=(e,t)=>{let r={"input-streaming":{color:"#eab308",text:t?t("tool.inputting"):"Inputting"},"input-available":{color:"#3b82f6",text:t?t("tool.running"):"Running"},error:{color:"#ef4444",text:t?t("tool.error"):"Error"},"output-available":{color:"#10b981",text:t?t("tool.called"):"Called"},finished:{color:"#10b981",text:t?t("tool.called"):"Called"}};return r[e||"output-available"]||r["output-available"]},mo=e=>{let t=/^(.+?)_([a-f0-9]{6})_(.+)$/,r=e.match(t);if(r){let[,o,,n]=r;return {isMCP:true,mcpName:o.replace(/_/g," "),toolName:n.replace(/_/g," ")}}return {isMCP:false,toolName:e}},go=e=>e.replace(/_/g," ").replace(/-/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\b\w/g,t=>t.toUpperCase());function nn({parts:e,messageId:t,openReasoningIds:r,toggleReasoning:o,resolvedColors:n,HsafaUI:s,onUIError:m,onUISuccess:u,addToolResult:C,dir:S="ltr",t:x}){let M=S==="rtl",k=[],f=[],i,b,c=false;for(let d of Array.isArray(e)?e:[]){if(!d)continue;if(d.type==="reasoning"&&typeof d.text=="string"){f.push(d.text),i||(i=d.startDate),b=d.endDate,d.state==="done"&&(c=true);continue}if(d.type==="text"&&typeof d.text=="string"){f.length&&(k.push({type:"reasoning",texts:f,startDate:i,endDate:b,isCompleted:c}),f=[],i=void 0,b=void 0,c=false),k.push({type:"text",text:d.text,startDate:d.startDate,endDate:d.endDate});continue}let h=d.type==="dynamic-tool",l=typeof d.type=="string"&&d.type.startsWith("tool-");if(h||l||d.type==="tool-call"){f.length&&(k.push({type:"reasoning",texts:f,startDate:i,endDate:b,isCompleted:c}),f=[],i=void 0,b=void 0,c=false);let a=String(h?d.toolName||"dynamic-tool":l?d.type?.slice(5)||"tool":d.toolName||"tool");a==="requestInput"?k.push({type:"tool",toolName:a,status:d.state||d.status,input:d.input,output:d.output,startDate:d.startDate,endDate:d.endDate,toolCallId:d.toolCallId}):k.push({type:"tool",toolName:a,status:d.state||d.status,input:d.input,output:d.output,startDate:d.startDate,endDate:d.endDate,toolCallId:d.toolCallId});continue}}return f.length&&k.push({type:"reasoning",texts:f,startDate:i,endDate:b,isCompleted:c}),k.length?jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px",direction:M?"rtl":"ltr"},children:[k.map((d,h)=>{let l=`${t}-${h}`,a=r.has(l);if(d.type==="reasoning"){let p=d.isCompleted||typeof d.startDate=="number"&&typeof d.endDate=="number",F=d.texts&&d.texts.length>0&&d.texts.some(_=>_.trim().length>0),W=()=>{F&&o(l);};return p&&!F?null:jsxRuntime.jsx("div",{onClick:W,style:{cursor:F?"pointer":"default",padding:"0"},children:jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:a?"4px":"0px"},children:[jsxRuntime.jsxs("div",{style:{fontSize:"13px",color:n.mutedTextColor,fontWeight:500,display:"flex",alignItems:"center",gap:"6px",overflow:"hidden",maxWidth:"100%",minWidth:0,width:"100%"},children:[jsxRuntime.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px"},children:[!p&&jsxRuntime.jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:n.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),jsxRuntime.jsx("span",{style:{color:n.textColor,fontWeight:600,opacity:.9,background:p?"none":`linear-gradient(90deg, ${n.textColor}, ${n.mutedTextColor}, ${n.mutedTextColor})`,backgroundSize:p?"auto":"200% 100%",backgroundClip:p?"unset":"text",WebkitBackgroundClip:p?"unset":"text",WebkitTextFillColor:p?n.mutedTextColor:"transparent",animation:p?void 0:"shimmer 2s ease-in-out infinite"},children:p?x?x("assistant.finishThinking"):"Finish Thinking":x?x("assistant.thinking"):"Thinking"})]}),F&&jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:a?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease-out"},children:jsxRuntime.jsx("polyline",{points:"9 18 15 12 9 6"})})]}),jsxRuntime.jsx("div",{style:{display:"grid",gridTemplateRows:a||!p?"1fr":"0fr",transition:"grid-template-rows 0.2s ease-out",overflow:"hidden"},children:jsxRuntime.jsx("div",{style:{minHeight:0},children:d.texts&&d.texts.length>0?jsxRuntime.jsx("div",{style:{fontSize:"13px",color:n.mutedTextColor,lineHeight:"1.6",maxWidth:"100%"},children:(!p&&a?d.texts:p?a?d.texts:[]:[d.texts[d.texts.length-1]]).map((_,te)=>jsxRuntime.jsx("div",{style:{marginBottom:"6px",opacity:.5},children:jsxRuntime.jsx(He,{content:_,theme:"dark",streaming:!p,dir:S})},`rg-line-${h}-${te}`))}):jsxRuntime.jsxs("div",{style:{fontSize:"12px",color:n.mutedTextColor,opacity:.7,display:"flex",alignItems:"center",gap:"8px"},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:n.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),jsxRuntime.jsx("span",{style:{letterSpacing:"2px",animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"},children:"..."})]})})})]})},l)}if(d.type==="text"){let p=typeof d.endDate!="number";return jsxRuntime.jsx("div",{style:{fontSize:"15px",color:n.textColor,lineHeight:"1.6",direction:M?"rtl":"ltr",textAlign:M?"right":"left"},children:jsxRuntime.jsx(He,{content:d.text,theme:"dark",streaming:p,dir:S})},l)}let{color:T,text:w}=po(d.status,x),v=d.status==="input-streaming"||d.status==="input-available";if(d.toolName==="requestInput")return jsxRuntime.jsx("div",{style:{display:"block",position:"relative"},children:jsxRuntime.jsx("div",{"data-get-from-user-host":d.toolCallId||l,style:{width:"100%"}})},l);let y=s?.[d.toolName||""];if(y)return jsxRuntime.jsx("div",{style:{display:"block",position:"relative"},children:jsxRuntime.jsx(yt,{componentName:d.toolName||"Unknown",resolvedColors:n,toolCallId:d.toolCallId,toolName:d.toolName||"unknown",onError:m,onSuccess:u,children:jsxRuntime.jsx(y,{toolName:d.toolName||"",toolCallId:d.toolCallId||"",input:d.input,output:d.output,status:d.status,addToolResult:C})})},l);let E=mo(d.toolName||"tool");return jsxRuntime.jsx("div",{style:{display:"flex",gap:"12px",position:"relative"},children:jsxRuntime.jsx("div",{style:{flex:1,minWidth:0},children:jsxRuntime.jsxs("div",{style:{fontSize:"13px",color:n.mutedTextColor,display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"},children:[jsxRuntime.jsxs("span",{style:{fontWeight:600,color:T,display:"flex",alignItems:"center",gap:"6px"},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:T,animation:v?"pulse 1.5s ease-in-out infinite":void 0}}),w]}),E.isMCP?jsxRuntime.jsxs("span",{style:{fontWeight:500,color:n.textColor},children:[jsxRuntime.jsx("span",{style:{fontWeight:600},children:E.toolName}),jsxRuntime.jsx("span",{style:{opacity:.7,margin:"0 4px"},children:"from"}),jsxRuntime.jsx("span",{style:{fontWeight:600,opacity:.85},children:E.mcpName})]}):jsxRuntime.jsx("span",{style:{fontWeight:500,color:n.textColor},children:go(E.toolName)})]})})},l)}),jsxRuntime.jsx("style",{children:`
|
|
169
|
+
`,document.head.appendChild(o);}Jr=true;}return t?(t.classList.add("as-arrow"),et||(et=client.createRoot(t),et.render(jsxRuntime.jsx(Zr,{arrowSvg:r.arrow,pointerSvg:r.pointer})))):(t=document.createElement("div"),t.id=e,t.className="fake-cursor as-arrow",t.style.position="fixed",t.style.left="20px",t.style.top="20px",document.body.appendChild(t),et=client.createRoot(t),et.render(jsxRuntime.jsx(Zr,{arrowSvg:r.arrow,pointerSvg:r.pointer}))),t}function Ne(e,t,r){return Math.max(t,Math.min(r,e))}function on(e){return e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2}function no(e){if(!e)return null;let t=document.createElement("canvas").getContext("2d");if(!t)return null;t.fillStyle="#000",t.fillStyle=e;let n=t.fillStyle.match(/rgba?\(([^)]+)\)/i);if(!n)return null;let o=n[1].split(/\s*,\s*/).map(Number),[s,g,u,C=1]=o;return {r:s,g,b:u,a:C}}function nn({r:e,g:t,b:r}){let n=[e,t,r].map(o=>o/255).map(o=>o<=.03928?o/12.92:Math.pow((o+.055)/1.055,2.4));return .2126*n[0]+.7152*n[1]+.0722*n[2]}function an(e){let t=e?no(e):null;return !t||t.a===0?false:nn(t)<.5}function sn(e,t){let r=document.elementFromPoint(e,t),n=new Set;for(;r&&!n.has(r);){n.add(r);let g=getComputedStyle(r).backgroundColor,u=no(g);if(u&&u.a>0)return g;r=r.parentElement;}return getComputedStyle(document.body).backgroundColor||"rgb(255,255,255)"}function qt(e,t,r){let n=sn(t,r),o=an(n),s=o?"#ffffff":"#000000";e.querySelectorAll("svg path").forEach(u=>{u.style.fill="white",u.style.stroke=s,u.style.strokeWidth="1";}),e.style.filter=o?"drop-shadow(0 1px 2px rgba(0,0,0,0.8))":"drop-shadow(0 1px 2px rgba(255,255,255,0.9))";}async function mt(e,t,r,n,o="ease-in-out",s="curve",g=.25,u="auto",C){oo(),_t(e);let T=performance.now(),y=o==="linear"?f=>f:on,I=s!=="straight",k={x:0,y:0};if(I){let f=r.x-t.x,i=r.y-t.y,b=Math.hypot(f,i)||1,c=(t.x+r.x)/2,d=(t.y+r.y)/2,h=-i/b,l=f/b,a=1;u==="left"?a=-1:u==="right"?a=1:a=Math.random()<.5?-1:1;let S=Ne(g,0,1)*b;k={x:c+a*h*S,y:d+a*l*S};}return new Promise(f=>{function i(b){let c=Ne((b-T)/n,0,1),d=y(c),h,l;if(I){let w=1-d;h=w*w*t.x+2*w*d*k.x+d*d*r.x,l=w*w*t.y+2*w*d*k.y+d*d*r.y;}else h=t.x+(r.x-t.x)*d,l=t.y+(r.y-t.y)*d;let S=.35*(1-d),v=Math.sin(b*.02)*S,x=Math.cos(b*.018)*S;e.style.left=`${h+v}px`,e.style.top=`${l+x}px`,qt(e,h+v,l+x),C&&C({x:h+v,y:l+x,t:c,now:b}),c<1?requestAnimationFrame(i):f();}requestAnimationFrame(i);})}function Qr(e,t){return {x:e.x+(t?.x??0),y:e.y+(t?.y??0)}}function he(e,t,r,n){let o={bubbles:true,cancelable:true,view:window,clientX:r.x,clientY:r.y,...n};try{let s=t==="pointerdown"||t==="mousedown",g=t==="pointerup"||t==="mouseup",u={button:0,buttons:s?1:0,isPrimary:!0,...o};if("PointerEvent"in window){let C=new PointerEvent(t,{pointerId:1,pointerType:"mouse",...u});e.dispatchEvent(C);}else {let C=new MouseEvent(t,u);e.dispatchEvent(C);}}catch{let s=new MouseEvent(t,o);e.dispatchEvent(s);}}function ao(e){return e&&typeof e=="object"&&e.nodeType===1}function ln(e){if(!e)return document;if(ao(e))return e;if(typeof e=="string"){let t=document.getElementById(e);if(t)return t;let r=document.querySelector(e);if(r)return r}return document}function eo(e){if(ao(e))return {kind:"element",element:e};if(typeof e=="string"){let t=document.getElementById(e);if(t)return {kind:"element",element:t};let r=document.querySelector(e);return {kind:r?"element":"position",element:r??null}}if(typeof e=="object"&&"position"in e)return {kind:"position",point:e.position};if(typeof e=="object"&&"selector"in e){let r=ln(e.within??null).querySelectorAll(e.selector),n=Math.max(0,Math.min(r.length-1,e.nth??0)),o=r[n]??null;return {kind:o?"element":"position",element:o}}return {kind:"position",point:{x:0,y:0}}}function to(e,t){let r=e.getBoundingClientRect();if(!t||t==="center")return {x:r.left+r.width/2,y:r.top+r.height/2};if(t==="top-left")return {x:r.left,y:r.top};if(t==="bottom-right")return {x:r.right,y:r.bottom};let n=Ne(t.x,0,1),o=Ne(t.y,0,1);return {x:r.left+r.width*n,y:r.top+r.height*o}}function ro(e){return {x:Ne(e.x,0,window.innerWidth),y:Ne(e.y,0,window.innerHeight)}}function dn(){return To.useEffect(()=>(window.__cursorGuide=async(e,t={})=>{let r=Array.isArray(e)?e:[{target:e,action:t.action??"none",options:t}],n=[],o=await rn();o.classList.add("visible","as-arrow"),o.classList.remove("as-pointer","pressing"),_t(o),oo();let s=parseFloat(o.style.left||"20")||20,g=parseFloat(o.style.top||"20")||20;qt(o,s,g);for(let u of r){let{durationMs:C=800,easing:T="ease-in-out",offset:y,highlight:I=true,path:k="curve",curveStrength:f=.25,curveDirection:i="auto",anchor:b,cursorHotspot:c,dragTo:d}=u.options??{},h=u.action??u.options?.action??"none",l=performance.now(),a=eo(u.target),S=null,v=null;if(a.kind==="element"&&a.element?(v=a.element,o.classList.remove("visible"),v.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),await Zo(v,1500,180),_t(o),S=to(v,b)):a.kind==="position"&&a.point&&(S=a.point),!S){n.push({ok:false,action:h,targetKind:a.kind,durationMs:Math.round(performance.now()-l),error:"Target not found"});continue}let x={x:parseFloat(o.style.left||"20")||20,y:parseFloat(o.style.top||"20")||20},w=ro(Qr(S,y));await mt(o,x,w,C,T,k,f,i);let M=w.x-x.x,p=w.y-x.y,F=Math.hypot(M,p)||1,G=M/F,_=p/F,re=Math.min(6,Math.max(3,F*.02)),le={x:w.x+G*re,y:w.y+_*re};await mt(o,w,le,Math.max(70,C*.1),"ease-out","straight",0,"right"),await mt(o,le,w,120,"ease-out","straight",0,"left"),I&&(o.classList?.add("click"),setTimeout(()=>o.classList?.remove("click"),180));let oe=null;try{if(h==="click"){o.classList.remove("as-arrow"),o.classList.add("as-pointer","pressing");let O={x:c?.x??0,y:c?.y??0},j={x:w.x+O.x,y:w.y+O.y};o.style.left=`${j.x}px`,o.style.top=`${j.y}px`,qt(o,j.x,j.y);let K=v??document.elementFromPoint(j.x,j.y)??document.body;he(K,"pointerdown",j),he(K,"mousedown",j),await new Promise(D=>setTimeout(D,90)),o.classList.remove("pressing"),he(K,"mouseup",j),he(K,"click",j),setTimeout(()=>{o.classList.remove("as-pointer"),o.classList.add("as-arrow");},140),K instanceof HTMLElement&&K.focus?.(),oe=K?.id??null;}else if(h==="drag"){if(!d)throw new Error("dragTo is required for action 'drag'");let O=eo(d),j=null;if(O.kind==="element"&&O.element&&(j=to(O.element,b)),O.kind==="position"&&O.point&&(j=O.point),!j)throw new Error("dragTo target not found");let K=ro(Qr(j,y)),D={x:w.x,y:w.y},fe=v??document.elementFromPoint(D.x,D.y)??document.body;o.classList.remove("as-arrow"),o.classList.add("as-pointer","pressing"),he(fe,"pointerdown",D),he(fe,"mousedown",D),await mt(o,D,K,Math.max(200,C),T,k,f,i,({x:ee,y:be})=>{let ye=document.elementFromPoint(ee,be)??document.body,Te={x:ee,y:be};he(ye,"pointermove",Te),he(ye,"mousemove",Te);});let J=document.elementFromPoint(K.x,K.y)??document.body;o.classList.remove("pressing"),he(J,"pointerup",K),he(J,"mouseup",K);}n.push({ok:!0,action:h,targetKind:a.kind,durationMs:Math.round(performance.now()-l),clickedElementId:oe});}catch(O){n.push({ok:false,action:h,targetKind:a.kind,durationMs:Math.round(performance.now()-l),error:O?.message??String(O)});}}return Yo(o,2e3),{ok:n.every(u=>u.ok),steps:n}},()=>{try{delete window.__cursorGuide;}catch{window.__cursorGuide=void 0;}}),[]),null}var tt=dn;function io(){return {getDomComponents:{tool:async({includeHidden:e,selector:t})=>await Ze({includeHidden:e,selector:t}),executeEachToken:false},controlCursor:{tool:async({target:e,action:t,anchor:r,durationMs:n,dragTo:o})=>{let s=await Ae(e,{action:t,anchor:r,durationMs:n,dragTo:o});if(s&&s.ok){let g=Array.isArray(s.steps)&&s.steps.length?s.steps[s.steps.length-1]:void 0,u=g?.clickedElementId?` (clicked element id: ${g.clickedElementId})`:"",C=t||g?.action||"none";return {success:true,message:C==="click"?`Cursor moved and clicked successfully${u}`:C==="drag"?"Cursor dragged successfully":"Cursor moved successfully",details:s}}return {success:false,message:"Cursor action failed",details:s}},executeEachToken:false},fillActiveInput:{tool:async({value:e})=>{let t=await Qe(e);return {success:!!t?.ok,message:t?.ok?"Active input filled successfully":t?.errors?.[0]||"Failed to fill active input",details:t}},executeEachToken:true},requestInput:{tool:async e=>({ok:true}),executeEachToken:true}}}function pn({input:e}){return jsxRuntime.jsx("div",{style:{fontSize:"14px",lineHeight:"1.6",width:"100%"},children:jsxRuntime.jsx(Be,{content:e?.text||"",theme:"dark"})})}function lo(){return {plainText:pn}}function co(e,t,r,n,o,s){let g=r.get(t);if(g){let a=g.parentElement,S=document.querySelector(`[data-get-from-user-host="${t}"]`);if(S&&a!==S){try{a?.removeChild(g);}catch{}S.innerHTML="",S.appendChild(g);}}else {g=document.createElement("div"),g.className="hsafa-inline-form";let a=document.querySelector(`[data-get-from-user-host="${t}"]`);a?(a.innerHTML="",a.appendChild(g)):(document.querySelector(".chat-scroll-container")||document.body).appendChild(g),r.set(t,g);}let u=e?.title||"Provide input",C=e?.description||"",T=e?.submitLabel||"Submit",y=e?.skipLabel||"Skip",I=Array.isArray(e?.fields)?e.fields:e?.label||e?.placeholder?[{id:"value",label:e?.label||"Value",type:"text",placeholder:e?.placeholder||""}]:[],k=n.get(t)||{submitted:false,skipped:false,values:void 0};g.innerHTML="";let f=document.createElement("form");f.style.margin="12px 0",f.style.padding="14px",f.style.border="1px solid var(--hsafa-border, #2A2C33)",f.style.borderRadius="12px",f.style.background="var(--hsafa-card, #121318)",f.style.color="var(--hsafa-text, #EDEEF0)",f.style.boxShadow="0 6px 20px rgba(0,0,0,0.25)";let i=document.createElement("div");if(i.style.fontWeight="600",i.style.marginBottom="6px",i.textContent=u,f.appendChild(i),C){let a=document.createElement("div");a.style.fontSize="12px",a.style.opacity="0.8",a.style.marginBottom="10px",a.textContent=C,f.appendChild(a);}I.forEach(a=>{let S=document.createElement("div");if(S.style.margin="10px 0",a.label){let p=document.createElement("label");p.style.display="block",p.style.fontSize="12px",p.style.marginBottom="6px",p.style.opacity="0.9",p.textContent=a.label,S.appendChild(p);}let v,x=(a.type||"text").toLowerCase();if(x==="textarea"){let p=document.createElement("textarea");p.placeholder=a.placeholder||"",p.value=a.value??"",p.style.width="100%",p.style.minHeight="72px",p.style.padding="10px 12px",p.style.border="1px solid var(--hsafa-border, #2A2C33)",p.style.borderRadius="10px",p.style.background="var(--hsafa-input-bg, #17181C)",p.style.color="inherit",v=p;}else if(x==="select"&&Array.isArray(a.options)){let p=document.createElement("select");p.style.width="100%",p.style.padding="10px 12px",p.style.border="1px solid var(--hsafa-border, #2A2C33)",p.style.borderRadius="10px",p.style.background="var(--hsafa-input-bg, #17181C)",p.style.color="inherit",a.options.forEach(F=>{let G=document.createElement("option");G.value=String(F.value),G.text=String(F.label??F.value),p.appendChild(G);}),p.value=a.value??"",v=p;}else if(x==="checkbox"){let p=document.createElement("input");p.type="checkbox",p.checked=!!a.value,p.style.transform="scale(1.1)",v=p;}else {let p=document.createElement("input");p.type=x,p.placeholder=a.placeholder||"",p.value=a.value??"",p.style.width="100%",p.style.padding="10px 12px",p.style.border="1px solid var(--hsafa-border, #2A2C33)",p.style.borderRadius="10px",p.style.background="var(--hsafa-input-bg, #17181C)",p.style.color="inherit",v=p;}let w=a.id||"value";v.dataset.fieldId=w;let M=k.values&&Object.prototype.hasOwnProperty.call(k.values,w)?k.values[w]:void 0;typeof M<"u"&&(v.type==="checkbox"?v.checked=!!M:v.value=String(M)),(k.submitted||k.skipped)&&(v.setAttribute("disabled","true"),v.style.opacity="0.7"),S.appendChild(v),f.appendChild(S);});let b=String(T).trim(),c=String(y).trim(),d=!!(b||c),h=null,l=null;if(d){let a=document.createElement("div");a.style.display="flex",a.style.gap="8px",a.style.marginTop="10px",h=document.createElement("button"),h.type="submit",h.textContent=b||"Submit",h.style.padding="6px 10px",h.style.borderRadius="8px",h.style.background="var(--hsafa-button-bg, var(--hsafa-primary, #2563eb))",h.style.color="#000000",l=document.createElement("button"),l.type="button",l.textContent=c||"Skip",l.style.padding="6px 10px",l.style.borderRadius="8px",l.style.background="transparent",l.style.border="1px solid var(--hsafa-border, #2A2C33)",l.style.color="inherit",a.appendChild(h),a.appendChild(l),f.appendChild(a);}if(f.onsubmit=a=>{a.preventDefault();let S={};f.querySelectorAll("[data-field-id]").forEach(v=>{let x=v.dataset.fieldId||"value";v.type==="checkbox"?S[x]=v.checked:S[x]=v.value??"";}),n.set(t,{submitted:true,skipped:false,values:S}),o({tool:"requestInput",toolCallId:t,output:{success:true,submitted:true,values:S}}),f.querySelectorAll("[data-field-id]").forEach(v=>{v.disabled=true,v.style.opacity="0.7";}),h&&(h.textContent=`${b||"Submit"} \u2713`,h.style.opacity="0.8",h.disabled=true),l&&(l.disabled=true);},l&&(l.onclick=()=>{n.set(t,{submitted:false,skipped:true,values:void 0}),o({tool:"requestInput",toolCallId:t,output:{success:true,submitted:false,skipped:true}}),f.querySelectorAll("[data-field-id]").forEach(a=>{a.disabled=true,a.style.opacity="0.7";}),l&&(l.textContent=`${c||"Skip"} \u2713`,l.style.opacity="0.8",l.disabled=true),h&&(h.disabled=true);}),k.submitted||k.skipped){let a=document.createElement("div");a.style.marginTop="10px",a.style.fontSize="12px",a.style.display="flex",a.style.alignItems="center",a.style.gap="8px";let S=document.createElement("span");S.style.display="inline-flex",S.style.alignItems="center",S.style.padding="2px 8px",S.style.borderRadius="999px",S.style.fontWeight="600",S.style.fontSize="11px",k.submitted?(S.style.background="rgba(16,185,129,0.15)",S.style.color="#10b981",S.textContent="Submitted"):(S.style.background="rgba(234,179,8,0.15)",S.style.color="#eab308",S.textContent="Skipped"),a.appendChild(S),f.appendChild(a);try{h&&(h.disabled=!0,h.style.opacity="0.8",k.submitted&&(h.textContent=`${b||"Submit"} \u2713`)),l&&(l.disabled=!0,l.style.opacity="0.8",k.skipped&&(l.textContent=`${c||"Skip"} \u2713`));}catch{}}g.appendChild(f);}function uo(e,t,r){let n=To.useRef(new Map),o=To.useRef(new Map),s=To.useRef(t),g=To.useRef(r);s.current=t,g.current=r,To.useEffect(()=>{e.forEach(u=>{u.role==="assistant"&&u.parts?.forEach(C=>{if(!C.toolCallId)return;let T=C.toolName;if(!T&&C.type?.startsWith("tool-")&&(T=C.type.replace(/^tool-/,"")),!T)return;let y=s.current[T];if(y&&typeof y=="object"&&y.executeEachToken&&y.tool){let I=C.input||C.args||{},k=JSON.stringify(I),f=n.current.get(C.toolCallId);if(k!==f&&k!=="{}"){n.current.set(C.toolCallId,k);try{if(T==="requestInput")g.current(I,C.toolCallId);else {let b=(o.current.get(C.toolCallId)||0)+1;o.current.set(C.toolCallId,b),b>1&&y.tool({...I,toolCallNumber:b-1});}}catch{}}}});});},[e]);}function Vt(e){let{agentId:t,baseUrl:r="",tools:n={},uiComponents:o={},onStart:s,onFinish:g,onError:u,initialMessages:C=[],onMessagesChange:T,controlledChatId:y,onChatIdChange:I,templateParams:k}=e,{baseUrl:f,setCurrentChatId:i}=ce(),b=r&&r.length>0?r:f||"",[c,d]=To.useState(""),[h,l]=To.useState(()=>`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`),a=y??h,S=To.useCallback(A=>{y===void 0&&l(A),I&&I(A);},[y,I]);To.useEffect(()=>{try{i(a);}catch{}return ()=>{try{i(void 0);}catch{}}},[a,i]);let v=To.useMemo(()=>Kr(b,t,a,k),[b,t,a,k]),x=To.useCallback(A=>{console.log("Message finished:",A);let z=A?.message?.id;if(!z&&Array.isArray(A?.messages))for(let B=A.messages.length-1;B>=0;B--){let N=A.messages[B];if(N&&N.role==="assistant"&&N.id){z=N.id;break}}g?.({...A,chatId:a,assistantMessageId:z});},[g,a]),w=To.useCallback(A=>{console.error("Chat error:",A),u?.(A);},[u]),M=To.useMemo(()=>io(),[]),p=To.useMemo(()=>({...M,...n}),[M,n]),F=To.useMemo(()=>lo(),[]),G=To.useMemo(()=>({...F,...o}),[F,o]),_=To.useRef(new Map),re=To.useRef(new Map),le=To.useCallback(()=>{try{_.current.forEach(A=>{try{A.remove();}catch{}}),_.current.clear(),re.current.clear();}catch{}},[]),oe=To.useCallback((A,z)=>{co(A,z,_.current,re.current,B=>O.current.addToolResult(B));},[]),O=To.useRef(null),j=To.useRef(new Set),K=To.useCallback((A,z,B)=>{console.error(`UI Error [${z}]:`,B),O.current&&j.current.has(A)&&(j.current.delete(A),O.current.addToolResult({tool:z,toolCallId:A,state:"output-error",errorText:B?.message||String(B)}));},[]),D=To.useCallback((A,z)=>{O.current&&j.current.has(A)&&(j.current.delete(A),O.current.addToolResult({tool:z,toolCallId:A,output:{status:"ok",rendered:true,component:z,logs:[]}}));},[]),fe=To.useCallback(A=>{let z=p[A];return z?typeof z=="object"&&"tool"in z?z.tool:typeof z=="function"?z:null:null},[p]),J=react.useChat({transport:v,onFinish:x,onError:w,experimental_throttle:10,sendAutomaticallyWhen:ai.lastAssistantMessageIsCompleteWithToolCalls,async onToolCall({toolCall:A}){let z=fe(A.toolName);if(A.toolName==="requestInput"){try{oe(A.input,A.toolCallId);}catch(ae){console.error("requestInput render error",ae);}return}let B=A.toolName==="ui";A?.input;let ne=G&&A.toolName in G;if(B||ne){j.current.add(A.toolCallId);return}if(z)try{let ae=await z(A.input);J.addToolResult({tool:A.toolName,toolCallId:A.toolCallId,output:ae});}catch(ae){J.addToolResult({tool:A.toolName,toolCallId:A.toolCallId,state:"output-error",errorText:ae?.message||String(ae)});}}}),{messages:ee,sendMessage:be,status:ye,stop:Te,error:Et}=J;O.current=J;let st=To.useRef(new Set);uo(ee,p,oe),To.useEffect(()=>{try{let A=new Set,z=[];if(ee.forEach(B=>{B.role==="assistant"&&(B.parts||[]).forEach(N=>{if((N?.toolName||(typeof N?.type=="string"&&N.type.startsWith("tool-")?String(N.type.replace(/^tool-/,"")):void 0))!=="requestInput")return;let ae=N?.toolCallId||"";if(!ae)return;A.add(ae);let E=N?.output;if(E&&(E.submitted||E.skipped||E.values)){let Rt={submitted:!!E.submitted,skipped:!!E.skipped,values:E.values||void 0};re.current.set(ae,Rt);}let $=N?.input||N?.args||{};z.push({input:$,toolCallId:ae});});}),_.current.forEach((B,N)=>{if(!A.has(N)){let ne=_.current.get(N);try{ne?.remove();}catch{}_.current.delete(N),re.current.delete(N);}}),z.length>0){let B=requestAnimationFrame(()=>{z.forEach(({input:N,toolCallId:ne})=>{try{oe(N,ne);}catch{}});});return ()=>cancelAnimationFrame(B)}}catch{}},[ee,oe]),To.useEffect(()=>{if(!(!C||C.length===0)&&ee.length===0&&!st.current.has(a)){st.current.add(a);try{J?.setMessages?.(C);}catch{}}},[C,ee.length,a,J]);let Ie=ye==="submitted"||ye==="streaming",Ue=To.useCallback(()=>{T&&T(ee,a);},[T,ee,a]),Oe=To.useCallback(async A=>{let z=A?.text!==void 0?A.text:c,B=A?.files||[],N=z.trim();if(!(!N&&B.length===0)&&!Ie){A?.text===void 0&&d("");try{if(s){let ne={role:"user",content:N,createdAt:Date.now(),chatId:a};s(ne);}await be({text:N,files:B});}catch(ne){throw console.error("Failed to send message:",ne),ne}}},[c,Ie,be,s,a]),Z=To.useCallback(()=>{if(Ie)return;le(),d("");try{J?.setMessages?.([]);}catch{}let A=`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`;S(A);},[Ie,J,le,S]),sr=To.useCallback(A=>{try{J?.setMessages?.(A);}catch{}},[J]);return {input:c,setInput:d,messages:ee,isLoading:Ie,status:ye,error:Et,sendMessage:Oe,stop:Te,newChat:Z,setMessages:sr,notifyMessagesChange:Ue,chatApi:J,chatId:a,setChatId:S,tools:p,uiComponents:G,formHostRef:_,formStateRef:re,cleanupForms:le,onUISuccess:D,onUIError:K}}function xt(e){let t=`hsafaChat_${e}`,r=`${t}.chats`,n=l=>`${t}.chat.${l}`,o=`${t}.currentChatId`,s=`${t}.showChat`,g=()=>{try{let l=localStorage.getItem(r);return l?JSON.parse(l):[]}catch{return []}},u=l=>{try{localStorage.setItem(r,JSON.stringify(l));}catch{}},C=l=>{try{let a=localStorage.getItem(n(l));return a?JSON.parse(a):null}catch{return null}},T=l=>{try{localStorage.setItem(n(l.id),JSON.stringify(l));}catch{}},y=l=>{let a=g(),S=a.findIndex(v=>v.id===l.id);S>=0?a[S]=l:a.unshift(l),u(a);},I=l=>{let S=g().filter(v=>v.id!==l);u(S);},k=l=>{try{localStorage.removeItem(n(l));}catch{}};return {loadChatsIndex:g,saveChatsIndex:u,loadChat:C,saveChat:T,upsertChatMeta:y,deleteChatMeta:I,deleteChatData:k,deleteChat:l=>{k(l),I(l);},loadShowChatPreference:l=>{try{let a=localStorage.getItem(s);return a!==null?a==="true":l}catch{return l}},saveShowChatPreference:l=>{try{localStorage.setItem(s,String(l));}catch{}},loadCurrentChatId:()=>{try{return localStorage.getItem(o)}catch{return null}},saveCurrentChatId:l=>{try{localStorage.setItem(o,l);}catch{}},removeCurrentChatId:()=>{try{localStorage.removeItem(o);}catch{}}}}function Yt(e){let{agentId:t,chatId:r,messages:n,isLoading:o=false,autoSave:s=true,autoRestore:g=true}=e,u=To.useMemo(()=>xt(t),[t]),[C,T]=To.useState([]),[y,I]=To.useState(null),k=To.useRef(false),f=To.useRef(false),i=To.useCallback(()=>{try{let v=u.loadChatsIndex();T(v);let x=v.find(w=>w.id===r);I(x||null);}catch(v){console.error("Failed to refresh chat list:",v);}},[u,r]);To.useEffect(()=>{i();},[i]),To.useEffect(()=>{if(!(!g||f.current)){try{u.loadCurrentChatId()&&(k.current=!0);}catch(v){console.error("Failed to restore chat:",v);}f.current=true;}},[u,g]),To.useEffect(()=>{if(!(!s||n.length===0))if(k.current){if(!o){let v=Date.now();try{u.saveChat({id:r,messages:n,agentId:t});let w=u.loadChatsIndex().find(M=>M.id===r);w&&(u.upsertChatMeta({...w,updatedAt:v}),i());}catch(x){console.error("Failed to save chat:",x);}}}else {let v=n.find(x=>x.role==="user");if(v){let x="";if(Array.isArray(v.parts)){let p=v.parts.find(F=>F&&F.type==="text");x=p&&typeof p.text=="string"?p.text:"";}let w=(x||"New chat").slice(0,80),M=Date.now();try{u.upsertChatMeta({id:r,title:w,createdAt:M,updatedAt:M}),u.saveChat({id:r,messages:n,agentId:t}),u.saveCurrentChatId(r),k.current=!0,i();}catch(p){console.error("Failed to create chat:",p);}}}},[]);let b=To.useRef(false);To.useEffect(()=>{if(o){b.current=true;return}if(b.current&&s){b.current=false;try{let v=Date.now();u.saveChat({id:r,messages:n,agentId:t});let w=u.loadChatsIndex().find(M=>M.id===r);if(w)u.upsertChatMeta({...w,updatedAt:v});else {let M="",p=Array.isArray(n)?n.find(G=>G&&G.role==="user"):void 0;if(p&&Array.isArray(p.parts)){let G=p.parts.find(_=>_&&_.type==="text");M=G&&typeof G.text=="string"?G.text:"";}let F=(M||"New chat").slice(0,80);u.upsertChatMeta({id:r,title:F,createdAt:v,updatedAt:v});try{u.saveCurrentChatId(r);}catch{}k.current=!0;}i();}catch(v){console.error("Failed to save chat on completion:",v);}}},[o,n,r,t,u,s,i]);let c=To.useCallback(v=>{try{let x=u.loadChat(v);return x?{id:x.id,messages:x.messages,agentId:x.agentId||t}:null}catch(x){return console.error("Failed to load chat:",x),null}},[u,t]),d=To.useCallback(()=>{if(n.length!==0)try{let v=Date.now();u.saveChat({id:r,messages:n,agentId:t});let w=u.loadChatsIndex().find(M=>M.id===r);w&&(u.upsertChatMeta({...w,updatedAt:v}),i());}catch(v){console.error("Failed to save chat:",v);}},[u,r,n,t,i]),h=To.useCallback(v=>{try{u.deleteChat(v),i();}catch(x){console.error("Failed to delete chat:",x);}},[u,i]),l=To.useCallback((v,x)=>{if(v!==r)try{k.current=!0,u.saveCurrentChatId(v);let w=u.loadChat(v),M=w&&Array.isArray(w.messages)?w.messages:[];x(M),i();}catch(w){console.error("Failed to switch chat:",w);}},[u,r,i]),a=To.useCallback(v=>{k.current=false,v();},[]),S=To.useCallback(v=>{if(!v.trim())return C;let x=v.toLowerCase();return C.filter(w=>w.title.toLowerCase().includes(x))},[C]);return {chatList:C,currentChatMeta:y,refreshChatList:i,loadChat:c,saveCurrentChat:d,deleteChat:h,switchToChat:l,createNewChat:a,searchChats:S,storage:u}}function yn(e){let{messages:t,isLoading:r,sendMessage:n,setMessages:o,baseUrl:s}=e,{baseUrl:g}=ce(),u=s||g||"",[C,T]=To.useState(null),[y,I]=To.useState(""),[k,f]=To.useState([]),[i,b]=To.useState(false),c=To.useCallback((v,x,w=[])=>{T(v),I(x),f(w);},[]),d=To.useCallback(()=>{T(null),I(""),f([]);},[]),h=To.useCallback(async v=>{if(!r)try{let x=t.findIndex(M=>M.id===v);if(x===-1)return;let w=t.slice(0,x);o(w),await n({text:y.trim(),files:k.map(M=>({type:"file",url:M.url,mediaType:M.mimeType||"application/octet-stream",...M.name?{name:M.name}:{},...M.size?{size:M.size}:{}}))}),d();}catch(x){throw console.error("Failed to save edit:",x),x}},[r,t,n,y,k,o,d]),l=To.useCallback(v=>C===v,[C]),a=To.useCallback(async v=>{if(!u){console.warn("baseUrl not provided, cannot upload attachments");return}b(true);try{let x=Array.from(v).map(async M=>{if(M.size>26214400)throw new Error(`${M.name} is too large (max 25MB)`);let p=new FormData;p.append("file",M);let F=await fetch(`${u}/api/upload`,{method:"POST",body:p});if(!F.ok)throw new Error(`Upload failed: ${F.statusText}`);let G=await F.json();return {id:G.url||`${Date.now()}-${Math.random()}`,name:M.name,url:G.url,mimeType:M.type,size:M.size}}),w=await Promise.all(x);f(M=>[...M,...w]);}catch(x){throw console.error("Failed to upload files:",x),x}finally{b(false);}},[u]),S=To.useCallback(v=>{f(x=>x.filter(w=>w.id!==v));},[]);return {editingMessageId:C,editingText:y,setEditingText:I,editAttachments:k,setEditAttachments:f,editUploading:i,startEdit:c,cancelEdit:d,saveEdit:h,isEditing:l,addEditAttachments:a,removeEditAttachment:S}}function X({IconComponent:e,...t}){return To__default.default.createElement(e,t)}function Jt({icon:e,onClick:t,ariaLabel:r,resolvedColors:n,disabled:o=false,title:s}){return jsxRuntime.jsx("button",{"aria-label":r,title:s,disabled:o,style:{backgroundColor:"transparent",color:n.mutedTextColor,border:"none",borderRadius:"8px",padding:"8px",cursor:o?"not-allowed":"pointer",opacity:o?.5:1,transition:"all 0.2s ease-out",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:g=>{o||(g.currentTarget.style.backgroundColor=n.hoverBackground,g.currentTarget.style.color=n.textColor);},onMouseLeave:g=>{g.currentTarget.style.backgroundColor="transparent",g.currentTarget.style.color=n.mutedTextColor;},onClick:t,children:e})}function fo({title:e,alwaysOpen:t,streaming:r,dir:n,resolvedColors:o,onNew:s,onToggleHistory:g,onClose:u,historyBtnRef:C,t:T}){return jsxRuntime.jsxs("div",{style:{marginBottom:"24px",display:"flex",alignItems:"center",justifyContent:"space-between",direction:n==="rtl"?"rtl":"ltr"},children:[jsxRuntime.jsx("div",{style:{minWidth:"0"},children:jsxRuntime.jsx("h1",{title:e,style:{color:o.textColor,fontSize:"18px",fontWeight:"600",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",margin:"0"},children:e})}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",position:"relative",color:o.mutedTextColor},children:[jsxRuntime.jsx(Jt,{icon:jsxRuntime.jsx(X,{IconComponent:lucideReact.Plus,size:"20",strokeWidth:"2"}),onClick:()=>{r||s();},ariaLabel:T("header.new"),resolvedColors:o,disabled:r}),jsxRuntime.jsx("button",{ref:C,"aria-label":T("header.history"),style:{backgroundColor:"transparent",color:o.mutedTextColor,border:"none",borderRadius:"8px",padding:"8px",cursor:"pointer",transition:"all 0.2s ease-out",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:y=>{y.currentTarget.style.backgroundColor=o.hoverBackground,y.currentTarget.style.color=o.textColor;},onMouseLeave:y=>{y.currentTarget.style.backgroundColor="transparent",y.currentTarget.style.color=o.mutedTextColor;},onClick:g,children:jsxRuntime.jsx(X,{IconComponent:lucideReact.History,size:"20",strokeWidth:"2"})}),!t&&jsxRuntime.jsx(Jt,{icon:jsxRuntime.jsx(X,{IconComponent:lucideReact.ChevronRight,size:"20",strokeWidth:"2",style:{transform:n==="rtl"?"rotate(180deg)":"none"}}),onClick:u,ariaLabel:T("header.close"),resolvedColors:o})]})]})}var wt=class extends To.Component{constructor(t){super(t),this.state={hasError:false,error:null,errorInfo:null};}static getDerivedStateFromError(t){return {hasError:true,error:t,errorInfo:null}}componentDidMount(){let{toolCallId:t,toolName:r,onSuccess:n}=this.props;t&&r&&n&&!this.state.hasError&&setTimeout(()=>{this.state.hasError||n(t,r);},0);}componentDidCatch(t,r){console.error(`UI Component Error (${this.props.componentName}):`,t,r),this.setState({error:t,errorInfo:r});let{toolCallId:n,toolName:o,onError:s}=this.props;n&&o&&s&&s(n,o,t);}render(){if(this.state.hasError&&this.state.error){let{resolvedColors:t,componentName:r}=this.props;return jsxRuntime.jsxs("div",{style:{padding:"16px",backgroundColor:t.errorColorLight,border:`2px solid ${t.errorColor}`,borderRadius:"12px",color:t.errorColorDark},children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},children:[jsxRuntime.jsx("span",{style:{fontSize:"20px"},children:"\u26A0\uFE0F"}),jsxRuntime.jsxs("strong",{style:{fontSize:"16px"},children:["Component Error: ",r]})]}),jsxRuntime.jsx("div",{style:{fontSize:"14px",marginBottom:"8px",fontFamily:"monospace"},children:this.state.error.message}),this.state.errorInfo&&jsxRuntime.jsxs("details",{style:{fontSize:"12px",marginTop:"8px"},children:[jsxRuntime.jsx("summary",{style:{cursor:"pointer",fontWeight:"bold"},children:"Stack Trace"}),jsxRuntime.jsx("pre",{style:{marginTop:"8px",padding:"8px",backgroundColor:t.errorColorLight,borderRadius:"4px",overflow:"auto",maxHeight:"200px",fontSize:"11px"},children:this.state.errorInfo.componentStack})]})]})}return this.props.children}};var Tn=(e,t,r)=>{let n={"input-streaming":{color:r?.warningColor||"#eab308",text:t?t("tool.inputting"):"Inputting"},"input-available":{color:r?.infoColor||"#3b82f6",text:t?t("tool.running"):"Running"},error:{color:r?.errorColor||"#ef4444",text:t?t("tool.error"):"Error"},"output-available":{color:r?.successColor||"#10b981",text:t?t("tool.called"):"Called"},finished:{color:r?.successColor||"#10b981",text:t?t("tool.called"):"Called"}};return n[e||"output-available"]||n["output-available"]},In=e=>{let t=/^(.+?)_([a-f0-9]{6})_(.+)$/,r=e.match(t);if(r){let[,n,,o]=r;return {isMCP:true,mcpName:n.replace(/_/g," "),toolName:o.replace(/_/g," ")}}return {isMCP:false,toolName:e}},Sn=e=>e.replace(/_/g," ").replace(/-/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\b\w/g,t=>t.toUpperCase());function ho({parts:e,messageId:t,openReasoningIds:r,toggleReasoning:n,resolvedColors:o,HsafaUI:s,onUIError:g,onUISuccess:u,addToolResult:C,dir:T="ltr",t:y}){let I=T==="rtl",k=[],f=[],i,b,c=false;for(let d of Array.isArray(e)?e:[]){if(!d)continue;if(d.type==="reasoning"&&typeof d.text=="string"){f.push(d.text),i||(i=d.startDate),b=d.endDate,d.state==="done"&&(c=true);continue}if(d.type==="text"&&typeof d.text=="string"){f.length&&(k.push({type:"reasoning",texts:f,startDate:i,endDate:b,isCompleted:c}),f=[],i=void 0,b=void 0,c=false),k.push({type:"text",text:d.text,startDate:d.startDate,endDate:d.endDate});continue}let h=d.type==="dynamic-tool",l=typeof d.type=="string"&&d.type.startsWith("tool-");if(h||l||d.type==="tool-call"){f.length&&(k.push({type:"reasoning",texts:f,startDate:i,endDate:b,isCompleted:c}),f=[],i=void 0,b=void 0,c=false);let a=String(h?d.toolName||"dynamic-tool":l?d.type?.slice(5)||"tool":d.toolName||"tool");a==="requestInput"?k.push({type:"tool",toolName:a,status:d.state||d.status,input:d.input,output:d.output,startDate:d.startDate,endDate:d.endDate,toolCallId:d.toolCallId}):k.push({type:"tool",toolName:a,status:d.state||d.status,input:d.input,output:d.output,startDate:d.startDate,endDate:d.endDate,toolCallId:d.toolCallId});continue}}return f.length&&k.push({type:"reasoning",texts:f,startDate:i,endDate:b,isCompleted:c}),k.length?jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px",direction:I?"rtl":"ltr"},children:[k.map((d,h)=>{let l=`${t}-${h}`,a=r.has(l);if(d.type==="reasoning"){let p=d.isCompleted||typeof d.startDate=="number"&&typeof d.endDate=="number",F=d.texts&&d.texts.length>0&&d.texts.some(_=>_.trim().length>0),G=()=>{F&&n(l);};return p&&!F?null:jsxRuntime.jsx("div",{onClick:G,style:{cursor:F?"pointer":"default",padding:"0"},children:jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:a?"4px":"0px"},children:[jsxRuntime.jsxs("div",{style:{fontSize:"13px",color:o.mutedTextColor,fontWeight:500,display:"flex",alignItems:"center",gap:"6px",overflow:"hidden",maxWidth:"100%",minWidth:0,width:"100%"},children:[jsxRuntime.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px"},children:[!p&&jsxRuntime.jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),jsxRuntime.jsx("span",{style:{color:o.textColor,fontWeight:600,opacity:.9,background:p?"none":`linear-gradient(90deg, ${o.textColor}, ${o.mutedTextColor}, ${o.mutedTextColor})`,backgroundSize:p?"auto":"200% 100%",backgroundClip:p?"unset":"text",WebkitBackgroundClip:p?"unset":"text",WebkitTextFillColor:p?o.mutedTextColor:"transparent",animation:p?void 0:"shimmer 2s ease-in-out infinite"},children:p?y?y("assistant.finishThinking"):"Finish Thinking":y?y("assistant.thinking"):"Thinking"})]}),F&&jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:a?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease-out"},children:jsxRuntime.jsx("polyline",{points:"9 18 15 12 9 6"})})]}),jsxRuntime.jsx("div",{style:{display:"grid",gridTemplateRows:a||!p?"1fr":"0fr",transition:"grid-template-rows 0.2s ease-out",overflow:"hidden"},children:jsxRuntime.jsx("div",{style:{minHeight:0},children:d.texts&&d.texts.length>0?jsxRuntime.jsx("div",{style:{fontSize:"13px",color:o.mutedTextColor,lineHeight:"1.6",maxWidth:"100%"},children:(!p&&a?d.texts:p?a?d.texts:[]:[d.texts[d.texts.length-1]]).map((_,re)=>jsxRuntime.jsx("div",{style:{marginBottom:"6px",opacity:.5},children:jsxRuntime.jsx(Be,{content:_,theme:"dark",streaming:!p,dir:T})},`rg-line-${h}-${re}`))}):jsxRuntime.jsxs("div",{style:{fontSize:"12px",color:o.mutedTextColor,opacity:.7,display:"flex",alignItems:"center",gap:"8px"},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),jsxRuntime.jsx("span",{style:{letterSpacing:"2px",animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"},children:"..."})]})})})]})},l)}if(d.type==="text"){let p=typeof d.endDate!="number";return jsxRuntime.jsx("div",{style:{fontSize:"15px",color:o.textColor,lineHeight:"1.6",direction:I?"rtl":"ltr",textAlign:I?"right":"left"},children:jsxRuntime.jsx(Be,{content:d.text,theme:"dark",streaming:p,dir:T})},l)}let{color:S,text:v}=Tn(d.status,y,o),x=d.status==="input-streaming"||d.status==="input-available";if(d.toolName==="requestInput")return jsxRuntime.jsx("div",{style:{display:"block",position:"relative"},children:jsxRuntime.jsx("div",{"data-get-from-user-host":d.toolCallId||l,style:{width:"100%"}})},l);let w=s?.[d.toolName||""];if(w)return jsxRuntime.jsx("div",{style:{display:"block",position:"relative"},children:jsxRuntime.jsx(wt,{componentName:d.toolName||"Unknown",resolvedColors:o,toolCallId:d.toolCallId,toolName:d.toolName||"unknown",onError:g,onSuccess:u,children:jsxRuntime.jsx(w,{toolName:d.toolName||"",toolCallId:d.toolCallId||"",input:d.input,output:d.output,status:d.status,addToolResult:C})})},l);let M=In(d.toolName||"tool");return jsxRuntime.jsx("div",{style:{display:"flex",gap:"12px",position:"relative"},children:jsxRuntime.jsx("div",{style:{flex:1,minWidth:0},children:jsxRuntime.jsxs("div",{style:{fontSize:"13px",color:o.mutedTextColor,display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"},children:[jsxRuntime.jsxs("span",{style:{fontWeight:600,color:S,display:"flex",alignItems:"center",gap:"6px"},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:S,animation:x?"pulse 1.5s ease-in-out infinite":void 0}}),v]}),M.isMCP?jsxRuntime.jsxs("span",{style:{fontWeight:500,color:o.textColor},children:[jsxRuntime.jsx("span",{style:{fontWeight:600},children:M.toolName}),jsxRuntime.jsx("span",{style:{opacity:.7,margin:"0 4px"},children:"from"}),jsxRuntime.jsx("span",{style:{fontWeight:600,opacity:.85},children:M.mcpName})]}):jsxRuntime.jsx("span",{style:{fontWeight:500,color:o.textColor},children:Sn(M.toolName)})]})})},l)}),jsxRuntime.jsx("style",{children:`
|
|
170
170
|
@keyframes shimmer {
|
|
171
171
|
0% { background-position: -200% 0; }
|
|
172
172
|
100% { background-position: 200% 0; }
|
|
173
173
|
}
|
|
174
|
-
`})]}):null}function
|
|
174
|
+
`})]}):null}function yo(e){if(!e||Number.isNaN(e))return "0 B";let t=["B","KB","MB","GB","TB"],r=Math.min(t.length-1,Math.floor(Math.log(e)/Math.log(1024)));return `${(e/Math.pow(1024,r)).toFixed(r===0?0:1)} ${t[r]}`}function xo({attachment:e,resolvedColors:t,mode:r,onRemove:n,maxWidth:o="200px"}){let s=e.mimeType?.startsWith("image/"),g=r==="editable"||r==="input",u=r==="viewable",C={display:"flex",alignItems:"center",gap:r==="input"?"8px":"6px",padding:r==="input"?"8px 12px":"6px 10px",backgroundColor:t.inputBackground,borderRadius:r==="input"?"10px":"8px",border:`1px solid ${t.borderColor}`,fontSize:r==="input"?"12px":"11px",color:t.textColor,transition:"all 0.2s ease-out",cursor:u?"pointer":"default",maxWidth:r==="input"?"140px":o,position:"relative"},T=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:r==="input"?"20px":"16px",height:r==="input"?"20px":"16px",borderRadius:r==="input"?"4px":"3px",backgroundColor:s?"transparent":t.accentColor,flexShrink:0},children:[s?jsxRuntime.jsx("img",{src:e.url,alt:e.name,style:{width:r==="input"?"20px":"16px",height:r==="input"?"20px":"16px",borderRadius:r==="input"?"4px":"3px",objectFit:"cover"},onError:y=>{y.target.style.display="none";let I=y.target.nextElementSibling;I&&(I.style.display="block");}}):null,jsxRuntime.jsx(X,{IconComponent:lucideReact.File,size:r==="input"?14:10,strokeWidth:"2",style:{display:s?"none":"block",color:t.mutedTextColor}})]}),jsxRuntime.jsxs("div",{style:{minWidth:"0",flex:"1",display:"flex",flexDirection:"column"},children:[jsxRuntime.jsx("span",{title:e.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:"500"},children:e.name}),jsxRuntime.jsx("span",{style:{fontSize:r==="input"?"10px":"9px",color:t.mutedTextColor,marginTop:r==="input"?"2px":"1px"},children:yo(e.size)})]}),r==="input"&&s&&jsxRuntime.jsx("button",{onClick:y=>{y.stopPropagation(),window.open(e.url,"_blank");},style:{background:"none",border:"none",color:t.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px",transition:"all 0.2s"},title:"Preview image",onMouseEnter:y=>{y.currentTarget.style.backgroundColor=t.hoverBackground,y.currentTarget.style.color=t.textColor;},onMouseLeave:y=>{y.currentTarget.style.backgroundColor="transparent",y.currentTarget.style.color=t.mutedTextColor;},children:jsxRuntime.jsx(X,{IconComponent:lucideReact.Eye,size:"12",strokeWidth:"2"})}),g&&n&&jsxRuntime.jsx("button",{onClick:y=>{y.stopPropagation(),n(e.id);},style:{display:"flex",alignItems:"center",justifyContent:"center",width:r==="input"?"auto":"16px",height:r==="input"?"auto":"16px",padding:r==="input"?"2px":"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",color:t.mutedTextColor,cursor:"pointer",transition:"all 0.2s",flexShrink:0},onMouseEnter:y=>{y.currentTarget.style.backgroundColor="#ef444420",y.currentTarget.style.color="#ef4444";},onMouseLeave:y=>{y.currentTarget.style.backgroundColor="transparent",y.currentTarget.style.color=t.mutedTextColor;},children:jsxRuntime.jsx(X,{IconComponent:lucideReact.X,size:"12",strokeWidth:"2"})}),u&&jsxRuntime.jsx(X,{IconComponent:lucideReact.Download,size:"10",strokeWidth:"2",style:{color:t.mutedTextColor,flexShrink:0}})]});return u?jsxRuntime.jsx("a",{href:e.url,target:"_blank",rel:"noreferrer",style:{...C,textDecoration:"none"},onMouseEnter:y=>{y.currentTarget.style.backgroundColor=t.hoverBackground,y.currentTarget.style.borderColor=t.primaryColor;},onMouseLeave:y=>{y.currentTarget.style.backgroundColor=t.inputBackground,y.currentTarget.style.borderColor=t.borderColor;},children:T}):jsxRuntime.jsx("div",{style:C,children:T})}function Co({attachments:e,resolvedColors:t,onRemove:r}){if(!Array.isArray(e)||e.length===0)return null;let n=typeof r=="function"?"editable":"viewable";return jsxRuntime.jsx("div",{style:{marginTop:"12px",display:"flex",flexWrap:"wrap",gap:"8px"},children:e.map(o=>jsxRuntime.jsx(xo,{attachment:o,resolvedColors:t,mode:n,onRemove:r},o.id))})}function Qt({chatMessages:e,isLoading:t,openReasoningIds:r,toggleReasoning:n,resolvedColors:o,t:s,onUserMessageClick:g,HsafaUI:u,onUIError:C,onUISuccess:T,addToolResult:y,editableMessageIcon:I,fullPage:k,dir:f}){return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("style",{children:`
|
|
175
175
|
@keyframes jumpingDots {
|
|
176
176
|
0%, 80%, 100% {
|
|
177
177
|
transform: translateY(0);
|
|
@@ -181,7 +181,7 @@
|
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
`}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",direction:f},children:[e.map((i,b)=>{let c=Array.isArray(i.parts)?i.parts:[],d=c.filter(l=>l.type==="text").map(l=>l&&typeof l.text=="string"?l.text:"").join(`
|
|
184
|
-
`),h=c.filter(l=>l.type==="file"||l.type==="image").map(l=>{if(l.type==="image"){let a=typeof l.image=="string"?l.image:l.image?.toString?.()||"";return {id:a||`${i.id}-img-${Date.now()}`,name:l.name||"image",url:a,mimeType:l.mediaType||"image/jpeg",size:l.size||0}}else return {id:l.url||`${i.id}-file-${Date.now()}`,name:l.name||"file",url:l.url||"",mimeType:l.mediaType||"application/octet-stream",size:l.size||0}});return jsxRuntime.jsx("div",{style:{padding:"0 4px",display:"flex",flexDirection:"column",alignItems:i.role==="user"&&k?"flex-end":"stretch"},children:i.role==="user"?jsxRuntime.jsx("div",{style:{maxWidth:k?"80%":"100%"},children:jsxRuntime.jsx("div",{title:s("editor.clickToEdit"),onClick:()=>m(i,i.id,d,h),style:{maxWidth:k?"100%":"720px",borderRadius:k?"20px":"16px",padding:"12px 16px",fontSize:"15px",lineHeight:"1.6",whiteSpace:"pre-wrap",cursor:"pointer",transition:"background-color 0.2s",backgroundColor:k?n.inputBackground:n.accentColor,color:n.textColor,marginBottom:"16px",marginTop:"16px",position:"relative",border:k?`1px solid ${n.borderColor}`:"none"},onMouseEnter:l=>l.currentTarget.style.backgroundColor=n.hoverBackground,onMouseLeave:l=>l.currentTarget.style.backgroundColor=k?n.inputBackground:n.accentColor,children:jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsxs("div",{style:{flex:1},children:[d,h.length>0&&jsxRuntime.jsx(ln,{attachments:h,resolvedColors:n})]}),jsxRuntime.jsx("div",{style:{flexShrink:0,opacity:.5,transition:"opacity 0.2s"},children:jsxRuntime.jsx(Y,{IconComponent:M||lucideReact.Pencil,size:"14",strokeWidth:"2"})})]})})}):jsxRuntime.jsx(nn,{parts:c,messageId:i.id,openReasoningIds:r,toggleReasoning:o,resolvedColors:n,HsafaUI:u,onUIError:C,onUISuccess:S,addToolResult:x,dir:f,t:s})},i.id)}),t&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",padding:"0 4px",height:"20px"},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:n.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0s"}}),jsxRuntime.jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:n.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0.2s"}}),jsxRuntime.jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:n.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0.4s"}})]})]})]})}function qt({input:e,setInput:t,textareaRef:r,fileInputRef:o,isLoading:n,uploading:s,attachments:m,formatBytes:u,handleRemoveAttachment:C,onFileInputChange:S,onSend:x,onStop:M,status:k,t:f,resolvedColors:i,fullPage:b,dir:c="ltr"}){let d=k==="streaming"||k==="submitted",h=m.length>0||e.trim().length>0,l=c==="rtl";return b?jsxRuntime.jsxs("div",{style:{position:"relative",width:"100%",maxWidth:"768px",margin:"0 auto"},children:[jsxRuntime.jsxs("div",{style:{position:"relative",width:"100%",borderRadius:"26px",padding:l?"14px 48px 14px 14px":"14px 14px 14px 48px",backgroundColor:i.inputBackground,boxShadow:"0 0 0 1px rgba(0,0,0,0.05)",transition:"box-shadow 0.2s ease",direction:l?"rtl":"ltr"},onFocus:a=>{},children:[jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"10px",...l?{right:"12px"}:{left:"12px"},zIndex:10},children:jsxRuntime.jsx("button",{onClick:()=>o.current?.click(),disabled:n||s,style:{borderRadius:"50%",width:"33px",height:"33px",transition:"all 0.2s",backgroundColor:"transparent",border:"none",cursor:n||s?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:i.textColor,opacity:n||s?.5:.7},"aria-label":f("input.attachFiles"),onMouseEnter:a=>{!n&&!s&&(a.currentTarget.style.backgroundColor=i.hoverBackground,a.currentTarget.style.opacity="1");},onMouseLeave:a=>{a.currentTarget.style.backgroundColor="transparent",a.currentTarget.style.opacity="0.7";},children:jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M12 5v14M5 12h14"})})})}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[m.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",paddingBottom:"8px",...l?{marginRight:"-4px",justifyContent:"flex-end"}:{marginLeft:"-4px"}},children:m.map(a=>{let T=a.mimeType.startsWith("image/");return jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 10px",backgroundColor:i.cardBackground,borderRadius:"8px",border:`1px solid ${i.borderColor}`,fontSize:"12px",color:i.textColor,position:"relative"},children:[jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",borderRadius:"4px",backgroundColor:T?"transparent":i.inputBackground},children:T?jsxRuntime.jsx("img",{src:a.url,alt:a.name,style:{width:"20px",height:"20px",borderRadius:"4px",objectFit:"cover"}}):jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("rect",{x:"4",y:"4",width:"16",height:"20",rx:"2",ry:"2"})})}),jsxRuntime.jsx("span",{title:a.name,style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:a.name}),jsxRuntime.jsx("button",{onClick:()=>C(a.id),style:{background:"none",border:"none",color:i.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px"},children:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},a.id)})}),s&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:i.mutedTextColor},children:[jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"spin 1s linear infinite"},children:jsxRuntime.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsxRuntime.jsx("span",{children:f("input.uploadingFiles")})]}),jsxRuntime.jsx("div",{style:{...l?{paddingLeft:"40px"}:{paddingRight:"40px"},display:"flex",alignItems:"center"},children:jsxRuntime.jsx("textarea",{ref:r,"aria-label":f("input.prompt"),rows:1,placeholder:f("input.placeholder"),value:e,onChange:a=>t(a.target.value),onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),x());},disabled:s,style:{maxHeight:"200px",width:"100%",resize:"none",backgroundColor:"transparent",fontSize:"16px",lineHeight:"1.5",outline:"none",border:"none",color:i.textColor,fontFamily:"inherit",overflow:"auto",padding:0,margin:0,direction:l?"rtl":"ltr",textAlign:l?"right":"left"}})})]}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"8px",...l?{left:"8px"}:{right:"8px"}},children:n?jsxRuntime.jsx("button",{onClick:M,disabled:!d,"aria-label":f("input.stop"),style:{borderRadius:"50%",width:"36px",height:"36px",transition:"all 0.2s ease-out",backgroundColor:i.textColor,color:i.inputBackground,border:"none",opacity:d?1:.7,cursor:d?"pointer":"not-allowed",display:"flex",alignItems:"center",justifyContent:"center"},children:jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:jsxRuntime.jsx("rect",{width:"24",height:"24",rx:"2"})})}):jsxRuntime.jsx("button",{onClick:x,disabled:!h||s,"aria-label":f("input.send"),style:{borderRadius:"50%",width:"36px",height:"36px",transition:"all 0.2s ease-out",backgroundColor:!h||s?i.cardBackground:i.textColor,color:!h||s?i.mutedTextColor:i.inputBackground,border:"none",cursor:!h||s?"default":"pointer",display:"flex",alignItems:"center",justifyContent:"center",transform:l?"rotate(180deg)":""},children:jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"M5 12h14"}),jsxRuntime.jsx("path",{d:"M12 5l7 7-7 7"})]})})})]}),jsxRuntime.jsx("input",{ref:o,type:"file",multiple:true,onChange:S,style:{display:"none"},accept:"*/*"}),jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"8px 0",fontSize:"12px",color:i.mutedTextColor,opacity:.8},children:"AI can make mistakes. Please check important information."})]}):jsxRuntime.jsx("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px",paddingTop:"4px"},children:jsxRuntime.jsx("div",{style:{position:"relative",flex:1},children:jsxRuntime.jsxs("div",{style:{position:"relative",width:"100%",borderRadius:"16px",paddingBottom:"48px",paddingTop:"16px",border:`1px solid ${i.borderColor}`,backgroundColor:i.cardBackground},children:[m.length>0&&jsxRuntime.jsx("div",{style:{padding:"0px 16px 12px 16px",display:"flex",flexWrap:"wrap",gap:"10px"},children:m.map(a=>{let T=a.mimeType.startsWith("image/");return jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",backgroundColor:i.inputBackground,borderRadius:"10px",border:`1px solid ${i.borderColor}`,fontSize:"12px",color:i.textColor,position:"relative"},children:[jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",borderRadius:"4px",backgroundColor:T?"transparent":i.cardBackground},children:T?jsxRuntime.jsx("img",{src:a.url,alt:a.name,style:{width:"20px",height:"20px",borderRadius:"4px",objectFit:"cover"}}):jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("rect",{x:"4",y:"4",width:"16",height:"20",rx:"2",ry:"2"})})}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",minWidth:0,flex:1},children:[jsxRuntime.jsx("span",{title:a.name,style:{maxWidth:"140px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:a.name}),jsxRuntime.jsx("span",{style:{color:i.mutedTextColor,fontSize:"10px",marginTop:"2px"},children:u(a.size)})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginLeft:"8px"},children:[T&&jsxRuntime.jsx("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",style:{background:"none",border:"none",color:i.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px",textDecoration:"none"},title:f("input.previewImage"),children:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),jsxRuntime.jsx("button",{onClick:()=>C(a.id),style:{background:"none",border:"none",color:i.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px"},title:f("input.removeFile"),children:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]},a.id)})}),s&&jsxRuntime.jsxs("div",{style:{padding:"0px 16px 12px 16px",display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:i.mutedTextColor},children:[jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"spin 1s linear infinite"},children:jsxRuntime.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsxRuntime.jsx("span",{children:f("input.uploadingFiles")})]}),jsxRuntime.jsx("div",{style:{padding:"0 16px"},children:jsxRuntime.jsx("textarea",{ref:r,"aria-label":f("input.prompt"),rows:1,placeholder:f("input.placeholder"),value:e,onChange:a=>t(a.target.value),onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),x());},disabled:s,style:{height:"24px",maxHeight:"200px",width:"100%",resize:"none",backgroundColor:"transparent",fontSize:"15px",lineHeight:"1.6",outline:"none",border:"none",color:i.textColor,fontFamily:"inherit",overflow:"auto",direction:l?"rtl":"ltr",textAlign:l?"right":"left"}})}),jsxRuntime.jsx("input",{ref:o,type:"file",multiple:true,onChange:S,style:{display:"none"},accept:"*/*"}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"8px",...l?{right:"8px"}:{left:"8px"},display:"flex",alignItems:"center",gap:"4px",color:i.mutedTextColor},children:jsxRuntime.jsx("button",{onClick:()=>o.current?.click(),disabled:n||s,style:{borderRadius:"8px",padding:"8px",transition:"all 0.2s",backgroundColor:"transparent",border:"none",cursor:n||s?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"inherit",opacity:n||s?.5:1},"aria-label":f("input.attachFiles"),children:jsxRuntime.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 1 1 5.66 5.66l-9.2 9.19a2 2 0 1 1-2.83-2.83l8.49-8.49"})})})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"8px",...l?{left:"8px"}:{right:"8px"}},children:n?jsxRuntime.jsx("button",{onClick:M,disabled:!d,"aria-label":f("input.stop"),title:"Stop generation",style:{borderRadius:"12px",padding:"12px",transition:"all 0.2s ease-out",border:"1px solid #ef4444",backgroundColor:"#ef444420",color:"#ef4444",opacity:d?1:.4,cursor:d?"pointer":"not-allowed",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:a=>{d&&(a.currentTarget.style.backgroundColor="#ef444430",a.currentTarget.style.transform="scale(1.02)");},onMouseLeave:a=>{a.currentTarget.style.backgroundColor="#ef444420",a.currentTarget.style.transform="scale(1)";},children:jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"})})}):jsxRuntime.jsx("button",{onClick:x,disabled:!h||s,"aria-label":f("input.send"),title:"Send message",style:{borderRadius:"12px",padding:"12px",transition:"all 0.2s ease-out",border:`1px solid ${i.borderColor}`,backgroundColor:i.cardBackground,color:!h||s?i.mutedTextColor:i.primaryColor,cursor:!h||s?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",opacity:!h||s?.5:1},onMouseEnter:a=>{h&&!s&&(a.currentTarget.style.borderColor=i.primaryColor,a.currentTarget.style.transform="scale(1.02)");},onMouseLeave:a=>{a.currentTarget.style.borderColor=i.borderColor,a.currentTarget.style.transform="scale(1)";},children:jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"m5 12 7-7 7 7"}),jsxRuntime.jsx("path",{d:"M12 19V5"})]})})})]})})})}function Kt({prompts:e,onSelect:t,resolvedColors:r,disabled:o=false,dir:n="ltr",t:s}){let[m,u]=pn.useState(null),C=n==="rtl";return !e||e.length===0?null:jsxRuntime.jsxs("div",{style:{padding:"12px 0",display:"flex",flexDirection:"column",gap:"8px",direction:C?"rtl":"ltr"},children:[jsxRuntime.jsx("div",{style:{fontSize:"12px",fontWeight:600,color:r.mutedTextColor,...C?{paddingRight:"4px",textAlign:"right"}:{paddingLeft:"4px",textAlign:"left"},textTransform:"uppercase",letterSpacing:"0.5px"},children:s?s("prompts.suggested"):"Suggested Prompts"}),jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((S,x)=>{let M=m===x,k=S.prompt.length>180,f=k&&!M?S.prompt.slice(0,180)+"...":S.prompt;return jsxRuntime.jsxs("button",{onClick:()=>{o||t(S.prompt);},disabled:o,style:{display:"flex",flexDirection:"column",padding:"12px",backgroundColor:r.cardBackground,border:`1px solid ${r.borderColor}`,borderRadius:"12px",cursor:o?"not-allowed":"pointer",transition:"all 0.2s ease",textAlign:C?"right":"left",opacity:o?.5:1,position:"relative",overflow:"hidden"},onMouseEnter:i=>{o||(i.currentTarget.style.backgroundColor=r.hoverBackground,i.currentTarget.style.borderColor=r.primaryColor,i.currentTarget.style.transform=C?"translateX(-2px)":"translateX(2px)");},onMouseLeave:i=>{i.currentTarget.style.backgroundColor=r.cardBackground,i.currentTarget.style.borderColor=r.borderColor,i.currentTarget.style.transform="translateX(0)";},children:[jsxRuntime.jsxs("div",{style:{fontSize:"13px",fontWeight:600,color:r.textColor,marginBottom:"6px",display:"flex",alignItems:"center",gap:"6px"},children:[jsxRuntime.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:r.primaryColor,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[jsxRuntime.jsx("path",{d:"M12 20h9"}),jsxRuntime.jsx("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]}),S.label]}),jsxRuntime.jsx("div",{style:{fontSize:"12px",color:r.mutedTextColor,lineHeight:"1.5",width:"100%",wordWrap:"break-word",whiteSpace:"pre-wrap",direction:C?"rtl":"ltr",textAlign:C?"right":"left"},children:f}),k&&jsxRuntime.jsxs("button",{onClick:i=>{i.stopPropagation(),u(M?null:x);},style:{marginTop:"8px",padding:"4px 8px",fontSize:"11px",color:r.primaryColor,backgroundColor:"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",gap:"4px",fontWeight:500},children:[M?s?s("prompts.showLess"):"Show less":s?s("prompts.showMore"):"Show more",jsxRuntime.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:M?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.2s"},children:jsxRuntime.jsx("polyline",{points:"6 9 12 15 18 9"})})]})]},x)})})]})}function dn(e){let t=Date.now()-e,r=Math.max(1,Math.floor(t/1e3));if(r<60)return `${r}s`;let o=Math.floor(r/60);if(o<60)return `${o}m`;let n=Math.floor(o/60);if(n<24)return `${n}h`;let s=Math.floor(n/24);if(s<7)return `${s}d`;let m=Math.floor(s/7);if(m<4)return `${m}w`;let u=Math.floor(s/30);return u<12?`${u}mo`:`${Math.floor(u/12)}y`}function xt({search:e,onSearchChange:t,chats:r,currentChatId:o,resolvedColors:n,onChatSelect:s,onChatDelete:m,className:u,style:C,dir:S="ltr",t:x}){let M=S==="rtl",k=e.trim()?r.filter(f=>(f.title||"").toLowerCase().includes(e.toLowerCase().trim())):r;return jsxRuntime.jsxs("div",{className:u,style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden",direction:M?"rtl":"ltr",...C},children:[jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",gap:"12px",borderBottom:`1px solid ${n.borderColor}`,padding:"12px 16px",flexShrink:0},children:jsxRuntime.jsx("div",{style:{flex:"1"},children:jsxRuntime.jsx("input",{value:e,onChange:f=>t(f.target.value),placeholder:x?x("history.search"):"Search",style:{width:"100%",borderRadius:"8px",backgroundColor:n.inputBackground,padding:"8px 12px",fontSize:"14px",color:n.textColor,border:`1px solid ${n.borderColor}`,outline:"none",direction:M?"rtl":"ltr",textAlign:M?"right":"left"},onFocus:f=>f.currentTarget.style.borderColor=n.primaryColor,onBlur:f=>f.currentTarget.style.borderColor=n.borderColor})})}),jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0"},children:k.length===0?jsxRuntime.jsx("div",{style:{padding:"24px",color:n.mutedTextColor,textAlign:"center"},children:x?x("history.noChatsFound"):"No chats found."}):jsxRuntime.jsx("div",{children:k.map((f,i)=>jsxRuntime.jsx("div",{style:{borderTop:i>0?`1px solid ${n.borderColor}`:"none"},children:jsxRuntime.jsxs("div",{style:{display:"flex",width:"100%",alignItems:"center",justifyContent:"space-between",gap:"12px",padding:"8px 12px",backgroundColor:f.id===o?n.cardBackground:"transparent",transition:"background-color 0.2s"},children:[jsxRuntime.jsx("button",{style:{flex:"1",textAlign:M?"right":"left",transition:"background-color 0.2s",borderRadius:"8px",padding:"8px",border:"none",backgroundColor:"transparent",cursor:"pointer",color:n.textColor,overflow:"hidden"},onMouseEnter:b=>b.currentTarget.style.backgroundColor=n.hoverBackground,onMouseLeave:b=>b.currentTarget.style.backgroundColor="transparent",onClick:()=>s(f.id),children:jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"12px"},children:[jsxRuntime.jsx("div",{style:{minWidth:"0",flex:"1"},children:jsxRuntime.jsx("div",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"14px",color:n.textColor,fontWeight:f.id===o?600:400},children:f.title||(x?x("history.untitledChat"):"Untitled chat")})}),jsxRuntime.jsx("div",{style:{flexShrink:0,fontSize:"12px",color:n.mutedTextColor},children:dn(f.updatedAt)})]})}),jsxRuntime.jsx("button",{style:{flexShrink:0,borderRadius:"6px",padding:"8px",color:n.mutedTextColor,border:"1px solid transparent",backgroundColor:"transparent",cursor:"pointer",transition:"all 0.2s"},title:x?x("history.deleteChat"):"Delete chat",onMouseEnter:b=>{b.currentTarget.style.color="#ef4444",b.currentTarget.style.backgroundColor="rgba(239, 68, 68, 0.1)",b.currentTarget.style.borderColor="rgba(239, 68, 68, 0.3)";},onMouseLeave:b=>{b.currentTarget.style.color=n.mutedTextColor,b.currentTarget.style.backgroundColor="transparent",b.currentTarget.style.borderColor="transparent";},onClick:b=>{b.stopPropagation(),m(f.id);},children:jsxRuntime.jsx(Y,{IconComponent:lucideReact.Trash2,size:"16",strokeWidth:"2"})})]})},f.id))})})]})}function Yt({historyOpen:e,historySearch:t,currentChatId:r,refreshKey:o,resolvedColors:n,onClose:s,onSearchChange:m,onChatSelect:u,onChatDelete:C,loadChatsIndex:S,historyPopupRef:x,dir:M="ltr",t:k}){if(!e)return null;let f=S(),i=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:s}),jsxRuntime.jsx("div",{ref:x,style:{position:"fixed",left:"50%",top:"64px",transform:"translateX(-50%)",zIndex:1101,width:"680px",maxWidth:"94vw",height:"60vh",maxHeight:"600px",overflow:"hidden",borderRadius:"16px",border:`1px solid ${n.borderColor}`,backgroundColor:`${n.backgroundColor}f0`,boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",display:"flex",flexDirection:"column"},children:jsxRuntime.jsx(xt,{search:t,onSearchChange:m,chats:f,currentChatId:r,resolvedColors:n,onChatSelect:u,onChatDelete:C,dir:M,t:k})})]});return typeof document<"u"&&document.body?reactDom.createPortal(i,document.body):i}function un({isOpen:e,historySearch:t,onSearchChange:r,chats:o,currentChatId:n,resolvedColors:s,onChatSelect:m,onChatDelete:u,onNewChat:C,isMobile:S=false,dir:x="ltr",t:M}){let k=x==="rtl";return jsxRuntime.jsxs("div",{style:{width:e?"260px":"0px",opacity:e?1:0,...k?{marginRight:e?0:-10}:{marginLeft:e?0:-10},height:"100%",backgroundColor:s.backgroundColor,...k?{borderLeft:e?`1px solid ${s.borderColor}`:"none"}:{borderRight:e?`1px solid ${s.borderColor}`:"none"},display:"flex",flexDirection:"column",transition:"all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",overflow:"hidden",flexShrink:0,position:S?"fixed":"relative",zIndex:S?100:1,...k?{right:0}:{left:0},top:0,bottom:0,visibility:e?"visible":"hidden",direction:k?"rtl":"ltr"},children:[jsxRuntime.jsx("div",{style:{padding:"12px",flexShrink:0,opacity:e?1:0,transition:"opacity 0.2s 0.1s"},children:jsxRuntime.jsxs("button",{onClick:C,style:{width:"100%",display:"flex",alignItems:"center",gap:"12px",padding:"10px 12px",borderRadius:"8px",border:`1px solid ${s.borderColor}`,backgroundColor:"transparent",color:s.textColor,cursor:"pointer",fontSize:"14px",transition:"all 0.2s",textAlign:k?"right":"left"},onMouseEnter:f=>f.currentTarget.style.backgroundColor=s.hoverBackground,onMouseLeave:f=>f.currentTarget.style.backgroundColor="transparent",children:[jsxRuntime.jsx(Y,{IconComponent:lucideReact.Plus,size:"16",strokeWidth:"2"}),jsxRuntime.jsx("span",{children:M?M("history.newChat"):"New chat"})]})}),jsxRuntime.jsx(xt,{search:t,onSearchChange:r,chats:o,currentChatId:n,resolvedColors:s,onChatSelect:m,onChatDelete:u,dir:x,t:M,style:{flex:1}})]})}function Jt({isOpen:e,resolvedColors:t,onConfirm:r,onCancel:o,editProcessContent:n,dir:s="ltr",t:m}){if(!e)return null;let u=n?.title||(m?m("editModal.title"):"Edit Message"),C=n?.content||(m?m("editModal.content"):"This will remove this message and all messages after it, and place its content in the input field for editing. Do you want to continue?"),S=n?.submit_button_label||(m?m("editModal.submit"):"Edit"),x=n?.cancel_button_label||(m?m("editModal.cancel"):"Cancel"),M=n?.icon,k=typeof C=="function",f=k?C:null,i=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:o}),jsxRuntime.jsxs("div",{style:{position:"fixed",left:"50%",top:"50%",transform:"translate(-50%, -50%)",zIndex:1101,width:"420px",maxWidth:"94vw",overflow:"hidden",borderRadius:"16px",border:`1px solid ${t.borderColor}`,backgroundColor:t.backgroundColor,boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",direction:s==="rtl"?"rtl":"ltr"},children:[jsxRuntime.jsxs("div",{style:{padding:"20px 24px",borderBottom:`1px solid ${t.borderColor}`,display:"flex",alignItems:"center",gap:"12px"},children:[M?jsxRuntime.jsx("div",{style:{flexShrink:0},children:jsxRuntime.jsx(Y,{IconComponent:M,size:"20",strokeWidth:"2"})}):jsxRuntime.jsx("div",{style:{flexShrink:0,color:t.mutedTextColor},children:jsxRuntime.jsx(Y,{IconComponent:lucideReact.Pencil,size:"20",strokeWidth:"2"})}),jsxRuntime.jsx("h3",{style:{margin:0,fontSize:"18px",fontWeight:"600",color:t.textColor,flex:1},children:u})]}),jsxRuntime.jsx("div",{style:{padding:"24px",color:t.textColor,fontSize:"14px",lineHeight:"1.6"},children:k&&f?jsxRuntime.jsx(f,{}):jsxRuntime.jsx("p",{style:{margin:0},children:C})}),jsxRuntime.jsxs("div",{style:{display:"flex",gap:"12px",padding:"16px 24px",borderTop:`1px solid ${t.borderColor}`,justifyContent:"flex-end"},children:[jsxRuntime.jsx("button",{onClick:o,style:{padding:"8px 16px",borderRadius:"8px",fontSize:"14px",fontWeight:"500",border:`1px solid ${t.borderColor}`,backgroundColor:"transparent",color:t.textColor,cursor:"pointer",transition:"all 0.2s"},onMouseEnter:b=>{b.currentTarget.style.backgroundColor=t.hoverBackground;},onMouseLeave:b=>{b.currentTarget.style.backgroundColor="transparent";},children:x}),jsxRuntime.jsx("button",{onClick:r,style:{padding:"8px 16px",borderRadius:"8px",fontSize:"14px",fontWeight:"500",border:"none",backgroundColor:t.primaryColor,color:t.backgroundColor,cursor:"pointer",transition:"all 0.2s",opacity:1},onMouseEnter:b=>{b.currentTarget.style.opacity="0.9";},onMouseLeave:b=>{b.currentTarget.style.opacity="1";},children:S})]})]})]});return typeof document<"u"&&document.body?reactDom.createPortal(i,document.body):i}function Fo({agentId:e,theme:t,primaryColor:r,primaryColorDark:o,primaryColorLight:n,backgroundColor:s,borderColor:m,textColor:u,accentColor:C,dir:S,lang:x,language:M,baseUrl:k="",initialMessages:f=[],onMessagesChange:i,defaultOpen:b=true,floatingButtonPosition:c={bottom:24,right:24},HsafaTools:d={},HsafaUI:h={},componentAboveInput:l,editProcessContent:a,presetPrompts:T,onStart:w,onFinish:v,currentChat:y,onChatChanged:E,templateParams:p,fullPageChat:F=false,title:W,placeholder:_,emptyStateMessage:te}){let {dir:xe,theme:ge,baseUrl:q,setStreamingState:U,setChatOpenState:K}=ie(),G=S||xe||"ltr",V=x||M||"en",re=V==="ar",Z=t||ge||"dark",fe=k&&k.length>0?k:q||"",A={primaryColor:Z==="dark"?o||r||"#ffffff":n||r||"#000000",backgroundColor:s||(Z==="dark"?"#0B0B0F":"#FFFFFF"),borderColor:m||(Z==="dark"?"#2A2C33":"#E5E7EB"),textColor:u||(Z==="dark"?"#EDEEF0":"#111827"),accentColor:C||(Z==="dark"?"#17181C":"#F9FAFB"),mutedTextColor:Z==="dark"?"#6f7276":"#6B7280",inputBackground:Z==="dark"?"#17181C":"#F3F4F6",cardBackground:Z==="dark"?"#121318":"#FFFFFF",hoverBackground:Z==="dark"?"#1c1e25":"#F3F4F6"},B=g=>{let L={"header.new":"New","header.history":"History","header.close":"Close chat","input.placeholder":_||"Ask your question...","input.prompt":"Prompt","input.attachFiles":"Attach files","input.insertLink":"Insert link","input.send":"Send","input.stop":"Stop","input.uploadingFiles":"Uploading files...","input.previewImage":"Preview image","input.removeFile":"Remove file","messages.empty":te||"Start by sending a message to the agent.","general.agent":W||"Agent","editor.cancel":"Cancel","editor.saveAndRegenerate":"Save & Regenerate","editor.clickToEdit":"Click to edit","prompts.suggested":"Suggested Prompts","prompts.showMore":"Show more","prompts.showLess":"Show less","history.search":"Search","history.noChatsFound":"No chats found.","history.untitledChat":"Untitled chat","history.deleteChat":"Delete chat","history.newChat":"New chat","editModal.title":"Edit Message","editModal.content":"This will remove this message and all messages after it, and place its content in the input field for editing. Do you want to continue?","editModal.submit":"Edit","editModal.cancel":"Cancel","assistant.thinking":"Thinking","assistant.finishThinking":"Finish Thinking","tool.inputting":"Inputting","tool.running":"Running","tool.error":"Error","tool.called":"Called","error.occurred":"An error occurred:","error.tryAgain":"Please try again.","error.refresh":"Refresh","error.failedSend":"Failed to send message. Please try again.","error.failedEdit":"Failed to edit message. Please try again."};return (re?{"header.new":"\u062C\u062F\u064A\u062F","header.history":"\u0627\u0644\u0633\u062C\u0644","header.close":"\u0625\u063A\u0644\u0627\u0642 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629","input.placeholder":_||"\u0627\u0643\u062A\u0628 \u0633\u0624\u0627\u0644\u0643...","input.prompt":"\u0627\u0644\u0631\u0633\u0627\u0644\u0629","input.attachFiles":"\u0625\u0631\u0641\u0627\u0642 \u0645\u0644\u0641\u0627\u062A","input.insertLink":"\u0625\u062F\u0631\u0627\u062C \u0631\u0627\u0628\u0637","input.send":"\u0625\u0631\u0633\u0627\u0644","input.stop":"\u0625\u064A\u0642\u0627\u0641","input.uploadingFiles":"\u062C\u0627\u0631\u064D \u0631\u0641\u0639 \u0627\u0644\u0645\u0644\u0641\u0627\u062A...","input.previewImage":"\u0645\u0639\u0627\u064A\u0646\u0629 \u0627\u0644\u0635\u0648\u0631\u0629","input.removeFile":"\u0625\u0632\u0627\u0644\u0629 \u0627\u0644\u0645\u0644\u0641","messages.empty":te||"\u0627\u0628\u062F\u0623 \u0628\u0625\u0631\u0633\u0627\u0644 \u0631\u0633\u0627\u0644\u0629 \u0625\u0644\u0649 \u0627\u0644\u0648\u0643\u064A\u0644.","general.agent":W||"\u0627\u0644\u0648\u0643\u064A\u0644","editor.cancel":"\u0625\u0644\u063A\u0627\u0621","editor.saveAndRegenerate":"\u062D\u0641\u0638 \u0648\u0625\u0639\u0627\u062F\u0629 \u0627\u0644\u062A\u0648\u0644\u064A\u062F","editor.clickToEdit":"\u0627\u0646\u0642\u0631 \u0644\u0644\u062A\u0639\u062F\u064A\u0644","prompts.suggested":"\u0627\u0642\u062A\u0631\u0627\u062D\u0627\u062A \u062C\u0627\u0647\u0632\u0629","prompts.showMore":"\u0639\u0631\u0636 \u0627\u0644\u0645\u0632\u064A\u062F","prompts.showLess":"\u0639\u0631\u0636 \u0623\u0642\u0644","history.search":"\u0628\u062D\u062B","history.noChatsFound":"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A.","history.untitledChat":"\u0645\u062D\u0627\u062F\u062B\u0629 \u0628\u062F\u0648\u0646 \u0639\u0646\u0648\u0627\u0646","history.deleteChat":"\u062D\u0630\u0641 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629","history.newChat":"\u0645\u062D\u0627\u062F\u062B\u0629 \u062C\u062F\u064A\u062F\u0629","editModal.title":"\u062A\u0639\u062F\u064A\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629","editModal.content":"\u0633\u064A\u0624\u062F\u064A \u0647\u0630\u0627 \u0625\u0644\u0649 \u062D\u0630\u0641 \u0647\u0630\u0647 \u0627\u0644\u0631\u0633\u0627\u0644\u0629 \u0648\u0643\u0644 \u0627\u0644\u0631\u0633\u0627\u0626\u0644 \u0627\u0644\u062A\u064A \u0628\u0639\u062F\u0647\u0627\u060C \u062B\u0645 \u0648\u0636\u0639 \u0645\u062D\u062A\u0648\u0627\u0647\u0627 \u0641\u064A \u062D\u0642\u0644 \u0627\u0644\u0625\u062F\u062E\u0627\u0644 \u0644\u0644\u062A\u0639\u062F\u064A\u0644. \u0647\u0644 \u062A\u0631\u064A\u062F \u0627\u0644\u0645\u062A\u0627\u0628\u0639\u0629\u061F","editModal.submit":"\u062A\u0639\u062F\u064A\u0644","editModal.cancel":"\u0625\u0644\u063A\u0627\u0621","assistant.thinking":"\u062C\u0627\u0631\u064D \u0627\u0644\u062A\u0641\u0643\u064A\u0631","assistant.finishThinking":"\u0627\u0646\u062A\u0647\u0649 \u0627\u0644\u062A\u0641\u0643\u064A\u0631","tool.inputting":"\u062C\u0627\u0631\u064D \u0627\u0644\u0625\u062F\u062E\u0627\u0644","tool.running":"\u0642\u064A\u062F \u0627\u0644\u062A\u0634\u063A\u064A\u0644","tool.error":"\u062E\u0637\u0623","tool.called":"\u062A\u0645 \u0627\u0644\u0627\u0633\u062A\u062F\u0639\u0627\u0621","error.occurred":"\u062D\u062F\u062B \u062E\u0637\u0623:","error.tryAgain":"\u064A\u0631\u062C\u0649 \u0627\u0644\u0645\u062D\u0627\u0648\u0644\u0629 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649.","error.refresh":"\u062A\u062D\u062F\u064A\u062B","error.failedSend":"\u062A\u0639\u0630\u0631 \u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629. \u064A\u0631\u062C\u0649 \u0627\u0644\u0645\u062D\u0627\u0648\u0644\u0629 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649.","error.failedEdit":"\u062A\u0639\u0630\u0631 \u062A\u0639\u062F\u064A\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629. \u064A\u0631\u062C\u0649 \u0627\u0644\u0645\u062D\u0627\u0648\u0644\u0629 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649."}:L)[g]||L[g]||g},kt=Wt({agentId:e,baseUrl:fe,tools:d,uiComponents:h,templateParams:p,controlledChatId:y,onChatIdChange:y===void 0?g=>{E&&E(g);}:void 0,onStart:pn.useCallback(g=>{w&&w(g);},[w]),onFinish:pn.useCallback(g=>{v&&v(g);},[v]),onError:pn.useCallback(g=>{console.error("Chat error:",g);},[]),initialMessages:f,onMessagesChange:i}),{input:ke,setInput:he,messages:ue,isLoading:I,status:P,error:O,sendMessage:z,stop:ee,setMessages:j,notifyMessagesChange:pe,chatId:We,setChatId:Re,tools:Uo,uiComponents:er,formHostRef:Oo,formStateRef:Go,cleanupForms:Ue,onUISuccess:tr,onUIError:rr,chatApi:nr}=kt,X=y!==void 0?y:We,we=pn.useCallback(g=>{y===void 0&&Re(g),E&&E(g);},[y,Re,E]);pn.useEffect(()=>{y!==void 0&&y!==We&&Re(y);},[y,We,Re]);let{attachments:Oe,uploading:or,fileInputRef:Ge,formatBytes:ar,handleRemoveAttachment:ir,handleFileSelection:sr,clearAttachments:ot,setAttachments:lr}=Br(fe),[at,Te]=pn.useState(null),[it,dr]=pn.useState(()=>{try{return pt(e).loadShowChatPreference(!!b)}catch{return !!b}}),[wt,Ae]=pn.useState(false),[Tt,It]=pn.useState(""),[St,Mt]=pn.useState(0),cr=pn.useRef(null),ur=pn.useRef(null),[pr,mr]=pn.useState(new Set),[gr,Et]=pn.useState(false),[je,Rt]=pn.useState(null),_e=pn.useRef(null),fr=Ar(I),[hr,fn]=pn.useState(false);pn.useEffect(()=>{let g=()=>fn(window.innerWidth<768);return g(),window.addEventListener("resize",g),()=>window.removeEventListener("resize",g)},[]);let At=Ot({agentId:e,chatId:X,messages:ue,isLoading:I,autoSave:true,autoRestore:false}),$=At.storage,yr=pn.useMemo(()=>{try{return $.loadChatsIndex()}catch{return []}},[$,St]),qe=pn.useRef(false),Ke=pn.useRef(null);pn.useEffect(()=>{if(!qe.current){if(y!==void 0){try{let g=$.loadChat(y),L=g&&Array.isArray(g.messages)?g.messages:[];if(L.length>0)try{j(L);}catch{}Ke.current=y;}catch{}try{$.saveCurrentChatId(y);}catch{}qe.current=true;return}try{let g=$.loadCurrentChatId();if(g){we(g);let L=$.loadChat(g),D=L&&Array.isArray(L.messages)?L.messages:[];try{j(D);}catch{}Ke.current=g;}}catch{}qe.current=true;}},[y]),pn.useEffect(()=>{if(qe.current&&y!==void 0&&y!==Ke.current)try{let g=$.loadChat(y),L=g&&Array.isArray(g.messages)?g.messages:[];try{j(L);}catch{}Ke.current=y;try{$.saveCurrentChatId(y);}catch{}}catch{}},[y,$,j]),pn.useEffect(()=>{if(qe.current)try{$.saveCurrentChatId(X);}catch{}},[X,$]),pn.useEffect(()=>{try{U(X,I);}catch{}return ()=>{try{U(X,!1);}catch{}}},[X,I,U]),pn.useEffect(()=>{try{K(X,it);}catch{}return ()=>{try{K(X,!1);}catch{}}},[X,it,K]);let xr=pn.useCallback(async()=>{let g=ke.trim();if(!g&&Oe.length===0||I)return;let L=[...Oe];he(""),ot(),Te(null),_e.current&&_e.current.focus();try{await z({text:g,files:L.map(D=>({type:"file",url:D.url,mediaType:D.mimeType||"application/octet-stream",...D.name?{name:D.name}:{},...D.size?{size:D.size}:{}}))});}catch(D){console.error("Failed to send message:",D),Te(B("error.failedSend"));}},[ke,Oe,I,z,ot,B]),Le=pn.useCallback(()=>{if(I)return;Ue(),he(""),ot(),Te(null);try{j([]);}catch{}let g=`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`;Ke.current=g;try{At.createNewChat(()=>{we(g);try{$.saveCurrentChatId(g);}catch{}});}catch{we(g);try{$.saveCurrentChatId(g);}catch{}}},[I,ot,$,j,we,Ue,At]),br=pn.useCallback(()=>{Ae(g=>!g);},[]),hn=pn.useCallback(()=>{dr(false);try{$.saveShowChatPreference(!1);}catch{}},[$]),Cr=pn.useCallback(async g=>{let L=g.target.files;L&&await sr(L,Te),Ge.current&&(Ge.current.value="");},[sr,Ge]);pn.useEffect(()=>{let g=_e.current;if(!g)return;g.style.height="24px",g.offsetHeight,g.style.height="auto";let L=Math.min(g.scrollHeight,200);g.style.height=`${L}px`;},[ke]);let vr=pn.useCallback((g,L,D,Ir)=>{Rt({id:L,text:D,attachments:Ir||[]}),Et(true);},[]),kr=pn.useCallback(()=>{if(!(!je||I))try{let g=ue.findIndex(D=>D.id===je.id);if(g===-1)return;let L=ue.slice(0,g);try{j(L);}catch{}he(je.text),lr(je.attachments),Et(!1),Rt(null),pe();}catch(g){console.error("Failed to edit message:",g),Te(B("error.failedEdit"));}},[je,I,ue,j,lr,pe,B]),wr=pn.useCallback(()=>{Et(false),Rt(null);},[]),yn=jsxRuntime.jsxs("div",{style:{position:"fixed",inset:0,display:"flex",backgroundColor:A.backgroundColor,color:A.textColor,overflow:"hidden"},children:[!hr&&jsxRuntime.jsx(un,{isOpen:wt,historySearch:Tt,onSearchChange:It,chats:yr,currentChatId:X,resolvedColors:A,dir:G,t:B,onChatSelect:g=>{if(g&&g!==X&&(Ue(),we(g),y===void 0)){try{$.saveCurrentChatId(g);}catch{}try{let L=$.loadChat(g),D=L&&Array.isArray(L.messages)?L.messages:[];try{j(D);}catch{}}catch{}}},onChatDelete:g=>{try{$.deleteChat(g),Mt(L=>L+1),g===X&&Le();}catch{}},onNewChat:Le,onClose:()=>Ae(false)}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",flex:1,minWidth:0,position:"relative"},children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 20px",backgroundColor:A.backgroundColor,minHeight:"60px",zIndex:10},children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[jsxRuntime.jsx("button",{ref:cr,onClick:br,style:{padding:"8px",borderRadius:"8px",border:"none",backgroundColor:"transparent",color:A.mutedTextColor,cursor:"pointer",transition:"all 0.2s",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:g=>{g.currentTarget.style.backgroundColor=A.hoverBackground,g.currentTarget.style.color=A.textColor;},onMouseLeave:g=>{g.currentTarget.style.backgroundColor="transparent",g.currentTarget.style.color=A.mutedTextColor;},"aria-label":B("header.history"),children:jsxRuntime.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),jsxRuntime.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),jsxRuntime.jsx("h1",{style:{fontSize:"16px",fontWeight:600,margin:0,color:A.textColor},children:B("general.agent")})]}),jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:jsxRuntime.jsx("button",{onClick:Le,disabled:I,style:{padding:"8px",borderRadius:"8px",border:"none",backgroundColor:"transparent",color:A.mutedTextColor,cursor:I?"not-allowed":"pointer",transition:"all 0.2s",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:g=>{I||(g.currentTarget.style.backgroundColor=A.hoverBackground,g.currentTarget.style.color=A.textColor);},onMouseLeave:g=>{g.currentTarget.style.backgroundColor="transparent",g.currentTarget.style.color=A.mutedTextColor;},"aria-label":B("header.new"),children:jsxRuntime.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M12 5v14M5 12h14"})})})})]}),jsxRuntime.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},children:[jsxRuntime.jsx("div",{ref:fr,className:"chat-scroll-container",style:{flex:1,overflowY:"auto",overflowX:"hidden",display:"flex",flexDirection:"column",scrollBehavior:"smooth","--hsafa-primary":A.primaryColor,"--hsafa-border":A.borderColor,"--hsafa-card":A.cardBackground,"--hsafa-text":A.textColor,"--hsafa-muted":A.mutedTextColor,"--hsafa-bg":A.backgroundColor,"--hsafa-hover":A.hoverBackground,"--hsafa-input-bg":A.inputBackground,"--hsafa-accent":A.accentColor},children:jsxRuntime.jsx("div",{style:{maxWidth:"768px",width:"100%",margin:"0 auto",padding:"32px 24px",display:"flex",flexDirection:"column",gap:"24px"},children:ue.length===0?jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px",padding:"64px 0"},children:T&&T.length>0?jsxRuntime.jsx(Kt,{prompts:T,onSelect:g=>he(g),resolvedColors:A,disabled:I,dir:G,t:B}):jsxRuntime.jsx("div",{style:{padding:"64px 32px",textAlign:"center",color:A.mutedTextColor,fontSize:"16px"},children:B("messages.empty")})}):jsxRuntime.jsx(_t,{chatMessages:ue,isLoading:I,openReasoningIds:pr,toggleReasoning:g=>mr(L=>{let D=new Set(L);return D.has(g)?D.delete(g):D.add(g),D}),resolvedColors:A,t:B,onUserMessageClick:vr,HsafaUI:er,onUIError:rr,onUISuccess:tr,addToolResult:g=>nr?.addToolResult?.(g),editableMessageIcon:a?.message_icon,fullPage:true,dir:G})})}),jsxRuntime.jsx("div",{style:{backgroundColor:A.backgroundColor,padding:"0 24px 24px",position:"relative",zIndex:20},children:jsxRuntime.jsxs("div",{style:{maxWidth:"768px",width:"100%",margin:"0 auto"},children:[l&&pn__default.default.createElement(l,{}),at&&jsxRuntime.jsxs("div",{style:{padding:"12px 16px",marginBottom:"12px",backgroundColor:"#ef4444",color:"#fff",borderRadius:"8px",fontSize:"14px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{children:at}),jsxRuntime.jsx("button",{onClick:()=>Te(null),style:{background:"none",border:"none",color:"#fff",cursor:"pointer",padding:"2px",fontSize:"20px"},children:"\xD7"})]}),O&&jsxRuntime.jsxs("div",{style:{padding:"12px 16px",marginBottom:"12px",backgroundColor:"#ef4444",color:"#fff",borderRadius:"8px",fontSize:"14px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxRuntime.jsxs("span",{children:[B("error.occurred")," ",O.message||B("error.tryAgain")]}),jsxRuntime.jsx("button",{onClick:()=>window.location.reload(),style:{background:"none",border:"1px solid #fff",color:"#fff",cursor:"pointer",padding:"4px 8px",borderRadius:"4px",fontSize:"12px"},children:B("error.refresh")})]}),jsxRuntime.jsx(qt,{input:ke,setInput:he,textareaRef:_e,fileInputRef:Ge,isLoading:I,uploading:or,attachments:Oe,formatBytes:ar,handleRemoveAttachment:ir,onFileInputChange:Cr,onSend:xr,onStop:()=>ee(),status:P,t:B,resolvedColors:A,fullPage:true,dir:G})]})})]})]}),hr&&jsxRuntime.jsx(Yt,{historyOpen:wt,historySearch:Tt,currentChatId:X,refreshKey:St,resolvedColors:A,onClose:()=>Ae(false),onSearchChange:It,dir:G,t:B,onChatSelect:g=>{if(Ae(false),g&&g!==X&&(Ue(),we(g),y===void 0)){try{$.saveCurrentChatId(g);}catch{}try{let L=$.loadChat(g),D=L&&Array.isArray(L.messages)?L.messages:[];try{j(D);}catch{}}catch{}}},onChatDelete:g=>{try{$.deleteChat(g),Mt(L=>L+1),g===X&&Le();}catch{}},loadChatsIndex:()=>yr,historyPopupRef:ur}),jsxRuntime.jsx(Jt,{isOpen:gr,resolvedColors:A,t:B,editProcessContent:a,onConfirm:kr,onCancel:wr,dir:G,lang:V}),jsxRuntime.jsx("style",{children:`
|
|
184
|
+
`),h=c.filter(l=>l.type==="file"||l.type==="image").map(l=>{if(l.type==="image"){let a=typeof l.image=="string"?l.image:l.image?.toString?.()||"";return {id:a||`${i.id}-img-${Date.now()}`,name:l.name||"image",url:a,mimeType:l.mediaType||"image/jpeg",size:l.size||0}}else return {id:l.url||`${i.id}-file-${Date.now()}`,name:l.name||"file",url:l.url||"",mimeType:l.mediaType||"application/octet-stream",size:l.size||0}});return jsxRuntime.jsx("div",{style:{padding:"0 4px",display:"flex",flexDirection:"column",alignItems:i.role==="user"&&k?"flex-end":"stretch"},children:i.role==="user"?jsxRuntime.jsx("div",{style:{maxWidth:k?"80%":"100%"},children:jsxRuntime.jsx("div",{title:s("editor.clickToEdit"),onClick:()=>g(i,i.id,d,h),style:{maxWidth:k?"100%":"720px",borderRadius:k?"20px":"16px",padding:"12px 16px",fontSize:"15px",lineHeight:"1.6",whiteSpace:"pre-wrap",cursor:"pointer",transition:"background-color 0.2s",backgroundColor:k?o.inputBackground:o.accentColor,color:o.textColor,marginBottom:"16px",marginTop:"16px",position:"relative",border:k?`1px solid ${o.borderColor}`:"none"},onMouseEnter:l=>l.currentTarget.style.backgroundColor=o.hoverBackground,onMouseLeave:l=>l.currentTarget.style.backgroundColor=k?o.inputBackground:o.accentColor,children:jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsxs("div",{style:{flex:1},children:[d,h.length>0&&jsxRuntime.jsx(Co,{attachments:h,resolvedColors:o})]}),jsxRuntime.jsx("div",{style:{flexShrink:0,opacity:.5,transition:"opacity 0.2s"},children:jsxRuntime.jsx(X,{IconComponent:I||lucideReact.Pencil,size:"14",strokeWidth:"2"})})]})})}):jsxRuntime.jsx(ho,{parts:c,messageId:i.id,openReasoningIds:r,toggleReasoning:n,resolvedColors:o,HsafaUI:u,onUIError:C,onUISuccess:T,addToolResult:y,dir:f,t:s})},i.id)}),t&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",padding:"0 4px",height:"20px"},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0s"}}),jsxRuntime.jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0.2s"}}),jsxRuntime.jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0.4s"}})]})]})]})}function er({input:e,setInput:t,textareaRef:r,fileInputRef:n,isLoading:o,uploading:s,attachments:g,formatBytes:u,handleRemoveAttachment:C,onFileInputChange:T,onSend:y,onStop:I,status:k,t:f,resolvedColors:i,fullPage:b,dir:c="ltr"}){let d=k==="streaming"||k==="submitted",h=g.length>0||e.trim().length>0,l=c==="rtl";return b?jsxRuntime.jsxs("div",{style:{position:"relative",width:"100%",maxWidth:"768px",margin:"0 auto"},children:[jsxRuntime.jsxs("div",{style:{position:"relative",width:"100%",borderRadius:"26px",padding:l?"14px 48px 14px 14px":"14px 14px 14px 48px",backgroundColor:i.inputBackground,boxShadow:"0 0 0 1px rgba(0,0,0,0.05)",transition:"box-shadow 0.2s ease",direction:l?"rtl":"ltr"},onFocus:a=>{},children:[jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"10px",...l?{right:"12px"}:{left:"12px"},zIndex:10},children:jsxRuntime.jsx("button",{onClick:()=>n.current?.click(),disabled:o||s,style:{borderRadius:"50%",width:"33px",height:"33px",transition:"all 0.2s",backgroundColor:"transparent",border:"none",cursor:o||s?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:i.textColor,opacity:o||s?.5:.7},"aria-label":f("input.attachFiles"),onMouseEnter:a=>{!o&&!s&&(a.currentTarget.style.backgroundColor=i.hoverBackground,a.currentTarget.style.opacity="1");},onMouseLeave:a=>{a.currentTarget.style.backgroundColor="transparent",a.currentTarget.style.opacity="0.7";},children:jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M12 5v14M5 12h14"})})})}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[g.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",paddingBottom:"8px",...l?{marginRight:"-4px",justifyContent:"flex-end"}:{marginLeft:"-4px"}},children:g.map(a=>{let S=a.mimeType.startsWith("image/");return jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 10px",backgroundColor:i.cardBackground,borderRadius:"8px",border:`1px solid ${i.borderColor}`,fontSize:"12px",color:i.textColor,position:"relative"},children:[jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",borderRadius:"4px",backgroundColor:S?"transparent":i.inputBackground},children:S?jsxRuntime.jsx("img",{src:a.url,alt:a.name,style:{width:"20px",height:"20px",borderRadius:"4px",objectFit:"cover"}}):jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("rect",{x:"4",y:"4",width:"16",height:"20",rx:"2",ry:"2"})})}),jsxRuntime.jsx("span",{title:a.name,style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:a.name}),jsxRuntime.jsx("button",{onClick:()=>C(a.id),style:{background:"none",border:"none",color:i.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px"},children:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},a.id)})}),s&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:i.mutedTextColor},children:[jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"spin 1s linear infinite"},children:jsxRuntime.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsxRuntime.jsx("span",{children:f("input.uploadingFiles")})]}),jsxRuntime.jsx("div",{style:{...l?{paddingLeft:"40px"}:{paddingRight:"40px"},display:"flex",alignItems:"center"},children:jsxRuntime.jsx("textarea",{ref:r,"aria-label":f("input.prompt"),rows:1,placeholder:f("input.placeholder"),value:e,onChange:a=>t(a.target.value),onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),y());},disabled:s,style:{maxHeight:"200px",width:"100%",resize:"none",backgroundColor:"transparent",fontSize:"16px",lineHeight:"1.5",outline:"none",border:"none",color:i.textColor,fontFamily:"inherit",overflow:"auto",padding:0,margin:0,direction:l?"rtl":"ltr",textAlign:l?"right":"left"}})})]}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"8px",...l?{left:"8px"}:{right:"8px"}},children:o?jsxRuntime.jsx("button",{onClick:I,disabled:!d,"aria-label":f("input.stop"),style:{borderRadius:"50%",width:"36px",height:"36px",transition:"all 0.2s ease-out",backgroundColor:i.textColor,color:i.inputBackground,border:"none",opacity:d?1:.7,cursor:d?"pointer":"not-allowed",display:"flex",alignItems:"center",justifyContent:"center"},children:jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:jsxRuntime.jsx("rect",{width:"24",height:"24",rx:"2"})})}):jsxRuntime.jsx("button",{onClick:y,disabled:!h||s,"aria-label":f("input.send"),style:{borderRadius:"50%",width:"36px",height:"36px",transition:"all 0.2s ease-out",backgroundColor:!h||s?i.cardBackground:i.textColor,color:!h||s?i.mutedTextColor:i.inputBackground,border:"none",cursor:!h||s?"default":"pointer",display:"flex",alignItems:"center",justifyContent:"center",transform:l?"rotate(180deg)":""},children:jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"M5 12h14"}),jsxRuntime.jsx("path",{d:"M12 5l7 7-7 7"})]})})})]}),jsxRuntime.jsx("input",{ref:n,type:"file",multiple:true,onChange:T,style:{display:"none"},accept:"*/*"}),jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"8px 0",fontSize:"12px",color:i.mutedTextColor,opacity:.8},children:"AI can make mistakes. Please check important information."})]}):jsxRuntime.jsx("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px",paddingTop:"4px"},children:jsxRuntime.jsx("div",{style:{position:"relative",flex:1},children:jsxRuntime.jsxs("div",{style:{position:"relative",width:"100%",borderRadius:"16px",paddingBottom:"48px",paddingTop:"16px",border:`1px solid ${i.borderColor}`,backgroundColor:i.cardBackground},children:[g.length>0&&jsxRuntime.jsx("div",{style:{padding:"0px 16px 12px 16px",display:"flex",flexWrap:"wrap",gap:"10px"},children:g.map(a=>{let S=a.mimeType.startsWith("image/");return jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",backgroundColor:i.inputBackground,borderRadius:"10px",border:`1px solid ${i.borderColor}`,fontSize:"12px",color:i.textColor,position:"relative"},children:[jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",borderRadius:"4px",backgroundColor:S?"transparent":i.cardBackground},children:S?jsxRuntime.jsx("img",{src:a.url,alt:a.name,style:{width:"20px",height:"20px",borderRadius:"4px",objectFit:"cover"}}):jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("rect",{x:"4",y:"4",width:"16",height:"20",rx:"2",ry:"2"})})}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",minWidth:0,flex:1},children:[jsxRuntime.jsx("span",{title:a.name,style:{maxWidth:"140px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:a.name}),jsxRuntime.jsx("span",{style:{color:i.mutedTextColor,fontSize:"10px",marginTop:"2px"},children:u(a.size)})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginLeft:"8px"},children:[S&&jsxRuntime.jsx("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",style:{background:"none",border:"none",color:i.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px",textDecoration:"none"},title:f("input.previewImage"),children:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),jsxRuntime.jsx("button",{onClick:()=>C(a.id),style:{background:"none",border:"none",color:i.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px"},title:f("input.removeFile"),children:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]},a.id)})}),s&&jsxRuntime.jsxs("div",{style:{padding:"0px 16px 12px 16px",display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:i.mutedTextColor},children:[jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"spin 1s linear infinite"},children:jsxRuntime.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsxRuntime.jsx("span",{children:f("input.uploadingFiles")})]}),jsxRuntime.jsx("div",{style:{padding:"0 16px"},children:jsxRuntime.jsx("textarea",{ref:r,"aria-label":f("input.prompt"),rows:1,placeholder:f("input.placeholder"),value:e,onChange:a=>t(a.target.value),onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),y());},disabled:s,style:{height:"24px",maxHeight:"200px",width:"100%",resize:"none",backgroundColor:"transparent",fontSize:"15px",lineHeight:"1.6",outline:"none",border:"none",color:i.textColor,fontFamily:"inherit",overflow:"auto",direction:l?"rtl":"ltr",textAlign:l?"right":"left"}})}),jsxRuntime.jsx("input",{ref:n,type:"file",multiple:true,onChange:T,style:{display:"none"},accept:"*/*"}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"8px",...l?{right:"8px"}:{left:"8px"},display:"flex",alignItems:"center",gap:"4px",color:i.mutedTextColor},children:jsxRuntime.jsx("button",{onClick:()=>n.current?.click(),disabled:o||s,style:{borderRadius:"8px",padding:"8px",transition:"all 0.2s",backgroundColor:"transparent",border:"none",cursor:o||s?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"inherit",opacity:o||s?.5:1},"aria-label":f("input.attachFiles"),children:jsxRuntime.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 1 1 5.66 5.66l-9.2 9.19a2 2 0 1 1-2.83-2.83l8.49-8.49"})})})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"8px",...l?{left:"8px"}:{right:"8px"}},children:o?jsxRuntime.jsx("button",{onClick:I,disabled:!d,"aria-label":f("input.stop"),title:"Stop generation",style:{borderRadius:"12px",padding:"12px",transition:"all 0.2s ease-out",border:`1px solid ${i.errorColor}`,backgroundColor:i.errorColorLight||`${i.errorColor}20`,color:i.errorColor,opacity:d?1:.4,cursor:d?"pointer":"not-allowed",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:a=>{d&&(a.currentTarget.style.backgroundColor=i.errorColorLight||`${i.errorColor}30`,a.currentTarget.style.transform="scale(1.02)");},onMouseLeave:a=>{a.currentTarget.style.backgroundColor=i.errorColorLight||`${i.errorColor}20`,a.currentTarget.style.transform="scale(1)";},children:jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"})})}):jsxRuntime.jsx("button",{onClick:y,disabled:!h||s,"aria-label":f("input.send"),title:"Send message",style:{borderRadius:"12px",padding:"12px",transition:"all 0.2s ease-out",border:`1px solid ${i.borderColor}`,backgroundColor:i.cardBackground,color:!h||s?i.mutedTextColor:i.primaryColor,cursor:!h||s?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",opacity:!h||s?.5:1},onMouseEnter:a=>{h&&!s&&(a.currentTarget.style.borderColor=i.primaryColor,a.currentTarget.style.transform="scale(1.02)");},onMouseLeave:a=>{a.currentTarget.style.borderColor=i.borderColor,a.currentTarget.style.transform="scale(1)";},children:jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"m5 12 7-7 7 7"}),jsxRuntime.jsx("path",{d:"M12 19V5"})]})})})]})})})}function tr({prompts:e,onSelect:t,resolvedColors:r,disabled:n=false,dir:o="ltr",t:s}){let[g,u]=To.useState(null),C=o==="rtl";return !e||e.length===0?null:jsxRuntime.jsxs("div",{style:{padding:"12px 0",display:"flex",flexDirection:"column",gap:"8px",direction:C?"rtl":"ltr"},children:[jsxRuntime.jsx("div",{style:{fontSize:"12px",fontWeight:600,color:r.mutedTextColor,...C?{paddingRight:"4px",textAlign:"right"}:{paddingLeft:"4px",textAlign:"left"},textTransform:"uppercase",letterSpacing:"0.5px"},children:s?s("prompts.suggested"):"Suggested Prompts"}),jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((T,y)=>{let I=g===y,k=T.prompt.length>180,f=k&&!I?T.prompt.slice(0,180)+"...":T.prompt;return jsxRuntime.jsxs("button",{onClick:()=>{n||t(T.prompt);},disabled:n,style:{display:"flex",flexDirection:"column",padding:"12px",backgroundColor:r.cardBackground,border:`1px solid ${r.borderColor}`,borderRadius:"12px",cursor:n?"not-allowed":"pointer",transition:"all 0.2s ease",textAlign:C?"right":"left",opacity:n?.5:1,position:"relative",overflow:"hidden"},onMouseEnter:i=>{n||(i.currentTarget.style.backgroundColor=r.hoverBackground,i.currentTarget.style.borderColor=r.primaryColor,i.currentTarget.style.transform=C?"translateX(-2px)":"translateX(2px)");},onMouseLeave:i=>{i.currentTarget.style.backgroundColor=r.cardBackground,i.currentTarget.style.borderColor=r.borderColor,i.currentTarget.style.transform="translateX(0)";},children:[jsxRuntime.jsxs("div",{style:{fontSize:"13px",fontWeight:600,color:r.textColor,marginBottom:"6px",display:"flex",alignItems:"center",gap:"6px"},children:[jsxRuntime.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:r.primaryColor,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[jsxRuntime.jsx("path",{d:"M12 20h9"}),jsxRuntime.jsx("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]}),T.label]}),jsxRuntime.jsx("div",{style:{fontSize:"12px",color:r.mutedTextColor,lineHeight:"1.5",width:"100%",wordWrap:"break-word",whiteSpace:"pre-wrap",direction:C?"rtl":"ltr",textAlign:C?"right":"left"},children:f}),k&&jsxRuntime.jsxs("button",{onClick:i=>{i.stopPropagation(),u(I?null:y);},style:{marginTop:"8px",padding:"4px 8px",fontSize:"11px",color:r.primaryColor,backgroundColor:"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",gap:"4px",fontWeight:500},children:[I?s?s("prompts.showLess"):"Show less":s?s("prompts.showMore"):"Show more",jsxRuntime.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:I?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.2s"},children:jsxRuntime.jsx("polyline",{points:"6 9 12 15 18 9"})})]})]},y)})})]})}function ko(e){let t=Date.now()-e,r=Math.max(1,Math.floor(t/1e3));if(r<60)return `${r}s`;let n=Math.floor(r/60);if(n<60)return `${n}m`;let o=Math.floor(n/60);if(o<24)return `${o}h`;let s=Math.floor(o/24);if(s<7)return `${s}d`;let g=Math.floor(s/7);if(g<4)return `${g}w`;let u=Math.floor(s/30);return u<12?`${u}mo`:`${Math.floor(u/12)}y`}function Tt({search:e,onSearchChange:t,chats:r,currentChatId:n,resolvedColors:o,onChatSelect:s,onChatDelete:g,className:u,style:C,dir:T="ltr",t:y}){let I=T==="rtl",k=e.trim()?r.filter(f=>(f.title||"").toLowerCase().includes(e.toLowerCase().trim())):r;return jsxRuntime.jsxs("div",{className:u,style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden",direction:I?"rtl":"ltr",...C},children:[jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",gap:"12px",borderBottom:`1px solid ${o.borderColor}`,padding:"12px 16px",flexShrink:0},children:jsxRuntime.jsx("div",{style:{flex:"1"},children:jsxRuntime.jsx("input",{value:e,onChange:f=>t(f.target.value),placeholder:y?y("history.search"):"Search",style:{width:"100%",borderRadius:"8px",backgroundColor:o.inputBackground,padding:"8px 12px",fontSize:"14px",color:o.textColor,border:`1px solid ${o.borderColor}`,outline:"none",direction:I?"rtl":"ltr",textAlign:I?"right":"left"},onFocus:f=>f.currentTarget.style.borderColor=o.primaryColor,onBlur:f=>f.currentTarget.style.borderColor=o.borderColor})})}),jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0"},children:k.length===0?jsxRuntime.jsx("div",{style:{padding:"24px",color:o.mutedTextColor,textAlign:"center"},children:y?y("history.noChatsFound"):"No chats found."}):jsxRuntime.jsx("div",{children:k.map((f,i)=>jsxRuntime.jsx("div",{style:{borderTop:i>0?`1px solid ${o.borderColor}`:"none"},children:jsxRuntime.jsxs("div",{style:{display:"flex",width:"100%",alignItems:"center",justifyContent:"space-between",gap:"12px",padding:"8px 12px",backgroundColor:f.id===n?o.cardBackground:"transparent",transition:"background-color 0.2s"},children:[jsxRuntime.jsx("button",{style:{flex:"1",textAlign:I?"right":"left",transition:"background-color 0.2s",borderRadius:"8px",padding:"8px",border:"none",backgroundColor:"transparent",cursor:"pointer",color:o.textColor,overflow:"hidden"},onMouseEnter:b=>b.currentTarget.style.backgroundColor=o.hoverBackground,onMouseLeave:b=>b.currentTarget.style.backgroundColor="transparent",onClick:()=>s(f.id),children:jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"12px"},children:[jsxRuntime.jsx("div",{style:{minWidth:"0",flex:"1"},children:jsxRuntime.jsx("div",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"14px",color:o.textColor,fontWeight:f.id===n?600:400},children:f.title||(y?y("history.untitledChat"):"Untitled chat")})}),jsxRuntime.jsx("div",{style:{flexShrink:0,fontSize:"12px",color:o.mutedTextColor},children:ko(f.updatedAt)})]})}),jsxRuntime.jsx("button",{style:{flexShrink:0,borderRadius:"6px",padding:"8px",color:o.mutedTextColor,border:"1px solid transparent",backgroundColor:"transparent",cursor:"pointer",transition:"all 0.2s"},title:y?y("history.deleteChat"):"Delete chat",onMouseEnter:b=>{b.currentTarget.style.color=o.dangerColor,b.currentTarget.style.backgroundColor=o.dangerColorLight,b.currentTarget.style.borderColor=`${o.dangerColor}4d`;},onMouseLeave:b=>{b.currentTarget.style.color=o.mutedTextColor,b.currentTarget.style.backgroundColor="transparent",b.currentTarget.style.borderColor="transparent";},onClick:b=>{b.stopPropagation(),g(f.id);},children:jsxRuntime.jsx(X,{IconComponent:lucideReact.Trash2,size:"16",strokeWidth:"2"})})]})},f.id))})})]})}function nr({historyOpen:e,historySearch:t,currentChatId:r,refreshKey:n,resolvedColors:o,onClose:s,onSearchChange:g,onChatSelect:u,onChatDelete:C,loadChatsIndex:T,historyPopupRef:y,dir:I="ltr",t:k}){if(!e)return null;let f=T(),i=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:s}),jsxRuntime.jsx("div",{ref:y,style:{position:"fixed",left:"50%",top:"64px",transform:"translateX(-50%)",zIndex:1101,width:"680px",maxWidth:"94vw",height:"60vh",maxHeight:"600px",overflow:"hidden",borderRadius:"16px",border:`1px solid ${o.borderColor}`,backgroundColor:`${o.backgroundColor}f0`,boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",display:"flex",flexDirection:"column"},children:jsxRuntime.jsx(Tt,{search:t,onSearchChange:g,chats:f,currentChatId:r,resolvedColors:o,onChatSelect:u,onChatDelete:C,dir:I,t:k})})]});return typeof document<"u"&&document.body?reactDom.createPortal(i,document.body):i}function wo({isOpen:e,historySearch:t,onSearchChange:r,chats:n,currentChatId:o,resolvedColors:s,onChatSelect:g,onChatDelete:u,onNewChat:C,isMobile:T=false,dir:y="ltr",t:I}){let k=y==="rtl";return jsxRuntime.jsxs("div",{style:{width:e?"260px":"0px",opacity:e?1:0,...k?{marginRight:e?0:-10}:{marginLeft:e?0:-10},height:"100%",backgroundColor:s.backgroundColor,...k?{borderLeft:e?`1px solid ${s.borderColor}`:"none"}:{borderRight:e?`1px solid ${s.borderColor}`:"none"},display:"flex",flexDirection:"column",transition:"all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",overflow:"hidden",flexShrink:0,position:T?"fixed":"relative",zIndex:T?100:1,...k?{right:0}:{left:0},top:0,bottom:0,visibility:e?"visible":"hidden",direction:k?"rtl":"ltr"},children:[jsxRuntime.jsx("div",{style:{padding:"12px",flexShrink:0,opacity:e?1:0,transition:"opacity 0.2s 0.1s"},children:jsxRuntime.jsxs("button",{onClick:C,style:{width:"100%",display:"flex",alignItems:"center",gap:"12px",padding:"10px 12px",borderRadius:"8px",border:`1px solid ${s.borderColor}`,backgroundColor:"transparent",color:s.textColor,cursor:"pointer",fontSize:"14px",transition:"all 0.2s",textAlign:k?"right":"left"},onMouseEnter:f=>f.currentTarget.style.backgroundColor=s.hoverBackground,onMouseLeave:f=>f.currentTarget.style.backgroundColor="transparent",children:[jsxRuntime.jsx(X,{IconComponent:lucideReact.Plus,size:"16",strokeWidth:"2"}),jsxRuntime.jsx("span",{children:I?I("history.newChat"):"New chat"})]})}),jsxRuntime.jsx(Tt,{search:t,onSearchChange:r,chats:n,currentChatId:o,resolvedColors:s,onChatSelect:g,onChatDelete:u,dir:y,t:I,style:{flex:1}})]})}function ar({isOpen:e,resolvedColors:t,onConfirm:r,onCancel:n,editProcessContent:o,dir:s="ltr",t:g}){if(!e)return null;let u=o?.title||(g?g("editModal.title"):"Edit Message"),C=o?.content||(g?g("editModal.content"):"This will remove this message and all messages after it, and place its content in the input field for editing. Do you want to continue?"),T=o?.submit_button_label||(g?g("editModal.submit"):"Edit"),y=o?.cancel_button_label||(g?g("editModal.cancel"):"Cancel"),I=o?.icon,k=typeof C=="function",f=k?C:null,i=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:n}),jsxRuntime.jsxs("div",{style:{position:"fixed",left:"50%",top:"50%",transform:"translate(-50%, -50%)",zIndex:1101,width:"420px",maxWidth:"94vw",overflow:"hidden",borderRadius:"16px",border:`1px solid ${t.borderColor}`,backgroundColor:t.backgroundColor,boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",direction:s==="rtl"?"rtl":"ltr"},children:[jsxRuntime.jsxs("div",{style:{padding:"20px 24px",borderBottom:`1px solid ${t.borderColor}`,display:"flex",alignItems:"center",gap:"12px"},children:[I?jsxRuntime.jsx("div",{style:{flexShrink:0},children:jsxRuntime.jsx(X,{IconComponent:I,size:"20",strokeWidth:"2"})}):jsxRuntime.jsx("div",{style:{flexShrink:0,color:t.mutedTextColor},children:jsxRuntime.jsx(X,{IconComponent:lucideReact.Pencil,size:"20",strokeWidth:"2"})}),jsxRuntime.jsx("h3",{style:{margin:0,fontSize:"18px",fontWeight:"600",color:t.textColor,flex:1},children:u})]}),jsxRuntime.jsx("div",{style:{padding:"24px",color:t.textColor,fontSize:"14px",lineHeight:"1.6"},children:k&&f?jsxRuntime.jsx(f,{}):jsxRuntime.jsx("p",{style:{margin:0},children:C})}),jsxRuntime.jsxs("div",{style:{display:"flex",gap:"12px",padding:"16px 24px",borderTop:`1px solid ${t.borderColor}`,justifyContent:"flex-end"},children:[jsxRuntime.jsx("button",{onClick:n,style:{padding:"8px 16px",borderRadius:"8px",fontSize:"14px",fontWeight:"500",border:`1px solid ${t.borderColor}`,backgroundColor:"transparent",color:t.textColor,cursor:"pointer",transition:"all 0.2s"},onMouseEnter:b=>{b.currentTarget.style.backgroundColor=t.hoverBackground;},onMouseLeave:b=>{b.currentTarget.style.backgroundColor="transparent";},children:y}),jsxRuntime.jsx("button",{onClick:r,style:{padding:"8px 16px",borderRadius:"8px",fontSize:"14px",fontWeight:"500",border:"none",backgroundColor:t.primaryColor,color:t.backgroundColor,cursor:"pointer",transition:"all 0.2s",opacity:1},onMouseEnter:b=>{b.currentTarget.style.opacity="0.9";},onMouseLeave:b=>{b.currentTarget.style.opacity="1";},children:T})]})]})]});return typeof document<"u"&&document.body?reactDom.createPortal(i,document.body):i}function _n({agentId:e,theme:t,primaryColor:r,primaryColorDark:n,primaryColorLight:o,backgroundColor:s,borderColor:g,textColor:u,accentColor:C,errorColor:T,errorColorLight:y,errorColorDark:I,successColor:k,successColorLight:f,warningColor:i,warningColorLight:b,infoColor:c,infoColorLight:d,dangerColor:h,dangerColorLight:l,dangerColorDark:a,dir:S,lang:v,language:x,baseUrl:w="",initialMessages:M=[],onMessagesChange:p,defaultOpen:F=true,floatingButtonPosition:G={bottom:24,right:24},HsafaTools:_={},HsafaUI:re={},componentAboveInput:le,editProcessContent:oe,presetPrompts:O,onStart:j,onFinish:K,currentChat:D,onChatChanged:fe,templateParams:J,fullPageChat:ee=false,title:be,placeholder:ye,emptyStateMessage:Te}){let {dir:Et,theme:st,baseUrl:Ie,setStreamingState:Ue,setChatOpenState:Oe}=ce(),Z=S||Et||"ltr",A=v||x||"en",z=A==="ar",B=t||st||"dark",N=w&&w.length>0?w:Ie||"",E={primaryColor:B==="dark"?n||r||"#ffffff":o||r||"#000000",backgroundColor:s||(B==="dark"?"#0B0B0F":"#FFFFFF"),borderColor:g||(B==="dark"?"#2A2C33":"#E5E7EB"),textColor:u||(B==="dark"?"#EDEEF0":"#111827"),accentColor:C||(B==="dark"?"#17181C":"#F9FAFB"),mutedTextColor:B==="dark"?"#6f7276":"#6B7280",inputBackground:B==="dark"?"#17181C":"#F3F4F6",cardBackground:B==="dark"?"#121318":"#FFFFFF",hoverBackground:B==="dark"?"#1c1e25":"#F3F4F6",errorColor:T||"#ef4444",errorColorLight:y||(B==="dark"?"#fee2e2":"#fef2f2"),errorColorDark:I||"#991b1b",successColor:k||"#10b981",successColorLight:f||(B==="dark"?"rgba(16,185,129,0.15)":"#d1fae5"),warningColor:i||"#eab308",warningColorLight:b||(B==="dark"?"rgba(234,179,8,0.15)":"#fef3c7"),infoColor:c||"#3b82f6",infoColorLight:d||(B==="dark"?"rgba(59,130,246,0.15)":"#dbeafe"),dangerColor:h||"#ef4444",dangerColorLight:l||"rgba(239, 68, 68, 0.1)",dangerColorDark:a||"#991b1b"},$=m=>{let L={"header.new":"New","header.history":"History","header.close":"Close chat","input.placeholder":ye||"Ask your question...","input.prompt":"Prompt","input.attachFiles":"Attach files","input.insertLink":"Insert link","input.send":"Send","input.stop":"Stop","input.uploadingFiles":"Uploading files...","input.previewImage":"Preview image","input.removeFile":"Remove file","messages.empty":Te||"Start by sending a message to the agent.","general.agent":be||"Agent","editor.cancel":"Cancel","editor.saveAndRegenerate":"Save & Regenerate","editor.clickToEdit":"Click to edit","prompts.suggested":"Suggested Prompts","prompts.showMore":"Show more","prompts.showLess":"Show less","history.search":"Search","history.noChatsFound":"No chats found.","history.untitledChat":"Untitled chat","history.deleteChat":"Delete chat","history.newChat":"New chat","editModal.title":"Edit Message","editModal.content":"This will remove this message and all messages after it, and place its content in the input field for editing. Do you want to continue?","editModal.submit":"Edit","editModal.cancel":"Cancel","assistant.thinking":"Thinking","assistant.finishThinking":"Finish Thinking","tool.inputting":"Inputting","tool.running":"Running","tool.error":"Error","tool.called":"Called","error.occurred":"An error occurred:","error.tryAgain":"Please try again.","error.refresh":"Refresh","error.failedSend":"Failed to send message. Please try again.","error.failedEdit":"Failed to edit message. Please try again."};return (z?{"header.new":"\u062C\u062F\u064A\u062F","header.history":"\u0627\u0644\u0633\u062C\u0644","header.close":"\u0625\u063A\u0644\u0627\u0642 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629","input.placeholder":ye||"\u0627\u0643\u062A\u0628 \u0633\u0624\u0627\u0644\u0643...","input.prompt":"\u0627\u0644\u0631\u0633\u0627\u0644\u0629","input.attachFiles":"\u0625\u0631\u0641\u0627\u0642 \u0645\u0644\u0641\u0627\u062A","input.insertLink":"\u0625\u062F\u0631\u0627\u062C \u0631\u0627\u0628\u0637","input.send":"\u0625\u0631\u0633\u0627\u0644","input.stop":"\u0625\u064A\u0642\u0627\u0641","input.uploadingFiles":"\u062C\u0627\u0631\u064D \u0631\u0641\u0639 \u0627\u0644\u0645\u0644\u0641\u0627\u062A...","input.previewImage":"\u0645\u0639\u0627\u064A\u0646\u0629 \u0627\u0644\u0635\u0648\u0631\u0629","input.removeFile":"\u0625\u0632\u0627\u0644\u0629 \u0627\u0644\u0645\u0644\u0641","messages.empty":Te||"\u0627\u0628\u062F\u0623 \u0628\u0625\u0631\u0633\u0627\u0644 \u0631\u0633\u0627\u0644\u0629 \u0625\u0644\u0649 \u0627\u0644\u0648\u0643\u064A\u0644.","general.agent":be||"\u0627\u0644\u0648\u0643\u064A\u0644","editor.cancel":"\u0625\u0644\u063A\u0627\u0621","editor.saveAndRegenerate":"\u062D\u0641\u0638 \u0648\u0625\u0639\u0627\u062F\u0629 \u0627\u0644\u062A\u0648\u0644\u064A\u062F","editor.clickToEdit":"\u0627\u0646\u0642\u0631 \u0644\u0644\u062A\u0639\u062F\u064A\u0644","prompts.suggested":"\u0627\u0642\u062A\u0631\u0627\u062D\u0627\u062A \u062C\u0627\u0647\u0632\u0629","prompts.showMore":"\u0639\u0631\u0636 \u0627\u0644\u0645\u0632\u064A\u062F","prompts.showLess":"\u0639\u0631\u0636 \u0623\u0642\u0644","history.search":"\u0628\u062D\u062B","history.noChatsFound":"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A.","history.untitledChat":"\u0645\u062D\u0627\u062F\u062B\u0629 \u0628\u062F\u0648\u0646 \u0639\u0646\u0648\u0627\u0646","history.deleteChat":"\u062D\u0630\u0641 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629","history.newChat":"\u0645\u062D\u0627\u062F\u062B\u0629 \u062C\u062F\u064A\u062F\u0629","editModal.title":"\u062A\u0639\u062F\u064A\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629","editModal.content":"\u0633\u064A\u0624\u062F\u064A \u0647\u0630\u0627 \u0625\u0644\u0649 \u062D\u0630\u0641 \u0647\u0630\u0647 \u0627\u0644\u0631\u0633\u0627\u0644\u0629 \u0648\u0643\u0644 \u0627\u0644\u0631\u0633\u0627\u0626\u0644 \u0627\u0644\u062A\u064A \u0628\u0639\u062F\u0647\u0627\u060C \u062B\u0645 \u0648\u0636\u0639 \u0645\u062D\u062A\u0648\u0627\u0647\u0627 \u0641\u064A \u062D\u0642\u0644 \u0627\u0644\u0625\u062F\u062E\u0627\u0644 \u0644\u0644\u062A\u0639\u062F\u064A\u0644. \u0647\u0644 \u062A\u0631\u064A\u062F \u0627\u0644\u0645\u062A\u0627\u0628\u0639\u0629\u061F","editModal.submit":"\u062A\u0639\u062F\u064A\u0644","editModal.cancel":"\u0625\u0644\u063A\u0627\u0621","assistant.thinking":"\u062C\u0627\u0631\u064D \u0627\u0644\u062A\u0641\u0643\u064A\u0631","assistant.finishThinking":"\u0627\u0646\u062A\u0647\u0649 \u0627\u0644\u062A\u0641\u0643\u064A\u0631","tool.inputting":"\u062C\u0627\u0631\u064D \u0627\u0644\u0625\u062F\u062E\u0627\u0644","tool.running":"\u0642\u064A\u062F \u0627\u0644\u062A\u0634\u063A\u064A\u0644","tool.error":"\u062E\u0637\u0623","tool.called":"\u062A\u0645 \u0627\u0644\u0627\u0633\u062A\u062F\u0639\u0627\u0621","error.occurred":"\u062D\u062F\u062B \u062E\u0637\u0623:","error.tryAgain":"\u064A\u0631\u062C\u0649 \u0627\u0644\u0645\u062D\u0627\u0648\u0644\u0629 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649.","error.refresh":"\u062A\u062D\u062F\u064A\u062B","error.failedSend":"\u062A\u0639\u0630\u0631 \u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629. \u064A\u0631\u062C\u0649 \u0627\u0644\u0645\u062D\u0627\u0648\u0644\u0629 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649.","error.failedEdit":"\u062A\u0639\u0630\u0631 \u062A\u0639\u062F\u064A\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629. \u064A\u0631\u062C\u0649 \u0627\u0644\u0645\u062D\u0627\u0648\u0644\u0629 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649."}:L)[m]||L[m]||m},Rt=Vt({agentId:e,baseUrl:N,tools:_,uiComponents:re,templateParams:J,controlledChatId:D,onChatIdChange:D===void 0?m=>{fe&&fe(m);}:void 0,onStart:To.useCallback(m=>{j&&j(m);},[j]),onFinish:To.useCallback(m=>{K&&K(m);},[K]),onError:To.useCallback(m=>{console.error("Chat error:",m);},[]),initialMessages:M,onMessagesChange:p}),{input:Ge,setInput:Se,messages:Ce,isLoading:q,status:lr,error:lt,sendMessage:dr,stop:cr,setMessages:de,notifyMessagesChange:ur,chatId:At,setChatId:dt,tools:Qn,uiComponents:pr,formHostRef:ea,formStateRef:ta,cleanupForms:je,onUISuccess:gr,onUIError:mr,chatApi:fr}=Rt,V=D!==void 0?D:At,Me=To.useCallback(m=>{D===void 0&&dt(m),fe&&fe(m);},[D,dt,fe]);To.useEffect(()=>{D!==void 0&&D!==At&&dt(D);},[D,At,dt]);let{attachments:_e,uploading:hr,fileInputRef:qe,formatBytes:yr,handleRemoveAttachment:xr,handleFileSelection:br,clearAttachments:ct,setAttachments:Cr}=qr(N),[ut,Ee]=To.useState(null),[pt,kr]=To.useState(()=>{try{return xt(e).loadShowChatPreference(!!F)}catch{return !!F}}),[Lt,Fe]=To.useState(false),[Ht,Ft]=To.useState(""),[Dt,Bt]=To.useState(0),vr=To.useRef(null),wr=To.useRef(null),[Tr,Ir]=To.useState(new Set),[Sr,Pt]=To.useState(false),[Ke,$t]=To.useState(null),Ve=To.useRef(null),Mr=Or(q),[Er,Mo]=To.useState(false);To.useEffect(()=>{let m=()=>Mo(window.innerWidth<768);return m(),window.addEventListener("resize",m),()=>window.removeEventListener("resize",m)},[]);let zt=Yt({agentId:e,chatId:V,messages:Ce,isLoading:q,autoSave:true,autoRestore:false}),W=zt.storage,Rr=To.useMemo(()=>{try{return W.loadChatsIndex()}catch{return []}},[W,Dt]),Xe=To.useRef(false),Ye=To.useRef(null);To.useEffect(()=>{if(!Xe.current){if(D!==void 0){try{let m=W.loadChat(D),L=m&&Array.isArray(m.messages)?m.messages:[];if(L.length>0)try{de(L);}catch{}Ye.current=D;}catch{}try{W.saveCurrentChatId(D);}catch{}Xe.current=true;return}try{let m=W.loadCurrentChatId();if(m){Me(m);let L=W.loadChat(m),P=L&&Array.isArray(L.messages)?L.messages:[];try{de(P);}catch{}Ye.current=m;}}catch{}Xe.current=true;}},[D]),To.useEffect(()=>{if(Xe.current&&D!==void 0&&D!==Ye.current)try{let m=W.loadChat(D),L=m&&Array.isArray(m.messages)?m.messages:[];try{de(L);}catch{}Ye.current=D;try{W.saveCurrentChatId(D);}catch{}}catch{}},[D,W,de]),To.useEffect(()=>{if(Xe.current)try{W.saveCurrentChatId(V);}catch{}},[V,W]),To.useEffect(()=>{try{Ue(V,q);}catch{}return ()=>{try{Ue(V,!1);}catch{}}},[V,q,Ue]),To.useEffect(()=>{try{Oe(V,pt);}catch{}return ()=>{try{Oe(V,!1);}catch{}}},[V,pt,Oe]);let Ar=To.useCallback(async()=>{let m=Ge.trim();if(!m&&_e.length===0||q)return;let L=[..._e];Se(""),ct(),Ee(null),Ve.current&&Ve.current.focus();try{await dr({text:m,files:L.map(P=>({type:"file",url:P.url,mediaType:P.mimeType||"application/octet-stream",...P.name?{name:P.name}:{},...P.size?{size:P.size}:{}}))});}catch(P){console.error("Failed to send message:",P),Ee($("error.failedSend"));}},[Ge,_e,q,dr,ct,$]),De=To.useCallback(()=>{if(q)return;je(),Se(""),ct(),Ee(null);try{de([]);}catch{}let m=`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`;Ye.current=m;try{zt.createNewChat(()=>{Me(m);try{W.saveCurrentChatId(m);}catch{}});}catch{Me(m);try{W.saveCurrentChatId(m);}catch{}}},[q,ct,W,de,Me,je,zt]),Lr=To.useCallback(()=>{Fe(m=>!m);},[]),Eo=To.useCallback(()=>{kr(false);try{W.saveShowChatPreference(!1);}catch{}},[W]),Hr=To.useCallback(async m=>{let L=m.target.files;L&&await br(L,Ee),qe.current&&(qe.current.value="");},[br,qe]);To.useEffect(()=>{let m=Ve.current;if(!m)return;m.style.height="24px",m.offsetHeight,m.style.height="auto";let L=Math.min(m.scrollHeight,200);m.style.height=`${L}px`;},[Ge]);let Fr=To.useCallback((m,L,P,$r)=>{$t({id:L,text:P,attachments:$r||[]}),Pt(true);},[]),Dr=To.useCallback(()=>{if(!(!Ke||q))try{let m=Ce.findIndex(P=>P.id===Ke.id);if(m===-1)return;let L=Ce.slice(0,m);try{de(L);}catch{}Se(Ke.text),Cr(Ke.attachments),Pt(!1),$t(null),ur();}catch(m){console.error("Failed to edit message:",m),Ee($("error.failedEdit"));}},[Ke,q,Ce,de,Cr,ur,$]),Br=To.useCallback(()=>{Pt(false),$t(null);},[]),Ro=jsxRuntime.jsxs("div",{style:{position:"fixed",inset:0,display:"flex",backgroundColor:E.backgroundColor,color:E.textColor,overflow:"hidden"},children:[!Er&&jsxRuntime.jsx(wo,{isOpen:Lt,historySearch:Ht,onSearchChange:Ft,chats:Rr,currentChatId:V,resolvedColors:E,dir:Z,t:$,onChatSelect:m=>{if(m&&m!==V&&(je(),Me(m),D===void 0)){try{W.saveCurrentChatId(m);}catch{}try{let L=W.loadChat(m),P=L&&Array.isArray(L.messages)?L.messages:[];try{de(P);}catch{}}catch{}}},onChatDelete:m=>{try{W.deleteChat(m),Bt(L=>L+1),m===V&&De();}catch{}},onNewChat:De,onClose:()=>Fe(false)}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",flex:1,minWidth:0,position:"relative"},children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 20px",backgroundColor:E.backgroundColor,minHeight:"60px",zIndex:10},children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[jsxRuntime.jsx("button",{ref:vr,onClick:Lr,style:{padding:"8px",borderRadius:"8px",border:"none",backgroundColor:"transparent",color:E.mutedTextColor,cursor:"pointer",transition:"all 0.2s",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:m=>{m.currentTarget.style.backgroundColor=E.hoverBackground,m.currentTarget.style.color=E.textColor;},onMouseLeave:m=>{m.currentTarget.style.backgroundColor="transparent",m.currentTarget.style.color=E.mutedTextColor;},"aria-label":$("header.history"),children:jsxRuntime.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),jsxRuntime.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),jsxRuntime.jsx("h1",{style:{fontSize:"16px",fontWeight:600,margin:0,color:E.textColor},children:$("general.agent")})]}),jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:jsxRuntime.jsx("button",{onClick:De,disabled:q,style:{padding:"8px",borderRadius:"8px",border:"none",backgroundColor:"transparent",color:E.mutedTextColor,cursor:q?"not-allowed":"pointer",transition:"all 0.2s",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:m=>{q||(m.currentTarget.style.backgroundColor=E.hoverBackground,m.currentTarget.style.color=E.textColor);},onMouseLeave:m=>{m.currentTarget.style.backgroundColor="transparent",m.currentTarget.style.color=E.mutedTextColor;},"aria-label":$("header.new"),children:jsxRuntime.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M12 5v14M5 12h14"})})})})]}),jsxRuntime.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},children:[jsxRuntime.jsx("div",{ref:Mr,className:"chat-scroll-container",style:{flex:1,overflowY:"auto",overflowX:"hidden",display:"flex",flexDirection:"column",scrollBehavior:"smooth","--hsafa-primary":E.primaryColor,"--hsafa-border":E.borderColor,"--hsafa-card":E.cardBackground,"--hsafa-text":E.textColor,"--hsafa-muted":E.mutedTextColor,"--hsafa-bg":E.backgroundColor,"--hsafa-hover":E.hoverBackground,"--hsafa-input-bg":E.inputBackground,"--hsafa-accent":E.accentColor},children:jsxRuntime.jsx("div",{style:{maxWidth:"768px",width:"100%",margin:"0 auto",padding:"32px 24px",display:"flex",flexDirection:"column",gap:"24px"},children:Ce.length===0?jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px",padding:"64px 0"},children:O&&O.length>0?jsxRuntime.jsx(tr,{prompts:O,onSelect:m=>Se(m),resolvedColors:E,disabled:q,dir:Z,t:$}):jsxRuntime.jsx("div",{style:{padding:"64px 32px",textAlign:"center",color:E.mutedTextColor,fontSize:"16px"},children:$("messages.empty")})}):jsxRuntime.jsx(Qt,{chatMessages:Ce,isLoading:q,openReasoningIds:Tr,toggleReasoning:m=>Ir(L=>{let P=new Set(L);return P.has(m)?P.delete(m):P.add(m),P}),resolvedColors:E,t:$,onUserMessageClick:Fr,HsafaUI:pr,onUIError:mr,onUISuccess:gr,addToolResult:m=>fr?.addToolResult?.(m),editableMessageIcon:oe?.message_icon,fullPage:true,dir:Z})})}),jsxRuntime.jsx("div",{style:{backgroundColor:E.backgroundColor,padding:"0 24px 24px",position:"relative",zIndex:20},children:jsxRuntime.jsxs("div",{style:{maxWidth:"768px",width:"100%",margin:"0 auto"},children:[le&&To__default.default.createElement(le,{}),ut&&jsxRuntime.jsxs("div",{style:{padding:"12px 16px",marginBottom:"12px",backgroundColor:E.errorColor,color:"#fff",borderRadius:"8px",fontSize:"14px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{children:ut}),jsxRuntime.jsx("button",{onClick:()=>Ee(null),style:{background:"none",border:"none",color:"#fff",cursor:"pointer",padding:"2px",fontSize:"20px"},children:"\xD7"})]}),lt&&jsxRuntime.jsxs("div",{style:{padding:"12px 16px",marginBottom:"12px",backgroundColor:E.errorColor,color:"#fff",borderRadius:"8px",fontSize:"14px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxRuntime.jsxs("span",{children:[$("error.occurred")," ",lt.message||$("error.tryAgain")]}),jsxRuntime.jsx("button",{onClick:()=>window.location.reload(),style:{background:"none",border:"1px solid #fff",color:"#fff",cursor:"pointer",padding:"4px 8px",borderRadius:"4px",fontSize:"12px"},children:$("error.refresh")})]}),jsxRuntime.jsx(er,{input:Ge,setInput:Se,textareaRef:Ve,fileInputRef:qe,isLoading:q,uploading:hr,attachments:_e,formatBytes:yr,handleRemoveAttachment:xr,onFileInputChange:Hr,onSend:Ar,onStop:()=>cr(),status:lr,t:$,resolvedColors:E,fullPage:true,dir:Z})]})})]})]}),Er&&jsxRuntime.jsx(nr,{historyOpen:Lt,historySearch:Ht,currentChatId:V,refreshKey:Dt,resolvedColors:E,onClose:()=>Fe(false),onSearchChange:Ft,dir:Z,t:$,onChatSelect:m=>{if(Fe(false),m&&m!==V&&(je(),Me(m),D===void 0)){try{W.saveCurrentChatId(m);}catch{}try{let L=W.loadChat(m),P=L&&Array.isArray(L.messages)?L.messages:[];try{de(P);}catch{}}catch{}}},onChatDelete:m=>{try{W.deleteChat(m),Bt(L=>L+1),m===V&&De();}catch{}},loadChatsIndex:()=>Rr,historyPopupRef:wr}),jsxRuntime.jsx(ar,{isOpen:Sr,resolvedColors:E,t:$,editProcessContent:oe,onConfirm:Dr,onCancel:Br,dir:Z,lang:A}),jsxRuntime.jsx("style",{children:`
|
|
185
185
|
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
|
|
186
186
|
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
|
|
187
187
|
|
|
@@ -238,7 +238,7 @@
|
|
|
238
238
|
margin: 12px 0;
|
|
239
239
|
border: 1px solid var(--hsafa-border);
|
|
240
240
|
}
|
|
241
|
-
`})]}),
|
|
241
|
+
`})]}),Pr=jsxRuntime.jsxs("div",{style:{position:"fixed",right:0,top:0,bottom:0,width:"420px",display:"flex",flexDirection:"column",padding:"24px 16px",color:E.textColor,gap:"16px",zIndex:1e3,transform:pt?"translateX(0)":"translateX(100%)",transition:"transform 0.25s ease-out, width 0.2s ease-out"},children:[jsxRuntime.jsx(fo,{title:$("general.agent"),alwaysOpen:false,streaming:q,dir:Z,resolvedColors:E,onNew:De,onToggleHistory:Lr,onClose:Eo,historyBtnRef:vr,t:$}),jsxRuntime.jsx("div",{ref:Mr,className:"chat-scroll-container",style:{flex:"1",overflowY:"auto",overflowX:"hidden",padding:"16px 4px 16px 4px",display:"flex",flexDirection:"column",gap:"16px",scrollBehavior:"smooth","--hsafa-primary":E.primaryColor,"--hsafa-border":E.borderColor,"--hsafa-card":E.cardBackground,"--hsafa-text":E.textColor,"--hsafa-muted":E.mutedTextColor,"--hsafa-bg":E.backgroundColor,"--hsafa-hover":E.hoverBackground,"--hsafa-input-bg":E.inputBackground,"--hsafa-accent":E.accentColor},children:Ce.length===0?jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px",padding:"16px 0"},children:O&&O.length>0?jsxRuntime.jsx(tr,{prompts:O,onSelect:m=>Se(m),resolvedColors:E,disabled:q,dir:Z,t:$}):jsxRuntime.jsx("div",{style:{padding:"32px",textAlign:"center",color:E.mutedTextColor,fontSize:"14px"},children:$("messages.empty")})}):jsxRuntime.jsx(Qt,{chatMessages:Ce,isLoading:q,openReasoningIds:Tr,toggleReasoning:m=>Ir(L=>{let P=new Set(L);return P.has(m)?P.delete(m):P.add(m),P}),resolvedColors:E,t:$,onUserMessageClick:Fr,HsafaUI:pr,onUIError:mr,onUISuccess:gr,addToolResult:m=>fr?.addToolResult?.(m),editableMessageIcon:oe?.message_icon,dir:Z})}),jsxRuntime.jsxs("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px"},children:[le&&To__default.default.createElement(le,{}),ut&&jsxRuntime.jsxs("div",{style:{padding:"8px 12px",marginBottom:"8px",backgroundColor:E.errorColor,color:"#fff",borderRadius:"8px",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{children:ut}),jsxRuntime.jsx("button",{onClick:()=>Ee(null),style:{background:"none",border:"none",color:"#fff",cursor:"pointer",padding:"2px"},children:"\xD7"})]}),lt&&jsxRuntime.jsxs("div",{style:{padding:"8px 12px",marginBottom:"8px",backgroundColor:E.errorColor,color:"#fff",borderRadius:"8px",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxRuntime.jsxs("span",{children:[$("error.occurred")," ",lt.message||$("error.tryAgain")]}),jsxRuntime.jsx("button",{onClick:()=>window.location.reload(),style:{background:"none",border:"1px solid #fff",color:"#fff",cursor:"pointer",padding:"4px 8px",borderRadius:"4px",fontSize:"12px"},children:$("error.refresh")})]}),jsxRuntime.jsx(er,{input:Ge,setInput:Se,textareaRef:Ve,fileInputRef:qe,isLoading:q,uploading:hr,attachments:_e,formatBytes:yr,handleRemoveAttachment:xr,onFileInputChange:Hr,onSend:Ar,onStop:()=>cr(),status:lr,t:$,resolvedColors:E,dir:Z})]}),jsxRuntime.jsx(nr,{historyOpen:Lt,historySearch:Ht,currentChatId:V,refreshKey:Dt,resolvedColors:E,onClose:()=>Fe(false),onSearchChange:Ft,dir:Z,t:$,onChatSelect:m=>{if(Fe(false),m&&m!==V&&(je(),Me(m),D===void 0)){try{W.saveCurrentChatId(m);}catch{}try{let L=W.loadChat(m),P=L&&Array.isArray(L.messages)?L.messages:[];try{de(P);}catch{}}catch{}}},onChatDelete:m=>{try{W.deleteChat(m),Bt(L=>L+1),m===V&&De();}catch{}},loadChatsIndex:()=>W.loadChatsIndex(),historyPopupRef:wr}),jsxRuntime.jsx(ar,{isOpen:Sr,resolvedColors:E,t:$,dir:Z,lang:A,onConfirm:Dr,onCancel:Br,editProcessContent:oe}),jsxRuntime.jsx("style",{children:`
|
|
242
242
|
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
|
|
243
243
|
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
|
|
244
244
|
|
|
@@ -295,11 +295,11 @@
|
|
|
295
295
|
margin: 12px 0;
|
|
296
296
|
border: 1px solid var(--hsafa-border);
|
|
297
297
|
}
|
|
298
|
-
`})]});return
|
|
298
|
+
`})]});return ee?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(tt,{}),Ro]}):typeof document<"u"&&document.body?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(tt,{}),reactDom.createPortal(Pr,document.body),jsxRuntime.jsx(Nr,{show:!pt,onClick:()=>{kr(true);try{W.saveShowChatPreference(!0);}catch{}},resolvedColors:E,floatingButtonPosition:G})]}):Pr}var So={dark:{primaryColor:"#4D78FF",backgroundColor:"#0B0B0F",borderColor:"#2A2C33",textColor:"#EDEEF0",accentColor:"#17181C",mutedTextColor:"#9AA0A6",inputBackground:"#17181C",cardBackground:"#121318",hoverBackground:"#1c1e25",errorColor:"#ef4444",errorColorLight:"#fee2e2",errorColorDark:"#991b1b",successColor:"#10b981",successColorLight:"rgba(16,185,129,0.15)",warningColor:"#eab308",warningColorLight:"rgba(234,179,8,0.15)",infoColor:"#3b82f6",infoColorLight:"rgba(59,130,246,0.15)",dangerColor:"#ef4444",dangerColorLight:"rgba(239, 68, 68, 0.1)",dangerColorDark:"#991b1b"},light:{primaryColor:"#2563EB",backgroundColor:"#FFFFFF",borderColor:"#E5E7EB",textColor:"#111827",accentColor:"#F9FAFB",mutedTextColor:"#6B7280",inputBackground:"#F9FAFB",cardBackground:"#F3F4F6",hoverBackground:"#F3F4F6",errorColor:"#ef4444",errorColorLight:"#fef2f2",errorColorDark:"#991b1b",successColor:"#10b981",successColorLight:"#d1fae5",warningColor:"#eab308",warningColorLight:"#fef3c7",infoColor:"#3b82f6",infoColorLight:"#dbeafe",dangerColor:"#ef4444",dangerColorLight:"rgba(239, 68, 68, 0.1)",dangerColorDark:"#991b1b"}};function Xn({children:e,theme:t="dark",primaryColor:r,backgroundColor:n,borderColor:o,textColor:s,mutedTextColor:g,enableBorderAnimation:u=true,borderRadius:C=16,enableContentBorder:T=true,className:y="",enableMargin:I=true,chatWidth:k=420,dir:f="ltr"}){let{isAnyStreaming:i,isAnyChatOpen:b,dir:c,theme:d}=ce(),h=(f??c)||"ltr",l=(t??d)||"dark",a=To.useRef(`content-container-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),[S,v]=To.useState(false);To.useEffect(()=>{let _=setTimeout(()=>v(true),50);return ()=>clearTimeout(_)},[]);let x=So[l],w={primaryColor:r||x.primaryColor,backgroundColor:n||x.backgroundColor,borderColor:o||x.borderColor,textColor:s||x.textColor,accentColor:x.accentColor,mutedTextColor:g||x.mutedTextColor,inputBackground:x.inputBackground,cardBackground:x.cardBackground,hoverBackground:x.hoverBackground,errorColor:x.errorColor,errorColorLight:x.errorColorLight,errorColorDark:x.errorColorDark,successColor:x.successColor,successColorLight:x.successColorLight,warningColor:x.warningColor,warningColorLight:x.warningColorLight,infoColor:x.infoColor,infoColorLight:x.infoColorLight,dangerColor:x.dangerColor,dangerColorLight:x.dangerColorLight,dangerColorDark:x.dangerColorDark},M=typeof C=="number"?`${C}px`:C,p=typeof k=="number"?`${k}px`:k,F=I&&b?h==="rtl"?{marginLeft:p}:{marginRight:p}:{},G=I&&b?`calc(100% - ${p})`:"100%";return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:y,style:{width:G,height:"100%",transition:S?"all 0.2s ease-out":"none",padding:b&&T?"16px":"0",...F},children:jsxRuntime.jsx("div",{style:{position:"relative",width:"100%",height:"100%",transition:S?"all 0.2s ease-out":"none",borderRadius:b?M:"0",border:b&&i&&u?"none":b?`1px solid ${w.borderColor}`:"none",padding:b&&i&&u?"1.5px":"0",background:b&&i&&u?`linear-gradient(120deg, ${w.primaryColor}dd 0%, ${w.primaryColor}88 25%, ${w.primaryColor}00 50%, ${w.primaryColor}88 75%, ${w.primaryColor}dd 100%)`:"transparent",backgroundSize:b&&i&&u?"300% 300%":"auto",animation:b&&i&&u?`${a.current}-border-flow 3s ease-in-out infinite`:"none",filter:b&&i&&u?`drop-shadow(0 0 10px ${w.primaryColor}40)`:"none"},children:jsxRuntime.jsx("div",{className:"hsafa-content-container",style:{width:"100%",height:"100%",borderRadius:b&&T?M:"0",backgroundColor:b&&T?w.backgroundColor:"transparent",overflow:"auto",position:"relative",isolation:"isolate",contain:"layout style paint",transform:"translateZ(0)",scrollbarWidth:"thin",scrollbarColor:`${w.mutedTextColor}40 transparent`},children:e})})}),jsxRuntime.jsx("style",{children:`
|
|
299
299
|
@keyframes ${a.current}-border-flow {
|
|
300
300
|
0% { background-position: 0% 50%; }
|
|
301
301
|
50% { background-position: 100% 50%; }
|
|
302
302
|
100% { background-position: 0% 50%; }
|
|
303
303
|
}
|
|
304
|
-
`})," "]})}var
|
|
304
|
+
`})," "]})}var ir=class{constructor(){this.components=new Map;}register(t,r){this.components.set(t,r);}unregister(t){this.components.delete(t);}get(t){return this.components.get(t)}has(t){return this.components.has(t)}clear(){this.components.clear();}getRegisteredNames(){return Array.from(this.components.keys())}},Zn=new ir;exports.Button=na;exports.ContentContainer=Xn;exports.CursorController=tt;exports.FillActiveInput=Qe;exports.FloatingChatButton=Nr;exports.HsafaChat=_n;exports.HsafaProvider=Po;exports.XMarkdownRenderer=Be;exports.componentRegistry=Zn;exports.controlCursor=Ae;exports.getDomComponents=Ze;exports.guideCursor=Ae;exports.useAutoScroll=Or;exports.useChatStorage=Yt;exports.useFileUpload=qr;exports.useHsafa=ce;exports.useHsafaAgent=Vt;exports.useMessageEditor=yn;//# sourceMappingURL=index.cjs.map
|
|
305
305
|
//# sourceMappingURL=index.cjs.map
|