nothumanallowed 15.1.21 → 15.1.23

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": "15.1.21",
3
+ "version": "15.1.23",
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 = '15.1.21';
8
+ export const VERSION = '15.1.23';
9
9
  export const BASE_URL = 'https://nothumanallowed.com/cli';
10
10
  export const API_BASE = 'https://nothumanallowed.com/api/v1';
11
11
 
@@ -291,37 +291,10 @@ class SandboxManager {
291
291
  if (matchedPattern && _attempt < MAX_RETRIES) {
292
292
  emit({ type: 'phase', phase: 'autofix', msg: `Runtime error detected: ${matchedPattern.name} — analyzing...` });
293
293
 
294
- // ── Special pre-fix for require/import mismatches ──
295
- // For "require is not defined" the project is ESM but uses CJS syntax.
296
- // Easiest fix: flip package.json — REMOVE "type":"module" so CJS works,
297
- // OR rewrite files. We try the package.json toggle FIRST (cheaper) only
298
- // when the failing files clearly use `require()`. For the inverse case
299
- // ("Cannot use import statement outside a module") we ADD "type":"module".
300
294
  const pkgPath = path.join(projectDir, 'package.json');
301
295
  const isRequireError = /require is not defined/i.test(stderrBuf);
302
296
  const isImportError = /Cannot use import statement outside a module/i.test(stderrBuf);
303
297
 
304
- if ((isRequireError || isImportError) && fs.existsSync(pkgPath)) {
305
- try {
306
- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
307
- if (isImportError && pkg.type !== 'module') {
308
- pkg.type = 'module';
309
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
310
- emit({ type: 'status', msg: 'Auto-fix: added "type":"module" to package.json — retrying...' });
311
- return this.start(projectName, projectDir, emit, _attempt + 1);
312
- }
313
- if (isRequireError && pkg.type === 'module') {
314
- // Flip OFF "type":"module" so require() works again
315
- delete pkg.type;
316
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
317
- emit({ type: 'status', msg: 'Auto-fix: removed "type":"module" from package.json — retrying...' });
318
- return this.start(projectName, projectDir, emit, _attempt + 1);
319
- }
320
- } catch (e) {
321
- emit({ type: 'warn', msg: `package.json toggle failed: ${e.message.slice(0, 200)}` });
322
- }
323
- }
324
-
325
298
  // ── Extract file path from stack trace (multiple patterns) ──
326
299
  // Try several regex forms to be robust against various Node stack formats.
327
300
  const allPaths = new Set();
@@ -378,10 +351,89 @@ class SandboxManager {
378
351
  }
379
352
  }
380
353
 
354
+ // ── Deterministic fixes BEFORE LLM repair (faster, no token cost) ──
355
+ // The trick is to consider the file extension because it overrides
356
+ // package.json "type" in Node.
357
+ let deterministicFixApplied = false;
358
+ if ((isRequireError || isImportError) && projectFiles.length > 0) {
359
+ for (const rel of projectFiles) {
360
+ const ext = path.extname(rel).toLowerCase();
361
+ const abs = path.join(projectDir, rel);
362
+
363
+ // Case A: file is .mjs (forced ESM) using require() → rename to .cjs
364
+ // This is the FAST fix Node itself suggests in the error message.
365
+ if (isRequireError && ext === '.mjs') {
366
+ const newAbs = abs.replace(/\.mjs$/i, '.cjs');
367
+ try {
368
+ fs.renameSync(abs, newAbs);
369
+ // Update package.json "main" if it pointed to the old file
370
+ if (fs.existsSync(pkgPath)) {
371
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
372
+ if (pkg.main && pkg.main.endsWith(rel)) {
373
+ pkg.main = pkg.main.replace(/\.mjs$/i, '.cjs');
374
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
375
+ }
376
+ }
377
+ emit({ type: 'status', msg: `Auto-fix: renamed ${rel} → ${path.basename(newAbs)} (Node suggests this for CJS-in-.mjs)` });
378
+ deterministicFixApplied = true;
379
+ } catch (e) {
380
+ emit({ type: 'warn', msg: `Rename ${rel} failed: ${e.message.slice(0, 200)}` });
381
+ }
382
+ }
383
+ // Case B: file is .cjs (forced CJS) using import → rename to .mjs
384
+ else if (isImportError && ext === '.cjs') {
385
+ const newAbs = abs.replace(/\.cjs$/i, '.mjs');
386
+ try {
387
+ fs.renameSync(abs, newAbs);
388
+ if (fs.existsSync(pkgPath)) {
389
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
390
+ if (pkg.main && pkg.main.endsWith(rel)) {
391
+ pkg.main = pkg.main.replace(/\.cjs$/i, '.mjs');
392
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
393
+ }
394
+ }
395
+ emit({ type: 'status', msg: `Auto-fix: renamed ${rel} → ${path.basename(newAbs)} (Node suggests this for import-in-.cjs)` });
396
+ deterministicFixApplied = true;
397
+ } catch (e) {
398
+ emit({ type: 'warn', msg: `Rename ${rel} failed: ${e.message.slice(0, 200)}` });
399
+ }
400
+ }
401
+ }
402
+ }
403
+
404
+ // Case C: ambiguous .js files — toggle package.json "type"
405
+ // ONLY effective when files are .js (extension doesn't force a mode)
406
+ if (!deterministicFixApplied && (isRequireError || isImportError) && fs.existsSync(pkgPath)) {
407
+ const onlyJsFiles = projectFiles.every(p => path.extname(p).toLowerCase() === '.js');
408
+ if (onlyJsFiles) {
409
+ try {
410
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
411
+ if (isImportError && pkg.type !== 'module') {
412
+ pkg.type = 'module';
413
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
414
+ emit({ type: 'status', msg: 'Auto-fix: added "type":"module" to package.json (for .js with import)' });
415
+ deterministicFixApplied = true;
416
+ } else if (isRequireError && pkg.type === 'module') {
417
+ delete pkg.type;
418
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
419
+ emit({ type: 'status', msg: 'Auto-fix: removed "type":"module" from package.json (for .js with require)' });
420
+ deterministicFixApplied = true;
421
+ }
422
+ } catch (e) {
423
+ emit({ type: 'warn', msg: `package.json toggle failed: ${e.message.slice(0, 200)}` });
424
+ }
425
+ }
426
+ }
427
+
428
+ if (deterministicFixApplied) {
429
+ emit({ type: 'status', msg: `Auto-fix: restarting sandbox (attempt ${_attempt + 1}/${MAX_RETRIES})...` });
430
+ return this.start(projectName, projectDir, emit, _attempt + 1);
431
+ }
432
+
381
433
  if (projectFiles.length === 0) {
382
434
  emit({ type: 'warn', msg: `Auto-fix: could not identify a target file to repair. Stack trace shown above.` });
383
435
  } else {
384
- emit({ type: 'phase', phase: 'autofix', msg: `Auto-fix repairing ${projectFiles.length} file(s): ${projectFiles.join(', ')}` });
436
+ emit({ type: 'phase', phase: 'autofix', msg: `Auto-fix repairing ${projectFiles.length} file(s) with LLM: ${projectFiles.join(', ')}` });
385
437
  let anyFixed = false;
386
438
  for (const rel of projectFiles) {
387
439
  const abs = path.join(projectDir, rel);
@@ -788,25 +788,25 @@ FRONTEND:
788
788
  - index.html: Job board homepage — (1) Hero: gradient background, large search widget (keyword input + location input + category select + Search button), quick stats bar (12,847 Jobs / 3,420 Companies / 45K Candidates). (2) Featured jobs: horizontal scroll row of 4 "Featured" cards with company logo (colored emoji), job title, company name, location + type badge + salary range + "Easy Apply" button. (3) Main layout: left sidebar filters (Job Type checkboxes, Salary Range slider, Category checkboxes, Location input, Posted Within select, Remote Only toggle) + right: jobs list (job row cards with company logo/title/company/location/type/salary/time-ago posted/Save bookmark/Apply button). (4) "Load More" button + results count "Showing 12 of 247 jobs". (5) Top companies section: 8 company cards with logo/name/industry/openings count. (6) Category browsing: 6 category cards with icon/name/count/link. (7) Job seeker CTA banner. (8) Newsletter.
789
789
  - job.html: Job detail page — company header (logo + name + industry + website + size + "Follow" button), job title + badges (Remote, Senior, Urgent), salary + location + posted date, Apply Now button (sticky on scroll), job description (markdown-rendered sections: About/Responsibilities/Requirements/Nice-to-Have/Benefits), company sidebar card (description + stats), similar jobs list (4 cards)
790
790
  - 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
791
- - 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`}],JT=[{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:`✉️`}],YT={js:`📄`,ts:`📄`,css:`🎨`,html:`🌐`,json:`📋`,md:`📑`,sql:`🗂`,env:`🔐`,conf:`⚙`,lock:`🔒`};function XT(e){return YT[e.split(`.`).pop()?.toLowerCase()??``]??`📄`}function ZT(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 QT(e){return e===`memory`?`🧠`:e===`provider`?`🤖`:e===`log`?`📄`:`📋`}function $T(){let e=j(),[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)(new Set),[w,ee]=(0,_.useState)(!1),[te,T]=(0,_.useState)(``),[ne,re]=(0,_.useState)(``),[ie,O]=(0,_.useState)(!1),[ae,A]=(0,_.useState)(null),[oe,se]=(0,_.useState)(!1),[ce,le]=(0,_.useState)([]),[ue,de]=(0,_.useState)([]),M=(0,_.useRef)(null),fe=(0,_.useRef)(null),pe=(0,_.useRef)(!0),me=(0,_.useRef)(null),he=(0,_.useRef)(null),ge=(0,_.useRef)(null),_e=(0,_.useRef)(null),[ve,ye]=(0,_.useState)(null),[be,xe]=(0,_.useState)(!1),[Se,N]=(0,_.useState)(!1),[Ce,we]=(0,_.useState)(0),[Te,Ee]=(0,_.useState)(0),[P,De]=(0,_.useState)(``),[Oe,ke]=(0,_.useState)({fi:0,total:0,name:``}),[F,I]=(0,_.useState)({tokIn:0,tokOut:0}),[Ae,je]=(0,_.useState)(null),[Me,Ne]=(0,_.useState)([]),[Pe,Fe]=(0,_.useState)(``),[Ie,Le]=(0,_.useState)(!1),[Re,ze]=(0,_.useState)([]),[L,Be]=(0,_.useState)(null),[Ve,He]=(0,_.useState)([]),[Ue,We]=(0,_.useState)(!1),[Ge,Ke]=(0,_.useState)(null),[qe,Je]=(0,_.useState)([]),[Ye,Xe]=(0,_.useState)(!1),[Ze,Qe]=(0,_.useState)(``),[$e,et]=(0,_.useState)([]),[tt,nt]=(0,_.useState)([]),[rt,it]=(0,_.useState)([]),[at,ot]=(0,_.useState)(null),[st,ct]=(0,_.useState)(!1),[lt,ut]=(0,_.useState)(!1),[dt,ft]=(0,_.useState)(null),[pt,mt]=(0,_.useState)(`0s`),[ht,gt]=(0,_.useState)(`0s`),_t=(0,_.useRef)(0),vt=(0,_.useRef)(0),yt=(0,_.useRef)(null),R=(0,_.useRef)(null),bt=(0,_.useRef)(null),xt=(0,_.useRef)(null),St=(0,_.useRef)(null),Ct=(0,_.useRef)(!1),wt=(0,_.useRef)(null);function Tt(e){console.log(`[WC-SCAN] scanning:`,e),D(`/api/studio/webcraft/scan`,{projectName:e}).then(e=>{console.log(`[WC-SCAN] result:`,e?.issues?.length,`issues`),e?.issues!==void 0&&de(e.issues)}).catch(e=>{console.error(`[WC-SCAN] error:`,e)})}(0,_.useEffect)(()=>{if(!at){le([]);return}let e=setInterval(()=>{E(`/api/studio/webcraft/sandbox/errors`).then(e=>{e?.errors?.length&&le(e.errors)}).catch(()=>{})},5e3);return()=>clearInterval(e)},[at]);let Et=(0,_.useRef)(at);Et.current=at,(0,_.useEffect)(()=>{let e=()=>{Et.current&&(navigator.sendBeacon(`/api/studio/webcraft/sandbox/stop-beacon`,``),fetch(`/api/studio/webcraft/sandbox`,{method:`DELETE`,keepalive:!0}).catch(()=>{}))};return window.addEventListener(`beforeunload`,e),()=>{window.removeEventListener(`beforeunload`,e),e()}},[]),(0,_.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key===`f`&&(e.preventDefault(),ee(e=>!e)),(e.metaKey||e.ctrlKey)&&e.key===`s`&&(e.preventDefault(),b!==null&&p[h])){let e=p[h];m(e=>e.map((e,t)=>t===h?{...e,content:b}:e)),D(`/api/studio/webcraft/file/write`,{projectName:a,path:e.name,content:b}),x(null),C(t=>{let n=new Set(t);return n.delete(e.name),n})}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[b,h,p,a]),(0,_.useEffect)(()=>{let e=()=>{let e=b===null?ge.current:he.current;e&&_e.current&&(_e.current.scrollTop=e.scrollTop)},t=b===null?ge.current:he.current;return t&&t.addEventListener(`scroll`,e),()=>{t&&t.removeEventListener(`scroll`,e)}},[b,h]);function z(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Dt(e){let t=Math.floor((Date.now()-e)/1e3),n=Math.floor(t/60);return(n>0?`${n}m `:``)+`${t%60}s`}(0,_.useEffect)(()=>(be||Se?yt.current=setInterval(()=>{be&&mt(Dt(_t.current)),Se&&gt(Dt(vt.current))},1e3):yt.current&&=(clearInterval(yt.current),null),()=>{yt.current&&clearInterval(yt.current)}),[be,Se]);function Ot(){bt.current&&(bt.current.scrollTop=bt.current.scrollHeight)}(0,_.useEffect)(()=>{Ot()},[Me]),(0,_.useEffect)(()=>{a&&!Ue&&(We(!0),E(`/api/studio/webcraft/skills/${encodeURIComponent(a)}`).then(e=>{e?.skills&&He(e.skills)}).catch(()=>{}))},[a,Ue]);async function kt(e,t){if(be||!e||e.length<5)return;xe(!0),m([]),g(0),y(null),ke({fi:0,total:0,name:``}),I({tokIn:0,tokOut:0}),_t.current=Date.now(),mt(`0s`),R.current=new AbortController;let n=Date.now();try{let r=await fetch(`/api/studio/webcraft/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},signal:R.current.signal,body:JSON.stringify({projectName:t,description:e,blocks:l,authFields:d})});if(!r.ok||!r.body){xe(!1);return}let i=r.body.getReader(),s=R.current,c=new TextDecoder,u=``,f=[];for(;;){if(s?.signal?.aborted){try{i.cancel()}catch{}break}let{done:e,value:t}=await i.read();if(e)break;u+=c.decode(t,{stream:!0});let r=u.split(`
791
+ - 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`}],JT=[{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:`✉️`}],YT={js:`📄`,ts:`📄`,css:`🎨`,html:`🌐`,json:`📋`,md:`📑`,sql:`🗂`,env:`🔐`,conf:`⚙`,lock:`🔒`};function XT(e){return YT[e.split(`.`).pop()?.toLowerCase()??``]??`📄`}function ZT(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 QT(e){return e===`memory`?`🧠`:e===`provider`?`🤖`:e===`log`?`📄`:`📋`}function $T(){let e=j(),[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)(new Set),[w,ee]=(0,_.useState)(!1),[te,T]=(0,_.useState)(``),[ne,re]=(0,_.useState)(``),[ie,O]=(0,_.useState)(!1),[ae,A]=(0,_.useState)(null),[oe,se]=(0,_.useState)(!1),[ce,le]=(0,_.useState)([]),[ue,de]=(0,_.useState)([]),M=(0,_.useRef)(null),fe=(0,_.useRef)(null),pe=(0,_.useRef)(!0),me=(0,_.useRef)(null),he=(0,_.useRef)(null),ge=(0,_.useRef)(null),_e=(0,_.useRef)(null),[ve,ye]=(0,_.useState)(null),[be,xe]=(0,_.useState)(!1),[Se,N]=(0,_.useState)(!1),[Ce,we]=(0,_.useState)(0),[Te,Ee]=(0,_.useState)(0),[P,De]=(0,_.useState)(``),[Oe,ke]=(0,_.useState)({fi:0,total:0,name:``}),[F,I]=(0,_.useState)({tokIn:0,tokOut:0}),[Ae,je]=(0,_.useState)(null),[Me,Ne]=(0,_.useState)([]),[Pe,Fe]=(0,_.useState)(``),[Ie,Le]=(0,_.useState)(!1),[Re,ze]=(0,_.useState)([]),[L,Be]=(0,_.useState)(null),[Ve,He]=(0,_.useState)([]),[Ue,We]=(0,_.useState)(!1),[Ge,Ke]=(0,_.useState)(null),[qe,Je]=(0,_.useState)([]),[Ye,Xe]=(0,_.useState)(!1),[Ze,Qe]=(0,_.useState)(``),[$e,et]=(0,_.useState)([]),[tt,nt]=(0,_.useState)([]),[rt,it]=(0,_.useState)([]),[at,ot]=(0,_.useState)(null),[st,ct]=(0,_.useState)(!1),[lt,ut]=(0,_.useState)(!1),[dt,ft]=(0,_.useState)(null),[pt,mt]=(0,_.useState)([]),[ht,gt]=(0,_.useState)(`0s`),[_t,vt]=(0,_.useState)(`0s`),yt=(0,_.useRef)(0),R=(0,_.useRef)(0),bt=(0,_.useRef)(null),xt=(0,_.useRef)(null),St=(0,_.useRef)(null),Ct=(0,_.useRef)(null),wt=(0,_.useRef)(null),Tt=(0,_.useRef)(!1),Et=(0,_.useRef)(null);function z(e){console.log(`[WC-SCAN] scanning:`,e),D(`/api/studio/webcraft/scan`,{projectName:e}).then(e=>{console.log(`[WC-SCAN] result:`,e?.issues?.length,`issues`),e?.issues!==void 0&&de(e.issues)}).catch(e=>{console.error(`[WC-SCAN] error:`,e)})}(0,_.useEffect)(()=>{if(!at){le([]);return}let e=setInterval(()=>{E(`/api/studio/webcraft/sandbox/errors`).then(e=>{e?.errors?.length&&le(e.errors)}).catch(()=>{})},5e3);return()=>clearInterval(e)},[at]);let Dt=(0,_.useRef)(at);Dt.current=at,(0,_.useEffect)(()=>{let e=()=>{Dt.current&&(navigator.sendBeacon(`/api/studio/webcraft/sandbox/stop-beacon`,``),fetch(`/api/studio/webcraft/sandbox`,{method:`DELETE`,keepalive:!0}).catch(()=>{}))};return window.addEventListener(`beforeunload`,e),()=>{window.removeEventListener(`beforeunload`,e),e()}},[]),(0,_.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key===`f`&&(e.preventDefault(),ee(e=>!e)),(e.metaKey||e.ctrlKey)&&e.key===`s`&&(e.preventDefault(),b!==null&&p[h])){let e=p[h];m(e=>e.map((e,t)=>t===h?{...e,content:b}:e)),D(`/api/studio/webcraft/file/write`,{projectName:a,path:e.name,content:b}),x(null),C(t=>{let n=new Set(t);return n.delete(e.name),n})}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[b,h,p,a]),(0,_.useEffect)(()=>{let e=()=>{let e=b===null?ge.current:he.current;e&&_e.current&&(_e.current.scrollTop=e.scrollTop)},t=b===null?ge.current:he.current;return t&&t.addEventListener(`scroll`,e),()=>{t&&t.removeEventListener(`scroll`,e)}},[b,h]);function Ot(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function kt(e){let t=Math.floor((Date.now()-e)/1e3),n=Math.floor(t/60);return(n>0?`${n}m `:``)+`${t%60}s`}(0,_.useEffect)(()=>(be||Se?bt.current=setInterval(()=>{be&&gt(kt(yt.current)),Se&&vt(kt(R.current))},1e3):bt.current&&=(clearInterval(bt.current),null),()=>{bt.current&&clearInterval(bt.current)}),[be,Se]);function At(){St.current&&(St.current.scrollTop=St.current.scrollHeight)}(0,_.useEffect)(()=>{At()},[Me]),(0,_.useEffect)(()=>{a&&!Ue&&(We(!0),E(`/api/studio/webcraft/skills/${encodeURIComponent(a)}`).then(e=>{e?.skills&&He(e.skills)}).catch(()=>{}))},[a,Ue]);async function jt(e,t){if(be||!e||e.length<5)return;xe(!0),m([]),g(0),y(null),ke({fi:0,total:0,name:``}),I({tokIn:0,tokOut:0}),yt.current=Date.now(),gt(`0s`),xt.current=new AbortController;let n=Date.now();try{let r=await fetch(`/api/studio/webcraft/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},signal:xt.current.signal,body:JSON.stringify({projectName:t,description:e,blocks:l,authFields:d})});if(!r.ok||!r.body){xe(!1);return}let i=r.body.getReader(),s=xt.current,c=new TextDecoder,u=``,f=[];for(;;){if(s?.signal?.aborted){try{i.cancel()}catch{}break}let{done:e,value:t}=await i.read();if(e)break;u+=c.decode(t,{stream:!0});let r=u.split(`
792
792
 
793
- `);u=r.pop()??``;for(let e of r){let t=e.replace(/^data: /,``).trim();if(t)try{let e=JSON.parse(t);if(e.type===`project_renamed`)o(e.name);else if(e.type===`processing`||e.type===`planning`)ke(t=>({...t,name:e.type===`planning`?`📋 Pianificazione struttura...`:e.msg||`Avvio...`}));else if(e.type===`file_start`)f.push({name:e.name,content:``,_pending:!0}),m([...f]),ke({fi:e.fi,total:e.total,name:e.name}),M.current=f.length-1,fe.current||(g(f.length-1),y(``)),pe.current=!0;else if(e.type===`file_chunk`){let t=f.find(t=>t.name===e.name);t&&(t.content+=e.chunk,t._pending=!1),m([...f]);let n=f.findIndex(t=>t.name===e.name);n>=0&&(M.current=n,y(t?t.content:null))}else if(e.type===`file_done`){let t=f.find(t=>t.name===e.name);t&&(t._pending=!1,e.syntaxError&&(t._syntaxError=e.syntaxError)),m([...f]),ke({fi:e.fi,total:e.total,name:e.name}),(e.cumTokIn||e.cumTokOut)&&I({tokIn:e.cumTokIn||0,tokOut:e.cumTokOut||0})}else if(e.type===`file_error`){let t=f.find(t=>t.name===e.name);t&&(t._error=!0,t._pending=!1),m([...f])}else e.type===`phase`||e.type===`status`&&!e.op?ke(t=>({...t,name:e.msg||e.phase||``})):e.type===`done`&&(je({seconds:Math.round((Date.now()-n)/1e3),tokIn:e.tokIn??0,tokOut:e.tokOut??0,files:f.length}),y(null),xe(!1),M.current=null,fe.current&&=(clearTimeout(fe.current),null),a&&Tt(a),se(!0),We(!1),He([]),f.some(e=>e._error||e._syntaxError)?setTimeout(()=>St.current?.(),800):setTimeout(()=>wt.current?.(),800))}catch{}}}}catch(e){e.name!==`AbortError`&&Ne(t=>[...t,{role:`system`,text:`Errore generazione: `+e.message}]),xe(!1)}}async function At(){let e=Pe.trim();if(!(a&&p.length>0)){if(!e||e.length<5)return;let t=a||`MyProject`;o(t),c(e),Fe(``),await kt(e,t);return}if(!e&&Re.length===0||Ie||be)return;let t=[...Re];if(ze([]),Fe(``),e.toLowerCase().startsWith(`/plan `)||e.toLowerCase().startsWith(`piano: `)){let t=e.replace(/^\/plan[ ]*/i,``).replace(/^piano:[ ]*/i,``);Ne(t=>[...t,{role:`user`,text:e}]),await jt(`[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}Ne(n=>[...n,{role:`user`,text:e,attachments:t}]),await jt(e,null,t)}async function jt(e,t,n){if(Ie)return;Le(!0),a&&p.length>0&&D(`/api/studio/webcraft/snapshot`,{projectName:a}).catch(()=>{});let r={};p.forEach(e=>{r[e.name]=e.content});try{let i=new AbortController;R.current=i;let o=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}))}),signal:i.signal});if(!o.ok||!o.body){Ne(e=>[...e,{role:`agent`,text:`Errore: ${o.status}`,tools:[]}]),Le(!1);return}let s={role:`agent`,text:``,tools:[]};Ne(e=>[...e,s]);let c=o.body.getReader(),l=new TextDecoder,u=``,d=!1,f=``;for(;;){if(i.signal.aborted){try{c.cancel()}catch{}break}let{done:e,value:n}=await c.read();if(e)break;u+=l.decode(n,{stream:!0});let o=u.split(`
793
+ `);u=r.pop()??``;for(let e of r){let t=e.replace(/^data: /,``).trim();if(t)try{let e=JSON.parse(t);if(e.type===`project_renamed`)o(e.name);else if(e.type===`processing`||e.type===`planning`)ke(t=>({...t,name:e.type===`planning`?`📋 Pianificazione struttura...`:e.msg||`Avvio...`}));else if(e.type===`file_start`)f.push({name:e.name,content:``,_pending:!0}),m([...f]),ke({fi:e.fi,total:e.total,name:e.name}),M.current=f.length-1,fe.current||(g(f.length-1),y(``)),pe.current=!0;else if(e.type===`file_chunk`){let t=f.find(t=>t.name===e.name);t&&(t.content+=e.chunk,t._pending=!1),m([...f]);let n=f.findIndex(t=>t.name===e.name);n>=0&&(M.current=n,y(t?t.content:null))}else if(e.type===`file_done`){let t=f.find(t=>t.name===e.name);t&&(t._pending=!1,e.syntaxError&&(t._syntaxError=e.syntaxError)),m([...f]),ke({fi:e.fi,total:e.total,name:e.name}),(e.cumTokIn||e.cumTokOut)&&I({tokIn:e.cumTokIn||0,tokOut:e.cumTokOut||0})}else if(e.type===`file_error`){let t=f.find(t=>t.name===e.name);t&&(t._error=!0,t._pending=!1),m([...f])}else e.type===`phase`||e.type===`status`&&!e.op?ke(t=>({...t,name:e.msg||e.phase||``})):e.type===`done`&&(je({seconds:Math.round((Date.now()-n)/1e3),tokIn:e.tokIn??0,tokOut:e.tokOut??0,files:f.length}),y(null),xe(!1),M.current=null,fe.current&&=(clearTimeout(fe.current),null),a&&z(a),se(!0),We(!1),He([]),f.some(e=>e._error||e._syntaxError)?setTimeout(()=>wt.current?.(),800):setTimeout(()=>Et.current?.(),800))}catch{}}}}catch(e){e.name!==`AbortError`&&Ne(t=>[...t,{role:`system`,text:`Errore generazione: `+e.message}]),xe(!1)}}async function B(){let e=Pe.trim();if(!(a&&p.length>0)){if(!e||e.length<5)return;let t=a||`MyProject`;o(t),c(e),Fe(``),await jt(e,t);return}if(!e&&Re.length===0||Ie||be)return;let t=[...Re];if(ze([]),Fe(``),e.toLowerCase().startsWith(`/plan `)||e.toLowerCase().startsWith(`piano: `)){let t=e.replace(/^\/plan[ ]*/i,``).replace(/^piano:[ ]*/i,``);Ne(t=>[...t,{role:`user`,text:e}]),await Mt(`[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}Ne(n=>[...n,{role:`user`,text:e,attachments:t}]),await Mt(e,null,t)}async function Mt(e,t,n){if(Ie)return;Le(!0),a&&p.length>0&&D(`/api/studio/webcraft/snapshot`,{projectName:a}).catch(()=>{});let r={};p.forEach(e=>{r[e.name]=e.content});try{let i=new AbortController;xt.current=i;let o=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}))}),signal:i.signal});if(!o.ok||!o.body){Ne(e=>[...e,{role:`agent`,text:`Errore: ${o.status}`,tools:[]}]),Le(!1);return}let s={role:`agent`,text:``,tools:[]};Ne(e=>[...e,s]);let c=o.body.getReader(),l=new TextDecoder,u=``,d=!1,f=``;for(;;){if(i.signal.aborted){try{c.cancel()}catch{}break}let{done:e,value:n}=await c.read();if(e)break;u+=l.decode(n,{stream:!0});let o=u.split(`
794
794
 
795
- `);u=o.pop()??``;for(let e of o){let n=e.replace(/^data: /,``).trim();if(n)try{let e=JSON.parse(n);if(e.type===`text`){f+=e.token;let t=f.lastIndexOf(`<`),n;t>=0&&!f.slice(t).includes(`>`)?(n=f.slice(0,t),f=f.slice(t)):(n=f.replace(/<tool>[\s\S]*?<\/tool>/g,``).replace(/<done\s*\/>/g,``),f=``),n&&(s.text+=n)}else if(e.type===`step`)s.text+=`\n\n**[Step ${e.step}/${e.max}]** `;else if(e.type===`tool`)(e.op===`edit`||e.op===`write`)&&console.log(`[WC-DEBUG] tool event:`,e.op,e.path,`result:`,e.result,`oldSnippet:`,(e.oldSnippet||``).length,`newSnippet:`,(e.newSnippet||``).length),s.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`||e.result===`ok_fuzzy`||e.result===`ok_repaired`)&&(d=!0),Ne(e=>{let t=[...e];return t[t.length-1]={...s},t});else if(e.type===`files_changed`)e.files?.length&&await B(e.files,r);else if(e.type===`syntax_errors`)e.errors?.length&&(s.syntaxErrors=e.errors,Ne(e=>{let t=[...e];return t[t.length-1]={...s},t}));else if(e.type===`sandbox_restart`)s.text+=`
795
+ `);u=o.pop()??``;for(let e of o){let n=e.replace(/^data: /,``).trim();if(n)try{let e=JSON.parse(n);if(e.type===`text`){f+=e.token;let t=f.lastIndexOf(`<`),n;t>=0&&!f.slice(t).includes(`>`)?(n=f.slice(0,t),f=f.slice(t)):(n=f.replace(/<tool>[\s\S]*?<\/tool>/g,``).replace(/<done\s*\/>/g,``),f=``),n&&(s.text+=n)}else if(e.type===`step`)s.text+=`\n\n**[Step ${e.step}/${e.max}]** `;else if(e.type===`tool`)(e.op===`edit`||e.op===`write`)&&console.log(`[WC-DEBUG] tool event:`,e.op,e.path,`result:`,e.result,`oldSnippet:`,(e.oldSnippet||``).length,`newSnippet:`,(e.newSnippet||``).length),s.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`||e.result===`ok_fuzzy`||e.result===`ok_repaired`)&&(d=!0),Ne(e=>{let t=[...e];return t[t.length-1]={...s},t});else if(e.type===`files_changed`)e.files?.length&&await Nt(e.files,r);else if(e.type===`syntax_errors`)e.errors?.length&&(s.syntaxErrors=e.errors,Ne(e=>{let t=[...e];return t[t.length-1]={...s},t}));else if(e.type===`sandbox_restart`)s.text+=`
796
796
 
797
797
  🔄 `+(e.msg||`Restarting sandbox...`),Ne(e=>{let t=[...e];return t[t.length-1]={...s},t});else if(e.type===`sandbox_ready`)ot(e.port),s.text+=`
798
798
  ✅ Sandbox ready on port `+e.port,Ne(e=>{let t=[...e];return t[t.length-1]={...s},t});else if(e.type===`sandbox_error`)s.text+=`
799
- ❌ Sandbox error: `+e.msg,Ne(e=>{let t=[...e];return t[t.length-1]={...s},t});else if(e.type===`done`){if(f){let e=f.replace(/<tool>[\s\S]*?<\/tool>/g,``).replace(/<done\s*\/>/g,``);e&&(s.text+=e),f=``}t&&!d&&Be({plan:s.text,originalMessage:t}),Le(!1),await B((s.tools??[]).filter(e=>(e.op===`edit`||e.op===`write`)&&(e.result===`ok`||e.result===`ok_fuzzy`||e.result===`ok_repaired`)).map(e=>e.path),r),a&&Tt(a)}else e.type===`error`&&(s.text+=`
800
- Errore: `+e.msg,Le(!1))}catch{}}}}catch(e){e instanceof DOMException&&e.name===`AbortError`||Ne(t=>[...t,{role:`agent`,text:`Errore di rete: `+e.message,tools:[]}])}if(Le(!1),a){try{let e=await E(`/api/studio/webcraft/projects/load/${encodeURIComponent(a)}`);e?.files&&m(e.files)}catch{}setTimeout(()=>{a&&Tt(a)},200)}}async function B(e,t){if(!a)return;let n=await E(`/api/studio/webcraft/projects/load/${encodeURIComponent(a)}`);if(n?.files&&(m(n.files),a&&setTimeout(()=>Tt(a),300),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);nt(e=>[...e,...r])}}function Mt(){R.current&&=(R.current.abort(),null),Ct.current=!0,xe(!1),Le(!1),N(!1),De(``),y(null),Ne(e=>[...e,{role:`system`,text:`⏹ Generazione interrotta.`}])}async function Nt(){return a?(await D(`/api/studio/webcraft/snapshot`,{projectName:a}))?.snapshot??null:null}async function Pt(){let e=await Nt();e&&(Ne(t=>[...t,{role:`system`,text:`💾 Snapshot salvato (${e.slice(0,16).replace(`T`,` `)})`}]),Ft())}async function Ft(){if(!a)return;let e=await E(`/api/studio/webcraft/snapshots/${encodeURIComponent(a)}`);e?.snapshots&&Je(e.snapshots)}async function It(e){confirm(`Ripristinare lo snapshot del ${e.replace(`T`,` `).slice(0,16)}? I file attuali verranno sovrascritti.`)&&await D(`/api/studio/webcraft/restore`,{projectName:a,ts:e})!==null&&(Ne(t=>[...t,{role:`agent`,text:`Snapshot ripristinato (${e}). Ricarico i file...`}]),B([],{}))}async function Lt(){if(!a)return;let e=await D(`/api/studio/webcraft/syntax-check`,{projectName:a});if(e?.results){let t=e.results.filter(e=>!e.ok);t.length>0?Ne(e=>[...e,{role:`system`,text:`⚠ Syntax check: ${t.length} errore/i trovato/i.`,syntaxErrors:t}]):Ne(e=>[...e,{role:`system`,text:`✓ Syntax check: tutti i file JS sono validi.`}])}}async function Rt(){let e=p.filter(e=>e._error||e._syntaxError);if(e.length===0){wt.current?.();return}Ct.current=!1,N(!0),we(0),Ee(e.length),vt.current=Date.now(),gt(`0s`);for(let t=0;t<e.length&&!Ct.current;t++){let n=e[t];De(n.name),we(t);let r=`FIX ERROR in ${n.name}: ${n._syntaxError??`generazione fallita`}\n\nUse the edit tool to make surgical fixes. Do NOT rewrite the entire file — only change the broken parts. Read the file first, identify the exact lines with errors, and edit only those lines.`;try{await jt(r,null,[])}catch{if(Ct.current)break}}a&&Tt(a),Ct.current||(we(e.length),setTimeout(()=>wt.current?.(),500)),De(``),N(!1)}async function zt(e){if(!lt){ut(!0),ft(null),ot(null),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){ft(t.ok?`No response body`:`HTTP ${t.status}`),ut(!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(`
801
-
802
- `);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`||(e.type===`ready`&&e.port?(ot(e.port),ut(!1)):e.type===`status`||e.type===`log`||e.type===`warn`||(e.type===`error`?ft(e.msg):e.type))}catch{}}}}catch(e){ft(e.message||`Connection failed`)}ut(!1)}}async function Bt(){a&&await zt(a)}(0,_.useEffect)(()=>{St.current=Rt,wt.current=Bt});async function V(){if(!Ze||!a)return;let e=await D(`/api/studio/webcraft/grep`,{projectName:a,query:Ze});e?.matches&&et(e.matches)}function Vt(e){let t=p.findIndex(t=>t.name===e);t>=0&&(g(t),i(`files`))}function Ht(){window.open(`/api/studio/webcraft/download/${encodeURIComponent(a)}`,`_blank`)}async function Ut(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],He(s),Ke(null);let c=a||`MyProject`;a||o(c),await D(`/api/studio/webcraft/skills/${encodeURIComponent(c)}`,{skills:s})}async function Wt(e){let t=Ve[e];!t||!confirm(`Eliminare "${t.name}"?`)||(await D(`/api/studio/webcraft/skills/${encodeURIComponent(a)}/delete`,{name:t.name}),He(Ve.filter((t,n)=>n!==e)))}async function Gt(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);He(n),await D(`/api/studio/webcraft/skills/${encodeURIComponent(a)}`,{skills:n})}async function Kt(){let e=await E(`/api/studio/webcraft/projects`);e?.projects&&it(e.projects)}async function qt(e){let t=await E(`/api/studio/webcraft/projects/load/${encodeURIComponent(e.name)}`);if(!t)return;let r=t.projectName??e.name;o(r),c(t.description??``),m(t.files??[]),g(0),n(`new`),i(`files`),Ne([]),He([]),We(!1),de([]),Tt(r);let a=await E(`/api/studio/webcraft/projects/chat/load/${encodeURIComponent(r)}`);a?.chat&&Ne(a.chat);let s=await E(`/api/studio/webcraft/skills/${encodeURIComponent(r)}`);s?.skills&&(He(s.skills),We(!0))}async function H(e){confirm(`Eliminare: ${e.name} - ${e.dir}?`)&&(await D(`/api/studio/webcraft/projects/${encodeURIComponent(e.name)}`,{},`DELETE`),it(rt.filter(t=>t.name!==e.name)),a===e.name&&(o(``),m([]),Ne([]),c(``)))}async function Jt(){if(!L)return;let e=L.originalMessage;Be(null),await jt(e+`
803
- [Piano approvato — procedi con le modifiche]`,null,[])}function Yt(e){e&&Array.from(e).forEach(e=>{let t=new FileReader;t.onload=t=>{let n=(t.target?.result).split(`,`)[1];ze(t=>[...t,{name:e.name,mimeType:e.type,base64:n,size:e.size}])},t.readAsDataURL(e)})}let Xt=a&&p.length>0,Zt=p[h],Qt=Ie||be;return(0,k.jsxs)(`div`,{className:Q.root,children:[(0,k.jsxs)(`div`,{className:Q.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`div`,{className:Q.title,children:[`⚙ WebCraft`,a?` — ${a}`:``]}),!a&&(0,k.jsx)(`div`,{className:Q.subtitle,children:`Genera progetti web completi con agenti AI`})]}),(0,k.jsxs)(`div`,{className:Q.headerTabs,children:[(0,k.jsx)(`button`,{className:`${Q.tabBtn} ${t===`new`?Q.tabActive:``}`,onClick:async()=>{if(!(S.size>0&&!confirm(`${S.size} unsaved file(s). Discard changes and create new project?`))){if(at){try{await fetch(`/api/studio/webcraft/sandbox`,{method:`DELETE`})}catch{}ot(null)}m([]),g(0),y(null),x(null),C(new Set),Ne([]),o(``),c(``),Fe(``),He([]),We(!1),je(null),xe(!1),Le(!1),O(!1),A(null),n(`new`)}},children:`+ Nuovo`}),(0,k.jsx)(`button`,{className:`${Q.tabBtn} ${t===`projects`?Q.tabActive:``}`,onClick:()=>{n(`projects`),Kt()},children:`📁 Progetti`})]})]}),(0,k.jsx)(`div`,{className:Q.body,children:t===`projects`?(0,k.jsx)(`div`,{className:Q.projectsList,children:rt.length===0?(0,k.jsxs)(`div`,{className:Q.emptyProjects,children:[(0,k.jsx)(`span`,{className:Q.emptyIcon,children:`📁`}),(0,k.jsx)(`span`,{children:e(`webcraft.noProjects`)}),(0,k.jsx)(`span`,{className:Q.emptyHint,children:`Crea un progetto nella tab Nuovo`})]}):rt.map(e=>(0,k.jsxs)(`div`,{className:Q.projectCard,children:[(0,k.jsxs)(`div`,{className:Q.projectInfo,children:[(0,k.jsx)(`div`,{className:Q.projectName,children:e.name}),(0,k.jsx)(`div`,{className:Q.projectDesc,children:e.description}),(0,k.jsxs)(`div`,{className:Q.projectMeta,children:[(0,k.jsxs)(`span`,{children:[`📄 `,e.fileCount,` file`]}),(0,k.jsxs)(`span`,{children:[`📅 `,e.createdAt?new Date(e.createdAt).toLocaleString():``]})]})]}),(0,k.jsx)(`button`,{className:Q.openBtn,onClick:()=>qt(e),children:`↗ Apri`}),(0,k.jsx)(`button`,{className:Q.deleteBtn,onClick:()=>H(e),children:`🗑`})]},e.name))}):(0,k.jsxs)(`div`,{className:Q.editor,children:[(0,k.jsxs)(`div`,{className:Q.examples,children:[(0,k.jsx)(`div`,{className:Q.sectionLabel,children:`Esempi`}),(0,k.jsx)(`div`,{className:Q.examplePills,children:qT.map(e=>(0,k.jsx)(`button`,{className:Q.examplePill,onClick:()=>{o(e.name),c(e.desc),Fe(e.desc)},children:e.name},e.name))})]}),(0,k.jsxs)(`div`,{className:Q.editorCols,children:[(0,k.jsxs)(`div`,{className:Q.leftSidebar,children:[(0,k.jsxs)(`div`,{className:Q.panel,children:[(0,k.jsx)(`div`,{className:Q.panelTitle,children:`Blocchi`}),JT.map(e=>(0,k.jsxs)(`label`,{className:Q.blockLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:l[e.key],onChange:t=>u(n=>({...n,[e.key]:t.target.checked})),className:Q.blockCheck}),(0,k.jsx)(`span`,{children:e.icon}),(0,k.jsx)(`span`,{children:e.label})]},e.key))]}),l.auth&&(0,k.jsxs)(`div`,{className:Q.panel,children:[(0,k.jsxs)(`div`,{className:Q.panelHeader,children:[(0,k.jsx)(`div`,{className:Q.panelTitle,children:`Campi Auth`}),(0,k.jsx)(`button`,{className:Q.addBtn,onClick:()=>f(e=>[...e,{label:`New field`,type:`text`,required:!1}]),children:`+ Campo`})]}),d.map((e,t)=>(0,k.jsxs)(`div`,{className:Q.authField,children:[(0,k.jsx)(`input`,{value:e.label,onChange:e=>f(n=>n.map((n,r)=>r===t?{...n,label:e.target.value}:n)),className:Q.authFieldInput}),(0,k.jsx)(`select`,{value:e.type,onChange:e=>f(n=>n.map((n,r)=>r===t?{...n,type:e.target.value}:n)),className:Q.authFieldSelect,children:[`text`,`email`,`password`,`tel`,`date`,`number`].map(e=>(0,k.jsx)(`option`,{value:e,children:e},e))}),(0,k.jsx)(`input`,{type:`checkbox`,checked:e.required,onChange:e=>f(n=>n.map((n,r)=>r===t?{...n,required:e.target.checked}:n)),title:`Required`,className:Q.authFieldReq}),(0,k.jsx)(`button`,{onClick:()=>f(e=>e.filter((e,n)=>n!==t)),className:Q.removeFieldBtn,children:`×`})]},t))]}),(0,k.jsxs)(`div`,{className:Q.panel,children:[(0,k.jsxs)(`div`,{className:Q.panelHeader,children:[(0,k.jsx)(`div`,{className:Q.panelTitle,children:`🗂 Contesto AI`}),(0,k.jsx)(`button`,{className:Q.addBtn,onClick:()=>Ke({mode:`new`,idx:null,name:``,content:``,type:`skill`,generating:!1}),children:`+ Skill`})]}),Ve.length>0?(0,k.jsx)(`div`,{className:Q.skillsList,children:Ve.map((e,t)=>(0,k.jsxs)(`div`,{className:Q.skillRow,children:[(0,k.jsx)(`span`,{className:Q.skillIcon,children:QT(e.type)}),(0,k.jsx)(`span`,{className:Q.skillName,title:e.name,children:e.name}),(0,k.jsx)(`span`,{className:`${Q.skillBadge} ${Q[`skillBadge_`+e.type]}`,children:e.type}),!e.content&&e.type!==`log`&&(0,k.jsx)(`span`,{className:Q.skillEmpty,children:`⚠`}),(0,k.jsx)(`button`,{className:Q.skillBtn,onClick:()=>Ke({mode:e.type===`log`?`view`:`edit`,idx:t,name:e.name,content:e.content,type:e.type,generating:!1}),children:e.type===`log`?`👁`:`✏`}),e.type!==`memory`&&e.type!==`provider`&&e.type!==`log`&&(0,k.jsx)(`button`,{className:Q.skillBtn,onClick:()=>Gt(t),children:`🗑`}),e.type===`log`&&(0,k.jsx)(`button`,{className:Q.skillBtn,onClick:()=>Wt(t),children:`🗑`})]},t))}):(0,k.jsx)(`div`,{className:Q.skillsEmpty,children:Ue?`Nessun file di contesto. Clicca "+ Skill" per aggiungerne uno.`:`Crea o carica un progetto per i file di contesto.`})]}),qe.length>0&&(0,k.jsxs)(`div`,{className:Q.panel,children:[(0,k.jsx)(`div`,{className:Q.panelTitle,children:`💾 Snapshot`}),qe.slice(0,5).map(e=>{let t=e.ts.replace(`T`,` `).slice(0,16);return(0,k.jsxs)(`div`,{className:Q.snapshotRow,children:[(0,k.jsx)(`span`,{className:Q.snapshotTs,children:t}),(0,k.jsxs)(`span`,{className:Q.snapshotCount,children:[e.fileCount,`f`]}),(0,k.jsx)(`button`,{className:Q.snapshotBtn,onClick:()=>It(e.ts),children:`↺`})]},e.ts)})]}),be&&(0,k.jsx)(`div`,{className:Q.genStatus,children:`⏳ Generazione...`}),Se&&(0,k.jsxs)(`div`,{className:Q.repairStatus,children:[(0,k.jsx)(`div`,{className:Q.repairStatusTitle,children:`🔧 Correzione automatica...`}),(0,k.jsxs)(`div`,{className:Q.repairStatusProg,children:[Ce,` / `,Te,` file`]}),(0,k.jsx)(`div`,{className:Q.repairStatusFile,children:P})]}),p.length>0&&!be&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:Q.actionRow,children:[(0,k.jsx)(`button`,{className:Q.actionBtn,onClick:Ht,children:`⬇ ZIP`}),(0,k.jsx)(`button`,{className:Q.actionBtnIcon,title:`Syntax check`,onClick:Lt,children:`✅`}),(0,k.jsx)(`button`,{className:`${Q.actionBtnIcon} ${Ye?Q.actionBtnActive:``}`,title:`Grep`,onClick:()=>Xe(!Ye),children:`🔍`}),(0,k.jsx)(`button`,{className:Q.actionBtnIcon,title:`Snapshot`,onClick:Pt,children:`💾`})]}),p.some(e=>e._error||e._syntaxError)&&!Se&&(0,k.jsx)(`button`,{className:Q.repairBtn,onClick:Rt,children:`🔧 Correggi tutti i file rossi`}),(0,k.jsx)(`button`,{className:Q.sandboxBtn,onClick:()=>{a?zt(a):i(`preview`)},children:lt?`⏳ Starting...`:at?`🌐 Sandbox Live`:`▶ Sandbox`}),Ae&&(0,k.jsxs)(`div`,{className:Q.statsBar,children:[(0,k.jsxs)(`span`,{children:[`⏱ `,Ae.seconds>=60?`${Math.floor(Ae.seconds/60)}m ${Ae.seconds%60}s`:`${Ae.seconds}s`]}),(0,k.jsxs)(`span`,{children:[`↑ `,Ae.tokIn.toLocaleString(),` tok`]}),(0,k.jsxs)(`span`,{children:[`↓ `,Ae.tokOut.toLocaleString(),` tok`]}),(0,k.jsxs)(`span`,{children:[`📄 `,Ae.files,` file`]})]})]})]}),(0,k.jsxs)(`div`,{className:Q.rightPanel,children:[(0,k.jsxs)(`div`,{className:Q.rightTabBar,children:[(0,k.jsx)(`button`,{className:`${Q.rightTab} ${r===`preview`?``:Q.rightTabActive}`,onClick:()=>i(`files`),children:`📄 File`}),(0,k.jsx)(`button`,{className:`${Q.rightTab} ${r===`preview`?Q.rightTabActive:``}`,onClick:()=>i(`preview`),children:`🌐 Sandbox`})]}),Se&&(0,k.jsxs)(`div`,{className:Q.repairBar,children:[(0,k.jsxs)(`div`,{className:Q.repairBarRow,children:[(0,k.jsx)(`span`,{className:Q.repairBarIcon,children:`🔧`}),(0,k.jsx)(`span`,{className:Q.repairBarLabel,children:`Auto-fix`}),(0,k.jsx)(`span`,{className:Q.repairBarFile,children:P}),(0,k.jsxs)(`span`,{className:Q.repairBarCounter,children:[Ce,` / `,Te]}),(0,k.jsx)(`span`,{className:Q.repairBarTime,children:ht}),(0,k.jsx)(`button`,{className:Q.stopBtn,onClick:Mt,children:`⏹ Stop`})]}),(0,k.jsx)(`div`,{className:Q.progressTrack,children:(0,k.jsx)(`div`,{className:Q.repairProgress,style:{width:Te>0?`${Math.round(Ce/Te*100)}%`:`0%`}})})]}),be&&(0,k.jsxs)(`div`,{className:Q.genBar,children:[(0,k.jsxs)(`div`,{className:Q.genBarRow,children:[(0,k.jsx)(`span`,{className:Q.genBarRobot,children:`🤖`}),(0,k.jsx)(`span`,{className:Q.genBarLabel,children:Oe.total===0?`Pianificazione...`:`Generazione`}),(0,k.jsx)(`span`,{className:Q.genBarFile,children:(Oe.name||``).split(`,`)[0].trim()}),(0,k.jsx)(`span`,{className:Q.genBarCounter,children:Oe.total>0?`${Oe.fi} / ${Oe.total}`:``}),(0,k.jsx)(`span`,{className:Q.genBarCounter,children:F.tokIn+F.tokOut>0?`↑${z(F.tokIn)} ↓${z(F.tokOut)}`:``}),(0,k.jsx)(`span`,{className:Q.genBarTime,children:pt}),(0,k.jsxs)(`span`,{className:Q.genDots,children:[(0,k.jsx)(`span`,{className:`${Q.dot} ${Q.dot1}`}),(0,k.jsx)(`span`,{className:`${Q.dot} ${Q.dot2}`}),(0,k.jsx)(`span`,{className:`${Q.dot} ${Q.dot3}`})]})]}),(0,k.jsx)(`div`,{className:Q.progressTrack,children:(0,k.jsx)(`div`,{className:Q.genProgress,style:{width:Oe.total>0?`${Math.round(Oe.fi/Oe.total*100)}%`:`0%`}})})]}),r===`preview`?(0,k.jsxs)(`div`,{className:Q.sandboxWrap,children:[(0,k.jsxs)(`div`,{className:Q.sandboxStatusBar,children:[(0,k.jsx)(`span`,{className:Q.sandboxStatusDot,style:{background:at?`#4ade80`:lt?`#facc15`:`#64748b`}}),(0,k.jsx)(`span`,{className:Q.sandboxStatusText,children:at?`Live :${at}`:lt?`Starting...`:`Stopped`}),at&&(0,k.jsx)(`button`,{className:Q.sandboxReloadBtn,onClick:()=>{let e=document.querySelector(`iframe[title="WebCraft Sandbox"]`);e&&(e.src=e.src)},children:`↻`}),at&&(0,k.jsx)(`button`,{className:Q.sandboxStopBtn,onClick:async()=>{ot(null),le([]);try{await fetch(`/api/studio/webcraft/sandbox`,{method:`DELETE`})}catch{}},children:`⏹`}),!at&&!lt&&(0,k.jsx)(`button`,{className:Q.sandboxStartBtnSmall,onClick:()=>{a&&zt(a)},children:`▶ Start`})]}),ce.length>0&&(0,k.jsxs)(`div`,{className:Q.runtimeErrors,children:[(0,k.jsxs)(`div`,{className:Q.runtimeErrorsHeader,children:[(0,k.jsxs)(`span`,{children:[`❌ `,ce.length,` runtime error`,ce.length>1?`s`:``]}),(0,k.jsx)(`button`,{className:Q.runtimeErrorsFix,onClick:()=>{Fe(`Fix these runtime errors:\n${ce.map(e=>`${e.message} (${e.source||``}:${e.line||0})`).join(`
804
- `)}`),fetch(`/api/studio/webcraft/sandbox/errors`,{method:`DELETE`}),le([]),i(`files`)},children:`🔧 Auto-fix`}),(0,k.jsx)(`button`,{className:Q.runtimeErrorsDismiss,onClick:()=>{fetch(`/api/studio/webcraft/sandbox/errors`,{method:`DELETE`}),le([])},children:`✕`})]}),ce.slice(0,3).map((e,t)=>(0,k.jsxs)(`div`,{className:Q.runtimeErrorLine,children:[e.message,e.source?` — ${e.source.split(`/`).pop()}:${e.line}`:``]},t))]}),at?(0,k.jsx)(`iframe`,{src:`http://localhost:${at}`,className:Q.sandboxFrame,title:`WebCraft Sandbox`,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups`}):(0,k.jsxs)(`div`,{className:Q.sandboxEmpty,children:[(0,k.jsx)(`span`,{style:{fontSize:48},children:lt?`⏳`:dt?`❌`:`🌐`}),(0,k.jsx)(`span`,{style:{fontWeight:700,fontSize:16},children:lt?`Starting sandbox...`:dt?`Sandbox Error`:`Preview`}),dt&&(0,k.jsx)(`pre`,{style:{fontSize:11,maxWidth:600,textAlign:`left`,color:`#f87171`,background:`rgba(248,113,113,0.08)`,border:`1px solid rgba(248,113,113,0.2)`,borderRadius:6,padding:`8px 12px`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,margin:`8px 0`,lineHeight:1.5,maxHeight:200,overflow:`auto`},children:dt}),!lt&&(0,k.jsxs)(`button`,{className:Q.sandboxStartBtn,onClick:()=>{a&&zt(a)},children:[`▶ `,dt?`Retry`:`Start Sandbox`]})]})]}):(0,k.jsx)(`div`,{className:Q.codeArea,children:p.length===0&&be?(0,k.jsx)(`div`,{className:Q.noFiles,children:(0,k.jsxs)(`div`,{className:Q.noFilesHero,children:[(0,k.jsx)(`span`,{className:Q.noFilesIcon,children:`⏳`}),(0,k.jsx)(`span`,{className:Q.noFilesTitle,children:`Pianificazione...`}),(0,k.jsx)(`span`,{className:Q.noFilesTagline,children:Oe.name||`Analisi della struttura del progetto in corso`})]})}):p.length===0?(0,k.jsxs)(`div`,{className:Q.noFiles,children:[(0,k.jsxs)(`div`,{className:Q.noFilesHero,children:[(0,k.jsx)(`span`,{className:Q.noFilesIcon,children:`🔨`}),(0,k.jsx)(`span`,{className:Q.noFilesTitle,children:`WebCraft`}),(0,k.jsx)(`span`,{className:Q.noFilesTagline,children:`Genera progetti web completi con AI`})]}),(0,k.jsxs)(`div`,{className:Q.noFilesSteps,children:[(0,k.jsxs)(`div`,{className:Q.noFilesStep,children:[(0,k.jsx)(`span`,{className:Q.noFilesStepNum,children:`1`}),(0,k.jsx)(`span`,{children:`Scegli un esempio o scrivi una descrizione nel box in basso`})]}),(0,k.jsxs)(`div`,{className:Q.noFilesStep,children:[(0,k.jsx)(`span`,{className:Q.noFilesStepNum,children:`2`}),(0,k.jsxs)(`span`,{children:[`Premi `,(0,k.jsx)(`strong`,{children:`▶ Genera`}),` — l'AI crea tutti i file del progetto`]})]}),(0,k.jsxs)(`div`,{className:Q.noFilesStep,children:[(0,k.jsx)(`span`,{className:Q.noFilesStepNum,children:`3`}),(0,k.jsx)(`span`,{children:`Chiedi modifiche in chat, scarica lo ZIP o avvia il Sandbox`})]})]}),(0,k.jsxs)(`div`,{className:Q.noFilesExamplesHint,children:[`💡 Prova: `,(0,k.jsx)(`button`,{className:Q.noFilesExampleBtn,onClick:()=>{let e=qT[0];o(e.name),c(e.desc),Fe(e.desc)},children:`MySaaS`}),(0,k.jsx)(`button`,{className:Q.noFilesExampleBtn,onClick:()=>{let e=qT[1];o(e.name),c(e.desc),Fe(e.desc)},children:`MyShop`}),(0,k.jsx)(`button`,{className:Q.noFilesExampleBtn,onClick:()=>{let e=qT[3];o(e.name),c(e.desc),Fe(e.desc)},children:`MyPortfolio`})]})]}):(0,k.jsxs)(`div`,{className:Q.codeLayout,children:[(0,k.jsx)(`div`,{className:Q.ideTabBar,children:p.map((e,t)=>{let n=e._error||!!e._syntaxError,r=t===h;return(0,k.jsxs)(`button`,{className:`${Q.ideTab} ${r?Q.ideTabActive:``} ${n?Q.ideTabError:``} ${e._pending?Q.ideTabPending:``}`,onClick:()=>{g(t),x(null),y(null),be&&M.current!==null&&t!==M.current&&(fe.current&&clearTimeout(fe.current),fe.current=setTimeout(()=>{M.current!==null&&(g(M.current),y(null))},1e4))},title:e.name,children:[(0,k.jsx)(`span`,{className:Q.ideTabIcon,children:e._pending?`⌛`:n?`⚠`:XT(e.name)}),(0,k.jsx)(`span`,{className:Q.ideTabName,children:(e.name||``).split(`/`).pop()}),S.has(e.name)&&(0,k.jsx)(`span`,{className:Q.ideTabUnsaved,children:`●`}),n&&(0,k.jsx)(`span`,{className:Q.ideTabDot})]},t)})}),ve&&(0,k.jsxs)(`div`,{className:Q.diffOverlay,children:[(0,k.jsxs)(`div`,{className:Q.diffOverlayHeader,children:[(0,k.jsxs)(`span`,{children:[`✏ Modifica proposta — `,(0,k.jsx)(`strong`,{children:ve.file})]}),(0,k.jsxs)(`div`,{className:Q.diffOverlayActions,children:[(0,k.jsx)(`button`,{className:Q.diffAcceptBtn,onClick:()=>{m(e=>e.map(e=>e.name===ve.file?{...e,content:ve.after}:e)),ye(null)},children:`✓ Accetta`}),(0,k.jsx)(`button`,{className:Q.diffRejectBtn,onClick:()=>ye(null),children:`✕ Rifiuta`})]})]}),(0,k.jsx)(`div`,{className:Q.diffOverlayBody,children:(0,k.jsx)(rE,{before:ve.before,after:ve.after})})]}),(0,k.jsxs)(`div`,{className:Q.codeRow,children:[(0,k.jsxs)(`div`,{className:Q.fileTreeWrap,children:[ue.length>0&&(0,k.jsxs)(`div`,{className:Q.scanBanner,children:[(0,k.jsx)(`span`,{className:Q.scanBannerIcon,children:`⚠`}),(0,k.jsxs)(`span`,{className:Q.scanBannerText,children:[ue.length,` issue`,ue.length>1?`s`:``]}),(0,k.jsx)(`button`,{className:Q.scanBannerFix,onClick:()=>{Fe(`Fix all these issues:\n${ue.map(e=>`[${e.severity}] ${e.file}: ${e.message}`).join(`
805
- `)}`),i(`files`)},children:`Fix`})]}),(0,k.jsx)(zT,{files:p,activeIndex:h,unsavedFiles:S,errorFiles:new Set(ue.filter(e=>e.severity===`error`).map(e=>e.file)),onSelect:e=>{g(e),x(null),y(null),be&&M.current!==null&&e!==M.current&&(fe.current&&clearTimeout(fe.current),fe.current=setTimeout(()=>{M.current!==null&&(g(M.current),y(null))},1e4))}})]}),(0,k.jsx)(`div`,{className:Q.codeEditorWrap,children:Zt&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:Q.codeHeader,children:[(0,k.jsx)(`span`,{className:Q.codeFileIcon,children:XT(Zt.name)}),(0,k.jsx)(`span`,{className:Q.codeFileName,children:Zt.name}),Zt.content&&!Zt._error&&(0,k.jsxs)(`span`,{className:Q.codeFileMeta,children:[(Zt.content||``).split(`
806
- `).length,` righe · `,ZT(Zt.content||``)]}),!Zt._pending&&!Zt._error&&Zt.content&&(0,k.jsx)(`button`,{className:`${Q.editToggleBtn} ${b===null?``:Q.editToggleBtnActive}`,onClick:()=>{b===null?x(Zt.content):(m(e=>e.map((e,t)=>t===h?{...e,content:b}:e)),D(`/api/studio/webcraft/file/write`,{projectName:a,path:Zt.name,content:b}),x(null))},children:b===null?`✏ Modifica`:`💾 Salva`}),(0,k.jsx)(`button`,{className:Q.headerIconBtn,title:`Split view`,onClick:()=>A(ae===null?+(h===0&&p.length>1):null),children:`⫼`}),(0,k.jsx)(`button`,{className:`${Q.headerIconBtn} ${ie?Q.headerIconBtnActive:``}`,title:`Terminal`,onClick:()=>O(!ie),children:`⌨`}),(0,k.jsx)(`button`,{className:Q.headerIconBtn,title:`Development Guide`,onClick:()=>se(!0),children:`📖`})]}),w&&(0,k.jsxs)(`div`,{className:Q.findBar,children:[(0,k.jsx)(`input`,{className:Q.findInput,value:te,onChange:e=>T(e.target.value),placeholder:`Find...`,autoFocus:!0}),(0,k.jsx)(`input`,{className:Q.findInput,value:ne,onChange:e=>re(e.target.value),placeholder:`Replace...`}),(0,k.jsx)(`span`,{className:Q.findCount,children:te?((Zt.content||``).match(new RegExp(te.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),`gi`))?.length||0)+` found`:``}),(0,k.jsx)(`button`,{className:Q.findBtn,onClick:()=>{!te||b===null||x(b.replace(new RegExp(te.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),`i`),ne))},children:`Replace`}),(0,k.jsx)(`button`,{className:Q.findBtn,onClick:()=>{!te||b===null||x(b.replace(new RegExp(te.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),`gi`),ne))},children:`All`}),(0,k.jsx)(`button`,{className:Q.findClose,onClick:()=>ee(!1),children:`×`})]}),Zt._error&&(0,k.jsx)(`div`,{className:Q.fileError,children:`⚠ Generazione fallita — chiedi al modello di rigenerare questo file`}),Zt._syntaxError&&!Zt._error&&(0,k.jsxs)(`div`,{className:Q.fileSyntaxError,children:[`⚠ Syntax error: `,Zt._syntaxError]}),be&&v!==null?(0,k.jsx)(`pre`,{className:Q.streamingPre,ref:e=>{e&&pe.current&&(e.scrollTop=e.scrollHeight)},onScroll:e=>{let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<50?pe.current=!0:(pe.current=!1,me.current&&clearTimeout(me.current),me.current=setTimeout(()=>{pe.current=!0},15e3))},dangerouslySetInnerHTML:{__html:GT(v||``,(Zt.name.split(`.`).pop()||`js`).toLowerCase())+`<span class="`+Q.streamingCursor+`">▋</span>`}}):(0,k.jsx)(NT,{value:b===null?Zt.content||``:b,filename:Zt.name,readOnly:b===null,projectName:a,onChange:e=>{x(e),Zt&&C(e=>new Set(e).add(Zt.name))},onSave:e=>{m(t=>t.map((t,n)=>n===h?{...t,content:e}:t)),D(`/api/studio/webcraft/file/write`,{projectName:a,path:Zt.name,content:e}),x(null),C(e=>{let t=new Set(e);return t.delete(Zt.name),t})}})]})}),ae!==null&&p[ae]&&(0,k.jsxs)(`div`,{className:Q.codeEditorWrap,children:[(0,k.jsxs)(`div`,{className:Q.codeHeader,children:[(0,k.jsx)(`span`,{className:Q.codeFileIcon,children:XT(p[ae].name)}),(0,k.jsx)(`span`,{className:Q.codeFileName,children:p[ae].name}),(0,k.jsx)(`button`,{className:Q.headerIconBtn,onClick:()=>A(null),children:`✕`})]}),(0,k.jsx)(NT,{value:p[ae].content||``,filename:p[ae].name,readOnly:!0})]})]}),ie&&(0,k.jsxs)(`div`,{className:Q.terminalPanel,children:[(0,k.jsxs)(`div`,{className:Q.terminalHeader,children:[(0,k.jsx)(`span`,{className:Q.terminalTitle,children:`Terminal`}),(0,k.jsx)(`button`,{className:Q.terminalClose,onClick:()=>O(!1),children:`✕`})]}),(0,k.jsx)(WT,{projectDir:a||void 0})]})]})})]})]})]})}),L&&t!==`projects`&&(0,k.jsxs)(`div`,{className:Q.planBanner,children:[(0,k.jsx)(`div`,{className:Q.planTitle,children:`📌 Piano proposto — approva per eseguire`}),(0,k.jsx)(`pre`,{className:Q.planText,children:L.plan}),(0,k.jsxs)(`div`,{className:Q.planActions,children:[(0,k.jsx)(`button`,{className:Q.planApprove,onClick:Jt,children:`✓ Esegui`}),(0,k.jsx)(`button`,{className:Q.planReject,onClick:()=>Be(null),children:`✕ Annulla`})]})]}),Ye&&t!==`projects`&&(0,k.jsxs)(`div`,{className:Q.grepPanel,children:[(0,k.jsxs)(`div`,{className:Q.grepRow,children:[(0,k.jsx)(`input`,{className:Q.grepInput,value:Ze,onChange:e=>Qe(e.target.value),onKeyDown:e=>e.key===`Enter`&&V(),placeholder:`Cerca nel codice...`}),(0,k.jsx)(`button`,{className:Q.grepBtn,onClick:V,children:`🔍`}),(0,k.jsx)(`button`,{className:Q.grepClose,onClick:()=>Xe(!1),children:`×`})]}),$e.length>0&&(0,k.jsxs)(`div`,{className:Q.grepCount,children:[$e.length,` risultati`]}),(0,k.jsx)(`div`,{className:Q.grepResults,children:$e.length===0?(0,k.jsx)(`div`,{className:Q.grepEmpty,children:`Nessun risultato.`}):$e.map((e,t)=>(0,k.jsxs)(`div`,{className:Q.grepMatch,onClick:()=>Vt(e.file),children:[(0,k.jsxs)(`span`,{className:Q.grepMatchFile,children:[e.file,`:`,e.lineNum]}),(0,k.jsx)(`pre`,{className:Q.grepMatchLine,children:e.line})]},t))})]}),tt.length>0&&t!==`projects`&&(0,k.jsxs)(`div`,{className:Q.diffPanel,children:[(0,k.jsxs)(`div`,{className:Q.diffHeader,children:[(0,k.jsxs)(`span`,{children:[`🔌 Diff — `,tt.length,` file modificati`]}),(0,k.jsx)(`button`,{className:Q.diffClose,onClick:()=>nt([]),children:`✕ Chiudi`})]}),tt.map((e,t)=>{let n=(e.after||``).split(`
799
+ ❌ Sandbox error: `+e.msg,Ne(e=>{let t=[...e];return t[t.length-1]={...s},t});else if(e.type===`done`){if(f){let e=f.replace(/<tool>[\s\S]*?<\/tool>/g,``).replace(/<done\s*\/>/g,``);e&&(s.text+=e),f=``}t&&!d&&Be({plan:s.text,originalMessage:t}),Le(!1),await Nt((s.tools??[]).filter(e=>(e.op===`edit`||e.op===`write`)&&(e.result===`ok`||e.result===`ok_fuzzy`||e.result===`ok_repaired`)).map(e=>e.path),r),a&&z(a)}else e.type===`error`&&(s.text+=`
800
+ Errore: `+e.msg,Le(!1))}catch{}}}}catch(e){e instanceof DOMException&&e.name===`AbortError`||Ne(t=>[...t,{role:`agent`,text:`Errore di rete: `+e.message,tools:[]}])}if(Le(!1),a){try{let e=await E(`/api/studio/webcraft/projects/load/${encodeURIComponent(a)}`);e?.files&&m(e.files)}catch{}setTimeout(()=>{a&&z(a)},200)}}async function Nt(e,t){if(!a)return;let n=await E(`/api/studio/webcraft/projects/load/${encodeURIComponent(a)}`);if(n?.files&&(m(n.files),a&&setTimeout(()=>z(a),300),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);nt(e=>[...e,...r])}}function Pt(){xt.current&&=(xt.current.abort(),null),Tt.current=!0,xe(!1),Le(!1),N(!1),De(``),y(null),Ne(e=>[...e,{role:`system`,text:`⏹ Generazione interrotta.`}])}async function Ft(){return a?(await D(`/api/studio/webcraft/snapshot`,{projectName:a}))?.snapshot??null:null}async function It(){let e=await Ft();e&&(Ne(t=>[...t,{role:`system`,text:`💾 Snapshot salvato (${e.slice(0,16).replace(`T`,` `)})`}]),Lt())}async function Lt(){if(!a)return;let e=await E(`/api/studio/webcraft/snapshots/${encodeURIComponent(a)}`);e?.snapshots&&Je(e.snapshots)}async function Rt(e){confirm(`Ripristinare lo snapshot del ${e.replace(`T`,` `).slice(0,16)}? I file attuali verranno sovrascritti.`)&&await D(`/api/studio/webcraft/restore`,{projectName:a,ts:e})!==null&&(Ne(t=>[...t,{role:`agent`,text:`Snapshot ripristinato (${e}). Ricarico i file...`}]),Nt([],{}))}async function zt(){if(!a)return;let e=await D(`/api/studio/webcraft/syntax-check`,{projectName:a});if(e?.results){let t=e.results.filter(e=>!e.ok);t.length>0?Ne(e=>[...e,{role:`system`,text:`⚠ Syntax check: ${t.length} errore/i trovato/i.`,syntaxErrors:t}]):Ne(e=>[...e,{role:`system`,text:`✓ Syntax check: tutti i file JS sono validi.`}])}}async function Bt(){let e=p.filter(e=>e._error||e._syntaxError);if(e.length===0){Et.current?.();return}Tt.current=!1,N(!0),we(0),Ee(e.length),R.current=Date.now(),vt(`0s`);for(let t=0;t<e.length&&!Tt.current;t++){let n=e[t];De(n.name),we(t);let r=`FIX ERROR in ${n.name}: ${n._syntaxError??`generazione fallita`}\n\nUse the edit tool to make surgical fixes. Do NOT rewrite the entire file — only change the broken parts. Read the file first, identify the exact lines with errors, and edit only those lines.`;try{await Mt(r,null,[])}catch{if(Tt.current)break}}a&&z(a),Tt.current||(we(e.length),setTimeout(()=>Et.current?.(),500)),De(``),N(!1)}async function V(e){if(!lt){ut(!0),ft(null),ot(null),mt([]),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){ft(t.ok?`No response body`:`HTTP ${t.status}`),ut(!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(`
801
+
802
+ `);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`||e.type===`status`||e.type===`log`||e.type===`warn`||e.type===`error`)&&mt(t=>[...t.slice(-49),{kind:e.type,msg:String(e.msg||``),ts:Date.now()}]),e.type===`ready`&&e.port?(ot(e.port),ut(!1)):e.type===`error`&&ft(e.msg)}catch{}}}}catch(e){ft(e.message||`Connection failed`)}ut(!1)}}async function Vt(){a&&await V(a)}(0,_.useEffect)(()=>{wt.current=Bt,Et.current=Vt});async function Ht(){if(!Ze||!a)return;let e=await D(`/api/studio/webcraft/grep`,{projectName:a,query:Ze});e?.matches&&et(e.matches)}function Ut(e){let t=p.findIndex(t=>t.name===e);t>=0&&(g(t),i(`files`))}function Wt(){window.open(`/api/studio/webcraft/download/${encodeURIComponent(a)}`,`_blank`)}async function Gt(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],He(s),Ke(null);let c=a||`MyProject`;a||o(c),await D(`/api/studio/webcraft/skills/${encodeURIComponent(c)}`,{skills:s})}async function Kt(e){let t=Ve[e];!t||!confirm(`Eliminare "${t.name}"?`)||(await D(`/api/studio/webcraft/skills/${encodeURIComponent(a)}/delete`,{name:t.name}),He(Ve.filter((t,n)=>n!==e)))}async function qt(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);He(n),await D(`/api/studio/webcraft/skills/${encodeURIComponent(a)}`,{skills:n})}async function H(){let e=await E(`/api/studio/webcraft/projects`);e?.projects&&it(e.projects)}async function Jt(e){let t=await E(`/api/studio/webcraft/projects/load/${encodeURIComponent(e.name)}`);if(!t)return;let r=t.projectName??e.name;o(r),c(t.description??``),m(t.files??[]),g(0),n(`new`),i(`files`),Ne([]),He([]),We(!1),de([]),z(r);let a=await E(`/api/studio/webcraft/projects/chat/load/${encodeURIComponent(r)}`);a?.chat&&Ne(a.chat);let s=await E(`/api/studio/webcraft/skills/${encodeURIComponent(r)}`);s?.skills&&(He(s.skills),We(!0))}async function Yt(e){confirm(`Eliminare: ${e.name} - ${e.dir}?`)&&(await D(`/api/studio/webcraft/projects/${encodeURIComponent(e.name)}`,{},`DELETE`),it(rt.filter(t=>t.name!==e.name)),a===e.name&&(o(``),m([]),Ne([]),c(``)))}async function Xt(){if(!L)return;let e=L.originalMessage;Be(null),await Mt(e+`
803
+ [Piano approvato — procedi con le modifiche]`,null,[])}function Zt(e){e&&Array.from(e).forEach(e=>{let t=new FileReader;t.onload=t=>{let n=(t.target?.result).split(`,`)[1];ze(t=>[...t,{name:e.name,mimeType:e.type,base64:n,size:e.size}])},t.readAsDataURL(e)})}let Qt=a&&p.length>0,U=p[h],$t=Ie||be;return(0,k.jsxs)(`div`,{className:Q.root,children:[(0,k.jsxs)(`div`,{className:Q.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`div`,{className:Q.title,children:[`⚙ WebCraft`,a?` — ${a}`:``]}),!a&&(0,k.jsx)(`div`,{className:Q.subtitle,children:`Genera progetti web completi con agenti AI`})]}),(0,k.jsxs)(`div`,{className:Q.headerTabs,children:[(0,k.jsx)(`button`,{className:`${Q.tabBtn} ${t===`new`?Q.tabActive:``}`,onClick:async()=>{if(!(S.size>0&&!confirm(`${S.size} unsaved file(s). Discard changes and create new project?`))){if(at){try{await fetch(`/api/studio/webcraft/sandbox`,{method:`DELETE`})}catch{}ot(null)}m([]),g(0),y(null),x(null),C(new Set),Ne([]),o(``),c(``),Fe(``),He([]),We(!1),je(null),xe(!1),Le(!1),O(!1),A(null),n(`new`)}},children:`+ Nuovo`}),(0,k.jsx)(`button`,{className:`${Q.tabBtn} ${t===`projects`?Q.tabActive:``}`,onClick:()=>{n(`projects`),H()},children:`📁 Progetti`})]})]}),(0,k.jsx)(`div`,{className:Q.body,children:t===`projects`?(0,k.jsx)(`div`,{className:Q.projectsList,children:rt.length===0?(0,k.jsxs)(`div`,{className:Q.emptyProjects,children:[(0,k.jsx)(`span`,{className:Q.emptyIcon,children:`📁`}),(0,k.jsx)(`span`,{children:e(`webcraft.noProjects`)}),(0,k.jsx)(`span`,{className:Q.emptyHint,children:`Crea un progetto nella tab Nuovo`})]}):rt.map(e=>(0,k.jsxs)(`div`,{className:Q.projectCard,children:[(0,k.jsxs)(`div`,{className:Q.projectInfo,children:[(0,k.jsx)(`div`,{className:Q.projectName,children:e.name}),(0,k.jsx)(`div`,{className:Q.projectDesc,children:e.description}),(0,k.jsxs)(`div`,{className:Q.projectMeta,children:[(0,k.jsxs)(`span`,{children:[`📄 `,e.fileCount,` file`]}),(0,k.jsxs)(`span`,{children:[`📅 `,e.createdAt?new Date(e.createdAt).toLocaleString():``]})]})]}),(0,k.jsx)(`button`,{className:Q.openBtn,onClick:()=>Jt(e),children:`↗ Apri`}),(0,k.jsx)(`button`,{className:Q.deleteBtn,onClick:()=>Yt(e),children:`🗑`})]},e.name))}):(0,k.jsxs)(`div`,{className:Q.editor,children:[(0,k.jsxs)(`div`,{className:Q.examples,children:[(0,k.jsx)(`div`,{className:Q.sectionLabel,children:`Esempi`}),(0,k.jsx)(`div`,{className:Q.examplePills,children:qT.map(e=>(0,k.jsx)(`button`,{className:Q.examplePill,onClick:()=>{o(e.name),c(e.desc),Fe(e.desc)},children:e.name},e.name))})]}),(0,k.jsxs)(`div`,{className:Q.editorCols,children:[(0,k.jsxs)(`div`,{className:Q.leftSidebar,children:[(0,k.jsxs)(`div`,{className:Q.panel,children:[(0,k.jsx)(`div`,{className:Q.panelTitle,children:`Blocchi`}),JT.map(e=>(0,k.jsxs)(`label`,{className:Q.blockLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:l[e.key],onChange:t=>u(n=>({...n,[e.key]:t.target.checked})),className:Q.blockCheck}),(0,k.jsx)(`span`,{children:e.icon}),(0,k.jsx)(`span`,{children:e.label})]},e.key))]}),l.auth&&(0,k.jsxs)(`div`,{className:Q.panel,children:[(0,k.jsxs)(`div`,{className:Q.panelHeader,children:[(0,k.jsx)(`div`,{className:Q.panelTitle,children:`Campi Auth`}),(0,k.jsx)(`button`,{className:Q.addBtn,onClick:()=>f(e=>[...e,{label:`New field`,type:`text`,required:!1}]),children:`+ Campo`})]}),d.map((e,t)=>(0,k.jsxs)(`div`,{className:Q.authField,children:[(0,k.jsx)(`input`,{value:e.label,onChange:e=>f(n=>n.map((n,r)=>r===t?{...n,label:e.target.value}:n)),className:Q.authFieldInput}),(0,k.jsx)(`select`,{value:e.type,onChange:e=>f(n=>n.map((n,r)=>r===t?{...n,type:e.target.value}:n)),className:Q.authFieldSelect,children:[`text`,`email`,`password`,`tel`,`date`,`number`].map(e=>(0,k.jsx)(`option`,{value:e,children:e},e))}),(0,k.jsx)(`input`,{type:`checkbox`,checked:e.required,onChange:e=>f(n=>n.map((n,r)=>r===t?{...n,required:e.target.checked}:n)),title:`Required`,className:Q.authFieldReq}),(0,k.jsx)(`button`,{onClick:()=>f(e=>e.filter((e,n)=>n!==t)),className:Q.removeFieldBtn,children:`×`})]},t))]}),(0,k.jsxs)(`div`,{className:Q.panel,children:[(0,k.jsxs)(`div`,{className:Q.panelHeader,children:[(0,k.jsx)(`div`,{className:Q.panelTitle,children:`🗂 Contesto AI`}),(0,k.jsx)(`button`,{className:Q.addBtn,onClick:()=>Ke({mode:`new`,idx:null,name:``,content:``,type:`skill`,generating:!1}),children:`+ Skill`})]}),Ve.length>0?(0,k.jsx)(`div`,{className:Q.skillsList,children:Ve.map((e,t)=>(0,k.jsxs)(`div`,{className:Q.skillRow,children:[(0,k.jsx)(`span`,{className:Q.skillIcon,children:QT(e.type)}),(0,k.jsx)(`span`,{className:Q.skillName,title:e.name,children:e.name}),(0,k.jsx)(`span`,{className:`${Q.skillBadge} ${Q[`skillBadge_`+e.type]}`,children:e.type}),!e.content&&e.type!==`log`&&(0,k.jsx)(`span`,{className:Q.skillEmpty,children:`⚠`}),(0,k.jsx)(`button`,{className:Q.skillBtn,onClick:()=>Ke({mode:e.type===`log`?`view`:`edit`,idx:t,name:e.name,content:e.content,type:e.type,generating:!1}),children:e.type===`log`?`👁`:`✏`}),e.type!==`memory`&&e.type!==`provider`&&e.type!==`log`&&(0,k.jsx)(`button`,{className:Q.skillBtn,onClick:()=>qt(t),children:`🗑`}),e.type===`log`&&(0,k.jsx)(`button`,{className:Q.skillBtn,onClick:()=>Kt(t),children:`🗑`})]},t))}):(0,k.jsx)(`div`,{className:Q.skillsEmpty,children:Ue?`Nessun file di contesto. Clicca "+ Skill" per aggiungerne uno.`:`Crea o carica un progetto per i file di contesto.`})]}),qe.length>0&&(0,k.jsxs)(`div`,{className:Q.panel,children:[(0,k.jsx)(`div`,{className:Q.panelTitle,children:`💾 Snapshot`}),qe.slice(0,5).map(e=>{let t=e.ts.replace(`T`,` `).slice(0,16);return(0,k.jsxs)(`div`,{className:Q.snapshotRow,children:[(0,k.jsx)(`span`,{className:Q.snapshotTs,children:t}),(0,k.jsxs)(`span`,{className:Q.snapshotCount,children:[e.fileCount,`f`]}),(0,k.jsx)(`button`,{className:Q.snapshotBtn,onClick:()=>Rt(e.ts),children:`↺`})]},e.ts)})]}),be&&(0,k.jsx)(`div`,{className:Q.genStatus,children:`⏳ Generazione...`}),Se&&(0,k.jsxs)(`div`,{className:Q.repairStatus,children:[(0,k.jsx)(`div`,{className:Q.repairStatusTitle,children:`🔧 Correzione automatica...`}),(0,k.jsxs)(`div`,{className:Q.repairStatusProg,children:[Ce,` / `,Te,` file`]}),(0,k.jsx)(`div`,{className:Q.repairStatusFile,children:P})]}),p.length>0&&!be&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:Q.actionRow,children:[(0,k.jsx)(`button`,{className:Q.actionBtn,onClick:Wt,children:`⬇ ZIP`}),(0,k.jsx)(`button`,{className:Q.actionBtnIcon,title:`Syntax check`,onClick:zt,children:`✅`}),(0,k.jsx)(`button`,{className:`${Q.actionBtnIcon} ${Ye?Q.actionBtnActive:``}`,title:`Grep`,onClick:()=>Xe(!Ye),children:`🔍`}),(0,k.jsx)(`button`,{className:Q.actionBtnIcon,title:`Snapshot`,onClick:It,children:`💾`})]}),p.some(e=>e._error||e._syntaxError)&&!Se&&(0,k.jsx)(`button`,{className:Q.repairBtn,onClick:Bt,children:`🔧 Correggi tutti i file rossi`}),(0,k.jsx)(`button`,{className:Q.sandboxBtn,onClick:()=>{a?V(a):i(`preview`)},children:lt?`⏳ Starting...`:at?`🌐 Sandbox Live`:`▶ Sandbox`}),Ae&&(0,k.jsxs)(`div`,{className:Q.statsBar,children:[(0,k.jsxs)(`span`,{children:[`⏱ `,Ae.seconds>=60?`${Math.floor(Ae.seconds/60)}m ${Ae.seconds%60}s`:`${Ae.seconds}s`]}),(0,k.jsxs)(`span`,{children:[`↑ `,Ae.tokIn.toLocaleString(),` tok`]}),(0,k.jsxs)(`span`,{children:[`↓ `,Ae.tokOut.toLocaleString(),` tok`]}),(0,k.jsxs)(`span`,{children:[`📄 `,Ae.files,` file`]})]})]})]}),(0,k.jsxs)(`div`,{className:Q.rightPanel,children:[(0,k.jsxs)(`div`,{className:Q.rightTabBar,children:[(0,k.jsx)(`button`,{className:`${Q.rightTab} ${r===`preview`?``:Q.rightTabActive}`,onClick:()=>i(`files`),children:`📄 File`}),(0,k.jsx)(`button`,{className:`${Q.rightTab} ${r===`preview`?Q.rightTabActive:``}`,onClick:()=>i(`preview`),children:`🌐 Sandbox`})]}),Se&&(0,k.jsxs)(`div`,{className:Q.repairBar,children:[(0,k.jsxs)(`div`,{className:Q.repairBarRow,children:[(0,k.jsx)(`span`,{className:Q.repairBarIcon,children:`🔧`}),(0,k.jsx)(`span`,{className:Q.repairBarLabel,children:`Auto-fix`}),(0,k.jsx)(`span`,{className:Q.repairBarFile,children:P}),(0,k.jsxs)(`span`,{className:Q.repairBarCounter,children:[Ce,` / `,Te]}),(0,k.jsx)(`span`,{className:Q.repairBarTime,children:_t}),(0,k.jsx)(`button`,{className:Q.stopBtn,onClick:Pt,children:`⏹ Stop`})]}),(0,k.jsx)(`div`,{className:Q.progressTrack,children:(0,k.jsx)(`div`,{className:Q.repairProgress,style:{width:Te>0?`${Math.round(Ce/Te*100)}%`:`0%`}})})]}),be&&(0,k.jsxs)(`div`,{className:Q.genBar,children:[(0,k.jsxs)(`div`,{className:Q.genBarRow,children:[(0,k.jsx)(`span`,{className:Q.genBarRobot,children:`🤖`}),(0,k.jsx)(`span`,{className:Q.genBarLabel,children:Oe.total===0?`Pianificazione...`:`Generazione`}),(0,k.jsx)(`span`,{className:Q.genBarFile,children:(Oe.name||``).split(`,`)[0].trim()}),(0,k.jsx)(`span`,{className:Q.genBarCounter,children:Oe.total>0?`${Oe.fi} / ${Oe.total}`:``}),(0,k.jsx)(`span`,{className:Q.genBarCounter,children:F.tokIn+F.tokOut>0?`↑${Ot(F.tokIn)} ↓${Ot(F.tokOut)}`:``}),(0,k.jsx)(`span`,{className:Q.genBarTime,children:ht}),(0,k.jsxs)(`span`,{className:Q.genDots,children:[(0,k.jsx)(`span`,{className:`${Q.dot} ${Q.dot1}`}),(0,k.jsx)(`span`,{className:`${Q.dot} ${Q.dot2}`}),(0,k.jsx)(`span`,{className:`${Q.dot} ${Q.dot3}`})]})]}),(0,k.jsx)(`div`,{className:Q.progressTrack,children:(0,k.jsx)(`div`,{className:Q.genProgress,style:{width:Oe.total>0?`${Math.round(Oe.fi/Oe.total*100)}%`:`0%`}})})]}),r===`preview`?(0,k.jsxs)(`div`,{className:Q.sandboxWrap,children:[(0,k.jsxs)(`div`,{className:Q.sandboxStatusBar,children:[(0,k.jsx)(`span`,{className:Q.sandboxStatusDot,style:{background:at?`#4ade80`:lt?`#facc15`:`#64748b`}}),(0,k.jsx)(`span`,{className:Q.sandboxStatusText,children:at?`Live :${at}`:lt?`Starting...`:`Stopped`}),at&&(0,k.jsx)(`button`,{className:Q.sandboxReloadBtn,onClick:()=>{let e=document.querySelector(`iframe[title="WebCraft Sandbox"]`);e&&(e.src=e.src)},children:`↻`}),at&&(0,k.jsx)(`button`,{className:Q.sandboxStopBtn,onClick:async()=>{ot(null),le([]);try{await fetch(`/api/studio/webcraft/sandbox`,{method:`DELETE`})}catch{}},children:`⏹`}),!at&&!lt&&(0,k.jsx)(`button`,{className:Q.sandboxStartBtnSmall,onClick:()=>{a&&V(a)},children:`▶ Start`})]}),ce.length>0&&(0,k.jsxs)(`div`,{className:Q.runtimeErrors,children:[(0,k.jsxs)(`div`,{className:Q.runtimeErrorsHeader,children:[(0,k.jsxs)(`span`,{children:[`❌ `,ce.length,` runtime error`,ce.length>1?`s`:``]}),(0,k.jsx)(`button`,{className:Q.runtimeErrorsFix,onClick:()=>{Fe(`Fix these runtime errors:\n${ce.map(e=>`${e.message} (${e.source||``}:${e.line||0})`).join(`
804
+ `)}`),fetch(`/api/studio/webcraft/sandbox/errors`,{method:`DELETE`}),le([]),i(`files`)},children:`🔧 Auto-fix`}),(0,k.jsx)(`button`,{className:Q.runtimeErrorsDismiss,onClick:()=>{fetch(`/api/studio/webcraft/sandbox/errors`,{method:`DELETE`}),le([])},children:`✕`})]}),ce.slice(0,3).map((e,t)=>(0,k.jsxs)(`div`,{className:Q.runtimeErrorLine,children:[e.message,e.source?` — ${e.source.split(`/`).pop()}:${e.line}`:``]},t))]}),at?(0,k.jsx)(`iframe`,{src:`http://localhost:${at}`,className:Q.sandboxFrame,title:`WebCraft Sandbox`,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups`}):(0,k.jsxs)(`div`,{className:Q.sandboxEmpty,children:[(0,k.jsx)(`span`,{style:{fontSize:48},children:lt?`⏳`:dt?`❌`:`🌐`}),(0,k.jsx)(`span`,{style:{fontWeight:700,fontSize:16},children:lt?`Starting sandbox...`:dt?`Sandbox Error`:`Preview`}),dt&&(0,k.jsx)(`pre`,{style:{fontSize:11,maxWidth:600,textAlign:`left`,color:`#f87171`,background:`rgba(248,113,113,0.08)`,border:`1px solid rgba(248,113,113,0.2)`,borderRadius:6,padding:`8px 12px`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,margin:`8px 0`,lineHeight:1.5,maxHeight:200,overflow:`auto`},children:dt}),pt.length>0&&(0,k.jsxs)(`div`,{style:{width:`100%`,maxWidth:720,margin:`8px 0`,textAlign:`left`},children:[(0,k.jsxs)(`div`,{style:{fontSize:10,color:`#94a3b8`,textTransform:`uppercase`,letterSpacing:`0.5px`,marginBottom:4},children:[`Sandbox log (`,pt.length,`)`]}),(0,k.jsx)(`pre`,{style:{fontSize:11,lineHeight:1.5,fontFamily:`SF Mono, Monaco, monospace`,background:`rgba(15, 23, 42, 0.6)`,border:`1px solid rgba(148, 163, 184, 0.18)`,borderRadius:6,padding:`8px 12px`,maxHeight:240,overflow:`auto`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,color:`#cbd5e1`},children:pt.slice(-40).map((e,t)=>(0,k.jsx)(`div`,{style:{color:e.kind===`error`?`#f87171`:e.kind===`warn`?`#fbbf24`:e.kind===`phase`?`#60a5fa`:e.kind===`status`?`#34d399`:`#94a3b8`},children:`[${e.kind}] ${e.msg}`},t))})]}),!lt&&(0,k.jsxs)(`button`,{className:Q.sandboxStartBtn,onClick:()=>{a&&V(a)},children:[`▶ `,dt?`Retry`:`Start Sandbox`]})]})]}):(0,k.jsx)(`div`,{className:Q.codeArea,children:p.length===0&&be?(0,k.jsx)(`div`,{className:Q.noFiles,children:(0,k.jsxs)(`div`,{className:Q.noFilesHero,children:[(0,k.jsx)(`span`,{className:Q.noFilesIcon,children:`⏳`}),(0,k.jsx)(`span`,{className:Q.noFilesTitle,children:`Pianificazione...`}),(0,k.jsx)(`span`,{className:Q.noFilesTagline,children:Oe.name||`Analisi della struttura del progetto in corso`})]})}):p.length===0?(0,k.jsxs)(`div`,{className:Q.noFiles,children:[(0,k.jsxs)(`div`,{className:Q.noFilesHero,children:[(0,k.jsx)(`span`,{className:Q.noFilesIcon,children:`🔨`}),(0,k.jsx)(`span`,{className:Q.noFilesTitle,children:`WebCraft`}),(0,k.jsx)(`span`,{className:Q.noFilesTagline,children:`Genera progetti web completi con AI`})]}),(0,k.jsxs)(`div`,{className:Q.noFilesSteps,children:[(0,k.jsxs)(`div`,{className:Q.noFilesStep,children:[(0,k.jsx)(`span`,{className:Q.noFilesStepNum,children:`1`}),(0,k.jsx)(`span`,{children:`Scegli un esempio o scrivi una descrizione nel box in basso`})]}),(0,k.jsxs)(`div`,{className:Q.noFilesStep,children:[(0,k.jsx)(`span`,{className:Q.noFilesStepNum,children:`2`}),(0,k.jsxs)(`span`,{children:[`Premi `,(0,k.jsx)(`strong`,{children:`▶ Genera`}),` — l'AI crea tutti i file del progetto`]})]}),(0,k.jsxs)(`div`,{className:Q.noFilesStep,children:[(0,k.jsx)(`span`,{className:Q.noFilesStepNum,children:`3`}),(0,k.jsx)(`span`,{children:`Chiedi modifiche in chat, scarica lo ZIP o avvia il Sandbox`})]})]}),(0,k.jsxs)(`div`,{className:Q.noFilesExamplesHint,children:[`💡 Prova: `,(0,k.jsx)(`button`,{className:Q.noFilesExampleBtn,onClick:()=>{let e=qT[0];o(e.name),c(e.desc),Fe(e.desc)},children:`MySaaS`}),(0,k.jsx)(`button`,{className:Q.noFilesExampleBtn,onClick:()=>{let e=qT[1];o(e.name),c(e.desc),Fe(e.desc)},children:`MyShop`}),(0,k.jsx)(`button`,{className:Q.noFilesExampleBtn,onClick:()=>{let e=qT[3];o(e.name),c(e.desc),Fe(e.desc)},children:`MyPortfolio`})]})]}):(0,k.jsxs)(`div`,{className:Q.codeLayout,children:[(0,k.jsx)(`div`,{className:Q.ideTabBar,children:p.map((e,t)=>{let n=e._error||!!e._syntaxError,r=t===h;return(0,k.jsxs)(`button`,{className:`${Q.ideTab} ${r?Q.ideTabActive:``} ${n?Q.ideTabError:``} ${e._pending?Q.ideTabPending:``}`,onClick:()=>{g(t),x(null),y(null),be&&M.current!==null&&t!==M.current&&(fe.current&&clearTimeout(fe.current),fe.current=setTimeout(()=>{M.current!==null&&(g(M.current),y(null))},1e4))},title:e.name,children:[(0,k.jsx)(`span`,{className:Q.ideTabIcon,children:e._pending?`⌛`:n?`⚠`:XT(e.name)}),(0,k.jsx)(`span`,{className:Q.ideTabName,children:(e.name||``).split(`/`).pop()}),S.has(e.name)&&(0,k.jsx)(`span`,{className:Q.ideTabUnsaved,children:`●`}),n&&(0,k.jsx)(`span`,{className:Q.ideTabDot})]},t)})}),ve&&(0,k.jsxs)(`div`,{className:Q.diffOverlay,children:[(0,k.jsxs)(`div`,{className:Q.diffOverlayHeader,children:[(0,k.jsxs)(`span`,{children:[`✏ Modifica proposta — `,(0,k.jsx)(`strong`,{children:ve.file})]}),(0,k.jsxs)(`div`,{className:Q.diffOverlayActions,children:[(0,k.jsx)(`button`,{className:Q.diffAcceptBtn,onClick:()=>{m(e=>e.map(e=>e.name===ve.file?{...e,content:ve.after}:e)),ye(null)},children:`✓ Accetta`}),(0,k.jsx)(`button`,{className:Q.diffRejectBtn,onClick:()=>ye(null),children:`✕ Rifiuta`})]})]}),(0,k.jsx)(`div`,{className:Q.diffOverlayBody,children:(0,k.jsx)(rE,{before:ve.before,after:ve.after})})]}),(0,k.jsxs)(`div`,{className:Q.codeRow,children:[(0,k.jsxs)(`div`,{className:Q.fileTreeWrap,children:[ue.length>0&&(0,k.jsxs)(`div`,{className:Q.scanBanner,children:[(0,k.jsx)(`span`,{className:Q.scanBannerIcon,children:`⚠`}),(0,k.jsxs)(`span`,{className:Q.scanBannerText,children:[ue.length,` issue`,ue.length>1?`s`:``]}),(0,k.jsx)(`button`,{className:Q.scanBannerFix,onClick:()=>{Fe(`Fix all these issues:\n${ue.map(e=>`[${e.severity}] ${e.file}: ${e.message}`).join(`
805
+ `)}`),i(`files`)},children:`Fix`})]}),(0,k.jsx)(zT,{files:p,activeIndex:h,unsavedFiles:S,errorFiles:new Set(ue.filter(e=>e.severity===`error`).map(e=>e.file)),onSelect:e=>{g(e),x(null),y(null),be&&M.current!==null&&e!==M.current&&(fe.current&&clearTimeout(fe.current),fe.current=setTimeout(()=>{M.current!==null&&(g(M.current),y(null))},1e4))}})]}),(0,k.jsx)(`div`,{className:Q.codeEditorWrap,children:U&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:Q.codeHeader,children:[(0,k.jsx)(`span`,{className:Q.codeFileIcon,children:XT(U.name)}),(0,k.jsx)(`span`,{className:Q.codeFileName,children:U.name}),U.content&&!U._error&&(0,k.jsxs)(`span`,{className:Q.codeFileMeta,children:[(U.content||``).split(`
806
+ `).length,` righe · `,ZT(U.content||``)]}),!U._pending&&!U._error&&U.content&&(0,k.jsx)(`button`,{className:`${Q.editToggleBtn} ${b===null?``:Q.editToggleBtnActive}`,onClick:()=>{b===null?x(U.content):(m(e=>e.map((e,t)=>t===h?{...e,content:b}:e)),D(`/api/studio/webcraft/file/write`,{projectName:a,path:U.name,content:b}),x(null))},children:b===null?`✏ Modifica`:`💾 Salva`}),(0,k.jsx)(`button`,{className:Q.headerIconBtn,title:`Split view`,onClick:()=>A(ae===null?+(h===0&&p.length>1):null),children:`⫼`}),(0,k.jsx)(`button`,{className:`${Q.headerIconBtn} ${ie?Q.headerIconBtnActive:``}`,title:`Terminal`,onClick:()=>O(!ie),children:`⌨`}),(0,k.jsx)(`button`,{className:Q.headerIconBtn,title:`Development Guide`,onClick:()=>se(!0),children:`📖`})]}),w&&(0,k.jsxs)(`div`,{className:Q.findBar,children:[(0,k.jsx)(`input`,{className:Q.findInput,value:te,onChange:e=>T(e.target.value),placeholder:`Find...`,autoFocus:!0}),(0,k.jsx)(`input`,{className:Q.findInput,value:ne,onChange:e=>re(e.target.value),placeholder:`Replace...`}),(0,k.jsx)(`span`,{className:Q.findCount,children:te?((U.content||``).match(new RegExp(te.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),`gi`))?.length||0)+` found`:``}),(0,k.jsx)(`button`,{className:Q.findBtn,onClick:()=>{!te||b===null||x(b.replace(new RegExp(te.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),`i`),ne))},children:`Replace`}),(0,k.jsx)(`button`,{className:Q.findBtn,onClick:()=>{!te||b===null||x(b.replace(new RegExp(te.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),`gi`),ne))},children:`All`}),(0,k.jsx)(`button`,{className:Q.findClose,onClick:()=>ee(!1),children:`×`})]}),U._error&&(0,k.jsx)(`div`,{className:Q.fileError,children:`⚠ Generazione fallita — chiedi al modello di rigenerare questo file`}),U._syntaxError&&!U._error&&(0,k.jsxs)(`div`,{className:Q.fileSyntaxError,children:[`⚠ Syntax error: `,U._syntaxError]}),be&&v!==null?(0,k.jsx)(`pre`,{className:Q.streamingPre,ref:e=>{e&&pe.current&&(e.scrollTop=e.scrollHeight)},onScroll:e=>{let t=e.currentTarget;t.scrollHeight-t.scrollTop-t.clientHeight<50?pe.current=!0:(pe.current=!1,me.current&&clearTimeout(me.current),me.current=setTimeout(()=>{pe.current=!0},15e3))},dangerouslySetInnerHTML:{__html:GT(v||``,(U.name.split(`.`).pop()||`js`).toLowerCase())+`<span class="`+Q.streamingCursor+`">▋</span>`}}):(0,k.jsx)(NT,{value:b===null?U.content||``:b,filename:U.name,readOnly:b===null,projectName:a,onChange:e=>{x(e),U&&C(e=>new Set(e).add(U.name))},onSave:e=>{m(t=>t.map((t,n)=>n===h?{...t,content:e}:t)),D(`/api/studio/webcraft/file/write`,{projectName:a,path:U.name,content:e}),x(null),C(e=>{let t=new Set(e);return t.delete(U.name),t})}})]})}),ae!==null&&p[ae]&&(0,k.jsxs)(`div`,{className:Q.codeEditorWrap,children:[(0,k.jsxs)(`div`,{className:Q.codeHeader,children:[(0,k.jsx)(`span`,{className:Q.codeFileIcon,children:XT(p[ae].name)}),(0,k.jsx)(`span`,{className:Q.codeFileName,children:p[ae].name}),(0,k.jsx)(`button`,{className:Q.headerIconBtn,onClick:()=>A(null),children:`✕`})]}),(0,k.jsx)(NT,{value:p[ae].content||``,filename:p[ae].name,readOnly:!0})]})]}),ie&&(0,k.jsxs)(`div`,{className:Q.terminalPanel,children:[(0,k.jsxs)(`div`,{className:Q.terminalHeader,children:[(0,k.jsx)(`span`,{className:Q.terminalTitle,children:`Terminal`}),(0,k.jsx)(`button`,{className:Q.terminalClose,onClick:()=>O(!1),children:`✕`})]}),(0,k.jsx)(WT,{projectDir:a||void 0})]})]})})]})]})]})}),L&&t!==`projects`&&(0,k.jsxs)(`div`,{className:Q.planBanner,children:[(0,k.jsx)(`div`,{className:Q.planTitle,children:`📌 Piano proposto — approva per eseguire`}),(0,k.jsx)(`pre`,{className:Q.planText,children:L.plan}),(0,k.jsxs)(`div`,{className:Q.planActions,children:[(0,k.jsx)(`button`,{className:Q.planApprove,onClick:Xt,children:`✓ Esegui`}),(0,k.jsx)(`button`,{className:Q.planReject,onClick:()=>Be(null),children:`✕ Annulla`})]})]}),Ye&&t!==`projects`&&(0,k.jsxs)(`div`,{className:Q.grepPanel,children:[(0,k.jsxs)(`div`,{className:Q.grepRow,children:[(0,k.jsx)(`input`,{className:Q.grepInput,value:Ze,onChange:e=>Qe(e.target.value),onKeyDown:e=>e.key===`Enter`&&Ht(),placeholder:`Cerca nel codice...`}),(0,k.jsx)(`button`,{className:Q.grepBtn,onClick:Ht,children:`🔍`}),(0,k.jsx)(`button`,{className:Q.grepClose,onClick:()=>Xe(!1),children:`×`})]}),$e.length>0&&(0,k.jsxs)(`div`,{className:Q.grepCount,children:[$e.length,` risultati`]}),(0,k.jsx)(`div`,{className:Q.grepResults,children:$e.length===0?(0,k.jsx)(`div`,{className:Q.grepEmpty,children:`Nessun risultato.`}):$e.map((e,t)=>(0,k.jsxs)(`div`,{className:Q.grepMatch,onClick:()=>Ut(e.file),children:[(0,k.jsxs)(`span`,{className:Q.grepMatchFile,children:[e.file,`:`,e.lineNum]}),(0,k.jsx)(`pre`,{className:Q.grepMatchLine,children:e.line})]},t))})]}),tt.length>0&&t!==`projects`&&(0,k.jsxs)(`div`,{className:Q.diffPanel,children:[(0,k.jsxs)(`div`,{className:Q.diffHeader,children:[(0,k.jsxs)(`span`,{children:[`🔌 Diff — `,tt.length,` file modificati`]}),(0,k.jsx)(`button`,{className:Q.diffClose,onClick:()=>nt([]),children:`✕ Chiudi`})]}),tt.map((e,t)=>{let n=(e.after||``).split(`
807
807
  `).length-(e.before||``).split(`
808
- `).length;return(0,k.jsxs)(`details`,{open:!0,className:Q.diffFile,children:[(0,k.jsxs)(`summary`,{className:Q.diffSummary,children:[(0,k.jsx)(`span`,{className:Q.diffArrow,children:`▲`}),(0,k.jsx)(`span`,{className:Q.diffFileName,children:e.file}),(0,k.jsxs)(`span`,{className:n>=0?Q.diffAdded:Q.diffRemoved,children:[n>=0?`+`:``,n,` linee`]})]}),(0,k.jsx)(`div`,{className:Q.diffContent,children:(0,k.jsx)(rE,{before:e.before,after:e.after})})]},t)})]}),t!==`projects`&&(0,k.jsxs)(`div`,{className:`${Q.chatPanel} ${st?Q.chatPanelCollapsed:``}`,children:[(0,k.jsxs)(`button`,{className:Q.chatCollapseBtn,onClick:()=>ct(e=>!e),children:[(0,k.jsx)(`span`,{children:st?`▲`:`▼`}),(0,k.jsx)(`span`,{children:st?`Show Chat`:`Hide Chat`}),Me.length>0&&(0,k.jsxs)(`span`,{style:{opacity:.5},children:[`(`,Me.length,`)`]})]}),(0,k.jsxs)(`div`,{className:Q.chatMessages,ref:bt,children:[Me.length===0&&Xt&&(0,k.jsxs)(`div`,{className:Q.chatWelcome,children:[`🤖 `,e(`webcraft.doctrine.title`),` — `,(0,k.jsx)(`button`,{className:Q.doctrineOpenBtn,onClick:()=>se(!0),children:`📖 Open Guide`})]}),Me.map((e,t)=>(0,k.jsxs)(`div`,{className:e.role===`user`?Q.chatUser:e.role===`system`?Q.chatSystem:Q.chatAgent,children:[e.role===`user`&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:Q.chatUserBubble,children:e.text}),e.attachments&&e.attachments.length>0&&(0,k.jsx)(`div`,{className:Q.chatAttachPreviews,children:e.attachments.map((e,t)=>(0,k.jsxs)(`span`,{className:Q.chatAttachBadge,children:[`📎 `,e.name]},t))})]}),e.role===`system`&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:Q.chatSystemBubble,children:e.text}),e.syntaxErrors?.map((e,t)=>(0,k.jsxs)(`div`,{className:Q.chatSyntaxErr,children:[`✕ `,e.file,`: `,e.error]},t))]}),e.role===`agent`&&(()=>{let t=e.text.replace(/<tool>[\s\S]*?<\/tool>/g,``).replace(/<done\s*\/?>/g,``).trim(),n=(e.tools||[]).filter(e=>(e.op===`edit`||e.op===`write`)&&(e.result===`ok`||e.result===`ok_fuzzy`||e.result===`ok_repaired`)),r=(e.tools||[]).filter(e=>e.result?.includes(`not_found`)||e.result?.includes(`error`)||e.result===`blocked_use_edit`),a=t.match(/^(.{10,120}?)[.\n]/),o=a?a[1]+`.`:t.slice(0,120),s=t.length>130;return(0,k.jsxs)(`div`,{className:Q.chatAgentCard,children:[n.map((e,t)=>(0,k.jsxs)(`div`,{style:{margin:`6px 0`,borderRadius:8,overflow:`hidden`,border:`1px solid rgba(255,255,255,0.08)`},children:[(0,k.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,padding:`6px 10px`,background:`rgba(99,102,241,0.1)`,fontSize:11},children:[(0,k.jsxs)(`span`,{style:{fontWeight:600,color:`#818cf8`,cursor:`pointer`},onClick:()=>{let t=p.findIndex(t=>t.name===e.path);t>=0&&(g(t),i(`files`))},children:[`✏ `,e.path]}),(0,k.jsx)(`span`,{style:{color:`#4ade80`,fontSize:10,fontWeight:600},children:e.result===`ok_fuzzy`?`applied (fuzzy)`:e.result===`ok_repaired`?`applied (repaired)`:`✓ applied`})]}),e.oldSnippet||e.newSnippet?(0,k.jsx)(rE,{before:e.oldSnippet||``,after:e.newSnippet||``,contextLines:3}):(0,k.jsx)(`div`,{style:{padding:`6px 10px`,fontSize:11,color:`#4ade80`,background:`rgba(74,222,128,0.05)`},children:`File modified successfully`})]},t)),r.length>0&&(0,k.jsx)(`div`,{style:{margin:`6px 0`,padding:`6px 10px`,background:`rgba(248,113,113,0.08)`,borderRadius:6,fontSize:11,color:`#f87171`},children:r.map((e,t)=>(0,k.jsxs)(`div`,{children:[`❌ `,e.op,` `,e.path,`: `,typeof e.result==`string`?e.result.slice(0,100):``]},t))}),t&&(s?(0,k.jsxs)(`details`,{style:{margin:`6px 0`,fontSize:11},children:[(0,k.jsx)(`summary`,{style:{cursor:`pointer`,color:`var(--dim)`,padding:`4px 0`,userSelect:`none`},children:o.slice(0,100)}),(0,k.jsx)(`div`,{className:Q.chatAgentText,style:{fontSize:11,opacity:.8,marginTop:4},dangerouslySetInnerHTML:{__html:KT(t)}})]}):(0,k.jsx)(`div`,{className:Q.chatAgentText,style:{fontSize:11,opacity:.8},dangerouslySetInnerHTML:{__html:KT(t)}}))]})})()]},t)),Ie&&(()=>{let e=Me[Me.length-1]?.tools??[],t=e[e.length-1],n=t?t.op===`read`?`Reading ${t.path}`:t.op===`edit`?`Editing ${t.path}`:t.op===`search`?`Searching...`:t.op===`lint`?`Linting ${t.path}`:t.op===`check`?`Checking ${t.path}`:t.op===`run`?`Running command...`:t.op===`sandbox`?`Starting sandbox...`:t.op:`Thinking...`;return(0,k.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`8px 12px`,fontSize:12,color:`#818cf8`},children:[(0,k.jsx)(`span`,{className:Q.chatAgentRobotAnim,style:{fontSize:14},children:`⟳`}),(0,k.jsx)(`span`,{style:{fontWeight:500},children:n})]})})()]}),Re.length>0&&(0,k.jsx)(`div`,{className:Q.attachPreviews,children:Re.map((e,t)=>(0,k.jsxs)(`span`,{className:Q.attachBadge,children:[`📎 `,e.name,(0,k.jsx)(`button`,{className:Q.removeAttachBtn,onClick:()=>ze(e=>e.filter((e,n)=>n!==t)),children:`×`})]},t))}),Xt?(0,k.jsxs)(`div`,{className:Q.projActiveRow,children:[`📄 `,(0,k.jsx)(`strong`,{className:Q.projActiveName,children:a}),` — scrivi per modificare o migliorare il progetto`]}):(0,k.jsxs)(`div`,{className:Q.projNameRow,children:[(0,k.jsx)(`span`,{className:Q.projNameLabel,children:`Nome progetto:`}),(0,k.jsx)(`input`,{className:Q.projNameInput,value:a,onChange:e=>o(e.target.value),placeholder:`MioProgetto`})]}),(0,k.jsxs)(`div`,{className:Q.chatInputRow,children:[(0,k.jsxs)(`label`,{className:Q.attachLabel,title:`Allega immagine o PDF`,children:[`📎`,(0,k.jsx)(`input`,{ref:xt,type:`file`,multiple:!0,accept:`image/*,.pdf`,style:{display:`none`},onChange:e=>Yt(e.target.files)})]}),(0,k.jsx)(`textarea`,{className:Q.chatTextarea,value:Pe,onChange:e=>Fe(e.target.value),placeholder:Xt?`Parla con il tuo agente: chiedi correzioni, migliorie, nuove funzionalità...`:`Descrivi il progetto da creare, poi premi Genera...`,disabled:Qt,onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),At())},rows:4}),(0,k.jsxs)(`div`,{className:Q.chatSendCol,children:[(0,k.jsx)(`button`,{className:Q.chatSendBtn,onClick:At,disabled:Qt,children:be?`⏳`:Xt?`▶`:`▶ Genera`}),Qt&&!Se&&(0,k.jsx)(`button`,{className:Q.chatStopBtn,onClick:Mt,children:`⏹ Stop`})]})]})]}),oe&&(0,k.jsx)(`div`,{className:Q.modalOverlay,onClick:()=>se(!1),children:(0,k.jsxs)(`div`,{className:Q.modal,onClick:e=>e.stopPropagation(),style:{width:720,maxHeight:`90vh`},children:[(0,k.jsxs)(`div`,{className:Q.modalHeader,children:[(0,k.jsxs)(`span`,{className:Q.modalTitle,children:[`📖 `,e(`webcraft.doctrine.title`)]}),(0,k.jsx)(`span`,{className:Q.doctrineSubtitle,children:e(`webcraft.doctrine.subtitle`)}),(0,k.jsx)(`button`,{className:Q.modalClose,onClick:()=>se(!1),children:`✕`})]}),(0,k.jsx)(`div`,{className:Q.modalBody,style:{gap:0},children:[`phase1`,`phase2`,`phase3`,`phase4`,`phase5`,`tools`,`golden`].map(t=>(0,k.jsxs)(`div`,{className:Q.doctrineSection,children:[(0,k.jsx)(`div`,{className:Q.doctrineSectionTitle,children:e(`webcraft.doctrine.${t}.title`)}),(0,k.jsx)(`div`,{className:Q.doctrineSectionBody,children:e(`webcraft.doctrine.${t}.desc`).split(`
809
- `).map((e,t)=>(0,k.jsx)(`p`,{className:e.startsWith(`•`)||e.startsWith(`1.`)||e.startsWith(`2.`)||e.startsWith(`3.`)||e.startsWith(`4.`)||e.startsWith(`5.`)||e.startsWith(`6.`)?Q.doctrineBullet:``,children:e},t))})]},t))}),(0,k.jsx)(`div`,{className:Q.modalFooter,children:(0,k.jsx)(`button`,{className:Q.modalSaveBtn,onClick:()=>se(!1),style:{padding:`10px 28px`,fontSize:14},children:e(`webcraft.doctrine.close`)})})]})}),Ge&&(0,k.jsx)(iE,{modal:Ge,skills:Ve,projectName:a,onClose:()=>Ke(null),onSave:(e,t,n)=>Ut(Ge,e,t,n)})]})}function eE(e,t){let n=e.length,r=t.length;if(n===0&&r===0)return[];if(n===r&&e.every((e,n)=>e===t[n]))return e.map((e,t)=>({type:`same`,text:e,oldLine:t+1,newLine:t+1}));if(n+r>8e3)return tE(e,t);let i=n+r,a=2*i+1,o=new Int32Array(a).fill(-1);new Int32Array(a).fill(-1);let s=i;o[s+1]=0;let c=[];outer:for(let l=0;l<=i;l++){let i=new Int32Array(a);i.set(o),c.push(i);for(let i=-l;i<=l;i+=2){let a;a=i===-l||i!==l&&o[s+i-1]<o[s+i+1]?o[s+i+1]:o[s+i-1]+1;let c=a-i;for(;a<n&&c<r&&e[a]===t[c];)a++,c++;if(o[s+i]=a,a>=n&&c>=r)break outer}}let l=[],u=n,d=r;for(let n=c.length-1;n>0;n--){let r=c[n-1],i=u-d,a;a=i===-n||i!==n&&r[s+i-1]<r[s+i+1]?i+1:i-1;let o=r[s+a],f=o-a;for(;u>o&&d>f;)u--,d--,l.push({type:`same`,text:e[u],oldLine:u+1,newLine:d+1});u>o?(u--,l.push({type:`rem`,text:e[u],oldLine:u+1})):d>f&&(d--,l.push({type:`add`,text:t[d],newLine:d+1}))}for(;u>0&&d>0;)u--,d--,l.push({type:`same`,text:e[u],oldLine:u+1,newLine:d+1});return l.reverse(),l}function tE(e,t){let n=[],r=0,i=0;for(;(r<e.length||i<t.length)&&(r>=e.length?(n.push({type:`add`,text:t[i],newLine:i+1}),i++):i>=t.length?(n.push({type:`rem`,text:e[r],oldLine:r+1}),r++):e[r]===t[i]?(n.push({type:`same`,text:e[r],oldLine:r+1,newLine:i+1}),r++,i++):(n.push({type:`rem`,text:e[r],oldLine:r+1}),n.push({type:`add`,text:t[i],newLine:i+1}),r++,i++),!(n.length>4e3)););return n}function nE(e,t){let n=(e||``).split(/(\s+)/),r=(t||``).split(/(\s+)/),i=n.length,a=r.length;if(i+a>400)return{old:(0,k.jsx)(k.Fragment,{children:e}),new:(0,k.jsx)(k.Fragment,{children:t})};let o=Array.from({length:i+1},()=>Array(a+1).fill(0));for(let e=1;e<=i;e++)for(let t=1;t<=a;t++)o[e][t]=n[e-1]===r[t-1]?o[e-1][t-1]+1:Math.max(o[e-1][t],o[e][t-1]);let s=[],c=[],l=i,u=a,d=[],f=[];for(;l>0||u>0;)l>0&&u>0&&n[l-1]===r[u-1]?(d.push({text:n[l-1],changed:!1}),f.push({text:r[u-1],changed:!1}),l--,u--):u>0&&(l===0||o[l][u-1]>=o[l-1][u])?(f.push({text:r[u-1],changed:!0}),u--):(d.push({text:n[l-1],changed:!0}),l--);return d.reverse().forEach(e=>s.push(e)),f.reverse().forEach(e=>c.push(e)),{old:(0,k.jsx)(k.Fragment,{children:s.map((e,t)=>e.changed?(0,k.jsx)(`span`,{style:{background:`rgba(248,113,113,0.3)`,borderRadius:2},children:e.text},t):(0,k.jsx)(`span`,{children:e.text},t))}),new:(0,k.jsx)(k.Fragment,{children:c.map((e,t)=>e.changed?(0,k.jsx)(`span`,{style:{background:`rgba(74,222,128,0.3)`,borderRadius:2},children:e.text},t):(0,k.jsx)(`span`,{children:e.text},t))})}}function rE({before:e,after:t,contextLines:n=3}){let r=eE((e||``).split(`
808
+ `).length;return(0,k.jsxs)(`details`,{open:!0,className:Q.diffFile,children:[(0,k.jsxs)(`summary`,{className:Q.diffSummary,children:[(0,k.jsx)(`span`,{className:Q.diffArrow,children:`▲`}),(0,k.jsx)(`span`,{className:Q.diffFileName,children:e.file}),(0,k.jsxs)(`span`,{className:n>=0?Q.diffAdded:Q.diffRemoved,children:[n>=0?`+`:``,n,` linee`]})]}),(0,k.jsx)(`div`,{className:Q.diffContent,children:(0,k.jsx)(rE,{before:e.before,after:e.after})})]},t)})]}),t!==`projects`&&(0,k.jsxs)(`div`,{className:`${Q.chatPanel} ${st?Q.chatPanelCollapsed:``}`,children:[(0,k.jsxs)(`button`,{className:Q.chatCollapseBtn,onClick:()=>ct(e=>!e),children:[(0,k.jsx)(`span`,{children:st?`▲`:`▼`}),(0,k.jsx)(`span`,{children:st?`Show Chat`:`Hide Chat`}),Me.length>0&&(0,k.jsxs)(`span`,{style:{opacity:.5},children:[`(`,Me.length,`)`]})]}),(0,k.jsxs)(`div`,{className:Q.chatMessages,ref:St,children:[Me.length===0&&Qt&&(0,k.jsxs)(`div`,{className:Q.chatWelcome,children:[`🤖 `,e(`webcraft.doctrine.title`),` — `,(0,k.jsx)(`button`,{className:Q.doctrineOpenBtn,onClick:()=>se(!0),children:`📖 Open Guide`})]}),Me.map((e,t)=>(0,k.jsxs)(`div`,{className:e.role===`user`?Q.chatUser:e.role===`system`?Q.chatSystem:Q.chatAgent,children:[e.role===`user`&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:Q.chatUserBubble,children:e.text}),e.attachments&&e.attachments.length>0&&(0,k.jsx)(`div`,{className:Q.chatAttachPreviews,children:e.attachments.map((e,t)=>(0,k.jsxs)(`span`,{className:Q.chatAttachBadge,children:[`📎 `,e.name]},t))})]}),e.role===`system`&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:Q.chatSystemBubble,children:e.text}),e.syntaxErrors?.map((e,t)=>(0,k.jsxs)(`div`,{className:Q.chatSyntaxErr,children:[`✕ `,e.file,`: `,e.error]},t))]}),e.role===`agent`&&(()=>{let t=e.text.replace(/<tool>[\s\S]*?<\/tool>/g,``).replace(/<done\s*\/?>/g,``).trim(),n=(e.tools||[]).filter(e=>(e.op===`edit`||e.op===`write`)&&(e.result===`ok`||e.result===`ok_fuzzy`||e.result===`ok_repaired`)),r=(e.tools||[]).filter(e=>e.result?.includes(`not_found`)||e.result?.includes(`error`)||e.result===`blocked_use_edit`),a=t.match(/^(.{10,120}?)[.\n]/),o=a?a[1]+`.`:t.slice(0,120),s=t.length>130;return(0,k.jsxs)(`div`,{className:Q.chatAgentCard,children:[n.map((e,t)=>(0,k.jsxs)(`div`,{style:{margin:`6px 0`,borderRadius:8,overflow:`hidden`,border:`1px solid rgba(255,255,255,0.08)`},children:[(0,k.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,padding:`6px 10px`,background:`rgba(99,102,241,0.1)`,fontSize:11},children:[(0,k.jsxs)(`span`,{style:{fontWeight:600,color:`#818cf8`,cursor:`pointer`},onClick:()=>{let t=p.findIndex(t=>t.name===e.path);t>=0&&(g(t),i(`files`))},children:[`✏ `,e.path]}),(0,k.jsx)(`span`,{style:{color:`#4ade80`,fontSize:10,fontWeight:600},children:e.result===`ok_fuzzy`?`applied (fuzzy)`:e.result===`ok_repaired`?`applied (repaired)`:`✓ applied`})]}),e.oldSnippet||e.newSnippet?(0,k.jsx)(rE,{before:e.oldSnippet||``,after:e.newSnippet||``,contextLines:3}):(0,k.jsx)(`div`,{style:{padding:`6px 10px`,fontSize:11,color:`#4ade80`,background:`rgba(74,222,128,0.05)`},children:`File modified successfully`})]},t)),r.length>0&&(0,k.jsx)(`div`,{style:{margin:`6px 0`,padding:`6px 10px`,background:`rgba(248,113,113,0.08)`,borderRadius:6,fontSize:11,color:`#f87171`},children:r.map((e,t)=>(0,k.jsxs)(`div`,{children:[`❌ `,e.op,` `,e.path,`: `,typeof e.result==`string`?e.result.slice(0,100):``]},t))}),t&&(s?(0,k.jsxs)(`details`,{style:{margin:`6px 0`,fontSize:11},children:[(0,k.jsx)(`summary`,{style:{cursor:`pointer`,color:`var(--dim)`,padding:`4px 0`,userSelect:`none`},children:o.slice(0,100)}),(0,k.jsx)(`div`,{className:Q.chatAgentText,style:{fontSize:11,opacity:.8,marginTop:4},dangerouslySetInnerHTML:{__html:KT(t)}})]}):(0,k.jsx)(`div`,{className:Q.chatAgentText,style:{fontSize:11,opacity:.8},dangerouslySetInnerHTML:{__html:KT(t)}}))]})})()]},t)),Ie&&(()=>{let e=Me[Me.length-1]?.tools??[],t=e[e.length-1],n=t?t.op===`read`?`Reading ${t.path}`:t.op===`edit`?`Editing ${t.path}`:t.op===`search`?`Searching...`:t.op===`lint`?`Linting ${t.path}`:t.op===`check`?`Checking ${t.path}`:t.op===`run`?`Running command...`:t.op===`sandbox`?`Starting sandbox...`:t.op:`Thinking...`;return(0,k.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`8px 12px`,fontSize:12,color:`#818cf8`},children:[(0,k.jsx)(`span`,{className:Q.chatAgentRobotAnim,style:{fontSize:14},children:`⟳`}),(0,k.jsx)(`span`,{style:{fontWeight:500},children:n})]})})()]}),Re.length>0&&(0,k.jsx)(`div`,{className:Q.attachPreviews,children:Re.map((e,t)=>(0,k.jsxs)(`span`,{className:Q.attachBadge,children:[`📎 `,e.name,(0,k.jsx)(`button`,{className:Q.removeAttachBtn,onClick:()=>ze(e=>e.filter((e,n)=>n!==t)),children:`×`})]},t))}),Qt?(0,k.jsxs)(`div`,{className:Q.projActiveRow,children:[`📄 `,(0,k.jsx)(`strong`,{className:Q.projActiveName,children:a}),` — scrivi per modificare o migliorare il progetto`]}):(0,k.jsxs)(`div`,{className:Q.projNameRow,children:[(0,k.jsx)(`span`,{className:Q.projNameLabel,children:`Nome progetto:`}),(0,k.jsx)(`input`,{className:Q.projNameInput,value:a,onChange:e=>o(e.target.value),placeholder:`MioProgetto`})]}),(0,k.jsxs)(`div`,{className:Q.chatInputRow,children:[(0,k.jsxs)(`label`,{className:Q.attachLabel,title:`Allega immagine o PDF`,children:[`📎`,(0,k.jsx)(`input`,{ref:Ct,type:`file`,multiple:!0,accept:`image/*,.pdf`,style:{display:`none`},onChange:e=>Zt(e.target.files)})]}),(0,k.jsx)(`textarea`,{className:Q.chatTextarea,value:Pe,onChange:e=>Fe(e.target.value),placeholder:Qt?`Parla con il tuo agente: chiedi correzioni, migliorie, nuove funzionalità...`:`Descrivi il progetto da creare, poi premi Genera...`,disabled:$t,onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),B())},rows:4}),(0,k.jsxs)(`div`,{className:Q.chatSendCol,children:[(0,k.jsx)(`button`,{className:Q.chatSendBtn,onClick:B,disabled:$t,children:be?`⏳`:Qt?`▶`:`▶ Genera`}),$t&&!Se&&(0,k.jsx)(`button`,{className:Q.chatStopBtn,onClick:Pt,children:`⏹ Stop`})]})]})]}),oe&&(0,k.jsx)(`div`,{className:Q.modalOverlay,onClick:()=>se(!1),children:(0,k.jsxs)(`div`,{className:Q.modal,onClick:e=>e.stopPropagation(),style:{width:720,maxHeight:`90vh`},children:[(0,k.jsxs)(`div`,{className:Q.modalHeader,children:[(0,k.jsxs)(`span`,{className:Q.modalTitle,children:[`📖 `,e(`webcraft.doctrine.title`)]}),(0,k.jsx)(`span`,{className:Q.doctrineSubtitle,children:e(`webcraft.doctrine.subtitle`)}),(0,k.jsx)(`button`,{className:Q.modalClose,onClick:()=>se(!1),children:`✕`})]}),(0,k.jsx)(`div`,{className:Q.modalBody,style:{gap:0},children:[`phase1`,`phase2`,`phase3`,`phase4`,`phase5`,`tools`,`golden`].map(t=>(0,k.jsxs)(`div`,{className:Q.doctrineSection,children:[(0,k.jsx)(`div`,{className:Q.doctrineSectionTitle,children:e(`webcraft.doctrine.${t}.title`)}),(0,k.jsx)(`div`,{className:Q.doctrineSectionBody,children:e(`webcraft.doctrine.${t}.desc`).split(`
809
+ `).map((e,t)=>(0,k.jsx)(`p`,{className:e.startsWith(`•`)||e.startsWith(`1.`)||e.startsWith(`2.`)||e.startsWith(`3.`)||e.startsWith(`4.`)||e.startsWith(`5.`)||e.startsWith(`6.`)?Q.doctrineBullet:``,children:e},t))})]},t))}),(0,k.jsx)(`div`,{className:Q.modalFooter,children:(0,k.jsx)(`button`,{className:Q.modalSaveBtn,onClick:()=>se(!1),style:{padding:`10px 28px`,fontSize:14},children:e(`webcraft.doctrine.close`)})})]})}),Ge&&(0,k.jsx)(iE,{modal:Ge,skills:Ve,projectName:a,onClose:()=>Ke(null),onSave:(e,t,n)=>Gt(Ge,e,t,n)})]})}function eE(e,t){let n=e.length,r=t.length;if(n===0&&r===0)return[];if(n===r&&e.every((e,n)=>e===t[n]))return e.map((e,t)=>({type:`same`,text:e,oldLine:t+1,newLine:t+1}));if(n+r>8e3)return tE(e,t);let i=n+r,a=2*i+1,o=new Int32Array(a).fill(-1);new Int32Array(a).fill(-1);let s=i;o[s+1]=0;let c=[];outer:for(let l=0;l<=i;l++){let i=new Int32Array(a);i.set(o),c.push(i);for(let i=-l;i<=l;i+=2){let a;a=i===-l||i!==l&&o[s+i-1]<o[s+i+1]?o[s+i+1]:o[s+i-1]+1;let c=a-i;for(;a<n&&c<r&&e[a]===t[c];)a++,c++;if(o[s+i]=a,a>=n&&c>=r)break outer}}let l=[],u=n,d=r;for(let n=c.length-1;n>0;n--){let r=c[n-1],i=u-d,a;a=i===-n||i!==n&&r[s+i-1]<r[s+i+1]?i+1:i-1;let o=r[s+a],f=o-a;for(;u>o&&d>f;)u--,d--,l.push({type:`same`,text:e[u],oldLine:u+1,newLine:d+1});u>o?(u--,l.push({type:`rem`,text:e[u],oldLine:u+1})):d>f&&(d--,l.push({type:`add`,text:t[d],newLine:d+1}))}for(;u>0&&d>0;)u--,d--,l.push({type:`same`,text:e[u],oldLine:u+1,newLine:d+1});return l.reverse(),l}function tE(e,t){let n=[],r=0,i=0;for(;(r<e.length||i<t.length)&&(r>=e.length?(n.push({type:`add`,text:t[i],newLine:i+1}),i++):i>=t.length?(n.push({type:`rem`,text:e[r],oldLine:r+1}),r++):e[r]===t[i]?(n.push({type:`same`,text:e[r],oldLine:r+1,newLine:i+1}),r++,i++):(n.push({type:`rem`,text:e[r],oldLine:r+1}),n.push({type:`add`,text:t[i],newLine:i+1}),r++,i++),!(n.length>4e3)););return n}function nE(e,t){let n=(e||``).split(/(\s+)/),r=(t||``).split(/(\s+)/),i=n.length,a=r.length;if(i+a>400)return{old:(0,k.jsx)(k.Fragment,{children:e}),new:(0,k.jsx)(k.Fragment,{children:t})};let o=Array.from({length:i+1},()=>Array(a+1).fill(0));for(let e=1;e<=i;e++)for(let t=1;t<=a;t++)o[e][t]=n[e-1]===r[t-1]?o[e-1][t-1]+1:Math.max(o[e-1][t],o[e][t-1]);let s=[],c=[],l=i,u=a,d=[],f=[];for(;l>0||u>0;)l>0&&u>0&&n[l-1]===r[u-1]?(d.push({text:n[l-1],changed:!1}),f.push({text:r[u-1],changed:!1}),l--,u--):u>0&&(l===0||o[l][u-1]>=o[l-1][u])?(f.push({text:r[u-1],changed:!0}),u--):(d.push({text:n[l-1],changed:!0}),l--);return d.reverse().forEach(e=>s.push(e)),f.reverse().forEach(e=>c.push(e)),{old:(0,k.jsx)(k.Fragment,{children:s.map((e,t)=>e.changed?(0,k.jsx)(`span`,{style:{background:`rgba(248,113,113,0.3)`,borderRadius:2},children:e.text},t):(0,k.jsx)(`span`,{children:e.text},t))}),new:(0,k.jsx)(k.Fragment,{children:c.map((e,t)=>e.changed?(0,k.jsx)(`span`,{style:{background:`rgba(74,222,128,0.3)`,borderRadius:2},children:e.text},t):(0,k.jsx)(`span`,{children:e.text},t))})}}function rE({before:e,after:t,contextLines:n=3}){let r=eE((e||``).split(`
810
810
  `),(t||``).split(`
811
811
  `)),i=new Set;r.forEach((e,t)=>{e.type!==`same`&&i.add(t)});let a=new Set;if(i.forEach(e=>{for(let t=Math.max(0,e-n);t<=Math.min(r.length-1,e+n);t++)a.add(t)}),i.size===0)for(let e=0;e<Math.min(5,r.length);e++)a.add(e);let o=new Map;for(let e=0;e<r.length-1;e++)r[e].type===`rem`&&r[e+1].type===`add`&&o.set(e,nE(r[e].text,r[e+1].text));let s=[],c=-1;for(let e=0;e<r.length;e++){if(!a.has(e))continue;if(c>=0&&e-c>1){let t=e-c-1;s.push((0,k.jsxs)(`div`,{style:{padding:`2px 8px`,background:`rgba(99,102,241,0.08)`,color:`#6366f1`,fontSize:9,textAlign:`center`,borderTop:`1px solid rgba(99,102,241,0.15)`,borderBottom:`1px solid rgba(99,102,241,0.15)`,userSelect:`none`},children:[`@@ `,t,` righe nascoste @@`]},`fold-${e}`))}c=e;let t=r[e],n=t.type===`add`?`rgba(74,222,128,0.08)`:t.type===`rem`?`rgba(248,113,113,0.08)`:`transparent`,i=t.type===`add`?`3px solid #4ade80`:t.type===`rem`?`3px solid #f87171`:`3px solid transparent`,l=t.type===`add`?`#4ade80`:t.type===`rem`?`#f87171`:`var(--dim)`,u=t.type===`add`?`+`:t.type===`rem`?`-`:` `,d=t.text,f=o.get(e);f&&t.type===`rem`&&(d=f.old);let p=o.get(e-1);p&&t.type===`add`&&(d=p.new),s.push((0,k.jsxs)(`div`,{style:{display:`flex`,alignItems:`stretch`,background:n,borderLeft:i,fontFamily:`var(--mono)`,fontSize:11,lineHeight:`18px`},children:[(0,k.jsx)(`span`,{style:{width:36,textAlign:`right`,padding:`0 4px`,color:`rgba(255,255,255,0.2)`,fontSize:10,flexShrink:0,userSelect:`none`},children:t.oldLine??``}),(0,k.jsx)(`span`,{style:{width:36,textAlign:`right`,padding:`0 4px`,color:`rgba(255,255,255,0.2)`,fontSize:10,flexShrink:0,userSelect:`none`},children:t.newLine??``}),(0,k.jsx)(`span`,{style:{width:14,textAlign:`center`,color:l,fontWeight:700,flexShrink:0,userSelect:`none`},children:u}),(0,k.jsx)(`span`,{style:{flex:1,padding:`0 4px`,color:l,whiteSpace:`pre-wrap`,wordBreak:`break-all`},children:d})]},e))}return(0,k.jsx)(`div`,{style:{overflow:`auto`,maxHeight:400},children:s})}function iE({modal:e,skills:t,projectName:n,onClose:r,onSave:i}){let[a,o]=(0,_.useState)(e.name),[s,c]=(0,_.useState)(e.content),[l,u]=(0,_.useState)(e.type),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(!1),h=l===`skill`?6e3:4e3,g=s.length>h;async function v(){if(!d.trim())return;m(!0);let e={skill:`Sei un esperto di sviluppo web fullstack. Genera un file Markdown "skill" per il WebCraft Agent. Deve contenere istruzioni, pattern di codice, best practice e snippet pronti all uso come contesto persistente. Scrivi SOLO il contenuto Markdown, niente altro.`,memory:`Sei un assistente tecnico. Genera un file Markdown "memory" per il WebCraft Agent. Deve riassumere decisioni architetturali, preferenze dello sviluppatore e contesto generale del progetto. Scrivi SOLO il Markdown.`,provider:`Sei un esperto di prompt engineering. Genera un file Markdown con istruzioni specifiche per calibrare il comportamento del modello AI. Scrivi SOLO il Markdown.`},t=await D(`/api/studio/webcraft`,{system:e[l]??e.skill,user:`Progetto: ${n}\n\n${d}`,max_tokens:2048});t?.text&&(c(t.text),a||o(l===`memory`?`memory.md`:l===`provider`?`liara.md`:d.toLowerCase().replace(/[^a-z0-9]+/g,`-`).slice(0,30)+`.md`)),m(!1)}function y(){if(!a.trim()){alert(`Inserisci un nome per il file.`);return}let n=a.endsWith(`.md`)?a:a+`.md`;if((l===`memory`||l===`provider`)&&e.mode===`new`&&t.findIndex(e=>e.type===l)>=0){alert(`Esiste già un file di tipo "${l}". Modificalo direttamente.`);return}i(n,s,l)}return(0,k.jsx)(`div`,{className:Q.modalOverlay,onClick:e=>{e.target===e.currentTarget&&r()},children:(0,k.jsxs)(`div`,{className:Q.modal,children:[(0,k.jsxs)(`div`,{className:Q.modalHeader,children:[(0,k.jsxs)(`span`,{className:Q.modalTitle,children:[QT(l),` `,e.mode===`new`?`Nuovo file di contesto`:`Modifica ${e.name}`]}),(0,k.jsx)(`button`,{className:Q.modalClose,onClick:r,children:`×`})]}),(0,k.jsx)(`div`,{className:Q.modalBody,children:e.mode===`view`?(0,k.jsx)(`pre`,{className:Q.logView,children:s}):(0,k.jsxs)(k.Fragment,{children:[e.mode===`new`&&(0,k.jsxs)(`div`,{className:Q.modalRow,children:[(0,k.jsxs)(`div`,{className:Q.modalField,children:[(0,k.jsx)(`div`,{className:Q.modalLabel,children:`TIPO`}),(0,k.jsx)(`select`,{value:l,onChange:e=>{let t=e.target.value;u(t),t===`memory`?o(`memory.md`):t===`provider`&&o(`liara.md`)},className:Q.modalSelect,children:[`skill`,`memory`,`provider`].map(e=>{let n=(e===`memory`||e===`provider`)&&t.some(t=>t.type===e);return(0,k.jsxs)(`option`,{value:e,disabled:n,children:[e,n?` (esiste già)`:``]},e)})})]}),(0,k.jsxs)(`div`,{className:Q.modalField,style:{flex:2},children:[(0,k.jsx)(`div`,{className:Q.modalLabel,children:`NOME FILE`}),(0,k.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),placeholder:l===`memory`?`memory.md`:l===`provider`?`liara.md`:`nome-skill.md`,className:Q.modalInput})]})]}),(0,k.jsxs)(`div`,{className:Q.modalHint,children:[`💡 `,l===`skill`?`Istruzioni tecniche, snippet, pattern di codice specifici. Max ~6000 caratteri.`:l===`memory`?`Note persistenti sul progetto: decisioni architetturali, preferenze. Solo UN file. Max ~4000 caratteri.`:`Istruzioni specifiche per il modello AI (tono, formato, vincoli). Solo UN file. Max ~4000 caratteri.`]}),(0,k.jsxs)(`div`,{className:Q.modalAiBox,children:[(0,k.jsx)(`div`,{className:Q.modalLabel,children:`🤖 GENERA CON AI`}),(0,k.jsxs)(`div`,{className:Q.modalAiRow,children:[(0,k.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),rows:2,placeholder:`Descrivi cosa deve contenere questo file...`,className:Q.modalAiDesc}),(0,k.jsx)(`button`,{onClick:v,disabled:p,className:Q.modalAiBtn,children:p?`⏳ ...`:`▶ Genera`})]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`div`,{className:Q.modalLabelRow,children:[(0,k.jsx)(`span`,{children:`CONTENUTO (markdown)`}),(0,k.jsxs)(`span`,{style:{color:g?`#e05050`:`var(--dim)`},children:[s.length,` car.`,g?` ⚠ Troppo lungo`:``]})]}),(0,k.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),rows:14,placeholder:`# Titolo
812
812
  Scrivi le istruzioni in Markdown...`,className:Q.modalContentArea,style:{borderColor:g?`#e05050`:`var(--border2)`}})]})]})}),(0,k.jsxs)(`div`,{className:Q.modalFooter,children:[(0,k.jsx)(`button`,{onClick:r,className:Q.modalCancelBtn,children:`Annulla`}),e.mode!==`view`&&(0,k.jsx)(`button`,{onClick:y,className:Q.modalSaveBtn,children:`✓ Salva`})]})]})})}var aE={root:`_root_x9yvu_1`,loading:`_loading_x9yvu_7`,empty:`_empty_x9yvu_18`,emptyIcon:`_emptyIcon_x9yvu_29`,emptyTitle:`_emptyTitle_x9yvu_30`,emptySub:`_emptySub_x9yvu_31`,generateBtn:`_generateBtn_x9yvu_33`,summary:`_summary_x9yvu_46`,sectionTitle:`_sectionTitle_x9yvu_57`,alertTitle:`_alertTitle_x9yvu_68`,actionCard:`_actionCard_x9yvu_70`,actionTime:`_actionTime_x9yvu_81`,actionText:`_actionText_x9yvu_89`,schedCard:`_schedCard_x9yvu_95`,schedTime:`_schedTime_x9yvu_106`,schedTitle:`_schedTitle_x9yvu_114`,alertCard:`_alertCard_x9yvu_119`,alertSev:`_alertSev_x9yvu_129`,alertAction:`_alertAction_x9yvu_135`,insight:`_insight_x9yvu_141`,regenRow:`_regenRow_x9yvu_148`,regenBtn:`_regenBtn_x9yvu_153`};function oE(){let e=j(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(!1),l=()=>{i(!0),c(!1),E(`/api/plan`).then(e=>{e?.plan?(n(e.plan),c(!1)):(n(null),c(!0)),i(!1)}).catch(()=>{i(!1),c(!0)})},u=async()=>{o(!0),i(!0),n(null);try{await D(`/api/plan/refresh`,{}),l()}catch{i(!1)}finally{o(!1)}};if((0,_.useEffect)(()=>{l()},[]),r)return(0,k.jsxs)(`div`,{className:aE.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),(0,k.jsx)(`div`,{children:a?`Generating plan with 5 agents...`:`Loading plan...`})]});if(s||!t)return(0,k.jsxs)(`div`,{className:aE.empty,children:[(0,k.jsx)(`div`,{className:aE.emptyIcon,children:`🗓️`}),(0,k.jsxs)(`div`,{className:aE.emptyTitle,children:[e(`plan.noplan`),` generated yet`]}),(0,k.jsx)(`div`,{className:aE.emptySub,children:`Generate a daily plan using your calendar, tasks, and emails.`}),(0,k.jsx)(`button`,{className:aE.generateBtn,onClick:u,children:e(`plan.generate`)})]});let d=e=>typeof e==`string`?e:e.description??e.message??e.action_required??`Alert`,f=e=>typeof e==`object`&&e.severity?` [${e.severity.toUpperCase()}]`:``,p=e=>typeof e==`object`&&e.action_required&&e.action_required!==d(e)?e.action_required:``,m=e=>typeof e==`string`?e:e.message??e.insight??``;return(0,k.jsxs)(`div`,{className:aE.root,children:[t.executive_summary&&(0,k.jsx)(`div`,{className:aE.summary,children:t.executive_summary}),t.priority_actions&&t.priority_actions.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:aE.sectionTitle,children:`Priority Actions`}),t.priority_actions.map((e,t)=>(0,k.jsxs)(`div`,{className:aE.actionCard,children:[e.time&&(0,k.jsx)(`span`,{className:aE.actionTime,children:e.time}),(0,k.jsx)(`span`,{className:aE.actionText,children:e.action})]},t))]}),t.schedule&&t.schedule.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:aE.sectionTitle,children:`Schedule`}),t.schedule.map((e,t)=>(0,k.jsxs)(`div`,{className:aE.schedCard,children:[(0,k.jsxs)(`span`,{className:aE.schedTime,children:[e.time_start,`–`,e.time_end]}),(0,k.jsx)(`span`,{className:aE.schedTitle,children:e.title})]},t))]}),t.security_alerts&&t.security_alerts.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:`${aE.sectionTitle} ${aE.alertTitle}`,children:`Security Alerts`}),t.security_alerts.map((e,t)=>(0,k.jsxs)(`div`,{className:aE.alertCard,children:[(0,k.jsxs)(`span`,{className:aE.alertSev,children:[`!`,f(e)]}),(0,k.jsx)(`span`,{children:d(e)}),p(e)&&(0,k.jsxs)(`div`,{className:aE.alertAction,children:[`Action: `,p(e)]})]},t))]}),t.insights&&t.insights.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:aE.sectionTitle,children:`Insights`}),t.insights.map((e,t)=>(0,k.jsxs)(`div`,{className:aE.insight,children:[`→ `,m(e)]},t))]}),(0,k.jsx)(`div`,{className:aE.regenRow,children:(0,k.jsx)(`button`,{className:aE.regenBtn,onClick:u,disabled:a,children:a?`Regenerating…`:`↺ Regenerate`})})]})}function sE(e){return e===`folder`?`📁`:e===`image`?`🖼`:e===`pdf`?`📕`:e===`video`?`🎬`:e===`audio`?`🎵`:e===`sheet`?`📊`:e===`slides`?`📽`:`📄`}function cE(){let e=j(),[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),l=(e=``)=>{i(!0),E(e?`/api/onedrive?q=${encodeURIComponent(e)}`:`/api/onedrive`).then(e=>{n(e??{files:[]}),i(!1)}).catch(()=>{o(`Could not load OneDrive. Run nha microsoft auth in the terminal to connect.`),i(!1)})};if((0,_.useEffect)(()=>{l()},[]),a)return(0,k.jsx)(`div`,{className:G.error,children:a});let u=t?.files??[],d=t?.quota;return(0,k.jsxs)(`div`,{className:G.root,children:[d&&(0,k.jsxs)(`div`,{className:G.quotaBar,children:[(0,k.jsxs)(`div`,{className:G.quotaText,children:[(0,k.jsxs)(`span`,{className:G.quotaUsed,children:[d.usage,` of `,d.limit,` used`]}),(0,k.jsxs)(`span`,{className:G.quotaPct,children:[d.percentUsed,`%`]})]}),(0,k.jsx)(`div`,{className:G.quotaTrack,children:(0,k.jsx)(`div`,{className:G.quotaFill,style:{width:`${Math.min(d.percentUsed,100)}%`,background:d.percentUsed>90?`var(--red)`:d.percentUsed>70?`var(--amber)`:`var(--cyan)`}})})]}),(0,k.jsxs)(`div`,{className:G.searchRow,children:[(0,k.jsx)(`input`,{className:G.searchInput,value:s,onChange:e=>c(e.target.value),placeholder:`Search OneDrive files…`,onKeyDown:e=>e.key===`Enter`&&l(s)}),(0,k.jsx)(`button`,{className:G.searchBtn,onClick:()=>l(s),children:`Search`})]}),r&&(0,k.jsxs)(`div`,{className:G.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}),!r&&u.length===0&&(0,k.jsx)(`div`,{className:G.empty,children:e(`drive.noFiles`)}),(0,k.jsx)(`div`,{className:G.fileList,children:u.map(e=>(0,k.jsxs)(`div`,{className:G.fileRow,children:[(0,k.jsx)(`span`,{className:G.fileIcon,children:sE(e.type)}),(0,k.jsxs)(`div`,{className:G.fileInfo,children:[(0,k.jsx)(`div`,{className:G.fileName,children:e.name}),(0,k.jsxs)(`div`,{className:G.fileMeta,children:[e.modifiedTime?new Date(e.modifiedTime).toLocaleDateString():``,e.size?` · ${e.size}`:``]})]}),(0,k.jsx)(`div`,{className:G.fileBtns,children:e.webViewLink&&(0,k.jsx)(`a`,{className:G.openBtn,href:e.webViewLink,target:`_blank`,rel:`noreferrer`,children:`Open`})})]},e.id))})]})}var lE={root:`_root_1vbmp_1`,loading:`_loading_1vbmp_2`,error:`_error_1vbmp_3`,empty:`_empty_1vbmp_4`,addRow:`_addRow_1vbmp_6`,addInput:`_addInput_1vbmp_7`,addBtn:`_addBtn_1vbmp_8`,list:`_list_1vbmp_10`,taskRow:`_taskRow_1vbmp_11`,checkBtn:`_checkBtn_1vbmp_12`,taskInfo:`_taskInfo_1vbmp_14`,taskTitle:`_taskTitle_1vbmp_15`,taskDue:`_taskDue_1vbmp_16`,taskImp:`_taskImp_1vbmp_17`};function uE(){let e=j(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(``),l=()=>{E(`/api/mstodo`).then(e=>{n(e?.tasks??[]),i(!1)}).catch(()=>{o(`Microsoft To Do requires Microsoft authentication. Run nha microsoft auth in the terminal.`),i(!1)})};(0,_.useEffect)(()=>{l()},[]);let u=()=>{let e=s.trim();e&&(c(``),D(`/api/mstodo`,{title:e}).then(e=>{e?.task&&l()}))},d=(e,t)=>{D(`/api/mstodo/${e}/complete`,{listId:t}).then(()=>l())};return r?(0,k.jsxs)(`div`,{className:lE.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):a?(0,k.jsx)(`div`,{className:lE.error,children:a}):(0,k.jsxs)(`div`,{className:lE.root,children:[(0,k.jsxs)(`div`,{className:lE.addRow,children:[(0,k.jsx)(`input`,{className:lE.addInput,value:s,onChange:e=>c(e.target.value),placeholder:`Add a new task…`,onKeyDown:e=>e.key===`Enter`&&u()}),(0,k.jsx)(`button`,{className:lE.addBtn,onClick:u,children:`+ Add`})]}),t.length===0&&(0,k.jsx)(`div`,{className:lE.empty,children:`No active tasks`}),(0,k.jsx)(`div`,{className:lE.list,children:t.map(e=>{let t=e.importance===`high`?`var(--red)`:e.importance===`low`?`var(--dim)`:`var(--amber)`;return(0,k.jsxs)(`div`,{className:lE.taskRow,children:[(0,k.jsx)(`button`,{className:lE.checkBtn,onClick:()=>d(e.id,e.listId)}),(0,k.jsxs)(`div`,{className:lE.taskInfo,children:[(0,k.jsx)(`div`,{className:lE.taskTitle,children:e.title}),e.dueDate&&(0,k.jsxs)(`div`,{className:lE.taskDue,children:[`Due: `,e.dueDate.split(`T`)[0]]})]}),e.importance&&(0,k.jsx)(`span`,{className:lE.taskImp,style:{color:t},children:e.importance})]},e.id)})})]})}var dE={root:`_root_1ag4s_1`,header:`_header_1ag4s_3`,title:`_title_1ag4s_4`,subtitle:`_subtitle_1ag4s_5`,controls:`_controls_1ag4s_7`,monitorRow:`_monitorRow_1ag4s_8`,label:`_label_1ag4s_9`,monitorBtn:`_monitorBtn_1ag4s_10`,monitorActive:`_monitorActive_1ag4s_11`,captureBtn:`_captureBtn_1ag4s_12`,analyzeSection:`_analyzeSection_1ag4s_15`,sectionTitle:`_sectionTitle_1ag4s_16`,presets:`_presets_1ag4s_17`,preset:`_preset_1ag4s_17`,presetActive:`_presetActive_1ag4s_20`,questionRow:`_questionRow_1ag4s_21`,questionInput:`_questionInput_1ag4s_22`,analyzeBtn:`_analyzeBtn_1ag4s_23`,error:`_error_1ag4s_26`,screenshotContainer:`_screenshotContainer_1ag4s_28`,screenshot:`_screenshot_1ag4s_28`,screenshotMeta:`_screenshotMeta_1ag4s_30`,analysis:`_analysis_1ag4s_32`,analysisTitle:`_analysisTitle_1ag4s_33`,analysisText:`_analysisText_1ag4s_34`,continueInChat:`_continueInChat_1ag4s_35`,history:`_history_1ag4s_37`,historyGrid:`_historyGrid_1ag4s_38`,historyItem:`_historyItem_1ag4s_39`,historyThumb:`_historyThumb_1ag4s_40`,historyMeta:`_historyMeta_1ag4s_41`,historyTs:`_historyTs_1ag4s_42`,historyQ:`_historyQ_1ag4s_43`,historyA:`_historyA_1ag4s_44`},fE=[`Describe exactly what you see on the screen`,`Identify any errors, warnings, or issues visible`,`What application is open and what is the user doing?`,`Summarize the content visible on screen and suggest next actions`,`Read and extract all visible text from the screen`,`Analyze the code visible on screen and identify bugs or improvements`,`What financial data or charts are visible? Summarize key numbers`,`Is there anything sensitive or that should be kept private?`];function pE(){let e=j(),t=T(e=>e.setView),n=T(e=>e.apiBase),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(1),[p,m]=(0,_.useState)([]),h=async()=>{i(!0),c(null);try{let e=await D(`/api/screen/capture`,{monitor:d});c(e),(e?.base64||e?.file)&&m(t=>[{ts:new Date().toLocaleTimeString(),question:`Screenshot`,analysis:``,src:e.base64?`data:image/${e.format??`jpeg`};base64,${e.base64}`:`${n}/api/screenshots/${e.file}`},...t.slice(0,9)])}catch(e){c({error:e.message})}i(!1)},g=async()=>{if(l.trim()){o(!0);try{let e=await D(`/api/screen/analyze`,{question:l.trim(),monitor:d});if(c(e),e?.analysis){let t=e.base64?`data:image/${e.format??`jpeg`};base64,${e.base64}`:e.file?`${n}/api/screenshots/${e.file}`:``;m(n=>[{ts:new Date().toLocaleTimeString(),question:l.trim(),analysis:e.analysis??``,src:t},...n.slice(0,9)])}}catch(e){c({error:e.message})}o(!1)}},v=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},y=s?.base64?`data:image/${s.format??`jpeg`};base64,${s.base64}`:s?.file?`${n}/api/screenshots/${s.file}`:null;return(0,k.jsxs)(`div`,{className:dE.root,children:[(0,k.jsx)(`div`,{className:dE.header,children:(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:dE.title,children:`🖥️ Screen Capture`}),(0,k.jsxs)(`div`,{className:dE.subtitle,children:[e(`screen.capture`),` and analyze your desktop screen with AI vision`]})]})}),(0,k.jsxs)(`div`,{className:dE.controls,children:[(0,k.jsxs)(`div`,{className:dE.monitorRow,children:[(0,k.jsx)(`label`,{className:dE.label,children:`Monitor`}),[1,2,3].map(e=>(0,k.jsxs)(`button`,{className:`${dE.monitorBtn} ${d===e?dE.monitorActive:``}`,onClick:()=>f(e),children:[`Monitor `,e]},e))]}),(0,k.jsx)(`button`,{className:dE.captureBtn,onClick:h,disabled:r||a,children:r?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:`spinner`}),` Capturing…`]}):`📷 Capture Screen`})]}),(0,k.jsxs)(`div`,{className:dE.analyzeSection,children:[(0,k.jsx)(`div`,{className:dE.sectionTitle,children:`Capture + Analyze`}),(0,k.jsx)(`div`,{className:dE.presets,children:fE.map(e=>(0,k.jsxs)(`button`,{className:`${dE.preset} ${l===e?dE.presetActive:``}`,onClick:()=>u(e),children:[e.slice(0,50),e.length>50?`…`:``]},e))}),(0,k.jsxs)(`div`,{className:dE.questionRow,children:[(0,k.jsx)(`input`,{className:dE.questionInput,value:l,onChange:e=>u(e.target.value),placeholder:`Ask something about your screen…`,onKeyDown:e=>e.key===`Enter`&&g()}),(0,k.jsx)(`button`,{className:dE.analyzeBtn,onClick:g,disabled:!l.trim()||r||a,children:a?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:`spinner`}),` Analyzing…`]}):`🔍 Analyze`})]})]}),s?.error&&(0,k.jsx)(`div`,{className:dE.error,children:s.error}),y&&(0,k.jsxs)(`div`,{className:dE.screenshotContainer,children:[(0,k.jsx)(`img`,{src:y,className:dE.screenshot,alt:`Screen capture`}),s?.width&&s?.height&&(0,k.jsxs)(`div`,{className:dE.screenshotMeta,children:[s.width,` × `,s.height,`px`]})]}),s?.analysis&&(0,k.jsxs)(`div`,{className:dE.analysis,children:[(0,k.jsx)(`div`,{className:dE.analysisTitle,children:`AI Analysis`}),(0,k.jsx)(`div`,{className:dE.analysisText,children:s.analysis}),(0,k.jsx)(`button`,{className:dE.continueInChat,onClick:()=>v(`I captured my screen. Here's what the AI saw:\n\n${s.analysis}\n\nCan you help me with this?`),children:`Continue in Chat →`})]}),p.length>0&&(0,k.jsxs)(`div`,{className:dE.history,children:[(0,k.jsx)(`div`,{className:dE.sectionTitle,children:`Recent Captures`}),(0,k.jsx)(`div`,{className:dE.historyGrid,children:p.map((e,t)=>(0,k.jsxs)(`div`,{className:dE.historyItem,children:[e.src&&(0,k.jsx)(`img`,{src:e.src,className:dE.historyThumb,alt:e.question}),(0,k.jsxs)(`div`,{className:dE.historyMeta,children:[(0,k.jsx)(`div`,{className:dE.historyTs,children:e.ts}),(0,k.jsx)(`div`,{className:dE.historyQ,children:e.question}),e.analysis&&(0,k.jsxs)(`div`,{className:dE.historyA,children:[e.analysis.slice(0,120),`…`]})]})]},t))})]})]})}var mE={root:`_root_v12qq_1`,header:`_header_v12qq_3`,title:`_title_v12qq_4`,subtitle:`_subtitle_v12qq_5`,section:`_section_v12qq_7`,sectionTitle:`_sectionTitle_v12qq_8`,quickBtns:`_quickBtns_v12qq_10`,quickBtn:`_quickBtn_v12qq_10`,searchRow:`_searchRow_v12qq_14`,searchInput:`_searchInput_v12qq_15`,searchBtn:`_searchBtn_v12qq_16`,modeRow:`_modeRow_v12qq_19`,modeBtn:`_modeBtn_v12qq_20`,modeActive:`_modeActive_v12qq_21`,routeInputs:`_routeInputs_v12qq_23`,inputWrapper:`_inputWrapper_v12qq_24`,inputIcon:`_inputIcon_v12qq_25`,routeInput:`_routeInput_v12qq_23`,swapBtn:`_swapBtn_v12qq_27`,dirBtns:`_dirBtns_v12qq_29`,dirBtn:`_dirBtn_v12qq_29`,openMapsBtn:`_openMapsBtn_v12qq_32`,error:`_error_v12qq_34`,resultCard:`_resultCard_v12qq_36`,routeSummary:`_routeSummary_v12qq_37`,routeDistance:`_routeDistance_v12qq_38`,routeDuration:`_routeDuration_v12qq_39`,routeMode:`_routeMode_v12qq_40`,steps:`_steps_v12qq_41`,step:`_step_v12qq_41`,stepNum:`_stepNum_v12qq_43`,stepText:`_stepText_v12qq_44`,mapLink:`_mapLink_v12qq_45`,askChatBtn:`_askChatBtn_v12qq_47`,savedRoute:`_savedRoute_v12qq_49`,savedFrom:`_savedFrom_v12qq_51`,savedArrow:`_savedArrow_v12qq_52`,savedTo:`_savedTo_v12qq_53`,savedTs:`_savedTs_v12qq_54`},hE=[`driving`,`walking`,`bicycling`,`transit`],gE={driving:`🚗`,walking:`🚶`,bicycling:`🚲`,transit:`🚌`},_E=[{label:`🏥 Nearest Hospital`,query:`nearest hospital`},{label:`⛽ Gas Station`,query:`gas station near me`},{label:`🛒 Supermarket`,query:`supermarket near me`},{label:`☕ Coffee Shop`,query:`coffee shop near me`},{label:`🏧 ATM`,query:`ATM near me`},{label:`🍕 Pizza`,query:`pizza restaurant near me`}];function vE(e,t,n){try{let r=JSON.parse(localStorage.getItem(`nha_maps_routes`)??`[]`),i=[{from:e,to:t,label:n,ts:new Date().toISOString()},...r.filter(n=>!(n.from===e&&n.to===t))].slice(0,10);localStorage.setItem(`nha_maps_routes`,JSON.stringify(i))}catch{}}function yE(){try{return JSON.parse(localStorage.getItem(`nha_maps_routes`)??`[]`)}catch{return[]}}function bE(){let e=j(),t=T(e=>e.setView),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(`driving`),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(yE),[m,h]=(0,_.useState)(``),g=async()=>{if(!(!n.trim()||!i.trim())){l(!0),d(null);try{let e=await E(`/api/maps/directions?from=${encodeURIComponent(n.trim())}&to=${encodeURIComponent(i.trim())}&mode=${o}`);e&&(d(e),e.error||(vE(n.trim(),i.trim()),p(yE())))}catch{d({url:`https://www.google.com/maps/dir/${encodeURIComponent(n.trim())}/${encodeURIComponent(i.trim())}/?travelmode=${o}`}),vE(n.trim(),i.trim()),p(yE())}l(!1)}},v=e=>{let t=`https://www.google.com/maps/search/${encodeURIComponent(e)}`;window.open(t,`_blank`)},y=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},b=e=>{r(e.from),a(e.to)},x=n.trim()&&i.trim()?`https://www.google.com/maps/dir/${encodeURIComponent(n.trim())}/${encodeURIComponent(i.trim())}/?travelmode=${o}`:null;return(0,k.jsxs)(`div`,{className:mE.root,children:[(0,k.jsx)(`div`,{className:mE.header,children:(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:mE.title,children:`🗺️ Maps & Directions`}),(0,k.jsx)(`div`,{className:mE.subtitle,children:e(`maps.directions`)})]})}),(0,k.jsxs)(`div`,{className:mE.section,children:[(0,k.jsx)(`div`,{className:mE.sectionTitle,children:e(`common.search`)}),(0,k.jsx)(`div`,{className:mE.quickBtns,children:_E.map(e=>(0,k.jsx)(`button`,{className:mE.quickBtn,onClick:()=>v(e.query),children:e.label},e.label))}),(0,k.jsxs)(`div`,{className:mE.searchRow,children:[(0,k.jsx)(`input`,{className:mE.searchInput,value:m,onChange:e=>h(e.target.value),placeholder:`Search for a place, address, or business…`,onKeyDown:e=>e.key===`Enter`&&v(m)}),(0,k.jsx)(`button`,{className:mE.searchBtn,onClick:()=>v(m),disabled:!m.trim(),children:`Search ↗`})]})]}),(0,k.jsxs)(`div`,{className:mE.section,children:[(0,k.jsx)(`div`,{className:mE.sectionTitle,children:`Directions`}),(0,k.jsx)(`div`,{className:mE.modeRow,children:hE.map(e=>(0,k.jsxs)(`button`,{className:`${mE.modeBtn} ${o===e?mE.modeActive:``}`,onClick:()=>s(e),title:e,children:[gE[e],` `,e.charAt(0).toUpperCase()+e.slice(1)]},e))}),(0,k.jsxs)(`div`,{className:mE.routeInputs,children:[(0,k.jsxs)(`div`,{className:mE.inputWrapper,children:[(0,k.jsx)(`span`,{className:mE.inputIcon,children:`A`}),(0,k.jsx)(`input`,{className:mE.routeInput,value:n,onChange:e=>r(e.target.value),placeholder:`From (address, city, or 'my location')`,onKeyDown:e=>e.key===`Enter`&&g()})]}),(0,k.jsx)(`button`,{className:mE.swapBtn,onClick:()=>{r(i),a(n)},title:`Swap`,children:`⇅`}),(0,k.jsxs)(`div`,{className:mE.inputWrapper,children:[(0,k.jsx)(`span`,{className:mE.inputIcon,children:`B`}),(0,k.jsx)(`input`,{className:mE.routeInput,value:i,onChange:e=>a(e.target.value),placeholder:`To (address, city, or landmark)`,onKeyDown:e=>e.key===`Enter`&&g()})]})]}),(0,k.jsxs)(`div`,{className:mE.dirBtns,children:[(0,k.jsx)(`button`,{className:mE.dirBtn,onClick:g,disabled:c||!n.trim()||!i.trim(),children:c?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:`spinner`}),` Getting route…`]}):`🗺️ Get Directions`}),x&&(0,k.jsx)(`a`,{className:mE.openMapsBtn,href:x,target:`_blank`,rel:`noreferrer`,children:`Open in Google Maps ↗`})]})]}),u?.error&&(0,k.jsx)(`div`,{className:mE.error,children:u.error}),u&&!u.error&&(0,k.jsxs)(`div`,{className:mE.resultCard,children:[(u.distance||u.duration)&&(0,k.jsxs)(`div`,{className:mE.routeSummary,children:[u.distance&&(0,k.jsxs)(`span`,{className:mE.routeDistance,children:[`📏 `,u.distance]}),u.duration&&(0,k.jsxs)(`span`,{className:mE.routeDuration,children:[`⏱ `,u.duration]}),(0,k.jsxs)(`span`,{className:mE.routeMode,children:[gE[o],` `,o]})]}),u.steps&&u.steps.length>0&&(0,k.jsx)(`div`,{className:mE.steps,children:u.steps.map((e,t)=>(0,k.jsxs)(`div`,{className:mE.step,children:[(0,k.jsx)(`span`,{className:mE.stepNum,children:t+1}),(0,k.jsx)(`span`,{className:mE.stepText,children:e})]},t))}),u.url&&(0,k.jsx)(`a`,{className:mE.mapLink,href:u.url,target:`_blank`,rel:`noreferrer`,children:`View full route on Google Maps ↗`}),(0,k.jsx)(`button`,{className:mE.askChatBtn,onClick:()=>y(`Give me directions from "${n}" to "${i}" by ${o}. Include estimated time, distance, and any traffic alerts or alternative routes.`),children:`Ask AI for detailed route advice →`})]}),f.length>0&&(0,k.jsxs)(`div`,{className:mE.section,children:[(0,k.jsx)(`div`,{className:mE.sectionTitle,children:`Recent Routes`}),f.map((e,t)=>(0,k.jsxs)(`div`,{className:mE.savedRoute,onClick:()=>b(e),children:[(0,k.jsx)(`span`,{className:mE.savedFrom,children:e.from}),(0,k.jsx)(`span`,{className:mE.savedArrow,children:`→`}),(0,k.jsx)(`span`,{className:mE.savedTo,children:e.to}),(0,k.jsx)(`span`,{className:mE.savedTs,children:new Date(e.ts).toLocaleDateString()})]},t))]})]})}var $={root:`_root_esnjz_1`,header:`_header_esnjz_3`,title:`_title_esnjz_4`,subtitle:`_subtitle_esnjz_5`,addBtn:`_addBtn_esnjz_6`,quickAdd:`_quickAdd_esnjz_8`,quickLabel:`_quickLabel_esnjz_9`,quickPresets:`_quickPresets_esnjz_10`,quickPreset:`_quickPreset_esnjz_10`,section:`_section_esnjz_14`,sectionTitle:`_sectionTitle_esnjz_15`,loading:`_loading_esnjz_17`,empty:`_empty_esnjz_18`,card:`_card_esnjz_20`,cardPast:`_cardPast_esnjz_21`,cardLeft:`_cardLeft_esnjz_22`,reminderMsg:`_reminderMsg_esnjz_23`,reminderTime:`_reminderTime_esnjz_24`,timeBadge:`_timeBadge_esnjz_25`,countdown:`_countdown_esnjz_26`,timePast:`_timePast_esnjz_27`,sentBadge:`_sentBadge_esnjz_28`,cancelledBadge:`_cancelledBadge_esnjz_29`,cancelBtn:`_cancelBtn_esnjz_30`,repeatBtn:`_repeatBtn_esnjz_31`,aiButtons:`_aiButtons_esnjz_33`,aiBtn:`_aiBtn_esnjz_34`,overlay:`_overlay_esnjz_38`,modal:`_modal_esnjz_39`,modalTitle:`_modalTitle_esnjz_40`,label:`_label_esnjz_41`,input:`_input_esnjz_42`,msgTemplates:`_msgTemplates_esnjz_44`,msgTemplate:`_msgTemplate_esnjz_44`,msgTemplateActive:`_msgTemplateActive_esnjz_47`,typeTabs:`_typeTabs_esnjz_49`,typeTab:`_typeTab_esnjz_49`,typeTabActive:`_typeTabActive_esnjz_51`,relRow:`_relRow_esnjz_53`,inLabel:`_inLabel_esnjz_54`,relInput:`_relInput_esnjz_55`,relSelect:`_relSelect_esnjz_56`,formErr:`_formErr_esnjz_58`,formOk:`_formOk_esnjz_59`,modalBtns:`_modalBtns_esnjz_60`,cancelModalBtn:`_cancelModalBtn_esnjz_61`,saveBtn:`_saveBtn_esnjz_62`},xE=[{label:`In 5 min`,value:`in 5 minutes`},{label:`In 15 min`,value:`in 15 minutes`},{label:`In 30 min`,value:`in 30 minutes`},{label:`In 1 hour`,value:`in 1 hour`},{label:`In 2 hours`,value:`in 2 hours`},{label:`In 3 hours`,value:`in 3 hours`},{label:`Tomorrow 9am`,value:`tomorrow at 09:00`},{label:`Tomorrow noon`,value:`tomorrow at 12:00`}],SE=[`Take a break and stretch`,`Check emails`,`Join the standup call`,`Review and respond to messages`,`Take your medication`,`Drink water`,`Focus review — what did you accomplish in the last hour?`,`Follow up on pending tasks`,`End of work day — log your achievements`,`Weekly review — prepare for next week`];function CE(e){if(e<1)return`now`;if(e<60)return`in ${e}m`;let t=Math.floor(e/60),n=e%60;return n>0?`in ${t}h ${n}m`:`in ${t}h`}function wE(){let e=j(),t=T(e=>e.setView),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)({message:``,atTime:``,atTimeType:`relative`,relValue:`30`,relUnit:`minutes`}),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(``),[m,h]=(0,_.useState)(!1),g=()=>{a(!0),E(`/api/reminders`).then(e=>{r(e?.reminders??[]),a(!1)}).catch(()=>{r([]),a(!1)})};(0,_.useEffect)(()=>{g()},[]);let v=async()=>{if(!o.message.trim()){d(`Message is required`);return}let e=``;if(o.atTimeType===`relative`)e=`in ${o.relValue} ${o.relUnit}`;else{if(!o.atTime){d(`Time is required`);return}e=o.atTime}l(!0),d(``);try{await D(`/api/reminders`,{message:o.message.trim(),atTime:e}),p(`Reminder set!`),setTimeout(()=>{p(``),h(!1)},1500),g()}catch(e){d(e.message??`Failed to set reminder`)}l(!1)},y=e=>{confirm(`Cancel this reminder?`)&&D(`/api/reminders/cancel`,{id:e}).then(g)},b=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},x=n.filter(e=>e.status===`pending`),S=n.filter(e=>e.status!==`pending`);return(0,k.jsxs)(`div`,{className:$.root,children:[(0,k.jsxs)(`div`,{className:$.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:$.title,children:`🔔 Reminders`}),(0,k.jsx)(`div`,{className:$.subtitle,children:`Set one-time notifications via the NHA daemon`})]}),(0,k.jsx)(`button`,{className:$.addBtn,onClick:()=>{h(!0),d(``),p(``)},children:`+ New Reminder`})]}),(0,k.jsxs)(`div`,{className:$.quickAdd,children:[(0,k.jsx)(`div`,{className:$.quickLabel,children:`Quick reminder for now:`}),(0,k.jsx)(`div`,{className:$.quickPresets,children:xE.map(e=>(0,k.jsx)(`button`,{className:$.quickPreset,onClick:()=>{s(e=>({...e,atTimeType:`relative`,atTime:``,message:e.message||`Reminder`})),h(!0),d(``),p(``)},children:e.label},e.value))})]}),i&&(0,k.jsxs)(`div`,{className:$.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}),!i&&(0,k.jsxs)(`div`,{className:$.section,children:[(0,k.jsxs)(`div`,{className:$.sectionTitle,children:[`Pending (`,x.length,`)`]}),x.length===0&&(0,k.jsx)(`div`,{className:$.empty,children:`No pending reminders. Set one to get notified.`}),x.map(e=>(0,k.jsxs)(`div`,{className:$.card,children:[(0,k.jsxs)(`div`,{className:$.cardLeft,children:[(0,k.jsx)(`div`,{className:$.reminderMsg,children:e.message}),(0,k.jsxs)(`div`,{className:$.reminderTime,children:[(0,k.jsx)(`span`,{className:$.timeBadge,children:new Date(e.atTime).toLocaleString()}),e.minutesUntil!==void 0&&(0,k.jsx)(`span`,{className:$.countdown,children:CE(e.minutesUntil)})]})]}),(0,k.jsx)(`button`,{className:$.cancelBtn,onClick:()=>y(e.id),children:`Cancel`})]},e.id))]}),S.length>0&&(0,k.jsxs)(`div`,{className:$.section,children:[(0,k.jsxs)(`div`,{className:$.sectionTitle,children:[`Recent (`,S.length,`)`]}),S.slice(0,10).map(e=>(0,k.jsxs)(`div`,{className:`${$.card} ${$.cardPast}`,children:[(0,k.jsxs)(`div`,{className:$.cardLeft,children:[(0,k.jsx)(`div`,{className:$.reminderMsg,children:e.message}),(0,k.jsxs)(`div`,{className:$.reminderTime,children:[(0,k.jsx)(`span`,{className:e.status===`sent`?$.sentBadge:$.cancelledBadge,children:e.status}),(0,k.jsx)(`span`,{className:$.timePast,children:new Date(e.atTime).toLocaleString()})]})]}),(0,k.jsx)(`button`,{className:$.repeatBtn,onClick:()=>{s(t=>({...t,message:e.message,atTimeType:`relative`,relValue:`30`,relUnit:`minutes`})),h(!0)},children:`Repeat`})]},e.id))]}),(0,k.jsxs)(`div`,{className:$.section,children:[(0,k.jsx)(`div`,{className:$.sectionTitle,children:`AI-Powered Reminders`}),(0,k.jsxs)(`div`,{className:$.aiButtons,children:[(0,k.jsx)(`button`,{className:$.aiBtn,onClick:()=>b(`Set a reminder to check my emails in 30 minutes`),children:`📧 Email check in 30min`}),(0,k.jsx)(`button`,{className:$.aiBtn,onClick:()=>b(`Set a reminder every hour to take a break and drink water`),children:`💧 Hourly water break`}),(0,k.jsx)(`button`,{className:$.aiBtn,onClick:()=>b(`Set a reminder at the end of the work day (6pm) to do an evening review of my tasks and prepare tomorrow's plan`),children:`🌆 Evening review 6pm`}),(0,k.jsx)(`button`,{className:$.aiBtn,onClick:()=>b(`Look at my calendar and set reminders for all events today`),children:`📅 Remind me of today's events`})]})]}),m&&(0,k.jsx)(`div`,{className:$.overlay,onClick:e=>{e.target===e.currentTarget&&h(!1)},children:(0,k.jsxs)(`div`,{className:$.modal,children:[(0,k.jsx)(`div`,{className:$.modalTitle,children:e(`reminders.new`)}),(0,k.jsx)(`div`,{className:$.label,children:`Message *`}),(0,k.jsx)(`div`,{className:$.msgTemplates,children:SE.map(e=>(0,k.jsx)(`button`,{className:`${$.msgTemplate} ${o.message===e?$.msgTemplateActive:``}`,onClick:()=>s(t=>({...t,message:e})),children:e},e))}),(0,k.jsx)(`input`,{className:$.input,value:o.message,onChange:e=>s(t=>({...t,message:e.target.value})),placeholder:`Reminder message (e.g. Call John)`}),(0,k.jsx)(`div`,{className:$.label,children:`When *`}),(0,k.jsxs)(`div`,{className:$.typeTabs,children:[(0,k.jsx)(`button`,{className:`${$.typeTab} ${o.atTimeType===`relative`?$.typeTabActive:``}`,onClick:()=>s(e=>({...e,atTimeType:`relative`})),children:`Relative`}),(0,k.jsx)(`button`,{className:`${$.typeTab} ${o.atTimeType===`absolute`?$.typeTabActive:``}`,onClick:()=>s(e=>({...e,atTimeType:`absolute`})),children:`Exact time`})]}),o.atTimeType===`relative`?(0,k.jsxs)(`div`,{className:$.relRow,children:[(0,k.jsx)(`span`,{className:$.inLabel,children:`in`}),(0,k.jsx)(`input`,{className:$.relInput,type:`number`,min:`1`,value:o.relValue,onChange:e=>s(t=>({...t,relValue:e.target.value}))}),(0,k.jsxs)(`select`,{className:$.relSelect,value:o.relUnit,onChange:e=>s(t=>({...t,relUnit:e.target.value})),children:[(0,k.jsx)(`option`,{value:`minutes`,children:`minutes`}),(0,k.jsx)(`option`,{value:`hours`,children:`hours`}),(0,k.jsx)(`option`,{value:`days`,children:`days`})]})]}):(0,k.jsx)(`input`,{className:$.input,type:`datetime-local`,value:o.atTime,onChange:e=>s(t=>({...t,atTime:e.target.value}))}),u&&(0,k.jsx)(`div`,{className:$.formErr,children:u}),f&&(0,k.jsx)(`div`,{className:$.formOk,children:f}),(0,k.jsxs)(`div`,{className:$.modalBtns,children:[(0,k.jsx)(`button`,{className:$.cancelModalBtn,onClick:()=>h(!1),children:`Cancel`}),(0,k.jsx)(`button`,{className:$.saveBtn,onClick:v,disabled:c,children:c?`Setting…`:`🔔 Set Reminder`})]})]})})]})}var TE={root:`_root_atgeb_1`,icon:`_icon_atgeb_10`,title:`_title_atgeb_11`,sub:`_sub_atgeb_12`},EE={dashboard:`⚡`,email:`📧`,calendar:`📅`,tasks:`✅`,contacts:`👤`,notes:`📝`,drive:`💾`,onedrive:`☁️`,mstodo:`📋`,github:`🐙`,slack:`💬`,notion:`📋`,collab:`🏛️`,maps:`🗺️`,cron:`⏰`,screen:`🖥️`,reminders:`🔔`,birthdays:`🎂`,settings:`⚙️`,agents:`🤖`,plan:`🗓️`,webcraft:`🔨`,connectors:`🔗`};function DE({view:e}){let t=j();return(0,k.jsxs)(`div`,{className:TE.root,children:[(0,k.jsx)(`div`,{className:TE.icon,children:EE[e]??`🔧`}),(0,k.jsx)(`div`,{className:TE.title,children:e.charAt(0).toUpperCase()+e.slice(1)}),(0,k.jsx)(`div`,{className:TE.sub,children:t(`common.comingSoon`)})]})}function OE({activeView:e}){switch(e){case`dashboard`:return(0,k.jsx)(wt,{});case`chat`:return(0,k.jsx)(Ee,{});case`email`:return(0,k.jsx)(Qt,{});case`calendar`:return(0,k.jsx)(nn,{});case`tasks`:return(0,k.jsx)(Et,{});case`notes`:return(0,k.jsx)(Lt,{});case`contacts`:return(0,k.jsx)(Bt,{});case`birthdays`:return(0,k.jsx)(jt,{});case`cron`:return(0,k.jsx)(Ft,{});case`connectors`:return(0,k.jsx)(qt,{});case`agents`:return(0,k.jsx)(sn,{});case`drive`:return(0,k.jsx)(un,{});case`onedrive`:return(0,k.jsx)(cE,{});case`mstodo`:return(0,k.jsx)(uE,{});case`github`:return(0,k.jsx)(fn,{});case`slack`:return(0,k.jsx)(mn,{});case`notion`:return(0,k.jsx)(hn,{});case`collab`:return(0,k.jsx)(yn,{});case`plan`:return(0,k.jsx)(oE,{});case`screen`:return(0,k.jsx)(pE,{});case`maps`:return(0,k.jsx)(bE,{});case`reminders`:return(0,k.jsx)(wE,{});case`settings`:return(0,k.jsx)(kt,{});default:return(0,k.jsx)(DE,{view:e})}}function kE(){let{activeView:e}=T();return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{style:{display:e===`studio`?`contents`:`none`},children:(0,k.jsx)(yt,{})}),(0,k.jsx)(`div`,{style:{display:e===`webcraft`?`contents`:`none`},children:(0,k.jsx)($T,{})}),e!==`studio`&&e!==`webcraft`&&(0,k.jsx)(OE,{activeView:e})]})}(0,v.createRoot)(document.getElementById(`root`)).render((0,k.jsx)(_.StrictMode,{children:(0,k.jsx)(me,{children:(0,k.jsx)(kE,{})})}));
@@ -8,7 +8,7 @@
8
8
  <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
9
9
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
10
10
  <title>NHA — NotHumanAllowed</title>
11
- <script type="module" crossorigin src="/assets/index-e_9WzUAL.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-DiRfvbLe.js"></script>
12
12
  <link rel="stylesheet" crossorigin href="/assets/index-DnJMrYkq.css">
13
13
  </head>
14
14
  <body>