tide-commander 1.147.1 → 1.149.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +6 -3
- package/dist/assets/BossLogsModal-Cs4kWugD.js +1 -0
- package/dist/assets/BossSpawnModal-BudMgJqj.js +1 -0
- package/dist/assets/ControlsModal-Bh6_3qtH.js +1 -0
- package/dist/assets/DockerLogsModal-Nf4wQFfz.js +2 -0
- package/dist/assets/{EmbeddedEditor-DfM3SrO7.js → EmbeddedEditor-BfRXRX50.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-DBWs7uzU.js → GmailOAuthSetup-CXUtjA0r.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-yQjT5QzU.js → GoogleOAuthSetup-D-_rwicD.js} +1 -1
- package/dist/assets/{IframeModal-DUTIyP5I.js → IframeModal-CdaXsQK0.js} +1 -1
- package/dist/assets/{IntegrationsPanel-DPURuiaz.js → IntegrationsPanel-ZsSVxcWr.js} +2 -2
- package/dist/assets/{LogViewerModal-CDZvTdfO.js → LogViewerModal-BAf-klB2.js} +1 -1
- package/dist/assets/{MonitoringModal-Dq2EJgbH.js → MonitoringModal-BjRbh5z4.js} +1 -1
- package/dist/assets/{PM2LogsModal-C3dlYlGv.js → PM2LogsModal-SaywDZVL.js} +2 -2
- package/dist/assets/{RestoreArchivedAreaModal-BMFk0G8D.js → RestoreArchivedAreaModal-jru2Ez9a.js} +1 -1
- package/dist/assets/Scene2DCanvas-NJHoe2Qg.js +1 -0
- package/dist/assets/SceneManager-i9wVMa_V.js +104 -0
- package/dist/assets/{SkillsPanel-D326VBDa.js → SkillsPanel-BHfKLzWe.js} +3 -3
- package/dist/assets/{SlackMultiInstanceSetup-CA4nm925.js → SlackMultiInstanceSetup-BfVevCSo.js} +1 -1
- package/dist/assets/SpawnModal-29x5z53B.js +1 -0
- package/dist/assets/{StatisticsModal-BUpvkJXA.js → StatisticsModal-MbIByjWD.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-DtVsKDqV.js → SubordinateAssignmentModal-DF0vYaM6.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-OD14xVMw.js → TriggerManagerPanel-EGcKS1Pt.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-B4UF3rcS.js → WorkflowEditorPanel-BLmejfqe.js} +1 -1
- package/dist/assets/{area-logos-Uc9SAeYg.js → area-logos-C4fgpLgO.js} +1 -1
- package/dist/assets/grok.ico +0 -0
- package/dist/assets/grok.png +0 -0
- package/dist/assets/{index-xBtKu0I8.js → index-B-2H7O_Y.js} +2 -2
- package/dist/assets/{index-CuHJm43U.js → index-B9xpLAcH.js} +1 -1
- package/dist/assets/index-BZ4wZwRu.js +19 -0
- package/dist/assets/index-BiiLWTXJ.js +1 -0
- package/dist/assets/{index-BC3Y_BAQ.js → index-C6Kf4ewu.js} +5 -5
- package/dist/assets/index-C8CGfmXP.js +1 -0
- package/dist/assets/index-DThK5_yS.js +5 -0
- package/dist/assets/index-DYgVP0G3.js +2 -0
- package/dist/assets/index-DhD3m2Qx.js +1 -0
- package/dist/assets/main-B0UlZnfk.js +260 -0
- package/dist/assets/main-DeiAIdzy.css +1 -0
- package/dist/assets/{web-DlzqHyn8.js → web-CXC8P25z.js} +1 -1
- package/dist/assets/{web-B-xc0c6e.js → web-LGEDa25c.js} +1 -1
- package/dist/assets/{web-BuDeKWBN.js → web-NM4dUqWg.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/locales/de/tools.json +3 -1
- package/dist/locales/en/tools.json +7 -3
- package/dist/locales/es/tools.json +3 -1
- package/dist/locales/fr/tools.json +4 -2
- package/dist/locales/hi/tools.json +4 -2
- package/dist/locales/it/tools.json +19 -17
- package/dist/locales/ja/tools.json +4 -2
- package/dist/locales/pt/tools.json +3 -1
- package/dist/locales/ru/tools.json +3 -1
- package/dist/locales/zh-CN/tools.json +3 -1
- package/dist/src/packages/server/claude/runner/process-lifecycle.js +53 -0
- package/dist/src/packages/server/claude/runner/stdout-pipeline.js +125 -4
- package/dist/src/packages/server/claude/runner/watchdog.js +12 -0
- package/dist/src/packages/server/claude/session-loader.js +280 -0
- package/dist/src/packages/server/data/index.js +1 -0
- package/dist/src/packages/server/grok/backend.js +231 -0
- package/dist/src/packages/server/grok/index.js +4 -0
- package/dist/src/packages/server/grok/json-event-parser.js +138 -0
- package/dist/src/packages/server/grok/session-watcher.js +460 -0
- package/dist/src/packages/server/routes/agents.js +7 -2
- package/dist/src/packages/server/runtime/grok-runtime-provider.js +11 -0
- package/dist/src/packages/server/runtime/index.js +1 -0
- package/dist/src/packages/server/services/agent-service.js +26 -5
- package/dist/src/packages/server/services/runtime-command-execution.js +4 -2
- package/dist/src/packages/server/services/runtime-events.js +46 -7
- package/dist/src/packages/server/services/runtime-service.js +19 -3
- package/dist/src/packages/server/utils/tool-formatting.js +40 -12
- package/dist/src/packages/server/websocket/handlers/agent-handler.js +70 -17
- package/dist/src/packages/server/websocket/listeners/runtime-listeners.js +63 -7
- package/dist/src/packages/shared/agent-types.js +10 -0
- package/package.json +1 -1
- package/dist/assets/BossLogsModal-Cn8IVdqn.js +0 -1
- package/dist/assets/BossSpawnModal-Don-RZyh.js +0 -1
- package/dist/assets/ControlsModal-C9--xWPi.js +0 -1
- package/dist/assets/DockerLogsModal-DSGnpfm5.js +0 -2
- package/dist/assets/Scene2DCanvas-DlumJCbl.js +0 -1
- package/dist/assets/SceneManager-UnhMFja8.js +0 -104
- package/dist/assets/SpawnModal-B1QOjZPe.js +0 -1
- package/dist/assets/index-BD6swoQU.js +0 -19
- package/dist/assets/index-C4mf6B5U.js +0 -1
- package/dist/assets/index-COHImd74.js +0 -1
- package/dist/assets/index-CScFEdm8.js +0 -1
- package/dist/assets/index-CmmpVZ8w.js +0 -2
- package/dist/assets/index-DkDzXtdj.js +0 -5
- package/dist/assets/main-Bp6V_-sL.js +0 -256
- package/dist/assets/main-ijcbyjBn.css +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{bM as ta,u as A,j as e,bb as j,bS as Ms,bT as Fs,bc as X,s as D,bU as $s,r as m,D as Q,I as F,ag as Us,bm as qe,m as na,bn as la,l as ia,bV as oa,_ as ra,S as ca,n as da,af as Ks,bo as Ue}from"./main-B0UlZnfk.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const ma=[{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 ua(o){return ta.t(o)}function Ve(o){if(o===0)return"0 B";const p=1024,u=["B","KB","MB","GB"],x=Math.floor(Math.log(o)/Math.log(p));return parseFloat((o/Math.pow(p,x)).toFixed(1))+" "+u[x]}function pa(o){const u=Date.now()-o,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(o){const p=[],u=/\x1B\[([0-9;]*)m/g;let x=0,n=null,y;for(;(y=u.exec(o))!==null;){if(y.index>x){const g=o.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<o.length){const C=o.slice(x);n?p.push(e.jsx("span",{style:{color:n},children:C},p.length)):p.push(C)}return p.length>0?p:[o]}function ha({buildingName:o,onClose:p,onConfirm:u}){const{t:x}=A(["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:o})}),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 xa({usePM2:o,setUsePM2:p}){const{t:u}=A(["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:o,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 ba({usePM2:o,pm2Script:p,setPm2Script:u,pm2Args:x,setPm2Args:n,pm2Interpreter:y,setPm2Interpreter:C,pm2InterpreterArgs:g,setPm2InterpreterArgs:v,pm2Env:s,setPm2Env:h,isEditMode:a,building:t,handleCommand:c}){var f;const{t:i}=A(["terminal","common"]);return o?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:o})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Arguments"),e.jsx(j,{text:i("terminal:building.helpPm2Arguments"),title:i("terminal:building.pm2Arguments"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:x,onChange:b=>n(b.target.value),placeholder:"run dev, -jar app.jar, app.py"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Interpreter"),e.jsx(j,{text:i("terminal:building.helpPm2Interpreter"),title:i("terminal:building.pm2Interpreter"),position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:y,onChange:b=>C(b.target.value),children:Object.keys(Ms).map(b=>e.jsx("option",{value:b,children:Ms[b].label},b))})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2InterpArgs"),e.jsx(j,{text:i("terminal:building.helpPm2InterpArgs"),title:i("terminal:building.pm2InterpArgs"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:g,onChange:b=>v(b.target.value),placeholder:"-jar (for Java)"})]}),e.jsxs("div",{className:"command-row env-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Environment"),e.jsx(j,{text:i("terminal:building.helpPm2Environment"),title:i("terminal:building.pm2Environment"),position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input form-textarea",value:s,onChange:b=>h(b.target.value),placeholder:`KEY=value
|
|
2
2
|
SERVER_PORT=7201
|
|
3
|
-
NODE_ENV=production`,rows:3})]}),e.jsx("div",{className:"pm2-examples",children:e.jsxs("details",{children:[e.jsx("summary",{children:i("terminal:building.pm2Examples")}),e.jsxs("div",{className:"pm2-examples-content",children:[e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Node.js:"})," Script: ",e.jsx("code",{children:"npm"}),", Args: ",e.jsx("code",{children:"run dev"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Symfony:"})," Script: ",e.jsx("code",{children:"symfony"}),", Args: ",e.jsx("code",{children:"serve --no-daemon"}),", Interpreter: ",e.jsx("code",{children:"None"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Java JAR:"})," Script: ",e.jsx("code",{children:"app.jar"}),", Interpreter: ",e.jsx("code",{children:"Java"}),", Interp. Args: ",e.jsx("code",{children:"-jar"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Python:"})," Script: ",e.jsx("code",{children:"app.py"}),", Interpreter: ",e.jsx("code",{children:"Python 3"})]})]})]})}),a&&(t==null?void 0:t.pm2Status)&&e.jsx("div",{className:"pm2-status-display",children:e.jsxs("div",{className:"pm2-status-row",children:[e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"PID"}),e.jsx("span",{className:"pm2-metric-value",children:t.pm2Status.pid||"-"})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"CPU"}),e.jsxs("span",{className:"pm2-metric-value",children:[((f=t.pm2Status.cpu)==null?void 0:f.toFixed(1))||"0","%"]})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"MEM"}),e.jsx("span",{className:"pm2-metric-value",children:Ve(t.pm2Status.memory||0)})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"Restarts"}),e.jsx("span",{className:"pm2-metric-value",children:t.pm2Status.restarts||0})]}),t.pm2Status.uptime&&e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"Uptime"}),e.jsx("span",{className:"pm2-metric-value",children:ma(t.pm2Status.uptime)})]})]})}),a&&e.jsxs("div",{className:"pm2-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>c("start"),children:i("common:buttons.start")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>c("stop"),children:i("common:buttons.stop")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>c("restart"),children:i("terminal:buildingAction.restart")}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>c("logs"),children:i("terminal:logs.title")})]})]}):null}function xa({dockerMode:r,setDockerMode:p,dockerImage:u,setDockerImage:x,dockerContainerName:n,setDockerContainerName:y,dockerCommand:C,setDockerCommand:g,dockerPorts:v,setDockerPorts:s,dockerVolumes:h,setDockerVolumes:a,dockerNetwork:t,setDockerNetwork:c,dockerRestart:i,setDockerRestart:f,dockerPull:b,setDockerPull:L,dockerEnv:T,setDockerEnv:A,dockerComposePath:K,setDockerComposePath:I,dockerComposeProject:$,setDockerComposeProject:R,dockerComposeServices:H,setDockerComposeServices:O,selectedExistingContainer:d,setSelectedExistingContainer:z,dockerContainersList:q,isEditMode:V,building:k,handleCommand:_}){const{t:M}=B(["config","common"]);return e.jsxs("div",{className:"form-section docker-config-section",children:[e.jsx("label",{className:"form-label",children:M("config:buildings.dockerConfig")}),e.jsxs("div",{className:"docker-mode-selector",children:[e.jsxs("label",{className:`docker-mode-option ${r==="container"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"container",checked:r==="container",onChange:()=>p("container")}),e.jsx("span",{className:"docker-mode-icon",children:"📦"}),e.jsx("span",{className:"docker-mode-label",children:"Container"}),e.jsx("span",{className:"docker-mode-desc",children:"Create a new container"})]}),e.jsxs("label",{className:`docker-mode-option ${r==="compose"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"compose",checked:r==="compose",onChange:()=>p("compose")}),e.jsx("span",{className:"docker-mode-icon",children:"🛠"}),e.jsx("span",{className:"docker-mode-label",children:"Compose"}),e.jsx("span",{className:"docker-mode-desc",children:"Manage multiple services"})]}),e.jsxs("label",{className:`docker-mode-option ${r==="existing"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"existing",checked:r==="existing",onChange:()=>p("existing")}),e.jsx("span",{className:"docker-mode-icon",children:"🔎"}),e.jsx("span",{className:"docker-mode-label",children:"Existing"}),e.jsx("span",{className:"docker-mode-desc",children:"Adopt existing container"})]})]}),r==="container"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Image:",e.jsx(j,{text:"Docker image to run, e.g., nginx:latest, redis:alpine, my-app:v1",title:"Image",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:u,onChange:l=>x(l.target.value),placeholder:"nginx:latest",required:!0})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Container Name:",e.jsx(j,{text:"Custom name for the container. If empty, auto-generated based on building name.",title:"Container Name",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:n,onChange:l=>y(l.target.value),placeholder:"Auto-generated (tc-{name}-{id})"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Command:",e.jsx(j,{text:"Override the default container command. Leave empty to use image's CMD.",title:"Command Override",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:l=>g(l.target.value),placeholder:"Optional command override"})]}),e.jsxs("div",{className:"form-section docker-ports-section",children:[e.jsxs("label",{className:"form-label",children:["Port Mappings",e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>s([...v,""]),children:"+ Add"})]}),v.map((l,S)=>e.jsxs("div",{className:"docker-mapping-row",children:[e.jsx("input",{type:"text",className:"form-input",value:l,onChange:U=>{const E=[...v];E[S]=U.target.value,s(E)},placeholder:"8080:80 or 3000"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>s(v.filter((U,E)=>E!==S)),children:"x"})]},S)),v.length===0&&e.jsx("div",{className:"form-hint",children:"Format: host:container (e.g., 8080:80) or same port (e.g., 3000)"})]}),e.jsxs("div",{className:"form-section docker-volumes-section",children:[e.jsxs("label",{className:"form-label",children:["Volume Mounts",e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>a([...h,""]),children:"+ Add"})]}),h.map((l,S)=>e.jsxs("div",{className:"docker-mapping-row",children:[e.jsx("input",{type:"text",className:"form-input",value:l,onChange:U=>{const E=[...h];E[S]=U.target.value,a(E)},placeholder:"./data:/app/data or /host/path:/container/path"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>a(h.filter((U,E)=>E!==S)),children:"x"})]},S)),h.length===0&&e.jsx("div",{className:"form-hint",children:"Format: host_path:container_path (relative paths resolved from working directory)"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Network:",e.jsx(j,{text:"Docker network to connect to. Leave empty for default bridge network.",title:"Network",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:t,onChange:l=>c(l.target.value),placeholder:"bridge (default)"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Restart Policy:",e.jsx(j,{text:"When should Docker restart the container automatically?",title:"Restart Policy",position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:i,onChange:l=>f(l.target.value),children:Object.keys(Fs).map(l=>e.jsx("option",{value:l,children:Fs[l].label},l))})]})]}),r==="compose"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Compose File:",e.jsx(j,{text:"Path to docker-compose.yml file, relative to working directory.",title:"Compose File",position:"top",size:"sm"})]}),e.jsx(Q,{value:K,onChange:I,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:$,onChange:l=>R(l.target.value),placeholder:"Auto-generated"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Services:",e.jsx(j,{text:"Specific services to manage (comma-separated). Leave empty for all services.",title:"Services",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:H,onChange:l=>O(l.target.value),placeholder:"All services (or: api, db, redis)"})]})]}),r==="existing"&&e.jsxs("div",{className:"docker-existing-section",children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Select Container:",e.jsx(j,{text:"Choose an existing Docker container to monitor and control. The container will not be deleted when removing the building.",title:"Existing Container",position:"top",size:"sm"})]}),e.jsxs("div",{className:"docker-existing-select-wrapper",children:[e.jsxs("select",{className:"form-input form-select",value:d,onChange:l=>z(l.target.value),required:r==="existing",children:[e.jsx("option",{value:"",children:"Select a container..."}),q.map(l=>e.jsxs("option",{value:l.name,children:[l.name," (",l.image,") - ",l.state]},l.id))]}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.requestDockerContainersList(),title:"Refresh container list",children:"↻"})]})]}),q.length===0&&e.jsx("div",{className:"form-hint docker-existing-hint",children:"No containers found. Make sure Docker is running and you have containers available."}),d&&e.jsx("div",{className:"docker-existing-info",children:(()=>{const l=q.find(S=>S.name===d);return l?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Image:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.image})]}),e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Status:"}),e.jsx("span",{className:`docker-existing-info-value docker-status-${l.status}`,children:l.state})]}),e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"ID:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.id.slice(0,12)})]}),l.ports.length>0&&e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Ports:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.ports.map(S=>`${S.host}:${S.container}/${S.protocol}`).join(", ")})]})]}):null})()}),e.jsx("div",{className:"form-hint",children:"Note: Existing containers will not be deleted when you remove this building."})]}),r!=="existing"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Pull Policy:",e.jsx(j,{text:"When to pull images: always, only if missing, or never.",title:"Pull Policy",position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:b,onChange:l=>L(l.target.value),children:Object.keys(Ks).map(l=>e.jsx("option",{value:l,children:Ks[l].label},l))})]}),e.jsxs("div",{className:"command-row env-row",children:[e.jsxs("span",{className:"command-label",children:["Environment:",e.jsx(j,{text:"Environment variables in KEY=value format, one per line.",title:"Environment Variables",position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input form-textarea",value:T,onChange:l=>A(l.target.value),placeholder:`KEY=value
|
|
3
|
+
NODE_ENV=production`,rows:3})]}),e.jsx("div",{className:"pm2-examples",children:e.jsxs("details",{children:[e.jsx("summary",{children:i("terminal:building.pm2Examples")}),e.jsxs("div",{className:"pm2-examples-content",children:[e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Node.js:"})," Script: ",e.jsx("code",{children:"npm"}),", Args: ",e.jsx("code",{children:"run dev"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Symfony:"})," Script: ",e.jsx("code",{children:"symfony"}),", Args: ",e.jsx("code",{children:"serve --no-daemon"}),", Interpreter: ",e.jsx("code",{children:"None"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Java JAR:"})," Script: ",e.jsx("code",{children:"app.jar"}),", Interpreter: ",e.jsx("code",{children:"Java"}),", Interp. Args: ",e.jsx("code",{children:"-jar"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Python:"})," Script: ",e.jsx("code",{children:"app.py"}),", Interpreter: ",e.jsx("code",{children:"Python 3"})]})]})]})}),a&&(t==null?void 0:t.pm2Status)&&e.jsx("div",{className:"pm2-status-display",children:e.jsxs("div",{className:"pm2-status-row",children:[e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"PID"}),e.jsx("span",{className:"pm2-metric-value",children:t.pm2Status.pid||"-"})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"CPU"}),e.jsxs("span",{className:"pm2-metric-value",children:[((f=t.pm2Status.cpu)==null?void 0:f.toFixed(1))||"0","%"]})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"MEM"}),e.jsx("span",{className:"pm2-metric-value",children:Ve(t.pm2Status.memory||0)})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"Restarts"}),e.jsx("span",{className:"pm2-metric-value",children:t.pm2Status.restarts||0})]}),t.pm2Status.uptime&&e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"Uptime"}),e.jsx("span",{className:"pm2-metric-value",children:pa(t.pm2Status.uptime)})]})]})}),a&&e.jsxs("div",{className:"pm2-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>c("start"),children:i("common:buttons.start")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>c("stop"),children:i("common:buttons.stop")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>c("restart"),children:i("terminal:buildingAction.restart")}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>c("logs"),children:i("terminal:logs.title")})]})]}):null}function ja({dockerMode:o,setDockerMode:p,dockerImage:u,setDockerImage:x,dockerContainerName:n,setDockerContainerName:y,dockerCommand:C,setDockerCommand:g,dockerPorts:v,setDockerPorts:s,dockerVolumes:h,setDockerVolumes:a,dockerNetwork:t,setDockerNetwork:c,dockerRestart:i,setDockerRestart:f,dockerPull:b,setDockerPull:z,dockerEnv:T,setDockerEnv:B,dockerComposePath:$,setDockerComposePath:R,dockerComposeProject:K,setDockerComposeProject:I,dockerComposeServices:H,setDockerComposeServices:O,selectedExistingContainer:d,setSelectedExistingContainer:L,dockerContainersList:q,isEditMode:V,building:k,handleCommand:_}){const{t:M}=A(["config","common"]);return e.jsxs("div",{className:"form-section docker-config-section",children:[e.jsx("label",{className:"form-label",children:M("config:buildings.dockerConfig")}),e.jsxs("div",{className:"docker-mode-selector",children:[e.jsxs("label",{className:`docker-mode-option ${o==="container"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"container",checked:o==="container",onChange:()=>p("container")}),e.jsx("span",{className:"docker-mode-icon",children:"📦"}),e.jsx("span",{className:"docker-mode-label",children:"Container"}),e.jsx("span",{className:"docker-mode-desc",children:"Create a new container"})]}),e.jsxs("label",{className:`docker-mode-option ${o==="compose"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"compose",checked:o==="compose",onChange:()=>p("compose")}),e.jsx("span",{className:"docker-mode-icon",children:"🛠"}),e.jsx("span",{className:"docker-mode-label",children:"Compose"}),e.jsx("span",{className:"docker-mode-desc",children:"Manage multiple services"})]}),e.jsxs("label",{className:`docker-mode-option ${o==="existing"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"existing",checked:o==="existing",onChange:()=>p("existing")}),e.jsx("span",{className:"docker-mode-icon",children:"🔎"}),e.jsx("span",{className:"docker-mode-label",children:"Existing"}),e.jsx("span",{className:"docker-mode-desc",children:"Adopt existing container"})]})]}),o==="container"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Image:",e.jsx(j,{text:"Docker image to run, e.g., nginx:latest, redis:alpine, my-app:v1",title:"Image",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:u,onChange:l=>x(l.target.value),placeholder:"nginx:latest",required:!0})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Container Name:",e.jsx(j,{text:"Custom name for the container. If empty, auto-generated based on building name.",title:"Container Name",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:n,onChange:l=>y(l.target.value),placeholder:"Auto-generated (tc-{name}-{id})"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Command:",e.jsx(j,{text:"Override the default container command. Leave empty to use image's CMD.",title:"Command Override",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:l=>g(l.target.value),placeholder:"Optional command override"})]}),e.jsxs("div",{className:"form-section docker-ports-section",children:[e.jsxs("label",{className:"form-label",children:["Port Mappings",e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>s([...v,""]),children:"+ Add"})]}),v.map((l,S)=>e.jsxs("div",{className:"docker-mapping-row",children:[e.jsx("input",{type:"text",className:"form-input",value:l,onChange:U=>{const E=[...v];E[S]=U.target.value,s(E)},placeholder:"8080:80 or 3000"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>s(v.filter((U,E)=>E!==S)),children:"x"})]},S)),v.length===0&&e.jsx("div",{className:"form-hint",children:"Format: host:container (e.g., 8080:80) or same port (e.g., 3000)"})]}),e.jsxs("div",{className:"form-section docker-volumes-section",children:[e.jsxs("label",{className:"form-label",children:["Volume Mounts",e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>a([...h,""]),children:"+ Add"})]}),h.map((l,S)=>e.jsxs("div",{className:"docker-mapping-row",children:[e.jsx("input",{type:"text",className:"form-input",value:l,onChange:U=>{const E=[...h];E[S]=U.target.value,a(E)},placeholder:"./data:/app/data or /host/path:/container/path"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>a(h.filter((U,E)=>E!==S)),children:"x"})]},S)),h.length===0&&e.jsx("div",{className:"form-hint",children:"Format: host_path:container_path (relative paths resolved from working directory)"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Network:",e.jsx(j,{text:"Docker network to connect to. Leave empty for default bridge network.",title:"Network",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:t,onChange:l=>c(l.target.value),placeholder:"bridge (default)"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Restart Policy:",e.jsx(j,{text:"When should Docker restart the container automatically?",title:"Restart Policy",position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:i,onChange:l=>f(l.target.value),children:Object.keys(Fs).map(l=>e.jsx("option",{value:l,children:Fs[l].label},l))})]})]}),o==="compose"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Compose File:",e.jsx(j,{text:"Path to docker-compose.yml file, relative to working directory.",title:"Compose File",position:"top",size:"sm"})]}),e.jsx(X,{value:$,onChange:R,placeholder:"docker-compose.yml",className:"form-input",directoriesOnly:!1})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Project Name:",e.jsx(j,{text:"Override the compose project name. Leave empty for auto-generated name.",title:"Project Name",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:K,onChange:l=>I(l.target.value),placeholder:"Auto-generated"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Services:",e.jsx(j,{text:"Specific services to manage (comma-separated). Leave empty for all services.",title:"Services",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:H,onChange:l=>O(l.target.value),placeholder:"All services (or: api, db, redis)"})]})]}),o==="existing"&&e.jsxs("div",{className:"docker-existing-section",children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Select Container:",e.jsx(j,{text:"Choose an existing Docker container to monitor and control. The container will not be deleted when removing the building.",title:"Existing Container",position:"top",size:"sm"})]}),e.jsxs("div",{className:"docker-existing-select-wrapper",children:[e.jsxs("select",{className:"form-input form-select",value:d,onChange:l=>L(l.target.value),required:o==="existing",children:[e.jsx("option",{value:"",children:"Select a container..."}),q.map(l=>e.jsxs("option",{value:l.name,children:[l.name," (",l.image,") - ",l.state]},l.id))]}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.requestDockerContainersList(),title:"Refresh container list",children:"↻"})]})]}),q.length===0&&e.jsx("div",{className:"form-hint docker-existing-hint",children:"No containers found. Make sure Docker is running and you have containers available."}),d&&e.jsx("div",{className:"docker-existing-info",children:(()=>{const l=q.find(S=>S.name===d);return l?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Image:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.image})]}),e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Status:"}),e.jsx("span",{className:`docker-existing-info-value docker-status-${l.status}`,children:l.state})]}),e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"ID:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.id.slice(0,12)})]}),l.ports.length>0&&e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Ports:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.ports.map(S=>`${S.host}:${S.container}/${S.protocol}`).join(", ")})]})]}):null})()}),e.jsx("div",{className:"form-hint",children:"Note: Existing containers will not be deleted when you remove this building."})]}),o!=="existing"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Pull Policy:",e.jsx(j,{text:"When to pull images: always, only if missing, or never.",title:"Pull Policy",position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:b,onChange:l=>z(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=>B(l.target.value),placeholder:`KEY=value
|
|
4
4
|
DATABASE_URL=postgres://...
|
|
5
|
-
NODE_ENV=production`,rows:3})]})]}),V&&(k==null?void 0:k.dockerStatus)&&e.jsxs("div",{className:"docker-status-display",children:[e.jsxs("div",{className:"docker-status-row",children:[e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"ID"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.containerId||"-"})]}),e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"Status"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.status||"-"})]}),k.dockerStatus.health&&k.dockerStatus.health!=="none"&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"Health"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.health})]}),k.dockerStatus.cpu!==void 0&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"CPU"}),e.jsxs("span",{className:"docker-metric-value",children:[k.dockerStatus.cpu.toFixed(1),"%"]})]}),k.dockerStatus.memory!==void 0&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"MEM"}),e.jsxs("span",{className:"docker-metric-value",children:[Ve(k.dockerStatus.memory),k.dockerStatus.memoryLimit?` / ${Ve(k.dockerStatus.memoryLimit)}`:""]})]})]}),k.dockerStatus.ports&&k.dockerStatus.ports.length>0&&e.jsxs("div",{className:"docker-ports-row",children:[e.jsx("span",{className:"docker-metric-label",children:"Ports:"}),k.dockerStatus.ports.map((l,S)=>e.jsxs("a",{href:`http://${window.location.hostname}:${l.host}`,target:"_blank",rel:"noopener noreferrer",className:"docker-port-link",children:[l.host,":",l.container,"/",l.protocol]},S))]}),k.dockerStatus.services&&k.dockerStatus.services.length>0&&e.jsxs("div",{className:"docker-services-status",children:[e.jsx("span",{className:"docker-metric-label",children:"Services:"}),e.jsx("div",{className:"docker-services-grid",children:k.dockerStatus.services.map((l,S)=>e.jsxs("div",{className:"docker-service-item",children:[e.jsx("span",{className:"docker-service-indicator",style:{backgroundColor:l.status==="running"?"#4ade80":"#f87171"}}),e.jsx("span",{className:"docker-service-name",children:l.name}),e.jsx("span",{className:"docker-service-status",children:l.status})]},S))})]})]}),V&&e.jsxs("div",{className:"docker-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>_("start"),children:"Start"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>_("stop"),children:"Stop"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>_("restart"),children:"Restart"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>_("logs"),children:"Logs"})]})]})}const ba={enabled:!1,host:"",port:22,username:"",authMethod:"password"};function ja({dbConnections:r,setDbConnections:p,activeDbConnectionId:u,setActiveDbConnectionId:x}){const{t:n}=B(["terminal","common"]),[y,C]=m.useState({}),g=m.useRef(new Map);m.useEffect(()=>{const a=t=>{const c=t.detail;if(!c||!c.requestId)return;const i=g.current.get(c.requestId);i&&(g.current.delete(c.requestId),C(f=>({...f,[i]:c.success?{status:"success",serverVersion:c.serverVersion}:{status:"error",error:c.error||"Connection failed"}})))};return window.addEventListener("tide:db-test-result",a),()=>window.removeEventListener("tide:db-test-result",a)},[]);const v=(a,t)=>{const c=[...r];c[a]={...c[a],...t},p(c)},s=(a,t)=>{const i={...r[a].ssh??ba,...t};v(a,{ssh:i})},h=a=>{const t=`test_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;g.current.set(t,a.id),C(c=>({...c,[a.id]:{status:"testing"}})),D.testDatabaseConnectionTransient(t,a),window.setTimeout(()=>{g.current.has(t)&&(g.current.delete(t),C(c=>{const i=c[a.id];return(i==null?void 0:i.status)!=="testing"?c:{...c,[a.id]:{status:"error",error:"Test connection timed out after 30s"}}}))},3e4)};return e.jsxs("div",{className:"form-section database-config-section",children:[e.jsxs("label",{className:"form-label",children:[n("terminal:building.dbConnections"),e.jsx(j,{text:n("terminal:building.helpDbConnections"),title:n("terminal:building.dbConnections"),position:"top",size:"sm"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>{const a={id:`conn_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,name:`Connection ${r.length+1}`,engine:"mysql",host:"localhost",port:3306,username:"root"};p([...r,a]),u||x(a.id)},children:n("terminal:database.addConnection")})]}),r.length===0&&e.jsx("div",{className:"form-hint",children:n("terminal:building.dbGetStarted")}),r.map((a,t)=>{var f,b,L,T,A,K,I,$,R,H,O;const c=y[a.id]??{status:"idle"},i=((f=a.ssh)==null?void 0:f.enabled)===!0;return e.jsxs("div",{className:"db-connection-card",children:[e.jsxs("div",{className:"db-connection-header",children:[e.jsxs("label",{className:"db-connection-active",children:[e.jsx("input",{type:"radio",name:"activeConnection",checked:u===a.id,onChange:()=>x(a.id)}),n("common:labels.default"),e.jsx(j,{text:n("terminal:building.helpDbDefault"),position:"top",size:"sm"})]}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>{const d=r.filter(z=>z.id!==a.id);p(d),u===a.id&&d.length>0?x(d[0].id):d.length===0&&x(void 0)},children:n("common:buttons.remove")})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("common:labels.name")}),e.jsx("input",{type:"text",className:"form-input",value:a.name,onChange:d=>v(t,{name:d.target.value}),placeholder:"My Database"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:n("terminal:building.dbEngine")}),e.jsx("select",{className:"form-input form-select",value:a.engine,onChange:d=>{const z=d.target.value;v(t,{engine:z,port:Z[z].defaultPort})},children:Object.keys(Z).map(d=>e.jsxs("option",{value:d,children:[Z[d].icon," ",Z[d].label]},d))})]})]}),a.engine==="sqlite"?e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:n("terminal:building.dbFilepath")}),e.jsx("input",{type:"text",className:"form-input",value:a.filepath||"",onChange:d=>v(t,{filepath:d.target.value||void 0}),placeholder:"/path/to/database.db"})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:[n("terminal:building.dbHost"),i&&e.jsx(j,{text:"Host as seen FROM the SSH server (often 'localhost' or 127.0.0.1).",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:a.host,onChange:d=>v(t,{host:d.target.value}),placeholder:i?"127.0.0.1":"localhost"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:n("terminal:building.dbPort")}),e.jsx("input",{type:"number",className:"form-input",value:a.port,onChange:d=>v(t,{port:parseInt(d.target.value)||Z[a.engine].defaultPort})})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("terminal:building.dbUsername")}),e.jsx("input",{type:"text",className:"form-input",value:a.username,onChange:d=>v(t,{username:d.target.value}),placeholder:"root"})]}),e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("terminal:building.dbPassword")}),e.jsx("input",{type:"password",className:"form-input",value:a.password||"",onChange:d=>v(t,{password:d.target.value||void 0}),placeholder:"Optional",autoComplete:"off"})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:n("terminal:building.dbDefaultDatabase")}),e.jsx("input",{type:"text",className:"form-input",value:a.database||"",onChange:d=>v(t,{database:d.target.value||void 0}),placeholder:"Optional - select after connecting"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsxs("label",{children:["SSL",e.jsx(j,{text:n("terminal:building.helpDbSsl"),position:"top",size:"sm"})]}),e.jsxs("label",{className:"toggle-switch toggle-switch--small",children:[e.jsx("input",{type:"checkbox",checked:a.ssl||!1,onChange:d=>v(t,{ssl:d.target.checked})}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})})]})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsx("div",{className:"db-field db-field--grow",children:e.jsxs("label",{children:["SSH Tunnel",e.jsx(j,{text:"Forward DB traffic through an SSH jump host. Required when the DB is only reachable from inside a private network.",position:"top",size:"sm"})]})}),e.jsx("div",{className:"db-field db-field--small",children:e.jsxs("label",{className:"toggle-switch toggle-switch--small",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:d=>s(t,{enabled:d.target.checked})}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})})]})})]}),i&&e.jsxs("div",{className:"db-ssh-subsection",children:[e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Host"}),e.jsx("input",{type:"text",className:"form-input",value:((b=a.ssh)==null?void 0:b.host)||"",onChange:d=>s(t,{host:d.target.value}),placeholder:"bastion.example.com"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:"SSH Port"}),e.jsx("input",{type:"number",className:"form-input",value:((L=a.ssh)==null?void 0:L.port)||22,onChange:d=>s(t,{port:parseInt(d.target.value)||22})})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Username"}),e.jsx("input",{type:"text",className:"form-input",value:((T=a.ssh)==null?void 0:T.username)||"",onChange:d=>s(t,{username:d.target.value}),placeholder:"ubuntu"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:"Auth Method"}),e.jsxs("select",{className:"form-input form-select",value:((A=a.ssh)==null?void 0:A.authMethod)||"password",onChange:d=>s(t,{authMethod:d.target.value}),children:[e.jsx("option",{value:"password",children:"Password"}),e.jsx("option",{value:"privateKey",children:"Private Key"})]})]})]}),(((K=a.ssh)==null?void 0:K.authMethod)||"password")==="password"?e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Password"}),e.jsx("input",{type:"password",className:"form-input",value:((I=a.ssh)==null?void 0:I.password)||"",onChange:d=>s(t,{password:d.target.value||void 0}),placeholder:"SSH password",autoComplete:"off"})]})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:["Private Key Path",e.jsx(j,{text:"Path to a private key file on the server, e.g. ~/.ssh/id_rsa. Use this OR paste the key contents below.",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:(($=a.ssh)==null?void 0:$.privateKeyPath)||"",onChange:d=>s(t,{privateKeyPath:d.target.value||void 0}),placeholder:"/home/user/.ssh/id_rsa"})]})}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:["Private Key Contents (PEM)",e.jsx(j,{text:"Paste the full private key contents inline. Encrypted at rest.",position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input",value:((R=a.ssh)==null?void 0:R.privateKey)||"",onChange:d=>s(t,{privateKey:d.target.value||void 0}),placeholder:"-----BEGIN OPENSSH PRIVATE KEY-----\\n...",rows:4,style:{fontFamily:"monospace",fontSize:12}})]})}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"Key Passphrase (optional)"}),e.jsx("input",{type:"password",className:"form-input",value:((H=a.ssh)==null?void 0:H.passphrase)||"",onChange:d=>s(t,{passphrase:d.target.value||void 0}),placeholder:"If your key is encrypted",autoComplete:"off"})]})})]}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--small",children:[e.jsxs("label",{children:["Local Port",e.jsx(j,{text:"Optional fixed local forwarded port. Leave blank to auto-assign.",position:"top",size:"sm"})]}),e.jsx("input",{type:"number",className:"form-input",value:((O=a.ssh)==null?void 0:O.localPort)??"",onChange:d=>{const z=d.target.value.trim();s(t,{localPort:z?parseInt(z):void 0})},placeholder:"auto"})]})})]}),e.jsxs("div",{className:"db-connection-row",style:{alignItems:"center",gap:8},children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-primary",disabled:c.status==="testing",onClick:()=>h(a),children:c.status==="testing"?"Testing…":"Test Connection"}),c.status==="success"&&e.jsxs("span",{style:{color:"#4aff9e",fontSize:12},children:["✓ Connected",c.serverVersion?` — ${c.serverVersion}`:""]}),c.status==="error"&&e.jsxs("span",{style:{color:"#ff6b6b",fontSize:12},title:c.error,children:["✗ ",c.error]})]})]})]},a.id)}),r.length>0&&e.jsx("div",{className:"form-hint",children:n("terminal:building.dbAfterSaving")})]})}function ga({buildings:r,buildingId:p,subordinateBuildingIds:u,setSubordinateBuildingIds:x,isEditMode:n,showBossLogs:y,setShowBossLogs:C,currentBossLogs:g,bossLogsContainerRef:v}){const{t:s}=B(["terminal","common"]);return e.jsxs("div",{className:"form-section boss-building-section",children:[e.jsxs("label",{className:"form-label",children:[s("terminal:building.managedBuildings"),e.jsx(j,{text:s("terminal:building.helpManagedBuildings"),title:s("terminal:building.managedBuildings"),position:"top",size:"sm"})]}),e.jsx("div",{className:"form-hint",children:s("terminal:building.managedBuildingsHint")}),e.jsxs("div",{className:"subordinate-buildings-list",children:[Array.from(r.values()).filter(h=>h.id!==p&&h.type!=="boss"&&h.type!=="link"&&h.type!=="folder").map(h=>e.jsxs("label",{className:"subordinate-building-item",children:[e.jsx("input",{type:"checkbox",checked:u.includes(h.id),onChange:a=>{a.target.checked?x([...u,h.id]):x(u.filter(t=>t!==h.id))}}),e.jsx("span",{className:"subordinate-building-icon",children:e.jsx(F,{name:Us(h.type),size:14})}),e.jsx("span",{className:"subordinate-building-name",children:h.name}),e.jsx("span",{className:"subordinate-building-status",style:{backgroundColor:qe[h.status]}})]},h.id)),Array.from(r.values()).filter(h=>h.id!==p&&h.type!=="boss"&&h.type!=="link"&&h.type!=="folder").length===0&&e.jsx("div",{className:"form-hint no-buildings-hint",children:s("terminal:building.noManageableBuildings")})]}),n&&u.length>0&&e.jsxs("div",{className:"boss-building-actions",children:[e.jsxs("div",{className:"boss-actions-header",children:[s("terminal:building.bulkActions"),e.jsx(j,{text:s("terminal:building.helpBulkActions"),position:"top",size:"sm"})]}),e.jsxs("div",{className:"boss-actions-row",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>D.sendBossBuildingCommand(p,"start_all"),children:s("terminal:building.startAll")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>D.sendBossBuildingCommand(p,"stop_all"),children:s("terminal:building.stopAll")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>D.sendBossBuildingCommand(p,"restart_all"),children:s("terminal:building.restartAll")}),e.jsx("button",{type:"button",className:`btn btn-sm ${y?"btn-primary":""}`,onClick:()=>{y?(D.stopBossLogStreaming(p),C(!1)):(D.startBossLogStreaming(p),C(!0))},children:s(y?"terminal:building.hideLogs":"terminal:building.unifiedLogs")})]}),e.jsxs("div",{className:"boss-subordinates-status",children:[e.jsx("div",{className:"boss-status-header",children:s("terminal:building.statusOverview")}),e.jsx("div",{className:"boss-status-grid",children:u.map(h=>{const a=r.get(h);return a?e.jsxs("div",{className:"boss-status-item",children:[e.jsx("span",{className:"boss-status-indicator",style:{backgroundColor:qe[a.status]}}),e.jsx("span",{className:"boss-status-name",children:a.name}),e.jsx("span",{className:"boss-status-label",children:a.status})]},h):null})})]})]}),n&&y&&e.jsxs("div",{className:"form-section boss-logs-section",children:[e.jsxs("label",{className:"form-label",children:[s("terminal:building.unifiedLogs"),e.jsx(j,{text:s("terminal:building.helpUnifiedLogs"),position:"top",size:"sm"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.clearBossStreamingLogs(p),children:s("common:buttons.clear")})]}),e.jsxs("div",{className:"boss-logs-container",ref:v,children:[g.map((h,a)=>e.jsxs("div",{className:"boss-log-entry",children:[e.jsxs("span",{className:"boss-log-source",children:["[",h.subordinateName,"]"]}),e.jsx("span",{className:"boss-log-content",children:qs(h.chunk)})]},a)),g.length===0&&e.jsx("div",{className:"boss-logs-empty",children:s("terminal:building.waitingForLogs")})]})]})]})}function va({startCmd:r,setStartCmd:p,stopCmd:u,setStopCmd:x,restartCmd:n,setRestartCmd:y,healthCheckCmd:C,setHealthCheckCmd:g,logsCmd:v,setLogsCmd:s,isEditMode:h,handleCommand:a}){const{t}=B(["terminal","common"]);return e.jsxs("div",{className:"form-section commands-section",children:[e.jsxs("label",{className:"form-label",children:[t("terminal:building.commands"),e.jsx(j,{text:t("terminal:building.helpCommands"),title:t("terminal:building.commands"),position:"top",size:"sm"})]}),e.jsxs("div",{className:"command-inputs",children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdStart"),e.jsx(j,{text:t("terminal:building.helpCmdStart"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:r,onChange:c=>p(c.target.value),placeholder:"npm run dev"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>a("start"),disabled:!r,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdStop"),e.jsx(j,{text:t("terminal:building.helpCmdStop"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:u,onChange:c=>x(c.target.value),placeholder:"pkill -f 'npm run dev'"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>a("stop"),disabled:!u,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdRestart"),e.jsx(j,{text:t("terminal:building.helpCmdRestart"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:n,onChange:c=>y(c.target.value),placeholder:"npm run restart"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>a("restart"),disabled:!n,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdHealthCheck"),e.jsx(j,{text:t("terminal:building.helpCmdHealthCheck"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:c=>g(c.target.value),placeholder:"curl -s http://localhost:3000/health"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>a("healthCheck"),disabled:!C,children:t("terminal:building.check")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdLogs"),e.jsx(j,{text:t("terminal:building.helpCmdLogs"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:v,onChange:c=>s(c.target.value),placeholder:"tail -n 100 /var/log/app.log"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>a("logs"),children:t("terminal:building.fetch")})]})]})]})}const fa=[{value:"",label:"Default ($SHELL)"},{value:"/bin/bash",label:"Bash"},{value:"/bin/zsh",label:"Zsh"},{value:"/usr/bin/fish",label:"Fish"},{value:"/bin/sh",label:"sh"}];function Na({terminalShell:r,setTerminalShell:p,terminalPort:u,setTerminalPort:x,terminalSaveSession:n,setTerminalSaveSession:y,terminalArgs:C,setTerminalArgs:g,isEditMode:v,building:s,handleCommand:h,onOpenTerminal:a,onOpenBelow:t}){const{t:c}=B(["config"]),i=(s==null?void 0:s.status)==="running",f=s==null?void 0:s.terminalStatus;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:c("config:buildings.terminalConfig",{defaultValue:"Terminal Configuration"})}),e.jsxs("div",{className:"form-row",children:[e.jsxs("div",{className:"form-field",children:[e.jsx("label",{className:"form-sublabel",children:c("config:buildings.terminalShell",{defaultValue:"Shell"})}),e.jsx("select",{className:"form-input",value:r,onChange:b=>p(b.target.value),children:fa.map(b=>e.jsx("option",{value:b.value,children:b.label},b.value))})]}),e.jsxs("div",{className:"form-field",children:[e.jsx("label",{className:"form-sublabel",children:c("config:buildings.terminalPort",{defaultValue:"Port"})}),e.jsx("input",{type:"number",className:"form-input",value:u,onChange:b=>x(b.target.value),placeholder:"Auto",min:1024,max:65535})]})]}),e.jsx("div",{className:"form-row",style:{marginTop:"8px"},children:e.jsxs("label",{className:"form-checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n,onChange:b=>y(b.target.checked)}),e.jsx("span",{children:c("config:buildings.terminalSaveSession",{defaultValue:"Persist session (tmux)"})})]})}),e.jsxs("div",{style:{marginTop:"8px"},children:[e.jsx("label",{className:"form-sublabel",children:c("config:buildings.terminalArgs",{defaultValue:"Extra ttyd args"})}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:b=>g(b.target.value),placeholder:"--client-option titleFixed=Terminal"}),e.jsx("div",{className:"form-hint",children:"Additional command-line arguments passed to ttyd"})]})]}),v&&s&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:c("config:buildings.terminalControls",{defaultValue:"Terminal Controls"})}),f&&e.jsxs("div",{className:"building-runtime-info",children:[e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Proxy"}),e.jsx("span",{className:"runtime-value",style:{color:"#4a9eff"},children:f.url})]}),e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"PID"}),e.jsx("span",{className:"runtime-value",children:f.pid})]}),e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Port"}),e.jsx("span",{className:"runtime-value",children:f.port})]}),f.tmuxSession&&e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Session"}),e.jsx("span",{className:"runtime-value",children:f.tmuxSession})]})]}),e.jsxs("div",{className:"building-actions",style:{marginTop:"8px"},children:[!i&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>h("start"),children:[e.jsx(F,{name:"play",size:12})," Start"]}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>h("restart"),children:[e.jsx(F,{name:"refresh",size:12})," Restart"]}),e.jsxs("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>h("stop"),children:[e.jsx(F,{name:"stop",size:12})," Stop"]}),(f==null?void 0:f.url)&&e.jsxs(e.Fragment,{children:[a&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-primary",onClick:()=>a(f.url),children:[e.jsx(F,{name:"desktop",size:12})," Modal"]}),t&&s&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-primary",onClick:()=>t(s.id),children:[e.jsx(F,{name:"arrow-down",size:12})," Below"]})]})]})]})]})]})}function ka({logs:r,buildingId:p,logsContainerRef:u}){return e.jsxs("div",{className:"form-section logs-section",children:[e.jsxs("label",{className:"form-label",children:["Logs",e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.clearBuildingLogs(p),children:"Clear"})]}),e.jsx("div",{className:"logs-container",ref:u,children:r.map((x,n)=>e.jsx("pre",{className:"log-entry",children:qs(x)},n))})]})}function wa({isOpen:r,onClose:p,buildingId:u,initialPosition:x}){const{t:n}=B(["config","common"]),{buildings:y,buildingLogs:C,bossStreamingLogs:g}=na(),v=la(),s=u?y.get(u):null,h=u?g.get(u)||[]:[],a=!!s,[t,c]=m.useState(""),[i,f]=m.useState("server"),[b,L]=m.useState("server-rack"),[T,A]=m.useState(""),[K,I]=m.useState(""),[$,R]=m.useState(""),[H,O]=m.useState(""),[d,z]=m.useState(""),[q,V]=m.useState(""),[k,_]=m.useState(""),[M,l]=m.useState([]),[S,U]=m.useState(!1),[E,J]=m.useState(""),[W,ee]=m.useState(1),[X,te]=m.useState(!1),[Ge,ne]=m.useState(""),[Ye,le]=m.useState(""),[Je,ie]=m.useState(""),[We,re]=m.useState(""),[Xe,oe]=m.useState(""),[Vs,ce]=m.useState(!1),[P,de]=m.useState("container"),[me,ue]=m.useState(""),[Ze,pe]=m.useState(""),[he,xe]=m.useState(""),[be,je]=m.useState([]),[ge,ve]=m.useState([]),[Qe,fe]=m.useState(""),[Ne,ke]=m.useState(""),[ye,Ce]=m.useState(""),[es,Se]=m.useState("unless-stopped"),[ss,we]=m.useState("missing"),[Pe,De]=m.useState(""),[Ee,ze]=m.useState(""),[Le,Ae]=m.useState(""),[Be,Te]=m.useState([]),[Gs,Ys]=m.useState(!1),[Ie,Re]=m.useState([]),[as,Oe]=m.useState(void 0),[ts,_e]=m.useState(""),[Me,Fe]=m.useState(""),[ns,Ke]=m.useState(!1),[ls,$e]=m.useState(""),is=m.useRef(null),Js=m.useRef(null),se=m.useRef(null);m.useEffect(()=>{var o,N,w,G,ds,ms,us,ps,hs,xs,bs,js,gs,vs,fs,Ns,ks,ys,Cs,Ss,ws,Ps,Ds,Es,zs,Ls,As,Bs,Ts,Is,Rs,Os,_s;r&&(s?(c(s.name),f(s.type),L(s.style||"server-rack"),A(s.color||""),I(s.cwd||""),R(((o=s.commands)==null?void 0:o.start)||""),O(((N=s.commands)==null?void 0:N.stop)||""),z(((w=s.commands)==null?void 0:w.restart)||""),V(((G=s.commands)==null?void 0:G.healthCheck)||""),_(((ds=s.commands)==null?void 0:ds.logs)||""),l(s.urls||[]),J(s.folderPath||""),ee(s.scale||1),te(((ms=s.pm2)==null?void 0:ms.enabled)||!1),ne(((us=s.pm2)==null?void 0:us.script)||""),le(((ps=s.pm2)==null?void 0:ps.args)||""),ie(((hs=s.pm2)==null?void 0:hs.interpreter)||""),re(((xs=s.pm2)==null?void 0:xs.interpreterArgs)||""),oe((bs=s.pm2)!=null&&bs.env?Object.entries(s.pm2.env).map(([Y,He])=>`${Y}=${He}`).join(`
|
|
5
|
+
NODE_ENV=production`,rows:3})]})]}),V&&(k==null?void 0:k.dockerStatus)&&e.jsxs("div",{className:"docker-status-display",children:[e.jsxs("div",{className:"docker-status-row",children:[e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"ID"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.containerId||"-"})]}),e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"Status"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.status||"-"})]}),k.dockerStatus.health&&k.dockerStatus.health!=="none"&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"Health"}),e.jsx("span",{className:"docker-metric-value",children:k.dockerStatus.health})]}),k.dockerStatus.cpu!==void 0&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"CPU"}),e.jsxs("span",{className:"docker-metric-value",children:[k.dockerStatus.cpu.toFixed(1),"%"]})]}),k.dockerStatus.memory!==void 0&&e.jsxs("span",{className:"docker-metric",children:[e.jsx("span",{className:"docker-metric-label",children:"MEM"}),e.jsxs("span",{className:"docker-metric-value",children:[Ve(k.dockerStatus.memory),k.dockerStatus.memoryLimit?` / ${Ve(k.dockerStatus.memoryLimit)}`:""]})]})]}),k.dockerStatus.ports&&k.dockerStatus.ports.length>0&&e.jsxs("div",{className:"docker-ports-row",children:[e.jsx("span",{className:"docker-metric-label",children:"Ports:"}),k.dockerStatus.ports.map((l,S)=>e.jsxs("a",{href:`http://${window.location.hostname}:${l.host}`,target:"_blank",rel:"noopener noreferrer",className:"docker-port-link",children:[l.host,":",l.container,"/",l.protocol]},S))]}),k.dockerStatus.services&&k.dockerStatus.services.length>0&&e.jsxs("div",{className:"docker-services-status",children:[e.jsx("span",{className:"docker-metric-label",children:"Services:"}),e.jsx("div",{className:"docker-services-grid",children:k.dockerStatus.services.map((l,S)=>e.jsxs("div",{className:"docker-service-item",children:[e.jsx("span",{className:"docker-service-indicator",style:{backgroundColor:l.status==="running"?"#4ade80":"#f87171"}}),e.jsx("span",{className:"docker-service-name",children:l.name}),e.jsx("span",{className:"docker-service-status",children:l.status})]},S))})]})]}),V&&e.jsxs("div",{className:"docker-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>_("start"),children:"Start"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>_("stop"),children:"Stop"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>_("restart"),children:"Restart"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>_("logs"),children:"Logs"})]})]})}const ga={enabled:!1,host:"",port:22,username:"",authMethod:"password"};function va({dbConnections:o,setDbConnections:p,activeDbConnectionId:u,setActiveDbConnectionId:x}){const{t:n}=A(["terminal","common"]),[y,C]=m.useState({}),g=m.useRef(new Map);m.useEffect(()=>{const a=t=>{const c=t.detail;if(!c||!c.requestId)return;const i=g.current.get(c.requestId);i&&(g.current.delete(c.requestId),C(f=>({...f,[i]:c.success?{status:"success",serverVersion:c.serverVersion}:{status:"error",error:c.error||"Connection failed"}})))};return window.addEventListener("tide:db-test-result",a),()=>window.removeEventListener("tide:db-test-result",a)},[]);const v=(a,t)=>{const c=[...o];c[a]={...c[a],...t},p(c)},s=(a,t)=>{const i={...o[a].ssh??ga,...t};v(a,{ssh:i})},h=a=>{const t=`test_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;g.current.set(t,a.id),C(c=>({...c,[a.id]:{status:"testing"}})),D.testDatabaseConnectionTransient(t,a),window.setTimeout(()=>{g.current.has(t)&&(g.current.delete(t),C(c=>{const i=c[a.id];return(i==null?void 0:i.status)!=="testing"?c:{...c,[a.id]:{status:"error",error:"Test connection timed out after 30s"}}}))},3e4)};return e.jsxs("div",{className:"form-section database-config-section",children:[e.jsxs("label",{className:"form-label",children:[n("terminal:building.dbConnections"),e.jsx(j,{text:n("terminal:building.helpDbConnections"),title:n("terminal:building.dbConnections"),position:"top",size:"sm"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>{const a={id:`conn_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,name:`Connection ${o.length+1}`,engine:"mysql",host:"localhost",port:3306,username:"root"};p([...o,a]),u||x(a.id)},children:n("terminal:database.addConnection")})]}),o.length===0&&e.jsx("div",{className:"form-hint",children:n("terminal:building.dbGetStarted")}),o.map((a,t)=>{var f,b,z,T,B,$,R,K,I,H,O;const c=y[a.id]??{status:"idle"},i=((f=a.ssh)==null?void 0:f.enabled)===!0;return e.jsxs("div",{className:"db-connection-card",children:[e.jsxs("div",{className:"db-connection-header",children:[e.jsxs("label",{className:"db-connection-active",children:[e.jsx("input",{type:"radio",name:"activeConnection",checked:u===a.id,onChange:()=>x(a.id)}),n("common:labels.default"),e.jsx(j,{text:n("terminal:building.helpDbDefault"),position:"top",size:"sm"})]}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>{const d=o.filter(L=>L.id!==a.id);p(d),u===a.id&&d.length>0?x(d[0].id):d.length===0&&x(void 0)},children:n("common:buttons.remove")})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("common:labels.name")}),e.jsx("input",{type:"text",className:"form-input",value:a.name,onChange:d=>v(t,{name:d.target.value}),placeholder:"My Database"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:n("terminal:building.dbEngine")}),e.jsx("select",{className:"form-input form-select",value:a.engine,onChange:d=>{const L=d.target.value;v(t,{engine:L,port:Q[L].defaultPort})},children:Object.keys(Q).map(d=>e.jsxs("option",{value:d,children:[Q[d].icon," ",Q[d].label]},d))})]})]}),a.engine==="sqlite"?e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:n("terminal:building.dbFilepath")}),e.jsx("input",{type:"text",className:"form-input",value:a.filepath||"",onChange:d=>v(t,{filepath:d.target.value||void 0}),placeholder:"/path/to/database.db"})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:[n("terminal:building.dbHost"),i&&e.jsx(j,{text:"Host as seen FROM the SSH server (often 'localhost' or 127.0.0.1).",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:a.host,onChange:d=>v(t,{host:d.target.value}),placeholder:i?"127.0.0.1":"localhost"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:n("terminal:building.dbPort")}),e.jsx("input",{type:"number",className:"form-input",value:a.port,onChange:d=>v(t,{port:parseInt(d.target.value)||Q[a.engine].defaultPort})})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("terminal:building.dbUsername")}),e.jsx("input",{type:"text",className:"form-input",value:a.username,onChange:d=>v(t,{username:d.target.value}),placeholder:"root"})]}),e.jsxs("div",{className:"db-field",children:[e.jsx("label",{children:n("terminal:building.dbPassword")}),e.jsx("input",{type:"password",className:"form-input",value:a.password||"",onChange:d=>v(t,{password:d.target.value||void 0}),placeholder:"Optional",autoComplete:"off"})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:n("terminal:building.dbDefaultDatabase")}),e.jsx("input",{type:"text",className:"form-input",value:a.database||"",onChange:d=>v(t,{database:d.target.value||void 0}),placeholder:"Optional - select after connecting"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsxs("label",{children:["SSL",e.jsx(j,{text:n("terminal:building.helpDbSsl"),position:"top",size:"sm"})]}),e.jsxs("label",{className:"toggle-switch toggle-switch--small",children:[e.jsx("input",{type:"checkbox",checked:a.ssl||!1,onChange:d=>v(t,{ssl:d.target.checked})}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})})]})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsx("div",{className:"db-field db-field--grow",children:e.jsxs("label",{children:["SSH Tunnel",e.jsx(j,{text:"Forward DB traffic through an SSH jump host. Required when the DB is only reachable from inside a private network.",position:"top",size:"sm"})]})}),e.jsx("div",{className:"db-field db-field--small",children:e.jsxs("label",{className:"toggle-switch toggle-switch--small",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:d=>s(t,{enabled:d.target.checked})}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})})]})})]}),i&&e.jsxs("div",{className:"db-ssh-subsection",children:[e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Host"}),e.jsx("input",{type:"text",className:"form-input",value:((b=a.ssh)==null?void 0:b.host)||"",onChange:d=>s(t,{host:d.target.value}),placeholder:"bastion.example.com"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:"SSH Port"}),e.jsx("input",{type:"number",className:"form-input",value:((z=a.ssh)==null?void 0:z.port)||22,onChange:d=>s(t,{port:parseInt(d.target.value)||22})})]})]}),e.jsxs("div",{className:"db-connection-row",children:[e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Username"}),e.jsx("input",{type:"text",className:"form-input",value:((T=a.ssh)==null?void 0:T.username)||"",onChange:d=>s(t,{username:d.target.value}),placeholder:"ubuntu"})]}),e.jsxs("div",{className:"db-field db-field--small",children:[e.jsx("label",{children:"Auth Method"}),e.jsxs("select",{className:"form-input form-select",value:((B=a.ssh)==null?void 0:B.authMethod)||"password",onChange:d=>s(t,{authMethod:d.target.value}),children:[e.jsx("option",{value:"password",children:"Password"}),e.jsx("option",{value:"privateKey",children:"Private Key"})]})]})]}),((($=a.ssh)==null?void 0:$.authMethod)||"password")==="password"?e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"SSH Password"}),e.jsx("input",{type:"password",className:"form-input",value:((R=a.ssh)==null?void 0:R.password)||"",onChange:d=>s(t,{password:d.target.value||void 0}),placeholder:"SSH password",autoComplete:"off"})]})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:["Private Key Path",e.jsx(j,{text:"Path to a private key file on the server, e.g. ~/.ssh/id_rsa. Use this OR paste the key contents below.",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:((K=a.ssh)==null?void 0:K.privateKeyPath)||"",onChange:d=>s(t,{privateKeyPath:d.target.value||void 0}),placeholder:"/home/user/.ssh/id_rsa"})]})}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsxs("label",{children:["Private Key Contents (PEM)",e.jsx(j,{text:"Paste the full private key contents inline. Encrypted at rest.",position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input",value:((I=a.ssh)==null?void 0:I.privateKey)||"",onChange:d=>s(t,{privateKey:d.target.value||void 0}),placeholder:"-----BEGIN OPENSSH PRIVATE KEY-----\\n...",rows:4,style:{fontFamily:"monospace",fontSize:12}})]})}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--grow",children:[e.jsx("label",{children:"Key Passphrase (optional)"}),e.jsx("input",{type:"password",className:"form-input",value:((H=a.ssh)==null?void 0:H.passphrase)||"",onChange:d=>s(t,{passphrase:d.target.value||void 0}),placeholder:"If your key is encrypted",autoComplete:"off"})]})})]}),e.jsx("div",{className:"db-connection-row",children:e.jsxs("div",{className:"db-field db-field--small",children:[e.jsxs("label",{children:["Local Port",e.jsx(j,{text:"Optional fixed local forwarded port. Leave blank to auto-assign.",position:"top",size:"sm"})]}),e.jsx("input",{type:"number",className:"form-input",value:((O=a.ssh)==null?void 0:O.localPort)??"",onChange:d=>{const L=d.target.value.trim();s(t,{localPort:L?parseInt(L):void 0})},placeholder:"auto"})]})})]}),e.jsxs("div",{className:"db-connection-row",style:{alignItems:"center",gap:8},children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-primary",disabled:c.status==="testing",onClick:()=>h(a),children:c.status==="testing"?"Testing…":"Test Connection"}),c.status==="success"&&e.jsxs("span",{style:{color:"#4aff9e",fontSize:12},children:["✓ Connected",c.serverVersion?` — ${c.serverVersion}`:""]}),c.status==="error"&&e.jsxs("span",{style:{color:"#ff6b6b",fontSize:12},title:c.error,children:["✗ ",c.error]})]})]})]},a.id)}),o.length>0&&e.jsx("div",{className:"form-hint",children:n("terminal:building.dbAfterSaving")})]})}function fa({buildings:o,buildingId:p,subordinateBuildingIds:u,setSubordinateBuildingIds:x,isEditMode:n,showBossLogs:y,setShowBossLogs:C,currentBossLogs:g,bossLogsContainerRef:v}){const{t:s}=A(["terminal","common"]);return e.jsxs("div",{className:"form-section boss-building-section",children:[e.jsxs("label",{className:"form-label",children:[s("terminal:building.managedBuildings"),e.jsx(j,{text:s("terminal:building.helpManagedBuildings"),title:s("terminal:building.managedBuildings"),position:"top",size:"sm"})]}),e.jsx("div",{className:"form-hint",children:s("terminal:building.managedBuildingsHint")}),e.jsxs("div",{className:"subordinate-buildings-list",children:[Array.from(o.values()).filter(h=>h.id!==p&&h.type!=="boss"&&h.type!=="link"&&h.type!=="folder").map(h=>e.jsxs("label",{className:"subordinate-building-item",children:[e.jsx("input",{type:"checkbox",checked:u.includes(h.id),onChange:a=>{a.target.checked?x([...u,h.id]):x(u.filter(t=>t!==h.id))}}),e.jsx("span",{className:"subordinate-building-icon",children:e.jsx(F,{name:Us(h.type),size:14})}),e.jsx("span",{className:"subordinate-building-name",children:h.name}),e.jsx("span",{className:"subordinate-building-status",style:{backgroundColor:qe[h.status]}})]},h.id)),Array.from(o.values()).filter(h=>h.id!==p&&h.type!=="boss"&&h.type!=="link"&&h.type!=="folder").length===0&&e.jsx("div",{className:"form-hint no-buildings-hint",children:s("terminal:building.noManageableBuildings")})]}),n&&u.length>0&&e.jsxs("div",{className:"boss-building-actions",children:[e.jsxs("div",{className:"boss-actions-header",children:[s("terminal:building.bulkActions"),e.jsx(j,{text:s("terminal:building.helpBulkActions"),position:"top",size:"sm"})]}),e.jsxs("div",{className:"boss-actions-row",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>D.sendBossBuildingCommand(p,"start_all"),children:s("terminal:building.startAll")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>D.sendBossBuildingCommand(p,"stop_all"),children:s("terminal:building.stopAll")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>D.sendBossBuildingCommand(p,"restart_all"),children:s("terminal:building.restartAll")}),e.jsx("button",{type:"button",className:`btn btn-sm ${y?"btn-primary":""}`,onClick:()=>{y?(D.stopBossLogStreaming(p),C(!1)):(D.startBossLogStreaming(p),C(!0))},children:s(y?"terminal:building.hideLogs":"terminal:building.unifiedLogs")})]}),e.jsxs("div",{className:"boss-subordinates-status",children:[e.jsx("div",{className:"boss-status-header",children:s("terminal:building.statusOverview")}),e.jsx("div",{className:"boss-status-grid",children:u.map(h=>{const a=o.get(h);return a?e.jsxs("div",{className:"boss-status-item",children:[e.jsx("span",{className:"boss-status-indicator",style:{backgroundColor:qe[a.status]}}),e.jsx("span",{className:"boss-status-name",children:a.name}),e.jsx("span",{className:"boss-status-label",children:a.status})]},h):null})})]})]}),n&&y&&e.jsxs("div",{className:"form-section boss-logs-section",children:[e.jsxs("label",{className:"form-label",children:[s("terminal:building.unifiedLogs"),e.jsx(j,{text:s("terminal:building.helpUnifiedLogs"),position:"top",size:"sm"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.clearBossStreamingLogs(p),children:s("common:buttons.clear")})]}),e.jsxs("div",{className:"boss-logs-container",ref:v,children:[g.map((h,a)=>e.jsxs("div",{className:"boss-log-entry",children:[e.jsxs("span",{className:"boss-log-source",children:["[",h.subordinateName,"]"]}),e.jsx("span",{className:"boss-log-content",children:qs(h.chunk)})]},a)),g.length===0&&e.jsx("div",{className:"boss-logs-empty",children:s("terminal:building.waitingForLogs")})]})]})]})}function Na({startCmd:o,setStartCmd:p,stopCmd:u,setStopCmd:x,restartCmd:n,setRestartCmd:y,healthCheckCmd:C,setHealthCheckCmd:g,logsCmd:v,setLogsCmd:s,isEditMode:h,handleCommand:a}){const{t}=A(["terminal","common"]);return e.jsxs("div",{className:"form-section commands-section",children:[e.jsxs("label",{className:"form-label",children:[t("terminal:building.commands"),e.jsx(j,{text:t("terminal:building.helpCommands"),title:t("terminal:building.commands"),position:"top",size:"sm"})]}),e.jsxs("div",{className:"command-inputs",children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdStart"),e.jsx(j,{text:t("terminal:building.helpCmdStart"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:o,onChange:c=>p(c.target.value),placeholder:"npm run dev"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>a("start"),disabled:!o,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdStop"),e.jsx(j,{text:t("terminal:building.helpCmdStop"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:u,onChange:c=>x(c.target.value),placeholder:"pkill -f 'npm run dev'"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>a("stop"),disabled:!u,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdRestart"),e.jsx(j,{text:t("terminal:building.helpCmdRestart"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:n,onChange:c=>y(c.target.value),placeholder:"npm run restart"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>a("restart"),disabled:!n,children:t("common:buttons2.run")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdHealthCheck"),e.jsx(j,{text:t("terminal:building.helpCmdHealthCheck"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:c=>g(c.target.value),placeholder:"curl -s http://localhost:3000/health"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>a("healthCheck"),disabled:!C,children:t("terminal:building.check")})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[t("terminal:building.cmdLogs"),e.jsx(j,{text:t("terminal:building.helpCmdLogs"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:v,onChange:c=>s(c.target.value),placeholder:"tail -n 100 /var/log/app.log"}),h&&e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>a("logs"),children:t("terminal:building.fetch")})]})]})]})}const ka=[{value:"",label:"Default ($SHELL)"},{value:"/bin/bash",label:"Bash"},{value:"/bin/zsh",label:"Zsh"},{value:"/usr/bin/fish",label:"Fish"},{value:"/bin/sh",label:"sh"}];function ya({terminalShell:o,setTerminalShell:p,terminalPort:u,setTerminalPort:x,terminalSaveSession:n,setTerminalSaveSession:y,terminalArgs:C,setTerminalArgs:g,isEditMode:v,building:s,handleCommand:h,onOpenTerminal:a,onOpenBelow:t}){const{t:c}=A(["config"]),i=(s==null?void 0:s.status)==="running",f=s==null?void 0:s.terminalStatus;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:c("config:buildings.terminalConfig",{defaultValue:"Terminal Configuration"})}),e.jsxs("div",{className:"form-row",children:[e.jsxs("div",{className:"form-field",children:[e.jsx("label",{className:"form-sublabel",children:c("config:buildings.terminalShell",{defaultValue:"Shell"})}),e.jsx("select",{className:"form-input",value:o,onChange:b=>p(b.target.value),children:ka.map(b=>e.jsx("option",{value:b.value,children:b.label},b.value))})]}),e.jsxs("div",{className:"form-field",children:[e.jsx("label",{className:"form-sublabel",children:c("config:buildings.terminalPort",{defaultValue:"Port"})}),e.jsx("input",{type:"number",className:"form-input",value:u,onChange:b=>x(b.target.value),placeholder:"Auto",min:1024,max:65535})]})]}),e.jsx("div",{className:"form-row",style:{marginTop:"8px"},children:e.jsxs("label",{className:"form-checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n,onChange:b=>y(b.target.checked)}),e.jsx("span",{children:c("config:buildings.terminalSaveSession",{defaultValue:"Persist session (tmux)"})})]})}),e.jsxs("div",{style:{marginTop:"8px"},children:[e.jsx("label",{className:"form-sublabel",children:c("config:buildings.terminalArgs",{defaultValue:"Extra ttyd args"})}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:b=>g(b.target.value),placeholder:"--client-option titleFixed=Terminal"}),e.jsx("div",{className:"form-hint",children:"Additional command-line arguments passed to ttyd"})]})]}),v&&s&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:c("config:buildings.terminalControls",{defaultValue:"Terminal Controls"})}),f&&e.jsxs("div",{className:"building-runtime-info",children:[e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Proxy"}),e.jsx("span",{className:"runtime-value",style:{color:"#4a9eff"},children:f.url})]}),e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"PID"}),e.jsx("span",{className:"runtime-value",children:f.pid})]}),e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Port"}),e.jsx("span",{className:"runtime-value",children:f.port})]}),f.tmuxSession&&e.jsxs("div",{className:"runtime-row",children:[e.jsx("span",{className:"runtime-label",children:"Session"}),e.jsx("span",{className:"runtime-value",children:f.tmuxSession})]})]}),e.jsxs("div",{className:"building-actions",style:{marginTop:"8px"},children:[!i&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>h("start"),children:[e.jsx(F,{name:"play",size:12})," Start"]}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>h("restart"),children:[e.jsx(F,{name:"refresh",size:12})," Restart"]}),e.jsxs("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>h("stop"),children:[e.jsx(F,{name:"stop",size:12})," Stop"]}),(f==null?void 0:f.url)&&e.jsxs(e.Fragment,{children:[a&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-primary",onClick:()=>a(f.url),children:[e.jsx(F,{name:"desktop",size:12})," Modal"]}),t&&s&&e.jsxs("button",{type:"button",className:"btn btn-sm btn-primary",onClick:()=>t(s.id),children:[e.jsx(F,{name:"arrow-down",size:12})," Below"]})]})]})]})]})]})}function Ca({logs:o,buildingId:p,logsContainerRef:u}){return e.jsxs("div",{className:"form-section logs-section",children:[e.jsxs("label",{className:"form-label",children:["Logs",e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.clearBuildingLogs(p),children:"Clear"})]}),e.jsx("div",{className:"logs-container",ref:u,children:o.map((x,n)=>e.jsx("pre",{className:"log-entry",children:qs(x)},n))})]})}function Da({isOpen:o,onClose:p,buildingId:u,initialPosition:x}){const{t:n}=A(["config","common"]),y=na(),C=la(),g=ia(),v=oa(),s=u?y.get(u):null,h=u?g.get(u)||[]:[],a=!!s,[t,c]=m.useState(""),[i,f]=m.useState("server"),[b,z]=m.useState("server-rack"),[T,B]=m.useState(""),[$,R]=m.useState(""),[K,I]=m.useState(""),[H,O]=m.useState(""),[d,L]=m.useState(""),[q,V]=m.useState(""),[k,_]=m.useState(""),[M,l]=m.useState([]),[S,U]=m.useState(!1),[E,J]=m.useState(""),[W,ee]=m.useState(1),[Z,te]=m.useState(!1),[Ge,ne]=m.useState(""),[Ye,le]=m.useState(""),[Je,ie]=m.useState(""),[We,oe]=m.useState(""),[Ze,re]=m.useState(""),[Vs,ce]=m.useState(!1),[P,de]=m.useState("container"),[me,ue]=m.useState(""),[Qe,pe]=m.useState(""),[he,xe]=m.useState(""),[be,je]=m.useState([]),[ge,ve]=m.useState([]),[Xe,fe]=m.useState(""),[Ne,ke]=m.useState(""),[ye,Ce]=m.useState(""),[es,Se]=m.useState("unless-stopped"),[ss,we]=m.useState("missing"),[Pe,De]=m.useState(""),[Ee,Le]=m.useState(""),[ze,Be]=m.useState(""),[Ae,Te]=m.useState([]),[Gs,Ys]=m.useState(!1),[Re,Ie]=m.useState([]),[as,Oe]=m.useState(void 0),[ts,_e]=m.useState(""),[Me,Fe]=m.useState(""),[ns,$e]=m.useState(!1),[ls,Ke]=m.useState(""),is=m.useRef(null),Js=m.useRef(null),se=m.useRef(null);m.useEffect(()=>{var r,N,w,G,ds,ms,us,ps,hs,xs,bs,js,gs,vs,fs,Ns,ks,ys,Cs,Ss,ws,Ps,Ds,Es,Ls,zs,Bs,As,Ts,Rs,Is,Os,_s;o&&(s?(c(s.name),f(s.type),z(s.style||"server-rack"),B(s.color||""),R(s.cwd||""),I(((r=s.commands)==null?void 0:r.start)||""),O(((N=s.commands)==null?void 0:N.stop)||""),L(((w=s.commands)==null?void 0:w.restart)||""),V(((G=s.commands)==null?void 0:G.healthCheck)||""),_(((ds=s.commands)==null?void 0:ds.logs)||""),l(s.urls||[]),J(s.folderPath||""),ee(s.scale||1),te(((ms=s.pm2)==null?void 0:ms.enabled)||!1),ne(((us=s.pm2)==null?void 0:us.script)||""),le(((ps=s.pm2)==null?void 0:ps.args)||""),ie(((hs=s.pm2)==null?void 0:hs.interpreter)||""),oe(((xs=s.pm2)==null?void 0:xs.interpreterArgs)||""),re((bs=s.pm2)!=null&&bs.env?Object.entries(s.pm2.env).map(([Y,He])=>`${Y}=${He}`).join(`
|
|
6
6
|
`):""),de(((js=s.docker)==null?void 0:js.mode)||"container"),ue(((gs=s.docker)==null?void 0:gs.mode)==="existing"&&((vs=s.docker)==null?void 0:vs.containerName)||""),pe(((fs=s.docker)==null?void 0:fs.image)||""),xe(((Ns=s.docker)==null?void 0:Ns.containerName)||""),je(((ks=s.docker)==null?void 0:ks.ports)||[]),ve(((ys=s.docker)==null?void 0:ys.volumes)||[]),fe((Cs=s.docker)!=null&&Cs.env?Object.entries(s.docker.env).map(([Y,He])=>`${Y}=${He}`).join(`
|
|
7
|
-
`):""),ke(((Ss=s.docker)==null?void 0:Ss.network)||""),Ce(((ws=s.docker)==null?void 0:ws.command)||""),Se(((Ps=s.docker)==null?void 0:Ps.restart)||"unless-stopped"),we(((Ds=s.docker)==null?void 0:Ds.pull)||"missing"),De(((Es=s.docker)==null?void 0:Es.composePath)||""),
|
|
8
|
-
`).map(N=>N.trim()).filter(N=>N&&N.includes("=")).map(N=>{const w=N.indexOf("=");return[N.slice(0,w),N.slice(w+1)]}))},Ws=
|
|
7
|
+
`):""),ke(((Ss=s.docker)==null?void 0:Ss.network)||""),Ce(((ws=s.docker)==null?void 0:ws.command)||""),Se(((Ps=s.docker)==null?void 0:Ps.restart)||"unless-stopped"),we(((Ds=s.docker)==null?void 0:Ds.pull)||"missing"),De(((Es=s.docker)==null?void 0:Es.composePath)||""),Le(((Ls=s.docker)==null?void 0:Ls.composeProject)||""),Be(((Bs=(zs=s.docker)==null?void 0:zs.services)==null?void 0:Bs.join(", "))||""),Te(s.subordinateBuildingIds||[]),Ie(((As=s.database)==null?void 0:As.connections)||[]),Oe((Ts=s.database)==null?void 0:Ts.activeConnectionId),_e(((Rs=s.terminal)==null?void 0:Rs.shell)||""),Fe((Is=s.terminal)!=null&&Is.port?String(s.terminal.port):""),$e(((Os=s.terminal)==null?void 0:Os.saveSession)||!1),Ke(((_s=s.terminal)==null?void 0:_s.args)||"")):(c("New Server"),f("server"),z("server-rack"),B(""),R(ra(ca.LAST_CWD)),I(""),O(""),L(""),V(""),_(""),l([]),J(""),ee(1),te(!1),ne(""),le(""),ie(""),oe(""),re(""),de("container"),ue(""),pe(""),xe(""),je([]),ve([]),fe(""),ke(""),Ce(""),Se("unless-stopped"),we("missing"),De(""),Le(""),Be(""),Te([]),Ie([]),Oe(void 0),_e(""),Fe(""),$e(!1),Ke("")),setTimeout(()=>{var Y;return(Y=is.current)==null?void 0:Y.focus()},100))},[o,s]),m.useEffect(()=>{se.current&&(se.current.scrollTop=se.current.scrollHeight)},[C]),m.useEffect(()=>{i==="docker"&&P==="existing"&&D.requestDockerContainersList()},[i,P]);const os=r=>{if(r.trim())return Object.fromEntries(r.trim().split(`
|
|
8
|
+
`).map(N=>N.trim()).filter(N=>N&&N.includes("=")).map(N=>{const w=N.indexOf("=");return[N.slice(0,w),N.slice(w+1)]}))},Ws=r=>{r.preventDefault();const N={name:t,type:i,style:b,color:T||void 0,position:x||(s==null?void 0:s.position)||{x:0,z:0},cwd:$||void 0,folderPath:E||void 0,commands:Z?void 0:{start:K||void 0,stop:H||void 0,restart:d||void 0,healthCheck:q||void 0,logs:k||void 0},pm2:Z?{enabled:!0,script:Ge,args:Ye||void 0,interpreter:Je||void 0,interpreterArgs:We||void 0,env:os(Ze)}:void 0,docker:i==="docker"?{enabled:!0,mode:P,image:P==="container"?Qe:void 0,containerName:P==="container"&&he?he:P==="existing"&&me?me:void 0,ports:P==="container"&&be.length>0?be:void 0,volumes:P==="container"&&ge.length>0?ge:void 0,env:os(Xe),network:P==="container"&&Ne?Ne:void 0,command:P==="container"&&ye?ye:void 0,restart:P==="container"?es:void 0,pull:P!=="existing"?ss:void 0,composePath:P==="compose"&&Pe?Pe:void 0,composeProject:P==="compose"&&Ee?Ee:void 0,services:P==="compose"&&ze?ze.split(",").map(w=>w.trim()).filter(w=>w):void 0}:void 0,urls:M.length>0?M:void 0,scale:W!==1?W:void 0,subordinateBuildingIds:i==="boss"&&Ae.length>0?Ae:void 0,database:i==="database"&&Re.length>0?{connections:Re,activeConnectionId:as}:void 0,terminal:i==="terminal"?{enabled:!0,shell:ts||void 0,port:Me?parseInt(Me,10):void 0,saveSession:ns||void 0,args:ls||void 0}:void 0};a&&u?D.updateBuilding(u,N):D.createBuilding(N),p()},Zs=()=>{ce(!0)},Qs=()=>{u&&(D.deleteBuilding(u),ce(!1),p())},ae=r=>{u&&(D.sendBuildingCommand(u,r),r==="logs"&&U(!0))},Xs=()=>{l([...M,{label:"",url:""}])},ea=r=>{l(M.filter((N,w)=>w!==r))},rs=(r,N,w)=>{const G=[...M];G[r]={...G[r],[N]:w},l(G)},{handleMouseDown:sa,handleClick:aa}=da(p);if(!o)return null;const cs=u?D.getBuildingLogs(u):[];return e.jsxs("div",{className:"modal-overlay visible",onMouseDown:sa,onClick:aa,children:[e.jsxs("div",{className:"modal building-config-modal",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("span",{children:n(a?"config:buildings.editBuilding":"config:buildings.addBuilding")}),a&&s&&e.jsx("span",{className:"building-status-badge",style:{backgroundColor:qe[s.status]},children:s.status})]}),e.jsxs("form",{onSubmit:Ws,children:[e.jsxs("div",{className:"modal-body",children:[e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("common:labels.name")}),e.jsx("input",{ref:is,type:"text",className:"form-input",value:t,onChange:r=>c(r.target.value),placeholder:n("config:buildings.namePlaceholder"),required:!0})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("common:labels.type")}),e.jsx("div",{className:"building-type-selector",children:Object.keys(Ks).map(r=>e.jsxs("button",{type:"button",className:`building-type-btn ${i===r?"active":""}`,onClick:()=>{f(r),r==="database"&&b==="server-rack"&&z("filing-cabinet"),r==="tests"&&b==="server-rack"&&z("dome"),r==="http"&&b==="server-rack"&&z("satellite")},title:Ks[r].description,children:[e.jsx("span",{className:"building-type-icon",children:e.jsx(F,{name:Us(r),size:16})}),e.jsx("span",{className:"building-type-name",children:r})]},r))})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("config:buildings.style")}),e.jsx("div",{className:"building-style-selector",children:Object.keys(Ue).map(r=>e.jsxs("button",{type:"button",className:`building-style-btn ${b===r?"active":""}`,onClick:()=>z(r),title:Ue[r].description,children:[e.jsx("span",{className:"building-style-preview","data-style":r}),e.jsx("span",{className:"building-style-name",children:Ue[r].label})]},r))})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("common:labels.color")}),e.jsxs("div",{className:"building-color-selector",children:[ma.map(r=>e.jsx("button",{type:"button",className:`building-color-btn ${T===r.value?"active":""}`,onClick:()=>B(r.value),title:ua(r.labelKey),style:r.value?{backgroundColor:r.value}:void 0,children:!r.value&&e.jsx("span",{className:"color-default-icon",children:e.jsx(F,{name:"gear",size:12})})},r.value||"default")),e.jsx("input",{type:"color",className:"building-color-picker",value:T||"#2a2a3a",onChange:r=>B(r.target.value),title:"Custom color"})]})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("common:labels.size")}),e.jsxs("div",{className:"building-size-control",children:[e.jsxs("div",{className:"size-slider-row",children:[e.jsx("input",{type:"range",className:"size-slider",min:"0",max:"100",step:"1",value:Math.log(W/.1)/Math.log(100)*100,onChange:r=>{const N=parseFloat(r.target.value),w=.1*Math.pow(100,N/100);ee(Math.round(w*100)/100)}}),e.jsxs("span",{className:"size-value",children:[W.toFixed(2),"x"]})]}),e.jsx("div",{className:"size-presets",children:[.5,.75,1,1.25,1.5,2].map(r=>e.jsxs("button",{type:"button",className:`size-preset-btn ${W===r?"active":""}`,onClick:()=>ee(r),children:[r,"x"]},r))})]})]}),e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("config:buildings.directory")}),e.jsx(X,{value:$,onChange:R,placeholder:"/path/to/project",className:"form-input",directoriesOnly:!0})]}),i==="folder"&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:n("config:buildings.folderPath")}),e.jsx(X,{value:E,onChange:J,placeholder:"/path/to/folder",className:"form-input",directoriesOnly:!0}),e.jsx("div",{className:"form-hint",children:"Click this building to open the file explorer at this path"})]}),i==="tests"&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:"Tests Folder"}),e.jsx(X,{value:E,onChange:J,placeholder:"/path/to/project/src/test",className:"form-input",directoriesOnly:!0}),e.jsx("div",{className:"form-hint",children:"Click this building to browse, search and run the tests of this folder (any folder inside a Maven module works)"})]}),i==="http"&&e.jsxs("div",{className:"form-section",children:[e.jsx("label",{className:"form-label",children:"Requests Folder"}),e.jsx(X,{value:E,onChange:J,placeholder:"/path/to/project/http-requests",className:"form-input",directoriesOnly:!0}),e.jsx("div",{className:"form-hint",children:"Click this building to browse and fire the .http request files of this folder (IntelliJ HTTP Client style; http-client.env.json environments supported)"})]}),i==="boss"&&e.jsx(fa,{buildings:y,buildingId:u,subordinateBuildingIds:Ae,setSubordinateBuildingIds:Te,isEditMode:a,showBossLogs:Gs,setShowBossLogs:Ys,currentBossLogs:h,bossLogsContainerRef:Js}),i==="database"&&e.jsx(va,{dbConnections:Re,setDbConnections:Ie,activeDbConnectionId:as,setActiveDbConnectionId:Oe}),i==="server"&&e.jsx(xa,{usePM2:Z,setUsePM2:te}),i==="server"&&e.jsx(ba,{usePM2:Z,pm2Script:Ge,setPm2Script:ne,pm2Args:Ye,setPm2Args:le,pm2Interpreter:Je,setPm2Interpreter:ie,pm2InterpreterArgs:We,setPm2InterpreterArgs:oe,pm2Env:Ze,setPm2Env:re,isEditMode:a,building:s??null,handleCommand:ae}),i==="docker"&&e.jsx(ja,{dockerMode:P,setDockerMode:de,dockerImage:Qe,setDockerImage:pe,dockerContainerName:he,setDockerContainerName:xe,dockerCommand:ye,setDockerCommand:Ce,dockerPorts:be,setDockerPorts:je,dockerVolumes:ge,setDockerVolumes:ve,dockerNetwork:Ne,setDockerNetwork:ke,dockerRestart:es,setDockerRestart:Se,dockerPull:ss,setDockerPull:we,dockerEnv:Xe,setDockerEnv:fe,dockerComposePath:Pe,setDockerComposePath:De,dockerComposeProject:Ee,setDockerComposeProject:Le,dockerComposeServices:ze,setDockerComposeServices:Be,selectedExistingContainer:me,setSelectedExistingContainer:ue,dockerContainersList:v,isEditMode:a,building:s??null,handleCommand:ae}),i==="terminal"&&e.jsx(ya,{terminalShell:ts,setTerminalShell:_e,terminalPort:Me,setTerminalPort:Fe,terminalSaveSession:ns,setTerminalSaveSession:$e,terminalArgs:ls,setTerminalArgs:Ke,isEditMode:a,building:s??null,handleCommand:ae,onOpenTerminal:()=>{s!=null&&s.id&&window.dispatchEvent(new CustomEvent("tide:open-iframe-modal",{detail:{buildingId:s.id}}))},onOpenBelow:r=>{window.dispatchEvent(new CustomEvent("tide:open-bottom-terminal",{detail:{buildingId:r}}))}}),i==="server"&&!Z&&e.jsx(Na,{startCmd:K,setStartCmd:I,stopCmd:H,setStopCmd:O,restartCmd:d,setRestartCmd:L,healthCheckCmd:q,setHealthCheckCmd:V,logsCmd:k,setLogsCmd:_,isEditMode:a,handleCommand:ae}),e.jsxs("div",{className:"form-section",children:[e.jsxs("label",{className:"form-label",children:[n("config:buildings.links"),e.jsxs("button",{type:"button",className:"btn btn-sm btn-add",onClick:Xs,children:["+ ",n("common:buttons.add")]})]}),M.map((r,N)=>e.jsxs("div",{className:"url-row",children:[e.jsx("input",{type:"text",className:"form-input url-label",value:r.label,onChange:w=>rs(N,"label",w.target.value),placeholder:"Label"}),e.jsx("input",{type:"text",className:"form-input url-value",value:r.url,onChange:w=>rs(N,"url",w.target.value),placeholder:"https://..."}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>ea(N),children:"x"})]},N))]}),a&&S&&cs.length>0&&e.jsx(Ca,{logs:cs,buildingId:u,logsContainerRef:se})]}),e.jsxs("div",{className:"modal-footer",children:[a&&e.jsx("button",{type:"button",className:"btn btn-danger",onClick:Zs,children:n("common:buttons.delete")}),e.jsx("div",{className:"footer-spacer"}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:p,children:n("common:buttons.cancel")}),e.jsx("button",{type:"submit",className:"btn btn-primary",children:n(a?"common:buttons.save":"common:buttons.create")})]})]})]}),Vs&&s&&e.jsx(ha,{buildingName:s.name,onClose:()=>ce(!1),onConfirm:Qs})]})}export{Da as BuildingConfigModal};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as At,k as yt,aC as Et,a5 as xt,m as Ct,cy as Mt,cz as Ft,aT as wt,r as d,$ as St,S as pe,cA as Bt,cB as fe,s as V,cC as vt,j as f,I as ne,cD as Ve,cE as It,a9 as _t,cF as Dt,cG as kt,cH as Ee,aq as ve,_ as Rt,v as nt,u as Fe,cI as Je}from"./main-B0UlZnfk.js";import{cJ as Ls,cK as $s,cL as js,cM as Ns,cN as Ps}from"./main-B0UlZnfk.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function re(t){return Array.isArray?Array.isArray(t):ct(t)==="[object Array]"}function bt(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Tt(t){return t==null?"":bt(t)}function Z(t){return typeof t=="string"}function rt(t){return typeof t=="number"}function Lt(t){return t===!0||t===!1||$t(t)&&ct(t)=="[object Boolean]"}function it(t){return typeof t=="object"}function $t(t){return it(t)&&t!==null}function G(t){return t!=null}function Ie(t){return!t.trim().length}function ct(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const jt="Incorrect 'index' type",Nt=t=>`Invalid value for key ${t}`,Pt=t=>`Pattern length exceeds max of ${t}.`,Kt=t=>`Missing ${t} property in key`,Ot=t=>`Property 'weight' in key '${t}' must be a positive integer`,Xe=Object.prototype.hasOwnProperty;class zt{constructor(e){this._keys=[],this._keyMap={};let n=0;e.forEach(r=>{let i=ot(r);this._keys.push(i),this._keyMap[i.id]=i,n+=i.weight}),this._keys.forEach(r=>{r.weight/=n})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function ot(t){let e=null,n=null,r=null,i=1,c=null;if(Z(t)||re(t))r=t,e=qe(t),n=_e(t);else{if(!Xe.call(t,"name"))throw new Error(Kt("name"));const o=t.name;if(r=o,Xe.call(t,"weight")&&(i=t.weight,i<=0))throw new Error(Ot(o));e=qe(o),n=_e(o),c=t.getFn}return{path:e,id:n,weight:i,src:r,getFn:c}}function qe(t){return re(t)?t:t.split(".")}function _e(t){return re(t)?t.join("."):t}function Gt(t,e){let n=[],r=!1;const i=(c,o,a)=>{if(G(c))if(!o[a])n.push(c);else{let u=o[a];const l=c[u];if(!G(l))return;if(a===o.length-1&&(Z(l)||rt(l)||Lt(l)))n.push(Tt(l));else if(re(l)){r=!0;for(let h=0,E=l.length;h<E;h+=1)i(l[h],o,a+1)}else o.length&&i(l,o,a+1)}};return i(t,Z(e)?e.split("."):e,0),r?n:n[0]}const Qt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Wt={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},Ht={location:0,threshold:.6,distance:100},Ut={useExtendedSearch:!1,getFn:Gt,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var y={...Wt,...Qt,...Ht,...Ut};const Yt=/[^ ]+/g;function Vt(t=1,e=3){const n=new Map,r=Math.pow(10,e);return{get(i){const c=i.match(Yt).length;if(n.has(c))return n.get(c);const o=1/Math.pow(c,.5*t),a=parseFloat(Math.round(o*r)/r);return n.set(c,a),a},clear(){n.clear()}}}class Le{constructor({getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){this.norm=Vt(n,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((n,r)=>{this._keysMap[n.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,Z(this.docs[0])?this.docs.forEach((e,n)=>{this._addString(e,n)}):this.docs.forEach((e,n)=>{this._addObject(e,n)}),this.norm.clear())}add(e){const n=this.size();Z(e)?this._addString(e,n):this._addObject(e,n)}removeAt(e){this.records.splice(e,1);for(let n=e,r=this.size();n<r;n+=1)this.records[n].i-=1}getValueForItemAtKeyId(e,n){return e[this._keysMap[n]]}size(){return this.records.length}_addString(e,n){if(!G(e)||Ie(e))return;let r={v:e,i:n,n:this.norm.get(e)};this.records.push(r)}_addObject(e,n){let r={i:n,$:{}};this.keys.forEach((i,c)=>{let o=i.getFn?i.getFn(e):this.getFn(e,i.path);if(G(o)){if(re(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(G(h))if(Z(h)&&!Ie(h)){let E={v:h,i:l,n:this.norm.get(h)};a.push(E)}else re(h)&&h.forEach((E,x)=>{u.push({nestedArrIndex:x,value:E})})}r.$[c]=a}else if(Z(o)&&!Ie(o)){let a={v:o,n:this.norm.get(o)};r.$[c]=a}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function at(t,e,{getFn:n=y.getFn,fieldNormWeight:r=y.fieldNormWeight}={}){const i=new Le({getFn:n,fieldNormWeight:r});return i.setKeys(t.map(ot)),i.setSources(e),i.create(),i}function Jt(t,{getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){const{keys:r,records:i}=t,c=new Le({getFn:e,fieldNormWeight:n});return c.setKeys(r),c.setIndexRecords(i),c}function xe(t,{errors:e=0,currentLocation:n=0,expectedLocation:r=0,distance:i=y.distance,ignoreLocation:c=y.ignoreLocation}={}){const o=e/t.length;if(c)return o;const a=Math.abs(r-n);return i?o+a/i:a?1:o}function Xt(t=[],e=y.minMatchCharLength){let n=[],r=-1,i=-1,c=0;for(let o=t.length;c<o;c+=1){let a=t[c];a&&r===-1?r=c:!a&&r!==-1&&(i=c-1,i-r+1>=e&&n.push([r,i]),r=-1)}return t[c-1]&&c-r>=e&&n.push([r,c-1]),n}const le=32;function qt(t,e,n,{location:r=y.location,distance:i=y.distance,threshold:c=y.threshold,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,includeMatches:u=y.includeMatches,ignoreLocation:l=y.ignoreLocation}={}){if(e.length>le)throw new Error(Pt(le));const h=e.length,E=t.length,x=Math.max(0,Math.min(r,E));let g=c,m=x;const S=a>1||u,w=S?Array(E):[];let T;for(;(T=t.indexOf(e,m))>-1;){let $=xe(e,{currentLocation:T,expectedLocation:x,distance:i,ignoreLocation:l});if(g=Math.min($,g),m=T+h,S){let N=0;for(;N<h;)w[T+N]=1,N+=1}}m=-1;let j=[],Q=1,W=h+E;const oe=1<<h-1;for(let $=0;$<h;$+=1){let N=0,D=W;for(;N<D;)xe(e,{errors:$,currentLocation:x+D,expectedLocation:x,distance:i,ignoreLocation:l})<=g?N=D:W=D,D=Math.floor((W-N)/2+N);W=D;let ae=Math.max(1,x-D+1),H=o?E:Math.min(x+D,E)+h,B=Array(H+2);B[H+1]=(1<<$)-1;for(let R=H;R>=ae;R-=1){let X=R-1,O=n[t.charAt(X)];if(S&&(w[X]=+!!O),B[R]=(B[R+1]<<1|1)&O,$&&(B[R]|=(j[R+1]|j[R])<<1|1|j[R+1]),B[R]&oe&&(Q=xe(e,{errors:$,currentLocation:X,expectedLocation:x,distance:i,ignoreLocation:l}),Q<=g)){if(g=Q,m=X,m<=x)break;ae=Math.max(1,2*x-m)}}if(xe(e,{errors:$+1,currentLocation:x,expectedLocation:x,distance:i,ignoreLocation:l})>g)break;j=B}const ie={isMatch:m>=0,score:Math.max(.001,Q)};if(S){const $=Xt(w,a);$.length?u&&(ie.indices=$):ie.isMatch=!1}return ie}function Zt(t){let e={};for(let n=0,r=t.length;n<r;n+=1){const i=t.charAt(n);e[i]=(e[i]||0)|1<<r-n-1}return e}const Ce=String.prototype.normalize?(t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(t=>t);class ut{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:i=y.distance,includeMatches:c=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){if(this.options={location:n,threshold:r,distance:i,includeMatches:c,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h},e=u?e:e.toLowerCase(),e=l?Ce(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const E=(g,m)=>{this.chunks.push({pattern:g,alphabet:Zt(g),startIndex:m})},x=this.pattern.length;if(x>le){let g=0;const m=x%le,S=x-m;for(;g<S;)E(this.pattern.substr(g,le),g),g+=le;if(m){const w=x-le;E(this.pattern.substr(w),w)}}else E(this.pattern,0)}searchIn(e){const{isCaseSensitive:n,ignoreDiacritics:r,includeMatches:i}=this.options;if(e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern===e){let S={isMatch:!0,score:0};return i&&(S.indices=[[0,e.length-1]]),S}const{location:c,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let E=[],x=0,g=!1;this.chunks.forEach(({pattern:S,alphabet:w,startIndex:T})=>{const{isMatch:j,score:Q,indices:W}=qt(e,S,w,{location:c+T,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:i,ignoreLocation:h});j&&(g=!0),x+=Q,j&&W&&(E=[...E,...W])});let m={isMatch:g,score:g?x/this.chunks.length:1};return g&&i&&(m.indices=E),m}}class ce{constructor(e){this.pattern=e}static isMultiMatch(e){return Ze(e,this.multiRegex)}static isSingleMatch(e){return Ze(e,this.singleRegex)}search(){}}function Ze(t,e){const n=t.match(e);return n?n[1]:null}class es extends ce{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const n=e===this.pattern;return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ts extends ce{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const r=e.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}}class ss extends ce{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const n=e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ns extends ce{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const n=!e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class rs extends ce{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const n=e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class is extends ce{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const n=!e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class lt extends ce{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:i=y.distance,includeMatches:c=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){super(e),this._bitapSearch=new ut(e,{location:n,threshold:r,distance:i,includeMatches:c,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class ht extends ce{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let n=0,r;const i=[],c=this.pattern.length;for(;(r=e.indexOf(this.pattern,n))>-1;)n=r+c,i.push([r,n-1]);const o=!!i.length;return{isMatch:o,score:o?0:1,indices:i}}}const De=[es,ht,ss,ns,is,rs,ts,lt],et=De.length,cs=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,os="|";function as(t,e={}){return t.split(os).map(n=>{let r=n.trim().split(cs).filter(c=>c&&!!c.trim()),i=[];for(let c=0,o=r.length;c<o;c+=1){const a=r[c];let u=!1,l=-1;for(;!u&&++l<et;){const h=De[l];let E=h.isMultiMatch(a);E&&(i.push(new h(E,e)),u=!0)}if(!u)for(l=-1;++l<et;){const h=De[l];let E=h.isSingleMatch(a);if(E){i.push(new h(E,e));break}}}return i})}const us=new Set([lt.type,ht.type]);class ls{constructor(e,{isCaseSensitive:n=y.isCaseSensitive,ignoreDiacritics:r=y.ignoreDiacritics,includeMatches:i=y.includeMatches,minMatchCharLength:c=y.minMatchCharLength,ignoreLocation:o=y.ignoreLocation,findAllMatches:a=y.findAllMatches,location:u=y.location,threshold:l=y.threshold,distance:h=y.distance}={}){this.query=null,this.options={isCaseSensitive:n,ignoreDiacritics:r,includeMatches:i,minMatchCharLength:c,findAllMatches:a,ignoreLocation:o,location:u,threshold:l,distance:h},e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern=e,this.query=as(this.pattern,this.options)}static condition(e,n){return n.useExtendedSearch}searchIn(e){const n=this.query;if(!n)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:i,ignoreDiacritics:c}=this.options;e=i?e:e.toLowerCase(),e=c?Ce(e):e;let o=0,a=[],u=0;for(let l=0,h=n.length;l<h;l+=1){const E=n[l];a.length=0,o=0;for(let x=0,g=E.length;x<g;x+=1){const m=E[x],{isMatch:S,indices:w,score:T}=m.search(e);if(S){if(o+=1,u+=T,r){const j=m.constructor.type;us.has(j)?a=[...a,...w]:a.push(w)}}else{u=0,o=0,a.length=0;break}}if(o){let x={isMatch:!0,score:u/o};return r&&(x.indices=a),x}}return{isMatch:!1,score:1}}}const ke=[];function hs(...t){ke.push(...t)}function Re(t,e){for(let n=0,r=ke.length;n<r;n+=1){let i=ke[n];if(i.condition(t,e))return new i(t,e)}return new ut(t,e)}const Me={AND:"$and",OR:"$or"},be={PATH:"$path",PATTERN:"$val"},Te=t=>!!(t[Me.AND]||t[Me.OR]),ds=t=>!!t[be.PATH],fs=t=>!re(t)&&it(t)&&!Te(t),tt=t=>({[Me.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function dt(t,e,{auto:n=!0}={}){const r=i=>{let c=Object.keys(i);const o=ds(i);if(!o&&c.length>1&&!Te(i))return r(tt(i));if(fs(i)){const u=o?i[be.PATH]:c[0],l=o?i[be.PATTERN]:i[u];if(!Z(l))throw new Error(Nt(u));const h={keyId:_e(u),pattern:l};return n&&(h.searcher=Re(l,e)),h}let a={children:[],operator:c[0]};return c.forEach(u=>{const l=i[u];re(l)&&l.forEach(h=>{a.children.push(r(h))})}),a};return Te(t)||(t=tt(t)),r(t)}function gs(t,{ignoreFieldNorm:e=y.ignoreFieldNorm}){t.forEach(n=>{let r=1;n.matches.forEach(({key:i,norm:c,score:o})=>{const a=i?i.weight:null;r*=Math.pow(o===0&&a?Number.EPSILON:o,(a||1)*(e?1:c))}),n.score=r})}function ps(t,e){const n=t.matches;e.matches=[],G(n)&&n.forEach(r=>{if(!G(r.indices)||!r.indices.length)return;const{indices:i,value:c}=r;let o={indices:i,value:c};r.key&&(o.key=r.key.src),r.idx>-1&&(o.refIndex=r.idx),e.matches.push(o)})}function ms(t,e){e.score=t.score}function As(t,e,{includeMatches:n=y.includeMatches,includeScore:r=y.includeScore}={}){const i=[];return n&&i.push(ps),r&&i.push(ms),t.map(c=>{const{idx:o}=c,a={item:e[o],refIndex:o};return i.length&&i.forEach(u=>{u(c,a)}),a})}class q{constructor(e,n={},r){this.options={...y,...n},this.options.useExtendedSearch,this._keyStore=new zt(this.options.keys),this.setCollection(e,r)}setCollection(e,n){if(this._docs=e,n&&!(n instanceof Le))throw new Error(jt);this._myIndex=n||at(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){G(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const n=[];for(let r=0,i=this._docs.length;r<i;r+=1){const c=this._docs[r];e(c,r)&&(this.removeAt(r),r-=1,i-=1,n.push(c))}return n}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:n=-1}={}){const{includeMatches:r,includeScore:i,shouldSort:c,sortFn:o,ignoreFieldNorm:a}=this.options;let u=Z(e)?Z(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return gs(u,{ignoreFieldNorm:a}),c&&u.sort(o),rt(n)&&n>-1&&(u=u.slice(0,n)),As(u,this._docs,{includeMatches:r,includeScore:i})}_searchStringList(e){const n=Re(e,this.options),{records:r}=this._myIndex,i=[];return r.forEach(({v:c,i:o,n:a})=>{if(!G(c))return;const{isMatch:u,score:l,indices:h}=n.searchIn(c);u&&i.push({item:c,idx:o,matches:[{score:l,value:c,norm:a,indices:h}]})}),i}_searchLogical(e){const n=dt(e,this.options),r=(a,u,l)=>{if(!a.children){const{keyId:E,searcher:x}=a,g=this._findMatches({key:this._keyStore.get(E),value:this._myIndex.getValueForItemAtKeyId(u,E),searcher:x});return g&&g.length?[{idx:l,item:u,matches:g}]:[]}const h=[];for(let E=0,x=a.children.length;E<x;E+=1){const g=a.children[E],m=r(g,u,l);if(m.length)h.push(...m);else if(a.operator===Me.AND)return[]}return h},i=this._myIndex.records,c={},o=[];return i.forEach(({$:a,i:u})=>{if(G(a)){let l=r(n,a,u);l.length&&(c[u]||(c[u]={idx:u,item:a,matches:[]},o.push(c[u])),l.forEach(({matches:h})=>{c[u].matches.push(...h)}))}}),o}_searchObjectList(e){const n=Re(e,this.options),{keys:r,records:i}=this._myIndex,c=[];return i.forEach(({$:o,i:a})=>{if(!G(o))return;let u=[];r.forEach((l,h)=>{u.push(...this._findMatches({key:l,value:o[h],searcher:n}))}),u.length&&c.push({idx:a,item:o,matches:u})}),c}_findMatches({key:e,value:n,searcher:r}){if(!G(n))return[];let i=[];if(re(n))n.forEach(({v:c,i:o,n:a})=>{if(!G(c))return;const{isMatch:u,score:l,indices:h}=r.searchIn(c);u&&i.push({score:l,key:e,value:c,idx:o,norm:a,indices:h})});else{const{v:c,n:o}=n,{isMatch:a,score:u,indices:l}=r.searchIn(c);a&&i.push({score:u,key:e,value:c,norm:o,indices:l})}return i}}q.version="7.1.0";q.createIndex=at;q.parseIndex=Jt;q.config=y;q.parseQuery=dt;hs(ls);async function ys(t){const e=new URLSearchParams({q:t}),n=await At(yt(`/api/folders/search?${e.toString()}`));if(!n.ok){const i=await n.json().catch(()=>({}));throw new Error(i.error||`Failed to search folders: ${n.statusText}`)}const r=await n.json();return Array.isArray(r.folders)?r.folders:[]}const Es=["command","agent","building","area","folder","modified-file"],xs=2;function Cs(){const t=nt(pe.SPOTLIGHT_TAB,"all");return fe.includes(t)?t:"all"}function st(){return Rt(pe.SPOTLIGHT_QUERY,"")}function Ms(){const t=nt(pe.AOP_CONFIG,{});return t.sortMode==="name"||t.sortMode==="status"||t.sortMode==="recent"?t.sortMode:"recent"}function Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:i,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=Et(),E=xt(),x=Ct(),g=Mt(),m=Ft(),S=wt(),w=d.useRef(e);w.current=e;const T=d.useRef(n);T.current=n;const j=d.useRef(r);j.current=r;const Q=d.useRef(i);Q.current=i;const W=d.useRef(c);W.current=c;const oe=d.useRef(o);oe.current=o;const ie=d.useRef(a);ie.current=a;const $=d.useRef(u);$.current=u;const N=d.useRef(l);N.current=l;const[D,ae]=d.useState(st),[H,B]=d.useState(0),[M,R]=d.useState(Cs),[X,O]=d.useState([]),ft=d.useCallback(s=>{ae(s),St(pe.SPOTLIGHT_QUERY,s)},[]);d.useEffect(()=>{t&&(ae(st()),B(0))},[t]),d.useEffect(()=>{if(!t){O([]);return}const s=D.trim();if(s.length<xs){O([]);return}let p=!1;const C=setTimeout(()=>{ys(s).then(F=>{p||O(F)}).catch(()=>{p||O([])})},250);return()=>{p=!0,clearTimeout(C)}},[t,D]);const we=d.useCallback(s=>{R(s),Bt(pe.SPOTLIGHT_TAB,s)},[]),$e=d.useRef(M);$e.current=M;const gt=d.useCallback(s=>{const p=fe.indexOf($e.current),C=fe[(p+s+fe.length)%fe.length];we(C)},[we]);d.useEffect(()=>{B(0)},[M]);const Se=V.getShortcuts(),ge=d.useMemo(()=>t?vt():{},[t]),me=d.useMemo(()=>{if(!t)return[];const s=Se.find(C=>C.id==="spawn-agent"),p=Se.find(C=>C.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:s?Ve(s):"Alt+N",icon:f.jsx(ne,{name:"plus",size:16}),action:()=>{w.current(),T.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:p!=null&&p.key?Ve(p):"Tab",icon:f.jsx(ne,{name:"dashboard",size:16}),action:()=>{w.current(),j.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:f.jsx(ne,{name:"gear",size:16}),action:()=>{w.current(),Q.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:f.jsx(ne,{name:"chart-line",size:16}),action:()=>{var C;w.current(),(C=N.current)==null||C.call(N)}}]},[t,Se]),he=d.useMemo(()=>t?Array.from(h.values()).map(s=>{const p=(g||[]).filter(Y=>Y.agentId===s.id).map(Y=>Y.filePath),C=[...new Set(p)],F=C.map(Y=>Y.split("/").pop()||Y),v=[];s.lastAssignedTask&&v.push(s.lastAssignedTask);const L=`${s.class} • ${s.cwd}`;let k=`${s.name} ${s.class} ${s.status} ${s.cwd}`;s.taskLabel&&(k+=` ${s.taskLabel}`),F.length>0&&(k+=` ${F.join(" ")} ${C.join(" ")}`),v.length>0&&(k+=` ${v.join(" ")}`);const P=Date.now()-s.lastActivity;let U;return s.lastAssignedTask&&(s.lastAssignedTask.length>150?U=s.lastAssignedTask.slice(0,150)+"...":U=s.lastAssignedTask),{id:`agent-${s.id}`,type:"agent",title:s.name,subtitle:L,lastUserInput:U,timeAway:P,icon:f.jsx(_t,{agent:s,size:20}),_searchText:k,_modifiedFiles:C,_userQueries:v,_agentId:s.id,_lastActivity:s.lastActivity,_taskLabel:s.taskLabel,_status:s.status,action:()=>{w.current(),It(s.id),V.selectAgent(s.id),V.getState().viewMode!=="flat"&&V.requestTerminalExpand()}}}):[],[t,h,g]),Ae=d.useMemo(()=>t?Array.from(E.values()).map(s=>{var p;return{id:`area-${s.id}`,type:"area",title:s.name,subtitle:`${s.assignedAgentIds.length} agents • ${((p=s.directories)==null?void 0:p.length)||0} folders`,icon:f.jsx(ne,{name:"map",size:16}),action:()=>{w.current(),V.selectArea(s.id)}}}):[],[t,E]),je=d.useMemo(()=>{const s=new Map;for(const p of he)p._agentId&&s.set(p._agentId,p);return s},[he]),Ne=d.useMemo(()=>{const s=new Map;if(!t)return s;for(const p of h.values()){const C=V.getAreaForAgent(p.id);if(!C||C.archived)continue;const F=s.get(C.id);F?F.push(p):s.set(C.id,[p])}return s},[t,h,E]),Pe=d.useMemo(()=>{const s=new Map;for(const p of m)s.has(p.agentId)||s.set(p.agentId,p.timestamp);return s},[m]),Be=d.useMemo(()=>{if(!t)return[];const s=D.trim().toLowerCase(),p=Dt({sortMode:Ms(),agentsWithUnseenOutput:S,getLatestToolTimestamp:v=>Pe.get(v)}),C=Array.from(E.values()).filter(v=>!v.archived).filter(v=>s?v.name.toLowerCase().includes(s):!0).sort((v,L)=>v.name.localeCompare(L.name,void 0,{sensitivity:"base"})),F=[];for(const v of C){const k=(Ne.get(v.id)||[]).slice().sort(p).map(P=>je.get(P.id)).filter(P=>!!P);!s&&k.length===0||F.push({areaId:v.id,areaName:v.name,areaColor:v.color,agents:k})}return F},[t,D,E,Ne,je,S,Pe]),ye=d.useMemo(()=>t?Array.from(x.values()).filter(s=>s.type==="server"||s.type==="boss"||s.type==="database"||s.type==="tests").map(s=>{var P,U,Y,ue,ee;const p=s.status==="running"?"#4ade80":s.status==="stopped"?"#f87171":"#facc15",C=s.type==="boss"?"crown":s.type==="database"?"database":s.type==="tests"?"flask":"desktop",F=s.type==="boss"?"Boss":s.type==="database"?"Database":s.type==="tests"?"Tests":"Server";let v=`${F} • ${s.status}`;if(s.type==="database"&&((U=(P=s.database)==null?void 0:P.connections)!=null&&U.length)){const z=s.database.connections[0];v+=` • ${z.engine} @ ${z.host}`}else s.type==="tests"&&s.folderPath?v=`${F} • ${s.folderPath}`:s.cwd&&(v+=` • ${s.cwd}`);const L=((Y=s.pm2Status)==null?void 0:Y.ports)||[];let k=`${s.name} ${s.type} ${s.status} ${s.cwd||""} ${((ue=s.pm2)==null?void 0:ue.name)||""}`;if(s.type==="tests"&&(k+=` ${s.folderPath||""} tests junit maven`),L.length>0&&(k+=` ${L.join(" ")}`),s.type==="database"&&((ee=s.database)!=null&&ee.connections))for(const z of s.database.connections)k+=` ${z.name} ${z.engine} ${z.host} ${z.database||""} mysql postgresql sql`;return{id:`building-${s.id}`,type:"building",title:s.name,subtitle:v,_ports:L,icon:f.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[f.jsx(ne,{name:"status-pending",size:10,weight:"fill",color:p}),f.jsx(ne,{name:C,size:16})]}),_searchText:k,action:()=>{var z;w.current(),s.type==="boss"?ie.current(s.id):s.type==="database"?$.current(s.id):s.type==="tests"?V.openTestsBuilding(s.id):s.type==="http"?V.openHttpBuilding(s.id):(z=s.pm2)!=null&&z.enabled&&oe.current(s.id)}}}):[],[t,x]),Ke=d.useMemo(()=>{if(!t)return[];const s=g||[],p=new Set,C=[];for(const F of s){if(p.has(F.filePath))continue;p.add(F.filePath);const v=F.filePath.split("/").pop()||F.filePath,L=F.action==="created"?"Created":F.action==="modified"?"Modified":F.action==="deleted"?"Deleted":"Read";if(C.push({id:`modified-${F.filePath}-${F.timestamp}`,type:"modified-file",title:v,subtitle:`${L} by ${F.agentName} • ${F.filePath}`,matchedText:F.filePath,icon:F.action==="deleted"?f.jsx(ne,{name:"trash",size:16}):kt(F.filePath),action:()=>{w.current();const k=Array.from(V.getState().areas.values());for(const P of k)for(const U of P.directories||[])if(F.filePath.startsWith(U)){V.setFileViewerPath(F.filePath),W.current(P.id);return}V.selectAgent(F.agentId)}}),C.length>=50)break}return C},[t,g]),Oe=d.useMemo(()=>t?X.map(s=>{const p=s.isGitRepo&&s.gitBranch?`${s.path} • ${s.gitBranch}`:s.path;return{id:`folder-${s.path}`,type:"folder",title:s.name,subtitle:p,matchedText:s.path,icon:f.jsx(ne,{name:s.isGitRepo?"git-branch":"folder",size:16}),_searchText:`${s.name} ${s.path}`,_isGitRepo:s.isGitRepo,_gitBranch:s.gitBranch,action:()=>{w.current(),V.openFileExplorer(s.path)}}}):[],[t,X]),ze=d.useMemo(()=>new q(he,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[he]),Ge=d.useMemo(()=>new q(me,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[me]),Qe=d.useMemo(()=>new q(Ae,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[Ae]),We=d.useMemo(()=>new q(Ke,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[Ke]),He=d.useMemo(()=>new q(ye,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ye]),de=d.useMemo(()=>{if(!D.trim()){const A=[];A.push(...ye);const I=[...he].sort((b,K)=>{const te=Ee(b._agentId,b._lastActivity,ge);return Ee(K._agentId,K._lastActivity,ge)-te});A.push(...I),A.push(...me.slice(0,2)),A.push(...Ae.slice(0,2));const _={};return Es.forEach((b,K)=>{_[b]=K}),A.sort((b,K)=>(_[b.type]??999)-(_[K.type]??999)),A}const s=D.trim().toLowerCase(),p=ze.search(D).slice(0,8),C=Ge.search(D).slice(0,3),F=Qe.search(D).slice(0,2),v=We.search(D).slice(0,3),L=Oe.slice(0,8),k=He.search(D).filter(A=>{const I=A.score??1;return`${A.item.title} ${A.item.subtitle||""} ${A.item._searchText||""}`.toLowerCase().includes(s)||I<=.2}).slice(0,4),P={agent:6,building:5,folder:4,command:3,area:2,"modified-file":1},U=A=>{if(!s)return 1;const I=A.title.toLowerCase();return I===s?6:I.startsWith(s)?5:I.split(/[^a-z0-9]+/i).includes(s)?4:I.includes(s)?3:`${A.subtitle||""} ${A._searchText||""} ${A.matchedText||""}`.toLowerCase().includes(s)?2:1},Y=(A,I)=>{const _=(1-Math.min(1,I??1))*4;return U(A)*100+(P[A.type]??0)*5+_},ue=new Map,ee=(A,I)=>{const _=ue.get(A.type),b={item:A,score:Y(A,I)};_?_.push(b):ue.set(A.type,[b])};for(const A of p){const I={...A.item};if(I._modifiedFiles&&I._modifiedFiles.length>0){const _=I._modifiedFiles.filter(b=>{var se;const K=((se=b.split("/").pop())==null?void 0:se.toLowerCase())||"",te=b.toLowerCase();return K.includes(s)||te.includes(s)});_.length>0&&(I.matchedFiles=_)}if(I._userQueries&&I._userQueries.length>0){const _=I._userQueries.find(b=>b.toLowerCase().includes(s));if(_)if(_.length>200){const K=_.toLowerCase().indexOf(s),te=Math.max(0,K-60),se=Math.min(_.length,K+s.length+100);I.matchedQuery=(te>0?"...":"")+_.slice(te,se)+(se<_.length?"...":"")}else I.matchedQuery=_}ee(I,A.score)}for(const A of k)ee(A.item,A.score);for(const A of C)ee(A.item,A.score);for(const A of F)ee(A.item,A.score);for(const A of v)ee(A.item,A.score);for(const A of L)ee(A,void 0);for(const[A,I]of ue)A==="agent"?I.sort((_,b)=>{const K=U(_.item),te=U(b.item);if(te!==K)return te-K;const se=Ee(_.item._agentId,_.item._lastActivity,ge),Ye=Ee(b.item._agentId,b.item._lastActivity,ge);return Ye!==se?Ye-se:b.score-_.score}):I.sort((_,b)=>b.score-_.score);const z=A=>A.reduce((I,_)=>Math.max(I,_.score),-1),Ue=[];return Array.from(ue.values()).sort((A,I)=>z(I)-z(A)).forEach(A=>{for(const I of A)Ue.push(I.item)}),Ue},[D,ze,Ge,Qe,We,He,me,he,Ae,ye,Oe,ge]),J=d.useMemo(()=>{switch(M){case"agents":return de.filter(s=>s.type==="agent");case"buildings":return de.filter(s=>s.type==="building");case"commands":return de.filter(s=>s.type==="command");case"folders":return de.filter(s=>s.type==="folder");case"areas":return Be.flatMap(s=>s.agents);case"all":default:return de}},[M,de,Be]);d.useEffect(()=>{H>=J.length&&B(Math.max(0,J.length-1))},[J.length,H]);const pt=d.useCallback(s=>{if(s.altKey&&!s.ctrlKey&&!s.metaKey&&(s.key==="p"||s.key==="n"||s.key==="P"||s.key==="N")){s.preventDefault(),s.stopPropagation(),s.nativeEvent.stopImmediatePropagation();const p=s.key.toLowerCase();B(p==="p"?C=>C>0?C-1:J.length-1:C=>C<J.length-1?C+1:0);return}switch(s.key){case"Escape":s.preventDefault(),w.current();break;case"ArrowUp":s.preventDefault(),B(p=>p>0?p-1:J.length-1);break;case"ArrowDown":s.preventDefault(),B(p=>p<J.length-1?p+1:0);break;case"Enter":s.preventDefault(),J[H]&&J[H].action();break}},[J,H]),mt=d.useCallback((s,p)=>{if(!p||!s)return s;const C=s.toLowerCase(),F=p.toLowerCase(),v=[];let L=0,k=C.indexOf(F),P=0;for(;k!==-1;)k>L&&v.push(s.slice(L,k)),v.push(ve.createElement("mark",{key:P++,className:"spotlight-highlight"},s.slice(k,k+p.length))),L=k+p.length,k=C.indexOf(F,L);return L<s.length&&v.push(s.slice(L)),v.length>0?ve.createElement(ve.Fragment,null,...v):s},[]);return{query:D,setQuery:ft,selectedIndex:H,setSelectedIndex:B,results:J,activeTab:M,setActiveTab:we,cycleTab:gt,areaSections:Be,handleKeyDown:pt,highlightMatch:mt}}const ws=d.forwardRef(function({query:e,onQueryChange:n,onKeyDown:r,onResetSelection:i},c){const{t:o}=Fe(["common"]);return f.jsxs("div",{className:"spotlight-input-wrapper",children:[f.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),f.jsx("input",{ref:c,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:a=>{n(a.target.value),i()},onKeyDown:r,autoFocus:!0,spellCheck:!1}),f.jsxs("div",{className:"spotlight-input-hints",children:[f.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Ss=d.memo(function({activeTab:e,onSelect:n}){const{t:r}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-tabs",role:"tablist","aria-label":r("terminal:spotlight.tabsLabel"),children:[fe.map(i=>f.jsx("button",{type:"button",role:"tab","aria-selected":i===e,tabIndex:-1,className:`spotlight-tab${i===e?" active":""}`,onClick:()=>n(i),children:r(`terminal:spotlight.tabs.${i}`)},i)),f.jsx("span",{className:"spotlight-tabs-hint",children:f.jsx("kbd",{children:"Tab"})})]})}),Bs=d.forwardRef(function({results:e,selectedIndex:n,query:r,activeTab:i,areaSections:c,highlightMatch:o,onSelectIndex:a},u){const{t:l}=Fe(["terminal"]),h=d.useRef(!1);d.useEffect(()=>{h.current=!1},[e]),d.useEffect(()=>{const g=typeof u=="function"?null:u==null?void 0:u.current;if(!g)return;const m=()=>{h.current=!0};return g.addEventListener("mousemove",m),()=>{g.removeEventListener("mousemove",m)}},[u,e]);const E={command:l("terminal:spotlight.categories.commands"),agent:l("terminal:spotlight.categories.agents"),building:l("terminal:spotlight.categories.infrastructure"),area:l("terminal:spotlight.categories.areas"),folder:l("terminal:spotlight.categories.folders"),"modified-file":l("terminal:spotlight.categories.modifiedFiles")},x=d.useMemo(()=>{const g=[];let m=null,S=[];return e.forEach((w,T)=>{w.type!==m&&(m!==null&&S.length>0&&g.push([m,S]),m=w.type,S=[]),S.push({result:w,index:T})}),m!==null&&S.length>0&&g.push([m,S]),g},[e]);if(d.useEffect(()=>{if(!u||typeof u=="function")return;const g=u.current;if(!g)return;const m=g.querySelector(".spotlight-item.selected");m&&m.scrollIntoView({block:"nearest",behavior:"smooth"})},[n,u]),i==="areas"){if(c.length===0)return f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})});let g=0;return f.jsx("div",{className:"spotlight-results",ref:u,children:c.map(m=>f.jsxs("div",{children:[f.jsxs("div",{className:"spotlight-category-header spotlight-area-section-header",children:[f.jsx("span",{className:"spotlight-area-dot",style:{background:m.areaColor},"aria-hidden":"true"}),f.jsx("span",{className:"spotlight-area-name",children:m.areaName}),f.jsx("span",{className:"spotlight-area-count",children:m.agents.length})]}),m.agents.length===0?f.jsx("div",{className:"spotlight-area-empty",children:l("terminal:spotlight.noAgentsInArea")}):m.agents.map(S=>{const w=g++;return f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id)})]},m.areaId))})}return e.length===0?f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})}):f.jsx("div",{className:"spotlight-results",ref:u,children:x.map(([g,m])=>f.jsxs("div",{children:[x.length>1&&f.jsx("div",{className:"spotlight-category-header",children:E[g]||g}),m.map(({result:S,index:w})=>f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id))]},g))})}),vs=d.memo(function(){const{t:e}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-footer",children:[f.jsxs("div",{className:"spotlight-footer-left",children:[f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"↑"}),f.jsx("kbd",{children:"↓"})," ",f.jsx("kbd",{children:"Alt+N"}),f.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Tab"})," ",e("terminal:spotlight.switchTabs")]})]}),f.jsx("div",{className:"spotlight-footer-right",children:f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),Is=768;function Rs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:i,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=d.useRef(null),E=d.useRef(null),x=d.useRef(null),g=d.useRef(0),{query:m,setQuery:S,selectedIndex:w,setSelectedIndex:T,results:j,activeTab:Q,setActiveTab:W,cycleTab:oe,areaSections:ie,handleKeyDown:$,highlightMatch:N}=Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:i,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});g.current=j.length;const D=d.useRef(oe);D.current=oe,d.useEffect(()=>{t&&setTimeout(()=>{var B,M;(B=h.current)==null||B.focus(),(M=h.current)==null||M.select()},50)},[t]),d.useEffect(()=>{if(!t)return;const B=window.visualViewport;if(!B||window.innerWidth>Is)return;const M=()=>{const R=E.current;R&&(R.style.height=`${B.height}px`,R.style.top=`${B.offsetTop}px`)};return M(),B.addEventListener("resize",M),B.addEventListener("scroll",M),()=>{B.removeEventListener("resize",M),B.removeEventListener("scroll",M);const R=E.current;R&&(R.style.height="",R.style.top="")}},[t]),d.useEffect(()=>{if(!t)return;const B=M=>{if(M.key==="Escape"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),e();return}if(M.key==="Tab"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),D.current(M.shiftKey?-1:1);return}if(M.altKey&&!M.ctrlKey&&!M.metaKey&&(M.key==="n"||M.key==="p"||M.key==="N"||M.key==="P")){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation();const R=M.key.toLowerCase(),X=g.current;T(R==="p"?O=>O>0?O-1:X-1:O=>O<X-1?O+1:0);return}};return window.addEventListener("keydown",B,{capture:!0}),()=>{window.removeEventListener("keydown",B,{capture:!0})}},[t,e]);const ae=d.useCallback(B=>{B.target===B.currentTarget&&e()},[e]),H=d.useCallback(()=>{T(0)},[T]);return t?f.jsx("div",{ref:E,className:"spotlight-overlay",onClick:ae,children:f.jsxs("div",{className:"spotlight-modal",children:[f.jsx(ws,{ref:h,query:m,onQueryChange:S,onKeyDown:$,onResetSelection:H}),f.jsx(Ss,{activeTab:Q,onSelect:W}),f.jsx(Bs,{ref:x,results:j,selectedIndex:w,query:m,activeTab:Q,areaSections:ie,highlightMatch:N,onSelectIndex:T}),f.jsx(vs,{})]})}):null}export{Ls as FILE_ICON_NAMES,Rs as Spotlight,vs as SpotlightFooter,ws as SpotlightInput,Je as SpotlightItem,Bs as SpotlightResults,$s as formatDuration,js as formatRelativeTime,Ns as getAgentIcon,kt as getFileIconFromPath,Ps as getTypeLabel,Fs as useSpotlightSearch};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{bW as He,r as t,s as I,k as ye,bX as Ee,i as Oe,j as e,I as O,u as fe,bY as ze,Z as Te,bZ as Be,b_ as Ue,q as We,b$ as Ke,c0 as De,c1 as Ve,ak as Ge,al as qe,am as Ye,bj as Je,_ as Me,S as le,bc as Xe,b9 as Ze,a9 as Qe,$ as Ie,aC as et,a5 as tt,c2 as st,t as X,c3 as nt}from"./main-B0UlZnfk.js";import{FileExplorerPanel as at}from"./index-BZ4wZwRu.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Se={status:"all",activity:"all",sort:"activity"},ct={"1h":3600*1e3,"6h":360*60*1e3,"24h":1440*60*1e3},Ae=20,me=3,lt={idle:"#4aff9e",working:"#4a9eff",waiting:"#ff9e4a",waiting_permission:"#ffcc00",error:"#ff4a4a",offline:"#888888",orphaned:"#ff9e4a"},ot=12e4;function rt(s){return s.trim().replace(/\r\n/g,`
|
|
2
|
+
`)}function $e(s,a){return`${s}:${rt(a)}`}function it(s,a,c,f){if(s.uuid&&a.has(s.uuid))return!1;if(s.uuid)return!0;const p=s.isUserPrompt?"user":"assistant",d=$e(p,s.text),M=s.timestamp||0,A=c.get(d);return A!==void 0&&Math.abs(M-A)<=ot?!1:M>f}function dt({isOpen:s,agents:a}){const c=He(),[f,p]=t.useState(new Map),d=t.useRef(new Set);t.useRef(a);const M=t.useMemo(()=>Array.from(a.keys()).sort().join(","),[a]),A=t.useMemo(()=>Array.from(a.values()).map(j=>`${j.id}:${j.sessionId||""}`).sort().join(","),[a]);t.useEffect(()=>{s||(d.current.clear(),p(new Map))},[s]),t.useEffect(()=>{if(!s)return;const j=new Set(Array.from(a.keys()));for(const i of d.current)j.has(i)||d.current.delete(i);let h=null;c>0&&(h=I.preserveOutputs(),d.current.clear());const v=async(i,k,F=0)=>{if(d.current.add(i.id),F>0&&await new Promise(x=>setTimeout(x,F)),p(x=>{const N=new Map(x);return N.set(i.id,{agentId:i.id,messages:[],loading:!0,hasMore:!1,totalCount:0}),N}),!i.sessionId){k&&k.length>0&&I.mergeOutputsWithHistory(i.id,[],k),p(x=>{const N=new Map(x);return N.set(i.id,{agentId:i.id,messages:[],loading:!1,hasMore:!1,totalCount:0}),N});return}try{const N=await(await Oe(ye(`/api/agents/${i.id}/history?limit=${Ee}&offset=0`))).json(),P=N.messages||[],K=P.length>0?Math.max(...P.map(w=>w.timestamp?new Date(w.timestamp).getTime():0)):0,Y=new Set(P.map(w=>w.uuid).filter(w=>!!w)),V=new Map;for(const w of P){if(w.type!=="user"&&w.type!=="assistant")continue;const o=$e(w.type,w.content),L=w.timestamp?new Date(w.timestamp).getTime():0,W=V.get(o)??0;L>W&&V.set(o,L)}const G=I.getOutputs(i.id),U=(k&&k.length>0?[...k,...G]:G).filter(w=>it(w,Y,V,K));I.clearOutputs(i.id);for(const w of U)I.addOutput(i.id,w);p(w=>{const o=new Map(w);return o.set(i.id,{agentId:i.id,messages:P,loading:!1,hasMore:N.hasMore||!1,totalCount:N.totalCount||0}),o})}catch(x){if(console.error(`Failed to load history for ${i.name}:`,x),k&&k.length>0){I.clearOutputs(i.id);for(const N of k)I.addOutput(i.id,N)}p(N=>{const P=new Map(N);return P.set(i.id,{agentId:i.id,messages:[],loading:!1,hasMore:!1,totalCount:0}),P})}},u=c>0?500:0,D=Array.from(a.values());for(const i of D)if(!d.current.has(i.id)){const k=h==null?void 0:h.get(i.id);v(i,k,u)}},[s,M,A,c]);const R=t.useRef(a),b=t.useRef(f);R.current=a,b.current=f;const C=t.useCallback(async j=>{const h=R.current.get(j),v=b.current.get(j);if(!(h!=null&&h.sessionId)||!v||!v.hasMore)return;const u=v.messages.length;try{const i=await(await fetch(ye(`/api/agents/${j}/history?limit=${Ee}&offset=${u}`))).json();i.messages&&i.messages.length>0&&p(k=>{const F=new Map(k),x=k.get(j);return x&&F.set(j,{...x,messages:[...i.messages,...x.messages],hasMore:i.hasMore||!1}),F})}catch(D){console.error(`Failed to load more history for agent ${j}:`,D)}},[]),E=t.useCallback(j=>{d.current.delete(j),p(h=>{const v=new Map(h),u=h.get(j);return u&&v.set(j,{...u,messages:[],hasMore:!1,totalCount:0,loading:!1}),v})},[]);return{histories:f,loadMoreHistory:C,clearAgentHistory:E}}function ut({command:s,onCommandChange:a,useTextarea:c,forceTextarea:f,onForceTextarea:p,onSend:d,canSend:M,attachedFiles:A,onAddFile:R,onRemoveFile:b,uploadFile:C,onAddPastedText:E,placeholder:j="Message...",className:h="",compact:v=!1,inputRef:u}){const D=t.useRef(null),i=t.useRef(null),k=t.useRef(c);t.useEffect(()=>{if(c&&!k.current&&i.current){const o=i.current;o.focus(),o.selectionStart=o.selectionEnd=o.value.length}k.current=c},[c]),t.useEffect(()=>{const o=i.current;if(!o||!c)return;o.style.height="auto";const L=v?120:180,W=Math.min(o.scrollHeight,L);o.style.height=`${W}px`},[s,c,v]);const F=t.useCallback(async o=>{const L=o.clipboardData.items;for(const z of L)if(z.type.startsWith("image/")){o.preventDefault();const $=z.getAsFile();if($){const _=await C($);_&&R(_)}return}const W=o.clipboardData.files;if(W.length>0){o.preventDefault();for(const z of W){const $=await C(z);$&&R($)}return}const B=o.clipboardData.getData("text"),te=(B.match(/\n/g)||[]).length+1;if(te>5){o.preventDefault();const $=`[Pasted text #${E(B)} +${te} lines]`,_=o.target,se=_.selectionStart||0,ae=_.selectionEnd||0,ne=s.slice(0,se)+$+s.slice(ae);a(ne),c||p(!0)}},[s,a,c,p,C,R,E]),x=t.useCallback(async o=>{const L=o.target.files;if(L){for(const W of L){const B=await C(W);B&&R(B)}D.current&&(D.current.value="")}},[C,R]),N=t.useCallback(o=>{if(o.key==="Enter"&&o.shiftKey){c||(o.preventDefault(),p(!0));return}o.key==="Enter"&&(o.preventDefault(),d())},[c,p,d]),P=t.useCallback(o=>{},[]),K=t.useCallback(o=>{o.button===1&&(o.preventDefault(),o.stopPropagation())},[]),Y=t.useCallback(o=>{i.current=o,u==null||u(o)},[u]),V=v?"agent-panel-input":"guake-input",G=v?"agent-panel-input-container":"guake-input-container",Z=v?"agent-panel-attach-btn":"guake-attach-btn",U=v?"agent-panel-send-btn":"",w=c?v?"agent-panel-input-expanded":"guake-input-expanded":"";return e.jsxs(e.Fragment,{children:[A.length>0&&e.jsx("div",{className:v?"agent-panel-attachments":"guake-attachments",children:A.map(o=>e.jsxs("div",{className:`${v?"agent-panel-attachment":"guake-attachment"} ${o.isImage?"is-image":""}`,children:[e.jsx("span",{className:v?"agent-panel-attachment-icon":"guake-attachment-icon",children:e.jsx(O,{name:o.isImage?"file":"paperclip",size:12})}),e.jsx("span",{className:v?"agent-panel-attachment-name":"guake-attachment-name",title:o.path,children:o.name}),!v&&e.jsxs("span",{className:"guake-attachment-size",children:["(",Math.round(o.size/1024),"KB)"]}),e.jsx("button",{className:v?"agent-panel-attachment-remove":"guake-attachment-remove",onClick:()=>b(o.id),title:"Remove",children:"×"})]},o.id))}),e.jsxs("div",{className:`${V} ${w} ${h}`,children:[e.jsx("input",{ref:D,type:"file",multiple:!0,onChange:x,style:{display:"none"},accept:"*"}),e.jsxs("div",{className:G,onAuxClick:K,children:[e.jsx("button",{className:Z,onClick:()=>{var o;return(o=D.current)==null?void 0:o.click()},title:"Attach file (or paste image)",children:e.jsx(O,{name:"paperclip",size:14})}),c?e.jsx("textarea",{ref:Y,placeholder:j,value:s,onChange:o=>a(o.target.value),onKeyDown:N,onPaste:F,onMouseDown:P}):e.jsx("input",{ref:u,type:"text",placeholder:j,value:s,onChange:o=>a(o.target.value),onKeyDown:N,onPaste:F,onMouseDown:P}),e.jsx("button",{className:U,onClick:d,disabled:!M,title:"Send",children:e.jsx(O,{name:"send",size:14})})]})]})]})}function mt(s){const a=Math.floor(s/1e3),c=Math.floor(a/60),f=a%60;return`${c}:${f.toString().padStart(2,"0")}`}const ft=t.memo(function({agentId:a,isWorking:c,timestamp:f}){const{t:p}=fe(["terminal"]),[d,M]=t.useState(0);return t.useEffect(()=>{if(!c||!f){M(0);return}M(Date.now()-f);const A=setInterval(()=>{M(Date.now()-f)},1e3);return()=>clearInterval(A)},[c,f]),c?e.jsxs("div",{className:"guake-stop-bar",children:[e.jsx("span",{className:"guake-elapsed-timer",children:mt(d)}),e.jsxs("button",{className:"guake-stop-btn",onClick:()=>I.stopAgent(a),title:p("terminal:input.stopOperation"),children:[e.jsx("span",{className:"stop-icon",children:e.jsx(O,{name:"stop",size:12,weight:"fill"})}),e.jsx("span",{className:"stop-label",children:p("terminal:input.stop")})]})]}):null});function pt({agent:s,history:a,outputs:c,isExpanded:f,isFocused:p,advancedView:d,onExpand:M,onFocus:A,inputRef:R,onLoadMore:b,onClearHistory:C}){const{t:E}=fe(["terminal","common"]),j=ze(s.id),h=t.useRef(null),[v,u]=t.useState(!1),D=t.useRef(0),i=t.useRef(!1),[k,F]=t.useState(!0),[x,N]=t.useState(!1),[P,K]=t.useState(null),[Y,V]=t.useState(null),[G,Z]=t.useState(null);Te(`commander-image-modal-${s.id}`,P!==null,()=>K(null));const{command:U,setCommand:w,forceTextarea:o,setForceTextarea:L,useTextarea:W,setPastedTexts:B,incrementPastedCount:te,resetPastedCount:z,attachedFiles:$,setAttachedFiles:_,removeAttachedFile:se,uploadFile:ae,expandPastedTexts:ne}=Be({selectedAgentId:s.id}),ce=U.trim().length>0||$.length>0,n=Ue({outputs:c,viewMode:d?"advanced":"simple"}),l=t.useMemo(()=>{const S=We(s);return{usedPercent:S.usedPercent,freePercent:S.freePercent,hasData:!!s.contextStats,totalTokens:S.totalTokens,contextWindow:S.contextWindow}},[s.contextStats,s.contextUsed,s.contextLimit]),g=t.useCallback(()=>{!v&&(a!=null&&a.hasMore)&&b&&(u(!0),D.current=h.current?h.current.scrollHeight-h.current.scrollTop:0,b())},[v,a==null?void 0:a.hasMore,b]);t.useEffect(()=>{v&&a&&!a.loading&&u(!1)},[a,v]);const m=t.useCallback(()=>{i.current=!0,F(!1)},[]),T=t.useRef(f),Q=t.useRef(p);t.useEffect(()=>{(f&&!T.current||p&&!Q.current)&&(i.current=!1,F(!0),N(!0)),T.current=f,Q.current=p},[f,p]);const ee=t.useRef(a==null?void 0:a.loading);t.useEffect(()=>{ee.current&&!(a!=null&&a.loading)&&(i.current=!1,F(!0),N(!0)),ee.current=a==null?void 0:a.loading},[a==null?void 0:a.loading]),t.useEffect(()=>{if(!x)return;const S=h.current;if(!S)return;const y=performance.now();let H=0,ue=-1,be;const Re=()=>{const{scrollTop:Fe,scrollHeight:Ne,clientHeight:Le}=S,_e=Ne-Fe-Le<=2;if(Math.abs(Ne-ue)<=1&&_e?H+=1:H=0,ue=Ne,H>=3){N(!1);return}if(performance.now()-y>5e3){N(!1);return}be=requestAnimationFrame(Re)};return be=requestAnimationFrame(Re),()=>cancelAnimationFrame(be)},[x]),t.useEffect(()=>{i.current||F(!0)},[n.length]);const q=t.useCallback(()=>!1,[]),ie=t.useCallback(S=>{const y=te();return B(H=>new Map(H).set(y,S)),y},[te,B]),he=t.useCallback(S=>{_(y=>[...y,S])},[_]),xe=t.useCallback(()=>{if(!ce)return;if(U.trim()==="/clear"&&$.length===0){I.clearContext(s.id),C(),w(""),L(!1),B(new Map),_([]),z();return}let S=ne(U.trim());if($.length>0){const y=$.map(H=>H.isImage?`[Image: ${H.path}]`:`[File: ${H.path}]`).join(`
|
|
3
|
+
`);S=S?`${S}
|
|
4
|
+
|
|
5
|
+
${y}`:y}I.sendCommand(s.id,S),w(""),L(!1),B(new Map),_([]),z()},[s.id,U,ce,$,ne,C,z,w,L,B,_]),ge=t.useCallback((S,y)=>{K({url:S,name:y})},[]),ve=t.useCallback((S,y)=>{const H=Ke(S,s.cwd),ue=H.line?{...y||{},targetLine:H.line}:y;I.setFileViewerPath(H.path,ue,s.cwd)},[s.cwd]),je=t.useCallback((S,y)=>{V({command:S,output:y,isLive:y==="Running..."})},[]),we=t.useCallback(S=>{Z(S)},[]),Ce=t.useCallback(()=>{N(!1),i.current=!0,F(!1)},[]),ke=t.useCallback(()=>K(null),[]),r=t.useCallback(()=>V(null),[]),J=t.useCallback(()=>Z(null),[]),de=t.useCallback(S=>{S.stopPropagation(),M()},[M]),oe=lt[s.status]||"#888888",re=(a==null?void 0:a.messages)||[];return e.jsxs("div",{className:`agent-panel ${s.status==="working"?"working":""} ${f?"expanded":""} ${p?"focused":""}`,onClick:p?void 0:A,children:[e.jsxs("div",{className:"agent-panel-header",onClick:p?A:void 0,children:[e.jsxs("div",{className:"agent-panel-info",children:[e.jsx("span",{className:"agent-panel-status",style:{background:oe},title:s.status}),e.jsxs("span",{className:"agent-panel-name",children:[(s.isBoss||s.class==="boss")&&e.jsx("span",{className:"agent-panel-boss-crown",children:e.jsx(O,{name:"crown",size:14})}),s.name]}),e.jsx("span",{className:`agent-panel-status-label ${s.status}`,children:s.status}),e.jsx("span",{className:"agent-panel-class",children:s.class}),e.jsx("span",{className:`agent-panel-provider ${s.provider==="codex"?"codex":s.provider==="opencode"?"opencode":s.provider==="grok"?"grok":"claude"}`,children:s.provider||"claude"}),e.jsxs("span",{className:"agent-panel-id",title:`ID: ${s.id}`,children:["[",s.id.substring(0,4),"]"]}),s.taskLabel?e.jsxs("div",{className:"agent-panel-task agent-panel-task-label",title:s.taskLabel,children:[e.jsx(O,{name:"task",size:12})," ",s.taskLabel]}):s.currentTask?e.jsxs("div",{className:"agent-panel-task",title:s.currentTask,children:[s.currentTask.substring(0,40),"..."]}):null]}),e.jsxs("div",{className:"agent-panel-context",title:`Context: ${Math.round(l.usedPercent)}% used (${De(l.totalTokens)} / ${De(l.contextWindow)})`,children:[e.jsx("div",{className:"agent-panel-context-bar",style:{background:l.freePercent<20?"#ff4a4a":l.freePercent<50?"#ff9e4a":"#4aff9e",width:`${l.freePercent}%`}}),e.jsxs("span",{className:"agent-panel-context-text",children:[Math.round(l.freePercent),"%"]})]}),e.jsx("div",{className:"agent-panel-actions",children:e.jsx("button",{className:"agent-panel-expand",onClick:de,title:E(f?"commander.collapsePanel":"commander.expandPanel"),children:f?e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("polyline",{points:"4 14 10 14 10 20"}),e.jsx("polyline",{points:"20 10 14 10 14 4"}),e.jsx("line",{x1:"14",y1:"10",x2:"21",y2:"3"}),e.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]}):e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("polyline",{points:"15 3 21 3 21 9"}),e.jsx("polyline",{points:"9 21 3 21 3 15"}),e.jsx("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),e.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})})})]}),e.jsx("div",{className:"agent-panel-content",ref:h,children:a!=null&&a.loading?e.jsx("div",{className:"agent-panel-loading",children:E("common:status.loading")}):e.jsx(e.Fragment,{children:!re.length&&!n.length?e.jsxs("div",{className:"agent-panel-empty",children:[E("commander.noMessages"),!s.sessionId&&e.jsx("div",{style:{fontSize:"10px",color:"#666"},children:E("commander.noSessionId")})]}):e.jsx(Ve,{historyMessages:re,liveOutputs:n,agentId:s.id,viewMode:d?"advanced":"simple",selectedMessageIndex:null,isMessageSelected:q,onImageClick:ge,onFileClick:ve,onBashClick:je,onViewMarkdown:we,scrollContainerRef:h,onScrollTopReached:g,isLoadingMore:v,hasMore:a==null?void 0:a.hasMore,shouldAutoScroll:k,onUserScroll:m,pinToBottom:x,onPinCancel:Ce,isLoadingHistory:a==null?void 0:a.loading})})}),e.jsxs("div",{className:`guake-input-wrapper ${s.status==="working"?"has-stop-btn is-working":""}`,children:[e.jsx(ft,{agentId:s.id,isWorking:s.status==="working",timestamp:j==null?void 0:j.timestamp}),e.jsx(ut,{command:U,onCommandChange:w,useTextarea:W,forceTextarea:o,onForceTextarea:L,onSend:xe,canSend:ce,attachedFiles:$,onAddFile:he,onRemoveFile:se,uploadFile:ae,onAddPastedText:ie,placeholder:E("commander.command",{name:s.name}),compact:!1,inputRef:R})]}),P&&e.jsx(Ge,{url:P.url,name:P.name,onClose:ke}),Y&&e.jsx(qe,{state:Y,onClose:r}),e.jsx(Ye,{agent:s,content:G,onClose:J})]})}function ht({currentArea:s,onClose:a}){const{t:c}=fe(["terminal","common"]),[f,p]=t.useState(()=>{const u=new Set(Array.from(I.getState().agents.values()).map(D=>D.name));return Je.find(D=>!u.has(D))||`Agent-${Date.now().toString(36)}`}),[d,M]=t.useState(()=>Me(le.LAST_CWD)),[A,R]=t.useState("scout"),[b,C]=t.useState("claude"),[E,j]=t.useState(!1),h=()=>{if(!f.trim()||!d.trim())return;j(!0),Ie(le.LAST_CWD,d);let u;s&&(u={x:s.center.x,z:s.center.z}),I.spawnAgent(f.trim(),A,d.trim(),u,void 0,void 0,void 0,void 0,b),setTimeout(()=>{a()},500)},v=u=>{u.key==="Enter"&&!u.shiftKey&&(u.preventDefault(),h()),u.key==="Escape"&&a()};return e.jsx("div",{className:"commander-spawn-overlay",onClick:a,children:e.jsxs("div",{className:"commander-spawn-form",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"commander-spawn-header",children:[e.jsx("h3",{children:c("spawn.addNewAgent")}),s&&e.jsxs("span",{className:"commander-spawn-area",children:[e.jsx("span",{className:"commander-spawn-area-dot",style:{background:s.color}}),s.name]})]}),e.jsxs("div",{className:"commander-spawn-body",children:[e.jsxs("div",{className:"commander-spawn-field",children:[e.jsx("label",{children:c("common:labels.name")}),e.jsx("input",{type:"text",value:f,onChange:u=>p(u.target.value),onKeyDown:v,autoFocus:!0})]}),e.jsxs("div",{className:"commander-spawn-field",children:[e.jsx("label",{children:c("common:labels.workingDirectory")}),e.jsx(Xe,{value:d,onChange:M,onSubmit:h,placeholder:c("spawn.workingDirPlaceholder"),directoriesOnly:!0})]}),e.jsxs("div",{className:"commander-spawn-field",children:[e.jsx("label",{children:c("common:labels.class")}),e.jsx("div",{className:"commander-spawn-classes",children:Ze.map(u=>e.jsxs("button",{className:`commander-spawn-class ${A===u.id?"selected":""}`,onClick:()=>R(u.id),children:[e.jsx(Qe,{classId:u.id,size:18,className:"commander-spawn-class-icon"}),e.jsx("span",{children:u.name})]},u.id))})]}),e.jsxs("div",{className:"commander-spawn-field",children:[e.jsx("label",{children:c("common:labels.runtime")}),e.jsxs("div",{className:"commander-spawn-classes",children:[e.jsxs("button",{className:`commander-spawn-class ${b==="claude"?"selected":""}`,onClick:()=>C("claude"),children:[e.jsx("span",{className:"commander-spawn-class-icon",children:e.jsx(O,{name:"brain",size:14})}),e.jsx("span",{children:"Claude"})]}),e.jsxs("button",{className:`commander-spawn-class ${b==="codex"?"selected":""}`,onClick:()=>C("codex"),children:[e.jsx("span",{className:"commander-spawn-class-icon",children:e.jsx(O,{name:"gear",size:14})}),e.jsx("span",{children:"Codex"})]}),e.jsxs("button",{className:`commander-spawn-class ${b==="opencode"?"selected":""}`,onClick:()=>C("opencode"),children:[e.jsx("span",{className:"commander-spawn-class-icon",children:e.jsx(O,{name:"status-pending",size:12,weight:"fill",color:"#4ade80"})}),e.jsx("span",{children:"OpenCode"})]}),e.jsxs("button",{className:`commander-spawn-class ${b==="grok"?"selected":""}`,onClick:()=>C("grok"),children:[e.jsx("span",{className:"commander-spawn-class-icon",children:e.jsx(O,{name:"status-pending",size:12,weight:"fill",color:"#6366f1"})}),e.jsx("span",{children:"Grok"})]})]})]})]}),e.jsxs("div",{className:"commander-spawn-footer",children:[e.jsx("button",{className:"commander-spawn-cancel",onClick:a,children:c("common:buttons.cancel")}),e.jsx("button",{className:"commander-spawn-submit",onClick:h,disabled:!f.trim()||!d.trim()||E,children:c(E?"common:buttons.deploying":"common:buttons.deploy")})]})]})})}const Pe=t.memo(function({agent:a,history:c,isExpanded:f,isFocused:p,advancedView:d,index:M,onExpand:A,onCollapse:R,onFocus:b,onInputRef:C,onLoadMore:E,onClearHistory:j}){const h=nt(a.id),v=t.useCallback(()=>{f?R():A(a.id)},[a.id,f,A,R]),u=t.useCallback(()=>{b(p?-1:M)},[M,p,b]),D=t.useCallback(F=>{C(a.id,F)},[a.id,C]),i=t.useCallback(()=>{E(a.id)},[a.id,E]),k=t.useCallback(()=>{j(a.id)},[a.id,j]);return e.jsx(pt,{agent:a,history:c,outputs:h,isExpanded:f,isFocused:p,advancedView:d,onExpand:v,onFocus:u,inputRef:D,onLoadMore:i,onClearHistory:k})});function Ct({isOpen:s,onClose:a}){const{t:c}=fe(["terminal","common"]),f=et(),p=tt(),[d,M]=t.useState(()=>Me(le.COMMANDER_TAB,"all")),[A,R]=t.useState(0),[b,C]=t.useState(null),E=t.useRef(null),[j,h]=t.useState(0),[v,u]=t.useState(!1),[D,i]=t.useState(null),[k,F]=t.useState(!1),[x,N]=t.useState(()=>{try{const n=Me(le.COMMANDER_FILTERS,"");if(n)return{...Se,...JSON.parse(n)}}catch{}return Se}),P=t.useRef(new Map),K=t.useRef([]),Y=t.useRef(0),V=t.useRef([]),G=t.useRef(d),{histories:Z,loadMoreHistory:U,clearAgentHistory:w}=dt({isOpen:s,agents:f});t.useEffect(()=>{s||(C(null),h(0),u(!1))},[s]);const o=t.useMemo(()=>{const n=Array.from(p.values()).sort((g,m)=>g.name.localeCompare(m.name)),l=[{id:"all",name:c("common:labels.all")}];for(const g of n)l.push({id:g.id,name:g.name,color:g.color});return l.push({id:"unassigned",name:c("commander.unassigned")}),l},[p]),L=t.useMemo(()=>d==="all"||d==="unassigned"?null:p.get(d)||null,[d,p]),W=t.useMemo(()=>{const n=new Map;n.set("all",f.size);let l=0;for(const g of f.values()){const m=I.getAreaForAgent(g.id);m?n.set(m.id,(n.get(m.id)||0)+1):l++}return n.set("unassigned",l),n},[f]),B=x.status!=="all"||x.activity!=="all"||x.sort!=="activity",te=(x.status!=="all"?1:0)+(x.activity!=="all"?1:0)+(x.sort!=="activity"?1:0),z=t.useMemo(()=>{const n=m=>m.isBoss===!0||m.class==="boss",l=Date.now();let g=Array.from(f.values());if(d==="unassigned"?g=g.filter(m=>!I.getAreaForAgent(m.id)):d!=="all"&&(g=g.filter(m=>{const T=I.getAreaForAgent(m.id);return(T==null?void 0:T.id)===d})),x.status!=="all"&&(g=g.filter(m=>{switch(x.status){case"working":return m.status==="working";case"idle":return m.status==="idle";case"error":return m.status==="error"||m.status==="waiting"||m.status==="waiting_permission";case"offline":return m.status==="offline"||m.status==="orphaned";default:return!0}})),x.activity!=="all"){const m=ct[x.activity];g=g.filter(T=>l-(T.lastActivity||0)<m)}return g.sort((m,T)=>{var Q,ee;if(n(m)&&!n(T))return-1;if(!n(m)&&n(T))return 1;switch(x.sort){case"activity":return(T.lastActivity||0)-(m.lastActivity||0);case"name":return m.name.localeCompare(T.name);case"created":return(m.createdAt||0)-(T.createdAt||0);case"context":{const q=((Q=m.contextStats)==null?void 0:Q.usedPercent)??(m.contextUsed||0)/(m.contextLimit||2e5)*100;return(((ee=T.contextStats)==null?void 0:ee.usedPercent)??(T.contextUsed||0)/(T.contextLimit||2e5)*100)-q}default:return(T.lastActivity||0)-(m.lastActivity||0)}}),g},[f,d,x]),$=Math.ceil(z.length/Ae),_=t.useMemo(()=>z.slice(A*Ae,(A+1)*Ae),[z,A]);K.current=_,E.current=b,Y.current=j,V.current=o,G.current=d,Te("commander-expanded",b!==null,()=>C(null));const se=st();t.useEffect(()=>{s&&se&&(C(se),I.clearCommanderExpandRequest())},[s,se]);const ae=t.useCallback(()=>C(null),[]),ne=t.useCallback(n=>C(n),[]),ce=t.useCallback(n=>h(n),[]),pe=t.useCallback((n,l)=>{l?P.current.set(n,l):P.current.delete(n)},[]);return t.useEffect(()=>{R(0),Ie(le.COMMANDER_TAB,d)},[d]),t.useEffect(()=>{Ie(le.COMMANDER_FILTERS,JSON.stringify(x)),R(0)},[x]),t.useEffect(()=>{var l;if(!s||window.matchMedia("(pointer: coarse)").matches)return;const n=b||((l=K.current[j])==null?void 0:l.id);if(n){const g=P.current.get(n);g&&document.activeElement!==g&&setTimeout(()=>g.focus(),50)}},[s,j,b]),t.useEffect(()=>{if(!s)return;const n=l=>{const g=I.getShortcuts(),m=l.target,T=m.tagName==="INPUT"||m.tagName==="TEXTAREA",Q=K.current,ee=Q.length-1,q=E.current,ie=g.find(r=>r.id==="commander-close");if(X(l,ie)){const{fileViewerPath:r,contextModalAgentId:J}=I.getState();if(r||J)return;l.preventDefault(),l.stopImmediatePropagation(),q?C(null):a();return}const he=g.find(r=>r.id==="commander-vim-left");if(X(l,he)&&!q){l.preventDefault(),h(r=>r>0?r-1:r);return}const xe=g.find(r=>r.id==="commander-vim-right");if(X(l,xe)&&!q){l.preventDefault(),h(r=>r<ee?r+1:r);return}const ge=g.find(r=>r.id==="commander-vim-up");if(X(l,ge)&&!q){l.preventDefault(),h(r=>r>=me?r-me:r);return}const ve=g.find(r=>r.id==="commander-vim-down");if(X(l,ve)&&!q){l.preventDefault(),h(r=>r+me<=ee?r+me:r);return}const je=g.find(r=>r.id==="commander-expand");if(X(l,je)){if(l.preventDefault(),q)C(null);else{const r=Q[Y.current];r&&C(r.id)}return}const we=g.find(r=>r.id==="commander-new-agent");if(X(l,we)){l.preventDefault(),u(!0);return}const Ce=g.find(r=>r.id==="commander-next-tab"),ke=g.find(r=>r.id==="commander-prev-tab");if(!T){const r=V.current;if(X(l,Ce)){const J=I.getState().latestNotificationAgentId;if(J){if(l.preventDefault(),l.stopPropagation(),!I.getState().agents.get(J)){I.setLatestNotificationAgentId(null);return}const y=I.getAreaForAgent(J);y&&r.some(H=>H.id===y.id)?M(y.id):M("unassigned"),C(J),h(0),R(0),I.setLatestNotificationAgentId(null);return}l.preventDefault(),l.stopPropagation();const oe=(r.findIndex(re=>re.id===G.current)+1)%r.length;M(r[oe].id),h(0);return}if(X(l,ke)){l.preventDefault(),l.stopPropagation();const de=(r.findIndex(oe=>oe.id===G.current)-1+r.length)%r.length;M(r[de].id),h(0);return}}};return document.addEventListener("keydown",n,!0),()=>document.removeEventListener("keydown",n,!0)},[s,a]),s?e.jsx("div",{className:"commander-overlay",onClick:a,children:e.jsxs("div",{className:"commander-view",onClick:n=>n.stopPropagation(),children:[e.jsxs("div",{className:"commander-header",children:[e.jsxs("div",{className:"commander-title-section",children:[e.jsx("h2",{className:"commander-title",children:c("commander.title")}),e.jsx("span",{className:"commander-shortcuts",children:c("commander.shortcuts")})]}),e.jsxs("div",{className:"commander-controls",children:[e.jsx("button",{className:`commander-view-toggle ${k?"active":""}`,onClick:()=>F(!k),title:c(k?"commander.simple":"commander.advanced"),children:k?e.jsxs(e.Fragment,{children:[e.jsx(O,{name:"target",size:12})," ",c("commander.advanced")]}):e.jsxs(e.Fragment,{children:[e.jsx(O,{name:"status-pending",size:12})," ",c("commander.simple")]})}),e.jsx("button",{className:"commander-add-btn",onClick:()=>u(!0),title:c("commander.addAgent"),children:c("commander.addAgent")}),e.jsx("button",{className:"commander-close",onClick:a,children:c("commander.close")})]})]}),e.jsx("div",{className:"commander-tabs",children:o.map(n=>{const l=n.id!=="all"&&n.id!=="unassigned"?p.get(n.id):null,g=l&&l.directories&&l.directories.length>0;return e.jsxs("button",{className:`commander-tab ${d===n.id?"active":""}`,onClick:()=>{M(n.id),h(0)},style:n.color?{borderBottomColor:d===n.id?n.color:"transparent"}:void 0,children:[n.color&&e.jsx("span",{className:"commander-tab-dot",style:{background:n.color}}),e.jsx("span",{children:n.name}),e.jsx("span",{className:"commander-tab-count",children:W.get(n.id)||0}),g&&e.jsx("span",{className:"commander-tab-folder",onClick:m=>{m.stopPropagation(),i(n.id)},title:c("commander.openFileExplorer"),children:e.jsx(O,{name:"folder",size:12})})]},n.id)})}),e.jsxs("div",{className:"commander-filters",children:[e.jsxs("div",{className:"commander-filter-group",children:[e.jsx("span",{className:"commander-filter-label",children:c("commander.filters.status")}),["all","working","idle","error","offline"].map(n=>e.jsx("button",{className:`commander-filter-btn ${x.status===n?"active":""}`,onClick:()=>N(l=>({...l,status:n})),children:n==="all"?c("commander.filters.all"):n==="error"?c("commander.filters.needsAttn"):n.charAt(0).toUpperCase()+n.slice(1)},n))]}),e.jsxs("div",{className:"commander-filter-group",children:[e.jsx("span",{className:"commander-filter-label",children:c("commander.filters.active")}),["all","1h","6h","24h"].map(n=>e.jsx("button",{className:`commander-filter-btn ${x.activity===n?"active":""}`,onClick:()=>N(l=>({...l,activity:n})),children:n==="all"?c("commander.filters.any"):`< ${n}`},n))]}),e.jsxs("div",{className:"commander-filter-group",children:[e.jsx("span",{className:"commander-filter-label",children:c("commander.filters.sort")}),["activity","name","created","context"].map(n=>e.jsx("button",{className:`commander-filter-btn ${x.sort===n?"active":""}`,onClick:()=>N(l=>({...l,sort:n})),children:n==="activity"?c("commander.filters.recent"):n==="context"?c("commander.filters.context"):n.charAt(0).toUpperCase()+n.slice(1)},n))]}),B&&e.jsx("button",{className:"commander-filter-clear",onClick:()=>N(Se),title:c("commander.clearFilters"),children:c("commander.filters.clearFilters",{count:te})})]}),$>1&&e.jsxs("div",{className:"commander-pagination",children:[e.jsxs("button",{className:"commander-page-btn",onClick:()=>R(n=>Math.max(0,n-1)),disabled:A===0,children:[e.jsx(O,{name:"caret-left",size:12})," ",c("commander.prev")]}),e.jsx("span",{className:"commander-page-info",children:c("commander.page",{current:A+1,total:$,count:z.length})}),e.jsxs("button",{className:"commander-page-btn",onClick:()=>R(n=>Math.min($-1,n+1)),disabled:A===$-1,children:[c("commander.next")," ",e.jsx(O,{name:"caret-right",size:12})]})]}),e.jsx("div",{className:`commander-grid ${b?"has-expanded":""}`,"data-agent-count":b?1:_.length,children:_.length===0?e.jsx("div",{className:"commander-empty",children:c(d==="all"?"commander.noAgentsAll":d==="unassigned"?"commander.noAgentsUnassigned":"commander.noAgentsArea")}):b?(()=>{const n=f.get(b);return n?e.jsx(Pe,{agent:n,history:Z.get(n.id),isExpanded:!0,isFocused:!0,advancedView:k,index:0,onExpand:ne,onCollapse:ae,onFocus:ce,onInputRef:pe,onLoadMore:U,onClearHistory:w},n.id):null})():_.map((n,l)=>e.jsx(Pe,{agent:n,history:Z.get(n.id),isExpanded:!1,isFocused:l===j,advancedView:k,index:l,onExpand:ne,onCollapse:ae,onFocus:ce,onInputRef:pe,onLoadMore:U,onClearHistory:w},n.id))}),v&&e.jsx(ht,{currentArea:L,onClose:()=>u(!1)}),D&&e.jsx(at,{isOpen:!0,areaId:D,onClose:()=>i(null),onChangeArea:n=>i(n)})]})}):null}export{Ct as CommanderView};
|