tide-commander 1.130.0 → 1.131.0

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.
Files changed (39) hide show
  1. package/dist/assets/{BossLogsModal-B1BJZtYN.js → BossLogsModal-CWI0TeXV.js} +1 -1
  2. package/dist/assets/{BossSpawnModal-BWAc8Tl3.js → BossSpawnModal-CxiQJasU.js} +1 -1
  3. package/dist/assets/{ControlsModal-eWw5Rop8.js → ControlsModal-BrPnWWpS.js} +1 -1
  4. package/dist/assets/{DockerLogsModal-3KYmSZ0D.js → DockerLogsModal-D1oIAzfZ.js} +1 -1
  5. package/dist/assets/{EmbeddedEditor-D-Hr6SKR.js → EmbeddedEditor-CHP_HStx.js} +1 -1
  6. package/dist/assets/{GmailOAuthSetup-Bj0WdFre.js → GmailOAuthSetup-DCn-EXjO.js} +1 -1
  7. package/dist/assets/{GoogleOAuthSetup-CKDUM2jS.js → GoogleOAuthSetup-D26zofAR.js} +1 -1
  8. package/dist/assets/{IframeModal-g0eqDvHl.js → IframeModal-CSN8ck7s.js} +1 -1
  9. package/dist/assets/{IntegrationsPanel-Cb-oZ4wo.js → IntegrationsPanel-BU_xwMMT.js} +2 -2
  10. package/dist/assets/{LogViewerModal-BWj_qNc8.js → LogViewerModal-Amod9PlS.js} +1 -1
  11. package/dist/assets/{MonitoringModal-B92PBeU8.js → MonitoringModal-D-2zR9Oi.js} +1 -1
  12. package/dist/assets/{PM2LogsModal-CVf6pfMB.js → PM2LogsModal-B48puyEY.js} +1 -1
  13. package/dist/assets/{RestoreArchivedAreaModal-Cl8t248p.js → RestoreArchivedAreaModal-C4IVaTMA.js} +1 -1
  14. package/dist/assets/{Scene2DCanvas-CtJ-402V.js → Scene2DCanvas-BYdgkm1n.js} +1 -1
  15. package/dist/assets/{SceneManager-BJNnOvdL.js → SceneManager-DVL0xQVk.js} +1 -1
  16. package/dist/assets/{SkillsPanel-avhqZsVK.js → SkillsPanel-BwCe6nFB.js} +1 -1
  17. package/dist/assets/{SlackMultiInstanceSetup-CUkW8jup.js → SlackMultiInstanceSetup-nSiRoxLD.js} +1 -1
  18. package/dist/assets/{SpawnModal-CTflBJPO.js → SpawnModal-DXvcL-cq.js} +1 -1
  19. package/dist/assets/{StatisticsModal-Cvg4hAz9.js → StatisticsModal-Dgq-n8L6.js} +1 -1
  20. package/dist/assets/{SubordinateAssignmentModal-CMTYlIWY.js → SubordinateAssignmentModal-DflOgTr1.js} +1 -1
  21. package/dist/assets/{TriggerManagerPanel-BEHEyek4.js → TriggerManagerPanel-wzVna9Th.js} +1 -1
  22. package/dist/assets/{WorkflowEditorPanel-Dmi1MoCF.js → WorkflowEditorPanel-Cv1Bb_0g.js} +1 -1
  23. package/dist/assets/{area-logos-BJJ6AZC2.js → area-logos-6NdoVnoc.js} +1 -1
  24. package/dist/assets/{index-B5iEYrCd.js → index-1_kNHqvQ.js} +1 -1
  25. package/dist/assets/{index-Ch9qOEPa.js → index-Bsf5hZbp.js} +1 -1
  26. package/dist/assets/{index-D9i6rhAe.js → index-CoGlYrB7.js} +1 -1
  27. package/dist/assets/{index-Bd5vzbeG.js → index-CqwyKXtm.js} +1 -1
  28. package/dist/assets/{index-UFc3Wfyr.js → index-D8cfBFRC.js} +1 -1
  29. package/dist/assets/{index-C3WlgIxN.js → index-DZcn4bXn.js} +1 -1
  30. package/dist/assets/{index-BZg6OccM.js → index-SaaO8V1I.js} +2 -2
  31. package/dist/assets/{index-D6E2F5UW.js → index-Tn-mXnAH.js} +1 -1
  32. package/dist/assets/{index-D0khiFSO.js → index-sLCEQwTe.js} +3 -3
  33. package/dist/assets/{main-Bi5x2SM0.css → main-BPim_cvM.css} +1 -1
  34. package/dist/assets/{main-D6Q3mJMF.js → main-DffU4pm2.js} +61 -61
  35. package/dist/assets/{web-BxA0OEx8.js → web-BzTFbp-p.js} +1 -1
  36. package/dist/assets/{web-CybtmV4V.js → web-CNVP9dOO.js} +1 -1
  37. package/dist/assets/{web-B6cscrTU.js → web-SdWeOa6A.js} +1 -1
  38. package/dist/index.html +2 -2
  39. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import{r as l,b4 as Ue,b5 as Je,j as e,I as $,u as X,b6 as ns,ab as is,f as Ke,s as _,b7 as ms,b8 as gs,aZ as fs,b9 as xs,C as he,G as se,H as Y,h as je,i as ke,m as bs,ba as js,bb as ws,bc as ys,bd as vs,P as Ns,be as Se,a6 as ks,bf as os,bg as Ss,bh as Ve,bi as Cs,bj as As,bk as Ts,bl as _s,bm as Is,bn as Es,bo as Ps,aT as Ls,W as $s,S as Ne,bp as Ds,bq as Os,aV as Fs,br as ze,X as Ee,b1 as Rs,bs as Me,bt as Us}from"./main-D6Q3mJMF.js";import{g as zs,d as Ms,u as Bs}from"./area-logos-BJJ6AZC2.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const He="deivid11/tide-commander",Vs=`https://api.github.com/repos/${He}/releases/latest`,Ks=`https://api.github.com/repos/${He}/releases?per_page=3`,Hs=3600*1e3,Ze="app_update_dismissed_version",Xe="1.130.0";function Ws(){var N,S;const[s,a]=l.useState({isChecking:!1,updateAvailable:!1,updateInfo:null,recentReleases:[],error:null,currentVersion:Xe}),t=((S=(N=Ue)==null?void 0:N.getPlatform)==null?void 0:S.call(N))==="android"||!1,o=u=>u.replace(/^v/,"").split(".").map(m=>parseInt(m,10)||0),d=(u,p)=>{const m=o(u),j=o(p),b=Math.max(m.length,j.length);for(let h=0;h<b;h++){const y=m[h]||0,P=j[h]||0;if(y>P)return 1;if(y<P)return-1}return 0},r=async u=>{var m,j;if(Ue&&Je&&((j=(m=Ue).isNativePlatform)==null?void 0:j.call(m))===!0){const b=await Je.get({url:u,headers:{Accept:"application/vnd.github.v3+json"}});return{data:b.data,status:b.status}}else{const b=await fetch(u,{headers:{Accept:"application/vnd.github.v3+json"}});return b.ok?{data:await b.json(),status:b.status}:{data:null,status:b.status}}},c=l.useCallback(async(u=!1)=>{a(p=>({...p,isChecking:!0,error:null}));try{const[p,m]=await Promise.all([r(Vs),r(Ks)]);if(p.status!==200)throw new Error(`GitHub API error: ${p.status}`);const j=p.data,b=j.tag_name;let h=[];m.status===200&&m.data&&(h=m.data.map(w=>({version:w.tag_name,name:w.name,publishedAt:w.published_at,releaseUrl:w.html_url})));const y=localStorage.getItem(Ze);if(!u&&y===b)return a(w=>({...w,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;if(!(d(b,Xe)>0))return a(w=>({...w,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;const I=j.assets.find(w=>w.name.endsWith(".apk")&&w.content_type==="application/vnd.android.package-archive"),H={version:b,name:j.name,changelog:j.body,releaseUrl:j.html_url,apkUrl:(I==null?void 0:I.browser_download_url)||null,apkSize:(I==null?void 0:I.size)||null,publishedAt:j.published_at};return a(w=>({...w,isChecking:!1,updateAvailable:!0,updateInfo:H,recentReleases:h})),H}catch(p){const m=p instanceof Error?p.message:"Failed to check for updates";return a(j=>({...j,isChecking:!1,error:m})),null}},[]),x=l.useCallback(async()=>{var u,p,m;if(!((u=s.updateInfo)!=null&&u.apkUrl)){(p=s.updateInfo)!=null&&p.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}if(!t){(m=s.updateInfo)!=null&&m.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}try{window.open(s.updateInfo.apkUrl,"_system"),a(j=>({...j,error:null}))}catch(j){const b=j instanceof Error?j.message:"Failed to open download";a(h=>({...h,error:b}))}},[s.updateInfo,t]),n=l.useCallback(()=>{s.updateInfo&&localStorage.setItem(Ze,s.updateInfo.version),a(u=>({...u,updateAvailable:!1,updateInfo:null}))},[s.updateInfo]),g=l.useCallback(()=>{var u;(u=s.updateInfo)!=null&&u.releaseUrl?window.open(s.updateInfo.releaseUrl,"_blank"):window.open(`https://github.com/${He}/releases`,"_blank")},[s.updateInfo]);return l.useEffect(()=>{if(!t)return;const u=setTimeout(()=>{c()},5e3),p=setInterval(()=>{c()},Hs);return()=>{clearTimeout(u),clearInterval(p)}},[t,c]),{...s,isAndroid:t,checkForUpdate:c,downloadAndInstall:x,dismissUpdate:n,openReleasePage:g}}const ls="tide-toolbox-collapse";function qs(s,a){try{const t=localStorage.getItem(`${ls}-${s}`);if(t!==null)return t==="true"}catch{}return a}function Gs(s,a){try{localStorage.setItem(`${ls}-${s}`,String(a))}catch{}}function G({title:s,storageKey:a,defaultOpen:t=!1,forceOpen:o=!1,children:d,headerExtra:r}){const[c,x]=l.useState(()=>a?qs(a,t):t),n=()=>{const N=!c;x(N),a&&Gs(a,N)},g=o||c;return e.jsxs("div",{className:`collapsible-section ${g?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:n,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[r,e.jsx("span",{className:"collapsible-arrow",children:e.jsx($,{name:g?"caret-down":"caret-right",size:10})})]})]}),g&&e.jsx("div",{className:"collapsible-content",children:d})]})}function Ys({area:s,isSelected:a,onClick:t,onDelete:o}){const{t:d}=X(["config","common"]),r=s.assignedAgentIds.length,c=s.type==="rectangle"?d("config:areas.rect"):d("config:areas.circle");return e.jsxs("div",{className:`area-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"area-color-dot",style:{backgroundColor:s.color}}),e.jsxs("div",{className:"area-info",children:[e.jsx("div",{className:"area-name",children:s.name}),e.jsxs("div",{className:"area-meta",children:[c," ",r>0&&`• ${r} ${r>1?d("common:labels.agents").toLowerCase():d("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:o,title:d("config:areas.deleteArea"),children:"×"})]})}function Js({building:s,isSelected:a,onClick:t,onEdit:o}){var x;const{t:d}=X(["config"]),r=((x=s.pm2Status)==null?void 0:x.ports)||[],c=(n,g)=>{n.stopPropagation(),window.open(`http://${window.location.hostname}:${g}`,"_blank")};return e.jsxs("div",{className:`building-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:ns[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx($,{name:is(s.type),size:16})}),e.jsxs("div",{className:"building-info",children:[e.jsx("div",{className:"building-name",children:s.name}),e.jsxs("div",{className:"building-meta",children:[s.type,r.length>0&&e.jsx("span",{className:"building-ports",children:r.map(n=>e.jsxs("a",{href:`http://${window.location.hostname}:${n}`,className:"building-port-link",onClick:g=>c(g,n),title:`Open :${n}`,children:[":",n]},n))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:n=>{n.stopPropagation(),o()},title:d("config:buildings.editBuilding"),children:e.jsx($,{name:"gear",size:14})})]})}function Zs({building:s,onClose:a,onOpenModal:t}){var g,N,S,u,p,m,j,b;const{t:o}=X(["config","common"]),{buildingLogs:d}=Ke(),r=_.getBuildingLogs(s.id),c=ms[s.style||"server-rack"],x=h=>{_.sendBuildingCommand(s.id,h)},n=h=>{window.open(h,"_blank")};return e.jsxs("div",{className:"building-editor",children:[e.jsxs("div",{className:"building-editor-header",children:[e.jsxs("div",{className:"building-editor-title-row",children:[e.jsx("span",{className:"building-editor-icon",children:e.jsx($,{name:is(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:ns[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:a,children:"×"})]}),e.jsx("div",{className:"building-editor-section",children:e.jsxs("div",{className:"building-editor-info-grid",children:[e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("common:labels.type")}),e.jsx("span",{className:"building-editor-info-value",children:s.type})]}),e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.style")}),e.jsx("span",{className:"building-editor-info-value",children:c.label})]}),s.cwd&&e.jsxs("div",{className:"building-editor-info-item building-editor-info-wide",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.directory")}),e.jsx("span",{className:"building-editor-info-value building-editor-cwd",title:s.cwd,children:s.cwd.split("/").pop()||s.cwd})]})]})}),s.type==="server"&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.actions")}),e.jsxs("div",{className:"building-editor-actions",children:[e.jsxs("button",{className:"building-editor-action-btn start",onClick:()=>x("start"),disabled:!((g=s.commands)!=null&&g.start)||s.status==="running",title:((N=s.commands)==null?void 0:N.start)||o("config:buildings.noStartCommand"),children:[e.jsx($,{name:"play",size:12})," ",o("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>x("stop"),disabled:!((S=s.commands)!=null&&S.stop)||s.status==="stopped",title:((u=s.commands)==null?void 0:u.stop)||o("config:buildings.noStopCommand"),children:[e.jsx($,{name:"stop",size:12,weight:"fill"})," ",o("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>x("restart"),disabled:!((p=s.commands)!=null&&p.restart),title:((m=s.commands)==null?void 0:m.restart)||o("config:buildings.noRestartCommand"),children:[e.jsx($,{name:"refresh",size:12})," ",o("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>x("healthCheck"),disabled:!((j=s.commands)!=null&&j.healthCheck),title:((b=s.commands)==null?void 0:b.healthCheck)||o("config:buildings.noHealthCheck"),children:[e.jsx($,{name:"heart",size:12})," Health"]})]})]}),s.urls&&s.urls.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.links")}),e.jsx("div",{className:"building-editor-links",children:s.urls.map((h,y)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>n(h.url),title:h.url,children:[e.jsx($,{name:"link",size:12})," ",h.label||h.url]},y))})]}),r.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsxs("div",{className:"building-editor-section-title",children:[o("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>_.clearBuildingLogs(s.id),title:o("common:buttons.clear"),children:o("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:r.slice(-5).map((h,y)=>e.jsx("div",{className:"building-editor-log-entry",children:h},y))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx($,{name:"gear",size:12})," ",o("config:buildings.fullSettings")]})})]})}const Xs=[{key:"center",labelKey:"posCenter"},{key:"top-left",labelKey:"posTopLeft"},{key:"top-right",labelKey:"posTopRight"},{key:"bottom-left",labelKey:"posBottomLeft"},{key:"bottom-right",labelKey:"posBottomRight"}];function Qs({area:s,onClose:a,onOpenFolder:t}){var te;const{t:o}=X(["config","common"]),[d,r]=l.useState(s.name),[c,x]=l.useState(s.prompt||""),[n,g]=l.useState(!1),[N,S]=l.useState(""),[u,p]=l.useState(!1),m=l.useRef(null);l.useEffect(()=>{r(s.name)},[s.id,s.name]),l.useEffect(()=>{x(s.prompt||"")},[s.id,s.prompt]);const j=k=>{const O=k.target.value;r(O),_.updateArea(s.id,{name:O})},b=k=>{_.updateArea(s.id,{color:k})},h=k=>{const O=k.target.value;x(O),_.updateArea(s.id,{prompt:O})},y=()=>{N.trim()&&(_.addDirectoryToArea(s.id,N.trim()),S(""),g(!1))},P=(k,O)=>{O.stopPropagation(),_.removeDirectoryFromArea(s.id,k)},I=()=>{_.bringAreaToFront(s.id)},H=()=>{_.sendAreaToBack(s.id)},w=l.useCallback(()=>{let k=2,O=2;s.type==="rectangle"&&s.width&&s.height?(k=s.width,O=s.height):s.type==="circle"&&s.radius&&(k=s.radius*1.414,O=s.radius*1.414);const V=Math.min(k,O)*.4;return{width:Math.round(V*10)/10,height:Math.round(V*10)/10}},[s.type,s.width,s.height,s.radius]),z=async k=>{var V;const O=(V=k.target.files)==null?void 0:V[0];if(O){p(!0);try{const v=await Bs(s.id,O),D=w();_.updateArea(s.id,{logo:{filename:v.filename,position:"center",width:D.width,height:D.height,keepAspectRatio:!0,opacity:.8}})}catch(v){console.error("Failed to upload logo:",v)}finally{p(!1),m.current&&(m.current.value="")}}},B=async()=>{try{await Ms(s.id),_.updateArea(s.id,{logo:void 0})}catch(k){console.error("Failed to remove logo:",k)}},q=k=>{s.logo&&_.updateArea(s.id,{logo:{...s.logo,position:k}})},C=k=>{if(!s.logo)return;const O=parseFloat(k.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const V=s.logo.height/s.logo.width;_.updateArea(s.id,{logo:{...s.logo,width:O,height:Math.round(O*V*10)/10}})}else _.updateArea(s.id,{logo:{...s.logo,width:O}})},R=k=>{if(!s.logo)return;const O=parseFloat(k.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const V=s.logo.width/s.logo.height;_.updateArea(s.id,{logo:{...s.logo,height:O,width:Math.round(O*V*10)/10}})}else _.updateArea(s.id,{logo:{...s.logo,height:O}})},K=()=>{s.logo&&_.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},W=k=>{s.logo&&_.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(k.target.value)}})};return e.jsxs("div",{className:"area-editor",children:[e.jsxs("div",{className:"area-editor-header",children:[e.jsx("span",{className:"area-editor-title",children:o("config:areas.editArea")}),e.jsx("button",{className:"area-editor-close",onClick:a,children:"×"})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:d,onChange:j,placeholder:o("config:areas.areaName")})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.color")}),e.jsx("div",{className:"color-picker-row",children:gs.map(k=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===k?"selected":""}`,style:{backgroundColor:k},onClick:()=>b(k),"aria-label":`Set area color ${k}`,"aria-pressed":s.color===k,title:k},k))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:I,title:o("config:areas.bringToFront"),children:[e.jsx($,{name:"arrow-up",size:12})," ",o("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:H,title:o("config:areas.sendToBack"),children:[e.jsx($,{name:"arrow-down",size:12})," ",o("config:areas.back")]})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.logo")}),e.jsxs("div",{className:"area-logo-section",children:[(te=s.logo)!=null&&te.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:zs(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:B,children:o("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var k;return(k=m.current)==null?void 0:k.click()},disabled:u,children:u?"...":e.jsx($,{name:"refresh",size:12})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:Xs.map(({key:k,labelKey:O})=>{var V;return e.jsx("button",{className:`area-logo-pos-btn ${((V=s.logo)==null?void 0:V.position)===k?"active":""}`,onClick:()=>q(k),children:o(`config:areas.${O}`)},k)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoSize")}),e.jsxs("div",{className:"area-logo-size-row",children:[e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:C,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoHeight")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.height,onChange:R,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-aspect-label",title:o("config:areas.keepAspectRatio"),children:[e.jsx("input",{type:"checkbox",checked:s.logo.keepAspectRatio,onChange:K}),o("config:areas.keepAspectRatio")]})]})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoOpacity")}),e.jsxs("div",{className:"area-logo-opacity-row",children:[e.jsx("input",{type:"range",min:0,max:1,step:.05,value:s.logo.opacity??.8,onChange:W,className:"area-logo-opacity-slider"}),e.jsxs("span",{className:"area-logo-opacity-value",children:[Math.round((s.logo.opacity??.8)*100),"%"]})]})]})]}):e.jsx("button",{className:"area-logo-upload-btn",onClick:()=>{var k;return(k=m.current)==null?void 0:k.click()},disabled:u,children:u?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:m,type:"file",accept:"image/*",style:{display:"none"},onChange:z})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(k=>e.jsxs("div",{className:"area-folder-item",title:k,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:o("config:areas.openFolder"),children:e.jsx($,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:k.split("/").pop()||k}),e.jsx("button",{className:"area-folder-remove",onClick:O=>P(k,O),title:o("config:areas.removeFolder"),children:"×"})]},k)),n?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(fs,{value:N,onChange:S,onSubmit:y,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:y,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>g(!0),children:o("config:areas.addFolder")})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.prompt","Prompt")}),e.jsx("textarea",{className:"area-editor-input",value:c,onChange:h,placeholder:o("config:areas.promptPlaceholder","System prompt for agents in this area..."),rows:4,style:{resize:"vertical",fontFamily:"monospace",fontSize:12}}),e.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:4},children:o("config:areas.promptHint","This prompt is injected into agents assigned to this area. Takes effect on next context refresh.")})]}),s.assignedAgentIds.length>0&&e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:o("config:areas.rightClickUnassign")})]})]})}function et(){const{t:s}=X(["config","common"]),a=xs(),[t,o]=l.useState(!1),[d,r]=l.useState(null),[c,x]=l.useState({name:"",key:"",value:"",description:""}),[n,g]=l.useState(null),N=()=>{o(!0),r(null),x({name:"",key:"",value:"",description:""})},S=h=>{r(h.id),o(!1),x({name:h.name,key:h.key,value:h.value,description:h.description||""})},u=()=>{o(!1),r(null),x({name:"",key:"",value:"",description:""})},p=()=>{!c.name.trim()||!c.key.trim()||(d?_.updateSecret(d,{name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}):_.createSecret({name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}),u())},m=h=>{g(h)},j=()=>{n&&(_.deleteSecret(n),d===n&&u())},b=h=>{navigator.clipboard.writeText(`{{${h}}}`)};return e.jsxs("div",{className:"secrets-section",children:[e.jsx("div",{className:"secrets-description",children:s("config:secrets.description",{placeholder:"{{KEY}}"})}),e.jsx("div",{className:"secrets-list",children:a.length===0&&!t?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):a.map(h=>e.jsxs("div",{className:`secret-item ${d===h.id?"editing":""}`,children:[e.jsxs("div",{className:"secret-item-header",children:[e.jsxs("div",{className:"secret-item-info",children:[e.jsx("span",{className:"secret-item-name",children:h.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>b(h.key),title:s("config:secrets.copyPlaceholder"),children:`{{${h.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>S(h),title:s("common:buttons.edit"),children:e.jsx($,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>m(h.id),title:s("common:buttons.delete"),children:"×"})]})]}),h.description&&e.jsx("div",{className:"secret-item-description",children:h.description})]},h.id))}),(t||d)&&e.jsxs("div",{className:"secret-form",children:[e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.name")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.namePlaceholder"),value:c.name,onChange:h=>x({...c,name:h.target.value}),autoFocus:!0})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:"Key"}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.keyPlaceholder"),value:c.key,onChange:h=>x({...c,key:h.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${c.key||"KEY"}}}`})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("config:secrets.secretValue")}),e.jsx("input",{type:"password",className:"secret-form-input",placeholder:s("config:secrets.valuePlaceholder"),value:c.value,onChange:h=>x({...c,value:h.target.value})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.description")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.descriptionPlaceholder"),value:c.description,onChange:h=>x({...c,description:h.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:u,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:p,disabled:!c.name.trim()||!c.key.trim(),children:s(d?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!d&&e.jsx("button",{className:"secrets-add-btn",onClick:N,children:s("config:secrets.addSecret")}),e.jsx(he,{isOpen:n!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:j,onClose:()=>g(null)})]})}async function st(){const s=se(),a=await fetch(`${Y()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch system prompt: ${a.statusText}`);return(await a.json()).prompt||""}async function tt(s){const a=se(),t=await fetch(`${Y()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({prompt:s})});if(!t.ok)throw new Error(`Failed to update system prompt: ${t.statusText}`)}async function at(){const s=se(),a=await fetch(`${Y()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to clear system prompt: ${a.statusText}`)}async function nt(){const s=se(),a=await fetch(`${Y()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch echo prompt setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function it(s){const a=se(),t=await fetch(`${Y()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function ot(){const s=se(),a=await fetch(`${Y()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch codex binary path: ${a.statusText}`);return(await a.json()).path||""}async function lt(s){const a=se(),t=await fetch(`${Y()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function ct(){const s=se(),a=await fetch(`${Y()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch tmux mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function rt(s){const a=se(),t=await fetch(`${Y()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function dt(){const s=se(),a=await fetch(`${Y()}/api/agents/system-settings/interactive-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch interactive mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function ut(s){const a=se(),t=await fetch(`${Y()}/api/agents/system-settings/interactive-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update interactive mode setting: ${t.statusText}`)}async function pt(){const s=se(),a=await fetch(`${Y()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch backup status: ${a.statusText}`);return a.json()}async function ht(s){const a=se(),t=await fetch(`${Y()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok){const o=await t.json().catch(()=>({}));throw new Error(o.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function mt({checked:s,onChange:a,disabled:t}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:t,onChange:o=>a(o.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function gt(){const{t:s}=X(["config","common"]),[a,t]=l.useState([]),[o,d]=l.useState(new Set),[r,c]=l.useState(new Set),[x,n]=l.useState(!1),[g,N]=l.useState(!1),[S,u]=l.useState(null),[p,m]=l.useState(null),[j,b]=l.useState(null),[h,y]=l.useState(null),[P,I]=l.useState(!1),[H,w]=l.useState(null);l.useEffect(()=>{je(ke("/api/config/categories")).then(v=>v.json()).then(v=>{const D=Array.isArray(v)?v:[];t(D),d(new Set(D.map(F=>F.id)))}).catch(v=>console.error("Failed to fetch config categories:",v))},[]),l.useEffect(()=>{pt().then(y).catch(v=>{console.error("Failed to fetch backup status:",v),w(v.message||"Failed to fetch backup status")})},[]);const z=async v=>{if(!P){I(!0),w(null);try{const D=await ht(v);y(D)}catch(D){w(D.message||"Failed to update backup setting")}finally{I(!1)}}},B=v=>{d(D=>{const F=new Set(D);return F.has(v)?F.delete(v):F.add(v),F})},q=v=>{c(D=>{const F=new Set(D);return F.has(v)?F.delete(v):F.add(v),F})},C=()=>d(new Set(a.map(v=>v.id))),R=()=>d(new Set),K=()=>{p&&c(new Set(p.categories.map(v=>v.id)))},W=()=>c(new Set),te=async()=>{var v;if(o.size!==0){n(!0),b(null);try{const D=Array.from(o).join(","),F=await je(ke(`/api/config/export?categories=${D}`));if(!F.ok)throw new Error("Export failed");const Q=await F.blob(),ee=window.URL.createObjectURL(Q),T=document.createElement("a");T.href=ee;const A=F.headers.get("Content-Disposition"),J=((v=A==null?void 0:A.match(/filename="(.+)"/))==null?void 0:v[1])||"tide-commander-config.zip";T.download=J,document.body.appendChild(T),T.click(),document.body.removeChild(T),window.URL.revokeObjectURL(ee),b({type:"success",text:s("config:data.exportSuccess")})}catch(D){b({type:"error",text:D.message||"Export failed"})}finally{n(!1)}}},k=async v=>{var F;const D=(F=v.target.files)==null?void 0:F[0];if(D){u(D),b(null),m(null),c(new Set);try{const Q=await je(ke("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await D.arrayBuffer()});if(!Q.ok){const A=await Q.json();throw new Error(A.error||"Failed to preview config file")}const ee=await Q.json(),T=Array.isArray(ee.categories)?ee.categories:[];m({...ee,categories:T}),c(new Set(T.map(A=>A.id)))}catch(Q){b({type:"error",text:Q.message||"Failed to read config file"}),u(null)}}},O=async()=>{if(!(!S||r.size===0)){N(!0),b(null);try{const v=Array.from(r).join(","),D=await je(ke(`/api/config/import?categories=${v}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await S.arrayBuffer()}),F=await D.json();if(!D.ok)throw new Error(F.error||"Import failed");b({type:"success",text:F.message||s("config:data.importSuccess")}),u(null),m(null),c(new Set)}catch(v){b({type:"error",text:v.message||"Import failed"})}finally{N(!1)}}},V=()=>{u(null),m(null),c(new Set),b(null)};return e.jsxs("div",{className:"data-section",children:[j&&e.jsx("div",{className:`data-message data-message-${j.type}`,children:j.text}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:"Hourly Backups"}),e.jsx(mt,{checked:!!(h!=null&&h.enabled),disabled:P||!h,onChange:z})]}),e.jsxs("div",{className:"data-backup-info",children:[h?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:h.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!h.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:h.scriptPath})]}),h.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(h.lastRunAt).toLocaleString(),h.lastRunOk===!0&&" — ok",h.lastRunOk===!1&&h.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",h.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),H&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:H})]})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:s("config:data.exportData")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:C,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:R,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:a.map(v=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(v.id),onChange:()=>B(v.id)}),e.jsx("span",{className:"data-category-name",children:v.name})]},v.id))}),e.jsx("button",{className:"data-action-btn export",onClick:te,disabled:x||o.size===0,children:x?s("config:data.exporting"):s("config:data.exportCount",{count:o.size})})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsx("div",{className:"data-subsection-header",children:e.jsx("span",{className:"data-subsection-title",children:s("config:data.importData")})}),S?p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:S.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(p.exportedAt).toLocaleDateString()]})]}),e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-subtitle",children:s("config:data.selectToImport")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:K,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:W,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:p.categories.map(v=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:r.has(v.id),onChange:()=>q(v.id)}),e.jsx("span",{className:"data-category-name",children:v.name}),v.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",v.fileCount," ",s("config:data.files"),")"]})]},v.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:V,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:O,disabled:g||r.size===0,children:g?s("config:data.importing"):s("config:data.importCount",{count:r.size})})]})]}):e.jsx("div",{className:"data-loading",children:s("config:data.readingFile")}):e.jsxs("label",{className:"data-file-input",children:[e.jsx("input",{type:"file",accept:".zip",onChange:k,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}async function ft(){const s=await je(`${Y()}/api/system/install-info`);if(!s.ok)throw new Error(`Failed to fetch install info: ${s.statusText}`);return s.json()}function xt(s,a){const t=new AbortController;return(async()=>{try{const o=await fetch(bs(`${Y()}/api/system/self-update`),{method:"POST",signal:t.signal,headers:{Accept:"text/event-stream"}});if(!o.ok||!o.body){const x=await o.text().catch(()=>"");let n=null;try{n=JSON.parse(x)}catch{}const g=n&&typeof n=="object"&&"error"in n&&typeof n.error=="string"?n.error:`Self-update failed: ${o.status} ${o.statusText}`;s({type:"error",message:g}),a(new Error(g));return}const d=o.body.getReader(),r=new TextDecoder("utf-8");let c="";for(;;){const{value:x,done:n}=await d.read();if(n)break;c+=r.decode(x,{stream:!0});let g=c.indexOf(`
1
+ import{r as l,b4 as Ue,b5 as Je,j as e,I as $,u as X,b6 as ns,ab as is,f as Ke,s as _,b7 as ms,b8 as gs,aZ as fs,b9 as xs,C as he,G as se,H as Y,h as je,i as ke,m as bs,ba as js,bb as ws,bc as ys,bd as vs,P as Ns,be as Se,a6 as ks,bf as os,bg as Ss,bh as Ve,bi as Cs,bj as As,bk as Ts,bl as _s,bm as Is,bn as Es,bo as Ps,aT as Ls,W as $s,S as Ne,bp as Ds,bq as Os,aV as Fs,br as ze,X as Ee,b1 as Rs,bs as Me,bt as Us}from"./main-DffU4pm2.js";import{g as zs,d as Ms,u as Bs}from"./area-logos-6NdoVnoc.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const He="deivid11/tide-commander",Vs=`https://api.github.com/repos/${He}/releases/latest`,Ks=`https://api.github.com/repos/${He}/releases?per_page=3`,Hs=3600*1e3,Ze="app_update_dismissed_version",Xe="1.131.0";function Ws(){var N,S;const[s,a]=l.useState({isChecking:!1,updateAvailable:!1,updateInfo:null,recentReleases:[],error:null,currentVersion:Xe}),t=((S=(N=Ue)==null?void 0:N.getPlatform)==null?void 0:S.call(N))==="android"||!1,o=u=>u.replace(/^v/,"").split(".").map(m=>parseInt(m,10)||0),d=(u,p)=>{const m=o(u),j=o(p),b=Math.max(m.length,j.length);for(let h=0;h<b;h++){const y=m[h]||0,P=j[h]||0;if(y>P)return 1;if(y<P)return-1}return 0},r=async u=>{var m,j;if(Ue&&Je&&((j=(m=Ue).isNativePlatform)==null?void 0:j.call(m))===!0){const b=await Je.get({url:u,headers:{Accept:"application/vnd.github.v3+json"}});return{data:b.data,status:b.status}}else{const b=await fetch(u,{headers:{Accept:"application/vnd.github.v3+json"}});return b.ok?{data:await b.json(),status:b.status}:{data:null,status:b.status}}},c=l.useCallback(async(u=!1)=>{a(p=>({...p,isChecking:!0,error:null}));try{const[p,m]=await Promise.all([r(Vs),r(Ks)]);if(p.status!==200)throw new Error(`GitHub API error: ${p.status}`);const j=p.data,b=j.tag_name;let h=[];m.status===200&&m.data&&(h=m.data.map(w=>({version:w.tag_name,name:w.name,publishedAt:w.published_at,releaseUrl:w.html_url})));const y=localStorage.getItem(Ze);if(!u&&y===b)return a(w=>({...w,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;if(!(d(b,Xe)>0))return a(w=>({...w,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;const I=j.assets.find(w=>w.name.endsWith(".apk")&&w.content_type==="application/vnd.android.package-archive"),H={version:b,name:j.name,changelog:j.body,releaseUrl:j.html_url,apkUrl:(I==null?void 0:I.browser_download_url)||null,apkSize:(I==null?void 0:I.size)||null,publishedAt:j.published_at};return a(w=>({...w,isChecking:!1,updateAvailable:!0,updateInfo:H,recentReleases:h})),H}catch(p){const m=p instanceof Error?p.message:"Failed to check for updates";return a(j=>({...j,isChecking:!1,error:m})),null}},[]),x=l.useCallback(async()=>{var u,p,m;if(!((u=s.updateInfo)!=null&&u.apkUrl)){(p=s.updateInfo)!=null&&p.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}if(!t){(m=s.updateInfo)!=null&&m.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}try{window.open(s.updateInfo.apkUrl,"_system"),a(j=>({...j,error:null}))}catch(j){const b=j instanceof Error?j.message:"Failed to open download";a(h=>({...h,error:b}))}},[s.updateInfo,t]),n=l.useCallback(()=>{s.updateInfo&&localStorage.setItem(Ze,s.updateInfo.version),a(u=>({...u,updateAvailable:!1,updateInfo:null}))},[s.updateInfo]),g=l.useCallback(()=>{var u;(u=s.updateInfo)!=null&&u.releaseUrl?window.open(s.updateInfo.releaseUrl,"_blank"):window.open(`https://github.com/${He}/releases`,"_blank")},[s.updateInfo]);return l.useEffect(()=>{if(!t)return;const u=setTimeout(()=>{c()},5e3),p=setInterval(()=>{c()},Hs);return()=>{clearTimeout(u),clearInterval(p)}},[t,c]),{...s,isAndroid:t,checkForUpdate:c,downloadAndInstall:x,dismissUpdate:n,openReleasePage:g}}const ls="tide-toolbox-collapse";function qs(s,a){try{const t=localStorage.getItem(`${ls}-${s}`);if(t!==null)return t==="true"}catch{}return a}function Gs(s,a){try{localStorage.setItem(`${ls}-${s}`,String(a))}catch{}}function G({title:s,storageKey:a,defaultOpen:t=!1,forceOpen:o=!1,children:d,headerExtra:r}){const[c,x]=l.useState(()=>a?qs(a,t):t),n=()=>{const N=!c;x(N),a&&Gs(a,N)},g=o||c;return e.jsxs("div",{className:`collapsible-section ${g?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:n,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[r,e.jsx("span",{className:"collapsible-arrow",children:e.jsx($,{name:g?"caret-down":"caret-right",size:10})})]})]}),g&&e.jsx("div",{className:"collapsible-content",children:d})]})}function Ys({area:s,isSelected:a,onClick:t,onDelete:o}){const{t:d}=X(["config","common"]),r=s.assignedAgentIds.length,c=s.type==="rectangle"?d("config:areas.rect"):d("config:areas.circle");return e.jsxs("div",{className:`area-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"area-color-dot",style:{backgroundColor:s.color}}),e.jsxs("div",{className:"area-info",children:[e.jsx("div",{className:"area-name",children:s.name}),e.jsxs("div",{className:"area-meta",children:[c," ",r>0&&`• ${r} ${r>1?d("common:labels.agents").toLowerCase():d("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:o,title:d("config:areas.deleteArea"),children:"×"})]})}function Js({building:s,isSelected:a,onClick:t,onEdit:o}){var x;const{t:d}=X(["config"]),r=((x=s.pm2Status)==null?void 0:x.ports)||[],c=(n,g)=>{n.stopPropagation(),window.open(`http://${window.location.hostname}:${g}`,"_blank")};return e.jsxs("div",{className:`building-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:ns[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx($,{name:is(s.type),size:16})}),e.jsxs("div",{className:"building-info",children:[e.jsx("div",{className:"building-name",children:s.name}),e.jsxs("div",{className:"building-meta",children:[s.type,r.length>0&&e.jsx("span",{className:"building-ports",children:r.map(n=>e.jsxs("a",{href:`http://${window.location.hostname}:${n}`,className:"building-port-link",onClick:g=>c(g,n),title:`Open :${n}`,children:[":",n]},n))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:n=>{n.stopPropagation(),o()},title:d("config:buildings.editBuilding"),children:e.jsx($,{name:"gear",size:14})})]})}function Zs({building:s,onClose:a,onOpenModal:t}){var g,N,S,u,p,m,j,b;const{t:o}=X(["config","common"]),{buildingLogs:d}=Ke(),r=_.getBuildingLogs(s.id),c=ms[s.style||"server-rack"],x=h=>{_.sendBuildingCommand(s.id,h)},n=h=>{window.open(h,"_blank")};return e.jsxs("div",{className:"building-editor",children:[e.jsxs("div",{className:"building-editor-header",children:[e.jsxs("div",{className:"building-editor-title-row",children:[e.jsx("span",{className:"building-editor-icon",children:e.jsx($,{name:is(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:ns[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:a,children:"×"})]}),e.jsx("div",{className:"building-editor-section",children:e.jsxs("div",{className:"building-editor-info-grid",children:[e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("common:labels.type")}),e.jsx("span",{className:"building-editor-info-value",children:s.type})]}),e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.style")}),e.jsx("span",{className:"building-editor-info-value",children:c.label})]}),s.cwd&&e.jsxs("div",{className:"building-editor-info-item building-editor-info-wide",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.directory")}),e.jsx("span",{className:"building-editor-info-value building-editor-cwd",title:s.cwd,children:s.cwd.split("/").pop()||s.cwd})]})]})}),s.type==="server"&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.actions")}),e.jsxs("div",{className:"building-editor-actions",children:[e.jsxs("button",{className:"building-editor-action-btn start",onClick:()=>x("start"),disabled:!((g=s.commands)!=null&&g.start)||s.status==="running",title:((N=s.commands)==null?void 0:N.start)||o("config:buildings.noStartCommand"),children:[e.jsx($,{name:"play",size:12})," ",o("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>x("stop"),disabled:!((S=s.commands)!=null&&S.stop)||s.status==="stopped",title:((u=s.commands)==null?void 0:u.stop)||o("config:buildings.noStopCommand"),children:[e.jsx($,{name:"stop",size:12,weight:"fill"})," ",o("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>x("restart"),disabled:!((p=s.commands)!=null&&p.restart),title:((m=s.commands)==null?void 0:m.restart)||o("config:buildings.noRestartCommand"),children:[e.jsx($,{name:"refresh",size:12})," ",o("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>x("healthCheck"),disabled:!((j=s.commands)!=null&&j.healthCheck),title:((b=s.commands)==null?void 0:b.healthCheck)||o("config:buildings.noHealthCheck"),children:[e.jsx($,{name:"heart",size:12})," Health"]})]})]}),s.urls&&s.urls.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.links")}),e.jsx("div",{className:"building-editor-links",children:s.urls.map((h,y)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>n(h.url),title:h.url,children:[e.jsx($,{name:"link",size:12})," ",h.label||h.url]},y))})]}),r.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsxs("div",{className:"building-editor-section-title",children:[o("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>_.clearBuildingLogs(s.id),title:o("common:buttons.clear"),children:o("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:r.slice(-5).map((h,y)=>e.jsx("div",{className:"building-editor-log-entry",children:h},y))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx($,{name:"gear",size:12})," ",o("config:buildings.fullSettings")]})})]})}const Xs=[{key:"center",labelKey:"posCenter"},{key:"top-left",labelKey:"posTopLeft"},{key:"top-right",labelKey:"posTopRight"},{key:"bottom-left",labelKey:"posBottomLeft"},{key:"bottom-right",labelKey:"posBottomRight"}];function Qs({area:s,onClose:a,onOpenFolder:t}){var te;const{t:o}=X(["config","common"]),[d,r]=l.useState(s.name),[c,x]=l.useState(s.prompt||""),[n,g]=l.useState(!1),[N,S]=l.useState(""),[u,p]=l.useState(!1),m=l.useRef(null);l.useEffect(()=>{r(s.name)},[s.id,s.name]),l.useEffect(()=>{x(s.prompt||"")},[s.id,s.prompt]);const j=k=>{const O=k.target.value;r(O),_.updateArea(s.id,{name:O})},b=k=>{_.updateArea(s.id,{color:k})},h=k=>{const O=k.target.value;x(O),_.updateArea(s.id,{prompt:O})},y=()=>{N.trim()&&(_.addDirectoryToArea(s.id,N.trim()),S(""),g(!1))},P=(k,O)=>{O.stopPropagation(),_.removeDirectoryFromArea(s.id,k)},I=()=>{_.bringAreaToFront(s.id)},H=()=>{_.sendAreaToBack(s.id)},w=l.useCallback(()=>{let k=2,O=2;s.type==="rectangle"&&s.width&&s.height?(k=s.width,O=s.height):s.type==="circle"&&s.radius&&(k=s.radius*1.414,O=s.radius*1.414);const V=Math.min(k,O)*.4;return{width:Math.round(V*10)/10,height:Math.round(V*10)/10}},[s.type,s.width,s.height,s.radius]),z=async k=>{var V;const O=(V=k.target.files)==null?void 0:V[0];if(O){p(!0);try{const v=await Bs(s.id,O),D=w();_.updateArea(s.id,{logo:{filename:v.filename,position:"center",width:D.width,height:D.height,keepAspectRatio:!0,opacity:.8}})}catch(v){console.error("Failed to upload logo:",v)}finally{p(!1),m.current&&(m.current.value="")}}},B=async()=>{try{await Ms(s.id),_.updateArea(s.id,{logo:void 0})}catch(k){console.error("Failed to remove logo:",k)}},q=k=>{s.logo&&_.updateArea(s.id,{logo:{...s.logo,position:k}})},C=k=>{if(!s.logo)return;const O=parseFloat(k.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const V=s.logo.height/s.logo.width;_.updateArea(s.id,{logo:{...s.logo,width:O,height:Math.round(O*V*10)/10}})}else _.updateArea(s.id,{logo:{...s.logo,width:O}})},R=k=>{if(!s.logo)return;const O=parseFloat(k.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const V=s.logo.width/s.logo.height;_.updateArea(s.id,{logo:{...s.logo,height:O,width:Math.round(O*V*10)/10}})}else _.updateArea(s.id,{logo:{...s.logo,height:O}})},K=()=>{s.logo&&_.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},W=k=>{s.logo&&_.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(k.target.value)}})};return e.jsxs("div",{className:"area-editor",children:[e.jsxs("div",{className:"area-editor-header",children:[e.jsx("span",{className:"area-editor-title",children:o("config:areas.editArea")}),e.jsx("button",{className:"area-editor-close",onClick:a,children:"×"})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:d,onChange:j,placeholder:o("config:areas.areaName")})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.color")}),e.jsx("div",{className:"color-picker-row",children:gs.map(k=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===k?"selected":""}`,style:{backgroundColor:k},onClick:()=>b(k),"aria-label":`Set area color ${k}`,"aria-pressed":s.color===k,title:k},k))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:I,title:o("config:areas.bringToFront"),children:[e.jsx($,{name:"arrow-up",size:12})," ",o("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:H,title:o("config:areas.sendToBack"),children:[e.jsx($,{name:"arrow-down",size:12})," ",o("config:areas.back")]})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.logo")}),e.jsxs("div",{className:"area-logo-section",children:[(te=s.logo)!=null&&te.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:zs(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:B,children:o("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var k;return(k=m.current)==null?void 0:k.click()},disabled:u,children:u?"...":e.jsx($,{name:"refresh",size:12})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:Xs.map(({key:k,labelKey:O})=>{var V;return e.jsx("button",{className:`area-logo-pos-btn ${((V=s.logo)==null?void 0:V.position)===k?"active":""}`,onClick:()=>q(k),children:o(`config:areas.${O}`)},k)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoSize")}),e.jsxs("div",{className:"area-logo-size-row",children:[e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:C,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoHeight")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.height,onChange:R,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-aspect-label",title:o("config:areas.keepAspectRatio"),children:[e.jsx("input",{type:"checkbox",checked:s.logo.keepAspectRatio,onChange:K}),o("config:areas.keepAspectRatio")]})]})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoOpacity")}),e.jsxs("div",{className:"area-logo-opacity-row",children:[e.jsx("input",{type:"range",min:0,max:1,step:.05,value:s.logo.opacity??.8,onChange:W,className:"area-logo-opacity-slider"}),e.jsxs("span",{className:"area-logo-opacity-value",children:[Math.round((s.logo.opacity??.8)*100),"%"]})]})]})]}):e.jsx("button",{className:"area-logo-upload-btn",onClick:()=>{var k;return(k=m.current)==null?void 0:k.click()},disabled:u,children:u?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:m,type:"file",accept:"image/*",style:{display:"none"},onChange:z})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(k=>e.jsxs("div",{className:"area-folder-item",title:k,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:o("config:areas.openFolder"),children:e.jsx($,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:k.split("/").pop()||k}),e.jsx("button",{className:"area-folder-remove",onClick:O=>P(k,O),title:o("config:areas.removeFolder"),children:"×"})]},k)),n?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(fs,{value:N,onChange:S,onSubmit:y,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:y,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>g(!0),children:o("config:areas.addFolder")})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.prompt","Prompt")}),e.jsx("textarea",{className:"area-editor-input",value:c,onChange:h,placeholder:o("config:areas.promptPlaceholder","System prompt for agents in this area..."),rows:4,style:{resize:"vertical",fontFamily:"monospace",fontSize:12}}),e.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:4},children:o("config:areas.promptHint","This prompt is injected into agents assigned to this area. Takes effect on next context refresh.")})]}),s.assignedAgentIds.length>0&&e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:o("config:areas.rightClickUnassign")})]})]})}function et(){const{t:s}=X(["config","common"]),a=xs(),[t,o]=l.useState(!1),[d,r]=l.useState(null),[c,x]=l.useState({name:"",key:"",value:"",description:""}),[n,g]=l.useState(null),N=()=>{o(!0),r(null),x({name:"",key:"",value:"",description:""})},S=h=>{r(h.id),o(!1),x({name:h.name,key:h.key,value:h.value,description:h.description||""})},u=()=>{o(!1),r(null),x({name:"",key:"",value:"",description:""})},p=()=>{!c.name.trim()||!c.key.trim()||(d?_.updateSecret(d,{name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}):_.createSecret({name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}),u())},m=h=>{g(h)},j=()=>{n&&(_.deleteSecret(n),d===n&&u())},b=h=>{navigator.clipboard.writeText(`{{${h}}}`)};return e.jsxs("div",{className:"secrets-section",children:[e.jsx("div",{className:"secrets-description",children:s("config:secrets.description",{placeholder:"{{KEY}}"})}),e.jsx("div",{className:"secrets-list",children:a.length===0&&!t?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):a.map(h=>e.jsxs("div",{className:`secret-item ${d===h.id?"editing":""}`,children:[e.jsxs("div",{className:"secret-item-header",children:[e.jsxs("div",{className:"secret-item-info",children:[e.jsx("span",{className:"secret-item-name",children:h.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>b(h.key),title:s("config:secrets.copyPlaceholder"),children:`{{${h.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>S(h),title:s("common:buttons.edit"),children:e.jsx($,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>m(h.id),title:s("common:buttons.delete"),children:"×"})]})]}),h.description&&e.jsx("div",{className:"secret-item-description",children:h.description})]},h.id))}),(t||d)&&e.jsxs("div",{className:"secret-form",children:[e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.name")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.namePlaceholder"),value:c.name,onChange:h=>x({...c,name:h.target.value}),autoFocus:!0})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:"Key"}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.keyPlaceholder"),value:c.key,onChange:h=>x({...c,key:h.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${c.key||"KEY"}}}`})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("config:secrets.secretValue")}),e.jsx("input",{type:"password",className:"secret-form-input",placeholder:s("config:secrets.valuePlaceholder"),value:c.value,onChange:h=>x({...c,value:h.target.value})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.description")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.descriptionPlaceholder"),value:c.description,onChange:h=>x({...c,description:h.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:u,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:p,disabled:!c.name.trim()||!c.key.trim(),children:s(d?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!d&&e.jsx("button",{className:"secrets-add-btn",onClick:N,children:s("config:secrets.addSecret")}),e.jsx(he,{isOpen:n!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:j,onClose:()=>g(null)})]})}async function st(){const s=se(),a=await fetch(`${Y()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch system prompt: ${a.statusText}`);return(await a.json()).prompt||""}async function tt(s){const a=se(),t=await fetch(`${Y()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({prompt:s})});if(!t.ok)throw new Error(`Failed to update system prompt: ${t.statusText}`)}async function at(){const s=se(),a=await fetch(`${Y()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to clear system prompt: ${a.statusText}`)}async function nt(){const s=se(),a=await fetch(`${Y()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch echo prompt setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function it(s){const a=se(),t=await fetch(`${Y()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function ot(){const s=se(),a=await fetch(`${Y()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch codex binary path: ${a.statusText}`);return(await a.json()).path||""}async function lt(s){const a=se(),t=await fetch(`${Y()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function ct(){const s=se(),a=await fetch(`${Y()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch tmux mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function rt(s){const a=se(),t=await fetch(`${Y()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function dt(){const s=se(),a=await fetch(`${Y()}/api/agents/system-settings/interactive-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch interactive mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function ut(s){const a=se(),t=await fetch(`${Y()}/api/agents/system-settings/interactive-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update interactive mode setting: ${t.statusText}`)}async function pt(){const s=se(),a=await fetch(`${Y()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch backup status: ${a.statusText}`);return a.json()}async function ht(s){const a=se(),t=await fetch(`${Y()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok){const o=await t.json().catch(()=>({}));throw new Error(o.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function mt({checked:s,onChange:a,disabled:t}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:t,onChange:o=>a(o.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function gt(){const{t:s}=X(["config","common"]),[a,t]=l.useState([]),[o,d]=l.useState(new Set),[r,c]=l.useState(new Set),[x,n]=l.useState(!1),[g,N]=l.useState(!1),[S,u]=l.useState(null),[p,m]=l.useState(null),[j,b]=l.useState(null),[h,y]=l.useState(null),[P,I]=l.useState(!1),[H,w]=l.useState(null);l.useEffect(()=>{je(ke("/api/config/categories")).then(v=>v.json()).then(v=>{const D=Array.isArray(v)?v:[];t(D),d(new Set(D.map(F=>F.id)))}).catch(v=>console.error("Failed to fetch config categories:",v))},[]),l.useEffect(()=>{pt().then(y).catch(v=>{console.error("Failed to fetch backup status:",v),w(v.message||"Failed to fetch backup status")})},[]);const z=async v=>{if(!P){I(!0),w(null);try{const D=await ht(v);y(D)}catch(D){w(D.message||"Failed to update backup setting")}finally{I(!1)}}},B=v=>{d(D=>{const F=new Set(D);return F.has(v)?F.delete(v):F.add(v),F})},q=v=>{c(D=>{const F=new Set(D);return F.has(v)?F.delete(v):F.add(v),F})},C=()=>d(new Set(a.map(v=>v.id))),R=()=>d(new Set),K=()=>{p&&c(new Set(p.categories.map(v=>v.id)))},W=()=>c(new Set),te=async()=>{var v;if(o.size!==0){n(!0),b(null);try{const D=Array.from(o).join(","),F=await je(ke(`/api/config/export?categories=${D}`));if(!F.ok)throw new Error("Export failed");const Q=await F.blob(),ee=window.URL.createObjectURL(Q),T=document.createElement("a");T.href=ee;const A=F.headers.get("Content-Disposition"),J=((v=A==null?void 0:A.match(/filename="(.+)"/))==null?void 0:v[1])||"tide-commander-config.zip";T.download=J,document.body.appendChild(T),T.click(),document.body.removeChild(T),window.URL.revokeObjectURL(ee),b({type:"success",text:s("config:data.exportSuccess")})}catch(D){b({type:"error",text:D.message||"Export failed"})}finally{n(!1)}}},k=async v=>{var F;const D=(F=v.target.files)==null?void 0:F[0];if(D){u(D),b(null),m(null),c(new Set);try{const Q=await je(ke("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await D.arrayBuffer()});if(!Q.ok){const A=await Q.json();throw new Error(A.error||"Failed to preview config file")}const ee=await Q.json(),T=Array.isArray(ee.categories)?ee.categories:[];m({...ee,categories:T}),c(new Set(T.map(A=>A.id)))}catch(Q){b({type:"error",text:Q.message||"Failed to read config file"}),u(null)}}},O=async()=>{if(!(!S||r.size===0)){N(!0),b(null);try{const v=Array.from(r).join(","),D=await je(ke(`/api/config/import?categories=${v}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await S.arrayBuffer()}),F=await D.json();if(!D.ok)throw new Error(F.error||"Import failed");b({type:"success",text:F.message||s("config:data.importSuccess")}),u(null),m(null),c(new Set)}catch(v){b({type:"error",text:v.message||"Import failed"})}finally{N(!1)}}},V=()=>{u(null),m(null),c(new Set),b(null)};return e.jsxs("div",{className:"data-section",children:[j&&e.jsx("div",{className:`data-message data-message-${j.type}`,children:j.text}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:"Hourly Backups"}),e.jsx(mt,{checked:!!(h!=null&&h.enabled),disabled:P||!h,onChange:z})]}),e.jsxs("div",{className:"data-backup-info",children:[h?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:h.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!h.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:h.scriptPath})]}),h.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(h.lastRunAt).toLocaleString(),h.lastRunOk===!0&&" — ok",h.lastRunOk===!1&&h.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",h.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),H&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:H})]})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:s("config:data.exportData")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:C,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:R,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:a.map(v=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(v.id),onChange:()=>B(v.id)}),e.jsx("span",{className:"data-category-name",children:v.name})]},v.id))}),e.jsx("button",{className:"data-action-btn export",onClick:te,disabled:x||o.size===0,children:x?s("config:data.exporting"):s("config:data.exportCount",{count:o.size})})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsx("div",{className:"data-subsection-header",children:e.jsx("span",{className:"data-subsection-title",children:s("config:data.importData")})}),S?p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:S.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(p.exportedAt).toLocaleDateString()]})]}),e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-subtitle",children:s("config:data.selectToImport")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:K,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:W,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:p.categories.map(v=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:r.has(v.id),onChange:()=>q(v.id)}),e.jsx("span",{className:"data-category-name",children:v.name}),v.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",v.fileCount," ",s("config:data.files"),")"]})]},v.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:V,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:O,disabled:g||r.size===0,children:g?s("config:data.importing"):s("config:data.importCount",{count:r.size})})]})]}):e.jsx("div",{className:"data-loading",children:s("config:data.readingFile")}):e.jsxs("label",{className:"data-file-input",children:[e.jsx("input",{type:"file",accept:".zip",onChange:k,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}async function ft(){const s=await je(`${Y()}/api/system/install-info`);if(!s.ok)throw new Error(`Failed to fetch install info: ${s.statusText}`);return s.json()}function xt(s,a){const t=new AbortController;return(async()=>{try{const o=await fetch(bs(`${Y()}/api/system/self-update`),{method:"POST",signal:t.signal,headers:{Accept:"text/event-stream"}});if(!o.ok||!o.body){const x=await o.text().catch(()=>"");let n=null;try{n=JSON.parse(x)}catch{}const g=n&&typeof n=="object"&&"error"in n&&typeof n.error=="string"?n.error:`Self-update failed: ${o.status} ${o.statusText}`;s({type:"error",message:g}),a(new Error(g));return}const d=o.body.getReader(),r=new TextDecoder("utf-8");let c="";for(;;){const{value:x,done:n}=await d.read();if(n)break;c+=r.decode(x,{stream:!0});let g=c.indexOf(`
2
2
 
3
3
  `);for(;g!==-1;){const N=c.slice(0,g);c=c.slice(g+2);const S=N.split(`
4
4
  `);let u="message",p="";for(const m of S)m.startsWith(":")||(m.startsWith("event:")?u=m.slice(6).trim():m.startsWith("data:")&&(p+=(p?`
@@ -1,4 +1,4 @@
1
- import{br as ta,u as B,j as e,aY as j,bu as Ms,bv as Fs,aZ as ae,s as D,bw as $s,r as m,D as Z,I as F,ab as Us,b6 as qe,f as na,bx as la,W as ia,S as ra,k as oa,aa as Ks,b7 as Ue}from"./main-D6Q3mJMF.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const ca=[{value:"",labelKey:"terminal:building.colorDefault"},{value:"#2a2a3a",labelKey:"terminal:building.colorDarkGray"},{value:"#3a2a2a",labelKey:"terminal:building.colorDarkRed"},{value:"#2a3a2a",labelKey:"terminal:building.colorDarkGreen"},{value:"#2a2a4a",labelKey:"terminal:building.colorDarkBlue"},{value:"#3a3a2a",labelKey:"terminal:building.colorDarkYellow"},{value:"#3a2a3a",labelKey:"terminal:building.colorDarkPurple"},{value:"#2a3a3a",labelKey:"terminal:building.colorDarkCyan"},{value:"#4a3a3a",labelKey:"terminal:building.colorWarmBrown"},{value:"#3a4a4a",labelKey:"terminal:building.colorCoolSteel"}];function da(r){return ta.t(r)}function Ve(r){if(r===0)return"0 B";const p=1024,u=["B","KB","MB","GB"],x=Math.floor(Math.log(r)/Math.log(p));return parseFloat((r/Math.pow(p,x)).toFixed(1))+" "+u[x]}function ma(r){const u=Date.now()-r,x=Math.floor(u/(1e3*60*60)),n=Math.floor(u%(1e3*60*60)/(1e3*60));return x>0?`${x}h ${n}m`:`${n}m`}const Hs={30:"#1a1a1a",31:"#e74c3c",32:"#2ecc71",33:"#f39c12",34:"#3498db",35:"#9b59b6",36:"#00bcd4",37:"#ecf0f1",90:"#7f8c8d",91:"#ff6b6b",92:"#4ade80",93:"#fbbf24",94:"#60a5fa",95:"#c084fc",96:"#22d3ee",97:"#ffffff"};function qs(r){const p=[],u=/\x1B\[([0-9;]*)m/g;let x=0,n=null,y;for(;(y=u.exec(r))!==null;){if(y.index>x){const g=r.slice(x,y.index);n?p.push(e.jsx("span",{style:{color:n},children:g},p.length)):p.push(g)}const C=y[1].split(";").map(Number);for(const g of C)g===0||g===39?n=null:Hs[g]&&(n=Hs[g]);x=u.lastIndex}if(x<r.length){const C=r.slice(x);n?p.push(e.jsx("span",{style:{color:n},children:C},p.length)):p.push(C)}return p.length>0?p:[r]}function ua({buildingName:r,onClose:p,onConfirm:u}){const{t:x}=B(["terminal","common"]);return e.jsx("div",{className:"modal-overlay visible",onClick:p,children:e.jsxs("div",{className:"modal confirm-modal",onClick:n=>n.stopPropagation(),children:[e.jsx("div",{className:"modal-header",children:x("terminal:building.deleteBuilding")}),e.jsxs("div",{className:"modal-body confirm-modal-body",children:[e.jsx("p",{children:x("terminal:building.deleteConfirm",{name:r})}),e.jsx("p",{className:"confirm-modal-note",children:x("terminal:building.deleteNote")})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("button",{className:"btn btn-secondary",onClick:p,children:x("common:buttons.cancel")}),e.jsx("button",{className:"btn btn-danger",onClick:u,autoFocus:!0,children:x("common:buttons.delete")})]})]})})}function pa({usePM2:r,setUsePM2:p}){const{t:u}=B(["terminal"]);return e.jsxs("div",{className:"form-section pm2-toggle-section",children:[e.jsxs("label",{className:"toggle-switch",children:[e.jsx("input",{type:"checkbox",className:"toggle-input",checked:r,onChange:x=>p(x.target.checked)}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})}),e.jsxs("span",{className:"toggle-label",children:[e.jsx("span",{className:"pm2-badge",children:"PM2"}),u("terminal:building.usePM2")]})]}),e.jsx("div",{className:"form-hint",children:u("terminal:building.pm2Hint")})]})}function ha({usePM2:r,pm2Script:p,setPm2Script:u,pm2Args:x,setPm2Args:n,pm2Interpreter:y,setPm2Interpreter:C,pm2InterpreterArgs:g,setPm2InterpreterArgs:v,pm2Env:s,setPm2Env:h,isEditMode:a,building:t,handleCommand:o}){var N;const{t:i}=B(["terminal","common"]);return r?e.jsxs("div",{className:"form-section pm2-config-section",children:[e.jsx("label",{className:"form-label",children:i("terminal:building.pm2Configuration")}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Script"),e.jsx(j,{text:i("terminal:building.helpPm2Script"),title:i("terminal:building.pm2Script"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:p,onChange:b=>u(b.target.value),placeholder:"npm, java, python, ./app.js",required:r})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Arguments"),e.jsx(j,{text:i("terminal:building.helpPm2Arguments"),title:i("terminal:building.pm2Arguments"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:x,onChange:b=>n(b.target.value),placeholder:"run dev, -jar app.jar, app.py"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Interpreter"),e.jsx(j,{text:i("terminal:building.helpPm2Interpreter"),title:i("terminal:building.pm2Interpreter"),position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:y,onChange:b=>C(b.target.value),children:Object.keys(Ms).map(b=>e.jsx("option",{value:b,children:Ms[b].label},b))})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2InterpArgs"),e.jsx(j,{text:i("terminal:building.helpPm2InterpArgs"),title:i("terminal:building.pm2InterpArgs"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:g,onChange:b=>v(b.target.value),placeholder:"-jar (for Java)"})]}),e.jsxs("div",{className:"command-row env-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Environment"),e.jsx(j,{text:i("terminal:building.helpPm2Environment"),title:i("terminal:building.pm2Environment"),position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input form-textarea",value:s,onChange:b=>h(b.target.value),placeholder:`KEY=value
1
+ import{br as ta,u as B,j as e,aY as j,bu as Ms,bv as Fs,aZ as ae,s as D,bw as $s,r as m,D as Z,I as F,ab as Us,b6 as qe,f as na,bx as la,W as ia,S as ra,k as oa,aa as Ks,b7 as Ue}from"./main-DffU4pm2.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const ca=[{value:"",labelKey:"terminal:building.colorDefault"},{value:"#2a2a3a",labelKey:"terminal:building.colorDarkGray"},{value:"#3a2a2a",labelKey:"terminal:building.colorDarkRed"},{value:"#2a3a2a",labelKey:"terminal:building.colorDarkGreen"},{value:"#2a2a4a",labelKey:"terminal:building.colorDarkBlue"},{value:"#3a3a2a",labelKey:"terminal:building.colorDarkYellow"},{value:"#3a2a3a",labelKey:"terminal:building.colorDarkPurple"},{value:"#2a3a3a",labelKey:"terminal:building.colorDarkCyan"},{value:"#4a3a3a",labelKey:"terminal:building.colorWarmBrown"},{value:"#3a4a4a",labelKey:"terminal:building.colorCoolSteel"}];function da(r){return ta.t(r)}function Ve(r){if(r===0)return"0 B";const p=1024,u=["B","KB","MB","GB"],x=Math.floor(Math.log(r)/Math.log(p));return parseFloat((r/Math.pow(p,x)).toFixed(1))+" "+u[x]}function ma(r){const u=Date.now()-r,x=Math.floor(u/(1e3*60*60)),n=Math.floor(u%(1e3*60*60)/(1e3*60));return x>0?`${x}h ${n}m`:`${n}m`}const Hs={30:"#1a1a1a",31:"#e74c3c",32:"#2ecc71",33:"#f39c12",34:"#3498db",35:"#9b59b6",36:"#00bcd4",37:"#ecf0f1",90:"#7f8c8d",91:"#ff6b6b",92:"#4ade80",93:"#fbbf24",94:"#60a5fa",95:"#c084fc",96:"#22d3ee",97:"#ffffff"};function qs(r){const p=[],u=/\x1B\[([0-9;]*)m/g;let x=0,n=null,y;for(;(y=u.exec(r))!==null;){if(y.index>x){const g=r.slice(x,y.index);n?p.push(e.jsx("span",{style:{color:n},children:g},p.length)):p.push(g)}const C=y[1].split(";").map(Number);for(const g of C)g===0||g===39?n=null:Hs[g]&&(n=Hs[g]);x=u.lastIndex}if(x<r.length){const C=r.slice(x);n?p.push(e.jsx("span",{style:{color:n},children:C},p.length)):p.push(C)}return p.length>0?p:[r]}function ua({buildingName:r,onClose:p,onConfirm:u}){const{t:x}=B(["terminal","common"]);return e.jsx("div",{className:"modal-overlay visible",onClick:p,children:e.jsxs("div",{className:"modal confirm-modal",onClick:n=>n.stopPropagation(),children:[e.jsx("div",{className:"modal-header",children:x("terminal:building.deleteBuilding")}),e.jsxs("div",{className:"modal-body confirm-modal-body",children:[e.jsx("p",{children:x("terminal:building.deleteConfirm",{name:r})}),e.jsx("p",{className:"confirm-modal-note",children:x("terminal:building.deleteNote")})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("button",{className:"btn btn-secondary",onClick:p,children:x("common:buttons.cancel")}),e.jsx("button",{className:"btn btn-danger",onClick:u,autoFocus:!0,children:x("common:buttons.delete")})]})]})})}function pa({usePM2:r,setUsePM2:p}){const{t:u}=B(["terminal"]);return e.jsxs("div",{className:"form-section pm2-toggle-section",children:[e.jsxs("label",{className:"toggle-switch",children:[e.jsx("input",{type:"checkbox",className:"toggle-input",checked:r,onChange:x=>p(x.target.checked)}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})}),e.jsxs("span",{className:"toggle-label",children:[e.jsx("span",{className:"pm2-badge",children:"PM2"}),u("terminal:building.usePM2")]})]}),e.jsx("div",{className:"form-hint",children:u("terminal:building.pm2Hint")})]})}function ha({usePM2:r,pm2Script:p,setPm2Script:u,pm2Args:x,setPm2Args:n,pm2Interpreter:y,setPm2Interpreter:C,pm2InterpreterArgs:g,setPm2InterpreterArgs:v,pm2Env:s,setPm2Env:h,isEditMode:a,building:t,handleCommand:o}){var N;const{t:i}=B(["terminal","common"]);return r?e.jsxs("div",{className:"form-section pm2-config-section",children:[e.jsx("label",{className:"form-label",children:i("terminal:building.pm2Configuration")}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Script"),e.jsx(j,{text:i("terminal:building.helpPm2Script"),title:i("terminal:building.pm2Script"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:p,onChange:b=>u(b.target.value),placeholder:"npm, java, python, ./app.js",required:r})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Arguments"),e.jsx(j,{text:i("terminal:building.helpPm2Arguments"),title:i("terminal:building.pm2Arguments"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:x,onChange:b=>n(b.target.value),placeholder:"run dev, -jar app.jar, app.py"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Interpreter"),e.jsx(j,{text:i("terminal:building.helpPm2Interpreter"),title:i("terminal:building.pm2Interpreter"),position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:y,onChange:b=>C(b.target.value),children:Object.keys(Ms).map(b=>e.jsx("option",{value:b,children:Ms[b].label},b))})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2InterpArgs"),e.jsx(j,{text:i("terminal:building.helpPm2InterpArgs"),title:i("terminal:building.pm2InterpArgs"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:g,onChange:b=>v(b.target.value),placeholder:"-jar (for Java)"})]}),e.jsxs("div",{className:"command-row env-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Environment"),e.jsx(j,{text:i("terminal:building.helpPm2Environment"),title:i("terminal:building.pm2Environment"),position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input form-textarea",value:s,onChange:b=>h(b.target.value),placeholder:`KEY=value
2
2
  SERVER_PORT=7201
3
3
  NODE_ENV=production`,rows:3})]}),e.jsx("div",{className:"pm2-examples",children:e.jsxs("details",{children:[e.jsx("summary",{children:i("terminal:building.pm2Examples")}),e.jsxs("div",{className:"pm2-examples-content",children:[e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Node.js:"})," Script: ",e.jsx("code",{children:"npm"}),", Args: ",e.jsx("code",{children:"run dev"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Symfony:"})," Script: ",e.jsx("code",{children:"symfony"}),", Args: ",e.jsx("code",{children:"serve --no-daemon"}),", Interpreter: ",e.jsx("code",{children:"None"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Java JAR:"})," Script: ",e.jsx("code",{children:"app.jar"}),", Interpreter: ",e.jsx("code",{children:"Java"}),", Interp. Args: ",e.jsx("code",{children:"-jar"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Python:"})," Script: ",e.jsx("code",{children:"app.py"}),", Interpreter: ",e.jsx("code",{children:"Python 3"})]})]})]})}),a&&(t==null?void 0:t.pm2Status)&&e.jsx("div",{className:"pm2-status-display",children:e.jsxs("div",{className:"pm2-status-row",children:[e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"PID"}),e.jsx("span",{className:"pm2-metric-value",children:t.pm2Status.pid||"-"})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"CPU"}),e.jsxs("span",{className:"pm2-metric-value",children:[((N=t.pm2Status.cpu)==null?void 0:N.toFixed(1))||"0","%"]})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"MEM"}),e.jsx("span",{className:"pm2-metric-value",children:Ve(t.pm2Status.memory||0)})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"Restarts"}),e.jsx("span",{className:"pm2-metric-value",children:t.pm2Status.restarts||0})]}),t.pm2Status.uptime&&e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"Uptime"}),e.jsx("span",{className:"pm2-metric-value",children:ma(t.pm2Status.uptime)})]})]})}),a&&e.jsxs("div",{className:"pm2-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>o("start"),children:i("common:buttons.start")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>o("stop"),children:i("common:buttons.stop")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>o("restart"),children:i("terminal:buildingAction.restart")}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>o("logs"),children:i("terminal:logs.title")})]})]}):null}function xa({dockerMode:r,setDockerMode:p,dockerImage:u,setDockerImage:x,dockerContainerName:n,setDockerContainerName:y,dockerCommand:C,setDockerCommand:g,dockerPorts:v,setDockerPorts:s,dockerVolumes:h,setDockerVolumes:a,dockerNetwork:t,setDockerNetwork:o,dockerRestart:i,setDockerRestart:N,dockerPull:b,setDockerPull:L,dockerEnv:T,setDockerEnv:A,dockerComposePath:$,setDockerComposePath:R,dockerComposeProject:K,setDockerComposeProject:I,dockerComposeServices:H,setDockerComposeServices:O,selectedExistingContainer:d,setSelectedExistingContainer:E,dockerContainersList:q,isEditMode:V,building:k,handleCommand:_}){const{t:M}=B(["config","common"]);return e.jsxs("div",{className:"form-section docker-config-section",children:[e.jsx("label",{className:"form-label",children:M("config:buildings.dockerConfig")}),e.jsxs("div",{className:"docker-mode-selector",children:[e.jsxs("label",{className:`docker-mode-option ${r==="container"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"container",checked:r==="container",onChange:()=>p("container")}),e.jsx("span",{className:"docker-mode-icon",children:"📦"}),e.jsx("span",{className:"docker-mode-label",children:"Container"}),e.jsx("span",{className:"docker-mode-desc",children:"Create a new container"})]}),e.jsxs("label",{className:`docker-mode-option ${r==="compose"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"compose",checked:r==="compose",onChange:()=>p("compose")}),e.jsx("span",{className:"docker-mode-icon",children:"🛠"}),e.jsx("span",{className:"docker-mode-label",children:"Compose"}),e.jsx("span",{className:"docker-mode-desc",children:"Manage multiple services"})]}),e.jsxs("label",{className:`docker-mode-option ${r==="existing"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"existing",checked:r==="existing",onChange:()=>p("existing")}),e.jsx("span",{className:"docker-mode-icon",children:"🔎"}),e.jsx("span",{className:"docker-mode-label",children:"Existing"}),e.jsx("span",{className:"docker-mode-desc",children:"Adopt existing container"})]})]}),r==="container"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Image:",e.jsx(j,{text:"Docker image to run, e.g., nginx:latest, redis:alpine, my-app:v1",title:"Image",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:u,onChange:l=>x(l.target.value),placeholder:"nginx:latest",required:!0})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Container Name:",e.jsx(j,{text:"Custom name for the container. If empty, auto-generated based on building name.",title:"Container Name",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:n,onChange:l=>y(l.target.value),placeholder:"Auto-generated (tc-{name}-{id})"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Command:",e.jsx(j,{text:"Override the default container command. Leave empty to use image's CMD.",title:"Command Override",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:l=>g(l.target.value),placeholder:"Optional command override"})]}),e.jsxs("div",{className:"form-section docker-ports-section",children:[e.jsxs("label",{className:"form-label",children:["Port Mappings",e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>s([...v,""]),children:"+ Add"})]}),v.map((l,S)=>e.jsxs("div",{className:"docker-mapping-row",children:[e.jsx("input",{type:"text",className:"form-input",value:l,onChange:U=>{const z=[...v];z[S]=U.target.value,s(z)},placeholder:"8080:80 or 3000"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>s(v.filter((U,z)=>z!==S)),children:"x"})]},S)),v.length===0&&e.jsx("div",{className:"form-hint",children:"Format: host:container (e.g., 8080:80) or same port (e.g., 3000)"})]}),e.jsxs("div",{className:"form-section docker-volumes-section",children:[e.jsxs("label",{className:"form-label",children:["Volume Mounts",e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>a([...h,""]),children:"+ Add"})]}),h.map((l,S)=>e.jsxs("div",{className:"docker-mapping-row",children:[e.jsx("input",{type:"text",className:"form-input",value:l,onChange:U=>{const z=[...h];z[S]=U.target.value,a(z)},placeholder:"./data:/app/data or /host/path:/container/path"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>a(h.filter((U,z)=>z!==S)),children:"x"})]},S)),h.length===0&&e.jsx("div",{className:"form-hint",children:"Format: host_path:container_path (relative paths resolved from working directory)"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Network:",e.jsx(j,{text:"Docker network to connect to. Leave empty for default bridge network.",title:"Network",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:t,onChange:l=>o(l.target.value),placeholder:"bridge (default)"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Restart Policy:",e.jsx(j,{text:"When should Docker restart the container automatically?",title:"Restart Policy",position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:i,onChange:l=>N(l.target.value),children:Object.keys(Fs).map(l=>e.jsx("option",{value:l,children:Fs[l].label},l))})]})]}),r==="compose"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Compose File:",e.jsx(j,{text:"Path to docker-compose.yml file, relative to working directory.",title:"Compose File",position:"top",size:"sm"})]}),e.jsx(ae,{value:$,onChange:R,placeholder:"docker-compose.yml",className:"form-input",directoriesOnly:!1})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Project Name:",e.jsx(j,{text:"Override the compose project name. Leave empty for auto-generated name.",title:"Project Name",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:K,onChange:l=>I(l.target.value),placeholder:"Auto-generated"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Services:",e.jsx(j,{text:"Specific services to manage (comma-separated). Leave empty for all services.",title:"Services",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:H,onChange:l=>O(l.target.value),placeholder:"All services (or: api, db, redis)"})]})]}),r==="existing"&&e.jsxs("div",{className:"docker-existing-section",children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Select Container:",e.jsx(j,{text:"Choose an existing Docker container to monitor and control. The container will not be deleted when removing the building.",title:"Existing Container",position:"top",size:"sm"})]}),e.jsxs("div",{className:"docker-existing-select-wrapper",children:[e.jsxs("select",{className:"form-input form-select",value:d,onChange:l=>E(l.target.value),required:r==="existing",children:[e.jsx("option",{value:"",children:"Select a container..."}),q.map(l=>e.jsxs("option",{value:l.name,children:[l.name," (",l.image,") - ",l.state]},l.id))]}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.requestDockerContainersList(),title:"Refresh container list",children:"↻"})]})]}),q.length===0&&e.jsx("div",{className:"form-hint docker-existing-hint",children:"No containers found. Make sure Docker is running and you have containers available."}),d&&e.jsx("div",{className:"docker-existing-info",children:(()=>{const l=q.find(S=>S.name===d);return l?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Image:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.image})]}),e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Status:"}),e.jsx("span",{className:`docker-existing-info-value docker-status-${l.status}`,children:l.state})]}),e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"ID:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.id.slice(0,12)})]}),l.ports.length>0&&e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Ports:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.ports.map(S=>`${S.host}:${S.container}/${S.protocol}`).join(", ")})]})]}):null})()}),e.jsx("div",{className:"form-hint",children:"Note: Existing containers will not be deleted when you remove this building."})]}),r!=="existing"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Pull Policy:",e.jsx(j,{text:"When to pull images: always, only if missing, or never.",title:"Pull Policy",position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:b,onChange:l=>L(l.target.value),children:Object.keys($s).map(l=>e.jsx("option",{value:l,children:$s[l].label},l))})]}),e.jsxs("div",{className:"command-row env-row",children:[e.jsxs("span",{className:"command-label",children:["Environment:",e.jsx(j,{text:"Environment variables in KEY=value format, one per line.",title:"Environment Variables",position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input form-textarea",value:T,onChange:l=>A(l.target.value),placeholder:`KEY=value
4
4
  DATABASE_URL=postgres://...
@@ -1 +1 @@
1
- import{h as At,i as yt,aw as Et,a1 as xt,a2 as Ct,c9 as Mt,ca as Ft,aF as wt,r as d,X as St,S as me,cb as vt,cc as fe,s as J,cd as Bt,j as f,I as ne,ce as Ve,cf as It,a6 as _t,cg as Dt,ch as kt,ci as Ee,al as Be,W as Rt,p as nt,u as Fe,cj as Je}from"./main-D6Q3mJMF.js";import{ck as Ls,cl as $s,cm as js,cn as Ns,co as Ps}from"./main-D6Q3mJMF.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function re(t){return Array.isArray?Array.isArray(t):it(t)==="[object Array]"}function bt(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Tt(t){return t==null?"":bt(t)}function q(t){return typeof t=="string"}function rt(t){return typeof t=="number"}function Lt(t){return t===!0||t===!1||$t(t)&&it(t)=="[object Boolean]"}function ct(t){return typeof t=="object"}function $t(t){return ct(t)&&t!==null}function G(t){return t!=null}function Ie(t){return!t.trim().length}function it(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const jt="Incorrect 'index' type",Nt=t=>`Invalid value for key ${t}`,Pt=t=>`Pattern length exceeds max of ${t}.`,Kt=t=>`Missing ${t} property in key`,Ot=t=>`Property 'weight' in key '${t}' must be a positive integer`,Xe=Object.prototype.hasOwnProperty;class zt{constructor(e){this._keys=[],this._keyMap={};let n=0;e.forEach(r=>{let c=ot(r);this._keys.push(c),this._keyMap[c.id]=c,n+=c.weight}),this._keys.forEach(r=>{r.weight/=n})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function ot(t){let e=null,n=null,r=null,c=1,i=null;if(q(t)||re(t))r=t,e=Ze(t),n=_e(t);else{if(!Xe.call(t,"name"))throw new Error(Kt("name"));const o=t.name;if(r=o,Xe.call(t,"weight")&&(c=t.weight,c<=0))throw new Error(Ot(o));e=Ze(o),n=_e(o),i=t.getFn}return{path:e,id:n,weight:c,src:r,getFn:i}}function Ze(t){return re(t)?t:t.split(".")}function _e(t){return re(t)?t.join("."):t}function Gt(t,e){let n=[],r=!1;const c=(i,o,a)=>{if(G(i))if(!o[a])n.push(i);else{let u=o[a];const l=i[u];if(!G(l))return;if(a===o.length-1&&(q(l)||rt(l)||Lt(l)))n.push(Tt(l));else if(re(l)){r=!0;for(let h=0,E=l.length;h<E;h+=1)c(l[h],o,a+1)}else o.length&&c(l,o,a+1)}};return c(t,q(e)?e.split("."):e,0),r?n:n[0]}const Qt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Wt={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},Ht={location:0,threshold:.6,distance:100},Ut={useExtendedSearch:!1,getFn:Gt,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var y={...Wt,...Qt,...Ht,...Ut};const Yt=/[^ ]+/g;function Vt(t=1,e=3){const n=new Map,r=Math.pow(10,e);return{get(c){const i=c.match(Yt).length;if(n.has(i))return n.get(i);const o=1/Math.pow(i,.5*t),a=parseFloat(Math.round(o*r)/r);return n.set(i,a),a},clear(){n.clear()}}}class Le{constructor({getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){this.norm=Vt(n,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((n,r)=>{this._keysMap[n.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,q(this.docs[0])?this.docs.forEach((e,n)=>{this._addString(e,n)}):this.docs.forEach((e,n)=>{this._addObject(e,n)}),this.norm.clear())}add(e){const n=this.size();q(e)?this._addString(e,n):this._addObject(e,n)}removeAt(e){this.records.splice(e,1);for(let n=e,r=this.size();n<r;n+=1)this.records[n].i-=1}getValueForItemAtKeyId(e,n){return e[this._keysMap[n]]}size(){return this.records.length}_addString(e,n){if(!G(e)||Ie(e))return;let r={v:e,i:n,n:this.norm.get(e)};this.records.push(r)}_addObject(e,n){let r={i:n,$:{}};this.keys.forEach((c,i)=>{let o=c.getFn?c.getFn(e):this.getFn(e,c.path);if(G(o)){if(re(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(G(h))if(q(h)&&!Ie(h)){let E={v:h,i:l,n:this.norm.get(h)};a.push(E)}else re(h)&&h.forEach((E,x)=>{u.push({nestedArrIndex:x,value:E})})}r.$[i]=a}else if(q(o)&&!Ie(o)){let a={v:o,n:this.norm.get(o)};r.$[i]=a}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function at(t,e,{getFn:n=y.getFn,fieldNormWeight:r=y.fieldNormWeight}={}){const c=new Le({getFn:n,fieldNormWeight:r});return c.setKeys(t.map(ot)),c.setSources(e),c.create(),c}function Jt(t,{getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){const{keys:r,records:c}=t,i=new Le({getFn:e,fieldNormWeight:n});return i.setKeys(r),i.setIndexRecords(c),i}function xe(t,{errors:e=0,currentLocation:n=0,expectedLocation:r=0,distance:c=y.distance,ignoreLocation:i=y.ignoreLocation}={}){const o=e/t.length;if(i)return o;const a=Math.abs(r-n);return c?o+a/c:a?1:o}function Xt(t=[],e=y.minMatchCharLength){let n=[],r=-1,c=-1,i=0;for(let o=t.length;i<o;i+=1){let a=t[i];a&&r===-1?r=i:!a&&r!==-1&&(c=i-1,c-r+1>=e&&n.push([r,c]),r=-1)}return t[i-1]&&i-r>=e&&n.push([r,i-1]),n}const le=32;function Zt(t,e,n,{location:r=y.location,distance:c=y.distance,threshold:i=y.threshold,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,includeMatches:u=y.includeMatches,ignoreLocation:l=y.ignoreLocation}={}){if(e.length>le)throw new Error(Pt(le));const h=e.length,E=t.length,x=Math.max(0,Math.min(r,E));let g=i,m=x;const S=a>1||u,w=S?Array(E):[];let T;for(;(T=t.indexOf(e,m))>-1;){let $=xe(e,{currentLocation:T,expectedLocation:x,distance:c,ignoreLocation:l});if(g=Math.min($,g),m=T+h,S){let N=0;for(;N<h;)w[T+N]=1,N+=1}}m=-1;let j=[],Q=1,W=h+E;const oe=1<<h-1;for(let $=0;$<h;$+=1){let N=0,D=W;for(;N<D;)xe(e,{errors:$,currentLocation:x+D,expectedLocation:x,distance:c,ignoreLocation:l})<=g?N=D:W=D,D=Math.floor((W-N)/2+N);W=D;let ae=Math.max(1,x-D+1),H=o?E:Math.min(x+D,E)+h,v=Array(H+2);v[H+1]=(1<<$)-1;for(let R=H;R>=ae;R-=1){let X=R-1,O=n[t.charAt(X)];if(S&&(w[X]=+!!O),v[R]=(v[R+1]<<1|1)&O,$&&(v[R]|=(j[R+1]|j[R])<<1|1|j[R+1]),v[R]&oe&&(Q=xe(e,{errors:$,currentLocation:X,expectedLocation:x,distance:c,ignoreLocation:l}),Q<=g)){if(g=Q,m=X,m<=x)break;ae=Math.max(1,2*x-m)}}if(xe(e,{errors:$+1,currentLocation:x,expectedLocation:x,distance:c,ignoreLocation:l})>g)break;j=v}const ce={isMatch:m>=0,score:Math.max(.001,Q)};if(S){const $=Xt(w,a);$.length?u&&(ce.indices=$):ce.isMatch=!1}return ce}function qt(t){let e={};for(let n=0,r=t.length;n<r;n+=1){const c=t.charAt(n);e[c]=(e[c]||0)|1<<r-n-1}return e}const Ce=String.prototype.normalize?(t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(t=>t);class ut{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:c=y.distance,includeMatches:i=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){if(this.options={location:n,threshold:r,distance:c,includeMatches:i,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h},e=u?e:e.toLowerCase(),e=l?Ce(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const E=(g,m)=>{this.chunks.push({pattern:g,alphabet:qt(g),startIndex:m})},x=this.pattern.length;if(x>le){let g=0;const m=x%le,S=x-m;for(;g<S;)E(this.pattern.substr(g,le),g),g+=le;if(m){const w=x-le;E(this.pattern.substr(w),w)}}else E(this.pattern,0)}searchIn(e){const{isCaseSensitive:n,ignoreDiacritics:r,includeMatches:c}=this.options;if(e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern===e){let S={isMatch:!0,score:0};return c&&(S.indices=[[0,e.length-1]]),S}const{location:i,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let E=[],x=0,g=!1;this.chunks.forEach(({pattern:S,alphabet:w,startIndex:T})=>{const{isMatch:j,score:Q,indices:W}=Zt(e,S,w,{location:i+T,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:c,ignoreLocation:h});j&&(g=!0),x+=Q,j&&W&&(E=[...E,...W])});let m={isMatch:g,score:g?x/this.chunks.length:1};return g&&c&&(m.indices=E),m}}class ie{constructor(e){this.pattern=e}static isMultiMatch(e){return qe(e,this.multiRegex)}static isSingleMatch(e){return qe(e,this.singleRegex)}search(){}}function qe(t,e){const n=t.match(e);return n?n[1]:null}class es extends ie{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const n=e===this.pattern;return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ts extends ie{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const r=e.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}}class ss extends ie{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const n=e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ns extends ie{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const n=!e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class rs extends ie{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const n=e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class cs extends ie{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const n=!e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class lt extends ie{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:c=y.distance,includeMatches:i=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){super(e),this._bitapSearch=new ut(e,{location:n,threshold:r,distance:c,includeMatches:i,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class ht extends ie{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let n=0,r;const c=[],i=this.pattern.length;for(;(r=e.indexOf(this.pattern,n))>-1;)n=r+i,c.push([r,n-1]);const o=!!c.length;return{isMatch:o,score:o?0:1,indices:c}}}const De=[es,ht,ss,ns,cs,rs,ts,lt],et=De.length,is=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,os="|";function as(t,e={}){return t.split(os).map(n=>{let r=n.trim().split(is).filter(i=>i&&!!i.trim()),c=[];for(let i=0,o=r.length;i<o;i+=1){const a=r[i];let u=!1,l=-1;for(;!u&&++l<et;){const h=De[l];let E=h.isMultiMatch(a);E&&(c.push(new h(E,e)),u=!0)}if(!u)for(l=-1;++l<et;){const h=De[l];let E=h.isSingleMatch(a);if(E){c.push(new h(E,e));break}}}return c})}const us=new Set([lt.type,ht.type]);class ls{constructor(e,{isCaseSensitive:n=y.isCaseSensitive,ignoreDiacritics:r=y.ignoreDiacritics,includeMatches:c=y.includeMatches,minMatchCharLength:i=y.minMatchCharLength,ignoreLocation:o=y.ignoreLocation,findAllMatches:a=y.findAllMatches,location:u=y.location,threshold:l=y.threshold,distance:h=y.distance}={}){this.query=null,this.options={isCaseSensitive:n,ignoreDiacritics:r,includeMatches:c,minMatchCharLength:i,findAllMatches:a,ignoreLocation:o,location:u,threshold:l,distance:h},e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern=e,this.query=as(this.pattern,this.options)}static condition(e,n){return n.useExtendedSearch}searchIn(e){const n=this.query;if(!n)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:c,ignoreDiacritics:i}=this.options;e=c?e:e.toLowerCase(),e=i?Ce(e):e;let o=0,a=[],u=0;for(let l=0,h=n.length;l<h;l+=1){const E=n[l];a.length=0,o=0;for(let x=0,g=E.length;x<g;x+=1){const m=E[x],{isMatch:S,indices:w,score:T}=m.search(e);if(S){if(o+=1,u+=T,r){const j=m.constructor.type;us.has(j)?a=[...a,...w]:a.push(w)}}else{u=0,o=0,a.length=0;break}}if(o){let x={isMatch:!0,score:u/o};return r&&(x.indices=a),x}}return{isMatch:!1,score:1}}}const ke=[];function hs(...t){ke.push(...t)}function Re(t,e){for(let n=0,r=ke.length;n<r;n+=1){let c=ke[n];if(c.condition(t,e))return new c(t,e)}return new ut(t,e)}const Me={AND:"$and",OR:"$or"},be={PATH:"$path",PATTERN:"$val"},Te=t=>!!(t[Me.AND]||t[Me.OR]),ds=t=>!!t[be.PATH],fs=t=>!re(t)&&ct(t)&&!Te(t),tt=t=>({[Me.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function dt(t,e,{auto:n=!0}={}){const r=c=>{let i=Object.keys(c);const o=ds(c);if(!o&&i.length>1&&!Te(c))return r(tt(c));if(fs(c)){const u=o?c[be.PATH]:i[0],l=o?c[be.PATTERN]:c[u];if(!q(l))throw new Error(Nt(u));const h={keyId:_e(u),pattern:l};return n&&(h.searcher=Re(l,e)),h}let a={children:[],operator:i[0]};return i.forEach(u=>{const l=c[u];re(l)&&l.forEach(h=>{a.children.push(r(h))})}),a};return Te(t)||(t=tt(t)),r(t)}function gs(t,{ignoreFieldNorm:e=y.ignoreFieldNorm}){t.forEach(n=>{let r=1;n.matches.forEach(({key:c,norm:i,score:o})=>{const a=c?c.weight:null;r*=Math.pow(o===0&&a?Number.EPSILON:o,(a||1)*(e?1:i))}),n.score=r})}function ms(t,e){const n=t.matches;e.matches=[],G(n)&&n.forEach(r=>{if(!G(r.indices)||!r.indices.length)return;const{indices:c,value:i}=r;let o={indices:c,value:i};r.key&&(o.key=r.key.src),r.idx>-1&&(o.refIndex=r.idx),e.matches.push(o)})}function ps(t,e){e.score=t.score}function As(t,e,{includeMatches:n=y.includeMatches,includeScore:r=y.includeScore}={}){const c=[];return n&&c.push(ms),r&&c.push(ps),t.map(i=>{const{idx:o}=i,a={item:e[o],refIndex:o};return c.length&&c.forEach(u=>{u(i,a)}),a})}class Z{constructor(e,n={},r){this.options={...y,...n},this.options.useExtendedSearch,this._keyStore=new zt(this.options.keys),this.setCollection(e,r)}setCollection(e,n){if(this._docs=e,n&&!(n instanceof Le))throw new Error(jt);this._myIndex=n||at(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){G(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const n=[];for(let r=0,c=this._docs.length;r<c;r+=1){const i=this._docs[r];e(i,r)&&(this.removeAt(r),r-=1,c-=1,n.push(i))}return n}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:n=-1}={}){const{includeMatches:r,includeScore:c,shouldSort:i,sortFn:o,ignoreFieldNorm:a}=this.options;let u=q(e)?q(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return gs(u,{ignoreFieldNorm:a}),i&&u.sort(o),rt(n)&&n>-1&&(u=u.slice(0,n)),As(u,this._docs,{includeMatches:r,includeScore:c})}_searchStringList(e){const n=Re(e,this.options),{records:r}=this._myIndex,c=[];return r.forEach(({v:i,i:o,n:a})=>{if(!G(i))return;const{isMatch:u,score:l,indices:h}=n.searchIn(i);u&&c.push({item:i,idx:o,matches:[{score:l,value:i,norm:a,indices:h}]})}),c}_searchLogical(e){const n=dt(e,this.options),r=(a,u,l)=>{if(!a.children){const{keyId:E,searcher:x}=a,g=this._findMatches({key:this._keyStore.get(E),value:this._myIndex.getValueForItemAtKeyId(u,E),searcher:x});return g&&g.length?[{idx:l,item:u,matches:g}]:[]}const h=[];for(let E=0,x=a.children.length;E<x;E+=1){const g=a.children[E],m=r(g,u,l);if(m.length)h.push(...m);else if(a.operator===Me.AND)return[]}return h},c=this._myIndex.records,i={},o=[];return c.forEach(({$:a,i:u})=>{if(G(a)){let l=r(n,a,u);l.length&&(i[u]||(i[u]={idx:u,item:a,matches:[]},o.push(i[u])),l.forEach(({matches:h})=>{i[u].matches.push(...h)}))}}),o}_searchObjectList(e){const n=Re(e,this.options),{keys:r,records:c}=this._myIndex,i=[];return c.forEach(({$:o,i:a})=>{if(!G(o))return;let u=[];r.forEach((l,h)=>{u.push(...this._findMatches({key:l,value:o[h],searcher:n}))}),u.length&&i.push({idx:a,item:o,matches:u})}),i}_findMatches({key:e,value:n,searcher:r}){if(!G(n))return[];let c=[];if(re(n))n.forEach(({v:i,i:o,n:a})=>{if(!G(i))return;const{isMatch:u,score:l,indices:h}=r.searchIn(i);u&&c.push({score:l,key:e,value:i,idx:o,norm:a,indices:h})});else{const{v:i,n:o}=n,{isMatch:a,score:u,indices:l}=r.searchIn(i);a&&c.push({score:u,key:e,value:i,norm:o,indices:l})}return c}}Z.version="7.1.0";Z.createIndex=at;Z.parseIndex=Jt;Z.config=y;Z.parseQuery=dt;hs(ls);async function ys(t){const e=new URLSearchParams({q:t}),n=await At(yt(`/api/folders/search?${e.toString()}`));if(!n.ok){const c=await n.json().catch(()=>({}));throw new Error(c.error||`Failed to search folders: ${n.statusText}`)}const r=await n.json();return Array.isArray(r.folders)?r.folders:[]}const Es=["command","agent","building","area","folder","modified-file"],xs=2;function Cs(){const t=nt(me.SPOTLIGHT_TAB,"all");return fe.includes(t)?t:"all"}function st(){return Rt(me.SPOTLIGHT_QUERY,"")}function Ms(){const t=nt(me.AOP_CONFIG,{});return t.sortMode==="name"||t.sortMode==="status"||t.sortMode==="recent"?t.sortMode:"recent"}function Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=Et(),E=xt(),x=Ct(),g=Mt(),m=Ft(),S=wt(),w=d.useRef(e);w.current=e;const T=d.useRef(n);T.current=n;const j=d.useRef(r);j.current=r;const Q=d.useRef(c);Q.current=c;const W=d.useRef(i);W.current=i;const oe=d.useRef(o);oe.current=o;const ce=d.useRef(a);ce.current=a;const $=d.useRef(u);$.current=u;const N=d.useRef(l);N.current=l;const[D,ae]=d.useState(st),[H,v]=d.useState(0),[M,R]=d.useState(Cs),[X,O]=d.useState([]),ft=d.useCallback(s=>{ae(s),St(me.SPOTLIGHT_QUERY,s)},[]);d.useEffect(()=>{t&&(ae(st()),v(0))},[t]),d.useEffect(()=>{if(!t){O([]);return}const s=D.trim();if(s.length<xs){O([]);return}let p=!1;const C=setTimeout(()=>{ys(s).then(F=>{p||O(F)}).catch(()=>{p||O([])})},250);return()=>{p=!0,clearTimeout(C)}},[t,D]);const we=d.useCallback(s=>{R(s),vt(me.SPOTLIGHT_TAB,s)},[]),$e=d.useRef(M);$e.current=M;const gt=d.useCallback(s=>{const p=fe.indexOf($e.current),C=fe[(p+s+fe.length)%fe.length];we(C)},[we]);d.useEffect(()=>{v(0)},[M]);const Se=J.getShortcuts(),ge=d.useMemo(()=>t?Bt():{},[t]),pe=d.useMemo(()=>{if(!t)return[];const s=Se.find(C=>C.id==="spawn-agent"),p=Se.find(C=>C.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:s?Ve(s):"Alt+N",icon:f.jsx(ne,{name:"plus",size:16}),action:()=>{w.current(),T.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:p?Ve(p):"Ctrl+K",icon:f.jsx(ne,{name:"dashboard",size:16}),action:()=>{w.current(),j.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:f.jsx(ne,{name:"gear",size:16}),action:()=>{w.current(),Q.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:f.jsx(ne,{name:"chart-line",size:16}),action:()=>{var C;w.current(),(C=N.current)==null||C.call(N)}}]},[t,Se]),he=d.useMemo(()=>t?Array.from(h.values()).map(s=>{const p=(g||[]).filter(Y=>Y.agentId===s.id).map(Y=>Y.filePath),C=[...new Set(p)],F=C.map(Y=>Y.split("/").pop()||Y),B=[];s.lastAssignedTask&&B.push(s.lastAssignedTask);const L=`${s.class} • ${s.cwd}`;let k=`${s.name} ${s.class} ${s.status} ${s.cwd}`;s.taskLabel&&(k+=` ${s.taskLabel}`),F.length>0&&(k+=` ${F.join(" ")} ${C.join(" ")}`),B.length>0&&(k+=` ${B.join(" ")}`);const P=Date.now()-s.lastActivity;let U;return s.lastAssignedTask&&(s.lastAssignedTask.length>150?U=s.lastAssignedTask.slice(0,150)+"...":U=s.lastAssignedTask),{id:`agent-${s.id}`,type:"agent",title:s.name,subtitle:L,lastUserInput:U,timeAway:P,icon:f.jsx(_t,{agent:s,size:20}),_searchText:k,_modifiedFiles:C,_userQueries:B,_agentId:s.id,_lastActivity:s.lastActivity,_taskLabel:s.taskLabel,_status:s.status,action:()=>{w.current(),It(s.id),J.selectAgent(s.id),J.getState().viewMode!=="flat"&&J.requestTerminalExpand()}}}):[],[t,h,g]),Ae=d.useMemo(()=>t?Array.from(E.values()).map(s=>{var p;return{id:`area-${s.id}`,type:"area",title:s.name,subtitle:`${s.assignedAgentIds.length} agents • ${((p=s.directories)==null?void 0:p.length)||0} folders`,icon:f.jsx(ne,{name:"map",size:16}),action:()=>{w.current(),J.selectArea(s.id)}}}):[],[t,E]),je=d.useMemo(()=>{const s=new Map;for(const p of he)p._agentId&&s.set(p._agentId,p);return s},[he]),Ne=d.useMemo(()=>{const s=new Map;if(!t)return s;for(const p of h.values()){const C=J.getAreaForAgent(p.id);if(!C||C.archived)continue;const F=s.get(C.id);F?F.push(p):s.set(C.id,[p])}return s},[t,h,E]),Pe=d.useMemo(()=>{const s=new Map;for(const p of m)s.has(p.agentId)||s.set(p.agentId,p.timestamp);return s},[m]),ve=d.useMemo(()=>{if(!t)return[];const s=D.trim().toLowerCase(),p=Dt({sortMode:Ms(),agentsWithUnseenOutput:S,getLatestToolTimestamp:B=>Pe.get(B)}),C=Array.from(E.values()).filter(B=>!B.archived).filter(B=>s?B.name.toLowerCase().includes(s):!0).sort((B,L)=>B.name.localeCompare(L.name,void 0,{sensitivity:"base"})),F=[];for(const B of C){const k=(Ne.get(B.id)||[]).slice().sort(p).map(P=>je.get(P.id)).filter(P=>!!P);!s&&k.length===0||F.push({areaId:B.id,areaName:B.name,areaColor:B.color,agents:k})}return F},[t,D,E,Ne,je,S,Pe]),ye=d.useMemo(()=>t?Array.from(x.values()).filter(s=>s.type==="server"||s.type==="boss"||s.type==="database"||s.type==="tests").map(s=>{var P,U,Y,ue,ee;const p=s.status==="running"?"#4ade80":s.status==="stopped"?"#f87171":"#facc15",C=s.type==="boss"?"crown":s.type==="database"?"database":s.type==="tests"?"flask":"desktop",F=s.type==="boss"?"Boss":s.type==="database"?"Database":s.type==="tests"?"Tests":"Server";let B=`${F} • ${s.status}`;if(s.type==="database"&&((U=(P=s.database)==null?void 0:P.connections)!=null&&U.length)){const z=s.database.connections[0];B+=` • ${z.engine} @ ${z.host}`}else s.type==="tests"&&s.folderPath?B=`${F} • ${s.folderPath}`:s.cwd&&(B+=` • ${s.cwd}`);const L=((Y=s.pm2Status)==null?void 0:Y.ports)||[];let k=`${s.name} ${s.type} ${s.status} ${s.cwd||""} ${((ue=s.pm2)==null?void 0:ue.name)||""}`;if(s.type==="tests"&&(k+=` ${s.folderPath||""} tests junit maven`),L.length>0&&(k+=` ${L.join(" ")}`),s.type==="database"&&((ee=s.database)!=null&&ee.connections))for(const z of s.database.connections)k+=` ${z.name} ${z.engine} ${z.host} ${z.database||""} mysql postgresql sql`;return{id:`building-${s.id}`,type:"building",title:s.name,subtitle:B,_ports:L,icon:f.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[f.jsx(ne,{name:"status-pending",size:10,weight:"fill",color:p}),f.jsx(ne,{name:C,size:16})]}),_searchText:k,action:()=>{var z;w.current(),s.type==="boss"?ce.current(s.id):s.type==="database"?$.current(s.id):s.type==="tests"?J.openTestsBuilding(s.id):(z=s.pm2)!=null&&z.enabled&&oe.current(s.id)}}}):[],[t,x]),Ke=d.useMemo(()=>{if(!t)return[];const s=g||[],p=new Set,C=[];for(const F of s){if(p.has(F.filePath))continue;p.add(F.filePath);const B=F.filePath.split("/").pop()||F.filePath,L=F.action==="created"?"Created":F.action==="modified"?"Modified":F.action==="deleted"?"Deleted":"Read";if(C.push({id:`modified-${F.filePath}-${F.timestamp}`,type:"modified-file",title:B,subtitle:`${L} by ${F.agentName} • ${F.filePath}`,matchedText:F.filePath,icon:F.action==="deleted"?f.jsx(ne,{name:"trash",size:16}):kt(F.filePath),action:()=>{w.current();const k=Array.from(J.getState().areas.values());for(const P of k)for(const U of P.directories||[])if(F.filePath.startsWith(U)){J.setFileViewerPath(F.filePath),W.current(P.id);return}J.selectAgent(F.agentId)}}),C.length>=50)break}return C},[t,g]),Oe=d.useMemo(()=>t?X.map(s=>{const p=s.isGitRepo&&s.gitBranch?`${s.path} • ${s.gitBranch}`:s.path;return{id:`folder-${s.path}`,type:"folder",title:s.name,subtitle:p,matchedText:s.path,icon:f.jsx(ne,{name:s.isGitRepo?"git-branch":"folder",size:16}),_searchText:`${s.name} ${s.path}`,_isGitRepo:s.isGitRepo,_gitBranch:s.gitBranch,action:()=>{w.current(),J.openFileExplorer(s.path)}}}):[],[t,X]),ze=d.useMemo(()=>new Z(he,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[he]),Ge=d.useMemo(()=>new Z(pe,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[pe]),Qe=d.useMemo(()=>new Z(Ae,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[Ae]),We=d.useMemo(()=>new Z(Ke,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[Ke]),He=d.useMemo(()=>new Z(ye,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ye]),de=d.useMemo(()=>{if(!D.trim()){const A=[];A.push(...ye);const I=[...he].sort((b,K)=>{const te=Ee(b._agentId,b._lastActivity,ge);return Ee(K._agentId,K._lastActivity,ge)-te});A.push(...I),A.push(...pe.slice(0,2)),A.push(...Ae.slice(0,2));const _={};return Es.forEach((b,K)=>{_[b]=K}),A.sort((b,K)=>(_[b.type]??999)-(_[K.type]??999)),A}const s=D.trim().toLowerCase(),p=ze.search(D).slice(0,8),C=Ge.search(D).slice(0,3),F=Qe.search(D).slice(0,2),B=We.search(D).slice(0,3),L=Oe.slice(0,8),k=He.search(D).filter(A=>{const I=A.score??1;return`${A.item.title} ${A.item.subtitle||""} ${A.item._searchText||""}`.toLowerCase().includes(s)||I<=.2}).slice(0,4),P={agent:6,building:5,folder:4,command:3,area:2,"modified-file":1},U=A=>{if(!s)return 1;const I=A.title.toLowerCase();return I===s?6:I.startsWith(s)?5:I.split(/[^a-z0-9]+/i).includes(s)?4:I.includes(s)?3:`${A.subtitle||""} ${A._searchText||""} ${A.matchedText||""}`.toLowerCase().includes(s)?2:1},Y=(A,I)=>{const _=(1-Math.min(1,I??1))*4;return U(A)*100+(P[A.type]??0)*5+_},ue=new Map,ee=(A,I)=>{const _=ue.get(A.type),b={item:A,score:Y(A,I)};_?_.push(b):ue.set(A.type,[b])};for(const A of p){const I={...A.item};if(I._modifiedFiles&&I._modifiedFiles.length>0){const _=I._modifiedFiles.filter(b=>{var se;const K=((se=b.split("/").pop())==null?void 0:se.toLowerCase())||"",te=b.toLowerCase();return K.includes(s)||te.includes(s)});_.length>0&&(I.matchedFiles=_)}if(I._userQueries&&I._userQueries.length>0){const _=I._userQueries.find(b=>b.toLowerCase().includes(s));if(_)if(_.length>200){const K=_.toLowerCase().indexOf(s),te=Math.max(0,K-60),se=Math.min(_.length,K+s.length+100);I.matchedQuery=(te>0?"...":"")+_.slice(te,se)+(se<_.length?"...":"")}else I.matchedQuery=_}ee(I,A.score)}for(const A of k)ee(A.item,A.score);for(const A of C)ee(A.item,A.score);for(const A of F)ee(A.item,A.score);for(const A of B)ee(A.item,A.score);for(const A of L)ee(A,void 0);for(const[A,I]of ue)A==="agent"?I.sort((_,b)=>{const K=U(_.item),te=U(b.item);if(te!==K)return te-K;const se=Ee(_.item._agentId,_.item._lastActivity,ge),Ye=Ee(b.item._agentId,b.item._lastActivity,ge);return Ye!==se?Ye-se:b.score-_.score}):I.sort((_,b)=>b.score-_.score);const z=A=>A.reduce((I,_)=>Math.max(I,_.score),-1),Ue=[];return Array.from(ue.values()).sort((A,I)=>z(I)-z(A)).forEach(A=>{for(const I of A)Ue.push(I.item)}),Ue},[D,ze,Ge,Qe,We,He,pe,he,Ae,ye,Oe,ge]),V=d.useMemo(()=>{switch(M){case"agents":return de.filter(s=>s.type==="agent");case"buildings":return de.filter(s=>s.type==="building");case"commands":return de.filter(s=>s.type==="command");case"folders":return de.filter(s=>s.type==="folder");case"areas":return ve.flatMap(s=>s.agents);case"all":default:return de}},[M,de,ve]);d.useEffect(()=>{H>=V.length&&v(Math.max(0,V.length-1))},[V.length,H]);const mt=d.useCallback(s=>{if(s.altKey&&!s.ctrlKey&&!s.metaKey&&(s.key==="p"||s.key==="n"||s.key==="P"||s.key==="N")){s.preventDefault(),s.stopPropagation(),s.nativeEvent.stopImmediatePropagation();const p=s.key.toLowerCase();v(p==="p"?C=>C>0?C-1:V.length-1:C=>C<V.length-1?C+1:0);return}switch(s.key){case"Escape":s.preventDefault(),w.current();break;case"ArrowUp":s.preventDefault(),v(p=>p>0?p-1:V.length-1);break;case"ArrowDown":s.preventDefault(),v(p=>p<V.length-1?p+1:0);break;case"Enter":s.preventDefault(),V[H]&&V[H].action();break}},[V,H]),pt=d.useCallback((s,p)=>{if(!p||!s)return s;const C=s.toLowerCase(),F=p.toLowerCase(),B=[];let L=0,k=C.indexOf(F),P=0;for(;k!==-1;)k>L&&B.push(s.slice(L,k)),B.push(Be.createElement("mark",{key:P++,className:"spotlight-highlight"},s.slice(k,k+p.length))),L=k+p.length,k=C.indexOf(F,L);return L<s.length&&B.push(s.slice(L)),B.length>0?Be.createElement(Be.Fragment,null,...B):s},[]);return{query:D,setQuery:ft,selectedIndex:H,setSelectedIndex:v,results:V,activeTab:M,setActiveTab:we,cycleTab:gt,areaSections:ve,handleKeyDown:mt,highlightMatch:pt}}const ws=d.forwardRef(function({query:e,onQueryChange:n,onKeyDown:r,onResetSelection:c},i){const{t:o}=Fe(["common"]);return f.jsxs("div",{className:"spotlight-input-wrapper",children:[f.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),f.jsx("input",{ref:i,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:a=>{n(a.target.value),c()},onKeyDown:r,autoFocus:!0,spellCheck:!1}),f.jsxs("div",{className:"spotlight-input-hints",children:[f.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Ss=d.memo(function({activeTab:e,onSelect:n}){const{t:r}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-tabs",role:"tablist","aria-label":r("terminal:spotlight.tabsLabel"),children:[fe.map(c=>f.jsx("button",{type:"button",role:"tab","aria-selected":c===e,tabIndex:-1,className:`spotlight-tab${c===e?" active":""}`,onClick:()=>n(c),children:r(`terminal:spotlight.tabs.${c}`)},c)),f.jsx("span",{className:"spotlight-tabs-hint",children:f.jsx("kbd",{children:"Tab"})})]})}),vs=d.forwardRef(function({results:e,selectedIndex:n,query:r,activeTab:c,areaSections:i,highlightMatch:o,onSelectIndex:a},u){const{t:l}=Fe(["terminal"]),h=d.useRef(!1);d.useEffect(()=>{h.current=!1},[e]),d.useEffect(()=>{const g=typeof u=="function"?null:u==null?void 0:u.current;if(!g)return;const m=()=>{h.current=!0};return g.addEventListener("mousemove",m),()=>{g.removeEventListener("mousemove",m)}},[u,e]);const E={command:l("terminal:spotlight.categories.commands"),agent:l("terminal:spotlight.categories.agents"),building:l("terminal:spotlight.categories.infrastructure"),area:l("terminal:spotlight.categories.areas"),folder:l("terminal:spotlight.categories.folders"),"modified-file":l("terminal:spotlight.categories.modifiedFiles")},x=d.useMemo(()=>{const g=[];let m=null,S=[];return e.forEach((w,T)=>{w.type!==m&&(m!==null&&S.length>0&&g.push([m,S]),m=w.type,S=[]),S.push({result:w,index:T})}),m!==null&&S.length>0&&g.push([m,S]),g},[e]);if(d.useEffect(()=>{if(!u||typeof u=="function")return;const g=u.current;if(!g)return;const m=g.querySelector(".spotlight-item.selected");m&&m.scrollIntoView({block:"nearest",behavior:"smooth"})},[n,u]),c==="areas"){if(i.length===0)return f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})});let g=0;return f.jsx("div",{className:"spotlight-results",ref:u,children:i.map(m=>f.jsxs("div",{children:[f.jsxs("div",{className:"spotlight-category-header spotlight-area-section-header",children:[f.jsx("span",{className:"spotlight-area-dot",style:{background:m.areaColor},"aria-hidden":"true"}),f.jsx("span",{className:"spotlight-area-name",children:m.areaName}),f.jsx("span",{className:"spotlight-area-count",children:m.agents.length})]}),m.agents.length===0?f.jsx("div",{className:"spotlight-area-empty",children:l("terminal:spotlight.noAgentsInArea")}):m.agents.map(S=>{const w=g++;return f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id)})]},m.areaId))})}return e.length===0?f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})}):f.jsx("div",{className:"spotlight-results",ref:u,children:x.map(([g,m])=>f.jsxs("div",{children:[x.length>1&&f.jsx("div",{className:"spotlight-category-header",children:E[g]||g}),m.map(({result:S,index:w})=>f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id))]},g))})}),Bs=d.memo(function(){const{t:e}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-footer",children:[f.jsxs("div",{className:"spotlight-footer-left",children:[f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"↑"}),f.jsx("kbd",{children:"↓"})," ",f.jsx("kbd",{children:"Alt+N"}),f.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Tab"})," ",e("terminal:spotlight.switchTabs")]})]}),f.jsx("div",{className:"spotlight-footer-right",children:f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),Is=768;function Rs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=d.useRef(null),E=d.useRef(null),x=d.useRef(null),g=d.useRef(0),{query:m,setQuery:S,selectedIndex:w,setSelectedIndex:T,results:j,activeTab:Q,setActiveTab:W,cycleTab:oe,areaSections:ce,handleKeyDown:$,highlightMatch:N}=Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});g.current=j.length;const D=d.useRef(oe);D.current=oe,d.useEffect(()=>{t&&setTimeout(()=>{var v,M;(v=h.current)==null||v.focus(),(M=h.current)==null||M.select()},50)},[t]),d.useEffect(()=>{if(!t)return;const v=window.visualViewport;if(!v||window.innerWidth>Is)return;const M=()=>{const R=E.current;R&&(R.style.height=`${v.height}px`,R.style.top=`${v.offsetTop}px`)};return M(),v.addEventListener("resize",M),v.addEventListener("scroll",M),()=>{v.removeEventListener("resize",M),v.removeEventListener("scroll",M);const R=E.current;R&&(R.style.height="",R.style.top="")}},[t]),d.useEffect(()=>{if(!t)return;const v=M=>{if(M.key==="Escape"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),e();return}if(M.key==="Tab"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),D.current(M.shiftKey?-1:1);return}if(M.altKey&&!M.ctrlKey&&!M.metaKey&&(M.key==="n"||M.key==="p"||M.key==="N"||M.key==="P")){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation();const R=M.key.toLowerCase(),X=g.current;T(R==="p"?O=>O>0?O-1:X-1:O=>O<X-1?O+1:0);return}};return window.addEventListener("keydown",v,{capture:!0}),()=>{window.removeEventListener("keydown",v,{capture:!0})}},[t,e]);const ae=d.useCallback(v=>{v.target===v.currentTarget&&e()},[e]),H=d.useCallback(()=>{T(0)},[T]);return t?f.jsx("div",{ref:E,className:"spotlight-overlay",onClick:ae,children:f.jsxs("div",{className:"spotlight-modal",children:[f.jsx(ws,{ref:h,query:m,onQueryChange:S,onKeyDown:$,onResetSelection:H}),f.jsx(Ss,{activeTab:Q,onSelect:W}),f.jsx(vs,{ref:x,results:j,selectedIndex:w,query:m,activeTab:Q,areaSections:ce,highlightMatch:N,onSelectIndex:T}),f.jsx(Bs,{})]})}):null}export{Ls as FILE_ICON_NAMES,Rs as Spotlight,Bs as SpotlightFooter,ws as SpotlightInput,Je as SpotlightItem,vs as SpotlightResults,$s as formatDuration,js as formatRelativeTime,Ns as getAgentIcon,kt as getFileIconFromPath,Ps as getTypeLabel,Fs as useSpotlightSearch};
1
+ import{h as At,i as yt,aw as Et,a1 as xt,a2 as Ct,c9 as Mt,ca as Ft,aF as wt,r as d,X as St,S as me,cb as vt,cc as fe,s as J,cd as Bt,j as f,I as ne,ce as Ve,cf as It,a6 as _t,cg as Dt,ch as kt,ci as Ee,al as Be,W as Rt,p as nt,u as Fe,cj as Je}from"./main-DffU4pm2.js";import{ck as Ls,cl as $s,cm as js,cn as Ns,co as Ps}from"./main-DffU4pm2.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function re(t){return Array.isArray?Array.isArray(t):it(t)==="[object Array]"}function bt(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Tt(t){return t==null?"":bt(t)}function q(t){return typeof t=="string"}function rt(t){return typeof t=="number"}function Lt(t){return t===!0||t===!1||$t(t)&&it(t)=="[object Boolean]"}function ct(t){return typeof t=="object"}function $t(t){return ct(t)&&t!==null}function G(t){return t!=null}function Ie(t){return!t.trim().length}function it(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const jt="Incorrect 'index' type",Nt=t=>`Invalid value for key ${t}`,Pt=t=>`Pattern length exceeds max of ${t}.`,Kt=t=>`Missing ${t} property in key`,Ot=t=>`Property 'weight' in key '${t}' must be a positive integer`,Xe=Object.prototype.hasOwnProperty;class zt{constructor(e){this._keys=[],this._keyMap={};let n=0;e.forEach(r=>{let c=ot(r);this._keys.push(c),this._keyMap[c.id]=c,n+=c.weight}),this._keys.forEach(r=>{r.weight/=n})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function ot(t){let e=null,n=null,r=null,c=1,i=null;if(q(t)||re(t))r=t,e=Ze(t),n=_e(t);else{if(!Xe.call(t,"name"))throw new Error(Kt("name"));const o=t.name;if(r=o,Xe.call(t,"weight")&&(c=t.weight,c<=0))throw new Error(Ot(o));e=Ze(o),n=_e(o),i=t.getFn}return{path:e,id:n,weight:c,src:r,getFn:i}}function Ze(t){return re(t)?t:t.split(".")}function _e(t){return re(t)?t.join("."):t}function Gt(t,e){let n=[],r=!1;const c=(i,o,a)=>{if(G(i))if(!o[a])n.push(i);else{let u=o[a];const l=i[u];if(!G(l))return;if(a===o.length-1&&(q(l)||rt(l)||Lt(l)))n.push(Tt(l));else if(re(l)){r=!0;for(let h=0,E=l.length;h<E;h+=1)c(l[h],o,a+1)}else o.length&&c(l,o,a+1)}};return c(t,q(e)?e.split("."):e,0),r?n:n[0]}const Qt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Wt={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},Ht={location:0,threshold:.6,distance:100},Ut={useExtendedSearch:!1,getFn:Gt,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var y={...Wt,...Qt,...Ht,...Ut};const Yt=/[^ ]+/g;function Vt(t=1,e=3){const n=new Map,r=Math.pow(10,e);return{get(c){const i=c.match(Yt).length;if(n.has(i))return n.get(i);const o=1/Math.pow(i,.5*t),a=parseFloat(Math.round(o*r)/r);return n.set(i,a),a},clear(){n.clear()}}}class Le{constructor({getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){this.norm=Vt(n,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((n,r)=>{this._keysMap[n.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,q(this.docs[0])?this.docs.forEach((e,n)=>{this._addString(e,n)}):this.docs.forEach((e,n)=>{this._addObject(e,n)}),this.norm.clear())}add(e){const n=this.size();q(e)?this._addString(e,n):this._addObject(e,n)}removeAt(e){this.records.splice(e,1);for(let n=e,r=this.size();n<r;n+=1)this.records[n].i-=1}getValueForItemAtKeyId(e,n){return e[this._keysMap[n]]}size(){return this.records.length}_addString(e,n){if(!G(e)||Ie(e))return;let r={v:e,i:n,n:this.norm.get(e)};this.records.push(r)}_addObject(e,n){let r={i:n,$:{}};this.keys.forEach((c,i)=>{let o=c.getFn?c.getFn(e):this.getFn(e,c.path);if(G(o)){if(re(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(G(h))if(q(h)&&!Ie(h)){let E={v:h,i:l,n:this.norm.get(h)};a.push(E)}else re(h)&&h.forEach((E,x)=>{u.push({nestedArrIndex:x,value:E})})}r.$[i]=a}else if(q(o)&&!Ie(o)){let a={v:o,n:this.norm.get(o)};r.$[i]=a}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function at(t,e,{getFn:n=y.getFn,fieldNormWeight:r=y.fieldNormWeight}={}){const c=new Le({getFn:n,fieldNormWeight:r});return c.setKeys(t.map(ot)),c.setSources(e),c.create(),c}function Jt(t,{getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){const{keys:r,records:c}=t,i=new Le({getFn:e,fieldNormWeight:n});return i.setKeys(r),i.setIndexRecords(c),i}function xe(t,{errors:e=0,currentLocation:n=0,expectedLocation:r=0,distance:c=y.distance,ignoreLocation:i=y.ignoreLocation}={}){const o=e/t.length;if(i)return o;const a=Math.abs(r-n);return c?o+a/c:a?1:o}function Xt(t=[],e=y.minMatchCharLength){let n=[],r=-1,c=-1,i=0;for(let o=t.length;i<o;i+=1){let a=t[i];a&&r===-1?r=i:!a&&r!==-1&&(c=i-1,c-r+1>=e&&n.push([r,c]),r=-1)}return t[i-1]&&i-r>=e&&n.push([r,i-1]),n}const le=32;function Zt(t,e,n,{location:r=y.location,distance:c=y.distance,threshold:i=y.threshold,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,includeMatches:u=y.includeMatches,ignoreLocation:l=y.ignoreLocation}={}){if(e.length>le)throw new Error(Pt(le));const h=e.length,E=t.length,x=Math.max(0,Math.min(r,E));let g=i,m=x;const S=a>1||u,w=S?Array(E):[];let T;for(;(T=t.indexOf(e,m))>-1;){let $=xe(e,{currentLocation:T,expectedLocation:x,distance:c,ignoreLocation:l});if(g=Math.min($,g),m=T+h,S){let N=0;for(;N<h;)w[T+N]=1,N+=1}}m=-1;let j=[],Q=1,W=h+E;const oe=1<<h-1;for(let $=0;$<h;$+=1){let N=0,D=W;for(;N<D;)xe(e,{errors:$,currentLocation:x+D,expectedLocation:x,distance:c,ignoreLocation:l})<=g?N=D:W=D,D=Math.floor((W-N)/2+N);W=D;let ae=Math.max(1,x-D+1),H=o?E:Math.min(x+D,E)+h,v=Array(H+2);v[H+1]=(1<<$)-1;for(let R=H;R>=ae;R-=1){let X=R-1,O=n[t.charAt(X)];if(S&&(w[X]=+!!O),v[R]=(v[R+1]<<1|1)&O,$&&(v[R]|=(j[R+1]|j[R])<<1|1|j[R+1]),v[R]&oe&&(Q=xe(e,{errors:$,currentLocation:X,expectedLocation:x,distance:c,ignoreLocation:l}),Q<=g)){if(g=Q,m=X,m<=x)break;ae=Math.max(1,2*x-m)}}if(xe(e,{errors:$+1,currentLocation:x,expectedLocation:x,distance:c,ignoreLocation:l})>g)break;j=v}const ce={isMatch:m>=0,score:Math.max(.001,Q)};if(S){const $=Xt(w,a);$.length?u&&(ce.indices=$):ce.isMatch=!1}return ce}function qt(t){let e={};for(let n=0,r=t.length;n<r;n+=1){const c=t.charAt(n);e[c]=(e[c]||0)|1<<r-n-1}return e}const Ce=String.prototype.normalize?(t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(t=>t);class ut{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:c=y.distance,includeMatches:i=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){if(this.options={location:n,threshold:r,distance:c,includeMatches:i,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h},e=u?e:e.toLowerCase(),e=l?Ce(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const E=(g,m)=>{this.chunks.push({pattern:g,alphabet:qt(g),startIndex:m})},x=this.pattern.length;if(x>le){let g=0;const m=x%le,S=x-m;for(;g<S;)E(this.pattern.substr(g,le),g),g+=le;if(m){const w=x-le;E(this.pattern.substr(w),w)}}else E(this.pattern,0)}searchIn(e){const{isCaseSensitive:n,ignoreDiacritics:r,includeMatches:c}=this.options;if(e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern===e){let S={isMatch:!0,score:0};return c&&(S.indices=[[0,e.length-1]]),S}const{location:i,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let E=[],x=0,g=!1;this.chunks.forEach(({pattern:S,alphabet:w,startIndex:T})=>{const{isMatch:j,score:Q,indices:W}=Zt(e,S,w,{location:i+T,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:c,ignoreLocation:h});j&&(g=!0),x+=Q,j&&W&&(E=[...E,...W])});let m={isMatch:g,score:g?x/this.chunks.length:1};return g&&c&&(m.indices=E),m}}class ie{constructor(e){this.pattern=e}static isMultiMatch(e){return qe(e,this.multiRegex)}static isSingleMatch(e){return qe(e,this.singleRegex)}search(){}}function qe(t,e){const n=t.match(e);return n?n[1]:null}class es extends ie{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const n=e===this.pattern;return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ts extends ie{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const r=e.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}}class ss extends ie{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const n=e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ns extends ie{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const n=!e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class rs extends ie{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const n=e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class cs extends ie{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const n=!e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class lt extends ie{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:c=y.distance,includeMatches:i=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){super(e),this._bitapSearch=new ut(e,{location:n,threshold:r,distance:c,includeMatches:i,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class ht extends ie{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let n=0,r;const c=[],i=this.pattern.length;for(;(r=e.indexOf(this.pattern,n))>-1;)n=r+i,c.push([r,n-1]);const o=!!c.length;return{isMatch:o,score:o?0:1,indices:c}}}const De=[es,ht,ss,ns,cs,rs,ts,lt],et=De.length,is=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,os="|";function as(t,e={}){return t.split(os).map(n=>{let r=n.trim().split(is).filter(i=>i&&!!i.trim()),c=[];for(let i=0,o=r.length;i<o;i+=1){const a=r[i];let u=!1,l=-1;for(;!u&&++l<et;){const h=De[l];let E=h.isMultiMatch(a);E&&(c.push(new h(E,e)),u=!0)}if(!u)for(l=-1;++l<et;){const h=De[l];let E=h.isSingleMatch(a);if(E){c.push(new h(E,e));break}}}return c})}const us=new Set([lt.type,ht.type]);class ls{constructor(e,{isCaseSensitive:n=y.isCaseSensitive,ignoreDiacritics:r=y.ignoreDiacritics,includeMatches:c=y.includeMatches,minMatchCharLength:i=y.minMatchCharLength,ignoreLocation:o=y.ignoreLocation,findAllMatches:a=y.findAllMatches,location:u=y.location,threshold:l=y.threshold,distance:h=y.distance}={}){this.query=null,this.options={isCaseSensitive:n,ignoreDiacritics:r,includeMatches:c,minMatchCharLength:i,findAllMatches:a,ignoreLocation:o,location:u,threshold:l,distance:h},e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern=e,this.query=as(this.pattern,this.options)}static condition(e,n){return n.useExtendedSearch}searchIn(e){const n=this.query;if(!n)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:c,ignoreDiacritics:i}=this.options;e=c?e:e.toLowerCase(),e=i?Ce(e):e;let o=0,a=[],u=0;for(let l=0,h=n.length;l<h;l+=1){const E=n[l];a.length=0,o=0;for(let x=0,g=E.length;x<g;x+=1){const m=E[x],{isMatch:S,indices:w,score:T}=m.search(e);if(S){if(o+=1,u+=T,r){const j=m.constructor.type;us.has(j)?a=[...a,...w]:a.push(w)}}else{u=0,o=0,a.length=0;break}}if(o){let x={isMatch:!0,score:u/o};return r&&(x.indices=a),x}}return{isMatch:!1,score:1}}}const ke=[];function hs(...t){ke.push(...t)}function Re(t,e){for(let n=0,r=ke.length;n<r;n+=1){let c=ke[n];if(c.condition(t,e))return new c(t,e)}return new ut(t,e)}const Me={AND:"$and",OR:"$or"},be={PATH:"$path",PATTERN:"$val"},Te=t=>!!(t[Me.AND]||t[Me.OR]),ds=t=>!!t[be.PATH],fs=t=>!re(t)&&ct(t)&&!Te(t),tt=t=>({[Me.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function dt(t,e,{auto:n=!0}={}){const r=c=>{let i=Object.keys(c);const o=ds(c);if(!o&&i.length>1&&!Te(c))return r(tt(c));if(fs(c)){const u=o?c[be.PATH]:i[0],l=o?c[be.PATTERN]:c[u];if(!q(l))throw new Error(Nt(u));const h={keyId:_e(u),pattern:l};return n&&(h.searcher=Re(l,e)),h}let a={children:[],operator:i[0]};return i.forEach(u=>{const l=c[u];re(l)&&l.forEach(h=>{a.children.push(r(h))})}),a};return Te(t)||(t=tt(t)),r(t)}function gs(t,{ignoreFieldNorm:e=y.ignoreFieldNorm}){t.forEach(n=>{let r=1;n.matches.forEach(({key:c,norm:i,score:o})=>{const a=c?c.weight:null;r*=Math.pow(o===0&&a?Number.EPSILON:o,(a||1)*(e?1:i))}),n.score=r})}function ms(t,e){const n=t.matches;e.matches=[],G(n)&&n.forEach(r=>{if(!G(r.indices)||!r.indices.length)return;const{indices:c,value:i}=r;let o={indices:c,value:i};r.key&&(o.key=r.key.src),r.idx>-1&&(o.refIndex=r.idx),e.matches.push(o)})}function ps(t,e){e.score=t.score}function As(t,e,{includeMatches:n=y.includeMatches,includeScore:r=y.includeScore}={}){const c=[];return n&&c.push(ms),r&&c.push(ps),t.map(i=>{const{idx:o}=i,a={item:e[o],refIndex:o};return c.length&&c.forEach(u=>{u(i,a)}),a})}class Z{constructor(e,n={},r){this.options={...y,...n},this.options.useExtendedSearch,this._keyStore=new zt(this.options.keys),this.setCollection(e,r)}setCollection(e,n){if(this._docs=e,n&&!(n instanceof Le))throw new Error(jt);this._myIndex=n||at(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){G(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const n=[];for(let r=0,c=this._docs.length;r<c;r+=1){const i=this._docs[r];e(i,r)&&(this.removeAt(r),r-=1,c-=1,n.push(i))}return n}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:n=-1}={}){const{includeMatches:r,includeScore:c,shouldSort:i,sortFn:o,ignoreFieldNorm:a}=this.options;let u=q(e)?q(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return gs(u,{ignoreFieldNorm:a}),i&&u.sort(o),rt(n)&&n>-1&&(u=u.slice(0,n)),As(u,this._docs,{includeMatches:r,includeScore:c})}_searchStringList(e){const n=Re(e,this.options),{records:r}=this._myIndex,c=[];return r.forEach(({v:i,i:o,n:a})=>{if(!G(i))return;const{isMatch:u,score:l,indices:h}=n.searchIn(i);u&&c.push({item:i,idx:o,matches:[{score:l,value:i,norm:a,indices:h}]})}),c}_searchLogical(e){const n=dt(e,this.options),r=(a,u,l)=>{if(!a.children){const{keyId:E,searcher:x}=a,g=this._findMatches({key:this._keyStore.get(E),value:this._myIndex.getValueForItemAtKeyId(u,E),searcher:x});return g&&g.length?[{idx:l,item:u,matches:g}]:[]}const h=[];for(let E=0,x=a.children.length;E<x;E+=1){const g=a.children[E],m=r(g,u,l);if(m.length)h.push(...m);else if(a.operator===Me.AND)return[]}return h},c=this._myIndex.records,i={},o=[];return c.forEach(({$:a,i:u})=>{if(G(a)){let l=r(n,a,u);l.length&&(i[u]||(i[u]={idx:u,item:a,matches:[]},o.push(i[u])),l.forEach(({matches:h})=>{i[u].matches.push(...h)}))}}),o}_searchObjectList(e){const n=Re(e,this.options),{keys:r,records:c}=this._myIndex,i=[];return c.forEach(({$:o,i:a})=>{if(!G(o))return;let u=[];r.forEach((l,h)=>{u.push(...this._findMatches({key:l,value:o[h],searcher:n}))}),u.length&&i.push({idx:a,item:o,matches:u})}),i}_findMatches({key:e,value:n,searcher:r}){if(!G(n))return[];let c=[];if(re(n))n.forEach(({v:i,i:o,n:a})=>{if(!G(i))return;const{isMatch:u,score:l,indices:h}=r.searchIn(i);u&&c.push({score:l,key:e,value:i,idx:o,norm:a,indices:h})});else{const{v:i,n:o}=n,{isMatch:a,score:u,indices:l}=r.searchIn(i);a&&c.push({score:u,key:e,value:i,norm:o,indices:l})}return c}}Z.version="7.1.0";Z.createIndex=at;Z.parseIndex=Jt;Z.config=y;Z.parseQuery=dt;hs(ls);async function ys(t){const e=new URLSearchParams({q:t}),n=await At(yt(`/api/folders/search?${e.toString()}`));if(!n.ok){const c=await n.json().catch(()=>({}));throw new Error(c.error||`Failed to search folders: ${n.statusText}`)}const r=await n.json();return Array.isArray(r.folders)?r.folders:[]}const Es=["command","agent","building","area","folder","modified-file"],xs=2;function Cs(){const t=nt(me.SPOTLIGHT_TAB,"all");return fe.includes(t)?t:"all"}function st(){return Rt(me.SPOTLIGHT_QUERY,"")}function Ms(){const t=nt(me.AOP_CONFIG,{});return t.sortMode==="name"||t.sortMode==="status"||t.sortMode==="recent"?t.sortMode:"recent"}function Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=Et(),E=xt(),x=Ct(),g=Mt(),m=Ft(),S=wt(),w=d.useRef(e);w.current=e;const T=d.useRef(n);T.current=n;const j=d.useRef(r);j.current=r;const Q=d.useRef(c);Q.current=c;const W=d.useRef(i);W.current=i;const oe=d.useRef(o);oe.current=o;const ce=d.useRef(a);ce.current=a;const $=d.useRef(u);$.current=u;const N=d.useRef(l);N.current=l;const[D,ae]=d.useState(st),[H,v]=d.useState(0),[M,R]=d.useState(Cs),[X,O]=d.useState([]),ft=d.useCallback(s=>{ae(s),St(me.SPOTLIGHT_QUERY,s)},[]);d.useEffect(()=>{t&&(ae(st()),v(0))},[t]),d.useEffect(()=>{if(!t){O([]);return}const s=D.trim();if(s.length<xs){O([]);return}let p=!1;const C=setTimeout(()=>{ys(s).then(F=>{p||O(F)}).catch(()=>{p||O([])})},250);return()=>{p=!0,clearTimeout(C)}},[t,D]);const we=d.useCallback(s=>{R(s),vt(me.SPOTLIGHT_TAB,s)},[]),$e=d.useRef(M);$e.current=M;const gt=d.useCallback(s=>{const p=fe.indexOf($e.current),C=fe[(p+s+fe.length)%fe.length];we(C)},[we]);d.useEffect(()=>{v(0)},[M]);const Se=J.getShortcuts(),ge=d.useMemo(()=>t?Bt():{},[t]),pe=d.useMemo(()=>{if(!t)return[];const s=Se.find(C=>C.id==="spawn-agent"),p=Se.find(C=>C.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:s?Ve(s):"Alt+N",icon:f.jsx(ne,{name:"plus",size:16}),action:()=>{w.current(),T.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:p?Ve(p):"Ctrl+K",icon:f.jsx(ne,{name:"dashboard",size:16}),action:()=>{w.current(),j.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:f.jsx(ne,{name:"gear",size:16}),action:()=>{w.current(),Q.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:f.jsx(ne,{name:"chart-line",size:16}),action:()=>{var C;w.current(),(C=N.current)==null||C.call(N)}}]},[t,Se]),he=d.useMemo(()=>t?Array.from(h.values()).map(s=>{const p=(g||[]).filter(Y=>Y.agentId===s.id).map(Y=>Y.filePath),C=[...new Set(p)],F=C.map(Y=>Y.split("/").pop()||Y),B=[];s.lastAssignedTask&&B.push(s.lastAssignedTask);const L=`${s.class} • ${s.cwd}`;let k=`${s.name} ${s.class} ${s.status} ${s.cwd}`;s.taskLabel&&(k+=` ${s.taskLabel}`),F.length>0&&(k+=` ${F.join(" ")} ${C.join(" ")}`),B.length>0&&(k+=` ${B.join(" ")}`);const P=Date.now()-s.lastActivity;let U;return s.lastAssignedTask&&(s.lastAssignedTask.length>150?U=s.lastAssignedTask.slice(0,150)+"...":U=s.lastAssignedTask),{id:`agent-${s.id}`,type:"agent",title:s.name,subtitle:L,lastUserInput:U,timeAway:P,icon:f.jsx(_t,{agent:s,size:20}),_searchText:k,_modifiedFiles:C,_userQueries:B,_agentId:s.id,_lastActivity:s.lastActivity,_taskLabel:s.taskLabel,_status:s.status,action:()=>{w.current(),It(s.id),J.selectAgent(s.id),J.getState().viewMode!=="flat"&&J.requestTerminalExpand()}}}):[],[t,h,g]),Ae=d.useMemo(()=>t?Array.from(E.values()).map(s=>{var p;return{id:`area-${s.id}`,type:"area",title:s.name,subtitle:`${s.assignedAgentIds.length} agents • ${((p=s.directories)==null?void 0:p.length)||0} folders`,icon:f.jsx(ne,{name:"map",size:16}),action:()=>{w.current(),J.selectArea(s.id)}}}):[],[t,E]),je=d.useMemo(()=>{const s=new Map;for(const p of he)p._agentId&&s.set(p._agentId,p);return s},[he]),Ne=d.useMemo(()=>{const s=new Map;if(!t)return s;for(const p of h.values()){const C=J.getAreaForAgent(p.id);if(!C||C.archived)continue;const F=s.get(C.id);F?F.push(p):s.set(C.id,[p])}return s},[t,h,E]),Pe=d.useMemo(()=>{const s=new Map;for(const p of m)s.has(p.agentId)||s.set(p.agentId,p.timestamp);return s},[m]),ve=d.useMemo(()=>{if(!t)return[];const s=D.trim().toLowerCase(),p=Dt({sortMode:Ms(),agentsWithUnseenOutput:S,getLatestToolTimestamp:B=>Pe.get(B)}),C=Array.from(E.values()).filter(B=>!B.archived).filter(B=>s?B.name.toLowerCase().includes(s):!0).sort((B,L)=>B.name.localeCompare(L.name,void 0,{sensitivity:"base"})),F=[];for(const B of C){const k=(Ne.get(B.id)||[]).slice().sort(p).map(P=>je.get(P.id)).filter(P=>!!P);!s&&k.length===0||F.push({areaId:B.id,areaName:B.name,areaColor:B.color,agents:k})}return F},[t,D,E,Ne,je,S,Pe]),ye=d.useMemo(()=>t?Array.from(x.values()).filter(s=>s.type==="server"||s.type==="boss"||s.type==="database"||s.type==="tests").map(s=>{var P,U,Y,ue,ee;const p=s.status==="running"?"#4ade80":s.status==="stopped"?"#f87171":"#facc15",C=s.type==="boss"?"crown":s.type==="database"?"database":s.type==="tests"?"flask":"desktop",F=s.type==="boss"?"Boss":s.type==="database"?"Database":s.type==="tests"?"Tests":"Server";let B=`${F} • ${s.status}`;if(s.type==="database"&&((U=(P=s.database)==null?void 0:P.connections)!=null&&U.length)){const z=s.database.connections[0];B+=` • ${z.engine} @ ${z.host}`}else s.type==="tests"&&s.folderPath?B=`${F} • ${s.folderPath}`:s.cwd&&(B+=` • ${s.cwd}`);const L=((Y=s.pm2Status)==null?void 0:Y.ports)||[];let k=`${s.name} ${s.type} ${s.status} ${s.cwd||""} ${((ue=s.pm2)==null?void 0:ue.name)||""}`;if(s.type==="tests"&&(k+=` ${s.folderPath||""} tests junit maven`),L.length>0&&(k+=` ${L.join(" ")}`),s.type==="database"&&((ee=s.database)!=null&&ee.connections))for(const z of s.database.connections)k+=` ${z.name} ${z.engine} ${z.host} ${z.database||""} mysql postgresql sql`;return{id:`building-${s.id}`,type:"building",title:s.name,subtitle:B,_ports:L,icon:f.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[f.jsx(ne,{name:"status-pending",size:10,weight:"fill",color:p}),f.jsx(ne,{name:C,size:16})]}),_searchText:k,action:()=>{var z;w.current(),s.type==="boss"?ce.current(s.id):s.type==="database"?$.current(s.id):s.type==="tests"?J.openTestsBuilding(s.id):(z=s.pm2)!=null&&z.enabled&&oe.current(s.id)}}}):[],[t,x]),Ke=d.useMemo(()=>{if(!t)return[];const s=g||[],p=new Set,C=[];for(const F of s){if(p.has(F.filePath))continue;p.add(F.filePath);const B=F.filePath.split("/").pop()||F.filePath,L=F.action==="created"?"Created":F.action==="modified"?"Modified":F.action==="deleted"?"Deleted":"Read";if(C.push({id:`modified-${F.filePath}-${F.timestamp}`,type:"modified-file",title:B,subtitle:`${L} by ${F.agentName} • ${F.filePath}`,matchedText:F.filePath,icon:F.action==="deleted"?f.jsx(ne,{name:"trash",size:16}):kt(F.filePath),action:()=>{w.current();const k=Array.from(J.getState().areas.values());for(const P of k)for(const U of P.directories||[])if(F.filePath.startsWith(U)){J.setFileViewerPath(F.filePath),W.current(P.id);return}J.selectAgent(F.agentId)}}),C.length>=50)break}return C},[t,g]),Oe=d.useMemo(()=>t?X.map(s=>{const p=s.isGitRepo&&s.gitBranch?`${s.path} • ${s.gitBranch}`:s.path;return{id:`folder-${s.path}`,type:"folder",title:s.name,subtitle:p,matchedText:s.path,icon:f.jsx(ne,{name:s.isGitRepo?"git-branch":"folder",size:16}),_searchText:`${s.name} ${s.path}`,_isGitRepo:s.isGitRepo,_gitBranch:s.gitBranch,action:()=>{w.current(),J.openFileExplorer(s.path)}}}):[],[t,X]),ze=d.useMemo(()=>new Z(he,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[he]),Ge=d.useMemo(()=>new Z(pe,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[pe]),Qe=d.useMemo(()=>new Z(Ae,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[Ae]),We=d.useMemo(()=>new Z(Ke,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[Ke]),He=d.useMemo(()=>new Z(ye,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ye]),de=d.useMemo(()=>{if(!D.trim()){const A=[];A.push(...ye);const I=[...he].sort((b,K)=>{const te=Ee(b._agentId,b._lastActivity,ge);return Ee(K._agentId,K._lastActivity,ge)-te});A.push(...I),A.push(...pe.slice(0,2)),A.push(...Ae.slice(0,2));const _={};return Es.forEach((b,K)=>{_[b]=K}),A.sort((b,K)=>(_[b.type]??999)-(_[K.type]??999)),A}const s=D.trim().toLowerCase(),p=ze.search(D).slice(0,8),C=Ge.search(D).slice(0,3),F=Qe.search(D).slice(0,2),B=We.search(D).slice(0,3),L=Oe.slice(0,8),k=He.search(D).filter(A=>{const I=A.score??1;return`${A.item.title} ${A.item.subtitle||""} ${A.item._searchText||""}`.toLowerCase().includes(s)||I<=.2}).slice(0,4),P={agent:6,building:5,folder:4,command:3,area:2,"modified-file":1},U=A=>{if(!s)return 1;const I=A.title.toLowerCase();return I===s?6:I.startsWith(s)?5:I.split(/[^a-z0-9]+/i).includes(s)?4:I.includes(s)?3:`${A.subtitle||""} ${A._searchText||""} ${A.matchedText||""}`.toLowerCase().includes(s)?2:1},Y=(A,I)=>{const _=(1-Math.min(1,I??1))*4;return U(A)*100+(P[A.type]??0)*5+_},ue=new Map,ee=(A,I)=>{const _=ue.get(A.type),b={item:A,score:Y(A,I)};_?_.push(b):ue.set(A.type,[b])};for(const A of p){const I={...A.item};if(I._modifiedFiles&&I._modifiedFiles.length>0){const _=I._modifiedFiles.filter(b=>{var se;const K=((se=b.split("/").pop())==null?void 0:se.toLowerCase())||"",te=b.toLowerCase();return K.includes(s)||te.includes(s)});_.length>0&&(I.matchedFiles=_)}if(I._userQueries&&I._userQueries.length>0){const _=I._userQueries.find(b=>b.toLowerCase().includes(s));if(_)if(_.length>200){const K=_.toLowerCase().indexOf(s),te=Math.max(0,K-60),se=Math.min(_.length,K+s.length+100);I.matchedQuery=(te>0?"...":"")+_.slice(te,se)+(se<_.length?"...":"")}else I.matchedQuery=_}ee(I,A.score)}for(const A of k)ee(A.item,A.score);for(const A of C)ee(A.item,A.score);for(const A of F)ee(A.item,A.score);for(const A of B)ee(A.item,A.score);for(const A of L)ee(A,void 0);for(const[A,I]of ue)A==="agent"?I.sort((_,b)=>{const K=U(_.item),te=U(b.item);if(te!==K)return te-K;const se=Ee(_.item._agentId,_.item._lastActivity,ge),Ye=Ee(b.item._agentId,b.item._lastActivity,ge);return Ye!==se?Ye-se:b.score-_.score}):I.sort((_,b)=>b.score-_.score);const z=A=>A.reduce((I,_)=>Math.max(I,_.score),-1),Ue=[];return Array.from(ue.values()).sort((A,I)=>z(I)-z(A)).forEach(A=>{for(const I of A)Ue.push(I.item)}),Ue},[D,ze,Ge,Qe,We,He,pe,he,Ae,ye,Oe,ge]),V=d.useMemo(()=>{switch(M){case"agents":return de.filter(s=>s.type==="agent");case"buildings":return de.filter(s=>s.type==="building");case"commands":return de.filter(s=>s.type==="command");case"folders":return de.filter(s=>s.type==="folder");case"areas":return ve.flatMap(s=>s.agents);case"all":default:return de}},[M,de,ve]);d.useEffect(()=>{H>=V.length&&v(Math.max(0,V.length-1))},[V.length,H]);const mt=d.useCallback(s=>{if(s.altKey&&!s.ctrlKey&&!s.metaKey&&(s.key==="p"||s.key==="n"||s.key==="P"||s.key==="N")){s.preventDefault(),s.stopPropagation(),s.nativeEvent.stopImmediatePropagation();const p=s.key.toLowerCase();v(p==="p"?C=>C>0?C-1:V.length-1:C=>C<V.length-1?C+1:0);return}switch(s.key){case"Escape":s.preventDefault(),w.current();break;case"ArrowUp":s.preventDefault(),v(p=>p>0?p-1:V.length-1);break;case"ArrowDown":s.preventDefault(),v(p=>p<V.length-1?p+1:0);break;case"Enter":s.preventDefault(),V[H]&&V[H].action();break}},[V,H]),pt=d.useCallback((s,p)=>{if(!p||!s)return s;const C=s.toLowerCase(),F=p.toLowerCase(),B=[];let L=0,k=C.indexOf(F),P=0;for(;k!==-1;)k>L&&B.push(s.slice(L,k)),B.push(Be.createElement("mark",{key:P++,className:"spotlight-highlight"},s.slice(k,k+p.length))),L=k+p.length,k=C.indexOf(F,L);return L<s.length&&B.push(s.slice(L)),B.length>0?Be.createElement(Be.Fragment,null,...B):s},[]);return{query:D,setQuery:ft,selectedIndex:H,setSelectedIndex:v,results:V,activeTab:M,setActiveTab:we,cycleTab:gt,areaSections:ve,handleKeyDown:mt,highlightMatch:pt}}const ws=d.forwardRef(function({query:e,onQueryChange:n,onKeyDown:r,onResetSelection:c},i){const{t:o}=Fe(["common"]);return f.jsxs("div",{className:"spotlight-input-wrapper",children:[f.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),f.jsx("input",{ref:i,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:a=>{n(a.target.value),c()},onKeyDown:r,autoFocus:!0,spellCheck:!1}),f.jsxs("div",{className:"spotlight-input-hints",children:[f.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Ss=d.memo(function({activeTab:e,onSelect:n}){const{t:r}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-tabs",role:"tablist","aria-label":r("terminal:spotlight.tabsLabel"),children:[fe.map(c=>f.jsx("button",{type:"button",role:"tab","aria-selected":c===e,tabIndex:-1,className:`spotlight-tab${c===e?" active":""}`,onClick:()=>n(c),children:r(`terminal:spotlight.tabs.${c}`)},c)),f.jsx("span",{className:"spotlight-tabs-hint",children:f.jsx("kbd",{children:"Tab"})})]})}),vs=d.forwardRef(function({results:e,selectedIndex:n,query:r,activeTab:c,areaSections:i,highlightMatch:o,onSelectIndex:a},u){const{t:l}=Fe(["terminal"]),h=d.useRef(!1);d.useEffect(()=>{h.current=!1},[e]),d.useEffect(()=>{const g=typeof u=="function"?null:u==null?void 0:u.current;if(!g)return;const m=()=>{h.current=!0};return g.addEventListener("mousemove",m),()=>{g.removeEventListener("mousemove",m)}},[u,e]);const E={command:l("terminal:spotlight.categories.commands"),agent:l("terminal:spotlight.categories.agents"),building:l("terminal:spotlight.categories.infrastructure"),area:l("terminal:spotlight.categories.areas"),folder:l("terminal:spotlight.categories.folders"),"modified-file":l("terminal:spotlight.categories.modifiedFiles")},x=d.useMemo(()=>{const g=[];let m=null,S=[];return e.forEach((w,T)=>{w.type!==m&&(m!==null&&S.length>0&&g.push([m,S]),m=w.type,S=[]),S.push({result:w,index:T})}),m!==null&&S.length>0&&g.push([m,S]),g},[e]);if(d.useEffect(()=>{if(!u||typeof u=="function")return;const g=u.current;if(!g)return;const m=g.querySelector(".spotlight-item.selected");m&&m.scrollIntoView({block:"nearest",behavior:"smooth"})},[n,u]),c==="areas"){if(i.length===0)return f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})});let g=0;return f.jsx("div",{className:"spotlight-results",ref:u,children:i.map(m=>f.jsxs("div",{children:[f.jsxs("div",{className:"spotlight-category-header spotlight-area-section-header",children:[f.jsx("span",{className:"spotlight-area-dot",style:{background:m.areaColor},"aria-hidden":"true"}),f.jsx("span",{className:"spotlight-area-name",children:m.areaName}),f.jsx("span",{className:"spotlight-area-count",children:m.agents.length})]}),m.agents.length===0?f.jsx("div",{className:"spotlight-area-empty",children:l("terminal:spotlight.noAgentsInArea")}):m.agents.map(S=>{const w=g++;return f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id)})]},m.areaId))})}return e.length===0?f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})}):f.jsx("div",{className:"spotlight-results",ref:u,children:x.map(([g,m])=>f.jsxs("div",{children:[x.length>1&&f.jsx("div",{className:"spotlight-category-header",children:E[g]||g}),m.map(({result:S,index:w})=>f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id))]},g))})}),Bs=d.memo(function(){const{t:e}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-footer",children:[f.jsxs("div",{className:"spotlight-footer-left",children:[f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"↑"}),f.jsx("kbd",{children:"↓"})," ",f.jsx("kbd",{children:"Alt+N"}),f.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Tab"})," ",e("terminal:spotlight.switchTabs")]})]}),f.jsx("div",{className:"spotlight-footer-right",children:f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),Is=768;function Rs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=d.useRef(null),E=d.useRef(null),x=d.useRef(null),g=d.useRef(0),{query:m,setQuery:S,selectedIndex:w,setSelectedIndex:T,results:j,activeTab:Q,setActiveTab:W,cycleTab:oe,areaSections:ce,handleKeyDown:$,highlightMatch:N}=Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});g.current=j.length;const D=d.useRef(oe);D.current=oe,d.useEffect(()=>{t&&setTimeout(()=>{var v,M;(v=h.current)==null||v.focus(),(M=h.current)==null||M.select()},50)},[t]),d.useEffect(()=>{if(!t)return;const v=window.visualViewport;if(!v||window.innerWidth>Is)return;const M=()=>{const R=E.current;R&&(R.style.height=`${v.height}px`,R.style.top=`${v.offsetTop}px`)};return M(),v.addEventListener("resize",M),v.addEventListener("scroll",M),()=>{v.removeEventListener("resize",M),v.removeEventListener("scroll",M);const R=E.current;R&&(R.style.height="",R.style.top="")}},[t]),d.useEffect(()=>{if(!t)return;const v=M=>{if(M.key==="Escape"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),e();return}if(M.key==="Tab"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),D.current(M.shiftKey?-1:1);return}if(M.altKey&&!M.ctrlKey&&!M.metaKey&&(M.key==="n"||M.key==="p"||M.key==="N"||M.key==="P")){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation();const R=M.key.toLowerCase(),X=g.current;T(R==="p"?O=>O>0?O-1:X-1:O=>O<X-1?O+1:0);return}};return window.addEventListener("keydown",v,{capture:!0}),()=>{window.removeEventListener("keydown",v,{capture:!0})}},[t,e]);const ae=d.useCallback(v=>{v.target===v.currentTarget&&e()},[e]),H=d.useCallback(()=>{T(0)},[T]);return t?f.jsx("div",{ref:E,className:"spotlight-overlay",onClick:ae,children:f.jsxs("div",{className:"spotlight-modal",children:[f.jsx(ws,{ref:h,query:m,onQueryChange:S,onKeyDown:$,onResetSelection:H}),f.jsx(Ss,{activeTab:Q,onSelect:W}),f.jsx(vs,{ref:x,results:j,selectedIndex:w,query:m,activeTab:Q,areaSections:ce,highlightMatch:N,onSelectIndex:T}),f.jsx(Bs,{})]})}):null}export{Ls as FILE_ICON_NAMES,Rs as Spotlight,Bs as SpotlightFooter,ws as SpotlightInput,Je as SpotlightItem,vs as SpotlightResults,$s as formatDuration,js as formatRelativeTime,Ns as getAgentIcon,kt as getFileIconFromPath,Ps as getTypeLabel,Fs as useSpotlightSearch};