tide-commander 1.134.0 → 1.134.2

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 (38) hide show
  1. package/dist/assets/{BossLogsModal-RefxNov0.js → BossLogsModal-DNQC-Ewi.js} +1 -1
  2. package/dist/assets/{BossSpawnModal-6YdVtXsV.js → BossSpawnModal-DSpPdHfB.js} +1 -1
  3. package/dist/assets/{ControlsModal-CzNNwFvF.js → ControlsModal-TPM0WTd7.js} +1 -1
  4. package/dist/assets/{DockerLogsModal-CKu0t2zp.js → DockerLogsModal-BsEfK9sY.js} +1 -1
  5. package/dist/assets/{EmbeddedEditor-DZt6t0pq.js → EmbeddedEditor-B7pzeHYJ.js} +1 -1
  6. package/dist/assets/{GmailOAuthSetup-CzwdXXpj.js → GmailOAuthSetup-BD0lLD6-.js} +1 -1
  7. package/dist/assets/{GoogleOAuthSetup-BSitbOF_.js → GoogleOAuthSetup-q_I-vMvg.js} +1 -1
  8. package/dist/assets/{IframeModal-BQH5btbe.js → IframeModal-C0-b5Igy.js} +1 -1
  9. package/dist/assets/{IntegrationsPanel-Cgj96DLZ.js → IntegrationsPanel-BPWcucBR.js} +2 -2
  10. package/dist/assets/{LogViewerModal-DWq3ch0_.js → LogViewerModal-D1puFD4z.js} +1 -1
  11. package/dist/assets/{MonitoringModal-DJan0ZfF.js → MonitoringModal-Dy3YmxW7.js} +1 -1
  12. package/dist/assets/{PM2LogsModal-BEg-S2UN.js → PM2LogsModal-DFNTztfk.js} +1 -1
  13. package/dist/assets/{RestoreArchivedAreaModal-DETyJSSk.js → RestoreArchivedAreaModal-CokHqFKe.js} +1 -1
  14. package/dist/assets/{Scene2DCanvas-Dvtx-tTF.js → Scene2DCanvas-Dr1l-tVX.js} +1 -1
  15. package/dist/assets/{SceneManager-D0YNBVvC.js → SceneManager-IcoT7Cdk.js} +1 -1
  16. package/dist/assets/{SkillsPanel-CY1MGXiv.js → SkillsPanel-Cc1zvnfm.js} +1 -1
  17. package/dist/assets/{SlackMultiInstanceSetup-x3J1T2CL.js → SlackMultiInstanceSetup-Cjva8TJX.js} +1 -1
  18. package/dist/assets/{SpawnModal-BuXvCAro.js → SpawnModal-DHKupuXe.js} +1 -1
  19. package/dist/assets/{StatisticsModal-JguU4fHR.js → StatisticsModal-DZXDkn4d.js} +1 -1
  20. package/dist/assets/{SubordinateAssignmentModal-TyPQN6G4.js → SubordinateAssignmentModal-DLJNIySK.js} +1 -1
  21. package/dist/assets/{TriggerManagerPanel-Co7nZrm5.js → TriggerManagerPanel-Bd5ZGBaw.js} +1 -1
  22. package/dist/assets/{WorkflowEditorPanel-DxDbJWw3.js → WorkflowEditorPanel-D1YylR-A.js} +1 -1
  23. package/dist/assets/{area-logos-Cmo2TPRg.js → area-logos-C1EKS2S6.js} +1 -1
  24. package/dist/assets/{index-BxEYSlj-.js → index-0yPqh1QY.js} +1 -1
  25. package/dist/assets/{index-DH6zCU8H.js → index-7EfWB7v9.js} +2 -2
  26. package/dist/assets/{index-C0PTjSKV.js → index-BLrXnQWB.js} +1 -1
  27. package/dist/assets/{index-DiZqkOIm.js → index-BmUoFUZP.js} +1 -1
  28. package/dist/assets/{index-C1drJm1h.js → index-C87bCtYJ.js} +1 -1
  29. package/dist/assets/{index-DmAPUqcW.js → index-Ch70UsM8.js} +1 -1
  30. package/dist/assets/{index-Byqe2ALL.js → index-E4hM-HPm.js} +1 -1
  31. package/dist/assets/{index-BWe3rGsu.js → index-IPKznDm8.js} +3 -3
  32. package/dist/assets/{index-BgzCW06Y.js → index-_wxXq7jG.js} +1 -1
  33. package/dist/assets/{main-BVwUBAk3.js → main-DhXGHPKx.js} +7 -7
  34. package/dist/assets/{web-D4QqghkZ.js → web-CDTjrhUg.js} +1 -1
  35. package/dist/assets/{web-B_mn8Bop.js → web-CHTqiViU.js} +1 -1
  36. package/dist/assets/{web-DuThEbz0.js → web-g3yRdGTs.js} +1 -1
  37. package/dist/index.html +1 -1
  38. package/package.json +1 -1
@@ -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-BVwUBAk3.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-DhXGHPKx.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,2 +1,2 @@
1
- import{r as a,B as mn,E as Bt,G as Zt,H as Jt,j as e,J as Qt,K as fn,u as Rt,L as hn,M as gn,N as xn,O as bn,V as _n,P as wn,U as vn,W as Ft,S,X as Wt,Y as Dt,Z as Ht,_ as xt,$ as ge,a0 as Cn,s as b,a1 as en,a2 as tn,a3 as jn,w as Ut,x as Vt,I as p,a4 as Nn,n as kn,a5 as yn,a6 as nn,a7 as an,a8 as An,a9 as Sn,aa as En,ab as Mn,ac as In,ad as Tn,ae as Pn,af as Ln,ag as Dn,ah as Rn,ai as $n,aj as zn,ak as Xt,C as On,al as Bn,am as Gt,an as Fn,ao as Wn,ap as Hn,aq as Un,ar as Vn,as as Xn,at as Gn,au as qn,av as Yn,aw as Kn,ax as Zn,ay as Jn,az as Qn,aA as ea,aB as ta,aC as na,aD as aa,aE as sa}from"./main-BVwUBAk3.js";import{g as ia}from"./area-logos-Cmo2TPRg.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function la(u){const r=a.useRef(u);r.current=u,a.useEffect(()=>{if(!mn())return;let m=null,h=!1;return Bt.addListener("backButton",()=>{r.current()==="exit"&&Bt.exitApp()}).then(N=>{h?N.remove():m=N}),()=>{h=!0,m&&(m.remove(),m=null)}},[])}async function ra(u){const r=Zt(),m=await fetch(`${Jt()}/api/agents/${u}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${r}`}});if(!m.ok){const h=await m.json().catch(()=>({}));throw new Error((h==null?void 0:h.error)||`Failed to start terminal (${m.status})`)}return m.json()}async function oa(u){const r=Zt();await fetch(`${Jt()}/api/agents/${u}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${r}`}})}const at=new Map;function ca({agentId:u}){const[r,m]=a.useState(null),[h,N]=a.useState(null);return a.useEffect(()=>{let P=!1;const M=at.get(u);return M&&(clearTimeout(M),at.delete(u)),m(null),N(null),ra(u).then(L=>{P||m(L.url)}).catch(L=>{P||N(L instanceof Error?L.message:"Failed to start terminal")}),()=>{P=!0;const L=at.get(u);L&&clearTimeout(L),at.set(u,setTimeout(()=>{at.delete(u),oa(u)},2500))}},[u]),h?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:h})}):r?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(Qt,{terminalUrl:r,visible:!0})}):e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:"Attaching to interactive session…"})})}const Pt=new Map,da=6e4;function ua({agentId:u,contextSummary:r}){const{t:m}=Rt(["terminal","common"]),[h,N]=a.useState(()=>{var I;return((I=Pt.get(u))==null?void 0:I.snapshot)??null}),[P,M]=a.useState(!1),[L,G]=a.useState(null),_=a.useRef(0);a.useEffect(()=>{const I=Pt.get(u);if(I&&Date.now()-I.fetchedAt<da){N(I.snapshot);return}const W=++_.current;M(!0),G(null),hn(u).then(U=>{W===_.current&&(Pt.set(u,{snapshot:U,fetchedAt:Date.now()}),N(U),M(!1))}).catch(U=>{W===_.current&&(G(U.message||"Failed to load plan limits"),M(!1))})},[u]);const F=[];if(h!=null&&h.rateLimits){const I=[{key:"fiveHour",label:m("terminal:usage.currentSession"),window:h.rateLimits.fiveHour},{key:"sevenDay",label:m("terminal:usage.currentWeekAll"),window:h.rateLimits.sevenDay},{key:"sevenDayOpus",label:m("terminal:usage.currentWeekOpus"),window:h.rateLimits.sevenDayOpus},{key:"sevenDaySonnet",label:m("terminal:usage.currentWeekSonnet"),window:h.rateLimits.sevenDaySonnet}];for(const W of I)W.window&&F.push({...W,window:W.window})}return e.jsxs("div",{className:"plan-limits-tooltip",children:[r&&e.jsx("div",{className:"plan-limits-tooltip__context",children:r}),e.jsx("div",{className:"plan-limits-tooltip__title",children:m("terminal:usage.limits")}),P&&!h&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[m("common:status.loading"),"…"]}),!P&&L&&!h&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:m("terminal:usage.limitsError",{message:L})}),F.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:F.map(({key:I,label:W,window:U})=>{const xe=Math.max(0,Math.min(100,U.utilization)),Z=xn(xe);return e.jsxs("div",{className:"plan-limits-tooltip__gauge",children:[e.jsxs("div",{className:"plan-limits-tooltip__gauge-head",children:[e.jsx("span",{className:"plan-limits-tooltip__gauge-label",children:W}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:Z},children:m("terminal:usage.percentUsed",{percent:Math.round(xe)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${xe}%`,background:Z}})}),e.jsx("div",{className:"plan-limits-tooltip__reset",children:m("terminal:usage.resets",{time:gn(U.resetsAt)})})]},I)})}):h&&!P&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:h.rateLimitsError?m("terminal:usage.limitsError",{message:h.rateLimitsError}):h.cliHint})]})}function pa({agentId:u,disabled:r,contextSummary:m,children:h}){return e.jsx(fn,{position:"top",maxWidth:320,disabled:r,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx(ua,{agentId:u,contextSummary:m}),children:h})}const ma=a.memo(function({className:r=""}){const{t:m}=Rt(["common"]),[h,N]=bn(),P=a.useRef(null),[M,L]=a.useState(null);a.useLayoutEffect(()=>{const _=P.current;if(!_)return;const F=_.querySelector(".view-mode-toggle__btn--active");F&&L({left:F.offsetLeft,width:F.offsetWidth})},[h]);const G=a.useCallback(_=>{if(_!==h){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:_}})),_==="3d"){requestAnimationFrame(()=>N(_));return}N(_)}},[h,N]);return e.jsxs("div",{className:`view-mode-toggle ${r}`,ref:P,children:[M&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:M.left,width:M.width}}),_n.map(_=>e.jsxs("button",{className:`view-mode-toggle__btn ${h===_?"view-mode-toggle__btn--active":""}`,onClick:()=>G(_),title:m(`common:viewMode.descriptions.${_}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[_==="2d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]}),_==="3d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]}),_==="flat"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1"})]}),_==="dashboard"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"12",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"3",y:"16",width:"7",height:"5",rx:"1"})]})]}),e.jsx("span",{className:"view-mode-toggle__label",children:m(`common:viewMode.labels.${_}`)})]},_))]})}),bt=3,_t=280,qt=320,Lt=240,Yt=64,fa=["simple","chat","advanced"],ha={simple:"Simple",chat:"Chat",advanced:"Advanced"},ga={simple:"○",chat:"◐",advanced:"◉"},xa={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Kt="flat-clear-context";function ba(u){const r=u.split("/").filter(Boolean);return r.length===0?u:r.slice(-2).join("/")}function _a(u){if(u.provider==="codex"){const P=u.codexModel||"gpt-5.3-codex",M=na[P];return{model:(M==null?void 0:M.label)||P}}if(u.provider==="opencode")return{model:u.opencodeModel||"opencode"};const r=u.model||"sonnet",m=sa[r],h=u.effort,N=h?aa[h]:void 0;return{model:(m==null?void 0:m.label)||r,effort:N==null?void 0:N.label}}function wa(u,r){if(r.type==="rectangle"&&r.width&&r.height){const m=r.width/2,h=r.height/2;return u.x>=r.center.x-m&&u.x<=r.center.x+m&&u.z>=r.center.z-h&&u.z<=r.center.z+h}if(r.type==="circle"&&r.radius){const m=u.x-r.center.x,h=u.z-r.center.z;return m*m+h*h<=r.radius*r.radius}return!1}const va=Bn.memo(function({agentId:r,terminalViewMode:m,onTerminalViewModeChange:h,inspectorOpen:N,onToggleInspector:P,onImageClick:M,onFileClick:L,onBashClick:G,onViewMarkdown:_,onRequestClearSubordinates:F,onOpenBuilding:I,keyboard:W,canNavigateBack:U,canNavigateForward:xe,onNavigateBack:Z,onNavigateForward:be,agentInfoOpen:Ee,onToggleAgentInfo:st,onHeaderContextMenu:ae,onBuildingContextMenu:_e}){var ut,pt,K,Ye;const f=Gt(r),H=tn(),we=Fn(),Me=a.useRef(null),We=a.useRef(null),{displayedAgentId:ve,fadingOut:wt}=Wn(r),it=Gt(ve),He=!!we.interactiveMode&&((f==null?void 0:f.provider)??"claude")==="claude"&&!!(f!=null&&f.sessionId),[J,Ue]=a.useState(!1);a.useEffect(()=>{Ue(!1)},[r]),a.useEffect(()=>{!He&&J&&Ue(!1)},[He,J]),a.useEffect(()=>{const s=We.current;if(!s)return;const l=d=>{d.button===3?(d.preventDefault(),d.stopPropagation(),Z()):d.button===4&&(d.preventDefault(),d.stopPropagation(),be())},c=d=>{(d.button===3||d.button===4)&&d.preventDefault()};return s.addEventListener("mouseup",l),s.addEventListener("mousedown",c),()=>{s.removeEventListener("mouseup",l),s.removeEventListener("mousedown",c)}},[Z,be]),a.useEffect(()=>{const s=We.current;if(!s)return;let l=0,c=0,d=0;const Se=250,ze=600,Ke=80,he=1.5,Et=X=>{let R=X instanceof HTMLElement?X:null;for(;R&&R!==s;){const Ze=window.getComputedStyle(R).overflowX;if((Ze==="auto"||Ze==="scroll")&&R.scrollWidth>R.clientWidth)return!0;R=R.parentElement}return!1},Oe=X=>{const R=Date.now();if(R<d){X.preventDefault();return}if(Math.abs(X.deltaX)<=Math.abs(X.deltaY)*he){l=0;return}if(Et(X.target)){l=0;return}R-c>Se&&(l=0),c=R,l+=X.deltaX,l<=-Ke?(l=0,d=R+ze,X.preventDefault(),Z()):l>=Ke&&(l=0,d=R+ze,X.preventDefault(),be())};return s.addEventListener("wheel",Oe,{passive:!1}),()=>s.removeEventListener("wheel",Oe)},[Z,be]);const Ce=en(),se=a.useMemo(()=>{if(!f)return null;const s=new Set,l=[];for(const c of Ce.values())c.archived||c.directories.length===0||c.assignedAgentIds.includes(r)&&(s.add(c.id),l.push(c));for(const c of Ce.values())c.archived||c.directories.length===0||s.has(c.id)||wa({x:f.position.x,z:f.position.z},c)&&(s.add(c.id),l.push(c));return l.length===0?null:l.flatMap(c=>c.directories.filter(d=>d&&d.trim().length>0).map(d=>({areaId:c.id,areaName:c.name,dir:d})))},[f,r,Ce]),{branches:ie,fetchRemote:le,fetchingDirs:lt}=Hn(se),Ve=a.useMemo(()=>{var c;const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const d of H.values())d.type==="terminal"&&b.isPositionInArea(d.position,s)&&l.push({id:d.id,name:d.name,hasUrl:!!((c=d.terminalStatus)!=null&&c.url)});return l},[r,H]),Ie=a.useMemo(()=>{var c;const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const d of H.values())d.type==="server"&&((c=d.pm2)!=null&&c.enabled)&&b.isPositionInArea(d.position,s)&&l.push({id:d.id,name:d.name});return l},[r,H]),je=a.useMemo(()=>{const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const c of H.values())c.type==="database"&&c.database&&b.isPositionInArea(c.position,s)&&l.push({id:c.id,name:c.name});return l},[r,H]),Ne=Un(),Te=a.useMemo(()=>{const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const c of H.values())if(c.type==="tests"&&b.isPositionInArea(c.position,s)){const d=!!c.folderPath&&Ne.some(Se=>Vn(Se,c.folderPath));l.push({id:c.id,name:c.name,working:d})}return l},[r,H,Ne]),[,Q]=a.useReducer(s=>s+1,0),re=((ut=Me.current)==null?void 0:ut.search.searchMode)??!1,ke=a.useCallback(()=>{var s;(s=Me.current)==null||s.search.toggleSearch(),Q()},[]),oe=Xn(),Je=oe.isPending(Kt),[ye,Pe]=a.useState(null),q=ye?H.get(ye):null,{height:vt,onResizeStart:Ct}=Gn(),{sidePanelWidth:Le,handleSidePanelResizeStart:jt}=qn(),[Ae,rt]=a.useState(()=>Dt(S.GIT_PANEL_OPEN,!1)),[ce,ot]=a.useState(()=>Dt(S.BUILDINGS_PANEL_OPEN,!1)),[De,ct]=a.useState(!1),Nt=a.useCallback(()=>{ct(s=>{const l=!s;return l&&Yn.setEnabled(!0),l})},[]),kt=a.useCallback(()=>ct(!1),[]),yt=a.useCallback(()=>{rt(s=>{const l=!s;return ge(S.GIT_PANEL_OPEN,l),l})},[]),Xe=a.useCallback(()=>{ot(s=>{const l=!s;return ge(S.BUILDINGS_PANEL_OPEN,l),l})},[]),v=a.useCallback(()=>{rt(!1),ge(S.GIT_PANEL_OPEN,!1)},[]),de=a.useCallback(()=>{ot(!1),ge(S.BUILDINGS_PANEL_OPEN,!1)},[]),Y=Kn();a.useEffect(()=>{if(!ye)return;Ve.some(l=>l.id===ye)||Pe(null)},[ye,Ve]);const[ee,ue]=a.useState(!1),Qe=a.useRef(null);if(a.useEffect(()=>{if(!ee)return;const s=l=>{Qe.current&&!Qe.current.contains(l.target)&&ue(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[ee]),!f)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const pe=f.contextStats,et=!!pe,dt=pe?pe.totalTokens:f.contextUsed||0,Ge=pe?pe.contextWindow:f.contextLimit||2e5,Re=pe?pe.usedPercent:Math.round(dt/Ge*100),te=Math.max(0,Math.min(100,Re)),me=Math.round(te*10)/10,At=Math.round((100-te)*10)/10,V=te>=80?"#ff4a4a":te>=60?"#ff9e4a":te>=40?"#ffd700":"#4aff9e",ne=(dt/1e3).toFixed(1),tt=(Ge/1e3).toFixed(1),fe=f.cwd,qe=fe?ba(fe):null,$e=((pt=f.subordinateIds)==null?void 0:pt.length)||0,St=$e>0;return e.jsxs("div",{ref:We,className:`flat-terminal-wrapper ${Ae||ce||De?"flat-terminal-wrapper--with-side-panel":""} ${wt?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${Le}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${Ee?"flat-terminal-wrapper__header-main--active":""}`,onClick:st,onContextMenu:s=>{s.preventDefault(),s.stopPropagation(),ae({x:s.clientX,y:s.clientY})},title:Ee?"Hide agent info":"Show agent info","aria-pressed":Ee,children:[e.jsx(nn,{agent:f,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:f.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:an(f.status)},children:f.status})]}),f.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:f.taskLabel,children:["📋 ",f.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:f.provider==="codex"?"/assets/codex.png":f.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:f.provider,className:"flat-terminal-wrapper__header-provider-icon",title:f.provider==="codex"?"Codex Agent":f.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:s,effort:l}=_a(f);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:l?`Model: ${s} · Effort: ${l}`:`Model: ${s}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:s}),l&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:l})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsxs("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:[fa.map(s=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!J&&m===s?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Ue(!1),h(s)},title:xa[s],"aria-pressed":!J&&m===s,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:ga[s]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:ha[s]})]},s)),He&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${J?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Ue(s=>!s),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":J,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:e.jsx(p,{name:"terminal",size:13})}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:"Classic TUI"})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:Z,disabled:!U,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(p,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:be,disabled:!xe,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(p,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${re?"flat-terminal-wrapper__action-btn--active":""}`,onClick:ke,title:re?"Close search":"Search messages","aria-pressed":re,children:e.jsx(p,{name:re?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Je?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>oe.handleClick(Kt,()=>{var s;b.clearContext(r),(s=Me.current)==null||s.historyLoader.clearHistory()}),title:Je?"Click again to confirm clear context":"Clear context",children:e.jsx(p,{name:Je?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Ae?"flat-terminal-wrapper__action-btn--active":""}`,onClick:yt,title:Ae?"Hide git panel":"Show git changes","aria-pressed":Ae,children:e.jsx(p,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ce?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Xe,title:ce?"Hide buildings panel":"Show area buildings","aria-pressed":ce,children:e.jsx(p,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:Qe,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ee?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>ue(s=>!s),title:"More actions","aria-expanded":ee,children:"⋮"}),ee&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${De?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Nt(),ue(!1)},title:De?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(p,{name:"bug",size:14}),e.jsx("span",{children:De?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{b.collapseContext(r),ue(!1)},disabled:f.status!=="idle",title:f.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(p,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),St&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{F(r,$e),ue(!1)},children:[e.jsx(p,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",$e," subordinate",$e===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{b.killAgent(r),ue(!1)},children:[e.jsx(p,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${N?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:P,title:N?"Hide inspector panel":"Show inspector panel","aria-label":N?"Hide inspector panel":"Show inspector panel","aria-pressed":N,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>b.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(p,{name:"cross",size:14})})]})]}),J&&He?e.jsx(ca,{agentId:r}):ve&&it?e.jsx(Zn,{ref:Me,agentId:ve,agent:it,viewMode:m,isOpen:!0,onImageClick:M,onFileClick:L,onBashClick:G,onViewMarkdown:_,keyboard:W,hasModalOpen:!1},ve):null,q&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:Ct,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${q.name}`,style:{height:vt},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(p,{name:"terminal",size:12}),e.jsx("span",{children:q.name}),!((K=q.terminalStatus)!=null&&K.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>Pe(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(p,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:(Ye=q.terminalStatus)!=null&&Ye.url?e.jsx(Qt,{terminalUrl:q.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."})})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[f.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(p,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),fe&&qe&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${fe}`,"aria-label":`Open ${fe} in file explorer`,role:"button",tabIndex:0,onClick:()=>b.openFileExplorer(fe),onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),b.openFileExplorer(fe))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(p,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:qe})]}),se&&se.map(({areaId:s,areaName:l,dir:c})=>{const d=ie.get(c),Se=lt.has(c),ze=c.split("/").filter(Boolean).pop()||c;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${l}: ${c}${d?` (${d.branch}${d.ahead?` ↑${d.ahead}`:""}${d.behind?` ↓${d.behind}`:""})`:""}`,onClick:()=>b.openFileExplorerForAreaFolder(s,c),children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:ze}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(p,{name:"git-branch",size:10})," ",d.branch]}),d.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${d.ahead} ahead`,children:[e.jsx(p,{name:"arrow-up",size:9}),d.ahead]}),d.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${d.behind} behind`,children:[e.jsx(p,{name:"arrow-down",size:9}),d.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${Se?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:Ke=>{Ke.stopPropagation(),le(c)},children:e.jsx(p,{name:Se?"hourglass":"download",size:12})})]})]},`${s}:${c}`)}),e.jsx(pa,{agentId:r,disabled:((f==null?void 0:f.provider)??"claude")!=="claude",contextSummary:et?`Context: ${ne}k / ${tt}k tokens (${me}% used)`:void 0,children:e.jsxs("span",{className:"flat-terminal-wrapper__context",tabIndex:0,role:"button",onClick:()=>b.setContextModalAgentId(r),onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),b.setContextModalAgentId(r))},title:((f==null?void 0:f.provider)??"claude")!=="claude"?et?`Context usage: ${ne}k / ${tt}k tokens (${me}% used). Click to view stats.`:"Click to fetch context stats":void 0,children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(p,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${te}%`,backgroundColor:V}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:V},children:[ne,"k/",tt,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",At,"% free)"]}),!et&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(p,{name:"warn",size:12})})]})}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),Ve.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:Ve.map(s=>{const l=ye===s.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${l?"flat-terminal-wrapper__building-btn--active":""} ${s.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${l?"Hide":"Show"} terminal: ${s.name}${s.hasUrl?"":" (starting...)"}`,onClick:()=>{if(l){Pe(null);return}s.hasUrl||b.sendBuildingCommand(s.id,"start"),Pe(s.id)},onContextMenu:c=>{c.preventDefault(),c.stopPropagation(),_e(s.id,{x:c.clientX,y:c.clientY})},children:e.jsx(p,{name:"terminal",size:14})},s.id)})}),Ie.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Ie.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"scroll",size:14})},s.id))}),je.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:je.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"hard-drives",size:14})},s.id))}),Te.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:Te.map(s=>e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${s.working?"flat-terminal-wrapper__building-btn--tests-working":""}`,title:s.working?`Running tests: ${s.name}`:`Open tests: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"flask",size:14})},s.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(Jn,{})})]}),Ae&&e.jsx(Qn,{agentId:r,agents:Y,onClose:v,branchInfoMap:ie,fetchRemote:le,fetchingDirs:lt,onResizeStart:s=>jt(s,"right")}),ce&&e.jsx(ea,{agentId:r,onClose:de}),De&&e.jsx(ta,{agentId:r,onClose:kt})]})});function ya({onAgentClick:u,onBuildingClick:r,onBuildingDoubleClick:m,onBuildingPopup:h,onAreaContextMenu:N,onOpenSpawnModal:P,onOpenBossSpawnModal:M,onOpenAreaModal:L}){const{t:G}=Rt(["common"]),_=wn(),F=vn(),[I,W]=a.useState(null),[U,xe]=a.useState(null),[Z,be]=a.useState(null),[Ee,st]=a.useState(null),[ae,_e]=a.useState(null),[f,H]=a.useState(null),[we,Me]=a.useState(null),[We,ve]=a.useState(!1),wt=a.useCallback(()=>{ve(t=>!t)},[]),it=a.useCallback(()=>{ve(!1)},[]),[He,J]=a.useState(()=>{const t=Ft(S.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ue=a.useCallback(t=>{J(t),Wt(S.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=n=>{if(n.key!==S.VIEW_MODE)return;const i=n.newValue;(i==="simple"||i==="chat"||i==="advanced")&&J(i)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[Ce,se]=a.useState(()=>Dt(S.FLAT_INSPECTOR_OPEN,!1)),[ie,le]=a.useState(!1),lt=a.useCallback(()=>le(t=>!t),[]),Ve=a.useCallback(()=>le(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:ie}}))},[ie]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:Ce}}))},[Ce]),a.useEffect(()=>{const t=()=>le(C=>!C),n=()=>{se(C=>{const k=!C;return ge(S.FLAT_INSPECTOR_OPEN,k),k})},i=()=>{le(!1),se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)},g=()=>le(!1),x=()=>{se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",n),window.addEventListener("tide-close-flat-side-views",i),window.addEventListener("tide-close-flat-agents-drawer-only",g),window.addEventListener("tide-close-flat-inspector-only",x),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",n),window.removeEventListener("tide-close-flat-side-views",i),window.removeEventListener("tide-close-flat-agents-drawer-only",g),window.removeEventListener("tide-close-flat-inspector-only",x)}},[]);const Ie=a.useRef(null),je=a.useRef(null),[Ne,Te]=a.useState(()=>{const t=Ht(S.FLAT_MIDDLE_WIDTH,0);return t>=_t?t:null}),[Q,re]=a.useState(()=>{const t=Ht(S.FLAT_INSPECTOR_WIDTH,0);return t>=Lt?t:null}),ke=a.useCallback(t=>{if(typeof window>"u")return t;const n=Q!==null?bt+Q:0,i=window.innerWidth-Yt-bt-qt-n;return Math.max(_t,Math.min(Math.max(i,_t),t))},[Q]),oe=a.useCallback(t=>{var x;if(typeof window>"u")return t;const n=(x=Ie.current)==null?void 0:x.querySelector(".flat-middle"),i=(n==null?void 0:n.getBoundingClientRect().width)??_t,g=window.innerWidth-Yt-i-bt-qt-bt;return Math.max(Lt,Math.min(Math.max(g,Lt),t))},[]);a.useEffect(()=>{if(Ne===null&&Q===null)return;const t=()=>{Te(n=>{if(n===null)return n;const i=ke(n);return i===n?n:i}),re(n=>{if(n===null)return n;const i=oe(n);return i===n?n:i})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[Ne,Q,ke,oe]);const Je=a.useCallback(t=>{var i;if(t.button!==0)return;const n=(i=Ie.current)==null?void 0:i.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),je.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),ye=a.useCallback(t=>{var i;if(t.button!==0)return;const n=(i=Ie.current)==null?void 0:i.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),je.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Pe=a.useCallback(t=>{const n=je.current;if(!n||t.pointerId!==n.pointerId)return;const i=t.clientX-n.startX;n.kind==="middle"?Te(ke(n.startWidth+i)):re(oe(n.startWidth-i))},[ke,oe]),q=a.useCallback(t=>{const n=je.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(je.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const g=t.clientX-n.startX;if(n.kind==="middle"){const x=ke(n.startWidth+g);Te(x),xt(S.FLAT_MIDDLE_WIDTH,x)}else{const x=oe(n.startWidth-g);re(x),xt(S.FLAT_INSPECTOR_WIDTH,x)}},[ke,oe]),vt=a.useCallback(()=>{Te(null),xt(S.FLAT_MIDDLE_WIDTH,0)},[]),Ct=a.useCallback(()=>{re(null),xt(S.FLAT_INSPECTOR_WIDTH,0)},[]),[Le,jt]=a.useState(()=>Ft(S.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Ae=a.useCallback(t=>{jt(t),Wt(S.FLAT_INSPECTOR_VIEW,t)},[]),rt=a.useCallback(()=>{se(t=>{const n=!t;return ge(S.FLAT_INSPECTOR_OPEN,n),n})},[]),ce=a.useCallback(()=>{se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)},[]),ot=Cn(),De=a.useCallback((t,n)=>{W({url:t,name:n})},[]),ct=a.useCallback((t,n)=>{xe({command:t,output:n,isLive:!1})},[]),Nt=a.useCallback((t,n)=>{b.setFileViewerPath(t,n)},[]),kt=a.useCallback(t=>{be(t)},[]),yt=a.useCallback((t,n)=>{st({agentId:t,count:n})},[]),Xe=a.useCallback(t=>{m?m(t):r(t)},[r,m]),v=a.useMemo(()=>F.size>0?Array.from(F)[0]:null,[F]);a.useEffect(()=>{ve(!1)},[v]);const de=a.useRef([]),Y=a.useRef(-1),ee=a.useRef(!1),ue=a.useRef(null),[Qe,pe]=a.useState(!1),[et,dt]=a.useState(!1),Ge=a.useRef(!1),Re=a.useRef(null),te=a.useRef(!1),me=a.useMemo(()=>new Set(_.map(t=>t.id)),[_]),At=a.useMemo(()=>{const t=new Map(_.map(i=>[i.id,i])),n=new Map;for(const i of _)if((i.isBoss||i.class==="boss")&&i.subordinateIds&&i.subordinateIds.length>0){const g=i.subordinateIds.map(x=>t.get(x)).filter(x=>x!==void 0);g.length>0&&n.set(i.id,g)}return n},[_]),V=a.useCallback(()=>{const t=de.current,n=Y.current;pe(n>0),dt(n>=0&&n<t.length-1)},[]),ne=a.useCallback(t=>{const n=de.current;if(n.length===0)return;let i=Y.current+t;for(;i>=0&&i<n.length;){const g=n[i];if(me.has(g)){ee.current=!0,Y.current=i,V(),b.selectAgent(g);return}i+=t}},[me,V]),tt=a.useCallback(()=>ne(-1),[ne]),fe=a.useCallback(()=>ne(1),[ne]);la(a.useCallback(()=>{const t=de.current,n=Y.current;return t.length>0&&n>0?(ne(-1),"handled"):"exit"},[ne]));const qe=a.useCallback((t,n)=>{if(typeof window>"u")return;const i=window.history.state,x={...typeof i=="object"&&i!==null?i:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(x,"",window.location.href):window.history.pushState(x,"",window.location.href)},[]);a.useEffect(()=>{if(!v){Ge.current=!1,Re.current=null;return}if(!Ge.current){qe(v,"replace"),Ge.current=!0,Re.current=v;return}if(te.current){te.current=!1,Re.current=v;return}Re.current!==v&&(qe(v,"push"),Re.current=v)},[v,qe]),a.useEffect(()=>{const t=n=>{var C,k;const i=(k=(C=n.state)==null?void 0:C.__flatAgentNav)==null?void 0:k.agentId;if(!i||typeof i!="string"||!me.has(i)||i===v)return;te.current=!0,ee.current=!0;const g=de.current,x=g.lastIndexOf(i);x>=0?Y.current=x:(g.push(i),Y.current=g.length-1),V(),b.selectAgent(i)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[me,v,V]),a.useEffect(()=>{if(!v){de.current=[],Y.current=-1,V();return}if(ue.current=v,ee.current){ee.current=!1,V();return}const t=de.current,n=Y.current;if(n>=0&&t[n]===v){V();return}const i=n<t.length-1?t.slice(0,n+1):t.slice();i.push(v),i.length>100&&i.shift(),de.current=i,Y.current=i.length-1,V()},[v,V]);const $e=a.useCallback(t=>{u(t),le(!1)},[u]),St=v??"",ut=a.useCallback(()=>{},[]),pt=a.useCallback(t=>{$e(t)},[$e]),K=Ce,[Ye,s]=a.useState(K),[l,c]=a.useState(K);a.useEffect(()=>{if(K){s(!0);return}c(!1);const t=setTimeout(()=>s(!1),240);return()=>clearTimeout(t)},[K]),a.useEffect(()=>{if(!Ye||!K)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>c(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[Ye,K]);const d=a.useRef(null);a.useEffect(()=>{if(v)return;const t=n=>{if(n.key!==" "&&n.key!=="Backspace")return;const i=n.target;if(i.tagName==="INPUT"||i.tagName==="TEXTAREA"||i.isContentEditable)return;const g=ue.current;!g||!me.has(g)||(n.preventDefault(),b.selectAgent(g))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[v,me]);const[Se,ze]=a.useState(new Set),Ke=a.useCallback(t=>{ze(n=>{const i=new Set(n);return i.has(t)?i.delete(t):i.add(t),i})},[]),[he,Et]=a.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),n=i=>Et(i.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const[Oe,X]=a.useState(null),R=a.useCallback(t=>{X(n=>n===t?null:t)},[]),Ze=en(),mt=tn(),[sn]=jn(),Be=a.useMemo(()=>{const t=new Map,n=[];for(const w of _){const A=b.getAreaForAgent(w.id);if(!Ut((A==null?void 0:A.id)??null))continue;if(!A||A.archived){n.push(w);continue}const E=t.get(A.id);E?E.push(w):t.set(A.id,[w])}const i=new Map,g=[];for(const w of mt.values()){let A=!1;for(const E of Ze.values())if(!E.archived&&Vt(E.id)&&b.isPositionInArea(w.position,E)){const z=i.get(E.id);z?z.push(w):i.set(E.id,[w]),A=!0;break}!A&&Ut(null)&&g.push(w)}const x=[];for(const[,w]of Ze){if(w.archived||!Vt(w.id))continue;const A=t.get(w.id),E=i.get(w.id)??[];(A&&A.length>0||E.length>0)&&x.push({area:w,agents:A??[],buildings:E})}(n.length>0||g.length>0)&&x.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:n,buildings:g});const C=x.filter(w=>w.area.id!=="__unassigned__"),k=x.filter(w=>w.area.id==="__unassigned__");let o=1,y=1;const $=new Map;if(C.length>1){let w=1/0,A=-1/0,E=1/0,z=-1/0;for(const O of C)w=Math.min(w,O.area.center.x),A=Math.max(A,O.area.center.x),E=Math.min(E,O.area.center.z),z=Math.max(z,O.area.center.z);const ft=A-w||1,ht=z-E||1;if(C.length<=4){o=C.length,y=1;const O=[...C].sort((B,Mt)=>B.area.center.x-Mt.area.center.x);for(let B=0;B<O.length;B++)$.set(O[B].area.id,{row:1,col:B+1})}else{const O=[...C].sort((j,D)=>j.area.center.x-D.area.center.x),B=[];for(let j=1;j<O.length;j++)B.push(O[j].area.center.x-O[j-1].area.center.x);const Mt=B.reduce((j,D)=>j+D,0)/B.length||1;let $t=1;for(const j of B)j>Mt*1.3&&$t++;o=Math.max(2,Math.min($t,C.length));const It=[...C].sort((j,D)=>j.area.center.z-D.area.center.z),gt=[];for(let j=1;j<It.length;j++)gt.push(It[j].area.center.z-It[j-1].area.center.z);const cn=gt.reduce((j,D)=>j+D,0)/gt.length||1;let zt=1;for(const j of gt)j>cn*1.3&&zt++;y=Math.max(2,Math.min(zt,C.length)),o=Math.max(o,Math.ceil(C.length/y)),y=Math.max(y,Math.ceil(C.length/o));const dn=ft/o,un=ht/y,Tt=new Set;for(const j of C){let D=Math.min(o-1,Math.max(0,Math.floor((j.area.center.x-w)/dn))),Fe=Math.min(y-1,Math.max(0,Math.floor((j.area.center.z-E)/un))),nt=`${Fe},${D}`,Ot=0;const pn=y*o;for(;Tt.has(nt)&&Ot<pn;)D++,D>=o&&(D=0,Fe=(Fe+1)%y),nt=`${Fe},${D}`,Ot++;Tt.has(nt)&&(Fe=y,D=0,nt=`${Fe},${D}`,y++),Tt.add(nt),$.set(j.area.id,{row:Fe+1,col:D+1})}}}const T=w=>{w.sort((A,E)=>{var ft,ht,O,B;const z=(((ft=A.position)==null?void 0:ft.z)??0)-(((ht=E.position)==null?void 0:ht.z)??0);return z!==0?z:(((O=A.position)==null?void 0:O.x)??0)-(((B=E.position)==null?void 0:B.x)??0)})};for(const w of C)T(w.agents);for(const w of k)T(w.agents);return{groups:[...C,...k],gridCols:o,gridRows:y,positions:$}},[_,Ze,mt,sn]),ln=a.useMemo(()=>{if(!ae)return[];const t=_.find(n=>n.id===ae.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(p,{name:"chat",size:14}),onClick:()=>u(t.id)},{id:"clone-agent",label:"Clone Agent",icon:e.jsx(p,{name:"clipboard",size:14}),onClick:()=>b.cloneAgent(t.id)},{id:"fork-agent",label:"Fork Agent (with history)",icon:e.jsx(p,{name:"git-branch",size:14}),onClick:()=>b.forkAgent(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>{Me({agentId:t.id,name:t.name})}}]:[]},[ae,_,u]),rn=a.useMemo(()=>{var C;if(!f)return[];const t=mt.get(f.buildingId);if(!t)return[];const n=[],i=t.type==="server"||t.type==="docker"||t.type==="terminal",g=t.status==="running",x=t.type==="boss";if(n.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="tests"?"Open Tests":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((C=t.pm2)!=null&&C.enabled)?"View PM2 Logs":"Open",icon:e.jsx(p,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="tests"?"flask":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>Xe(t.id)}),i&&(g||n.push({id:"start",label:"Start",icon:e.jsx(p,{name:"play",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"start")}),g&&(n.push({id:"restart",label:"Restart",icon:e.jsx(p,{name:"refresh",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(p,{name:"stop",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"stop")}))),x&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(n.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(p,{name:"launch",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"start")}}),n.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(p,{name:"pause",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"stop")}}),n.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(p,{name:"restart",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"restart")}})),i&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(p,{name:"health",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"healthCheck")}),n.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),n.push({id:"edit",label:"Edit Building",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),n.push({id:"clone",label:"Clone Building",icon:e.jsx(p,{name:"copy",size:14}),onClick:()=>{b.createBuilding({name:`${t.name} (Copy)`,type:t.type,style:t.style,color:t.color,scale:t.scale,position:{x:t.position.x+2,z:t.position.z+2},cwd:t.cwd,folderPath:t.folderPath,commands:t.commands,pm2:t.pm2,docker:t.docker,database:t.database,terminal:t.terminal,urls:t.urls,subordinateBuildingIds:t.subordinateBuildingIds})}}),t.urls&&t.urls.length>0)for(const k of t.urls)n.push({id:`url-${k.label}`,label:k.label,icon:e.jsx(p,{name:"link",size:14}),onClick:()=>window.open(k.url,"_blank","noopener,noreferrer")});return n.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),n.push({id:"delete",label:"Delete Building",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>b.deleteBuilding(t.id)}),n},[f,mt,Xe]),on=a.useCallback(t=>{const n=new Set(Be.groups.map(i=>i.area.id));n.delete(t),ze(n),requestAnimationFrame(()=>{const i=d.current;if(!i)return;const g=i.querySelector(`[data-area-id="${t}"]`);if(!g)return;const x=i.getBoundingClientRect(),k=g.getBoundingClientRect().top-x.top+i.scrollTop-8;i.scrollTo({top:Math.max(0,k),behavior:"smooth"})})},[Be]);return e.jsxs("div",{ref:Ie,className:`flat-view ${K?"flat-view--with-inspector":""} ${v?"flat-view--has-chat":""} ${ie?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(Ne===null&&Q===null)return;const t={};return Ne!==null&&(t["--flat-middle-width"]=`${Ne}px`),Q!==null&&(t["--flat-inspector-width"]=`${Q}px`),t})(),children:[ie&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Ve,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children:e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:P,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:M,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:L,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(Nn,{activeAgentId:St,onClose:ut,onSelectAgent:pt,collapsedAreas:Se,onToggleArea:Ke,agentListRef:d})})]}),e.jsx("div",{className:"flat-splitter flat-splitter--middle",role:"separator","aria-orientation":"vertical","aria-label":"Resize agents panel",title:"Drag to resize · Double-click to reset",onPointerDown:Je,onPointerMove:Pe,onPointerUp:q,onPointerCancel:q,onDoubleClick:vt}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":ie?"Close agents sidebar":"Open agents sidebar","aria-expanded":ie,onClick:lt,children:[e.jsx(p,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),v?e.jsx(va,{agentId:v,terminalViewMode:He,onTerminalViewModeChange:Ue,inspectorOpen:Ce,onToggleInspector:rt,onImageClick:De,onFileClick:Nt,onBashClick:ct,onViewMarkdown:kt,onRequestClearSubordinates:yt,onOpenBuilding:Xe,keyboard:ot,canNavigateBack:Qe,canNavigateForward:et,onNavigateBack:tt,onNavigateForward:fe,agentInfoOpen:We,onToggleAgentInfo:wt,onHeaderContextMenu:t=>{v&&_e({agentId:v,position:t})},onBuildingContextMenu:(t,n)=>{H({buildingId:t,position:n})}}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"}),e.jsx(ma,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Be.gridCols}, 1fr)`},children:Be.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var n;const t=he&&Oe?((n=Be.positions.get(Oe))==null?void 0:n.row)??null:null;return Be.groups.map(i=>{var k;const g=i.area.id,x=Be.positions.get(g),C=he&&Oe!==g;return he&&t!=null&&(x==null?void 0:x.row)===t&&g!==Oe?null:e.jsxs("div",{className:`flat-map-area-card${C?" flat-map-area-card--collapsed":""}`,style:{"--area-color":i.area.color,gridRow:x==null?void 0:x.row,gridColumn:x==null?void 0:x.col},onContextMenu:o=>{N&&(o.preventDefault(),o.stopPropagation(),N(g,{x:o.clientX,y:o.clientY}))},children:[((k=i.area.logo)==null?void 0:k.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:ia(i.area.logo.filename),alt:"","aria-hidden":"true",onError:o=>{o.currentTarget.style.display="none"}}),e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>he?R(g):on(g),title:he?C?`Expand ${i.area.name}`:`Collapse ${i.area.name}`:`Focus ${i.area.name} in left panel`,"aria-expanded":he?!C:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:i.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:i.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:i.agents.length}),he&&e.jsx(p,{name:C?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:i.agents.map(o=>{const y=o.isBoss||o.class==="boss",$=y?At.get(o.id):void 0,T=kn(o),w=T.usedPercent>=80?"#ff4a4a":T.usedPercent>=60?"#ff9e4a":T.usedPercent>=40?"#ffd700":"#4aff9e",A=`Context: ${(T.totalTokens/1e3).toFixed(1)}k / ${(T.contextWindow/1e3).toFixed(1)}k (${T.usedPercent}% used, ${T.freePercent}% free)`,E=o.latestTodos&&o.latestTodos.length>0||$&&$.length>0;return e.jsx(yn,{todos:o.latestTodos,subordinates:$,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${o.status}`,onClick:()=>u(o.id),onContextMenu:z=>{z.preventDefault(),z.stopPropagation(),_e({agentId:o.id,position:{x:z.clientX,y:z.clientY}})},title:E?void 0:`${y?"Boss · ":""}Open chat with ${o.name}
1
+ import{r as a,B as mn,E as Bt,G as Zt,H as Jt,j as e,J as Qt,K as fn,u as Rt,L as hn,M as gn,N as xn,O as bn,V as _n,P as wn,U as vn,W as Ft,S,X as Wt,Y as Dt,Z as Ht,_ as xt,$ as ge,a0 as Cn,s as b,a1 as en,a2 as tn,a3 as jn,w as Ut,x as Vt,I as p,a4 as Nn,n as kn,a5 as yn,a6 as nn,a7 as an,a8 as An,a9 as Sn,aa as En,ab as Mn,ac as In,ad as Tn,ae as Pn,af as Ln,ag as Dn,ah as Rn,ai as $n,aj as zn,ak as Xt,C as On,al as Bn,am as Gt,an as Fn,ao as Wn,ap as Hn,aq as Un,ar as Vn,as as Xn,at as Gn,au as qn,av as Yn,aw as Kn,ax as Zn,ay as Jn,az as Qn,aA as ea,aB as ta,aC as na,aD as aa,aE as sa}from"./main-DhXGHPKx.js";import{g as ia}from"./area-logos-C1EKS2S6.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function la(u){const r=a.useRef(u);r.current=u,a.useEffect(()=>{if(!mn())return;let m=null,h=!1;return Bt.addListener("backButton",()=>{r.current()==="exit"&&Bt.exitApp()}).then(N=>{h?N.remove():m=N}),()=>{h=!0,m&&(m.remove(),m=null)}},[])}async function ra(u){const r=Zt(),m=await fetch(`${Jt()}/api/agents/${u}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${r}`}});if(!m.ok){const h=await m.json().catch(()=>({}));throw new Error((h==null?void 0:h.error)||`Failed to start terminal (${m.status})`)}return m.json()}async function oa(u){const r=Zt();await fetch(`${Jt()}/api/agents/${u}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${r}`}})}const at=new Map;function ca({agentId:u}){const[r,m]=a.useState(null),[h,N]=a.useState(null);return a.useEffect(()=>{let P=!1;const M=at.get(u);return M&&(clearTimeout(M),at.delete(u)),m(null),N(null),ra(u).then(L=>{P||m(L.url)}).catch(L=>{P||N(L instanceof Error?L.message:"Failed to start terminal")}),()=>{P=!0;const L=at.get(u);L&&clearTimeout(L),at.set(u,setTimeout(()=>{at.delete(u),oa(u)},2500))}},[u]),h?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:h})}):r?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(Qt,{terminalUrl:r,visible:!0})}):e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:"Attaching to interactive session…"})})}const Pt=new Map,da=6e4;function ua({agentId:u,contextSummary:r}){const{t:m}=Rt(["terminal","common"]),[h,N]=a.useState(()=>{var I;return((I=Pt.get(u))==null?void 0:I.snapshot)??null}),[P,M]=a.useState(!1),[L,G]=a.useState(null),_=a.useRef(0);a.useEffect(()=>{const I=Pt.get(u);if(I&&Date.now()-I.fetchedAt<da){N(I.snapshot);return}const W=++_.current;M(!0),G(null),hn(u).then(U=>{W===_.current&&(Pt.set(u,{snapshot:U,fetchedAt:Date.now()}),N(U),M(!1))}).catch(U=>{W===_.current&&(G(U.message||"Failed to load plan limits"),M(!1))})},[u]);const F=[];if(h!=null&&h.rateLimits){const I=[{key:"fiveHour",label:m("terminal:usage.currentSession"),window:h.rateLimits.fiveHour},{key:"sevenDay",label:m("terminal:usage.currentWeekAll"),window:h.rateLimits.sevenDay},{key:"sevenDayOpus",label:m("terminal:usage.currentWeekOpus"),window:h.rateLimits.sevenDayOpus},{key:"sevenDaySonnet",label:m("terminal:usage.currentWeekSonnet"),window:h.rateLimits.sevenDaySonnet}];for(const W of I)W.window&&F.push({...W,window:W.window})}return e.jsxs("div",{className:"plan-limits-tooltip",children:[r&&e.jsx("div",{className:"plan-limits-tooltip__context",children:r}),e.jsx("div",{className:"plan-limits-tooltip__title",children:m("terminal:usage.limits")}),P&&!h&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[m("common:status.loading"),"…"]}),!P&&L&&!h&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:m("terminal:usage.limitsError",{message:L})}),F.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:F.map(({key:I,label:W,window:U})=>{const xe=Math.max(0,Math.min(100,U.utilization)),Z=xn(xe);return e.jsxs("div",{className:"plan-limits-tooltip__gauge",children:[e.jsxs("div",{className:"plan-limits-tooltip__gauge-head",children:[e.jsx("span",{className:"plan-limits-tooltip__gauge-label",children:W}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:Z},children:m("terminal:usage.percentUsed",{percent:Math.round(xe)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${xe}%`,background:Z}})}),e.jsx("div",{className:"plan-limits-tooltip__reset",children:m("terminal:usage.resets",{time:gn(U.resetsAt)})})]},I)})}):h&&!P&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:h.rateLimitsError?m("terminal:usage.limitsError",{message:h.rateLimitsError}):h.cliHint})]})}function pa({agentId:u,disabled:r,contextSummary:m,children:h}){return e.jsx(fn,{position:"top",maxWidth:320,disabled:r,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx(ua,{agentId:u,contextSummary:m}),children:h})}const ma=a.memo(function({className:r=""}){const{t:m}=Rt(["common"]),[h,N]=bn(),P=a.useRef(null),[M,L]=a.useState(null);a.useLayoutEffect(()=>{const _=P.current;if(!_)return;const F=_.querySelector(".view-mode-toggle__btn--active");F&&L({left:F.offsetLeft,width:F.offsetWidth})},[h]);const G=a.useCallback(_=>{if(_!==h){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:_}})),_==="3d"){requestAnimationFrame(()=>N(_));return}N(_)}},[h,N]);return e.jsxs("div",{className:`view-mode-toggle ${r}`,ref:P,children:[M&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:M.left,width:M.width}}),_n.map(_=>e.jsxs("button",{className:`view-mode-toggle__btn ${h===_?"view-mode-toggle__btn--active":""}`,onClick:()=>G(_),title:m(`common:viewMode.descriptions.${_}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[_==="2d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]}),_==="3d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]}),_==="flat"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1"})]}),_==="dashboard"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"12",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"3",y:"16",width:"7",height:"5",rx:"1"})]})]}),e.jsx("span",{className:"view-mode-toggle__label",children:m(`common:viewMode.labels.${_}`)})]},_))]})}),bt=3,_t=280,qt=320,Lt=240,Yt=64,fa=["simple","chat","advanced"],ha={simple:"Simple",chat:"Chat",advanced:"Advanced"},ga={simple:"○",chat:"◐",advanced:"◉"},xa={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Kt="flat-clear-context";function ba(u){const r=u.split("/").filter(Boolean);return r.length===0?u:r.slice(-2).join("/")}function _a(u){if(u.provider==="codex"){const P=u.codexModel||"gpt-5.3-codex",M=na[P];return{model:(M==null?void 0:M.label)||P}}if(u.provider==="opencode")return{model:u.opencodeModel||"opencode"};const r=u.model||"sonnet",m=sa[r],h=u.effort,N=h?aa[h]:void 0;return{model:(m==null?void 0:m.label)||r,effort:N==null?void 0:N.label}}function wa(u,r){if(r.type==="rectangle"&&r.width&&r.height){const m=r.width/2,h=r.height/2;return u.x>=r.center.x-m&&u.x<=r.center.x+m&&u.z>=r.center.z-h&&u.z<=r.center.z+h}if(r.type==="circle"&&r.radius){const m=u.x-r.center.x,h=u.z-r.center.z;return m*m+h*h<=r.radius*r.radius}return!1}const va=Bn.memo(function({agentId:r,terminalViewMode:m,onTerminalViewModeChange:h,inspectorOpen:N,onToggleInspector:P,onImageClick:M,onFileClick:L,onBashClick:G,onViewMarkdown:_,onRequestClearSubordinates:F,onOpenBuilding:I,keyboard:W,canNavigateBack:U,canNavigateForward:xe,onNavigateBack:Z,onNavigateForward:be,agentInfoOpen:Ee,onToggleAgentInfo:st,onHeaderContextMenu:ae,onBuildingContextMenu:_e}){var ut,pt,K,Ye;const f=Gt(r),H=tn(),we=Fn(),Me=a.useRef(null),We=a.useRef(null),{displayedAgentId:ve,fadingOut:wt}=Wn(r),it=Gt(ve),He=!!we.interactiveMode&&((f==null?void 0:f.provider)??"claude")==="claude"&&!!(f!=null&&f.sessionId),[J,Ue]=a.useState(!1);a.useEffect(()=>{Ue(!1)},[r]),a.useEffect(()=>{!He&&J&&Ue(!1)},[He,J]),a.useEffect(()=>{const s=We.current;if(!s)return;const l=d=>{d.button===3?(d.preventDefault(),d.stopPropagation(),Z()):d.button===4&&(d.preventDefault(),d.stopPropagation(),be())},c=d=>{(d.button===3||d.button===4)&&d.preventDefault()};return s.addEventListener("mouseup",l),s.addEventListener("mousedown",c),()=>{s.removeEventListener("mouseup",l),s.removeEventListener("mousedown",c)}},[Z,be]),a.useEffect(()=>{const s=We.current;if(!s)return;let l=0,c=0,d=0;const Se=250,ze=600,Ke=80,he=1.5,Et=X=>{let R=X instanceof HTMLElement?X:null;for(;R&&R!==s;){const Ze=window.getComputedStyle(R).overflowX;if((Ze==="auto"||Ze==="scroll")&&R.scrollWidth>R.clientWidth)return!0;R=R.parentElement}return!1},Oe=X=>{const R=Date.now();if(R<d){X.preventDefault();return}if(Math.abs(X.deltaX)<=Math.abs(X.deltaY)*he){l=0;return}if(Et(X.target)){l=0;return}R-c>Se&&(l=0),c=R,l+=X.deltaX,l<=-Ke?(l=0,d=R+ze,X.preventDefault(),Z()):l>=Ke&&(l=0,d=R+ze,X.preventDefault(),be())};return s.addEventListener("wheel",Oe,{passive:!1}),()=>s.removeEventListener("wheel",Oe)},[Z,be]);const Ce=en(),se=a.useMemo(()=>{if(!f)return null;const s=new Set,l=[];for(const c of Ce.values())c.archived||c.directories.length===0||c.assignedAgentIds.includes(r)&&(s.add(c.id),l.push(c));for(const c of Ce.values())c.archived||c.directories.length===0||s.has(c.id)||wa({x:f.position.x,z:f.position.z},c)&&(s.add(c.id),l.push(c));return l.length===0?null:l.flatMap(c=>c.directories.filter(d=>d&&d.trim().length>0).map(d=>({areaId:c.id,areaName:c.name,dir:d})))},[f,r,Ce]),{branches:ie,fetchRemote:le,fetchingDirs:lt}=Hn(se),Ve=a.useMemo(()=>{var c;const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const d of H.values())d.type==="terminal"&&b.isPositionInArea(d.position,s)&&l.push({id:d.id,name:d.name,hasUrl:!!((c=d.terminalStatus)!=null&&c.url)});return l},[r,H]),Ie=a.useMemo(()=>{var c;const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const d of H.values())d.type==="server"&&((c=d.pm2)!=null&&c.enabled)&&b.isPositionInArea(d.position,s)&&l.push({id:d.id,name:d.name});return l},[r,H]),je=a.useMemo(()=>{const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const c of H.values())c.type==="database"&&c.database&&b.isPositionInArea(c.position,s)&&l.push({id:c.id,name:c.name});return l},[r,H]),Ne=Un(),Te=a.useMemo(()=>{const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const c of H.values())if(c.type==="tests"&&b.isPositionInArea(c.position,s)){const d=!!c.folderPath&&Ne.some(Se=>Vn(Se,c.folderPath));l.push({id:c.id,name:c.name,working:d})}return l},[r,H,Ne]),[,Q]=a.useReducer(s=>s+1,0),re=((ut=Me.current)==null?void 0:ut.search.searchMode)??!1,ke=a.useCallback(()=>{var s;(s=Me.current)==null||s.search.toggleSearch(),Q()},[]),oe=Xn(),Je=oe.isPending(Kt),[ye,Pe]=a.useState(null),q=ye?H.get(ye):null,{height:vt,onResizeStart:Ct}=Gn(),{sidePanelWidth:Le,handleSidePanelResizeStart:jt}=qn(),[Ae,rt]=a.useState(()=>Dt(S.GIT_PANEL_OPEN,!1)),[ce,ot]=a.useState(()=>Dt(S.BUILDINGS_PANEL_OPEN,!1)),[De,ct]=a.useState(!1),Nt=a.useCallback(()=>{ct(s=>{const l=!s;return l&&Yn.setEnabled(!0),l})},[]),kt=a.useCallback(()=>ct(!1),[]),yt=a.useCallback(()=>{rt(s=>{const l=!s;return ge(S.GIT_PANEL_OPEN,l),l})},[]),Xe=a.useCallback(()=>{ot(s=>{const l=!s;return ge(S.BUILDINGS_PANEL_OPEN,l),l})},[]),v=a.useCallback(()=>{rt(!1),ge(S.GIT_PANEL_OPEN,!1)},[]),de=a.useCallback(()=>{ot(!1),ge(S.BUILDINGS_PANEL_OPEN,!1)},[]),Y=Kn();a.useEffect(()=>{if(!ye)return;Ve.some(l=>l.id===ye)||Pe(null)},[ye,Ve]);const[ee,ue]=a.useState(!1),Qe=a.useRef(null);if(a.useEffect(()=>{if(!ee)return;const s=l=>{Qe.current&&!Qe.current.contains(l.target)&&ue(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[ee]),!f)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const pe=f.contextStats,et=!!pe,dt=pe?pe.totalTokens:f.contextUsed||0,Ge=pe?pe.contextWindow:f.contextLimit||2e5,Re=pe?pe.usedPercent:Math.round(dt/Ge*100),te=Math.max(0,Math.min(100,Re)),me=Math.round(te*10)/10,At=Math.round((100-te)*10)/10,V=te>=80?"#ff4a4a":te>=60?"#ff9e4a":te>=40?"#ffd700":"#4aff9e",ne=(dt/1e3).toFixed(1),tt=(Ge/1e3).toFixed(1),fe=f.cwd,qe=fe?ba(fe):null,$e=((pt=f.subordinateIds)==null?void 0:pt.length)||0,St=$e>0;return e.jsxs("div",{ref:We,className:`flat-terminal-wrapper ${Ae||ce||De?"flat-terminal-wrapper--with-side-panel":""} ${wt?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${Le}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${Ee?"flat-terminal-wrapper__header-main--active":""}`,onClick:st,onContextMenu:s=>{s.preventDefault(),s.stopPropagation(),ae({x:s.clientX,y:s.clientY})},title:Ee?"Hide agent info":"Show agent info","aria-pressed":Ee,children:[e.jsx(nn,{agent:f,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:f.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:an(f.status)},children:f.status})]}),f.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:f.taskLabel,children:["📋 ",f.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:f.provider==="codex"?"/assets/codex.png":f.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:f.provider,className:"flat-terminal-wrapper__header-provider-icon",title:f.provider==="codex"?"Codex Agent":f.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:s,effort:l}=_a(f);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:l?`Model: ${s} · Effort: ${l}`:`Model: ${s}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:s}),l&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:l})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsxs("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:[fa.map(s=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!J&&m===s?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Ue(!1),h(s)},title:xa[s],"aria-pressed":!J&&m===s,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:ga[s]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:ha[s]})]},s)),He&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${J?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Ue(s=>!s),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":J,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:e.jsx(p,{name:"terminal",size:13})}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:"Classic TUI"})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:Z,disabled:!U,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(p,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:be,disabled:!xe,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(p,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${re?"flat-terminal-wrapper__action-btn--active":""}`,onClick:ke,title:re?"Close search":"Search messages","aria-pressed":re,children:e.jsx(p,{name:re?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Je?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>oe.handleClick(Kt,()=>{var s;b.clearContext(r),(s=Me.current)==null||s.historyLoader.clearHistory()}),title:Je?"Click again to confirm clear context":"Clear context",children:e.jsx(p,{name:Je?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Ae?"flat-terminal-wrapper__action-btn--active":""}`,onClick:yt,title:Ae?"Hide git panel":"Show git changes","aria-pressed":Ae,children:e.jsx(p,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ce?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Xe,title:ce?"Hide buildings panel":"Show area buildings","aria-pressed":ce,children:e.jsx(p,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:Qe,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ee?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>ue(s=>!s),title:"More actions","aria-expanded":ee,children:"⋮"}),ee&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${De?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Nt(),ue(!1)},title:De?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(p,{name:"bug",size:14}),e.jsx("span",{children:De?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{b.collapseContext(r),ue(!1)},disabled:f.status!=="idle",title:f.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(p,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),St&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{F(r,$e),ue(!1)},children:[e.jsx(p,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",$e," subordinate",$e===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{b.killAgent(r),ue(!1)},children:[e.jsx(p,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${N?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:P,title:N?"Hide inspector panel":"Show inspector panel","aria-label":N?"Hide inspector panel":"Show inspector panel","aria-pressed":N,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>b.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(p,{name:"cross",size:14})})]})]}),J&&He?e.jsx(ca,{agentId:r}):ve&&it?e.jsx(Zn,{ref:Me,agentId:ve,agent:it,viewMode:m,isOpen:!0,onImageClick:M,onFileClick:L,onBashClick:G,onViewMarkdown:_,keyboard:W,hasModalOpen:!1},ve):null,q&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:Ct,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${q.name}`,style:{height:vt},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(p,{name:"terminal",size:12}),e.jsx("span",{children:q.name}),!((K=q.terminalStatus)!=null&&K.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>Pe(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(p,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:(Ye=q.terminalStatus)!=null&&Ye.url?e.jsx(Qt,{terminalUrl:q.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."})})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[f.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(p,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),fe&&qe&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${fe}`,"aria-label":`Open ${fe} in file explorer`,role:"button",tabIndex:0,onClick:()=>b.openFileExplorer(fe),onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),b.openFileExplorer(fe))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(p,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:qe})]}),se&&se.map(({areaId:s,areaName:l,dir:c})=>{const d=ie.get(c),Se=lt.has(c),ze=c.split("/").filter(Boolean).pop()||c;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${l}: ${c}${d?` (${d.branch}${d.ahead?` ↑${d.ahead}`:""}${d.behind?` ↓${d.behind}`:""})`:""}`,onClick:()=>b.openFileExplorerForAreaFolder(s,c),children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:ze}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(p,{name:"git-branch",size:10})," ",d.branch]}),d.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${d.ahead} ahead`,children:[e.jsx(p,{name:"arrow-up",size:9}),d.ahead]}),d.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${d.behind} behind`,children:[e.jsx(p,{name:"arrow-down",size:9}),d.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${Se?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:Ke=>{Ke.stopPropagation(),le(c)},children:e.jsx(p,{name:Se?"hourglass":"download",size:12})})]})]},`${s}:${c}`)}),e.jsx(pa,{agentId:r,disabled:((f==null?void 0:f.provider)??"claude")!=="claude",contextSummary:et?`Context: ${ne}k / ${tt}k tokens (${me}% used)`:void 0,children:e.jsxs("span",{className:"flat-terminal-wrapper__context",tabIndex:0,role:"button",onClick:()=>b.setContextModalAgentId(r),onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),b.setContextModalAgentId(r))},title:((f==null?void 0:f.provider)??"claude")!=="claude"?et?`Context usage: ${ne}k / ${tt}k tokens (${me}% used). Click to view stats.`:"Click to fetch context stats":void 0,children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(p,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${te}%`,backgroundColor:V}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:V},children:[ne,"k/",tt,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",At,"% free)"]}),!et&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(p,{name:"warn",size:12})})]})}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),Ve.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:Ve.map(s=>{const l=ye===s.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${l?"flat-terminal-wrapper__building-btn--active":""} ${s.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${l?"Hide":"Show"} terminal: ${s.name}${s.hasUrl?"":" (starting...)"}`,onClick:()=>{if(l){Pe(null);return}s.hasUrl||b.sendBuildingCommand(s.id,"start"),Pe(s.id)},onContextMenu:c=>{c.preventDefault(),c.stopPropagation(),_e(s.id,{x:c.clientX,y:c.clientY})},children:e.jsx(p,{name:"terminal",size:14})},s.id)})}),Ie.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Ie.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"scroll",size:14})},s.id))}),je.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:je.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"hard-drives",size:14})},s.id))}),Te.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:Te.map(s=>e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${s.working?"flat-terminal-wrapper__building-btn--tests-working":""}`,title:s.working?`Running tests: ${s.name}`:`Open tests: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"flask",size:14})},s.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(Jn,{})})]}),Ae&&e.jsx(Qn,{agentId:r,agents:Y,onClose:v,branchInfoMap:ie,fetchRemote:le,fetchingDirs:lt,onResizeStart:s=>jt(s,"right")}),ce&&e.jsx(ea,{agentId:r,onClose:de}),De&&e.jsx(ta,{agentId:r,onClose:kt})]})});function ya({onAgentClick:u,onBuildingClick:r,onBuildingDoubleClick:m,onBuildingPopup:h,onAreaContextMenu:N,onOpenSpawnModal:P,onOpenBossSpawnModal:M,onOpenAreaModal:L}){const{t:G}=Rt(["common"]),_=wn(),F=vn(),[I,W]=a.useState(null),[U,xe]=a.useState(null),[Z,be]=a.useState(null),[Ee,st]=a.useState(null),[ae,_e]=a.useState(null),[f,H]=a.useState(null),[we,Me]=a.useState(null),[We,ve]=a.useState(!1),wt=a.useCallback(()=>{ve(t=>!t)},[]),it=a.useCallback(()=>{ve(!1)},[]),[He,J]=a.useState(()=>{const t=Ft(S.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ue=a.useCallback(t=>{J(t),Wt(S.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=n=>{if(n.key!==S.VIEW_MODE)return;const i=n.newValue;(i==="simple"||i==="chat"||i==="advanced")&&J(i)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[Ce,se]=a.useState(()=>Dt(S.FLAT_INSPECTOR_OPEN,!1)),[ie,le]=a.useState(!1),lt=a.useCallback(()=>le(t=>!t),[]),Ve=a.useCallback(()=>le(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:ie}}))},[ie]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:Ce}}))},[Ce]),a.useEffect(()=>{const t=()=>le(C=>!C),n=()=>{se(C=>{const k=!C;return ge(S.FLAT_INSPECTOR_OPEN,k),k})},i=()=>{le(!1),se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)},g=()=>le(!1),x=()=>{se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",n),window.addEventListener("tide-close-flat-side-views",i),window.addEventListener("tide-close-flat-agents-drawer-only",g),window.addEventListener("tide-close-flat-inspector-only",x),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",n),window.removeEventListener("tide-close-flat-side-views",i),window.removeEventListener("tide-close-flat-agents-drawer-only",g),window.removeEventListener("tide-close-flat-inspector-only",x)}},[]);const Ie=a.useRef(null),je=a.useRef(null),[Ne,Te]=a.useState(()=>{const t=Ht(S.FLAT_MIDDLE_WIDTH,0);return t>=_t?t:null}),[Q,re]=a.useState(()=>{const t=Ht(S.FLAT_INSPECTOR_WIDTH,0);return t>=Lt?t:null}),ke=a.useCallback(t=>{if(typeof window>"u")return t;const n=Q!==null?bt+Q:0,i=window.innerWidth-Yt-bt-qt-n;return Math.max(_t,Math.min(Math.max(i,_t),t))},[Q]),oe=a.useCallback(t=>{var x;if(typeof window>"u")return t;const n=(x=Ie.current)==null?void 0:x.querySelector(".flat-middle"),i=(n==null?void 0:n.getBoundingClientRect().width)??_t,g=window.innerWidth-Yt-i-bt-qt-bt;return Math.max(Lt,Math.min(Math.max(g,Lt),t))},[]);a.useEffect(()=>{if(Ne===null&&Q===null)return;const t=()=>{Te(n=>{if(n===null)return n;const i=ke(n);return i===n?n:i}),re(n=>{if(n===null)return n;const i=oe(n);return i===n?n:i})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[Ne,Q,ke,oe]);const Je=a.useCallback(t=>{var i;if(t.button!==0)return;const n=(i=Ie.current)==null?void 0:i.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),je.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),ye=a.useCallback(t=>{var i;if(t.button!==0)return;const n=(i=Ie.current)==null?void 0:i.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),je.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Pe=a.useCallback(t=>{const n=je.current;if(!n||t.pointerId!==n.pointerId)return;const i=t.clientX-n.startX;n.kind==="middle"?Te(ke(n.startWidth+i)):re(oe(n.startWidth-i))},[ke,oe]),q=a.useCallback(t=>{const n=je.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(je.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const g=t.clientX-n.startX;if(n.kind==="middle"){const x=ke(n.startWidth+g);Te(x),xt(S.FLAT_MIDDLE_WIDTH,x)}else{const x=oe(n.startWidth-g);re(x),xt(S.FLAT_INSPECTOR_WIDTH,x)}},[ke,oe]),vt=a.useCallback(()=>{Te(null),xt(S.FLAT_MIDDLE_WIDTH,0)},[]),Ct=a.useCallback(()=>{re(null),xt(S.FLAT_INSPECTOR_WIDTH,0)},[]),[Le,jt]=a.useState(()=>Ft(S.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Ae=a.useCallback(t=>{jt(t),Wt(S.FLAT_INSPECTOR_VIEW,t)},[]),rt=a.useCallback(()=>{se(t=>{const n=!t;return ge(S.FLAT_INSPECTOR_OPEN,n),n})},[]),ce=a.useCallback(()=>{se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)},[]),ot=Cn(),De=a.useCallback((t,n)=>{W({url:t,name:n})},[]),ct=a.useCallback((t,n)=>{xe({command:t,output:n,isLive:!1})},[]),Nt=a.useCallback((t,n)=>{b.setFileViewerPath(t,n)},[]),kt=a.useCallback(t=>{be(t)},[]),yt=a.useCallback((t,n)=>{st({agentId:t,count:n})},[]),Xe=a.useCallback(t=>{m?m(t):r(t)},[r,m]),v=a.useMemo(()=>F.size>0?Array.from(F)[0]:null,[F]);a.useEffect(()=>{ve(!1)},[v]);const de=a.useRef([]),Y=a.useRef(-1),ee=a.useRef(!1),ue=a.useRef(null),[Qe,pe]=a.useState(!1),[et,dt]=a.useState(!1),Ge=a.useRef(!1),Re=a.useRef(null),te=a.useRef(!1),me=a.useMemo(()=>new Set(_.map(t=>t.id)),[_]),At=a.useMemo(()=>{const t=new Map(_.map(i=>[i.id,i])),n=new Map;for(const i of _)if((i.isBoss||i.class==="boss")&&i.subordinateIds&&i.subordinateIds.length>0){const g=i.subordinateIds.map(x=>t.get(x)).filter(x=>x!==void 0);g.length>0&&n.set(i.id,g)}return n},[_]),V=a.useCallback(()=>{const t=de.current,n=Y.current;pe(n>0),dt(n>=0&&n<t.length-1)},[]),ne=a.useCallback(t=>{const n=de.current;if(n.length===0)return;let i=Y.current+t;for(;i>=0&&i<n.length;){const g=n[i];if(me.has(g)){ee.current=!0,Y.current=i,V(),b.selectAgent(g);return}i+=t}},[me,V]),tt=a.useCallback(()=>ne(-1),[ne]),fe=a.useCallback(()=>ne(1),[ne]);la(a.useCallback(()=>{const t=de.current,n=Y.current;return t.length>0&&n>0?(ne(-1),"handled"):"exit"},[ne]));const qe=a.useCallback((t,n)=>{if(typeof window>"u")return;const i=window.history.state,x={...typeof i=="object"&&i!==null?i:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(x,"",window.location.href):window.history.pushState(x,"",window.location.href)},[]);a.useEffect(()=>{if(!v){Ge.current=!1,Re.current=null;return}if(!Ge.current){qe(v,"replace"),Ge.current=!0,Re.current=v;return}if(te.current){te.current=!1,Re.current=v;return}Re.current!==v&&(qe(v,"push"),Re.current=v)},[v,qe]),a.useEffect(()=>{const t=n=>{var C,k;const i=(k=(C=n.state)==null?void 0:C.__flatAgentNav)==null?void 0:k.agentId;if(!i||typeof i!="string"||!me.has(i)||i===v)return;te.current=!0,ee.current=!0;const g=de.current,x=g.lastIndexOf(i);x>=0?Y.current=x:(g.push(i),Y.current=g.length-1),V(),b.selectAgent(i)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[me,v,V]),a.useEffect(()=>{if(!v){de.current=[],Y.current=-1,V();return}if(ue.current=v,ee.current){ee.current=!1,V();return}const t=de.current,n=Y.current;if(n>=0&&t[n]===v){V();return}const i=n<t.length-1?t.slice(0,n+1):t.slice();i.push(v),i.length>100&&i.shift(),de.current=i,Y.current=i.length-1,V()},[v,V]);const $e=a.useCallback(t=>{u(t),le(!1)},[u]),St=v??"",ut=a.useCallback(()=>{},[]),pt=a.useCallback(t=>{$e(t)},[$e]),K=Ce,[Ye,s]=a.useState(K),[l,c]=a.useState(K);a.useEffect(()=>{if(K){s(!0);return}c(!1);const t=setTimeout(()=>s(!1),240);return()=>clearTimeout(t)},[K]),a.useEffect(()=>{if(!Ye||!K)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>c(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[Ye,K]);const d=a.useRef(null);a.useEffect(()=>{if(v)return;const t=n=>{if(n.key!==" "&&n.key!=="Backspace")return;const i=n.target;if(i.tagName==="INPUT"||i.tagName==="TEXTAREA"||i.isContentEditable)return;const g=ue.current;!g||!me.has(g)||(n.preventDefault(),b.selectAgent(g))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[v,me]);const[Se,ze]=a.useState(new Set),Ke=a.useCallback(t=>{ze(n=>{const i=new Set(n);return i.has(t)?i.delete(t):i.add(t),i})},[]),[he,Et]=a.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),n=i=>Et(i.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const[Oe,X]=a.useState(null),R=a.useCallback(t=>{X(n=>n===t?null:t)},[]),Ze=en(),mt=tn(),[sn]=jn(),Be=a.useMemo(()=>{const t=new Map,n=[];for(const w of _){const A=b.getAreaForAgent(w.id);if(!Ut((A==null?void 0:A.id)??null))continue;if(!A||A.archived){n.push(w);continue}const E=t.get(A.id);E?E.push(w):t.set(A.id,[w])}const i=new Map,g=[];for(const w of mt.values()){let A=!1;for(const E of Ze.values())if(!E.archived&&Vt(E.id)&&b.isPositionInArea(w.position,E)){const z=i.get(E.id);z?z.push(w):i.set(E.id,[w]),A=!0;break}!A&&Ut(null)&&g.push(w)}const x=[];for(const[,w]of Ze){if(w.archived||!Vt(w.id))continue;const A=t.get(w.id),E=i.get(w.id)??[];(A&&A.length>0||E.length>0)&&x.push({area:w,agents:A??[],buildings:E})}(n.length>0||g.length>0)&&x.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:n,buildings:g});const C=x.filter(w=>w.area.id!=="__unassigned__"),k=x.filter(w=>w.area.id==="__unassigned__");let o=1,y=1;const $=new Map;if(C.length>1){let w=1/0,A=-1/0,E=1/0,z=-1/0;for(const O of C)w=Math.min(w,O.area.center.x),A=Math.max(A,O.area.center.x),E=Math.min(E,O.area.center.z),z=Math.max(z,O.area.center.z);const ft=A-w||1,ht=z-E||1;if(C.length<=4){o=C.length,y=1;const O=[...C].sort((B,Mt)=>B.area.center.x-Mt.area.center.x);for(let B=0;B<O.length;B++)$.set(O[B].area.id,{row:1,col:B+1})}else{const O=[...C].sort((j,D)=>j.area.center.x-D.area.center.x),B=[];for(let j=1;j<O.length;j++)B.push(O[j].area.center.x-O[j-1].area.center.x);const Mt=B.reduce((j,D)=>j+D,0)/B.length||1;let $t=1;for(const j of B)j>Mt*1.3&&$t++;o=Math.max(2,Math.min($t,C.length));const It=[...C].sort((j,D)=>j.area.center.z-D.area.center.z),gt=[];for(let j=1;j<It.length;j++)gt.push(It[j].area.center.z-It[j-1].area.center.z);const cn=gt.reduce((j,D)=>j+D,0)/gt.length||1;let zt=1;for(const j of gt)j>cn*1.3&&zt++;y=Math.max(2,Math.min(zt,C.length)),o=Math.max(o,Math.ceil(C.length/y)),y=Math.max(y,Math.ceil(C.length/o));const dn=ft/o,un=ht/y,Tt=new Set;for(const j of C){let D=Math.min(o-1,Math.max(0,Math.floor((j.area.center.x-w)/dn))),Fe=Math.min(y-1,Math.max(0,Math.floor((j.area.center.z-E)/un))),nt=`${Fe},${D}`,Ot=0;const pn=y*o;for(;Tt.has(nt)&&Ot<pn;)D++,D>=o&&(D=0,Fe=(Fe+1)%y),nt=`${Fe},${D}`,Ot++;Tt.has(nt)&&(Fe=y,D=0,nt=`${Fe},${D}`,y++),Tt.add(nt),$.set(j.area.id,{row:Fe+1,col:D+1})}}}const T=w=>{w.sort((A,E)=>{var ft,ht,O,B;const z=(((ft=A.position)==null?void 0:ft.z)??0)-(((ht=E.position)==null?void 0:ht.z)??0);return z!==0?z:(((O=A.position)==null?void 0:O.x)??0)-(((B=E.position)==null?void 0:B.x)??0)})};for(const w of C)T(w.agents);for(const w of k)T(w.agents);return{groups:[...C,...k],gridCols:o,gridRows:y,positions:$}},[_,Ze,mt,sn]),ln=a.useMemo(()=>{if(!ae)return[];const t=_.find(n=>n.id===ae.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(p,{name:"chat",size:14}),onClick:()=>u(t.id)},{id:"clone-agent",label:"Clone Agent",icon:e.jsx(p,{name:"clipboard",size:14}),onClick:()=>b.cloneAgent(t.id)},{id:"fork-agent",label:"Fork Agent (with history)",icon:e.jsx(p,{name:"git-branch",size:14}),onClick:()=>b.forkAgent(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>{Me({agentId:t.id,name:t.name})}}]:[]},[ae,_,u]),rn=a.useMemo(()=>{var C;if(!f)return[];const t=mt.get(f.buildingId);if(!t)return[];const n=[],i=t.type==="server"||t.type==="docker"||t.type==="terminal",g=t.status==="running",x=t.type==="boss";if(n.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="tests"?"Open Tests":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((C=t.pm2)!=null&&C.enabled)?"View PM2 Logs":"Open",icon:e.jsx(p,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="tests"?"flask":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>Xe(t.id)}),i&&(g||n.push({id:"start",label:"Start",icon:e.jsx(p,{name:"play",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"start")}),g&&(n.push({id:"restart",label:"Restart",icon:e.jsx(p,{name:"refresh",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(p,{name:"stop",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"stop")}))),x&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(n.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(p,{name:"launch",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"start")}}),n.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(p,{name:"pause",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"stop")}}),n.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(p,{name:"restart",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"restart")}})),i&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(p,{name:"health",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"healthCheck")}),n.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),n.push({id:"edit",label:"Edit Building",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),n.push({id:"clone",label:"Clone Building",icon:e.jsx(p,{name:"copy",size:14}),onClick:()=>{b.createBuilding({name:`${t.name} (Copy)`,type:t.type,style:t.style,color:t.color,scale:t.scale,position:{x:t.position.x+2,z:t.position.z+2},cwd:t.cwd,folderPath:t.folderPath,commands:t.commands,pm2:t.pm2,docker:t.docker,database:t.database,terminal:t.terminal,urls:t.urls,subordinateBuildingIds:t.subordinateBuildingIds})}}),t.urls&&t.urls.length>0)for(const k of t.urls)n.push({id:`url-${k.label}`,label:k.label,icon:e.jsx(p,{name:"link",size:14}),onClick:()=>window.open(k.url,"_blank","noopener,noreferrer")});return n.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),n.push({id:"delete",label:"Delete Building",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>b.deleteBuilding(t.id)}),n},[f,mt,Xe]),on=a.useCallback(t=>{const n=new Set(Be.groups.map(i=>i.area.id));n.delete(t),ze(n),requestAnimationFrame(()=>{const i=d.current;if(!i)return;const g=i.querySelector(`[data-area-id="${t}"]`);if(!g)return;const x=i.getBoundingClientRect(),k=g.getBoundingClientRect().top-x.top+i.scrollTop-8;i.scrollTo({top:Math.max(0,k),behavior:"smooth"})})},[Be]);return e.jsxs("div",{ref:Ie,className:`flat-view ${K?"flat-view--with-inspector":""} ${v?"flat-view--has-chat":""} ${ie?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(Ne===null&&Q===null)return;const t={};return Ne!==null&&(t["--flat-middle-width"]=`${Ne}px`),Q!==null&&(t["--flat-inspector-width"]=`${Q}px`),t})(),children:[ie&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Ve,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children:e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:P,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:M,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:L,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(Nn,{activeAgentId:St,onClose:ut,onSelectAgent:pt,collapsedAreas:Se,onToggleArea:Ke,agentListRef:d})})]}),e.jsx("div",{className:"flat-splitter flat-splitter--middle",role:"separator","aria-orientation":"vertical","aria-label":"Resize agents panel",title:"Drag to resize · Double-click to reset",onPointerDown:Je,onPointerMove:Pe,onPointerUp:q,onPointerCancel:q,onDoubleClick:vt}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":ie?"Close agents sidebar":"Open agents sidebar","aria-expanded":ie,onClick:lt,children:[e.jsx(p,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),v?e.jsx(va,{agentId:v,terminalViewMode:He,onTerminalViewModeChange:Ue,inspectorOpen:Ce,onToggleInspector:rt,onImageClick:De,onFileClick:Nt,onBashClick:ct,onViewMarkdown:kt,onRequestClearSubordinates:yt,onOpenBuilding:Xe,keyboard:ot,canNavigateBack:Qe,canNavigateForward:et,onNavigateBack:tt,onNavigateForward:fe,agentInfoOpen:We,onToggleAgentInfo:wt,onHeaderContextMenu:t=>{v&&_e({agentId:v,position:t})},onBuildingContextMenu:(t,n)=>{H({buildingId:t,position:n})}}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"}),e.jsx(ma,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Be.gridCols}, 1fr)`},children:Be.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var n;const t=he&&Oe?((n=Be.positions.get(Oe))==null?void 0:n.row)??null:null;return Be.groups.map(i=>{var k;const g=i.area.id,x=Be.positions.get(g),C=he&&Oe!==g;return he&&t!=null&&(x==null?void 0:x.row)===t&&g!==Oe?null:e.jsxs("div",{className:`flat-map-area-card${C?" flat-map-area-card--collapsed":""}`,style:{"--area-color":i.area.color,gridRow:x==null?void 0:x.row,gridColumn:x==null?void 0:x.col},onContextMenu:o=>{N&&(o.preventDefault(),o.stopPropagation(),N(g,{x:o.clientX,y:o.clientY}))},children:[((k=i.area.logo)==null?void 0:k.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:ia(i.area.logo.filename),alt:"","aria-hidden":"true",onError:o=>{o.currentTarget.style.display="none"}}),e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>he?R(g):on(g),title:he?C?`Expand ${i.area.name}`:`Collapse ${i.area.name}`:`Focus ${i.area.name} in left panel`,"aria-expanded":he?!C:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:i.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:i.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:i.agents.length}),he&&e.jsx(p,{name:C?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:i.agents.map(o=>{const y=o.isBoss||o.class==="boss",$=y?At.get(o.id):void 0,T=kn(o),w=T.usedPercent>=80?"#ff4a4a":T.usedPercent>=60?"#ff9e4a":T.usedPercent>=40?"#ffd700":"#4aff9e",A=`Context: ${(T.totalTokens/1e3).toFixed(1)}k / ${(T.contextWindow/1e3).toFixed(1)}k (${T.usedPercent}% used, ${T.freePercent}% free)`,E=o.latestTodos&&o.latestTodos.length>0||$&&$.length>0;return e.jsx(yn,{todos:o.latestTodos,subordinates:$,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${o.status}`,onClick:()=>u(o.id),onContextMenu:z=>{z.preventDefault(),z.stopPropagation(),_e({agentId:o.id,position:{x:z.clientX,y:z.clientY}})},title:E?void 0:`${y?"Boss · ":""}Open chat with ${o.name}
2
2
  ${A}`,children:[e.jsx(nn,{agent:o,size:16}),y&&e.jsx("span",{className:"flat-map-agent-chip__crown","aria-hidden":"true",children:e.jsx(p,{name:"crown",size:11,color:"#ffd700",weight:"fill"})}),e.jsx("span",{className:"flat-map-agent-chip__name",children:o.name}),e.jsx("img",{src:o.provider==="codex"?"/assets/codex.png":o.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:o.provider,className:"flat-map-agent-chip__provider-icon",title:o.provider==="codex"?"Codex Agent":o.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:an(o.status)}}),o.latestTodos&&o.latestTodos.length>0&&e.jsx(An,{todos:o.latestTodos,maxDots:6}),y&&$&&$.length>0&&e.jsx(Sn,{subordinates:$,maxDots:6}),e.jsx("span",{className:"flat-map-agent-chip__context-bar","aria-hidden":"true",children:e.jsx("span",{className:"flat-map-agent-chip__context-bar-fill",style:{width:`${T.usedPercent}%`,backgroundColor:w}})})]})},o.id)})}),i.area.directories.length>0&&e.jsx("div",{className:"flat-map-area-card__folders",role:"group","aria-label":`${i.area.name} folders`,children:i.area.directories.map(o=>{const y=o.split("/").filter(Boolean).pop()||o;return e.jsxs("button",{type:"button",className:"flat-map-folder-chip",onClick:$=>{$.stopPropagation(),b.openFileExplorerForAreaFolder(g,o)},title:`Open in file explorer: ${o}`,children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-map-folder-chip__name",children:y})]},o)})}),i.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:i.buildings.map(o=>{var $;const y=($=En[o.type])==null?void 0:$.color;return e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${o.status}`,style:y?{"--building-type-color":y}:void 0,onClick:T=>{if(h){const w=T.currentTarget.getBoundingClientRect();h(o.id,{x:w.right,y:w.top+w.height/2})}else Xe(o.id)},onContextMenu:T=>{T.preventDefault(),T.stopPropagation(),H({buildingId:o.id,position:{x:T.clientX,y:T.clientY}})},title:`${o.name} · ${o.type} · ${o.status}`,children:[e.jsx(p,{name:Mn(o.type),size:12,color:y}),e.jsx("span",{className:"flat-map-building-chip__name",children:o.name}),e.jsx("span",{className:"flat-map-building-chip__dot",style:{backgroundColor:In(o.status)}})]},o.id)})})]},g)})})()})]})})]}),K&&e.jsx("div",{className:"flat-splitter flat-splitter--inspector",role:"separator","aria-orientation":"vertical","aria-label":"Resize inspector panel",title:"Drag to resize · Double-click to reset",onPointerDown:ye,onPointerMove:Pe,onPointerUp:q,onPointerCancel:q,onDoubleClick:Ct}),Ye&&e.jsxs("aside",{className:`flat-inspector ${l?"flat-inspector--open":"flat-inspector--closing"}`,"aria-label":"Inspector panel",children:[e.jsxs("div",{className:"flat-inspector__header",children:[e.jsxs("div",{className:"flat-inspector__tabs",role:"tablist","aria-label":"Inspector view",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":Le==="agent",className:`flat-inspector__tab ${Le==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>Ae("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":Le==="tracking",className:`flat-inspector__tab ${Le==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>Ae("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:ce,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:Le==="tracking"?e.jsx(Tn,{activeAgentId:v??"",onSelectAgent:t=>{u(t),window.innerWidth<=768&&ce()}}):(()=>{if(!v)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=_.find(n=>n.id===v);return t?e.jsx(Pn,{agent:t,onFocusAgent:n=>{u(n),window.innerWidth<=768&&ce()},onKillAgent:n=>b.killAgent(n)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),I&&e.jsx(Ln,{url:I.url,name:I.name,onClose:()=>W(null)}),U&&e.jsx(Dn,{state:U,onClose:()=>xe(null)}),e.jsx(Rn,{agent:v?_.find(t=>t.id===v)??null:null,content:Z,onClose:()=>be(null)}),Ee&&e.jsx($n,{action:"clear-subordinates",selectedAgentId:Ee.agentId,subordinateCount:Ee.count,onClose:()=>st(null),onClearHistory:()=>{}}),e.jsx(zn,{agent:v?_.find(t=>t.id===v)??null:null,isOpen:We&&!!v,onClose:it}),e.jsx(Xt,{isOpen:ae!==null,position:(ae==null?void 0:ae.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:ln,onClose:()=>_e(null)}),e.jsx(Xt,{isOpen:f!==null,position:(f==null?void 0:f.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:rn,onClose:()=>H(null)}),e.jsx(On,{isOpen:we!==null,title:G("common:confirm.removeAgentTitle"),message:G("common:confirm.removeAgentMessage",{name:(we==null?void 0:we.name)??""}),confirmLabel:G("common:buttons.remove"),cancelLabel:G("common:buttons.cancel"),variant:"danger",onConfirm:()=>{we&&b.removeAgentFromServer(we.agentId)},onClose:()=>Me(null)})]})}export{ya as FlatView};
@@ -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-BVwUBAk3.js";import{g as zs,d as Ms,u as Bs}from"./area-logos-Cmo2TPRg.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.134.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-DhXGHPKx.js";import{g as zs,d as Ms,u as Bs}from"./area-logos-C1EKS2S6.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.134.2";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?`