nothumanallowed 14.1.76 → 14.1.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nothumanallowed",
3
- "version": "14.1.76",
3
+ "version": "14.1.77",
4
4
  "description": "NotHumanAllowed — 38 AI agents, 80 tools, Studio (visual agentic workflows). Email, calendar, browser automation, screen capture, canvas, cron/heartbeat, Alexandria E2E messaging, GitHub, Notion, Slack, voice chat, free AI (Liara), 28 languages. Zero-dependency CLI.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/constants.mjs CHANGED
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'url';
5
5
  const __filename = fileURLToPath(import.meta.url);
6
6
  const __dirname = path.dirname(__filename);
7
7
 
8
- export const VERSION = '14.1.76';
8
+ export const VERSION = '14.1.77';
9
9
  export const BASE_URL = 'https://nothumanallowed.com/cli';
10
10
  export const API_BASE = 'https://nothumanallowed.com/api/v1';
11
11
 
@@ -142,12 +142,15 @@ class SandboxManager {
142
142
  });
143
143
 
144
144
  this._sandbox = { proc, port, projectName, startedAt: new Date(), healthy: false };
145
+ let readyEmitted = false;
145
146
 
146
147
  proc.stdout.on('data', (d) => {
147
148
  const line = d.toString().trim();
148
149
  if (line) emit({ type: 'log', msg: line });
149
- if (/listen|running|started|ready|port/i.test(line)) {
150
+ if (!readyEmitted && /listen|running|started|ready|port/i.test(line)) {
151
+ readyEmitted = true;
150
152
  if (this._sandbox) this._sandbox.healthy = true;
153
+ emit({ type: 'phase', phase: 'ready', msg: `Server running on port ${port}` });
151
154
  emit({ type: 'ready', port });
152
155
  }
153
156
  });
@@ -172,13 +175,18 @@ class SandboxManager {
172
175
  ]);
173
176
 
174
177
  if (healthy === 'healthy') {
175
- if (this._sandbox) this._sandbox.healthy = true;
176
- emit({ type: 'phase', phase: 'ready', msg: `Server running on port ${port}` });
177
- emit({ type: 'ready', port });
178
+ if (!readyEmitted) {
179
+ readyEmitted = true;
180
+ if (this._sandbox) this._sandbox.healthy = true;
181
+ emit({ type: 'phase', phase: 'ready', msg: `Server running on port ${port}` });
182
+ emit({ type: 'ready', port });
183
+ }
178
184
  return;
179
185
  }
180
186
 
187
+ // If ready was already emitted by stdout, ignore timeout
181
188
  if (healthy === 'timeout') {
189
+ if (readyEmitted) return;
182
190
  emit({ type: 'warn', msg: 'Server started but port not yet bound — may still be loading.' });
183
191
  return;
184
192
  }
@@ -588,7 +588,7 @@ ${u}
588
588
 
589
589
  `),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 ne(`/api/chat/stream`,{message:r,systemPrompt:`You are the Conductor — a meta-agent that synthesizes the outputs of multiple specialist AI agents.
590
590
  Your job: examine all agent responses to a user's question, identify agreements, disagreements, complementary insights, and deliver a unified, high-quality synthesis.
591
- 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)}},pe=e=>{let t=window.SpeechRecognition??window.webkitSpeechRecognition;if(!t){alert(`Speech recognition not supported.`);return}let n=D.current.get(e);if(l.find(t=>t.agent.id===e)?.voiceActive&&n){n.stop(),F(e,{voiceActive:!1});return}let r=new t;D.current.set(e,r),r.lang=`it-IT`,r.continuous=!1,r.interimResults=!1,r.onresult=t=>{let n=t.results[0][0].transcript;F(e,{input:(l.find(t=>t.agent.id===e)?.input??``)+(l.find(t=>t.agent.id===e)?.input?` `:``)+n})},r.onend=()=>F(e,{voiceActive:!1}),r.onerror=()=>F(e,{voiceActive:!1}),r.start(),F(e,{voiceActive:!0})},me=(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];F(e,{attachedFile:{name:t.name,size:t.size,base64:r,mimeType:`application/pdf`,isPDF:!0},attachedImage:null})},r.readAsDataURL(t)):(r.onload=n=>{F(e,{attachedFile:{name:t.name,size:t.size,content:n.target?.result},attachedImage:null})},r.readAsText(t))},he=(e,t)=>{if(!t)return;let n=new FileReader;n.onload=n=>{let r=(n.target?.result).split(`,`)[1];F(e,{attachedImage:{name:t.name,size:t.size,base64:r,mimeType:t.type||`image/jpeg`},attachedFile:null})},n.readAsDataURL(t)},ge=()=>{x({name:``,tagline:``,systemPrompt:``}),C(`create`),T(``)},_e=async e=>{let t=await O(`/api/agents/${e.id}`).catch(()=>null);x({name:e.id,tagline:t?.tagline??e.description,systemPrompt:t?.systemPrompt??``}),C(`edit`),T(``)},ve=async()=>{if(b){if(!b.tagline.trim()||!b.systemPrompt.trim()){T(`Tagline and system prompt are required.`);return}ee(!0),T(``);try{if(S===`create`){let e=b.name.toLowerCase().replace(/[^a-z0-9_-]/g,``);if(!e){T(`Agent name required (lowercase, no spaces).`),ee(!1);return}let t=await k(`/api/agents`,{name:e,tagline:b.tagline,systemPrompt:b.systemPrompt});if(t?.error){T(`Error: `+t.error),ee(!1);return}}else await k(`/api/agents/${b.name}`,{tagline:b.tagline,systemPrompt:b.systemPrompt,category:`custom`},`PUT`);x(null),ie()}catch(e){T(`Error: `+e.message)}finally{ee(!1)}}},I=e=>{confirm(`Delete agent "${e.label}"?`)&&k(`/api/agents/${e.id}`,{},`DELETE`).then(()=>ie())};return r?(0,j.jsx)(`div`,{className:q.root,children:(0,j.jsx)(`div`,{className:q.loading,children:(0,j.jsx)(`div`,{className:`spinner`})})}):(0,j.jsxs)(`div`,{className:q.root,children:[(0,j.jsxs)(`div`,{className:q.gridSection,children:[(0,j.jsxs)(`div`,{className:q.gridHeader,children:[(0,j.jsxs)(`div`,{className:q.headerRow,children:[(0,j.jsx)(`input`,{className:q.search,value:a,onChange:e=>o(e.target.value),placeholder:`Search agents…`}),(0,j.jsx)(`button`,{className:q.createBtn,onClick:ge,children:`+ Create`})]}),(0,j.jsx)(`div`,{className:q.catTabs,children:ae.map(e=>(0,j.jsxs)(`button`,{className:`${q.catTab} ${s===e?q.catActive:``}`,onClick:()=>c(e),children:[e,` (`,e===`All`?t.length:t.filter(t=>t.category===e).length,`)`]},e))})]}),(0,j.jsx)(`div`,{className:q.grid,children:oe.map(e=>{let t=l.some(t=>t.agent.id===e.id);return(0,j.jsxs)(`div`,{className:`${q.agentCard} ${t?q.agentActive:``}`,onClick:()=>se(e),children:[(0,j.jsxs)(`div`,{className:q.agentCardTop,children:[(0,j.jsx)(`div`,{className:q.agentIcon,children:e.icon}),e.isCustom&&(0,j.jsxs)(`div`,{className:q.agentActions,children:[(0,j.jsx)(`button`,{className:q.agentEditBtn,onClick:t=>{t.stopPropagation(),_e(e)},children:`✏️`}),(0,j.jsx)(`button`,{className:q.agentDelBtn,onClick:t=>{t.stopPropagation(),I(e)},children:`🗑`})]})]}),(0,j.jsx)(`div`,{className:q.agentLabel,children:e.label}),(0,j.jsx)(`div`,{className:q.agentDesc,children:e.description}),(0,j.jsx)(`div`,{className:q.agentCat,children:e.category})]},e.id)})})]}),(0,j.jsx)(`div`,{className:q.chatArea,children:l.length===0?(0,j.jsxs)(`div`,{className:q.emptyChat,children:[(0,j.jsx)(`span`,{children:`Click an agent above to open a chat`}),(0,j.jsx)(`span`,{className:q.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,j.jsxs)(`div`,{className:q.chatPanel,children:[(0,j.jsxs)(`div`,{className:q.chatHeader,children:[(0,j.jsx)(`span`,{className:q.chatIcon,children:t.icon}),(0,j.jsxs)(`div`,{className:q.chatHeaderInfo,children:[(0,j.jsx)(`div`,{className:q.chatAgentName,children:t.label}),(0,j.jsx)(`div`,{className:q.chatAgentDesc,children:t.description})]}),(0,j.jsx)(`button`,{className:q.closeChat,onClick:()=>ce(t.id),children:`✕`})]}),(0,j.jsxs)(`div`,{className:q.chatMessages,ref:e=>{A.current.set(t.id,e)},children:[e.history.length===0&&(0,j.jsxs)(`div`,{className:q.chatEmpty,children:[`Ask `,t.label,` anything…`]}),e.history.map((e,t)=>(0,j.jsx)(`div`,{className:`${q.chatMsg} ${e.role===`user`?q.msgUser:q.msgAgent}`,children:e.role===`assistant`?(0,j.jsx)(`div`,{dangerouslySetInnerHTML:{__html:ye(e.content||`…`)}}):(0,j.jsx)(`span`,{children:e.content})},t)),e.streaming&&e.history[e.history.length-1]?.role===`assistant`&&e.history[e.history.length-1]?.content===``&&(0,j.jsxs)(`div`,{className:q.thinking,children:[(0,j.jsx)(`span`,{className:q.dot}),(0,j.jsx)(`span`,{className:q.dot}),(0,j.jsx)(`span`,{className:q.dot})]})]}),n&&(0,j.jsxs)(`div`,{className:q.attachBar,children:[(0,j.jsx)(`span`,{children:n}),(0,j.jsx)(`button`,{className:q.attachClear,onClick:()=>F(t.id,{attachedFile:null,attachedImage:null}),children:`×`})]}),(0,j.jsxs)(`div`,{className:q.chatInput,children:[(0,j.jsxs)(`div`,{className:q.chatTools,children:[(0,j.jsx)(`button`,{className:`${q.toolBtn} ${e.voiceActive?q.toolBtnActive:``}`,onClick:()=>pe(t.id),title:`Voice`,children:`🎤`}),(0,j.jsx)(`button`,{className:q.toolBtn,onClick:()=>re.current.get(t.id)?.click(),title:`Attach file`,children:`📎`}),(0,j.jsx)(`button`,{className:q.toolBtn,onClick:()=>M.current.get(t.id)?.click(),title:`Attach image`,children:`🖼`}),(0,j.jsx)(`input`,{type:`file`,style:{display:`none`},ref:e=>{re.current.set(t.id,e)},onChange:e=>me(t.id,e.target.files?.[0])}),(0,j.jsx)(`input`,{type:`file`,accept:`image/*`,style:{display:`none`},ref:e=>{M.current.set(t.id,e)},onChange:e=>he(t.id,e.target.files?.[0])})]}),(0,j.jsxs)(`div`,{className:q.chatInputRow,children:[(0,j.jsx)(`textarea`,{className:q.chatTextarea,value:e.input,onChange:e=>F(t.id,{input:e.target.value}),placeholder:`Message ${t.label}…`,rows:2,onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),de(e,e.input,e.attachedFile,e.attachedImage))}}),(0,j.jsx)(`button`,{className:q.sendBtn,onClick:()=>de(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,j.jsxs)(`div`,{className:q.orchBar,children:[(0,j.jsxs)(`div`,{className:q.orchLabel,children:[`🎼 Conductor · `,l.map(e=>`${e.agent.icon} ${e.agent.label}`).join(` · `)]}),(0,j.jsxs)(`div`,{className:q.orchRow,children:[(0,j.jsx)(`textarea`,{ref:N,className:q.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(),fe())}}),(0,j.jsx)(`button`,{className:q.orchBtn,onClick:fe,disabled:p||v||!d.trim(),children:p?`⏳`:v?`🔄`:`🎼 Run`})]}),(v||h)&&(0,j.jsxs)(`div`,{className:q.orchSynthesis,children:[(0,j.jsxs)(`div`,{className:q.orchSynthHeader,children:[(0,j.jsx)(`span`,{children:`🎼 Conductor Synthesis`}),v&&(0,j.jsx)(`span`,{className:q.orchSynthSpinner,children:`synthesizing…`})]}),(0,j.jsx)(`div`,{className:q.orchSynthBody,dangerouslySetInnerHTML:{__html:ye(h||`…`)}})]})]}),b&&(0,j.jsx)(`div`,{className:q.modalOverlay,onClick:e=>{e.target===e.currentTarget&&x(null)},children:(0,j.jsxs)(`div`,{className:q.modal,children:[(0,j.jsx)(`div`,{className:q.modalTitle,children:S===`create`?`+ New Agent`:`✏️ Edit Agent`}),S===`create`&&(0,j.jsxs)(`div`,{className:q.formField,children:[(0,j.jsx)(`label`,{className:q.formLabel,children:`Agent name (lowercase, no spaces)`}),(0,j.jsx)(`input`,{className:q.formInput,placeholder:`my-agent`,value:b.name,onChange:e=>x(t=>t&&{...t,name:e.target.value})})]}),(0,j.jsxs)(`div`,{className:q.formField,children:[(0,j.jsx)(`label`,{className:q.formLabel,children:`Tagline`}),(0,j.jsx)(`input`,{className:q.formInput,placeholder:`Short description`,value:b.tagline,onChange:e=>x(t=>t&&{...t,tagline:e.target.value})})]}),(0,j.jsxs)(`div`,{className:q.formField,children:[(0,j.jsx)(`label`,{className:q.formLabel,children:`System Prompt`}),(0,j.jsx)(`textarea`,{className:q.formTextarea,placeholder:`You are an expert in…`,value:b.systemPrompt,onChange:e=>x(t=>t&&{...t,systemPrompt:e.target.value})})]}),w&&(0,j.jsx)(`div`,{className:q.formError,children:w}),(0,j.jsxs)(`div`,{className:q.modalBtns,children:[(0,j.jsx)(`button`,{className:q.cancelBtn,onClick:()=>x(null),children:e(`common.cancel`)}),(0,j.jsx)(`button`,{className:q.modalSaveBtn,onClick:ve,disabled:E,children:E?`…`:S===`create`?`Create Agent`:`Save`})]})]})})]})}var J={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 Zt(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 $t(){let e=P(),[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),T=(e=s,t=l)=>{i(!0);let r=`/api/drive`;e&&(r+=`?filter=${e}`),t&&(r+=`${e?`&`:`?`}search=${encodeURIComponent(t)}`),O(r).then(e=>{n(e??{files:[]}),i(!1)}).catch(e=>{o(e.message??`Error`),i(!1)})};(0,_.useEffect)(()=>{T()},[]);let E=e=>{c(e),T(e,l)},ee=()=>{u(d),T(s,d)},D=(e,t)=>{i(!0),O(`/api/drive/read/${e}`).then(n=>{g({id:e,name:t,content:n?.content??``}),y(n?.content??``),m(`editor`),i(!1)}).catch(()=>i(!1))},te=async()=>{if(h&&confirm(`Save changes to "${h.name}" on Drive?`)){C(!0);try{await k(`/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)}}},ne=(e,t)=>{i(!0),O(`/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))},A=(e,t)=>{i(!0),O(`/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))},re=(e,t)=>{confirm(`Delete "${t}" from Drive? (moved to trash)`)&&k(`/api/drive/delete/${e}`,{}).then(()=>{n(null),T()})},M=()=>{let e=prompt(`File name (e.g. notes.txt, script.py):`);e&&k(`/api/drive/upload`,{name:e,content:``,mimeType:`text/plain`}).then(t=>{t?.id?D(t.id,e):T()}).catch(e=>alert(`Error: `+e.message))},N=()=>{w.current?.click()},ie=e=>{if(!e)return;let t=new FileReader;t.onload=t=>{let r=(t.target?.result).split(`,`)[1]??``;k(`/api/drive/upload`,{name:e.name,content:r,mimeType:e.type||`application/octet-stream`,encoding:`base64`}).then(()=>{n(null),T()}).catch(e=>alert(`Upload error: `+e.message))},t.readAsDataURL(e)};if(a)return(0,j.jsxs)(`div`,{className:J.error,children:[(0,j.jsx)(`div`,{children:a}),(0,j.jsxs)(`div`,{className:J.errorHint,children:[`Run: `,(0,j.jsx)(`code`,{children:`nha google revoke`}),` then `,(0,j.jsx)(`code`,{children:`nha google auth`})]})]});if(p===`editor`&&h)return(0,j.jsxs)(`div`,{className:J.editorRoot,children:[(0,j.jsxs)(`div`,{className:J.editorToolbar,children:[(0,j.jsx)(`button`,{className:J.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,j.jsx)(`span`,{className:J.editorName,children:h.name}),(0,j.jsx)(`button`,{className:J.saveBtn,onClick:te,disabled:S,children:S?`Saving…`:`Save to Drive`})]}),(0,j.jsx)(`textarea`,{className:J.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,j.jsxs)(`div`,{className:J.editorMeta,children:[`File ID: `,h.id,` · Tab = 2 spaces · Not auto-saved`]})]});if(p===`image`&&b)return(0,j.jsxs)(`div`,{className:J.viewerRoot,children:[(0,j.jsxs)(`div`,{className:J.editorToolbar,children:[(0,j.jsx)(`button`,{className:J.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,j.jsx)(`span`,{className:J.editorName,children:b.name})]}),(0,j.jsx)(`div`,{className:J.imgContainer,children:(0,j.jsx)(`img`,{src:b.src,alt:b.name,className:J.imgView})})]});if(p===`pdf`&&b)return(0,j.jsxs)(`div`,{className:J.viewerRoot,children:[(0,j.jsxs)(`div`,{className:J.editorToolbar,children:[(0,j.jsx)(`button`,{className:J.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,j.jsx)(`span`,{className:J.editorName,children:b.name})]}),(0,j.jsx)(`iframe`,{className:J.pdfFrame,src:b.src,title:b.name})]});let ae=t?.files??[],oe=t?.quota;return(0,j.jsxs)(`div`,{className:J.root,children:[oe&&(0,j.jsxs)(`div`,{className:J.quotaBar,children:[(0,j.jsxs)(`div`,{className:J.quotaText,children:[(0,j.jsxs)(`span`,{className:J.quotaUsed,children:[oe.usage,` of `,oe.limit,` used`]}),(0,j.jsxs)(`span`,{className:J.quotaPct,children:[oe.percentUsed,`%`]})]}),(0,j.jsx)(`div`,{className:J.quotaTrack,children:(0,j.jsx)(`div`,{className:J.quotaFill,style:{width:`${Math.min(oe.percentUsed,100)}%`,background:oe.percentUsed>90?`var(--red)`:oe.percentUsed>70?`var(--amber)`:`var(--green)`}})})]}),(0,j.jsxs)(`div`,{className:J.actionBar,children:[[``,`recent`,`starred`,`shared`].map(e=>(0,j.jsx)(`button`,{className:`${J.filterBtn} ${s===e?J.filterActive:``}`,onClick:()=>E(e),children:e?e.charAt(0).toUpperCase()+e.slice(1):`All Files`},e)),(0,j.jsx)(`div`,{className:J.spacer}),(0,j.jsx)(`button`,{className:J.newBtn,onClick:M,children:`+ New File`}),(0,j.jsx)(`button`,{className:J.uploadBtn,onClick:N,children:e(`drive.upload`)}),(0,j.jsx)(`input`,{ref:w,type:`file`,style:{display:`none`},onChange:e=>ie(e.target.files?.[0])})]}),(0,j.jsxs)(`div`,{className:J.searchRow,children:[(0,j.jsx)(`input`,{className:J.searchInput,value:d,onChange:e=>f(e.target.value),placeholder:`Search files…`,onKeyDown:e=>e.key===`Enter`&&ee()}),(0,j.jsx)(`button`,{className:J.searchBtn,onClick:ee,children:`Search`})]}),r&&(0,j.jsx)(`div`,{className:J.loading,children:(0,j.jsx)(`div`,{className:`spinner`})}),!r&&ae.length===0&&(0,j.jsxs)(`div`,{className:J.empty,children:[e(`drive.noFiles`),` found`]}),(0,j.jsx)(`div`,{className:J.fileList,children:ae.map(e=>{let t=Qt(e),n=e.type===`image`,r=e.type===`pdf`||e.mimeType.includes(`pdf`);return(0,j.jsxs)(`div`,{className:J.fileRow,onClick:()=>{t?D(e.id,e.name):n?ne(e.id,e.name):r?A(e.id,e.name):e.webViewLink&&window.open(e.webViewLink,`_blank`)},style:{cursor:t||n||r||e.webViewLink?`pointer`:`default`},children:[(0,j.jsx)(`span`,{className:J.fileIcon,children:Zt(e.type,e.mimeType)}),(0,j.jsxs)(`div`,{className:J.fileInfo,children:[(0,j.jsx)(`div`,{className:J.fileName,children:e.name}),(0,j.jsxs)(`div`,{className:J.fileMeta,children:[e.modifiedTime?new Date(e.modifiedTime).toLocaleDateString():``,e.size?` · ${e.size}`:``,e.shared?` · Shared`:``,e.starred?` ★`:``]})]}),(0,j.jsxs)(`div`,{className:J.fileBtns,children:[t&&(0,j.jsx)(`button`,{className:J.editBtn,onClick:t=>{t.stopPropagation(),D(e.id,e.name)},children:`Edit`}),n&&(0,j.jsx)(`button`,{className:J.viewBtn,onClick:t=>{t.stopPropagation(),ne(e.id,e.name)},children:`View`}),r&&(0,j.jsx)(`button`,{className:J.pdfBtn,onClick:t=>{t.stopPropagation(),A(e.id,e.name)},children:`PDF`}),e.webViewLink&&(0,j.jsx)(`a`,{className:J.openBtn,href:e.webViewLink,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),children:`Open ↗`}),(0,j.jsx)(`button`,{className:J.delBtn,onClick:t=>{t.stopPropagation(),re(e.id,e.name)},children:`Del`})]})]},e.id)})})]})}var Y={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 en(){let e=P(),[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),O(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=()=>k(`/api/github/mark-read`,{}).then(()=>d(a)),h=()=>{confirm(`Remove GitHub connection? You can reconnect anytime.`)&&k(`/api/config`,{key:`github-token`,value:``}).then(()=>{n(null),i(!1)})};if(r)return(0,j.jsx)(`div`,{className:Y.loading,children:(0,j.jsx)(`div`,{className:`spinner`})});if(t?.error)return(0,j.jsxs)(`div`,{className:Y.errorBox,children:[(0,j.jsx)(`div`,{children:t.error}),(0,j.jsxs)(`div`,{className:Y.errorHint,children:[`Run: `,(0,j.jsx)(`code`,{children:`nha config set github-token YOUR_PAT`})]})]});let g=t?.user,v=Array.isArray(t?.notifications)?t.notifications:[],y=Array.isArray(t?.issues)?t.issues:[],b=Array.isArray(t?.prs)?t.prs:[];return(0,j.jsxs)(`div`,{className:Y.root,children:[g?.login&&(0,j.jsxs)(`div`,{className:Y.userRow,children:[g.avatar&&(0,j.jsx)(`img`,{src:g.avatar,className:Y.avatar,alt:g.login}),(0,j.jsxs)(`div`,{style:{flex:1},children:[(0,j.jsxs)(`div`,{className:Y.userLogin,children:[`@`,g.login]}),g.name&&(0,j.jsx)(`div`,{className:Y.userName,children:g.name})]}),(0,j.jsx)(`button`,{className:Y.disconnectBtn,onClick:h,children:`Disconnect`})]}),(0,j.jsxs)(`div`,{className:Y.repoBar,children:[(0,j.jsx)(`input`,{className:Y.repoInput,value:s,onChange:e=>c(e.target.value),placeholder:`owner/repo`,onKeyDown:e=>e.key===`Enter`&&f()}),(0,j.jsx)(`button`,{className:Y.issuesBtn,onClick:f,children:`Issues`}),(0,j.jsx)(`button`,{className:Y.prsBtn,onClick:p,children:`PRs`})]}),g?.repos&&g.repos.length>0&&(0,j.jsx)(`div`,{className:Y.repoPills,children:g.repos.slice(0,12).map(e=>(0,j.jsxs)(`button`,{className:Y.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,j.jsx)(`span`,{className:Y.issueCount,children:e.open_issues}):null]},e.full_name))}),(0,j.jsxs)(`div`,{className:Y.tabs,children:[(0,j.jsxs)(`button`,{className:`${Y.tab} ${l===`notifs`?Y.tabActive:``}`,onClick:()=>u(`notifs`),children:[`Notifications `,v.length>0?`(${v.length})`:``]}),y.length>0&&(0,j.jsxs)(`button`,{className:`${Y.tab} ${l===`issues`?Y.tabActive:``}`,onClick:()=>u(`issues`),children:[`Issues (`,y.length,`)`]}),b.length>0&&(0,j.jsxs)(`button`,{className:`${Y.tab} ${l===`prs`?Y.tabActive:``}`,onClick:()=>u(`prs`),children:[`PRs (`,b.length,`)`]}),l===`notifs`&&v.length>0&&(0,j.jsx)(`button`,{className:Y.markRead,onClick:m,children:`Mark all read`})]}),(0,j.jsxs)(`div`,{className:Y.content,children:[l===`notifs`&&(v.length===0?(0,j.jsx)(`div`,{className:Y.empty,children:`No notifications`}):v.map((e,t)=>(0,j.jsxs)(`a`,{className:Y.notifRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,j.jsx)(`span`,{className:Y.notifRepo,children:e.repo}),(0,j.jsxs)(`span`,{className:Y.notifType,children:[`[`,e.type,`]`]}),(0,j.jsx)(`div`,{className:Y.notifTitle,children:e.title}),(0,j.jsxs)(`div`,{className:Y.notifMeta,children:[e.reason,` · `,e.updated]})]},t))),l===`issues`&&(y.length===0?(0,j.jsxs)(`div`,{className:Y.empty,children:[e(`github.noIssues`),` for `,a]}):y.map((e,t)=>(0,j.jsxs)(`a`,{className:Y.issueRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,j.jsxs)(`span`,{className:Y.issueNum,children:[`#`,e.number]}),(0,j.jsx)(`span`,{className:Y.issueTitle,children:e.title}),e.assignee&&(0,j.jsxs)(`span`,{className:Y.issueMeta,children:[`→ `,e.assignee]}),e.labels&&(0,j.jsxs)(`span`,{className:Y.issueLabel,children:[`[`,e.labels,`]`]}),(0,j.jsx)(`div`,{className:Y.issueMeta,children:e.updated})]},t))),l===`prs`&&(b.length===0?(0,j.jsxs)(`div`,{className:Y.empty,children:[`No PRs for `,a]}):b.map((e,t)=>(0,j.jsxs)(`a`,{className:Y.prRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,j.jsxs)(`span`,{className:Y.prNum,children:[`#`,e.number]}),(0,j.jsx)(`span`,{className:Y.prTitle,children:e.title}),(0,j.jsxs)(`span`,{className:Y.prAuthor,children:[`by `,e.author]}),e.draft&&(0,j.jsx)(`span`,{className:Y.prDraft,children:`DRAFT`}),(0,j.jsx)(`div`,{className:Y.prMeta,children:e.updated})]},t)))]})]})}var tn={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 nn(){let e=P(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)([]),l=()=>{i(!0),O(`/api/slack/channels`).then(e=>{n(e??{}),i(!1)}).catch(()=>i(!1))},u=e=>{o(e),O(`/api/slack/messages?channel=${e.id}`).then(e=>c(e?.messages??[]))};if((0,_.useEffect)(()=>{l()},[]),r)return(0,j.jsxs)(`div`,{className:tn.loading,children:[(0,j.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]});if(t?.error)return(0,j.jsxs)(`div`,{className:tn.errorBox,children:[(0,j.jsx)(`div`,{children:t.error}),(0,j.jsxs)(`div`,{className:tn.errorHint,children:[`Run: `,(0,j.jsx)(`code`,{children:`nha config set slack-token xoxb-YOUR-TOKEN`})]})]});let d=t?.channels??[];return(0,j.jsxs)(`div`,{className:tn.twoPane,children:[(0,j.jsxs)(`div`,{className:tn.sidebar,children:[(0,j.jsxs)(`div`,{className:tn.sidebarTitle,children:[(0,j.jsx)(`span`,{children:`💬 Slack`}),t?.workspace&&(0,j.jsx)(`span`,{className:tn.workspace,children:t.workspace})]}),d.length===0&&(0,j.jsx)(`div`,{className:tn.empty,children:`No channels`}),d.map(e=>(0,j.jsxs)(`div`,{className:`${tn.channelItem} ${a?.id===e.id?tn.channelActive:``}`,onClick:()=>u(e),children:[`# `,e.name]},e.id)),(0,j.jsx)(`button`,{className:tn.disconnectBtn,onClick:()=>k(`/api/config`,{key:`slack-token`,value:``}).then(l),children:`Disconnect`})]}),(0,j.jsx)(`div`,{className:tn.messagePane,children:a?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{className:tn.channelHeader,children:[`#`,a.name]}),s.length===0&&(0,j.jsx)(`div`,{className:tn.empty,children:`No messages`}),s.map((e,t)=>(0,j.jsxs)(`div`,{className:tn.message,children:[(0,j.jsx)(`span`,{className:tn.msgUser,children:e.username||e.user||`Unknown`}),(0,j.jsx)(`span`,{className:tn.msgText,children:e.text}),(0,j.jsx)(`span`,{className:tn.msgTs,children:new Date(parseFloat(e.ts)*1e3).toLocaleTimeString()})]},t))]}):(0,j.jsx)(`div`,{className:tn.emptyPane,children:`Select a channel`})})]})}function rn(){let e=P(),[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),O(e?`/api/notion/search?q=${encodeURIComponent(e)}`:`/api/notion`).then(e=>{n(e??{}),i(!1)}).catch(()=>i(!1))},f=e=>{o(e),O(`/api/notion/page?id=${encodeURIComponent(e.id)}`).then(e=>c(e?.content??``))};(0,_.useEffect)(()=>{d()},[]);let p=()=>d(l);if(r)return(0,j.jsxs)(`div`,{className:tn.loading,children:[(0,j.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]});if(t?.error)return(0,j.jsxs)(`div`,{className:tn.errorBox,children:[(0,j.jsx)(`div`,{children:t.error}),(0,j.jsxs)(`div`,{className:tn.errorHint,children:[`Run: `,(0,j.jsx)(`code`,{children:`nha config set notion-token secret_YOUR_TOKEN`})]})]});let m=t?.pages??[];return(0,j.jsxs)(`div`,{className:tn.twoPane,children:[(0,j.jsxs)(`div`,{className:tn.sidebar,children:[(0,j.jsx)(`div`,{className:tn.sidebarTitle,children:`📋 Notion`}),(0,j.jsxs)(`div`,{className:tn.searchRow,children:[(0,j.jsx)(`input`,{className:tn.searchInput,value:l,onChange:e=>u(e.target.value),placeholder:`Search pages…`,onKeyDown:e=>e.key===`Enter`&&p()}),(0,j.jsx)(`button`,{className:tn.searchBtn,onClick:p,children:`Go`})]}),m.length===0&&(0,j.jsx)(`div`,{className:tn.empty,children:`No pages found`}),m.map(e=>(0,j.jsxs)(`div`,{className:`${tn.channelItem} ${a?.id===e.id?tn.channelActive:``}`,onClick:()=>f(e),children:[(0,j.jsx)(`div`,{className:tn.pageTitle,children:e.title||`Untitled`}),e.last_edited&&(0,j.jsx)(`div`,{className:tn.pageMeta,children:e.last_edited.slice(0,10)})]},e.id)),(0,j.jsx)(`button`,{className:tn.disconnectBtn,onClick:()=>k(`/api/config`,{key:`notion-token`,value:``}).then(()=>d()),children:`Disconnect`})]}),(0,j.jsx)(`div`,{className:tn.messagePane,children:a?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:tn.channelHeader,children:a.title}),a.url&&(0,j.jsx)(`a`,{className:tn.openLink,href:a.url,target:`_blank`,rel:`noreferrer`,children:`Open in Notion ↗`}),(0,j.jsx)(`div`,{className:tn.pageBody,dangerouslySetInnerHTML:{__html:ye(s||`Loading…`)}})]}):(0,j.jsx)(`div`,{className:tn.emptyPane,children:`Select a page`})})]})}var X={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 an(e){return e.content||e.plaintext||e.message||``}function on(e){return e.senderName||e.senderFingerprint?.slice(0,8)||e.sender||`unknown`}function sn(){let e=P(),[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)(()=>{O(`/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=>{O(`/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 k(`/api/collab/create`,{name:e}).catch(()=>null);if(!t||t.error){alert(t?.error||`Error creating channel`);return}let r=t.id;await k(`/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 k(`/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 k(`/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.`)&&(k(`/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 k(`/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,j.jsxs)(`div`,{className:X.root,children:[(0,j.jsxs)(`div`,{className:X.sidebar,children:[(0,j.jsx)(`div`,{className:X.sidebarHeader,children:(0,j.jsx)(`div`,{className:X.sidebarTitle,children:`Alexandria`})}),(0,j.jsxs)(`div`,{className:X.sidebarBtns,children:[(0,j.jsx)(`button`,{className:X.createBtn,onClick:g,children:`+ Create`}),(0,j.jsx)(`button`,{className:X.joinBtn,onClick:v,children:`Join`})]}),t.length===0?(0,j.jsxs)(`div`,{className:X.noChannels,children:[e(`collab.noChannels`),` yet`]}):t.map(e=>(0,j.jsxs)(`div`,{className:`${X.channelItem} ${r===e.id?X.channelActive:``}`,onClick:()=>i(e.id),children:[(0,j.jsx)(`div`,{className:X.channelName,children:e.name}),(0,j.jsxs)(`div`,{className:X.channelMeta,children:[(0,j.jsxs)(`span`,{className:X.channelCode,onClick:t=>{t.stopPropagation(),x(e.id)},title:`Click to copy invite code`,children:[e.id.slice(0,8),`…`]}),(0,j.jsx)(`button`,{className:X.channelDel,onClick:t=>{t.stopPropagation(),y(e.id)},children:`del`})]})]},e.id))]}),(0,j.jsx)(`div`,{className:X.main,children:r?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{className:X.chatHeader,children:[(0,j.jsx)(`div`,{className:X.chatChannelName,children:t.find(e=>e.id===r)?.name??r.slice(0,12)}),(0,j.jsx)(`div`,{className:X.chatChannelId,children:r}),(0,j.jsx)(`div`,{className:`${X.statusDot} ${l?X.connected:X.disconnected}`}),(0,j.jsx)(`span`,{className:X.statusText,children:l?`Live`:`HTTP`})]}),(0,j.jsxs)(`div`,{className:X.messages,ref:p,children:[a.length===0&&(0,j.jsx)(`div`,{className:X.emptyMsgs,children:`No messages yet`}),a.map((e,t)=>{let n=on(e),r=an(e),i=n===d;return(0,j.jsxs)(`div`,{className:`${X.msg} ${i?X.msgSelf:X.msgOther}`,children:[!i&&(0,j.jsx)(`div`,{className:X.msgSender,children:n}),(0,j.jsx)(`div`,{className:X.msgContent,children:r}),(0,j.jsx)(`div`,{className:X.msgTime,children:new Date(e.timestamp).toLocaleTimeString()})]},e.id||t)})]}),(0,j.jsxs)(`div`,{className:X.inputRow,children:[(0,j.jsx)(`input`,{className:X.textInput,value:s,onChange:e=>c(e.target.value),placeholder:`Send an encrypted message…`,onKeyDown:e=>e.key===`Enter`&&!e.shiftKey&&b()}),(0,j.jsx)(`button`,{className:X.sendBtn,onClick:b,disabled:!s.trim(),children:e(`collab.send`)})]})]}):(0,j.jsxs)(`div`,{className:X.welcome,children:[(0,j.jsx)(`div`,{className:X.welcomeIcon,children:`🔐`}),(0,j.jsx)(`div`,{className:X.welcomeTitle,children:`Alexandria`}),(0,j.jsx)(`div`,{className:X.welcomeSub,children:`E2E encrypted messaging for AI agents and teams`}),(0,j.jsxs)(`div`,{className:X.welcomeBox,children:[(0,j.jsx)(`div`,{className:X.welcomeBoxTitle,children:`HOW TO USE`}),(0,j.jsxs)(`div`,{className:X.welcomeStep,children:[(0,j.jsx)(`strong`,{children:`1. Create a channel`}),` — Click [+ Create] in the sidebar. Give it a name.`]}),(0,j.jsx)(`div`,{className:X.welcomeHint,children:`You get an invite code. Share it with your team or another AI session.`}),(0,j.jsxs)(`div`,{className:X.welcomeStep,children:[(0,j.jsx)(`strong`,{children:`2. Others join`}),` — They click [Join] and paste the invite code.`]}),(0,j.jsx)(`div`,{className:X.welcomeHint,children:`Works from this web UI, the Android app, or the CLI.`}),(0,j.jsxs)(`div`,{className:X.welcomeStep,children:[(0,j.jsx)(`strong`,{children:`3. Chat encrypted`}),` — All messages are E2E encrypted. The server sees only ciphertext.`]})]}),(0,j.jsxs)(`div`,{className:X.welcomeBox,children:[(0,j.jsx)(`div`,{className:X.welcomeBoxTitle,children:`FROM CLI (same channels)`}),(0,j.jsx)(`div`,{className:X.cliCmd,children:`nha collab create "Project X"`}),(0,j.jsx)(`div`,{className:X.cliCmd,children:`nha collab join <invite-code>`}),(0,j.jsx)(`div`,{className:X.cliCmd,children:`nha collab send "Hello from CLI"`}),(0,j.jsx)(`div`,{className:X.cliCmd,children:`nha collab read`})]})]})})]})}var Z={root:`_root_11bte_2`,header:`_header_11bte_10`,title:`_title_11bte_21`,subtitle:`_subtitle_11bte_28`,headerTabs:`_headerTabs_11bte_34`,tabBtn:`_tabBtn_11bte_40`,tabActive:`_tabActive_11bte_51`,body:`_body_11bte_58`,editor:`_editor_11bte_67`,examples:`_examples_11bte_75`,sectionLabel:`_sectionLabel_11bte_81`,examplePills:`_examplePills_11bte_89`,examplePill:`_examplePill_11bte_89`,editorCols:`_editorCols_11bte_109`,leftSidebar:`_leftSidebar_11bte_119`,panel:`_panel_11bte_128`,panelHeader:`_panelHeader_11bte_135`,panelTitle:`_panelTitle_11bte_142`,addBtn:`_addBtn_11bte_149`,blockLabel:`_blockLabel_11bte_160`,blockCheck:`_blockCheck_11bte_170`,authField:`_authField_11bte_173`,authFieldInput:`_authFieldInput_11bte_183`,authFieldSelect:`_authFieldSelect_11bte_193`,authFieldReq:`_authFieldReq_11bte_204`,removeFieldBtn:`_removeFieldBtn_11bte_205`,skillsList:`_skillsList_11bte_208`,skillRow:`_skillRow_11bte_210`,skillIcon:`_skillIcon_11bte_218`,skillName:`_skillName_11bte_220`,skillBadge:`_skillBadge_11bte_229`,skillBadge_skill:`_skillBadge_skill_11bte_237`,skillBadge_memory:`_skillBadge_memory_11bte_238`,skillBadge_provider:`_skillBadge_provider_11bte_239`,skillBadge_log:`_skillBadge_log_11bte_240`,skillEmpty:`_skillEmpty_11bte_242`,skillBtn:`_skillBtn_11bte_244`,skillsEmpty:`_skillsEmpty_11bte_246`,snapshotRow:`_snapshotRow_11bte_249`,snapshotTs:`_snapshotTs_11bte_258`,snapshotCount:`_snapshotCount_11bte_259`,snapshotBtn:`_snapshotBtn_11bte_260`,genStatus:`_genStatus_11bte_263`,repairStatus:`_repairStatus_11bte_265`,repairStatusTitle:`_repairStatusTitle_11bte_266`,repairStatusProg:`_repairStatusProg_11bte_267`,repairStatusFile:`_repairStatusFile_11bte_268`,actionRow:`_actionRow_11bte_271`,actionBtn:`_actionBtn_11bte_273`,actionBtnIcon:`_actionBtnIcon_11bte_275`,actionBtnActive:`_actionBtnActive_11bte_276`,repairBtn:`_repairBtn_11bte_278`,sandboxBtn:`_sandboxBtn_11bte_280`,statsBar:`_statsBar_11bte_282`,rightPanel:`_rightPanel_11bte_285`,rightTabBar:`_rightTabBar_11bte_296`,rightTab:`_rightTab_11bte_296`,rightTabActive:`_rightTabActive_11bte_313`,repairBar:`_repairBar_11bte_316`,repairBarRow:`_repairBarRow_11bte_326`,repairBarIcon:`_repairBarIcon_11bte_327`,repairBarLabel:`_repairBarLabel_11bte_328`,repairBarFile:`_repairBarFile_11bte_329`,repairBarCounter:`_repairBarCounter_11bte_330`,repairBarTime:`_repairBarTime_11bte_331`,genBar:`_genBar_11bte_333`,genBarRow:`_genBarRow_11bte_343`,genBarRobot:`_genBarRobot_11bte_344`,robotBob:`_robotBob_11bte_1`,genBarLabel:`_genBarLabel_11bte_345`,genBarFile:`_genBarFile_11bte_346`,genBarCounter:`_genBarCounter_11bte_347`,genBarTime:`_genBarTime_11bte_348`,progressTrack:`_progressTrack_11bte_350`,repairProgress:`_repairProgress_11bte_351`,genProgress:`_genProgress_11bte_352`,genDots:`_genDots_11bte_355`,dot:`_dot_11bte_356`,dot1:`_dot1_11bte_357`,dotBounce:`_dotBounce_11bte_1`,dot2:`_dot2_11bte_358`,dot3:`_dot3_11bte_359`,stopBtn:`_stopBtn_11bte_362`,codeArea:`_codeArea_11bte_365`,sandboxWrap:`_sandboxWrap_11bte_366`,sandboxFrame:`_sandboxFrame_11bte_367`,sandboxEmpty:`_sandboxEmpty_11bte_368`,sandboxStartBtn:`_sandboxStartBtn_11bte_369`,sandboxConsole:`_sandboxConsole_11bte_372`,sandboxConsoleHeader:`_sandboxConsoleHeader_11bte_380`,sandboxConsoleTitle:`_sandboxConsoleTitle_11bte_389`,sandboxConsolePort:`_sandboxConsolePort_11bte_390`,sandboxConsoleDots:`_sandboxConsoleDots_11bte_391`,sandboxConsoleBody:`_sandboxConsoleBody_11bte_392`,sandboxLogLine:`_sandboxLogLine_11bte_398`,sandboxLogPhase:`_sandboxLogPhase_11bte_407`,sandboxLogError:`_sandboxLogError_11bte_408`,sandboxLogWarn:`_sandboxLogWarn_11bte_409`,sandboxLogOk:`_sandboxLogOk_11bte_410`,codeLayout:`_codeLayout_11bte_413`,codeRow:`_codeRow_11bte_422`,ideTabBar:`_ideTabBar_11bte_430`,ideTab:`_ideTab_11bte_430`,ideTabActive:`_ideTabActive_11bte_462`,ideTabError:`_ideTabError_11bte_467`,ideTabPending:`_ideTabPending_11bte_468`,ideTabIcon:`_ideTabIcon_11bte_469`,ideTabName:`_ideTabName_11bte_470`,ideTabDot:`_ideTabDot_11bte_471`,codeEditorWrap:`_codeEditorWrap_11bte_479`,editToggleBtn:`_editToggleBtn_11bte_490`,editToggleBtnActive:`_editToggleBtnActive_11bte_501`,codeEditor:`_codeEditor_11bte_479`,genCursor:`_genCursor_11bte_523`,cursorBlink:`_cursorBlink_11bte_1`,diffOverlay:`_diffOverlay_11bte_532`,diffOverlayHeader:`_diffOverlayHeader_11bte_541`,diffOverlayActions:`_diffOverlayActions_11bte_552`,diffAcceptBtn:`_diffAcceptBtn_11bte_553`,diffRejectBtn:`_diffRejectBtn_11bte_554`,diffOverlayBody:`_diffOverlayBody_11bte_555`,diffSame:`_diffSame_11bte_556`,diffRem:`_diffRem_11bte_557`,diffAdd:`_diffAdd_11bte_558`,noFiles:`_noFiles_11bte_560`,noFilesHero:`_noFilesHero_11bte_570`,noFilesIcon:`_noFilesIcon_11bte_577`,noFilesTitle:`_noFilesTitle_11bte_579`,noFilesTagline:`_noFilesTagline_11bte_586`,noFilesSteps:`_noFilesSteps_11bte_591`,noFilesStep:`_noFilesStep_11bte_591`,noFilesStepNum:`_noFilesStepNum_11bte_608`,noFilesExamplesHint:`_noFilesExamplesHint_11bte_622`,noFilesExampleBtn:`_noFilesExampleBtn_11bte_632`,codeViewer:`_codeViewer_11bte_644`,codeHeader:`_codeHeader_11bte_652`,codeFileIcon:`_codeFileIcon_11bte_665`,codeFileName:`_codeFileName_11bte_666`,codeFileMeta:`_codeFileMeta_11bte_667`,fileError:`_fileError_11bte_669`,fileSyntaxError:`_fileSyntaxError_11bte_670`,filePending:`_filePending_11bte_671`,code:`_code_11bte_365`,codeError:`_codeError_11bte_686`,codeSyntaxError:`_codeSyntaxError_11bte_687`,fileSidebar:`_fileSidebar_11bte_690`,fileSidebarHeader:`_fileSidebarHeader_11bte_699`,fileTab:`_fileTab_11bte_709`,fileTabActive:`_fileTabActive_11bte_725`,fileTabError:`_fileTabError_11bte_726`,fileTabRow:`_fileTabRow_11bte_728`,fileTabIcon:`_fileTabIcon_11bte_729`,fileTabName:`_fileTabName_11bte_730`,fileTabSize:`_fileTabSize_11bte_731`,fileTabDir:`_fileTabDir_11bte_732`,fileTabTokens:`_fileTabTokens_11bte_733`,fileTabMeta:`_fileTabMeta_11bte_734`,projectsList:`_projectsList_11bte_737`,emptyProjects:`_emptyProjects_11bte_739`,emptyIcon:`_emptyIcon_11bte_740`,emptyHint:`_emptyHint_11bte_741`,projectCard:`_projectCard_11bte_743`,projectInfo:`_projectInfo_11bte_744`,projectName:`_projectName_11bte_745`,projectDesc:`_projectDesc_11bte_746`,projectMeta:`_projectMeta_11bte_747`,openBtn:`_openBtn_11bte_748`,deleteBtn:`_deleteBtn_11bte_749`,planBanner:`_planBanner_11bte_752`,planTitle:`_planTitle_11bte_761`,planText:`_planText_11bte_762`,planActions:`_planActions_11bte_763`,planApprove:`_planApprove_11bte_764`,planReject:`_planReject_11bte_765`,grepPanel:`_grepPanel_11bte_768`,grepRow:`_grepRow_11bte_777`,grepInput:`_grepInput_11bte_778`,grepBtn:`_grepBtn_11bte_780`,grepClose:`_grepClose_11bte_781`,grepCount:`_grepCount_11bte_782`,grepResults:`_grepResults_11bte_783`,grepEmpty:`_grepEmpty_11bte_784`,grepMatch:`_grepMatch_11bte_785`,grepMatchFile:`_grepMatchFile_11bte_787`,grepMatchLine:`_grepMatchLine_11bte_788`,diffPanel:`_diffPanel_11bte_791`,diffHeader:`_diffHeader_11bte_800`,diffClose:`_diffClose_11bte_801`,diffFile:`_diffFile_11bte_802`,diffSummary:`_diffSummary_11bte_803`,diffArrow:`_diffArrow_11bte_804`,diffFileName:`_diffFileName_11bte_805`,diffAdded:`_diffAdded_11bte_806`,diffRemoved:`_diffRemoved_11bte_807`,diffContent:`_diffContent_11bte_808`,diffInline:`_diffInline_11bte_811`,diffInlineHeader:`_diffInlineHeader_11bte_812`,diffRemLine:`_diffRemLine_11bte_813`,diffAddLine:`_diffAddLine_11bte_814`,chatPanel:`_chatPanel_11bte_817`,chatMessages:`_chatMessages_11bte_826`,chatWelcome:`_chatWelcome_11bte_828`,chatUser:`_chatUser_11bte_830`,chatUserBubble:`_chatUserBubble_11bte_831`,chatAttachPreviews:`_chatAttachPreviews_11bte_832`,chatAttachBadge:`_chatAttachBadge_11bte_833`,chatSystem:`_chatSystem_11bte_835`,chatSystemBubble:`_chatSystemBubble_11bte_836`,chatSyntaxErr:`_chatSyntaxErr_11bte_837`,chatAgent:`_chatAgent_11bte_839`,chatAgentCard:`_chatAgentCard_11bte_840`,chatAgentHeader:`_chatAgentHeader_11bte_841`,chatAgentRobot:`_chatAgentRobot_11bte_842`,chatAgentRobotAnim:`_chatAgentRobotAnim_11bte_843`,chatAgentLabel:`_chatAgentLabel_11bte_844`,chatRunningDots:`_chatRunningDots_11bte_845`,chatAgentText:`_chatAgentText_11bte_846`,chatToolBadges:`_chatToolBadges_11bte_847`,toolBadge:`_toolBadge_11bte_848`,toolBadgeOk:`_toolBadgeOk_11bte_849`,toolBadgeErr:`_toolBadgeErr_11bte_850`,cursor:`_cursor_11bte_852`,blink:`_blink_11bte_1`,attachPreviews:`_attachPreviews_11bte_855`,attachBadge:`_attachBadge_11bte_856`,removeAttachBtn:`_removeAttachBtn_11bte_857`,projNameRow:`_projNameRow_11bte_860`,projNameLabel:`_projNameLabel_11bte_861`,projNameInput:`_projNameInput_11bte_862`,projActiveRow:`_projActiveRow_11bte_863`,projActiveName:`_projActiveName_11bte_864`,chatInputRow:`_chatInputRow_11bte_867`,attachLabel:`_attachLabel_11bte_868`,chatTextarea:`_chatTextarea_11bte_869`,chatSendCol:`_chatSendCol_11bte_872`,chatSendBtn:`_chatSendBtn_11bte_873`,chatStopBtn:`_chatStopBtn_11bte_875`,modalOverlay:`_modalOverlay_11bte_878`,modal:`_modal_11bte_878`,modalHeader:`_modalHeader_11bte_900`,modalTitle:`_modalTitle_11bte_901`,modalClose:`_modalClose_11bte_902`,modalBody:`_modalBody_11bte_904`,modalRow:`_modalRow_11bte_906`,modalField:`_modalField_11bte_907`,modalLabel:`_modalLabel_11bte_908`,modalLabelRow:`_modalLabelRow_11bte_909`,modalSelect:`_modalSelect_11bte_911`,modalInput:`_modalInput_11bte_912`,modalHint:`_modalHint_11bte_915`,modalAiBox:`_modalAiBox_11bte_917`,modalAiRow:`_modalAiRow_11bte_918`,modalAiDesc:`_modalAiDesc_11bte_919`,modalAiBtn:`_modalAiBtn_11bte_920`,modalContentArea:`_modalContentArea_11bte_923`,logView:`_logView_11bte_926`,modalFooter:`_modalFooter_11bte_928`,modalCancelBtn:`_modalCancelBtn_11bte_929`,modalSaveBtn:`_modalSaveBtn_11bte_930`},cn=[{name:`MySaaS`,desc:`Full-stack SaaS web application with Node.js/Express backend and vanilla JS frontend.
591
+ 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)}},pe=e=>{let t=window.SpeechRecognition??window.webkitSpeechRecognition;if(!t){alert(`Speech recognition not supported.`);return}let n=D.current.get(e);if(l.find(t=>t.agent.id===e)?.voiceActive&&n){n.stop(),F(e,{voiceActive:!1});return}let r=new t;D.current.set(e,r),r.lang=`it-IT`,r.continuous=!1,r.interimResults=!1,r.onresult=t=>{let n=t.results[0][0].transcript;F(e,{input:(l.find(t=>t.agent.id===e)?.input??``)+(l.find(t=>t.agent.id===e)?.input?` `:``)+n})},r.onend=()=>F(e,{voiceActive:!1}),r.onerror=()=>F(e,{voiceActive:!1}),r.start(),F(e,{voiceActive:!0})},me=(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];F(e,{attachedFile:{name:t.name,size:t.size,base64:r,mimeType:`application/pdf`,isPDF:!0},attachedImage:null})},r.readAsDataURL(t)):(r.onload=n=>{F(e,{attachedFile:{name:t.name,size:t.size,content:n.target?.result},attachedImage:null})},r.readAsText(t))},he=(e,t)=>{if(!t)return;let n=new FileReader;n.onload=n=>{let r=(n.target?.result).split(`,`)[1];F(e,{attachedImage:{name:t.name,size:t.size,base64:r,mimeType:t.type||`image/jpeg`},attachedFile:null})},n.readAsDataURL(t)},ge=()=>{x({name:``,tagline:``,systemPrompt:``}),C(`create`),T(``)},_e=async e=>{let t=await O(`/api/agents/${e.id}`).catch(()=>null);x({name:e.id,tagline:t?.tagline??e.description,systemPrompt:t?.systemPrompt??``}),C(`edit`),T(``)},ve=async()=>{if(b){if(!b.tagline.trim()||!b.systemPrompt.trim()){T(`Tagline and system prompt are required.`);return}ee(!0),T(``);try{if(S===`create`){let e=b.name.toLowerCase().replace(/[^a-z0-9_-]/g,``);if(!e){T(`Agent name required (lowercase, no spaces).`),ee(!1);return}let t=await k(`/api/agents`,{name:e,tagline:b.tagline,systemPrompt:b.systemPrompt});if(t?.error){T(`Error: `+t.error),ee(!1);return}}else await k(`/api/agents/${b.name}`,{tagline:b.tagline,systemPrompt:b.systemPrompt,category:`custom`},`PUT`);x(null),ie()}catch(e){T(`Error: `+e.message)}finally{ee(!1)}}},I=e=>{confirm(`Delete agent "${e.label}"?`)&&k(`/api/agents/${e.id}`,{},`DELETE`).then(()=>ie())};return r?(0,j.jsx)(`div`,{className:q.root,children:(0,j.jsx)(`div`,{className:q.loading,children:(0,j.jsx)(`div`,{className:`spinner`})})}):(0,j.jsxs)(`div`,{className:q.root,children:[(0,j.jsxs)(`div`,{className:q.gridSection,children:[(0,j.jsxs)(`div`,{className:q.gridHeader,children:[(0,j.jsxs)(`div`,{className:q.headerRow,children:[(0,j.jsx)(`input`,{className:q.search,value:a,onChange:e=>o(e.target.value),placeholder:`Search agents…`}),(0,j.jsx)(`button`,{className:q.createBtn,onClick:ge,children:`+ Create`})]}),(0,j.jsx)(`div`,{className:q.catTabs,children:ae.map(e=>(0,j.jsxs)(`button`,{className:`${q.catTab} ${s===e?q.catActive:``}`,onClick:()=>c(e),children:[e,` (`,e===`All`?t.length:t.filter(t=>t.category===e).length,`)`]},e))})]}),(0,j.jsx)(`div`,{className:q.grid,children:oe.map(e=>{let t=l.some(t=>t.agent.id===e.id);return(0,j.jsxs)(`div`,{className:`${q.agentCard} ${t?q.agentActive:``}`,onClick:()=>se(e),children:[(0,j.jsxs)(`div`,{className:q.agentCardTop,children:[(0,j.jsx)(`div`,{className:q.agentIcon,children:e.icon}),e.isCustom&&(0,j.jsxs)(`div`,{className:q.agentActions,children:[(0,j.jsx)(`button`,{className:q.agentEditBtn,onClick:t=>{t.stopPropagation(),_e(e)},children:`✏️`}),(0,j.jsx)(`button`,{className:q.agentDelBtn,onClick:t=>{t.stopPropagation(),I(e)},children:`🗑`})]})]}),(0,j.jsx)(`div`,{className:q.agentLabel,children:e.label}),(0,j.jsx)(`div`,{className:q.agentDesc,children:e.description}),(0,j.jsx)(`div`,{className:q.agentCat,children:e.category})]},e.id)})})]}),(0,j.jsx)(`div`,{className:q.chatArea,children:l.length===0?(0,j.jsxs)(`div`,{className:q.emptyChat,children:[(0,j.jsx)(`span`,{children:`Click an agent above to open a chat`}),(0,j.jsx)(`span`,{className:q.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,j.jsxs)(`div`,{className:q.chatPanel,children:[(0,j.jsxs)(`div`,{className:q.chatHeader,children:[(0,j.jsx)(`span`,{className:q.chatIcon,children:t.icon}),(0,j.jsxs)(`div`,{className:q.chatHeaderInfo,children:[(0,j.jsx)(`div`,{className:q.chatAgentName,children:t.label}),(0,j.jsx)(`div`,{className:q.chatAgentDesc,children:t.description})]}),(0,j.jsx)(`button`,{className:q.closeChat,onClick:()=>ce(t.id),children:`✕`})]}),(0,j.jsxs)(`div`,{className:q.chatMessages,ref:e=>{A.current.set(t.id,e)},children:[e.history.length===0&&(0,j.jsxs)(`div`,{className:q.chatEmpty,children:[`Ask `,t.label,` anything…`]}),e.history.map((e,t)=>(0,j.jsx)(`div`,{className:`${q.chatMsg} ${e.role===`user`?q.msgUser:q.msgAgent}`,children:e.role===`assistant`?(0,j.jsx)(`div`,{dangerouslySetInnerHTML:{__html:ye(e.content||`…`)}}):(0,j.jsx)(`span`,{children:e.content})},t)),e.streaming&&e.history[e.history.length-1]?.role===`assistant`&&e.history[e.history.length-1]?.content===``&&(0,j.jsxs)(`div`,{className:q.thinking,children:[(0,j.jsx)(`span`,{className:q.dot}),(0,j.jsx)(`span`,{className:q.dot}),(0,j.jsx)(`span`,{className:q.dot})]})]}),n&&(0,j.jsxs)(`div`,{className:q.attachBar,children:[(0,j.jsx)(`span`,{children:n}),(0,j.jsx)(`button`,{className:q.attachClear,onClick:()=>F(t.id,{attachedFile:null,attachedImage:null}),children:`×`})]}),(0,j.jsxs)(`div`,{className:q.chatInput,children:[(0,j.jsxs)(`div`,{className:q.chatTools,children:[(0,j.jsx)(`button`,{className:`${q.toolBtn} ${e.voiceActive?q.toolBtnActive:``}`,onClick:()=>pe(t.id),title:`Voice`,children:`🎤`}),(0,j.jsx)(`button`,{className:q.toolBtn,onClick:()=>re.current.get(t.id)?.click(),title:`Attach file`,children:`📎`}),(0,j.jsx)(`button`,{className:q.toolBtn,onClick:()=>M.current.get(t.id)?.click(),title:`Attach image`,children:`🖼`}),(0,j.jsx)(`input`,{type:`file`,style:{display:`none`},ref:e=>{re.current.set(t.id,e)},onChange:e=>me(t.id,e.target.files?.[0])}),(0,j.jsx)(`input`,{type:`file`,accept:`image/*`,style:{display:`none`},ref:e=>{M.current.set(t.id,e)},onChange:e=>he(t.id,e.target.files?.[0])})]}),(0,j.jsxs)(`div`,{className:q.chatInputRow,children:[(0,j.jsx)(`textarea`,{className:q.chatTextarea,value:e.input,onChange:e=>F(t.id,{input:e.target.value}),placeholder:`Message ${t.label}…`,rows:2,onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),de(e,e.input,e.attachedFile,e.attachedImage))}}),(0,j.jsx)(`button`,{className:q.sendBtn,onClick:()=>de(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,j.jsxs)(`div`,{className:q.orchBar,children:[(0,j.jsxs)(`div`,{className:q.orchLabel,children:[`🎼 Conductor · `,l.map(e=>`${e.agent.icon} ${e.agent.label}`).join(` · `)]}),(0,j.jsxs)(`div`,{className:q.orchRow,children:[(0,j.jsx)(`textarea`,{ref:N,className:q.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(),fe())}}),(0,j.jsx)(`button`,{className:q.orchBtn,onClick:fe,disabled:p||v||!d.trim(),children:p?`⏳`:v?`🔄`:`🎼 Run`})]}),(v||h)&&(0,j.jsxs)(`div`,{className:q.orchSynthesis,children:[(0,j.jsxs)(`div`,{className:q.orchSynthHeader,children:[(0,j.jsx)(`span`,{children:`🎼 Conductor Synthesis`}),v&&(0,j.jsx)(`span`,{className:q.orchSynthSpinner,children:`synthesizing…`})]}),(0,j.jsx)(`div`,{className:q.orchSynthBody,dangerouslySetInnerHTML:{__html:ye(h||`…`)}})]})]}),b&&(0,j.jsx)(`div`,{className:q.modalOverlay,onClick:e=>{e.target===e.currentTarget&&x(null)},children:(0,j.jsxs)(`div`,{className:q.modal,children:[(0,j.jsx)(`div`,{className:q.modalTitle,children:S===`create`?`+ New Agent`:`✏️ Edit Agent`}),S===`create`&&(0,j.jsxs)(`div`,{className:q.formField,children:[(0,j.jsx)(`label`,{className:q.formLabel,children:`Agent name (lowercase, no spaces)`}),(0,j.jsx)(`input`,{className:q.formInput,placeholder:`my-agent`,value:b.name,onChange:e=>x(t=>t&&{...t,name:e.target.value})})]}),(0,j.jsxs)(`div`,{className:q.formField,children:[(0,j.jsx)(`label`,{className:q.formLabel,children:`Tagline`}),(0,j.jsx)(`input`,{className:q.formInput,placeholder:`Short description`,value:b.tagline,onChange:e=>x(t=>t&&{...t,tagline:e.target.value})})]}),(0,j.jsxs)(`div`,{className:q.formField,children:[(0,j.jsx)(`label`,{className:q.formLabel,children:`System Prompt`}),(0,j.jsx)(`textarea`,{className:q.formTextarea,placeholder:`You are an expert in…`,value:b.systemPrompt,onChange:e=>x(t=>t&&{...t,systemPrompt:e.target.value})})]}),w&&(0,j.jsx)(`div`,{className:q.formError,children:w}),(0,j.jsxs)(`div`,{className:q.modalBtns,children:[(0,j.jsx)(`button`,{className:q.cancelBtn,onClick:()=>x(null),children:e(`common.cancel`)}),(0,j.jsx)(`button`,{className:q.modalSaveBtn,onClick:ve,disabled:E,children:E?`…`:S===`create`?`Create Agent`:`Save`})]})]})})]})}var J={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 Zt(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 $t(){let e=P(),[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),T=(e=s,t=l)=>{i(!0);let r=`/api/drive`;e&&(r+=`?filter=${e}`),t&&(r+=`${e?`&`:`?`}search=${encodeURIComponent(t)}`),O(r).then(e=>{n(e??{files:[]}),i(!1)}).catch(e=>{o(e.message??`Error`),i(!1)})};(0,_.useEffect)(()=>{T()},[]);let E=e=>{c(e),T(e,l)},ee=()=>{u(d),T(s,d)},D=(e,t)=>{i(!0),O(`/api/drive/read/${e}`).then(n=>{g({id:e,name:t,content:n?.content??``}),y(n?.content??``),m(`editor`),i(!1)}).catch(()=>i(!1))},te=async()=>{if(h&&confirm(`Save changes to "${h.name}" on Drive?`)){C(!0);try{await k(`/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)}}},ne=(e,t)=>{i(!0),O(`/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))},A=(e,t)=>{i(!0),O(`/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))},re=(e,t)=>{confirm(`Delete "${t}" from Drive? (moved to trash)`)&&k(`/api/drive/delete/${e}`,{}).then(()=>{n(null),T()})},M=()=>{let e=prompt(`File name (e.g. notes.txt, script.py):`);e&&k(`/api/drive/upload`,{name:e,content:``,mimeType:`text/plain`}).then(t=>{t?.id?D(t.id,e):T()}).catch(e=>alert(`Error: `+e.message))},N=()=>{w.current?.click()},ie=e=>{if(!e)return;let t=new FileReader;t.onload=t=>{let r=(t.target?.result).split(`,`)[1]??``;k(`/api/drive/upload`,{name:e.name,content:r,mimeType:e.type||`application/octet-stream`,encoding:`base64`}).then(()=>{n(null),T()}).catch(e=>alert(`Upload error: `+e.message))},t.readAsDataURL(e)};if(a)return(0,j.jsxs)(`div`,{className:J.error,children:[(0,j.jsx)(`div`,{children:a}),(0,j.jsxs)(`div`,{className:J.errorHint,children:[`Run: `,(0,j.jsx)(`code`,{children:`nha google revoke`}),` then `,(0,j.jsx)(`code`,{children:`nha google auth`})]})]});if(p===`editor`&&h)return(0,j.jsxs)(`div`,{className:J.editorRoot,children:[(0,j.jsxs)(`div`,{className:J.editorToolbar,children:[(0,j.jsx)(`button`,{className:J.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,j.jsx)(`span`,{className:J.editorName,children:h.name}),(0,j.jsx)(`button`,{className:J.saveBtn,onClick:te,disabled:S,children:S?`Saving…`:`Save to Drive`})]}),(0,j.jsx)(`textarea`,{className:J.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,j.jsxs)(`div`,{className:J.editorMeta,children:[`File ID: `,h.id,` · Tab = 2 spaces · Not auto-saved`]})]});if(p===`image`&&b)return(0,j.jsxs)(`div`,{className:J.viewerRoot,children:[(0,j.jsxs)(`div`,{className:J.editorToolbar,children:[(0,j.jsx)(`button`,{className:J.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,j.jsx)(`span`,{className:J.editorName,children:b.name})]}),(0,j.jsx)(`div`,{className:J.imgContainer,children:(0,j.jsx)(`img`,{src:b.src,alt:b.name,className:J.imgView})})]});if(p===`pdf`&&b)return(0,j.jsxs)(`div`,{className:J.viewerRoot,children:[(0,j.jsxs)(`div`,{className:J.editorToolbar,children:[(0,j.jsx)(`button`,{className:J.backBtn,onClick:()=>m(`list`),children:`← Back`}),(0,j.jsx)(`span`,{className:J.editorName,children:b.name})]}),(0,j.jsx)(`iframe`,{className:J.pdfFrame,src:b.src,title:b.name})]});let ae=t?.files??[],oe=t?.quota;return(0,j.jsxs)(`div`,{className:J.root,children:[oe&&(0,j.jsxs)(`div`,{className:J.quotaBar,children:[(0,j.jsxs)(`div`,{className:J.quotaText,children:[(0,j.jsxs)(`span`,{className:J.quotaUsed,children:[oe.usage,` of `,oe.limit,` used`]}),(0,j.jsxs)(`span`,{className:J.quotaPct,children:[oe.percentUsed,`%`]})]}),(0,j.jsx)(`div`,{className:J.quotaTrack,children:(0,j.jsx)(`div`,{className:J.quotaFill,style:{width:`${Math.min(oe.percentUsed,100)}%`,background:oe.percentUsed>90?`var(--red)`:oe.percentUsed>70?`var(--amber)`:`var(--green)`}})})]}),(0,j.jsxs)(`div`,{className:J.actionBar,children:[[``,`recent`,`starred`,`shared`].map(e=>(0,j.jsx)(`button`,{className:`${J.filterBtn} ${s===e?J.filterActive:``}`,onClick:()=>E(e),children:e?e.charAt(0).toUpperCase()+e.slice(1):`All Files`},e)),(0,j.jsx)(`div`,{className:J.spacer}),(0,j.jsx)(`button`,{className:J.newBtn,onClick:M,children:`+ New File`}),(0,j.jsx)(`button`,{className:J.uploadBtn,onClick:N,children:e(`drive.upload`)}),(0,j.jsx)(`input`,{ref:w,type:`file`,style:{display:`none`},onChange:e=>ie(e.target.files?.[0])})]}),(0,j.jsxs)(`div`,{className:J.searchRow,children:[(0,j.jsx)(`input`,{className:J.searchInput,value:d,onChange:e=>f(e.target.value),placeholder:`Search files…`,onKeyDown:e=>e.key===`Enter`&&ee()}),(0,j.jsx)(`button`,{className:J.searchBtn,onClick:ee,children:`Search`})]}),r&&(0,j.jsx)(`div`,{className:J.loading,children:(0,j.jsx)(`div`,{className:`spinner`})}),!r&&ae.length===0&&(0,j.jsxs)(`div`,{className:J.empty,children:[e(`drive.noFiles`),` found`]}),(0,j.jsx)(`div`,{className:J.fileList,children:ae.map(e=>{let t=Qt(e),n=e.type===`image`,r=e.type===`pdf`||e.mimeType.includes(`pdf`);return(0,j.jsxs)(`div`,{className:J.fileRow,onClick:()=>{t?D(e.id,e.name):n?ne(e.id,e.name):r?A(e.id,e.name):e.webViewLink&&window.open(e.webViewLink,`_blank`)},style:{cursor:t||n||r||e.webViewLink?`pointer`:`default`},children:[(0,j.jsx)(`span`,{className:J.fileIcon,children:Zt(e.type,e.mimeType)}),(0,j.jsxs)(`div`,{className:J.fileInfo,children:[(0,j.jsx)(`div`,{className:J.fileName,children:e.name}),(0,j.jsxs)(`div`,{className:J.fileMeta,children:[e.modifiedTime?new Date(e.modifiedTime).toLocaleDateString():``,e.size?` · ${e.size}`:``,e.shared?` · Shared`:``,e.starred?` ★`:``]})]}),(0,j.jsxs)(`div`,{className:J.fileBtns,children:[t&&(0,j.jsx)(`button`,{className:J.editBtn,onClick:t=>{t.stopPropagation(),D(e.id,e.name)},children:`Edit`}),n&&(0,j.jsx)(`button`,{className:J.viewBtn,onClick:t=>{t.stopPropagation(),ne(e.id,e.name)},children:`View`}),r&&(0,j.jsx)(`button`,{className:J.pdfBtn,onClick:t=>{t.stopPropagation(),A(e.id,e.name)},children:`PDF`}),e.webViewLink&&(0,j.jsx)(`a`,{className:J.openBtn,href:e.webViewLink,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),children:`Open ↗`}),(0,j.jsx)(`button`,{className:J.delBtn,onClick:t=>{t.stopPropagation(),re(e.id,e.name)},children:`Del`})]})]},e.id)})})]})}var Y={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 en(){let e=P(),[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),O(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=()=>k(`/api/github/mark-read`,{}).then(()=>d(a)),h=()=>{confirm(`Remove GitHub connection? You can reconnect anytime.`)&&k(`/api/config`,{key:`github-token`,value:``}).then(()=>{n(null),i(!1)})};if(r)return(0,j.jsx)(`div`,{className:Y.loading,children:(0,j.jsx)(`div`,{className:`spinner`})});if(t?.error)return(0,j.jsxs)(`div`,{className:Y.errorBox,children:[(0,j.jsx)(`div`,{children:t.error}),(0,j.jsxs)(`div`,{className:Y.errorHint,children:[`Run: `,(0,j.jsx)(`code`,{children:`nha config set github-token YOUR_PAT`})]})]});let g=t?.user,v=Array.isArray(t?.notifications)?t.notifications:[],y=Array.isArray(t?.issues)?t.issues:[],b=Array.isArray(t?.prs)?t.prs:[];return(0,j.jsxs)(`div`,{className:Y.root,children:[g?.login&&(0,j.jsxs)(`div`,{className:Y.userRow,children:[g.avatar&&(0,j.jsx)(`img`,{src:g.avatar,className:Y.avatar,alt:g.login}),(0,j.jsxs)(`div`,{style:{flex:1},children:[(0,j.jsxs)(`div`,{className:Y.userLogin,children:[`@`,g.login]}),g.name&&(0,j.jsx)(`div`,{className:Y.userName,children:g.name})]}),(0,j.jsx)(`button`,{className:Y.disconnectBtn,onClick:h,children:`Disconnect`})]}),(0,j.jsxs)(`div`,{className:Y.repoBar,children:[(0,j.jsx)(`input`,{className:Y.repoInput,value:s,onChange:e=>c(e.target.value),placeholder:`owner/repo`,onKeyDown:e=>e.key===`Enter`&&f()}),(0,j.jsx)(`button`,{className:Y.issuesBtn,onClick:f,children:`Issues`}),(0,j.jsx)(`button`,{className:Y.prsBtn,onClick:p,children:`PRs`})]}),g?.repos&&g.repos.length>0&&(0,j.jsx)(`div`,{className:Y.repoPills,children:g.repos.slice(0,12).map(e=>(0,j.jsxs)(`button`,{className:Y.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,j.jsx)(`span`,{className:Y.issueCount,children:e.open_issues}):null]},e.full_name))}),(0,j.jsxs)(`div`,{className:Y.tabs,children:[(0,j.jsxs)(`button`,{className:`${Y.tab} ${l===`notifs`?Y.tabActive:``}`,onClick:()=>u(`notifs`),children:[`Notifications `,v.length>0?`(${v.length})`:``]}),y.length>0&&(0,j.jsxs)(`button`,{className:`${Y.tab} ${l===`issues`?Y.tabActive:``}`,onClick:()=>u(`issues`),children:[`Issues (`,y.length,`)`]}),b.length>0&&(0,j.jsxs)(`button`,{className:`${Y.tab} ${l===`prs`?Y.tabActive:``}`,onClick:()=>u(`prs`),children:[`PRs (`,b.length,`)`]}),l===`notifs`&&v.length>0&&(0,j.jsx)(`button`,{className:Y.markRead,onClick:m,children:`Mark all read`})]}),(0,j.jsxs)(`div`,{className:Y.content,children:[l===`notifs`&&(v.length===0?(0,j.jsx)(`div`,{className:Y.empty,children:`No notifications`}):v.map((e,t)=>(0,j.jsxs)(`a`,{className:Y.notifRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,j.jsx)(`span`,{className:Y.notifRepo,children:e.repo}),(0,j.jsxs)(`span`,{className:Y.notifType,children:[`[`,e.type,`]`]}),(0,j.jsx)(`div`,{className:Y.notifTitle,children:e.title}),(0,j.jsxs)(`div`,{className:Y.notifMeta,children:[e.reason,` · `,e.updated]})]},t))),l===`issues`&&(y.length===0?(0,j.jsxs)(`div`,{className:Y.empty,children:[e(`github.noIssues`),` for `,a]}):y.map((e,t)=>(0,j.jsxs)(`a`,{className:Y.issueRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,j.jsxs)(`span`,{className:Y.issueNum,children:[`#`,e.number]}),(0,j.jsx)(`span`,{className:Y.issueTitle,children:e.title}),e.assignee&&(0,j.jsxs)(`span`,{className:Y.issueMeta,children:[`→ `,e.assignee]}),e.labels&&(0,j.jsxs)(`span`,{className:Y.issueLabel,children:[`[`,e.labels,`]`]}),(0,j.jsx)(`div`,{className:Y.issueMeta,children:e.updated})]},t))),l===`prs`&&(b.length===0?(0,j.jsxs)(`div`,{className:Y.empty,children:[`No PRs for `,a]}):b.map((e,t)=>(0,j.jsxs)(`a`,{className:Y.prRow,href:e.url,target:`_blank`,rel:`noreferrer`,children:[(0,j.jsxs)(`span`,{className:Y.prNum,children:[`#`,e.number]}),(0,j.jsx)(`span`,{className:Y.prTitle,children:e.title}),(0,j.jsxs)(`span`,{className:Y.prAuthor,children:[`by `,e.author]}),e.draft&&(0,j.jsx)(`span`,{className:Y.prDraft,children:`DRAFT`}),(0,j.jsx)(`div`,{className:Y.prMeta,children:e.updated})]},t)))]})]})}var tn={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 nn(){let e=P(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)([]),l=()=>{i(!0),O(`/api/slack/channels`).then(e=>{n(e??{}),i(!1)}).catch(()=>i(!1))},u=e=>{o(e),O(`/api/slack/messages?channel=${e.id}`).then(e=>c(e?.messages??[]))};if((0,_.useEffect)(()=>{l()},[]),r)return(0,j.jsxs)(`div`,{className:tn.loading,children:[(0,j.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]});if(t?.error)return(0,j.jsxs)(`div`,{className:tn.errorBox,children:[(0,j.jsx)(`div`,{children:t.error}),(0,j.jsxs)(`div`,{className:tn.errorHint,children:[`Run: `,(0,j.jsx)(`code`,{children:`nha config set slack-token xoxb-YOUR-TOKEN`})]})]});let d=t?.channels??[];return(0,j.jsxs)(`div`,{className:tn.twoPane,children:[(0,j.jsxs)(`div`,{className:tn.sidebar,children:[(0,j.jsxs)(`div`,{className:tn.sidebarTitle,children:[(0,j.jsx)(`span`,{children:`💬 Slack`}),t?.workspace&&(0,j.jsx)(`span`,{className:tn.workspace,children:t.workspace})]}),d.length===0&&(0,j.jsx)(`div`,{className:tn.empty,children:`No channels`}),d.map(e=>(0,j.jsxs)(`div`,{className:`${tn.channelItem} ${a?.id===e.id?tn.channelActive:``}`,onClick:()=>u(e),children:[`# `,e.name]},e.id)),(0,j.jsx)(`button`,{className:tn.disconnectBtn,onClick:()=>k(`/api/config`,{key:`slack-token`,value:``}).then(l),children:`Disconnect`})]}),(0,j.jsx)(`div`,{className:tn.messagePane,children:a?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{className:tn.channelHeader,children:[`#`,a.name]}),s.length===0&&(0,j.jsx)(`div`,{className:tn.empty,children:`No messages`}),s.map((e,t)=>(0,j.jsxs)(`div`,{className:tn.message,children:[(0,j.jsx)(`span`,{className:tn.msgUser,children:e.username||e.user||`Unknown`}),(0,j.jsx)(`span`,{className:tn.msgText,children:e.text}),(0,j.jsx)(`span`,{className:tn.msgTs,children:new Date(parseFloat(e.ts)*1e3).toLocaleTimeString()})]},t))]}):(0,j.jsx)(`div`,{className:tn.emptyPane,children:`Select a channel`})})]})}function rn(){let e=P(),[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),O(e?`/api/notion/search?q=${encodeURIComponent(e)}`:`/api/notion`).then(e=>{n(e??{}),i(!1)}).catch(()=>i(!1))},f=e=>{o(e),O(`/api/notion/page?id=${encodeURIComponent(e.id)}`).then(e=>c(e?.content??``))};(0,_.useEffect)(()=>{d()},[]);let p=()=>d(l);if(r)return(0,j.jsxs)(`div`,{className:tn.loading,children:[(0,j.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]});if(t?.error)return(0,j.jsxs)(`div`,{className:tn.errorBox,children:[(0,j.jsx)(`div`,{children:t.error}),(0,j.jsxs)(`div`,{className:tn.errorHint,children:[`Run: `,(0,j.jsx)(`code`,{children:`nha config set notion-token secret_YOUR_TOKEN`})]})]});let m=t?.pages??[];return(0,j.jsxs)(`div`,{className:tn.twoPane,children:[(0,j.jsxs)(`div`,{className:tn.sidebar,children:[(0,j.jsx)(`div`,{className:tn.sidebarTitle,children:`📋 Notion`}),(0,j.jsxs)(`div`,{className:tn.searchRow,children:[(0,j.jsx)(`input`,{className:tn.searchInput,value:l,onChange:e=>u(e.target.value),placeholder:`Search pages…`,onKeyDown:e=>e.key===`Enter`&&p()}),(0,j.jsx)(`button`,{className:tn.searchBtn,onClick:p,children:`Go`})]}),m.length===0&&(0,j.jsx)(`div`,{className:tn.empty,children:`No pages found`}),m.map(e=>(0,j.jsxs)(`div`,{className:`${tn.channelItem} ${a?.id===e.id?tn.channelActive:``}`,onClick:()=>f(e),children:[(0,j.jsx)(`div`,{className:tn.pageTitle,children:e.title||`Untitled`}),e.last_edited&&(0,j.jsx)(`div`,{className:tn.pageMeta,children:e.last_edited.slice(0,10)})]},e.id)),(0,j.jsx)(`button`,{className:tn.disconnectBtn,onClick:()=>k(`/api/config`,{key:`notion-token`,value:``}).then(()=>d()),children:`Disconnect`})]}),(0,j.jsx)(`div`,{className:tn.messagePane,children:a?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:tn.channelHeader,children:a.title}),a.url&&(0,j.jsx)(`a`,{className:tn.openLink,href:a.url,target:`_blank`,rel:`noreferrer`,children:`Open in Notion ↗`}),(0,j.jsx)(`div`,{className:tn.pageBody,dangerouslySetInnerHTML:{__html:ye(s||`Loading…`)}})]}):(0,j.jsx)(`div`,{className:tn.emptyPane,children:`Select a page`})})]})}var X={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 an(e){return e.content||e.plaintext||e.message||``}function on(e){return e.senderName||e.senderFingerprint?.slice(0,8)||e.sender||`unknown`}function sn(){let e=P(),[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)(()=>{O(`/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=>{O(`/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 k(`/api/collab/create`,{name:e}).catch(()=>null);if(!t||t.error){alert(t?.error||`Error creating channel`);return}let r=t.id;await k(`/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 k(`/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 k(`/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.`)&&(k(`/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 k(`/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,j.jsxs)(`div`,{className:X.root,children:[(0,j.jsxs)(`div`,{className:X.sidebar,children:[(0,j.jsx)(`div`,{className:X.sidebarHeader,children:(0,j.jsx)(`div`,{className:X.sidebarTitle,children:`Alexandria`})}),(0,j.jsxs)(`div`,{className:X.sidebarBtns,children:[(0,j.jsx)(`button`,{className:X.createBtn,onClick:g,children:`+ Create`}),(0,j.jsx)(`button`,{className:X.joinBtn,onClick:v,children:`Join`})]}),t.length===0?(0,j.jsxs)(`div`,{className:X.noChannels,children:[e(`collab.noChannels`),` yet`]}):t.map(e=>(0,j.jsxs)(`div`,{className:`${X.channelItem} ${r===e.id?X.channelActive:``}`,onClick:()=>i(e.id),children:[(0,j.jsx)(`div`,{className:X.channelName,children:e.name}),(0,j.jsxs)(`div`,{className:X.channelMeta,children:[(0,j.jsxs)(`span`,{className:X.channelCode,onClick:t=>{t.stopPropagation(),x(e.id)},title:`Click to copy invite code`,children:[e.id.slice(0,8),`…`]}),(0,j.jsx)(`button`,{className:X.channelDel,onClick:t=>{t.stopPropagation(),y(e.id)},children:`del`})]})]},e.id))]}),(0,j.jsx)(`div`,{className:X.main,children:r?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{className:X.chatHeader,children:[(0,j.jsx)(`div`,{className:X.chatChannelName,children:t.find(e=>e.id===r)?.name??r.slice(0,12)}),(0,j.jsx)(`div`,{className:X.chatChannelId,children:r}),(0,j.jsx)(`div`,{className:`${X.statusDot} ${l?X.connected:X.disconnected}`}),(0,j.jsx)(`span`,{className:X.statusText,children:l?`Live`:`HTTP`})]}),(0,j.jsxs)(`div`,{className:X.messages,ref:p,children:[a.length===0&&(0,j.jsx)(`div`,{className:X.emptyMsgs,children:`No messages yet`}),a.map((e,t)=>{let n=on(e),r=an(e),i=n===d;return(0,j.jsxs)(`div`,{className:`${X.msg} ${i?X.msgSelf:X.msgOther}`,children:[!i&&(0,j.jsx)(`div`,{className:X.msgSender,children:n}),(0,j.jsx)(`div`,{className:X.msgContent,children:r}),(0,j.jsx)(`div`,{className:X.msgTime,children:new Date(e.timestamp).toLocaleTimeString()})]},e.id||t)})]}),(0,j.jsxs)(`div`,{className:X.inputRow,children:[(0,j.jsx)(`input`,{className:X.textInput,value:s,onChange:e=>c(e.target.value),placeholder:`Send an encrypted message…`,onKeyDown:e=>e.key===`Enter`&&!e.shiftKey&&b()}),(0,j.jsx)(`button`,{className:X.sendBtn,onClick:b,disabled:!s.trim(),children:e(`collab.send`)})]})]}):(0,j.jsxs)(`div`,{className:X.welcome,children:[(0,j.jsx)(`div`,{className:X.welcomeIcon,children:`🔐`}),(0,j.jsx)(`div`,{className:X.welcomeTitle,children:`Alexandria`}),(0,j.jsx)(`div`,{className:X.welcomeSub,children:`E2E encrypted messaging for AI agents and teams`}),(0,j.jsxs)(`div`,{className:X.welcomeBox,children:[(0,j.jsx)(`div`,{className:X.welcomeBoxTitle,children:`HOW TO USE`}),(0,j.jsxs)(`div`,{className:X.welcomeStep,children:[(0,j.jsx)(`strong`,{children:`1. Create a channel`}),` — Click [+ Create] in the sidebar. Give it a name.`]}),(0,j.jsx)(`div`,{className:X.welcomeHint,children:`You get an invite code. Share it with your team or another AI session.`}),(0,j.jsxs)(`div`,{className:X.welcomeStep,children:[(0,j.jsx)(`strong`,{children:`2. Others join`}),` — They click [Join] and paste the invite code.`]}),(0,j.jsx)(`div`,{className:X.welcomeHint,children:`Works from this web UI, the Android app, or the CLI.`}),(0,j.jsxs)(`div`,{className:X.welcomeStep,children:[(0,j.jsx)(`strong`,{children:`3. Chat encrypted`}),` — All messages are E2E encrypted. The server sees only ciphertext.`]})]}),(0,j.jsxs)(`div`,{className:X.welcomeBox,children:[(0,j.jsx)(`div`,{className:X.welcomeBoxTitle,children:`FROM CLI (same channels)`}),(0,j.jsx)(`div`,{className:X.cliCmd,children:`nha collab create "Project X"`}),(0,j.jsx)(`div`,{className:X.cliCmd,children:`nha collab join <invite-code>`}),(0,j.jsx)(`div`,{className:X.cliCmd,children:`nha collab send "Hello from CLI"`}),(0,j.jsx)(`div`,{className:X.cliCmd,children:`nha collab read`})]})]})})]})}var Z={root:`_root_1rr0l_2`,header:`_header_1rr0l_10`,title:`_title_1rr0l_21`,subtitle:`_subtitle_1rr0l_28`,headerTabs:`_headerTabs_1rr0l_34`,tabBtn:`_tabBtn_1rr0l_40`,tabActive:`_tabActive_1rr0l_51`,body:`_body_1rr0l_58`,editor:`_editor_1rr0l_67`,examples:`_examples_1rr0l_75`,sectionLabel:`_sectionLabel_1rr0l_81`,examplePills:`_examplePills_1rr0l_89`,examplePill:`_examplePill_1rr0l_89`,editorCols:`_editorCols_1rr0l_109`,leftSidebar:`_leftSidebar_1rr0l_119`,panel:`_panel_1rr0l_128`,panelHeader:`_panelHeader_1rr0l_135`,panelTitle:`_panelTitle_1rr0l_142`,addBtn:`_addBtn_1rr0l_149`,blockLabel:`_blockLabel_1rr0l_160`,blockCheck:`_blockCheck_1rr0l_170`,authField:`_authField_1rr0l_173`,authFieldInput:`_authFieldInput_1rr0l_183`,authFieldSelect:`_authFieldSelect_1rr0l_193`,authFieldReq:`_authFieldReq_1rr0l_204`,removeFieldBtn:`_removeFieldBtn_1rr0l_205`,skillsList:`_skillsList_1rr0l_208`,skillRow:`_skillRow_1rr0l_210`,skillIcon:`_skillIcon_1rr0l_218`,skillName:`_skillName_1rr0l_220`,skillBadge:`_skillBadge_1rr0l_229`,skillBadge_skill:`_skillBadge_skill_1rr0l_237`,skillBadge_memory:`_skillBadge_memory_1rr0l_238`,skillBadge_provider:`_skillBadge_provider_1rr0l_239`,skillBadge_log:`_skillBadge_log_1rr0l_240`,skillEmpty:`_skillEmpty_1rr0l_242`,skillBtn:`_skillBtn_1rr0l_244`,skillsEmpty:`_skillsEmpty_1rr0l_246`,snapshotRow:`_snapshotRow_1rr0l_249`,snapshotTs:`_snapshotTs_1rr0l_258`,snapshotCount:`_snapshotCount_1rr0l_259`,snapshotBtn:`_snapshotBtn_1rr0l_260`,genStatus:`_genStatus_1rr0l_263`,repairStatus:`_repairStatus_1rr0l_265`,repairStatusTitle:`_repairStatusTitle_1rr0l_266`,repairStatusProg:`_repairStatusProg_1rr0l_267`,repairStatusFile:`_repairStatusFile_1rr0l_268`,actionRow:`_actionRow_1rr0l_271`,actionBtn:`_actionBtn_1rr0l_273`,actionBtnIcon:`_actionBtnIcon_1rr0l_275`,actionBtnActive:`_actionBtnActive_1rr0l_276`,repairBtn:`_repairBtn_1rr0l_278`,sandboxBtn:`_sandboxBtn_1rr0l_280`,statsBar:`_statsBar_1rr0l_282`,rightPanel:`_rightPanel_1rr0l_285`,rightTabBar:`_rightTabBar_1rr0l_296`,rightTab:`_rightTab_1rr0l_296`,rightTabActive:`_rightTabActive_1rr0l_313`,repairBar:`_repairBar_1rr0l_316`,repairBarRow:`_repairBarRow_1rr0l_326`,repairBarIcon:`_repairBarIcon_1rr0l_327`,repairBarLabel:`_repairBarLabel_1rr0l_328`,repairBarFile:`_repairBarFile_1rr0l_329`,repairBarCounter:`_repairBarCounter_1rr0l_330`,repairBarTime:`_repairBarTime_1rr0l_331`,genBar:`_genBar_1rr0l_333`,genBarRow:`_genBarRow_1rr0l_343`,genBarRobot:`_genBarRobot_1rr0l_344`,robotBob:`_robotBob_1rr0l_1`,genBarLabel:`_genBarLabel_1rr0l_345`,genBarFile:`_genBarFile_1rr0l_346`,genBarCounter:`_genBarCounter_1rr0l_347`,genBarTime:`_genBarTime_1rr0l_348`,progressTrack:`_progressTrack_1rr0l_350`,repairProgress:`_repairProgress_1rr0l_351`,genProgress:`_genProgress_1rr0l_352`,genDots:`_genDots_1rr0l_355`,dot:`_dot_1rr0l_356`,dot1:`_dot1_1rr0l_357`,dotBounce:`_dotBounce_1rr0l_1`,dot2:`_dot2_1rr0l_358`,dot3:`_dot3_1rr0l_359`,stopBtn:`_stopBtn_1rr0l_362`,codeArea:`_codeArea_1rr0l_365`,sandboxWrap:`_sandboxWrap_1rr0l_366`,sandboxFrame:`_sandboxFrame_1rr0l_367`,sandboxEmpty:`_sandboxEmpty_1rr0l_368`,sandboxStartBtn:`_sandboxStartBtn_1rr0l_369`,sandboxConsole:`_sandboxConsole_1rr0l_372`,sandboxConsoleCollapsed:`_sandboxConsoleCollapsed_1rr0l_381`,sandboxConsoleHeader:`_sandboxConsoleHeader_1rr0l_382`,sandboxConsoleTitle:`_sandboxConsoleTitle_1rr0l_394`,sandboxConsolePort:`_sandboxConsolePort_1rr0l_395`,sandboxConsoleDots:`_sandboxConsoleDots_1rr0l_396`,sandboxConsoleToggle:`_sandboxConsoleToggle_1rr0l_397`,sandboxReloadBtn:`_sandboxReloadBtn_1rr0l_398`,sandboxStopBtn:`_sandboxStopBtn_1rr0l_400`,sandboxConsoleBody:`_sandboxConsoleBody_1rr0l_402`,sandboxLogLine:`_sandboxLogLine_1rr0l_408`,sandboxLogPhase:`_sandboxLogPhase_1rr0l_417`,sandboxLogError:`_sandboxLogError_1rr0l_418`,sandboxLogWarn:`_sandboxLogWarn_1rr0l_419`,sandboxLogOk:`_sandboxLogOk_1rr0l_420`,codeLayout:`_codeLayout_1rr0l_423`,codeRow:`_codeRow_1rr0l_432`,ideTabBar:`_ideTabBar_1rr0l_440`,ideTab:`_ideTab_1rr0l_440`,ideTabActive:`_ideTabActive_1rr0l_472`,ideTabError:`_ideTabError_1rr0l_477`,ideTabPending:`_ideTabPending_1rr0l_478`,ideTabIcon:`_ideTabIcon_1rr0l_479`,ideTabName:`_ideTabName_1rr0l_480`,ideTabDot:`_ideTabDot_1rr0l_481`,codeEditorWrap:`_codeEditorWrap_1rr0l_489`,editToggleBtn:`_editToggleBtn_1rr0l_500`,editToggleBtnActive:`_editToggleBtnActive_1rr0l_511`,codeEditor:`_codeEditor_1rr0l_489`,genCursor:`_genCursor_1rr0l_533`,cursorBlink:`_cursorBlink_1rr0l_1`,diffOverlay:`_diffOverlay_1rr0l_542`,diffOverlayHeader:`_diffOverlayHeader_1rr0l_551`,diffOverlayActions:`_diffOverlayActions_1rr0l_562`,diffAcceptBtn:`_diffAcceptBtn_1rr0l_563`,diffRejectBtn:`_diffRejectBtn_1rr0l_564`,diffOverlayBody:`_diffOverlayBody_1rr0l_565`,diffSame:`_diffSame_1rr0l_566`,diffRem:`_diffRem_1rr0l_567`,diffAdd:`_diffAdd_1rr0l_568`,noFiles:`_noFiles_1rr0l_570`,noFilesHero:`_noFilesHero_1rr0l_580`,noFilesIcon:`_noFilesIcon_1rr0l_587`,noFilesTitle:`_noFilesTitle_1rr0l_589`,noFilesTagline:`_noFilesTagline_1rr0l_596`,noFilesSteps:`_noFilesSteps_1rr0l_601`,noFilesStep:`_noFilesStep_1rr0l_601`,noFilesStepNum:`_noFilesStepNum_1rr0l_618`,noFilesExamplesHint:`_noFilesExamplesHint_1rr0l_632`,noFilesExampleBtn:`_noFilesExampleBtn_1rr0l_642`,codeViewer:`_codeViewer_1rr0l_654`,codeHeader:`_codeHeader_1rr0l_662`,codeFileIcon:`_codeFileIcon_1rr0l_675`,codeFileName:`_codeFileName_1rr0l_676`,codeFileMeta:`_codeFileMeta_1rr0l_677`,fileError:`_fileError_1rr0l_679`,fileSyntaxError:`_fileSyntaxError_1rr0l_680`,filePending:`_filePending_1rr0l_681`,code:`_code_1rr0l_365`,codeError:`_codeError_1rr0l_696`,codeSyntaxError:`_codeSyntaxError_1rr0l_697`,fileSidebar:`_fileSidebar_1rr0l_700`,fileSidebarHeader:`_fileSidebarHeader_1rr0l_709`,fileTab:`_fileTab_1rr0l_719`,fileTabActive:`_fileTabActive_1rr0l_735`,fileTabError:`_fileTabError_1rr0l_736`,fileTabRow:`_fileTabRow_1rr0l_738`,fileTabIcon:`_fileTabIcon_1rr0l_739`,fileTabName:`_fileTabName_1rr0l_740`,fileTabSize:`_fileTabSize_1rr0l_741`,fileTabDir:`_fileTabDir_1rr0l_742`,fileTabTokens:`_fileTabTokens_1rr0l_743`,fileTabMeta:`_fileTabMeta_1rr0l_744`,projectsList:`_projectsList_1rr0l_747`,emptyProjects:`_emptyProjects_1rr0l_749`,emptyIcon:`_emptyIcon_1rr0l_750`,emptyHint:`_emptyHint_1rr0l_751`,projectCard:`_projectCard_1rr0l_753`,projectInfo:`_projectInfo_1rr0l_754`,projectName:`_projectName_1rr0l_755`,projectDesc:`_projectDesc_1rr0l_756`,projectMeta:`_projectMeta_1rr0l_757`,openBtn:`_openBtn_1rr0l_758`,deleteBtn:`_deleteBtn_1rr0l_759`,planBanner:`_planBanner_1rr0l_762`,planTitle:`_planTitle_1rr0l_771`,planText:`_planText_1rr0l_772`,planActions:`_planActions_1rr0l_773`,planApprove:`_planApprove_1rr0l_774`,planReject:`_planReject_1rr0l_775`,grepPanel:`_grepPanel_1rr0l_778`,grepRow:`_grepRow_1rr0l_787`,grepInput:`_grepInput_1rr0l_788`,grepBtn:`_grepBtn_1rr0l_790`,grepClose:`_grepClose_1rr0l_791`,grepCount:`_grepCount_1rr0l_792`,grepResults:`_grepResults_1rr0l_793`,grepEmpty:`_grepEmpty_1rr0l_794`,grepMatch:`_grepMatch_1rr0l_795`,grepMatchFile:`_grepMatchFile_1rr0l_797`,grepMatchLine:`_grepMatchLine_1rr0l_798`,diffPanel:`_diffPanel_1rr0l_801`,diffHeader:`_diffHeader_1rr0l_810`,diffClose:`_diffClose_1rr0l_811`,diffFile:`_diffFile_1rr0l_812`,diffSummary:`_diffSummary_1rr0l_813`,diffArrow:`_diffArrow_1rr0l_814`,diffFileName:`_diffFileName_1rr0l_815`,diffAdded:`_diffAdded_1rr0l_816`,diffRemoved:`_diffRemoved_1rr0l_817`,diffContent:`_diffContent_1rr0l_818`,diffInline:`_diffInline_1rr0l_821`,diffInlineHeader:`_diffInlineHeader_1rr0l_822`,diffRemLine:`_diffRemLine_1rr0l_823`,diffAddLine:`_diffAddLine_1rr0l_824`,chatPanel:`_chatPanel_1rr0l_827`,chatMessages:`_chatMessages_1rr0l_836`,chatWelcome:`_chatWelcome_1rr0l_838`,chatUser:`_chatUser_1rr0l_840`,chatUserBubble:`_chatUserBubble_1rr0l_841`,chatAttachPreviews:`_chatAttachPreviews_1rr0l_842`,chatAttachBadge:`_chatAttachBadge_1rr0l_843`,chatSystem:`_chatSystem_1rr0l_845`,chatSystemBubble:`_chatSystemBubble_1rr0l_846`,chatSyntaxErr:`_chatSyntaxErr_1rr0l_847`,chatAgent:`_chatAgent_1rr0l_849`,chatAgentCard:`_chatAgentCard_1rr0l_850`,chatAgentHeader:`_chatAgentHeader_1rr0l_851`,chatAgentRobot:`_chatAgentRobot_1rr0l_852`,chatAgentRobotAnim:`_chatAgentRobotAnim_1rr0l_853`,chatAgentLabel:`_chatAgentLabel_1rr0l_854`,chatRunningDots:`_chatRunningDots_1rr0l_855`,chatAgentText:`_chatAgentText_1rr0l_856`,chatToolBadges:`_chatToolBadges_1rr0l_857`,toolBadge:`_toolBadge_1rr0l_858`,toolBadgeOk:`_toolBadgeOk_1rr0l_859`,toolBadgeErr:`_toolBadgeErr_1rr0l_860`,cursor:`_cursor_1rr0l_862`,blink:`_blink_1rr0l_1`,attachPreviews:`_attachPreviews_1rr0l_865`,attachBadge:`_attachBadge_1rr0l_866`,removeAttachBtn:`_removeAttachBtn_1rr0l_867`,projNameRow:`_projNameRow_1rr0l_870`,projNameLabel:`_projNameLabel_1rr0l_871`,projNameInput:`_projNameInput_1rr0l_872`,projActiveRow:`_projActiveRow_1rr0l_873`,projActiveName:`_projActiveName_1rr0l_874`,chatInputRow:`_chatInputRow_1rr0l_877`,attachLabel:`_attachLabel_1rr0l_878`,chatTextarea:`_chatTextarea_1rr0l_879`,chatSendCol:`_chatSendCol_1rr0l_882`,chatSendBtn:`_chatSendBtn_1rr0l_883`,chatStopBtn:`_chatStopBtn_1rr0l_885`,modalOverlay:`_modalOverlay_1rr0l_888`,modal:`_modal_1rr0l_888`,modalHeader:`_modalHeader_1rr0l_910`,modalTitle:`_modalTitle_1rr0l_911`,modalClose:`_modalClose_1rr0l_912`,modalBody:`_modalBody_1rr0l_914`,modalRow:`_modalRow_1rr0l_916`,modalField:`_modalField_1rr0l_917`,modalLabel:`_modalLabel_1rr0l_918`,modalLabelRow:`_modalLabelRow_1rr0l_919`,modalSelect:`_modalSelect_1rr0l_921`,modalInput:`_modalInput_1rr0l_922`,modalHint:`_modalHint_1rr0l_925`,modalAiBox:`_modalAiBox_1rr0l_927`,modalAiRow:`_modalAiRow_1rr0l_928`,modalAiDesc:`_modalAiDesc_1rr0l_929`,modalAiBtn:`_modalAiBtn_1rr0l_930`,modalContentArea:`_modalContentArea_1rr0l_933`,logView:`_logView_1rr0l_936`,modalFooter:`_modalFooter_1rr0l_938`,modalCancelBtn:`_modalCancelBtn_1rr0l_939`,modalSaveBtn:`_modalSaveBtn_1rr0l_940`},cn=[{name:`MySaaS`,desc:`Full-stack SaaS web application with Node.js/Express backend and vanilla JS frontend.
592
592
 
593
593
  BACKEND (server.js + routes/):
594
594
  - Express server with helmet, cors, rate-limiting, compression middleware
@@ -676,25 +676,25 @@ FRONTEND:
676
676
  - index.html: Job board homepage — (1) Hero: gradient background, large search widget (keyword input + location input + category select + Search button), quick stats bar (12,847 Jobs / 3,420 Companies / 45K Candidates). (2) Featured jobs: horizontal scroll row of 4 "Featured" cards with company logo (colored emoji), job title, company name, location + type badge + salary range + "Easy Apply" button. (3) Main layout: left sidebar filters (Job Type checkboxes, Salary Range slider, Category checkboxes, Location input, Posted Within select, Remote Only toggle) + right: jobs list (job row cards with company logo/title/company/location/type/salary/time-ago posted/Save bookmark/Apply button). (4) "Load More" button + results count "Showing 12 of 247 jobs". (5) Top companies section: 8 company cards with logo/name/industry/openings count. (6) Category browsing: 6 category cards with icon/name/count/link. (7) Job seeker CTA banner. (8) Newsletter.
677
677
  - job.html: Job detail page — company header (logo + name + industry + website + size + "Follow" button), job title + badges (Remote, Senior, Urgent), salary + location + posted date, Apply Now button (sticky on scroll), job description (markdown-rendered sections: About/Responsibilities/Requirements/Nice-to-Have/Benefits), company sidebar card (description + stats), similar jobs list (4 cards)
678
678
  - apply.html: Application modal/page — job summary header, form (Full Name / Email / Phone / LinkedIn URL / Portfolio URL / Cover Letter textarea with character count / Resume paste textarea), Submit button with loading state, success page with application reference number
679
- - public/css/main.css: Modern job board design — tag/badge system (Remote=blue, Onsite=green, Urgent=red), salary range display, company logo placeholder styles, filter sidebar collapse on mobile, job card hover effects, application form validation styles`}],ln=[{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:`✉️`}],un={js:`📄`,ts:`📄`,css:`🎨`,html:`🌐`,json:`📋`,md:`📑`,sql:`🗂`,env:`🔐`,conf:`⚙`,lock:`🔒`};function dn(e){return un[e.split(`.`).pop()?.toLowerCase()??``]??`📄`}function fn(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 pn(e){return e===`memory`?`🧠`:e===`provider`?`🤖`:e===`log`?`📄`:`📋`}function mn(){let e=P(),[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)(null),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(null),[w,T]=(0,_.useState)(!1),[E,ee]=(0,_.useState)(!1),[D,te]=(0,_.useState)(0),[ne,A]=(0,_.useState)(0),[re,M]=(0,_.useState)(``),[N,ie]=(0,_.useState)({fi:0,total:0,name:``}),[ae,oe]=(0,_.useState)({tokIn:0,tokOut:0}),[se,ce]=(0,_.useState)(null),[F,le]=(0,_.useState)([]),[ue,de]=(0,_.useState)(``),[fe,pe]=(0,_.useState)(!1),[me,he]=(0,_.useState)([]),[ge,_e]=(0,_.useState)(null),[ve,ye]=(0,_.useState)([]),[I,be]=(0,_.useState)(!1),[xe,Se]=(0,_.useState)(null),[Ce,L]=(0,_.useState)([]),[we,Te]=(0,_.useState)(!1),[Ee,R]=(0,_.useState)(``),[z,De]=(0,_.useState)([]),[Oe,ke]=(0,_.useState)([]),[Ae,je]=(0,_.useState)([]),[Me,Ne]=(0,_.useState)(null),[Pe,Fe]=(0,_.useState)(!1),[Ie,B]=(0,_.useState)([]),[Le,Re]=(0,_.useState)(null),ze=(0,_.useRef)(null),[Be,Ve]=(0,_.useState)(`0s`),[He,Ue]=(0,_.useState)(`0s`),We=(0,_.useRef)(0),Ge=(0,_.useRef)(0),Ke=(0,_.useRef)(null),qe=(0,_.useRef)(null),Je=(0,_.useRef)(null),Ye=(0,_.useRef)(null),Xe=(0,_.useRef)(null),Ze=(0,_.useRef)(null);function Qe(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function $e(e){let t=Math.floor((Date.now()-e)/1e3),n=Math.floor(t/60);return(n>0?`${n}m `:``)+`${t%60}s`}(0,_.useEffect)(()=>(w||E?Ke.current=setInterval(()=>{w&&Ve($e(We.current)),E&&Ue($e(Ge.current))},1e3):Ke.current&&=(clearInterval(Ke.current),null),()=>{Ke.current&&clearInterval(Ke.current)}),[w,E]);function et(){Je.current&&(Je.current.scrollTop=Je.current.scrollHeight)}(0,_.useEffect)(()=>{et()},[F]),(0,_.useEffect)(()=>{a&&!I&&(be(!0),O(`/api/studio/webcraft/skills/${encodeURIComponent(a)}`).then(e=>{e?.skills&&ye(e.skills)}).catch(()=>{}))},[a,I]);async function tt(e,t){if(w||!e||e.length<5)return;T(!0),m([]),g(0),y(null),ie({fi:0,total:0,name:``}),oe({tokIn:0,tokOut:0}),We.current=Date.now(),Ve(`0s`),qe.current=new AbortController;let n=Date.now();try{let r=await fetch(`/api/studio/webcraft/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},signal:qe.current.signal,body:JSON.stringify({projectName:t,description:e,blocks:l,authFields:d})});if(!r.ok||!r.body){T(!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(`
679
+ - public/css/main.css: Modern job board design — tag/badge system (Remote=blue, Onsite=green, Urgent=red), salary range display, company logo placeholder styles, filter sidebar collapse on mobile, job card hover effects, application form validation styles`}],ln=[{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:`✉️`}],un={js:`📄`,ts:`📄`,css:`🎨`,html:`🌐`,json:`📋`,md:`📑`,sql:`🗂`,env:`🔐`,conf:`⚙`,lock:`🔒`};function dn(e){return un[e.split(`.`).pop()?.toLowerCase()??``]??`📄`}function fn(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 pn(e){return e===`memory`?`🧠`:e===`provider`?`🤖`:e===`log`?`📄`:`📋`}function mn(){let e=P(),[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)(null),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(null),[w,T]=(0,_.useState)(!1),[E,ee]=(0,_.useState)(!1),[D,te]=(0,_.useState)(0),[ne,A]=(0,_.useState)(0),[re,M]=(0,_.useState)(``),[N,ie]=(0,_.useState)({fi:0,total:0,name:``}),[ae,oe]=(0,_.useState)({tokIn:0,tokOut:0}),[se,ce]=(0,_.useState)(null),[F,le]=(0,_.useState)([]),[ue,de]=(0,_.useState)(``),[fe,pe]=(0,_.useState)(!1),[me,he]=(0,_.useState)([]),[ge,_e]=(0,_.useState)(null),[ve,ye]=(0,_.useState)([]),[I,be]=(0,_.useState)(!1),[xe,Se]=(0,_.useState)(null),[Ce,L]=(0,_.useState)([]),[we,Te]=(0,_.useState)(!1),[Ee,R]=(0,_.useState)(``),[z,De]=(0,_.useState)([]),[Oe,ke]=(0,_.useState)([]),[Ae,je]=(0,_.useState)([]),[Me,Ne]=(0,_.useState)(null),[Pe,Fe]=(0,_.useState)(!1),[Ie,B]=(0,_.useState)([]),[Le,Re]=(0,_.useState)(null),[ze,Be]=(0,_.useState)(!0),Ve=(0,_.useRef)(null),[He,Ue]=(0,_.useState)(`0s`),[We,Ge]=(0,_.useState)(`0s`),Ke=(0,_.useRef)(0),qe=(0,_.useRef)(0),Je=(0,_.useRef)(null),Ye=(0,_.useRef)(null),Xe=(0,_.useRef)(null),Ze=(0,_.useRef)(null),Qe=(0,_.useRef)(null),$e=(0,_.useRef)(null);function et(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function tt(e){let t=Math.floor((Date.now()-e)/1e3),n=Math.floor(t/60);return(n>0?`${n}m `:``)+`${t%60}s`}(0,_.useEffect)(()=>(w||E?Je.current=setInterval(()=>{w&&Ue(tt(Ke.current)),E&&Ge(tt(qe.current))},1e3):Je.current&&=(clearInterval(Je.current),null),()=>{Je.current&&clearInterval(Je.current)}),[w,E]);function nt(){Xe.current&&(Xe.current.scrollTop=Xe.current.scrollHeight)}(0,_.useEffect)(()=>{nt()},[F]),(0,_.useEffect)(()=>{a&&!I&&(be(!0),O(`/api/studio/webcraft/skills/${encodeURIComponent(a)}`).then(e=>{e?.skills&&ye(e.skills)}).catch(()=>{}))},[a,I]);async function rt(e,t){if(w||!e||e.length<5)return;T(!0),m([]),g(0),y(null),ie({fi:0,total:0,name:``}),oe({tokIn:0,tokOut:0}),Ke.current=Date.now(),Ue(`0s`),Ye.current=new AbortController;let n=Date.now();try{let r=await fetch(`/api/studio/webcraft/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},signal:Ye.current.signal,body:JSON.stringify({projectName:t,description:e,blocks:l,authFields:d})});if(!r.ok||!r.body){T(!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(`
680
680
 
681
- `);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===`processing`||e.type===`planning`)ie(t=>({...t,name:e.type===`planning`?`📋 Pianificazione struttura...`:e.msg||`Avvio...`}));else if(e.type===`file_start`)s.push({name:e.name,content:``,_pending:!0}),m([...s]),ie({fi:e.fi,total:e.total,name:e.name}),g(s.length-1),y(``);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]),y(t?t.content:null)}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]),ie({fi:e.fi,total:e.total,name:e.name}),(e.cumTokIn||e.cumTokOut)&&oe({tokIn:e.cumTokIn||0,tokOut:e.cumTokOut||0})}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`&&(ce({seconds:Math.round((Date.now()-n)/1e3),tokIn:e.tokIn??0,tokOut:e.tokOut??0,files:s.length}),y(null),T(!1),be(!1),ye([]),s.some(e=>e._error||e._syntaxError)?setTimeout(()=>Xe.current?.(),800):setTimeout(()=>Ze.current?.(),800))}catch{}}}}catch(e){e.name!==`AbortError`&&le(t=>[...t,{role:`system`,text:`Errore generazione: `+e.message}]),T(!1)}}async function nt(){let e=ue.trim();if(!(a&&p.length>0)){if(!e||e.length<5)return;let t=a||`MyProject`;o(t),c(e),de(``),await tt(e,t);return}if(!e&&me.length===0||fe||w)return;let t=[...me];if(he([]),de(``),e.toLowerCase().startsWith(`/plan `)||e.toLowerCase().startsWith(`piano: `)){let t=e.replace(/^\/plan[ ]*/i,``).replace(/^piano:[ ]*/i,``);le(t=>[...t,{role:`user`,text:e}]),await rt(`[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}le(n=>[...n,{role:`user`,text:e,attachments:t}]),await rt(e,null,t)}async function rt(e,t,n){if(fe)return;pe(!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){le(e=>[...e,{role:`agent`,text:`Errore: ${i.status}`,tools:[]}]),pe(!1);return}let o={role:`agent`,text:``,tools:[]};le(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(`
681
+ `);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===`processing`||e.type===`planning`)ie(t=>({...t,name:e.type===`planning`?`📋 Pianificazione struttura...`:e.msg||`Avvio...`}));else if(e.type===`file_start`)s.push({name:e.name,content:``,_pending:!0}),m([...s]),ie({fi:e.fi,total:e.total,name:e.name}),g(s.length-1),y(``);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]),y(t?t.content:null)}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]),ie({fi:e.fi,total:e.total,name:e.name}),(e.cumTokIn||e.cumTokOut)&&oe({tokIn:e.cumTokIn||0,tokOut:e.cumTokOut||0})}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`&&(ce({seconds:Math.round((Date.now()-n)/1e3),tokIn:e.tokIn??0,tokOut:e.tokOut??0,files:s.length}),y(null),T(!1),be(!1),ye([]),s.some(e=>e._error||e._syntaxError)?setTimeout(()=>Qe.current?.(),800):setTimeout(()=>$e.current?.(),800))}catch{}}}}catch(e){e.name!==`AbortError`&&le(t=>[...t,{role:`system`,text:`Errore generazione: `+e.message}]),T(!1)}}async function it(){let e=ue.trim();if(!(a&&p.length>0)){if(!e||e.length<5)return;let t=a||`MyProject`;o(t),c(e),de(``),await rt(e,t);return}if(!e&&me.length===0||fe||w)return;let t=[...me];if(he([]),de(``),e.toLowerCase().startsWith(`/plan `)||e.toLowerCase().startsWith(`piano: `)){let t=e.replace(/^\/plan[ ]*/i,``).replace(/^piano:[ ]*/i,``);le(t=>[...t,{role:`user`,text:e}]),await at(`[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}le(n=>[...n,{role:`user`,text:e,attachments:t}]),await at(e,null,t)}async function at(e,t,n){if(fe)return;pe(!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){le(e=>[...e,{role:`agent`,text:`Errore: ${i.status}`,tools:[]}]),pe(!1);return}let o={role:`agent`,text:``,tools:[]};le(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(`
682
682
 
683
- `);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,le(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),le(e=>{let t=[...e];return t[t.length-1]={...o},t})):e.type===`done`?(t&&!u&&_e({plan:o.text,originalMessage:t}),pe(!1),e.changed&&await it((o.tools??[]).filter(e=>e.op===`edit`||e.op===`write`).map(e=>e.path),r)):e.type===`error`&&(o.text+=`
684
- Errore: `+e.msg,pe(!1))}catch{}}}}catch(e){le(t=>[...t,{role:`agent`,text:`Errore di rete: `+e.message,tools:[]}])}pe(!1)}async function it(e,t){if(!a)return;let n=await O(`/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);ke(e=>[...e,...r])}}function at(){qe.current&&=(qe.current.abort(),null),T(!1),pe(!1),le(e=>[...e,{role:`system`,text:`⏹ Generazione interrotta.`}])}async function ot(){return a?(await k(`/api/studio/webcraft/snapshot`,{projectName:a}))?.snapshot??null:null}async function st(){let e=await ot();e&&(le(t=>[...t,{role:`system`,text:`💾 Snapshot salvato (${e.slice(0,16).replace(`T`,` `)})`}]),ct())}async function ct(){if(!a)return;let e=await O(`/api/studio/webcraft/snapshots/${encodeURIComponent(a)}`);e?.snapshots&&L(e.snapshots)}async function lt(e){confirm(`Ripristinare lo snapshot del ${e.replace(`T`,` `).slice(0,16)}? I file attuali verranno sovrascritti.`)&&await k(`/api/studio/webcraft/restore`,{projectName:a,ts:e})!==null&&(le(t=>[...t,{role:`agent`,text:`Snapshot ripristinato (${e}). Ricarico i file...`}]),it([],{}))}async function V(){if(!a)return;let e=await k(`/api/studio/webcraft/syntax-check`,{projectName:a});if(e?.results){let t=e.results.filter(e=>!e.ok);t.length>0?le(e=>[...e,{role:`system`,text:`⚠ Syntax check: ${t.length} errore/i trovato/i.`,syntaxErrors:t}]):le(e=>[...e,{role:`system`,text:`✓ Syntax check: tutti i file JS sono validi.`}])}}async function ut(){let e=p.filter(e=>e._error||e._syntaxError);if(e.length===0){Ze.current?.();return}ee(!0),te(0),A(e.length),Ge.current=Date.now(),Ue(`0s`);for(let t=0;t<e.length;t++){let n=e[t];M(n.name),te(t),await rt(`REPAIR FILE: ${n.name}\nErrore: ${n._syntaxError??`generazione fallita`}\nRigenera il file correttamente. Output SOLO il contenuto del file, nessuna spiegazione.`,null,[])}te(e.length),M(``),ee(!1),setTimeout(()=>Ze.current?.(),500)}let dt={cleanup:`🧹`,shims:`🔌`,deps:`📦`,start:`🚀`,autofix:`🔧`,ready:`✅`};function ft(e,t=`info`){let n=new Date().toLocaleTimeString();B(r=>[...r,`${t===`phase`?`
685
- `:``}[${n}] ${e}`]),setTimeout(()=>{ze.current?.scrollTo(0,ze.current.scrollHeight)},50)}async function pt(e){if(!Pe){Fe(!0),Re(null),Ne(null),B([]),i(`preview`);try{let t=await fetch(`/api/studio/webcraft/sandbox/start`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({projectName:e})});if(!t.ok||!t.body){let e=t.ok?`No response body`:`HTTP ${t.status}`;ft(`ERROR: ${e}`,`error`),Re(e),Fe(!1);return}let n=t.body.getReader(),r=new TextDecoder,i=``;for(;;){let{done:e,value:t}=await n.read();if(e)break;i+=r.decode(t,{stream:!0});let a=i.split(`
683
+ `);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,le(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),le(e=>{let t=[...e];return t[t.length-1]={...o},t})):e.type===`done`?(t&&!u&&_e({plan:o.text,originalMessage:t}),pe(!1),e.changed&&await ot((o.tools??[]).filter(e=>e.op===`edit`||e.op===`write`).map(e=>e.path),r)):e.type===`error`&&(o.text+=`
684
+ Errore: `+e.msg,pe(!1))}catch{}}}}catch(e){le(t=>[...t,{role:`agent`,text:`Errore di rete: `+e.message,tools:[]}])}pe(!1)}async function ot(e,t){if(!a)return;let n=await O(`/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);ke(e=>[...e,...r])}}function st(){Ye.current&&=(Ye.current.abort(),null),T(!1),pe(!1),le(e=>[...e,{role:`system`,text:`⏹ Generazione interrotta.`}])}async function ct(){return a?(await k(`/api/studio/webcraft/snapshot`,{projectName:a}))?.snapshot??null:null}async function lt(){let e=await ct();e&&(le(t=>[...t,{role:`system`,text:`💾 Snapshot salvato (${e.slice(0,16).replace(`T`,` `)})`}]),V())}async function V(){if(!a)return;let e=await O(`/api/studio/webcraft/snapshots/${encodeURIComponent(a)}`);e?.snapshots&&L(e.snapshots)}async function ut(e){confirm(`Ripristinare lo snapshot del ${e.replace(`T`,` `).slice(0,16)}? I file attuali verranno sovrascritti.`)&&await k(`/api/studio/webcraft/restore`,{projectName:a,ts:e})!==null&&(le(t=>[...t,{role:`agent`,text:`Snapshot ripristinato (${e}). Ricarico i file...`}]),ot([],{}))}async function dt(){if(!a)return;let e=await k(`/api/studio/webcraft/syntax-check`,{projectName:a});if(e?.results){let t=e.results.filter(e=>!e.ok);t.length>0?le(e=>[...e,{role:`system`,text:`⚠ Syntax check: ${t.length} errore/i trovato/i.`,syntaxErrors:t}]):le(e=>[...e,{role:`system`,text:`✓ Syntax check: tutti i file JS sono validi.`}])}}async function ft(){let e=p.filter(e=>e._error||e._syntaxError);if(e.length===0){$e.current?.();return}ee(!0),te(0),A(e.length),qe.current=Date.now(),Ge(`0s`);for(let t=0;t<e.length;t++){let n=e[t];M(n.name),te(t),await at(`REPAIR FILE: ${n.name}\nErrore: ${n._syntaxError??`generazione fallita`}\nRigenera il file correttamente. Output SOLO il contenuto del file, nessuna spiegazione.`,null,[])}te(e.length),M(``),ee(!1),setTimeout(()=>$e.current?.(),500)}let pt={cleanup:`🧹`,shims:`🔌`,deps:`📦`,start:`🚀`,autofix:`🔧`,ready:`✅`};function mt(e,t=`info`){let n=new Date().toLocaleTimeString();B(r=>[...r,`${t===`phase`?`
685
+ `:``}[${n}] ${e}`]),setTimeout(()=>{Ve.current?.scrollTo(0,Ve.current.scrollHeight)},50)}async function ht(e){if(!Pe){Fe(!0),Re(null),Ne(null),B([]),Be(!0),i(`preview`);try{let t=await fetch(`/api/studio/webcraft/sandbox/start`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({projectName:e})});if(!t.ok||!t.body){let e=t.ok?`No response body`:`HTTP ${t.status}`;mt(`ERROR: ${e}`,`error`),Re(e),Fe(!1);return}let n=t.body.getReader(),r=new TextDecoder,i=``;for(;;){let{done:e,value:t}=await n.read();if(e)break;i+=r.decode(t,{stream:!0});let a=i.split(`
686
686
 
687
- `);i=a.pop()??``;for(let e of a){let t=e.replace(/^data: /,``).trim();if(t)try{let e=JSON.parse(t);e.type===`phase`?ft(`${dt[e.phase]||`▸`} ${e.msg}`,`phase`):e.type===`ready`&&e.port?(ft(`✅ Server ready on port ${e.port}`,`ok`),Ne(e.port)):e.type===`status`?ft(` ${e.msg||`Processing...`}`,`info`):e.type===`log`?ft(` ${e.msg||``}`,`log`):e.type===`warn`?ft(`⚠ ${e.msg}`,`warn`):e.type===`error`?(ft(`❌ ${e.msg}`,`error`),Re(e.msg)):e.type===`exit`&&e.code!==0&&ft(`💥 Process crashed (exit code ${e.code})`,`error`)}catch{}}}}catch(e){let t=e.message||`Connection failed`;ft(`❌ ${t}`,`error`),Re(t)}Fe(!1)}}async function mt(){a&&await pt(a)}(0,_.useEffect)(()=>{Xe.current=ut,Ze.current=mt});async function ht(){if(!Ee||!a)return;let e=await k(`/api/studio/webcraft/grep`,{projectName:a,query:Ee});e?.matches&&De(e.matches)}function gt(e){let t=p.findIndex(t=>t.name===e);t>=0&&(g(t),i(`files`))}function H(){window.open(`/api/studio/webcraft/download/${encodeURIComponent(a)}`,`_blank`)}async function _t(e,t,n,r){t.endsWith(`.md`)||(t+=`.md`);let i={name:t,content:n,type:r},s;s=e.mode===`edit`&&e.idx!==null?ve.map((t,n)=>n===e.idx?i:t):[...ve,i],ye(s),Se(null);let c=a||`MyProject`;a||o(c),await k(`/api/studio/webcraft/skills/${encodeURIComponent(c)}`,{skills:s})}async function vt(e){let t=ve[e];!t||!confirm(`Eliminare "${t.name}"?`)||(await k(`/api/studio/webcraft/skills/${encodeURIComponent(a)}/delete`,{name:t.name}),ye(ve.filter((t,n)=>n!==e)))}async function yt(e){let t=ve[e];if(!t||!confirm(`Svuotare "${t.name}"? Il file rimane ma il contenuto viene cancellato.`))return;let n=ve.map((t,n)=>n===e?{...t,content:``}:t);ye(n),await k(`/api/studio/webcraft/skills/${encodeURIComponent(a)}`,{skills:n})}async function bt(){let e=await O(`/api/studio/webcraft/projects`);e?.projects&&je(e.projects)}async function xt(e){let t=await O(`/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`),le([]),ye([]),be(!1);let r=await O(`/api/studio/webcraft/projects/chat/load/${encodeURIComponent(t.projectName??e.name)}`);r?.chat&&le(r.chat);let a=await O(`/api/studio/webcraft/skills/${encodeURIComponent(t.projectName??e.name)}`);a?.skills&&(ye(a.skills),be(!0))}async function U(e){confirm(`Eliminare: ${e.name} - ${e.dir}?`)&&(await k(`/api/studio/webcraft/projects/${encodeURIComponent(e.name)}`,{},`DELETE`),je(Ae.filter(t=>t.name!==e.name)),a===e.name&&(o(``),m([]),le([]),c(``)))}async function St(){if(!ge)return;let e=ge.originalMessage;_e(null),await rt(e+`
688
- [Piano approvato — procedi con le modifiche]`,null,[])}function Ct(e){e&&Array.from(e).forEach(e=>{let t=new FileReader;t.onload=t=>{let n=(t.target?.result).split(`,`)[1];he(t=>[...t,{name:e.name,mimeType:e.type,base64:n,size:e.size}])},t.readAsDataURL(e)})}let wt=a&&p.length>0,Tt=p[h],Et=fe||w;return(0,j.jsxs)(`div`,{className:Z.root,children:[(0,j.jsxs)(`div`,{className:Z.header,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`div`,{className:Z.title,children:`⚙ WebCraft`}),(0,j.jsx)(`div`,{className:Z.subtitle,children:`Genera progetti web completi con agenti AI`})]}),(0,j.jsxs)(`div`,{className:Z.headerTabs,children:[(0,j.jsx)(`button`,{className:`${Z.tabBtn} ${t===`new`?Z.tabActive:``}`,onClick:()=>n(`new`),children:`+ Nuovo`}),(0,j.jsx)(`button`,{className:`${Z.tabBtn} ${t===`projects`?Z.tabActive:``}`,onClick:()=>{n(`projects`),bt()},children:`📁 Progetti`})]})]}),(0,j.jsx)(`div`,{className:Z.body,children:t===`projects`?(0,j.jsx)(`div`,{className:Z.projectsList,children:Ae.length===0?(0,j.jsxs)(`div`,{className:Z.emptyProjects,children:[(0,j.jsx)(`span`,{className:Z.emptyIcon,children:`📁`}),(0,j.jsx)(`span`,{children:e(`webcraft.noProjects`)}),(0,j.jsx)(`span`,{className:Z.emptyHint,children:`Crea un progetto nella tab Nuovo`})]}):Ae.map(e=>(0,j.jsxs)(`div`,{className:Z.projectCard,children:[(0,j.jsxs)(`div`,{className:Z.projectInfo,children:[(0,j.jsx)(`div`,{className:Z.projectName,children:e.name}),(0,j.jsx)(`div`,{className:Z.projectDesc,children:e.description}),(0,j.jsxs)(`div`,{className:Z.projectMeta,children:[(0,j.jsxs)(`span`,{children:[`📄 `,e.fileCount,` file`]}),(0,j.jsxs)(`span`,{children:[`📅 `,e.createdAt?new Date(e.createdAt).toLocaleString():``]})]})]}),(0,j.jsx)(`button`,{className:Z.openBtn,onClick:()=>xt(e),children:`↗ Apri`}),(0,j.jsx)(`button`,{className:Z.deleteBtn,onClick:()=>U(e),children:`🗑`})]},e.name))}):(0,j.jsxs)(`div`,{className:Z.editor,children:[(0,j.jsxs)(`div`,{className:Z.examples,children:[(0,j.jsx)(`div`,{className:Z.sectionLabel,children:`Esempi`}),(0,j.jsx)(`div`,{className:Z.examplePills,children:cn.map(e=>(0,j.jsx)(`button`,{className:Z.examplePill,onClick:()=>{o(e.name),c(e.desc),de(e.desc)},children:e.name},e.name))})]}),(0,j.jsxs)(`div`,{className:Z.editorCols,children:[(0,j.jsxs)(`div`,{className:Z.leftSidebar,children:[(0,j.jsxs)(`div`,{className:Z.panel,children:[(0,j.jsx)(`div`,{className:Z.panelTitle,children:`Blocchi`}),ln.map(e=>(0,j.jsxs)(`label`,{className:Z.blockLabel,children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:l[e.key],onChange:t=>u(n=>({...n,[e.key]:t.target.checked})),className:Z.blockCheck}),(0,j.jsx)(`span`,{children:e.icon}),(0,j.jsx)(`span`,{children:e.label})]},e.key))]}),l.auth&&(0,j.jsxs)(`div`,{className:Z.panel,children:[(0,j.jsxs)(`div`,{className:Z.panelHeader,children:[(0,j.jsx)(`div`,{className:Z.panelTitle,children:`Campi Auth`}),(0,j.jsx)(`button`,{className:Z.addBtn,onClick:()=>f(e=>[...e,{label:`New field`,type:`text`,required:!1}]),children:`+ Campo`})]}),d.map((e,t)=>(0,j.jsxs)(`div`,{className:Z.authField,children:[(0,j.jsx)(`input`,{value:e.label,onChange:e=>f(n=>n.map((n,r)=>r===t?{...n,label:e.target.value}:n)),className:Z.authFieldInput}),(0,j.jsx)(`select`,{value:e.type,onChange:e=>f(n=>n.map((n,r)=>r===t?{...n,type:e.target.value}:n)),className:Z.authFieldSelect,children:[`text`,`email`,`password`,`tel`,`date`,`number`].map(e=>(0,j.jsx)(`option`,{value:e,children:e},e))}),(0,j.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:Z.authFieldReq}),(0,j.jsx)(`button`,{onClick:()=>f(e=>e.filter((e,n)=>n!==t)),className:Z.removeFieldBtn,children:`×`})]},t))]}),(0,j.jsxs)(`div`,{className:Z.panel,children:[(0,j.jsxs)(`div`,{className:Z.panelHeader,children:[(0,j.jsx)(`div`,{className:Z.panelTitle,children:`🗂 Contesto AI`}),(0,j.jsx)(`button`,{className:Z.addBtn,onClick:()=>Se({mode:`new`,idx:null,name:``,content:``,type:`skill`,generating:!1}),children:`+ Skill`})]}),ve.length>0?(0,j.jsx)(`div`,{className:Z.skillsList,children:ve.map((e,t)=>(0,j.jsxs)(`div`,{className:Z.skillRow,children:[(0,j.jsx)(`span`,{className:Z.skillIcon,children:pn(e.type)}),(0,j.jsx)(`span`,{className:Z.skillName,title:e.name,children:e.name}),(0,j.jsx)(`span`,{className:`${Z.skillBadge} ${Z[`skillBadge_`+e.type]}`,children:e.type}),!e.content&&e.type!==`log`&&(0,j.jsx)(`span`,{className:Z.skillEmpty,children:`⚠`}),(0,j.jsx)(`button`,{className:Z.skillBtn,onClick:()=>Se({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,j.jsx)(`button`,{className:Z.skillBtn,onClick:()=>yt(t),children:`🗑`}),e.type===`log`&&(0,j.jsx)(`button`,{className:Z.skillBtn,onClick:()=>vt(t),children:`🗑`})]},t))}):(0,j.jsx)(`div`,{className:Z.skillsEmpty,children:I?`Nessun file di contesto. Clicca "+ Skill" per aggiungerne uno.`:`Crea o carica un progetto per i file di contesto.`})]}),Ce.length>0&&(0,j.jsxs)(`div`,{className:Z.panel,children:[(0,j.jsx)(`div`,{className:Z.panelTitle,children:`💾 Snapshot`}),Ce.slice(0,5).map(e=>{let t=e.ts.replace(`T`,` `).slice(0,16);return(0,j.jsxs)(`div`,{className:Z.snapshotRow,children:[(0,j.jsx)(`span`,{className:Z.snapshotTs,children:t}),(0,j.jsxs)(`span`,{className:Z.snapshotCount,children:[e.fileCount,`f`]}),(0,j.jsx)(`button`,{className:Z.snapshotBtn,onClick:()=>lt(e.ts),children:`↺`})]},e.ts)})]}),w&&(0,j.jsx)(`div`,{className:Z.genStatus,children:`⏳ Generazione...`}),E&&(0,j.jsxs)(`div`,{className:Z.repairStatus,children:[(0,j.jsx)(`div`,{className:Z.repairStatusTitle,children:`🔧 Correzione automatica...`}),(0,j.jsxs)(`div`,{className:Z.repairStatusProg,children:[D,` / `,ne,` file`]}),(0,j.jsx)(`div`,{className:Z.repairStatusFile,children:re})]}),p.length>0&&!w&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{className:Z.actionRow,children:[(0,j.jsx)(`button`,{className:Z.actionBtn,onClick:H,children:`⬇ ZIP`}),(0,j.jsx)(`button`,{className:Z.actionBtnIcon,title:`Syntax check`,onClick:V,children:`✅`}),(0,j.jsx)(`button`,{className:`${Z.actionBtnIcon} ${we?Z.actionBtnActive:``}`,title:`Grep`,onClick:()=>Te(!we),children:`🔍`}),(0,j.jsx)(`button`,{className:Z.actionBtnIcon,title:`Snapshot`,onClick:st,children:`💾`})]}),p.some(e=>e._error||e._syntaxError)&&!E&&(0,j.jsx)(`button`,{className:Z.repairBtn,onClick:ut,children:`🔧 Correggi tutti i file rossi`}),(0,j.jsx)(`button`,{className:Z.sandboxBtn,onClick:()=>{a?pt(a):i(`preview`)},children:Pe?`⏳ Starting...`:Me?`🌐 Sandbox Live`:`▶ Sandbox`}),se&&(0,j.jsxs)(`div`,{className:Z.statsBar,children:[(0,j.jsxs)(`span`,{children:[`⏱ `,se.seconds>=60?`${Math.floor(se.seconds/60)}m ${se.seconds%60}s`:`${se.seconds}s`]}),(0,j.jsxs)(`span`,{children:[`↑ `,se.tokIn.toLocaleString(),` tok`]}),(0,j.jsxs)(`span`,{children:[`↓ `,se.tokOut.toLocaleString(),` tok`]}),(0,j.jsxs)(`span`,{children:[`📄 `,se.files,` file`]})]})]})]}),(0,j.jsxs)(`div`,{className:Z.rightPanel,children:[(0,j.jsxs)(`div`,{className:Z.rightTabBar,children:[(0,j.jsx)(`button`,{className:`${Z.rightTab} ${r===`preview`?``:Z.rightTabActive}`,onClick:()=>i(`files`),children:`📄 File`}),(0,j.jsx)(`button`,{className:`${Z.rightTab} ${r===`preview`?Z.rightTabActive:``}`,onClick:()=>i(`preview`),children:`🌐 Sandbox`})]}),E&&(0,j.jsxs)(`div`,{className:Z.repairBar,children:[(0,j.jsxs)(`div`,{className:Z.repairBarRow,children:[(0,j.jsx)(`span`,{className:Z.repairBarIcon,children:`🔧`}),(0,j.jsx)(`span`,{className:Z.repairBarLabel,children:`Auto-fix`}),(0,j.jsx)(`span`,{className:Z.repairBarFile,children:re}),(0,j.jsxs)(`span`,{className:Z.repairBarCounter,children:[D,` / `,ne]}),(0,j.jsx)(`span`,{className:Z.repairBarTime,children:He}),(0,j.jsx)(`button`,{className:Z.stopBtn,onClick:at,children:`⏹ Stop`})]}),(0,j.jsx)(`div`,{className:Z.progressTrack,children:(0,j.jsx)(`div`,{className:Z.repairProgress,style:{width:ne>0?`${Math.round(D/ne*100)}%`:`0%`}})})]}),w&&(0,j.jsxs)(`div`,{className:Z.genBar,children:[(0,j.jsxs)(`div`,{className:Z.genBarRow,children:[(0,j.jsx)(`span`,{className:Z.genBarRobot,children:`🤖`}),(0,j.jsx)(`span`,{className:Z.genBarLabel,children:N.total===0?`Pianificazione...`:`Generazione`}),(0,j.jsx)(`span`,{className:Z.genBarFile,children:N.name.split(`,`)[0].trim()}),(0,j.jsx)(`span`,{className:Z.genBarCounter,children:N.total>0?`${N.fi} / ${N.total}`:``}),(0,j.jsx)(`span`,{className:Z.genBarCounter,children:ae.tokIn+ae.tokOut>0?`↑${Qe(ae.tokIn)} ↓${Qe(ae.tokOut)}`:``}),(0,j.jsx)(`span`,{className:Z.genBarTime,children:Be}),(0,j.jsxs)(`span`,{className:Z.genDots,children:[(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot1}`}),(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot2}`}),(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot3}`})]})]}),(0,j.jsx)(`div`,{className:Z.progressTrack,children:(0,j.jsx)(`div`,{className:Z.genProgress,style:{width:N.total>0?`${Math.round(N.fi/N.total*100)}%`:`0%`}})})]}),r===`preview`?(0,j.jsxs)(`div`,{className:Z.sandboxWrap,children:[(Pe||Ie.length>0||Le)&&(0,j.jsxs)(`div`,{className:Z.sandboxConsole,children:[(0,j.jsxs)(`div`,{className:Z.sandboxConsoleHeader,children:[(0,j.jsxs)(`span`,{className:Z.sandboxConsoleTitle,children:[Pe?`⏳`:Le?`❌`:Me?`✅`:`🌐`,` Sandbox Console`]}),Me&&(0,j.jsxs)(`span`,{className:Z.sandboxConsolePort,children:[`:`,Me]}),Pe&&(0,j.jsxs)(`span`,{className:Z.sandboxConsoleDots,children:[(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot1}`}),(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot2}`}),(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot3}`})]})]}),(0,j.jsx)(`div`,{className:Z.sandboxConsoleBody,ref:ze,children:Ie.map((e,t)=>(0,j.jsx)(`div`,{className:`${Z.sandboxLogLine} ${e.includes(`❌`)||e.includes(`💥`)?Z.sandboxLogError:e.includes(`⚠`)?Z.sandboxLogWarn:e.includes(`✅`)?Z.sandboxLogOk:e.includes(`🔌`)||e.includes(`📦`)||e.includes(`🚀`)||e.includes(`🔧`)||e.includes(`🧹`)?Z.sandboxLogPhase:``}`,children:e},t))})]}),Me?(0,j.jsx)(`iframe`,{src:`http://127.0.0.1:${Me}`,className:Z.sandboxFrame,title:`WebCraft Sandbox`,sandbox:`allow-scripts allow-same-origin allow-forms`}):(0,j.jsxs)(`div`,{className:Z.sandboxEmpty,children:[(0,j.jsx)(`span`,{children:Pe?`⏳`:Le?`❌`:`🌐`}),(0,j.jsx)(`span`,{children:Pe?`Avvio in corso...`:Le||`Sandbox non attiva`}),!Pe&&(0,j.jsx)(`button`,{className:Z.sandboxStartBtn,onClick:()=>{a&&pt(a)},children:`▶ Avvia Sandbox`})]})]}):(0,j.jsx)(`div`,{className:Z.codeArea,children:p.length===0&&w?(0,j.jsx)(`div`,{className:Z.noFiles,children:(0,j.jsxs)(`div`,{className:Z.noFilesHero,children:[(0,j.jsx)(`span`,{className:Z.noFilesIcon,children:`⏳`}),(0,j.jsx)(`span`,{className:Z.noFilesTitle,children:`Pianificazione...`}),(0,j.jsx)(`span`,{className:Z.noFilesTagline,children:N.name||`Analisi della struttura del progetto in corso`})]})}):p.length===0?(0,j.jsxs)(`div`,{className:Z.noFiles,children:[(0,j.jsxs)(`div`,{className:Z.noFilesHero,children:[(0,j.jsx)(`span`,{className:Z.noFilesIcon,children:`🔨`}),(0,j.jsx)(`span`,{className:Z.noFilesTitle,children:`WebCraft`}),(0,j.jsx)(`span`,{className:Z.noFilesTagline,children:`Genera progetti web completi con AI`})]}),(0,j.jsxs)(`div`,{className:Z.noFilesSteps,children:[(0,j.jsxs)(`div`,{className:Z.noFilesStep,children:[(0,j.jsx)(`span`,{className:Z.noFilesStepNum,children:`1`}),(0,j.jsx)(`span`,{children:`Scegli un esempio o scrivi una descrizione nel box in basso`})]}),(0,j.jsxs)(`div`,{className:Z.noFilesStep,children:[(0,j.jsx)(`span`,{className:Z.noFilesStepNum,children:`2`}),(0,j.jsxs)(`span`,{children:[`Premi `,(0,j.jsx)(`strong`,{children:`▶ Genera`}),` — l'AI crea tutti i file del progetto`]})]}),(0,j.jsxs)(`div`,{className:Z.noFilesStep,children:[(0,j.jsx)(`span`,{className:Z.noFilesStepNum,children:`3`}),(0,j.jsx)(`span`,{children:`Chiedi modifiche in chat, scarica lo ZIP o avvia il Sandbox`})]})]}),(0,j.jsxs)(`div`,{className:Z.noFilesExamplesHint,children:[`💡 Prova: `,(0,j.jsx)(`button`,{className:Z.noFilesExampleBtn,onClick:()=>{let e=cn[0];o(e.name),c(e.desc),de(e.desc)},children:`MySaaS`}),(0,j.jsx)(`button`,{className:Z.noFilesExampleBtn,onClick:()=>{let e=cn[1];o(e.name),c(e.desc),de(e.desc)},children:`MyShop`}),(0,j.jsx)(`button`,{className:Z.noFilesExampleBtn,onClick:()=>{let e=cn[3];o(e.name),c(e.desc),de(e.desc)},children:`MyPortfolio`})]})]}):(0,j.jsxs)(`div`,{className:Z.codeLayout,children:[(0,j.jsx)(`div`,{className:Z.ideTabBar,children:p.map((e,t)=>{let n=e._error||!!e._syntaxError,r=t===h;return(0,j.jsxs)(`button`,{className:`${Z.ideTab} ${r?Z.ideTabActive:``} ${n?Z.ideTabError:``} ${e._pending?Z.ideTabPending:``}`,onClick:()=>{g(t),x(null)},title:e.name,children:[(0,j.jsx)(`span`,{className:Z.ideTabIcon,children:e._pending?`⌛`:n?`⚠`:dn(e.name)}),(0,j.jsx)(`span`,{className:Z.ideTabName,children:e.name.split(`/`).pop()}),n&&(0,j.jsx)(`span`,{className:Z.ideTabDot})]},t)})}),S&&(0,j.jsxs)(`div`,{className:Z.diffOverlay,children:[(0,j.jsxs)(`div`,{className:Z.diffOverlayHeader,children:[(0,j.jsxs)(`span`,{children:[`✏ Modifica proposta — `,(0,j.jsx)(`strong`,{children:S.file})]}),(0,j.jsxs)(`div`,{className:Z.diffOverlayActions,children:[(0,j.jsx)(`button`,{className:Z.diffAcceptBtn,onClick:()=>{m(e=>e.map(e=>e.name===S.file?{...e,content:S.after}:e)),C(null)},children:`✓ Accetta`}),(0,j.jsx)(`button`,{className:Z.diffRejectBtn,onClick:()=>C(null),children:`✕ Rifiuta`})]})]}),(0,j.jsxs)(`div`,{className:Z.diffOverlayBody,children:[S.before.split(`
687
+ `);i=a.pop()??``;for(let e of a){let t=e.replace(/^data: /,``).trim();if(t)try{let e=JSON.parse(t);e.type===`phase`?mt(`${pt[e.phase]||`▸`} ${e.msg}`,`phase`):e.type===`ready`&&e.port?(mt(`✅ Server ready on port ${e.port}`,`ok`),Ne(e.port),Fe(!1),setTimeout(()=>Be(!1),1500)):e.type===`status`?mt(` ${e.msg||`Processing...`}`,`info`):e.type===`log`?mt(` ${e.msg||``}`,`log`):e.type===`warn`?mt(`⚠ ${e.msg}`,`warn`):e.type===`error`?(mt(`❌ ${e.msg}`,`error`),Re(e.msg)):e.type===`exit`&&e.code!==0&&mt(`💥 Process crashed (exit code ${e.code})`,`error`)}catch{}}}}catch(e){let t=e.message||`Connection failed`;mt(`❌ ${t}`,`error`),Re(t)}Fe(!1)}}async function gt(){a&&await ht(a)}(0,_.useEffect)(()=>{Qe.current=ft,$e.current=gt});async function H(){if(!Ee||!a)return;let e=await k(`/api/studio/webcraft/grep`,{projectName:a,query:Ee});e?.matches&&De(e.matches)}function _t(e){let t=p.findIndex(t=>t.name===e);t>=0&&(g(t),i(`files`))}function vt(){window.open(`/api/studio/webcraft/download/${encodeURIComponent(a)}`,`_blank`)}async function yt(e,t,n,r){t.endsWith(`.md`)||(t+=`.md`);let i={name:t,content:n,type:r},s;s=e.mode===`edit`&&e.idx!==null?ve.map((t,n)=>n===e.idx?i:t):[...ve,i],ye(s),Se(null);let c=a||`MyProject`;a||o(c),await k(`/api/studio/webcraft/skills/${encodeURIComponent(c)}`,{skills:s})}async function bt(e){let t=ve[e];!t||!confirm(`Eliminare "${t.name}"?`)||(await k(`/api/studio/webcraft/skills/${encodeURIComponent(a)}/delete`,{name:t.name}),ye(ve.filter((t,n)=>n!==e)))}async function xt(e){let t=ve[e];if(!t||!confirm(`Svuotare "${t.name}"? Il file rimane ma il contenuto viene cancellato.`))return;let n=ve.map((t,n)=>n===e?{...t,content:``}:t);ye(n),await k(`/api/studio/webcraft/skills/${encodeURIComponent(a)}`,{skills:n})}async function U(){let e=await O(`/api/studio/webcraft/projects`);e?.projects&&je(e.projects)}async function St(e){let t=await O(`/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`),le([]),ye([]),be(!1);let r=await O(`/api/studio/webcraft/projects/chat/load/${encodeURIComponent(t.projectName??e.name)}`);r?.chat&&le(r.chat);let a=await O(`/api/studio/webcraft/skills/${encodeURIComponent(t.projectName??e.name)}`);a?.skills&&(ye(a.skills),be(!0))}async function Ct(e){confirm(`Eliminare: ${e.name} - ${e.dir}?`)&&(await k(`/api/studio/webcraft/projects/${encodeURIComponent(e.name)}`,{},`DELETE`),je(Ae.filter(t=>t.name!==e.name)),a===e.name&&(o(``),m([]),le([]),c(``)))}async function wt(){if(!ge)return;let e=ge.originalMessage;_e(null),await at(e+`
688
+ [Piano approvato — procedi con le modifiche]`,null,[])}function Tt(e){e&&Array.from(e).forEach(e=>{let t=new FileReader;t.onload=t=>{let n=(t.target?.result).split(`,`)[1];he(t=>[...t,{name:e.name,mimeType:e.type,base64:n,size:e.size}])},t.readAsDataURL(e)})}let Et=a&&p.length>0,Dt=p[h],Ot=fe||w;return(0,j.jsxs)(`div`,{className:Z.root,children:[(0,j.jsxs)(`div`,{className:Z.header,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`div`,{className:Z.title,children:`⚙ WebCraft`}),(0,j.jsx)(`div`,{className:Z.subtitle,children:`Genera progetti web completi con agenti AI`})]}),(0,j.jsxs)(`div`,{className:Z.headerTabs,children:[(0,j.jsx)(`button`,{className:`${Z.tabBtn} ${t===`new`?Z.tabActive:``}`,onClick:()=>n(`new`),children:`+ Nuovo`}),(0,j.jsx)(`button`,{className:`${Z.tabBtn} ${t===`projects`?Z.tabActive:``}`,onClick:()=>{n(`projects`),U()},children:`📁 Progetti`})]})]}),(0,j.jsx)(`div`,{className:Z.body,children:t===`projects`?(0,j.jsx)(`div`,{className:Z.projectsList,children:Ae.length===0?(0,j.jsxs)(`div`,{className:Z.emptyProjects,children:[(0,j.jsx)(`span`,{className:Z.emptyIcon,children:`📁`}),(0,j.jsx)(`span`,{children:e(`webcraft.noProjects`)}),(0,j.jsx)(`span`,{className:Z.emptyHint,children:`Crea un progetto nella tab Nuovo`})]}):Ae.map(e=>(0,j.jsxs)(`div`,{className:Z.projectCard,children:[(0,j.jsxs)(`div`,{className:Z.projectInfo,children:[(0,j.jsx)(`div`,{className:Z.projectName,children:e.name}),(0,j.jsx)(`div`,{className:Z.projectDesc,children:e.description}),(0,j.jsxs)(`div`,{className:Z.projectMeta,children:[(0,j.jsxs)(`span`,{children:[`📄 `,e.fileCount,` file`]}),(0,j.jsxs)(`span`,{children:[`📅 `,e.createdAt?new Date(e.createdAt).toLocaleString():``]})]})]}),(0,j.jsx)(`button`,{className:Z.openBtn,onClick:()=>St(e),children:`↗ Apri`}),(0,j.jsx)(`button`,{className:Z.deleteBtn,onClick:()=>Ct(e),children:`🗑`})]},e.name))}):(0,j.jsxs)(`div`,{className:Z.editor,children:[(0,j.jsxs)(`div`,{className:Z.examples,children:[(0,j.jsx)(`div`,{className:Z.sectionLabel,children:`Esempi`}),(0,j.jsx)(`div`,{className:Z.examplePills,children:cn.map(e=>(0,j.jsx)(`button`,{className:Z.examplePill,onClick:()=>{o(e.name),c(e.desc),de(e.desc)},children:e.name},e.name))})]}),(0,j.jsxs)(`div`,{className:Z.editorCols,children:[(0,j.jsxs)(`div`,{className:Z.leftSidebar,children:[(0,j.jsxs)(`div`,{className:Z.panel,children:[(0,j.jsx)(`div`,{className:Z.panelTitle,children:`Blocchi`}),ln.map(e=>(0,j.jsxs)(`label`,{className:Z.blockLabel,children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:l[e.key],onChange:t=>u(n=>({...n,[e.key]:t.target.checked})),className:Z.blockCheck}),(0,j.jsx)(`span`,{children:e.icon}),(0,j.jsx)(`span`,{children:e.label})]},e.key))]}),l.auth&&(0,j.jsxs)(`div`,{className:Z.panel,children:[(0,j.jsxs)(`div`,{className:Z.panelHeader,children:[(0,j.jsx)(`div`,{className:Z.panelTitle,children:`Campi Auth`}),(0,j.jsx)(`button`,{className:Z.addBtn,onClick:()=>f(e=>[...e,{label:`New field`,type:`text`,required:!1}]),children:`+ Campo`})]}),d.map((e,t)=>(0,j.jsxs)(`div`,{className:Z.authField,children:[(0,j.jsx)(`input`,{value:e.label,onChange:e=>f(n=>n.map((n,r)=>r===t?{...n,label:e.target.value}:n)),className:Z.authFieldInput}),(0,j.jsx)(`select`,{value:e.type,onChange:e=>f(n=>n.map((n,r)=>r===t?{...n,type:e.target.value}:n)),className:Z.authFieldSelect,children:[`text`,`email`,`password`,`tel`,`date`,`number`].map(e=>(0,j.jsx)(`option`,{value:e,children:e},e))}),(0,j.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:Z.authFieldReq}),(0,j.jsx)(`button`,{onClick:()=>f(e=>e.filter((e,n)=>n!==t)),className:Z.removeFieldBtn,children:`×`})]},t))]}),(0,j.jsxs)(`div`,{className:Z.panel,children:[(0,j.jsxs)(`div`,{className:Z.panelHeader,children:[(0,j.jsx)(`div`,{className:Z.panelTitle,children:`🗂 Contesto AI`}),(0,j.jsx)(`button`,{className:Z.addBtn,onClick:()=>Se({mode:`new`,idx:null,name:``,content:``,type:`skill`,generating:!1}),children:`+ Skill`})]}),ve.length>0?(0,j.jsx)(`div`,{className:Z.skillsList,children:ve.map((e,t)=>(0,j.jsxs)(`div`,{className:Z.skillRow,children:[(0,j.jsx)(`span`,{className:Z.skillIcon,children:pn(e.type)}),(0,j.jsx)(`span`,{className:Z.skillName,title:e.name,children:e.name}),(0,j.jsx)(`span`,{className:`${Z.skillBadge} ${Z[`skillBadge_`+e.type]}`,children:e.type}),!e.content&&e.type!==`log`&&(0,j.jsx)(`span`,{className:Z.skillEmpty,children:`⚠`}),(0,j.jsx)(`button`,{className:Z.skillBtn,onClick:()=>Se({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,j.jsx)(`button`,{className:Z.skillBtn,onClick:()=>xt(t),children:`🗑`}),e.type===`log`&&(0,j.jsx)(`button`,{className:Z.skillBtn,onClick:()=>bt(t),children:`🗑`})]},t))}):(0,j.jsx)(`div`,{className:Z.skillsEmpty,children:I?`Nessun file di contesto. Clicca "+ Skill" per aggiungerne uno.`:`Crea o carica un progetto per i file di contesto.`})]}),Ce.length>0&&(0,j.jsxs)(`div`,{className:Z.panel,children:[(0,j.jsx)(`div`,{className:Z.panelTitle,children:`💾 Snapshot`}),Ce.slice(0,5).map(e=>{let t=e.ts.replace(`T`,` `).slice(0,16);return(0,j.jsxs)(`div`,{className:Z.snapshotRow,children:[(0,j.jsx)(`span`,{className:Z.snapshotTs,children:t}),(0,j.jsxs)(`span`,{className:Z.snapshotCount,children:[e.fileCount,`f`]}),(0,j.jsx)(`button`,{className:Z.snapshotBtn,onClick:()=>ut(e.ts),children:`↺`})]},e.ts)})]}),w&&(0,j.jsx)(`div`,{className:Z.genStatus,children:`⏳ Generazione...`}),E&&(0,j.jsxs)(`div`,{className:Z.repairStatus,children:[(0,j.jsx)(`div`,{className:Z.repairStatusTitle,children:`🔧 Correzione automatica...`}),(0,j.jsxs)(`div`,{className:Z.repairStatusProg,children:[D,` / `,ne,` file`]}),(0,j.jsx)(`div`,{className:Z.repairStatusFile,children:re})]}),p.length>0&&!w&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{className:Z.actionRow,children:[(0,j.jsx)(`button`,{className:Z.actionBtn,onClick:vt,children:`⬇ ZIP`}),(0,j.jsx)(`button`,{className:Z.actionBtnIcon,title:`Syntax check`,onClick:dt,children:`✅`}),(0,j.jsx)(`button`,{className:`${Z.actionBtnIcon} ${we?Z.actionBtnActive:``}`,title:`Grep`,onClick:()=>Te(!we),children:`🔍`}),(0,j.jsx)(`button`,{className:Z.actionBtnIcon,title:`Snapshot`,onClick:lt,children:`💾`})]}),p.some(e=>e._error||e._syntaxError)&&!E&&(0,j.jsx)(`button`,{className:Z.repairBtn,onClick:ft,children:`🔧 Correggi tutti i file rossi`}),(0,j.jsx)(`button`,{className:Z.sandboxBtn,onClick:()=>{a?ht(a):i(`preview`)},children:Pe?`⏳ Starting...`:Me?`🌐 Sandbox Live`:`▶ Sandbox`}),se&&(0,j.jsxs)(`div`,{className:Z.statsBar,children:[(0,j.jsxs)(`span`,{children:[`⏱ `,se.seconds>=60?`${Math.floor(se.seconds/60)}m ${se.seconds%60}s`:`${se.seconds}s`]}),(0,j.jsxs)(`span`,{children:[`↑ `,se.tokIn.toLocaleString(),` tok`]}),(0,j.jsxs)(`span`,{children:[`↓ `,se.tokOut.toLocaleString(),` tok`]}),(0,j.jsxs)(`span`,{children:[`📄 `,se.files,` file`]})]})]})]}),(0,j.jsxs)(`div`,{className:Z.rightPanel,children:[(0,j.jsxs)(`div`,{className:Z.rightTabBar,children:[(0,j.jsx)(`button`,{className:`${Z.rightTab} ${r===`preview`?``:Z.rightTabActive}`,onClick:()=>i(`files`),children:`📄 File`}),(0,j.jsx)(`button`,{className:`${Z.rightTab} ${r===`preview`?Z.rightTabActive:``}`,onClick:()=>i(`preview`),children:`🌐 Sandbox`})]}),E&&(0,j.jsxs)(`div`,{className:Z.repairBar,children:[(0,j.jsxs)(`div`,{className:Z.repairBarRow,children:[(0,j.jsx)(`span`,{className:Z.repairBarIcon,children:`🔧`}),(0,j.jsx)(`span`,{className:Z.repairBarLabel,children:`Auto-fix`}),(0,j.jsx)(`span`,{className:Z.repairBarFile,children:re}),(0,j.jsxs)(`span`,{className:Z.repairBarCounter,children:[D,` / `,ne]}),(0,j.jsx)(`span`,{className:Z.repairBarTime,children:We}),(0,j.jsx)(`button`,{className:Z.stopBtn,onClick:st,children:`⏹ Stop`})]}),(0,j.jsx)(`div`,{className:Z.progressTrack,children:(0,j.jsx)(`div`,{className:Z.repairProgress,style:{width:ne>0?`${Math.round(D/ne*100)}%`:`0%`}})})]}),w&&(0,j.jsxs)(`div`,{className:Z.genBar,children:[(0,j.jsxs)(`div`,{className:Z.genBarRow,children:[(0,j.jsx)(`span`,{className:Z.genBarRobot,children:`🤖`}),(0,j.jsx)(`span`,{className:Z.genBarLabel,children:N.total===0?`Pianificazione...`:`Generazione`}),(0,j.jsx)(`span`,{className:Z.genBarFile,children:N.name.split(`,`)[0].trim()}),(0,j.jsx)(`span`,{className:Z.genBarCounter,children:N.total>0?`${N.fi} / ${N.total}`:``}),(0,j.jsx)(`span`,{className:Z.genBarCounter,children:ae.tokIn+ae.tokOut>0?`↑${et(ae.tokIn)} ↓${et(ae.tokOut)}`:``}),(0,j.jsx)(`span`,{className:Z.genBarTime,children:He}),(0,j.jsxs)(`span`,{className:Z.genDots,children:[(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot1}`}),(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot2}`}),(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot3}`})]})]}),(0,j.jsx)(`div`,{className:Z.progressTrack,children:(0,j.jsx)(`div`,{className:Z.genProgress,style:{width:N.total>0?`${Math.round(N.fi/N.total*100)}%`:`0%`}})})]}),r===`preview`?(0,j.jsxs)(`div`,{className:Z.sandboxWrap,children:[Ie.length>0&&(0,j.jsxs)(`div`,{className:`${Z.sandboxConsole} ${ze?``:Z.sandboxConsoleCollapsed}`,children:[(0,j.jsxs)(`div`,{className:Z.sandboxConsoleHeader,onClick:()=>Be(!ze),children:[(0,j.jsxs)(`span`,{className:Z.sandboxConsoleTitle,children:[Pe?`⏳`:Le?`❌`:Me?`✅`:`🌐`,` Console`]}),Me&&(0,j.jsxs)(`span`,{className:Z.sandboxConsolePort,children:[`:`,Me]}),Pe&&(0,j.jsxs)(`span`,{className:Z.sandboxConsoleDots,children:[(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot1}`}),(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot2}`}),(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot3}`})]}),(0,j.jsx)(`span`,{className:Z.sandboxConsoleToggle,children:ze?`▼`:`▶`}),Me&&(0,j.jsx)(`button`,{className:Z.sandboxReloadBtn,onClick:e=>{e.stopPropagation();let t=document.querySelector(`iframe[title="WebCraft Sandbox"]`);t&&(t.src=t.src)},children:`↻`}),Me&&(0,j.jsx)(`button`,{className:Z.sandboxStopBtn,onClick:e=>{e.stopPropagation(),fetch(`/api/studio/webcraft/sandbox`,{method:`DELETE`}),Ne(null),B([])},children:`⏹`})]}),ze&&(0,j.jsx)(`div`,{className:Z.sandboxConsoleBody,ref:Ve,children:Ie.map((e,t)=>(0,j.jsx)(`div`,{className:`${Z.sandboxLogLine} ${e.includes(`❌`)||e.includes(`💥`)?Z.sandboxLogError:e.includes(`⚠`)?Z.sandboxLogWarn:e.includes(`✅`)?Z.sandboxLogOk:e.includes(`🔌`)||e.includes(`📦`)||e.includes(`🚀`)||e.includes(`🔧`)||e.includes(`🧹`)?Z.sandboxLogPhase:``}`,children:e},t))})]}),Me?(0,j.jsx)(`iframe`,{src:`http://127.0.0.1:${Me}`,className:Z.sandboxFrame,title:`WebCraft Sandbox`,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups`}):(0,j.jsxs)(`div`,{className:Z.sandboxEmpty,children:[(0,j.jsx)(`span`,{style:{fontSize:40},children:Pe?`⏳`:Le?`❌`:`🌐`}),(0,j.jsx)(`span`,{style:{fontWeight:600},children:Pe?`Avvio sandbox in corso...`:Le?`Errore sandbox`:`Sandbox`}),Le&&(0,j.jsx)(`span`,{style:{fontSize:11,maxWidth:400,textAlign:`center`},children:Le}),!Pe&&(0,j.jsxs)(`button`,{className:Z.sandboxStartBtn,onClick:()=>{a&&ht(a)},children:[`▶ `,Le?`Riprova`:`Avvia Sandbox`]})]})]}):(0,j.jsx)(`div`,{className:Z.codeArea,children:p.length===0&&w?(0,j.jsx)(`div`,{className:Z.noFiles,children:(0,j.jsxs)(`div`,{className:Z.noFilesHero,children:[(0,j.jsx)(`span`,{className:Z.noFilesIcon,children:`⏳`}),(0,j.jsx)(`span`,{className:Z.noFilesTitle,children:`Pianificazione...`}),(0,j.jsx)(`span`,{className:Z.noFilesTagline,children:N.name||`Analisi della struttura del progetto in corso`})]})}):p.length===0?(0,j.jsxs)(`div`,{className:Z.noFiles,children:[(0,j.jsxs)(`div`,{className:Z.noFilesHero,children:[(0,j.jsx)(`span`,{className:Z.noFilesIcon,children:`🔨`}),(0,j.jsx)(`span`,{className:Z.noFilesTitle,children:`WebCraft`}),(0,j.jsx)(`span`,{className:Z.noFilesTagline,children:`Genera progetti web completi con AI`})]}),(0,j.jsxs)(`div`,{className:Z.noFilesSteps,children:[(0,j.jsxs)(`div`,{className:Z.noFilesStep,children:[(0,j.jsx)(`span`,{className:Z.noFilesStepNum,children:`1`}),(0,j.jsx)(`span`,{children:`Scegli un esempio o scrivi una descrizione nel box in basso`})]}),(0,j.jsxs)(`div`,{className:Z.noFilesStep,children:[(0,j.jsx)(`span`,{className:Z.noFilesStepNum,children:`2`}),(0,j.jsxs)(`span`,{children:[`Premi `,(0,j.jsx)(`strong`,{children:`▶ Genera`}),` — l'AI crea tutti i file del progetto`]})]}),(0,j.jsxs)(`div`,{className:Z.noFilesStep,children:[(0,j.jsx)(`span`,{className:Z.noFilesStepNum,children:`3`}),(0,j.jsx)(`span`,{children:`Chiedi modifiche in chat, scarica lo ZIP o avvia il Sandbox`})]})]}),(0,j.jsxs)(`div`,{className:Z.noFilesExamplesHint,children:[`💡 Prova: `,(0,j.jsx)(`button`,{className:Z.noFilesExampleBtn,onClick:()=>{let e=cn[0];o(e.name),c(e.desc),de(e.desc)},children:`MySaaS`}),(0,j.jsx)(`button`,{className:Z.noFilesExampleBtn,onClick:()=>{let e=cn[1];o(e.name),c(e.desc),de(e.desc)},children:`MyShop`}),(0,j.jsx)(`button`,{className:Z.noFilesExampleBtn,onClick:()=>{let e=cn[3];o(e.name),c(e.desc),de(e.desc)},children:`MyPortfolio`})]})]}):(0,j.jsxs)(`div`,{className:Z.codeLayout,children:[(0,j.jsx)(`div`,{className:Z.ideTabBar,children:p.map((e,t)=>{let n=e._error||!!e._syntaxError,r=t===h;return(0,j.jsxs)(`button`,{className:`${Z.ideTab} ${r?Z.ideTabActive:``} ${n?Z.ideTabError:``} ${e._pending?Z.ideTabPending:``}`,onClick:()=>{g(t),x(null)},title:e.name,children:[(0,j.jsx)(`span`,{className:Z.ideTabIcon,children:e._pending?`⌛`:n?`⚠`:dn(e.name)}),(0,j.jsx)(`span`,{className:Z.ideTabName,children:e.name.split(`/`).pop()}),n&&(0,j.jsx)(`span`,{className:Z.ideTabDot})]},t)})}),S&&(0,j.jsxs)(`div`,{className:Z.diffOverlay,children:[(0,j.jsxs)(`div`,{className:Z.diffOverlayHeader,children:[(0,j.jsxs)(`span`,{children:[`✏ Modifica proposta — `,(0,j.jsx)(`strong`,{children:S.file})]}),(0,j.jsxs)(`div`,{className:Z.diffOverlayActions,children:[(0,j.jsx)(`button`,{className:Z.diffAcceptBtn,onClick:()=>{m(e=>e.map(e=>e.name===S.file?{...e,content:S.after}:e)),C(null)},children:`✓ Accetta`}),(0,j.jsx)(`button`,{className:Z.diffRejectBtn,onClick:()=>C(null),children:`✕ Rifiuta`})]})]}),(0,j.jsxs)(`div`,{className:Z.diffOverlayBody,children:[S.before.split(`
689
689
  `).map((e,t)=>e===(S.after.split(`
690
690
  `)[t]??``)?(0,j.jsxs)(`div`,{className:Z.diffSame,children:[`\xA0`,e||` `]},t):(0,j.jsxs)(`div`,{className:Z.diffRem,children:[`- `,e]},`r${t}`)),S.after.split(`
691
691
  `).map((e,t)=>e===(S.before.split(`
692
- `)[t]??``)?null:(0,j.jsxs)(`div`,{className:Z.diffAdd,children:[`+ `,e]},`a${t}`))]})]}),(0,j.jsxs)(`div`,{className:Z.codeRow,children:[(0,j.jsx)(`div`,{className:Z.codeEditorWrap,children:Tt&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{className:Z.codeHeader,children:[(0,j.jsx)(`span`,{className:Z.codeFileIcon,children:dn(Tt.name)}),(0,j.jsx)(`span`,{className:Z.codeFileName,children:Tt.name}),Tt.content&&!Tt._error&&(0,j.jsxs)(`span`,{className:Z.codeFileMeta,children:[Tt.content.split(`
693
- `).length,` righe · `,fn(Tt.content)]}),!Tt._pending&&!Tt._error&&!w&&(0,j.jsx)(`button`,{className:`${Z.editToggleBtn} ${b===null?``:Z.editToggleBtnActive}`,onClick:()=>{b===null?x(Tt.content):(m(e=>e.map((e,t)=>t===h?{...e,content:b}:e)),x(null))},children:b===null?`✏ Modifica`:`💾 Salva`})]}),Tt._error&&(0,j.jsx)(`div`,{className:Z.fileError,children:`⚠ Generazione fallita — chiedi al modello di rigenerare questo file`}),Tt._syntaxError&&!Tt._error&&(0,j.jsxs)(`div`,{className:Z.fileSyntaxError,children:[`⚠ Syntax error: `,Tt._syntaxError]}),b===null?(0,j.jsxs)(`pre`,{className:`${Z.code} ${Tt._error?Z.codeError:Tt._syntaxError?Z.codeSyntaxError:``}`,children:[w&&v!==null?v:Tt.content,(Tt._pending||w&&v!==null)&&(0,j.jsx)(`span`,{className:Z.genCursor,children:`▋`})]}):(0,j.jsx)(`textarea`,{className:Z.codeEditor,value:b,onChange:e=>x(e.target.value),spellCheck:!1})]})}),(0,j.jsxs)(`div`,{className:Z.fileSidebar,children:[(0,j.jsxs)(`div`,{className:Z.fileSidebarHeader,children:[p.length,` file`]}),p.map((e,t)=>{let n=e._error||!!e._syntaxError,r=t===h;return(0,j.jsxs)(`button`,{className:`${Z.fileTab} ${r?Z.fileTabActive:``} ${n?Z.fileTabError:``}`,onClick:()=>{g(t),x(null),y(null)},children:[(0,j.jsxs)(`div`,{className:Z.fileTabRow,children:[(0,j.jsx)(`span`,{className:Z.fileTabIcon,children:e._pending?`⌛`:n?`⚠`:dn(e.name)}),(0,j.jsx)(`span`,{className:Z.fileTabName,children:e.name.split(`/`).pop()}),e.content&&!e._pending&&(0,j.jsx)(`span`,{className:Z.fileTabSize,children:fn(e.content)})]}),(0,j.jsx)(`div`,{className:Z.fileTabDir,children:e.name.includes(`/`)?e.name:`./${e.name}`}),e.content&&!e._pending&&(0,j.jsxs)(`div`,{className:Z.fileTabTokens,children:[`~`,Math.ceil(e.content.length/4),` tok`]})]},t)})]})]})]})})]})]})]})}),ge&&t!==`projects`&&(0,j.jsxs)(`div`,{className:Z.planBanner,children:[(0,j.jsx)(`div`,{className:Z.planTitle,children:`📌 Piano proposto — approva per eseguire`}),(0,j.jsx)(`pre`,{className:Z.planText,children:ge.plan}),(0,j.jsxs)(`div`,{className:Z.planActions,children:[(0,j.jsx)(`button`,{className:Z.planApprove,onClick:St,children:`✓ Esegui`}),(0,j.jsx)(`button`,{className:Z.planReject,onClick:()=>_e(null),children:`✕ Annulla`})]})]}),we&&t!==`projects`&&(0,j.jsxs)(`div`,{className:Z.grepPanel,children:[(0,j.jsxs)(`div`,{className:Z.grepRow,children:[(0,j.jsx)(`input`,{className:Z.grepInput,value:Ee,onChange:e=>R(e.target.value),onKeyDown:e=>e.key===`Enter`&&ht(),placeholder:`Cerca nel codice...`}),(0,j.jsx)(`button`,{className:Z.grepBtn,onClick:ht,children:`🔍`}),(0,j.jsx)(`button`,{className:Z.grepClose,onClick:()=>Te(!1),children:`×`})]}),z.length>0&&(0,j.jsxs)(`div`,{className:Z.grepCount,children:[z.length,` risultati`]}),(0,j.jsx)(`div`,{className:Z.grepResults,children:z.length===0?(0,j.jsx)(`div`,{className:Z.grepEmpty,children:`Nessun risultato.`}):z.map((e,t)=>(0,j.jsxs)(`div`,{className:Z.grepMatch,onClick:()=>gt(e.file),children:[(0,j.jsxs)(`span`,{className:Z.grepMatchFile,children:[e.file,`:`,e.lineNum]}),(0,j.jsx)(`pre`,{className:Z.grepMatchLine,children:e.line})]},t))})]}),Oe.length>0&&t!==`projects`&&(0,j.jsxs)(`div`,{className:Z.diffPanel,children:[(0,j.jsxs)(`div`,{className:Z.diffHeader,children:[(0,j.jsxs)(`span`,{children:[`🔌 Diff — `,Oe.length,` file modificati`]}),(0,j.jsx)(`button`,{className:Z.diffClose,onClick:()=>ke([]),children:`✕ Chiudi`})]}),Oe.map((e,t)=>{let n=e.after.split(`
692
+ `)[t]??``)?null:(0,j.jsxs)(`div`,{className:Z.diffAdd,children:[`+ `,e]},`a${t}`))]})]}),(0,j.jsxs)(`div`,{className:Z.codeRow,children:[(0,j.jsx)(`div`,{className:Z.codeEditorWrap,children:Dt&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`div`,{className:Z.codeHeader,children:[(0,j.jsx)(`span`,{className:Z.codeFileIcon,children:dn(Dt.name)}),(0,j.jsx)(`span`,{className:Z.codeFileName,children:Dt.name}),Dt.content&&!Dt._error&&(0,j.jsxs)(`span`,{className:Z.codeFileMeta,children:[Dt.content.split(`
693
+ `).length,` righe · `,fn(Dt.content)]}),!Dt._pending&&!Dt._error&&!w&&(0,j.jsx)(`button`,{className:`${Z.editToggleBtn} ${b===null?``:Z.editToggleBtnActive}`,onClick:()=>{b===null?x(Dt.content):(m(e=>e.map((e,t)=>t===h?{...e,content:b}:e)),x(null))},children:b===null?`✏ Modifica`:`💾 Salva`})]}),Dt._error&&(0,j.jsx)(`div`,{className:Z.fileError,children:`⚠ Generazione fallita — chiedi al modello di rigenerare questo file`}),Dt._syntaxError&&!Dt._error&&(0,j.jsxs)(`div`,{className:Z.fileSyntaxError,children:[`⚠ Syntax error: `,Dt._syntaxError]}),b===null?(0,j.jsxs)(`pre`,{className:`${Z.code} ${Dt._error?Z.codeError:Dt._syntaxError?Z.codeSyntaxError:``}`,children:[w&&v!==null?v:Dt.content,(Dt._pending||w&&v!==null)&&(0,j.jsx)(`span`,{className:Z.genCursor,children:`▋`})]}):(0,j.jsx)(`textarea`,{className:Z.codeEditor,value:b,onChange:e=>x(e.target.value),spellCheck:!1})]})}),(0,j.jsxs)(`div`,{className:Z.fileSidebar,children:[(0,j.jsxs)(`div`,{className:Z.fileSidebarHeader,children:[p.length,` file`]}),p.map((e,t)=>{let n=e._error||!!e._syntaxError,r=t===h;return(0,j.jsxs)(`button`,{className:`${Z.fileTab} ${r?Z.fileTabActive:``} ${n?Z.fileTabError:``}`,onClick:()=>{g(t),x(null),y(null)},children:[(0,j.jsxs)(`div`,{className:Z.fileTabRow,children:[(0,j.jsx)(`span`,{className:Z.fileTabIcon,children:e._pending?`⌛`:n?`⚠`:dn(e.name)}),(0,j.jsx)(`span`,{className:Z.fileTabName,children:e.name.split(`/`).pop()}),e.content&&!e._pending&&(0,j.jsx)(`span`,{className:Z.fileTabSize,children:fn(e.content)})]}),(0,j.jsx)(`div`,{className:Z.fileTabDir,children:e.name.includes(`/`)?e.name:`./${e.name}`}),e.content&&!e._pending&&(0,j.jsxs)(`div`,{className:Z.fileTabTokens,children:[`~`,Math.ceil(e.content.length/4),` tok`]})]},t)})]})]})]})})]})]})]})}),ge&&t!==`projects`&&(0,j.jsxs)(`div`,{className:Z.planBanner,children:[(0,j.jsx)(`div`,{className:Z.planTitle,children:`📌 Piano proposto — approva per eseguire`}),(0,j.jsx)(`pre`,{className:Z.planText,children:ge.plan}),(0,j.jsxs)(`div`,{className:Z.planActions,children:[(0,j.jsx)(`button`,{className:Z.planApprove,onClick:wt,children:`✓ Esegui`}),(0,j.jsx)(`button`,{className:Z.planReject,onClick:()=>_e(null),children:`✕ Annulla`})]})]}),we&&t!==`projects`&&(0,j.jsxs)(`div`,{className:Z.grepPanel,children:[(0,j.jsxs)(`div`,{className:Z.grepRow,children:[(0,j.jsx)(`input`,{className:Z.grepInput,value:Ee,onChange:e=>R(e.target.value),onKeyDown:e=>e.key===`Enter`&&H(),placeholder:`Cerca nel codice...`}),(0,j.jsx)(`button`,{className:Z.grepBtn,onClick:H,children:`🔍`}),(0,j.jsx)(`button`,{className:Z.grepClose,onClick:()=>Te(!1),children:`×`})]}),z.length>0&&(0,j.jsxs)(`div`,{className:Z.grepCount,children:[z.length,` risultati`]}),(0,j.jsx)(`div`,{className:Z.grepResults,children:z.length===0?(0,j.jsx)(`div`,{className:Z.grepEmpty,children:`Nessun risultato.`}):z.map((e,t)=>(0,j.jsxs)(`div`,{className:Z.grepMatch,onClick:()=>_t(e.file),children:[(0,j.jsxs)(`span`,{className:Z.grepMatchFile,children:[e.file,`:`,e.lineNum]}),(0,j.jsx)(`pre`,{className:Z.grepMatchLine,children:e.line})]},t))})]}),Oe.length>0&&t!==`projects`&&(0,j.jsxs)(`div`,{className:Z.diffPanel,children:[(0,j.jsxs)(`div`,{className:Z.diffHeader,children:[(0,j.jsxs)(`span`,{children:[`🔌 Diff — `,Oe.length,` file modificati`]}),(0,j.jsx)(`button`,{className:Z.diffClose,onClick:()=>ke([]),children:`✕ Chiudi`})]}),Oe.map((e,t)=>{let n=e.after.split(`
694
694
  `).length-e.before.split(`
695
- `).length;return(0,j.jsxs)(`details`,{open:!0,className:Z.diffFile,children:[(0,j.jsxs)(`summary`,{className:Z.diffSummary,children:[(0,j.jsx)(`span`,{className:Z.diffArrow,children:`▲`}),(0,j.jsx)(`span`,{className:Z.diffFileName,children:e.file}),(0,j.jsxs)(`span`,{className:n>=0?Z.diffAdded:Z.diffRemoved,children:[n>=0?`+`:``,n,` linee`]})]}),(0,j.jsx)(`div`,{className:Z.diffContent,children:(0,j.jsx)(hn,{before:e.before,after:e.after})})]},t)})]}),t!==`projects`&&(0,j.jsxs)(`div`,{className:Z.chatPanel,children:[(0,j.jsxs)(`div`,{className:Z.chatMessages,ref:Je,children:[F.length===0&&wt&&(0,j.jsx)(`div`,{className:Z.chatWelcome,children:`🤖 Pronto! Dimmi cosa vuoi modificare o migliorare nel progetto.`}),F.map((e,t)=>(0,j.jsxs)(`div`,{className:e.role===`user`?Z.chatUser:e.role===`system`?Z.chatSystem:Z.chatAgent,children:[e.role===`user`&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:Z.chatUserBubble,children:e.text}),e.attachments&&e.attachments.length>0&&(0,j.jsx)(`div`,{className:Z.chatAttachPreviews,children:e.attachments.map((e,t)=>(0,j.jsxs)(`span`,{className:Z.chatAttachBadge,children:[`📎 `,e.name]},t))})]}),e.role===`system`&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:Z.chatSystemBubble,children:e.text}),e.syntaxErrors?.map((e,t)=>(0,j.jsxs)(`div`,{className:Z.chatSyntaxErr,children:[`✕ `,e.file,`: `,e.error]},t))]}),e.role===`agent`&&(0,j.jsxs)(`div`,{className:Z.chatAgentCard,children:[(0,j.jsxs)(`div`,{className:Z.chatAgentHeader,children:[(0,j.jsx)(`span`,{className:Z.chatAgentRobot,children:`🤖`}),(0,j.jsx)(`span`,{className:Z.chatAgentLabel,children:`WebCraft Agent`})]}),(0,j.jsx)(`div`,{className:Z.chatAgentText,children:e.text.replace(/<tool>[\s\S]*?<\/tool>/g,``).trim()}),e.tools&&e.tools.filter(e=>(e.op===`edit`||e.op===`write`)&&e.result===`ok`&&(e.oldSnippet||e.newSnippet)).map((e,t)=>(0,j.jsxs)(`div`,{className:Z.diffInline,children:[(0,j.jsxs)(`div`,{className:Z.diffInlineHeader,children:[`✏ `,e.path]}),e.oldSnippet?.split(`
695
+ `).length;return(0,j.jsxs)(`details`,{open:!0,className:Z.diffFile,children:[(0,j.jsxs)(`summary`,{className:Z.diffSummary,children:[(0,j.jsx)(`span`,{className:Z.diffArrow,children:`▲`}),(0,j.jsx)(`span`,{className:Z.diffFileName,children:e.file}),(0,j.jsxs)(`span`,{className:n>=0?Z.diffAdded:Z.diffRemoved,children:[n>=0?`+`:``,n,` linee`]})]}),(0,j.jsx)(`div`,{className:Z.diffContent,children:(0,j.jsx)(hn,{before:e.before,after:e.after})})]},t)})]}),t!==`projects`&&(0,j.jsxs)(`div`,{className:Z.chatPanel,children:[(0,j.jsxs)(`div`,{className:Z.chatMessages,ref:Xe,children:[F.length===0&&Et&&(0,j.jsx)(`div`,{className:Z.chatWelcome,children:`🤖 Pronto! Dimmi cosa vuoi modificare o migliorare nel progetto.`}),F.map((e,t)=>(0,j.jsxs)(`div`,{className:e.role===`user`?Z.chatUser:e.role===`system`?Z.chatSystem:Z.chatAgent,children:[e.role===`user`&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:Z.chatUserBubble,children:e.text}),e.attachments&&e.attachments.length>0&&(0,j.jsx)(`div`,{className:Z.chatAttachPreviews,children:e.attachments.map((e,t)=>(0,j.jsxs)(`span`,{className:Z.chatAttachBadge,children:[`📎 `,e.name]},t))})]}),e.role===`system`&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:Z.chatSystemBubble,children:e.text}),e.syntaxErrors?.map((e,t)=>(0,j.jsxs)(`div`,{className:Z.chatSyntaxErr,children:[`✕ `,e.file,`: `,e.error]},t))]}),e.role===`agent`&&(0,j.jsxs)(`div`,{className:Z.chatAgentCard,children:[(0,j.jsxs)(`div`,{className:Z.chatAgentHeader,children:[(0,j.jsx)(`span`,{className:Z.chatAgentRobot,children:`🤖`}),(0,j.jsx)(`span`,{className:Z.chatAgentLabel,children:`WebCraft Agent`})]}),(0,j.jsx)(`div`,{className:Z.chatAgentText,children:e.text.replace(/<tool>[\s\S]*?<\/tool>/g,``).trim()}),e.tools&&e.tools.filter(e=>(e.op===`edit`||e.op===`write`)&&e.result===`ok`&&(e.oldSnippet||e.newSnippet)).map((e,t)=>(0,j.jsxs)(`div`,{className:Z.diffInline,children:[(0,j.jsxs)(`div`,{className:Z.diffInlineHeader,children:[`✏ `,e.path]}),e.oldSnippet?.split(`
696
696
  `).map((e,t)=>(0,j.jsxs)(`div`,{className:Z.diffRemLine,children:[`- `,e]},`r${t}`)),e.newSnippet?.split(`
697
- `).map((e,t)=>(0,j.jsxs)(`div`,{className:Z.diffAddLine,children:[`+ `,e]},`a${t}`))]},t)),e.tools&&e.tools.length>0&&(0,j.jsx)(`div`,{className:Z.chatToolBadges,children:e.tools.map((e,t)=>(0,j.jsxs)(`span`,{className:`${Z.toolBadge} ${e.result===`ok`?Z.toolBadgeOk:Z.toolBadgeErr}`,children:[e.op===`edit`?`✏`:e.op===`write`?`+`:`👁`,` `,e.path]},t))})]})]},t)),fe&&(0,j.jsxs)(`div`,{className:Z.chatAgentCard,children:[(0,j.jsxs)(`div`,{className:Z.chatAgentHeader,children:[(0,j.jsx)(`span`,{className:Z.chatAgentRobotAnim,children:`🤖`}),(0,j.jsx)(`span`,{className:Z.chatAgentLabel,children:`WebCraft Agent`}),(0,j.jsxs)(`span`,{className:Z.chatRunningDots,children:[(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot1}`}),(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot2}`}),(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot3}`})]})]}),(0,j.jsx)(`div`,{className:Z.chatAgentText,children:(0,j.jsx)(`span`,{className:Z.cursor,children:`​`})})]})]}),me.length>0&&(0,j.jsx)(`div`,{className:Z.attachPreviews,children:me.map((e,t)=>(0,j.jsxs)(`span`,{className:Z.attachBadge,children:[`📎 `,e.name,(0,j.jsx)(`button`,{className:Z.removeAttachBtn,onClick:()=>he(e=>e.filter((e,n)=>n!==t)),children:`×`})]},t))}),wt?(0,j.jsxs)(`div`,{className:Z.projActiveRow,children:[`📄 `,(0,j.jsx)(`strong`,{className:Z.projActiveName,children:a}),` — scrivi per modificare o migliorare il progetto`]}):(0,j.jsxs)(`div`,{className:Z.projNameRow,children:[(0,j.jsx)(`span`,{className:Z.projNameLabel,children:`Nome progetto:`}),(0,j.jsx)(`input`,{className:Z.projNameInput,value:a,onChange:e=>o(e.target.value),placeholder:`MioProgetto`})]}),(0,j.jsxs)(`div`,{className:Z.chatInputRow,children:[(0,j.jsxs)(`label`,{className:Z.attachLabel,title:`Allega immagine o PDF`,children:[`📎`,(0,j.jsx)(`input`,{ref:Ye,type:`file`,multiple:!0,accept:`image/*,.pdf`,style:{display:`none`},onChange:e=>Ct(e.target.files)})]}),(0,j.jsx)(`textarea`,{className:Z.chatTextarea,value:ue,onChange:e=>de(e.target.value),placeholder:wt?`Parla con il tuo agente: chiedi correzioni, migliorie, nuove funzionalità...`:`Descrivi il progetto da creare, poi premi Genera...`,disabled:Et,onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),nt())},rows:4}),(0,j.jsxs)(`div`,{className:Z.chatSendCol,children:[(0,j.jsx)(`button`,{className:Z.chatSendBtn,onClick:nt,disabled:Et,children:w?`⏳`:wt?`▶`:`▶ Genera`}),Et&&(0,j.jsx)(`button`,{className:Z.chatStopBtn,onClick:at,children:`⏹ Stop`})]})]})]}),xe&&(0,j.jsx)(gn,{modal:xe,skills:ve,projectName:a,onClose:()=>Se(null),onSave:(e,t,n)=>_t(xe,e,t,n)})]})}function hn({before:e,after:t}){let n=e.split(`
697
+ `).map((e,t)=>(0,j.jsxs)(`div`,{className:Z.diffAddLine,children:[`+ `,e]},`a${t}`))]},t)),e.tools&&e.tools.length>0&&(0,j.jsx)(`div`,{className:Z.chatToolBadges,children:e.tools.map((e,t)=>(0,j.jsxs)(`span`,{className:`${Z.toolBadge} ${e.result===`ok`?Z.toolBadgeOk:Z.toolBadgeErr}`,children:[e.op===`edit`?`✏`:e.op===`write`?`+`:`👁`,` `,e.path]},t))})]})]},t)),fe&&(0,j.jsxs)(`div`,{className:Z.chatAgentCard,children:[(0,j.jsxs)(`div`,{className:Z.chatAgentHeader,children:[(0,j.jsx)(`span`,{className:Z.chatAgentRobotAnim,children:`🤖`}),(0,j.jsx)(`span`,{className:Z.chatAgentLabel,children:`WebCraft Agent`}),(0,j.jsxs)(`span`,{className:Z.chatRunningDots,children:[(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot1}`}),(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot2}`}),(0,j.jsx)(`span`,{className:`${Z.dot} ${Z.dot3}`})]})]}),(0,j.jsx)(`div`,{className:Z.chatAgentText,children:(0,j.jsx)(`span`,{className:Z.cursor,children:`​`})})]})]}),me.length>0&&(0,j.jsx)(`div`,{className:Z.attachPreviews,children:me.map((e,t)=>(0,j.jsxs)(`span`,{className:Z.attachBadge,children:[`📎 `,e.name,(0,j.jsx)(`button`,{className:Z.removeAttachBtn,onClick:()=>he(e=>e.filter((e,n)=>n!==t)),children:`×`})]},t))}),Et?(0,j.jsxs)(`div`,{className:Z.projActiveRow,children:[`📄 `,(0,j.jsx)(`strong`,{className:Z.projActiveName,children:a}),` — scrivi per modificare o migliorare il progetto`]}):(0,j.jsxs)(`div`,{className:Z.projNameRow,children:[(0,j.jsx)(`span`,{className:Z.projNameLabel,children:`Nome progetto:`}),(0,j.jsx)(`input`,{className:Z.projNameInput,value:a,onChange:e=>o(e.target.value),placeholder:`MioProgetto`})]}),(0,j.jsxs)(`div`,{className:Z.chatInputRow,children:[(0,j.jsxs)(`label`,{className:Z.attachLabel,title:`Allega immagine o PDF`,children:[`📎`,(0,j.jsx)(`input`,{ref:Ze,type:`file`,multiple:!0,accept:`image/*,.pdf`,style:{display:`none`},onChange:e=>Tt(e.target.files)})]}),(0,j.jsx)(`textarea`,{className:Z.chatTextarea,value:ue,onChange:e=>de(e.target.value),placeholder:Et?`Parla con il tuo agente: chiedi correzioni, migliorie, nuove funzionalità...`:`Descrivi il progetto da creare, poi premi Genera...`,disabled:Ot,onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),it())},rows:4}),(0,j.jsxs)(`div`,{className:Z.chatSendCol,children:[(0,j.jsx)(`button`,{className:Z.chatSendBtn,onClick:it,disabled:Ot,children:w?`⏳`:Et?`▶`:`▶ Genera`}),Ot&&(0,j.jsx)(`button`,{className:Z.chatStopBtn,onClick:st,children:`⏹ Stop`})]})]})]}),xe&&(0,j.jsx)(gn,{modal:xe,skills:ve,projectName:a,onClose:()=>Se(null),onSave:(e,t,n)=>yt(xe,e,t,n)})]})}function hn({before:e,after:t}){let n=e.split(`
698
698
  `),r=t.split(`
699
699
  `),i=[],a=0,o=0;for(;(a<n.length||o<r.length)&&(a>=n.length?i.push({type:`add`,text:r[o++]??``}):o>=r.length?i.push({type:`rem`,text:n[a++]??``}):n[a]===r[o]?(i.push({type:`same`,text:n[a++]??``}),o++):(i.push({type:`rem`,text:n[a++]??``}),i.push({type:`add`,text:r[o++]??``})),!(i.length>2e3)););return(0,j.jsx)(`div`,{style:{fontFamily:`var(--mono)`,fontSize:10},children:i.map((e,t)=>(0,j.jsxs)(`div`,{style:{padding:`1px 8px`,background:e.type===`add`?`#0a3a1a`:e.type===`rem`?`#3a0a0a`:`transparent`,color:e.type===`add`?`#4ade80`:e.type===`rem`?`#f87171`:`var(--dim)`,whiteSpace:`pre-wrap`,wordBreak:`break-all`},children:[e.type===`add`?`+`:e.type===`rem`?`-`:` `,e.text]},t))})}function gn({modal:e,skills:t,projectName:n,onClose:r,onSave:i}){let[a,o]=(0,_.useState)(e.name),[s,c]=(0,_.useState)(e.content),[l,u]=(0,_.useState)(e.type),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(!1),h=l===`skill`?6e3:4e3,g=s.length>h;async function v(){if(!d.trim())return;m(!0);let e={skill:`Sei un esperto di sviluppo web fullstack. Genera un file Markdown "skill" per il WebCraft Agent. Deve contenere istruzioni, pattern di codice, best practice e snippet pronti all uso come contesto persistente. Scrivi SOLO il contenuto Markdown, niente altro.`,memory:`Sei un assistente tecnico. Genera un file Markdown "memory" per il WebCraft Agent. Deve riassumere decisioni architetturali, preferenze dello sviluppatore e contesto generale del progetto. Scrivi SOLO il Markdown.`,provider:`Sei un esperto di prompt engineering. Genera un file Markdown con istruzioni specifiche per calibrare il comportamento del modello AI. Scrivi SOLO il Markdown.`},t=await k(`/api/studio/webcraft`,{system:e[l]??e.skill,user:`Progetto: ${n}\n\n${d}`,max_tokens:2048});t?.text&&(c(t.text),a||o(l===`memory`?`memory.md`:l===`provider`?`liara.md`:d.toLowerCase().replace(/[^a-z0-9]+/g,`-`).slice(0,30)+`.md`)),m(!1)}function y(){if(!a.trim()){alert(`Inserisci un nome per il file.`);return}let n=a.endsWith(`.md`)?a:a+`.md`;if((l===`memory`||l===`provider`)&&e.mode===`new`&&t.findIndex(e=>e.type===l)>=0){alert(`Esiste già un file di tipo "${l}". Modificalo direttamente.`);return}i(n,s,l)}return(0,j.jsx)(`div`,{className:Z.modalOverlay,onClick:e=>{e.target===e.currentTarget&&r()},children:(0,j.jsxs)(`div`,{className:Z.modal,children:[(0,j.jsxs)(`div`,{className:Z.modalHeader,children:[(0,j.jsxs)(`span`,{className:Z.modalTitle,children:[pn(l),` `,e.mode===`new`?`Nuovo file di contesto`:`Modifica ${e.name}`]}),(0,j.jsx)(`button`,{className:Z.modalClose,onClick:r,children:`×`})]}),(0,j.jsx)(`div`,{className:Z.modalBody,children:e.mode===`view`?(0,j.jsx)(`pre`,{className:Z.logView,children:s}):(0,j.jsxs)(j.Fragment,{children:[e.mode===`new`&&(0,j.jsxs)(`div`,{className:Z.modalRow,children:[(0,j.jsxs)(`div`,{className:Z.modalField,children:[(0,j.jsx)(`div`,{className:Z.modalLabel,children:`TIPO`}),(0,j.jsx)(`select`,{value:l,onChange:e=>{let t=e.target.value;u(t),t===`memory`?o(`memory.md`):t===`provider`&&o(`liara.md`)},className:Z.modalSelect,children:[`skill`,`memory`,`provider`].map(e=>{let n=(e===`memory`||e===`provider`)&&t.some(t=>t.type===e);return(0,j.jsxs)(`option`,{value:e,disabled:n,children:[e,n?` (esiste già)`:``]},e)})})]}),(0,j.jsxs)(`div`,{className:Z.modalField,style:{flex:2},children:[(0,j.jsx)(`div`,{className:Z.modalLabel,children:`NOME FILE`}),(0,j.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),placeholder:l===`memory`?`memory.md`:l===`provider`?`liara.md`:`nome-skill.md`,className:Z.modalInput})]})]}),(0,j.jsxs)(`div`,{className:Z.modalHint,children:[`💡 `,l===`skill`?`Istruzioni tecniche, snippet, pattern di codice specifici. Max ~6000 caratteri.`:l===`memory`?`Note persistenti sul progetto: decisioni architetturali, preferenze. Solo UN file. Max ~4000 caratteri.`:`Istruzioni specifiche per il modello AI (tono, formato, vincoli). Solo UN file. Max ~4000 caratteri.`]}),(0,j.jsxs)(`div`,{className:Z.modalAiBox,children:[(0,j.jsx)(`div`,{className:Z.modalLabel,children:`🤖 GENERA CON AI`}),(0,j.jsxs)(`div`,{className:Z.modalAiRow,children:[(0,j.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),rows:2,placeholder:`Descrivi cosa deve contenere questo file...`,className:Z.modalAiDesc}),(0,j.jsx)(`button`,{onClick:v,disabled:p,className:Z.modalAiBtn,children:p?`⏳ ...`:`▶ Genera`})]})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`div`,{className:Z.modalLabelRow,children:[(0,j.jsx)(`span`,{children:`CONTENUTO (markdown)`}),(0,j.jsxs)(`span`,{style:{color:g?`#e05050`:`var(--dim)`},children:[s.length,` car.`,g?` ⚠ Troppo lungo`:``]})]}),(0,j.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),rows:14,placeholder:`# Titolo
700
700
  Scrivi le istruzioni in Markdown...`,className:Z.modalContentArea,style:{borderColor:g?`#e05050`:`var(--border2)`}})]})]})}),(0,j.jsxs)(`div`,{className:Z.modalFooter,children:[(0,j.jsx)(`button`,{onClick:r,className:Z.modalCancelBtn,children:`Annulla`}),e.mode!==`view`&&(0,j.jsx)(`button`,{onClick:y,className:Z.modalSaveBtn,children:`✓ Salva`})]})]})})}var _n={root:`_root_x9yvu_1`,loading:`_loading_x9yvu_7`,empty:`_empty_x9yvu_18`,emptyIcon:`_emptyIcon_x9yvu_29`,emptyTitle:`_emptyTitle_x9yvu_30`,emptySub:`_emptySub_x9yvu_31`,generateBtn:`_generateBtn_x9yvu_33`,summary:`_summary_x9yvu_46`,sectionTitle:`_sectionTitle_x9yvu_57`,alertTitle:`_alertTitle_x9yvu_68`,actionCard:`_actionCard_x9yvu_70`,actionTime:`_actionTime_x9yvu_81`,actionText:`_actionText_x9yvu_89`,schedCard:`_schedCard_x9yvu_95`,schedTime:`_schedTime_x9yvu_106`,schedTitle:`_schedTitle_x9yvu_114`,alertCard:`_alertCard_x9yvu_119`,alertSev:`_alertSev_x9yvu_129`,alertAction:`_alertAction_x9yvu_135`,insight:`_insight_x9yvu_141`,regenRow:`_regenRow_x9yvu_148`,regenBtn:`_regenBtn_x9yvu_153`};function vn(){let e=P(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(!1),l=()=>{i(!0),c(!1),O(`/api/plan`).then(e=>{e?.plan?(n(e.plan),c(!1)):(n(null),c(!0)),i(!1)}).catch(()=>{i(!1),c(!0)})},u=async()=>{o(!0),i(!0),n(null);try{await k(`/api/plan/refresh`,{}),l()}catch{i(!1)}finally{o(!1)}};if((0,_.useEffect)(()=>{l()},[]),r)return(0,j.jsxs)(`div`,{className:_n.loading,children:[(0,j.jsx)(`div`,{className:`spinner`}),(0,j.jsx)(`div`,{children:a?`Generating plan with 5 agents...`:`Loading plan...`})]});if(s||!t)return(0,j.jsxs)(`div`,{className:_n.empty,children:[(0,j.jsx)(`div`,{className:_n.emptyIcon,children:`🗓️`}),(0,j.jsxs)(`div`,{className:_n.emptyTitle,children:[e(`plan.noplan`),` generated yet`]}),(0,j.jsx)(`div`,{className:_n.emptySub,children:`Generate a daily plan using your calendar, tasks, and emails.`}),(0,j.jsx)(`button`,{className:_n.generateBtn,onClick:u,children:e(`plan.generate`)})]});let d=e=>typeof e==`string`?e:e.description??e.message??e.action_required??`Alert`,f=e=>typeof e==`object`&&e.severity?` [${e.severity.toUpperCase()}]`:``,p=e=>typeof e==`object`&&e.action_required&&e.action_required!==d(e)?e.action_required:``,m=e=>typeof e==`string`?e:e.message??e.insight??``;return(0,j.jsxs)(`div`,{className:_n.root,children:[t.executive_summary&&(0,j.jsx)(`div`,{className:_n.summary,children:t.executive_summary}),t.priority_actions&&t.priority_actions.length>0&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:_n.sectionTitle,children:`Priority Actions`}),t.priority_actions.map((e,t)=>(0,j.jsxs)(`div`,{className:_n.actionCard,children:[e.time&&(0,j.jsx)(`span`,{className:_n.actionTime,children:e.time}),(0,j.jsx)(`span`,{className:_n.actionText,children:e.action})]},t))]}),t.schedule&&t.schedule.length>0&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:_n.sectionTitle,children:`Schedule`}),t.schedule.map((e,t)=>(0,j.jsxs)(`div`,{className:_n.schedCard,children:[(0,j.jsxs)(`span`,{className:_n.schedTime,children:[e.time_start,`–`,e.time_end]}),(0,j.jsx)(`span`,{className:_n.schedTitle,children:e.title})]},t))]}),t.security_alerts&&t.security_alerts.length>0&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:`${_n.sectionTitle} ${_n.alertTitle}`,children:`Security Alerts`}),t.security_alerts.map((e,t)=>(0,j.jsxs)(`div`,{className:_n.alertCard,children:[(0,j.jsxs)(`span`,{className:_n.alertSev,children:[`!`,f(e)]}),(0,j.jsx)(`span`,{children:d(e)}),p(e)&&(0,j.jsxs)(`div`,{className:_n.alertAction,children:[`Action: `,p(e)]})]},t))]}),t.insights&&t.insights.length>0&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:_n.sectionTitle,children:`Insights`}),t.insights.map((e,t)=>(0,j.jsxs)(`div`,{className:_n.insight,children:[`→ `,m(e)]},t))]}),(0,j.jsx)(`div`,{className:_n.regenRow,children:(0,j.jsx)(`button`,{className:_n.regenBtn,onClick:u,disabled:a,children:a?`Regenerating…`:`↺ Regenerate`})})]})}function yn(e){return e===`folder`?`📁`:e===`image`?`🖼`:e===`pdf`?`📕`:e===`video`?`🎬`:e===`audio`?`🎵`:e===`sheet`?`📊`:e===`slides`?`📽`:`📄`}function bn(){let e=P(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),l=(e=``)=>{i(!0),O(e?`/api/onedrive?q=${encodeURIComponent(e)}`:`/api/onedrive`).then(e=>{n(e??{files:[]}),i(!1)}).catch(()=>{o(`Could not load OneDrive. Run nha microsoft auth in the terminal to connect.`),i(!1)})};if((0,_.useEffect)(()=>{l()},[]),a)return(0,j.jsx)(`div`,{className:J.error,children:a});let u=t?.files??[],d=t?.quota;return(0,j.jsxs)(`div`,{className:J.root,children:[d&&(0,j.jsxs)(`div`,{className:J.quotaBar,children:[(0,j.jsxs)(`div`,{className:J.quotaText,children:[(0,j.jsxs)(`span`,{className:J.quotaUsed,children:[d.usage,` of `,d.limit,` used`]}),(0,j.jsxs)(`span`,{className:J.quotaPct,children:[d.percentUsed,`%`]})]}),(0,j.jsx)(`div`,{className:J.quotaTrack,children:(0,j.jsx)(`div`,{className:J.quotaFill,style:{width:`${Math.min(d.percentUsed,100)}%`,background:d.percentUsed>90?`var(--red)`:d.percentUsed>70?`var(--amber)`:`var(--cyan)`}})})]}),(0,j.jsxs)(`div`,{className:J.searchRow,children:[(0,j.jsx)(`input`,{className:J.searchInput,value:s,onChange:e=>c(e.target.value),placeholder:`Search OneDrive files…`,onKeyDown:e=>e.key===`Enter`&&l(s)}),(0,j.jsx)(`button`,{className:J.searchBtn,onClick:()=>l(s),children:`Search`})]}),r&&(0,j.jsxs)(`div`,{className:J.loading,children:[(0,j.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}),!r&&u.length===0&&(0,j.jsx)(`div`,{className:J.empty,children:e(`drive.noFiles`)}),(0,j.jsx)(`div`,{className:J.fileList,children:u.map(e=>(0,j.jsxs)(`div`,{className:J.fileRow,children:[(0,j.jsx)(`span`,{className:J.fileIcon,children:yn(e.type)}),(0,j.jsxs)(`div`,{className:J.fileInfo,children:[(0,j.jsx)(`div`,{className:J.fileName,children:e.name}),(0,j.jsxs)(`div`,{className:J.fileMeta,children:[e.modifiedTime?new Date(e.modifiedTime).toLocaleDateString():``,e.size?` · ${e.size}`:``]})]}),(0,j.jsx)(`div`,{className:J.fileBtns,children:e.webViewLink&&(0,j.jsx)(`a`,{className:J.openBtn,href:e.webViewLink,target:`_blank`,rel:`noreferrer`,children:`Open`})})]},e.id))})]})}var xn={root:`_root_1vbmp_1`,loading:`_loading_1vbmp_2`,error:`_error_1vbmp_3`,empty:`_empty_1vbmp_4`,addRow:`_addRow_1vbmp_6`,addInput:`_addInput_1vbmp_7`,addBtn:`_addBtn_1vbmp_8`,list:`_list_1vbmp_10`,taskRow:`_taskRow_1vbmp_11`,checkBtn:`_checkBtn_1vbmp_12`,taskInfo:`_taskInfo_1vbmp_14`,taskTitle:`_taskTitle_1vbmp_15`,taskDue:`_taskDue_1vbmp_16`,taskImp:`_taskImp_1vbmp_17`};function Sn(){let e=P(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),l=()=>{O(`/api/mstodo`).then(e=>{n(e?.tasks??[]),i(!1)}).catch(()=>{o(`Microsoft To Do requires Microsoft authentication. Run nha microsoft auth in the terminal.`),i(!1)})};(0,_.useEffect)(()=>{l()},[]);let u=()=>{let e=s.trim();e&&(c(``),k(`/api/mstodo`,{title:e}).then(e=>{e?.task&&l()}))},d=(e,t)=>{k(`/api/mstodo/${e}/complete`,{listId:t}).then(()=>l())};return r?(0,j.jsxs)(`div`,{className:xn.loading,children:[(0,j.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):a?(0,j.jsx)(`div`,{className:xn.error,children:a}):(0,j.jsxs)(`div`,{className:xn.root,children:[(0,j.jsxs)(`div`,{className:xn.addRow,children:[(0,j.jsx)(`input`,{className:xn.addInput,value:s,onChange:e=>c(e.target.value),placeholder:`Add a new task…`,onKeyDown:e=>e.key===`Enter`&&u()}),(0,j.jsx)(`button`,{className:xn.addBtn,onClick:u,children:`+ Add`})]}),t.length===0&&(0,j.jsx)(`div`,{className:xn.empty,children:`No active tasks`}),(0,j.jsx)(`div`,{className:xn.list,children:t.map(e=>{let t=e.importance===`high`?`var(--red)`:e.importance===`low`?`var(--dim)`:`var(--amber)`;return(0,j.jsxs)(`div`,{className:xn.taskRow,children:[(0,j.jsx)(`button`,{className:xn.checkBtn,onClick:()=>d(e.id,e.listId)}),(0,j.jsxs)(`div`,{className:xn.taskInfo,children:[(0,j.jsx)(`div`,{className:xn.taskTitle,children:e.title}),e.dueDate&&(0,j.jsxs)(`div`,{className:xn.taskDue,children:[`Due: `,e.dueDate.split(`T`)[0]]})]}),e.importance&&(0,j.jsx)(`span`,{className:xn.taskImp,style:{color:t},children:e.importance})]},e.id)})})]})}var Cn={root:`_root_1ag4s_1`,header:`_header_1ag4s_3`,title:`_title_1ag4s_4`,subtitle:`_subtitle_1ag4s_5`,controls:`_controls_1ag4s_7`,monitorRow:`_monitorRow_1ag4s_8`,label:`_label_1ag4s_9`,monitorBtn:`_monitorBtn_1ag4s_10`,monitorActive:`_monitorActive_1ag4s_11`,captureBtn:`_captureBtn_1ag4s_12`,analyzeSection:`_analyzeSection_1ag4s_15`,sectionTitle:`_sectionTitle_1ag4s_16`,presets:`_presets_1ag4s_17`,preset:`_preset_1ag4s_17`,presetActive:`_presetActive_1ag4s_20`,questionRow:`_questionRow_1ag4s_21`,questionInput:`_questionInput_1ag4s_22`,analyzeBtn:`_analyzeBtn_1ag4s_23`,error:`_error_1ag4s_26`,screenshotContainer:`_screenshotContainer_1ag4s_28`,screenshot:`_screenshot_1ag4s_28`,screenshotMeta:`_screenshotMeta_1ag4s_30`,analysis:`_analysis_1ag4s_32`,analysisTitle:`_analysisTitle_1ag4s_33`,analysisText:`_analysisText_1ag4s_34`,continueInChat:`_continueInChat_1ag4s_35`,history:`_history_1ag4s_37`,historyGrid:`_historyGrid_1ag4s_38`,historyItem:`_historyItem_1ag4s_39`,historyThumb:`_historyThumb_1ag4s_40`,historyMeta:`_historyMeta_1ag4s_41`,historyTs:`_historyTs_1ag4s_42`,historyQ:`_historyQ_1ag4s_43`,historyA:`_historyA_1ag4s_44`},wn=[`Describe exactly what you see on the screen`,`Identify any errors, warnings, or issues visible`,`What application is open and what is the user doing?`,`Summarize the content visible on screen and suggest next actions`,`Read and extract all visible text from the screen`,`Analyze the code visible on screen and identify bugs or improvements`,`What financial data or charts are visible? Summarize key numbers`,`Is there anything sensitive or that should be kept private?`];function Tn(){let e=P(),t=ee(e=>e.setView),n=ee(e=>e.apiBase),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(1),[p,m]=(0,_.useState)([]),h=async()=>{i(!0),c(null);try{let e=await k(`/api/screen/capture`,{monitor:d});c(e),(e?.base64||e?.file)&&m(t=>[{ts:new Date().toLocaleTimeString(),question:`Screenshot`,analysis:``,src:e.base64?`data:image/${e.format??`jpeg`};base64,${e.base64}`:`${n}/api/screenshots/${e.file}`},...t.slice(0,9)])}catch(e){c({error:e.message})}i(!1)},g=async()=>{if(l.trim()){o(!0);try{let e=await k(`/api/screen/analyze`,{question:l.trim(),monitor:d});if(c(e),e?.analysis){let t=e.base64?`data:image/${e.format??`jpeg`};base64,${e.base64}`:e.file?`${n}/api/screenshots/${e.file}`:``;m(n=>[{ts:new Date().toLocaleTimeString(),question:l.trim(),analysis:e.analysis??``,src:t},...n.slice(0,9)])}}catch(e){c({error:e.message})}o(!1)}},v=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},y=s?.base64?`data:image/${s.format??`jpeg`};base64,${s.base64}`:s?.file?`${n}/api/screenshots/${s.file}`:null;return(0,j.jsxs)(`div`,{className:Cn.root,children:[(0,j.jsx)(`div`,{className:Cn.header,children:(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`div`,{className:Cn.title,children:`🖥️ Screen Capture`}),(0,j.jsxs)(`div`,{className:Cn.subtitle,children:[e(`screen.capture`),` and analyze your desktop screen with AI vision`]})]})}),(0,j.jsxs)(`div`,{className:Cn.controls,children:[(0,j.jsxs)(`div`,{className:Cn.monitorRow,children:[(0,j.jsx)(`label`,{className:Cn.label,children:`Monitor`}),[1,2,3].map(e=>(0,j.jsxs)(`button`,{className:`${Cn.monitorBtn} ${d===e?Cn.monitorActive:``}`,onClick:()=>f(e),children:[`Monitor `,e]},e))]}),(0,j.jsx)(`button`,{className:Cn.captureBtn,onClick:h,disabled:r||a,children:r?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:`spinner`}),` Capturing…`]}):`📷 Capture Screen`})]}),(0,j.jsxs)(`div`,{className:Cn.analyzeSection,children:[(0,j.jsx)(`div`,{className:Cn.sectionTitle,children:`Capture + Analyze`}),(0,j.jsx)(`div`,{className:Cn.presets,children:wn.map(e=>(0,j.jsxs)(`button`,{className:`${Cn.preset} ${l===e?Cn.presetActive:``}`,onClick:()=>u(e),children:[e.slice(0,50),e.length>50?`…`:``]},e))}),(0,j.jsxs)(`div`,{className:Cn.questionRow,children:[(0,j.jsx)(`input`,{className:Cn.questionInput,value:l,onChange:e=>u(e.target.value),placeholder:`Ask something about your screen…`,onKeyDown:e=>e.key===`Enter`&&g()}),(0,j.jsx)(`button`,{className:Cn.analyzeBtn,onClick:g,disabled:!l.trim()||r||a,children:a?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:`spinner`}),` Analyzing…`]}):`🔍 Analyze`})]})]}),s?.error&&(0,j.jsx)(`div`,{className:Cn.error,children:s.error}),y&&(0,j.jsxs)(`div`,{className:Cn.screenshotContainer,children:[(0,j.jsx)(`img`,{src:y,className:Cn.screenshot,alt:`Screen capture`}),s?.width&&s?.height&&(0,j.jsxs)(`div`,{className:Cn.screenshotMeta,children:[s.width,` × `,s.height,`px`]})]}),s?.analysis&&(0,j.jsxs)(`div`,{className:Cn.analysis,children:[(0,j.jsx)(`div`,{className:Cn.analysisTitle,children:`AI Analysis`}),(0,j.jsx)(`div`,{className:Cn.analysisText,children:s.analysis}),(0,j.jsx)(`button`,{className:Cn.continueInChat,onClick:()=>v(`I captured my screen. Here's what the AI saw:\n\n${s.analysis}\n\nCan you help me with this?`),children:`Continue in Chat →`})]}),p.length>0&&(0,j.jsxs)(`div`,{className:Cn.history,children:[(0,j.jsx)(`div`,{className:Cn.sectionTitle,children:`Recent Captures`}),(0,j.jsx)(`div`,{className:Cn.historyGrid,children:p.map((e,t)=>(0,j.jsxs)(`div`,{className:Cn.historyItem,children:[e.src&&(0,j.jsx)(`img`,{src:e.src,className:Cn.historyThumb,alt:e.question}),(0,j.jsxs)(`div`,{className:Cn.historyMeta,children:[(0,j.jsx)(`div`,{className:Cn.historyTs,children:e.ts}),(0,j.jsx)(`div`,{className:Cn.historyQ,children:e.question}),e.analysis&&(0,j.jsxs)(`div`,{className:Cn.historyA,children:[e.analysis.slice(0,120),`…`]})]})]},t))})]})]})}var Q={root:`_root_v12qq_1`,header:`_header_v12qq_3`,title:`_title_v12qq_4`,subtitle:`_subtitle_v12qq_5`,section:`_section_v12qq_7`,sectionTitle:`_sectionTitle_v12qq_8`,quickBtns:`_quickBtns_v12qq_10`,quickBtn:`_quickBtn_v12qq_10`,searchRow:`_searchRow_v12qq_14`,searchInput:`_searchInput_v12qq_15`,searchBtn:`_searchBtn_v12qq_16`,modeRow:`_modeRow_v12qq_19`,modeBtn:`_modeBtn_v12qq_20`,modeActive:`_modeActive_v12qq_21`,routeInputs:`_routeInputs_v12qq_23`,inputWrapper:`_inputWrapper_v12qq_24`,inputIcon:`_inputIcon_v12qq_25`,routeInput:`_routeInput_v12qq_23`,swapBtn:`_swapBtn_v12qq_27`,dirBtns:`_dirBtns_v12qq_29`,dirBtn:`_dirBtn_v12qq_29`,openMapsBtn:`_openMapsBtn_v12qq_32`,error:`_error_v12qq_34`,resultCard:`_resultCard_v12qq_36`,routeSummary:`_routeSummary_v12qq_37`,routeDistance:`_routeDistance_v12qq_38`,routeDuration:`_routeDuration_v12qq_39`,routeMode:`_routeMode_v12qq_40`,steps:`_steps_v12qq_41`,step:`_step_v12qq_41`,stepNum:`_stepNum_v12qq_43`,stepText:`_stepText_v12qq_44`,mapLink:`_mapLink_v12qq_45`,askChatBtn:`_askChatBtn_v12qq_47`,savedRoute:`_savedRoute_v12qq_49`,savedFrom:`_savedFrom_v12qq_51`,savedArrow:`_savedArrow_v12qq_52`,savedTo:`_savedTo_v12qq_53`,savedTs:`_savedTs_v12qq_54`},En=[`driving`,`walking`,`bicycling`,`transit`],Dn={driving:`🚗`,walking:`🚶`,bicycling:`🚲`,transit:`🚌`},On=[{label:`🏥 Nearest Hospital`,query:`nearest hospital`},{label:`⛽ Gas Station`,query:`gas station near me`},{label:`🛒 Supermarket`,query:`supermarket near me`},{label:`☕ Coffee Shop`,query:`coffee shop near me`},{label:`🏧 ATM`,query:`ATM near me`},{label:`🍕 Pizza`,query:`pizza restaurant near me`}];function kn(e,t,n){try{let r=JSON.parse(localStorage.getItem(`nha_maps_routes`)??`[]`),i=[{from:e,to:t,label:n,ts:new Date().toISOString()},...r.filter(n=>!(n.from===e&&n.to===t))].slice(0,10);localStorage.setItem(`nha_maps_routes`,JSON.stringify(i))}catch{}}function An(){try{return JSON.parse(localStorage.getItem(`nha_maps_routes`)??`[]`)}catch{return[]}}function jn(){let e=P(),t=ee(e=>e.setView),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(`driving`),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(An),[m,h]=(0,_.useState)(``),g=async()=>{if(!(!n.trim()||!i.trim())){l(!0),d(null);try{let e=await O(`/api/maps/directions?from=${encodeURIComponent(n.trim())}&to=${encodeURIComponent(i.trim())}&mode=${o}`);e&&(d(e),e.error||(kn(n.trim(),i.trim()),p(An())))}catch{d({url:`https://www.google.com/maps/dir/${encodeURIComponent(n.trim())}/${encodeURIComponent(i.trim())}/?travelmode=${o}`}),kn(n.trim(),i.trim()),p(An())}l(!1)}},v=e=>{let t=`https://www.google.com/maps/search/${encodeURIComponent(e)}`;window.open(t,`_blank`)},y=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},b=e=>{r(e.from),a(e.to)},x=n.trim()&&i.trim()?`https://www.google.com/maps/dir/${encodeURIComponent(n.trim())}/${encodeURIComponent(i.trim())}/?travelmode=${o}`:null;return(0,j.jsxs)(`div`,{className:Q.root,children:[(0,j.jsx)(`div`,{className:Q.header,children:(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`div`,{className:Q.title,children:`🗺️ Maps & Directions`}),(0,j.jsx)(`div`,{className:Q.subtitle,children:e(`maps.directions`)})]})}),(0,j.jsxs)(`div`,{className:Q.section,children:[(0,j.jsx)(`div`,{className:Q.sectionTitle,children:e(`common.search`)}),(0,j.jsx)(`div`,{className:Q.quickBtns,children:On.map(e=>(0,j.jsx)(`button`,{className:Q.quickBtn,onClick:()=>v(e.query),children:e.label},e.label))}),(0,j.jsxs)(`div`,{className:Q.searchRow,children:[(0,j.jsx)(`input`,{className:Q.searchInput,value:m,onChange:e=>h(e.target.value),placeholder:`Search for a place, address, or business…`,onKeyDown:e=>e.key===`Enter`&&v(m)}),(0,j.jsx)(`button`,{className:Q.searchBtn,onClick:()=>v(m),disabled:!m.trim(),children:`Search ↗`})]})]}),(0,j.jsxs)(`div`,{className:Q.section,children:[(0,j.jsx)(`div`,{className:Q.sectionTitle,children:`Directions`}),(0,j.jsx)(`div`,{className:Q.modeRow,children:En.map(e=>(0,j.jsxs)(`button`,{className:`${Q.modeBtn} ${o===e?Q.modeActive:``}`,onClick:()=>s(e),title:e,children:[Dn[e],` `,e.charAt(0).toUpperCase()+e.slice(1)]},e))}),(0,j.jsxs)(`div`,{className:Q.routeInputs,children:[(0,j.jsxs)(`div`,{className:Q.inputWrapper,children:[(0,j.jsx)(`span`,{className:Q.inputIcon,children:`A`}),(0,j.jsx)(`input`,{className:Q.routeInput,value:n,onChange:e=>r(e.target.value),placeholder:`From (address, city, or 'my location')`,onKeyDown:e=>e.key===`Enter`&&g()})]}),(0,j.jsx)(`button`,{className:Q.swapBtn,onClick:()=>{r(i),a(n)},title:`Swap`,children:`⇅`}),(0,j.jsxs)(`div`,{className:Q.inputWrapper,children:[(0,j.jsx)(`span`,{className:Q.inputIcon,children:`B`}),(0,j.jsx)(`input`,{className:Q.routeInput,value:i,onChange:e=>a(e.target.value),placeholder:`To (address, city, or landmark)`,onKeyDown:e=>e.key===`Enter`&&g()})]})]}),(0,j.jsxs)(`div`,{className:Q.dirBtns,children:[(0,j.jsx)(`button`,{className:Q.dirBtn,onClick:g,disabled:c||!n.trim()||!i.trim(),children:c?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:`spinner`}),` Getting route…`]}):`🗺️ Get Directions`}),x&&(0,j.jsx)(`a`,{className:Q.openMapsBtn,href:x,target:`_blank`,rel:`noreferrer`,children:`Open in Google Maps ↗`})]})]}),u?.error&&(0,j.jsx)(`div`,{className:Q.error,children:u.error}),u&&!u.error&&(0,j.jsxs)(`div`,{className:Q.resultCard,children:[(u.distance||u.duration)&&(0,j.jsxs)(`div`,{className:Q.routeSummary,children:[u.distance&&(0,j.jsxs)(`span`,{className:Q.routeDistance,children:[`📏 `,u.distance]}),u.duration&&(0,j.jsxs)(`span`,{className:Q.routeDuration,children:[`⏱ `,u.duration]}),(0,j.jsxs)(`span`,{className:Q.routeMode,children:[Dn[o],` `,o]})]}),u.steps&&u.steps.length>0&&(0,j.jsx)(`div`,{className:Q.steps,children:u.steps.map((e,t)=>(0,j.jsxs)(`div`,{className:Q.step,children:[(0,j.jsx)(`span`,{className:Q.stepNum,children:t+1}),(0,j.jsx)(`span`,{className:Q.stepText,children:e})]},t))}),u.url&&(0,j.jsx)(`a`,{className:Q.mapLink,href:u.url,target:`_blank`,rel:`noreferrer`,children:`View full route on Google Maps ↗`}),(0,j.jsx)(`button`,{className:Q.askChatBtn,onClick:()=>y(`Give me directions from "${n}" to "${i}" by ${o}. Include estimated time, distance, and any traffic alerts or alternative routes.`),children:`Ask AI for detailed route advice →`})]}),f.length>0&&(0,j.jsxs)(`div`,{className:Q.section,children:[(0,j.jsx)(`div`,{className:Q.sectionTitle,children:`Recent Routes`}),f.map((e,t)=>(0,j.jsxs)(`div`,{className:Q.savedRoute,onClick:()=>b(e),children:[(0,j.jsx)(`span`,{className:Q.savedFrom,children:e.from}),(0,j.jsx)(`span`,{className:Q.savedArrow,children:`→`}),(0,j.jsx)(`span`,{className:Q.savedTo,children:e.to}),(0,j.jsx)(`span`,{className:Q.savedTs,children:new Date(e.ts).toLocaleDateString()})]},t))]})]})}var $={root:`_root_esnjz_1`,header:`_header_esnjz_3`,title:`_title_esnjz_4`,subtitle:`_subtitle_esnjz_5`,addBtn:`_addBtn_esnjz_6`,quickAdd:`_quickAdd_esnjz_8`,quickLabel:`_quickLabel_esnjz_9`,quickPresets:`_quickPresets_esnjz_10`,quickPreset:`_quickPreset_esnjz_10`,section:`_section_esnjz_14`,sectionTitle:`_sectionTitle_esnjz_15`,loading:`_loading_esnjz_17`,empty:`_empty_esnjz_18`,card:`_card_esnjz_20`,cardPast:`_cardPast_esnjz_21`,cardLeft:`_cardLeft_esnjz_22`,reminderMsg:`_reminderMsg_esnjz_23`,reminderTime:`_reminderTime_esnjz_24`,timeBadge:`_timeBadge_esnjz_25`,countdown:`_countdown_esnjz_26`,timePast:`_timePast_esnjz_27`,sentBadge:`_sentBadge_esnjz_28`,cancelledBadge:`_cancelledBadge_esnjz_29`,cancelBtn:`_cancelBtn_esnjz_30`,repeatBtn:`_repeatBtn_esnjz_31`,aiButtons:`_aiButtons_esnjz_33`,aiBtn:`_aiBtn_esnjz_34`,overlay:`_overlay_esnjz_38`,modal:`_modal_esnjz_39`,modalTitle:`_modalTitle_esnjz_40`,label:`_label_esnjz_41`,input:`_input_esnjz_42`,msgTemplates:`_msgTemplates_esnjz_44`,msgTemplate:`_msgTemplate_esnjz_44`,msgTemplateActive:`_msgTemplateActive_esnjz_47`,typeTabs:`_typeTabs_esnjz_49`,typeTab:`_typeTab_esnjz_49`,typeTabActive:`_typeTabActive_esnjz_51`,relRow:`_relRow_esnjz_53`,inLabel:`_inLabel_esnjz_54`,relInput:`_relInput_esnjz_55`,relSelect:`_relSelect_esnjz_56`,formErr:`_formErr_esnjz_58`,formOk:`_formOk_esnjz_59`,modalBtns:`_modalBtns_esnjz_60`,cancelModalBtn:`_cancelModalBtn_esnjz_61`,saveBtn:`_saveBtn_esnjz_62`},Mn=[{label:`In 5 min`,value:`in 5 minutes`},{label:`In 15 min`,value:`in 15 minutes`},{label:`In 30 min`,value:`in 30 minutes`},{label:`In 1 hour`,value:`in 1 hour`},{label:`In 2 hours`,value:`in 2 hours`},{label:`In 3 hours`,value:`in 3 hours`},{label:`Tomorrow 9am`,value:`tomorrow at 09:00`},{label:`Tomorrow noon`,value:`tomorrow at 12:00`}],Nn=[`Take a break and stretch`,`Check emails`,`Join the standup call`,`Review and respond to messages`,`Take your medication`,`Drink water`,`Focus review — what did you accomplish in the last hour?`,`Follow up on pending tasks`,`End of work day — log your achievements`,`Weekly review — prepare for next week`];function Pn(e){if(e<1)return`now`;if(e<60)return`in ${e}m`;let t=Math.floor(e/60),n=e%60;return n>0?`in ${t}h ${n}m`:`in ${t}h`}function Fn(){let e=P(),t=ee(e=>e.setView),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)({message:``,atTime:``,atTimeType:`relative`,relValue:`30`,relUnit:`minutes`}),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(``),[m,h]=(0,_.useState)(!1),g=()=>{a(!0),O(`/api/reminders`).then(e=>{r(e?.reminders??[]),a(!1)}).catch(()=>{r([]),a(!1)})};(0,_.useEffect)(()=>{g()},[]);let v=async()=>{if(!o.message.trim()){d(`Message is required`);return}let e=``;if(o.atTimeType===`relative`)e=`in ${o.relValue} ${o.relUnit}`;else{if(!o.atTime){d(`Time is required`);return}e=o.atTime}l(!0),d(``);try{await k(`/api/reminders`,{message:o.message.trim(),atTime:e}),p(`Reminder set!`),setTimeout(()=>{p(``),h(!1)},1500),g()}catch(e){d(e.message??`Failed to set reminder`)}l(!1)},y=e=>{confirm(`Cancel this reminder?`)&&k(`/api/reminders/cancel`,{id:e}).then(g)},b=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},x=n.filter(e=>e.status===`pending`),S=n.filter(e=>e.status!==`pending`);return(0,j.jsxs)(`div`,{className:$.root,children:[(0,j.jsxs)(`div`,{className:$.header,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`div`,{className:$.title,children:`🔔 Reminders`}),(0,j.jsx)(`div`,{className:$.subtitle,children:`Set one-time notifications via the NHA daemon`})]}),(0,j.jsx)(`button`,{className:$.addBtn,onClick:()=>{h(!0),d(``),p(``)},children:`+ New Reminder`})]}),(0,j.jsxs)(`div`,{className:$.quickAdd,children:[(0,j.jsx)(`div`,{className:$.quickLabel,children:`Quick reminder for now:`}),(0,j.jsx)(`div`,{className:$.quickPresets,children:Mn.map(e=>(0,j.jsx)(`button`,{className:$.quickPreset,onClick:()=>{s(e=>({...e,atTimeType:`relative`,atTime:``,message:e.message||`Reminder`})),h(!0),d(``),p(``)},children:e.label},e.value))})]}),i&&(0,j.jsxs)(`div`,{className:$.loading,children:[(0,j.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}),!i&&(0,j.jsxs)(`div`,{className:$.section,children:[(0,j.jsxs)(`div`,{className:$.sectionTitle,children:[`Pending (`,x.length,`)`]}),x.length===0&&(0,j.jsx)(`div`,{className:$.empty,children:`No pending reminders. Set one to get notified.`}),x.map(e=>(0,j.jsxs)(`div`,{className:$.card,children:[(0,j.jsxs)(`div`,{className:$.cardLeft,children:[(0,j.jsx)(`div`,{className:$.reminderMsg,children:e.message}),(0,j.jsxs)(`div`,{className:$.reminderTime,children:[(0,j.jsx)(`span`,{className:$.timeBadge,children:new Date(e.atTime).toLocaleString()}),e.minutesUntil!==void 0&&(0,j.jsx)(`span`,{className:$.countdown,children:Pn(e.minutesUntil)})]})]}),(0,j.jsx)(`button`,{className:$.cancelBtn,onClick:()=>y(e.id),children:`Cancel`})]},e.id))]}),S.length>0&&(0,j.jsxs)(`div`,{className:$.section,children:[(0,j.jsxs)(`div`,{className:$.sectionTitle,children:[`Recent (`,S.length,`)`]}),S.slice(0,10).map(e=>(0,j.jsxs)(`div`,{className:`${$.card} ${$.cardPast}`,children:[(0,j.jsxs)(`div`,{className:$.cardLeft,children:[(0,j.jsx)(`div`,{className:$.reminderMsg,children:e.message}),(0,j.jsxs)(`div`,{className:$.reminderTime,children:[(0,j.jsx)(`span`,{className:e.status===`sent`?$.sentBadge:$.cancelledBadge,children:e.status}),(0,j.jsx)(`span`,{className:$.timePast,children:new Date(e.atTime).toLocaleString()})]})]}),(0,j.jsx)(`button`,{className:$.repeatBtn,onClick:()=>{s(t=>({...t,message:e.message,atTimeType:`relative`,relValue:`30`,relUnit:`minutes`})),h(!0)},children:`Repeat`})]},e.id))]}),(0,j.jsxs)(`div`,{className:$.section,children:[(0,j.jsx)(`div`,{className:$.sectionTitle,children:`AI-Powered Reminders`}),(0,j.jsxs)(`div`,{className:$.aiButtons,children:[(0,j.jsx)(`button`,{className:$.aiBtn,onClick:()=>b(`Set a reminder to check my emails in 30 minutes`),children:`📧 Email check in 30min`}),(0,j.jsx)(`button`,{className:$.aiBtn,onClick:()=>b(`Set a reminder every hour to take a break and drink water`),children:`💧 Hourly water break`}),(0,j.jsx)(`button`,{className:$.aiBtn,onClick:()=>b(`Set a reminder at the end of the work day (6pm) to do an evening review of my tasks and prepare tomorrow's plan`),children:`🌆 Evening review 6pm`}),(0,j.jsx)(`button`,{className:$.aiBtn,onClick:()=>b(`Look at my calendar and set reminders for all events today`),children:`📅 Remind me of today's events`})]})]}),m&&(0,j.jsx)(`div`,{className:$.overlay,onClick:e=>{e.target===e.currentTarget&&h(!1)},children:(0,j.jsxs)(`div`,{className:$.modal,children:[(0,j.jsx)(`div`,{className:$.modalTitle,children:e(`reminders.new`)}),(0,j.jsx)(`div`,{className:$.label,children:`Message *`}),(0,j.jsx)(`div`,{className:$.msgTemplates,children:Nn.map(e=>(0,j.jsx)(`button`,{className:`${$.msgTemplate} ${o.message===e?$.msgTemplateActive:``}`,onClick:()=>s(t=>({...t,message:e})),children:e},e))}),(0,j.jsx)(`input`,{className:$.input,value:o.message,onChange:e=>s(t=>({...t,message:e.target.value})),placeholder:`Reminder message (e.g. Call John)`}),(0,j.jsx)(`div`,{className:$.label,children:`When *`}),(0,j.jsxs)(`div`,{className:$.typeTabs,children:[(0,j.jsx)(`button`,{className:`${$.typeTab} ${o.atTimeType===`relative`?$.typeTabActive:``}`,onClick:()=>s(e=>({...e,atTimeType:`relative`})),children:`Relative`}),(0,j.jsx)(`button`,{className:`${$.typeTab} ${o.atTimeType===`absolute`?$.typeTabActive:``}`,onClick:()=>s(e=>({...e,atTimeType:`absolute`})),children:`Exact time`})]}),o.atTimeType===`relative`?(0,j.jsxs)(`div`,{className:$.relRow,children:[(0,j.jsx)(`span`,{className:$.inLabel,children:`in`}),(0,j.jsx)(`input`,{className:$.relInput,type:`number`,min:`1`,value:o.relValue,onChange:e=>s(t=>({...t,relValue:e.target.value}))}),(0,j.jsxs)(`select`,{className:$.relSelect,value:o.relUnit,onChange:e=>s(t=>({...t,relUnit:e.target.value})),children:[(0,j.jsx)(`option`,{value:`minutes`,children:`minutes`}),(0,j.jsx)(`option`,{value:`hours`,children:`hours`}),(0,j.jsx)(`option`,{value:`days`,children:`days`})]})]}):(0,j.jsx)(`input`,{className:$.input,type:`datetime-local`,value:o.atTime,onChange:e=>s(t=>({...t,atTime:e.target.value}))}),u&&(0,j.jsx)(`div`,{className:$.formErr,children:u}),f&&(0,j.jsx)(`div`,{className:$.formOk,children:f}),(0,j.jsxs)(`div`,{className:$.modalBtns,children:[(0,j.jsx)(`button`,{className:$.cancelModalBtn,onClick:()=>h(!1),children:`Cancel`}),(0,j.jsx)(`button`,{className:$.saveBtn,onClick:v,disabled:c,children:c?`Setting…`:`🔔 Set Reminder`})]})]})})]})}var In={root:`_root_atgeb_1`,icon:`_icon_atgeb_10`,title:`_title_atgeb_11`,sub:`_sub_atgeb_12`},Ln={dashboard:`⚡`,email:`📧`,calendar:`📅`,tasks:`✅`,contacts:`👤`,notes:`📝`,drive:`💾`,onedrive:`☁️`,mstodo:`📋`,github:`🐙`,slack:`💬`,notion:`📋`,collab:`🏛️`,maps:`🗺️`,cron:`⏰`,screen:`🖥️`,reminders:`🔔`,birthdays:`🎂`,settings:`⚙️`,agents:`🤖`,plan:`🗓️`,webcraft:`🔨`,connectors:`🔗`};function Rn({view:e}){let t=P();return(0,j.jsxs)(`div`,{className:In.root,children:[(0,j.jsx)(`div`,{className:In.icon,children:Ln[e]??`🔧`}),(0,j.jsx)(`div`,{className:In.title,children:e.charAt(0).toUpperCase()+e.slice(1)}),(0,j.jsx)(`div`,{className:In.sub,children:t(`common.comingSoon`)})]})}function zn(){let{activeView:e}=ee();switch(e){case`dashboard`:return(0,j.jsx)(mt,{});case`chat`:return(0,j.jsx)(Ce,{});case`studio`:return(0,j.jsx)(lt,{});case`email`:return(0,j.jsx)(Ht,{});case`calendar`:return(0,j.jsx)(Kt,{});case`tasks`:return(0,j.jsx)(gt,{});case`notes`:return(0,j.jsx)(Dt,{});case`contacts`:return(0,j.jsx)(At,{});case`birthdays`:return(0,j.jsx)(xt,{});case`cron`:return(0,j.jsx)(Tt,{});case`connectors`:return(0,j.jsx)(Lt,{});case`agents`:return(0,j.jsx)(Xt,{});case`drive`:return(0,j.jsx)($t,{});case`onedrive`:return(0,j.jsx)(bn,{});case`mstodo`:return(0,j.jsx)(Sn,{});case`github`:return(0,j.jsx)(en,{});case`slack`:return(0,j.jsx)(nn,{});case`notion`:return(0,j.jsx)(rn,{});case`collab`:return(0,j.jsx)(sn,{});case`webcraft`:return(0,j.jsx)(mn,{});case`plan`:return(0,j.jsx)(vn,{});case`screen`:return(0,j.jsx)(Tn,{});case`maps`:return(0,j.jsx)(jn,{});case`reminders`:return(0,j.jsx)(Fn,{});case`settings`:return(0,j.jsx)(yt,{});default:return(0,j.jsx)(Rn,{view:e})}}(0,v.createRoot)(document.getElementById(`root`)).render((0,j.jsx)(_.StrictMode,{children:(0,j.jsx)(de,{children:(0,j.jsx)(zn,{})})}));