nothumanallowed 14.1.6 → 14.1.7

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.
@@ -14,7 +14,7 @@ Error generating stack: `+e.message+`
14
14
  `).trim()}var he={browser_open:`Opening page`,browser_screenshot:`Taking screenshot`,browser_click:`Clicking element`,browser_type:`Typing text`,browser_extract:`Extracting content`,browser_js:`Running JavaScript`,browser_wait:`Waiting for element`,browser_scroll:`Scrolling page`,browser_key:`Pressing key`,browser_close:`Closing browser`,web_search:`Searching the web`,fetch_url:`Fetching URL`,gmail_list:`Searching emails`,gmail_read:`Reading email`,gmail_send:`Sending email`,calendar_today:`Loading calendar`,calendar_create:`Creating event`};function ge(){let e=P(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(()=>localStorage.getItem(`nha_conv_sidebar`)!==`hidden`),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(!1),p=(0,_.useRef)(null),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(null),y=(0,_.useRef)(null),b=(0,_.useRef)(null),[x,S]=(0,_.useState)(!1),[C,w]=(0,_.useState)(!1),ee=(0,_.useRef)(null),[te,T]=(0,_.useState)(null),[ie,O]=(0,_.useState)(!1),[ae,A]=(0,_.useState)(null),[j,oe]=(0,_.useState)(``),[se,M]=(0,_.useState)([]),[ce,N]=(0,_.useState)(!1),[F,le]=(0,_.useState)(!1),ue=(0,_.useRef)(null),de=(0,_.useRef)(null),ge=(0,_.useRef)(null);(0,_.useEffect)(()=>{ue.current?.scrollIntoView({behavior:`smooth`})},[a]),(0,_.useEffect)(()=>{E(`/api/config`).then(e=>{e&&(e.thinking===!0||e.thinking===`on`||e.thinking===`true`)&&S(!0)}),L().then(e=>{e&&e.length>0?_e(e[0].id):ve()});try{let e=sessionStorage.getItem(`nha_chat_prefill`)??sessionStorage.getItem(`nha_studio_import`);e&&(u(e),sessionStorage.removeItem(`nha_chat_prefill`),sessionStorage.removeItem(`nha_studio_import`),setTimeout(()=>de.current?.focus(),100))}catch{}},[]);let L=(0,_.useCallback)(async()=>{let e=(await E(`/api/conversations`))?.conversations??[];return n(e),e},[]),_e=(0,_.useCallback)(async e=>{let t=await E(`/api/conversations/${e}`);t?.conversation&&(i(t.conversation.id),o(t.conversation.messages??[]))},[]),ve=(0,_.useCallback)(async()=>{let e=await D(`/api/conversations`,{});e?.conversation&&(i(e.conversation.id),o([]),L())},[L]),ye=(0,_.useCallback)(async e=>{let t=ne.getState().apiBase;await fetch(`${t}/api/conversations/${e}`,{method:`DELETE`}),L().then(t=>{e===r&&(t.length>0?_e(t[0].id):ve())})},[r,L,_e,ve]),R=()=>{r&&window.open(`/api/conversations/${r}/export?format=md`,`_blank`)},z=()=>{let e=!x;S(e),D(`/api/config`,{key:`thinking`,value:e?`on`:`off`}).catch(()=>{})},be=()=>{c(e=>{let t=!e;return localStorage.setItem(`nha_conv_sidebar`,t?`visible`:`hidden`),t})},xe=e=>{let t=e.target.files?.[0];if(!t)return;let n=t.name.toLowerCase().endsWith(`.pdf`)||t.type===`application/pdf`,r=new FileReader;n?(r.onload=e=>{let n=(e.target?.result).split(`,`)[1];h({name:t.name,size:t.size,base64:n,mimeType:`application/pdf`,isPDF:!0}),v(null)},r.readAsDataURL(t)):(r.onload=e=>{h({name:t.name,size:t.size,content:e.target?.result}),v(null)},r.readAsText(t))},Se=e=>{let t=e.target.files?.[0];if(!t)return;let n=new FileReader;n.onload=e=>{let n=(e.target?.result).split(`,`)[1];v({name:t.name,size:t.size,base64:n,mimeType:t.type||`image/jpeg`}),h(null)},n.readAsDataURL(t)},Ce=()=>{h(null),v(null),y.current&&(y.current.value=``),b.current&&(b.current.value=``)},we=m?`[file] ${m.name} (${Math.round(m.size/1024)}KB)`:g?`[img] ${g.name} (${Math.round(g.size/1024)}KB)`:null,Te=()=>{let e=window.SpeechRecognition??window.webkitSpeechRecognition;if(!e){alert(`Speech recognition not supported in this browser.`);return}if(C&&ee.current){ee.current.stop(),w(!1);return}let t=new e;ee.current=t,t.lang=`it-IT`,t.continuous=!1,t.interimResults=!1,t.onresult=e=>{let t=e.results[0][0].transcript;u(e=>e?e+` `+t:t)},t.onend=()=>w(!1),t.onerror=()=>w(!1),t.start(),w(!0)},Ee=(0,_.useCallback)(async()=>{let t=l.trim(),n=!!(m||g);if(!t&&!n||d)return;let i={role:`user`,content:m?(t?t+` `:``)+`[File: ${m.name}]`:g?(t?t+` `:``)+`[Image: ${g.name}]`:t};if(o(e=>[...e,i]),u(``),n){let n={message:t||`Analyze this attachment`,history:a.map(e=>({role:e.role,content:e.content}))};m?.isPDF&&m.base64?(n.pdfBase64=m.base64,n.pdfName=m.name):m?.content&&(n.fileContent=m.content,n.fileName=m.name),g?.base64&&(n.imageBase64=g.base64,n.imageMimeType=g.mimeType),Ce(),o(t=>[...t,{role:`assistant`,content:e(`chat.thinking`),streaming:!0}]),f(!0);try{let e=await D(`/api/chat`,n);o(t=>{let n=[...t],r=n[n.length-1];return r?.role===`assistant`&&(n[n.length-1]={...r,content:e?.response??(e?.error?`Error: `+e.error:`Error`),streaming:!1}),n}),L()}catch(e){o(t=>{let n=[...t],r=n[n.length-1];return r?.role===`assistant`&&(n[n.length-1]={...r,content:`Error: `+e.message,streaming:!1}),n})}finally{f(!1)}return}Ce(),f(!0),M([]),N(!1),le(!0);let s=new AbortController;p.current=s,o(e=>[...e,{role:`assistant`,content:``,streaming:!0}]);let c=a.map(e=>({role:e.role,content:e.content})),h;if(c.length>10){let e=c.slice(0,c.length-10);h=[{role:`user`,content:e.reduce((t,n,r)=>n.role===`user`?t+`\nUser: ${n.content.slice(0,120)}`:r>0&&e[r-1]?.role===`user`?t+` → ${n.content.slice(0,150)}`:t,`[Earlier conversation summary]:`)},{role:`assistant`,content:`Understood, I have context from our earlier conversation.`},...c.slice(-10)]}else h=c;try{let e=``,n=!1,i=[];await re(`/api/chat/stream`,{message:t,history:h,conversationId:r},t=>{if(t.type===`processing`&&le(!0),t.type===`token`&&typeof t.data.content==`string`){le(!1),n&&e===``&&o(e=>{let t=[...e],n=t[t.length-1];return n?.role===`assistant`&&(t[t.length-1]={...n,content:``}),t}),e+=t.data.content;let r=e,i=r.includes(`<think>`)&&!r.includes(`</think>`);if(N(i),i)return;r=me(r.replace(/<think>[\s\S]*?<\/think>/g,``)),o(e=>{let t=[...e],n=t[t.length-1];return n?.role===`assistant`&&(t[t.length-1]={...n,content:r}),t})}if(t.type===`tool`){let n=t.data.action,r=t.data.status,i=he[n]??n,a=r===`executing`?`active`:r===`error`?`error`:`done`;M(e=>{let t=e.findIndex(e=>e.action===n&&e.status===`active`);if(t>=0){let r=[...e];return r[t]={action:n,label:i,status:a},r}return[...e,{action:n,label:i,status:a}]}),r===`executing`&&(e=me(e))}if(t.type===`tool_synthesis`&&(e=``,n=!0,N(!1),le(!0)),t.type===`screenshot`&&typeof t.data.url==`string`&&i.push(t.data.url),t.type===`canvas`&&typeof t.data.markers==`string`){let e=t.data.markers.match(/\[CANVAS_RENDER\]([\s\S]*?)\[\/CANVAS_RENDER\]/);if(e)try{T(JSON.parse(e[1]).html),O(!0)}catch{}}if(t.type===`done`){N(!1),le(!1),M(e=>e.map(e=>e.status===`active`?{...e,status:`done`}:e));let n=t.data.content,r=!!t.data.__sentinel_blocked,a=(n??e).replace(/<think>[\s\S]*?<\/think>/g,``),s=a.match(/\[CANVAS_RENDER\]([\s\S]*?)\[\/CANVAS_RENDER\]/);if(s)try{T(JSON.parse(s[1]).html),O(!0)}catch{T(s[1]),O(!0)}if(!s){let e=a.match(/```html\n([\s\S]*?)```/);e&&e[1].includes(`<`)&&(T(e[1]),O(!0))}let c=i.length>0?`
15
15
 
16
16
  `+i.map(e=>`![Screenshot](${e})`).join(`
17
- `):``,l=me(a.replace(/\[CANVAS_RENDER\][\s\S]*?\[\/CANVAS_RENDER\]/g,``).replace(/```html[\s\S]*?```/g,`[Canvas HTML — click Panel to view]`))+c;o(r?e=>{let t=[...e],n=t.findIndex((e,n)=>n===t.length-1&&e.role===`assistant`);return n>=0&&(t[n]={role:`assistant`,content:l||`Message blocked by SENTINEL.`,sentinelBlocked:!0,streaming:!1}),t}:e=>{let t=[...e],n=t[t.length-1];return n?.role===`assistant`&&(t[t.length-1]={...n,content:l,streaming:!1}),t}),L()}t.type===`error`&&o(e=>{let n=[...e],r=n[n.length-1];return r?.role===`assistant`&&(n[n.length-1]={...r,content:`Error: `+(t.data.message??`Unknown`),streaming:!1}),n})},s.signal)}catch(e){e.name!==`AbortError`&&o(e=>{let t=[...e],n=t[t.length-1];return n?.role===`assistant`&&(t[t.length-1]={...n,content:n.content||`Error connecting to server.`,streaming:!1}),t})}finally{N(!1),le(!1),o(e=>{let t=[...e],n=t[t.length-1];return n?.role===`assistant`&&n.streaming&&(t[t.length-1]={...n,streaming:!1}),t}),f(!1),p.current=null,setTimeout(()=>M([]),2e3)}},[l,a,d,m,g,r,L]),De=()=>{p.current?.abort(),f(!1)},Oe=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Ee())},B=e=>{navigator.clipboard.writeText(e.replace(/\[CANVAS_RENDER\][\s\S]*?\[\/CANVAS_RENDER\]/g,``).trim()).catch(()=>{})},ke=(0,_.useCallback)(async t=>{if(d)return;let n=t-1;if(n<0||a[n]?.role!==`user`)return;let i=a[n],s=a.slice(0,n).map(e=>({role:e.role,content:e.content}));o(e=>{let n=[...e];return n[t]={role:`assistant`,content:``,streaming:!0},n.slice(0,t+1)}),f(!0);let c=new AbortController;p.current=c;let l=``;try{await re(`/api/chat/stream`,{message:i.content,history:s,conversationId:r},t=>{if(t.type===`token`&&typeof t.data.content==`string`){l+=t.data.content;let n=l;n=n.includes(`<think>`)&&!n.includes(`</think>`)?`💭 `+e(`chat.thinking`):me(n.replace(/<think>[\s\S]*?<\/think>/g,``)),o(e=>{let t=[...e],r=t[t.length-1];return r?.role===`assistant`&&(t[t.length-1]={...r,content:n}),t})}if(t.type===`tool_synthesis`&&(l=``,o(e=>{let t=[...e],n=t[t.length-1];return n?.role===`assistant`&&(t[t.length-1]={...n,content:``}),t})),t.type===`done`){let e=me((t.data.content??l).replace(/<think>[\s\S]*?<\/think>/g,``));o(t=>{let n=[...t],r=n[n.length-1];return r?.role===`assistant`&&(n[n.length-1]={...r,content:e,streaming:!1}),n}),L()}},c.signal)}catch{}finally{f(!1),p.current=null}},[d,a,r,L,e]),Ae=e=>{d||(A(e),oe(a[e].content))},je=(0,_.useCallback)(async()=>{if(ae===null)return;let t=j.trim();if(!t)return;let n=a.slice(0,ae).map(e=>({role:e.role,content:e.content}));o(e=>{let n=e.slice(0,ae);return n.push({role:`user`,content:t}),n.push({role:`assistant`,content:``,streaming:!0}),n}),A(null),oe(``),f(!0);let i=new AbortController;p.current=i;let s=``;try{await re(`/api/chat/stream`,{message:t,history:n,conversationId:r},t=>{if(t.type===`token`&&typeof t.data.content==`string`){s+=t.data.content;let n=s;n=n.includes(`<think>`)&&!n.includes(`</think>`)?`💭 `+e(`chat.thinking`):me(n.replace(/<think>[\s\S]*?<\/think>/g,``)),o(e=>{let t=[...e],r=t[t.length-1];return r?.role===`assistant`&&(t[t.length-1]={...r,content:n}),t})}if(t.type===`tool_synthesis`&&(s=``,o(e=>{let t=[...e],n=t[t.length-1];return n?.role===`assistant`&&(t[t.length-1]={...n,content:``}),t})),t.type===`done`){let e=me((t.data.content??s).replace(/<think>[\s\S]*?<\/think>/g,``));o(t=>{let n=[...t],r=n[n.length-1];return r?.role===`assistant`&&(n[n.length-1]={...r,content:e,streaming:!1}),n}),L()}},i.signal)}catch{}finally{f(!1),p.current=null}},[ae,j,a,r,L,e]);return(0,k.jsxs)(`div`,{className:I.root,children:[s&&(0,k.jsxs)(`div`,{className:I.convSidebar,children:[(0,k.jsx)(`div`,{className:I.convSidebarHeader,children:(0,k.jsxs)(`button`,{className:I.newConvBtn,onClick:ve,children:[`+ `,e(`chat.newChat`)]})}),(0,k.jsx)(`div`,{className:I.convList,children:t.map(t=>{let n=Math.floor(t.messageCount/2),i=t.id===r;return(0,k.jsxs)(`div`,{className:`${I.convItem} ${i?I.convItemActive:``}`,onClick:()=>_e(t.id),children:[(0,k.jsx)(`div`,{className:I.convTitle,children:t.title||e(`chat.newChat`)}),(0,k.jsxs)(`div`,{className:I.convMeta,children:[(0,k.jsxs)(`span`,{children:[n,` turns`]}),!i&&(0,k.jsx)(`span`,{className:I.convDelete,onClick:e=>{e.stopPropagation(),ye(t.id)},children:`del`})]})]},t.id)})})]}),(0,k.jsxs)(`div`,{className:I.chatMain,children:[(0,k.jsxs)(`div`,{className:I.chatToolbar,children:[(0,k.jsx)(`button`,{className:I.toolbarBtn,onClick:be,title:`Toggle conversations`,children:`💬 Chats`}),(0,k.jsx)(`span`,{className:I.convTitleBar,children:t.find(e=>e.id===r)?.title||e(`chat.newChat`)}),(0,k.jsx)(`button`,{className:I.toolbarBtn,onClick:ve,children:`+ New`}),(0,k.jsx)(`button`,{className:I.toolbarBtnDim,onClick:R,title:`Export Markdown`,children:`Export`}),te&&(0,k.jsx)(`button`,{className:`${I.toolbarBtn} ${I.toolbarBtnCanvas}`,onClick:()=>O(e=>!e),title:`Toggle canvas panel`,children:ie?`▣ Panel ✕`:`▣ Panel`})]}),(0,k.jsxs)(`div`,{className:I.messages,ref:ge,children:[a.length===0&&(0,k.jsxs)(`div`,{className:I.empty,children:[(0,k.jsx)(`div`,{className:I.emptyIcon,children:`💬`}),(0,k.jsx)(`div`,{className:I.emptyTitle,children:`NHA Chat`}),(0,k.jsx)(`div`,{className:I.emptySub,children:`Personal Operations Assistant · 80 Tools · 38 Agents · Free AI`}),(0,k.jsxs)(`div`,{className:I.suggGroups,children:[(0,k.jsxs)(`div`,{className:I.suggGroup,children:[(0,k.jsx)(`div`,{className:I.suggGroupTitle,children:`⚡ Quick Actions`}),(0,k.jsx)(`div`,{className:I.suggBtns,children:[`Show my unread emails and summarize the most important ones`,`What's on my calendar today? Any meetings I need to prepare for?`,`List my pending tasks sorted by priority`,`Check my GitHub notifications and summarize open issues`].map(e=>(0,k.jsx)(`button`,{className:I.suggBtn,onClick:()=>u(e),children:e},e))})]}),(0,k.jsxs)(`div`,{className:I.suggGroup,children:[(0,k.jsx)(`div`,{className:I.suggGroupTitle,children:`🌐 Web & Research`}),(0,k.jsx)(`div`,{className:I.suggBtns,children:[`Search the web for the latest AI news and summarize the top 5 stories`,`Open google.com and take a screenshot of the homepage`,`Search for the best restaurants near me and create a summary`,`Research the latest developments in quantum computing and write a report`].map(e=>(0,k.jsx)(`button`,{className:I.suggBtn,onClick:()=>u(e),children:e},e))})]}),(0,k.jsxs)(`div`,{className:I.suggGroup,children:[(0,k.jsx)(`div`,{className:I.suggGroupTitle,children:`🛠️ Productivity`}),(0,k.jsx)(`div`,{className:I.suggBtns,children:[`Draft a professional reply to my last email`,`Create a new calendar event for tomorrow at 10am with reminder`,`Summarize my notes and create a to-do list from action items`,`Find contacts named Mario and show their details`].map(e=>(0,k.jsx)(`button`,{className:I.suggBtn,onClick:()=>u(e),children:e},e))})]}),(0,k.jsxs)(`div`,{className:I.suggGroup,children:[(0,k.jsx)(`div`,{className:I.suggGroupTitle,children:`📈 Finance`}),(0,k.jsx)(`div`,{className:I.suggBtns,children:[`What is the current price of Bitcoin and its 24h performance?`,`Analyze the current macro environment and suggest 3 trading opportunities`,`What is the current market regime? Risk-on or risk-off?`,`Give me a technical analysis of AAPL with key support/resistance levels`].map(e=>(0,k.jsx)(`button`,{className:I.suggBtn,onClick:()=>u(e),children:e},e))})]})]})]}),a.map((e,t)=>(0,k.jsxs)(`div`,{className:`${I.message} ${I[e.role]}`,children:[(0,k.jsx)(`div`,{className:I.msgLabel,children:e.role===`user`?`You`:`NHA`}),e.role===`assistant`&&e.streaming&&(0,k.jsxs)(`div`,{className:I.toolActivity,children:[(F||e.content===``&&!ce&&se.length===0)&&(0,k.jsxs)(`div`,{className:I.thinkingIndicator,children:[(0,k.jsxs)(`div`,{className:I.thinkingDots,children:[(0,k.jsx)(`div`,{className:I.thinkingDot}),(0,k.jsx)(`div`,{className:I.thinkingDot}),(0,k.jsx)(`div`,{className:I.thinkingDot})]}),ce?`Deep thinking...`:`Generating...`]}),ce&&!F&&(0,k.jsxs)(`div`,{className:I.thinkingIndicator,children:[(0,k.jsxs)(`div`,{className:I.thinkingDots,children:[(0,k.jsx)(`div`,{className:I.thinkingDot}),(0,k.jsx)(`div`,{className:I.thinkingDot}),(0,k.jsx)(`div`,{className:I.thinkingDot})]}),`Deep thinking...`]}),se.map((e,t)=>(0,k.jsxs)(`div`,{className:`${I.toolActivityItem} ${I[e.status]}`,children:[e.status===`active`?`⏳`:e.status===`error`?`❌`:`✅`,` `,e.label,e.status===`active`&&`...`]},t))]}),e.role===`user`&&ae===t?(0,k.jsxs)(`div`,{className:I.editBox,children:[(0,k.jsx)(`textarea`,{className:I.editInput,value:j,onChange:e=>oe(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),je()),e.key===`Escape`&&A(null)},autoFocus:!0,rows:3}),(0,k.jsxs)(`div`,{className:I.editActions,children:[(0,k.jsx)(`button`,{className:I.editSaveBtn,onClick:je,children:`Send ↵`}),(0,k.jsx)(`button`,{className:I.editCancelBtn,onClick:()=>A(null),children:`Cancel`})]})]}):e.role===`assistant`?e.content!==``&&(0,k.jsx)(`div`,{className:`${I.bubble} ${pe.body} ${e.sentinelBlocked?I.sentinelBubble:``}`,dangerouslySetInnerHTML:{__html:fe(e.content)}}):(0,k.jsx)(`div`,{className:I.bubble,children:e.content}),e.streaming&&(0,k.jsx)(`span`,{className:I.cursor}),!e.streaming&&ae!==t&&(0,k.jsxs)(`div`,{className:I.msgActions,children:[(0,k.jsx)(`button`,{className:I.msgActionBtn,onClick:()=>B(e.content),children:`Copy`}),e.role===`user`&&!d&&(0,k.jsx)(`button`,{className:I.msgActionBtn,onClick:()=>Ae(t),children:`Edit`}),e.role===`assistant`&&!d&&(0,k.jsx)(`button`,{className:I.msgActionBtn,onClick:()=>ke(t),children:`Retry`})]})]},t)),(0,k.jsx)(`div`,{ref:ue})]}),we&&(0,k.jsxs)(`div`,{className:I.attachBar,children:[(0,k.jsx)(`span`,{children:we}),(0,k.jsx)(`button`,{className:I.attachClear,onClick:Ce,children:`×`})]}),(0,k.jsxs)(`div`,{className:I.inputBar,children:[(0,k.jsxs)(`div`,{className:I.inputTools,children:[(0,k.jsx)(`button`,{className:`${I.iconBtn} ${C?I.iconBtnActive:``}`,onClick:Te,title:`Voice input`,children:`🎤`}),(0,k.jsx)(`button`,{className:I.iconBtn,onClick:()=>y.current?.click(),title:`Attach file`,children:`📎`}),(0,k.jsx)(`button`,{className:I.iconBtn,onClick:()=>b.current?.click(),title:`Attach image`,children:`🖼`}),(0,k.jsx)(`input`,{ref:y,type:`file`,style:{display:`none`},onChange:xe}),(0,k.jsx)(`input`,{ref:b,type:`file`,accept:`image/*`,style:{display:`none`},onChange:Se}),(0,k.jsx)(`span`,{style:{flex:1}}),(0,k.jsxs)(`button`,{className:`${I.thinkBtn} ${x?I.thinkBtnOn:``}`,onClick:z,title:`Extended Thinking`,children:[`Think: `,x?`on`:`off`]}),te&&(0,k.jsx)(`button`,{className:I.toolbarBtn,onClick:()=>O(e=>!e),title:`Canvas panel`,children:`▣ Panel`})]}),(0,k.jsxs)(`div`,{className:I.inputRow,children:[(0,k.jsx)(`textarea`,{ref:de,className:I.input,value:l,onChange:e=>u(e.target.value),onKeyDown:Oe,placeholder:e(`chat.placeholder`),rows:1,disabled:d}),d?(0,k.jsxs)(`button`,{className:`${I.btn} ${I.stop}`,onClick:De,children:[`■ `,e(`chat.stopGeneration`)]}):(0,k.jsx)(`button`,{className:`${I.btn} ${I.send}`,onClick:Ee,disabled:!l.trim()&&!m&&!g,children:`Send ↵`})]})]})]}),ie&&te&&(0,k.jsxs)(`div`,{className:I.canvasPanel,children:[(0,k.jsxs)(`div`,{className:I.canvasPanelHeader,children:[(0,k.jsx)(`span`,{children:`Canvas`}),(0,k.jsxs)(`div`,{className:I.canvasPanelActions,children:[(0,k.jsx)(`button`,{className:I.canvasPanelBtn,onClick:()=>{let e=new Blob([te],{type:`text/html`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`NHA-Canvas.html`,n.click(),setTimeout(()=>URL.revokeObjectURL(t),5e3)},children:`↓ Download`}),(0,k.jsx)(`button`,{className:I.canvasPanelBtn,onClick:()=>navigator.clipboard.writeText(te).catch(()=>{}),children:`Copy HTML`}),(0,k.jsx)(`button`,{className:I.canvasPanelClose,onClick:()=>O(!1),children:`×`})]})]}),(0,k.jsx)(`iframe`,{className:I.canvasFrame,sandbox:`allow-scripts`,srcDoc:te,title:`Canvas`})]})]})}var L={root:`_root_1p83q_1`,header:`_header_1p83q_8`,headerLeft:`_headerLeft_1p83q_18`,title:`_title_1p83q_20`,subtitle:`_subtitle_1p83q_27`,headerActions:`_headerActions_1p83q_33`,tokenBar:`_tokenBar_1p83q_40`,tokIn:`_tokIn_1p83q_48`,tokOut:`_tokOut_1p83q_49`,tokTotal:`_tokTotal_1p83q_50`,tokDim:`_tokDim_1p83q_51`,sessionsBtn:`_sessionsBtn_1p83q_53`,pdfBtn:`_pdfBtn_1p83q_65`,clearBtn:`_clearBtn_1p83q_75`,sessionsDrawer:`_sessionsDrawer_1p83q_88`,noSessions:`_noSessions_1p83q_96`,sessionItem:`_sessionItem_1p83q_103`,sessionInfo:`_sessionInfo_1p83q_113`,sessionTask:`_sessionTask_1p83q_119`,sessionMeta:`_sessionMeta_1p83q_129`,sessionBtns:`_sessionBtns_1p83q_135`,importBtn:`_importBtn_1p83q_141`,delSessionBtn:`_delSessionBtn_1p83q_151`,inputArea:`_inputArea_1p83q_162`,inputRow:`_inputRow_1p83q_171`,taskInput:`_taskInput_1p83q_177`,inputControls:`_inputControls_1p83q_192`,runBtn:`_runBtn_1p83q_198`,stopBtn:`_stopBtn_1p83q_211`,attachBtn:`_attachBtn_1p83q_222`,attachBadge:`_attachBadge_1p83q_235`,clearAttach:`_clearAttach_1p83q_248`,examples:`_examples_1p83q_257`,exampleBtn:`_exampleBtn_1p83q_263`,body:`_body_1p83q_281`,agentChip:`_agentChip_1p83q_291`,chip_running:`_chip_running_1p83q_302`,charCardPulse:`_charCardPulse_1p83q_1`,chip_done:`_chip_done_1p83q_308`,chip_error:`_chip_error_1p83q_309`,chip_waiting:`_chip_waiting_1p83q_310`,chipIcon:`_chipIcon_1p83q_311`,chipLabel:`_chipLabel_1p83q_312`,chipDots:`_chipDots_1p83q_313`,chipCheck:`_chipCheck_1p83q_314`,chipErr:`_chipErr_1p83q_315`,officeSceneWrap:`_officeSceneWrap_1p83q_318`,pipeline:`_pipeline_1p83q_324`,pipelineRunning:`_pipelineRunning_1p83q_337`,scanSweep:`_scanSweep_1p83q_1`,pipelineTitle:`_pipelineTitle_1p83q_359`,pipelineNodes:`_pipelineNodes_1p83q_367`,pipelineStep:`_pipelineStep_1p83q_374`,arrow:`_arrow_1p83q_380`,arrowActive:`_arrowActive_1p83q_389`,arrowPulse:`_arrowPulse_1p83q_1`,agentChar:`_agentChar_1p83q_401`,charWaiting:`_charWaiting_1p83q_416`,charActive:`_charActive_1p83q_421`,charDone:`_charDone_1p83q_429`,charError:`_charError_1p83q_434`,orbitRing1:`_orbitRing1_1p83q_445`,orbitRing2:`_orbitRing2_1p83q_446`,orbitSpin1:`_orbitSpin1_1p83q_1`,orbitSpin2:`_orbitSpin2_1p83q_1`,charAvatar:`_charAvatar_1p83q_492`,charIcon:`_charIcon_1p83q_507`,iconBob:`_iconBob_1p83q_1`,charCheck:`_charCheck_1p83q_524`,badgePop:`_badgePop_1p83q_1`,charErr:`_charErr_1p83q_434`,charPulse:`_charPulse_1p83q_568`,charPulse2:`_charPulse2_1p83q_569`,expandRing:`_expandRing_1p83q_1`,charLabel:`_charLabel_1p83q_588`,charStatus:`_charStatus_1p83q_600`,charStatusDots:`_charStatusDots_1p83q_613`,dot1:`_dot1_1p83q_614`,dot2:`_dot2_1p83q_614`,dot3:`_dot3_1p83q_614`,dotFade:`_dotFade_1p83q_1`,twoCol:`_twoCol_1p83q_628`,panelTitle:`_panelTitle_1p83q_635`,logPanel:`_logPanel_1p83q_645`,logBody:`_logBody_1p83q_657`,logEntry:`_logEntry_1p83q_665`,logTime:`_logTime_1p83q_675`,logIcon:`_logIcon_1p83q_676`,logAgent:`_logAgent_1p83q_677`,logText:`_logText_1p83q_678`,log_system:`_log_system_1p83q_680`,log_error:`_log_error_1p83q_681`,liveOutputPanel:`_liveOutputPanel_1p83q_684`,liveBlock:`_liveBlock_1p83q_690`,blockSlideIn:`_blockSlideIn_1p83q_1`,liveBlockActive:`_liveBlockActive_1p83q_704`,liveBlockPulse:`_liveBlockPulse_1p83q_1`,liveBlockScan:`_liveBlockScan_1p83q_1`,liveBlockHeader:`_liveBlockHeader_1p83q_733`,liveBlockIcon:`_liveBlockIcon_1p83q_742`,liveBlockLabel:`_liveBlockLabel_1p83q_744`,outputStatus:`_outputStatus_1p83q_752`,status_done:`_status_done_1p83q_763`,status_running:`_status_running_1p83q_764`,status_error:`_status_error_1p83q_765`,status_waiting:`_status_waiting_1p83q_766`,liveBlockBody:`_liveBlockBody_1p83q_769`,liveBlockWorking:`_liveBlockWorking_1p83q_907`,workingDot:`_workingDot_1p83q_914`,workingBounce:`_workingBounce_1p83q_1`,workingLabel:`_workingLabel_1p83q_931`,workingFade:`_workingFade_1p83q_1`,studioBlinkCursor:`_studioBlinkCursor_1p83q_1`,resultAccordion:`_resultAccordion_1p83q_960`,resultAccordionSummary:`_resultAccordionSummary_1p83q_967`,resultAccordionBody:`_resultAccordionBody_1p83q_984`,financeSection:`_financeSection_1p83q_1018`,financeSectionTitle:`_financeSectionTitle_1p83q_1026`,financePresets:`_financePresets_1p83q_1035`,financeBtn:`_financeBtn_1p83q_1041`,canvasToggleBtn:`_canvasToggleBtn_1p83q_1059`,canvasPanel:`_canvasPanel_1p83q_1075`,canvasPanelHeader:`_canvasPanelHeader_1p83q_1090`,canvasPanelActions:`_canvasPanelActions_1p83q_1102`,canvasPanelBtn:`_canvasPanelBtn_1p83q_1108`,canvasPanelClose:`_canvasPanelClose_1p83q_1120`,canvasFrame:`_canvasFrame_1p83q_1131`,pipelineLiveTag:`_pipelineLiveTag_1p83q_1139`,liveTagBlink:`_liveTagBlink_1p83q_1`,reasonRow:`_reasonRow_1p83q_1153`,reasonChip:`_reasonChip_1p83q_1162`,reasonIcon:`_reasonIcon_1p83q_1175`,reasonText:`_reasonText_1p83q_1176`,liveBlockReason:`_liveBlockReason_1p83q_1179`,councilWrapper:`_councilWrapper_1p83q_1189`,councilPanel:`_councilPanel_1p83q_1194`,councilHeader:`_councilHeader_1p83q_1202`,councilHeaderLeft:`_councilHeaderLeft_1p83q_1213`,councilHeaderRight:`_councilHeaderRight_1p83q_1219`,councilIcon:`_councilIcon_1p83q_1225`,councilTitle:`_councilTitle_1p83q_1227`,councilConvergedBadge:`_councilConvergedBadge_1p83q_1236`,councilDivergedBadge:`_councilDivergedBadge_1p83q_1248`,councilPhaseTag:`_councilPhaseTag_1p83q_1260`,councilPhaseActive:`_councilPhaseActive_1p83q_1266`,phaseGlow:`_phaseGlow_1p83q_1`,councilPhaseDone:`_councilPhaseDone_1p83q_1275`,councilMetrics:`_councilMetrics_1p83q_1278`,convRow:`_convRow_1p83q_1286`,convLabel:`_convLabel_1p83q_1292`,convTrack:`_convTrack_1p83q_1300`,convFill:`_convFill_1p83q_1308`,convPct:`_convPct_1p83q_1314`,councilNodes:`_councilNodes_1p83q_1324`,councilSectionTitle:`_councilSectionTitle_1p83q_1329`,councilNode:`_councilNode_1p83q_1324`,councilNodeHeader:`_councilNodeHeader_1p83q_1346`,councilNodeIcon:`_councilNodeIcon_1p83q_1359`,councilNodeLabel:`_councilNodeLabel_1p83q_1360`,councilNodeToggle:`_councilNodeToggle_1p83q_1361`,councilNodeBody:`_councilNodeBody_1p83q_1363`,councilSynthesis:`_councilSynthesis_1p83q_1373`,councilSynthesisHeader:`_councilSynthesisHeader_1p83q_1377`,heraldIcon:`_heraldIcon_1p83q_1386`,heraldLabel:`_heraldLabel_1p83q_1388`,heraldStreaming:`_heraldStreaming_1p83q_1396`,councilSynthesisBody:`_councilSynthesisBody_1p83q_1398`,councilSkipped:`_councilSkipped_1p83q_1428`,councilSkipIcon:`_councilSkipIcon_1p83q_1439`,charSpriteRunning:`_charSpriteRunning_1p83q_1452`,spriteWalk:`_spriteWalk_1p83q_1`,charSpriteDone:`_charSpriteDone_1p83q_1461`,charScanline:`_charScanline_1p83q_1465`,scanlineScroll:`_scanlineScroll_1p83q_1`,auraAnim:`_auraAnim_1p83q_1485`,auraGlow:`_auraGlow_1p83q_1`,parliamentPrompt:`_parliamentPrompt_1p83q_1492`,parliamentPromptIcon:`_parliamentPromptIcon_1p83q_1502`,parliamentPromptContent:`_parliamentPromptContent_1p83q_1503`,parliamentPromptTitle:`_parliamentPromptTitle_1p83q_1504`,parliamentPromptDesc:`_parliamentPromptDesc_1p83q_1505`,parliamentPromptMeta:`_parliamentPromptMeta_1p83q_1506`,parliamentPromptBtns:`_parliamentPromptBtns_1p83q_1507`,parliamentActivateBtn:`_parliamentActivateBtn_1p83q_1508`,parliamentSkipBtn:`_parliamentSkipBtn_1p83q_1515`,panelTabs:`_panelTabs_1p83q_1523`,panelTabBtn:`_panelTabBtn_1p83q_1524`,panelTabActive:`_panelTabActive_1p83q_1531`,panelEmpty:`_panelEmpty_1p83q_1533`,browserPanel:`_browserPanel_1p83q_1542`,browserBar:`_browserBar_1p83q_1543`,browserInput:`_browserInput_1p83q_1544`,browserGo:`_browserGo_1p83q_1551`},_e=[{label:`📈 Full Trading Strategy`,task:`You are a team of senior quantitative analysts and macro traders. Build a complete, actionable trading strategy with the following structure:
17
+ `):``,l=me(a.replace(/\[CANVAS_RENDER\][\s\S]*?\[\/CANVAS_RENDER\]/g,``).replace(/```html[\s\S]*?```/g,`[Canvas HTML — click Panel to view]`))+c;o(r?e=>{let t=[...e],n=t.findIndex((e,n)=>n===t.length-1&&e.role===`assistant`);return n>=0&&(t[n]={role:`assistant`,content:l||`Message blocked by SENTINEL.`,sentinelBlocked:!0,streaming:!1}),t}:e=>{let t=[...e],n=t[t.length-1];return n?.role===`assistant`&&(t[t.length-1]={...n,content:l,streaming:!1}),t}),L()}t.type===`error`&&o(e=>{let n=[...e],r=n[n.length-1];return r?.role===`assistant`&&(n[n.length-1]={...r,content:`Error: `+(t.data.message??`Unknown`),streaming:!1}),n})},s.signal)}catch(e){e.name!==`AbortError`&&o(e=>{let t=[...e],n=t[t.length-1];return n?.role===`assistant`&&(t[t.length-1]={...n,content:n.content||`Error connecting to server.`,streaming:!1}),t})}finally{N(!1),le(!1),o(e=>{let t=[...e],n=t[t.length-1];return n?.role===`assistant`&&n.streaming&&(t[t.length-1]={...n,streaming:!1}),t}),f(!1),p.current=null,setTimeout(()=>M([]),2e3)}},[l,a,d,m,g,r,L]),De=()=>{p.current?.abort(),f(!1)},Oe=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Ee())},B=e=>{navigator.clipboard.writeText(e.replace(/\[CANVAS_RENDER\][\s\S]*?\[\/CANVAS_RENDER\]/g,``).trim()).catch(()=>{})},ke=(0,_.useCallback)(async t=>{if(d)return;let n=t-1;if(n<0||a[n]?.role!==`user`)return;let i=a[n],s=a.slice(0,n).map(e=>({role:e.role,content:e.content}));o(e=>{let n=[...e];return n[t]={role:`assistant`,content:``,streaming:!0},n.slice(0,t+1)}),f(!0);let c=new AbortController;p.current=c;let l=``;try{await re(`/api/chat/stream`,{message:i.content,history:s,conversationId:r},t=>{if(t.type===`token`&&typeof t.data.content==`string`){l+=t.data.content;let n=l;n=n.includes(`<think>`)&&!n.includes(`</think>`)?`💭 `+e(`chat.thinking`):me(n.replace(/<think>[\s\S]*?<\/think>/g,``)),o(e=>{let t=[...e],r=t[t.length-1];return r?.role===`assistant`&&(t[t.length-1]={...r,content:n}),t})}if(t.type===`tool_synthesis`&&(l=``,o(e=>{let t=[...e],n=t[t.length-1];return n?.role===`assistant`&&(t[t.length-1]={...n,content:``}),t})),t.type===`done`){let e=me((t.data.content??l).replace(/<think>[\s\S]*?<\/think>/g,``));o(t=>{let n=[...t],r=n[n.length-1];return r?.role===`assistant`&&(n[n.length-1]={...r,content:e,streaming:!1}),n}),L()}},c.signal)}catch{}finally{f(!1),p.current=null}},[d,a,r,L,e]),Ae=e=>{d||(A(e),oe(a[e].content))},je=(0,_.useCallback)(async()=>{if(ae===null)return;let t=j.trim();if(!t)return;let n=a.slice(0,ae).map(e=>({role:e.role,content:e.content}));o(e=>{let n=e.slice(0,ae);return n.push({role:`user`,content:t}),n.push({role:`assistant`,content:``,streaming:!0}),n}),A(null),oe(``),f(!0);let i=new AbortController;p.current=i;let s=``;try{await re(`/api/chat/stream`,{message:t,history:n,conversationId:r},t=>{if(t.type===`token`&&typeof t.data.content==`string`){s+=t.data.content;let n=s;n=n.includes(`<think>`)&&!n.includes(`</think>`)?`💭 `+e(`chat.thinking`):me(n.replace(/<think>[\s\S]*?<\/think>/g,``)),o(e=>{let t=[...e],r=t[t.length-1];return r?.role===`assistant`&&(t[t.length-1]={...r,content:n}),t})}if(t.type===`tool_synthesis`&&(s=``,o(e=>{let t=[...e],n=t[t.length-1];return n?.role===`assistant`&&(t[t.length-1]={...n,content:``}),t})),t.type===`done`){let e=me((t.data.content??s).replace(/<think>[\s\S]*?<\/think>/g,``));o(t=>{let n=[...t],r=n[n.length-1];return r?.role===`assistant`&&(n[n.length-1]={...r,content:e,streaming:!1}),n}),L()}},i.signal)}catch{}finally{f(!1),p.current=null}},[ae,j,a,r,L,e]);return(0,k.jsxs)(`div`,{className:I.root,children:[s&&(0,k.jsxs)(`div`,{className:I.convSidebar,children:[(0,k.jsx)(`div`,{className:I.convSidebarHeader,children:(0,k.jsxs)(`button`,{className:I.newConvBtn,onClick:ve,children:[`+ `,e(`chat.newChat`)]})}),(0,k.jsx)(`div`,{className:I.convList,children:t.map(t=>{let n=Math.floor(t.messageCount/2),i=t.id===r;return(0,k.jsxs)(`div`,{className:`${I.convItem} ${i?I.convItemActive:``}`,onClick:()=>_e(t.id),children:[(0,k.jsx)(`div`,{className:I.convTitle,children:t.title||e(`chat.newChat`)}),(0,k.jsxs)(`div`,{className:I.convMeta,children:[(0,k.jsxs)(`span`,{children:[n,` turns`]}),!i&&(0,k.jsx)(`span`,{className:I.convDelete,onClick:e=>{e.stopPropagation(),ye(t.id)},children:`del`})]})]},t.id)})})]}),(0,k.jsxs)(`div`,{className:I.chatMain,children:[(0,k.jsxs)(`div`,{className:I.chatToolbar,children:[(0,k.jsx)(`button`,{className:I.toolbarBtn,onClick:be,title:`Toggle conversations`,children:`💬 Chats`}),(0,k.jsx)(`span`,{className:I.convTitleBar,children:t.find(e=>e.id===r)?.title||e(`chat.newChat`)}),(0,k.jsx)(`button`,{className:I.toolbarBtn,onClick:ve,children:`+ New`}),(0,k.jsx)(`button`,{className:I.toolbarBtnDim,onClick:R,title:`Export Markdown`,children:`Export`}),te&&(0,k.jsx)(`button`,{className:`${I.toolbarBtn} ${I.toolbarBtnCanvas}`,onClick:()=>O(e=>!e),title:`Toggle canvas panel`,children:ie?`▣ Panel ✕`:`▣ Panel`})]}),(0,k.jsxs)(`div`,{className:I.messages,ref:ge,children:[a.length===0&&(0,k.jsxs)(`div`,{className:I.empty,children:[(0,k.jsx)(`div`,{className:I.emptyIcon,children:`💬`}),(0,k.jsx)(`div`,{className:I.emptyTitle,children:`NHA Chat`}),(0,k.jsx)(`div`,{className:I.emptySub,children:`Personal Operations Assistant · 80 Tools · 38 Agents · Free AI`}),(0,k.jsxs)(`div`,{className:I.suggGroups,children:[(0,k.jsxs)(`div`,{className:I.suggGroup,children:[(0,k.jsx)(`div`,{className:I.suggGroupTitle,children:`⚡ Quick Actions`}),(0,k.jsx)(`div`,{className:I.suggBtns,children:[`Show my unread emails and summarize the most important ones`,`What's on my calendar today? Any meetings I need to prepare for?`,`List my pending tasks sorted by priority`,`Check my GitHub notifications and summarize open issues`].map(e=>(0,k.jsx)(`button`,{className:I.suggBtn,onClick:()=>u(e),children:e},e))})]}),(0,k.jsxs)(`div`,{className:I.suggGroup,children:[(0,k.jsx)(`div`,{className:I.suggGroupTitle,children:`🌐 Web & Research`}),(0,k.jsx)(`div`,{className:I.suggBtns,children:[`Search the web for the latest AI news and summarize the top 5 stories`,`Open google.com and take a screenshot of the homepage`,`Search for the best restaurants near me and create a summary`,`Research the latest developments in quantum computing and write a report`].map(e=>(0,k.jsx)(`button`,{className:I.suggBtn,onClick:()=>u(e),children:e},e))})]}),(0,k.jsxs)(`div`,{className:I.suggGroup,children:[(0,k.jsx)(`div`,{className:I.suggGroupTitle,children:`🛠️ Productivity`}),(0,k.jsx)(`div`,{className:I.suggBtns,children:[`Draft a professional reply to my last email`,`Create a new calendar event for tomorrow at 10am with reminder`,`Summarize my notes and create a to-do list from action items`,`Find contacts named Mario and show their details`].map(e=>(0,k.jsx)(`button`,{className:I.suggBtn,onClick:()=>u(e),children:e},e))})]}),(0,k.jsxs)(`div`,{className:I.suggGroup,children:[(0,k.jsx)(`div`,{className:I.suggGroupTitle,children:`📈 Finance`}),(0,k.jsx)(`div`,{className:I.suggBtns,children:[`What is the current price of Bitcoin and its 24h performance?`,`Analyze the current macro environment and suggest 3 trading opportunities`,`What is the current market regime? Risk-on or risk-off?`,`Give me a technical analysis of AAPL with key support/resistance levels`].map(e=>(0,k.jsx)(`button`,{className:I.suggBtn,onClick:()=>u(e),children:e},e))})]})]})]}),a.map((e,t)=>(0,k.jsxs)(`div`,{className:`${I.message} ${I[e.role]}`,children:[(0,k.jsx)(`div`,{className:I.msgLabel,children:e.role===`user`?`You`:`NHA`}),e.role===`assistant`&&e.streaming&&(0,k.jsxs)(`div`,{className:I.toolActivity,children:[(F||e.content===``&&!ce&&se.length===0)&&(0,k.jsxs)(`div`,{className:I.thinkingIndicator,children:[(0,k.jsxs)(`div`,{className:I.thinkingDots,children:[(0,k.jsx)(`div`,{className:I.thinkingDot}),(0,k.jsx)(`div`,{className:I.thinkingDot}),(0,k.jsx)(`div`,{className:I.thinkingDot})]}),ce?`Deep thinking...`:`Generating...`]}),ce&&!F&&(0,k.jsxs)(`div`,{className:I.thinkingIndicator,children:[(0,k.jsxs)(`div`,{className:I.thinkingDots,children:[(0,k.jsx)(`div`,{className:I.thinkingDot}),(0,k.jsx)(`div`,{className:I.thinkingDot}),(0,k.jsx)(`div`,{className:I.thinkingDot})]}),`Deep thinking...`]}),se.map((e,t)=>(0,k.jsxs)(`div`,{className:`${I.toolActivityItem} ${I[e.status]}`,children:[e.status===`active`?`⏳`:e.status===`error`?`❌`:`✅`,` `,e.label,e.status===`active`&&`...`]},t))]}),e.role===`user`&&ae===t?(0,k.jsxs)(`div`,{className:I.editBox,children:[(0,k.jsx)(`textarea`,{className:I.editInput,value:j,onChange:e=>oe(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),je()),e.key===`Escape`&&A(null)},autoFocus:!0,rows:3}),(0,k.jsxs)(`div`,{className:I.editActions,children:[(0,k.jsx)(`button`,{className:I.editSaveBtn,onClick:je,children:`Send ↵`}),(0,k.jsx)(`button`,{className:I.editCancelBtn,onClick:()=>A(null),children:`Cancel`})]})]}):e.role===`assistant`?e.content!==``&&(0,k.jsx)(`div`,{className:`${I.bubble} ${pe.body} ${e.sentinelBlocked?I.sentinelBubble:``}`,dangerouslySetInnerHTML:{__html:fe(e.content)}}):(0,k.jsx)(`div`,{className:I.bubble,children:e.content}),e.streaming&&(0,k.jsx)(`span`,{className:I.cursor}),!e.streaming&&ae!==t&&(0,k.jsxs)(`div`,{className:I.msgActions,children:[(0,k.jsx)(`button`,{className:I.msgActionBtn,onClick:()=>B(e.content),children:`Copy`}),e.role===`user`&&!d&&(0,k.jsx)(`button`,{className:I.msgActionBtn,onClick:()=>Ae(t),children:`Edit`}),e.role===`assistant`&&!d&&(0,k.jsx)(`button`,{className:I.msgActionBtn,onClick:()=>ke(t),children:`Retry`})]})]},t)),(0,k.jsx)(`div`,{ref:ue})]}),we&&(0,k.jsxs)(`div`,{className:I.attachBar,children:[(0,k.jsx)(`span`,{children:we}),(0,k.jsx)(`button`,{className:I.attachClear,onClick:Ce,children:`×`})]}),(0,k.jsxs)(`div`,{className:I.inputBar,children:[(0,k.jsxs)(`div`,{className:I.inputTools,children:[(0,k.jsx)(`button`,{className:`${I.iconBtn} ${C?I.iconBtnActive:``}`,onClick:Te,title:`Voice input`,children:`🎤`}),(0,k.jsx)(`button`,{className:I.iconBtn,onClick:()=>y.current?.click(),title:`Attach file`,children:`📎`}),(0,k.jsx)(`button`,{className:I.iconBtn,onClick:()=>b.current?.click(),title:`Attach image`,children:`🖼`}),(0,k.jsx)(`input`,{ref:y,type:`file`,style:{display:`none`},onChange:xe}),(0,k.jsx)(`input`,{ref:b,type:`file`,accept:`image/*`,style:{display:`none`},onChange:Se}),(0,k.jsx)(`span`,{style:{flex:1}}),(0,k.jsxs)(`button`,{className:`${I.thinkBtn} ${x?I.thinkBtnOn:``}`,onClick:z,title:`Extended Thinking`,children:[`Think: `,x?`on`:`off`]}),te&&(0,k.jsx)(`button`,{className:I.toolbarBtn,onClick:()=>O(e=>!e),title:`Canvas panel`,children:`▣ Panel`})]}),(0,k.jsxs)(`div`,{className:I.inputRow,children:[(0,k.jsx)(`textarea`,{ref:de,className:I.input,value:l,onChange:e=>u(e.target.value),onKeyDown:Oe,placeholder:e(`chat.placeholder`),rows:1,disabled:d}),d?(0,k.jsxs)(`button`,{className:`${I.btn} ${I.stop}`,onClick:De,children:[`■ `,e(`chat.stopGeneration`)]}):(0,k.jsx)(`button`,{className:`${I.btn} ${I.send}`,onClick:Ee,disabled:!l.trim()&&!m&&!g,children:`Send ↵`})]})]})]}),ie&&te&&(0,k.jsxs)(`div`,{className:I.canvasPanel,children:[(0,k.jsxs)(`div`,{className:I.canvasPanelHeader,children:[(0,k.jsx)(`span`,{children:`Canvas`}),(0,k.jsxs)(`div`,{className:I.canvasPanelActions,children:[(0,k.jsx)(`button`,{className:I.canvasPanelBtn,onClick:()=>{let e=new Blob([te],{type:`text/html`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`NHA-Canvas.html`,n.click(),setTimeout(()=>URL.revokeObjectURL(t),5e3)},children:`↓ Download`}),(0,k.jsx)(`button`,{className:I.canvasPanelBtn,onClick:()=>navigator.clipboard.writeText(te).catch(()=>{}),children:`Copy HTML`}),(0,k.jsx)(`button`,{className:I.canvasPanelClose,onClick:()=>O(!1),children:`×`})]})]}),(0,k.jsx)(`iframe`,{className:I.canvasFrame,sandbox:`allow-scripts`,srcDoc:te,title:`Canvas`})]})]})}var L={root:`_root_8zc2t_1`,header:`_header_8zc2t_8`,headerLeft:`_headerLeft_8zc2t_18`,title:`_title_8zc2t_20`,subtitle:`_subtitle_8zc2t_27`,headerActions:`_headerActions_8zc2t_33`,tokenBar:`_tokenBar_8zc2t_40`,tokIn:`_tokIn_8zc2t_48`,tokOut:`_tokOut_8zc2t_49`,tokTotal:`_tokTotal_8zc2t_50`,tokDim:`_tokDim_8zc2t_51`,sessionsBtn:`_sessionsBtn_8zc2t_53`,pdfBtn:`_pdfBtn_8zc2t_65`,clearBtn:`_clearBtn_8zc2t_75`,sessionsDrawer:`_sessionsDrawer_8zc2t_88`,noSessions:`_noSessions_8zc2t_96`,sessionItem:`_sessionItem_8zc2t_103`,sessionInfo:`_sessionInfo_8zc2t_113`,sessionTask:`_sessionTask_8zc2t_119`,sessionMeta:`_sessionMeta_8zc2t_129`,sessionBtns:`_sessionBtns_8zc2t_135`,importBtn:`_importBtn_8zc2t_141`,delSessionBtn:`_delSessionBtn_8zc2t_151`,inputArea:`_inputArea_8zc2t_162`,inputRow:`_inputRow_8zc2t_171`,taskInput:`_taskInput_8zc2t_177`,inputControls:`_inputControls_8zc2t_192`,runBtn:`_runBtn_8zc2t_198`,stopBtn:`_stopBtn_8zc2t_211`,attachBtn:`_attachBtn_8zc2t_222`,attachBadge:`_attachBadge_8zc2t_235`,clearAttach:`_clearAttach_8zc2t_248`,examples:`_examples_8zc2t_257`,exampleBtn:`_exampleBtn_8zc2t_263`,body:`_body_8zc2t_281`,agentChip:`_agentChip_8zc2t_291`,chip_running:`_chip_running_8zc2t_302`,charCardPulse:`_charCardPulse_8zc2t_1`,chip_done:`_chip_done_8zc2t_308`,chip_error:`_chip_error_8zc2t_309`,chip_waiting:`_chip_waiting_8zc2t_310`,chipIcon:`_chipIcon_8zc2t_311`,chipLabel:`_chipLabel_8zc2t_312`,chipDots:`_chipDots_8zc2t_313`,chipCheck:`_chipCheck_8zc2t_314`,chipErr:`_chipErr_8zc2t_315`,officeSceneWrap:`_officeSceneWrap_8zc2t_318`,pipeline:`_pipeline_8zc2t_326`,pipelineRunning:`_pipelineRunning_8zc2t_339`,scanSweep:`_scanSweep_8zc2t_1`,pipelineTitle:`_pipelineTitle_8zc2t_361`,pipelineNodes:`_pipelineNodes_8zc2t_369`,pipelineStep:`_pipelineStep_8zc2t_376`,arrow:`_arrow_8zc2t_382`,arrowActive:`_arrowActive_8zc2t_391`,arrowPulse:`_arrowPulse_8zc2t_1`,agentChar:`_agentChar_8zc2t_403`,charWaiting:`_charWaiting_8zc2t_418`,charActive:`_charActive_8zc2t_423`,charDone:`_charDone_8zc2t_431`,charError:`_charError_8zc2t_436`,orbitRing1:`_orbitRing1_8zc2t_447`,orbitRing2:`_orbitRing2_8zc2t_448`,orbitSpin1:`_orbitSpin1_8zc2t_1`,orbitSpin2:`_orbitSpin2_8zc2t_1`,charAvatar:`_charAvatar_8zc2t_494`,charIcon:`_charIcon_8zc2t_509`,iconBob:`_iconBob_8zc2t_1`,charCheck:`_charCheck_8zc2t_526`,badgePop:`_badgePop_8zc2t_1`,charErr:`_charErr_8zc2t_436`,charPulse:`_charPulse_8zc2t_570`,charPulse2:`_charPulse2_8zc2t_571`,expandRing:`_expandRing_8zc2t_1`,charLabel:`_charLabel_8zc2t_590`,charStatus:`_charStatus_8zc2t_602`,charStatusDots:`_charStatusDots_8zc2t_615`,dot1:`_dot1_8zc2t_616`,dot2:`_dot2_8zc2t_616`,dot3:`_dot3_8zc2t_616`,dotFade:`_dotFade_8zc2t_1`,twoCol:`_twoCol_8zc2t_630`,panelTitle:`_panelTitle_8zc2t_637`,logPanel:`_logPanel_8zc2t_647`,logBody:`_logBody_8zc2t_659`,logEntry:`_logEntry_8zc2t_667`,logTime:`_logTime_8zc2t_677`,logIcon:`_logIcon_8zc2t_678`,logAgent:`_logAgent_8zc2t_679`,logText:`_logText_8zc2t_680`,log_system:`_log_system_8zc2t_682`,log_error:`_log_error_8zc2t_683`,liveOutputPanel:`_liveOutputPanel_8zc2t_686`,liveBlock:`_liveBlock_8zc2t_692`,blockSlideIn:`_blockSlideIn_8zc2t_1`,liveBlockActive:`_liveBlockActive_8zc2t_706`,liveBlockPulse:`_liveBlockPulse_8zc2t_1`,liveBlockScan:`_liveBlockScan_8zc2t_1`,liveBlockHeader:`_liveBlockHeader_8zc2t_735`,liveBlockIcon:`_liveBlockIcon_8zc2t_744`,liveBlockLabel:`_liveBlockLabel_8zc2t_746`,outputStatus:`_outputStatus_8zc2t_754`,status_done:`_status_done_8zc2t_765`,status_running:`_status_running_8zc2t_766`,status_error:`_status_error_8zc2t_767`,status_waiting:`_status_waiting_8zc2t_768`,liveBlockBody:`_liveBlockBody_8zc2t_771`,liveBlockWorking:`_liveBlockWorking_8zc2t_909`,workingDot:`_workingDot_8zc2t_916`,workingBounce:`_workingBounce_8zc2t_1`,workingLabel:`_workingLabel_8zc2t_933`,workingFade:`_workingFade_8zc2t_1`,studioBlinkCursor:`_studioBlinkCursor_8zc2t_1`,resultAccordion:`_resultAccordion_8zc2t_962`,resultAccordionSummary:`_resultAccordionSummary_8zc2t_969`,resultAccordionBody:`_resultAccordionBody_8zc2t_986`,financeSection:`_financeSection_8zc2t_1020`,financeSectionTitle:`_financeSectionTitle_8zc2t_1028`,financePresets:`_financePresets_8zc2t_1037`,financeBtn:`_financeBtn_8zc2t_1043`,canvasToggleBtn:`_canvasToggleBtn_8zc2t_1061`,canvasPanel:`_canvasPanel_8zc2t_1077`,canvasPanelHeader:`_canvasPanelHeader_8zc2t_1092`,canvasPanelActions:`_canvasPanelActions_8zc2t_1104`,canvasPanelBtn:`_canvasPanelBtn_8zc2t_1110`,canvasPanelClose:`_canvasPanelClose_8zc2t_1122`,canvasFrame:`_canvasFrame_8zc2t_1133`,pipelineLiveTag:`_pipelineLiveTag_8zc2t_1141`,liveTagBlink:`_liveTagBlink_8zc2t_1`,reasonRow:`_reasonRow_8zc2t_1155`,reasonChip:`_reasonChip_8zc2t_1164`,reasonIcon:`_reasonIcon_8zc2t_1177`,reasonText:`_reasonText_8zc2t_1178`,liveBlockReason:`_liveBlockReason_8zc2t_1181`,councilWrapper:`_councilWrapper_8zc2t_1191`,councilPanel:`_councilPanel_8zc2t_1196`,councilHeader:`_councilHeader_8zc2t_1204`,councilHeaderLeft:`_councilHeaderLeft_8zc2t_1215`,councilHeaderRight:`_councilHeaderRight_8zc2t_1221`,councilIcon:`_councilIcon_8zc2t_1227`,councilTitle:`_councilTitle_8zc2t_1229`,councilConvergedBadge:`_councilConvergedBadge_8zc2t_1238`,councilDivergedBadge:`_councilDivergedBadge_8zc2t_1250`,councilPhaseTag:`_councilPhaseTag_8zc2t_1262`,councilPhaseActive:`_councilPhaseActive_8zc2t_1268`,phaseGlow:`_phaseGlow_8zc2t_1`,councilPhaseDone:`_councilPhaseDone_8zc2t_1277`,councilMetrics:`_councilMetrics_8zc2t_1280`,convRow:`_convRow_8zc2t_1288`,convLabel:`_convLabel_8zc2t_1294`,convTrack:`_convTrack_8zc2t_1302`,convFill:`_convFill_8zc2t_1310`,convPct:`_convPct_8zc2t_1316`,councilNodes:`_councilNodes_8zc2t_1326`,councilSectionTitle:`_councilSectionTitle_8zc2t_1331`,councilNode:`_councilNode_8zc2t_1326`,councilNodeHeader:`_councilNodeHeader_8zc2t_1348`,councilNodeIcon:`_councilNodeIcon_8zc2t_1361`,councilNodeLabel:`_councilNodeLabel_8zc2t_1362`,councilNodeToggle:`_councilNodeToggle_8zc2t_1363`,councilNodeBody:`_councilNodeBody_8zc2t_1365`,councilSynthesis:`_councilSynthesis_8zc2t_1375`,councilSynthesisHeader:`_councilSynthesisHeader_8zc2t_1379`,heraldIcon:`_heraldIcon_8zc2t_1388`,heraldLabel:`_heraldLabel_8zc2t_1390`,heraldStreaming:`_heraldStreaming_8zc2t_1398`,councilSynthesisBody:`_councilSynthesisBody_8zc2t_1400`,councilSkipped:`_councilSkipped_8zc2t_1430`,councilSkipIcon:`_councilSkipIcon_8zc2t_1441`,charSpriteRunning:`_charSpriteRunning_8zc2t_1454`,spriteWalk:`_spriteWalk_8zc2t_1`,charSpriteDone:`_charSpriteDone_8zc2t_1463`,charScanline:`_charScanline_8zc2t_1467`,scanlineScroll:`_scanlineScroll_8zc2t_1`,auraAnim:`_auraAnim_8zc2t_1487`,auraGlow:`_auraGlow_8zc2t_1`,parliamentPrompt:`_parliamentPrompt_8zc2t_1494`,parliamentPromptIcon:`_parliamentPromptIcon_8zc2t_1504`,parliamentPromptContent:`_parliamentPromptContent_8zc2t_1505`,parliamentPromptTitle:`_parliamentPromptTitle_8zc2t_1506`,parliamentPromptDesc:`_parliamentPromptDesc_8zc2t_1507`,parliamentPromptMeta:`_parliamentPromptMeta_8zc2t_1508`,parliamentPromptBtns:`_parliamentPromptBtns_8zc2t_1509`,parliamentActivateBtn:`_parliamentActivateBtn_8zc2t_1510`,parliamentSkipBtn:`_parliamentSkipBtn_8zc2t_1517`,panelTabs:`_panelTabs_8zc2t_1525`,panelTabBtn:`_panelTabBtn_8zc2t_1526`,panelTabActive:`_panelTabActive_8zc2t_1533`,panelEmpty:`_panelEmpty_8zc2t_1535`,browserPanel:`_browserPanel_8zc2t_1544`,browserBar:`_browserBar_8zc2t_1545`,browserInput:`_browserInput_8zc2t_1546`,browserGo:`_browserGo_8zc2t_1553`},_e=[{label:`📈 Full Trading Strategy`,task:`You are a team of senior quantitative analysts and macro traders. Build a complete, actionable trading strategy with the following structure:
18
18
 
19
19
  1. MACRO REGIME ANALYSIS
20
20
  - Current macro cycle phase (expansion/peak/contraction/trough) with supporting indicators (yield curve, PMI, CPI trajectory, Fed/ECB policy stance)
@@ -226,7 +226,7 @@ Provide specific, actionable levels. Use technical analysis (EMA, RSI, MACD, Fib
226
226
  - Maximum drawdown and recovery expectations
227
227
  - Strategy capacity (AUM limits before alpha decay)
228
228
  - Implementation costs: slippage, market impact, transaction costs
229
- - Key risks: overfitting, regime change, crowding`,agents:[{icon:`📊`,agent:`oracle`,label:`Oracle`,status:`waiting`,output:``},{icon:`💹`,agent:`mercury`,label:`Mercury`,status:`waiting`,output:``},{icon:`📈`,agent:`edi`,label:`Edi`,status:`waiting`,output:``},{icon:`⚠️`,agent:`cassandra`,label:`Cassandra`,status:`waiting`,output:``},{icon:`🔥`,agent:`prometheus`,label:`Prometheus`,status:`waiting`,output:``}]}],ve=`trading strategy.fundamental analysis.portfolio risk.sector deep dive.crypto analysis.quant factor.macro regime.cross-asset.hedge.derivative.yield curve.market_price.market_chart.market_indicators.macro_data.crypto_data.valuation.equity.earnings.dividend.short interest.volatility.options.futures.bitcoin.ethereum`.split(`.`),ye=[`Analyze my unread emails and create a priority action plan`,`Search the web for AI news today and summarize it in a canvas report`,`Check my calendar for this week and suggest how to optimize my schedule`,`Review my GitHub notifications and draft responses to open issues`,`Search for information about a topic, fact-check it, and write a report`],R={bg:`#0a0d14`,wall:`#0d1117`,wallStripe:`#0f1520`,baseboard:`#1e293b`,floorA:`#111827`,floorB:`#141c2b`,floorLine:`#1e293b`,ceiling:`#0b0f18`,lampBody:`#854d0e`,lampGlow:`#fef08a`,partition:`#1a2436`,partitionH:`#253347`,partitionT:`#2d4a6e`,deskTop:`#2d4263`,deskFace:`#1e3352`,deskSide:`#192b43`,deskLeg:`#0f1e30`,monBody:`#0f172a`,monFace:`#162032`,monScrIdle:`#060b12`,monScrOn:`#001208`,monScrDone:`#001a08`,monStand:`#0d1625`,keyboard:`#162032`,chairBack:`#1a3a5c`,chairSeat:`#1e4068`,chairLeg:`#0f1e30`,plant1:`#14532d`,plant2:`#166534`,pot:`#78350f`,cup:`#7c2d12`,skin:[`#f5c97a`,`#fbbf24`,`#fca5a5`,`#86efac`,`#a5f3fc`,`#c4b5fd`,`#fde68a`,`#f9a8d4`,`#d8b4fe`],shirt:[`#1e40af`,`#065f46`,`#312e81`,`#0f172a`,`#be123c`,`#164e63`,`#7c3aed`,`#7f1d1d`,`#0e7490`],hair:[`#7c3aed`,`#92400e`,`#1e293b`,`#6b21a8`,`#78350f`,`#292524`,`#422006`,`#0c4a6e`,`#1c1917`],pants:`#1e293b`,shoes:`#0f172a`,cSkin:`#fbbf24`,cShirt:`#4f46e5`,cHair:`#111827`,cTie:`#dc2626`,cPants:`#1e293b`,cShoes:`#0f172a`,cBag:`#78350f`,green:`#22c55e`,greenDim:`#14532d`,cyan:`#67e8f9`,purple:`#a78bfa`,red:`#ef4444`,amber:`#fbbf24`,dim:`#334155`,white:`#f1f5f9`,paper:`#e2e8f0`,paperLine:`#94a3b8`,bubbleBg:`#0f172a`,bubbleBdr:`#334155`,bubbleText:`#67e8f9`,bubbleRun:`#22c55e`},z=2,be=800,xe=240,Se=be*z,Ce=xe*z,we=190,Te=82,Ee=20,De=we-Ee-2,Oe=14;function B(e,t,n,r,i=1,a=1){e.fillStyle=t,e.fillRect(n*z,r*z,i*z,a*z)}function ke(e){B(e,R.ceiling,0,0,be,8);for(let t=0;t<be;t++)B(e,t%16<8?R.wall:R.wallStripe,t,8,1,we-8);B(e,R.baseboard,0,we-3,be,3);for(let t=0;t<be;t+=14)for(let n=we;n<xe;n+=7)B(e,(Math.floor(t/14)+Math.floor((n-we)/7))%2==0?R.floorA:R.floorB,t,n,14,7),B(e,R.floorLine,t,n,14,1),B(e,R.floorLine,t,n,1,7);for(let t=30;t<be;t+=90){B(e,R.lampBody,t,1,32,4),B(e,R.lampGlow,t+2,2,28,2);for(let n=0;n<18;n++)e.fillStyle=`rgba(254,240,138,${.055-n*.003})`,e.fillRect((t+16-n*1.1)*z,(5+n)*z,n*2.2*z,z)}let t=be-24;B(e,R.monBody,t-8,14,16,16),B(e,`#e2e8f0`,t-6,16,12,12),B(e,R.monBody,t-1,17,2,5),B(e,R.red,t,18,1,5),B(e,R.monBody,t,22,1,1)}function Ae(e,t,n,r){let i=t.x,a=t.status===`running`,o=t.status===`done`,s=t.status===`error`,c=Math.abs(n-(i+Te/2))<24;a&&(e.fillStyle=`rgba(99,102,241,0.07)`,e.fillRect(i*z,8*z,Te*z,(xe-8)*z)),o&&(e.fillStyle=`rgba(34,197,94,0.04)`,e.fillRect(i*z,8*z,Te*z,(xe-8)*z)),B(e,R.partition,i,10,3,we-10),B(e,R.partitionH,i+2,10,1,we-10),B(e,R.partition,i+Te,10,3,we-10),B(e,a?R.partitionT:o?`#1a3a2e`:s?`#3a1a1a`:R.partitionH,i,10,Te+3,4),B(e,`#0f172a`,i+5,15,18,12),B(e,`#162032`,i+6,16,16,3),a?(B(e,R.green,i+6,20,12,1),B(e,R.greenDim,i+6,22,16,1),B(e,R.greenDim,i+6,24,10,1)):o?(B(e,R.green,i+6,19,16,1),B(e,R.green,i+6,21,12,1),B(e,R.green,i+6,23,14,1)):(B(e,R.dim,i+6,19,14,1),B(e,R.dim,i+6,22,10,1));let l=i+Te-14;B(e,R.pot,l+2,De+Ee-6,8,6),B(e,R.plant1,l,De+Ee-14,12,8),B(e,R.plant2,l+2,De+Ee-17,8,5),B(e,R.plant2,l-2,De+Ee-12,5,4),B(e,R.plant2,l+8,De+Ee-13,5,4),B(e,R.deskTop,i+3,De,Te-5,3),B(e,R.deskFace,i+3,De+3,Te-5,Ee-3),B(e,R.deskSide,i+3,De+Ee,Te-5,3),B(e,R.deskLeg,i+7,De+Ee+3,4,we-De-Ee-3),B(e,R.deskLeg,i+Te-9,De+Ee+3,4,we-De-Ee-3);let u=i+14,d=De-22;if(B(e,R.monBody,u,d,28,18),B(e,R.monFace,u+1,d+1,26,16),B(e,a?R.monScrOn:o?R.monScrDone:R.monScrIdle,u+2,d+2,24,12),a){for(let t=0;t<5;t++){let n=4+Math.floor((r/100+t*5)%18);B(e,R.green,u+3,d+3+t*2,n,1),B(e,R.greenDim,u+3+n,d+3+t*2,18-n,1)}Math.floor(r/400)%2==0&&B(e,R.green,u+3,d+13,2,1)}else o?(B(e,R.green,u+4,d+4,18,1),B(e,R.green,u+4,d+6,14,1),B(e,R.green,u+4,d+8,16,1),B(e,R.green,u+4,d+10,10,1),B(e,R.green,u+18,d+5,2,4),B(e,R.green,u+16,d+7,2,2),B(e,R.green,u+14,d+9,2,2)):s?(B(e,R.red,u+10,d+3,4,8),B(e,R.red,u+10,d+12,4,2)):(B(e,R.dim,u+4,d+5,16,1),B(e,R.dim,u+4,d+8,10,1),B(e,R.dim,u+4,d+11,14,1));B(e,R.monStand,u+11,d+18,6,3),B(e,R.monStand,u+8,d+21,12,2),B(e,R.keyboard,u-2,De+1,18,4);for(let t=0;t<5;t++)B(e,R.monFace,u-1+t*3,De+2,2,2);B(e,R.cup,i+6,De+2,5,6),B(e,`#92400e`,i+7,De+1,3,1),B(e,R.paper,i+36,De+2,10,7),B(e,R.paper,i+37,De+1,10,7),B(e,R.paperLine,i+38,De+3,7,1),B(e,R.paperLine,i+38,De+5,5,1),B(e,R.chairBack,i+18,we-24,24,3),B(e,R.chairSeat,i+16,we-16,28,10),B(e,R.chairLeg,i+20,we-6,4,8),B(e,R.chairLeg,i+36,we-6,4,8),je(e,t,i+Te/2-3,we-26,a,c,r);let f=a?R.cyan:o?R.green:s?R.red:R.dim;e.font=`bold ${4.5*z}px "Courier New", monospace`,e.fillStyle=f,e.textBaseline=`alphabetic`;let p=t.label.length>10?t.label.slice(0,9)+`…`:t.label;e.fillText(p,(i+4)*z,9*z),B(e,f,i+Te-4,11,4,4),a&&Math.floor(r/300)%2==0&&B(e,R.white,i+Te-3,12,2,2)}function je(e,t,n,r,i,a,o){let s=R.skin[t.skinIdx],c=R.shirt[t.shirtIdx],l=R.hair[t.hairIdx];if(a&&i){B(e,l,n-1,r,8,3),B(e,s,n,r+3,6,5),B(e,`#0f172a`,n+1,r+5,2,1),B(e,`#0f172a`,n+4,r+5,2,1),B(e,c,n-2,r+8,10,8),B(e,s,n-4,r+9,4,4),B(e,s,n+8,r+9,4,4),B(e,R.pants,n,r+16,3,6),B(e,R.pants,n+3,r+16,3,6),B(e,R.shoes,n-1,r+22,4,2),B(e,R.shoes,n+3,r+22,4,2),Me(e,t.icon,n+1,r+9);return}let u=i?Math.floor(o/800)%2:0;if(B(e,l,n-1,r+u,8,3),B(e,s,n,r+3+u,6,4),B(e,c,n-3,r+7,12,7),Me(e,t.icon,n,r+9),i){let t=Math.floor(o/130)%2;B(e,s,n-5,r+10+t,5,3),B(e,s,n+7,r+10+(1-t),5,3)}else B(e,s,n-5,r+11,5,3),B(e,s,n+7,r+11,5,3)}function Me(e,t,n,r){e.fillStyle=`#f1f5f9`,e.beginPath(),e.arc((n+9)*z,(r+2)*z,5*z,0,Math.PI*2),e.fill(),e.fillStyle=`#e2e8f0`,e.beginPath(),e.arc((n+9)*z,(r+2)*z,4*z,0,Math.PI*2),e.fill(),e.font=`${5*z}px serif`,e.textBaseline=`middle`,e.fillText(t,(n+6)*z,(r+3)*z)}function Ne(e){e.papers.length>=6||e.papers.push({x:e.x+10+Math.random()*(Te-20),y:De-2,vx:(Math.random()-.5)*1.2,vy:-1.2-Math.random()*.8,rot:Math.random()*360,vrot:(Math.random()-.5)*8,life:0,maxLife:60+Math.random()*40})}function Pe(e){e.papers=e.papers.filter(e=>e.life<e.maxLife);for(let t of e.papers)t.x+=t.vx,t.y+=t.vy,t.vy+=.05,t.rot+=t.vrot,t.life++}function Fe(e,t){for(let n of t.papers){let t=1-n.life/n.maxLife;e.save(),e.globalAlpha=t,e.translate(n.x*z,n.y*z),e.rotate(n.rot*Math.PI/180),e.fillStyle=R.paper,e.fillRect(-5*z,-3*z,10*z,7*z),e.fillStyle=R.paperLine,e.fillRect(-3*z,-1*z,6*z,z),e.fillRect(-3*z,z,4*z,z),e.restore()}e.globalAlpha=1}var Ie=`ABCDEFGHIJKLMNOPRSTUVWXYZ0123456789!?-_.:`;function Le(e,t){return t<=0?e:Ie[Math.floor(Math.random()*41)]??e}function Re(e,t,n,r,i,a=80,o=`down`){if(t.length===0)return;e.fillStyle=R.bubbleBg,e.fillRect(r*z,i*z,a*z,28*z),e.strokeStyle=R.bubbleBdr,e.lineWidth=z,e.strokeRect(r*z,i*z,a*z,28*z),e.fillStyle=R.cyan,e.fillRect(r*z,i*z,a*z,z),e.fillStyle=R.bubbleBdr,e.fillRect(r*z,(i+10+4)*z,a*z,z);for(let o=0;o<2;o++){let s=t[(Math.floor(n)+o)%t.length];if(!s)continue;let c=i+4+o*11;e.fillStyle=o%2==0?`#0f172a`:`#111827`,e.fillRect(r*z,c*z,a*z,10*z);let l=n-Math.floor(n),u=s.text.split(``);e.font=`bold ${5*z}px "Courier New", monospace`,e.textBaseline=`middle`;for(let t=0;t<Math.min(u.length,Math.floor(a/6)-1);t++){let n=l>.3&&t>u.length*(1-l)?Le(u[t],3):u[t];e.globalAlpha=l>0&&t>u.length*(1-l)?.5+l*.5:1,e.fillStyle=s.color,e.fillText(n,(r+4+t*6)*z,(c+5)*z)}e.globalAlpha=1}let s=r+a/2;if(o===`down`){let t=i+28;e.fillStyle=R.bubbleBdr,e.fillRect((s-1)*z,t*z,2*z,3*z),e.fillRect((s-2)*z,(t+3)*z,4*z,2*z)}else e.fillStyle=R.bubbleBdr,e.fillRect((s-1)*z,(i-3)*z,2*z,3*z),e.fillRect((s-2)*z,(i-5)*z,4*z,2*z)}function ze(e,t,n,r){let i=we-36,a=n%2;e.fillStyle=`rgba(0,0,0,0.4)`,e.beginPath(),e.ellipse((t+5)*z,(we-1)*z,10*z,2*z,0,0,Math.PI*2),e.fill(),e.save(),e.translate((t+5)*z,0),e.scale(r?1:-1,1),B(e,R.cHair,-5,i,12,3),B(e,R.cHair,-6,i+1,14,3),B(e,R.cSkin,-4,i+3,10,6),B(e,`#0f172a`,-2,i+5,2,2),B(e,`#0f172a`,2,i+5,2,2),B(e,R.cHair,-3,i+4,3,1),B(e,R.cHair,1,i+4,3,1),B(e,`#7f1d1d`,-1,i+8,4,1),B(e,R.cShirt,-6,i+9,14,10),B(e,`#3730a3`,-6,i+9,4,5),B(e,`#3730a3`,4,i+9,4,5),B(e,R.cTie,-1,i+9,4,8),B(e,`#f1f5f9`,-2,i+9,2,3),B(e,`#f1f5f9`,2,i+9,2,3),B(e,R.cShirt,-8,i+10,4,6),B(e,R.cShirt,6,i+10,4,6),B(e,R.cSkin,-8,i+16,4,2),B(e,R.cSkin,6,i+16,4,2),B(e,R.cBag,6,i+18,7,5),B(e,`#92400e`,7,i+17,5,1),B(e,`#d97706`,8,i+20,3,1),B(e,R.cPants,-4,i+19,5,8),B(e,R.cPants,1,i+19,5,8);let o=a===0?3:0,s=a===0?0:3;B(e,R.cPants,-4,i+19+o,4,6),B(e,R.cPants,2,i+19+s,4,6),B(e,R.cShoes,-5,i+25+o,6,2),B(e,R.cShoes,1,i+25+s,6,2),e.restore()}var Be=[[{text:`RUNNING WORKFLOW`,color:R.cyan},{text:`DISPATCHING...`,color:R.amber}],[{text:`ORCHESTRATING`,color:R.cyan},{text:`ALL SYSTEMS GO`,color:R.green}],[{text:`AGENT PIPELINE`,color:R.purple},{text:`EXECUTING...`,color:R.cyan}]];function Ve(e,t){return t===`running`?[{text:e.toUpperCase().slice(0,12),color:R.cyan},{text:`WORKING...`,color:R.green}]:t===`done`?[{text:e.toUpperCase().slice(0,12),color:R.green},{text:`TASK COMPLETE`,color:R.green}]:t===`error`?[{text:e.toUpperCase().slice(0,12),color:R.red},{text:`ERROR`,color:R.red}]:[{text:e.toUpperCase().slice(0,12),color:R.dim},{text:`STANDBY`,color:R.dim}]}function He({nodes:e,running:t}){let n=(0,_.useRef)(null),r=(0,_.useRef)(null);return(0,_.useEffect)(()=>{if(e.length===0)return;let t=Math.min(e.length,8)*(Te+Oe)-Oe,n=Math.max(4,(be-t)/2);if(!r.current)r.current={agents:e.slice(0,8).map((e,t)=>({x:n+t*(Te+Oe),icon:e.icon,label:e.label,status:e.status,skinIdx:t%R.skin.length,shirtIdx:t%R.shirt.length,hairIdx:t%R.hair.length,papers:[],bubbleLines:Ve(e.label,e.status),bubbleScroll:0,bubbleTimer:0})),condX:n+Te/2-5,condTargetX:n+Te/2-5,condFacing:!0,condFrame:0,condFrameTimer:0,condIdleTimer:0,condBubble:Be[0],condBubbleScroll:0,condBubbleTimer:0,rafId:0};else{let t=r.current;for(let r=0;r<Math.min(e.length,8);r++){let i=e[r],a=t.agents[r];a?(a.status!==i.status&&(a.status=i.status,a.bubbleLines=Ve(i.label,i.status),a.bubbleScroll=0),a.icon=i.icon,a.label=i.label):t.agents.push({x:n+r*(Te+Oe),icon:i.icon,label:i.label,status:i.status,skinIdx:r%R.skin.length,shirtIdx:r%R.shirt.length,hairIdx:r%R.hair.length,papers:[],bubbleLines:Ve(i.label,i.status),bubbleScroll:0,bubbleTimer:0})}}},[e]),(0,_.useEffect)(()=>{let e=n.current;if(!e)return;let i=e.getContext(`2d`);if(!i||(i.imageSmoothingEnabled=!1,!r.current))return;let a=0,o=0;function s(e){let n=r.current,c=Math.min(e-a,50);a=e;let l=e,u=n.agents.find(e=>e.status===`running`);if(u)n.condTargetX=u.x+Te/2-5,n.condBubbleTimer+=c,n.condBubbleTimer>2200&&(n.condBubbleTimer=0,n.condBubble=Be[Math.floor(Math.random()*Be.length)],n.condBubbleScroll=(n.condBubbleScroll+1)%4);else if(n.condIdleTimer-=c,n.condIdleTimer<=0){let e=n.agents[Math.floor(Math.random()*n.agents.length)];e&&(n.condTargetX=e.x+Te/2-5),n.condIdleTimer=2500+Math.random()*2500}let d=n.condTargetX-n.condX;if(Math.abs(d)>1&&(n.condX+=d*(t?.1:.035)*(c/16),n.condFacing=d>0,n.condFrameTimer+=c,n.condFrameTimer>110&&(n.condFrame++,n.condFrameTimer=0)),o+=c,o>220){o=0;for(let e of n.agents)e.status===`running`&&Ne(e)}for(let e of n.agents)Pe(e);for(let e of n.agents)e.bubbleTimer+=c,e.bubbleTimer>1800&&(e.bubbleTimer=0,e.bubbleScroll=(e.bubbleScroll+1)%4);i.clearRect(0,0,Se,Ce),ke(i);for(let e of n.agents)Ae(i,e,n.condX,l),Fe(i,e);ze(i,n.condX,n.condFrame,n.condFacing);for(let e of n.agents){let t=Math.min(e.label.length*6+16,82),n=Math.max(e.x,Math.min(e.x+(Te-t)/2,be-t-2));Re(i,e.bubbleLines,e.bubbleScroll,n,28,t,`down`)}if(u||n.condBubble.length>0){let e=Math.max(2,Math.min(n.condX-30,be-84));Re(i,n.condBubble,n.condBubbleScroll,e,we-66,82,`down`)}for(let e=0;e<Ce;e+=z*3)i.fillStyle=`rgba(0,0,0,0.06)`,i.fillRect(0,e,Se,z);n.rafId=requestAnimationFrame(s)}return r.current.rafId=requestAnimationFrame(s),()=>{r.current&&cancelAnimationFrame(r.current.rafId)}},[t]),e.length===0?null:(0,k.jsx)(`div`,{style:{display:`flex`,justifyContent:`center`,width:`100%`},children:(0,k.jsx)(`canvas`,{ref:n,width:Se,height:Ce,style:{width:`100%`,maxWidth:be,height:`auto`,imageRendering:`pixelated`,display:`block`,borderRadius:8,border:`1px solid #1e293b`,background:R.bg,boxShadow:`0 0 40px rgba(99,102,241,0.18), inset 0 0 80px rgba(0,0,0,0.5)`}})})}function Ue(e){let t=e.toLowerCase();return ve.some(e=>t.includes(e.toLowerCase()))}function We(e,t){let n=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`),r=t.map(e=>e.output).join(`
229
+ - Key risks: overfitting, regime change, crowding`,agents:[{icon:`📊`,agent:`oracle`,label:`Oracle`,status:`waiting`,output:``},{icon:`💹`,agent:`mercury`,label:`Mercury`,status:`waiting`,output:``},{icon:`📈`,agent:`edi`,label:`Edi`,status:`waiting`,output:``},{icon:`⚠️`,agent:`cassandra`,label:`Cassandra`,status:`waiting`,output:``},{icon:`🔥`,agent:`prometheus`,label:`Prometheus`,status:`waiting`,output:``}]}],ve=`trading strategy.fundamental analysis.portfolio risk.sector deep dive.crypto analysis.quant factor.macro regime.cross-asset.hedge.derivative.yield curve.market_price.market_chart.market_indicators.macro_data.crypto_data.valuation.equity.earnings.dividend.short interest.volatility.options.futures.bitcoin.ethereum`.split(`.`),ye=[`Analyze my unread emails and create a priority action plan`,`Search the web for AI news today and summarize it in a canvas report`,`Check my calendar for this week and suggest how to optimize my schedule`,`Review my GitHub notifications and draft responses to open issues`,`Search for information about a topic, fact-check it, and write a report`],R={bg:`#0a0d14`,wall:`#0d1117`,wallStripe:`#0f1520`,baseboard:`#1e293b`,floorA:`#111827`,floorB:`#141c2b`,floorLine:`#1e293b`,ceiling:`#0b0f18`,lampBody:`#854d0e`,lampGlow:`#fef08a`,partition:`#1a2436`,partitionH:`#253347`,partitionT:`#2d4a6e`,deskTop:`#2d4263`,deskFace:`#1e3352`,deskSide:`#192b43`,deskLeg:`#0f1e30`,monBody:`#0f172a`,monFace:`#162032`,monScrIdle:`#060b12`,monScrOn:`#001208`,monScrDone:`#001a08`,monStand:`#0d1625`,keyboard:`#162032`,chairBack:`#1a3a5c`,chairSeat:`#1e4068`,chairLeg:`#0f1e30`,plant1:`#14532d`,plant2:`#166534`,pot:`#78350f`,cup:`#7c2d12`,skin:[`#f5c97a`,`#fbbf24`,`#fca5a5`,`#86efac`,`#a5f3fc`,`#c4b5fd`,`#fde68a`,`#f9a8d4`,`#d8b4fe`],shirt:[`#1e40af`,`#065f46`,`#312e81`,`#0f172a`,`#be123c`,`#164e63`,`#7c3aed`,`#7f1d1d`,`#0e7490`],hair:[`#7c3aed`,`#92400e`,`#1e293b`,`#6b21a8`,`#78350f`,`#292524`,`#422006`,`#0c4a6e`,`#1c1917`],pants:`#1e293b`,shoes:`#0f172a`,cSkin:`#fbbf24`,cShirt:`#4f46e5`,cHair:`#111827`,cTie:`#dc2626`,cPants:`#1e293b`,cShoes:`#0f172a`,cBag:`#78350f`,green:`#22c55e`,greenDim:`#14532d`,cyan:`#67e8f9`,purple:`#a78bfa`,red:`#ef4444`,amber:`#fbbf24`,dim:`#334155`,white:`#f1f5f9`,paper:`#e2e8f0`,paperLine:`#94a3b8`,bubbleBg:`#0f172a`,bubbleBdr:`#334155`,bubbleText:`#67e8f9`,bubbleRun:`#22c55e`},z=2,be=1200,xe=320,Se=be*z,Ce=xe*z,we=260,Te=96,Ee=22,De=we-Ee-2,Oe=16;function B(e,t,n,r,i=1,a=1){e.fillStyle=t,e.fillRect(n*z,r*z,i*z,a*z)}function ke(e){B(e,R.ceiling,0,0,be,8);for(let t=0;t<be;t++)B(e,t%16<8?R.wall:R.wallStripe,t,8,1,we-8);B(e,R.baseboard,0,we-3,be,3);for(let t=0;t<be;t+=14)for(let n=we;n<xe;n+=7)B(e,(Math.floor(t/14)+Math.floor((n-we)/7))%2==0?R.floorA:R.floorB,t,n,14,7),B(e,R.floorLine,t,n,14,1),B(e,R.floorLine,t,n,1,7);for(let t=30;t<be;t+=90){B(e,R.lampBody,t,1,32,4),B(e,R.lampGlow,t+2,2,28,2);for(let n=0;n<18;n++)e.fillStyle=`rgba(254,240,138,${.055-n*.003})`,e.fillRect((t+16-n*1.1)*z,(5+n)*z,n*2.2*z,z)}let t=be-24;B(e,R.monBody,t-8,14,16,16),B(e,`#e2e8f0`,t-6,16,12,12),B(e,R.monBody,t-1,17,2,5),B(e,R.red,t,18,1,5),B(e,R.monBody,t,22,1,1)}function Ae(e,t,n,r){let i=t.x,a=t.status===`running`,o=t.status===`done`,s=t.status===`error`,c=Math.abs(n-(i+Te/2))<24;a&&(e.fillStyle=`rgba(99,102,241,0.07)`,e.fillRect(i*z,8*z,Te*z,(xe-8)*z)),o&&(e.fillStyle=`rgba(34,197,94,0.04)`,e.fillRect(i*z,8*z,Te*z,(xe-8)*z)),B(e,R.partition,i,10,3,we-10),B(e,R.partitionH,i+2,10,1,we-10),B(e,R.partition,i+Te,10,3,we-10),B(e,a?R.partitionT:o?`#1a3a2e`:s?`#3a1a1a`:R.partitionH,i,10,Te+3,4),B(e,`#0f172a`,i+5,15,18,12),B(e,`#162032`,i+6,16,16,3),a?(B(e,R.green,i+6,20,12,1),B(e,R.greenDim,i+6,22,16,1),B(e,R.greenDim,i+6,24,10,1)):o?(B(e,R.green,i+6,19,16,1),B(e,R.green,i+6,21,12,1),B(e,R.green,i+6,23,14,1)):(B(e,R.dim,i+6,19,14,1),B(e,R.dim,i+6,22,10,1));let l=i+Te-14;B(e,R.pot,l+2,De+Ee-6,8,6),B(e,R.plant1,l,De+Ee-14,12,8),B(e,R.plant2,l+2,De+Ee-17,8,5),B(e,R.plant2,l-2,De+Ee-12,5,4),B(e,R.plant2,l+8,De+Ee-13,5,4),B(e,R.deskTop,i+3,De,Te-5,3),B(e,R.deskFace,i+3,De+3,Te-5,Ee-3),B(e,R.deskSide,i+3,De+Ee,Te-5,3),B(e,R.deskLeg,i+7,De+Ee+3,4,we-De-Ee-3),B(e,R.deskLeg,i+Te-9,De+Ee+3,4,we-De-Ee-3);let u=i+14,d=De-22;if(B(e,R.monBody,u,d,28,18),B(e,R.monFace,u+1,d+1,26,16),B(e,a?R.monScrOn:o?R.monScrDone:R.monScrIdle,u+2,d+2,24,12),a){for(let t=0;t<5;t++){let n=4+Math.floor((r/100+t*5)%18);B(e,R.green,u+3,d+3+t*2,n,1),B(e,R.greenDim,u+3+n,d+3+t*2,18-n,1)}Math.floor(r/400)%2==0&&B(e,R.green,u+3,d+13,2,1)}else o?(B(e,R.green,u+4,d+4,18,1),B(e,R.green,u+4,d+6,14,1),B(e,R.green,u+4,d+8,16,1),B(e,R.green,u+4,d+10,10,1),B(e,R.green,u+18,d+5,2,4),B(e,R.green,u+16,d+7,2,2),B(e,R.green,u+14,d+9,2,2)):s?(B(e,R.red,u+10,d+3,4,8),B(e,R.red,u+10,d+12,4,2)):(B(e,R.dim,u+4,d+5,16,1),B(e,R.dim,u+4,d+8,10,1),B(e,R.dim,u+4,d+11,14,1));B(e,R.monStand,u+11,d+18,6,3),B(e,R.monStand,u+8,d+21,12,2),B(e,R.keyboard,u-2,De+1,18,4);for(let t=0;t<5;t++)B(e,R.monFace,u-1+t*3,De+2,2,2);B(e,R.cup,i+6,De+2,5,6),B(e,`#92400e`,i+7,De+1,3,1),B(e,R.paper,i+36,De+2,10,7),B(e,R.paper,i+37,De+1,10,7),B(e,R.paperLine,i+38,De+3,7,1),B(e,R.paperLine,i+38,De+5,5,1),B(e,R.chairBack,i+18,we-24,24,3),B(e,R.chairSeat,i+16,we-16,28,10),B(e,R.chairLeg,i+20,we-6,4,8),B(e,R.chairLeg,i+36,we-6,4,8),je(e,t,i+Te/2-3,we-26,a,c,r);let f=a?R.cyan:o?R.green:s?R.red:R.dim;e.font=`bold ${4.5*z}px "Courier New", monospace`,e.fillStyle=f,e.textBaseline=`alphabetic`;let p=t.label.length>10?t.label.slice(0,9)+`…`:t.label;e.fillText(p,(i+4)*z,9*z),B(e,f,i+Te-4,11,4,4),a&&Math.floor(r/300)%2==0&&B(e,R.white,i+Te-3,12,2,2)}function je(e,t,n,r,i,a,o){let s=R.skin[t.skinIdx],c=R.shirt[t.shirtIdx],l=R.hair[t.hairIdx];if(a&&i){B(e,l,n-1,r,8,3),B(e,s,n,r+3,6,5),B(e,`#0f172a`,n+1,r+5,2,1),B(e,`#0f172a`,n+4,r+5,2,1),B(e,c,n-2,r+8,10,8),B(e,s,n-4,r+9,4,4),B(e,s,n+8,r+9,4,4),B(e,R.pants,n,r+16,3,6),B(e,R.pants,n+3,r+16,3,6),B(e,R.shoes,n-1,r+22,4,2),B(e,R.shoes,n+3,r+22,4,2),Me(e,t.icon,n+1,r+9);return}let u=i?Math.floor(o/800)%2:0;if(B(e,l,n-1,r+u,8,3),B(e,s,n,r+3+u,6,4),B(e,c,n-3,r+7,12,7),Me(e,t.icon,n,r+9),i){let t=Math.floor(o/130)%2;B(e,s,n-5,r+10+t,5,3),B(e,s,n+7,r+10+(1-t),5,3)}else B(e,s,n-5,r+11,5,3),B(e,s,n+7,r+11,5,3)}function Me(e,t,n,r){e.fillStyle=`#f1f5f9`,e.beginPath(),e.arc((n+9)*z,(r+2)*z,5*z,0,Math.PI*2),e.fill(),e.fillStyle=`#e2e8f0`,e.beginPath(),e.arc((n+9)*z,(r+2)*z,4*z,0,Math.PI*2),e.fill(),e.font=`${5*z}px serif`,e.textBaseline=`middle`,e.fillText(t,(n+6)*z,(r+3)*z)}function Ne(e){e.papers.length>=6||e.papers.push({x:e.x+10+Math.random()*(Te-20),y:De-2,vx:(Math.random()-.5)*1.2,vy:-1.2-Math.random()*.8,rot:Math.random()*360,vrot:(Math.random()-.5)*8,life:0,maxLife:60+Math.random()*40})}function Pe(e){e.papers=e.papers.filter(e=>e.life<e.maxLife);for(let t of e.papers)t.x+=t.vx,t.y+=t.vy,t.vy+=.05,t.rot+=t.vrot,t.life++}function Fe(e,t){for(let n of t.papers){let t=1-n.life/n.maxLife;e.save(),e.globalAlpha=t,e.translate(n.x*z,n.y*z),e.rotate(n.rot*Math.PI/180),e.fillStyle=R.paper,e.fillRect(-5*z,-3*z,10*z,7*z),e.fillStyle=R.paperLine,e.fillRect(-3*z,-1*z,6*z,z),e.fillRect(-3*z,z,4*z,z),e.restore()}e.globalAlpha=1}var Ie=`ABCDEFGHIJKLMNOPRSTUVWXYZ0123456789!?-_.:`;function Le(e,t){return t<=0?e:Ie[Math.floor(Math.random()*41)]??e}function Re(e,t,n,r,i,a=80,o=`down`){if(t.length===0)return;e.fillStyle=R.bubbleBg,e.fillRect(r*z,i*z,a*z,28*z),e.strokeStyle=R.bubbleBdr,e.lineWidth=z,e.strokeRect(r*z,i*z,a*z,28*z),e.fillStyle=R.cyan,e.fillRect(r*z,i*z,a*z,z),e.fillStyle=R.bubbleBdr,e.fillRect(r*z,(i+10+4)*z,a*z,z);for(let o=0;o<2;o++){let s=t[(Math.floor(n)+o)%t.length];if(!s)continue;let c=i+4+o*11;e.fillStyle=o%2==0?`#0f172a`:`#111827`,e.fillRect(r*z,c*z,a*z,10*z);let l=n-Math.floor(n),u=s.text.split(``);e.font=`bold ${5*z}px "Courier New", monospace`,e.textBaseline=`middle`;for(let t=0;t<Math.min(u.length,Math.floor(a/6)-1);t++){let n=l>.3&&t>u.length*(1-l)?Le(u[t],3):u[t];e.globalAlpha=l>0&&t>u.length*(1-l)?.5+l*.5:1,e.fillStyle=s.color,e.fillText(n,(r+4+t*6)*z,(c+5)*z)}e.globalAlpha=1}let s=r+a/2;if(o===`down`){let t=i+28;e.fillStyle=R.bubbleBdr,e.fillRect((s-1)*z,t*z,2*z,3*z),e.fillRect((s-2)*z,(t+3)*z,4*z,2*z)}else e.fillStyle=R.bubbleBdr,e.fillRect((s-1)*z,(i-3)*z,2*z,3*z),e.fillRect((s-2)*z,(i-5)*z,4*z,2*z)}function ze(e,t,n,r){let i=we-36,a=n%2;e.fillStyle=`rgba(0,0,0,0.4)`,e.beginPath(),e.ellipse((t+5)*z,(we-1)*z,10*z,2*z,0,0,Math.PI*2),e.fill(),e.save(),e.translate((t+5)*z,0),e.scale(r?1:-1,1),B(e,R.cHair,-5,i,12,3),B(e,R.cHair,-6,i+1,14,3),B(e,R.cSkin,-4,i+3,10,6),B(e,`#0f172a`,-2,i+5,2,2),B(e,`#0f172a`,2,i+5,2,2),B(e,R.cHair,-3,i+4,3,1),B(e,R.cHair,1,i+4,3,1),B(e,`#7f1d1d`,-1,i+8,4,1),B(e,R.cShirt,-6,i+9,14,10),B(e,`#3730a3`,-6,i+9,4,5),B(e,`#3730a3`,4,i+9,4,5),B(e,R.cTie,-1,i+9,4,8),B(e,`#f1f5f9`,-2,i+9,2,3),B(e,`#f1f5f9`,2,i+9,2,3),B(e,R.cShirt,-8,i+10,4,6),B(e,R.cShirt,6,i+10,4,6),B(e,R.cSkin,-8,i+16,4,2),B(e,R.cSkin,6,i+16,4,2),B(e,R.cBag,6,i+18,7,5),B(e,`#92400e`,7,i+17,5,1),B(e,`#d97706`,8,i+20,3,1),B(e,R.cPants,-4,i+19,5,8),B(e,R.cPants,1,i+19,5,8);let o=a===0?3:0,s=a===0?0:3;B(e,R.cPants,-4,i+19+o,4,6),B(e,R.cPants,2,i+19+s,4,6),B(e,R.cShoes,-5,i+25+o,6,2),B(e,R.cShoes,1,i+25+s,6,2),e.restore()}var Be=[[{text:`RUNNING WORKFLOW`,color:R.cyan},{text:`DISPATCHING...`,color:R.amber}],[{text:`ORCHESTRATING`,color:R.cyan},{text:`ALL SYSTEMS GO`,color:R.green}],[{text:`AGENT PIPELINE`,color:R.purple},{text:`EXECUTING...`,color:R.cyan}]];function Ve(e,t){return t===`running`?[{text:e.toUpperCase().slice(0,12),color:R.cyan},{text:`WORKING...`,color:R.green}]:t===`done`?[{text:e.toUpperCase().slice(0,12),color:R.green},{text:`TASK COMPLETE`,color:R.green}]:t===`error`?[{text:e.toUpperCase().slice(0,12),color:R.red},{text:`ERROR`,color:R.red}]:[{text:e.toUpperCase().slice(0,12),color:R.dim},{text:`STANDBY`,color:R.dim}]}function He({nodes:e,running:t}){let n=(0,_.useRef)(null),r=(0,_.useRef)(null);return(0,_.useEffect)(()=>{if(e.length===0)return;let t=Math.min(e.length,8)*(Te+Oe)-Oe,n=Math.max(4,(be-t)/2);if(!r.current)r.current={agents:e.slice(0,8).map((e,t)=>({x:n+t*(Te+Oe),icon:e.icon,label:e.label,status:e.status,skinIdx:t%R.skin.length,shirtIdx:t%R.shirt.length,hairIdx:t%R.hair.length,papers:[],bubbleLines:Ve(e.label,e.status),bubbleScroll:0,bubbleTimer:0})),condX:n+Te/2-5,condTargetX:n+Te/2-5,condFacing:!0,condFrame:0,condFrameTimer:0,condIdleTimer:0,condBubble:Be[0],condBubbleScroll:0,condBubbleTimer:0,rafId:0};else{let t=r.current;for(let r=0;r<Math.min(e.length,8);r++){let i=e[r],a=t.agents[r];a?(a.status!==i.status&&(a.status=i.status,a.bubbleLines=Ve(i.label,i.status),a.bubbleScroll=0),a.icon=i.icon,a.label=i.label):t.agents.push({x:n+r*(Te+Oe),icon:i.icon,label:i.label,status:i.status,skinIdx:r%R.skin.length,shirtIdx:r%R.shirt.length,hairIdx:r%R.hair.length,papers:[],bubbleLines:Ve(i.label,i.status),bubbleScroll:0,bubbleTimer:0})}}},[e]),(0,_.useEffect)(()=>{let e=n.current;if(!e)return;let i=e.getContext(`2d`);if(!i||(i.imageSmoothingEnabled=!1,!r.current))return;let a=0,o=0;function s(e){let n=r.current,c=Math.min(e-a,50);a=e;let l=e,u=n.agents.find(e=>e.status===`running`);if(u)n.condTargetX=u.x+Te/2-5,n.condBubbleTimer+=c,n.condBubbleTimer>2200&&(n.condBubbleTimer=0,n.condBubble=Be[Math.floor(Math.random()*Be.length)],n.condBubbleScroll=(n.condBubbleScroll+1)%4);else if(n.condIdleTimer-=c,n.condIdleTimer<=0){let e=n.agents[Math.floor(Math.random()*n.agents.length)];e&&(n.condTargetX=e.x+Te/2-5),n.condIdleTimer=2500+Math.random()*2500}let d=n.condTargetX-n.condX;if(Math.abs(d)>1&&(n.condX+=d*(t?.1:.035)*(c/16),n.condFacing=d>0,n.condFrameTimer+=c,n.condFrameTimer>110&&(n.condFrame++,n.condFrameTimer=0)),o+=c,o>220){o=0;for(let e of n.agents)e.status===`running`&&Ne(e)}for(let e of n.agents)Pe(e);for(let e of n.agents)e.bubbleTimer+=c,e.bubbleTimer>1800&&(e.bubbleTimer=0,e.bubbleScroll=(e.bubbleScroll+1)%4);i.clearRect(0,0,Se,Ce),ke(i);for(let e of n.agents)Ae(i,e,n.condX,l),Fe(i,e);ze(i,n.condX,n.condFrame,n.condFacing);for(let e of n.agents){let t=Math.min(e.label.length*6+16,82),n=Math.max(e.x,Math.min(e.x+(Te-t)/2,be-t-2));Re(i,e.bubbleLines,e.bubbleScroll,n,28,t,`down`)}if(u||n.condBubble.length>0){let e=Math.max(2,Math.min(n.condX-30,be-84));Re(i,n.condBubble,n.condBubbleScroll,e,we-66,82,`down`)}for(let e=0;e<Ce;e+=z*3)i.fillStyle=`rgba(0,0,0,0.06)`,i.fillRect(0,e,Se,z);n.rafId=requestAnimationFrame(s)}return r.current.rafId=requestAnimationFrame(s),()=>{r.current&&cancelAnimationFrame(r.current.rafId)}},[t]),e.length===0?null:(0,k.jsx)(`div`,{style:{display:`flex`,justifyContent:`center`,width:`100%`},children:(0,k.jsx)(`canvas`,{ref:n,width:Se,height:Ce,style:{width:`100%`,maxWidth:`100%`,height:`auto`,imageRendering:`pixelated`,display:`block`,borderRadius:8,border:`1px solid #1e293b`,background:R.bg,boxShadow:`0 0 40px rgba(99,102,241,0.18), inset 0 0 80px rgba(0,0,0,0.5)`}})})}function Ue(e){let t=e.toLowerCase();return ve.some(e=>t.includes(e.toLowerCase()))}function We(e,t){let n=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`),r=t.map(e=>e.output).join(`
230
230
 
231
231
  `),i=/([+-]?\d+(?:\.\d+)?)\s*%/g,a=[],o;for(;(o=i.exec(r))!==null;){let e=parseFloat(o[1]);e>=-100&&e<=500&&a.push(e)}let s=t.filter(e=>e.output&&e.output!==`(no output)`).map(e=>{let t=n(e.output).replace(/\*\*(.*?)\*\*/g,`<strong>$1</strong>`).replace(/^(#{1,3})\s+(.+)$/gm,(e,t,n)=>{let r=Math.min(t.length+1,5);return`<h${r} class="sh${r}">${n}</h${r}>`}).replace(/\n/g,`<br>`);return`
232
232
  <div class="section">
@@ -458,7 +458,7 @@ ${l}
458
458
  ${e.map(e=>`<div class="section"><div class="agent-header"><span class="icon">${e.icon}</span><div class="agent-name">${e.label}</div></div><div class="section-body"><p>${r(e.output)}</p></div></div>`).join(``)}
459
459
  ${u}
460
460
  <div class="footer">NHA Studio · nothumanallowed.com · ${new Date().getFullYear()}</div>
461
- </body></html>`,f=new Blob([d],{type:`text/html`}),p=URL.createObjectURL(f),m=document.createElement(`a`);m.href=p,m.download=`nha-report-${Date.now()}.html`,m.click(),URL.revokeObjectURL(p);let h=window.open(``,`_blank`,`width=1100,height=800`);h&&(h.document.open(),h.document.write(d),h.document.close(),h.onload=()=>setTimeout(()=>{h.focus(),h.print()},600))},me=t=>{let n=`**Studio Workflow Result**\n\nTask: ${t.task}\n\nAgents: ${t.nodes.map(e=>e.label).join(` → `)}\n\n---\n\n${t.result}`;try{sessionStorage.setItem(`nha_studio_import`,n)}catch{}e(`chat`)},he=()=>{if(!u){r(``),a([]),s([]),l(``),S(``),se.current=``,w(null),M.current=null,te(!1),b({in:0,out:0}),v(null),re(!1);try{sessionStorage.removeItem(qe)}catch{}}},ge=i.some(e=>e.output||e.status===`running`);return(0,k.jsxs)(`div`,{className:L.root,children:[(0,k.jsxs)(`div`,{className:L.header,children:[(0,k.jsxs)(`div`,{className:L.headerLeft,children:[(0,k.jsx)(`div`,{className:L.title,children:`Studio`}),(0,k.jsx)(`div`,{className:L.subtitle,children:`Multi-agent orchestration · Parliament deliberation · Geth Consensus`})]}),(0,k.jsxs)(`div`,{className:L.headerActions,children:[y.in+y.out>0&&(0,k.jsxs)(`div`,{className:L.tokenBar,children:[(0,k.jsxs)(`span`,{className:L.tokIn,children:[`↑ `,y.in.toLocaleString()]}),(0,k.jsx)(`span`,{className:L.tokDim,children:` in `}),(0,k.jsxs)(`span`,{className:L.tokOut,children:[`↓ `,y.out.toLocaleString()]}),(0,k.jsx)(`span`,{className:L.tokDim,children:` out`})]}),(0,k.jsxs)(`button`,{className:L.sessionsBtn,onClick:()=>h(e=>!e),children:[`Sessions (`,f.length,`)`]}),x&&(0,k.jsx)(`button`,{className:L.canvasToggleBtn,onClick:()=>{re(!0),O(`canvas`)},children:`📊 Panel`}),c&&(0,k.jsx)(`button`,{className:L.pdfBtn,onClick:pe,children:`⬇ PDF / HTML`}),(i.length>0||c||o.length>0)&&!u&&(0,k.jsx)(`button`,{className:L.clearBtn,onClick:he,title:`Clear all — start fresh`,children:`✕ Clear`})]})]}),m&&(0,k.jsxs)(`div`,{className:L.sessionsDrawer,children:[f.length===0&&(0,k.jsx)(`div`,{className:L.noSessions,children:`No saved sessions yet.`}),f.map(e=>(0,k.jsxs)(`div`,{className:L.sessionItem,children:[(0,k.jsxs)(`div`,{className:L.sessionInfo,onClick:()=>de(e),children:[(0,k.jsx)(`div`,{className:L.sessionTask,children:e.task.slice(0,80)}),(0,k.jsxs)(`div`,{className:L.sessionMeta,children:[e.ts.slice(0,16),` · `,e.nodes.length,` agents`,e.council?.phase===`done`?` · 🏛️ Parliament`:``]})]}),(0,k.jsxs)(`div`,{className:L.sessionBtns,children:[(0,k.jsx)(`button`,{className:L.importBtn,onClick:()=>me(e),children:`→ Chat`}),(0,k.jsx)(`button`,{className:L.delSessionBtn,onClick:()=>I(e.id),children:`✕`})]})]},e.id))]}),(0,k.jsxs)(`div`,{className:L.inputArea,children:[(0,k.jsxs)(`div`,{className:L.inputRow,children:[(0,k.jsx)(`textarea`,{className:L.taskInput,value:n,onChange:e=>r(e.target.value),placeholder:`Describe your task… e.g. Analyze my emails and create a priority action plan`,rows:2,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),F())}}),(0,k.jsxs)(`div`,{className:L.inputControls,children:[u?(0,k.jsx)(`button`,{className:L.stopBtn,onClick:le,children:`■ Stop`}):(0,k.jsx)(`button`,{className:L.runBtn,onClick:F,disabled:!n.trim(),children:`Run ▶`}),(0,k.jsxs)(`label`,{className:L.attachBtn,title:`Attach PDF or image`,children:[`📎`,(0,k.jsx)(`input`,{type:`file`,accept:`.pdf,.png,.jpg,.jpeg,.gif,.webp`,style:{display:`none`},onChange:e=>P(e.target.files?.[0])})]})]})]}),g&&(0,k.jsxs)(`div`,{className:L.attachBadge,children:[`📎 `,g.name,(0,k.jsx)(`button`,{className:L.clearAttach,onClick:()=>v(null),children:`✕`})]}),!u&&i.length===0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:L.examples,children:ye.map((e,t)=>(0,k.jsx)(`button`,{className:L.exampleBtn,onClick:()=>r(e),children:e},t))}),(0,k.jsxs)(`div`,{className:L.financeSection,children:[(0,k.jsx)(`div`,{className:L.financeSectionTitle,children:`📈 Finance & Trading Workflows`}),(0,k.jsx)(`div`,{className:L.financePresets,children:_e.map((e,t)=>(0,k.jsx)(`button`,{className:L.financeBtn,onClick:()=>{r(e.task),a(e.agents)},children:e.label},t))})]})]})]}),(0,k.jsxs)(`div`,{className:L.body,children:[i.length>0&&(0,k.jsxs)(`div`,{className:`${L.pipeline} ${u?L.pipelineRunning:``}`,children:[(0,k.jsxs)(`div`,{className:L.pipelineTitle,children:[`Agent Pipeline`,u&&(0,k.jsx)(`span`,{className:L.pipelineLiveTag,children:`● LIVE`})]}),(0,k.jsx)(`div`,{className:L.pipelineNodes,children:i.map((e,t)=>(0,k.jsxs)(`div`,{className:L.pipelineStep,children:[(0,k.jsxs)(`div`,{className:`${L.agentChip} ${L[`chip_${e.status}`]}`,children:[(0,k.jsx)(`span`,{className:L.chipIcon,children:e.icon}),(0,k.jsx)(`span`,{className:L.chipLabel,children:e.label}),e.status===`running`&&(0,k.jsxs)(`span`,{className:L.chipDots,children:[(0,k.jsx)(`span`,{className:L.dot1,children:`.`}),(0,k.jsx)(`span`,{className:L.dot2,children:`.`}),(0,k.jsx)(`span`,{className:L.dot3,children:`.`})]}),e.status===`done`&&(0,k.jsx)(`span`,{className:L.chipCheck,children:`✓`}),e.status===`error`&&(0,k.jsx)(`span`,{className:L.chipErr,children:`✗`})]}),t<i.length-1&&(0,k.jsx)(`div`,{className:`${L.arrow} ${u?L.arrowActive:``}`,children:`→`})]},t))}),i.some(e=>e.reason)&&(0,k.jsx)(`div`,{className:L.reasonRow,children:i.map((e,t)=>e.reason?(0,k.jsxs)(`div`,{className:L.reasonChip,title:e.reason,children:[(0,k.jsx)(`span`,{className:L.reasonIcon,children:e.icon}),(0,k.jsxs)(`span`,{className:L.reasonText,children:[e.reason.slice(0,60),e.reason.length>60?`…`:``]})]},t):null)})]}),i.length>0&&(0,k.jsx)(`div`,{className:L.officeSceneWrap,children:(0,k.jsx)(He,{nodes:i,running:u})}),(o.length>0||ge)&&(0,k.jsxs)(`div`,{className:L.twoCol,children:[(0,k.jsxs)(`div`,{className:L.logPanel,children:[(0,k.jsx)(`div`,{className:L.panelTitle,children:`Live Log`}),(0,k.jsx)(`div`,{className:L.logBody,ref:oe,children:o.map((e,t)=>(0,k.jsxs)(`div`,{className:`${L.logEntry} ${L[`log_${e.type}`]}`,children:[(0,k.jsx)(`span`,{className:L.logTime,children:e.time}),(0,k.jsx)(`span`,{className:L.logIcon,children:e.icon}),(0,k.jsx)(`span`,{className:L.logAgent,children:e.agent}),(0,k.jsx)(`span`,{className:L.logText,children:e.text})]},t))})]}),(0,k.jsx)(`div`,{className:L.liveOutputPanel,children:i.filter(e=>e.output||e.status===`running`).map((e,t)=>(0,k.jsxs)(`div`,{className:`${L.liveBlock} ${e.status===`running`?L.liveBlockActive:``}`,children:[(0,k.jsxs)(`div`,{className:L.liveBlockHeader,children:[(0,k.jsx)(`span`,{className:L.liveBlockIcon,children:e.icon}),(0,k.jsx)(`span`,{className:L.liveBlockLabel,children:e.label}),e.reason&&(0,k.jsx)(`span`,{className:L.liveBlockReason,title:e.reason,children:`ℹ`}),(0,k.jsx)(`span`,{className:`${L.outputStatus} ${L[`status_${e.status}`]}`,children:e.status})]}),e.status===`running`&&!e.output&&(0,k.jsxs)(`div`,{className:L.liveBlockWorking,children:[(0,k.jsx)(`span`,{className:L.workingDot}),(0,k.jsx)(`span`,{className:L.workingDot}),(0,k.jsx)(`span`,{className:L.workingDot}),(0,k.jsx)(`span`,{className:L.workingLabel,children:`elaborazione in corso`})]}),(0,k.jsx)(`div`,{className:L.liveBlockBody,dangerouslySetInnerHTML:{__html:fe(e.output)+(e.status===`running`&&e.output?`<span class="studio-cursor"></span>`:``)}})]},t))})]}),ee&&(0,k.jsxs)(`div`,{className:L.parliamentPrompt,children:[(0,k.jsx)(`div`,{className:L.parliamentPromptIcon,children:`🏛️`}),(0,k.jsxs)(`div`,{className:L.parliamentPromptContent,children:[(0,k.jsx)(`div`,{className:L.parliamentPromptTitle,children:`Attivare il Consiglio?`}),(0,k.jsxs)(`div`,{className:L.parliamentPromptDesc,children:[T.length,` agenti (`,T.map(e=>e.label).join(`, `),`) hanno prodotto output. Il Geth Consensus eseguirà cross-reading, refinement e mediazione HERALD per raggiungere un consenso collettivo.`]}),(0,k.jsxs)(`div`,{className:L.parliamentPromptMeta,children:[`Complessità: `,T.length<=3?`⚡ Rapido (~30s)`:T.length<=5?`⏱ Medio (~60s)`:`🕐 Lungo (~2min)`,`\xA0· Consigliato per task analitici complessi`]})]}),(0,k.jsxs)(`div`,{className:L.parliamentPromptBtns,children:[(0,k.jsx)(`button`,{className:L.parliamentActivateBtn,onClick:ue,children:`🏛️ Attiva`}),(0,k.jsx)(`button`,{className:L.parliamentSkipBtn,onClick:()=>te(!1),children:`Salta`})]})]}),C&&!ee&&(0,k.jsx)(`div`,{className:L.councilWrapper,children:(0,k.jsx)(et,{council:C})}),c&&!u&&(0,k.jsxs)(`details`,{className:L.resultAccordion,open:i.length<=1,children:[(0,k.jsxs)(`summary`,{className:L.resultAccordionSummary,children:[`Full Combined Report (`,i.filter(e=>e.output&&e.output!==`(no output)`).length,` agents)`]}),(0,k.jsx)(`div`,{className:L.resultAccordionBody,dangerouslySetInnerHTML:{__html:fe(c)}})]})]}),D&&(0,k.jsxs)(`div`,{className:L.canvasPanel,children:[(0,k.jsxs)(`div`,{className:L.canvasPanelHeader,children:[(0,k.jsxs)(`div`,{className:L.panelTabs,children:[(0,k.jsx)(`button`,{className:`${L.panelTabBtn} ${ie===`canvas`?L.panelTabActive:``}`,onClick:()=>O(`canvas`),children:`📊 Canvas`}),(0,k.jsx)(`button`,{className:`${L.panelTabBtn} ${ie===`browser`?L.panelTabActive:``}`,onClick:()=>O(`browser`),children:`🌐 Browser`})]}),(0,k.jsxs)(`div`,{className:L.canvasPanelActions,children:[ie===`canvas`&&x&&(0,k.jsx)(`button`,{className:L.canvasPanelBtn,onClick:()=>{let e=new Blob([x],{type:`text/html`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`nha-canvas-report.html`,n.click(),URL.revokeObjectURL(t)},children:`⬇ HTML`}),(0,k.jsx)(`button`,{className:L.canvasPanelClose,onClick:()=>re(!1),children:`✕`})]})]}),ie===`canvas`?x?(0,k.jsx)(`iframe`,{className:L.canvasFrame,srcDoc:x,sandbox:`allow-scripts`,title:`Canvas Report`}):(0,k.jsx)(`div`,{className:L.panelEmpty,children:`No canvas report yet. Run a workflow first.`}):(0,k.jsxs)(`div`,{className:L.browserPanel,children:[(0,k.jsxs)(`div`,{className:L.browserBar,children:[(0,k.jsx)(`input`,{className:L.browserInput,value:ae,onChange:e=>A(e.target.value),placeholder:`https://…`,onKeyDown:e=>{e.key===`Enter`&&A(ae)}}),(0,k.jsx)(`button`,{className:L.browserGo,onClick:()=>A(ae),children:`Go`})]}),ae?(0,k.jsx)(`iframe`,{className:L.canvasFrame,src:ae,sandbox:`allow-scripts allow-same-origin allow-forms`,title:`Browser`}):(0,k.jsx)(`div`,{className:L.panelEmpty,children:`Enter a URL above to browse`})]})]})]})}var V={root:`_root_13wnr_2`,hero:`_hero_13wnr_12`,heroLeft:`_heroLeft_13wnr_21`,heroDate:`_heroDate_13wnr_22`,heroTitle:`_heroTitle_13wnr_23`,heroVer:`_heroVer_13wnr_24`,heroUptime:`_heroUptime_13wnr_25`,heroWeather:`_heroWeather_13wnr_27`,wIcon:`_wIcon_13wnr_35`,wInfo:`_wInfo_13wnr_36`,wTemp:`_wTemp_13wnr_37`,wCity:`_wCity_13wnr_38`,wDesc:`_wDesc_13wnr_39`,wEmpty:`_wEmpty_13wnr_40`,kpiRow:`_kpiRow_13wnr_43`,kpi:`_kpi_13wnr_43`,kpiNum:`_kpiNum_13wnr_55`,kpiLbl:`_kpiLbl_13wnr_56`,kpiBar:`_kpiBar_13wnr_57`,kpiFill:`_kpiFill_13wnr_58`,liveGrid:`_liveGrid_13wnr_61`,liveCard:`_liveCard_13wnr_67`,liveHdr:`_liveHdr_13wnr_71`,liveMore:`_liveMore_13wnr_79`,liveRow:`_liveRow_13wnr_81`,liveUnread:`_liveUnread_13wnr_89`,liveTitle:`_liveTitle_13wnr_89`,liveTime:`_liveTime_13wnr_91`,liveBody:`_liveBody_13wnr_95`,liveSub:`_liveSub_13wnr_97`,prio:`_prio_13wnr_99`,prio_high:`_prio_high_13wnr_103`,prio_medium:`_prio_medium_13wnr_104`,prio_low:`_prio_low_13wnr_105`,launcher:`_launcher_13wnr_108`,launchGroup:`_launchGroup_13wnr_115`,launchGroupLabel:`_launchGroupLabel_13wnr_117`,launchTiles:`_launchTiles_13wnr_123`,tile:`_tile_13wnr_129`,tileIcon:`_tileIcon_13wnr_143`,tileLabel:`_tileLabel_13wnr_144`},nt=[{view:`chat`,icon:`💬`,label:`Chat`,color:`#38bdf8`,group:`Panoramica`},{view:`plan`,icon:`🗓️`,label:`Daily Plan`,color:`#818cf8`,group:`Panoramica`},{view:`tasks`,icon:`✅`,label:`Tasks`,color:`#4ade80`,group:`Panoramica`},{view:`email`,icon:`📧`,label:`Email`,color:`#f87171`,group:`Google`},{view:`calendar`,icon:`📅`,label:`Calendar`,color:`#fb923c`,group:`Google`},{view:`drive`,icon:`💾`,label:`Drive`,color:`#facc15`,group:`Google`},{view:`contacts`,icon:`👤`,label:`Contacts`,color:`#34d399`,group:`Google`},{view:`notes`,icon:`📝`,label:`Notes`,color:`#a78bfa`,group:`Google`},{view:`onedrive`,icon:`☁️`,label:`OneDrive`,color:`#60a5fa`,group:`Microsoft`},{view:`mstodo`,icon:`📋`,label:`MS Todo`,color:`#38bdf8`,group:`Microsoft`},{view:`github`,icon:`🐙`,label:`GitHub`,color:`#e2e8f0`,group:`Tools`},{view:`notion`,icon:`📓`,label:`Notion`,color:`#94a3b8`,group:`Tools`},{view:`slack`,icon:`💼`,label:`Slack`,color:`#e879f9`,group:`Tools`},{view:`maps`,icon:`🗺️`,label:`Maps`,color:`#2dd4bf`,group:`Tools`},{view:`reminders`,icon:`🔔`,label:`Reminders`,color:`#fbbf24`,group:`Tools`},{view:`birthdays`,icon:`🎂`,label:`Birthdays`,color:`#f472b6`,group:`Tools`},{view:`cron`,icon:`⏰`,label:`Cron`,color:`#fb923c`,group:`Tools`},{view:`screen`,icon:`🖥️`,label:`Screen`,color:`#64748b`,group:`Tools`},{view:`agents`,icon:`🤖`,label:`Agents`,color:`#4ade80`,group:`AI`},{view:`studio`,icon:`🎭`,label:`Studio`,color:`#a78bfa`,group:`AI`},{view:`webcraft`,icon:`🔨`,label:`WebCraft`,color:`#f59e0b`,group:`AI`},{view:`collab`,icon:`🏛️`,label:`Alexandria`,color:`#38bdf8`,group:`AI`},{view:`connectors`,icon:`🔗`,label:`Connectors`,color:`#94a3b8`,group:`Config`},{view:`settings`,icon:`⚙️`,label:`Settings`,color:`#64748b`,group:`Config`}],rt={Sunny:`☀️`,Clear:`☀️`,"Partly Cloudy":`⛅`,"Partly cloudy":`⛅`,Cloudy:`☁️`,Overcast:`☁️`,"Light rain":`🌧️`,Rain:`🌧️`,Drizzle:`🌧️`,"Moderate rain":`🌧️`,"Heavy rain":`🌧️`,Snow:`❄️`,"Light snow":`❄️`,Fog:`🌫️`,Mist:`🌫️`,Thunder:`⚡`,"Thundery outbreaks":`⚡`};function it(e){try{return new Date(e).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,hour12:!1})}catch{return e}}function at(e){try{return new Date(e).toLocaleDateString(`en`,{month:`short`,day:`numeric`})}catch{return e}}function ot(){let e=ne(e=>e.setView),t=P(),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(new Date);(0,_.useEffect)(()=>{let e=setInterval(()=>p(new Date),6e4);return()=>clearInterval(e)},[]),(0,_.useEffect)(()=>{let e=!0,t=t=>n=>{e&&n!=null&&t(n)};E(`/api/tasks`).then(e=>t(r)(e?.tasks??[])),E(`/api/emails?page=0&pageSize=8`).then(e=>t(a)(e?.emails??[])),E(`/api/calendar`).then(e=>t(s)(e?.events??[])),E(`/api/status`).then(t(l));let n=localStorage.getItem(`nha_weather_location`),i=t=>E(`/api/weather?location=${encodeURIComponent(t)}`).then(t=>{e&&t?.tempC&&d(t)});return n?i(n):navigator.geolocation?.getCurrentPosition(e=>i(`${e.coords.latitude.toFixed(4)},${e.coords.longitude.toFixed(4)}`),()=>{},{timeout:6e3}),()=>{e=!1}},[]);let m=n.filter(e=>e.status!==`done`),h=n.filter(e=>e.status===`done`),g=n.length>0?Math.round(h.length/n.length*100):0,v=i.filter(e=>e.isUnread).length,y=f.toLocaleDateString(`en`,{weekday:`long`,month:`long`,day:`numeric`}),b=[...new Set(nt.map(e=>e.group))];return(0,k.jsxs)(`div`,{className:V.root,children:[(0,k.jsxs)(`div`,{className:V.hero,children:[(0,k.jsxs)(`div`,{className:V.heroLeft,children:[(0,k.jsx)(`div`,{className:V.heroDate,children:y}),(0,k.jsx)(`div`,{className:V.heroTitle,children:c?(0,k.jsxs)(k.Fragment,{children:[`NHA `,(0,k.jsxs)(`span`,{className:V.heroVer,children:[`v`,c.version]}),` · `,(0,k.jsxs)(`span`,{className:V.heroUptime,children:[Math.floor(c.uptime/60),`m uptime`]})]}):`NotHumanAllowed`})]}),(0,k.jsx)(`div`,{className:V.heroWeather,onClick:()=>{let e=prompt(`City or lat,lon:`);e&&(localStorage.setItem(`nha_weather_location`,e),location.reload())},children:u?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`span`,{className:V.wIcon,children:rt[u.desc]??u.icon??`🌡️`}),(0,k.jsxs)(`div`,{className:V.wInfo,children:[(0,k.jsxs)(`span`,{className:V.wTemp,children:[u.tempC,`°C`]}),(0,k.jsxs)(`span`,{className:V.wCity,children:[u.city.split(`,`)[0],u.country?`, ${u.country.slice(0,2).toUpperCase()}`:``]}),(0,k.jsxs)(`span`,{className:V.wDesc,children:[u.desc,` · 💧`,u.humidity,`%`]})]})]}):(0,k.jsxs)(`span`,{className:V.wEmpty,children:[`🌡️ `,t(`dashboard.weather`)]})})]}),(0,k.jsxs)(`div`,{className:V.kpiRow,children:[(0,k.jsxs)(`div`,{className:V.kpi,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.kpiNum,children:m.length}),(0,k.jsx)(`span`,{className:V.kpiLbl,children:`Pending tasks`}),n.length>0&&(0,k.jsx)(`div`,{className:V.kpiBar,children:(0,k.jsx)(`div`,{className:V.kpiFill,style:{width:`${g}%`}})})]}),(0,k.jsxs)(`div`,{className:V.kpi,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.kpiNum,children:v>0?v:i.length}),(0,k.jsx)(`span`,{className:V.kpiLbl,children:v>0?`Unread emails`:`Emails`})]}),(0,k.jsxs)(`div`,{className:V.kpi,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.kpiNum,children:o.length}),(0,k.jsx)(`span`,{className:V.kpiLbl,children:`Today's events`})]}),u&&(0,k.jsxs)(`div`,{className:V.kpi,children:[(0,k.jsxs)(`span`,{className:V.kpiNum,children:[u.feelsC,`°`]}),(0,k.jsx)(`span`,{className:V.kpiLbl,children:`Feels like`})]})]}),(0,k.jsxs)(`div`,{className:V.liveGrid,children:[o.length>0&&(0,k.jsxs)(`div`,{className:V.liveCard,children:[(0,k.jsxs)(`div`,{className:V.liveHdr,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📅 `,t(`calendar.title`)]}),(0,k.jsx)(`span`,{className:V.liveMore,children:`→`})]}),o.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:V.liveRow,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.liveTime,children:t.isAllDay?`All day`:it(t.start)}),(0,k.jsxs)(`div`,{className:V.liveBody,children:[(0,k.jsx)(`span`,{className:V.liveTitle,children:t.summary}),t.location&&(0,k.jsx)(`span`,{className:V.liveSub,children:t.location})]})]},n))]}),i.length>0&&(0,k.jsxs)(`div`,{className:V.liveCard,children:[(0,k.jsxs)(`div`,{className:V.liveHdr,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📧 `,t(`email.inbox`)]}),(0,k.jsx)(`span`,{className:V.liveMore,children:`→`})]}),i.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:`${V.liveRow} ${t.isUnread?V.liveUnread:``}`,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.liveTime,children:at(t.date)}),(0,k.jsxs)(`div`,{className:V.liveBody,children:[(0,k.jsx)(`span`,{className:V.liveTitle,children:t.subject}),(0,k.jsx)(`span`,{className:V.liveSub,children:t.from})]})]},n))]}),m.length>0&&(0,k.jsxs)(`div`,{className:V.liveCard,children:[(0,k.jsxs)(`div`,{className:V.liveHdr,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`✅ `,t(`tasks.title`),` · `,h.length,`/`,n.length,` (`,g,`%)`]}),(0,k.jsx)(`span`,{className:V.liveMore,children:`→`})]}),m.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:V.liveRow,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:`${V.prio} ${V[`prio_`+t.priority]}`,children:t.priority[0].toUpperCase()}),(0,k.jsx)(`div`,{className:V.liveBody,children:(0,k.jsx)(`span`,{className:V.liveTitle,children:t.description})})]},n))]})]}),(0,k.jsx)(`div`,{className:V.launcher,children:b.map(t=>(0,k.jsxs)(`div`,{className:V.launchGroup,children:[(0,k.jsx)(`div`,{className:V.launchGroupLabel,children:t}),(0,k.jsx)(`div`,{className:V.launchTiles,children:nt.filter(e=>e.group===t).map(t=>(0,k.jsxs)(`button`,{className:V.tile,onClick:()=>e(t.view),style:{"--tc":t.color},children:[(0,k.jsx)(`span`,{className:V.tileIcon,children:t.icon}),(0,k.jsx)(`span`,{className:V.tileLabel,children:t.label})]},t.view))})]},t))})]})}var st={root:`_root_1pldx_1`,loading:`_loading_1pldx_2`,bar:`_bar_1pldx_4`,input:`_input_1pldx_5`,select:`_select_1pldx_6`,addBtn:`_addBtn_1pldx_7`,actions:`_actions_1pldx_10`,clearDone:`_clearDone_1pldx_11`,clearAll:`_clearAll_1pldx_12`,stats:`_stats_1pldx_14`,progress:`_progress_1pldx_15`,progressBar:`_progressBar_1pldx_16`,empty:`_empty_1pldx_18`,task:`_task_1pldx_20`,taskDone:`_taskDone_1pldx_22`,check:`_check_1pldx_23`,checkDone:`_checkDone_1pldx_25`,desc:`_desc_1pldx_26`,del:`_del_1pldx_27`,badge:`_badge_1pldx_30`,badge_high:`_badge_high_1pldx_31`,badge_medium:`_badge_medium_1pldx_32`,badge_low:`_badge_low_1pldx_33`,doneLabel:`_doneLabel_1pldx_35`};function ct(){let e=P(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(`medium`),[l,u]=(0,_.useState)(!1),d=(0,_.useRef)(null),f=()=>E(`/api/tasks`).then(e=>{n(e?.tasks??[]),i(!1)});(0,_.useEffect)(()=>{f()},[]);let p=async()=>{a.trim()&&(u(!0),await D(`/api/tasks`,{description:a.trim(),priority:s}),o(``),u(!1),f(),d.current?.focus())},m=e=>D(`/api/tasks/${e}/done`,{},`PATCH`).then(f),h=e=>D(`/api/tasks/${e}/delete`,{}).then(f),g=()=>D(`/api/tasks/clear`,{filter:`done`}).then(f),v=()=>{confirm(e(`tasks.deleteTask`))&&D(`/api/tasks/clear`,{filter:`all`}).then(f)},y=t.filter(e=>e.status!==`done`),b=t.filter(e=>e.status===`done`);return r?(0,k.jsxs)(`div`,{className:st.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:st.root,children:[(0,k.jsxs)(`div`,{className:st.bar,children:[(0,k.jsx)(`input`,{ref:d,className:st.input,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>e.key===`Enter`&&p(),placeholder:e(`tasks.newTask`)}),(0,k.jsxs)(`select`,{className:st.select,value:s,onChange:e=>c(e.target.value),children:[(0,k.jsx)(`option`,{value:`high`,children:`High`}),(0,k.jsx)(`option`,{value:`medium`,children:`Medium`}),(0,k.jsx)(`option`,{value:`low`,children:`Low`})]}),(0,k.jsx)(`button`,{className:st.addBtn,onClick:p,disabled:l||!a.trim(),children:l?`…`:`+ `+e(`common.add`)})]}),t.length>0&&(0,k.jsxs)(`div`,{className:st.actions,children:[(0,k.jsx)(`button`,{className:st.clearDone,onClick:g,children:`Clear completed`}),(0,k.jsx)(`button`,{className:st.clearAll,onClick:v,children:`Clear all`})]}),t.length>0&&(0,k.jsxs)(`div`,{className:st.stats,children:[y.length,` pending · `,b.length,` done`,t.length>0&&(0,k.jsx)(`span`,{className:st.progress,children:(0,k.jsx)(`span`,{className:st.progressBar,style:{width:`${Math.round(b.length/t.length*100)}%`}})})]}),y.length===0&&b.length===0&&(0,k.jsx)(`div`,{className:st.empty,children:`No tasks yet. Add one above ↑`}),y.map(e=>(0,k.jsxs)(`div`,{className:st.task,children:[(0,k.jsx)(`span`,{className:st.check,onClick:()=>m(e.id)}),(0,k.jsx)(`span`,{className:st.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${st.badge} ${st[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:st.del,onClick:()=>h(e.id),children:`×`})]},e.id)),b.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:st.doneLabel,children:`Completed`}),b.map(e=>(0,k.jsxs)(`div`,{className:`${st.task} ${st.taskDone}`,children:[(0,k.jsx)(`span`,{className:`${st.check} ${st.checkDone}`,onClick:()=>m(e.id),children:`✓`}),(0,k.jsx)(`span`,{className:st.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${st.badge} ${st[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:st.del,onClick:()=>h(e.id),children:`×`})]},e.id))]})]})}var H={root:`_root_1jj88_1`,loading:`_loading_1jj88_2`,card:`_card_1jj88_4`,cardTitle:`_cardTitle_1jj88_5`,cardTitleRow:`_cardTitleRow_1jj88_6`,cardSub:`_cardSub_1jj88_7`,connected:`_connected_1jj88_8`,statusMsg:`_statusMsg_1jj88_9`,fields:`_fields_1jj88_11`,field:`_field_1jj88_11`,fieldLabel:`_fieldLabel_1jj88_13`,fieldInput:`_fieldInput_1jj88_14`,saveBtn:`_saveBtn_1jj88_17`,dangerBtn:`_dangerBtn_1jj88_18`,cancelBtn:`_cancelBtn_1jj88_19`,btnRow:`_btnRow_1jj88_20`,keySet:`_keySet_1jj88_22`,nhaFree:`_nhaFree_1jj88_24`,nhaFreeTitle:`_nhaFreeTitle_1jj88_25`,nhaFreeSub:`_nhaFreeSub_1jj88_26`,nhaFreeBtn:`_nhaFreeBtn_1jj88_27`,imapRow:`_imapRow_1jj88_29`,imapName:`_imapName_1jj88_30`,imapMeta:`_imapMeta_1jj88_31`,imapStatus:`_imapStatus_1jj88_32`,imapBtns:`_imapBtns_1jj88_36`,imapSyncBtn:`_imapSyncBtn_1jj88_37`,imapEditBtn:`_imapEditBtn_1jj88_38`,imapDelBtn:`_imapDelBtn_1jj88_39`,emptyImap:`_emptyImap_1jj88_40`,imapForm:`_imapForm_1jj88_42`,imapFormTitle:`_imapFormTitle_1jj88_43`,pwdNote:`_pwdNote_1jj88_44`,pwdRow:`_pwdRow_1jj88_45`,togglePwd:`_togglePwd_1jj88_46`},lt={id:``,display_name:``,email_address:``,from_name:``,imap_host:``,imap_port:`993`,smtp_host:``,smtp_port:`587`,username:``,password:``};function ut({id:e,label:t,placeholder:n,value:r,onChange:i,type:a=`text`}){return(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsx)(`label`,{className:H.fieldLabel,children:t}),(0,k.jsx)(`input`,{id:e,type:a,placeholder:n,value:r,onChange:e=>i(e.target.value),className:H.fieldInput})]})}function dt(){let{setConfig:e}=ne(),t=P(),[n,r]=(0,_.useState)({}),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(!1),[x,S]=(0,_.useState)({name:``,email:``,phone:``,homeAddress:``,workAddress:``,city:``,country:``,company:``,role:``,notes:``}),[C,w]=(0,_.useState)(`nha`),[ee,te]=(0,_.useState)(``),[T,re]=(0,_.useState)(``),[ie,O]=(0,_.useState)(`en`),[ae,A]=(0,_.useState)(`07:00`),[j,oe]=(0,_.useState)(`18:00`),[se,M]=(0,_.useState)(`30`),[ce,N]=(0,_.useState)(`off`),[F,le]=(0,_.useState)(``),[ue,de]=(0,_.useState)(``);(0,_.useEffect)(()=>{E(`/api/config`).then(t=>{r(t??{});let n=t?.profile??{};S({name:n.name??``,email:n.email??``,phone:n.phone??``,homeAddress:n.homeAddress??``,workAddress:n.workAddress??``,city:n.city??``,country:n.country??``,company:n.company??``,role:n.role??``,notes:n.notes??``}),w(t?.provider??`nha`),re(t?.model??``),O(t?.lang??`en`),A(t?.planTime??`07:00`),oe(t?.summaryTime??`18:00`),M(String(t?.meetingAlert??`30`)),N(t?.thinking??`off`),te(``),a(!1),t&&e(t)}),fe()},[]);let fe=()=>E(`/api/imap/accounts`).then(e=>d(e?.accounts??[])),I=async(e,t)=>{s(e),await D(`/api/config`,{key:e,value:t}),l(e),s(null),setTimeout(()=>l(null),2e3)},pe=()=>I(`profile`,x),me=()=>{I(`provider`,C),I(`model`,T),I(`thinking`,ce),ee&&I(`key`,ee)},he=()=>{I(`planTime`,ae),I(`summaryTime`,j),I(`meetingAlert`,Number(se))},ge=()=>{v(t(`settings.googleOpening`)),D(`/api/google/auth`,{}).then(e=>{e?.url?(window.open(e.url,`_blank`),v(t(`settings.googleOpened`))):e?.error&&v(t(`common.error`)+`: `+e.error)}).catch(e=>v(t(`common.error`)+`: `+e.message))},L=()=>{confirm(t(`settings.disconnectGoogleConfirm`))&&D(`/api/google/revoke`,{}).then(()=>{r(e=>({...e,hasGoogle:!1})),v(t(`common.disconnected`))})},_e=()=>{if(!f)return;let e=!!f.id,t={display_name:f.display_name,email_address:f.email_address,from_name:f.from_name,imap_host:f.imap_host,imap_port:Number(f.imap_port),smtp_host:f.smtp_host,smtp_port:Number(f.smtp_port),username:f.username};f.password&&(t.password=f.password),e&&(t.id=f.id),h(`Saving…`),D(e?`/api/imap/accounts/update`:`/api/imap/accounts`,t).then(e=>{e?.ok||e?.id?(h(`Saved!`),p(null),fe()):h(`Error: `+(e?.error??`Unknown error`))}).catch(e=>h(`Error: `+e.message))},ve=(e,n)=>{confirm(t(`settings.imapDelete`,{name:n}))&&D(`/api/imap/accounts/delete`,{id:e}).then(()=>fe())},ye=e=>{D(`/api/imap/sync`,{accountId:e}).then(()=>setTimeout(fe,3e3))};if(i)return(0,k.jsxs)(`div`,{className:H.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),t(`common.loading`)]});let R=e=>t(o===e?`common.saving`:c===e?`common.saved`:`common.save`);return(0,k.jsxs)(`div`,{className:H.root,children:[(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.profile`)}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.profileSub`)}),(0,k.jsx)(`div`,{className:H.fields,children:[[`name`,t(`settings.name`),t(`settings.namePh`)],[`email`,t(`common.email`),t(`settings.emailPh`)],[`phone`,t(`common.phone`),t(`settings.phonePh`)],[`homeAddress`,t(`settings.homeAddress`),t(`settings.homeAddressPh`)],[`workAddress`,t(`settings.workAddress`),t(`settings.workAddressPh`)],[`city`,t(`settings.city`),t(`settings.cityPh`)],[`country`,t(`settings.country`),t(`settings.countryPh`)],[`company`,t(`settings.company`),t(`settings.companyPh`)],[`role`,t(`settings.role`),t(`settings.rolePh`)],[`notes`,t(`settings.notes`),t(`settings.notesPh`)]].map(([e,t,n])=>(0,k.jsx)(ut,{id:e,label:t,placeholder:n,value:x[e],onChange:t=>S(n=>({...n,[e]:t}))},e))}),(0,k.jsxs)(`button`,{className:H.saveBtn,onClick:pe,children:[R(`profile`),` `,t(`settings.saveProfile`)]})]}),(0,k.jsxs)(`div`,{className:H.nhaFree,children:[(0,k.jsx)(`div`,{className:H.nhaFreeTitle,children:t(`settings.nhaFreeTitle`)}),(0,k.jsx)(`div`,{className:H.nhaFreeSub,children:t(`settings.nhaFreeSub`)}),(0,k.jsx)(`button`,{className:H.nhaFreeBtn,onClick:()=>{D(`/api/config`,{updates:[{key:`provider`,value:`nha`},{key:`model`,value:``},{key:`key`,value:``}]}).then(()=>{w(`nha`),re(``),te(``),l(`nhaFree`),setTimeout(()=>l(null),2e3)})},children:t(c===`nhaFree`?`settings.liaraActivated`:`settings.useLiara`)})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.llmProvider`)}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.llmProviderSub`)}),(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsx)(`label`,{className:H.fieldLabel,children:t(`settings.provider`)}),(0,k.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),className:H.fieldInput,children:[(0,k.jsx)(`option`,{value:`nha`,children:`NHA Free (Liara) — no API key needed`}),(0,k.jsx)(`option`,{value:`anthropic`,children:`Anthropic (Claude)`}),(0,k.jsx)(`option`,{value:`openai`,children:`OpenAI (GPT-4)`}),(0,k.jsx)(`option`,{value:`gemini`,children:`Google (Gemini)`}),(0,k.jsx)(`option`,{value:`deepseek`,children:`DeepSeek`}),(0,k.jsx)(`option`,{value:`grok`,children:`xAI (Grok)`}),(0,k.jsx)(`option`,{value:`mistral`,children:`Mistral`}),(0,k.jsx)(`option`,{value:`cohere`,children:`Cohere`})]})]}),C!==`nha`&&({anthropic:n.hasApiKey,openai:n.hasOpenaiKey,gemini:n.hasGeminiKey,deepseek:n.hasDeepseekKey,grok:n.hasGrokKey,mistral:n.hasMistralKey,cohere:n.hasCohereKey}[C]?(0,k.jsx)(`div`,{className:H.keySet,children:t(`settings.apiKeySet`)}):null),(0,k.jsx)(ut,{id:`apiKey`,label:t(`settings.apiKey`),placeholder:t(C===`nha`?`settings.apiKeyFreeNote`:`settings.apiKeyPh`),type:`password`,value:ee,onChange:te}),(0,k.jsx)(ut,{id:`model`,label:t(`settings.model`),placeholder:t(`settings.modelPh`),value:T,onChange:re}),(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsx)(`label`,{className:H.fieldLabel,children:t(`settings.thinking`)}),(0,k.jsxs)(`select`,{value:ce,onChange:e=>N(e.target.value),className:H.fieldInput,children:[(0,k.jsx)(`option`,{value:`off`,children:t(`settings.thinkingOff`)}),(0,k.jsx)(`option`,{value:`on`,children:t(`settings.thinkingOn`)})]})]}),(0,k.jsxs)(`button`,{className:H.saveBtn,onClick:me,children:[R(`provider`),` `,t(`settings.saveProvider`)]})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.language`)}),(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsx)(`label`,{className:H.fieldLabel,children:t(`settings.languageLabel`)}),(0,k.jsx)(`select`,{value:ie,onChange:t=>{let r=t.target.value;O(r),I(`lang`,r),e({...n,lang:r})},className:H.fieldInput,children:[[`it`,`Italiano`],[`en`,`English`],[`es`,`Español`],[`fr`,`Français`],[`de`,`Deutsch`],[`pt`,`Português`],[`nl`,`Nederlands`],[`pl`,`Polski`],[`ru`,`Русский`],[`zh`,`中文`],[`ja`,`日本語`],[`ko`,`한국어`],[`ar`,`العربية`],[`hi`,`हिन्दी`],[`tr`,`Türkçe`],[`sv`,`Svenska`],[`da`,`Dansk`],[`fi`,`Suomi`],[`cs`,`Čeština`]].map(([e,t])=>(0,k.jsx)(`option`,{value:e,children:t},e))})]})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.telegram`)}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.telegramSub`)}),n.hasTelegram&&(0,k.jsxs)(`div`,{className:H.connected,children:[`Telegram: `,t(`common.connected`)]}),n.hasDiscord&&(0,k.jsxs)(`div`,{className:H.connected,children:[`Discord: `,t(`common.connected`)]}),(0,k.jsx)(ut,{id:`tgToken`,label:t(`settings.telegramToken`),placeholder:n.hasTelegram?t(`settings.telegramSet`):t(`settings.telegramPh`),type:`password`,value:F,onChange:le}),(0,k.jsx)(ut,{id:`discordToken`,label:t(`settings.discordToken`),placeholder:n.hasDiscord?t(`settings.discordSet`):t(`settings.discordPh`),type:`password`,value:ue,onChange:de}),(0,k.jsxs)(`button`,{className:H.saveBtn,onClick:()=>{F&&I(`telegram-bot-token`,F),ue&&I(`discord-bot-token`,ue)},children:[R(`telegram-bot-token`),` `,t(`settings.saveBots`)]})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.dailyOps`)}),(0,k.jsx)(ut,{id:`planTime`,label:t(`settings.planTime`),placeholder:`07:00`,value:ae,onChange:A}),(0,k.jsx)(ut,{id:`summaryTime`,label:t(`settings.summaryTime`),placeholder:`18:00`,value:j,onChange:oe}),(0,k.jsx)(ut,{id:`meetingAlert`,label:t(`settings.meetingAlert`),placeholder:`30`,value:se,onChange:M}),(0,k.jsxs)(`button`,{className:H.saveBtn,onClick:he,children:[R(`planTime`),` `,t(`settings.saveSchedule`)]})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.googleAccount`)}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.googleSub`)}),n.hasGoogle&&(0,k.jsxs)(`div`,{className:H.connected,children:[`✅ `,t(`common.connected`),n.googleEmail?` · ${n.googleEmail}`:``]}),(0,k.jsxs)(`div`,{className:H.btnRow,children:[(0,k.jsx)(`button`,{className:H.saveBtn,onClick:ge,children:n.hasGoogle?t(`settings.reconnectGoogle`):t(`settings.connectGoogle`)}),n.hasGoogle&&(0,k.jsx)(`button`,{className:H.dangerBtn,onClick:L,children:t(`settings.disconnectGoogle`)})]}),g&&(0,k.jsx)(`div`,{className:H.statusMsg,children:g})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsxs)(`div`,{className:H.cardTitleRow,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.imapAccounts`)}),(0,k.jsx)(`button`,{className:H.saveBtn,onClick:()=>{p({...lt}),h(``)},children:t(`settings.addAccount`)})]}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.imapSub`)}),u.length===0&&!f&&(0,k.jsx)(`div`,{className:H.emptyImap,children:t(`settings.noImapAccounts`)}),u.map(e=>(0,k.jsxs)(`div`,{className:H.imapRow,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:H.imapName,children:e.display_name}),(0,k.jsxs)(`div`,{className:H.imapMeta,children:[e.email_address,` · `,e.imap_host]}),(0,k.jsxs)(`div`,{className:H.imapStatus,"data-status":e.sync_status,children:[e.sync_status,e.last_sync_at?` · ${t(`email.lastSync`)}: ${e.last_sync_at.slice(0,16)}`:``]})]}),(0,k.jsxs)(`div`,{className:H.imapBtns,children:[(0,k.jsx)(`button`,{className:H.imapSyncBtn,onClick:()=>ye(e.id),children:t(`settings.sync`)}),(0,k.jsx)(`button`,{className:H.imapEditBtn,onClick:()=>{p({...lt,id:e.id,display_name:e.display_name,email_address:e.email_address,from_name:e.from_name??``,imap_host:e.imap_host,imap_port:String(e.imap_port??993),smtp_host:e.smtp_host??``,smtp_port:String(e.smtp_port??587),username:e.username??``,password:``}),h(``)},children:t(`common.edit`)}),(0,k.jsx)(`button`,{className:H.imapDelBtn,onClick:()=>ve(e.id,e.display_name),children:t(`common.delete`)})]})]},e.id)),f&&(0,k.jsxs)(`div`,{className:H.imapForm,children:[(0,k.jsx)(`div`,{className:H.imapFormTitle,children:f.id?t(`settings.editImapAccount`):t(`settings.addImapAccount`)}),[[`display_name`,t(`settings.displayName`),t(`settings.displayNamePh`)],[`email_address`,t(`common.email`),`user@example.com`],[`from_name`,t(`settings.fromName`),t(`settings.fromNamePh`)],[`imap_host`,t(`settings.imapServer`),`e.g. imap.gmail.com`],[`imap_port`,t(`settings.imapPort`),`993`],[`smtp_host`,t(`settings.smtpServer`),`e.g. smtp.gmail.com`],[`smtp_port`,t(`settings.smtpPort`),`587`],[`username`,t(`settings.username`),`user@example.com`]].map(([e,t,n])=>(0,k.jsx)(ut,{id:`imap_${e}`,label:t,placeholder:n,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t})},e)),(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsxs)(`label`,{className:H.fieldLabel,children:[t(`settings.password`),` `,f.id&&(0,k.jsx)(`span`,{className:H.pwdNote,children:t(`settings.passwordKeep`)})]}),(0,k.jsxs)(`div`,{className:H.pwdRow,children:[(0,k.jsx)(`input`,{type:y?`text`:`password`,placeholder:t(`settings.passwordPh`),value:f.password,onChange:e=>p(t=>t&&{...t,password:e.target.value}),className:H.fieldInput,style:{flex:1}}),(0,k.jsx)(`button`,{className:H.togglePwd,onClick:()=>b(e=>!e),children:t(y?`settings.hide`:`settings.show`)})]})]}),(0,k.jsxs)(`div`,{className:H.btnRow,children:[(0,k.jsx)(`button`,{className:H.saveBtn,onClick:_e,children:t(`common.save`)}),(0,k.jsx)(`button`,{className:H.cancelBtn,onClick:()=>p(null),children:t(`common.cancel`)})]}),m&&(0,k.jsx)(`div`,{className:H.statusMsg,children:m})]})]})]})}var ft={root:`_root_o07ov_1`,loading:`_loading_o07ov_2`,err:`_err_o07ov_3`,header:`_header_o07ov_4`,title:`_title_o07ov_5`,addBtn:`_addBtn_o07ov_6`,empty:`_empty_o07ov_7`,card:`_card_o07ov_8`,cardToday:`_cardToday_o07ov_9`,icon:`_icon_o07ov_10`,info:`_info_o07ov_11`,name:`_name_o07ov_12`,date:`_date_o07ov_13`,labelToday:`_labelToday_o07ov_14`,labelTomorrow:`_labelTomorrow_o07ov_15`,labelFuture:`_labelFuture_o07ov_16`,editBtn:`_editBtn_o07ov_17`,delBtn:`_delBtn_o07ov_18`,overlay:`_overlay_o07ov_20`,modal:`_modal_o07ov_21`,modalTitle:`_modalTitle_o07ov_22`,label:`_label_o07ov_14`,input:`_input_o07ov_24`,hint:`_hint_o07ov_25`,formErr:`_formErr_o07ov_26`,modalBtns:`_modalBtns_o07ov_27`,cancelBtn:`_cancelBtn_o07ov_28`,saveBtn:`_saveBtn_o07ov_29`};function pt(){let e=P(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(!1),p=(0,_.useCallback)(()=>{i(!0),E(`/api/birthdays`).then(e=>{e?.error?o(e.error):n(e?.birthdays??[]),i(!1)})},[]);(0,_.useEffect)(()=>{p()},[p]);let m=()=>{c({name:``,date:``}),u(``)},h=e=>{c({name:e.name,date:e.date,contactId:e.contactId}),u(``)},g=async()=>{if(!s)return;if(!s.name.trim()){u(`Name is required`);return}if(!s.date.trim()){u(`Date is required`);return}f(!0);let e=s.date;/^\d{2}-\d{2}$/.test(e)&&(e=`${new Date().getFullYear()}-${e}`),await D(`/api/birthdays`,{name:s.name,date:e,contactId:s.contactId??null,edit:!!s.contactId}),f(!1),c(null),p()},v=e=>{confirm(`Remove birthday for ${e.name}?`)&&D(`/api/birthdays/delete`,{contactId:e.contactId}).then(p)};return r?(0,k.jsxs)(`div`,{className:ft.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):a?(0,k.jsx)(`div`,{className:ft.err,children:a}):(0,k.jsxs)(`div`,{className:ft.root,children:[(0,k.jsxs)(`div`,{className:ft.header,children:[(0,k.jsx)(`div`,{className:ft.title,children:`Upcoming Birthdays`}),(0,k.jsx)(`button`,{className:ft.addBtn,onClick:m,children:`+ Add Birthday`})]}),t.length===0&&(0,k.jsxs)(`div`,{className:ft.empty,children:[e(`birthdays.noBirthdays`),(0,k.jsx)(`br`,{}),(0,k.jsx)(`small`,{children:`Add one above, or add birthdays to your Google Contacts.`})]}),t.map((t,n)=>{let r=t.daysUntil===0,i=t.daysUntil===1;return(0,k.jsxs)(`div`,{className:`${ft.card} ${r?ft.cardToday:``}`,children:[(0,k.jsx)(`span`,{className:ft.icon,children:`🎂`}),(0,k.jsxs)(`div`,{className:ft.info,children:[(0,k.jsx)(`div`,{className:ft.name,children:t.name}),(0,k.jsx)(`div`,{className:ft.date,children:t.date})]}),(0,k.jsx)(`div`,{className:r?ft.labelToday:i?ft.labelTomorrow:ft.labelFuture,children:r?`TODAY!`:i?`Tomorrow`:`in ${t.daysUntil} days`}),t.contactId&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:ft.editBtn,onClick:()=>h(t),children:e(`common.edit`)}),(0,k.jsx)(`button`,{className:ft.delBtn,onClick:()=>v(t),children:e(`common.delete`)})]})]},n)}),s&&(0,k.jsx)(`div`,{className:ft.overlay,onClick:e=>{e.target===e.currentTarget&&c(null)},children:(0,k.jsxs)(`div`,{className:ft.modal,children:[(0,k.jsx)(`div`,{className:ft.modalTitle,children:s.contactId?`Edit Birthday`:`Add Birthday`}),(0,k.jsx)(`label`,{className:ft.label,children:`Name *`}),(0,k.jsx)(`input`,{className:ft.input,value:s.name,onChange:e=>c(t=>t&&{...t,name:e.target.value}),placeholder:`Contact name`}),(0,k.jsx)(`label`,{className:ft.label,children:`Birthday (MM-DD or YYYY-MM-DD)`}),(0,k.jsx)(`input`,{className:ft.input,value:s.date,onChange:e=>c(t=>t&&{...t,date:e.target.value}),placeholder:`e.g. 03-15 or 1990-03-15`}),(0,k.jsx)(`div`,{className:ft.hint,children:`Birthday will be saved as a Google Calendar event.`}),l&&(0,k.jsx)(`div`,{className:ft.formErr,children:l}),(0,k.jsxs)(`div`,{className:ft.modalBtns,children:[(0,k.jsx)(`button`,{className:ft.cancelBtn,onClick:()=>c(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:ft.saveBtn,onClick:g,disabled:d,children:d?`Saving…`:s.contactId?`Save`:`Add`})]})]})})]})}var U={root:`_root_1z04o_1`,header:`_header_1z04o_3`,title:`_title_1z04o_4`,subtitle:`_subtitle_1z04o_5`,code:`_code_1z04o_6`,addBtn:`_addBtn_1z04o_8`,tabs:`_tabs_1z04o_10`,tab:`_tab_1z04o_10`,tabActive:`_tabActive_1z04o_12`,loading:`_loading_1z04o_14`,err:`_err_1z04o_15`,empty:`_empty_1z04o_17`,emptyIcon:`_emptyIcon_1z04o_18`,emptyTitle:`_emptyTitle_1z04o_19`,emptySub:`_emptySub_1z04o_20`,card:`_card_1z04o_23`,cardDisabled:`_cardDisabled_1z04o_24`,cardTop:`_cardTop_1z04o_25`,cardLeft:`_cardLeft_1z04o_26`,jobName:`_jobName_1z04o_27`,schedule:`_schedule_1z04o_28`,agentBadge:`_agentBadge_1z04o_29`,statusBadge:`_statusBadge_1z04o_30`,statusActive:`_statusActive_1z04o_31`,statusPaused:`_statusPaused_1z04o_32`,jobPrompt:`_jobPrompt_1z04o_33`,jobMeta:`_jobMeta_1z04o_34`,cardActions:`_cardActions_1z04o_35`,runBtn:`_runBtn_1z04o_36`,editBtn:`_editBtn_1z04o_37`,pauseBtn:`_pauseBtn_1z04o_38`,resumeBtn:`_resumeBtn_1z04o_39`,delBtn:`_delBtn_1z04o_40`,templates:`_templates_1z04o_43`,templatesNote:`_templatesNote_1z04o_44`,templateCard:`_templateCard_1z04o_45`,templateLabel:`_templateLabel_1z04o_46`,templatePrompt:`_templatePrompt_1z04o_47`,templateBtns:`_templateBtns_1z04o_48`,scheduleTplBtn:`_scheduleTplBtn_1z04o_49`,runTplBtn:`_runTplBtn_1z04o_50`,formOverlay:`_formOverlay_1z04o_54`,formModal:`_formModal_1z04o_55`,formTitle:`_formTitle_1z04o_56`,label:`_label_1z04o_57`,input:`_input_1z04o_58`,textarea:`_textarea_1z04o_59`,presets:`_presets_1z04o_61`,preset:`_preset_1z04o_61`,presetActive:`_presetActive_1z04o_63`,cronHints:`_cronHints_1z04o_65`,cronHint:`_cronHint_1z04o_65`,formErr:`_formErr_1z04o_70`,formOk:`_formOk_1z04o_71`,formBtns:`_formBtns_1z04o_72`,cancelBtn:`_cancelBtn_1z04o_73`,saveBtn:`_saveBtn_1z04o_74`},mt=[{label:`Every 15 min`,value:`every 15 minutes`},{label:`Every 30 min`,value:`every 30 minutes`},{label:`Every hour`,value:`every hour`},{label:`Every 6h`,value:`every 6 hours`},{label:`Daily 8am`,value:`every day at 08:00`},{label:`Daily 9am`,value:`every day at 09:00`},{label:`Daily noon`,value:`every day at 12:00`},{label:`Daily 6pm`,value:`every day at 18:00`},{label:`Mon–Fri 9am`,value:`weekdays at 09:00`},{label:`Every Monday`,value:`every monday at 09:00`}],ht=[{label:`🌅 Morning Briefing`,prompt:`Summarize my unread emails from the last 12 hours, check today's calendar events, list my top 3 priority tasks, and give me a focused action plan for the day.`},{label:`🌆 Evening Review`,prompt:`Review what I accomplished today: check completed tasks, summarize any important emails received, flag unresolved issues, and prepare a priority list for tomorrow.`},{label:`📰 News Digest`,prompt:`Search for the top AI, tech, and finance news from the last 24 hours. Summarize the 5 most important stories with key takeaways and market implications.`},{label:`📈 Market Update`,prompt:`Provide a comprehensive market update: macro environment, major indices performance, top movers, notable events, and key levels to watch. Use herald and mercury agents.`},{label:`🐙 GitHub Monitor`,prompt:`Check my GitHub notifications, summarize open issues and pull requests that need attention, and draft brief responses for the most urgent ones.`},{label:`📊 Weekly Report`,prompt:`Generate a weekly productivity report: tasks completed vs pending, email response rate, upcoming calendar events, and 3 strategic priorities for next week.`},{label:`🔒 Security Scan`,prompt:`Run a security awareness check: scan recent code commits for potential vulnerabilities, check dependency alerts, and summarize any security-related GitHub notifications.`},{label:`🎯 Goal Tracker`,prompt:`Review my tasks and notes for goal progress. Identify what's on track, what's at risk, and suggest one concrete action to unblock the most important goal.`}],gt=[{label:`0 9 * * 1-5`,desc:`Mon–Fri at 9:00 AM`},{label:`0 */6 * * *`,desc:`Every 6 hours`},{label:`*/30 * * * *`,desc:`Every 30 minutes`},{label:`0 8 * * *`,desc:`Daily at 8:00 AM`},{label:`0 20 * * 5`,desc:`Every Friday at 8 PM`}];function _t(){let e=P(),t=ne(e=>e.setView),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)({name:``,schedule:``,prompt:``,agent:``}),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(null),[x,S]=(0,_.useState)(`jobs`),C=()=>{a(!0),E(`/api/cron`).then(e=>{e?.error?s(e.error):r(e?.jobs??[]),a(!1)}).catch(()=>{r([]),a(!1)})};(0,_.useEffect)(()=>{C()},[]);let w=()=>{d({name:``,schedule:``,prompt:``,agent:``}),h(``),v(``),b(null),l(!0)},ee=e=>{d({name:e.name??``,schedule:e.schedule,prompt:e.prompt??e.command??``,agent:e.agent??``}),h(``),v(``),b(e.id),l(!0)},te=async()=>{if(!u.schedule.trim()){h(`Schedule is required`);return}if(!u.prompt.trim()){h(`Task prompt is required`);return}p(!0),h(``);try{y?await D(`/api/cron/update`,{id:y,schedule:u.schedule,prompt:u.prompt,agent:u.agent||void 0,name:u.name||void 0}):await D(`/api/cron`,{schedule:u.schedule,prompt:u.prompt,agent:u.agent||void 0,name:u.name||void 0}),v(y?`Updated!`:`Job scheduled!`),setTimeout(()=>{v(``),l(!1)},1500),C()}catch(e){h(e.message??`Failed`)}p(!1)},T=(e,t)=>D(`/api/cron/toggle`,{id:e,enabled:!t}).then(C),re=e=>{confirm(`Delete this scheduled task?`)&&D(`/api/cron/delete`,{id:e}).then(C)},ie=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},O=e=>{d(t=>({...t,prompt:e.prompt,name:e.label.replace(/^[^\s]+\s/,``)})),S(`jobs`),l(!0)};return(0,k.jsxs)(`div`,{className:U.root,children:[(0,k.jsxs)(`div`,{className:U.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:U.title,children:`⏰ Scheduled Tasks`}),(0,k.jsxs)(`div`,{className:U.subtitle,children:[`Automate agents on a recurring schedule. Daemon must be running: `,(0,k.jsx)(`code`,{className:U.code,children:`nha ops start`})]})]}),(0,k.jsx)(`button`,{className:U.addBtn,onClick:w,children:`+ New Task`})]}),(0,k.jsxs)(`div`,{className:U.tabs,children:[(0,k.jsxs)(`button`,{className:`${U.tab} ${x===`jobs`?U.tabActive:``}`,onClick:()=>S(`jobs`),children:[`Jobs (`,n.length,`)`]}),(0,k.jsx)(`button`,{className:`${U.tab} ${x===`templates`?U.tabActive:``}`,onClick:()=>S(`templates`),children:`Templates`})]}),x===`templates`&&(0,k.jsxs)(`div`,{className:U.templates,children:[(0,k.jsx)(`div`,{className:U.templatesNote,children:`Click a template to pre-fill the job form or run it immediately in Chat.`}),ht.map(t=>(0,k.jsxs)(`div`,{className:U.templateCard,children:[(0,k.jsx)(`div`,{className:U.templateLabel,children:t.label}),(0,k.jsx)(`div`,{className:U.templatePrompt,children:t.prompt}),(0,k.jsxs)(`div`,{className:U.templateBtns,children:[(0,k.jsx)(`button`,{className:U.scheduleTplBtn,onClick:()=>O(t),children:`Schedule`}),(0,k.jsxs)(`button`,{className:U.runTplBtn,onClick:()=>ie(t.prompt),children:[e(`cron.run`),` in Chat →`]})]})]},t.label))]}),x===`jobs`&&(0,k.jsxs)(k.Fragment,{children:[i&&(0,k.jsxs)(`div`,{className:U.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading jobs…`]}),o&&(0,k.jsx)(`div`,{className:U.err,children:o}),!i&&n.length===0&&!c&&(0,k.jsxs)(`div`,{className:U.empty,children:[(0,k.jsx)(`div`,{className:U.emptyIcon,children:`⏰`}),(0,k.jsxs)(`div`,{className:U.emptyTitle,children:[e(`cron.noJobs`),` tasks`]}),(0,k.jsx)(`div`,{className:U.emptySub,children:`Create a job to automate agents on a recurring schedule, or browse the Templates tab for ready-made automation recipes.`}),(0,k.jsx)(`button`,{className:U.addBtn,onClick:w,children:`+ New Task`})]}),n.map(e=>(0,k.jsxs)(`div`,{className:`${U.card} ${e.enabled?``:U.cardDisabled}`,children:[(0,k.jsxs)(`div`,{className:U.cardTop,children:[(0,k.jsxs)(`div`,{className:U.cardLeft,children:[e.name&&(0,k.jsx)(`div`,{className:U.jobName,children:e.name}),(0,k.jsx)(`code`,{className:U.schedule,children:e.schedule}),e.agent&&(0,k.jsx)(`span`,{className:U.agentBadge,children:e.agent}),(0,k.jsx)(`span`,{className:`${U.statusBadge} ${e.enabled?U.statusActive:U.statusPaused}`,children:e.enabled?`active`:`paused`})]}),(0,k.jsxs)(`div`,{className:U.cardActions,children:[(0,k.jsx)(`button`,{className:U.runBtn,onClick:()=>ie(e.prompt??e.command??``),title:`Run now in Chat`,children:`▶`}),(0,k.jsx)(`button`,{className:U.editBtn,onClick:()=>ee(e),children:`Edit`}),(0,k.jsx)(`button`,{className:e.enabled?U.pauseBtn:U.resumeBtn,onClick:()=>T(e.id,e.enabled),children:e.enabled?`Pause`:`Resume`}),(0,k.jsx)(`button`,{className:U.delBtn,onClick:()=>re(e.id),children:`✕`})]})]}),(0,k.jsx)(`div`,{className:U.jobPrompt,children:e.prompt??e.command}),(0,k.jsxs)(`div`,{className:U.jobMeta,children:[e.runCount!==void 0&&(0,k.jsxs)(`span`,{children:[`ran `,e.runCount,`×`]}),e.lastRun&&(0,k.jsxs)(`span`,{children:[` · last `,new Date(e.lastRun).toLocaleString()]}),e.nextRun&&(0,k.jsxs)(`span`,{children:[` · next `,new Date(e.nextRun).toLocaleString()]})]})]},e.id))]}),c&&(0,k.jsx)(`div`,{className:U.formOverlay,onClick:e=>{e.target===e.currentTarget&&l(!1)},children:(0,k.jsxs)(`div`,{className:U.formModal,children:[(0,k.jsx)(`div`,{className:U.formTitle,children:y?`Edit Scheduled Task`:`New Scheduled Task`}),(0,k.jsx)(`label`,{className:U.label,children:`Name (optional)`}),(0,k.jsx)(`input`,{className:U.input,value:u.name,onChange:e=>d(t=>({...t,name:e.target.value})),placeholder:`e.g. Morning Briefing`}),(0,k.jsx)(`label`,{className:U.label,children:`Schedule *`}),(0,k.jsx)(`div`,{className:U.presets,children:mt.map(e=>(0,k.jsx)(`button`,{className:`${U.preset} ${u.schedule===e.value?U.presetActive:``}`,onClick:()=>d(t=>({...t,schedule:e.value})),children:e.label},e.value))}),(0,k.jsx)(`input`,{className:U.input,value:u.schedule,onChange:e=>d(t=>({...t,schedule:e.target.value})),placeholder:`every day at 09:00 — or cron syntax: 0 9 * * 1-5`}),(0,k.jsx)(`div`,{className:U.cronHints,children:gt.map(e=>(0,k.jsxs)(`span`,{className:U.cronHint,onClick:()=>d(t=>({...t,schedule:e.label})),children:[(0,k.jsx)(`code`,{children:e.label}),` `,e.desc]},e.label))}),(0,k.jsx)(`label`,{className:U.label,children:`Task / Prompt *`}),(0,k.jsx)(`textarea`,{className:U.textarea,value:u.prompt,onChange:e=>d(t=>({...t,prompt:e.target.value})),placeholder:`Describe what the agent should do (e.g. Summarize my unread emails and list my 3 top priority tasks)`,rows:4}),(0,k.jsx)(`label`,{className:U.label,children:`Agent (optional — leave blank for auto-routing)`}),(0,k.jsx)(`input`,{className:U.input,value:u.agent,onChange:e=>d(t=>({...t,agent:e.target.value})),placeholder:`e.g. herald, oracle, mercury, EmailAgent, general`}),m&&(0,k.jsx)(`div`,{className:U.formErr,children:m}),g&&(0,k.jsx)(`div`,{className:U.formOk,children:g}),(0,k.jsxs)(`div`,{className:U.formBtns,children:[(0,k.jsx)(`button`,{className:U.cancelBtn,onClick:()=>l(!1),children:`Cancel`}),(0,k.jsx)(`button`,{className:U.saveBtn,onClick:te,disabled:f,children:f?`Saving…`:y?`Update`:`Schedule`})]})]})})]})}var vt={root:`_root_1npv7_1`,loading:`_loading_1npv7_2`,sidebar:`_sidebar_1npv7_4`,newBtn:`_newBtn_1npv7_5`,empty:`_empty_1npv7_6`,noteItem:`_noteItem_1npv7_8`,noteItemActive:`_noteItemActive_1npv7_10`,noteTitle:`_noteTitle_1npv7_11`,noteMeta:`_noteMeta_1npv7_12`,notePreview:`_notePreview_1npv7_13`,noteTags:`_noteTags_1npv7_14`,noteTag:`_noteTag_1npv7_14`,editor:`_editor_1npv7_17`,emptyEditor:`_emptyEditor_1npv7_18`,titleInput:`_titleInput_1npv7_19`,contentArea:`_contentArea_1npv7_21`,editorFooter:`_editorFooter_1npv7_22`,delNoteBtn:`_delNoteBtn_1npv7_23`,cancelBtn:`_cancelBtn_1npv7_24`,saveBtn:`_saveBtn_1npv7_25`};function yt(){let e=P(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(!1),h=()=>E(`/api/notes`).then(e=>{n(e?.notes??[]),i(!1)});(0,_.useEffect)(()=>{h()},[]);let g=e=>{o(e),c(e.title),u(e.content),m(!1)},v=()=>{o(null),c(``),u(``),m(!0)},y=async()=>{f(!0),p?await D(`/api/notes`,{title:s||`Untitled`,content:l}):a&&await D(`/api/notes/${a.id}`,{title:s,content:l}),f(!1),m(!1),h()},b=(e,t)=>{confirm(`Delete note "${t}"?`)&&D(`/api/notes/${e}/delete`,{}).then(h)};return r?(0,k.jsxs)(`div`,{className:vt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:vt.root,children:[(0,k.jsxs)(`div`,{className:vt.sidebar,children:[(0,k.jsx)(`button`,{className:vt.newBtn,onClick:v,children:`+ New Note`}),t.length===0&&(0,k.jsx)(`div`,{className:vt.empty,children:e(`notes.noNotes`)}),t.map(e=>(0,k.jsxs)(`div`,{className:`${vt.noteItem} ${a?.id===e.id?vt.noteItemActive:``}`,onClick:()=>g(e),children:[(0,k.jsx)(`div`,{className:vt.noteTitle,children:e.title||`Untitled`}),(0,k.jsx)(`div`,{className:vt.noteMeta,children:e.updatedAt?new Date(e.updatedAt).toLocaleDateString():``}),e.content&&(0,k.jsx)(`div`,{className:vt.notePreview,children:e.content.slice(0,150)}),e.tags&&e.tags.length>0&&(0,k.jsx)(`div`,{className:vt.noteTags,children:e.tags.map(e=>(0,k.jsx)(`span`,{className:vt.noteTag,children:e},e))})]},e.id))]}),(0,k.jsx)(`div`,{className:vt.editor,children:a||p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`input`,{className:vt.titleInput,value:s,onChange:e=>c(e.target.value),placeholder:`Note title…`}),(0,k.jsx)(`textarea`,{className:vt.contentArea,value:l,onChange:e=>u(e.target.value),placeholder:`Start writing…`}),(0,k.jsxs)(`div`,{className:vt.editorFooter,children:[a&&(0,k.jsx)(`button`,{className:vt.delNoteBtn,onClick:()=>b(a.id,a.title),children:e(`common.delete`)}),(0,k.jsx)(`button`,{className:vt.cancelBtn,onClick:()=>{o(null),m(!1)},children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:vt.saveBtn,onClick:y,disabled:d,children:d?`Saving…`:`Save`})]})]}):(0,k.jsx)(`div`,{className:vt.emptyEditor,children:`Select a note or create a new one`})})]})}var bt={root:`_root_18yos_1`,loading:`_loading_18yos_2`,error:`_error_18yos_3`,toolbar:`_toolbar_18yos_5`,search:`_search_18yos_6`,addBtn:`_addBtn_18yos_7`,count:`_count_18yos_10`,empty:`_empty_18yos_12`,grid:`_grid_18yos_14`,card:`_card_18yos_16`,actions:`_actions_18yos_29`,avatar:`_avatar_18yos_31`,avatarImg:`_avatarImg_18yos_38`,info:`_info_18yos_40`,name:`_name_18yos_41`,row:`_row_18yos_42`,email:`_email_18yos_43`,phone:`_phone_18yos_44`,company:`_company_18yos_45`,birthday:`_birthday_18yos_46`,iconBtn:`_iconBtn_18yos_52`,iconBtnRed:`_iconBtnRed_18yos_58`,overlay:`_overlay_18yos_61`,modal:`_modal_18yos_62`,modalTitle:`_modalTitle_18yos_63`,field:`_field_18yos_64`,label:`_label_18yos_65`,input:`_input_18yos_66`,formStatus:`_formStatus_18yos_67`,formError:`_formError_18yos_68`,modalBtns:`_modalBtns_18yos_69`,cancelBtn:`_cancelBtn_18yos_70`,saveBtn:`_saveBtn_18yos_71`},xt={name:``,email:``,phone:``,company:``,address:``,notes:``};function St(){let e=P(),t=ne(e=>e.setView),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(``),y=(0,_.useRef)(null),b=(e=``)=>{E(e?`/api/contacts?q=${encodeURIComponent(e)}`:`/api/contacts`).then(e=>{r(e?.contacts??[]),a(!1),s(``)}).catch(()=>{s(`Could not load contacts. Run nha google revoke then nha google auth.`),a(!1)})};(0,_.useEffect)(()=>{b()},[]);let x=e=>{l(e),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>b(e),400)},S=()=>{d(null),p({...xt}),v(``)},C=e=>{d(e),p({name:e.name,email:e.email??``,phone:e.phone??``,company:e.company??``,address:e.address??``,notes:e.notes??``}),v(``)},w=async()=>{if(f?.name){h(!0),v(`Saving…`);try{if(u?.resourceName){let e=await D(`/api/contacts/update`,{resourceName:u.resourceName,fields:f});if(e?.error){v(`Error: `+e.error);return}}else if(u)await D(`/api/contacts/update`,{resourceName:u.id,fields:f});else{let e=await D(`/api/contacts`,f);if(e?.error){v(`Error: `+e.error);return}}v(`Saved!`),setTimeout(()=>{p(null),d(null),b(c)},800)}catch(e){v(`Error: `+e.message)}finally{h(!1)}}},ee=(e,t)=>{e.stopPropagation(),confirm(`Delete "${t.name}"?`)&&D(`/api/contacts/delete`,{resourceName:t.resourceName||t.id}).then(e=>{let t=e;if(t?.error){alert(`Error: `+t.error);return}b(c)})},te=(e,n,r)=>{e.stopPropagation(),t(`chat`),setTimeout(()=>{let e=document.getElementById(`chatInput`);e&&(e.value=`Send an email to ${r} (${n}) about `,e.focus())},300)},T=e=>(e||`?`).split(` `).map(e=>e[0]).slice(0,2).join(``).toUpperCase();return i?(0,k.jsxs)(`div`,{className:bt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading contacts…`]}):o?(0,k.jsx)(`div`,{className:bt.error,children:o}):(0,k.jsxs)(`div`,{className:bt.root,children:[(0,k.jsxs)(`div`,{className:bt.toolbar,children:[(0,k.jsx)(`input`,{className:bt.search,value:c,onChange:e=>x(e.target.value),placeholder:`Search contacts…`}),n.length>0&&(0,k.jsxs)(`span`,{className:bt.count,children:[n.length,` contact`,n.length===1?``:`s`]}),(0,k.jsx)(`button`,{className:bt.addBtn,onClick:S,children:`+ Add`})]}),n.length===0&&(0,k.jsxs)(`div`,{className:bt.empty,children:[e(`contacts.noContacts`),(0,k.jsx)(`br`,{}),`Add a Google account or add contacts manually.`]}),(0,k.jsx)(`div`,{className:bt.grid,children:n.map(e=>(0,k.jsxs)(`div`,{className:bt.card,onClick:()=>C(e),children:[(0,k.jsx)(`div`,{className:bt.avatar,children:e.photo?(0,k.jsx)(`img`,{src:e.photo,alt:e.name,className:bt.avatarImg}):T(e.name)}),(0,k.jsxs)(`div`,{className:bt.info,children:[(0,k.jsx)(`div`,{className:bt.name,children:e.name||`(no name)`}),(0,k.jsxs)(`div`,{className:bt.row,children:[e.email&&(0,k.jsx)(`span`,{className:bt.email,children:e.email}),e.phone&&(0,k.jsx)(`span`,{className:bt.phone,children:e.phone}),e.company&&(0,k.jsxs)(`span`,{className:bt.company,children:[e.company,e.title?` · ${e.title}`:``]}),e.birthday&&(0,k.jsxs)(`span`,{className:bt.birthday,children:[`🎂 `,e.birthday]})]})]}),(0,k.jsxs)(`div`,{className:bt.actions,children:[e.email&&(0,k.jsx)(`button`,{className:bt.iconBtn,onClick:t=>te(t,e.email,e.name),title:`Send email via chat`,children:`✉`}),(0,k.jsx)(`button`,{className:bt.iconBtn,onClick:t=>{t.stopPropagation(),C(e)},title:`Edit`,children:`✎`}),(0,k.jsx)(`button`,{className:`${bt.iconBtn} ${bt.iconBtnRed}`,onClick:t=>ee(t,e),title:`Delete`,children:`✕`})]})]},e.id))}),f&&(0,k.jsx)(`div`,{className:bt.overlay,onClick:e=>{e.target===e.currentTarget&&p(null)},children:(0,k.jsxs)(`div`,{className:bt.modal,children:[(0,k.jsx)(`div`,{className:bt.modalTitle,children:u?`Edit Contact`:`New Contact`}),[[`name`,`Name`,`Full name *`],[`email`,`Email`,`user@example.com`],[`phone`,`Phone`,`+1 555 123 4567`],[`company`,`Company`,`Acme Inc`],[`address`,`Address`,`123 Main St, New York`],[`notes`,`Notes`,`Any additional info`]].map(([e,t,n])=>(0,k.jsxs)(`div`,{className:bt.field,children:[(0,k.jsx)(`label`,{className:bt.label,children:t}),(0,k.jsx)(`input`,{className:bt.input,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t.target.value}),placeholder:n,onKeyDown:t=>t.key===`Enter`&&e===`name`&&w()})]},e)),g&&(0,k.jsx)(`div`,{className:g.startsWith(`Error`)?bt.formError:bt.formStatus,children:g}),(0,k.jsxs)(`div`,{className:bt.modalBtns,children:[(0,k.jsx)(`button`,{className:bt.cancelBtn,onClick:()=>p(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:bt.saveBtn,onClick:w,disabled:m||!f.name,children:m?`…`:`Save`})]})]})})]})}var W={root:`_root_19042_2`,topbar:`_topbar_19042_11`,topbarLeft:`_topbarLeft_19042_20`,topbarTitle:`_topbarTitle_19042_21`,topbarSub:`_topbarSub_19042_22`,topbarActions:`_topbarActions_19042_23`,runBtn:`_runBtn_19042_25`,runBtnActive:`_runBtnActive_19042_32`,logBtn:`_logBtn_19042_34`,newWfBtn:`_newWfBtn_19042_41`,body:`_body_19042_50`,sidebar:`_sidebar_19042_53`,sidebarTitle:`_sidebarTitle_19042_61`,sidebarEmpty:`_sidebarEmpty_19042_65`,wfItem:`_wfItem_19042_67`,wfItemActive:`_wfItemActive_19042_78`,wfItemRow:`_wfItemRow_19042_79`,wfItemName:`_wfItemName_19042_80`,wfItemMeta:`_wfItemMeta_19042_81`,wfOn:`_wfOn_19042_82`,wfOff:`_wfOff_19042_83`,wfDelBtn:`_wfDelBtn_19042_84`,canvasArea:`_canvasArea_19042_92`,canvasHeader:`_canvasHeader_19042_94`,wfNameInput:`_wfNameInput_19042_99`,canvasHint:`_canvasHint_19042_106`,portHint:`_portHint_19042_107`,connectHint:`_connectHint_19042_108`,cancelConnectBtn:`_cancelConnectBtn_19042_109`,canvas:`_canvas_19042_92`,canvasConnecting:`_canvasConnecting_19042_122`,canvasSvg:`_canvasSvg_19042_124`,canvasNode:`_canvasNode_19042_134`,canvasNodeSelected:`_canvasNodeSelected_19042_152`,canvasNodeConnecting:`_canvasNodeConnecting_19042_153`,nodeIcon:`_nodeIcon_19042_155`,nodeLabel:`_nodeLabel_19042_156`,nodeConfigPreview:`_nodeConfigPreview_19042_157`,nodeDelBtn:`_nodeDelBtn_19042_159`,portOut:`_portOut_19042_171`,portActive:`_portActive_19042_182`,portIn:`_portIn_19042_184`,pulse:`_pulse_19042_1`,canvasDrop:`_canvasDrop_19042_195`,canvasEmpty:`_canvasEmpty_19042_203`,canvasEmptyIcon:`_canvasEmptyIcon_19042_208`,canvasEmptyTitle:`_canvasEmptyTitle_19042_209`,canvasEmptyDesc:`_canvasEmptyDesc_19042_210`,logPanel:`_logPanel_19042_213`,logHeader:`_logHeader_19042_220`,logTime:`_logTime_19042_226`,logClose:`_logClose_19042_227`,logEmpty:`_logEmpty_19042_228`,logStep:`_logStep_19042_229`,logStepError:`_logStepError_19042_230`,logStepHeader:`_logStepHeader_19042_231`,logStepIcon:`_logStepIcon_19042_232`,logStepLabel:`_logStepLabel_19042_233`,logStepErrBadge:`_logStepErrBadge_19042_234`,logStepErr:`_logStepErr_19042_230`,logStepOutput:`_logStepOutput_19042_236`,rightPanel:`_rightPanel_19042_241`,configPanel:`_configPanel_19042_252`,configHeader:`_configHeader_19042_253`,configClose:`_configClose_19042_254`,configDesc:`_configDesc_19042_255`,configFields:`_configFields_19042_256`,configField:`_configField_19042_256`,configLabel:`_configLabel_19042_258`,configRequired:`_configRequired_19042_259`,configInput:`_configInput_19042_260`,configHint:`_configHint_19042_267`,configDelete:`_configDelete_19042_269`,palette:`_palette_19042_273`,paletteTitle:`_paletteTitle_19042_274`,paletteTabs:`_paletteTabs_19042_275`,paletteTab:`_paletteTab_19042_275`,paletteTabActive:`_paletteTabActive_19042_281`,paletteNodes:`_paletteNodes_19042_282`,paletteDef:`_paletteDef_19042_284`,paletteDefIcon:`_paletteDefIcon_19042_292`,paletteDefLabel:`_paletteDefLabel_19042_293`,paletteDefDesc:`_paletteDefDesc_19042_294`,paletteFooter:`_paletteFooter_19042_296`,paletteGuide:`_paletteGuide_19042_300`,guideTitle:`_guideTitle_19042_308`,guideStep:`_guideStep_19042_317`,guideNum:`_guideNum_19042_325`,guideTip:`_guideTip_19042_341`,guideCode:`_guideCode_19042_352`},Ct=[{id:`trigger_manual`,type:`trigger`,label:`Manual`,icon:`▶`,color:`#6366f1`,description:`Run manually with optional text input.`,configFields:[{key:`input`,label:`Input text`,placeholder:`Optional initial input`}]},{id:`trigger_cron`,type:`trigger`,label:`Cron`,icon:`⏰`,color:`#fbbf24`,description:`Run on a schedule (cron expression).`,configFields:[{key:`schedule`,label:`Cron expression`,placeholder:`0 8 * * *`,required:!0}]},{id:`trigger_email`,type:`trigger`,label:`New Email`,icon:`📧`,color:`#38bdf8`,description:`Trigger when a new email arrives matching a filter.`,configFields:[{key:`filter`,label:`Gmail filter`,placeholder:`subject:TODO is:unread`}]},{id:`trigger_webhook`,type:`trigger`,label:`Webhook`,icon:`🔗`,color:`#a5b4fc`,description:`Trigger via HTTP POST.`,configFields:[{key:`path`,label:`Path`,placeholder:`/hook/my-trigger`}]},{id:`action_email`,type:`action`,label:`Send Email`,icon:`✉`,color:`#38bdf8`,description:`Send email via Gmail or IMAP.`,configFields:[{key:`to`,label:`To`,placeholder:`email@example.com`,required:!0},{key:`subject`,label:`Subject`,placeholder:`Subject or {{output}}`},{key:`body`,label:`Body`,placeholder:`{{output}}`}]},{id:`action_slack`,type:`action`,label:`Slack Message`,icon:`💬`,color:`#818cf8`,description:`Post a message to a Slack channel.`,configFields:[{key:`channel`,label:`Channel`,placeholder:`#general`,required:!0},{key:`text`,label:`Text`,placeholder:`{{output}}`}]},{id:`action_calendar`,type:`action`,label:`Create Event`,icon:`📅`,color:`#4ade80`,description:`Create a Google Calendar event.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`date`,label:`Date (YYYY-MM-DD)`,placeholder:`2025-01-15`},{key:`time`,label:`Time (HH:MM)`,placeholder:`09:00`}]},{id:`action_task`,type:`action`,label:`Create Task`,icon:`✅`,color:`#fbbf24`,description:`Add a task to your task list.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`priority`,label:`Priority`,placeholder:`medium`}]},{id:`action_drive`,type:`action`,label:`Save to Drive`,icon:`💾`,color:`#a78bfa`,description:`Save a text file to Google Drive.`,configFields:[{key:`name`,label:`Filename`,placeholder:`output.txt`,required:!0},{key:`content`,label:`Content`,placeholder:`{{output}}`}]},{id:`action_notion`,type:`action`,label:`Notion Page`,icon:`📋`,color:`#e4e4e7`,description:`Create or update a Notion page.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`content`,label:`Content`,placeholder:`{{output}}`}]},{id:`action_github`,type:`action`,label:`GitHub Issue`,icon:`🐙`,color:`#6ee7b7`,description:`Create a GitHub issue.`,configFields:[{key:`repo`,label:`Repo (owner/name)`,placeholder:`user/repo`,required:!0},{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`body`,label:`Body`,placeholder:``}]},{id:`action_webhook`,type:`action`,label:`HTTP Request`,icon:`🌐`,color:`#38bdf8`,description:`Make an HTTP request.`,configFields:[{key:`url`,label:`URL`,placeholder:`https://…`,required:!0},{key:`method`,label:`Method`,placeholder:`POST`},{key:`body`,label:`Body`,placeholder:`{{output}}`}]},{id:`ai_agent`,type:`ai`,label:`Run Agent`,icon:`🤖`,color:`#818cf8`,description:`Run any of the 38 NHA specialist agents.`,configFields:[{key:`agent`,label:`Agent name`,placeholder:`herald, saber, forge…`,required:!0},{key:`prompt`,label:`Prompt`,placeholder:`Summarize this: {{output}}`,required:!0}]},{id:`ai_summarize`,type:`ai`,label:`Summarize`,icon:`📝`,color:`#a5b4fc`,description:`Summarize text with AI (free via Liara).`,configFields:[{key:`prompt`,label:`Prompt`,placeholder:`Summarize: {{output}}`}]},{id:`ai_classify`,type:`ai`,label:`Classify`,icon:`🏷`,color:`#a5b4fc`,description:`Classify content into categories.`,configFields:[{key:`categories`,label:`Categories (comma-separated)`,placeholder:`urgent, normal, spam`},{key:`prompt`,label:`Prompt`,placeholder:`Classify this email: {{output}}`}]},{id:`ai_extract`,type:`ai`,label:`Extract Data`,icon:`🔍`,color:`#a5b4fc`,description:`Extract structured data from text.`,configFields:[{key:`prompt`,label:`What to extract`,placeholder:`Extract name, email, date from: {{output}}`}]},{id:`ai_translate`,type:`ai`,label:`Translate`,icon:`🌍`,color:`#a5b4fc`,description:`Translate text to another language.`,configFields:[{key:`lang`,label:`Target language`,placeholder:`Italian`,required:!0},{key:`prompt`,label:`Text`,placeholder:`{{output}}`}]}],wt=Object.fromEntries(Ct.map(e=>[e.id,e])),Tt=90,Et=72;function Dt(){return`n_${Date.now()}_${Math.random().toString(36).slice(2,6)}`}function Ot(e,t){return{x:e.x+(t===`out`?Tt:0),y:e.y+Et/2}}function kt(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(`trigger`),g=(0,_.useRef)(null),v=(0,_.useRef)(null),y=(0,_.useRef)(null),b=(0,_.useCallback)(async()=>{let e=(await E(`/api/workflows`).catch(()=>null))?.workflows??[];t(e),r(t=>t?e.find(e=>e.id===t.id)??e[0]??null:e[0]??null)},[]);(0,_.useEffect)(()=>{b()},[b]);let x=(0,_.useCallback)(async e=>{r(e),t(t=>t.map(t=>t.id===e.id?e:t)),await D(`/api/workflows/${e.id}`,e,`PUT`).catch(()=>null)},[]),S=async()=>{let e={id:`wf_${Date.now()}`,name:`New Workflow`,enabled:!1,nodes:[],edges:[],nodeDefs:Ct},n=(await D(`/api/workflows`,e).catch(()=>null))?.workflow??e;t(e=>[...e,n]),r(n),a(null),d([]),p(!1)},C=async e=>{confirm(`Delete this workflow?`)&&(await D(`/api/workflows/${e}`,{},`DELETE`).catch(()=>null),b())},w=(0,_.useCallback)(e=>{e.preventDefault();let t=v.current;if(!t||!n)return;let r=y.current.getBoundingClientRect(),i=Math.round((e.clientX-r.left-Tt/2)/20)*20,o=Math.round((e.clientY-r.top-Et/2)/20)*20,s={id:Dt(),defId:t,x:Math.max(0,i),y:Math.max(0,o),config:{}};x({...n,nodes:[...n.nodes,s]}),a(s.id),v.current=null},[n,x]),ee=(0,_.useCallback)((e,t)=>{if(e.stopPropagation(),o){o!==t&&n&&(n.edges.some(e=>e.from===o&&e.to===t)||x({...n,edges:[...n.edges,{from:o,to:t}]})),s(null);return}a(t);let r=n?.nodes.find(e=>e.id===t);r&&(g.current={id:t,ox:e.clientX-r.x,oy:e.clientY-r.y})},[o,n,x]),te=(0,_.useCallback)(e=>{if(!g.current||!n)return;let{id:t,ox:i,oy:a}=g.current,o=e.clientX-i,s=e.clientY-a,c=Math.max(0,Math.round(o/20)*20),l=Math.max(0,Math.round(s/20)*20);r(e=>e&&{...e,nodes:e.nodes.map(e=>e.id===t?{...e,x:c,y:l}:e)})},[n]),ne=(0,_.useCallback)(()=>{if(!g.current||!n){g.current=null;return}n.nodes.find(e=>e.id===g.current.id)&&x(n),g.current=null},[n,x]),T=(0,_.useCallback)(e=>{n&&(x({...n,nodes:n.nodes.filter(t=>t.id!==e),edges:n.edges.filter(t=>t.from!==e&&t.to!==e)}),a(null))},[n,x]),re=(0,_.useCallback)((e,t)=>{n&&x({...n,edges:n.edges.filter(n=>!(n.from===e&&n.to===t))})},[n,x]),ie=(0,_.useCallback)((e,i,a)=>{if(!n)return;let o={...n,nodes:n.nodes.map(t=>t.id===e?{...t,config:{...t.config,[i]:a}}:t)};r(o),t(e=>e.map(e=>e.id===o.id?o:e))},[n]),O=(0,_.useCallback)(()=>{n&&x(n)},[n,x]),ae=async()=>{if(!(!n||c)){l(!0),p(!0),d([]);try{let e={...n,nodeDefs:Ct};await D(`/api/workflows/${n.id}`,e,`PUT`).catch(()=>null),d((await D(`/api/workflows/${n.id}/run`,{}))?.steps??[]),b()}catch(e){d([{nodeId:`__error`,nodeLabel:`Error`,nodeIcon:`❌`,output:``,error:e.message}])}finally{l(!1)}}},A=async e=>{let i={...e,enabled:!e.enabled};await D(`/api/workflows/${e.id}`,i,`PUT`).catch(()=>null),t(t=>t.map(t=>t.id===e.id?i:t)),n?.id===e.id&&r(i)},j=n?.nodes.find(e=>e.id===i)??null,oe=j?wt[j.defId]:null;return(0,k.jsxs)(`div`,{className:W.root,children:[(0,k.jsxs)(`div`,{className:W.topbar,children:[(0,k.jsxs)(`div`,{className:W.topbarLeft,children:[(0,k.jsx)(`span`,{className:W.topbarTitle,children:`Connectors`}),(0,k.jsx)(`span`,{className:W.topbarSub,children:`Visual workflow automation · 80 tools · 38 AI agents · free AI via Liara`})]}),(0,k.jsxs)(`div`,{className:W.topbarActions,children:[n&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:`${W.runBtn} ${c?W.runBtnActive:``}`,onClick:ae,disabled:c||n.nodes.length===0,children:c?`⏳ Running…`:`▶ Run`}),(0,k.jsx)(`button`,{className:W.logBtn,onClick:()=>p(e=>!e),children:f?`Hide Log`:`📋 Log`})]}),(0,k.jsx)(`button`,{className:W.newWfBtn,onClick:S,children:`+ New Workflow`})]})]}),(0,k.jsxs)(`div`,{className:W.body,children:[(0,k.jsxs)(`div`,{className:W.sidebar,children:[(0,k.jsx)(`div`,{className:W.sidebarTitle,children:`Workflows`}),e.length===0&&(0,k.jsxs)(`div`,{className:W.sidebarEmpty,children:[`No workflows yet.`,(0,k.jsx)(`br`,{}),`Click "New Workflow" to start.`]}),e.map(e=>(0,k.jsxs)(`div`,{className:`${W.wfItem} ${n?.id===e.id?W.wfItemActive:``}`,onClick:()=>{r(e),a(null),d(e.lastRun?.steps??[]),p(!1)},children:[(0,k.jsxs)(`div`,{className:W.wfItemRow,children:[(0,k.jsx)(`span`,{className:W.wfItemName,children:e.name}),(0,k.jsx)(`button`,{className:e.enabled?W.wfOn:W.wfOff,onClick:t=>{t.stopPropagation(),A(e)},children:e.enabled?`ON`:`OFF`})]}),(0,k.jsxs)(`div`,{className:W.wfItemMeta,children:[e.nodes.length,` nodes · `,e.edges.length,` edges`,e.lastRun&&(0,k.jsxs)(`span`,{children:[` · ran `,new Date(e.lastRun.at).toLocaleTimeString()]})]}),(0,k.jsx)(`button`,{className:W.wfDelBtn,onClick:t=>{t.stopPropagation(),C(e.id)},children:`✕`})]},e.id))]}),(0,k.jsx)(`div`,{className:W.canvasArea,children:n?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:W.canvasHeader,children:[(0,k.jsx)(`input`,{className:W.wfNameInput,value:n.name,onChange:e=>r(t=>t&&{...t,name:e.target.value}),onBlur:()=>n&&x(n)}),o?(0,k.jsxs)(`span`,{className:W.connectHint,children:[`Click a target node to connect · `,(0,k.jsx)(`button`,{className:W.cancelConnectBtn,onClick:()=>s(null),children:`Cancel`})]}):(0,k.jsxs)(`span`,{className:W.canvasHint,children:[`Drag nodes from palette · Click `,(0,k.jsx)(`span`,{className:W.portHint,children:`▶`}),` to connect · Drag nodes to reposition`]})]}),(0,k.jsxs)(`div`,{ref:y,className:`${W.canvas} ${o?W.canvasConnecting:``}`,onMouseMove:te,onMouseUp:ne,onMouseLeave:ne,onDragOver:e=>e.preventDefault(),onDrop:w,onClick:()=>{o||a(null)},children:[(0,k.jsx)(`svg`,{className:W.canvasSvg,children:n.edges.map((e,t)=>{let r=n.nodes.find(t=>t.id===e.from),i=n.nodes.find(t=>t.id===e.to);if(!r||!i)return null;let a=Ot(r,`out`),o=Ot(i,`in`),s=(a.x+o.x)/2;return(0,k.jsxs)(`g`,{children:[(0,k.jsx)(`path`,{d:`M${a.x},${a.y} C${s},${a.y} ${s},${o.y} ${o.x},${o.y}`,stroke:`var(--green3)`,strokeWidth:`2`,fill:`none`,strokeDasharray:`6,3`,opacity:`0.8`}),(0,k.jsx)(`path`,{d:`M${a.x},${a.y} C${s},${a.y} ${s},${o.y} ${o.x},${o.y}`,stroke:`transparent`,strokeWidth:`12`,fill:`none`,style:{cursor:`pointer`},onClick:t=>{t.stopPropagation(),re(e.from,e.to)}}),(0,k.jsx)(`circle`,{cx:s,cy:(a.y+o.y)/2,r:`7`,fill:`var(--bg2)`,stroke:`var(--border)`,strokeWidth:`1.5`,style:{cursor:`pointer`},onClick:t=>{t.stopPropagation(),re(e.from,e.to)}}),(0,k.jsx)(`text`,{x:s,y:(a.y+o.y)/2+4,textAnchor:`middle`,fill:`var(--dim)`,fontSize:`9`,style:{cursor:`pointer`,pointerEvents:`none`},children:`✕`})]},t)})}),n.nodes.map(e=>{let t=wt[e.defId];if(!t)return null;let n=i===e.id,r=o===e.id;return(0,k.jsxs)(`div`,{className:`${W.canvasNode} ${n?W.canvasNodeSelected:``} ${r?W.canvasNodeConnecting:``}`,style:{left:e.x,top:e.y,borderColor:t.color+(n?`ff`:`88`),background:t.color+`18`},onMouseDown:t=>ee(t,e.id),onClick:e=>e.stopPropagation(),children:[(0,k.jsx)(`button`,{className:W.nodeDelBtn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),T(e.id)},children:`✕`}),(0,k.jsx)(`span`,{className:W.nodeIcon,children:t.icon}),(0,k.jsx)(`span`,{className:W.nodeLabel,style:{color:t.color},children:t.label}),Object.values(e.config).filter(Boolean).slice(0,1).map((e,t)=>(0,k.jsx)(`span`,{className:W.nodeConfigPreview,children:String(e).slice(0,14)},t)),(0,k.jsx)(`button`,{className:`${W.portOut} ${r?W.portActive:``}`,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),s(t=>t===e.id?null:e.id)},title:`Connect from here`,children:`▶`}),o&&o!==e.id&&(0,k.jsx)(`button`,{className:W.portIn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),ee(t,e.id)},title:`Connect here`,children:`◀`})]},e.id)}),n.nodes.length===0&&(0,k.jsx)(`div`,{className:W.canvasDrop,children:`Drag nodes from the right panel and drop here`})]}),f&&(0,k.jsxs)(`div`,{className:W.logPanel,children:[(0,k.jsxs)(`div`,{className:W.logHeader,children:[(0,k.jsx)(`span`,{children:`Run Log`}),n.lastRun&&(0,k.jsx)(`span`,{className:W.logTime,children:new Date(n.lastRun.at).toLocaleString()}),(0,k.jsx)(`button`,{className:W.logClose,onClick:()=>p(!1),children:`✕`})]}),u.length===0&&(0,k.jsx)(`div`,{className:W.logEmpty,children:c?`Running…`:`No run results yet.`}),u.map((e,t)=>(0,k.jsxs)(`div`,{className:`${W.logStep} ${e.error?W.logStepError:``}`,children:[(0,k.jsxs)(`div`,{className:W.logStepHeader,children:[(0,k.jsx)(`span`,{className:W.logStepIcon,children:e.nodeIcon}),(0,k.jsx)(`span`,{className:W.logStepLabel,children:e.nodeLabel}),e.error&&(0,k.jsx)(`span`,{className:W.logStepErrBadge,children:`ERROR`})]}),e.error&&(0,k.jsx)(`div`,{className:W.logStepErr,children:e.error}),e.output&&(0,k.jsx)(`div`,{className:W.logStepOutput,dangerouslySetInnerHTML:{__html:fe(e.output.slice(0,500))}})]},t))]})]}):(0,k.jsxs)(`div`,{className:W.canvasEmpty,children:[(0,k.jsx)(`div`,{className:W.canvasEmptyIcon,children:`🔗`}),(0,k.jsx)(`div`,{className:W.canvasEmptyTitle,children:`Select or create a workflow`}),(0,k.jsxs)(`div`,{className:W.canvasEmptyDesc,children:[`Drag nodes from the right panel onto the canvas.`,(0,k.jsx)(`br`,{}),`Connect them by clicking the `,(0,k.jsx)(`span`,{className:W.portHint,children:`▶`}),` output port then the target node.`,(0,k.jsx)(`br`,{}),`Run with one click — all 80 NHA tools already authenticated.`]}),(0,k.jsx)(`button`,{className:W.newWfBtn,onClick:S,children:`+ New Workflow`})]})}),(0,k.jsx)(`div`,{className:W.rightPanel,children:j&&oe?(0,k.jsxs)(`div`,{className:W.configPanel,children:[(0,k.jsxs)(`div`,{className:W.configHeader,children:[(0,k.jsxs)(`span`,{style:{color:oe.color},children:[oe.icon,` `,oe.label]}),(0,k.jsx)(`button`,{className:W.configClose,onClick:()=>a(null),children:`✕`})]}),(0,k.jsx)(`div`,{className:W.configDesc,children:oe.description}),(0,k.jsx)(`div`,{className:W.configFields,children:(oe.configFields??[]).map(e=>(0,k.jsxs)(`div`,{className:W.configField,children:[(0,k.jsxs)(`label`,{className:W.configLabel,children:[e.label,e.required&&(0,k.jsx)(`span`,{className:W.configRequired,children:`*`})]}),(0,k.jsx)(`input`,{className:W.configInput,value:j.config[e.key]??``,placeholder:e.placeholder??``,onChange:t=>ie(j.id,e.key,t.target.value),onBlur:O}),(e.placeholder?.includes(`{{`)??!1)&&(0,k.jsxs)(`div`,{className:W.configHint,children:[`Use `,(0,k.jsx)(`code`,{children:`{{output}}`}),` to pass previous node result`]})]},e.key))}),(0,k.jsx)(`button`,{className:W.configDelete,onClick:()=>T(j.id),children:`Delete node`})]}):(0,k.jsxs)(`div`,{className:W.palette,children:[(0,k.jsx)(`div`,{className:W.paletteTitle,children:`Node Palette`}),(0,k.jsx)(`div`,{className:W.paletteTabs,children:[{id:`trigger`,label:`Triggers`,color:`#fbbf24`},{id:`action`,label:`Actions`,color:`#38bdf8`},{id:`ai`,label:`AI`,color:`#a5b4fc`}].map(e=>(0,k.jsx)(`button`,{className:`${W.paletteTab} ${m===e.id?W.paletteTabActive:``}`,style:m===e.id?{borderColor:e.color,color:e.color}:{},onClick:()=>h(e.id),children:e.label},e.id))}),(0,k.jsx)(`div`,{className:W.paletteNodes,children:Ct.filter(e=>e.type===m).map(e=>(0,k.jsxs)(`div`,{className:W.paletteDef,style:{borderColor:e.color+`44`,background:e.color+`14`},draggable:!0,onDragStart:()=>{v.current=e.id},onDragEnd:()=>{v.current=null},children:[(0,k.jsx)(`span`,{className:W.paletteDefIcon,children:e.icon}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:W.paletteDefLabel,style:{color:e.color},children:e.label}),(0,k.jsx)(`div`,{className:W.paletteDefDesc,children:e.description})]})]},e.id))}),(0,k.jsxs)(`div`,{className:W.paletteGuide,children:[(0,k.jsx)(`div`,{className:W.guideTitle,children:`How to use Connectors`}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`1`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Create`}),` a workflow with "+ New Workflow"`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`2`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Drag`}),` a Trigger node (e.g. Manual, Cron) onto the canvas`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`3`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Drag`}),` Action or AI nodes to chain operations`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`4`}),(0,k.jsxs)(`span`,{children:[`Click the `,(0,k.jsx)(`strong`,{style:{color:`var(--green3)`},children:`▶`}),` port on a node then click the next to `,(0,k.jsx)(`strong`,{children:`connect`}),` them`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`5`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Click`}),` a node to configure it — use `,(0,k.jsx)(`code`,{className:W.guideCode,children:`{{output}}`}),` to pass the previous result`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`6`}),(0,k.jsxs)(`span`,{children:[`Press `,(0,k.jsx)(`strong`,{children:`▶ Run`}),` to execute · toggle `,(0,k.jsx)(`strong`,{children:`ON`}),` to run automatically (cron/webhook)`]})]}),(0,k.jsxs)(`div`,{className:W.guideTip,children:[(0,k.jsx)(`strong`,{children:`Tip:`}),` Click an edge to delete it. Drag nodes on the canvas to reposition. All 80 NHA tools are pre-authenticated — no extra setup.`]}),(0,k.jsxs)(`div`,{className:W.guideTip,children:[(0,k.jsx)(`strong`,{children:`AI nodes`}),` use Liara (free) by default. They receive `,(0,k.jsx)(`code`,{className:W.guideCode,children:`{{output}}`}),` from the previous step automatically.`]})]})]})})]})]})}var G={root:`_root_1ssbe_1`,sidebar:`_sidebar_1ssbe_12`,sidebarSection:`_sidebarSection_1ssbe_23`,sidebarLabel:`_sidebarLabel_1ssbe_28`,accountSelect:`_accountSelect_1ssbe_36`,sidebarCompose:`_sidebarCompose_1ssbe_46`,composeBtn:`_composeBtn_1ssbe_51`,folderList:`_folderList_1ssbe_63`,folderItem:`_folderItem_1ssbe_69`,folderActive:`_folderActive_1ssbe_82`,badge:`_badge_1ssbe_88`,labelHeader:`_labelHeader_1ssbe_103`,addLabelBtn:`_addLabelBtn_1ssbe_114`,newLabelRow:`_newLabelRow_1ssbe_123`,newLabelInput:`_newLabelInput_1ssbe_129`,newLabelSave:`_newLabelSave_1ssbe_139`,labelDot:`_labelDot_1ssbe_150`,syncArea:`_syncArea_1ssbe_158`,syncBtn:`_syncBtn_1ssbe_163`,messageList:`_messageList_1ssbe_175`,listHeader:`_listHeader_1ssbe_185`,searchInput:`_searchInput_1ssbe_194`,searchBtn:`_searchBtn_1ssbe_204`,listBody:`_listBody_1ssbe_214`,listLoading:`_listLoading_1ssbe_219`,noMessages:`_noMessages_1ssbe_224`,msgRow:`_msgRow_1ssbe_231`,msgUnread:`_msgUnread_1ssbe_242`,msgActive:`_msgActive_1ssbe_247`,msgTop:`_msgTop_1ssbe_251`,msgFrom:`_msgFrom_1ssbe_257`,msgDate:`_msgDate_1ssbe_270`,msgSubject:`_msgSubject_1ssbe_277`,msgPreview:`_msgPreview_1ssbe_289`,listFooter:`_listFooter_1ssbe_300`,loadMoreBtn:`_loadMoreBtn_1ssbe_311`,pane:`_pane_1ssbe_322`,emptyPane:`_emptyPane_1ssbe_330`,readingPane:`_readingPane_1ssbe_337`,paneToolbar:`_paneToolbar_1ssbe_344`,paneActions:`_paneActions_1ssbe_354`,replyBtn:`_replyBtn_1ssbe_360`,fwdBtn:`_fwdBtn_1ssbe_371`,trashBtn:`_trashBtn_1ssbe_371`,starBtn:`_starBtn_1ssbe_371`,aiBtn:`_aiBtn_1ssbe_384`,labelSelect:`_labelSelect_1ssbe_394`,paneHeader:`_paneHeader_1ssbe_403`,paneSubject:`_paneSubject_1ssbe_409`,paneMeta:`_paneMeta_1ssbe_416`,attachments:`_attachments_1ssbe_424`,attachLink:`_attachLink_1ssbe_431`,paneBody:`_paneBody_1ssbe_441`,bodyFrame:`_bodyFrame_1ssbe_447`,bodyText:`_bodyText_1ssbe_455`,composePane:`_composePane_1ssbe_465`,composeTitle:`_composeTitle_1ssbe_474`,composeField:`_composeField_1ssbe_483`,templateRow:`_templateRow_1ssbe_495`,templateToggle:`_templateToggle_1ssbe_500`,templateDrop:`_templateDrop_1ssbe_510`,templateItem:`_templateItem_1ssbe_524`,templateSubject:`_templateSubject_1ssbe_534`,composeBody:`_composeBody_1ssbe_540`,composeActions:`_composeActions_1ssbe_556`,sendBtn:`_sendBtn_1ssbe_563`,cancelBtn:`_cancelBtn_1ssbe_574`,compStatus:`_compStatus_1ssbe_584`,ok:`_ok_1ssbe_585`,err:`_err_1ssbe_586`},At=[{id:`INBOX`,name:`Inbox`,icon:`✉`},{id:`SENT`,name:`Sent`,icon:`→`},{id:`DRAFTS`,name:`Drafts`,icon:`📄`},{id:`SPAM`,name:`Spam`,icon:`🛡`},{id:`TRASH`,name:`Trash`,icon:`🗑`}],jt=[{name:`Product Promo`,subject:`Discover our offer on [PRODUCT]`},{name:`Monthly Newsletter`,subject:`[COMPANY] Newsletter — [MONTH] [YEAR]`},{name:`Commercial Follow-up`,subject:`Following our conversation — [TOPIC]`},{name:`Offer / Quote`,subject:`Offer [NUMBER] — [SUBJECT]`},{name:`Event Invitation`,subject:`You are invited: [EVENT NAME] — [DATE]`},{name:`Customer Thank You`,subject:`Thank you for your trust, [NAME]`}];function Mt(e){return e?e.slice(0,10):``}function Nt(e){if(!e)return``;try{let t=typeof e==`string`?JSON.parse(e):e;return Array.isArray(t)?t.map(e=>e.name?`${e.name} <${e.address}>`:e.address||``).join(`, `):String(e)}catch{return String(e)}}function Pt(){let e=P(),t=ne(e=>e.setView),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(`google`),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(`INBOX`),[m,h]=(0,_.useState)([]),[g,v]=(0,_.useState)(0),[y,b]=(0,_.useState)(0),[x,S]=(0,_.useState)(null),[C,w]=(0,_.useState)(null),[ee,te]=(0,_.useState)(!1),[T,re]=(0,_.useState)(!1),[ie,O]=(0,_.useState)(``),[ae,A]=(0,_.useState)(``),[j,oe]=(0,_.useState)(0),[se,M]=(0,_.useState)(!1),[ce,N]=(0,_.useState)({}),[F,le]=(0,_.useState)(``),[ue,de]=(0,_.useState)(``),[fe,I]=(0,_.useState)(``),[pe,me]=(0,_.useState)(``),[he,ge]=(0,_.useState)(``),[L,_e]=(0,_.useState)(!1),[ve,ye]=(0,_.useState)(``),[R,z]=(0,_.useState)(!1),be=(0,_.useRef)(null);(0,_.useEffect)(()=>{E(`/api/config`).then(e=>r(!!e?.hasGoogle)),E(`/api/imap/accounts`).then(e=>{let t=e?.accounts??[];a(t),t.length>0?xe(t[0].id,`imap`):xe(`google`,`google`)})},[]);let xe=(e,t)=>{s(e),l(t),p(t===`google`?`INBOX`:null),h([]),b(0),S(null),w(null),t===`imap`?E(`/api/imap/labels?accountId=${e}`).then(t=>{let n=t?.labels??[];d(n);let r=n.find(e=>e.system_type===`inbox`)?.id??null;p(r),Se(e,r,0,``)}):(d([]),Ce(`INBOX`,``))},Se=(e,t,n,r)=>{te(!0);let i=`/api/imap/messages?accountId=${encodeURIComponent(e)}&limit=50&offset=${n}`;t&&(i+=`&labelId=${encodeURIComponent(t)}`),r&&(i+=`&search=${encodeURIComponent(r)}`),E(i).then(e=>{h(n===0?e?.messages??[]:t=>[...t,...e?.messages??[]]),v(e?.total??0),te(!1)}).catch(()=>te(!1))},Ce=(e,t)=>{te(!0);let n=e===`INBOX`||!e?`all`:e.toLowerCase(),r=`/api/emails?filter=${encodeURIComponent(t||n)}&page=0&pageSize=50`;t&&(r=`/api/emails?filter=${encodeURIComponent(t)}&page=0&pageSize=50`),E(r).then(e=>{let t=(e?.emails??[]).map(e=>({id:e.id,subject:e.subject,from_name:e.from,from_address:e.from,internal_date:e.date,body_preview:e.snippet,is_read:!e.isUnread,is_starred:!1,has_attachments:!1,_google:!0}));h(t),v(t.length);let n=t.filter(e=>!e.is_read).length;oe(n),te(!1)}).catch(()=>te(!1))},we=()=>{O(ae),b(0),h([]),c===`imap`&&o?Se(o,f,0,ae):Ce(f??`INBOX`,ae)},Te=e=>{S(e),M(!1),re(!0),c===`google`?D(`/api/email/read`,{messageId:e}).then(t=>{w({...t?.message??t,id:e,_google:!0}),re(!1),D(`/api/email/mark-read`,{messageId:e}).catch(()=>{})}).catch(()=>re(!1)):E(`/api/imap/message?id=${encodeURIComponent(e)}`).then(t=>{w(t?.message??null),h(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),re(!1)}).catch(()=>re(!1))},Ee=(e={})=>{M(!0),N(e),le(e.to??``),de(``),I(e.subject??``),me(e.type===`forward`&&e.body?`\n\n---------- Forwarded message ----------\n${e.body}`:``),ge(``),_e(!1),S(null),w(null)},De=async()=>{if(!F.trim()){ge(`Recipient required`);return}ge(`Sending…`);try{if(c===`imap`&&o){let e=await D(`/api/imap/send`,{accountId:o,to:F.trim(),cc:ue.trim()||void 0,subject:fe.trim(),bodyHtml:pe.replace(/\n/g,`<br>`),bodyText:pe,inReplyTo:ce.inReplyTo||void 0});e?.ok?(ge(`Sent!`),setTimeout(()=>M(!1),800)):ge(e?.error??`Error`)}else{let e=await D(`/api/email/send`,{to:F.trim(),subject:fe.trim(),body:pe});e?.ok||e?.id?(ge(`Sent!`),setTimeout(()=>M(!1),800)):ge(e?.error??`Error`)}}catch(e){ge(e.message??`Error`)}},Oe=e=>{confirm(`Move to trash? Email stays on the server.`)&&D(`/api/imap/trash`,{messageId:e}).then(()=>{h(t=>t.filter(t=>t.id!==e)),w(null),S(null)})},B=(e,t)=>{D(`/api/imap/mark-starred`,{messageId:e,isStarred:t}).then(()=>{C?.id===e&&w(e=>e&&{...e,is_starred:t})})},ke=(e,t)=>{t&&D(`/api/imap/labels/assign`,{messageId:e,labelId:t})},Ae=()=>{!ve.trim()||!o||D(`/api/imap/labels`,{accountId:o,name:ve.trim()}).then(()=>{z(!1),ye(``),E(`/api/imap/labels?accountId=${o}`).then(e=>d(e?.labels??[]))})};return(0,k.jsxs)(`div`,{className:G.root,children:[(0,k.jsxs)(`div`,{className:G.sidebar,children:[(0,k.jsxs)(`div`,{className:G.sidebarSection,children:[(0,k.jsx)(`div`,{className:G.sidebarLabel,children:`Account`}),(0,k.jsxs)(`select`,{className:G.accountSelect,value:c===`google`?`google`:`imap:${o}`,onChange:e=>{let t=e.target.value;t===`google`?xe(`google`,`google`):t.startsWith(`imap:`)&&xe(t.slice(5),`imap`)},children:[n&&(0,k.jsx)(`option`,{value:`google`,children:`Google (Gmail)`}),i.map(e=>(0,k.jsx)(`option`,{value:`imap:${e.id}`,children:e.display_name||e.email_address},e.id)),!n&&i.length===0&&(0,k.jsx)(`option`,{value:``,children:`No accounts — add in Settings`})]})]}),(0,k.jsx)(`div`,{className:G.sidebarCompose,children:(0,k.jsx)(`button`,{className:G.composeBtn,onClick:()=>Ee(),children:`+ Compose`})}),(0,k.jsx)(`div`,{className:G.folderList,children:c===`google`?At.map(e=>(0,k.jsxs)(`div`,{className:`${G.folderItem} ${f===e.id?G.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),Ce(e.id,ie)},children:[(0,k.jsx)(`span`,{children:e.icon}),(0,k.jsx)(`span`,{children:e.name}),e.id===`INBOX`&&j>0&&(0,k.jsx)(`span`,{className:G.badge,children:j})]},e.id)):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:G.labelHeader,children:[(0,k.jsx)(`span`,{children:`Labels`}),(0,k.jsx)(`button`,{className:G.addLabelBtn,onClick:()=>z(e=>!e),children:`+`})]}),R&&(0,k.jsxs)(`div`,{className:G.newLabelRow,children:[(0,k.jsx)(`input`,{className:G.newLabelInput,value:ve,onChange:e=>ye(e.target.value),placeholder:`Label name`,onKeyDown:e=>e.key===`Enter`&&Ae()}),(0,k.jsx)(`button`,{className:G.newLabelSave,onClick:Ae,children:`+`})]}),u.map(e=>(0,k.jsxs)(`div`,{className:`${G.folderItem} ${f===e.id?G.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),o&&Se(o,e.id,0,ie)},children:[(0,k.jsx)(`span`,{className:G.labelDot,style:{background:e.color??`var(--dim)`}}),(0,k.jsx)(`span`,{children:e.name}),e.unread_count?(0,k.jsx)(`span`,{className:G.badge,children:e.unread_count}):null]},e.id))]})}),c===`imap`&&o&&(0,k.jsx)(`div`,{className:G.syncArea,children:(0,k.jsx)(`button`,{className:G.syncBtn,onClick:()=>{o&&c===`imap`&&D(`/api/imap/sync/${o}`,{})},children:`Sync now`})})]}),(0,k.jsxs)(`div`,{className:G.messageList,children:[(0,k.jsxs)(`div`,{className:G.listHeader,children:[(0,k.jsx)(`input`,{className:G.searchInput,value:ae,onChange:e=>A(e.target.value),placeholder:`Search…`,onKeyDown:e=>e.key===`Enter`&&we()}),(0,k.jsx)(`button`,{className:G.searchBtn,onClick:we,children:`Go`})]}),(0,k.jsxs)(`div`,{className:G.listBody,children:[ee&&(0,k.jsx)(`div`,{className:G.listLoading,children:(0,k.jsx)(`div`,{className:`spinner`})}),!ee&&m.length===0&&(0,k.jsx)(`div`,{className:G.noMessages,children:`No messages`}),m.map(e=>(0,k.jsxs)(`div`,{className:`${G.msgRow} ${e.id===x?G.msgActive:``} ${e.is_read?``:G.msgUnread}`,onClick:()=>Te(e.id),children:[(0,k.jsxs)(`div`,{className:G.msgTop,children:[(0,k.jsx)(`span`,{className:G.msgFrom,children:e.from_name||e.from_address||``}),(0,k.jsx)(`span`,{className:G.msgDate,children:Mt(e.internal_date)})]}),(0,k.jsx)(`div`,{className:G.msgSubject,children:e.subject||`(no subject)`}),(0,k.jsx)(`div`,{className:G.msgPreview,children:(e.body_preview||``).slice(0,80)})]},e.id))]}),(0,k.jsxs)(`div`,{className:G.listFooter,children:[(0,k.jsxs)(`span`,{children:[g,` messages`]}),m.length<g&&c===`imap`&&(0,k.jsx)(`button`,{className:G.loadMoreBtn,onClick:()=>{let e=y+50;b(e),o&&Se(o,f,e,ie)},children:`Load more`})]})]}),(0,k.jsx)(`div`,{className:G.pane,children:(()=>{if(se)return(0,k.jsxs)(`div`,{className:G.composePane,children:[(0,k.jsx)(`div`,{className:G.composeTitle,children:e(`email.compose`)}),(0,k.jsx)(`input`,{className:G.composeField,value:F,onChange:e=>le(e.target.value),placeholder:`To`}),(0,k.jsx)(`input`,{className:G.composeField,value:ue,onChange:e=>de(e.target.value),placeholder:`Cc`}),(0,k.jsx)(`input`,{className:G.composeField,value:fe,onChange:e=>I(e.target.value),placeholder:`Subject`}),(0,k.jsxs)(`div`,{className:G.templateRow,children:[(0,k.jsx)(`button`,{className:G.templateToggle,onClick:()=>_e(e=>!e),children:`📄 Templates`}),L&&(0,k.jsx)(`div`,{className:G.templateDrop,children:jt.map((e,t)=>(0,k.jsxs)(`div`,{className:G.templateItem,onClick:()=>{I(t=>t||e.subject),_e(!1)},children:[(0,k.jsx)(`strong`,{children:e.name}),(0,k.jsx)(`div`,{className:G.templateSubject,children:e.subject})]},t))})]}),(0,k.jsx)(`textarea`,{className:G.composeBody,value:pe,onChange:e=>me(e.target.value),placeholder:`Write your message…`}),(0,k.jsxs)(`div`,{className:G.composeActions,children:[(0,k.jsx)(`button`,{className:G.sendBtn,onClick:De,children:e(`email.send_ok`)}),(0,k.jsx)(`button`,{className:G.cancelBtn,onClick:()=>M(!1),children:`Discard`}),he&&(0,k.jsx)(`span`,{className:`${G.compStatus} ${he===`Sent!`?G.ok:G.err}`,children:he})]})]});if(T)return(0,k.jsx)(`div`,{className:G.emptyPane,children:(0,k.jsx)(`div`,{className:`spinner`})});if(!C)return(0,k.jsx)(`div`,{className:G.emptyPane,children:`Select a message`});let n=Nt(C.to_addresses);return(0,k.jsxs)(`div`,{className:G.readingPane,children:[(0,k.jsx)(`div`,{className:G.paneToolbar,children:(0,k.jsxs)(`div`,{className:G.paneActions,children:[(0,k.jsx)(`button`,{className:G.replyBtn,onClick:()=>Ee({to:C.from_address,subject:`Re: ${C.subject??``}`,inReplyTo:C.message_id??C.id,replyTo:C.id,type:`reply`}),children:e(`email.reply`)}),(0,k.jsx)(`button`,{className:G.fwdBtn,onClick:()=>Ee({subject:`Fwd: ${C.subject??``}`,type:`forward`,body:C.body_text??C.body_preview??``}),children:`Forward`}),!C._google&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:G.trashBtn,onClick:()=>Oe(C.id),children:`🗑`}),(0,k.jsx)(`button`,{className:G.starBtn,onClick:()=>B(C.id,!C.is_starred),children:C.is_starred?`★`:`☆`}),u.length>0&&(0,k.jsxs)(`select`,{className:G.labelSelect,defaultValue:``,onChange:e=>ke(C.id,e.target.value),children:[(0,k.jsx)(`option`,{value:``,children:`+ Label`}),u.map(e=>(0,k.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,k.jsx)(`button`,{className:G.aiBtn,onClick:()=>t(`chat`),children:`Ask AI`})]})}),(0,k.jsxs)(`div`,{className:G.paneHeader,children:[(0,k.jsx)(`div`,{className:G.paneSubject,children:C.subject||`(no subject)`}),(0,k.jsxs)(`div`,{className:G.paneMeta,children:[(0,k.jsx)(`strong`,{children:`From:`}),` `,C.from_name&&C.from_name!==C.from_address?`${C.from_name} <${C.from_address}>`:C.from_address]}),(0,k.jsxs)(`div`,{className:G.paneMeta,children:[(0,k.jsx)(`strong`,{children:`To:`}),` `,n]}),(0,k.jsxs)(`div`,{className:G.paneMeta,children:[(0,k.jsx)(`strong`,{children:`Date:`}),` `,C.internal_date]}),C.attachments&&C.attachments.length>0&&(0,k.jsx)(`div`,{className:G.attachments,children:C.attachments.map((e,t)=>(0,k.jsxs)(`a`,{className:G.attachLink,href:`/api/imap/attachment?messageId=${encodeURIComponent(C.id)}&partId=${encodeURIComponent(e.part_id??``)}&accountId=${encodeURIComponent(o??``)}`,download:e.filename??`attachment`,children:[`📎 `,e.filename??`attachment`,` (`,Math.round((e.size_bytes??0)/1024),`KB)`]},t))})]}),(0,k.jsx)(`div`,{className:G.paneBody,children:C.body_html?(0,k.jsx)(`iframe`,{ref:be,sandbox:`allow-same-origin`,className:G.bodyFrame,srcDoc:C.body_html,title:`Email body`}):(0,k.jsx)(`pre`,{className:G.bodyText,children:C.body_text??C.body_preview??`(empty)`})})]})})()})]})}var K={root:`_root_1u06k_1`,center:`_center_1u06k_10`,noGoogle:`_noGoogle_1u06k_17`,noGoogleIcon:`_noGoogleIcon_1u06k_26`,noGoogleTitle:`_noGoogleTitle_1u06k_27`,noGoogleSub:`_noGoogleSub_1u06k_28`,connectBtn:`_connectBtn_1u06k_30`,calCol:`_calCol_1u06k_42`,navRow:`_navRow_1u06k_50`,navBtn:`_navBtn_1u06k_57`,monthTitle:`_monthTitle_1u06k_70`,dayHeaders:`_dayHeaders_1u06k_78`,dayHeader:`_dayHeader_1u06k_78`,weekend:`_weekend_1u06k_92`,grid:`_grid_1u06k_94`,cell:`_cell_1u06k_103`,emptyCell:`_emptyCell_1u06k_119`,weekendCell:`_weekendCell_1u06k_121`,todayCell:`_todayCell_1u06k_122`,activeCell:`_activeCell_1u06k_123`,hasEvtsCell:`_hasEvtsCell_1u06k_124`,holidayCell:`_holidayCell_1u06k_125`,dayNum:`_dayNum_1u06k_127`,todayNum:`_todayNum_1u06k_133`,weekendNum:`_weekendNum_1u06k_134`,evtPills:`_evtPills_1u06k_136`,evtPill:`_evtPill_1u06k_136`,holidayPill:`_holidayPill_1u06k_156`,morePill:`_morePill_1u06k_158`,loadingBar:`_loadingBar_1u06k_164`,detailCol:`_detailCol_1u06k_173`,detailHeader:`_detailHeader_1u06k_184`,detailDate:`_detailDate_1u06k_192`,addEvtBtn:`_addEvtBtn_1u06k_198`,noEvts:`_noEvts_1u06k_210`,selectDay:`_selectDay_1u06k_217`,evtCard:`_evtCard_1u06k_224`,evtTop:`_evtTop_1u06k_234`,evtTime:`_evtTime_1u06k_241`,evtBtns:`_evtBtns_1u06k_247`,editBtn:`_editBtn_1u06k_253`,delBtn:`_delBtn_1u06k_263`,readOnly:`_readOnly_1u06k_273`,evtTitle:`_evtTitle_1u06k_280`,evtLoc:`_evtLoc_1u06k_286`,evtMeta:`_evtMeta_1u06k_287`,attendees:`_attendees_1u06k_289`,attendee:`_attendee_1u06k_289`,evtDesc:`_evtDesc_1u06k_300`,joinBtn:`_joinBtn_1u06k_310`,gcalLink:`_gcalLink_1u06k_317`,overlay:`_overlay_1u06k_324`,formCard:`_formCard_1u06k_334`,formTitle:`_formTitle_1u06k_348`,formLabel:`_formLabel_1u06k_355`,formInput:`_formInput_1u06k_361`,formTextarea:`_formTextarea_1u06k_374`,formError:`_formError_1u06k_390`,formBtns:`_formBtns_1u06k_395`,cancelFormBtn:`_cancelFormBtn_1u06k_402`,saveFormBtn:`_saveFormBtn_1u06k_412`};function Ft(e,t,n){return`${e}-${String(t+1).padStart(2,`0`)}-${String(n).padStart(2,`0`)}`}function It(e,t,n){let r=new Date;return r.getFullYear()===e&&r.getMonth()===t&&r.getDate()===n}function Lt(e){if(!e)return``;let t=new Date(e);return isNaN(t.getTime())?e.slice(11,16):t.toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`})}function Rt(){let e=P(),t=ne(e=>e.setView),[n,r]=(0,_.useState)(null),i=new Date,[a,o]=(0,_.useState)(i.getFullYear()),[s,c]=(0,_.useState)(i.getMonth()),[l,u]=(0,_.useState)({}),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(``),[b,x]=(0,_.useState)(!1);(0,_.useEffect)(()=>{E(`/api/config`).then(e=>r(!!e?.hasGoogle))},[]);let S=(0,_.useCallback)((e,t)=>{let n=`${e}-${String(t+1).padStart(2,`0`)}`;f(!0),E(`/api/calendar?month=${n}`).then(e=>{e?.byDate&&u(t=>({...t,...e.byDate})),f(!1)}).catch(()=>f(!1))},[]);(0,_.useEffect)(()=>{n&&S(a,s)},[n,a,s,S]);let C=e=>{E(`/api/calendar?date=${e}`).then(t=>{u(n=>({...n,[e]:t?.events??[]}))})},w=(e,t,n)=>{confirm(`Delete this event?`)&&D(`/api/calendar/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{},`DELETE`).then(()=>C(n))},ee=e=>{g({title:``,start:`${e}T09:00`,end:`${e}T10:00`,location:``,description:``,isEdit:!1}),y(``)},te=(e,t)=>{let n=e.start?e.start.slice(0,16):`${t}T09:00`,r=e.end?e.end.slice(0,16):`${t}T10:00`;g({id:e.id,calId:e.calendarId??`primary`,title:e.summary,start:n,end:r,location:e.location??``,description:e.description??``,isEdit:!0}),y(``)},T=async()=>{if(h){if(!h.title.trim()){y(`Title is required`);return}x(!0);try{if(h.isEdit&&h.id){let e=h.calId??`primary`;await D(`/api/calendar/${encodeURIComponent(e)}/${encodeURIComponent(h.id)}`,{summary:h.title,start:h.start,end:h.end,location:h.location||void 0,description:h.description||void 0},`PATCH`)}else{let e=h.start.split(`T`)[0];await D(`/api/calendar`,{summary:h.title,start:h.start,end:h.end,location:h.location||void 0,description:h.description||void 0,date:e})}let e=h.start.split(`T`)[0];C(e),g(null)}catch(e){y(`Error: `+(e.message??`Unknown`))}finally{x(!1)}}};if(n===null)return(0,k.jsx)(`div`,{className:K.center,children:(0,k.jsx)(`div`,{className:`spinner`})});if(!n)return(0,k.jsx)(`div`,{className:K.center,children:(0,k.jsxs)(`div`,{className:K.noGoogle,children:[(0,k.jsx)(`div`,{className:K.noGoogleIcon,children:`📅`}),(0,k.jsx)(`div`,{className:K.noGoogleTitle,children:`Calendar`}),(0,k.jsx)(`div`,{className:K.noGoogleSub,children:`Connect your Google account to view and manage calendar events.`}),(0,k.jsx)(`button`,{className:K.connectBtn,onClick:()=>t(`settings`),children:`Connect Google →`})]})});let re=new Date(a,s,1).getDay(),ie=new Date(a,s+1,0).getDate(),O=new Date(a,s,1).toLocaleDateString(`en`,{month:`long`,year:`numeric`}),ae=(re+6)%7,A=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],j=p?l[p]??[]:[];return(0,k.jsxs)(`div`,{className:K.root,children:[(0,k.jsxs)(`div`,{className:K.calCol,children:[(0,k.jsxs)(`div`,{className:K.navRow,children:[(0,k.jsx)(`button`,{className:K.navBtn,onClick:()=>{let e=s-1;e<0?(o(e=>e-1),c(11)):c(e)},children:`←`}),(0,k.jsx)(`div`,{className:K.monthTitle,children:O}),(0,k.jsx)(`button`,{className:K.navBtn,onClick:()=>{let e=s+1;e>11?(o(e=>e+1),c(0)):c(e)},children:`→`})]}),(0,k.jsx)(`div`,{className:K.dayHeaders,children:A.map((e,t)=>(0,k.jsx)(`div`,{className:`${K.dayHeader} ${t>=5?K.weekend:``}`,children:e},e))}),(0,k.jsxs)(`div`,{className:K.grid,children:[Array.from({length:ae}).map((e,t)=>(0,k.jsx)(`div`,{className:`${K.cell} ${K.emptyCell} ${t>=5?K.weekendCell:``}`},`e${t}`)),Array.from({length:ie}).map((e,t)=>{let n=t+1,r=Ft(a,s,n),i=It(a,s,n),o=l[r]??[],c=o.length,u=(ae+n-1)%7>=5,d=o.some(e=>e._isHoliday||e.readOnly),f=p===r;return(0,k.jsxs)(`div`,{className:`${K.cell} ${i?K.todayCell:u?K.weekendCell:``} ${f?K.activeCell:``} ${d?K.holidayCell:c>0?K.hasEvtsCell:``}`,onClick:()=>m(r),children:[(0,k.jsx)(`div`,{className:`${K.dayNum} ${i?K.todayNum:u?K.weekendNum:``}`,children:n}),c>0&&(0,k.jsxs)(`div`,{className:K.evtPills,children:[o.slice(0,2).map((e,t)=>(0,k.jsx)(`div`,{className:`${K.evtPill} ${e._isHoliday||e.readOnly?K.holidayPill:``}`,children:e.summary},t)),c>2&&(0,k.jsxs)(`div`,{className:K.morePill,children:[`+`,c-2]})]})]},r)})]}),d&&(0,k.jsx)(`div`,{className:K.loadingBar,children:`Loading events…`})]}),(0,k.jsx)(`div`,{className:K.detailCol,children:p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:K.detailHeader,children:[(0,k.jsx)(`div`,{className:K.detailDate,children:new Date(p+`T12:00:00`).toLocaleDateString(`en`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}),(0,k.jsx)(`button`,{className:K.addEvtBtn,onClick:()=>ee(p),children:`+ Add Event`})]}),j.length===0?(0,k.jsx)(`div`,{className:K.noEvts,children:`No events on this day`}):j.map((t,n)=>{let r=t.isAllDay?`All day`:`${Lt(t.start)} - ${Lt(t.end)}`,i=t.calendarId??`primary`;return(0,k.jsxs)(`div`,{className:K.evtCard,children:[(0,k.jsxs)(`div`,{className:K.evtTop,children:[(0,k.jsx)(`div`,{className:K.evtTime,children:r}),t.id&&!t.readOnly&&(0,k.jsxs)(`div`,{className:K.evtBtns,children:[(0,k.jsx)(`button`,{className:K.editBtn,onClick:()=>te(t,p),children:`Edit`}),(0,k.jsx)(`button`,{className:K.delBtn,onClick:()=>w(i,t.id,p),children:e(`common.delete`)})]}),t.readOnly&&(0,k.jsx)(`span`,{className:K.readOnly,children:`read-only`})]}),(0,k.jsx)(`div`,{className:K.evtTitle,children:t.summary}),t.location&&(0,k.jsxs)(`div`,{className:K.evtLoc,children:[`📍 `,t.location]}),t.organizer&&(0,k.jsxs)(`div`,{className:K.evtMeta,children:[`Organizer: `,t.organizer]}),t.attendees&&t.attendees.length>0&&(0,k.jsxs)(`div`,{className:K.attendees,children:[(0,k.jsx)(`div`,{className:K.evtMeta,children:`Attendees:`}),t.attendees.map((e,t)=>(0,k.jsxs)(`div`,{className:K.attendee,"data-status":e.responseStatus,children:[e.name||e.email,` (`,e.responseStatus,`)`]},t))]}),t.description&&(0,k.jsx)(`div`,{className:K.evtDesc,children:t.description}),t.hangoutLink&&(0,k.jsx)(`a`,{className:K.joinBtn,href:t.hangoutLink,target:`_blank`,rel:`noreferrer`,children:`Join Video Call`}),t.htmlLink&&(0,k.jsx)(`a`,{className:K.gcalLink,href:t.htmlLink,target:`_blank`,rel:`noreferrer`,children:`Open in Google Calendar`})]},n)})]}):(0,k.jsx)(`div`,{className:K.selectDay,children:`Select a day to see events`})}),h&&(0,k.jsx)(`div`,{className:K.overlay,onClick:e=>{e.target===e.currentTarget&&g(null)},children:(0,k.jsxs)(`div`,{className:K.formCard,children:[(0,k.jsx)(`div`,{className:K.formTitle,children:h.isEdit?`Edit Event`:`New Event`}),(0,k.jsx)(`label`,{className:K.formLabel,children:`Title *`}),(0,k.jsx)(`input`,{className:K.formInput,value:h.title,onChange:e=>g(t=>t&&{...t,title:e.target.value}),placeholder:`Event title`}),(0,k.jsx)(`label`,{className:K.formLabel,children:`Start`}),(0,k.jsx)(`input`,{className:K.formInput,type:`datetime-local`,value:h.start,onChange:e=>g(t=>t&&{...t,start:e.target.value})}),(0,k.jsx)(`label`,{className:K.formLabel,children:`End`}),(0,k.jsx)(`input`,{className:K.formInput,type:`datetime-local`,value:h.end,onChange:e=>g(t=>t&&{...t,end:e.target.value})}),(0,k.jsx)(`label`,{className:K.formLabel,children:`Location`}),(0,k.jsx)(`input`,{className:K.formInput,value:h.location,onChange:e=>g(t=>t&&{...t,location:e.target.value}),placeholder:`Optional`}),(0,k.jsx)(`label`,{className:K.formLabel,children:`Description`}),(0,k.jsx)(`textarea`,{className:K.formTextarea,value:h.description,onChange:e=>g(t=>t&&{...t,description:e.target.value})}),v&&(0,k.jsx)(`div`,{className:K.formError,children:v}),(0,k.jsxs)(`div`,{className:K.formBtns,children:[(0,k.jsx)(`button`,{className:K.cancelFormBtn,onClick:()=>g(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:K.saveFormBtn,onClick:T,disabled:b,children:b?`Saving…`:h.isEdit?`Save Changes`:`Create Event`})]})]})})]})}var q={root:`_root_1tngw_1`,gridSection:`_gridSection_1tngw_9`,gridHeader:`_gridHeader_1tngw_14`,headerRow:`_headerRow_1tngw_21`,search:`_search_1tngw_23`,createBtn:`_createBtn_1tngw_34`,catTabs:`_catTabs_1tngw_41`,catTab:`_catTab_1tngw_41`,catActive:`_catActive_1tngw_48`,grid:`_grid_1tngw_9`,agentCard:`_agentCard_1tngw_59`,agentActive:`_agentActive_1tngw_66`,agentCardTop:`_agentCardTop_1tngw_68`,agentIcon:`_agentIcon_1tngw_69`,agentActions:`_agentActions_1tngw_70`,agentEditBtn:`_agentEditBtn_1tngw_71`,agentDelBtn:`_agentDelBtn_1tngw_71`,agentLabel:`_agentLabel_1tngw_74`,agentDesc:`_agentDesc_1tngw_75`,agentCat:`_agentCat_1tngw_76`,loading:`_loading_1tngw_78`,chatArea:`_chatArea_1tngw_81`,emptyChat:`_emptyChat_1tngw_88`,emptyChatHint:`_emptyChatHint_1tngw_98`,chatPanel:`_chatPanel_1tngw_101`,chatHeader:`_chatHeader_1tngw_111`,chatIcon:`_chatIcon_1tngw_118`,chatHeaderInfo:`_chatHeaderInfo_1tngw_119`,chatAgentName:`_chatAgentName_1tngw_120`,chatAgentDesc:`_chatAgentDesc_1tngw_121`,closeChat:`_closeChat_1tngw_122`,chatMessages:`_chatMessages_1tngw_125`,chatEmpty:`_chatEmpty_1tngw_130`,chatMsg:`_chatMsg_1tngw_132`,msgUser:`_msgUser_1tngw_136`,msgAgent:`_msgAgent_1tngw_137`,thinking:`_thinking_1tngw_139`,dot:`_dot_1tngw_140`,dotPulse:`_dotPulse_1tngw_1`,chatInput:`_chatInput_1tngw_146`,chatTools:`_chatTools_1tngw_147`,toolBtn:`_toolBtn_1tngw_148`,toolBtnActive:`_toolBtnActive_1tngw_156`,attachBar:`_attachBar_1tngw_158`,attachClear:`_attachClear_1tngw_163`,chatInputRow:`_chatInputRow_1tngw_165`,chatTextarea:`_chatTextarea_1tngw_166`,sendBtn:`_sendBtn_1tngw_173`,orchBar:`_orchBar_1tngw_181`,orchLabel:`_orchLabel_1tngw_192`,orchRow:`_orchRow_1tngw_193`,orchInput:`_orchInput_1tngw_194`,orchBtn:`_orchBtn_1tngw_201`,orchSynthesis:`_orchSynthesis_1tngw_208`,orchSynthHeader:`_orchSynthHeader_1tngw_214`,orchSynthSpinner:`_orchSynthSpinner_1tngw_220`,blink:`_blink_1tngw_1`,orchSynthBody:`_orchSynthBody_1tngw_222`,modalOverlay:`_modalOverlay_1tngw_230`,modal:`_modal_1tngw_230`,modalTitle:`_modalTitle_1tngw_232`,formField:`_formField_1tngw_233`,formLabel:`_formLabel_1tngw_234`,formInput:`_formInput_1tngw_235`,formTextarea:`_formTextarea_1tngw_236`,formError:`_formError_1tngw_237`,modalBtns:`_modalBtns_1tngw_238`,cancelBtn:`_cancelBtn_1tngw_239`,modalSaveBtn:`_modalSaveBtn_1tngw_240`},zt={saber:{icon:`🛡`},zero:{icon:`🔍`},ade:{icon:`🔬`},heimdall:{icon:`🔒`},cassandra:{icon:`⚠`},sauron:{icon:`👁`},jarvis:{icon:`💻`},forge:{icon:`⚙`},pipe:{icon:`🔧`},shell:{icon:`📟`},glitch:{icon:`🐛`},hermes:{icon:`🔗`},babel:{icon:`🌎`},shogun:{icon:`☸`},flux:{icon:`🔄`},cron:{icon:`⏰`},atlas:{icon:`🗺`},oracle:{icon:`📊`},logos:{icon:`🧮`},navi:{icon:`🧭`},edi:{icon:`📈`},mercury:{icon:`🌐`},tempest:{icon:`⛈`},cartographer:{icon:`🌍`},scheherazade:{icon:`✍`},quill:{icon:`📝`},muse:{icon:`🎨`},murasaki:{icon:`🖌`},echo:{icon:`📡`},polyglot:{icon:`🗣`},prometheus:{icon:`🔥`},herald:{icon:`📢`},veritas:{icon:`✓`},athena:{icon:`🧠`},conductor:{icon:`🎼`},link:{icon:`🔌`},macro:{icon:`⚡`},epicure:{icon:`🍽`}};function Bt(e){let t=e.card??e,n=(t.name||t.displayName||t.agentName||e.name||``).toLowerCase().replace(/\s+/g,`-`),r=zt[n],i=t.displayName||t.agentName||t.name||e.displayName||n,a=t.tagline||t.description||e.tagline||``,o=t.category||e.category||`Other`;return{id:n,icon:r?.icon??t.icon??`🤖`,label:i,description:a,category:o,isCustom:o===`custom`,systemPrompt:e.systemPrompt}}function Vt(e){return{agent:e,history:[],streaming:!1,input:``,attachedFile:null,attachedImage:null,voiceActive:!1}}function Ht(){let e=P(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(`All`),[l,u]=(0,_.useState)([]),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(``),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(`create`),[w,ee]=(0,_.useState)(``),[te,ne]=(0,_.useState)(!1),T=(0,_.useRef)(new Map),re=(0,_.useRef)(new Map),O=(0,_.useRef)(new Map),ae=(0,_.useRef)(new Map),A=(0,_.useRef)(new Map),j=(0,_.useRef)(null),oe=()=>{E(`/api/agents`).then(e=>{n((e?.agents??[]).map(Bt)),i(!1)}).catch(()=>i(!1))};(0,_.useEffect)(()=>{oe()},[]);let se=[`All`,...Array.from(new Set(t.map(e=>e.category))).sort()],M=t.filter(e=>{let t=s===`All`||e.category===s,n=a.toLowerCase();return t&&(!n||e.label.toLowerCase().includes(n)||e.description.toLowerCase().includes(n))}),ce=e=>{u(t=>{let n=t.findIndex(t=>t.agent.id===e.id);return n>=0?(re.current.get(e.id)?.abort(),re.current.delete(e.id),t.filter((e,t)=>t!==n)):[...t,Vt(e)]})},N=e=>{re.current.get(e)?.abort(),re.current.delete(e),u(t=>t.filter(t=>t.agent.id!==e))},F=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,...t}:n))},le=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,history:[...n.history,t]}:n))},ue=(e,t)=>{u(n=>n.map(n=>{if(n.agent.id!==e)return n;let r=[...n.history];return r[r.length-1]={...r[r.length-1],content:t},{...n,history:r}}))},de=async(e,t,n,r)=>{let i=e.agent.id;if(!t.trim()&&!n&&!r)return;le(i,{role:`user`,content:n?(t?t+` `:``)+`[File: ${n.name}]`:r?(t?t+` `:``)+`[Image: ${r.name}]`:t}),F(i,{streaming:!0,input:``,attachedFile:null,attachedImage:null});let a=e.history.slice(-20);if(n||r){try{let e={message:t||`Analyze this`,agent:i};n?.isPDF&&n.base64?(e.pdfBase64=n.base64,e.pdfName=n.name):n?.content&&(e.fileContent=n.content,e.fileName=n.name),r?.base64&&(e.imageBase64=r.base64,e.imageMimeType=r.mimeType??`image/jpeg`);let a=await D(`/api/chat`,e);le(i,{role:`assistant`,content:a?.response||a?.content||``})}catch{le(i,{role:`assistant`,content:`Error sending attachment.`})}F(i,{streaming:!1});return}le(i,{role:`assistant`,content:``,streaming:!0});let o=new AbortController;re.current.set(i,o);let s=``;try{await ie(`/api/chat/stream`,{message:t,agent:i,history:a,_agentSystemPrompt:e.agent.systemPrompt},e=>{s+=e,ue(i,s);let t=O.current.get(i);t&&(t.scrollTop=t.scrollHeight)},o.signal)}catch{}finally{F(i,{streaming:!1}),re.current.delete(i)}},I=async()=>{let e=d.trim();if(!e||p||l.length===0)return;f(``),m(!0),g(``);let t=[];if(await Promise.all(l.map(async n=>{let r=n.agent.id;le(r,{role:`user`,content:e}),F(r,{streaming:!0});let i=``,a=new AbortController;re.current.set(r,a),le(r,{role:`assistant`,content:``,streaming:!0});try{await ie(`/api/chat/stream`,{message:e,agent:r,history:n.history.slice(-20),_agentSystemPrompt:n.agent.systemPrompt},e=>{i+=e,ue(r,i);let t=O.current.get(r);t&&(t.scrollTop=t.scrollHeight)},a.signal)}catch{}finally{F(r,{streaming:!1}),re.current.delete(r)}t.push({agentId:r,agentLabel:n.agent.label,icon:n.agent.icon,content:i})})),m(!1),t.length<2)return;y(!0);let n=t.map(e=>`## ${e.icon} ${e.agentLabel}\n${e.content}`).join(`
461
+ </body></html>`,f=new Blob([d],{type:`text/html`}),p=URL.createObjectURL(f),m=document.createElement(`a`);m.href=p,m.download=`nha-report-${Date.now()}.html`,m.click(),URL.revokeObjectURL(p);let h=window.open(``,`_blank`,`width=1100,height=800`);h&&(h.document.open(),h.document.write(d),h.document.close(),h.onload=()=>setTimeout(()=>{h.focus(),h.print()},600))},me=t=>{let n=`**Studio Workflow Result**\n\nTask: ${t.task}\n\nAgents: ${t.nodes.map(e=>e.label).join(` → `)}\n\n---\n\n${t.result}`;try{sessionStorage.setItem(`nha_studio_import`,n)}catch{}e(`chat`)},he=()=>{if(!u){r(``),a([]),s([]),l(``),S(``),se.current=``,w(null),M.current=null,te(!1),b({in:0,out:0}),v(null),re(!1);try{sessionStorage.removeItem(qe)}catch{}}},ge=i.some(e=>e.output||e.status===`running`);return(0,k.jsxs)(`div`,{className:L.root,children:[(0,k.jsxs)(`div`,{className:L.header,children:[(0,k.jsxs)(`div`,{className:L.headerLeft,children:[(0,k.jsx)(`div`,{className:L.title,children:`Studio`}),(0,k.jsx)(`div`,{className:L.subtitle,children:`Multi-agent orchestration · Parliament deliberation · Geth Consensus`})]}),(0,k.jsxs)(`div`,{className:L.headerActions,children:[y.in+y.out>0&&(0,k.jsxs)(`div`,{className:L.tokenBar,children:[(0,k.jsxs)(`span`,{className:L.tokIn,children:[`↑ `,y.in.toLocaleString()]}),(0,k.jsx)(`span`,{className:L.tokDim,children:` in `}),(0,k.jsxs)(`span`,{className:L.tokOut,children:[`↓ `,y.out.toLocaleString()]}),(0,k.jsx)(`span`,{className:L.tokDim,children:` out`})]}),(0,k.jsxs)(`button`,{className:L.sessionsBtn,onClick:()=>h(e=>!e),children:[`Sessions (`,f.length,`)`]}),x&&(0,k.jsx)(`button`,{className:L.canvasToggleBtn,onClick:()=>{re(!0),O(`canvas`)},children:`📊 Panel`}),c&&(0,k.jsx)(`button`,{className:L.pdfBtn,onClick:pe,children:`⬇ PDF / HTML`}),(i.length>0||c||o.length>0)&&!u&&(0,k.jsx)(`button`,{className:L.clearBtn,onClick:he,title:`Clear all — start fresh`,children:`✕ Clear`})]})]}),m&&(0,k.jsxs)(`div`,{className:L.sessionsDrawer,children:[f.length===0&&(0,k.jsx)(`div`,{className:L.noSessions,children:`No saved sessions yet.`}),f.map(e=>(0,k.jsxs)(`div`,{className:L.sessionItem,children:[(0,k.jsxs)(`div`,{className:L.sessionInfo,onClick:()=>de(e),children:[(0,k.jsx)(`div`,{className:L.sessionTask,children:e.task.slice(0,80)}),(0,k.jsxs)(`div`,{className:L.sessionMeta,children:[e.ts.slice(0,16),` · `,e.nodes.length,` agents`,e.council?.phase===`done`?` · 🏛️ Parliament`:``]})]}),(0,k.jsxs)(`div`,{className:L.sessionBtns,children:[(0,k.jsx)(`button`,{className:L.importBtn,onClick:()=>me(e),children:`→ Chat`}),(0,k.jsx)(`button`,{className:L.delSessionBtn,onClick:()=>I(e.id),children:`✕`})]})]},e.id))]}),(0,k.jsxs)(`div`,{className:L.inputArea,children:[(0,k.jsxs)(`div`,{className:L.inputRow,children:[(0,k.jsx)(`textarea`,{className:L.taskInput,value:n,onChange:e=>r(e.target.value),placeholder:`Describe your task… e.g. Analyze my emails and create a priority action plan`,rows:2,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),F())}}),(0,k.jsxs)(`div`,{className:L.inputControls,children:[u?(0,k.jsx)(`button`,{className:L.stopBtn,onClick:le,children:`■ Stop`}):(0,k.jsx)(`button`,{className:L.runBtn,onClick:F,disabled:!n.trim(),children:`Run ▶`}),(0,k.jsxs)(`label`,{className:L.attachBtn,title:`Attach PDF or image`,children:[`📎`,(0,k.jsx)(`input`,{type:`file`,accept:`.pdf,.png,.jpg,.jpeg,.gif,.webp`,style:{display:`none`},onChange:e=>P(e.target.files?.[0])})]})]})]}),g&&(0,k.jsxs)(`div`,{className:L.attachBadge,children:[`📎 `,g.name,(0,k.jsx)(`button`,{className:L.clearAttach,onClick:()=>v(null),children:`✕`})]}),!u&&i.length===0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:L.examples,children:ye.map((e,t)=>(0,k.jsx)(`button`,{className:L.exampleBtn,onClick:()=>r(e),children:e},t))}),(0,k.jsxs)(`div`,{className:L.financeSection,children:[(0,k.jsx)(`div`,{className:L.financeSectionTitle,children:`📈 Finance & Trading Workflows`}),(0,k.jsx)(`div`,{className:L.financePresets,children:_e.map((e,t)=>(0,k.jsx)(`button`,{className:L.financeBtn,onClick:()=>{r(e.task),a(e.agents)},children:e.label},t))})]})]})]}),i.length>0&&(0,k.jsx)(`div`,{className:L.officeSceneWrap,children:(0,k.jsx)(He,{nodes:i,running:u})}),(0,k.jsxs)(`div`,{className:L.body,children:[i.length>0&&(0,k.jsxs)(`div`,{className:`${L.pipeline} ${u?L.pipelineRunning:``}`,children:[(0,k.jsxs)(`div`,{className:L.pipelineTitle,children:[`Agent Pipeline`,u&&(0,k.jsx)(`span`,{className:L.pipelineLiveTag,children:`● LIVE`})]}),(0,k.jsx)(`div`,{className:L.pipelineNodes,children:i.map((e,t)=>(0,k.jsxs)(`div`,{className:L.pipelineStep,children:[(0,k.jsxs)(`div`,{className:`${L.agentChip} ${L[`chip_${e.status}`]}`,children:[(0,k.jsx)(`span`,{className:L.chipIcon,children:e.icon}),(0,k.jsx)(`span`,{className:L.chipLabel,children:e.label}),e.status===`running`&&(0,k.jsxs)(`span`,{className:L.chipDots,children:[(0,k.jsx)(`span`,{className:L.dot1,children:`.`}),(0,k.jsx)(`span`,{className:L.dot2,children:`.`}),(0,k.jsx)(`span`,{className:L.dot3,children:`.`})]}),e.status===`done`&&(0,k.jsx)(`span`,{className:L.chipCheck,children:`✓`}),e.status===`error`&&(0,k.jsx)(`span`,{className:L.chipErr,children:`✗`})]}),t<i.length-1&&(0,k.jsx)(`div`,{className:`${L.arrow} ${u?L.arrowActive:``}`,children:`→`})]},t))}),i.some(e=>e.reason)&&(0,k.jsx)(`div`,{className:L.reasonRow,children:i.map((e,t)=>e.reason?(0,k.jsxs)(`div`,{className:L.reasonChip,title:e.reason,children:[(0,k.jsx)(`span`,{className:L.reasonIcon,children:e.icon}),(0,k.jsxs)(`span`,{className:L.reasonText,children:[e.reason.slice(0,60),e.reason.length>60?`…`:``]})]},t):null)})]}),(o.length>0||ge)&&(0,k.jsxs)(`div`,{className:L.twoCol,children:[(0,k.jsxs)(`div`,{className:L.logPanel,children:[(0,k.jsx)(`div`,{className:L.panelTitle,children:`Live Log`}),(0,k.jsx)(`div`,{className:L.logBody,ref:oe,children:o.map((e,t)=>(0,k.jsxs)(`div`,{className:`${L.logEntry} ${L[`log_${e.type}`]}`,children:[(0,k.jsx)(`span`,{className:L.logTime,children:e.time}),(0,k.jsx)(`span`,{className:L.logIcon,children:e.icon}),(0,k.jsx)(`span`,{className:L.logAgent,children:e.agent}),(0,k.jsx)(`span`,{className:L.logText,children:e.text})]},t))})]}),(0,k.jsx)(`div`,{className:L.liveOutputPanel,children:i.filter(e=>e.output||e.status===`running`).map((e,t)=>(0,k.jsxs)(`div`,{className:`${L.liveBlock} ${e.status===`running`?L.liveBlockActive:``}`,children:[(0,k.jsxs)(`div`,{className:L.liveBlockHeader,children:[(0,k.jsx)(`span`,{className:L.liveBlockIcon,children:e.icon}),(0,k.jsx)(`span`,{className:L.liveBlockLabel,children:e.label}),e.reason&&(0,k.jsx)(`span`,{className:L.liveBlockReason,title:e.reason,children:`ℹ`}),(0,k.jsx)(`span`,{className:`${L.outputStatus} ${L[`status_${e.status}`]}`,children:e.status})]}),e.status===`running`&&!e.output&&(0,k.jsxs)(`div`,{className:L.liveBlockWorking,children:[(0,k.jsx)(`span`,{className:L.workingDot}),(0,k.jsx)(`span`,{className:L.workingDot}),(0,k.jsx)(`span`,{className:L.workingDot}),(0,k.jsx)(`span`,{className:L.workingLabel,children:`elaborazione in corso`})]}),(0,k.jsx)(`div`,{className:L.liveBlockBody,dangerouslySetInnerHTML:{__html:fe(e.output)+(e.status===`running`&&e.output?`<span class="studio-cursor"></span>`:``)}})]},t))})]}),ee&&(0,k.jsxs)(`div`,{className:L.parliamentPrompt,children:[(0,k.jsx)(`div`,{className:L.parliamentPromptIcon,children:`🏛️`}),(0,k.jsxs)(`div`,{className:L.parliamentPromptContent,children:[(0,k.jsx)(`div`,{className:L.parliamentPromptTitle,children:`Attivare il Consiglio?`}),(0,k.jsxs)(`div`,{className:L.parliamentPromptDesc,children:[T.length,` agenti (`,T.map(e=>e.label).join(`, `),`) hanno prodotto output. Il Geth Consensus eseguirà cross-reading, refinement e mediazione HERALD per raggiungere un consenso collettivo.`]}),(0,k.jsxs)(`div`,{className:L.parliamentPromptMeta,children:[`Complessità: `,T.length<=3?`⚡ Rapido (~30s)`:T.length<=5?`⏱ Medio (~60s)`:`🕐 Lungo (~2min)`,`\xA0· Consigliato per task analitici complessi`]})]}),(0,k.jsxs)(`div`,{className:L.parliamentPromptBtns,children:[(0,k.jsx)(`button`,{className:L.parliamentActivateBtn,onClick:ue,children:`🏛️ Attiva`}),(0,k.jsx)(`button`,{className:L.parliamentSkipBtn,onClick:()=>te(!1),children:`Salta`})]})]}),C&&!ee&&(0,k.jsx)(`div`,{className:L.councilWrapper,children:(0,k.jsx)(et,{council:C})}),c&&!u&&(0,k.jsxs)(`details`,{className:L.resultAccordion,open:i.length<=1,children:[(0,k.jsxs)(`summary`,{className:L.resultAccordionSummary,children:[`Full Combined Report (`,i.filter(e=>e.output&&e.output!==`(no output)`).length,` agents)`]}),(0,k.jsx)(`div`,{className:L.resultAccordionBody,dangerouslySetInnerHTML:{__html:fe(c)}})]})]}),D&&(0,k.jsxs)(`div`,{className:L.canvasPanel,children:[(0,k.jsxs)(`div`,{className:L.canvasPanelHeader,children:[(0,k.jsxs)(`div`,{className:L.panelTabs,children:[(0,k.jsx)(`button`,{className:`${L.panelTabBtn} ${ie===`canvas`?L.panelTabActive:``}`,onClick:()=>O(`canvas`),children:`📊 Canvas`}),(0,k.jsx)(`button`,{className:`${L.panelTabBtn} ${ie===`browser`?L.panelTabActive:``}`,onClick:()=>O(`browser`),children:`🌐 Browser`})]}),(0,k.jsxs)(`div`,{className:L.canvasPanelActions,children:[ie===`canvas`&&x&&(0,k.jsx)(`button`,{className:L.canvasPanelBtn,onClick:()=>{let e=new Blob([x],{type:`text/html`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`nha-canvas-report.html`,n.click(),URL.revokeObjectURL(t)},children:`⬇ HTML`}),(0,k.jsx)(`button`,{className:L.canvasPanelClose,onClick:()=>re(!1),children:`✕`})]})]}),ie===`canvas`?x?(0,k.jsx)(`iframe`,{className:L.canvasFrame,srcDoc:x,sandbox:`allow-scripts`,title:`Canvas Report`}):(0,k.jsx)(`div`,{className:L.panelEmpty,children:`No canvas report yet. Run a workflow first.`}):(0,k.jsxs)(`div`,{className:L.browserPanel,children:[(0,k.jsxs)(`div`,{className:L.browserBar,children:[(0,k.jsx)(`input`,{className:L.browserInput,value:ae,onChange:e=>A(e.target.value),placeholder:`https://…`,onKeyDown:e=>{e.key===`Enter`&&A(ae)}}),(0,k.jsx)(`button`,{className:L.browserGo,onClick:()=>A(ae),children:`Go`})]}),ae?(0,k.jsx)(`iframe`,{className:L.canvasFrame,src:ae,sandbox:`allow-scripts allow-same-origin allow-forms`,title:`Browser`}):(0,k.jsx)(`div`,{className:L.panelEmpty,children:`Enter a URL above to browse`})]})]})]})}var V={root:`_root_13wnr_2`,hero:`_hero_13wnr_12`,heroLeft:`_heroLeft_13wnr_21`,heroDate:`_heroDate_13wnr_22`,heroTitle:`_heroTitle_13wnr_23`,heroVer:`_heroVer_13wnr_24`,heroUptime:`_heroUptime_13wnr_25`,heroWeather:`_heroWeather_13wnr_27`,wIcon:`_wIcon_13wnr_35`,wInfo:`_wInfo_13wnr_36`,wTemp:`_wTemp_13wnr_37`,wCity:`_wCity_13wnr_38`,wDesc:`_wDesc_13wnr_39`,wEmpty:`_wEmpty_13wnr_40`,kpiRow:`_kpiRow_13wnr_43`,kpi:`_kpi_13wnr_43`,kpiNum:`_kpiNum_13wnr_55`,kpiLbl:`_kpiLbl_13wnr_56`,kpiBar:`_kpiBar_13wnr_57`,kpiFill:`_kpiFill_13wnr_58`,liveGrid:`_liveGrid_13wnr_61`,liveCard:`_liveCard_13wnr_67`,liveHdr:`_liveHdr_13wnr_71`,liveMore:`_liveMore_13wnr_79`,liveRow:`_liveRow_13wnr_81`,liveUnread:`_liveUnread_13wnr_89`,liveTitle:`_liveTitle_13wnr_89`,liveTime:`_liveTime_13wnr_91`,liveBody:`_liveBody_13wnr_95`,liveSub:`_liveSub_13wnr_97`,prio:`_prio_13wnr_99`,prio_high:`_prio_high_13wnr_103`,prio_medium:`_prio_medium_13wnr_104`,prio_low:`_prio_low_13wnr_105`,launcher:`_launcher_13wnr_108`,launchGroup:`_launchGroup_13wnr_115`,launchGroupLabel:`_launchGroupLabel_13wnr_117`,launchTiles:`_launchTiles_13wnr_123`,tile:`_tile_13wnr_129`,tileIcon:`_tileIcon_13wnr_143`,tileLabel:`_tileLabel_13wnr_144`},nt=[{view:`chat`,icon:`💬`,label:`Chat`,color:`#38bdf8`,group:`Panoramica`},{view:`plan`,icon:`🗓️`,label:`Daily Plan`,color:`#818cf8`,group:`Panoramica`},{view:`tasks`,icon:`✅`,label:`Tasks`,color:`#4ade80`,group:`Panoramica`},{view:`email`,icon:`📧`,label:`Email`,color:`#f87171`,group:`Google`},{view:`calendar`,icon:`📅`,label:`Calendar`,color:`#fb923c`,group:`Google`},{view:`drive`,icon:`💾`,label:`Drive`,color:`#facc15`,group:`Google`},{view:`contacts`,icon:`👤`,label:`Contacts`,color:`#34d399`,group:`Google`},{view:`notes`,icon:`📝`,label:`Notes`,color:`#a78bfa`,group:`Google`},{view:`onedrive`,icon:`☁️`,label:`OneDrive`,color:`#60a5fa`,group:`Microsoft`},{view:`mstodo`,icon:`📋`,label:`MS Todo`,color:`#38bdf8`,group:`Microsoft`},{view:`github`,icon:`🐙`,label:`GitHub`,color:`#e2e8f0`,group:`Tools`},{view:`notion`,icon:`📓`,label:`Notion`,color:`#94a3b8`,group:`Tools`},{view:`slack`,icon:`💼`,label:`Slack`,color:`#e879f9`,group:`Tools`},{view:`maps`,icon:`🗺️`,label:`Maps`,color:`#2dd4bf`,group:`Tools`},{view:`reminders`,icon:`🔔`,label:`Reminders`,color:`#fbbf24`,group:`Tools`},{view:`birthdays`,icon:`🎂`,label:`Birthdays`,color:`#f472b6`,group:`Tools`},{view:`cron`,icon:`⏰`,label:`Cron`,color:`#fb923c`,group:`Tools`},{view:`screen`,icon:`🖥️`,label:`Screen`,color:`#64748b`,group:`Tools`},{view:`agents`,icon:`🤖`,label:`Agents`,color:`#4ade80`,group:`AI`},{view:`studio`,icon:`🎭`,label:`Studio`,color:`#a78bfa`,group:`AI`},{view:`webcraft`,icon:`🔨`,label:`WebCraft`,color:`#f59e0b`,group:`AI`},{view:`collab`,icon:`🏛️`,label:`Alexandria`,color:`#38bdf8`,group:`AI`},{view:`connectors`,icon:`🔗`,label:`Connectors`,color:`#94a3b8`,group:`Config`},{view:`settings`,icon:`⚙️`,label:`Settings`,color:`#64748b`,group:`Config`}],rt={Sunny:`☀️`,Clear:`☀️`,"Partly Cloudy":`⛅`,"Partly cloudy":`⛅`,Cloudy:`☁️`,Overcast:`☁️`,"Light rain":`🌧️`,Rain:`🌧️`,Drizzle:`🌧️`,"Moderate rain":`🌧️`,"Heavy rain":`🌧️`,Snow:`❄️`,"Light snow":`❄️`,Fog:`🌫️`,Mist:`🌫️`,Thunder:`⚡`,"Thundery outbreaks":`⚡`};function it(e){try{return new Date(e).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,hour12:!1})}catch{return e}}function at(e){try{return new Date(e).toLocaleDateString(`en`,{month:`short`,day:`numeric`})}catch{return e}}function ot(){let e=ne(e=>e.setView),t=P(),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(new Date);(0,_.useEffect)(()=>{let e=setInterval(()=>p(new Date),6e4);return()=>clearInterval(e)},[]),(0,_.useEffect)(()=>{let e=!0,t=t=>n=>{e&&n!=null&&t(n)};E(`/api/tasks`).then(e=>t(r)(e?.tasks??[])),E(`/api/emails?page=0&pageSize=8`).then(e=>t(a)(e?.emails??[])),E(`/api/calendar`).then(e=>t(s)(e?.events??[])),E(`/api/status`).then(t(l));let n=localStorage.getItem(`nha_weather_location`),i=t=>E(`/api/weather?location=${encodeURIComponent(t)}`).then(t=>{e&&t?.tempC&&d(t)});return n?i(n):navigator.geolocation?.getCurrentPosition(e=>i(`${e.coords.latitude.toFixed(4)},${e.coords.longitude.toFixed(4)}`),()=>{},{timeout:6e3}),()=>{e=!1}},[]);let m=n.filter(e=>e.status!==`done`),h=n.filter(e=>e.status===`done`),g=n.length>0?Math.round(h.length/n.length*100):0,v=i.filter(e=>e.isUnread).length,y=f.toLocaleDateString(`en`,{weekday:`long`,month:`long`,day:`numeric`}),b=[...new Set(nt.map(e=>e.group))];return(0,k.jsxs)(`div`,{className:V.root,children:[(0,k.jsxs)(`div`,{className:V.hero,children:[(0,k.jsxs)(`div`,{className:V.heroLeft,children:[(0,k.jsx)(`div`,{className:V.heroDate,children:y}),(0,k.jsx)(`div`,{className:V.heroTitle,children:c?(0,k.jsxs)(k.Fragment,{children:[`NHA `,(0,k.jsxs)(`span`,{className:V.heroVer,children:[`v`,c.version]}),` · `,(0,k.jsxs)(`span`,{className:V.heroUptime,children:[Math.floor(c.uptime/60),`m uptime`]})]}):`NotHumanAllowed`})]}),(0,k.jsx)(`div`,{className:V.heroWeather,onClick:()=>{let e=prompt(`City or lat,lon:`);e&&(localStorage.setItem(`nha_weather_location`,e),location.reload())},children:u?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`span`,{className:V.wIcon,children:rt[u.desc]??u.icon??`🌡️`}),(0,k.jsxs)(`div`,{className:V.wInfo,children:[(0,k.jsxs)(`span`,{className:V.wTemp,children:[u.tempC,`°C`]}),(0,k.jsxs)(`span`,{className:V.wCity,children:[u.city.split(`,`)[0],u.country?`, ${u.country.slice(0,2).toUpperCase()}`:``]}),(0,k.jsxs)(`span`,{className:V.wDesc,children:[u.desc,` · 💧`,u.humidity,`%`]})]})]}):(0,k.jsxs)(`span`,{className:V.wEmpty,children:[`🌡️ `,t(`dashboard.weather`)]})})]}),(0,k.jsxs)(`div`,{className:V.kpiRow,children:[(0,k.jsxs)(`div`,{className:V.kpi,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.kpiNum,children:m.length}),(0,k.jsx)(`span`,{className:V.kpiLbl,children:`Pending tasks`}),n.length>0&&(0,k.jsx)(`div`,{className:V.kpiBar,children:(0,k.jsx)(`div`,{className:V.kpiFill,style:{width:`${g}%`}})})]}),(0,k.jsxs)(`div`,{className:V.kpi,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.kpiNum,children:v>0?v:i.length}),(0,k.jsx)(`span`,{className:V.kpiLbl,children:v>0?`Unread emails`:`Emails`})]}),(0,k.jsxs)(`div`,{className:V.kpi,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.kpiNum,children:o.length}),(0,k.jsx)(`span`,{className:V.kpiLbl,children:`Today's events`})]}),u&&(0,k.jsxs)(`div`,{className:V.kpi,children:[(0,k.jsxs)(`span`,{className:V.kpiNum,children:[u.feelsC,`°`]}),(0,k.jsx)(`span`,{className:V.kpiLbl,children:`Feels like`})]})]}),(0,k.jsxs)(`div`,{className:V.liveGrid,children:[o.length>0&&(0,k.jsxs)(`div`,{className:V.liveCard,children:[(0,k.jsxs)(`div`,{className:V.liveHdr,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📅 `,t(`calendar.title`)]}),(0,k.jsx)(`span`,{className:V.liveMore,children:`→`})]}),o.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:V.liveRow,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.liveTime,children:t.isAllDay?`All day`:it(t.start)}),(0,k.jsxs)(`div`,{className:V.liveBody,children:[(0,k.jsx)(`span`,{className:V.liveTitle,children:t.summary}),t.location&&(0,k.jsx)(`span`,{className:V.liveSub,children:t.location})]})]},n))]}),i.length>0&&(0,k.jsxs)(`div`,{className:V.liveCard,children:[(0,k.jsxs)(`div`,{className:V.liveHdr,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📧 `,t(`email.inbox`)]}),(0,k.jsx)(`span`,{className:V.liveMore,children:`→`})]}),i.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:`${V.liveRow} ${t.isUnread?V.liveUnread:``}`,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:V.liveTime,children:at(t.date)}),(0,k.jsxs)(`div`,{className:V.liveBody,children:[(0,k.jsx)(`span`,{className:V.liveTitle,children:t.subject}),(0,k.jsx)(`span`,{className:V.liveSub,children:t.from})]})]},n))]}),m.length>0&&(0,k.jsxs)(`div`,{className:V.liveCard,children:[(0,k.jsxs)(`div`,{className:V.liveHdr,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`✅ `,t(`tasks.title`),` · `,h.length,`/`,n.length,` (`,g,`%)`]}),(0,k.jsx)(`span`,{className:V.liveMore,children:`→`})]}),m.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:V.liveRow,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:`${V.prio} ${V[`prio_`+t.priority]}`,children:t.priority[0].toUpperCase()}),(0,k.jsx)(`div`,{className:V.liveBody,children:(0,k.jsx)(`span`,{className:V.liveTitle,children:t.description})})]},n))]})]}),(0,k.jsx)(`div`,{className:V.launcher,children:b.map(t=>(0,k.jsxs)(`div`,{className:V.launchGroup,children:[(0,k.jsx)(`div`,{className:V.launchGroupLabel,children:t}),(0,k.jsx)(`div`,{className:V.launchTiles,children:nt.filter(e=>e.group===t).map(t=>(0,k.jsxs)(`button`,{className:V.tile,onClick:()=>e(t.view),style:{"--tc":t.color},children:[(0,k.jsx)(`span`,{className:V.tileIcon,children:t.icon}),(0,k.jsx)(`span`,{className:V.tileLabel,children:t.label})]},t.view))})]},t))})]})}var st={root:`_root_1pldx_1`,loading:`_loading_1pldx_2`,bar:`_bar_1pldx_4`,input:`_input_1pldx_5`,select:`_select_1pldx_6`,addBtn:`_addBtn_1pldx_7`,actions:`_actions_1pldx_10`,clearDone:`_clearDone_1pldx_11`,clearAll:`_clearAll_1pldx_12`,stats:`_stats_1pldx_14`,progress:`_progress_1pldx_15`,progressBar:`_progressBar_1pldx_16`,empty:`_empty_1pldx_18`,task:`_task_1pldx_20`,taskDone:`_taskDone_1pldx_22`,check:`_check_1pldx_23`,checkDone:`_checkDone_1pldx_25`,desc:`_desc_1pldx_26`,del:`_del_1pldx_27`,badge:`_badge_1pldx_30`,badge_high:`_badge_high_1pldx_31`,badge_medium:`_badge_medium_1pldx_32`,badge_low:`_badge_low_1pldx_33`,doneLabel:`_doneLabel_1pldx_35`};function ct(){let e=P(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(`medium`),[l,u]=(0,_.useState)(!1),d=(0,_.useRef)(null),f=()=>E(`/api/tasks`).then(e=>{n(e?.tasks??[]),i(!1)});(0,_.useEffect)(()=>{f()},[]);let p=async()=>{a.trim()&&(u(!0),await D(`/api/tasks`,{description:a.trim(),priority:s}),o(``),u(!1),f(),d.current?.focus())},m=e=>D(`/api/tasks/${e}/done`,{},`PATCH`).then(f),h=e=>D(`/api/tasks/${e}/delete`,{}).then(f),g=()=>D(`/api/tasks/clear`,{filter:`done`}).then(f),v=()=>{confirm(e(`tasks.deleteTask`))&&D(`/api/tasks/clear`,{filter:`all`}).then(f)},y=t.filter(e=>e.status!==`done`),b=t.filter(e=>e.status===`done`);return r?(0,k.jsxs)(`div`,{className:st.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:st.root,children:[(0,k.jsxs)(`div`,{className:st.bar,children:[(0,k.jsx)(`input`,{ref:d,className:st.input,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>e.key===`Enter`&&p(),placeholder:e(`tasks.newTask`)}),(0,k.jsxs)(`select`,{className:st.select,value:s,onChange:e=>c(e.target.value),children:[(0,k.jsx)(`option`,{value:`high`,children:`High`}),(0,k.jsx)(`option`,{value:`medium`,children:`Medium`}),(0,k.jsx)(`option`,{value:`low`,children:`Low`})]}),(0,k.jsx)(`button`,{className:st.addBtn,onClick:p,disabled:l||!a.trim(),children:l?`…`:`+ `+e(`common.add`)})]}),t.length>0&&(0,k.jsxs)(`div`,{className:st.actions,children:[(0,k.jsx)(`button`,{className:st.clearDone,onClick:g,children:`Clear completed`}),(0,k.jsx)(`button`,{className:st.clearAll,onClick:v,children:`Clear all`})]}),t.length>0&&(0,k.jsxs)(`div`,{className:st.stats,children:[y.length,` pending · `,b.length,` done`,t.length>0&&(0,k.jsx)(`span`,{className:st.progress,children:(0,k.jsx)(`span`,{className:st.progressBar,style:{width:`${Math.round(b.length/t.length*100)}%`}})})]}),y.length===0&&b.length===0&&(0,k.jsx)(`div`,{className:st.empty,children:`No tasks yet. Add one above ↑`}),y.map(e=>(0,k.jsxs)(`div`,{className:st.task,children:[(0,k.jsx)(`span`,{className:st.check,onClick:()=>m(e.id)}),(0,k.jsx)(`span`,{className:st.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${st.badge} ${st[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:st.del,onClick:()=>h(e.id),children:`×`})]},e.id)),b.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:st.doneLabel,children:`Completed`}),b.map(e=>(0,k.jsxs)(`div`,{className:`${st.task} ${st.taskDone}`,children:[(0,k.jsx)(`span`,{className:`${st.check} ${st.checkDone}`,onClick:()=>m(e.id),children:`✓`}),(0,k.jsx)(`span`,{className:st.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${st.badge} ${st[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:st.del,onClick:()=>h(e.id),children:`×`})]},e.id))]})]})}var H={root:`_root_1jj88_1`,loading:`_loading_1jj88_2`,card:`_card_1jj88_4`,cardTitle:`_cardTitle_1jj88_5`,cardTitleRow:`_cardTitleRow_1jj88_6`,cardSub:`_cardSub_1jj88_7`,connected:`_connected_1jj88_8`,statusMsg:`_statusMsg_1jj88_9`,fields:`_fields_1jj88_11`,field:`_field_1jj88_11`,fieldLabel:`_fieldLabel_1jj88_13`,fieldInput:`_fieldInput_1jj88_14`,saveBtn:`_saveBtn_1jj88_17`,dangerBtn:`_dangerBtn_1jj88_18`,cancelBtn:`_cancelBtn_1jj88_19`,btnRow:`_btnRow_1jj88_20`,keySet:`_keySet_1jj88_22`,nhaFree:`_nhaFree_1jj88_24`,nhaFreeTitle:`_nhaFreeTitle_1jj88_25`,nhaFreeSub:`_nhaFreeSub_1jj88_26`,nhaFreeBtn:`_nhaFreeBtn_1jj88_27`,imapRow:`_imapRow_1jj88_29`,imapName:`_imapName_1jj88_30`,imapMeta:`_imapMeta_1jj88_31`,imapStatus:`_imapStatus_1jj88_32`,imapBtns:`_imapBtns_1jj88_36`,imapSyncBtn:`_imapSyncBtn_1jj88_37`,imapEditBtn:`_imapEditBtn_1jj88_38`,imapDelBtn:`_imapDelBtn_1jj88_39`,emptyImap:`_emptyImap_1jj88_40`,imapForm:`_imapForm_1jj88_42`,imapFormTitle:`_imapFormTitle_1jj88_43`,pwdNote:`_pwdNote_1jj88_44`,pwdRow:`_pwdRow_1jj88_45`,togglePwd:`_togglePwd_1jj88_46`},lt={id:``,display_name:``,email_address:``,from_name:``,imap_host:``,imap_port:`993`,smtp_host:``,smtp_port:`587`,username:``,password:``};function ut({id:e,label:t,placeholder:n,value:r,onChange:i,type:a=`text`}){return(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsx)(`label`,{className:H.fieldLabel,children:t}),(0,k.jsx)(`input`,{id:e,type:a,placeholder:n,value:r,onChange:e=>i(e.target.value),className:H.fieldInput})]})}function dt(){let{setConfig:e}=ne(),t=P(),[n,r]=(0,_.useState)({}),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(!1),[x,S]=(0,_.useState)({name:``,email:``,phone:``,homeAddress:``,workAddress:``,city:``,country:``,company:``,role:``,notes:``}),[C,w]=(0,_.useState)(`nha`),[ee,te]=(0,_.useState)(``),[T,re]=(0,_.useState)(``),[ie,O]=(0,_.useState)(`en`),[ae,A]=(0,_.useState)(`07:00`),[j,oe]=(0,_.useState)(`18:00`),[se,M]=(0,_.useState)(`30`),[ce,N]=(0,_.useState)(`off`),[F,le]=(0,_.useState)(``),[ue,de]=(0,_.useState)(``);(0,_.useEffect)(()=>{E(`/api/config`).then(t=>{r(t??{});let n=t?.profile??{};S({name:n.name??``,email:n.email??``,phone:n.phone??``,homeAddress:n.homeAddress??``,workAddress:n.workAddress??``,city:n.city??``,country:n.country??``,company:n.company??``,role:n.role??``,notes:n.notes??``}),w(t?.provider??`nha`),re(t?.model??``),O(t?.lang??`en`),A(t?.planTime??`07:00`),oe(t?.summaryTime??`18:00`),M(String(t?.meetingAlert??`30`)),N(t?.thinking??`off`),te(``),a(!1),t&&e(t)}),fe()},[]);let fe=()=>E(`/api/imap/accounts`).then(e=>d(e?.accounts??[])),I=async(e,t)=>{s(e),await D(`/api/config`,{key:e,value:t}),l(e),s(null),setTimeout(()=>l(null),2e3)},pe=()=>I(`profile`,x),me=()=>{I(`provider`,C),I(`model`,T),I(`thinking`,ce),ee&&I(`key`,ee)},he=()=>{I(`planTime`,ae),I(`summaryTime`,j),I(`meetingAlert`,Number(se))},ge=()=>{v(t(`settings.googleOpening`)),D(`/api/google/auth`,{}).then(e=>{e?.url?(window.open(e.url,`_blank`),v(t(`settings.googleOpened`))):e?.error&&v(t(`common.error`)+`: `+e.error)}).catch(e=>v(t(`common.error`)+`: `+e.message))},L=()=>{confirm(t(`settings.disconnectGoogleConfirm`))&&D(`/api/google/revoke`,{}).then(()=>{r(e=>({...e,hasGoogle:!1})),v(t(`common.disconnected`))})},_e=()=>{if(!f)return;let e=!!f.id,t={display_name:f.display_name,email_address:f.email_address,from_name:f.from_name,imap_host:f.imap_host,imap_port:Number(f.imap_port),smtp_host:f.smtp_host,smtp_port:Number(f.smtp_port),username:f.username};f.password&&(t.password=f.password),e&&(t.id=f.id),h(`Saving…`),D(e?`/api/imap/accounts/update`:`/api/imap/accounts`,t).then(e=>{e?.ok||e?.id?(h(`Saved!`),p(null),fe()):h(`Error: `+(e?.error??`Unknown error`))}).catch(e=>h(`Error: `+e.message))},ve=(e,n)=>{confirm(t(`settings.imapDelete`,{name:n}))&&D(`/api/imap/accounts/delete`,{id:e}).then(()=>fe())},ye=e=>{D(`/api/imap/sync`,{accountId:e}).then(()=>setTimeout(fe,3e3))};if(i)return(0,k.jsxs)(`div`,{className:H.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),t(`common.loading`)]});let R=e=>t(o===e?`common.saving`:c===e?`common.saved`:`common.save`);return(0,k.jsxs)(`div`,{className:H.root,children:[(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.profile`)}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.profileSub`)}),(0,k.jsx)(`div`,{className:H.fields,children:[[`name`,t(`settings.name`),t(`settings.namePh`)],[`email`,t(`common.email`),t(`settings.emailPh`)],[`phone`,t(`common.phone`),t(`settings.phonePh`)],[`homeAddress`,t(`settings.homeAddress`),t(`settings.homeAddressPh`)],[`workAddress`,t(`settings.workAddress`),t(`settings.workAddressPh`)],[`city`,t(`settings.city`),t(`settings.cityPh`)],[`country`,t(`settings.country`),t(`settings.countryPh`)],[`company`,t(`settings.company`),t(`settings.companyPh`)],[`role`,t(`settings.role`),t(`settings.rolePh`)],[`notes`,t(`settings.notes`),t(`settings.notesPh`)]].map(([e,t,n])=>(0,k.jsx)(ut,{id:e,label:t,placeholder:n,value:x[e],onChange:t=>S(n=>({...n,[e]:t}))},e))}),(0,k.jsxs)(`button`,{className:H.saveBtn,onClick:pe,children:[R(`profile`),` `,t(`settings.saveProfile`)]})]}),(0,k.jsxs)(`div`,{className:H.nhaFree,children:[(0,k.jsx)(`div`,{className:H.nhaFreeTitle,children:t(`settings.nhaFreeTitle`)}),(0,k.jsx)(`div`,{className:H.nhaFreeSub,children:t(`settings.nhaFreeSub`)}),(0,k.jsx)(`button`,{className:H.nhaFreeBtn,onClick:()=>{D(`/api/config`,{updates:[{key:`provider`,value:`nha`},{key:`model`,value:``},{key:`key`,value:``}]}).then(()=>{w(`nha`),re(``),te(``),l(`nhaFree`),setTimeout(()=>l(null),2e3)})},children:t(c===`nhaFree`?`settings.liaraActivated`:`settings.useLiara`)})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.llmProvider`)}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.llmProviderSub`)}),(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsx)(`label`,{className:H.fieldLabel,children:t(`settings.provider`)}),(0,k.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),className:H.fieldInput,children:[(0,k.jsx)(`option`,{value:`nha`,children:`NHA Free (Liara) — no API key needed`}),(0,k.jsx)(`option`,{value:`anthropic`,children:`Anthropic (Claude)`}),(0,k.jsx)(`option`,{value:`openai`,children:`OpenAI (GPT-4)`}),(0,k.jsx)(`option`,{value:`gemini`,children:`Google (Gemini)`}),(0,k.jsx)(`option`,{value:`deepseek`,children:`DeepSeek`}),(0,k.jsx)(`option`,{value:`grok`,children:`xAI (Grok)`}),(0,k.jsx)(`option`,{value:`mistral`,children:`Mistral`}),(0,k.jsx)(`option`,{value:`cohere`,children:`Cohere`})]})]}),C!==`nha`&&({anthropic:n.hasApiKey,openai:n.hasOpenaiKey,gemini:n.hasGeminiKey,deepseek:n.hasDeepseekKey,grok:n.hasGrokKey,mistral:n.hasMistralKey,cohere:n.hasCohereKey}[C]?(0,k.jsx)(`div`,{className:H.keySet,children:t(`settings.apiKeySet`)}):null),(0,k.jsx)(ut,{id:`apiKey`,label:t(`settings.apiKey`),placeholder:t(C===`nha`?`settings.apiKeyFreeNote`:`settings.apiKeyPh`),type:`password`,value:ee,onChange:te}),(0,k.jsx)(ut,{id:`model`,label:t(`settings.model`),placeholder:t(`settings.modelPh`),value:T,onChange:re}),(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsx)(`label`,{className:H.fieldLabel,children:t(`settings.thinking`)}),(0,k.jsxs)(`select`,{value:ce,onChange:e=>N(e.target.value),className:H.fieldInput,children:[(0,k.jsx)(`option`,{value:`off`,children:t(`settings.thinkingOff`)}),(0,k.jsx)(`option`,{value:`on`,children:t(`settings.thinkingOn`)})]})]}),(0,k.jsxs)(`button`,{className:H.saveBtn,onClick:me,children:[R(`provider`),` `,t(`settings.saveProvider`)]})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.language`)}),(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsx)(`label`,{className:H.fieldLabel,children:t(`settings.languageLabel`)}),(0,k.jsx)(`select`,{value:ie,onChange:t=>{let r=t.target.value;O(r),I(`lang`,r),e({...n,lang:r})},className:H.fieldInput,children:[[`it`,`Italiano`],[`en`,`English`],[`es`,`Español`],[`fr`,`Français`],[`de`,`Deutsch`],[`pt`,`Português`],[`nl`,`Nederlands`],[`pl`,`Polski`],[`ru`,`Русский`],[`zh`,`中文`],[`ja`,`日本語`],[`ko`,`한국어`],[`ar`,`العربية`],[`hi`,`हिन्दी`],[`tr`,`Türkçe`],[`sv`,`Svenska`],[`da`,`Dansk`],[`fi`,`Suomi`],[`cs`,`Čeština`]].map(([e,t])=>(0,k.jsx)(`option`,{value:e,children:t},e))})]})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.telegram`)}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.telegramSub`)}),n.hasTelegram&&(0,k.jsxs)(`div`,{className:H.connected,children:[`Telegram: `,t(`common.connected`)]}),n.hasDiscord&&(0,k.jsxs)(`div`,{className:H.connected,children:[`Discord: `,t(`common.connected`)]}),(0,k.jsx)(ut,{id:`tgToken`,label:t(`settings.telegramToken`),placeholder:n.hasTelegram?t(`settings.telegramSet`):t(`settings.telegramPh`),type:`password`,value:F,onChange:le}),(0,k.jsx)(ut,{id:`discordToken`,label:t(`settings.discordToken`),placeholder:n.hasDiscord?t(`settings.discordSet`):t(`settings.discordPh`),type:`password`,value:ue,onChange:de}),(0,k.jsxs)(`button`,{className:H.saveBtn,onClick:()=>{F&&I(`telegram-bot-token`,F),ue&&I(`discord-bot-token`,ue)},children:[R(`telegram-bot-token`),` `,t(`settings.saveBots`)]})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.dailyOps`)}),(0,k.jsx)(ut,{id:`planTime`,label:t(`settings.planTime`),placeholder:`07:00`,value:ae,onChange:A}),(0,k.jsx)(ut,{id:`summaryTime`,label:t(`settings.summaryTime`),placeholder:`18:00`,value:j,onChange:oe}),(0,k.jsx)(ut,{id:`meetingAlert`,label:t(`settings.meetingAlert`),placeholder:`30`,value:se,onChange:M}),(0,k.jsxs)(`button`,{className:H.saveBtn,onClick:he,children:[R(`planTime`),` `,t(`settings.saveSchedule`)]})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.googleAccount`)}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.googleSub`)}),n.hasGoogle&&(0,k.jsxs)(`div`,{className:H.connected,children:[`✅ `,t(`common.connected`),n.googleEmail?` · ${n.googleEmail}`:``]}),(0,k.jsxs)(`div`,{className:H.btnRow,children:[(0,k.jsx)(`button`,{className:H.saveBtn,onClick:ge,children:n.hasGoogle?t(`settings.reconnectGoogle`):t(`settings.connectGoogle`)}),n.hasGoogle&&(0,k.jsx)(`button`,{className:H.dangerBtn,onClick:L,children:t(`settings.disconnectGoogle`)})]}),g&&(0,k.jsx)(`div`,{className:H.statusMsg,children:g})]}),(0,k.jsxs)(`div`,{className:H.card,children:[(0,k.jsxs)(`div`,{className:H.cardTitleRow,children:[(0,k.jsx)(`div`,{className:H.cardTitle,children:t(`settings.imapAccounts`)}),(0,k.jsx)(`button`,{className:H.saveBtn,onClick:()=>{p({...lt}),h(``)},children:t(`settings.addAccount`)})]}),(0,k.jsx)(`div`,{className:H.cardSub,children:t(`settings.imapSub`)}),u.length===0&&!f&&(0,k.jsx)(`div`,{className:H.emptyImap,children:t(`settings.noImapAccounts`)}),u.map(e=>(0,k.jsxs)(`div`,{className:H.imapRow,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:H.imapName,children:e.display_name}),(0,k.jsxs)(`div`,{className:H.imapMeta,children:[e.email_address,` · `,e.imap_host]}),(0,k.jsxs)(`div`,{className:H.imapStatus,"data-status":e.sync_status,children:[e.sync_status,e.last_sync_at?` · ${t(`email.lastSync`)}: ${e.last_sync_at.slice(0,16)}`:``]})]}),(0,k.jsxs)(`div`,{className:H.imapBtns,children:[(0,k.jsx)(`button`,{className:H.imapSyncBtn,onClick:()=>ye(e.id),children:t(`settings.sync`)}),(0,k.jsx)(`button`,{className:H.imapEditBtn,onClick:()=>{p({...lt,id:e.id,display_name:e.display_name,email_address:e.email_address,from_name:e.from_name??``,imap_host:e.imap_host,imap_port:String(e.imap_port??993),smtp_host:e.smtp_host??``,smtp_port:String(e.smtp_port??587),username:e.username??``,password:``}),h(``)},children:t(`common.edit`)}),(0,k.jsx)(`button`,{className:H.imapDelBtn,onClick:()=>ve(e.id,e.display_name),children:t(`common.delete`)})]})]},e.id)),f&&(0,k.jsxs)(`div`,{className:H.imapForm,children:[(0,k.jsx)(`div`,{className:H.imapFormTitle,children:f.id?t(`settings.editImapAccount`):t(`settings.addImapAccount`)}),[[`display_name`,t(`settings.displayName`),t(`settings.displayNamePh`)],[`email_address`,t(`common.email`),`user@example.com`],[`from_name`,t(`settings.fromName`),t(`settings.fromNamePh`)],[`imap_host`,t(`settings.imapServer`),`e.g. imap.gmail.com`],[`imap_port`,t(`settings.imapPort`),`993`],[`smtp_host`,t(`settings.smtpServer`),`e.g. smtp.gmail.com`],[`smtp_port`,t(`settings.smtpPort`),`587`],[`username`,t(`settings.username`),`user@example.com`]].map(([e,t,n])=>(0,k.jsx)(ut,{id:`imap_${e}`,label:t,placeholder:n,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t})},e)),(0,k.jsxs)(`div`,{className:H.field,children:[(0,k.jsxs)(`label`,{className:H.fieldLabel,children:[t(`settings.password`),` `,f.id&&(0,k.jsx)(`span`,{className:H.pwdNote,children:t(`settings.passwordKeep`)})]}),(0,k.jsxs)(`div`,{className:H.pwdRow,children:[(0,k.jsx)(`input`,{type:y?`text`:`password`,placeholder:t(`settings.passwordPh`),value:f.password,onChange:e=>p(t=>t&&{...t,password:e.target.value}),className:H.fieldInput,style:{flex:1}}),(0,k.jsx)(`button`,{className:H.togglePwd,onClick:()=>b(e=>!e),children:t(y?`settings.hide`:`settings.show`)})]})]}),(0,k.jsxs)(`div`,{className:H.btnRow,children:[(0,k.jsx)(`button`,{className:H.saveBtn,onClick:_e,children:t(`common.save`)}),(0,k.jsx)(`button`,{className:H.cancelBtn,onClick:()=>p(null),children:t(`common.cancel`)})]}),m&&(0,k.jsx)(`div`,{className:H.statusMsg,children:m})]})]})]})}var ft={root:`_root_o07ov_1`,loading:`_loading_o07ov_2`,err:`_err_o07ov_3`,header:`_header_o07ov_4`,title:`_title_o07ov_5`,addBtn:`_addBtn_o07ov_6`,empty:`_empty_o07ov_7`,card:`_card_o07ov_8`,cardToday:`_cardToday_o07ov_9`,icon:`_icon_o07ov_10`,info:`_info_o07ov_11`,name:`_name_o07ov_12`,date:`_date_o07ov_13`,labelToday:`_labelToday_o07ov_14`,labelTomorrow:`_labelTomorrow_o07ov_15`,labelFuture:`_labelFuture_o07ov_16`,editBtn:`_editBtn_o07ov_17`,delBtn:`_delBtn_o07ov_18`,overlay:`_overlay_o07ov_20`,modal:`_modal_o07ov_21`,modalTitle:`_modalTitle_o07ov_22`,label:`_label_o07ov_14`,input:`_input_o07ov_24`,hint:`_hint_o07ov_25`,formErr:`_formErr_o07ov_26`,modalBtns:`_modalBtns_o07ov_27`,cancelBtn:`_cancelBtn_o07ov_28`,saveBtn:`_saveBtn_o07ov_29`};function pt(){let e=P(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(!1),p=(0,_.useCallback)(()=>{i(!0),E(`/api/birthdays`).then(e=>{e?.error?o(e.error):n(e?.birthdays??[]),i(!1)})},[]);(0,_.useEffect)(()=>{p()},[p]);let m=()=>{c({name:``,date:``}),u(``)},h=e=>{c({name:e.name,date:e.date,contactId:e.contactId}),u(``)},g=async()=>{if(!s)return;if(!s.name.trim()){u(`Name is required`);return}if(!s.date.trim()){u(`Date is required`);return}f(!0);let e=s.date;/^\d{2}-\d{2}$/.test(e)&&(e=`${new Date().getFullYear()}-${e}`),await D(`/api/birthdays`,{name:s.name,date:e,contactId:s.contactId??null,edit:!!s.contactId}),f(!1),c(null),p()},v=e=>{confirm(`Remove birthday for ${e.name}?`)&&D(`/api/birthdays/delete`,{contactId:e.contactId}).then(p)};return r?(0,k.jsxs)(`div`,{className:ft.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):a?(0,k.jsx)(`div`,{className:ft.err,children:a}):(0,k.jsxs)(`div`,{className:ft.root,children:[(0,k.jsxs)(`div`,{className:ft.header,children:[(0,k.jsx)(`div`,{className:ft.title,children:`Upcoming Birthdays`}),(0,k.jsx)(`button`,{className:ft.addBtn,onClick:m,children:`+ Add Birthday`})]}),t.length===0&&(0,k.jsxs)(`div`,{className:ft.empty,children:[e(`birthdays.noBirthdays`),(0,k.jsx)(`br`,{}),(0,k.jsx)(`small`,{children:`Add one above, or add birthdays to your Google Contacts.`})]}),t.map((t,n)=>{let r=t.daysUntil===0,i=t.daysUntil===1;return(0,k.jsxs)(`div`,{className:`${ft.card} ${r?ft.cardToday:``}`,children:[(0,k.jsx)(`span`,{className:ft.icon,children:`🎂`}),(0,k.jsxs)(`div`,{className:ft.info,children:[(0,k.jsx)(`div`,{className:ft.name,children:t.name}),(0,k.jsx)(`div`,{className:ft.date,children:t.date})]}),(0,k.jsx)(`div`,{className:r?ft.labelToday:i?ft.labelTomorrow:ft.labelFuture,children:r?`TODAY!`:i?`Tomorrow`:`in ${t.daysUntil} days`}),t.contactId&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:ft.editBtn,onClick:()=>h(t),children:e(`common.edit`)}),(0,k.jsx)(`button`,{className:ft.delBtn,onClick:()=>v(t),children:e(`common.delete`)})]})]},n)}),s&&(0,k.jsx)(`div`,{className:ft.overlay,onClick:e=>{e.target===e.currentTarget&&c(null)},children:(0,k.jsxs)(`div`,{className:ft.modal,children:[(0,k.jsx)(`div`,{className:ft.modalTitle,children:s.contactId?`Edit Birthday`:`Add Birthday`}),(0,k.jsx)(`label`,{className:ft.label,children:`Name *`}),(0,k.jsx)(`input`,{className:ft.input,value:s.name,onChange:e=>c(t=>t&&{...t,name:e.target.value}),placeholder:`Contact name`}),(0,k.jsx)(`label`,{className:ft.label,children:`Birthday (MM-DD or YYYY-MM-DD)`}),(0,k.jsx)(`input`,{className:ft.input,value:s.date,onChange:e=>c(t=>t&&{...t,date:e.target.value}),placeholder:`e.g. 03-15 or 1990-03-15`}),(0,k.jsx)(`div`,{className:ft.hint,children:`Birthday will be saved as a Google Calendar event.`}),l&&(0,k.jsx)(`div`,{className:ft.formErr,children:l}),(0,k.jsxs)(`div`,{className:ft.modalBtns,children:[(0,k.jsx)(`button`,{className:ft.cancelBtn,onClick:()=>c(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:ft.saveBtn,onClick:g,disabled:d,children:d?`Saving…`:s.contactId?`Save`:`Add`})]})]})})]})}var U={root:`_root_1z04o_1`,header:`_header_1z04o_3`,title:`_title_1z04o_4`,subtitle:`_subtitle_1z04o_5`,code:`_code_1z04o_6`,addBtn:`_addBtn_1z04o_8`,tabs:`_tabs_1z04o_10`,tab:`_tab_1z04o_10`,tabActive:`_tabActive_1z04o_12`,loading:`_loading_1z04o_14`,err:`_err_1z04o_15`,empty:`_empty_1z04o_17`,emptyIcon:`_emptyIcon_1z04o_18`,emptyTitle:`_emptyTitle_1z04o_19`,emptySub:`_emptySub_1z04o_20`,card:`_card_1z04o_23`,cardDisabled:`_cardDisabled_1z04o_24`,cardTop:`_cardTop_1z04o_25`,cardLeft:`_cardLeft_1z04o_26`,jobName:`_jobName_1z04o_27`,schedule:`_schedule_1z04o_28`,agentBadge:`_agentBadge_1z04o_29`,statusBadge:`_statusBadge_1z04o_30`,statusActive:`_statusActive_1z04o_31`,statusPaused:`_statusPaused_1z04o_32`,jobPrompt:`_jobPrompt_1z04o_33`,jobMeta:`_jobMeta_1z04o_34`,cardActions:`_cardActions_1z04o_35`,runBtn:`_runBtn_1z04o_36`,editBtn:`_editBtn_1z04o_37`,pauseBtn:`_pauseBtn_1z04o_38`,resumeBtn:`_resumeBtn_1z04o_39`,delBtn:`_delBtn_1z04o_40`,templates:`_templates_1z04o_43`,templatesNote:`_templatesNote_1z04o_44`,templateCard:`_templateCard_1z04o_45`,templateLabel:`_templateLabel_1z04o_46`,templatePrompt:`_templatePrompt_1z04o_47`,templateBtns:`_templateBtns_1z04o_48`,scheduleTplBtn:`_scheduleTplBtn_1z04o_49`,runTplBtn:`_runTplBtn_1z04o_50`,formOverlay:`_formOverlay_1z04o_54`,formModal:`_formModal_1z04o_55`,formTitle:`_formTitle_1z04o_56`,label:`_label_1z04o_57`,input:`_input_1z04o_58`,textarea:`_textarea_1z04o_59`,presets:`_presets_1z04o_61`,preset:`_preset_1z04o_61`,presetActive:`_presetActive_1z04o_63`,cronHints:`_cronHints_1z04o_65`,cronHint:`_cronHint_1z04o_65`,formErr:`_formErr_1z04o_70`,formOk:`_formOk_1z04o_71`,formBtns:`_formBtns_1z04o_72`,cancelBtn:`_cancelBtn_1z04o_73`,saveBtn:`_saveBtn_1z04o_74`},mt=[{label:`Every 15 min`,value:`every 15 minutes`},{label:`Every 30 min`,value:`every 30 minutes`},{label:`Every hour`,value:`every hour`},{label:`Every 6h`,value:`every 6 hours`},{label:`Daily 8am`,value:`every day at 08:00`},{label:`Daily 9am`,value:`every day at 09:00`},{label:`Daily noon`,value:`every day at 12:00`},{label:`Daily 6pm`,value:`every day at 18:00`},{label:`Mon–Fri 9am`,value:`weekdays at 09:00`},{label:`Every Monday`,value:`every monday at 09:00`}],ht=[{label:`🌅 Morning Briefing`,prompt:`Summarize my unread emails from the last 12 hours, check today's calendar events, list my top 3 priority tasks, and give me a focused action plan for the day.`},{label:`🌆 Evening Review`,prompt:`Review what I accomplished today: check completed tasks, summarize any important emails received, flag unresolved issues, and prepare a priority list for tomorrow.`},{label:`📰 News Digest`,prompt:`Search for the top AI, tech, and finance news from the last 24 hours. Summarize the 5 most important stories with key takeaways and market implications.`},{label:`📈 Market Update`,prompt:`Provide a comprehensive market update: macro environment, major indices performance, top movers, notable events, and key levels to watch. Use herald and mercury agents.`},{label:`🐙 GitHub Monitor`,prompt:`Check my GitHub notifications, summarize open issues and pull requests that need attention, and draft brief responses for the most urgent ones.`},{label:`📊 Weekly Report`,prompt:`Generate a weekly productivity report: tasks completed vs pending, email response rate, upcoming calendar events, and 3 strategic priorities for next week.`},{label:`🔒 Security Scan`,prompt:`Run a security awareness check: scan recent code commits for potential vulnerabilities, check dependency alerts, and summarize any security-related GitHub notifications.`},{label:`🎯 Goal Tracker`,prompt:`Review my tasks and notes for goal progress. Identify what's on track, what's at risk, and suggest one concrete action to unblock the most important goal.`}],gt=[{label:`0 9 * * 1-5`,desc:`Mon–Fri at 9:00 AM`},{label:`0 */6 * * *`,desc:`Every 6 hours`},{label:`*/30 * * * *`,desc:`Every 30 minutes`},{label:`0 8 * * *`,desc:`Daily at 8:00 AM`},{label:`0 20 * * 5`,desc:`Every Friday at 8 PM`}];function _t(){let e=P(),t=ne(e=>e.setView),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)({name:``,schedule:``,prompt:``,agent:``}),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(null),[x,S]=(0,_.useState)(`jobs`),C=()=>{a(!0),E(`/api/cron`).then(e=>{e?.error?s(e.error):r(e?.jobs??[]),a(!1)}).catch(()=>{r([]),a(!1)})};(0,_.useEffect)(()=>{C()},[]);let w=()=>{d({name:``,schedule:``,prompt:``,agent:``}),h(``),v(``),b(null),l(!0)},ee=e=>{d({name:e.name??``,schedule:e.schedule,prompt:e.prompt??e.command??``,agent:e.agent??``}),h(``),v(``),b(e.id),l(!0)},te=async()=>{if(!u.schedule.trim()){h(`Schedule is required`);return}if(!u.prompt.trim()){h(`Task prompt is required`);return}p(!0),h(``);try{y?await D(`/api/cron/update`,{id:y,schedule:u.schedule,prompt:u.prompt,agent:u.agent||void 0,name:u.name||void 0}):await D(`/api/cron`,{schedule:u.schedule,prompt:u.prompt,agent:u.agent||void 0,name:u.name||void 0}),v(y?`Updated!`:`Job scheduled!`),setTimeout(()=>{v(``),l(!1)},1500),C()}catch(e){h(e.message??`Failed`)}p(!1)},T=(e,t)=>D(`/api/cron/toggle`,{id:e,enabled:!t}).then(C),re=e=>{confirm(`Delete this scheduled task?`)&&D(`/api/cron/delete`,{id:e}).then(C)},ie=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},O=e=>{d(t=>({...t,prompt:e.prompt,name:e.label.replace(/^[^\s]+\s/,``)})),S(`jobs`),l(!0)};return(0,k.jsxs)(`div`,{className:U.root,children:[(0,k.jsxs)(`div`,{className:U.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:U.title,children:`⏰ Scheduled Tasks`}),(0,k.jsxs)(`div`,{className:U.subtitle,children:[`Automate agents on a recurring schedule. Daemon must be running: `,(0,k.jsx)(`code`,{className:U.code,children:`nha ops start`})]})]}),(0,k.jsx)(`button`,{className:U.addBtn,onClick:w,children:`+ New Task`})]}),(0,k.jsxs)(`div`,{className:U.tabs,children:[(0,k.jsxs)(`button`,{className:`${U.tab} ${x===`jobs`?U.tabActive:``}`,onClick:()=>S(`jobs`),children:[`Jobs (`,n.length,`)`]}),(0,k.jsx)(`button`,{className:`${U.tab} ${x===`templates`?U.tabActive:``}`,onClick:()=>S(`templates`),children:`Templates`})]}),x===`templates`&&(0,k.jsxs)(`div`,{className:U.templates,children:[(0,k.jsx)(`div`,{className:U.templatesNote,children:`Click a template to pre-fill the job form or run it immediately in Chat.`}),ht.map(t=>(0,k.jsxs)(`div`,{className:U.templateCard,children:[(0,k.jsx)(`div`,{className:U.templateLabel,children:t.label}),(0,k.jsx)(`div`,{className:U.templatePrompt,children:t.prompt}),(0,k.jsxs)(`div`,{className:U.templateBtns,children:[(0,k.jsx)(`button`,{className:U.scheduleTplBtn,onClick:()=>O(t),children:`Schedule`}),(0,k.jsxs)(`button`,{className:U.runTplBtn,onClick:()=>ie(t.prompt),children:[e(`cron.run`),` in Chat →`]})]})]},t.label))]}),x===`jobs`&&(0,k.jsxs)(k.Fragment,{children:[i&&(0,k.jsxs)(`div`,{className:U.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading jobs…`]}),o&&(0,k.jsx)(`div`,{className:U.err,children:o}),!i&&n.length===0&&!c&&(0,k.jsxs)(`div`,{className:U.empty,children:[(0,k.jsx)(`div`,{className:U.emptyIcon,children:`⏰`}),(0,k.jsxs)(`div`,{className:U.emptyTitle,children:[e(`cron.noJobs`),` tasks`]}),(0,k.jsx)(`div`,{className:U.emptySub,children:`Create a job to automate agents on a recurring schedule, or browse the Templates tab for ready-made automation recipes.`}),(0,k.jsx)(`button`,{className:U.addBtn,onClick:w,children:`+ New Task`})]}),n.map(e=>(0,k.jsxs)(`div`,{className:`${U.card} ${e.enabled?``:U.cardDisabled}`,children:[(0,k.jsxs)(`div`,{className:U.cardTop,children:[(0,k.jsxs)(`div`,{className:U.cardLeft,children:[e.name&&(0,k.jsx)(`div`,{className:U.jobName,children:e.name}),(0,k.jsx)(`code`,{className:U.schedule,children:e.schedule}),e.agent&&(0,k.jsx)(`span`,{className:U.agentBadge,children:e.agent}),(0,k.jsx)(`span`,{className:`${U.statusBadge} ${e.enabled?U.statusActive:U.statusPaused}`,children:e.enabled?`active`:`paused`})]}),(0,k.jsxs)(`div`,{className:U.cardActions,children:[(0,k.jsx)(`button`,{className:U.runBtn,onClick:()=>ie(e.prompt??e.command??``),title:`Run now in Chat`,children:`▶`}),(0,k.jsx)(`button`,{className:U.editBtn,onClick:()=>ee(e),children:`Edit`}),(0,k.jsx)(`button`,{className:e.enabled?U.pauseBtn:U.resumeBtn,onClick:()=>T(e.id,e.enabled),children:e.enabled?`Pause`:`Resume`}),(0,k.jsx)(`button`,{className:U.delBtn,onClick:()=>re(e.id),children:`✕`})]})]}),(0,k.jsx)(`div`,{className:U.jobPrompt,children:e.prompt??e.command}),(0,k.jsxs)(`div`,{className:U.jobMeta,children:[e.runCount!==void 0&&(0,k.jsxs)(`span`,{children:[`ran `,e.runCount,`×`]}),e.lastRun&&(0,k.jsxs)(`span`,{children:[` · last `,new Date(e.lastRun).toLocaleString()]}),e.nextRun&&(0,k.jsxs)(`span`,{children:[` · next `,new Date(e.nextRun).toLocaleString()]})]})]},e.id))]}),c&&(0,k.jsx)(`div`,{className:U.formOverlay,onClick:e=>{e.target===e.currentTarget&&l(!1)},children:(0,k.jsxs)(`div`,{className:U.formModal,children:[(0,k.jsx)(`div`,{className:U.formTitle,children:y?`Edit Scheduled Task`:`New Scheduled Task`}),(0,k.jsx)(`label`,{className:U.label,children:`Name (optional)`}),(0,k.jsx)(`input`,{className:U.input,value:u.name,onChange:e=>d(t=>({...t,name:e.target.value})),placeholder:`e.g. Morning Briefing`}),(0,k.jsx)(`label`,{className:U.label,children:`Schedule *`}),(0,k.jsx)(`div`,{className:U.presets,children:mt.map(e=>(0,k.jsx)(`button`,{className:`${U.preset} ${u.schedule===e.value?U.presetActive:``}`,onClick:()=>d(t=>({...t,schedule:e.value})),children:e.label},e.value))}),(0,k.jsx)(`input`,{className:U.input,value:u.schedule,onChange:e=>d(t=>({...t,schedule:e.target.value})),placeholder:`every day at 09:00 — or cron syntax: 0 9 * * 1-5`}),(0,k.jsx)(`div`,{className:U.cronHints,children:gt.map(e=>(0,k.jsxs)(`span`,{className:U.cronHint,onClick:()=>d(t=>({...t,schedule:e.label})),children:[(0,k.jsx)(`code`,{children:e.label}),` `,e.desc]},e.label))}),(0,k.jsx)(`label`,{className:U.label,children:`Task / Prompt *`}),(0,k.jsx)(`textarea`,{className:U.textarea,value:u.prompt,onChange:e=>d(t=>({...t,prompt:e.target.value})),placeholder:`Describe what the agent should do (e.g. Summarize my unread emails and list my 3 top priority tasks)`,rows:4}),(0,k.jsx)(`label`,{className:U.label,children:`Agent (optional — leave blank for auto-routing)`}),(0,k.jsx)(`input`,{className:U.input,value:u.agent,onChange:e=>d(t=>({...t,agent:e.target.value})),placeholder:`e.g. herald, oracle, mercury, EmailAgent, general`}),m&&(0,k.jsx)(`div`,{className:U.formErr,children:m}),g&&(0,k.jsx)(`div`,{className:U.formOk,children:g}),(0,k.jsxs)(`div`,{className:U.formBtns,children:[(0,k.jsx)(`button`,{className:U.cancelBtn,onClick:()=>l(!1),children:`Cancel`}),(0,k.jsx)(`button`,{className:U.saveBtn,onClick:te,disabled:f,children:f?`Saving…`:y?`Update`:`Schedule`})]})]})})]})}var vt={root:`_root_1npv7_1`,loading:`_loading_1npv7_2`,sidebar:`_sidebar_1npv7_4`,newBtn:`_newBtn_1npv7_5`,empty:`_empty_1npv7_6`,noteItem:`_noteItem_1npv7_8`,noteItemActive:`_noteItemActive_1npv7_10`,noteTitle:`_noteTitle_1npv7_11`,noteMeta:`_noteMeta_1npv7_12`,notePreview:`_notePreview_1npv7_13`,noteTags:`_noteTags_1npv7_14`,noteTag:`_noteTag_1npv7_14`,editor:`_editor_1npv7_17`,emptyEditor:`_emptyEditor_1npv7_18`,titleInput:`_titleInput_1npv7_19`,contentArea:`_contentArea_1npv7_21`,editorFooter:`_editorFooter_1npv7_22`,delNoteBtn:`_delNoteBtn_1npv7_23`,cancelBtn:`_cancelBtn_1npv7_24`,saveBtn:`_saveBtn_1npv7_25`};function yt(){let e=P(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(!1),h=()=>E(`/api/notes`).then(e=>{n(e?.notes??[]),i(!1)});(0,_.useEffect)(()=>{h()},[]);let g=e=>{o(e),c(e.title),u(e.content),m(!1)},v=()=>{o(null),c(``),u(``),m(!0)},y=async()=>{f(!0),p?await D(`/api/notes`,{title:s||`Untitled`,content:l}):a&&await D(`/api/notes/${a.id}`,{title:s,content:l}),f(!1),m(!1),h()},b=(e,t)=>{confirm(`Delete note "${t}"?`)&&D(`/api/notes/${e}/delete`,{}).then(h)};return r?(0,k.jsxs)(`div`,{className:vt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:vt.root,children:[(0,k.jsxs)(`div`,{className:vt.sidebar,children:[(0,k.jsx)(`button`,{className:vt.newBtn,onClick:v,children:`+ New Note`}),t.length===0&&(0,k.jsx)(`div`,{className:vt.empty,children:e(`notes.noNotes`)}),t.map(e=>(0,k.jsxs)(`div`,{className:`${vt.noteItem} ${a?.id===e.id?vt.noteItemActive:``}`,onClick:()=>g(e),children:[(0,k.jsx)(`div`,{className:vt.noteTitle,children:e.title||`Untitled`}),(0,k.jsx)(`div`,{className:vt.noteMeta,children:e.updatedAt?new Date(e.updatedAt).toLocaleDateString():``}),e.content&&(0,k.jsx)(`div`,{className:vt.notePreview,children:e.content.slice(0,150)}),e.tags&&e.tags.length>0&&(0,k.jsx)(`div`,{className:vt.noteTags,children:e.tags.map(e=>(0,k.jsx)(`span`,{className:vt.noteTag,children:e},e))})]},e.id))]}),(0,k.jsx)(`div`,{className:vt.editor,children:a||p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`input`,{className:vt.titleInput,value:s,onChange:e=>c(e.target.value),placeholder:`Note title…`}),(0,k.jsx)(`textarea`,{className:vt.contentArea,value:l,onChange:e=>u(e.target.value),placeholder:`Start writing…`}),(0,k.jsxs)(`div`,{className:vt.editorFooter,children:[a&&(0,k.jsx)(`button`,{className:vt.delNoteBtn,onClick:()=>b(a.id,a.title),children:e(`common.delete`)}),(0,k.jsx)(`button`,{className:vt.cancelBtn,onClick:()=>{o(null),m(!1)},children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:vt.saveBtn,onClick:y,disabled:d,children:d?`Saving…`:`Save`})]})]}):(0,k.jsx)(`div`,{className:vt.emptyEditor,children:`Select a note or create a new one`})})]})}var bt={root:`_root_18yos_1`,loading:`_loading_18yos_2`,error:`_error_18yos_3`,toolbar:`_toolbar_18yos_5`,search:`_search_18yos_6`,addBtn:`_addBtn_18yos_7`,count:`_count_18yos_10`,empty:`_empty_18yos_12`,grid:`_grid_18yos_14`,card:`_card_18yos_16`,actions:`_actions_18yos_29`,avatar:`_avatar_18yos_31`,avatarImg:`_avatarImg_18yos_38`,info:`_info_18yos_40`,name:`_name_18yos_41`,row:`_row_18yos_42`,email:`_email_18yos_43`,phone:`_phone_18yos_44`,company:`_company_18yos_45`,birthday:`_birthday_18yos_46`,iconBtn:`_iconBtn_18yos_52`,iconBtnRed:`_iconBtnRed_18yos_58`,overlay:`_overlay_18yos_61`,modal:`_modal_18yos_62`,modalTitle:`_modalTitle_18yos_63`,field:`_field_18yos_64`,label:`_label_18yos_65`,input:`_input_18yos_66`,formStatus:`_formStatus_18yos_67`,formError:`_formError_18yos_68`,modalBtns:`_modalBtns_18yos_69`,cancelBtn:`_cancelBtn_18yos_70`,saveBtn:`_saveBtn_18yos_71`},xt={name:``,email:``,phone:``,company:``,address:``,notes:``};function St(){let e=P(),t=ne(e=>e.setView),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(``),y=(0,_.useRef)(null),b=(e=``)=>{E(e?`/api/contacts?q=${encodeURIComponent(e)}`:`/api/contacts`).then(e=>{r(e?.contacts??[]),a(!1),s(``)}).catch(()=>{s(`Could not load contacts. Run nha google revoke then nha google auth.`),a(!1)})};(0,_.useEffect)(()=>{b()},[]);let x=e=>{l(e),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>b(e),400)},S=()=>{d(null),p({...xt}),v(``)},C=e=>{d(e),p({name:e.name,email:e.email??``,phone:e.phone??``,company:e.company??``,address:e.address??``,notes:e.notes??``}),v(``)},w=async()=>{if(f?.name){h(!0),v(`Saving…`);try{if(u?.resourceName){let e=await D(`/api/contacts/update`,{resourceName:u.resourceName,fields:f});if(e?.error){v(`Error: `+e.error);return}}else if(u)await D(`/api/contacts/update`,{resourceName:u.id,fields:f});else{let e=await D(`/api/contacts`,f);if(e?.error){v(`Error: `+e.error);return}}v(`Saved!`),setTimeout(()=>{p(null),d(null),b(c)},800)}catch(e){v(`Error: `+e.message)}finally{h(!1)}}},ee=(e,t)=>{e.stopPropagation(),confirm(`Delete "${t.name}"?`)&&D(`/api/contacts/delete`,{resourceName:t.resourceName||t.id}).then(e=>{let t=e;if(t?.error){alert(`Error: `+t.error);return}b(c)})},te=(e,n,r)=>{e.stopPropagation(),t(`chat`),setTimeout(()=>{let e=document.getElementById(`chatInput`);e&&(e.value=`Send an email to ${r} (${n}) about `,e.focus())},300)},T=e=>(e||`?`).split(` `).map(e=>e[0]).slice(0,2).join(``).toUpperCase();return i?(0,k.jsxs)(`div`,{className:bt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading contacts…`]}):o?(0,k.jsx)(`div`,{className:bt.error,children:o}):(0,k.jsxs)(`div`,{className:bt.root,children:[(0,k.jsxs)(`div`,{className:bt.toolbar,children:[(0,k.jsx)(`input`,{className:bt.search,value:c,onChange:e=>x(e.target.value),placeholder:`Search contacts…`}),n.length>0&&(0,k.jsxs)(`span`,{className:bt.count,children:[n.length,` contact`,n.length===1?``:`s`]}),(0,k.jsx)(`button`,{className:bt.addBtn,onClick:S,children:`+ Add`})]}),n.length===0&&(0,k.jsxs)(`div`,{className:bt.empty,children:[e(`contacts.noContacts`),(0,k.jsx)(`br`,{}),`Add a Google account or add contacts manually.`]}),(0,k.jsx)(`div`,{className:bt.grid,children:n.map(e=>(0,k.jsxs)(`div`,{className:bt.card,onClick:()=>C(e),children:[(0,k.jsx)(`div`,{className:bt.avatar,children:e.photo?(0,k.jsx)(`img`,{src:e.photo,alt:e.name,className:bt.avatarImg}):T(e.name)}),(0,k.jsxs)(`div`,{className:bt.info,children:[(0,k.jsx)(`div`,{className:bt.name,children:e.name||`(no name)`}),(0,k.jsxs)(`div`,{className:bt.row,children:[e.email&&(0,k.jsx)(`span`,{className:bt.email,children:e.email}),e.phone&&(0,k.jsx)(`span`,{className:bt.phone,children:e.phone}),e.company&&(0,k.jsxs)(`span`,{className:bt.company,children:[e.company,e.title?` · ${e.title}`:``]}),e.birthday&&(0,k.jsxs)(`span`,{className:bt.birthday,children:[`🎂 `,e.birthday]})]})]}),(0,k.jsxs)(`div`,{className:bt.actions,children:[e.email&&(0,k.jsx)(`button`,{className:bt.iconBtn,onClick:t=>te(t,e.email,e.name),title:`Send email via chat`,children:`✉`}),(0,k.jsx)(`button`,{className:bt.iconBtn,onClick:t=>{t.stopPropagation(),C(e)},title:`Edit`,children:`✎`}),(0,k.jsx)(`button`,{className:`${bt.iconBtn} ${bt.iconBtnRed}`,onClick:t=>ee(t,e),title:`Delete`,children:`✕`})]})]},e.id))}),f&&(0,k.jsx)(`div`,{className:bt.overlay,onClick:e=>{e.target===e.currentTarget&&p(null)},children:(0,k.jsxs)(`div`,{className:bt.modal,children:[(0,k.jsx)(`div`,{className:bt.modalTitle,children:u?`Edit Contact`:`New Contact`}),[[`name`,`Name`,`Full name *`],[`email`,`Email`,`user@example.com`],[`phone`,`Phone`,`+1 555 123 4567`],[`company`,`Company`,`Acme Inc`],[`address`,`Address`,`123 Main St, New York`],[`notes`,`Notes`,`Any additional info`]].map(([e,t,n])=>(0,k.jsxs)(`div`,{className:bt.field,children:[(0,k.jsx)(`label`,{className:bt.label,children:t}),(0,k.jsx)(`input`,{className:bt.input,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t.target.value}),placeholder:n,onKeyDown:t=>t.key===`Enter`&&e===`name`&&w()})]},e)),g&&(0,k.jsx)(`div`,{className:g.startsWith(`Error`)?bt.formError:bt.formStatus,children:g}),(0,k.jsxs)(`div`,{className:bt.modalBtns,children:[(0,k.jsx)(`button`,{className:bt.cancelBtn,onClick:()=>p(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:bt.saveBtn,onClick:w,disabled:m||!f.name,children:m?`…`:`Save`})]})]})})]})}var W={root:`_root_19042_2`,topbar:`_topbar_19042_11`,topbarLeft:`_topbarLeft_19042_20`,topbarTitle:`_topbarTitle_19042_21`,topbarSub:`_topbarSub_19042_22`,topbarActions:`_topbarActions_19042_23`,runBtn:`_runBtn_19042_25`,runBtnActive:`_runBtnActive_19042_32`,logBtn:`_logBtn_19042_34`,newWfBtn:`_newWfBtn_19042_41`,body:`_body_19042_50`,sidebar:`_sidebar_19042_53`,sidebarTitle:`_sidebarTitle_19042_61`,sidebarEmpty:`_sidebarEmpty_19042_65`,wfItem:`_wfItem_19042_67`,wfItemActive:`_wfItemActive_19042_78`,wfItemRow:`_wfItemRow_19042_79`,wfItemName:`_wfItemName_19042_80`,wfItemMeta:`_wfItemMeta_19042_81`,wfOn:`_wfOn_19042_82`,wfOff:`_wfOff_19042_83`,wfDelBtn:`_wfDelBtn_19042_84`,canvasArea:`_canvasArea_19042_92`,canvasHeader:`_canvasHeader_19042_94`,wfNameInput:`_wfNameInput_19042_99`,canvasHint:`_canvasHint_19042_106`,portHint:`_portHint_19042_107`,connectHint:`_connectHint_19042_108`,cancelConnectBtn:`_cancelConnectBtn_19042_109`,canvas:`_canvas_19042_92`,canvasConnecting:`_canvasConnecting_19042_122`,canvasSvg:`_canvasSvg_19042_124`,canvasNode:`_canvasNode_19042_134`,canvasNodeSelected:`_canvasNodeSelected_19042_152`,canvasNodeConnecting:`_canvasNodeConnecting_19042_153`,nodeIcon:`_nodeIcon_19042_155`,nodeLabel:`_nodeLabel_19042_156`,nodeConfigPreview:`_nodeConfigPreview_19042_157`,nodeDelBtn:`_nodeDelBtn_19042_159`,portOut:`_portOut_19042_171`,portActive:`_portActive_19042_182`,portIn:`_portIn_19042_184`,pulse:`_pulse_19042_1`,canvasDrop:`_canvasDrop_19042_195`,canvasEmpty:`_canvasEmpty_19042_203`,canvasEmptyIcon:`_canvasEmptyIcon_19042_208`,canvasEmptyTitle:`_canvasEmptyTitle_19042_209`,canvasEmptyDesc:`_canvasEmptyDesc_19042_210`,logPanel:`_logPanel_19042_213`,logHeader:`_logHeader_19042_220`,logTime:`_logTime_19042_226`,logClose:`_logClose_19042_227`,logEmpty:`_logEmpty_19042_228`,logStep:`_logStep_19042_229`,logStepError:`_logStepError_19042_230`,logStepHeader:`_logStepHeader_19042_231`,logStepIcon:`_logStepIcon_19042_232`,logStepLabel:`_logStepLabel_19042_233`,logStepErrBadge:`_logStepErrBadge_19042_234`,logStepErr:`_logStepErr_19042_230`,logStepOutput:`_logStepOutput_19042_236`,rightPanel:`_rightPanel_19042_241`,configPanel:`_configPanel_19042_252`,configHeader:`_configHeader_19042_253`,configClose:`_configClose_19042_254`,configDesc:`_configDesc_19042_255`,configFields:`_configFields_19042_256`,configField:`_configField_19042_256`,configLabel:`_configLabel_19042_258`,configRequired:`_configRequired_19042_259`,configInput:`_configInput_19042_260`,configHint:`_configHint_19042_267`,configDelete:`_configDelete_19042_269`,palette:`_palette_19042_273`,paletteTitle:`_paletteTitle_19042_274`,paletteTabs:`_paletteTabs_19042_275`,paletteTab:`_paletteTab_19042_275`,paletteTabActive:`_paletteTabActive_19042_281`,paletteNodes:`_paletteNodes_19042_282`,paletteDef:`_paletteDef_19042_284`,paletteDefIcon:`_paletteDefIcon_19042_292`,paletteDefLabel:`_paletteDefLabel_19042_293`,paletteDefDesc:`_paletteDefDesc_19042_294`,paletteFooter:`_paletteFooter_19042_296`,paletteGuide:`_paletteGuide_19042_300`,guideTitle:`_guideTitle_19042_308`,guideStep:`_guideStep_19042_317`,guideNum:`_guideNum_19042_325`,guideTip:`_guideTip_19042_341`,guideCode:`_guideCode_19042_352`},Ct=[{id:`trigger_manual`,type:`trigger`,label:`Manual`,icon:`▶`,color:`#6366f1`,description:`Run manually with optional text input.`,configFields:[{key:`input`,label:`Input text`,placeholder:`Optional initial input`}]},{id:`trigger_cron`,type:`trigger`,label:`Cron`,icon:`⏰`,color:`#fbbf24`,description:`Run on a schedule (cron expression).`,configFields:[{key:`schedule`,label:`Cron expression`,placeholder:`0 8 * * *`,required:!0}]},{id:`trigger_email`,type:`trigger`,label:`New Email`,icon:`📧`,color:`#38bdf8`,description:`Trigger when a new email arrives matching a filter.`,configFields:[{key:`filter`,label:`Gmail filter`,placeholder:`subject:TODO is:unread`}]},{id:`trigger_webhook`,type:`trigger`,label:`Webhook`,icon:`🔗`,color:`#a5b4fc`,description:`Trigger via HTTP POST.`,configFields:[{key:`path`,label:`Path`,placeholder:`/hook/my-trigger`}]},{id:`action_email`,type:`action`,label:`Send Email`,icon:`✉`,color:`#38bdf8`,description:`Send email via Gmail or IMAP.`,configFields:[{key:`to`,label:`To`,placeholder:`email@example.com`,required:!0},{key:`subject`,label:`Subject`,placeholder:`Subject or {{output}}`},{key:`body`,label:`Body`,placeholder:`{{output}}`}]},{id:`action_slack`,type:`action`,label:`Slack Message`,icon:`💬`,color:`#818cf8`,description:`Post a message to a Slack channel.`,configFields:[{key:`channel`,label:`Channel`,placeholder:`#general`,required:!0},{key:`text`,label:`Text`,placeholder:`{{output}}`}]},{id:`action_calendar`,type:`action`,label:`Create Event`,icon:`📅`,color:`#4ade80`,description:`Create a Google Calendar event.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`date`,label:`Date (YYYY-MM-DD)`,placeholder:`2025-01-15`},{key:`time`,label:`Time (HH:MM)`,placeholder:`09:00`}]},{id:`action_task`,type:`action`,label:`Create Task`,icon:`✅`,color:`#fbbf24`,description:`Add a task to your task list.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`priority`,label:`Priority`,placeholder:`medium`}]},{id:`action_drive`,type:`action`,label:`Save to Drive`,icon:`💾`,color:`#a78bfa`,description:`Save a text file to Google Drive.`,configFields:[{key:`name`,label:`Filename`,placeholder:`output.txt`,required:!0},{key:`content`,label:`Content`,placeholder:`{{output}}`}]},{id:`action_notion`,type:`action`,label:`Notion Page`,icon:`📋`,color:`#e4e4e7`,description:`Create or update a Notion page.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`content`,label:`Content`,placeholder:`{{output}}`}]},{id:`action_github`,type:`action`,label:`GitHub Issue`,icon:`🐙`,color:`#6ee7b7`,description:`Create a GitHub issue.`,configFields:[{key:`repo`,label:`Repo (owner/name)`,placeholder:`user/repo`,required:!0},{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`body`,label:`Body`,placeholder:``}]},{id:`action_webhook`,type:`action`,label:`HTTP Request`,icon:`🌐`,color:`#38bdf8`,description:`Make an HTTP request.`,configFields:[{key:`url`,label:`URL`,placeholder:`https://…`,required:!0},{key:`method`,label:`Method`,placeholder:`POST`},{key:`body`,label:`Body`,placeholder:`{{output}}`}]},{id:`ai_agent`,type:`ai`,label:`Run Agent`,icon:`🤖`,color:`#818cf8`,description:`Run any of the 38 NHA specialist agents.`,configFields:[{key:`agent`,label:`Agent name`,placeholder:`herald, saber, forge…`,required:!0},{key:`prompt`,label:`Prompt`,placeholder:`Summarize this: {{output}}`,required:!0}]},{id:`ai_summarize`,type:`ai`,label:`Summarize`,icon:`📝`,color:`#a5b4fc`,description:`Summarize text with AI (free via Liara).`,configFields:[{key:`prompt`,label:`Prompt`,placeholder:`Summarize: {{output}}`}]},{id:`ai_classify`,type:`ai`,label:`Classify`,icon:`🏷`,color:`#a5b4fc`,description:`Classify content into categories.`,configFields:[{key:`categories`,label:`Categories (comma-separated)`,placeholder:`urgent, normal, spam`},{key:`prompt`,label:`Prompt`,placeholder:`Classify this email: {{output}}`}]},{id:`ai_extract`,type:`ai`,label:`Extract Data`,icon:`🔍`,color:`#a5b4fc`,description:`Extract structured data from text.`,configFields:[{key:`prompt`,label:`What to extract`,placeholder:`Extract name, email, date from: {{output}}`}]},{id:`ai_translate`,type:`ai`,label:`Translate`,icon:`🌍`,color:`#a5b4fc`,description:`Translate text to another language.`,configFields:[{key:`lang`,label:`Target language`,placeholder:`Italian`,required:!0},{key:`prompt`,label:`Text`,placeholder:`{{output}}`}]}],wt=Object.fromEntries(Ct.map(e=>[e.id,e])),Tt=90,Et=72;function Dt(){return`n_${Date.now()}_${Math.random().toString(36).slice(2,6)}`}function Ot(e,t){return{x:e.x+(t===`out`?Tt:0),y:e.y+Et/2}}function kt(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(`trigger`),g=(0,_.useRef)(null),v=(0,_.useRef)(null),y=(0,_.useRef)(null),b=(0,_.useCallback)(async()=>{let e=(await E(`/api/workflows`).catch(()=>null))?.workflows??[];t(e),r(t=>t?e.find(e=>e.id===t.id)??e[0]??null:e[0]??null)},[]);(0,_.useEffect)(()=>{b()},[b]);let x=(0,_.useCallback)(async e=>{r(e),t(t=>t.map(t=>t.id===e.id?e:t)),await D(`/api/workflows/${e.id}`,e,`PUT`).catch(()=>null)},[]),S=async()=>{let e={id:`wf_${Date.now()}`,name:`New Workflow`,enabled:!1,nodes:[],edges:[],nodeDefs:Ct},n=(await D(`/api/workflows`,e).catch(()=>null))?.workflow??e;t(e=>[...e,n]),r(n),a(null),d([]),p(!1)},C=async e=>{confirm(`Delete this workflow?`)&&(await D(`/api/workflows/${e}`,{},`DELETE`).catch(()=>null),b())},w=(0,_.useCallback)(e=>{e.preventDefault();let t=v.current;if(!t||!n)return;let r=y.current.getBoundingClientRect(),i=Math.round((e.clientX-r.left-Tt/2)/20)*20,o=Math.round((e.clientY-r.top-Et/2)/20)*20,s={id:Dt(),defId:t,x:Math.max(0,i),y:Math.max(0,o),config:{}};x({...n,nodes:[...n.nodes,s]}),a(s.id),v.current=null},[n,x]),ee=(0,_.useCallback)((e,t)=>{if(e.stopPropagation(),o){o!==t&&n&&(n.edges.some(e=>e.from===o&&e.to===t)||x({...n,edges:[...n.edges,{from:o,to:t}]})),s(null);return}a(t);let r=n?.nodes.find(e=>e.id===t);r&&(g.current={id:t,ox:e.clientX-r.x,oy:e.clientY-r.y})},[o,n,x]),te=(0,_.useCallback)(e=>{if(!g.current||!n)return;let{id:t,ox:i,oy:a}=g.current,o=e.clientX-i,s=e.clientY-a,c=Math.max(0,Math.round(o/20)*20),l=Math.max(0,Math.round(s/20)*20);r(e=>e&&{...e,nodes:e.nodes.map(e=>e.id===t?{...e,x:c,y:l}:e)})},[n]),ne=(0,_.useCallback)(()=>{if(!g.current||!n){g.current=null;return}n.nodes.find(e=>e.id===g.current.id)&&x(n),g.current=null},[n,x]),T=(0,_.useCallback)(e=>{n&&(x({...n,nodes:n.nodes.filter(t=>t.id!==e),edges:n.edges.filter(t=>t.from!==e&&t.to!==e)}),a(null))},[n,x]),re=(0,_.useCallback)((e,t)=>{n&&x({...n,edges:n.edges.filter(n=>!(n.from===e&&n.to===t))})},[n,x]),ie=(0,_.useCallback)((e,i,a)=>{if(!n)return;let o={...n,nodes:n.nodes.map(t=>t.id===e?{...t,config:{...t.config,[i]:a}}:t)};r(o),t(e=>e.map(e=>e.id===o.id?o:e))},[n]),O=(0,_.useCallback)(()=>{n&&x(n)},[n,x]),ae=async()=>{if(!(!n||c)){l(!0),p(!0),d([]);try{let e={...n,nodeDefs:Ct};await D(`/api/workflows/${n.id}`,e,`PUT`).catch(()=>null),d((await D(`/api/workflows/${n.id}/run`,{}))?.steps??[]),b()}catch(e){d([{nodeId:`__error`,nodeLabel:`Error`,nodeIcon:`❌`,output:``,error:e.message}])}finally{l(!1)}}},A=async e=>{let i={...e,enabled:!e.enabled};await D(`/api/workflows/${e.id}`,i,`PUT`).catch(()=>null),t(t=>t.map(t=>t.id===e.id?i:t)),n?.id===e.id&&r(i)},j=n?.nodes.find(e=>e.id===i)??null,oe=j?wt[j.defId]:null;return(0,k.jsxs)(`div`,{className:W.root,children:[(0,k.jsxs)(`div`,{className:W.topbar,children:[(0,k.jsxs)(`div`,{className:W.topbarLeft,children:[(0,k.jsx)(`span`,{className:W.topbarTitle,children:`Connectors`}),(0,k.jsx)(`span`,{className:W.topbarSub,children:`Visual workflow automation · 80 tools · 38 AI agents · free AI via Liara`})]}),(0,k.jsxs)(`div`,{className:W.topbarActions,children:[n&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:`${W.runBtn} ${c?W.runBtnActive:``}`,onClick:ae,disabled:c||n.nodes.length===0,children:c?`⏳ Running…`:`▶ Run`}),(0,k.jsx)(`button`,{className:W.logBtn,onClick:()=>p(e=>!e),children:f?`Hide Log`:`📋 Log`})]}),(0,k.jsx)(`button`,{className:W.newWfBtn,onClick:S,children:`+ New Workflow`})]})]}),(0,k.jsxs)(`div`,{className:W.body,children:[(0,k.jsxs)(`div`,{className:W.sidebar,children:[(0,k.jsx)(`div`,{className:W.sidebarTitle,children:`Workflows`}),e.length===0&&(0,k.jsxs)(`div`,{className:W.sidebarEmpty,children:[`No workflows yet.`,(0,k.jsx)(`br`,{}),`Click "New Workflow" to start.`]}),e.map(e=>(0,k.jsxs)(`div`,{className:`${W.wfItem} ${n?.id===e.id?W.wfItemActive:``}`,onClick:()=>{r(e),a(null),d(e.lastRun?.steps??[]),p(!1)},children:[(0,k.jsxs)(`div`,{className:W.wfItemRow,children:[(0,k.jsx)(`span`,{className:W.wfItemName,children:e.name}),(0,k.jsx)(`button`,{className:e.enabled?W.wfOn:W.wfOff,onClick:t=>{t.stopPropagation(),A(e)},children:e.enabled?`ON`:`OFF`})]}),(0,k.jsxs)(`div`,{className:W.wfItemMeta,children:[e.nodes.length,` nodes · `,e.edges.length,` edges`,e.lastRun&&(0,k.jsxs)(`span`,{children:[` · ran `,new Date(e.lastRun.at).toLocaleTimeString()]})]}),(0,k.jsx)(`button`,{className:W.wfDelBtn,onClick:t=>{t.stopPropagation(),C(e.id)},children:`✕`})]},e.id))]}),(0,k.jsx)(`div`,{className:W.canvasArea,children:n?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:W.canvasHeader,children:[(0,k.jsx)(`input`,{className:W.wfNameInput,value:n.name,onChange:e=>r(t=>t&&{...t,name:e.target.value}),onBlur:()=>n&&x(n)}),o?(0,k.jsxs)(`span`,{className:W.connectHint,children:[`Click a target node to connect · `,(0,k.jsx)(`button`,{className:W.cancelConnectBtn,onClick:()=>s(null),children:`Cancel`})]}):(0,k.jsxs)(`span`,{className:W.canvasHint,children:[`Drag nodes from palette · Click `,(0,k.jsx)(`span`,{className:W.portHint,children:`▶`}),` to connect · Drag nodes to reposition`]})]}),(0,k.jsxs)(`div`,{ref:y,className:`${W.canvas} ${o?W.canvasConnecting:``}`,onMouseMove:te,onMouseUp:ne,onMouseLeave:ne,onDragOver:e=>e.preventDefault(),onDrop:w,onClick:()=>{o||a(null)},children:[(0,k.jsx)(`svg`,{className:W.canvasSvg,children:n.edges.map((e,t)=>{let r=n.nodes.find(t=>t.id===e.from),i=n.nodes.find(t=>t.id===e.to);if(!r||!i)return null;let a=Ot(r,`out`),o=Ot(i,`in`),s=(a.x+o.x)/2;return(0,k.jsxs)(`g`,{children:[(0,k.jsx)(`path`,{d:`M${a.x},${a.y} C${s},${a.y} ${s},${o.y} ${o.x},${o.y}`,stroke:`var(--green3)`,strokeWidth:`2`,fill:`none`,strokeDasharray:`6,3`,opacity:`0.8`}),(0,k.jsx)(`path`,{d:`M${a.x},${a.y} C${s},${a.y} ${s},${o.y} ${o.x},${o.y}`,stroke:`transparent`,strokeWidth:`12`,fill:`none`,style:{cursor:`pointer`},onClick:t=>{t.stopPropagation(),re(e.from,e.to)}}),(0,k.jsx)(`circle`,{cx:s,cy:(a.y+o.y)/2,r:`7`,fill:`var(--bg2)`,stroke:`var(--border)`,strokeWidth:`1.5`,style:{cursor:`pointer`},onClick:t=>{t.stopPropagation(),re(e.from,e.to)}}),(0,k.jsx)(`text`,{x:s,y:(a.y+o.y)/2+4,textAnchor:`middle`,fill:`var(--dim)`,fontSize:`9`,style:{cursor:`pointer`,pointerEvents:`none`},children:`✕`})]},t)})}),n.nodes.map(e=>{let t=wt[e.defId];if(!t)return null;let n=i===e.id,r=o===e.id;return(0,k.jsxs)(`div`,{className:`${W.canvasNode} ${n?W.canvasNodeSelected:``} ${r?W.canvasNodeConnecting:``}`,style:{left:e.x,top:e.y,borderColor:t.color+(n?`ff`:`88`),background:t.color+`18`},onMouseDown:t=>ee(t,e.id),onClick:e=>e.stopPropagation(),children:[(0,k.jsx)(`button`,{className:W.nodeDelBtn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),T(e.id)},children:`✕`}),(0,k.jsx)(`span`,{className:W.nodeIcon,children:t.icon}),(0,k.jsx)(`span`,{className:W.nodeLabel,style:{color:t.color},children:t.label}),Object.values(e.config).filter(Boolean).slice(0,1).map((e,t)=>(0,k.jsx)(`span`,{className:W.nodeConfigPreview,children:String(e).slice(0,14)},t)),(0,k.jsx)(`button`,{className:`${W.portOut} ${r?W.portActive:``}`,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),s(t=>t===e.id?null:e.id)},title:`Connect from here`,children:`▶`}),o&&o!==e.id&&(0,k.jsx)(`button`,{className:W.portIn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),ee(t,e.id)},title:`Connect here`,children:`◀`})]},e.id)}),n.nodes.length===0&&(0,k.jsx)(`div`,{className:W.canvasDrop,children:`Drag nodes from the right panel and drop here`})]}),f&&(0,k.jsxs)(`div`,{className:W.logPanel,children:[(0,k.jsxs)(`div`,{className:W.logHeader,children:[(0,k.jsx)(`span`,{children:`Run Log`}),n.lastRun&&(0,k.jsx)(`span`,{className:W.logTime,children:new Date(n.lastRun.at).toLocaleString()}),(0,k.jsx)(`button`,{className:W.logClose,onClick:()=>p(!1),children:`✕`})]}),u.length===0&&(0,k.jsx)(`div`,{className:W.logEmpty,children:c?`Running…`:`No run results yet.`}),u.map((e,t)=>(0,k.jsxs)(`div`,{className:`${W.logStep} ${e.error?W.logStepError:``}`,children:[(0,k.jsxs)(`div`,{className:W.logStepHeader,children:[(0,k.jsx)(`span`,{className:W.logStepIcon,children:e.nodeIcon}),(0,k.jsx)(`span`,{className:W.logStepLabel,children:e.nodeLabel}),e.error&&(0,k.jsx)(`span`,{className:W.logStepErrBadge,children:`ERROR`})]}),e.error&&(0,k.jsx)(`div`,{className:W.logStepErr,children:e.error}),e.output&&(0,k.jsx)(`div`,{className:W.logStepOutput,dangerouslySetInnerHTML:{__html:fe(e.output.slice(0,500))}})]},t))]})]}):(0,k.jsxs)(`div`,{className:W.canvasEmpty,children:[(0,k.jsx)(`div`,{className:W.canvasEmptyIcon,children:`🔗`}),(0,k.jsx)(`div`,{className:W.canvasEmptyTitle,children:`Select or create a workflow`}),(0,k.jsxs)(`div`,{className:W.canvasEmptyDesc,children:[`Drag nodes from the right panel onto the canvas.`,(0,k.jsx)(`br`,{}),`Connect them by clicking the `,(0,k.jsx)(`span`,{className:W.portHint,children:`▶`}),` output port then the target node.`,(0,k.jsx)(`br`,{}),`Run with one click — all 80 NHA tools already authenticated.`]}),(0,k.jsx)(`button`,{className:W.newWfBtn,onClick:S,children:`+ New Workflow`})]})}),(0,k.jsx)(`div`,{className:W.rightPanel,children:j&&oe?(0,k.jsxs)(`div`,{className:W.configPanel,children:[(0,k.jsxs)(`div`,{className:W.configHeader,children:[(0,k.jsxs)(`span`,{style:{color:oe.color},children:[oe.icon,` `,oe.label]}),(0,k.jsx)(`button`,{className:W.configClose,onClick:()=>a(null),children:`✕`})]}),(0,k.jsx)(`div`,{className:W.configDesc,children:oe.description}),(0,k.jsx)(`div`,{className:W.configFields,children:(oe.configFields??[]).map(e=>(0,k.jsxs)(`div`,{className:W.configField,children:[(0,k.jsxs)(`label`,{className:W.configLabel,children:[e.label,e.required&&(0,k.jsx)(`span`,{className:W.configRequired,children:`*`})]}),(0,k.jsx)(`input`,{className:W.configInput,value:j.config[e.key]??``,placeholder:e.placeholder??``,onChange:t=>ie(j.id,e.key,t.target.value),onBlur:O}),(e.placeholder?.includes(`{{`)??!1)&&(0,k.jsxs)(`div`,{className:W.configHint,children:[`Use `,(0,k.jsx)(`code`,{children:`{{output}}`}),` to pass previous node result`]})]},e.key))}),(0,k.jsx)(`button`,{className:W.configDelete,onClick:()=>T(j.id),children:`Delete node`})]}):(0,k.jsxs)(`div`,{className:W.palette,children:[(0,k.jsx)(`div`,{className:W.paletteTitle,children:`Node Palette`}),(0,k.jsx)(`div`,{className:W.paletteTabs,children:[{id:`trigger`,label:`Triggers`,color:`#fbbf24`},{id:`action`,label:`Actions`,color:`#38bdf8`},{id:`ai`,label:`AI`,color:`#a5b4fc`}].map(e=>(0,k.jsx)(`button`,{className:`${W.paletteTab} ${m===e.id?W.paletteTabActive:``}`,style:m===e.id?{borderColor:e.color,color:e.color}:{},onClick:()=>h(e.id),children:e.label},e.id))}),(0,k.jsx)(`div`,{className:W.paletteNodes,children:Ct.filter(e=>e.type===m).map(e=>(0,k.jsxs)(`div`,{className:W.paletteDef,style:{borderColor:e.color+`44`,background:e.color+`14`},draggable:!0,onDragStart:()=>{v.current=e.id},onDragEnd:()=>{v.current=null},children:[(0,k.jsx)(`span`,{className:W.paletteDefIcon,children:e.icon}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:W.paletteDefLabel,style:{color:e.color},children:e.label}),(0,k.jsx)(`div`,{className:W.paletteDefDesc,children:e.description})]})]},e.id))}),(0,k.jsxs)(`div`,{className:W.paletteGuide,children:[(0,k.jsx)(`div`,{className:W.guideTitle,children:`How to use Connectors`}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`1`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Create`}),` a workflow with "+ New Workflow"`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`2`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Drag`}),` a Trigger node (e.g. Manual, Cron) onto the canvas`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`3`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Drag`}),` Action or AI nodes to chain operations`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`4`}),(0,k.jsxs)(`span`,{children:[`Click the `,(0,k.jsx)(`strong`,{style:{color:`var(--green3)`},children:`▶`}),` port on a node then click the next to `,(0,k.jsx)(`strong`,{children:`connect`}),` them`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`5`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Click`}),` a node to configure it — use `,(0,k.jsx)(`code`,{className:W.guideCode,children:`{{output}}`}),` to pass the previous result`]})]}),(0,k.jsxs)(`div`,{className:W.guideStep,children:[(0,k.jsx)(`span`,{className:W.guideNum,children:`6`}),(0,k.jsxs)(`span`,{children:[`Press `,(0,k.jsx)(`strong`,{children:`▶ Run`}),` to execute · toggle `,(0,k.jsx)(`strong`,{children:`ON`}),` to run automatically (cron/webhook)`]})]}),(0,k.jsxs)(`div`,{className:W.guideTip,children:[(0,k.jsx)(`strong`,{children:`Tip:`}),` Click an edge to delete it. Drag nodes on the canvas to reposition. All 80 NHA tools are pre-authenticated — no extra setup.`]}),(0,k.jsxs)(`div`,{className:W.guideTip,children:[(0,k.jsx)(`strong`,{children:`AI nodes`}),` use Liara (free) by default. They receive `,(0,k.jsx)(`code`,{className:W.guideCode,children:`{{output}}`}),` from the previous step automatically.`]})]})]})})]})]})}var G={root:`_root_1ssbe_1`,sidebar:`_sidebar_1ssbe_12`,sidebarSection:`_sidebarSection_1ssbe_23`,sidebarLabel:`_sidebarLabel_1ssbe_28`,accountSelect:`_accountSelect_1ssbe_36`,sidebarCompose:`_sidebarCompose_1ssbe_46`,composeBtn:`_composeBtn_1ssbe_51`,folderList:`_folderList_1ssbe_63`,folderItem:`_folderItem_1ssbe_69`,folderActive:`_folderActive_1ssbe_82`,badge:`_badge_1ssbe_88`,labelHeader:`_labelHeader_1ssbe_103`,addLabelBtn:`_addLabelBtn_1ssbe_114`,newLabelRow:`_newLabelRow_1ssbe_123`,newLabelInput:`_newLabelInput_1ssbe_129`,newLabelSave:`_newLabelSave_1ssbe_139`,labelDot:`_labelDot_1ssbe_150`,syncArea:`_syncArea_1ssbe_158`,syncBtn:`_syncBtn_1ssbe_163`,messageList:`_messageList_1ssbe_175`,listHeader:`_listHeader_1ssbe_185`,searchInput:`_searchInput_1ssbe_194`,searchBtn:`_searchBtn_1ssbe_204`,listBody:`_listBody_1ssbe_214`,listLoading:`_listLoading_1ssbe_219`,noMessages:`_noMessages_1ssbe_224`,msgRow:`_msgRow_1ssbe_231`,msgUnread:`_msgUnread_1ssbe_242`,msgActive:`_msgActive_1ssbe_247`,msgTop:`_msgTop_1ssbe_251`,msgFrom:`_msgFrom_1ssbe_257`,msgDate:`_msgDate_1ssbe_270`,msgSubject:`_msgSubject_1ssbe_277`,msgPreview:`_msgPreview_1ssbe_289`,listFooter:`_listFooter_1ssbe_300`,loadMoreBtn:`_loadMoreBtn_1ssbe_311`,pane:`_pane_1ssbe_322`,emptyPane:`_emptyPane_1ssbe_330`,readingPane:`_readingPane_1ssbe_337`,paneToolbar:`_paneToolbar_1ssbe_344`,paneActions:`_paneActions_1ssbe_354`,replyBtn:`_replyBtn_1ssbe_360`,fwdBtn:`_fwdBtn_1ssbe_371`,trashBtn:`_trashBtn_1ssbe_371`,starBtn:`_starBtn_1ssbe_371`,aiBtn:`_aiBtn_1ssbe_384`,labelSelect:`_labelSelect_1ssbe_394`,paneHeader:`_paneHeader_1ssbe_403`,paneSubject:`_paneSubject_1ssbe_409`,paneMeta:`_paneMeta_1ssbe_416`,attachments:`_attachments_1ssbe_424`,attachLink:`_attachLink_1ssbe_431`,paneBody:`_paneBody_1ssbe_441`,bodyFrame:`_bodyFrame_1ssbe_447`,bodyText:`_bodyText_1ssbe_455`,composePane:`_composePane_1ssbe_465`,composeTitle:`_composeTitle_1ssbe_474`,composeField:`_composeField_1ssbe_483`,templateRow:`_templateRow_1ssbe_495`,templateToggle:`_templateToggle_1ssbe_500`,templateDrop:`_templateDrop_1ssbe_510`,templateItem:`_templateItem_1ssbe_524`,templateSubject:`_templateSubject_1ssbe_534`,composeBody:`_composeBody_1ssbe_540`,composeActions:`_composeActions_1ssbe_556`,sendBtn:`_sendBtn_1ssbe_563`,cancelBtn:`_cancelBtn_1ssbe_574`,compStatus:`_compStatus_1ssbe_584`,ok:`_ok_1ssbe_585`,err:`_err_1ssbe_586`},At=[{id:`INBOX`,name:`Inbox`,icon:`✉`},{id:`SENT`,name:`Sent`,icon:`→`},{id:`DRAFTS`,name:`Drafts`,icon:`📄`},{id:`SPAM`,name:`Spam`,icon:`🛡`},{id:`TRASH`,name:`Trash`,icon:`🗑`}],jt=[{name:`Product Promo`,subject:`Discover our offer on [PRODUCT]`},{name:`Monthly Newsletter`,subject:`[COMPANY] Newsletter — [MONTH] [YEAR]`},{name:`Commercial Follow-up`,subject:`Following our conversation — [TOPIC]`},{name:`Offer / Quote`,subject:`Offer [NUMBER] — [SUBJECT]`},{name:`Event Invitation`,subject:`You are invited: [EVENT NAME] — [DATE]`},{name:`Customer Thank You`,subject:`Thank you for your trust, [NAME]`}];function Mt(e){return e?e.slice(0,10):``}function Nt(e){if(!e)return``;try{let t=typeof e==`string`?JSON.parse(e):e;return Array.isArray(t)?t.map(e=>e.name?`${e.name} <${e.address}>`:e.address||``).join(`, `):String(e)}catch{return String(e)}}function Pt(){let e=P(),t=ne(e=>e.setView),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(`google`),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(`INBOX`),[m,h]=(0,_.useState)([]),[g,v]=(0,_.useState)(0),[y,b]=(0,_.useState)(0),[x,S]=(0,_.useState)(null),[C,w]=(0,_.useState)(null),[ee,te]=(0,_.useState)(!1),[T,re]=(0,_.useState)(!1),[ie,O]=(0,_.useState)(``),[ae,A]=(0,_.useState)(``),[j,oe]=(0,_.useState)(0),[se,M]=(0,_.useState)(!1),[ce,N]=(0,_.useState)({}),[F,le]=(0,_.useState)(``),[ue,de]=(0,_.useState)(``),[fe,I]=(0,_.useState)(``),[pe,me]=(0,_.useState)(``),[he,ge]=(0,_.useState)(``),[L,_e]=(0,_.useState)(!1),[ve,ye]=(0,_.useState)(``),[R,z]=(0,_.useState)(!1),be=(0,_.useRef)(null);(0,_.useEffect)(()=>{E(`/api/config`).then(e=>r(!!e?.hasGoogle)),E(`/api/imap/accounts`).then(e=>{let t=e?.accounts??[];a(t),t.length>0?xe(t[0].id,`imap`):xe(`google`,`google`)})},[]);let xe=(e,t)=>{s(e),l(t),p(t===`google`?`INBOX`:null),h([]),b(0),S(null),w(null),t===`imap`?E(`/api/imap/labels?accountId=${e}`).then(t=>{let n=t?.labels??[];d(n);let r=n.find(e=>e.system_type===`inbox`)?.id??null;p(r),Se(e,r,0,``)}):(d([]),Ce(`INBOX`,``))},Se=(e,t,n,r)=>{te(!0);let i=`/api/imap/messages?accountId=${encodeURIComponent(e)}&limit=50&offset=${n}`;t&&(i+=`&labelId=${encodeURIComponent(t)}`),r&&(i+=`&search=${encodeURIComponent(r)}`),E(i).then(e=>{h(n===0?e?.messages??[]:t=>[...t,...e?.messages??[]]),v(e?.total??0),te(!1)}).catch(()=>te(!1))},Ce=(e,t)=>{te(!0);let n=e===`INBOX`||!e?`all`:e.toLowerCase(),r=`/api/emails?filter=${encodeURIComponent(t||n)}&page=0&pageSize=50`;t&&(r=`/api/emails?filter=${encodeURIComponent(t)}&page=0&pageSize=50`),E(r).then(e=>{let t=(e?.emails??[]).map(e=>({id:e.id,subject:e.subject,from_name:e.from,from_address:e.from,internal_date:e.date,body_preview:e.snippet,is_read:!e.isUnread,is_starred:!1,has_attachments:!1,_google:!0}));h(t),v(t.length);let n=t.filter(e=>!e.is_read).length;oe(n),te(!1)}).catch(()=>te(!1))},we=()=>{O(ae),b(0),h([]),c===`imap`&&o?Se(o,f,0,ae):Ce(f??`INBOX`,ae)},Te=e=>{S(e),M(!1),re(!0),c===`google`?D(`/api/email/read`,{messageId:e}).then(t=>{w({...t?.message??t,id:e,_google:!0}),re(!1),D(`/api/email/mark-read`,{messageId:e}).catch(()=>{})}).catch(()=>re(!1)):E(`/api/imap/message?id=${encodeURIComponent(e)}`).then(t=>{w(t?.message??null),h(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),re(!1)}).catch(()=>re(!1))},Ee=(e={})=>{M(!0),N(e),le(e.to??``),de(``),I(e.subject??``),me(e.type===`forward`&&e.body?`\n\n---------- Forwarded message ----------\n${e.body}`:``),ge(``),_e(!1),S(null),w(null)},De=async()=>{if(!F.trim()){ge(`Recipient required`);return}ge(`Sending…`);try{if(c===`imap`&&o){let e=await D(`/api/imap/send`,{accountId:o,to:F.trim(),cc:ue.trim()||void 0,subject:fe.trim(),bodyHtml:pe.replace(/\n/g,`<br>`),bodyText:pe,inReplyTo:ce.inReplyTo||void 0});e?.ok?(ge(`Sent!`),setTimeout(()=>M(!1),800)):ge(e?.error??`Error`)}else{let e=await D(`/api/email/send`,{to:F.trim(),subject:fe.trim(),body:pe});e?.ok||e?.id?(ge(`Sent!`),setTimeout(()=>M(!1),800)):ge(e?.error??`Error`)}}catch(e){ge(e.message??`Error`)}},Oe=e=>{confirm(`Move to trash? Email stays on the server.`)&&D(`/api/imap/trash`,{messageId:e}).then(()=>{h(t=>t.filter(t=>t.id!==e)),w(null),S(null)})},B=(e,t)=>{D(`/api/imap/mark-starred`,{messageId:e,isStarred:t}).then(()=>{C?.id===e&&w(e=>e&&{...e,is_starred:t})})},ke=(e,t)=>{t&&D(`/api/imap/labels/assign`,{messageId:e,labelId:t})},Ae=()=>{!ve.trim()||!o||D(`/api/imap/labels`,{accountId:o,name:ve.trim()}).then(()=>{z(!1),ye(``),E(`/api/imap/labels?accountId=${o}`).then(e=>d(e?.labels??[]))})};return(0,k.jsxs)(`div`,{className:G.root,children:[(0,k.jsxs)(`div`,{className:G.sidebar,children:[(0,k.jsxs)(`div`,{className:G.sidebarSection,children:[(0,k.jsx)(`div`,{className:G.sidebarLabel,children:`Account`}),(0,k.jsxs)(`select`,{className:G.accountSelect,value:c===`google`?`google`:`imap:${o}`,onChange:e=>{let t=e.target.value;t===`google`?xe(`google`,`google`):t.startsWith(`imap:`)&&xe(t.slice(5),`imap`)},children:[n&&(0,k.jsx)(`option`,{value:`google`,children:`Google (Gmail)`}),i.map(e=>(0,k.jsx)(`option`,{value:`imap:${e.id}`,children:e.display_name||e.email_address},e.id)),!n&&i.length===0&&(0,k.jsx)(`option`,{value:``,children:`No accounts — add in Settings`})]})]}),(0,k.jsx)(`div`,{className:G.sidebarCompose,children:(0,k.jsx)(`button`,{className:G.composeBtn,onClick:()=>Ee(),children:`+ Compose`})}),(0,k.jsx)(`div`,{className:G.folderList,children:c===`google`?At.map(e=>(0,k.jsxs)(`div`,{className:`${G.folderItem} ${f===e.id?G.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),Ce(e.id,ie)},children:[(0,k.jsx)(`span`,{children:e.icon}),(0,k.jsx)(`span`,{children:e.name}),e.id===`INBOX`&&j>0&&(0,k.jsx)(`span`,{className:G.badge,children:j})]},e.id)):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:G.labelHeader,children:[(0,k.jsx)(`span`,{children:`Labels`}),(0,k.jsx)(`button`,{className:G.addLabelBtn,onClick:()=>z(e=>!e),children:`+`})]}),R&&(0,k.jsxs)(`div`,{className:G.newLabelRow,children:[(0,k.jsx)(`input`,{className:G.newLabelInput,value:ve,onChange:e=>ye(e.target.value),placeholder:`Label name`,onKeyDown:e=>e.key===`Enter`&&Ae()}),(0,k.jsx)(`button`,{className:G.newLabelSave,onClick:Ae,children:`+`})]}),u.map(e=>(0,k.jsxs)(`div`,{className:`${G.folderItem} ${f===e.id?G.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),o&&Se(o,e.id,0,ie)},children:[(0,k.jsx)(`span`,{className:G.labelDot,style:{background:e.color??`var(--dim)`}}),(0,k.jsx)(`span`,{children:e.name}),e.unread_count?(0,k.jsx)(`span`,{className:G.badge,children:e.unread_count}):null]},e.id))]})}),c===`imap`&&o&&(0,k.jsx)(`div`,{className:G.syncArea,children:(0,k.jsx)(`button`,{className:G.syncBtn,onClick:()=>{o&&c===`imap`&&D(`/api/imap/sync/${o}`,{})},children:`Sync now`})})]}),(0,k.jsxs)(`div`,{className:G.messageList,children:[(0,k.jsxs)(`div`,{className:G.listHeader,children:[(0,k.jsx)(`input`,{className:G.searchInput,value:ae,onChange:e=>A(e.target.value),placeholder:`Search…`,onKeyDown:e=>e.key===`Enter`&&we()}),(0,k.jsx)(`button`,{className:G.searchBtn,onClick:we,children:`Go`})]}),(0,k.jsxs)(`div`,{className:G.listBody,children:[ee&&(0,k.jsx)(`div`,{className:G.listLoading,children:(0,k.jsx)(`div`,{className:`spinner`})}),!ee&&m.length===0&&(0,k.jsx)(`div`,{className:G.noMessages,children:`No messages`}),m.map(e=>(0,k.jsxs)(`div`,{className:`${G.msgRow} ${e.id===x?G.msgActive:``} ${e.is_read?``:G.msgUnread}`,onClick:()=>Te(e.id),children:[(0,k.jsxs)(`div`,{className:G.msgTop,children:[(0,k.jsx)(`span`,{className:G.msgFrom,children:e.from_name||e.from_address||``}),(0,k.jsx)(`span`,{className:G.msgDate,children:Mt(e.internal_date)})]}),(0,k.jsx)(`div`,{className:G.msgSubject,children:e.subject||`(no subject)`}),(0,k.jsx)(`div`,{className:G.msgPreview,children:(e.body_preview||``).slice(0,80)})]},e.id))]}),(0,k.jsxs)(`div`,{className:G.listFooter,children:[(0,k.jsxs)(`span`,{children:[g,` messages`]}),m.length<g&&c===`imap`&&(0,k.jsx)(`button`,{className:G.loadMoreBtn,onClick:()=>{let e=y+50;b(e),o&&Se(o,f,e,ie)},children:`Load more`})]})]}),(0,k.jsx)(`div`,{className:G.pane,children:(()=>{if(se)return(0,k.jsxs)(`div`,{className:G.composePane,children:[(0,k.jsx)(`div`,{className:G.composeTitle,children:e(`email.compose`)}),(0,k.jsx)(`input`,{className:G.composeField,value:F,onChange:e=>le(e.target.value),placeholder:`To`}),(0,k.jsx)(`input`,{className:G.composeField,value:ue,onChange:e=>de(e.target.value),placeholder:`Cc`}),(0,k.jsx)(`input`,{className:G.composeField,value:fe,onChange:e=>I(e.target.value),placeholder:`Subject`}),(0,k.jsxs)(`div`,{className:G.templateRow,children:[(0,k.jsx)(`button`,{className:G.templateToggle,onClick:()=>_e(e=>!e),children:`📄 Templates`}),L&&(0,k.jsx)(`div`,{className:G.templateDrop,children:jt.map((e,t)=>(0,k.jsxs)(`div`,{className:G.templateItem,onClick:()=>{I(t=>t||e.subject),_e(!1)},children:[(0,k.jsx)(`strong`,{children:e.name}),(0,k.jsx)(`div`,{className:G.templateSubject,children:e.subject})]},t))})]}),(0,k.jsx)(`textarea`,{className:G.composeBody,value:pe,onChange:e=>me(e.target.value),placeholder:`Write your message…`}),(0,k.jsxs)(`div`,{className:G.composeActions,children:[(0,k.jsx)(`button`,{className:G.sendBtn,onClick:De,children:e(`email.send_ok`)}),(0,k.jsx)(`button`,{className:G.cancelBtn,onClick:()=>M(!1),children:`Discard`}),he&&(0,k.jsx)(`span`,{className:`${G.compStatus} ${he===`Sent!`?G.ok:G.err}`,children:he})]})]});if(T)return(0,k.jsx)(`div`,{className:G.emptyPane,children:(0,k.jsx)(`div`,{className:`spinner`})});if(!C)return(0,k.jsx)(`div`,{className:G.emptyPane,children:`Select a message`});let n=Nt(C.to_addresses);return(0,k.jsxs)(`div`,{className:G.readingPane,children:[(0,k.jsx)(`div`,{className:G.paneToolbar,children:(0,k.jsxs)(`div`,{className:G.paneActions,children:[(0,k.jsx)(`button`,{className:G.replyBtn,onClick:()=>Ee({to:C.from_address,subject:`Re: ${C.subject??``}`,inReplyTo:C.message_id??C.id,replyTo:C.id,type:`reply`}),children:e(`email.reply`)}),(0,k.jsx)(`button`,{className:G.fwdBtn,onClick:()=>Ee({subject:`Fwd: ${C.subject??``}`,type:`forward`,body:C.body_text??C.body_preview??``}),children:`Forward`}),!C._google&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:G.trashBtn,onClick:()=>Oe(C.id),children:`🗑`}),(0,k.jsx)(`button`,{className:G.starBtn,onClick:()=>B(C.id,!C.is_starred),children:C.is_starred?`★`:`☆`}),u.length>0&&(0,k.jsxs)(`select`,{className:G.labelSelect,defaultValue:``,onChange:e=>ke(C.id,e.target.value),children:[(0,k.jsx)(`option`,{value:``,children:`+ Label`}),u.map(e=>(0,k.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,k.jsx)(`button`,{className:G.aiBtn,onClick:()=>t(`chat`),children:`Ask AI`})]})}),(0,k.jsxs)(`div`,{className:G.paneHeader,children:[(0,k.jsx)(`div`,{className:G.paneSubject,children:C.subject||`(no subject)`}),(0,k.jsxs)(`div`,{className:G.paneMeta,children:[(0,k.jsx)(`strong`,{children:`From:`}),` `,C.from_name&&C.from_name!==C.from_address?`${C.from_name} <${C.from_address}>`:C.from_address]}),(0,k.jsxs)(`div`,{className:G.paneMeta,children:[(0,k.jsx)(`strong`,{children:`To:`}),` `,n]}),(0,k.jsxs)(`div`,{className:G.paneMeta,children:[(0,k.jsx)(`strong`,{children:`Date:`}),` `,C.internal_date]}),C.attachments&&C.attachments.length>0&&(0,k.jsx)(`div`,{className:G.attachments,children:C.attachments.map((e,t)=>(0,k.jsxs)(`a`,{className:G.attachLink,href:`/api/imap/attachment?messageId=${encodeURIComponent(C.id)}&partId=${encodeURIComponent(e.part_id??``)}&accountId=${encodeURIComponent(o??``)}`,download:e.filename??`attachment`,children:[`📎 `,e.filename??`attachment`,` (`,Math.round((e.size_bytes??0)/1024),`KB)`]},t))})]}),(0,k.jsx)(`div`,{className:G.paneBody,children:C.body_html?(0,k.jsx)(`iframe`,{ref:be,sandbox:`allow-same-origin`,className:G.bodyFrame,srcDoc:C.body_html,title:`Email body`}):(0,k.jsx)(`pre`,{className:G.bodyText,children:C.body_text??C.body_preview??`(empty)`})})]})})()})]})}var K={root:`_root_1u06k_1`,center:`_center_1u06k_10`,noGoogle:`_noGoogle_1u06k_17`,noGoogleIcon:`_noGoogleIcon_1u06k_26`,noGoogleTitle:`_noGoogleTitle_1u06k_27`,noGoogleSub:`_noGoogleSub_1u06k_28`,connectBtn:`_connectBtn_1u06k_30`,calCol:`_calCol_1u06k_42`,navRow:`_navRow_1u06k_50`,navBtn:`_navBtn_1u06k_57`,monthTitle:`_monthTitle_1u06k_70`,dayHeaders:`_dayHeaders_1u06k_78`,dayHeader:`_dayHeader_1u06k_78`,weekend:`_weekend_1u06k_92`,grid:`_grid_1u06k_94`,cell:`_cell_1u06k_103`,emptyCell:`_emptyCell_1u06k_119`,weekendCell:`_weekendCell_1u06k_121`,todayCell:`_todayCell_1u06k_122`,activeCell:`_activeCell_1u06k_123`,hasEvtsCell:`_hasEvtsCell_1u06k_124`,holidayCell:`_holidayCell_1u06k_125`,dayNum:`_dayNum_1u06k_127`,todayNum:`_todayNum_1u06k_133`,weekendNum:`_weekendNum_1u06k_134`,evtPills:`_evtPills_1u06k_136`,evtPill:`_evtPill_1u06k_136`,holidayPill:`_holidayPill_1u06k_156`,morePill:`_morePill_1u06k_158`,loadingBar:`_loadingBar_1u06k_164`,detailCol:`_detailCol_1u06k_173`,detailHeader:`_detailHeader_1u06k_184`,detailDate:`_detailDate_1u06k_192`,addEvtBtn:`_addEvtBtn_1u06k_198`,noEvts:`_noEvts_1u06k_210`,selectDay:`_selectDay_1u06k_217`,evtCard:`_evtCard_1u06k_224`,evtTop:`_evtTop_1u06k_234`,evtTime:`_evtTime_1u06k_241`,evtBtns:`_evtBtns_1u06k_247`,editBtn:`_editBtn_1u06k_253`,delBtn:`_delBtn_1u06k_263`,readOnly:`_readOnly_1u06k_273`,evtTitle:`_evtTitle_1u06k_280`,evtLoc:`_evtLoc_1u06k_286`,evtMeta:`_evtMeta_1u06k_287`,attendees:`_attendees_1u06k_289`,attendee:`_attendee_1u06k_289`,evtDesc:`_evtDesc_1u06k_300`,joinBtn:`_joinBtn_1u06k_310`,gcalLink:`_gcalLink_1u06k_317`,overlay:`_overlay_1u06k_324`,formCard:`_formCard_1u06k_334`,formTitle:`_formTitle_1u06k_348`,formLabel:`_formLabel_1u06k_355`,formInput:`_formInput_1u06k_361`,formTextarea:`_formTextarea_1u06k_374`,formError:`_formError_1u06k_390`,formBtns:`_formBtns_1u06k_395`,cancelFormBtn:`_cancelFormBtn_1u06k_402`,saveFormBtn:`_saveFormBtn_1u06k_412`};function Ft(e,t,n){return`${e}-${String(t+1).padStart(2,`0`)}-${String(n).padStart(2,`0`)}`}function It(e,t,n){let r=new Date;return r.getFullYear()===e&&r.getMonth()===t&&r.getDate()===n}function Lt(e){if(!e)return``;let t=new Date(e);return isNaN(t.getTime())?e.slice(11,16):t.toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`})}function Rt(){let e=P(),t=ne(e=>e.setView),[n,r]=(0,_.useState)(null),i=new Date,[a,o]=(0,_.useState)(i.getFullYear()),[s,c]=(0,_.useState)(i.getMonth()),[l,u]=(0,_.useState)({}),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(``),[b,x]=(0,_.useState)(!1);(0,_.useEffect)(()=>{E(`/api/config`).then(e=>r(!!e?.hasGoogle))},[]);let S=(0,_.useCallback)((e,t)=>{let n=`${e}-${String(t+1).padStart(2,`0`)}`;f(!0),E(`/api/calendar?month=${n}`).then(e=>{e?.byDate&&u(t=>({...t,...e.byDate})),f(!1)}).catch(()=>f(!1))},[]);(0,_.useEffect)(()=>{n&&S(a,s)},[n,a,s,S]);let C=e=>{E(`/api/calendar?date=${e}`).then(t=>{u(n=>({...n,[e]:t?.events??[]}))})},w=(e,t,n)=>{confirm(`Delete this event?`)&&D(`/api/calendar/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{},`DELETE`).then(()=>C(n))},ee=e=>{g({title:``,start:`${e}T09:00`,end:`${e}T10:00`,location:``,description:``,isEdit:!1}),y(``)},te=(e,t)=>{let n=e.start?e.start.slice(0,16):`${t}T09:00`,r=e.end?e.end.slice(0,16):`${t}T10:00`;g({id:e.id,calId:e.calendarId??`primary`,title:e.summary,start:n,end:r,location:e.location??``,description:e.description??``,isEdit:!0}),y(``)},T=async()=>{if(h){if(!h.title.trim()){y(`Title is required`);return}x(!0);try{if(h.isEdit&&h.id){let e=h.calId??`primary`;await D(`/api/calendar/${encodeURIComponent(e)}/${encodeURIComponent(h.id)}`,{summary:h.title,start:h.start,end:h.end,location:h.location||void 0,description:h.description||void 0},`PATCH`)}else{let e=h.start.split(`T`)[0];await D(`/api/calendar`,{summary:h.title,start:h.start,end:h.end,location:h.location||void 0,description:h.description||void 0,date:e})}let e=h.start.split(`T`)[0];C(e),g(null)}catch(e){y(`Error: `+(e.message??`Unknown`))}finally{x(!1)}}};if(n===null)return(0,k.jsx)(`div`,{className:K.center,children:(0,k.jsx)(`div`,{className:`spinner`})});if(!n)return(0,k.jsx)(`div`,{className:K.center,children:(0,k.jsxs)(`div`,{className:K.noGoogle,children:[(0,k.jsx)(`div`,{className:K.noGoogleIcon,children:`📅`}),(0,k.jsx)(`div`,{className:K.noGoogleTitle,children:`Calendar`}),(0,k.jsx)(`div`,{className:K.noGoogleSub,children:`Connect your Google account to view and manage calendar events.`}),(0,k.jsx)(`button`,{className:K.connectBtn,onClick:()=>t(`settings`),children:`Connect Google →`})]})});let re=new Date(a,s,1).getDay(),ie=new Date(a,s+1,0).getDate(),O=new Date(a,s,1).toLocaleDateString(`en`,{month:`long`,year:`numeric`}),ae=(re+6)%7,A=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],j=p?l[p]??[]:[];return(0,k.jsxs)(`div`,{className:K.root,children:[(0,k.jsxs)(`div`,{className:K.calCol,children:[(0,k.jsxs)(`div`,{className:K.navRow,children:[(0,k.jsx)(`button`,{className:K.navBtn,onClick:()=>{let e=s-1;e<0?(o(e=>e-1),c(11)):c(e)},children:`←`}),(0,k.jsx)(`div`,{className:K.monthTitle,children:O}),(0,k.jsx)(`button`,{className:K.navBtn,onClick:()=>{let e=s+1;e>11?(o(e=>e+1),c(0)):c(e)},children:`→`})]}),(0,k.jsx)(`div`,{className:K.dayHeaders,children:A.map((e,t)=>(0,k.jsx)(`div`,{className:`${K.dayHeader} ${t>=5?K.weekend:``}`,children:e},e))}),(0,k.jsxs)(`div`,{className:K.grid,children:[Array.from({length:ae}).map((e,t)=>(0,k.jsx)(`div`,{className:`${K.cell} ${K.emptyCell} ${t>=5?K.weekendCell:``}`},`e${t}`)),Array.from({length:ie}).map((e,t)=>{let n=t+1,r=Ft(a,s,n),i=It(a,s,n),o=l[r]??[],c=o.length,u=(ae+n-1)%7>=5,d=o.some(e=>e._isHoliday||e.readOnly),f=p===r;return(0,k.jsxs)(`div`,{className:`${K.cell} ${i?K.todayCell:u?K.weekendCell:``} ${f?K.activeCell:``} ${d?K.holidayCell:c>0?K.hasEvtsCell:``}`,onClick:()=>m(r),children:[(0,k.jsx)(`div`,{className:`${K.dayNum} ${i?K.todayNum:u?K.weekendNum:``}`,children:n}),c>0&&(0,k.jsxs)(`div`,{className:K.evtPills,children:[o.slice(0,2).map((e,t)=>(0,k.jsx)(`div`,{className:`${K.evtPill} ${e._isHoliday||e.readOnly?K.holidayPill:``}`,children:e.summary},t)),c>2&&(0,k.jsxs)(`div`,{className:K.morePill,children:[`+`,c-2]})]})]},r)})]}),d&&(0,k.jsx)(`div`,{className:K.loadingBar,children:`Loading events…`})]}),(0,k.jsx)(`div`,{className:K.detailCol,children:p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:K.detailHeader,children:[(0,k.jsx)(`div`,{className:K.detailDate,children:new Date(p+`T12:00:00`).toLocaleDateString(`en`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}),(0,k.jsx)(`button`,{className:K.addEvtBtn,onClick:()=>ee(p),children:`+ Add Event`})]}),j.length===0?(0,k.jsx)(`div`,{className:K.noEvts,children:`No events on this day`}):j.map((t,n)=>{let r=t.isAllDay?`All day`:`${Lt(t.start)} - ${Lt(t.end)}`,i=t.calendarId??`primary`;return(0,k.jsxs)(`div`,{className:K.evtCard,children:[(0,k.jsxs)(`div`,{className:K.evtTop,children:[(0,k.jsx)(`div`,{className:K.evtTime,children:r}),t.id&&!t.readOnly&&(0,k.jsxs)(`div`,{className:K.evtBtns,children:[(0,k.jsx)(`button`,{className:K.editBtn,onClick:()=>te(t,p),children:`Edit`}),(0,k.jsx)(`button`,{className:K.delBtn,onClick:()=>w(i,t.id,p),children:e(`common.delete`)})]}),t.readOnly&&(0,k.jsx)(`span`,{className:K.readOnly,children:`read-only`})]}),(0,k.jsx)(`div`,{className:K.evtTitle,children:t.summary}),t.location&&(0,k.jsxs)(`div`,{className:K.evtLoc,children:[`📍 `,t.location]}),t.organizer&&(0,k.jsxs)(`div`,{className:K.evtMeta,children:[`Organizer: `,t.organizer]}),t.attendees&&t.attendees.length>0&&(0,k.jsxs)(`div`,{className:K.attendees,children:[(0,k.jsx)(`div`,{className:K.evtMeta,children:`Attendees:`}),t.attendees.map((e,t)=>(0,k.jsxs)(`div`,{className:K.attendee,"data-status":e.responseStatus,children:[e.name||e.email,` (`,e.responseStatus,`)`]},t))]}),t.description&&(0,k.jsx)(`div`,{className:K.evtDesc,children:t.description}),t.hangoutLink&&(0,k.jsx)(`a`,{className:K.joinBtn,href:t.hangoutLink,target:`_blank`,rel:`noreferrer`,children:`Join Video Call`}),t.htmlLink&&(0,k.jsx)(`a`,{className:K.gcalLink,href:t.htmlLink,target:`_blank`,rel:`noreferrer`,children:`Open in Google Calendar`})]},n)})]}):(0,k.jsx)(`div`,{className:K.selectDay,children:`Select a day to see events`})}),h&&(0,k.jsx)(`div`,{className:K.overlay,onClick:e=>{e.target===e.currentTarget&&g(null)},children:(0,k.jsxs)(`div`,{className:K.formCard,children:[(0,k.jsx)(`div`,{className:K.formTitle,children:h.isEdit?`Edit Event`:`New Event`}),(0,k.jsx)(`label`,{className:K.formLabel,children:`Title *`}),(0,k.jsx)(`input`,{className:K.formInput,value:h.title,onChange:e=>g(t=>t&&{...t,title:e.target.value}),placeholder:`Event title`}),(0,k.jsx)(`label`,{className:K.formLabel,children:`Start`}),(0,k.jsx)(`input`,{className:K.formInput,type:`datetime-local`,value:h.start,onChange:e=>g(t=>t&&{...t,start:e.target.value})}),(0,k.jsx)(`label`,{className:K.formLabel,children:`End`}),(0,k.jsx)(`input`,{className:K.formInput,type:`datetime-local`,value:h.end,onChange:e=>g(t=>t&&{...t,end:e.target.value})}),(0,k.jsx)(`label`,{className:K.formLabel,children:`Location`}),(0,k.jsx)(`input`,{className:K.formInput,value:h.location,onChange:e=>g(t=>t&&{...t,location:e.target.value}),placeholder:`Optional`}),(0,k.jsx)(`label`,{className:K.formLabel,children:`Description`}),(0,k.jsx)(`textarea`,{className:K.formTextarea,value:h.description,onChange:e=>g(t=>t&&{...t,description:e.target.value})}),v&&(0,k.jsx)(`div`,{className:K.formError,children:v}),(0,k.jsxs)(`div`,{className:K.formBtns,children:[(0,k.jsx)(`button`,{className:K.cancelFormBtn,onClick:()=>g(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:K.saveFormBtn,onClick:T,disabled:b,children:b?`Saving…`:h.isEdit?`Save Changes`:`Create Event`})]})]})})]})}var q={root:`_root_1tngw_1`,gridSection:`_gridSection_1tngw_9`,gridHeader:`_gridHeader_1tngw_14`,headerRow:`_headerRow_1tngw_21`,search:`_search_1tngw_23`,createBtn:`_createBtn_1tngw_34`,catTabs:`_catTabs_1tngw_41`,catTab:`_catTab_1tngw_41`,catActive:`_catActive_1tngw_48`,grid:`_grid_1tngw_9`,agentCard:`_agentCard_1tngw_59`,agentActive:`_agentActive_1tngw_66`,agentCardTop:`_agentCardTop_1tngw_68`,agentIcon:`_agentIcon_1tngw_69`,agentActions:`_agentActions_1tngw_70`,agentEditBtn:`_agentEditBtn_1tngw_71`,agentDelBtn:`_agentDelBtn_1tngw_71`,agentLabel:`_agentLabel_1tngw_74`,agentDesc:`_agentDesc_1tngw_75`,agentCat:`_agentCat_1tngw_76`,loading:`_loading_1tngw_78`,chatArea:`_chatArea_1tngw_81`,emptyChat:`_emptyChat_1tngw_88`,emptyChatHint:`_emptyChatHint_1tngw_98`,chatPanel:`_chatPanel_1tngw_101`,chatHeader:`_chatHeader_1tngw_111`,chatIcon:`_chatIcon_1tngw_118`,chatHeaderInfo:`_chatHeaderInfo_1tngw_119`,chatAgentName:`_chatAgentName_1tngw_120`,chatAgentDesc:`_chatAgentDesc_1tngw_121`,closeChat:`_closeChat_1tngw_122`,chatMessages:`_chatMessages_1tngw_125`,chatEmpty:`_chatEmpty_1tngw_130`,chatMsg:`_chatMsg_1tngw_132`,msgUser:`_msgUser_1tngw_136`,msgAgent:`_msgAgent_1tngw_137`,thinking:`_thinking_1tngw_139`,dot:`_dot_1tngw_140`,dotPulse:`_dotPulse_1tngw_1`,chatInput:`_chatInput_1tngw_146`,chatTools:`_chatTools_1tngw_147`,toolBtn:`_toolBtn_1tngw_148`,toolBtnActive:`_toolBtnActive_1tngw_156`,attachBar:`_attachBar_1tngw_158`,attachClear:`_attachClear_1tngw_163`,chatInputRow:`_chatInputRow_1tngw_165`,chatTextarea:`_chatTextarea_1tngw_166`,sendBtn:`_sendBtn_1tngw_173`,orchBar:`_orchBar_1tngw_181`,orchLabel:`_orchLabel_1tngw_192`,orchRow:`_orchRow_1tngw_193`,orchInput:`_orchInput_1tngw_194`,orchBtn:`_orchBtn_1tngw_201`,orchSynthesis:`_orchSynthesis_1tngw_208`,orchSynthHeader:`_orchSynthHeader_1tngw_214`,orchSynthSpinner:`_orchSynthSpinner_1tngw_220`,blink:`_blink_1tngw_1`,orchSynthBody:`_orchSynthBody_1tngw_222`,modalOverlay:`_modalOverlay_1tngw_230`,modal:`_modal_1tngw_230`,modalTitle:`_modalTitle_1tngw_232`,formField:`_formField_1tngw_233`,formLabel:`_formLabel_1tngw_234`,formInput:`_formInput_1tngw_235`,formTextarea:`_formTextarea_1tngw_236`,formError:`_formError_1tngw_237`,modalBtns:`_modalBtns_1tngw_238`,cancelBtn:`_cancelBtn_1tngw_239`,modalSaveBtn:`_modalSaveBtn_1tngw_240`},zt={saber:{icon:`🛡`},zero:{icon:`🔍`},ade:{icon:`🔬`},heimdall:{icon:`🔒`},cassandra:{icon:`⚠`},sauron:{icon:`👁`},jarvis:{icon:`💻`},forge:{icon:`⚙`},pipe:{icon:`🔧`},shell:{icon:`📟`},glitch:{icon:`🐛`},hermes:{icon:`🔗`},babel:{icon:`🌎`},shogun:{icon:`☸`},flux:{icon:`🔄`},cron:{icon:`⏰`},atlas:{icon:`🗺`},oracle:{icon:`📊`},logos:{icon:`🧮`},navi:{icon:`🧭`},edi:{icon:`📈`},mercury:{icon:`🌐`},tempest:{icon:`⛈`},cartographer:{icon:`🌍`},scheherazade:{icon:`✍`},quill:{icon:`📝`},muse:{icon:`🎨`},murasaki:{icon:`🖌`},echo:{icon:`📡`},polyglot:{icon:`🗣`},prometheus:{icon:`🔥`},herald:{icon:`📢`},veritas:{icon:`✓`},athena:{icon:`🧠`},conductor:{icon:`🎼`},link:{icon:`🔌`},macro:{icon:`⚡`},epicure:{icon:`🍽`}};function Bt(e){let t=e.card??e,n=(t.name||t.displayName||t.agentName||e.name||``).toLowerCase().replace(/\s+/g,`-`),r=zt[n],i=t.displayName||t.agentName||t.name||e.displayName||n,a=t.tagline||t.description||e.tagline||``,o=t.category||e.category||`Other`;return{id:n,icon:r?.icon??t.icon??`🤖`,label:i,description:a,category:o,isCustom:o===`custom`,systemPrompt:e.systemPrompt}}function Vt(e){return{agent:e,history:[],streaming:!1,input:``,attachedFile:null,attachedImage:null,voiceActive:!1}}function Ht(){let e=P(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(`All`),[l,u]=(0,_.useState)([]),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(``),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(`create`),[w,ee]=(0,_.useState)(``),[te,ne]=(0,_.useState)(!1),T=(0,_.useRef)(new Map),re=(0,_.useRef)(new Map),O=(0,_.useRef)(new Map),ae=(0,_.useRef)(new Map),A=(0,_.useRef)(new Map),j=(0,_.useRef)(null),oe=()=>{E(`/api/agents`).then(e=>{n((e?.agents??[]).map(Bt)),i(!1)}).catch(()=>i(!1))};(0,_.useEffect)(()=>{oe()},[]);let se=[`All`,...Array.from(new Set(t.map(e=>e.category))).sort()],M=t.filter(e=>{let t=s===`All`||e.category===s,n=a.toLowerCase();return t&&(!n||e.label.toLowerCase().includes(n)||e.description.toLowerCase().includes(n))}),ce=e=>{u(t=>{let n=t.findIndex(t=>t.agent.id===e.id);return n>=0?(re.current.get(e.id)?.abort(),re.current.delete(e.id),t.filter((e,t)=>t!==n)):[...t,Vt(e)]})},N=e=>{re.current.get(e)?.abort(),re.current.delete(e),u(t=>t.filter(t=>t.agent.id!==e))},F=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,...t}:n))},le=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,history:[...n.history,t]}:n))},ue=(e,t)=>{u(n=>n.map(n=>{if(n.agent.id!==e)return n;let r=[...n.history];return r[r.length-1]={...r[r.length-1],content:t},{...n,history:r}}))},de=async(e,t,n,r)=>{let i=e.agent.id;if(!t.trim()&&!n&&!r)return;le(i,{role:`user`,content:n?(t?t+` `:``)+`[File: ${n.name}]`:r?(t?t+` `:``)+`[Image: ${r.name}]`:t}),F(i,{streaming:!0,input:``,attachedFile:null,attachedImage:null});let a=e.history.slice(-20);if(n||r){try{let e={message:t||`Analyze this`,agent:i};n?.isPDF&&n.base64?(e.pdfBase64=n.base64,e.pdfName=n.name):n?.content&&(e.fileContent=n.content,e.fileName=n.name),r?.base64&&(e.imageBase64=r.base64,e.imageMimeType=r.mimeType??`image/jpeg`);let a=await D(`/api/chat`,e);le(i,{role:`assistant`,content:a?.response||a?.content||``})}catch{le(i,{role:`assistant`,content:`Error sending attachment.`})}F(i,{streaming:!1});return}le(i,{role:`assistant`,content:``,streaming:!0});let o=new AbortController;re.current.set(i,o);let s=``;try{await ie(`/api/chat/stream`,{message:t,agent:i,history:a,_agentSystemPrompt:e.agent.systemPrompt},e=>{s+=e,ue(i,s);let t=O.current.get(i);t&&(t.scrollTop=t.scrollHeight)},o.signal)}catch{}finally{F(i,{streaming:!1}),re.current.delete(i)}},I=async()=>{let e=d.trim();if(!e||p||l.length===0)return;f(``),m(!0),g(``);let t=[];if(await Promise.all(l.map(async n=>{let r=n.agent.id;le(r,{role:`user`,content:e}),F(r,{streaming:!0});let i=``,a=new AbortController;re.current.set(r,a),le(r,{role:`assistant`,content:``,streaming:!0});try{await ie(`/api/chat/stream`,{message:e,agent:r,history:n.history.slice(-20),_agentSystemPrompt:n.agent.systemPrompt},e=>{i+=e,ue(r,i);let t=O.current.get(r);t&&(t.scrollTop=t.scrollHeight)},a.signal)}catch{}finally{F(r,{streaming:!1}),re.current.delete(r)}t.push({agentId:r,agentLabel:n.agent.label,icon:n.agent.icon,content:i})})),m(!1),t.length<2)return;y(!0);let n=t.map(e=>`## ${e.icon} ${e.agentLabel}\n${e.content}`).join(`
462
462
 
463
463
  ---
464
464