nothumanallowed 14.1.11 → 14.1.13

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 _e={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 ve(){let e=M(),[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,ce]=(0,_.useState)([]),[le,ue]=(0,_.useState)(!1),[N,de]=(0,_.useState)(!1),fe=(0,_.useRef)(null),pe=(0,_.useRef)(null),ve=(0,_.useRef)(null);(0,_.useEffect)(()=>{fe.current?.scrollIntoView({behavior:`smooth`})},[a]),(0,_.useEffect)(()=>{E(`/api/config`).then(e=>{e&&(e.thinking===!0||e.thinking===`on`||e.thinking===`true`)&&S(!0)}),F().then(e=>{e&&e.length>0?ye(e[0].id):be()});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(()=>pe.current?.focus(),100))}catch{}},[]);let F=(0,_.useCallback)(async()=>{let e=(await E(`/api/conversations`))?.conversations??[];return n(e),e},[]),ye=(0,_.useCallback)(async e=>{let t=await E(`/api/conversations/${e}`);t?.conversation&&(i(t.conversation.id),o(t.conversation.messages??[]))},[]),be=(0,_.useCallback)(async()=>{let e=await D(`/api/conversations`,{});e?.conversation&&(i(e.conversation.id),o([]),F())},[F]),xe=(0,_.useCallback)(async e=>{let t=ne.getState().apiBase;await fetch(`${t}/api/conversations/${e}`,{method:`DELETE`}),F().then(t=>{e===r&&(t.length>0?ye(t[0].id):be())})},[r,F,ye,be]),I=()=>{r&&window.open(`/api/conversations/${r}/export?format=md`,`_blank`)},L=()=>{let e=!x;S(e),D(`/api/config`,{key:`thinking`,value:e?`on`:`off`}).catch(()=>{})},Se=()=>{c(e=>{let t=!e;return localStorage.setItem(`nha_conv_sidebar`,t?`visible`:`hidden`),t})},Ce=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))},we=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)},Te=()=>{h(null),v(null),y.current&&(y.current.value=``),b.current&&(b.current.value=``)},Ee=m?`[file] ${m.name} (${Math.round(m.size/1024)}KB)`:g?`[img] ${g.name} (${Math.round(g.size/1024)}KB)`:null,De=()=>{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)},Oe=(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),Te(),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}),F()}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}Te(),f(!0),ce([]),ue(!1),de(!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`&&de(!0),t.type===`token`&&typeof t.data.content==`string`){de(!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(ue(i),i)return;r=ge(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=_e[n]??n,a=r===`executing`?`active`:r===`error`?`error`:`done`;ce(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=ge(e))}if(t.type===`tool_synthesis`&&(e=``,n=!0,ue(!1),de(!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`){ue(!1),de(!1),ce(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=ge(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}),F()}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{ue(!1),de(!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(()=>ce([]),2e3)}},[l,a,d,m,g,r,F]),ke=()=>{p.current?.abort(),f(!1)},Ae=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Oe())},je=e=>{navigator.clipboard.writeText(e.replace(/\[CANVAS_RENDER\][\s\S]*?\[\/CANVAS_RENDER\]/g,``).trim()).catch(()=>{})},R=(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`):ge(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=ge((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}),F()}},c.signal)}catch{}finally{f(!1),p.current=null}},[d,a,r,F,e]),Me=e=>{d||(A(e),oe(a[e].content))},Ne=(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`):ge(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=ge((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}),F()}},i.signal)}catch{}finally{f(!1),p.current=null}},[ae,j,a,r,F,e]);return(0,k.jsxs)(`div`,{className:P.root,children:[s&&(0,k.jsxs)(`div`,{className:P.convSidebar,children:[(0,k.jsx)(`div`,{className:P.convSidebarHeader,children:(0,k.jsxs)(`button`,{className:P.newConvBtn,onClick:be,children:[`+ `,e(`chat.newChat`)]})}),(0,k.jsx)(`div`,{className:P.convList,children:t.map(t=>{let n=Math.floor(t.messageCount/2),i=t.id===r;return(0,k.jsxs)(`div`,{className:`${P.convItem} ${i?P.convItemActive:``}`,onClick:()=>ye(t.id),children:[(0,k.jsx)(`div`,{className:P.convTitle,children:t.title||e(`chat.newChat`)}),(0,k.jsxs)(`div`,{className:P.convMeta,children:[(0,k.jsxs)(`span`,{children:[n,` turns`]}),!i&&(0,k.jsx)(`span`,{className:P.convDelete,onClick:e=>{e.stopPropagation(),xe(t.id)},children:`del`})]})]},t.id)})})]}),(0,k.jsxs)(`div`,{className:P.chatMain,children:[(0,k.jsxs)(`div`,{className:P.chatToolbar,children:[(0,k.jsx)(`button`,{className:P.toolbarBtn,onClick:Se,title:`Toggle conversations`,children:`💬 Chats`}),(0,k.jsx)(`span`,{className:P.convTitleBar,children:t.find(e=>e.id===r)?.title||e(`chat.newChat`)}),(0,k.jsx)(`button`,{className:P.toolbarBtn,onClick:be,children:`+ New`}),(0,k.jsx)(`button`,{className:P.toolbarBtnDim,onClick:I,title:`Export Markdown`,children:`Export`}),te&&(0,k.jsx)(`button`,{className:`${P.toolbarBtn} ${P.toolbarBtnCanvas}`,onClick:()=>O(e=>!e),title:`Toggle canvas panel`,children:ie?`▣ Panel ✕`:`▣ Panel`})]}),(0,k.jsxs)(`div`,{className:P.messages,ref:ve,children:[a.length===0&&(0,k.jsxs)(`div`,{className:P.empty,children:[(0,k.jsx)(`div`,{className:P.emptyIcon,children:`💬`}),(0,k.jsx)(`div`,{className:P.emptyTitle,children:`NHA Chat`}),(0,k.jsx)(`div`,{className:P.emptySub,children:`Personal Operations Assistant · 80 Tools · 38 Agents · Free AI`}),(0,k.jsxs)(`div`,{className:P.suggGroups,children:[(0,k.jsxs)(`div`,{className:P.suggGroup,children:[(0,k.jsx)(`div`,{className:P.suggGroupTitle,children:`⚡ Quick Actions`}),(0,k.jsx)(`div`,{className:P.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:P.suggBtn,onClick:()=>u(e),children:e},e))})]}),(0,k.jsxs)(`div`,{className:P.suggGroup,children:[(0,k.jsx)(`div`,{className:P.suggGroupTitle,children:`🌐 Web & Research`}),(0,k.jsx)(`div`,{className:P.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:P.suggBtn,onClick:()=>u(e),children:e},e))})]}),(0,k.jsxs)(`div`,{className:P.suggGroup,children:[(0,k.jsx)(`div`,{className:P.suggGroupTitle,children:`🛠️ Productivity`}),(0,k.jsx)(`div`,{className:P.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:P.suggBtn,onClick:()=>u(e),children:e},e))})]}),(0,k.jsxs)(`div`,{className:P.suggGroup,children:[(0,k.jsx)(`div`,{className:P.suggGroupTitle,children:`📈 Finance`}),(0,k.jsx)(`div`,{className:P.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:P.suggBtn,onClick:()=>u(e),children:e},e))})]})]})]}),a.map((e,t)=>(0,k.jsxs)(`div`,{className:`${P.message} ${P[e.role]}`,children:[(0,k.jsx)(`div`,{className:P.msgLabel,children:e.role===`user`?`You`:`NHA`}),e.role===`assistant`&&e.streaming&&(0,k.jsxs)(`div`,{className:P.toolActivity,children:[(N||e.content===``&&!le&&se.length===0)&&(0,k.jsxs)(`div`,{className:P.thinkingIndicator,children:[(0,k.jsxs)(`div`,{className:P.thinkingDots,children:[(0,k.jsx)(`div`,{className:P.thinkingDot}),(0,k.jsx)(`div`,{className:P.thinkingDot}),(0,k.jsx)(`div`,{className:P.thinkingDot})]}),le?`Deep thinking...`:`Generating...`]}),le&&!N&&(0,k.jsxs)(`div`,{className:P.thinkingIndicator,children:[(0,k.jsxs)(`div`,{className:P.thinkingDots,children:[(0,k.jsx)(`div`,{className:P.thinkingDot}),(0,k.jsx)(`div`,{className:P.thinkingDot}),(0,k.jsx)(`div`,{className:P.thinkingDot})]}),`Deep thinking...`]}),se.map((e,t)=>(0,k.jsxs)(`div`,{className:`${P.toolActivityItem} ${P[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:P.editBox,children:[(0,k.jsx)(`textarea`,{className:P.editInput,value:j,onChange:e=>oe(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Ne()),e.key===`Escape`&&A(null)},autoFocus:!0,rows:3}),(0,k.jsxs)(`div`,{className:P.editActions,children:[(0,k.jsx)(`button`,{className:P.editSaveBtn,onClick:Ne,children:`Send ↵`}),(0,k.jsx)(`button`,{className:P.editCancelBtn,onClick:()=>A(null),children:`Cancel`})]})]}):e.role===`assistant`?e.content!==``&&(0,k.jsx)(`div`,{className:`${P.bubble} ${he.body} ${e.sentinelBlocked?P.sentinelBubble:``}`,dangerouslySetInnerHTML:{__html:me(e.content)}}):(0,k.jsx)(`div`,{className:P.bubble,children:e.content}),e.streaming&&(0,k.jsx)(`span`,{className:P.cursor}),!e.streaming&&ae!==t&&(0,k.jsxs)(`div`,{className:P.msgActions,children:[(0,k.jsx)(`button`,{className:P.msgActionBtn,onClick:()=>je(e.content),children:`Copy`}),e.role===`user`&&!d&&(0,k.jsx)(`button`,{className:P.msgActionBtn,onClick:()=>Me(t),children:`Edit`}),e.role===`assistant`&&!d&&(0,k.jsx)(`button`,{className:P.msgActionBtn,onClick:()=>R(t),children:`Retry`})]})]},t)),(0,k.jsx)(`div`,{ref:fe})]}),Ee&&(0,k.jsxs)(`div`,{className:P.attachBar,children:[(0,k.jsx)(`span`,{children:Ee}),(0,k.jsx)(`button`,{className:P.attachClear,onClick:Te,children:`×`})]}),(0,k.jsxs)(`div`,{className:P.inputBar,children:[(0,k.jsxs)(`div`,{className:P.inputTools,children:[(0,k.jsx)(`button`,{className:`${P.iconBtn} ${C?P.iconBtnActive:``}`,onClick:De,title:`Voice input`,children:`🎤`}),(0,k.jsx)(`button`,{className:P.iconBtn,onClick:()=>y.current?.click(),title:`Attach file`,children:`📎`}),(0,k.jsx)(`button`,{className:P.iconBtn,onClick:()=>b.current?.click(),title:`Attach image`,children:`🖼`}),(0,k.jsx)(`input`,{ref:y,type:`file`,style:{display:`none`},onChange:Ce}),(0,k.jsx)(`input`,{ref:b,type:`file`,accept:`image/*`,style:{display:`none`},onChange:we}),(0,k.jsx)(`span`,{style:{flex:1}}),(0,k.jsxs)(`button`,{className:`${P.thinkBtn} ${x?P.thinkBtnOn:``}`,onClick:L,title:`Extended Thinking`,children:[`Think: `,x?`on`:`off`]}),te&&(0,k.jsx)(`button`,{className:P.toolbarBtn,onClick:()=>O(e=>!e),title:`Canvas panel`,children:`▣ Panel`})]}),(0,k.jsxs)(`div`,{className:P.inputRow,children:[(0,k.jsx)(`textarea`,{ref:pe,className:P.input,value:l,onChange:e=>u(e.target.value),onKeyDown:Ae,placeholder:e(`chat.placeholder`),rows:1,disabled:d}),d?(0,k.jsxs)(`button`,{className:`${P.btn} ${P.stop}`,onClick:ke,children:[`■ `,e(`chat.stopGeneration`)]}):(0,k.jsx)(`button`,{className:`${P.btn} ${P.send}`,onClick:Oe,disabled:!l.trim()&&!m&&!g,children:`Send ↵`})]})]})]}),ie&&te&&(0,k.jsxs)(`div`,{className:P.canvasPanel,children:[(0,k.jsxs)(`div`,{className:P.canvasPanelHeader,children:[(0,k.jsx)(`span`,{children:`Canvas`}),(0,k.jsxs)(`div`,{className:P.canvasPanelActions,children:[(0,k.jsx)(`button`,{className:P.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:P.canvasPanelBtn,onClick:()=>navigator.clipboard.writeText(te).catch(()=>{}),children:`Copy HTML`}),(0,k.jsx)(`button`,{className:P.canvasPanelClose,onClick:()=>O(!1),children:`×`})]})]}),(0,k.jsx)(`iframe`,{className:P.canvasFrame,sandbox:`allow-scripts`,srcDoc:te,title:`Canvas`})]})]})}var F={root:`_root_5xh8v_1`,header:`_header_5xh8v_8`,headerLeft:`_headerLeft_5xh8v_18`,title:`_title_5xh8v_20`,subtitle:`_subtitle_5xh8v_27`,headerActions:`_headerActions_5xh8v_33`,tokenBar:`_tokenBar_5xh8v_40`,tokIn:`_tokIn_5xh8v_48`,tokOut:`_tokOut_5xh8v_49`,tokTotal:`_tokTotal_5xh8v_50`,tokDim:`_tokDim_5xh8v_51`,sessionsBtn:`_sessionsBtn_5xh8v_53`,pdfBtn:`_pdfBtn_5xh8v_65`,clearBtn:`_clearBtn_5xh8v_75`,sessionsDrawer:`_sessionsDrawer_5xh8v_88`,noSessions:`_noSessions_5xh8v_96`,sessionItem:`_sessionItem_5xh8v_103`,sessionInfo:`_sessionInfo_5xh8v_113`,sessionTask:`_sessionTask_5xh8v_119`,sessionMeta:`_sessionMeta_5xh8v_129`,sessionBtns:`_sessionBtns_5xh8v_135`,importBtn:`_importBtn_5xh8v_141`,delSessionBtn:`_delSessionBtn_5xh8v_151`,inputArea:`_inputArea_5xh8v_162`,inputRow:`_inputRow_5xh8v_171`,taskInput:`_taskInput_5xh8v_177`,inputControls:`_inputControls_5xh8v_192`,runBtn:`_runBtn_5xh8v_198`,stopBtn:`_stopBtn_5xh8v_211`,attachBtn:`_attachBtn_5xh8v_222`,attachBadge:`_attachBadge_5xh8v_235`,clearAttach:`_clearAttach_5xh8v_248`,examples:`_examples_5xh8v_257`,exampleBtn:`_exampleBtn_5xh8v_263`,body:`_body_5xh8v_281`,agentChip:`_agentChip_5xh8v_294`,chip_running:`_chip_running_5xh8v_305`,charCardPulse:`_charCardPulse_5xh8v_1`,chip_done:`_chip_done_5xh8v_311`,chip_error:`_chip_error_5xh8v_312`,chip_waiting:`_chip_waiting_5xh8v_313`,chipIcon:`_chipIcon_5xh8v_314`,chipLabel:`_chipLabel_5xh8v_315`,chipDots:`_chipDots_5xh8v_316`,chipCheck:`_chipCheck_5xh8v_317`,chipErr:`_chipErr_5xh8v_318`,officeSceneWrap:`_officeSceneWrap_5xh8v_321`,pipeline:`_pipeline_5xh8v_331`,pipelineRunning:`_pipelineRunning_5xh8v_344`,scanSweep:`_scanSweep_5xh8v_1`,pipelineTitle:`_pipelineTitle_5xh8v_366`,pipelineNodes:`_pipelineNodes_5xh8v_374`,pipelineStep:`_pipelineStep_5xh8v_381`,arrow:`_arrow_5xh8v_387`,arrowActive:`_arrowActive_5xh8v_396`,arrowPulse:`_arrowPulse_5xh8v_1`,agentChar:`_agentChar_5xh8v_408`,charWaiting:`_charWaiting_5xh8v_423`,charActive:`_charActive_5xh8v_428`,charDone:`_charDone_5xh8v_436`,charError:`_charError_5xh8v_441`,orbitRing1:`_orbitRing1_5xh8v_452`,orbitRing2:`_orbitRing2_5xh8v_453`,orbitSpin1:`_orbitSpin1_5xh8v_1`,orbitSpin2:`_orbitSpin2_5xh8v_1`,charAvatar:`_charAvatar_5xh8v_499`,charIcon:`_charIcon_5xh8v_514`,iconBob:`_iconBob_5xh8v_1`,charCheck:`_charCheck_5xh8v_531`,badgePop:`_badgePop_5xh8v_1`,charErr:`_charErr_5xh8v_441`,charPulse:`_charPulse_5xh8v_575`,charPulse2:`_charPulse2_5xh8v_576`,expandRing:`_expandRing_5xh8v_1`,charLabel:`_charLabel_5xh8v_595`,charStatus:`_charStatus_5xh8v_607`,charStatusDots:`_charStatusDots_5xh8v_620`,dot1:`_dot1_5xh8v_621`,dot2:`_dot2_5xh8v_621`,dot3:`_dot3_5xh8v_621`,dotFade:`_dotFade_5xh8v_1`,twoCol:`_twoCol_5xh8v_635`,panelTitle:`_panelTitle_5xh8v_642`,logPanel:`_logPanel_5xh8v_652`,logBody:`_logBody_5xh8v_664`,logEntry:`_logEntry_5xh8v_672`,logTime:`_logTime_5xh8v_682`,logIcon:`_logIcon_5xh8v_683`,logAgent:`_logAgent_5xh8v_684`,logText:`_logText_5xh8v_685`,log_system:`_log_system_5xh8v_687`,log_error:`_log_error_5xh8v_688`,liveOutputPanel:`_liveOutputPanel_5xh8v_691`,liveBlock:`_liveBlock_5xh8v_697`,blockSlideIn:`_blockSlideIn_5xh8v_1`,liveBlockActive:`_liveBlockActive_5xh8v_711`,liveBlockPulse:`_liveBlockPulse_5xh8v_1`,liveBlockScan:`_liveBlockScan_5xh8v_1`,liveBlockHeader:`_liveBlockHeader_5xh8v_740`,liveBlockIcon:`_liveBlockIcon_5xh8v_749`,liveBlockLabel:`_liveBlockLabel_5xh8v_751`,outputStatus:`_outputStatus_5xh8v_759`,status_done:`_status_done_5xh8v_770`,status_running:`_status_running_5xh8v_771`,status_error:`_status_error_5xh8v_772`,status_waiting:`_status_waiting_5xh8v_773`,liveBlockBody:`_liveBlockBody_5xh8v_776`,liveBlockWorking:`_liveBlockWorking_5xh8v_914`,workingDot:`_workingDot_5xh8v_921`,workingBounce:`_workingBounce_5xh8v_1`,workingLabel:`_workingLabel_5xh8v_938`,workingFade:`_workingFade_5xh8v_1`,studioBlinkCursor:`_studioBlinkCursor_5xh8v_1`,resultAccordion:`_resultAccordion_5xh8v_967`,resultAccordionSummary:`_resultAccordionSummary_5xh8v_974`,resultAccordionBody:`_resultAccordionBody_5xh8v_991`,financeSection:`_financeSection_5xh8v_1025`,financeSectionTitle:`_financeSectionTitle_5xh8v_1033`,financePresets:`_financePresets_5xh8v_1042`,financeBtn:`_financeBtn_5xh8v_1048`,canvasToggleBtn:`_canvasToggleBtn_5xh8v_1066`,canvasPanel:`_canvasPanel_5xh8v_1082`,canvasPanelHeader:`_canvasPanelHeader_5xh8v_1097`,canvasPanelActions:`_canvasPanelActions_5xh8v_1109`,canvasPanelBtn:`_canvasPanelBtn_5xh8v_1115`,canvasPanelClose:`_canvasPanelClose_5xh8v_1127`,canvasFrame:`_canvasFrame_5xh8v_1138`,pipelineLiveTag:`_pipelineLiveTag_5xh8v_1146`,liveTagBlink:`_liveTagBlink_5xh8v_1`,reasonRow:`_reasonRow_5xh8v_1160`,reasonChip:`_reasonChip_5xh8v_1169`,reasonIcon:`_reasonIcon_5xh8v_1182`,reasonText:`_reasonText_5xh8v_1183`,liveBlockReason:`_liveBlockReason_5xh8v_1186`,councilWrapper:`_councilWrapper_5xh8v_1196`,councilPanel:`_councilPanel_5xh8v_1201`,councilHeader:`_councilHeader_5xh8v_1209`,councilHeaderLeft:`_councilHeaderLeft_5xh8v_1220`,councilHeaderRight:`_councilHeaderRight_5xh8v_1226`,councilIcon:`_councilIcon_5xh8v_1232`,councilTitle:`_councilTitle_5xh8v_1234`,councilConvergedBadge:`_councilConvergedBadge_5xh8v_1243`,councilDivergedBadge:`_councilDivergedBadge_5xh8v_1255`,councilPhaseTag:`_councilPhaseTag_5xh8v_1267`,councilPhaseActive:`_councilPhaseActive_5xh8v_1273`,phaseGlow:`_phaseGlow_5xh8v_1`,councilPhaseDone:`_councilPhaseDone_5xh8v_1282`,councilMetrics:`_councilMetrics_5xh8v_1285`,convRow:`_convRow_5xh8v_1293`,convLabel:`_convLabel_5xh8v_1299`,convTrack:`_convTrack_5xh8v_1307`,convFill:`_convFill_5xh8v_1315`,convPct:`_convPct_5xh8v_1321`,councilNodes:`_councilNodes_5xh8v_1331`,councilSectionTitle:`_councilSectionTitle_5xh8v_1336`,councilNode:`_councilNode_5xh8v_1331`,councilNodeHeader:`_councilNodeHeader_5xh8v_1353`,councilNodeIcon:`_councilNodeIcon_5xh8v_1366`,councilNodeLabel:`_councilNodeLabel_5xh8v_1367`,councilNodeToggle:`_councilNodeToggle_5xh8v_1368`,councilNodeBody:`_councilNodeBody_5xh8v_1370`,councilSynthesis:`_councilSynthesis_5xh8v_1380`,councilSynthesisHeader:`_councilSynthesisHeader_5xh8v_1384`,heraldIcon:`_heraldIcon_5xh8v_1393`,heraldLabel:`_heraldLabel_5xh8v_1395`,heraldStreaming:`_heraldStreaming_5xh8v_1403`,councilSynthesisBody:`_councilSynthesisBody_5xh8v_1405`,councilSkipped:`_councilSkipped_5xh8v_1435`,councilSkipIcon:`_councilSkipIcon_5xh8v_1446`,charSpriteRunning:`_charSpriteRunning_5xh8v_1459`,spriteWalk:`_spriteWalk_5xh8v_1`,charSpriteDone:`_charSpriteDone_5xh8v_1468`,charScanline:`_charScanline_5xh8v_1472`,scanlineScroll:`_scanlineScroll_5xh8v_1`,auraAnim:`_auraAnim_5xh8v_1492`,auraGlow:`_auraGlow_5xh8v_1`,parliamentPrompt:`_parliamentPrompt_5xh8v_1499`,parliamentPromptIcon:`_parliamentPromptIcon_5xh8v_1509`,parliamentPromptContent:`_parliamentPromptContent_5xh8v_1510`,parliamentPromptTitle:`_parliamentPromptTitle_5xh8v_1511`,parliamentPromptDesc:`_parliamentPromptDesc_5xh8v_1512`,parliamentPromptMeta:`_parliamentPromptMeta_5xh8v_1513`,parliamentPromptBtns:`_parliamentPromptBtns_5xh8v_1514`,parliamentActivateBtn:`_parliamentActivateBtn_5xh8v_1515`,parliamentSkipBtn:`_parliamentSkipBtn_5xh8v_1522`,panelTabs:`_panelTabs_5xh8v_1530`,panelTabBtn:`_panelTabBtn_5xh8v_1531`,panelTabActive:`_panelTabActive_5xh8v_1538`,panelEmpty:`_panelEmpty_5xh8v_1540`,browserPanel:`_browserPanel_5xh8v_1549`,browserBar:`_browserBar_5xh8v_1550`,browserInput:`_browserInput_5xh8v_1551`,browserGo:`_browserGo_5xh8v_1558`,liveBlockClickable:`_liveBlockClickable_5xh8v_1565`,liveBlockBodyClamped:`_liveBlockBodyClamped_5xh8v_1574`,expandHint:`_expandHint_5xh8v_1581`,blockModalOverlay:`_blockModalOverlay_5xh8v_1590`,blockModal:`_blockModal_5xh8v_1590`,blockModalHeader:`_blockModalHeader_5xh8v_1615`,blockModalTitle:`_blockModalTitle_5xh8v_1625`,blockModalClose:`_blockModalClose_5xh8v_1633`,blockModalBody:`_blockModalBody_5xh8v_1645`},ye=[{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=ge(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}),F()}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{ue(!1),de(!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(()=>ce([]),2e3)}},[l,a,d,m,g,r,F]),ke=()=>{p.current?.abort(),f(!1)},Ae=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Oe())},je=e=>{navigator.clipboard.writeText(e.replace(/\[CANVAS_RENDER\][\s\S]*?\[\/CANVAS_RENDER\]/g,``).trim()).catch(()=>{})},R=(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`):ge(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=ge((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}),F()}},c.signal)}catch{}finally{f(!1),p.current=null}},[d,a,r,F,e]),Me=e=>{d||(A(e),oe(a[e].content))},Ne=(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`):ge(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=ge((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}),F()}},i.signal)}catch{}finally{f(!1),p.current=null}},[ae,j,a,r,F,e]);return(0,k.jsxs)(`div`,{className:P.root,children:[s&&(0,k.jsxs)(`div`,{className:P.convSidebar,children:[(0,k.jsx)(`div`,{className:P.convSidebarHeader,children:(0,k.jsxs)(`button`,{className:P.newConvBtn,onClick:be,children:[`+ `,e(`chat.newChat`)]})}),(0,k.jsx)(`div`,{className:P.convList,children:t.map(t=>{let n=Math.floor(t.messageCount/2),i=t.id===r;return(0,k.jsxs)(`div`,{className:`${P.convItem} ${i?P.convItemActive:``}`,onClick:()=>ye(t.id),children:[(0,k.jsx)(`div`,{className:P.convTitle,children:t.title||e(`chat.newChat`)}),(0,k.jsxs)(`div`,{className:P.convMeta,children:[(0,k.jsxs)(`span`,{children:[n,` turns`]}),!i&&(0,k.jsx)(`span`,{className:P.convDelete,onClick:e=>{e.stopPropagation(),xe(t.id)},children:`del`})]})]},t.id)})})]}),(0,k.jsxs)(`div`,{className:P.chatMain,children:[(0,k.jsxs)(`div`,{className:P.chatToolbar,children:[(0,k.jsx)(`button`,{className:P.toolbarBtn,onClick:Se,title:`Toggle conversations`,children:`💬 Chats`}),(0,k.jsx)(`span`,{className:P.convTitleBar,children:t.find(e=>e.id===r)?.title||e(`chat.newChat`)}),(0,k.jsx)(`button`,{className:P.toolbarBtn,onClick:be,children:`+ New`}),(0,k.jsx)(`button`,{className:P.toolbarBtnDim,onClick:I,title:`Export Markdown`,children:`Export`}),te&&(0,k.jsx)(`button`,{className:`${P.toolbarBtn} ${P.toolbarBtnCanvas}`,onClick:()=>O(e=>!e),title:`Toggle canvas panel`,children:ie?`▣ Panel ✕`:`▣ Panel`})]}),(0,k.jsxs)(`div`,{className:P.messages,ref:ve,children:[a.length===0&&(0,k.jsxs)(`div`,{className:P.empty,children:[(0,k.jsx)(`div`,{className:P.emptyIcon,children:`💬`}),(0,k.jsx)(`div`,{className:P.emptyTitle,children:`NHA Chat`}),(0,k.jsx)(`div`,{className:P.emptySub,children:`Personal Operations Assistant · 80 Tools · 38 Agents · Free AI`}),(0,k.jsxs)(`div`,{className:P.suggGroups,children:[(0,k.jsxs)(`div`,{className:P.suggGroup,children:[(0,k.jsx)(`div`,{className:P.suggGroupTitle,children:`⚡ Quick Actions`}),(0,k.jsx)(`div`,{className:P.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:P.suggBtn,onClick:()=>u(e),children:e},e))})]}),(0,k.jsxs)(`div`,{className:P.suggGroup,children:[(0,k.jsx)(`div`,{className:P.suggGroupTitle,children:`🌐 Web & Research`}),(0,k.jsx)(`div`,{className:P.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:P.suggBtn,onClick:()=>u(e),children:e},e))})]}),(0,k.jsxs)(`div`,{className:P.suggGroup,children:[(0,k.jsx)(`div`,{className:P.suggGroupTitle,children:`🛠️ Productivity`}),(0,k.jsx)(`div`,{className:P.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:P.suggBtn,onClick:()=>u(e),children:e},e))})]}),(0,k.jsxs)(`div`,{className:P.suggGroup,children:[(0,k.jsx)(`div`,{className:P.suggGroupTitle,children:`📈 Finance`}),(0,k.jsx)(`div`,{className:P.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:P.suggBtn,onClick:()=>u(e),children:e},e))})]})]})]}),a.map((e,t)=>(0,k.jsxs)(`div`,{className:`${P.message} ${P[e.role]}`,children:[(0,k.jsx)(`div`,{className:P.msgLabel,children:e.role===`user`?`You`:`NHA`}),e.role===`assistant`&&e.streaming&&(0,k.jsxs)(`div`,{className:P.toolActivity,children:[(N||e.content===``&&!le&&se.length===0)&&(0,k.jsxs)(`div`,{className:P.thinkingIndicator,children:[(0,k.jsxs)(`div`,{className:P.thinkingDots,children:[(0,k.jsx)(`div`,{className:P.thinkingDot}),(0,k.jsx)(`div`,{className:P.thinkingDot}),(0,k.jsx)(`div`,{className:P.thinkingDot})]}),le?`Deep thinking...`:`Generating...`]}),le&&!N&&(0,k.jsxs)(`div`,{className:P.thinkingIndicator,children:[(0,k.jsxs)(`div`,{className:P.thinkingDots,children:[(0,k.jsx)(`div`,{className:P.thinkingDot}),(0,k.jsx)(`div`,{className:P.thinkingDot}),(0,k.jsx)(`div`,{className:P.thinkingDot})]}),`Deep thinking...`]}),se.map((e,t)=>(0,k.jsxs)(`div`,{className:`${P.toolActivityItem} ${P[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:P.editBox,children:[(0,k.jsx)(`textarea`,{className:P.editInput,value:j,onChange:e=>oe(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Ne()),e.key===`Escape`&&A(null)},autoFocus:!0,rows:3}),(0,k.jsxs)(`div`,{className:P.editActions,children:[(0,k.jsx)(`button`,{className:P.editSaveBtn,onClick:Ne,children:`Send ↵`}),(0,k.jsx)(`button`,{className:P.editCancelBtn,onClick:()=>A(null),children:`Cancel`})]})]}):e.role===`assistant`?e.content!==``&&(0,k.jsx)(`div`,{className:`${P.bubble} ${he.body} ${e.sentinelBlocked?P.sentinelBubble:``}`,dangerouslySetInnerHTML:{__html:me(e.content)}}):(0,k.jsx)(`div`,{className:P.bubble,children:e.content}),e.streaming&&(0,k.jsx)(`span`,{className:P.cursor}),!e.streaming&&ae!==t&&(0,k.jsxs)(`div`,{className:P.msgActions,children:[(0,k.jsx)(`button`,{className:P.msgActionBtn,onClick:()=>je(e.content),children:`Copy`}),e.role===`user`&&!d&&(0,k.jsx)(`button`,{className:P.msgActionBtn,onClick:()=>Me(t),children:`Edit`}),e.role===`assistant`&&!d&&(0,k.jsx)(`button`,{className:P.msgActionBtn,onClick:()=>R(t),children:`Retry`})]})]},t)),(0,k.jsx)(`div`,{ref:fe})]}),Ee&&(0,k.jsxs)(`div`,{className:P.attachBar,children:[(0,k.jsx)(`span`,{children:Ee}),(0,k.jsx)(`button`,{className:P.attachClear,onClick:Te,children:`×`})]}),(0,k.jsxs)(`div`,{className:P.inputBar,children:[(0,k.jsxs)(`div`,{className:P.inputTools,children:[(0,k.jsx)(`button`,{className:`${P.iconBtn} ${C?P.iconBtnActive:``}`,onClick:De,title:`Voice input`,children:`🎤`}),(0,k.jsx)(`button`,{className:P.iconBtn,onClick:()=>y.current?.click(),title:`Attach file`,children:`📎`}),(0,k.jsx)(`button`,{className:P.iconBtn,onClick:()=>b.current?.click(),title:`Attach image`,children:`🖼`}),(0,k.jsx)(`input`,{ref:y,type:`file`,style:{display:`none`},onChange:Ce}),(0,k.jsx)(`input`,{ref:b,type:`file`,accept:`image/*`,style:{display:`none`},onChange:we}),(0,k.jsx)(`span`,{style:{flex:1}}),(0,k.jsxs)(`button`,{className:`${P.thinkBtn} ${x?P.thinkBtnOn:``}`,onClick:L,title:`Extended Thinking`,children:[`Think: `,x?`on`:`off`]}),te&&(0,k.jsx)(`button`,{className:P.toolbarBtn,onClick:()=>O(e=>!e),title:`Canvas panel`,children:`▣ Panel`})]}),(0,k.jsxs)(`div`,{className:P.inputRow,children:[(0,k.jsx)(`textarea`,{ref:pe,className:P.input,value:l,onChange:e=>u(e.target.value),onKeyDown:Ae,placeholder:e(`chat.placeholder`),rows:1,disabled:d}),d?(0,k.jsxs)(`button`,{className:`${P.btn} ${P.stop}`,onClick:ke,children:[`■ `,e(`chat.stopGeneration`)]}):(0,k.jsx)(`button`,{className:`${P.btn} ${P.send}`,onClick:Oe,disabled:!l.trim()&&!m&&!g,children:`Send ↵`})]})]})]}),ie&&te&&(0,k.jsxs)(`div`,{className:P.canvasPanel,children:[(0,k.jsxs)(`div`,{className:P.canvasPanelHeader,children:[(0,k.jsx)(`span`,{children:`Canvas`}),(0,k.jsxs)(`div`,{className:P.canvasPanelActions,children:[(0,k.jsx)(`button`,{className:P.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:P.canvasPanelBtn,onClick:()=>navigator.clipboard.writeText(te).catch(()=>{}),children:`Copy HTML`}),(0,k.jsx)(`button`,{className:P.canvasPanelClose,onClick:()=>O(!1),children:`×`})]})]}),(0,k.jsx)(`iframe`,{className:P.canvasFrame,sandbox:`allow-scripts`,srcDoc:te,title:`Canvas`})]})]})}var F={root:`_root_hrpqm_1`,header:`_header_hrpqm_8`,headerLeft:`_headerLeft_hrpqm_19`,title:`_title_hrpqm_21`,subtitle:`_subtitle_hrpqm_28`,headerActions:`_headerActions_hrpqm_34`,tokenBar:`_tokenBar_hrpqm_41`,tokIn:`_tokIn_hrpqm_49`,tokOut:`_tokOut_hrpqm_50`,tokTotal:`_tokTotal_hrpqm_51`,tokDim:`_tokDim_hrpqm_52`,sessionsBtn:`_sessionsBtn_hrpqm_54`,pdfBtn:`_pdfBtn_hrpqm_66`,clearBtn:`_clearBtn_hrpqm_76`,sessionsDrawer:`_sessionsDrawer_hrpqm_89`,noSessions:`_noSessions_hrpqm_104`,sessionItem:`_sessionItem_hrpqm_111`,sessionInfo:`_sessionInfo_hrpqm_121`,sessionTask:`_sessionTask_hrpqm_127`,sessionMeta:`_sessionMeta_hrpqm_137`,sessionBtns:`_sessionBtns_hrpqm_143`,importBtn:`_importBtn_hrpqm_149`,delSessionBtn:`_delSessionBtn_hrpqm_159`,inputArea:`_inputArea_hrpqm_170`,inputRow:`_inputRow_hrpqm_179`,taskInput:`_taskInput_hrpqm_185`,inputControls:`_inputControls_hrpqm_200`,runBtn:`_runBtn_hrpqm_206`,stopBtn:`_stopBtn_hrpqm_219`,attachBtn:`_attachBtn_hrpqm_230`,attachBadge:`_attachBadge_hrpqm_243`,clearAttach:`_clearAttach_hrpqm_256`,examples:`_examples_hrpqm_265`,exampleBtn:`_exampleBtn_hrpqm_271`,body:`_body_hrpqm_289`,agentChip:`_agentChip_hrpqm_302`,chip_running:`_chip_running_hrpqm_313`,charCardPulse:`_charCardPulse_hrpqm_1`,chip_done:`_chip_done_hrpqm_319`,chip_error:`_chip_error_hrpqm_320`,chip_waiting:`_chip_waiting_hrpqm_321`,chipIcon:`_chipIcon_hrpqm_322`,chipLabel:`_chipLabel_hrpqm_323`,chipDots:`_chipDots_hrpqm_324`,chipCheck:`_chipCheck_hrpqm_325`,chipErr:`_chipErr_hrpqm_326`,officeSceneWrap:`_officeSceneWrap_hrpqm_329`,pipeline:`_pipeline_hrpqm_339`,pipelineWrap:`_pipelineWrap_hrpqm_354`,pipelineRunning:`_pipelineRunning_hrpqm_364`,scanSweep:`_scanSweep_hrpqm_1`,pipelineTitle:`_pipelineTitle_hrpqm_387`,pipelineNodes:`_pipelineNodes_hrpqm_395`,pipelineStep:`_pipelineStep_hrpqm_402`,arrow:`_arrow_hrpqm_408`,arrowActive:`_arrowActive_hrpqm_417`,arrowPulse:`_arrowPulse_hrpqm_1`,agentChar:`_agentChar_hrpqm_429`,charWaiting:`_charWaiting_hrpqm_444`,charActive:`_charActive_hrpqm_449`,charDone:`_charDone_hrpqm_457`,charError:`_charError_hrpqm_462`,orbitRing1:`_orbitRing1_hrpqm_473`,orbitRing2:`_orbitRing2_hrpqm_474`,orbitSpin1:`_orbitSpin1_hrpqm_1`,orbitSpin2:`_orbitSpin2_hrpqm_1`,charAvatar:`_charAvatar_hrpqm_520`,charIcon:`_charIcon_hrpqm_535`,iconBob:`_iconBob_hrpqm_1`,charCheck:`_charCheck_hrpqm_552`,badgePop:`_badgePop_hrpqm_1`,charErr:`_charErr_hrpqm_462`,charPulse:`_charPulse_hrpqm_596`,charPulse2:`_charPulse2_hrpqm_597`,expandRing:`_expandRing_hrpqm_1`,charLabel:`_charLabel_hrpqm_616`,charStatus:`_charStatus_hrpqm_628`,charStatusDots:`_charStatusDots_hrpqm_641`,dot1:`_dot1_hrpqm_642`,dot2:`_dot2_hrpqm_642`,dot3:`_dot3_hrpqm_642`,dotFade:`_dotFade_hrpqm_1`,twoCol:`_twoCol_hrpqm_656`,panelTitle:`_panelTitle_hrpqm_663`,logPanel:`_logPanel_hrpqm_673`,logBody:`_logBody_hrpqm_685`,logEntry:`_logEntry_hrpqm_693`,logTime:`_logTime_hrpqm_703`,logIcon:`_logIcon_hrpqm_704`,logAgent:`_logAgent_hrpqm_705`,logText:`_logText_hrpqm_706`,log_system:`_log_system_hrpqm_708`,log_error:`_log_error_hrpqm_709`,liveOutputPanel:`_liveOutputPanel_hrpqm_712`,liveBlock:`_liveBlock_hrpqm_719`,blockSlideIn:`_blockSlideIn_hrpqm_1`,liveBlockActive:`_liveBlockActive_hrpqm_733`,liveBlockPulse:`_liveBlockPulse_hrpqm_1`,liveBlockScan:`_liveBlockScan_hrpqm_1`,liveBlockHeader:`_liveBlockHeader_hrpqm_762`,liveBlockIcon:`_liveBlockIcon_hrpqm_771`,liveBlockLabel:`_liveBlockLabel_hrpqm_773`,outputStatus:`_outputStatus_hrpqm_781`,status_done:`_status_done_hrpqm_792`,status_running:`_status_running_hrpqm_793`,status_error:`_status_error_hrpqm_794`,status_waiting:`_status_waiting_hrpqm_795`,liveBlockBody:`_liveBlockBody_hrpqm_798`,liveBlockWorking:`_liveBlockWorking_hrpqm_936`,workingDot:`_workingDot_hrpqm_943`,workingBounce:`_workingBounce_hrpqm_1`,workingLabel:`_workingLabel_hrpqm_960`,workingFade:`_workingFade_hrpqm_1`,studioBlinkCursor:`_studioBlinkCursor_hrpqm_1`,resultAccordion:`_resultAccordion_hrpqm_989`,resultAccordionSummary:`_resultAccordionSummary_hrpqm_996`,resultAccordionBody:`_resultAccordionBody_hrpqm_1013`,financeSection:`_financeSection_hrpqm_1047`,financeSectionTitle:`_financeSectionTitle_hrpqm_1055`,financePresets:`_financePresets_hrpqm_1064`,financeBtn:`_financeBtn_hrpqm_1070`,canvasToggleBtn:`_canvasToggleBtn_hrpqm_1088`,canvasPanel:`_canvasPanel_hrpqm_1104`,canvasPanelHeader:`_canvasPanelHeader_hrpqm_1119`,canvasPanelActions:`_canvasPanelActions_hrpqm_1131`,canvasPanelBtn:`_canvasPanelBtn_hrpqm_1137`,canvasPanelClose:`_canvasPanelClose_hrpqm_1149`,canvasFrame:`_canvasFrame_hrpqm_1160`,pipelineLiveTag:`_pipelineLiveTag_hrpqm_1168`,liveTagBlink:`_liveTagBlink_hrpqm_1`,reasonRow:`_reasonRow_hrpqm_1182`,reasonChip:`_reasonChip_hrpqm_1191`,reasonIcon:`_reasonIcon_hrpqm_1204`,reasonText:`_reasonText_hrpqm_1205`,liveBlockReason:`_liveBlockReason_hrpqm_1208`,councilWrapper:`_councilWrapper_hrpqm_1218`,councilPanel:`_councilPanel_hrpqm_1223`,councilHeader:`_councilHeader_hrpqm_1231`,councilHeaderLeft:`_councilHeaderLeft_hrpqm_1242`,councilHeaderRight:`_councilHeaderRight_hrpqm_1248`,councilIcon:`_councilIcon_hrpqm_1254`,councilTitle:`_councilTitle_hrpqm_1256`,councilConvergedBadge:`_councilConvergedBadge_hrpqm_1265`,councilDivergedBadge:`_councilDivergedBadge_hrpqm_1277`,councilPhaseTag:`_councilPhaseTag_hrpqm_1289`,councilPhaseActive:`_councilPhaseActive_hrpqm_1295`,phaseGlow:`_phaseGlow_hrpqm_1`,councilPhaseDone:`_councilPhaseDone_hrpqm_1304`,councilMetrics:`_councilMetrics_hrpqm_1307`,convRow:`_convRow_hrpqm_1315`,convLabel:`_convLabel_hrpqm_1321`,convTrack:`_convTrack_hrpqm_1329`,convFill:`_convFill_hrpqm_1337`,convPct:`_convPct_hrpqm_1343`,councilNodes:`_councilNodes_hrpqm_1353`,councilSectionTitle:`_councilSectionTitle_hrpqm_1358`,councilNode:`_councilNode_hrpqm_1353`,councilNodeHeader:`_councilNodeHeader_hrpqm_1375`,councilNodeIcon:`_councilNodeIcon_hrpqm_1388`,councilNodeLabel:`_councilNodeLabel_hrpqm_1389`,councilNodeToggle:`_councilNodeToggle_hrpqm_1390`,councilNodeBody:`_councilNodeBody_hrpqm_1392`,councilSynthesis:`_councilSynthesis_hrpqm_1402`,councilSynthesisHeader:`_councilSynthesisHeader_hrpqm_1406`,heraldIcon:`_heraldIcon_hrpqm_1415`,heraldLabel:`_heraldLabel_hrpqm_1417`,heraldStreaming:`_heraldStreaming_hrpqm_1425`,councilSynthesisBody:`_councilSynthesisBody_hrpqm_1427`,councilSkipped:`_councilSkipped_hrpqm_1457`,councilSkipIcon:`_councilSkipIcon_hrpqm_1468`,charSpriteRunning:`_charSpriteRunning_hrpqm_1481`,spriteWalk:`_spriteWalk_hrpqm_1`,charSpriteDone:`_charSpriteDone_hrpqm_1490`,charScanline:`_charScanline_hrpqm_1494`,scanlineScroll:`_scanlineScroll_hrpqm_1`,auraAnim:`_auraAnim_hrpqm_1514`,auraGlow:`_auraGlow_hrpqm_1`,parliamentPrompt:`_parliamentPrompt_hrpqm_1521`,parliamentPromptIcon:`_parliamentPromptIcon_hrpqm_1531`,parliamentPromptContent:`_parliamentPromptContent_hrpqm_1532`,parliamentPromptTitle:`_parliamentPromptTitle_hrpqm_1533`,parliamentPromptDesc:`_parliamentPromptDesc_hrpqm_1534`,parliamentPromptMeta:`_parliamentPromptMeta_hrpqm_1535`,parliamentPromptBtns:`_parliamentPromptBtns_hrpqm_1536`,parliamentActivateBtn:`_parliamentActivateBtn_hrpqm_1537`,parliamentSkipBtn:`_parliamentSkipBtn_hrpqm_1544`,panelTabs:`_panelTabs_hrpqm_1552`,panelTabBtn:`_panelTabBtn_hrpqm_1553`,panelTabActive:`_panelTabActive_hrpqm_1560`,panelEmpty:`_panelEmpty_hrpqm_1562`,browserPanel:`_browserPanel_hrpqm_1571`,browserBar:`_browserBar_hrpqm_1572`,browserInput:`_browserInput_hrpqm_1573`,browserGo:`_browserGo_hrpqm_1580`,liveBlockClickable:`_liveBlockClickable_hrpqm_1587`,liveBlockBodyClamped:`_liveBlockBodyClamped_hrpqm_1596`,expandHint:`_expandHint_hrpqm_1603`,blockModalOverlay:`_blockModalOverlay_hrpqm_1612`,blockModal:`_blockModal_hrpqm_1612`,blockModalHeader:`_blockModalHeader_hrpqm_1637`,blockModalTitle:`_blockModalTitle_hrpqm_1647`,blockModalClose:`_blockModalClose_hrpqm_1655`,blockModalBody:`_blockModalBody_hrpqm_1667`},ye=[{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)
@@ -392,37 +392,67 @@ if (signalCtx) {
392
392
  ${g}
393
393
  <\/script>
394
394
  </body>
395
- </html>`}function qe(e,t){let n=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`),r=t.map(e=>`
396
- <section class="agent-section">
397
- <div class="agent-header">
398
- <span class="agent-icon">${n(e.icon)}</span>
399
- <span class="agent-label">${n(e.label)}</span>
400
- </div>
401
- <div class="agent-body">${n(e.output??``).replace(/\n/g,`<br>`)}</div>
402
- </section>`).join(`
403
- `);return`<!DOCTYPE html>
404
- <html lang="it">
405
- <head>
406
- <meta charset="UTF-8">
407
- <title>${n(e.slice(0,80))}</title>
395
+ </html>`}function qe(e,t){let n=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`),r=e=>n(e).replace(/^#{3}\s+(.+)$/gm,`<h3>$1</h3>`).replace(/^#{2}\s+(.+)$/gm,`<h2>$1</h2>`).replace(/^#{1}\s+(.+)$/gm,`<h1>$1</h1>`).replace(/\*\*(.*?)\*\*/g,`<strong>$1</strong>`).replace(/\*(.*?)\*/g,`<em>$1</em>`).replace(/`([^`]+)`/g,`<code>$1</code>`).replace(/^\|\s*(.*?)\s*\|/gm,(e,t)=>`<tr>${t.split(`|`).map(e=>`<td>${e.trim()}</td>`).join(``)}</tr>`).replace(/(<tr>.*?<\/tr>\n?)+/gs,e=>`<table>${e}</table>`).replace(/^[-*]\s+(.+)$/gm,`<li>$1</li>`).replace(/(<li>.*?<\/li>\n?)+/gs,e=>`<ul>${e}</ul>`).replace(/\n{2,}/g,`</p><p>`).replace(/^(?!<[a-zA-Z])(.+)$/gm,`$1<br>`),i=t.filter(e=>e.output&&e.output!==`(no output)`),a=i.map(e=>{let t=(e.output.match(/bullish|buy|positive|strong|upside|growth|ottimo|eccellente|positiv/gi)??[]).length,n=(e.output.match(/bearish|sell|negative|weak|risk|downside|problema|critico|negativ/gi)??[]).length;return Math.max(5,Math.min(95,50+(t-n)*6))}),o=Math.floor(Math.min(560,i.length*80)),s=i.length>0?Math.floor(o/i.length)-6:40,c=i.length>=2?`
396
+ <div class="chart-section">
397
+ <h3 class="chart-title">Agent Confidence Scores</h3>
398
+ <svg width="${o}" height="120" viewBox="0 0 ${o} 120" xmlns="http://www.w3.org/2000/svg">
399
+ <rect width="${o}" height="120" fill="#f8fafc" rx="6"/>
400
+ ${a.map((e,t)=>{let n=t*(s+6)+4,r=Math.round(e*.8),a=100-r,o=e>=65?`#22c55e`:e<=35?`#ef4444`:`#f59e0b`;return`<rect x="${n}" y="${a}" width="${s}" height="${r}" fill="${o}" rx="3"/>
401
+ <text x="${n+s/2}" y="114" text-anchor="middle" font-size="8" fill="#64748b">${i[t].label.slice(0,8)}</text>
402
+ <text x="${n+s/2}" y="${a-4}" text-anchor="middle" font-size="9" font-weight="bold" fill="${o}">${e}%</text>`}).join(``)}
403
+ <line x1="0" y1="100" x2="${o}" y2="100" stroke="#e2e8f0" stroke-width="1"/>
404
+ </svg>
405
+ </div>`:``,l=i.map(e=>`<div class="toc-item"><span class="toc-icon">${e.icon}</span>${n(e.label)}</div>`).join(``),u=i.map(e=>`<div class="section"><div class="agent-header"><span class="icon">${e.icon}</span><div class="agent-name">${n(e.label)}</div></div><div class="section-body"><p>${r(e.output)}</p></div></div>`).join(``);return`<!DOCTYPE html><html lang="it"><head><meta charset="UTF-8"><title>NHA Studio — ${n(e.slice(0,80))}</title>
408
406
  <style>
409
- * { box-sizing: border-box; margin: 0; padding: 0; }
410
- body { font-family: system-ui, sans-serif; background: #0a0d14; color: #e2e8f0; padding: 32px; }
411
- h1 { font-size: 22px; font-weight: 700; color: #f1f5f9; margin-bottom: 8px; border-bottom: 2px solid #334155; padding-bottom: 12px; }
412
- .meta { font-size: 12px; color: #64748b; margin-bottom: 28px; }
413
- .agent-section { background: #0f172a; border: 1px solid #1e293b; border-radius: 10px; margin-bottom: 20px; overflow: hidden; }
414
- .agent-header { display: flex; align-items: center; gap: 10px; padding: 12px 18px; background: #111827; border-bottom: 1px solid #1e293b; }
415
- .agent-icon { font-size: 20px; }
416
- .agent-label { font-size: 14px; font-weight: 700; color: #67e8f9; font-family: monospace; }
417
- .agent-body { padding: 16px 18px; font-size: 14px; line-height: 1.7; color: #cbd5e1; white-space: pre-wrap; word-break: break-word; }
418
- </style>
419
- </head>
420
- <body>
421
- <h1>${n(e.slice(0,120))}</h1>
422
- <div class="meta">Studio Report · ${new Date().toLocaleString(`it-IT`)} · ${t.length} agent${t.length===1?`e`:`i`}</div>
423
- ${r}
424
- </body>
425
- </html>`}function Je(e){try{localStorage.setItem(`nha_studio_sessions`,JSON.stringify(e.slice(0,20)))}catch{}}function Ye(){try{return JSON.parse(localStorage.getItem(`nha_studio_sessions`)??`[]`)}catch{return[]}}var Xe=`nha_studio_active`;function Ze(e){try{sessionStorage.setItem(Xe,JSON.stringify(e))}catch{}}function Qe(){try{let e=sessionStorage.getItem(Xe);return e?JSON.parse(e):null}catch{return null}}function $e(e){let t=[];return{clean:e.replace(/```json\s*\n?\s*\{[^`]*"action"\s*:\s*"canvas_render"[^`]*\}\s*```/g,e=>{try{let n=JSON.parse(e.replace(/```json\s*|\s*```/g,``).trim());n?.params?.html&&t.push(n.params.html)}catch{}return``}).replace(/\{"action"\s*:\s*"canvas_render"[^}]*"html"\s*:\s*"((?:[^"\\]|\\.)*)"/g,e=>{try{let n=JSON.parse(e+`}`);n?.params?.html&&t.push(n.params.html)}catch{try{let n=e.match(/"html"\s*:\s*"((?:[^"\\]|\\.)*?)"/);n&&t.push(JSON.parse(`"`+n[1]+`"`))}catch{}}return``}).trim(),canvasBlocks:t}}function et(){return ne.getState().apiBase}async function tt(e,t,n,r){let i=await fetch(et()+e,{method:`POST`,headers:{"Content-Type":`application/json`,"x-nha-client":`web-ui`},body:JSON.stringify(t),signal:r});if(!i.ok||!i.body)throw Error(`HTTP ${i.status}`);let a=i.body.getReader(),o=new TextDecoder,s=``;for(;;){let{done:e,value:t}=await a.read();if(e)break;s+=o.decode(t,{stream:!0});let r=s.split(`
407
+ *{box-sizing:border-box;margin:0;padding:0;-webkit-print-color-adjust:exact;print-color-adjust:exact}
408
+ body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;color:#1e293b;background:#fff;font-size:13px;line-height:1.75;padding:40px;max-width:900px;margin:0 auto}
409
+ .cover{background:linear-gradient(135deg,#1e1b4b 0%,#312e81 50%,#0f172a 100%) !important;color:#fff !important;padding:48px 52px;margin-bottom:36px;border-radius:12px;-webkit-print-color-adjust:exact;print-color-adjust:exact}
410
+ .cover h1{color:#fff !important;font-size:28px;font-weight:900;margin-bottom:6px;letter-spacing:-0.5px}
411
+ .cover .meta{color:rgba(255,255,255,.7) !important;font-size:11px;margin-bottom:18px}
412
+ .task{color:#fff !important;font-size:14px;padding:14px 18px;background:rgba(99,102,241,0.25) !important;border-radius:8px;border-left:4px solid #818cf8 !important;line-height:1.6}
413
+ .toc{margin-bottom:32px;padding:16px 20px;background:#f1f5f9 !important;border-radius:8px;border-left:3px solid #6366f1 !important;-webkit-print-color-adjust:exact;print-color-adjust:exact}
414
+ .toc h3{font-size:11px;font-weight:700;color:#64748b;text-transform:uppercase;letter-spacing:1px;margin-bottom:10px}
415
+ .toc-item{display:flex;align-items:center;gap:8px;padding:3px 0;font-size:12px;color:#334155}
416
+ .toc-icon{font-size:14px;width:20px;text-align:center}
417
+ .section{margin-bottom:36px;padding-bottom:36px;border-bottom:1px solid #e2e8f0;page-break-inside:avoid}
418
+ .agent-header{display:flex;align-items:center;gap:12px;margin-bottom:18px;padding-bottom:10px;border-bottom:2px solid #6366f1 !important}
419
+ .icon{font-size:22px;width:32px;text-align:center}
420
+ .agent-name{font-size:15px;font-weight:800;color:#0f172a}
421
+ .section-body{font-size:13px;line-height:1.8;color:#374151}
422
+ .section-body h1{font-size:17px;font-weight:800;margin:20px 0 10px;color:#0f172a;padding-bottom:6px;border-bottom:2px solid #6366f1}
423
+ .section-body h2{font-size:14px;font-weight:700;margin:16px 0 8px;color:#0f172a;padding-left:10px;border-left:3px solid #4f46e5}
424
+ .section-body h3{font-size:13px;font-weight:700;margin:12px 0 6px;color:#7c3aed;padding-left:8px;border-left:2px solid #7c3aed}
425
+ .section-body strong{color:#0f172a;font-weight:700}
426
+ .section-body em{font-style:italic;color:#64748b}
427
+ .section-body code{background:#f1f5f9 !important;border:1px solid #e2e8f0;border-radius:3px;padding:1px 5px;font-family:monospace;font-size:11px;color:#7c3aed !important}
428
+ .section-body table{width:100%;border-collapse:collapse;margin:14px 0}
429
+ .section-body th{background:#f1f5f9 !important;color:#0f172a;font-weight:700;padding:8px 12px;text-align:left;border:1px solid #e2e8f0;font-size:11px;text-transform:uppercase;letter-spacing:0.5px;-webkit-print-color-adjust:exact;print-color-adjust:exact}
430
+ .section-body td{padding:8px 12px;border:1px solid #e2e8f0;color:#374151;font-size:12px}
431
+ .section-body tr:nth-child(even) td{background:#f8fafc !important;-webkit-print-color-adjust:exact;print-color-adjust:exact}
432
+ .section-body ul{padding-left:20px;margin:8px 0}
433
+ .section-body li{margin-bottom:4px}
434
+ .section-body p{margin:0 0 8px}
435
+ .chart-section{margin:24px 0;padding:16px 20px;background:#f8fafc !important;border-radius:8px;border:1px solid #e2e8f0;-webkit-print-color-adjust:exact;print-color-adjust:exact}
436
+ .chart-title{font-size:12px;font-weight:700;color:#64748b;text-transform:uppercase;letter-spacing:0.5px;margin-bottom:14px}
437
+ .footer{margin-top:48px;padding-top:16px;border-top:1px solid #e2e8f0;color:#94a3b8;font-size:10px;text-align:center}
438
+ @media print{*{-webkit-print-color-adjust:exact !important;print-color-adjust:exact !important}
439
+ .cover{background:linear-gradient(135deg,#1e1b4b 0%,#312e81 50%,#0f172a 100%) !important;page-break-after:always}
440
+ .section{page-break-inside:avoid}
441
+ @page{margin:1.5cm;size:A4}}
442
+ </style></head><body>
443
+ <div class="cover">
444
+ <h1>NHA Studio Report</h1>
445
+ <div class="meta">Generated ${new Date().toLocaleString()} · ${i.length} agents</div>
446
+ <div class="task">${n(e)}</div>
447
+ </div>
448
+ <div class="toc">
449
+ <h3>Table of Contents</h3>
450
+ ${l}
451
+ </div>
452
+ ${c}
453
+ ${u}
454
+ <div class="footer">NHA Studio · nothumanallowed.com · ${new Date().getFullYear()}</div>
455
+ </body></html>`}function Je(e){try{localStorage.setItem(`nha_studio_sessions`,JSON.stringify(e.slice(0,20)))}catch{}}function Ye(){try{return JSON.parse(localStorage.getItem(`nha_studio_sessions`)??`[]`)}catch{return[]}}var Xe=`nha_studio_active`;function Ze(e){try{sessionStorage.setItem(Xe,JSON.stringify(e))}catch{}}function Qe(){try{let e=sessionStorage.getItem(Xe);return e?JSON.parse(e):null}catch{return null}}function $e(e){let t=[];return{clean:e.replace(/```json\s*\n?\s*\{[^`]*"action"\s*:\s*"canvas_render"[^`]*\}\s*```/g,e=>{try{let n=JSON.parse(e.replace(/```json\s*|\s*```/g,``).trim());n?.params?.html&&t.push(n.params.html)}catch{}return``}).replace(/\{"action"\s*:\s*"canvas_render"[^}]*"html"\s*:\s*"((?:[^"\\]|\\.)*)"/g,e=>{try{let n=JSON.parse(e+`}`);n?.params?.html&&t.push(n.params.html)}catch{try{let n=e.match(/"html"\s*:\s*"((?:[^"\\]|\\.)*?)"/);n&&t.push(JSON.parse(`"`+n[1]+`"`))}catch{}}return``}).trim(),canvasBlocks:t}}function et(){return ne.getState().apiBase}async function tt(e,t,n,r){let i=await fetch(et()+e,{method:`POST`,headers:{"Content-Type":`application/json`,"x-nha-client":`web-ui`},body:JSON.stringify(t),signal:r});if(!i.ok||!i.body)throw Error(`HTTP ${i.status}`);let a=i.body.getReader(),o=new TextDecoder,s=``;for(;;){let{done:e,value:t}=await a.read();if(e)break;s+=o.decode(t,{stream:!0});let r=s.split(`
426
456
  `);s=r.pop()??``;for(let e of r){if(!e.startsWith(`data: `))continue;let t=e.slice(6).trim();if(t===`[DONE]`)return;try{n(JSON.parse(t))}catch{}}}}function nt({label:e,value:t}){let n=Math.round(t*100),r=n>=60?`#22c55e`:n>=30?`#f59e0b`:`#ef4444`;return(0,k.jsxs)(`div`,{className:F.convRow,children:[(0,k.jsx)(`span`,{className:F.convLabel,children:e}),(0,k.jsx)(`div`,{className:F.convTrack,children:(0,k.jsx)(`div`,{className:F.convFill,style:{width:`${n}%`,background:r}})}),(0,k.jsxs)(`span`,{className:F.convPct,style:{color:r},children:[n,`%`]})]})}function rt({council:e}){let[t,n]=(0,_.useState)(null);if(e.skipped)return(0,k.jsxs)(`div`,{className:F.councilSkipped,children:[(0,k.jsx)(`span`,{className:F.councilSkipIcon,children:`🏛️`}),(0,k.jsxs)(`span`,{children:[`Council skipped — `,e.skipReason??`fewer than 2 eligible agents`]})]});let r=e.phase===`r2`?`⚡ Cross-reading & Refinement (Round 2)…`:e.phase===`r3`?`🏛️ HERALD Mediation (Round 3)…`:e.phase===`done`?`✅ Council Consensus Reached`:`🏛️ Council…`,i=e.converged?(0,k.jsx)(`span`,{className:F.councilConvergedBadge,children:`CONSENSUS`}):(0,k.jsx)(`span`,{className:F.councilDivergedBadge,children:`MEDIATED`});return(0,k.jsxs)(`div`,{className:F.councilPanel,children:[(0,k.jsxs)(`div`,{className:F.councilHeader,children:[(0,k.jsxs)(`div`,{className:F.councilHeaderLeft,children:[(0,k.jsx)(`span`,{className:F.councilIcon,children:`🏛️`}),(0,k.jsx)(`span`,{className:F.councilTitle,children:`Council · Geth Consensus`}),e.phase===`done`&&i]}),(0,k.jsx)(`div`,{className:F.councilHeaderRight,children:e.phase!==`idle`&&(0,k.jsx)(`span`,{className:`${F.councilPhaseTag} ${e.phase===`done`?F.councilPhaseDone:F.councilPhaseActive}`,children:r})})]}),(e.r1Convergence>0||e.r2Convergence>0)&&(0,k.jsxs)(`div`,{className:F.councilMetrics,children:[e.r1Convergence>0&&(0,k.jsx)(nt,{label:`Round 1`,value:e.r1Convergence}),e.r2Convergence>0&&(0,k.jsx)(nt,{label:`Round 2`,value:e.r2Convergence})]}),e.r2Nodes.length>0&&(0,k.jsxs)(`div`,{className:F.councilNodes,children:[(0,k.jsx)(`div`,{className:F.councilSectionTitle,children:`Refined Positions (Round 2)`}),e.r2Nodes.map(e=>(0,k.jsxs)(`div`,{className:F.councilNode,children:[(0,k.jsxs)(`button`,{className:F.councilNodeHeader,onClick:()=>n(t===e.agent?null:e.agent),children:[(0,k.jsx)(`span`,{className:F.councilNodeIcon,children:e.icon}),(0,k.jsx)(`span`,{className:F.councilNodeLabel,children:e.label}),(0,k.jsx)(`span`,{className:F.councilNodeToggle,children:t===e.agent?`▲`:`▼`})]}),t===e.agent&&(0,k.jsx)(`div`,{className:F.councilNodeBody,dangerouslySetInnerHTML:{__html:me(e.output)}})]},e.agent))]}),e.synthesis&&(0,k.jsxs)(`div`,{className:F.councilSynthesis,children:[(0,k.jsxs)(`div`,{className:F.councilSynthesisHeader,children:[(0,k.jsx)(`span`,{className:F.heraldIcon,children:`📰`}),(0,k.jsx)(`span`,{className:F.heraldLabel,children:`HERALD — Final Synthesis`}),e.phase===`r3`&&(0,k.jsx)(`span`,{className:F.heraldStreaming,children:(0,k.jsx)(`span`,{className:`studio-cursor`})})]}),(0,k.jsx)(`div`,{className:F.councilSynthesisBody,dangerouslySetInnerHTML:{__html:me(e.synthesis)+(e.phase===`r3`?`<span class="studio-cursor"></span>`:``)}})]})]})}function it(){let e=ne(e=>e.setView),t=Qe(),[n,r]=(0,_.useState)(t?.task??``),[i,a]=(0,_.useState)(t?.nodes??[]),[o,s]=(0,_.useState)(t?.log??[]),[c,l]=(0,_.useState)(t?.result??``),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(Ye),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),[y,b]=(0,_.useState)({in:0,out:0}),[x,S]=(0,_.useState)(t?.canvasHtml??``),[C,w]=(0,_.useState)(t?.council??null),[ee,te]=(0,_.useState)(!1),[T,E]=(0,_.useState)([]),[D,re]=(0,_.useState)(!1),[ie,O]=(0,_.useState)(`canvas`),[ae,A]=(0,_.useState)(``),[j,oe]=(0,_.useState)(null),se=(0,_.useRef)(null),ce=(0,_.useRef)(null),le=(0,_.useRef)(t?.canvasHtml??``),ue=(0,_.useRef)(t?.council??null),M=(0,_.useRef)([]);(0,_.useEffect)(()=>{Ze({task:n,nodes:i,log:o,result:c,canvasHtml:x,council:C})},[n,i,o,c,x,C]),(0,_.useEffect)(()=>{ce.current&&(ce.current.scrollTop=ce.current.scrollHeight)},[o]);let N=(0,_.useCallback)((e,t,n,r=`agent`)=>{let i=new Date().toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1});s(a=>[...a,{agent:e,icon:t,text:n,time:i,type:r}])},[]),de=e=>{if(!e)return;let t=e.name.toLowerCase();if(!t.endsWith(`.pdf`)&&!/\.(png|jpe?g|gif|webp)$/i.test(t)){alert(`Supported: PDF, PNG, JPG, GIF, WEBP`);return}let n=new FileReader;n.onload=t=>v({name:e.name,data:t.target?.result}),n.readAsDataURL(e)},fe=async()=>{if(!n.trim()||u)return;d(!0),a([]),s([]),l(``),w(null),ue.current=null,b({in:0,out:0}),le.current=``,S(``),N(`Studio`,`🎬`,`Planning workflow…`,`system`);let e=new AbortController;se.current=e;try{let t={task:n.trim()};g&&(t[g.name.endsWith(`.pdf`)?`pdfBase64`:`imageBase64`]=g.data,g.name.endsWith(`.pdf`)&&(t.pdfName=g.name));let r=[];try{let n=await fetch(et()+`/api/studio/plan`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t),signal:e.signal});if(n.ok){let e=await n.json();r=e.steps??e.nodes??[]}}catch{}r.length||(r=[{icon:`🤖`,agent:`general`,label:`Assistant`,status:`waiting`,output:``}]);let i=r.map(e=>({...e,status:`waiting`,output:``}));a(i),N(`Studio`,`📋`,`${i.length} agents planned: ${i.map(e=>e.label).join(` → `)}`,`system`);let o=``,s=[...i];for(let t=0;t<s.length&&!e.signal.aborted;t++){let r=s[t];s[t]={...r,status:`running`,output:``},a([...s]),N(r.label,r.icon,`Running ${r.label}…`,`agent`);let i=``;try{await tt(`/api/studio/run`,{stepIdx:t,agent:r.agent,task:n.trim(),prompt:(r.reason,void 0),context:o.length>12e4?o.slice(-12e4):o,...t===0&&g?g.name.endsWith(`.pdf`)?{pdfBase64:g.data,pdfName:g.name}:{imageBase64:g.data}:{}},e=>{let n=e.token??e.content??``;n&&(n.startsWith(`[`)&&n.indexOf(`]`)>0&&n.length<80&&!n.includes(`
427
457
  `)||(i+=n,s[t]={...s[t],output:i},a([...s])))},e.signal);let{clean:c,canvasBlocks:l}=$e(i),u=c||`(no output)`;if(s[t]={...s[t],status:`done`,output:u},a([...s]),o+=`\n\n[${r.label}]:\n${u}`,N(r.label,r.icon,`Done (${u.length} chars)`,`agent`),l.length>0){let e=l[l.length-1];le.current=e,S(e),re(!0),O(`canvas`),N(r.label,r.icon,`Canvas render captured`,`system`)}}catch(n){if(e.signal.aborted)break;s[t]={...s[t],status:`error`,output:n.message??`Error`},a([...s]),N(r.label,r.icon,`Error: ${n.message}`,`error`)}}let c=s.filter(e=>e.status===`done`&&e.output&&e.output!==`(no output)`&&![`CanvasAgent`,`GitHubAgent`,`EmailAgent`,`CalendarAgent`].includes(e.agent));c.length>=2?(M.current=c,E(c),te(!0),N(`Consiglio`,`🏛️`,`${c.length} agenti pronti — attendi conferma utente`,`system`)):N(`Studio`,`ℹ️`,`Council skipped — fewer than 2 eligible specialist agents`,`system`);let u=ue.current,d=s.filter(e=>e.output&&e.output!==`(no output)`).map(e=>`## ${e.icon} ${e.label}\n\n${e.output}`).join(`
428
458
 
@@ -440,19 +470,19 @@ ${g}
440
470
  </svg>
441
471
  </div>`:``,u=C?.synthesis?`<div class="section parliament"><div class="agent-header"><span class="icon">🏛️</span><div class="agent-name">Parliament — HERALD Synthesis</div></div><div class="section-body"><p>${r(C.synthesis)}</p></div></div>`:``,d=`<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>NHA Studio — ${t(n)}</title>
442
472
  <style>
443
- *{box-sizing:border-box;margin:0;padding:0}
473
+ *{box-sizing:border-box;margin:0;padding:0;-webkit-print-color-adjust:exact;print-color-adjust:exact}
444
474
  body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;color:#1e293b;background:#fff;font-size:13px;line-height:1.75;padding:40px;max-width:900px;margin:0 auto}
445
- .cover{background:linear-gradient(135deg,#1e1b4b 0%,#312e81 50%,#0f172a 100%);color:#fff;padding:48px 52px;margin-bottom:36px;border-radius:12px;page-break-after:always}
446
- .cover h1{color:#fff;font-size:28px;font-weight:900;margin-bottom:6px;letter-spacing:-0.5px}
447
- .cover .meta{color:rgba(255,255,255,.55);font-size:11px;margin-bottom:18px}
448
- .task{color:rgba(255,255,255,.85);font-size:14px;padding:14px 18px;background:rgba(255,255,255,.07);border-radius:8px;border-left:3px solid #818cf8;line-height:1.6}
449
- .toc{margin-bottom:32px;padding:16px 20px;background:#f1f5f9;border-radius:8px;border-left:3px solid #6366f1}
475
+ .cover{background:linear-gradient(135deg,#1e1b4b 0%,#312e81 50%,#0f172a 100%) !important;color:#fff !important;padding:48px 52px;margin-bottom:36px;border-radius:12px;page-break-after:always;-webkit-print-color-adjust:exact;print-color-adjust:exact}
476
+ .cover h1{color:#fff !important;font-size:28px;font-weight:900;margin-bottom:6px;letter-spacing:-0.5px}
477
+ .cover .meta{color:rgba(255,255,255,.7) !important;font-size:11px;margin-bottom:18px}
478
+ .task{color:#fff !important;font-size:14px;padding:14px 18px;background:rgba(99,102,241,0.25) !important;border-radius:8px;border-left:4px solid #818cf8 !important;line-height:1.6}
479
+ .toc{margin-bottom:32px;padding:16px 20px;background:#f1f5f9 !important;border-radius:8px;border-left:3px solid #6366f1 !important;-webkit-print-color-adjust:exact;print-color-adjust:exact}
450
480
  .toc h3{font-size:11px;font-weight:700;color:#64748b;text-transform:uppercase;letter-spacing:1px;margin-bottom:10px}
451
481
  .toc-item{display:flex;align-items:center;gap:8px;padding:3px 0;font-size:12px;color:#334155}
452
482
  .toc-icon{font-size:14px;width:20px;text-align:center}
453
483
  .section{margin-bottom:36px;padding-bottom:36px;border-bottom:1px solid #e2e8f0;page-break-inside:avoid}
454
- .section.parliament{background:linear-gradient(135deg,#ede9fe,#f0f9ff);padding:20px 24px;border-radius:10px;border:1px solid #c4b5fd;border-bottom:1px solid #c4b5fd}
455
- .agent-header{display:flex;align-items:center;gap:12px;margin-bottom:18px;padding-bottom:10px;border-bottom:1px solid #e2e8f0}
484
+ .section.parliament{background:linear-gradient(135deg,#ede9fe,#f0f9ff) !important;padding:20px 24px;border-radius:10px;border:1px solid #c4b5fd !important;-webkit-print-color-adjust:exact;print-color-adjust:exact}
485
+ .agent-header{display:flex;align-items:center;gap:12px;margin-bottom:18px;padding-bottom:10px;border-bottom:2px solid #6366f1 !important}
456
486
  .icon{font-size:22px;width:32px;text-align:center}
457
487
  .agent-name{font-size:15px;font-weight:800;color:#0f172a}
458
488
  .section-body{font-size:13px;line-height:1.8;color:#374151}
@@ -461,18 +491,21 @@ body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;color:#1
461
491
  .section-body h3{font-size:13px;font-weight:700;margin:12px 0 6px;color:#7c3aed;padding-left:8px;border-left:2px solid #7c3aed}
462
492
  .section-body strong{color:#0f172a;font-weight:700}
463
493
  .section-body em{font-style:italic;color:#64748b}
464
- .section-body code{background:#f1f5f9;border:1px solid #e2e8f0;border-radius:3px;padding:1px 5px;font-family:monospace;font-size:11px;color:#7c3aed}
494
+ .section-body code{background:#f1f5f9 !important;border:1px solid #e2e8f0;border-radius:3px;padding:1px 5px;font-family:monospace;font-size:11px;color:#7c3aed !important}
465
495
  .section-body table{width:100%;border-collapse:collapse;margin:14px 0}
466
- .section-body th{background:#f1f5f9;color:#0f172a;font-weight:700;padding:8px 12px;text-align:left;border:1px solid #e2e8f0;font-size:11px;text-transform:uppercase;letter-spacing:0.5px}
496
+ .section-body th{background:#f1f5f9 !important;color:#0f172a;font-weight:700;padding:8px 12px;text-align:left;border:1px solid #e2e8f0;font-size:11px;text-transform:uppercase;letter-spacing:0.5px;-webkit-print-color-adjust:exact;print-color-adjust:exact}
467
497
  .section-body td{padding:8px 12px;border:1px solid #e2e8f0;color:#374151;font-size:12px}
468
- .section-body tr:nth-child(even) td{background:#f8fafc}
498
+ .section-body tr:nth-child(even) td{background:#f8fafc !important;-webkit-print-color-adjust:exact;print-color-adjust:exact}
469
499
  .section-body ul{padding-left:20px;margin:8px 0}
470
500
  .section-body li{margin-bottom:4px}
471
501
  .section-body p{margin:0 0 8px}
472
- .chart-section{margin:24px 0;padding:16px 20px;background:#f8fafc;border-radius:8px;border:1px solid #e2e8f0}
502
+ .chart-section{margin:24px 0;padding:16px 20px;background:#f8fafc !important;border-radius:8px;border:1px solid #e2e8f0;-webkit-print-color-adjust:exact;print-color-adjust:exact}
473
503
  .chart-title{font-size:12px;font-weight:700;color:#64748b;text-transform:uppercase;letter-spacing:0.5px;margin-bottom:14px}
474
504
  .footer{margin-top:48px;padding-top:16px;border-top:1px solid #e2e8f0;color:#94a3b8;font-size:10px;text-align:center}
475
- @media print{.cover{page-break-after:always}.section{page-break-inside:avoid}}
505
+ @media print{*{-webkit-print-color-adjust:exact !important;print-color-adjust:exact !important}
506
+ .cover{page-break-after:always;background:linear-gradient(135deg,#1e1b4b 0%,#312e81 50%,#0f172a 100%) !important}
507
+ .section{page-break-inside:avoid}
508
+ @page{margin:1.5cm;size:A4}}
476
509
  </style></head><body>
477
510
  <div class="cover">
478
511
  <h1>NHA Studio Report</h1>
@@ -488,19 +521,19 @@ ${l}
488
521
  ${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(``)}
489
522
  ${u}
490
523
  <div class="footer">NHA Studio · nothumanallowed.com · ${new Date().getFullYear()}</div>
491
- </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))},ve=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`)},be=()=>{if(!u){r(``),a([]),s([]),l(``),S(``),le.current=``,w(null),ue.current=null,te(!1),b({in:0,out:0}),v(null),re(!1);try{sessionStorage.removeItem(Xe)}catch{}}},I=i.some(e=>e.output||e.status===`running`);return(0,k.jsxs)(`div`,{className:F.root,children:[(0,k.jsxs)(`div`,{className:F.header,children:[(0,k.jsxs)(`div`,{className:F.headerLeft,children:[(0,k.jsx)(`div`,{className:F.title,children:`Studio`}),(0,k.jsx)(`div`,{className:F.subtitle,children:`Multi-agent orchestration · Council deliberation · Geth Consensus`})]}),(0,k.jsxs)(`div`,{className:F.headerActions,children:[y.in+y.out>0&&(0,k.jsxs)(`div`,{className:F.tokenBar,children:[(0,k.jsxs)(`span`,{className:F.tokIn,children:[`↑ `,y.in.toLocaleString()]}),(0,k.jsx)(`span`,{className:F.tokDim,children:` in `}),(0,k.jsxs)(`span`,{className:F.tokOut,children:[`↓ `,y.out.toLocaleString()]}),(0,k.jsx)(`span`,{className:F.tokDim,children:` out`})]}),(0,k.jsxs)(`button`,{className:F.sessionsBtn,onClick:()=>h(e=>!e),children:[`Sessions (`,f.length,`)`]}),x&&(0,k.jsx)(`button`,{className:F.canvasToggleBtn,onClick:()=>{re(!0),O(`canvas`)},children:`📊 Panel`}),c&&(0,k.jsx)(`button`,{className:F.pdfBtn,onClick:_e,children:`⬇ PDF / HTML`}),(i.length>0||c||o.length>0)&&!u&&(0,k.jsx)(`button`,{className:F.clearBtn,onClick:be,title:`Clear all — start fresh`,children:`✕ Clear`})]})]}),m&&(0,k.jsxs)(`div`,{className:F.sessionsDrawer,children:[f.length===0&&(0,k.jsx)(`div`,{className:F.noSessions,children:`No saved sessions yet.`}),f.map(e=>(0,k.jsxs)(`div`,{className:F.sessionItem,children:[(0,k.jsxs)(`div`,{className:F.sessionInfo,onClick:()=>he(e),children:[(0,k.jsx)(`div`,{className:F.sessionTask,children:e.task.slice(0,80)}),(0,k.jsxs)(`div`,{className:F.sessionMeta,children:[e.ts.slice(0,16),` · `,e.nodes.length,` agents`,e.council?.phase===`done`?` · 🏛️ Parliament`:``]})]}),(0,k.jsxs)(`div`,{className:F.sessionBtns,children:[(0,k.jsx)(`button`,{className:F.importBtn,onClick:()=>ve(e),children:`→ Chat`}),(0,k.jsx)(`button`,{className:F.delSessionBtn,onClick:()=>ge(e.id),children:`✕`})]})]},e.id))]}),(0,k.jsxs)(`div`,{className:F.inputArea,children:[(0,k.jsxs)(`div`,{className:F.inputRow,children:[(0,k.jsx)(`textarea`,{className:F.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(),fe())}}),(0,k.jsxs)(`div`,{className:F.inputControls,children:[u?(0,k.jsx)(`button`,{className:F.stopBtn,onClick:pe,children:`■ Stop`}):(0,k.jsx)(`button`,{className:F.runBtn,onClick:fe,disabled:!n.trim(),children:`Run ▶`}),(0,k.jsxs)(`label`,{className:F.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=>de(e.target.files?.[0])})]})]})]}),g&&(0,k.jsxs)(`div`,{className:F.attachBadge,children:[`📎 `,g.name,(0,k.jsx)(`button`,{className:F.clearAttach,onClick:()=>v(null),children:`✕`})]}),!u&&i.length===0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:F.examples,children:xe.map((e,t)=>(0,k.jsx)(`button`,{className:F.exampleBtn,onClick:()=>r(e),children:e},t))}),(0,k.jsxs)(`div`,{className:F.financeSection,children:[(0,k.jsx)(`div`,{className:F.financeSectionTitle,children:`📈 Finance & Trading Workflows`}),(0,k.jsx)(`div`,{className:F.financePresets,children:ye.map((e,t)=>(0,k.jsx)(`button`,{className:F.financeBtn,onClick:()=>{r(e.task),a(e.agents)},children:e.label},t))})]})]})]}),i.length>0&&(0,k.jsx)(`div`,{className:F.officeSceneWrap,children:(0,k.jsx)(We,{nodes:i,running:u})}),(0,k.jsxs)(`div`,{className:F.body,children:[i.length>0&&(0,k.jsxs)(`div`,{className:`${F.pipeline} ${u?F.pipelineRunning:``}`,children:[(0,k.jsxs)(`div`,{className:F.pipelineTitle,children:[`Agent Pipeline`,u&&(0,k.jsx)(`span`,{className:F.pipelineLiveTag,children:`● LIVE`})]}),(0,k.jsx)(`div`,{className:F.pipelineNodes,children:i.map((e,t)=>(0,k.jsxs)(`div`,{className:F.pipelineStep,children:[(0,k.jsxs)(`div`,{className:`${F.agentChip} ${F[`chip_${e.status}`]}`,children:[(0,k.jsx)(`span`,{className:F.chipIcon,children:e.icon}),(0,k.jsx)(`span`,{className:F.chipLabel,children:e.label}),e.status===`running`&&(0,k.jsxs)(`span`,{className:F.chipDots,children:[(0,k.jsx)(`span`,{className:F.dot1,children:`.`}),(0,k.jsx)(`span`,{className:F.dot2,children:`.`}),(0,k.jsx)(`span`,{className:F.dot3,children:`.`})]}),e.status===`done`&&(0,k.jsx)(`span`,{className:F.chipCheck,children:`✓`}),e.status===`error`&&(0,k.jsx)(`span`,{className:F.chipErr,children:`✗`})]}),t<i.length-1&&(0,k.jsx)(`div`,{className:`${F.arrow} ${u?F.arrowActive:``}`,children:`→`})]},t))}),i.some(e=>e.reason)&&(0,k.jsx)(`div`,{className:F.reasonRow,children:i.map((e,t)=>e.reason?(0,k.jsxs)(`div`,{className:F.reasonChip,title:e.reason,children:[(0,k.jsx)(`span`,{className:F.reasonIcon,children:e.icon}),(0,k.jsxs)(`span`,{className:F.reasonText,children:[e.reason.slice(0,60),e.reason.length>60?`…`:``]})]},t):null)})]}),(o.length>0||I)&&(0,k.jsxs)(`div`,{className:F.twoCol,children:[(0,k.jsxs)(`div`,{className:F.logPanel,children:[(0,k.jsx)(`div`,{className:F.panelTitle,children:`Live Log`}),(0,k.jsx)(`div`,{className:F.logBody,ref:ce,children:o.map((e,t)=>(0,k.jsxs)(`div`,{className:`${F.logEntry} ${F[`log_${e.type}`]}`,children:[(0,k.jsx)(`span`,{className:F.logTime,children:e.time}),(0,k.jsx)(`span`,{className:F.logIcon,children:e.icon}),(0,k.jsx)(`span`,{className:F.logAgent,children:e.agent}),(0,k.jsx)(`span`,{className:F.logText,children:e.text})]},t))})]}),(0,k.jsx)(`div`,{className:F.liveOutputPanel,children:i.filter(e=>e.output||e.status===`running`).map((e,t)=>(0,k.jsxs)(`div`,{className:`${F.liveBlock} ${e.status===`running`?F.liveBlockActive:``} ${e.status===`done`&&e.output?F.liveBlockClickable:``}`,onClick:()=>e.status===`done`&&e.output?oe(e):void 0,children:[(0,k.jsxs)(`div`,{className:F.liveBlockHeader,children:[(0,k.jsx)(`span`,{className:F.liveBlockIcon,children:e.icon}),(0,k.jsx)(`span`,{className:F.liveBlockLabel,children:e.label}),e.reason&&(0,k.jsx)(`span`,{className:F.liveBlockReason,title:e.reason,children:`ℹ`}),(0,k.jsx)(`span`,{className:`${F.outputStatus} ${F[`status_${e.status}`]}`,children:e.status}),e.status===`done`&&e.output&&(0,k.jsx)(`span`,{className:F.expandHint,children:`↗ espandi`})]}),e.status===`running`&&!e.output&&(0,k.jsxs)(`div`,{className:F.liveBlockWorking,children:[(0,k.jsx)(`span`,{className:F.workingDot}),(0,k.jsx)(`span`,{className:F.workingDot}),(0,k.jsx)(`span`,{className:F.workingDot}),(0,k.jsx)(`span`,{className:F.workingLabel,children:`elaborazione in corso`})]}),(0,k.jsx)(`div`,{className:`${F.liveBlockBody} ${e.status===`done`&&e.output?F.liveBlockBodyClamped:``}`,dangerouslySetInnerHTML:{__html:me(e.output)+(e.status===`running`&&e.output?`<span class="studio-cursor"></span>`:``)}})]},t))})]}),ee&&(0,k.jsxs)(`div`,{className:F.parliamentPrompt,children:[(0,k.jsx)(`div`,{className:F.parliamentPromptIcon,children:`🏛️`}),(0,k.jsxs)(`div`,{className:F.parliamentPromptContent,children:[(0,k.jsx)(`div`,{className:F.parliamentPromptTitle,children:`Attivare il Consiglio?`}),(0,k.jsxs)(`div`,{className:F.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:F.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:F.parliamentPromptBtns,children:[(0,k.jsx)(`button`,{className:F.parliamentActivateBtn,onClick:P,children:`🏛️ Attiva`}),(0,k.jsx)(`button`,{className:F.parliamentSkipBtn,onClick:()=>te(!1),children:`Salta`})]})]}),C&&!ee&&(0,k.jsx)(`div`,{className:F.councilWrapper,children:(0,k.jsx)(rt,{council:C})}),c&&!u&&(0,k.jsxs)(`details`,{className:F.resultAccordion,open:i.length<=1,children:[(0,k.jsxs)(`summary`,{className:F.resultAccordionSummary,children:[`Full Combined Report (`,i.filter(e=>e.output&&e.output!==`(no output)`).length,` agents)`]}),(0,k.jsx)(`div`,{className:F.resultAccordionBody,dangerouslySetInnerHTML:{__html:me(c)}})]})]}),D&&(0,k.jsxs)(`div`,{className:F.canvasPanel,children:[(0,k.jsxs)(`div`,{className:F.canvasPanelHeader,children:[(0,k.jsxs)(`div`,{className:F.panelTabs,children:[(0,k.jsx)(`button`,{className:`${F.panelTabBtn} ${ie===`canvas`?F.panelTabActive:``}`,onClick:()=>O(`canvas`),children:`📊 Canvas`}),(0,k.jsx)(`button`,{className:`${F.panelTabBtn} ${ie===`browser`?F.panelTabActive:``}`,onClick:()=>O(`browser`),children:`🌐 Browser`})]}),(0,k.jsxs)(`div`,{className:F.canvasPanelActions,children:[ie===`canvas`&&x&&(0,k.jsx)(`button`,{className:F.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:F.canvasPanelClose,onClick:()=>re(!1),children:`✕`})]})]}),ie===`canvas`?x?(0,k.jsx)(`iframe`,{className:F.canvasFrame,srcDoc:x,sandbox:`allow-scripts`,title:`Canvas Report`}):(0,k.jsx)(`div`,{className:F.panelEmpty,children:`No canvas report yet. Run a workflow first.`}):(0,k.jsxs)(`div`,{className:F.browserPanel,children:[(0,k.jsxs)(`div`,{className:F.browserBar,children:[(0,k.jsx)(`input`,{className:F.browserInput,value:ae,onChange:e=>A(e.target.value),placeholder:`https://…`,onKeyDown:e=>{e.key===`Enter`&&A(ae)}}),(0,k.jsx)(`button`,{className:F.browserGo,onClick:()=>A(ae),children:`Go`})]}),ae?(0,k.jsx)(`iframe`,{className:F.canvasFrame,src:ae,sandbox:`allow-scripts allow-same-origin allow-forms`,title:`Browser`}):(0,k.jsx)(`div`,{className:F.panelEmpty,children:`Enter a URL above to browse`})]})]}),j&&(0,k.jsx)(`div`,{className:F.blockModalOverlay,onClick:()=>oe(null),children:(0,k.jsxs)(`div`,{className:F.blockModal,onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:F.blockModalHeader,children:[(0,k.jsx)(`span`,{className:F.liveBlockIcon,children:j.icon}),(0,k.jsx)(`span`,{className:F.blockModalTitle,children:j.label}),(0,k.jsx)(`button`,{className:F.blockModalClose,onClick:()=>oe(null),children:`✕`})]}),(0,k.jsx)(`div`,{className:`${F.liveBlockBody} ${F.blockModalBody}`,dangerouslySetInnerHTML:{__html:me(j.output)}})]})})]})}var z={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`},at=[{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`}],ot={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 st(e){try{return new Date(e).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,hour12:!1})}catch{return e}}function ct(e){try{return new Date(e).toLocaleDateString(`en`,{month:`short`,day:`numeric`})}catch{return e}}function lt(){let e=ne(e=>e.setView),t=M(),[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(at.map(e=>e.group))];return(0,k.jsxs)(`div`,{className:z.root,children:[(0,k.jsxs)(`div`,{className:z.hero,children:[(0,k.jsxs)(`div`,{className:z.heroLeft,children:[(0,k.jsx)(`div`,{className:z.heroDate,children:y}),(0,k.jsx)(`div`,{className:z.heroTitle,children:c?(0,k.jsxs)(k.Fragment,{children:[`NHA `,(0,k.jsxs)(`span`,{className:z.heroVer,children:[`v`,c.version]}),` · `,(0,k.jsxs)(`span`,{className:z.heroUptime,children:[Math.floor(c.uptime/60),`m uptime`]})]}):`NotHumanAllowed`})]}),(0,k.jsx)(`div`,{className:z.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:z.wIcon,children:ot[u.desc]??u.icon??`🌡️`}),(0,k.jsxs)(`div`,{className:z.wInfo,children:[(0,k.jsxs)(`span`,{className:z.wTemp,children:[u.tempC,`°C`]}),(0,k.jsxs)(`span`,{className:z.wCity,children:[u.city.split(`,`)[0],u.country?`, ${u.country.slice(0,2).toUpperCase()}`:``]}),(0,k.jsxs)(`span`,{className:z.wDesc,children:[u.desc,` · 💧`,u.humidity,`%`]})]})]}):(0,k.jsxs)(`span`,{className:z.wEmpty,children:[`🌡️ `,t(`dashboard.weather`)]})})]}),(0,k.jsxs)(`div`,{className:z.kpiRow,children:[(0,k.jsxs)(`div`,{className:z.kpi,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:z.kpiNum,children:m.length}),(0,k.jsx)(`span`,{className:z.kpiLbl,children:`Pending tasks`}),n.length>0&&(0,k.jsx)(`div`,{className:z.kpiBar,children:(0,k.jsx)(`div`,{className:z.kpiFill,style:{width:`${g}%`}})})]}),(0,k.jsxs)(`div`,{className:z.kpi,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:z.kpiNum,children:v>0?v:i.length}),(0,k.jsx)(`span`,{className:z.kpiLbl,children:v>0?`Unread emails`:`Emails`})]}),(0,k.jsxs)(`div`,{className:z.kpi,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:z.kpiNum,children:o.length}),(0,k.jsx)(`span`,{className:z.kpiLbl,children:`Today's events`})]}),u&&(0,k.jsxs)(`div`,{className:z.kpi,children:[(0,k.jsxs)(`span`,{className:z.kpiNum,children:[u.feelsC,`°`]}),(0,k.jsx)(`span`,{className:z.kpiLbl,children:`Feels like`})]})]}),(0,k.jsxs)(`div`,{className:z.liveGrid,children:[o.length>0&&(0,k.jsxs)(`div`,{className:z.liveCard,children:[(0,k.jsxs)(`div`,{className:z.liveHdr,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📅 `,t(`calendar.title`)]}),(0,k.jsx)(`span`,{className:z.liveMore,children:`→`})]}),o.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:z.liveRow,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:z.liveTime,children:t.isAllDay?`All day`:st(t.start)}),(0,k.jsxs)(`div`,{className:z.liveBody,children:[(0,k.jsx)(`span`,{className:z.liveTitle,children:t.summary}),t.location&&(0,k.jsx)(`span`,{className:z.liveSub,children:t.location})]})]},n))]}),i.length>0&&(0,k.jsxs)(`div`,{className:z.liveCard,children:[(0,k.jsxs)(`div`,{className:z.liveHdr,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📧 `,t(`email.inbox`)]}),(0,k.jsx)(`span`,{className:z.liveMore,children:`→`})]}),i.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:`${z.liveRow} ${t.isUnread?z.liveUnread:``}`,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:z.liveTime,children:ct(t.date)}),(0,k.jsxs)(`div`,{className:z.liveBody,children:[(0,k.jsx)(`span`,{className:z.liveTitle,children:t.subject}),(0,k.jsx)(`span`,{className:z.liveSub,children:t.from})]})]},n))]}),m.length>0&&(0,k.jsxs)(`div`,{className:z.liveCard,children:[(0,k.jsxs)(`div`,{className:z.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:z.liveMore,children:`→`})]}),m.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:z.liveRow,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:`${z.prio} ${z[`prio_`+t.priority]}`,children:t.priority[0].toUpperCase()}),(0,k.jsx)(`div`,{className:z.liveBody,children:(0,k.jsx)(`span`,{className:z.liveTitle,children:t.description})})]},n))]})]}),(0,k.jsx)(`div`,{className:z.launcher,children:b.map(t=>(0,k.jsxs)(`div`,{className:z.launchGroup,children:[(0,k.jsx)(`div`,{className:z.launchGroupLabel,children:t}),(0,k.jsx)(`div`,{className:z.launchTiles,children:at.filter(e=>e.group===t).map(t=>(0,k.jsxs)(`button`,{className:z.tile,onClick:()=>e(t.view),style:{"--tc":t.color},children:[(0,k.jsx)(`span`,{className:z.tileIcon,children:t.icon}),(0,k.jsx)(`span`,{className:z.tileLabel,children:t.label})]},t.view))})]},t))})]})}var ut={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 dt(){let e=M(),[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:ut.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:ut.root,children:[(0,k.jsxs)(`div`,{className:ut.bar,children:[(0,k.jsx)(`input`,{ref:d,className:ut.input,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>e.key===`Enter`&&p(),placeholder:e(`tasks.newTask`)}),(0,k.jsxs)(`select`,{className:ut.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:ut.addBtn,onClick:p,disabled:l||!a.trim(),children:l?`…`:`+ `+e(`common.add`)})]}),t.length>0&&(0,k.jsxs)(`div`,{className:ut.actions,children:[(0,k.jsx)(`button`,{className:ut.clearDone,onClick:g,children:`Clear completed`}),(0,k.jsx)(`button`,{className:ut.clearAll,onClick:v,children:`Clear all`})]}),t.length>0&&(0,k.jsxs)(`div`,{className:ut.stats,children:[y.length,` pending · `,b.length,` done`,t.length>0&&(0,k.jsx)(`span`,{className:ut.progress,children:(0,k.jsx)(`span`,{className:ut.progressBar,style:{width:`${Math.round(b.length/t.length*100)}%`}})})]}),y.length===0&&b.length===0&&(0,k.jsx)(`div`,{className:ut.empty,children:`No tasks yet. Add one above ↑`}),y.map(e=>(0,k.jsxs)(`div`,{className:ut.task,children:[(0,k.jsx)(`span`,{className:ut.check,onClick:()=>m(e.id)}),(0,k.jsx)(`span`,{className:ut.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${ut.badge} ${ut[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:ut.del,onClick:()=>h(e.id),children:`×`})]},e.id)),b.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:ut.doneLabel,children:`Completed`}),b.map(e=>(0,k.jsxs)(`div`,{className:`${ut.task} ${ut.taskDone}`,children:[(0,k.jsx)(`span`,{className:`${ut.check} ${ut.checkDone}`,onClick:()=>m(e.id),children:`✓`}),(0,k.jsx)(`span`,{className:ut.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${ut.badge} ${ut[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:ut.del,onClick:()=>h(e.id),children:`×`})]},e.id))]})]})}var B={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`},ft={id:``,display_name:``,email_address:``,from_name:``,imap_host:``,imap_port:`993`,smtp_host:``,smtp_port:`587`,username:``,password:``};function pt({id:e,label:t,placeholder:n,value:r,onChange:i,type:a=`text`}){return(0,k.jsxs)(`div`,{className:B.field,children:[(0,k.jsx)(`label`,{className:B.fieldLabel,children:t}),(0,k.jsx)(`input`,{id:e,type:a,placeholder:n,value:r,onChange:e=>i(e.target.value),className:B.fieldInput})]})}function mt(){let{setConfig:e}=ne(),t=M(),[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,ce]=(0,_.useState)(`30`),[le,ue]=(0,_.useState)(`off`),[N,de]=(0,_.useState)(``),[fe,pe]=(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`),ce(String(t?.meetingAlert??`30`)),ue(t?.thinking??`off`),te(``),a(!1),t&&e(t)}),me()},[]);let me=()=>E(`/api/imap/accounts`).then(e=>d(e?.accounts??[])),P=async(e,t)=>{s(e),await D(`/api/config`,{key:e,value:t}),l(e),s(null),setTimeout(()=>l(null),2e3)},he=()=>P(`profile`,x),ge=()=>{P(`provider`,C),P(`model`,T),P(`thinking`,le),ee&&P(`key`,ee)},_e=()=>{P(`planTime`,ae),P(`summaryTime`,j),P(`meetingAlert`,Number(se))},ve=()=>{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))},F=()=>{confirm(t(`settings.disconnectGoogleConfirm`))&&D(`/api/google/revoke`,{}).then(()=>{r(e=>({...e,hasGoogle:!1})),v(t(`common.disconnected`))})},ye=()=>{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),me()):h(`Error: `+(e?.error??`Unknown error`))}).catch(e=>h(`Error: `+e.message))},be=(e,n)=>{confirm(t(`settings.imapDelete`,{name:n}))&&D(`/api/imap/accounts/delete`,{id:e}).then(()=>me())},xe=e=>{D(`/api/imap/sync`,{accountId:e}).then(()=>setTimeout(me,3e3))};if(i)return(0,k.jsxs)(`div`,{className:B.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),t(`common.loading`)]});let I=e=>t(o===e?`common.saving`:c===e?`common.saved`:`common.save`);return(0,k.jsxs)(`div`,{className:B.root,children:[(0,k.jsxs)(`div`,{className:B.card,children:[(0,k.jsx)(`div`,{className:B.cardTitle,children:t(`settings.profile`)}),(0,k.jsx)(`div`,{className:B.cardSub,children:t(`settings.profileSub`)}),(0,k.jsx)(`div`,{className:B.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)(pt,{id:e,label:t,placeholder:n,value:x[e],onChange:t=>S(n=>({...n,[e]:t}))},e))}),(0,k.jsxs)(`button`,{className:B.saveBtn,onClick:he,children:[I(`profile`),` `,t(`settings.saveProfile`)]})]}),(0,k.jsxs)(`div`,{className:B.nhaFree,children:[(0,k.jsx)(`div`,{className:B.nhaFreeTitle,children:t(`settings.nhaFreeTitle`)}),(0,k.jsx)(`div`,{className:B.nhaFreeSub,children:t(`settings.nhaFreeSub`)}),(0,k.jsx)(`button`,{className:B.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:B.card,children:[(0,k.jsx)(`div`,{className:B.cardTitle,children:t(`settings.llmProvider`)}),(0,k.jsx)(`div`,{className:B.cardSub,children:t(`settings.llmProviderSub`)}),(0,k.jsxs)(`div`,{className:B.field,children:[(0,k.jsx)(`label`,{className:B.fieldLabel,children:t(`settings.provider`)}),(0,k.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),className:B.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:B.keySet,children:t(`settings.apiKeySet`)}):null),(0,k.jsx)(pt,{id:`apiKey`,label:t(`settings.apiKey`),placeholder:t(C===`nha`?`settings.apiKeyFreeNote`:`settings.apiKeyPh`),type:`password`,value:ee,onChange:te}),(0,k.jsx)(pt,{id:`model`,label:t(`settings.model`),placeholder:t(`settings.modelPh`),value:T,onChange:re}),(0,k.jsxs)(`div`,{className:B.field,children:[(0,k.jsx)(`label`,{className:B.fieldLabel,children:t(`settings.thinking`)}),(0,k.jsxs)(`select`,{value:le,onChange:e=>ue(e.target.value),className:B.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:B.saveBtn,onClick:ge,children:[I(`provider`),` `,t(`settings.saveProvider`)]})]}),(0,k.jsxs)(`div`,{className:B.card,children:[(0,k.jsx)(`div`,{className:B.cardTitle,children:t(`settings.language`)}),(0,k.jsxs)(`div`,{className:B.field,children:[(0,k.jsx)(`label`,{className:B.fieldLabel,children:t(`settings.languageLabel`)}),(0,k.jsx)(`select`,{value:ie,onChange:t=>{let r=t.target.value;O(r),P(`lang`,r),e({...n,lang:r})},className:B.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:B.card,children:[(0,k.jsx)(`div`,{className:B.cardTitle,children:t(`settings.telegram`)}),(0,k.jsx)(`div`,{className:B.cardSub,children:t(`settings.telegramSub`)}),n.hasTelegram&&(0,k.jsxs)(`div`,{className:B.connected,children:[`Telegram: `,t(`common.connected`)]}),n.hasDiscord&&(0,k.jsxs)(`div`,{className:B.connected,children:[`Discord: `,t(`common.connected`)]}),(0,k.jsx)(pt,{id:`tgToken`,label:t(`settings.telegramToken`),placeholder:n.hasTelegram?t(`settings.telegramSet`):t(`settings.telegramPh`),type:`password`,value:N,onChange:de}),(0,k.jsx)(pt,{id:`discordToken`,label:t(`settings.discordToken`),placeholder:n.hasDiscord?t(`settings.discordSet`):t(`settings.discordPh`),type:`password`,value:fe,onChange:pe}),(0,k.jsxs)(`button`,{className:B.saveBtn,onClick:()=>{N&&P(`telegram-bot-token`,N),fe&&P(`discord-bot-token`,fe)},children:[I(`telegram-bot-token`),` `,t(`settings.saveBots`)]})]}),(0,k.jsxs)(`div`,{className:B.card,children:[(0,k.jsx)(`div`,{className:B.cardTitle,children:t(`settings.dailyOps`)}),(0,k.jsx)(pt,{id:`planTime`,label:t(`settings.planTime`),placeholder:`07:00`,value:ae,onChange:A}),(0,k.jsx)(pt,{id:`summaryTime`,label:t(`settings.summaryTime`),placeholder:`18:00`,value:j,onChange:oe}),(0,k.jsx)(pt,{id:`meetingAlert`,label:t(`settings.meetingAlert`),placeholder:`30`,value:se,onChange:ce}),(0,k.jsxs)(`button`,{className:B.saveBtn,onClick:_e,children:[I(`planTime`),` `,t(`settings.saveSchedule`)]})]}),(0,k.jsxs)(`div`,{className:B.card,children:[(0,k.jsx)(`div`,{className:B.cardTitle,children:t(`settings.googleAccount`)}),(0,k.jsx)(`div`,{className:B.cardSub,children:t(`settings.googleSub`)}),n.hasGoogle&&(0,k.jsxs)(`div`,{className:B.connected,children:[`✅ `,t(`common.connected`),n.googleEmail?` · ${n.googleEmail}`:``]}),(0,k.jsxs)(`div`,{className:B.btnRow,children:[(0,k.jsx)(`button`,{className:B.saveBtn,onClick:ve,children:n.hasGoogle?t(`settings.reconnectGoogle`):t(`settings.connectGoogle`)}),n.hasGoogle&&(0,k.jsx)(`button`,{className:B.dangerBtn,onClick:F,children:t(`settings.disconnectGoogle`)})]}),g&&(0,k.jsx)(`div`,{className:B.statusMsg,children:g})]}),(0,k.jsxs)(`div`,{className:B.card,children:[(0,k.jsxs)(`div`,{className:B.cardTitleRow,children:[(0,k.jsx)(`div`,{className:B.cardTitle,children:t(`settings.imapAccounts`)}),(0,k.jsx)(`button`,{className:B.saveBtn,onClick:()=>{p({...ft}),h(``)},children:t(`settings.addAccount`)})]}),(0,k.jsx)(`div`,{className:B.cardSub,children:t(`settings.imapSub`)}),u.length===0&&!f&&(0,k.jsx)(`div`,{className:B.emptyImap,children:t(`settings.noImapAccounts`)}),u.map(e=>(0,k.jsxs)(`div`,{className:B.imapRow,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:B.imapName,children:e.display_name}),(0,k.jsxs)(`div`,{className:B.imapMeta,children:[e.email_address,` · `,e.imap_host]}),(0,k.jsxs)(`div`,{className:B.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:B.imapBtns,children:[(0,k.jsx)(`button`,{className:B.imapSyncBtn,onClick:()=>xe(e.id),children:t(`settings.sync`)}),(0,k.jsx)(`button`,{className:B.imapEditBtn,onClick:()=>{p({...ft,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:B.imapDelBtn,onClick:()=>be(e.id,e.display_name),children:t(`common.delete`)})]})]},e.id)),f&&(0,k.jsxs)(`div`,{className:B.imapForm,children:[(0,k.jsx)(`div`,{className:B.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)(pt,{id:`imap_${e}`,label:t,placeholder:n,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t})},e)),(0,k.jsxs)(`div`,{className:B.field,children:[(0,k.jsxs)(`label`,{className:B.fieldLabel,children:[t(`settings.password`),` `,f.id&&(0,k.jsx)(`span`,{className:B.pwdNote,children:t(`settings.passwordKeep`)})]}),(0,k.jsxs)(`div`,{className:B.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:B.fieldInput,style:{flex:1}}),(0,k.jsx)(`button`,{className:B.togglePwd,onClick:()=>b(e=>!e),children:t(y?`settings.hide`:`settings.show`)})]})]}),(0,k.jsxs)(`div`,{className:B.btnRow,children:[(0,k.jsx)(`button`,{className:B.saveBtn,onClick:ye,children:t(`common.save`)}),(0,k.jsx)(`button`,{className:B.cancelBtn,onClick:()=>p(null),children:t(`common.cancel`)})]}),m&&(0,k.jsx)(`div`,{className:B.statusMsg,children:m})]})]})]})}var ht={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 gt(){let e=M(),[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:ht.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):a?(0,k.jsx)(`div`,{className:ht.err,children:a}):(0,k.jsxs)(`div`,{className:ht.root,children:[(0,k.jsxs)(`div`,{className:ht.header,children:[(0,k.jsx)(`div`,{className:ht.title,children:`Upcoming Birthdays`}),(0,k.jsx)(`button`,{className:ht.addBtn,onClick:m,children:`+ Add Birthday`})]}),t.length===0&&(0,k.jsxs)(`div`,{className:ht.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:`${ht.card} ${r?ht.cardToday:``}`,children:[(0,k.jsx)(`span`,{className:ht.icon,children:`🎂`}),(0,k.jsxs)(`div`,{className:ht.info,children:[(0,k.jsx)(`div`,{className:ht.name,children:t.name}),(0,k.jsx)(`div`,{className:ht.date,children:t.date})]}),(0,k.jsx)(`div`,{className:r?ht.labelToday:i?ht.labelTomorrow:ht.labelFuture,children:r?`TODAY!`:i?`Tomorrow`:`in ${t.daysUntil} days`}),t.contactId&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:ht.editBtn,onClick:()=>h(t),children:e(`common.edit`)}),(0,k.jsx)(`button`,{className:ht.delBtn,onClick:()=>v(t),children:e(`common.delete`)})]})]},n)}),s&&(0,k.jsx)(`div`,{className:ht.overlay,onClick:e=>{e.target===e.currentTarget&&c(null)},children:(0,k.jsxs)(`div`,{className:ht.modal,children:[(0,k.jsx)(`div`,{className:ht.modalTitle,children:s.contactId?`Edit Birthday`:`Add Birthday`}),(0,k.jsx)(`label`,{className:ht.label,children:`Name *`}),(0,k.jsx)(`input`,{className:ht.input,value:s.name,onChange:e=>c(t=>t&&{...t,name:e.target.value}),placeholder:`Contact name`}),(0,k.jsx)(`label`,{className:ht.label,children:`Birthday (MM-DD or YYYY-MM-DD)`}),(0,k.jsx)(`input`,{className:ht.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:ht.hint,children:`Birthday will be saved as a Google Calendar event.`}),l&&(0,k.jsx)(`div`,{className:ht.formErr,children:l}),(0,k.jsxs)(`div`,{className:ht.modalBtns,children:[(0,k.jsx)(`button`,{className:ht.cancelBtn,onClick:()=>c(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:ht.saveBtn,onClick:g,disabled:d,children:d?`Saving…`:s.contactId?`Save`:`Add`})]})]})})]})}var V={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`},_t=[{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`}],vt=[{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.`}],yt=[{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 bt(){let e=M(),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:V.root,children:[(0,k.jsxs)(`div`,{className:V.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:V.title,children:`⏰ Scheduled Tasks`}),(0,k.jsxs)(`div`,{className:V.subtitle,children:[`Automate agents on a recurring schedule. Daemon must be running: `,(0,k.jsx)(`code`,{className:V.code,children:`nha ops start`})]})]}),(0,k.jsx)(`button`,{className:V.addBtn,onClick:w,children:`+ New Task`})]}),(0,k.jsxs)(`div`,{className:V.tabs,children:[(0,k.jsxs)(`button`,{className:`${V.tab} ${x===`jobs`?V.tabActive:``}`,onClick:()=>S(`jobs`),children:[`Jobs (`,n.length,`)`]}),(0,k.jsx)(`button`,{className:`${V.tab} ${x===`templates`?V.tabActive:``}`,onClick:()=>S(`templates`),children:`Templates`})]}),x===`templates`&&(0,k.jsxs)(`div`,{className:V.templates,children:[(0,k.jsx)(`div`,{className:V.templatesNote,children:`Click a template to pre-fill the job form or run it immediately in Chat.`}),vt.map(t=>(0,k.jsxs)(`div`,{className:V.templateCard,children:[(0,k.jsx)(`div`,{className:V.templateLabel,children:t.label}),(0,k.jsx)(`div`,{className:V.templatePrompt,children:t.prompt}),(0,k.jsxs)(`div`,{className:V.templateBtns,children:[(0,k.jsx)(`button`,{className:V.scheduleTplBtn,onClick:()=>O(t),children:`Schedule`}),(0,k.jsxs)(`button`,{className:V.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:V.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading jobs…`]}),o&&(0,k.jsx)(`div`,{className:V.err,children:o}),!i&&n.length===0&&!c&&(0,k.jsxs)(`div`,{className:V.empty,children:[(0,k.jsx)(`div`,{className:V.emptyIcon,children:`⏰`}),(0,k.jsxs)(`div`,{className:V.emptyTitle,children:[e(`cron.noJobs`),` tasks`]}),(0,k.jsx)(`div`,{className:V.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:V.addBtn,onClick:w,children:`+ New Task`})]}),n.map(e=>(0,k.jsxs)(`div`,{className:`${V.card} ${e.enabled?``:V.cardDisabled}`,children:[(0,k.jsxs)(`div`,{className:V.cardTop,children:[(0,k.jsxs)(`div`,{className:V.cardLeft,children:[e.name&&(0,k.jsx)(`div`,{className:V.jobName,children:e.name}),(0,k.jsx)(`code`,{className:V.schedule,children:e.schedule}),e.agent&&(0,k.jsx)(`span`,{className:V.agentBadge,children:e.agent}),(0,k.jsx)(`span`,{className:`${V.statusBadge} ${e.enabled?V.statusActive:V.statusPaused}`,children:e.enabled?`active`:`paused`})]}),(0,k.jsxs)(`div`,{className:V.cardActions,children:[(0,k.jsx)(`button`,{className:V.runBtn,onClick:()=>ie(e.prompt??e.command??``),title:`Run now in Chat`,children:`▶`}),(0,k.jsx)(`button`,{className:V.editBtn,onClick:()=>ee(e),children:`Edit`}),(0,k.jsx)(`button`,{className:e.enabled?V.pauseBtn:V.resumeBtn,onClick:()=>T(e.id,e.enabled),children:e.enabled?`Pause`:`Resume`}),(0,k.jsx)(`button`,{className:V.delBtn,onClick:()=>re(e.id),children:`✕`})]})]}),(0,k.jsx)(`div`,{className:V.jobPrompt,children:e.prompt??e.command}),(0,k.jsxs)(`div`,{className:V.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:V.formOverlay,onClick:e=>{e.target===e.currentTarget&&l(!1)},children:(0,k.jsxs)(`div`,{className:V.formModal,children:[(0,k.jsx)(`div`,{className:V.formTitle,children:y?`Edit Scheduled Task`:`New Scheduled Task`}),(0,k.jsx)(`label`,{className:V.label,children:`Name (optional)`}),(0,k.jsx)(`input`,{className:V.input,value:u.name,onChange:e=>d(t=>({...t,name:e.target.value})),placeholder:`e.g. Morning Briefing`}),(0,k.jsx)(`label`,{className:V.label,children:`Schedule *`}),(0,k.jsx)(`div`,{className:V.presets,children:_t.map(e=>(0,k.jsx)(`button`,{className:`${V.preset} ${u.schedule===e.value?V.presetActive:``}`,onClick:()=>d(t=>({...t,schedule:e.value})),children:e.label},e.value))}),(0,k.jsx)(`input`,{className:V.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:V.cronHints,children:yt.map(e=>(0,k.jsxs)(`span`,{className:V.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:V.label,children:`Task / Prompt *`}),(0,k.jsx)(`textarea`,{className:V.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:V.label,children:`Agent (optional — leave blank for auto-routing)`}),(0,k.jsx)(`input`,{className:V.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:V.formErr,children:m}),g&&(0,k.jsx)(`div`,{className:V.formOk,children:g}),(0,k.jsxs)(`div`,{className:V.formBtns,children:[(0,k.jsx)(`button`,{className:V.cancelBtn,onClick:()=>l(!1),children:`Cancel`}),(0,k.jsx)(`button`,{className:V.saveBtn,onClick:te,disabled:f,children:f?`Saving…`:y?`Update`:`Schedule`})]})]})})]})}var xt={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 St(){let e=M(),[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:xt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:xt.root,children:[(0,k.jsxs)(`div`,{className:xt.sidebar,children:[(0,k.jsx)(`button`,{className:xt.newBtn,onClick:v,children:`+ New Note`}),t.length===0&&(0,k.jsx)(`div`,{className:xt.empty,children:e(`notes.noNotes`)}),t.map(e=>(0,k.jsxs)(`div`,{className:`${xt.noteItem} ${a?.id===e.id?xt.noteItemActive:``}`,onClick:()=>g(e),children:[(0,k.jsx)(`div`,{className:xt.noteTitle,children:e.title||`Untitled`}),(0,k.jsx)(`div`,{className:xt.noteMeta,children:e.updatedAt?new Date(e.updatedAt).toLocaleDateString():``}),e.content&&(0,k.jsx)(`div`,{className:xt.notePreview,children:e.content.slice(0,150)}),e.tags&&e.tags.length>0&&(0,k.jsx)(`div`,{className:xt.noteTags,children:e.tags.map(e=>(0,k.jsx)(`span`,{className:xt.noteTag,children:e},e))})]},e.id))]}),(0,k.jsx)(`div`,{className:xt.editor,children:a||p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`input`,{className:xt.titleInput,value:s,onChange:e=>c(e.target.value),placeholder:`Note title…`}),(0,k.jsx)(`textarea`,{className:xt.contentArea,value:l,onChange:e=>u(e.target.value),placeholder:`Start writing…`}),(0,k.jsxs)(`div`,{className:xt.editorFooter,children:[a&&(0,k.jsx)(`button`,{className:xt.delNoteBtn,onClick:()=>b(a.id,a.title),children:e(`common.delete`)}),(0,k.jsx)(`button`,{className:xt.cancelBtn,onClick:()=>{o(null),m(!1)},children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:xt.saveBtn,onClick:y,disabled:d,children:d?`Saving…`:`Save`})]})]}):(0,k.jsx)(`div`,{className:xt.emptyEditor,children:`Select a note or create a new one`})})]})}var Ct={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`},wt={name:``,email:``,phone:``,company:``,address:``,notes:``};function Tt(){let e=M(),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({...wt}),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:Ct.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading contacts…`]}):o?(0,k.jsx)(`div`,{className:Ct.error,children:o}):(0,k.jsxs)(`div`,{className:Ct.root,children:[(0,k.jsxs)(`div`,{className:Ct.toolbar,children:[(0,k.jsx)(`input`,{className:Ct.search,value:c,onChange:e=>x(e.target.value),placeholder:`Search contacts…`}),n.length>0&&(0,k.jsxs)(`span`,{className:Ct.count,children:[n.length,` contact`,n.length===1?``:`s`]}),(0,k.jsx)(`button`,{className:Ct.addBtn,onClick:S,children:`+ Add`})]}),n.length===0&&(0,k.jsxs)(`div`,{className:Ct.empty,children:[e(`contacts.noContacts`),(0,k.jsx)(`br`,{}),`Add a Google account or add contacts manually.`]}),(0,k.jsx)(`div`,{className:Ct.grid,children:n.map(e=>(0,k.jsxs)(`div`,{className:Ct.card,onClick:()=>C(e),children:[(0,k.jsx)(`div`,{className:Ct.avatar,children:e.photo?(0,k.jsx)(`img`,{src:e.photo,alt:e.name,className:Ct.avatarImg}):T(e.name)}),(0,k.jsxs)(`div`,{className:Ct.info,children:[(0,k.jsx)(`div`,{className:Ct.name,children:e.name||`(no name)`}),(0,k.jsxs)(`div`,{className:Ct.row,children:[e.email&&(0,k.jsx)(`span`,{className:Ct.email,children:e.email}),e.phone&&(0,k.jsx)(`span`,{className:Ct.phone,children:e.phone}),e.company&&(0,k.jsxs)(`span`,{className:Ct.company,children:[e.company,e.title?` · ${e.title}`:``]}),e.birthday&&(0,k.jsxs)(`span`,{className:Ct.birthday,children:[`🎂 `,e.birthday]})]})]}),(0,k.jsxs)(`div`,{className:Ct.actions,children:[e.email&&(0,k.jsx)(`button`,{className:Ct.iconBtn,onClick:t=>te(t,e.email,e.name),title:`Send email via chat`,children:`✉`}),(0,k.jsx)(`button`,{className:Ct.iconBtn,onClick:t=>{t.stopPropagation(),C(e)},title:`Edit`,children:`✎`}),(0,k.jsx)(`button`,{className:`${Ct.iconBtn} ${Ct.iconBtnRed}`,onClick:t=>ee(t,e),title:`Delete`,children:`✕`})]})]},e.id))}),f&&(0,k.jsx)(`div`,{className:Ct.overlay,onClick:e=>{e.target===e.currentTarget&&p(null)},children:(0,k.jsxs)(`div`,{className:Ct.modal,children:[(0,k.jsx)(`div`,{className:Ct.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:Ct.field,children:[(0,k.jsx)(`label`,{className:Ct.label,children:t}),(0,k.jsx)(`input`,{className:Ct.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`)?Ct.formError:Ct.formStatus,children:g}),(0,k.jsxs)(`div`,{className:Ct.modalBtns,children:[(0,k.jsx)(`button`,{className:Ct.cancelBtn,onClick:()=>p(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:Ct.saveBtn,onClick:w,disabled:m||!f.name,children:m?`…`:`Save`})]})]})})]})}var H={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`},Et=[{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}}`}]}],Dt=Object.fromEntries(Et.map(e=>[e.id,e])),Ot=90,kt=72;function At(){return`n_${Date.now()}_${Math.random().toString(36).slice(2,6)}`}function jt(e,t){return{x:e.x+(t===`out`?Ot:0),y:e.y+kt/2}}function Mt(){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:Et},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-Ot/2)/20)*20,o=Math.round((e.clientY-r.top-kt/2)/20)*20,s={id:At(),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:Et};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?Dt[j.defId]:null;return(0,k.jsxs)(`div`,{className:H.root,children:[(0,k.jsxs)(`div`,{className:H.topbar,children:[(0,k.jsxs)(`div`,{className:H.topbarLeft,children:[(0,k.jsx)(`span`,{className:H.topbarTitle,children:`Connectors`}),(0,k.jsx)(`span`,{className:H.topbarSub,children:`Visual workflow automation · 80 tools · 38 AI agents · free AI via Liara`})]}),(0,k.jsxs)(`div`,{className:H.topbarActions,children:[n&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:`${H.runBtn} ${c?H.runBtnActive:``}`,onClick:ae,disabled:c||n.nodes.length===0,children:c?`⏳ Running…`:`▶ Run`}),(0,k.jsx)(`button`,{className:H.logBtn,onClick:()=>p(e=>!e),children:f?`Hide Log`:`📋 Log`})]}),(0,k.jsx)(`button`,{className:H.newWfBtn,onClick:S,children:`+ New Workflow`})]})]}),(0,k.jsxs)(`div`,{className:H.body,children:[(0,k.jsxs)(`div`,{className:H.sidebar,children:[(0,k.jsx)(`div`,{className:H.sidebarTitle,children:`Workflows`}),e.length===0&&(0,k.jsxs)(`div`,{className:H.sidebarEmpty,children:[`No workflows yet.`,(0,k.jsx)(`br`,{}),`Click "New Workflow" to start.`]}),e.map(e=>(0,k.jsxs)(`div`,{className:`${H.wfItem} ${n?.id===e.id?H.wfItemActive:``}`,onClick:()=>{r(e),a(null),d(e.lastRun?.steps??[]),p(!1)},children:[(0,k.jsxs)(`div`,{className:H.wfItemRow,children:[(0,k.jsx)(`span`,{className:H.wfItemName,children:e.name}),(0,k.jsx)(`button`,{className:e.enabled?H.wfOn:H.wfOff,onClick:t=>{t.stopPropagation(),A(e)},children:e.enabled?`ON`:`OFF`})]}),(0,k.jsxs)(`div`,{className:H.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:H.wfDelBtn,onClick:t=>{t.stopPropagation(),C(e.id)},children:`✕`})]},e.id))]}),(0,k.jsx)(`div`,{className:H.canvasArea,children:n?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:H.canvasHeader,children:[(0,k.jsx)(`input`,{className:H.wfNameInput,value:n.name,onChange:e=>r(t=>t&&{...t,name:e.target.value}),onBlur:()=>n&&x(n)}),o?(0,k.jsxs)(`span`,{className:H.connectHint,children:[`Click a target node to connect · `,(0,k.jsx)(`button`,{className:H.cancelConnectBtn,onClick:()=>s(null),children:`Cancel`})]}):(0,k.jsxs)(`span`,{className:H.canvasHint,children:[`Drag nodes from palette · Click `,(0,k.jsx)(`span`,{className:H.portHint,children:`▶`}),` to connect · Drag nodes to reposition`]})]}),(0,k.jsxs)(`div`,{ref:y,className:`${H.canvas} ${o?H.canvasConnecting:``}`,onMouseMove:te,onMouseUp:ne,onMouseLeave:ne,onDragOver:e=>e.preventDefault(),onDrop:w,onClick:()=>{o||a(null)},children:[(0,k.jsx)(`svg`,{className:H.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=jt(r,`out`),o=jt(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=Dt[e.defId];if(!t)return null;let n=i===e.id,r=o===e.id;return(0,k.jsxs)(`div`,{className:`${H.canvasNode} ${n?H.canvasNodeSelected:``} ${r?H.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:H.nodeDelBtn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),T(e.id)},children:`✕`}),(0,k.jsx)(`span`,{className:H.nodeIcon,children:t.icon}),(0,k.jsx)(`span`,{className:H.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:H.nodeConfigPreview,children:String(e).slice(0,14)},t)),(0,k.jsx)(`button`,{className:`${H.portOut} ${r?H.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:H.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:H.canvasDrop,children:`Drag nodes from the right panel and drop here`})]}),f&&(0,k.jsxs)(`div`,{className:H.logPanel,children:[(0,k.jsxs)(`div`,{className:H.logHeader,children:[(0,k.jsx)(`span`,{children:`Run Log`}),n.lastRun&&(0,k.jsx)(`span`,{className:H.logTime,children:new Date(n.lastRun.at).toLocaleString()}),(0,k.jsx)(`button`,{className:H.logClose,onClick:()=>p(!1),children:`✕`})]}),u.length===0&&(0,k.jsx)(`div`,{className:H.logEmpty,children:c?`Running…`:`No run results yet.`}),u.map((e,t)=>(0,k.jsxs)(`div`,{className:`${H.logStep} ${e.error?H.logStepError:``}`,children:[(0,k.jsxs)(`div`,{className:H.logStepHeader,children:[(0,k.jsx)(`span`,{className:H.logStepIcon,children:e.nodeIcon}),(0,k.jsx)(`span`,{className:H.logStepLabel,children:e.nodeLabel}),e.error&&(0,k.jsx)(`span`,{className:H.logStepErrBadge,children:`ERROR`})]}),e.error&&(0,k.jsx)(`div`,{className:H.logStepErr,children:e.error}),e.output&&(0,k.jsx)(`div`,{className:H.logStepOutput,dangerouslySetInnerHTML:{__html:me(e.output.slice(0,500))}})]},t))]})]}):(0,k.jsxs)(`div`,{className:H.canvasEmpty,children:[(0,k.jsx)(`div`,{className:H.canvasEmptyIcon,children:`🔗`}),(0,k.jsx)(`div`,{className:H.canvasEmptyTitle,children:`Select or create a workflow`}),(0,k.jsxs)(`div`,{className:H.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:H.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:H.newWfBtn,onClick:S,children:`+ New Workflow`})]})}),(0,k.jsx)(`div`,{className:H.rightPanel,children:j&&oe?(0,k.jsxs)(`div`,{className:H.configPanel,children:[(0,k.jsxs)(`div`,{className:H.configHeader,children:[(0,k.jsxs)(`span`,{style:{color:oe.color},children:[oe.icon,` `,oe.label]}),(0,k.jsx)(`button`,{className:H.configClose,onClick:()=>a(null),children:`✕`})]}),(0,k.jsx)(`div`,{className:H.configDesc,children:oe.description}),(0,k.jsx)(`div`,{className:H.configFields,children:(oe.configFields??[]).map(e=>(0,k.jsxs)(`div`,{className:H.configField,children:[(0,k.jsxs)(`label`,{className:H.configLabel,children:[e.label,e.required&&(0,k.jsx)(`span`,{className:H.configRequired,children:`*`})]}),(0,k.jsx)(`input`,{className:H.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:H.configHint,children:[`Use `,(0,k.jsx)(`code`,{children:`{{output}}`}),` to pass previous node result`]})]},e.key))}),(0,k.jsx)(`button`,{className:H.configDelete,onClick:()=>T(j.id),children:`Delete node`})]}):(0,k.jsxs)(`div`,{className:H.palette,children:[(0,k.jsx)(`div`,{className:H.paletteTitle,children:`Node Palette`}),(0,k.jsx)(`div`,{className:H.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:`${H.paletteTab} ${m===e.id?H.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:H.paletteNodes,children:Et.filter(e=>e.type===m).map(e=>(0,k.jsxs)(`div`,{className:H.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:H.paletteDefIcon,children:e.icon}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:H.paletteDefLabel,style:{color:e.color},children:e.label}),(0,k.jsx)(`div`,{className:H.paletteDefDesc,children:e.description})]})]},e.id))}),(0,k.jsxs)(`div`,{className:H.paletteGuide,children:[(0,k.jsx)(`div`,{className:H.guideTitle,children:`How to use Connectors`}),(0,k.jsxs)(`div`,{className:H.guideStep,children:[(0,k.jsx)(`span`,{className:H.guideNum,children:`1`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Create`}),` a workflow with "+ New Workflow"`]})]}),(0,k.jsxs)(`div`,{className:H.guideStep,children:[(0,k.jsx)(`span`,{className:H.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:H.guideStep,children:[(0,k.jsx)(`span`,{className:H.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:H.guideStep,children:[(0,k.jsx)(`span`,{className:H.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:H.guideStep,children:[(0,k.jsx)(`span`,{className:H.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:H.guideCode,children:`{{output}}`}),` to pass the previous result`]})]}),(0,k.jsxs)(`div`,{className:H.guideStep,children:[(0,k.jsx)(`span`,{className:H.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:H.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:H.guideTip,children:[(0,k.jsx)(`strong`,{children:`AI nodes`}),` use Liara (free) by default. They receive `,(0,k.jsx)(`code`,{className:H.guideCode,children:`{{output}}`}),` from the previous step automatically.`]})]})]})})]})]})}var U={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`},Nt=[{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:`🗑`}],Pt=[{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 Ft(e){return e?e.slice(0,10):``}function It(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 Lt(){let e=M(),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,ce]=(0,_.useState)(!1),[le,ue]=(0,_.useState)({}),[N,de]=(0,_.useState)(``),[fe,pe]=(0,_.useState)(``),[me,P]=(0,_.useState)(``),[he,ge]=(0,_.useState)(``),[_e,ve]=(0,_.useState)(``),[F,ye]=(0,_.useState)(!1),[be,xe]=(0,_.useState)(``),[I,L]=(0,_.useState)(!1),Se=(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?Ce(t[0].id,`imap`):Ce(`google`,`google`)})},[]);let Ce=(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),we(e,r,0,``)}):(d([]),Te(`INBOX`,``))},we=(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))},Te=(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))},Ee=()=>{O(ae),b(0),h([]),c===`imap`&&o?we(o,f,0,ae):Te(f??`INBOX`,ae)},De=e=>{S(e),ce(!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))},Oe=(e={})=>{ce(!0),ue(e),de(e.to??``),pe(``),P(e.subject??``),ge(e.type===`forward`&&e.body?`\n\n---------- Forwarded message ----------\n${e.body}`:``),ve(``),ye(!1),S(null),w(null)},ke=async()=>{if(!N.trim()){ve(`Recipient required`);return}ve(`Sending…`);try{if(c===`imap`&&o){let e=await D(`/api/imap/send`,{accountId:o,to:N.trim(),cc:fe.trim()||void 0,subject:me.trim(),bodyHtml:he.replace(/\n/g,`<br>`),bodyText:he,inReplyTo:le.inReplyTo||void 0});e?.ok?(ve(`Sent!`),setTimeout(()=>ce(!1),800)):ve(e?.error??`Error`)}else{let e=await D(`/api/email/send`,{to:N.trim(),subject:me.trim(),body:he});e?.ok||e?.id?(ve(`Sent!`),setTimeout(()=>ce(!1),800)):ve(e?.error??`Error`)}}catch(e){ve(e.message??`Error`)}},Ae=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)})},je=(e,t)=>{D(`/api/imap/mark-starred`,{messageId:e,isStarred:t}).then(()=>{C?.id===e&&w(e=>e&&{...e,is_starred:t})})},R=(e,t)=>{t&&D(`/api/imap/labels/assign`,{messageId:e,labelId:t})},Me=()=>{!be.trim()||!o||D(`/api/imap/labels`,{accountId:o,name:be.trim()}).then(()=>{L(!1),xe(``),E(`/api/imap/labels?accountId=${o}`).then(e=>d(e?.labels??[]))})};return(0,k.jsxs)(`div`,{className:U.root,children:[(0,k.jsxs)(`div`,{className:U.sidebar,children:[(0,k.jsxs)(`div`,{className:U.sidebarSection,children:[(0,k.jsx)(`div`,{className:U.sidebarLabel,children:`Account`}),(0,k.jsxs)(`select`,{className:U.accountSelect,value:c===`google`?`google`:`imap:${o}`,onChange:e=>{let t=e.target.value;t===`google`?Ce(`google`,`google`):t.startsWith(`imap:`)&&Ce(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:U.sidebarCompose,children:(0,k.jsx)(`button`,{className:U.composeBtn,onClick:()=>Oe(),children:`+ Compose`})}),(0,k.jsx)(`div`,{className:U.folderList,children:c===`google`?Nt.map(e=>(0,k.jsxs)(`div`,{className:`${U.folderItem} ${f===e.id?U.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),Te(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:U.badge,children:j})]},e.id)):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:U.labelHeader,children:[(0,k.jsx)(`span`,{children:`Labels`}),(0,k.jsx)(`button`,{className:U.addLabelBtn,onClick:()=>L(e=>!e),children:`+`})]}),I&&(0,k.jsxs)(`div`,{className:U.newLabelRow,children:[(0,k.jsx)(`input`,{className:U.newLabelInput,value:be,onChange:e=>xe(e.target.value),placeholder:`Label name`,onKeyDown:e=>e.key===`Enter`&&Me()}),(0,k.jsx)(`button`,{className:U.newLabelSave,onClick:Me,children:`+`})]}),u.map(e=>(0,k.jsxs)(`div`,{className:`${U.folderItem} ${f===e.id?U.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),o&&we(o,e.id,0,ie)},children:[(0,k.jsx)(`span`,{className:U.labelDot,style:{background:e.color??`var(--dim)`}}),(0,k.jsx)(`span`,{children:e.name}),e.unread_count?(0,k.jsx)(`span`,{className:U.badge,children:e.unread_count}):null]},e.id))]})}),c===`imap`&&o&&(0,k.jsx)(`div`,{className:U.syncArea,children:(0,k.jsx)(`button`,{className:U.syncBtn,onClick:()=>{o&&c===`imap`&&D(`/api/imap/sync/${o}`,{})},children:`Sync now`})})]}),(0,k.jsxs)(`div`,{className:U.messageList,children:[(0,k.jsxs)(`div`,{className:U.listHeader,children:[(0,k.jsx)(`input`,{className:U.searchInput,value:ae,onChange:e=>A(e.target.value),placeholder:`Search…`,onKeyDown:e=>e.key===`Enter`&&Ee()}),(0,k.jsx)(`button`,{className:U.searchBtn,onClick:Ee,children:`Go`})]}),(0,k.jsxs)(`div`,{className:U.listBody,children:[ee&&(0,k.jsx)(`div`,{className:U.listLoading,children:(0,k.jsx)(`div`,{className:`spinner`})}),!ee&&m.length===0&&(0,k.jsx)(`div`,{className:U.noMessages,children:`No messages`}),m.map(e=>(0,k.jsxs)(`div`,{className:`${U.msgRow} ${e.id===x?U.msgActive:``} ${e.is_read?``:U.msgUnread}`,onClick:()=>De(e.id),children:[(0,k.jsxs)(`div`,{className:U.msgTop,children:[(0,k.jsx)(`span`,{className:U.msgFrom,children:e.from_name||e.from_address||``}),(0,k.jsx)(`span`,{className:U.msgDate,children:Ft(e.internal_date)})]}),(0,k.jsx)(`div`,{className:U.msgSubject,children:e.subject||`(no subject)`}),(0,k.jsx)(`div`,{className:U.msgPreview,children:(e.body_preview||``).slice(0,80)})]},e.id))]}),(0,k.jsxs)(`div`,{className:U.listFooter,children:[(0,k.jsxs)(`span`,{children:[g,` messages`]}),m.length<g&&c===`imap`&&(0,k.jsx)(`button`,{className:U.loadMoreBtn,onClick:()=>{let e=y+50;b(e),o&&we(o,f,e,ie)},children:`Load more`})]})]}),(0,k.jsx)(`div`,{className:U.pane,children:(()=>{if(se)return(0,k.jsxs)(`div`,{className:U.composePane,children:[(0,k.jsx)(`div`,{className:U.composeTitle,children:e(`email.compose`)}),(0,k.jsx)(`input`,{className:U.composeField,value:N,onChange:e=>de(e.target.value),placeholder:`To`}),(0,k.jsx)(`input`,{className:U.composeField,value:fe,onChange:e=>pe(e.target.value),placeholder:`Cc`}),(0,k.jsx)(`input`,{className:U.composeField,value:me,onChange:e=>P(e.target.value),placeholder:`Subject`}),(0,k.jsxs)(`div`,{className:U.templateRow,children:[(0,k.jsx)(`button`,{className:U.templateToggle,onClick:()=>ye(e=>!e),children:`📄 Templates`}),F&&(0,k.jsx)(`div`,{className:U.templateDrop,children:Pt.map((e,t)=>(0,k.jsxs)(`div`,{className:U.templateItem,onClick:()=>{P(t=>t||e.subject),ye(!1)},children:[(0,k.jsx)(`strong`,{children:e.name}),(0,k.jsx)(`div`,{className:U.templateSubject,children:e.subject})]},t))})]}),(0,k.jsx)(`textarea`,{className:U.composeBody,value:he,onChange:e=>ge(e.target.value),placeholder:`Write your message…`}),(0,k.jsxs)(`div`,{className:U.composeActions,children:[(0,k.jsx)(`button`,{className:U.sendBtn,onClick:ke,children:e(`email.send_ok`)}),(0,k.jsx)(`button`,{className:U.cancelBtn,onClick:()=>ce(!1),children:`Discard`}),_e&&(0,k.jsx)(`span`,{className:`${U.compStatus} ${_e===`Sent!`?U.ok:U.err}`,children:_e})]})]});if(T)return(0,k.jsx)(`div`,{className:U.emptyPane,children:(0,k.jsx)(`div`,{className:`spinner`})});if(!C)return(0,k.jsx)(`div`,{className:U.emptyPane,children:`Select a message`});let n=It(C.to_addresses);return(0,k.jsxs)(`div`,{className:U.readingPane,children:[(0,k.jsx)(`div`,{className:U.paneToolbar,children:(0,k.jsxs)(`div`,{className:U.paneActions,children:[(0,k.jsx)(`button`,{className:U.replyBtn,onClick:()=>Oe({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:U.fwdBtn,onClick:()=>Oe({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:U.trashBtn,onClick:()=>Ae(C.id),children:`🗑`}),(0,k.jsx)(`button`,{className:U.starBtn,onClick:()=>je(C.id,!C.is_starred),children:C.is_starred?`★`:`☆`}),u.length>0&&(0,k.jsxs)(`select`,{className:U.labelSelect,defaultValue:``,onChange:e=>R(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:U.aiBtn,onClick:()=>t(`chat`),children:`Ask AI`})]})}),(0,k.jsxs)(`div`,{className:U.paneHeader,children:[(0,k.jsx)(`div`,{className:U.paneSubject,children:C.subject||`(no subject)`}),(0,k.jsxs)(`div`,{className:U.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:U.paneMeta,children:[(0,k.jsx)(`strong`,{children:`To:`}),` `,n]}),(0,k.jsxs)(`div`,{className:U.paneMeta,children:[(0,k.jsx)(`strong`,{children:`Date:`}),` `,C.internal_date]}),C.attachments&&C.attachments.length>0&&(0,k.jsx)(`div`,{className:U.attachments,children:C.attachments.map((e,t)=>(0,k.jsxs)(`a`,{className:U.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:U.paneBody,children:C.body_html?(0,k.jsx)(`iframe`,{ref:Se,sandbox:`allow-same-origin`,className:U.bodyFrame,srcDoc:C.body_html,title:`Email body`}):(0,k.jsx)(`pre`,{className:U.bodyText,children:C.body_text??C.body_preview??`(empty)`})})]})})()})]})}var W={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 Rt(e,t,n){return`${e}-${String(t+1).padStart(2,`0`)}-${String(n).padStart(2,`0`)}`}function zt(e,t,n){let r=new Date;return r.getFullYear()===e&&r.getMonth()===t&&r.getDate()===n}function Bt(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 Vt(){let e=M(),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:W.center,children:(0,k.jsx)(`div`,{className:`spinner`})});if(!n)return(0,k.jsx)(`div`,{className:W.center,children:(0,k.jsxs)(`div`,{className:W.noGoogle,children:[(0,k.jsx)(`div`,{className:W.noGoogleIcon,children:`📅`}),(0,k.jsx)(`div`,{className:W.noGoogleTitle,children:`Calendar`}),(0,k.jsx)(`div`,{className:W.noGoogleSub,children:`Connect your Google account to view and manage calendar events.`}),(0,k.jsx)(`button`,{className:W.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:W.root,children:[(0,k.jsxs)(`div`,{className:W.calCol,children:[(0,k.jsxs)(`div`,{className:W.navRow,children:[(0,k.jsx)(`button`,{className:W.navBtn,onClick:()=>{let e=s-1;e<0?(o(e=>e-1),c(11)):c(e)},children:`←`}),(0,k.jsx)(`div`,{className:W.monthTitle,children:O}),(0,k.jsx)(`button`,{className:W.navBtn,onClick:()=>{let e=s+1;e>11?(o(e=>e+1),c(0)):c(e)},children:`→`})]}),(0,k.jsx)(`div`,{className:W.dayHeaders,children:A.map((e,t)=>(0,k.jsx)(`div`,{className:`${W.dayHeader} ${t>=5?W.weekend:``}`,children:e},e))}),(0,k.jsxs)(`div`,{className:W.grid,children:[Array.from({length:ae}).map((e,t)=>(0,k.jsx)(`div`,{className:`${W.cell} ${W.emptyCell} ${t>=5?W.weekendCell:``}`},`e${t}`)),Array.from({length:ie}).map((e,t)=>{let n=t+1,r=Rt(a,s,n),i=zt(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:`${W.cell} ${i?W.todayCell:u?W.weekendCell:``} ${f?W.activeCell:``} ${d?W.holidayCell:c>0?W.hasEvtsCell:``}`,onClick:()=>m(r),children:[(0,k.jsx)(`div`,{className:`${W.dayNum} ${i?W.todayNum:u?W.weekendNum:``}`,children:n}),c>0&&(0,k.jsxs)(`div`,{className:W.evtPills,children:[o.slice(0,2).map((e,t)=>(0,k.jsx)(`div`,{className:`${W.evtPill} ${e._isHoliday||e.readOnly?W.holidayPill:``}`,children:e.summary},t)),c>2&&(0,k.jsxs)(`div`,{className:W.morePill,children:[`+`,c-2]})]})]},r)})]}),d&&(0,k.jsx)(`div`,{className:W.loadingBar,children:`Loading events…`})]}),(0,k.jsx)(`div`,{className:W.detailCol,children:p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:W.detailHeader,children:[(0,k.jsx)(`div`,{className:W.detailDate,children:new Date(p+`T12:00:00`).toLocaleDateString(`en`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}),(0,k.jsx)(`button`,{className:W.addEvtBtn,onClick:()=>ee(p),children:`+ Add Event`})]}),j.length===0?(0,k.jsx)(`div`,{className:W.noEvts,children:`No events on this day`}):j.map((t,n)=>{let r=t.isAllDay?`All day`:`${Bt(t.start)} - ${Bt(t.end)}`,i=t.calendarId??`primary`;return(0,k.jsxs)(`div`,{className:W.evtCard,children:[(0,k.jsxs)(`div`,{className:W.evtTop,children:[(0,k.jsx)(`div`,{className:W.evtTime,children:r}),t.id&&!t.readOnly&&(0,k.jsxs)(`div`,{className:W.evtBtns,children:[(0,k.jsx)(`button`,{className:W.editBtn,onClick:()=>te(t,p),children:`Edit`}),(0,k.jsx)(`button`,{className:W.delBtn,onClick:()=>w(i,t.id,p),children:e(`common.delete`)})]}),t.readOnly&&(0,k.jsx)(`span`,{className:W.readOnly,children:`read-only`})]}),(0,k.jsx)(`div`,{className:W.evtTitle,children:t.summary}),t.location&&(0,k.jsxs)(`div`,{className:W.evtLoc,children:[`📍 `,t.location]}),t.organizer&&(0,k.jsxs)(`div`,{className:W.evtMeta,children:[`Organizer: `,t.organizer]}),t.attendees&&t.attendees.length>0&&(0,k.jsxs)(`div`,{className:W.attendees,children:[(0,k.jsx)(`div`,{className:W.evtMeta,children:`Attendees:`}),t.attendees.map((e,t)=>(0,k.jsxs)(`div`,{className:W.attendee,"data-status":e.responseStatus,children:[e.name||e.email,` (`,e.responseStatus,`)`]},t))]}),t.description&&(0,k.jsx)(`div`,{className:W.evtDesc,children:t.description}),t.hangoutLink&&(0,k.jsx)(`a`,{className:W.joinBtn,href:t.hangoutLink,target:`_blank`,rel:`noreferrer`,children:`Join Video Call`}),t.htmlLink&&(0,k.jsx)(`a`,{className:W.gcalLink,href:t.htmlLink,target:`_blank`,rel:`noreferrer`,children:`Open in Google Calendar`})]},n)})]}):(0,k.jsx)(`div`,{className:W.selectDay,children:`Select a day to see events`})}),h&&(0,k.jsx)(`div`,{className:W.overlay,onClick:e=>{e.target===e.currentTarget&&g(null)},children:(0,k.jsxs)(`div`,{className:W.formCard,children:[(0,k.jsx)(`div`,{className:W.formTitle,children:h.isEdit?`Edit Event`:`New Event`}),(0,k.jsx)(`label`,{className:W.formLabel,children:`Title *`}),(0,k.jsx)(`input`,{className:W.formInput,value:h.title,onChange:e=>g(t=>t&&{...t,title:e.target.value}),placeholder:`Event title`}),(0,k.jsx)(`label`,{className:W.formLabel,children:`Start`}),(0,k.jsx)(`input`,{className:W.formInput,type:`datetime-local`,value:h.start,onChange:e=>g(t=>t&&{...t,start:e.target.value})}),(0,k.jsx)(`label`,{className:W.formLabel,children:`End`}),(0,k.jsx)(`input`,{className:W.formInput,type:`datetime-local`,value:h.end,onChange:e=>g(t=>t&&{...t,end:e.target.value})}),(0,k.jsx)(`label`,{className:W.formLabel,children:`Location`}),(0,k.jsx)(`input`,{className:W.formInput,value:h.location,onChange:e=>g(t=>t&&{...t,location:e.target.value}),placeholder:`Optional`}),(0,k.jsx)(`label`,{className:W.formLabel,children:`Description`}),(0,k.jsx)(`textarea`,{className:W.formTextarea,value:h.description,onChange:e=>g(t=>t&&{...t,description:e.target.value})}),v&&(0,k.jsx)(`div`,{className:W.formError,children:v}),(0,k.jsxs)(`div`,{className:W.formBtns,children:[(0,k.jsx)(`button`,{className:W.cancelFormBtn,onClick:()=>g(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:W.saveFormBtn,onClick:T,disabled:b,children:b?`Saving…`:h.isEdit?`Save Changes`:`Create Event`})]})]})})]})}var G={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`},Ht={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 Ut(e){let t=e.card??e,n=(t.name||t.displayName||t.agentName||e.name||``).toLowerCase().replace(/\s+/g,`-`),r=Ht[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 Wt(e){return{agent:e,history:[],streaming:!1,input:``,attachedFile:null,attachedImage:null,voiceActive:!1}}function Gt(){let e=M(),[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(Ut)),i(!1)}).catch(()=>i(!1))};(0,_.useEffect)(()=>{oe()},[]);let se=[`All`,...Array.from(new Set(t.map(e=>e.category))).sort()],ce=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))}),le=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,Wt(e)]})},ue=e=>{re.current.get(e)?.abort(),re.current.delete(e),u(t=>t.filter(t=>t.agent.id!==e))},N=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,...t}:n))},de=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,history:[...n.history,t]}:n))},fe=(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}}))},pe=async(e,t,n,r)=>{let i=e.agent.id;if(!t.trim()&&!n&&!r)return;de(i,{role:`user`,content:n?(t?t+` `:``)+`[File: ${n.name}]`:r?(t?t+` `:``)+`[Image: ${r.name}]`:t}),N(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);de(i,{role:`assistant`,content:a?.response||a?.content||``})}catch{de(i,{role:`assistant`,content:`Error sending attachment.`})}N(i,{streaming:!1});return}de(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,fe(i,s);let t=O.current.get(i);t&&(t.scrollTop=t.scrollHeight)},o.signal)}catch{}finally{N(i,{streaming:!1}),re.current.delete(i)}},P=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;de(r,{role:`user`,content:e}),N(r,{streaming:!0});let i=``,a=new AbortController;re.current.set(r,a),de(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,fe(r,i);let t=O.current.get(r);t&&(t.scrollTop=t.scrollHeight)},a.signal)}catch{}finally{N(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(`
524
+ </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))},ve=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`)},be=()=>{if(!u){r(``),a([]),s([]),l(``),S(``),le.current=``,w(null),ue.current=null,te(!1),b({in:0,out:0}),v(null),re(!1);try{sessionStorage.removeItem(Xe)}catch{}}},I=i.some(e=>e.output||e.status===`running`);return(0,k.jsxs)(`div`,{className:F.root,children:[(0,k.jsxs)(`div`,{className:F.header,children:[(0,k.jsxs)(`div`,{className:F.headerLeft,children:[(0,k.jsx)(`div`,{className:F.title,children:`Studio`}),(0,k.jsx)(`div`,{className:F.subtitle,children:`Multi-agent orchestration · Council deliberation · Geth Consensus`})]}),(0,k.jsxs)(`div`,{className:F.headerActions,children:[y.in+y.out>0&&(0,k.jsxs)(`div`,{className:F.tokenBar,children:[(0,k.jsxs)(`span`,{className:F.tokIn,children:[`↑ `,y.in.toLocaleString()]}),(0,k.jsx)(`span`,{className:F.tokDim,children:` in `}),(0,k.jsxs)(`span`,{className:F.tokOut,children:[`↓ `,y.out.toLocaleString()]}),(0,k.jsx)(`span`,{className:F.tokDim,children:` out`})]}),(0,k.jsxs)(`div`,{style:{position:`relative`},children:[(0,k.jsxs)(`button`,{className:F.sessionsBtn,onClick:()=>h(e=>!e),children:[`Sessions (`,f.length,`)`]}),m&&(0,k.jsxs)(`div`,{className:F.sessionsDrawer,children:[f.length===0&&(0,k.jsx)(`div`,{className:F.noSessions,children:`No saved sessions yet.`}),f.map(e=>(0,k.jsxs)(`div`,{className:F.sessionItem,children:[(0,k.jsxs)(`div`,{className:F.sessionInfo,onClick:()=>he(e),children:[(0,k.jsx)(`div`,{className:F.sessionTask,children:e.task.slice(0,80)}),(0,k.jsxs)(`div`,{className:F.sessionMeta,children:[e.ts.slice(0,16),` · `,e.nodes.length,` agents`,e.council?.phase===`done`?` · 🏛️ Council`:``]})]}),(0,k.jsxs)(`div`,{className:F.sessionBtns,children:[(0,k.jsx)(`button`,{className:F.importBtn,onClick:()=>ve(e),children:`→ Chat`}),(0,k.jsx)(`button`,{className:F.delSessionBtn,onClick:()=>ge(e.id),children:`✕`})]})]},e.id))]})]}),x&&(0,k.jsx)(`button`,{className:F.canvasToggleBtn,onClick:()=>{re(!0),O(`canvas`)},children:`📊 Panel`}),c&&(0,k.jsx)(`button`,{className:F.pdfBtn,onClick:_e,children:`⬇ PDF / HTML`}),(i.length>0||c||o.length>0)&&!u&&(0,k.jsx)(`button`,{className:F.clearBtn,onClick:be,title:`Clear all — start fresh`,children:`✕ Clear`})]})]}),(0,k.jsxs)(`div`,{className:F.inputArea,children:[(0,k.jsxs)(`div`,{className:F.inputRow,children:[(0,k.jsx)(`textarea`,{className:F.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:4,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),fe())}}),(0,k.jsxs)(`div`,{className:F.inputControls,children:[u?(0,k.jsx)(`button`,{className:F.stopBtn,onClick:pe,children:`■ Stop`}):(0,k.jsx)(`button`,{className:F.runBtn,onClick:fe,disabled:!n.trim(),children:`Run ▶`}),(0,k.jsxs)(`label`,{className:F.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=>de(e.target.files?.[0])})]})]})]}),g&&(0,k.jsxs)(`div`,{className:F.attachBadge,children:[`📎 `,g.name,(0,k.jsx)(`button`,{className:F.clearAttach,onClick:()=>v(null),children:`✕`})]}),!u&&i.length===0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:F.examples,children:xe.map((e,t)=>(0,k.jsx)(`button`,{className:F.exampleBtn,onClick:()=>r(e),children:e},t))}),(0,k.jsxs)(`div`,{className:F.financeSection,children:[(0,k.jsx)(`div`,{className:F.financeSectionTitle,children:`📈 Finance & Trading Workflows`}),(0,k.jsx)(`div`,{className:F.financePresets,children:ye.map((e,t)=>(0,k.jsx)(`button`,{className:F.financeBtn,onClick:()=>{r(e.task),a(e.agents)},children:e.label},t))})]})]})]}),i.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:F.officeSceneWrap,children:(0,k.jsx)(We,{nodes:i,running:u})}),(0,k.jsxs)(`div`,{className:`${F.pipelineWrap} ${u?F.pipelineRunning:``}`,children:[(0,k.jsxs)(`div`,{className:F.pipelineTitle,children:[`Agent Pipeline`,u&&(0,k.jsx)(`span`,{className:F.pipelineLiveTag,children:`● LIVE`})]}),(0,k.jsx)(`div`,{className:F.pipelineNodes,children:i.map((e,t)=>(0,k.jsxs)(`div`,{className:F.pipelineStep,children:[(0,k.jsxs)(`div`,{className:`${F.agentChip} ${F[`chip_${e.status}`]}`,children:[(0,k.jsx)(`span`,{className:F.chipIcon,children:e.icon}),(0,k.jsx)(`span`,{className:F.chipLabel,children:e.label}),e.status===`running`&&(0,k.jsxs)(`span`,{className:F.chipDots,children:[(0,k.jsx)(`span`,{className:F.dot1,children:`.`}),(0,k.jsx)(`span`,{className:F.dot2,children:`.`}),(0,k.jsx)(`span`,{className:F.dot3,children:`.`})]}),e.status===`done`&&(0,k.jsx)(`span`,{className:F.chipCheck,children:`✓`}),e.status===`error`&&(0,k.jsx)(`span`,{className:F.chipErr,children:`✗`})]}),t<i.length-1&&(0,k.jsx)(`div`,{className:`${F.arrow} ${u?F.arrowActive:``}`,children:`→`})]},t))}),i.some(e=>e.reason)&&(0,k.jsx)(`div`,{className:F.reasonRow,children:i.map((e,t)=>e.reason?(0,k.jsxs)(`div`,{className:F.reasonChip,title:e.reason,children:[(0,k.jsx)(`span`,{className:F.reasonIcon,children:e.icon}),(0,k.jsxs)(`span`,{className:F.reasonText,children:[e.reason.slice(0,60),e.reason.length>60?`…`:``]})]},t):null)})]})]}),(0,k.jsxs)(`div`,{className:F.body,children:[(o.length>0||I)&&(0,k.jsxs)(`div`,{className:F.twoCol,children:[(0,k.jsxs)(`div`,{className:F.logPanel,children:[(0,k.jsx)(`div`,{className:F.panelTitle,children:`Live Log`}),(0,k.jsx)(`div`,{className:F.logBody,ref:ce,children:o.map((e,t)=>(0,k.jsxs)(`div`,{className:`${F.logEntry} ${F[`log_${e.type}`]}`,children:[(0,k.jsx)(`span`,{className:F.logTime,children:e.time}),(0,k.jsx)(`span`,{className:F.logIcon,children:e.icon}),(0,k.jsx)(`span`,{className:F.logAgent,children:e.agent}),(0,k.jsx)(`span`,{className:F.logText,children:e.text})]},t))})]}),(0,k.jsx)(`div`,{className:F.liveOutputPanel,children:i.filter(e=>e.output||e.status===`running`).map((e,t)=>(0,k.jsxs)(`div`,{className:`${F.liveBlock} ${e.status===`running`?F.liveBlockActive:``} ${e.status===`done`&&e.output?F.liveBlockClickable:``}`,onClick:()=>e.status===`done`&&e.output?oe(e):void 0,children:[(0,k.jsxs)(`div`,{className:F.liveBlockHeader,children:[(0,k.jsx)(`span`,{className:F.liveBlockIcon,children:e.icon}),(0,k.jsx)(`span`,{className:F.liveBlockLabel,children:e.label}),e.reason&&(0,k.jsx)(`span`,{className:F.liveBlockReason,title:e.reason,children:`ℹ`}),(0,k.jsx)(`span`,{className:`${F.outputStatus} ${F[`status_${e.status}`]}`,children:e.status}),e.status===`done`&&e.output&&(0,k.jsx)(`span`,{className:F.expandHint,children:`↗ espandi`})]}),e.status===`running`&&!e.output&&(0,k.jsxs)(`div`,{className:F.liveBlockWorking,children:[(0,k.jsx)(`span`,{className:F.workingDot}),(0,k.jsx)(`span`,{className:F.workingDot}),(0,k.jsx)(`span`,{className:F.workingDot}),(0,k.jsx)(`span`,{className:F.workingLabel,children:`elaborazione in corso`})]}),(0,k.jsx)(`div`,{className:`${F.liveBlockBody} ${e.status===`done`&&e.output?F.liveBlockBodyClamped:``}`,dangerouslySetInnerHTML:{__html:me(e.output)+(e.status===`running`&&e.output?`<span class="studio-cursor"></span>`:``)}})]},t))})]}),ee&&(0,k.jsxs)(`div`,{className:F.parliamentPrompt,children:[(0,k.jsx)(`div`,{className:F.parliamentPromptIcon,children:`🏛️`}),(0,k.jsxs)(`div`,{className:F.parliamentPromptContent,children:[(0,k.jsx)(`div`,{className:F.parliamentPromptTitle,children:`Attivare il Consiglio?`}),(0,k.jsxs)(`div`,{className:F.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:F.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:F.parliamentPromptBtns,children:[(0,k.jsx)(`button`,{className:F.parliamentActivateBtn,onClick:P,children:`🏛️ Attiva`}),(0,k.jsx)(`button`,{className:F.parliamentSkipBtn,onClick:()=>te(!1),children:`Salta`})]})]}),C&&!ee&&(0,k.jsx)(`div`,{className:F.councilWrapper,children:(0,k.jsx)(rt,{council:C})}),c&&!u&&(0,k.jsxs)(`details`,{className:F.resultAccordion,open:i.length<=1,children:[(0,k.jsxs)(`summary`,{className:F.resultAccordionSummary,children:[`Full Combined Report (`,i.filter(e=>e.output&&e.output!==`(no output)`).length,` agents)`]}),(0,k.jsx)(`div`,{className:F.resultAccordionBody,dangerouslySetInnerHTML:{__html:me(c)}})]})]}),D&&(0,k.jsxs)(`div`,{className:F.canvasPanel,children:[(0,k.jsxs)(`div`,{className:F.canvasPanelHeader,children:[(0,k.jsxs)(`div`,{className:F.panelTabs,children:[(0,k.jsx)(`button`,{className:`${F.panelTabBtn} ${ie===`canvas`?F.panelTabActive:``}`,onClick:()=>O(`canvas`),children:`📊 Canvas`}),(0,k.jsx)(`button`,{className:`${F.panelTabBtn} ${ie===`browser`?F.panelTabActive:``}`,onClick:()=>O(`browser`),children:`🌐 Browser`})]}),(0,k.jsxs)(`div`,{className:F.canvasPanelActions,children:[ie===`canvas`&&x&&(0,k.jsx)(`button`,{className:F.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:F.canvasPanelClose,onClick:()=>re(!1),children:`✕`})]})]}),ie===`canvas`?x?(0,k.jsx)(`iframe`,{className:F.canvasFrame,srcDoc:x,sandbox:`allow-scripts`,title:`Canvas Report`}):(0,k.jsx)(`div`,{className:F.panelEmpty,children:`No canvas report yet. Run a workflow first.`}):(0,k.jsxs)(`div`,{className:F.browserPanel,children:[(0,k.jsxs)(`div`,{className:F.browserBar,children:[(0,k.jsx)(`input`,{className:F.browserInput,value:ae,onChange:e=>A(e.target.value),placeholder:`https://…`,onKeyDown:e=>{e.key===`Enter`&&A(ae)}}),(0,k.jsx)(`button`,{className:F.browserGo,onClick:()=>A(ae),children:`Go`})]}),ae?(0,k.jsx)(`iframe`,{className:F.canvasFrame,src:ae,sandbox:`allow-scripts allow-same-origin allow-forms`,title:`Browser`}):(0,k.jsx)(`div`,{className:F.panelEmpty,children:`Enter a URL above to browse`})]})]}),j&&(0,k.jsx)(`div`,{className:F.blockModalOverlay,onClick:()=>oe(null),children:(0,k.jsxs)(`div`,{className:F.blockModal,onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:F.blockModalHeader,children:[(0,k.jsx)(`span`,{className:F.liveBlockIcon,children:j.icon}),(0,k.jsx)(`span`,{className:F.blockModalTitle,children:j.label}),(0,k.jsx)(`button`,{className:F.blockModalClose,onClick:()=>oe(null),children:`✕`})]}),(0,k.jsx)(`div`,{className:`${F.liveBlockBody} ${F.blockModalBody}`,dangerouslySetInnerHTML:{__html:me(j.output)}})]})})]})}var z={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`},at=[{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`}],ot={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 st(e){try{return new Date(e).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,hour12:!1})}catch{return e}}function ct(e){try{return new Date(e).toLocaleDateString(`en`,{month:`short`,day:`numeric`})}catch{return e}}function lt(){let e=ne(e=>e.setView),t=M(),[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(at.map(e=>e.group))];return(0,k.jsxs)(`div`,{className:z.root,children:[(0,k.jsxs)(`div`,{className:z.hero,children:[(0,k.jsxs)(`div`,{className:z.heroLeft,children:[(0,k.jsx)(`div`,{className:z.heroDate,children:y}),(0,k.jsx)(`div`,{className:z.heroTitle,children:c?(0,k.jsxs)(k.Fragment,{children:[`NHA `,(0,k.jsxs)(`span`,{className:z.heroVer,children:[`v`,c.version]}),` · `,(0,k.jsxs)(`span`,{className:z.heroUptime,children:[Math.floor(c.uptime/60),`m uptime`]})]}):`NotHumanAllowed`})]}),(0,k.jsx)(`div`,{className:z.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:z.wIcon,children:ot[u.desc]??u.icon??`🌡️`}),(0,k.jsxs)(`div`,{className:z.wInfo,children:[(0,k.jsxs)(`span`,{className:z.wTemp,children:[u.tempC,`°C`]}),(0,k.jsxs)(`span`,{className:z.wCity,children:[u.city.split(`,`)[0],u.country?`, ${u.country.slice(0,2).toUpperCase()}`:``]}),(0,k.jsxs)(`span`,{className:z.wDesc,children:[u.desc,` · 💧`,u.humidity,`%`]})]})]}):(0,k.jsxs)(`span`,{className:z.wEmpty,children:[`🌡️ `,t(`dashboard.weather`)]})})]}),(0,k.jsxs)(`div`,{className:z.kpiRow,children:[(0,k.jsxs)(`div`,{className:z.kpi,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:z.kpiNum,children:m.length}),(0,k.jsx)(`span`,{className:z.kpiLbl,children:`Pending tasks`}),n.length>0&&(0,k.jsx)(`div`,{className:z.kpiBar,children:(0,k.jsx)(`div`,{className:z.kpiFill,style:{width:`${g}%`}})})]}),(0,k.jsxs)(`div`,{className:z.kpi,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:z.kpiNum,children:v>0?v:i.length}),(0,k.jsx)(`span`,{className:z.kpiLbl,children:v>0?`Unread emails`:`Emails`})]}),(0,k.jsxs)(`div`,{className:z.kpi,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:z.kpiNum,children:o.length}),(0,k.jsx)(`span`,{className:z.kpiLbl,children:`Today's events`})]}),u&&(0,k.jsxs)(`div`,{className:z.kpi,children:[(0,k.jsxs)(`span`,{className:z.kpiNum,children:[u.feelsC,`°`]}),(0,k.jsx)(`span`,{className:z.kpiLbl,children:`Feels like`})]})]}),(0,k.jsxs)(`div`,{className:z.liveGrid,children:[o.length>0&&(0,k.jsxs)(`div`,{className:z.liveCard,children:[(0,k.jsxs)(`div`,{className:z.liveHdr,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📅 `,t(`calendar.title`)]}),(0,k.jsx)(`span`,{className:z.liveMore,children:`→`})]}),o.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:z.liveRow,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:z.liveTime,children:t.isAllDay?`All day`:st(t.start)}),(0,k.jsxs)(`div`,{className:z.liveBody,children:[(0,k.jsx)(`span`,{className:z.liveTitle,children:t.summary}),t.location&&(0,k.jsx)(`span`,{className:z.liveSub,children:t.location})]})]},n))]}),i.length>0&&(0,k.jsxs)(`div`,{className:z.liveCard,children:[(0,k.jsxs)(`div`,{className:z.liveHdr,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📧 `,t(`email.inbox`)]}),(0,k.jsx)(`span`,{className:z.liveMore,children:`→`})]}),i.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:`${z.liveRow} ${t.isUnread?z.liveUnread:``}`,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:z.liveTime,children:ct(t.date)}),(0,k.jsxs)(`div`,{className:z.liveBody,children:[(0,k.jsx)(`span`,{className:z.liveTitle,children:t.subject}),(0,k.jsx)(`span`,{className:z.liveSub,children:t.from})]})]},n))]}),m.length>0&&(0,k.jsxs)(`div`,{className:z.liveCard,children:[(0,k.jsxs)(`div`,{className:z.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:z.liveMore,children:`→`})]}),m.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:z.liveRow,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:`${z.prio} ${z[`prio_`+t.priority]}`,children:t.priority[0].toUpperCase()}),(0,k.jsx)(`div`,{className:z.liveBody,children:(0,k.jsx)(`span`,{className:z.liveTitle,children:t.description})})]},n))]})]}),(0,k.jsx)(`div`,{className:z.launcher,children:b.map(t=>(0,k.jsxs)(`div`,{className:z.launchGroup,children:[(0,k.jsx)(`div`,{className:z.launchGroupLabel,children:t}),(0,k.jsx)(`div`,{className:z.launchTiles,children:at.filter(e=>e.group===t).map(t=>(0,k.jsxs)(`button`,{className:z.tile,onClick:()=>e(t.view),style:{"--tc":t.color},children:[(0,k.jsx)(`span`,{className:z.tileIcon,children:t.icon}),(0,k.jsx)(`span`,{className:z.tileLabel,children:t.label})]},t.view))})]},t))})]})}var ut={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 dt(){let e=M(),[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:ut.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:ut.root,children:[(0,k.jsxs)(`div`,{className:ut.bar,children:[(0,k.jsx)(`input`,{ref:d,className:ut.input,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>e.key===`Enter`&&p(),placeholder:e(`tasks.newTask`)}),(0,k.jsxs)(`select`,{className:ut.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:ut.addBtn,onClick:p,disabled:l||!a.trim(),children:l?`…`:`+ `+e(`common.add`)})]}),t.length>0&&(0,k.jsxs)(`div`,{className:ut.actions,children:[(0,k.jsx)(`button`,{className:ut.clearDone,onClick:g,children:`Clear completed`}),(0,k.jsx)(`button`,{className:ut.clearAll,onClick:v,children:`Clear all`})]}),t.length>0&&(0,k.jsxs)(`div`,{className:ut.stats,children:[y.length,` pending · `,b.length,` done`,t.length>0&&(0,k.jsx)(`span`,{className:ut.progress,children:(0,k.jsx)(`span`,{className:ut.progressBar,style:{width:`${Math.round(b.length/t.length*100)}%`}})})]}),y.length===0&&b.length===0&&(0,k.jsx)(`div`,{className:ut.empty,children:`No tasks yet. Add one above ↑`}),y.map(e=>(0,k.jsxs)(`div`,{className:ut.task,children:[(0,k.jsx)(`span`,{className:ut.check,onClick:()=>m(e.id)}),(0,k.jsx)(`span`,{className:ut.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${ut.badge} ${ut[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:ut.del,onClick:()=>h(e.id),children:`×`})]},e.id)),b.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:ut.doneLabel,children:`Completed`}),b.map(e=>(0,k.jsxs)(`div`,{className:`${ut.task} ${ut.taskDone}`,children:[(0,k.jsx)(`span`,{className:`${ut.check} ${ut.checkDone}`,onClick:()=>m(e.id),children:`✓`}),(0,k.jsx)(`span`,{className:ut.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${ut.badge} ${ut[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:ut.del,onClick:()=>h(e.id),children:`×`})]},e.id))]})]})}var B={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`},ft={id:``,display_name:``,email_address:``,from_name:``,imap_host:``,imap_port:`993`,smtp_host:``,smtp_port:`587`,username:``,password:``};function pt({id:e,label:t,placeholder:n,value:r,onChange:i,type:a=`text`}){return(0,k.jsxs)(`div`,{className:B.field,children:[(0,k.jsx)(`label`,{className:B.fieldLabel,children:t}),(0,k.jsx)(`input`,{id:e,type:a,placeholder:n,value:r,onChange:e=>i(e.target.value),className:B.fieldInput})]})}function mt(){let{setConfig:e}=ne(),t=M(),[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,ce]=(0,_.useState)(`30`),[le,ue]=(0,_.useState)(`off`),[N,de]=(0,_.useState)(``),[fe,pe]=(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`),ce(String(t?.meetingAlert??`30`)),ue(t?.thinking??`off`),te(``),a(!1),t&&e(t)}),me()},[]);let me=()=>E(`/api/imap/accounts`).then(e=>d(e?.accounts??[])),P=async(e,t)=>{s(e),await D(`/api/config`,{key:e,value:t}),l(e),s(null),setTimeout(()=>l(null),2e3)},he=()=>P(`profile`,x),ge=()=>{P(`provider`,C),P(`model`,T),P(`thinking`,le),ee&&P(`key`,ee)},_e=()=>{P(`planTime`,ae),P(`summaryTime`,j),P(`meetingAlert`,Number(se))},ve=()=>{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))},F=()=>{confirm(t(`settings.disconnectGoogleConfirm`))&&D(`/api/google/revoke`,{}).then(()=>{r(e=>({...e,hasGoogle:!1})),v(t(`common.disconnected`))})},ye=()=>{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),me()):h(`Error: `+(e?.error??`Unknown error`))}).catch(e=>h(`Error: `+e.message))},be=(e,n)=>{confirm(t(`settings.imapDelete`,{name:n}))&&D(`/api/imap/accounts/delete`,{id:e}).then(()=>me())},xe=e=>{D(`/api/imap/sync`,{accountId:e}).then(()=>setTimeout(me,3e3))};if(i)return(0,k.jsxs)(`div`,{className:B.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),t(`common.loading`)]});let I=e=>t(o===e?`common.saving`:c===e?`common.saved`:`common.save`);return(0,k.jsxs)(`div`,{className:B.root,children:[(0,k.jsxs)(`div`,{className:B.card,children:[(0,k.jsx)(`div`,{className:B.cardTitle,children:t(`settings.profile`)}),(0,k.jsx)(`div`,{className:B.cardSub,children:t(`settings.profileSub`)}),(0,k.jsx)(`div`,{className:B.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)(pt,{id:e,label:t,placeholder:n,value:x[e],onChange:t=>S(n=>({...n,[e]:t}))},e))}),(0,k.jsxs)(`button`,{className:B.saveBtn,onClick:he,children:[I(`profile`),` `,t(`settings.saveProfile`)]})]}),(0,k.jsxs)(`div`,{className:B.nhaFree,children:[(0,k.jsx)(`div`,{className:B.nhaFreeTitle,children:t(`settings.nhaFreeTitle`)}),(0,k.jsx)(`div`,{className:B.nhaFreeSub,children:t(`settings.nhaFreeSub`)}),(0,k.jsx)(`button`,{className:B.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:B.card,children:[(0,k.jsx)(`div`,{className:B.cardTitle,children:t(`settings.llmProvider`)}),(0,k.jsx)(`div`,{className:B.cardSub,children:t(`settings.llmProviderSub`)}),(0,k.jsxs)(`div`,{className:B.field,children:[(0,k.jsx)(`label`,{className:B.fieldLabel,children:t(`settings.provider`)}),(0,k.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),className:B.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:B.keySet,children:t(`settings.apiKeySet`)}):null),(0,k.jsx)(pt,{id:`apiKey`,label:t(`settings.apiKey`),placeholder:t(C===`nha`?`settings.apiKeyFreeNote`:`settings.apiKeyPh`),type:`password`,value:ee,onChange:te}),(0,k.jsx)(pt,{id:`model`,label:t(`settings.model`),placeholder:t(`settings.modelPh`),value:T,onChange:re}),(0,k.jsxs)(`div`,{className:B.field,children:[(0,k.jsx)(`label`,{className:B.fieldLabel,children:t(`settings.thinking`)}),(0,k.jsxs)(`select`,{value:le,onChange:e=>ue(e.target.value),className:B.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:B.saveBtn,onClick:ge,children:[I(`provider`),` `,t(`settings.saveProvider`)]})]}),(0,k.jsxs)(`div`,{className:B.card,children:[(0,k.jsx)(`div`,{className:B.cardTitle,children:t(`settings.language`)}),(0,k.jsxs)(`div`,{className:B.field,children:[(0,k.jsx)(`label`,{className:B.fieldLabel,children:t(`settings.languageLabel`)}),(0,k.jsx)(`select`,{value:ie,onChange:t=>{let r=t.target.value;O(r),P(`lang`,r),e({...n,lang:r})},className:B.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:B.card,children:[(0,k.jsx)(`div`,{className:B.cardTitle,children:t(`settings.telegram`)}),(0,k.jsx)(`div`,{className:B.cardSub,children:t(`settings.telegramSub`)}),n.hasTelegram&&(0,k.jsxs)(`div`,{className:B.connected,children:[`Telegram: `,t(`common.connected`)]}),n.hasDiscord&&(0,k.jsxs)(`div`,{className:B.connected,children:[`Discord: `,t(`common.connected`)]}),(0,k.jsx)(pt,{id:`tgToken`,label:t(`settings.telegramToken`),placeholder:n.hasTelegram?t(`settings.telegramSet`):t(`settings.telegramPh`),type:`password`,value:N,onChange:de}),(0,k.jsx)(pt,{id:`discordToken`,label:t(`settings.discordToken`),placeholder:n.hasDiscord?t(`settings.discordSet`):t(`settings.discordPh`),type:`password`,value:fe,onChange:pe}),(0,k.jsxs)(`button`,{className:B.saveBtn,onClick:()=>{N&&P(`telegram-bot-token`,N),fe&&P(`discord-bot-token`,fe)},children:[I(`telegram-bot-token`),` `,t(`settings.saveBots`)]})]}),(0,k.jsxs)(`div`,{className:B.card,children:[(0,k.jsx)(`div`,{className:B.cardTitle,children:t(`settings.dailyOps`)}),(0,k.jsx)(pt,{id:`planTime`,label:t(`settings.planTime`),placeholder:`07:00`,value:ae,onChange:A}),(0,k.jsx)(pt,{id:`summaryTime`,label:t(`settings.summaryTime`),placeholder:`18:00`,value:j,onChange:oe}),(0,k.jsx)(pt,{id:`meetingAlert`,label:t(`settings.meetingAlert`),placeholder:`30`,value:se,onChange:ce}),(0,k.jsxs)(`button`,{className:B.saveBtn,onClick:_e,children:[I(`planTime`),` `,t(`settings.saveSchedule`)]})]}),(0,k.jsxs)(`div`,{className:B.card,children:[(0,k.jsx)(`div`,{className:B.cardTitle,children:t(`settings.googleAccount`)}),(0,k.jsx)(`div`,{className:B.cardSub,children:t(`settings.googleSub`)}),n.hasGoogle&&(0,k.jsxs)(`div`,{className:B.connected,children:[`✅ `,t(`common.connected`),n.googleEmail?` · ${n.googleEmail}`:``]}),(0,k.jsxs)(`div`,{className:B.btnRow,children:[(0,k.jsx)(`button`,{className:B.saveBtn,onClick:ve,children:n.hasGoogle?t(`settings.reconnectGoogle`):t(`settings.connectGoogle`)}),n.hasGoogle&&(0,k.jsx)(`button`,{className:B.dangerBtn,onClick:F,children:t(`settings.disconnectGoogle`)})]}),g&&(0,k.jsx)(`div`,{className:B.statusMsg,children:g})]}),(0,k.jsxs)(`div`,{className:B.card,children:[(0,k.jsxs)(`div`,{className:B.cardTitleRow,children:[(0,k.jsx)(`div`,{className:B.cardTitle,children:t(`settings.imapAccounts`)}),(0,k.jsx)(`button`,{className:B.saveBtn,onClick:()=>{p({...ft}),h(``)},children:t(`settings.addAccount`)})]}),(0,k.jsx)(`div`,{className:B.cardSub,children:t(`settings.imapSub`)}),u.length===0&&!f&&(0,k.jsx)(`div`,{className:B.emptyImap,children:t(`settings.noImapAccounts`)}),u.map(e=>(0,k.jsxs)(`div`,{className:B.imapRow,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:B.imapName,children:e.display_name}),(0,k.jsxs)(`div`,{className:B.imapMeta,children:[e.email_address,` · `,e.imap_host]}),(0,k.jsxs)(`div`,{className:B.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:B.imapBtns,children:[(0,k.jsx)(`button`,{className:B.imapSyncBtn,onClick:()=>xe(e.id),children:t(`settings.sync`)}),(0,k.jsx)(`button`,{className:B.imapEditBtn,onClick:()=>{p({...ft,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:B.imapDelBtn,onClick:()=>be(e.id,e.display_name),children:t(`common.delete`)})]})]},e.id)),f&&(0,k.jsxs)(`div`,{className:B.imapForm,children:[(0,k.jsx)(`div`,{className:B.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)(pt,{id:`imap_${e}`,label:t,placeholder:n,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t})},e)),(0,k.jsxs)(`div`,{className:B.field,children:[(0,k.jsxs)(`label`,{className:B.fieldLabel,children:[t(`settings.password`),` `,f.id&&(0,k.jsx)(`span`,{className:B.pwdNote,children:t(`settings.passwordKeep`)})]}),(0,k.jsxs)(`div`,{className:B.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:B.fieldInput,style:{flex:1}}),(0,k.jsx)(`button`,{className:B.togglePwd,onClick:()=>b(e=>!e),children:t(y?`settings.hide`:`settings.show`)})]})]}),(0,k.jsxs)(`div`,{className:B.btnRow,children:[(0,k.jsx)(`button`,{className:B.saveBtn,onClick:ye,children:t(`common.save`)}),(0,k.jsx)(`button`,{className:B.cancelBtn,onClick:()=>p(null),children:t(`common.cancel`)})]}),m&&(0,k.jsx)(`div`,{className:B.statusMsg,children:m})]})]})]})}var ht={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 gt(){let e=M(),[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:ht.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):a?(0,k.jsx)(`div`,{className:ht.err,children:a}):(0,k.jsxs)(`div`,{className:ht.root,children:[(0,k.jsxs)(`div`,{className:ht.header,children:[(0,k.jsx)(`div`,{className:ht.title,children:`Upcoming Birthdays`}),(0,k.jsx)(`button`,{className:ht.addBtn,onClick:m,children:`+ Add Birthday`})]}),t.length===0&&(0,k.jsxs)(`div`,{className:ht.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:`${ht.card} ${r?ht.cardToday:``}`,children:[(0,k.jsx)(`span`,{className:ht.icon,children:`🎂`}),(0,k.jsxs)(`div`,{className:ht.info,children:[(0,k.jsx)(`div`,{className:ht.name,children:t.name}),(0,k.jsx)(`div`,{className:ht.date,children:t.date})]}),(0,k.jsx)(`div`,{className:r?ht.labelToday:i?ht.labelTomorrow:ht.labelFuture,children:r?`TODAY!`:i?`Tomorrow`:`in ${t.daysUntil} days`}),t.contactId&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:ht.editBtn,onClick:()=>h(t),children:e(`common.edit`)}),(0,k.jsx)(`button`,{className:ht.delBtn,onClick:()=>v(t),children:e(`common.delete`)})]})]},n)}),s&&(0,k.jsx)(`div`,{className:ht.overlay,onClick:e=>{e.target===e.currentTarget&&c(null)},children:(0,k.jsxs)(`div`,{className:ht.modal,children:[(0,k.jsx)(`div`,{className:ht.modalTitle,children:s.contactId?`Edit Birthday`:`Add Birthday`}),(0,k.jsx)(`label`,{className:ht.label,children:`Name *`}),(0,k.jsx)(`input`,{className:ht.input,value:s.name,onChange:e=>c(t=>t&&{...t,name:e.target.value}),placeholder:`Contact name`}),(0,k.jsx)(`label`,{className:ht.label,children:`Birthday (MM-DD or YYYY-MM-DD)`}),(0,k.jsx)(`input`,{className:ht.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:ht.hint,children:`Birthday will be saved as a Google Calendar event.`}),l&&(0,k.jsx)(`div`,{className:ht.formErr,children:l}),(0,k.jsxs)(`div`,{className:ht.modalBtns,children:[(0,k.jsx)(`button`,{className:ht.cancelBtn,onClick:()=>c(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:ht.saveBtn,onClick:g,disabled:d,children:d?`Saving…`:s.contactId?`Save`:`Add`})]})]})})]})}var V={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`},_t=[{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`}],vt=[{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.`}],yt=[{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 bt(){let e=M(),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:V.root,children:[(0,k.jsxs)(`div`,{className:V.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:V.title,children:`⏰ Scheduled Tasks`}),(0,k.jsxs)(`div`,{className:V.subtitle,children:[`Automate agents on a recurring schedule. Daemon must be running: `,(0,k.jsx)(`code`,{className:V.code,children:`nha ops start`})]})]}),(0,k.jsx)(`button`,{className:V.addBtn,onClick:w,children:`+ New Task`})]}),(0,k.jsxs)(`div`,{className:V.tabs,children:[(0,k.jsxs)(`button`,{className:`${V.tab} ${x===`jobs`?V.tabActive:``}`,onClick:()=>S(`jobs`),children:[`Jobs (`,n.length,`)`]}),(0,k.jsx)(`button`,{className:`${V.tab} ${x===`templates`?V.tabActive:``}`,onClick:()=>S(`templates`),children:`Templates`})]}),x===`templates`&&(0,k.jsxs)(`div`,{className:V.templates,children:[(0,k.jsx)(`div`,{className:V.templatesNote,children:`Click a template to pre-fill the job form or run it immediately in Chat.`}),vt.map(t=>(0,k.jsxs)(`div`,{className:V.templateCard,children:[(0,k.jsx)(`div`,{className:V.templateLabel,children:t.label}),(0,k.jsx)(`div`,{className:V.templatePrompt,children:t.prompt}),(0,k.jsxs)(`div`,{className:V.templateBtns,children:[(0,k.jsx)(`button`,{className:V.scheduleTplBtn,onClick:()=>O(t),children:`Schedule`}),(0,k.jsxs)(`button`,{className:V.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:V.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading jobs…`]}),o&&(0,k.jsx)(`div`,{className:V.err,children:o}),!i&&n.length===0&&!c&&(0,k.jsxs)(`div`,{className:V.empty,children:[(0,k.jsx)(`div`,{className:V.emptyIcon,children:`⏰`}),(0,k.jsxs)(`div`,{className:V.emptyTitle,children:[e(`cron.noJobs`),` tasks`]}),(0,k.jsx)(`div`,{className:V.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:V.addBtn,onClick:w,children:`+ New Task`})]}),n.map(e=>(0,k.jsxs)(`div`,{className:`${V.card} ${e.enabled?``:V.cardDisabled}`,children:[(0,k.jsxs)(`div`,{className:V.cardTop,children:[(0,k.jsxs)(`div`,{className:V.cardLeft,children:[e.name&&(0,k.jsx)(`div`,{className:V.jobName,children:e.name}),(0,k.jsx)(`code`,{className:V.schedule,children:e.schedule}),e.agent&&(0,k.jsx)(`span`,{className:V.agentBadge,children:e.agent}),(0,k.jsx)(`span`,{className:`${V.statusBadge} ${e.enabled?V.statusActive:V.statusPaused}`,children:e.enabled?`active`:`paused`})]}),(0,k.jsxs)(`div`,{className:V.cardActions,children:[(0,k.jsx)(`button`,{className:V.runBtn,onClick:()=>ie(e.prompt??e.command??``),title:`Run now in Chat`,children:`▶`}),(0,k.jsx)(`button`,{className:V.editBtn,onClick:()=>ee(e),children:`Edit`}),(0,k.jsx)(`button`,{className:e.enabled?V.pauseBtn:V.resumeBtn,onClick:()=>T(e.id,e.enabled),children:e.enabled?`Pause`:`Resume`}),(0,k.jsx)(`button`,{className:V.delBtn,onClick:()=>re(e.id),children:`✕`})]})]}),(0,k.jsx)(`div`,{className:V.jobPrompt,children:e.prompt??e.command}),(0,k.jsxs)(`div`,{className:V.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:V.formOverlay,onClick:e=>{e.target===e.currentTarget&&l(!1)},children:(0,k.jsxs)(`div`,{className:V.formModal,children:[(0,k.jsx)(`div`,{className:V.formTitle,children:y?`Edit Scheduled Task`:`New Scheduled Task`}),(0,k.jsx)(`label`,{className:V.label,children:`Name (optional)`}),(0,k.jsx)(`input`,{className:V.input,value:u.name,onChange:e=>d(t=>({...t,name:e.target.value})),placeholder:`e.g. Morning Briefing`}),(0,k.jsx)(`label`,{className:V.label,children:`Schedule *`}),(0,k.jsx)(`div`,{className:V.presets,children:_t.map(e=>(0,k.jsx)(`button`,{className:`${V.preset} ${u.schedule===e.value?V.presetActive:``}`,onClick:()=>d(t=>({...t,schedule:e.value})),children:e.label},e.value))}),(0,k.jsx)(`input`,{className:V.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:V.cronHints,children:yt.map(e=>(0,k.jsxs)(`span`,{className:V.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:V.label,children:`Task / Prompt *`}),(0,k.jsx)(`textarea`,{className:V.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:V.label,children:`Agent (optional — leave blank for auto-routing)`}),(0,k.jsx)(`input`,{className:V.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:V.formErr,children:m}),g&&(0,k.jsx)(`div`,{className:V.formOk,children:g}),(0,k.jsxs)(`div`,{className:V.formBtns,children:[(0,k.jsx)(`button`,{className:V.cancelBtn,onClick:()=>l(!1),children:`Cancel`}),(0,k.jsx)(`button`,{className:V.saveBtn,onClick:te,disabled:f,children:f?`Saving…`:y?`Update`:`Schedule`})]})]})})]})}var xt={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 St(){let e=M(),[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:xt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:xt.root,children:[(0,k.jsxs)(`div`,{className:xt.sidebar,children:[(0,k.jsx)(`button`,{className:xt.newBtn,onClick:v,children:`+ New Note`}),t.length===0&&(0,k.jsx)(`div`,{className:xt.empty,children:e(`notes.noNotes`)}),t.map(e=>(0,k.jsxs)(`div`,{className:`${xt.noteItem} ${a?.id===e.id?xt.noteItemActive:``}`,onClick:()=>g(e),children:[(0,k.jsx)(`div`,{className:xt.noteTitle,children:e.title||`Untitled`}),(0,k.jsx)(`div`,{className:xt.noteMeta,children:e.updatedAt?new Date(e.updatedAt).toLocaleDateString():``}),e.content&&(0,k.jsx)(`div`,{className:xt.notePreview,children:e.content.slice(0,150)}),e.tags&&e.tags.length>0&&(0,k.jsx)(`div`,{className:xt.noteTags,children:e.tags.map(e=>(0,k.jsx)(`span`,{className:xt.noteTag,children:e},e))})]},e.id))]}),(0,k.jsx)(`div`,{className:xt.editor,children:a||p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`input`,{className:xt.titleInput,value:s,onChange:e=>c(e.target.value),placeholder:`Note title…`}),(0,k.jsx)(`textarea`,{className:xt.contentArea,value:l,onChange:e=>u(e.target.value),placeholder:`Start writing…`}),(0,k.jsxs)(`div`,{className:xt.editorFooter,children:[a&&(0,k.jsx)(`button`,{className:xt.delNoteBtn,onClick:()=>b(a.id,a.title),children:e(`common.delete`)}),(0,k.jsx)(`button`,{className:xt.cancelBtn,onClick:()=>{o(null),m(!1)},children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:xt.saveBtn,onClick:y,disabled:d,children:d?`Saving…`:`Save`})]})]}):(0,k.jsx)(`div`,{className:xt.emptyEditor,children:`Select a note or create a new one`})})]})}var Ct={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`},wt={name:``,email:``,phone:``,company:``,address:``,notes:``};function Tt(){let e=M(),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({...wt}),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:Ct.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading contacts…`]}):o?(0,k.jsx)(`div`,{className:Ct.error,children:o}):(0,k.jsxs)(`div`,{className:Ct.root,children:[(0,k.jsxs)(`div`,{className:Ct.toolbar,children:[(0,k.jsx)(`input`,{className:Ct.search,value:c,onChange:e=>x(e.target.value),placeholder:`Search contacts…`}),n.length>0&&(0,k.jsxs)(`span`,{className:Ct.count,children:[n.length,` contact`,n.length===1?``:`s`]}),(0,k.jsx)(`button`,{className:Ct.addBtn,onClick:S,children:`+ Add`})]}),n.length===0&&(0,k.jsxs)(`div`,{className:Ct.empty,children:[e(`contacts.noContacts`),(0,k.jsx)(`br`,{}),`Add a Google account or add contacts manually.`]}),(0,k.jsx)(`div`,{className:Ct.grid,children:n.map(e=>(0,k.jsxs)(`div`,{className:Ct.card,onClick:()=>C(e),children:[(0,k.jsx)(`div`,{className:Ct.avatar,children:e.photo?(0,k.jsx)(`img`,{src:e.photo,alt:e.name,className:Ct.avatarImg}):T(e.name)}),(0,k.jsxs)(`div`,{className:Ct.info,children:[(0,k.jsx)(`div`,{className:Ct.name,children:e.name||`(no name)`}),(0,k.jsxs)(`div`,{className:Ct.row,children:[e.email&&(0,k.jsx)(`span`,{className:Ct.email,children:e.email}),e.phone&&(0,k.jsx)(`span`,{className:Ct.phone,children:e.phone}),e.company&&(0,k.jsxs)(`span`,{className:Ct.company,children:[e.company,e.title?` · ${e.title}`:``]}),e.birthday&&(0,k.jsxs)(`span`,{className:Ct.birthday,children:[`🎂 `,e.birthday]})]})]}),(0,k.jsxs)(`div`,{className:Ct.actions,children:[e.email&&(0,k.jsx)(`button`,{className:Ct.iconBtn,onClick:t=>te(t,e.email,e.name),title:`Send email via chat`,children:`✉`}),(0,k.jsx)(`button`,{className:Ct.iconBtn,onClick:t=>{t.stopPropagation(),C(e)},title:`Edit`,children:`✎`}),(0,k.jsx)(`button`,{className:`${Ct.iconBtn} ${Ct.iconBtnRed}`,onClick:t=>ee(t,e),title:`Delete`,children:`✕`})]})]},e.id))}),f&&(0,k.jsx)(`div`,{className:Ct.overlay,onClick:e=>{e.target===e.currentTarget&&p(null)},children:(0,k.jsxs)(`div`,{className:Ct.modal,children:[(0,k.jsx)(`div`,{className:Ct.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:Ct.field,children:[(0,k.jsx)(`label`,{className:Ct.label,children:t}),(0,k.jsx)(`input`,{className:Ct.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`)?Ct.formError:Ct.formStatus,children:g}),(0,k.jsxs)(`div`,{className:Ct.modalBtns,children:[(0,k.jsx)(`button`,{className:Ct.cancelBtn,onClick:()=>p(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:Ct.saveBtn,onClick:w,disabled:m||!f.name,children:m?`…`:`Save`})]})]})})]})}var H={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`},Et=[{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}}`}]}],Dt=Object.fromEntries(Et.map(e=>[e.id,e])),Ot=90,kt=72;function At(){return`n_${Date.now()}_${Math.random().toString(36).slice(2,6)}`}function jt(e,t){return{x:e.x+(t===`out`?Ot:0),y:e.y+kt/2}}function Mt(){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:Et},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-Ot/2)/20)*20,o=Math.round((e.clientY-r.top-kt/2)/20)*20,s={id:At(),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:Et};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?Dt[j.defId]:null;return(0,k.jsxs)(`div`,{className:H.root,children:[(0,k.jsxs)(`div`,{className:H.topbar,children:[(0,k.jsxs)(`div`,{className:H.topbarLeft,children:[(0,k.jsx)(`span`,{className:H.topbarTitle,children:`Connectors`}),(0,k.jsx)(`span`,{className:H.topbarSub,children:`Visual workflow automation · 80 tools · 38 AI agents · free AI via Liara`})]}),(0,k.jsxs)(`div`,{className:H.topbarActions,children:[n&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:`${H.runBtn} ${c?H.runBtnActive:``}`,onClick:ae,disabled:c||n.nodes.length===0,children:c?`⏳ Running…`:`▶ Run`}),(0,k.jsx)(`button`,{className:H.logBtn,onClick:()=>p(e=>!e),children:f?`Hide Log`:`📋 Log`})]}),(0,k.jsx)(`button`,{className:H.newWfBtn,onClick:S,children:`+ New Workflow`})]})]}),(0,k.jsxs)(`div`,{className:H.body,children:[(0,k.jsxs)(`div`,{className:H.sidebar,children:[(0,k.jsx)(`div`,{className:H.sidebarTitle,children:`Workflows`}),e.length===0&&(0,k.jsxs)(`div`,{className:H.sidebarEmpty,children:[`No workflows yet.`,(0,k.jsx)(`br`,{}),`Click "New Workflow" to start.`]}),e.map(e=>(0,k.jsxs)(`div`,{className:`${H.wfItem} ${n?.id===e.id?H.wfItemActive:``}`,onClick:()=>{r(e),a(null),d(e.lastRun?.steps??[]),p(!1)},children:[(0,k.jsxs)(`div`,{className:H.wfItemRow,children:[(0,k.jsx)(`span`,{className:H.wfItemName,children:e.name}),(0,k.jsx)(`button`,{className:e.enabled?H.wfOn:H.wfOff,onClick:t=>{t.stopPropagation(),A(e)},children:e.enabled?`ON`:`OFF`})]}),(0,k.jsxs)(`div`,{className:H.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:H.wfDelBtn,onClick:t=>{t.stopPropagation(),C(e.id)},children:`✕`})]},e.id))]}),(0,k.jsx)(`div`,{className:H.canvasArea,children:n?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:H.canvasHeader,children:[(0,k.jsx)(`input`,{className:H.wfNameInput,value:n.name,onChange:e=>r(t=>t&&{...t,name:e.target.value}),onBlur:()=>n&&x(n)}),o?(0,k.jsxs)(`span`,{className:H.connectHint,children:[`Click a target node to connect · `,(0,k.jsx)(`button`,{className:H.cancelConnectBtn,onClick:()=>s(null),children:`Cancel`})]}):(0,k.jsxs)(`span`,{className:H.canvasHint,children:[`Drag nodes from palette · Click `,(0,k.jsx)(`span`,{className:H.portHint,children:`▶`}),` to connect · Drag nodes to reposition`]})]}),(0,k.jsxs)(`div`,{ref:y,className:`${H.canvas} ${o?H.canvasConnecting:``}`,onMouseMove:te,onMouseUp:ne,onMouseLeave:ne,onDragOver:e=>e.preventDefault(),onDrop:w,onClick:()=>{o||a(null)},children:[(0,k.jsx)(`svg`,{className:H.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=jt(r,`out`),o=jt(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=Dt[e.defId];if(!t)return null;let n=i===e.id,r=o===e.id;return(0,k.jsxs)(`div`,{className:`${H.canvasNode} ${n?H.canvasNodeSelected:``} ${r?H.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:H.nodeDelBtn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),T(e.id)},children:`✕`}),(0,k.jsx)(`span`,{className:H.nodeIcon,children:t.icon}),(0,k.jsx)(`span`,{className:H.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:H.nodeConfigPreview,children:String(e).slice(0,14)},t)),(0,k.jsx)(`button`,{className:`${H.portOut} ${r?H.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:H.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:H.canvasDrop,children:`Drag nodes from the right panel and drop here`})]}),f&&(0,k.jsxs)(`div`,{className:H.logPanel,children:[(0,k.jsxs)(`div`,{className:H.logHeader,children:[(0,k.jsx)(`span`,{children:`Run Log`}),n.lastRun&&(0,k.jsx)(`span`,{className:H.logTime,children:new Date(n.lastRun.at).toLocaleString()}),(0,k.jsx)(`button`,{className:H.logClose,onClick:()=>p(!1),children:`✕`})]}),u.length===0&&(0,k.jsx)(`div`,{className:H.logEmpty,children:c?`Running…`:`No run results yet.`}),u.map((e,t)=>(0,k.jsxs)(`div`,{className:`${H.logStep} ${e.error?H.logStepError:``}`,children:[(0,k.jsxs)(`div`,{className:H.logStepHeader,children:[(0,k.jsx)(`span`,{className:H.logStepIcon,children:e.nodeIcon}),(0,k.jsx)(`span`,{className:H.logStepLabel,children:e.nodeLabel}),e.error&&(0,k.jsx)(`span`,{className:H.logStepErrBadge,children:`ERROR`})]}),e.error&&(0,k.jsx)(`div`,{className:H.logStepErr,children:e.error}),e.output&&(0,k.jsx)(`div`,{className:H.logStepOutput,dangerouslySetInnerHTML:{__html:me(e.output.slice(0,500))}})]},t))]})]}):(0,k.jsxs)(`div`,{className:H.canvasEmpty,children:[(0,k.jsx)(`div`,{className:H.canvasEmptyIcon,children:`🔗`}),(0,k.jsx)(`div`,{className:H.canvasEmptyTitle,children:`Select or create a workflow`}),(0,k.jsxs)(`div`,{className:H.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:H.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:H.newWfBtn,onClick:S,children:`+ New Workflow`})]})}),(0,k.jsx)(`div`,{className:H.rightPanel,children:j&&oe?(0,k.jsxs)(`div`,{className:H.configPanel,children:[(0,k.jsxs)(`div`,{className:H.configHeader,children:[(0,k.jsxs)(`span`,{style:{color:oe.color},children:[oe.icon,` `,oe.label]}),(0,k.jsx)(`button`,{className:H.configClose,onClick:()=>a(null),children:`✕`})]}),(0,k.jsx)(`div`,{className:H.configDesc,children:oe.description}),(0,k.jsx)(`div`,{className:H.configFields,children:(oe.configFields??[]).map(e=>(0,k.jsxs)(`div`,{className:H.configField,children:[(0,k.jsxs)(`label`,{className:H.configLabel,children:[e.label,e.required&&(0,k.jsx)(`span`,{className:H.configRequired,children:`*`})]}),(0,k.jsx)(`input`,{className:H.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:H.configHint,children:[`Use `,(0,k.jsx)(`code`,{children:`{{output}}`}),` to pass previous node result`]})]},e.key))}),(0,k.jsx)(`button`,{className:H.configDelete,onClick:()=>T(j.id),children:`Delete node`})]}):(0,k.jsxs)(`div`,{className:H.palette,children:[(0,k.jsx)(`div`,{className:H.paletteTitle,children:`Node Palette`}),(0,k.jsx)(`div`,{className:H.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:`${H.paletteTab} ${m===e.id?H.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:H.paletteNodes,children:Et.filter(e=>e.type===m).map(e=>(0,k.jsxs)(`div`,{className:H.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:H.paletteDefIcon,children:e.icon}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:H.paletteDefLabel,style:{color:e.color},children:e.label}),(0,k.jsx)(`div`,{className:H.paletteDefDesc,children:e.description})]})]},e.id))}),(0,k.jsxs)(`div`,{className:H.paletteGuide,children:[(0,k.jsx)(`div`,{className:H.guideTitle,children:`How to use Connectors`}),(0,k.jsxs)(`div`,{className:H.guideStep,children:[(0,k.jsx)(`span`,{className:H.guideNum,children:`1`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Create`}),` a workflow with "+ New Workflow"`]})]}),(0,k.jsxs)(`div`,{className:H.guideStep,children:[(0,k.jsx)(`span`,{className:H.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:H.guideStep,children:[(0,k.jsx)(`span`,{className:H.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:H.guideStep,children:[(0,k.jsx)(`span`,{className:H.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:H.guideStep,children:[(0,k.jsx)(`span`,{className:H.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:H.guideCode,children:`{{output}}`}),` to pass the previous result`]})]}),(0,k.jsxs)(`div`,{className:H.guideStep,children:[(0,k.jsx)(`span`,{className:H.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:H.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:H.guideTip,children:[(0,k.jsx)(`strong`,{children:`AI nodes`}),` use Liara (free) by default. They receive `,(0,k.jsx)(`code`,{className:H.guideCode,children:`{{output}}`}),` from the previous step automatically.`]})]})]})})]})]})}var U={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`},Nt=[{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:`🗑`}],Pt=[{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 Ft(e){return e?e.slice(0,10):``}function It(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 Lt(){let e=M(),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,ce]=(0,_.useState)(!1),[le,ue]=(0,_.useState)({}),[N,de]=(0,_.useState)(``),[fe,pe]=(0,_.useState)(``),[me,P]=(0,_.useState)(``),[he,ge]=(0,_.useState)(``),[_e,ve]=(0,_.useState)(``),[F,ye]=(0,_.useState)(!1),[be,xe]=(0,_.useState)(``),[I,L]=(0,_.useState)(!1),Se=(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?Ce(t[0].id,`imap`):Ce(`google`,`google`)})},[]);let Ce=(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),we(e,r,0,``)}):(d([]),Te(`INBOX`,``))},we=(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))},Te=(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))},Ee=()=>{O(ae),b(0),h([]),c===`imap`&&o?we(o,f,0,ae):Te(f??`INBOX`,ae)},De=e=>{S(e),ce(!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))},Oe=(e={})=>{ce(!0),ue(e),de(e.to??``),pe(``),P(e.subject??``),ge(e.type===`forward`&&e.body?`\n\n---------- Forwarded message ----------\n${e.body}`:``),ve(``),ye(!1),S(null),w(null)},ke=async()=>{if(!N.trim()){ve(`Recipient required`);return}ve(`Sending…`);try{if(c===`imap`&&o){let e=await D(`/api/imap/send`,{accountId:o,to:N.trim(),cc:fe.trim()||void 0,subject:me.trim(),bodyHtml:he.replace(/\n/g,`<br>`),bodyText:he,inReplyTo:le.inReplyTo||void 0});e?.ok?(ve(`Sent!`),setTimeout(()=>ce(!1),800)):ve(e?.error??`Error`)}else{let e=await D(`/api/email/send`,{to:N.trim(),subject:me.trim(),body:he});e?.ok||e?.id?(ve(`Sent!`),setTimeout(()=>ce(!1),800)):ve(e?.error??`Error`)}}catch(e){ve(e.message??`Error`)}},Ae=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)})},je=(e,t)=>{D(`/api/imap/mark-starred`,{messageId:e,isStarred:t}).then(()=>{C?.id===e&&w(e=>e&&{...e,is_starred:t})})},R=(e,t)=>{t&&D(`/api/imap/labels/assign`,{messageId:e,labelId:t})},Me=()=>{!be.trim()||!o||D(`/api/imap/labels`,{accountId:o,name:be.trim()}).then(()=>{L(!1),xe(``),E(`/api/imap/labels?accountId=${o}`).then(e=>d(e?.labels??[]))})};return(0,k.jsxs)(`div`,{className:U.root,children:[(0,k.jsxs)(`div`,{className:U.sidebar,children:[(0,k.jsxs)(`div`,{className:U.sidebarSection,children:[(0,k.jsx)(`div`,{className:U.sidebarLabel,children:`Account`}),(0,k.jsxs)(`select`,{className:U.accountSelect,value:c===`google`?`google`:`imap:${o}`,onChange:e=>{let t=e.target.value;t===`google`?Ce(`google`,`google`):t.startsWith(`imap:`)&&Ce(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:U.sidebarCompose,children:(0,k.jsx)(`button`,{className:U.composeBtn,onClick:()=>Oe(),children:`+ Compose`})}),(0,k.jsx)(`div`,{className:U.folderList,children:c===`google`?Nt.map(e=>(0,k.jsxs)(`div`,{className:`${U.folderItem} ${f===e.id?U.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),Te(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:U.badge,children:j})]},e.id)):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:U.labelHeader,children:[(0,k.jsx)(`span`,{children:`Labels`}),(0,k.jsx)(`button`,{className:U.addLabelBtn,onClick:()=>L(e=>!e),children:`+`})]}),I&&(0,k.jsxs)(`div`,{className:U.newLabelRow,children:[(0,k.jsx)(`input`,{className:U.newLabelInput,value:be,onChange:e=>xe(e.target.value),placeholder:`Label name`,onKeyDown:e=>e.key===`Enter`&&Me()}),(0,k.jsx)(`button`,{className:U.newLabelSave,onClick:Me,children:`+`})]}),u.map(e=>(0,k.jsxs)(`div`,{className:`${U.folderItem} ${f===e.id?U.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),o&&we(o,e.id,0,ie)},children:[(0,k.jsx)(`span`,{className:U.labelDot,style:{background:e.color??`var(--dim)`}}),(0,k.jsx)(`span`,{children:e.name}),e.unread_count?(0,k.jsx)(`span`,{className:U.badge,children:e.unread_count}):null]},e.id))]})}),c===`imap`&&o&&(0,k.jsx)(`div`,{className:U.syncArea,children:(0,k.jsx)(`button`,{className:U.syncBtn,onClick:()=>{o&&c===`imap`&&D(`/api/imap/sync/${o}`,{})},children:`Sync now`})})]}),(0,k.jsxs)(`div`,{className:U.messageList,children:[(0,k.jsxs)(`div`,{className:U.listHeader,children:[(0,k.jsx)(`input`,{className:U.searchInput,value:ae,onChange:e=>A(e.target.value),placeholder:`Search…`,onKeyDown:e=>e.key===`Enter`&&Ee()}),(0,k.jsx)(`button`,{className:U.searchBtn,onClick:Ee,children:`Go`})]}),(0,k.jsxs)(`div`,{className:U.listBody,children:[ee&&(0,k.jsx)(`div`,{className:U.listLoading,children:(0,k.jsx)(`div`,{className:`spinner`})}),!ee&&m.length===0&&(0,k.jsx)(`div`,{className:U.noMessages,children:`No messages`}),m.map(e=>(0,k.jsxs)(`div`,{className:`${U.msgRow} ${e.id===x?U.msgActive:``} ${e.is_read?``:U.msgUnread}`,onClick:()=>De(e.id),children:[(0,k.jsxs)(`div`,{className:U.msgTop,children:[(0,k.jsx)(`span`,{className:U.msgFrom,children:e.from_name||e.from_address||``}),(0,k.jsx)(`span`,{className:U.msgDate,children:Ft(e.internal_date)})]}),(0,k.jsx)(`div`,{className:U.msgSubject,children:e.subject||`(no subject)`}),(0,k.jsx)(`div`,{className:U.msgPreview,children:(e.body_preview||``).slice(0,80)})]},e.id))]}),(0,k.jsxs)(`div`,{className:U.listFooter,children:[(0,k.jsxs)(`span`,{children:[g,` messages`]}),m.length<g&&c===`imap`&&(0,k.jsx)(`button`,{className:U.loadMoreBtn,onClick:()=>{let e=y+50;b(e),o&&we(o,f,e,ie)},children:`Load more`})]})]}),(0,k.jsx)(`div`,{className:U.pane,children:(()=>{if(se)return(0,k.jsxs)(`div`,{className:U.composePane,children:[(0,k.jsx)(`div`,{className:U.composeTitle,children:e(`email.compose`)}),(0,k.jsx)(`input`,{className:U.composeField,value:N,onChange:e=>de(e.target.value),placeholder:`To`}),(0,k.jsx)(`input`,{className:U.composeField,value:fe,onChange:e=>pe(e.target.value),placeholder:`Cc`}),(0,k.jsx)(`input`,{className:U.composeField,value:me,onChange:e=>P(e.target.value),placeholder:`Subject`}),(0,k.jsxs)(`div`,{className:U.templateRow,children:[(0,k.jsx)(`button`,{className:U.templateToggle,onClick:()=>ye(e=>!e),children:`📄 Templates`}),F&&(0,k.jsx)(`div`,{className:U.templateDrop,children:Pt.map((e,t)=>(0,k.jsxs)(`div`,{className:U.templateItem,onClick:()=>{P(t=>t||e.subject),ye(!1)},children:[(0,k.jsx)(`strong`,{children:e.name}),(0,k.jsx)(`div`,{className:U.templateSubject,children:e.subject})]},t))})]}),(0,k.jsx)(`textarea`,{className:U.composeBody,value:he,onChange:e=>ge(e.target.value),placeholder:`Write your message…`}),(0,k.jsxs)(`div`,{className:U.composeActions,children:[(0,k.jsx)(`button`,{className:U.sendBtn,onClick:ke,children:e(`email.send_ok`)}),(0,k.jsx)(`button`,{className:U.cancelBtn,onClick:()=>ce(!1),children:`Discard`}),_e&&(0,k.jsx)(`span`,{className:`${U.compStatus} ${_e===`Sent!`?U.ok:U.err}`,children:_e})]})]});if(T)return(0,k.jsx)(`div`,{className:U.emptyPane,children:(0,k.jsx)(`div`,{className:`spinner`})});if(!C)return(0,k.jsx)(`div`,{className:U.emptyPane,children:`Select a message`});let n=It(C.to_addresses);return(0,k.jsxs)(`div`,{className:U.readingPane,children:[(0,k.jsx)(`div`,{className:U.paneToolbar,children:(0,k.jsxs)(`div`,{className:U.paneActions,children:[(0,k.jsx)(`button`,{className:U.replyBtn,onClick:()=>Oe({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:U.fwdBtn,onClick:()=>Oe({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:U.trashBtn,onClick:()=>Ae(C.id),children:`🗑`}),(0,k.jsx)(`button`,{className:U.starBtn,onClick:()=>je(C.id,!C.is_starred),children:C.is_starred?`★`:`☆`}),u.length>0&&(0,k.jsxs)(`select`,{className:U.labelSelect,defaultValue:``,onChange:e=>R(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:U.aiBtn,onClick:()=>t(`chat`),children:`Ask AI`})]})}),(0,k.jsxs)(`div`,{className:U.paneHeader,children:[(0,k.jsx)(`div`,{className:U.paneSubject,children:C.subject||`(no subject)`}),(0,k.jsxs)(`div`,{className:U.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:U.paneMeta,children:[(0,k.jsx)(`strong`,{children:`To:`}),` `,n]}),(0,k.jsxs)(`div`,{className:U.paneMeta,children:[(0,k.jsx)(`strong`,{children:`Date:`}),` `,C.internal_date]}),C.attachments&&C.attachments.length>0&&(0,k.jsx)(`div`,{className:U.attachments,children:C.attachments.map((e,t)=>(0,k.jsxs)(`a`,{className:U.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:U.paneBody,children:C.body_html?(0,k.jsx)(`iframe`,{ref:Se,sandbox:`allow-same-origin`,className:U.bodyFrame,srcDoc:C.body_html,title:`Email body`}):(0,k.jsx)(`pre`,{className:U.bodyText,children:C.body_text??C.body_preview??`(empty)`})})]})})()})]})}var W={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 Rt(e,t,n){return`${e}-${String(t+1).padStart(2,`0`)}-${String(n).padStart(2,`0`)}`}function zt(e,t,n){let r=new Date;return r.getFullYear()===e&&r.getMonth()===t&&r.getDate()===n}function Bt(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 Vt(){let e=M(),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:W.center,children:(0,k.jsx)(`div`,{className:`spinner`})});if(!n)return(0,k.jsx)(`div`,{className:W.center,children:(0,k.jsxs)(`div`,{className:W.noGoogle,children:[(0,k.jsx)(`div`,{className:W.noGoogleIcon,children:`📅`}),(0,k.jsx)(`div`,{className:W.noGoogleTitle,children:`Calendar`}),(0,k.jsx)(`div`,{className:W.noGoogleSub,children:`Connect your Google account to view and manage calendar events.`}),(0,k.jsx)(`button`,{className:W.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:W.root,children:[(0,k.jsxs)(`div`,{className:W.calCol,children:[(0,k.jsxs)(`div`,{className:W.navRow,children:[(0,k.jsx)(`button`,{className:W.navBtn,onClick:()=>{let e=s-1;e<0?(o(e=>e-1),c(11)):c(e)},children:`←`}),(0,k.jsx)(`div`,{className:W.monthTitle,children:O}),(0,k.jsx)(`button`,{className:W.navBtn,onClick:()=>{let e=s+1;e>11?(o(e=>e+1),c(0)):c(e)},children:`→`})]}),(0,k.jsx)(`div`,{className:W.dayHeaders,children:A.map((e,t)=>(0,k.jsx)(`div`,{className:`${W.dayHeader} ${t>=5?W.weekend:``}`,children:e},e))}),(0,k.jsxs)(`div`,{className:W.grid,children:[Array.from({length:ae}).map((e,t)=>(0,k.jsx)(`div`,{className:`${W.cell} ${W.emptyCell} ${t>=5?W.weekendCell:``}`},`e${t}`)),Array.from({length:ie}).map((e,t)=>{let n=t+1,r=Rt(a,s,n),i=zt(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:`${W.cell} ${i?W.todayCell:u?W.weekendCell:``} ${f?W.activeCell:``} ${d?W.holidayCell:c>0?W.hasEvtsCell:``}`,onClick:()=>m(r),children:[(0,k.jsx)(`div`,{className:`${W.dayNum} ${i?W.todayNum:u?W.weekendNum:``}`,children:n}),c>0&&(0,k.jsxs)(`div`,{className:W.evtPills,children:[o.slice(0,2).map((e,t)=>(0,k.jsx)(`div`,{className:`${W.evtPill} ${e._isHoliday||e.readOnly?W.holidayPill:``}`,children:e.summary},t)),c>2&&(0,k.jsxs)(`div`,{className:W.morePill,children:[`+`,c-2]})]})]},r)})]}),d&&(0,k.jsx)(`div`,{className:W.loadingBar,children:`Loading events…`})]}),(0,k.jsx)(`div`,{className:W.detailCol,children:p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:W.detailHeader,children:[(0,k.jsx)(`div`,{className:W.detailDate,children:new Date(p+`T12:00:00`).toLocaleDateString(`en`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}),(0,k.jsx)(`button`,{className:W.addEvtBtn,onClick:()=>ee(p),children:`+ Add Event`})]}),j.length===0?(0,k.jsx)(`div`,{className:W.noEvts,children:`No events on this day`}):j.map((t,n)=>{let r=t.isAllDay?`All day`:`${Bt(t.start)} - ${Bt(t.end)}`,i=t.calendarId??`primary`;return(0,k.jsxs)(`div`,{className:W.evtCard,children:[(0,k.jsxs)(`div`,{className:W.evtTop,children:[(0,k.jsx)(`div`,{className:W.evtTime,children:r}),t.id&&!t.readOnly&&(0,k.jsxs)(`div`,{className:W.evtBtns,children:[(0,k.jsx)(`button`,{className:W.editBtn,onClick:()=>te(t,p),children:`Edit`}),(0,k.jsx)(`button`,{className:W.delBtn,onClick:()=>w(i,t.id,p),children:e(`common.delete`)})]}),t.readOnly&&(0,k.jsx)(`span`,{className:W.readOnly,children:`read-only`})]}),(0,k.jsx)(`div`,{className:W.evtTitle,children:t.summary}),t.location&&(0,k.jsxs)(`div`,{className:W.evtLoc,children:[`📍 `,t.location]}),t.organizer&&(0,k.jsxs)(`div`,{className:W.evtMeta,children:[`Organizer: `,t.organizer]}),t.attendees&&t.attendees.length>0&&(0,k.jsxs)(`div`,{className:W.attendees,children:[(0,k.jsx)(`div`,{className:W.evtMeta,children:`Attendees:`}),t.attendees.map((e,t)=>(0,k.jsxs)(`div`,{className:W.attendee,"data-status":e.responseStatus,children:[e.name||e.email,` (`,e.responseStatus,`)`]},t))]}),t.description&&(0,k.jsx)(`div`,{className:W.evtDesc,children:t.description}),t.hangoutLink&&(0,k.jsx)(`a`,{className:W.joinBtn,href:t.hangoutLink,target:`_blank`,rel:`noreferrer`,children:`Join Video Call`}),t.htmlLink&&(0,k.jsx)(`a`,{className:W.gcalLink,href:t.htmlLink,target:`_blank`,rel:`noreferrer`,children:`Open in Google Calendar`})]},n)})]}):(0,k.jsx)(`div`,{className:W.selectDay,children:`Select a day to see events`})}),h&&(0,k.jsx)(`div`,{className:W.overlay,onClick:e=>{e.target===e.currentTarget&&g(null)},children:(0,k.jsxs)(`div`,{className:W.formCard,children:[(0,k.jsx)(`div`,{className:W.formTitle,children:h.isEdit?`Edit Event`:`New Event`}),(0,k.jsx)(`label`,{className:W.formLabel,children:`Title *`}),(0,k.jsx)(`input`,{className:W.formInput,value:h.title,onChange:e=>g(t=>t&&{...t,title:e.target.value}),placeholder:`Event title`}),(0,k.jsx)(`label`,{className:W.formLabel,children:`Start`}),(0,k.jsx)(`input`,{className:W.formInput,type:`datetime-local`,value:h.start,onChange:e=>g(t=>t&&{...t,start:e.target.value})}),(0,k.jsx)(`label`,{className:W.formLabel,children:`End`}),(0,k.jsx)(`input`,{className:W.formInput,type:`datetime-local`,value:h.end,onChange:e=>g(t=>t&&{...t,end:e.target.value})}),(0,k.jsx)(`label`,{className:W.formLabel,children:`Location`}),(0,k.jsx)(`input`,{className:W.formInput,value:h.location,onChange:e=>g(t=>t&&{...t,location:e.target.value}),placeholder:`Optional`}),(0,k.jsx)(`label`,{className:W.formLabel,children:`Description`}),(0,k.jsx)(`textarea`,{className:W.formTextarea,value:h.description,onChange:e=>g(t=>t&&{...t,description:e.target.value})}),v&&(0,k.jsx)(`div`,{className:W.formError,children:v}),(0,k.jsxs)(`div`,{className:W.formBtns,children:[(0,k.jsx)(`button`,{className:W.cancelFormBtn,onClick:()=>g(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:W.saveFormBtn,onClick:T,disabled:b,children:b?`Saving…`:h.isEdit?`Save Changes`:`Create Event`})]})]})})]})}var G={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`},Ht={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 Ut(e){let t=e.card??e,n=(t.name||t.displayName||t.agentName||e.name||``).toLowerCase().replace(/\s+/g,`-`),r=Ht[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 Wt(e){return{agent:e,history:[],streaming:!1,input:``,attachedFile:null,attachedImage:null,voiceActive:!1}}function Gt(){let e=M(),[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(Ut)),i(!1)}).catch(()=>i(!1))};(0,_.useEffect)(()=>{oe()},[]);let se=[`All`,...Array.from(new Set(t.map(e=>e.category))).sort()],ce=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))}),le=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,Wt(e)]})},ue=e=>{re.current.get(e)?.abort(),re.current.delete(e),u(t=>t.filter(t=>t.agent.id!==e))},N=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,...t}:n))},de=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,history:[...n.history,t]}:n))},fe=(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}}))},pe=async(e,t,n,r)=>{let i=e.agent.id;if(!t.trim()&&!n&&!r)return;de(i,{role:`user`,content:n?(t?t+` `:``)+`[File: ${n.name}]`:r?(t?t+` `:``)+`[Image: ${r.name}]`:t}),N(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);de(i,{role:`assistant`,content:a?.response||a?.content||``})}catch{de(i,{role:`assistant`,content:`Error sending attachment.`})}N(i,{streaming:!1});return}de(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,fe(i,s);let t=O.current.get(i);t&&(t.scrollTop=t.scrollHeight)},o.signal)}catch{}finally{N(i,{streaming:!1}),re.current.delete(i)}},P=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;de(r,{role:`user`,content:e}),N(r,{streaming:!0});let i=``,a=new AbortController;re.current.set(r,a),de(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,fe(r,i);let t=O.current.get(r);t&&(t.scrollTop=t.scrollHeight)},a.signal)}catch{}finally{N(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(`
492
525
 
493
526
  ---
494
527
 
495
528
  `),r=`The user asked: "${e}"\n\nHere are the responses from ${t.length} specialist agents:\n\n${n}\n\nSynthesize these responses into a unified analysis.`,i=``;try{await ie(`/api/chat/stream`,{message:r,systemPrompt:`You are the Conductor — a meta-agent that synthesizes the outputs of multiple specialist AI agents.
496
529
  Your job: examine all agent responses to a user's question, identify agreements, disagreements, complementary insights, and deliver a unified, high-quality synthesis.
497
- Be concise. Highlight what each agent contributed uniquely. Give your own synthesis verdict at the end.`},e=>{i+=e,g(i)})}catch{}finally{y(!1)}},he=e=>{let t=window.SpeechRecognition??window.webkitSpeechRecognition;if(!t){alert(`Speech recognition not supported.`);return}let n=T.current.get(e);if(l.find(t=>t.agent.id===e)?.voiceActive&&n){n.stop(),N(e,{voiceActive:!1});return}let r=new t;T.current.set(e,r),r.lang=`it-IT`,r.continuous=!1,r.interimResults=!1,r.onresult=t=>{let n=t.results[0][0].transcript;N(e,{input:(l.find(t=>t.agent.id===e)?.input??``)+(l.find(t=>t.agent.id===e)?.input?` `:``)+n})},r.onend=()=>N(e,{voiceActive:!1}),r.onerror=()=>N(e,{voiceActive:!1}),r.start(),N(e,{voiceActive:!0})},ge=(e,t)=>{if(!t)return;let n=t.name.toLowerCase().endsWith(`.pdf`)||t.type===`application/pdf`,r=new FileReader;n?(r.onload=n=>{let r=(n.target?.result).split(`,`)[1];N(e,{attachedFile:{name:t.name,size:t.size,base64:r,mimeType:`application/pdf`,isPDF:!0},attachedImage:null})},r.readAsDataURL(t)):(r.onload=n=>{N(e,{attachedFile:{name:t.name,size:t.size,content:n.target?.result},attachedImage:null})},r.readAsText(t))},_e=(e,t)=>{if(!t)return;let n=new FileReader;n.onload=n=>{let r=(n.target?.result).split(`,`)[1];N(e,{attachedImage:{name:t.name,size:t.size,base64:r,mimeType:t.type||`image/jpeg`},attachedFile:null})},n.readAsDataURL(t)},ve=()=>{x({name:``,tagline:``,systemPrompt:``}),C(`create`),ee(``)},F=async e=>{let t=await E(`/api/agents/${e.id}`).catch(()=>null);x({name:e.id,tagline:t?.tagline??e.description,systemPrompt:t?.systemPrompt??``}),C(`edit`),ee(``)},ye=async()=>{if(b){if(!b.tagline.trim()||!b.systemPrompt.trim()){ee(`Tagline and system prompt are required.`);return}ne(!0),ee(``);try{if(S===`create`){let e=b.name.toLowerCase().replace(/[^a-z0-9_-]/g,``);if(!e){ee(`Agent name required (lowercase, no spaces).`),ne(!1);return}let t=await D(`/api/agents`,{name:e,tagline:b.tagline,systemPrompt:b.systemPrompt});if(t?.error){ee(`Error: `+t.error),ne(!1);return}}else await D(`/api/agents/${b.name}`,{tagline:b.tagline,systemPrompt:b.systemPrompt,category:`custom`},`PUT`);x(null),oe()}catch(e){ee(`Error: `+e.message)}finally{ne(!1)}}},be=e=>{confirm(`Delete agent "${e.label}"?`)&&D(`/api/agents/${e.id}`,{},`DELETE`).then(()=>oe())};return r?(0,k.jsx)(`div`,{className:G.root,children:(0,k.jsx)(`div`,{className:G.loading,children:(0,k.jsx)(`div`,{className:`spinner`})})}):(0,k.jsxs)(`div`,{className:G.root,children:[(0,k.jsxs)(`div`,{className:G.gridSection,children:[(0,k.jsxs)(`div`,{className:G.gridHeader,children:[(0,k.jsxs)(`div`,{className:G.headerRow,children:[(0,k.jsx)(`input`,{className:G.search,value:a,onChange:e=>o(e.target.value),placeholder:`Search agents…`}),(0,k.jsx)(`button`,{className:G.createBtn,onClick:ve,children:`+ Create`})]}),(0,k.jsx)(`div`,{className:G.catTabs,children:se.map(e=>(0,k.jsxs)(`button`,{className:`${G.catTab} ${s===e?G.catActive:``}`,onClick:()=>c(e),children:[e,` (`,e===`All`?t.length:t.filter(t=>t.category===e).length,`)`]},e))})]}),(0,k.jsx)(`div`,{className:G.grid,children:ce.map(e=>{let t=l.some(t=>t.agent.id===e.id);return(0,k.jsxs)(`div`,{className:`${G.agentCard} ${t?G.agentActive:``}`,onClick:()=>le(e),children:[(0,k.jsxs)(`div`,{className:G.agentCardTop,children:[(0,k.jsx)(`div`,{className:G.agentIcon,children:e.icon}),e.isCustom&&(0,k.jsxs)(`div`,{className:G.agentActions,children:[(0,k.jsx)(`button`,{className:G.agentEditBtn,onClick:t=>{t.stopPropagation(),F(e)},children:`✏️`}),(0,k.jsx)(`button`,{className:G.agentDelBtn,onClick:t=>{t.stopPropagation(),be(e)},children:`🗑`})]})]}),(0,k.jsx)(`div`,{className:G.agentLabel,children:e.label}),(0,k.jsx)(`div`,{className:G.agentDesc,children:e.description}),(0,k.jsx)(`div`,{className:G.agentCat,children:e.category})]},e.id)})})]}),(0,k.jsx)(`div`,{className:G.chatArea,children:l.length===0?(0,k.jsxs)(`div`,{className:G.emptyChat,children:[(0,k.jsx)(`span`,{children:`Click an agent above to open a chat`}),(0,k.jsx)(`span`,{className:G.emptyChatHint,children:`Open multiple agents to run them in parallel`})]}):l.map(e=>{let{agent:t}=e,n=e.attachedFile?`📎 ${e.attachedFile.name}`:e.attachedImage?`🖼 ${e.attachedImage.name}`:null;return(0,k.jsxs)(`div`,{className:G.chatPanel,children:[(0,k.jsxs)(`div`,{className:G.chatHeader,children:[(0,k.jsx)(`span`,{className:G.chatIcon,children:t.icon}),(0,k.jsxs)(`div`,{className:G.chatHeaderInfo,children:[(0,k.jsx)(`div`,{className:G.chatAgentName,children:t.label}),(0,k.jsx)(`div`,{className:G.chatAgentDesc,children:t.description})]}),(0,k.jsx)(`button`,{className:G.closeChat,onClick:()=>ue(t.id),children:`✕`})]}),(0,k.jsxs)(`div`,{className:G.chatMessages,ref:e=>{O.current.set(t.id,e)},children:[e.history.length===0&&(0,k.jsxs)(`div`,{className:G.chatEmpty,children:[`Ask `,t.label,` anything…`]}),e.history.map((e,t)=>(0,k.jsx)(`div`,{className:`${G.chatMsg} ${e.role===`user`?G.msgUser:G.msgAgent}`,children:e.role===`assistant`?(0,k.jsx)(`div`,{dangerouslySetInnerHTML:{__html:me(e.content||`…`)}}):(0,k.jsx)(`span`,{children:e.content})},t)),e.streaming&&e.history[e.history.length-1]?.role===`assistant`&&e.history[e.history.length-1]?.content===``&&(0,k.jsxs)(`div`,{className:G.thinking,children:[(0,k.jsx)(`span`,{className:G.dot}),(0,k.jsx)(`span`,{className:G.dot}),(0,k.jsx)(`span`,{className:G.dot})]})]}),n&&(0,k.jsxs)(`div`,{className:G.attachBar,children:[(0,k.jsx)(`span`,{children:n}),(0,k.jsx)(`button`,{className:G.attachClear,onClick:()=>N(t.id,{attachedFile:null,attachedImage:null}),children:`×`})]}),(0,k.jsxs)(`div`,{className:G.chatInput,children:[(0,k.jsxs)(`div`,{className:G.chatTools,children:[(0,k.jsx)(`button`,{className:`${G.toolBtn} ${e.voiceActive?G.toolBtnActive:``}`,onClick:()=>he(t.id),title:`Voice`,children:`🎤`}),(0,k.jsx)(`button`,{className:G.toolBtn,onClick:()=>ae.current.get(t.id)?.click(),title:`Attach file`,children:`📎`}),(0,k.jsx)(`button`,{className:G.toolBtn,onClick:()=>A.current.get(t.id)?.click(),title:`Attach image`,children:`🖼`}),(0,k.jsx)(`input`,{type:`file`,style:{display:`none`},ref:e=>{ae.current.set(t.id,e)},onChange:e=>ge(t.id,e.target.files?.[0])}),(0,k.jsx)(`input`,{type:`file`,accept:`image/*`,style:{display:`none`},ref:e=>{A.current.set(t.id,e)},onChange:e=>_e(t.id,e.target.files?.[0])})]}),(0,k.jsxs)(`div`,{className:G.chatInputRow,children:[(0,k.jsx)(`textarea`,{className:G.chatTextarea,value:e.input,onChange:e=>N(t.id,{input:e.target.value}),placeholder:`Message ${t.label}…`,rows:2,onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),pe(e,e.input,e.attachedFile,e.attachedImage))}}),(0,k.jsx)(`button`,{className:G.sendBtn,onClick:()=>pe(e,e.input,e.attachedFile,e.attachedImage),disabled:e.streaming||!e.input.trim()&&!e.attachedFile&&!e.attachedImage,children:e.streaming?`…`:`→`})]})]})]},t.id)})}),l.length>=2&&(0,k.jsxs)(`div`,{className:G.orchBar,children:[(0,k.jsxs)(`div`,{className:G.orchLabel,children:[`🎼 Conductor · `,l.map(e=>`${e.agent.icon} ${e.agent.label}`).join(` · `)]}),(0,k.jsxs)(`div`,{className:G.orchRow,children:[(0,k.jsx)(`textarea`,{ref:j,className:G.orchInput,value:d,onChange:e=>f(e.target.value),placeholder:`Ask all agents — Conductor will synthesize a unified response…`,rows:1,onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),P())}}),(0,k.jsx)(`button`,{className:G.orchBtn,onClick:P,disabled:p||v||!d.trim(),children:p?`⏳`:v?`🔄`:`🎼 Run`})]}),(v||h)&&(0,k.jsxs)(`div`,{className:G.orchSynthesis,children:[(0,k.jsxs)(`div`,{className:G.orchSynthHeader,children:[(0,k.jsx)(`span`,{children:`🎼 Conductor Synthesis`}),v&&(0,k.jsx)(`span`,{className:G.orchSynthSpinner,children:`synthesizing…`})]}),(0,k.jsx)(`div`,{className:G.orchSynthBody,dangerouslySetInnerHTML:{__html:me(h||`…`)}})]})]}),b&&(0,k.jsx)(`div`,{className:G.modalOverlay,onClick:e=>{e.target===e.currentTarget&&x(null)},children:(0,k.jsxs)(`div`,{className:G.modal,children:[(0,k.jsx)(`div`,{className:G.modalTitle,children:S===`create`?`+ New Agent`:`✏️ Edit Agent`}),S===`create`&&(0,k.jsxs)(`div`,{className:G.formField,children:[(0,k.jsx)(`label`,{className:G.formLabel,children:`Agent name (lowercase, no spaces)`}),(0,k.jsx)(`input`,{className:G.formInput,placeholder:`my-agent`,value:b.name,onChange:e=>x(t=>t&&{...t,name:e.target.value})})]}),(0,k.jsxs)(`div`,{className:G.formField,children:[(0,k.jsx)(`label`,{className:G.formLabel,children:`Tagline`}),(0,k.jsx)(`input`,{className:G.formInput,placeholder:`Short description`,value:b.tagline,onChange:e=>x(t=>t&&{...t,tagline:e.target.value})})]}),(0,k.jsxs)(`div`,{className:G.formField,children:[(0,k.jsx)(`label`,{className:G.formLabel,children:`System Prompt`}),(0,k.jsx)(`textarea`,{className:G.formTextarea,placeholder:`You are an expert in…`,value:b.systemPrompt,onChange:e=>x(t=>t&&{...t,systemPrompt:e.target.value})})]}),w&&(0,k.jsx)(`div`,{className:G.formError,children:w}),(0,k.jsxs)(`div`,{className:G.modalBtns,children:[(0,k.jsx)(`button`,{className:G.cancelBtn,onClick:()=>x(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:G.modalSaveBtn,onClick:ye,disabled:te,children:te?`…`:S===`create`?`Create Agent`:`Save`})]})]})})]})}var K={root:`_root_1mam6_1`,error:`_error_1mam6_10`,errorHint:`_errorHint_1mam6_16`,quotaBar:`_quotaBar_1mam6_29`,quotaText:`_quotaText_1mam6_37`,quotaUsed:`_quotaUsed_1mam6_43`,quotaPct:`_quotaPct_1mam6_44`,quotaTrack:`_quotaTrack_1mam6_46`,quotaFill:`_quotaFill_1mam6_53`,actionBar:`_actionBar_1mam6_59`,filterBtn:`_filterBtn_1mam6_67`,filterActive:`_filterActive_1mam6_79`,spacer:`_spacer_1mam6_85`,newBtn:`_newBtn_1mam6_87`,uploadBtn:`_uploadBtn_1mam6_98`,searchRow:`_searchRow_1mam6_108`,searchInput:`_searchInput_1mam6_114`,searchBtn:`_searchBtn_1mam6_126`,loading:`_loading_1mam6_136`,empty:`_empty_1mam6_141`,fileList:`_fileList_1mam6_151`,fileRow:`_fileRow_1mam6_159`,fileIcon:`_fileIcon_1mam6_172`,fileInfo:`_fileInfo_1mam6_174`,fileName:`_fileName_1mam6_176`,fileMeta:`_fileMeta_1mam6_184`,fileBtns:`_fileBtns_1mam6_190`,editBtn:`_editBtn_1mam6_196`,viewBtn:`_viewBtn_1mam6_197`,pdfBtn:`_pdfBtn_1mam6_198`,openBtn:`_openBtn_1mam6_199`,delBtn:`_delBtn_1mam6_200`,editorRoot:`_editorRoot_1mam6_204`,editorToolbar:`_editorToolbar_1mam6_211`,backBtn:`_backBtn_1mam6_221`,editorName:`_editorName_1mam6_231`,saveBtn:`_saveBtn_1mam6_238`,editorArea:`_editorArea_1mam6_251`,editorMeta:`_editorMeta_1mam6_266`,viewerRoot:`_viewerRoot_1mam6_276`,imgContainer:`_imgContainer_1mam6_283`,imgView:`_imgView_1mam6_292`,pdfFrame:`_pdfFrame_1mam6_298`};function Kt(e,t){return e===`folder`?`📁`:e===`image`?`🖼`:e===`pdf`||t.includes(`pdf`)?`📕`:e===`video`?`🎬`:e===`audio`?`🎵`:t.includes(`spreadsheet`)||t.includes(`excel`)?`📊`:t.includes(`presentation`)||t.includes(`powerpoint`)?`📽`:t.includes(`document`)||t.includes(`word`)?`📄`:t.includes(`zip`)||t.includes(`archive`)?`📦`:`📄`}function qt(e){let t=e.mimeType;return e.type===`text`||e.type===`doc`||t.includes(`text`)||t.includes(`json`)||t.includes(`javascript`)||t.includes(`xml`)||t.includes(`csv`)||t.includes(`yaml`)||t.includes(`markdown`)||t.includes(`html`)||t.includes(`css`)||t.includes(`python`)||t.includes(`vnd.google-apps.document`)}function Jt(){let e=M(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(`list`),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(``),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(!1),w=(0,_.useRef)(null),ee=(e=s,t=l)=>{i(!0);let r=`/api/drive`;e&&(r+=`?filter=${e}`),t&&(r+=`${e?`&`:`?`}search=${encodeURIComponent(t)}`),E(r).then(e=>{n(e??{files:[]}),i(!1)}).catch(e=>{o(e.message??`Error`),i(!1)})};(0,_.useEffect)(()=>{ee()},[]);let te=e=>{c(e),ee(e,l)},ne=()=>{u(d),ee(s,d)},T=(e,t)=>{i(!0),E(`/api/drive/read/${e}`).then(n=>{g({id:e,name:t,content:n?.content??``}),y(n?.content??``),m(`editor`),i(!1)}).catch(()=>i(!1))},re=async()=>{if(h&&confirm(`Save changes to "${h.name}" on Drive?`)){C(!0);try{await D(`/api/drive/update/${h.id}`,{content:v}),g(e=>e&&{...e,content:v}),alert(`Saved!`)}catch(e){alert(`Save failed: `+e.message)}finally{C(!1)}}},ie=(e,t)=>{i(!0),E(`/api/drive/download/${e}`).then(n=>{x({id:e,name:t,src:`data:${n?.mimeType??`image/jpeg`};base64,${n?.base64}`,mode:`image`}),m(`image`),i(!1)}).catch(()=>i(!1))},O=(e,t)=>{i(!0),E(`/api/drive/download/${e}`).then(n=>{x({id:e,name:t,src:`data:application/pdf;base64,${n?.base64}`,mode:`pdf`}),m(`pdf`),i(!1)}).catch(()=>i(!1))},ae=(e,t)=>{confirm(`Delete "${t}" from Drive? (moved to trash)`)&&D(`/api/drive/delete/${e}`,{}).then(()=>{n(null),ee()})},A=()=>{let e=prompt(`File name (e.g. notes.txt, script.py):`);e&&D(`/api/drive/upload`,{name:e,content:``,mimeType:`text/plain`}).then(t=>{t?.id?T(t.id,e):ee()}).catch(e=>alert(`Error: `+e.message))},j=()=>{w.current?.click()},oe=e=>{if(!e)return;let t=new FileReader;t.onload=t=>{let r=(t.target?.result).split(`,`)[1]??``;D(`/api/drive/upload`,{name:e.name,content:r,mimeType:e.type||`application/octet-stream`,encoding:`base64`}).then(()=>{n(null),ee()}).catch(e=>alert(`Upload error: `+e.message))},t.readAsDataURL(e)};if(a)return(0,k.jsxs)(`div`,{className:K.error,children:[(0,k.jsx)(`div`,{children:a}),(0,k.jsxs)(`div`,{className:K.errorHint,children:[`Run: `,(0,k.jsx)(`code`,{children:`nha google revoke`}),` then `,(0,k.jsx)(`code`,{children:`nha google auth`})]})]});if(p===`editor`&&h)return(0,k.jsxs)(`div`,{className:K.editorRoot,children:[(0,k.jsxs)(`div`,{className:K.editorToolbar,children:[(0,k.jsx)(`button`,{className:K.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,k.jsx)(`span`,{className:K.editorName,children:h.name}),(0,k.jsx)(`button`,{className:K.saveBtn,onClick:re,disabled:S,children:S?`Saving…`:`Save to Drive`})]}),(0,k.jsx)(`textarea`,{className:K.editorArea,value:v,onChange:e=>y(e.target.value),spellCheck:!1,onKeyDown:e=>{if(e.key===`Tab`){e.preventDefault();let t=e.currentTarget.selectionStart,n=e.currentTarget.selectionEnd,r=e.currentTarget.value;e.currentTarget.value=r.slice(0,t)+` `+r.slice(n),e.currentTarget.selectionStart=e.currentTarget.selectionEnd=t+2}}}),(0,k.jsxs)(`div`,{className:K.editorMeta,children:[`File ID: `,h.id,` · Tab = 2 spaces · Not auto-saved`]})]});if(p===`image`&&b)return(0,k.jsxs)(`div`,{className:K.viewerRoot,children:[(0,k.jsxs)(`div`,{className:K.editorToolbar,children:[(0,k.jsx)(`button`,{className:K.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,k.jsx)(`span`,{className:K.editorName,children:b.name})]}),(0,k.jsx)(`div`,{className:K.imgContainer,children:(0,k.jsx)(`img`,{src:b.src,alt:b.name,className:K.imgView})})]});if(p===`pdf`&&b)return(0,k.jsxs)(`div`,{className:K.viewerRoot,children:[(0,k.jsxs)(`div`,{className:K.editorToolbar,children:[(0,k.jsx)(`button`,{className:K.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,k.jsx)(`span`,{className:K.editorName,children:b.name})]}),(0,k.jsx)(`iframe`,{className:K.pdfFrame,src:b.src,title:b.name})]});let se=t?.files??[],ce=t?.quota;return(0,k.jsxs)(`div`,{className:K.root,children:[ce&&(0,k.jsxs)(`div`,{className:K.quotaBar,children:[(0,k.jsxs)(`div`,{className:K.quotaText,children:[(0,k.jsxs)(`span`,{className:K.quotaUsed,children:[ce.usage,` of `,ce.limit,` used`]}),(0,k.jsxs)(`span`,{className:K.quotaPct,children:[ce.percentUsed,`%`]})]}),(0,k.jsx)(`div`,{className:K.quotaTrack,children:(0,k.jsx)(`div`,{className:K.quotaFill,style:{width:`${Math.min(ce.percentUsed,100)}%`,background:ce.percentUsed>90?`var(--red)`:ce.percentUsed>70?`var(--amber)`:`var(--green)`}})})]}),(0,k.jsxs)(`div`,{className:K.actionBar,children:[[``,`recent`,`starred`,`shared`].map(e=>(0,k.jsx)(`button`,{className:`${K.filterBtn} ${s===e?K.filterActive:``}`,onClick:()=>te(e),children:e?e.charAt(0).toUpperCase()+e.slice(1):`All Files`},e)),(0,k.jsx)(`div`,{className:K.spacer}),(0,k.jsx)(`button`,{className:K.newBtn,onClick:A,children:`+ New File`}),(0,k.jsx)(`button`,{className:K.uploadBtn,onClick:j,children:e(`drive.upload`)}),(0,k.jsx)(`input`,{ref:w,type:`file`,style:{display:`none`},onChange:e=>oe(e.target.files?.[0])})]}),(0,k.jsxs)(`div`,{className:K.searchRow,children:[(0,k.jsx)(`input`,{className:K.searchInput,value:d,onChange:e=>f(e.target.value),placeholder:`Search files…`,onKeyDown:e=>e.key===`Enter`&&ne()}),(0,k.jsx)(`button`,{className:K.searchBtn,onClick:ne,children:`Search`})]}),r&&(0,k.jsx)(`div`,{className:K.loading,children:(0,k.jsx)(`div`,{className:`spinner`})}),!r&&se.length===0&&(0,k.jsxs)(`div`,{className:K.empty,children:[e(`drive.noFiles`),` found`]}),(0,k.jsx)(`div`,{className:K.fileList,children:se.map(e=>{let t=qt(e),n=e.type===`image`,r=e.type===`pdf`||e.mimeType.includes(`pdf`);return(0,k.jsxs)(`div`,{className:K.fileRow,onClick:()=>{t?T(e.id,e.name):n?ie(e.id,e.name):r?O(e.id,e.name):e.webViewLink&&window.open(e.webViewLink,`_blank`)},style:{cursor:t||n||r||e.webViewLink?`pointer`:`default`},children:[(0,k.jsx)(`span`,{className:K.fileIcon,children:Kt(e.type,e.mimeType)}),(0,k.jsxs)(`div`,{className:K.fileInfo,children:[(0,k.jsx)(`div`,{className:K.fileName,children:e.name}),(0,k.jsxs)(`div`,{className:K.fileMeta,children:[e.modifiedTime?new Date(e.modifiedTime).toLocaleDateString():``,e.size?` · ${e.size}`:``,e.shared?` · Shared`:``,e.starred?` ★`:``]})]}),(0,k.jsxs)(`div`,{className:K.fileBtns,children:[t&&(0,k.jsx)(`button`,{className:K.editBtn,onClick:t=>{t.stopPropagation(),T(e.id,e.name)},children:`Edit`}),n&&(0,k.jsx)(`button`,{className:K.viewBtn,onClick:t=>{t.stopPropagation(),ie(e.id,e.name)},children:`View`}),r&&(0,k.jsx)(`button`,{className:K.pdfBtn,onClick:t=>{t.stopPropagation(),O(e.id,e.name)},children:`PDF`}),e.webViewLink&&(0,k.jsx)(`a`,{className:K.openBtn,href:e.webViewLink,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),children:`Open ↗`}),(0,k.jsx)(`button`,{className:K.delBtn,onClick:t=>{t.stopPropagation(),ae(e.id,e.name)},children:`Del`})]})]},e.id)})})]})}var q={root:`_root_a0x57_1`,loading:`_loading_a0x57_10`,errorBox:`_errorBox_a0x57_12`,errorHint:`_errorHint_a0x57_13`,userRow:`_userRow_a0x57_16`,avatar:`_avatar_a0x57_27`,userLogin:`_userLogin_a0x57_29`,userName:`_userName_a0x57_30`,disconnectBtn:`_disconnectBtn_a0x57_32`,repoBar:`_repoBar_a0x57_43`,repoInput:`_repoInput_a0x57_49`,issuesBtn:`_issuesBtn_a0x57_61`,prsBtn:`_prsBtn_a0x57_72`,repoPills:`_repoPills_a0x57_83`,repoPill:`_repoPill_a0x57_83`,issueCount:`_issueCount_a0x57_106`,tabs:`_tabs_a0x57_112`,tab:`_tab_a0x57_112`,tabActive:`_tabActive_a0x57_131`,markRead:`_markRead_a0x57_137`,content:`_content_a0x57_148`,empty:`_empty_a0x57_150`,notifRow:`_notifRow_a0x57_152`,issueRow:`_issueRow_a0x57_152`,prRow:`_prRow_a0x57_152`,notifRepo:`_notifRepo_a0x57_166`,notifType:`_notifType_a0x57_167`,notifTitle:`_notifTitle_a0x57_168`,notifMeta:`_notifMeta_a0x57_169`,issueNum:`_issueNum_a0x57_171`,issueTitle:`_issueTitle_a0x57_172`,issueMeta:`_issueMeta_a0x57_173`,issueLabel:`_issueLabel_a0x57_174`,prNum:`_prNum_a0x57_176`,prTitle:`_prTitle_a0x57_177`,prAuthor:`_prAuthor_a0x57_178`,prDraft:`_prDraft_a0x57_179`,prMeta:`_prMeta_a0x57_180`};function Yt(){let e=M(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(`notifs`),d=(e=``)=>{i(!0),E(e?`/api/github?repo=${encodeURIComponent(e)}`:`/api/github`).then(e=>{n(e??{}),i(!1)}).catch(()=>i(!1))};(0,_.useEffect)(()=>{d()},[]);let f=()=>{let e=s.trim();o(e),d(e),u(`issues`)},p=()=>{let e=s.trim();o(e),d(e),u(`prs`)},m=()=>D(`/api/github/mark-read`,{}).then(()=>d(a)),h=()=>{confirm(`Remove GitHub connection? You can reconnect anytime.`)&&D(`/api/config`,{key:`github-token`,value:``}).then(()=>{n(null),i(!1)})};if(r)return(0,k.jsx)(`div`,{className:q.loading,children:(0,k.jsx)(`div`,{className:`spinner`})});if(t?.error)return(0,k.jsxs)(`div`,{className:q.errorBox,children:[(0,k.jsx)(`div`,{children:t.error}),(0,k.jsxs)(`div`,{className:q.errorHint,children:[`Run: `,(0,k.jsx)(`code`,{children:`nha config set github-token YOUR_PAT`})]})]});let g=t?.user,v=t?.notifications??[],y=t?.issues??[],b=t?.prs??[];return(0,k.jsxs)(`div`,{className:q.root,children:[g?.login&&(0,k.jsxs)(`div`,{className:q.userRow,children:[g.avatar&&(0,k.jsx)(`img`,{src:g.avatar,className:q.avatar,alt:g.login}),(0,k.jsxs)(`div`,{style:{flex:1},children:[(0,k.jsxs)(`div`,{className:q.userLogin,children:[`@`,g.login]}),g.name&&(0,k.jsx)(`div`,{className:q.userName,children:g.name})]}),(0,k.jsx)(`button`,{className:q.disconnectBtn,onClick:h,children:`Disconnect`})]}),(0,k.jsxs)(`div`,{className:q.repoBar,children:[(0,k.jsx)(`input`,{className:q.repoInput,value:s,onChange:e=>c(e.target.value),placeholder:`owner/repo`,onKeyDown:e=>e.key===`Enter`&&f()}),(0,k.jsx)(`button`,{className:q.issuesBtn,onClick:f,children:`Issues`}),(0,k.jsx)(`button`,{className:q.prsBtn,onClick:p,children:`PRs`})]}),g?.repos&&g.repos.length>0&&(0,k.jsx)(`div`,{className:q.repoPills,children:g.repos.slice(0,12).map(e=>(0,k.jsxs)(`button`,{className:q.repoPill,onClick:()=>{c(e.full_name),o(e.full_name),d(e.full_name),u(`issues`)},title:e.description??``,children:[e.private?`🔒 `:``,e.full_name,e.open_issues?(0,k.jsx)(`span`,{className:q.issueCount,children:e.open_issues}):null]},e.full_name))}),(0,k.jsxs)(`div`,{className:q.tabs,children:[(0,k.jsxs)(`button`,{className:`${q.tab} ${l===`notifs`?q.tabActive:``}`,onClick:()=>u(`notifs`),children:[`Notifications `,v.length>0?`(${v.length})`:``]}),y.length>0&&(0,k.jsxs)(`button`,{className:`${q.tab} ${l===`issues`?q.tabActive:``}`,onClick:()=>u(`issues`),children:[`Issues (`,y.length,`)`]}),b.length>0&&(0,k.jsxs)(`button`,{className:`${q.tab} ${l===`prs`?q.tabActive:``}`,onClick:()=>u(`prs`),children:[`PRs (`,b.length,`)`]}),l===`notifs`&&v.length>0&&(0,k.jsx)(`button`,{className:q.markRead,onClick:m,children:`Mark all read`})]}),(0,k.jsxs)(`div`,{className:q.content,children:[l===`notifs`&&(v.length===0?(0,k.jsx)(`div`,{className:q.empty,children:`No notifications`}):v.map((e,t)=>(0,k.jsxs)(`a`,{className:q.notifRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,k.jsx)(`span`,{className:q.notifRepo,children:e.repo}),(0,k.jsxs)(`span`,{className:q.notifType,children:[`[`,e.type,`]`]}),(0,k.jsx)(`div`,{className:q.notifTitle,children:e.title}),(0,k.jsxs)(`div`,{className:q.notifMeta,children:[e.reason,` · `,e.updated]})]},t))),l===`issues`&&(y.length===0?(0,k.jsxs)(`div`,{className:q.empty,children:[e(`github.noIssues`),` for `,a]}):y.map((e,t)=>(0,k.jsxs)(`a`,{className:q.issueRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,k.jsxs)(`span`,{className:q.issueNum,children:[`#`,e.number]}),(0,k.jsx)(`span`,{className:q.issueTitle,children:e.title}),e.assignee&&(0,k.jsxs)(`span`,{className:q.issueMeta,children:[`→ `,e.assignee]}),e.labels&&(0,k.jsxs)(`span`,{className:q.issueLabel,children:[`[`,e.labels,`]`]}),(0,k.jsx)(`div`,{className:q.issueMeta,children:e.updated})]},t))),l===`prs`&&(b.length===0?(0,k.jsxs)(`div`,{className:q.empty,children:[`No PRs for `,a]}):b.map((e,t)=>(0,k.jsxs)(`a`,{className:q.prRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,k.jsxs)(`span`,{className:q.prNum,children:[`#`,e.number]}),(0,k.jsx)(`span`,{className:q.prTitle,children:e.title}),(0,k.jsxs)(`span`,{className:q.prAuthor,children:[`by `,e.author]}),e.draft&&(0,k.jsx)(`span`,{className:q.prDraft,children:`DRAFT`}),(0,k.jsx)(`div`,{className:q.prMeta,children:e.updated})]},t)))]})]})}var J={loading:`_loading_1h5ss_1`,errorBox:`_errorBox_1h5ss_3`,errorHint:`_errorHint_1h5ss_4`,twoPane:`_twoPane_1h5ss_7`,sidebar:`_sidebar_1h5ss_13`,sidebarTitle:`_sidebarTitle_1h5ss_24`,workspace:`_workspace_1h5ss_36`,searchRow:`_searchRow_1h5ss_42`,searchInput:`_searchInput_1h5ss_50`,searchBtn:`_searchBtn_1h5ss_63`,channelItem:`_channelItem_1h5ss_73`,channelActive:`_channelActive_1h5ss_83`,pageTitle:`_pageTitle_1h5ss_89`,pageMeta:`_pageMeta_1h5ss_97`,disconnectBtn:`_disconnectBtn_1h5ss_99`,empty:`_empty_1h5ss_110`,messagePane:`_messagePane_1h5ss_112`,channelHeader:`_channelHeader_1h5ss_120`,emptyPane:`_emptyPane_1h5ss_129`,message:`_message_1h5ss_112`,msgUser:`_msgUser_1h5ss_146`,msgText:`_msgText_1h5ss_147`,msgTs:`_msgTs_1h5ss_148`,openLink:`_openLink_1h5ss_150`,pageBody:`_pageBody_1h5ss_160`};function Xt(){let e=M(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)([]),l=()=>{i(!0),E(`/api/slack/channels`).then(e=>{n(e??{}),i(!1)}).catch(()=>i(!1))},u=e=>{o(e),E(`/api/slack/messages?channel=${e.id}`).then(e=>c(e?.messages??[]))};if((0,_.useEffect)(()=>{l()},[]),r)return(0,k.jsxs)(`div`,{className:J.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]});if(t?.error)return(0,k.jsxs)(`div`,{className:J.errorBox,children:[(0,k.jsx)(`div`,{children:t.error}),(0,k.jsxs)(`div`,{className:J.errorHint,children:[`Run: `,(0,k.jsx)(`code`,{children:`nha config set slack-token xoxb-YOUR-TOKEN`})]})]});let d=t?.channels??[];return(0,k.jsxs)(`div`,{className:J.twoPane,children:[(0,k.jsxs)(`div`,{className:J.sidebar,children:[(0,k.jsxs)(`div`,{className:J.sidebarTitle,children:[(0,k.jsx)(`span`,{children:`💬 Slack`}),t?.workspace&&(0,k.jsx)(`span`,{className:J.workspace,children:t.workspace})]}),d.length===0&&(0,k.jsx)(`div`,{className:J.empty,children:`No channels`}),d.map(e=>(0,k.jsxs)(`div`,{className:`${J.channelItem} ${a?.id===e.id?J.channelActive:``}`,onClick:()=>u(e),children:[`# `,e.name]},e.id)),(0,k.jsx)(`button`,{className:J.disconnectBtn,onClick:()=>D(`/api/config`,{key:`slack-token`,value:``}).then(l),children:`Disconnect`})]}),(0,k.jsx)(`div`,{className:J.messagePane,children:a?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:J.channelHeader,children:[`#`,a.name]}),s.length===0&&(0,k.jsx)(`div`,{className:J.empty,children:`No messages`}),s.map((e,t)=>(0,k.jsxs)(`div`,{className:J.message,children:[(0,k.jsx)(`span`,{className:J.msgUser,children:e.username||e.user||`Unknown`}),(0,k.jsx)(`span`,{className:J.msgText,children:e.text}),(0,k.jsx)(`span`,{className:J.msgTs,children:new Date(parseFloat(e.ts)*1e3).toLocaleTimeString()})]},t))]}):(0,k.jsx)(`div`,{className:J.emptyPane,children:`Select a channel`})})]})}function Zt(){let e=M(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),d=(e=``)=>{i(!0),E(e?`/api/notion/search?q=${encodeURIComponent(e)}`:`/api/notion`).then(e=>{n(e??{}),i(!1)}).catch(()=>i(!1))},f=e=>{o(e),E(`/api/notion/page?id=${encodeURIComponent(e.id)}`).then(e=>c(e?.content??``))};(0,_.useEffect)(()=>{d()},[]);let p=()=>d(l);if(r)return(0,k.jsxs)(`div`,{className:J.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]});if(t?.error)return(0,k.jsxs)(`div`,{className:J.errorBox,children:[(0,k.jsx)(`div`,{children:t.error}),(0,k.jsxs)(`div`,{className:J.errorHint,children:[`Run: `,(0,k.jsx)(`code`,{children:`nha config set notion-token secret_YOUR_TOKEN`})]})]});let m=t?.pages??[];return(0,k.jsxs)(`div`,{className:J.twoPane,children:[(0,k.jsxs)(`div`,{className:J.sidebar,children:[(0,k.jsx)(`div`,{className:J.sidebarTitle,children:`📋 Notion`}),(0,k.jsxs)(`div`,{className:J.searchRow,children:[(0,k.jsx)(`input`,{className:J.searchInput,value:l,onChange:e=>u(e.target.value),placeholder:`Search pages…`,onKeyDown:e=>e.key===`Enter`&&p()}),(0,k.jsx)(`button`,{className:J.searchBtn,onClick:p,children:`Go`})]}),m.length===0&&(0,k.jsx)(`div`,{className:J.empty,children:`No pages found`}),m.map(e=>(0,k.jsxs)(`div`,{className:`${J.channelItem} ${a?.id===e.id?J.channelActive:``}`,onClick:()=>f(e),children:[(0,k.jsx)(`div`,{className:J.pageTitle,children:e.title||`Untitled`}),e.last_edited&&(0,k.jsx)(`div`,{className:J.pageMeta,children:e.last_edited.slice(0,10)})]},e.id)),(0,k.jsx)(`button`,{className:J.disconnectBtn,onClick:()=>D(`/api/config`,{key:`notion-token`,value:``}).then(()=>d()),children:`Disconnect`})]}),(0,k.jsx)(`div`,{className:J.messagePane,children:a?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:J.channelHeader,children:a.title}),a.url&&(0,k.jsx)(`a`,{className:J.openLink,href:a.url,target:`_blank`,rel:`noreferrer`,children:`Open in Notion ↗`}),(0,k.jsx)(`div`,{className:J.pageBody,dangerouslySetInnerHTML:{__html:me(s||`Loading…`)}})]}):(0,k.jsx)(`div`,{className:J.emptyPane,children:`Select a page`})})]})}var Y={root:`_root_1l3ll_1`,sidebar:`_sidebar_1l3ll_8`,sidebarHeader:`_sidebarHeader_1l3ll_18`,sidebarTitle:`_sidebarTitle_1l3ll_19`,sidebarBtns:`_sidebarBtns_1l3ll_21`,createBtn:`_createBtn_1l3ll_22`,joinBtn:`_joinBtn_1l3ll_23`,noChannels:`_noChannels_1l3ll_25`,channelItem:`_channelItem_1l3ll_27`,channelActive:`_channelActive_1l3ll_29`,channelName:`_channelName_1l3ll_30`,channelMeta:`_channelMeta_1l3ll_31`,channelCode:`_channelCode_1l3ll_32`,channelDel:`_channelDel_1l3ll_34`,main:`_main_1l3ll_38`,chatHeader:`_chatHeader_1l3ll_41`,chatChannelName:`_chatChannelName_1l3ll_50`,chatChannelId:`_chatChannelId_1l3ll_51`,statusDot:`_statusDot_1l3ll_52`,connected:`_connected_1l3ll_53`,disconnected:`_disconnected_1l3ll_54`,statusText:`_statusText_1l3ll_55`,messages:`_messages_1l3ll_58`,emptyMsgs:`_emptyMsgs_1l3ll_66`,msg:`_msg_1l3ll_68`,msgSelf:`_msgSelf_1l3ll_69`,msgOther:`_msgOther_1l3ll_70`,msgSender:`_msgSender_1l3ll_71`,msgContent:`_msgContent_1l3ll_72`,msgTime:`_msgTime_1l3ll_82`,inputRow:`_inputRow_1l3ll_85`,textInput:`_textInput_1l3ll_86`,sendBtn:`_sendBtn_1l3ll_88`,welcome:`_welcome_1l3ll_92`,welcomeIcon:`_welcomeIcon_1l3ll_103`,welcomeTitle:`_welcomeTitle_1l3ll_104`,welcomeSub:`_welcomeSub_1l3ll_105`,welcomeBox:`_welcomeBox_1l3ll_106`,welcomeBoxTitle:`_welcomeBoxTitle_1l3ll_107`,welcomeStep:`_welcomeStep_1l3ll_108`,welcomeHint:`_welcomeHint_1l3ll_109`,cliCmd:`_cliCmd_1l3ll_110`};function Qt(e){return e.content||e.plaintext||e.message||``}function $t(e){return e.senderName||e.senderFingerprint?.slice(0,8)||e.sender||`unknown`}function en(){let e=M(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(!1),[d]=(0,_.useState)(()=>`nha-ui-${Math.random().toString(36).slice(2,8)}`),f=(0,_.useRef)(null),p=(0,_.useRef)(null);(0,_.useEffect)(()=>{E(`/api/collab/channels`).then(e=>{n(e?.channels??[])}).catch(()=>{})},[]),(0,_.useEffect)(()=>{if(r)return m(r),h(r),()=>{f.current?.close(),u(!1)}},[r]);let m=e=>{E(`/api/collab/messages?channelId=${e}`).then(e=>{e?.messages&&(o(e.messages),setTimeout(()=>{p.current&&(p.current.scrollTop=p.current.scrollHeight)},50))}).catch(()=>{})},h=e=>{f.current?.close();let t=window.location.protocol===`https:`?`wss:`:`ws:`,n=window.location.port===`3030`||window.location.port===`3031`?`3020`:window.location.port||`3020`,r=`${t}//${window.location.hostname}:${n}/ws/alexandria?channel=${e}&agentId=${encodeURIComponent(d)}`,i=new WebSocket(r);f.current=i,i.onopen=()=>u(!0),i.onclose=()=>u(!1),i.onmessage=e=>{try{let t=JSON.parse(e.data);if(!t)return;o(e=>[...e,{...t,id:t.id||Date.now().toString(),type:`message`}]),p.current&&(p.current.scrollTop=p.current.scrollHeight)}catch{}}},g=async()=>{let e=prompt(`Channel name:`);if(!e)return;let t=await D(`/api/collab/create`,{name:e}).catch(()=>null);if(!t||t.error){alert(t?.error||`Error creating channel`);return}let r=t.id;await D(`/api/collab/channels`,{id:r,name:e,role:`creator`}).catch(()=>{});let a={id:r,name:e,role:`creator`};n(e=>[...e,a]),i(r),prompt(`Share this invite code with collaborators:`,r)},v=async()=>{let e=prompt(`Invite code:`);if(!e)return;let t=await D(`/api/collab/join`,{channelId:e}).catch(()=>null);if(!t||t.error){alert(t?.error||`Error joining channel`);return}let r=t.name||e.slice(0,8);await D(`/api/collab/channels`,{id:e,name:r,role:`member`}).catch(()=>{}),n(t=>[...t,{id:e,name:r,role:`member`}]),i(e)},y=async e=>{confirm(`Delete this channel? Messages will be lost.`)&&(D(`/api/collab/delete`,{channelId:e}).catch(()=>{}),n(t=>t.filter(t=>t.id!==e)),r===e&&(i(null),o([]),f.current?.close(),u(!1)))},b=async()=>{let e=s.trim();if(!e||!r)return;c(``);let t=await D(`/api/collab/send`,{channelId:r,message:e}).catch(()=>null);t?.error&&alert(t.error),l||m(r)},x=e=>{navigator.clipboard.writeText(e).catch(()=>{})};return(0,k.jsxs)(`div`,{className:Y.root,children:[(0,k.jsxs)(`div`,{className:Y.sidebar,children:[(0,k.jsx)(`div`,{className:Y.sidebarHeader,children:(0,k.jsx)(`div`,{className:Y.sidebarTitle,children:`Alexandria`})}),(0,k.jsxs)(`div`,{className:Y.sidebarBtns,children:[(0,k.jsx)(`button`,{className:Y.createBtn,onClick:g,children:`+ Create`}),(0,k.jsx)(`button`,{className:Y.joinBtn,onClick:v,children:`Join`})]}),t.length===0?(0,k.jsxs)(`div`,{className:Y.noChannels,children:[e(`collab.noChannels`),` yet`]}):t.map(e=>(0,k.jsxs)(`div`,{className:`${Y.channelItem} ${r===e.id?Y.channelActive:``}`,onClick:()=>i(e.id),children:[(0,k.jsx)(`div`,{className:Y.channelName,children:e.name}),(0,k.jsxs)(`div`,{className:Y.channelMeta,children:[(0,k.jsxs)(`span`,{className:Y.channelCode,onClick:t=>{t.stopPropagation(),x(e.id)},title:`Click to copy invite code`,children:[e.id.slice(0,8),`…`]}),(0,k.jsx)(`button`,{className:Y.channelDel,onClick:t=>{t.stopPropagation(),y(e.id)},children:`del`})]})]},e.id))]}),(0,k.jsx)(`div`,{className:Y.main,children:r?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:Y.chatHeader,children:[(0,k.jsx)(`div`,{className:Y.chatChannelName,children:t.find(e=>e.id===r)?.name??r.slice(0,12)}),(0,k.jsx)(`div`,{className:Y.chatChannelId,children:r}),(0,k.jsx)(`div`,{className:`${Y.statusDot} ${l?Y.connected:Y.disconnected}`}),(0,k.jsx)(`span`,{className:Y.statusText,children:l?`Live`:`HTTP`})]}),(0,k.jsxs)(`div`,{className:Y.messages,ref:p,children:[a.length===0&&(0,k.jsx)(`div`,{className:Y.emptyMsgs,children:`No messages yet`}),a.map((e,t)=>{let n=$t(e),r=Qt(e),i=n===d;return(0,k.jsxs)(`div`,{className:`${Y.msg} ${i?Y.msgSelf:Y.msgOther}`,children:[!i&&(0,k.jsx)(`div`,{className:Y.msgSender,children:n}),(0,k.jsx)(`div`,{className:Y.msgContent,children:r}),(0,k.jsx)(`div`,{className:Y.msgTime,children:new Date(e.timestamp).toLocaleTimeString()})]},e.id||t)})]}),(0,k.jsxs)(`div`,{className:Y.inputRow,children:[(0,k.jsx)(`input`,{className:Y.textInput,value:s,onChange:e=>c(e.target.value),placeholder:`Send an encrypted message…`,onKeyDown:e=>e.key===`Enter`&&!e.shiftKey&&b()}),(0,k.jsx)(`button`,{className:Y.sendBtn,onClick:b,disabled:!s.trim(),children:e(`collab.send`)})]})]}):(0,k.jsxs)(`div`,{className:Y.welcome,children:[(0,k.jsx)(`div`,{className:Y.welcomeIcon,children:`🔐`}),(0,k.jsx)(`div`,{className:Y.welcomeTitle,children:`Alexandria`}),(0,k.jsx)(`div`,{className:Y.welcomeSub,children:`E2E encrypted messaging for AI agents and teams`}),(0,k.jsxs)(`div`,{className:Y.welcomeBox,children:[(0,k.jsx)(`div`,{className:Y.welcomeBoxTitle,children:`HOW TO USE`}),(0,k.jsxs)(`div`,{className:Y.welcomeStep,children:[(0,k.jsx)(`strong`,{children:`1. Create a channel`}),` — Click [+ Create] in the sidebar. Give it a name.`]}),(0,k.jsx)(`div`,{className:Y.welcomeHint,children:`You get an invite code. Share it with your team or another AI session.`}),(0,k.jsxs)(`div`,{className:Y.welcomeStep,children:[(0,k.jsx)(`strong`,{children:`2. Others join`}),` — They click [Join] and paste the invite code.`]}),(0,k.jsx)(`div`,{className:Y.welcomeHint,children:`Works from this web UI, the Android app, or the CLI.`}),(0,k.jsxs)(`div`,{className:Y.welcomeStep,children:[(0,k.jsx)(`strong`,{children:`3. Chat encrypted`}),` — All messages are E2E encrypted. The server sees only ciphertext.`]})]}),(0,k.jsxs)(`div`,{className:Y.welcomeBox,children:[(0,k.jsx)(`div`,{className:Y.welcomeBoxTitle,children:`FROM CLI (same channels)`}),(0,k.jsx)(`div`,{className:Y.cliCmd,children:`nha collab create "Project X"`}),(0,k.jsx)(`div`,{className:Y.cliCmd,children:`nha collab join <invite-code>`}),(0,k.jsx)(`div`,{className:Y.cliCmd,children:`nha collab send "Hello from CLI"`}),(0,k.jsx)(`div`,{className:Y.cliCmd,children:`nha collab read`})]})]})})]})}var X={root:`_root_14zra_2`,header:`_header_14zra_10`,title:`_title_14zra_21`,subtitle:`_subtitle_14zra_28`,headerTabs:`_headerTabs_14zra_34`,tabBtn:`_tabBtn_14zra_40`,tabActive:`_tabActive_14zra_51`,body:`_body_14zra_58`,editor:`_editor_14zra_67`,examples:`_examples_14zra_75`,sectionLabel:`_sectionLabel_14zra_81`,examplePills:`_examplePills_14zra_89`,examplePill:`_examplePill_14zra_89`,editorCols:`_editorCols_14zra_109`,leftSidebar:`_leftSidebar_14zra_119`,panel:`_panel_14zra_128`,panelHeader:`_panelHeader_14zra_135`,panelTitle:`_panelTitle_14zra_142`,addBtn:`_addBtn_14zra_149`,blockLabel:`_blockLabel_14zra_160`,blockCheck:`_blockCheck_14zra_170`,authField:`_authField_14zra_173`,authFieldInput:`_authFieldInput_14zra_183`,authFieldSelect:`_authFieldSelect_14zra_193`,authFieldReq:`_authFieldReq_14zra_204`,removeFieldBtn:`_removeFieldBtn_14zra_205`,skillsList:`_skillsList_14zra_208`,skillRow:`_skillRow_14zra_210`,skillIcon:`_skillIcon_14zra_218`,skillName:`_skillName_14zra_220`,skillBadge:`_skillBadge_14zra_229`,skillBadge_skill:`_skillBadge_skill_14zra_237`,skillBadge_memory:`_skillBadge_memory_14zra_238`,skillBadge_provider:`_skillBadge_provider_14zra_239`,skillBadge_log:`_skillBadge_log_14zra_240`,skillEmpty:`_skillEmpty_14zra_242`,skillBtn:`_skillBtn_14zra_244`,skillsEmpty:`_skillsEmpty_14zra_246`,snapshotRow:`_snapshotRow_14zra_249`,snapshotTs:`_snapshotTs_14zra_258`,snapshotCount:`_snapshotCount_14zra_259`,snapshotBtn:`_snapshotBtn_14zra_260`,genStatus:`_genStatus_14zra_263`,repairStatus:`_repairStatus_14zra_265`,repairStatusTitle:`_repairStatusTitle_14zra_266`,repairStatusProg:`_repairStatusProg_14zra_267`,repairStatusFile:`_repairStatusFile_14zra_268`,actionRow:`_actionRow_14zra_271`,actionBtn:`_actionBtn_14zra_273`,actionBtnIcon:`_actionBtnIcon_14zra_275`,actionBtnActive:`_actionBtnActive_14zra_276`,repairBtn:`_repairBtn_14zra_278`,sandboxBtn:`_sandboxBtn_14zra_280`,statsBar:`_statsBar_14zra_282`,rightPanel:`_rightPanel_14zra_285`,rightTabBar:`_rightTabBar_14zra_296`,rightTab:`_rightTab_14zra_296`,rightTabActive:`_rightTabActive_14zra_313`,repairBar:`_repairBar_14zra_316`,repairBarRow:`_repairBarRow_14zra_326`,repairBarIcon:`_repairBarIcon_14zra_327`,repairBarLabel:`_repairBarLabel_14zra_328`,repairBarFile:`_repairBarFile_14zra_329`,repairBarCounter:`_repairBarCounter_14zra_330`,repairBarTime:`_repairBarTime_14zra_331`,genBar:`_genBar_14zra_333`,genBarRow:`_genBarRow_14zra_343`,genBarRobot:`_genBarRobot_14zra_344`,robotBob:`_robotBob_14zra_1`,genBarLabel:`_genBarLabel_14zra_345`,genBarFile:`_genBarFile_14zra_346`,genBarCounter:`_genBarCounter_14zra_347`,genBarTime:`_genBarTime_14zra_348`,progressTrack:`_progressTrack_14zra_350`,repairProgress:`_repairProgress_14zra_351`,genProgress:`_genProgress_14zra_352`,genDots:`_genDots_14zra_355`,dot:`_dot_14zra_356`,dot1:`_dot1_14zra_357`,dotBounce:`_dotBounce_14zra_1`,dot2:`_dot2_14zra_358`,dot3:`_dot3_14zra_359`,stopBtn:`_stopBtn_14zra_362`,codeArea:`_codeArea_14zra_365`,sandboxWrap:`_sandboxWrap_14zra_366`,sandboxFrame:`_sandboxFrame_14zra_367`,sandboxEmpty:`_sandboxEmpty_14zra_368`,sandboxStartBtn:`_sandboxStartBtn_14zra_369`,noFiles:`_noFiles_14zra_371`,noFilesIcon:`_noFilesIcon_14zra_372`,codeLayout:`_codeLayout_14zra_374`,codeViewer:`_codeViewer_14zra_376`,codeHeader:`_codeHeader_14zra_384`,codeFileIcon:`_codeFileIcon_14zra_397`,codeFileName:`_codeFileName_14zra_398`,codeFileMeta:`_codeFileMeta_14zra_399`,fileError:`_fileError_14zra_401`,fileSyntaxError:`_fileSyntaxError_14zra_402`,filePending:`_filePending_14zra_403`,code:`_code_14zra_365`,codeError:`_codeError_14zra_418`,codeSyntaxError:`_codeSyntaxError_14zra_419`,fileSidebar:`_fileSidebar_14zra_422`,fileSidebarHeader:`_fileSidebarHeader_14zra_431`,fileTab:`_fileTab_14zra_441`,fileTabActive:`_fileTabActive_14zra_457`,fileTabError:`_fileTabError_14zra_458`,fileTabRow:`_fileTabRow_14zra_460`,fileTabIcon:`_fileTabIcon_14zra_461`,fileTabName:`_fileTabName_14zra_462`,fileTabDir:`_fileTabDir_14zra_463`,fileTabMeta:`_fileTabMeta_14zra_464`,projectsList:`_projectsList_14zra_467`,emptyProjects:`_emptyProjects_14zra_469`,emptyIcon:`_emptyIcon_14zra_470`,emptyHint:`_emptyHint_14zra_471`,projectCard:`_projectCard_14zra_473`,projectInfo:`_projectInfo_14zra_474`,projectName:`_projectName_14zra_475`,projectDesc:`_projectDesc_14zra_476`,projectMeta:`_projectMeta_14zra_477`,openBtn:`_openBtn_14zra_478`,deleteBtn:`_deleteBtn_14zra_479`,planBanner:`_planBanner_14zra_482`,planTitle:`_planTitle_14zra_491`,planText:`_planText_14zra_492`,planActions:`_planActions_14zra_493`,planApprove:`_planApprove_14zra_494`,planReject:`_planReject_14zra_495`,grepPanel:`_grepPanel_14zra_498`,grepRow:`_grepRow_14zra_507`,grepInput:`_grepInput_14zra_508`,grepBtn:`_grepBtn_14zra_510`,grepClose:`_grepClose_14zra_511`,grepCount:`_grepCount_14zra_512`,grepResults:`_grepResults_14zra_513`,grepEmpty:`_grepEmpty_14zra_514`,grepMatch:`_grepMatch_14zra_515`,grepMatchFile:`_grepMatchFile_14zra_517`,grepMatchLine:`_grepMatchLine_14zra_518`,diffPanel:`_diffPanel_14zra_521`,diffHeader:`_diffHeader_14zra_530`,diffClose:`_diffClose_14zra_531`,diffFile:`_diffFile_14zra_532`,diffSummary:`_diffSummary_14zra_533`,diffArrow:`_diffArrow_14zra_534`,diffFileName:`_diffFileName_14zra_535`,diffAdded:`_diffAdded_14zra_536`,diffRemoved:`_diffRemoved_14zra_537`,diffContent:`_diffContent_14zra_538`,diffInline:`_diffInline_14zra_541`,diffInlineHeader:`_diffInlineHeader_14zra_542`,diffRemLine:`_diffRemLine_14zra_543`,diffAddLine:`_diffAddLine_14zra_544`,chatPanel:`_chatPanel_14zra_547`,chatMessages:`_chatMessages_14zra_556`,chatWelcome:`_chatWelcome_14zra_558`,chatUser:`_chatUser_14zra_560`,chatUserBubble:`_chatUserBubble_14zra_561`,chatAttachPreviews:`_chatAttachPreviews_14zra_562`,chatAttachBadge:`_chatAttachBadge_14zra_563`,chatSystem:`_chatSystem_14zra_565`,chatSystemBubble:`_chatSystemBubble_14zra_566`,chatSyntaxErr:`_chatSyntaxErr_14zra_567`,chatAgent:`_chatAgent_14zra_569`,chatAgentCard:`_chatAgentCard_14zra_570`,chatAgentHeader:`_chatAgentHeader_14zra_571`,chatAgentRobot:`_chatAgentRobot_14zra_572`,chatAgentRobotAnim:`_chatAgentRobotAnim_14zra_573`,chatAgentLabel:`_chatAgentLabel_14zra_574`,chatRunningDots:`_chatRunningDots_14zra_575`,chatAgentText:`_chatAgentText_14zra_576`,chatToolBadges:`_chatToolBadges_14zra_577`,toolBadge:`_toolBadge_14zra_578`,toolBadgeOk:`_toolBadgeOk_14zra_579`,toolBadgeErr:`_toolBadgeErr_14zra_580`,cursor:`_cursor_14zra_582`,blink:`_blink_14zra_1`,attachPreviews:`_attachPreviews_14zra_585`,attachBadge:`_attachBadge_14zra_586`,removeAttachBtn:`_removeAttachBtn_14zra_587`,projNameRow:`_projNameRow_14zra_590`,projNameLabel:`_projNameLabel_14zra_591`,projNameInput:`_projNameInput_14zra_592`,projActiveRow:`_projActiveRow_14zra_593`,projActiveName:`_projActiveName_14zra_594`,chatInputRow:`_chatInputRow_14zra_597`,attachLabel:`_attachLabel_14zra_598`,chatTextarea:`_chatTextarea_14zra_599`,chatSendCol:`_chatSendCol_14zra_602`,chatSendBtn:`_chatSendBtn_14zra_603`,chatStopBtn:`_chatStopBtn_14zra_605`,modalOverlay:`_modalOverlay_14zra_608`,modal:`_modal_14zra_608`,modalHeader:`_modalHeader_14zra_630`,modalTitle:`_modalTitle_14zra_631`,modalClose:`_modalClose_14zra_632`,modalBody:`_modalBody_14zra_634`,modalRow:`_modalRow_14zra_636`,modalField:`_modalField_14zra_637`,modalLabel:`_modalLabel_14zra_638`,modalLabelRow:`_modalLabelRow_14zra_639`,modalSelect:`_modalSelect_14zra_641`,modalInput:`_modalInput_14zra_642`,modalHint:`_modalHint_14zra_645`,modalAiBox:`_modalAiBox_14zra_647`,modalAiRow:`_modalAiRow_14zra_648`,modalAiDesc:`_modalAiDesc_14zra_649`,modalAiBtn:`_modalAiBtn_14zra_650`,modalContentArea:`_modalContentArea_14zra_653`,logView:`_logView_14zra_656`,modalFooter:`_modalFooter_14zra_658`,modalCancelBtn:`_modalCancelBtn_14zra_659`,modalSaveBtn:`_modalSaveBtn_14zra_660`},tn=[{name:`MySaaS`,desc:`SaaS product landing page. Hero: large headline, subheadline, two CTA buttons (Start free trial / Watch demo), animated gradient background. Features section: 3-column grid with icon, title, description for 6 features. Pricing section: 3 cards (Free / Pro $29/mo / Enterprise). Testimonials: 3 customer quotes. FAQ accordion: 5 questions. Footer with links and social icons. Sticky nav.`},{name:`MyShop`,desc:`E-commerce storefront homepage. Nav with logo, search bar, cart badge, hamburger mobile menu. Hero banner. Category strip: 6 cards. Featured products grid: 8 cards with rating, price, Add to Cart, wishlist. Promo banner. Newsletter signup. Responsive.`},{name:`MyBlog`,desc:`Blog platform homepage. Nav with category links. Hero: featured article card. Article grid: 6 cards. Sidebar: recent posts, tags cloud, newsletter widget. Pagination. Author bio section. Minimal footer.`},{name:`MyPortfolio`,desc:`Developer portfolio. Nav with scroll hide/show. Hero: typewriter role subtitle, CTA buttons. Work section: 6 project cards. Skills grouped by category with bars. About: timeline of milestones. Contact form. Scroll entrance animations via Intersection Observer.`},{name:`MyRestaurant`,desc:`Restaurant website. Nav: logo center, transparent→solid on scroll. Hero: full-viewport with overlay. Menu preview: tabbed (Starters/Mains/Desserts/Drinks). Reservation form. Gallery 3x3 mosaic. Chef section. Testimonials horizontal scroll.`},{name:`MyJobBoard`,desc:`Job board homepage. Hero search widget. Stats strip. Featured jobs list: 8 cards with company, location badge, salary, Quick Apply. Filter sidebar. Top companies section. Category cards. Newsletter.`}],nn=[{key:`auth`,label:`Auth (register/login/JWT)`,icon:`🔒`},{key:`cookieBanner`,label:`GDPR Cookie Banner`,icon:`🍪`},{key:`securityMiddleware`,label:`Security Middleware`,icon:`🛡️`},{key:`emailVerification`,label:`Email Verification`,icon:`✉️`}],rn={js:`📄`,ts:`📄`,css:`🎨`,html:`🌐`,json:`{`,md:`📑`,sql:`🗂`,env:`🔐`,conf:`⚙`,lock:`🔒`};function an(e){return rn[e.split(`.`).pop()?.toLowerCase()??``]??`📄`}function on(e){let t=new TextEncoder().encode(e).length;return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(2)} MB`}function sn(e){return e===`memory`?`🧠`:e===`provider`?`🤖`:e===`log`?`📄`:`📋`}function cn(){let e=M(),[t,n]=(0,_.useState)(`new`),[r,i]=(0,_.useState)(`files`),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)({auth:!0,cookieBanner:!0,securityMiddleware:!0,emailVerification:!0}),[d,f]=(0,_.useState)([{label:`Email`,type:`email`,required:!0},{label:`Password`,type:`password`,required:!0},{label:`Name`,type:`text`,required:!0}]),[p,m]=(0,_.useState)([]),[h,g]=(0,_.useState)(0),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(!1),[S,C]=(0,_.useState)(0),[w,ee]=(0,_.useState)(0),[te,ne]=(0,_.useState)(``),[T,re]=(0,_.useState)({fi:0,total:0,name:``}),[ie,O]=(0,_.useState)(null),[ae,A]=(0,_.useState)([]),[j,oe]=(0,_.useState)(``),[se,ce]=(0,_.useState)(!1),[le,ue]=(0,_.useState)([]),[N,de]=(0,_.useState)(null),[fe,pe]=(0,_.useState)([]),[me,P]=(0,_.useState)(!1),[he,ge]=(0,_.useState)(null),[_e,ve]=(0,_.useState)([]),[F,ye]=(0,_.useState)(!1),[be,xe]=(0,_.useState)(``),[I,L]=(0,_.useState)([]),[Se,Ce]=(0,_.useState)([]),[we,Te]=(0,_.useState)([]),[Ee,De]=(0,_.useState)(null),[Oe,ke]=(0,_.useState)(`0s`),[Ae,je]=(0,_.useState)(`0s`),R=(0,_.useRef)(0),Me=(0,_.useRef)(0),Ne=(0,_.useRef)(null),Pe=(0,_.useRef)(null),Fe=(0,_.useRef)(null),Ie=(0,_.useRef)(null);function Le(e){let t=Math.floor((Date.now()-e)/1e3),n=Math.floor(t/60);return(n>0?`${n}m `:``)+`${t%60}s`}(0,_.useEffect)(()=>(v||b?Ne.current=setInterval(()=>{v&&ke(Le(R.current)),b&&je(Le(Me.current))},1e3):Ne.current&&=(clearInterval(Ne.current),null),()=>{Ne.current&&clearInterval(Ne.current)}),[v,b]);function Re(){Fe.current&&(Fe.current.scrollTop=Fe.current.scrollHeight)}(0,_.useEffect)(()=>{Re()},[ae]),(0,_.useEffect)(()=>{a&&p.length>0&&!me&&(P(!0),E(`/api/studio/webcraft/skills/${encodeURIComponent(a)}`).then(e=>{e?.skills&&pe(e.skills)}).catch(()=>{}))},[a,p.length,me]);async function ze(e,t){if(v||!e||e.length<5)return;y(!0),m([]),g(0),re({fi:0,total:0,name:``}),R.current=Date.now(),ke(`0s`),Pe.current=new AbortController;let n=Date.now();try{let r=await fetch(`/api/studio/webcraft/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},signal:Pe.current.signal,body:JSON.stringify({projectName:t,description:e,blocks:l,authFields:d})});if(!r.ok||!r.body){y(!1);return}let i=r.body.getReader(),a=new TextDecoder,o=``,s=[];for(;;){let{done:e,value:t}=await i.read();if(e)break;o+=a.decode(t,{stream:!0});let r=o.split(`
530
+ Be concise. Highlight what each agent contributed uniquely. Give your own synthesis verdict at the end.`},e=>{i+=e,g(i)})}catch{}finally{y(!1)}},he=e=>{let t=window.SpeechRecognition??window.webkitSpeechRecognition;if(!t){alert(`Speech recognition not supported.`);return}let n=T.current.get(e);if(l.find(t=>t.agent.id===e)?.voiceActive&&n){n.stop(),N(e,{voiceActive:!1});return}let r=new t;T.current.set(e,r),r.lang=`it-IT`,r.continuous=!1,r.interimResults=!1,r.onresult=t=>{let n=t.results[0][0].transcript;N(e,{input:(l.find(t=>t.agent.id===e)?.input??``)+(l.find(t=>t.agent.id===e)?.input?` `:``)+n})},r.onend=()=>N(e,{voiceActive:!1}),r.onerror=()=>N(e,{voiceActive:!1}),r.start(),N(e,{voiceActive:!0})},ge=(e,t)=>{if(!t)return;let n=t.name.toLowerCase().endsWith(`.pdf`)||t.type===`application/pdf`,r=new FileReader;n?(r.onload=n=>{let r=(n.target?.result).split(`,`)[1];N(e,{attachedFile:{name:t.name,size:t.size,base64:r,mimeType:`application/pdf`,isPDF:!0},attachedImage:null})},r.readAsDataURL(t)):(r.onload=n=>{N(e,{attachedFile:{name:t.name,size:t.size,content:n.target?.result},attachedImage:null})},r.readAsText(t))},_e=(e,t)=>{if(!t)return;let n=new FileReader;n.onload=n=>{let r=(n.target?.result).split(`,`)[1];N(e,{attachedImage:{name:t.name,size:t.size,base64:r,mimeType:t.type||`image/jpeg`},attachedFile:null})},n.readAsDataURL(t)},ve=()=>{x({name:``,tagline:``,systemPrompt:``}),C(`create`),ee(``)},F=async e=>{let t=await E(`/api/agents/${e.id}`).catch(()=>null);x({name:e.id,tagline:t?.tagline??e.description,systemPrompt:t?.systemPrompt??``}),C(`edit`),ee(``)},ye=async()=>{if(b){if(!b.tagline.trim()||!b.systemPrompt.trim()){ee(`Tagline and system prompt are required.`);return}ne(!0),ee(``);try{if(S===`create`){let e=b.name.toLowerCase().replace(/[^a-z0-9_-]/g,``);if(!e){ee(`Agent name required (lowercase, no spaces).`),ne(!1);return}let t=await D(`/api/agents`,{name:e,tagline:b.tagline,systemPrompt:b.systemPrompt});if(t?.error){ee(`Error: `+t.error),ne(!1);return}}else await D(`/api/agents/${b.name}`,{tagline:b.tagline,systemPrompt:b.systemPrompt,category:`custom`},`PUT`);x(null),oe()}catch(e){ee(`Error: `+e.message)}finally{ne(!1)}}},be=e=>{confirm(`Delete agent "${e.label}"?`)&&D(`/api/agents/${e.id}`,{},`DELETE`).then(()=>oe())};return r?(0,k.jsx)(`div`,{className:G.root,children:(0,k.jsx)(`div`,{className:G.loading,children:(0,k.jsx)(`div`,{className:`spinner`})})}):(0,k.jsxs)(`div`,{className:G.root,children:[(0,k.jsxs)(`div`,{className:G.gridSection,children:[(0,k.jsxs)(`div`,{className:G.gridHeader,children:[(0,k.jsxs)(`div`,{className:G.headerRow,children:[(0,k.jsx)(`input`,{className:G.search,value:a,onChange:e=>o(e.target.value),placeholder:`Search agents…`}),(0,k.jsx)(`button`,{className:G.createBtn,onClick:ve,children:`+ Create`})]}),(0,k.jsx)(`div`,{className:G.catTabs,children:se.map(e=>(0,k.jsxs)(`button`,{className:`${G.catTab} ${s===e?G.catActive:``}`,onClick:()=>c(e),children:[e,` (`,e===`All`?t.length:t.filter(t=>t.category===e).length,`)`]},e))})]}),(0,k.jsx)(`div`,{className:G.grid,children:ce.map(e=>{let t=l.some(t=>t.agent.id===e.id);return(0,k.jsxs)(`div`,{className:`${G.agentCard} ${t?G.agentActive:``}`,onClick:()=>le(e),children:[(0,k.jsxs)(`div`,{className:G.agentCardTop,children:[(0,k.jsx)(`div`,{className:G.agentIcon,children:e.icon}),e.isCustom&&(0,k.jsxs)(`div`,{className:G.agentActions,children:[(0,k.jsx)(`button`,{className:G.agentEditBtn,onClick:t=>{t.stopPropagation(),F(e)},children:`✏️`}),(0,k.jsx)(`button`,{className:G.agentDelBtn,onClick:t=>{t.stopPropagation(),be(e)},children:`🗑`})]})]}),(0,k.jsx)(`div`,{className:G.agentLabel,children:e.label}),(0,k.jsx)(`div`,{className:G.agentDesc,children:e.description}),(0,k.jsx)(`div`,{className:G.agentCat,children:e.category})]},e.id)})})]}),(0,k.jsx)(`div`,{className:G.chatArea,children:l.length===0?(0,k.jsxs)(`div`,{className:G.emptyChat,children:[(0,k.jsx)(`span`,{children:`Click an agent above to open a chat`}),(0,k.jsx)(`span`,{className:G.emptyChatHint,children:`Open multiple agents to run them in parallel`})]}):l.map(e=>{let{agent:t}=e,n=e.attachedFile?`📎 ${e.attachedFile.name}`:e.attachedImage?`🖼 ${e.attachedImage.name}`:null;return(0,k.jsxs)(`div`,{className:G.chatPanel,children:[(0,k.jsxs)(`div`,{className:G.chatHeader,children:[(0,k.jsx)(`span`,{className:G.chatIcon,children:t.icon}),(0,k.jsxs)(`div`,{className:G.chatHeaderInfo,children:[(0,k.jsx)(`div`,{className:G.chatAgentName,children:t.label}),(0,k.jsx)(`div`,{className:G.chatAgentDesc,children:t.description})]}),(0,k.jsx)(`button`,{className:G.closeChat,onClick:()=>ue(t.id),children:`✕`})]}),(0,k.jsxs)(`div`,{className:G.chatMessages,ref:e=>{O.current.set(t.id,e)},children:[e.history.length===0&&(0,k.jsxs)(`div`,{className:G.chatEmpty,children:[`Ask `,t.label,` anything…`]}),e.history.map((e,t)=>(0,k.jsx)(`div`,{className:`${G.chatMsg} ${e.role===`user`?G.msgUser:G.msgAgent}`,children:e.role===`assistant`?(0,k.jsx)(`div`,{dangerouslySetInnerHTML:{__html:me(e.content||`…`)}}):(0,k.jsx)(`span`,{children:e.content})},t)),e.streaming&&e.history[e.history.length-1]?.role===`assistant`&&e.history[e.history.length-1]?.content===``&&(0,k.jsxs)(`div`,{className:G.thinking,children:[(0,k.jsx)(`span`,{className:G.dot}),(0,k.jsx)(`span`,{className:G.dot}),(0,k.jsx)(`span`,{className:G.dot})]})]}),n&&(0,k.jsxs)(`div`,{className:G.attachBar,children:[(0,k.jsx)(`span`,{children:n}),(0,k.jsx)(`button`,{className:G.attachClear,onClick:()=>N(t.id,{attachedFile:null,attachedImage:null}),children:`×`})]}),(0,k.jsxs)(`div`,{className:G.chatInput,children:[(0,k.jsxs)(`div`,{className:G.chatTools,children:[(0,k.jsx)(`button`,{className:`${G.toolBtn} ${e.voiceActive?G.toolBtnActive:``}`,onClick:()=>he(t.id),title:`Voice`,children:`🎤`}),(0,k.jsx)(`button`,{className:G.toolBtn,onClick:()=>ae.current.get(t.id)?.click(),title:`Attach file`,children:`📎`}),(0,k.jsx)(`button`,{className:G.toolBtn,onClick:()=>A.current.get(t.id)?.click(),title:`Attach image`,children:`🖼`}),(0,k.jsx)(`input`,{type:`file`,style:{display:`none`},ref:e=>{ae.current.set(t.id,e)},onChange:e=>ge(t.id,e.target.files?.[0])}),(0,k.jsx)(`input`,{type:`file`,accept:`image/*`,style:{display:`none`},ref:e=>{A.current.set(t.id,e)},onChange:e=>_e(t.id,e.target.files?.[0])})]}),(0,k.jsxs)(`div`,{className:G.chatInputRow,children:[(0,k.jsx)(`textarea`,{className:G.chatTextarea,value:e.input,onChange:e=>N(t.id,{input:e.target.value}),placeholder:`Message ${t.label}…`,rows:2,onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),pe(e,e.input,e.attachedFile,e.attachedImage))}}),(0,k.jsx)(`button`,{className:G.sendBtn,onClick:()=>pe(e,e.input,e.attachedFile,e.attachedImage),disabled:e.streaming||!e.input.trim()&&!e.attachedFile&&!e.attachedImage,children:e.streaming?`…`:`→`})]})]})]},t.id)})}),l.length>=2&&(0,k.jsxs)(`div`,{className:G.orchBar,children:[(0,k.jsxs)(`div`,{className:G.orchLabel,children:[`🎼 Conductor · `,l.map(e=>`${e.agent.icon} ${e.agent.label}`).join(` · `)]}),(0,k.jsxs)(`div`,{className:G.orchRow,children:[(0,k.jsx)(`textarea`,{ref:j,className:G.orchInput,value:d,onChange:e=>f(e.target.value),placeholder:`Ask all agents — Conductor will synthesize a unified response…`,rows:1,onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),P())}}),(0,k.jsx)(`button`,{className:G.orchBtn,onClick:P,disabled:p||v||!d.trim(),children:p?`⏳`:v?`🔄`:`🎼 Run`})]}),(v||h)&&(0,k.jsxs)(`div`,{className:G.orchSynthesis,children:[(0,k.jsxs)(`div`,{className:G.orchSynthHeader,children:[(0,k.jsx)(`span`,{children:`🎼 Conductor Synthesis`}),v&&(0,k.jsx)(`span`,{className:G.orchSynthSpinner,children:`synthesizing…`})]}),(0,k.jsx)(`div`,{className:G.orchSynthBody,dangerouslySetInnerHTML:{__html:me(h||`…`)}})]})]}),b&&(0,k.jsx)(`div`,{className:G.modalOverlay,onClick:e=>{e.target===e.currentTarget&&x(null)},children:(0,k.jsxs)(`div`,{className:G.modal,children:[(0,k.jsx)(`div`,{className:G.modalTitle,children:S===`create`?`+ New Agent`:`✏️ Edit Agent`}),S===`create`&&(0,k.jsxs)(`div`,{className:G.formField,children:[(0,k.jsx)(`label`,{className:G.formLabel,children:`Agent name (lowercase, no spaces)`}),(0,k.jsx)(`input`,{className:G.formInput,placeholder:`my-agent`,value:b.name,onChange:e=>x(t=>t&&{...t,name:e.target.value})})]}),(0,k.jsxs)(`div`,{className:G.formField,children:[(0,k.jsx)(`label`,{className:G.formLabel,children:`Tagline`}),(0,k.jsx)(`input`,{className:G.formInput,placeholder:`Short description`,value:b.tagline,onChange:e=>x(t=>t&&{...t,tagline:e.target.value})})]}),(0,k.jsxs)(`div`,{className:G.formField,children:[(0,k.jsx)(`label`,{className:G.formLabel,children:`System Prompt`}),(0,k.jsx)(`textarea`,{className:G.formTextarea,placeholder:`You are an expert in…`,value:b.systemPrompt,onChange:e=>x(t=>t&&{...t,systemPrompt:e.target.value})})]}),w&&(0,k.jsx)(`div`,{className:G.formError,children:w}),(0,k.jsxs)(`div`,{className:G.modalBtns,children:[(0,k.jsx)(`button`,{className:G.cancelBtn,onClick:()=>x(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:G.modalSaveBtn,onClick:ye,disabled:te,children:te?`…`:S===`create`?`Create Agent`:`Save`})]})]})})]})}var K={root:`_root_1mam6_1`,error:`_error_1mam6_10`,errorHint:`_errorHint_1mam6_16`,quotaBar:`_quotaBar_1mam6_29`,quotaText:`_quotaText_1mam6_37`,quotaUsed:`_quotaUsed_1mam6_43`,quotaPct:`_quotaPct_1mam6_44`,quotaTrack:`_quotaTrack_1mam6_46`,quotaFill:`_quotaFill_1mam6_53`,actionBar:`_actionBar_1mam6_59`,filterBtn:`_filterBtn_1mam6_67`,filterActive:`_filterActive_1mam6_79`,spacer:`_spacer_1mam6_85`,newBtn:`_newBtn_1mam6_87`,uploadBtn:`_uploadBtn_1mam6_98`,searchRow:`_searchRow_1mam6_108`,searchInput:`_searchInput_1mam6_114`,searchBtn:`_searchBtn_1mam6_126`,loading:`_loading_1mam6_136`,empty:`_empty_1mam6_141`,fileList:`_fileList_1mam6_151`,fileRow:`_fileRow_1mam6_159`,fileIcon:`_fileIcon_1mam6_172`,fileInfo:`_fileInfo_1mam6_174`,fileName:`_fileName_1mam6_176`,fileMeta:`_fileMeta_1mam6_184`,fileBtns:`_fileBtns_1mam6_190`,editBtn:`_editBtn_1mam6_196`,viewBtn:`_viewBtn_1mam6_197`,pdfBtn:`_pdfBtn_1mam6_198`,openBtn:`_openBtn_1mam6_199`,delBtn:`_delBtn_1mam6_200`,editorRoot:`_editorRoot_1mam6_204`,editorToolbar:`_editorToolbar_1mam6_211`,backBtn:`_backBtn_1mam6_221`,editorName:`_editorName_1mam6_231`,saveBtn:`_saveBtn_1mam6_238`,editorArea:`_editorArea_1mam6_251`,editorMeta:`_editorMeta_1mam6_266`,viewerRoot:`_viewerRoot_1mam6_276`,imgContainer:`_imgContainer_1mam6_283`,imgView:`_imgView_1mam6_292`,pdfFrame:`_pdfFrame_1mam6_298`};function Kt(e,t){return e===`folder`?`📁`:e===`image`?`🖼`:e===`pdf`||t.includes(`pdf`)?`📕`:e===`video`?`🎬`:e===`audio`?`🎵`:t.includes(`spreadsheet`)||t.includes(`excel`)?`📊`:t.includes(`presentation`)||t.includes(`powerpoint`)?`📽`:t.includes(`document`)||t.includes(`word`)?`📄`:t.includes(`zip`)||t.includes(`archive`)?`📦`:`📄`}function qt(e){let t=e.mimeType;return e.type===`text`||e.type===`doc`||t.includes(`text`)||t.includes(`json`)||t.includes(`javascript`)||t.includes(`xml`)||t.includes(`csv`)||t.includes(`yaml`)||t.includes(`markdown`)||t.includes(`html`)||t.includes(`css`)||t.includes(`python`)||t.includes(`vnd.google-apps.document`)}function Jt(){let e=M(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(`list`),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(``),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(!1),w=(0,_.useRef)(null),ee=(e=s,t=l)=>{i(!0);let r=`/api/drive`;e&&(r+=`?filter=${e}`),t&&(r+=`${e?`&`:`?`}search=${encodeURIComponent(t)}`),E(r).then(e=>{n(e??{files:[]}),i(!1)}).catch(e=>{o(e.message??`Error`),i(!1)})};(0,_.useEffect)(()=>{ee()},[]);let te=e=>{c(e),ee(e,l)},ne=()=>{u(d),ee(s,d)},T=(e,t)=>{i(!0),E(`/api/drive/read/${e}`).then(n=>{g({id:e,name:t,content:n?.content??``}),y(n?.content??``),m(`editor`),i(!1)}).catch(()=>i(!1))},re=async()=>{if(h&&confirm(`Save changes to "${h.name}" on Drive?`)){C(!0);try{await D(`/api/drive/update/${h.id}`,{content:v}),g(e=>e&&{...e,content:v}),alert(`Saved!`)}catch(e){alert(`Save failed: `+e.message)}finally{C(!1)}}},ie=(e,t)=>{i(!0),E(`/api/drive/download/${e}`).then(n=>{x({id:e,name:t,src:`data:${n?.mimeType??`image/jpeg`};base64,${n?.base64}`,mode:`image`}),m(`image`),i(!1)}).catch(()=>i(!1))},O=(e,t)=>{i(!0),E(`/api/drive/download/${e}`).then(n=>{x({id:e,name:t,src:`data:application/pdf;base64,${n?.base64}`,mode:`pdf`}),m(`pdf`),i(!1)}).catch(()=>i(!1))},ae=(e,t)=>{confirm(`Delete "${t}" from Drive? (moved to trash)`)&&D(`/api/drive/delete/${e}`,{}).then(()=>{n(null),ee()})},A=()=>{let e=prompt(`File name (e.g. notes.txt, script.py):`);e&&D(`/api/drive/upload`,{name:e,content:``,mimeType:`text/plain`}).then(t=>{t?.id?T(t.id,e):ee()}).catch(e=>alert(`Error: `+e.message))},j=()=>{w.current?.click()},oe=e=>{if(!e)return;let t=new FileReader;t.onload=t=>{let r=(t.target?.result).split(`,`)[1]??``;D(`/api/drive/upload`,{name:e.name,content:r,mimeType:e.type||`application/octet-stream`,encoding:`base64`}).then(()=>{n(null),ee()}).catch(e=>alert(`Upload error: `+e.message))},t.readAsDataURL(e)};if(a)return(0,k.jsxs)(`div`,{className:K.error,children:[(0,k.jsx)(`div`,{children:a}),(0,k.jsxs)(`div`,{className:K.errorHint,children:[`Run: `,(0,k.jsx)(`code`,{children:`nha google revoke`}),` then `,(0,k.jsx)(`code`,{children:`nha google auth`})]})]});if(p===`editor`&&h)return(0,k.jsxs)(`div`,{className:K.editorRoot,children:[(0,k.jsxs)(`div`,{className:K.editorToolbar,children:[(0,k.jsx)(`button`,{className:K.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,k.jsx)(`span`,{className:K.editorName,children:h.name}),(0,k.jsx)(`button`,{className:K.saveBtn,onClick:re,disabled:S,children:S?`Saving…`:`Save to Drive`})]}),(0,k.jsx)(`textarea`,{className:K.editorArea,value:v,onChange:e=>y(e.target.value),spellCheck:!1,onKeyDown:e=>{if(e.key===`Tab`){e.preventDefault();let t=e.currentTarget.selectionStart,n=e.currentTarget.selectionEnd,r=e.currentTarget.value;e.currentTarget.value=r.slice(0,t)+` `+r.slice(n),e.currentTarget.selectionStart=e.currentTarget.selectionEnd=t+2}}}),(0,k.jsxs)(`div`,{className:K.editorMeta,children:[`File ID: `,h.id,` · Tab = 2 spaces · Not auto-saved`]})]});if(p===`image`&&b)return(0,k.jsxs)(`div`,{className:K.viewerRoot,children:[(0,k.jsxs)(`div`,{className:K.editorToolbar,children:[(0,k.jsx)(`button`,{className:K.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,k.jsx)(`span`,{className:K.editorName,children:b.name})]}),(0,k.jsx)(`div`,{className:K.imgContainer,children:(0,k.jsx)(`img`,{src:b.src,alt:b.name,className:K.imgView})})]});if(p===`pdf`&&b)return(0,k.jsxs)(`div`,{className:K.viewerRoot,children:[(0,k.jsxs)(`div`,{className:K.editorToolbar,children:[(0,k.jsx)(`button`,{className:K.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,k.jsx)(`span`,{className:K.editorName,children:b.name})]}),(0,k.jsx)(`iframe`,{className:K.pdfFrame,src:b.src,title:b.name})]});let se=t?.files??[],ce=t?.quota;return(0,k.jsxs)(`div`,{className:K.root,children:[ce&&(0,k.jsxs)(`div`,{className:K.quotaBar,children:[(0,k.jsxs)(`div`,{className:K.quotaText,children:[(0,k.jsxs)(`span`,{className:K.quotaUsed,children:[ce.usage,` of `,ce.limit,` used`]}),(0,k.jsxs)(`span`,{className:K.quotaPct,children:[ce.percentUsed,`%`]})]}),(0,k.jsx)(`div`,{className:K.quotaTrack,children:(0,k.jsx)(`div`,{className:K.quotaFill,style:{width:`${Math.min(ce.percentUsed,100)}%`,background:ce.percentUsed>90?`var(--red)`:ce.percentUsed>70?`var(--amber)`:`var(--green)`}})})]}),(0,k.jsxs)(`div`,{className:K.actionBar,children:[[``,`recent`,`starred`,`shared`].map(e=>(0,k.jsx)(`button`,{className:`${K.filterBtn} ${s===e?K.filterActive:``}`,onClick:()=>te(e),children:e?e.charAt(0).toUpperCase()+e.slice(1):`All Files`},e)),(0,k.jsx)(`div`,{className:K.spacer}),(0,k.jsx)(`button`,{className:K.newBtn,onClick:A,children:`+ New File`}),(0,k.jsx)(`button`,{className:K.uploadBtn,onClick:j,children:e(`drive.upload`)}),(0,k.jsx)(`input`,{ref:w,type:`file`,style:{display:`none`},onChange:e=>oe(e.target.files?.[0])})]}),(0,k.jsxs)(`div`,{className:K.searchRow,children:[(0,k.jsx)(`input`,{className:K.searchInput,value:d,onChange:e=>f(e.target.value),placeholder:`Search files…`,onKeyDown:e=>e.key===`Enter`&&ne()}),(0,k.jsx)(`button`,{className:K.searchBtn,onClick:ne,children:`Search`})]}),r&&(0,k.jsx)(`div`,{className:K.loading,children:(0,k.jsx)(`div`,{className:`spinner`})}),!r&&se.length===0&&(0,k.jsxs)(`div`,{className:K.empty,children:[e(`drive.noFiles`),` found`]}),(0,k.jsx)(`div`,{className:K.fileList,children:se.map(e=>{let t=qt(e),n=e.type===`image`,r=e.type===`pdf`||e.mimeType.includes(`pdf`);return(0,k.jsxs)(`div`,{className:K.fileRow,onClick:()=>{t?T(e.id,e.name):n?ie(e.id,e.name):r?O(e.id,e.name):e.webViewLink&&window.open(e.webViewLink,`_blank`)},style:{cursor:t||n||r||e.webViewLink?`pointer`:`default`},children:[(0,k.jsx)(`span`,{className:K.fileIcon,children:Kt(e.type,e.mimeType)}),(0,k.jsxs)(`div`,{className:K.fileInfo,children:[(0,k.jsx)(`div`,{className:K.fileName,children:e.name}),(0,k.jsxs)(`div`,{className:K.fileMeta,children:[e.modifiedTime?new Date(e.modifiedTime).toLocaleDateString():``,e.size?` · ${e.size}`:``,e.shared?` · Shared`:``,e.starred?` ★`:``]})]}),(0,k.jsxs)(`div`,{className:K.fileBtns,children:[t&&(0,k.jsx)(`button`,{className:K.editBtn,onClick:t=>{t.stopPropagation(),T(e.id,e.name)},children:`Edit`}),n&&(0,k.jsx)(`button`,{className:K.viewBtn,onClick:t=>{t.stopPropagation(),ie(e.id,e.name)},children:`View`}),r&&(0,k.jsx)(`button`,{className:K.pdfBtn,onClick:t=>{t.stopPropagation(),O(e.id,e.name)},children:`PDF`}),e.webViewLink&&(0,k.jsx)(`a`,{className:K.openBtn,href:e.webViewLink,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),children:`Open ↗`}),(0,k.jsx)(`button`,{className:K.delBtn,onClick:t=>{t.stopPropagation(),ae(e.id,e.name)},children:`Del`})]})]},e.id)})})]})}var q={root:`_root_a0x57_1`,loading:`_loading_a0x57_10`,errorBox:`_errorBox_a0x57_12`,errorHint:`_errorHint_a0x57_13`,userRow:`_userRow_a0x57_16`,avatar:`_avatar_a0x57_27`,userLogin:`_userLogin_a0x57_29`,userName:`_userName_a0x57_30`,disconnectBtn:`_disconnectBtn_a0x57_32`,repoBar:`_repoBar_a0x57_43`,repoInput:`_repoInput_a0x57_49`,issuesBtn:`_issuesBtn_a0x57_61`,prsBtn:`_prsBtn_a0x57_72`,repoPills:`_repoPills_a0x57_83`,repoPill:`_repoPill_a0x57_83`,issueCount:`_issueCount_a0x57_106`,tabs:`_tabs_a0x57_112`,tab:`_tab_a0x57_112`,tabActive:`_tabActive_a0x57_131`,markRead:`_markRead_a0x57_137`,content:`_content_a0x57_148`,empty:`_empty_a0x57_150`,notifRow:`_notifRow_a0x57_152`,issueRow:`_issueRow_a0x57_152`,prRow:`_prRow_a0x57_152`,notifRepo:`_notifRepo_a0x57_166`,notifType:`_notifType_a0x57_167`,notifTitle:`_notifTitle_a0x57_168`,notifMeta:`_notifMeta_a0x57_169`,issueNum:`_issueNum_a0x57_171`,issueTitle:`_issueTitle_a0x57_172`,issueMeta:`_issueMeta_a0x57_173`,issueLabel:`_issueLabel_a0x57_174`,prNum:`_prNum_a0x57_176`,prTitle:`_prTitle_a0x57_177`,prAuthor:`_prAuthor_a0x57_178`,prDraft:`_prDraft_a0x57_179`,prMeta:`_prMeta_a0x57_180`};function Yt(){let e=M(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(`notifs`),d=(e=``)=>{i(!0),E(e?`/api/github?repo=${encodeURIComponent(e)}`:`/api/github`).then(e=>{n(e??{}),i(!1)}).catch(()=>i(!1))};(0,_.useEffect)(()=>{d()},[]);let f=()=>{let e=s.trim();o(e),d(e),u(`issues`)},p=()=>{let e=s.trim();o(e),d(e),u(`prs`)},m=()=>D(`/api/github/mark-read`,{}).then(()=>d(a)),h=()=>{confirm(`Remove GitHub connection? You can reconnect anytime.`)&&D(`/api/config`,{key:`github-token`,value:``}).then(()=>{n(null),i(!1)})};if(r)return(0,k.jsx)(`div`,{className:q.loading,children:(0,k.jsx)(`div`,{className:`spinner`})});if(t?.error)return(0,k.jsxs)(`div`,{className:q.errorBox,children:[(0,k.jsx)(`div`,{children:t.error}),(0,k.jsxs)(`div`,{className:q.errorHint,children:[`Run: `,(0,k.jsx)(`code`,{children:`nha config set github-token YOUR_PAT`})]})]});let g=t?.user,v=t?.notifications??[],y=t?.issues??[],b=t?.prs??[];return(0,k.jsxs)(`div`,{className:q.root,children:[g?.login&&(0,k.jsxs)(`div`,{className:q.userRow,children:[g.avatar&&(0,k.jsx)(`img`,{src:g.avatar,className:q.avatar,alt:g.login}),(0,k.jsxs)(`div`,{style:{flex:1},children:[(0,k.jsxs)(`div`,{className:q.userLogin,children:[`@`,g.login]}),g.name&&(0,k.jsx)(`div`,{className:q.userName,children:g.name})]}),(0,k.jsx)(`button`,{className:q.disconnectBtn,onClick:h,children:`Disconnect`})]}),(0,k.jsxs)(`div`,{className:q.repoBar,children:[(0,k.jsx)(`input`,{className:q.repoInput,value:s,onChange:e=>c(e.target.value),placeholder:`owner/repo`,onKeyDown:e=>e.key===`Enter`&&f()}),(0,k.jsx)(`button`,{className:q.issuesBtn,onClick:f,children:`Issues`}),(0,k.jsx)(`button`,{className:q.prsBtn,onClick:p,children:`PRs`})]}),g?.repos&&g.repos.length>0&&(0,k.jsx)(`div`,{className:q.repoPills,children:g.repos.slice(0,12).map(e=>(0,k.jsxs)(`button`,{className:q.repoPill,onClick:()=>{c(e.full_name),o(e.full_name),d(e.full_name),u(`issues`)},title:e.description??``,children:[e.private?`🔒 `:``,e.full_name,e.open_issues?(0,k.jsx)(`span`,{className:q.issueCount,children:e.open_issues}):null]},e.full_name))}),(0,k.jsxs)(`div`,{className:q.tabs,children:[(0,k.jsxs)(`button`,{className:`${q.tab} ${l===`notifs`?q.tabActive:``}`,onClick:()=>u(`notifs`),children:[`Notifications `,v.length>0?`(${v.length})`:``]}),y.length>0&&(0,k.jsxs)(`button`,{className:`${q.tab} ${l===`issues`?q.tabActive:``}`,onClick:()=>u(`issues`),children:[`Issues (`,y.length,`)`]}),b.length>0&&(0,k.jsxs)(`button`,{className:`${q.tab} ${l===`prs`?q.tabActive:``}`,onClick:()=>u(`prs`),children:[`PRs (`,b.length,`)`]}),l===`notifs`&&v.length>0&&(0,k.jsx)(`button`,{className:q.markRead,onClick:m,children:`Mark all read`})]}),(0,k.jsxs)(`div`,{className:q.content,children:[l===`notifs`&&(v.length===0?(0,k.jsx)(`div`,{className:q.empty,children:`No notifications`}):v.map((e,t)=>(0,k.jsxs)(`a`,{className:q.notifRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,k.jsx)(`span`,{className:q.notifRepo,children:e.repo}),(0,k.jsxs)(`span`,{className:q.notifType,children:[`[`,e.type,`]`]}),(0,k.jsx)(`div`,{className:q.notifTitle,children:e.title}),(0,k.jsxs)(`div`,{className:q.notifMeta,children:[e.reason,` · `,e.updated]})]},t))),l===`issues`&&(y.length===0?(0,k.jsxs)(`div`,{className:q.empty,children:[e(`github.noIssues`),` for `,a]}):y.map((e,t)=>(0,k.jsxs)(`a`,{className:q.issueRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,k.jsxs)(`span`,{className:q.issueNum,children:[`#`,e.number]}),(0,k.jsx)(`span`,{className:q.issueTitle,children:e.title}),e.assignee&&(0,k.jsxs)(`span`,{className:q.issueMeta,children:[`→ `,e.assignee]}),e.labels&&(0,k.jsxs)(`span`,{className:q.issueLabel,children:[`[`,e.labels,`]`]}),(0,k.jsx)(`div`,{className:q.issueMeta,children:e.updated})]},t))),l===`prs`&&(b.length===0?(0,k.jsxs)(`div`,{className:q.empty,children:[`No PRs for `,a]}):b.map((e,t)=>(0,k.jsxs)(`a`,{className:q.prRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,k.jsxs)(`span`,{className:q.prNum,children:[`#`,e.number]}),(0,k.jsx)(`span`,{className:q.prTitle,children:e.title}),(0,k.jsxs)(`span`,{className:q.prAuthor,children:[`by `,e.author]}),e.draft&&(0,k.jsx)(`span`,{className:q.prDraft,children:`DRAFT`}),(0,k.jsx)(`div`,{className:q.prMeta,children:e.updated})]},t)))]})]})}var J={loading:`_loading_1h5ss_1`,errorBox:`_errorBox_1h5ss_3`,errorHint:`_errorHint_1h5ss_4`,twoPane:`_twoPane_1h5ss_7`,sidebar:`_sidebar_1h5ss_13`,sidebarTitle:`_sidebarTitle_1h5ss_24`,workspace:`_workspace_1h5ss_36`,searchRow:`_searchRow_1h5ss_42`,searchInput:`_searchInput_1h5ss_50`,searchBtn:`_searchBtn_1h5ss_63`,channelItem:`_channelItem_1h5ss_73`,channelActive:`_channelActive_1h5ss_83`,pageTitle:`_pageTitle_1h5ss_89`,pageMeta:`_pageMeta_1h5ss_97`,disconnectBtn:`_disconnectBtn_1h5ss_99`,empty:`_empty_1h5ss_110`,messagePane:`_messagePane_1h5ss_112`,channelHeader:`_channelHeader_1h5ss_120`,emptyPane:`_emptyPane_1h5ss_129`,message:`_message_1h5ss_112`,msgUser:`_msgUser_1h5ss_146`,msgText:`_msgText_1h5ss_147`,msgTs:`_msgTs_1h5ss_148`,openLink:`_openLink_1h5ss_150`,pageBody:`_pageBody_1h5ss_160`};function Xt(){let e=M(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)([]),l=()=>{i(!0),E(`/api/slack/channels`).then(e=>{n(e??{}),i(!1)}).catch(()=>i(!1))},u=e=>{o(e),E(`/api/slack/messages?channel=${e.id}`).then(e=>c(e?.messages??[]))};if((0,_.useEffect)(()=>{l()},[]),r)return(0,k.jsxs)(`div`,{className:J.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]});if(t?.error)return(0,k.jsxs)(`div`,{className:J.errorBox,children:[(0,k.jsx)(`div`,{children:t.error}),(0,k.jsxs)(`div`,{className:J.errorHint,children:[`Run: `,(0,k.jsx)(`code`,{children:`nha config set slack-token xoxb-YOUR-TOKEN`})]})]});let d=t?.channels??[];return(0,k.jsxs)(`div`,{className:J.twoPane,children:[(0,k.jsxs)(`div`,{className:J.sidebar,children:[(0,k.jsxs)(`div`,{className:J.sidebarTitle,children:[(0,k.jsx)(`span`,{children:`💬 Slack`}),t?.workspace&&(0,k.jsx)(`span`,{className:J.workspace,children:t.workspace})]}),d.length===0&&(0,k.jsx)(`div`,{className:J.empty,children:`No channels`}),d.map(e=>(0,k.jsxs)(`div`,{className:`${J.channelItem} ${a?.id===e.id?J.channelActive:``}`,onClick:()=>u(e),children:[`# `,e.name]},e.id)),(0,k.jsx)(`button`,{className:J.disconnectBtn,onClick:()=>D(`/api/config`,{key:`slack-token`,value:``}).then(l),children:`Disconnect`})]}),(0,k.jsx)(`div`,{className:J.messagePane,children:a?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:J.channelHeader,children:[`#`,a.name]}),s.length===0&&(0,k.jsx)(`div`,{className:J.empty,children:`No messages`}),s.map((e,t)=>(0,k.jsxs)(`div`,{className:J.message,children:[(0,k.jsx)(`span`,{className:J.msgUser,children:e.username||e.user||`Unknown`}),(0,k.jsx)(`span`,{className:J.msgText,children:e.text}),(0,k.jsx)(`span`,{className:J.msgTs,children:new Date(parseFloat(e.ts)*1e3).toLocaleTimeString()})]},t))]}):(0,k.jsx)(`div`,{className:J.emptyPane,children:`Select a channel`})})]})}function Zt(){let e=M(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),d=(e=``)=>{i(!0),E(e?`/api/notion/search?q=${encodeURIComponent(e)}`:`/api/notion`).then(e=>{n(e??{}),i(!1)}).catch(()=>i(!1))},f=e=>{o(e),E(`/api/notion/page?id=${encodeURIComponent(e.id)}`).then(e=>c(e?.content??``))};(0,_.useEffect)(()=>{d()},[]);let p=()=>d(l);if(r)return(0,k.jsxs)(`div`,{className:J.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]});if(t?.error)return(0,k.jsxs)(`div`,{className:J.errorBox,children:[(0,k.jsx)(`div`,{children:t.error}),(0,k.jsxs)(`div`,{className:J.errorHint,children:[`Run: `,(0,k.jsx)(`code`,{children:`nha config set notion-token secret_YOUR_TOKEN`})]})]});let m=t?.pages??[];return(0,k.jsxs)(`div`,{className:J.twoPane,children:[(0,k.jsxs)(`div`,{className:J.sidebar,children:[(0,k.jsx)(`div`,{className:J.sidebarTitle,children:`📋 Notion`}),(0,k.jsxs)(`div`,{className:J.searchRow,children:[(0,k.jsx)(`input`,{className:J.searchInput,value:l,onChange:e=>u(e.target.value),placeholder:`Search pages…`,onKeyDown:e=>e.key===`Enter`&&p()}),(0,k.jsx)(`button`,{className:J.searchBtn,onClick:p,children:`Go`})]}),m.length===0&&(0,k.jsx)(`div`,{className:J.empty,children:`No pages found`}),m.map(e=>(0,k.jsxs)(`div`,{className:`${J.channelItem} ${a?.id===e.id?J.channelActive:``}`,onClick:()=>f(e),children:[(0,k.jsx)(`div`,{className:J.pageTitle,children:e.title||`Untitled`}),e.last_edited&&(0,k.jsx)(`div`,{className:J.pageMeta,children:e.last_edited.slice(0,10)})]},e.id)),(0,k.jsx)(`button`,{className:J.disconnectBtn,onClick:()=>D(`/api/config`,{key:`notion-token`,value:``}).then(()=>d()),children:`Disconnect`})]}),(0,k.jsx)(`div`,{className:J.messagePane,children:a?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:J.channelHeader,children:a.title}),a.url&&(0,k.jsx)(`a`,{className:J.openLink,href:a.url,target:`_blank`,rel:`noreferrer`,children:`Open in Notion ↗`}),(0,k.jsx)(`div`,{className:J.pageBody,dangerouslySetInnerHTML:{__html:me(s||`Loading…`)}})]}):(0,k.jsx)(`div`,{className:J.emptyPane,children:`Select a page`})})]})}var Y={root:`_root_1l3ll_1`,sidebar:`_sidebar_1l3ll_8`,sidebarHeader:`_sidebarHeader_1l3ll_18`,sidebarTitle:`_sidebarTitle_1l3ll_19`,sidebarBtns:`_sidebarBtns_1l3ll_21`,createBtn:`_createBtn_1l3ll_22`,joinBtn:`_joinBtn_1l3ll_23`,noChannels:`_noChannels_1l3ll_25`,channelItem:`_channelItem_1l3ll_27`,channelActive:`_channelActive_1l3ll_29`,channelName:`_channelName_1l3ll_30`,channelMeta:`_channelMeta_1l3ll_31`,channelCode:`_channelCode_1l3ll_32`,channelDel:`_channelDel_1l3ll_34`,main:`_main_1l3ll_38`,chatHeader:`_chatHeader_1l3ll_41`,chatChannelName:`_chatChannelName_1l3ll_50`,chatChannelId:`_chatChannelId_1l3ll_51`,statusDot:`_statusDot_1l3ll_52`,connected:`_connected_1l3ll_53`,disconnected:`_disconnected_1l3ll_54`,statusText:`_statusText_1l3ll_55`,messages:`_messages_1l3ll_58`,emptyMsgs:`_emptyMsgs_1l3ll_66`,msg:`_msg_1l3ll_68`,msgSelf:`_msgSelf_1l3ll_69`,msgOther:`_msgOther_1l3ll_70`,msgSender:`_msgSender_1l3ll_71`,msgContent:`_msgContent_1l3ll_72`,msgTime:`_msgTime_1l3ll_82`,inputRow:`_inputRow_1l3ll_85`,textInput:`_textInput_1l3ll_86`,sendBtn:`_sendBtn_1l3ll_88`,welcome:`_welcome_1l3ll_92`,welcomeIcon:`_welcomeIcon_1l3ll_103`,welcomeTitle:`_welcomeTitle_1l3ll_104`,welcomeSub:`_welcomeSub_1l3ll_105`,welcomeBox:`_welcomeBox_1l3ll_106`,welcomeBoxTitle:`_welcomeBoxTitle_1l3ll_107`,welcomeStep:`_welcomeStep_1l3ll_108`,welcomeHint:`_welcomeHint_1l3ll_109`,cliCmd:`_cliCmd_1l3ll_110`};function Qt(e){return e.content||e.plaintext||e.message||``}function $t(e){return e.senderName||e.senderFingerprint?.slice(0,8)||e.sender||`unknown`}function en(){let e=M(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(!1),[d]=(0,_.useState)(()=>`nha-ui-${Math.random().toString(36).slice(2,8)}`),f=(0,_.useRef)(null),p=(0,_.useRef)(null);(0,_.useEffect)(()=>{E(`/api/collab/channels`).then(e=>{n(e?.channels??[])}).catch(()=>{})},[]),(0,_.useEffect)(()=>{if(r)return m(r),h(r),()=>{f.current?.close(),u(!1)}},[r]);let m=e=>{E(`/api/collab/messages?channelId=${e}`).then(e=>{e?.messages&&(o(e.messages),setTimeout(()=>{p.current&&(p.current.scrollTop=p.current.scrollHeight)},50))}).catch(()=>{})},h=e=>{f.current?.close();let t=window.location.protocol===`https:`?`wss:`:`ws:`,n=window.location.port===`3030`||window.location.port===`3031`?`3020`:window.location.port||`3020`,r=`${t}//${window.location.hostname}:${n}/ws/alexandria?channel=${e}&agentId=${encodeURIComponent(d)}`,i=new WebSocket(r);f.current=i,i.onopen=()=>u(!0),i.onclose=()=>u(!1),i.onmessage=e=>{try{let t=JSON.parse(e.data);if(!t)return;o(e=>[...e,{...t,id:t.id||Date.now().toString(),type:`message`}]),p.current&&(p.current.scrollTop=p.current.scrollHeight)}catch{}}},g=async()=>{let e=prompt(`Channel name:`);if(!e)return;let t=await D(`/api/collab/create`,{name:e}).catch(()=>null);if(!t||t.error){alert(t?.error||`Error creating channel`);return}let r=t.id;await D(`/api/collab/channels`,{id:r,name:e,role:`creator`}).catch(()=>{});let a={id:r,name:e,role:`creator`};n(e=>[...e,a]),i(r),prompt(`Share this invite code with collaborators:`,r)},v=async()=>{let e=prompt(`Invite code:`);if(!e)return;let t=await D(`/api/collab/join`,{channelId:e}).catch(()=>null);if(!t||t.error){alert(t?.error||`Error joining channel`);return}let r=t.name||e.slice(0,8);await D(`/api/collab/channels`,{id:e,name:r,role:`member`}).catch(()=>{}),n(t=>[...t,{id:e,name:r,role:`member`}]),i(e)},y=async e=>{confirm(`Delete this channel? Messages will be lost.`)&&(D(`/api/collab/delete`,{channelId:e}).catch(()=>{}),n(t=>t.filter(t=>t.id!==e)),r===e&&(i(null),o([]),f.current?.close(),u(!1)))},b=async()=>{let e=s.trim();if(!e||!r)return;c(``);let t=await D(`/api/collab/send`,{channelId:r,message:e}).catch(()=>null);t?.error&&alert(t.error),l||m(r)},x=e=>{navigator.clipboard.writeText(e).catch(()=>{})};return(0,k.jsxs)(`div`,{className:Y.root,children:[(0,k.jsxs)(`div`,{className:Y.sidebar,children:[(0,k.jsx)(`div`,{className:Y.sidebarHeader,children:(0,k.jsx)(`div`,{className:Y.sidebarTitle,children:`Alexandria`})}),(0,k.jsxs)(`div`,{className:Y.sidebarBtns,children:[(0,k.jsx)(`button`,{className:Y.createBtn,onClick:g,children:`+ Create`}),(0,k.jsx)(`button`,{className:Y.joinBtn,onClick:v,children:`Join`})]}),t.length===0?(0,k.jsxs)(`div`,{className:Y.noChannels,children:[e(`collab.noChannels`),` yet`]}):t.map(e=>(0,k.jsxs)(`div`,{className:`${Y.channelItem} ${r===e.id?Y.channelActive:``}`,onClick:()=>i(e.id),children:[(0,k.jsx)(`div`,{className:Y.channelName,children:e.name}),(0,k.jsxs)(`div`,{className:Y.channelMeta,children:[(0,k.jsxs)(`span`,{className:Y.channelCode,onClick:t=>{t.stopPropagation(),x(e.id)},title:`Click to copy invite code`,children:[e.id.slice(0,8),`…`]}),(0,k.jsx)(`button`,{className:Y.channelDel,onClick:t=>{t.stopPropagation(),y(e.id)},children:`del`})]})]},e.id))]}),(0,k.jsx)(`div`,{className:Y.main,children:r?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:Y.chatHeader,children:[(0,k.jsx)(`div`,{className:Y.chatChannelName,children:t.find(e=>e.id===r)?.name??r.slice(0,12)}),(0,k.jsx)(`div`,{className:Y.chatChannelId,children:r}),(0,k.jsx)(`div`,{className:`${Y.statusDot} ${l?Y.connected:Y.disconnected}`}),(0,k.jsx)(`span`,{className:Y.statusText,children:l?`Live`:`HTTP`})]}),(0,k.jsxs)(`div`,{className:Y.messages,ref:p,children:[a.length===0&&(0,k.jsx)(`div`,{className:Y.emptyMsgs,children:`No messages yet`}),a.map((e,t)=>{let n=$t(e),r=Qt(e),i=n===d;return(0,k.jsxs)(`div`,{className:`${Y.msg} ${i?Y.msgSelf:Y.msgOther}`,children:[!i&&(0,k.jsx)(`div`,{className:Y.msgSender,children:n}),(0,k.jsx)(`div`,{className:Y.msgContent,children:r}),(0,k.jsx)(`div`,{className:Y.msgTime,children:new Date(e.timestamp).toLocaleTimeString()})]},e.id||t)})]}),(0,k.jsxs)(`div`,{className:Y.inputRow,children:[(0,k.jsx)(`input`,{className:Y.textInput,value:s,onChange:e=>c(e.target.value),placeholder:`Send an encrypted message…`,onKeyDown:e=>e.key===`Enter`&&!e.shiftKey&&b()}),(0,k.jsx)(`button`,{className:Y.sendBtn,onClick:b,disabled:!s.trim(),children:e(`collab.send`)})]})]}):(0,k.jsxs)(`div`,{className:Y.welcome,children:[(0,k.jsx)(`div`,{className:Y.welcomeIcon,children:`🔐`}),(0,k.jsx)(`div`,{className:Y.welcomeTitle,children:`Alexandria`}),(0,k.jsx)(`div`,{className:Y.welcomeSub,children:`E2E encrypted messaging for AI agents and teams`}),(0,k.jsxs)(`div`,{className:Y.welcomeBox,children:[(0,k.jsx)(`div`,{className:Y.welcomeBoxTitle,children:`HOW TO USE`}),(0,k.jsxs)(`div`,{className:Y.welcomeStep,children:[(0,k.jsx)(`strong`,{children:`1. Create a channel`}),` — Click [+ Create] in the sidebar. Give it a name.`]}),(0,k.jsx)(`div`,{className:Y.welcomeHint,children:`You get an invite code. Share it with your team or another AI session.`}),(0,k.jsxs)(`div`,{className:Y.welcomeStep,children:[(0,k.jsx)(`strong`,{children:`2. Others join`}),` — They click [Join] and paste the invite code.`]}),(0,k.jsx)(`div`,{className:Y.welcomeHint,children:`Works from this web UI, the Android app, or the CLI.`}),(0,k.jsxs)(`div`,{className:Y.welcomeStep,children:[(0,k.jsx)(`strong`,{children:`3. Chat encrypted`}),` — All messages are E2E encrypted. The server sees only ciphertext.`]})]}),(0,k.jsxs)(`div`,{className:Y.welcomeBox,children:[(0,k.jsx)(`div`,{className:Y.welcomeBoxTitle,children:`FROM CLI (same channels)`}),(0,k.jsx)(`div`,{className:Y.cliCmd,children:`nha collab create "Project X"`}),(0,k.jsx)(`div`,{className:Y.cliCmd,children:`nha collab join <invite-code>`}),(0,k.jsx)(`div`,{className:Y.cliCmd,children:`nha collab send "Hello from CLI"`}),(0,k.jsx)(`div`,{className:Y.cliCmd,children:`nha collab read`})]})]})})]})}var X={root:`_root_1xa21_2`,header:`_header_1xa21_10`,title:`_title_1xa21_21`,subtitle:`_subtitle_1xa21_28`,headerTabs:`_headerTabs_1xa21_34`,tabBtn:`_tabBtn_1xa21_40`,tabActive:`_tabActive_1xa21_51`,body:`_body_1xa21_58`,editor:`_editor_1xa21_67`,examples:`_examples_1xa21_75`,sectionLabel:`_sectionLabel_1xa21_81`,examplePills:`_examplePills_1xa21_89`,examplePill:`_examplePill_1xa21_89`,editorCols:`_editorCols_1xa21_109`,leftSidebar:`_leftSidebar_1xa21_119`,panel:`_panel_1xa21_128`,panelHeader:`_panelHeader_1xa21_135`,panelTitle:`_panelTitle_1xa21_142`,addBtn:`_addBtn_1xa21_149`,blockLabel:`_blockLabel_1xa21_160`,blockCheck:`_blockCheck_1xa21_170`,authField:`_authField_1xa21_173`,authFieldInput:`_authFieldInput_1xa21_183`,authFieldSelect:`_authFieldSelect_1xa21_193`,authFieldReq:`_authFieldReq_1xa21_204`,removeFieldBtn:`_removeFieldBtn_1xa21_205`,skillsList:`_skillsList_1xa21_208`,skillRow:`_skillRow_1xa21_210`,skillIcon:`_skillIcon_1xa21_218`,skillName:`_skillName_1xa21_220`,skillBadge:`_skillBadge_1xa21_229`,skillBadge_skill:`_skillBadge_skill_1xa21_237`,skillBadge_memory:`_skillBadge_memory_1xa21_238`,skillBadge_provider:`_skillBadge_provider_1xa21_239`,skillBadge_log:`_skillBadge_log_1xa21_240`,skillEmpty:`_skillEmpty_1xa21_242`,skillBtn:`_skillBtn_1xa21_244`,skillsEmpty:`_skillsEmpty_1xa21_246`,snapshotRow:`_snapshotRow_1xa21_249`,snapshotTs:`_snapshotTs_1xa21_258`,snapshotCount:`_snapshotCount_1xa21_259`,snapshotBtn:`_snapshotBtn_1xa21_260`,genStatus:`_genStatus_1xa21_263`,repairStatus:`_repairStatus_1xa21_265`,repairStatusTitle:`_repairStatusTitle_1xa21_266`,repairStatusProg:`_repairStatusProg_1xa21_267`,repairStatusFile:`_repairStatusFile_1xa21_268`,actionRow:`_actionRow_1xa21_271`,actionBtn:`_actionBtn_1xa21_273`,actionBtnIcon:`_actionBtnIcon_1xa21_275`,actionBtnActive:`_actionBtnActive_1xa21_276`,repairBtn:`_repairBtn_1xa21_278`,sandboxBtn:`_sandboxBtn_1xa21_280`,statsBar:`_statsBar_1xa21_282`,rightPanel:`_rightPanel_1xa21_285`,rightTabBar:`_rightTabBar_1xa21_296`,rightTab:`_rightTab_1xa21_296`,rightTabActive:`_rightTabActive_1xa21_313`,repairBar:`_repairBar_1xa21_316`,repairBarRow:`_repairBarRow_1xa21_326`,repairBarIcon:`_repairBarIcon_1xa21_327`,repairBarLabel:`_repairBarLabel_1xa21_328`,repairBarFile:`_repairBarFile_1xa21_329`,repairBarCounter:`_repairBarCounter_1xa21_330`,repairBarTime:`_repairBarTime_1xa21_331`,genBar:`_genBar_1xa21_333`,genBarRow:`_genBarRow_1xa21_343`,genBarRobot:`_genBarRobot_1xa21_344`,robotBob:`_robotBob_1xa21_1`,genBarLabel:`_genBarLabel_1xa21_345`,genBarFile:`_genBarFile_1xa21_346`,genBarCounter:`_genBarCounter_1xa21_347`,genBarTime:`_genBarTime_1xa21_348`,progressTrack:`_progressTrack_1xa21_350`,repairProgress:`_repairProgress_1xa21_351`,genProgress:`_genProgress_1xa21_352`,genDots:`_genDots_1xa21_355`,dot:`_dot_1xa21_356`,dot1:`_dot1_1xa21_357`,dotBounce:`_dotBounce_1xa21_1`,dot2:`_dot2_1xa21_358`,dot3:`_dot3_1xa21_359`,stopBtn:`_stopBtn_1xa21_362`,codeArea:`_codeArea_1xa21_365`,sandboxWrap:`_sandboxWrap_1xa21_366`,sandboxFrame:`_sandboxFrame_1xa21_367`,sandboxEmpty:`_sandboxEmpty_1xa21_368`,sandboxStartBtn:`_sandboxStartBtn_1xa21_369`,noFiles:`_noFiles_1xa21_371`,noFilesHero:`_noFilesHero_1xa21_381`,noFilesIcon:`_noFilesIcon_1xa21_388`,noFilesTitle:`_noFilesTitle_1xa21_390`,noFilesTagline:`_noFilesTagline_1xa21_397`,noFilesSteps:`_noFilesSteps_1xa21_402`,noFilesStep:`_noFilesStep_1xa21_402`,noFilesStepNum:`_noFilesStepNum_1xa21_419`,noFilesExamplesHint:`_noFilesExamplesHint_1xa21_433`,noFilesExampleBtn:`_noFilesExampleBtn_1xa21_443`,codeLayout:`_codeLayout_1xa21_455`,codeViewer:`_codeViewer_1xa21_457`,codeHeader:`_codeHeader_1xa21_465`,codeFileIcon:`_codeFileIcon_1xa21_478`,codeFileName:`_codeFileName_1xa21_479`,codeFileMeta:`_codeFileMeta_1xa21_480`,fileError:`_fileError_1xa21_482`,fileSyntaxError:`_fileSyntaxError_1xa21_483`,filePending:`_filePending_1xa21_484`,code:`_code_1xa21_365`,codeError:`_codeError_1xa21_499`,codeSyntaxError:`_codeSyntaxError_1xa21_500`,fileSidebar:`_fileSidebar_1xa21_503`,fileSidebarHeader:`_fileSidebarHeader_1xa21_512`,fileTab:`_fileTab_1xa21_522`,fileTabActive:`_fileTabActive_1xa21_538`,fileTabError:`_fileTabError_1xa21_539`,fileTabRow:`_fileTabRow_1xa21_541`,fileTabIcon:`_fileTabIcon_1xa21_542`,fileTabName:`_fileTabName_1xa21_543`,fileTabDir:`_fileTabDir_1xa21_544`,fileTabMeta:`_fileTabMeta_1xa21_545`,projectsList:`_projectsList_1xa21_548`,emptyProjects:`_emptyProjects_1xa21_550`,emptyIcon:`_emptyIcon_1xa21_551`,emptyHint:`_emptyHint_1xa21_552`,projectCard:`_projectCard_1xa21_554`,projectInfo:`_projectInfo_1xa21_555`,projectName:`_projectName_1xa21_556`,projectDesc:`_projectDesc_1xa21_557`,projectMeta:`_projectMeta_1xa21_558`,openBtn:`_openBtn_1xa21_559`,deleteBtn:`_deleteBtn_1xa21_560`,planBanner:`_planBanner_1xa21_563`,planTitle:`_planTitle_1xa21_572`,planText:`_planText_1xa21_573`,planActions:`_planActions_1xa21_574`,planApprove:`_planApprove_1xa21_575`,planReject:`_planReject_1xa21_576`,grepPanel:`_grepPanel_1xa21_579`,grepRow:`_grepRow_1xa21_588`,grepInput:`_grepInput_1xa21_589`,grepBtn:`_grepBtn_1xa21_591`,grepClose:`_grepClose_1xa21_592`,grepCount:`_grepCount_1xa21_593`,grepResults:`_grepResults_1xa21_594`,grepEmpty:`_grepEmpty_1xa21_595`,grepMatch:`_grepMatch_1xa21_596`,grepMatchFile:`_grepMatchFile_1xa21_598`,grepMatchLine:`_grepMatchLine_1xa21_599`,diffPanel:`_diffPanel_1xa21_602`,diffHeader:`_diffHeader_1xa21_611`,diffClose:`_diffClose_1xa21_612`,diffFile:`_diffFile_1xa21_613`,diffSummary:`_diffSummary_1xa21_614`,diffArrow:`_diffArrow_1xa21_615`,diffFileName:`_diffFileName_1xa21_616`,diffAdded:`_diffAdded_1xa21_617`,diffRemoved:`_diffRemoved_1xa21_618`,diffContent:`_diffContent_1xa21_619`,diffInline:`_diffInline_1xa21_622`,diffInlineHeader:`_diffInlineHeader_1xa21_623`,diffRemLine:`_diffRemLine_1xa21_624`,diffAddLine:`_diffAddLine_1xa21_625`,chatPanel:`_chatPanel_1xa21_628`,chatMessages:`_chatMessages_1xa21_637`,chatWelcome:`_chatWelcome_1xa21_639`,chatUser:`_chatUser_1xa21_641`,chatUserBubble:`_chatUserBubble_1xa21_642`,chatAttachPreviews:`_chatAttachPreviews_1xa21_643`,chatAttachBadge:`_chatAttachBadge_1xa21_644`,chatSystem:`_chatSystem_1xa21_646`,chatSystemBubble:`_chatSystemBubble_1xa21_647`,chatSyntaxErr:`_chatSyntaxErr_1xa21_648`,chatAgent:`_chatAgent_1xa21_650`,chatAgentCard:`_chatAgentCard_1xa21_651`,chatAgentHeader:`_chatAgentHeader_1xa21_652`,chatAgentRobot:`_chatAgentRobot_1xa21_653`,chatAgentRobotAnim:`_chatAgentRobotAnim_1xa21_654`,chatAgentLabel:`_chatAgentLabel_1xa21_655`,chatRunningDots:`_chatRunningDots_1xa21_656`,chatAgentText:`_chatAgentText_1xa21_657`,chatToolBadges:`_chatToolBadges_1xa21_658`,toolBadge:`_toolBadge_1xa21_659`,toolBadgeOk:`_toolBadgeOk_1xa21_660`,toolBadgeErr:`_toolBadgeErr_1xa21_661`,cursor:`_cursor_1xa21_663`,blink:`_blink_1xa21_1`,attachPreviews:`_attachPreviews_1xa21_666`,attachBadge:`_attachBadge_1xa21_667`,removeAttachBtn:`_removeAttachBtn_1xa21_668`,projNameRow:`_projNameRow_1xa21_671`,projNameLabel:`_projNameLabel_1xa21_672`,projNameInput:`_projNameInput_1xa21_673`,projActiveRow:`_projActiveRow_1xa21_674`,projActiveName:`_projActiveName_1xa21_675`,chatInputRow:`_chatInputRow_1xa21_678`,attachLabel:`_attachLabel_1xa21_679`,chatTextarea:`_chatTextarea_1xa21_680`,chatSendCol:`_chatSendCol_1xa21_683`,chatSendBtn:`_chatSendBtn_1xa21_684`,chatStopBtn:`_chatStopBtn_1xa21_686`,modalOverlay:`_modalOverlay_1xa21_689`,modal:`_modal_1xa21_689`,modalHeader:`_modalHeader_1xa21_711`,modalTitle:`_modalTitle_1xa21_712`,modalClose:`_modalClose_1xa21_713`,modalBody:`_modalBody_1xa21_715`,modalRow:`_modalRow_1xa21_717`,modalField:`_modalField_1xa21_718`,modalLabel:`_modalLabel_1xa21_719`,modalLabelRow:`_modalLabelRow_1xa21_720`,modalSelect:`_modalSelect_1xa21_722`,modalInput:`_modalInput_1xa21_723`,modalHint:`_modalHint_1xa21_726`,modalAiBox:`_modalAiBox_1xa21_728`,modalAiRow:`_modalAiRow_1xa21_729`,modalAiDesc:`_modalAiDesc_1xa21_730`,modalAiBtn:`_modalAiBtn_1xa21_731`,modalContentArea:`_modalContentArea_1xa21_734`,logView:`_logView_1xa21_737`,modalFooter:`_modalFooter_1xa21_739`,modalCancelBtn:`_modalCancelBtn_1xa21_740`,modalSaveBtn:`_modalSaveBtn_1xa21_741`},tn=[{name:`MySaaS`,desc:`SaaS product landing page. Hero: large headline, subheadline, two CTA buttons (Start free trial / Watch demo), animated gradient background. Features section: 3-column grid with icon, title, description for 6 features. Pricing section: 3 cards (Free / Pro $29/mo / Enterprise). Testimonials: 3 customer quotes. FAQ accordion: 5 questions. Footer with links and social icons. Sticky nav.`},{name:`MyShop`,desc:`E-commerce storefront homepage. Nav with logo, search bar, cart badge, hamburger mobile menu. Hero banner. Category strip: 6 cards. Featured products grid: 8 cards with rating, price, Add to Cart, wishlist. Promo banner. Newsletter signup. Responsive.`},{name:`MyBlog`,desc:`Blog platform homepage. Nav with category links. Hero: featured article card. Article grid: 6 cards. Sidebar: recent posts, tags cloud, newsletter widget. Pagination. Author bio section. Minimal footer.`},{name:`MyPortfolio`,desc:`Developer portfolio. Nav with scroll hide/show. Hero: typewriter role subtitle, CTA buttons. Work section: 6 project cards. Skills grouped by category with bars. About: timeline of milestones. Contact form. Scroll entrance animations via Intersection Observer.`},{name:`MyRestaurant`,desc:`Restaurant website. Nav: logo center, transparent→solid on scroll. Hero: full-viewport with overlay. Menu preview: tabbed (Starters/Mains/Desserts/Drinks). Reservation form. Gallery 3x3 mosaic. Chef section. Testimonials horizontal scroll.`},{name:`MyJobBoard`,desc:`Job board homepage. Hero search widget. Stats strip. Featured jobs list: 8 cards with company, location badge, salary, Quick Apply. Filter sidebar. Top companies section. Category cards. Newsletter.`}],nn=[{key:`auth`,label:`Auth (register/login/JWT)`,icon:`🔒`},{key:`cookieBanner`,label:`GDPR Cookie Banner`,icon:`🍪`},{key:`securityMiddleware`,label:`Security Middleware`,icon:`🛡️`},{key:`emailVerification`,label:`Email Verification`,icon:`✉️`}],rn={js:`📄`,ts:`📄`,css:`🎨`,html:`🌐`,json:`{`,md:`📑`,sql:`🗂`,env:`🔐`,conf:`⚙`,lock:`🔒`};function an(e){return rn[e.split(`.`).pop()?.toLowerCase()??``]??`📄`}function on(e){let t=new TextEncoder().encode(e).length;return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(2)} MB`}function sn(e){return e===`memory`?`🧠`:e===`provider`?`🤖`:e===`log`?`📄`:`📋`}function cn(){let e=M(),[t,n]=(0,_.useState)(`new`),[r,i]=(0,_.useState)(`files`),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)({auth:!0,cookieBanner:!0,securityMiddleware:!0,emailVerification:!0}),[d,f]=(0,_.useState)([{label:`Email`,type:`email`,required:!0},{label:`Password`,type:`password`,required:!0},{label:`Name`,type:`text`,required:!0}]),[p,m]=(0,_.useState)([]),[h,g]=(0,_.useState)(0),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(!1),[S,C]=(0,_.useState)(0),[w,ee]=(0,_.useState)(0),[te,ne]=(0,_.useState)(``),[T,re]=(0,_.useState)({fi:0,total:0,name:``}),[ie,O]=(0,_.useState)(null),[ae,A]=(0,_.useState)([]),[j,oe]=(0,_.useState)(``),[se,ce]=(0,_.useState)(!1),[le,ue]=(0,_.useState)([]),[N,de]=(0,_.useState)(null),[fe,pe]=(0,_.useState)([]),[me,P]=(0,_.useState)(!1),[he,ge]=(0,_.useState)(null),[_e,ve]=(0,_.useState)([]),[F,ye]=(0,_.useState)(!1),[be,xe]=(0,_.useState)(``),[I,L]=(0,_.useState)([]),[Se,Ce]=(0,_.useState)([]),[we,Te]=(0,_.useState)([]),[Ee,De]=(0,_.useState)(null),[Oe,ke]=(0,_.useState)(`0s`),[Ae,je]=(0,_.useState)(`0s`),R=(0,_.useRef)(0),Me=(0,_.useRef)(0),Ne=(0,_.useRef)(null),Pe=(0,_.useRef)(null),Fe=(0,_.useRef)(null),Ie=(0,_.useRef)(null);function Le(e){let t=Math.floor((Date.now()-e)/1e3),n=Math.floor(t/60);return(n>0?`${n}m `:``)+`${t%60}s`}(0,_.useEffect)(()=>(v||b?Ne.current=setInterval(()=>{v&&ke(Le(R.current)),b&&je(Le(Me.current))},1e3):Ne.current&&=(clearInterval(Ne.current),null),()=>{Ne.current&&clearInterval(Ne.current)}),[v,b]);function Re(){Fe.current&&(Fe.current.scrollTop=Fe.current.scrollHeight)}(0,_.useEffect)(()=>{Re()},[ae]),(0,_.useEffect)(()=>{a&&p.length>0&&!me&&(P(!0),E(`/api/studio/webcraft/skills/${encodeURIComponent(a)}`).then(e=>{e?.skills&&pe(e.skills)}).catch(()=>{}))},[a,p.length,me]);async function ze(e,t){if(v||!e||e.length<5)return;y(!0),m([]),g(0),re({fi:0,total:0,name:``}),R.current=Date.now(),ke(`0s`),Pe.current=new AbortController;let n=Date.now();try{let r=await fetch(`/api/studio/webcraft/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},signal:Pe.current.signal,body:JSON.stringify({projectName:t,description:e,blocks:l,authFields:d})});if(!r.ok||!r.body){y(!1);return}let i=r.body.getReader(),a=new TextDecoder,o=``,s=[];for(;;){let{done:e,value:t}=await i.read();if(e)break;o+=a.decode(t,{stream:!0});let r=o.split(`
498
531
 
499
532
  `);o=r.pop()??``;for(let e of r){let t=e.replace(/^data: /,``).trim();if(t)try{let e=JSON.parse(t);if(e.type===`file_start`)s.push({name:e.name,content:``,_pending:!0}),m([...s]),re({fi:e.fi,total:e.total,name:e.name});else if(e.type===`file_chunk`){let t=s.find(t=>t.name===e.name);t&&(t.content+=e.chunk,t._pending=!1),m([...s])}else if(e.type===`file_done`){let t=s.find(t=>t.name===e.name);t&&(t._pending=!1,e.syntaxError&&(t._syntaxError=e.syntaxError)),m([...s]),re({fi:e.fi,total:e.total,name:e.name})}else if(e.type===`file_error`){let t=s.find(t=>t.name===e.name);t&&(t._error=!0,t._pending=!1),m([...s])}else e.type===`done`&&(O({seconds:Math.round((Date.now()-n)/1e3),tokIn:e.tokIn??0,tokOut:e.tokOut??0,files:s.length}),y(!1),P(!1),pe([]))}catch{}}}}catch(e){e.name!==`AbortError`&&A(t=>[...t,{role:`system`,text:`Errore generazione: `+e.message}]),y(!1)}}async function Be(){let e=j.trim();if(!(a&&p.length>0)){if(!e||e.length<5)return;let t=a||`MyProject`;o(t),c(e),oe(``),await ze(e,t);return}if(!e&&le.length===0||se||v)return;let t=[...le];if(ue([]),oe(``),e.toLowerCase().startsWith(`/plan `)||e.toLowerCase().startsWith(`piano: `)){let t=e.replace(/^\/plan[ ]*/i,``).replace(/^piano:[ ]*/i,``);A(t=>[...t,{role:`user`,text:e}]),await Ve(`[MODALITA PIANO] Descrivi cosa modificheresti per: "${t}". Elenca i file e cosa faresti. NON applicare modifiche ancora. Rispondi con il piano in bullet list.`,t,[]);return}A(n=>[...n,{role:`user`,text:e,attachments:t}]),await Ve(e,null,t)}async function Ve(e,t,n){if(se)return;ce(!0);let r={};p.forEach(e=>{r[e.name]=e.content});try{let i=await fetch(`/api/studio/webcraft/agent`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({projectName:a,message:e,attachments:n.map(e=>({name:e.name,mimeType:e.mimeType,base64:e.base64}))})});if(!i.ok||!i.body){A(e=>[...e,{role:`agent`,text:`Errore: ${i.status}`,tools:[]}]),ce(!1);return}let o={role:`agent`,text:``,tools:[]};A(e=>[...e,o]);let s=i.body.getReader(),c=new TextDecoder,l=``,u=!1;for(;;){let{done:e,value:n}=await s.read();if(e)break;l+=c.decode(n,{stream:!0});let i=l.split(`
500
533
 
501
534
  `);l=i.pop()??``;for(let e of i){let n=e.replace(/^data: /,``).trim();if(n)try{let e=JSON.parse(n);e.type===`text`?(o.text+=e.token,A(e=>{let t=[...e];return t[t.length-1]={...o},t})):e.type===`tool`?(o.tools.push({op:e.op,path:e.path,result:e.result,oldSnippet:e.oldSnippet??``,newSnippet:e.newSnippet??``}),(e.op===`edit`||e.op===`write`)&&e.result===`ok`&&(u=!0),A(e=>{let t=[...e];return t[t.length-1]={...o},t})):e.type===`done`?(t&&!u&&de({plan:o.text,originalMessage:t}),ce(!1),e.changed&&await He((o.tools??[]).filter(e=>e.op===`edit`||e.op===`write`).map(e=>e.path),r)):e.type===`error`&&(o.text+=`
502
535
  Errore: `+e.msg,ce(!1))}catch{}}}}catch(e){A(t=>[...t,{role:`agent`,text:`Errore di rete: `+e.message,tools:[]}])}ce(!1)}async function He(e,t){if(!a)return;let n=await E(`/api/studio/webcraft/projects/load/${encodeURIComponent(a)}`);if(n?.files&&(m(n.files),e.length>0)){let r=e.map(e=>{let r=n.files.find(t=>t.name===e);return r?{file:e,before:t[e]??``,after:r.content}:null}).filter(Boolean);Ce(e=>[...e,...r])}}function Ue(){Pe.current&&=(Pe.current.abort(),null),y(!1),ce(!1),A(e=>[...e,{role:`system`,text:`⏹ Generazione interrotta.`}])}async function We(){return a?(await D(`/api/studio/webcraft/snapshot`,{projectName:a}))?.snapshot??null:null}async function Ge(){let e=await We();e&&(A(t=>[...t,{role:`system`,text:`💾 Snapshot salvato (${e.slice(0,16).replace(`T`,` `)})`}]),Ke())}async function Ke(){if(!a)return;let e=await E(`/api/studio/webcraft/snapshots/${encodeURIComponent(a)}`);e?.snapshots&&ve(e.snapshots)}async function qe(e){confirm(`Ripristinare lo snapshot del ${e.replace(`T`,` `).slice(0,16)}? I file attuali verranno sovrascritti.`)&&await D(`/api/studio/webcraft/restore`,{projectName:a,ts:e})!==null&&(A(t=>[...t,{role:`agent`,text:`Snapshot ripristinato (${e}). Ricarico i file...`}]),He([],{}))}async function Je(){if(!a)return;let e=await D(`/api/studio/webcraft/syntax-check`,{projectName:a});if(e?.results){let t=e.results.filter(e=>!e.ok);t.length>0?A(e=>[...e,{role:`system`,text:`⚠ Syntax check: ${t.length} errore/i trovato/i.`,syntaxErrors:t}]):A(e=>[...e,{role:`system`,text:`✓ Syntax check: tutti i file JS sono validi.`}])}}async function Ye(){let e=p.filter(e=>e._error||e._syntaxError);if(e.length!==0){x(!0),C(0),ee(e.length),Me.current=Date.now(),je(`0s`);for(let t=0;t<e.length;t++){let n=e[t];ne(n.name),C(t),await Ve(`REPAIR FILE: ${n.name}\nErrore: ${n._syntaxError??`generazione fallita`}\nRigenera il file correttamente. Output SOLO il contenuto del file, nessuna spiegazione.`,null,[])}C(e.length),ne(``),x(!1)}}async function Xe(){if(!be||!a)return;let e=await D(`/api/studio/webcraft/grep`,{projectName:a,query:be});e?.matches&&L(e.matches)}function Ze(e){let t=p.findIndex(t=>t.name===e);t>=0&&(g(t),i(`files`))}function Qe(){window.open(`/api/studio/webcraft/download/${encodeURIComponent(a)}`,`_blank`)}async function $e(e,t,n,r){t.endsWith(`.md`)||(t+=`.md`);let i={name:t,content:n,type:r},o;o=e.mode===`edit`&&e.idx!==null?fe.map((t,n)=>n===e.idx?i:t):[...fe,i],pe(o),ge(null),await D(`/api/studio/webcraft/skills/${encodeURIComponent(a)}`,{skills:o})}async function et(e){let t=fe[e];!t||!confirm(`Eliminare "${t.name}"?`)||(await D(`/api/studio/webcraft/skills/${encodeURIComponent(a)}/delete`,{name:t.name}),pe(fe.filter((t,n)=>n!==e)))}async function tt(e){let t=fe[e];if(!t||!confirm(`Svuotare "${t.name}"? Il file rimane ma il contenuto viene cancellato.`))return;let n=fe.map((t,n)=>n===e?{...t,content:``}:t);pe(n),await D(`/api/studio/webcraft/skills/${encodeURIComponent(a)}`,{skills:n})}async function nt(){let e=await E(`/api/studio/webcraft/projects`);e?.projects&&Te(e.projects)}async function rt(e){let t=await E(`/api/studio/webcraft/projects/load/${encodeURIComponent(e.name)}`);if(!t)return;o(t.projectName??e.name),c(t.description??``),m(t.files??[]),g(0),n(`new`),i(`files`),A([]),pe([]),P(!1);let r=await E(`/api/studio/webcraft/projects/chat/load/${encodeURIComponent(t.projectName??e.name)}`);r?.chat&&A(r.chat);let a=await E(`/api/studio/webcraft/skills/${encodeURIComponent(t.projectName??e.name)}`);a?.skills&&(pe(a.skills),P(!0))}async function it(e){confirm(`Eliminare: ${e.name} - ${e.dir}?`)&&(await D(`/api/studio/webcraft/projects/${encodeURIComponent(e.name)}`,{},`DELETE`),Te(we.filter(t=>t.name!==e.name)),a===e.name&&(o(``),m([]),A([]),c(``)))}async function z(){if(!N)return;let e=N.originalMessage;de(null),await Ve(e+`
503
- [Piano approvato — procedi con le modifiche]`,null,[])}function at(e){e&&Array.from(e).forEach(e=>{let t=new FileReader;t.onload=t=>{let n=(t.target?.result).split(`,`)[1];ue(t=>[...t,{name:e.name,mimeType:e.type,base64:n,size:e.size}])},t.readAsDataURL(e)})}let ot=a&&p.length>0,st=p[h],ct=se||v;return(0,k.jsxs)(`div`,{className:X.root,children:[(0,k.jsxs)(`div`,{className:X.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:X.title,children:`⚙ WebCraft`}),(0,k.jsx)(`div`,{className:X.subtitle,children:`Genera progetti web completi con agenti AI`})]}),(0,k.jsxs)(`div`,{className:X.headerTabs,children:[(0,k.jsx)(`button`,{className:`${X.tabBtn} ${t===`new`?X.tabActive:``}`,onClick:()=>n(`new`),children:`+ Nuovo`}),(0,k.jsx)(`button`,{className:`${X.tabBtn} ${t===`projects`?X.tabActive:``}`,onClick:()=>{n(`projects`),nt()},children:`📁 Progetti`})]})]}),(0,k.jsx)(`div`,{className:X.body,children:t===`projects`?(0,k.jsx)(`div`,{className:X.projectsList,children:we.length===0?(0,k.jsxs)(`div`,{className:X.emptyProjects,children:[(0,k.jsx)(`span`,{className:X.emptyIcon,children:`📁`}),(0,k.jsx)(`span`,{children:e(`webcraft.noProjects`)}),(0,k.jsx)(`span`,{className:X.emptyHint,children:`Crea un progetto nella tab Nuovo`})]}):we.map(e=>(0,k.jsxs)(`div`,{className:X.projectCard,children:[(0,k.jsxs)(`div`,{className:X.projectInfo,children:[(0,k.jsx)(`div`,{className:X.projectName,children:e.name}),(0,k.jsx)(`div`,{className:X.projectDesc,children:e.description}),(0,k.jsxs)(`div`,{className:X.projectMeta,children:[(0,k.jsxs)(`span`,{children:[`📄 `,e.fileCount,` file`]}),(0,k.jsxs)(`span`,{children:[`📅 `,e.createdAt?new Date(e.createdAt).toLocaleString():``]})]})]}),(0,k.jsx)(`button`,{className:X.openBtn,onClick:()=>rt(e),children:`↗ Apri`}),(0,k.jsx)(`button`,{className:X.deleteBtn,onClick:()=>it(e),children:`🗑`})]},e.name))}):(0,k.jsxs)(`div`,{className:X.editor,children:[(0,k.jsxs)(`div`,{className:X.examples,children:[(0,k.jsx)(`div`,{className:X.sectionLabel,children:`Esempi`}),(0,k.jsx)(`div`,{className:X.examplePills,children:tn.map(e=>(0,k.jsx)(`button`,{className:X.examplePill,onClick:()=>{o(e.name),c(e.desc),oe(e.desc)},children:e.name},e.name))})]}),(0,k.jsxs)(`div`,{className:X.editorCols,children:[(0,k.jsxs)(`div`,{className:X.leftSidebar,children:[(0,k.jsxs)(`div`,{className:X.panel,children:[(0,k.jsx)(`div`,{className:X.panelTitle,children:`Blocchi`}),nn.map(e=>(0,k.jsxs)(`label`,{className:X.blockLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:l[e.key],onChange:t=>u(n=>({...n,[e.key]:t.target.checked})),className:X.blockCheck}),(0,k.jsx)(`span`,{children:e.icon}),(0,k.jsx)(`span`,{children:e.label})]},e.key))]}),l.auth&&(0,k.jsxs)(`div`,{className:X.panel,children:[(0,k.jsxs)(`div`,{className:X.panelHeader,children:[(0,k.jsx)(`div`,{className:X.panelTitle,children:`Campi Auth`}),(0,k.jsx)(`button`,{className:X.addBtn,onClick:()=>f(e=>[...e,{label:`New field`,type:`text`,required:!1}]),children:`+ Campo`})]}),d.map((e,t)=>(0,k.jsxs)(`div`,{className:X.authField,children:[(0,k.jsx)(`input`,{value:e.label,onChange:e=>f(n=>n.map((n,r)=>r===t?{...n,label:e.target.value}:n)),className:X.authFieldInput}),(0,k.jsx)(`select`,{value:e.type,onChange:e=>f(n=>n.map((n,r)=>r===t?{...n,type:e.target.value}:n)),className:X.authFieldSelect,children:[`text`,`email`,`password`,`tel`,`date`,`number`].map(e=>(0,k.jsx)(`option`,{value:e,children:e},e))}),(0,k.jsx)(`input`,{type:`checkbox`,checked:e.required,onChange:e=>f(n=>n.map((n,r)=>r===t?{...n,required:e.target.checked}:n)),title:`Required`,className:X.authFieldReq}),(0,k.jsx)(`button`,{onClick:()=>f(e=>e.filter((e,n)=>n!==t)),className:X.removeFieldBtn,children:`×`})]},t))]}),(0,k.jsxs)(`div`,{className:X.panel,children:[(0,k.jsxs)(`div`,{className:X.panelHeader,children:[(0,k.jsx)(`div`,{className:X.panelTitle,children:`🗂 Contesto AI`}),ot&&(0,k.jsx)(`button`,{className:X.addBtn,onClick:()=>ge({mode:`new`,idx:null,name:``,content:``,type:`skill`,generating:!1}),children:`+ Skill`})]}),fe.length>0?(0,k.jsx)(`div`,{className:X.skillsList,children:fe.map((e,t)=>(0,k.jsxs)(`div`,{className:X.skillRow,children:[(0,k.jsx)(`span`,{className:X.skillIcon,children:sn(e.type)}),(0,k.jsx)(`span`,{className:X.skillName,title:e.name,children:e.name}),(0,k.jsx)(`span`,{className:`${X.skillBadge} ${X[`skillBadge_`+e.type]}`,children:e.type}),!e.content&&e.type!==`log`&&(0,k.jsx)(`span`,{className:X.skillEmpty,children:`⚠`}),(0,k.jsx)(`button`,{className:X.skillBtn,onClick:()=>ge({mode:e.type===`log`?`view`:`edit`,idx:t,name:e.name,content:e.content,type:e.type,generating:!1}),children:e.type===`log`?`👁`:`✏`}),e.type!==`memory`&&e.type!==`provider`&&e.type!==`log`&&(0,k.jsx)(`button`,{className:X.skillBtn,onClick:()=>tt(t),children:`🗑`}),e.type===`log`&&(0,k.jsx)(`button`,{className:X.skillBtn,onClick:()=>et(t),children:`🗑`})]},t))}):(0,k.jsx)(`div`,{className:X.skillsEmpty,children:ot?`Caricamento...`:`Genera un progetto per attivare i file di contesto.`})]}),_e.length>0&&(0,k.jsxs)(`div`,{className:X.panel,children:[(0,k.jsx)(`div`,{className:X.panelTitle,children:`💾 Snapshot`}),_e.slice(0,5).map(e=>{let t=e.ts.replace(`T`,` `).slice(0,16);return(0,k.jsxs)(`div`,{className:X.snapshotRow,children:[(0,k.jsx)(`span`,{className:X.snapshotTs,children:t}),(0,k.jsxs)(`span`,{className:X.snapshotCount,children:[e.fileCount,`f`]}),(0,k.jsx)(`button`,{className:X.snapshotBtn,onClick:()=>qe(e.ts),children:`↺`})]},e.ts)})]}),v&&(0,k.jsx)(`div`,{className:X.genStatus,children:`⏳ Generazione...`}),b&&(0,k.jsxs)(`div`,{className:X.repairStatus,children:[(0,k.jsx)(`div`,{className:X.repairStatusTitle,children:`🔧 Correzione automatica...`}),(0,k.jsxs)(`div`,{className:X.repairStatusProg,children:[S,` / `,w,` file`]}),(0,k.jsx)(`div`,{className:X.repairStatusFile,children:te})]}),p.length>0&&!v&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:X.actionRow,children:[(0,k.jsx)(`button`,{className:X.actionBtn,onClick:Qe,children:`⬇ ZIP`}),(0,k.jsx)(`button`,{className:X.actionBtnIcon,title:`Syntax check`,onClick:Je,children:`✅`}),(0,k.jsx)(`button`,{className:`${X.actionBtnIcon} ${F?X.actionBtnActive:``}`,title:`Grep`,onClick:()=>ye(!F),children:`🔍`}),(0,k.jsx)(`button`,{className:X.actionBtnIcon,title:`Snapshot`,onClick:Ge,children:`💾`})]}),p.some(e=>e._error||e._syntaxError)&&!b&&(0,k.jsx)(`button`,{className:X.repairBtn,onClick:Ye,children:`🔧 Correggi tutti i file rossi`}),(0,k.jsx)(`button`,{className:X.sandboxBtn,onClick:()=>i(`preview`),children:`▶ Sandbox`}),ie&&(0,k.jsxs)(`div`,{className:X.statsBar,children:[(0,k.jsxs)(`span`,{children:[`⏱ `,ie.seconds>=60?`${Math.floor(ie.seconds/60)}m ${ie.seconds%60}s`:`${ie.seconds}s`]}),(0,k.jsxs)(`span`,{children:[`↑ `,ie.tokIn.toLocaleString(),` tok`]}),(0,k.jsxs)(`span`,{children:[`↓ `,ie.tokOut.toLocaleString(),` tok`]}),(0,k.jsxs)(`span`,{children:[`📄 `,ie.files,` file`]})]})]})]}),(0,k.jsxs)(`div`,{className:X.rightPanel,children:[(0,k.jsxs)(`div`,{className:X.rightTabBar,children:[(0,k.jsx)(`button`,{className:`${X.rightTab} ${r===`preview`?``:X.rightTabActive}`,onClick:()=>i(`files`),children:`📄 File`}),(0,k.jsx)(`button`,{className:`${X.rightTab} ${r===`preview`?X.rightTabActive:``}`,onClick:()=>i(`preview`),children:`🌐 Sandbox`})]}),b&&(0,k.jsxs)(`div`,{className:X.repairBar,children:[(0,k.jsxs)(`div`,{className:X.repairBarRow,children:[(0,k.jsx)(`span`,{className:X.repairBarIcon,children:`🔧`}),(0,k.jsx)(`span`,{className:X.repairBarLabel,children:`Auto-fix`}),(0,k.jsx)(`span`,{className:X.repairBarFile,children:te}),(0,k.jsxs)(`span`,{className:X.repairBarCounter,children:[S,` / `,w]}),(0,k.jsx)(`span`,{className:X.repairBarTime,children:Ae}),(0,k.jsx)(`button`,{className:X.stopBtn,onClick:Ue,children:`⏹ Stop`})]}),(0,k.jsx)(`div`,{className:X.progressTrack,children:(0,k.jsx)(`div`,{className:X.repairProgress,style:{width:w>0?`${Math.round(S/w*100)}%`:`0%`}})})]}),v&&(0,k.jsxs)(`div`,{className:X.genBar,children:[(0,k.jsxs)(`div`,{className:X.genBarRow,children:[(0,k.jsx)(`span`,{className:X.genBarRobot,children:`🤖`}),(0,k.jsx)(`span`,{className:X.genBarLabel,children:`Generazione`}),(0,k.jsx)(`span`,{className:X.genBarFile,children:T.name.split(`,`)[0].trim()}),(0,k.jsxs)(`span`,{className:X.genBarCounter,children:[T.fi,` / `,T.total]}),(0,k.jsx)(`span`,{className:X.genBarTime,children:Oe}),(0,k.jsxs)(`span`,{className:X.genDots,children:[(0,k.jsx)(`span`,{className:`${X.dot} ${X.dot1}`}),(0,k.jsx)(`span`,{className:`${X.dot} ${X.dot2}`}),(0,k.jsx)(`span`,{className:`${X.dot} ${X.dot3}`})]})]}),(0,k.jsx)(`div`,{className:X.progressTrack,children:(0,k.jsx)(`div`,{className:X.genProgress,style:{width:T.total>0?`${Math.round(T.fi/T.total*100)}%`:`0%`}})})]}),r===`preview`?(0,k.jsx)(`div`,{className:X.sandboxWrap,children:Ee?(0,k.jsx)(`iframe`,{src:`http://127.0.0.1:${Ee}`,className:X.sandboxFrame,title:`WebCraft Sandbox`,sandbox:`allow-scripts allow-same-origin allow-forms`}):(0,k.jsxs)(`div`,{className:X.sandboxEmpty,children:[(0,k.jsx)(`span`,{children:`🌐`}),(0,k.jsx)(`span`,{children:e(`webcraft.stopped`)}),(0,k.jsx)(`button`,{className:X.sandboxStartBtn,onClick:()=>{D(`/api/studio/webcraft/sandbox/start`,{projectName:a}).then(e=>{e?.port&&De(e.port)})},children:`▶ Avvia Sandbox`})]})}):(0,k.jsx)(`div`,{className:X.codeArea,children:p.length===0?(0,k.jsxs)(`div`,{className:X.noFiles,children:[(0,k.jsx)(`span`,{className:X.noFilesIcon,children:`⚙`}),(0,k.jsx)(`span`,{children:e(`common.empty`)})]}):(0,k.jsxs)(`div`,{className:X.codeLayout,children:[(0,k.jsx)(`div`,{className:X.codeViewer,children:st&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:X.codeHeader,children:[(0,k.jsx)(`span`,{className:X.codeFileIcon,children:an(st.name)}),(0,k.jsx)(`span`,{className:X.codeFileName,children:st.name}),!st._pending&&!st._error&&(0,k.jsxs)(`span`,{className:X.codeFileMeta,children:[st.content.split(`
536
+ [Piano approvato — procedi con le modifiche]`,null,[])}function at(e){e&&Array.from(e).forEach(e=>{let t=new FileReader;t.onload=t=>{let n=(t.target?.result).split(`,`)[1];ue(t=>[...t,{name:e.name,mimeType:e.type,base64:n,size:e.size}])},t.readAsDataURL(e)})}let ot=a&&p.length>0,st=p[h],ct=se||v;return(0,k.jsxs)(`div`,{className:X.root,children:[(0,k.jsxs)(`div`,{className:X.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:X.title,children:`⚙ WebCraft`}),(0,k.jsx)(`div`,{className:X.subtitle,children:`Genera progetti web completi con agenti AI`})]}),(0,k.jsxs)(`div`,{className:X.headerTabs,children:[(0,k.jsx)(`button`,{className:`${X.tabBtn} ${t===`new`?X.tabActive:``}`,onClick:()=>n(`new`),children:`+ Nuovo`}),(0,k.jsx)(`button`,{className:`${X.tabBtn} ${t===`projects`?X.tabActive:``}`,onClick:()=>{n(`projects`),nt()},children:`📁 Progetti`})]})]}),(0,k.jsx)(`div`,{className:X.body,children:t===`projects`?(0,k.jsx)(`div`,{className:X.projectsList,children:we.length===0?(0,k.jsxs)(`div`,{className:X.emptyProjects,children:[(0,k.jsx)(`span`,{className:X.emptyIcon,children:`📁`}),(0,k.jsx)(`span`,{children:e(`webcraft.noProjects`)}),(0,k.jsx)(`span`,{className:X.emptyHint,children:`Crea un progetto nella tab Nuovo`})]}):we.map(e=>(0,k.jsxs)(`div`,{className:X.projectCard,children:[(0,k.jsxs)(`div`,{className:X.projectInfo,children:[(0,k.jsx)(`div`,{className:X.projectName,children:e.name}),(0,k.jsx)(`div`,{className:X.projectDesc,children:e.description}),(0,k.jsxs)(`div`,{className:X.projectMeta,children:[(0,k.jsxs)(`span`,{children:[`📄 `,e.fileCount,` file`]}),(0,k.jsxs)(`span`,{children:[`📅 `,e.createdAt?new Date(e.createdAt).toLocaleString():``]})]})]}),(0,k.jsx)(`button`,{className:X.openBtn,onClick:()=>rt(e),children:`↗ Apri`}),(0,k.jsx)(`button`,{className:X.deleteBtn,onClick:()=>it(e),children:`🗑`})]},e.name))}):(0,k.jsxs)(`div`,{className:X.editor,children:[(0,k.jsxs)(`div`,{className:X.examples,children:[(0,k.jsx)(`div`,{className:X.sectionLabel,children:`Esempi`}),(0,k.jsx)(`div`,{className:X.examplePills,children:tn.map(e=>(0,k.jsx)(`button`,{className:X.examplePill,onClick:()=>{o(e.name),c(e.desc),oe(e.desc)},children:e.name},e.name))})]}),(0,k.jsxs)(`div`,{className:X.editorCols,children:[(0,k.jsxs)(`div`,{className:X.leftSidebar,children:[(0,k.jsxs)(`div`,{className:X.panel,children:[(0,k.jsx)(`div`,{className:X.panelTitle,children:`Blocchi`}),nn.map(e=>(0,k.jsxs)(`label`,{className:X.blockLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:l[e.key],onChange:t=>u(n=>({...n,[e.key]:t.target.checked})),className:X.blockCheck}),(0,k.jsx)(`span`,{children:e.icon}),(0,k.jsx)(`span`,{children:e.label})]},e.key))]}),l.auth&&(0,k.jsxs)(`div`,{className:X.panel,children:[(0,k.jsxs)(`div`,{className:X.panelHeader,children:[(0,k.jsx)(`div`,{className:X.panelTitle,children:`Campi Auth`}),(0,k.jsx)(`button`,{className:X.addBtn,onClick:()=>f(e=>[...e,{label:`New field`,type:`text`,required:!1}]),children:`+ Campo`})]}),d.map((e,t)=>(0,k.jsxs)(`div`,{className:X.authField,children:[(0,k.jsx)(`input`,{value:e.label,onChange:e=>f(n=>n.map((n,r)=>r===t?{...n,label:e.target.value}:n)),className:X.authFieldInput}),(0,k.jsx)(`select`,{value:e.type,onChange:e=>f(n=>n.map((n,r)=>r===t?{...n,type:e.target.value}:n)),className:X.authFieldSelect,children:[`text`,`email`,`password`,`tel`,`date`,`number`].map(e=>(0,k.jsx)(`option`,{value:e,children:e},e))}),(0,k.jsx)(`input`,{type:`checkbox`,checked:e.required,onChange:e=>f(n=>n.map((n,r)=>r===t?{...n,required:e.target.checked}:n)),title:`Required`,className:X.authFieldReq}),(0,k.jsx)(`button`,{onClick:()=>f(e=>e.filter((e,n)=>n!==t)),className:X.removeFieldBtn,children:`×`})]},t))]}),(0,k.jsxs)(`div`,{className:X.panel,children:[(0,k.jsxs)(`div`,{className:X.panelHeader,children:[(0,k.jsx)(`div`,{className:X.panelTitle,children:`🗂 Contesto AI`}),ot&&(0,k.jsx)(`button`,{className:X.addBtn,onClick:()=>ge({mode:`new`,idx:null,name:``,content:``,type:`skill`,generating:!1}),children:`+ Skill`})]}),fe.length>0?(0,k.jsx)(`div`,{className:X.skillsList,children:fe.map((e,t)=>(0,k.jsxs)(`div`,{className:X.skillRow,children:[(0,k.jsx)(`span`,{className:X.skillIcon,children:sn(e.type)}),(0,k.jsx)(`span`,{className:X.skillName,title:e.name,children:e.name}),(0,k.jsx)(`span`,{className:`${X.skillBadge} ${X[`skillBadge_`+e.type]}`,children:e.type}),!e.content&&e.type!==`log`&&(0,k.jsx)(`span`,{className:X.skillEmpty,children:`⚠`}),(0,k.jsx)(`button`,{className:X.skillBtn,onClick:()=>ge({mode:e.type===`log`?`view`:`edit`,idx:t,name:e.name,content:e.content,type:e.type,generating:!1}),children:e.type===`log`?`👁`:`✏`}),e.type!==`memory`&&e.type!==`provider`&&e.type!==`log`&&(0,k.jsx)(`button`,{className:X.skillBtn,onClick:()=>tt(t),children:`🗑`}),e.type===`log`&&(0,k.jsx)(`button`,{className:X.skillBtn,onClick:()=>et(t),children:`🗑`})]},t))}):(0,k.jsx)(`div`,{className:X.skillsEmpty,children:ot?`Caricamento...`:`Genera un progetto per attivare i file di contesto.`})]}),_e.length>0&&(0,k.jsxs)(`div`,{className:X.panel,children:[(0,k.jsx)(`div`,{className:X.panelTitle,children:`💾 Snapshot`}),_e.slice(0,5).map(e=>{let t=e.ts.replace(`T`,` `).slice(0,16);return(0,k.jsxs)(`div`,{className:X.snapshotRow,children:[(0,k.jsx)(`span`,{className:X.snapshotTs,children:t}),(0,k.jsxs)(`span`,{className:X.snapshotCount,children:[e.fileCount,`f`]}),(0,k.jsx)(`button`,{className:X.snapshotBtn,onClick:()=>qe(e.ts),children:`↺`})]},e.ts)})]}),v&&(0,k.jsx)(`div`,{className:X.genStatus,children:`⏳ Generazione...`}),b&&(0,k.jsxs)(`div`,{className:X.repairStatus,children:[(0,k.jsx)(`div`,{className:X.repairStatusTitle,children:`🔧 Correzione automatica...`}),(0,k.jsxs)(`div`,{className:X.repairStatusProg,children:[S,` / `,w,` file`]}),(0,k.jsx)(`div`,{className:X.repairStatusFile,children:te})]}),p.length>0&&!v&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:X.actionRow,children:[(0,k.jsx)(`button`,{className:X.actionBtn,onClick:Qe,children:`⬇ ZIP`}),(0,k.jsx)(`button`,{className:X.actionBtnIcon,title:`Syntax check`,onClick:Je,children:`✅`}),(0,k.jsx)(`button`,{className:`${X.actionBtnIcon} ${F?X.actionBtnActive:``}`,title:`Grep`,onClick:()=>ye(!F),children:`🔍`}),(0,k.jsx)(`button`,{className:X.actionBtnIcon,title:`Snapshot`,onClick:Ge,children:`💾`})]}),p.some(e=>e._error||e._syntaxError)&&!b&&(0,k.jsx)(`button`,{className:X.repairBtn,onClick:Ye,children:`🔧 Correggi tutti i file rossi`}),(0,k.jsx)(`button`,{className:X.sandboxBtn,onClick:()=>i(`preview`),children:`▶ Sandbox`}),ie&&(0,k.jsxs)(`div`,{className:X.statsBar,children:[(0,k.jsxs)(`span`,{children:[`⏱ `,ie.seconds>=60?`${Math.floor(ie.seconds/60)}m ${ie.seconds%60}s`:`${ie.seconds}s`]}),(0,k.jsxs)(`span`,{children:[`↑ `,ie.tokIn.toLocaleString(),` tok`]}),(0,k.jsxs)(`span`,{children:[`↓ `,ie.tokOut.toLocaleString(),` tok`]}),(0,k.jsxs)(`span`,{children:[`📄 `,ie.files,` file`]})]})]})]}),(0,k.jsxs)(`div`,{className:X.rightPanel,children:[(0,k.jsxs)(`div`,{className:X.rightTabBar,children:[(0,k.jsx)(`button`,{className:`${X.rightTab} ${r===`preview`?``:X.rightTabActive}`,onClick:()=>i(`files`),children:`📄 File`}),(0,k.jsx)(`button`,{className:`${X.rightTab} ${r===`preview`?X.rightTabActive:``}`,onClick:()=>i(`preview`),children:`🌐 Sandbox`})]}),b&&(0,k.jsxs)(`div`,{className:X.repairBar,children:[(0,k.jsxs)(`div`,{className:X.repairBarRow,children:[(0,k.jsx)(`span`,{className:X.repairBarIcon,children:`🔧`}),(0,k.jsx)(`span`,{className:X.repairBarLabel,children:`Auto-fix`}),(0,k.jsx)(`span`,{className:X.repairBarFile,children:te}),(0,k.jsxs)(`span`,{className:X.repairBarCounter,children:[S,` / `,w]}),(0,k.jsx)(`span`,{className:X.repairBarTime,children:Ae}),(0,k.jsx)(`button`,{className:X.stopBtn,onClick:Ue,children:`⏹ Stop`})]}),(0,k.jsx)(`div`,{className:X.progressTrack,children:(0,k.jsx)(`div`,{className:X.repairProgress,style:{width:w>0?`${Math.round(S/w*100)}%`:`0%`}})})]}),v&&(0,k.jsxs)(`div`,{className:X.genBar,children:[(0,k.jsxs)(`div`,{className:X.genBarRow,children:[(0,k.jsx)(`span`,{className:X.genBarRobot,children:`🤖`}),(0,k.jsx)(`span`,{className:X.genBarLabel,children:`Generazione`}),(0,k.jsx)(`span`,{className:X.genBarFile,children:T.name.split(`,`)[0].trim()}),(0,k.jsxs)(`span`,{className:X.genBarCounter,children:[T.fi,` / `,T.total]}),(0,k.jsx)(`span`,{className:X.genBarTime,children:Oe}),(0,k.jsxs)(`span`,{className:X.genDots,children:[(0,k.jsx)(`span`,{className:`${X.dot} ${X.dot1}`}),(0,k.jsx)(`span`,{className:`${X.dot} ${X.dot2}`}),(0,k.jsx)(`span`,{className:`${X.dot} ${X.dot3}`})]})]}),(0,k.jsx)(`div`,{className:X.progressTrack,children:(0,k.jsx)(`div`,{className:X.genProgress,style:{width:T.total>0?`${Math.round(T.fi/T.total*100)}%`:`0%`}})})]}),r===`preview`?(0,k.jsx)(`div`,{className:X.sandboxWrap,children:Ee?(0,k.jsx)(`iframe`,{src:`http://127.0.0.1:${Ee}`,className:X.sandboxFrame,title:`WebCraft Sandbox`,sandbox:`allow-scripts allow-same-origin allow-forms`}):(0,k.jsxs)(`div`,{className:X.sandboxEmpty,children:[(0,k.jsx)(`span`,{children:`🌐`}),(0,k.jsx)(`span`,{children:e(`webcraft.stopped`)}),(0,k.jsx)(`button`,{className:X.sandboxStartBtn,onClick:()=>{D(`/api/studio/webcraft/sandbox/start`,{projectName:a}).then(e=>{e?.port&&De(e.port)})},children:`▶ Avvia Sandbox`})]})}):(0,k.jsx)(`div`,{className:X.codeArea,children:p.length===0?(0,k.jsxs)(`div`,{className:X.noFiles,children:[(0,k.jsxs)(`div`,{className:X.noFilesHero,children:[(0,k.jsx)(`span`,{className:X.noFilesIcon,children:`🔨`}),(0,k.jsx)(`span`,{className:X.noFilesTitle,children:`WebCraft`}),(0,k.jsx)(`span`,{className:X.noFilesTagline,children:`Genera progetti web completi con AI`})]}),(0,k.jsxs)(`div`,{className:X.noFilesSteps,children:[(0,k.jsxs)(`div`,{className:X.noFilesStep,children:[(0,k.jsx)(`span`,{className:X.noFilesStepNum,children:`1`}),(0,k.jsx)(`span`,{children:`Scegli un esempio o scrivi una descrizione nel box in basso`})]}),(0,k.jsxs)(`div`,{className:X.noFilesStep,children:[(0,k.jsx)(`span`,{className:X.noFilesStepNum,children:`2`}),(0,k.jsxs)(`span`,{children:[`Premi `,(0,k.jsx)(`strong`,{children:`▶ Genera`}),` — l'AI crea tutti i file del progetto`]})]}),(0,k.jsxs)(`div`,{className:X.noFilesStep,children:[(0,k.jsx)(`span`,{className:X.noFilesStepNum,children:`3`}),(0,k.jsx)(`span`,{children:`Chiedi modifiche in chat, scarica lo ZIP o avvia il Sandbox`})]})]}),(0,k.jsxs)(`div`,{className:X.noFilesExamplesHint,children:[`💡 Prova: `,(0,k.jsx)(`button`,{className:X.noFilesExampleBtn,onClick:()=>{let e=tn[0];o(e.name),c(e.desc),oe(e.desc)},children:`MySaaS`}),(0,k.jsx)(`button`,{className:X.noFilesExampleBtn,onClick:()=>{let e=tn[1];o(e.name),c(e.desc),oe(e.desc)},children:`MyShop`}),(0,k.jsx)(`button`,{className:X.noFilesExampleBtn,onClick:()=>{let e=tn[3];o(e.name),c(e.desc),oe(e.desc)},children:`MyPortfolio`})]})]}):(0,k.jsxs)(`div`,{className:X.codeLayout,children:[(0,k.jsx)(`div`,{className:X.codeViewer,children:st&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:X.codeHeader,children:[(0,k.jsx)(`span`,{className:X.codeFileIcon,children:an(st.name)}),(0,k.jsx)(`span`,{className:X.codeFileName,children:st.name}),!st._pending&&!st._error&&(0,k.jsxs)(`span`,{className:X.codeFileMeta,children:[st.content.split(`
504
537
  `).length,` righe · `,on(st.content)]})]}),st._error&&(0,k.jsx)(`div`,{className:X.fileError,children:`⚠ Generazione fallita — chiedi al modello di rigenerare questo file`}),st._syntaxError&&!st._error&&(0,k.jsxs)(`div`,{className:X.fileSyntaxError,children:[`⚠ Syntax error: `,st._syntaxError]}),st._pending?(0,k.jsx)(`div`,{className:X.filePending,children:`⌛ In generazione...`}):(0,k.jsx)(`pre`,{className:`${X.code} ${st._error?X.codeError:st._syntaxError?X.codeSyntaxError:``}`,children:st.content})]})}),(0,k.jsxs)(`div`,{className:X.fileSidebar,children:[(0,k.jsxs)(`div`,{className:X.fileSidebarHeader,children:[p.length,` file`]}),p.map((e,t)=>{let n=e._error||!!e._syntaxError,r=t===h;return(0,k.jsxs)(`button`,{className:`${X.fileTab} ${r?X.fileTabActive:``} ${n?X.fileTabError:``}`,onClick:()=>g(t),children:[(0,k.jsxs)(`div`,{className:X.fileTabRow,children:[(0,k.jsx)(`span`,{className:X.fileTabIcon,children:e._pending?`⌛`:n?`⚠`:an(e.name)}),(0,k.jsx)(`span`,{className:X.fileTabName,children:e.name.split(`/`).pop()})]}),e.name.includes(`/`)&&(0,k.jsx)(`div`,{className:X.fileTabDir,children:e.name.split(`/`).slice(0,-1).join(`/`)}),!e._pending&&(0,k.jsxs)(`div`,{className:X.fileTabMeta,children:[e.content.split(`
505
538
  `).length,` righe · `,on(e.content)]})]},t)})]})]})})]})]})]})}),N&&t!==`projects`&&(0,k.jsxs)(`div`,{className:X.planBanner,children:[(0,k.jsx)(`div`,{className:X.planTitle,children:`📌 Piano proposto — approva per eseguire`}),(0,k.jsx)(`pre`,{className:X.planText,children:N.plan}),(0,k.jsxs)(`div`,{className:X.planActions,children:[(0,k.jsx)(`button`,{className:X.planApprove,onClick:z,children:`✓ Esegui`}),(0,k.jsx)(`button`,{className:X.planReject,onClick:()=>de(null),children:`✕ Annulla`})]})]}),F&&t!==`projects`&&(0,k.jsxs)(`div`,{className:X.grepPanel,children:[(0,k.jsxs)(`div`,{className:X.grepRow,children:[(0,k.jsx)(`input`,{className:X.grepInput,value:be,onChange:e=>xe(e.target.value),onKeyDown:e=>e.key===`Enter`&&Xe(),placeholder:`Cerca nel codice...`}),(0,k.jsx)(`button`,{className:X.grepBtn,onClick:Xe,children:`🔍`}),(0,k.jsx)(`button`,{className:X.grepClose,onClick:()=>ye(!1),children:`×`})]}),I.length>0&&(0,k.jsxs)(`div`,{className:X.grepCount,children:[I.length,` risultati`]}),(0,k.jsx)(`div`,{className:X.grepResults,children:I.length===0?(0,k.jsx)(`div`,{className:X.grepEmpty,children:`Nessun risultato.`}):I.map((e,t)=>(0,k.jsxs)(`div`,{className:X.grepMatch,onClick:()=>Ze(e.file),children:[(0,k.jsxs)(`span`,{className:X.grepMatchFile,children:[e.file,`:`,e.lineNum]}),(0,k.jsx)(`pre`,{className:X.grepMatchLine,children:e.line})]},t))})]}),Se.length>0&&t!==`projects`&&(0,k.jsxs)(`div`,{className:X.diffPanel,children:[(0,k.jsxs)(`div`,{className:X.diffHeader,children:[(0,k.jsxs)(`span`,{children:[`🔌 Diff — `,Se.length,` file modificati`]}),(0,k.jsx)(`button`,{className:X.diffClose,onClick:()=>Ce([]),children:`✕ Chiudi`})]}),Se.map((e,t)=>{let n=e.after.split(`
506
539
  `).length-e.before.split(`