tide-commander 1.133.1 → 1.133.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{BossLogsModal-BaX_B_N5.js → BossLogsModal-DwuIK9m6.js} +1 -1
- package/dist/assets/{BossSpawnModal-C00UowDz.js → BossSpawnModal-Dj3RAYvK.js} +1 -1
- package/dist/assets/{ControlsModal-Dt7oE27Q.js → ControlsModal-2RYmmfrr.js} +1 -1
- package/dist/assets/{DockerLogsModal-lx6mKZ4i.js → DockerLogsModal-CtK69VXz.js} +1 -1
- package/dist/assets/{EmbeddedEditor-DIo_5FuD.js → EmbeddedEditor-D4dyGPWp.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-C2U2nxPP.js → GmailOAuthSetup-D4WIJQPh.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-Dc_Z6eoa.js → GoogleOAuthSetup-CeOoPjBn.js} +1 -1
- package/dist/assets/{IframeModal-Cee04vV5.js → IframeModal-Czpk8nNY.js} +1 -1
- package/dist/assets/{IntegrationsPanel-Bmcek1lk.js → IntegrationsPanel-BTWvtUqh.js} +2 -2
- package/dist/assets/{LogViewerModal-D7rUAo21.js → LogViewerModal-BoFD-vk1.js} +1 -1
- package/dist/assets/{MonitoringModal-CIVDImlk.js → MonitoringModal-ChR0ELIz.js} +1 -1
- package/dist/assets/{PM2LogsModal-BL6J-qAf.js → PM2LogsModal-CoCnLncV.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-BQ9_Ek9-.js → RestoreArchivedAreaModal-DPTPKLHh.js} +1 -1
- package/dist/assets/{Scene2DCanvas-DgGN3yZr.js → Scene2DCanvas-BH-47TIq.js} +1 -1
- package/dist/assets/{SceneManager-DeF_SgXg.js → SceneManager-IluWBEFk.js} +1 -1
- package/dist/assets/{SkillsPanel-Dewf3uKl.js → SkillsPanel-XcUykivP.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-DWzkYONn.js → SlackMultiInstanceSetup-DeLiUle3.js} +1 -1
- package/dist/assets/{SpawnModal-B0NGfZ2O.js → SpawnModal-BZfIZTdq.js} +1 -1
- package/dist/assets/{StatisticsModal-ChDwmrkc.js → StatisticsModal-C0Ets4vl.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-DmazQXKC.js → SubordinateAssignmentModal-BMT6EK_E.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-DkIXFFWd.js → TriggerManagerPanel-Bnwo6pTt.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-CTqX4HYi.js → WorkflowEditorPanel-D0G14Ebq.js} +1 -1
- package/dist/assets/{area-logos-BXaYMk1M.js → area-logos-C5XZBFfj.js} +1 -1
- package/dist/assets/{index-Cq-sPYkl.js → index-AlXP8uuc.js} +3 -3
- package/dist/assets/{index-CI38phrA.js → index-B3k628ul.js} +1 -1
- package/dist/assets/{index-BPkrDTdP.js → index-BV42oiJT.js} +1 -1
- package/dist/assets/{index-DecYdDhH.js → index-Bd5JKG69.js} +1 -1
- package/dist/assets/{index-zRJvCXm1.js → index-D-ETqZcB.js} +2 -2
- package/dist/assets/{index-CFiTx9XT.js → index-D5ufwk7t.js} +1 -1
- package/dist/assets/{index-B_z6xFfT.js → index-D_shYCrx.js} +1 -1
- package/dist/assets/{index-BKf_8kzR.js → index-GtO7k8QG.js} +1 -1
- package/dist/assets/{index-sSOmA52G.js → index-bY0k_5jo.js} +1 -1
- package/dist/assets/{main-D1dj_wn_.js → main-DZgTocNE.js} +7 -7
- package/dist/assets/{web-Br_mMcoY.js → web-CwRGXDj6.js} +1 -1
- package/dist/assets/{web-BBfhX6Mx.js → web-i9NDpV0L.js} +1 -1
- package/dist/assets/{web-DG_dqGGb.js → web-zQ3wpRl0.js} +1 -1
- package/dist/index.html +1 -1
- package/dist/src/packages/server/services/subagent-jsonl-watcher.js +33 -7
- package/dist/src/packages/server/websocket/listeners/runtime-listeners.js +20 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{br as ta,u as B,j as e,aY as j,bu as Ms,bv as Fs,aZ as ae,s as D,bw as $s,r as m,D as Z,I as F,ab as Us,b6 as qe,f as na,bx as la,W as ia,S as ra,k as oa,aa as Ks,b7 as Ue}from"./main-
|
|
1
|
+
import{br as ta,u as B,j as e,aY as j,bu as Ms,bv as Fs,aZ as ae,s as D,bw as $s,r as m,D as Z,I as F,ab as Us,b6 as qe,f as na,bx as la,W as ia,S as ra,k as oa,aa as Ks,b7 as Ue}from"./main-DZgTocNE.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const ca=[{value:"",labelKey:"terminal:building.colorDefault"},{value:"#2a2a3a",labelKey:"terminal:building.colorDarkGray"},{value:"#3a2a2a",labelKey:"terminal:building.colorDarkRed"},{value:"#2a3a2a",labelKey:"terminal:building.colorDarkGreen"},{value:"#2a2a4a",labelKey:"terminal:building.colorDarkBlue"},{value:"#3a3a2a",labelKey:"terminal:building.colorDarkYellow"},{value:"#3a2a3a",labelKey:"terminal:building.colorDarkPurple"},{value:"#2a3a3a",labelKey:"terminal:building.colorDarkCyan"},{value:"#4a3a3a",labelKey:"terminal:building.colorWarmBrown"},{value:"#3a4a4a",labelKey:"terminal:building.colorCoolSteel"}];function da(r){return ta.t(r)}function Ve(r){if(r===0)return"0 B";const p=1024,u=["B","KB","MB","GB"],x=Math.floor(Math.log(r)/Math.log(p));return parseFloat((r/Math.pow(p,x)).toFixed(1))+" "+u[x]}function ma(r){const u=Date.now()-r,x=Math.floor(u/(1e3*60*60)),n=Math.floor(u%(1e3*60*60)/(1e3*60));return x>0?`${x}h ${n}m`:`${n}m`}const Hs={30:"#1a1a1a",31:"#e74c3c",32:"#2ecc71",33:"#f39c12",34:"#3498db",35:"#9b59b6",36:"#00bcd4",37:"#ecf0f1",90:"#7f8c8d",91:"#ff6b6b",92:"#4ade80",93:"#fbbf24",94:"#60a5fa",95:"#c084fc",96:"#22d3ee",97:"#ffffff"};function qs(r){const p=[],u=/\x1B\[([0-9;]*)m/g;let x=0,n=null,y;for(;(y=u.exec(r))!==null;){if(y.index>x){const g=r.slice(x,y.index);n?p.push(e.jsx("span",{style:{color:n},children:g},p.length)):p.push(g)}const C=y[1].split(";").map(Number);for(const g of C)g===0||g===39?n=null:Hs[g]&&(n=Hs[g]);x=u.lastIndex}if(x<r.length){const C=r.slice(x);n?p.push(e.jsx("span",{style:{color:n},children:C},p.length)):p.push(C)}return p.length>0?p:[r]}function ua({buildingName:r,onClose:p,onConfirm:u}){const{t:x}=B(["terminal","common"]);return e.jsx("div",{className:"modal-overlay visible",onClick:p,children:e.jsxs("div",{className:"modal confirm-modal",onClick:n=>n.stopPropagation(),children:[e.jsx("div",{className:"modal-header",children:x("terminal:building.deleteBuilding")}),e.jsxs("div",{className:"modal-body confirm-modal-body",children:[e.jsx("p",{children:x("terminal:building.deleteConfirm",{name:r})}),e.jsx("p",{className:"confirm-modal-note",children:x("terminal:building.deleteNote")})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("button",{className:"btn btn-secondary",onClick:p,children:x("common:buttons.cancel")}),e.jsx("button",{className:"btn btn-danger",onClick:u,autoFocus:!0,children:x("common:buttons.delete")})]})]})})}function pa({usePM2:r,setUsePM2:p}){const{t:u}=B(["terminal"]);return e.jsxs("div",{className:"form-section pm2-toggle-section",children:[e.jsxs("label",{className:"toggle-switch",children:[e.jsx("input",{type:"checkbox",className:"toggle-input",checked:r,onChange:x=>p(x.target.checked)}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})}),e.jsxs("span",{className:"toggle-label",children:[e.jsx("span",{className:"pm2-badge",children:"PM2"}),u("terminal:building.usePM2")]})]}),e.jsx("div",{className:"form-hint",children:u("terminal:building.pm2Hint")})]})}function ha({usePM2:r,pm2Script:p,setPm2Script:u,pm2Args:x,setPm2Args:n,pm2Interpreter:y,setPm2Interpreter:C,pm2InterpreterArgs:g,setPm2InterpreterArgs:v,pm2Env:s,setPm2Env:h,isEditMode:a,building:t,handleCommand:o}){var N;const{t:i}=B(["terminal","common"]);return r?e.jsxs("div",{className:"form-section pm2-config-section",children:[e.jsx("label",{className:"form-label",children:i("terminal:building.pm2Configuration")}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Script"),e.jsx(j,{text:i("terminal:building.helpPm2Script"),title:i("terminal:building.pm2Script"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:p,onChange:b=>u(b.target.value),placeholder:"npm, java, python, ./app.js",required:r})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Arguments"),e.jsx(j,{text:i("terminal:building.helpPm2Arguments"),title:i("terminal:building.pm2Arguments"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:x,onChange:b=>n(b.target.value),placeholder:"run dev, -jar app.jar, app.py"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Interpreter"),e.jsx(j,{text:i("terminal:building.helpPm2Interpreter"),title:i("terminal:building.pm2Interpreter"),position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:y,onChange:b=>C(b.target.value),children:Object.keys(Ms).map(b=>e.jsx("option",{value:b,children:Ms[b].label},b))})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2InterpArgs"),e.jsx(j,{text:i("terminal:building.helpPm2InterpArgs"),title:i("terminal:building.pm2InterpArgs"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:g,onChange:b=>v(b.target.value),placeholder:"-jar (for Java)"})]}),e.jsxs("div",{className:"command-row env-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Environment"),e.jsx(j,{text:i("terminal:building.helpPm2Environment"),title:i("terminal:building.pm2Environment"),position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input form-textarea",value:s,onChange:b=>h(b.target.value),placeholder:`KEY=value
|
|
2
2
|
SERVER_PORT=7201
|
|
3
3
|
NODE_ENV=production`,rows:3})]}),e.jsx("div",{className:"pm2-examples",children:e.jsxs("details",{children:[e.jsx("summary",{children:i("terminal:building.pm2Examples")}),e.jsxs("div",{className:"pm2-examples-content",children:[e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Node.js:"})," Script: ",e.jsx("code",{children:"npm"}),", Args: ",e.jsx("code",{children:"run dev"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Symfony:"})," Script: ",e.jsx("code",{children:"symfony"}),", Args: ",e.jsx("code",{children:"serve --no-daemon"}),", Interpreter: ",e.jsx("code",{children:"None"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Java JAR:"})," Script: ",e.jsx("code",{children:"app.jar"}),", Interpreter: ",e.jsx("code",{children:"Java"}),", Interp. Args: ",e.jsx("code",{children:"-jar"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Python:"})," Script: ",e.jsx("code",{children:"app.py"}),", Interpreter: ",e.jsx("code",{children:"Python 3"})]})]})]})}),a&&(t==null?void 0:t.pm2Status)&&e.jsx("div",{className:"pm2-status-display",children:e.jsxs("div",{className:"pm2-status-row",children:[e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"PID"}),e.jsx("span",{className:"pm2-metric-value",children:t.pm2Status.pid||"-"})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"CPU"}),e.jsxs("span",{className:"pm2-metric-value",children:[((N=t.pm2Status.cpu)==null?void 0:N.toFixed(1))||"0","%"]})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"MEM"}),e.jsx("span",{className:"pm2-metric-value",children:Ve(t.pm2Status.memory||0)})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"Restarts"}),e.jsx("span",{className:"pm2-metric-value",children:t.pm2Status.restarts||0})]}),t.pm2Status.uptime&&e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"Uptime"}),e.jsx("span",{className:"pm2-metric-value",children:ma(t.pm2Status.uptime)})]})]})}),a&&e.jsxs("div",{className:"pm2-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>o("start"),children:i("common:buttons.start")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>o("stop"),children:i("common:buttons.stop")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>o("restart"),children:i("terminal:buildingAction.restart")}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>o("logs"),children:i("terminal:logs.title")})]})]}):null}function xa({dockerMode:r,setDockerMode:p,dockerImage:u,setDockerImage:x,dockerContainerName:n,setDockerContainerName:y,dockerCommand:C,setDockerCommand:g,dockerPorts:v,setDockerPorts:s,dockerVolumes:h,setDockerVolumes:a,dockerNetwork:t,setDockerNetwork:o,dockerRestart:i,setDockerRestart:N,dockerPull:b,setDockerPull:L,dockerEnv:T,setDockerEnv:A,dockerComposePath:$,setDockerComposePath:R,dockerComposeProject:K,setDockerComposeProject:I,dockerComposeServices:H,setDockerComposeServices:O,selectedExistingContainer:d,setSelectedExistingContainer:E,dockerContainersList:q,isEditMode:V,building:k,handleCommand:_}){const{t:M}=B(["config","common"]);return e.jsxs("div",{className:"form-section docker-config-section",children:[e.jsx("label",{className:"form-label",children:M("config:buildings.dockerConfig")}),e.jsxs("div",{className:"docker-mode-selector",children:[e.jsxs("label",{className:`docker-mode-option ${r==="container"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"container",checked:r==="container",onChange:()=>p("container")}),e.jsx("span",{className:"docker-mode-icon",children:"📦"}),e.jsx("span",{className:"docker-mode-label",children:"Container"}),e.jsx("span",{className:"docker-mode-desc",children:"Create a new container"})]}),e.jsxs("label",{className:`docker-mode-option ${r==="compose"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"compose",checked:r==="compose",onChange:()=>p("compose")}),e.jsx("span",{className:"docker-mode-icon",children:"🛠"}),e.jsx("span",{className:"docker-mode-label",children:"Compose"}),e.jsx("span",{className:"docker-mode-desc",children:"Manage multiple services"})]}),e.jsxs("label",{className:`docker-mode-option ${r==="existing"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"existing",checked:r==="existing",onChange:()=>p("existing")}),e.jsx("span",{className:"docker-mode-icon",children:"🔎"}),e.jsx("span",{className:"docker-mode-label",children:"Existing"}),e.jsx("span",{className:"docker-mode-desc",children:"Adopt existing container"})]})]}),r==="container"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Image:",e.jsx(j,{text:"Docker image to run, e.g., nginx:latest, redis:alpine, my-app:v1",title:"Image",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:u,onChange:l=>x(l.target.value),placeholder:"nginx:latest",required:!0})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Container Name:",e.jsx(j,{text:"Custom name for the container. If empty, auto-generated based on building name.",title:"Container Name",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:n,onChange:l=>y(l.target.value),placeholder:"Auto-generated (tc-{name}-{id})"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Command:",e.jsx(j,{text:"Override the default container command. Leave empty to use image's CMD.",title:"Command Override",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:l=>g(l.target.value),placeholder:"Optional command override"})]}),e.jsxs("div",{className:"form-section docker-ports-section",children:[e.jsxs("label",{className:"form-label",children:["Port Mappings",e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>s([...v,""]),children:"+ Add"})]}),v.map((l,S)=>e.jsxs("div",{className:"docker-mapping-row",children:[e.jsx("input",{type:"text",className:"form-input",value:l,onChange:U=>{const z=[...v];z[S]=U.target.value,s(z)},placeholder:"8080:80 or 3000"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>s(v.filter((U,z)=>z!==S)),children:"x"})]},S)),v.length===0&&e.jsx("div",{className:"form-hint",children:"Format: host:container (e.g., 8080:80) or same port (e.g., 3000)"})]}),e.jsxs("div",{className:"form-section docker-volumes-section",children:[e.jsxs("label",{className:"form-label",children:["Volume Mounts",e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>a([...h,""]),children:"+ Add"})]}),h.map((l,S)=>e.jsxs("div",{className:"docker-mapping-row",children:[e.jsx("input",{type:"text",className:"form-input",value:l,onChange:U=>{const z=[...h];z[S]=U.target.value,a(z)},placeholder:"./data:/app/data or /host/path:/container/path"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>a(h.filter((U,z)=>z!==S)),children:"x"})]},S)),h.length===0&&e.jsx("div",{className:"form-hint",children:"Format: host_path:container_path (relative paths resolved from working directory)"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Network:",e.jsx(j,{text:"Docker network to connect to. Leave empty for default bridge network.",title:"Network",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:t,onChange:l=>o(l.target.value),placeholder:"bridge (default)"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Restart Policy:",e.jsx(j,{text:"When should Docker restart the container automatically?",title:"Restart Policy",position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:i,onChange:l=>N(l.target.value),children:Object.keys(Fs).map(l=>e.jsx("option",{value:l,children:Fs[l].label},l))})]})]}),r==="compose"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Compose File:",e.jsx(j,{text:"Path to docker-compose.yml file, relative to working directory.",title:"Compose File",position:"top",size:"sm"})]}),e.jsx(ae,{value:$,onChange:R,placeholder:"docker-compose.yml",className:"form-input",directoriesOnly:!1})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Project Name:",e.jsx(j,{text:"Override the compose project name. Leave empty for auto-generated name.",title:"Project Name",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:K,onChange:l=>I(l.target.value),placeholder:"Auto-generated"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Services:",e.jsx(j,{text:"Specific services to manage (comma-separated). Leave empty for all services.",title:"Services",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:H,onChange:l=>O(l.target.value),placeholder:"All services (or: api, db, redis)"})]})]}),r==="existing"&&e.jsxs("div",{className:"docker-existing-section",children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Select Container:",e.jsx(j,{text:"Choose an existing Docker container to monitor and control. The container will not be deleted when removing the building.",title:"Existing Container",position:"top",size:"sm"})]}),e.jsxs("div",{className:"docker-existing-select-wrapper",children:[e.jsxs("select",{className:"form-input form-select",value:d,onChange:l=>E(l.target.value),required:r==="existing",children:[e.jsx("option",{value:"",children:"Select a container..."}),q.map(l=>e.jsxs("option",{value:l.name,children:[l.name," (",l.image,") - ",l.state]},l.id))]}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.requestDockerContainersList(),title:"Refresh container list",children:"↻"})]})]}),q.length===0&&e.jsx("div",{className:"form-hint docker-existing-hint",children:"No containers found. Make sure Docker is running and you have containers available."}),d&&e.jsx("div",{className:"docker-existing-info",children:(()=>{const l=q.find(S=>S.name===d);return l?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Image:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.image})]}),e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Status:"}),e.jsx("span",{className:`docker-existing-info-value docker-status-${l.status}`,children:l.state})]}),e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"ID:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.id.slice(0,12)})]}),l.ports.length>0&&e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Ports:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.ports.map(S=>`${S.host}:${S.container}/${S.protocol}`).join(", ")})]})]}):null})()}),e.jsx("div",{className:"form-hint",children:"Note: Existing containers will not be deleted when you remove this building."})]}),r!=="existing"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Pull Policy:",e.jsx(j,{text:"When to pull images: always, only if missing, or never.",title:"Pull Policy",position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:b,onChange:l=>L(l.target.value),children:Object.keys($s).map(l=>e.jsx("option",{value:l,children:$s[l].label},l))})]}),e.jsxs("div",{className:"command-row env-row",children:[e.jsxs("span",{className:"command-label",children:["Environment:",e.jsx(j,{text:"Environment variables in KEY=value format, one per line.",title:"Environment Variables",position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input form-textarea",value:T,onChange:l=>A(l.target.value),placeholder:`KEY=value
|
|
4
4
|
DATABASE_URL=postgres://...
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/web-
|
|
2
|
-
import{cD as e,bL as o}from"./main-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/web-i9NDpV0L.js","assets/main-DZgTocNE.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-Chj50gSY.js","assets/main-rrlO1Py8.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{cD as e,bL as o}from"./main-DZgTocNE.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";var i;(function(r){r.Heavy="HEAVY",r.Medium="MEDIUM",r.Light="LIGHT"})(i||(i={}));var t;(function(r){r.Success="SUCCESS",r.Warning="WARNING",r.Error="ERROR"})(t||(t={}));const c=e("Haptics",{web:()=>o(()=>import("./web-i9NDpV0L.js"),__vite__mapDeps([0,1,2,3,4])).then(r=>new r.HapticsWeb)});export{c as Haptics,i as ImpactStyle,t as NotificationType};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as J,a as Z,r,s as h,j as e,D as de,I as H,C as oe,b as me,c as be,d as ue,g as he,e as _e,Q as pe,R as xe}from"./main-D1dj_wn_.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const fe=({building:a,connections:x,activeConnectionId:l,activeDatabase:c,collapsed:y,onToggleCollapse:f,onConnectionChange:Q,onDatabaseChange:S,onInsertTable:L,onSelectTableQuery:P})=>{const{t:m}=J(["terminal"]),q=Z(a.id),[I,R]=r.useState(new Set),[k,n]=r.useState(""),[d,g]=r.useState(""),[$,w]=r.useState(!1),[U,F]=r.useState(null),K=r.useRef(null),C=r.useRef(null),O=r.useRef(null),N=l?q.databases.get(l)??[]:[],G=l&&c?`${l}:${c}`:"",j=G?q.tables.get(G)??[]:[],p=l?q.connectionStatus.get(l):void 0,D=r.useMemo(()=>{if(!k.trim())return N;const t=k.toLowerCase();return N.filter(o=>o.toLowerCase().includes(t))},[N,k]),b=r.useMemo(()=>{if(!d.trim())return j;const t=d.toLowerCase();return j.filter(o=>o.name.toLowerCase().includes(t))},[j,d]);r.useEffect(()=>{const t=o=>{C.current&&!C.current.contains(o.target)&&w(!1)};return $&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[$]),r.useEffect(()=>{l&&!p&&h.testDatabaseConnection(a.id,l)},[a.id,l,p]),r.useEffect(()=>{l&&(p!=null&&p.connected)&&N.length===0&&h.listDatabases(a.id,l)},[a.id,l,p==null?void 0:p.connected,N.length]),r.useEffect(()=>{l&&c&&j.length===0&&h.listTables(a.id,l,c)},[a.id,l,c,j.length]),r.useEffect(()=>{F(null),g("")},[l,c]);const _=r.useCallback(t=>{R(o=>{const T=new Set(o);if(T.has(t))T.delete(t);else if(T.add(t),l&&c){const v=`${l}:${c}:${t}`;q.tableSchemas.has(v)||h.getTableSchema(a.id,l,c,t)}return T})},[a.id,l,c,q.tableSchemas]),z=t=>{if(!l||!c)return null;const o=`${l}:${c}:${t}`;return q.tableSchemas.get(o)};return y?e.jsx("div",{className:"database-sidebar database-sidebar--collapsed",children:e.jsx("button",{className:"database-sidebar__toggle",onClick:f,title:m("terminal:database.expandSidebar"),children:"»"})}):e.jsxs("div",{className:"database-sidebar",children:[e.jsxs("div",{className:"database-sidebar__header",children:[e.jsx("span",{children:m("terminal:database.explorer")}),e.jsx("button",{className:"database-sidebar__toggle",onClick:f,title:m("terminal:database.collapseSidebar"),children:"«"})]}),e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:m("terminal:database.connection")}),e.jsx("select",{className:"database-sidebar__select",value:l||"",onChange:t=>Q(t.target.value),children:x.length===0?e.jsx("option",{value:"",children:m("terminal:database.noConnections")}):x.map(t=>{var o;return e.jsxs("option",{value:t.id,children:[((o=de[t.engine])==null?void 0:o.icon)??"🗄️"," ",t.name]},t.id)})}),p&&e.jsx("div",{className:`database-sidebar__status ${p.connected?"database-sidebar__status--connected":"database-sidebar__status--error"}`,children:p.connected?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✓"}),m("terminal:database.connected"),p.serverVersion&&e.jsxs("span",{className:"database-sidebar__version",children:["(",p.serverVersion,")"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✗"}),p.error||m("terminal:database.disconnected")]})})]}),N.length>0&&e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:m("terminal:database.databaseTitle")}),e.jsxs("div",{className:"database-sidebar__searchable-select",ref:C,children:[e.jsx("input",{ref:K,className:"database-sidebar__search-input",type:"text",value:$?k:c||"",placeholder:m("terminal:database.selectDatabase"),onChange:t=>{n(t.target.value),$||w(!0)},onFocus:()=>{w(!0),n("")},onKeyDown:t=>{var o,T;t.key==="Escape"?(w(!1),n(""),(o=K.current)==null||o.blur()):t.key==="Enter"&&D.length===1&&(S(D[0]),w(!1),n(""),(T=K.current)==null||T.blur())}}),$&&e.jsx("div",{className:"database-sidebar__dropdown",children:D.length===0?e.jsx("div",{className:"database-sidebar__dropdown-empty",children:"No matches"}):D.map(t=>e.jsx("div",{className:`database-sidebar__dropdown-item ${t===c?"database-sidebar__dropdown-item--active":""}`,onMouseDown:o=>{o.preventDefault(),S(t),w(!1),n("")},children:t},t))})]})]}),j.length>0&&e.jsxs("div",{className:"database-sidebar__section database-sidebar__section--tables",children:[e.jsx("div",{className:"database-sidebar__section-title",children:d.trim()?m("terminal:database.tablesCount",{count:b.length})+` / ${j.length}`:m("terminal:database.tablesCount",{count:j.length})}),e.jsxs("div",{className:"database-sidebar__table-filter",children:[e.jsx("input",{ref:O,className:"database-sidebar__table-filter-input",type:"text",value:d,placeholder:m("terminal:database.filterTables"),onChange:t=>g(t.target.value),onKeyDown:t=>{var o;t.key==="Escape"&&(d?g(""):(o=O.current)==null||o.blur(),t.stopPropagation())}}),d&&e.jsx("button",{className:"database-sidebar__table-filter-clear",onClick:()=>{var t;g(""),(t=O.current)==null||t.focus()},title:"Clear filter",children:"×"})]}),e.jsxs("div",{className:"database-sidebar__tables",children:[d.trim()&&b.length===0&&e.jsx("div",{className:"database-sidebar__tables-empty",children:m("terminal:database.noTablesMatch")}),b.map(t=>{const o=I.has(t.name),T=o?z(t.name):null;return e.jsxs("div",{className:"database-sidebar__table",children:[e.jsxs("div",{className:"database-sidebar__table-header",children:[e.jsx("button",{className:"database-sidebar__table-expand",onClick:()=>_(t.name),title:o?"Collapse table schema":"Expand table schema",children:e.jsx(H,{name:o?"caret-down":"caret-right",size:10})}),e.jsx("span",{className:"database-sidebar__table-icon",children:e.jsx(H,{name:t.type==="view"?"eye":"clipboard",size:12})}),e.jsx("span",{className:`database-sidebar__table-name ${U===t.name?"database-sidebar__table-name--selected":""}`,onClick:()=>F(t.name),onDoubleClick:()=>{F(t.name),P(t.name)},children:t.name}),e.jsx("button",{className:"database-sidebar__table-insert",onClick:v=>{v.stopPropagation(),L(t.name)},title:m("terminal:database.insertTableName"),children:"+"})]}),o&&T&&e.jsx("div",{className:"database-sidebar__table-columns",children:T.columns.map(v=>e.jsxs("div",{className:"database-sidebar__column",onClick:()=>L(v.name),title:`${v.type}${v.nullable?" NULL":" NOT NULL"}${v.primaryKey?" PK":""}`,children:[e.jsx("span",{className:"database-sidebar__column-icon",children:v.primaryKey?e.jsx(H,{name:"key",size:11}):null}),e.jsx("span",{className:"database-sidebar__column-name",children:v.name}),e.jsx("span",{className:"database-sidebar__column-type",children:v.type})]},v.name))})]},t.name)})]})]})]})},je=({buildingId:a,history:x,onLoadQuery:l})=>{const{t:c}=J(["terminal","common"]),[y,f]=r.useState(""),[Q,S]=r.useState(!1),[L,P]=r.useState(!1),m=r.useMemo(()=>{let n=x;if(Q&&(n=n.filter(d=>d.favorite)),y.trim()){const d=y.toLowerCase();n=n.filter(g=>g.query.toLowerCase().includes(d)||g.database.toLowerCase().includes(d))}return n},[x,Q,y]),q=n=>{const d=new Date(n),$=new Date().getTime()-d.getTime();return $<1440*60*1e3?d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):$<10080*60*1e3?d.toLocaleDateString([],{weekday:"short"})+" "+d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):d.toLocaleDateString([],{month:"short",day:"numeric"})},I=r.useCallback((n,d)=>{d.stopPropagation(),h.toggleQueryFavorite(a,n)},[a]),R=r.useCallback((n,d)=>{d.stopPropagation(),h.deleteQueryFromHistory(a,n)},[a]),k=r.useCallback(()=>{P(!0)},[]);return x.length===0?e.jsxs("div",{className:"query-history query-history--empty",children:[e.jsx("p",{children:c("terminal:database.noHistory")}),e.jsx("p",{children:c("terminal:database.queriesAppearHere")})]}):e.jsxs("div",{className:"query-history",children:[e.jsxs("div",{className:"query-history__toolbar",children:[e.jsx("input",{type:"text",className:"query-history__search",placeholder:c("terminal:database.searchQueries"),value:y,onChange:n=>f(n.target.value)}),e.jsxs("label",{className:"query-history__filter",children:[e.jsx("input",{type:"checkbox",checked:Q,onChange:n=>S(n.target.checked)}),c("terminal:database.favoritesOnly")]}),e.jsx("button",{className:"query-history__clear",onClick:k,title:c("terminal:database.clearAll"),children:c("terminal:database.clearAll")})]}),e.jsxs("div",{className:"query-history__list",children:[m.map(n=>e.jsxs("div",{className:`query-history__item ${n.status==="error"?"query-history__item--error":""}`,onClick:()=>l(n.query),children:[e.jsxs("div",{className:"query-history__item-header",children:[e.jsx("span",{className:`query-history__status ${n.status==="success"?"query-history__status--success":"query-history__status--error"}`,children:e.jsx(H,{name:n.status==="success"?"check":"cross",size:12})}),e.jsx("span",{className:"query-history__database",children:n.database}),e.jsx("span",{className:"query-history__date",children:q(n.executedAt)}),e.jsxs("span",{className:"query-history__duration",children:[n.duration,"ms"]}),n.rowCount!==void 0&&e.jsx("span",{className:"query-history__row-count",children:c("terminal:database.rowCount",{count:n.rowCount})})]}),e.jsx("div",{className:"query-history__query",children:e.jsx("code",{children:n.query.length>200?n.query.substring(0,200)+"...":n.query})}),n.error&&e.jsx("div",{className:"query-history__error",children:n.error}),e.jsxs("div",{className:"query-history__actions",children:[e.jsx("button",{className:`query-history__favorite ${n.favorite?"query-history__favorite--active":""}`,onClick:d=>I(n.id,d),title:n.favorite?c("terminal:database.removeFromFavorites"):c("terminal:database.addToFavorites"),children:e.jsx(H,{name:"star",size:12,weight:n.favorite?"fill":"regular",color:n.favorite?"#facc15":void 0})}),e.jsx("button",{className:"query-history__delete",onClick:d=>R(n.id,d),title:c("terminal:database.deleteFromHistory"),children:e.jsx(H,{name:"trash",size:12})})]})]},n.id)),m.length===0&&e.jsx("div",{className:"query-history__no-results",children:c("terminal:database.noQueriesMatch")})]}),e.jsx(oe,{isOpen:L,title:c("terminal:database.clearAll"),message:c("terminal:database.confirmClearHistory"),confirmLabel:c("terminal:database.clearAll"),cancelLabel:c("common:buttons.cancel"),variant:"danger",onConfirm:()=>h.clearQueryHistory(a),onClose:()=>P(!1)})]})},ye=({tabs:a,activeTabId:x,onTabClick:l,onTabClose:c})=>{const{t:y}=J(["terminal"]);return e.jsx("div",{className:"database-tabs",children:a.map(f=>e.jsxs("div",{className:`database-tabs__tab ${x===f.id?"database-tabs__tab--active":""}`,children:[e.jsxs("button",{className:"database-tabs__tab-label",onClick:()=>l(f),title:`${f.connectionName} / ${f.database}`,children:[f.database,e.jsx("span",{className:"database-tabs__tab-connection",children:f.connectionName})]}),e.jsx("button",{className:"database-tabs__tab-close",onClick:()=>c(f.id),title:y("terminal:database.closeTab"),"aria-label":`Close ${f.database} tab`,children:"×"})]},f.id))})},ee=a=>`db-panel-${a}`;function Ne(a){try{const x=localStorage.getItem(ee(a));return x?JSON.parse(x):{}}catch{return{}}}function ve(a,x){try{localStorage.setItem(ee(a),JSON.stringify(x))}catch{}}const ge=({building:a,onClose:x})=>{var B,W,Y,X;const{t:l}=J(["terminal","common"]),c=Z(a.id),y=me(a.id),f=be(a.id),Q=ue(a.id),S=r.useRef(Ne(a.id)),L=r.useRef(null),P=r.useRef(0),m=((B=a.database)==null?void 0:B.connections)??[],q=(s,i)=>`${s}:${i}`,I=s=>s?(S.current.queries??{})[s]??"":S.current.generalQuery??"",[R,k]=r.useState("results"),[n,d]=r.useState(0),[g,$]=r.useState(!1),[w,U]=r.useState(!1),[F,K]=r.useState(()=>(S.current.openTabs??[]).map(i=>{var u;return{id:`${i.connectionId}:${i.database}`,connectionId:i.connectionId,connectionName:((u=m.find(A=>A.id===i.connectionId))==null?void 0:u.name)??i.connectionId,database:i.database}})),[C,O]=r.useState(S.current.activeTabId??null),[N,G]=r.useState(()=>{const s=S.current.queries??{};return S.current.generalQuery,s}),[j,p]=r.useState(I(C)),D=r.useCallback(s=>{p(i=>{const u=typeof s=="function"?s(i):s;return G(A=>{const E={...A};return C&&(E[C]=u),E}),u})},[C]),b=c.activeConnectionId??S.current.connectionId??((W=a.database)==null?void 0:W.activeConnectionId)??((Y=m[0])==null?void 0:Y.id),_=c.activeDatabase??S.current.database??((X=a.database)==null?void 0:X.activeDatabase),z=m.find(s=>s.id===b),t=b&&_?`${b}:${_}`:"",o=t?c.tables.get(t)??[]:[],T=r.useMemo(()=>{const s=new Map;return!b||!_||o.forEach(i=>{const u=c.tableSchemas.get(`${b}:${_}:${i.name}`);u&&s.set(i.name,{columns:u.columns})}),s},[b,_,o,c.tableSchemas]),v=r.useCallback((s,i)=>{var E;const u=q(s,i),A=((E=m.find(M=>M.id===s))==null?void 0:E.name)??s;K(M=>{if(M.some(ie=>ie.id===u))return M;const ce={id:u,connectionId:s,connectionName:A,database:i};return[...M,ce]}),O(u),p(N[u]??""),h.setActiveConnection(a.id,s),h.setActiveDatabase(a.id,i)},[a.id,m,N]),ae=r.useCallback(s=>{K(i=>i.filter(u=>u.id!==s)),C===s&&K(i=>{if(i.length>0){const u=i[0];O(u.id),p(N[u.id]??""),h.setActiveConnection(a.id,u.connectionId),h.setActiveDatabase(a.id,u.database)}else O(null),p("");return i})},[C,a.id,N]),se=r.useCallback(s=>{O(s.id),p(N[s.id]??""),h.setActiveConnection(a.id,s.connectionId),h.setActiveDatabase(a.id,s.database)},[a.id,N]);r.useEffect(()=>{if(!w&&m.length>0){const s=S.current;s.connectionId&&m.some(i=>i.id===s.connectionId)&&(h.setActiveConnection(a.id,s.connectionId),h.listDatabases(a.id,s.connectionId),s.database&&(h.setActiveDatabase(a.id,s.database),h.listTables(a.id,s.connectionId,s.database))),U(!0)}},[a.id,m,w]),r.useEffect(()=>{h.requestQueryHistory(a.id)},[a.id]),r.useEffect(()=>{const s=i=>{i.key==="Escape"&&(i.preventDefault(),i.stopPropagation(),x())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[x]),r.useEffect(()=>{w&&b&&ve(a.id,{connectionId:b,database:_,lastQuery:j,queries:N,generalQuery:"",openTabs:F.map(s=>({connectionId:s.connectionId,database:s.database})),activeTabId:C??void 0})},[a.id,b,_,j,w,F,C,N]);const te=r.useCallback(s=>{var i;if(!(!b||!_||!j.trim()||Q))if(s==="cursor"){const u=(i=L.current)==null?void 0:i.querySelector(".query-editor__textarea"),A=(u==null?void 0:u.selectionStart)??P.current,E=he(j,A);E&&h.executeQuery(a.id,b,_,E)}else{const u=_e(j);if(u.length<=1)h.executeQuery(a.id,b,_,j.trim());else{const A=b,E=_;(async()=>{for(const M of u)await h.executeQueryAndWait(a.id,A,E,M.sql)})()}}},[a.id,b,_,j,Q]),ne=r.useCallback(s=>{D(s),k("results")},[]),re=r.useCallback(s=>{h.setActiveConnection(a.id,s),h.listDatabases(a.id,s)},[a.id]),le=r.useCallback(s=>{b&&(v(b,s),h.listTables(a.id,b,s))},[a.id,b,v]),V=y[n];return m.length===0?e.jsxs("div",{className:"database-panel",ref:L,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:e.jsx(H,{name:"database",size:16})}),e.jsx("span",{className:"database-panel__name",children:a.name})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsx("div",{className:"database-panel__body",children:e.jsxs("div",{className:"database-panel__no-connections",children:[e.jsx("div",{className:"database-panel__no-connections-icon",children:e.jsx(H,{name:"plug",size:32})}),e.jsx("h3",{children:l("terminal:database.noConnections")}),e.jsx("p",{children:l("terminal:database.noConnectionsDesc")}),e.jsx("p",{children:l("terminal:database.toGetStarted")}),e.jsxs("ol",{children:[e.jsx("li",{children:l("terminal:database.step1Close")}),e.jsx("li",{children:l("terminal:database.step2Settings")}),e.jsx("li",{children:l("terminal:database.step3AddConnection")}),e.jsx("li",{children:l("terminal:database.step4Reopen")})]})]})})]}):e.jsxs("div",{className:"database-panel",ref:L,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:(z==null?void 0:z.engine)==="mysql"?"🐬":"🐘"}),e.jsx("span",{className:"database-panel__name",children:a.name}),z&&e.jsxs("span",{className:"database-panel__connection-info",children:[z.name," / ",_||l("terminal:database.noDatabaseSelected")]})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsxs("div",{className:"database-panel__body",children:[e.jsx(fe,{building:a,connections:m,activeConnectionId:b,activeDatabase:_,collapsed:g,onToggleCollapse:()=>$(!g),onConnectionChange:re,onDatabaseChange:le,onInsertTable:s=>D(i=>i+` ${s}`),onSelectTableQuery:s=>{const i=`SELECT * FROM ${s}`;D(i),b&&_&&h.executeQuery(a.id,b,_,i)}}),e.jsxs("div",{className:"database-panel__main",children:[F.length>0&&e.jsx(ye,{tabs:F,activeTabId:C,onTabClick:se,onTabClose:ae}),e.jsx(pe,{query:j,onChange:D,onExecute:te,isExecuting:Q,disabled:!b||!_,tables:o,tableSchemas:T,onRequestTableSchema:s=>{b&&_&&h.getTableSchema(a.id,b,_,s)}}),e.jsxs("div",{className:"database-panel__tabs",children:[e.jsxs("button",{className:`database-panel__tab ${R==="results"?"database-panel__tab--active":""}`,onClick:()=>k("results"),children:[l("terminal:database.results"),y.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:y.length})]}),e.jsxs("button",{className:`database-panel__tab ${R==="history"?"database-panel__tab--active":""}`,onClick:()=>k("history"),children:[l("terminal:database.history"),f.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:f.length})]}),R==="results"&&y.length>1&&e.jsxs("div",{className:"database-panel__result-nav",children:[e.jsxs("button",{disabled:n>=y.length-1,onClick:()=>d(s=>s+1),children:["← ",l("terminal:database.older")]}),e.jsxs("span",{children:[n+1," / ",y.length]}),e.jsxs("button",{disabled:n<=0,onClick:()=>d(s=>s-1),children:[l("terminal:database.newer")," →"]})]})]}),e.jsx("div",{className:"database-panel__tab-content",children:R==="results"?V?e.jsx(xe,{result:V,buildingId:a.id,building:a}):e.jsxs("div",{className:"database-panel__empty",children:[e.jsx("p",{children:l("terminal:database.noResultsYet")}),e.jsx("p",{children:l("terminal:database.selectDbAndRun")})]}):e.jsx(je,{buildingId:a.id,history:f,onLoadQuery:ne})})]})]})]})};export{ge as DatabasePanel,fe as DatabaseSidebar,ye as DatabaseTabs,pe as QueryEditor,je as QueryHistoryPanel,xe as ResultsTable};
|
|
1
|
+
import{u as J,a as Z,r,s as h,j as e,D as de,I as H,C as oe,b as me,c as be,d as ue,g as he,e as _e,Q as pe,R as xe}from"./main-DZgTocNE.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const fe=({building:a,connections:x,activeConnectionId:l,activeDatabase:c,collapsed:y,onToggleCollapse:f,onConnectionChange:Q,onDatabaseChange:S,onInsertTable:L,onSelectTableQuery:P})=>{const{t:m}=J(["terminal"]),q=Z(a.id),[I,R]=r.useState(new Set),[k,n]=r.useState(""),[d,g]=r.useState(""),[$,w]=r.useState(!1),[U,F]=r.useState(null),K=r.useRef(null),C=r.useRef(null),O=r.useRef(null),N=l?q.databases.get(l)??[]:[],G=l&&c?`${l}:${c}`:"",j=G?q.tables.get(G)??[]:[],p=l?q.connectionStatus.get(l):void 0,D=r.useMemo(()=>{if(!k.trim())return N;const t=k.toLowerCase();return N.filter(o=>o.toLowerCase().includes(t))},[N,k]),b=r.useMemo(()=>{if(!d.trim())return j;const t=d.toLowerCase();return j.filter(o=>o.name.toLowerCase().includes(t))},[j,d]);r.useEffect(()=>{const t=o=>{C.current&&!C.current.contains(o.target)&&w(!1)};return $&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[$]),r.useEffect(()=>{l&&!p&&h.testDatabaseConnection(a.id,l)},[a.id,l,p]),r.useEffect(()=>{l&&(p!=null&&p.connected)&&N.length===0&&h.listDatabases(a.id,l)},[a.id,l,p==null?void 0:p.connected,N.length]),r.useEffect(()=>{l&&c&&j.length===0&&h.listTables(a.id,l,c)},[a.id,l,c,j.length]),r.useEffect(()=>{F(null),g("")},[l,c]);const _=r.useCallback(t=>{R(o=>{const T=new Set(o);if(T.has(t))T.delete(t);else if(T.add(t),l&&c){const v=`${l}:${c}:${t}`;q.tableSchemas.has(v)||h.getTableSchema(a.id,l,c,t)}return T})},[a.id,l,c,q.tableSchemas]),z=t=>{if(!l||!c)return null;const o=`${l}:${c}:${t}`;return q.tableSchemas.get(o)};return y?e.jsx("div",{className:"database-sidebar database-sidebar--collapsed",children:e.jsx("button",{className:"database-sidebar__toggle",onClick:f,title:m("terminal:database.expandSidebar"),children:"»"})}):e.jsxs("div",{className:"database-sidebar",children:[e.jsxs("div",{className:"database-sidebar__header",children:[e.jsx("span",{children:m("terminal:database.explorer")}),e.jsx("button",{className:"database-sidebar__toggle",onClick:f,title:m("terminal:database.collapseSidebar"),children:"«"})]}),e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:m("terminal:database.connection")}),e.jsx("select",{className:"database-sidebar__select",value:l||"",onChange:t=>Q(t.target.value),children:x.length===0?e.jsx("option",{value:"",children:m("terminal:database.noConnections")}):x.map(t=>{var o;return e.jsxs("option",{value:t.id,children:[((o=de[t.engine])==null?void 0:o.icon)??"🗄️"," ",t.name]},t.id)})}),p&&e.jsx("div",{className:`database-sidebar__status ${p.connected?"database-sidebar__status--connected":"database-sidebar__status--error"}`,children:p.connected?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✓"}),m("terminal:database.connected"),p.serverVersion&&e.jsxs("span",{className:"database-sidebar__version",children:["(",p.serverVersion,")"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✗"}),p.error||m("terminal:database.disconnected")]})})]}),N.length>0&&e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:m("terminal:database.databaseTitle")}),e.jsxs("div",{className:"database-sidebar__searchable-select",ref:C,children:[e.jsx("input",{ref:K,className:"database-sidebar__search-input",type:"text",value:$?k:c||"",placeholder:m("terminal:database.selectDatabase"),onChange:t=>{n(t.target.value),$||w(!0)},onFocus:()=>{w(!0),n("")},onKeyDown:t=>{var o,T;t.key==="Escape"?(w(!1),n(""),(o=K.current)==null||o.blur()):t.key==="Enter"&&D.length===1&&(S(D[0]),w(!1),n(""),(T=K.current)==null||T.blur())}}),$&&e.jsx("div",{className:"database-sidebar__dropdown",children:D.length===0?e.jsx("div",{className:"database-sidebar__dropdown-empty",children:"No matches"}):D.map(t=>e.jsx("div",{className:`database-sidebar__dropdown-item ${t===c?"database-sidebar__dropdown-item--active":""}`,onMouseDown:o=>{o.preventDefault(),S(t),w(!1),n("")},children:t},t))})]})]}),j.length>0&&e.jsxs("div",{className:"database-sidebar__section database-sidebar__section--tables",children:[e.jsx("div",{className:"database-sidebar__section-title",children:d.trim()?m("terminal:database.tablesCount",{count:b.length})+` / ${j.length}`:m("terminal:database.tablesCount",{count:j.length})}),e.jsxs("div",{className:"database-sidebar__table-filter",children:[e.jsx("input",{ref:O,className:"database-sidebar__table-filter-input",type:"text",value:d,placeholder:m("terminal:database.filterTables"),onChange:t=>g(t.target.value),onKeyDown:t=>{var o;t.key==="Escape"&&(d?g(""):(o=O.current)==null||o.blur(),t.stopPropagation())}}),d&&e.jsx("button",{className:"database-sidebar__table-filter-clear",onClick:()=>{var t;g(""),(t=O.current)==null||t.focus()},title:"Clear filter",children:"×"})]}),e.jsxs("div",{className:"database-sidebar__tables",children:[d.trim()&&b.length===0&&e.jsx("div",{className:"database-sidebar__tables-empty",children:m("terminal:database.noTablesMatch")}),b.map(t=>{const o=I.has(t.name),T=o?z(t.name):null;return e.jsxs("div",{className:"database-sidebar__table",children:[e.jsxs("div",{className:"database-sidebar__table-header",children:[e.jsx("button",{className:"database-sidebar__table-expand",onClick:()=>_(t.name),title:o?"Collapse table schema":"Expand table schema",children:e.jsx(H,{name:o?"caret-down":"caret-right",size:10})}),e.jsx("span",{className:"database-sidebar__table-icon",children:e.jsx(H,{name:t.type==="view"?"eye":"clipboard",size:12})}),e.jsx("span",{className:`database-sidebar__table-name ${U===t.name?"database-sidebar__table-name--selected":""}`,onClick:()=>F(t.name),onDoubleClick:()=>{F(t.name),P(t.name)},children:t.name}),e.jsx("button",{className:"database-sidebar__table-insert",onClick:v=>{v.stopPropagation(),L(t.name)},title:m("terminal:database.insertTableName"),children:"+"})]}),o&&T&&e.jsx("div",{className:"database-sidebar__table-columns",children:T.columns.map(v=>e.jsxs("div",{className:"database-sidebar__column",onClick:()=>L(v.name),title:`${v.type}${v.nullable?" NULL":" NOT NULL"}${v.primaryKey?" PK":""}`,children:[e.jsx("span",{className:"database-sidebar__column-icon",children:v.primaryKey?e.jsx(H,{name:"key",size:11}):null}),e.jsx("span",{className:"database-sidebar__column-name",children:v.name}),e.jsx("span",{className:"database-sidebar__column-type",children:v.type})]},v.name))})]},t.name)})]})]})]})},je=({buildingId:a,history:x,onLoadQuery:l})=>{const{t:c}=J(["terminal","common"]),[y,f]=r.useState(""),[Q,S]=r.useState(!1),[L,P]=r.useState(!1),m=r.useMemo(()=>{let n=x;if(Q&&(n=n.filter(d=>d.favorite)),y.trim()){const d=y.toLowerCase();n=n.filter(g=>g.query.toLowerCase().includes(d)||g.database.toLowerCase().includes(d))}return n},[x,Q,y]),q=n=>{const d=new Date(n),$=new Date().getTime()-d.getTime();return $<1440*60*1e3?d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):$<10080*60*1e3?d.toLocaleDateString([],{weekday:"short"})+" "+d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):d.toLocaleDateString([],{month:"short",day:"numeric"})},I=r.useCallback((n,d)=>{d.stopPropagation(),h.toggleQueryFavorite(a,n)},[a]),R=r.useCallback((n,d)=>{d.stopPropagation(),h.deleteQueryFromHistory(a,n)},[a]),k=r.useCallback(()=>{P(!0)},[]);return x.length===0?e.jsxs("div",{className:"query-history query-history--empty",children:[e.jsx("p",{children:c("terminal:database.noHistory")}),e.jsx("p",{children:c("terminal:database.queriesAppearHere")})]}):e.jsxs("div",{className:"query-history",children:[e.jsxs("div",{className:"query-history__toolbar",children:[e.jsx("input",{type:"text",className:"query-history__search",placeholder:c("terminal:database.searchQueries"),value:y,onChange:n=>f(n.target.value)}),e.jsxs("label",{className:"query-history__filter",children:[e.jsx("input",{type:"checkbox",checked:Q,onChange:n=>S(n.target.checked)}),c("terminal:database.favoritesOnly")]}),e.jsx("button",{className:"query-history__clear",onClick:k,title:c("terminal:database.clearAll"),children:c("terminal:database.clearAll")})]}),e.jsxs("div",{className:"query-history__list",children:[m.map(n=>e.jsxs("div",{className:`query-history__item ${n.status==="error"?"query-history__item--error":""}`,onClick:()=>l(n.query),children:[e.jsxs("div",{className:"query-history__item-header",children:[e.jsx("span",{className:`query-history__status ${n.status==="success"?"query-history__status--success":"query-history__status--error"}`,children:e.jsx(H,{name:n.status==="success"?"check":"cross",size:12})}),e.jsx("span",{className:"query-history__database",children:n.database}),e.jsx("span",{className:"query-history__date",children:q(n.executedAt)}),e.jsxs("span",{className:"query-history__duration",children:[n.duration,"ms"]}),n.rowCount!==void 0&&e.jsx("span",{className:"query-history__row-count",children:c("terminal:database.rowCount",{count:n.rowCount})})]}),e.jsx("div",{className:"query-history__query",children:e.jsx("code",{children:n.query.length>200?n.query.substring(0,200)+"...":n.query})}),n.error&&e.jsx("div",{className:"query-history__error",children:n.error}),e.jsxs("div",{className:"query-history__actions",children:[e.jsx("button",{className:`query-history__favorite ${n.favorite?"query-history__favorite--active":""}`,onClick:d=>I(n.id,d),title:n.favorite?c("terminal:database.removeFromFavorites"):c("terminal:database.addToFavorites"),children:e.jsx(H,{name:"star",size:12,weight:n.favorite?"fill":"regular",color:n.favorite?"#facc15":void 0})}),e.jsx("button",{className:"query-history__delete",onClick:d=>R(n.id,d),title:c("terminal:database.deleteFromHistory"),children:e.jsx(H,{name:"trash",size:12})})]})]},n.id)),m.length===0&&e.jsx("div",{className:"query-history__no-results",children:c("terminal:database.noQueriesMatch")})]}),e.jsx(oe,{isOpen:L,title:c("terminal:database.clearAll"),message:c("terminal:database.confirmClearHistory"),confirmLabel:c("terminal:database.clearAll"),cancelLabel:c("common:buttons.cancel"),variant:"danger",onConfirm:()=>h.clearQueryHistory(a),onClose:()=>P(!1)})]})},ye=({tabs:a,activeTabId:x,onTabClick:l,onTabClose:c})=>{const{t:y}=J(["terminal"]);return e.jsx("div",{className:"database-tabs",children:a.map(f=>e.jsxs("div",{className:`database-tabs__tab ${x===f.id?"database-tabs__tab--active":""}`,children:[e.jsxs("button",{className:"database-tabs__tab-label",onClick:()=>l(f),title:`${f.connectionName} / ${f.database}`,children:[f.database,e.jsx("span",{className:"database-tabs__tab-connection",children:f.connectionName})]}),e.jsx("button",{className:"database-tabs__tab-close",onClick:()=>c(f.id),title:y("terminal:database.closeTab"),"aria-label":`Close ${f.database} tab`,children:"×"})]},f.id))})},ee=a=>`db-panel-${a}`;function Ne(a){try{const x=localStorage.getItem(ee(a));return x?JSON.parse(x):{}}catch{return{}}}function ve(a,x){try{localStorage.setItem(ee(a),JSON.stringify(x))}catch{}}const ge=({building:a,onClose:x})=>{var B,W,Y,X;const{t:l}=J(["terminal","common"]),c=Z(a.id),y=me(a.id),f=be(a.id),Q=ue(a.id),S=r.useRef(Ne(a.id)),L=r.useRef(null),P=r.useRef(0),m=((B=a.database)==null?void 0:B.connections)??[],q=(s,i)=>`${s}:${i}`,I=s=>s?(S.current.queries??{})[s]??"":S.current.generalQuery??"",[R,k]=r.useState("results"),[n,d]=r.useState(0),[g,$]=r.useState(!1),[w,U]=r.useState(!1),[F,K]=r.useState(()=>(S.current.openTabs??[]).map(i=>{var u;return{id:`${i.connectionId}:${i.database}`,connectionId:i.connectionId,connectionName:((u=m.find(A=>A.id===i.connectionId))==null?void 0:u.name)??i.connectionId,database:i.database}})),[C,O]=r.useState(S.current.activeTabId??null),[N,G]=r.useState(()=>{const s=S.current.queries??{};return S.current.generalQuery,s}),[j,p]=r.useState(I(C)),D=r.useCallback(s=>{p(i=>{const u=typeof s=="function"?s(i):s;return G(A=>{const E={...A};return C&&(E[C]=u),E}),u})},[C]),b=c.activeConnectionId??S.current.connectionId??((W=a.database)==null?void 0:W.activeConnectionId)??((Y=m[0])==null?void 0:Y.id),_=c.activeDatabase??S.current.database??((X=a.database)==null?void 0:X.activeDatabase),z=m.find(s=>s.id===b),t=b&&_?`${b}:${_}`:"",o=t?c.tables.get(t)??[]:[],T=r.useMemo(()=>{const s=new Map;return!b||!_||o.forEach(i=>{const u=c.tableSchemas.get(`${b}:${_}:${i.name}`);u&&s.set(i.name,{columns:u.columns})}),s},[b,_,o,c.tableSchemas]),v=r.useCallback((s,i)=>{var E;const u=q(s,i),A=((E=m.find(M=>M.id===s))==null?void 0:E.name)??s;K(M=>{if(M.some(ie=>ie.id===u))return M;const ce={id:u,connectionId:s,connectionName:A,database:i};return[...M,ce]}),O(u),p(N[u]??""),h.setActiveConnection(a.id,s),h.setActiveDatabase(a.id,i)},[a.id,m,N]),ae=r.useCallback(s=>{K(i=>i.filter(u=>u.id!==s)),C===s&&K(i=>{if(i.length>0){const u=i[0];O(u.id),p(N[u.id]??""),h.setActiveConnection(a.id,u.connectionId),h.setActiveDatabase(a.id,u.database)}else O(null),p("");return i})},[C,a.id,N]),se=r.useCallback(s=>{O(s.id),p(N[s.id]??""),h.setActiveConnection(a.id,s.connectionId),h.setActiveDatabase(a.id,s.database)},[a.id,N]);r.useEffect(()=>{if(!w&&m.length>0){const s=S.current;s.connectionId&&m.some(i=>i.id===s.connectionId)&&(h.setActiveConnection(a.id,s.connectionId),h.listDatabases(a.id,s.connectionId),s.database&&(h.setActiveDatabase(a.id,s.database),h.listTables(a.id,s.connectionId,s.database))),U(!0)}},[a.id,m,w]),r.useEffect(()=>{h.requestQueryHistory(a.id)},[a.id]),r.useEffect(()=>{const s=i=>{i.key==="Escape"&&(i.preventDefault(),i.stopPropagation(),x())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[x]),r.useEffect(()=>{w&&b&&ve(a.id,{connectionId:b,database:_,lastQuery:j,queries:N,generalQuery:"",openTabs:F.map(s=>({connectionId:s.connectionId,database:s.database})),activeTabId:C??void 0})},[a.id,b,_,j,w,F,C,N]);const te=r.useCallback(s=>{var i;if(!(!b||!_||!j.trim()||Q))if(s==="cursor"){const u=(i=L.current)==null?void 0:i.querySelector(".query-editor__textarea"),A=(u==null?void 0:u.selectionStart)??P.current,E=he(j,A);E&&h.executeQuery(a.id,b,_,E)}else{const u=_e(j);if(u.length<=1)h.executeQuery(a.id,b,_,j.trim());else{const A=b,E=_;(async()=>{for(const M of u)await h.executeQueryAndWait(a.id,A,E,M.sql)})()}}},[a.id,b,_,j,Q]),ne=r.useCallback(s=>{D(s),k("results")},[]),re=r.useCallback(s=>{h.setActiveConnection(a.id,s),h.listDatabases(a.id,s)},[a.id]),le=r.useCallback(s=>{b&&(v(b,s),h.listTables(a.id,b,s))},[a.id,b,v]),V=y[n];return m.length===0?e.jsxs("div",{className:"database-panel",ref:L,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:e.jsx(H,{name:"database",size:16})}),e.jsx("span",{className:"database-panel__name",children:a.name})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsx("div",{className:"database-panel__body",children:e.jsxs("div",{className:"database-panel__no-connections",children:[e.jsx("div",{className:"database-panel__no-connections-icon",children:e.jsx(H,{name:"plug",size:32})}),e.jsx("h3",{children:l("terminal:database.noConnections")}),e.jsx("p",{children:l("terminal:database.noConnectionsDesc")}),e.jsx("p",{children:l("terminal:database.toGetStarted")}),e.jsxs("ol",{children:[e.jsx("li",{children:l("terminal:database.step1Close")}),e.jsx("li",{children:l("terminal:database.step2Settings")}),e.jsx("li",{children:l("terminal:database.step3AddConnection")}),e.jsx("li",{children:l("terminal:database.step4Reopen")})]})]})})]}):e.jsxs("div",{className:"database-panel",ref:L,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:(z==null?void 0:z.engine)==="mysql"?"🐬":"🐘"}),e.jsx("span",{className:"database-panel__name",children:a.name}),z&&e.jsxs("span",{className:"database-panel__connection-info",children:[z.name," / ",_||l("terminal:database.noDatabaseSelected")]})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsxs("div",{className:"database-panel__body",children:[e.jsx(fe,{building:a,connections:m,activeConnectionId:b,activeDatabase:_,collapsed:g,onToggleCollapse:()=>$(!g),onConnectionChange:re,onDatabaseChange:le,onInsertTable:s=>D(i=>i+` ${s}`),onSelectTableQuery:s=>{const i=`SELECT * FROM ${s}`;D(i),b&&_&&h.executeQuery(a.id,b,_,i)}}),e.jsxs("div",{className:"database-panel__main",children:[F.length>0&&e.jsx(ye,{tabs:F,activeTabId:C,onTabClick:se,onTabClose:ae}),e.jsx(pe,{query:j,onChange:D,onExecute:te,isExecuting:Q,disabled:!b||!_,tables:o,tableSchemas:T,onRequestTableSchema:s=>{b&&_&&h.getTableSchema(a.id,b,_,s)}}),e.jsxs("div",{className:"database-panel__tabs",children:[e.jsxs("button",{className:`database-panel__tab ${R==="results"?"database-panel__tab--active":""}`,onClick:()=>k("results"),children:[l("terminal:database.results"),y.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:y.length})]}),e.jsxs("button",{className:`database-panel__tab ${R==="history"?"database-panel__tab--active":""}`,onClick:()=>k("history"),children:[l("terminal:database.history"),f.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:f.length})]}),R==="results"&&y.length>1&&e.jsxs("div",{className:"database-panel__result-nav",children:[e.jsxs("button",{disabled:n>=y.length-1,onClick:()=>d(s=>s+1),children:["← ",l("terminal:database.older")]}),e.jsxs("span",{children:[n+1," / ",y.length]}),e.jsxs("button",{disabled:n<=0,onClick:()=>d(s=>s-1),children:[l("terminal:database.newer")," →"]})]})]}),e.jsx("div",{className:"database-panel__tab-content",children:R==="results"?V?e.jsx(xe,{result:V,buildingId:a.id,building:a}):e.jsxs("div",{className:"database-panel__empty",children:[e.jsx("p",{children:l("terminal:database.noResultsYet")}),e.jsx("p",{children:l("terminal:database.selectDbAndRun")})]}):e.jsx(je,{buildingId:a.id,history:f,onLoadQuery:ne})})]})]})]})};export{ge as DatabasePanel,fe as DatabaseSidebar,ye as DatabaseTabs,pe as QueryEditor,je as QueryHistoryPanel,xe as ResultsTable};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as a,B as mn,E as Bt,G as Zt,H as Jt,j as e,J as Qt,K as fn,u as Rt,L as hn,M as gn,N as xn,O as bn,V as _n,P as wn,U as vn,W as Ft,S,X as Wt,Y as Dt,Z as Ht,_ as xt,$ as ge,a0 as Cn,s as b,a1 as en,a2 as tn,a3 as jn,w as Ut,x as Vt,I as p,a4 as Nn,n as kn,a5 as yn,a6 as nn,a7 as an,a8 as An,a9 as Sn,aa as En,ab as Mn,ac as In,ad as Tn,ae as Pn,af as Ln,ag as Dn,ah as Rn,ai as $n,aj as zn,ak as Xt,C as On,al as Bn,am as Gt,an as Fn,ao as Wn,ap as Hn,aq as Un,ar as Vn,as as Xn,at as Gn,au as qn,av as Yn,aw as Kn,ax as Zn,ay as Jn,az as Qn,aA as ea,aB as ta,aC as na,aD as aa,aE as sa}from"./main-D1dj_wn_.js";import{g as ia}from"./area-logos-BXaYMk1M.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function la(u){const r=a.useRef(u);r.current=u,a.useEffect(()=>{if(!mn())return;let m=null,h=!1;return Bt.addListener("backButton",()=>{r.current()==="exit"&&Bt.exitApp()}).then(N=>{h?N.remove():m=N}),()=>{h=!0,m&&(m.remove(),m=null)}},[])}async function ra(u){const r=Zt(),m=await fetch(`${Jt()}/api/agents/${u}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${r}`}});if(!m.ok){const h=await m.json().catch(()=>({}));throw new Error((h==null?void 0:h.error)||`Failed to start terminal (${m.status})`)}return m.json()}async function oa(u){const r=Zt();await fetch(`${Jt()}/api/agents/${u}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${r}`}})}const at=new Map;function ca({agentId:u}){const[r,m]=a.useState(null),[h,N]=a.useState(null);return a.useEffect(()=>{let P=!1;const M=at.get(u);return M&&(clearTimeout(M),at.delete(u)),m(null),N(null),ra(u).then(L=>{P||m(L.url)}).catch(L=>{P||N(L instanceof Error?L.message:"Failed to start terminal")}),()=>{P=!0;const L=at.get(u);L&&clearTimeout(L),at.set(u,setTimeout(()=>{at.delete(u),oa(u)},2500))}},[u]),h?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:h})}):r?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(Qt,{terminalUrl:r,visible:!0})}):e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:"Attaching to interactive session…"})})}const Pt=new Map,da=6e4;function ua({agentId:u,contextSummary:r}){const{t:m}=Rt(["terminal","common"]),[h,N]=a.useState(()=>{var I;return((I=Pt.get(u))==null?void 0:I.snapshot)??null}),[P,M]=a.useState(!1),[L,G]=a.useState(null),_=a.useRef(0);a.useEffect(()=>{const I=Pt.get(u);if(I&&Date.now()-I.fetchedAt<da){N(I.snapshot);return}const W=++_.current;M(!0),G(null),hn(u).then(U=>{W===_.current&&(Pt.set(u,{snapshot:U,fetchedAt:Date.now()}),N(U),M(!1))}).catch(U=>{W===_.current&&(G(U.message||"Failed to load plan limits"),M(!1))})},[u]);const F=[];if(h!=null&&h.rateLimits){const I=[{key:"fiveHour",label:m("terminal:usage.currentSession"),window:h.rateLimits.fiveHour},{key:"sevenDay",label:m("terminal:usage.currentWeekAll"),window:h.rateLimits.sevenDay},{key:"sevenDayOpus",label:m("terminal:usage.currentWeekOpus"),window:h.rateLimits.sevenDayOpus},{key:"sevenDaySonnet",label:m("terminal:usage.currentWeekSonnet"),window:h.rateLimits.sevenDaySonnet}];for(const W of I)W.window&&F.push({...W,window:W.window})}return e.jsxs("div",{className:"plan-limits-tooltip",children:[r&&e.jsx("div",{className:"plan-limits-tooltip__context",children:r}),e.jsx("div",{className:"plan-limits-tooltip__title",children:m("terminal:usage.limits")}),P&&!h&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[m("common:status.loading"),"…"]}),!P&&L&&!h&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:m("terminal:usage.limitsError",{message:L})}),F.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:F.map(({key:I,label:W,window:U})=>{const xe=Math.max(0,Math.min(100,U.utilization)),Z=xn(xe);return e.jsxs("div",{className:"plan-limits-tooltip__gauge",children:[e.jsxs("div",{className:"plan-limits-tooltip__gauge-head",children:[e.jsx("span",{className:"plan-limits-tooltip__gauge-label",children:W}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:Z},children:m("terminal:usage.percentUsed",{percent:Math.round(xe)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${xe}%`,background:Z}})}),e.jsx("div",{className:"plan-limits-tooltip__reset",children:m("terminal:usage.resets",{time:gn(U.resetsAt)})})]},I)})}):h&&!P&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:h.rateLimitsError?m("terminal:usage.limitsError",{message:h.rateLimitsError}):h.cliHint})]})}function pa({agentId:u,disabled:r,contextSummary:m,children:h}){return e.jsx(fn,{position:"top",maxWidth:320,disabled:r,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx(ua,{agentId:u,contextSummary:m}),children:h})}const ma=a.memo(function({className:r=""}){const{t:m}=Rt(["common"]),[h,N]=bn(),P=a.useRef(null),[M,L]=a.useState(null);a.useLayoutEffect(()=>{const _=P.current;if(!_)return;const F=_.querySelector(".view-mode-toggle__btn--active");F&&L({left:F.offsetLeft,width:F.offsetWidth})},[h]);const G=a.useCallback(_=>{if(_!==h){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:_}})),_==="3d"){requestAnimationFrame(()=>N(_));return}N(_)}},[h,N]);return e.jsxs("div",{className:`view-mode-toggle ${r}`,ref:P,children:[M&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:M.left,width:M.width}}),_n.map(_=>e.jsxs("button",{className:`view-mode-toggle__btn ${h===_?"view-mode-toggle__btn--active":""}`,onClick:()=>G(_),title:m(`common:viewMode.descriptions.${_}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[_==="2d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]}),_==="3d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]}),_==="flat"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1"})]}),_==="dashboard"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"12",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"3",y:"16",width:"7",height:"5",rx:"1"})]})]}),e.jsx("span",{className:"view-mode-toggle__label",children:m(`common:viewMode.labels.${_}`)})]},_))]})}),bt=3,_t=280,qt=320,Lt=240,Yt=64,fa=["simple","chat","advanced"],ha={simple:"Simple",chat:"Chat",advanced:"Advanced"},ga={simple:"○",chat:"◐",advanced:"◉"},xa={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Kt="flat-clear-context";function ba(u){const r=u.split("/").filter(Boolean);return r.length===0?u:r.slice(-2).join("/")}function _a(u){if(u.provider==="codex"){const P=u.codexModel||"gpt-5.3-codex",M=na[P];return{model:(M==null?void 0:M.label)||P}}if(u.provider==="opencode")return{model:u.opencodeModel||"opencode"};const r=u.model||"sonnet",m=sa[r],h=u.effort,N=h?aa[h]:void 0;return{model:(m==null?void 0:m.label)||r,effort:N==null?void 0:N.label}}function wa(u,r){if(r.type==="rectangle"&&r.width&&r.height){const m=r.width/2,h=r.height/2;return u.x>=r.center.x-m&&u.x<=r.center.x+m&&u.z>=r.center.z-h&&u.z<=r.center.z+h}if(r.type==="circle"&&r.radius){const m=u.x-r.center.x,h=u.z-r.center.z;return m*m+h*h<=r.radius*r.radius}return!1}const va=Bn.memo(function({agentId:r,terminalViewMode:m,onTerminalViewModeChange:h,inspectorOpen:N,onToggleInspector:P,onImageClick:M,onFileClick:L,onBashClick:G,onViewMarkdown:_,onRequestClearSubordinates:F,onOpenBuilding:I,keyboard:W,canNavigateBack:U,canNavigateForward:xe,onNavigateBack:Z,onNavigateForward:be,agentInfoOpen:Ee,onToggleAgentInfo:st,onHeaderContextMenu:ae,onBuildingContextMenu:_e}){var ut,pt,K,Ye;const f=Gt(r),H=tn(),we=Fn(),Me=a.useRef(null),We=a.useRef(null),{displayedAgentId:ve,fadingOut:wt}=Wn(r),it=Gt(ve),He=!!we.interactiveMode&&((f==null?void 0:f.provider)??"claude")==="claude"&&!!(f!=null&&f.sessionId),[J,Ue]=a.useState(!1);a.useEffect(()=>{Ue(!1)},[r]),a.useEffect(()=>{!He&&J&&Ue(!1)},[He,J]),a.useEffect(()=>{const s=We.current;if(!s)return;const l=d=>{d.button===3?(d.preventDefault(),d.stopPropagation(),Z()):d.button===4&&(d.preventDefault(),d.stopPropagation(),be())},c=d=>{(d.button===3||d.button===4)&&d.preventDefault()};return s.addEventListener("mouseup",l),s.addEventListener("mousedown",c),()=>{s.removeEventListener("mouseup",l),s.removeEventListener("mousedown",c)}},[Z,be]),a.useEffect(()=>{const s=We.current;if(!s)return;let l=0,c=0,d=0;const Se=250,ze=600,Ke=80,he=1.5,Et=X=>{let R=X instanceof HTMLElement?X:null;for(;R&&R!==s;){const Ze=window.getComputedStyle(R).overflowX;if((Ze==="auto"||Ze==="scroll")&&R.scrollWidth>R.clientWidth)return!0;R=R.parentElement}return!1},Oe=X=>{const R=Date.now();if(R<d){X.preventDefault();return}if(Math.abs(X.deltaX)<=Math.abs(X.deltaY)*he){l=0;return}if(Et(X.target)){l=0;return}R-c>Se&&(l=0),c=R,l+=X.deltaX,l<=-Ke?(l=0,d=R+ze,X.preventDefault(),Z()):l>=Ke&&(l=0,d=R+ze,X.preventDefault(),be())};return s.addEventListener("wheel",Oe,{passive:!1}),()=>s.removeEventListener("wheel",Oe)},[Z,be]);const Ce=en(),se=a.useMemo(()=>{if(!f)return null;const s=new Set,l=[];for(const c of Ce.values())c.archived||c.directories.length===0||c.assignedAgentIds.includes(r)&&(s.add(c.id),l.push(c));for(const c of Ce.values())c.archived||c.directories.length===0||s.has(c.id)||wa({x:f.position.x,z:f.position.z},c)&&(s.add(c.id),l.push(c));return l.length===0?null:l.flatMap(c=>c.directories.filter(d=>d&&d.trim().length>0).map(d=>({areaId:c.id,areaName:c.name,dir:d})))},[f,r,Ce]),{branches:ie,fetchRemote:le,fetchingDirs:lt}=Hn(se),Ve=a.useMemo(()=>{var c;const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const d of H.values())d.type==="terminal"&&b.isPositionInArea(d.position,s)&&l.push({id:d.id,name:d.name,hasUrl:!!((c=d.terminalStatus)!=null&&c.url)});return l},[r,H]),Ie=a.useMemo(()=>{var c;const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const d of H.values())d.type==="server"&&((c=d.pm2)!=null&&c.enabled)&&b.isPositionInArea(d.position,s)&&l.push({id:d.id,name:d.name});return l},[r,H]),je=a.useMemo(()=>{const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const c of H.values())c.type==="database"&&c.database&&b.isPositionInArea(c.position,s)&&l.push({id:c.id,name:c.name});return l},[r,H]),Ne=Un(),Te=a.useMemo(()=>{const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const c of H.values())if(c.type==="tests"&&b.isPositionInArea(c.position,s)){const d=!!c.folderPath&&Ne.some(Se=>Vn(Se,c.folderPath));l.push({id:c.id,name:c.name,working:d})}return l},[r,H,Ne]),[,Q]=a.useReducer(s=>s+1,0),re=((ut=Me.current)==null?void 0:ut.search.searchMode)??!1,ke=a.useCallback(()=>{var s;(s=Me.current)==null||s.search.toggleSearch(),Q()},[]),oe=Xn(),Je=oe.isPending(Kt),[ye,Pe]=a.useState(null),q=ye?H.get(ye):null,{height:vt,onResizeStart:Ct}=Gn(),{sidePanelWidth:Le,handleSidePanelResizeStart:jt}=qn(),[Ae,rt]=a.useState(()=>Dt(S.GIT_PANEL_OPEN,!1)),[ce,ot]=a.useState(()=>Dt(S.BUILDINGS_PANEL_OPEN,!1)),[De,ct]=a.useState(!1),Nt=a.useCallback(()=>{ct(s=>{const l=!s;return l&&Yn.setEnabled(!0),l})},[]),kt=a.useCallback(()=>ct(!1),[]),yt=a.useCallback(()=>{rt(s=>{const l=!s;return ge(S.GIT_PANEL_OPEN,l),l})},[]),Xe=a.useCallback(()=>{ot(s=>{const l=!s;return ge(S.BUILDINGS_PANEL_OPEN,l),l})},[]),v=a.useCallback(()=>{rt(!1),ge(S.GIT_PANEL_OPEN,!1)},[]),de=a.useCallback(()=>{ot(!1),ge(S.BUILDINGS_PANEL_OPEN,!1)},[]),Y=Kn();a.useEffect(()=>{if(!ye)return;Ve.some(l=>l.id===ye)||Pe(null)},[ye,Ve]);const[ee,ue]=a.useState(!1),Qe=a.useRef(null);if(a.useEffect(()=>{if(!ee)return;const s=l=>{Qe.current&&!Qe.current.contains(l.target)&&ue(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[ee]),!f)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const pe=f.contextStats,et=!!pe,dt=pe?pe.totalTokens:f.contextUsed||0,Ge=pe?pe.contextWindow:f.contextLimit||2e5,Re=pe?pe.usedPercent:Math.round(dt/Ge*100),te=Math.max(0,Math.min(100,Re)),me=Math.round(te*10)/10,At=Math.round((100-te)*10)/10,V=te>=80?"#ff4a4a":te>=60?"#ff9e4a":te>=40?"#ffd700":"#4aff9e",ne=(dt/1e3).toFixed(1),tt=(Ge/1e3).toFixed(1),fe=f.cwd,qe=fe?ba(fe):null,$e=((pt=f.subordinateIds)==null?void 0:pt.length)||0,St=$e>0;return e.jsxs("div",{ref:We,className:`flat-terminal-wrapper ${Ae||ce||De?"flat-terminal-wrapper--with-side-panel":""} ${wt?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${Le}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${Ee?"flat-terminal-wrapper__header-main--active":""}`,onClick:st,onContextMenu:s=>{s.preventDefault(),s.stopPropagation(),ae({x:s.clientX,y:s.clientY})},title:Ee?"Hide agent info":"Show agent info","aria-pressed":Ee,children:[e.jsx(nn,{agent:f,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:f.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:an(f.status)},children:f.status})]}),f.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:f.taskLabel,children:["📋 ",f.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:f.provider==="codex"?"/assets/codex.png":f.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:f.provider,className:"flat-terminal-wrapper__header-provider-icon",title:f.provider==="codex"?"Codex Agent":f.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:s,effort:l}=_a(f);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:l?`Model: ${s} · Effort: ${l}`:`Model: ${s}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:s}),l&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:l})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsxs("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:[fa.map(s=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!J&&m===s?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Ue(!1),h(s)},title:xa[s],"aria-pressed":!J&&m===s,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:ga[s]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:ha[s]})]},s)),He&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${J?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Ue(s=>!s),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":J,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:e.jsx(p,{name:"terminal",size:13})}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:"Classic TUI"})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:Z,disabled:!U,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(p,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:be,disabled:!xe,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(p,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${re?"flat-terminal-wrapper__action-btn--active":""}`,onClick:ke,title:re?"Close search":"Search messages","aria-pressed":re,children:e.jsx(p,{name:re?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Je?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>oe.handleClick(Kt,()=>{var s;b.clearContext(r),(s=Me.current)==null||s.historyLoader.clearHistory()}),title:Je?"Click again to confirm clear context":"Clear context",children:e.jsx(p,{name:Je?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Ae?"flat-terminal-wrapper__action-btn--active":""}`,onClick:yt,title:Ae?"Hide git panel":"Show git changes","aria-pressed":Ae,children:e.jsx(p,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ce?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Xe,title:ce?"Hide buildings panel":"Show area buildings","aria-pressed":ce,children:e.jsx(p,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:Qe,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ee?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>ue(s=>!s),title:"More actions","aria-expanded":ee,children:"⋮"}),ee&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${De?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Nt(),ue(!1)},title:De?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(p,{name:"bug",size:14}),e.jsx("span",{children:De?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{b.collapseContext(r),ue(!1)},disabled:f.status!=="idle",title:f.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(p,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),St&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{F(r,$e),ue(!1)},children:[e.jsx(p,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",$e," subordinate",$e===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{b.killAgent(r),ue(!1)},children:[e.jsx(p,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${N?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:P,title:N?"Hide inspector panel":"Show inspector panel","aria-label":N?"Hide inspector panel":"Show inspector panel","aria-pressed":N,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>b.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(p,{name:"cross",size:14})})]})]}),J&&He?e.jsx(ca,{agentId:r}):ve&&it?e.jsx(Zn,{ref:Me,agentId:ve,agent:it,viewMode:m,isOpen:!0,onImageClick:M,onFileClick:L,onBashClick:G,onViewMarkdown:_,keyboard:W,hasModalOpen:!1},ve):null,q&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:Ct,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${q.name}`,style:{height:vt},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(p,{name:"terminal",size:12}),e.jsx("span",{children:q.name}),!((K=q.terminalStatus)!=null&&K.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>Pe(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(p,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:(Ye=q.terminalStatus)!=null&&Ye.url?e.jsx(Qt,{terminalUrl:q.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."})})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[f.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(p,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),fe&&qe&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${fe}`,"aria-label":`Open ${fe} in file explorer`,role:"button",tabIndex:0,onClick:()=>b.openFileExplorer(fe),onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),b.openFileExplorer(fe))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(p,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:qe})]}),se&&se.map(({areaId:s,areaName:l,dir:c})=>{const d=ie.get(c),Se=lt.has(c),ze=c.split("/").filter(Boolean).pop()||c;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${l}: ${c}${d?` (${d.branch}${d.ahead?` ↑${d.ahead}`:""}${d.behind?` ↓${d.behind}`:""})`:""}`,onClick:()=>b.openFileExplorerForAreaFolder(s,c),children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:ze}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(p,{name:"git-branch",size:10})," ",d.branch]}),d.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${d.ahead} ahead`,children:[e.jsx(p,{name:"arrow-up",size:9}),d.ahead]}),d.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${d.behind} behind`,children:[e.jsx(p,{name:"arrow-down",size:9}),d.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${Se?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:Ke=>{Ke.stopPropagation(),le(c)},children:e.jsx(p,{name:Se?"hourglass":"download",size:12})})]})]},`${s}:${c}`)}),e.jsx(pa,{agentId:r,disabled:((f==null?void 0:f.provider)??"claude")!=="claude",contextSummary:et?`Context: ${ne}k / ${tt}k tokens (${me}% used)`:void 0,children:e.jsxs("span",{className:"flat-terminal-wrapper__context",tabIndex:0,role:"button",onClick:()=>b.setContextModalAgentId(r),onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),b.setContextModalAgentId(r))},title:((f==null?void 0:f.provider)??"claude")!=="claude"?et?`Context usage: ${ne}k / ${tt}k tokens (${me}% used). Click to view stats.`:"Click to fetch context stats":void 0,children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(p,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${te}%`,backgroundColor:V}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:V},children:[ne,"k/",tt,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",At,"% free)"]}),!et&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(p,{name:"warn",size:12})})]})}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),Ve.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:Ve.map(s=>{const l=ye===s.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${l?"flat-terminal-wrapper__building-btn--active":""} ${s.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${l?"Hide":"Show"} terminal: ${s.name}${s.hasUrl?"":" (starting...)"}`,onClick:()=>{if(l){Pe(null);return}s.hasUrl||b.sendBuildingCommand(s.id,"start"),Pe(s.id)},onContextMenu:c=>{c.preventDefault(),c.stopPropagation(),_e(s.id,{x:c.clientX,y:c.clientY})},children:e.jsx(p,{name:"terminal",size:14})},s.id)})}),Ie.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Ie.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"scroll",size:14})},s.id))}),je.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:je.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"hard-drives",size:14})},s.id))}),Te.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:Te.map(s=>e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${s.working?"flat-terminal-wrapper__building-btn--tests-working":""}`,title:s.working?`Running tests: ${s.name}`:`Open tests: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"flask",size:14})},s.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(Jn,{})})]}),Ae&&e.jsx(Qn,{agentId:r,agents:Y,onClose:v,branchInfoMap:ie,fetchRemote:le,fetchingDirs:lt,onResizeStart:s=>jt(s,"right")}),ce&&e.jsx(ea,{agentId:r,onClose:de}),De&&e.jsx(ta,{agentId:r,onClose:kt})]})});function ya({onAgentClick:u,onBuildingClick:r,onBuildingDoubleClick:m,onBuildingPopup:h,onAreaContextMenu:N,onOpenSpawnModal:P,onOpenBossSpawnModal:M,onOpenAreaModal:L}){const{t:G}=Rt(["common"]),_=wn(),F=vn(),[I,W]=a.useState(null),[U,xe]=a.useState(null),[Z,be]=a.useState(null),[Ee,st]=a.useState(null),[ae,_e]=a.useState(null),[f,H]=a.useState(null),[we,Me]=a.useState(null),[We,ve]=a.useState(!1),wt=a.useCallback(()=>{ve(t=>!t)},[]),it=a.useCallback(()=>{ve(!1)},[]),[He,J]=a.useState(()=>{const t=Ft(S.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ue=a.useCallback(t=>{J(t),Wt(S.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=n=>{if(n.key!==S.VIEW_MODE)return;const i=n.newValue;(i==="simple"||i==="chat"||i==="advanced")&&J(i)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[Ce,se]=a.useState(()=>Dt(S.FLAT_INSPECTOR_OPEN,!1)),[ie,le]=a.useState(!1),lt=a.useCallback(()=>le(t=>!t),[]),Ve=a.useCallback(()=>le(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:ie}}))},[ie]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:Ce}}))},[Ce]),a.useEffect(()=>{const t=()=>le(C=>!C),n=()=>{se(C=>{const k=!C;return ge(S.FLAT_INSPECTOR_OPEN,k),k})},i=()=>{le(!1),se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)},g=()=>le(!1),x=()=>{se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",n),window.addEventListener("tide-close-flat-side-views",i),window.addEventListener("tide-close-flat-agents-drawer-only",g),window.addEventListener("tide-close-flat-inspector-only",x),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",n),window.removeEventListener("tide-close-flat-side-views",i),window.removeEventListener("tide-close-flat-agents-drawer-only",g),window.removeEventListener("tide-close-flat-inspector-only",x)}},[]);const Ie=a.useRef(null),je=a.useRef(null),[Ne,Te]=a.useState(()=>{const t=Ht(S.FLAT_MIDDLE_WIDTH,0);return t>=_t?t:null}),[Q,re]=a.useState(()=>{const t=Ht(S.FLAT_INSPECTOR_WIDTH,0);return t>=Lt?t:null}),ke=a.useCallback(t=>{if(typeof window>"u")return t;const n=Q!==null?bt+Q:0,i=window.innerWidth-Yt-bt-qt-n;return Math.max(_t,Math.min(Math.max(i,_t),t))},[Q]),oe=a.useCallback(t=>{var x;if(typeof window>"u")return t;const n=(x=Ie.current)==null?void 0:x.querySelector(".flat-middle"),i=(n==null?void 0:n.getBoundingClientRect().width)??_t,g=window.innerWidth-Yt-i-bt-qt-bt;return Math.max(Lt,Math.min(Math.max(g,Lt),t))},[]);a.useEffect(()=>{if(Ne===null&&Q===null)return;const t=()=>{Te(n=>{if(n===null)return n;const i=ke(n);return i===n?n:i}),re(n=>{if(n===null)return n;const i=oe(n);return i===n?n:i})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[Ne,Q,ke,oe]);const Je=a.useCallback(t=>{var i;if(t.button!==0)return;const n=(i=Ie.current)==null?void 0:i.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),je.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),ye=a.useCallback(t=>{var i;if(t.button!==0)return;const n=(i=Ie.current)==null?void 0:i.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),je.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Pe=a.useCallback(t=>{const n=je.current;if(!n||t.pointerId!==n.pointerId)return;const i=t.clientX-n.startX;n.kind==="middle"?Te(ke(n.startWidth+i)):re(oe(n.startWidth-i))},[ke,oe]),q=a.useCallback(t=>{const n=je.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(je.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const g=t.clientX-n.startX;if(n.kind==="middle"){const x=ke(n.startWidth+g);Te(x),xt(S.FLAT_MIDDLE_WIDTH,x)}else{const x=oe(n.startWidth-g);re(x),xt(S.FLAT_INSPECTOR_WIDTH,x)}},[ke,oe]),vt=a.useCallback(()=>{Te(null),xt(S.FLAT_MIDDLE_WIDTH,0)},[]),Ct=a.useCallback(()=>{re(null),xt(S.FLAT_INSPECTOR_WIDTH,0)},[]),[Le,jt]=a.useState(()=>Ft(S.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Ae=a.useCallback(t=>{jt(t),Wt(S.FLAT_INSPECTOR_VIEW,t)},[]),rt=a.useCallback(()=>{se(t=>{const n=!t;return ge(S.FLAT_INSPECTOR_OPEN,n),n})},[]),ce=a.useCallback(()=>{se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)},[]),ot=Cn(),De=a.useCallback((t,n)=>{W({url:t,name:n})},[]),ct=a.useCallback((t,n)=>{xe({command:t,output:n,isLive:!1})},[]),Nt=a.useCallback((t,n)=>{b.setFileViewerPath(t,n)},[]),kt=a.useCallback(t=>{be(t)},[]),yt=a.useCallback((t,n)=>{st({agentId:t,count:n})},[]),Xe=a.useCallback(t=>{m?m(t):r(t)},[r,m]),v=a.useMemo(()=>F.size>0?Array.from(F)[0]:null,[F]);a.useEffect(()=>{ve(!1)},[v]);const de=a.useRef([]),Y=a.useRef(-1),ee=a.useRef(!1),ue=a.useRef(null),[Qe,pe]=a.useState(!1),[et,dt]=a.useState(!1),Ge=a.useRef(!1),Re=a.useRef(null),te=a.useRef(!1),me=a.useMemo(()=>new Set(_.map(t=>t.id)),[_]),At=a.useMemo(()=>{const t=new Map(_.map(i=>[i.id,i])),n=new Map;for(const i of _)if((i.isBoss||i.class==="boss")&&i.subordinateIds&&i.subordinateIds.length>0){const g=i.subordinateIds.map(x=>t.get(x)).filter(x=>x!==void 0);g.length>0&&n.set(i.id,g)}return n},[_]),V=a.useCallback(()=>{const t=de.current,n=Y.current;pe(n>0),dt(n>=0&&n<t.length-1)},[]),ne=a.useCallback(t=>{const n=de.current;if(n.length===0)return;let i=Y.current+t;for(;i>=0&&i<n.length;){const g=n[i];if(me.has(g)){ee.current=!0,Y.current=i,V(),b.selectAgent(g);return}i+=t}},[me,V]),tt=a.useCallback(()=>ne(-1),[ne]),fe=a.useCallback(()=>ne(1),[ne]);la(a.useCallback(()=>{const t=de.current,n=Y.current;return t.length>0&&n>0?(ne(-1),"handled"):"exit"},[ne]));const qe=a.useCallback((t,n)=>{if(typeof window>"u")return;const i=window.history.state,x={...typeof i=="object"&&i!==null?i:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(x,"",window.location.href):window.history.pushState(x,"",window.location.href)},[]);a.useEffect(()=>{if(!v){Ge.current=!1,Re.current=null;return}if(!Ge.current){qe(v,"replace"),Ge.current=!0,Re.current=v;return}if(te.current){te.current=!1,Re.current=v;return}Re.current!==v&&(qe(v,"push"),Re.current=v)},[v,qe]),a.useEffect(()=>{const t=n=>{var C,k;const i=(k=(C=n.state)==null?void 0:C.__flatAgentNav)==null?void 0:k.agentId;if(!i||typeof i!="string"||!me.has(i)||i===v)return;te.current=!0,ee.current=!0;const g=de.current,x=g.lastIndexOf(i);x>=0?Y.current=x:(g.push(i),Y.current=g.length-1),V(),b.selectAgent(i)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[me,v,V]),a.useEffect(()=>{if(!v){de.current=[],Y.current=-1,V();return}if(ue.current=v,ee.current){ee.current=!1,V();return}const t=de.current,n=Y.current;if(n>=0&&t[n]===v){V();return}const i=n<t.length-1?t.slice(0,n+1):t.slice();i.push(v),i.length>100&&i.shift(),de.current=i,Y.current=i.length-1,V()},[v,V]);const $e=a.useCallback(t=>{u(t),le(!1)},[u]),St=v??"",ut=a.useCallback(()=>{},[]),pt=a.useCallback(t=>{$e(t)},[$e]),K=Ce,[Ye,s]=a.useState(K),[l,c]=a.useState(K);a.useEffect(()=>{if(K){s(!0);return}c(!1);const t=setTimeout(()=>s(!1),240);return()=>clearTimeout(t)},[K]),a.useEffect(()=>{if(!Ye||!K)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>c(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[Ye,K]);const d=a.useRef(null);a.useEffect(()=>{if(v)return;const t=n=>{if(n.key!==" "&&n.key!=="Backspace")return;const i=n.target;if(i.tagName==="INPUT"||i.tagName==="TEXTAREA"||i.isContentEditable)return;const g=ue.current;!g||!me.has(g)||(n.preventDefault(),b.selectAgent(g))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[v,me]);const[Se,ze]=a.useState(new Set),Ke=a.useCallback(t=>{ze(n=>{const i=new Set(n);return i.has(t)?i.delete(t):i.add(t),i})},[]),[he,Et]=a.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),n=i=>Et(i.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const[Oe,X]=a.useState(null),R=a.useCallback(t=>{X(n=>n===t?null:t)},[]),Ze=en(),mt=tn(),[sn]=jn(),Be=a.useMemo(()=>{const t=new Map,n=[];for(const w of _){const A=b.getAreaForAgent(w.id);if(!Ut((A==null?void 0:A.id)??null))continue;if(!A||A.archived){n.push(w);continue}const E=t.get(A.id);E?E.push(w):t.set(A.id,[w])}const i=new Map,g=[];for(const w of mt.values()){let A=!1;for(const E of Ze.values())if(!E.archived&&Vt(E.id)&&b.isPositionInArea(w.position,E)){const z=i.get(E.id);z?z.push(w):i.set(E.id,[w]),A=!0;break}!A&&Ut(null)&&g.push(w)}const x=[];for(const[,w]of Ze){if(w.archived||!Vt(w.id))continue;const A=t.get(w.id),E=i.get(w.id)??[];(A&&A.length>0||E.length>0)&&x.push({area:w,agents:A??[],buildings:E})}(n.length>0||g.length>0)&&x.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:n,buildings:g});const C=x.filter(w=>w.area.id!=="__unassigned__"),k=x.filter(w=>w.area.id==="__unassigned__");let o=1,y=1;const $=new Map;if(C.length>1){let w=1/0,A=-1/0,E=1/0,z=-1/0;for(const O of C)w=Math.min(w,O.area.center.x),A=Math.max(A,O.area.center.x),E=Math.min(E,O.area.center.z),z=Math.max(z,O.area.center.z);const ft=A-w||1,ht=z-E||1;if(C.length<=4){o=C.length,y=1;const O=[...C].sort((B,Mt)=>B.area.center.x-Mt.area.center.x);for(let B=0;B<O.length;B++)$.set(O[B].area.id,{row:1,col:B+1})}else{const O=[...C].sort((j,D)=>j.area.center.x-D.area.center.x),B=[];for(let j=1;j<O.length;j++)B.push(O[j].area.center.x-O[j-1].area.center.x);const Mt=B.reduce((j,D)=>j+D,0)/B.length||1;let $t=1;for(const j of B)j>Mt*1.3&&$t++;o=Math.max(2,Math.min($t,C.length));const It=[...C].sort((j,D)=>j.area.center.z-D.area.center.z),gt=[];for(let j=1;j<It.length;j++)gt.push(It[j].area.center.z-It[j-1].area.center.z);const cn=gt.reduce((j,D)=>j+D,0)/gt.length||1;let zt=1;for(const j of gt)j>cn*1.3&&zt++;y=Math.max(2,Math.min(zt,C.length)),o=Math.max(o,Math.ceil(C.length/y)),y=Math.max(y,Math.ceil(C.length/o));const dn=ft/o,un=ht/y,Tt=new Set;for(const j of C){let D=Math.min(o-1,Math.max(0,Math.floor((j.area.center.x-w)/dn))),Fe=Math.min(y-1,Math.max(0,Math.floor((j.area.center.z-E)/un))),nt=`${Fe},${D}`,Ot=0;const pn=y*o;for(;Tt.has(nt)&&Ot<pn;)D++,D>=o&&(D=0,Fe=(Fe+1)%y),nt=`${Fe},${D}`,Ot++;Tt.has(nt)&&(Fe=y,D=0,nt=`${Fe},${D}`,y++),Tt.add(nt),$.set(j.area.id,{row:Fe+1,col:D+1})}}}const T=w=>{w.sort((A,E)=>{var ft,ht,O,B;const z=(((ft=A.position)==null?void 0:ft.z)??0)-(((ht=E.position)==null?void 0:ht.z)??0);return z!==0?z:(((O=A.position)==null?void 0:O.x)??0)-(((B=E.position)==null?void 0:B.x)??0)})};for(const w of C)T(w.agents);for(const w of k)T(w.agents);return{groups:[...C,...k],gridCols:o,gridRows:y,positions:$}},[_,Ze,mt,sn]),ln=a.useMemo(()=>{if(!ae)return[];const t=_.find(n=>n.id===ae.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(p,{name:"chat",size:14}),onClick:()=>u(t.id)},{id:"clone-agent",label:"Clone Agent",icon:e.jsx(p,{name:"clipboard",size:14}),onClick:()=>b.cloneAgent(t.id)},{id:"fork-agent",label:"Fork Agent (with history)",icon:e.jsx(p,{name:"git-branch",size:14}),onClick:()=>b.forkAgent(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>{Me({agentId:t.id,name:t.name})}}]:[]},[ae,_,u]),rn=a.useMemo(()=>{var C;if(!f)return[];const t=mt.get(f.buildingId);if(!t)return[];const n=[],i=t.type==="server"||t.type==="docker"||t.type==="terminal",g=t.status==="running",x=t.type==="boss";if(n.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="tests"?"Open Tests":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((C=t.pm2)!=null&&C.enabled)?"View PM2 Logs":"Open",icon:e.jsx(p,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="tests"?"flask":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>Xe(t.id)}),i&&(g||n.push({id:"start",label:"Start",icon:e.jsx(p,{name:"play",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"start")}),g&&(n.push({id:"restart",label:"Restart",icon:e.jsx(p,{name:"refresh",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(p,{name:"stop",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"stop")}))),x&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(n.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(p,{name:"launch",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"start")}}),n.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(p,{name:"pause",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"stop")}}),n.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(p,{name:"restart",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"restart")}})),i&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(p,{name:"health",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"healthCheck")}),n.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),n.push({id:"edit",label:"Edit Building",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),n.push({id:"clone",label:"Clone Building",icon:e.jsx(p,{name:"copy",size:14}),onClick:()=>{b.createBuilding({name:`${t.name} (Copy)`,type:t.type,style:t.style,color:t.color,scale:t.scale,position:{x:t.position.x+2,z:t.position.z+2},cwd:t.cwd,folderPath:t.folderPath,commands:t.commands,pm2:t.pm2,docker:t.docker,database:t.database,terminal:t.terminal,urls:t.urls,subordinateBuildingIds:t.subordinateBuildingIds})}}),t.urls&&t.urls.length>0)for(const k of t.urls)n.push({id:`url-${k.label}`,label:k.label,icon:e.jsx(p,{name:"link",size:14}),onClick:()=>window.open(k.url,"_blank","noopener,noreferrer")});return n.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),n.push({id:"delete",label:"Delete Building",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>b.deleteBuilding(t.id)}),n},[f,mt,Xe]),on=a.useCallback(t=>{const n=new Set(Be.groups.map(i=>i.area.id));n.delete(t),ze(n),requestAnimationFrame(()=>{const i=d.current;if(!i)return;const g=i.querySelector(`[data-area-id="${t}"]`);if(!g)return;const x=i.getBoundingClientRect(),k=g.getBoundingClientRect().top-x.top+i.scrollTop-8;i.scrollTo({top:Math.max(0,k),behavior:"smooth"})})},[Be]);return e.jsxs("div",{ref:Ie,className:`flat-view ${K?"flat-view--with-inspector":""} ${v?"flat-view--has-chat":""} ${ie?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(Ne===null&&Q===null)return;const t={};return Ne!==null&&(t["--flat-middle-width"]=`${Ne}px`),Q!==null&&(t["--flat-inspector-width"]=`${Q}px`),t})(),children:[ie&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Ve,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children:e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:P,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:M,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:L,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(Nn,{activeAgentId:St,onClose:ut,onSelectAgent:pt,collapsedAreas:Se,onToggleArea:Ke,agentListRef:d})})]}),e.jsx("div",{className:"flat-splitter flat-splitter--middle",role:"separator","aria-orientation":"vertical","aria-label":"Resize agents panel",title:"Drag to resize · Double-click to reset",onPointerDown:Je,onPointerMove:Pe,onPointerUp:q,onPointerCancel:q,onDoubleClick:vt}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":ie?"Close agents sidebar":"Open agents sidebar","aria-expanded":ie,onClick:lt,children:[e.jsx(p,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),v?e.jsx(va,{agentId:v,terminalViewMode:He,onTerminalViewModeChange:Ue,inspectorOpen:Ce,onToggleInspector:rt,onImageClick:De,onFileClick:Nt,onBashClick:ct,onViewMarkdown:kt,onRequestClearSubordinates:yt,onOpenBuilding:Xe,keyboard:ot,canNavigateBack:Qe,canNavigateForward:et,onNavigateBack:tt,onNavigateForward:fe,agentInfoOpen:We,onToggleAgentInfo:wt,onHeaderContextMenu:t=>{v&&_e({agentId:v,position:t})},onBuildingContextMenu:(t,n)=>{H({buildingId:t,position:n})}}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"}),e.jsx(ma,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Be.gridCols}, 1fr)`},children:Be.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var n;const t=he&&Oe?((n=Be.positions.get(Oe))==null?void 0:n.row)??null:null;return Be.groups.map(i=>{var k;const g=i.area.id,x=Be.positions.get(g),C=he&&Oe!==g;return he&&t!=null&&(x==null?void 0:x.row)===t&&g!==Oe?null:e.jsxs("div",{className:`flat-map-area-card${C?" flat-map-area-card--collapsed":""}`,style:{"--area-color":i.area.color,gridRow:x==null?void 0:x.row,gridColumn:x==null?void 0:x.col},onContextMenu:o=>{N&&(o.preventDefault(),o.stopPropagation(),N(g,{x:o.clientX,y:o.clientY}))},children:[((k=i.area.logo)==null?void 0:k.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:ia(i.area.logo.filename),alt:"","aria-hidden":"true",onError:o=>{o.currentTarget.style.display="none"}}),e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>he?R(g):on(g),title:he?C?`Expand ${i.area.name}`:`Collapse ${i.area.name}`:`Focus ${i.area.name} in left panel`,"aria-expanded":he?!C:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:i.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:i.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:i.agents.length}),he&&e.jsx(p,{name:C?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:i.agents.map(o=>{const y=o.isBoss||o.class==="boss",$=y?At.get(o.id):void 0,T=kn(o),w=T.usedPercent>=80?"#ff4a4a":T.usedPercent>=60?"#ff9e4a":T.usedPercent>=40?"#ffd700":"#4aff9e",A=`Context: ${(T.totalTokens/1e3).toFixed(1)}k / ${(T.contextWindow/1e3).toFixed(1)}k (${T.usedPercent}% used, ${T.freePercent}% free)`,E=o.latestTodos&&o.latestTodos.length>0||$&&$.length>0;return e.jsx(yn,{todos:o.latestTodos,subordinates:$,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${o.status}`,onClick:()=>u(o.id),onContextMenu:z=>{z.preventDefault(),z.stopPropagation(),_e({agentId:o.id,position:{x:z.clientX,y:z.clientY}})},title:E?void 0:`${y?"Boss · ":""}Open chat with ${o.name}
|
|
1
|
+
import{r as a,B as mn,E as Bt,G as Zt,H as Jt,j as e,J as Qt,K as fn,u as Rt,L as hn,M as gn,N as xn,O as bn,V as _n,P as wn,U as vn,W as Ft,S,X as Wt,Y as Dt,Z as Ht,_ as xt,$ as ge,a0 as Cn,s as b,a1 as en,a2 as tn,a3 as jn,w as Ut,x as Vt,I as p,a4 as Nn,n as kn,a5 as yn,a6 as nn,a7 as an,a8 as An,a9 as Sn,aa as En,ab as Mn,ac as In,ad as Tn,ae as Pn,af as Ln,ag as Dn,ah as Rn,ai as $n,aj as zn,ak as Xt,C as On,al as Bn,am as Gt,an as Fn,ao as Wn,ap as Hn,aq as Un,ar as Vn,as as Xn,at as Gn,au as qn,av as Yn,aw as Kn,ax as Zn,ay as Jn,az as Qn,aA as ea,aB as ta,aC as na,aD as aa,aE as sa}from"./main-DZgTocNE.js";import{g as ia}from"./area-logos-C5XZBFfj.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function la(u){const r=a.useRef(u);r.current=u,a.useEffect(()=>{if(!mn())return;let m=null,h=!1;return Bt.addListener("backButton",()=>{r.current()==="exit"&&Bt.exitApp()}).then(N=>{h?N.remove():m=N}),()=>{h=!0,m&&(m.remove(),m=null)}},[])}async function ra(u){const r=Zt(),m=await fetch(`${Jt()}/api/agents/${u}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${r}`}});if(!m.ok){const h=await m.json().catch(()=>({}));throw new Error((h==null?void 0:h.error)||`Failed to start terminal (${m.status})`)}return m.json()}async function oa(u){const r=Zt();await fetch(`${Jt()}/api/agents/${u}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${r}`}})}const at=new Map;function ca({agentId:u}){const[r,m]=a.useState(null),[h,N]=a.useState(null);return a.useEffect(()=>{let P=!1;const M=at.get(u);return M&&(clearTimeout(M),at.delete(u)),m(null),N(null),ra(u).then(L=>{P||m(L.url)}).catch(L=>{P||N(L instanceof Error?L.message:"Failed to start terminal")}),()=>{P=!0;const L=at.get(u);L&&clearTimeout(L),at.set(u,setTimeout(()=>{at.delete(u),oa(u)},2500))}},[u]),h?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:h})}):r?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(Qt,{terminalUrl:r,visible:!0})}):e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:"Attaching to interactive session…"})})}const Pt=new Map,da=6e4;function ua({agentId:u,contextSummary:r}){const{t:m}=Rt(["terminal","common"]),[h,N]=a.useState(()=>{var I;return((I=Pt.get(u))==null?void 0:I.snapshot)??null}),[P,M]=a.useState(!1),[L,G]=a.useState(null),_=a.useRef(0);a.useEffect(()=>{const I=Pt.get(u);if(I&&Date.now()-I.fetchedAt<da){N(I.snapshot);return}const W=++_.current;M(!0),G(null),hn(u).then(U=>{W===_.current&&(Pt.set(u,{snapshot:U,fetchedAt:Date.now()}),N(U),M(!1))}).catch(U=>{W===_.current&&(G(U.message||"Failed to load plan limits"),M(!1))})},[u]);const F=[];if(h!=null&&h.rateLimits){const I=[{key:"fiveHour",label:m("terminal:usage.currentSession"),window:h.rateLimits.fiveHour},{key:"sevenDay",label:m("terminal:usage.currentWeekAll"),window:h.rateLimits.sevenDay},{key:"sevenDayOpus",label:m("terminal:usage.currentWeekOpus"),window:h.rateLimits.sevenDayOpus},{key:"sevenDaySonnet",label:m("terminal:usage.currentWeekSonnet"),window:h.rateLimits.sevenDaySonnet}];for(const W of I)W.window&&F.push({...W,window:W.window})}return e.jsxs("div",{className:"plan-limits-tooltip",children:[r&&e.jsx("div",{className:"plan-limits-tooltip__context",children:r}),e.jsx("div",{className:"plan-limits-tooltip__title",children:m("terminal:usage.limits")}),P&&!h&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[m("common:status.loading"),"…"]}),!P&&L&&!h&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:m("terminal:usage.limitsError",{message:L})}),F.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:F.map(({key:I,label:W,window:U})=>{const xe=Math.max(0,Math.min(100,U.utilization)),Z=xn(xe);return e.jsxs("div",{className:"plan-limits-tooltip__gauge",children:[e.jsxs("div",{className:"plan-limits-tooltip__gauge-head",children:[e.jsx("span",{className:"plan-limits-tooltip__gauge-label",children:W}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:Z},children:m("terminal:usage.percentUsed",{percent:Math.round(xe)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${xe}%`,background:Z}})}),e.jsx("div",{className:"plan-limits-tooltip__reset",children:m("terminal:usage.resets",{time:gn(U.resetsAt)})})]},I)})}):h&&!P&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:h.rateLimitsError?m("terminal:usage.limitsError",{message:h.rateLimitsError}):h.cliHint})]})}function pa({agentId:u,disabled:r,contextSummary:m,children:h}){return e.jsx(fn,{position:"top",maxWidth:320,disabled:r,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx(ua,{agentId:u,contextSummary:m}),children:h})}const ma=a.memo(function({className:r=""}){const{t:m}=Rt(["common"]),[h,N]=bn(),P=a.useRef(null),[M,L]=a.useState(null);a.useLayoutEffect(()=>{const _=P.current;if(!_)return;const F=_.querySelector(".view-mode-toggle__btn--active");F&&L({left:F.offsetLeft,width:F.offsetWidth})},[h]);const G=a.useCallback(_=>{if(_!==h){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:_}})),_==="3d"){requestAnimationFrame(()=>N(_));return}N(_)}},[h,N]);return e.jsxs("div",{className:`view-mode-toggle ${r}`,ref:P,children:[M&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:M.left,width:M.width}}),_n.map(_=>e.jsxs("button",{className:`view-mode-toggle__btn ${h===_?"view-mode-toggle__btn--active":""}`,onClick:()=>G(_),title:m(`common:viewMode.descriptions.${_}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[_==="2d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]}),_==="3d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]}),_==="flat"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1"})]}),_==="dashboard"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"12",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"3",y:"16",width:"7",height:"5",rx:"1"})]})]}),e.jsx("span",{className:"view-mode-toggle__label",children:m(`common:viewMode.labels.${_}`)})]},_))]})}),bt=3,_t=280,qt=320,Lt=240,Yt=64,fa=["simple","chat","advanced"],ha={simple:"Simple",chat:"Chat",advanced:"Advanced"},ga={simple:"○",chat:"◐",advanced:"◉"},xa={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Kt="flat-clear-context";function ba(u){const r=u.split("/").filter(Boolean);return r.length===0?u:r.slice(-2).join("/")}function _a(u){if(u.provider==="codex"){const P=u.codexModel||"gpt-5.3-codex",M=na[P];return{model:(M==null?void 0:M.label)||P}}if(u.provider==="opencode")return{model:u.opencodeModel||"opencode"};const r=u.model||"sonnet",m=sa[r],h=u.effort,N=h?aa[h]:void 0;return{model:(m==null?void 0:m.label)||r,effort:N==null?void 0:N.label}}function wa(u,r){if(r.type==="rectangle"&&r.width&&r.height){const m=r.width/2,h=r.height/2;return u.x>=r.center.x-m&&u.x<=r.center.x+m&&u.z>=r.center.z-h&&u.z<=r.center.z+h}if(r.type==="circle"&&r.radius){const m=u.x-r.center.x,h=u.z-r.center.z;return m*m+h*h<=r.radius*r.radius}return!1}const va=Bn.memo(function({agentId:r,terminalViewMode:m,onTerminalViewModeChange:h,inspectorOpen:N,onToggleInspector:P,onImageClick:M,onFileClick:L,onBashClick:G,onViewMarkdown:_,onRequestClearSubordinates:F,onOpenBuilding:I,keyboard:W,canNavigateBack:U,canNavigateForward:xe,onNavigateBack:Z,onNavigateForward:be,agentInfoOpen:Ee,onToggleAgentInfo:st,onHeaderContextMenu:ae,onBuildingContextMenu:_e}){var ut,pt,K,Ye;const f=Gt(r),H=tn(),we=Fn(),Me=a.useRef(null),We=a.useRef(null),{displayedAgentId:ve,fadingOut:wt}=Wn(r),it=Gt(ve),He=!!we.interactiveMode&&((f==null?void 0:f.provider)??"claude")==="claude"&&!!(f!=null&&f.sessionId),[J,Ue]=a.useState(!1);a.useEffect(()=>{Ue(!1)},[r]),a.useEffect(()=>{!He&&J&&Ue(!1)},[He,J]),a.useEffect(()=>{const s=We.current;if(!s)return;const l=d=>{d.button===3?(d.preventDefault(),d.stopPropagation(),Z()):d.button===4&&(d.preventDefault(),d.stopPropagation(),be())},c=d=>{(d.button===3||d.button===4)&&d.preventDefault()};return s.addEventListener("mouseup",l),s.addEventListener("mousedown",c),()=>{s.removeEventListener("mouseup",l),s.removeEventListener("mousedown",c)}},[Z,be]),a.useEffect(()=>{const s=We.current;if(!s)return;let l=0,c=0,d=0;const Se=250,ze=600,Ke=80,he=1.5,Et=X=>{let R=X instanceof HTMLElement?X:null;for(;R&&R!==s;){const Ze=window.getComputedStyle(R).overflowX;if((Ze==="auto"||Ze==="scroll")&&R.scrollWidth>R.clientWidth)return!0;R=R.parentElement}return!1},Oe=X=>{const R=Date.now();if(R<d){X.preventDefault();return}if(Math.abs(X.deltaX)<=Math.abs(X.deltaY)*he){l=0;return}if(Et(X.target)){l=0;return}R-c>Se&&(l=0),c=R,l+=X.deltaX,l<=-Ke?(l=0,d=R+ze,X.preventDefault(),Z()):l>=Ke&&(l=0,d=R+ze,X.preventDefault(),be())};return s.addEventListener("wheel",Oe,{passive:!1}),()=>s.removeEventListener("wheel",Oe)},[Z,be]);const Ce=en(),se=a.useMemo(()=>{if(!f)return null;const s=new Set,l=[];for(const c of Ce.values())c.archived||c.directories.length===0||c.assignedAgentIds.includes(r)&&(s.add(c.id),l.push(c));for(const c of Ce.values())c.archived||c.directories.length===0||s.has(c.id)||wa({x:f.position.x,z:f.position.z},c)&&(s.add(c.id),l.push(c));return l.length===0?null:l.flatMap(c=>c.directories.filter(d=>d&&d.trim().length>0).map(d=>({areaId:c.id,areaName:c.name,dir:d})))},[f,r,Ce]),{branches:ie,fetchRemote:le,fetchingDirs:lt}=Hn(se),Ve=a.useMemo(()=>{var c;const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const d of H.values())d.type==="terminal"&&b.isPositionInArea(d.position,s)&&l.push({id:d.id,name:d.name,hasUrl:!!((c=d.terminalStatus)!=null&&c.url)});return l},[r,H]),Ie=a.useMemo(()=>{var c;const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const d of H.values())d.type==="server"&&((c=d.pm2)!=null&&c.enabled)&&b.isPositionInArea(d.position,s)&&l.push({id:d.id,name:d.name});return l},[r,H]),je=a.useMemo(()=>{const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const c of H.values())c.type==="database"&&c.database&&b.isPositionInArea(c.position,s)&&l.push({id:c.id,name:c.name});return l},[r,H]),Ne=Un(),Te=a.useMemo(()=>{const s=b.getAreaForAgent(r);if(!s)return[];const l=[];for(const c of H.values())if(c.type==="tests"&&b.isPositionInArea(c.position,s)){const d=!!c.folderPath&&Ne.some(Se=>Vn(Se,c.folderPath));l.push({id:c.id,name:c.name,working:d})}return l},[r,H,Ne]),[,Q]=a.useReducer(s=>s+1,0),re=((ut=Me.current)==null?void 0:ut.search.searchMode)??!1,ke=a.useCallback(()=>{var s;(s=Me.current)==null||s.search.toggleSearch(),Q()},[]),oe=Xn(),Je=oe.isPending(Kt),[ye,Pe]=a.useState(null),q=ye?H.get(ye):null,{height:vt,onResizeStart:Ct}=Gn(),{sidePanelWidth:Le,handleSidePanelResizeStart:jt}=qn(),[Ae,rt]=a.useState(()=>Dt(S.GIT_PANEL_OPEN,!1)),[ce,ot]=a.useState(()=>Dt(S.BUILDINGS_PANEL_OPEN,!1)),[De,ct]=a.useState(!1),Nt=a.useCallback(()=>{ct(s=>{const l=!s;return l&&Yn.setEnabled(!0),l})},[]),kt=a.useCallback(()=>ct(!1),[]),yt=a.useCallback(()=>{rt(s=>{const l=!s;return ge(S.GIT_PANEL_OPEN,l),l})},[]),Xe=a.useCallback(()=>{ot(s=>{const l=!s;return ge(S.BUILDINGS_PANEL_OPEN,l),l})},[]),v=a.useCallback(()=>{rt(!1),ge(S.GIT_PANEL_OPEN,!1)},[]),de=a.useCallback(()=>{ot(!1),ge(S.BUILDINGS_PANEL_OPEN,!1)},[]),Y=Kn();a.useEffect(()=>{if(!ye)return;Ve.some(l=>l.id===ye)||Pe(null)},[ye,Ve]);const[ee,ue]=a.useState(!1),Qe=a.useRef(null);if(a.useEffect(()=>{if(!ee)return;const s=l=>{Qe.current&&!Qe.current.contains(l.target)&&ue(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[ee]),!f)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const pe=f.contextStats,et=!!pe,dt=pe?pe.totalTokens:f.contextUsed||0,Ge=pe?pe.contextWindow:f.contextLimit||2e5,Re=pe?pe.usedPercent:Math.round(dt/Ge*100),te=Math.max(0,Math.min(100,Re)),me=Math.round(te*10)/10,At=Math.round((100-te)*10)/10,V=te>=80?"#ff4a4a":te>=60?"#ff9e4a":te>=40?"#ffd700":"#4aff9e",ne=(dt/1e3).toFixed(1),tt=(Ge/1e3).toFixed(1),fe=f.cwd,qe=fe?ba(fe):null,$e=((pt=f.subordinateIds)==null?void 0:pt.length)||0,St=$e>0;return e.jsxs("div",{ref:We,className:`flat-terminal-wrapper ${Ae||ce||De?"flat-terminal-wrapper--with-side-panel":""} ${wt?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${Le}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${Ee?"flat-terminal-wrapper__header-main--active":""}`,onClick:st,onContextMenu:s=>{s.preventDefault(),s.stopPropagation(),ae({x:s.clientX,y:s.clientY})},title:Ee?"Hide agent info":"Show agent info","aria-pressed":Ee,children:[e.jsx(nn,{agent:f,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:f.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:an(f.status)},children:f.status})]}),f.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:f.taskLabel,children:["📋 ",f.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:f.provider==="codex"?"/assets/codex.png":f.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:f.provider,className:"flat-terminal-wrapper__header-provider-icon",title:f.provider==="codex"?"Codex Agent":f.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:s,effort:l}=_a(f);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:l?`Model: ${s} · Effort: ${l}`:`Model: ${s}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:s}),l&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:l})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsxs("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:[fa.map(s=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!J&&m===s?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Ue(!1),h(s)},title:xa[s],"aria-pressed":!J&&m===s,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:ga[s]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:ha[s]})]},s)),He&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${J?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Ue(s=>!s),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":J,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:e.jsx(p,{name:"terminal",size:13})}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:"Classic TUI"})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:Z,disabled:!U,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(p,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:be,disabled:!xe,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(p,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${re?"flat-terminal-wrapper__action-btn--active":""}`,onClick:ke,title:re?"Close search":"Search messages","aria-pressed":re,children:e.jsx(p,{name:re?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Je?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>oe.handleClick(Kt,()=>{var s;b.clearContext(r),(s=Me.current)==null||s.historyLoader.clearHistory()}),title:Je?"Click again to confirm clear context":"Clear context",children:e.jsx(p,{name:Je?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Ae?"flat-terminal-wrapper__action-btn--active":""}`,onClick:yt,title:Ae?"Hide git panel":"Show git changes","aria-pressed":Ae,children:e.jsx(p,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ce?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Xe,title:ce?"Hide buildings panel":"Show area buildings","aria-pressed":ce,children:e.jsx(p,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:Qe,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ee?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>ue(s=>!s),title:"More actions","aria-expanded":ee,children:"⋮"}),ee&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${De?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Nt(),ue(!1)},title:De?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(p,{name:"bug",size:14}),e.jsx("span",{children:De?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{b.collapseContext(r),ue(!1)},disabled:f.status!=="idle",title:f.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(p,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),St&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{F(r,$e),ue(!1)},children:[e.jsx(p,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",$e," subordinate",$e===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{b.killAgent(r),ue(!1)},children:[e.jsx(p,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${N?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:P,title:N?"Hide inspector panel":"Show inspector panel","aria-label":N?"Hide inspector panel":"Show inspector panel","aria-pressed":N,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>b.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(p,{name:"cross",size:14})})]})]}),J&&He?e.jsx(ca,{agentId:r}):ve&&it?e.jsx(Zn,{ref:Me,agentId:ve,agent:it,viewMode:m,isOpen:!0,onImageClick:M,onFileClick:L,onBashClick:G,onViewMarkdown:_,keyboard:W,hasModalOpen:!1},ve):null,q&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:Ct,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${q.name}`,style:{height:vt},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(p,{name:"terminal",size:12}),e.jsx("span",{children:q.name}),!((K=q.terminalStatus)!=null&&K.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>Pe(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(p,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:(Ye=q.terminalStatus)!=null&&Ye.url?e.jsx(Qt,{terminalUrl:q.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."})})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[f.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(p,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),fe&&qe&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${fe}`,"aria-label":`Open ${fe} in file explorer`,role:"button",tabIndex:0,onClick:()=>b.openFileExplorer(fe),onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),b.openFileExplorer(fe))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(p,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:qe})]}),se&&se.map(({areaId:s,areaName:l,dir:c})=>{const d=ie.get(c),Se=lt.has(c),ze=c.split("/").filter(Boolean).pop()||c;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${l}: ${c}${d?` (${d.branch}${d.ahead?` ↑${d.ahead}`:""}${d.behind?` ↓${d.behind}`:""})`:""}`,onClick:()=>b.openFileExplorerForAreaFolder(s,c),children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:ze}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(p,{name:"git-branch",size:10})," ",d.branch]}),d.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${d.ahead} ahead`,children:[e.jsx(p,{name:"arrow-up",size:9}),d.ahead]}),d.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${d.behind} behind`,children:[e.jsx(p,{name:"arrow-down",size:9}),d.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${Se?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:Ke=>{Ke.stopPropagation(),le(c)},children:e.jsx(p,{name:Se?"hourglass":"download",size:12})})]})]},`${s}:${c}`)}),e.jsx(pa,{agentId:r,disabled:((f==null?void 0:f.provider)??"claude")!=="claude",contextSummary:et?`Context: ${ne}k / ${tt}k tokens (${me}% used)`:void 0,children:e.jsxs("span",{className:"flat-terminal-wrapper__context",tabIndex:0,role:"button",onClick:()=>b.setContextModalAgentId(r),onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),b.setContextModalAgentId(r))},title:((f==null?void 0:f.provider)??"claude")!=="claude"?et?`Context usage: ${ne}k / ${tt}k tokens (${me}% used). Click to view stats.`:"Click to fetch context stats":void 0,children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(p,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${te}%`,backgroundColor:V}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:V},children:[ne,"k/",tt,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",At,"% free)"]}),!et&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(p,{name:"warn",size:12})})]})}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),Ve.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:Ve.map(s=>{const l=ye===s.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${l?"flat-terminal-wrapper__building-btn--active":""} ${s.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${l?"Hide":"Show"} terminal: ${s.name}${s.hasUrl?"":" (starting...)"}`,onClick:()=>{if(l){Pe(null);return}s.hasUrl||b.sendBuildingCommand(s.id,"start"),Pe(s.id)},onContextMenu:c=>{c.preventDefault(),c.stopPropagation(),_e(s.id,{x:c.clientX,y:c.clientY})},children:e.jsx(p,{name:"terminal",size:14})},s.id)})}),Ie.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Ie.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"scroll",size:14})},s.id))}),je.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:je.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"hard-drives",size:14})},s.id))}),Te.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:Te.map(s=>e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${s.working?"flat-terminal-wrapper__building-btn--tests-working":""}`,title:s.working?`Running tests: ${s.name}`:`Open tests: ${s.name}`,onClick:()=>I(s.id),onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),_e(s.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"flask",size:14})},s.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(Jn,{})})]}),Ae&&e.jsx(Qn,{agentId:r,agents:Y,onClose:v,branchInfoMap:ie,fetchRemote:le,fetchingDirs:lt,onResizeStart:s=>jt(s,"right")}),ce&&e.jsx(ea,{agentId:r,onClose:de}),De&&e.jsx(ta,{agentId:r,onClose:kt})]})});function ya({onAgentClick:u,onBuildingClick:r,onBuildingDoubleClick:m,onBuildingPopup:h,onAreaContextMenu:N,onOpenSpawnModal:P,onOpenBossSpawnModal:M,onOpenAreaModal:L}){const{t:G}=Rt(["common"]),_=wn(),F=vn(),[I,W]=a.useState(null),[U,xe]=a.useState(null),[Z,be]=a.useState(null),[Ee,st]=a.useState(null),[ae,_e]=a.useState(null),[f,H]=a.useState(null),[we,Me]=a.useState(null),[We,ve]=a.useState(!1),wt=a.useCallback(()=>{ve(t=>!t)},[]),it=a.useCallback(()=>{ve(!1)},[]),[He,J]=a.useState(()=>{const t=Ft(S.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ue=a.useCallback(t=>{J(t),Wt(S.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=n=>{if(n.key!==S.VIEW_MODE)return;const i=n.newValue;(i==="simple"||i==="chat"||i==="advanced")&&J(i)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[Ce,se]=a.useState(()=>Dt(S.FLAT_INSPECTOR_OPEN,!1)),[ie,le]=a.useState(!1),lt=a.useCallback(()=>le(t=>!t),[]),Ve=a.useCallback(()=>le(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:ie}}))},[ie]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:Ce}}))},[Ce]),a.useEffect(()=>{const t=()=>le(C=>!C),n=()=>{se(C=>{const k=!C;return ge(S.FLAT_INSPECTOR_OPEN,k),k})},i=()=>{le(!1),se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)},g=()=>le(!1),x=()=>{se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",n),window.addEventListener("tide-close-flat-side-views",i),window.addEventListener("tide-close-flat-agents-drawer-only",g),window.addEventListener("tide-close-flat-inspector-only",x),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",n),window.removeEventListener("tide-close-flat-side-views",i),window.removeEventListener("tide-close-flat-agents-drawer-only",g),window.removeEventListener("tide-close-flat-inspector-only",x)}},[]);const Ie=a.useRef(null),je=a.useRef(null),[Ne,Te]=a.useState(()=>{const t=Ht(S.FLAT_MIDDLE_WIDTH,0);return t>=_t?t:null}),[Q,re]=a.useState(()=>{const t=Ht(S.FLAT_INSPECTOR_WIDTH,0);return t>=Lt?t:null}),ke=a.useCallback(t=>{if(typeof window>"u")return t;const n=Q!==null?bt+Q:0,i=window.innerWidth-Yt-bt-qt-n;return Math.max(_t,Math.min(Math.max(i,_t),t))},[Q]),oe=a.useCallback(t=>{var x;if(typeof window>"u")return t;const n=(x=Ie.current)==null?void 0:x.querySelector(".flat-middle"),i=(n==null?void 0:n.getBoundingClientRect().width)??_t,g=window.innerWidth-Yt-i-bt-qt-bt;return Math.max(Lt,Math.min(Math.max(g,Lt),t))},[]);a.useEffect(()=>{if(Ne===null&&Q===null)return;const t=()=>{Te(n=>{if(n===null)return n;const i=ke(n);return i===n?n:i}),re(n=>{if(n===null)return n;const i=oe(n);return i===n?n:i})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[Ne,Q,ke,oe]);const Je=a.useCallback(t=>{var i;if(t.button!==0)return;const n=(i=Ie.current)==null?void 0:i.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),je.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),ye=a.useCallback(t=>{var i;if(t.button!==0)return;const n=(i=Ie.current)==null?void 0:i.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),je.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Pe=a.useCallback(t=>{const n=je.current;if(!n||t.pointerId!==n.pointerId)return;const i=t.clientX-n.startX;n.kind==="middle"?Te(ke(n.startWidth+i)):re(oe(n.startWidth-i))},[ke,oe]),q=a.useCallback(t=>{const n=je.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(je.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const g=t.clientX-n.startX;if(n.kind==="middle"){const x=ke(n.startWidth+g);Te(x),xt(S.FLAT_MIDDLE_WIDTH,x)}else{const x=oe(n.startWidth-g);re(x),xt(S.FLAT_INSPECTOR_WIDTH,x)}},[ke,oe]),vt=a.useCallback(()=>{Te(null),xt(S.FLAT_MIDDLE_WIDTH,0)},[]),Ct=a.useCallback(()=>{re(null),xt(S.FLAT_INSPECTOR_WIDTH,0)},[]),[Le,jt]=a.useState(()=>Ft(S.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Ae=a.useCallback(t=>{jt(t),Wt(S.FLAT_INSPECTOR_VIEW,t)},[]),rt=a.useCallback(()=>{se(t=>{const n=!t;return ge(S.FLAT_INSPECTOR_OPEN,n),n})},[]),ce=a.useCallback(()=>{se(!1),ge(S.FLAT_INSPECTOR_OPEN,!1)},[]),ot=Cn(),De=a.useCallback((t,n)=>{W({url:t,name:n})},[]),ct=a.useCallback((t,n)=>{xe({command:t,output:n,isLive:!1})},[]),Nt=a.useCallback((t,n)=>{b.setFileViewerPath(t,n)},[]),kt=a.useCallback(t=>{be(t)},[]),yt=a.useCallback((t,n)=>{st({agentId:t,count:n})},[]),Xe=a.useCallback(t=>{m?m(t):r(t)},[r,m]),v=a.useMemo(()=>F.size>0?Array.from(F)[0]:null,[F]);a.useEffect(()=>{ve(!1)},[v]);const de=a.useRef([]),Y=a.useRef(-1),ee=a.useRef(!1),ue=a.useRef(null),[Qe,pe]=a.useState(!1),[et,dt]=a.useState(!1),Ge=a.useRef(!1),Re=a.useRef(null),te=a.useRef(!1),me=a.useMemo(()=>new Set(_.map(t=>t.id)),[_]),At=a.useMemo(()=>{const t=new Map(_.map(i=>[i.id,i])),n=new Map;for(const i of _)if((i.isBoss||i.class==="boss")&&i.subordinateIds&&i.subordinateIds.length>0){const g=i.subordinateIds.map(x=>t.get(x)).filter(x=>x!==void 0);g.length>0&&n.set(i.id,g)}return n},[_]),V=a.useCallback(()=>{const t=de.current,n=Y.current;pe(n>0),dt(n>=0&&n<t.length-1)},[]),ne=a.useCallback(t=>{const n=de.current;if(n.length===0)return;let i=Y.current+t;for(;i>=0&&i<n.length;){const g=n[i];if(me.has(g)){ee.current=!0,Y.current=i,V(),b.selectAgent(g);return}i+=t}},[me,V]),tt=a.useCallback(()=>ne(-1),[ne]),fe=a.useCallback(()=>ne(1),[ne]);la(a.useCallback(()=>{const t=de.current,n=Y.current;return t.length>0&&n>0?(ne(-1),"handled"):"exit"},[ne]));const qe=a.useCallback((t,n)=>{if(typeof window>"u")return;const i=window.history.state,x={...typeof i=="object"&&i!==null?i:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(x,"",window.location.href):window.history.pushState(x,"",window.location.href)},[]);a.useEffect(()=>{if(!v){Ge.current=!1,Re.current=null;return}if(!Ge.current){qe(v,"replace"),Ge.current=!0,Re.current=v;return}if(te.current){te.current=!1,Re.current=v;return}Re.current!==v&&(qe(v,"push"),Re.current=v)},[v,qe]),a.useEffect(()=>{const t=n=>{var C,k;const i=(k=(C=n.state)==null?void 0:C.__flatAgentNav)==null?void 0:k.agentId;if(!i||typeof i!="string"||!me.has(i)||i===v)return;te.current=!0,ee.current=!0;const g=de.current,x=g.lastIndexOf(i);x>=0?Y.current=x:(g.push(i),Y.current=g.length-1),V(),b.selectAgent(i)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[me,v,V]),a.useEffect(()=>{if(!v){de.current=[],Y.current=-1,V();return}if(ue.current=v,ee.current){ee.current=!1,V();return}const t=de.current,n=Y.current;if(n>=0&&t[n]===v){V();return}const i=n<t.length-1?t.slice(0,n+1):t.slice();i.push(v),i.length>100&&i.shift(),de.current=i,Y.current=i.length-1,V()},[v,V]);const $e=a.useCallback(t=>{u(t),le(!1)},[u]),St=v??"",ut=a.useCallback(()=>{},[]),pt=a.useCallback(t=>{$e(t)},[$e]),K=Ce,[Ye,s]=a.useState(K),[l,c]=a.useState(K);a.useEffect(()=>{if(K){s(!0);return}c(!1);const t=setTimeout(()=>s(!1),240);return()=>clearTimeout(t)},[K]),a.useEffect(()=>{if(!Ye||!K)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>c(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[Ye,K]);const d=a.useRef(null);a.useEffect(()=>{if(v)return;const t=n=>{if(n.key!==" "&&n.key!=="Backspace")return;const i=n.target;if(i.tagName==="INPUT"||i.tagName==="TEXTAREA"||i.isContentEditable)return;const g=ue.current;!g||!me.has(g)||(n.preventDefault(),b.selectAgent(g))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[v,me]);const[Se,ze]=a.useState(new Set),Ke=a.useCallback(t=>{ze(n=>{const i=new Set(n);return i.has(t)?i.delete(t):i.add(t),i})},[]),[he,Et]=a.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),n=i=>Et(i.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const[Oe,X]=a.useState(null),R=a.useCallback(t=>{X(n=>n===t?null:t)},[]),Ze=en(),mt=tn(),[sn]=jn(),Be=a.useMemo(()=>{const t=new Map,n=[];for(const w of _){const A=b.getAreaForAgent(w.id);if(!Ut((A==null?void 0:A.id)??null))continue;if(!A||A.archived){n.push(w);continue}const E=t.get(A.id);E?E.push(w):t.set(A.id,[w])}const i=new Map,g=[];for(const w of mt.values()){let A=!1;for(const E of Ze.values())if(!E.archived&&Vt(E.id)&&b.isPositionInArea(w.position,E)){const z=i.get(E.id);z?z.push(w):i.set(E.id,[w]),A=!0;break}!A&&Ut(null)&&g.push(w)}const x=[];for(const[,w]of Ze){if(w.archived||!Vt(w.id))continue;const A=t.get(w.id),E=i.get(w.id)??[];(A&&A.length>0||E.length>0)&&x.push({area:w,agents:A??[],buildings:E})}(n.length>0||g.length>0)&&x.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:n,buildings:g});const C=x.filter(w=>w.area.id!=="__unassigned__"),k=x.filter(w=>w.area.id==="__unassigned__");let o=1,y=1;const $=new Map;if(C.length>1){let w=1/0,A=-1/0,E=1/0,z=-1/0;for(const O of C)w=Math.min(w,O.area.center.x),A=Math.max(A,O.area.center.x),E=Math.min(E,O.area.center.z),z=Math.max(z,O.area.center.z);const ft=A-w||1,ht=z-E||1;if(C.length<=4){o=C.length,y=1;const O=[...C].sort((B,Mt)=>B.area.center.x-Mt.area.center.x);for(let B=0;B<O.length;B++)$.set(O[B].area.id,{row:1,col:B+1})}else{const O=[...C].sort((j,D)=>j.area.center.x-D.area.center.x),B=[];for(let j=1;j<O.length;j++)B.push(O[j].area.center.x-O[j-1].area.center.x);const Mt=B.reduce((j,D)=>j+D,0)/B.length||1;let $t=1;for(const j of B)j>Mt*1.3&&$t++;o=Math.max(2,Math.min($t,C.length));const It=[...C].sort((j,D)=>j.area.center.z-D.area.center.z),gt=[];for(let j=1;j<It.length;j++)gt.push(It[j].area.center.z-It[j-1].area.center.z);const cn=gt.reduce((j,D)=>j+D,0)/gt.length||1;let zt=1;for(const j of gt)j>cn*1.3&&zt++;y=Math.max(2,Math.min(zt,C.length)),o=Math.max(o,Math.ceil(C.length/y)),y=Math.max(y,Math.ceil(C.length/o));const dn=ft/o,un=ht/y,Tt=new Set;for(const j of C){let D=Math.min(o-1,Math.max(0,Math.floor((j.area.center.x-w)/dn))),Fe=Math.min(y-1,Math.max(0,Math.floor((j.area.center.z-E)/un))),nt=`${Fe},${D}`,Ot=0;const pn=y*o;for(;Tt.has(nt)&&Ot<pn;)D++,D>=o&&(D=0,Fe=(Fe+1)%y),nt=`${Fe},${D}`,Ot++;Tt.has(nt)&&(Fe=y,D=0,nt=`${Fe},${D}`,y++),Tt.add(nt),$.set(j.area.id,{row:Fe+1,col:D+1})}}}const T=w=>{w.sort((A,E)=>{var ft,ht,O,B;const z=(((ft=A.position)==null?void 0:ft.z)??0)-(((ht=E.position)==null?void 0:ht.z)??0);return z!==0?z:(((O=A.position)==null?void 0:O.x)??0)-(((B=E.position)==null?void 0:B.x)??0)})};for(const w of C)T(w.agents);for(const w of k)T(w.agents);return{groups:[...C,...k],gridCols:o,gridRows:y,positions:$}},[_,Ze,mt,sn]),ln=a.useMemo(()=>{if(!ae)return[];const t=_.find(n=>n.id===ae.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(p,{name:"chat",size:14}),onClick:()=>u(t.id)},{id:"clone-agent",label:"Clone Agent",icon:e.jsx(p,{name:"clipboard",size:14}),onClick:()=>b.cloneAgent(t.id)},{id:"fork-agent",label:"Fork Agent (with history)",icon:e.jsx(p,{name:"git-branch",size:14}),onClick:()=>b.forkAgent(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>{Me({agentId:t.id,name:t.name})}}]:[]},[ae,_,u]),rn=a.useMemo(()=>{var C;if(!f)return[];const t=mt.get(f.buildingId);if(!t)return[];const n=[],i=t.type==="server"||t.type==="docker"||t.type==="terminal",g=t.status==="running",x=t.type==="boss";if(n.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="tests"?"Open Tests":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((C=t.pm2)!=null&&C.enabled)?"View PM2 Logs":"Open",icon:e.jsx(p,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="tests"?"flask":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>Xe(t.id)}),i&&(g||n.push({id:"start",label:"Start",icon:e.jsx(p,{name:"play",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"start")}),g&&(n.push({id:"restart",label:"Restart",icon:e.jsx(p,{name:"refresh",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(p,{name:"stop",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"stop")}))),x&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(n.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(p,{name:"launch",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"start")}}),n.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(p,{name:"pause",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"stop")}}),n.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(p,{name:"restart",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)b.sendBuildingCommand(k,"restart")}})),i&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(p,{name:"health",size:14}),onClick:()=>b.sendBuildingCommand(t.id,"healthCheck")}),n.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),n.push({id:"edit",label:"Edit Building",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),n.push({id:"clone",label:"Clone Building",icon:e.jsx(p,{name:"copy",size:14}),onClick:()=>{b.createBuilding({name:`${t.name} (Copy)`,type:t.type,style:t.style,color:t.color,scale:t.scale,position:{x:t.position.x+2,z:t.position.z+2},cwd:t.cwd,folderPath:t.folderPath,commands:t.commands,pm2:t.pm2,docker:t.docker,database:t.database,terminal:t.terminal,urls:t.urls,subordinateBuildingIds:t.subordinateBuildingIds})}}),t.urls&&t.urls.length>0)for(const k of t.urls)n.push({id:`url-${k.label}`,label:k.label,icon:e.jsx(p,{name:"link",size:14}),onClick:()=>window.open(k.url,"_blank","noopener,noreferrer")});return n.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),n.push({id:"delete",label:"Delete Building",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>b.deleteBuilding(t.id)}),n},[f,mt,Xe]),on=a.useCallback(t=>{const n=new Set(Be.groups.map(i=>i.area.id));n.delete(t),ze(n),requestAnimationFrame(()=>{const i=d.current;if(!i)return;const g=i.querySelector(`[data-area-id="${t}"]`);if(!g)return;const x=i.getBoundingClientRect(),k=g.getBoundingClientRect().top-x.top+i.scrollTop-8;i.scrollTo({top:Math.max(0,k),behavior:"smooth"})})},[Be]);return e.jsxs("div",{ref:Ie,className:`flat-view ${K?"flat-view--with-inspector":""} ${v?"flat-view--has-chat":""} ${ie?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(Ne===null&&Q===null)return;const t={};return Ne!==null&&(t["--flat-middle-width"]=`${Ne}px`),Q!==null&&(t["--flat-inspector-width"]=`${Q}px`),t})(),children:[ie&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Ve,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children:e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:P,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:M,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:L,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(Nn,{activeAgentId:St,onClose:ut,onSelectAgent:pt,collapsedAreas:Se,onToggleArea:Ke,agentListRef:d})})]}),e.jsx("div",{className:"flat-splitter flat-splitter--middle",role:"separator","aria-orientation":"vertical","aria-label":"Resize agents panel",title:"Drag to resize · Double-click to reset",onPointerDown:Je,onPointerMove:Pe,onPointerUp:q,onPointerCancel:q,onDoubleClick:vt}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":ie?"Close agents sidebar":"Open agents sidebar","aria-expanded":ie,onClick:lt,children:[e.jsx(p,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),v?e.jsx(va,{agentId:v,terminalViewMode:He,onTerminalViewModeChange:Ue,inspectorOpen:Ce,onToggleInspector:rt,onImageClick:De,onFileClick:Nt,onBashClick:ct,onViewMarkdown:kt,onRequestClearSubordinates:yt,onOpenBuilding:Xe,keyboard:ot,canNavigateBack:Qe,canNavigateForward:et,onNavigateBack:tt,onNavigateForward:fe,agentInfoOpen:We,onToggleAgentInfo:wt,onHeaderContextMenu:t=>{v&&_e({agentId:v,position:t})},onBuildingContextMenu:(t,n)=>{H({buildingId:t,position:n})}}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"}),e.jsx(ma,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Be.gridCols}, 1fr)`},children:Be.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var n;const t=he&&Oe?((n=Be.positions.get(Oe))==null?void 0:n.row)??null:null;return Be.groups.map(i=>{var k;const g=i.area.id,x=Be.positions.get(g),C=he&&Oe!==g;return he&&t!=null&&(x==null?void 0:x.row)===t&&g!==Oe?null:e.jsxs("div",{className:`flat-map-area-card${C?" flat-map-area-card--collapsed":""}`,style:{"--area-color":i.area.color,gridRow:x==null?void 0:x.row,gridColumn:x==null?void 0:x.col},onContextMenu:o=>{N&&(o.preventDefault(),o.stopPropagation(),N(g,{x:o.clientX,y:o.clientY}))},children:[((k=i.area.logo)==null?void 0:k.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:ia(i.area.logo.filename),alt:"","aria-hidden":"true",onError:o=>{o.currentTarget.style.display="none"}}),e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>he?R(g):on(g),title:he?C?`Expand ${i.area.name}`:`Collapse ${i.area.name}`:`Focus ${i.area.name} in left panel`,"aria-expanded":he?!C:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:i.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:i.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:i.agents.length}),he&&e.jsx(p,{name:C?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:i.agents.map(o=>{const y=o.isBoss||o.class==="boss",$=y?At.get(o.id):void 0,T=kn(o),w=T.usedPercent>=80?"#ff4a4a":T.usedPercent>=60?"#ff9e4a":T.usedPercent>=40?"#ffd700":"#4aff9e",A=`Context: ${(T.totalTokens/1e3).toFixed(1)}k / ${(T.contextWindow/1e3).toFixed(1)}k (${T.usedPercent}% used, ${T.freePercent}% free)`,E=o.latestTodos&&o.latestTodos.length>0||$&&$.length>0;return e.jsx(yn,{todos:o.latestTodos,subordinates:$,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${o.status}`,onClick:()=>u(o.id),onContextMenu:z=>{z.preventDefault(),z.stopPropagation(),_e({agentId:o.id,position:{x:z.clientX,y:z.clientY}})},title:E?void 0:`${y?"Boss · ":""}Open chat with ${o.name}
|
|
2
2
|
${A}`,children:[e.jsx(nn,{agent:o,size:16}),y&&e.jsx("span",{className:"flat-map-agent-chip__crown","aria-hidden":"true",children:e.jsx(p,{name:"crown",size:11,color:"#ffd700",weight:"fill"})}),e.jsx("span",{className:"flat-map-agent-chip__name",children:o.name}),e.jsx("img",{src:o.provider==="codex"?"/assets/codex.png":o.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:o.provider,className:"flat-map-agent-chip__provider-icon",title:o.provider==="codex"?"Codex Agent":o.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:an(o.status)}}),o.latestTodos&&o.latestTodos.length>0&&e.jsx(An,{todos:o.latestTodos,maxDots:6}),y&&$&&$.length>0&&e.jsx(Sn,{subordinates:$,maxDots:6}),e.jsx("span",{className:"flat-map-agent-chip__context-bar","aria-hidden":"true",children:e.jsx("span",{className:"flat-map-agent-chip__context-bar-fill",style:{width:`${T.usedPercent}%`,backgroundColor:w}})})]})},o.id)})}),i.area.directories.length>0&&e.jsx("div",{className:"flat-map-area-card__folders",role:"group","aria-label":`${i.area.name} folders`,children:i.area.directories.map(o=>{const y=o.split("/").filter(Boolean).pop()||o;return e.jsxs("button",{type:"button",className:"flat-map-folder-chip",onClick:$=>{$.stopPropagation(),b.openFileExplorerForAreaFolder(g,o)},title:`Open in file explorer: ${o}`,children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-map-folder-chip__name",children:y})]},o)})}),i.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:i.buildings.map(o=>{var $;const y=($=En[o.type])==null?void 0:$.color;return e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${o.status}`,style:y?{"--building-type-color":y}:void 0,onClick:T=>{if(h){const w=T.currentTarget.getBoundingClientRect();h(o.id,{x:w.right,y:w.top+w.height/2})}else Xe(o.id)},onContextMenu:T=>{T.preventDefault(),T.stopPropagation(),H({buildingId:o.id,position:{x:T.clientX,y:T.clientY}})},title:`${o.name} · ${o.type} · ${o.status}`,children:[e.jsx(p,{name:Mn(o.type),size:12,color:y}),e.jsx("span",{className:"flat-map-building-chip__name",children:o.name}),e.jsx("span",{className:"flat-map-building-chip__dot",style:{backgroundColor:In(o.status)}})]},o.id)})})]},g)})})()})]})})]}),K&&e.jsx("div",{className:"flat-splitter flat-splitter--inspector",role:"separator","aria-orientation":"vertical","aria-label":"Resize inspector panel",title:"Drag to resize · Double-click to reset",onPointerDown:ye,onPointerMove:Pe,onPointerUp:q,onPointerCancel:q,onDoubleClick:Ct}),Ye&&e.jsxs("aside",{className:`flat-inspector ${l?"flat-inspector--open":"flat-inspector--closing"}`,"aria-label":"Inspector panel",children:[e.jsxs("div",{className:"flat-inspector__header",children:[e.jsxs("div",{className:"flat-inspector__tabs",role:"tablist","aria-label":"Inspector view",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":Le==="agent",className:`flat-inspector__tab ${Le==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>Ae("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":Le==="tracking",className:`flat-inspector__tab ${Le==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>Ae("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:ce,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:Le==="tracking"?e.jsx(Tn,{activeAgentId:v??"",onSelectAgent:t=>{u(t),window.innerWidth<=768&&ce()}}):(()=>{if(!v)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=_.find(n=>n.id===v);return t?e.jsx(Pn,{agent:t,onFocusAgent:n=>{u(n),window.innerWidth<=768&&ce()},onKillAgent:n=>b.killAgent(n)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),I&&e.jsx(Ln,{url:I.url,name:I.name,onClose:()=>W(null)}),U&&e.jsx(Dn,{state:U,onClose:()=>xe(null)}),e.jsx(Rn,{agent:v?_.find(t=>t.id===v)??null:null,content:Z,onClose:()=>be(null)}),Ee&&e.jsx($n,{action:"clear-subordinates",selectedAgentId:Ee.agentId,subordinateCount:Ee.count,onClose:()=>st(null),onClearHistory:()=>{}}),e.jsx(zn,{agent:v?_.find(t=>t.id===v)??null:null,isOpen:We&&!!v,onClose:it}),e.jsx(Xt,{isOpen:ae!==null,position:(ae==null?void 0:ae.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:ln,onClose:()=>_e(null)}),e.jsx(Xt,{isOpen:f!==null,position:(f==null?void 0:f.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:rn,onClose:()=>H(null)}),e.jsx(On,{isOpen:we!==null,title:G("common:confirm.removeAgentTitle"),message:G("common:confirm.removeAgentMessage",{name:(we==null?void 0:we.name)??""}),confirmLabel:G("common:buttons.remove"),cancelLabel:G("common:buttons.cancel"),variant:"danger",onConfirm:()=>{we&&b.removeAgentFromServer(we.agentId)},onClose:()=>Me(null)})]})}export{ya as FlatView};
|