nothumanallowed 14.1.78 → 14.1.80

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.78",
3
+ "version": "14.1.80",
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.78';
8
+ export const VERSION = '14.1.80';
9
9
  export const BASE_URL = 'https://nothumanallowed.com/cli';
10
10
  export const API_BASE = 'https://nothumanallowed.com/api/v1';
11
11
 
@@ -851,56 +851,112 @@ ${prevContext ? `Recent files generated (for consistency):\n${prevContext}\n\n`
851
851
  let syntaxError = null;
852
852
  const fileTokensIn = countTokens(fileSys) + countTokens(filePrompt);
853
853
 
854
- try {
855
- // Collect full LLM output first, then stream it to the client in small chunks.
856
- // This gives real word-by-word animation even with non-streaming providers (NHA/Liara).
857
- let rawOutput = '';
858
- await callLLMStream(config, fileSys, filePrompt, (chunk) => {
859
- rawOutput += chunk;
860
- }, { max_tokens: maxTokens });
861
-
862
- // Strip markdown fences if LLM wrapped the output
863
- rawOutput = rawOutput
864
- .replace(/^```[\w]*\n/, '').replace(/\n```$/, '')
865
- .replace(/^```[\w]*\r\n/, '').replace(/\r\n```$/, '').trim();
866
-
867
- // Continuation: if the file appears truncated, ask the model to continue
868
- if (isFileTruncated(rawOutput, fileSpec.name)) {
869
- const contPrompt = `Continue writing the file ${fileSpec.name} exactly from where it was cut off. Output ONLY the continuation (no repetition of what was already written, no explanation):
870
-
871
- ${rawOutput.slice(-800)}`;
872
- let continuation = '';
873
- await callLLMStream(config, fileSys, contPrompt, (chunk) => {
874
- continuation += chunk;
875
- }, { max_tokens: Math.min(maxTokens, 4096) });
876
- continuation = continuation
877
- .replace(/^```[\w]*\n/, '').replace(/\n```$/, '').trim();
878
- rawOutput = rawOutput + '\n' + continuation;
879
- }
854
+ // Retry loop — up to 2 attempts per file
855
+ for (let attempt = 0; attempt < 2; attempt++) {
856
+ try {
857
+ // Stream chunks to browser in real-time during generation
858
+ let rawOutput = '';
859
+ await callLLMStream(config, fileSys, filePrompt, (chunk) => {
860
+ rawOutput += chunk;
861
+ // Real-time streaming to browser
862
+ emit({ type: 'file_chunk', name: fileSpec.name, chunk, fi: fi + 1, total: filePlan.length });
863
+ }, { max_tokens: maxTokens });
864
+
865
+ // Strip markdown fences if LLM wrapped the output
866
+ rawOutput = rawOutput
867
+ .replace(/^```[\w]*\n/, '').replace(/\n```$/, '')
868
+ .replace(/^```[\w]*\r\n/, '').replace(/\r\n```$/, '').trim();
869
+
870
+ // Continuation loop — up to 3 rounds if file appears truncated
871
+ for (let contRound = 0; contRound < 3 && isFileTruncated(rawOutput, fileSpec.name); contRound++) {
872
+ emit({ type: 'file_chunk', name: fileSpec.name, chunk: `\n/* ... continuing (${contRound + 1}) ... */\n`, fi: fi + 1, total: filePlan.length });
873
+ const contPrompt = `The file ${fileSpec.name} was truncated. Continue EXACTLY from the last line. Output ONLY the remaining code (no repetition, no explanation):
874
+
875
+ LAST 600 CHARS OF WHAT WAS WRITTEN:
876
+ ${rawOutput.slice(-600)}
877
+
878
+ Continue from here:`;
879
+ let continuation = '';
880
+ await callLLMStream(config, fileSys, contPrompt, (chunk) => {
881
+ continuation += chunk;
882
+ emit({ type: 'file_chunk', name: fileSpec.name, chunk, fi: fi + 1, total: filePlan.length });
883
+ }, { max_tokens: Math.min(maxTokens, 8192) });
884
+ continuation = continuation
885
+ .replace(/^```[\w]*\n/, '').replace(/\n```$/, '').trim();
886
+ if (continuation.length > 20) {
887
+ rawOutput = rawOutput + '\n' + continuation;
888
+ } else {
889
+ break; // continuation too short — likely done
890
+ }
891
+ }
880
892
 
881
- fileContent = rawOutput;
893
+ fileContent = rawOutput;
894
+ syntaxError = null;
882
895
 
883
- // Stream the final content to the browser in small chunks for animation
884
- await emitTextAsStream(fileContent, (chunk) => {
885
- emit({ type: 'file_chunk', name: fileSpec.name, chunk, fi: fi + 1, total: filePlan.length });
886
- });
896
+ const fileTokensOut = countTokens(fileContent);
897
+ totalTokensIn += fileTokensIn;
898
+ totalTokensOut += fileTokensOut;
887
899
 
888
- const fileTokensOut = countTokens(fileContent);
889
- totalTokensIn += fileTokensIn;
890
- totalTokensOut += fileTokensOut;
900
+ // Quick syntax check for JS/TS files
901
+ if (fileSpec.name.endsWith('.js') || fileSpec.name.endsWith('.mjs')) {
902
+ try { new Function(fileContent); } catch (e) { syntaxError = e.message.replace(/\n.*/s, ''); }
903
+ }
904
+ // HTML completeness check
905
+ if (fileSpec.name.endsWith('.html') && !fileContent.includes('</html>')) {
906
+ syntaxError = 'Missing </html> closing tag';
907
+ }
908
+
909
+ const abs = path.join(projectDir, fileSpec.name);
910
+ ensureDir(path.dirname(abs));
911
+ fs.writeFileSync(abs, fileContent, 'utf-8');
912
+ generatedFiles.push({ name: fileSpec.name, content: fileContent });
913
+ emit({ type: 'file_done', name: fileSpec.name, fi: fi + 1, total: filePlan.length, syntaxError, tokOut: fileTokensOut, cumTokIn: totalTokensIn, cumTokOut: totalTokensOut });
914
+ break; // success — exit retry loop
891
915
 
892
- // Quick syntax check for JS/TS files
893
- if (fileSpec.name.endsWith('.js') || fileSpec.name.endsWith('.mjs')) {
894
- try { new Function(fileContent); } catch (e) { syntaxError = e.message.replace(/\n.*/s, ''); }
916
+ } catch (e) {
917
+ if (attempt === 0) {
918
+ emit({ type: 'file_chunk', name: fileSpec.name, chunk: `\n/* Retry: ${e.message.slice(0, 100)} */\n`, fi: fi + 1, total: filePlan.length });
919
+ continue; // retry once
920
+ }
921
+ emit({ type: 'file_error', name: fileSpec.name, error: e.message });
895
922
  }
923
+ }
924
+ }
896
925
 
897
- const abs = path.join(projectDir, fileSpec.name);
898
- ensureDir(path.dirname(abs));
899
- fs.writeFileSync(abs, fileContent, 'utf-8');
900
- generatedFiles.push({ name: fileSpec.name, content: fileContent });
901
- emit({ type: 'file_done', name: fileSpec.name, fi: fi + 1, total: filePlan.length, syntaxError, tokOut: fileTokensOut, cumTokIn: totalTokensIn, cumTokOut: totalTokensOut });
902
- } catch (e) {
903
- emit({ type: 'file_error', name: fileSpec.name, error: e.message });
926
+ // ── Post-generation integrity check ──────────────────────────────────────
927
+ const brokenFiles = generatedFiles.filter((f) => {
928
+ if (!f.content || f.content.length < 20) return true;
929
+ if (f.name.endsWith('.html') && !f.content.includes('</html>')) return true;
930
+ if ((f.name.endsWith('.js') || f.name.endsWith('.mjs'))) {
931
+ try { new Function(f.content); } catch { return true; }
932
+ }
933
+ if (f.name.endsWith('.json')) {
934
+ try { JSON.parse(f.content); } catch { return true; }
935
+ }
936
+ return isFileTruncated(f.content, f.name);
937
+ });
938
+
939
+ if (brokenFiles.length > 0 && brokenFiles.length <= 10) {
940
+ emit({ type: 'phase', phase: 'autofix', msg: `Post-generation fix: ${brokenFiles.length} file(s) need repair...` });
941
+ for (const broken of brokenFiles) {
942
+ try {
943
+ emit({ type: 'status', msg: `Regenerating ${broken.name}...` });
944
+ let fixedContent = '';
945
+ const fixPrompt = `Regenerate this file COMPLETELY. It was truncated or has errors.\n\nFile: ${broken.name}\nProject: ${projectName}\nDescription: ${description}\nFull file list: ${allFileNames}\n\nOutput the COMPLETE file content only, no explanation.`;
946
+ await callLLMStream(config, fileSys, fixPrompt, (chunk) => {
947
+ fixedContent += chunk;
948
+ }, { max_tokens: 16384 });
949
+ fixedContent = fixedContent
950
+ .replace(/^```[\w]*\n/, '').replace(/\n```$/, '').trim();
951
+ if (fixedContent.length > broken.content.length) {
952
+ broken.content = fixedContent;
953
+ const abs = path.join(projectDir, broken.name);
954
+ fs.writeFileSync(abs, fixedContent, 'utf-8');
955
+ emit({ type: 'status', msg: `Fixed ${broken.name} (${fixedContent.length} chars)` });
956
+ }
957
+ } catch (e) {
958
+ emit({ type: 'status', msg: `Could not fix ${broken.name}: ${e.message.slice(0, 100)}` });
959
+ }
904
960
  }
905
961
  }
906
962
 
@@ -1128,6 +1184,17 @@ export function register(router) {
1128
1184
  } catch (e) { sendError(res, 500, e.message); }
1129
1185
  });
1130
1186
 
1187
+ // ── File write (from IDE editor) ──────────────────────────────────────────
1188
+ router.post('/api/studio/webcraft/file/write', async (req, res) => {
1189
+ try {
1190
+ const { projectName, path: relPath, content } = await parseBody(req, 10_485_760);
1191
+ if (!projectName || !relPath || content === undefined) return sendError(res, 400, 'projectName, path, content required');
1192
+ if (!_isSafePath(relPath)) return sendError(res, 400, 'unsafe path');
1193
+ ProjectStore.writeFile(projectName, relPath, content);
1194
+ sendJSON(res, 200, { ok: true });
1195
+ } catch (e) { sendError(res, 500, e.message); }
1196
+ });
1197
+
1131
1198
  // ── Sandbox start — SSE ───────────────────────────────────────────────────
1132
1199
  router.post('/api/studio/webcraft/sandbox/start', async (req, res) => {
1133
1200
  const { projectName } = await parseBody(req);
@@ -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_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.
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_13pxc_2`,header:`_header_13pxc_10`,title:`_title_13pxc_21`,subtitle:`_subtitle_13pxc_28`,headerTabs:`_headerTabs_13pxc_34`,tabBtn:`_tabBtn_13pxc_40`,tabActive:`_tabActive_13pxc_51`,body:`_body_13pxc_58`,editor:`_editor_13pxc_67`,examples:`_examples_13pxc_75`,sectionLabel:`_sectionLabel_13pxc_81`,examplePills:`_examplePills_13pxc_89`,examplePill:`_examplePill_13pxc_89`,editorCols:`_editorCols_13pxc_109`,leftSidebar:`_leftSidebar_13pxc_119`,panel:`_panel_13pxc_128`,panelHeader:`_panelHeader_13pxc_135`,panelTitle:`_panelTitle_13pxc_142`,addBtn:`_addBtn_13pxc_149`,blockLabel:`_blockLabel_13pxc_160`,blockCheck:`_blockCheck_13pxc_170`,authField:`_authField_13pxc_173`,authFieldInput:`_authFieldInput_13pxc_183`,authFieldSelect:`_authFieldSelect_13pxc_193`,authFieldReq:`_authFieldReq_13pxc_204`,removeFieldBtn:`_removeFieldBtn_13pxc_205`,skillsList:`_skillsList_13pxc_208`,skillRow:`_skillRow_13pxc_210`,skillIcon:`_skillIcon_13pxc_218`,skillName:`_skillName_13pxc_220`,skillBadge:`_skillBadge_13pxc_229`,skillBadge_skill:`_skillBadge_skill_13pxc_237`,skillBadge_memory:`_skillBadge_memory_13pxc_238`,skillBadge_provider:`_skillBadge_provider_13pxc_239`,skillBadge_log:`_skillBadge_log_13pxc_240`,skillEmpty:`_skillEmpty_13pxc_242`,skillBtn:`_skillBtn_13pxc_244`,skillsEmpty:`_skillsEmpty_13pxc_246`,snapshotRow:`_snapshotRow_13pxc_249`,snapshotTs:`_snapshotTs_13pxc_258`,snapshotCount:`_snapshotCount_13pxc_259`,snapshotBtn:`_snapshotBtn_13pxc_260`,genStatus:`_genStatus_13pxc_263`,repairStatus:`_repairStatus_13pxc_265`,repairStatusTitle:`_repairStatusTitle_13pxc_266`,repairStatusProg:`_repairStatusProg_13pxc_267`,repairStatusFile:`_repairStatusFile_13pxc_268`,actionRow:`_actionRow_13pxc_271`,actionBtn:`_actionBtn_13pxc_273`,actionBtnIcon:`_actionBtnIcon_13pxc_275`,actionBtnActive:`_actionBtnActive_13pxc_276`,repairBtn:`_repairBtn_13pxc_278`,sandboxBtn:`_sandboxBtn_13pxc_280`,statsBar:`_statsBar_13pxc_282`,rightPanel:`_rightPanel_13pxc_285`,rightTabBar:`_rightTabBar_13pxc_296`,rightTab:`_rightTab_13pxc_296`,rightTabActive:`_rightTabActive_13pxc_313`,repairBar:`_repairBar_13pxc_316`,repairBarRow:`_repairBarRow_13pxc_326`,repairBarIcon:`_repairBarIcon_13pxc_327`,repairBarLabel:`_repairBarLabel_13pxc_328`,repairBarFile:`_repairBarFile_13pxc_329`,repairBarCounter:`_repairBarCounter_13pxc_330`,repairBarTime:`_repairBarTime_13pxc_331`,genBar:`_genBar_13pxc_333`,genBarRow:`_genBarRow_13pxc_343`,genBarRobot:`_genBarRobot_13pxc_344`,robotBob:`_robotBob_13pxc_1`,genBarLabel:`_genBarLabel_13pxc_345`,genBarFile:`_genBarFile_13pxc_346`,genBarCounter:`_genBarCounter_13pxc_347`,genBarTime:`_genBarTime_13pxc_348`,progressTrack:`_progressTrack_13pxc_350`,repairProgress:`_repairProgress_13pxc_351`,genProgress:`_genProgress_13pxc_352`,genDots:`_genDots_13pxc_355`,dot:`_dot_13pxc_356`,dot1:`_dot1_13pxc_357`,dotBounce:`_dotBounce_13pxc_1`,dot2:`_dot2_13pxc_358`,dot3:`_dot3_13pxc_359`,stopBtn:`_stopBtn_13pxc_362`,codeArea:`_codeArea_13pxc_365`,sandboxWrap:`_sandboxWrap_13pxc_366`,sandboxFrame:`_sandboxFrame_13pxc_367`,sandboxEmpty:`_sandboxEmpty_13pxc_368`,sandboxStartBtn:`_sandboxStartBtn_13pxc_369`,sandboxConsole:`_sandboxConsole_13pxc_372`,sandboxConsoleCollapsed:`_sandboxConsoleCollapsed_13pxc_381`,sandboxConsoleHeader:`_sandboxConsoleHeader_13pxc_382`,sandboxConsoleTitle:`_sandboxConsoleTitle_13pxc_394`,sandboxConsolePort:`_sandboxConsolePort_13pxc_395`,sandboxConsoleDots:`_sandboxConsoleDots_13pxc_396`,sandboxConsoleToggle:`_sandboxConsoleToggle_13pxc_397`,sandboxReloadBtn:`_sandboxReloadBtn_13pxc_398`,sandboxStopBtn:`_sandboxStopBtn_13pxc_400`,sandboxConsoleBody:`_sandboxConsoleBody_13pxc_402`,sandboxLogLine:`_sandboxLogLine_13pxc_408`,sandboxLogPhase:`_sandboxLogPhase_13pxc_417`,sandboxLogError:`_sandboxLogError_13pxc_418`,sandboxLogWarn:`_sandboxLogWarn_13pxc_419`,sandboxLogOk:`_sandboxLogOk_13pxc_420`,codeLayout:`_codeLayout_13pxc_423`,codeRow:`_codeRow_13pxc_432`,ideTabBar:`_ideTabBar_13pxc_440`,ideTab:`_ideTab_13pxc_440`,ideTabActive:`_ideTabActive_13pxc_472`,ideTabError:`_ideTabError_13pxc_477`,ideTabPending:`_ideTabPending_13pxc_478`,ideTabIcon:`_ideTabIcon_13pxc_479`,ideTabName:`_ideTabName_13pxc_480`,ideTabDot:`_ideTabDot_13pxc_481`,codeEditorWrap:`_codeEditorWrap_13pxc_489`,editToggleBtn:`_editToggleBtn_13pxc_500`,editToggleBtnActive:`_editToggleBtnActive_13pxc_511`,codeEditor:`_codeEditor_13pxc_489`,genCursor:`_genCursor_13pxc_533`,cursorBlink:`_cursorBlink_13pxc_1`,diffOverlay:`_diffOverlay_13pxc_542`,diffOverlayHeader:`_diffOverlayHeader_13pxc_551`,diffOverlayActions:`_diffOverlayActions_13pxc_562`,diffAcceptBtn:`_diffAcceptBtn_13pxc_563`,diffRejectBtn:`_diffRejectBtn_13pxc_564`,diffOverlayBody:`_diffOverlayBody_13pxc_565`,diffSame:`_diffSame_13pxc_566`,diffRem:`_diffRem_13pxc_567`,diffAdd:`_diffAdd_13pxc_568`,noFiles:`_noFiles_13pxc_570`,noFilesHero:`_noFilesHero_13pxc_580`,noFilesIcon:`_noFilesIcon_13pxc_587`,noFilesTitle:`_noFilesTitle_13pxc_589`,noFilesTagline:`_noFilesTagline_13pxc_596`,noFilesSteps:`_noFilesSteps_13pxc_601`,noFilesStep:`_noFilesStep_13pxc_601`,noFilesStepNum:`_noFilesStepNum_13pxc_618`,noFilesExamplesHint:`_noFilesExamplesHint_13pxc_632`,noFilesExampleBtn:`_noFilesExampleBtn_13pxc_642`,codeViewer:`_codeViewer_13pxc_654`,codeHeader:`_codeHeader_13pxc_662`,codeFileIcon:`_codeFileIcon_13pxc_675`,codeFileName:`_codeFileName_13pxc_676`,codeFileMeta:`_codeFileMeta_13pxc_677`,fileError:`_fileError_13pxc_679`,fileSyntaxError:`_fileSyntaxError_13pxc_680`,filePending:`_filePending_13pxc_681`,codeWithLines:`_codeWithLines_13pxc_684`,lineNumbers:`_lineNumbers_13pxc_691`,lineNum:`_lineNum_13pxc_691`,code:`_code_13pxc_365`,codeError:`_codeError_13pxc_723`,codeSyntaxError:`_codeSyntaxError_13pxc_724`,fileSidebar:`_fileSidebar_13pxc_727`,fileSidebarHeader:`_fileSidebarHeader_13pxc_736`,fileTab:`_fileTab_13pxc_746`,fileTabActive:`_fileTabActive_13pxc_762`,fileTabError:`_fileTabError_13pxc_763`,fileTabRow:`_fileTabRow_13pxc_765`,fileTabIcon:`_fileTabIcon_13pxc_766`,fileTabName:`_fileTabName_13pxc_767`,fileTabSize:`_fileTabSize_13pxc_768`,fileTabDir:`_fileTabDir_13pxc_769`,fileTabTokens:`_fileTabTokens_13pxc_770`,fileTabMeta:`_fileTabMeta_13pxc_771`,projectsList:`_projectsList_13pxc_774`,emptyProjects:`_emptyProjects_13pxc_776`,emptyIcon:`_emptyIcon_13pxc_777`,emptyHint:`_emptyHint_13pxc_778`,projectCard:`_projectCard_13pxc_780`,projectInfo:`_projectInfo_13pxc_781`,projectName:`_projectName_13pxc_782`,projectDesc:`_projectDesc_13pxc_783`,projectMeta:`_projectMeta_13pxc_784`,openBtn:`_openBtn_13pxc_785`,deleteBtn:`_deleteBtn_13pxc_786`,planBanner:`_planBanner_13pxc_789`,planTitle:`_planTitle_13pxc_798`,planText:`_planText_13pxc_799`,planActions:`_planActions_13pxc_800`,planApprove:`_planApprove_13pxc_801`,planReject:`_planReject_13pxc_802`,grepPanel:`_grepPanel_13pxc_805`,grepRow:`_grepRow_13pxc_814`,grepInput:`_grepInput_13pxc_815`,grepBtn:`_grepBtn_13pxc_817`,grepClose:`_grepClose_13pxc_818`,grepCount:`_grepCount_13pxc_819`,grepResults:`_grepResults_13pxc_820`,grepEmpty:`_grepEmpty_13pxc_821`,grepMatch:`_grepMatch_13pxc_822`,grepMatchFile:`_grepMatchFile_13pxc_824`,grepMatchLine:`_grepMatchLine_13pxc_825`,diffPanel:`_diffPanel_13pxc_828`,diffHeader:`_diffHeader_13pxc_837`,diffClose:`_diffClose_13pxc_838`,diffFile:`_diffFile_13pxc_839`,diffSummary:`_diffSummary_13pxc_840`,diffArrow:`_diffArrow_13pxc_841`,diffFileName:`_diffFileName_13pxc_842`,diffAdded:`_diffAdded_13pxc_843`,diffRemoved:`_diffRemoved_13pxc_844`,diffContent:`_diffContent_13pxc_845`,diffInline:`_diffInline_13pxc_848`,diffInlineHeader:`_diffInlineHeader_13pxc_849`,diffRemLine:`_diffRemLine_13pxc_850`,diffAddLine:`_diffAddLine_13pxc_851`,chatPanel:`_chatPanel_13pxc_854`,chatMessages:`_chatMessages_13pxc_863`,chatWelcome:`_chatWelcome_13pxc_865`,chatUser:`_chatUser_13pxc_867`,chatUserBubble:`_chatUserBubble_13pxc_868`,chatAttachPreviews:`_chatAttachPreviews_13pxc_869`,chatAttachBadge:`_chatAttachBadge_13pxc_870`,chatSystem:`_chatSystem_13pxc_872`,chatSystemBubble:`_chatSystemBubble_13pxc_873`,chatSyntaxErr:`_chatSyntaxErr_13pxc_874`,chatAgent:`_chatAgent_13pxc_876`,chatAgentCard:`_chatAgentCard_13pxc_877`,chatAgentHeader:`_chatAgentHeader_13pxc_878`,chatAgentRobot:`_chatAgentRobot_13pxc_879`,chatAgentRobotAnim:`_chatAgentRobotAnim_13pxc_880`,chatAgentLabel:`_chatAgentLabel_13pxc_881`,chatRunningDots:`_chatRunningDots_13pxc_882`,chatAgentText:`_chatAgentText_13pxc_883`,chatToolBadges:`_chatToolBadges_13pxc_884`,toolBadge:`_toolBadge_13pxc_885`,toolBadgeOk:`_toolBadgeOk_13pxc_886`,toolBadgeErr:`_toolBadgeErr_13pxc_887`,cursor:`_cursor_13pxc_889`,blink:`_blink_13pxc_1`,attachPreviews:`_attachPreviews_13pxc_892`,attachBadge:`_attachBadge_13pxc_893`,removeAttachBtn:`_removeAttachBtn_13pxc_894`,projNameRow:`_projNameRow_13pxc_897`,projNameLabel:`_projNameLabel_13pxc_898`,projNameInput:`_projNameInput_13pxc_899`,projActiveRow:`_projActiveRow_13pxc_900`,projActiveName:`_projActiveName_13pxc_901`,chatInputRow:`_chatInputRow_13pxc_904`,attachLabel:`_attachLabel_13pxc_905`,chatTextarea:`_chatTextarea_13pxc_906`,chatSendCol:`_chatSendCol_13pxc_909`,chatSendBtn:`_chatSendBtn_13pxc_910`,chatStopBtn:`_chatStopBtn_13pxc_912`,modalOverlay:`_modalOverlay_13pxc_915`,modal:`_modal_13pxc_915`,modalHeader:`_modalHeader_13pxc_937`,modalTitle:`_modalTitle_13pxc_938`,modalClose:`_modalClose_13pxc_939`,modalBody:`_modalBody_13pxc_941`,modalRow:`_modalRow_13pxc_943`,modalField:`_modalField_13pxc_944`,modalLabel:`_modalLabel_13pxc_945`,modalLabelRow:`_modalLabelRow_13pxc_946`,modalSelect:`_modalSelect_13pxc_948`,modalInput:`_modalInput_13pxc_949`,modalHint:`_modalHint_13pxc_952`,modalAiBox:`_modalAiBox_13pxc_954`,modalAiRow:`_modalAiRow_13pxc_955`,modalAiDesc:`_modalAiDesc_13pxc_956`,modalAiBtn:`_modalAiBtn_13pxc_957`,modalContentArea:`_modalContentArea_13pxc_960`,logView:`_logView_13pxc_963`,modalFooter:`_modalFooter_13pxc_965`,modalCancelBtn:`_modalCancelBtn_13pxc_966`,modalSaveBtn:`_modalSaveBtn_13pxc_967`},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
@@ -678,19 +678,20 @@ FRONTEND:
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
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(()=>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(`
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===`phase`||e.type===`status`&&!e.op?ie(t=>({...t,name:e.msg||e.phase||``})):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
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
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
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
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(`
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),y(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
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(`
693
+ `).length,` righe · `,fn(Dt.content)]}),!Dt._pending&&!Dt._error&&Dt.content&&(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)),k(`/api/studio/webcraft/file/write`,{projectName:a,path:Dt.name,content:b}),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]}),(()=>{let e=b===null?w&&v!==null?v:Dt.content:b,t=(e||``).split(`
694
+ `),n=Dt._pending||w&&v!==null;return b===null?(0,j.jsxs)(`div`,{className:`${Z.codeWithLines} ${Dt._error?Z.codeError:Dt._syntaxError?Z.codeSyntaxError:``}`,children:[(0,j.jsx)(`div`,{className:Z.lineNumbers,children:t.map((e,t)=>(0,j.jsx)(`div`,{className:Z.lineNum,children:t+1},t))}),(0,j.jsxs)(`pre`,{className:Z.code,children:[e,n&&(0,j.jsx)(`span`,{className:Z.genCursor,children:`▋`})]})]}):(0,j.jsxs)(`div`,{className:Z.codeWithLines,children:[(0,j.jsx)(`div`,{className:Z.lineNumbers,children:t.map((e,t)=>(0,j.jsx)(`div`,{className:Z.lineNum,children:t+1},t))}),(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
695
  `).length-e.before.split(`
695
696
  `).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
697
  `).map((e,t)=>(0,j.jsxs)(`div`,{className:Z.diffRemLine,children:[`- `,e]},`r${t}`)),e.newSnippet?.split(`