tide-commander 1.145.0 → 1.145.1

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-DPXsdZ7u.js → BossLogsModal-CruMnuIg.js} +1 -1
  3. package/dist/assets/{BossSpawnModal-Bn8bGZyF.js → BossSpawnModal-BcvQB3wq.js} +1 -1
  4. package/dist/assets/{ControlsModal-J62POwmI.js → ControlsModal-Dzqvty4h.js} +1 -1
  5. package/dist/assets/{DockerLogsModal-DZx8OuLO.js → DockerLogsModal-DCmej8nQ.js} +1 -1
  6. package/dist/assets/{EmbeddedEditor-BLZrqHph.js → EmbeddedEditor-B4uPYFAp.js} +1 -1
  7. package/dist/assets/{GmailOAuthSetup-BD-W3VJ9.js → GmailOAuthSetup-CbqZaOwy.js} +1 -1
  8. package/dist/assets/{GoogleOAuthSetup-miugyyJJ.js → GoogleOAuthSetup-CeBaT6F-.js} +1 -1
  9. package/dist/assets/{IframeModal-uiyVg9VQ.js → IframeModal-DyFaV2RW.js} +1 -1
  10. package/dist/assets/{IntegrationsPanel-CAt_jjW7.js → IntegrationsPanel-CskQuV_g.js} +2 -2
  11. package/dist/assets/{LogViewerModal-DHSPYmTn.js → LogViewerModal-uQVzAKZ9.js} +1 -1
  12. package/dist/assets/{MonitoringModal-DJdIFnXI.js → MonitoringModal-BxgyPrXB.js} +1 -1
  13. package/dist/assets/{PM2LogsModal-CA7IDf-Q.js → PM2LogsModal-B-uHRH5-.js} +1 -1
  14. package/dist/assets/{RestoreArchivedAreaModal-CrgrnJrN.js → RestoreArchivedAreaModal-C5am-szg.js} +1 -1
  15. package/dist/assets/{Scene2DCanvas-CCKFfv_Q.js → Scene2DCanvas-BiwOn6i-.js} +1 -1
  16. package/dist/assets/{SceneManager-DPogxokC.js → SceneManager-BiDObF1U.js} +1 -1
  17. package/dist/assets/{SkillsPanel-BGH4Jzy2.js → SkillsPanel-C54Kk6FN.js} +1 -1
  18. package/dist/assets/{SlackMultiInstanceSetup-Cde0PF27.js → SlackMultiInstanceSetup-CPpKQof5.js} +1 -1
  19. package/dist/assets/{SpawnModal-B_1WTo88.js → SpawnModal-BkvFwsfC.js} +1 -1
  20. package/dist/assets/{StatisticsModal-BWx5rOYA.js → StatisticsModal-CdVUxX4w.js} +1 -1
  21. package/dist/assets/{SubordinateAssignmentModal-BcACB1Rb.js → SubordinateAssignmentModal-4ODSWfe0.js} +1 -1
  22. package/dist/assets/{TriggerManagerPanel-BQdBJs9X.js → TriggerManagerPanel-Cz79u_Pb.js} +1 -1
  23. package/dist/assets/{WorkflowEditorPanel-CzM3DxVG.js → WorkflowEditorPanel-lDvTaV8b.js} +1 -1
  24. package/dist/assets/{area-logos-BHJ2RYkS.js → area-logos-59hkGSIt.js} +1 -1
  25. package/dist/assets/{index-C4Xpdvs6.js → index-BFcqSPwk.js} +1 -1
  26. package/dist/assets/{index-D0wHZqkk.js → index-BICR9qsc.js} +1 -1
  27. package/dist/assets/{index-f23AFZac.js → index-CWmcRznG.js} +1 -1
  28. package/dist/assets/{index-DtuQeAw2.js → index-CvgYmf1T.js} +1 -1
  29. package/dist/assets/{index-DxcL_hH1.js → index-Cx-onkQl.js} +1 -1
  30. package/dist/assets/{index-D_wa-zns.js → index-DBcyZtOh.js} +3 -3
  31. package/dist/assets/{index-B20Fn_-l.js → index-DI8nbfRj.js} +1 -1
  32. package/dist/assets/{index-DuPDS7BI.js → index-DNl2f-Te.js} +2 -2
  33. package/dist/assets/{index-BksOQHtD.js → index-DW9AqIML.js} +1 -1
  34. package/dist/assets/{main-DBurmQCa.js → main-CtBd-RH5.js} +87 -87
  35. package/dist/assets/{web-B-nLiUYo.js → web-Co63TMly.js} +1 -1
  36. package/dist/assets/{web-XTmM7Spb.js → web-HzioHV-R.js} +1 -1
  37. package/dist/assets/{web-BkDI_Oul.js → web-Rewx3mYc.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-DBurmQCa.js";import{g as ba}from"./area-logos-BHJ2RYkS.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-CtBd-RH5.js";import{g as ba}from"./area-logos-59hkGSIt.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};