@hsafa/ui-sdk 0.5.7 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +166 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +166 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {jsxs,jsx,Fragment}from'react/jsx-runtime';import po,{createContext,useRef,useEffect,useState,useCallback,useMemo,useContext,Component}from'react';import {useChat}from'@ai-sdk/react';import {lastAssistantMessageIsCompleteWithToolCalls,DefaultChatTransport}from'ai';import {createRoot}from'react-dom/client';import {XMarkdown}from'@ant-design/x-markdown';import'@ant-design/x-markdown/themes/light.css';import'@ant-design/x-markdown/themes/dark.css';import {createPortal}from'react-dom';import {Plus,Pencil,History,ChevronRight,Trash2,File as File$1,Eye,X as X$1,Download}from'lucide-react';var Te={};var _r=({variant:e="primary",size:t="md",loading:n=false,disabled:r,children:o,className:l,...m})=>{let u=[Te.button,Te[e],Te[t],n&&Te.loading,l].filter(Boolean).join(" ");return jsxs("button",{className:u,disabled:r||n,...m,children:[n&&jsx("span",{className:Te.spinner}),jsx("span",{className:n?Te.hiddenText:void 0,children:o})]})};function Mn({show:e,onClick:t,resolvedColors:n,floatingButtonPosition:r}){if(!e)return null;let o={position:"fixed",bottom:typeof r.bottom=="number"?`${r.bottom}px`:r.bottom,right:r.right?typeof r.right=="number"?`${r.right}px`:r.right:void 0,top:r.top?typeof r.top=="number"?`${r.top}px`:r.top:void 0,left:r.left?typeof r.left=="number"?`${r.left}px`:r.left:void 0,zIndex:1e3};return jsx("button",{"aria-label":"Open chat",onClick:t,style:{...o,borderColor:n.borderColor,backgroundColor:n.accentColor,color:n.textColor,borderRadius:"50%",border:`1px solid ${n.borderColor}`,padding:"12px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)",transition:"all 0.2s",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:l=>{l.currentTarget.style.borderColor=n.primaryColor,l.currentTarget.style.backgroundColor=`${n.accentColor}dd`;},onMouseLeave:l=>{l.currentTarget.style.borderColor=n.borderColor,l.currentTarget.style.backgroundColor=n.accentColor;},children:jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})})}function An(e=true){let t=useRef(null),n=useRef(e);return useEffect(()=>{n.current=e;},[e]),useEffect(()=>{let r=t.current;if(!r)return;let o=new MutationObserver(()=>{n.current&&(r.scrollTop=r.scrollHeight);});return o.observe(r,{childList:true,subtree:true}),n.current&&(r.scrollTop=r.scrollHeight),()=>o.disconnect()},[]),t}function Ln(e,t){if(!e)return t;let n=e.endsWith("/")?e.slice(0,-1):e,r=t.startsWith("/")?t:`/${t}`;return `${n}${r}`}var Hn=createContext(void 0);function ko({baseUrl:e,dir:t="ltr",theme:n="dark",children:r}){let[o,l]=useState(new Map),[m,u]=useState(new Map),[C,M]=useState(new Map),[x,I]=useState(new Map),[k,h]=useState(void 0),i=useCallback((v,y)=>(l(S=>{let p=new Map(S);return p.set(String(v),y),p}),()=>{l(S=>{let p=new Map(S),B=p.get(String(v));return (!y||B===y)&&p.delete(String(v)),p});}),[]),b=useCallback((v,y)=>{l(S=>{let p=new Map(S),B=p.get(String(v));return (!y||B===y)&&p.delete(String(v)),p});},[]),d=useCallback((v,y)=>(u(S=>{let p=new Map(S);return p.set(String(v),y),p}),()=>{u(S=>{let p=new Map(S),B=p.get(String(v));return (!y||B===y)&&p.delete(String(v)),p});}),[]),c=useCallback((v,y)=>{u(S=>{let p=new Map(S),B=p.get(String(v));return (!y||B===y)&&p.delete(String(v)),p});},[]),f=useCallback((v,y)=>{M(S=>{let p=new Map(S);return y?p.set(v,true):p.delete(v),p});},[]),s=useCallback((v,y)=>{I(S=>{let p=new Map(S);return p.set(v,y),p});},[]),a=useMemo(()=>Array.from(C.values()).some(v=>v),[C]),T=useMemo(()=>Array.from(x.values()).some(v=>v),[x]),w=useMemo(()=>({baseUrl:e,dir:t,theme:n,actions:o,components:m,registerAction:i,unregisterAction:b,registerComponent:d,unregisterComponent:c,isAnyStreaming:a,setStreamingState:f,isAnyChatOpen:T,setChatOpenState:s,currentChatId:k,setCurrentChatId:h}),[e,t,n,o,m,i,b,d,c,a,f,T,s,k]);return jsx(Hn.Provider,{value:w,children:r})}function se(){let e=useContext(Hn);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 Ft=25*1024*1024;function Bn(e){let{baseUrl:t}=se(),n=e||t||"",[r,o]=useState([]),[l,m]=useState(false),u=useRef(null),C=useCallback(i=>{if(!i||Number.isNaN(i))return "0 B";let b=["B","KB","MB","GB","TB"],d=Math.min(b.length-1,Math.floor(Math.log(i)/Math.log(1024)));return `${(i/Math.pow(1024,d)).toFixed(d===0?0:1)} ${b[d]}`},[]),M=useCallback(async i=>{let b=new FormData;b.append("file",i);let d=await fetch(Ln(n,"/api/uploads"),{method:"POST",body:b});if(!d.ok){let f=await d.text().catch(()=>"");throw new Error(f||`Failed to upload ${i.name}`)}let c=await d.json();return {id:c.id,name:c.name||i.name,url:c.url,mimeType:c.mimeType||i.type||"application/octet-stream",size:typeof c.size=="number"?c.size:i.size}},[n]),x=useCallback(i=>{o(b=>b.filter(d=>d.id!==i));},[]),I=useCallback(async(i,b)=>{if(!i)return;let d=Array.isArray(i)?i:Array.from(i);b(null),m(true);let c=[];try{for(let f of d){if(f.size>Ft){b(`"${f.name}" exceeds the ${C(Ft)} limit.`);continue}try{let s=await M(f);c.push(s);}catch(s){console.error("Failed to upload attachment:",s),b(String(s?.message??`Failed to upload ${f.name}`));}}c.length&&o(f=>[...f,...c]);}finally{m(false);}},[M,C]),k=useCallback((i,b)=>{let d=[],c=(i||"").trim();c&&d.push({type:"text",text:c});for(let f of b||[]){let s=f.mimeType||"application/octet-stream";s.startsWith("image/")?d.push({type:"image",image:new URL(f.url),mediaType:s}):d.push({type:"file",data:f.url,mediaType:s,name:f.name});}return d},[]),h=useCallback(()=>{o([]);},[]);return {attachments:r,uploading:l,fileInputRef:u,formatBytes:C,handleRemoveAttachment:x,handleFileSelection:I,buildUserContent:k,clearAttachments:h,setAttachments:o,MAX_UPLOAD_SIZE:Ft}}function Dn(e,t,n,r){return console.log("\u{1F680} [SDK] createHsafaTransport called with templateParams:",r),new DefaultChatTransport({api:`${e}/api/run/${t}`,fetch:async(o,l)=>{let m=l||{},u=m?.body?JSON.parse(m.body):{},C=r&&typeof r=="object"?r:{};console.log("\u{1F680} [SDK] Before merge - body:",u),console.log("\u{1F680} [SDK] Before merge - mergedParams:",C);let M={...C,...u,chatId:n};return console.log("\u{1F680} [SDK] After merge - enhancedBody:",M),fetch(o,{...l,body:JSON.stringify(M)})}})}function So(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 Mo(e){if(e.id){let n=document.querySelector(`label[for="${e.id}"]`);if(n)return n.textContent?.trim()}let t=e.closest("label");if(t){let n=t.cloneNode(true),r=n.querySelector("input, select, textarea");return r&&r.remove(),n.textContent?.trim()}}function Bt(e){if(e.textContent&&e.textContent.trim())return e.textContent.trim().slice(0,100)}function Dt(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 Eo(e){if(e.id)return `#${e.id}`;let t=[],n=e;for(;n&&n!==document.body;){let r=n.tagName.toLowerCase();if(n.className&&typeof n.className=="string"){let l=n.className.split(" ").filter(m=>m.trim()).slice(0,2);l.length>0&&(r+="."+l.join("."));}let o=n.parentElement;if(o){let l=Array.from(o.children).filter(m=>m.tagName===n.tagName);if(l.length>1){let m=l.indexOf(n)+1;r+=`:nth-child(${m})`;}}t.unshift(r),n=o;}return t.slice(-3).join(" > ")}async function qe(e={}){try{let{includeHidden:t=!1,selector:n,what:r="content",limit:o}=e,l=document.querySelector(".hsafa-content-container");if(!l)return {ok:!1,components:[],count:0,total:0,containerFound:!1,error:"ContentContainer not found on page. Make sure you have wrapped your app with <ContentContainer>."};let m=n&&l.querySelector(n)||l,u=[],C=[];r==="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(d=>{let c=So(d);if(!c&&!t)return;let f={id:d.id||null,tag:d.tagName.toLowerCase(),className:d.className&&typeof d.className=="string"?d.className:void 0,isVisible:c,isInteractive:!0,selector:Eo(d)};d instanceof HTMLInputElement?(f.type=d.type,f.name=d.name||void 0,f.placeholder=d.placeholder||void 0,f.value=Dt(d),f.checked=d.type==="checkbox"||d.type==="radio"?d.checked:void 0,f.disabled=d.disabled,f.required=d.required):d instanceof HTMLTextAreaElement?(f.name=d.name||void 0,f.placeholder=d.placeholder||void 0,f.value=Dt(d),f.disabled=d.disabled,f.required=d.required):d instanceof HTMLSelectElement?(f.name=d.name||void 0,f.value=Dt(d),f.disabled=d.disabled,f.required=d.required,f.options=Array.from(d.options).map(s=>({value:s.value,label:s.text,selected:s.selected,disabled:s.disabled}))):d instanceof HTMLButtonElement?(f.type=d.type,f.disabled=d.disabled,f.text=Bt(d)):d instanceof HTMLAnchorElement?(f.href=d.href,f.text=Bt(d)):d instanceof HTMLImageElement?(f.text=d.alt||void 0,f.label=d.alt||f.label):f.text=Bt(d),f.label=Mo(d),f.role=d.getAttribute("role")||void 0,f.ariaLabel=d.getAttribute("aria-label")||void 0,u.push(f);});let x=d=>d.isVisible?r==="inputs"?d.tag==="input"||d.tag==="textarea"||d.tag==="select"||d.role==="textbox"?3:d.tag==="button"||d.tag==="a"?2:1:["header","nav","main","footer"].includes(d.tag)?5:["section","article","aside"].includes(d.tag)||["h1","h2","h3"].includes(d.tag)?4:["h4","h5","h6"].includes(d.tag)?3:d.tag==="form"?4:d.tag==="label"?3:d.tag==="input"||d.tag==="textarea"||d.tag==="select"?4:d.tag==="p"||d.tag==="img"||d.tag==="button"||d.tag==="a"?3:1:0;u.sort((d,c)=>x(c)-x(d));let I=u.length,h=Math.max(1,Math.min(200,typeof o=="number"?Math.floor(o):r==="inputs"?100:150)),i=I>h,b=i?u.slice(0,h):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=qe);async function Ie(e,t={}){if(typeof window>"u")return {ok:false,steps:[{ok:false,action:"none",targetKind:"position",durationMs:0,error:"guideCursor only works in browser environment"}]};let n=window.__cursorGuide;if(!n)return {ok:false,steps:[{ok:false,action:"none",targetKind:"position",durationMs:0,error:"CursorController not initialized. Make sure to mount <CursorController /> component."}]};try{return await n(e,t)}catch(r){return {ok:false,steps:[{ok:false,action:t.action||"none",targetKind:"position",durationMs:0,error:r?.message||String(r)}]}}}typeof window<"u"&&(window.guideCursor=Ie);function Pn(e){return !!e&&e.nodeType===1}function le(e,t){e.dispatchEvent(new Event(t,{bubbles:true}));}function $n(e,t){let n=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(e),"value")?.set;n?n.call(e,t):e.value=t,le(e,"input");}function Ro(e,t){e.checked!==t&&e.click();}function Ao(e,t){if(typeof t=="object"&&t&&"index"in t&&typeof t.index=="number")e.selectedIndex=Math.max(0,Math.min(e.options.length-1,t.index));else if(typeof t=="object"&&t&&"label"in t&&typeof t.label=="string"){let n=Array.from(e.options).findIndex(r=>r.text===t.label);e.selectedIndex=n>=0?n:0;}else e.value=String(t);le(e,"input"),le(e,"change");}function Lo(e,t){let n=new Set(t.map(String));Array.from(e.options).forEach(r=>{r.selected=n.has(r.value)||n.has(r.text);}),le(e,"input"),le(e,"change");}function Ho(e){return e?e instanceof Date?e.toISOString().slice(0,10):String(e):""}function Fo(e,t){let n=Array.isArray(t)?t:[t],r=new DataTransfer;for(let o of n)r.items.add(o);Object.defineProperty(e,"files",{value:r.files,configurable:true}),le(e,"input"),le(e,"change");}async function Ke(e,t={}){let n=document.activeElement||null;if(n&&Pn(n)){let r=n.closest('[contenteditable="true"], [contenteditable=""]');r&&(n=r);}if(!n||n===document.body)return {ok:false,filled:[{key:"active",status:"skipped",message:"No active input element"}],errors:["No active input element"]};try{let r=n.tagName.toLowerCase();if(r==="input"){let o=n,l=(o.type||"text").toLowerCase();if(l==="checkbox")Ro(o,!!e);else if(l==="radio"){let m=o.name;if(m&&e!=null&&String(o.value)!==String(e)){let u=document.querySelector(`input[type="radio"][name="${CSS.escape(m)}"][value="${CSS.escape(String(e))}"]`);u?u.click():o.click();}else o.click();}else if(l==="file")if(e instanceof File||Array.isArray(e)&&e.every(m=>m instanceof File))Fo(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 m=l==="date"?Ho(e):String(e??"");$n(o,m),le(o,"change");}return {ok:!0,filled:[{key:"active",status:"ok"}]}}if(r==="textarea"){let o=n,l=String(e??"");return $n(o,l),le(o,"change"),{ok:!0,filled:[{key:"active",status:"ok"}]}}if(r==="select"){let o=n;return o.multiple?Lo(o,Array.isArray(e)?e:[e]):Ao(o,e),{ok:!0,filled:[{key:"active",status:"ok"}]}}if(Pn(n)&&n.isContentEditable){let o=n;return o.focus(),o.textContent=String(e??""),le(o,"input"),le(o,"change"),o.blur?.(),{ok:!0,filled:[{key:"active",status:"ok"}]}}return {ok:!1,filled:[{key:"active",status:"skipped",message:`Unsupported active element: ${r}`}],errors:[`Unsupported active element: ${r}`]}}catch(r){return {ok:false,filled:[{key:"active",status:"error",message:r?.message??String(r)}],errors:[r?.message??String(r)]}}}typeof window<"u"&&(window.FillActiveInput=Ke);var Ve=null,it={},Nn=false,He=null,lt=false;function Pt(e){e.classList.add("visible");}function _n(){lt=true,He!=null&&(clearTimeout(He),He=null);}function Do(e,t=1500){lt||(He!=null&&clearTimeout(He),He=window.setTimeout(()=>{lt||e.classList.remove("visible");},t));}function Po(e,t=1200){lt=false,Do(e,t);}function $o(e){let t=[],n=e?.parentElement;for(;n;){let r=getComputedStyle(n),o=r.overflow+r.overflowY+r.overflowX;/(auto|scroll)/.test(o)&&t.push(n),n=n.parentElement;}return t}async function zo(e,t=1500,n=160){let r=performance.now(),o=e?$o(e):[],l=()=>{let x=[window.scrollX||document.documentElement.scrollLeft||0,window.scrollY||document.documentElement.scrollTop||0];return o.forEach(I=>{x.push(I.scrollLeft,I.scrollTop);}),x},m=()=>{if(!e)return {x:0,y:0};let x=e.getBoundingClientRect();return {x:x.left,y:x.top}},u=l(),C=m(),M=performance.now();return new Promise(x=>{function I(k){let h=l(),i=m(),b=false;for(let d=0;d<h.length;d++)if(h[d]!==u[d]){b=true;break}if(!b&&e&&(i.x!==C.x||i.y!==C.y)&&(b=true),b&&(u=h,C=i,M=k),k-M>=n||k-r>=t){x();return}requestAnimationFrame(I);}requestAnimationFrame(I);})}var No='<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>',Wo='<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 Uo(){if(!it.arrow)try{it.arrow=No,it.pointer=Wo;}catch(e){console.warn("Failed to set cursor SVGs",e);}return it}function Wn({arrowSvg:e,pointerSvg:t}){return jsxs(Fragment,{children:[e&&jsx("div",{className:"arrow",dangerouslySetInnerHTML:{__html:e}}),t&&jsx("div",{className:"pointer",dangerouslySetInnerHTML:{__html:t}})]})}async function Oo(){let e="demo-fake-cursor",t=document.getElementById(e),n=await Uo();if(!Nn){let r="cursor-controller-styles";if(!document.getElementById(r)){let o=document.createElement("style");o.id=r,o.textContent=`
|
|
1
|
+
import {jsxs,jsx,Fragment}from'react/jsx-runtime';import pn,{createContext,useRef,useEffect,useState,useCallback,useMemo,useContext,Component}from'react';import {useChat}from'@ai-sdk/react';import {lastAssistantMessageIsCompleteWithToolCalls,DefaultChatTransport}from'ai';import {createRoot}from'react-dom/client';import {XMarkdown}from'@ant-design/x-markdown';import'@ant-design/x-markdown/themes/light.css';import'@ant-design/x-markdown/themes/dark.css';import {createPortal}from'react-dom';import {Plus,Pencil,History,ChevronRight,Trash2,File as File$1,Eye,X as X$1,Download}from'lucide-react';var Te={};var qo=({variant:e="primary",size:t="md",loading:r=false,disabled:o,children:n,className:s,...m})=>{let u=[Te.button,Te[e],Te[t],r&&Te.loading,s].filter(Boolean).join(" ");return jsxs("button",{className:u,disabled:o||r,...m,children:[r&&jsx("span",{className:Te.spinner}),jsx("span",{className:r?Te.hiddenText:void 0,children:n})]})};function Mr({show:e,onClick:t,resolvedColors:r,floatingButtonPosition:o}){if(!e)return null;let n={position:"fixed",bottom:typeof o.bottom=="number"?`${o.bottom}px`:o.bottom,right:o.right?typeof o.right=="number"?`${o.right}px`:o.right:void 0,top:o.top?typeof o.top=="number"?`${o.top}px`:o.top:void 0,left:o.left?typeof o.left=="number"?`${o.left}px`:o.left:void 0,zIndex:1e3};return jsx("button",{"aria-label":"Open chat",onClick:t,style:{...n,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:jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})})}function Ar(e=true){let t=useRef(null),r=useRef(e);return useEffect(()=>{r.current=e;},[e]),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=createContext(void 0);function kn({baseUrl:e,dir:t="ltr",theme:r="dark",children:o}){let[n,s]=useState(new Map),[m,u]=useState(new Map),[C,I]=useState(new Map),[x,S]=useState(new Map),[k,f]=useState(void 0),i=useCallback((v,y)=>(s(M=>{let p=new Map(M);return p.set(String(v),y),p}),()=>{s(M=>{let p=new Map(M),B=p.get(String(v));return (!y||B===y)&&p.delete(String(v)),p});}),[]),b=useCallback((v,y)=>{s(M=>{let p=new Map(M),B=p.get(String(v));return (!y||B===y)&&p.delete(String(v)),p});},[]),c=useCallback((v,y)=>(u(M=>{let p=new Map(M);return p.set(String(v),y),p}),()=>{u(M=>{let p=new Map(M),B=p.get(String(v));return (!y||B===y)&&p.delete(String(v)),p});}),[]),d=useCallback((v,y)=>{u(M=>{let p=new Map(M),B=p.get(String(v));return (!y||B===y)&&p.delete(String(v)),p});},[]),h=useCallback((v,y)=>{I(M=>{let p=new Map(M);return y?p.set(v,true):p.delete(v),p});},[]),l=useCallback((v,y)=>{S(M=>{let p=new Map(M);return p.set(v,y),p});},[]),a=useMemo(()=>Array.from(C.values()).some(v=>v),[C]),T=useMemo(()=>Array.from(x.values()).some(v=>v),[x]),w=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 jsx(Hr.Provider,{value:w,children:o})}function se(){let e=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 Ft=25*1024*1024;function Br(e){let{baseUrl:t}=se(),r=e||t||"",[o,n]=useState([]),[s,m]=useState(false),u=useRef(null),C=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]}`},[]),I=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=useCallback(i=>{n(b=>b.filter(c=>c.id!==i));},[]),S=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>Ft){b(`"${h.name}" exceeds the ${C(Ft)} limit.`);continue}try{let l=await I(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);}},[I,C]),k=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=useCallback(()=>{n([]);},[]);return {attachments:o,uploading:s,fileInputRef:u,formatBytes:C,handleRemoveAttachment:x,handleFileSelection:S,buildUserContent:k,clearAttachments:f,setAttachments:n,MAX_UPLOAD_SIZE:Ft}}function Dr(e,t,r,o){return console.log("\u{1F680} [SDK] createHsafaTransport called with templateParams:",o),new 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 I={...C,...u,chatId:r};return console.log("\u{1F680} [SDK] After merge - enhancedBody:",I),fetch(n,{...s,body:JSON.stringify(I)})}})}function Sn(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 Mn(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 Bt(e){if(e.textContent&&e.textContent.trim())return e.textContent.trim().slice(0,100)}function Dt(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 En(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 qe(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=Sn(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:En(c)};c instanceof HTMLInputElement?(h.type=c.type,h.name=c.name||void 0,h.placeholder=c.placeholder||void 0,h.value=Dt(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=Dt(c),h.disabled=c.disabled,h.required=c.required):c instanceof HTMLSelectElement?(h.name=c.name||void 0,h.value=Dt(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=Bt(c)):c instanceof HTMLAnchorElement?(h.href=c.href,h.text=Bt(c)):c instanceof HTMLImageElement?(h.text=c.alt||void 0,h.label=c.alt||h.label):h.text=Bt(c),h.label=Mn(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 S=u.length,f=Math.max(1,Math.min(200,typeof n=="number"?Math.floor(n):o==="inputs"?100:150)),i=S>f,b=i?u.slice(0,f):u;return {ok:!0,components:b,count:b.length,total:S,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=qe);async function Ie(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=Ie);function Pr(e){return !!e&&e.nodeType===1}function le(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,le(e,"input");}function Rn(e,t){e.checked!==t&&e.click();}function An(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);le(e,"input"),le(e,"change");}function Ln(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);}),le(e,"input"),le(e,"change");}function Hn(e){return e?e instanceof Date?e.toISOString().slice(0,10):String(e):""}function Fn(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}),le(e,"input"),le(e,"change");}async function Ke(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")Rn(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))Fn(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"?Hn(e):String(e??"");zr(n,m),le(n,"change");}return {ok:!0,filled:[{key:"active",status:"ok"}]}}if(o==="textarea"){let n=r,s=String(e??"");return zr(n,s),le(n,"change"),{ok:!0,filled:[{key:"active",status:"ok"}]}}if(o==="select"){let n=r;return n.multiple?Ln(n,Array.isArray(e)?e:[e]):An(n,e),{ok:!0,filled:[{key:"active",status:"ok"}]}}if(Pr(r)&&r.isContentEditable){let n=r;return n.focus(),n.textContent=String(e??""),le(n,"input"),le(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=Ke);var Ve=null,it={},Nr=false,He=null,lt=false;function Pt(e){e.classList.add("visible");}function _r(){lt=true,He!=null&&(clearTimeout(He),He=null);}function Dn(e,t=1500){lt||(He!=null&&clearTimeout(He),He=window.setTimeout(()=>{lt||e.classList.remove("visible");},t));}function Pn(e,t=1200){lt=false,Dn(e,t);}function zn(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 $n(e,t=1500,r=160){let o=performance.now(),n=e?zn(e):[],s=()=>{let x=[window.scrollX||document.documentElement.scrollLeft||0,window.scrollY||document.documentElement.scrollTop||0];return n.forEach(S=>{x.push(S.scrollLeft,S.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(),I=performance.now();return new Promise(x=>{function S(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,I=k),k-I>=r||k-o>=t){x();return}requestAnimationFrame(S);}requestAnimationFrame(S);})}var Nn='<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>',Wn='<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 Un(){if(!it.arrow)try{it.arrow=Nn,it.pointer=Wn;}catch(e){console.warn("Failed to set cursor SVGs",e);}return it}function Wr({arrowSvg:e,pointerSvg:t}){return jsxs(Fragment,{children:[e&&jsx("div",{className:"arrow",dangerouslySetInnerHTML:{__html:e}}),t&&jsx("div",{className:"pointer",dangerouslySetInnerHTML:{__html:t}})]})}async function On(){let e="demo-fake-cursor",t=document.getElementById(e),r=await Un();if(!Nr){let o="cursor-controller-styles";if(!document.getElementById(o)){let n=document.createElement("style");n.id=o,n.textContent=`
|
|
2
2
|
.fake-cursor { pointer-events: none; opacity: 0; transition: opacity 0.2s ease; z-index: 2147483647; }
|
|
3
3
|
.fake-cursor.visible { opacity: 1; }
|
|
4
4
|
.fake-cursor .arrow { display: none; }
|
|
@@ -8,12 +8,170 @@ import {jsxs,jsx,Fragment}from'react/jsx-runtime';import po,{createContext,useRe
|
|
|
8
8
|
.fake-cursor.as-pointer .arrow { display: none; }
|
|
9
9
|
.fake-cursor.as-pointer .pointer { display: block; }
|
|
10
10
|
.fake-cursor.pressing .pointer svg path { filter: brightness(0.9); }
|
|
11
|
-
`,document.head.appendChild(o);}Nn=true;}return t?(t.classList.add("as-arrow"),Ve||(Ve=createRoot(t),Ve.render(jsx(Wn,{arrowSvg:n.arrow,pointerSvg:n.pointer})))):(t=document.createElement("div"),t.id=e,t.className="fake-cursor as-arrow",t.style.position="fixed",t.style.left="20px",t.style.top="20px",document.body.appendChild(t),Ve=createRoot(t),Ve.render(jsx(Wn,{arrowSvg:n.arrow,pointerSvg:n.pointer}))),t}function Fe(e,t,n){return Math.max(t,Math.min(n,e))}function Go(e){return e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2}function qn(e){if(!e)return null;let t=document.createElement("canvas").getContext("2d");if(!t)return null;t.fillStyle="#000",t.fillStyle=e;let r=t.fillStyle.match(/rgba?\(([^)]+)\)/i);if(!r)return null;let o=r[1].split(/\s*,\s*/).map(Number),[l,m,u,C=1]=o;return {r:l,g:m,b:u,a:C}}function jo({r:e,g:t,b:n}){let r=[e,t,n].map(o=>o/255).map(o=>o<=.03928?o/12.92:Math.pow((o+.055)/1.055,2.4));return .2126*r[0]+.7152*r[1]+.0722*r[2]}function _o(e){let t=e?qn(e):null;return !t||t.a===0?false:jo(t)<.5}function qo(e,t){let n=document.elementFromPoint(e,t),r=new Set;for(;n&&!r.has(n);){r.add(n);let m=getComputedStyle(n).backgroundColor,u=qn(m);if(u&&u.a>0)return m;n=n.parentElement;}return getComputedStyle(document.body).backgroundColor||"rgb(255,255,255)"}function $t(e,t,n){let r=qo(t,n),o=_o(r),l=o?"#ffffff":"#000000";e.querySelectorAll("svg path").forEach(u=>{u.style.fill="white",u.style.stroke=l,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 st(e,t,n,r,o="ease-in-out",l="curve",m=.25,u="auto",C){_n(),Pt(e);let M=performance.now(),x=o==="linear"?h=>h:Go,I=l!=="straight",k={x:0,y:0};if(I){let h=n.x-t.x,i=n.y-t.y,b=Math.hypot(h,i)||1,d=(t.x+n.x)/2,c=(t.y+n.y)/2,f=-i/b,s=h/b,a=1;u==="left"?a=-1:u==="right"?a=1:a=Math.random()<.5?-1:1;let T=Fe(m,0,1)*b;k={x:d+a*f*T,y:c+a*s*T};}return new Promise(h=>{function i(b){let d=Fe((b-M)/r,0,1),c=x(d),f,s;if(I){let y=1-c;f=y*y*t.x+2*y*c*k.x+c*c*n.x,s=y*y*t.y+2*y*c*k.y+c*c*n.y;}else f=t.x+(n.x-t.x)*c,s=t.y+(n.y-t.y)*c;let T=.35*(1-c),w=Math.sin(b*.02)*T,v=Math.cos(b*.018)*T;e.style.left=`${f+w}px`,e.style.top=`${s+v}px`,$t(e,f+w,s+v),C&&C({x:f+w,y:s+v,t:d,now:b}),d<1?requestAnimationFrame(i):h();}requestAnimationFrame(i);})}function Un(e,t){return {x:e.x+(t?.x??0),y:e.y+(t?.y??0)}}function pe(e,t,n,r){let o={bubbles:true,cancelable:true,view:window,clientX:n.x,clientY:n.y,...r};try{let l=t==="pointerdown"||t==="mousedown",m=t==="pointerup"||t==="mouseup",u={button:0,buttons:l?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 l=new MouseEvent(t,o);e.dispatchEvent(l);}}function Kn(e){return e&&typeof e=="object"&&e.nodeType===1}function Ko(e){if(!e)return document;if(Kn(e))return e;if(typeof e=="string"){let t=document.getElementById(e);if(t)return t;let n=document.querySelector(e);if(n)return n}return document}function On(e){if(Kn(e))return {kind:"element",element:e};if(typeof e=="string"){let t=document.getElementById(e);if(t)return {kind:"element",element:t};let n=document.querySelector(e);return {kind:n?"element":"position",element:n??null}}if(typeof e=="object"&&"position"in e)return {kind:"position",point:e.position};if(typeof e=="object"&&"selector"in e){let n=Ko(e.within??null).querySelectorAll(e.selector),r=Math.max(0,Math.min(n.length-1,e.nth??0)),o=n[r]??null;return {kind:o?"element":"position",element:o}}return {kind:"position",point:{x:0,y:0}}}function Gn(e,t){let n=e.getBoundingClientRect();if(!t||t==="center")return {x:n.left+n.width/2,y:n.top+n.height/2};if(t==="top-left")return {x:n.left,y:n.top};if(t==="bottom-right")return {x:n.right,y:n.bottom};let r=Fe(t.x,0,1),o=Fe(t.y,0,1);return {x:n.left+n.width*r,y:n.top+n.height*o}}function jn(e){return {x:Fe(e.x,0,window.innerWidth),y:Fe(e.y,0,window.innerHeight)}}function Vo(){return useEffect(()=>(window.__cursorGuide=async(e,t={})=>{let n=Array.isArray(e)?e:[{target:e,action:t.action??"none",options:t}],r=[],o=await Oo();o.classList.add("visible","as-arrow"),o.classList.remove("as-pointer","pressing"),Pt(o),_n();let l=parseFloat(o.style.left||"20")||20,m=parseFloat(o.style.top||"20")||20;$t(o,l,m);for(let u of n){let{durationMs:C=800,easing:M="ease-in-out",offset:x,highlight:I=true,path:k="curve",curveStrength:h=.25,curveDirection:i="auto",anchor:b,cursorHotspot:d,dragTo:c}=u.options??{},f=u.action??u.options?.action??"none",s=performance.now(),a=On(u.target),T=null,w=null;if(a.kind==="element"&&a.element?(w=a.element,o.classList.remove("visible"),w.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),await zo(w,1500,180),Pt(o),T=Gn(w,b)):a.kind==="position"&&a.point&&(T=a.point),!T){r.push({ok:false,action:f,targetKind:a.kind,durationMs:Math.round(performance.now()-s),error:"Target not found"});continue}let v={x:parseFloat(o.style.left||"20")||20,y:parseFloat(o.style.top||"20")||20},y=jn(Un(T,x));await st(o,v,y,C,M,k,h,i);let S=y.x-v.x,p=y.y-v.y,B=Math.hypot(S,p)||1,W=S/B,j=p/B,ne=Math.min(6,Math.max(3,B*.02)),ye={x:y.x+W*ne,y:y.y+j*ne};await st(o,y,ye,Math.max(70,C*.1),"ease-out","straight",0,"right"),await st(o,ye,y,120,"ease-out","straight",0,"left"),I&&(o.classList?.add("click"),setTimeout(()=>o.classList?.remove("click"),180));let me=null;try{if(f==="click"){o.classList.remove("as-arrow"),o.classList.add("as-pointer","pressing");let _={x:d?.x??0,y:d?.y??0},U={x:y.x+_.x,y:y.y+_.y};o.style.left=`${U.x}px`,o.style.top=`${U.y}px`,$t(o,U.x,U.y);let q=w??document.elementFromPoint(U.x,U.y)??document.body;pe(q,"pointerdown",U),pe(q,"mousedown",U),await new Promise(O=>setTimeout(O,90)),o.classList.remove("pressing"),pe(q,"mouseup",U),pe(q,"click",U),setTimeout(()=>{o.classList.remove("as-pointer"),o.classList.add("as-arrow");},140),q instanceof HTMLElement&&q.focus?.(),me=q?.id??null;}else if(f==="drag"){if(!c)throw new Error("dragTo is required for action 'drag'");let _=On(c),U=null;if(_.kind==="element"&&_.element&&(U=Gn(_.element,b)),_.kind==="position"&&_.point&&(U=_.point),!U)throw new Error("dragTo target not found");let q=jn(Un(U,x)),O={x:y.x,y:y.y},De=w??document.elementFromPoint(O.x,O.y)??document.body;o.classList.remove("as-arrow"),o.classList.add("as-pointer","pressing"),pe(De,"pointerdown",O),pe(De,"mousedown",O),await st(o,O,q,Math.max(200,C),M,k,h,i,({x:oe,y:Z})=>{let ge=document.elementFromPoint(oe,Z)??document.body,Pe={x:oe,y:Z};pe(ge,"pointermove",Pe),pe(ge,"mousemove",Pe);});let J=document.elementFromPoint(q.x,q.y)??document.body;o.classList.remove("pressing"),pe(J,"pointerup",q),pe(J,"mouseup",q);}r.push({ok:!0,action:f,targetKind:a.kind,durationMs:Math.round(performance.now()-s),clickedElementId:me});}catch(_){r.push({ok:false,action:f,targetKind:a.kind,durationMs:Math.round(performance.now()-s),error:_?.message??String(_)});}}return Po(o,2e3),{ok:r.every(u=>u.ok),steps:r}},()=>{try{delete window.__cursorGuide;}catch{window.__cursorGuide=void 0;}}),[]),null}var Xe=Vo;function Vn(){return {getDomComponents:{tool:async({includeHidden:e,selector:t})=>await qe({includeHidden:e,selector:t}),executeEachToken:false},controlCursor:{tool:async({target:e,action:t,anchor:n,durationMs:r,dragTo:o})=>{let l=await Ie(e,{action:t,anchor:n,durationMs:r,dragTo:o});if(l&&l.ok){let m=Array.isArray(l.steps)&&l.steps.length?l.steps[l.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:l}}return {success:false,message:"Cursor action failed",details:l}},executeEachToken:false},fillActiveInput:{tool:async({value:e})=>{let t=await Ke(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 Ye({content:e,theme:t="dark",streaming:n=false}){return jsx(XMarkdown,{content:e,className:t==="dark"?"x-markdown-dark":"x-markdown-light",streaming:{hasNextChunk:n,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"}})}function Qo({input:e}){return jsx("div",{style:{fontSize:"14px",lineHeight:"1.6",width:"100%"},children:jsx(Ye,{content:e?.text||"",theme:"dark"})})}function Yn(){return {plainText:Qo}}function Jn(e,t,n,r,o,l){let m=n.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),n.set(t,m);}let u=e?.title||"Provide input",C=e?.description||"",M=e?.submitLabel||"Submit",x=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=r.get(t)||{submitted:false,skipped:false,values:void 0};m.innerHTML="";let h=document.createElement("form");h.style.margin="12px 0",h.style.padding="14px",h.style.border="1px solid var(--hsafa-border, #2A2C33)",h.style.borderRadius="12px",h.style.background="var(--hsafa-card, #121318)",h.style.color="var(--hsafa-text, #EDEEF0)",h.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,h.appendChild(i),C){let a=document.createElement("div");a.style.fontSize="12px",a.style.opacity="0.8",a.style.marginBottom="10px",a.textContent=C,h.appendChild(a);}I.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(B=>{let W=document.createElement("option");W.value=String(B.value),W.text=String(B.label??B.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 S=k.values&&Object.prototype.hasOwnProperty.call(k.values,y)?k.values[y]:void 0;typeof S<"u"&&(w.type==="checkbox"?w.checked=!!S:w.value=String(S)),(k.submitted||k.skipped)&&(w.setAttribute("disabled","true"),w.style.opacity="0.7"),T.appendChild(w),h.appendChild(T);});let b=String(M).trim(),d=String(x).trim(),c=!!(b||d),f=null,s=null;if(c){let a=document.createElement("div");a.style.display="flex",a.style.gap="8px",a.style.marginTop="10px",f=document.createElement("button"),f.type="submit",f.textContent=b||"Submit",f.style.padding="6px 10px",f.style.borderRadius="8px",f.style.background="var(--hsafa-button-bg, var(--hsafa-primary, #2563eb))",f.style.color="#000000",s=document.createElement("button"),s.type="button",s.textContent=d||"Skip",s.style.padding="6px 10px",s.style.borderRadius="8px",s.style.background="transparent",s.style.border="1px solid var(--hsafa-border, #2A2C33)",s.style.color="inherit",a.appendChild(f),a.appendChild(s),h.appendChild(a);}if(h.onsubmit=a=>{a.preventDefault();let T={};h.querySelectorAll("[data-field-id]").forEach(w=>{let v=w.dataset.fieldId||"value";w.type==="checkbox"?T[v]=w.checked:T[v]=w.value??"";}),r.set(t,{submitted:true,skipped:false,values:T}),o({tool:"requestInput",toolCallId:t,output:{success:true,submitted:true,values:T}}),h.querySelectorAll("[data-field-id]").forEach(w=>{w.disabled=true,w.style.opacity="0.7";}),f&&(f.textContent=`${b||"Submit"} \u2713`,f.style.opacity="0.8",f.disabled=true),s&&(s.disabled=true);},s&&(s.onclick=()=>{r.set(t,{submitted:false,skipped:true,values:void 0}),o({tool:"requestInput",toolCallId:t,output:{success:true,submitted:false,skipped:true}}),h.querySelectorAll("[data-field-id]").forEach(a=>{a.disabled=true,a.style.opacity="0.7";}),s&&(s.textContent=`${d||"Skip"} \u2713`,s.style.opacity="0.8",s.disabled=true),f&&(f.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),h.appendChild(a);try{f&&(f.disabled=!0,f.style.opacity="0.8",k.submitted&&(f.textContent=`${b||"Submit"} \u2713`)),s&&(s.disabled=!0,s.style.opacity="0.8",k.skipped&&(s.textContent=`${d||"Skip"} \u2713`));}catch{}}m.appendChild(h);}function Zn(e,t,n){let r=useRef(new Map),o=useRef(new Map),l=useRef(t),m=useRef(n);l.current=t,m.current=n,useEffect(()=>{e.forEach(u=>{u.role==="assistant"&&u.parts?.forEach(C=>{if(!C.toolCallId)return;let M=C.toolName;if(!M&&C.type?.startsWith("tool-")&&(M=C.type.replace(/^tool-/,"")),!M)return;let x=l.current[M];if(x&&typeof x=="object"&&x.executeEachToken&&x.tool){let I=C.input||C.args||{},k=JSON.stringify(I),h=r.current.get(C.toolCallId);if(k!==h&&k!=="{}"){r.current.set(C.toolCallId,k);try{if(M==="requestInput")m.current(I,C.toolCallId);else {let b=(o.current.get(C.toolCallId)||0)+1;o.current.set(C.toolCallId,b),b>1&&x.tool({...I,toolCallNumber:b-1});}}catch{}}}});});},[e]);}function Nt(e){let{agentId:t,baseUrl:n="",tools:r={},uiComponents:o={},onStart:l,onFinish:m,onError:u,initialMessages:C=[],onMessagesChange:M,controlledChatId:x,onChatIdChange:I,templateParams:k}=e,{baseUrl:h,setCurrentChatId:i}=se(),b=n&&n.length>0?n:h||"",[d,c]=useState(""),[f,s]=useState(()=>`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`),a=x??f,T=useCallback(E=>{x===void 0&&s(E),I&&I(E);},[x,I]);useEffect(()=>{try{i(a);}catch{}return ()=>{try{i(void 0);}catch{}}},[a,i]);let w=useMemo(()=>Dn(b,t,a,k),[b,t,a,k]),v=useCallback(E=>{console.log("Message finished:",E);let L=E?.message?.id;if(!L&&Array.isArray(E?.messages))for(let G=E.messages.length-1;G>=0;G--){let $=E.messages[G];if($&&$.role==="assistant"&&$.id){L=$.id;break}}m?.({...E,chatId:a,assistantMessageId:L});},[m,a]),y=useCallback(E=>{console.error("Chat error:",E),u?.(E);},[u]),S=useMemo(()=>Vn(),[]),p=useMemo(()=>({...S,...r}),[S,r]),B=useMemo(()=>Yn(),[]),W=useMemo(()=>({...B,...o}),[B,o]),j=useRef(new Map),ne=useRef(new Map),ye=useCallback(()=>{try{j.current.forEach(E=>{try{E.remove();}catch{}}),j.current.clear(),ne.current.clear();}catch{}},[]),me=useCallback((E,L)=>{Jn(E,L,j.current,ne.current,G=>_.current.addToolResult(G));},[]),_=useRef(null),U=useRef(new Set),q=useCallback((E,L,G)=>{console.error(`UI Error [${L}]:`,G),_.current&&U.current.has(E)&&(U.current.delete(E),_.current.addToolResult({tool:L,toolCallId:E,state:"output-error",errorText:G?.message||String(G)}));},[]),O=useCallback((E,L)=>{_.current&&U.current.has(E)&&(U.current.delete(E),_.current.addToolResult({tool:L,toolCallId:E,output:{status:"ok",rendered:true,component:L,logs:[]}}));},[]),De=useCallback(E=>{let L=p[E];return L?typeof L=="object"&&"tool"in L?L.tool:typeof L=="function"?L:null:null},[p]),J=useChat({transport:w,onFinish:v,onError:y,experimental_throttle:10,sendAutomaticallyWhen:lastAssistantMessageIsCompleteWithToolCalls,async onToolCall({toolCall:E}){let L=De(E.toolName);if(E.toolName==="requestInput"){try{me(E.input,E.toolCallId);}catch(te){console.error("requestInput render error",te);}return}let G=E.toolName==="ui";E?.input;let ee=W&&E.toolName in W;if(G||ee){U.current.add(E.toolCallId);return}if(L)try{let te=await L(E.input);J.addToolResult({tool:E.toolName,toolCallId:E.toolCallId,output:te});}catch(te){J.addToolResult({tool:E.toolName,toolCallId:E.toolCallId,state:"output-error",errorText:te?.message||String(te)});}}}),{messages:oe,sendMessage:Z,status:ge,stop:Pe,error:Zt}=J;_.current=J,Zn(oe,p,me),useEffect(()=>{try{let E=new Set,L=[];if(oe.forEach(G=>{G.role==="assistant"&&(G.parts||[]).forEach($=>{if(($?.toolName||(typeof $?.type=="string"&&$.type.startsWith("tool-")?String($.type.replace(/^tool-/,"")):void 0))!=="requestInput")return;let te=$?.toolCallId||"";if(!te)return;E.add(te);let K=$?.output;if(K&&(K.submitted||K.skipped||K.values)){let $e={submitted:!!K.submitted,skipped:!!K.skipped,values:K.values||void 0};ne.current.set(te,$e);}let tt=$?.input||$?.args||{};L.push({input:tt,toolCallId:te});});}),j.current.forEach((G,$)=>{if(!E.has($)){let ee=j.current.get($);try{ee?.remove();}catch{}j.current.delete($),ne.current.delete($);}}),L.length>0){let G=requestAnimationFrame(()=>{L.forEach(({input:$,toolCallId:ee})=>{try{me($,ee);}catch{}});});return ()=>cancelAnimationFrame(G)}}catch{}},[oe,me]),useEffect(()=>{C&&C.length>0&&oe.length===0&&console.log("Initial messages:",C);},[C,oe.length]);let A=ge==="submitted"||ge==="streaming",P=useCallback(()=>{M&&M(oe,a);},[M,oe,a]),kt=useCallback(async E=>{let L=E?.text!==void 0?E.text:d,G=E?.files||[],$=L.trim();if(!(!$&&G.length===0)&&!A){E?.text===void 0&&c("");try{if(l){let ee={role:"user",content:$,createdAt:Date.now(),chatId:a};l(ee);}await Z({text:$,files:G});}catch(ee){throw console.error("Failed to send message:",ee),ee}}},[d,A,Z,l,a]),ve=useCallback(()=>{if(A)return;ye(),c("");try{J?.setMessages?.([]);}catch{}let E=`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`;T(E);},[A,J,ye,T]),fe=useCallback(E=>{try{J?.setMessages?.(E);}catch{}},[J]);return {input:d,setInput:c,messages:oe,isLoading:A,status:ge,error:Zt,sendMessage:kt,stop:Pe,newChat:ve,setMessages:fe,notifyMessagesChange:P,chatApi:J,chatId:a,setChatId:T,tools:p,uiComponents:W,formHostRef:j,formStateRef:ne,cleanupForms:ye,onUISuccess:O,onUIError:q}}function pt(e){let t=`hsafaChat_${e}`,n=`${t}.chats`,r=s=>`${t}.chat.${s}`,o=`${t}.currentChatId`,l=`${t}.showChat`,m=()=>{try{let s=localStorage.getItem(n);return s?JSON.parse(s):[]}catch{return []}},u=s=>{try{localStorage.setItem(n,JSON.stringify(s));}catch{}},C=s=>{try{let a=localStorage.getItem(r(s));return a?JSON.parse(a):null}catch{return null}},M=s=>{try{localStorage.setItem(r(s.id),JSON.stringify(s));}catch{}},x=s=>{let a=m(),T=a.findIndex(w=>w.id===s.id);T>=0?a[T]=s:a.unshift(s),u(a);},I=s=>{let T=m().filter(w=>w.id!==s);u(T);},k=s=>{try{localStorage.removeItem(r(s));}catch{}};return {loadChatsIndex:m,saveChatsIndex:u,loadChat:C,saveChat:M,upsertChatMeta:x,deleteChatMeta:I,deleteChatData:k,deleteChat:s=>{k(s),I(s);},loadShowChatPreference:s=>{try{let a=localStorage.getItem(l);return a!==null?a==="true":s}catch{return s}},saveShowChatPreference:s=>{try{localStorage.setItem(l,String(s));}catch{}},loadCurrentChatId:()=>{try{return localStorage.getItem(o)}catch{return null}},saveCurrentChatId:s=>{try{localStorage.setItem(o,s);}catch{}},removeCurrentChatId:()=>{try{localStorage.removeItem(o);}catch{}}}}function Ut(e){let{agentId:t,chatId:n,messages:r,isLoading:o=false,autoSave:l=true,autoRestore:m=true}=e,u=useMemo(()=>pt(t),[t]),[C,M]=useState([]),[x,I]=useState(null),k=useRef(false),h=useRef(false),i=useCallback(()=>{try{let w=u.loadChatsIndex();M(w);let v=w.find(y=>y.id===n);I(v||null);}catch(w){console.error("Failed to refresh chat list:",w);}},[u,n]);useEffect(()=>{i();},[i]),useEffect(()=>{if(!(!m||h.current)){try{u.loadCurrentChatId()&&(k.current=!0);}catch(w){console.error("Failed to restore chat:",w);}h.current=true;}},[u,m]),useEffect(()=>{if(!(!l||r.length===0))if(k.current){if(!o){let w=Date.now();try{u.saveChat({id:n,messages:r,agentId:t});let y=u.loadChatsIndex().find(S=>S.id===n);y&&(u.upsertChatMeta({...y,updatedAt:w}),i());}catch(v){console.error("Failed to save chat:",v);}}}else {let w=r.find(v=>v.role==="user");if(w){let v="";if(Array.isArray(w.parts)){let p=w.parts.find(B=>B&&B.type==="text");v=p&&typeof p.text=="string"?p.text:"";}let y=(v||"New chat").slice(0,80),S=Date.now();try{u.upsertChatMeta({id:n,title:y,createdAt:S,updatedAt:S}),u.saveChat({id:n,messages:r,agentId:t}),u.saveCurrentChatId(n),k.current=!0,i();}catch(p){console.error("Failed to create chat:",p);}}}},[]);let b=useRef(false);useEffect(()=>{if(o){b.current=true;return}if(b.current&&l){b.current=false;try{let w=Date.now();u.saveChat({id:n,messages:r,agentId:t});let y=u.loadChatsIndex().find(S=>S.id===n);if(y)u.upsertChatMeta({...y,updatedAt:w});else {let S="",p=Array.isArray(r)?r.find(W=>W&&W.role==="user"):void 0;if(p&&Array.isArray(p.parts)){let W=p.parts.find(j=>j&&j.type==="text");S=W&&typeof W.text=="string"?W.text:"";}let B=(S||"New chat").slice(0,80);u.upsertChatMeta({id:n,title:B,createdAt:w,updatedAt:w});try{u.saveCurrentChatId(n);}catch{}k.current=!0;}i();}catch(w){console.error("Failed to save chat on completion:",w);}}},[o,r,n,t,u,l,i]);let d=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]),c=useCallback(()=>{if(r.length!==0)try{let w=Date.now();u.saveChat({id:n,messages:r,agentId:t});let y=u.loadChatsIndex().find(S=>S.id===n);y&&(u.upsertChatMeta({...y,updatedAt:w}),i());}catch(w){console.error("Failed to save chat:",w);}},[u,n,r,t,i]),f=useCallback(w=>{try{u.deleteChat(w),i();}catch(v){console.error("Failed to delete chat:",v);}},[u,i]),s=useCallback((w,v)=>{if(w!==n)try{k.current=!0,u.saveCurrentChatId(w);let y=u.loadChat(w),S=y&&Array.isArray(y.messages)?y.messages:[];v(S),i();}catch(y){console.error("Failed to switch chat:",y);}},[u,n,i]),a=useCallback(w=>{k.current=false,w();},[]),T=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:d,saveCurrentChat:c,deleteChat:f,switchToChat:s,createNewChat:a,searchChats:T,storage:u}}function rr(e){let{messages:t,isLoading:n,sendMessage:r,setMessages:o,baseUrl:l}=e,{baseUrl:m}=se(),u=l||m||"",[C,M]=useState(null),[x,I]=useState(""),[k,h]=useState([]),[i,b]=useState(false),d=useCallback((w,v,y=[])=>{M(w),I(v),h(y);},[]),c=useCallback(()=>{M(null),I(""),h([]);},[]),f=useCallback(async w=>{if(!n)try{let v=t.findIndex(S=>S.id===w);if(v===-1)return;let y=t.slice(0,v);o(y),await r({text:x.trim(),files:k.map(S=>({type:"file",url:S.url,mediaType:S.mimeType||"application/octet-stream",...S.name?{name:S.name}:{},...S.size?{size:S.size}:{}}))}),c();}catch(v){throw console.error("Failed to save edit:",v),v}},[n,t,r,x,k,o,c]),s=useCallback(w=>C===w,[C]),a=useCallback(async w=>{if(!u){console.warn("baseUrl not provided, cannot upload attachments");return}b(true);try{let v=Array.from(w).map(async S=>{if(S.size>26214400)throw new Error(`${S.name} is too large (max 25MB)`);let p=new FormData;p.append("file",S);let B=await fetch(`${u}/api/upload`,{method:"POST",body:p});if(!B.ok)throw new Error(`Upload failed: ${B.statusText}`);let W=await B.json();return {id:W.url||`${Date.now()}-${Math.random()}`,name:S.name,url:W.url,mimeType:S.type,size:S.size}}),y=await Promise.all(v);h(S=>[...S,...y]);}catch(v){throw console.error("Failed to upload files:",v),v}finally{b(false);}},[u]),T=useCallback(w=>{h(v=>v.filter(y=>y.id!==w));},[]);return {editingMessageId:C,editingText:x,setEditingText:I,editAttachments:k,setEditAttachments:h,editUploading:i,startEdit:d,cancelEdit:c,saveEdit:f,isEditing:s,addEditAttachments:a,removeEditAttachment:T}}function X({IconComponent:e,...t}){return po.createElement(e,t)}function Ot({icon:e,onClick:t,ariaLabel:n,resolvedColors:r,disabled:o=false,title:l}){return jsx("button",{"aria-label":n,title:l,disabled:o,style:{backgroundColor:"transparent",color:r.mutedTextColor,border:"none",borderRadius:"8px",padding:"8px",cursor:o?"not-allowed":"pointer",opacity:o?.5:1,transition:"all 0.2s ease-out",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:m=>{o||(m.currentTarget.style.backgroundColor=r.hoverBackground,m.currentTarget.style.color=r.textColor);},onMouseLeave:m=>{m.currentTarget.style.backgroundColor="transparent",m.currentTarget.style.color=r.mutedTextColor;},onClick:t,children:e})}function no({title:e,alwaysOpen:t,streaming:n,dir:r,resolvedColors:o,onNew:l,onToggleHistory:m,onClose:u,historyBtnRef:C,t:M}){return jsxs("div",{style:{marginBottom:"24px",display:"flex",alignItems:"center",justifyContent:"space-between",direction:r==="rtl"?"rtl":"ltr"},children:[jsx("div",{style:{minWidth:"0"},children:jsx("h1",{title:e,style:{color:o.textColor,fontSize:"18px",fontWeight:"600",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",margin:"0"},children:e})}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",position:"relative",color:o.mutedTextColor},children:[jsx(Ot,{icon:jsx(X,{IconComponent:Plus,size:"20",strokeWidth:"2"}),onClick:()=>{n||l();},ariaLabel:M("header.new"),resolvedColors:o,disabled:n}),jsx("button",{ref:C,"aria-label":M("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:x=>{x.currentTarget.style.backgroundColor=o.hoverBackground,x.currentTarget.style.color=o.textColor;},onMouseLeave:x=>{x.currentTarget.style.backgroundColor="transparent",x.currentTarget.style.color=o.mutedTextColor;},onClick:m,children:jsx(X,{IconComponent:History,size:"20",strokeWidth:"2"})}),!t&&jsx(Ot,{icon:jsx(X,{IconComponent:ChevronRight,size:"20",strokeWidth:"2",style:{transform:r==="rtl"?"rotate(180deg)":"none"}}),onClick:u,ariaLabel:M("header.close"),resolvedColors:o})]})]})}var yt=class extends Component{constructor(t){super(t),this.state={hasError:false,error:null,errorInfo:null};}static getDerivedStateFromError(t){return {hasError:true,error:t,errorInfo:null}}componentDidMount(){let{toolCallId:t,toolName:n,onSuccess:r}=this.props;t&&n&&r&&!this.state.hasError&&setTimeout(()=>{this.state.hasError||r(t,n);},0);}componentDidCatch(t,n){console.error(`UI Component Error (${this.props.componentName}):`,t,n),this.setState({error:t,errorInfo:n});let{toolCallId:r,toolName:o,onError:l}=this.props;r&&o&&l&&l(r,o,t);}render(){if(this.state.hasError&&this.state.error){let{resolvedColors:t,componentName:n}=this.props;return jsxs("div",{style:{padding:"16px",backgroundColor:"#fee2e2",border:"2px solid #ef4444",borderRadius:"12px",color:"#991b1b"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},children:[jsx("span",{style:{fontSize:"20px"},children:"\u26A0\uFE0F"}),jsxs("strong",{style:{fontSize:"16px"},children:["Component Error: ",n]})]}),jsx("div",{style:{fontSize:"14px",marginBottom:"8px",fontFamily:"monospace"},children:this.state.error.message}),this.state.errorInfo&&jsxs("details",{style:{fontSize:"12px",marginTop:"8px"},children:[jsx("summary",{style:{cursor:"pointer",fontWeight:"bold"},children:"Stack Trace"}),jsx("pre",{style:{marginTop:"8px",padding:"8px",backgroundColor:"#fef2f2",borderRadius:"4px",overflow:"auto",maxHeight:"200px",fontSize:"11px"},children:this.state.errorInfo.componentStack})]})]})}return this.props.children}};var ur=(e,t)=>{let n={"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 n[e||"output-available"]||n["output-available"]},pr=e=>{let t=/^(.+?)_([a-f0-9]{6})_(.+)$/,n=e.match(t);if(n){let[,r,,o]=n;return {isMCP:true,mcpName:r.replace(/_/g," "),toolName:o.replace(/_/g," ")}}return {isMCP:false,toolName:e}},mr=e=>e.replace(/_/g," ").replace(/-/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\b\w/g,t=>t.toUpperCase());function oo({parts:e,messageId:t,openReasoningIds:n,toggleReasoning:r,resolvedColors:o,HsafaUI:l,onUIError:m,onUISuccess:u,addToolResult:C,dir:M="ltr",t:x}){let I=M==="rtl",k=[],h=[],i,b,d=false;for(let c of Array.isArray(e)?e:[]){if(!c)continue;if(c.type==="reasoning"&&typeof c.text=="string"){h.push(c.text),i||(i=c.startDate),b=c.endDate,c.state==="done"&&(d=true);continue}if(c.type==="text"&&typeof c.text=="string"){h.length&&(k.push({type:"reasoning",texts:h,startDate:i,endDate:b,isCompleted:d}),h=[],i=void 0,b=void 0,d=false),k.push({type:"text",text:c.text,startDate:c.startDate,endDate:c.endDate});continue}let f=c.type==="dynamic-tool",s=typeof c.type=="string"&&c.type.startsWith("tool-");if(f||s||c.type==="tool-call"){h.length&&(k.push({type:"reasoning",texts:h,startDate:i,endDate:b,isCompleted:d}),h=[],i=void 0,b=void 0,d=false);let a=String(f?c.toolName||"dynamic-tool":s?c.type?.slice(5)||"tool":c.toolName||"tool");a==="requestInput"?k.push({type:"tool",toolName:a,status:c.state||c.status,input:c.input,output:c.output,startDate:c.startDate,endDate:c.endDate,toolCallId:c.toolCallId}):k.push({type:"tool",toolName:a,status:c.state||c.status,input:c.input,output:c.output,startDate:c.startDate,endDate:c.endDate,toolCallId:c.toolCallId});continue}}return h.length&&k.push({type:"reasoning",texts:h,startDate:i,endDate:b,isCompleted:d}),k.length?jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px",direction:I?"rtl":"ltr"},children:[k.map((c,f)=>{let s=`${t}-${f}`,a=n.has(s);if(c.type==="reasoning"){let p=c.isCompleted||typeof c.startDate=="number"&&typeof c.endDate=="number",B=c.texts&&c.texts.length>0&&c.texts.some(j=>j.trim().length>0),W=()=>{B&&r(s);};return p&&!B?null:jsx("div",{onClick:W,style:{cursor:B?"pointer":"default",padding:"0"},children:jsxs("div",{style:{display:"flex",flexDirection:"column",gap:a?"4px":"0px"},children:[jsxs("div",{style:{fontSize:"13px",color:o.mutedTextColor,fontWeight:500,display:"flex",alignItems:"center",gap:"6px",overflow:"hidden",maxWidth:"100%",minWidth:0,width:"100%"},children:[jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px"},children:[!p&&jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),jsx("span",{style:{color:o.textColor,fontWeight:600,opacity:.9,background:p?"none":`linear-gradient(90deg, ${o.textColor}, ${o.mutedTextColor}, ${o.mutedTextColor})`,backgroundSize:p?"auto":"200% 100%",backgroundClip:p?"unset":"text",WebkitBackgroundClip:p?"unset":"text",WebkitTextFillColor:p?o.mutedTextColor:"transparent",animation:p?void 0:"shimmer 2s ease-in-out infinite"},children:p?x?x("assistant.finishThinking"):"Finish Thinking":x?x("assistant.thinking"):"Thinking"})]}),B&&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:jsx("polyline",{points:"9 18 15 12 9 6"})})]}),jsx("div",{style:{display:"grid",gridTemplateRows:a||!p?"1fr":"0fr",transition:"grid-template-rows 0.2s ease-out",overflow:"hidden"},children:jsx("div",{style:{minHeight:0},children:c.texts&&c.texts.length>0?jsx("div",{style:{fontSize:"13px",color:o.mutedTextColor,lineHeight:"1.6",maxWidth:"100%"},children:(!p&&a?c.texts:p?a?c.texts:[]:[c.texts[c.texts.length-1]]).map((j,ne)=>jsx("div",{style:{marginBottom:"6px",opacity:.5},children:jsx(Ye,{content:j,theme:"dark",streaming:!p})},`rg-line-${f}-${ne}`))}):jsxs("div",{style:{fontSize:"12px",color:o.mutedTextColor,opacity:.7,display:"flex",alignItems:"center",gap:"8px"},children:[jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),jsx("span",{style:{letterSpacing:"2px",animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"},children:"..."})]})})})]})},s)}if(c.type==="text"){let p=typeof c.endDate!="number";return jsx("div",{style:{fontSize:"15px",color:o.textColor,lineHeight:"1.6",direction:I?"rtl":"ltr",textAlign:I?"right":"left"},children:jsx(Ye,{content:c.text,theme:"dark",streaming:p})},s)}let{color:T,text:w}=ur(c.status,x),v=c.status==="input-streaming"||c.status==="input-available";if(c.toolName==="requestInput")return jsx("div",{style:{display:"block",position:"relative"},children:jsx("div",{"data-get-from-user-host":c.toolCallId||s,style:{width:"100%"}})},s);let y=l?.[c.toolName||""];if(y)return jsx("div",{style:{display:"block",position:"relative"},children:jsx(yt,{componentName:c.toolName||"Unknown",resolvedColors:o,toolCallId:c.toolCallId,toolName:c.toolName||"unknown",onError:m,onSuccess:u,children:jsx(y,{toolName:c.toolName||"",toolCallId:c.toolCallId||"",input:c.input,output:c.output,status:c.status,addToolResult:C})})},s);let S=pr(c.toolName||"tool");return jsx("div",{style:{display:"flex",gap:"12px",position:"relative"},children:jsx("div",{style:{flex:1,minWidth:0},children:jsxs("div",{style:{fontSize:"13px",color:o.mutedTextColor,display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"},children:[jsxs("span",{style:{fontWeight:600,color:T,display:"flex",alignItems:"center",gap:"6px"},children:[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]}),S.isMCP?jsxs("span",{style:{fontWeight:500,color:o.textColor},children:[jsx("span",{style:{fontWeight:600},children:S.toolName}),jsx("span",{style:{opacity:.7,margin:"0 4px"},children:"from"}),jsx("span",{style:{fontWeight:600,opacity:.85},children:S.mcpName})]}):jsx("span",{style:{fontWeight:500,color:o.textColor},children:mr(S.toolName)})]})})},s)}),jsx("style",{children:`
|
|
11
|
+
`,document.head.appendChild(n);}Nr=true;}return t?(t.classList.add("as-arrow"),Ve||(Ve=createRoot(t),Ve.render(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),Ve=createRoot(t),Ve.render(jsx(Wr,{arrowSvg:r.arrow,pointerSvg:r.pointer}))),t}function Fe(e,t,r){return Math.max(t,Math.min(r,e))}function Gn(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 jn({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 _n(e){let t=e?qr(e):null;return !t||t.a===0?false:jn(t)<.5}function qn(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 zt(e,t,r){let o=qn(t,r),n=_n(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 st(e,t,r,o,n="ease-in-out",s="curve",m=.25,u="auto",C){_r(),Pt(e);let I=performance.now(),x=n==="linear"?f=>f:Gn,S=s!=="straight",k={x:0,y:0};if(S){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=Fe(m,0,1)*b;k={x:c+a*h*T,y:d+a*l*T};}return new Promise(f=>{function i(b){let c=Fe((b-I)/o,0,1),d=x(c),h,l;if(S){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`,zt(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 pe(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 Kn(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=Kn(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=Fe(t.x,0,1),n=Fe(t.y,0,1);return {x:r.left+r.width*o,y:r.top+r.height*n}}function jr(e){return {x:Fe(e.x,0,window.innerWidth),y:Fe(e.y,0,window.innerHeight)}}function Vn(){return useEffect(()=>(window.__cursorGuide=async(e,t={})=>{let r=Array.isArray(e)?e:[{target:e,action:t.action??"none",options:t}],o=[],n=await On();n.classList.add("visible","as-arrow"),n.classList.remove("as-pointer","pressing"),Pt(n),_r();let s=parseFloat(n.style.left||"20")||20,m=parseFloat(n.style.top||"20")||20;zt(n,s,m);for(let u of r){let{durationMs:C=800,easing:I="ease-in-out",offset:x,highlight:S=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 $n(w,1500,180),Pt(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 st(n,v,y,C,I,k,f,i);let M=y.x-v.x,p=y.y-v.y,B=Math.hypot(M,p)||1,W=M/B,j=p/B,re=Math.min(6,Math.max(3,B*.02)),ye={x:y.x+W*re,y:y.y+j*re};await st(n,y,ye,Math.max(70,C*.1),"ease-out","straight",0,"right"),await st(n,ye,y,120,"ease-out","straight",0,"left"),S&&(n.classList?.add("click"),setTimeout(()=>n.classList?.remove("click"),180));let me=null;try{if(h==="click"){n.classList.remove("as-arrow"),n.classList.add("as-pointer","pressing");let _={x:c?.x??0,y:c?.y??0},U={x:y.x+_.x,y:y.y+_.y};n.style.left=`${U.x}px`,n.style.top=`${U.y}px`,zt(n,U.x,U.y);let q=w??document.elementFromPoint(U.x,U.y)??document.body;pe(q,"pointerdown",U),pe(q,"mousedown",U),await new Promise(O=>setTimeout(O,90)),n.classList.remove("pressing"),pe(q,"mouseup",U),pe(q,"click",U),setTimeout(()=>{n.classList.remove("as-pointer"),n.classList.add("as-arrow");},140),q instanceof HTMLElement&&q.focus?.(),me=q?.id??null;}else if(h==="drag"){if(!d)throw new Error("dragTo is required for action 'drag'");let _=Or(d),U=null;if(_.kind==="element"&&_.element&&(U=Gr(_.element,b)),_.kind==="position"&&_.point&&(U=_.point),!U)throw new Error("dragTo target not found");let q=jr(Ur(U,x)),O={x:y.x,y:y.y},De=w??document.elementFromPoint(O.x,O.y)??document.body;n.classList.remove("as-arrow"),n.classList.add("as-pointer","pressing"),pe(De,"pointerdown",O),pe(De,"mousedown",O),await st(n,O,q,Math.max(200,C),I,k,f,i,({x:ne,y:Z})=>{let ge=document.elementFromPoint(ne,Z)??document.body,Pe={x:ne,y:Z};pe(ge,"pointermove",Pe),pe(ge,"mousemove",Pe);});let J=document.elementFromPoint(q.x,q.y)??document.body;n.classList.remove("pressing"),pe(J,"pointerup",q),pe(J,"mouseup",q);}o.push({ok:!0,action:h,targetKind:a.kind,durationMs:Math.round(performance.now()-l),clickedElementId:me});}catch(_){o.push({ok:false,action:h,targetKind:a.kind,durationMs:Math.round(performance.now()-l),error:_?.message??String(_)});}}return Pn(n,2e3),{ok:o.every(u=>u.ok),steps:o}},()=>{try{delete window.__cursorGuide;}catch{window.__cursorGuide=void 0;}}),[]),null}var Xe=Vn;function Vr(){return {getDomComponents:{tool:async({includeHidden:e,selector:t})=>await qe({includeHidden:e,selector:t}),executeEachToken:false},controlCursor:{tool:async({target:e,action:t,anchor:r,durationMs:o,dragTo:n})=>{let s=await Ie(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 Ke(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 Ye({content:e,theme:t="dark",streaming:r=false,dir:o="ltr"}){return jsxs("div",{dir:o,className:"x-markdown-wrapper",style:{width:"100%",maxWidth:"100%"},children:[jsx(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:o,width:"100%"}}),jsx("style",{children:`
|
|
12
|
+
/* Ensure tables take full width */
|
|
13
|
+
.x-markdown-wrapper table,
|
|
14
|
+
.x-markdown-dark table,
|
|
15
|
+
.x-markdown-light table {
|
|
16
|
+
width: 100% !important;
|
|
17
|
+
table-layout: auto !important;
|
|
18
|
+
display: table !important;
|
|
19
|
+
box-sizing: border-box !important;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.x-markdown-wrapper table thead,
|
|
23
|
+
.x-markdown-wrapper table tbody,
|
|
24
|
+
.x-markdown-wrapper table tfoot {
|
|
25
|
+
width: 100% !important;
|
|
26
|
+
display: table-header-group !important;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.x-markdown-wrapper table tbody {
|
|
30
|
+
display: table-row-group !important;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.x-markdown-wrapper table tr {
|
|
34
|
+
width: 100% !important;
|
|
35
|
+
display: table-row !important;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.x-markdown-wrapper table th,
|
|
39
|
+
.x-markdown-wrapper table td {
|
|
40
|
+
display: table-cell !important;
|
|
41
|
+
box-sizing: border-box !important;
|
|
42
|
+
}
|
|
43
|
+
`}),o==="rtl"&&jsx("style",{children:`
|
|
44
|
+
/* Lists */
|
|
45
|
+
[dir="rtl"] ul,
|
|
46
|
+
[dir="rtl"] ol {
|
|
47
|
+
padding-right: 2em;
|
|
48
|
+
padding-left: 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
[dir="rtl"] ul li,
|
|
52
|
+
[dir="rtl"] ol li {
|
|
53
|
+
text-align: right;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
[dir="rtl"] ul {
|
|
57
|
+
list-style-position: inside;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
[dir="rtl"] ol {
|
|
61
|
+
list-style-position: inside;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* Blockquotes */
|
|
65
|
+
[dir="rtl"] blockquote {
|
|
66
|
+
border-left: none;
|
|
67
|
+
border-right: 4px solid;
|
|
68
|
+
padding-left: 0;
|
|
69
|
+
padding-right: 1em;
|
|
70
|
+
margin-left: 0;
|
|
71
|
+
margin-right: 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* Code blocks - keep LTR */
|
|
75
|
+
[dir="rtl"] code {
|
|
76
|
+
direction: ltr;
|
|
77
|
+
text-align: left;
|
|
78
|
+
display: inline-block;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
[dir="rtl"] pre {
|
|
82
|
+
direction: ltr;
|
|
83
|
+
text-align: left;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
[dir="rtl"] pre code {
|
|
87
|
+
direction: ltr;
|
|
88
|
+
text-align: left;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* Tables */
|
|
92
|
+
[dir="rtl"] table {
|
|
93
|
+
direction: rtl;
|
|
94
|
+
width: 100%;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
[dir="rtl"] table th,
|
|
98
|
+
[dir="rtl"] table td {
|
|
99
|
+
text-align: right;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
[dir="rtl"] table th:first-child,
|
|
103
|
+
[dir="rtl"] table td:first-child {
|
|
104
|
+
padding-right: 12px;
|
|
105
|
+
padding-left: 12px;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
[dir="rtl"] table th:last-child,
|
|
109
|
+
[dir="rtl"] table td:last-child {
|
|
110
|
+
padding-left: 12px;
|
|
111
|
+
padding-right: 12px;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/* Headings */
|
|
115
|
+
[dir="rtl"] h1,
|
|
116
|
+
[dir="rtl"] h2,
|
|
117
|
+
[dir="rtl"] h3,
|
|
118
|
+
[dir="rtl"] h4,
|
|
119
|
+
[dir="rtl"] h5,
|
|
120
|
+
[dir="rtl"] h6 {
|
|
121
|
+
text-align: right;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* Paragraphs */
|
|
125
|
+
[dir="rtl"] p {
|
|
126
|
+
text-align: right;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/* Links */
|
|
130
|
+
[dir="rtl"] a {
|
|
131
|
+
direction: rtl;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/* Horizontal rules */
|
|
135
|
+
[dir="rtl"] hr {
|
|
136
|
+
margin-left: 0;
|
|
137
|
+
margin-right: 0;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/* Task lists */
|
|
141
|
+
[dir="rtl"] input[type="checkbox"] {
|
|
142
|
+
margin-right: 0;
|
|
143
|
+
margin-left: 0.5em;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/* Nested lists */
|
|
147
|
+
[dir="rtl"] ul ul,
|
|
148
|
+
[dir="rtl"] ol ol,
|
|
149
|
+
[dir="rtl"] ul ol,
|
|
150
|
+
[dir="rtl"] ol ul {
|
|
151
|
+
padding-right: 2em;
|
|
152
|
+
padding-left: 0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* Images */
|
|
156
|
+
[dir="rtl"] img {
|
|
157
|
+
margin-left: auto;
|
|
158
|
+
margin-right: 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* Details/Summary */
|
|
162
|
+
[dir="rtl"] details {
|
|
163
|
+
text-align: right;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
[dir="rtl"] summary {
|
|
167
|
+
text-align: right;
|
|
168
|
+
}
|
|
169
|
+
`})]})}function Qn({input:e}){return jsx("div",{style:{fontSize:"14px",lineHeight:"1.6",width:"100%"},children:jsx(Ye,{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||"",I=e?.submitLabel||"Submit",x=e?.skipLabel||"Skip",S=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);}S.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(B=>{let W=document.createElement("option");W.value=String(B.value),W.text=String(B.label??B.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 M=k.values&&Object.prototype.hasOwnProperty.call(k.values,y)?k.values[y]:void 0;typeof M<"u"&&(w.type==="checkbox"?w.checked=!!M:w.value=String(M)),(k.submitted||k.skipped)&&(w.setAttribute("disabled","true"),w.style.opacity="0.7"),T.appendChild(w),f.appendChild(T);});let b=String(I).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=useRef(new Map),n=useRef(new Map),s=useRef(t),m=useRef(r);s.current=t,m.current=r,useEffect(()=>{e.forEach(u=>{u.role==="assistant"&&u.parts?.forEach(C=>{if(!C.toolCallId)return;let I=C.toolName;if(!I&&C.type?.startsWith("tool-")&&(I=C.type.replace(/^tool-/,"")),!I)return;let x=s.current[I];if(x&&typeof x=="object"&&x.executeEachToken&&x.tool){let S=C.input||C.args||{},k=JSON.stringify(S),f=o.current.get(C.toolCallId);if(k!==f&&k!=="{}"){o.current.set(C.toolCallId,k);try{if(I==="requestInput")m.current(S,C.toolCallId);else {let b=(n.current.get(C.toolCallId)||0)+1;n.current.set(C.toolCallId,b),b>1&&x.tool({...S,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:I,controlledChatId:x,onChatIdChange:S,templateParams:k}=e,{baseUrl:f,setCurrentChatId:i}=se(),b=r&&r.length>0?r:f||"",[c,d]=useState(""),[h,l]=useState(()=>`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`),a=x??h,T=useCallback(E=>{x===void 0&&l(E),S&&S(E);},[x,S]);useEffect(()=>{try{i(a);}catch{}return ()=>{try{i(void 0);}catch{}}},[a,i]);let w=useMemo(()=>Dr(b,t,a,k),[b,t,a,k]),v=useCallback(E=>{console.log("Message finished:",E);let L=E?.message?.id;if(!L&&Array.isArray(E?.messages))for(let G=E.messages.length-1;G>=0;G--){let z=E.messages[G];if(z&&z.role==="assistant"&&z.id){L=z.id;break}}m?.({...E,chatId:a,assistantMessageId:L});},[m,a]),y=useCallback(E=>{console.error("Chat error:",E),u?.(E);},[u]),M=useMemo(()=>Vr(),[]),p=useMemo(()=>({...M,...o}),[M,o]),B=useMemo(()=>Yr(),[]),W=useMemo(()=>({...B,...n}),[B,n]),j=useRef(new Map),re=useRef(new Map),ye=useCallback(()=>{try{j.current.forEach(E=>{try{E.remove();}catch{}}),j.current.clear(),re.current.clear();}catch{}},[]),me=useCallback((E,L)=>{Jr(E,L,j.current,re.current,G=>_.current.addToolResult(G));},[]),_=useRef(null),U=useRef(new Set),q=useCallback((E,L,G)=>{console.error(`UI Error [${L}]:`,G),_.current&&U.current.has(E)&&(U.current.delete(E),_.current.addToolResult({tool:L,toolCallId:E,state:"output-error",errorText:G?.message||String(G)}));},[]),O=useCallback((E,L)=>{_.current&&U.current.has(E)&&(U.current.delete(E),_.current.addToolResult({tool:L,toolCallId:E,output:{status:"ok",rendered:true,component:L,logs:[]}}));},[]),De=useCallback(E=>{let L=p[E];return L?typeof L=="object"&&"tool"in L?L.tool:typeof L=="function"?L:null:null},[p]),J=useChat({transport:w,onFinish:v,onError:y,experimental_throttle:10,sendAutomaticallyWhen:lastAssistantMessageIsCompleteWithToolCalls,async onToolCall({toolCall:E}){let L=De(E.toolName);if(E.toolName==="requestInput"){try{me(E.input,E.toolCallId);}catch(te){console.error("requestInput render error",te);}return}let G=E.toolName==="ui";E?.input;let ee=W&&E.toolName in W;if(G||ee){U.current.add(E.toolCallId);return}if(L)try{let te=await L(E.input);J.addToolResult({tool:E.toolName,toolCallId:E.toolCallId,output:te});}catch(te){J.addToolResult({tool:E.toolName,toolCallId:E.toolCallId,state:"output-error",errorText:te?.message||String(te)});}}}),{messages:ne,sendMessage:Z,status:ge,stop:Pe,error:Qt}=J;_.current=J,Zr(ne,p,me),useEffect(()=>{try{let E=new Set,L=[];if(ne.forEach(G=>{G.role==="assistant"&&(G.parts||[]).forEach(z=>{if((z?.toolName||(typeof z?.type=="string"&&z.type.startsWith("tool-")?String(z.type.replace(/^tool-/,"")):void 0))!=="requestInput")return;let te=z?.toolCallId||"";if(!te)return;E.add(te);let K=z?.output;if(K&&(K.submitted||K.skipped||K.values)){let ze={submitted:!!K.submitted,skipped:!!K.skipped,values:K.values||void 0};re.current.set(te,ze);}let tt=z?.input||z?.args||{};L.push({input:tt,toolCallId:te});});}),j.current.forEach((G,z)=>{if(!E.has(z)){let ee=j.current.get(z);try{ee?.remove();}catch{}j.current.delete(z),re.current.delete(z);}}),L.length>0){let G=requestAnimationFrame(()=>{L.forEach(({input:z,toolCallId:ee})=>{try{me(z,ee);}catch{}});});return ()=>cancelAnimationFrame(G)}}catch{}},[ne,me]),useEffect(()=>{C&&C.length>0&&ne.length===0&&console.log("Initial messages:",C);},[C,ne.length]);let A=ge==="submitted"||ge==="streaming",P=useCallback(()=>{I&&I(ne,a);},[I,ne,a]),kt=useCallback(async E=>{let L=E?.text!==void 0?E.text:c,G=E?.files||[],z=L.trim();if(!(!z&&G.length===0)&&!A){E?.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:G});}catch(ee){throw console.error("Failed to send message:",ee),ee}}},[c,A,Z,s,a]),ve=useCallback(()=>{if(A)return;ye(),d("");try{J?.setMessages?.([]);}catch{}let E=`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`;T(E);},[A,J,ye,T]),fe=useCallback(E=>{try{J?.setMessages?.(E);}catch{}},[J]);return {input:c,setInput:d,messages:ne,isLoading:A,status:ge,error:Qt,sendMessage:kt,stop:Pe,newChat:ve,setMessages:fe,notifyMessagesChange:P,chatApi:J,chatId:a,setChatId:T,tools:p,uiComponents:W,formHostRef:j,formStateRef:re,cleanupForms:ye,onUISuccess:O,onUIError:q}}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}},I=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);},S=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:I,upsertChatMeta:x,deleteChatMeta:S,deleteChatData:k,deleteChat:l=>{k(l),S(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=useMemo(()=>pt(t),[t]),[C,I]=useState([]),[x,S]=useState(null),k=useRef(false),f=useRef(false),i=useCallback(()=>{try{let w=u.loadChatsIndex();I(w);let v=w.find(y=>y.id===r);S(v||null);}catch(w){console.error("Failed to refresh chat list:",w);}},[u,r]);useEffect(()=>{i();},[i]),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]),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(M=>M.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(B=>B&&B.type==="text");v=p&&typeof p.text=="string"?p.text:"";}let y=(v||"New chat").slice(0,80),M=Date.now();try{u.upsertChatMeta({id:r,title:y,createdAt:M,updatedAt:M}),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=useRef(false);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(M=>M.id===r);if(y)u.upsertChatMeta({...y,updatedAt:w});else {let M="",p=Array.isArray(o)?o.find(W=>W&&W.role==="user"):void 0;if(p&&Array.isArray(p.parts)){let W=p.parts.find(j=>j&&j.type==="text");M=W&&typeof W.text=="string"?W.text:"";}let B=(M||"New chat").slice(0,80);u.upsertChatMeta({id:r,title:B,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=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=useCallback(()=>{if(o.length!==0)try{let w=Date.now();u.saveChat({id:r,messages:o,agentId:t});let y=u.loadChatsIndex().find(M=>M.id===r);y&&(u.upsertChatMeta({...y,updatedAt:w}),i());}catch(w){console.error("Failed to save chat:",w);}},[u,r,o,t,i]),h=useCallback(w=>{try{u.deleteChat(w),i();}catch(v){console.error("Failed to delete chat:",v);}},[u,i]),l=useCallback((w,v)=>{if(w!==r)try{k.current=!0,u.saveCurrentChatId(w);let y=u.loadChat(w),M=y&&Array.isArray(y.messages)?y.messages:[];v(M),i();}catch(y){console.error("Failed to switch chat:",y);}},[u,r,i]),a=useCallback(w=>{k.current=false,w();},[]),T=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}=se(),u=s||m||"",[C,I]=useState(null),[x,S]=useState(""),[k,f]=useState([]),[i,b]=useState(false),c=useCallback((w,v,y=[])=>{I(w),S(v),f(y);},[]),d=useCallback(()=>{I(null),S(""),f([]);},[]),h=useCallback(async w=>{if(!r)try{let v=t.findIndex(M=>M.id===w);if(v===-1)return;let y=t.slice(0,v);n(y),await o({text:x.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(v){throw console.error("Failed to save edit:",v),v}},[r,t,o,x,k,n,d]),l=useCallback(w=>C===w,[C]),a=useCallback(async w=>{if(!u){console.warn("baseUrl not provided, cannot upload attachments");return}b(true);try{let v=Array.from(w).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 B=await fetch(`${u}/api/upload`,{method:"POST",body:p});if(!B.ok)throw new Error(`Upload failed: ${B.statusText}`);let W=await B.json();return {id:W.url||`${Date.now()}-${Math.random()}`,name:M.name,url:W.url,mimeType:M.type,size:M.size}}),y=await Promise.all(v);f(M=>[...M,...y]);}catch(v){throw console.error("Failed to upload files:",v),v}finally{b(false);}},[u]),T=useCallback(w=>{f(v=>v.filter(y=>y.id!==w));},[]);return {editingMessageId:C,editingText:x,setEditingText:S,editAttachments:k,setEditAttachments:f,editUploading:i,startEdit:c,cancelEdit:d,saveEdit:h,isEditing:l,addEditAttachments:a,removeEditAttachment:T}}function X({IconComponent:e,...t}){return pn.createElement(e,t)}function Gt({icon:e,onClick:t,ariaLabel:r,resolvedColors:o,disabled:n=false,title:s}){return 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:I}){return jsxs("div",{style:{marginBottom:"24px",display:"flex",alignItems:"center",justifyContent:"space-between",direction:o==="rtl"?"rtl":"ltr"},children:[jsx("div",{style:{minWidth:"0"},children:jsx("h1",{title:e,style:{color:n.textColor,fontSize:"18px",fontWeight:"600",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",margin:"0"},children:e})}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",position:"relative",color:n.mutedTextColor},children:[jsx(Gt,{icon:jsx(X,{IconComponent:Plus,size:"20",strokeWidth:"2"}),onClick:()=>{r||s();},ariaLabel:I("header.new"),resolvedColors:n,disabled:r}),jsx("button",{ref:C,"aria-label":I("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:jsx(X,{IconComponent:History,size:"20",strokeWidth:"2"})}),!t&&jsx(Gt,{icon:jsx(X,{IconComponent:ChevronRight,size:"20",strokeWidth:"2",style:{transform:o==="rtl"?"rotate(180deg)":"none"}}),onClick:u,ariaLabel:I("header.close"),resolvedColors:n})]})]})}var yt=class extends Component{constructor(t){super(t),this.state={hasError:false,error:null,errorInfo:null};}static getDerivedStateFromError(t){return {hasError:true,error:t,errorInfo:null}}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 jsxs("div",{style:{padding:"16px",backgroundColor:"#fee2e2",border:"2px solid #ef4444",borderRadius:"12px",color:"#991b1b"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},children:[jsx("span",{style:{fontSize:"20px"},children:"\u26A0\uFE0F"}),jsxs("strong",{style:{fontSize:"16px"},children:["Component Error: ",r]})]}),jsx("div",{style:{fontSize:"14px",marginBottom:"8px",fontFamily:"monospace"},children:this.state.error.message}),this.state.errorInfo&&jsxs("details",{style:{fontSize:"12px",marginTop:"8px"},children:[jsx("summary",{style:{cursor:"pointer",fontWeight:"bold"},children:"Stack Trace"}),jsx("pre",{style:{marginTop:"8px",padding:"8px",backgroundColor:"#fef2f2",borderRadius:"4px",overflow:"auto",maxHeight:"200px",fontSize:"11px"},children:this.state.errorInfo.componentStack})]})]})}return this.props.children}};var 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:I="ltr",t:x}){let S=I==="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?jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px",direction:S?"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",B=d.texts&&d.texts.length>0&&d.texts.some(j=>j.trim().length>0),W=()=>{B&&o(l);};return p&&!B?null:jsx("div",{onClick:W,style:{cursor:B?"pointer":"default",padding:"0"},children:jsxs("div",{style:{display:"flex",flexDirection:"column",gap:a?"4px":"0px"},children:[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:[jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px"},children:[!p&&jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:n.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),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"})]}),B&&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:jsx("polyline",{points:"9 18 15 12 9 6"})})]}),jsx("div",{style:{display:"grid",gridTemplateRows:a||!p?"1fr":"0fr",transition:"grid-template-rows 0.2s ease-out",overflow:"hidden"},children:jsx("div",{style:{minHeight:0},children:d.texts&&d.texts.length>0?jsx("div",{style:{fontSize:"13px",color:n.mutedTextColor,lineHeight:"1.6",maxWidth:"100%"},children:(!p&&a?d.texts:p?a?d.texts:[]:[d.texts[d.texts.length-1]]).map((j,re)=>jsx("div",{style:{marginBottom:"6px",opacity:.5},children:jsx(Ye,{content:j,theme:"dark",streaming:!p,dir:I})},`rg-line-${h}-${re}`))}):jsxs("div",{style:{fontSize:"12px",color:n.mutedTextColor,opacity:.7,display:"flex",alignItems:"center",gap:"8px"},children:[jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:n.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),jsx("span",{style:{letterSpacing:"2px",animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"},children:"..."})]})})})]})},l)}if(d.type==="text"){let p=typeof d.endDate!="number";return jsx("div",{style:{fontSize:"15px",color:n.textColor,lineHeight:"1.6",direction:S?"rtl":"ltr",textAlign:S?"right":"left"},children:jsx(Ye,{content:d.text,theme:"dark",streaming:p,dir:I})},l)}let{color:T,text:w}=po(d.status,x),v=d.status==="input-streaming"||d.status==="input-available";if(d.toolName==="requestInput")return jsx("div",{style:{display:"block",position:"relative"},children:jsx("div",{"data-get-from-user-host":d.toolCallId||l,style:{width:"100%"}})},l);let y=s?.[d.toolName||""];if(y)return jsx("div",{style:{display:"block",position:"relative"},children:jsx(yt,{componentName:d.toolName||"Unknown",resolvedColors:n,toolCallId:d.toolCallId,toolName:d.toolName||"unknown",onError:m,onSuccess:u,children:jsx(y,{toolName:d.toolName||"",toolCallId:d.toolCallId||"",input:d.input,output:d.output,status:d.status,addToolResult:C})})},l);let M=mo(d.toolName||"tool");return jsx("div",{style:{display:"flex",gap:"12px",position:"relative"},children:jsx("div",{style:{flex:1,minWidth:0},children:jsxs("div",{style:{fontSize:"13px",color:n.mutedTextColor,display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"},children:[jsxs("span",{style:{fontWeight:600,color:T,display:"flex",alignItems:"center",gap:"6px"},children:[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]}),M.isMCP?jsxs("span",{style:{fontWeight:500,color:n.textColor},children:[jsx("span",{style:{fontWeight:600},children:M.toolName}),jsx("span",{style:{opacity:.7,margin:"0 4px"},children:"from"}),jsx("span",{style:{fontWeight:600,opacity:.85},children:M.mcpName})]}):jsx("span",{style:{fontWeight:500,color:n.textColor},children:go(M.toolName)})]})})},l)}),jsx("style",{children:`
|
|
12
170
|
@keyframes shimmer {
|
|
13
171
|
0% { background-position: -200% 0; }
|
|
14
172
|
100% { background-position: 200% 0; }
|
|
15
173
|
}
|
|
16
|
-
`})]}):null}function
|
|
174
|
+
`})]}):null}function on(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 an({attachment:e,resolvedColors:t,mode:r,onRemove:o,maxWidth:n="200px"}){let s=e.mimeType?.startsWith("image/"),m=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":n,position:"relative"},I=jsxs(Fragment,{children:[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?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:x=>{x.target.style.display="none";let S=x.target.nextElementSibling;S&&(S.style.display="block");}}):null,jsx(X,{IconComponent:File$1,size:r==="input"?14:10,strokeWidth:"2",style:{display:s?"none":"block",color:t.mutedTextColor}})]}),jsxs("div",{style:{minWidth:"0",flex:"1",display:"flex",flexDirection:"column"},children:[jsx("span",{title:e.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:"500"},children:e.name}),jsx("span",{style:{fontSize:r==="input"?"10px":"9px",color:t.mutedTextColor,marginTop:r==="input"?"2px":"1px"},children:on(e.size)})]}),r==="input"&&s&&jsx("button",{onClick:x=>{x.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:x=>{x.currentTarget.style.backgroundColor=t.hoverBackground,x.currentTarget.style.color=t.textColor;},onMouseLeave:x=>{x.currentTarget.style.backgroundColor="transparent",x.currentTarget.style.color=t.mutedTextColor;},children:jsx(X,{IconComponent:Eye,size:"12",strokeWidth:"2"})}),m&&o&&jsx("button",{onClick:x=>{x.stopPropagation(),o(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:x=>{x.currentTarget.style.backgroundColor="#ef444420",x.currentTarget.style.color="#ef4444";},onMouseLeave:x=>{x.currentTarget.style.backgroundColor="transparent",x.currentTarget.style.color=t.mutedTextColor;},children:jsx(X,{IconComponent:X$1,size:"12",strokeWidth:"2"})}),u&&jsx(X,{IconComponent:Download,size:"10",strokeWidth:"2",style:{color:t.mutedTextColor,flexShrink:0}})]});return u?jsx("a",{href:e.url,target:"_blank",rel:"noreferrer",style:{...C,textDecoration:"none"},onMouseEnter:x=>{x.currentTarget.style.backgroundColor=t.hoverBackground,x.currentTarget.style.borderColor=t.primaryColor;},onMouseLeave:x=>{x.currentTarget.style.backgroundColor=t.inputBackground,x.currentTarget.style.borderColor=t.borderColor;},children:I}):jsx("div",{style:C,children:I})}function ln({attachments:e,resolvedColors:t,onRemove:r}){if(!Array.isArray(e)||e.length===0)return null;let o=typeof r=="function"?"editable":"viewable";return jsx("div",{style:{marginTop:"12px",display:"flex",flexWrap:"wrap",gap:"8px"},children:e.map(n=>jsx(an,{attachment:n,resolvedColors:t,mode:o,onRemove:r},n.id))})}function _t({chatMessages:e,isLoading:t,openReasoningIds:r,toggleReasoning:o,resolvedColors:n,t:s,onUserMessageClick:m,HsafaUI:u,onUIError:C,onUISuccess:I,addToolResult:x,editableMessageIcon:S,fullPage:k,dir:f}){return jsxs(Fragment,{children:[jsx("style",{children:`
|
|
17
175
|
@keyframes jumpingDots {
|
|
18
176
|
0%, 80%, 100% {
|
|
19
177
|
transform: translateY(0);
|
|
@@ -22,8 +180,8 @@ import {jsxs,jsx,Fragment}from'react/jsx-runtime';import po,{createContext,useRe
|
|
|
22
180
|
transform: translateY(-5px);
|
|
23
181
|
}
|
|
24
182
|
}
|
|
25
|
-
`}),jsxs("div",{style:{display:"flex",flexDirection:"column",direction:
|
|
26
|
-
`),f=d.filter(s=>s.type==="file"||s.type==="image").map(s=>{if(s.type==="image"){let a=typeof s.image=="string"?s.image:s.image?.toString?.()||"";return {id:a||`${i.id}-img-${Date.now()}`,name:s.name||"image",url:a,mimeType:s.mediaType||"image/jpeg",size:s.size||0}}else return {id:s.url||`${i.id}-file-${Date.now()}`,name:s.name||"file",url:s.url||"",mimeType:s.mediaType||"application/octet-stream",size:s.size||0}});return jsx("div",{style:{padding:"0 4px",display:"flex",flexDirection:"column",alignItems:i.role==="user"&&k?"flex-end":"stretch"},children:i.role==="user"?jsx("div",{style:{maxWidth:k?"80%":"100%"},children:jsx("div",{title:l("editor.clickToEdit"),onClick:()=>m(i,i.id,c,f),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:s=>s.currentTarget.style.backgroundColor=o.hoverBackground,onMouseLeave:s=>s.currentTarget.style.backgroundColor=k?o.inputBackground:o.accentColor,children:jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxs("div",{style:{flex:1},children:[c,f.length>0&&jsx(so,{attachments:f,resolvedColors:o})]}),jsx("div",{style:{flexShrink:0,opacity:.5,transition:"opacity 0.2s"},children:jsx(X,{IconComponent:I||Pencil,size:"14",strokeWidth:"2"})})]})})}):jsx(oo,{parts:d,messageId:i.id,openReasoningIds:n,toggleReasoning:r,resolvedColors:o,HsafaUI:u,onUIError:C,onUISuccess:M,addToolResult:x})},i.id)}),t&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",padding:"0 4px",height:"20px"},children:[jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0s"}}),jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0.2s"}}),jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0.4s"}})]})]})]})}function _t({input:e,setInput:t,textareaRef:n,fileInputRef:r,isLoading:o,uploading:l,attachments:m,formatBytes:u,handleRemoveAttachment:C,onFileInputChange:M,onSend:x,onStop:I,status:k,t:h,resolvedColors:i,fullPage:b,dir:d="ltr"}){let c=k==="streaming"||k==="submitted",f=m.length>0||e.trim().length>0,s=d==="rtl";return b?jsxs("div",{style:{position:"relative",width:"100%",maxWidth:"768px",margin:"0 auto"},children:[jsxs("div",{style:{position:"relative",width:"100%",borderRadius:"26px",padding:s?"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:s?"rtl":"ltr"},onFocus:a=>{},children:[jsx("div",{style:{position:"absolute",bottom:"10px",...s?{right:"12px"}:{left:"12px"},zIndex:10},children:jsx("button",{onClick:()=>r.current?.click(),disabled:o||l,style:{borderRadius:"50%",width:"33px",height:"33px",transition:"all 0.2s",backgroundColor:"transparent",border:"none",cursor:o||l?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:i.textColor,opacity:o||l?.5:.7},"aria-label":h("input.attachFiles"),onMouseEnter:a=>{!o&&!l&&(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:jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:"M12 5v14M5 12h14"})})})}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[m.length>0&&jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",paddingBottom:"8px",...s?{marginRight:"-4px",justifyContent:"flex-end"}:{marginLeft:"-4px"}},children:m.map(a=>{let T=a.mimeType.startsWith("image/");return 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:[jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",borderRadius:"4px",backgroundColor:T?"transparent":i.inputBackground},children:T?jsx("img",{src:a.url,alt:a.name,style:{width:"20px",height:"20px",borderRadius:"4px",objectFit:"cover"}}):jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("rect",{x:"4",y:"4",width:"16",height:"20",rx:"2",ry:"2"})})}),jsx("span",{title:a.name,style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:a.name}),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:jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},a.id)})}),l&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:i.mutedTextColor},children:[jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"spin 1s linear infinite"},children:jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsx("span",{children:h("input.uploadingFiles")})]}),jsx("div",{style:{...s?{paddingLeft:"40px"}:{paddingRight:"40px"},display:"flex",alignItems:"center"},children:jsx("textarea",{ref:n,"aria-label":h("input.prompt"),rows:1,placeholder:h("input.placeholder"),value:e,onChange:a=>t(a.target.value),onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),x());},disabled:l,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:s?"rtl":"ltr",textAlign:s?"right":"left"}})})]}),jsx("div",{style:{position:"absolute",bottom:"8px",...s?{left:"8px"}:{right:"8px"}},children:o?jsx("button",{onClick:I,disabled:!c,"aria-label":h("input.stop"),style:{borderRadius:"50%",width:"36px",height:"36px",transition:"all 0.2s ease-out",backgroundColor:i.textColor,color:i.inputBackground,border:"none",opacity:c?1:.7,cursor:c?"pointer":"not-allowed",display:"flex",alignItems:"center",justifyContent:"center"},children:jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:jsx("rect",{width:"24",height:"24",rx:"2"})})}):jsx("button",{onClick:x,disabled:!f||l,"aria-label":h("input.send"),style:{borderRadius:"50%",width:"36px",height:"36px",transition:"all 0.2s ease-out",backgroundColor:!f||l?i.cardBackground:i.textColor,color:!f||l?i.mutedTextColor:i.inputBackground,border:"none",cursor:!f||l?"default":"pointer",display:"flex",alignItems:"center",justifyContent:"center",transform:s?"rotate(180deg)":""},children:jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M5 12h14"}),jsx("path",{d:"M12 5l7 7-7 7"})]})})})]}),jsx("input",{ref:r,type:"file",multiple:true,onChange:M,style:{display:"none"},accept:"*/*"}),jsx("div",{style:{textAlign:"center",padding:"8px 0",fontSize:"12px",color:i.mutedTextColor,opacity:.8},children:"AI can make mistakes. Please check important information."})]}):jsx("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px",paddingTop:"4px"},children:jsx("div",{style:{position:"relative",flex:1},children:jsxs("div",{style:{position:"relative",width:"100%",borderRadius:"16px",paddingBottom:"48px",paddingTop:"16px",border:`1px solid ${i.borderColor}`,backgroundColor:i.cardBackground},children:[m.length>0&&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 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:[jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",borderRadius:"4px",backgroundColor:T?"transparent":i.cardBackground},children:T?jsx("img",{src:a.url,alt:a.name,style:{width:"20px",height:"20px",borderRadius:"4px",objectFit:"cover"}}):jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("rect",{x:"4",y:"4",width:"16",height:"20",rx:"2",ry:"2"})})}),jsxs("div",{style:{display:"flex",flexDirection:"column",minWidth:0,flex:1},children:[jsx("span",{title:a.name,style:{maxWidth:"140px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:a.name}),jsx("span",{style:{color:i.mutedTextColor,fontSize:"10px",marginTop:"2px"},children:u(a.size)})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginLeft:"8px"},children:[T&&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:h("input.previewImage"),children:jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),jsx("button",{onClick:()=>C(a.id),style:{background:"none",border:"none",color:i.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px"},title:h("input.removeFile"),children:jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]},a.id)})}),l&&jsxs("div",{style:{padding:"0px 16px 12px 16px",display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:i.mutedTextColor},children:[jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"spin 1s linear infinite"},children:jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsx("span",{children:h("input.uploadingFiles")})]}),jsx("div",{style:{padding:"0 16px"},children:jsx("textarea",{ref:n,"aria-label":h("input.prompt"),rows:1,placeholder:h("input.placeholder"),value:e,onChange:a=>t(a.target.value),onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),x());},disabled:l,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:s?"rtl":"ltr",textAlign:s?"right":"left"}})}),jsx("input",{ref:r,type:"file",multiple:true,onChange:M,style:{display:"none"},accept:"*/*"}),jsx("div",{style:{position:"absolute",bottom:"8px",...s?{right:"8px"}:{left:"8px"},display:"flex",alignItems:"center",gap:"4px",color:i.mutedTextColor},children:jsx("button",{onClick:()=>r.current?.click(),disabled:o||l,style:{borderRadius:"8px",padding:"8px",transition:"all 0.2s",backgroundColor:"transparent",border:"none",cursor:o||l?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"inherit",opacity:o||l?.5:1},"aria-label":h("input.attachFiles"),children:jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 1 1 5.66 5.66l-9.2 9.19a2 2 0 1 1-2.83-2.83l8.49-8.49"})})})}),jsx("div",{style:{position:"absolute",bottom:"8px",...s?{left:"8px"}:{right:"8px"}},children:o?jsx("button",{onClick:I,disabled:!c,"aria-label":h("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:c?1:.4,cursor:c?"pointer":"not-allowed",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:a=>{c&&(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:jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"})})}):jsx("button",{onClick:x,disabled:!f||l,"aria-label":h("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:!f||l?i.mutedTextColor:i.primaryColor,cursor:!f||l?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",opacity:!f||l?.5:1},onMouseEnter:a=>{f&&!l&&(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:jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"m5 12 7-7 7 7"}),jsx("path",{d:"M12 19V5"})]})})})]})})})}function qt({prompts:e,onSelect:t,resolvedColors:n,disabled:r=false,dir:o="ltr",t:l}){let[m,u]=useState(null),C=o==="rtl";return !e||e.length===0?null:jsxs("div",{style:{padding:"12px 0",display:"flex",flexDirection:"column",gap:"8px",direction:C?"rtl":"ltr"},children:[jsx("div",{style:{fontSize:"12px",fontWeight:600,color:n.mutedTextColor,...C?{paddingRight:"4px",textAlign:"right"}:{paddingLeft:"4px",textAlign:"left"},textTransform:"uppercase",letterSpacing:"0.5px"},children:l?l("prompts.suggested"):"Suggested Prompts"}),jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((M,x)=>{let I=m===x,k=M.prompt.length>180,h=k&&!I?M.prompt.slice(0,180)+"...":M.prompt;return jsxs("button",{onClick:()=>{r||t(M.prompt);},disabled:r,style:{display:"flex",flexDirection:"column",padding:"12px",backgroundColor:n.cardBackground,border:`1px solid ${n.borderColor}`,borderRadius:"12px",cursor:r?"not-allowed":"pointer",transition:"all 0.2s ease",textAlign:C?"right":"left",opacity:r?.5:1,position:"relative",overflow:"hidden"},onMouseEnter:i=>{r||(i.currentTarget.style.backgroundColor=n.hoverBackground,i.currentTarget.style.borderColor=n.primaryColor,i.currentTarget.style.transform=C?"translateX(-2px)":"translateX(2px)");},onMouseLeave:i=>{i.currentTarget.style.backgroundColor=n.cardBackground,i.currentTarget.style.borderColor=n.borderColor,i.currentTarget.style.transform="translateX(0)";},children:[jsxs("div",{style:{fontSize:"13px",fontWeight:600,color:n.textColor,marginBottom:"6px",display:"flex",alignItems:"center",gap:"6px"},children:[jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:n.primaryColor,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[jsx("path",{d:"M12 20h9"}),jsx("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]}),M.label]}),jsx("div",{style:{fontSize:"12px",color:n.mutedTextColor,lineHeight:"1.5",width:"100%",wordWrap:"break-word",whiteSpace:"pre-wrap",direction:C?"rtl":"ltr",textAlign:C?"right":"left"},children:h}),k&&jsxs("button",{onClick:i=>{i.stopPropagation(),u(I?null:x);},style:{marginTop:"8px",padding:"4px 8px",fontSize:"11px",color:n.primaryColor,backgroundColor:"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",gap:"4px",fontWeight:500},children:[I?l?l("prompts.showLess"):"Show less":l?l("prompts.showMore"):"Show more",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:jsx("polyline",{points:"6 9 12 15 18 9"})})]})]},x)})})]})}function lo(e){let t=Date.now()-e,n=Math.max(1,Math.floor(t/1e3));if(n<60)return `${n}s`;let r=Math.floor(n/60);if(r<60)return `${r}m`;let o=Math.floor(r/60);if(o<24)return `${o}h`;let l=Math.floor(o/24);if(l<7)return `${l}d`;let m=Math.floor(l/7);if(m<4)return `${m}w`;let u=Math.floor(l/30);return u<12?`${u}mo`:`${Math.floor(u/12)}y`}function xt({search:e,onSearchChange:t,chats:n,currentChatId:r,resolvedColors:o,onChatSelect:l,onChatDelete:m,className:u,style:C,dir:M="ltr",t:x}){let I=M==="rtl",k=e.trim()?n.filter(h=>(h.title||"").toLowerCase().includes(e.toLowerCase().trim())):n;return jsxs("div",{className:u,style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden",direction:I?"rtl":"ltr",...C},children:[jsx("div",{style:{display:"flex",alignItems:"center",gap:"12px",borderBottom:`1px solid ${o.borderColor}`,padding:"12px 16px",flexShrink:0},children:jsx("div",{style:{flex:"1"},children:jsx("input",{value:e,onChange:h=>t(h.target.value),placeholder:x?x("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:h=>h.currentTarget.style.borderColor=o.primaryColor,onBlur:h=>h.currentTarget.style.borderColor=o.borderColor})})}),jsx("div",{style:{flex:1,overflowY:"auto",padding:"0"},children:k.length===0?jsx("div",{style:{padding:"24px",color:o.mutedTextColor,textAlign:"center"},children:x?x("history.noChatsFound"):"No chats found."}):jsx("div",{children:k.map((h,i)=>jsx("div",{style:{borderTop:i>0?`1px solid ${o.borderColor}`:"none"},children:jsxs("div",{style:{display:"flex",width:"100%",alignItems:"center",justifyContent:"space-between",gap:"12px",padding:"8px 12px",backgroundColor:h.id===r?o.cardBackground:"transparent",transition:"background-color 0.2s"},children:[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:()=>l(h.id),children:jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"12px"},children:[jsx("div",{style:{minWidth:"0",flex:"1"},children:jsx("div",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"14px",color:o.textColor,fontWeight:h.id===r?600:400},children:h.title||(x?x("history.untitledChat"):"Untitled chat")})}),jsx("div",{style:{flexShrink:0,fontSize:"12px",color:o.mutedTextColor},children:lo(h.updatedAt)})]})}),jsx("button",{style:{flexShrink:0,borderRadius:"6px",padding:"8px",color:o.mutedTextColor,border:"1px solid transparent",backgroundColor:"transparent",cursor:"pointer",transition:"all 0.2s"},title: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=o.mutedTextColor,b.currentTarget.style.backgroundColor="transparent",b.currentTarget.style.borderColor="transparent";},onClick:b=>{b.stopPropagation(),m(h.id);},children:jsx(X,{IconComponent:Trash2,size:"16",strokeWidth:"2"})})]})},h.id))})})]})}function Xt({historyOpen:e,historySearch:t,currentChatId:n,refreshKey:r,resolvedColors:o,onClose:l,onSearchChange:m,onChatSelect:u,onChatDelete:C,loadChatsIndex:M,historyPopupRef:x,dir:I="ltr",t:k}){if(!e)return null;let h=M(),i=jsxs(Fragment,{children:[jsx("div",{style:{position:"fixed",inset:"0",zIndex:1100,backgroundColor:"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)"},onClick:l}),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 ${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:jsx(xt,{search:t,onSearchChange:m,chats:h,currentChatId:n,resolvedColors:o,onChatSelect:u,onChatDelete:C,dir:I,t:k})})]});return typeof document<"u"&&document.body?createPortal(i,document.body):i}function uo({isOpen:e,historySearch:t,onSearchChange:n,chats:r,currentChatId:o,resolvedColors:l,onChatSelect:m,onChatDelete:u,onNewChat:C,isMobile:M=false,dir:x="ltr",t:I}){let k=x==="rtl";return jsxs("div",{style:{width:e?"260px":"0px",opacity:e?1:0,...k?{marginRight:e?0:-10}:{marginLeft:e?0:-10},height:"100%",backgroundColor:l.backgroundColor,...k?{borderLeft:e?`1px solid ${l.borderColor}`:"none"}:{borderRight:e?`1px solid ${l.borderColor}`:"none"},display:"flex",flexDirection:"column",transition:"all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",overflow:"hidden",flexShrink:0,position:M?"fixed":"relative",zIndex:M?100:1,...k?{right:0}:{left:0},top:0,bottom:0,visibility:e?"visible":"hidden",direction:k?"rtl":"ltr"},children:[jsx("div",{style:{padding:"12px",flexShrink:0,opacity:e?1:0,transition:"opacity 0.2s 0.1s"},children:jsxs("button",{onClick:C,style:{width:"100%",display:"flex",alignItems:"center",gap:"12px",padding:"10px 12px",borderRadius:"8px",border:`1px solid ${l.borderColor}`,backgroundColor:"transparent",color:l.textColor,cursor:"pointer",fontSize:"14px",transition:"all 0.2s",textAlign:k?"right":"left"},onMouseEnter:h=>h.currentTarget.style.backgroundColor=l.hoverBackground,onMouseLeave:h=>h.currentTarget.style.backgroundColor="transparent",children:[jsx(X,{IconComponent:Plus,size:"16",strokeWidth:"2"}),jsx("span",{children:I?I("history.newChat"):"New chat"})]})}),jsx(xt,{search:t,onSearchChange:n,chats:r,currentChatId:o,resolvedColors:l,onChatSelect:m,onChatDelete:u,dir:x,t:I,style:{flex:1}})]})}function Yt({isOpen:e,resolvedColors:t,onConfirm:n,onCancel:r,editProcessContent:o,dir:l="ltr",t:m}){if(!e)return null;let u=o?.title||(m?m("editModal.title"):"Edit Message"),C=o?.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?"),M=o?.submit_button_label||(m?m("editModal.submit"):"Edit"),x=o?.cancel_button_label||(m?m("editModal.cancel"):"Cancel"),I=o?.icon,k=typeof C=="function",h=k?C:null,i=jsxs(Fragment,{children:[jsx("div",{style:{position:"fixed",inset:"0",zIndex:1100,backgroundColor:"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)"},onClick:r}),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:l==="rtl"?"rtl":"ltr"},children:[jsxs("div",{style:{padding:"20px 24px",borderBottom:`1px solid ${t.borderColor}`,display:"flex",alignItems:"center",gap:"12px"},children:[I?jsx("div",{style:{flexShrink:0},children:jsx(X,{IconComponent:I,size:"20",strokeWidth:"2"})}):jsx("div",{style:{flexShrink:0,color:t.mutedTextColor},children:jsx(X,{IconComponent:Pencil,size:"20",strokeWidth:"2"})}),jsx("h3",{style:{margin:0,fontSize:"18px",fontWeight:"600",color:t.textColor,flex:1},children:u})]}),jsx("div",{style:{padding:"24px",color:t.textColor,fontSize:"14px",lineHeight:"1.6"},children:k&&h?jsx(h,{}):jsx("p",{style:{margin:0},children:C})}),jsxs("div",{style:{display:"flex",gap:"12px",padding:"16px 24px",borderTop:`1px solid ${t.borderColor}`,justifyContent:"flex-end"},children:[jsx("button",{onClick:r,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}),jsx("button",{onClick:n,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:M})]})]})]});return typeof document<"u"&&document.body?createPortal(i,document.body):i}function Hr({agentId:e,theme:t,primaryColor:n,primaryColorDark:r,primaryColorLight:o,backgroundColor:l,borderColor:m,textColor:u,accentColor:C,dir:M,lang:x,language:I,baseUrl:k="",initialMessages:h=[],onMessagesChange:i,defaultOpen:b=true,floatingButtonPosition:d={bottom:24,right:24},HsafaTools:c={},HsafaUI:f={},componentAboveInput:s,editProcessContent:a,presetPrompts:T,onStart:w,onFinish:v,currentChat:y,onChatChanged:S,templateParams:p,fullPageChat:B=false,title:W,placeholder:j,emptyStateMessage:ne}){let {dir:ye,theme:me,baseUrl:_,setStreamingState:U,setChatOpenState:q}=se(),O=M||ye||"ltr",J=x||I||"en",oe=J==="ar",Z=t||me||"dark",ge=k&&k.length>0?k:_||"",A={primaryColor:Z==="dark"?r||n||"#ffffff":o||n||"#000000",backgroundColor:l||(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"},P=g=>{let H={"header.new":"New","header.history":"History","header.close":"Close chat","input.placeholder":j||"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":ne||"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 (oe?{"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":j||"\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":ne||"\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."}:H)[g]||H[g]||g},kt=Nt({agentId:e,baseUrl:ge,tools:c,uiComponents:f,templateParams:p,controlledChatId:y,onChatIdChange:y===void 0?g=>{S&&S(g);}:void 0,onStart:useCallback(g=>{w&&w(g);},[w]),onFinish:useCallback(g=>{v&&v(g);},[v]),onError:useCallback(g=>{console.error("Chat error:",g);},[]),initialMessages:h,onMessagesChange:i}),{input:ve,setInput:fe,messages:E,isLoading:L,status:G,error:$,sendMessage:ee,stop:te,setMessages:K,notifyMessagesChange:tt,chatId:$e,setChatId:nt,tools:Wr,uiComponents:Qt,formHostRef:Ur,formStateRef:Or,cleanupForms:ze,onUISuccess:en,onUIError:tn,chatApi:nn}=kt,V=y!==void 0?y:$e,ke=useCallback(g=>{y===void 0&&nt(g),S&&S(g);},[y,nt,S]);useEffect(()=>{y!==void 0&&y!==$e&&nt(y);},[y,$e,nt]);let{attachments:Ne,uploading:on,fileInputRef:We,formatBytes:rn,handleRemoveAttachment:an,handleFileSelection:sn,clearAttachments:ot,setAttachments:ln}=Bn(ge),[rt,we]=useState(null),[at,cn]=useState(()=>{try{return pt(e).loadShowChatPreference(!!b)}catch{return !!b}}),[wt,Ee]=useState(false),[Tt,It]=useState(""),[St,Mt]=useState(0),dn=useRef(null),un=useRef(null),[pn,mn]=useState(new Set),[gn,Et]=useState(false),[Ue,Rt]=useState(null),Oe=useRef(null),fn=An(L),[hn,fo]=useState(false);useEffect(()=>{let g=()=>fo(window.innerWidth<768);return g(),window.addEventListener("resize",g),()=>window.removeEventListener("resize",g)},[]);let At=Ut({agentId:e,chatId:V,messages:E,isLoading:L,autoSave:true,autoRestore:false}),z=At.storage,yn=useMemo(()=>{try{return z.loadChatsIndex()}catch{return []}},[z,St]),Ge=useRef(false),je=useRef(null);useEffect(()=>{if(!Ge.current){if(y!==void 0){try{let g=z.loadChat(y),H=g&&Array.isArray(g.messages)?g.messages:[];if(H.length>0)try{K(H);}catch{}je.current=y;}catch{}try{z.saveCurrentChatId(y);}catch{}Ge.current=true;return}try{let g=z.loadCurrentChatId();if(g){ke(g);let H=z.loadChat(g),D=H&&Array.isArray(H.messages)?H.messages:[];try{K(D);}catch{}je.current=g;}}catch{}Ge.current=true;}},[y]),useEffect(()=>{if(Ge.current&&y!==void 0&&y!==je.current)try{let g=z.loadChat(y),H=g&&Array.isArray(g.messages)?g.messages:[];try{K(H);}catch{}je.current=y;try{z.saveCurrentChatId(y);}catch{}}catch{}},[y,z,K]),useEffect(()=>{if(Ge.current)try{z.saveCurrentChatId(V);}catch{}},[V,z]),useEffect(()=>{try{U(V,L);}catch{}return ()=>{try{U(V,!1);}catch{}}},[V,L,U]),useEffect(()=>{try{q(V,at);}catch{}return ()=>{try{q(V,!1);}catch{}}},[V,at,q]);let xn=useCallback(async()=>{let g=ve.trim();if(!g&&Ne.length===0||L)return;let H=[...Ne];fe(""),ot(),we(null),Oe.current&&Oe.current.focus();try{await ee({text:g,files:H.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),we(P("error.failedSend"));}},[ve,Ne,L,ee,ot,P]),Re=useCallback(()=>{if(L)return;ze(),fe(""),ot(),we(null);try{K([]);}catch{}let g=`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`;je.current=g;try{At.createNewChat(()=>{ke(g);try{z.saveCurrentChatId(g);}catch{}});}catch{ke(g);try{z.saveCurrentChatId(g);}catch{}}},[L,ot,z,K,ke,ze,At]),bn=useCallback(()=>{Ee(g=>!g);},[]),ho=useCallback(()=>{cn(false);try{z.saveShowChatPreference(!1);}catch{}},[z]),Cn=useCallback(async g=>{let H=g.target.files;H&&await sn(H,we),We.current&&(We.current.value="");},[sn,We]);useEffect(()=>{let g=Oe.current;if(!g)return;g.style.height="24px",g.offsetHeight,g.style.height="auto";let H=Math.min(g.scrollHeight,200);g.style.height=`${H}px`;},[ve]);let vn=useCallback((g,H,D,In)=>{Rt({id:H,text:D,attachments:In||[]}),Et(true);},[]),kn=useCallback(()=>{if(!(!Ue||L))try{let g=E.findIndex(D=>D.id===Ue.id);if(g===-1)return;let H=E.slice(0,g);try{K(H);}catch{}fe(Ue.text),ln(Ue.attachments),Et(!1),Rt(null),tt();}catch(g){console.error("Failed to edit message:",g),we(P("error.failedEdit"));}},[Ue,L,E,K,ln,tt,P]),wn=useCallback(()=>{Et(false),Rt(null);},[]),yo=jsxs("div",{style:{position:"fixed",inset:0,display:"flex",backgroundColor:A.backgroundColor,color:A.textColor,overflow:"hidden"},children:[!hn&&jsx(uo,{isOpen:wt,historySearch:Tt,onSearchChange:It,chats:yn,currentChatId:V,resolvedColors:A,dir:O,t:P,onChatSelect:g=>{if(g&&g!==V&&(ze(),ke(g),y===void 0)){try{z.saveCurrentChatId(g);}catch{}try{let H=z.loadChat(g),D=H&&Array.isArray(H.messages)?H.messages:[];try{K(D);}catch{}}catch{}}},onChatDelete:g=>{try{z.deleteChat(g),Mt(H=>H+1),g===V&&Re();}catch{}},onNewChat:Re,onClose:()=>Ee(false)}),jsxs("div",{style:{display:"flex",flexDirection:"column",flex:1,minWidth:0,position:"relative"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 20px",backgroundColor:A.backgroundColor,minHeight:"60px",zIndex:10},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[jsx("button",{ref:dn,onClick:bn,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":P("header.history"),children:jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),jsx("h1",{style:{fontSize:"16px",fontWeight:600,margin:0,color:A.textColor},children:P("general.agent")})]}),jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:jsx("button",{onClick:Re,disabled:L,style:{padding:"8px",borderRadius:"8px",border:"none",backgroundColor:"transparent",color:A.mutedTextColor,cursor:L?"not-allowed":"pointer",transition:"all 0.2s",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:g=>{L||(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":P("header.new"),children:jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:"M12 5v14M5 12h14"})})})})]}),jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},children:[jsx("div",{ref:fn,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:jsx("div",{style:{maxWidth:"768px",width:"100%",margin:"0 auto",padding:"32px 24px",display:"flex",flexDirection:"column",gap:"24px"},children:E.length===0?jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px",padding:"64px 0"},children:T&&T.length>0?jsx(qt,{prompts:T,onSelect:g=>fe(g),resolvedColors:A,disabled:L,dir:O,t:P}):jsx("div",{style:{padding:"64px 32px",textAlign:"center",color:A.mutedTextColor,fontSize:"16px"},children:P("messages.empty")})}):jsx(jt,{chatMessages:E,isLoading:L,openReasoningIds:pn,toggleReasoning:g=>mn(H=>{let D=new Set(H);return D.has(g)?D.delete(g):D.add(g),D}),resolvedColors:A,t:P,onUserMessageClick:vn,HsafaUI:Qt,onUIError:tn,onUISuccess:en,addToolResult:g=>nn?.addToolResult?.(g),editableMessageIcon:a?.message_icon,fullPage:true,dir:O})})}),jsx("div",{style:{backgroundColor:A.backgroundColor,padding:"0 24px 24px",position:"relative",zIndex:20},children:jsxs("div",{style:{maxWidth:"768px",width:"100%",margin:"0 auto"},children:[s&&po.createElement(s,{}),rt&&jsxs("div",{style:{padding:"12px 16px",marginBottom:"12px",backgroundColor:"#ef4444",color:"#fff",borderRadius:"8px",fontSize:"14px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsx("span",{children:rt}),jsx("button",{onClick:()=>we(null),style:{background:"none",border:"none",color:"#fff",cursor:"pointer",padding:"2px",fontSize:"20px"},children:"\xD7"})]}),$&&jsxs("div",{style:{padding:"12px 16px",marginBottom:"12px",backgroundColor:"#ef4444",color:"#fff",borderRadius:"8px",fontSize:"14px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxs("span",{children:[P("error.occurred")," ",$.message||P("error.tryAgain")]}),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:P("error.refresh")})]}),jsx(_t,{input:ve,setInput:fe,textareaRef:Oe,fileInputRef:We,isLoading:L,uploading:on,attachments:Ne,formatBytes:rn,handleRemoveAttachment:an,onFileInputChange:Cn,onSend:xn,onStop:()=>te(),status:G,t:P,resolvedColors:A,fullPage:true,dir:O})]})})]})]}),hn&&jsx(Xt,{historyOpen:wt,historySearch:Tt,currentChatId:V,refreshKey:St,resolvedColors:A,onClose:()=>Ee(false),onSearchChange:It,dir:O,t:P,onChatSelect:g=>{if(Ee(false),g&&g!==V&&(ze(),ke(g),y===void 0)){try{z.saveCurrentChatId(g);}catch{}try{let H=z.loadChat(g),D=H&&Array.isArray(H.messages)?H.messages:[];try{K(D);}catch{}}catch{}}},onChatDelete:g=>{try{z.deleteChat(g),Mt(H=>H+1),g===V&&Re();}catch{}},loadChatsIndex:()=>yn,historyPopupRef:un}),jsx(Yt,{isOpen:gn,resolvedColors:A,t:P,editProcessContent:a,onConfirm:kn,onCancel:wn,dir:O,lang:J}),jsx("style",{children:`
|
|
183
|
+
`}),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 jsx("div",{style:{padding:"0 4px",display:"flex",flexDirection:"column",alignItems:i.role==="user"&&k?"flex-end":"stretch"},children:i.role==="user"?jsx("div",{style:{maxWidth:k?"80%":"100%"},children: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:jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxs("div",{style:{flex:1},children:[d,h.length>0&&jsx(ln,{attachments:h,resolvedColors:n})]}),jsx("div",{style:{flexShrink:0,opacity:.5,transition:"opacity 0.2s"},children:jsx(X,{IconComponent:S||Pencil,size:"14",strokeWidth:"2"})})]})})}):jsx(nn,{parts:c,messageId:i.id,openReasoningIds:r,toggleReasoning:o,resolvedColors:n,HsafaUI:u,onUIError:C,onUISuccess:I,addToolResult:x,dir:f,t:s})},i.id)}),t&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",padding:"0 4px",height:"20px"},children:[jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:n.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0s"}}),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"}}),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:I,onSend:x,onStop:S,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?jsxs("div",{style:{position:"relative",width:"100%",maxWidth:"768px",margin:"0 auto"},children:[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:[jsx("div",{style:{position:"absolute",bottom:"10px",...l?{right:"12px"}:{left:"12px"},zIndex:10},children: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:jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:"M12 5v14M5 12h14"})})})}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[m.length>0&&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 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:[jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",borderRadius:"4px",backgroundColor:T?"transparent":i.inputBackground},children:T?jsx("img",{src:a.url,alt:a.name,style:{width:"20px",height:"20px",borderRadius:"4px",objectFit:"cover"}}):jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("rect",{x:"4",y:"4",width:"16",height:"20",rx:"2",ry:"2"})})}),jsx("span",{title:a.name,style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:a.name}),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:jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},a.id)})}),s&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:i.mutedTextColor},children:[jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"spin 1s linear infinite"},children:jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsx("span",{children:f("input.uploadingFiles")})]}),jsx("div",{style:{...l?{paddingLeft:"40px"}:{paddingRight:"40px"},display:"flex",alignItems:"center"},children: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"}})})]}),jsx("div",{style:{position:"absolute",bottom:"8px",...l?{left:"8px"}:{right:"8px"}},children:n?jsx("button",{onClick:S,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:jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:jsx("rect",{width:"24",height:"24",rx:"2"})})}):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:jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M5 12h14"}),jsx("path",{d:"M12 5l7 7-7 7"})]})})})]}),jsx("input",{ref:o,type:"file",multiple:true,onChange:I,style:{display:"none"},accept:"*/*"}),jsx("div",{style:{textAlign:"center",padding:"8px 0",fontSize:"12px",color:i.mutedTextColor,opacity:.8},children:"AI can make mistakes. Please check important information."})]}):jsx("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px",paddingTop:"4px"},children:jsx("div",{style:{position:"relative",flex:1},children:jsxs("div",{style:{position:"relative",width:"100%",borderRadius:"16px",paddingBottom:"48px",paddingTop:"16px",border:`1px solid ${i.borderColor}`,backgroundColor:i.cardBackground},children:[m.length>0&&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 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:[jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",borderRadius:"4px",backgroundColor:T?"transparent":i.cardBackground},children:T?jsx("img",{src:a.url,alt:a.name,style:{width:"20px",height:"20px",borderRadius:"4px",objectFit:"cover"}}):jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsx("rect",{x:"4",y:"4",width:"16",height:"20",rx:"2",ry:"2"})})}),jsxs("div",{style:{display:"flex",flexDirection:"column",minWidth:0,flex:1},children:[jsx("span",{title:a.name,style:{maxWidth:"140px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:a.name}),jsx("span",{style:{color:i.mutedTextColor,fontSize:"10px",marginTop:"2px"},children:u(a.size)})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginLeft:"8px"},children:[T&&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:jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),jsx("button",{onClick:()=>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:jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]},a.id)})}),s&&jsxs("div",{style:{padding:"0px 16px 12px 16px",display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:i.mutedTextColor},children:[jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"spin 1s linear infinite"},children:jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsx("span",{children:f("input.uploadingFiles")})]}),jsx("div",{style:{padding:"0 16px"},children:jsx("textarea",{ref: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"}})}),jsx("input",{ref:o,type:"file",multiple:true,onChange:I,style:{display:"none"},accept:"*/*"}),jsx("div",{style:{position:"absolute",bottom:"8px",...l?{right:"8px"}:{left:"8px"},display:"flex",alignItems:"center",gap:"4px",color:i.mutedTextColor},children: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:jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 1 1 5.66 5.66l-9.2 9.19a2 2 0 1 1-2.83-2.83l8.49-8.49"})})})}),jsx("div",{style:{position:"absolute",bottom:"8px",...l?{left:"8px"}:{right:"8px"}},children:n?jsx("button",{onClick:S,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:jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"})})}):jsx("button",{onClick: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:jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"m5 12 7-7 7 7"}),jsx("path",{d:"M12 19V5"})]})})})]})})})}function Kt({prompts:e,onSelect:t,resolvedColors:r,disabled:o=false,dir:n="ltr",t:s}){let[m,u]=useState(null),C=n==="rtl";return !e||e.length===0?null:jsxs("div",{style:{padding:"12px 0",display:"flex",flexDirection:"column",gap:"8px",direction:C?"rtl":"ltr"},children:[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"}),jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((I,x)=>{let S=m===x,k=I.prompt.length>180,f=k&&!S?I.prompt.slice(0,180)+"...":I.prompt;return jsxs("button",{onClick:()=>{o||t(I.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:[jsxs("div",{style:{fontSize:"13px",fontWeight:600,color:r.textColor,marginBottom:"6px",display:"flex",alignItems:"center",gap:"6px"},children:[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:[jsx("path",{d:"M12 20h9"}),jsx("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]}),I.label]}),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&&jsxs("button",{onClick:i=>{i.stopPropagation(),u(S?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:[S?s?s("prompts.showLess"):"Show less":s?s("prompts.showMore"):"Show more",jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:S?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.2s"},children: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:I="ltr",t:x}){let S=I==="rtl",k=e.trim()?r.filter(f=>(f.title||"").toLowerCase().includes(e.toLowerCase().trim())):r;return jsxs("div",{className:u,style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden",direction:S?"rtl":"ltr",...C},children:[jsx("div",{style:{display:"flex",alignItems:"center",gap:"12px",borderBottom:`1px solid ${n.borderColor}`,padding:"12px 16px",flexShrink:0},children:jsx("div",{style:{flex:"1"},children: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:S?"rtl":"ltr",textAlign:S?"right":"left"},onFocus:f=>f.currentTarget.style.borderColor=n.primaryColor,onBlur:f=>f.currentTarget.style.borderColor=n.borderColor})})}),jsx("div",{style:{flex:1,overflowY:"auto",padding:"0"},children:k.length===0?jsx("div",{style:{padding:"24px",color:n.mutedTextColor,textAlign:"center"},children:x?x("history.noChatsFound"):"No chats found."}):jsx("div",{children:k.map((f,i)=>jsx("div",{style:{borderTop:i>0?`1px solid ${n.borderColor}`:"none"},children: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:[jsx("button",{style:{flex:"1",textAlign:S?"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:jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"12px"},children:[jsx("div",{style:{minWidth:"0",flex:"1"},children:jsx("div",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"14px",color:n.textColor,fontWeight:f.id===o?600:400},children:f.title||(x?x("history.untitledChat"):"Untitled chat")})}),jsx("div",{style:{flexShrink:0,fontSize:"12px",color:n.mutedTextColor},children:dn(f.updatedAt)})]})}),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:jsx(X,{IconComponent: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:I,historyPopupRef:x,dir:S="ltr",t:k}){if(!e)return null;let f=I(),i=jsxs(Fragment,{children:[jsx("div",{style:{position:"fixed",inset:"0",zIndex:1100,backgroundColor:"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)"},onClick:s}),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:jsx(xt,{search:t,onSearchChange:m,chats:f,currentChatId:r,resolvedColors:n,onChatSelect:u,onChatDelete:C,dir:S,t:k})})]});return typeof document<"u"&&document.body?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:I=false,dir:x="ltr",t:S}){let k=x==="rtl";return 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:I?"fixed":"relative",zIndex:I?100:1,...k?{right:0}:{left:0},top:0,bottom:0,visibility:e?"visible":"hidden",direction:k?"rtl":"ltr"},children:[jsx("div",{style:{padding:"12px",flexShrink:0,opacity:e?1:0,transition:"opacity 0.2s 0.1s"},children: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:[jsx(X,{IconComponent:Plus,size:"16",strokeWidth:"2"}),jsx("span",{children:S?S("history.newChat"):"New chat"})]})}),jsx(xt,{search:t,onSearchChange:r,chats:o,currentChatId:n,resolvedColors:s,onChatSelect:m,onChatDelete:u,dir:x,t:S,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?"),I=n?.submit_button_label||(m?m("editModal.submit"):"Edit"),x=n?.cancel_button_label||(m?m("editModal.cancel"):"Cancel"),S=n?.icon,k=typeof C=="function",f=k?C:null,i=jsxs(Fragment,{children:[jsx("div",{style:{position:"fixed",inset:"0",zIndex:1100,backgroundColor:"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)"},onClick:o}),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:[jsxs("div",{style:{padding:"20px 24px",borderBottom:`1px solid ${t.borderColor}`,display:"flex",alignItems:"center",gap:"12px"},children:[S?jsx("div",{style:{flexShrink:0},children:jsx(X,{IconComponent:S,size:"20",strokeWidth:"2"})}):jsx("div",{style:{flexShrink:0,color:t.mutedTextColor},children:jsx(X,{IconComponent:Pencil,size:"20",strokeWidth:"2"})}),jsx("h3",{style:{margin:0,fontSize:"18px",fontWeight:"600",color:t.textColor,flex:1},children:u})]}),jsx("div",{style:{padding:"24px",color:t.textColor,fontSize:"14px",lineHeight:"1.6"},children:k&&f?jsx(f,{}):jsx("p",{style:{margin:0},children:C})}),jsxs("div",{style:{display:"flex",gap:"12px",padding:"16px 24px",borderTop:`1px solid ${t.borderColor}`,justifyContent:"flex-end"},children:[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}),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:I})]})]})]});return typeof document<"u"&&document.body?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:I,lang:x,language:S,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:M,templateParams:p,fullPageChat:B=false,title:W,placeholder:j,emptyStateMessage:re}){let {dir:ye,theme:me,baseUrl:_,setStreamingState:U,setChatOpenState:q}=se(),O=I||ye||"ltr",J=x||S||"en",ne=J==="ar",Z=t||me||"dark",ge=k&&k.length>0?k:_||"",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"},P=g=>{let H={"header.new":"New","header.history":"History","header.close":"Close chat","input.placeholder":j||"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":re||"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 (ne?{"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":j||"\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":re||"\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."}:H)[g]||H[g]||g},kt=Wt({agentId:e,baseUrl:ge,tools:d,uiComponents:h,templateParams:p,controlledChatId:y,onChatIdChange:y===void 0?g=>{M&&M(g);}:void 0,onStart:useCallback(g=>{w&&w(g);},[w]),onFinish:useCallback(g=>{v&&v(g);},[v]),onError:useCallback(g=>{console.error("Chat error:",g);},[]),initialMessages:f,onMessagesChange:i}),{input:ve,setInput:fe,messages:E,isLoading:L,status:G,error:z,sendMessage:ee,stop:te,setMessages:K,notifyMessagesChange:tt,chatId:ze,setChatId:rt,tools:Uo,uiComponents:er,formHostRef:Oo,formStateRef:Go,cleanupForms:$e,onUISuccess:tr,onUIError:rr,chatApi:nr}=kt,V=y!==void 0?y:ze,ke=useCallback(g=>{y===void 0&&rt(g),M&&M(g);},[y,rt,M]);useEffect(()=>{y!==void 0&&y!==ze&&rt(y);},[y,ze,rt]);let{attachments:Ne,uploading:or,fileInputRef:We,formatBytes:ar,handleRemoveAttachment:ir,handleFileSelection:sr,clearAttachments:nt,setAttachments:lr}=Br(ge),[ot,we]=useState(null),[at,dr]=useState(()=>{try{return pt(e).loadShowChatPreference(!!b)}catch{return !!b}}),[wt,Ee]=useState(false),[Tt,It]=useState(""),[St,Mt]=useState(0),cr=useRef(null),ur=useRef(null),[pr,mr]=useState(new Set),[gr,Et]=useState(false),[Ue,Rt]=useState(null),Oe=useRef(null),fr=Ar(L),[hr,fn]=useState(false);useEffect(()=>{let g=()=>fn(window.innerWidth<768);return g(),window.addEventListener("resize",g),()=>window.removeEventListener("resize",g)},[]);let At=Ot({agentId:e,chatId:V,messages:E,isLoading:L,autoSave:true,autoRestore:false}),$=At.storage,yr=useMemo(()=>{try{return $.loadChatsIndex()}catch{return []}},[$,St]),Ge=useRef(false),je=useRef(null);useEffect(()=>{if(!Ge.current){if(y!==void 0){try{let g=$.loadChat(y),H=g&&Array.isArray(g.messages)?g.messages:[];if(H.length>0)try{K(H);}catch{}je.current=y;}catch{}try{$.saveCurrentChatId(y);}catch{}Ge.current=true;return}try{let g=$.loadCurrentChatId();if(g){ke(g);let H=$.loadChat(g),D=H&&Array.isArray(H.messages)?H.messages:[];try{K(D);}catch{}je.current=g;}}catch{}Ge.current=true;}},[y]),useEffect(()=>{if(Ge.current&&y!==void 0&&y!==je.current)try{let g=$.loadChat(y),H=g&&Array.isArray(g.messages)?g.messages:[];try{K(H);}catch{}je.current=y;try{$.saveCurrentChatId(y);}catch{}}catch{}},[y,$,K]),useEffect(()=>{if(Ge.current)try{$.saveCurrentChatId(V);}catch{}},[V,$]),useEffect(()=>{try{U(V,L);}catch{}return ()=>{try{U(V,!1);}catch{}}},[V,L,U]),useEffect(()=>{try{q(V,at);}catch{}return ()=>{try{q(V,!1);}catch{}}},[V,at,q]);let xr=useCallback(async()=>{let g=ve.trim();if(!g&&Ne.length===0||L)return;let H=[...Ne];fe(""),nt(),we(null),Oe.current&&Oe.current.focus();try{await ee({text:g,files:H.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),we(P("error.failedSend"));}},[ve,Ne,L,ee,nt,P]),Re=useCallback(()=>{if(L)return;$e(),fe(""),nt(),we(null);try{K([]);}catch{}let g=`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`;je.current=g;try{At.createNewChat(()=>{ke(g);try{$.saveCurrentChatId(g);}catch{}});}catch{ke(g);try{$.saveCurrentChatId(g);}catch{}}},[L,nt,$,K,ke,$e,At]),br=useCallback(()=>{Ee(g=>!g);},[]),hn=useCallback(()=>{dr(false);try{$.saveShowChatPreference(!1);}catch{}},[$]),Cr=useCallback(async g=>{let H=g.target.files;H&&await sr(H,we),We.current&&(We.current.value="");},[sr,We]);useEffect(()=>{let g=Oe.current;if(!g)return;g.style.height="24px",g.offsetHeight,g.style.height="auto";let H=Math.min(g.scrollHeight,200);g.style.height=`${H}px`;},[ve]);let vr=useCallback((g,H,D,Ir)=>{Rt({id:H,text:D,attachments:Ir||[]}),Et(true);},[]),kr=useCallback(()=>{if(!(!Ue||L))try{let g=E.findIndex(D=>D.id===Ue.id);if(g===-1)return;let H=E.slice(0,g);try{K(H);}catch{}fe(Ue.text),lr(Ue.attachments),Et(!1),Rt(null),tt();}catch(g){console.error("Failed to edit message:",g),we(P("error.failedEdit"));}},[Ue,L,E,K,lr,tt,P]),wr=useCallback(()=>{Et(false),Rt(null);},[]),yn=jsxs("div",{style:{position:"fixed",inset:0,display:"flex",backgroundColor:A.backgroundColor,color:A.textColor,overflow:"hidden"},children:[!hr&&jsx(un,{isOpen:wt,historySearch:Tt,onSearchChange:It,chats:yr,currentChatId:V,resolvedColors:A,dir:O,t:P,onChatSelect:g=>{if(g&&g!==V&&($e(),ke(g),y===void 0)){try{$.saveCurrentChatId(g);}catch{}try{let H=$.loadChat(g),D=H&&Array.isArray(H.messages)?H.messages:[];try{K(D);}catch{}}catch{}}},onChatDelete:g=>{try{$.deleteChat(g),Mt(H=>H+1),g===V&&Re();}catch{}},onNewChat:Re,onClose:()=>Ee(false)}),jsxs("div",{style:{display:"flex",flexDirection:"column",flex:1,minWidth:0,position:"relative"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 20px",backgroundColor:A.backgroundColor,minHeight:"60px",zIndex:10},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[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":P("header.history"),children:jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),jsx("h1",{style:{fontSize:"16px",fontWeight:600,margin:0,color:A.textColor},children:P("general.agent")})]}),jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:jsx("button",{onClick:Re,disabled:L,style:{padding:"8px",borderRadius:"8px",border:"none",backgroundColor:"transparent",color:A.mutedTextColor,cursor:L?"not-allowed":"pointer",transition:"all 0.2s",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:g=>{L||(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":P("header.new"),children:jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:"M12 5v14M5 12h14"})})})})]}),jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},children:[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:jsx("div",{style:{maxWidth:"768px",width:"100%",margin:"0 auto",padding:"32px 24px",display:"flex",flexDirection:"column",gap:"24px"},children:E.length===0?jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px",padding:"64px 0"},children:T&&T.length>0?jsx(Kt,{prompts:T,onSelect:g=>fe(g),resolvedColors:A,disabled:L,dir:O,t:P}):jsx("div",{style:{padding:"64px 32px",textAlign:"center",color:A.mutedTextColor,fontSize:"16px"},children:P("messages.empty")})}):jsx(_t,{chatMessages:E,isLoading:L,openReasoningIds:pr,toggleReasoning:g=>mr(H=>{let D=new Set(H);return D.has(g)?D.delete(g):D.add(g),D}),resolvedColors:A,t:P,onUserMessageClick:vr,HsafaUI:er,onUIError:rr,onUISuccess:tr,addToolResult:g=>nr?.addToolResult?.(g),editableMessageIcon:a?.message_icon,fullPage:true,dir:O})})}),jsx("div",{style:{backgroundColor:A.backgroundColor,padding:"0 24px 24px",position:"relative",zIndex:20},children:jsxs("div",{style:{maxWidth:"768px",width:"100%",margin:"0 auto"},children:[l&&pn.createElement(l,{}),ot&&jsxs("div",{style:{padding:"12px 16px",marginBottom:"12px",backgroundColor:"#ef4444",color:"#fff",borderRadius:"8px",fontSize:"14px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsx("span",{children:ot}),jsx("button",{onClick:()=>we(null),style:{background:"none",border:"none",color:"#fff",cursor:"pointer",padding:"2px",fontSize:"20px"},children:"\xD7"})]}),z&&jsxs("div",{style:{padding:"12px 16px",marginBottom:"12px",backgroundColor:"#ef4444",color:"#fff",borderRadius:"8px",fontSize:"14px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxs("span",{children:[P("error.occurred")," ",z.message||P("error.tryAgain")]}),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:P("error.refresh")})]}),jsx(qt,{input:ve,setInput:fe,textareaRef:Oe,fileInputRef:We,isLoading:L,uploading:or,attachments:Ne,formatBytes:ar,handleRemoveAttachment:ir,onFileInputChange:Cr,onSend:xr,onStop:()=>te(),status:G,t:P,resolvedColors:A,fullPage:true,dir:O})]})})]})]}),hr&&jsx(Yt,{historyOpen:wt,historySearch:Tt,currentChatId:V,refreshKey:St,resolvedColors:A,onClose:()=>Ee(false),onSearchChange:It,dir:O,t:P,onChatSelect:g=>{if(Ee(false),g&&g!==V&&($e(),ke(g),y===void 0)){try{$.saveCurrentChatId(g);}catch{}try{let H=$.loadChat(g),D=H&&Array.isArray(H.messages)?H.messages:[];try{K(D);}catch{}}catch{}}},onChatDelete:g=>{try{$.deleteChat(g),Mt(H=>H+1),g===V&&Re();}catch{}},loadChatsIndex:()=>yr,historyPopupRef:ur}),jsx(Jt,{isOpen:gr,resolvedColors:A,t:P,editProcessContent:a,onConfirm:kr,onCancel:wr,dir:O,lang:J}),jsx("style",{children:`
|
|
27
185
|
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
|
|
28
186
|
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
|
|
29
187
|
|
|
@@ -80,7 +238,7 @@ import {jsxs,jsx,Fragment}from'react/jsx-runtime';import po,{createContext,useRe
|
|
|
80
238
|
margin: 12px 0;
|
|
81
239
|
border: 1px solid var(--hsafa-border);
|
|
82
240
|
}
|
|
83
|
-
`})]}),
|
|
241
|
+
`})]}),Tr=jsxs("div",{style:{position:"fixed",right:0,top:0,bottom:0,width:"420px",display:"flex",flexDirection:"column",padding:"24px 16px",color:A.textColor,gap:"16px",zIndex:1e3,transform:at?"translateX(0)":"translateX(100%)",transition:"transform 0.25s ease-out, width 0.2s ease-out"},children:[jsx(rn,{title:P("general.agent"),alwaysOpen:false,streaming:L,dir:O,resolvedColors:A,onNew:Re,onToggleHistory:br,onClose:hn,historyBtnRef:cr,t:P}),jsx("div",{ref:fr,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":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:E.length===0?jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px",padding:"16px 0"},children:T&&T.length>0?jsx(Kt,{prompts:T,onSelect:g=>fe(g),resolvedColors:A,disabled:L,dir:O,t:P}):jsx("div",{style:{padding:"32px",textAlign:"center",color:A.mutedTextColor,fontSize:"14px"},children:P("messages.empty")})}):jsx(_t,{chatMessages:E,isLoading:L,openReasoningIds:pr,toggleReasoning:g=>mr(H=>{let D=new Set(H);return D.has(g)?D.delete(g):D.add(g),D}),resolvedColors:A,t:P,onUserMessageClick:vr,HsafaUI:er,onUIError:rr,onUISuccess:tr,addToolResult:g=>nr?.addToolResult?.(g),editableMessageIcon:a?.message_icon,dir:O})}),jsxs("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px"},children:[l&&pn.createElement(l,{}),ot&&jsxs("div",{style:{padding:"8px 12px",marginBottom:"8px",backgroundColor:"#ef4444",color:"#fff",borderRadius:"8px",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsx("span",{children:ot}),jsx("button",{onClick:()=>we(null),style:{background:"none",border:"none",color:"#fff",cursor:"pointer",padding:"2px"},children:"\xD7"})]}),z&&jsxs("div",{style:{padding:"8px 12px",marginBottom:"8px",backgroundColor:"#ef4444",color:"#fff",borderRadius:"8px",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxs("span",{children:[P("error.occurred")," ",z.message||P("error.tryAgain")]}),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:P("error.refresh")})]}),jsx(qt,{input:ve,setInput:fe,textareaRef:Oe,fileInputRef:We,isLoading:L,uploading:or,attachments:Ne,formatBytes:ar,handleRemoveAttachment:ir,onFileInputChange:Cr,onSend:xr,onStop:()=>te(),status:G,t:P,resolvedColors:A,dir:O})]}),jsx(Yt,{historyOpen:wt,historySearch:Tt,currentChatId:V,refreshKey:St,resolvedColors:A,onClose:()=>Ee(false),onSearchChange:It,dir:O,t:P,onChatSelect:g=>{if(Ee(false),g&&g!==V&&($e(),ke(g),y===void 0)){try{$.saveCurrentChatId(g);}catch{}try{let H=$.loadChat(g),D=H&&Array.isArray(H.messages)?H.messages:[];try{K(D);}catch{}}catch{}}},onChatDelete:g=>{try{$.deleteChat(g),Mt(H=>H+1),g===V&&Re();}catch{}},loadChatsIndex:()=>$.loadChatsIndex(),historyPopupRef:ur}),jsx(Jt,{isOpen:gr,resolvedColors:A,t:P,dir:O,lang:J,onConfirm:kr,onCancel:wr,editProcessContent:a}),jsx("style",{children:`
|
|
84
242
|
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
|
|
85
243
|
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
|
|
86
244
|
|
|
@@ -137,11 +295,11 @@ import {jsxs,jsx,Fragment}from'react/jsx-runtime';import po,{createContext,useRe
|
|
|
137
295
|
margin: 12px 0;
|
|
138
296
|
border: 1px solid var(--hsafa-border);
|
|
139
297
|
}
|
|
140
|
-
`})]});return B?jsxs(Fragment,{children:[jsx(Xe,{}),
|
|
298
|
+
`})]});return B?jsxs(Fragment,{children:[jsx(Xe,{}),yn]}):typeof document<"u"&&document.body?jsxs(Fragment,{children:[jsx(Xe,{}),createPortal(Tr,document.body),jsx(Mr,{show:!at,onClick:()=>{dr(true);try{$.saveShowChatPreference(!0);}catch{}},resolvedColors:A,floatingButtonPosition:c})]}):Tr}var gn={dark:{primaryColor:"#4D78FF",backgroundColor:"#0B0B0F",borderColor:"#2A2C33",textColor:"#EDEEF0",accentColor:"#17181C",mutedTextColor:"#9AA0A6",inputBackground:"#17181C",cardBackground:"#121318",hoverBackground:"#1c1e25"},light:{primaryColor:"#2563EB",backgroundColor:"#FFFFFF",borderColor:"#E5E7EB",textColor:"#111827",accentColor:"#F9FAFB",mutedTextColor:"#6B7280",inputBackground:"#F9FAFB",cardBackground:"#F3F4F6",hoverBackground:"#F3F4F6"}};function zo({children:e,theme:t="dark",primaryColor:r,backgroundColor:o,borderColor:n,textColor:s,mutedTextColor:m,enableBorderAnimation:u=true,borderRadius:C=16,enableContentBorder:I=true,className:x="",enableMargin:S=true,chatWidth:k=420,dir:f="ltr"}){let{isAnyStreaming:i,isAnyChatOpen:b,dir:c,theme:d}=se(),h=(f??c)||"ltr",l=(t??d)||"dark",a=useRef(`content-container-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),[T,w]=useState(false);useEffect(()=>{let j=setTimeout(()=>w(true),50);return ()=>clearTimeout(j)},[]);let v=gn[l],y={primaryColor:r||v.primaryColor,backgroundColor:o||v.backgroundColor,borderColor:n||v.borderColor,textColor:s||v.textColor,accentColor:v.accentColor,mutedTextColor:m||v.mutedTextColor,inputBackground:v.inputBackground,cardBackground:v.cardBackground,hoverBackground:v.hoverBackground},M=typeof C=="number"?`${C}px`:C,p=typeof k=="number"?`${k}px`:k,B=S&&b?h==="rtl"?{marginLeft:p}:{marginRight:p}:{},W=S&&b?`calc(100% - ${p})`:"100%";return jsxs(Fragment,{children:[jsx("div",{className:x,style:{width:W,height:"100%",transition:T?"all 0.2s ease-out":"none",padding:b&&I?"16px":"0",...B},children:jsx("div",{style:{position:"relative",width:"100%",height:"100%",transition:T?"all 0.2s ease-out":"none",borderRadius:b?M:"0",border:b&&i&&u?"none":b?`1px solid ${y.borderColor}`:"none",padding:b&&i&&u?"1.5px":"0",background:b&&i&&u?`linear-gradient(120deg, ${y.primaryColor}dd 0%, ${y.primaryColor}88 25%, ${y.primaryColor}00 50%, ${y.primaryColor}88 75%, ${y.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 ${y.primaryColor}40)`:"none"},children:jsx("div",{className:"hsafa-content-container",style:{width:"100%",height:"100%",borderRadius:b&&I?M:"0",backgroundColor:b&&I?y.backgroundColor:"transparent",overflow:"auto",position:"relative",isolation:"isolate",contain:"layout style paint",transform:"translateZ(0)",scrollbarWidth:"thin",scrollbarColor:`${y.mutedTextColor}40 transparent`},children:e})})}),jsx("style",{children:`
|
|
141
299
|
@keyframes ${a.current}-border-flow {
|
|
142
300
|
0% { background-position: 0% 50%; }
|
|
143
301
|
50% { background-position: 100% 50%; }
|
|
144
302
|
100% { background-position: 0% 50%; }
|
|
145
303
|
}
|
|
146
|
-
`})," "]})}var
|
|
304
|
+
`})," "]})}var Zt=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())}},Wo=new Zt;export{qo as Button,zo as ContentContainer,Xe as CursorController,Ke as FillActiveInput,Mr as FloatingChatButton,Fo as HsafaChat,kn as HsafaProvider,Wo as componentRegistry,Ie as controlCursor,qe as getDomComponents,Ie as guideCursor,Ar as useAutoScroll,Ot as useChatStorage,Br as useFileUpload,se as useHsafa,Wt as useHsafaAgent,oo as useMessageEditor};//# sourceMappingURL=index.js.map
|
|
147
305
|
//# sourceMappingURL=index.js.map
|