@filigran/chatbot 3.6.1 → 3.7.1
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.d.ts +21 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -128,6 +128,27 @@ interface ChatPanelProps {
|
|
|
128
128
|
* - 'ag-ui': AG-UI protocol (https://github.com/ag-ui-protocol/ag-ui)
|
|
129
129
|
*/
|
|
130
130
|
backendType?: BackendType;
|
|
131
|
+
/**
|
|
132
|
+
* Show the waiting experience during longer waits: dynamic rotating status
|
|
133
|
+
* messages plus an optional Space Invader mini-game that shoots the message
|
|
134
|
+
* letters away one by one. Users can still toggle the game off per browser
|
|
135
|
+
* from the panel; this prop is a host-level master switch. Default: true.
|
|
136
|
+
*/
|
|
137
|
+
miniGameEnabled?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Notify the user when a long-running turn finishes while they are not
|
|
140
|
+
* watching the chat — away (tab hidden / another window) via a document-title
|
|
141
|
+
* flash and a browser notification (when already granted), or in-app but
|
|
142
|
+
* looking elsewhere via the `onTaskComplete` host toast. Default: true.
|
|
143
|
+
*/
|
|
144
|
+
notifyOnComplete?: boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Called when a long turn finishes and the user is not actively watching the
|
|
147
|
+
* chat (away, or in-app but focused elsewhere) so the host can raise its own
|
|
148
|
+
* in-app toast (the chatbot has no toast surface of its own). Receives the
|
|
149
|
+
* already-translated `title` and `body`.
|
|
150
|
+
*/
|
|
151
|
+
onTaskComplete?: (title: string, body: string) => void;
|
|
131
152
|
}
|
|
132
153
|
interface ChatToggleButtonProps {
|
|
133
154
|
isOpen: boolean;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsxs as e,jsx as t,Fragment as n}from"react/jsx-runtime";import{useState as r,useRef as a,useCallback as o,useEffect as s,useMemo as i}from"react";import{createPortal as l}from"react-dom";import c from"react-markdown";import d from"remark-gfm";function h(e,t){return`${e}${Math.round(255*t).toString(16).padStart(2,"0")}`}function u(e){if(!e)return e;const t=e.split("\n"),n=/^(\s*)(`{3,})(.*)$/,r=/^(markdown|md|mdx|markup)\b/i;let a=-1;for(let e=0;e<t.length;e++){const o=t[e].match(n);if(o&&3===o[2].length&&r.test(o[3].trim())){a=e;break}}if(-1===a)return e;let o=3,s=0,i=-1;for(let e=a+1;e<t.length;e++){const r=t[e].match(n);r&&(s++,o=Math.max(o,r[2].length),""===r[3].trim()&&(i=e))}if(0===s)return e;const l="`".repeat(Math.max(o+1,4)),c=t[a].match(n);if(t[a]=`${c[1]}${l}${c[3]}`,i>a){const e=t[i].match(n);t[i]=`${e[1]}${l}`}return t.join("\n")}const g=e=>e;function m(e){let t=e;for(;t;){if(t.classList.contains("filigran-chatbot"))return t;t=t.parentElement}return document.body}const p=/\[\[FILE(?::[^\]]*)?\]?$/;function f(e){if(!Array.isArray(e))return;const t=[];for(const n of e){if(!n||"object"!=typeof n)continue;const e=n,r=e.file_id;"string"==typeof r&&r&&t.push({fileId:r,filename:"string"==typeof e.filename?e.filename:"file",type:"string"==typeof e.type?e.type:void 0,size:"number"==typeof e.size?e.size:void 0,contentType:"string"==typeof e.content_type?e.content_type:void 0,fileTag:"working_file"===e.file_tag?"working_file":"download_file"})}return t.length>0?t:void 0}function x(e){if(!Array.isArray(e))return;const t=[];for(const n of e){if(!n||"object"!=typeof n)continue;const e=n;"string"==typeof e.name&&e.name&&t.push({name:e.name,input:"string"==typeof e.input?e.input:void 0,output:"string"==typeof e.output?e.output:void 0,success:"boolean"!=typeof e.success||e.success})}return t.length>0?t:void 0}function w(e){if(!Array.isArray(e))return;const t=[];for(const n of e){if(!n||"object"!=typeof n)continue;const e=n;"string"==typeof e.agent_name&&e.agent_name&&t.push({agentId:"string"==typeof e.agent_id?e.agent_id:"",agentName:e.agent_name})}return t.length>0?t:void 0}function b(e,t){const n=e.type;if("error"===n)return{action:"error",content:e.content||""};if("status"===n){const n=e.status;return"tool_done"===n||"wind_down"===n?{action:"noop"}:"streaming"===n?{action:"status",status:"streaming"}:"thinking_text"===n?{action:"status",status:"thinking_text",thinkingContent:e.content}:"tool_start"===n?(t.hasUsedTools=!0,{action:"status",status:"tool_start",tools:e.tools}):"tool_heartbeat"===n?{action:"status",status:"tool_heartbeat",tools:e.tools,elapsedS:"number"==typeof e.elapsed_s?e.elapsed_s:void 0}:"thinking"===n&&t.hasUsedTools?{action:"status",status:"analyzing"}:{action:"status",status:n,tools:e.tools}}return"stream"===n?{action:"stream",content:e.content}:"done"===n?{action:"done",content:e.content,conversationId:e.conversation_id,toolNames:e.tool_names,toolCallCount:e.tool_call_count,iterations:e.iterations,transferAgentId:e.transfer_agent_id,transferAgentName:e.transfer_agent_name,attachments:f(e.attachments),reasoning:"string"==typeof e.reasoning?e.reasoning:void 0,toolCallTrace:x(e.tool_call_trace),transferChain:w(e.transfer_chain),isTruncated:!0===e.is_truncated||void 0}:{action:"noop"}}function v(e,t){const n=e.event;if("nextAgentFlow"===n){const n=e.data,r=n?.nodeId;return"INPROGRESS"===n?.status&&r&&(t.activeNodeId=r),{action:"noop"}}if("start"===n)return{action:"noop"};if("token"===n){return{action:"stream",content:(e.data??"").replace(/<br\s*\/?>/g,"\n")}}if("agentReasoning"===n){const n=e.data,r=n?.usedTools;return r?.length?(t.hasUsedTools=!0,{action:"status",status:"tool_start",tools:r.map(e=>e.tool)}):t.hasUsedTools?{action:"status",status:"analyzing"}:{action:"status",status:"thinking"}}if("usedTools"===n){t.hasUsedTools=!0;const n=e.data;return{action:"status",status:"tool_start",tools:Array.isArray(n)?n.map(e=>e.tool):[]}}if("metadata"===n){const t=e.data,n=t?.chatId;return n?{action:"set_chat_id",chatId:n}:{action:"noop"}}return"error"===n?{action:"error",content:e.data||""}:"end"===n?{action:"done",content:""}:{action:"noop"}}function y(e,t){const n=e.type;if("RUN_STARTED"===n)return{action:"status",status:"thinking"};if("RUN_FINISHED"===n)return{action:"done",content:""};if("RUN_ERROR"===n)return{action:"error",content:e.message||"Unknown error"};if("STEP_STARTED"===n){return{action:"status",status:e.stepName||"thinking"}}if("STEP_FINISHED"===n)return{action:"noop"};if("TEXT_MESSAGE_START"===n)return{action:"status",status:"streaming"};if("TEXT_MESSAGE_CONTENT"===n){const t=e.delta;return t?{action:"stream",content:t}:{action:"noop"}}if("TEXT_MESSAGE_END"===n)return{action:"noop"};if("TEXT_MESSAGE_CHUNK"===n){const t=e.delta;return t?{action:"stream",content:t}:{action:"noop"}}if("TOOL_CALL_START"===n){t.hasUsedTools=!0;const n=e.toolCallName;return{action:"status",status:"tool_start",tools:n?[n]:[]}}if("TOOL_CALL_ARGS"===n)return{action:"noop"};if("TOOL_CALL_END"===n)return{action:"status",status:"analyzing"};if("TOOL_CALL_RESULT"===n)return{action:"noop"};if("TOOL_CALL_CHUNK"===n){const n=e.toolCallName;return n?(t.hasUsedTools=!0,{action:"status",status:"tool_start",tools:[n]}):{action:"noop"}}if("REASONING_START"===n||"REASONING_MESSAGE_START"===n)return{action:"status",status:"thinking"};if("REASONING_MESSAGE_CONTENT"===n||"REASONING_MESSAGE_CHUNK"===n){const t=e.delta;return t?{action:"status",status:"thinking_text",thinkingContent:t}:{action:"status",status:"thinking"}}return{action:"noop"}}const k="filigranChatConversationId",N="filigranChatLegacyChatId",C=52428800;function _({apiBaseUrl:e,apiEndpoints:t,backendType:n="rest",agentSlug:s,requestHeaders:i,pageContext:l,t:c,maxFileCount:d=10,maxTotalSize:h=52428800}){const u="legacy"===n,[g,m]=r([]),[p,f]=r(""),[x,w]=r(!1),[_,S]=r(null),[I,L]=r(()=>"undefined"==typeof window?null:localStorage.getItem(k)),[z,M]=r([]),[$,T]=r(null),[E,A]=r(()=>"undefined"==typeof window?null:localStorage.getItem(N)),j=a(!1),D=a(null),R=a(!1),U=a(I),B=a(l);B.current=l;const O=a(null),W=a(new AbortController),F=Number.isFinite(d)&&d>0?Math.floor(d):10,H=Number.isFinite(h)&&h>0?h:C,P=()=>u||"ag-ui"===n||t?.singleEndpoint||null===t?.steer?null:`${e}${t?.steer??"/chat/messages/steer"}`,V=()=>u||t?.singleEndpoint||null===t?.upload?null:`${e}${t?.upload??"/chat/upload"}`,G=o(e=>{U.current=e,L(e),e?localStorage.setItem(k,e):localStorage.removeItem(k)},[]),q=async n=>{if(U.current)return U.current;if(O.current)return O.current;const r=u||t?.singleEndpoint||null===t?.sessions?null:`${e}${t?.sessions??"/chat/sessions"}`;if(!r)return null;const a=(async()=>{try{const e=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json",...i??{}},body:JSON.stringify({agent_slug:n})});if(!e.ok)return null;const t=await e.json(),a=t?.conversation_id??null;return a&&G(a),a}catch{return null}finally{O.current=null}})();return O.current=a,a},J=async(e,t,n)=>{const r=V(),a=new FormData;a.append("conversation_id",t),a.append("file",e,e.name);const o=i?Object.fromEntries(Object.entries(i).filter(([e])=>"content-type"!==e.toLowerCase())):void 0,s=await fetch(r,{method:"POST",headers:o,body:a,signal:n});if(!s.ok)throw new Error(`File upload failed: ${s.status}`);const l=(await s.json()).file_ids??[];if(0===l.length)throw new Error("No file_id returned");return l[0]},K=e=>{if(!e||0===e.length||!V())return;const t=Array.from(e).map(e=>({file:e,tempId:crypto.randomUUID()}));let n=[];M(e=>{const r=e.length,a=e.reduce((e,t)=>e+t.size,0),o=F-r;if(o<=0)return e;let s=H-a;const i=[];for(const e of t.slice(0,o))e.file.size<=s&&(i.push(e),s-=e.file.size);if(0===i.length)return e;n=i;const l=i.map(({file:e,tempId:t})=>({name:e.name,type:e.type,size:e.size,rawFile:e,uploadStatus:"pending",fileId:t}));return[...e,...l]}),setTimeout(()=>{const e=W.current.signal;for(const{file:t,tempId:r}of n)(async()=>{try{const n=await q(s);if(!n)return void M(e=>e.map(e=>e.fileId===r?{...e,uploadStatus:"error"}:e));const a=await J(t,n,e);M(e=>e.map(e=>e.fileId===r?{...e,fileId:a,uploadStatus:"done"}:e))}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;M(e=>e.map(e=>e.fileId===r?{...e,uploadStatus:"error"}:e))}})()},0)},Z=()=>{D.current?.abort(),D.current=null,W.current.abort(),W.current=new AbortController,O.current=null,m([]),f(""),M([]),w(!1),S(null),T(null),R.current=!1,j.current=!1,u?(A(null),localStorage.removeItem(N)):G(null)},X=x&&null!==P()&&null!==I;return{messages:g,inputValue:p,setInputValue:f,isLoading:x,agentStatus:_,attachedFiles:z,conversationId:I,transferredAgent:$,canSteer:X,historyLoadedRef:j,conversationIdRef:U,handleFileAdd:K,handlePaste:e=>{const{files:t}=e.clipboardData;t.length>0&&(e.preventDefault(),K(t))},handleSendMessage:async()=>{const r=p.trim();if(x)return void(r&&0===z.length&&P()&&U.current&&(f(""),await(async e=>{const t=P(),n=U.current;if(!t||!n)return;const r={id:crypto.randomUUID(),role:"user",content:e,timestamp:new Date};m(e=>[...e,r]);try{const r=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",...i??{}},body:JSON.stringify({conversation_id:n,content:e,agent_slug:s})});if(!r.ok)throw new Error(`Steer failed: ${r.status}`)}catch{m(e=>e.filter(e=>e.id!==r.id)),f(t=>t?`${e}\n${t}`:e)}})(r)));if(!p.trim()&&0===z.length)return;const a=p.trim(),o={id:crypto.randomUUID(),role:"user",content:a,timestamp:new Date,files:z.length>0?[...z]:void 0};m(e=>[...e,o]),f(""),M([]),w(!0),S({status:"thinking"}),R.current=!1;const l=crypto.randomUUID();m(e=>[...e,{id:l,role:"assistant",content:"",timestamp:new Date}]);let d=l;try{const r=new AbortController;D.current=r;const h=(o.files??[]).filter(e=>"done"===e.uploadStatus&&e.fileId).map(e=>e.fileId),g=function(e,t,n){switch(e){case"legacy":return{question:t,chatId:n.legacyChatId??void 0,streaming:!0};case"ag-ui":return{threadId:n.conversationId??crypto.randomUUID(),runId:crypto.randomUUID(),messages:[{id:crypto.randomUUID(),role:"user",content:t}],tools:[],context:[],state:{},forwardedProps:n.agentSlug?{agentSlug:n.agentSlug}:{}};default:{const e={content:t,conversation_id:n.conversationId,agent_slug:n.agentSlug};if(n.pageContext&&Object.keys(n.pageContext).length>0)try{const t=JSON.stringify(n.pageContext);t&&"{}"!==t&&(e.context=n.pageContext)}catch{}return e}}}(n,a,{legacyChatId:E,conversationId:U.current,agentSlug:s,pageContext:B.current});h.length>0&&(g.file_ids=h),S({status:"thinking"});const p=await fetch(u||t?.singleEndpoint?e:`${e}${t?.messages??"/chat/messages"}`,{method:"POST",headers:{"Content-Type":"application/json",...i??{}},body:JSON.stringify(g),signal:r.signal});if(!p.ok||!p.body)return void m(e=>e.map(e=>e.id===l?{...e,content:c("Unable to connect. Please check the configuration.")}:e));const f=function(e){switch(e){case"legacy":return v;case"ag-ui":return y;default:return b}}(n),x={hasUsedTools:!1,activeNodeId:""},w=p.body.getReader(),k=new TextDecoder;let C="",_="",I=!1;const L=()=>{if(!I)return;I=!1,_="",d=crypto.randomUUID();const e=d;m(t=>[...t,{id:e,role:"assistant",content:"",timestamp:new Date}]),S({status:"thinking"})};for(;;){const{done:e,value:t}=await w.read();if(e)break;C+=k.decode(t,{stream:!0});const n=C.split("\n");C=n.pop()||"";for(const e of n){const t=e.replace(/\r$/,"");if(!t.startsWith("data:"))continue;const n=t.startsWith("data: ")?t.slice(6):t.slice(5);try{const e=f(JSON.parse(n),x);switch(x.hasUsedTools=x.hasUsedTools||R.current,e.action){case"status":{L();const t=d;"tool_start"===e.status&&(R.current=!0),"stream_retract"===e.status?(_="",m(e=>e.map(e=>e.id===t?{...e,content:""}:e)),S(e=>({status:"analyzing",thinkingContent:e?.thinkingContent}))):"thinking_text"===e.status?S(t=>({...t,status:t?.status??"thinking",thinkingContent:(t?.thinkingContent??"")+(e.thinkingContent??"")})):"tool_heartbeat"===e.status?S(t=>t?{...t,elapsedS:e.elapsedS}:{status:"tool_start",tools:e.tools,elapsedS:e.elapsedS}):S(t=>({status:e.status,tools:e.tools,thinkingContent:t?.thinkingContent}));break}case"stream":{L(),_+=e.content;const t=d,n=_;S(e=>({status:"streaming",thinkingContent:e?.thinkingContent})),m(e=>e.map(e=>e.id===t?{...e,content:n}:e));break}case"done":{I=!0,e.conversationId&&G(e.conversationId),e.transferAgentId&&e.transferAgentName&&T({id:e.transferAgentId,name:e.transferAgentName});const t=d,n=e.content||_;m(r=>r.map(r=>r.id===t?{...r,content:n,toolNames:e.toolNames,toolCallCount:e.toolCallCount,iterations:e.iterations,attachments:e.attachments,reasoning:e.reasoning,toolCallTrace:e.toolCallTrace,transferChain:e.transferChain,isTruncated:e.isTruncated}:r));break}case"error":{L();const t=d;return void m(n=>n.map(n=>n.id===t?{...n,content:e.content||c("Unable to connect. Please check the configuration.")}:n))}case"set_chat_id":A(e.chatId),localStorage.setItem(N,e.chatId)}R.current=x.hasUsedTools}catch{}}}if(_&&!I){const e=d,t=_;m(n=>n.map(n=>n.id===e?{...n,content:t||"No response."}:n))}}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;const t=d;m(e=>e.map(e=>e.id===t?{...e,content:c("Sorry, an error occurred. Please try again.")}:e))}finally{D.current=null,w(!1),S(null),R.current=!1}},handleNewChat:Z,handleStopGenerating:()=>{D.current?.abort(),D.current=null,w(!1),S(null),R.current=!1,m(e=>e.filter(e=>!("assistant"===e.role&&!e.content)))},setAttachedFiles:M,setMessages:m,updateConversationId:G,handleSwitchConversation:e=>{(u||e!==U.current)&&(Z(),u||G(e))}}}const S="filigranChatAgentSlug";function I(e){if(!e||"object"!=typeof e)return null;const t=e,n=t.conversation_id??t.id;if("string"!=typeof n||!n)return null;return{conversationId:n,title:"string"==typeof t.title?t.title.trim():"",updatedAt:"string"==typeof t.updated_at?t.updated_at:"string"==typeof t.created_at?t.created_at:void 0,messageCount:"number"==typeof t.message_count?t.message_count:void 0}}const L=400,z="filigranChatSidebarWidth";const M=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"}),t("path",{d:"M12 9v4"}),t("path",{d:"M12 17h.01"})]}),$=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"m16 3 4 4-4 4"}),t("path",{d:"M20 7H4"}),t("path",{d:"m8 21-4-4 4-4"}),t("path",{d:"M4 17h16"})]}),T=({className:e,size:n=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:e,children:t("path",{d:"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"})}),E=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M12 8V4H8"}),t("rect",{width:"16",height:"12",x:"4",y:"8",rx:"2"}),t("path",{d:"M2 14h2"}),t("path",{d:"M20 14h2"}),t("path",{d:"M15 13v2"}),t("path",{d:"M9 13v2"})]}),A=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z"}),t("path",{d:"M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z"}),t("path",{d:"M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4"}),t("path",{d:"M17.599 6.5a3 3 0 0 0 .399-1.375"}),t("path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5"}),t("path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396"}),t("path",{d:"M19.938 10.5a4 4 0 0 1 .585.396"}),t("path",{d:"M6 18a4 4 0 0 1-1.967-.516"}),t("path",{d:"M19.967 17.484A4 4 0 0 1 18 18"})]}),j=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("circle",{cx:"12",cy:"12",r:"10"}),t("path",{d:"m9 12 2 2 4-4"})]}),D=({className:e,size:n=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:e,children:t("path",{d:"M20 6 9 17l-5-5"})}),R=({className:e,size:n=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:e,children:t("path",{d:"m6 9 6 6 6-6"})}),U=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M18 6 6 18"}),t("path",{d:"m6 6 12 12"})]}),B=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2"}),t("path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"})]}),O=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),t("path",{d:"M3 5V19A9 3 0 0 0 21 19V5"}),t("path",{d:"M3 12A9 3 0 0 0 21 12"})]}),W=({className:e,size:n=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",className:e,children:t("path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"})}),F=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),t("polyline",{points:"7 10 12 15 17 10"}),t("line",{x1:"12",x2:"12",y1:"15",y2:"3"})]}),H=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M12 20h9"}),t("path",{d:"M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z"})]}),P=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M15 3h6v6"}),t("path",{d:"M10 14 21 3"}),t("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]}),V=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),t("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]}),G=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M11 13H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h7"}),t("rect",{width:"12",height:"12",x:"10",y:"10",rx:"2"})]}),q=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M8 3v3a2 2 0 0 1-2 2H3"}),t("path",{d:"M21 8h-3a2 2 0 0 1-2-2V3"}),t("path",{d:"M3 16h3a2 2 0 0 0 2 2v3"}),t("path",{d:"M16 21v-3a2 2 0 0 1 2-2h3"})]}),J=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M8 3H5a2 2 0 0 0-2 2v3"}),t("path",{d:"M21 8V5a2 2 0 0 0-2-2h-3"}),t("path",{d:"M3 16v3a2 2 0 0 0 2 2h3"}),t("path",{d:"M16 21h3a2 2 0 0 0 2-2v-3"})]}),K=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("circle",{cx:"12",cy:"12",r:"10"}),t("path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"}),t("path",{d:"M2 12h20"})]}),Z=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),t("path",{d:"M3 3v5h5"}),t("path",{d:"M12 7v5l4 2"})]}),X=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("circle",{cx:"12",cy:"12",r:"10"}),t("path",{d:"M12 16v-4"}),t("path",{d:"M12 8h.01"})]}),Q=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("rect",{width:"20",height:"16",x:"2",y:"4",rx:"2"}),t("path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"})]}),Y=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("circle",{cx:"11",cy:"11",r:"8"}),t("path",{d:"m21 21-4.3-4.3"})]}),ee=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"m22 2-7 20-4-9-9-4Z"}),t("path",{d:"m22 2-11 11"})]}),te=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),t("path",{d:"M15 3v18"})]}),ne=({className:e,size:n=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:e,children:t("path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"})}),re=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("circle",{cx:"12",cy:"12",r:"10"}),t("rect",{width:"6",height:"6",x:"9",y:"9"})]}),ae=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("polyline",{points:"4 17 10 11 4 5"}),t("line",{x1:"12",x2:"20",y1:"19",y2:"19"})]}),oe=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M3 6h18"}),t("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),t("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"}),t("line",{x1:"10",x2:"10",y1:"11",y2:"17"}),t("line",{x1:"14",x2:"14",y1:"11",y2:"17"})]}),se=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),t("circle",{cx:"9",cy:"7",r:"4"}),t("line",{x1:"19",x2:"19",y1:"8",y2:"14"}),t("line",{x1:"22",x2:"16",y1:"11",y2:"11"})]}),ie=({className:e,size:n=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:e,children:t("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),le=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("circle",{cx:"12",cy:"12",r:"10"}),t("path",{d:"m15 9-6 6"}),t("path",{d:"m9 9 6 6"})]});const ce=({open:e,onClose:n,anchorRef:i,placement:c="bottom-start",width:d=280,children:h})=>{const u=a(null),[g,p]=r({top:0,left:0});if(function(e,t,n=!0){s(()=>{if(!n)return;const r=n=>{e.current&&!e.current.contains(n.target)&&t()};return document.addEventListener("mousedown",r),document.addEventListener("touchstart",r),()=>{document.removeEventListener("mousedown",r),document.removeEventListener("touchstart",r)}},[e,t,n])}(u,o(()=>n(),[n]),e),s(()=>{if(!e||!i.current)return;const t=i.current.getBoundingClientRect(),n="bottom-end"===c?t.right-d:t.left;p({top:t.bottom+4,left:n})},[e,i,c,d]),!e)return null;const f=m(i.current);return l(t("div",{ref:u,className:"fixed z-[10000] rounded-[10px] overflow-hidden border border-gray-200 dark:border-white/10 bg-white dark:bg-[#2a2a3e] shadow-xl",style:{top:g.top,left:g.left,width:d},children:h}),f)},de=({size:e=16,className:n=""})=>t("div",{className:`animate-spin rounded-full border-2 border-current/20 border-t-[var(--chat-accent)] ${n}`,style:{width:e,height:e}}),he=({title:n,children:o})=>{const s=a(null),[i,c]=r(!1),[d,h]=r({top:0,left:0}),[u,g]=r(!1);if(!n)return o;return e("span",{ref:s,className:"inline-flex",onMouseEnter:()=>{if(!s.current)return;const e=s.current.getBoundingClientRect(),t=m(s.current).getBoundingClientRect().top,n=e.top-t<28;g(n),h({top:n?e.bottom+4:e.top-4,left:e.left+e.width/2}),c(!0)},onMouseLeave:()=>c(!1),children:[o,i&&l(t("span",{className:`pointer-events-none fixed z-[10001] -translate-x-1/2 ${u?"":"-translate-y-full"} whitespace-nowrap rounded-md bg-gray-900 dark:bg-gray-100 px-2 py-1 text-xs text-white dark:text-gray-900 shadow-lg`,style:{top:d.top,left:d.left},role:"tooltip",children:n}),m(s.current))]})},ue=[{mode:"floating",label:"Floating",getIcon:e=>t(G,{...e})},{mode:"sidebar",label:"Sidebar",getIcon:e=>t(te,{...e})},{mode:"fullscreen",label:"Full screen",getIcon:e=>t(J,{...e})}],ge=({mode:r,agentName:o,agents:s,selectedAgent:i,transferredFrom:l,agentMenuOpen:c,onAgentMenuToggle:d,onAgentMenuClose:h,onSwitchAgent:u,modeMenuOpen:g,onModeMenuToggle:m,onModeMenuClose:p,onModeChange:f,onNewChat:x,onClose:w,logoIcon:b,agentDashboardUrl:v,historyEnabled:y=!1,historyMenuOpen:k=!1,onHistoryMenuToggle:N,onHistoryMenuClose:C,conversations:_=[],conversationsLoading:S=!1,activeConversationId:I=null,onSelectConversation:L,onDeleteConversation:z,t:M})=>{const $=a(null),T=a(null),E=a(null),A="sidebar"===r?te:"fullscreen"===r?q:G;return e("div",{className:"flex items-center px-3 py-2 min-h-[48px] border-b border-gray-200 dark:border-white/10 bg-gradient-to-br from-[var(--chat-accent-dark)]/[0.13] to-[var(--chat-accent)]/[0.07] "+("floating"===r?"rounded-t-xl":""),children:[e("div",{className:"min-w-0",children:[e("button",{ref:$,type:"button",onClick:d,className:"flex items-center gap-1.5 text-sm font-semibold text-gray-900 dark:text-white px-2 py-1 rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:[t("span",{className:"flex items-center text-[var(--chat-accent)] [&>svg]:w-[18px] [&>svg]:h-[18px]",children:b}),t("span",{children:o}),t(R,{size:16,className:"text-gray-400 dark:text-white/30"})]}),l&&e("div",{className:"pl-10 pr-2 text-[0.6rem] font-normal text-gray-400 dark:text-white/30",children:[M("Transferred from")," ",l]})]}),e(ce,{open:c,onClose:h,anchorRef:$,width:280,children:[t("span",{className:"block px-4 pt-3 pb-1 text-[0.68rem] tracking-[1px] uppercase text-gray-400 dark:text-white/40",children:M("Switch to another agent")}),0===s.length&&t("div",{className:"px-4 py-2",children:t(de,{size:16})}),t("div",{children:s.map(n=>e("button",{type:"button",onClick:()=>u(n),className:"w-full flex items-center gap-2 px-4 py-1.5 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors "+(n.id===i?.id?"bg-[var(--chat-accent)]/10":""),children:[t("div",{className:"w-7 h-7 rounded-full flex items-center justify-center shrink-0 bg-gradient-to-br from-[var(--chat-accent)]/20 to-[var(--chat-accent)]/5",children:t("span",{className:"text-[var(--chat-accent)] [&>svg]:w-4 [&>svg]:h-4",children:b})}),e("div",{className:"min-w-0",children:[t("div",{className:"text-[0.8125rem] font-medium text-gray-900 dark:text-white truncate",children:n.name}),n.description&&t("div",{className:"text-[0.7rem] text-gray-500 dark:text-white/40 truncate",children:n.description})]})]},n.id))}),t("div",{className:"h-px bg-gray-200 dark:bg-white/10 mx-2"}),e("div",{children:[v&&e("button",{type:"button",onClick:()=>{h(),window.open(`${v}/agents`,"_blank")},className:"w-full flex items-center gap-2 px-4 py-1.5 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:[t(P,{size:18,className:"text-gray-400 dark:text-white/40 shrink-0"}),t("span",{className:"text-[0.8125rem] text-gray-700 dark:text-white/70",children:M("Browse agents")})]}),v&&e("button",{type:"button",onClick:()=>{h(),window.open(`${v}/agents/new`,"_blank")},className:"w-full flex items-center gap-2 px-4 py-1.5 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:[t(se,{size:18,className:"text-gray-400 dark:text-white/40 shrink-0"}),t("span",{className:"text-[0.8125rem] text-gray-700 dark:text-white/70",children:M("Create agent")})]})]})]}),t("div",{className:"flex-1"}),y&&e(n,{children:[t(he,{title:M("Conversation history"),children:t("button",{ref:E,type:"button",onClick:N,"aria-label":M("Conversation history"),"aria-haspopup":"menu","aria-expanded":k,className:"w-8 h-8 flex items-center justify-center rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-500 dark:text-white/40 hover:text-gray-700 dark:hover:text-white/70 transition-colors",children:t(Z,{size:18})})}),e(ce,{open:k,onClose:()=>C?.(),anchorRef:E,placement:"bottom-end",width:300,children:[t("span",{className:"block px-4 pt-3 pb-1 text-[0.68rem] tracking-[1px] uppercase text-gray-400 dark:text-white/40",children:M("Conversation history")}),e("div",{className:"max-h-72 overflow-y-auto filigran-chat-scrollable",children:[S&&0===_.length&&t("div",{className:"px-4 py-2",children:t(de,{size:16})}),!S&&0===_.length&&t("div",{className:"px-4 py-3 text-[0.75rem] text-gray-400 dark:text-white/40",children:M("No conversations yet")}),_.map(n=>{const r=n.conversationId===I,a=function(e,t){if(!e)return"";const n=new Date(e).getTime();if(Number.isNaN(n))return"";const r=Date.now()-n,a=Math.floor(r/6e4);if(a<1)return t("just now");if(a<60)return`${a}${t("m ago")}`;const o=Math.floor(a/60);if(o<24)return`${o}${t("h ago")}`;const s=Math.floor(o/24);return s<7?`${s}${t("d ago")}`:new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})}(n.updatedAt,M);return e("div",{className:"group flex items-center gap-2 px-4 py-1.5 hover:bg-gray-100 dark:hover:bg-white/10 transition-colors "+(r?"bg-[var(--chat-accent)]/10":""),children:[e("button",{type:"button",onClick:()=>L?.(n.conversationId),className:"flex-1 min-w-0 text-left",children:[t("div",{className:"text-[0.8125rem] font-medium text-gray-900 dark:text-white truncate",children:n.title||M("Untitled conversation")}),a&&t("div",{className:"text-[0.7rem] text-gray-500 dark:text-white/40 truncate",children:a})]}),z&&t("button",{type:"button",onClick:()=>z(n.conversationId),title:M("Delete conversation"),"aria-label":M("Delete conversation"),className:"shrink-0 p-1 rounded-md text-gray-400 dark:text-white/30 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 hover:text-red-500 dark:hover:text-red-400 transition-all",children:t(oe,{size:14})})]},n.conversationId)})]}),t("div",{className:"h-px bg-gray-200 dark:bg-white/10 mx-2"}),e("button",{type:"button",onClick:()=>{C?.(),x()},className:"w-full flex items-center gap-2 px-4 py-2 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:[t(H,{size:16,className:"text-gray-400 dark:text-white/40 shrink-0"}),t("span",{className:"text-[0.8125rem] text-gray-700 dark:text-white/70",children:M("New conversation")})]})]})]}),t(he,{title:M("New chat"),children:t("button",{type:"button",onClick:x,className:"w-8 h-8 flex items-center justify-center rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-500 dark:text-white/40 hover:text-gray-700 dark:hover:text-white/70 transition-colors",children:t(H,{size:18})})}),t(he,{title:M("Switch view"),children:t("button",{ref:T,type:"button",onClick:m,className:"w-8 h-8 flex items-center justify-center rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-500 dark:text-white/40 hover:text-gray-700 dark:hover:text-white/70 transition-colors",children:t(A,{size:18})})}),e(ce,{open:g,onClose:p,anchorRef:T,placement:"bottom-end",width:180,children:[t("span",{className:"block px-4 pt-3 pb-1 text-[0.68rem] tracking-[1px] uppercase text-gray-400 dark:text-white/40",children:M("Switch to")}),t("div",{className:"pb-1",children:ue.map(n=>e("button",{type:"button",onClick:()=>{f(n.mode),p()},className:"w-full flex items-center gap-3 px-4 py-1 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors "+(r===n.mode?"bg-[var(--chat-accent)]/10":""),children:[n.getIcon({size:18,className:"text-gray-400 dark:text-white/40"}),t("span",{className:"text-[0.8125rem] text-gray-700 dark:text-white/70",children:M(n.label)})]},n.mode))})]}),t(he,{title:M("Close"),children:t("button",{type:"button",onClick:w,className:"w-8 h-8 flex items-center justify-center rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-500 dark:text-white/40 hover:text-gray-700 dark:hover:text-white/70 transition-colors",children:t(U,{size:18})})})]})},me=({inputValue:r,onInputChange:o,onSend:s,onStop:i,isLoading:l,canSteer:c=!1,attachedFiles:d=[],onFileAdd:h,onFileRemove:u,onPaste:g,t:m,mode:p,separatorColor:f})=>{const x=a(null),w=a(null),b=Boolean(h&&u&&g),v=r.trim()||b&&d.length>0,y=b&&d.some(e=>"pending"===e.uploadStatus),k=v&&!y,N=b&&d.length>0,C=l&&c&&Boolean(r.trim())&&!N,_=m(l&&c&&!N?"Enter to send now · Esc to stop":l&&N?"Attachments wait for the current response":"Uses AI. Verify results.");return e("div",{className:"px-4 py-3 border-t border-gray-200 dark:border-white/10 "+("floating"===p?"rounded-b-xl":""),style:f?{borderTopColor:f,borderTopWidth:1}:void 0,children:[b&&d.length>0&&t("div",{className:"flex gap-1.5 flex-wrap mb-2",children:d.map((n,r)=>e("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full border text-[0.7rem] "+("error"===n.uploadStatus?"border-red-300 dark:border-red-500/30 text-red-500 dark:text-red-400":"pending"===n.uploadStatus?"border-gray-200 dark:border-white/10 text-gray-400 dark:text-white/40":"border-gray-200 dark:border-white/10 text-gray-600 dark:text-white/60"),children:["pending"===n.uploadStatus?t("span",{className:"w-3.5 h-3.5 border border-current/30 border-t-current rounded-full animate-spin"}):t(V,{size:14}),n.name,"error"===n.uploadStatus&&t("span",{className:"text-red-400 text-[0.6rem]",children:"✕"}),t("button",{type:"button",onClick:()=>u?.(r),className:"ml-0.5 text-gray-400 dark:text-white/30 hover:text-gray-600 dark:hover:text-white/60",children:"×"})]},r))}),e("div",{className:"flex items-center border border-gray-200 dark:border-white/10 rounded-xl px-2 py-1 transition-colors focus-within:border-[var(--chat-accent)]",children:[b&&e(n,{children:[t("input",{ref:x,type:"file",multiple:!0,hidden:!0,onChange:e=>{h?.(e.target.files),e.target.value=""}}),t("button",{type:"button",onClick:()=>x.current?.click(),className:"w-8 h-8 flex items-center justify-center shrink-0 rounded-lg text-gray-400 dark:text-white/30 hover:bg-gray-100 dark:hover:bg-white/10 mr-0.5 transition-colors",children:t(T,{size:18})})]}),t("textarea",{ref:w,placeholder:m("Ask a question..."),value:r,onChange:e=>{o(e.target.value);const t=e.target;t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,120)}px`},onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),s()),"Escape"===e.key&&l&&(e.preventDefault(),i())},onPaste:g,rows:1,className:"flex-1 bg-transparent border-none outline-hidden resize-none text-[0.8125rem] py-1.5 text-gray-900 dark:text-white placeholder:text-gray-400 dark:placeholder:text-white/30 filigran-chat-scrollable",style:{maxHeight:120}}),C&&t(he,{title:m("Send now"),children:t("button",{type:"button",onClick:s,"aria-label":m("Send now"),className:"p-1.5 rounded-lg w-8 h-8 flex items-center justify-center transition-all duration-150 text-[var(--chat-accent)] bg-[var(--chat-accent)]/10 hover:bg-[var(--chat-accent)]/20",children:t(ee,{size:18})})}),t(he,{title:l?m("Stop generating"):y?m("Files uploading..."):"",children:t("button",{type:"button",onClick:l?i:s,disabled:!l&&!k,className:"p-1.5 rounded-lg w-8 h-8 flex items-center justify-center transition-all duration-150 "+(l?"text-red-500 bg-red-500/10 hover:bg-red-500/20 ml-0.5":k?"text-[var(--chat-accent)] bg-[var(--chat-accent)]/10 hover:bg-[var(--chat-accent)]/20":"text-gray-300 dark:text-white/20 cursor-not-allowed"),children:t(l?re:ee,{size:18})})})]}),t("p",{className:"text-center text-[0.65rem] text-gray-400 dark:text-white/30 mt-1.5 opacity-70",children:_})]})};function pe(e){return e.replace(/```[\s\S]*?```/g," ").replace(/`([^`]+)`/g,"$1").replace(/\*\*(.+?)\*\*/g,"$1").replace(/__(.+?)__/g,"$1").replace(/#{1,6}\s+/g,"").replace(/^[ \t]*[-*>]+[ \t]*/gm,"").replace(/[ \t]+/g," ").replace(/\n{3,}/g,"\n\n").trim()}function fe({content:e}){const n=a(null),[o,i]=r(!1),l=pe(e);return s(()=>{const e=n.current;e&&(e.scrollTop=e.scrollHeight,i(e.scrollHeight>e.clientHeight+1))},[l]),l.length<3?null:t("div",{className:"ml-11 mt-2.5 max-w-[75%] rounded-md border-l-2 bg-[var(--chat-accent)]/[0.03] py-2 pl-3 pr-3",style:{animation:"reasoningGlow 3s ease-in-out infinite, chat-fade-in 0.5s ease-out"},children:t("div",{ref:n,className:"max-h-40 overflow-hidden"+(o?" [-webkit-mask-image:linear-gradient(to_bottom,transparent_0,rgb(0_0_0/0.25)_1.5rem,rgb(0_0_0/0.7)_3rem,black_4.5rem)] [mask-image:linear-gradient(to_bottom,transparent_0,rgb(0_0_0/0.25)_1.5rem,rgb(0_0_0/0.7)_3rem,black_4.5rem)]":""),children:t("p",{className:"m-0 whitespace-pre-wrap break-words text-xs leading-5 text-gray-500 dark:text-white/45",children:l})})})}function xe(e){const t=Math.floor(e);if(t<60)return`${t}s`;const n=Math.floor(t/60),r=t%60;return r>0?`${n}m ${r}s`:`${n}m`}const we=({agentStatus:r,logoIcon:a,t:o})=>{const{label:s,StatusIcon:i,showDots:l}=function(e,t){if(!e)return{label:t("Thinking..."),StatusIcon:A,showDots:!1};switch(e.status){case"tool_start":{const n=e.tools??[],r=n.map(e=>e.toLowerCase());if(r.some(e=>"spawn_background_task"===e)){const e=n.filter(e=>"spawn_background_task"===e).length;return{label:e>1?`${t("Delegating")} ${e} ${t("tasks")}…`:`${t("Delegating task")}…`,StatusIcon:se,showDots:!1}}if(r.some(e=>"check_task_status"===e)){const e=n.filter(e=>"check_task_status"===e).length,r=e>1?`${e} ${t("background tasks")}`:t("background task");return{label:`${t("Waiting for")} ${r}…`,StatusIcon:ne,showDots:!1}}if(r.some(e=>"get_task_result"===e)){const e=n.filter(e=>"get_task_result"===e).length,r=e>1?`${e} ${t("tasks")}`:t("task");return{label:`${t("Collecting results from")} ${r}…`,StatusIcon:ne,showDots:!1}}let a,o=ie;if(r.some(e=>e.includes("search")||e.includes("list"))?o=Y:r.some(e=>e.includes("read")||e.includes("get")||e.includes("query"))?o=O:r.some(e=>e.includes("send")||e.includes("create")||e.includes("draft")||e.includes("reply")||e.includes("flag"))?o=Q:r.some(e=>e.includes("code")||e.includes("execute"))?o=ae:r.some(e=>e.includes("web")||e.includes("browse"))&&(o=K),n.length>0){const e=n.map(e=>e.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase())),t=Array.from(new Set(e));a=1===t.length?`${t[0]}…`:`${t[0]} (+${t.length-1} more)…`}else a=t("Using tools…");return{label:a,StatusIcon:o,showDots:!1}}case"analyzing":return{label:t("Analyzing results…"),StatusIcon:ne,showDots:!1};case"steering":return{label:t("Incorporating your message…"),StatusIcon:ne,showDots:!0};case"composing":return{label:t("Composing answer…"),StatusIcon:A,showDots:!0};case"consulting":{const n=e.tools?.[0]??"agent";return{label:`${t("Consulting")} ${n}…`,StatusIcon:se,showDots:!1}}case"delegating":{const n=e.tools?.filter(e=>"spawn_background_task"===e).length??0;return{label:n>1?`${t("Delegating")} ${n} ${t("tasks")}…`:`${t("Delegating task")}…`,StatusIcon:se,showDots:!1}}case"polling":{const n=e.tools?.filter(e=>"check_task_status"===e).length??0,r=n>1?`${n} ${t("background tasks")}`:t("background task");return{label:`${t("Waiting for")} ${r}…`,StatusIcon:ne,showDots:!1}}case"collecting":{const n=e.tools?.filter(e=>"get_task_result"===e).length??0,r=n>1?`${n} ${t("tasks")}`:t("task");return{label:`${t("Collecting results from")} ${r}…`,StatusIcon:ne,showDots:!1}}case"transferring":{const n=e.tools?.[0]??"agent";return{label:`${t("Transferring to")} ${n}…`,StatusIcon:P,showDots:!1}}default:return{label:t("Thinking..."),StatusIcon:A,showDots:!1}}}(r,o),c=r?.thinkingContent,d=r?.elapsedS,h="number"==typeof d&&d>=15;return e(n,{children:[e("div",{className:"flex gap-3 items-center justify-start",children:[t("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-gradient-to-br from-[var(--chat-accent)]/15 to-[var(--chat-accent)]/5",children:t("span",{className:"text-[var(--chat-accent)] [&>svg]:w-4 [&>svg]:h-4",children:a})}),e("div",{className:"rounded-lg bg-gray-50 dark:bg-white/[0.03] px-4 py-3 relative overflow-hidden",children:[t("div",{className:"absolute inset-0 bg-gradient-to-r from-[var(--chat-accent)]/[0.03] via-transparent to-[var(--chat-accent)]/[0.03] animate-pulse pointer-events-none"}),e("div",{className:"relative flex items-center gap-2.5",children:[l?t("div",{className:"flex gap-[3px] items-center h-3.5 w-3.5 justify-center",children:[0,.15,.3].map((e,n)=>t("span",{className:"h-[5px] w-[5px] rounded-full bg-[var(--chat-accent)]/50",style:{animation:`chat-dot 1s ease-in-out infinite ${e}s`}},n))}):t(i,{size:14,className:"text-[var(--chat-accent)] animate-pulse transition-all duration-300"}),t("span",{className:"text-sm text-gray-500 dark:text-white/50 transition-all duration-300",children:s}),h&&t("span",{className:"text-xs text-gray-400 dark:text-white/30 tabular-nums shrink-0",children:xe(d)})]})]})]}),c&&t(fe,{content:c})]})},be=e=>{if(!e)return!1;if(e.startsWith("//"))return!1;return!/^[a-zA-Z][a-zA-Z\d+.-]*:/.test(e)},ve=({content:n,onRelativeLinkClick:a})=>{const[o,s]=r(null);return t(c,{remarkPlugins:[d],components:{p:({children:e})=>t("p",{className:"mb-3 last:mb-0 leading-7 break-words text-[0.8125rem] text-gray-900 dark:text-white/90",children:e}),code:({className:n,children:r})=>{const a=/language-(\w+)/.exec(n||""),i=String(r).replace(/\n$/,"");return a?e("div",{className:"my-3 rounded-lg border border-gray-200 dark:border-white/10 overflow-hidden bg-gray-50 dark:bg-white/[0.03]",children:[e("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-gray-200 dark:border-white/10 bg-gray-100 dark:bg-white/[0.03]",children:[t("span",{className:"text-[0.7rem] text-gray-500 dark:text-white/40 font-mono",children:a[1]}),t("button",{type:"button",onClick:()=>{return e=i,navigator.clipboard.writeText(e),s(e),void setTimeout(()=>s(null),2e3);var e},className:"p-0.5 rounded-sm hover:bg-gray-200 dark:hover:bg-white/10 transition-colors",children:o===i?t(D,{size:14,className:"text-green-500"}):t(B,{size:14,className:"text-gray-400 dark:text-white/40"})})]}),t("pre",{className:"m-0 px-3 py-2 overflow-x-auto",children:t("code",{className:"font-mono text-xs leading-[1.7] text-gray-800 dark:text-white/90 whitespace-pre",children:i})})]}):t("code",{className:"bg-gray-100 dark:bg-white/[0.08] px-1.5 py-0.5 rounded-sm font-mono text-xs text-[var(--chat-accent)]",children:r})},ul:({children:e})=>t("ul",{className:"pl-5 mb-3 text-[0.8125rem] text-gray-900 dark:text-white/90 [&_li]:mb-1 marker:text-[var(--chat-accent)]/50",children:e}),ol:({children:e})=>t("ol",{className:"pl-5 mb-3 text-[0.8125rem] text-gray-900 dark:text-white/90 [&_li]:mb-1 marker:text-[var(--chat-accent)]/50",children:e}),blockquote:({children:e})=>t("blockquote",{className:"my-3 border-l-2 border-[var(--chat-accent)]/30 bg-[var(--chat-accent)]/[0.03] pl-4 pr-3 py-2 rounded-r-md italic text-gray-500 dark:text-white/60",children:e}),a:({href:e,children:n})=>{const r=(e=>{if(!e)return null;if(be(e))return e;if("undefined"==typeof window)return null;try{const t=new URL(e,window.location.href);if(("http:"===t.protocol||"https:"===t.protocol)&&t.origin===window.location.origin)return`${t.pathname}${t.search}${t.hash}`||"/"}catch{}return null})(e),o=null!==r&&!!a,s=!o&&!be(e);return t("a",{href:e,onClick:e=>{o&&(e.preventDefault(),a(r))},target:s?"_blank":void 0,rel:s?"noopener noreferrer":void 0,className:"text-[var(--chat-accent)] underline underline-offset-2 hover:brightness-125",children:n})},h1:({children:e})=>t("h1",{className:"mt-4 first:mt-0 mb-2 font-bold text-base text-gray-900 dark:text-white",children:e}),h2:({children:e})=>t("h2",{className:"mt-3 first:mt-0 mb-2 font-bold text-[0.9rem] text-gray-900 dark:text-white",children:e}),h3:({children:e})=>t("h3",{className:"mt-3 first:mt-0 mb-1.5 font-semibold text-[0.85rem] text-gray-900 dark:text-white",children:e}),table:({children:e})=>t("div",{className:"my-3 overflow-x-auto rounded-lg border border-gray-200 dark:border-white/10",children:t("table",{className:"w-full border-collapse text-xs",children:e})}),th:({children:e})=>t("th",{className:"px-3 py-2 text-left font-semibold bg-gray-50 dark:bg-white/[0.04] border-b border-gray-200 dark:border-white/10 text-gray-900 dark:text-white",children:e}),td:({children:e})=>t("td",{className:"px-3 py-2 border-b border-gray-200 dark:border-white/10 text-gray-700 dark:text-white/80",children:e})},children:u(n)})};function ye(e){if(!e)return"";if(e.length>1e4)return e;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function ke(e){return e.replace(/_/g," ")}const Ne=({entry:n,index:a,t:o})=>{const[s,l]=r(!1),c=i(()=>ye(n.input),[n.input]),d=i(()=>ye(n.output),[n.output]),h=!!c&&"{}"!==c;return e("div",{className:"border border-gray-200 dark:border-white/[0.06] rounded-md overflow-hidden",children:[e("button",{type:"button",onClick:()=>l(e=>!e),"aria-expanded":s,className:"w-full flex items-center gap-2.5 px-3 py-2 hover:bg-gray-50 dark:hover:bg-white/[0.03] transition-colors text-left",children:[t("span",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded bg-[var(--chat-accent)]/10 text-[0.65rem] font-medium text-[var(--chat-accent)]",children:a+1}),n.success?t(j,{size:12,className:"shrink-0 text-emerald-500 dark:text-emerald-400"}):t(le,{size:12,className:"shrink-0 text-red-500 dark:text-red-400"}),t("span",{className:"flex-1 min-w-0 text-[0.8125rem] text-gray-700 dark:text-white/80 truncate font-mono",children:ke(n.name)}),t(R,{size:14,className:"shrink-0 text-gray-400 dark:text-white/50 transition-transform duration-200 "+(s?"rotate-180":"")})]}),s&&e("div",{className:"border-t border-gray-200 dark:border-white/[0.06]",children:[h&&e("div",{className:"px-3 py-2 border-b border-gray-100 dark:border-white/[0.04] bg-gray-50/50 dark:bg-white/[0.01]",children:[t("p",{className:"m-0 mb-1.5 text-[0.6rem] text-gray-500 dark:text-white/40 uppercase tracking-wider font-medium",children:o("Input")}),t("pre",{className:"m-0 text-[0.7rem] text-gray-600 dark:text-white/60 font-mono whitespace-pre-wrap break-all leading-relaxed max-h-40 overflow-y-auto filigran-chat-scrollable",children:c})]}),e("div",{className:"px-3 py-2 bg-gray-50/50 dark:bg-white/[0.01]",children:[t("p",{className:"m-0 mb-1.5 text-[0.6rem] text-gray-500 dark:text-white/40 uppercase tracking-wider font-medium",children:o("Output")}),t("pre",{className:"m-0 text-[0.7rem] text-gray-600 dark:text-white/60 font-mono whitespace-pre-wrap break-all leading-relaxed max-h-48 overflow-y-auto filigran-chat-scrollable",children:d||o("(no output)")})]})]})]})},Ce=({msg:n,onClose:o,t:i})=>{const c=a(null),d=a(null),h=a(null),[u,g]=r(null);s(()=>{g(m(c.current))},[]),s(()=>{const e=e=>{if("Escape"===e.key)return void o();if("Tab"!==e.key)return;const t=h.current;if(!t)return;const n=t.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(0===n.length)return;const r=n[0],a=n[n.length-1],s=document.activeElement;e.shiftKey?s!==r&&t.contains(s)||(e.preventDefault(),a.focus()):s!==a&&t.contains(s)||(e.preventDefault(),r.focus())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[o]),s(()=>{if(!u)return;const e=document.activeElement instanceof HTMLElement?document.activeElement:null;return d.current?.focus({preventScroll:!0}),()=>e?.focus({preventScroll:!0})},[u]);const p=n.toolCallCount??n.toolCallTrace?.length??n.toolNames?.length??0,f=n.toolNames??[],x=n.iterations??1,w=n.transferChain??[],b=n.toolCallTrace??[],v=(n.reasoning??"").trim(),y=[x>1?`${x} ${i("iterations")}`:"",`${p} ${i(1===p?"tool call":"tool calls")}`,w.length>0?`${w.length} ${1===w.length?i("transfer"):i("transfers")}`:""].filter(Boolean);return t("span",{ref:c,className:"hidden",children:u&&l(t("div",{className:"absolute inset-0 z-[10000] flex items-center justify-center bg-black/30 dark:bg-black/50 p-4",onClick:o,role:"presentation",children:e("div",{ref:h,role:"dialog","aria-modal":"true","aria-label":i("Reasoning details"),onClick:e=>e.stopPropagation(),className:"w-full max-w-md max-h-full flex flex-col rounded-xl border border-gray-200 dark:border-white/10 bg-white dark:bg-[#1e1e2e] shadow-[0_8px_32px_rgba(0,0,0,0.25)] dark:shadow-[0_8px_32px_rgba(0,0,0,0.6)]",children:[e("div",{className:"px-4 pt-3.5 pb-2.5 border-b border-gray-200 dark:border-white/10",children:[e("div",{className:"flex items-center gap-2",children:[t(ie,{size:15,className:"text-[var(--chat-accent)]"}),t("span",{className:"flex-1 text-[0.875rem] font-semibold text-gray-900 dark:text-white",children:i("Reasoning details")}),t("button",{ref:d,type:"button",onClick:o,"aria-label":i("Close"),className:"w-7 h-7 flex items-center justify-center rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-500 dark:text-white/40 hover:text-gray-700 dark:hover:text-white/70 transition-colors",children:t(U,{size:16})})]}),t("p",{className:"m-0 mt-0.5 text-[0.72rem] text-gray-500 dark:text-white/40",children:y.join(" · ")})]}),e("div",{className:"px-4 py-3 overflow-y-auto filigran-chat-scrollable flex flex-col gap-3",children:[n.isTruncated&&e("div",{className:"flex items-start gap-2.5 rounded-md border border-amber-500/20 bg-amber-500/5 px-3 py-2.5 text-[0.72rem] text-amber-600 dark:text-amber-300/90",children:[t(M,{size:14,className:"shrink-0 mt-0.5 text-amber-500 dark:text-amber-400"}),e("span",{children:[t("span",{className:"font-semibold",children:i("Turn limit reached.")})," ",i("The agent's iteration budget was exhausted - execution stopped before completing all planned steps. The final response is a best-effort summary of work done so far.")]})]}),v&&e("div",{children:[e("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t(A,{size:13,className:"text-[var(--chat-accent)]/70"}),t("span",{className:"text-[0.72rem] font-medium text-gray-500 dark:text-white/50",children:i("Model reasoning")})]}),t("div",{className:"rounded-md border border-gray-200 dark:border-white/[0.06] bg-gray-50/50 dark:bg-white/[0.01] px-2.5 py-2 max-h-44 overflow-y-auto filigran-chat-scrollable",children:t("p",{className:"m-0 whitespace-pre-wrap break-words text-[0.72rem] leading-5 text-gray-500 dark:text-white/45",children:pe(v)})})]}),b.length>0?t("div",{className:"flex flex-col gap-1.5",children:b.map((e,n)=>t(Ne,{entry:e,index:n,t:i},`${e.name}-${n}`))}):f.length>0&&t("div",{children:f.map((n,r)=>e("div",{className:"flex items-center gap-3 py-2 border-b border-gray-100 dark:border-white/[0.04] last:border-0",children:[t("span",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded bg-[var(--chat-accent)]/10 text-[0.65rem] font-medium text-[var(--chat-accent)]",children:r+1}),t(ie,{size:12,className:"shrink-0 text-gray-400 dark:text-white/50"}),t("span",{className:"text-[0.8125rem] text-gray-700 dark:text-white/80 truncate font-mono",children:ke(n)})]},`${n}-${r}`))}),w.length>0&&e("div",{children:[e("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t($,{size:13,className:"text-[var(--chat-accent)]/70"}),t("span",{className:"text-[0.72rem] font-medium text-gray-500 dark:text-white/50",children:i("Transfer chain")})]}),t("div",{className:"flex items-center gap-1.5 flex-wrap",children:w.map((n,r)=>e("div",{className:"flex items-center gap-1.5",children:[r>0&&t("span",{className:"text-gray-300 dark:text-white/30 text-[0.72rem]",children:"→"}),e("span",{className:"inline-flex items-center gap-1 rounded-md bg-[var(--chat-accent)]/10 px-2 py-0.5 text-[0.72rem] font-medium text-[var(--chat-accent)]",children:[t(E,{size:12}),n.agentName]})]},`${n.agentId}-${r}`))})]})]})]})}),u)})};function _e(e){const t=e.lastIndexOf(".");if(t<=0||t===e.length-1)return;const n=e.slice(t+1);return n.length<=8?n.toUpperCase():void 0}const Se=({messages:o,isLoading:i,agentStatus:l,agentName:c,logoIcon:d,onRelativeLinkClick:h,onDownloadFile:u,t:g})=>{const m=a(null),[f,x]=r(null);s(()=>{m.current?.scrollIntoView({behavior:"smooth"})},[o]);const w=l?.thinkingContent?.length??0;s(()=>{w&&m.current?.scrollIntoView({behavior:"instant"})},[w]);const b=(n,r)=>{const a="working_file"===n.fileTag,o=!(s=n.size)||s<=0?"":s<1024?`${s} B`:s<1048576?`${(s/1024).toFixed(0)} KB`:`${(s/1048576).toFixed(1)} MB`;var s;return e("button",{type:"button",onClick:()=>u?.(n),title:g("Download"),className:"group flex items-center gap-2 text-left rounded-lg border px-2.5 py-1.5 transition-colors cursor-pointer max-w-[90%] "+(a?"border-gray-200 dark:border-white/10 bg-transparent":"border-gray-200 dark:border-white/10 bg-gray-50 dark:bg-white/[0.04] hover:border-[var(--chat-accent)] hover:bg-[var(--chat-accent)]/5"),children:[t("span",{className:"shrink-0 "+(a?"text-gray-400 dark:text-white/40":"text-[var(--chat-accent)]"),children:t(V,{size:16})}),e("span",{className:"flex flex-col min-w-0 flex-1",children:[t("span",{className:"truncate text-[0.75rem] text-gray-900 dark:text-white",children:n.filename}),(n.type||o)&&t("span",{className:"text-[0.65rem] text-gray-400 dark:text-white/40 uppercase",children:[n.type,o].filter(Boolean).join(" · ")})]}),t("span",{className:"shrink-0 text-gray-400 dark:text-white/30 group-hover:text-[var(--chat-accent)]",children:t(F,{size:15})})]},r)},v=(e,n)=>{const r=function(e){if(!e)return[];const t=[],n=/\[\[FILE:([^\]]+)\]\]/g;let r=0,a=n.exec(e);for(;null!==a;)a.index>r&&t.push({type:"text",value:e.slice(r,a.index)}),t.push({type:"file",fileId:a[1]}),r=n.lastIndex,a=n.exec(e);const o=e.slice(r).replace(p,"");return o&&t.push({type:"text",value:o}),t}(e.content),a=new Map((e.attachments??[]).map(e=>[e.fileId,e])),o=new Set,s=[];return r.forEach((e,n)=>{if("text"===e.type)e.value.trim()&&s.push(t("div",{className:"max-w-[90%] pl-1 py-1 text-[0.8125rem] leading-7",children:t(ve,{content:e.value,onRelativeLinkClick:h})},`t-${n}`));else if(u){const t=a.get(e.fileId);t&&(o.add(e.fileId),s.push(b(t,`f-${e.fileId}-${n}`)))}}),u&&(e.attachments??[]).forEach(e=>{o.has(e.fileId)||s.push(b(e,`orphan-${e.fileId}`))}),0!==s.length||n||s.push(t("span",{className:"pl-1 text-[0.8125rem] text-gray-400 dark:text-white/40 italic",children:"..."},"empty")),s},y=(n,r)=>e("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full border border-gray-200 dark:border-white/10 text-[0.7rem] text-gray-600 dark:text-white/60",children:[t(V,{size:14}),n]},r),k=e=>{const t=[],n=new Set;return(e.files??[]).forEach((e,r)=>{!(!u||!e.fileId||"done"!==e.uploadStatus)&&e.fileId?(n.add(e.fileId),t.push(b({fileId:e.fileId,filename:e.name,type:_e(e.name),size:e.size,contentType:e.type},`file-${e.fileId}-${r}`))):t.push(y(e.name,`file-${r}`))}),(e.attachments??[]).forEach((e,r)=>{n.has(e.fileId)||(n.add(e.fileId),t.push(u?b(e,`att-${e.fileId}-${r}`):y(e.filename,`att-${r}`)))}),t};let N=-1;for(let e=o.length-1;e>=0;e--)if("assistant"===o[e].role){N=e;break}return e("div",{className:"flex-1 overflow-y-auto px-4 py-3 flex flex-col gap-4 filigran-chat-scrollable",children:[o.map((r,a)=>{const o="assistant"===r.role,s=!r.content,h=i&&a===N;return o&&s&&h?t("div",{children:t(we,{agentStatus:l,logoIcon:d,t:g})},r.id):e("div",{className:"flex flex-col "+(o?"items-start":"items-end"),children:[o&&e("div",{className:"flex items-center gap-1.5 mb-1",children:[t("div",{className:"w-6 h-6 rounded-lg flex items-center justify-center bg-gradient-to-br from-[var(--chat-accent)]/20 to-[var(--chat-accent)]/5",children:t("span",{className:"text-[var(--chat-accent)] [&>svg]:w-3 [&>svg]:h-3",children:d})}),t("span",{className:"font-semibold text-xs text-gray-900 dark:text-white",children:c})]}),!o&&((r.files?.length??0)>0||(r.attachments?.length??0)>0)&&t("div",{className:"flex gap-1.5 flex-wrap mb-1.5 justify-end",children:k(r)}),o?e("div",{className:"flex flex-col gap-1.5 w-full items-start",children:[v(r,h),!s&&h&&t("span",{className:"inline-block w-1.5 h-4 bg-[var(--chat-accent)]/70 rounded-xs ml-1 animate-pulse"})]}):t("div",{className:"max-w-[90%] px-3.5 py-2 rounded-[14px_14px_4px_14px] bg-[var(--chat-accent-dark)] text-white text-[0.8125rem] leading-6",children:r.content}),o&&!s&&!h&&(r.toolNames&&r.toolNames.length>0||(r.reasoning??"").trim()||r.toolCallTrace&&r.toolCallTrace.length>0||r.transferChain&&r.transferChain.length>0||r.isTruncated)&&e(n,{children:[t("button",{type:"button",onClick:()=>x(f===r.id?null:r.id),className:"mt-0.5 p-1 rounded-lg transition-opacity "+(r.isTruncated?"opacity-100 text-amber-500 dark:text-amber-400 hover:text-amber-600 dark:hover:text-amber-300":"opacity-50 hover:opacity-100 hover:text-[var(--chat-accent)]"),title:r.isTruncated?g("Reasoning details — turn limit reached"):g("Reasoning details"),"aria-label":r.isTruncated?g("Reasoning details — turn limit reached"):g("Reasoning details"),"aria-haspopup":"dialog","aria-expanded":f===r.id,children:r.isTruncated?t(M,{size:14}):t(X,{size:14})}),f===r.id&&t(Ce,{msg:r,onClose:()=>x(null),t:g})]})]},r.id)}),t("div",{ref:m})]})},Ie=({firstName:n,logoIcon:r,promptSuggestions:a,onPromptClick:o,t:s})=>e("div",{className:"flex-1 flex flex-col items-center justify-center px-6 pb-8",children:[t("span",{className:"text-[var(--chat-accent)] mb-4 [&>svg]:w-12 [&>svg]:h-12 drop-shadow-[0_0_12px_var(--chat-accent-40)]",children:r}),e("h2",{className:"text-xl font-medium mb-6 text-center text-gray-900 dark:text-white",style:{fontFamily:'"Geologica", sans-serif'},children:[s("How can I help you, "),n,"?"]}),e("div",{className:"w-full max-w-[320px]",children:[t("span",{className:"block text-center mb-2 text-[0.65rem] tracking-[1.5px] uppercase text-[var(--chat-accent)] font-semibold",children:s("Suggestions")}),a.map(e=>t("button",{type:"button",onClick:()=>o(e),className:"w-full text-left text-[0.8125rem] text-gray-800 dark:text-white py-1.5 px-3 mb-1 rounded-lg border border-gray-200 dark:border-white/10 bg-transparent transition-colors hover:bg-[var(--chat-accent-10)] hover:border-[var(--chat-accent-50)]",children:s(e)},e))]})]}),Le=["Help me create a new simulation scenario","What are the latest attack patterns?","How do I configure detection rules?","Summarize my recent findings"],ze=({mode:n,onClose:i,onModeChange:l,topOffset:c=0,apiBaseUrl:d,apiEndpoints:u,agentDashboardUrl:m,user:p,t:b=g,accentColor:v="#7b5cff",logoIcon:y,promptSuggestions:k=Le,draftBorderColor:N,resizable:C=!1,onWidthChange:M,onResizeStart:$,onResizeEnd:T,disableFileManagement:E=!1,onRelativeLinkClick:A,onDownloadError:j,maxFileCount:D,maxTotalSize:R,requestHeaders:U,pageContext:B,pushContentSelector:O,backendType:F="rest"})=>{const[H,P]=r(!1),{agents:V,selectedAgent:G,agentMenuOpen:q,setAgentMenuOpen:J,handleSwitchAgent:K}=function({apiBaseUrl:e,apiEndpoints:t,backendType:n="rest",requestHeaders:a}){const[o,i]=r([]),[l,c]=r(null),[d,h]=r(!1);return s(()=>{null===t?.agents||t?.singleEndpoint||"legacy"===n||fetch(`${e}${t?.agents??"/chat/agents"}`,{headers:a}).then(e=>e.ok?e.json():[]).then(e=>{if(i(e),e.length>0&&!l){const t=localStorage.getItem(S),n=t?e.find(e=>e.slug===t):null;c(n||e[0])}}).catch(()=>{})},[e,t,n,a]),{agents:o,selectedAgent:l,setSelectedAgent:c,agentMenuOpen:d,setAgentMenuOpen:h,handleSwitchAgent:(e,t)=>{e.id!==l?.id?(c(e),e.slug&&localStorage.setItem(S,e.slug),h(!1),t?.()):h(!1)}}}({apiBaseUrl:d,apiEndpoints:u,backendType:F,requestHeaders:U}),{messages:Z,inputValue:X,setInputValue:Q,isLoading:Y,agentStatus:ee,attachedFiles:te,conversationId:ne,transferredAgent:re,canSteer:ae,historyLoadedRef:oe,conversationIdRef:se,handleFileAdd:ie,handlePaste:le,handleSendMessage:ce,handleNewChat:de,handleStopGenerating:he,setAttachedFiles:ue,setMessages:pe,updateConversationId:fe,handleSwitchConversation:xe}=_({apiBaseUrl:d,apiEndpoints:u,backendType:F,agentSlug:G?.slug,requestHeaders:U,pageContext:B,t:b,maxFileCount:D,maxTotalSize:R}),{historyEnabled:we,conversations:be,conversationsLoading:ve,refreshConversations:ye,deleteConversation:ke}=function({apiBaseUrl:e,apiEndpoints:t,backendType:n="rest",requestHeaders:a}){const[s,i]=r([]),[l,c]=r(!1),d="rest"===n&&!t?.singleEndpoint&&null!==t?.sessions&&null!==t?.history,h=`${e}${t?.history??t?.sessions??"/chat/sessions"}`,u=o(async()=>{if(d){c(!0);try{const e=await fetch(h,{method:"GET",headers:{...a??{}}});if(!e.ok)return void i([]);const t=await e.json(),n=Array.isArray(t)?t:Array.isArray(t?.conversations)?t.conversations:[];i(n.map(I).filter(e=>null!==e))}catch{i([])}finally{c(!1)}}},[d,h,a]),g=o(async e=>{if(!d)return!1;try{return!!(await fetch(`${h}/${encodeURIComponent(e)}`,{method:"DELETE",headers:{...a??{}}})).ok&&(i(t=>t.filter(t=>t.conversationId!==e)),!0)}catch{return!1}},[d,h,a]);return{historyEnabled:d,conversations:s,conversationsLoading:l,refreshConversations:u,deleteConversation:g}}({apiBaseUrl:d,apiEndpoints:u,backendType:F,requestHeaders:U}),[Ne,Ce]=r(!1),{sidebarWidth:_e,handleResizeStart:ze,defaultWidth:Me,isResizing:$e}=function({mode:e,resizable:t,onWidthChange:n,onResizeStart:o,onResizeEnd:i}){const[l,c]=r(()=>{if("undefined"==typeof window)return L;const e=localStorage.getItem(z);if(e){const t=parseInt(e,10);if(!Number.isNaN(t)&&t>=L)return t}return L}),[d,h]=r(!1),u=a(!1),g=a(l);g.current=l;const m=a(n);m.current=n;const p=a(i);return p.current=i,s(()=>{"sidebar"===e&&t&&m.current?.(g.current)},[e,t]),s(()=>{if("sidebar"!==e||!t)return;const n=e=>{if(!u.current)return;e.preventDefault();const t=window.innerWidth-e.clientX,n=.4*window.innerWidth,r=Math.min(Math.max(t,L),n);c(r),g.current=r,m.current?.(r)},r=()=>{u.current&&(u.current=!1,h(!1),document.body.style.cursor="",document.body.style.userSelect="",localStorage.setItem(z,String(g.current)),p.current?.())},a=()=>{const e=.4*window.innerWidth;if(g.current>e){const t=Math.max(e,L);c(t),g.current=t,m.current?.(t)}};return document.addEventListener("mousemove",n),document.addEventListener("mouseup",r),window.addEventListener("resize",a),()=>{document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",r),window.removeEventListener("resize",a)}},[e,t]),{sidebarWidth:l,handleResizeStart:e=>{e.preventDefault(),u.current=!0,h(!0),document.body.style.cursor="col-resize",document.body.style.userSelect="none",o?.()},defaultWidth:L,isResizing:d}}({mode:n,resizable:C,onWidthChange:M,onResizeStart:$,onResizeEnd:T});s(()=>{const e="sidebar"===n?C?_e:Me:0,t=e>0?e+6:0;if(document.documentElement.style.setProperty("--chatbot-sidebar-width",`${t}px`),document.documentElement.style.setProperty("--chatbot-transition",$e?"none":"all 225ms cubic-bezier(0.4, 0, 0.2, 1)"),O){const e=document.querySelector(O);if(e){const n=e.style.paddingRight,r=e.style.transition;return e.style.paddingRight=t>0?`${t}px`:"",e.style.transition=$e?"none":"padding-right 225ms cubic-bezier(0.4, 0, 0.2, 1)",()=>{e.style.paddingRight=n,e.style.transition=r,document.documentElement.style.setProperty("--chatbot-sidebar-width","0px")}}}return()=>{document.documentElement.style.setProperty("--chatbot-sidebar-width","0px")}},[O,n,_e,Me,C,$e]);const Te=y??t(W,{size:24}),Ee=p.firstName,Ae=re?.name||G?.name||"Assistant",je=null!=u?.download,De="rest"===F&&null!==u?.download&&(!u?.singleEndpoint||je),Re=o(async e=>{const t=`${d}${u?.download??"/chat/files"}/${encodeURIComponent(e.fileId)}/download`;try{const n=await fetch(t,{method:"GET",credentials:"include",headers:{...U??{}}});if(!n.ok)throw new Error(`Download failed: ${n.status}`);const r=await n.blob(),a=URL.createObjectURL(r),o=document.createElement("a");o.href=a,o.download=e.filename||"download",document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(a)}catch(t){j?.(t,e)}},[d,u,U,j]),Ue={"--chat-accent":v,"--chat-accent-10":h(v,.1),"--chat-accent-40":h(v,.25),"--chat-accent-50":h(v,.5),"--chat-accent-dark":v},Be=a(!0);s(()=>(Be.current=!0,()=>{Be.current=!1}),[]),s(()=>{if(null===u?.sessions||u?.singleEndpoint||"legacy"===F||"ag-ui"===F)return;if(!ne||oe.current||!G)return;oe.current=!0;const e=ne,t=()=>!Be.current||se.current!==e;fetch(`${d}${u?.sessions??"/chat/sessions"}`,{method:"POST",headers:{"Content-Type":"application/json",...U??{}},body:JSON.stringify({conversation_id:ne,agent_slug:G.slug})}).then(e=>t()?null:e.ok?e.json():(fe(null),null)).then(n=>{if(!n||t())return;if("string"==typeof n.conversation_id&&n.conversation_id&&n.conversation_id!==e&&fe(n.conversation_id),!n.messages?.length)return;const r=n.messages.map((e,t)=>({id:`restored-${t}`,role:e.role,content:e.content,timestamp:new Date,attachments:f(e.attachments),toolNames:Array.isArray(e.tool_names)?e.tool_names:void 0,toolCallCount:"number"==typeof e.tool_call_count?e.tool_call_count:void 0,iterations:"number"==typeof e.iterations?e.iterations:void 0,reasoning:"string"==typeof e.reasoning?e.reasoning:void 0,toolCallTrace:x(e.tool_call_trace),transferChain:w(e.transfer_chain),isTruncated:!0===e.is_truncated||void 0}));pe(r)}).catch(()=>{t()||fe(null)})},[ne,G,d,u,F,oe,se,Be,U,pe,fe]);const Oe=(()=>{const e="filigran-chatbot";switch(n){case"sidebar":return`${e} fixed right-0 bottom-0 flex flex-col bg-white dark:bg-[#1e1e2e] border-l border-gray-200 dark:border-white/10 z-[1200]`;case"floating":return`${e} fixed bottom-5 right-5 flex flex-col bg-white dark:bg-[#1e1e2e] rounded-xl shadow-[0_8px_32px_rgba(0,0,0,0.15)] dark:shadow-[0_8px_32px_rgba(0,0,0,0.4)] z-[1300] border border-gray-200 dark:border-white/10`;case"fullscreen":return`${e} fixed right-0 bottom-0 left-0 flex flex-col bg-gray-50 dark:bg-[#161622] z-[1400]`;default:return e}})(),We={...Ue,..."sidebar"===n?{top:c,width:C?_e:Me}:"floating"===n?{width:380,height:560}:{top:c}};return e("div",{className:Oe,style:We,children:["sidebar"===n&&C&&t("div",{onMouseDown:ze,className:"absolute top-0 -left-1 bottom-0 w-2 cursor-col-resize z-10 group",children:t("div",{className:"absolute top-0 left-1/2 -translate-x-1/2 bottom-0 w-0.5 rounded-sm bg-[var(--chat-accent)] opacity-0 transition-opacity group-hover:opacity-100 group-active:opacity-100"})}),t(ge,{mode:n,agentName:Ae,agents:V,selectedAgent:G,transferredFrom:re?G?.name:void 0,agentMenuOpen:q,onAgentMenuToggle:()=>J(e=>!e),onAgentMenuClose:()=>J(!1),onSwitchAgent:e=>{e&&K(e,()=>{de()})},modeMenuOpen:H,onModeMenuToggle:()=>P(e=>!e),onModeMenuClose:()=>P(!1),onModeChange:l,onNewChat:de,onClose:i,logoIcon:Te,agentDashboardUrl:m,historyEnabled:we,historyMenuOpen:Ne,onHistoryMenuToggle:()=>{const e=!Ne;e&&ye(),Ce(e)},onHistoryMenuClose:()=>Ce(!1),conversations:be,conversationsLoading:ve,activeConversationId:ne,onSelectConversation:e=>{Ce(!1),xe(e)},onDeleteConversation:e=>{(async e=>{await ke(e)&&e===se.current&&de()})(e)},t:b}),0===Z.length?t(Ie,{firstName:Ee,logoIcon:Te,promptSuggestions:k,onPromptClick:Q,t:b}):t(Se,{messages:Z,isLoading:Y,agentStatus:ee,agentName:Ae,logoIcon:Te,onRelativeLinkClick:A,onDownloadFile:De?Re:void 0,t:b}),t(me,{inputValue:X,onInputChange:Q,onSend:ce,onStop:he,isLoading:Y,canSteer:ae,attachedFiles:E?[]:te,onFileAdd:E?void 0:ie,onFileRemove:E?void 0:e=>ue(t=>t.filter((t,n)=>n!==e)),onPaste:E?void 0:le,t:b,mode:n,separatorColor:N})]})},Me=({isOpen:n,onToggle:r,label:a="Ask Assistant",accentColor:o="#7b5cff",icon:s})=>{const i=s??t(W,{size:16});return e("button",{type:"button",onClick:r,className:"filigran-chatbot inline-flex items-center gap-1.5 px-3 py-[3px] text-[0.8125rem] font-medium whitespace-nowrap rounded-md border transition-colors",style:{borderColor:n?o:h(o,.5),color:o,backgroundColor:n?h(o,.1):"transparent"},onMouseEnter:e=>{e.currentTarget.style.borderColor=o,e.currentTarget.style.backgroundColor=h(o,.1)},onMouseLeave:e=>{e.currentTarget.style.borderColor=n?o:h(o,.5),e.currentTarget.style.backgroundColor=n?h(o,.1):"transparent"},children:[t("span",{className:"[&>svg]:w-4 [&>svg]:h-4",children:i}),a]})};export{ze as ChatPanel,Me as ChatToggleButton};
|
|
1
|
+
import{jsxs as e,jsx as t,Fragment as n}from"react/jsx-runtime";import{useState as r,useRef as a,useCallback as o,useEffect as s,useMemo as i}from"react";import{createPortal as l}from"react-dom";import c from"react-markdown";import d from"remark-gfm";function h(e,t){return`${e}${Math.round(255*t).toString(16).padStart(2,"0")}`}function u(e){if(!e)return e;const t=e.split("\n"),n=/^(\s*)(`{3,})(.*)$/,r=/^(markdown|md|mdx|markup)\b/i;let a=-1;for(let e=0;e<t.length;e++){const o=t[e].match(n);if(o&&3===o[2].length&&r.test(o[3].trim())){a=e;break}}if(-1===a)return e;let o=3,s=0,i=-1;for(let e=a+1;e<t.length;e++){const r=t[e].match(n);r&&(s++,o=Math.max(o,r[2].length),""===r[3].trim()&&(i=e))}if(0===s)return e;const l="`".repeat(Math.max(o+1,4)),c=t[a].match(n);if(t[a]=`${c[1]}${l}${c[3]}`,i>a){const e=t[i].match(n);t[i]=`${e[1]}${l}`}return t.join("\n")}const g=e=>e;function m(e){let t=e;for(;t;){if(t.classList.contains("filigran-chatbot"))return t;t=t.parentElement}return document.body}const p=/\[\[FILE(?::[^\]]*)?\]?$/;function f(e){if(!Array.isArray(e))return;const t=[];for(const n of e){if(!n||"object"!=typeof n)continue;const e=n,r=e.file_id;"string"==typeof r&&r&&t.push({fileId:r,filename:"string"==typeof e.filename?e.filename:"file",type:"string"==typeof e.type?e.type:void 0,size:"number"==typeof e.size?e.size:void 0,contentType:"string"==typeof e.content_type?e.content_type:void 0,fileTag:"working_file"===e.file_tag?"working_file":"download_file"})}return t.length>0?t:void 0}function w(e){if(!Array.isArray(e))return;const t=[];for(const n of e){if(!n||"object"!=typeof n)continue;const e=n;"string"==typeof e.name&&e.name&&t.push({name:e.name,input:"string"==typeof e.input?e.input:void 0,output:"string"==typeof e.output?e.output:void 0,success:"boolean"!=typeof e.success||e.success})}return t.length>0?t:void 0}function x(e){if(!Array.isArray(e))return;const t=[];for(const n of e){if(!n||"object"!=typeof n)continue;const e=n;"string"==typeof e.agent_name&&e.agent_name&&t.push({agentId:"string"==typeof e.agent_id?e.agent_id:"",agentName:e.agent_name})}return t.length>0?t:void 0}function v(e,t){const n=e.type;if("error"===n)return{action:"error",content:e.content||""};if("status"===n){const n=e.status;return"tool_done"===n||"wind_down"===n?{action:"noop"}:"streaming"===n?{action:"status",status:"streaming"}:"thinking_text"===n?{action:"status",status:"thinking_text",thinkingContent:e.content}:"tool_start"===n?(t.hasUsedTools=!0,{action:"status",status:"tool_start",tools:e.tools}):"tool_heartbeat"===n?{action:"status",status:"tool_heartbeat",tools:e.tools,elapsedS:"number"==typeof e.elapsed_s?e.elapsed_s:void 0}:"thinking"===n&&t.hasUsedTools?{action:"status",status:"analyzing"}:{action:"status",status:n,tools:e.tools}}return"stream"===n?{action:"stream",content:e.content}:"done"===n?{action:"done",content:e.content,conversationId:e.conversation_id,toolNames:e.tool_names,toolCallCount:e.tool_call_count,iterations:e.iterations,transferAgentId:e.transfer_agent_id,transferAgentName:e.transfer_agent_name,attachments:f(e.attachments),reasoning:"string"==typeof e.reasoning?e.reasoning:void 0,toolCallTrace:w(e.tool_call_trace),transferChain:x(e.transfer_chain),isTruncated:!0===e.is_truncated||void 0}:{action:"noop"}}function y(e,t){const n=e.event;if("nextAgentFlow"===n){const n=e.data,r=n?.nodeId;return"INPROGRESS"===n?.status&&r&&(t.activeNodeId=r),{action:"noop"}}if("start"===n)return{action:"noop"};if("token"===n){return{action:"stream",content:(e.data??"").replace(/<br\s*\/?>/g,"\n")}}if("agentReasoning"===n){const n=e.data,r=n?.usedTools;return r?.length?(t.hasUsedTools=!0,{action:"status",status:"tool_start",tools:r.map(e=>e.tool)}):t.hasUsedTools?{action:"status",status:"analyzing"}:{action:"status",status:"thinking"}}if("usedTools"===n){t.hasUsedTools=!0;const n=e.data;return{action:"status",status:"tool_start",tools:Array.isArray(n)?n.map(e=>e.tool):[]}}if("metadata"===n){const t=e.data,n=t?.chatId;return n?{action:"set_chat_id",chatId:n}:{action:"noop"}}return"error"===n?{action:"error",content:e.data||""}:"end"===n?{action:"done",content:""}:{action:"noop"}}function b(e,t){const n=e.type;if("RUN_STARTED"===n)return{action:"status",status:"thinking"};if("RUN_FINISHED"===n)return{action:"done",content:""};if("RUN_ERROR"===n)return{action:"error",content:e.message||"Unknown error"};if("STEP_STARTED"===n){return{action:"status",status:e.stepName||"thinking"}}if("STEP_FINISHED"===n)return{action:"noop"};if("TEXT_MESSAGE_START"===n)return{action:"status",status:"streaming"};if("TEXT_MESSAGE_CONTENT"===n){const t=e.delta;return t?{action:"stream",content:t}:{action:"noop"}}if("TEXT_MESSAGE_END"===n)return{action:"noop"};if("TEXT_MESSAGE_CHUNK"===n){const t=e.delta;return t?{action:"stream",content:t}:{action:"noop"}}if("TOOL_CALL_START"===n){t.hasUsedTools=!0;const n=e.toolCallName;return{action:"status",status:"tool_start",tools:n?[n]:[]}}if("TOOL_CALL_ARGS"===n)return{action:"noop"};if("TOOL_CALL_END"===n)return{action:"status",status:"analyzing"};if("TOOL_CALL_RESULT"===n)return{action:"noop"};if("TOOL_CALL_CHUNK"===n){const n=e.toolCallName;return n?(t.hasUsedTools=!0,{action:"status",status:"tool_start",tools:[n]}):{action:"noop"}}if("REASONING_START"===n||"REASONING_MESSAGE_START"===n)return{action:"status",status:"thinking"};if("REASONING_MESSAGE_CONTENT"===n||"REASONING_MESSAGE_CHUNK"===n){const t=e.delta;return t?{action:"status",status:"thinking_text",thinkingContent:t}:{action:"status",status:"thinking"}}return{action:"noop"}}const k="filigranChatConversationId",N="filigranChatLegacyChatId",C=52428800;function _({apiBaseUrl:e,apiEndpoints:t,backendType:n="rest",agentSlug:s,requestHeaders:i,pageContext:l,t:c,maxFileCount:d=10,maxTotalSize:h=52428800}){const u="legacy"===n,[g,m]=r([]),[p,f]=r(""),[w,x]=r(!1),[_,S]=r(null),[L,I]=r(()=>"undefined"==typeof window?null:localStorage.getItem(k)),[M,z]=r([]),[T,E]=r(null),[$,A]=r(()=>"undefined"==typeof window?null:localStorage.getItem(N)),R=a(!1),j=a(null),D=a(!1),U=a(L),B=a(l);B.current=l;const O=a(null),W=a(new AbortController),F=Number.isFinite(d)&&d>0?Math.floor(d):10,H=Number.isFinite(h)&&h>0?h:C,P=()=>u||"ag-ui"===n||t?.singleEndpoint||null===t?.steer?null:`${e}${t?.steer??"/chat/messages/steer"}`,G=()=>u||t?.singleEndpoint||null===t?.upload?null:`${e}${t?.upload??"/chat/upload"}`,V=o(e=>{U.current=e,I(e),e?localStorage.setItem(k,e):localStorage.removeItem(k)},[]),q=async n=>{if(U.current)return U.current;if(O.current)return O.current;const r=u||t?.singleEndpoint||null===t?.sessions?null:`${e}${t?.sessions??"/chat/sessions"}`;if(!r)return null;const a=(async()=>{try{const e=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json",...i??{}},body:JSON.stringify({agent_slug:n})});if(!e.ok)return null;const t=await e.json(),a=t?.conversation_id??null;return a&&V(a),a}catch{return null}finally{O.current=null}})();return O.current=a,a},J=async(e,t,n)=>{const r=G(),a=new FormData;a.append("conversation_id",t),a.append("file",e,e.name);const o=i?Object.fromEntries(Object.entries(i).filter(([e])=>"content-type"!==e.toLowerCase())):void 0,s=await fetch(r,{method:"POST",headers:o,body:a,signal:n});if(!s.ok)throw new Error(`File upload failed: ${s.status}`);const l=(await s.json()).file_ids??[];if(0===l.length)throw new Error("No file_id returned");return l[0]},K=e=>{if(!e||0===e.length||!G())return;const t=Array.from(e).map(e=>({file:e,tempId:crypto.randomUUID()}));let n=[];z(e=>{const r=e.length,a=e.reduce((e,t)=>e+t.size,0),o=F-r;if(o<=0)return e;let s=H-a;const i=[];for(const e of t.slice(0,o))e.file.size<=s&&(i.push(e),s-=e.file.size);if(0===i.length)return e;n=i;const l=i.map(({file:e,tempId:t})=>({name:e.name,type:e.type,size:e.size,rawFile:e,uploadStatus:"pending",fileId:t}));return[...e,...l]}),setTimeout(()=>{const e=W.current.signal;for(const{file:t,tempId:r}of n)(async()=>{try{const n=await q(s);if(!n)return void z(e=>e.map(e=>e.fileId===r?{...e,uploadStatus:"error"}:e));const a=await J(t,n,e);z(e=>e.map(e=>e.fileId===r?{...e,fileId:a,uploadStatus:"done"}:e))}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;z(e=>e.map(e=>e.fileId===r?{...e,uploadStatus:"error"}:e))}})()},0)},Z=()=>{j.current?.abort(),j.current=null,W.current.abort(),W.current=new AbortController,O.current=null,m([]),f(""),z([]),x(!1),S(null),E(null),D.current=!1,R.current=!1,u?(A(null),localStorage.removeItem(N)):V(null)},X=w&&null!==P()&&null!==L;return{messages:g,inputValue:p,setInputValue:f,isLoading:w,agentStatus:_,attachedFiles:M,conversationId:L,transferredAgent:T,canSteer:X,historyLoadedRef:R,conversationIdRef:U,handleFileAdd:K,handlePaste:e=>{const{files:t}=e.clipboardData;t.length>0&&(e.preventDefault(),K(t))},handleSendMessage:async()=>{const r=p.trim();if(w)return void(r&&0===M.length&&P()&&U.current&&(f(""),await(async e=>{const t=P(),n=U.current;if(!t||!n)return;const r={id:crypto.randomUUID(),role:"user",content:e,timestamp:new Date};m(e=>[...e,r]);try{const r=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",...i??{}},body:JSON.stringify({conversation_id:n,content:e,agent_slug:s})});if(!r.ok)throw new Error(`Steer failed: ${r.status}`)}catch{m(e=>e.filter(e=>e.id!==r.id)),f(t=>t?`${e}\n${t}`:e)}})(r)));if(!p.trim()&&0===M.length)return;const a=p.trim(),o={id:crypto.randomUUID(),role:"user",content:a,timestamp:new Date,files:M.length>0?[...M]:void 0};m(e=>[...e,o]),f(""),z([]),x(!0),S({status:"thinking"}),D.current=!1;const l=crypto.randomUUID();m(e=>[...e,{id:l,role:"assistant",content:"",timestamp:new Date}]);let d=l;try{const r=new AbortController;j.current=r;const h=(o.files??[]).filter(e=>"done"===e.uploadStatus&&e.fileId).map(e=>e.fileId),g=function(e,t,n){switch(e){case"legacy":return{question:t,chatId:n.legacyChatId??void 0,streaming:!0};case"ag-ui":return{threadId:n.conversationId??crypto.randomUUID(),runId:crypto.randomUUID(),messages:[{id:crypto.randomUUID(),role:"user",content:t}],tools:[],context:[],state:{},forwardedProps:n.agentSlug?{agentSlug:n.agentSlug}:{}};default:{const e={content:t,conversation_id:n.conversationId,agent_slug:n.agentSlug};if(n.pageContext&&Object.keys(n.pageContext).length>0)try{const t=JSON.stringify(n.pageContext);t&&"{}"!==t&&(e.context=n.pageContext)}catch{}return e}}}(n,a,{legacyChatId:$,conversationId:U.current,agentSlug:s,pageContext:B.current});h.length>0&&(g.file_ids=h),S({status:"thinking"});const p=await fetch(u||t?.singleEndpoint?e:`${e}${t?.messages??"/chat/messages"}`,{method:"POST",headers:{"Content-Type":"application/json",...i??{}},body:JSON.stringify(g),signal:r.signal});if(!p.ok||!p.body)return void m(e=>e.map(e=>e.id===l?{...e,content:c("Unable to connect. Please check the configuration.")}:e));const f=function(e){switch(e){case"legacy":return y;case"ag-ui":return b;default:return v}}(n),w={hasUsedTools:!1,activeNodeId:""},x=p.body.getReader(),k=new TextDecoder;let C="",_="",L=!1;const I=()=>{if(!L)return;L=!1,_="",d=crypto.randomUUID();const e=d;m(t=>[...t,{id:e,role:"assistant",content:"",timestamp:new Date}]),S({status:"thinking"})};for(;;){const{done:e,value:t}=await x.read();if(e)break;C+=k.decode(t,{stream:!0});const n=C.split("\n");C=n.pop()||"";for(const e of n){const t=e.replace(/\r$/,"");if(!t.startsWith("data:"))continue;const n=t.startsWith("data: ")?t.slice(6):t.slice(5);try{const e=f(JSON.parse(n),w);switch(w.hasUsedTools=w.hasUsedTools||D.current,e.action){case"status":{I();const t=d;"tool_start"===e.status&&(D.current=!0),"stream_retract"===e.status?(_="",m(e=>e.map(e=>e.id===t?{...e,content:""}:e)),S(e=>({status:"analyzing",thinkingContent:e?.thinkingContent}))):"thinking_text"===e.status?S(t=>({...t,status:t?.status??"thinking",thinkingContent:(t?.thinkingContent??"")+(e.thinkingContent??"")})):"tool_heartbeat"===e.status?S(t=>t?{...t,elapsedS:e.elapsedS}:{status:"tool_start",tools:e.tools,elapsedS:e.elapsedS}):S(t=>({status:e.status,tools:e.tools,thinkingContent:t?.thinkingContent}));break}case"stream":{I(),_+=e.content;const t=d,n=_;S(e=>({status:"streaming",thinkingContent:e?.thinkingContent})),m(e=>e.map(e=>e.id===t?{...e,content:n}:e));break}case"done":{L=!0,e.conversationId&&V(e.conversationId),e.transferAgentId&&e.transferAgentName&&E({id:e.transferAgentId,name:e.transferAgentName});const t=d,n=e.content||_;m(r=>r.map(r=>r.id===t?{...r,content:n,toolNames:e.toolNames,toolCallCount:e.toolCallCount,iterations:e.iterations,attachments:e.attachments,reasoning:e.reasoning,toolCallTrace:e.toolCallTrace,transferChain:e.transferChain,isTruncated:e.isTruncated}:r));break}case"error":{I();const t=d;return void m(n=>n.map(n=>n.id===t?{...n,content:e.content||c("Unable to connect. Please check the configuration.")}:n))}case"set_chat_id":A(e.chatId),localStorage.setItem(N,e.chatId)}D.current=w.hasUsedTools}catch{}}}if(_&&!L){const e=d,t=_;m(n=>n.map(n=>n.id===e?{...n,content:t||"No response."}:n))}}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;const t=d;m(e=>e.map(e=>e.id===t?{...e,content:c("Sorry, an error occurred. Please try again.")}:e))}finally{j.current=null,x(!1),S(null),D.current=!1}},handleNewChat:Z,handleStopGenerating:()=>{j.current?.abort(),j.current=null,x(!1),S(null),D.current=!1,m(e=>e.filter(e=>!("assistant"===e.role&&!e.content)))},setAttachedFiles:z,setMessages:m,updateConversationId:V,handleSwitchConversation:e=>{(u||e!==U.current)&&(Z(),u||V(e))}}}const S="filigranChatAgentSlug";function L(e){if(!e||"object"!=typeof e)return null;const t=e,n=t.conversation_id??t.id;if("string"!=typeof n||!n)return null;return{conversationId:n,title:"string"==typeof t.title?t.title.trim():"",updatedAt:"string"==typeof t.updated_at?t.updated_at:"string"==typeof t.created_at?t.created_at:void 0,messageCount:"number"==typeof t.message_count?t.message_count:void 0}}const I=400,M="filigranChatSidebarWidth";let z=null,T=null,E=0;function $(){null!==z&&(window.clearInterval(z),z=null),null!==T&&(document.title=T,T=null)}function A({isLoading:e,agentName:t,t:n,enabled:r=!0,onComplete:o,isViewingChat:i}){const l=a(!1),c=a(0);s(()=>{if(!r||"undefined"==typeof document)return;E+=1;const e=()=>{!document.hidden&&document.hasFocus()&&$()};return document.addEventListener("visibilitychange",e),window.addEventListener("focus",e),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("focus",e),E=Math.max(0,E-1),0===E&&$()}},[r]),s(()=>{const a=l.current;if(l.current=e,!e||a){if(!e&&a&&r){if(Date.now()-c.current<4e3)return;const e="undefined"!=typeof document&&document.hidden,r="undefined"!=typeof document&&!document.hasFocus(),a=e||r,s=!i||i();if(!a&&s)return;const l=n("Response ready"),d=`${t} ${n("has finished")}`;a&&(function(e){if("undefined"==typeof document)return;null===T&&(T=document.title),null!==z&&window.clearInterval(z);let t=!0;document.title=e,z=window.setInterval(()=>{t=!t,document.title=t?e:T??e},1200)}(l),function(e,t){try{if("undefined"==typeof Notification||"granted"!==Notification.permission)return;new Notification(e,{body:t,tag:"filigran-chat-complete"})}catch{}}(l,d)),o?.(l,d)}}else c.current=Date.now()},[e,r,t,n,o,i])}const R=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"}),t("path",{d:"M12 9v4"}),t("path",{d:"M12 17h.01"})]}),j=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"m16 3 4 4-4 4"}),t("path",{d:"M20 7H4"}),t("path",{d:"m8 21-4-4 4-4"}),t("path",{d:"M4 17h16"})]}),D=({className:e,size:n=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:e,children:t("path",{d:"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"})}),U=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M12 8V4H8"}),t("rect",{width:"16",height:"12",x:"4",y:"8",rx:"2"}),t("path",{d:"M2 14h2"}),t("path",{d:"M20 14h2"}),t("path",{d:"M15 13v2"}),t("path",{d:"M9 13v2"})]}),B=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z"}),t("path",{d:"M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z"}),t("path",{d:"M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4"}),t("path",{d:"M17.599 6.5a3 3 0 0 0 .399-1.375"}),t("path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5"}),t("path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396"}),t("path",{d:"M19.938 10.5a4 4 0 0 1 .585.396"}),t("path",{d:"M6 18a4 4 0 0 1-1.967-.516"}),t("path",{d:"M19.967 17.484A4 4 0 0 1 18 18"})]}),O=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("circle",{cx:"12",cy:"12",r:"10"}),t("path",{d:"m9 12 2 2 4-4"})]}),W=({className:e,size:n=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:e,children:t("path",{d:"M20 6 9 17l-5-5"})}),F=({className:e,size:n=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:e,children:t("path",{d:"m6 9 6 6 6-6"})}),H=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M18 6 6 18"}),t("path",{d:"m6 6 12 12"})]}),P=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2"}),t("path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"})]}),G=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),t("path",{d:"M3 5V19A9 3 0 0 0 21 19V5"}),t("path",{d:"M3 12A9 3 0 0 0 21 12"})]}),V=({className:e,size:n=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",className:e,children:t("path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"})}),q=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),t("polyline",{points:"7 10 12 15 17 10"}),t("line",{x1:"12",x2:"12",y1:"15",y2:"3"})]}),J=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M12 20h9"}),t("path",{d:"M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z"})]}),K=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M15 3h6v6"}),t("path",{d:"M10 14 21 3"}),t("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]}),Z=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),t("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]}),X=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M11 13H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h7"}),t("rect",{width:"12",height:"12",x:"10",y:"10",rx:"2"})]}),Q=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M8 3v3a2 2 0 0 1-2 2H3"}),t("path",{d:"M21 8h-3a2 2 0 0 1-2-2V3"}),t("path",{d:"M3 16h3a2 2 0 0 0 2 2v3"}),t("path",{d:"M16 21v-3a2 2 0 0 1 2-2h3"})]}),Y=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M8 3H5a2 2 0 0 0-2 2v3"}),t("path",{d:"M21 8V5a2 2 0 0 0-2-2h-3"}),t("path",{d:"M3 16v3a2 2 0 0 0 2 2h3"}),t("path",{d:"M16 21h3a2 2 0 0 0 2-2v-3"})]}),ee=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("line",{x1:"6",x2:"10",y1:"11",y2:"11"}),t("line",{x1:"8",x2:"8",y1:"9",y2:"13"}),t("line",{x1:"15",x2:"15.01",y1:"12",y2:"12"}),t("line",{x1:"18",x2:"18.01",y1:"10",y2:"10"}),t("path",{d:"M17.32 5H6.68a4 4 0 0 0-3.978 3.59c-.006.052-.01.101-.017.152C2.604 9.416 2 14.456 2 16a3 3 0 0 0 3 3c1 0 1.5-.5 2-1l1.414-1.414A2 2 0 0 1 9.828 16h4.344a2 2 0 0 1 1.414.586L17 18c.5.5 1 1 2 1a3 3 0 0 0 3-3c0-1.545-.604-6.584-.685-7.258-.007-.05-.011-.1-.017-.151A4 4 0 0 0 17.32 5z"})]}),te=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("circle",{cx:"12",cy:"12",r:"10"}),t("path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"}),t("path",{d:"M2 12h20"})]}),ne=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),t("path",{d:"M3 3v5h5"}),t("path",{d:"M12 7v5l4 2"})]}),re=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("circle",{cx:"12",cy:"12",r:"10"}),t("path",{d:"M12 16v-4"}),t("path",{d:"M12 8h.01"})]}),ae=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("rect",{width:"20",height:"16",x:"2",y:"4",rx:"2"}),t("path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"})]}),oe=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("circle",{cx:"11",cy:"11",r:"8"}),t("path",{d:"m21 21-4.3-4.3"})]}),se=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"m22 2-7 20-4-9-9-4Z"}),t("path",{d:"m22 2-11 11"})]}),ie=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),t("path",{d:"M15 3v18"})]}),le=({className:e,size:n=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:e,children:t("path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"})}),ce=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("circle",{cx:"12",cy:"12",r:"10"}),t("rect",{width:"6",height:"6",x:"9",y:"9"})]}),de=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("polyline",{points:"4 17 10 11 4 5"}),t("line",{x1:"12",x2:"20",y1:"19",y2:"19"})]}),he=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M3 6h18"}),t("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),t("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"}),t("line",{x1:"10",x2:"10",y1:"11",y2:"17"}),t("line",{x1:"14",x2:"14",y1:"11",y2:"17"})]}),ue=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),t("circle",{cx:"9",cy:"7",r:"4"}),t("line",{x1:"19",x2:"19",y1:"8",y2:"14"}),t("line",{x1:"22",x2:"16",y1:"11",y2:"11"})]}),ge=({className:e,size:n=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:e,children:t("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),me=({className:n,size:r=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[t("circle",{cx:"12",cy:"12",r:"10"}),t("path",{d:"m15 9-6 6"}),t("path",{d:"m9 9 6 6"})]});const pe=({open:e,onClose:n,anchorRef:i,placement:c="bottom-start",width:d=280,children:h})=>{const u=a(null),[g,p]=r({top:0,left:0});if(function(e,t,n=!0){s(()=>{if(!n)return;const r=n=>{e.current&&!e.current.contains(n.target)&&t()};return document.addEventListener("mousedown",r),document.addEventListener("touchstart",r),()=>{document.removeEventListener("mousedown",r),document.removeEventListener("touchstart",r)}},[e,t,n])}(u,o(()=>n(),[n]),e),s(()=>{if(!e||!i.current)return;const t=i.current.getBoundingClientRect(),n="bottom-end"===c?t.right-d:t.left;p({top:t.bottom+4,left:n})},[e,i,c,d]),!e)return null;const f=m(i.current);return l(t("div",{ref:u,className:"fixed z-[10000] rounded-[10px] overflow-hidden border border-gray-200 dark:border-white/10 bg-white dark:bg-[#2a2a3e] shadow-xl",style:{top:g.top,left:g.left,width:d},children:h}),f)},fe=({size:e=16,className:n=""})=>t("div",{className:`animate-spin rounded-full border-2 border-current/20 border-t-[var(--chat-accent)] ${n}`,style:{width:e,height:e}}),we=({title:n,children:o})=>{const s=a(null),[i,c]=r(!1),[d,h]=r({top:0,left:0}),[u,g]=r(!1);if(!n)return o;return e("span",{ref:s,className:"inline-flex",onMouseEnter:()=>{if(!s.current)return;const e=s.current.getBoundingClientRect(),t=m(s.current).getBoundingClientRect().top,n=e.top-t<28;g(n),h({top:n?e.bottom+4:e.top-4,left:e.left+e.width/2}),c(!0)},onMouseLeave:()=>c(!1),children:[o,i&&l(t("span",{className:`pointer-events-none fixed z-[10001] -translate-x-1/2 ${u?"":"-translate-y-full"} whitespace-nowrap rounded-md bg-gray-900 dark:bg-gray-100 px-2 py-1 text-xs text-white dark:text-gray-900 shadow-lg`,style:{top:d.top,left:d.left},role:"tooltip",children:n}),m(s.current))]})},xe=[{mode:"floating",label:"Floating",getIcon:e=>t(X,{...e})},{mode:"sidebar",label:"Sidebar",getIcon:e=>t(ie,{...e})},{mode:"fullscreen",label:"Full screen",getIcon:e=>t(Y,{...e})}],ve=({mode:r,agentName:o,agents:s,selectedAgent:i,transferredFrom:l,agentMenuOpen:c,onAgentMenuToggle:d,onAgentMenuClose:h,onSwitchAgent:u,modeMenuOpen:g,onModeMenuToggle:m,onModeMenuClose:p,onModeChange:f,onNewChat:w,onClose:x,logoIcon:v,agentDashboardUrl:y,historyEnabled:b=!1,historyMenuOpen:k=!1,onHistoryMenuToggle:N,onHistoryMenuClose:C,conversations:_=[],conversationsLoading:S=!1,activeConversationId:L=null,onSelectConversation:I,onDeleteConversation:M,t:z})=>{const T=a(null),E=a(null),$=a(null),A="sidebar"===r?ie:"fullscreen"===r?Q:X;return e("div",{className:"flex items-center px-3 py-2 min-h-[48px] border-b border-gray-200 dark:border-white/10 bg-gradient-to-br from-[var(--chat-accent-dark)]/[0.13] to-[var(--chat-accent)]/[0.07] "+("floating"===r?"rounded-t-xl":""),children:[e("div",{className:"min-w-0",children:[e("button",{ref:T,type:"button",onClick:d,className:"flex items-center gap-1.5 text-sm font-semibold text-gray-900 dark:text-white px-2 py-1 rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:[t("span",{className:"flex items-center text-[var(--chat-accent)] [&>svg]:w-[18px] [&>svg]:h-[18px]",children:v}),t("span",{children:o}),t(F,{size:16,className:"text-gray-400 dark:text-white/30"})]}),l&&e("div",{className:"pl-10 pr-2 text-[0.6rem] font-normal text-gray-400 dark:text-white/30",children:[z("Transferred from")," ",l]})]}),e(pe,{open:c,onClose:h,anchorRef:T,width:280,children:[t("span",{className:"block px-4 pt-3 pb-1 text-[0.68rem] tracking-[1px] uppercase text-gray-400 dark:text-white/40",children:z("Switch to another agent")}),0===s.length&&t("div",{className:"px-4 py-2",children:t(fe,{size:16})}),t("div",{children:s.map(n=>e("button",{type:"button",onClick:()=>u(n),className:"w-full flex items-center gap-2 px-4 py-1.5 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors "+(n.id===i?.id?"bg-[var(--chat-accent)]/10":""),children:[t("div",{className:"w-7 h-7 rounded-full flex items-center justify-center shrink-0 bg-gradient-to-br from-[var(--chat-accent)]/20 to-[var(--chat-accent)]/5",children:t("span",{className:"text-[var(--chat-accent)] [&>svg]:w-4 [&>svg]:h-4",children:v})}),e("div",{className:"min-w-0",children:[t("div",{className:"text-[0.8125rem] font-medium text-gray-900 dark:text-white truncate",children:n.name}),n.description&&t("div",{className:"text-[0.7rem] text-gray-500 dark:text-white/40 truncate",children:n.description})]})]},n.id))}),t("div",{className:"h-px bg-gray-200 dark:bg-white/10 mx-2"}),e("div",{children:[y&&e("button",{type:"button",onClick:()=>{h(),window.open(`${y}/agents`,"_blank")},className:"w-full flex items-center gap-2 px-4 py-1.5 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:[t(K,{size:18,className:"text-gray-400 dark:text-white/40 shrink-0"}),t("span",{className:"text-[0.8125rem] text-gray-700 dark:text-white/70",children:z("Browse agents")})]}),y&&e("button",{type:"button",onClick:()=>{h(),window.open(`${y}/agents/new`,"_blank")},className:"w-full flex items-center gap-2 px-4 py-1.5 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:[t(ue,{size:18,className:"text-gray-400 dark:text-white/40 shrink-0"}),t("span",{className:"text-[0.8125rem] text-gray-700 dark:text-white/70",children:z("Create agent")})]})]})]}),t("div",{className:"flex-1"}),b&&e(n,{children:[t(we,{title:z("Conversation history"),children:t("button",{ref:$,type:"button",onClick:N,"aria-label":z("Conversation history"),"aria-haspopup":"menu","aria-expanded":k,className:"w-8 h-8 flex items-center justify-center rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-500 dark:text-white/40 hover:text-gray-700 dark:hover:text-white/70 transition-colors",children:t(ne,{size:18})})}),e(pe,{open:k,onClose:()=>C?.(),anchorRef:$,placement:"bottom-end",width:300,children:[t("span",{className:"block px-4 pt-3 pb-1 text-[0.68rem] tracking-[1px] uppercase text-gray-400 dark:text-white/40",children:z("Conversation history")}),e("div",{className:"max-h-72 overflow-y-auto filigran-chat-scrollable",children:[S&&0===_.length&&t("div",{className:"px-4 py-2",children:t(fe,{size:16})}),!S&&0===_.length&&t("div",{className:"px-4 py-3 text-[0.75rem] text-gray-400 dark:text-white/40",children:z("No conversations yet")}),_.map(n=>{const r=n.conversationId===L,a=function(e,t){if(!e)return"";const n=new Date(e).getTime();if(Number.isNaN(n))return"";const r=Date.now()-n,a=Math.floor(r/6e4);if(a<1)return t("just now");if(a<60)return`${a}${t("m ago")}`;const o=Math.floor(a/60);if(o<24)return`${o}${t("h ago")}`;const s=Math.floor(o/24);return s<7?`${s}${t("d ago")}`:new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})}(n.updatedAt,z);return e("div",{className:"group flex items-center gap-2 px-4 py-1.5 hover:bg-gray-100 dark:hover:bg-white/10 transition-colors "+(r?"bg-[var(--chat-accent)]/10":""),children:[e("button",{type:"button",onClick:()=>I?.(n.conversationId),className:"flex-1 min-w-0 text-left",children:[t("div",{className:"text-[0.8125rem] font-medium text-gray-900 dark:text-white truncate",children:n.title||z("Untitled conversation")}),a&&t("div",{className:"text-[0.7rem] text-gray-500 dark:text-white/40 truncate",children:a})]}),M&&t("button",{type:"button",onClick:()=>M(n.conversationId),title:z("Delete conversation"),"aria-label":z("Delete conversation"),className:"shrink-0 p-1 rounded-md text-gray-400 dark:text-white/30 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 hover:text-red-500 dark:hover:text-red-400 transition-all",children:t(he,{size:14})})]},n.conversationId)})]}),t("div",{className:"h-px bg-gray-200 dark:bg-white/10 mx-2"}),e("button",{type:"button",onClick:()=>{C?.(),w()},className:"w-full flex items-center gap-2 px-4 py-2 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:[t(J,{size:16,className:"text-gray-400 dark:text-white/40 shrink-0"}),t("span",{className:"text-[0.8125rem] text-gray-700 dark:text-white/70",children:z("New conversation")})]})]})]}),t(we,{title:z("New chat"),children:t("button",{type:"button",onClick:w,className:"w-8 h-8 flex items-center justify-center rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-500 dark:text-white/40 hover:text-gray-700 dark:hover:text-white/70 transition-colors",children:t(J,{size:18})})}),t(we,{title:z("Switch view"),children:t("button",{ref:E,type:"button",onClick:m,className:"w-8 h-8 flex items-center justify-center rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-500 dark:text-white/40 hover:text-gray-700 dark:hover:text-white/70 transition-colors",children:t(A,{size:18})})}),e(pe,{open:g,onClose:p,anchorRef:E,placement:"bottom-end",width:180,children:[t("span",{className:"block px-4 pt-3 pb-1 text-[0.68rem] tracking-[1px] uppercase text-gray-400 dark:text-white/40",children:z("Switch to")}),t("div",{className:"pb-1",children:xe.map(n=>e("button",{type:"button",onClick:()=>{f(n.mode),p()},className:"w-full flex items-center gap-3 px-4 py-1 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors "+(r===n.mode?"bg-[var(--chat-accent)]/10":""),children:[n.getIcon({size:18,className:"text-gray-400 dark:text-white/40"}),t("span",{className:"text-[0.8125rem] text-gray-700 dark:text-white/70",children:z(n.label)})]},n.mode))})]}),t(we,{title:z("Close"),children:t("button",{type:"button",onClick:x,className:"w-8 h-8 flex items-center justify-center rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-500 dark:text-white/40 hover:text-gray-700 dark:hover:text-white/70 transition-colors",children:t(H,{size:18})})})]})},ye=({inputValue:r,onInputChange:o,onSend:s,onStop:i,isLoading:l,canSteer:c=!1,attachedFiles:d=[],onFileAdd:h,onFileRemove:u,onPaste:g,t:m,mode:p,separatorColor:f})=>{const w=a(null),x=a(null),v=Boolean(h&&u&&g),y=r.trim()||v&&d.length>0,b=v&&d.some(e=>"pending"===e.uploadStatus),k=y&&!b,N=v&&d.length>0,C=l&&c&&Boolean(r.trim())&&!N,_=m(l&&c&&!N?"Enter to send now · Esc to stop":l&&N?"Attachments wait for the current response":"Uses AI. Verify results.");return e("div",{className:"px-4 py-3 border-t border-gray-200 dark:border-white/10 "+("floating"===p?"rounded-b-xl":""),style:f?{borderTopColor:f,borderTopWidth:1}:void 0,children:[v&&d.length>0&&t("div",{className:"flex gap-1.5 flex-wrap mb-2",children:d.map((n,r)=>e("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full border text-[0.7rem] "+("error"===n.uploadStatus?"border-red-300 dark:border-red-500/30 text-red-500 dark:text-red-400":"pending"===n.uploadStatus?"border-gray-200 dark:border-white/10 text-gray-400 dark:text-white/40":"border-gray-200 dark:border-white/10 text-gray-600 dark:text-white/60"),children:["pending"===n.uploadStatus?t("span",{className:"w-3.5 h-3.5 border border-current/30 border-t-current rounded-full animate-spin"}):t(Z,{size:14}),n.name,"error"===n.uploadStatus&&t("span",{className:"text-red-400 text-[0.6rem]",children:"✕"}),t("button",{type:"button",onClick:()=>u?.(r),className:"ml-0.5 text-gray-400 dark:text-white/30 hover:text-gray-600 dark:hover:text-white/60",children:"×"})]},r))}),e("div",{className:"flex items-center border border-gray-200 dark:border-white/10 rounded-xl px-2 py-1 transition-colors focus-within:border-[var(--chat-accent)]",children:[v&&e(n,{children:[t("input",{ref:w,type:"file",multiple:!0,hidden:!0,onChange:e=>{h?.(e.target.files),e.target.value=""}}),t("button",{type:"button",onClick:()=>w.current?.click(),className:"w-8 h-8 flex items-center justify-center shrink-0 rounded-lg text-gray-400 dark:text-white/30 hover:bg-gray-100 dark:hover:bg-white/10 mr-0.5 transition-colors",children:t(D,{size:18})})]}),t("textarea",{ref:x,placeholder:m("Ask a question..."),value:r,onChange:e=>{o(e.target.value);const t=e.target;t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,120)}px`},onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),s()),"Escape"===e.key&&l&&(e.preventDefault(),i())},onPaste:g,rows:1,className:"flex-1 bg-transparent border-none outline-hidden resize-none text-[0.8125rem] py-1.5 text-gray-900 dark:text-white placeholder:text-gray-400 dark:placeholder:text-white/30 filigran-chat-scrollable",style:{maxHeight:120}}),C&&t(we,{title:m("Send now"),children:t("button",{type:"button",onClick:s,"aria-label":m("Send now"),className:"p-1.5 rounded-lg w-8 h-8 flex items-center justify-center transition-all duration-150 text-[var(--chat-accent)] bg-[var(--chat-accent)]/10 hover:bg-[var(--chat-accent)]/20",children:t(se,{size:18})})}),t(we,{title:l?m("Stop generating"):b?m("Files uploading..."):"",children:t("button",{type:"button",onClick:l?i:s,disabled:!l&&!k,className:"p-1.5 rounded-lg w-8 h-8 flex items-center justify-center transition-all duration-150 "+(l?"text-red-500 bg-red-500/10 hover:bg-red-500/20 ml-0.5":k?"text-[var(--chat-accent)] bg-[var(--chat-accent)]/10 hover:bg-[var(--chat-accent)]/20":"text-gray-300 dark:text-white/20 cursor-not-allowed"),children:t(l?ce:se,{size:18})})})]}),t("p",{className:"text-center text-[0.65rem] text-gray-400 dark:text-white/30 mt-1.5 opacity-70",children:_})]})},be=["Crunching the data","Connecting the dots","Consulting the sources","Thinking it through","Reticulating splines","Analyzing the details","Almost there","Putting it together","Polishing the answer","Wrapping things up"],ke="filigranChatMiniGame",Ne=e=>`700 ${e}px 'Courier New', ui-monospace, monospace`,Ce=[["00100000100","00010001000","00111111100","01101110110","11111111111","10111111101","10100000101","00011011000"],["00100000100","10010001001","10111111101","11101110111","11111111111","00111111100","00100000100","01000000010"]];function _e(){if("undefined"==typeof window)return!0;try{return"off"!==window.localStorage.getItem(ke)}catch{return!0}}function Se(e,t,n){const r=e.getContext("2d");if(!r)return()=>{};const a=r;let o=0,s=0;let i=13,l="#7b5cff",c=0,d=[],h=-1,u=[],g=[],m=0,p=0,f=0,w=0,x=0,v=performance.now();const y=Math.round(29.4);function b(e){for(let t=e;t<d.length;t++)if(d[t].alive)return t;return-1}function k(){if(s<=0)return;const e=t[c%t.length]||"";for(n(c%t.length),i=13;i>=8&&(a.font=Ne(i),!(a.measureText(e).width<=s-16));i--);a.font=Ne(i);const r=Array.from(e).map(e=>a.measureText(e).width),o=r.reduce((e,t)=>e+t,0);let l=(s-o)/2;d=Array.from(e).map((e,t)=>{const n=l;return l+=r[t],{char:e,x:n,w:r[t],alive:e.trim().length>0}}),h=b(0),u=[],g=[],p=0,f=0,m<=0&&(m=s/2)}function N(e){return d[e].x+d[e].w/2}function C(){const t=e.getBoundingClientRect(),n=window.devicePixelRatio||1;s=t.width,e.width=Math.max(1,Math.round(s*n)),e.height=Math.round(70*n),a.setTransform(n,0,0,n,0,0),function(){const t=getComputedStyle(e).getPropertyValue("--chat-accent").trim();t&&(l=t)}(),k()}let _=null;return"undefined"!=typeof ResizeObserver?(_=new ResizeObserver(C),_.observe(e)):window.addEventListener("resize",C),C(),o=requestAnimationFrame(function e(t){const n=t-v;v=t,!document.hidden&&s>0&&(function(e){const t=Math.min(e/16.6667,3);if(x+=e,x>320&&(x=0,w^=1),-1===h)0===f?f=performance.now():performance.now()-f>650&&(c++,k());else{const n=N(h);m+=(n-m)*Math.min(.16*t,1),p-=e,0===u.length&&p<=0&&Math.abs(m-n)<4&&(u.push({x:m,y:50}),p=130)}for(let e=u.length-1;e>=0;e--)if(u[e].y-=2.6*t,u[e].y<=y){if(-1!==h){const e=N(h);d[h].alive=!1;for(let t=0;t<7;t++){const n=2*Math.PI*t/7+Math.random(),r=.6+1.4*Math.random();g.push({x:e,y:y,vx:Math.cos(n)*r,vy:Math.sin(n)*r,life:1})}h=b(h+1)}u.splice(e,1)}for(let e=g.length-1;e>=0;e--){const n=g[e];n.x+=n.vx*t,n.y+=n.vy*t,n.life-=.045*t,n.life<=0&&g.splice(e,1)}}(n),function(){a.clearRect(0,0,s,70),a.fillStyle=l,a.font=Ne(i),a.textBaseline="middle",a.globalAlpha=.85;for(const e of d)e.alive&&a.fillText(e.char,e.x,y);a.globalAlpha=1;for(const e of u)a.fillRect(e.x-1,e.y,2,7);for(const e of g)a.globalAlpha=.9*Math.max(e.life,0),a.fillRect(e.x-1.5,e.y-1.5,3,3);a.globalAlpha=1;const e=Ce[w],t=Math.round(m-11);for(let n=0;n<e.length;n++){const r=e[n];for(let e=0;e<r.length;e++)"1"===r[e]&&a.fillRect(t+2*e,50+2*n,2,2)}}()),o=requestAnimationFrame(e)}),()=>{cancelAnimationFrame(o),_?_.disconnect():window.removeEventListener("resize",C)}}const Le=({t:n,enabled:o=!0})=>{const l=i(()=>be.map(e=>n(e)),[n]),c=function(){const[e,t]=r(()=>!("undefined"==typeof window||!window.matchMedia)&&window.matchMedia("(prefers-reduced-motion: reduce)").matches);return s(()=>{if("undefined"==typeof window||!window.matchMedia)return;const e=window.matchMedia("(prefers-reduced-motion: reduce)"),n=()=>t(e.matches);return"function"==typeof e.addEventListener?(e.addEventListener("change",n),()=>e.removeEventListener("change",n)):(e.addListener(n),()=>e.removeListener(n))},[]),e}(),[d,h]=r(_e),[u,g]=r(0),m=a(null),p=o&&d&&!c;if(s(()=>{if(p||!o)return;const e=window.setInterval(()=>g(e=>(e+1)%l.length),2600);return()=>window.clearInterval(e)},[p,o,l.length]),s(()=>{if(!p)return;const e=m.current;return e?Se(e,l,g):void 0},[p,l]),!o)return null;const f=l[u%l.length];return e("div",{className:"ml-11 mt-2.5 max-w-[78%]",children:[t("span",{className:"sr-only",role:"status","aria-live":"polite",children:f}),e("div",{className:"relative overflow-hidden rounded-md bg-[var(--chat-accent)]/[0.03]",style:c?void 0:{animation:"chat-fade-in 0.5s ease-out"},children:[p?t("canvas",{ref:m,"aria-hidden":!0,className:"block w-full",style:{height:70}}):t("div",{className:"flex items-center",style:{height:70},children:e("span",{className:"px-3 text-xs text-gray-500 dark:text-white/45",style:c?void 0:{animation:"chat-fade-in 0.4s ease-out"},children:[f,t("span",{className:"ml-0.5 inline-block w-1 h-3 align-middle bg-[var(--chat-accent)]/60 "+(c?"":"animate-pulse")})]},f)}),!c&&t("button",{type:"button",onClick:()=>{const e=!d;h(e),function(e){try{window.localStorage.setItem(ke,e?"on":"off")}catch{}}(e)},"aria-pressed":d,"aria-label":n(d?"Turn off the waiting mini-game":"Turn on the waiting mini-game"),title:n(d?"Turn off the waiting mini-game":"Turn on the waiting mini-game"),className:"absolute top-1 right-1 rounded p-1 transition-opacity "+(d?"text-[var(--chat-accent)] opacity-50 hover:opacity-100":"text-gray-400 dark:text-white/40 opacity-40 hover:opacity-90"),children:t(ee,{size:13})})]})]})};function Ie(e){return e.replace(/```[\s\S]*?```/g," ").replace(/`([^`]+)`/g,"$1").replace(/\*\*(.+?)\*\*/g,"$1").replace(/__(.+?)__/g,"$1").replace(/#{1,6}\s+/g,"").replace(/^[ \t]*[-*>]+[ \t]*/gm,"").replace(/[ \t]+/g," ").replace(/\n{3,}/g,"\n\n").trim()}function Me({content:e}){const n=a(null),[o,i]=r(!1),l=Ie(e);return s(()=>{const e=n.current;e&&(e.scrollTop=e.scrollHeight,i(e.scrollHeight>e.clientHeight+1))},[l]),l.length<3?null:t("div",{className:"ml-11 mt-2.5 max-w-[75%] rounded-md border-l-2 bg-[var(--chat-accent)]/[0.03] py-2 pl-3 pr-3",style:{animation:"reasoningGlow 3s ease-in-out infinite, chat-fade-in 0.5s ease-out"},children:t("div",{ref:n,className:"max-h-40 overflow-hidden"+(o?" [-webkit-mask-image:linear-gradient(to_bottom,transparent_0,rgb(0_0_0/0.25)_1.5rem,rgb(0_0_0/0.7)_3rem,black_4.5rem)] [mask-image:linear-gradient(to_bottom,transparent_0,rgb(0_0_0/0.25)_1.5rem,rgb(0_0_0/0.7)_3rem,black_4.5rem)]":""),children:t("p",{className:"m-0 whitespace-pre-wrap break-words text-xs leading-5 text-gray-500 dark:text-white/45",children:l})})})}function ze(e){const t=Math.floor(e);if(t<60)return`${t}s`;const n=Math.floor(t/60),r=t%60;return r>0?`${n}m ${r}s`:`${n}m`}const Te=({agentStatus:o,logoIcon:i,t:l,miniGameEnabled:c=!0})=>{const{label:d,StatusIcon:h,showDots:u}=function(e,t){if(!e)return{label:t("Thinking..."),StatusIcon:B,showDots:!1};switch(e.status){case"tool_start":{const n=e.tools??[],r=n.map(e=>e.toLowerCase());if(r.some(e=>"spawn_background_task"===e)){const e=n.filter(e=>"spawn_background_task"===e).length;return{label:e>1?`${t("Delegating")} ${e} ${t("tasks")}…`:`${t("Delegating task")}…`,StatusIcon:ue,showDots:!1}}if(r.some(e=>"check_task_status"===e)){const e=n.filter(e=>"check_task_status"===e).length,r=e>1?`${e} ${t("background tasks")}`:t("background task");return{label:`${t("Waiting for")} ${r}…`,StatusIcon:le,showDots:!1}}if(r.some(e=>"get_task_result"===e)){const e=n.filter(e=>"get_task_result"===e).length,r=e>1?`${e} ${t("tasks")}`:t("task");return{label:`${t("Collecting results from")} ${r}…`,StatusIcon:le,showDots:!1}}let a,o=ge;if(r.some(e=>e.includes("search")||e.includes("list"))?o=oe:r.some(e=>e.includes("read")||e.includes("get")||e.includes("query"))?o=G:r.some(e=>e.includes("send")||e.includes("create")||e.includes("draft")||e.includes("reply")||e.includes("flag"))?o=ae:r.some(e=>e.includes("code")||e.includes("execute"))?o=de:r.some(e=>e.includes("web")||e.includes("browse"))&&(o=te),n.length>0){const e=n.map(e=>e.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase())),t=Array.from(new Set(e));a=1===t.length?`${t[0]}…`:`${t[0]} (+${t.length-1} more)…`}else a=t("Using tools…");return{label:a,StatusIcon:o,showDots:!1}}case"analyzing":return{label:t("Analyzing results…"),StatusIcon:le,showDots:!1};case"steering":return{label:t("Incorporating your message…"),StatusIcon:le,showDots:!0};case"composing":return{label:t("Composing answer…"),StatusIcon:B,showDots:!0};case"consulting":{const n=e.tools?.[0]??"agent";return{label:`${t("Consulting")} ${n}…`,StatusIcon:ue,showDots:!1}}case"delegating":{const n=e.tools?.filter(e=>"spawn_background_task"===e).length??0;return{label:n>1?`${t("Delegating")} ${n} ${t("tasks")}…`:`${t("Delegating task")}…`,StatusIcon:ue,showDots:!1}}case"polling":{const n=e.tools?.filter(e=>"check_task_status"===e).length??0,r=n>1?`${n} ${t("background tasks")}`:t("background task");return{label:`${t("Waiting for")} ${r}…`,StatusIcon:le,showDots:!1}}case"collecting":{const n=e.tools?.filter(e=>"get_task_result"===e).length??0,r=n>1?`${n} ${t("tasks")}`:t("task");return{label:`${t("Collecting results from")} ${r}…`,StatusIcon:le,showDots:!1}}case"transferring":{const n=e.tools?.[0]??"agent";return{label:`${t("Transferring to")} ${n}…`,StatusIcon:K,showDots:!1}}default:return{label:t("Thinking..."),StatusIcon:B,showDots:!1}}}(o,l),g=o?.thinkingContent,m=o?.elapsedS,p="number"==typeof m&&m>=15,f=function(e,t,n){const[o,i]=r(!1),l=a(e),c=l.current!==e;return s(()=>{if(l.current=e,i(!1),!n)return;const r=window.setTimeout(()=>i(!0),t);return()=>window.clearTimeout(r)},[e,t,n]),n&&o&&!c}(g?.length??0,5e3,c),w=c&&f;return e(n,{children:[e("div",{className:"flex gap-3 items-center justify-start",children:[t("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-gradient-to-br from-[var(--chat-accent)]/15 to-[var(--chat-accent)]/5",children:t("span",{className:"text-[var(--chat-accent)] [&>svg]:w-4 [&>svg]:h-4",children:i})}),e("div",{className:"rounded-lg bg-gray-50 dark:bg-white/[0.03] px-4 py-3 relative overflow-hidden",children:[t("div",{className:"absolute inset-0 bg-gradient-to-r from-[var(--chat-accent)]/[0.03] via-transparent to-[var(--chat-accent)]/[0.03] animate-pulse pointer-events-none"}),e("div",{className:"relative flex items-center gap-2.5",children:[u?t("div",{className:"flex gap-[3px] items-center h-3.5 w-3.5 justify-center",children:[0,.15,.3].map((e,n)=>t("span",{className:"h-[5px] w-[5px] rounded-full bg-[var(--chat-accent)]/50",style:{animation:`chat-dot 1s ease-in-out infinite ${e}s`}},n))}):t(h,{size:14,className:"text-[var(--chat-accent)] animate-pulse transition-all duration-300"}),t("span",{className:"text-sm text-gray-500 dark:text-white/50 transition-all duration-300",children:d}),p&&t("span",{className:"text-xs text-gray-400 dark:text-white/30 tabular-nums shrink-0",children:ze(m)})]})]})]}),g&&!w?t(Me,{content:g}):w?t(Le,{t:l,enabled:c}):null]})},Ee=e=>{if(!e)return!1;if(e.startsWith("//"))return!1;return!/^[a-zA-Z][a-zA-Z\d+.-]*:/.test(e)},$e=({content:n,onRelativeLinkClick:a})=>{const[o,s]=r(null);return t(c,{remarkPlugins:[d],components:{p:({children:e})=>t("p",{className:"mb-3 last:mb-0 leading-7 break-words text-[0.8125rem] text-gray-900 dark:text-white/90",children:e}),code:({className:n,children:r})=>{const a=/language-(\w+)/.exec(n||""),i=String(r).replace(/\n$/,"");return a?e("div",{className:"my-3 rounded-lg border border-gray-200 dark:border-white/10 overflow-hidden bg-gray-50 dark:bg-white/[0.03]",children:[e("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-gray-200 dark:border-white/10 bg-gray-100 dark:bg-white/[0.03]",children:[t("span",{className:"text-[0.7rem] text-gray-500 dark:text-white/40 font-mono",children:a[1]}),t("button",{type:"button",onClick:()=>{return e=i,navigator.clipboard.writeText(e),s(e),void setTimeout(()=>s(null),2e3);var e},className:"p-0.5 rounded-sm hover:bg-gray-200 dark:hover:bg-white/10 transition-colors",children:o===i?t(W,{size:14,className:"text-green-500"}):t(P,{size:14,className:"text-gray-400 dark:text-white/40"})})]}),t("pre",{className:"m-0 px-3 py-2 overflow-x-auto",children:t("code",{className:"font-mono text-xs leading-[1.7] text-gray-800 dark:text-white/90 whitespace-pre",children:i})})]}):t("code",{className:"bg-gray-100 dark:bg-white/[0.08] px-1.5 py-0.5 rounded-sm font-mono text-xs text-[var(--chat-accent)]",children:r})},ul:({children:e})=>t("ul",{className:"pl-5 mb-3 text-[0.8125rem] text-gray-900 dark:text-white/90 [&_li]:mb-1 marker:text-[var(--chat-accent)]/50",children:e}),ol:({children:e})=>t("ol",{className:"pl-5 mb-3 text-[0.8125rem] text-gray-900 dark:text-white/90 [&_li]:mb-1 marker:text-[var(--chat-accent)]/50",children:e}),blockquote:({children:e})=>t("blockquote",{className:"my-3 border-l-2 border-[var(--chat-accent)]/30 bg-[var(--chat-accent)]/[0.03] pl-4 pr-3 py-2 rounded-r-md italic text-gray-500 dark:text-white/60",children:e}),a:({href:e,children:n})=>{const r=(e=>{if(!e)return null;if(Ee(e))return e;if("undefined"==typeof window)return null;try{const t=new URL(e,window.location.href);if(("http:"===t.protocol||"https:"===t.protocol)&&t.origin===window.location.origin)return`${t.pathname}${t.search}${t.hash}`||"/"}catch{}return null})(e),o=null!==r&&!!a,s=!o&&!Ee(e);return t("a",{href:e,onClick:e=>{o&&(e.preventDefault(),a(r))},target:s?"_blank":void 0,rel:s?"noopener noreferrer":void 0,className:"text-[var(--chat-accent)] underline underline-offset-2 hover:brightness-125",children:n})},h1:({children:e})=>t("h1",{className:"mt-4 first:mt-0 mb-2 font-bold text-base text-gray-900 dark:text-white",children:e}),h2:({children:e})=>t("h2",{className:"mt-3 first:mt-0 mb-2 font-bold text-[0.9rem] text-gray-900 dark:text-white",children:e}),h3:({children:e})=>t("h3",{className:"mt-3 first:mt-0 mb-1.5 font-semibold text-[0.85rem] text-gray-900 dark:text-white",children:e}),table:({children:e})=>t("div",{className:"my-3 overflow-x-auto rounded-lg border border-gray-200 dark:border-white/10",children:t("table",{className:"w-full border-collapse text-xs",children:e})}),th:({children:e})=>t("th",{className:"px-3 py-2 text-left font-semibold bg-gray-50 dark:bg-white/[0.04] border-b border-gray-200 dark:border-white/10 text-gray-900 dark:text-white",children:e}),td:({children:e})=>t("td",{className:"px-3 py-2 border-b border-gray-200 dark:border-white/10 text-gray-700 dark:text-white/80",children:e})},children:u(n)})};function Ae(e){if(!e)return"";if(e.length>1e4)return e;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function Re(e){return e.replace(/_/g," ")}const je=({entry:n,index:a,t:o})=>{const[s,l]=r(!1),c=i(()=>Ae(n.input),[n.input]),d=i(()=>Ae(n.output),[n.output]),h=!!c&&"{}"!==c;return e("div",{className:"border border-gray-200 dark:border-white/[0.06] rounded-md overflow-hidden",children:[e("button",{type:"button",onClick:()=>l(e=>!e),"aria-expanded":s,className:"w-full flex items-center gap-2.5 px-3 py-2 hover:bg-gray-50 dark:hover:bg-white/[0.03] transition-colors text-left",children:[t("span",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded bg-[var(--chat-accent)]/10 text-[0.65rem] font-medium text-[var(--chat-accent)]",children:a+1}),n.success?t(O,{size:12,className:"shrink-0 text-emerald-500 dark:text-emerald-400"}):t(me,{size:12,className:"shrink-0 text-red-500 dark:text-red-400"}),t("span",{className:"flex-1 min-w-0 text-[0.8125rem] text-gray-700 dark:text-white/80 truncate font-mono",children:Re(n.name)}),t(F,{size:14,className:"shrink-0 text-gray-400 dark:text-white/50 transition-transform duration-200 "+(s?"rotate-180":"")})]}),s&&e("div",{className:"border-t border-gray-200 dark:border-white/[0.06]",children:[h&&e("div",{className:"px-3 py-2 border-b border-gray-100 dark:border-white/[0.04] bg-gray-50/50 dark:bg-white/[0.01]",children:[t("p",{className:"m-0 mb-1.5 text-[0.6rem] text-gray-500 dark:text-white/40 uppercase tracking-wider font-medium",children:o("Input")}),t("pre",{className:"m-0 text-[0.7rem] text-gray-600 dark:text-white/60 font-mono whitespace-pre-wrap break-all leading-relaxed max-h-40 overflow-y-auto filigran-chat-scrollable",children:c})]}),e("div",{className:"px-3 py-2 bg-gray-50/50 dark:bg-white/[0.01]",children:[t("p",{className:"m-0 mb-1.5 text-[0.6rem] text-gray-500 dark:text-white/40 uppercase tracking-wider font-medium",children:o("Output")}),t("pre",{className:"m-0 text-[0.7rem] text-gray-600 dark:text-white/60 font-mono whitespace-pre-wrap break-all leading-relaxed max-h-48 overflow-y-auto filigran-chat-scrollable",children:d||o("(no output)")})]})]})]})},De=({msg:n,onClose:o,t:i})=>{const c=a(null),d=a(null),h=a(null),[u,g]=r(null);s(()=>{g(m(c.current))},[]),s(()=>{const e=e=>{if("Escape"===e.key)return void o();if("Tab"!==e.key)return;const t=h.current;if(!t)return;const n=t.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(0===n.length)return;const r=n[0],a=n[n.length-1],s=document.activeElement;e.shiftKey?s!==r&&t.contains(s)||(e.preventDefault(),a.focus()):s!==a&&t.contains(s)||(e.preventDefault(),r.focus())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[o]),s(()=>{if(!u)return;const e=document.activeElement instanceof HTMLElement?document.activeElement:null;return d.current?.focus({preventScroll:!0}),()=>e?.focus({preventScroll:!0})},[u]);const p=n.toolCallCount??n.toolCallTrace?.length??n.toolNames?.length??0,f=n.toolNames??[],w=n.iterations??1,x=n.transferChain??[],v=n.toolCallTrace??[],y=(n.reasoning??"").trim(),b=[w>1?`${w} ${i("iterations")}`:"",`${p} ${i(1===p?"tool call":"tool calls")}`,x.length>0?`${x.length} ${1===x.length?i("transfer"):i("transfers")}`:""].filter(Boolean);return t("span",{ref:c,className:"hidden",children:u&&l(t("div",{className:"absolute inset-0 z-[10000] flex items-center justify-center bg-black/30 dark:bg-black/50 p-4",onClick:o,role:"presentation",children:e("div",{ref:h,role:"dialog","aria-modal":"true","aria-label":i("Reasoning details"),onClick:e=>e.stopPropagation(),className:"w-full max-w-md max-h-full flex flex-col rounded-xl border border-gray-200 dark:border-white/10 bg-white dark:bg-[#1e1e2e] shadow-[0_8px_32px_rgba(0,0,0,0.25)] dark:shadow-[0_8px_32px_rgba(0,0,0,0.6)]",children:[e("div",{className:"px-4 pt-3.5 pb-2.5 border-b border-gray-200 dark:border-white/10",children:[e("div",{className:"flex items-center gap-2",children:[t(ge,{size:15,className:"text-[var(--chat-accent)]"}),t("span",{className:"flex-1 text-[0.875rem] font-semibold text-gray-900 dark:text-white",children:i("Reasoning details")}),t("button",{ref:d,type:"button",onClick:o,"aria-label":i("Close"),className:"w-7 h-7 flex items-center justify-center rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-500 dark:text-white/40 hover:text-gray-700 dark:hover:text-white/70 transition-colors",children:t(H,{size:16})})]}),t("p",{className:"m-0 mt-0.5 text-[0.72rem] text-gray-500 dark:text-white/40",children:b.join(" · ")})]}),e("div",{className:"px-4 py-3 overflow-y-auto filigran-chat-scrollable flex flex-col gap-3",children:[n.isTruncated&&e("div",{className:"flex items-start gap-2.5 rounded-md border border-amber-500/20 bg-amber-500/5 px-3 py-2.5 text-[0.72rem] text-amber-600 dark:text-amber-300/90",children:[t(R,{size:14,className:"shrink-0 mt-0.5 text-amber-500 dark:text-amber-400"}),e("span",{children:[t("span",{className:"font-semibold",children:i("Turn limit reached.")})," ",i("The agent's iteration budget was exhausted - execution stopped before completing all planned steps. The final response is a best-effort summary of work done so far.")]})]}),y&&e("div",{children:[e("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t(B,{size:13,className:"text-[var(--chat-accent)]/70"}),t("span",{className:"text-[0.72rem] font-medium text-gray-500 dark:text-white/50",children:i("Model reasoning")})]}),t("div",{className:"rounded-md border border-gray-200 dark:border-white/[0.06] bg-gray-50/50 dark:bg-white/[0.01] px-2.5 py-2 max-h-44 overflow-y-auto filigran-chat-scrollable",children:t("p",{className:"m-0 whitespace-pre-wrap break-words text-[0.72rem] leading-5 text-gray-500 dark:text-white/45",children:Ie(y)})})]}),v.length>0?t("div",{className:"flex flex-col gap-1.5",children:v.map((e,n)=>t(je,{entry:e,index:n,t:i},`${e.name}-${n}`))}):f.length>0&&t("div",{children:f.map((n,r)=>e("div",{className:"flex items-center gap-3 py-2 border-b border-gray-100 dark:border-white/[0.04] last:border-0",children:[t("span",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded bg-[var(--chat-accent)]/10 text-[0.65rem] font-medium text-[var(--chat-accent)]",children:r+1}),t(ge,{size:12,className:"shrink-0 text-gray-400 dark:text-white/50"}),t("span",{className:"text-[0.8125rem] text-gray-700 dark:text-white/80 truncate font-mono",children:Re(n)})]},`${n}-${r}`))}),x.length>0&&e("div",{children:[e("div",{className:"flex items-center gap-1.5 mb-1.5",children:[t(j,{size:13,className:"text-[var(--chat-accent)]/70"}),t("span",{className:"text-[0.72rem] font-medium text-gray-500 dark:text-white/50",children:i("Transfer chain")})]}),t("div",{className:"flex items-center gap-1.5 flex-wrap",children:x.map((n,r)=>e("div",{className:"flex items-center gap-1.5",children:[r>0&&t("span",{className:"text-gray-300 dark:text-white/30 text-[0.72rem]",children:"→"}),e("span",{className:"inline-flex items-center gap-1 rounded-md bg-[var(--chat-accent)]/10 px-2 py-0.5 text-[0.72rem] font-medium text-[var(--chat-accent)]",children:[t(U,{size:12}),n.agentName]})]},`${n.agentId}-${r}`))})]})]})]})}),u)})};function Ue(e){const t=e.lastIndexOf(".");if(t<=0||t===e.length-1)return;const n=e.slice(t+1);return n.length<=8?n.toUpperCase():void 0}const Be=({messages:o,isLoading:i,agentStatus:l,agentName:c,logoIcon:d,onRelativeLinkClick:h,onDownloadFile:u,miniGameEnabled:g=!0,t:m})=>{const f=a(null),[w,x]=r(null);s(()=>{f.current?.scrollIntoView({behavior:"smooth"})},[o]);const v=l?.thinkingContent?.length??0;s(()=>{v&&f.current?.scrollIntoView({behavior:"instant"})},[v]);const y=(n,r)=>{const a="working_file"===n.fileTag,o=!(s=n.size)||s<=0?"":s<1024?`${s} B`:s<1048576?`${(s/1024).toFixed(0)} KB`:`${(s/1048576).toFixed(1)} MB`;var s;return e("button",{type:"button",onClick:()=>u?.(n),title:m("Download"),className:"group flex items-center gap-2 text-left rounded-lg border px-2.5 py-1.5 transition-colors cursor-pointer max-w-[90%] "+(a?"border-gray-200 dark:border-white/10 bg-transparent":"border-gray-200 dark:border-white/10 bg-gray-50 dark:bg-white/[0.04] hover:border-[var(--chat-accent)] hover:bg-[var(--chat-accent)]/5"),children:[t("span",{className:"shrink-0 "+(a?"text-gray-400 dark:text-white/40":"text-[var(--chat-accent)]"),children:t(Z,{size:16})}),e("span",{className:"flex flex-col min-w-0 flex-1",children:[t("span",{className:"truncate text-[0.75rem] text-gray-900 dark:text-white",children:n.filename}),(n.type||o)&&t("span",{className:"text-[0.65rem] text-gray-400 dark:text-white/40 uppercase",children:[n.type,o].filter(Boolean).join(" · ")})]}),t("span",{className:"shrink-0 text-gray-400 dark:text-white/30 group-hover:text-[var(--chat-accent)]",children:t(q,{size:15})})]},r)},b=(e,n)=>{const r=function(e){if(!e)return[];const t=[],n=/\[\[FILE:([^\]]+)\]\]/g;let r=0,a=n.exec(e);for(;null!==a;)a.index>r&&t.push({type:"text",value:e.slice(r,a.index)}),t.push({type:"file",fileId:a[1]}),r=n.lastIndex,a=n.exec(e);const o=e.slice(r).replace(p,"");return o&&t.push({type:"text",value:o}),t}(e.content),a=new Map((e.attachments??[]).map(e=>[e.fileId,e])),o=new Set,s=[];return r.forEach((e,n)=>{if("text"===e.type)e.value.trim()&&s.push(t("div",{className:"max-w-[90%] pl-1 py-1 text-[0.8125rem] leading-7",children:t($e,{content:e.value,onRelativeLinkClick:h})},`t-${n}`));else if(u){const t=a.get(e.fileId);t&&(o.add(e.fileId),s.push(y(t,`f-${e.fileId}-${n}`)))}}),u&&(e.attachments??[]).forEach(e=>{o.has(e.fileId)||s.push(y(e,`orphan-${e.fileId}`))}),0!==s.length||n||s.push(t("span",{className:"pl-1 text-[0.8125rem] text-gray-400 dark:text-white/40 italic",children:"..."},"empty")),s},k=(n,r)=>e("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full border border-gray-200 dark:border-white/10 text-[0.7rem] text-gray-600 dark:text-white/60",children:[t(Z,{size:14}),n]},r),N=e=>{const t=[],n=new Set;return(e.files??[]).forEach((e,r)=>{!(!u||!e.fileId||"done"!==e.uploadStatus)&&e.fileId?(n.add(e.fileId),t.push(y({fileId:e.fileId,filename:e.name,type:Ue(e.name),size:e.size,contentType:e.type},`file-${e.fileId}-${r}`))):t.push(k(e.name,`file-${r}`))}),(e.attachments??[]).forEach((e,r)=>{n.has(e.fileId)||(n.add(e.fileId),t.push(u?y(e,`att-${e.fileId}-${r}`):k(e.filename,`att-${r}`)))}),t};let C=-1;for(let e=o.length-1;e>=0;e--)if("assistant"===o[e].role){C=e;break}return e("div",{className:"flex-1 overflow-y-auto px-4 py-3 flex flex-col gap-4 filigran-chat-scrollable",children:[o.map((r,a)=>{const o="assistant"===r.role,s=!r.content,h=i&&a===C;return o&&s&&h?t("div",{children:t(Te,{agentStatus:l,logoIcon:d,t:m,miniGameEnabled:g})},r.id):e("div",{className:"flex flex-col "+(o?"items-start":"items-end"),children:[o&&e("div",{className:"flex items-center gap-1.5 mb-1",children:[t("div",{className:"w-6 h-6 rounded-lg flex items-center justify-center bg-gradient-to-br from-[var(--chat-accent)]/20 to-[var(--chat-accent)]/5",children:t("span",{className:"text-[var(--chat-accent)] [&>svg]:w-3 [&>svg]:h-3",children:d})}),t("span",{className:"font-semibold text-xs text-gray-900 dark:text-white",children:c})]}),!o&&((r.files?.length??0)>0||(r.attachments?.length??0)>0)&&t("div",{className:"flex gap-1.5 flex-wrap mb-1.5 justify-end",children:N(r)}),o?e("div",{className:"flex flex-col gap-1.5 w-full items-start",children:[b(r,h),!s&&h&&t("span",{className:"inline-block w-1.5 h-4 bg-[var(--chat-accent)]/70 rounded-xs ml-1 animate-pulse"})]}):t("div",{className:"max-w-[90%] px-3.5 py-2 rounded-[14px_14px_4px_14px] bg-[var(--chat-accent-dark)] text-white text-[0.8125rem] leading-6",children:r.content}),o&&!s&&!h&&(r.toolNames&&r.toolNames.length>0||(r.reasoning??"").trim()||r.toolCallTrace&&r.toolCallTrace.length>0||r.transferChain&&r.transferChain.length>0||r.isTruncated)&&e(n,{children:[t("button",{type:"button",onClick:()=>x(w===r.id?null:r.id),className:"mt-0.5 p-1 rounded-lg transition-opacity "+(r.isTruncated?"opacity-100 text-amber-500 dark:text-amber-400 hover:text-amber-600 dark:hover:text-amber-300":"opacity-50 hover:opacity-100 hover:text-[var(--chat-accent)]"),title:r.isTruncated?m("Reasoning details — turn limit reached"):m("Reasoning details"),"aria-label":r.isTruncated?m("Reasoning details — turn limit reached"):m("Reasoning details"),"aria-haspopup":"dialog","aria-expanded":w===r.id,children:r.isTruncated?t(R,{size:14}):t(re,{size:14})}),w===r.id&&t(De,{msg:r,onClose:()=>x(null),t:m})]})]},r.id)}),t("div",{ref:f})]})},Oe=({firstName:n,logoIcon:r,promptSuggestions:a,onPromptClick:o,t:s})=>e("div",{className:"flex-1 flex flex-col items-center justify-center px-6 pb-8",children:[t("span",{className:"text-[var(--chat-accent)] mb-4 [&>svg]:w-12 [&>svg]:h-12 drop-shadow-[0_0_12px_var(--chat-accent-40)]",children:r}),e("h2",{className:"text-xl font-medium mb-6 text-center text-gray-900 dark:text-white",style:{fontFamily:'"Geologica", sans-serif'},children:[s("How can I help you, "),n,"?"]}),e("div",{className:"w-full max-w-[320px]",children:[t("span",{className:"block text-center mb-2 text-[0.65rem] tracking-[1.5px] uppercase text-[var(--chat-accent)] font-semibold",children:s("Suggestions")}),a.map(e=>t("button",{type:"button",onClick:()=>o(e),className:"w-full text-left text-[0.8125rem] text-gray-800 dark:text-white py-1.5 px-3 mb-1 rounded-lg border border-gray-200 dark:border-white/10 bg-transparent transition-colors hover:bg-[var(--chat-accent-10)] hover:border-[var(--chat-accent-50)]",children:s(e)},e))]})]}),We=["Help me create a new simulation scenario","What are the latest attack patterns?","How do I configure detection rules?","Summarize my recent findings"],Fe=({mode:n,onClose:i,onModeChange:l,topOffset:c=0,apiBaseUrl:d,apiEndpoints:u,agentDashboardUrl:m,user:p,t:v=g,accentColor:y="#7b5cff",logoIcon:b,promptSuggestions:k=We,draftBorderColor:N,resizable:C=!1,onWidthChange:z,onResizeStart:T,onResizeEnd:E,disableFileManagement:$=!1,onRelativeLinkClick:R,onDownloadError:j,maxFileCount:D,maxTotalSize:U,requestHeaders:B,pageContext:O,pushContentSelector:W,backendType:F="rest",miniGameEnabled:H=!0,notifyOnComplete:P=!0,onTaskComplete:G})=>{const[q,J]=r(!1),{agents:K,selectedAgent:Z,agentMenuOpen:X,setAgentMenuOpen:Q,handleSwitchAgent:Y}=function({apiBaseUrl:e,apiEndpoints:t,backendType:n="rest",requestHeaders:a}){const[o,i]=r([]),[l,c]=r(null),[d,h]=r(!1);return s(()=>{null===t?.agents||t?.singleEndpoint||"legacy"===n||fetch(`${e}${t?.agents??"/chat/agents"}`,{headers:a}).then(e=>e.ok?e.json():[]).then(e=>{if(i(e),e.length>0&&!l){const t=localStorage.getItem(S),n=t?e.find(e=>e.slug===t):null;c(n||e[0])}}).catch(()=>{})},[e,t,n,a]),{agents:o,selectedAgent:l,setSelectedAgent:c,agentMenuOpen:d,setAgentMenuOpen:h,handleSwitchAgent:(e,t)=>{e.id!==l?.id?(c(e),e.slug&&localStorage.setItem(S,e.slug),h(!1),t?.()):h(!1)}}}({apiBaseUrl:d,apiEndpoints:u,backendType:F,requestHeaders:B}),{messages:ee,inputValue:te,setInputValue:ne,isLoading:re,agentStatus:ae,attachedFiles:oe,conversationId:se,transferredAgent:ie,canSteer:le,historyLoadedRef:ce,conversationIdRef:de,handleFileAdd:he,handlePaste:ue,handleSendMessage:ge,handleNewChat:me,handleStopGenerating:pe,setAttachedFiles:fe,setMessages:we,updateConversationId:xe,handleSwitchConversation:be}=_({apiBaseUrl:d,apiEndpoints:u,backendType:F,agentSlug:Z?.slug,requestHeaders:B,pageContext:O,t:v,maxFileCount:D,maxTotalSize:U}),{historyEnabled:ke,conversations:Ne,conversationsLoading:Ce,refreshConversations:_e,deleteConversation:Se}=function({apiBaseUrl:e,apiEndpoints:t,backendType:n="rest",requestHeaders:a}){const[s,i]=r([]),[l,c]=r(!1),d="rest"===n&&!t?.singleEndpoint&&null!==t?.sessions&&null!==t?.history,h=`${e}${t?.history??t?.sessions??"/chat/sessions"}`,u=o(async()=>{if(d){c(!0);try{const e=await fetch(h,{method:"GET",headers:{...a??{}}});if(!e.ok)return void i([]);const t=await e.json(),n=Array.isArray(t)?t:Array.isArray(t?.conversations)?t.conversations:[];i(n.map(L).filter(e=>null!==e))}catch{i([])}finally{c(!1)}}},[d,h,a]),g=o(async e=>{if(!d)return!1;try{return!!(await fetch(`${h}/${encodeURIComponent(e)}`,{method:"DELETE",headers:{...a??{}}})).ok&&(i(t=>t.filter(t=>t.conversationId!==e)),!0)}catch{return!1}},[d,h,a]);return{historyEnabled:d,conversations:s,conversationsLoading:l,refreshConversations:u,deleteConversation:g}}({apiBaseUrl:d,apiEndpoints:u,backendType:F,requestHeaders:B}),[Le,Ie]=r(!1),{sidebarWidth:Me,handleResizeStart:ze,defaultWidth:Te,isResizing:Ee}=function({mode:e,resizable:t,onWidthChange:n,onResizeStart:o,onResizeEnd:i}){const[l,c]=r(()=>{if("undefined"==typeof window)return I;const e=localStorage.getItem(M);if(e){const t=parseInt(e,10);if(!Number.isNaN(t)&&t>=I)return t}return I}),[d,h]=r(!1),u=a(!1),g=a(l);g.current=l;const m=a(n);m.current=n;const p=a(i);return p.current=i,s(()=>{"sidebar"===e&&t&&m.current?.(g.current)},[e,t]),s(()=>{if("sidebar"!==e||!t)return;const n=e=>{if(!u.current)return;e.preventDefault();const t=window.innerWidth-e.clientX,n=.4*window.innerWidth,r=Math.min(Math.max(t,I),n);c(r),g.current=r,m.current?.(r)},r=()=>{u.current&&(u.current=!1,h(!1),document.body.style.cursor="",document.body.style.userSelect="",localStorage.setItem(M,String(g.current)),p.current?.())},a=()=>{const e=.4*window.innerWidth;if(g.current>e){const t=Math.max(e,I);c(t),g.current=t,m.current?.(t)}};return document.addEventListener("mousemove",n),document.addEventListener("mouseup",r),window.addEventListener("resize",a),()=>{document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",r),window.removeEventListener("resize",a)}},[e,t]),{sidebarWidth:l,handleResizeStart:e=>{e.preventDefault(),u.current=!0,h(!0),document.body.style.cursor="col-resize",document.body.style.userSelect="none",o?.()},defaultWidth:I,isResizing:d}}({mode:n,resizable:C,onWidthChange:z,onResizeStart:T,onResizeEnd:E});s(()=>{const e="sidebar"===n?C?Me:Te:0,t=e>0?e+6:0;if(document.documentElement.style.setProperty("--chatbot-sidebar-width",`${t}px`),document.documentElement.style.setProperty("--chatbot-transition",Ee?"none":"all 225ms cubic-bezier(0.4, 0, 0.2, 1)"),W){const e=document.querySelector(W);if(e){const n=e.style.paddingRight,r=e.style.transition;return e.style.paddingRight=t>0?`${t}px`:"",e.style.transition=Ee?"none":"padding-right 225ms cubic-bezier(0.4, 0, 0.2, 1)",()=>{e.style.paddingRight=n,e.style.transition=r,document.documentElement.style.setProperty("--chatbot-sidebar-width","0px")}}}return()=>{document.documentElement.style.setProperty("--chatbot-sidebar-width","0px")}},[W,n,Me,Te,C,Ee]);const $e=b??t(V,{size:24}),Ae=p.firstName,Re=ie?.name||Z?.name||"Assistant";A({isLoading:re,agentName:Re,t:v,enabled:P,onComplete:G,isViewingChat:o(()=>"undefined"!=typeof document&&!!document.activeElement?.closest(".filigran-chatbot.fixed"),[])});const je=null!=u?.download,De="rest"===F&&null!==u?.download&&(!u?.singleEndpoint||je),Ue=o(async e=>{const t=`${d}${u?.download??"/chat/files"}/${encodeURIComponent(e.fileId)}/download`;try{const n=await fetch(t,{method:"GET",credentials:"include",headers:{...B??{}}});if(!n.ok)throw new Error(`Download failed: ${n.status}`);const r=await n.blob(),a=URL.createObjectURL(r),o=document.createElement("a");o.href=a,o.download=e.filename||"download",document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(a)}catch(t){j?.(t,e)}},[d,u,B,j]),Fe={"--chat-accent":y,"--chat-accent-10":h(y,.1),"--chat-accent-40":h(y,.25),"--chat-accent-50":h(y,.5),"--chat-accent-dark":y},He=a(!0);s(()=>(He.current=!0,()=>{He.current=!1}),[]),s(()=>{if(null===u?.sessions||u?.singleEndpoint||"legacy"===F||"ag-ui"===F)return;if(!se||ce.current||!Z)return;ce.current=!0;const e=se,t=()=>!He.current||de.current!==e;fetch(`${d}${u?.sessions??"/chat/sessions"}`,{method:"POST",headers:{"Content-Type":"application/json",...B??{}},body:JSON.stringify({conversation_id:se,agent_slug:Z.slug})}).then(e=>t()?null:e.ok?e.json():(xe(null),null)).then(n=>{if(!n||t())return;if("string"==typeof n.conversation_id&&n.conversation_id&&n.conversation_id!==e&&xe(n.conversation_id),!n.messages?.length)return;const r=n.messages.map((e,t)=>({id:`restored-${t}`,role:e.role,content:e.content,timestamp:new Date,attachments:f(e.attachments),toolNames:Array.isArray(e.tool_names)?e.tool_names:void 0,toolCallCount:"number"==typeof e.tool_call_count?e.tool_call_count:void 0,iterations:"number"==typeof e.iterations?e.iterations:void 0,reasoning:"string"==typeof e.reasoning?e.reasoning:void 0,toolCallTrace:w(e.tool_call_trace),transferChain:x(e.transfer_chain),isTruncated:!0===e.is_truncated||void 0}));we(r)}).catch(()=>{t()||xe(null)})},[se,Z,d,u,F,ce,de,He,B,we,xe]);const Pe=(()=>{const e="filigran-chatbot";switch(n){case"sidebar":return`${e} fixed right-0 bottom-0 flex flex-col bg-white dark:bg-[#1e1e2e] border-l border-gray-200 dark:border-white/10 z-[1200]`;case"floating":return`${e} fixed bottom-5 right-5 flex flex-col bg-white dark:bg-[#1e1e2e] rounded-xl shadow-[0_8px_32px_rgba(0,0,0,0.15)] dark:shadow-[0_8px_32px_rgba(0,0,0,0.4)] z-[1300] border border-gray-200 dark:border-white/10`;case"fullscreen":return`${e} fixed right-0 bottom-0 left-0 flex flex-col bg-gray-50 dark:bg-[#161622] z-[1400]`;default:return e}})(),Ge={...Fe,..."sidebar"===n?{top:c,width:C?Me:Te}:"floating"===n?{width:380,height:560}:{top:c}};return e("div",{className:Pe,style:Ge,children:["sidebar"===n&&C&&t("div",{onMouseDown:ze,className:"absolute top-0 -left-1 bottom-0 w-2 cursor-col-resize z-10 group",children:t("div",{className:"absolute top-0 left-1/2 -translate-x-1/2 bottom-0 w-0.5 rounded-sm bg-[var(--chat-accent)] opacity-0 transition-opacity group-hover:opacity-100 group-active:opacity-100"})}),t(ve,{mode:n,agentName:Re,agents:K,selectedAgent:Z,transferredFrom:ie?Z?.name:void 0,agentMenuOpen:X,onAgentMenuToggle:()=>Q(e=>!e),onAgentMenuClose:()=>Q(!1),onSwitchAgent:e=>{e&&Y(e,()=>{me()})},modeMenuOpen:q,onModeMenuToggle:()=>J(e=>!e),onModeMenuClose:()=>J(!1),onModeChange:l,onNewChat:me,onClose:i,logoIcon:$e,agentDashboardUrl:m,historyEnabled:ke,historyMenuOpen:Le,onHistoryMenuToggle:()=>{const e=!Le;e&&_e(),Ie(e)},onHistoryMenuClose:()=>Ie(!1),conversations:Ne,conversationsLoading:Ce,activeConversationId:se,onSelectConversation:e=>{Ie(!1),be(e)},onDeleteConversation:e=>{(async e=>{await Se(e)&&e===de.current&&me()})(e)},t:v}),0===ee.length?t(Oe,{firstName:Ae,logoIcon:$e,promptSuggestions:k,onPromptClick:ne,t:v}):t(Be,{messages:ee,isLoading:re,agentStatus:ae,agentName:Re,logoIcon:$e,onRelativeLinkClick:R,onDownloadFile:De?Ue:void 0,miniGameEnabled:H,t:v}),t(ye,{inputValue:te,onInputChange:ne,onSend:ge,onStop:pe,isLoading:re,canSteer:le,attachedFiles:$?[]:oe,onFileAdd:$?void 0:he,onFileRemove:$?void 0:e=>fe(t=>t.filter((t,n)=>n!==e)),onPaste:$?void 0:ue,t:v,mode:n,separatorColor:N})]})},He=({isOpen:n,onToggle:r,label:a="Ask Assistant",accentColor:o="#7b5cff",icon:s})=>{const i=s??t(V,{size:16});return e("button",{type:"button",onClick:r,className:"filigran-chatbot inline-flex items-center gap-1.5 px-3 py-[3px] text-[0.8125rem] font-medium whitespace-nowrap rounded-md border transition-colors",style:{borderColor:n?o:h(o,.5),color:o,backgroundColor:n?h(o,.1):"transparent"},onMouseEnter:e=>{e.currentTarget.style.borderColor=o,e.currentTarget.style.backgroundColor=h(o,.1)},onMouseLeave:e=>{e.currentTarget.style.borderColor=n?o:h(o,.5),e.currentTarget.style.backgroundColor=n?h(o,.1):"transparent"},children:[t("span",{className:"[&>svg]:w-4 [&>svg]:h-4",children:i}),a]})};export{Fe as ChatPanel,He as ChatToggleButton};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|