tide-commander 1.143.2 → 1.144.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/dist/assets/{BossLogsModal-sKZIHu2O.js → BossLogsModal-FhMUTJGK.js} +1 -1
  3. package/dist/assets/{BossSpawnModal-CyThCjT2.js → BossSpawnModal-CLXDwX9H.js} +1 -1
  4. package/dist/assets/{ControlsModal-Ca8RnUPB.js → ControlsModal-CW2_kaAP.js} +1 -1
  5. package/dist/assets/{DockerLogsModal-DI7RluN0.js → DockerLogsModal-D__PBcUP.js} +1 -1
  6. package/dist/assets/{EmbeddedEditor-BRRGvGeC.js → EmbeddedEditor-CXK_lzfA.js} +1 -1
  7. package/dist/assets/{GmailOAuthSetup-BJ2Bh5XV.js → GmailOAuthSetup-30XE2OWq.js} +1 -1
  8. package/dist/assets/{GoogleOAuthSetup-BF7wSPIf.js → GoogleOAuthSetup-N5vBrxOk.js} +1 -1
  9. package/dist/assets/{IframeModal-gCnVVZnP.js → IframeModal-BzReoJfL.js} +1 -1
  10. package/dist/assets/{IntegrationsPanel-6Jk7iUl5.js → IntegrationsPanel-C8SWl_KL.js} +2 -2
  11. package/dist/assets/{LogViewerModal-CFebSjnH.js → LogViewerModal-BRSu4DqY.js} +1 -1
  12. package/dist/assets/{MonitoringModal-lEBkfAzA.js → MonitoringModal-CFtfi7mX.js} +1 -1
  13. package/dist/assets/{PM2LogsModal-DKD-BadA.js → PM2LogsModal-Dlr5LSmg.js} +1 -1
  14. package/dist/assets/{RestoreArchivedAreaModal-CiFIbSij.js → RestoreArchivedAreaModal-BNlshzaM.js} +1 -1
  15. package/dist/assets/{Scene2DCanvas-T7PibG25.js → Scene2DCanvas-D83H5DB0.js} +1 -1
  16. package/dist/assets/{SceneManager-9wdDNmt6.js → SceneManager-9JzNnq6U.js} +1 -1
  17. package/dist/assets/{SkillsPanel-4BfX1C0M.js → SkillsPanel-BIBgpF4l.js} +1 -1
  18. package/dist/assets/{SlackMultiInstanceSetup-BqQXJMEA.js → SlackMultiInstanceSetup-3BN50IK7.js} +1 -1
  19. package/dist/assets/{SpawnModal-CQ1JEad-.js → SpawnModal-CILIQoGy.js} +1 -1
  20. package/dist/assets/{StatisticsModal-B6MAhWjH.js → StatisticsModal-B8E4WlPL.js} +1 -1
  21. package/dist/assets/{SubordinateAssignmentModal-CBhBxXbx.js → SubordinateAssignmentModal-CCdRRFeg.js} +1 -1
  22. package/dist/assets/{TriggerManagerPanel-BbFdcqnK.js → TriggerManagerPanel-BZjTSKom.js} +1 -1
  23. package/dist/assets/{WorkflowEditorPanel-D0wb8vqJ.js → WorkflowEditorPanel-GOjjVqdg.js} +1 -1
  24. package/dist/assets/{area-logos-BkDUE0ko.js → area-logos-CQqvtlze.js} +1 -1
  25. package/dist/assets/{index-BAJaQU48.js → index-BHQC3zTm.js} +3 -3
  26. package/dist/assets/{index-CXgJk1pj.js → index-CK4XmEu4.js} +1 -1
  27. package/dist/assets/{index-DwR2ExVD.js → index-CP3XfkK0.js} +1 -1
  28. package/dist/assets/{index-PDIZlLr0.js → index-CblWR1Bu.js} +1 -1
  29. package/dist/assets/{index-D6VMC6Va.js → index-DHyzGXFW.js} +1 -1
  30. package/dist/assets/{index-DTeysr2A.js → index-DNdUYEhU.js} +1 -1
  31. package/dist/assets/{index-DTZyzsKG.js → index-DUy4ACFd.js} +2 -2
  32. package/dist/assets/{index-BQs9yi3a.js → index-DoYz4TJz.js} +1 -1
  33. package/dist/assets/{index-D2lH7C12.js → index-UFcbzxaf.js} +1 -1
  34. package/dist/assets/{main-BYtCWmOh.js → main-C6HtzRV0.js} +7 -7
  35. package/dist/assets/{web-BrEs4l2o.js → web--6LAmL-M.js} +1 -1
  36. package/dist/assets/{web-BwWJMKpX.js → web-BtTGMld6.js} +1 -1
  37. package/dist/assets/{web-DAuj7juy.js → web-JTXJ9zZC.js} +1 -1
  38. package/dist/index.html +1 -1
  39. package/package.json +1 -1
@@ -1,2 +1,2 @@
1
- import{r as a,B as bn,E as Gt,G as sn,H as ln,j as e,J as rn,K as _n,u as Ht,L as wn,M as vn,N as jn,O as Cn,V as Nn,P as yn,U as kn,W as An,X as qt,S as E,Y as Yt,Z as Wt,_ as Kt,$ as jt,a0 as ye,a1 as Sn,s as f,a2 as on,a3 as cn,a4 as En,w as Zt,x as Jt,I as p,a5 as In,n as Mn,a6 as Tn,a7 as dn,a8 as un,a9 as Pn,aa as Ln,ab as Rn,ac as $n,ad as Dn,ae as zn,af as On,ag as Bn,ah as Fn,ai as Wn,aj as Hn,ak as Un,al as Qt,C as Vn,am as Xn,an as en,ao as Gn,ap as qn,aq as Yn,ar as Kn,as as Zn,at as Jn,au as Qn,av as ea,aw as ta,ax as na,ay as aa,az as sa,aA as ia,aB as la,aC as Ke,aD as ra,aE as oa,aF as ca,aG as da,aH as rt,aI as ua,aJ as pa,aK as ma,aL as fa,aM as ha,aN as ga,aO as xa}from"./main-BYtCWmOh.js";import{g as ba}from"./area-logos-BkDUE0ko.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function _a(u){const o=a.useRef(u);o.current=u,a.useEffect(()=>{if(!bn())return;let m=null,h=!1;return Gt.addListener("backButton",()=>{o.current()==="exit"&&Gt.exitApp()}).then(y=>{h?y.remove():m=y}),()=>{h=!0,m&&(m.remove(),m=null)}},[])}async function wa(u){const o=sn(),m=await fetch(`${ln()}/api/agents/${u}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${o}`}});if(!m.ok){const h=await m.json().catch(()=>({}));throw new Error((h==null?void 0:h.error)||`Failed to start terminal (${m.status})`)}return m.json()}async function va(u){const o=sn();await fetch(`${ln()}/api/agents/${u}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${o}`}})}const ot=new Map;function ja({agentId:u}){const[o,m]=a.useState(null),[h,y]=a.useState(null);return a.useEffect(()=>{let R=!1;const P=ot.get(u);return P&&(clearTimeout(P),ot.delete(u)),m(null),y(null),wa(u).then(z=>{R||m(z.url)}).catch(z=>{R||y(z instanceof Error?z.message:"Failed to start terminal")}),()=>{R=!0;const z=ot.get(u);z&&clearTimeout(z),ot.set(u,setTimeout(()=>{ot.delete(u),va(u)},2500))}},[u]),h?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:h})}):o?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(rn,{terminalUrl:o,visible:!0})}):e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:"Attaching to interactive session…"})})}const Ot=new Map,Ca=6e4;function Na({agentId:u,contextSummary:o}){const{t:m}=Ht(["terminal","common"]),[h,y]=a.useState(()=>{var $;return(($=Ot.get(u))==null?void 0:$.snapshot)??null}),[R,P]=a.useState(!1),[z,le]=a.useState(null),_=a.useRef(0);a.useEffect(()=>{const $=Ot.get(u);if($&&Date.now()-$.fetchedAt<Ca){y($.snapshot);return}const U=++_.current;P(!0),le(null),wn(u).then(ee=>{U===_.current&&(Ot.set(u,{snapshot:ee,fetchedAt:Date.now()}),y(ee),P(!1))}).catch(ee=>{U===_.current&&(le(ee.message||"Failed to load plan limits"),P(!1))})},[u]);const O=[];if(h!=null&&h.rateLimits){const $=[{key:"fiveHour",label:m("terminal:usage.currentSession"),window:h.rateLimits.fiveHour},{key:"sevenDay",label:m("terminal:usage.currentWeekAll"),window:h.rateLimits.sevenDay},{key:"sevenDayOpus",label:m("terminal:usage.currentWeekOpus"),window:h.rateLimits.sevenDayOpus},{key:"sevenDaySonnet",label:m("terminal:usage.currentWeekSonnet"),window:h.rateLimits.sevenDaySonnet}];for(const U of $)U.window&&O.push({...U,window:U.window})}return e.jsxs("div",{className:"plan-limits-tooltip",children:[o&&e.jsx("div",{className:"plan-limits-tooltip__context",children:o}),e.jsx("div",{className:"plan-limits-tooltip__title",children:m("terminal:usage.limits")}),R&&!h&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[m("common:status.loading"),"…"]}),!R&&z&&!h&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:m("terminal:usage.limitsError",{message:z})}),O.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:O.map(({key:$,label:U,window:ee})=>{const te=Math.max(0,Math.min(100,ee.utilization)),de=jn(te);return e.jsxs("div",{className:"plan-limits-tooltip__gauge",children:[e.jsxs("div",{className:"plan-limits-tooltip__gauge-head",children:[e.jsx("span",{className:"plan-limits-tooltip__gauge-label",children:U}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:de},children:m("terminal:usage.percentUsed",{percent:Math.round(te)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${te}%`,background:de}})}),e.jsx("div",{className:"plan-limits-tooltip__reset",children:m("terminal:usage.resets",{time:vn(ee.resetsAt)})})]},$)})}):h&&!R&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:h.rateLimitsError?m("terminal:usage.limitsError",{message:h.rateLimitsError}):h.cliHint})]})}function ya({agentId:u,disabled:o,contextSummary:m,children:h}){return e.jsx(_n,{position:"top",maxWidth:320,disabled:o,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx(Na,{agentId:u,contextSummary:m}),children:h})}const ka=a.memo(function({className:o=""}){const{t:m}=Ht(["common"]),[h,y]=Cn(),R=a.useRef(null),[P,z]=a.useState(null);a.useLayoutEffect(()=>{const _=R.current;if(!_)return;const O=_.querySelector(".view-mode-toggle__btn--active");O&&z({left:O.offsetLeft,width:O.offsetWidth})},[h]);const le=a.useCallback(_=>{if(_!==h){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:_}})),_==="3d"){requestAnimationFrame(()=>y(_));return}y(_)}},[h,y]);return e.jsxs("div",{className:`view-mode-toggle ${o}`,ref:R,children:[P&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:P.left,width:P.width}}),Nn.map(_=>e.jsxs("button",{className:`view-mode-toggle__btn ${h===_?"view-mode-toggle__btn--active":""}`,onClick:()=>le(_),title:m(`common:viewMode.descriptions.${_}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[_==="2d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]}),_==="3d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]}),_==="flat"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1"})]}),_==="dashboard"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"12",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"3",y:"16",width:"7",height:"5",rx:"1"})]})]}),e.jsx("span",{className:"view-mode-toggle__label",children:m(`common:viewMode.labels.${_}`)})]},_))]})}),Ct=3,Nt=280,tn=320,Bt=240,nn=64,Aa=["simple","chat","advanced"],Sa={simple:"Simple",chat:"Chat",advanced:"Advanced"},Ea={simple:"○",chat:"◐",advanced:"◉"},Ia={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},an="flat-clear-context",pn="tide:flat-embedded-panels";function mn(){try{const u=localStorage.getItem(pn),o=u?JSON.parse(u):{};return o&&typeof o=="object"?o:{}}catch{return{}}}function Ft(u,o){try{const m=mn();o?m[u]=o:delete m[u],localStorage.setItem(pn,JSON.stringify(m))}catch{}}function Ma(u){const o=u.split("/").filter(Boolean);return o.length===0?u:o.slice(-2).join("/")}function Ta(u){if(u.provider==="codex"){const R=u.codexModel||"gpt-5.3-codex",P=ha[R];return{model:(P==null?void 0:P.label)||R}}if(u.provider==="opencode")return{model:u.opencodeModel||"opencode"};const o=u.model||"sonnet",m=xa[o],h=u.effort,y=h?ga[h]:void 0;return{model:(m==null?void 0:m.label)||o,effort:y==null?void 0:y.label}}function Pa(u,o){if(o.type==="rectangle"&&o.width&&o.height){const m=o.width/2,h=o.height/2;return u.x>=o.center.x-m&&u.x<=o.center.x+m&&u.z>=o.center.z-h&&u.z<=o.center.z+h}if(o.type==="circle"&&o.radius){const m=u.x-o.center.x,h=u.z-o.center.z;return m*m+h*h<=o.radius*o.radius}return!1}const La=Xn.memo(function({agentId:o,terminalViewMode:m,onTerminalViewModeChange:h,inspectorOpen:y,onToggleInspector:R,onImageClick:P,onFileClick:z,onBashClick:le,onViewMarkdown:_,onRequestClearSubordinates:O,keyboard:$,canNavigateBack:U,canNavigateForward:ee,onNavigateBack:te,onNavigateForward:de,agentInfoOpen:Be,onToggleAgentInfo:Ze,onHeaderContextMenu:ct,onBuildingContextMenu:K}){var it,xt;const b=en(o),T=cn(),Je=Gn(),re=a.useRef(null),Fe=a.useRef(null),{displayedAgentId:Pe,fadingOut:Qe}=qn(o),dt=en(Pe),We=!!Je.interactiveMode&&((b==null?void 0:b.provider)??"claude")==="claude"&&!!(b!=null&&b.sessionId),[me,Le]=a.useState(!1);a.useEffect(()=>{Le(!1)},[o]),a.useEffect(()=>{!We&&me&&Le(!1)},[We,me]),a.useEffect(()=>{const n=Fe.current;if(!n)return;const r=d=>{d.button===3?(d.preventDefault(),d.stopPropagation(),te()):d.button===4&&(d.preventDefault(),d.stopPropagation(),de())},l=d=>{(d.button===3||d.button===4)&&d.preventDefault()};return n.addEventListener("mouseup",r),n.addEventListener("mousedown",l),()=>{n.removeEventListener("mouseup",r),n.removeEventListener("mousedown",l)}},[te,de]),a.useEffect(()=>{const n=Fe.current;if(!n)return;let r=0,l=0,d=0;const X=250,Q=600,I=80,Ye=1.5,Ne=ie=>{let W=ie instanceof HTMLElement?ie:null;for(;W&&W!==n;){const t=window.getComputedStyle(W).overflowX;if((t==="auto"||t==="scroll")&&W.scrollWidth>W.clientWidth)return!0;W=W.parentElement}return!1},bt=ie=>{const W=Date.now();if(W<d){ie.preventDefault();return}if(Math.abs(ie.deltaX)<=Math.abs(ie.deltaY)*Ye){r=0;return}if(Ne(ie.target)){r=0;return}W-l>X&&(r=0),l=W,r+=ie.deltaX,r<=-I?(r=0,d=W+Q,ie.preventDefault(),te()):r>=I&&(r=0,d=W+Q,ie.preventDefault(),de())};return n.addEventListener("wheel",bt,{passive:!1}),()=>n.removeEventListener("wheel",bt)},[te,de]);const et=on(),ke=a.useMemo(()=>{if(!b)return null;const n=new Set,r=[];for(const l of et.values())l.archived||l.directories.length===0||l.assignedAgentIds.includes(o)&&(n.add(l.id),r.push(l));for(const l of et.values())l.archived||l.directories.length===0||n.has(l.id)||Pa({x:b.position.x,z:b.position.z},l)&&(n.add(l.id),r.push(l));return r.length===0?null:r.flatMap(l=>l.directories.filter(d=>d&&d.trim().length>0).map(d=>({areaId:l.id,areaName:l.name,dir:d})))},[b,o,et]),{branches:Ae,fetchRemote:fe,fetchingDirs:he}=Yn(ke),He=a.useMemo(()=>{var l;const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const d of T.values())d.type==="terminal"&&f.isPositionInArea(d.position,n)&&r.push({id:d.id,name:d.name,hasUrl:!!((l=d.terminalStatus)!=null&&l.url)});return r},[o,T]),Ue=a.useMemo(()=>{var l;const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const d of T.values())d.type==="server"&&((l=d.pm2)!=null&&l.enabled)&&f.isPositionInArea(d.position,n)&&r.push({id:d.id,name:d.name});return r},[o,T]),ge=a.useMemo(()=>{const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const l of T.values())l.type==="database"&&l.database&&f.isPositionInArea(l.position,n)&&r.push({id:l.id,name:l.name});return r},[o,T]),Se=Kn(),ue=a.useMemo(()=>{const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const l of T.values())if(l.type==="tests"&&f.isPositionInArea(l.position,n)){const d=!!l.folderPath&&Se.some(X=>Zn(X,l.folderPath));r.push({id:l.id,name:l.name,working:d})}return r},[o,T,Se]),xe=a.useMemo(()=>{const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const l of T.values())l.type==="http"&&f.isPositionInArea(l.position,n)&&r.push({id:l.id,name:l.name});return r},[o,T]),[,pe]=a.useReducer(n=>n+1,0),be=((it=re.current)==null?void 0:it.search.searchMode)??!1,Ee=a.useCallback(()=>{var n;(n=re.current)==null||n.search.toggleSearch(),pe()},[]),_e=Jn(),tt=_e.isPending(an),[j,we]=a.useState(null),B=j?T.get(j.buildingId):null,[ut,Ie]=a.useState(""),[ve,yt]=a.useState(()=>Qn()),D=a.useMemo(()=>{var n;return((n=f.getAreaForAgent(o))==null?void 0:n.id)??null},[o,T]),Re=a.useCallback((n,r)=>{Ie(""),we(l=>{const d=(l==null?void 0:l.buildingId)===r?null:{type:n,buildingId:r};return D&&Ft(D,d),d})},[D]),oe=a.useCallback(()=>{Ie(""),we(null),D&&Ft(D,null)},[D]);a.useEffect(()=>{if((j==null?void 0:j.type)!=="pm2-logs")return;const n=j.buildingId;return f.startLogStreaming(n,200),()=>f.stopLogStreaming(n)},[j]);const{height:kt,onResizeStart:At}=ea(),{sidePanelWidth:St,handleSidePanelResizeStart:Et}=ta(),[$e,pt]=a.useState(()=>Wt(E.GIT_PANEL_OPEN,!1)),[je,v]=a.useState(()=>Wt(E.BUILDINGS_PANEL_OPEN,!1)),[Z,ne]=a.useState(!1),Ve=a.useCallback(()=>{ne(n=>{const r=!n;return r&&na.setEnabled(!0),r})},[]),mt=a.useCallback(()=>ne(!1),[]),It=a.useCallback(()=>{pt(n=>{const r=!n;return ye(E.GIT_PANEL_OPEN,r),r})},[]),Mt=a.useCallback(()=>{v(n=>{const r=!n;return ye(E.BUILDINGS_PANEL_OPEN,r),r})},[]),Tt=a.useCallback(()=>{pt(!1),ye(E.GIT_PANEL_OPEN,!1)},[]),Pt=a.useCallback(()=>{v(!1),ye(E.BUILDINGS_PANEL_OPEN,!1)},[]),nt=aa(),ae=a.useMemo(()=>({terminal:He,"pm2-logs":Ue,database:ge,tests:ue,http:xe}),[He,Ue,ge,ue,xe]);a.useEffect(()=>{if(!j)return;ae[j.type].some(r=>r.id===j.buildingId)||(Ie(""),we(null))},[j,ae]);const Xe=a.useRef(void 0);a.useEffect(()=>{var r;if(Xe.current===D)return;Xe.current=D;const n=D?mn()[D]:void 0;Ie(""),n&&((r=ae[n.type])!=null&&r.some(l=>l.id===n.buildingId))?we(n):we(null)},[D,ae]),a.useEffect(()=>{const n=r=>{var X;const l=r.detail;if(!(l!=null&&l.buildingId)||!(l!=null&&l.type)||!((X=ae[l.type])!=null&&X.some(Q=>Q.id===l.buildingId)))return;l.handled=!0,Ie("");const d={type:l.type,buildingId:l.buildingId};we(d),D&&Ft(D,d)};return window.addEventListener("tide:dock-building-flat",n),()=>window.removeEventListener("tide:dock-building-flat",n)},[ae,D]);const[se,Me]=a.useState(!1),J=a.useRef(null);if(a.useEffect(()=>{if(!se)return;const n=r=>{J.current&&!J.current.contains(r.target)&&Me(!1)};return document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[se]),!b)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const V=b.contextStats,at=!!V,ft=V?V.totalTokens:b.contextUsed||0,Ge=V?V.contextWindow:b.contextLimit||2e5,ht=V?V.usedPercent:Math.round(ft/Ge*100),Te=Math.max(0,Math.min(100,ht)),gt=Math.round(Te*10)/10,Lt=Math.round((100-Te)*10)/10,ce=Te>=80?"#ff4a4a":Te>=60?"#ff9e4a":Te>=40?"#ffd700":"#4aff9e",De=(ft/1e3).toFixed(1),qe=(Ge/1e3).toFixed(1),Ce=b.cwd,st=Ce?Ma(Ce):null,ze=((xt=b.subordinateIds)==null?void 0:xt.length)||0,Rt=ze>0;return e.jsxs("div",{ref:Fe,className:`flat-terminal-wrapper ${$e||je||Z?"flat-terminal-wrapper--with-side-panel":""} ${Qe?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${St}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${Be?"flat-terminal-wrapper__header-main--active":""}`,onClick:Ze,onContextMenu:n=>{n.preventDefault(),n.stopPropagation(),ct({x:n.clientX,y:n.clientY})},title:Be?"Hide agent info":"Show agent info","aria-pressed":Be,children:[e.jsx(dn,{agent:b,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:b.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:un(b.status)},children:b.status})]}),b.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:b.taskLabel,children:["📋 ",b.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:b.provider==="codex"?"/assets/codex.png":b.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:b.provider,className:"flat-terminal-wrapper__header-provider-icon",title:b.provider==="codex"?"Codex Agent":b.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:n,effort:r}=Ta(b);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:r?`Model: ${n} · Effort: ${r}`:`Model: ${n}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:n}),r&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:r})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsxs("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:[Aa.map(n=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!me&&m===n?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Le(!1),h(n)},title:Ia[n],"aria-pressed":!me&&m===n,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:Ea[n]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Sa[n]})]},n)),We&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${me?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Le(n=>!n),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":me,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:e.jsx(p,{name:"terminal",size:13})}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:"Classic TUI"})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:te,disabled:!U,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(p,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:de,disabled:!ee,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(p,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${be?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Ee,title:be?"Close search":"Search messages","aria-pressed":be,children:e.jsx(p,{name:be?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${tt?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>_e.handleClick(an,()=>{var n;f.clearContext(o),(n=re.current)==null||n.historyLoader.clearHistory()}),title:tt?"Click again to confirm clear context":"Clear context",children:e.jsx(p,{name:tt?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${$e?"flat-terminal-wrapper__action-btn--active":""}`,onClick:It,title:$e?"Hide git panel":"Show git changes","aria-pressed":$e,children:e.jsx(p,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${je?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Mt,title:je?"Hide buildings panel":"Show area buildings","aria-pressed":je,children:e.jsx(p,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:J,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${se?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>Me(n=>!n),title:"More actions","aria-expanded":se,children:"⋮"}),se&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${Z?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Ve(),Me(!1)},title:Z?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(p,{name:"bug",size:14}),e.jsx("span",{children:Z?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{f.collapseContext(o),Me(!1)},disabled:b.status!=="idle",title:b.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(p,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),Rt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{O(o,ze),Me(!1)},children:[e.jsx(p,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",ze," subordinate",ze===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{f.killAgent(o),Me(!1)},children:[e.jsx(p,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${y?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:R,title:y?"Hide inspector panel":"Show inspector panel","aria-label":y?"Hide inspector panel":"Show inspector panel","aria-pressed":y,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>f.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(p,{name:"cross",size:14})})]})]}),me&&We?e.jsx(ja,{agentId:o}):Pe&&dt?e.jsx(sa,{ref:re,agentId:Pe,agent:dt,viewMode:m,isOpen:!0,onImageClick:P,onFileClick:z,onBashClick:le,onViewMarkdown:_,keyboard:$,hasModalOpen:!1},Pe):null,j&&B&&(()=>{var X,Q;const n=j.type,r={terminal:"terminal","pm2-logs":"scroll",database:"hard-drives",tests:"flask",http:"globe"},l=n==="terminal"&&!((X=B.terminalStatus)!=null&&X.url),d=!l;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:At,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded panel"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`${B.name} panel`,style:{height:kt},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(p,{name:r[n],size:12}),e.jsx("span",{children:B.name}),l&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsxs("span",{className:"flat-bottom-panel__header-actions",children:[n==="pm2-logs"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",className:"guake-bottom-terminal-filter",value:ut,onChange:I=>Ie(I.target.value),placeholder:"Filter logs","aria-label":`Filter logs for ${B.name}`,spellCheck:!1}),e.jsx("select",{className:"guake-bottom-terminal-retention",value:ve===null?"unlimited":String(ve),onChange:I=>{const Ye=I.target.value==="unlimited"?null:Number(I.target.value);yt(Ye),la(Ye)},"aria-label":`Max log retention for ${B.name}`,children:ia.map(I=>e.jsx("option",{value:I===null?"unlimited":String(I),children:I===null?"Unlimited":`${I.toLocaleString()} lines`},I===null?"unlimited":I))}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>f.clearStreamingLogs(j.buildingId),title:"Clear logs",children:e.jsx(p,{name:"trash",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>f.sendBuildingCommand(j.buildingId,"restart"),title:"Restart",children:e.jsx(p,{name:"restart",size:12})})]}),d&&e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>{oe(),Ke(j.buildingId)},title:"Maximize — open as modal","aria-label":"Open as modal",children:e.jsx(p,{name:"fullscreen",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:oe,title:"Close panel","aria-label":"Close panel",children:e.jsx(p,{name:"cross",size:12})})]})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:n==="terminal"?(Q=B.terminalStatus)!=null&&Q.url?e.jsx(rn,{terminalUrl:B.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."}):n==="pm2-logs"?e.jsx(ra,{buildingId:j.buildingId,filterText:ut,maxRetention:ve}):n==="database"?e.jsx(oa,{building:B}):n==="tests"?e.jsx("div",{className:"tests-panel-host",children:e.jsx(ca,{building:B,autoFocusSearch:!1})}):e.jsx("div",{className:"http-requests-panel-host",children:e.jsx(da,{building:B,autoFocusSearch:!1})})})]})]})})(),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[b.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(p,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),Ce&&st&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${Ce}`,"aria-label":`Open ${Ce} in file explorer`,role:"button",tabIndex:0,onClick:()=>f.openFileExplorer(Ce),onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),f.openFileExplorer(Ce))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(p,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:st})]}),ke&&ke.map(({areaId:n,areaName:r,dir:l})=>{const d=Ae.get(l),X=he.has(l),Q=l.split("/").filter(Boolean).pop()||l;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${r}: ${l}${d?` (${d.branch}${d.ahead?` ↑${d.ahead}`:""}${d.behind?` ↓${d.behind}`:""})`:""}`,onClick:()=>f.openFileExplorerForAreaFolder(n,l),children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:Q}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(p,{name:"git-branch",size:10})," ",d.branch]}),d.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${d.ahead} ahead`,children:[e.jsx(p,{name:"arrow-up",size:9}),d.ahead]}),d.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${d.behind} behind`,children:[e.jsx(p,{name:"arrow-down",size:9}),d.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${X?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:I=>{I.stopPropagation(),fe(l)},children:e.jsx(p,{name:X?"hourglass":"download",size:12})})]})]},`${n}:${l}`)}),e.jsx(ya,{agentId:o,disabled:((b==null?void 0:b.provider)??"claude")!=="claude",contextSummary:at?`Context: ${De}k / ${qe}k tokens (${gt}% used)`:void 0,children:e.jsxs("span",{className:"flat-terminal-wrapper__context",tabIndex:0,role:"button",onClick:()=>f.setContextModalAgentId(o),onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),f.setContextModalAgentId(o))},title:((b==null?void 0:b.provider)??"claude")!=="claude"?at?`Context usage: ${De}k / ${qe}k tokens (${gt}% used). Click to view stats.`:"Click to fetch context stats":void 0,children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(p,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${Te}%`,backgroundColor:ce}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:ce},children:[De,"k/",qe,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",Lt,"% free)"]}),!at&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(p,{name:"warn",size:12})})]})}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),He.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:He.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""} ${n.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${r?"Hide":"Show"} terminal: ${n.name}${n.hasUrl?"":" (starting...)"}`,onClick:()=>{if(r){oe();return}if(n.hasUrl&&rt(n.id)==="modal"){Ke(n.id);return}n.hasUrl||f.sendBuildingCommand(n.id,"start"),Re("terminal",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"terminal",size:14})},n.id)})}),Ue.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Ue.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""}`,title:`${r?"Hide":"Show"} logs: ${n.name}`,onClick:()=>{r?oe():rt(n.id)==="modal"?Ke(n.id):Re("pm2-logs",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"scroll",size:14})},n.id)})}),ge.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:ge.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""}`,title:`${r?"Hide":"Show"} database: ${n.name}`,onClick:()=>{r?oe():rt(n.id)==="modal"?Ke(n.id):Re("database",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"hard-drives",size:14})},n.id)})}),ue.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:ue.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""} ${n.working?"flat-terminal-wrapper__building-btn--tests-working":""}`,title:n.working?`Running tests: ${n.name}`:`${r?"Hide":"Show"} tests: ${n.name}`,onClick:()=>{r?oe():rt(n.id)==="modal"?Ke(n.id):Re("tests",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"flask",size:14})},n.id)})}),xe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area HTTP requests",children:xe.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""}`,title:`${r?"Hide":"Show"} HTTP requests: ${n.name}`,onClick:()=>{r?oe():rt(n.id)==="modal"?Ke(n.id):Re("http",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"globe",size:14})},n.id)})}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(ua,{})})]}),$e&&e.jsx(pa,{agentId:o,agents:nt,onClose:Tt,branchInfoMap:Ae,fetchRemote:fe,fetchingDirs:he,onResizeStart:n=>Et(n,"right")}),je&&e.jsx(ma,{agentId:o,onClose:Pt}),Z&&e.jsx(fa,{agentId:o,onClose:mt})]})});function Oa({onAgentClick:u,onBuildingClick:o,onBuildingDoubleClick:m,onBuildingPopup:h,onAreaContextMenu:y,onOpenSpawnModal:R,onOpenBossSpawnModal:P,onOpenAreaModal:z}){const{t:le}=Ht(["common"]),_=yn(),O=kn(),[$,U]=a.useState(null),[ee,te]=a.useState(null),[de,Be]=a.useState(null);An("flatview-image-modal",$!==null,()=>U(null));const[Ze,ct]=a.useState(null),[K,b]=a.useState(null),[T,Je]=a.useState(null),[re,Fe]=a.useState(null),[Pe,Qe]=a.useState(!1),dt=a.useCallback(()=>{Qe(t=>!t)},[]),We=a.useCallback(()=>{Qe(!1)},[]),[me,Le]=a.useState(()=>{const t=qt(E.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),et=a.useCallback(t=>{Le(t),Yt(E.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=s=>{if(s.key!==E.VIEW_MODE)return;const i=s.newValue;(i==="simple"||i==="chat"||i==="advanced")&&Le(i)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[ke,Ae]=a.useState(()=>Wt(E.FLAT_INSPECTOR_OPEN,!1)),[fe,he]=a.useState(!1),He=a.useCallback(()=>he(t=>!t),[]),Ue=a.useCallback(()=>he(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:fe}}))},[fe]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:ke}}))},[ke]),a.useEffect(()=>{const t=()=>he(C=>!C),s=()=>{Ae(C=>{const k=!C;return ye(E.FLAT_INSPECTOR_OPEN,k),k})},i=()=>{he(!1),Ae(!1),ye(E.FLAT_INSPECTOR_OPEN,!1)},g=()=>he(!1),x=()=>{Ae(!1),ye(E.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",s),window.addEventListener("tide-close-flat-side-views",i),window.addEventListener("tide-close-flat-agents-drawer-only",g),window.addEventListener("tide-close-flat-inspector-only",x),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",s),window.removeEventListener("tide-close-flat-side-views",i),window.removeEventListener("tide-close-flat-agents-drawer-only",g),window.removeEventListener("tide-close-flat-inspector-only",x)}},[]);const ge=a.useRef(null),Se=a.useRef(null),[ue,xe]=a.useState(()=>{const t=Kt(E.FLAT_MIDDLE_WIDTH,0);return t>=Nt?t:null}),[pe,be]=a.useState(()=>{const t=Kt(E.FLAT_INSPECTOR_WIDTH,0);return t>=Bt?t:null}),Ee=a.useCallback(t=>{if(typeof window>"u")return t;const s=pe!==null?Ct+pe:0,i=window.innerWidth-nn-Ct-tn-s;return Math.max(Nt,Math.min(Math.max(i,Nt),t))},[pe]),_e=a.useCallback(t=>{var x;if(typeof window>"u")return t;const s=(x=ge.current)==null?void 0:x.querySelector(".flat-middle"),i=(s==null?void 0:s.getBoundingClientRect().width)??Nt,g=window.innerWidth-nn-i-Ct-tn-Ct;return Math.max(Bt,Math.min(Math.max(g,Bt),t))},[]);a.useEffect(()=>{if(ue===null&&pe===null)return;const t=()=>{xe(s=>{if(s===null)return s;const i=Ee(s);return i===s?s:i}),be(s=>{if(s===null)return s;const i=_e(s);return i===s?s:i})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[ue,pe,Ee,_e]);const tt=a.useCallback(t=>{var i;if(t.button!==0)return;const s=(i=ge.current)==null?void 0:i.querySelector(".flat-middle");s&&(t.currentTarget.setPointerCapture(t.pointerId),Se.current={kind:"middle",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),j=a.useCallback(t=>{var i;if(t.button!==0)return;const s=(i=ge.current)==null?void 0:i.querySelector(".flat-inspector");s&&(t.currentTarget.setPointerCapture(t.pointerId),Se.current={kind:"inspector",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),we=a.useCallback(t=>{const s=Se.current;if(!s||t.pointerId!==s.pointerId)return;const i=t.clientX-s.startX;s.kind==="middle"?xe(Ee(s.startWidth+i)):be(_e(s.startWidth-i))},[Ee,_e]),B=a.useCallback(t=>{const s=Se.current;if(!s||t.pointerId!==s.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(Se.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-s.startX)>2))return;const g=t.clientX-s.startX;if(s.kind==="middle"){const x=Ee(s.startWidth+g);xe(x),jt(E.FLAT_MIDDLE_WIDTH,x)}else{const x=_e(s.startWidth-g);be(x),jt(E.FLAT_INSPECTOR_WIDTH,x)}},[Ee,_e]),ut=a.useCallback(()=>{xe(null),jt(E.FLAT_MIDDLE_WIDTH,0)},[]),Ie=a.useCallback(()=>{be(null),jt(E.FLAT_INSPECTOR_WIDTH,0)},[]),[ve,yt]=a.useState(()=>qt(E.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),D=a.useCallback(t=>{yt(t),Yt(E.FLAT_INSPECTOR_VIEW,t)},[]),Re=a.useCallback(()=>{Ae(t=>{const s=!t;return ye(E.FLAT_INSPECTOR_OPEN,s),s})},[]),oe=a.useCallback(()=>{Ae(!1),ye(E.FLAT_INSPECTOR_OPEN,!1)},[]),kt=Sn(),At=a.useCallback((t,s)=>{U({url:t,name:s})},[]),St=a.useCallback((t,s)=>{te({command:t,output:s,isLive:!1})},[]),Et=a.useCallback((t,s)=>{var x;const i=O.size>0?Array.from(O)[0]:null,g=i?(x=f.getState().agents.get(i))==null?void 0:x.cwd:void 0;f.setFileViewerPath(t,s,g)},[O]),$e=a.useCallback(t=>{Be(t)},[]),pt=a.useCallback((t,s)=>{ct({agentId:t,count:s})},[]),je=a.useCallback(t=>{m?m(t):o(t)},[o,m]),v=a.useMemo(()=>O.size>0?Array.from(O)[0]:null,[O]);a.useEffect(()=>{Qe(!1)},[v]);const Z=a.useRef([]),ne=a.useRef(-1),Ve=a.useRef(!1),mt=a.useRef(null),[It,Mt]=a.useState(!1),[Tt,Pt]=a.useState(!1),nt=a.useRef(!1),ae=a.useRef(null),Xe=a.useRef(!1),se=a.useMemo(()=>new Set(_.map(t=>t.id)),[_]),Me=a.useMemo(()=>{const t=new Map(_.map(i=>[i.id,i])),s=new Map;for(const i of _)if((i.isBoss||i.class==="boss")&&i.subordinateIds&&i.subordinateIds.length>0){const g=i.subordinateIds.map(x=>t.get(x)).filter(x=>x!==void 0);g.length>0&&s.set(i.id,g)}return s},[_]),J=a.useCallback(()=>{const t=Z.current,s=ne.current;Mt(s>0),Pt(s>=0&&s<t.length-1)},[]),V=a.useCallback(t=>{const s=Z.current;if(s.length===0)return;let i=ne.current+t;for(;i>=0&&i<s.length;){const g=s[i];if(se.has(g)){Ve.current=!0,ne.current=i,J(),f.selectAgent(g);return}i+=t}},[se,J]),at=a.useCallback(()=>V(-1),[V]),ft=a.useCallback(()=>V(1),[V]);_a(a.useCallback(()=>{const t=Z.current,s=ne.current;return t.length>0&&s>0?(V(-1),"handled"):"exit"},[V]));const Ge=a.useCallback((t,s)=>{if(typeof window>"u")return;const i=window.history.state,x={...typeof i=="object"&&i!==null?i:{},__flatAgentNav:{agentId:t}};s==="replace"?window.history.replaceState(x,"",window.location.href):window.history.pushState(x,"",window.location.href)},[]);a.useEffect(()=>{if(!v){nt.current=!1,ae.current=null;return}if(!nt.current){Ge(v,"replace"),nt.current=!0,ae.current=v;return}if(Xe.current){Xe.current=!1,ae.current=v;return}ae.current!==v&&(Ge(v,"push"),ae.current=v)},[v,Ge]),a.useEffect(()=>{const t=s=>{var C,k;const i=(k=(C=s.state)==null?void 0:C.__flatAgentNav)==null?void 0:k.agentId;if(!i||typeof i!="string"||!se.has(i)||i===v)return;Xe.current=!0,Ve.current=!0;const g=Z.current,x=g.lastIndexOf(i);x>=0?ne.current=x:(g.push(i),ne.current=g.length-1),J(),f.selectAgent(i)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[se,v,J]),a.useEffect(()=>{if(!v){Z.current=[],ne.current=-1,J();return}if(mt.current=v,Ve.current){Ve.current=!1,J();return}const t=Z.current,s=ne.current;if(s>=0&&t[s]===v){J();return}const i=s<t.length-1?t.slice(0,s+1):t.slice();i.push(v),i.length>100&&i.shift(),Z.current=i,ne.current=i.length-1,J()},[v,J]);const ht=a.useCallback(t=>{u(t),he(!1)},[u]),Te=v??"",gt=a.useCallback(()=>{},[]),Lt=a.useCallback(t=>{ht(t)},[ht]),ce=ke,[De,qe]=a.useState(ce),[Ce,st]=a.useState(ce);a.useEffect(()=>{if(ce){qe(!0);return}st(!1);const t=setTimeout(()=>qe(!1),240);return()=>clearTimeout(t)},[ce]),a.useEffect(()=>{if(!De||!ce)return;let t=0;const s=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>st(!0))});return()=>{cancelAnimationFrame(s),cancelAnimationFrame(t)}},[De,ce]);const ze=a.useRef(null);a.useEffect(()=>{if(v)return;const t=s=>{if(s.key!==" "&&s.key!=="Backspace")return;const i=s.target;if(i.tagName==="INPUT"||i.tagName==="TEXTAREA"||i.isContentEditable)return;const g=mt.current;!g||!se.has(g)||(s.preventDefault(),f.selectAgent(g))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[v,se]);const[Rt,it]=a.useState(new Set),xt=a.useCallback(t=>{it(s=>{const i=new Set(s);return i.has(t)?i.delete(t):i.add(t),i})},[]),[n,r]=a.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),s=i=>r(i.matches);return t.addEventListener("change",s),()=>t.removeEventListener("change",s)},[]);const[l,d]=a.useState(null),X=a.useCallback(t=>{d(s=>s===t?null:t)},[]),Q=on(),I=cn(),[Ye]=En(),Ne=a.useMemo(()=>{const t=new Map,s=[];for(const w of _){const S=f.getAreaForAgent(w.id);if(!Zt((S==null?void 0:S.id)??null))continue;if(!S||S.archived){s.push(w);continue}const M=t.get(S.id);M?M.push(w):t.set(S.id,[w])}const i=new Map,g=[];for(const w of I.values()){let S=!1;for(const M of Q.values())if(!M.archived&&Jt(M.id)&&f.isPositionInArea(w.position,M)){const G=i.get(M.id);G?G.push(w):i.set(M.id,[w]),S=!0;break}!S&&Zt(null)&&g.push(w)}const x=[];for(const[,w]of Q){if(w.archived||!Jt(w.id))continue;const S=t.get(w.id),M=i.get(w.id)??[];(S&&S.length>0||M.length>0)&&x.push({area:w,agents:S??[],buildings:M})}(s.length>0||g.length>0)&&x.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:s,buildings:g});const C=x.filter(w=>w.area.id!=="__unassigned__"),k=x.filter(w=>w.area.id==="__unassigned__");let c=1,A=1;const H=new Map;if(C.length>1){let w=1/0,S=-1/0,M=1/0,G=-1/0;for(const q of C)w=Math.min(w,q.area.center.x),S=Math.max(S,q.area.center.x),M=Math.min(M,q.area.center.z),G=Math.max(G,q.area.center.z);const _t=S-w||1,wt=G-M||1;if(C.length<=4){c=C.length,A=1;const q=[...C].sort((Y,$t)=>Y.area.center.x-$t.area.center.x);for(let Y=0;Y<q.length;Y++)H.set(q[Y].area.id,{row:1,col:Y+1})}else{const q=[...C].sort((N,F)=>N.area.center.x-F.area.center.x),Y=[];for(let N=1;N<q.length;N++)Y.push(q[N].area.center.x-q[N-1].area.center.x);const $t=Y.reduce((N,F)=>N+F,0)/Y.length||1;let Ut=1;for(const N of Y)N>$t*1.3&&Ut++;c=Math.max(2,Math.min(Ut,C.length));const Dt=[...C].sort((N,F)=>N.area.center.z-F.area.center.z),vt=[];for(let N=1;N<Dt.length;N++)vt.push(Dt[N].area.center.z-Dt[N-1].area.center.z);const fn=vt.reduce((N,F)=>N+F,0)/vt.length||1;let Vt=1;for(const N of vt)N>fn*1.3&&Vt++;A=Math.max(2,Math.min(Vt,C.length)),c=Math.max(c,Math.ceil(C.length/A)),A=Math.max(A,Math.ceil(C.length/c));const hn=_t/c,gn=wt/A,zt=new Set;for(const N of C){let F=Math.min(c-1,Math.max(0,Math.floor((N.area.center.x-w)/hn))),Oe=Math.min(A-1,Math.max(0,Math.floor((N.area.center.z-M)/gn))),lt=`${Oe},${F}`,Xt=0;const xn=A*c;for(;zt.has(lt)&&Xt<xn;)F++,F>=c&&(F=0,Oe=(Oe+1)%A),lt=`${Oe},${F}`,Xt++;zt.has(lt)&&(Oe=A,F=0,lt=`${Oe},${F}`,A++),zt.add(lt),H.set(N.area.id,{row:Oe+1,col:F+1})}}}const L=w=>{w.sort((S,M)=>{var _t,wt,q,Y;const G=(((_t=S.position)==null?void 0:_t.z)??0)-(((wt=M.position)==null?void 0:wt.z)??0);return G!==0?G:(((q=S.position)==null?void 0:q.x)??0)-(((Y=M.position)==null?void 0:Y.x)??0)})};for(const w of C)L(w.agents);for(const w of k)L(w.agents);return{groups:[...C,...k],gridCols:c,gridRows:A,positions:H}},[_,Q,I,Ye]),bt=a.useMemo(()=>{if(!K)return[];const t=_.find(s=>s.id===K.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(p,{name:"chat",size:14}),onClick:()=>u(t.id)},{id:"clone-agent",label:"Clone Agent",icon:e.jsx(p,{name:"clipboard",size:14}),onClick:()=>f.cloneAgent(t.id)},{id:"fork-agent",label:"Fork Agent (with history)",icon:e.jsx(p,{name:"git-branch",size:14}),onClick:()=>f.forkAgent(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>{Fe({agentId:t.id,name:t.name})}}]:[]},[K,_,u]),ie=a.useMemo(()=>{var C;if(!T)return[];const t=I.get(T.buildingId);if(!t)return[];const s=[],i=t.type==="server"||t.type==="docker"||t.type==="terminal",g=t.status==="running",x=t.type==="boss";if(s.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="tests"?"Open Tests":t.type==="http"?"Open Requests":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((C=t.pm2)!=null&&C.enabled)?"View PM2 Logs":"Open",icon:e.jsx(p,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="tests"?"flask":t.type==="http"?"globe":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>je(t.id)}),i&&(g||s.push({id:"start",label:"Start",icon:e.jsx(p,{name:"play",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"start")}),g&&(s.push({id:"restart",label:"Restart",icon:e.jsx(p,{name:"refresh",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"restart")}),s.push({id:"stop",label:"Stop",icon:e.jsx(p,{name:"stop",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"stop")}))),x&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(s.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(p,{name:"launch",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)f.sendBuildingCommand(k,"start")}}),s.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(p,{name:"pause",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)f.sendBuildingCommand(k,"stop")}}),s.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(p,{name:"restart",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)f.sendBuildingCommand(k,"restart")}})),i&&s.push({id:"health-check",label:"Health Check",icon:e.jsx(p,{name:"health",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"healthCheck")}),s.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),s.push({id:"edit",label:"Edit Building",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),s.push({id:"clone",label:"Clone Building",icon:e.jsx(p,{name:"copy",size:14}),onClick:()=>{f.createBuilding({name:`${t.name} (Copy)`,type:t.type,style:t.style,color:t.color,scale:t.scale,position:{x:t.position.x+2,z:t.position.z+2},cwd:t.cwd,folderPath:t.folderPath,commands:t.commands,pm2:t.pm2,docker:t.docker,database:t.database,terminal:t.terminal,urls:t.urls,subordinateBuildingIds:t.subordinateBuildingIds})}}),t.urls&&t.urls.length>0)for(const k of t.urls)s.push({id:`url-${k.label}`,label:k.label,icon:e.jsx(p,{name:"link",size:14}),onClick:()=>window.open(k.url,"_blank","noopener,noreferrer")});return s.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),s.push({id:"delete",label:"Delete Building",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>f.deleteBuilding(t.id)}),s},[T,I,je]),W=a.useCallback(t=>{const s=new Set(Ne.groups.map(i=>i.area.id));s.delete(t),it(s),requestAnimationFrame(()=>{const i=ze.current;if(!i)return;const g=i.querySelector(`[data-area-id="${t}"]`);if(!g)return;const x=i.getBoundingClientRect(),k=g.getBoundingClientRect().top-x.top+i.scrollTop-8;i.scrollTo({top:Math.max(0,k),behavior:"smooth"})})},[Ne]);return e.jsxs("div",{ref:ge,className:`flat-view ${ce?"flat-view--with-inspector":""} ${v?"flat-view--has-chat":""} ${fe?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(ue===null&&pe===null)return;const t={};return ue!==null&&(t["--flat-middle-width"]=`${ue}px`),pe!==null&&(t["--flat-inspector-width"]=`${pe}px`),t})(),children:[fe&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Ue,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children:e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:R,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:P,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:z,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(In,{activeAgentId:Te,onClose:gt,onSelectAgent:Lt,collapsedAreas:Rt,onToggleArea:xt,agentListRef:ze})})]}),e.jsx("div",{className:"flat-splitter flat-splitter--middle",role:"separator","aria-orientation":"vertical","aria-label":"Resize agents panel",title:"Drag to resize · Double-click to reset",onPointerDown:tt,onPointerMove:we,onPointerUp:B,onPointerCancel:B,onDoubleClick:ut}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":fe?"Close agents sidebar":"Open agents sidebar","aria-expanded":fe,onClick:He,children:[e.jsx(p,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),v?e.jsx(La,{agentId:v,terminalViewMode:me,onTerminalViewModeChange:et,inspectorOpen:ke,onToggleInspector:Re,onImageClick:At,onFileClick:Et,onBashClick:St,onViewMarkdown:$e,onRequestClearSubordinates:pt,keyboard:kt,canNavigateBack:It,canNavigateForward:Tt,onNavigateBack:at,onNavigateForward:ft,agentInfoOpen:Pe,onToggleAgentInfo:dt,onHeaderContextMenu:t=>{v&&b({agentId:v,position:t})},onBuildingContextMenu:(t,s)=>{Je({buildingId:t,position:s})}}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"}),e.jsx(ka,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Ne.gridCols}, 1fr)`},children:Ne.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var s;const t=n&&l?((s=Ne.positions.get(l))==null?void 0:s.row)??null:null;return Ne.groups.map(i=>{var k;const g=i.area.id,x=Ne.positions.get(g),C=n&&l!==g;return n&&t!=null&&(x==null?void 0:x.row)===t&&g!==l?null:e.jsxs("div",{className:`flat-map-area-card${C?" flat-map-area-card--collapsed":""}`,style:{"--area-color":i.area.color,gridRow:x==null?void 0:x.row,gridColumn:x==null?void 0:x.col},onContextMenu:c=>{y&&(c.preventDefault(),c.stopPropagation(),y(g,{x:c.clientX,y:c.clientY}))},children:[((k=i.area.logo)==null?void 0:k.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:ba(i.area.logo.filename),alt:"","aria-hidden":"true",onError:c=>{c.currentTarget.style.display="none"}}),e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>n?X(g):W(g),title:n?C?`Expand ${i.area.name}`:`Collapse ${i.area.name}`:`Focus ${i.area.name} in left panel`,"aria-expanded":n?!C:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:i.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:i.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:i.agents.length}),n&&e.jsx(p,{name:C?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:i.agents.map(c=>{const A=c.isBoss||c.class==="boss",H=A?Me.get(c.id):void 0,L=Mn(c),w=L.usedPercent>=80?"#ff4a4a":L.usedPercent>=60?"#ff9e4a":L.usedPercent>=40?"#ffd700":"#4aff9e",S=`Context: ${(L.totalTokens/1e3).toFixed(1)}k / ${(L.contextWindow/1e3).toFixed(1)}k (${L.usedPercent}% used, ${L.freePercent}% free)`,M=c.latestTodos&&c.latestTodos.length>0||H&&H.length>0;return e.jsx(Tn,{todos:c.latestTodos,subordinates:H,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${c.status}`,onClick:()=>u(c.id),onContextMenu:G=>{G.preventDefault(),G.stopPropagation(),b({agentId:c.id,position:{x:G.clientX,y:G.clientY}})},title:M?void 0:`${A?"Boss · ":""}Open chat with ${c.name}
1
+ import{r as a,B as bn,E as Gt,G as sn,H as ln,j as e,J as rn,K as _n,u as Ht,L as wn,M as vn,N as jn,O as Cn,V as Nn,P as yn,U as kn,W as An,X as qt,S as E,Y as Yt,Z as Wt,_ as Kt,$ as jt,a0 as ye,a1 as Sn,s as f,a2 as on,a3 as cn,a4 as En,w as Zt,x as Jt,I as p,a5 as In,n as Mn,a6 as Tn,a7 as dn,a8 as un,a9 as Pn,aa as Ln,ab as Rn,ac as $n,ad as Dn,ae as zn,af as On,ag as Bn,ah as Fn,ai as Wn,aj as Hn,ak as Un,al as Qt,C as Vn,am as Xn,an as en,ao as Gn,ap as qn,aq as Yn,ar as Kn,as as Zn,at as Jn,au as Qn,av as ea,aw as ta,ax as na,ay as aa,az as sa,aA as ia,aB as la,aC as Ke,aD as ra,aE as oa,aF as ca,aG as da,aH as rt,aI as ua,aJ as pa,aK as ma,aL as fa,aM as ha,aN as ga,aO as xa}from"./main-C6HtzRV0.js";import{g as ba}from"./area-logos-CQqvtlze.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function _a(u){const o=a.useRef(u);o.current=u,a.useEffect(()=>{if(!bn())return;let m=null,h=!1;return Gt.addListener("backButton",()=>{o.current()==="exit"&&Gt.exitApp()}).then(y=>{h?y.remove():m=y}),()=>{h=!0,m&&(m.remove(),m=null)}},[])}async function wa(u){const o=sn(),m=await fetch(`${ln()}/api/agents/${u}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${o}`}});if(!m.ok){const h=await m.json().catch(()=>({}));throw new Error((h==null?void 0:h.error)||`Failed to start terminal (${m.status})`)}return m.json()}async function va(u){const o=sn();await fetch(`${ln()}/api/agents/${u}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${o}`}})}const ot=new Map;function ja({agentId:u}){const[o,m]=a.useState(null),[h,y]=a.useState(null);return a.useEffect(()=>{let R=!1;const P=ot.get(u);return P&&(clearTimeout(P),ot.delete(u)),m(null),y(null),wa(u).then(z=>{R||m(z.url)}).catch(z=>{R||y(z instanceof Error?z.message:"Failed to start terminal")}),()=>{R=!0;const z=ot.get(u);z&&clearTimeout(z),ot.set(u,setTimeout(()=>{ot.delete(u),va(u)},2500))}},[u]),h?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:h})}):o?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(rn,{terminalUrl:o,visible:!0})}):e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:"Attaching to interactive session…"})})}const Ot=new Map,Ca=6e4;function Na({agentId:u,contextSummary:o}){const{t:m}=Ht(["terminal","common"]),[h,y]=a.useState(()=>{var $;return(($=Ot.get(u))==null?void 0:$.snapshot)??null}),[R,P]=a.useState(!1),[z,le]=a.useState(null),_=a.useRef(0);a.useEffect(()=>{const $=Ot.get(u);if($&&Date.now()-$.fetchedAt<Ca){y($.snapshot);return}const U=++_.current;P(!0),le(null),wn(u).then(ee=>{U===_.current&&(Ot.set(u,{snapshot:ee,fetchedAt:Date.now()}),y(ee),P(!1))}).catch(ee=>{U===_.current&&(le(ee.message||"Failed to load plan limits"),P(!1))})},[u]);const O=[];if(h!=null&&h.rateLimits){const $=[{key:"fiveHour",label:m("terminal:usage.currentSession"),window:h.rateLimits.fiveHour},{key:"sevenDay",label:m("terminal:usage.currentWeekAll"),window:h.rateLimits.sevenDay},{key:"sevenDayOpus",label:m("terminal:usage.currentWeekOpus"),window:h.rateLimits.sevenDayOpus},{key:"sevenDaySonnet",label:m("terminal:usage.currentWeekSonnet"),window:h.rateLimits.sevenDaySonnet}];for(const U of $)U.window&&O.push({...U,window:U.window})}return e.jsxs("div",{className:"plan-limits-tooltip",children:[o&&e.jsx("div",{className:"plan-limits-tooltip__context",children:o}),e.jsx("div",{className:"plan-limits-tooltip__title",children:m("terminal:usage.limits")}),R&&!h&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[m("common:status.loading"),"…"]}),!R&&z&&!h&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:m("terminal:usage.limitsError",{message:z})}),O.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:O.map(({key:$,label:U,window:ee})=>{const te=Math.max(0,Math.min(100,ee.utilization)),de=jn(te);return e.jsxs("div",{className:"plan-limits-tooltip__gauge",children:[e.jsxs("div",{className:"plan-limits-tooltip__gauge-head",children:[e.jsx("span",{className:"plan-limits-tooltip__gauge-label",children:U}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:de},children:m("terminal:usage.percentUsed",{percent:Math.round(te)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${te}%`,background:de}})}),e.jsx("div",{className:"plan-limits-tooltip__reset",children:m("terminal:usage.resets",{time:vn(ee.resetsAt)})})]},$)})}):h&&!R&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:h.rateLimitsError?m("terminal:usage.limitsError",{message:h.rateLimitsError}):h.cliHint})]})}function ya({agentId:u,disabled:o,contextSummary:m,children:h}){return e.jsx(_n,{position:"top",maxWidth:320,disabled:o,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx(Na,{agentId:u,contextSummary:m}),children:h})}const ka=a.memo(function({className:o=""}){const{t:m}=Ht(["common"]),[h,y]=Cn(),R=a.useRef(null),[P,z]=a.useState(null);a.useLayoutEffect(()=>{const _=R.current;if(!_)return;const O=_.querySelector(".view-mode-toggle__btn--active");O&&z({left:O.offsetLeft,width:O.offsetWidth})},[h]);const le=a.useCallback(_=>{if(_!==h){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:_}})),_==="3d"){requestAnimationFrame(()=>y(_));return}y(_)}},[h,y]);return e.jsxs("div",{className:`view-mode-toggle ${o}`,ref:R,children:[P&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:P.left,width:P.width}}),Nn.map(_=>e.jsxs("button",{className:`view-mode-toggle__btn ${h===_?"view-mode-toggle__btn--active":""}`,onClick:()=>le(_),title:m(`common:viewMode.descriptions.${_}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[_==="2d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]}),_==="3d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]}),_==="flat"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1"})]}),_==="dashboard"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"12",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"3",y:"16",width:"7",height:"5",rx:"1"})]})]}),e.jsx("span",{className:"view-mode-toggle__label",children:m(`common:viewMode.labels.${_}`)})]},_))]})}),Ct=3,Nt=280,tn=320,Bt=240,nn=64,Aa=["simple","chat","advanced"],Sa={simple:"Simple",chat:"Chat",advanced:"Advanced"},Ea={simple:"○",chat:"◐",advanced:"◉"},Ia={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},an="flat-clear-context",pn="tide:flat-embedded-panels";function mn(){try{const u=localStorage.getItem(pn),o=u?JSON.parse(u):{};return o&&typeof o=="object"?o:{}}catch{return{}}}function Ft(u,o){try{const m=mn();o?m[u]=o:delete m[u],localStorage.setItem(pn,JSON.stringify(m))}catch{}}function Ma(u){const o=u.split("/").filter(Boolean);return o.length===0?u:o.slice(-2).join("/")}function Ta(u){if(u.provider==="codex"){const R=u.codexModel||"gpt-5.3-codex",P=ha[R];return{model:(P==null?void 0:P.label)||R}}if(u.provider==="opencode")return{model:u.opencodeModel||"opencode"};const o=u.model||"sonnet",m=xa[o],h=u.effort,y=h?ga[h]:void 0;return{model:(m==null?void 0:m.label)||o,effort:y==null?void 0:y.label}}function Pa(u,o){if(o.type==="rectangle"&&o.width&&o.height){const m=o.width/2,h=o.height/2;return u.x>=o.center.x-m&&u.x<=o.center.x+m&&u.z>=o.center.z-h&&u.z<=o.center.z+h}if(o.type==="circle"&&o.radius){const m=u.x-o.center.x,h=u.z-o.center.z;return m*m+h*h<=o.radius*o.radius}return!1}const La=Xn.memo(function({agentId:o,terminalViewMode:m,onTerminalViewModeChange:h,inspectorOpen:y,onToggleInspector:R,onImageClick:P,onFileClick:z,onBashClick:le,onViewMarkdown:_,onRequestClearSubordinates:O,keyboard:$,canNavigateBack:U,canNavigateForward:ee,onNavigateBack:te,onNavigateForward:de,agentInfoOpen:Be,onToggleAgentInfo:Ze,onHeaderContextMenu:ct,onBuildingContextMenu:K}){var it,xt;const b=en(o),T=cn(),Je=Gn(),re=a.useRef(null),Fe=a.useRef(null),{displayedAgentId:Pe,fadingOut:Qe}=qn(o),dt=en(Pe),We=!!Je.interactiveMode&&((b==null?void 0:b.provider)??"claude")==="claude"&&!!(b!=null&&b.sessionId),[me,Le]=a.useState(!1);a.useEffect(()=>{Le(!1)},[o]),a.useEffect(()=>{!We&&me&&Le(!1)},[We,me]),a.useEffect(()=>{const n=Fe.current;if(!n)return;const r=d=>{d.button===3?(d.preventDefault(),d.stopPropagation(),te()):d.button===4&&(d.preventDefault(),d.stopPropagation(),de())},l=d=>{(d.button===3||d.button===4)&&d.preventDefault()};return n.addEventListener("mouseup",r),n.addEventListener("mousedown",l),()=>{n.removeEventListener("mouseup",r),n.removeEventListener("mousedown",l)}},[te,de]),a.useEffect(()=>{const n=Fe.current;if(!n)return;let r=0,l=0,d=0;const X=250,Q=600,I=80,Ye=1.5,Ne=ie=>{let W=ie instanceof HTMLElement?ie:null;for(;W&&W!==n;){const t=window.getComputedStyle(W).overflowX;if((t==="auto"||t==="scroll")&&W.scrollWidth>W.clientWidth)return!0;W=W.parentElement}return!1},bt=ie=>{const W=Date.now();if(W<d){ie.preventDefault();return}if(Math.abs(ie.deltaX)<=Math.abs(ie.deltaY)*Ye){r=0;return}if(Ne(ie.target)){r=0;return}W-l>X&&(r=0),l=W,r+=ie.deltaX,r<=-I?(r=0,d=W+Q,ie.preventDefault(),te()):r>=I&&(r=0,d=W+Q,ie.preventDefault(),de())};return n.addEventListener("wheel",bt,{passive:!1}),()=>n.removeEventListener("wheel",bt)},[te,de]);const et=on(),ke=a.useMemo(()=>{if(!b)return null;const n=new Set,r=[];for(const l of et.values())l.archived||l.directories.length===0||l.assignedAgentIds.includes(o)&&(n.add(l.id),r.push(l));for(const l of et.values())l.archived||l.directories.length===0||n.has(l.id)||Pa({x:b.position.x,z:b.position.z},l)&&(n.add(l.id),r.push(l));return r.length===0?null:r.flatMap(l=>l.directories.filter(d=>d&&d.trim().length>0).map(d=>({areaId:l.id,areaName:l.name,dir:d})))},[b,o,et]),{branches:Ae,fetchRemote:fe,fetchingDirs:he}=Yn(ke),He=a.useMemo(()=>{var l;const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const d of T.values())d.type==="terminal"&&f.isPositionInArea(d.position,n)&&r.push({id:d.id,name:d.name,hasUrl:!!((l=d.terminalStatus)!=null&&l.url)});return r},[o,T]),Ue=a.useMemo(()=>{var l;const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const d of T.values())d.type==="server"&&((l=d.pm2)!=null&&l.enabled)&&f.isPositionInArea(d.position,n)&&r.push({id:d.id,name:d.name});return r},[o,T]),ge=a.useMemo(()=>{const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const l of T.values())l.type==="database"&&l.database&&f.isPositionInArea(l.position,n)&&r.push({id:l.id,name:l.name});return r},[o,T]),Se=Kn(),ue=a.useMemo(()=>{const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const l of T.values())if(l.type==="tests"&&f.isPositionInArea(l.position,n)){const d=!!l.folderPath&&Se.some(X=>Zn(X,l.folderPath));r.push({id:l.id,name:l.name,working:d})}return r},[o,T,Se]),xe=a.useMemo(()=>{const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const l of T.values())l.type==="http"&&f.isPositionInArea(l.position,n)&&r.push({id:l.id,name:l.name});return r},[o,T]),[,pe]=a.useReducer(n=>n+1,0),be=((it=re.current)==null?void 0:it.search.searchMode)??!1,Ee=a.useCallback(()=>{var n;(n=re.current)==null||n.search.toggleSearch(),pe()},[]),_e=Jn(),tt=_e.isPending(an),[j,we]=a.useState(null),B=j?T.get(j.buildingId):null,[ut,Ie]=a.useState(""),[ve,yt]=a.useState(()=>Qn()),D=a.useMemo(()=>{var n;return((n=f.getAreaForAgent(o))==null?void 0:n.id)??null},[o,T]),Re=a.useCallback((n,r)=>{Ie(""),we(l=>{const d=(l==null?void 0:l.buildingId)===r?null:{type:n,buildingId:r};return D&&Ft(D,d),d})},[D]),oe=a.useCallback(()=>{Ie(""),we(null),D&&Ft(D,null)},[D]);a.useEffect(()=>{if((j==null?void 0:j.type)!=="pm2-logs")return;const n=j.buildingId;return f.startLogStreaming(n,200),()=>f.stopLogStreaming(n)},[j]);const{height:kt,onResizeStart:At}=ea(),{sidePanelWidth:St,handleSidePanelResizeStart:Et}=ta(),[$e,pt]=a.useState(()=>Wt(E.GIT_PANEL_OPEN,!1)),[je,v]=a.useState(()=>Wt(E.BUILDINGS_PANEL_OPEN,!1)),[Z,ne]=a.useState(!1),Ve=a.useCallback(()=>{ne(n=>{const r=!n;return r&&na.setEnabled(!0),r})},[]),mt=a.useCallback(()=>ne(!1),[]),It=a.useCallback(()=>{pt(n=>{const r=!n;return ye(E.GIT_PANEL_OPEN,r),r})},[]),Mt=a.useCallback(()=>{v(n=>{const r=!n;return ye(E.BUILDINGS_PANEL_OPEN,r),r})},[]),Tt=a.useCallback(()=>{pt(!1),ye(E.GIT_PANEL_OPEN,!1)},[]),Pt=a.useCallback(()=>{v(!1),ye(E.BUILDINGS_PANEL_OPEN,!1)},[]),nt=aa(),ae=a.useMemo(()=>({terminal:He,"pm2-logs":Ue,database:ge,tests:ue,http:xe}),[He,Ue,ge,ue,xe]);a.useEffect(()=>{if(!j)return;ae[j.type].some(r=>r.id===j.buildingId)||(Ie(""),we(null))},[j,ae]);const Xe=a.useRef(void 0);a.useEffect(()=>{var r;if(Xe.current===D)return;Xe.current=D;const n=D?mn()[D]:void 0;Ie(""),n&&((r=ae[n.type])!=null&&r.some(l=>l.id===n.buildingId))?we(n):we(null)},[D,ae]),a.useEffect(()=>{const n=r=>{var X;const l=r.detail;if(!(l!=null&&l.buildingId)||!(l!=null&&l.type)||!((X=ae[l.type])!=null&&X.some(Q=>Q.id===l.buildingId)))return;l.handled=!0,Ie("");const d={type:l.type,buildingId:l.buildingId};we(d),D&&Ft(D,d)};return window.addEventListener("tide:dock-building-flat",n),()=>window.removeEventListener("tide:dock-building-flat",n)},[ae,D]);const[se,Me]=a.useState(!1),J=a.useRef(null);if(a.useEffect(()=>{if(!se)return;const n=r=>{J.current&&!J.current.contains(r.target)&&Me(!1)};return document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[se]),!b)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const V=b.contextStats,at=!!V,ft=V?V.totalTokens:b.contextUsed||0,Ge=V?V.contextWindow:b.contextLimit||2e5,ht=V?V.usedPercent:Math.round(ft/Ge*100),Te=Math.max(0,Math.min(100,ht)),gt=Math.round(Te*10)/10,Lt=Math.round((100-Te)*10)/10,ce=Te>=80?"#ff4a4a":Te>=60?"#ff9e4a":Te>=40?"#ffd700":"#4aff9e",De=(ft/1e3).toFixed(1),qe=(Ge/1e3).toFixed(1),Ce=b.cwd,st=Ce?Ma(Ce):null,ze=((xt=b.subordinateIds)==null?void 0:xt.length)||0,Rt=ze>0;return e.jsxs("div",{ref:Fe,className:`flat-terminal-wrapper ${$e||je||Z?"flat-terminal-wrapper--with-side-panel":""} ${Qe?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${St}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${Be?"flat-terminal-wrapper__header-main--active":""}`,onClick:Ze,onContextMenu:n=>{n.preventDefault(),n.stopPropagation(),ct({x:n.clientX,y:n.clientY})},title:Be?"Hide agent info":"Show agent info","aria-pressed":Be,children:[e.jsx(dn,{agent:b,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:b.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:un(b.status)},children:b.status})]}),b.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:b.taskLabel,children:["📋 ",b.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:b.provider==="codex"?"/assets/codex.png":b.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:b.provider,className:"flat-terminal-wrapper__header-provider-icon",title:b.provider==="codex"?"Codex Agent":b.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:n,effort:r}=Ta(b);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:r?`Model: ${n} · Effort: ${r}`:`Model: ${n}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:n}),r&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:r})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsxs("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:[Aa.map(n=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!me&&m===n?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Le(!1),h(n)},title:Ia[n],"aria-pressed":!me&&m===n,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:Ea[n]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Sa[n]})]},n)),We&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${me?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Le(n=>!n),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":me,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:e.jsx(p,{name:"terminal",size:13})}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:"Classic TUI"})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:te,disabled:!U,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(p,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:de,disabled:!ee,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(p,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${be?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Ee,title:be?"Close search":"Search messages","aria-pressed":be,children:e.jsx(p,{name:be?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${tt?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>_e.handleClick(an,()=>{var n;f.clearContext(o),(n=re.current)==null||n.historyLoader.clearHistory()}),title:tt?"Click again to confirm clear context":"Clear context",children:e.jsx(p,{name:tt?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${$e?"flat-terminal-wrapper__action-btn--active":""}`,onClick:It,title:$e?"Hide git panel":"Show git changes","aria-pressed":$e,children:e.jsx(p,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${je?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Mt,title:je?"Hide buildings panel":"Show area buildings","aria-pressed":je,children:e.jsx(p,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:J,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${se?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>Me(n=>!n),title:"More actions","aria-expanded":se,children:"⋮"}),se&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${Z?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Ve(),Me(!1)},title:Z?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(p,{name:"bug",size:14}),e.jsx("span",{children:Z?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{f.collapseContext(o),Me(!1)},disabled:b.status!=="idle",title:b.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(p,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),Rt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{O(o,ze),Me(!1)},children:[e.jsx(p,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",ze," subordinate",ze===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{f.killAgent(o),Me(!1)},children:[e.jsx(p,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${y?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:R,title:y?"Hide inspector panel":"Show inspector panel","aria-label":y?"Hide inspector panel":"Show inspector panel","aria-pressed":y,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>f.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(p,{name:"cross",size:14})})]})]}),me&&We?e.jsx(ja,{agentId:o}):Pe&&dt?e.jsx(sa,{ref:re,agentId:Pe,agent:dt,viewMode:m,isOpen:!0,onImageClick:P,onFileClick:z,onBashClick:le,onViewMarkdown:_,keyboard:$,hasModalOpen:!1},Pe):null,j&&B&&(()=>{var X,Q;const n=j.type,r={terminal:"terminal","pm2-logs":"scroll",database:"hard-drives",tests:"flask",http:"globe"},l=n==="terminal"&&!((X=B.terminalStatus)!=null&&X.url),d=!l;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:At,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded panel"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`${B.name} panel`,style:{height:kt},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(p,{name:r[n],size:12}),e.jsx("span",{children:B.name}),l&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsxs("span",{className:"flat-bottom-panel__header-actions",children:[n==="pm2-logs"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",className:"guake-bottom-terminal-filter",value:ut,onChange:I=>Ie(I.target.value),placeholder:"Filter logs","aria-label":`Filter logs for ${B.name}`,spellCheck:!1}),e.jsx("select",{className:"guake-bottom-terminal-retention",value:ve===null?"unlimited":String(ve),onChange:I=>{const Ye=I.target.value==="unlimited"?null:Number(I.target.value);yt(Ye),la(Ye)},"aria-label":`Max log retention for ${B.name}`,children:ia.map(I=>e.jsx("option",{value:I===null?"unlimited":String(I),children:I===null?"Unlimited":`${I.toLocaleString()} lines`},I===null?"unlimited":I))}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>f.clearStreamingLogs(j.buildingId),title:"Clear logs",children:e.jsx(p,{name:"trash",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>f.sendBuildingCommand(j.buildingId,"restart"),title:"Restart",children:e.jsx(p,{name:"restart",size:12})})]}),d&&e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>{oe(),Ke(j.buildingId)},title:"Maximize — open as modal","aria-label":"Open as modal",children:e.jsx(p,{name:"fullscreen",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:oe,title:"Close panel","aria-label":"Close panel",children:e.jsx(p,{name:"cross",size:12})})]})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:n==="terminal"?(Q=B.terminalStatus)!=null&&Q.url?e.jsx(rn,{terminalUrl:B.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."}):n==="pm2-logs"?e.jsx(ra,{buildingId:j.buildingId,filterText:ut,maxRetention:ve}):n==="database"?e.jsx(oa,{building:B}):n==="tests"?e.jsx("div",{className:"tests-panel-host",children:e.jsx(ca,{building:B,autoFocusSearch:!1})}):e.jsx("div",{className:"http-requests-panel-host",children:e.jsx(da,{building:B,autoFocusSearch:!1})})})]})]})})(),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[b.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(p,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),Ce&&st&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${Ce}`,"aria-label":`Open ${Ce} in file explorer`,role:"button",tabIndex:0,onClick:()=>f.openFileExplorer(Ce),onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),f.openFileExplorer(Ce))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(p,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:st})]}),ke&&ke.map(({areaId:n,areaName:r,dir:l})=>{const d=Ae.get(l),X=he.has(l),Q=l.split("/").filter(Boolean).pop()||l;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${r}: ${l}${d?` (${d.branch}${d.ahead?` ↑${d.ahead}`:""}${d.behind?` ↓${d.behind}`:""})`:""}`,onClick:()=>f.openFileExplorerForAreaFolder(n,l),children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:Q}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(p,{name:"git-branch",size:10})," ",d.branch]}),d.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${d.ahead} ahead`,children:[e.jsx(p,{name:"arrow-up",size:9}),d.ahead]}),d.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${d.behind} behind`,children:[e.jsx(p,{name:"arrow-down",size:9}),d.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${X?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:I=>{I.stopPropagation(),fe(l)},children:e.jsx(p,{name:X?"hourglass":"download",size:12})})]})]},`${n}:${l}`)}),e.jsx(ya,{agentId:o,disabled:((b==null?void 0:b.provider)??"claude")!=="claude",contextSummary:at?`Context: ${De}k / ${qe}k tokens (${gt}% used)`:void 0,children:e.jsxs("span",{className:"flat-terminal-wrapper__context",tabIndex:0,role:"button",onClick:()=>f.setContextModalAgentId(o),onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),f.setContextModalAgentId(o))},title:((b==null?void 0:b.provider)??"claude")!=="claude"?at?`Context usage: ${De}k / ${qe}k tokens (${gt}% used). Click to view stats.`:"Click to fetch context stats":void 0,children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(p,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${Te}%`,backgroundColor:ce}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:ce},children:[De,"k/",qe,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",Lt,"% free)"]}),!at&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(p,{name:"warn",size:12})})]})}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),He.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:He.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""} ${n.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${r?"Hide":"Show"} terminal: ${n.name}${n.hasUrl?"":" (starting...)"}`,onClick:()=>{if(r){oe();return}if(n.hasUrl&&rt(n.id)==="modal"){Ke(n.id);return}n.hasUrl||f.sendBuildingCommand(n.id,"start"),Re("terminal",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"terminal",size:14})},n.id)})}),Ue.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Ue.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""}`,title:`${r?"Hide":"Show"} logs: ${n.name}`,onClick:()=>{r?oe():rt(n.id)==="modal"?Ke(n.id):Re("pm2-logs",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"scroll",size:14})},n.id)})}),ge.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:ge.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""}`,title:`${r?"Hide":"Show"} database: ${n.name}`,onClick:()=>{r?oe():rt(n.id)==="modal"?Ke(n.id):Re("database",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"hard-drives",size:14})},n.id)})}),ue.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:ue.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""} ${n.working?"flat-terminal-wrapper__building-btn--tests-working":""}`,title:n.working?`Running tests: ${n.name}`:`${r?"Hide":"Show"} tests: ${n.name}`,onClick:()=>{r?oe():rt(n.id)==="modal"?Ke(n.id):Re("tests",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"flask",size:14})},n.id)})}),xe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area HTTP requests",children:xe.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""}`,title:`${r?"Hide":"Show"} HTTP requests: ${n.name}`,onClick:()=>{r?oe():rt(n.id)==="modal"?Ke(n.id):Re("http",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"globe",size:14})},n.id)})}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(ua,{})})]}),$e&&e.jsx(pa,{agentId:o,agents:nt,onClose:Tt,branchInfoMap:Ae,fetchRemote:fe,fetchingDirs:he,onResizeStart:n=>Et(n,"right")}),je&&e.jsx(ma,{agentId:o,onClose:Pt}),Z&&e.jsx(fa,{agentId:o,onClose:mt})]})});function Oa({onAgentClick:u,onBuildingClick:o,onBuildingDoubleClick:m,onBuildingPopup:h,onAreaContextMenu:y,onOpenSpawnModal:R,onOpenBossSpawnModal:P,onOpenAreaModal:z}){const{t:le}=Ht(["common"]),_=yn(),O=kn(),[$,U]=a.useState(null),[ee,te]=a.useState(null),[de,Be]=a.useState(null);An("flatview-image-modal",$!==null,()=>U(null));const[Ze,ct]=a.useState(null),[K,b]=a.useState(null),[T,Je]=a.useState(null),[re,Fe]=a.useState(null),[Pe,Qe]=a.useState(!1),dt=a.useCallback(()=>{Qe(t=>!t)},[]),We=a.useCallback(()=>{Qe(!1)},[]),[me,Le]=a.useState(()=>{const t=qt(E.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),et=a.useCallback(t=>{Le(t),Yt(E.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=s=>{if(s.key!==E.VIEW_MODE)return;const i=s.newValue;(i==="simple"||i==="chat"||i==="advanced")&&Le(i)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[ke,Ae]=a.useState(()=>Wt(E.FLAT_INSPECTOR_OPEN,!1)),[fe,he]=a.useState(!1),He=a.useCallback(()=>he(t=>!t),[]),Ue=a.useCallback(()=>he(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:fe}}))},[fe]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:ke}}))},[ke]),a.useEffect(()=>{const t=()=>he(C=>!C),s=()=>{Ae(C=>{const k=!C;return ye(E.FLAT_INSPECTOR_OPEN,k),k})},i=()=>{he(!1),Ae(!1),ye(E.FLAT_INSPECTOR_OPEN,!1)},g=()=>he(!1),x=()=>{Ae(!1),ye(E.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",s),window.addEventListener("tide-close-flat-side-views",i),window.addEventListener("tide-close-flat-agents-drawer-only",g),window.addEventListener("tide-close-flat-inspector-only",x),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",s),window.removeEventListener("tide-close-flat-side-views",i),window.removeEventListener("tide-close-flat-agents-drawer-only",g),window.removeEventListener("tide-close-flat-inspector-only",x)}},[]);const ge=a.useRef(null),Se=a.useRef(null),[ue,xe]=a.useState(()=>{const t=Kt(E.FLAT_MIDDLE_WIDTH,0);return t>=Nt?t:null}),[pe,be]=a.useState(()=>{const t=Kt(E.FLAT_INSPECTOR_WIDTH,0);return t>=Bt?t:null}),Ee=a.useCallback(t=>{if(typeof window>"u")return t;const s=pe!==null?Ct+pe:0,i=window.innerWidth-nn-Ct-tn-s;return Math.max(Nt,Math.min(Math.max(i,Nt),t))},[pe]),_e=a.useCallback(t=>{var x;if(typeof window>"u")return t;const s=(x=ge.current)==null?void 0:x.querySelector(".flat-middle"),i=(s==null?void 0:s.getBoundingClientRect().width)??Nt,g=window.innerWidth-nn-i-Ct-tn-Ct;return Math.max(Bt,Math.min(Math.max(g,Bt),t))},[]);a.useEffect(()=>{if(ue===null&&pe===null)return;const t=()=>{xe(s=>{if(s===null)return s;const i=Ee(s);return i===s?s:i}),be(s=>{if(s===null)return s;const i=_e(s);return i===s?s:i})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[ue,pe,Ee,_e]);const tt=a.useCallback(t=>{var i;if(t.button!==0)return;const s=(i=ge.current)==null?void 0:i.querySelector(".flat-middle");s&&(t.currentTarget.setPointerCapture(t.pointerId),Se.current={kind:"middle",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),j=a.useCallback(t=>{var i;if(t.button!==0)return;const s=(i=ge.current)==null?void 0:i.querySelector(".flat-inspector");s&&(t.currentTarget.setPointerCapture(t.pointerId),Se.current={kind:"inspector",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),we=a.useCallback(t=>{const s=Se.current;if(!s||t.pointerId!==s.pointerId)return;const i=t.clientX-s.startX;s.kind==="middle"?xe(Ee(s.startWidth+i)):be(_e(s.startWidth-i))},[Ee,_e]),B=a.useCallback(t=>{const s=Se.current;if(!s||t.pointerId!==s.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(Se.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-s.startX)>2))return;const g=t.clientX-s.startX;if(s.kind==="middle"){const x=Ee(s.startWidth+g);xe(x),jt(E.FLAT_MIDDLE_WIDTH,x)}else{const x=_e(s.startWidth-g);be(x),jt(E.FLAT_INSPECTOR_WIDTH,x)}},[Ee,_e]),ut=a.useCallback(()=>{xe(null),jt(E.FLAT_MIDDLE_WIDTH,0)},[]),Ie=a.useCallback(()=>{be(null),jt(E.FLAT_INSPECTOR_WIDTH,0)},[]),[ve,yt]=a.useState(()=>qt(E.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),D=a.useCallback(t=>{yt(t),Yt(E.FLAT_INSPECTOR_VIEW,t)},[]),Re=a.useCallback(()=>{Ae(t=>{const s=!t;return ye(E.FLAT_INSPECTOR_OPEN,s),s})},[]),oe=a.useCallback(()=>{Ae(!1),ye(E.FLAT_INSPECTOR_OPEN,!1)},[]),kt=Sn(),At=a.useCallback((t,s)=>{U({url:t,name:s})},[]),St=a.useCallback((t,s)=>{te({command:t,output:s,isLive:!1})},[]),Et=a.useCallback((t,s)=>{var x;const i=O.size>0?Array.from(O)[0]:null,g=i?(x=f.getState().agents.get(i))==null?void 0:x.cwd:void 0;f.setFileViewerPath(t,s,g)},[O]),$e=a.useCallback(t=>{Be(t)},[]),pt=a.useCallback((t,s)=>{ct({agentId:t,count:s})},[]),je=a.useCallback(t=>{m?m(t):o(t)},[o,m]),v=a.useMemo(()=>O.size>0?Array.from(O)[0]:null,[O]);a.useEffect(()=>{Qe(!1)},[v]);const Z=a.useRef([]),ne=a.useRef(-1),Ve=a.useRef(!1),mt=a.useRef(null),[It,Mt]=a.useState(!1),[Tt,Pt]=a.useState(!1),nt=a.useRef(!1),ae=a.useRef(null),Xe=a.useRef(!1),se=a.useMemo(()=>new Set(_.map(t=>t.id)),[_]),Me=a.useMemo(()=>{const t=new Map(_.map(i=>[i.id,i])),s=new Map;for(const i of _)if((i.isBoss||i.class==="boss")&&i.subordinateIds&&i.subordinateIds.length>0){const g=i.subordinateIds.map(x=>t.get(x)).filter(x=>x!==void 0);g.length>0&&s.set(i.id,g)}return s},[_]),J=a.useCallback(()=>{const t=Z.current,s=ne.current;Mt(s>0),Pt(s>=0&&s<t.length-1)},[]),V=a.useCallback(t=>{const s=Z.current;if(s.length===0)return;let i=ne.current+t;for(;i>=0&&i<s.length;){const g=s[i];if(se.has(g)){Ve.current=!0,ne.current=i,J(),f.selectAgent(g);return}i+=t}},[se,J]),at=a.useCallback(()=>V(-1),[V]),ft=a.useCallback(()=>V(1),[V]);_a(a.useCallback(()=>{const t=Z.current,s=ne.current;return t.length>0&&s>0?(V(-1),"handled"):"exit"},[V]));const Ge=a.useCallback((t,s)=>{if(typeof window>"u")return;const i=window.history.state,x={...typeof i=="object"&&i!==null?i:{},__flatAgentNav:{agentId:t}};s==="replace"?window.history.replaceState(x,"",window.location.href):window.history.pushState(x,"",window.location.href)},[]);a.useEffect(()=>{if(!v){nt.current=!1,ae.current=null;return}if(!nt.current){Ge(v,"replace"),nt.current=!0,ae.current=v;return}if(Xe.current){Xe.current=!1,ae.current=v;return}ae.current!==v&&(Ge(v,"push"),ae.current=v)},[v,Ge]),a.useEffect(()=>{const t=s=>{var C,k;const i=(k=(C=s.state)==null?void 0:C.__flatAgentNav)==null?void 0:k.agentId;if(!i||typeof i!="string"||!se.has(i)||i===v)return;Xe.current=!0,Ve.current=!0;const g=Z.current,x=g.lastIndexOf(i);x>=0?ne.current=x:(g.push(i),ne.current=g.length-1),J(),f.selectAgent(i)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[se,v,J]),a.useEffect(()=>{if(!v){Z.current=[],ne.current=-1,J();return}if(mt.current=v,Ve.current){Ve.current=!1,J();return}const t=Z.current,s=ne.current;if(s>=0&&t[s]===v){J();return}const i=s<t.length-1?t.slice(0,s+1):t.slice();i.push(v),i.length>100&&i.shift(),Z.current=i,ne.current=i.length-1,J()},[v,J]);const ht=a.useCallback(t=>{u(t),he(!1)},[u]),Te=v??"",gt=a.useCallback(()=>{},[]),Lt=a.useCallback(t=>{ht(t)},[ht]),ce=ke,[De,qe]=a.useState(ce),[Ce,st]=a.useState(ce);a.useEffect(()=>{if(ce){qe(!0);return}st(!1);const t=setTimeout(()=>qe(!1),240);return()=>clearTimeout(t)},[ce]),a.useEffect(()=>{if(!De||!ce)return;let t=0;const s=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>st(!0))});return()=>{cancelAnimationFrame(s),cancelAnimationFrame(t)}},[De,ce]);const ze=a.useRef(null);a.useEffect(()=>{if(v)return;const t=s=>{if(s.key!==" "&&s.key!=="Backspace")return;const i=s.target;if(i.tagName==="INPUT"||i.tagName==="TEXTAREA"||i.isContentEditable)return;const g=mt.current;!g||!se.has(g)||(s.preventDefault(),f.selectAgent(g))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[v,se]);const[Rt,it]=a.useState(new Set),xt=a.useCallback(t=>{it(s=>{const i=new Set(s);return i.has(t)?i.delete(t):i.add(t),i})},[]),[n,r]=a.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),s=i=>r(i.matches);return t.addEventListener("change",s),()=>t.removeEventListener("change",s)},[]);const[l,d]=a.useState(null),X=a.useCallback(t=>{d(s=>s===t?null:t)},[]),Q=on(),I=cn(),[Ye]=En(),Ne=a.useMemo(()=>{const t=new Map,s=[];for(const w of _){const S=f.getAreaForAgent(w.id);if(!Zt((S==null?void 0:S.id)??null))continue;if(!S||S.archived){s.push(w);continue}const M=t.get(S.id);M?M.push(w):t.set(S.id,[w])}const i=new Map,g=[];for(const w of I.values()){let S=!1;for(const M of Q.values())if(!M.archived&&Jt(M.id)&&f.isPositionInArea(w.position,M)){const G=i.get(M.id);G?G.push(w):i.set(M.id,[w]),S=!0;break}!S&&Zt(null)&&g.push(w)}const x=[];for(const[,w]of Q){if(w.archived||!Jt(w.id))continue;const S=t.get(w.id),M=i.get(w.id)??[];(S&&S.length>0||M.length>0)&&x.push({area:w,agents:S??[],buildings:M})}(s.length>0||g.length>0)&&x.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:s,buildings:g});const C=x.filter(w=>w.area.id!=="__unassigned__"),k=x.filter(w=>w.area.id==="__unassigned__");let c=1,A=1;const H=new Map;if(C.length>1){let w=1/0,S=-1/0,M=1/0,G=-1/0;for(const q of C)w=Math.min(w,q.area.center.x),S=Math.max(S,q.area.center.x),M=Math.min(M,q.area.center.z),G=Math.max(G,q.area.center.z);const _t=S-w||1,wt=G-M||1;if(C.length<=4){c=C.length,A=1;const q=[...C].sort((Y,$t)=>Y.area.center.x-$t.area.center.x);for(let Y=0;Y<q.length;Y++)H.set(q[Y].area.id,{row:1,col:Y+1})}else{const q=[...C].sort((N,F)=>N.area.center.x-F.area.center.x),Y=[];for(let N=1;N<q.length;N++)Y.push(q[N].area.center.x-q[N-1].area.center.x);const $t=Y.reduce((N,F)=>N+F,0)/Y.length||1;let Ut=1;for(const N of Y)N>$t*1.3&&Ut++;c=Math.max(2,Math.min(Ut,C.length));const Dt=[...C].sort((N,F)=>N.area.center.z-F.area.center.z),vt=[];for(let N=1;N<Dt.length;N++)vt.push(Dt[N].area.center.z-Dt[N-1].area.center.z);const fn=vt.reduce((N,F)=>N+F,0)/vt.length||1;let Vt=1;for(const N of vt)N>fn*1.3&&Vt++;A=Math.max(2,Math.min(Vt,C.length)),c=Math.max(c,Math.ceil(C.length/A)),A=Math.max(A,Math.ceil(C.length/c));const hn=_t/c,gn=wt/A,zt=new Set;for(const N of C){let F=Math.min(c-1,Math.max(0,Math.floor((N.area.center.x-w)/hn))),Oe=Math.min(A-1,Math.max(0,Math.floor((N.area.center.z-M)/gn))),lt=`${Oe},${F}`,Xt=0;const xn=A*c;for(;zt.has(lt)&&Xt<xn;)F++,F>=c&&(F=0,Oe=(Oe+1)%A),lt=`${Oe},${F}`,Xt++;zt.has(lt)&&(Oe=A,F=0,lt=`${Oe},${F}`,A++),zt.add(lt),H.set(N.area.id,{row:Oe+1,col:F+1})}}}const L=w=>{w.sort((S,M)=>{var _t,wt,q,Y;const G=(((_t=S.position)==null?void 0:_t.z)??0)-(((wt=M.position)==null?void 0:wt.z)??0);return G!==0?G:(((q=S.position)==null?void 0:q.x)??0)-(((Y=M.position)==null?void 0:Y.x)??0)})};for(const w of C)L(w.agents);for(const w of k)L(w.agents);return{groups:[...C,...k],gridCols:c,gridRows:A,positions:H}},[_,Q,I,Ye]),bt=a.useMemo(()=>{if(!K)return[];const t=_.find(s=>s.id===K.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(p,{name:"chat",size:14}),onClick:()=>u(t.id)},{id:"clone-agent",label:"Clone Agent",icon:e.jsx(p,{name:"clipboard",size:14}),onClick:()=>f.cloneAgent(t.id)},{id:"fork-agent",label:"Fork Agent (with history)",icon:e.jsx(p,{name:"git-branch",size:14}),onClick:()=>f.forkAgent(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>{Fe({agentId:t.id,name:t.name})}}]:[]},[K,_,u]),ie=a.useMemo(()=>{var C;if(!T)return[];const t=I.get(T.buildingId);if(!t)return[];const s=[],i=t.type==="server"||t.type==="docker"||t.type==="terminal",g=t.status==="running",x=t.type==="boss";if(s.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="tests"?"Open Tests":t.type==="http"?"Open Requests":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((C=t.pm2)!=null&&C.enabled)?"View PM2 Logs":"Open",icon:e.jsx(p,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="tests"?"flask":t.type==="http"?"globe":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>je(t.id)}),i&&(g||s.push({id:"start",label:"Start",icon:e.jsx(p,{name:"play",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"start")}),g&&(s.push({id:"restart",label:"Restart",icon:e.jsx(p,{name:"refresh",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"restart")}),s.push({id:"stop",label:"Stop",icon:e.jsx(p,{name:"stop",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"stop")}))),x&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(s.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(p,{name:"launch",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)f.sendBuildingCommand(k,"start")}}),s.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(p,{name:"pause",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)f.sendBuildingCommand(k,"stop")}}),s.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(p,{name:"restart",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)f.sendBuildingCommand(k,"restart")}})),i&&s.push({id:"health-check",label:"Health Check",icon:e.jsx(p,{name:"health",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"healthCheck")}),s.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),s.push({id:"edit",label:"Edit Building",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),s.push({id:"clone",label:"Clone Building",icon:e.jsx(p,{name:"copy",size:14}),onClick:()=>{f.createBuilding({name:`${t.name} (Copy)`,type:t.type,style:t.style,color:t.color,scale:t.scale,position:{x:t.position.x+2,z:t.position.z+2},cwd:t.cwd,folderPath:t.folderPath,commands:t.commands,pm2:t.pm2,docker:t.docker,database:t.database,terminal:t.terminal,urls:t.urls,subordinateBuildingIds:t.subordinateBuildingIds})}}),t.urls&&t.urls.length>0)for(const k of t.urls)s.push({id:`url-${k.label}`,label:k.label,icon:e.jsx(p,{name:"link",size:14}),onClick:()=>window.open(k.url,"_blank","noopener,noreferrer")});return s.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),s.push({id:"delete",label:"Delete Building",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>f.deleteBuilding(t.id)}),s},[T,I,je]),W=a.useCallback(t=>{const s=new Set(Ne.groups.map(i=>i.area.id));s.delete(t),it(s),requestAnimationFrame(()=>{const i=ze.current;if(!i)return;const g=i.querySelector(`[data-area-id="${t}"]`);if(!g)return;const x=i.getBoundingClientRect(),k=g.getBoundingClientRect().top-x.top+i.scrollTop-8;i.scrollTo({top:Math.max(0,k),behavior:"smooth"})})},[Ne]);return e.jsxs("div",{ref:ge,className:`flat-view ${ce?"flat-view--with-inspector":""} ${v?"flat-view--has-chat":""} ${fe?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(ue===null&&pe===null)return;const t={};return ue!==null&&(t["--flat-middle-width"]=`${ue}px`),pe!==null&&(t["--flat-inspector-width"]=`${pe}px`),t})(),children:[fe&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Ue,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children:e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:R,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:P,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:z,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(In,{activeAgentId:Te,onClose:gt,onSelectAgent:Lt,collapsedAreas:Rt,onToggleArea:xt,agentListRef:ze})})]}),e.jsx("div",{className:"flat-splitter flat-splitter--middle",role:"separator","aria-orientation":"vertical","aria-label":"Resize agents panel",title:"Drag to resize · Double-click to reset",onPointerDown:tt,onPointerMove:we,onPointerUp:B,onPointerCancel:B,onDoubleClick:ut}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":fe?"Close agents sidebar":"Open agents sidebar","aria-expanded":fe,onClick:He,children:[e.jsx(p,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),v?e.jsx(La,{agentId:v,terminalViewMode:me,onTerminalViewModeChange:et,inspectorOpen:ke,onToggleInspector:Re,onImageClick:At,onFileClick:Et,onBashClick:St,onViewMarkdown:$e,onRequestClearSubordinates:pt,keyboard:kt,canNavigateBack:It,canNavigateForward:Tt,onNavigateBack:at,onNavigateForward:ft,agentInfoOpen:Pe,onToggleAgentInfo:dt,onHeaderContextMenu:t=>{v&&b({agentId:v,position:t})},onBuildingContextMenu:(t,s)=>{Je({buildingId:t,position:s})}}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"}),e.jsx(ka,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Ne.gridCols}, 1fr)`},children:Ne.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var s;const t=n&&l?((s=Ne.positions.get(l))==null?void 0:s.row)??null:null;return Ne.groups.map(i=>{var k;const g=i.area.id,x=Ne.positions.get(g),C=n&&l!==g;return n&&t!=null&&(x==null?void 0:x.row)===t&&g!==l?null:e.jsxs("div",{className:`flat-map-area-card${C?" flat-map-area-card--collapsed":""}`,style:{"--area-color":i.area.color,gridRow:x==null?void 0:x.row,gridColumn:x==null?void 0:x.col},onContextMenu:c=>{y&&(c.preventDefault(),c.stopPropagation(),y(g,{x:c.clientX,y:c.clientY}))},children:[((k=i.area.logo)==null?void 0:k.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:ba(i.area.logo.filename),alt:"","aria-hidden":"true",onError:c=>{c.currentTarget.style.display="none"}}),e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>n?X(g):W(g),title:n?C?`Expand ${i.area.name}`:`Collapse ${i.area.name}`:`Focus ${i.area.name} in left panel`,"aria-expanded":n?!C:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:i.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:i.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:i.agents.length}),n&&e.jsx(p,{name:C?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:i.agents.map(c=>{const A=c.isBoss||c.class==="boss",H=A?Me.get(c.id):void 0,L=Mn(c),w=L.usedPercent>=80?"#ff4a4a":L.usedPercent>=60?"#ff9e4a":L.usedPercent>=40?"#ffd700":"#4aff9e",S=`Context: ${(L.totalTokens/1e3).toFixed(1)}k / ${(L.contextWindow/1e3).toFixed(1)}k (${L.usedPercent}% used, ${L.freePercent}% free)`,M=c.latestTodos&&c.latestTodos.length>0||H&&H.length>0;return e.jsx(Tn,{todos:c.latestTodos,subordinates:H,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${c.status}`,onClick:()=>u(c.id),onContextMenu:G=>{G.preventDefault(),G.stopPropagation(),b({agentId:c.id,position:{x:G.clientX,y:G.clientY}})},title:M?void 0:`${A?"Boss · ":""}Open chat with ${c.name}
2
2
  ${S}`,children:[e.jsx(dn,{agent:c,size:16}),A&&e.jsx("span",{className:"flat-map-agent-chip__crown","aria-hidden":"true",children:e.jsx(p,{name:"crown",size:11,color:"#ffd700",weight:"fill"})}),e.jsx("span",{className:"flat-map-agent-chip__name",children:c.name}),e.jsx("img",{src:c.provider==="codex"?"/assets/codex.png":c.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:c.provider,className:"flat-map-agent-chip__provider-icon",title:c.provider==="codex"?"Codex Agent":c.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:un(c.status)}}),c.latestTodos&&c.latestTodos.length>0&&e.jsx(Pn,{todos:c.latestTodos,maxDots:6}),A&&H&&H.length>0&&e.jsx(Ln,{subordinates:H,maxDots:6}),e.jsx("span",{className:"flat-map-agent-chip__context-bar","aria-hidden":"true",children:e.jsx("span",{className:"flat-map-agent-chip__context-bar-fill",style:{width:`${L.usedPercent}%`,backgroundColor:w}})})]})},c.id)})}),i.area.directories.length>0&&e.jsx("div",{className:"flat-map-area-card__folders",role:"group","aria-label":`${i.area.name} folders`,children:i.area.directories.map(c=>{const A=c.split("/").filter(Boolean).pop()||c;return e.jsxs("button",{type:"button",className:"flat-map-folder-chip",onClick:H=>{H.stopPropagation(),f.openFileExplorerForAreaFolder(g,c)},title:`Open in file explorer: ${c}`,children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-map-folder-chip__name",children:A})]},c)})}),i.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:i.buildings.map(c=>{var H;const A=(H=Rn[c.type])==null?void 0:H.color;return e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${c.status}`,style:A?{"--building-type-color":A}:void 0,onClick:L=>{if(h){const w=L.currentTarget.getBoundingClientRect();h(c.id,{x:w.right,y:w.top+w.height/2})}else je(c.id)},onContextMenu:L=>{L.preventDefault(),L.stopPropagation(),Je({buildingId:c.id,position:{x:L.clientX,y:L.clientY}})},title:`${c.name} · ${c.type} · ${c.status}`,children:[e.jsx(p,{name:$n(c.type),size:12,color:A}),e.jsx("span",{className:"flat-map-building-chip__name",children:c.name}),e.jsx("span",{className:"flat-map-building-chip__dot",style:{backgroundColor:Dn(c.status)}})]},c.id)})})]},g)})})()})]})})]}),ce&&e.jsx("div",{className:"flat-splitter flat-splitter--inspector",role:"separator","aria-orientation":"vertical","aria-label":"Resize inspector panel",title:"Drag to resize · Double-click to reset",onPointerDown:j,onPointerMove:we,onPointerUp:B,onPointerCancel:B,onDoubleClick:Ie}),De&&e.jsxs("aside",{className:`flat-inspector ${Ce?"flat-inspector--open":"flat-inspector--closing"}`,"aria-label":"Inspector panel",children:[e.jsxs("div",{className:"flat-inspector__header",children:[e.jsxs("div",{className:"flat-inspector__tabs",role:"tablist","aria-label":"Inspector view",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":ve==="agent",className:`flat-inspector__tab ${ve==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>D("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":ve==="tracking",className:`flat-inspector__tab ${ve==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>D("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:oe,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:ve==="tracking"?e.jsx(zn,{activeAgentId:v??"",onSelectAgent:t=>{u(t),window.innerWidth<=768&&oe()}}):(()=>{if(!v)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=_.find(s=>s.id===v);return t?e.jsx(On,{agent:t,onFocusAgent:s=>{u(s),window.innerWidth<=768&&oe()},onKillAgent:s=>f.killAgent(s)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),$&&e.jsx(Bn,{url:$.url,name:$.name,onClose:()=>U(null)}),ee&&e.jsx(Fn,{state:ee,onClose:()=>te(null)}),e.jsx(Wn,{agent:v?_.find(t=>t.id===v)??null:null,content:de,onClose:()=>Be(null)}),Ze&&e.jsx(Hn,{action:"clear-subordinates",selectedAgentId:Ze.agentId,subordinateCount:Ze.count,onClose:()=>ct(null),onClearHistory:()=>{}}),e.jsx(Un,{agent:v?_.find(t=>t.id===v)??null:null,isOpen:Pe&&!!v,onClose:We}),e.jsx(Qt,{isOpen:K!==null,position:(K==null?void 0:K.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:bt,onClose:()=>b(null)}),e.jsx(Qt,{isOpen:T!==null,position:(T==null?void 0:T.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:ie,onClose:()=>Je(null)}),e.jsx(Vn,{isOpen:re!==null,title:le("common:confirm.removeAgentTitle"),message:le("common:confirm.removeAgentMessage",{name:(re==null?void 0:re.name)??""}),confirmLabel:le("common:buttons.remove"),cancelLabel:le("common:buttons.cancel"),variant:"danger",onConfirm:()=>{re&&f.removeAgentFromServer(re.agentId)},onClose:()=>Fe(null)})]})}export{Oa as FlatView};
@@ -1 +1 @@
1
- import{h as At,i as yt,ay as Et,a2 as xt,a3 as Ct,ck as Mt,cl as Ft,aP as wt,r as d,Y as St,S as ge,cm as vt,cn as fe,s as V,co as Bt,j as f,I as ne,cp as Ve,cq as It,a7 as _t,cr as Dt,cs as kt,ct as Ee,am as Be,X as Rt,p as nt,u as Fe,cu as Je}from"./main-BYtCWmOh.js";import{cv as Ls,cw as $s,cx as js,cy as Ns,cz as Ps}from"./main-BYtCWmOh.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function re(t){return Array.isArray?Array.isArray(t):it(t)==="[object Array]"}function bt(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Tt(t){return t==null?"":bt(t)}function Z(t){return typeof t=="string"}function rt(t){return typeof t=="number"}function Lt(t){return t===!0||t===!1||$t(t)&&it(t)=="[object Boolean]"}function ct(t){return typeof t=="object"}function $t(t){return ct(t)&&t!==null}function G(t){return t!=null}function Ie(t){return!t.trim().length}function it(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const jt="Incorrect 'index' type",Nt=t=>`Invalid value for key ${t}`,Pt=t=>`Pattern length exceeds max of ${t}.`,Kt=t=>`Missing ${t} property in key`,Ot=t=>`Property 'weight' in key '${t}' must be a positive integer`,Xe=Object.prototype.hasOwnProperty;class zt{constructor(e){this._keys=[],this._keyMap={};let n=0;e.forEach(r=>{let c=ot(r);this._keys.push(c),this._keyMap[c.id]=c,n+=c.weight}),this._keys.forEach(r=>{r.weight/=n})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function ot(t){let e=null,n=null,r=null,c=1,i=null;if(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")&&(c=t.weight,c<=0))throw new Error(Ot(o));e=qe(o),n=_e(o),i=t.getFn}return{path:e,id:n,weight:c,src:r,getFn:i}}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 c=(i,o,a)=>{if(G(i))if(!o[a])n.push(i);else{let u=o[a];const l=i[u];if(!G(l))return;if(a===o.length-1&&(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)c(l[h],o,a+1)}else o.length&&c(l,o,a+1)}};return c(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(c){const i=c.match(Yt).length;if(n.has(i))return n.get(i);const o=1/Math.pow(i,.5*t),a=parseFloat(Math.round(o*r)/r);return n.set(i,a),a},clear(){n.clear()}}}class Le{constructor({getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){this.norm=Vt(n,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((n,r)=>{this._keysMap[n.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,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((c,i)=>{let o=c.getFn?c.getFn(e):this.getFn(e,c.path);if(G(o)){if(re(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(G(h))if(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.$[i]=a}else if(Z(o)&&!Ie(o)){let a={v:o,n:this.norm.get(o)};r.$[i]=a}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function at(t,e,{getFn:n=y.getFn,fieldNormWeight:r=y.fieldNormWeight}={}){const c=new Le({getFn:n,fieldNormWeight:r});return c.setKeys(t.map(ot)),c.setSources(e),c.create(),c}function Jt(t,{getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){const{keys:r,records:c}=t,i=new Le({getFn:e,fieldNormWeight:n});return i.setKeys(r),i.setIndexRecords(c),i}function xe(t,{errors:e=0,currentLocation:n=0,expectedLocation:r=0,distance:c=y.distance,ignoreLocation:i=y.ignoreLocation}={}){const o=e/t.length;if(i)return o;const a=Math.abs(r-n);return c?o+a/c:a?1:o}function Xt(t=[],e=y.minMatchCharLength){let n=[],r=-1,c=-1,i=0;for(let o=t.length;i<o;i+=1){let a=t[i];a&&r===-1?r=i:!a&&r!==-1&&(c=i-1,c-r+1>=e&&n.push([r,c]),r=-1)}return t[i-1]&&i-r>=e&&n.push([r,i-1]),n}const le=32;function qt(t,e,n,{location:r=y.location,distance:c=y.distance,threshold:i=y.threshold,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,includeMatches:u=y.includeMatches,ignoreLocation:l=y.ignoreLocation}={}){if(e.length>le)throw new Error(Pt(le));const h=e.length,E=t.length,x=Math.max(0,Math.min(r,E));let p=i,g=x;const S=a>1||u,w=S?Array(E):[];let T;for(;(T=t.indexOf(e,g))>-1;){let $=xe(e,{currentLocation:T,expectedLocation:x,distance:c,ignoreLocation:l});if(p=Math.min($,p),g=T+h,S){let N=0;for(;N<h;)w[T+N]=1,N+=1}}g=-1;let j=[],Q=1,W=h+E;const oe=1<<h-1;for(let $=0;$<h;$+=1){let N=0,D=W;for(;N<D;)xe(e,{errors:$,currentLocation:x+D,expectedLocation:x,distance:c,ignoreLocation:l})<=p?N=D:W=D,D=Math.floor((W-N)/2+N);W=D;let ae=Math.max(1,x-D+1),H=o?E:Math.min(x+D,E)+h,v=Array(H+2);v[H+1]=(1<<$)-1;for(let R=H;R>=ae;R-=1){let X=R-1,O=n[t.charAt(X)];if(S&&(w[X]=+!!O),v[R]=(v[R+1]<<1|1)&O,$&&(v[R]|=(j[R+1]|j[R])<<1|1|j[R+1]),v[R]&oe&&(Q=xe(e,{errors:$,currentLocation:X,expectedLocation:x,distance:c,ignoreLocation:l}),Q<=p)){if(p=Q,g=X,g<=x)break;ae=Math.max(1,2*x-g)}}if(xe(e,{errors:$+1,currentLocation:x,expectedLocation:x,distance:c,ignoreLocation:l})>p)break;j=v}const ce={isMatch:g>=0,score:Math.max(.001,Q)};if(S){const $=Xt(w,a);$.length?u&&(ce.indices=$):ce.isMatch=!1}return ce}function Zt(t){let e={};for(let n=0,r=t.length;n<r;n+=1){const c=t.charAt(n);e[c]=(e[c]||0)|1<<r-n-1}return e}const Ce=String.prototype.normalize?(t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(t=>t);class ut{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:c=y.distance,includeMatches:i=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){if(this.options={location:n,threshold:r,distance:c,includeMatches:i,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h},e=u?e:e.toLowerCase(),e=l?Ce(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const E=(p,g)=>{this.chunks.push({pattern:p,alphabet:Zt(p),startIndex:g})},x=this.pattern.length;if(x>le){let p=0;const g=x%le,S=x-g;for(;p<S;)E(this.pattern.substr(p,le),p),p+=le;if(g){const w=x-le;E(this.pattern.substr(w),w)}}else E(this.pattern,0)}searchIn(e){const{isCaseSensitive:n,ignoreDiacritics:r,includeMatches:c}=this.options;if(e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern===e){let S={isMatch:!0,score:0};return c&&(S.indices=[[0,e.length-1]]),S}const{location:i,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let E=[],x=0,p=!1;this.chunks.forEach(({pattern:S,alphabet:w,startIndex:T})=>{const{isMatch:j,score:Q,indices:W}=qt(e,S,w,{location:i+T,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:c,ignoreLocation:h});j&&(p=!0),x+=Q,j&&W&&(E=[...E,...W])});let g={isMatch:p,score:p?x/this.chunks.length:1};return p&&c&&(g.indices=E),g}}class ie{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 ie{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const n=e===this.pattern;return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ts extends ie{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const r=e.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}}class ss extends ie{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const n=e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ns extends ie{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const n=!e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class rs extends ie{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const n=e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class cs extends ie{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const n=!e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class lt extends ie{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:c=y.distance,includeMatches:i=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){super(e),this._bitapSearch=new ut(e,{location:n,threshold:r,distance:c,includeMatches:i,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class ht extends ie{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let n=0,r;const c=[],i=this.pattern.length;for(;(r=e.indexOf(this.pattern,n))>-1;)n=r+i,c.push([r,n-1]);const o=!!c.length;return{isMatch:o,score:o?0:1,indices:c}}}const De=[es,ht,ss,ns,cs,rs,ts,lt],et=De.length,is=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,os="|";function as(t,e={}){return t.split(os).map(n=>{let r=n.trim().split(is).filter(i=>i&&!!i.trim()),c=[];for(let i=0,o=r.length;i<o;i+=1){const a=r[i];let u=!1,l=-1;for(;!u&&++l<et;){const h=De[l];let E=h.isMultiMatch(a);E&&(c.push(new h(E,e)),u=!0)}if(!u)for(l=-1;++l<et;){const h=De[l];let E=h.isSingleMatch(a);if(E){c.push(new h(E,e));break}}}return c})}const us=new Set([lt.type,ht.type]);class ls{constructor(e,{isCaseSensitive:n=y.isCaseSensitive,ignoreDiacritics:r=y.ignoreDiacritics,includeMatches:c=y.includeMatches,minMatchCharLength:i=y.minMatchCharLength,ignoreLocation:o=y.ignoreLocation,findAllMatches:a=y.findAllMatches,location:u=y.location,threshold:l=y.threshold,distance:h=y.distance}={}){this.query=null,this.options={isCaseSensitive:n,ignoreDiacritics:r,includeMatches:c,minMatchCharLength:i,findAllMatches:a,ignoreLocation:o,location:u,threshold:l,distance:h},e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern=e,this.query=as(this.pattern,this.options)}static condition(e,n){return n.useExtendedSearch}searchIn(e){const n=this.query;if(!n)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:c,ignoreDiacritics:i}=this.options;e=c?e:e.toLowerCase(),e=i?Ce(e):e;let o=0,a=[],u=0;for(let l=0,h=n.length;l<h;l+=1){const E=n[l];a.length=0,o=0;for(let x=0,p=E.length;x<p;x+=1){const g=E[x],{isMatch:S,indices:w,score:T}=g.search(e);if(S){if(o+=1,u+=T,r){const j=g.constructor.type;us.has(j)?a=[...a,...w]:a.push(w)}}else{u=0,o=0,a.length=0;break}}if(o){let x={isMatch:!0,score:u/o};return r&&(x.indices=a),x}}return{isMatch:!1,score:1}}}const ke=[];function hs(...t){ke.push(...t)}function Re(t,e){for(let n=0,r=ke.length;n<r;n+=1){let c=ke[n];if(c.condition(t,e))return new c(t,e)}return new ut(t,e)}const Me={AND:"$and",OR:"$or"},be={PATH:"$path",PATTERN:"$val"},Te=t=>!!(t[Me.AND]||t[Me.OR]),ds=t=>!!t[be.PATH],fs=t=>!re(t)&&ct(t)&&!Te(t),tt=t=>({[Me.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function dt(t,e,{auto:n=!0}={}){const r=c=>{let i=Object.keys(c);const o=ds(c);if(!o&&i.length>1&&!Te(c))return r(tt(c));if(fs(c)){const u=o?c[be.PATH]:i[0],l=o?c[be.PATTERN]:c[u];if(!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:i[0]};return i.forEach(u=>{const l=c[u];re(l)&&l.forEach(h=>{a.children.push(r(h))})}),a};return Te(t)||(t=tt(t)),r(t)}function ps(t,{ignoreFieldNorm:e=y.ignoreFieldNorm}){t.forEach(n=>{let r=1;n.matches.forEach(({key:c,norm:i,score:o})=>{const a=c?c.weight:null;r*=Math.pow(o===0&&a?Number.EPSILON:o,(a||1)*(e?1:i))}),n.score=r})}function gs(t,e){const n=t.matches;e.matches=[],G(n)&&n.forEach(r=>{if(!G(r.indices)||!r.indices.length)return;const{indices:c,value:i}=r;let o={indices:c,value:i};r.key&&(o.key=r.key.src),r.idx>-1&&(o.refIndex=r.idx),e.matches.push(o)})}function ms(t,e){e.score=t.score}function As(t,e,{includeMatches:n=y.includeMatches,includeScore:r=y.includeScore}={}){const c=[];return n&&c.push(gs),r&&c.push(ms),t.map(i=>{const{idx:o}=i,a={item:e[o],refIndex:o};return c.length&&c.forEach(u=>{u(i,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,c=this._docs.length;r<c;r+=1){const i=this._docs[r];e(i,r)&&(this.removeAt(r),r-=1,c-=1,n.push(i))}return n}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:n=-1}={}){const{includeMatches:r,includeScore:c,shouldSort:i,sortFn:o,ignoreFieldNorm:a}=this.options;let u=Z(e)?Z(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return ps(u,{ignoreFieldNorm:a}),i&&u.sort(o),rt(n)&&n>-1&&(u=u.slice(0,n)),As(u,this._docs,{includeMatches:r,includeScore:c})}_searchStringList(e){const n=Re(e,this.options),{records:r}=this._myIndex,c=[];return r.forEach(({v:i,i:o,n:a})=>{if(!G(i))return;const{isMatch:u,score:l,indices:h}=n.searchIn(i);u&&c.push({item:i,idx:o,matches:[{score:l,value:i,norm:a,indices:h}]})}),c}_searchLogical(e){const n=dt(e,this.options),r=(a,u,l)=>{if(!a.children){const{keyId:E,searcher:x}=a,p=this._findMatches({key:this._keyStore.get(E),value:this._myIndex.getValueForItemAtKeyId(u,E),searcher:x});return p&&p.length?[{idx:l,item:u,matches:p}]:[]}const h=[];for(let E=0,x=a.children.length;E<x;E+=1){const p=a.children[E],g=r(p,u,l);if(g.length)h.push(...g);else if(a.operator===Me.AND)return[]}return h},c=this._myIndex.records,i={},o=[];return c.forEach(({$:a,i:u})=>{if(G(a)){let l=r(n,a,u);l.length&&(i[u]||(i[u]={idx:u,item:a,matches:[]},o.push(i[u])),l.forEach(({matches:h})=>{i[u].matches.push(...h)}))}}),o}_searchObjectList(e){const n=Re(e,this.options),{keys:r,records:c}=this._myIndex,i=[];return c.forEach(({$:o,i:a})=>{if(!G(o))return;let u=[];r.forEach((l,h)=>{u.push(...this._findMatches({key:l,value:o[h],searcher:n}))}),u.length&&i.push({idx:a,item:o,matches:u})}),i}_findMatches({key:e,value:n,searcher:r}){if(!G(n))return[];let c=[];if(re(n))n.forEach(({v:i,i:o,n:a})=>{if(!G(i))return;const{isMatch:u,score:l,indices:h}=r.searchIn(i);u&&c.push({score:l,key:e,value:i,idx:o,norm:a,indices:h})});else{const{v:i,n:o}=n,{isMatch:a,score:u,indices:l}=r.searchIn(i);a&&c.push({score:u,key:e,value:i,norm:o,indices:l})}return c}}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 c=await n.json().catch(()=>({}));throw new Error(c.error||`Failed to search folders: ${n.statusText}`)}const r=await n.json();return Array.isArray(r.folders)?r.folders:[]}const Es=["command","agent","building","area","folder","modified-file"],xs=2;function Cs(){const t=nt(ge.SPOTLIGHT_TAB,"all");return fe.includes(t)?t:"all"}function st(){return Rt(ge.SPOTLIGHT_QUERY,"")}function Ms(){const t=nt(ge.AOP_CONFIG,{});return t.sortMode==="name"||t.sortMode==="status"||t.sortMode==="recent"?t.sortMode:"recent"}function Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=Et(),E=xt(),x=Ct(),p=Mt(),g=Ft(),S=wt(),w=d.useRef(e);w.current=e;const T=d.useRef(n);T.current=n;const j=d.useRef(r);j.current=r;const Q=d.useRef(c);Q.current=c;const W=d.useRef(i);W.current=i;const oe=d.useRef(o);oe.current=o;const ce=d.useRef(a);ce.current=a;const $=d.useRef(u);$.current=u;const N=d.useRef(l);N.current=l;const[D,ae]=d.useState(st),[H,v]=d.useState(0),[M,R]=d.useState(Cs),[X,O]=d.useState([]),ft=d.useCallback(s=>{ae(s),St(ge.SPOTLIGHT_QUERY,s)},[]);d.useEffect(()=>{t&&(ae(st()),v(0))},[t]),d.useEffect(()=>{if(!t){O([]);return}const s=D.trim();if(s.length<xs){O([]);return}let m=!1;const C=setTimeout(()=>{ys(s).then(F=>{m||O(F)}).catch(()=>{m||O([])})},250);return()=>{m=!0,clearTimeout(C)}},[t,D]);const we=d.useCallback(s=>{R(s),vt(ge.SPOTLIGHT_TAB,s)},[]),$e=d.useRef(M);$e.current=M;const pt=d.useCallback(s=>{const m=fe.indexOf($e.current),C=fe[(m+s+fe.length)%fe.length];we(C)},[we]);d.useEffect(()=>{v(0)},[M]);const Se=V.getShortcuts(),pe=d.useMemo(()=>t?Bt():{},[t]),me=d.useMemo(()=>{if(!t)return[];const s=Se.find(C=>C.id==="spawn-agent"),m=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:m?Ve(m):"Ctrl+K",icon:f.jsx(ne,{name:"dashboard",size:16}),action:()=>{w.current(),j.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:f.jsx(ne,{name:"gear",size:16}),action:()=>{w.current(),Q.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:f.jsx(ne,{name:"chart-line",size:16}),action:()=>{var C;w.current(),(C=N.current)==null||C.call(N)}}]},[t,Se]),he=d.useMemo(()=>t?Array.from(h.values()).map(s=>{const m=(p||[]).filter(Y=>Y.agentId===s.id).map(Y=>Y.filePath),C=[...new Set(m)],F=C.map(Y=>Y.split("/").pop()||Y),B=[];s.lastAssignedTask&&B.push(s.lastAssignedTask);const L=`${s.class} • ${s.cwd}`;let k=`${s.name} ${s.class} ${s.status} ${s.cwd}`;s.taskLabel&&(k+=` ${s.taskLabel}`),F.length>0&&(k+=` ${F.join(" ")} ${C.join(" ")}`),B.length>0&&(k+=` ${B.join(" ")}`);const P=Date.now()-s.lastActivity;let U;return s.lastAssignedTask&&(s.lastAssignedTask.length>150?U=s.lastAssignedTask.slice(0,150)+"...":U=s.lastAssignedTask),{id:`agent-${s.id}`,type:"agent",title:s.name,subtitle:L,lastUserInput:U,timeAway:P,icon:f.jsx(_t,{agent:s,size:20}),_searchText:k,_modifiedFiles:C,_userQueries:B,_agentId:s.id,_lastActivity:s.lastActivity,_taskLabel:s.taskLabel,_status:s.status,action:()=>{w.current(),It(s.id),V.selectAgent(s.id),V.getState().viewMode!=="flat"&&V.requestTerminalExpand()}}}):[],[t,h,p]),Ae=d.useMemo(()=>t?Array.from(E.values()).map(s=>{var m;return{id:`area-${s.id}`,type:"area",title:s.name,subtitle:`${s.assignedAgentIds.length} agents • ${((m=s.directories)==null?void 0:m.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 m of he)m._agentId&&s.set(m._agentId,m);return s},[he]),Ne=d.useMemo(()=>{const s=new Map;if(!t)return s;for(const m of h.values()){const C=V.getAreaForAgent(m.id);if(!C||C.archived)continue;const F=s.get(C.id);F?F.push(m):s.set(C.id,[m])}return s},[t,h,E]),Pe=d.useMemo(()=>{const s=new Map;for(const m of g)s.has(m.agentId)||s.set(m.agentId,m.timestamp);return s},[g]),ve=d.useMemo(()=>{if(!t)return[];const s=D.trim().toLowerCase(),m=Dt({sortMode:Ms(),agentsWithUnseenOutput:S,getLatestToolTimestamp:B=>Pe.get(B)}),C=Array.from(E.values()).filter(B=>!B.archived).filter(B=>s?B.name.toLowerCase().includes(s):!0).sort((B,L)=>B.name.localeCompare(L.name,void 0,{sensitivity:"base"})),F=[];for(const B of C){const k=(Ne.get(B.id)||[]).slice().sort(m).map(P=>je.get(P.id)).filter(P=>!!P);!s&&k.length===0||F.push({areaId:B.id,areaName:B.name,areaColor:B.color,agents:k})}return F},[t,D,E,Ne,je,S,Pe]),ye=d.useMemo(()=>t?Array.from(x.values()).filter(s=>s.type==="server"||s.type==="boss"||s.type==="database"||s.type==="tests").map(s=>{var P,U,Y,ue,ee;const m=s.status==="running"?"#4ade80":s.status==="stopped"?"#f87171":"#facc15",C=s.type==="boss"?"crown":s.type==="database"?"database":s.type==="tests"?"flask":"desktop",F=s.type==="boss"?"Boss":s.type==="database"?"Database":s.type==="tests"?"Tests":"Server";let B=`${F} • ${s.status}`;if(s.type==="database"&&((U=(P=s.database)==null?void 0:P.connections)!=null&&U.length)){const z=s.database.connections[0];B+=` • ${z.engine} @ ${z.host}`}else s.type==="tests"&&s.folderPath?B=`${F} • ${s.folderPath}`:s.cwd&&(B+=` • ${s.cwd}`);const L=((Y=s.pm2Status)==null?void 0:Y.ports)||[];let k=`${s.name} ${s.type} ${s.status} ${s.cwd||""} ${((ue=s.pm2)==null?void 0:ue.name)||""}`;if(s.type==="tests"&&(k+=` ${s.folderPath||""} tests junit maven`),L.length>0&&(k+=` ${L.join(" ")}`),s.type==="database"&&((ee=s.database)!=null&&ee.connections))for(const z of s.database.connections)k+=` ${z.name} ${z.engine} ${z.host} ${z.database||""} mysql postgresql sql`;return{id:`building-${s.id}`,type:"building",title:s.name,subtitle:B,_ports:L,icon:f.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[f.jsx(ne,{name:"status-pending",size:10,weight:"fill",color:m}),f.jsx(ne,{name:C,size:16})]}),_searchText:k,action:()=>{var z;w.current(),s.type==="boss"?ce.current(s.id):s.type==="database"?$.current(s.id):s.type==="tests"?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=p||[],m=new Set,C=[];for(const F of s){if(m.has(F.filePath))continue;m.add(F.filePath);const B=F.filePath.split("/").pop()||F.filePath,L=F.action==="created"?"Created":F.action==="modified"?"Modified":F.action==="deleted"?"Deleted":"Read";if(C.push({id:`modified-${F.filePath}-${F.timestamp}`,type:"modified-file",title:B,subtitle:`${L} by ${F.agentName} • ${F.filePath}`,matchedText:F.filePath,icon:F.action==="deleted"?f.jsx(ne,{name:"trash",size:16}):kt(F.filePath),action:()=>{w.current();const k=Array.from(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,p]),Oe=d.useMemo(()=>t?X.map(s=>{const m=s.isGitRepo&&s.gitBranch?`${s.path} • ${s.gitBranch}`:s.path;return{id:`folder-${s.path}`,type:"folder",title:s.name,subtitle:m,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,pe);return Ee(K._agentId,K._lastActivity,pe)-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(),m=ze.search(D).slice(0,8),C=Ge.search(D).slice(0,3),F=Qe.search(D).slice(0,2),B=We.search(D).slice(0,3),L=Oe.slice(0,8),k=He.search(D).filter(A=>{const I=A.score??1;return`${A.item.title} ${A.item.subtitle||""} ${A.item._searchText||""}`.toLowerCase().includes(s)||I<=.2}).slice(0,4),P={agent:6,building:5,folder:4,command:3,area:2,"modified-file":1},U=A=>{if(!s)return 1;const I=A.title.toLowerCase();return I===s?6:I.startsWith(s)?5:I.split(/[^a-z0-9]+/i).includes(s)?4:I.includes(s)?3:`${A.subtitle||""} ${A._searchText||""} ${A.matchedText||""}`.toLowerCase().includes(s)?2:1},Y=(A,I)=>{const _=(1-Math.min(1,I??1))*4;return U(A)*100+(P[A.type]??0)*5+_},ue=new Map,ee=(A,I)=>{const _=ue.get(A.type),b={item:A,score:Y(A,I)};_?_.push(b):ue.set(A.type,[b])};for(const A of m){const I={...A.item};if(I._modifiedFiles&&I._modifiedFiles.length>0){const _=I._modifiedFiles.filter(b=>{var se;const K=((se=b.split("/").pop())==null?void 0:se.toLowerCase())||"",te=b.toLowerCase();return K.includes(s)||te.includes(s)});_.length>0&&(I.matchedFiles=_)}if(I._userQueries&&I._userQueries.length>0){const _=I._userQueries.find(b=>b.toLowerCase().includes(s));if(_)if(_.length>200){const K=_.toLowerCase().indexOf(s),te=Math.max(0,K-60),se=Math.min(_.length,K+s.length+100);I.matchedQuery=(te>0?"...":"")+_.slice(te,se)+(se<_.length?"...":"")}else I.matchedQuery=_}ee(I,A.score)}for(const A of k)ee(A.item,A.score);for(const A of C)ee(A.item,A.score);for(const A of F)ee(A.item,A.score);for(const A of B)ee(A.item,A.score);for(const A of L)ee(A,void 0);for(const[A,I]of ue)A==="agent"?I.sort((_,b)=>{const K=U(_.item),te=U(b.item);if(te!==K)return te-K;const se=Ee(_.item._agentId,_.item._lastActivity,pe),Ye=Ee(b.item._agentId,b.item._lastActivity,pe);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,pe]),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 ve.flatMap(s=>s.agents);case"all":default:return de}},[M,de,ve]);d.useEffect(()=>{H>=J.length&&v(Math.max(0,J.length-1))},[J.length,H]);const gt=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 m=s.key.toLowerCase();v(m==="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(),v(m=>m>0?m-1:J.length-1);break;case"ArrowDown":s.preventDefault(),v(m=>m<J.length-1?m+1:0);break;case"Enter":s.preventDefault(),J[H]&&J[H].action();break}},[J,H]),mt=d.useCallback((s,m)=>{if(!m||!s)return s;const C=s.toLowerCase(),F=m.toLowerCase(),B=[];let L=0,k=C.indexOf(F),P=0;for(;k!==-1;)k>L&&B.push(s.slice(L,k)),B.push(Be.createElement("mark",{key:P++,className:"spotlight-highlight"},s.slice(k,k+m.length))),L=k+m.length,k=C.indexOf(F,L);return L<s.length&&B.push(s.slice(L)),B.length>0?Be.createElement(Be.Fragment,null,...B):s},[]);return{query:D,setQuery:ft,selectedIndex:H,setSelectedIndex:v,results:J,activeTab:M,setActiveTab:we,cycleTab:pt,areaSections:ve,handleKeyDown:gt,highlightMatch:mt}}const ws=d.forwardRef(function({query:e,onQueryChange:n,onKeyDown:r,onResetSelection:c},i){const{t:o}=Fe(["common"]);return f.jsxs("div",{className:"spotlight-input-wrapper",children:[f.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),f.jsx("input",{ref:i,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:a=>{n(a.target.value),c()},onKeyDown:r,autoFocus:!0,spellCheck:!1}),f.jsxs("div",{className:"spotlight-input-hints",children:[f.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Ss=d.memo(function({activeTab:e,onSelect:n}){const{t:r}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-tabs",role:"tablist","aria-label":r("terminal:spotlight.tabsLabel"),children:[fe.map(c=>f.jsx("button",{type:"button",role:"tab","aria-selected":c===e,tabIndex:-1,className:`spotlight-tab${c===e?" active":""}`,onClick:()=>n(c),children:r(`terminal:spotlight.tabs.${c}`)},c)),f.jsx("span",{className:"spotlight-tabs-hint",children:f.jsx("kbd",{children:"Tab"})})]})}),vs=d.forwardRef(function({results:e,selectedIndex:n,query:r,activeTab:c,areaSections:i,highlightMatch:o,onSelectIndex:a},u){const{t:l}=Fe(["terminal"]),h=d.useRef(!1);d.useEffect(()=>{h.current=!1},[e]),d.useEffect(()=>{const p=typeof u=="function"?null:u==null?void 0:u.current;if(!p)return;const g=()=>{h.current=!0};return p.addEventListener("mousemove",g),()=>{p.removeEventListener("mousemove",g)}},[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 p=[];let g=null,S=[];return e.forEach((w,T)=>{w.type!==g&&(g!==null&&S.length>0&&p.push([g,S]),g=w.type,S=[]),S.push({result:w,index:T})}),g!==null&&S.length>0&&p.push([g,S]),p},[e]);if(d.useEffect(()=>{if(!u||typeof u=="function")return;const p=u.current;if(!p)return;const g=p.querySelector(".spotlight-item.selected");g&&g.scrollIntoView({block:"nearest",behavior:"smooth"})},[n,u]),c==="areas"){if(i.length===0)return f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})});let p=0;return f.jsx("div",{className:"spotlight-results",ref:u,children:i.map(g=>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:g.areaColor},"aria-hidden":"true"}),f.jsx("span",{className:"spotlight-area-name",children:g.areaName}),f.jsx("span",{className:"spotlight-area-count",children:g.agents.length})]}),g.agents.length===0?f.jsx("div",{className:"spotlight-area-empty",children:l("terminal:spotlight.noAgentsInArea")}):g.agents.map(S=>{const w=p++;return f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id)})]},g.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(([p,g])=>f.jsxs("div",{children:[x.length>1&&f.jsx("div",{className:"spotlight-category-header",children:E[p]||p}),g.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))]},p))})}),Bs=d.memo(function(){const{t:e}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-footer",children:[f.jsxs("div",{className:"spotlight-footer-left",children:[f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"↑"}),f.jsx("kbd",{children:"↓"})," ",f.jsx("kbd",{children:"Alt+N"}),f.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Tab"})," ",e("terminal:spotlight.switchTabs")]})]}),f.jsx("div",{className:"spotlight-footer-right",children:f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),Is=768;function Rs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=d.useRef(null),E=d.useRef(null),x=d.useRef(null),p=d.useRef(0),{query:g,setQuery:S,selectedIndex:w,setSelectedIndex:T,results:j,activeTab:Q,setActiveTab:W,cycleTab:oe,areaSections:ce,handleKeyDown:$,highlightMatch:N}=Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});p.current=j.length;const D=d.useRef(oe);D.current=oe,d.useEffect(()=>{t&&setTimeout(()=>{var v,M;(v=h.current)==null||v.focus(),(M=h.current)==null||M.select()},50)},[t]),d.useEffect(()=>{if(!t)return;const v=window.visualViewport;if(!v||window.innerWidth>Is)return;const M=()=>{const R=E.current;R&&(R.style.height=`${v.height}px`,R.style.top=`${v.offsetTop}px`)};return M(),v.addEventListener("resize",M),v.addEventListener("scroll",M),()=>{v.removeEventListener("resize",M),v.removeEventListener("scroll",M);const R=E.current;R&&(R.style.height="",R.style.top="")}},[t]),d.useEffect(()=>{if(!t)return;const v=M=>{if(M.key==="Escape"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),e();return}if(M.key==="Tab"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),D.current(M.shiftKey?-1:1);return}if(M.altKey&&!M.ctrlKey&&!M.metaKey&&(M.key==="n"||M.key==="p"||M.key==="N"||M.key==="P")){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation();const R=M.key.toLowerCase(),X=p.current;T(R==="p"?O=>O>0?O-1:X-1:O=>O<X-1?O+1:0);return}};return window.addEventListener("keydown",v,{capture:!0}),()=>{window.removeEventListener("keydown",v,{capture:!0})}},[t,e]);const ae=d.useCallback(v=>{v.target===v.currentTarget&&e()},[e]),H=d.useCallback(()=>{T(0)},[T]);return t?f.jsx("div",{ref:E,className:"spotlight-overlay",onClick:ae,children:f.jsxs("div",{className:"spotlight-modal",children:[f.jsx(ws,{ref:h,query:g,onQueryChange:S,onKeyDown:$,onResetSelection:H}),f.jsx(Ss,{activeTab:Q,onSelect:W}),f.jsx(vs,{ref:x,results:j,selectedIndex:w,query:g,activeTab:Q,areaSections:ce,highlightMatch:N,onSelectIndex:T}),f.jsx(Bs,{})]})}):null}export{Ls as FILE_ICON_NAMES,Rs as Spotlight,Bs as SpotlightFooter,ws as SpotlightInput,Je as SpotlightItem,vs as SpotlightResults,$s as formatDuration,js as formatRelativeTime,Ns as getAgentIcon,kt as getFileIconFromPath,Ps as getTypeLabel,Fs as useSpotlightSearch};
1
+ import{h as At,i as yt,ay as Et,a2 as xt,a3 as Ct,ck as Mt,cl as Ft,aP as wt,r as d,Y as St,S as ge,cm as vt,cn as fe,s as V,co as Bt,j as f,I as ne,cp as Ve,cq as It,a7 as _t,cr as Dt,cs as kt,ct as Ee,am as Be,X as Rt,p as nt,u as Fe,cu as Je}from"./main-C6HtzRV0.js";import{cv as Ls,cw as $s,cx as js,cy as Ns,cz as Ps}from"./main-C6HtzRV0.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function re(t){return Array.isArray?Array.isArray(t):it(t)==="[object Array]"}function bt(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Tt(t){return t==null?"":bt(t)}function Z(t){return typeof t=="string"}function rt(t){return typeof t=="number"}function Lt(t){return t===!0||t===!1||$t(t)&&it(t)=="[object Boolean]"}function ct(t){return typeof t=="object"}function $t(t){return ct(t)&&t!==null}function G(t){return t!=null}function Ie(t){return!t.trim().length}function it(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const jt="Incorrect 'index' type",Nt=t=>`Invalid value for key ${t}`,Pt=t=>`Pattern length exceeds max of ${t}.`,Kt=t=>`Missing ${t} property in key`,Ot=t=>`Property 'weight' in key '${t}' must be a positive integer`,Xe=Object.prototype.hasOwnProperty;class zt{constructor(e){this._keys=[],this._keyMap={};let n=0;e.forEach(r=>{let c=ot(r);this._keys.push(c),this._keyMap[c.id]=c,n+=c.weight}),this._keys.forEach(r=>{r.weight/=n})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function ot(t){let e=null,n=null,r=null,c=1,i=null;if(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")&&(c=t.weight,c<=0))throw new Error(Ot(o));e=qe(o),n=_e(o),i=t.getFn}return{path:e,id:n,weight:c,src:r,getFn:i}}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 c=(i,o,a)=>{if(G(i))if(!o[a])n.push(i);else{let u=o[a];const l=i[u];if(!G(l))return;if(a===o.length-1&&(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)c(l[h],o,a+1)}else o.length&&c(l,o,a+1)}};return c(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(c){const i=c.match(Yt).length;if(n.has(i))return n.get(i);const o=1/Math.pow(i,.5*t),a=parseFloat(Math.round(o*r)/r);return n.set(i,a),a},clear(){n.clear()}}}class Le{constructor({getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){this.norm=Vt(n,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((n,r)=>{this._keysMap[n.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,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((c,i)=>{let o=c.getFn?c.getFn(e):this.getFn(e,c.path);if(G(o)){if(re(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(G(h))if(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.$[i]=a}else if(Z(o)&&!Ie(o)){let a={v:o,n:this.norm.get(o)};r.$[i]=a}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function at(t,e,{getFn:n=y.getFn,fieldNormWeight:r=y.fieldNormWeight}={}){const c=new Le({getFn:n,fieldNormWeight:r});return c.setKeys(t.map(ot)),c.setSources(e),c.create(),c}function Jt(t,{getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){const{keys:r,records:c}=t,i=new Le({getFn:e,fieldNormWeight:n});return i.setKeys(r),i.setIndexRecords(c),i}function xe(t,{errors:e=0,currentLocation:n=0,expectedLocation:r=0,distance:c=y.distance,ignoreLocation:i=y.ignoreLocation}={}){const o=e/t.length;if(i)return o;const a=Math.abs(r-n);return c?o+a/c:a?1:o}function Xt(t=[],e=y.minMatchCharLength){let n=[],r=-1,c=-1,i=0;for(let o=t.length;i<o;i+=1){let a=t[i];a&&r===-1?r=i:!a&&r!==-1&&(c=i-1,c-r+1>=e&&n.push([r,c]),r=-1)}return t[i-1]&&i-r>=e&&n.push([r,i-1]),n}const le=32;function qt(t,e,n,{location:r=y.location,distance:c=y.distance,threshold:i=y.threshold,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,includeMatches:u=y.includeMatches,ignoreLocation:l=y.ignoreLocation}={}){if(e.length>le)throw new Error(Pt(le));const h=e.length,E=t.length,x=Math.max(0,Math.min(r,E));let p=i,g=x;const S=a>1||u,w=S?Array(E):[];let T;for(;(T=t.indexOf(e,g))>-1;){let $=xe(e,{currentLocation:T,expectedLocation:x,distance:c,ignoreLocation:l});if(p=Math.min($,p),g=T+h,S){let N=0;for(;N<h;)w[T+N]=1,N+=1}}g=-1;let j=[],Q=1,W=h+E;const oe=1<<h-1;for(let $=0;$<h;$+=1){let N=0,D=W;for(;N<D;)xe(e,{errors:$,currentLocation:x+D,expectedLocation:x,distance:c,ignoreLocation:l})<=p?N=D:W=D,D=Math.floor((W-N)/2+N);W=D;let ae=Math.max(1,x-D+1),H=o?E:Math.min(x+D,E)+h,v=Array(H+2);v[H+1]=(1<<$)-1;for(let R=H;R>=ae;R-=1){let X=R-1,O=n[t.charAt(X)];if(S&&(w[X]=+!!O),v[R]=(v[R+1]<<1|1)&O,$&&(v[R]|=(j[R+1]|j[R])<<1|1|j[R+1]),v[R]&oe&&(Q=xe(e,{errors:$,currentLocation:X,expectedLocation:x,distance:c,ignoreLocation:l}),Q<=p)){if(p=Q,g=X,g<=x)break;ae=Math.max(1,2*x-g)}}if(xe(e,{errors:$+1,currentLocation:x,expectedLocation:x,distance:c,ignoreLocation:l})>p)break;j=v}const ce={isMatch:g>=0,score:Math.max(.001,Q)};if(S){const $=Xt(w,a);$.length?u&&(ce.indices=$):ce.isMatch=!1}return ce}function Zt(t){let e={};for(let n=0,r=t.length;n<r;n+=1){const c=t.charAt(n);e[c]=(e[c]||0)|1<<r-n-1}return e}const Ce=String.prototype.normalize?(t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(t=>t);class ut{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:c=y.distance,includeMatches:i=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){if(this.options={location:n,threshold:r,distance:c,includeMatches:i,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h},e=u?e:e.toLowerCase(),e=l?Ce(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const E=(p,g)=>{this.chunks.push({pattern:p,alphabet:Zt(p),startIndex:g})},x=this.pattern.length;if(x>le){let p=0;const g=x%le,S=x-g;for(;p<S;)E(this.pattern.substr(p,le),p),p+=le;if(g){const w=x-le;E(this.pattern.substr(w),w)}}else E(this.pattern,0)}searchIn(e){const{isCaseSensitive:n,ignoreDiacritics:r,includeMatches:c}=this.options;if(e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern===e){let S={isMatch:!0,score:0};return c&&(S.indices=[[0,e.length-1]]),S}const{location:i,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let E=[],x=0,p=!1;this.chunks.forEach(({pattern:S,alphabet:w,startIndex:T})=>{const{isMatch:j,score:Q,indices:W}=qt(e,S,w,{location:i+T,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:c,ignoreLocation:h});j&&(p=!0),x+=Q,j&&W&&(E=[...E,...W])});let g={isMatch:p,score:p?x/this.chunks.length:1};return p&&c&&(g.indices=E),g}}class ie{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 ie{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const n=e===this.pattern;return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ts extends ie{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const r=e.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}}class ss extends ie{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const n=e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class ns extends ie{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const n=!e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class rs extends ie{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const n=e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class cs extends ie{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const n=!e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class lt extends ie{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:c=y.distance,includeMatches:i=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){super(e),this._bitapSearch=new ut(e,{location:n,threshold:r,distance:c,includeMatches:i,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class ht extends ie{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let n=0,r;const c=[],i=this.pattern.length;for(;(r=e.indexOf(this.pattern,n))>-1;)n=r+i,c.push([r,n-1]);const o=!!c.length;return{isMatch:o,score:o?0:1,indices:c}}}const De=[es,ht,ss,ns,cs,rs,ts,lt],et=De.length,is=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,os="|";function as(t,e={}){return t.split(os).map(n=>{let r=n.trim().split(is).filter(i=>i&&!!i.trim()),c=[];for(let i=0,o=r.length;i<o;i+=1){const a=r[i];let u=!1,l=-1;for(;!u&&++l<et;){const h=De[l];let E=h.isMultiMatch(a);E&&(c.push(new h(E,e)),u=!0)}if(!u)for(l=-1;++l<et;){const h=De[l];let E=h.isSingleMatch(a);if(E){c.push(new h(E,e));break}}}return c})}const us=new Set([lt.type,ht.type]);class ls{constructor(e,{isCaseSensitive:n=y.isCaseSensitive,ignoreDiacritics:r=y.ignoreDiacritics,includeMatches:c=y.includeMatches,minMatchCharLength:i=y.minMatchCharLength,ignoreLocation:o=y.ignoreLocation,findAllMatches:a=y.findAllMatches,location:u=y.location,threshold:l=y.threshold,distance:h=y.distance}={}){this.query=null,this.options={isCaseSensitive:n,ignoreDiacritics:r,includeMatches:c,minMatchCharLength:i,findAllMatches:a,ignoreLocation:o,location:u,threshold:l,distance:h},e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern=e,this.query=as(this.pattern,this.options)}static condition(e,n){return n.useExtendedSearch}searchIn(e){const n=this.query;if(!n)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:c,ignoreDiacritics:i}=this.options;e=c?e:e.toLowerCase(),e=i?Ce(e):e;let o=0,a=[],u=0;for(let l=0,h=n.length;l<h;l+=1){const E=n[l];a.length=0,o=0;for(let x=0,p=E.length;x<p;x+=1){const g=E[x],{isMatch:S,indices:w,score:T}=g.search(e);if(S){if(o+=1,u+=T,r){const j=g.constructor.type;us.has(j)?a=[...a,...w]:a.push(w)}}else{u=0,o=0,a.length=0;break}}if(o){let x={isMatch:!0,score:u/o};return r&&(x.indices=a),x}}return{isMatch:!1,score:1}}}const ke=[];function hs(...t){ke.push(...t)}function Re(t,e){for(let n=0,r=ke.length;n<r;n+=1){let c=ke[n];if(c.condition(t,e))return new c(t,e)}return new ut(t,e)}const Me={AND:"$and",OR:"$or"},be={PATH:"$path",PATTERN:"$val"},Te=t=>!!(t[Me.AND]||t[Me.OR]),ds=t=>!!t[be.PATH],fs=t=>!re(t)&&ct(t)&&!Te(t),tt=t=>({[Me.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function dt(t,e,{auto:n=!0}={}){const r=c=>{let i=Object.keys(c);const o=ds(c);if(!o&&i.length>1&&!Te(c))return r(tt(c));if(fs(c)){const u=o?c[be.PATH]:i[0],l=o?c[be.PATTERN]:c[u];if(!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:i[0]};return i.forEach(u=>{const l=c[u];re(l)&&l.forEach(h=>{a.children.push(r(h))})}),a};return Te(t)||(t=tt(t)),r(t)}function ps(t,{ignoreFieldNorm:e=y.ignoreFieldNorm}){t.forEach(n=>{let r=1;n.matches.forEach(({key:c,norm:i,score:o})=>{const a=c?c.weight:null;r*=Math.pow(o===0&&a?Number.EPSILON:o,(a||1)*(e?1:i))}),n.score=r})}function gs(t,e){const n=t.matches;e.matches=[],G(n)&&n.forEach(r=>{if(!G(r.indices)||!r.indices.length)return;const{indices:c,value:i}=r;let o={indices:c,value:i};r.key&&(o.key=r.key.src),r.idx>-1&&(o.refIndex=r.idx),e.matches.push(o)})}function ms(t,e){e.score=t.score}function As(t,e,{includeMatches:n=y.includeMatches,includeScore:r=y.includeScore}={}){const c=[];return n&&c.push(gs),r&&c.push(ms),t.map(i=>{const{idx:o}=i,a={item:e[o],refIndex:o};return c.length&&c.forEach(u=>{u(i,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,c=this._docs.length;r<c;r+=1){const i=this._docs[r];e(i,r)&&(this.removeAt(r),r-=1,c-=1,n.push(i))}return n}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:n=-1}={}){const{includeMatches:r,includeScore:c,shouldSort:i,sortFn:o,ignoreFieldNorm:a}=this.options;let u=Z(e)?Z(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return ps(u,{ignoreFieldNorm:a}),i&&u.sort(o),rt(n)&&n>-1&&(u=u.slice(0,n)),As(u,this._docs,{includeMatches:r,includeScore:c})}_searchStringList(e){const n=Re(e,this.options),{records:r}=this._myIndex,c=[];return r.forEach(({v:i,i:o,n:a})=>{if(!G(i))return;const{isMatch:u,score:l,indices:h}=n.searchIn(i);u&&c.push({item:i,idx:o,matches:[{score:l,value:i,norm:a,indices:h}]})}),c}_searchLogical(e){const n=dt(e,this.options),r=(a,u,l)=>{if(!a.children){const{keyId:E,searcher:x}=a,p=this._findMatches({key:this._keyStore.get(E),value:this._myIndex.getValueForItemAtKeyId(u,E),searcher:x});return p&&p.length?[{idx:l,item:u,matches:p}]:[]}const h=[];for(let E=0,x=a.children.length;E<x;E+=1){const p=a.children[E],g=r(p,u,l);if(g.length)h.push(...g);else if(a.operator===Me.AND)return[]}return h},c=this._myIndex.records,i={},o=[];return c.forEach(({$:a,i:u})=>{if(G(a)){let l=r(n,a,u);l.length&&(i[u]||(i[u]={idx:u,item:a,matches:[]},o.push(i[u])),l.forEach(({matches:h})=>{i[u].matches.push(...h)}))}}),o}_searchObjectList(e){const n=Re(e,this.options),{keys:r,records:c}=this._myIndex,i=[];return c.forEach(({$:o,i:a})=>{if(!G(o))return;let u=[];r.forEach((l,h)=>{u.push(...this._findMatches({key:l,value:o[h],searcher:n}))}),u.length&&i.push({idx:a,item:o,matches:u})}),i}_findMatches({key:e,value:n,searcher:r}){if(!G(n))return[];let c=[];if(re(n))n.forEach(({v:i,i:o,n:a})=>{if(!G(i))return;const{isMatch:u,score:l,indices:h}=r.searchIn(i);u&&c.push({score:l,key:e,value:i,idx:o,norm:a,indices:h})});else{const{v:i,n:o}=n,{isMatch:a,score:u,indices:l}=r.searchIn(i);a&&c.push({score:u,key:e,value:i,norm:o,indices:l})}return c}}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 c=await n.json().catch(()=>({}));throw new Error(c.error||`Failed to search folders: ${n.statusText}`)}const r=await n.json();return Array.isArray(r.folders)?r.folders:[]}const Es=["command","agent","building","area","folder","modified-file"],xs=2;function Cs(){const t=nt(ge.SPOTLIGHT_TAB,"all");return fe.includes(t)?t:"all"}function st(){return Rt(ge.SPOTLIGHT_QUERY,"")}function Ms(){const t=nt(ge.AOP_CONFIG,{});return t.sortMode==="name"||t.sortMode==="status"||t.sortMode==="recent"?t.sortMode:"recent"}function Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=Et(),E=xt(),x=Ct(),p=Mt(),g=Ft(),S=wt(),w=d.useRef(e);w.current=e;const T=d.useRef(n);T.current=n;const j=d.useRef(r);j.current=r;const Q=d.useRef(c);Q.current=c;const W=d.useRef(i);W.current=i;const oe=d.useRef(o);oe.current=o;const ce=d.useRef(a);ce.current=a;const $=d.useRef(u);$.current=u;const N=d.useRef(l);N.current=l;const[D,ae]=d.useState(st),[H,v]=d.useState(0),[M,R]=d.useState(Cs),[X,O]=d.useState([]),ft=d.useCallback(s=>{ae(s),St(ge.SPOTLIGHT_QUERY,s)},[]);d.useEffect(()=>{t&&(ae(st()),v(0))},[t]),d.useEffect(()=>{if(!t){O([]);return}const s=D.trim();if(s.length<xs){O([]);return}let m=!1;const C=setTimeout(()=>{ys(s).then(F=>{m||O(F)}).catch(()=>{m||O([])})},250);return()=>{m=!0,clearTimeout(C)}},[t,D]);const we=d.useCallback(s=>{R(s),vt(ge.SPOTLIGHT_TAB,s)},[]),$e=d.useRef(M);$e.current=M;const pt=d.useCallback(s=>{const m=fe.indexOf($e.current),C=fe[(m+s+fe.length)%fe.length];we(C)},[we]);d.useEffect(()=>{v(0)},[M]);const Se=V.getShortcuts(),pe=d.useMemo(()=>t?Bt():{},[t]),me=d.useMemo(()=>{if(!t)return[];const s=Se.find(C=>C.id==="spawn-agent"),m=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:m?Ve(m):"Ctrl+K",icon:f.jsx(ne,{name:"dashboard",size:16}),action:()=>{w.current(),j.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:f.jsx(ne,{name:"gear",size:16}),action:()=>{w.current(),Q.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:f.jsx(ne,{name:"chart-line",size:16}),action:()=>{var C;w.current(),(C=N.current)==null||C.call(N)}}]},[t,Se]),he=d.useMemo(()=>t?Array.from(h.values()).map(s=>{const m=(p||[]).filter(Y=>Y.agentId===s.id).map(Y=>Y.filePath),C=[...new Set(m)],F=C.map(Y=>Y.split("/").pop()||Y),B=[];s.lastAssignedTask&&B.push(s.lastAssignedTask);const L=`${s.class} • ${s.cwd}`;let k=`${s.name} ${s.class} ${s.status} ${s.cwd}`;s.taskLabel&&(k+=` ${s.taskLabel}`),F.length>0&&(k+=` ${F.join(" ")} ${C.join(" ")}`),B.length>0&&(k+=` ${B.join(" ")}`);const P=Date.now()-s.lastActivity;let U;return s.lastAssignedTask&&(s.lastAssignedTask.length>150?U=s.lastAssignedTask.slice(0,150)+"...":U=s.lastAssignedTask),{id:`agent-${s.id}`,type:"agent",title:s.name,subtitle:L,lastUserInput:U,timeAway:P,icon:f.jsx(_t,{agent:s,size:20}),_searchText:k,_modifiedFiles:C,_userQueries:B,_agentId:s.id,_lastActivity:s.lastActivity,_taskLabel:s.taskLabel,_status:s.status,action:()=>{w.current(),It(s.id),V.selectAgent(s.id),V.getState().viewMode!=="flat"&&V.requestTerminalExpand()}}}):[],[t,h,p]),Ae=d.useMemo(()=>t?Array.from(E.values()).map(s=>{var m;return{id:`area-${s.id}`,type:"area",title:s.name,subtitle:`${s.assignedAgentIds.length} agents • ${((m=s.directories)==null?void 0:m.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 m of he)m._agentId&&s.set(m._agentId,m);return s},[he]),Ne=d.useMemo(()=>{const s=new Map;if(!t)return s;for(const m of h.values()){const C=V.getAreaForAgent(m.id);if(!C||C.archived)continue;const F=s.get(C.id);F?F.push(m):s.set(C.id,[m])}return s},[t,h,E]),Pe=d.useMemo(()=>{const s=new Map;for(const m of g)s.has(m.agentId)||s.set(m.agentId,m.timestamp);return s},[g]),ve=d.useMemo(()=>{if(!t)return[];const s=D.trim().toLowerCase(),m=Dt({sortMode:Ms(),agentsWithUnseenOutput:S,getLatestToolTimestamp:B=>Pe.get(B)}),C=Array.from(E.values()).filter(B=>!B.archived).filter(B=>s?B.name.toLowerCase().includes(s):!0).sort((B,L)=>B.name.localeCompare(L.name,void 0,{sensitivity:"base"})),F=[];for(const B of C){const k=(Ne.get(B.id)||[]).slice().sort(m).map(P=>je.get(P.id)).filter(P=>!!P);!s&&k.length===0||F.push({areaId:B.id,areaName:B.name,areaColor:B.color,agents:k})}return F},[t,D,E,Ne,je,S,Pe]),ye=d.useMemo(()=>t?Array.from(x.values()).filter(s=>s.type==="server"||s.type==="boss"||s.type==="database"||s.type==="tests").map(s=>{var P,U,Y,ue,ee;const m=s.status==="running"?"#4ade80":s.status==="stopped"?"#f87171":"#facc15",C=s.type==="boss"?"crown":s.type==="database"?"database":s.type==="tests"?"flask":"desktop",F=s.type==="boss"?"Boss":s.type==="database"?"Database":s.type==="tests"?"Tests":"Server";let B=`${F} • ${s.status}`;if(s.type==="database"&&((U=(P=s.database)==null?void 0:P.connections)!=null&&U.length)){const z=s.database.connections[0];B+=` • ${z.engine} @ ${z.host}`}else s.type==="tests"&&s.folderPath?B=`${F} • ${s.folderPath}`:s.cwd&&(B+=` • ${s.cwd}`);const L=((Y=s.pm2Status)==null?void 0:Y.ports)||[];let k=`${s.name} ${s.type} ${s.status} ${s.cwd||""} ${((ue=s.pm2)==null?void 0:ue.name)||""}`;if(s.type==="tests"&&(k+=` ${s.folderPath||""} tests junit maven`),L.length>0&&(k+=` ${L.join(" ")}`),s.type==="database"&&((ee=s.database)!=null&&ee.connections))for(const z of s.database.connections)k+=` ${z.name} ${z.engine} ${z.host} ${z.database||""} mysql postgresql sql`;return{id:`building-${s.id}`,type:"building",title:s.name,subtitle:B,_ports:L,icon:f.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[f.jsx(ne,{name:"status-pending",size:10,weight:"fill",color:m}),f.jsx(ne,{name:C,size:16})]}),_searchText:k,action:()=>{var z;w.current(),s.type==="boss"?ce.current(s.id):s.type==="database"?$.current(s.id):s.type==="tests"?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=p||[],m=new Set,C=[];for(const F of s){if(m.has(F.filePath))continue;m.add(F.filePath);const B=F.filePath.split("/").pop()||F.filePath,L=F.action==="created"?"Created":F.action==="modified"?"Modified":F.action==="deleted"?"Deleted":"Read";if(C.push({id:`modified-${F.filePath}-${F.timestamp}`,type:"modified-file",title:B,subtitle:`${L} by ${F.agentName} • ${F.filePath}`,matchedText:F.filePath,icon:F.action==="deleted"?f.jsx(ne,{name:"trash",size:16}):kt(F.filePath),action:()=>{w.current();const k=Array.from(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,p]),Oe=d.useMemo(()=>t?X.map(s=>{const m=s.isGitRepo&&s.gitBranch?`${s.path} • ${s.gitBranch}`:s.path;return{id:`folder-${s.path}`,type:"folder",title:s.name,subtitle:m,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,pe);return Ee(K._agentId,K._lastActivity,pe)-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(),m=ze.search(D).slice(0,8),C=Ge.search(D).slice(0,3),F=Qe.search(D).slice(0,2),B=We.search(D).slice(0,3),L=Oe.slice(0,8),k=He.search(D).filter(A=>{const I=A.score??1;return`${A.item.title} ${A.item.subtitle||""} ${A.item._searchText||""}`.toLowerCase().includes(s)||I<=.2}).slice(0,4),P={agent:6,building:5,folder:4,command:3,area:2,"modified-file":1},U=A=>{if(!s)return 1;const I=A.title.toLowerCase();return I===s?6:I.startsWith(s)?5:I.split(/[^a-z0-9]+/i).includes(s)?4:I.includes(s)?3:`${A.subtitle||""} ${A._searchText||""} ${A.matchedText||""}`.toLowerCase().includes(s)?2:1},Y=(A,I)=>{const _=(1-Math.min(1,I??1))*4;return U(A)*100+(P[A.type]??0)*5+_},ue=new Map,ee=(A,I)=>{const _=ue.get(A.type),b={item:A,score:Y(A,I)};_?_.push(b):ue.set(A.type,[b])};for(const A of m){const I={...A.item};if(I._modifiedFiles&&I._modifiedFiles.length>0){const _=I._modifiedFiles.filter(b=>{var se;const K=((se=b.split("/").pop())==null?void 0:se.toLowerCase())||"",te=b.toLowerCase();return K.includes(s)||te.includes(s)});_.length>0&&(I.matchedFiles=_)}if(I._userQueries&&I._userQueries.length>0){const _=I._userQueries.find(b=>b.toLowerCase().includes(s));if(_)if(_.length>200){const K=_.toLowerCase().indexOf(s),te=Math.max(0,K-60),se=Math.min(_.length,K+s.length+100);I.matchedQuery=(te>0?"...":"")+_.slice(te,se)+(se<_.length?"...":"")}else I.matchedQuery=_}ee(I,A.score)}for(const A of k)ee(A.item,A.score);for(const A of C)ee(A.item,A.score);for(const A of F)ee(A.item,A.score);for(const A of B)ee(A.item,A.score);for(const A of L)ee(A,void 0);for(const[A,I]of ue)A==="agent"?I.sort((_,b)=>{const K=U(_.item),te=U(b.item);if(te!==K)return te-K;const se=Ee(_.item._agentId,_.item._lastActivity,pe),Ye=Ee(b.item._agentId,b.item._lastActivity,pe);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,pe]),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 ve.flatMap(s=>s.agents);case"all":default:return de}},[M,de,ve]);d.useEffect(()=>{H>=J.length&&v(Math.max(0,J.length-1))},[J.length,H]);const gt=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 m=s.key.toLowerCase();v(m==="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(),v(m=>m>0?m-1:J.length-1);break;case"ArrowDown":s.preventDefault(),v(m=>m<J.length-1?m+1:0);break;case"Enter":s.preventDefault(),J[H]&&J[H].action();break}},[J,H]),mt=d.useCallback((s,m)=>{if(!m||!s)return s;const C=s.toLowerCase(),F=m.toLowerCase(),B=[];let L=0,k=C.indexOf(F),P=0;for(;k!==-1;)k>L&&B.push(s.slice(L,k)),B.push(Be.createElement("mark",{key:P++,className:"spotlight-highlight"},s.slice(k,k+m.length))),L=k+m.length,k=C.indexOf(F,L);return L<s.length&&B.push(s.slice(L)),B.length>0?Be.createElement(Be.Fragment,null,...B):s},[]);return{query:D,setQuery:ft,selectedIndex:H,setSelectedIndex:v,results:J,activeTab:M,setActiveTab:we,cycleTab:pt,areaSections:ve,handleKeyDown:gt,highlightMatch:mt}}const ws=d.forwardRef(function({query:e,onQueryChange:n,onKeyDown:r,onResetSelection:c},i){const{t:o}=Fe(["common"]);return f.jsxs("div",{className:"spotlight-input-wrapper",children:[f.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),f.jsx("input",{ref:i,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:a=>{n(a.target.value),c()},onKeyDown:r,autoFocus:!0,spellCheck:!1}),f.jsxs("div",{className:"spotlight-input-hints",children:[f.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Ss=d.memo(function({activeTab:e,onSelect:n}){const{t:r}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-tabs",role:"tablist","aria-label":r("terminal:spotlight.tabsLabel"),children:[fe.map(c=>f.jsx("button",{type:"button",role:"tab","aria-selected":c===e,tabIndex:-1,className:`spotlight-tab${c===e?" active":""}`,onClick:()=>n(c),children:r(`terminal:spotlight.tabs.${c}`)},c)),f.jsx("span",{className:"spotlight-tabs-hint",children:f.jsx("kbd",{children:"Tab"})})]})}),vs=d.forwardRef(function({results:e,selectedIndex:n,query:r,activeTab:c,areaSections:i,highlightMatch:o,onSelectIndex:a},u){const{t:l}=Fe(["terminal"]),h=d.useRef(!1);d.useEffect(()=>{h.current=!1},[e]),d.useEffect(()=>{const p=typeof u=="function"?null:u==null?void 0:u.current;if(!p)return;const g=()=>{h.current=!0};return p.addEventListener("mousemove",g),()=>{p.removeEventListener("mousemove",g)}},[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 p=[];let g=null,S=[];return e.forEach((w,T)=>{w.type!==g&&(g!==null&&S.length>0&&p.push([g,S]),g=w.type,S=[]),S.push({result:w,index:T})}),g!==null&&S.length>0&&p.push([g,S]),p},[e]);if(d.useEffect(()=>{if(!u||typeof u=="function")return;const p=u.current;if(!p)return;const g=p.querySelector(".spotlight-item.selected");g&&g.scrollIntoView({block:"nearest",behavior:"smooth"})},[n,u]),c==="areas"){if(i.length===0)return f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})});let p=0;return f.jsx("div",{className:"spotlight-results",ref:u,children:i.map(g=>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:g.areaColor},"aria-hidden":"true"}),f.jsx("span",{className:"spotlight-area-name",children:g.areaName}),f.jsx("span",{className:"spotlight-area-count",children:g.agents.length})]}),g.agents.length===0?f.jsx("div",{className:"spotlight-area-empty",children:l("terminal:spotlight.noAgentsInArea")}):g.agents.map(S=>{const w=p++;return f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id)})]},g.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(([p,g])=>f.jsxs("div",{children:[x.length>1&&f.jsx("div",{className:"spotlight-category-header",children:E[p]||p}),g.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))]},p))})}),Bs=d.memo(function(){const{t:e}=Fe(["terminal"]);return f.jsxs("div",{className:"spotlight-footer",children:[f.jsxs("div",{className:"spotlight-footer-left",children:[f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"↑"}),f.jsx("kbd",{children:"↓"})," ",f.jsx("kbd",{children:"Alt+N"}),f.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Tab"})," ",e("terminal:spotlight.switchTabs")]})]}),f.jsx("div",{className:"spotlight-footer-right",children:f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),Is=768;function Rs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=d.useRef(null),E=d.useRef(null),x=d.useRef(null),p=d.useRef(0),{query:g,setQuery:S,selectedIndex:w,setSelectedIndex:T,results:j,activeTab:Q,setActiveTab:W,cycleTab:oe,areaSections:ce,handleKeyDown:$,highlightMatch:N}=Fs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:c,onOpenFileExplorer:i,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});p.current=j.length;const D=d.useRef(oe);D.current=oe,d.useEffect(()=>{t&&setTimeout(()=>{var v,M;(v=h.current)==null||v.focus(),(M=h.current)==null||M.select()},50)},[t]),d.useEffect(()=>{if(!t)return;const v=window.visualViewport;if(!v||window.innerWidth>Is)return;const M=()=>{const R=E.current;R&&(R.style.height=`${v.height}px`,R.style.top=`${v.offsetTop}px`)};return M(),v.addEventListener("resize",M),v.addEventListener("scroll",M),()=>{v.removeEventListener("resize",M),v.removeEventListener("scroll",M);const R=E.current;R&&(R.style.height="",R.style.top="")}},[t]),d.useEffect(()=>{if(!t)return;const v=M=>{if(M.key==="Escape"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),e();return}if(M.key==="Tab"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),D.current(M.shiftKey?-1:1);return}if(M.altKey&&!M.ctrlKey&&!M.metaKey&&(M.key==="n"||M.key==="p"||M.key==="N"||M.key==="P")){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation();const R=M.key.toLowerCase(),X=p.current;T(R==="p"?O=>O>0?O-1:X-1:O=>O<X-1?O+1:0);return}};return window.addEventListener("keydown",v,{capture:!0}),()=>{window.removeEventListener("keydown",v,{capture:!0})}},[t,e]);const ae=d.useCallback(v=>{v.target===v.currentTarget&&e()},[e]),H=d.useCallback(()=>{T(0)},[T]);return t?f.jsx("div",{ref:E,className:"spotlight-overlay",onClick:ae,children:f.jsxs("div",{className:"spotlight-modal",children:[f.jsx(ws,{ref:h,query:g,onQueryChange:S,onKeyDown:$,onResetSelection:H}),f.jsx(Ss,{activeTab:Q,onSelect:W}),f.jsx(vs,{ref:x,results:j,selectedIndex:w,query:g,activeTab:Q,areaSections:ce,highlightMatch:N,onSelectIndex:T}),f.jsx(Bs,{})]})}):null}export{Ls as FILE_ICON_NAMES,Rs as Spotlight,Bs as SpotlightFooter,ws as SpotlightInput,Je as SpotlightItem,vs as SpotlightResults,$s as formatDuration,js as formatRelativeTime,Ns as getAgentIcon,kt as getFileIconFromPath,Ps as getTypeLabel,Fs as useSpotlightSearch};
@@ -1,4 +1,4 @@
1
- import{bD as ta,u as B,j as e,b6 as j,bG as Ms,bH as Fs,b7 as Q,s as D,bI as $s,r as m,D as Z,I as F,ac as Us,bg as qe,f as na,bJ as la,X as ia,S as ra,k as oa,ab as Ks,bh as Ue}from"./main-BYtCWmOh.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const ca=[{value:"",labelKey:"terminal:building.colorDefault"},{value:"#2a2a3a",labelKey:"terminal:building.colorDarkGray"},{value:"#3a2a2a",labelKey:"terminal:building.colorDarkRed"},{value:"#2a3a2a",labelKey:"terminal:building.colorDarkGreen"},{value:"#2a2a4a",labelKey:"terminal:building.colorDarkBlue"},{value:"#3a3a2a",labelKey:"terminal:building.colorDarkYellow"},{value:"#3a2a3a",labelKey:"terminal:building.colorDarkPurple"},{value:"#2a3a3a",labelKey:"terminal:building.colorDarkCyan"},{value:"#4a3a3a",labelKey:"terminal:building.colorWarmBrown"},{value:"#3a4a4a",labelKey:"terminal:building.colorCoolSteel"}];function da(r){return ta.t(r)}function Ve(r){if(r===0)return"0 B";const p=1024,u=["B","KB","MB","GB"],x=Math.floor(Math.log(r)/Math.log(p));return parseFloat((r/Math.pow(p,x)).toFixed(1))+" "+u[x]}function ma(r){const u=Date.now()-r,x=Math.floor(u/(1e3*60*60)),n=Math.floor(u%(1e3*60*60)/(1e3*60));return x>0?`${x}h ${n}m`:`${n}m`}const Hs={30:"#1a1a1a",31:"#e74c3c",32:"#2ecc71",33:"#f39c12",34:"#3498db",35:"#9b59b6",36:"#00bcd4",37:"#ecf0f1",90:"#7f8c8d",91:"#ff6b6b",92:"#4ade80",93:"#fbbf24",94:"#60a5fa",95:"#c084fc",96:"#22d3ee",97:"#ffffff"};function qs(r){const p=[],u=/\x1B\[([0-9;]*)m/g;let x=0,n=null,y;for(;(y=u.exec(r))!==null;){if(y.index>x){const g=r.slice(x,y.index);n?p.push(e.jsx("span",{style:{color:n},children:g},p.length)):p.push(g)}const C=y[1].split(";").map(Number);for(const g of C)g===0||g===39?n=null:Hs[g]&&(n=Hs[g]);x=u.lastIndex}if(x<r.length){const C=r.slice(x);n?p.push(e.jsx("span",{style:{color:n},children:C},p.length)):p.push(C)}return p.length>0?p:[r]}function ua({buildingName:r,onClose:p,onConfirm:u}){const{t:x}=B(["terminal","common"]);return e.jsx("div",{className:"modal-overlay visible",onClick:p,children:e.jsxs("div",{className:"modal confirm-modal",onClick:n=>n.stopPropagation(),children:[e.jsx("div",{className:"modal-header",children:x("terminal:building.deleteBuilding")}),e.jsxs("div",{className:"modal-body confirm-modal-body",children:[e.jsx("p",{children:x("terminal:building.deleteConfirm",{name:r})}),e.jsx("p",{className:"confirm-modal-note",children:x("terminal:building.deleteNote")})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("button",{className:"btn btn-secondary",onClick:p,children:x("common:buttons.cancel")}),e.jsx("button",{className:"btn btn-danger",onClick:u,autoFocus:!0,children:x("common:buttons.delete")})]})]})})}function pa({usePM2:r,setUsePM2:p}){const{t:u}=B(["terminal"]);return e.jsxs("div",{className:"form-section pm2-toggle-section",children:[e.jsxs("label",{className:"toggle-switch",children:[e.jsx("input",{type:"checkbox",className:"toggle-input",checked:r,onChange:x=>p(x.target.checked)}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})}),e.jsxs("span",{className:"toggle-label",children:[e.jsx("span",{className:"pm2-badge",children:"PM2"}),u("terminal:building.usePM2")]})]}),e.jsx("div",{className:"form-hint",children:u("terminal:building.pm2Hint")})]})}function ha({usePM2:r,pm2Script:p,setPm2Script:u,pm2Args:x,setPm2Args:n,pm2Interpreter:y,setPm2Interpreter:C,pm2InterpreterArgs:g,setPm2InterpreterArgs:v,pm2Env:s,setPm2Env:h,isEditMode:a,building:t,handleCommand:c}){var f;const{t:i}=B(["terminal","common"]);return r?e.jsxs("div",{className:"form-section pm2-config-section",children:[e.jsx("label",{className:"form-label",children:i("terminal:building.pm2Configuration")}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Script"),e.jsx(j,{text:i("terminal:building.helpPm2Script"),title:i("terminal:building.pm2Script"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:p,onChange:b=>u(b.target.value),placeholder:"npm, java, python, ./app.js",required:r})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Arguments"),e.jsx(j,{text:i("terminal:building.helpPm2Arguments"),title:i("terminal:building.pm2Arguments"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:x,onChange:b=>n(b.target.value),placeholder:"run dev, -jar app.jar, app.py"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Interpreter"),e.jsx(j,{text:i("terminal:building.helpPm2Interpreter"),title:i("terminal:building.pm2Interpreter"),position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:y,onChange:b=>C(b.target.value),children:Object.keys(Ms).map(b=>e.jsx("option",{value:b,children:Ms[b].label},b))})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2InterpArgs"),e.jsx(j,{text:i("terminal:building.helpPm2InterpArgs"),title:i("terminal:building.pm2InterpArgs"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:g,onChange:b=>v(b.target.value),placeholder:"-jar (for Java)"})]}),e.jsxs("div",{className:"command-row env-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Environment"),e.jsx(j,{text:i("terminal:building.helpPm2Environment"),title:i("terminal:building.pm2Environment"),position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input form-textarea",value:s,onChange:b=>h(b.target.value),placeholder:`KEY=value
1
+ import{bD as ta,u as B,j as e,b6 as j,bG as Ms,bH as Fs,b7 as Q,s as D,bI as $s,r as m,D as Z,I as F,ac as Us,bg as qe,f as na,bJ as la,X as ia,S as ra,k as oa,ab as Ks,bh as Ue}from"./main-C6HtzRV0.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const ca=[{value:"",labelKey:"terminal:building.colorDefault"},{value:"#2a2a3a",labelKey:"terminal:building.colorDarkGray"},{value:"#3a2a2a",labelKey:"terminal:building.colorDarkRed"},{value:"#2a3a2a",labelKey:"terminal:building.colorDarkGreen"},{value:"#2a2a4a",labelKey:"terminal:building.colorDarkBlue"},{value:"#3a3a2a",labelKey:"terminal:building.colorDarkYellow"},{value:"#3a2a3a",labelKey:"terminal:building.colorDarkPurple"},{value:"#2a3a3a",labelKey:"terminal:building.colorDarkCyan"},{value:"#4a3a3a",labelKey:"terminal:building.colorWarmBrown"},{value:"#3a4a4a",labelKey:"terminal:building.colorCoolSteel"}];function da(r){return ta.t(r)}function Ve(r){if(r===0)return"0 B";const p=1024,u=["B","KB","MB","GB"],x=Math.floor(Math.log(r)/Math.log(p));return parseFloat((r/Math.pow(p,x)).toFixed(1))+" "+u[x]}function ma(r){const u=Date.now()-r,x=Math.floor(u/(1e3*60*60)),n=Math.floor(u%(1e3*60*60)/(1e3*60));return x>0?`${x}h ${n}m`:`${n}m`}const Hs={30:"#1a1a1a",31:"#e74c3c",32:"#2ecc71",33:"#f39c12",34:"#3498db",35:"#9b59b6",36:"#00bcd4",37:"#ecf0f1",90:"#7f8c8d",91:"#ff6b6b",92:"#4ade80",93:"#fbbf24",94:"#60a5fa",95:"#c084fc",96:"#22d3ee",97:"#ffffff"};function qs(r){const p=[],u=/\x1B\[([0-9;]*)m/g;let x=0,n=null,y;for(;(y=u.exec(r))!==null;){if(y.index>x){const g=r.slice(x,y.index);n?p.push(e.jsx("span",{style:{color:n},children:g},p.length)):p.push(g)}const C=y[1].split(";").map(Number);for(const g of C)g===0||g===39?n=null:Hs[g]&&(n=Hs[g]);x=u.lastIndex}if(x<r.length){const C=r.slice(x);n?p.push(e.jsx("span",{style:{color:n},children:C},p.length)):p.push(C)}return p.length>0?p:[r]}function ua({buildingName:r,onClose:p,onConfirm:u}){const{t:x}=B(["terminal","common"]);return e.jsx("div",{className:"modal-overlay visible",onClick:p,children:e.jsxs("div",{className:"modal confirm-modal",onClick:n=>n.stopPropagation(),children:[e.jsx("div",{className:"modal-header",children:x("terminal:building.deleteBuilding")}),e.jsxs("div",{className:"modal-body confirm-modal-body",children:[e.jsx("p",{children:x("terminal:building.deleteConfirm",{name:r})}),e.jsx("p",{className:"confirm-modal-note",children:x("terminal:building.deleteNote")})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("button",{className:"btn btn-secondary",onClick:p,children:x("common:buttons.cancel")}),e.jsx("button",{className:"btn btn-danger",onClick:u,autoFocus:!0,children:x("common:buttons.delete")})]})]})})}function pa({usePM2:r,setUsePM2:p}){const{t:u}=B(["terminal"]);return e.jsxs("div",{className:"form-section pm2-toggle-section",children:[e.jsxs("label",{className:"toggle-switch",children:[e.jsx("input",{type:"checkbox",className:"toggle-input",checked:r,onChange:x=>p(x.target.checked)}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})}),e.jsxs("span",{className:"toggle-label",children:[e.jsx("span",{className:"pm2-badge",children:"PM2"}),u("terminal:building.usePM2")]})]}),e.jsx("div",{className:"form-hint",children:u("terminal:building.pm2Hint")})]})}function ha({usePM2:r,pm2Script:p,setPm2Script:u,pm2Args:x,setPm2Args:n,pm2Interpreter:y,setPm2Interpreter:C,pm2InterpreterArgs:g,setPm2InterpreterArgs:v,pm2Env:s,setPm2Env:h,isEditMode:a,building:t,handleCommand:c}){var f;const{t:i}=B(["terminal","common"]);return r?e.jsxs("div",{className:"form-section pm2-config-section",children:[e.jsx("label",{className:"form-label",children:i("terminal:building.pm2Configuration")}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Script"),e.jsx(j,{text:i("terminal:building.helpPm2Script"),title:i("terminal:building.pm2Script"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:p,onChange:b=>u(b.target.value),placeholder:"npm, java, python, ./app.js",required:r})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Arguments"),e.jsx(j,{text:i("terminal:building.helpPm2Arguments"),title:i("terminal:building.pm2Arguments"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:x,onChange:b=>n(b.target.value),placeholder:"run dev, -jar app.jar, app.py"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Interpreter"),e.jsx(j,{text:i("terminal:building.helpPm2Interpreter"),title:i("terminal:building.pm2Interpreter"),position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:y,onChange:b=>C(b.target.value),children:Object.keys(Ms).map(b=>e.jsx("option",{value:b,children:Ms[b].label},b))})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2InterpArgs"),e.jsx(j,{text:i("terminal:building.helpPm2InterpArgs"),title:i("terminal:building.pm2InterpArgs"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:g,onChange:b=>v(b.target.value),placeholder:"-jar (for Java)"})]}),e.jsxs("div",{className:"command-row env-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Environment"),e.jsx(j,{text:i("terminal:building.helpPm2Environment"),title:i("terminal:building.pm2Environment"),position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input form-textarea",value:s,onChange:b=>h(b.target.value),placeholder:`KEY=value
2
2
  SERVER_PORT=7201
3
3
  NODE_ENV=production`,rows:3})]}),e.jsx("div",{className:"pm2-examples",children:e.jsxs("details",{children:[e.jsx("summary",{children:i("terminal:building.pm2Examples")}),e.jsxs("div",{className:"pm2-examples-content",children:[e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Node.js:"})," Script: ",e.jsx("code",{children:"npm"}),", Args: ",e.jsx("code",{children:"run dev"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Symfony:"})," Script: ",e.jsx("code",{children:"symfony"}),", Args: ",e.jsx("code",{children:"serve --no-daemon"}),", Interpreter: ",e.jsx("code",{children:"None"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Java JAR:"})," Script: ",e.jsx("code",{children:"app.jar"}),", Interpreter: ",e.jsx("code",{children:"Java"}),", Interp. Args: ",e.jsx("code",{children:"-jar"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Python:"})," Script: ",e.jsx("code",{children:"app.py"}),", Interpreter: ",e.jsx("code",{children:"Python 3"})]})]})]})}),a&&(t==null?void 0:t.pm2Status)&&e.jsx("div",{className:"pm2-status-display",children:e.jsxs("div",{className:"pm2-status-row",children:[e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"PID"}),e.jsx("span",{className:"pm2-metric-value",children:t.pm2Status.pid||"-"})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"CPU"}),e.jsxs("span",{className:"pm2-metric-value",children:[((f=t.pm2Status.cpu)==null?void 0:f.toFixed(1))||"0","%"]})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"MEM"}),e.jsx("span",{className:"pm2-metric-value",children:Ve(t.pm2Status.memory||0)})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"Restarts"}),e.jsx("span",{className:"pm2-metric-value",children:t.pm2Status.restarts||0})]}),t.pm2Status.uptime&&e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"Uptime"}),e.jsx("span",{className:"pm2-metric-value",children:ma(t.pm2Status.uptime)})]})]})}),a&&e.jsxs("div",{className:"pm2-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>c("start"),children:i("common:buttons.start")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>c("stop"),children:i("common:buttons.stop")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>c("restart"),children:i("terminal:buildingAction.restart")}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>c("logs"),children:i("terminal:logs.title")})]})]}):null}function xa({dockerMode:r,setDockerMode:p,dockerImage:u,setDockerImage:x,dockerContainerName:n,setDockerContainerName:y,dockerCommand:C,setDockerCommand:g,dockerPorts:v,setDockerPorts:s,dockerVolumes:h,setDockerVolumes:a,dockerNetwork:t,setDockerNetwork:c,dockerRestart:i,setDockerRestart:f,dockerPull:b,setDockerPull:L,dockerEnv:T,setDockerEnv:A,dockerComposePath:$,setDockerComposePath:I,dockerComposeProject:K,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:$,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:K,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($s).map(l=>e.jsx("option",{value:l,children:$s[l].label},l))})]}),e.jsxs("div",{className:"command-row env-row",children:[e.jsxs("span",{className:"command-label",children:["Environment:",e.jsx(j,{text:"Environment variables in KEY=value format, one per line.",title:"Environment Variables",position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input form-textarea",value:T,onChange:l=>A(l.target.value),placeholder:`KEY=value
4
4
  DATABASE_URL=postgres://...