tide-commander 1.140.0 → 1.141.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5432 -0
- package/dist/assets/{BossLogsModal-CEShD72G.js → BossLogsModal-DUh9mA0g.js} +1 -1
- package/dist/assets/{BossSpawnModal-D_DbznYG.js → BossSpawnModal-CGEysDmo.js} +1 -1
- package/dist/assets/{ControlsModal-CSV9_1uM.js → ControlsModal-DKlL4BtE.js} +1 -1
- package/dist/assets/{DockerLogsModal-CiygMroW.js → DockerLogsModal-Dmbe01S9.js} +1 -1
- package/dist/assets/{EmbeddedEditor-Dkdulh-K.js → EmbeddedEditor-Bx_zcxVC.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-Diq3kLhl.js → GmailOAuthSetup-CIPQc_WY.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-CeeDd_xu.js → GoogleOAuthSetup-CnOo59V4.js} +1 -1
- package/dist/assets/{IframeModal-C5dbNqKD.js → IframeModal-ByDSCNMW.js} +1 -1
- package/dist/assets/{IntegrationsPanel-DRn7C1MY.js → IntegrationsPanel-CaiJ__1J.js} +2 -2
- package/dist/assets/{LogViewerModal-DOQxrBbw.js → LogViewerModal-C-w4cekL.js} +1 -1
- package/dist/assets/{MonitoringModal-Cwwk7At7.js → MonitoringModal-DIJd8oHM.js} +1 -1
- package/dist/assets/{PM2LogsModal-BBLqAy_X.js → PM2LogsModal-BFelxtQL.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-D02230fP.js → RestoreArchivedAreaModal-BYTl2kIG.js} +1 -1
- package/dist/assets/{Scene2DCanvas-T1mD-NLE.js → Scene2DCanvas-CJgfmvZA.js} +1 -1
- package/dist/assets/{SceneManager-B8CWKy5o.js → SceneManager-dbNZbSKp.js} +1 -1
- package/dist/assets/{SkillsPanel-BcckjcEb.js → SkillsPanel-CwVwPU5t.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-Cj8Iu2Wk.js → SlackMultiInstanceSetup-DgjwCx-F.js} +1 -1
- package/dist/assets/{SpawnModal-BvhLamvi.js → SpawnModal-DLdyhgtN.js} +1 -1
- package/dist/assets/{StatisticsModal-CZ5_LEYB.js → StatisticsModal-Dd1yh0YT.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-B5fsamyK.js → SubordinateAssignmentModal-bGplpTfz.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-6lpEA2KC.js → TriggerManagerPanel-BmdbFUJB.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-BrF8p9-9.js → WorkflowEditorPanel-BRGVEv4g.js} +1 -1
- package/dist/assets/{area-logos-N2igqdil.js → area-logos-CPBT7k6a.js} +1 -1
- package/dist/assets/{index-BQHw3dpO.js → index-BIfX5_Xq.js} +6 -6
- package/dist/assets/index-C09uD--W.js +2 -0
- package/dist/assets/{index-DqPObBhQ.js → index-Cd31ErRd.js} +1 -1
- package/dist/assets/{index-C4WbvHfv.js → index-CjdSuvf1.js} +1 -1
- package/dist/assets/{index-C05ImQcq.js → index-Clk0mGIC.js} +1 -1
- package/dist/assets/{index-HX-vahcd.js → index-DIWScVQf.js} +1 -1
- package/dist/assets/{index-DQOQTnz4.js → index-DPPtFIs3.js} +3 -3
- package/dist/assets/{index-egOui-YJ.js → index-DX8uai_5.js} +1 -1
- package/dist/assets/{index-BEjvvTvd.js → index-YDzuES6L.js} +2 -2
- package/dist/assets/main-BCym1dpG.css +1 -0
- package/dist/assets/main-CAE1L3Sb.js +256 -0
- package/dist/assets/{web-Bp9InB_8.js → web-B0Nj3gOp.js} +1 -1
- package/dist/assets/{web-BV4UqfvW.js → web-B5mCc_qm.js} +1 -1
- package/dist/assets/{web-Cbif1aIk.js → web-CaEzTKao.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/src/packages/server/data/builtin-skills/create-building.js +7 -2
- package/dist/src/packages/server/data/builtin-skills/http-requests.js +51 -0
- package/dist/src/packages/server/data/builtin-skills/index.js +2 -0
- package/dist/src/packages/server/data/builtin-skills/release-pipeline.js +10 -1
- package/dist/src/packages/server/data/index.js +65 -0
- package/dist/src/packages/server/routes/http-requests.js +148 -0
- package/dist/src/packages/server/routes/index.js +3 -1
- package/dist/src/packages/server/routes/system.js +30 -0
- package/dist/src/packages/server/services/building-service.js +5 -1
- package/dist/src/packages/server/services/claude-usage-service.js +101 -3
- package/dist/src/packages/server/services/http-requests-service.js +450 -0
- package/dist/src/packages/server/services/index.js +1 -0
- package/dist/src/packages/server/websocket/handler.js +2 -1
- package/dist/src/packages/server/websocket/listeners/runtime-listeners.js +75 -0
- package/dist/src/packages/shared/building-types.js +1 -0
- package/dist/src/packages/shared/http-requests-types.js +7 -0
- package/dist/src/packages/shared/types.js +1 -0
- package/package.json +3 -2
- package/dist/assets/index-HVo8TeN6.js +0 -2
- package/dist/assets/main-CAmYbJhQ.js +0 -243
- package/dist/assets/main-DYAzUs5m.css +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{bu as ta,u as B,j as e,aZ as j,bx as Ms,by as Fs,a_ as
|
|
1
|
+
import{bu as ta,u as B,j as e,aZ as j,bx as Ms,by as Fs,a_ as Q,s as D,bz as $s,r as m,D as X,I as F,ac as Us,b7 as qe,f as na,bA as la,X as ia,S as ra,k as oa,ab as Ks,b8 as Ue}from"./main-CAE1L3Sb.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:c}){var f;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
|
-
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:()=>r("start"),children:i("common:buttons.start")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>r("stop"),children:i("common:buttons.stop")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>r("restart"),children:i("terminal:buildingAction.restart")}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>r("logs"),children:i("terminal:logs.title")})]})]}):null}function xa({dockerMode:o,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:r,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 ${o==="container"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"container",checked:o==="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 ${o==="compose"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"compose",checked:o==="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 ${o==="existing"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"existing",checked:o==="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"})]})]}),o==="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=>r(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))})]})]}),o==="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)"})]})]}),o==="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:o==="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."})]}),o!=="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
|
|
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:[((f=t.pm2Status.cpu)==null?void 0:f.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:()=>c("start"),children:i("common:buttons.start")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>c("stop"),children:i("common:buttons.stop")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>c("restart"),children:i("terminal:buildingAction.restart")}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>c("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:c,dockerRestart:i,setDockerRestart:f,dockerPull:b,setDockerPull:L,dockerEnv:T,setDockerEnv:A,dockerComposePath:$,setDockerComposePath:R,dockerComposeProject:K,setDockerComposeProject:I,dockerComposeServices:H,setDockerComposeServices:O,selectedExistingContainer:d,setSelectedExistingContainer:z,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 E=[...v];E[S]=U.target.value,s(E)},placeholder:"8080:80 or 3000"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>s(v.filter((U,E)=>E!==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 E=[...h];E[S]=U.target.value,a(E)},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,E)=>E!==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=>c(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=>f(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(Q,{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=>z(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://...
|
|
5
|
-
NODE_ENV=production`,rows:3})]})]}),V&&(k==null?void 0:k.dockerStatus)&&e.jsxs("div",{className:"docker-status-display",children:[e.jsxs("div",{className:"docker-status-row",children:[e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"ID"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.containerId||"-"})]}),e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"Status"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.status||"-"})]}),k.dockerStatus.health&&k.dockerStatus.health!=="none"&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"Health"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.health})]}),k.dockerStatus.cpu!==void 0&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"CPU"}),e.jsxs("span",{className:"docker-metric-value",children:[k.dockerStatus.cpu.toFixed(1),"%"]})]}),k.dockerStatus.memory!==void 0&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"MEM"}),e.jsxs("span",{className:"docker-metric-value",children:[Ve(k.dockerStatus.memory),k.dockerStatus.memoryLimit?` / ${Ve(k.dockerStatus.memoryLimit)}`:""]})]})]}),k.dockerStatus.ports&&k.dockerStatus.ports.length>0&&e.jsxs("div",{className:"docker-ports-row",children:[e.jsx("span",{className:"docker-metric-label",children:"Ports:"}),k.dockerStatus.ports.map((l,S)=>e.jsxs("a",{href:`http://${window.location.hostname}:${l.host}`,target:"_blank",rel:"noopener noreferrer",className:"docker-port-link",children:[l.host,":",l.container,"/",l.protocol]},S))]}),k.dockerStatus.services&&k.dockerStatus.services.length>0&&e.jsxs("div",{className:"docker-services-status",children:[e.jsx("span",{className:"docker-metric-label",children:"Services:"}),e.jsx("div",{className:"docker-services-grid",children:k.dockerStatus.services.map((l,S)=>e.jsxs("div",{className:"docker-service-item",children:[e.jsx("span",{className:"docker-service-indicator",style:{backgroundColor:l.status==="running"?"#4ade80":"#f87171"}}),e.jsx("span",{className:"docker-service-name",children:l.name}),e.jsx("span",{className:"docker-service-status",children:l.status})]},S))})]})]}),V&&e.jsxs("div",{className:"docker-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>_("start"),children:"Start"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>_("stop"),children:"Stop"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>_("restart"),children:"Restart"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>_("logs"),children:"Logs"})]})]})}const ba={enabled:!1,host:"",port:22,username:"",authMethod:"password"};function ja({dbConnections:o,setDbConnections:p,activeDbConnectionId:u,setActiveDbConnectionId:x}){const{t:n}=B(["terminal","common"]),[y,C]=m.useState({}),g=m.useRef(new Map);m.useEffect(()=>{const a=t=>{const r=t.detail;if(!r||!r.requestId)return;const i=g.current.get(r.requestId);i&&(g.current.delete(r.requestId),C(N=>({...N,[i]:r.success?{status:"success",serverVersion:r.serverVersion}:{status:"error",error:r.error||"Connection failed"}})))};return window.addEventListener("tide:db-test-result",a),()=>window.removeEventListener("tide:db-test-result",a)},[]);const v=(a,t)=>{const r=[...o];r[a]={...r[a],...t},p(r)},s=(a,t)=>{const i={...o[a].ssh??ba,...t};v(a,{ssh:i})},h=a=>{const t=`test_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;g.current.set(t,a.id),C(r=>({...r,[a.id]:{status:"testing"}})),D.testDatabaseConnectionTransient(t,a),window.setTimeout(()=>{g.current.has(t)&&(g.current.delete(t),C(r=>{const i=r[a.id];return(i==null?void 0:i.status)!=="testing"?r:{...r,[a.id]:{status:"error",error:"Test connection timed out after 30s"}}}))},3e4)};return e.jsxs("div",{className:"form-section database-config-section",children:[e.jsxs("label",{className:"form-label",children:[n("terminal:building.dbConnections"),e.jsx(j,{text:n("terminal:building.helpDbConnections"),title:n("terminal:building.dbConnections"),position:"top",size:"sm"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>{const a={id:`conn_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,name:`Connection ${o.length+1}`,engine:"mysql",host:"localhost",port:3306,username:"root"};p([...o,a]),u||x(a.id)},children:n("terminal:database.addConnection")})]}),o.length===0&&e.jsx("div",{className:"form-hint",children:n("terminal:building.dbGetStarted")}),o.map((a,t)=>{var N,b,L,T,A,$,R,K,I,H,O;const r=y[a.id]??{status:"idle"},i=((N=a.ssh)==null?void 0:N.enabled)===!0;return e.jsxs("div",{className:"db-connection-card",children:[e.jsxs("div",{className:"db-connection-header",children:[e.jsxs("label",{className:"db-connection-active",children:[e.jsx("input",{type:"radio",name:"activeConnection",checked:u===a.id,onChange:()=>x(a.id)}),n("common:labels.default"),e.jsx(j,{text:n("terminal:building.helpDbDefault"),position:"top",size:"sm"})]}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>{const d=o.filter(E=>E.id!==a.id);p(d),u===a.id&&d.length>0?x(d[0].id):d.length===0&&x(void 0)},children:n("common:buttons.remove")})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("common:labels.name")}),e.jsx("input",{type:"text",className:"form-input",value:a.name,onChange:d=>v(t,{name:d.target.value}),placeholder:"My Database"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:n("terminal:building.dbEngine")}),e.jsx("select",{className:"form-input form-select",value:a.engine,onChange:d=>{const E=d.target.value;v(t,{engine:E,port:Z[E].defaultPort})},children:Object.keys(Z).map(d=>e.jsxs("option",{value:d,children:[Z[d].icon," ",Z[d].label]},d))})]})]}),a.engine==="sqlite"?e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:n("terminal:building.dbFilepath")}),e.jsx("input",{type:"text",className:"form-input",value:a.filepath||"",onChange:d=>v(t,{filepath:d.target.value||void 0}),placeholder:"/path/to/database.db"})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:[n("terminal:building.dbHost"),i&&e.jsx(j,{text:"Host as seen FROM the SSH server (often 'localhost' or 127.0.0.1).",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:a.host,onChange:d=>v(t,{host:d.target.value}),placeholder:i?"127.0.0.1":"localhost"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:n("terminal:building.dbPort")}),e.jsx("input",{type:"number",className:"form-input",value:a.port,onChange:d=>v(t,{port:parseInt(d.target.value)||Z[a.engine].defaultPort})})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("terminal:building.dbUsername")}),e.jsx("input",{type:"text",className:"form-input",value:a.username,onChange:d=>v(t,{username:d.target.value}),placeholder:"root"})]}),e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("terminal:building.dbPassword")}),e.jsx("input",{type:"password",className:"form-input",value:a.password||"",onChange:d=>v(t,{password:d.target.value||void 0}),placeholder:"Optional",autoComplete:"off"})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:n("terminal:building.dbDefaultDatabase")}),e.jsx("input",{type:"text",className:"form-input",value:a.database||"",onChange:d=>v(t,{database:d.target.value||void 0}),placeholder:"Optional - select after connecting"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsxs("label",{children:["SSL",e.jsx(j,{text:n("terminal:building.helpDbSsl"),position:"top",size:"sm"})]}),e.jsxs("label",{className:"toggle-switch toggle-switch--small",children:[e.jsx("input",{type:"checkbox",checked:a.ssl||!1,onChange:d=>v(t,{ssl:d.target.checked})}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})})]})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsx("div",{className:"db-field db-field--grow",children:e.jsxs("label",{children:["SSH Tunnel",e.jsx(j,{text:"Forward DB traffic through an SSH jump host. Required when the DB is only reachable from inside a private network.",position:"top",size:"sm"})]})}),e.jsx("div",{className:"db-field db-field--small",children:e.jsxs("label",{className:"toggle-switch toggle-switch--small",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:d=>s(t,{enabled:d.target.checked})}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})})]})})]}),i&&e.jsxs("div",{className:"db-ssh-subsection",children:[e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Host"}),e.jsx("input",{type:"text",className:"form-input",value:((b=a.ssh)==null?void 0:b.host)||"",onChange:d=>s(t,{host:d.target.value}),placeholder:"bastion.example.com"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:"SSH Port"}),e.jsx("input",{type:"number",className:"form-input",value:((L=a.ssh)==null?void 0:L.port)||22,onChange:d=>s(t,{port:parseInt(d.target.value)||22})})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Username"}),e.jsx("input",{type:"text",className:"form-input",value:((T=a.ssh)==null?void 0:T.username)||"",onChange:d=>s(t,{username:d.target.value}),placeholder:"ubuntu"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:"Auth Method"}),e.jsxs("select",{className:"form-input form-select",value:((A=a.ssh)==null?void 0:A.authMethod)||"password",onChange:d=>s(t,{authMethod:d.target.value}),children:[e.jsx("option",{value:"password",children:"Password"}),e.jsx("option",{value:"privateKey",children:"Private Key"})]})]})]}),((($=a.ssh)==null?void 0:$.authMethod)||"password")==="password"?e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Password"}),e.jsx("input",{type:"password",className:"form-input",value:((R=a.ssh)==null?void 0:R.password)||"",onChange:d=>s(t,{password:d.target.value||void 0}),placeholder:"SSH password",autoComplete:"off"})]})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:["Private Key Path",e.jsx(j,{text:"Path to a private key file on the server, e.g. ~/.ssh/id_rsa. Use this OR paste the key contents below.",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:((K=a.ssh)==null?void 0:K.privateKeyPath)||"",onChange:d=>s(t,{privateKeyPath:d.target.value||void 0}),placeholder:"/home/user/.ssh/id_rsa"})]})}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:["Private Key Contents (PEM)",e.jsx(j,{text:"Paste the full private key contents inline. Encrypted at rest.",position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input",value:((I=a.ssh)==null?void 0:I.privateKey)||"",onChange:d=>s(t,{privateKey:d.target.value||void 0}),placeholder:"-----BEGIN OPENSSH PRIVATE KEY-----\\n...",rows:4,style:{fontFamily:"monospace",fontSize:12}})]})}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"Key Passphrase (optional)"}),e.jsx("input",{type:"password",className:"form-input",value:((H=a.ssh)==null?void 0:H.passphrase)||"",onChange:d=>s(t,{passphrase:d.target.value||void 0}),placeholder:"If your key is encrypted",autoComplete:"off"})]})})]}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--small",children:[e.jsxs("label",{children:["Local Port",e.jsx(j,{text:"Optional fixed local forwarded port. Leave blank to auto-assign.",position:"top",size:"sm"})]}),e.jsx("input",{type:"number",className:"form-input",value:((O=a.ssh)==null?void 0:O.localPort)??"",onChange:d=>{const E=d.target.value.trim();s(t,{localPort:E?parseInt(E):void 0})},placeholder:"auto"})]})})]}),e.jsxs("div",{className:"db-connection-row",style:{alignItems:"center",gap:8},children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-primary",disabled:r.status==="testing",onClick:()=>h(a),children:r.status==="testing"?"Testing…":"Test Connection"}),r.status==="success"&&e.jsxs("span",{style:{color:"#4aff9e",fontSize:12},children:["✓ Connected",r.serverVersion?` — ${r.serverVersion}`:""]}),r.status==="error"&&e.jsxs("span",{style:{color:"#ff6b6b",fontSize:12},title:r.error,children:["✗ ",r.error]})]})]})]},a.id)}),o.length>0&&e.jsx("div",{className:"form-hint",children:n("terminal:building.dbAfterSaving")})]})}function ga({buildings:o,buildingId:p,subordinateBuildingIds:u,setSubordinateBuildingIds:x,isEditMode:n,showBossLogs:y,setShowBossLogs:C,currentBossLogs:g,bossLogsContainerRef:v}){const{t:s}=B(["terminal","common"]);return e.jsxs("div",{className:"form-section boss-building-section",children:[e.jsxs("label",{className:"form-label",children:[s("terminal:building.managedBuildings"),e.jsx(j,{text:s("terminal:building.helpManagedBuildings"),title:s("terminal:building.managedBuildings"),position:"top",size:"sm"})]}),e.jsx("div",{className:"form-hint",children:s("terminal:building.managedBuildingsHint")}),e.jsxs("div",{className:"subordinate-buildings-list",children:[Array.from(o.values()).filter(h=>h.id!==p&&h.type!=="boss"&&h.type!=="link"&&h.type!=="folder").map(h=>e.jsxs("label",{className:"subordinate-building-item",children:[e.jsx("input",{type:"checkbox",checked:u.includes(h.id),onChange:a=>{a.target.checked?x([...u,h.id]):x(u.filter(t=>t!==h.id))}}),e.jsx("span",{className:"subordinate-building-icon",children:e.jsx(F,{name:Us(h.type),size:14})}),e.jsx("span",{className:"subordinate-building-name",children:h.name}),e.jsx("span",{className:"subordinate-building-status",style:{backgroundColor:qe[h.status]}})]},h.id)),Array.from(o.values()).filter(h=>h.id!==p&&h.type!=="boss"&&h.type!=="link"&&h.type!=="folder").length===0&&e.jsx("div",{className:"form-hint no-buildings-hint",children:s("terminal:building.noManageableBuildings")})]}),n&&u.length>0&&e.jsxs("div",{className:"boss-building-actions",children:[e.jsxs("div",{className:"boss-actions-header",children:[s("terminal:building.bulkActions"),e.jsx(j,{text:s("terminal:building.helpBulkActions"),position:"top",size:"sm"})]}),e.jsxs("div",{className:"boss-actions-row",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>D.sendBossBuildingCommand(p,"start_all"),children:s("terminal:building.startAll")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>D.sendBossBuildingCommand(p,"stop_all"),children:s("terminal:building.stopAll")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>D.sendBossBuildingCommand(p,"restart_all"),children:s("terminal:building.restartAll")}),e.jsx("button",{type:"button",className:`btn btn-sm ${y?"btn-primary":""}`,onClick:()=>{y?(D.stopBossLogStreaming(p),C(!1)):(D.startBossLogStreaming(p),C(!0))},children:s(y?"terminal:building.hideLogs":"terminal:building.unifiedLogs")})]}),e.jsxs("div",{className:"boss-subordinates-status",children:[e.jsx("div",{className:"boss-status-header",children:s("terminal:building.statusOverview")}),e.jsx("div",{className:"boss-status-grid",children:u.map(h=>{const a=o.get(h);return a?e.jsxs("div",{className:"boss-status-item",children:[e.jsx("span",{className:"boss-status-indicator",style:{backgroundColor:qe[a.status]}}),e.jsx("span",{className:"boss-status-name",children:a.name}),e.jsx("span",{className:"boss-status-label",children:a.status})]},h):null})})]})]}),n&&y&&e.jsxs("div",{className:"form-section boss-logs-section",children:[e.jsxs("label",{className:"form-label",children:[s("terminal:building.unifiedLogs"),e.jsx(j,{text:s("terminal:building.helpUnifiedLogs"),position:"top",size:"sm"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.clearBossStreamingLogs(p),children:s("common:buttons.clear")})]}),e.jsxs("div",{className:"boss-logs-container",ref:v,children:[g.map((h,a)=>e.jsxs("div",{className:"boss-log-entry",children:[e.jsxs("span",{className:"boss-log-source",children:["[",h.subordinateName,"]"]}),e.jsx("span",{className:"boss-log-content",children:qs(h.chunk)})]},a)),g.length===0&&e.jsx("div",{className:"boss-logs-empty",children:s("terminal:building.waitingForLogs")})]})]})]})}function va({startCmd:o,setStartCmd:p,stopCmd:u,setStopCmd:x,restartCmd:n,setRestartCmd:y,healthCheckCmd:C,setHealthCheckCmd:g,logsCmd:v,setLogsCmd:s,isEditMode:h,handleCommand:a}){const{t}=B(["terminal","common"]);return e.jsxs("div",{className:"form-section commands-section",children:[e.jsxs("label",{className:"form-label",children:[t("terminal:building.commands"),e.jsx(j,{text:t("terminal:building.helpCommands"),title:t("terminal:building.commands"),position:"top",size:"sm"})]}),e.jsxs("div",{className:"command-inputs",children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdStart"),e.jsx(j,{text:t("terminal:building.helpCmdStart"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:o,onChange:r=>p(r.target.value),placeholder:"npm run dev"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>a("start"),disabled:!o,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdStop"),e.jsx(j,{text:t("terminal:building.helpCmdStop"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:u,onChange:r=>x(r.target.value),placeholder:"pkill -f 'npm run dev'"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>a("stop"),disabled:!u,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdRestart"),e.jsx(j,{text:t("terminal:building.helpCmdRestart"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:n,onChange:r=>y(r.target.value),placeholder:"npm run restart"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>a("restart"),disabled:!n,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdHealthCheck"),e.jsx(j,{text:t("terminal:building.helpCmdHealthCheck"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:r=>g(r.target.value),placeholder:"curl -s http://localhost:3000/health"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>a("healthCheck"),disabled:!C,children:t("terminal:building.check")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdLogs"),e.jsx(j,{text:t("terminal:building.helpCmdLogs"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:v,onChange:r=>s(r.target.value),placeholder:"tail -n 100 /var/log/app.log"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>a("logs"),children:t("terminal:building.fetch")})]})]})]})}const Na=[{value:"",label:"Default ($SHELL)"},{value:"/bin/bash",label:"Bash"},{value:"/bin/zsh",label:"Zsh"},{value:"/usr/bin/fish",label:"Fish"},{value:"/bin/sh",label:"sh"}];function fa({terminalShell:o,setTerminalShell:p,terminalPort:u,setTerminalPort:x,terminalSaveSession:n,setTerminalSaveSession:y,terminalArgs:C,setTerminalArgs:g,isEditMode:v,building:s,handleCommand:h,onOpenTerminal:a,onOpenBelow:t}){const{t:r}=B(["config"]),i=(s==null?void 0:s.status)==="running",N=s==null?void 0:s.terminalStatus;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:r("config:buildings.terminalConfig",{defaultValue:"Terminal Configuration"})}),e.jsxs("div",{className:"form-row",children:[e.jsxs("div",{className:"form-field",children:[e.jsx("label",{className:"form-sublabel",children:r("config:buildings.terminalShell",{defaultValue:"Shell"})}),e.jsx("select",{className:"form-input",value:o,onChange:b=>p(b.target.value),children:Na.map(b=>e.jsx("option",{value:b.value,children:b.label},b.value))})]}),e.jsxs("div",{className:"form-field",children:[e.jsx("label",{className:"form-sublabel",children:r("config:buildings.terminalPort",{defaultValue:"Port"})}),e.jsx("input",{type:"number",className:"form-input",value:u,onChange:b=>x(b.target.value),placeholder:"Auto",min:1024,max:65535})]})]}),e.jsx("div",{className:"form-row",style:{marginTop:"8px"},children:e.jsxs("label",{className:"form-checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n,onChange:b=>y(b.target.checked)}),e.jsx("span",{children:r("config:buildings.terminalSaveSession",{defaultValue:"Persist session (tmux)"})})]})}),e.jsxs("div",{style:{marginTop:"8px"},children:[e.jsx("label",{className:"form-sublabel",children:r("config:buildings.terminalArgs",{defaultValue:"Extra ttyd args"})}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:b=>g(b.target.value),placeholder:"--client-option titleFixed=Terminal"}),e.jsx("div",{className:"form-hint",children:"Additional command-line arguments passed to ttyd"})]})]}),v&&s&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:r("config:buildings.terminalControls",{defaultValue:"Terminal Controls"})}),N&&e.jsxs("div",{className:"building-runtime-info",children:[e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Proxy"}),e.jsx("span",{className:"runtime-value",style:{color:"#4a9eff"},children:N.url})]}),e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"PID"}),e.jsx("span",{className:"runtime-value",children:N.pid})]}),e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Port"}),e.jsx("span",{className:"runtime-value",children:N.port})]}),N.tmuxSession&&e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Session"}),e.jsx("span",{className:"runtime-value",children:N.tmuxSession})]})]}),e.jsxs("div",{className:"building-actions",style:{marginTop:"8px"},children:[!i&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>h("start"),children:[e.jsx(F,{name:"play",size:12})," Start"]}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>h("restart"),children:[e.jsx(F,{name:"refresh",size:12})," Restart"]}),e.jsxs("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>h("stop"),children:[e.jsx(F,{name:"stop",size:12})," Stop"]}),(N==null?void 0:N.url)&&e.jsxs(e.Fragment,{children:[a&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-primary",onClick:()=>a(N.url),children:[e.jsx(F,{name:"desktop",size:12})," Modal"]}),t&&s&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-primary",onClick:()=>t(s.id),children:[e.jsx(F,{name:"arrow-down",size:12})," Below"]})]})]})]})]})]})}function ka({logs:o,buildingId:p,logsContainerRef:u}){return e.jsxs("div",{className:"form-section logs-section",children:[e.jsxs("label",{className:"form-label",children:["Logs",e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.clearBuildingLogs(p),children:"Clear"})]}),e.jsx("div",{className:"logs-container",ref:u,children:o.map((x,n)=>e.jsx("pre",{className:"log-entry",children:qs(x)},n))})]})}function wa({isOpen:o,onClose:p,buildingId:u,initialPosition:x}){const{t:n}=B(["config","common"]),{buildings:y,buildingLogs:C,bossStreamingLogs:g}=na(),v=la(),s=u?y.get(u):null,h=u?g.get(u)||[]:[],a=!!s,[t,r]=m.useState(""),[i,N]=m.useState("server"),[b,L]=m.useState("server-rack"),[T,A]=m.useState(""),[$,R]=m.useState(""),[K,I]=m.useState(""),[H,O]=m.useState(""),[d,E]=m.useState(""),[q,V]=m.useState(""),[k,_]=m.useState(""),[M,l]=m.useState([]),[S,U]=m.useState(!1),[z,X]=m.useState(""),[J,Q]=m.useState(1),[W,te]=m.useState(!1),[Ge,ne]=m.useState(""),[Ye,le]=m.useState(""),[Je,ie]=m.useState(""),[We,oe]=m.useState(""),[Ze,re]=m.useState(""),[Vs,ce]=m.useState(!1),[P,de]=m.useState("container"),[me,ue]=m.useState(""),[Xe,pe]=m.useState(""),[he,xe]=m.useState(""),[be,je]=m.useState([]),[ge,ve]=m.useState([]),[Qe,Ne]=m.useState(""),[fe,ke]=m.useState(""),[ye,Ce]=m.useState(""),[es,Se]=m.useState("unless-stopped"),[ss,we]=m.useState("missing"),[Pe,De]=m.useState(""),[Ee,ze]=m.useState(""),[Le,Ae]=m.useState(""),[Be,Te]=m.useState([]),[Gs,Ys]=m.useState(!1),[Re,Ie]=m.useState([]),[as,Oe]=m.useState(void 0),[ts,_e]=m.useState(""),[Me,Fe]=m.useState(""),[ns,$e]=m.useState(!1),[ls,Ke]=m.useState(""),is=m.useRef(null),Js=m.useRef(null),ee=m.useRef(null);m.useEffect(()=>{var c,f,w,G,ds,ms,us,ps,hs,xs,bs,js,gs,vs,Ns,fs,ks,ys,Cs,Ss,ws,Ps,Ds,Es,zs,Ls,As,Bs,Ts,Rs,Is,Os,_s;o&&(s?(r(s.name),N(s.type),L(s.style||"server-rack"),A(s.color||""),R(s.cwd||""),I(((c=s.commands)==null?void 0:c.start)||""),O(((f=s.commands)==null?void 0:f.stop)||""),E(((w=s.commands)==null?void 0:w.restart)||""),V(((G=s.commands)==null?void 0:G.healthCheck)||""),_(((ds=s.commands)==null?void 0:ds.logs)||""),l(s.urls||[]),X(s.folderPath||""),Q(s.scale||1),te(((ms=s.pm2)==null?void 0:ms.enabled)||!1),ne(((us=s.pm2)==null?void 0:us.script)||""),le(((ps=s.pm2)==null?void 0:ps.args)||""),ie(((hs=s.pm2)==null?void 0:hs.interpreter)||""),oe(((xs=s.pm2)==null?void 0:xs.interpreterArgs)||""),re((bs=s.pm2)!=null&&bs.env?Object.entries(s.pm2.env).map(([Y,He])=>`${Y}=${He}`).join(`
|
|
6
|
-
`):""),de(((js=s.docker)==null?void 0:js.mode)||"container"),ue(((gs=s.docker)==null?void 0:gs.mode)==="existing"&&((vs=s.docker)==null?void 0:vs.containerName)||""),pe(((
|
|
7
|
-
`):""),ke(((Ss=s.docker)==null?void 0:Ss.network)||""),Ce(((ws=s.docker)==null?void 0:ws.command)||""),Se(((Ps=s.docker)==null?void 0:Ps.restart)||"unless-stopped"),we(((Ds=s.docker)==null?void 0:Ds.pull)||"missing"),De(((Es=s.docker)==null?void 0:Es.composePath)||""),ze(((zs=s.docker)==null?void 0:zs.composeProject)||""),Ae(((As=(Ls=s.docker)==null?void 0:Ls.services)==null?void 0:As.join(", "))||""),Te(s.subordinateBuildingIds||[]),Ie(((Bs=s.database)==null?void 0:Bs.connections)||[]),Oe((Ts=s.database)==null?void 0:Ts.activeConnectionId),_e(((Rs=s.terminal)==null?void 0:Rs.shell)||""),Fe((Is=s.terminal)!=null&&Is.port?String(s.terminal.port):""),$e(((Os=s.terminal)==null?void 0:Os.saveSession)||!1),Ke(((_s=s.terminal)==null?void 0:_s.args)||"")):(
|
|
8
|
-
`).map(
|
|
5
|
+
NODE_ENV=production`,rows:3})]})]}),V&&(k==null?void 0:k.dockerStatus)&&e.jsxs("div",{className:"docker-status-display",children:[e.jsxs("div",{className:"docker-status-row",children:[e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"ID"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.containerId||"-"})]}),e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"Status"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.status||"-"})]}),k.dockerStatus.health&&k.dockerStatus.health!=="none"&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"Health"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.health})]}),k.dockerStatus.cpu!==void 0&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"CPU"}),e.jsxs("span",{className:"docker-metric-value",children:[k.dockerStatus.cpu.toFixed(1),"%"]})]}),k.dockerStatus.memory!==void 0&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"MEM"}),e.jsxs("span",{className:"docker-metric-value",children:[Ve(k.dockerStatus.memory),k.dockerStatus.memoryLimit?` / ${Ve(k.dockerStatus.memoryLimit)}`:""]})]})]}),k.dockerStatus.ports&&k.dockerStatus.ports.length>0&&e.jsxs("div",{className:"docker-ports-row",children:[e.jsx("span",{className:"docker-metric-label",children:"Ports:"}),k.dockerStatus.ports.map((l,S)=>e.jsxs("a",{href:`http://${window.location.hostname}:${l.host}`,target:"_blank",rel:"noopener noreferrer",className:"docker-port-link",children:[l.host,":",l.container,"/",l.protocol]},S))]}),k.dockerStatus.services&&k.dockerStatus.services.length>0&&e.jsxs("div",{className:"docker-services-status",children:[e.jsx("span",{className:"docker-metric-label",children:"Services:"}),e.jsx("div",{className:"docker-services-grid",children:k.dockerStatus.services.map((l,S)=>e.jsxs("div",{className:"docker-service-item",children:[e.jsx("span",{className:"docker-service-indicator",style:{backgroundColor:l.status==="running"?"#4ade80":"#f87171"}}),e.jsx("span",{className:"docker-service-name",children:l.name}),e.jsx("span",{className:"docker-service-status",children:l.status})]},S))})]})]}),V&&e.jsxs("div",{className:"docker-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>_("start"),children:"Start"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>_("stop"),children:"Stop"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>_("restart"),children:"Restart"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>_("logs"),children:"Logs"})]})]})}const ba={enabled:!1,host:"",port:22,username:"",authMethod:"password"};function ja({dbConnections:r,setDbConnections:p,activeDbConnectionId:u,setActiveDbConnectionId:x}){const{t:n}=B(["terminal","common"]),[y,C]=m.useState({}),g=m.useRef(new Map);m.useEffect(()=>{const a=t=>{const c=t.detail;if(!c||!c.requestId)return;const i=g.current.get(c.requestId);i&&(g.current.delete(c.requestId),C(f=>({...f,[i]:c.success?{status:"success",serverVersion:c.serverVersion}:{status:"error",error:c.error||"Connection failed"}})))};return window.addEventListener("tide:db-test-result",a),()=>window.removeEventListener("tide:db-test-result",a)},[]);const v=(a,t)=>{const c=[...r];c[a]={...c[a],...t},p(c)},s=(a,t)=>{const i={...r[a].ssh??ba,...t};v(a,{ssh:i})},h=a=>{const t=`test_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;g.current.set(t,a.id),C(c=>({...c,[a.id]:{status:"testing"}})),D.testDatabaseConnectionTransient(t,a),window.setTimeout(()=>{g.current.has(t)&&(g.current.delete(t),C(c=>{const i=c[a.id];return(i==null?void 0:i.status)!=="testing"?c:{...c,[a.id]:{status:"error",error:"Test connection timed out after 30s"}}}))},3e4)};return e.jsxs("div",{className:"form-section database-config-section",children:[e.jsxs("label",{className:"form-label",children:[n("terminal:building.dbConnections"),e.jsx(j,{text:n("terminal:building.helpDbConnections"),title:n("terminal:building.dbConnections"),position:"top",size:"sm"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>{const a={id:`conn_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,name:`Connection ${r.length+1}`,engine:"mysql",host:"localhost",port:3306,username:"root"};p([...r,a]),u||x(a.id)},children:n("terminal:database.addConnection")})]}),r.length===0&&e.jsx("div",{className:"form-hint",children:n("terminal:building.dbGetStarted")}),r.map((a,t)=>{var f,b,L,T,A,$,R,K,I,H,O;const c=y[a.id]??{status:"idle"},i=((f=a.ssh)==null?void 0:f.enabled)===!0;return e.jsxs("div",{className:"db-connection-card",children:[e.jsxs("div",{className:"db-connection-header",children:[e.jsxs("label",{className:"db-connection-active",children:[e.jsx("input",{type:"radio",name:"activeConnection",checked:u===a.id,onChange:()=>x(a.id)}),n("common:labels.default"),e.jsx(j,{text:n("terminal:building.helpDbDefault"),position:"top",size:"sm"})]}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>{const d=r.filter(z=>z.id!==a.id);p(d),u===a.id&&d.length>0?x(d[0].id):d.length===0&&x(void 0)},children:n("common:buttons.remove")})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("common:labels.name")}),e.jsx("input",{type:"text",className:"form-input",value:a.name,onChange:d=>v(t,{name:d.target.value}),placeholder:"My Database"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:n("terminal:building.dbEngine")}),e.jsx("select",{className:"form-input form-select",value:a.engine,onChange:d=>{const z=d.target.value;v(t,{engine:z,port:X[z].defaultPort})},children:Object.keys(X).map(d=>e.jsxs("option",{value:d,children:[X[d].icon," ",X[d].label]},d))})]})]}),a.engine==="sqlite"?e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:n("terminal:building.dbFilepath")}),e.jsx("input",{type:"text",className:"form-input",value:a.filepath||"",onChange:d=>v(t,{filepath:d.target.value||void 0}),placeholder:"/path/to/database.db"})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:[n("terminal:building.dbHost"),i&&e.jsx(j,{text:"Host as seen FROM the SSH server (often 'localhost' or 127.0.0.1).",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:a.host,onChange:d=>v(t,{host:d.target.value}),placeholder:i?"127.0.0.1":"localhost"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:n("terminal:building.dbPort")}),e.jsx("input",{type:"number",className:"form-input",value:a.port,onChange:d=>v(t,{port:parseInt(d.target.value)||X[a.engine].defaultPort})})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("terminal:building.dbUsername")}),e.jsx("input",{type:"text",className:"form-input",value:a.username,onChange:d=>v(t,{username:d.target.value}),placeholder:"root"})]}),e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("terminal:building.dbPassword")}),e.jsx("input",{type:"password",className:"form-input",value:a.password||"",onChange:d=>v(t,{password:d.target.value||void 0}),placeholder:"Optional",autoComplete:"off"})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:n("terminal:building.dbDefaultDatabase")}),e.jsx("input",{type:"text",className:"form-input",value:a.database||"",onChange:d=>v(t,{database:d.target.value||void 0}),placeholder:"Optional - select after connecting"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsxs("label",{children:["SSL",e.jsx(j,{text:n("terminal:building.helpDbSsl"),position:"top",size:"sm"})]}),e.jsxs("label",{className:"toggle-switch toggle-switch--small",children:[e.jsx("input",{type:"checkbox",checked:a.ssl||!1,onChange:d=>v(t,{ssl:d.target.checked})}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})})]})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsx("div",{className:"db-field db-field--grow",children:e.jsxs("label",{children:["SSH Tunnel",e.jsx(j,{text:"Forward DB traffic through an SSH jump host. Required when the DB is only reachable from inside a private network.",position:"top",size:"sm"})]})}),e.jsx("div",{className:"db-field db-field--small",children:e.jsxs("label",{className:"toggle-switch toggle-switch--small",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:d=>s(t,{enabled:d.target.checked})}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})})]})})]}),i&&e.jsxs("div",{className:"db-ssh-subsection",children:[e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Host"}),e.jsx("input",{type:"text",className:"form-input",value:((b=a.ssh)==null?void 0:b.host)||"",onChange:d=>s(t,{host:d.target.value}),placeholder:"bastion.example.com"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:"SSH Port"}),e.jsx("input",{type:"number",className:"form-input",value:((L=a.ssh)==null?void 0:L.port)||22,onChange:d=>s(t,{port:parseInt(d.target.value)||22})})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Username"}),e.jsx("input",{type:"text",className:"form-input",value:((T=a.ssh)==null?void 0:T.username)||"",onChange:d=>s(t,{username:d.target.value}),placeholder:"ubuntu"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:"Auth Method"}),e.jsxs("select",{className:"form-input form-select",value:((A=a.ssh)==null?void 0:A.authMethod)||"password",onChange:d=>s(t,{authMethod:d.target.value}),children:[e.jsx("option",{value:"password",children:"Password"}),e.jsx("option",{value:"privateKey",children:"Private Key"})]})]})]}),((($=a.ssh)==null?void 0:$.authMethod)||"password")==="password"?e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Password"}),e.jsx("input",{type:"password",className:"form-input",value:((R=a.ssh)==null?void 0:R.password)||"",onChange:d=>s(t,{password:d.target.value||void 0}),placeholder:"SSH password",autoComplete:"off"})]})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:["Private Key Path",e.jsx(j,{text:"Path to a private key file on the server, e.g. ~/.ssh/id_rsa. Use this OR paste the key contents below.",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:((K=a.ssh)==null?void 0:K.privateKeyPath)||"",onChange:d=>s(t,{privateKeyPath:d.target.value||void 0}),placeholder:"/home/user/.ssh/id_rsa"})]})}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:["Private Key Contents (PEM)",e.jsx(j,{text:"Paste the full private key contents inline. Encrypted at rest.",position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input",value:((I=a.ssh)==null?void 0:I.privateKey)||"",onChange:d=>s(t,{privateKey:d.target.value||void 0}),placeholder:"-----BEGIN OPENSSH PRIVATE KEY-----\\n...",rows:4,style:{fontFamily:"monospace",fontSize:12}})]})}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"Key Passphrase (optional)"}),e.jsx("input",{type:"password",className:"form-input",value:((H=a.ssh)==null?void 0:H.passphrase)||"",onChange:d=>s(t,{passphrase:d.target.value||void 0}),placeholder:"If your key is encrypted",autoComplete:"off"})]})})]}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--small",children:[e.jsxs("label",{children:["Local Port",e.jsx(j,{text:"Optional fixed local forwarded port. Leave blank to auto-assign.",position:"top",size:"sm"})]}),e.jsx("input",{type:"number",className:"form-input",value:((O=a.ssh)==null?void 0:O.localPort)??"",onChange:d=>{const z=d.target.value.trim();s(t,{localPort:z?parseInt(z):void 0})},placeholder:"auto"})]})})]}),e.jsxs("div",{className:"db-connection-row",style:{alignItems:"center",gap:8},children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-primary",disabled:c.status==="testing",onClick:()=>h(a),children:c.status==="testing"?"Testing…":"Test Connection"}),c.status==="success"&&e.jsxs("span",{style:{color:"#4aff9e",fontSize:12},children:["✓ Connected",c.serverVersion?` — ${c.serverVersion}`:""]}),c.status==="error"&&e.jsxs("span",{style:{color:"#ff6b6b",fontSize:12},title:c.error,children:["✗ ",c.error]})]})]})]},a.id)}),r.length>0&&e.jsx("div",{className:"form-hint",children:n("terminal:building.dbAfterSaving")})]})}function ga({buildings:r,buildingId:p,subordinateBuildingIds:u,setSubordinateBuildingIds:x,isEditMode:n,showBossLogs:y,setShowBossLogs:C,currentBossLogs:g,bossLogsContainerRef:v}){const{t:s}=B(["terminal","common"]);return e.jsxs("div",{className:"form-section boss-building-section",children:[e.jsxs("label",{className:"form-label",children:[s("terminal:building.managedBuildings"),e.jsx(j,{text:s("terminal:building.helpManagedBuildings"),title:s("terminal:building.managedBuildings"),position:"top",size:"sm"})]}),e.jsx("div",{className:"form-hint",children:s("terminal:building.managedBuildingsHint")}),e.jsxs("div",{className:"subordinate-buildings-list",children:[Array.from(r.values()).filter(h=>h.id!==p&&h.type!=="boss"&&h.type!=="link"&&h.type!=="folder").map(h=>e.jsxs("label",{className:"subordinate-building-item",children:[e.jsx("input",{type:"checkbox",checked:u.includes(h.id),onChange:a=>{a.target.checked?x([...u,h.id]):x(u.filter(t=>t!==h.id))}}),e.jsx("span",{className:"subordinate-building-icon",children:e.jsx(F,{name:Us(h.type),size:14})}),e.jsx("span",{className:"subordinate-building-name",children:h.name}),e.jsx("span",{className:"subordinate-building-status",style:{backgroundColor:qe[h.status]}})]},h.id)),Array.from(r.values()).filter(h=>h.id!==p&&h.type!=="boss"&&h.type!=="link"&&h.type!=="folder").length===0&&e.jsx("div",{className:"form-hint no-buildings-hint",children:s("terminal:building.noManageableBuildings")})]}),n&&u.length>0&&e.jsxs("div",{className:"boss-building-actions",children:[e.jsxs("div",{className:"boss-actions-header",children:[s("terminal:building.bulkActions"),e.jsx(j,{text:s("terminal:building.helpBulkActions"),position:"top",size:"sm"})]}),e.jsxs("div",{className:"boss-actions-row",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>D.sendBossBuildingCommand(p,"start_all"),children:s("terminal:building.startAll")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>D.sendBossBuildingCommand(p,"stop_all"),children:s("terminal:building.stopAll")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>D.sendBossBuildingCommand(p,"restart_all"),children:s("terminal:building.restartAll")}),e.jsx("button",{type:"button",className:`btn btn-sm ${y?"btn-primary":""}`,onClick:()=>{y?(D.stopBossLogStreaming(p),C(!1)):(D.startBossLogStreaming(p),C(!0))},children:s(y?"terminal:building.hideLogs":"terminal:building.unifiedLogs")})]}),e.jsxs("div",{className:"boss-subordinates-status",children:[e.jsx("div",{className:"boss-status-header",children:s("terminal:building.statusOverview")}),e.jsx("div",{className:"boss-status-grid",children:u.map(h=>{const a=r.get(h);return a?e.jsxs("div",{className:"boss-status-item",children:[e.jsx("span",{className:"boss-status-indicator",style:{backgroundColor:qe[a.status]}}),e.jsx("span",{className:"boss-status-name",children:a.name}),e.jsx("span",{className:"boss-status-label",children:a.status})]},h):null})})]})]}),n&&y&&e.jsxs("div",{className:"form-section boss-logs-section",children:[e.jsxs("label",{className:"form-label",children:[s("terminal:building.unifiedLogs"),e.jsx(j,{text:s("terminal:building.helpUnifiedLogs"),position:"top",size:"sm"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.clearBossStreamingLogs(p),children:s("common:buttons.clear")})]}),e.jsxs("div",{className:"boss-logs-container",ref:v,children:[g.map((h,a)=>e.jsxs("div",{className:"boss-log-entry",children:[e.jsxs("span",{className:"boss-log-source",children:["[",h.subordinateName,"]"]}),e.jsx("span",{className:"boss-log-content",children:qs(h.chunk)})]},a)),g.length===0&&e.jsx("div",{className:"boss-logs-empty",children:s("terminal:building.waitingForLogs")})]})]})]})}function va({startCmd:r,setStartCmd:p,stopCmd:u,setStopCmd:x,restartCmd:n,setRestartCmd:y,healthCheckCmd:C,setHealthCheckCmd:g,logsCmd:v,setLogsCmd:s,isEditMode:h,handleCommand:a}){const{t}=B(["terminal","common"]);return e.jsxs("div",{className:"form-section commands-section",children:[e.jsxs("label",{className:"form-label",children:[t("terminal:building.commands"),e.jsx(j,{text:t("terminal:building.helpCommands"),title:t("terminal:building.commands"),position:"top",size:"sm"})]}),e.jsxs("div",{className:"command-inputs",children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdStart"),e.jsx(j,{text:t("terminal:building.helpCmdStart"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:r,onChange:c=>p(c.target.value),placeholder:"npm run dev"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>a("start"),disabled:!r,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdStop"),e.jsx(j,{text:t("terminal:building.helpCmdStop"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:u,onChange:c=>x(c.target.value),placeholder:"pkill -f 'npm run dev'"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>a("stop"),disabled:!u,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdRestart"),e.jsx(j,{text:t("terminal:building.helpCmdRestart"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:n,onChange:c=>y(c.target.value),placeholder:"npm run restart"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>a("restart"),disabled:!n,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdHealthCheck"),e.jsx(j,{text:t("terminal:building.helpCmdHealthCheck"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:c=>g(c.target.value),placeholder:"curl -s http://localhost:3000/health"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>a("healthCheck"),disabled:!C,children:t("terminal:building.check")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdLogs"),e.jsx(j,{text:t("terminal:building.helpCmdLogs"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:v,onChange:c=>s(c.target.value),placeholder:"tail -n 100 /var/log/app.log"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>a("logs"),children:t("terminal:building.fetch")})]})]})]})}const fa=[{value:"",label:"Default ($SHELL)"},{value:"/bin/bash",label:"Bash"},{value:"/bin/zsh",label:"Zsh"},{value:"/usr/bin/fish",label:"Fish"},{value:"/bin/sh",label:"sh"}];function Na({terminalShell:r,setTerminalShell:p,terminalPort:u,setTerminalPort:x,terminalSaveSession:n,setTerminalSaveSession:y,terminalArgs:C,setTerminalArgs:g,isEditMode:v,building:s,handleCommand:h,onOpenTerminal:a,onOpenBelow:t}){const{t:c}=B(["config"]),i=(s==null?void 0:s.status)==="running",f=s==null?void 0:s.terminalStatus;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:c("config:buildings.terminalConfig",{defaultValue:"Terminal Configuration"})}),e.jsxs("div",{className:"form-row",children:[e.jsxs("div",{className:"form-field",children:[e.jsx("label",{className:"form-sublabel",children:c("config:buildings.terminalShell",{defaultValue:"Shell"})}),e.jsx("select",{className:"form-input",value:r,onChange:b=>p(b.target.value),children:fa.map(b=>e.jsx("option",{value:b.value,children:b.label},b.value))})]}),e.jsxs("div",{className:"form-field",children:[e.jsx("label",{className:"form-sublabel",children:c("config:buildings.terminalPort",{defaultValue:"Port"})}),e.jsx("input",{type:"number",className:"form-input",value:u,onChange:b=>x(b.target.value),placeholder:"Auto",min:1024,max:65535})]})]}),e.jsx("div",{className:"form-row",style:{marginTop:"8px"},children:e.jsxs("label",{className:"form-checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n,onChange:b=>y(b.target.checked)}),e.jsx("span",{children:c("config:buildings.terminalSaveSession",{defaultValue:"Persist session (tmux)"})})]})}),e.jsxs("div",{style:{marginTop:"8px"},children:[e.jsx("label",{className:"form-sublabel",children:c("config:buildings.terminalArgs",{defaultValue:"Extra ttyd args"})}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:b=>g(b.target.value),placeholder:"--client-option titleFixed=Terminal"}),e.jsx("div",{className:"form-hint",children:"Additional command-line arguments passed to ttyd"})]})]}),v&&s&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:c("config:buildings.terminalControls",{defaultValue:"Terminal Controls"})}),f&&e.jsxs("div",{className:"building-runtime-info",children:[e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Proxy"}),e.jsx("span",{className:"runtime-value",style:{color:"#4a9eff"},children:f.url})]}),e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"PID"}),e.jsx("span",{className:"runtime-value",children:f.pid})]}),e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Port"}),e.jsx("span",{className:"runtime-value",children:f.port})]}),f.tmuxSession&&e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Session"}),e.jsx("span",{className:"runtime-value",children:f.tmuxSession})]})]}),e.jsxs("div",{className:"building-actions",style:{marginTop:"8px"},children:[!i&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>h("start"),children:[e.jsx(F,{name:"play",size:12})," Start"]}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>h("restart"),children:[e.jsx(F,{name:"refresh",size:12})," Restart"]}),e.jsxs("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>h("stop"),children:[e.jsx(F,{name:"stop",size:12})," Stop"]}),(f==null?void 0:f.url)&&e.jsxs(e.Fragment,{children:[a&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-primary",onClick:()=>a(f.url),children:[e.jsx(F,{name:"desktop",size:12})," Modal"]}),t&&s&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-primary",onClick:()=>t(s.id),children:[e.jsx(F,{name:"arrow-down",size:12})," Below"]})]})]})]})]})]})}function ka({logs:r,buildingId:p,logsContainerRef:u}){return e.jsxs("div",{className:"form-section logs-section",children:[e.jsxs("label",{className:"form-label",children:["Logs",e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.clearBuildingLogs(p),children:"Clear"})]}),e.jsx("div",{className:"logs-container",ref:u,children:r.map((x,n)=>e.jsx("pre",{className:"log-entry",children:qs(x)},n))})]})}function wa({isOpen:r,onClose:p,buildingId:u,initialPosition:x}){const{t:n}=B(["config","common"]),{buildings:y,buildingLogs:C,bossStreamingLogs:g}=na(),v=la(),s=u?y.get(u):null,h=u?g.get(u)||[]:[],a=!!s,[t,c]=m.useState(""),[i,f]=m.useState("server"),[b,L]=m.useState("server-rack"),[T,A]=m.useState(""),[$,R]=m.useState(""),[K,I]=m.useState(""),[H,O]=m.useState(""),[d,z]=m.useState(""),[q,V]=m.useState(""),[k,_]=m.useState(""),[M,l]=m.useState([]),[S,U]=m.useState(!1),[E,J]=m.useState(""),[W,ee]=m.useState(1),[Z,te]=m.useState(!1),[Ge,ne]=m.useState(""),[Ye,le]=m.useState(""),[Je,ie]=m.useState(""),[We,re]=m.useState(""),[Ze,oe]=m.useState(""),[Vs,ce]=m.useState(!1),[P,de]=m.useState("container"),[me,ue]=m.useState(""),[Xe,pe]=m.useState(""),[he,xe]=m.useState(""),[be,je]=m.useState([]),[ge,ve]=m.useState([]),[Qe,fe]=m.useState(""),[Ne,ke]=m.useState(""),[ye,Ce]=m.useState(""),[es,Se]=m.useState("unless-stopped"),[ss,we]=m.useState("missing"),[Pe,De]=m.useState(""),[Ee,ze]=m.useState(""),[Le,Ae]=m.useState(""),[Be,Te]=m.useState([]),[Gs,Ys]=m.useState(!1),[Re,Ie]=m.useState([]),[as,Oe]=m.useState(void 0),[ts,_e]=m.useState(""),[Me,Fe]=m.useState(""),[ns,$e]=m.useState(!1),[ls,Ke]=m.useState(""),is=m.useRef(null),Js=m.useRef(null),se=m.useRef(null);m.useEffect(()=>{var o,N,w,G,ds,ms,us,ps,hs,xs,bs,js,gs,vs,fs,Ns,ks,ys,Cs,Ss,ws,Ps,Ds,Es,zs,Ls,As,Bs,Ts,Rs,Is,Os,_s;r&&(s?(c(s.name),f(s.type),L(s.style||"server-rack"),A(s.color||""),R(s.cwd||""),I(((o=s.commands)==null?void 0:o.start)||""),O(((N=s.commands)==null?void 0:N.stop)||""),z(((w=s.commands)==null?void 0:w.restart)||""),V(((G=s.commands)==null?void 0:G.healthCheck)||""),_(((ds=s.commands)==null?void 0:ds.logs)||""),l(s.urls||[]),J(s.folderPath||""),ee(s.scale||1),te(((ms=s.pm2)==null?void 0:ms.enabled)||!1),ne(((us=s.pm2)==null?void 0:us.script)||""),le(((ps=s.pm2)==null?void 0:ps.args)||""),ie(((hs=s.pm2)==null?void 0:hs.interpreter)||""),re(((xs=s.pm2)==null?void 0:xs.interpreterArgs)||""),oe((bs=s.pm2)!=null&&bs.env?Object.entries(s.pm2.env).map(([Y,He])=>`${Y}=${He}`).join(`
|
|
6
|
+
`):""),de(((js=s.docker)==null?void 0:js.mode)||"container"),ue(((gs=s.docker)==null?void 0:gs.mode)==="existing"&&((vs=s.docker)==null?void 0:vs.containerName)||""),pe(((fs=s.docker)==null?void 0:fs.image)||""),xe(((Ns=s.docker)==null?void 0:Ns.containerName)||""),je(((ks=s.docker)==null?void 0:ks.ports)||[]),ve(((ys=s.docker)==null?void 0:ys.volumes)||[]),fe((Cs=s.docker)!=null&&Cs.env?Object.entries(s.docker.env).map(([Y,He])=>`${Y}=${He}`).join(`
|
|
7
|
+
`):""),ke(((Ss=s.docker)==null?void 0:Ss.network)||""),Ce(((ws=s.docker)==null?void 0:ws.command)||""),Se(((Ps=s.docker)==null?void 0:Ps.restart)||"unless-stopped"),we(((Ds=s.docker)==null?void 0:Ds.pull)||"missing"),De(((Es=s.docker)==null?void 0:Es.composePath)||""),ze(((zs=s.docker)==null?void 0:zs.composeProject)||""),Ae(((As=(Ls=s.docker)==null?void 0:Ls.services)==null?void 0:As.join(", "))||""),Te(s.subordinateBuildingIds||[]),Ie(((Bs=s.database)==null?void 0:Bs.connections)||[]),Oe((Ts=s.database)==null?void 0:Ts.activeConnectionId),_e(((Rs=s.terminal)==null?void 0:Rs.shell)||""),Fe((Is=s.terminal)!=null&&Is.port?String(s.terminal.port):""),$e(((Os=s.terminal)==null?void 0:Os.saveSession)||!1),Ke(((_s=s.terminal)==null?void 0:_s.args)||"")):(c("New Server"),f("server"),L("server-rack"),A(""),R(ia(ra.LAST_CWD)),I(""),O(""),z(""),V(""),_(""),l([]),J(""),ee(1),te(!1),ne(""),le(""),ie(""),re(""),oe(""),de("container"),ue(""),pe(""),xe(""),je([]),ve([]),fe(""),ke(""),Ce(""),Se("unless-stopped"),we("missing"),De(""),ze(""),Ae(""),Te([]),Ie([]),Oe(void 0),_e(""),Fe(""),$e(!1),Ke("")),setTimeout(()=>{var Y;return(Y=is.current)==null?void 0:Y.focus()},100))},[r,s]),m.useEffect(()=>{se.current&&(se.current.scrollTop=se.current.scrollHeight)},[C]),m.useEffect(()=>{i==="docker"&&P==="existing"&&D.requestDockerContainersList()},[i,P]);const rs=o=>{if(o.trim())return Object.fromEntries(o.trim().split(`
|
|
8
|
+
`).map(N=>N.trim()).filter(N=>N&&N.includes("=")).map(N=>{const w=N.indexOf("=");return[N.slice(0,w),N.slice(w+1)]}))},Ws=o=>{o.preventDefault();const N={name:t,type:i,style:b,color:T||void 0,position:x||(s==null?void 0:s.position)||{x:0,z:0},cwd:$||void 0,folderPath:E||void 0,commands:Z?void 0:{start:K||void 0,stop:H||void 0,restart:d||void 0,healthCheck:q||void 0,logs:k||void 0},pm2:Z?{enabled:!0,script:Ge,args:Ye||void 0,interpreter:Je||void 0,interpreterArgs:We||void 0,env:rs(Ze)}:void 0,docker:i==="docker"?{enabled:!0,mode:P,image:P==="container"?Xe:void 0,containerName:P==="container"&&he?he:P==="existing"&&me?me:void 0,ports:P==="container"&&be.length>0?be:void 0,volumes:P==="container"&&ge.length>0?ge:void 0,env:rs(Qe),network:P==="container"&&Ne?Ne:void 0,command:P==="container"&&ye?ye:void 0,restart:P==="container"?es:void 0,pull:P!=="existing"?ss:void 0,composePath:P==="compose"&&Pe?Pe:void 0,composeProject:P==="compose"&&Ee?Ee:void 0,services:P==="compose"&&Le?Le.split(",").map(w=>w.trim()).filter(w=>w):void 0}:void 0,urls:M.length>0?M:void 0,scale:W!==1?W:void 0,subordinateBuildingIds:i==="boss"&&Be.length>0?Be:void 0,database:i==="database"&&Re.length>0?{connections:Re,activeConnectionId:as}:void 0,terminal:i==="terminal"?{enabled:!0,shell:ts||void 0,port:Me?parseInt(Me,10):void 0,saveSession:ns||void 0,args:ls||void 0}:void 0};a&&u?D.updateBuilding(u,N):D.createBuilding(N),p()},Zs=()=>{ce(!0)},Xs=()=>{u&&(D.deleteBuilding(u),ce(!1),p())},ae=o=>{u&&(D.sendBuildingCommand(u,o),o==="logs"&&U(!0))},Qs=()=>{l([...M,{label:"",url:""}])},ea=o=>{l(M.filter((N,w)=>w!==o))},os=(o,N,w)=>{const G=[...M];G[o]={...G[o],[N]:w},l(G)},{handleMouseDown:sa,handleClick:aa}=oa(p);if(!r)return null;const cs=u?D.getBuildingLogs(u):[];return e.jsxs("div",{className:"modal-overlay visible",onMouseDown:sa,onClick:aa,children:[e.jsxs("div",{className:"modal building-config-modal",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("span",{children:n(a?"config:buildings.editBuilding":"config:buildings.addBuilding")}),a&&s&&e.jsx("span",{className:"building-status-badge",style:{backgroundColor:qe[s.status]},children:s.status})]}),e.jsxs("form",{onSubmit:Ws,children:[e.jsxs("div",{className:"modal-body",children:[e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("common:labels.name")}),e.jsx("input",{ref:is,type:"text",className:"form-input",value:t,onChange:o=>c(o.target.value),placeholder:n("config:buildings.namePlaceholder"),required:!0})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("common:labels.type")}),e.jsx("div",{className:"building-type-selector",children:Object.keys(Ks).map(o=>e.jsxs("button",{type:"button",className:`building-type-btn ${i===o?"active":""}`,onClick:()=>{f(o),o==="database"&&b==="server-rack"&&L("filing-cabinet"),o==="tests"&&b==="server-rack"&&L("dome"),o==="http"&&b==="server-rack"&&L("satellite")},title:Ks[o].description,children:[e.jsx("span",{className:"building-type-icon",children:e.jsx(F,{name:Us(o),size:16})}),e.jsx("span",{className:"building-type-name",children:o})]},o))})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("config:buildings.style")}),e.jsx("div",{className:"building-style-selector",children:Object.keys(Ue).map(o=>e.jsxs("button",{type:"button",className:`building-style-btn ${b===o?"active":""}`,onClick:()=>L(o),title:Ue[o].description,children:[e.jsx("span",{className:"building-style-preview","data-style":o}),e.jsx("span",{className:"building-style-name",children:Ue[o].label})]},o))})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("common:labels.color")}),e.jsxs("div",{className:"building-color-selector",children:[ca.map(o=>e.jsx("button",{type:"button",className:`building-color-btn ${T===o.value?"active":""}`,onClick:()=>A(o.value),title:da(o.labelKey),style:o.value?{backgroundColor:o.value}:void 0,children:!o.value&&e.jsx("span",{className:"color-default-icon",children:e.jsx(F,{name:"gear",size:12})})},o.value||"default")),e.jsx("input",{type:"color",className:"building-color-picker",value:T||"#2a2a3a",onChange:o=>A(o.target.value),title:"Custom color"})]})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("common:labels.size")}),e.jsxs("div",{className:"building-size-control",children:[e.jsxs("div",{className:"size-slider-row",children:[e.jsx("input",{type:"range",className:"size-slider",min:"0",max:"100",step:"1",value:Math.log(W/.1)/Math.log(100)*100,onChange:o=>{const N=parseFloat(o.target.value),w=.1*Math.pow(100,N/100);ee(Math.round(w*100)/100)}}),e.jsxs("span",{className:"size-value",children:[W.toFixed(2),"x"]})]}),e.jsx("div",{className:"size-presets",children:[.5,.75,1,1.25,1.5,2].map(o=>e.jsxs("button",{type:"button",className:`size-preset-btn ${W===o?"active":""}`,onClick:()=>ee(o),children:[o,"x"]},o))})]})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("config:buildings.directory")}),e.jsx(Q,{value:$,onChange:R,placeholder:"/path/to/project",className:"form-input",directoriesOnly:!0})]}),i==="folder"&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("config:buildings.folderPath")}),e.jsx(Q,{value:E,onChange:J,placeholder:"/path/to/folder",className:"form-input",directoriesOnly:!0}),e.jsx("div",{className:"form-hint",children:"Click this building to open the file explorer at this path"})]}),i==="tests"&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:"Tests Folder"}),e.jsx(Q,{value:E,onChange:J,placeholder:"/path/to/project/src/test",className:"form-input",directoriesOnly:!0}),e.jsx("div",{className:"form-hint",children:"Click this building to browse, search and run the tests of this folder (any folder inside a Maven module works)"})]}),i==="http"&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:"Requests Folder"}),e.jsx(Q,{value:E,onChange:J,placeholder:"/path/to/project/http-requests",className:"form-input",directoriesOnly:!0}),e.jsx("div",{className:"form-hint",children:"Click this building to browse and fire the .http request files of this folder (IntelliJ HTTP Client style; http-client.env.json environments supported)"})]}),i==="boss"&&e.jsx(ga,{buildings:y,buildingId:u,subordinateBuildingIds:Be,setSubordinateBuildingIds:Te,isEditMode:a,showBossLogs:Gs,setShowBossLogs:Ys,currentBossLogs:h,bossLogsContainerRef:Js}),i==="database"&&e.jsx(ja,{dbConnections:Re,setDbConnections:Ie,activeDbConnectionId:as,setActiveDbConnectionId:Oe}),i==="server"&&e.jsx(pa,{usePM2:Z,setUsePM2:te}),i==="server"&&e.jsx(ha,{usePM2:Z,pm2Script:Ge,setPm2Script:ne,pm2Args:Ye,setPm2Args:le,pm2Interpreter:Je,setPm2Interpreter:ie,pm2InterpreterArgs:We,setPm2InterpreterArgs:re,pm2Env:Ze,setPm2Env:oe,isEditMode:a,building:s??null,handleCommand:ae}),i==="docker"&&e.jsx(xa,{dockerMode:P,setDockerMode:de,dockerImage:Xe,setDockerImage:pe,dockerContainerName:he,setDockerContainerName:xe,dockerCommand:ye,setDockerCommand:Ce,dockerPorts:be,setDockerPorts:je,dockerVolumes:ge,setDockerVolumes:ve,dockerNetwork:Ne,setDockerNetwork:ke,dockerRestart:es,setDockerRestart:Se,dockerPull:ss,setDockerPull:we,dockerEnv:Qe,setDockerEnv:fe,dockerComposePath:Pe,setDockerComposePath:De,dockerComposeProject:Ee,setDockerComposeProject:ze,dockerComposeServices:Le,setDockerComposeServices:Ae,selectedExistingContainer:me,setSelectedExistingContainer:ue,dockerContainersList:v,isEditMode:a,building:s??null,handleCommand:ae}),i==="terminal"&&e.jsx(Na,{terminalShell:ts,setTerminalShell:_e,terminalPort:Me,setTerminalPort:Fe,terminalSaveSession:ns,setTerminalSaveSession:$e,terminalArgs:ls,setTerminalArgs:Ke,isEditMode:a,building:s??null,handleCommand:ae,onOpenTerminal:()=>{s!=null&&s.id&&window.dispatchEvent(new CustomEvent("tide:open-iframe-modal",{detail:{buildingId:s.id}}))},onOpenBelow:o=>{window.dispatchEvent(new CustomEvent("tide:open-bottom-terminal",{detail:{buildingId:o}}))}}),i==="server"&&!Z&&e.jsx(va,{startCmd:K,setStartCmd:I,stopCmd:H,setStopCmd:O,restartCmd:d,setRestartCmd:z,healthCheckCmd:q,setHealthCheckCmd:V,logsCmd:k,setLogsCmd:_,isEditMode:a,handleCommand:ae}),e.jsxs("div",{className:"form-section",children:[e.jsxs("label",{className:"form-label",children:[n("config:buildings.links"),e.jsxs("button",{type:"button",className:"btn btn-sm btn-add",onClick:Qs,children:["+ ",n("common:buttons.add")]})]}),M.map((o,N)=>e.jsxs("div",{className:"url-row",children:[e.jsx("input",{type:"text",className:"form-input url-label",value:o.label,onChange:w=>os(N,"label",w.target.value),placeholder:"Label"}),e.jsx("input",{type:"text",className:"form-input url-value",value:o.url,onChange:w=>os(N,"url",w.target.value),placeholder:"https://..."}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>ea(N),children:"x"})]},N))]}),a&&S&&cs.length>0&&e.jsx(ka,{logs:cs,buildingId:u,logsContainerRef:se})]}),e.jsxs("div",{className:"modal-footer",children:[a&&e.jsx("button",{type:"button",className:"btn btn-danger",onClick:Zs,children:n("common:buttons.delete")}),e.jsx("div",{className:"footer-spacer"}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:p,children:n("common:buttons.cancel")}),e.jsx("button",{type:"submit",className:"btn btn-primary",children:n(a?"common:buttons.save":"common:buttons.create")})]})]})]}),Vs&&s&&e.jsx(ua,{buildingName:s.name,onClose:()=>ce(!1),onConfirm:Xs})]})}export{wa as BuildingConfigModal};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{r as n,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 Cn,X as Ft,S,Y as Wt,Z as Dt,_ as Ht,$ as wt,a0 as fe,a1 as jn,s as b,a2 as en,a3 as tn,a4 as Nn,w as Ut,x as Xt,I as p,a5 as kn,n as yn,a6 as An,a7 as nn,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 On,al as Vt,C as Bn,am as Fn,an as Gt,ao as Wn,ap as Hn,aq as Un,ar as Xn,as as Vn,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,aF as ia}from"./main-CAE1L3Sb.js";import{g as la}from"./area-logos-CPBT7k6a.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function ra(d){const r=n.useRef(d);r.current=d,n.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 oa(d){const r=Zt(),m=await fetch(`${Jt()}/api/agents/${d}/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 ca(d){const r=Zt();await fetch(`${Jt()}/api/agents/${d}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${r}`}})}const lt=new Map;function da({agentId:d}){const[r,m]=n.useState(null),[h,N]=n.useState(null);return n.useEffect(()=>{let P=!1;const I=lt.get(d);return I&&(clearTimeout(I),lt.delete(d)),m(null),N(null),oa(d).then(D=>{P||m(D.url)}).catch(D=>{P||N(D instanceof Error?D.message:"Failed to start terminal")}),()=>{P=!0;const D=lt.get(d);D&&clearTimeout(D),lt.set(d,setTimeout(()=>{lt.delete(d),ca(d)},2500))}},[d]),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,ua=6e4;function pa({agentId:d,contextSummary:r}){const{t:m}=Rt(["terminal","common"]),[h,N]=n.useState(()=>{var M;return((M=Pt.get(d))==null?void 0:M.snapshot)??null}),[P,I]=n.useState(!1),[D,q]=n.useState(null),_=n.useRef(0);n.useEffect(()=>{const M=Pt.get(d);if(M&&Date.now()-M.fetchedAt<ua){N(M.snapshot);return}const B=++_.current;I(!0),q(null),hn(d).then(X=>{B===_.current&&(Pt.set(d,{snapshot:X,fetchedAt:Date.now()}),N(X),I(!1))}).catch(X=>{B===_.current&&(q(X.message||"Failed to load plan limits"),I(!1))})},[d]);const R=[];if(h!=null&&h.rateLimits){const M=[{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 B of M)B.window&&R.push({...B,window:B.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&&D&&!h&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:m("terminal:usage.limitsError",{message:D})}),R.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:R.map(({key:M,label:B,window:X})=>{const he=Math.max(0,Math.min(100,X.utilization)),te=xn(he);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:B}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:te},children:m("terminal:usage.percentUsed",{percent:Math.round(he)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${he}%`,background:te}})}),e.jsx("div",{className:"plan-limits-tooltip__reset",children:m("terminal:usage.resets",{time:gn(X.resetsAt)})})]},M)})}):h&&!P&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:h.rateLimitsError?m("terminal:usage.limitsError",{message:h.rateLimitsError}):h.cliHint})]})}function ma({agentId:d,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(pa,{agentId:d,contextSummary:m}),children:h})}const fa=n.memo(function({className:r=""}){const{t:m}=Rt(["common"]),[h,N]=bn(),P=n.useRef(null),[I,D]=n.useState(null);n.useLayoutEffect(()=>{const _=P.current;if(!_)return;const R=_.querySelector(".view-mode-toggle__btn--active");R&&D({left:R.offsetLeft,width:R.offsetWidth})},[h]);const q=n.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:[I&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:I.left,width:I.width}}),_n.map(_=>e.jsxs("button",{className:`view-mode-toggle__btn ${h===_?"view-mode-toggle__btn--active":""}`,onClick:()=>q(_),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.${_}`)})]},_))]})}),vt=3,Ct=280,qt=320,Lt=240,Yt=64,ha=["simple","chat","advanced"],ga={simple:"Simple",chat:"Chat",advanced:"Advanced"},xa={simple:"○",chat:"◐",advanced:"◉"},ba={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 _a(d){const r=d.split("/").filter(Boolean);return r.length===0?d:r.slice(-2).join("/")}function wa(d){if(d.provider==="codex"){const P=d.codexModel||"gpt-5.3-codex",I=aa[P];return{model:(I==null?void 0:I.label)||P}}if(d.provider==="opencode")return{model:d.opencodeModel||"opencode"};const r=d.model||"sonnet",m=ia[r],h=d.effort,N=h?sa[h]:void 0;return{model:(m==null?void 0:m.label)||r,effort:N==null?void 0:N.label}}function va(d,r){if(r.type==="rectangle"&&r.width&&r.height){const m=r.width/2,h=r.height/2;return d.x>=r.center.x-m&&d.x<=r.center.x+m&&d.z>=r.center.z-h&&d.z<=r.center.z+h}if(r.type==="circle"&&r.radius){const m=d.x-r.center.x,h=d.z-r.center.z;return m*m+h*h<=r.radius*r.radius}return!1}const Ca=Fn.memo(function({agentId:r,terminalViewMode:m,onTerminalViewModeChange:h,inspectorOpen:N,onToggleInspector:P,onImageClick:I,onFileClick:D,onBashClick:q,onViewMarkdown:_,onRequestClearSubordinates:R,onOpenBuilding:M,keyboard:B,canNavigateBack:X,canNavigateForward:he,onNavigateBack:te,onNavigateForward:ge,agentInfoOpen:Ae,onToggleAgentInfo:rt,onHeaderContextMenu:ae,onBuildingContextMenu:se}){var ht,ee,qe,st;const f=Gt(r),z=tn(),xe=Wn(),Se=n.useRef(null),ze=n.useRef(null),{displayedAgentId:be,fadingOut:jt}=Hn(r),ot=Gt(be),Oe=!!xe.interactiveMode&&((f==null?void 0:f.provider)??"claude")==="claude"&&!!(f!=null&&f.sessionId),[ne,Be]=n.useState(!1);n.useEffect(()=>{Be(!1)},[r]),n.useEffect(()=>{!Oe&&ne&&Be(!1)},[Oe,ne]),n.useEffect(()=>{const s=ze.current;if(!s)return;const l=u=>{u.button===3?(u.preventDefault(),u.stopPropagation(),te()):u.button===4&&(u.preventDefault(),u.stopPropagation(),ge())},o=u=>{(u.button===3||u.button===4)&&u.preventDefault()};return s.addEventListener("mouseup",l),s.addEventListener("mousedown",o),()=>{s.removeEventListener("mouseup",l),s.removeEventListener("mousedown",o)}},[te,ge]),n.useEffect(()=>{const s=ze.current;if(!s)return;let l=0,o=0,u=0;const me=250,Ye=600,V=80,Et=1.5,Ke=G=>{let L=G instanceof HTMLElement?G:null;for(;L&&L!==s;){const De=window.getComputedStyle(L).overflowX;if((De==="auto"||De==="scroll")&&L.scrollWidth>L.clientWidth)return!0;L=L.parentElement}return!1},gt=G=>{const L=Date.now();if(L<u){G.preventDefault();return}if(Math.abs(G.deltaX)<=Math.abs(G.deltaY)*Et){l=0;return}if(Ke(G.target)){l=0;return}L-o>me&&(l=0),o=L,l+=G.deltaX,l<=-V?(l=0,u=L+Ye,G.preventDefault(),te()):l>=V&&(l=0,u=L+Ye,G.preventDefault(),ge())};return s.addEventListener("wheel",gt,{passive:!1}),()=>s.removeEventListener("wheel",gt)},[te,ge]);const _e=en(),ie=n.useMemo(()=>{if(!f)return null;const s=new Set,l=[];for(const o of _e.values())o.archived||o.directories.length===0||o.assignedAgentIds.includes(r)&&(s.add(o.id),l.push(o));for(const o of _e.values())o.archived||o.directories.length===0||s.has(o.id)||va({x:f.position.x,z:f.position.z},o)&&(s.add(o.id),l.push(o));return l.length===0?null:l.flatMap(o=>o.directories.filter(u=>u&&u.trim().length>0).map(u=>({areaId:o.id,areaName:o.name,dir:u})))},[f,r,_e]),{branches:le,fetchRemote:re,fetchingDirs:ct}=Un(ie),Fe=n.useMemo(()=>{var o;const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const u of z.values())u.type==="terminal"&&b.isPositionInArea(u.position,s)&&l.push({id:u.id,name:u.name,hasUrl:!!((o=u.terminalStatus)!=null&&o.url)});return l},[r,z]),Ee=n.useMemo(()=>{var o;const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const u of z.values())u.type==="server"&&((o=u.pm2)!=null&&o.enabled)&&b.isPositionInArea(u.position,s)&&l.push({id:u.id,name:u.name});return l},[r,z]),we=n.useMemo(()=>{const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const o of z.values())o.type==="database"&&o.database&&b.isPositionInArea(o.position,s)&&l.push({id:o.id,name:o.name});return l},[r,z]),ve=Xn(),Me=n.useMemo(()=>{const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const o of z.values())if(o.type==="tests"&&b.isPositionInArea(o.position,s)){const u=!!o.folderPath&&ve.some(me=>Vn(me,o.folderPath));l.push({id:o.id,name:o.name,working:u})}return l},[r,z,ve]),Y=n.useMemo(()=>{const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const o of z.values())o.type==="http"&&b.isPositionInArea(o.position,s)&&l.push({id:o.id,name:o.name});return l},[r,z]),[,We]=n.useReducer(s=>s+1,0),K=((ht=Se.current)==null?void 0:ht.search.searchMode)??!1,Ce=n.useCallback(()=>{var s;(s=Se.current)==null||s.search.toggleSearch(),We()},[]),dt=Gn(),Ze=dt.isPending(Kt),[oe,ce]=n.useState(null),je=oe?z.get(oe):null,{height:Nt,onResizeStart:Ie}=qn(),{sidePanelWidth:kt,handleSidePanelResizeStart:ut}=Yn(),[Te,He]=n.useState(()=>Dt(S.GIT_PANEL_OPEN,!1)),[Pe,pt]=n.useState(()=>Dt(S.BUILDINGS_PANEL_OPEN,!1)),[Le,mt]=n.useState(!1),yt=n.useCallback(()=>{mt(s=>{const l=!s;return l&&Kn.setEnabled(!0),l})},[]),At=n.useCallback(()=>mt(!1),[]),Ue=n.useCallback(()=>{He(s=>{const l=!s;return fe(S.GIT_PANEL_OPEN,l),l})},[]),v=n.useCallback(()=>{pt(s=>{const l=!s;return fe(S.BUILDINGS_PANEL_OPEN,l),l})},[]),de=n.useCallback(()=>{He(!1),fe(S.GIT_PANEL_OPEN,!1)},[]),Z=n.useCallback(()=>{pt(!1),fe(S.BUILDINGS_PANEL_OPEN,!1)},[]),Xe=Zn();n.useEffect(()=>{if(!oe)return;Fe.some(l=>l.id===oe)||ce(null)},[oe,Fe]);const[Ne,ke]=n.useState(!1),Je=n.useRef(null);if(n.useEffect(()=>{if(!Ne)return;const s=l=>{Je.current&&!Je.current.contains(l.target)&&ke(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[Ne]),!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 ue=f.contextStats,Qe=!!ue,Ve=ue?ue.totalTokens:f.contextUsed||0,ye=ue?ue.contextWindow:f.contextLimit||2e5,et=ue?ue.usedPercent:Math.round(Ve/ye*100),U=Math.max(0,Math.min(100,et)),ft=Math.round(U*10)/10,J=Math.round((100-U)*10)/10,pe=U>=80?"#ff4a4a":U>=60?"#ff9e4a":U>=40?"#ffd700":"#4aff9e",tt=(Ve/1e3).toFixed(1),nt=(ye/1e3).toFixed(1),Q=f.cwd,at=Q?_a(Q):null,Ge=((ee=f.subordinateIds)==null?void 0:ee.length)||0,St=Ge>0;return e.jsxs("div",{ref:ze,className:`flat-terminal-wrapper ${Te||Pe||Le?"flat-terminal-wrapper--with-side-panel":""} ${jt?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${kt}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${Ae?"flat-terminal-wrapper__header-main--active":""}`,onClick:rt,onContextMenu:s=>{s.preventDefault(),s.stopPropagation(),ae({x:s.clientX,y:s.clientY})},title:Ae?"Hide agent info":"Show agent info","aria-pressed":Ae,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}=wa(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:[ha.map(s=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!ne&&m===s?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Be(!1),h(s)},title:ba[s],"aria-pressed":!ne&&m===s,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:xa[s]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:ga[s]})]},s)),Oe&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${ne?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Be(s=>!s),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":ne,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:te,disabled:!X,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:ge,disabled:!he,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 ${K?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Ce,title:K?"Close search":"Search messages","aria-pressed":K,children:e.jsx(p,{name:K?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Ze?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>dt.handleClick(Kt,()=>{var s;b.clearContext(r),(s=Se.current)==null||s.historyLoader.clearHistory()}),title:Ze?"Click again to confirm clear context":"Clear context",children:e.jsx(p,{name:Ze?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Te?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Ue,title:Te?"Hide git panel":"Show git changes","aria-pressed":Te,children:e.jsx(p,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Pe?"flat-terminal-wrapper__action-btn--active":""}`,onClick:v,title:Pe?"Hide buildings panel":"Show area buildings","aria-pressed":Pe,children:e.jsx(p,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:Je,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Ne?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>ke(s=>!s),title:"More actions","aria-expanded":Ne,children:"⋮"}),Ne&&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 ${Le?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{yt(),ke(!1)},title:Le?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(p,{name:"bug",size:14}),e.jsx("span",{children:Le?"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),ke(!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:()=>{R(r,Ge),ke(!1)},children:[e.jsx(p,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",Ge," subordinate",Ge===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),ke(!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})})]})]}),ne&&Oe?e.jsx(da,{agentId:r}):be&&ot?e.jsx(Jn,{ref:Se,agentId:be,agent:ot,viewMode:m,isOpen:!0,onImageClick:I,onFileClick:D,onBashClick:q,onViewMarkdown:_,keyboard:B,hasModalOpen:!1},be):null,je&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:Ie,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${je.name}`,style:{height:Nt},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:je.name}),!((qe=je.terminalStatus)!=null&&qe.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>ce(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:(st=je.terminalStatus)!=null&&st.url?e.jsx(Qt,{terminalUrl:je.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"})]}),Q&&at&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${Q}`,"aria-label":`Open ${Q} in file explorer`,role:"button",tabIndex:0,onClick:()=>b.openFileExplorer(Q),onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),b.openFileExplorer(Q))},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:at})]}),ie&&ie.map(({areaId:s,areaName:l,dir:o})=>{const u=le.get(o),me=ct.has(o),Ye=o.split("/").filter(Boolean).pop()||o;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${l}: ${o}${u?` (${u.branch}${u.ahead?` ↑${u.ahead}`:""}${u.behind?` ↓${u.behind}`:""})`:""}`,onClick:()=>b.openFileExplorerForAreaFolder(s,o),children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:Ye}),u&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(p,{name:"git-branch",size:10})," ",u.branch]}),u.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${u.ahead} ahead`,children:[e.jsx(p,{name:"arrow-up",size:9}),u.ahead]}),u.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${u.behind} behind`,children:[e.jsx(p,{name:"arrow-down",size:9}),u.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${me?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:V=>{V.stopPropagation(),re(o)},children:e.jsx(p,{name:me?"hourglass":"download",size:12})})]})]},`${s}:${o}`)}),e.jsx(ma,{agentId:r,disabled:((f==null?void 0:f.provider)??"claude")!=="claude",contextSummary:Qe?`Context: ${tt}k / ${nt}k tokens (${ft}% 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"?Qe?`Context usage: ${tt}k / ${nt}k tokens (${ft}% 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:`${U}%`,backgroundColor:pe}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:pe},children:[tt,"k/",nt,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",J,"% free)"]}),!Qe&&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"}),Fe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:Fe.map(s=>{const l=oe===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){ce(null);return}s.hasUrl||b.sendBuildingCommand(s.id,"start"),ce(s.id)},onContextMenu:o=>{o.preventDefault(),o.stopPropagation(),se(s.id,{x:o.clientX,y:o.clientY})},children:e.jsx(p,{name:"terminal",size:14})},s.id)})}),Ee.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Ee.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${s.name}`,onClick:()=>M(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),se(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"scroll",size:14})},s.id))}),we.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:we.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${s.name}`,onClick:()=>M(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),se(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"hard-drives",size:14})},s.id))}),Me.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:Me.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:()=>M(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),se(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"flask",size:14})},s.id))}),Y.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area HTTP requests",children:Y.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open HTTP requests: ${s.name}`,onClick:()=>M(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),se(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"globe",size:14})},s.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(Qn,{})})]}),Te&&e.jsx(ea,{agentId:r,agents:Xe,onClose:de,branchInfoMap:le,fetchRemote:re,fetchingDirs:ct,onResizeStart:s=>ut(s,"right")}),Pe&&e.jsx(ta,{agentId:r,onClose:Z}),Le&&e.jsx(na,{agentId:r,onClose:At})]})});function Aa({onAgentClick:d,onBuildingClick:r,onBuildingDoubleClick:m,onBuildingPopup:h,onAreaContextMenu:N,onOpenSpawnModal:P,onOpenBossSpawnModal:I,onOpenAreaModal:D}){const{t:q}=Rt(["common"]),_=wn(),R=vn(),[M,B]=n.useState(null),[X,he]=n.useState(null),[te,ge]=n.useState(null);Cn("flatview-image-modal",M!==null,()=>B(null));const[Ae,rt]=n.useState(null),[ae,se]=n.useState(null),[f,z]=n.useState(null),[xe,Se]=n.useState(null),[ze,be]=n.useState(!1),jt=n.useCallback(()=>{be(t=>!t)},[]),ot=n.useCallback(()=>{be(!1)},[]),[Oe,ne]=n.useState(()=>{const t=Ft(S.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Be=n.useCallback(t=>{ne(t),Wt(S.VIEW_MODE,t)},[]);n.useEffect(()=>{const t=a=>{if(a.key!==S.VIEW_MODE)return;const i=a.newValue;(i==="simple"||i==="chat"||i==="advanced")&&ne(i)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[_e,ie]=n.useState(()=>Dt(S.FLAT_INSPECTOR_OPEN,!1)),[le,re]=n.useState(!1),ct=n.useCallback(()=>re(t=>!t),[]),Fe=n.useCallback(()=>re(!1),[]);n.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:le}}))},[le]),n.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:_e}}))},[_e]),n.useEffect(()=>{const t=()=>re(C=>!C),a=()=>{ie(C=>{const k=!C;return fe(S.FLAT_INSPECTOR_OPEN,k),k})},i=()=>{re(!1),ie(!1),fe(S.FLAT_INSPECTOR_OPEN,!1)},g=()=>re(!1),x=()=>{ie(!1),fe(S.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",a),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",a),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 Ee=n.useRef(null),we=n.useRef(null),[ve,Me]=n.useState(()=>{const t=Ht(S.FLAT_MIDDLE_WIDTH,0);return t>=Ct?t:null}),[Y,We]=n.useState(()=>{const t=Ht(S.FLAT_INSPECTOR_WIDTH,0);return t>=Lt?t:null}),K=n.useCallback(t=>{if(typeof window>"u")return t;const a=Y!==null?vt+Y:0,i=window.innerWidth-Yt-vt-qt-a;return Math.max(Ct,Math.min(Math.max(i,Ct),t))},[Y]),Ce=n.useCallback(t=>{var x;if(typeof window>"u")return t;const a=(x=Ee.current)==null?void 0:x.querySelector(".flat-middle"),i=(a==null?void 0:a.getBoundingClientRect().width)??Ct,g=window.innerWidth-Yt-i-vt-qt-vt;return Math.max(Lt,Math.min(Math.max(g,Lt),t))},[]);n.useEffect(()=>{if(ve===null&&Y===null)return;const t=()=>{Me(a=>{if(a===null)return a;const i=K(a);return i===a?a:i}),We(a=>{if(a===null)return a;const i=Ce(a);return i===a?a:i})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[ve,Y,K,Ce]);const dt=n.useCallback(t=>{var i;if(t.button!==0)return;const a=(i=Ee.current)==null?void 0:i.querySelector(".flat-middle");a&&(t.currentTarget.setPointerCapture(t.pointerId),we.current={kind:"middle",startX:t.clientX,startWidth:a.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Ze=n.useCallback(t=>{var i;if(t.button!==0)return;const a=(i=Ee.current)==null?void 0:i.querySelector(".flat-inspector");a&&(t.currentTarget.setPointerCapture(t.pointerId),we.current={kind:"inspector",startX:t.clientX,startWidth:a.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),oe=n.useCallback(t=>{const a=we.current;if(!a||t.pointerId!==a.pointerId)return;const i=t.clientX-a.startX;a.kind==="middle"?Me(K(a.startWidth+i)):We(Ce(a.startWidth-i))},[K,Ce]),ce=n.useCallback(t=>{const a=we.current;if(!a||t.pointerId!==a.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(we.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-a.startX)>2))return;const g=t.clientX-a.startX;if(a.kind==="middle"){const x=K(a.startWidth+g);Me(x),wt(S.FLAT_MIDDLE_WIDTH,x)}else{const x=Ce(a.startWidth-g);We(x),wt(S.FLAT_INSPECTOR_WIDTH,x)}},[K,Ce]),je=n.useCallback(()=>{Me(null),wt(S.FLAT_MIDDLE_WIDTH,0)},[]),Nt=n.useCallback(()=>{We(null),wt(S.FLAT_INSPECTOR_WIDTH,0)},[]),[Ie,kt]=n.useState(()=>Ft(S.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),ut=n.useCallback(t=>{kt(t),Wt(S.FLAT_INSPECTOR_VIEW,t)},[]),Te=n.useCallback(()=>{ie(t=>{const a=!t;return fe(S.FLAT_INSPECTOR_OPEN,a),a})},[]),He=n.useCallback(()=>{ie(!1),fe(S.FLAT_INSPECTOR_OPEN,!1)},[]),Pe=jn(),pt=n.useCallback((t,a)=>{B({url:t,name:a})},[]),Le=n.useCallback((t,a)=>{he({command:t,output:a,isLive:!1})},[]),mt=n.useCallback((t,a)=>{var x;const i=R.size>0?Array.from(R)[0]:null,g=i?(x=b.getState().agents.get(i))==null?void 0:x.cwd:void 0;b.setFileViewerPath(t,a,g)},[R]),yt=n.useCallback(t=>{ge(t)},[]),At=n.useCallback((t,a)=>{rt({agentId:t,count:a})},[]),Ue=n.useCallback(t=>{m?m(t):r(t)},[r,m]),v=n.useMemo(()=>R.size>0?Array.from(R)[0]:null,[R]);n.useEffect(()=>{be(!1)},[v]);const de=n.useRef([]),Z=n.useRef(-1),Xe=n.useRef(!1),Ne=n.useRef(null),[ke,Je]=n.useState(!1),[ue,Qe]=n.useState(!1),Ve=n.useRef(!1),ye=n.useRef(null),et=n.useRef(!1),U=n.useMemo(()=>new Set(_.map(t=>t.id)),[_]),ft=n.useMemo(()=>{const t=new Map(_.map(i=>[i.id,i])),a=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&&a.set(i.id,g)}return a},[_]),J=n.useCallback(()=>{const t=de.current,a=Z.current;Je(a>0),Qe(a>=0&&a<t.length-1)},[]),pe=n.useCallback(t=>{const a=de.current;if(a.length===0)return;let i=Z.current+t;for(;i>=0&&i<a.length;){const g=a[i];if(U.has(g)){Xe.current=!0,Z.current=i,J(),b.selectAgent(g);return}i+=t}},[U,J]),tt=n.useCallback(()=>pe(-1),[pe]),nt=n.useCallback(()=>pe(1),[pe]);ra(n.useCallback(()=>{const t=de.current,a=Z.current;return t.length>0&&a>0?(pe(-1),"handled"):"exit"},[pe]));const Q=n.useCallback((t,a)=>{if(typeof window>"u")return;const i=window.history.state,x={...typeof i=="object"&&i!==null?i:{},__flatAgentNav:{agentId:t}};a==="replace"?window.history.replaceState(x,"",window.location.href):window.history.pushState(x,"",window.location.href)},[]);n.useEffect(()=>{if(!v){Ve.current=!1,ye.current=null;return}if(!Ve.current){Q(v,"replace"),Ve.current=!0,ye.current=v;return}if(et.current){et.current=!1,ye.current=v;return}ye.current!==v&&(Q(v,"push"),ye.current=v)},[v,Q]),n.useEffect(()=>{const t=a=>{var C,k;const i=(k=(C=a.state)==null?void 0:C.__flatAgentNav)==null?void 0:k.agentId;if(!i||typeof i!="string"||!U.has(i)||i===v)return;et.current=!0,Xe.current=!0;const g=de.current,x=g.lastIndexOf(i);x>=0?Z.current=x:(g.push(i),Z.current=g.length-1),J(),b.selectAgent(i)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[U,v,J]),n.useEffect(()=>{if(!v){de.current=[],Z.current=-1,J();return}if(Ne.current=v,Xe.current){Xe.current=!1,J();return}const t=de.current,a=Z.current;if(a>=0&&t[a]===v){J();return}const i=a<t.length-1?t.slice(0,a+1):t.slice();i.push(v),i.length>100&&i.shift(),de.current=i,Z.current=i.length-1,J()},[v,J]);const at=n.useCallback(t=>{d(t),re(!1)},[d]),Ge=v??"",St=n.useCallback(()=>{},[]),ht=n.useCallback(t=>{at(t)},[at]),ee=_e,[qe,st]=n.useState(ee),[s,l]=n.useState(ee);n.useEffect(()=>{if(ee){st(!0);return}l(!1);const t=setTimeout(()=>st(!1),240);return()=>clearTimeout(t)},[ee]),n.useEffect(()=>{if(!qe||!ee)return;let t=0;const a=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>l(!0))});return()=>{cancelAnimationFrame(a),cancelAnimationFrame(t)}},[qe,ee]);const o=n.useRef(null);n.useEffect(()=>{if(v)return;const t=a=>{if(a.key!==" "&&a.key!=="Backspace")return;const i=a.target;if(i.tagName==="INPUT"||i.tagName==="TEXTAREA"||i.isContentEditable)return;const g=Ne.current;!g||!U.has(g)||(a.preventDefault(),b.selectAgent(g))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[v,U]);const[u,me]=n.useState(new Set),Ye=n.useCallback(t=>{me(a=>{const i=new Set(a);return i.has(t)?i.delete(t):i.add(t),i})},[]),[V,Et]=n.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);n.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),a=i=>Et(i.matches);return t.addEventListener("change",a),()=>t.removeEventListener("change",a)},[]);const[Ke,gt]=n.useState(null),G=n.useCallback(t=>{gt(a=>a===t?null:t)},[]),L=en(),De=tn(),[sn]=Nn(),Re=n.useMemo(()=>{const t=new Map,a=[];for(const w of _){const A=b.getAreaForAgent(w.id);if(!Ut((A==null?void 0:A.id)??null))continue;if(!A||A.archived){a.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 De.values()){let A=!1;for(const E of L.values())if(!E.archived&&Xt(E.id)&&b.isPositionInArea(w.position,E)){const F=i.get(E.id);F?F.push(w):i.set(E.id,[w]),A=!0;break}!A&&Ut(null)&&g.push(w)}const x=[];for(const[,w]of L){if(w.archived||!Xt(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})}(a.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:a,buildings:g});const C=x.filter(w=>w.area.id!=="__unassigned__"),k=x.filter(w=>w.area.id==="__unassigned__");let c=1,y=1;const O=new Map;if(C.length>1){let w=1/0,A=-1/0,E=1/0,F=-1/0;for(const W of C)w=Math.min(w,W.area.center.x),A=Math.max(A,W.area.center.x),E=Math.min(E,W.area.center.z),F=Math.max(F,W.area.center.z);const xt=A-w||1,bt=F-E||1;if(C.length<=4){c=C.length,y=1;const W=[...C].sort((H,Mt)=>H.area.center.x-Mt.area.center.x);for(let H=0;H<W.length;H++)O.set(W[H].area.id,{row:1,col:H+1})}else{const W=[...C].sort((j,$)=>j.area.center.x-$.area.center.x),H=[];for(let j=1;j<W.length;j++)H.push(W[j].area.center.x-W[j-1].area.center.x);const Mt=H.reduce((j,$)=>j+$,0)/H.length||1;let $t=1;for(const j of H)j>Mt*1.3&&$t++;c=Math.max(2,Math.min($t,C.length));const It=[...C].sort((j,$)=>j.area.center.z-$.area.center.z),_t=[];for(let j=1;j<It.length;j++)_t.push(It[j].area.center.z-It[j-1].area.center.z);const cn=_t.reduce((j,$)=>j+$,0)/_t.length||1;let zt=1;for(const j of _t)j>cn*1.3&&zt++;y=Math.max(2,Math.min(zt,C.length)),c=Math.max(c,Math.ceil(C.length/y)),y=Math.max(y,Math.ceil(C.length/c));const dn=xt/c,un=bt/y,Tt=new Set;for(const j of C){let $=Math.min(c-1,Math.max(0,Math.floor((j.area.center.x-w)/dn))),$e=Math.min(y-1,Math.max(0,Math.floor((j.area.center.z-E)/un))),it=`${$e},${$}`,Ot=0;const pn=y*c;for(;Tt.has(it)&&Ot<pn;)$++,$>=c&&($=0,$e=($e+1)%y),it=`${$e},${$}`,Ot++;Tt.has(it)&&($e=y,$=0,it=`${$e},${$}`,y++),Tt.add(it),O.set(j.area.id,{row:$e+1,col:$+1})}}}const T=w=>{w.sort((A,E)=>{var xt,bt,W,H;const F=(((xt=A.position)==null?void 0:xt.z)??0)-(((bt=E.position)==null?void 0:bt.z)??0);return F!==0?F:(((W=A.position)==null?void 0:W.x)??0)-(((H=E.position)==null?void 0:H.x)??0)})};for(const w of C)T(w.agents);for(const w of k)T(w.agents);return{groups:[...C,...k],gridCols:c,gridRows:y,positions:O}},[_,L,De,sn]),ln=n.useMemo(()=>{if(!ae)return[];const t=_.find(a=>a.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:()=>d(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:()=>{Se({agentId:t.id,name:t.name})}}]:[]},[ae,_,d]),rn=n.useMemo(()=>{var C;if(!f)return[];const t=De.get(f.buildingId);if(!t)return[];const a=[],i=t.type==="server"||t.type==="docker"||t.type==="terminal",g=t.status==="running",x=t.type==="boss";if(a.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="tests"?"Open Tests":t.type==="http"?"Open Requests":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==="http"?"globe":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>Ue(t.id)}),i&&(g||a.push({id:"start",label:"Start",icon:e.jsx(p,{name:"play",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"start")}),g&&(a.push({id:"restart",label:"Restart",icon:e.jsx(p,{name:"refresh",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"restart")}),a.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&&(a.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")}}),a.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")}}),a.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&&a.push({id:"health-check",label:"Health Check",icon:e.jsx(p,{name:"health",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"healthCheck")}),a.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),a.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}}))}}),a.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)a.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 a.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),a.push({id:"delete",label:"Delete Building",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>b.deleteBuilding(t.id)}),a},[f,De,Ue]),on=n.useCallback(t=>{const a=new Set(Re.groups.map(i=>i.area.id));a.delete(t),me(a),requestAnimationFrame(()=>{const i=o.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"})})},[Re]);return e.jsxs("div",{ref:Ee,className:`flat-view ${ee?"flat-view--with-inspector":""} ${v?"flat-view--has-chat":""} ${le?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(ve===null&&Y===null)return;const t={};return ve!==null&&(t["--flat-middle-width"]=`${ve}px`),Y!==null&&(t["--flat-inspector-width"]=`${Y}px`),t})(),children:[le&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Fe,"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:I,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:D,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(kn,{activeAgentId:Ge,onClose:St,onSelectAgent:ht,collapsedAreas:u,onToggleArea:Ye,agentListRef:o})})]}),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:dt,onPointerMove:oe,onPointerUp:ce,onPointerCancel:ce,onDoubleClick:je}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":le?"Close agents sidebar":"Open agents sidebar","aria-expanded":le,onClick:ct,children:[e.jsx(p,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),v?e.jsx(Ca,{agentId:v,terminalViewMode:Oe,onTerminalViewModeChange:Be,inspectorOpen:_e,onToggleInspector:Te,onImageClick:pt,onFileClick:mt,onBashClick:Le,onViewMarkdown:yt,onRequestClearSubordinates:At,onOpenBuilding:Ue,keyboard:Pe,canNavigateBack:ke,canNavigateForward:ue,onNavigateBack:tt,onNavigateForward:nt,agentInfoOpen:ze,onToggleAgentInfo:jt,onHeaderContextMenu:t=>{v&&se({agentId:v,position:t})},onBuildingContextMenu:(t,a)=>{z({buildingId:t,position:a})}}):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(fa,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Re.gridCols}, 1fr)`},children:Re.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var a;const t=V&&Ke?((a=Re.positions.get(Ke))==null?void 0:a.row)??null:null;return Re.groups.map(i=>{var k;const g=i.area.id,x=Re.positions.get(g),C=V&&Ke!==g;return V&&t!=null&&(x==null?void 0:x.row)===t&&g!==Ke?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:c=>{N&&(c.preventDefault(),c.stopPropagation(),N(g,{x:c.clientX,y:c.clientY}))},children:[((k=i.area.logo)==null?void 0:k.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:la(i.area.logo.filename),alt:"","aria-hidden":"true",onError:c=>{c.currentTarget.style.display="none"}}),e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>V?G(g):on(g),title:V?C?`Expand ${i.area.name}`:`Collapse ${i.area.name}`:`Focus ${i.area.name} in left panel`,"aria-expanded":V?!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}),V&&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(c=>{const y=c.isBoss||c.class==="boss",O=y?ft.get(c.id):void 0,T=yn(c),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=c.latestTodos&&c.latestTodos.length>0||O&&O.length>0;return e.jsx(An,{todos:c.latestTodos,subordinates:O,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${c.status}`,onClick:()=>d(c.id),onContextMenu:F=>{F.preventDefault(),F.stopPropagation(),se({agentId:c.id,position:{x:F.clientX,y:F.clientY}})},title:E?void 0:`${y?"Boss · ":""}Open chat with ${c.name}
|
|
2
|
+
${A}`,children:[e.jsx(nn,{agent:c,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:c.name}),e.jsx("img",{src:c.provider==="codex"?"/assets/codex.png":c.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:c.provider,className:"flat-map-agent-chip__provider-icon",title:c.provider==="codex"?"Codex Agent":c.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:an(c.status)}}),c.latestTodos&&c.latestTodos.length>0&&e.jsx(Sn,{todos:c.latestTodos,maxDots:6}),y&&O&&O.length>0&&e.jsx(En,{subordinates:O,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}})})]})},c.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(c=>{const y=c.split("/").filter(Boolean).pop()||c;return e.jsxs("button",{type:"button",className:"flat-map-folder-chip",onClick:O=>{O.stopPropagation(),b.openFileExplorerForAreaFolder(g,c)},title:`Open in file explorer: ${c}`,children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-map-folder-chip__name",children:y})]},c)})}),i.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:i.buildings.map(c=>{var O;const y=(O=Mn[c.type])==null?void 0:O.color;return e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${c.status}`,style:y?{"--building-type-color":y}:void 0,onClick:T=>{if(h){const w=T.currentTarget.getBoundingClientRect();h(c.id,{x:w.right,y:w.top+w.height/2})}else Ue(c.id)},onContextMenu:T=>{T.preventDefault(),T.stopPropagation(),z({buildingId:c.id,position:{x:T.clientX,y:T.clientY}})},title:`${c.name} · ${c.type} · ${c.status}`,children:[e.jsx(p,{name:In(c.type),size:12,color:y}),e.jsx("span",{className:"flat-map-building-chip__name",children:c.name}),e.jsx("span",{className:"flat-map-building-chip__dot",style:{backgroundColor:Tn(c.status)}})]},c.id)})})]},g)})})()})]})})]}),ee&&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:Ze,onPointerMove:oe,onPointerUp:ce,onPointerCancel:ce,onDoubleClick:Nt}),qe&&e.jsxs("aside",{className:`flat-inspector ${s?"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":Ie==="agent",className:`flat-inspector__tab ${Ie==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>ut("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":Ie==="tracking",className:`flat-inspector__tab ${Ie==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>ut("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:He,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:Ie==="tracking"?e.jsx(Pn,{activeAgentId:v??"",onSelectAgent:t=>{d(t),window.innerWidth<=768&&He()}}):(()=>{if(!v)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=_.find(a=>a.id===v);return t?e.jsx(Ln,{agent:t,onFocusAgent:a=>{d(a),window.innerWidth<=768&&He()},onKillAgent:a=>b.killAgent(a)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),M&&e.jsx(Dn,{url:M.url,name:M.name,onClose:()=>B(null)}),X&&e.jsx(Rn,{state:X,onClose:()=>he(null)}),e.jsx($n,{agent:v?_.find(t=>t.id===v)??null:null,content:te,onClose:()=>ge(null)}),Ae&&e.jsx(zn,{action:"clear-subordinates",selectedAgentId:Ae.agentId,subordinateCount:Ae.count,onClose:()=>rt(null),onClearHistory:()=>{}}),e.jsx(On,{agent:v?_.find(t=>t.id===v)??null:null,isOpen:ze&&!!v,onClose:ot}),e.jsx(Vt,{isOpen:ae!==null,position:(ae==null?void 0:ae.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:ln,onClose:()=>se(null)}),e.jsx(Vt,{isOpen:f!==null,position:(f==null?void 0:f.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:rn,onClose:()=>z(null)}),e.jsx(Bn,{isOpen:xe!==null,title:q("common:confirm.removeAgentTitle"),message:q("common:confirm.removeAgentMessage",{name:(xe==null?void 0:xe.name)??""}),confirmLabel:q("common:buttons.remove"),cancelLabel:q("common:buttons.cancel"),variant:"danger",onConfirm:()=>{xe&&b.removeAgentFromServer(xe.agentId)},onClose:()=>Se(null)})]})}export{Aa as FlatView};
|