@hsafa/ui-sdk 0.6.3 → 0.6.4
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 +65 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +65 -30
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,39 @@
|
|
|
1
|
-
'use strict';var jsxRuntime=require('react/jsx-runtime'),xMarkdown=require('@ant-design/x-markdown');require('@ant-design/x-markdown/themes/light.css'),require('@ant-design/x-markdown/themes/dark.css');var Io=require('react'),react=require('@ai-sdk/react'),ai=require('ai'),client=require('react-dom/client'),reactDom=require('react-dom'),lucideReact=require('lucide-react');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Io__default=/*#__PURE__*/_interopDefault(Io);var Ae={};var ia=({variant:e="primary",size:t="md",loading:r=false,disabled:n,children:o,className:
|
|
1
|
+
'use strict';var jsxRuntime=require('react/jsx-runtime'),xMarkdown=require('@ant-design/x-markdown');require('@ant-design/x-markdown/themes/light.css'),require('@ant-design/x-markdown/themes/dark.css');var Io=require('react'),react=require('@ai-sdk/react'),ai=require('ai'),client=require('react-dom/client'),reactDom=require('react-dom'),lucideReact=require('lucide-react');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Io__default=/*#__PURE__*/_interopDefault(Io);var Ae={};var ia=({variant:e="primary",size:t="md",loading:r=false,disabled:n,children:o,className:l,...p})=>{let c=[Ae.button,Ae[e],Ae[t],r&&Ae.loading,l].filter(Boolean).join(" ");return jsxRuntime.jsxs("button",{className:c,disabled:n||r,...p,children:[r&&jsxRuntime.jsx("span",{className:Ae.spinner}),jsxRuntime.jsx("span",{className:r?Ae.hiddenText:void 0,children:o})]})};function Wr({show:e,onClick:t,resolvedColors:r,floatingButtonPosition:n}){if(!e)return null;let o={position:"fixed",bottom:typeof n.bottom=="number"?`${n.bottom}px`:n.bottom,right:n.right?typeof n.right=="number"?`${n.right}px`:n.right:void 0,top:n.top?typeof n.top=="number"?`${n.top}px`:n.top:void 0,left:n.left?typeof n.left=="number"?`${n.left}px`:n.left:void 0,zIndex:1e3};return jsxRuntime.jsx("button",{"aria-label":"Open chat",onClick:t,style:{...o,borderColor:r.borderColor,backgroundColor:r.accentColor,color:r.textColor,borderRadius:"50%",border:`1px solid ${r.borderColor}`,padding:"12px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)",transition:"all 0.2s",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:l=>{l.currentTarget.style.borderColor=r.primaryColor,l.currentTarget.style.backgroundColor=`${r.accentColor}dd`;},onMouseLeave:l=>{l.currentTarget.style.borderColor=r.borderColor,l.currentTarget.style.backgroundColor=r.accentColor;},children:jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})})}function Pe({content:e,theme:t="dark",streaming:r=false,dir:n="ltr"}){return jsxRuntime.jsxs("div",{dir:n,className:"x-markdown-wrapper",style:{width:"100%",maxWidth:"100%"},children:[jsxRuntime.jsx(xMarkdown.XMarkdown,{content:e,className:t==="dark"?"x-markdown-dark":"x-markdown-light",streaming:{hasNextChunk:r,enableAnimation:true,animationConfig:{fadeDuration:200},incompleteMarkdownComponentMap:{html:"IncompleteBlock",link:"IncompleteBlock",image:"IncompleteBlock"}},openLinksInNewTab:true,config:{gfm:true},dompurifyConfig:{ADD_TAGS:["data-chart","welcome","user-card","mermaid"],ADD_ATTR:["data-source","data-spec","data-icon","data-description","data-raw"]},style:{fontSize:"14px",lineHeight:"1.6",wordBreak:"break-word",maxWidth:"100%",overflow:"hidden",direction:n,width:"100%"}}),jsxRuntime.jsx("style",{children:`
|
|
2
|
+
/* Fix light theme text colors */
|
|
3
|
+
.x-markdown-light {
|
|
4
|
+
color: #111827 !important;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.x-markdown-light p,
|
|
8
|
+
.x-markdown-light span,
|
|
9
|
+
.x-markdown-light div,
|
|
10
|
+
.x-markdown-light li,
|
|
11
|
+
.x-markdown-light td,
|
|
12
|
+
.x-markdown-light th {
|
|
13
|
+
color: #111827 !important;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.x-markdown-light h1,
|
|
17
|
+
.x-markdown-light h2,
|
|
18
|
+
.x-markdown-light h3,
|
|
19
|
+
.x-markdown-light h4,
|
|
20
|
+
.x-markdown-light h5,
|
|
21
|
+
.x-markdown-light h6 {
|
|
22
|
+
color: #111827 !important;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.x-markdown-light a {
|
|
26
|
+
color: #2563eb !important;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.x-markdown-light code {
|
|
30
|
+
color: #111827 !important;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.x-markdown-light blockquote {
|
|
34
|
+
color: #374151 !important;
|
|
35
|
+
}
|
|
36
|
+
|
|
2
37
|
/* Ensure tables take full width */
|
|
3
38
|
.x-markdown-wrapper table,
|
|
4
39
|
.x-markdown-dark table,
|
|
@@ -156,7 +191,7 @@
|
|
|
156
191
|
[dir="rtl"] summary {
|
|
157
192
|
text-align: right;
|
|
158
193
|
}
|
|
159
|
-
`})]})}function Gr(e=true){let t=Io.useRef(null),r=Io.useRef(e);return Io.useEffect(()=>{r.current=e;},[e]),Io.useEffect(()=>{let n=t.current;if(!n)return;let o=new MutationObserver(()=>{r.current&&(n.scrollTop=n.scrollHeight);});return o.observe(n,{childList:true,subtree:true}),r.current&&(n.scrollTop=n.scrollHeight),()=>o.disconnect()},[]),t}function jr(e,t){if(!e)return t;let r=e.endsWith("/")?e.slice(0,-1):e,n=t.startsWith("/")?t:`/${t}`;return `${r}${n}`}var _r=Io.createContext(void 0);function zo({baseUrl:e,dir:t="ltr",theme:r="dark",children:n}){let[o,s]=Io.useState(new Map),[g,u]=Io.useState(new Map),[C,I]=Io.useState(new Map),[y,S]=Io.useState(new Map),[k,f]=Io.useState(void 0),i=Io.useCallback((x,w)=>(s(E=>{let p=new Map(E);return p.set(String(x),w),p}),()=>{s(E=>{let p=new Map(E),D=p.get(String(x));return (!w||D===w)&&p.delete(String(x)),p});}),[]),b=Io.useCallback((x,w)=>{s(E=>{let p=new Map(E),D=p.get(String(x));return (!w||D===w)&&p.delete(String(x)),p});},[]),c=Io.useCallback((x,w)=>(u(E=>{let p=new Map(E);return p.set(String(x),w),p}),()=>{u(E=>{let p=new Map(E),D=p.get(String(x));return (!w||D===w)&&p.delete(String(x)),p});}),[]),d=Io.useCallback((x,w)=>{u(E=>{let p=new Map(E),D=p.get(String(x));return (!w||D===w)&&p.delete(String(x)),p});},[]),h=Io.useCallback((x,w)=>{I(E=>{let p=new Map(E);return w?p.set(x,true):p.delete(x),p});},[]),l=Io.useCallback((x,w)=>{S(E=>{let p=new Map(E);return p.set(x,w),p});},[]),a=Io.useMemo(()=>Array.from(C.values()).some(x=>x),[C]),M=Io.useMemo(()=>Array.from(y.values()).some(x=>x),[y]),v=Io.useMemo(()=>({baseUrl:e,dir:t,theme:r,actions:o,components:g,registerAction:i,unregisterAction:b,registerComponent:c,unregisterComponent:d,isAnyStreaming:a,setStreamingState:h,isAnyChatOpen:M,setChatOpenState:l,currentChatId:k,setCurrentChatId:f}),[e,t,r,o,g,i,b,c,d,a,h,M,l,k]);return jsxRuntime.jsx(_r.Provider,{value:v,children:n})}function ce(){let e=Io.useContext(_r);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 Gt=25*1024*1024;function Kr(e){let{baseUrl:t}=ce(),r=e||t||"",[n,o]=Io.useState([]),[s,g]=Io.useState(false),u=Io.useRef(null),C=Io.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=Io.useCallback(async i=>{let b=new FormData;b.append("file",i);let c=await fetch(jr(r,"/api/uploads"),{method:"POST",body:b});if(!c.ok){let h=await c.text().catch(()=>"");throw new Error(h||`Failed to upload ${i.name}`)}let d=await c.json();return {id:d.id,name:d.name||i.name,url:d.url,mimeType:d.mimeType||i.type||"application/octet-stream",size:typeof d.size=="number"?d.size:i.size}},[r]),y=Io.useCallback(i=>{o(b=>b.filter(c=>c.id!==i));},[]),S=Io.useCallback(async(i,b)=>{if(!i)return;let c=Array.isArray(i)?i:Array.from(i);b(null),g(true);let d=[];try{for(let h of c){if(h.size>Gt){b(`"${h.name}" exceeds the ${C(Gt)} 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&&o(h=>[...h,...d]);}finally{g(false);}},[I,C]),k=Io.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=Io.useCallback(()=>{o([]);},[]);return {attachments:n,uploading:s,fileInputRef:u,formatBytes:C,handleRemoveAttachment:y,handleFileSelection:S,buildUserContent:k,clearAttachments:f,setAttachments:o,MAX_UPLOAD_SIZE:Gt}}function Vr(e,t,r,n){return console.log("\u{1F680} [SDK] createHsafaTransport called with templateParams:",n),new ai.DefaultChatTransport({api:`${e}/api/run/${t}`,fetch:async(o,s)=>{let g=s||{},u=g?.body?JSON.parse(g.body):{},C=n&&typeof n=="object"?n:{};console.log("\u{1F680} [SDK] Before merge - body:",u),console.log("\u{1F680} [SDK] Before merge - mergedParams:",C);let I={...C,...u,chatId:r};return console.log("\u{1F680} [SDK] After merge - enhancedBody:",I),fetch(o,{...s,body:JSON.stringify(I)})}})}function Oo(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 Go(e){if(e.id){let r=document.querySelector(`label[for="${e.id}"]`);if(r)return r.textContent?.trim()}let t=e.closest("label");if(t){let r=t.cloneNode(true),n=r.querySelector("input, select, textarea");return n&&n.remove(),r.textContent?.trim()}}function jt(e){if(e.textContent&&e.textContent.trim())return e.textContent.trim().slice(0,100)}function _t(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 jo(e){if(e.id)return `#${e.id}`;let t=[],r=e;for(;r&&r!==document.body;){let n=r.tagName.toLowerCase();if(r.className&&typeof r.className=="string"){let s=r.className.split(" ").filter(g=>g.trim()).slice(0,2);s.length>0&&(n+="."+s.join("."));}let o=r.parentElement;if(o){let s=Array.from(o.children).filter(g=>g.tagName===r.tagName);if(s.length>1){let g=s.indexOf(r)+1;n+=`:nth-child(${g})`;}}t.unshift(n),r=o;}return t.slice(-3).join(" > ")}async function Qe(e={}){try{let{includeHidden:t=!1,selector:r,what:n="content",limit:o}=e,s=document.querySelector(".hsafa-content-container");if(!s)return {ok:!1,components:[],count:0,total:0,containerFound:!1,error:"ContentContainer not found on page. Make sure you have wrapped your app with <ContentContainer>."};let g=r&&s.querySelector(r)||s,u=[],C=[];n==="inputs"?C=["input","textarea","select",'[contenteditable="true"]','[contenteditable=""]']:C=["header","nav","main","section","article","aside","footer","h1","h2","h3","h4","h5","h6","p","img[alt]","ul","ol","li","table","thead","tbody","tr","td","th","form","label","input","textarea","select",'[contenteditable="true"]','[contenteditable=""]',"a[href]","button",'[role="button"]','[role="link"]',"[onclick]","[tabindex]","div"],g.querySelectorAll(C.join(", ")).forEach(c=>{let d=Oo(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:jo(c)};c instanceof HTMLInputElement?(h.type=c.type,h.name=c.name||void 0,h.placeholder=c.placeholder||void 0,h.value=_t(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=_t(c),h.disabled=c.disabled,h.required=c.required):c instanceof HTMLSelectElement?(h.name=c.name||void 0,h.value=_t(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=jt(c)):c instanceof HTMLAnchorElement?(h.href=c.href,h.text=jt(c)):c instanceof HTMLImageElement?(h.text=c.alt||void 0,h.label=c.alt||h.label):h.text=jt(c),h.label=Go(c),h.role=c.getAttribute("role")||void 0,h.ariaLabel=c.getAttribute("aria-label")||void 0,u.push(h);});let y=c=>c.isVisible?n==="inputs"?c.tag==="input"||c.tag==="textarea"||c.tag==="select"||c.role==="textbox"?3:c.tag==="button"||c.tag==="a"?2:1:["header","nav","main","footer"].includes(c.tag)?5:["section","article","aside"].includes(c.tag)||["h1","h2","h3"].includes(c.tag)?4:["h4","h5","h6"].includes(c.tag)?3:c.tag==="form"?4:c.tag==="label"?3:c.tag==="input"||c.tag==="textarea"||c.tag==="select"?4:c.tag==="p"||c.tag==="img"||c.tag==="button"||c.tag==="a"?3:1:0;u.sort((c,d)=>y(d)-y(c));let S=u.length,f=Math.max(1,Math.min(200,typeof o=="number"?Math.floor(o):n==="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 Le(e,t={}){if(typeof window>"u")return {ok:false,steps:[{ok:false,action:"none",targetKind:"position",durationMs:0,error:"guideCursor only works in browser environment"}]};let r=window.__cursorGuide;if(!r)return {ok:false,steps:[{ok:false,action:"none",targetKind:"position",durationMs:0,error:"CursorController not initialized. Make sure to mount <CursorController /> component."}]};try{return await r(e,t)}catch(n){return {ok:false,steps:[{ok:false,action:t.action||"none",targetKind:"position",durationMs:0,error:n?.message||String(n)}]}}}typeof window<"u"&&(window.guideCursor=Le);function Xr(e){return !!e&&e.nodeType===1}function ue(e,t){e.dispatchEvent(new Event(t,{bubbles:true}));}function Yr(e,t){let r=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(e),"value")?.set;r?r.call(e,t):e.value=t,ue(e,"input");}function _o(e,t){e.checked!==t&&e.click();}function qo(e,t){if(typeof t=="object"&&t&&"index"in t&&typeof t.index=="number")e.selectedIndex=Math.max(0,Math.min(e.options.length-1,t.index));else if(typeof t=="object"&&t&&"label"in t&&typeof t.label=="string"){let r=Array.from(e.options).findIndex(n=>n.text===t.label);e.selectedIndex=r>=0?r:0;}else e.value=String(t);ue(e,"input"),ue(e,"change");}function Ko(e,t){let r=new Set(t.map(String));Array.from(e.options).forEach(n=>{n.selected=r.has(n.value)||r.has(n.text);}),ue(e,"input"),ue(e,"change");}function Vo(e){return e?e instanceof Date?e.toISOString().slice(0,10):String(e):""}function Xo(e,t){let r=Array.isArray(t)?t:[t],n=new DataTransfer;for(let o of r)n.items.add(o);Object.defineProperty(e,"files",{value:n.files,configurable:true}),ue(e,"input"),ue(e,"change");}async function et(e,t={}){let r=document.activeElement||null;if(r&&Xr(r)){let n=r.closest('[contenteditable="true"], [contenteditable=""]');n&&(r=n);}if(!r||r===document.body)return {ok:false,filled:[{key:"active",status:"skipped",message:"No active input element"}],errors:["No active input element"]};try{let n=r.tagName.toLowerCase();if(n==="input"){let o=r,s=(o.type||"text").toLowerCase();if(s==="checkbox")_o(o,!!e);else if(s==="radio"){let g=o.name;if(g&&e!=null&&String(o.value)!==String(e)){let u=document.querySelector(`input[type="radio"][name="${CSS.escape(g)}"][value="${CSS.escape(String(e))}"]`);u?u.click():o.click();}else o.click();}else if(s==="file")if(e instanceof File||Array.isArray(e)&&e.every(g=>g instanceof File))Xo(o,e);else return {ok:!1,filled:[{key:"active",status:"skipped",message:"Provide File or File[] for file input"}],errors:["Provide File or File[] for file input"]};else {let g=s==="date"?Vo(e):String(e??"");Yr(o,g),ue(o,"change");}return {ok:!0,filled:[{key:"active",status:"ok"}]}}if(n==="textarea"){let o=r,s=String(e??"");return Yr(o,s),ue(o,"change"),{ok:!0,filled:[{key:"active",status:"ok"}]}}if(n==="select"){let o=r;return o.multiple?Ko(o,Array.isArray(e)?e:[e]):qo(o,e),{ok:!0,filled:[{key:"active",status:"ok"}]}}if(Xr(r)&&r.isContentEditable){let o=r;return o.focus(),o.textContent=String(e??""),ue(o,"input"),ue(o,"change"),o.blur?.(),{ok:!0,filled:[{key:"active",status:"ok"}]}}return {ok:!1,filled:[{key:"active",status:"skipped",message:`Unsupported active element: ${n}`}],errors:[`Unsupported active element: ${n}`]}}catch(n){return {ok:false,filled:[{key:"active",status:"error",message:n?.message??String(n)}],errors:[n?.message??String(n)]}}}typeof window<"u"&&(window.FillActiveInput=et);var tt=null,mt={},Zr=false,Ne=null,ht=false;function qt(e){e.classList.add("visible");}function no(){ht=true,Ne!=null&&(clearTimeout(Ne),Ne=null);}function Jo(e,t=1500){ht||(Ne!=null&&clearTimeout(Ne),Ne=window.setTimeout(()=>{ht||e.classList.remove("visible");},t));}function Zo(e,t=1200){ht=false,Jo(e,t);}function Qo(e){let t=[],r=e?.parentElement;for(;r;){let n=getComputedStyle(r),o=n.overflow+n.overflowY+n.overflowX;/(auto|scroll)/.test(o)&&t.push(r),r=r.parentElement;}return t}async function en(e,t=1500,r=160){let n=performance.now(),o=e?Qo(e):[],s=()=>{let y=[window.scrollX||document.documentElement.scrollLeft||0,window.scrollY||document.documentElement.scrollTop||0];return o.forEach(S=>{y.push(S.scrollLeft,S.scrollTop);}),y},g=()=>{if(!e)return {x:0,y:0};let y=e.getBoundingClientRect();return {x:y.left,y:y.top}},u=s(),C=g(),I=performance.now();return new Promise(y=>{function S(k){let f=s(),i=g(),b=false;for(let c=0;c<f.length;c++)if(f[c]!==u[c]){b=true;break}if(!b&&e&&(i.x!==C.x||i.y!==C.y)&&(b=true),b&&(u=f,C=i,I=k),k-I>=r||k-n>=t){y();return}requestAnimationFrame(S);}requestAnimationFrame(S);})}var tn='<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>',rn='<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 on(){if(!mt.arrow)try{mt.arrow=tn,mt.pointer=rn;}catch(e){console.warn("Failed to set cursor SVGs",e);}return mt}function Qr({arrowSvg:e,pointerSvg:t}){return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[e&&jsxRuntime.jsx("div",{className:"arrow",dangerouslySetInnerHTML:{__html:e}}),t&&jsxRuntime.jsx("div",{className:"pointer",dangerouslySetInnerHTML:{__html:t}})]})}async function nn(){let e="demo-fake-cursor",t=document.getElementById(e),r=await on();if(!Zr){let n="cursor-controller-styles";if(!document.getElementById(n)){let o=document.createElement("style");o.id=n,o.textContent=`
|
|
194
|
+
`})]})}function Gr(e=true){let t=Io.useRef(null),r=Io.useRef(e);return Io.useEffect(()=>{r.current=e;},[e]),Io.useEffect(()=>{let n=t.current;if(!n)return;let o=new MutationObserver(()=>{r.current&&(n.scrollTop=n.scrollHeight);});return o.observe(n,{childList:true,subtree:true}),r.current&&(n.scrollTop=n.scrollHeight),()=>o.disconnect()},[]),t}function jr(e,t){if(!e)return t;let r=e.endsWith("/")?e.slice(0,-1):e,n=t.startsWith("/")?t:`/${t}`;return `${r}${n}`}var _r=Io.createContext(void 0);function zo({baseUrl:e,dir:t="ltr",theme:r="dark",children:n}){let[o,l]=Io.useState(new Map),[p,c]=Io.useState(new Map),[b,S]=Io.useState(new Map),[h,M]=Io.useState(new Map),[v,f]=Io.useState(void 0),s=Io.useCallback((y,k)=>(l(E=>{let x=new Map(E);return x.set(String(y),k),x}),()=>{l(E=>{let x=new Map(E),L=x.get(String(y));return (!k||L===k)&&x.delete(String(y)),x});}),[]),u=Io.useCallback((y,k)=>{l(E=>{let x=new Map(E),L=x.get(String(y));return (!k||L===k)&&x.delete(String(y)),x});},[]),d=Io.useCallback((y,k)=>(c(E=>{let x=new Map(E);return x.set(String(y),k),x}),()=>{c(E=>{let x=new Map(E),L=x.get(String(y));return (!k||L===k)&&x.delete(String(y)),x});}),[]),T=Io.useCallback((y,k)=>{c(E=>{let x=new Map(E),L=x.get(String(y));return (!k||L===k)&&x.delete(String(y)),x});},[]),i=Io.useCallback((y,k)=>{S(E=>{let x=new Map(E);return k?x.set(y,true):x.delete(y),x});},[]),g=Io.useCallback((y,k)=>{M(E=>{let x=new Map(E);return x.set(y,k),x});},[]),a=Io.useMemo(()=>Array.from(b.values()).some(y=>y),[b]),w=Io.useMemo(()=>Array.from(h.values()).some(y=>y),[h]),C=Io.useMemo(()=>({baseUrl:e,dir:t,theme:r,actions:o,components:p,registerAction:s,unregisterAction:u,registerComponent:d,unregisterComponent:T,isAnyStreaming:a,setStreamingState:i,isAnyChatOpen:w,setChatOpenState:g,currentChatId:v,setCurrentChatId:f}),[e,t,r,o,p,s,u,d,T,a,i,w,g,v]);return jsxRuntime.jsx(_r.Provider,{value:C,children:n})}function ce(){let e=Io.useContext(_r);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 Gt=25*1024*1024;function Kr(e){let{baseUrl:t}=ce(),r=e||t||"",[n,o]=Io.useState([]),[l,p]=Io.useState(false),c=Io.useRef(null),b=Io.useCallback(s=>{if(!s||Number.isNaN(s))return "0 B";let u=["B","KB","MB","GB","TB"],d=Math.min(u.length-1,Math.floor(Math.log(s)/Math.log(1024)));return `${(s/Math.pow(1024,d)).toFixed(d===0?0:1)} ${u[d]}`},[]),S=Io.useCallback(async s=>{let u=new FormData;u.append("file",s);let d=await fetch(jr(r,"/api/uploads"),{method:"POST",body:u});if(!d.ok){let i=await d.text().catch(()=>"");throw new Error(i||`Failed to upload ${s.name}`)}let T=await d.json();return {id:T.id,name:T.name||s.name,url:T.url,mimeType:T.mimeType||s.type||"application/octet-stream",size:typeof T.size=="number"?T.size:s.size}},[r]),h=Io.useCallback(s=>{o(u=>u.filter(d=>d.id!==s));},[]),M=Io.useCallback(async(s,u)=>{if(!s)return;let d=Array.isArray(s)?s:Array.from(s);u(null),p(true);let T=[];try{for(let i of d){if(i.size>Gt){u(`"${i.name}" exceeds the ${b(Gt)} limit.`);continue}try{let g=await S(i);T.push(g);}catch(g){console.error("Failed to upload attachment:",g),u(String(g?.message??`Failed to upload ${i.name}`));}}T.length&&o(i=>[...i,...T]);}finally{p(false);}},[S,b]),v=Io.useCallback((s,u)=>{let d=[],T=(s||"").trim();T&&d.push({type:"text",text:T});for(let i of u||[]){let g=i.mimeType||"application/octet-stream";g.startsWith("image/")?d.push({type:"image",image:new URL(i.url),mediaType:g}):d.push({type:"file",data:i.url,mediaType:g,name:i.name});}return d},[]),f=Io.useCallback(()=>{o([]);},[]);return {attachments:n,uploading:l,fileInputRef:c,formatBytes:b,handleRemoveAttachment:h,handleFileSelection:M,buildUserContent:v,clearAttachments:f,setAttachments:o,MAX_UPLOAD_SIZE:Gt}}function Vr(e,t,r,n){return console.log("\u{1F680} [SDK] createHsafaTransport called with templateParams:",n),new ai.DefaultChatTransport({api:`${e}/api/run/${t}`,fetch:async(o,l)=>{let p=l||{},c=p?.body?JSON.parse(p.body):{},b=n&&typeof n=="object"?n:{};console.log("\u{1F680} [SDK] Before merge - body:",c),console.log("\u{1F680} [SDK] Before merge - mergedParams:",b);let S={...b,...c,chatId:r};return console.log("\u{1F680} [SDK] After merge - enhancedBody:",S),fetch(o,{...l,body:JSON.stringify(S)})}})}function Oo(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 Go(e){if(e.id){let r=document.querySelector(`label[for="${e.id}"]`);if(r)return r.textContent?.trim()}let t=e.closest("label");if(t){let r=t.cloneNode(true),n=r.querySelector("input, select, textarea");return n&&n.remove(),r.textContent?.trim()}}function jt(e){if(e.textContent&&e.textContent.trim())return e.textContent.trim().slice(0,100)}function _t(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 jo(e){if(e.id)return `#${e.id}`;let t=[],r=e;for(;r&&r!==document.body;){let n=r.tagName.toLowerCase();if(r.className&&typeof r.className=="string"){let l=r.className.split(" ").filter(p=>p.trim()).slice(0,2);l.length>0&&(n+="."+l.join("."));}let o=r.parentElement;if(o){let l=Array.from(o.children).filter(p=>p.tagName===r.tagName);if(l.length>1){let p=l.indexOf(r)+1;n+=`:nth-child(${p})`;}}t.unshift(n),r=o;}return t.slice(-3).join(" > ")}async function Qe(e={}){try{let{includeHidden:t=!1,selector:r,what:n="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 p=r&&l.querySelector(r)||l,c=[],b=[];n==="inputs"?b=["input","textarea","select",'[contenteditable="true"]','[contenteditable=""]']:b=["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"],p.querySelectorAll(b.join(", ")).forEach(d=>{let T=Oo(d);if(!T&&!t)return;let i={id:d.id||null,tag:d.tagName.toLowerCase(),className:d.className&&typeof d.className=="string"?d.className:void 0,isVisible:T,isInteractive:!0,selector:jo(d)};d instanceof HTMLInputElement?(i.type=d.type,i.name=d.name||void 0,i.placeholder=d.placeholder||void 0,i.value=_t(d),i.checked=d.type==="checkbox"||d.type==="radio"?d.checked:void 0,i.disabled=d.disabled,i.required=d.required):d instanceof HTMLTextAreaElement?(i.name=d.name||void 0,i.placeholder=d.placeholder||void 0,i.value=_t(d),i.disabled=d.disabled,i.required=d.required):d instanceof HTMLSelectElement?(i.name=d.name||void 0,i.value=_t(d),i.disabled=d.disabled,i.required=d.required,i.options=Array.from(d.options).map(g=>({value:g.value,label:g.text,selected:g.selected,disabled:g.disabled}))):d instanceof HTMLButtonElement?(i.type=d.type,i.disabled=d.disabled,i.text=jt(d)):d instanceof HTMLAnchorElement?(i.href=d.href,i.text=jt(d)):d instanceof HTMLImageElement?(i.text=d.alt||void 0,i.label=d.alt||i.label):i.text=jt(d),i.label=Go(d),i.role=d.getAttribute("role")||void 0,i.ariaLabel=d.getAttribute("aria-label")||void 0,c.push(i);});let h=d=>d.isVisible?n==="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;c.sort((d,T)=>h(T)-h(d));let M=c.length,f=Math.max(1,Math.min(200,typeof o=="number"?Math.floor(o):n==="inputs"?100:150)),s=M>f,u=s?c.slice(0,f):c;return {ok:!0,components:u,count:u.length,total:M,truncated:s,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 Le(e,t={}){if(typeof window>"u")return {ok:false,steps:[{ok:false,action:"none",targetKind:"position",durationMs:0,error:"guideCursor only works in browser environment"}]};let r=window.__cursorGuide;if(!r)return {ok:false,steps:[{ok:false,action:"none",targetKind:"position",durationMs:0,error:"CursorController not initialized. Make sure to mount <CursorController /> component."}]};try{return await r(e,t)}catch(n){return {ok:false,steps:[{ok:false,action:t.action||"none",targetKind:"position",durationMs:0,error:n?.message||String(n)}]}}}typeof window<"u"&&(window.guideCursor=Le);function Xr(e){return !!e&&e.nodeType===1}function ue(e,t){e.dispatchEvent(new Event(t,{bubbles:true}));}function Yr(e,t){let r=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(e),"value")?.set;r?r.call(e,t):e.value=t,ue(e,"input");}function _o(e,t){e.checked!==t&&e.click();}function qo(e,t){if(typeof t=="object"&&t&&"index"in t&&typeof t.index=="number")e.selectedIndex=Math.max(0,Math.min(e.options.length-1,t.index));else if(typeof t=="object"&&t&&"label"in t&&typeof t.label=="string"){let r=Array.from(e.options).findIndex(n=>n.text===t.label);e.selectedIndex=r>=0?r:0;}else e.value=String(t);ue(e,"input"),ue(e,"change");}function Ko(e,t){let r=new Set(t.map(String));Array.from(e.options).forEach(n=>{n.selected=r.has(n.value)||r.has(n.text);}),ue(e,"input"),ue(e,"change");}function Vo(e){return e?e instanceof Date?e.toISOString().slice(0,10):String(e):""}function Xo(e,t){let r=Array.isArray(t)?t:[t],n=new DataTransfer;for(let o of r)n.items.add(o);Object.defineProperty(e,"files",{value:n.files,configurable:true}),ue(e,"input"),ue(e,"change");}async function et(e,t={}){let r=document.activeElement||null;if(r&&Xr(r)){let n=r.closest('[contenteditable="true"], [contenteditable=""]');n&&(r=n);}if(!r||r===document.body)return {ok:false,filled:[{key:"active",status:"skipped",message:"No active input element"}],errors:["No active input element"]};try{let n=r.tagName.toLowerCase();if(n==="input"){let o=r,l=(o.type||"text").toLowerCase();if(l==="checkbox")_o(o,!!e);else if(l==="radio"){let p=o.name;if(p&&e!=null&&String(o.value)!==String(e)){let c=document.querySelector(`input[type="radio"][name="${CSS.escape(p)}"][value="${CSS.escape(String(e))}"]`);c?c.click():o.click();}else o.click();}else if(l==="file")if(e instanceof File||Array.isArray(e)&&e.every(p=>p instanceof File))Xo(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 p=l==="date"?Vo(e):String(e??"");Yr(o,p),ue(o,"change");}return {ok:!0,filled:[{key:"active",status:"ok"}]}}if(n==="textarea"){let o=r,l=String(e??"");return Yr(o,l),ue(o,"change"),{ok:!0,filled:[{key:"active",status:"ok"}]}}if(n==="select"){let o=r;return o.multiple?Ko(o,Array.isArray(e)?e:[e]):qo(o,e),{ok:!0,filled:[{key:"active",status:"ok"}]}}if(Xr(r)&&r.isContentEditable){let o=r;return o.focus(),o.textContent=String(e??""),ue(o,"input"),ue(o,"change"),o.blur?.(),{ok:!0,filled:[{key:"active",status:"ok"}]}}return {ok:!1,filled:[{key:"active",status:"skipped",message:`Unsupported active element: ${n}`}],errors:[`Unsupported active element: ${n}`]}}catch(n){return {ok:false,filled:[{key:"active",status:"error",message:n?.message??String(n)}],errors:[n?.message??String(n)]}}}typeof window<"u"&&(window.FillActiveInput=et);var tt=null,mt={},Zr=false,Ne=null,ht=false;function qt(e){e.classList.add("visible");}function no(){ht=true,Ne!=null&&(clearTimeout(Ne),Ne=null);}function Jo(e,t=1500){ht||(Ne!=null&&clearTimeout(Ne),Ne=window.setTimeout(()=>{ht||e.classList.remove("visible");},t));}function Zo(e,t=1200){ht=false,Jo(e,t);}function Qo(e){let t=[],r=e?.parentElement;for(;r;){let n=getComputedStyle(r),o=n.overflow+n.overflowY+n.overflowX;/(auto|scroll)/.test(o)&&t.push(r),r=r.parentElement;}return t}async function en(e,t=1500,r=160){let n=performance.now(),o=e?Qo(e):[],l=()=>{let h=[window.scrollX||document.documentElement.scrollLeft||0,window.scrollY||document.documentElement.scrollTop||0];return o.forEach(M=>{h.push(M.scrollLeft,M.scrollTop);}),h},p=()=>{if(!e)return {x:0,y:0};let h=e.getBoundingClientRect();return {x:h.left,y:h.top}},c=l(),b=p(),S=performance.now();return new Promise(h=>{function M(v){let f=l(),s=p(),u=false;for(let d=0;d<f.length;d++)if(f[d]!==c[d]){u=true;break}if(!u&&e&&(s.x!==b.x||s.y!==b.y)&&(u=true),u&&(c=f,b=s,S=v),v-S>=r||v-n>=t){h();return}requestAnimationFrame(M);}requestAnimationFrame(M);})}var tn='<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>',rn='<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 on(){if(!mt.arrow)try{mt.arrow=tn,mt.pointer=rn;}catch(e){console.warn("Failed to set cursor SVGs",e);}return mt}function Qr({arrowSvg:e,pointerSvg:t}){return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[e&&jsxRuntime.jsx("div",{className:"arrow",dangerouslySetInnerHTML:{__html:e}}),t&&jsxRuntime.jsx("div",{className:"pointer",dangerouslySetInnerHTML:{__html:t}})]})}async function nn(){let e="demo-fake-cursor",t=document.getElementById(e),r=await on();if(!Zr){let n="cursor-controller-styles";if(!document.getElementById(n)){let o=document.createElement("style");o.id=n,o.textContent=`
|
|
160
195
|
.fake-cursor { pointer-events: none; opacity: 0; transition: opacity 0.2s ease; z-index: 2147483647; }
|
|
161
196
|
.fake-cursor.visible { opacity: 1; }
|
|
162
197
|
.fake-cursor .arrow { display: none; }
|
|
@@ -166,12 +201,12 @@
|
|
|
166
201
|
.fake-cursor.as-pointer .arrow { display: none; }
|
|
167
202
|
.fake-cursor.as-pointer .pointer { display: block; }
|
|
168
203
|
.fake-cursor.pressing .pointer svg path { filter: brightness(0.9); }
|
|
169
|
-
`,document.head.appendChild(o);}Zr=true;}return t?(t.classList.add("as-arrow"),tt||(tt=client.createRoot(t),tt.render(jsxRuntime.jsx(Qr,{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),tt=client.createRoot(t),tt.render(jsxRuntime.jsx(Qr,{arrowSvg:r.arrow,pointerSvg:r.pointer}))),t}function We(e,t,r){return Math.max(t,Math.min(r,e))}function an(e){return e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2}function ao(e){if(!e)return null;let t=document.createElement("canvas").getContext("2d");if(!t)return null;t.fillStyle="#000",t.fillStyle=e;let n=t.fillStyle.match(/rgba?\(([^)]+)\)/i);if(!n)return null;let o=n[1].split(/\s*,\s*/).map(Number),[s,g,u,C=1]=o;return {r:s,g,b:u,a:C}}function sn({r:e,g:t,b:r}){let n=[e,t,r].map(o=>o/255).map(o=>o<=.03928?o/12.92:Math.pow((o+.055)/1.055,2.4));return .2126*n[0]+.7152*n[1]+.0722*n[2]}function ln(e){let t=e?ao(e):null;return !t||t.a===0?false:sn(t)<.5}function dn(e,t){let r=document.elementFromPoint(e,t),n=new Set;for(;r&&!n.has(r);){n.add(r);let g=getComputedStyle(r).backgroundColor,u=ao(g);if(u&&u.a>0)return g;r=r.parentElement;}return getComputedStyle(document.body).backgroundColor||"rgb(255,255,255)"}function Kt(e,t,r){let n=dn(t,r),o=ln(n),s=o?"#ffffff":"#000000";e.querySelectorAll("svg path").forEach(u=>{u.style.fill="white",u.style.stroke=s,u.style.strokeWidth="1";}),e.style.filter=o?"drop-shadow(0 1px 2px rgba(0,0,0,0.8))":"drop-shadow(0 1px 2px rgba(255,255,255,0.9))";}async function ft(e,t,r,n,o="ease-in-out",s="curve",g=.25,u="auto",C){no(),qt(e);let I=performance.now(),y=o==="linear"?f=>f:an,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 M=We(g,0,1)*b;k={x:c+a*h*M,y:d+a*l*M};}return new Promise(f=>{function i(b){let c=We((b-I)/n,0,1),d=y(c),h,l;if(S){let w=1-d;h=w*w*t.x+2*w*d*k.x+d*d*r.x,l=w*w*t.y+2*w*d*k.y+d*d*r.y;}else h=t.x+(r.x-t.x)*d,l=t.y+(r.y-t.y)*d;let M=.35*(1-d),v=Math.sin(b*.02)*M,x=Math.cos(b*.018)*M;e.style.left=`${h+v}px`,e.style.top=`${l+x}px`,Kt(e,h+v,l+x),C&&C({x:h+v,y:l+x,t:c,now:b}),c<1?requestAnimationFrame(i):f();}requestAnimationFrame(i);})}function eo(e,t){return {x:e.x+(t?.x??0),y:e.y+(t?.y??0)}}function he(e,t,r,n){let o={bubbles:true,cancelable:true,view:window,clientX:r.x,clientY:r.y,...n};try{let s=t==="pointerdown"||t==="mousedown",g=t==="pointerup"||t==="mouseup",u={button:0,buttons:s?1:0,isPrimary:!0,...o};if("PointerEvent"in window){let C=new PointerEvent(t,{pointerId:1,pointerType:"mouse",...u});e.dispatchEvent(C);}else {let C=new MouseEvent(t,u);e.dispatchEvent(C);}}catch{let s=new MouseEvent(t,o);e.dispatchEvent(s);}}function io(e){return e&&typeof e=="object"&&e.nodeType===1}function cn(e){if(!e)return document;if(io(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 to(e){if(io(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=cn(e.within??null).querySelectorAll(e.selector),n=Math.max(0,Math.min(r.length-1,e.nth??0)),o=r[n]??null;return {kind:o?"element":"position",element:o}}return {kind:"position",point:{x:0,y:0}}}function ro(e,t){let r=e.getBoundingClientRect();if(!t||t==="center")return {x:r.left+r.width/2,y:r.top+r.height/2};if(t==="top-left")return {x:r.left,y:r.top};if(t==="bottom-right")return {x:r.right,y:r.bottom};let n=We(t.x,0,1),o=We(t.y,0,1);return {x:r.left+r.width*n,y:r.top+r.height*o}}function oo(e){return {x:We(e.x,0,window.innerWidth),y:We(e.y,0,window.innerHeight)}}function un(){return Io.useEffect(()=>(window.__cursorGuide=async(e,t={})=>{let r=Array.isArray(e)?e:[{target:e,action:t.action??"none",options:t}],n=[],o=await nn();o.classList.add("visible","as-arrow"),o.classList.remove("as-pointer","pressing"),qt(o),no();let s=parseFloat(o.style.left||"20")||20,g=parseFloat(o.style.top||"20")||20;Kt(o,s,g);for(let u of r){let{durationMs:C=800,easing:I="ease-in-out",offset:y,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=to(u.target),M=null,v=null;if(a.kind==="element"&&a.element?(v=a.element,o.classList.remove("visible"),v.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),await en(v,1500,180),qt(o),M=ro(v,b)):a.kind==="position"&&a.point&&(M=a.point),!M){n.push({ok:false,action:h,targetKind:a.kind,durationMs:Math.round(performance.now()-l),error:"Target not found"});continue}let x={x:parseFloat(o.style.left||"20")||20,y:parseFloat(o.style.top||"20")||20},w=oo(eo(M,y));await ft(o,x,w,C,I,k,f,i);let E=w.x-x.x,p=w.y-x.y,D=Math.hypot(E,p)||1,O=E/D,_=p/D,oe=Math.min(6,Math.max(3,D*.02)),le={x:w.x+O*oe,y:w.y+_*oe};await ft(o,w,le,Math.max(70,C*.1),"ease-out","straight",0,"right"),await ft(o,le,w,120,"ease-out","straight",0,"left"),S&&(o.classList?.add("click"),setTimeout(()=>o.classList?.remove("click"),180));let ne=null;try{if(h==="click"){o.classList.remove("as-arrow"),o.classList.add("as-pointer","pressing");let U={x:c?.x??0,y:c?.y??0},G={x:w.x+U.x,y:w.y+U.y};o.style.left=`${G.x}px`,o.style.top=`${G.y}px`,Kt(o,G.x,G.y);let K=v??document.elementFromPoint(G.x,G.y)??document.body;he(K,"pointerdown",G),he(K,"mousedown",G),await new Promise(B=>setTimeout(B,90)),o.classList.remove("pressing"),he(K,"mouseup",G),he(K,"click",G),setTimeout(()=>{o.classList.remove("as-pointer"),o.classList.add("as-arrow");},140),K instanceof HTMLElement&&K.focus?.(),ne=K?.id??null;}else if(h==="drag"){if(!d)throw new Error("dragTo is required for action 'drag'");let U=to(d),G=null;if(U.kind==="element"&&U.element&&(G=ro(U.element,b)),U.kind==="position"&&U.point&&(G=U.point),!G)throw new Error("dragTo target not found");let K=oo(eo(G,y)),B={x:w.x,y:w.y},fe=v??document.elementFromPoint(B.x,B.y)??document.body;o.classList.remove("as-arrow"),o.classList.add("as-pointer","pressing"),he(fe,"pointerdown",B),he(fe,"mousedown",B),await ft(o,B,K,Math.max(200,C),I,k,f,i,({x:te,y:be})=>{let ye=document.elementFromPoint(te,be)??document.body,Ie={x:te,y:be};he(ye,"pointermove",Ie),he(ye,"mousemove",Ie);});let J=document.elementFromPoint(K.x,K.y)??document.body;o.classList.remove("pressing"),he(J,"pointerup",K),he(J,"mouseup",K);}n.push({ok:!0,action:h,targetKind:a.kind,durationMs:Math.round(performance.now()-l),clickedElementId:ne});}catch(U){n.push({ok:false,action:h,targetKind:a.kind,durationMs:Math.round(performance.now()-l),error:U?.message??String(U)});}}return Zo(o,2e3),{ok:n.every(u=>u.ok),steps:n}},()=>{try{delete window.__cursorGuide;}catch{window.__cursorGuide=void 0;}}),[]),null}var rt=un;function so(){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:n,dragTo:o})=>{let s=await Le(e,{action:t,anchor:r,durationMs:n,dragTo:o});if(s&&s.ok){let g=Array.isArray(s.steps)&&s.steps.length?s.steps[s.steps.length-1]:void 0,u=g?.clickedElementId?` (clicked element id: ${g.clickedElementId})`:"",C=t||g?.action||"none";return {success:true,message:C==="click"?`Cursor moved and clicked successfully${u}`:C==="drag"?"Cursor dragged successfully":"Cursor moved successfully",details:s}}return {success:false,message:"Cursor action failed",details:s}},executeEachToken:false},fillActiveInput:{tool:async({value:e})=>{let t=await et(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 mn({input:e}){return jsxRuntime.jsx("div",{style:{fontSize:"14px",lineHeight:"1.6",width:"100%"},children:jsxRuntime.jsx(Pe,{content:e?.text||"",theme:"dark"})})}function co(){return {plainText:mn}}function uo(e,t,r,n,o,s){let g=r.get(t);if(g){let a=g.parentElement,M=document.querySelector(`[data-get-from-user-host="${t}"]`);if(M&&a!==M){try{a?.removeChild(g);}catch{}M.innerHTML="",M.appendChild(g);}}else {g=document.createElement("div"),g.className="hsafa-inline-form";let a=document.querySelector(`[data-get-from-user-host="${t}"]`);a?(a.innerHTML="",a.appendChild(g)):(document.querySelector(".chat-scroll-container")||document.body).appendChild(g),r.set(t,g);}let u=e?.title||"Provide input",C=e?.description||"",I=e?.submitLabel||"Submit",y=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=n.get(t)||{submitted:false,skipped:false,values:void 0};g.innerHTML="";let f=document.createElement("form");f.style.margin="12px 0",f.style.padding="14px",f.style.border="1px solid var(--hsafa-border, #2A2C33)",f.style.borderRadius="12px",f.style.background="var(--hsafa-card, #121318)",f.style.color="var(--hsafa-text, #EDEEF0)",f.style.boxShadow="0 6px 20px rgba(0,0,0,0.25)";let i=document.createElement("div");if(i.style.fontWeight="600",i.style.marginBottom="6px",i.textContent=u,f.appendChild(i),C){let a=document.createElement("div");a.style.fontSize="12px",a.style.opacity="0.8",a.style.marginBottom="10px",a.textContent=C,f.appendChild(a);}S.forEach(a=>{let M=document.createElement("div");if(M.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,M.appendChild(p);}let v,x=(a.type||"text").toLowerCase();if(x==="textarea"){let p=document.createElement("textarea");p.placeholder=a.placeholder||"",p.value=a.value??"",p.style.width="100%",p.style.minHeight="72px",p.style.padding="10px 12px",p.style.border="1px solid var(--hsafa-border, #2A2C33)",p.style.borderRadius="10px",p.style.background="var(--hsafa-input-bg, #17181C)",p.style.color="inherit",v=p;}else if(x==="select"&&Array.isArray(a.options)){let p=document.createElement("select");p.style.width="100%",p.style.padding="10px 12px",p.style.border="1px solid var(--hsafa-border, #2A2C33)",p.style.borderRadius="10px",p.style.background="var(--hsafa-input-bg, #17181C)",p.style.color="inherit",a.options.forEach(D=>{let O=document.createElement("option");O.value=String(D.value),O.text=String(D.label??D.value),p.appendChild(O);}),p.value=a.value??"",v=p;}else if(x==="checkbox"){let p=document.createElement("input");p.type="checkbox",p.checked=!!a.value,p.style.transform="scale(1.1)",v=p;}else {let p=document.createElement("input");p.type=x,p.placeholder=a.placeholder||"",p.value=a.value??"",p.style.width="100%",p.style.padding="10px 12px",p.style.border="1px solid var(--hsafa-border, #2A2C33)",p.style.borderRadius="10px",p.style.background="var(--hsafa-input-bg, #17181C)",p.style.color="inherit",v=p;}let w=a.id||"value";v.dataset.fieldId=w;let E=k.values&&Object.prototype.hasOwnProperty.call(k.values,w)?k.values[w]:void 0;typeof E<"u"&&(v.type==="checkbox"?v.checked=!!E:v.value=String(E)),(k.submitted||k.skipped)&&(v.setAttribute("disabled","true"),v.style.opacity="0.7"),M.appendChild(v),f.appendChild(M);});let b=String(I).trim(),c=String(y).trim(),d=!!(b||c),h=null,l=null;if(d){let a=document.createElement("div");a.style.display="flex",a.style.gap="8px",a.style.marginTop="10px",h=document.createElement("button"),h.type="submit",h.textContent=b||"Submit",h.style.padding="6px 10px",h.style.borderRadius="8px",h.style.background="var(--hsafa-button-bg, var(--hsafa-primary, #2563eb))",h.style.color="#000000",l=document.createElement("button"),l.type="button",l.textContent=c||"Skip",l.style.padding="6px 10px",l.style.borderRadius="8px",l.style.background="transparent",l.style.border="1px solid var(--hsafa-border, #2A2C33)",l.style.color="inherit",a.appendChild(h),a.appendChild(l),f.appendChild(a);}if(f.onsubmit=a=>{a.preventDefault();let M={};f.querySelectorAll("[data-field-id]").forEach(v=>{let x=v.dataset.fieldId||"value";v.type==="checkbox"?M[x]=v.checked:M[x]=v.value??"";}),n.set(t,{submitted:true,skipped:false,values:M}),o({tool:"requestInput",toolCallId:t,output:{success:true,submitted:true,values:M}}),f.querySelectorAll("[data-field-id]").forEach(v=>{v.disabled=true,v.style.opacity="0.7";}),h&&(h.textContent=`${b||"Submit"} \u2713`,h.style.opacity="0.8",h.disabled=true),l&&(l.disabled=true);},l&&(l.onclick=()=>{n.set(t,{submitted:false,skipped:true,values:void 0}),o({tool:"requestInput",toolCallId:t,output:{success:true,submitted:false,skipped:true}}),f.querySelectorAll("[data-field-id]").forEach(a=>{a.disabled=true,a.style.opacity="0.7";}),l&&(l.textContent=`${c||"Skip"} \u2713`,l.style.opacity="0.8",l.disabled=true),h&&(h.disabled=true);}),k.submitted||k.skipped){let a=document.createElement("div");a.style.marginTop="10px",a.style.fontSize="12px",a.style.display="flex",a.style.alignItems="center",a.style.gap="8px";let M=document.createElement("span");M.style.display="inline-flex",M.style.alignItems="center",M.style.padding="2px 8px",M.style.borderRadius="999px",M.style.fontWeight="600",M.style.fontSize="11px",k.submitted?(M.style.background="rgba(16,185,129,0.15)",M.style.color="#10b981",M.textContent="Submitted"):(M.style.background="rgba(234,179,8,0.15)",M.style.color="#eab308",M.textContent="Skipped"),a.appendChild(M),f.appendChild(a);try{h&&(h.disabled=!0,h.style.opacity="0.8",k.submitted&&(h.textContent=`${b||"Submit"} \u2713`)),l&&(l.disabled=!0,l.style.opacity="0.8",k.skipped&&(l.textContent=`${c||"Skip"} \u2713`));}catch{}}g.appendChild(f);}function po(e,t,r){let n=Io.useRef(new Map),o=Io.useRef(new Map),s=Io.useRef(t),g=Io.useRef(r);s.current=t,g.current=r,Io.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 y=s.current[I];if(y&&typeof y=="object"&&y.executeEachToken&&y.tool){let S=C.input||C.args||{},k=JSON.stringify(S),f=n.current.get(C.toolCallId);if(k!==f&&k!=="{}"){n.current.set(C.toolCallId,k);try{if(I==="requestInput")g.current(S,C.toolCallId);else {let b=(o.current.get(C.toolCallId)||0)+1;o.current.set(C.toolCallId,b),b>1&&y.tool({...S,toolCallNumber:b-1});}}catch{}}}});});},[e]);}function Xt(e){let{agentId:t,baseUrl:r="",tools:n={},uiComponents:o={},onStart:s,onFinish:g,onError:u,initialMessages:C=[],onMessagesChange:I,controlledChatId:y,onChatIdChange:S,templateParams:k}=e,{baseUrl:f,setCurrentChatId:i}=ce(),b=r&&r.length>0?r:f||"",[c,d]=Io.useState(""),[h,l]=Io.useState(()=>`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`),a=y??h,M=Io.useCallback(A=>{y===void 0&&l(A),S&&S(A);},[y,S]);Io.useEffect(()=>{try{i(a);}catch{}return ()=>{try{i(void 0);}catch{}}},[a,i]);let v=Io.useMemo(()=>Vr(b,t,a,k),[b,t,a,k]),x=Io.useCallback(A=>{console.log("Message finished:",A);let P=A?.message?.id;if(!P&&Array.isArray(A?.messages))for(let j=A.messages.length-1;j>=0;j--){let H=A.messages[j];if(H&&H.role==="assistant"&&H.id){P=H.id;break}}g?.({...A,chatId:a,assistantMessageId:P});},[g,a]),w=Io.useCallback(A=>{console.error("Chat error:",A),u?.(A);},[u]),E=Io.useMemo(()=>so(),[]),p=Io.useMemo(()=>({...E,...n}),[E,n]),D=Io.useMemo(()=>co(),[]),O=Io.useMemo(()=>({...D,...o}),[D,o]),_=Io.useRef(new Map),oe=Io.useRef(new Map),le=Io.useCallback(()=>{try{_.current.forEach(A=>{try{A.remove();}catch{}}),_.current.clear(),oe.current.clear();}catch{}},[]),ne=Io.useCallback((A,P)=>{uo(A,P,_.current,oe.current,j=>U.current.addToolResult(j));},[]),U=Io.useRef(null),G=Io.useRef(new Set),K=Io.useCallback((A,P,j)=>{console.error(`UI Error [${P}]:`,j),U.current&&G.current.has(A)&&(G.current.delete(A),U.current.addToolResult({tool:P,toolCallId:A,state:"output-error",errorText:j?.message||String(j)}));},[]),B=Io.useCallback((A,P)=>{U.current&&G.current.has(A)&&(G.current.delete(A),U.current.addToolResult({tool:P,toolCallId:A,output:{status:"ok",rendered:true,component:P,logs:[]}}));},[]),fe=Io.useCallback(A=>{let P=p[A];return P?typeof P=="object"&&"tool"in P?P.tool:typeof P=="function"?P:null:null},[p]),J=react.useChat({transport:v,onFinish:x,onError:w,experimental_throttle:10,sendAutomaticallyWhen:ai.lastAssistantMessageIsCompleteWithToolCalls,async onToolCall({toolCall:A}){let P=fe(A.toolName);if(A.toolName==="requestInput"){try{ne(A.input,A.toolCallId);}catch(ae){console.error("requestInput render error",ae);}return}let j=A.toolName==="ui";A?.input;let ee=O&&A.toolName in O;if(j||ee){G.current.add(A.toolCallId);return}if(P)try{let ae=await P(A.input);J.addToolResult({tool:A.toolName,toolCallId:A.toolCallId,output:ae});}catch(ae){J.addToolResult({tool:A.toolName,toolCallId:A.toolCallId,state:"output-error",errorText:ae?.message||String(ae)});}}}),{messages:te,sendMessage:be,status:ye,stop:Ie,error:Rt}=J;U.current=J;let lt=Io.useRef(new Set);po(te,p,ne),Io.useEffect(()=>{try{let A=new Set,P=[];if(te.forEach(j=>{j.role==="assistant"&&(j.parts||[]).forEach(H=>{if((H?.toolName||(typeof H?.type=="string"&&H.type.startsWith("tool-")?String(H.type.replace(/^tool-/,"")):void 0))!=="requestInput")return;let ae=H?.toolCallId||"";if(!ae)return;A.add(ae);let Ce=H?.output;if(Ce&&(Ce.submitted||Ce.skipped||Ce.values)){let z={submitted:!!Ce.submitted,skipped:!!Ce.skipped,values:Ce.values||void 0};oe.current.set(ae,z);}let T=H?.input||H?.args||{};P.push({input:T,toolCallId:ae});});}),_.current.forEach((j,H)=>{if(!A.has(H)){let ee=_.current.get(H);try{ee?.remove();}catch{}_.current.delete(H),oe.current.delete(H);}}),P.length>0){let j=requestAnimationFrame(()=>{P.forEach(({input:H,toolCallId:ee})=>{try{ne(H,ee);}catch{}});});return ()=>cancelAnimationFrame(j)}}catch{}},[te,ne]),Io.useEffect(()=>{if(!(!C||C.length===0)&&te.length===0&&!lt.current.has(a)){lt.current.add(a);try{J?.setMessages?.(C);}catch{}}},[C,te.length,a,J]);let Se=ye==="submitted"||ye==="streaming",At=Io.useCallback(()=>{I&&I(te,a);},[I,te,a]),Oe=Io.useCallback(async A=>{let P=A?.text!==void 0?A.text:c,j=A?.files||[],H=P.trim();if(!(!H&&j.length===0)&&!Se){A?.text===void 0&&d("");try{if(s){let ee={role:"user",content:H,createdAt:Date.now(),chatId:a};s(ee);}await be({text:H,files:j});}catch(ee){throw console.error("Failed to send message:",ee),ee}}},[c,Se,be,s,a]),Ge=Io.useCallback(()=>{if(Se)return;le(),d("");try{J?.setMessages?.([]);}catch{}let A=`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`;M(A);},[Se,J,le,M]),Z=Io.useCallback(A=>{try{J?.setMessages?.(A);}catch{}},[J]);return {input:c,setInput:d,messages:te,isLoading:Se,status:ye,error:Rt,sendMessage:Oe,stop:Ie,newChat:Ge,setMessages:Z,notifyMessagesChange:At,chatApi:J,chatId:a,setChatId:M,tools:p,uiComponents:O,formHostRef:_,formStateRef:oe,cleanupForms:le,onUISuccess:B,onUIError:K}}function bt(e){let t=`hsafaChat_${e}`,r=`${t}.chats`,n=l=>`${t}.chat.${l}`,o=`${t}.currentChatId`,s=`${t}.showChat`,g=()=>{try{let l=localStorage.getItem(r);return l?JSON.parse(l):[]}catch{return []}},u=l=>{try{localStorage.setItem(r,JSON.stringify(l));}catch{}},C=l=>{try{let a=localStorage.getItem(n(l));return a?JSON.parse(a):null}catch{return null}},I=l=>{try{localStorage.setItem(n(l.id),JSON.stringify(l));}catch{}},y=l=>{let a=g(),M=a.findIndex(v=>v.id===l.id);M>=0?a[M]=l:a.unshift(l),u(a);},S=l=>{let M=g().filter(v=>v.id!==l);u(M);},k=l=>{try{localStorage.removeItem(n(l));}catch{}};return {loadChatsIndex:g,saveChatsIndex:u,loadChat:C,saveChat:I,upsertChatMeta:y,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(o)}catch{return null}},saveCurrentChatId:l=>{try{localStorage.setItem(o,l);}catch{}},removeCurrentChatId:()=>{try{localStorage.removeItem(o);}catch{}}}}function Jt(e){let{agentId:t,chatId:r,messages:n,isLoading:o=false,autoSave:s=true,autoRestore:g=true}=e,u=Io.useMemo(()=>bt(t),[t]),[C,I]=Io.useState([]),[y,S]=Io.useState(null),k=Io.useRef(false),f=Io.useRef(false),i=Io.useCallback(()=>{try{let v=u.loadChatsIndex();I(v);let x=v.find(w=>w.id===r);S(x||null);}catch(v){console.error("Failed to refresh chat list:",v);}},[u,r]);Io.useEffect(()=>{i();},[i]),Io.useEffect(()=>{if(!(!g||f.current)){try{u.loadCurrentChatId()&&(k.current=!0);}catch(v){console.error("Failed to restore chat:",v);}f.current=true;}},[u,g]),Io.useEffect(()=>{if(!(!s||n.length===0))if(k.current){if(!o){let v=Date.now();try{u.saveChat({id:r,messages:n,agentId:t});let w=u.loadChatsIndex().find(E=>E.id===r);w&&(u.upsertChatMeta({...w,updatedAt:v}),i());}catch(x){console.error("Failed to save chat:",x);}}}else {let v=n.find(x=>x.role==="user");if(v){let x="";if(Array.isArray(v.parts)){let p=v.parts.find(D=>D&&D.type==="text");x=p&&typeof p.text=="string"?p.text:"";}let w=(x||"New chat").slice(0,80),E=Date.now();try{u.upsertChatMeta({id:r,title:w,createdAt:E,updatedAt:E}),u.saveChat({id:r,messages:n,agentId:t}),u.saveCurrentChatId(r),k.current=!0,i();}catch(p){console.error("Failed to create chat:",p);}}}},[]);let b=Io.useRef(false);Io.useEffect(()=>{if(o){b.current=true;return}if(b.current&&s){b.current=false;try{let v=Date.now();u.saveChat({id:r,messages:n,agentId:t});let w=u.loadChatsIndex().find(E=>E.id===r);if(w)u.upsertChatMeta({...w,updatedAt:v});else {let E="",p=Array.isArray(n)?n.find(O=>O&&O.role==="user"):void 0;if(p&&Array.isArray(p.parts)){let O=p.parts.find(_=>_&&_.type==="text");E=O&&typeof O.text=="string"?O.text:"";}let D=(E||"New chat").slice(0,80);u.upsertChatMeta({id:r,title:D,createdAt:v,updatedAt:v});try{u.saveCurrentChatId(r);}catch{}k.current=!0;}i();}catch(v){console.error("Failed to save chat on completion:",v);}}},[o,n,r,t,u,s,i]);let c=Io.useCallback(v=>{try{let x=u.loadChat(v);return x?{id:x.id,messages:x.messages,agentId:x.agentId||t}:null}catch(x){return console.error("Failed to load chat:",x),null}},[u,t]),d=Io.useCallback(()=>{if(n.length!==0)try{let v=Date.now();u.saveChat({id:r,messages:n,agentId:t});let w=u.loadChatsIndex().find(E=>E.id===r);w&&(u.upsertChatMeta({...w,updatedAt:v}),i());}catch(v){console.error("Failed to save chat:",v);}},[u,r,n,t,i]),h=Io.useCallback(v=>{try{u.deleteChat(v),i();}catch(x){console.error("Failed to delete chat:",x);}},[u,i]),l=Io.useCallback((v,x)=>{if(v!==r)try{k.current=!0,u.saveCurrentChatId(v);let w=u.loadChat(v),E=w&&Array.isArray(w.messages)?w.messages:[];x(E),i();}catch(w){console.error("Failed to switch chat:",w);}},[u,r,i]),a=Io.useCallback(v=>{k.current=false,v();},[]),M=Io.useCallback(v=>{if(!v.trim())return C;let x=v.toLowerCase();return C.filter(w=>w.title.toLowerCase().includes(x))},[C]);return {chatList:C,currentChatMeta:y,refreshChatList:i,loadChat:c,saveCurrentChat:d,deleteChat:h,switchToChat:l,createNewChat:a,searchChats:M,storage:u}}function bn(e){let{messages:t,isLoading:r,sendMessage:n,setMessages:o,baseUrl:s}=e,{baseUrl:g}=ce(),u=s||g||"",[C,I]=Io.useState(null),[y,S]=Io.useState(""),[k,f]=Io.useState([]),[i,b]=Io.useState(false),c=Io.useCallback((v,x,w=[])=>{I(v),S(x),f(w);},[]),d=Io.useCallback(()=>{I(null),S(""),f([]);},[]),h=Io.useCallback(async v=>{if(!r)try{let x=t.findIndex(E=>E.id===v);if(x===-1)return;let w=t.slice(0,x);o(w),await n({text:y.trim(),files:k.map(E=>({type:"file",url:E.url,mediaType:E.mimeType||"application/octet-stream",...E.name?{name:E.name}:{},...E.size?{size:E.size}:{}}))}),d();}catch(x){throw console.error("Failed to save edit:",x),x}},[r,t,n,y,k,o,d]),l=Io.useCallback(v=>C===v,[C]),a=Io.useCallback(async v=>{if(!u){console.warn("baseUrl not provided, cannot upload attachments");return}b(true);try{let x=Array.from(v).map(async E=>{if(E.size>26214400)throw new Error(`${E.name} is too large (max 25MB)`);let p=new FormData;p.append("file",E);let D=await fetch(`${u}/api/upload`,{method:"POST",body:p});if(!D.ok)throw new Error(`Upload failed: ${D.statusText}`);let O=await D.json();return {id:O.url||`${Date.now()}-${Math.random()}`,name:E.name,url:O.url,mimeType:E.type,size:E.size}}),w=await Promise.all(x);f(E=>[...E,...w]);}catch(x){throw console.error("Failed to upload files:",x),x}finally{b(false);}},[u]),M=Io.useCallback(v=>{f(x=>x.filter(w=>w.id!==v));},[]);return {editingMessageId:C,editingText:y,setEditingText:S,editAttachments:k,setEditAttachments:f,editUploading:i,startEdit:c,cancelEdit:d,saveEdit:h,isEditing:l,addEditAttachments:a,removeEditAttachment:M}}function X({IconComponent:e,...t}){return Io__default.default.createElement(e,t)}function Zt({icon:e,onClick:t,ariaLabel:r,resolvedColors:n,disabled:o=false,title:s}){return jsxRuntime.jsx("button",{"aria-label":r,title:s,disabled:o,style:{backgroundColor:"transparent",color:n.mutedTextColor,border:"none",borderRadius:"8px",padding:"8px",cursor:o?"not-allowed":"pointer",opacity:o?.5:1,transition:"all 0.2s ease-out",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:g=>{o||(g.currentTarget.style.backgroundColor=n.hoverBackground,g.currentTarget.style.color=n.textColor);},onMouseLeave:g=>{g.currentTarget.style.backgroundColor="transparent",g.currentTarget.style.color=n.mutedTextColor;},onClick:t,children:e})}function ho({title:e,alwaysOpen:t,streaming:r,dir:n,resolvedColors:o,onNew:s,onToggleHistory:g,onClose:u,historyBtnRef:C,t:I}){return jsxRuntime.jsxs("div",{style:{marginBottom:"24px",display:"flex",alignItems:"center",justifyContent:"space-between",direction:n==="rtl"?"rtl":"ltr"},children:[jsxRuntime.jsx("div",{style:{minWidth:"0"},children:jsxRuntime.jsx("h1",{title:e,style:{color:o.textColor,fontSize:"18px",fontWeight:"600",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",margin:"0"},children:e})}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",position:"relative",color:o.mutedTextColor},children:[jsxRuntime.jsx(Zt,{icon:jsxRuntime.jsx(X,{IconComponent:lucideReact.Plus,size:"20",strokeWidth:"2"}),onClick:()=>{r||s();},ariaLabel:I("header.new"),resolvedColors:o,disabled:r}),jsxRuntime.jsx("button",{ref:C,"aria-label":I("header.history"),style:{backgroundColor:"transparent",color:o.mutedTextColor,border:"none",borderRadius:"8px",padding:"8px",cursor:"pointer",transition:"all 0.2s ease-out",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:y=>{y.currentTarget.style.backgroundColor=o.hoverBackground,y.currentTarget.style.color=o.textColor;},onMouseLeave:y=>{y.currentTarget.style.backgroundColor="transparent",y.currentTarget.style.color=o.mutedTextColor;},onClick:g,children:jsxRuntime.jsx(X,{IconComponent:lucideReact.History,size:"20",strokeWidth:"2"})}),!t&&jsxRuntime.jsx(Zt,{icon:jsxRuntime.jsx(X,{IconComponent:lucideReact.ChevronRight,size:"20",strokeWidth:"2",style:{transform:n==="rtl"?"rotate(180deg)":"none"}}),onClick:u,ariaLabel:I("header.close"),resolvedColors:o})]})]})}var Tt=class extends Io.Component{constructor(t){super(t),this.state={hasError:false,error:null,errorInfo:null};}static getDerivedStateFromError(t){return {hasError:true,error:t,errorInfo:null}}componentDidMount(){let{toolCallId:t,toolName:r,onSuccess:n}=this.props;t&&r&&n&&!this.state.hasError&&setTimeout(()=>{this.state.hasError||n(t,r);},0);}componentDidCatch(t,r){console.error(`UI Component Error (${this.props.componentName}):`,t,r),this.setState({error:t,errorInfo:r});let{toolCallId:n,toolName:o,onError:s}=this.props;n&&o&&s&&s(n,o,t);}render(){if(this.state.hasError&&this.state.error){let{resolvedColors:t,componentName:r}=this.props;return jsxRuntime.jsxs("div",{style:{padding:"16px",backgroundColor:t.errorColorLight,border:`2px solid ${t.errorColor}`,borderRadius:"12px",color:t.errorColorDark},children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},children:[jsxRuntime.jsx("span",{style:{fontSize:"20px"},children:"\u26A0\uFE0F"}),jsxRuntime.jsxs("strong",{style:{fontSize:"16px"},children:["Component Error: ",r]})]}),jsxRuntime.jsx("div",{style:{fontSize:"14px",marginBottom:"8px",fontFamily:"monospace"},children:this.state.error.message}),this.state.errorInfo&&jsxRuntime.jsxs("details",{style:{fontSize:"12px",marginTop:"8px"},children:[jsxRuntime.jsx("summary",{style:{cursor:"pointer",fontWeight:"bold"},children:"Stack Trace"}),jsxRuntime.jsx("pre",{style:{marginTop:"8px",padding:"8px",backgroundColor:t.errorColorLight,borderRadius:"4px",overflow:"auto",maxHeight:"200px",fontSize:"11px"},children:this.state.errorInfo.componentStack})]})]})}return this.props.children}};var Sn=(e,t,r)=>{let n={"input-streaming":{color:r?.warningColor||"#eab308",text:t?t("tool.inputting"):"Inputting"},"input-available":{color:r?.infoColor||"#3b82f6",text:t?t("tool.running"):"Running"},error:{color:r?.errorColor||"#ef4444",text:t?t("tool.error"):"Error"},"output-available":{color:r?.successColor||"#10b981",text:t?t("tool.called"):"Called"},finished:{color:r?.successColor||"#10b981",text:t?t("tool.called"):"Called"}};return n[e||"output-available"]||n["output-available"]},Mn=e=>{let t=/^(.+?)_([a-f0-9]{6})_(.+)$/,r=e.match(t);if(r){let[,n,,o]=r;return {isMCP:true,mcpName:n.replace(/_/g," "),toolName:o.replace(/_/g," ")}}return {isMCP:false,toolName:e}},En=e=>e.replace(/_/g," ").replace(/-/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\b\w/g,t=>t.toUpperCase());function yo({parts:e,messageId:t,openReasoningIds:r,toggleReasoning:n,resolvedColors:o,HsafaUI:s,onUIError:g,onUISuccess:u,addToolResult:C,dir:I="ltr",t:y}){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?jsxRuntime.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",D=d.texts&&d.texts.length>0&&d.texts.some(_=>_.trim().length>0),O=()=>{D&&n(l);};return p&&!D?null:jsxRuntime.jsx("div",{onClick:O,style:{cursor:D?"pointer":"default",padding:"0"},children:jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:a?"4px":"0px"},children:[jsxRuntime.jsxs("div",{style:{fontSize:"13px",color:o.mutedTextColor,fontWeight:500,display:"flex",alignItems:"center",gap:"6px",overflow:"hidden",maxWidth:"100%",minWidth:0,width:"100%"},children:[jsxRuntime.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px"},children:[!p&&jsxRuntime.jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),jsxRuntime.jsx("span",{style:{color:o.textColor,fontWeight:600,opacity:.9,background:p?"none":`linear-gradient(90deg, ${o.textColor}, ${o.mutedTextColor}, ${o.mutedTextColor})`,backgroundSize:p?"auto":"200% 100%",backgroundClip:p?"unset":"text",WebkitBackgroundClip:p?"unset":"text",WebkitTextFillColor:p?o.mutedTextColor:"transparent",animation:p?void 0:"shimmer 2s ease-in-out infinite"},children:p?y?y("assistant.finishThinking"):"Finish Thinking":y?y("assistant.thinking"):"Thinking"})]}),D&&jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:a?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease-out"},children:jsxRuntime.jsx("polyline",{points:"9 18 15 12 9 6"})})]}),jsxRuntime.jsx("div",{style:{display:"grid",gridTemplateRows:a||!p?"1fr":"0fr",transition:"grid-template-rows 0.2s ease-out",overflow:"hidden"},children:jsxRuntime.jsx("div",{style:{minHeight:0},children:d.texts&&d.texts.length>0?jsxRuntime.jsx("div",{style:{fontSize:"13px",color:o.mutedTextColor,lineHeight:"1.6",maxWidth:"100%"},children:(!p&&a?d.texts:p?a?d.texts:[]:[d.texts[d.texts.length-1]]).map((_,oe)=>jsxRuntime.jsx("div",{style:{marginBottom:"6px",opacity:.5},children:jsxRuntime.jsx(Pe,{content:_,theme:"dark",streaming:!p,dir:I})},`rg-line-${h}-${oe}`))}):jsxRuntime.jsxs("div",{style:{fontSize:"12px",color:o.mutedTextColor,opacity:.7,display:"flex",alignItems:"center",gap:"8px"},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),jsxRuntime.jsx("span",{style:{letterSpacing:"2px",animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"},children:"..."})]})})})]})},l)}if(d.type==="text"){let p=typeof d.endDate!="number";return jsxRuntime.jsx("div",{style:{fontSize:"15px",color:o.textColor,lineHeight:"1.6",direction:S?"rtl":"ltr",textAlign:S?"right":"left"},children:jsxRuntime.jsx(Pe,{content:d.text,theme:"dark",streaming:p,dir:I})},l)}let{color:M,text:v}=Sn(d.status,y,o),x=d.status==="input-streaming"||d.status==="input-available";if(d.toolName==="requestInput")return jsxRuntime.jsx("div",{style:{display:"block",position:"relative"},children:jsxRuntime.jsx("div",{"data-get-from-user-host":d.toolCallId||l,style:{width:"100%"}})},l);let w=s?.[d.toolName||""];if(w)return jsxRuntime.jsx("div",{style:{display:"block",position:"relative"},children:jsxRuntime.jsx(Tt,{componentName:d.toolName||"Unknown",resolvedColors:o,toolCallId:d.toolCallId,toolName:d.toolName||"unknown",onError:g,onSuccess:u,children:jsxRuntime.jsx(w,{toolName:d.toolName||"",toolCallId:d.toolCallId||"",input:d.input,output:d.output,status:d.status,addToolResult:C})})},l);let E=Mn(d.toolName||"tool");return jsxRuntime.jsx("div",{style:{display:"flex",gap:"12px",position:"relative"},children:jsxRuntime.jsx("div",{style:{flex:1,minWidth:0},children:jsxRuntime.jsxs("div",{style:{fontSize:"13px",color:o.mutedTextColor,display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"},children:[jsxRuntime.jsxs("span",{style:{fontWeight:600,color:M,display:"flex",alignItems:"center",gap:"6px"},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:M,animation:x?"pulse 1.5s ease-in-out infinite":void 0}}),v]}),E.isMCP?jsxRuntime.jsxs("span",{style:{fontWeight:500,color:o.textColor},children:[jsxRuntime.jsx("span",{style:{fontWeight:600},children:E.toolName}),jsxRuntime.jsx("span",{style:{opacity:.7,margin:"0 4px"},children:"from"}),jsxRuntime.jsx("span",{style:{fontWeight:600,opacity:.85},children:E.mcpName})]}):jsxRuntime.jsx("span",{style:{fontWeight:500,color:o.textColor},children:En(E.toolName)})]})})},l)}),jsxRuntime.jsx("style",{children:`
|
|
204
|
+
`,document.head.appendChild(o);}Zr=true;}return t?(t.classList.add("as-arrow"),tt||(tt=client.createRoot(t),tt.render(jsxRuntime.jsx(Qr,{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),tt=client.createRoot(t),tt.render(jsxRuntime.jsx(Qr,{arrowSvg:r.arrow,pointerSvg:r.pointer}))),t}function We(e,t,r){return Math.max(t,Math.min(r,e))}function an(e){return e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2}function ao(e){if(!e)return null;let t=document.createElement("canvas").getContext("2d");if(!t)return null;t.fillStyle="#000",t.fillStyle=e;let n=t.fillStyle.match(/rgba?\(([^)]+)\)/i);if(!n)return null;let o=n[1].split(/\s*,\s*/).map(Number),[l,p,c,b=1]=o;return {r:l,g:p,b:c,a:b}}function sn({r:e,g:t,b:r}){let n=[e,t,r].map(o=>o/255).map(o=>o<=.03928?o/12.92:Math.pow((o+.055)/1.055,2.4));return .2126*n[0]+.7152*n[1]+.0722*n[2]}function ln(e){let t=e?ao(e):null;return !t||t.a===0?false:sn(t)<.5}function dn(e,t){let r=document.elementFromPoint(e,t),n=new Set;for(;r&&!n.has(r);){n.add(r);let p=getComputedStyle(r).backgroundColor,c=ao(p);if(c&&c.a>0)return p;r=r.parentElement;}return getComputedStyle(document.body).backgroundColor||"rgb(255,255,255)"}function Kt(e,t,r){let n=dn(t,r),o=ln(n),l=o?"#ffffff":"#000000";e.querySelectorAll("svg path").forEach(c=>{c.style.fill="white",c.style.stroke=l,c.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 ft(e,t,r,n,o="ease-in-out",l="curve",p=.25,c="auto",b){no(),qt(e);let S=performance.now(),h=o==="linear"?f=>f:an,M=l!=="straight",v={x:0,y:0};if(M){let f=r.x-t.x,s=r.y-t.y,u=Math.hypot(f,s)||1,d=(t.x+r.x)/2,T=(t.y+r.y)/2,i=-s/u,g=f/u,a=1;c==="left"?a=-1:c==="right"?a=1:a=Math.random()<.5?-1:1;let w=We(p,0,1)*u;v={x:d+a*i*w,y:T+a*g*w};}return new Promise(f=>{function s(u){let d=We((u-S)/n,0,1),T=h(d),i,g;if(M){let k=1-T;i=k*k*t.x+2*k*T*v.x+T*T*r.x,g=k*k*t.y+2*k*T*v.y+T*T*r.y;}else i=t.x+(r.x-t.x)*T,g=t.y+(r.y-t.y)*T;let w=.35*(1-T),C=Math.sin(u*.02)*w,y=Math.cos(u*.018)*w;e.style.left=`${i+C}px`,e.style.top=`${g+y}px`,Kt(e,i+C,g+y),b&&b({x:i+C,y:g+y,t:d,now:u}),d<1?requestAnimationFrame(s):f();}requestAnimationFrame(s);})}function eo(e,t){return {x:e.x+(t?.x??0),y:e.y+(t?.y??0)}}function he(e,t,r,n){let o={bubbles:true,cancelable:true,view:window,clientX:r.x,clientY:r.y,...n};try{let l=t==="pointerdown"||t==="mousedown",p=t==="pointerup"||t==="mouseup",c={button:0,buttons:l?1:0,isPrimary:!0,...o};if("PointerEvent"in window){let b=new PointerEvent(t,{pointerId:1,pointerType:"mouse",...c});e.dispatchEvent(b);}else {let b=new MouseEvent(t,c);e.dispatchEvent(b);}}catch{let l=new MouseEvent(t,o);e.dispatchEvent(l);}}function io(e){return e&&typeof e=="object"&&e.nodeType===1}function cn(e){if(!e)return document;if(io(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 to(e){if(io(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=cn(e.within??null).querySelectorAll(e.selector),n=Math.max(0,Math.min(r.length-1,e.nth??0)),o=r[n]??null;return {kind:o?"element":"position",element:o}}return {kind:"position",point:{x:0,y:0}}}function ro(e,t){let r=e.getBoundingClientRect();if(!t||t==="center")return {x:r.left+r.width/2,y:r.top+r.height/2};if(t==="top-left")return {x:r.left,y:r.top};if(t==="bottom-right")return {x:r.right,y:r.bottom};let n=We(t.x,0,1),o=We(t.y,0,1);return {x:r.left+r.width*n,y:r.top+r.height*o}}function oo(e){return {x:We(e.x,0,window.innerWidth),y:We(e.y,0,window.innerHeight)}}function un(){return Io.useEffect(()=>(window.__cursorGuide=async(e,t={})=>{let r=Array.isArray(e)?e:[{target:e,action:t.action??"none",options:t}],n=[],o=await nn();o.classList.add("visible","as-arrow"),o.classList.remove("as-pointer","pressing"),qt(o),no();let l=parseFloat(o.style.left||"20")||20,p=parseFloat(o.style.top||"20")||20;Kt(o,l,p);for(let c of r){let{durationMs:b=800,easing:S="ease-in-out",offset:h,highlight:M=true,path:v="curve",curveStrength:f=.25,curveDirection:s="auto",anchor:u,cursorHotspot:d,dragTo:T}=c.options??{},i=c.action??c.options?.action??"none",g=performance.now(),a=to(c.target),w=null,C=null;if(a.kind==="element"&&a.element?(C=a.element,o.classList.remove("visible"),C.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),await en(C,1500,180),qt(o),w=ro(C,u)):a.kind==="position"&&a.point&&(w=a.point),!w){n.push({ok:false,action:i,targetKind:a.kind,durationMs:Math.round(performance.now()-g),error:"Target not found"});continue}let y={x:parseFloat(o.style.left||"20")||20,y:parseFloat(o.style.top||"20")||20},k=oo(eo(w,h));await ft(o,y,k,b,S,v,f,s);let E=k.x-y.x,x=k.y-y.y,L=Math.hypot(E,x)||1,N=E/L,K=x/L,ee=Math.min(6,Math.max(3,L*.02)),re={x:k.x+N*ee,y:k.y+K*ee};await ft(o,k,re,Math.max(70,b*.1),"ease-out","straight",0,"right"),await ft(o,re,k,120,"ease-out","straight",0,"left"),M&&(o.classList?.add("click"),setTimeout(()=>o.classList?.remove("click"),180));let ae=null;try{if(i==="click"){o.classList.remove("as-arrow"),o.classList.add("as-pointer","pressing");let O={x:d?.x??0,y:d?.y??0},G={x:k.x+O.x,y:k.y+O.y};o.style.left=`${G.x}px`,o.style.top=`${G.y}px`,Kt(o,G.x,G.y);let q=C??document.elementFromPoint(G.x,G.y)??document.body;he(q,"pointerdown",G),he(q,"mousedown",G),await new Promise(B=>setTimeout(B,90)),o.classList.remove("pressing"),he(q,"mouseup",G),he(q,"click",G),setTimeout(()=>{o.classList.remove("as-pointer"),o.classList.add("as-arrow");},140),q instanceof HTMLElement&&q.focus?.(),ae=q?.id??null;}else if(i==="drag"){if(!T)throw new Error("dragTo is required for action 'drag'");let O=to(T),G=null;if(O.kind==="element"&&O.element&&(G=ro(O.element,u)),O.kind==="position"&&O.point&&(G=O.point),!G)throw new Error("dragTo target not found");let q=oo(eo(G,h)),B={x:k.x,y:k.y},fe=C??document.elementFromPoint(B.x,B.y)??document.body;o.classList.remove("as-arrow"),o.classList.add("as-pointer","pressing"),he(fe,"pointerdown",B),he(fe,"mousedown",B),await ft(o,B,q,Math.max(200,b),S,v,f,s,({x:oe,y:be})=>{let ye=document.elementFromPoint(oe,be)??document.body,Ie={x:oe,y:be};he(ye,"pointermove",Ie),he(ye,"mousemove",Ie);});let J=document.elementFromPoint(q.x,q.y)??document.body;o.classList.remove("pressing"),he(J,"pointerup",q),he(J,"mouseup",q);}n.push({ok:!0,action:i,targetKind:a.kind,durationMs:Math.round(performance.now()-g),clickedElementId:ae});}catch(O){n.push({ok:false,action:i,targetKind:a.kind,durationMs:Math.round(performance.now()-g),error:O?.message??String(O)});}}return Zo(o,2e3),{ok:n.every(c=>c.ok),steps:n}},()=>{try{delete window.__cursorGuide;}catch{window.__cursorGuide=void 0;}}),[]),null}var rt=un;function so(){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:n,dragTo:o})=>{let l=await Le(e,{action:t,anchor:r,durationMs:n,dragTo:o});if(l&&l.ok){let p=Array.isArray(l.steps)&&l.steps.length?l.steps[l.steps.length-1]:void 0,c=p?.clickedElementId?` (clicked element id: ${p.clickedElementId})`:"",b=t||p?.action||"none";return {success:true,message:b==="click"?`Cursor moved and clicked successfully${c}`:b==="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 et(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 mn({input:e,theme:t="dark"}){return jsxRuntime.jsx("div",{style:{fontSize:"14px",lineHeight:"1.6",width:"100%"},children:jsxRuntime.jsx(Pe,{content:e?.text||"",theme:t})})}function co(){return {plainText:mn}}function uo(e,t,r,n,o,l){let p=r.get(t);if(p){let a=p.parentElement,w=document.querySelector(`[data-get-from-user-host="${t}"]`);if(w&&a!==w){try{a?.removeChild(p);}catch{}w.innerHTML="",w.appendChild(p);}}else {p=document.createElement("div"),p.className="hsafa-inline-form";let a=document.querySelector(`[data-get-from-user-host="${t}"]`);a?(a.innerHTML="",a.appendChild(p)):(document.querySelector(".chat-scroll-container")||document.body).appendChild(p),r.set(t,p);}let c=e?.title||"Provide input",b=e?.description||"",S=e?.submitLabel||"Submit",h=e?.skipLabel||"Skip",M=Array.isArray(e?.fields)?e.fields:e?.label||e?.placeholder?[{id:"value",label:e?.label||"Value",type:"text",placeholder:e?.placeholder||""}]:[],v=n.get(t)||{submitted:false,skipped:false,values:void 0};p.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 s=document.createElement("div");if(s.style.fontWeight="600",s.style.marginBottom="6px",s.textContent=c,f.appendChild(s),b){let a=document.createElement("div");a.style.fontSize="12px",a.style.opacity="0.8",a.style.marginBottom="10px",a.textContent=b,f.appendChild(a);}M.forEach(a=>{let w=document.createElement("div");if(w.style.margin="10px 0",a.label){let x=document.createElement("label");x.style.display="block",x.style.fontSize="12px",x.style.marginBottom="6px",x.style.opacity="0.9",x.textContent=a.label,w.appendChild(x);}let C,y=(a.type||"text").toLowerCase();if(y==="textarea"){let x=document.createElement("textarea");x.placeholder=a.placeholder||"",x.value=a.value??"",x.style.width="100%",x.style.minHeight="72px",x.style.padding="10px 12px",x.style.border="1px solid var(--hsafa-border, #2A2C33)",x.style.borderRadius="10px",x.style.background="var(--hsafa-input-bg, #17181C)",x.style.color="inherit",C=x;}else if(y==="select"&&Array.isArray(a.options)){let x=document.createElement("select");x.style.width="100%",x.style.padding="10px 12px",x.style.border="1px solid var(--hsafa-border, #2A2C33)",x.style.borderRadius="10px",x.style.background="var(--hsafa-input-bg, #17181C)",x.style.color="inherit",a.options.forEach(L=>{let N=document.createElement("option");N.value=String(L.value),N.text=String(L.label??L.value),x.appendChild(N);}),x.value=a.value??"",C=x;}else if(y==="checkbox"){let x=document.createElement("input");x.type="checkbox",x.checked=!!a.value,x.style.transform="scale(1.1)",C=x;}else {let x=document.createElement("input");x.type=y,x.placeholder=a.placeholder||"",x.value=a.value??"",x.style.width="100%",x.style.padding="10px 12px",x.style.border="1px solid var(--hsafa-border, #2A2C33)",x.style.borderRadius="10px",x.style.background="var(--hsafa-input-bg, #17181C)",x.style.color="inherit",C=x;}let k=a.id||"value";C.dataset.fieldId=k;let E=v.values&&Object.prototype.hasOwnProperty.call(v.values,k)?v.values[k]:void 0;typeof E<"u"&&(C.type==="checkbox"?C.checked=!!E:C.value=String(E)),(v.submitted||v.skipped)&&(C.setAttribute("disabled","true"),C.style.opacity="0.7"),w.appendChild(C),f.appendChild(w);});let u=String(S).trim(),d=String(h).trim(),T=!!(u||d),i=null,g=null;if(T){let a=document.createElement("div");a.style.display="flex",a.style.gap="8px",a.style.marginTop="10px",i=document.createElement("button"),i.type="submit",i.textContent=u||"Submit",i.style.padding="6px 10px",i.style.borderRadius="8px",i.style.background="var(--hsafa-button-bg, var(--hsafa-primary, #2563eb))",i.style.color="#000000",g=document.createElement("button"),g.type="button",g.textContent=d||"Skip",g.style.padding="6px 10px",g.style.borderRadius="8px",g.style.background="transparent",g.style.border="1px solid var(--hsafa-border, #2A2C33)",g.style.color="inherit",a.appendChild(i),a.appendChild(g),f.appendChild(a);}if(f.onsubmit=a=>{a.preventDefault();let w={};f.querySelectorAll("[data-field-id]").forEach(C=>{let y=C.dataset.fieldId||"value";C.type==="checkbox"?w[y]=C.checked:w[y]=C.value??"";}),n.set(t,{submitted:true,skipped:false,values:w}),o({tool:"requestInput",toolCallId:t,output:{success:true,submitted:true,values:w}}),f.querySelectorAll("[data-field-id]").forEach(C=>{C.disabled=true,C.style.opacity="0.7";}),i&&(i.textContent=`${u||"Submit"} \u2713`,i.style.opacity="0.8",i.disabled=true),g&&(g.disabled=true);},g&&(g.onclick=()=>{n.set(t,{submitted:false,skipped:true,values:void 0}),o({tool:"requestInput",toolCallId:t,output:{success:true,submitted:false,skipped:true}}),f.querySelectorAll("[data-field-id]").forEach(a=>{a.disabled=true,a.style.opacity="0.7";}),g&&(g.textContent=`${d||"Skip"} \u2713`,g.style.opacity="0.8",g.disabled=true),i&&(i.disabled=true);}),v.submitted||v.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 w=document.createElement("span");w.style.display="inline-flex",w.style.alignItems="center",w.style.padding="2px 8px",w.style.borderRadius="999px",w.style.fontWeight="600",w.style.fontSize="11px",v.submitted?(w.style.background="rgba(16,185,129,0.15)",w.style.color="#10b981",w.textContent="Submitted"):(w.style.background="rgba(234,179,8,0.15)",w.style.color="#eab308",w.textContent="Skipped"),a.appendChild(w),f.appendChild(a);try{i&&(i.disabled=!0,i.style.opacity="0.8",v.submitted&&(i.textContent=`${u||"Submit"} \u2713`)),g&&(g.disabled=!0,g.style.opacity="0.8",v.skipped&&(g.textContent=`${d||"Skip"} \u2713`));}catch{}}p.appendChild(f);}function po(e,t,r){let n=Io.useRef(new Map),o=Io.useRef(new Map),l=Io.useRef(t),p=Io.useRef(r);l.current=t,p.current=r,Io.useEffect(()=>{e.forEach(c=>{c.role==="assistant"&&c.parts?.forEach(b=>{if(!b.toolCallId)return;let S=b.toolName;if(!S&&b.type?.startsWith("tool-")&&(S=b.type.replace(/^tool-/,"")),!S)return;let h=l.current[S];if(h&&typeof h=="object"&&h.executeEachToken&&h.tool){let M=b.input||b.args||{},v=JSON.stringify(M),f=n.current.get(b.toolCallId);if(v!==f&&v!=="{}"){n.current.set(b.toolCallId,v);try{if(S==="requestInput")p.current(M,b.toolCallId);else {let u=(o.current.get(b.toolCallId)||0)+1;o.current.set(b.toolCallId,u),u>1&&h.tool({...M,toolCallNumber:u-1});}}catch{}}}});});},[e]);}function Xt(e){let{agentId:t,baseUrl:r="",tools:n={},uiComponents:o={},onStart:l,onFinish:p,onError:c,initialMessages:b=[],onMessagesChange:S,controlledChatId:h,onChatIdChange:M,templateParams:v}=e,{baseUrl:f,setCurrentChatId:s}=ce(),u=r&&r.length>0?r:f||"",[d,T]=Io.useState(""),[i,g]=Io.useState(()=>`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`),a=h??i,w=Io.useCallback(A=>{h===void 0&&g(A),M&&M(A);},[h,M]);Io.useEffect(()=>{try{s(a);}catch{}return ()=>{try{s(void 0);}catch{}}},[a,s]);let C=Io.useMemo(()=>Vr(u,t,a,v),[u,t,a,v]),y=Io.useCallback(A=>{console.log("Message finished:",A);let P=A?.message?.id;if(!P&&Array.isArray(A?.messages))for(let j=A.messages.length-1;j>=0;j--){let H=A.messages[j];if(H&&H.role==="assistant"&&H.id){P=H.id;break}}p?.({...A,chatId:a,assistantMessageId:P});},[p,a]),k=Io.useCallback(A=>{console.error("Chat error:",A),c?.(A);},[c]),E=Io.useMemo(()=>so(),[]),x=Io.useMemo(()=>({...E,...n}),[E,n]),L=Io.useMemo(()=>co(),[]),N=Io.useMemo(()=>({...L,...o}),[L,o]),K=Io.useRef(new Map),ee=Io.useRef(new Map),re=Io.useCallback(()=>{try{K.current.forEach(A=>{try{A.remove();}catch{}}),K.current.clear(),ee.current.clear();}catch{}},[]),ae=Io.useCallback((A,P)=>{uo(A,P,K.current,ee.current,j=>O.current.addToolResult(j));},[]),O=Io.useRef(null),G=Io.useRef(new Set),q=Io.useCallback((A,P,j)=>{console.error(`UI Error [${P}]:`,j),O.current&&G.current.has(A)&&(G.current.delete(A),O.current.addToolResult({tool:P,toolCallId:A,state:"output-error",errorText:j?.message||String(j)}));},[]),B=Io.useCallback((A,P)=>{O.current&&G.current.has(A)&&(G.current.delete(A),O.current.addToolResult({tool:P,toolCallId:A,output:{status:"ok",rendered:true,component:P,logs:[]}}));},[]),fe=Io.useCallback(A=>{let P=x[A];return P?typeof P=="object"&&"tool"in P?P.tool:typeof P=="function"?P:null:null},[x]),J=react.useChat({transport:C,onFinish:y,onError:k,experimental_throttle:10,sendAutomaticallyWhen:ai.lastAssistantMessageIsCompleteWithToolCalls,async onToolCall({toolCall:A}){let P=fe(A.toolName);if(A.toolName==="requestInput"){try{ae(A.input,A.toolCallId);}catch(ie){console.error("requestInput render error",ie);}return}let j=A.toolName==="ui";A?.input;let te=N&&A.toolName in N;if(j||te){G.current.add(A.toolCallId);return}if(P)try{let ie=await P(A.input);J.addToolResult({tool:A.toolName,toolCallId:A.toolCallId,output:ie});}catch(ie){J.addToolResult({tool:A.toolName,toolCallId:A.toolCallId,state:"output-error",errorText:ie?.message||String(ie)});}}}),{messages:oe,sendMessage:be,status:ye,stop:Ie,error:Rt}=J;O.current=J;let lt=Io.useRef(new Set);po(oe,x,ae),Io.useEffect(()=>{try{let A=new Set,P=[];if(oe.forEach(j=>{j.role==="assistant"&&(j.parts||[]).forEach(H=>{if((H?.toolName||(typeof H?.type=="string"&&H.type.startsWith("tool-")?String(H.type.replace(/^tool-/,"")):void 0))!=="requestInput")return;let ie=H?.toolCallId||"";if(!ie)return;A.add(ie);let Ce=H?.output;if(Ce&&(Ce.submitted||Ce.skipped||Ce.values)){let z={submitted:!!Ce.submitted,skipped:!!Ce.skipped,values:Ce.values||void 0};ee.current.set(ie,z);}let I=H?.input||H?.args||{};P.push({input:I,toolCallId:ie});});}),K.current.forEach((j,H)=>{if(!A.has(H)){let te=K.current.get(H);try{te?.remove();}catch{}K.current.delete(H),ee.current.delete(H);}}),P.length>0){let j=requestAnimationFrame(()=>{P.forEach(({input:H,toolCallId:te})=>{try{ae(H,te);}catch{}});});return ()=>cancelAnimationFrame(j)}}catch{}},[oe,ae]),Io.useEffect(()=>{if(!(!b||b.length===0)&&oe.length===0&&!lt.current.has(a)){lt.current.add(a);try{J?.setMessages?.(b);}catch{}}},[b,oe.length,a,J]);let Se=ye==="submitted"||ye==="streaming",At=Io.useCallback(()=>{S&&S(oe,a);},[S,oe,a]),Oe=Io.useCallback(async A=>{let P=A?.text!==void 0?A.text:d,j=A?.files||[],H=P.trim();if(!(!H&&j.length===0)&&!Se){A?.text===void 0&&T("");try{if(l){let te={role:"user",content:H,createdAt:Date.now(),chatId:a};l(te);}await be({text:H,files:j});}catch(te){throw console.error("Failed to send message:",te),te}}},[d,Se,be,l,a]),Ge=Io.useCallback(()=>{if(Se)return;re(),T("");try{J?.setMessages?.([]);}catch{}let A=`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`;w(A);},[Se,J,re,w]),Z=Io.useCallback(A=>{try{J?.setMessages?.(A);}catch{}},[J]);return {input:d,setInput:T,messages:oe,isLoading:Se,status:ye,error:Rt,sendMessage:Oe,stop:Ie,newChat:Ge,setMessages:Z,notifyMessagesChange:At,chatApi:J,chatId:a,setChatId:w,tools:x,uiComponents:N,formHostRef:K,formStateRef:ee,cleanupForms:re,onUISuccess:B,onUIError:q}}function bt(e){let t=`hsafaChat_${e}`,r=`${t}.chats`,n=g=>`${t}.chat.${g}`,o=`${t}.currentChatId`,l=`${t}.showChat`,p=()=>{try{let g=localStorage.getItem(r);return g?JSON.parse(g):[]}catch{return []}},c=g=>{try{localStorage.setItem(r,JSON.stringify(g));}catch{}},b=g=>{try{let a=localStorage.getItem(n(g));return a?JSON.parse(a):null}catch{return null}},S=g=>{try{localStorage.setItem(n(g.id),JSON.stringify(g));}catch{}},h=g=>{let a=p(),w=a.findIndex(C=>C.id===g.id);w>=0?a[w]=g:a.unshift(g),c(a);},M=g=>{let w=p().filter(C=>C.id!==g);c(w);},v=g=>{try{localStorage.removeItem(n(g));}catch{}};return {loadChatsIndex:p,saveChatsIndex:c,loadChat:b,saveChat:S,upsertChatMeta:h,deleteChatMeta:M,deleteChatData:v,deleteChat:g=>{v(g),M(g);},loadShowChatPreference:g=>{try{let a=localStorage.getItem(l);return a!==null?a==="true":g}catch{return g}},saveShowChatPreference:g=>{try{localStorage.setItem(l,String(g));}catch{}},loadCurrentChatId:()=>{try{return localStorage.getItem(o)}catch{return null}},saveCurrentChatId:g=>{try{localStorage.setItem(o,g);}catch{}},removeCurrentChatId:()=>{try{localStorage.removeItem(o);}catch{}}}}function Jt(e){let{agentId:t,chatId:r,messages:n,isLoading:o=false,autoSave:l=true,autoRestore:p=true}=e,c=Io.useMemo(()=>bt(t),[t]),[b,S]=Io.useState([]),[h,M]=Io.useState(null),v=Io.useRef(false),f=Io.useRef(false),s=Io.useCallback(()=>{try{let C=c.loadChatsIndex();S(C);let y=C.find(k=>k.id===r);M(y||null);}catch(C){console.error("Failed to refresh chat list:",C);}},[c,r]);Io.useEffect(()=>{s();},[s]),Io.useEffect(()=>{if(!(!p||f.current)){try{c.loadCurrentChatId()&&(v.current=!0);}catch(C){console.error("Failed to restore chat:",C);}f.current=true;}},[c,p]),Io.useEffect(()=>{if(!(!l||n.length===0))if(v.current){if(!o){let C=Date.now();try{c.saveChat({id:r,messages:n,agentId:t});let k=c.loadChatsIndex().find(E=>E.id===r);k&&(c.upsertChatMeta({...k,updatedAt:C}),s());}catch(y){console.error("Failed to save chat:",y);}}}else {let C=n.find(y=>y.role==="user");if(C){let y="";if(Array.isArray(C.parts)){let x=C.parts.find(L=>L&&L.type==="text");y=x&&typeof x.text=="string"?x.text:"";}let k=(y||"New chat").slice(0,80),E=Date.now();try{c.upsertChatMeta({id:r,title:k,createdAt:E,updatedAt:E}),c.saveChat({id:r,messages:n,agentId:t}),c.saveCurrentChatId(r),v.current=!0,s();}catch(x){console.error("Failed to create chat:",x);}}}},[]);let u=Io.useRef(false);Io.useEffect(()=>{if(o){u.current=true;return}if(u.current&&l){u.current=false;try{let C=Date.now();c.saveChat({id:r,messages:n,agentId:t});let k=c.loadChatsIndex().find(E=>E.id===r);if(k)c.upsertChatMeta({...k,updatedAt:C});else {let E="",x=Array.isArray(n)?n.find(N=>N&&N.role==="user"):void 0;if(x&&Array.isArray(x.parts)){let N=x.parts.find(K=>K&&K.type==="text");E=N&&typeof N.text=="string"?N.text:"";}let L=(E||"New chat").slice(0,80);c.upsertChatMeta({id:r,title:L,createdAt:C,updatedAt:C});try{c.saveCurrentChatId(r);}catch{}v.current=!0;}s();}catch(C){console.error("Failed to save chat on completion:",C);}}},[o,n,r,t,c,l,s]);let d=Io.useCallback(C=>{try{let y=c.loadChat(C);return y?{id:y.id,messages:y.messages,agentId:y.agentId||t}:null}catch(y){return console.error("Failed to load chat:",y),null}},[c,t]),T=Io.useCallback(()=>{if(n.length!==0)try{let C=Date.now();c.saveChat({id:r,messages:n,agentId:t});let k=c.loadChatsIndex().find(E=>E.id===r);k&&(c.upsertChatMeta({...k,updatedAt:C}),s());}catch(C){console.error("Failed to save chat:",C);}},[c,r,n,t,s]),i=Io.useCallback(C=>{try{c.deleteChat(C),s();}catch(y){console.error("Failed to delete chat:",y);}},[c,s]),g=Io.useCallback((C,y)=>{if(C!==r)try{v.current=!0,c.saveCurrentChatId(C);let k=c.loadChat(C),E=k&&Array.isArray(k.messages)?k.messages:[];y(E),s();}catch(k){console.error("Failed to switch chat:",k);}},[c,r,s]),a=Io.useCallback(C=>{v.current=false,C();},[]),w=Io.useCallback(C=>{if(!C.trim())return b;let y=C.toLowerCase();return b.filter(k=>k.title.toLowerCase().includes(y))},[b]);return {chatList:b,currentChatMeta:h,refreshChatList:s,loadChat:d,saveCurrentChat:T,deleteChat:i,switchToChat:g,createNewChat:a,searchChats:w,storage:c}}function bn(e){let{messages:t,isLoading:r,sendMessage:n,setMessages:o,baseUrl:l}=e,{baseUrl:p}=ce(),c=l||p||"",[b,S]=Io.useState(null),[h,M]=Io.useState(""),[v,f]=Io.useState([]),[s,u]=Io.useState(false),d=Io.useCallback((C,y,k=[])=>{S(C),M(y),f(k);},[]),T=Io.useCallback(()=>{S(null),M(""),f([]);},[]),i=Io.useCallback(async C=>{if(!r)try{let y=t.findIndex(E=>E.id===C);if(y===-1)return;let k=t.slice(0,y);o(k),await n({text:h.trim(),files:v.map(E=>({type:"file",url:E.url,mediaType:E.mimeType||"application/octet-stream",...E.name?{name:E.name}:{},...E.size?{size:E.size}:{}}))}),T();}catch(y){throw console.error("Failed to save edit:",y),y}},[r,t,n,h,v,o,T]),g=Io.useCallback(C=>b===C,[b]),a=Io.useCallback(async C=>{if(!c){console.warn("baseUrl not provided, cannot upload attachments");return}u(true);try{let y=Array.from(C).map(async E=>{if(E.size>26214400)throw new Error(`${E.name} is too large (max 25MB)`);let x=new FormData;x.append("file",E);let L=await fetch(`${c}/api/upload`,{method:"POST",body:x});if(!L.ok)throw new Error(`Upload failed: ${L.statusText}`);let N=await L.json();return {id:N.url||`${Date.now()}-${Math.random()}`,name:E.name,url:N.url,mimeType:E.type,size:E.size}}),k=await Promise.all(y);f(E=>[...E,...k]);}catch(y){throw console.error("Failed to upload files:",y),y}finally{u(false);}},[c]),w=Io.useCallback(C=>{f(y=>y.filter(k=>k.id!==C));},[]);return {editingMessageId:b,editingText:h,setEditingText:M,editAttachments:v,setEditAttachments:f,editUploading:s,startEdit:d,cancelEdit:T,saveEdit:i,isEditing:g,addEditAttachments:a,removeEditAttachment:w}}function X({IconComponent:e,...t}){return Io__default.default.createElement(e,t)}function Zt({icon:e,onClick:t,ariaLabel:r,resolvedColors:n,disabled:o=false,title:l}){return jsxRuntime.jsx("button",{"aria-label":r,title:l,disabled:o,style:{backgroundColor:"transparent",color:n.mutedTextColor,border:"none",borderRadius:"8px",padding:"8px",cursor:o?"not-allowed":"pointer",opacity:o?.5:1,transition:"all 0.2s ease-out",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:p=>{o||(p.currentTarget.style.backgroundColor=n.hoverBackground,p.currentTarget.style.color=n.textColor);},onMouseLeave:p=>{p.currentTarget.style.backgroundColor="transparent",p.currentTarget.style.color=n.mutedTextColor;},onClick:t,children:e})}function ho({title:e,alwaysOpen:t,streaming:r,dir:n,resolvedColors:o,onNew:l,onToggleHistory:p,onClose:c,historyBtnRef:b,t:S}){return jsxRuntime.jsxs("div",{style:{marginBottom:"24px",display:"flex",alignItems:"center",justifyContent:"space-between",direction:n==="rtl"?"rtl":"ltr"},children:[jsxRuntime.jsx("div",{style:{minWidth:"0"},children:jsxRuntime.jsx("h1",{title:e,style:{color:o.textColor,fontSize:"18px",fontWeight:"600",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",margin:"0"},children:e})}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",position:"relative",color:o.mutedTextColor},children:[jsxRuntime.jsx(Zt,{icon:jsxRuntime.jsx(X,{IconComponent:lucideReact.Plus,size:"20",strokeWidth:"2"}),onClick:()=>{r||l();},ariaLabel:S("header.new"),resolvedColors:o,disabled:r}),jsxRuntime.jsx("button",{ref:b,"aria-label":S("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:h=>{h.currentTarget.style.backgroundColor=o.hoverBackground,h.currentTarget.style.color=o.textColor;},onMouseLeave:h=>{h.currentTarget.style.backgroundColor="transparent",h.currentTarget.style.color=o.mutedTextColor;},onClick:p,children:jsxRuntime.jsx(X,{IconComponent:lucideReact.History,size:"20",strokeWidth:"2"})}),!t&&jsxRuntime.jsx(Zt,{icon:jsxRuntime.jsx(X,{IconComponent:lucideReact.ChevronRight,size:"20",strokeWidth:"2",style:{transform:n==="rtl"?"rotate(180deg)":"none"}}),onClick:c,ariaLabel:S("header.close"),resolvedColors:o})]})]})}var Tt=class extends Io.Component{constructor(t){super(t),this.state={hasError:false,error:null,errorInfo:null};}static getDerivedStateFromError(t){return {hasError:true,error:t,errorInfo:null}}componentDidMount(){let{toolCallId:t,toolName:r,onSuccess:n}=this.props;t&&r&&n&&!this.state.hasError&&setTimeout(()=>{this.state.hasError||n(t,r);},0);}componentDidCatch(t,r){console.error(`UI Component Error (${this.props.componentName}):`,t,r),this.setState({error:t,errorInfo:r});let{toolCallId:n,toolName:o,onError:l}=this.props;n&&o&&l&&l(n,o,t);}render(){if(this.state.hasError&&this.state.error){let{resolvedColors:t,componentName:r}=this.props;return jsxRuntime.jsxs("div",{style:{padding:"16px",backgroundColor:t.errorColorLight,border:`2px solid ${t.errorColor}`,borderRadius:"12px",color:t.errorColorDark},children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},children:[jsxRuntime.jsx("span",{style:{fontSize:"20px"},children:"\u26A0\uFE0F"}),jsxRuntime.jsxs("strong",{style:{fontSize:"16px"},children:["Component Error: ",r]})]}),jsxRuntime.jsx("div",{style:{fontSize:"14px",marginBottom:"8px",fontFamily:"monospace"},children:this.state.error.message}),this.state.errorInfo&&jsxRuntime.jsxs("details",{style:{fontSize:"12px",marginTop:"8px"},children:[jsxRuntime.jsx("summary",{style:{cursor:"pointer",fontWeight:"bold"},children:"Stack Trace"}),jsxRuntime.jsx("pre",{style:{marginTop:"8px",padding:"8px",backgroundColor:t.errorColorLight,borderRadius:"4px",overflow:"auto",maxHeight:"200px",fontSize:"11px"},children:this.state.errorInfo.componentStack})]})]})}return this.props.children}};var Sn=(e,t,r)=>{let n={"input-streaming":{color:r?.warningColor||"#eab308",text:t?t("tool.inputting"):"Inputting"},"input-available":{color:r?.infoColor||"#3b82f6",text:t?t("tool.running"):"Running"},error:{color:r?.errorColor||"#ef4444",text:t?t("tool.error"):"Error"},"output-available":{color:r?.successColor||"#10b981",text:t?t("tool.called"):"Called"},finished:{color:r?.successColor||"#10b981",text:t?t("tool.called"):"Called"}};return n[e||"output-available"]||n["output-available"]},Mn=e=>{let t=/^(.+?)_([a-f0-9]{6})_(.+)$/,r=e.match(t);if(r){let[,n,,o]=r;return {isMCP:true,mcpName:n.replace(/_/g," "),toolName:o.replace(/_/g," ")}}return {isMCP:false,toolName:e}},En=e=>e.replace(/_/g," ").replace(/-/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\b\w/g,t=>t.toUpperCase());function yo({parts:e,messageId:t,openReasoningIds:r,toggleReasoning:n,resolvedColors:o,HsafaUI:l,onUIError:p,onUISuccess:c,addToolResult:b,dir:S="ltr",t:h,theme:M="dark"}){let v=S==="rtl",f=[],s=[],u,d,T=false;for(let i of Array.isArray(e)?e:[]){if(!i)continue;if(i.type==="reasoning"&&typeof i.text=="string"){s.push(i.text),u||(u=i.startDate),d=i.endDate,i.state==="done"&&(T=true);continue}if(i.type==="text"&&typeof i.text=="string"){s.length&&(f.push({type:"reasoning",texts:s,startDate:u,endDate:d,isCompleted:T}),s=[],u=void 0,d=void 0,T=false),f.push({type:"text",text:i.text,startDate:i.startDate,endDate:i.endDate});continue}let g=i.type==="dynamic-tool",a=typeof i.type=="string"&&i.type.startsWith("tool-");if(g||a||i.type==="tool-call"){s.length&&(f.push({type:"reasoning",texts:s,startDate:u,endDate:d,isCompleted:T}),s=[],u=void 0,d=void 0,T=false);let w=String(g?i.toolName||"dynamic-tool":a?i.type?.slice(5)||"tool":i.toolName||"tool");w==="requestInput"?f.push({type:"tool",toolName:w,status:i.state||i.status,input:i.input,output:i.output,startDate:i.startDate,endDate:i.endDate,toolCallId:i.toolCallId}):f.push({type:"tool",toolName:w,status:i.state||i.status,input:i.input,output:i.output,startDate:i.startDate,endDate:i.endDate,toolCallId:i.toolCallId});continue}}return s.length&&f.push({type:"reasoning",texts:s,startDate:u,endDate:d,isCompleted:T}),f.length?jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px",direction:v?"rtl":"ltr"},children:[f.map((i,g)=>{let a=`${t}-${g}`,w=r.has(a);if(i.type==="reasoning"){let L=i.isCompleted||typeof i.startDate=="number"&&typeof i.endDate=="number",N=i.texts&&i.texts.length>0&&i.texts.some(ee=>ee.trim().length>0),K=()=>{N&&n(a);};return L&&!N?null:jsxRuntime.jsx("div",{onClick:K,style:{cursor:N?"pointer":"default",padding:"0"},children:jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:w?"4px":"0px"},children:[jsxRuntime.jsxs("div",{style:{fontSize:"13px",color:o.mutedTextColor,fontWeight:500,display:"flex",alignItems:"center",gap:"6px",overflow:"hidden",maxWidth:"100%",minWidth:0,width:"100%"},children:[jsxRuntime.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"6px"},children:[!L&&jsxRuntime.jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),jsxRuntime.jsx("span",{style:{color:o.textColor,fontWeight:600,opacity:.9,background:L?"none":`linear-gradient(90deg, ${o.textColor}, ${o.mutedTextColor}, ${o.mutedTextColor})`,backgroundSize:L?"auto":"200% 100%",backgroundClip:L?"unset":"text",WebkitBackgroundClip:L?"unset":"text",WebkitTextFillColor:L?o.mutedTextColor:"transparent",animation:L?void 0:"shimmer 2s ease-in-out infinite"},children:L?h?h("assistant.finishThinking"):"Finish Thinking":h?h("assistant.thinking"):"Thinking"})]}),N&&jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,transform:w?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.2s ease-out"},children:jsxRuntime.jsx("polyline",{points:"9 18 15 12 9 6"})})]}),jsxRuntime.jsx("div",{style:{display:"grid",gridTemplateRows:w||!L?"1fr":"0fr",transition:"grid-template-rows 0.2s ease-out",overflow:"hidden"},children:jsxRuntime.jsx("div",{style:{minHeight:0},children:i.texts&&i.texts.length>0?jsxRuntime.jsx("div",{style:{fontSize:"13px",color:o.mutedTextColor,lineHeight:"1.6",maxWidth:"100%"},children:(!L&&w?i.texts:L?w?i.texts:[]:[i.texts[i.texts.length-1]]).map((ee,re)=>jsxRuntime.jsx("div",{style:{marginBottom:"6px",opacity:.5},children:jsxRuntime.jsx(Pe,{content:ee,theme:M,streaming:!L,dir:S})},`rg-line-${g}-${re}`))}):jsxRuntime.jsxs("div",{style:{fontSize:"12px",color:o.mutedTextColor,opacity:.7,display:"flex",alignItems:"center",gap:"8px"},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"pulse 1.5s ease-in-out infinite"}}),jsxRuntime.jsx("span",{style:{letterSpacing:"2px",animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"},children:"..."})]})})})]})},a)}if(i.type==="text"){let L=typeof i.endDate!="number";return jsxRuntime.jsx("div",{style:{fontSize:"15px",color:o.textColor,lineHeight:"1.6",direction:v?"rtl":"ltr",textAlign:v?"right":"left"},children:jsxRuntime.jsx(Pe,{content:i.text,theme:M,streaming:L,dir:S})},a)}let{color:C,text:y}=Sn(i.status,h,o),k=i.status==="input-streaming"||i.status==="input-available";if(i.toolName==="requestInput")return jsxRuntime.jsx("div",{style:{display:"block",position:"relative"},children:jsxRuntime.jsx("div",{"data-get-from-user-host":i.toolCallId||a,style:{width:"100%"}})},a);let E=l?.[i.toolName||""];if(E)return jsxRuntime.jsx("div",{style:{display:"block",position:"relative"},children:jsxRuntime.jsx(Tt,{componentName:i.toolName||"Unknown",resolvedColors:o,toolCallId:i.toolCallId,toolName:i.toolName||"unknown",onError:p,onSuccess:c,children:jsxRuntime.jsx(E,{toolName:i.toolName||"",toolCallId:i.toolCallId||"",input:i.input,output:i.output,status:i.status,addToolResult:b,theme:M})})},a);let x=Mn(i.toolName||"tool");return jsxRuntime.jsx("div",{style:{display:"flex",gap:"12px",position:"relative"},children:jsxRuntime.jsx("div",{style:{flex:1,minWidth:0},children:jsxRuntime.jsxs("div",{style:{fontSize:"13px",color:o.mutedTextColor,display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"},children:[jsxRuntime.jsxs("span",{style:{fontWeight:600,color:C,display:"flex",alignItems:"center",gap:"6px"},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",height:"6px",width:"6px",borderRadius:"50%",backgroundColor:C,animation:k?"pulse 1.5s ease-in-out infinite":void 0}}),y]}),x.isMCP?jsxRuntime.jsxs("span",{style:{fontWeight:500,color:o.textColor},children:[jsxRuntime.jsx("span",{style:{fontWeight:600},children:x.toolName}),jsxRuntime.jsx("span",{style:{opacity:.7,margin:"0 4px"},children:"from"}),jsxRuntime.jsx("span",{style:{fontWeight:600,opacity:.85},children:x.mcpName})]}):jsxRuntime.jsx("span",{style:{fontWeight:500,color:o.textColor},children:En(x.toolName)})]})})},a)}),jsxRuntime.jsx("style",{children:`
|
|
170
205
|
@keyframes shimmer {
|
|
171
206
|
0% { background-position: -200% 0; }
|
|
172
207
|
100% { background-position: 200% 0; }
|
|
173
208
|
}
|
|
174
|
-
`})]}):null}function xo(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 bo({attachment:e,resolvedColors:t,mode:r,onRemove:n,maxWidth:o="200px"}){let
|
|
209
|
+
`})]}):null}function xo(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 bo({attachment:e,resolvedColors:t,mode:r,onRemove:n,maxWidth:o="200px"}){let l=e.mimeType?.startsWith("image/"),p=r==="editable"||r==="input",c=r==="viewable",b={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:c?"pointer":"default",maxWidth:r==="input"?"140px":o,position:"relative"},S=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:r==="input"?"20px":"16px",height:r==="input"?"20px":"16px",borderRadius:r==="input"?"4px":"3px",backgroundColor:l?"transparent":t.accentColor,flexShrink:0},children:[l?jsxRuntime.jsx("img",{src:e.url,alt:e.name,style:{width:r==="input"?"20px":"16px",height:r==="input"?"20px":"16px",borderRadius:r==="input"?"4px":"3px",objectFit:"cover"},onError:h=>{h.target.style.display="none";let M=h.target.nextElementSibling;M&&(M.style.display="block");}}):null,jsxRuntime.jsx(X,{IconComponent:lucideReact.File,size:r==="input"?14:10,strokeWidth:"2",style:{display:l?"none":"block",color:t.mutedTextColor}})]}),jsxRuntime.jsxs("div",{style:{minWidth:"0",flex:"1",display:"flex",flexDirection:"column"},children:[jsxRuntime.jsx("span",{title:e.name,style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:"500"},children:e.name}),jsxRuntime.jsx("span",{style:{fontSize:r==="input"?"10px":"9px",color:t.mutedTextColor,marginTop:r==="input"?"2px":"1px"},children:xo(e.size)})]}),r==="input"&&l&&jsxRuntime.jsx("button",{onClick:h=>{h.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:h=>{h.currentTarget.style.backgroundColor=t.hoverBackground,h.currentTarget.style.color=t.textColor;},onMouseLeave:h=>{h.currentTarget.style.backgroundColor="transparent",h.currentTarget.style.color=t.mutedTextColor;},children:jsxRuntime.jsx(X,{IconComponent:lucideReact.Eye,size:"12",strokeWidth:"2"})}),p&&n&&jsxRuntime.jsx("button",{onClick:h=>{h.stopPropagation(),n(e.id);},style:{display:"flex",alignItems:"center",justifyContent:"center",width:r==="input"?"auto":"16px",height:r==="input"?"auto":"16px",padding:r==="input"?"2px":"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",color:t.mutedTextColor,cursor:"pointer",transition:"all 0.2s",flexShrink:0},onMouseEnter:h=>{h.currentTarget.style.backgroundColor="#ef444420",h.currentTarget.style.color="#ef4444";},onMouseLeave:h=>{h.currentTarget.style.backgroundColor="transparent",h.currentTarget.style.color=t.mutedTextColor;},children:jsxRuntime.jsx(X,{IconComponent:lucideReact.X,size:"12",strokeWidth:"2"})}),c&&jsxRuntime.jsx(X,{IconComponent:lucideReact.Download,size:"10",strokeWidth:"2",style:{color:t.mutedTextColor,flexShrink:0}})]});return c?jsxRuntime.jsx("a",{href:e.url,target:"_blank",rel:"noreferrer",style:{...b,textDecoration:"none"},onMouseEnter:h=>{h.currentTarget.style.backgroundColor=t.hoverBackground,h.currentTarget.style.borderColor=t.primaryColor;},onMouseLeave:h=>{h.currentTarget.style.backgroundColor=t.inputBackground,h.currentTarget.style.borderColor=t.borderColor;},children:S}):jsxRuntime.jsx("div",{style:b,children:S})}function ko({attachments:e,resolvedColors:t,onRemove:r}){if(!Array.isArray(e)||e.length===0)return null;let n=typeof r=="function"?"editable":"viewable";return jsxRuntime.jsx("div",{style:{marginTop:"12px",display:"flex",flexWrap:"wrap",gap:"8px"},children:e.map(o=>jsxRuntime.jsx(bo,{attachment:o,resolvedColors:t,mode:n,onRemove:r},o.id))})}function er({chatMessages:e,isLoading:t,openReasoningIds:r,toggleReasoning:n,resolvedColors:o,t:l,onUserMessageClick:p,HsafaUI:c,onUIError:b,onUISuccess:S,addToolResult:h,editableMessageIcon:M,fullPage:v,dir:f,theme:s="dark"}){return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("style",{children:`
|
|
175
210
|
@keyframes jumpingDots {
|
|
176
211
|
0%, 80%, 100% {
|
|
177
212
|
transform: translateY(0);
|
|
@@ -180,34 +215,34 @@
|
|
|
180
215
|
transform: translateY(-5px);
|
|
181
216
|
}
|
|
182
217
|
}
|
|
183
|
-
`}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",direction:f},children:[e.map((
|
|
184
|
-
`),h=c.filter(l=>l.type==="file"||l.type==="image").map(l=>{if(l.type==="image"){let a=typeof l.image=="string"?l.image:l.image?.toString?.()||"";return {id:a||`${i.id}-img-${Date.now()}`,name:l.name||"image",url:a,mimeType:l.mediaType||"image/jpeg",size:l.size||0}}else return {id:l.url||`${i.id}-file-${Date.now()}`,name:l.name||"file",url:l.url||"",mimeType:l.mediaType||"application/octet-stream",size:l.size||0}});return jsxRuntime.jsx("div",{style:{padding:"0 4px",display:"flex",flexDirection:"column",alignItems:i.role==="user"&&k?"flex-end":"stretch"},children:i.role==="user"?jsxRuntime.jsx("div",{style:{maxWidth:k?"80%":"100%"},children:jsxRuntime.jsx("div",{title:s("editor.clickToEdit"),onClick:()=>g(i,i.id,d,h),style:{maxWidth:k?"100%":"720px",borderRadius:k?"20px":"16px",padding:"12px 16px",fontSize:"15px",lineHeight:"1.6",whiteSpace:"pre-wrap",cursor:"pointer",transition:"background-color 0.2s",backgroundColor:k?o.inputBackground:o.accentColor,color:o.textColor,marginBottom:"16px",marginTop:"16px",position:"relative",border:k?`1px solid ${o.borderColor}`:"none"},onMouseEnter:l=>l.currentTarget.style.backgroundColor=o.hoverBackground,onMouseLeave:l=>l.currentTarget.style.backgroundColor=k?o.inputBackground:o.accentColor,children:jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsxs("div",{style:{flex:1},children:[d,h.length>0&&jsxRuntime.jsx(ko,{attachments:h,resolvedColors:o})]}),jsxRuntime.jsx("div",{style:{flexShrink:0,opacity:.5,transition:"opacity 0.2s"},children:jsxRuntime.jsx(X,{IconComponent:S||lucideReact.Pencil,size:"14",strokeWidth:"2"})})]})})}):jsxRuntime.jsx(yo,{parts:c,messageId:i.id,openReasoningIds:r,toggleReasoning:n,resolvedColors:o,HsafaUI:u,onUIError:C,onUISuccess:I,addToolResult:y,dir:f,t:s})},i.id)}),t&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",padding:"0 4px",height:"20px"},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0s"}}),jsxRuntime.jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0.2s"}}),jsxRuntime.jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0.4s"}})]})]})]})}function tr({input:e,setInput:t,textareaRef:r,fileInputRef:n,isLoading:o,uploading:s,attachments:g,formatBytes:u,handleRemoveAttachment:C,onFileInputChange:I,onSend:y,onStop:S,status:k,t:f,resolvedColors:i,fullPage:b,dir:c="ltr"}){let d=k==="streaming"||k==="submitted",h=g.length>0||e.trim().length>0,l=c==="rtl";return b?jsxRuntime.jsxs("div",{style:{position:"relative",width:"100%",maxWidth:"768px",margin:"0 auto"},children:[jsxRuntime.jsxs("div",{style:{position:"relative",width:"100%",borderRadius:"26px",padding:l?"14px 48px 14px 14px":"14px 14px 14px 48px",backgroundColor:i.inputBackground,boxShadow:"0 0 0 1px rgba(0,0,0,0.05)",transition:"box-shadow 0.2s ease",direction:l?"rtl":"ltr"},onFocus:a=>{},children:[jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"10px",...l?{right:"12px"}:{left:"12px"},zIndex:10},children:jsxRuntime.jsx("button",{onClick:()=>n.current?.click(),disabled:o||s,style:{borderRadius:"50%",width:"33px",height:"33px",transition:"all 0.2s",backgroundColor:"transparent",border:"none",cursor:o||s?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:i.textColor,opacity:o||s?.5:.7},"aria-label":f("input.attachFiles"),onMouseEnter:a=>{!o&&!s&&(a.currentTarget.style.backgroundColor=i.hoverBackground,a.currentTarget.style.opacity="1");},onMouseLeave:a=>{a.currentTarget.style.backgroundColor="transparent",a.currentTarget.style.opacity="0.7";},children:jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M12 5v14M5 12h14"})})})}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[g.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",paddingBottom:"8px",...l?{marginRight:"-4px",justifyContent:"flex-end"}:{marginLeft:"-4px"}},children:g.map(a=>{let M=a.mimeType.startsWith("image/");return jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 10px",backgroundColor:i.cardBackground,borderRadius:"8px",border:`1px solid ${i.borderColor}`,fontSize:"12px",color:i.textColor,position:"relative"},children:[jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",borderRadius:"4px",backgroundColor:M?"transparent":i.inputBackground},children:M?jsxRuntime.jsx("img",{src:a.url,alt:a.name,style:{width:"20px",height:"20px",borderRadius:"4px",objectFit:"cover"}}):jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("rect",{x:"4",y:"4",width:"16",height:"20",rx:"2",ry:"2"})})}),jsxRuntime.jsx("span",{title:a.name,style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:a.name}),jsxRuntime.jsx("button",{onClick:()=>C(a.id),style:{background:"none",border:"none",color:i.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px"},children:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},a.id)})}),s&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:i.mutedTextColor},children:[jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"spin 1s linear infinite"},children:jsxRuntime.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsxRuntime.jsx("span",{children:f("input.uploadingFiles")})]}),jsxRuntime.jsx("div",{style:{...l?{paddingLeft:"40px"}:{paddingRight:"40px"},display:"flex",alignItems:"center"},children:jsxRuntime.jsx("textarea",{ref:r,"aria-label":f("input.prompt"),rows:1,placeholder:f("input.placeholder"),value:e,onChange:a=>t(a.target.value),onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),y());},disabled:s,style:{maxHeight:"200px",width:"100%",resize:"none",backgroundColor:"transparent",fontSize:"16px",lineHeight:"1.5",outline:"none",border:"none",color:i.textColor,fontFamily:"inherit",overflow:"auto",padding:0,margin:0,direction:l?"rtl":"ltr",textAlign:l?"right":"left"}})})]}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"8px",...l?{left:"8px"}:{right:"8px"}},children:o?jsxRuntime.jsx("button",{onClick: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:jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:jsxRuntime.jsx("rect",{width:"24",height:"24",rx:"2"})})}):jsxRuntime.jsx("button",{onClick:y,disabled:!h||s,"aria-label":f("input.send"),style:{borderRadius:"50%",width:"36px",height:"36px",transition:"all 0.2s ease-out",backgroundColor:!h||s?i.cardBackground:i.textColor,color:!h||s?i.mutedTextColor:i.inputBackground,border:"none",cursor:!h||s?"default":"pointer",display:"flex",alignItems:"center",justifyContent:"center",transform:l?"rotate(180deg)":""},children:jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"M5 12h14"}),jsxRuntime.jsx("path",{d:"M12 5l7 7-7 7"})]})})})]}),jsxRuntime.jsx("input",{ref:n,type:"file",multiple:true,onChange:I,style:{display:"none"},accept:"*/*"}),jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"8px 0",fontSize:"12px",color:i.mutedTextColor,opacity:.8},children:"AI can make mistakes. Please check important information."})]}):jsxRuntime.jsx("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px",paddingTop:"4px"},children:jsxRuntime.jsx("div",{style:{position:"relative",flex:1},children:jsxRuntime.jsxs("div",{style:{position:"relative",width:"100%",borderRadius:"16px",paddingBottom:"48px",paddingTop:"16px",border:`1px solid ${i.borderColor}`,backgroundColor:i.cardBackground},children:[g.length>0&&jsxRuntime.jsx("div",{style:{padding:"0px 16px 12px 16px",display:"flex",flexWrap:"wrap",gap:"10px"},children:g.map(a=>{let M=a.mimeType.startsWith("image/");return jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",backgroundColor:i.inputBackground,borderRadius:"10px",border:`1px solid ${i.borderColor}`,fontSize:"12px",color:i.textColor,position:"relative"},children:[jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",borderRadius:"4px",backgroundColor:M?"transparent":i.cardBackground},children:M?jsxRuntime.jsx("img",{src:a.url,alt:a.name,style:{width:"20px",height:"20px",borderRadius:"4px",objectFit:"cover"}}):jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("rect",{x:"4",y:"4",width:"16",height:"20",rx:"2",ry:"2"})})}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",minWidth:0,flex:1},children:[jsxRuntime.jsx("span",{title:a.name,style:{maxWidth:"140px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:a.name}),jsxRuntime.jsx("span",{style:{color:i.mutedTextColor,fontSize:"10px",marginTop:"2px"},children:u(a.size)})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginLeft:"8px"},children:[M&&jsxRuntime.jsx("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",style:{background:"none",border:"none",color:i.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px",textDecoration:"none"},title:f("input.previewImage"),children:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),jsxRuntime.jsx("button",{onClick:()=>C(a.id),style:{background:"none",border:"none",color:i.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px"},title:f("input.removeFile"),children:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]},a.id)})}),s&&jsxRuntime.jsxs("div",{style:{padding:"0px 16px 12px 16px",display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:i.mutedTextColor},children:[jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"spin 1s linear infinite"},children:jsxRuntime.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsxRuntime.jsx("span",{children:f("input.uploadingFiles")})]}),jsxRuntime.jsx("div",{style:{padding:"0 16px"},children:jsxRuntime.jsx("textarea",{ref:r,"aria-label":f("input.prompt"),rows:1,placeholder:f("input.placeholder"),value:e,onChange:a=>t(a.target.value),onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),y());},disabled:s,style:{height:"24px",maxHeight:"200px",width:"100%",resize:"none",backgroundColor:"transparent",fontSize:"15px",lineHeight:"1.6",outline:"none",border:"none",color:i.textColor,fontFamily:"inherit",overflow:"auto",direction:l?"rtl":"ltr",textAlign:l?"right":"left"}})}),jsxRuntime.jsx("input",{ref:n,type:"file",multiple:true,onChange:I,style:{display:"none"},accept:"*/*"}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"8px",...l?{right:"8px"}:{left:"8px"},display:"flex",alignItems:"center",gap:"4px",color:i.mutedTextColor},children:jsxRuntime.jsx("button",{onClick:()=>n.current?.click(),disabled:o||s,style:{borderRadius:"8px",padding:"8px",transition:"all 0.2s",backgroundColor:"transparent",border:"none",cursor:o||s?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"inherit",opacity:o||s?.5:1},"aria-label":f("input.attachFiles"),children:jsxRuntime.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 1 1 5.66 5.66l-9.2 9.19a2 2 0 1 1-2.83-2.83l8.49-8.49"})})})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"8px",...l?{left:"8px"}:{right:"8px"}},children:o?jsxRuntime.jsx("button",{onClick: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 ${i.errorColor}`,backgroundColor:i.errorColorLight||`${i.errorColor}20`,color:i.errorColor,opacity:d?1:.4,cursor:d?"pointer":"not-allowed",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:a=>{d&&(a.currentTarget.style.backgroundColor=i.errorColorLight||`${i.errorColor}30`,a.currentTarget.style.transform="scale(1.02)");},onMouseLeave:a=>{a.currentTarget.style.backgroundColor=i.errorColorLight||`${i.errorColor}20`,a.currentTarget.style.transform="scale(1)";},children:jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"})})}):jsxRuntime.jsx("button",{onClick:y,disabled:!h||s,"aria-label":f("input.send"),title:"Send message",style:{borderRadius:"12px",padding:"12px",transition:"all 0.2s ease-out",border:`1px solid ${i.borderColor}`,backgroundColor:i.cardBackground,color:!h||s?i.mutedTextColor:i.primaryColor,cursor:!h||s?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",opacity:!h||s?.5:1},onMouseEnter:a=>{h&&!s&&(a.currentTarget.style.borderColor=i.primaryColor,a.currentTarget.style.transform="scale(1.02)");},onMouseLeave:a=>{a.currentTarget.style.borderColor=i.borderColor,a.currentTarget.style.transform="scale(1)";},children:jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"m5 12 7-7 7 7"}),jsxRuntime.jsx("path",{d:"M12 19V5"})]})})})]})})})}function rr({prompts:e,onSelect:t,resolvedColors:r,disabled:n=false,dir:o="ltr",t:s}){let[g,u]=Io.useState(null),C=o==="rtl";return !e||e.length===0?null:jsxRuntime.jsxs("div",{style:{padding:"12px 0",display:"flex",flexDirection:"column",gap:"8px",direction:C?"rtl":"ltr"},children:[jsxRuntime.jsx("div",{style:{fontSize:"12px",fontWeight:600,color:r.mutedTextColor,...C?{paddingRight:"4px",textAlign:"right"}:{paddingLeft:"4px",textAlign:"left"},textTransform:"uppercase",letterSpacing:"0.5px"},children:s?s("prompts.suggested"):"Suggested Prompts"}),jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((I,y)=>{let S=g===y,k=I.prompt.length>180,f=k&&!S?I.prompt.slice(0,180)+"...":I.prompt;return jsxRuntime.jsxs("button",{onClick:()=>{n||t(I.prompt);},disabled:n,style:{display:"flex",flexDirection:"column",padding:"12px",backgroundColor:r.cardBackground,border:`1px solid ${r.borderColor}`,borderRadius:"12px",cursor:n?"not-allowed":"pointer",transition:"all 0.2s ease",textAlign:C?"right":"left",opacity:n?.5:1,position:"relative",overflow:"hidden"},onMouseEnter:i=>{n||(i.currentTarget.style.backgroundColor=r.hoverBackground,i.currentTarget.style.borderColor=r.primaryColor,i.currentTarget.style.transform=C?"translateX(-2px)":"translateX(2px)");},onMouseLeave:i=>{i.currentTarget.style.backgroundColor=r.cardBackground,i.currentTarget.style.borderColor=r.borderColor,i.currentTarget.style.transform="translateX(0)";},children:[jsxRuntime.jsxs("div",{style:{fontSize:"13px",fontWeight:600,color:r.textColor,marginBottom:"6px",display:"flex",alignItems:"center",gap:"6px"},children:[jsxRuntime.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:r.primaryColor,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[jsxRuntime.jsx("path",{d:"M12 20h9"}),jsxRuntime.jsx("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]}),I.label]}),jsxRuntime.jsx("div",{style:{fontSize:"12px",color:r.mutedTextColor,lineHeight:"1.5",width:"100%",wordWrap:"break-word",whiteSpace:"pre-wrap",direction:C?"rtl":"ltr",textAlign:C?"right":"left"},children:f}),k&&jsxRuntime.jsxs("button",{onClick:i=>{i.stopPropagation(),u(S?null:y);},style:{marginTop:"8px",padding:"4px 8px",fontSize:"11px",color:r.primaryColor,backgroundColor:"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",gap:"4px",fontWeight:500},children:[S?s?s("prompts.showLess"):"Show less":s?s("prompts.showMore"):"Show more",jsxRuntime.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:S?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.2s"},children:jsxRuntime.jsx("polyline",{points:"6 9 12 15 18 9"})})]})]},y)})})]})}function vo(e){let t=Date.now()-e,r=Math.max(1,Math.floor(t/1e3));if(r<60)return `${r}s`;let n=Math.floor(r/60);if(n<60)return `${n}m`;let o=Math.floor(n/60);if(o<24)return `${o}h`;let s=Math.floor(o/24);if(s<7)return `${s}d`;let g=Math.floor(s/7);if(g<4)return `${g}w`;let u=Math.floor(s/30);return u<12?`${u}mo`:`${Math.floor(u/12)}y`}function It({search:e,onSearchChange:t,chats:r,currentChatId:n,resolvedColors:o,onChatSelect:s,onChatDelete:g,className:u,style:C,dir:I="ltr",t:y}){let S=I==="rtl",k=e.trim()?r.filter(f=>(f.title||"").toLowerCase().includes(e.toLowerCase().trim())):r;return jsxRuntime.jsxs("div",{className:u,style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden",direction:S?"rtl":"ltr",...C},children:[jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",gap:"12px",borderBottom:`1px solid ${o.borderColor}`,padding:"12px 16px",flexShrink:0},children:jsxRuntime.jsx("div",{style:{flex:"1"},children:jsxRuntime.jsx("input",{value:e,onChange:f=>t(f.target.value),placeholder:y?y("history.search"):"Search",style:{width:"100%",borderRadius:"8px",backgroundColor:o.inputBackground,padding:"8px 12px",fontSize:"14px",color:o.textColor,border:`1px solid ${o.borderColor}`,outline:"none",direction:S?"rtl":"ltr",textAlign:S?"right":"left"},onFocus:f=>f.currentTarget.style.borderColor=o.primaryColor,onBlur:f=>f.currentTarget.style.borderColor=o.borderColor})})}),jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0"},children:k.length===0?jsxRuntime.jsx("div",{style:{padding:"24px",color:o.mutedTextColor,textAlign:"center"},children:y?y("history.noChatsFound"):"No chats found."}):jsxRuntime.jsx("div",{children:k.map((f,i)=>jsxRuntime.jsx("div",{style:{borderTop:i>0?`1px solid ${o.borderColor}`:"none"},children:jsxRuntime.jsxs("div",{style:{display:"flex",width:"100%",alignItems:"center",justifyContent:"space-between",gap:"12px",padding:"8px 12px",backgroundColor:f.id===n?o.cardBackground:"transparent",transition:"background-color 0.2s"},children:[jsxRuntime.jsx("button",{style:{flex:"1",textAlign:S?"right":"left",transition:"background-color 0.2s",borderRadius:"8px",padding:"8px",border:"none",backgroundColor:"transparent",cursor:"pointer",color:o.textColor,overflow:"hidden"},onMouseEnter:b=>b.currentTarget.style.backgroundColor=o.hoverBackground,onMouseLeave:b=>b.currentTarget.style.backgroundColor="transparent",onClick:()=>s(f.id),children:jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"12px"},children:[jsxRuntime.jsx("div",{style:{minWidth:"0",flex:"1"},children:jsxRuntime.jsx("div",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"14px",color:o.textColor,fontWeight:f.id===n?600:400},children:f.title||(y?y("history.untitledChat"):"Untitled chat")})}),jsxRuntime.jsx("div",{style:{flexShrink:0,fontSize:"12px",color:o.mutedTextColor},children:vo(f.updatedAt)})]})}),jsxRuntime.jsx("button",{style:{flexShrink:0,borderRadius:"6px",padding:"8px",color:o.mutedTextColor,border:"1px solid transparent",backgroundColor:"transparent",cursor:"pointer",transition:"all 0.2s"},title:y?y("history.deleteChat"):"Delete chat",onMouseEnter:b=>{b.currentTarget.style.color=o.dangerColor,b.currentTarget.style.backgroundColor=o.dangerColorLight,b.currentTarget.style.borderColor=`${o.dangerColor}4d`;},onMouseLeave:b=>{b.currentTarget.style.color=o.mutedTextColor,b.currentTarget.style.backgroundColor="transparent",b.currentTarget.style.borderColor="transparent";},onClick:b=>{b.stopPropagation(),g(f.id);},children:jsxRuntime.jsx(X,{IconComponent:lucideReact.Trash2,size:"16",strokeWidth:"2"})})]})},f.id))})})]})}function ar({historyOpen:e,historySearch:t,currentChatId:r,refreshKey:n,resolvedColors:o,onClose:s,onSearchChange:g,onChatSelect:u,onChatDelete:C,loadChatsIndex:I,historyPopupRef:y,dir:S="ltr",t:k}){if(!e)return null;let f=I(),i=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{style:{position:"fixed",inset:"0",zIndex:1100,backgroundColor:"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)"},onClick:s}),jsxRuntime.jsx("div",{ref:y,style:{position:"fixed",left:"50%",top:"64px",transform:"translateX(-50%)",zIndex:1101,width:"680px",maxWidth:"94vw",height:"60vh",maxHeight:"600px",overflow:"hidden",borderRadius:"16px",border:`1px solid ${o.borderColor}`,backgroundColor:`${o.backgroundColor}f0`,boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",display:"flex",flexDirection:"column"},children:jsxRuntime.jsx(It,{search:t,onSearchChange:g,chats:f,currentChatId:r,resolvedColors:o,onChatSelect:u,onChatDelete:C,dir:S,t:k})})]});return typeof document<"u"&&document.body?reactDom.createPortal(i,document.body):i}function To({isOpen:e,historySearch:t,onSearchChange:r,chats:n,currentChatId:o,resolvedColors:s,onChatSelect:g,onChatDelete:u,onNewChat:C,isMobile:I=false,dir:y="ltr",t:S}){let k=y==="rtl";return jsxRuntime.jsxs("div",{style:{width:e?"260px":"0px",opacity:e?1:0,...k?{marginRight:e?0:-10}:{marginLeft:e?0:-10},height:"100%",backgroundColor:s.backgroundColor,...k?{borderLeft:e?`1px solid ${s.borderColor}`:"none"}:{borderRight:e?`1px solid ${s.borderColor}`:"none"},display:"flex",flexDirection:"column",transition:"all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",overflow:"hidden",flexShrink:0,position: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:[jsxRuntime.jsx("div",{style:{padding:"12px",flexShrink:0,opacity:e?1:0,transition:"opacity 0.2s 0.1s"},children:jsxRuntime.jsxs("button",{onClick:C,style:{width:"100%",display:"flex",alignItems:"center",gap:"12px",padding:"10px 12px",borderRadius:"8px",border:`1px solid ${s.borderColor}`,backgroundColor:"transparent",color:s.textColor,cursor:"pointer",fontSize:"14px",transition:"all 0.2s",textAlign:k?"right":"left"},onMouseEnter:f=>f.currentTarget.style.backgroundColor=s.hoverBackground,onMouseLeave:f=>f.currentTarget.style.backgroundColor="transparent",children:[jsxRuntime.jsx(X,{IconComponent:lucideReact.Plus,size:"16",strokeWidth:"2"}),jsxRuntime.jsx("span",{children:S?S("history.newChat"):"New chat"})]})}),jsxRuntime.jsx(It,{search:t,onSearchChange:r,chats:n,currentChatId:o,resolvedColors:s,onChatSelect:g,onChatDelete:u,dir:y,t:S,style:{flex:1}})]})}function ir({isOpen:e,resolvedColors:t,onConfirm:r,onCancel:n,editProcessContent:o,dir:s="ltr",t:g}){if(!e)return null;let u=o?.title||(g?g("editModal.title"):"Edit Message"),C=o?.content||(g?g("editModal.content"):"This will remove this message and all messages after it, and place its content in the input field for editing. Do you want to continue?"),I=o?.submit_button_label||(g?g("editModal.submit"):"Edit"),y=o?.cancel_button_label||(g?g("editModal.cancel"):"Cancel"),S=o?.icon,k=typeof C=="function",f=k?C:null,i=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{style:{position:"fixed",inset:"0",zIndex:1100,backgroundColor:"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)"},onClick:n}),jsxRuntime.jsxs("div",{style:{position:"fixed",left:"50%",top:"50%",transform:"translate(-50%, -50%)",zIndex:1101,width:"420px",maxWidth:"94vw",overflow:"hidden",borderRadius:"16px",border:`1px solid ${t.borderColor}`,backgroundColor:t.backgroundColor,boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",direction:s==="rtl"?"rtl":"ltr"},children:[jsxRuntime.jsxs("div",{style:{padding:"20px 24px",borderBottom:`1px solid ${t.borderColor}`,display:"flex",alignItems:"center",gap:"12px"},children:[S?jsxRuntime.jsx("div",{style:{flexShrink:0},children:jsxRuntime.jsx(X,{IconComponent:S,size:"20",strokeWidth:"2"})}):jsxRuntime.jsx("div",{style:{flexShrink:0,color:t.mutedTextColor},children:jsxRuntime.jsx(X,{IconComponent:lucideReact.Pencil,size:"20",strokeWidth:"2"})}),jsxRuntime.jsx("h3",{style:{margin:0,fontSize:"18px",fontWeight:"600",color:t.textColor,flex:1},children:u})]}),jsxRuntime.jsx("div",{style:{padding:"24px",color:t.textColor,fontSize:"14px",lineHeight:"1.6"},children:k&&f?jsxRuntime.jsx(f,{}):jsxRuntime.jsx("p",{style:{margin:0},children:C})}),jsxRuntime.jsxs("div",{style:{display:"flex",gap:"12px",padding:"16px 24px",borderTop:`1px solid ${t.borderColor}`,justifyContent:"flex-end"},children:[jsxRuntime.jsx("button",{onClick:n,style:{padding:"8px 16px",borderRadius:"8px",fontSize:"14px",fontWeight:"500",border:`1px solid ${t.borderColor}`,backgroundColor:"transparent",color:t.textColor,cursor:"pointer",transition:"all 0.2s"},onMouseEnter:b=>{b.currentTarget.style.backgroundColor=t.hoverBackground;},onMouseLeave:b=>{b.currentTarget.style.backgroundColor="transparent";},children:y}),jsxRuntime.jsx("button",{onClick:r,style:{padding:"8px 16px",borderRadius:"8px",fontSize:"14px",fontWeight:"500",border:"none",backgroundColor:t.primaryColor,color:t.backgroundColor,cursor:"pointer",transition:"all 0.2s",opacity:1},onMouseEnter:b=>{b.currentTarget.style.opacity="0.9";},onMouseLeave:b=>{b.currentTarget.style.opacity="1";},children:I})]})]})]});return typeof document<"u"&&document.body?reactDom.createPortal(i,document.body):i}function Kn({agentId:e,theme:t,primaryColor:r,primaryColorDark:n,primaryColorLight:o,backgroundColor:s,borderColor:g,textColor:u,accentColor:C,errorColor:I,errorColorLight:y,errorColorDark:S,successColor:k,successColorLight:f,warningColor:i,warningColorLight:b,infoColor:c,infoColorLight:d,dangerColor:h,dangerColorLight:l,dangerColorDark:a,dir:M,lang:v,language:x,baseUrl:w="",initialMessages:E=[],onMessagesChange:p,defaultOpen:D=true,floatingButtonPosition:O={bottom:24,right:24},HsafaTools:_={},HsafaUI:oe={},componentAboveInput:le,editProcessContent:ne,presetPrompts:U,onStart:G,onFinish:K,currentChat:B,onChatChanged:fe,templateParams:J,fullPageChat:te=false,title:be,placeholder:ye,emptyStateMessage:Ie,customStyles:Rt}){let {dir:lt,theme:Se,baseUrl:At,setStreamingState:Oe,setChatOpenState:Ge}=ce(),Z=M||lt||"ltr",P=v||x||"en",j=P==="ar",H=t||Se||"dark",ee=w&&w.length>0?w:At||"",T={primaryColor:H==="dark"?n||r||"#ffffff":o||r||"#000000",backgroundColor:s||(H==="dark"?"#0B0B0F":"#FFFFFF"),borderColor:g||(H==="dark"?"#2A2C33":"#E5E7EB"),textColor:u||(H==="dark"?"#EDEEF0":"#111827"),accentColor:C||(H==="dark"?"#17181C":"#F9FAFB"),mutedTextColor:H==="dark"?"#6f7276":"#6B7280",inputBackground:H==="dark"?"#17181C":"#F3F4F6",cardBackground:H==="dark"?"#121318":"#FFFFFF",hoverBackground:H==="dark"?"#1c1e25":"#F3F4F6",errorColor:I||"#ef4444",errorColorLight:y||(H==="dark"?"#fee2e2":"#fef2f2"),errorColorDark:S||"#991b1b",successColor:k||"#10b981",successColorLight:f||(H==="dark"?"rgba(16,185,129,0.15)":"#d1fae5"),warningColor:i||"#eab308",warningColorLight:b||(H==="dark"?"rgba(234,179,8,0.15)":"#fef3c7"),infoColor:c||"#3b82f6",infoColorLight:d||(H==="dark"?"rgba(59,130,246,0.15)":"#dbeafe"),dangerColor:h||"#ef4444",dangerColorLight:l||"rgba(239, 68, 68, 0.1)",dangerColorDark:a||"#991b1b"},z=m=>{let L={"header.new":"New","header.history":"History","header.close":"Close chat","input.placeholder":ye||"Ask your question...","input.prompt":"Prompt","input.attachFiles":"Attach files","input.insertLink":"Insert link","input.send":"Send","input.stop":"Stop","input.uploadingFiles":"Uploading files...","input.previewImage":"Preview image","input.removeFile":"Remove file","messages.empty":Ie||"Start by sending a message to the agent.","general.agent":be||"Agent","editor.cancel":"Cancel","editor.saveAndRegenerate":"Save & Regenerate","editor.clickToEdit":"Click to edit","prompts.suggested":"Suggested Prompts","prompts.showMore":"Show more","prompts.showLess":"Show less","history.search":"Search","history.noChatsFound":"No chats found.","history.untitledChat":"Untitled chat","history.deleteChat":"Delete chat","history.newChat":"New chat","editModal.title":"Edit Message","editModal.content":"This will remove this message and all messages after it, and place its content in the input field for editing. Do you want to continue?","editModal.submit":"Edit","editModal.cancel":"Cancel","assistant.thinking":"Thinking","assistant.finishThinking":"Finish Thinking","tool.inputting":"Inputting","tool.running":"Running","tool.error":"Error","tool.called":"Called","error.occurred":"An error occurred:","error.tryAgain":"Please try again.","error.refresh":"Refresh","error.failedSend":"Failed to send message. Please try again.","error.failedEdit":"Failed to edit message. Please try again."};return (j?{"header.new":"\u062C\u062F\u064A\u062F","header.history":"\u0627\u0644\u0633\u062C\u0644","header.close":"\u0625\u063A\u0644\u0627\u0642 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629","input.placeholder":ye||"\u0627\u0643\u062A\u0628 \u0633\u0624\u0627\u0644\u0643...","input.prompt":"\u0627\u0644\u0631\u0633\u0627\u0644\u0629","input.attachFiles":"\u0625\u0631\u0641\u0627\u0642 \u0645\u0644\u0641\u0627\u062A","input.insertLink":"\u0625\u062F\u0631\u0627\u062C \u0631\u0627\u0628\u0637","input.send":"\u0625\u0631\u0633\u0627\u0644","input.stop":"\u0625\u064A\u0642\u0627\u0641","input.uploadingFiles":"\u062C\u0627\u0631\u064D \u0631\u0641\u0639 \u0627\u0644\u0645\u0644\u0641\u0627\u062A...","input.previewImage":"\u0645\u0639\u0627\u064A\u0646\u0629 \u0627\u0644\u0635\u0648\u0631\u0629","input.removeFile":"\u0625\u0632\u0627\u0644\u0629 \u0627\u0644\u0645\u0644\u0641","messages.empty":Ie||"\u0627\u0628\u062F\u0623 \u0628\u0625\u0631\u0633\u0627\u0644 \u0631\u0633\u0627\u0644\u0629 \u0625\u0644\u0649 \u0627\u0644\u0648\u0643\u064A\u0644.","general.agent":be||"\u0627\u0644\u0648\u0643\u064A\u0644","editor.cancel":"\u0625\u0644\u063A\u0627\u0621","editor.saveAndRegenerate":"\u062D\u0641\u0638 \u0648\u0625\u0639\u0627\u062F\u0629 \u0627\u0644\u062A\u0648\u0644\u064A\u062F","editor.clickToEdit":"\u0627\u0646\u0642\u0631 \u0644\u0644\u062A\u0639\u062F\u064A\u0644","prompts.suggested":"\u0627\u0642\u062A\u0631\u0627\u062D\u0627\u062A \u062C\u0627\u0647\u0632\u0629","prompts.showMore":"\u0639\u0631\u0636 \u0627\u0644\u0645\u0632\u064A\u062F","prompts.showLess":"\u0639\u0631\u0636 \u0623\u0642\u0644","history.search":"\u0628\u062D\u062B","history.noChatsFound":"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A.","history.untitledChat":"\u0645\u062D\u0627\u062F\u062B\u0629 \u0628\u062F\u0648\u0646 \u0639\u0646\u0648\u0627\u0646","history.deleteChat":"\u062D\u0630\u0641 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629","history.newChat":"\u0645\u062D\u0627\u062F\u062B\u0629 \u062C\u062F\u064A\u062F\u0629","editModal.title":"\u062A\u0639\u062F\u064A\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629","editModal.content":"\u0633\u064A\u0624\u062F\u064A \u0647\u0630\u0627 \u0625\u0644\u0649 \u062D\u0630\u0641 \u0647\u0630\u0647 \u0627\u0644\u0631\u0633\u0627\u0644\u0629 \u0648\u0643\u0644 \u0627\u0644\u0631\u0633\u0627\u0626\u0644 \u0627\u0644\u062A\u064A \u0628\u0639\u062F\u0647\u0627\u060C \u062B\u0645 \u0648\u0636\u0639 \u0645\u062D\u062A\u0648\u0627\u0647\u0627 \u0641\u064A \u062D\u0642\u0644 \u0627\u0644\u0625\u062F\u062E\u0627\u0644 \u0644\u0644\u062A\u0639\u062F\u064A\u0644. \u0647\u0644 \u062A\u0631\u064A\u062F \u0627\u0644\u0645\u062A\u0627\u0628\u0639\u0629\u061F","editModal.submit":"\u062A\u0639\u062F\u064A\u0644","editModal.cancel":"\u0625\u0644\u063A\u0627\u0621","assistant.thinking":"\u062C\u0627\u0631\u064D \u0627\u0644\u062A\u0641\u0643\u064A\u0631","assistant.finishThinking":"\u0627\u0646\u062A\u0647\u0649 \u0627\u0644\u062A\u0641\u0643\u064A\u0631","tool.inputting":"\u062C\u0627\u0631\u064D \u0627\u0644\u0625\u062F\u062E\u0627\u0644","tool.running":"\u0642\u064A\u062F \u0627\u0644\u062A\u0634\u063A\u064A\u0644","tool.error":"\u062E\u0637\u0623","tool.called":"\u062A\u0645 \u0627\u0644\u0627\u0633\u062A\u062F\u0639\u0627\u0621","error.occurred":"\u062D\u062F\u062B \u062E\u0637\u0623:","error.tryAgain":"\u064A\u0631\u062C\u0649 \u0627\u0644\u0645\u062D\u0627\u0648\u0644\u0629 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649.","error.refresh":"\u062A\u062D\u062F\u064A\u062B","error.failedSend":"\u062A\u0639\u0630\u0631 \u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629. \u064A\u0631\u062C\u0649 \u0627\u0644\u0645\u062D\u0627\u0648\u0644\u0629 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649.","error.failedEdit":"\u062A\u0639\u0630\u0631 \u062A\u0639\u062F\u064A\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629. \u064A\u0631\u062C\u0649 \u0627\u0644\u0645\u062D\u0627\u0648\u0644\u0629 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649."}:L)[m]||L[m]||m},Eo=Xt({agentId:e,baseUrl:ee,tools:_,uiComponents:oe,templateParams:J,controlledChatId:B,onChatIdChange:B===void 0?m=>{fe&&fe(m);}:void 0,onStart:Io.useCallback(m=>{G&&G(m);},[G]),onFinish:Io.useCallback(m=>{K&&K(m);},[K]),onError:Io.useCallback(m=>{console.error("Chat error:",m);},[]),initialMessages:E,onMessagesChange:p}),{input:je,setInput:Me,messages:ke,isLoading:q,status:lr,error:dt,sendMessage:dr,stop:cr,setMessages:de,notifyMessagesChange:ur,chatId:Lt,setChatId:ct,tools:ta,uiComponents:pr,formHostRef:ra,formStateRef:oa,cleanupForms:_e,onUISuccess:gr,onUIError:mr,chatApi:fr}=Eo,V=B!==void 0?B:Lt,Ee=Io.useCallback(m=>{B===void 0&&ct(m),fe&&fe(m);},[B,ct,fe]);Io.useEffect(()=>{B!==void 0&&B!==Lt&&ct(B);},[B,Lt,ct]);let{attachments:qe,uploading:hr,fileInputRef:Ke,formatBytes:yr,handleRemoveAttachment:xr,handleFileSelection:br,clearAttachments:ut,setAttachments:Cr}=Kr(ee),[pt,Re]=Io.useState(null),[gt,kr]=Io.useState(()=>{try{return bt(e).loadShowChatPreference(!!D)}catch{return !!D}}),[Ht,De]=Io.useState(false),[Ft,Dt]=Io.useState(""),[Bt,Pt]=Io.useState(0),vr=Io.useRef(null),wr=Io.useRef(null),[Tr,Ir]=Io.useState(new Set),[Sr,$t]=Io.useState(false),[Ve,zt]=Io.useState(null),Xe=Io.useRef(null),Mr=Gr(q),[Er,Ro]=Io.useState(false);Io.useEffect(()=>{let m=()=>Ro(window.innerWidth<768);return m(),window.addEventListener("resize",m),()=>window.removeEventListener("resize",m)},[]);let Nt=Jt({agentId:e,chatId:V,messages:ke,isLoading:q,autoSave:true,autoRestore:false}),N=Nt.storage,Rr=Io.useMemo(()=>{try{return N.loadChatsIndex()}catch{return []}},[N,Bt]),Ye=Io.useRef(false),Je=Io.useRef(null);Io.useEffect(()=>{if(!Ye.current){if(B!==void 0){try{let m=N.loadChat(B),L=m&&Array.isArray(m.messages)?m.messages:[];if(L.length>0)try{de(L);}catch{}Je.current=B;}catch{}try{N.saveCurrentChatId(B);}catch{}Ye.current=true;return}try{let m=N.loadCurrentChatId();if(m){Ee(m);let L=N.loadChat(m),$=L&&Array.isArray(L.messages)?L.messages:[];try{de($);}catch{}Je.current=m;}}catch{}Ye.current=true;}},[B]),Io.useEffect(()=>{if(Ye.current&&B!==void 0&&B!==Je.current)try{let m=N.loadChat(B),L=m&&Array.isArray(m.messages)?m.messages:[];try{de(L);}catch{}Je.current=B;try{N.saveCurrentChatId(B);}catch{}}catch{}},[B,N,de]),Io.useEffect(()=>{if(Ye.current)try{N.saveCurrentChatId(V);}catch{}},[V,N]),Io.useEffect(()=>{try{Oe(V,q);}catch{}return ()=>{try{Oe(V,!1);}catch{}}},[V,q,Oe]),Io.useEffect(()=>{try{Ge(V,gt);}catch{}return ()=>{try{Ge(V,!1);}catch{}}},[V,gt,Ge]);let Ar=Io.useCallback(async()=>{let m=je.trim();if(!m&&qe.length===0||q)return;let L=[...qe];Me(""),ut(),Re(null),Xe.current&&Xe.current.focus();try{await dr({text:m,files:L.map($=>({type:"file",url:$.url,mediaType:$.mimeType||"application/octet-stream",...$.name?{name:$.name}:{},...$.size?{size:$.size}:{}}))});}catch($){console.error("Failed to send message:",$),Re(z("error.failedSend"));}},[je,qe,q,dr,ut,z]),Be=Io.useCallback(()=>{if(q)return;_e(),Me(""),ut(),Re(null);try{de([]);}catch{}let m=`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`;Je.current=m;try{Nt.createNewChat(()=>{Ee(m);try{N.saveCurrentChatId(m);}catch{}});}catch{Ee(m);try{N.saveCurrentChatId(m);}catch{}}},[q,ut,N,de,Ee,_e,Nt]),Lr=Io.useCallback(()=>{De(m=>!m);},[]),Ao=Io.useCallback(()=>{kr(false);try{N.saveShowChatPreference(!1);}catch{}},[N]),Hr=Io.useCallback(async m=>{let L=m.target.files;L&&await br(L,Re),Ke.current&&(Ke.current.value="");},[br,Ke]);Io.useEffect(()=>{let m=Xe.current;if(!m)return;m.style.height="24px",m.offsetHeight,m.style.height="auto";let L=Math.min(m.scrollHeight,200);m.style.height=`${L}px`;},[je]);let Fr=Io.useCallback((m,L,$,zr)=>{zt({id:L,text:$,attachments:zr||[]}),$t(true);},[]),Dr=Io.useCallback(()=>{if(!(!Ve||q))try{let m=ke.findIndex($=>$.id===Ve.id);if(m===-1)return;let L=ke.slice(0,m);try{de(L);}catch{}Me(Ve.text),Cr(Ve.attachments),$t(!1),zt(null),ur();}catch(m){console.error("Failed to edit message:",m),Re(z("error.failedEdit"));}},[Ve,q,ke,de,Cr,ur,z]),Br=Io.useCallback(()=>{$t(false),zt(null);},[]),Pr=`
|
|
218
|
+
`}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",direction:f},children:[e.map((u,d)=>{let T=Array.isArray(u.parts)?u.parts:[],i=T.filter(a=>a.type==="text").map(a=>a&&typeof a.text=="string"?a.text:"").join(`
|
|
219
|
+
`),g=T.filter(a=>a.type==="file"||a.type==="image").map(a=>{if(a.type==="image"){let w=typeof a.image=="string"?a.image:a.image?.toString?.()||"";return {id:w||`${u.id}-img-${Date.now()}`,name:a.name||"image",url:w,mimeType:a.mediaType||"image/jpeg",size:a.size||0}}else return {id:a.url||`${u.id}-file-${Date.now()}`,name:a.name||"file",url:a.url||"",mimeType:a.mediaType||"application/octet-stream",size:a.size||0}});return jsxRuntime.jsx("div",{style:{padding:"0 4px",display:"flex",flexDirection:"column",alignItems:u.role==="user"&&v?"flex-end":"stretch"},children:u.role==="user"?jsxRuntime.jsx("div",{style:{maxWidth:v?"80%":"100%"},children:jsxRuntime.jsx("div",{title:l("editor.clickToEdit"),onClick:()=>p(u,u.id,i,g),style:{maxWidth:v?"100%":"720px",borderRadius:v?"20px":"16px",padding:"12px 16px",fontSize:"15px",lineHeight:"1.6",whiteSpace:"pre-wrap",cursor:"pointer",transition:"background-color 0.2s",backgroundColor:v?o.inputBackground:o.accentColor,color:o.textColor,marginBottom:"16px",marginTop:"16px",position:"relative",border:v?`1px solid ${o.borderColor}`:"none"},onMouseEnter:a=>a.currentTarget.style.backgroundColor=o.hoverBackground,onMouseLeave:a=>a.currentTarget.style.backgroundColor=v?o.inputBackground:o.accentColor,children:jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsxs("div",{style:{flex:1},children:[i,g.length>0&&jsxRuntime.jsx(ko,{attachments:g,resolvedColors:o})]}),jsxRuntime.jsx("div",{style:{flexShrink:0,opacity:.5,transition:"opacity 0.2s"},children:jsxRuntime.jsx(X,{IconComponent:M||lucideReact.Pencil,size:"14",strokeWidth:"2"})})]})})}):jsxRuntime.jsx(yo,{parts:T,messageId:u.id,openReasoningIds:r,toggleReasoning:n,resolvedColors:o,HsafaUI:c,onUIError:b,onUISuccess:S,addToolResult:h,dir:f,t:l,theme:s})},u.id)}),t&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",padding:"0 4px",height:"20px"},children:[jsxRuntime.jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0s"}}),jsxRuntime.jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0.2s"}}),jsxRuntime.jsx("span",{style:{display:"inline-block",width:"4px",height:"4px",borderRadius:"50%",backgroundColor:o.mutedTextColor,animation:"jumpingDots 1s infinite ease-in-out",animationDelay:"0.4s"}})]})]})]})}function tr({input:e,setInput:t,textareaRef:r,fileInputRef:n,isLoading:o,uploading:l,attachments:p,formatBytes:c,handleRemoveAttachment:b,onFileInputChange:S,onSend:h,onStop:M,status:v,t:f,resolvedColors:s,fullPage:u,dir:d="ltr"}){let T=v==="streaming"||v==="submitted",i=p.length>0||e.trim().length>0,g=d==="rtl";return u?jsxRuntime.jsxs("div",{style:{position:"relative",width:"100%",maxWidth:"768px",margin:"0 auto"},children:[jsxRuntime.jsxs("div",{style:{position:"relative",width:"100%",borderRadius:"26px",padding:g?"14px 48px 14px 14px":"14px 14px 14px 48px",backgroundColor:s.inputBackground,boxShadow:"0 0 0 1px rgba(0,0,0,0.05)",transition:"box-shadow 0.2s ease",direction:g?"rtl":"ltr"},onFocus:a=>{},children:[jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"10px",...g?{right:"12px"}:{left:"12px"},zIndex:10},children:jsxRuntime.jsx("button",{onClick:()=>n.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:s.textColor,opacity:o||l?.5:.7},"aria-label":f("input.attachFiles"),onMouseEnter:a=>{!o&&!l&&(a.currentTarget.style.backgroundColor=s.hoverBackground,a.currentTarget.style.opacity="1");},onMouseLeave:a=>{a.currentTarget.style.backgroundColor="transparent",a.currentTarget.style.opacity="0.7";},children:jsxRuntime.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M12 5v14M5 12h14"})})})}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[p.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",paddingBottom:"8px",...g?{marginRight:"-4px",justifyContent:"flex-end"}:{marginLeft:"-4px"}},children:p.map(a=>{let w=a.mimeType.startsWith("image/");return jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 10px",backgroundColor:s.cardBackground,borderRadius:"8px",border:`1px solid ${s.borderColor}`,fontSize:"12px",color:s.textColor,position:"relative"},children:[jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",borderRadius:"4px",backgroundColor:w?"transparent":s.inputBackground},children:w?jsxRuntime.jsx("img",{src:a.url,alt:a.name,style:{width:"20px",height:"20px",borderRadius:"4px",objectFit:"cover"}}):jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("rect",{x:"4",y:"4",width:"16",height:"20",rx:"2",ry:"2"})})}),jsxRuntime.jsx("span",{title:a.name,style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:a.name}),jsxRuntime.jsx("button",{onClick:()=>b(a.id),style:{background:"none",border:"none",color:s.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px"},children:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},a.id)})}),l&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:s.mutedTextColor},children:[jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"spin 1s linear infinite"},children:jsxRuntime.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsxRuntime.jsx("span",{children:f("input.uploadingFiles")})]}),jsxRuntime.jsx("div",{style:{...g?{paddingLeft:"40px"}:{paddingRight:"40px"},display:"flex",alignItems:"center"},children:jsxRuntime.jsx("textarea",{ref:r,"aria-label":f("input.prompt"),rows:1,placeholder:f("input.placeholder"),value:e,onChange:a=>t(a.target.value),onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),h());},disabled:l,style:{maxHeight:"200px",width:"100%",resize:"none",backgroundColor:"transparent",fontSize:"16px",lineHeight:"1.5",outline:"none",border:"none",color:s.textColor,fontFamily:"inherit",overflow:"auto",padding:0,margin:0,direction:g?"rtl":"ltr",textAlign:g?"right":"left"}})})]}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"8px",...g?{left:"8px"}:{right:"8px"}},children:o?jsxRuntime.jsx("button",{onClick:M,disabled:!T,"aria-label":f("input.stop"),style:{borderRadius:"50%",width:"36px",height:"36px",transition:"all 0.2s ease-out",backgroundColor:s.textColor,color:s.inputBackground,border:"none",opacity:T?1:.7,cursor:T?"pointer":"not-allowed",display:"flex",alignItems:"center",justifyContent:"center"},children:jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:jsxRuntime.jsx("rect",{width:"24",height:"24",rx:"2"})})}):jsxRuntime.jsx("button",{onClick:h,disabled:!i||l,"aria-label":f("input.send"),style:{borderRadius:"50%",width:"36px",height:"36px",transition:"all 0.2s ease-out",backgroundColor:!i||l?s.cardBackground:s.textColor,color:!i||l?s.mutedTextColor:s.inputBackground,border:"none",cursor:!i||l?"default":"pointer",display:"flex",alignItems:"center",justifyContent:"center",transform:g?"rotate(180deg)":""},children:jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"M5 12h14"}),jsxRuntime.jsx("path",{d:"M12 5l7 7-7 7"})]})})})]}),jsxRuntime.jsx("input",{ref:n,type:"file",multiple:true,onChange:S,style:{display:"none"},accept:"*/*"}),jsxRuntime.jsx("div",{style:{textAlign:"center",padding:"8px 0",fontSize:"12px",color:s.mutedTextColor,opacity:.8},children:"AI can make mistakes. Please check important information."})]}):jsxRuntime.jsx("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px",paddingTop:"4px"},children:jsxRuntime.jsx("div",{style:{position:"relative",flex:1},children:jsxRuntime.jsxs("div",{style:{position:"relative",width:"100%",borderRadius:"16px",paddingBottom:"48px",paddingTop:"16px",border:`1px solid ${s.borderColor}`,backgroundColor:s.cardBackground},children:[p.length>0&&jsxRuntime.jsx("div",{style:{padding:"0px 16px 12px 16px",display:"flex",flexWrap:"wrap",gap:"10px"},children:p.map(a=>{let w=a.mimeType.startsWith("image/");return jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",backgroundColor:s.inputBackground,borderRadius:"10px",border:`1px solid ${s.borderColor}`,fontSize:"12px",color:s.textColor,position:"relative"},children:[jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"20px",height:"20px",borderRadius:"4px",backgroundColor:w?"transparent":s.cardBackground},children:w?jsxRuntime.jsx("img",{src:a.url,alt:a.name,style:{width:"20px",height:"20px",borderRadius:"4px",objectFit:"cover"}}):jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:jsxRuntime.jsx("rect",{x:"4",y:"4",width:"16",height:"20",rx:"2",ry:"2"})})}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",minWidth:0,flex:1},children:[jsxRuntime.jsx("span",{title:a.name,style:{maxWidth:"140px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:500},children:a.name}),jsxRuntime.jsx("span",{style:{color:s.mutedTextColor,fontSize:"10px",marginTop:"2px"},children:c(a.size)})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginLeft:"8px"},children:[w&&jsxRuntime.jsx("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",style:{background:"none",border:"none",color:s.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px",textDecoration:"none"},title:f("input.previewImage"),children:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),jsxRuntime.jsx("button",{onClick:()=>b(a.id),style:{background:"none",border:"none",color:s.mutedTextColor,cursor:"pointer",padding:"2px",display:"flex",alignItems:"center",borderRadius:"4px"},title:f("input.removeFile"),children:jsxRuntime.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),jsxRuntime.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]},a.id)})}),l&&jsxRuntime.jsxs("div",{style:{padding:"0px 16px 12px 16px",display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",color:s.mutedTextColor},children:[jsxRuntime.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{animation:"spin 1s linear infinite"},children:jsxRuntime.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),jsxRuntime.jsx("span",{children:f("input.uploadingFiles")})]}),jsxRuntime.jsx("div",{style:{padding:"0 16px"},children:jsxRuntime.jsx("textarea",{ref:r,"aria-label":f("input.prompt"),rows:1,placeholder:f("input.placeholder"),value:e,onChange:a=>t(a.target.value),onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),h());},disabled:l,style:{height:"24px",maxHeight:"200px",width:"100%",resize:"none",backgroundColor:"transparent",fontSize:"15px",lineHeight:"1.6",outline:"none",border:"none",color:s.textColor,fontFamily:"inherit",overflow:"auto",direction:g?"rtl":"ltr",textAlign:g?"right":"left"}})}),jsxRuntime.jsx("input",{ref:n,type:"file",multiple:true,onChange:S,style:{display:"none"},accept:"*/*"}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"8px",...g?{right:"8px"}:{left:"8px"},display:"flex",alignItems:"center",gap:"4px",color:s.mutedTextColor},children:jsxRuntime.jsx("button",{onClick:()=>n.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":f("input.attachFiles"),children:jsxRuntime.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 1 1 5.66 5.66l-9.2 9.19a2 2 0 1 1-2.83-2.83l8.49-8.49"})})})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:"8px",...g?{left:"8px"}:{right:"8px"}},children:o?jsxRuntime.jsx("button",{onClick:M,disabled:!T,"aria-label":f("input.stop"),title:"Stop generation",style:{borderRadius:"12px",padding:"12px",transition:"all 0.2s ease-out",border:`1px solid ${s.errorColor}`,backgroundColor:s.errorColorLight||`${s.errorColor}20`,color:s.errorColor,opacity:T?1:.4,cursor:T?"pointer":"not-allowed",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:a=>{T&&(a.currentTarget.style.backgroundColor=s.errorColorLight||`${s.errorColor}30`,a.currentTarget.style.transform="scale(1.02)");},onMouseLeave:a=>{a.currentTarget.style.backgroundColor=s.errorColorLight||`${s.errorColor}20`,a.currentTarget.style.transform="scale(1)";},children:jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"})})}):jsxRuntime.jsx("button",{onClick:h,disabled:!i||l,"aria-label":f("input.send"),title:"Send message",style:{borderRadius:"12px",padding:"12px",transition:"all 0.2s ease-out",border:`1px solid ${s.borderColor}`,backgroundColor:s.cardBackground,color:!i||l?s.mutedTextColor:s.primaryColor,cursor:!i||l?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",opacity:!i||l?.5:1},onMouseEnter:a=>{i&&!l&&(a.currentTarget.style.borderColor=s.primaryColor,a.currentTarget.style.transform="scale(1.02)");},onMouseLeave:a=>{a.currentTarget.style.borderColor=s.borderColor,a.currentTarget.style.transform="scale(1)";},children:jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"m5 12 7-7 7 7"}),jsxRuntime.jsx("path",{d:"M12 19V5"})]})})})]})})})}function rr({prompts:e,onSelect:t,resolvedColors:r,disabled:n=false,dir:o="ltr",t:l}){let[p,c]=Io.useState(null),b=o==="rtl";return !e||e.length===0?null:jsxRuntime.jsxs("div",{style:{padding:"12px 0",display:"flex",flexDirection:"column",gap:"8px",direction:b?"rtl":"ltr"},children:[jsxRuntime.jsx("div",{style:{fontSize:"12px",fontWeight:600,color:r.mutedTextColor,...b?{paddingRight:"4px",textAlign:"right"}:{paddingLeft:"4px",textAlign:"left"},textTransform:"uppercase",letterSpacing:"0.5px"},children:l?l("prompts.suggested"):"Suggested Prompts"}),jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((S,h)=>{let M=p===h,v=S.prompt.length>180,f=v&&!M?S.prompt.slice(0,180)+"...":S.prompt;return jsxRuntime.jsxs("button",{onClick:()=>{n||t(S.prompt);},disabled:n,style:{display:"flex",flexDirection:"column",padding:"12px",backgroundColor:r.cardBackground,border:`1px solid ${r.borderColor}`,borderRadius:"12px",cursor:n?"not-allowed":"pointer",transition:"all 0.2s ease",textAlign:b?"right":"left",opacity:n?.5:1,position:"relative",overflow:"hidden"},onMouseEnter:s=>{n||(s.currentTarget.style.backgroundColor=r.hoverBackground,s.currentTarget.style.borderColor=r.primaryColor,s.currentTarget.style.transform=b?"translateX(-2px)":"translateX(2px)");},onMouseLeave:s=>{s.currentTarget.style.backgroundColor=r.cardBackground,s.currentTarget.style.borderColor=r.borderColor,s.currentTarget.style.transform="translateX(0)";},children:[jsxRuntime.jsxs("div",{style:{fontSize:"13px",fontWeight:600,color:r.textColor,marginBottom:"6px",display:"flex",alignItems:"center",gap:"6px"},children:[jsxRuntime.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:r.primaryColor,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[jsxRuntime.jsx("path",{d:"M12 20h9"}),jsxRuntime.jsx("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]}),S.label]}),jsxRuntime.jsx("div",{style:{fontSize:"12px",color:r.mutedTextColor,lineHeight:"1.5",width:"100%",wordWrap:"break-word",whiteSpace:"pre-wrap",direction:b?"rtl":"ltr",textAlign:b?"right":"left"},children:f}),v&&jsxRuntime.jsxs("button",{onClick:s=>{s.stopPropagation(),c(M?null:h);},style:{marginTop:"8px",padding:"4px 8px",fontSize:"11px",color:r.primaryColor,backgroundColor:"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",gap:"4px",fontWeight:500},children:[M?l?l("prompts.showLess"):"Show less":l?l("prompts.showMore"):"Show more",jsxRuntime.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:M?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.2s"},children:jsxRuntime.jsx("polyline",{points:"6 9 12 15 18 9"})})]})]},h)})})]})}function vo(e){let t=Date.now()-e,r=Math.max(1,Math.floor(t/1e3));if(r<60)return `${r}s`;let n=Math.floor(r/60);if(n<60)return `${n}m`;let o=Math.floor(n/60);if(o<24)return `${o}h`;let l=Math.floor(o/24);if(l<7)return `${l}d`;let p=Math.floor(l/7);if(p<4)return `${p}w`;let c=Math.floor(l/30);return c<12?`${c}mo`:`${Math.floor(c/12)}y`}function It({search:e,onSearchChange:t,chats:r,currentChatId:n,resolvedColors:o,onChatSelect:l,onChatDelete:p,className:c,style:b,dir:S="ltr",t:h}){let M=S==="rtl",v=e.trim()?r.filter(f=>(f.title||"").toLowerCase().includes(e.toLowerCase().trim())):r;return jsxRuntime.jsxs("div",{className:c,style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden",direction:M?"rtl":"ltr",...b},children:[jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",gap:"12px",borderBottom:`1px solid ${o.borderColor}`,padding:"12px 16px",flexShrink:0},children:jsxRuntime.jsx("div",{style:{flex:"1"},children:jsxRuntime.jsx("input",{value:e,onChange:f=>t(f.target.value),placeholder:h?h("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:M?"rtl":"ltr",textAlign:M?"right":"left"},onFocus:f=>f.currentTarget.style.borderColor=o.primaryColor,onBlur:f=>f.currentTarget.style.borderColor=o.borderColor})})}),jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0"},children:v.length===0?jsxRuntime.jsx("div",{style:{padding:"24px",color:o.mutedTextColor,textAlign:"center"},children:h?h("history.noChatsFound"):"No chats found."}):jsxRuntime.jsx("div",{children:v.map((f,s)=>jsxRuntime.jsx("div",{style:{borderTop:s>0?`1px solid ${o.borderColor}`:"none"},children:jsxRuntime.jsxs("div",{style:{display:"flex",width:"100%",alignItems:"center",justifyContent:"space-between",gap:"12px",padding:"8px 12px",backgroundColor:f.id===n?o.cardBackground:"transparent",transition:"background-color 0.2s"},children:[jsxRuntime.jsx("button",{style:{flex:"1",textAlign:M?"right":"left",transition:"background-color 0.2s",borderRadius:"8px",padding:"8px",border:"none",backgroundColor:"transparent",cursor:"pointer",color:o.textColor,overflow:"hidden"},onMouseEnter:u=>u.currentTarget.style.backgroundColor=o.hoverBackground,onMouseLeave:u=>u.currentTarget.style.backgroundColor="transparent",onClick:()=>l(f.id),children:jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"12px"},children:[jsxRuntime.jsx("div",{style:{minWidth:"0",flex:"1"},children:jsxRuntime.jsx("div",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"14px",color:o.textColor,fontWeight:f.id===n?600:400},children:f.title||(h?h("history.untitledChat"):"Untitled chat")})}),jsxRuntime.jsx("div",{style:{flexShrink:0,fontSize:"12px",color:o.mutedTextColor},children:vo(f.updatedAt)})]})}),jsxRuntime.jsx("button",{style:{flexShrink:0,borderRadius:"6px",padding:"8px",color:o.mutedTextColor,border:"1px solid transparent",backgroundColor:"transparent",cursor:"pointer",transition:"all 0.2s"},title:h?h("history.deleteChat"):"Delete chat",onMouseEnter:u=>{u.currentTarget.style.color=o.dangerColor,u.currentTarget.style.backgroundColor=o.dangerColorLight,u.currentTarget.style.borderColor=`${o.dangerColor}4d`;},onMouseLeave:u=>{u.currentTarget.style.color=o.mutedTextColor,u.currentTarget.style.backgroundColor="transparent",u.currentTarget.style.borderColor="transparent";},onClick:u=>{u.stopPropagation(),p(f.id);},children:jsxRuntime.jsx(X,{IconComponent:lucideReact.Trash2,size:"16",strokeWidth:"2"})})]})},f.id))})})]})}function ar({historyOpen:e,historySearch:t,currentChatId:r,refreshKey:n,resolvedColors:o,onClose:l,onSearchChange:p,onChatSelect:c,onChatDelete:b,loadChatsIndex:S,historyPopupRef:h,dir:M="ltr",t:v}){if(!e)return null;let f=S(),s=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{style:{position:"fixed",inset:"0",zIndex:1100,backgroundColor:"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)"},onClick:l}),jsxRuntime.jsx("div",{ref:h,style:{position:"fixed",left:"50%",top:"64px",transform:"translateX(-50%)",zIndex:1101,width:"680px",maxWidth:"94vw",height:"60vh",maxHeight:"600px",overflow:"hidden",borderRadius:"16px",border:`1px solid ${o.borderColor}`,backgroundColor:`${o.backgroundColor}f0`,boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",display:"flex",flexDirection:"column"},children:jsxRuntime.jsx(It,{search:t,onSearchChange:p,chats:f,currentChatId:r,resolvedColors:o,onChatSelect:c,onChatDelete:b,dir:M,t:v})})]});return typeof document<"u"&&document.body?reactDom.createPortal(s,document.body):s}function To({isOpen:e,historySearch:t,onSearchChange:r,chats:n,currentChatId:o,resolvedColors:l,onChatSelect:p,onChatDelete:c,onNewChat:b,isMobile:S=false,dir:h="ltr",t:M}){let v=h==="rtl";return jsxRuntime.jsxs("div",{style:{width:e?"260px":"0px",opacity:e?1:0,...v?{marginRight:e?0:-10}:{marginLeft:e?0:-10},height:"100%",backgroundColor:l.backgroundColor,...v?{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:S?"fixed":"relative",zIndex:S?100:1,...v?{right:0}:{left:0},top:0,bottom:0,visibility:e?"visible":"hidden",direction:v?"rtl":"ltr"},children:[jsxRuntime.jsx("div",{style:{padding:"12px",flexShrink:0,opacity:e?1:0,transition:"opacity 0.2s 0.1s"},children:jsxRuntime.jsxs("button",{onClick:b,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:v?"right":"left"},onMouseEnter:f=>f.currentTarget.style.backgroundColor=l.hoverBackground,onMouseLeave:f=>f.currentTarget.style.backgroundColor="transparent",children:[jsxRuntime.jsx(X,{IconComponent:lucideReact.Plus,size:"16",strokeWidth:"2"}),jsxRuntime.jsx("span",{children:M?M("history.newChat"):"New chat"})]})}),jsxRuntime.jsx(It,{search:t,onSearchChange:r,chats:n,currentChatId:o,resolvedColors:l,onChatSelect:p,onChatDelete:c,dir:h,t:M,style:{flex:1}})]})}function ir({isOpen:e,resolvedColors:t,onConfirm:r,onCancel:n,editProcessContent:o,dir:l="ltr",t:p}){if(!e)return null;let c=o?.title||(p?p("editModal.title"):"Edit Message"),b=o?.content||(p?p("editModal.content"):"This will remove this message and all messages after it, and place its content in the input field for editing. Do you want to continue?"),S=o?.submit_button_label||(p?p("editModal.submit"):"Edit"),h=o?.cancel_button_label||(p?p("editModal.cancel"):"Cancel"),M=o?.icon,v=typeof b=="function",f=v?b:null,s=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{style:{position:"fixed",inset:"0",zIndex:1100,backgroundColor:"rgba(0, 0, 0, 0.4)",backdropFilter:"blur(4px)",WebkitBackdropFilter:"blur(4px)"},onClick:n}),jsxRuntime.jsxs("div",{style:{position:"fixed",left:"50%",top:"50%",transform:"translate(-50%, -50%)",zIndex:1101,width:"420px",maxWidth:"94vw",overflow:"hidden",borderRadius:"16px",border:`1px solid ${t.borderColor}`,backgroundColor:t.backgroundColor,boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",direction:l==="rtl"?"rtl":"ltr"},children:[jsxRuntime.jsxs("div",{style:{padding:"20px 24px",borderBottom:`1px solid ${t.borderColor}`,display:"flex",alignItems:"center",gap:"12px"},children:[M?jsxRuntime.jsx("div",{style:{flexShrink:0},children:jsxRuntime.jsx(X,{IconComponent:M,size:"20",strokeWidth:"2"})}):jsxRuntime.jsx("div",{style:{flexShrink:0,color:t.mutedTextColor},children:jsxRuntime.jsx(X,{IconComponent:lucideReact.Pencil,size:"20",strokeWidth:"2"})}),jsxRuntime.jsx("h3",{style:{margin:0,fontSize:"18px",fontWeight:"600",color:t.textColor,flex:1},children:c})]}),jsxRuntime.jsx("div",{style:{padding:"24px",color:t.textColor,fontSize:"14px",lineHeight:"1.6"},children:v&&f?jsxRuntime.jsx(f,{}):jsxRuntime.jsx("p",{style:{margin:0},children:b})}),jsxRuntime.jsxs("div",{style:{display:"flex",gap:"12px",padding:"16px 24px",borderTop:`1px solid ${t.borderColor}`,justifyContent:"flex-end"},children:[jsxRuntime.jsx("button",{onClick:n,style:{padding:"8px 16px",borderRadius:"8px",fontSize:"14px",fontWeight:"500",border:`1px solid ${t.borderColor}`,backgroundColor:"transparent",color:t.textColor,cursor:"pointer",transition:"all 0.2s"},onMouseEnter:u=>{u.currentTarget.style.backgroundColor=t.hoverBackground;},onMouseLeave:u=>{u.currentTarget.style.backgroundColor="transparent";},children:h}),jsxRuntime.jsx("button",{onClick:r,style:{padding:"8px 16px",borderRadius:"8px",fontSize:"14px",fontWeight:"500",border:"none",backgroundColor:t.primaryColor,color:t.backgroundColor,cursor:"pointer",transition:"all 0.2s",opacity:1},onMouseEnter:u=>{u.currentTarget.style.opacity="0.9";},onMouseLeave:u=>{u.currentTarget.style.opacity="1";},children:S})]})]})]});return typeof document<"u"&&document.body?reactDom.createPortal(s,document.body):s}function Kn({agentId:e,theme:t,primaryColor:r,primaryColorDark:n,primaryColorLight:o,backgroundColor:l,borderColor:p,textColor:c,accentColor:b,errorColor:S,errorColorLight:h,errorColorDark:M,successColor:v,successColorLight:f,warningColor:s,warningColorLight:u,infoColor:d,infoColorLight:T,dangerColor:i,dangerColorLight:g,dangerColorDark:a,dir:w,lang:C,language:y,baseUrl:k="",initialMessages:E=[],onMessagesChange:x,defaultOpen:L=true,floatingButtonPosition:N={bottom:24,right:24},HsafaTools:K={},HsafaUI:ee={},componentAboveInput:re,editProcessContent:ae,presetPrompts:O,onStart:G,onFinish:q,currentChat:B,onChatChanged:fe,templateParams:J,fullPageChat:oe=false,title:be,placeholder:ye,emptyStateMessage:Ie,customStyles:Rt}){let {dir:lt,theme:Se,baseUrl:At,setStreamingState:Oe,setChatOpenState:Ge}=ce(),Z=w||lt||"ltr",P=C||y||"en",j=P==="ar",H=t||Se||"dark",te=k&&k.length>0?k:At||"",I={primaryColor:H==="dark"?n||r||"#ffffff":o||r||"#000000",backgroundColor:l||(H==="dark"?"#0B0B0F":"#FFFFFF"),borderColor:p||(H==="dark"?"#2A2C33":"#E5E7EB"),textColor:c||(H==="dark"?"#EDEEF0":"#111827"),accentColor:b||(H==="dark"?"#17181C":"#F9FAFB"),mutedTextColor:H==="dark"?"#6f7276":"#6B7280",inputBackground:H==="dark"?"#17181C":"#F3F4F6",cardBackground:H==="dark"?"#121318":"#FFFFFF",hoverBackground:H==="dark"?"#1c1e25":"#F3F4F6",errorColor:S||"#ef4444",errorColorLight:h||(H==="dark"?"#fee2e2":"#fef2f2"),errorColorDark:M||"#991b1b",successColor:v||"#10b981",successColorLight:f||(H==="dark"?"rgba(16,185,129,0.15)":"#d1fae5"),warningColor:s||"#eab308",warningColorLight:u||(H==="dark"?"rgba(234,179,8,0.15)":"#fef3c7"),infoColor:d||"#3b82f6",infoColorLight:T||(H==="dark"?"rgba(59,130,246,0.15)":"#dbeafe"),dangerColor:i||"#ef4444",dangerColorLight:g||"rgba(239, 68, 68, 0.1)",dangerColorDark:a||"#991b1b"},z=m=>{let F={"header.new":"New","header.history":"History","header.close":"Close chat","input.placeholder":ye||"Ask your question...","input.prompt":"Prompt","input.attachFiles":"Attach files","input.insertLink":"Insert link","input.send":"Send","input.stop":"Stop","input.uploadingFiles":"Uploading files...","input.previewImage":"Preview image","input.removeFile":"Remove file","messages.empty":Ie||"Start by sending a message to the agent.","general.agent":be||"Agent","editor.cancel":"Cancel","editor.saveAndRegenerate":"Save & Regenerate","editor.clickToEdit":"Click to edit","prompts.suggested":"Suggested Prompts","prompts.showMore":"Show more","prompts.showLess":"Show less","history.search":"Search","history.noChatsFound":"No chats found.","history.untitledChat":"Untitled chat","history.deleteChat":"Delete chat","history.newChat":"New chat","editModal.title":"Edit Message","editModal.content":"This will remove this message and all messages after it, and place its content in the input field for editing. Do you want to continue?","editModal.submit":"Edit","editModal.cancel":"Cancel","assistant.thinking":"Thinking","assistant.finishThinking":"Finish Thinking","tool.inputting":"Inputting","tool.running":"Running","tool.error":"Error","tool.called":"Called","error.occurred":"An error occurred:","error.tryAgain":"Please try again.","error.refresh":"Refresh","error.failedSend":"Failed to send message. Please try again.","error.failedEdit":"Failed to edit message. Please try again."};return (j?{"header.new":"\u062C\u062F\u064A\u062F","header.history":"\u0627\u0644\u0633\u062C\u0644","header.close":"\u0625\u063A\u0644\u0627\u0642 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629","input.placeholder":ye||"\u0627\u0643\u062A\u0628 \u0633\u0624\u0627\u0644\u0643...","input.prompt":"\u0627\u0644\u0631\u0633\u0627\u0644\u0629","input.attachFiles":"\u0625\u0631\u0641\u0627\u0642 \u0645\u0644\u0641\u0627\u062A","input.insertLink":"\u0625\u062F\u0631\u0627\u062C \u0631\u0627\u0628\u0637","input.send":"\u0625\u0631\u0633\u0627\u0644","input.stop":"\u0625\u064A\u0642\u0627\u0641","input.uploadingFiles":"\u062C\u0627\u0631\u064D \u0631\u0641\u0639 \u0627\u0644\u0645\u0644\u0641\u0627\u062A...","input.previewImage":"\u0645\u0639\u0627\u064A\u0646\u0629 \u0627\u0644\u0635\u0648\u0631\u0629","input.removeFile":"\u0625\u0632\u0627\u0644\u0629 \u0627\u0644\u0645\u0644\u0641","messages.empty":Ie||"\u0627\u0628\u062F\u0623 \u0628\u0625\u0631\u0633\u0627\u0644 \u0631\u0633\u0627\u0644\u0629 \u0625\u0644\u0649 \u0627\u0644\u0648\u0643\u064A\u0644.","general.agent":be||"\u0627\u0644\u0648\u0643\u064A\u0644","editor.cancel":"\u0625\u0644\u063A\u0627\u0621","editor.saveAndRegenerate":"\u062D\u0641\u0638 \u0648\u0625\u0639\u0627\u062F\u0629 \u0627\u0644\u062A\u0648\u0644\u064A\u062F","editor.clickToEdit":"\u0627\u0646\u0642\u0631 \u0644\u0644\u062A\u0639\u062F\u064A\u0644","prompts.suggested":"\u0627\u0642\u062A\u0631\u0627\u062D\u0627\u062A \u062C\u0627\u0647\u0632\u0629","prompts.showMore":"\u0639\u0631\u0636 \u0627\u0644\u0645\u0632\u064A\u062F","prompts.showLess":"\u0639\u0631\u0636 \u0623\u0642\u0644","history.search":"\u0628\u062D\u062B","history.noChatsFound":"\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u062D\u0627\u062F\u062B\u0627\u062A.","history.untitledChat":"\u0645\u062D\u0627\u062F\u062B\u0629 \u0628\u062F\u0648\u0646 \u0639\u0646\u0648\u0627\u0646","history.deleteChat":"\u062D\u0630\u0641 \u0627\u0644\u0645\u062D\u0627\u062F\u062B\u0629","history.newChat":"\u0645\u062D\u0627\u062F\u062B\u0629 \u062C\u062F\u064A\u062F\u0629","editModal.title":"\u062A\u0639\u062F\u064A\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629","editModal.content":"\u0633\u064A\u0624\u062F\u064A \u0647\u0630\u0627 \u0625\u0644\u0649 \u062D\u0630\u0641 \u0647\u0630\u0647 \u0627\u0644\u0631\u0633\u0627\u0644\u0629 \u0648\u0643\u0644 \u0627\u0644\u0631\u0633\u0627\u0626\u0644 \u0627\u0644\u062A\u064A \u0628\u0639\u062F\u0647\u0627\u060C \u062B\u0645 \u0648\u0636\u0639 \u0645\u062D\u062A\u0648\u0627\u0647\u0627 \u0641\u064A \u062D\u0642\u0644 \u0627\u0644\u0625\u062F\u062E\u0627\u0644 \u0644\u0644\u062A\u0639\u062F\u064A\u0644. \u0647\u0644 \u062A\u0631\u064A\u062F \u0627\u0644\u0645\u062A\u0627\u0628\u0639\u0629\u061F","editModal.submit":"\u062A\u0639\u062F\u064A\u0644","editModal.cancel":"\u0625\u0644\u063A\u0627\u0621","assistant.thinking":"\u062C\u0627\u0631\u064D \u0627\u0644\u062A\u0641\u0643\u064A\u0631","assistant.finishThinking":"\u0627\u0646\u062A\u0647\u0649 \u0627\u0644\u062A\u0641\u0643\u064A\u0631","tool.inputting":"\u062C\u0627\u0631\u064D \u0627\u0644\u0625\u062F\u062E\u0627\u0644","tool.running":"\u0642\u064A\u062F \u0627\u0644\u062A\u0634\u063A\u064A\u0644","tool.error":"\u062E\u0637\u0623","tool.called":"\u062A\u0645 \u0627\u0644\u0627\u0633\u062A\u062F\u0639\u0627\u0621","error.occurred":"\u062D\u062F\u062B \u062E\u0637\u0623:","error.tryAgain":"\u064A\u0631\u062C\u0649 \u0627\u0644\u0645\u062D\u0627\u0648\u0644\u0629 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649.","error.refresh":"\u062A\u062D\u062F\u064A\u062B","error.failedSend":"\u062A\u0639\u0630\u0631 \u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629. \u064A\u0631\u062C\u0649 \u0627\u0644\u0645\u062D\u0627\u0648\u0644\u0629 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649.","error.failedEdit":"\u062A\u0639\u0630\u0631 \u062A\u0639\u062F\u064A\u0644 \u0627\u0644\u0631\u0633\u0627\u0644\u0629. \u064A\u0631\u062C\u0649 \u0627\u0644\u0645\u062D\u0627\u0648\u0644\u0629 \u0645\u0631\u0629 \u0623\u062E\u0631\u0649."}:F)[m]||F[m]||m},Eo=Xt({agentId:e,baseUrl:te,tools:K,uiComponents:ee,templateParams:J,controlledChatId:B,onChatIdChange:B===void 0?m=>{fe&&fe(m);}:void 0,onStart:Io.useCallback(m=>{G&&G(m);},[G]),onFinish:Io.useCallback(m=>{q&&q(m);},[q]),onError:Io.useCallback(m=>{console.error("Chat error:",m);},[]),initialMessages:E,onMessagesChange:x}),{input:je,setInput:Me,messages:ke,isLoading:_,status:lr,error:dt,sendMessage:dr,stop:cr,setMessages:de,notifyMessagesChange:ur,chatId:Lt,setChatId:ct,tools:ta,uiComponents:pr,formHostRef:ra,formStateRef:oa,cleanupForms:_e,onUISuccess:gr,onUIError:mr,chatApi:fr}=Eo,V=B!==void 0?B:Lt,Ee=Io.useCallback(m=>{B===void 0&&ct(m),fe&&fe(m);},[B,ct,fe]);Io.useEffect(()=>{B!==void 0&&B!==Lt&&ct(B);},[B,Lt,ct]);let{attachments:qe,uploading:hr,fileInputRef:Ke,formatBytes:yr,handleRemoveAttachment:xr,handleFileSelection:br,clearAttachments:ut,setAttachments:Cr}=Kr(te),[pt,Re]=Io.useState(null),[gt,kr]=Io.useState(()=>{try{return bt(e).loadShowChatPreference(!!L)}catch{return !!L}}),[Ht,De]=Io.useState(false),[Ft,Dt]=Io.useState(""),[Bt,Pt]=Io.useState(0),vr=Io.useRef(null),wr=Io.useRef(null),[Tr,Ir]=Io.useState(new Set),[Sr,$t]=Io.useState(false),[Ve,zt]=Io.useState(null),Xe=Io.useRef(null),Mr=Gr(_),[Er,Ro]=Io.useState(false);Io.useEffect(()=>{let m=()=>Ro(window.innerWidth<768);return m(),window.addEventListener("resize",m),()=>window.removeEventListener("resize",m)},[]);let Nt=Jt({agentId:e,chatId:V,messages:ke,isLoading:_,autoSave:true,autoRestore:false}),W=Nt.storage,Rr=Io.useMemo(()=>{try{return W.loadChatsIndex()}catch{return []}},[W,Bt]),Ye=Io.useRef(false),Je=Io.useRef(null);Io.useEffect(()=>{if(!Ye.current){if(B!==void 0){try{let m=W.loadChat(B),F=m&&Array.isArray(m.messages)?m.messages:[];if(F.length>0)try{de(F);}catch{}Je.current=B;}catch{}try{W.saveCurrentChatId(B);}catch{}Ye.current=true;return}try{let m=W.loadCurrentChatId();if(m){Ee(m);let F=W.loadChat(m),$=F&&Array.isArray(F.messages)?F.messages:[];try{de($);}catch{}Je.current=m;}}catch{}Ye.current=true;}},[B]),Io.useEffect(()=>{if(Ye.current&&B!==void 0&&B!==Je.current)try{let m=W.loadChat(B),F=m&&Array.isArray(m.messages)?m.messages:[];try{de(F);}catch{}Je.current=B;try{W.saveCurrentChatId(B);}catch{}}catch{}},[B,W,de]),Io.useEffect(()=>{if(Ye.current)try{W.saveCurrentChatId(V);}catch{}},[V,W]),Io.useEffect(()=>{try{Oe(V,_);}catch{}return ()=>{try{Oe(V,!1);}catch{}}},[V,_,Oe]),Io.useEffect(()=>{try{Ge(V,gt);}catch{}return ()=>{try{Ge(V,!1);}catch{}}},[V,gt,Ge]);let Ar=Io.useCallback(async()=>{let m=je.trim();if(!m&&qe.length===0||_)return;let F=[...qe];Me(""),ut(),Re(null),Xe.current&&Xe.current.focus();try{await dr({text:m,files:F.map($=>({type:"file",url:$.url,mediaType:$.mimeType||"application/octet-stream",...$.name?{name:$.name}:{},...$.size?{size:$.size}:{}}))});}catch($){console.error("Failed to send message:",$),Re(z("error.failedSend"));}},[je,qe,_,dr,ut,z]),Be=Io.useCallback(()=>{if(_)return;_e(),Me(""),ut(),Re(null);try{de([]);}catch{}let m=`chat_${Date.now()}_${Math.random().toString(36).slice(2)}`;Je.current=m;try{Nt.createNewChat(()=>{Ee(m);try{W.saveCurrentChatId(m);}catch{}});}catch{Ee(m);try{W.saveCurrentChatId(m);}catch{}}},[_,ut,W,de,Ee,_e,Nt]),Lr=Io.useCallback(()=>{De(m=>!m);},[]),Ao=Io.useCallback(()=>{kr(false);try{W.saveShowChatPreference(!1);}catch{}},[W]),Hr=Io.useCallback(async m=>{let F=m.target.files;F&&await br(F,Re),Ke.current&&(Ke.current.value="");},[br,Ke]);Io.useEffect(()=>{let m=Xe.current;if(!m)return;m.style.height="24px",m.offsetHeight,m.style.height="auto";let F=Math.min(m.scrollHeight,200);m.style.height=`${F}px`;},[je]);let Fr=Io.useCallback((m,F,$,zr)=>{zt({id:F,text:$,attachments:zr||[]}),$t(true);},[]),Dr=Io.useCallback(()=>{if(!(!Ve||_))try{let m=ke.findIndex($=>$.id===Ve.id);if(m===-1)return;let F=ke.slice(0,m);try{de(F);}catch{}Me(Ve.text),Cr(Ve.attachments),$t(!1),zt(null),ur();}catch(m){console.error("Failed to edit message:",m),Re(z("error.failedEdit"));}},[Ve,_,ke,de,Cr,ur,z]),Br=Io.useCallback(()=>{$t(false),zt(null);},[]),Pr=`
|
|
185
220
|
:root {
|
|
186
221
|
--hsafa-theme: ${H};
|
|
187
|
-
--hsafa-primary: ${
|
|
188
|
-
--hsafa-background: ${
|
|
189
|
-
--hsafa-border: ${
|
|
190
|
-
--hsafa-text: ${
|
|
191
|
-
--hsafa-accent: ${
|
|
192
|
-
--hsafa-muted-text: ${
|
|
193
|
-
--hsafa-input-bg: ${
|
|
194
|
-
--hsafa-card-bg: ${
|
|
195
|
-
--hsafa-hover-bg: ${
|
|
196
|
-
--hsafa-error: ${
|
|
197
|
-
--hsafa-error-light: ${
|
|
198
|
-
--hsafa-error-dark: ${
|
|
199
|
-
--hsafa-success: ${
|
|
200
|
-
--hsafa-success-light: ${
|
|
201
|
-
--hsafa-warning: ${
|
|
202
|
-
--hsafa-warning-light: ${
|
|
203
|
-
--hsafa-info: ${
|
|
204
|
-
--hsafa-info-light: ${
|
|
205
|
-
--hsafa-danger: ${
|
|
206
|
-
--hsafa-danger-light: ${
|
|
207
|
-
--hsafa-danger-dark: ${
|
|
222
|
+
--hsafa-primary: ${I.primaryColor};
|
|
223
|
+
--hsafa-background: ${I.backgroundColor};
|
|
224
|
+
--hsafa-border: ${I.borderColor};
|
|
225
|
+
--hsafa-text: ${I.textColor};
|
|
226
|
+
--hsafa-accent: ${I.accentColor};
|
|
227
|
+
--hsafa-muted-text: ${I.mutedTextColor};
|
|
228
|
+
--hsafa-input-bg: ${I.inputBackground};
|
|
229
|
+
--hsafa-card-bg: ${I.cardBackground};
|
|
230
|
+
--hsafa-hover-bg: ${I.hoverBackground};
|
|
231
|
+
--hsafa-error: ${I.errorColor};
|
|
232
|
+
--hsafa-error-light: ${I.errorColorLight};
|
|
233
|
+
--hsafa-error-dark: ${I.errorColorDark};
|
|
234
|
+
--hsafa-success: ${I.successColor};
|
|
235
|
+
--hsafa-success-light: ${I.successColorLight};
|
|
236
|
+
--hsafa-warning: ${I.warningColor};
|
|
237
|
+
--hsafa-warning-light: ${I.warningColorLight};
|
|
238
|
+
--hsafa-info: ${I.infoColor};
|
|
239
|
+
--hsafa-info-light: ${I.infoColorLight};
|
|
240
|
+
--hsafa-danger: ${I.dangerColor};
|
|
241
|
+
--hsafa-danger-light: ${I.dangerColorLight};
|
|
242
|
+
--hsafa-danger-dark: ${I.dangerColorDark};
|
|
208
243
|
}
|
|
209
244
|
${Rt||""}
|
|
210
|
-
`,Lo=jsxRuntime.jsxs("div",{"data-hsafa-chat":"fullpage","data-hsafa-theme":H,"data-hsafa-agent-id":e,style:{position:"fixed",inset:0,display:"flex",backgroundColor:
|
|
245
|
+
`,Lo=jsxRuntime.jsxs("div",{"data-hsafa-chat":"fullpage","data-hsafa-theme":H,"data-hsafa-agent-id":e,style:{position:"fixed",inset:0,display:"flex",backgroundColor:I.backgroundColor,color:I.textColor,overflow:"hidden"},children:[Pr&&jsxRuntime.jsx("style",{dangerouslySetInnerHTML:{__html:Pr}}),!Er&&jsxRuntime.jsx(To,{isOpen:Ht,historySearch:Ft,onSearchChange:Dt,chats:Rr,currentChatId:V,resolvedColors:I,dir:Z,t:z,onChatSelect:m=>{if(m&&m!==V&&(_e(),Ee(m),B===void 0)){try{W.saveCurrentChatId(m);}catch{}try{let F=W.loadChat(m),$=F&&Array.isArray(F.messages)?F.messages:[];try{de($);}catch{}}catch{}}},onChatDelete:m=>{try{W.deleteChat(m),Pt(F=>F+1),m===V&&Be();}catch{}},onNewChat:Be,onClose:()=>De(false)}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",flex:1,minWidth:0,position:"relative"},children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 20px",backgroundColor:I.backgroundColor,minHeight:"60px",zIndex:10},children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[jsxRuntime.jsx("button",{ref:vr,onClick:Lr,style:{padding:"8px",borderRadius:"8px",border:"none",backgroundColor:"transparent",color:I.mutedTextColor,cursor:"pointer",transition:"all 0.2s",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:m=>{m.currentTarget.style.backgroundColor=I.hoverBackground,m.currentTarget.style.color=I.textColor;},onMouseLeave:m=>{m.currentTarget.style.backgroundColor="transparent",m.currentTarget.style.color=I.mutedTextColor;},"aria-label":z("header.history"),children:jsxRuntime.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),jsxRuntime.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),jsxRuntime.jsx("h1",{style:{fontSize:"16px",fontWeight:600,margin:0,color:I.textColor},children:z("general.agent")})]}),jsxRuntime.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:jsxRuntime.jsx("button",{onClick:Be,disabled:_,style:{padding:"8px",borderRadius:"8px",border:"none",backgroundColor:"transparent",color:I.mutedTextColor,cursor:_?"not-allowed":"pointer",transition:"all 0.2s",display:"flex",alignItems:"center",justifyContent:"center"},onMouseEnter:m=>{_||(m.currentTarget.style.backgroundColor=I.hoverBackground,m.currentTarget.style.color=I.textColor);},onMouseLeave:m=>{m.currentTarget.style.backgroundColor="transparent",m.currentTarget.style.color=I.mutedTextColor;},"aria-label":z("header.new"),children:jsxRuntime.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M12 5v14M5 12h14"})})})})]}),jsxRuntime.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},children:[jsxRuntime.jsx("div",{ref:Mr,className:"chat-scroll-container",style:{flex:1,overflowY:"auto",overflowX:"hidden",display:"flex",flexDirection:"column",scrollBehavior:"smooth","--hsafa-primary":I.primaryColor,"--hsafa-border":I.borderColor,"--hsafa-card":I.cardBackground,"--hsafa-text":I.textColor,"--hsafa-muted":I.mutedTextColor,"--hsafa-bg":I.backgroundColor,"--hsafa-hover":I.hoverBackground,"--hsafa-input-bg":I.inputBackground,"--hsafa-accent":I.accentColor},children:jsxRuntime.jsx("div",{style:{maxWidth:"768px",width:"100%",margin:"0 auto",padding:"32px 24px",display:"flex",flexDirection:"column",gap:"24px"},children:ke.length===0?jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px",padding:"64px 0"},children:O&&O.length>0?jsxRuntime.jsx(rr,{prompts:O,onSelect:m=>Me(m),resolvedColors:I,disabled:_,dir:Z,t:z}):jsxRuntime.jsx("div",{style:{padding:"64px 32px",textAlign:"center",color:I.mutedTextColor,fontSize:"16px"},children:z("messages.empty")})}):jsxRuntime.jsx(er,{chatMessages:ke,isLoading:_,openReasoningIds:Tr,toggleReasoning:m=>Ir(F=>{let $=new Set(F);return $.has(m)?$.delete(m):$.add(m),$}),resolvedColors:I,t:z,onUserMessageClick:Fr,HsafaUI:pr,onUIError:mr,onUISuccess:gr,addToolResult:m=>fr?.addToolResult?.(m),editableMessageIcon:ae?.message_icon,fullPage:true,dir:Z,theme:H})})}),jsxRuntime.jsx("div",{style:{backgroundColor:I.backgroundColor,padding:"0 24px 24px",position:"relative",zIndex:20},children:jsxRuntime.jsxs("div",{style:{maxWidth:"768px",width:"100%",margin:"0 auto"},children:[re&&Io__default.default.createElement(re,{}),pt&&jsxRuntime.jsxs("div",{style:{padding:"12px 16px",marginBottom:"12px",backgroundColor:I.errorColor,color:"#fff",borderRadius:"8px",fontSize:"14px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{children:pt}),jsxRuntime.jsx("button",{onClick:()=>Re(null),style:{background:"none",border:"none",color:"#fff",cursor:"pointer",padding:"2px",fontSize:"20px"},children:"\xD7"})]}),dt&&jsxRuntime.jsxs("div",{style:{padding:"12px 16px",marginBottom:"12px",backgroundColor:I.errorColor,color:"#fff",borderRadius:"8px",fontSize:"14px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxRuntime.jsxs("span",{children:[z("error.occurred")," ",dt.message||z("error.tryAgain")]}),jsxRuntime.jsx("button",{onClick:()=>window.location.reload(),style:{background:"none",border:"1px solid #fff",color:"#fff",cursor:"pointer",padding:"4px 8px",borderRadius:"4px",fontSize:"12px"},children:z("error.refresh")})]}),jsxRuntime.jsx(tr,{input:je,setInput:Me,textareaRef:Xe,fileInputRef:Ke,isLoading:_,uploading:hr,attachments:qe,formatBytes:yr,handleRemoveAttachment:xr,onFileInputChange:Hr,onSend:Ar,onStop:()=>cr(),status:lr,t:z,resolvedColors:I,fullPage:true,dir:Z})]})})]})]}),Er&&jsxRuntime.jsx(ar,{historyOpen:Ht,historySearch:Ft,currentChatId:V,refreshKey:Bt,resolvedColors:I,onClose:()=>De(false),onSearchChange:Dt,dir:Z,t:z,onChatSelect:m=>{if(De(false),m&&m!==V&&(_e(),Ee(m),B===void 0)){try{W.saveCurrentChatId(m);}catch{}try{let F=W.loadChat(m),$=F&&Array.isArray(F.messages)?F.messages:[];try{de($);}catch{}}catch{}}},onChatDelete:m=>{try{W.deleteChat(m),Pt(F=>F+1),m===V&&Be();}catch{}},loadChatsIndex:()=>Rr,historyPopupRef:wr}),jsxRuntime.jsx(ir,{isOpen:Sr,resolvedColors:I,t:z,editProcessContent:ae,onConfirm:Dr,onCancel:Br,dir:Z,lang:P}),jsxRuntime.jsx("style",{children:`
|
|
211
246
|
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
|
|
212
247
|
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
|
|
213
248
|
|
|
@@ -264,7 +299,7 @@
|
|
|
264
299
|
margin: 12px 0;
|
|
265
300
|
border: 1px solid var(--hsafa-border);
|
|
266
301
|
}
|
|
267
|
-
`})]}),$r=jsxRuntime.jsxs("div",{"data-hsafa-chat":"panel","data-hsafa-theme":H,"data-hsafa-agent-id":e,style:{position:"fixed",right:0,top:0,bottom:0,width:"420px",display:"flex",flexDirection:"column",padding:"24px 16px",color:
|
|
302
|
+
`})]}),$r=jsxRuntime.jsxs("div",{"data-hsafa-chat":"panel","data-hsafa-theme":H,"data-hsafa-agent-id":e,style:{position:"fixed",right:0,top:0,bottom:0,width:"420px",display:"flex",flexDirection:"column",padding:"24px 16px",color:I.textColor,gap:"16px",zIndex:1e3,transform:gt?"translateX(0)":"translateX(100%)",transition:"transform 0.25s ease-out, width 0.2s ease-out"},children:[jsxRuntime.jsx(ho,{title:z("general.agent"),alwaysOpen:false,streaming:_,dir:Z,resolvedColors:I,onNew:Be,onToggleHistory:Lr,onClose:Ao,historyBtnRef:vr,t:z}),jsxRuntime.jsx("div",{ref:Mr,className:"chat-scroll-container",style:{flex:"1",overflowY:"auto",overflowX:"hidden",padding:"16px 4px 16px 4px",display:"flex",flexDirection:"column",gap:"16px",scrollBehavior:"smooth","--hsafa-primary":I.primaryColor,"--hsafa-border":I.borderColor,"--hsafa-card":I.cardBackground,"--hsafa-text":I.textColor,"--hsafa-muted":I.mutedTextColor,"--hsafa-bg":I.backgroundColor,"--hsafa-hover":I.hoverBackground,"--hsafa-input-bg":I.inputBackground,"--hsafa-accent":I.accentColor},children:ke.length===0?jsxRuntime.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px",padding:"16px 0"},children:O&&O.length>0?jsxRuntime.jsx(rr,{prompts:O,onSelect:m=>Me(m),resolvedColors:I,disabled:_,dir:Z,t:z}):jsxRuntime.jsx("div",{style:{padding:"32px",textAlign:"center",color:I.mutedTextColor,fontSize:"14px"},children:z("messages.empty")})}):jsxRuntime.jsx(er,{chatMessages:ke,isLoading:_,openReasoningIds:Tr,toggleReasoning:m=>Ir(F=>{let $=new Set(F);return $.has(m)?$.delete(m):$.add(m),$}),resolvedColors:I,t:z,onUserMessageClick:Fr,HsafaUI:pr,onUIError:mr,onUISuccess:gr,addToolResult:m=>fr?.addToolResult?.(m),editableMessageIcon:ae?.message_icon,dir:Z,theme:H})}),jsxRuntime.jsxs("div",{style:{position:"sticky",bottom:"0",marginTop:"auto",paddingBottom:"8px"},children:[re&&Io__default.default.createElement(re,{}),pt&&jsxRuntime.jsxs("div",{style:{padding:"8px 12px",marginBottom:"8px",backgroundColor:I.errorColor,color:"#fff",borderRadius:"8px",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxRuntime.jsx("span",{children:pt}),jsxRuntime.jsx("button",{onClick:()=>Re(null),style:{background:"none",border:"none",color:"#fff",cursor:"pointer",padding:"2px"},children:"\xD7"})]}),dt&&jsxRuntime.jsxs("div",{style:{padding:"8px 12px",marginBottom:"8px",backgroundColor:I.errorColor,color:"#fff",borderRadius:"8px",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[jsxRuntime.jsxs("span",{children:[z("error.occurred")," ",dt.message||z("error.tryAgain")]}),jsxRuntime.jsx("button",{onClick:()=>window.location.reload(),style:{background:"none",border:"1px solid #fff",color:"#fff",cursor:"pointer",padding:"4px 8px",borderRadius:"4px",fontSize:"12px"},children:z("error.refresh")})]}),jsxRuntime.jsx(tr,{input:je,setInput:Me,textareaRef:Xe,fileInputRef:Ke,isLoading:_,uploading:hr,attachments:qe,formatBytes:yr,handleRemoveAttachment:xr,onFileInputChange:Hr,onSend:Ar,onStop:()=>cr(),status:lr,t:z,resolvedColors:I,dir:Z})]}),jsxRuntime.jsx(ar,{historyOpen:Ht,historySearch:Ft,currentChatId:V,refreshKey:Bt,resolvedColors:I,onClose:()=>De(false),onSearchChange:Dt,dir:Z,t:z,onChatSelect:m=>{if(De(false),m&&m!==V&&(_e(),Ee(m),B===void 0)){try{W.saveCurrentChatId(m);}catch{}try{let F=W.loadChat(m),$=F&&Array.isArray(F.messages)?F.messages:[];try{de($);}catch{}}catch{}}},onChatDelete:m=>{try{W.deleteChat(m),Pt(F=>F+1),m===V&&Be();}catch{}},loadChatsIndex:()=>W.loadChatsIndex(),historyPopupRef:wr}),jsxRuntime.jsx(ir,{isOpen:Sr,resolvedColors:I,t:z,dir:Z,lang:P,onConfirm:Dr,onCancel:Br,editProcessContent:ae}),jsxRuntime.jsx("style",{children:`
|
|
268
303
|
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
|
|
269
304
|
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
|
|
270
305
|
|
|
@@ -321,7 +356,7 @@
|
|
|
321
356
|
margin: 12px 0;
|
|
322
357
|
border: 1px solid var(--hsafa-border);
|
|
323
358
|
}
|
|
324
|
-
`})]});return
|
|
359
|
+
`})]});return oe?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(rt,{}),Lo]}):typeof document<"u"&&document.body?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(rt,{}),reactDom.createPortal($r,document.body),jsxRuntime.jsx(Wr,{show:!gt,onClick:()=>{kr(true);try{W.saveShowChatPreference(!0);}catch{}},resolvedColors:I,floatingButtonPosition:N})]}):$r}var Mo={dark:{primaryColor:"#4D78FF",backgroundColor:"#0B0B0F",borderColor:"#2A2C33",textColor:"#EDEEF0",accentColor:"#17181C",mutedTextColor:"#9AA0A6",inputBackground:"#17181C",cardBackground:"#121318",hoverBackground:"#1c1e25",errorColor:"#ef4444",errorColorLight:"#fee2e2",errorColorDark:"#991b1b",successColor:"#10b981",successColorLight:"rgba(16,185,129,0.15)",warningColor:"#eab308",warningColorLight:"rgba(234,179,8,0.15)",infoColor:"#3b82f6",infoColorLight:"rgba(59,130,246,0.15)",dangerColor:"#ef4444",dangerColorLight:"rgba(239, 68, 68, 0.1)",dangerColorDark:"#991b1b"},light:{primaryColor:"#2563EB",backgroundColor:"#FFFFFF",borderColor:"#E5E7EB",textColor:"#111827",accentColor:"#F9FAFB",mutedTextColor:"#6B7280",inputBackground:"#F9FAFB",cardBackground:"#F3F4F6",hoverBackground:"#F3F4F6",errorColor:"#ef4444",errorColorLight:"#fef2f2",errorColorDark:"#991b1b",successColor:"#10b981",successColorLight:"#d1fae5",warningColor:"#eab308",warningColorLight:"#fef3c7",infoColor:"#3b82f6",infoColorLight:"#dbeafe",dangerColor:"#ef4444",dangerColorLight:"rgba(239, 68, 68, 0.1)",dangerColorDark:"#991b1b"}};function Jn({children:e,theme:t="dark",primaryColor:r,backgroundColor:n,borderColor:o,textColor:l,mutedTextColor:p,enableBorderAnimation:c=true,borderRadius:b=16,enableContentBorder:S=true,className:h="",enableMargin:M=true,chatWidth:v=420,dir:f="ltr"}){let{isAnyStreaming:s,isAnyChatOpen:u,dir:d,theme:T}=ce(),i=(f??d)||"ltr",g=(t??T)||"dark",a=Io.useRef(`content-container-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),[w,C]=Io.useState(false);Io.useEffect(()=>{let K=setTimeout(()=>C(true),50);return ()=>clearTimeout(K)},[]);let y=Mo[g],k={primaryColor:r||y.primaryColor,backgroundColor:n||y.backgroundColor,borderColor:o||y.borderColor,textColor:l||y.textColor,accentColor:y.accentColor,mutedTextColor:p||y.mutedTextColor,inputBackground:y.inputBackground,cardBackground:y.cardBackground,hoverBackground:y.hoverBackground,errorColor:y.errorColor,errorColorLight:y.errorColorLight,errorColorDark:y.errorColorDark,successColor:y.successColor,successColorLight:y.successColorLight,warningColor:y.warningColor,warningColorLight:y.warningColorLight,infoColor:y.infoColor,infoColorLight:y.infoColorLight,dangerColor:y.dangerColor,dangerColorLight:y.dangerColorLight,dangerColorDark:y.dangerColorDark},E=typeof b=="number"?`${b}px`:b,x=typeof v=="number"?`${v}px`:v,L=M&&u?i==="rtl"?{marginLeft:x}:{marginRight:x}:{},N=M&&u?`calc(100% - ${x})`:"100%";return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:h,style:{width:N,height:"100%",transition:w?"all 0.2s ease-out":"none",padding:u&&S?"16px":"0",...L},children:jsxRuntime.jsx("div",{style:{position:"relative",width:"100%",height:"100%",transition:w?"all 0.2s ease-out":"none",borderRadius:u?E:"0",border:u&&s&&c?"none":u?`1px solid ${k.borderColor}`:"none",padding:u&&s&&c?"1.5px":"0",background:u&&s&&c?`linear-gradient(120deg, ${k.primaryColor}dd 0%, ${k.primaryColor}88 25%, ${k.primaryColor}00 50%, ${k.primaryColor}88 75%, ${k.primaryColor}dd 100%)`:"transparent",backgroundSize:u&&s&&c?"300% 300%":"auto",animation:u&&s&&c?`${a.current}-border-flow 3s ease-in-out infinite`:"none",filter:u&&s&&c?`drop-shadow(0 0 10px ${k.primaryColor}40)`:"none"},children:jsxRuntime.jsx("div",{className:"hsafa-content-container",style:{width:"100%",height:"100%",borderRadius:u&&S?E:"0",backgroundColor:u&&S?k.backgroundColor:"transparent",overflow:"auto",position:"relative",isolation:"isolate",contain:"layout style paint",transform:"translateZ(0)",scrollbarWidth:"thin",scrollbarColor:`${k.mutedTextColor}40 transparent`},children:e})})}),jsxRuntime.jsx("style",{children:`
|
|
325
360
|
@keyframes ${a.current}-border-flow {
|
|
326
361
|
0% { background-position: 0% 50%; }
|
|
327
362
|
50% { background-position: 100% 50%; }
|