tide-commander 1.151.1 → 1.152.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/assets/{BossLogsModal-BRXVs2zX.js → BossLogsModal-DZWUfQXs.js} +1 -1
- package/dist/assets/{BossSpawnModal-BqM8EeOS.js → BossSpawnModal-7IwzcqE7.js} +1 -1
- package/dist/assets/{ControlsModal-Do6sfsyz.js → ControlsModal-D8L1xD-H.js} +1 -1
- package/dist/assets/{DockerLogsModal-Clb8M2rL.js → DockerLogsModal-_zLe5UFl.js} +1 -1
- package/dist/assets/{EmbeddedEditor-DMFNGABf.js → EmbeddedEditor-gbiFXvt_.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-D4-bi1Rt.js → GmailOAuthSetup-CcXTV3NP.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-D2Wyhnw0.js → GoogleOAuthSetup-wbETidgv.js} +1 -1
- package/dist/assets/{IframeModal-Zun7245W.js → IframeModal-a9E5UDBk.js} +1 -1
- package/dist/assets/{IntegrationsPanel-U8SIOpPt.js → IntegrationsPanel-BbGyluL0.js} +2 -2
- package/dist/assets/{LogViewerModal-BnFRX2hq.js → LogViewerModal-cnMAbNvY.js} +1 -1
- package/dist/assets/{MonitoringModal-CObUxMPl.js → MonitoringModal-DymqjenY.js} +1 -1
- package/dist/assets/{PM2LogsModal-DLf14YCU.js → PM2LogsModal-CEaCk-dt.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-Chg4LCCi.js → RestoreArchivedAreaModal-q_FFv7L6.js} +1 -1
- package/dist/assets/{Scene2DCanvas-CI_QSx9i.js → Scene2DCanvas-DOvVtiYO.js} +1 -1
- package/dist/assets/{SceneManager-SS5ahbEe.js → SceneManager-D0NdrG8K.js} +1 -1
- package/dist/assets/{SkillsPanel-DgPHgt3c.js → SkillsPanel-DpqD60Hy.js} +3 -3
- package/dist/assets/{SlackMultiInstanceSetup-iIjyM2kW.js → SlackMultiInstanceSetup-BdoALd_g.js} +1 -1
- package/dist/assets/{SpawnModal-BDgxHGYh.js → SpawnModal-DFFFH2kc.js} +1 -1
- package/dist/assets/{StatisticsModal-BuYkJsul.js → StatisticsModal-Dv_rYZDt.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-D71lnDXZ.js → SubordinateAssignmentModal-CRCCI686.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-DKiXSpSu.js → TriggerManagerPanel-DBN8IRa-.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-Dz6fJy8X.js → WorkflowEditorPanel-uQEvNTs2.js} +1 -1
- package/dist/assets/{area-logos-UIiMtczR.js → area-logos-CuVxToGM.js} +1 -1
- package/dist/assets/{index-DrUrcPns.js → index-8Ghh3AQ-.js} +1 -1
- package/dist/assets/{index-OQ-kWRyS.js → index-BHM8V4i-.js} +1 -1
- package/dist/assets/index-BNzYPyBm.css +1 -0
- package/dist/assets/{index-Ci67fScw.js → index-Blc4MwKs.js} +3 -3
- package/dist/assets/{index-BXnQVuar.js → index-D4iie3Vd.js} +1 -1
- package/dist/assets/{index-DgxY9KIr.js → index-DKnfLe7S.js} +1 -1
- package/dist/assets/{index-4BenQ81a.js → index-Dwll5Eyj.js} +4 -4
- package/dist/assets/{index-BZKCuVK4.js → index-HvyFhszc.js} +2 -2
- package/dist/assets/index-OkenGYC6.js +1 -0
- package/dist/assets/{index-BAvhLzXF.js → index-ipuWrg1S.js} +3 -3
- package/dist/assets/main-DpNJ8pqp.css +1 -0
- package/dist/assets/main-aIpEYDDR.js +289 -0
- package/dist/assets/{web-DSHhrW0P.js → web-1pfPwxBS.js} +1 -1
- package/dist/assets/{web-BSnmr2eo.js → web-D0JSbYeo.js} +1 -1
- package/dist/assets/{web-jsCXVjsN.js → web-DjgiLxvi.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/locales/en/config.json +18 -0
- package/dist/src/packages/server/routes/system.js +110 -0
- package/package.json +1 -1
- package/dist/assets/index-CLA5nZlA.css +0 -1
- package/dist/assets/index-DvSK7N4C.js +0 -1
- package/dist/assets/main-CEq_Fs_S.js +0 -289
- package/dist/assets/main-CX7XkoZ4.css +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as a,H as yn,J as Yt,K as cn,L as dn,j as e,M as un,N as Nn,u as Vt,O as Sn,P as An,U as En,V as In,W as Mn,X as Tn,Y as Ln,Z as Pn,_ as Kt,S as A,$ as Zt,a0 as Ut,a1 as Jt,a2 as yt,a3 as ge,a4 as Rn,s as g,a5 as pn,m as mn,a6 as Dn,z as Qt,B as en,I as f,a7 as $n,q as zn,a8 as On,a9 as fn,aa as hn,ab as gn,ac as xn,ad as Bn,ae as Fn,af as Wn,ag as Hn,ah as Un,ai as Vn,aj as Xn,ak as Gn,al as qn,am as Yn,an as Kn,ao as Zn,ap as tn,C as Jn,aq as Qn,ar as nn,as as ea,at as ta,au as na,av as aa,aw as sa,ax as ia,ay as la,az as ra,aA as oa,aB as ca,aC as da,aD as ua,aE as pa,aF as ma,aG as fa,aH as Je,aI as ha,aJ as ga,aK as xa,aL as ba,aM as lt,aN as _a,aO as wa,aP as va,aQ as ja,aR as Ca,aS as an,aT as ka}from"./main-CEq_Fs_S.js";import{g as ya}from"./area-logos-UIiMtczR.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Na(c){const r=a.useRef(c);r.current=c,a.useEffect(()=>{if(!yn())return;let p=null,h=!1;return Yt.addListener("backButton",()=>{r.current()==="exit"&&Yt.exitApp()}).then(k=>{h?k.remove():p=k}),()=>{h=!0,p&&(p.remove(),p=null)}},[])}async function Sa(c){const r=cn(),p=await fetch(`${dn()}/api/agents/${c}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${r}`}});if(!p.ok){const h=await p.json().catch(()=>({}));throw new Error((h==null?void 0:h.error)||`Failed to start terminal (${p.status})`)}return p.json()}async function Aa(c){const r=cn();await fetch(`${dn()}/api/agents/${c}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${r}`}})}const rt=new Map;function Ea({agentId:c}){const[r,p]=a.useState(null),[h,k]=a.useState(null);return a.useEffect(()=>{let T=!1;const S=rt.get(c);return S&&(clearTimeout(S),rt.delete(c)),p(null),k(null),Sa(c).then(y=>{T||p(y.url)}).catch(y=>{T||k(y instanceof Error?y.message:"Failed to start terminal")}),()=>{T=!0;const y=rt.get(c);y&&clearTimeout(y),rt.set(c,setTimeout(()=>{rt.delete(c),Aa(c)},2500))}},[c]),h?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:h})}):r?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(un,{terminalUrl:r,visible:!0})}):e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:"Attaching to interactive session…"})})}const Ft=new Map,Ia=6e4;function sn(c){return Number.isFinite(c)?Math.abs(c)>=1e3?c.toLocaleString(void 0,{maximumFractionDigits:0}):c.toLocaleString(void 0,{maximumFractionDigits:2}):String(c)}function Ma(c,r){var k,T,S;const p=[];if(!c.rateLimits)return p;if(c.provider==="claude"){const y=c,Y=[{key:"fiveHour",label:r("terminal:usage.currentSession"),window:y.rateLimits.fiveHour},{key:"sevenDay",label:r("terminal:usage.currentWeekAll"),window:y.rateLimits.sevenDay},{key:"sevenDayOpus",label:r("terminal:usage.currentWeekOpus"),window:y.rateLimits.sevenDayOpus},{key:"sevenDaySonnet",label:r("terminal:usage.currentWeekSonnet"),window:y.rateLimits.sevenDaySonnet}];for(const _ of Y)_.window&&p.push({..._,window:_.window});return p}const h=c;return(k=h.rateLimits)!=null&&k.weekly&&p.push({key:"weekly",label:r("terminal:usage.weeklyLimit"),window:h.rateLimits.weekly}),(T=h.rateLimits)!=null&&T.monthly&&p.push({key:"monthly",label:r("terminal:usage.monthlyLimit"),window:h.rateLimits.monthly}),(S=h.rateLimits)!=null&&S.onDemand&&p.push({key:"onDemand",label:r("terminal:usage.onDemandLimit"),window:h.rateLimits.onDemand}),p}function Ta({agentId:c,contextSummary:r}){const{t:p}=Vt(["terminal","common"]),[h,k]=a.useState(()=>{var H;return((H=Ft.get(c))==null?void 0:H.snapshot)??null}),[T,S]=a.useState(!1),[y,Y]=a.useState(null),_=a.useRef(0);a.useEffect(()=>{const H=Ft.get(c);if(H&&Date.now()-H.fetchedAt<Ia){k(H.snapshot);return}const re=++_.current;S(!0),Y(null),Sn(c).then(P=>{re===_.current&&(Ft.set(c,{snapshot:P,fetchedAt:Date.now()}),k(P),S(!1))}).catch(P=>{re===_.current&&(Y(P.message||"Failed to load plan limits"),S(!1))})},[c]);const W=h?Ma(h,p):[];return e.jsxs("div",{className:"plan-limits-tooltip",children:[r&&e.jsx("div",{className:"plan-limits-tooltip__context",children:r}),e.jsx("div",{className:"plan-limits-tooltip__title",children:p("terminal:usage.limits")}),T&&!h&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[p("common:status.loading"),"…"]}),!T&&y&&!h&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:p("terminal:usage.limitsError",{message:y})}),W.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:W.map(({key:H,label:re,window:P})=>{const Ee=Math.max(0,Math.min(100,P.utilization)),oe=En(Ee),ce=typeof P.used=="number"&&typeof P.limit=="number"&&Number.isFinite(P.used)&&Number.isFinite(P.limit);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:re}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:oe},children:p("terminal:usage.percentUsed",{percent:Math.round(Ee)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${Ee}%`,background:oe}})}),e.jsxs("div",{className:"plan-limits-tooltip__reset",children:[p("terminal:usage.resets",{time:An(P.resetsAt)}),ce&&e.jsx("span",{style:{marginLeft:8},children:p("terminal:usage.creditsUsed",{used:sn(P.used),limit:sn(P.limit)})})]})]},H)})}):h&&!T&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:h.rateLimitsError?p("terminal:usage.limitsError",{message:h.rateLimitsError}):h.cliHint})]})}function La({agentId:c,disabled:r,contextSummary:p,children:h}){return e.jsx(Nn,{position:"top",maxWidth:320,disabled:r,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx(Ta,{agentId:c,contextSummary:p}),children:h})}const Pa=a.memo(function({className:r=""}){const{t:p}=Vt(["common"]),[h,k]=In(),T=a.useRef(null),[S,y]=a.useState(null);a.useLayoutEffect(()=>{const _=T.current;if(!_)return;const W=_.querySelector(".view-mode-toggle__btn--active");W&&y({left:W.offsetLeft,width:W.offsetWidth})},[h]);const Y=a.useCallback(_=>{if(_!==h){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:_}})),_==="3d"){requestAnimationFrame(()=>k(_));return}k(_)}},[h,k]);return e.jsxs("div",{className:`view-mode-toggle ${r}`,ref:T,children:[S&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:S.left,width:S.width}}),Mn.map(_=>e.jsxs("button",{className:`view-mode-toggle__btn ${h===_?"view-mode-toggle__btn--active":""}`,onClick:()=>Y(_),title:p(`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:p(`common:viewMode.labels.${_}`)})]},_))]})}),Nt=3,St=280,ln=320,Wt=240,rn=64,Ra=["simple","chat","advanced"],Da={simple:"Simple",chat:"Chat",advanced:"Advanced"},$a={simple:"○",chat:"◐",advanced:"◉"},za={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},on="flat-clear-context",bn="tide:flat-embedded-panels";function _n(){try{const c=localStorage.getItem(bn),r=c?JSON.parse(c):{};return r&&typeof r=="object"?r:{}}catch{return{}}}function Ht(c,r){try{const p=_n();r?p[c]=r:delete p[c],localStorage.setItem(bn,JSON.stringify(p))}catch{}}function Oa(c){const r=c.split("/").filter(Boolean);return r.length===0?c:r.slice(-2).join("/")}function Ba(c){if(c.provider==="codex"){const T=c.codexModel||"gpt-5.6-luna",S=Ca[T];return{model:(S==null?void 0:S.label)||T}}if(c.provider==="opencode")return{model:c.opencodeModel||"opencode"};if(c.provider==="grok"){const T=c.grokModel||"grok-4.5",S=c.effort,y=S?an[S]:void 0;return{model:T,effort:y==null?void 0:y.label}}const r=c.model||"sonnet",p=ka[r],h=c.effort,k=h?an[h]:void 0;return{model:(p==null?void 0:p.label)||r,effort:k==null?void 0:k.label}}function Fa(c,r){if(r.type==="rectangle"&&r.width&&r.height){const p=r.width/2,h=r.height/2;return c.x>=r.center.x-p&&c.x<=r.center.x+p&&c.z>=r.center.z-h&&c.z<=r.center.z+h}if(r.type==="circle"&&r.radius){const p=c.x-r.center.x,h=c.z-r.center.z;return p*p+h*h<=r.radius*r.radius}return!1}const Wa=Qn.memo(function({agentId:r,terminalViewMode:p,onTerminalViewModeChange:h,inspectorOpen:k,onToggleInspector:T,onShowTaskBoard:S,onImageClick:y,onFileClick:Y,onBashClick:_,onViewMarkdown:W,onRequestClearSubordinates:H,keyboard:re,canNavigateBack:P,canNavigateForward:Ee,onNavigateBack:oe,onNavigateForward:ce,agentInfoOpen:$e,onToggleAgentInfo:ot,onHeaderContextMenu:xe,onBuildingContextMenu:be}){var st,_t;const m=nn(r),O=mn(),Ie=ea(),ze=a.useRef(null),We=a.useRef(null),{displayedAgentId:Me,fadingOut:At}=ta(r),ct=nn(Me),He=!!Ie.interactiveMode&&((m==null?void 0:m.provider)??"claude")==="claude"&&!!(m!=null&&m.sessionId),[de,Ue]=a.useState(!1);a.useEffect(()=>{Ue(!1)},[r]),a.useEffect(()=>{!He&&de&&Ue(!1)},[He,de]),a.useEffect(()=>{const n=We.current;if(!n)return;const o=d=>{d.button===3?(d.preventDefault(),d.stopPropagation(),oe()):d.button===4&&(d.preventDefault(),d.stopPropagation(),ce())},i=d=>{(d.button===3||d.button===4)&&d.preventDefault()};return n.addEventListener("mouseup",o),n.addEventListener("mousedown",i),()=>{n.removeEventListener("mouseup",o),n.removeEventListener("mousedown",i)}},[oe,ce]),a.useEffect(()=>{const n=We.current;if(!n)return;let o=0,i=0,d=0;const z=250,le=600,R=80,De=1.5,Ze=D=>{let U=D instanceof HTMLElement?D:null;for(;U&&U!==n;){const vt=window.getComputedStyle(U).overflowX;if((vt==="auto"||vt==="scroll")&&U.scrollWidth>U.clientWidth)return!0;U=U.parentElement}return!1},wt=D=>{const U=Date.now();if(U<d){D.preventDefault();return}if(Math.abs(D.deltaX)<=Math.abs(D.deltaY)*De){o=0;return}if(Ze(D.target)){o=0;return}U-i>z&&(o=0),i=U,o+=D.deltaX,o<=-R?(o=0,d=U+le,D.preventDefault(),oe()):o>=R&&(o=0,d=U+le,D.preventDefault(),ce())};return n.addEventListener("wheel",wt,{passive:!1}),()=>n.removeEventListener("wheel",wt)},[oe,ce]);const Te=pn(),ue=a.useMemo(()=>{if(!m)return null;const n=new Set,o=[];for(const i of Te.values())i.archived||i.directories.length===0||i.assignedAgentIds.includes(r)&&(n.add(i.id),o.push(i));for(const i of Te.values())i.archived||i.directories.length===0||n.has(i.id)||Fa({x:m.position.x,z:m.position.z},i)&&(n.add(i.id),o.push(i));return o.length===0?null:o.flatMap(i=>i.directories.filter(d=>d&&d.trim().length>0).map(d=>({areaId:i.id,areaName:i.name,dir:d})))},[m,r,Te]),{branches:_e,fetchRemote:we,fetchingDirs:dt}=na(ue),Ve=a.useMemo(()=>{var i;const n=g.getAreaForAgent(r);if(!n)return[];const o=[];for(const d of O.values())d.type==="terminal"&&g.isPositionInArea(d.position,n)&&o.push({id:d.id,name:d.name,hasUrl:!!((i=d.terminalStatus)!=null&&i.url)});return o},[r,O]),ve=a.useMemo(()=>{var i;const n=g.getAreaForAgent(r);if(!n)return[];const o=[];for(const d of O.values())d.type==="server"&&((i=d.pm2)!=null&&i.enabled)&&g.isPositionInArea(d.position,n)&&o.push({id:d.id,name:d.name});return o},[r,O]),pe=a.useMemo(()=>{const n=g.getAreaForAgent(r);if(!n)return[];const o=[];for(const i of O.values())i.type==="database"&&i.database&&g.isPositionInArea(i.position,n)&&o.push({id:i.id,name:i.name});return o},[r,O]),Le=aa(),je=a.useMemo(()=>{const n=g.getAreaForAgent(r);if(!n)return[];const o=[];for(const i of O.values())if(i.type==="tests"&&g.isPositionInArea(i.position,n)){const d=!!i.folderPath&&Le.some(z=>sa(z,i.folderPath));o.push({id:i.id,name:i.name,working:d})}return o},[r,O,Le]),K=a.useMemo(()=>{const n=g.getAreaForAgent(r);if(!n)return[];const o=[];for(const i of O.values())i.type==="http"&&g.isPositionInArea(i.position,n)&&o.push({id:i.id,name:i.name});return o},[r,O]),[,Xe]=a.useReducer(n=>n+1,0),te=((st=ze.current)==null?void 0:st.search.searchMode)??!1,Pe=a.useCallback(()=>{var n;(n=ze.current)==null||n.search.toggleSearch(),Xe()},[]),ut=ia(),Qe=ut.isPending(on),[j,ne]=a.useState(null),Z=j?O.get(j.buildingId):null,[pt,Q]=a.useState(""),[et,Ge]=a.useState(()=>la()),B=a.useMemo(()=>{var n;return((n=g.getAreaForAgent(r))==null?void 0:n.id)??null},[r,O]),Ce=a.useCallback((n,o)=>{Q(""),ne(i=>{const d=(i==null?void 0:i.buildingId)===o?null:{type:n,buildingId:o};return B&&Ht(B,d),d})},[B]),ke=a.useCallback(()=>{Q(""),ne(null),B&&Ht(B,null)},[B]);a.useEffect(()=>{if((j==null?void 0:j.type)!=="pm2-logs")return;const n=j.buildingId;return g.startLogStreaming(n,200),()=>g.stopLogStreaming(n)},[j]);const{height:Et,onResizeStart:It}=ra(),{sidePanelWidth:Mt,handleSidePanelResizeStart:Tt}=oa(),[Oe,mt]=a.useState(()=>Ut(A.GIT_PANEL_OPEN,!1)),[ye,w]=a.useState(()=>Ut(A.BUILDINGS_PANEL_OPEN,!1)),[Be,ft]=a.useState(!1),Ne=a.useCallback(()=>{ft(n=>{const o=!n;return o&&ca.setEnabled(!0),o})},[]),ae=a.useCallback(()=>ft(!1),[]),qe=a.useCallback(()=>{mt(n=>{const o=!n;return ge(A.GIT_PANEL_OPEN,o),o})},[]),ht=a.useCallback(()=>{w(n=>{const o=!n;return ge(A.BUILDINGS_PANEL_OPEN,o),o})},[]),Lt=a.useCallback(()=>{mt(!1),ge(A.GIT_PANEL_OPEN,!1)},[]),Pt=a.useCallback(()=>{w(!1),ge(A.BUILDINGS_PANEL_OPEN,!1)},[]),Rt=da(),Re=a.useMemo(()=>({terminal:Ve,"pm2-logs":ve,database:pe,tests:je,http:K}),[Ve,ve,pe,je,K]);a.useEffect(()=>{if(!j)return;Re[j.type].some(o=>o.id===j.buildingId)||(Q(""),ne(null))},[j,Re]);const Ye=a.useRef(void 0);a.useEffect(()=>{var o;if(Ye.current===B)return;Ye.current=B;const n=B?_n()[B]:void 0;Q(""),n&&((o=Re[n.type])!=null&&o.some(i=>i.id===n.buildingId))?ne(n):ne(null)},[B,Re]),a.useEffect(()=>{const n=o=>{var z;const i=o.detail;if(!(i!=null&&i.buildingId)||!(i!=null&&i.type)||!((z=Re[i.type])!=null&&z.some(le=>le.id===i.buildingId)))return;i.handled=!0,Q("");const d={type:i.type,buildingId:i.buildingId};ne(d),B&&Ht(B,d)};return window.addEventListener("tide:dock-building-flat",n),()=>window.removeEventListener("tide:dock-building-flat",n)},[Re,B]);const[se,me]=a.useState(!1),fe=a.useRef(null);if(a.useEffect(()=>{if(!se)return;const n=o=>{fe.current&&!fe.current.contains(o.target)&&me(!1)};return document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[se]),!m)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 Se=m.contextStats,J=!!Se,Ae=Se?Se.totalTokens:m.contextUsed||0,gt=Se?Se.contextWindow:m.contextLimit||(m.provider==="grok"?5e5:2e5),Dt=Se?Se.usedPercent:Math.round(Ae/gt*100),he=Math.max(0,Math.min(100,Dt)),tt=Math.round(he*10)/10,$t=Math.round((100-he)*10)/10,xt=he>=80?"#ff4a4a":he>=60?"#ff9e4a":he>=40?"#ffd700":"#4aff9e",nt=(Ae/1e3).toFixed(1),ee=(gt/1e3).toFixed(1),ie=m.cwd,at=ie?Oa(ie):null,Ke=((_t=m.subordinateIds)==null?void 0:_t.length)||0,bt=Ke>0;return e.jsxs("div",{ref:We,className:`flat-terminal-wrapper ${Oe||ye||Be?"flat-terminal-wrapper--with-side-panel":""} ${At?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${Mt}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${$e?"flat-terminal-wrapper__header-main--active":""}`,onClick:ot,onContextMenu:n=>{n.preventDefault(),n.stopPropagation(),xe({x:n.clientX,y:n.clientY})},title:$e?"Hide agent info":"Show agent info","aria-pressed":$e,children:[e.jsx("span",{className:`flat-terminal-wrapper__header-avatar${m.status==="working"?" is-working":""}`,children:e.jsx(fn,{agent:m,size:28})}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:m.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:xn(m.status)},children:m.status})]}),m.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:m.taskLabel,children:["📋 ",m.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:gn(m.provider,"/"),alt:m.provider,className:"flat-terminal-wrapper__header-provider-icon",title:hn(m.provider)}),(()=>{const{model:n,effort:o}=Ba(m);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:o?`Model: ${n} · Effort: ${o}`:`Model: ${n}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:n}),o&&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:o})]})]})})()]})]}),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:[Ra.map(n=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!de&&p===n?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Ue(!1),h(n)},title:za[n],"aria-pressed":!de&&p===n,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:$a[n]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Da[n]})]},n)),He&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${de?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Ue(n=>!n),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":de,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:e.jsx(f,{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:oe,disabled:!P,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(f,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:ce,disabled:!Ee,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(f,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${te?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Pe,title:te?"Close search":"Search messages","aria-pressed":te,children:e.jsx(f,{name:te?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Qe?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>ut.handleClick(on,()=>{var n;g.clearContext(r),(n=ze.current)==null||n.historyLoader.clearHistory()}),title:Qe?"Click again to confirm clear context":"Clear context",children:e.jsx(f,{name:Qe?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Oe?"flat-terminal-wrapper__action-btn--active":""}`,onClick:qe,title:Oe?"Hide git panel":"Show git changes","aria-pressed":Oe,children:e.jsx(f,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ye?"flat-terminal-wrapper__action-btn--active":""}`,onClick:ht,title:ye?"Hide buildings panel":"Show area buildings","aria-pressed":ye,children:e.jsx(f,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:fe,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 ${Be?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Ne(),me(!1)},title:Be?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(f,{name:"bug",size:14}),e.jsx("span",{children:Be?"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:()=>{g.collapseContext(r),me(!1)},disabled:m.status!=="idle",title:m.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(f,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),bt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{H(r,Ke),me(!1)},children:[e.jsx(f,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",Ke," subordinate",Ke===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:()=>{g.killAgent(r),me(!1)},children:[e.jsx(f,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${k?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:T,title:k?"Hide inspector panel":"Show inspector panel","aria-label":k?"Hide inspector panel":"Show inspector panel","aria-pressed":k,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:()=>g.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(f,{name:"cross",size:14})})]})]}),e.jsx(ua,{agent:m,onClick:S}),de&&He?e.jsx(Ea,{agentId:r}):Me&&ct?e.jsx(pa,{ref:ze,agentId:Me,agent:ct,viewMode:p,isOpen:!0,onImageClick:y,onFileClick:Y,onBashClick:_,onViewMarkdown:W,keyboard:re,hasModalOpen:!1},Me):null,j&&Z&&(()=>{var z,le;const n=j.type,o={terminal:"terminal","pm2-logs":"scroll",database:"hard-drives",tests:"flask",http:"globe"},i=n==="terminal"&&!((z=Z.terminalStatus)!=null&&z.url),d=!i;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:It,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded panel"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`${Z.name} panel`,style:{height:Et},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(f,{name:o[n],size:12}),e.jsx("span",{children:Z.name}),i&&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:pt,onChange:R=>Q(R.target.value),placeholder:"Filter logs","aria-label":`Filter logs for ${Z.name}`,spellCheck:!1}),e.jsx("select",{className:"guake-bottom-terminal-retention",value:et===null?"unlimited":String(et),onChange:R=>{const De=R.target.value==="unlimited"?null:Number(R.target.value);Ge(De),fa(De)},"aria-label":`Max log retention for ${Z.name}`,children:ma.map(R=>e.jsx("option",{value:R===null?"unlimited":String(R),children:R===null?"Unlimited":`${R.toLocaleString()} lines`},R===null?"unlimited":R))}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>g.clearStreamingLogs(j.buildingId),title:"Clear logs",children:e.jsx(f,{name:"trash",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>g.sendBuildingCommand(j.buildingId,"restart"),title:"Restart",children:e.jsx(f,{name:"restart",size:12})})]}),d&&e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>{ke(),Je(j.buildingId)},title:"Maximize — open as modal","aria-label":"Open as modal",children:e.jsx(f,{name:"fullscreen",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:ke,title:"Close panel","aria-label":"Close panel",children:e.jsx(f,{name:"cross",size:12})})]})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:n==="terminal"?(le=Z.terminalStatus)!=null&&le.url?e.jsx(un,{terminalUrl:Z.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."}):n==="pm2-logs"?e.jsx(ha,{buildingId:j.buildingId,filterText:pt,maxRetention:et}):n==="database"?e.jsx(ga,{building:Z}):n==="tests"?e.jsx("div",{className:"tests-panel-host",children:e.jsx(xa,{building:Z,autoFocusSearch:!1})}):e.jsx("div",{className:"http-requests-panel-host",children:e.jsx(ba,{building:Z,autoFocusSearch:!1})})})]})]})})(),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[m.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(f,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),ie&&at&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${ie}`,"aria-label":`Open ${ie} in file explorer`,role:"button",tabIndex:0,onClick:()=>g.openFileExplorer(ie),onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),g.openFileExplorer(ie))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(f,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:at})]}),ue&&ue.map(({areaId:n,areaName:o,dir:i})=>{const d=_e.get(i),z=dt.has(i),le=i.split("/").filter(Boolean).pop()||i;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${o}: ${i}${d?` (${d.branch}${d.ahead?` ↑${d.ahead}`:""}${d.behind?` ↓${d.behind}`:""})`:""}`,onClick:()=>g.openFileExplorerForAreaFolder(n,i),children:[e.jsx(f,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:le}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(f,{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(f,{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(f,{name:"arrow-down",size:9}),d.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${z?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:R=>{R.stopPropagation(),we(i)},children:e.jsx(f,{name:z?"hourglass":"download",size:12})})]})]},`${n}:${i}`)}),e.jsx(La,{agentId:r,disabled:((m==null?void 0:m.provider)??"claude")!=="claude"&&((m==null?void 0:m.provider)??"claude")!=="grok",contextSummary:J?`Context: ${nt}k / ${ee}k tokens (${tt}% used)`:void 0,children:e.jsxs("span",{className:"flat-terminal-wrapper__context",tabIndex:0,role:"button",onClick:()=>g.setContextModalAgentId(r),onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),g.setContextModalAgentId(r))},title:((m==null?void 0:m.provider)??"claude")!=="claude"&&((m==null?void 0:m.provider)??"claude")!=="grok"?J?`Context usage: ${nt}k / ${ee}k tokens (${tt}% 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(f,{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:`${he}%`,backgroundColor:xt}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:xt},children:[nt,"k/",ee,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",$t,"% free)"]}),!J&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(f,{name:"warn",size:12})})]})}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),Ve.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:Ve.map(n=>{const o=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""} ${n.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${o?"Hide":"Show"} terminal: ${n.name}${n.hasUrl?"":" (starting...)"}`,onClick:()=>{if(o){ke();return}if(n.hasUrl&<(n.id)==="modal"){Je(n.id);return}n.hasUrl||g.sendBuildingCommand(n.id,"start"),Ce("terminal",n.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),be(n.id,{x:i.clientX,y:i.clientY})},children:e.jsx(f,{name:"terminal",size:14})},n.id)})}),ve.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:ve.map(n=>{const o=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} logs: ${n.name}`,onClick:()=>{o?ke():lt(n.id)==="modal"?Je(n.id):Ce("pm2-logs",n.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),be(n.id,{x:i.clientX,y:i.clientY})},children:e.jsx(f,{name:"scroll",size:14})},n.id)})}),pe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:pe.map(n=>{const o=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} database: ${n.name}`,onClick:()=>{o?ke():lt(n.id)==="modal"?Je(n.id):Ce("database",n.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),be(n.id,{x:i.clientX,y:i.clientY})},children:e.jsx(f,{name:"hard-drives",size:14})},n.id)})}),je.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:je.map(n=>{const o=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""} ${n.working?"flat-terminal-wrapper__building-btn--tests-working":""}`,title:n.working?`Running tests: ${n.name}`:`${o?"Hide":"Show"} tests: ${n.name}`,onClick:()=>{o?ke():lt(n.id)==="modal"?Je(n.id):Ce("tests",n.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),be(n.id,{x:i.clientX,y:i.clientY})},children:e.jsx(f,{name:"flask",size:14})},n.id)})}),K.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area HTTP requests",children:K.map(n=>{const o=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} HTTP requests: ${n.name}`,onClick:()=>{o?ke():lt(n.id)==="modal"?Je(n.id):Ce("http",n.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),be(n.id,{x:i.clientX,y:i.clientY})},children:e.jsx(f,{name:"globe",size:14})},n.id)})}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(_a,{})})]}),Oe&&e.jsx(wa,{agentId:r,agents:Rt,onClose:Lt,branchInfoMap:_e,fetchRemote:we,fetchingDirs:dt,onResizeStart:n=>Tt(n,"right")}),ye&&e.jsx(va,{agentId:r,onClose:Pt}),Be&&e.jsx(ja,{agentId:r,onClose:ae})]})}),Ha={groups:[],gridCols:1,gridRows:1,positions:new Map};function qa({onAgentClick:c,onBuildingClick:r,onBuildingDoubleClick:p,onBuildingPopup:h,onAreaContextMenu:k,onOpenSpawnModal:T,onOpenBossSpawnModal:S,onOpenAreaModal:y}){const{t:Y}=Vt(["common"]),_=Tn(),W=Ln(),[H,re]=a.useState(null),[P,Ee]=a.useState(null),[oe,ce]=a.useState(null);Pn("flatview-image-modal",H!==null,()=>re(null));const[$e,ot]=a.useState(null),[xe,be]=a.useState(null),[m,O]=a.useState(null),[Ie,ze]=a.useState(null),[We,Me]=a.useState(!1),At=a.useCallback(()=>{Me(t=>!t)},[]),ct=a.useCallback(()=>{Me(!1)},[]),[He,de]=a.useState(()=>{const t=Kt(A.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ue=a.useCallback(t=>{de(t),Zt(A.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=s=>{if(s.key!==A.VIEW_MODE)return;const l=s.newValue;(l==="simple"||l==="chat"||l==="advanced")&&de(l)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[Te,ue]=a.useState(()=>Ut(A.FLAT_INSPECTOR_OPEN,!1)),[_e,we]=a.useState(!1),dt=a.useCallback(()=>we(t=>!t),[]),Ve=a.useCallback(()=>we(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:_e}}))},[_e]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:Te}}))},[Te]),a.useEffect(()=>{const t=()=>we(C=>!C),s=()=>{ue(C=>{const E=!C;return ge(A.FLAT_INSPECTOR_OPEN,E),E})},l=()=>{we(!1),ue(!1),ge(A.FLAT_INSPECTOR_OPEN,!1)},x=()=>we(!1),b=()=>{ue(!1),ge(A.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",l),window.addEventListener("tide-close-flat-agents-drawer-only",x),window.addEventListener("tide-close-flat-inspector-only",b),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",s),window.removeEventListener("tide-close-flat-side-views",l),window.removeEventListener("tide-close-flat-agents-drawer-only",x),window.removeEventListener("tide-close-flat-inspector-only",b)}},[]);const ve=a.useRef(null),pe=a.useRef(null),[Le,je]=a.useState(()=>{const t=Jt(A.FLAT_MIDDLE_WIDTH,0);return t>=St?t:null}),[K,Xe]=a.useState(()=>{const t=Jt(A.FLAT_INSPECTOR_WIDTH,0);return t>=Wt?t:null}),te=a.useCallback(t=>{if(typeof window>"u")return t;const s=K!==null?Nt+K:0,l=window.innerWidth-rn-Nt-ln-s;return Math.max(St,Math.min(Math.max(l,St),t))},[K]),Pe=a.useCallback(t=>{var b;if(typeof window>"u")return t;const s=(b=ve.current)==null?void 0:b.querySelector(".flat-middle"),l=(s==null?void 0:s.getBoundingClientRect().width)??St,x=window.innerWidth-rn-l-Nt-ln-Nt;return Math.max(Wt,Math.min(Math.max(x,Wt),t))},[]);a.useEffect(()=>{if(Le===null&&K===null)return;const t=()=>{je(s=>{if(s===null)return s;const l=te(s);return l===s?s:l}),Xe(s=>{if(s===null)return s;const l=Pe(s);return l===s?s:l})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[Le,K,te,Pe]);const ut=a.useCallback(t=>{var l;if(t.button!==0)return;const s=(l=ve.current)==null?void 0:l.querySelector(".flat-middle");s&&(t.currentTarget.setPointerCapture(t.pointerId),pe.current={kind:"middle",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Qe=a.useCallback(t=>{var l;if(t.button!==0)return;const s=(l=ve.current)==null?void 0:l.querySelector(".flat-inspector");s&&(t.currentTarget.setPointerCapture(t.pointerId),pe.current={kind:"inspector",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),j=a.useCallback(t=>{const s=pe.current;if(!s||t.pointerId!==s.pointerId)return;const l=t.clientX-s.startX;s.kind==="middle"?je(te(s.startWidth+l)):Xe(Pe(s.startWidth-l))},[te,Pe]),ne=a.useCallback(t=>{const s=pe.current;if(!s||t.pointerId!==s.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(pe.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-s.startX)>2))return;const x=t.clientX-s.startX;if(s.kind==="middle"){const b=te(s.startWidth+x);je(b),yt(A.FLAT_MIDDLE_WIDTH,b)}else{const b=Pe(s.startWidth-x);Xe(b),yt(A.FLAT_INSPECTOR_WIDTH,b)}},[te,Pe]),Z=a.useCallback(()=>{je(null),yt(A.FLAT_MIDDLE_WIDTH,0)},[]),pt=a.useCallback(()=>{Xe(null),yt(A.FLAT_INSPECTOR_WIDTH,0)},[]),[Q,et]=a.useState(()=>Kt(A.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Ge=a.useCallback(t=>{et(t),Zt(A.FLAT_INSPECTOR_VIEW,t)},[]),B=a.useCallback(()=>{ue(t=>{const s=!t;return ge(A.FLAT_INSPECTOR_OPEN,s),s})},[]),Ce=a.useCallback(()=>{ue(!1),ge(A.FLAT_INSPECTOR_OPEN,!1)},[]),ke=a.useCallback(()=>{Ge("tracking"),ue(!0),ge(A.FLAT_INSPECTOR_OPEN,!0)},[Ge]),Et=Rn(),It=a.useCallback((t,s)=>{re({url:t,name:s})},[]),Mt=a.useCallback((t,s)=>{Ee({command:t,output:s,isLive:!1})},[]),Tt=a.useCallback((t,s)=>{var b;const l=W.size>0?Array.from(W)[0]:null,x=l?(b=g.getState().agents.get(l))==null?void 0:b.cwd:void 0;g.setFileViewerPath(t,s,x)},[W]),Oe=a.useCallback(t=>{ce(t)},[]),mt=a.useCallback((t,s)=>{ot({agentId:t,count:s})},[]),ye=a.useCallback(t=>{p?p(t):r(t)},[r,p]),w=a.useMemo(()=>W.size>0?Array.from(W)[0]:null,[W]),Be=a.useCallback(t=>{w&&be({agentId:w,position:t})},[w]),ft=a.useCallback((t,s)=>{O({buildingId:t,position:s})},[]);a.useEffect(()=>{Me(!1)},[w]);const Ne=a.useRef([]),ae=a.useRef(-1),qe=a.useRef(!1),ht=a.useRef(null),[Lt,Pt]=a.useState(!1),[Rt,Re]=a.useState(!1),Ye=a.useRef(!1),se=a.useRef(null),me=a.useRef(!1),fe=a.useMemo(()=>new Set(_.map(t=>t.id)),[_]),Se=a.useMemo(()=>{const t=new Map(_.map(l=>[l.id,l])),s=new Map;for(const l of _)if((l.isBoss||l.class==="boss")&&l.subordinateIds&&l.subordinateIds.length>0){const x=l.subordinateIds.map(b=>t.get(b)).filter(b=>b!==void 0);x.length>0&&s.set(l.id,x)}return s},[_]),J=a.useCallback(()=>{const t=Ne.current,s=ae.current;Pt(s>0),Re(s>=0&&s<t.length-1)},[]),Ae=a.useCallback(t=>{const s=Ne.current;if(s.length===0)return;let l=ae.current+t;for(;l>=0&&l<s.length;){const x=s[l];if(fe.has(x)){qe.current=!0,ae.current=l,J(),g.selectAgent(x);return}l+=t}},[fe,J]),gt=a.useCallback(()=>Ae(-1),[Ae]),Dt=a.useCallback(()=>Ae(1),[Ae]);Na(a.useCallback(()=>{const t=Ne.current,s=ae.current;return t.length>0&&s>0?(Ae(-1),"handled"):"exit"},[Ae]));const he=a.useCallback((t,s)=>{if(typeof window>"u")return;const l=window.history.state,b={...typeof l=="object"&&l!==null?l:{},__flatAgentNav:{agentId:t}};s==="replace"?window.history.replaceState(b,"",window.location.href):window.history.pushState(b,"",window.location.href)},[]);a.useEffect(()=>{if(!w){Ye.current=!1,se.current=null;return}if(!Ye.current){he(w,"replace"),Ye.current=!0,se.current=w;return}if(me.current){me.current=!1,se.current=w;return}se.current!==w&&(he(w,"push"),se.current=w)},[w,he]),a.useEffect(()=>{const t=s=>{var C,E;const l=(E=(C=s.state)==null?void 0:C.__flatAgentNav)==null?void 0:E.agentId;if(!l||typeof l!="string"||!fe.has(l)||l===w)return;me.current=!0,qe.current=!0;const x=Ne.current,b=x.lastIndexOf(l);b>=0?ae.current=b:(x.push(l),ae.current=x.length-1),J(),g.selectAgent(l)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[fe,w,J]),a.useEffect(()=>{if(!w){Ne.current=[],ae.current=-1,J();return}if(ht.current=w,qe.current){qe.current=!1,J();return}const t=Ne.current,s=ae.current;if(s>=0&&t[s]===w){J();return}const l=s<t.length-1?t.slice(0,s+1):t.slice();l.push(w),l.length>100&&l.shift(),Ne.current=l,ae.current=l.length-1,J()},[w,J]);const tt=a.useCallback(t=>{c(t),we(!1)},[c]),$t=w??"",xt=a.useCallback(()=>{},[]),nt=a.useCallback(t=>{tt(t)},[tt]),ee=Te,[ie,at]=a.useState(ee),[Ke,bt]=a.useState(ee);a.useEffect(()=>{if(ee){at(!0);return}bt(!1);const t=setTimeout(()=>at(!1),240);return()=>clearTimeout(t)},[ee]),a.useEffect(()=>{if(!ie||!ee)return;let t=0;const s=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>bt(!0))});return()=>{cancelAnimationFrame(s),cancelAnimationFrame(t)}},[ie,ee]);const st=a.useRef(null);a.useEffect(()=>{if(w)return;const t=s=>{if(s.key!==" "&&s.key!=="Backspace")return;const l=s.target;if(l.tagName==="INPUT"||l.tagName==="TEXTAREA"||l.isContentEditable)return;const x=ht.current;!x||!fe.has(x)||(s.preventDefault(),g.selectAgent(x))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[w,fe]);const[_t,n]=a.useState(new Set),o=a.useCallback(t=>{n(s=>{const l=new Set(s);return l.has(t)?l.delete(t):l.add(t),l})},[]),[i,d]=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=l=>d(l.matches);return t.addEventListener("change",s),()=>t.removeEventListener("change",s)},[]);const[z,le]=a.useState(null),R=a.useCallback(t=>{le(s=>s===t?null:t)},[]),De=pn(),Ze=mn(),[wt]=Dn(),D=a.useMemo(()=>{if(w)return Ha;const t=new Map,s=[];for(const v of _){const M=g.getAreaForAgent(v.id);if(!Qt((M==null?void 0:M.id)??null))continue;if(!M||M.archived){s.push(v);continue}const L=t.get(M.id);L?L.push(v):t.set(M.id,[v])}const l=new Map,x=[];for(const v of Ze.values()){let M=!1;for(const L of De.values())if(!L.archived&&en(L.id)&&g.isPositionInArea(v.position,L)){const X=l.get(L.id);X?X.push(v):l.set(L.id,[v]),M=!0;break}!M&&Qt(null)&&x.push(v)}const b=[];for(const[,v]of De){if(v.archived||!en(v.id))continue;const M=t.get(v.id),L=l.get(v.id)??[];(M&&M.length>0||L.length>0)&&b.push({area:v,agents:M??[],buildings:L})}(s.length>0||x.length>0)&&b.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:x});const C=b.filter(v=>v.area.id!=="__unassigned__"),E=b.filter(v=>v.area.id==="__unassigned__");let u=1,I=1;const V=new Map;if(C.length>1){let v=1/0,M=-1/0,L=1/0,X=-1/0;for(const G of C)v=Math.min(v,G.area.center.x),M=Math.max(M,G.area.center.x),L=Math.min(L,G.area.center.z),X=Math.max(X,G.area.center.z);const jt=M-v||1,Ct=X-L||1;if(C.length<=4){u=C.length,I=1;const G=[...C].sort((q,zt)=>q.area.center.x-zt.area.center.x);for(let q=0;q<G.length;q++)V.set(G[q].area.id,{row:1,col:q+1})}else{const G=[...C].sort((N,F)=>N.area.center.x-F.area.center.x),q=[];for(let N=1;N<G.length;N++)q.push(G[N].area.center.x-G[N-1].area.center.x);const zt=q.reduce((N,F)=>N+F,0)/q.length||1;let Xt=1;for(const N of q)N>zt*1.3&&Xt++;u=Math.max(2,Math.min(Xt,C.length));const Ot=[...C].sort((N,F)=>N.area.center.z-F.area.center.z),kt=[];for(let N=1;N<Ot.length;N++)kt.push(Ot[N].area.center.z-Ot[N-1].area.center.z);const vn=kt.reduce((N,F)=>N+F,0)/kt.length||1;let Gt=1;for(const N of kt)N>vn*1.3&&Gt++;I=Math.max(2,Math.min(Gt,C.length)),u=Math.max(u,Math.ceil(C.length/I)),I=Math.max(I,Math.ceil(C.length/u));const jn=jt/u,Cn=Ct/I,Bt=new Set;for(const N of C){let F=Math.min(u-1,Math.max(0,Math.floor((N.area.center.x-v)/jn))),Fe=Math.min(I-1,Math.max(0,Math.floor((N.area.center.z-L)/Cn))),it=`${Fe},${F}`,qt=0;const kn=I*u;for(;Bt.has(it)&&qt<kn;)F++,F>=u&&(F=0,Fe=(Fe+1)%I),it=`${Fe},${F}`,qt++;Bt.has(it)&&(Fe=I,F=0,it=`${Fe},${F}`,I++),Bt.add(it),V.set(N.area.id,{row:Fe+1,col:F+1})}}}const $=v=>{v.sort((M,L)=>{var jt,Ct,G,q;const X=(((jt=M.position)==null?void 0:jt.z)??0)-(((Ct=L.position)==null?void 0:Ct.z)??0);return X!==0?X:(((G=M.position)==null?void 0:G.x)??0)-(((q=L.position)==null?void 0:q.x)??0)})};for(const v of C)$(v.agents);for(const v of E)$(v.agents);return{groups:[...C,...E],gridCols:u,gridRows:I,positions:V}},[_,De,Ze,wt,w]),U=a.useMemo(()=>{if(!xe)return[];const t=_.find(s=>s.id===xe.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(f,{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(f,{name:"chat",size:14}),onClick:()=>c(t.id)},{id:"clone-agent",label:"Clone Agent",icon:e.jsx(f,{name:"clipboard",size:14}),onClick:()=>g.cloneAgent(t.id)},{id:"fork-agent",label:"Fork Agent (with history)",icon:e.jsx(f,{name:"git-branch",size:14}),onClick:()=>g.forkAgent(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(f,{name:"trash",size:14}),danger:!0,onClick:()=>{ze({agentId:t.id,name:t.name})}}]:[]},[xe,_,c]),vt=a.useMemo(()=>{var C;if(!m)return[];const t=Ze.get(m.buildingId);if(!t)return[];const s=[],l=t.type==="server"||t.type==="docker"||t.type==="terminal",x=t.status==="running",b=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(f,{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:()=>ye(t.id)}),l&&(x||s.push({id:"start",label:"Start",icon:e.jsx(f,{name:"play",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"start")}),x&&(s.push({id:"restart",label:"Restart",icon:e.jsx(f,{name:"refresh",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"restart")}),s.push({id:"stop",label:"Stop",icon:e.jsx(f,{name:"stop",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"stop")}))),b&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(s.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(f,{name:"launch",size:14}),onClick:()=>{for(const E of t.subordinateBuildingIds)g.sendBuildingCommand(E,"start")}}),s.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(f,{name:"pause",size:14}),onClick:()=>{for(const E of t.subordinateBuildingIds)g.sendBuildingCommand(E,"stop")}}),s.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(f,{name:"restart",size:14}),onClick:()=>{for(const E of t.subordinateBuildingIds)g.sendBuildingCommand(E,"restart")}})),l&&s.push({id:"health-check",label:"Health Check",icon:e.jsx(f,{name:"health",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"healthCheck")}),s.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),s.push({id:"edit",label:"Edit Building",icon:e.jsx(f,{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(f,{name:"copy",size:14}),onClick:()=>{g.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 E of t.urls)s.push({id:`url-${E.label}`,label:E.label,icon:e.jsx(f,{name:"link",size:14}),onClick:()=>window.open(E.url,"_blank","noopener,noreferrer")});return s.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),s.push({id:"delete",label:"Delete Building",icon:e.jsx(f,{name:"trash",size:14}),danger:!0,onClick:()=>g.deleteBuilding(t.id)}),s},[m,Ze,ye]),wn=a.useCallback(t=>{const s=new Set(D.groups.map(l=>l.area.id));s.delete(t),n(s),requestAnimationFrame(()=>{const l=st.current;if(!l)return;const x=l.querySelector(`[data-area-id="${t}"]`);if(!x)return;const b=l.getBoundingClientRect(),E=x.getBoundingClientRect().top-b.top+l.scrollTop-8;l.scrollTo({top:Math.max(0,E),behavior:"smooth"})})},[D]);return e.jsxs("div",{ref:ve,className:`flat-view ${ee?"flat-view--with-inspector":""} ${w?"flat-view--has-chat":""} ${_e?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(Le===null&&K===null)return;const t={};return Le!==null&&(t["--flat-middle-width"]=`${Le}px`),K!==null&&(t["--flat-inspector-width"]=`${K}px`),t})(),children:[_e&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Ve,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children:e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:T,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:S,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:y,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx($n,{activeAgentId:$t,onClose:xt,onSelectAgent:nt,collapsedAreas:_t,onToggleArea:o,agentListRef:st})})]}),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:ut,onPointerMove:j,onPointerUp:ne,onPointerCancel:ne,onDoubleClick:Z}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":_e?"Close agents sidebar":"Open agents sidebar","aria-expanded":_e,onClick:dt,children:[e.jsx(f,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),w?e.jsx(Wa,{agentId:w,terminalViewMode:He,onTerminalViewModeChange:Ue,inspectorOpen:Te,onToggleInspector:B,onShowTaskBoard:ke,onImageClick:It,onFileClick:Tt,onBashClick:Mt,onViewMarkdown:Oe,onRequestClearSubordinates:mt,keyboard:Et,canNavigateBack:Lt,canNavigateForward:Rt,onNavigateBack:gt,onNavigateForward:Dt,agentInfoOpen:We,onToggleAgentInfo:At,onHeaderContextMenu:Be,onBuildingContextMenu:ft}):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(Pa,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${D.gridCols}, 1fr)`},children:D.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var s;const t=i&&z?((s=D.positions.get(z))==null?void 0:s.row)??null:null;return D.groups.map(l=>{var E;const x=l.area.id,b=D.positions.get(x),C=i&&z!==x;return i&&t!=null&&(b==null?void 0:b.row)===t&&x!==z?null:e.jsxs("div",{className:`flat-map-area-card${C?" flat-map-area-card--collapsed":""}`,style:{"--area-color":l.area.color,gridRow:b==null?void 0:b.row,gridColumn:b==null?void 0:b.col},onContextMenu:u=>{k&&(u.preventDefault(),u.stopPropagation(),k(x,{x:u.clientX,y:u.clientY}))},children:[((E=l.area.logo)==null?void 0:E.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:ya(l.area.logo.filename),alt:"","aria-hidden":"true",onError:u=>{u.currentTarget.style.display="none"}}),e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>i?R(x):wn(x),title:i?C?`Expand ${l.area.name}`:`Collapse ${l.area.name}`:`Focus ${l.area.name} in left panel`,"aria-expanded":i?!C:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:l.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:l.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:l.agents.length}),i&&e.jsx(f,{name:C?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:l.agents.map(u=>{const I=u.isBoss||u.class==="boss",V=I?Se.get(u.id):void 0,$=zn(u),v=$.usedPercent>=80?"#ff4a4a":$.usedPercent>=60?"#ff9e4a":$.usedPercent>=40?"#ffd700":"#4aff9e",M=`Context: ${($.totalTokens/1e3).toFixed(1)}k / ${($.contextWindow/1e3).toFixed(1)}k (${$.usedPercent}% used, ${$.freePercent}% free)`,L=u.latestTodos&&u.latestTodos.length>0||V&&V.length>0;return e.jsx(On,{todos:u.latestTodos,subordinates:V,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${u.status}`,onClick:()=>c(u.id),onContextMenu:X=>{X.preventDefault(),X.stopPropagation(),be({agentId:u.id,position:{x:X.clientX,y:X.clientY}})},title:L?void 0:`${I?"Boss · ":""}Open chat with ${u.name}
|
|
1
|
+
import{r as a,H as yn,J as Yt,K as cn,L as dn,j as e,M as un,N as Nn,u as Vt,O as Sn,P as An,U as En,V as In,W as Mn,X as Tn,Y as Ln,Z as Pn,_ as Kt,S as A,$ as Zt,a0 as Ut,a1 as Jt,a2 as yt,a3 as ge,a4 as Rn,s as g,a5 as pn,m as mn,a6 as Dn,z as Qt,B as en,I as f,a7 as $n,q as zn,a8 as On,a9 as fn,aa as hn,ab as gn,ac as xn,ad as Bn,ae as Fn,af as Wn,ag as Hn,ah as Un,ai as Vn,aj as Xn,ak as Gn,al as qn,am as Yn,an as Kn,ao as Zn,ap as tn,C as Jn,aq as Qn,ar as nn,as as ea,at as ta,au as na,av as aa,aw as sa,ax as ia,ay as la,az as ra,aA as oa,aB as ca,aC as da,aD as ua,aE as pa,aF as ma,aG as fa,aH as Je,aI as ha,aJ as ga,aK as xa,aL as ba,aM as lt,aN as _a,aO as wa,aP as va,aQ as ja,aR as Ca,aS as an,aT as ka}from"./main-aIpEYDDR.js";import{g as ya}from"./area-logos-CuVxToGM.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Na(c){const r=a.useRef(c);r.current=c,a.useEffect(()=>{if(!yn())return;let p=null,h=!1;return Yt.addListener("backButton",()=>{r.current()==="exit"&&Yt.exitApp()}).then(k=>{h?k.remove():p=k}),()=>{h=!0,p&&(p.remove(),p=null)}},[])}async function Sa(c){const r=cn(),p=await fetch(`${dn()}/api/agents/${c}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${r}`}});if(!p.ok){const h=await p.json().catch(()=>({}));throw new Error((h==null?void 0:h.error)||`Failed to start terminal (${p.status})`)}return p.json()}async function Aa(c){const r=cn();await fetch(`${dn()}/api/agents/${c}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${r}`}})}const rt=new Map;function Ea({agentId:c}){const[r,p]=a.useState(null),[h,k]=a.useState(null);return a.useEffect(()=>{let T=!1;const S=rt.get(c);return S&&(clearTimeout(S),rt.delete(c)),p(null),k(null),Sa(c).then(y=>{T||p(y.url)}).catch(y=>{T||k(y instanceof Error?y.message:"Failed to start terminal")}),()=>{T=!0;const y=rt.get(c);y&&clearTimeout(y),rt.set(c,setTimeout(()=>{rt.delete(c),Aa(c)},2500))}},[c]),h?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:h})}):r?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(un,{terminalUrl:r,visible:!0})}):e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:"Attaching to interactive session…"})})}const Ft=new Map,Ia=6e4;function sn(c){return Number.isFinite(c)?Math.abs(c)>=1e3?c.toLocaleString(void 0,{maximumFractionDigits:0}):c.toLocaleString(void 0,{maximumFractionDigits:2}):String(c)}function Ma(c,r){var k,T,S;const p=[];if(!c.rateLimits)return p;if(c.provider==="claude"){const y=c,Y=[{key:"fiveHour",label:r("terminal:usage.currentSession"),window:y.rateLimits.fiveHour},{key:"sevenDay",label:r("terminal:usage.currentWeekAll"),window:y.rateLimits.sevenDay},{key:"sevenDayOpus",label:r("terminal:usage.currentWeekOpus"),window:y.rateLimits.sevenDayOpus},{key:"sevenDaySonnet",label:r("terminal:usage.currentWeekSonnet"),window:y.rateLimits.sevenDaySonnet}];for(const _ of Y)_.window&&p.push({..._,window:_.window});return p}const h=c;return(k=h.rateLimits)!=null&&k.weekly&&p.push({key:"weekly",label:r("terminal:usage.weeklyLimit"),window:h.rateLimits.weekly}),(T=h.rateLimits)!=null&&T.monthly&&p.push({key:"monthly",label:r("terminal:usage.monthlyLimit"),window:h.rateLimits.monthly}),(S=h.rateLimits)!=null&&S.onDemand&&p.push({key:"onDemand",label:r("terminal:usage.onDemandLimit"),window:h.rateLimits.onDemand}),p}function Ta({agentId:c,contextSummary:r}){const{t:p}=Vt(["terminal","common"]),[h,k]=a.useState(()=>{var H;return((H=Ft.get(c))==null?void 0:H.snapshot)??null}),[T,S]=a.useState(!1),[y,Y]=a.useState(null),_=a.useRef(0);a.useEffect(()=>{const H=Ft.get(c);if(H&&Date.now()-H.fetchedAt<Ia){k(H.snapshot);return}const re=++_.current;S(!0),Y(null),Sn(c).then(P=>{re===_.current&&(Ft.set(c,{snapshot:P,fetchedAt:Date.now()}),k(P),S(!1))}).catch(P=>{re===_.current&&(Y(P.message||"Failed to load plan limits"),S(!1))})},[c]);const W=h?Ma(h,p):[];return e.jsxs("div",{className:"plan-limits-tooltip",children:[r&&e.jsx("div",{className:"plan-limits-tooltip__context",children:r}),e.jsx("div",{className:"plan-limits-tooltip__title",children:p("terminal:usage.limits")}),T&&!h&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[p("common:status.loading"),"…"]}),!T&&y&&!h&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:p("terminal:usage.limitsError",{message:y})}),W.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:W.map(({key:H,label:re,window:P})=>{const Ee=Math.max(0,Math.min(100,P.utilization)),oe=En(Ee),ce=typeof P.used=="number"&&typeof P.limit=="number"&&Number.isFinite(P.used)&&Number.isFinite(P.limit);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:re}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:oe},children:p("terminal:usage.percentUsed",{percent:Math.round(Ee)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${Ee}%`,background:oe}})}),e.jsxs("div",{className:"plan-limits-tooltip__reset",children:[p("terminal:usage.resets",{time:An(P.resetsAt)}),ce&&e.jsx("span",{style:{marginLeft:8},children:p("terminal:usage.creditsUsed",{used:sn(P.used),limit:sn(P.limit)})})]})]},H)})}):h&&!T&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:h.rateLimitsError?p("terminal:usage.limitsError",{message:h.rateLimitsError}):h.cliHint})]})}function La({agentId:c,disabled:r,contextSummary:p,children:h}){return e.jsx(Nn,{position:"top",maxWidth:320,disabled:r,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx(Ta,{agentId:c,contextSummary:p}),children:h})}const Pa=a.memo(function({className:r=""}){const{t:p}=Vt(["common"]),[h,k]=In(),T=a.useRef(null),[S,y]=a.useState(null);a.useLayoutEffect(()=>{const _=T.current;if(!_)return;const W=_.querySelector(".view-mode-toggle__btn--active");W&&y({left:W.offsetLeft,width:W.offsetWidth})},[h]);const Y=a.useCallback(_=>{if(_!==h){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:_}})),_==="3d"){requestAnimationFrame(()=>k(_));return}k(_)}},[h,k]);return e.jsxs("div",{className:`view-mode-toggle ${r}`,ref:T,children:[S&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:S.left,width:S.width}}),Mn.map(_=>e.jsxs("button",{className:`view-mode-toggle__btn ${h===_?"view-mode-toggle__btn--active":""}`,onClick:()=>Y(_),title:p(`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:p(`common:viewMode.labels.${_}`)})]},_))]})}),Nt=3,St=280,ln=320,Wt=240,rn=64,Ra=["simple","chat","advanced"],Da={simple:"Simple",chat:"Chat",advanced:"Advanced"},$a={simple:"○",chat:"◐",advanced:"◉"},za={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},on="flat-clear-context",bn="tide:flat-embedded-panels";function _n(){try{const c=localStorage.getItem(bn),r=c?JSON.parse(c):{};return r&&typeof r=="object"?r:{}}catch{return{}}}function Ht(c,r){try{const p=_n();r?p[c]=r:delete p[c],localStorage.setItem(bn,JSON.stringify(p))}catch{}}function Oa(c){const r=c.split("/").filter(Boolean);return r.length===0?c:r.slice(-2).join("/")}function Ba(c){if(c.provider==="codex"){const T=c.codexModel||"gpt-5.6-luna",S=Ca[T];return{model:(S==null?void 0:S.label)||T}}if(c.provider==="opencode")return{model:c.opencodeModel||"opencode"};if(c.provider==="grok"){const T=c.grokModel||"grok-4.5",S=c.effort,y=S?an[S]:void 0;return{model:T,effort:y==null?void 0:y.label}}const r=c.model||"sonnet",p=ka[r],h=c.effort,k=h?an[h]:void 0;return{model:(p==null?void 0:p.label)||r,effort:k==null?void 0:k.label}}function Fa(c,r){if(r.type==="rectangle"&&r.width&&r.height){const p=r.width/2,h=r.height/2;return c.x>=r.center.x-p&&c.x<=r.center.x+p&&c.z>=r.center.z-h&&c.z<=r.center.z+h}if(r.type==="circle"&&r.radius){const p=c.x-r.center.x,h=c.z-r.center.z;return p*p+h*h<=r.radius*r.radius}return!1}const Wa=Qn.memo(function({agentId:r,terminalViewMode:p,onTerminalViewModeChange:h,inspectorOpen:k,onToggleInspector:T,onShowTaskBoard:S,onImageClick:y,onFileClick:Y,onBashClick:_,onViewMarkdown:W,onRequestClearSubordinates:H,keyboard:re,canNavigateBack:P,canNavigateForward:Ee,onNavigateBack:oe,onNavigateForward:ce,agentInfoOpen:$e,onToggleAgentInfo:ot,onHeaderContextMenu:xe,onBuildingContextMenu:be}){var st,_t;const m=nn(r),O=mn(),Ie=ea(),ze=a.useRef(null),We=a.useRef(null),{displayedAgentId:Me,fadingOut:At}=ta(r),ct=nn(Me),He=!!Ie.interactiveMode&&((m==null?void 0:m.provider)??"claude")==="claude"&&!!(m!=null&&m.sessionId),[de,Ue]=a.useState(!1);a.useEffect(()=>{Ue(!1)},[r]),a.useEffect(()=>{!He&&de&&Ue(!1)},[He,de]),a.useEffect(()=>{const n=We.current;if(!n)return;const o=d=>{d.button===3?(d.preventDefault(),d.stopPropagation(),oe()):d.button===4&&(d.preventDefault(),d.stopPropagation(),ce())},i=d=>{(d.button===3||d.button===4)&&d.preventDefault()};return n.addEventListener("mouseup",o),n.addEventListener("mousedown",i),()=>{n.removeEventListener("mouseup",o),n.removeEventListener("mousedown",i)}},[oe,ce]),a.useEffect(()=>{const n=We.current;if(!n)return;let o=0,i=0,d=0;const z=250,le=600,R=80,De=1.5,Ze=D=>{let U=D instanceof HTMLElement?D:null;for(;U&&U!==n;){const vt=window.getComputedStyle(U).overflowX;if((vt==="auto"||vt==="scroll")&&U.scrollWidth>U.clientWidth)return!0;U=U.parentElement}return!1},wt=D=>{const U=Date.now();if(U<d){D.preventDefault();return}if(Math.abs(D.deltaX)<=Math.abs(D.deltaY)*De){o=0;return}if(Ze(D.target)){o=0;return}U-i>z&&(o=0),i=U,o+=D.deltaX,o<=-R?(o=0,d=U+le,D.preventDefault(),oe()):o>=R&&(o=0,d=U+le,D.preventDefault(),ce())};return n.addEventListener("wheel",wt,{passive:!1}),()=>n.removeEventListener("wheel",wt)},[oe,ce]);const Te=pn(),ue=a.useMemo(()=>{if(!m)return null;const n=new Set,o=[];for(const i of Te.values())i.archived||i.directories.length===0||i.assignedAgentIds.includes(r)&&(n.add(i.id),o.push(i));for(const i of Te.values())i.archived||i.directories.length===0||n.has(i.id)||Fa({x:m.position.x,z:m.position.z},i)&&(n.add(i.id),o.push(i));return o.length===0?null:o.flatMap(i=>i.directories.filter(d=>d&&d.trim().length>0).map(d=>({areaId:i.id,areaName:i.name,dir:d})))},[m,r,Te]),{branches:_e,fetchRemote:we,fetchingDirs:dt}=na(ue),Ve=a.useMemo(()=>{var i;const n=g.getAreaForAgent(r);if(!n)return[];const o=[];for(const d of O.values())d.type==="terminal"&&g.isPositionInArea(d.position,n)&&o.push({id:d.id,name:d.name,hasUrl:!!((i=d.terminalStatus)!=null&&i.url)});return o},[r,O]),ve=a.useMemo(()=>{var i;const n=g.getAreaForAgent(r);if(!n)return[];const o=[];for(const d of O.values())d.type==="server"&&((i=d.pm2)!=null&&i.enabled)&&g.isPositionInArea(d.position,n)&&o.push({id:d.id,name:d.name});return o},[r,O]),pe=a.useMemo(()=>{const n=g.getAreaForAgent(r);if(!n)return[];const o=[];for(const i of O.values())i.type==="database"&&i.database&&g.isPositionInArea(i.position,n)&&o.push({id:i.id,name:i.name});return o},[r,O]),Le=aa(),je=a.useMemo(()=>{const n=g.getAreaForAgent(r);if(!n)return[];const o=[];for(const i of O.values())if(i.type==="tests"&&g.isPositionInArea(i.position,n)){const d=!!i.folderPath&&Le.some(z=>sa(z,i.folderPath));o.push({id:i.id,name:i.name,working:d})}return o},[r,O,Le]),K=a.useMemo(()=>{const n=g.getAreaForAgent(r);if(!n)return[];const o=[];for(const i of O.values())i.type==="http"&&g.isPositionInArea(i.position,n)&&o.push({id:i.id,name:i.name});return o},[r,O]),[,Xe]=a.useReducer(n=>n+1,0),te=((st=ze.current)==null?void 0:st.search.searchMode)??!1,Pe=a.useCallback(()=>{var n;(n=ze.current)==null||n.search.toggleSearch(),Xe()},[]),ut=ia(),Qe=ut.isPending(on),[j,ne]=a.useState(null),Z=j?O.get(j.buildingId):null,[pt,Q]=a.useState(""),[et,Ge]=a.useState(()=>la()),B=a.useMemo(()=>{var n;return((n=g.getAreaForAgent(r))==null?void 0:n.id)??null},[r,O]),Ce=a.useCallback((n,o)=>{Q(""),ne(i=>{const d=(i==null?void 0:i.buildingId)===o?null:{type:n,buildingId:o};return B&&Ht(B,d),d})},[B]),ke=a.useCallback(()=>{Q(""),ne(null),B&&Ht(B,null)},[B]);a.useEffect(()=>{if((j==null?void 0:j.type)!=="pm2-logs")return;const n=j.buildingId;return g.startLogStreaming(n,200),()=>g.stopLogStreaming(n)},[j]);const{height:Et,onResizeStart:It}=ra(),{sidePanelWidth:Mt,handleSidePanelResizeStart:Tt}=oa(),[Oe,mt]=a.useState(()=>Ut(A.GIT_PANEL_OPEN,!1)),[ye,w]=a.useState(()=>Ut(A.BUILDINGS_PANEL_OPEN,!1)),[Be,ft]=a.useState(!1),Ne=a.useCallback(()=>{ft(n=>{const o=!n;return o&&ca.setEnabled(!0),o})},[]),ae=a.useCallback(()=>ft(!1),[]),qe=a.useCallback(()=>{mt(n=>{const o=!n;return ge(A.GIT_PANEL_OPEN,o),o})},[]),ht=a.useCallback(()=>{w(n=>{const o=!n;return ge(A.BUILDINGS_PANEL_OPEN,o),o})},[]),Lt=a.useCallback(()=>{mt(!1),ge(A.GIT_PANEL_OPEN,!1)},[]),Pt=a.useCallback(()=>{w(!1),ge(A.BUILDINGS_PANEL_OPEN,!1)},[]),Rt=da(),Re=a.useMemo(()=>({terminal:Ve,"pm2-logs":ve,database:pe,tests:je,http:K}),[Ve,ve,pe,je,K]);a.useEffect(()=>{if(!j)return;Re[j.type].some(o=>o.id===j.buildingId)||(Q(""),ne(null))},[j,Re]);const Ye=a.useRef(void 0);a.useEffect(()=>{var o;if(Ye.current===B)return;Ye.current=B;const n=B?_n()[B]:void 0;Q(""),n&&((o=Re[n.type])!=null&&o.some(i=>i.id===n.buildingId))?ne(n):ne(null)},[B,Re]),a.useEffect(()=>{const n=o=>{var z;const i=o.detail;if(!(i!=null&&i.buildingId)||!(i!=null&&i.type)||!((z=Re[i.type])!=null&&z.some(le=>le.id===i.buildingId)))return;i.handled=!0,Q("");const d={type:i.type,buildingId:i.buildingId};ne(d),B&&Ht(B,d)};return window.addEventListener("tide:dock-building-flat",n),()=>window.removeEventListener("tide:dock-building-flat",n)},[Re,B]);const[se,me]=a.useState(!1),fe=a.useRef(null);if(a.useEffect(()=>{if(!se)return;const n=o=>{fe.current&&!fe.current.contains(o.target)&&me(!1)};return document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[se]),!m)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 Se=m.contextStats,J=!!Se,Ae=Se?Se.totalTokens:m.contextUsed||0,gt=Se?Se.contextWindow:m.contextLimit||(m.provider==="grok"?5e5:2e5),Dt=Se?Se.usedPercent:Math.round(Ae/gt*100),he=Math.max(0,Math.min(100,Dt)),tt=Math.round(he*10)/10,$t=Math.round((100-he)*10)/10,xt=he>=80?"#ff4a4a":he>=60?"#ff9e4a":he>=40?"#ffd700":"#4aff9e",nt=(Ae/1e3).toFixed(1),ee=(gt/1e3).toFixed(1),ie=m.cwd,at=ie?Oa(ie):null,Ke=((_t=m.subordinateIds)==null?void 0:_t.length)||0,bt=Ke>0;return e.jsxs("div",{ref:We,className:`flat-terminal-wrapper ${Oe||ye||Be?"flat-terminal-wrapper--with-side-panel":""} ${At?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${Mt}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${$e?"flat-terminal-wrapper__header-main--active":""}`,onClick:ot,onContextMenu:n=>{n.preventDefault(),n.stopPropagation(),xe({x:n.clientX,y:n.clientY})},title:$e?"Hide agent info":"Show agent info","aria-pressed":$e,children:[e.jsx("span",{className:`flat-terminal-wrapper__header-avatar${m.status==="working"?" is-working":""}`,children:e.jsx(fn,{agent:m,size:28})}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:m.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:xn(m.status)},children:m.status})]}),m.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:m.taskLabel,children:["📋 ",m.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:gn(m.provider,"/"),alt:m.provider,className:"flat-terminal-wrapper__header-provider-icon",title:hn(m.provider)}),(()=>{const{model:n,effort:o}=Ba(m);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:o?`Model: ${n} · Effort: ${o}`:`Model: ${n}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:n}),o&&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:o})]})]})})()]})]}),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:[Ra.map(n=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!de&&p===n?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Ue(!1),h(n)},title:za[n],"aria-pressed":!de&&p===n,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:$a[n]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Da[n]})]},n)),He&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${de?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Ue(n=>!n),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":de,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:e.jsx(f,{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:oe,disabled:!P,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(f,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:ce,disabled:!Ee,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(f,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${te?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Pe,title:te?"Close search":"Search messages","aria-pressed":te,children:e.jsx(f,{name:te?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Qe?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>ut.handleClick(on,()=>{var n;g.clearContext(r),(n=ze.current)==null||n.historyLoader.clearHistory()}),title:Qe?"Click again to confirm clear context":"Clear context",children:e.jsx(f,{name:Qe?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Oe?"flat-terminal-wrapper__action-btn--active":""}`,onClick:qe,title:Oe?"Hide git panel":"Show git changes","aria-pressed":Oe,children:e.jsx(f,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ye?"flat-terminal-wrapper__action-btn--active":""}`,onClick:ht,title:ye?"Hide buildings panel":"Show area buildings","aria-pressed":ye,children:e.jsx(f,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:fe,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 ${Be?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Ne(),me(!1)},title:Be?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(f,{name:"bug",size:14}),e.jsx("span",{children:Be?"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:()=>{g.collapseContext(r),me(!1)},disabled:m.status!=="idle",title:m.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(f,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),bt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{H(r,Ke),me(!1)},children:[e.jsx(f,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",Ke," subordinate",Ke===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:()=>{g.killAgent(r),me(!1)},children:[e.jsx(f,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${k?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:T,title:k?"Hide inspector panel":"Show inspector panel","aria-label":k?"Hide inspector panel":"Show inspector panel","aria-pressed":k,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:()=>g.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(f,{name:"cross",size:14})})]})]}),e.jsx(ua,{agent:m,onClick:S}),de&&He?e.jsx(Ea,{agentId:r}):Me&&ct?e.jsx(pa,{ref:ze,agentId:Me,agent:ct,viewMode:p,isOpen:!0,onImageClick:y,onFileClick:Y,onBashClick:_,onViewMarkdown:W,keyboard:re,hasModalOpen:!1},Me):null,j&&Z&&(()=>{var z,le;const n=j.type,o={terminal:"terminal","pm2-logs":"scroll",database:"hard-drives",tests:"flask",http:"globe"},i=n==="terminal"&&!((z=Z.terminalStatus)!=null&&z.url),d=!i;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:It,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded panel"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`${Z.name} panel`,style:{height:Et},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(f,{name:o[n],size:12}),e.jsx("span",{children:Z.name}),i&&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:pt,onChange:R=>Q(R.target.value),placeholder:"Filter logs","aria-label":`Filter logs for ${Z.name}`,spellCheck:!1}),e.jsx("select",{className:"guake-bottom-terminal-retention",value:et===null?"unlimited":String(et),onChange:R=>{const De=R.target.value==="unlimited"?null:Number(R.target.value);Ge(De),fa(De)},"aria-label":`Max log retention for ${Z.name}`,children:ma.map(R=>e.jsx("option",{value:R===null?"unlimited":String(R),children:R===null?"Unlimited":`${R.toLocaleString()} lines`},R===null?"unlimited":R))}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>g.clearStreamingLogs(j.buildingId),title:"Clear logs",children:e.jsx(f,{name:"trash",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>g.sendBuildingCommand(j.buildingId,"restart"),title:"Restart",children:e.jsx(f,{name:"restart",size:12})})]}),d&&e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>{ke(),Je(j.buildingId)},title:"Maximize — open as modal","aria-label":"Open as modal",children:e.jsx(f,{name:"fullscreen",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:ke,title:"Close panel","aria-label":"Close panel",children:e.jsx(f,{name:"cross",size:12})})]})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:n==="terminal"?(le=Z.terminalStatus)!=null&&le.url?e.jsx(un,{terminalUrl:Z.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."}):n==="pm2-logs"?e.jsx(ha,{buildingId:j.buildingId,filterText:pt,maxRetention:et}):n==="database"?e.jsx(ga,{building:Z}):n==="tests"?e.jsx("div",{className:"tests-panel-host",children:e.jsx(xa,{building:Z,autoFocusSearch:!1})}):e.jsx("div",{className:"http-requests-panel-host",children:e.jsx(ba,{building:Z,autoFocusSearch:!1})})})]})]})})(),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[m.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(f,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),ie&&at&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${ie}`,"aria-label":`Open ${ie} in file explorer`,role:"button",tabIndex:0,onClick:()=>g.openFileExplorer(ie),onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),g.openFileExplorer(ie))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(f,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:at})]}),ue&&ue.map(({areaId:n,areaName:o,dir:i})=>{const d=_e.get(i),z=dt.has(i),le=i.split("/").filter(Boolean).pop()||i;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${o}: ${i}${d?` (${d.branch}${d.ahead?` ↑${d.ahead}`:""}${d.behind?` ↓${d.behind}`:""})`:""}`,onClick:()=>g.openFileExplorerForAreaFolder(n,i),children:[e.jsx(f,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:le}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(f,{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(f,{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(f,{name:"arrow-down",size:9}),d.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${z?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:R=>{R.stopPropagation(),we(i)},children:e.jsx(f,{name:z?"hourglass":"download",size:12})})]})]},`${n}:${i}`)}),e.jsx(La,{agentId:r,disabled:((m==null?void 0:m.provider)??"claude")!=="claude"&&((m==null?void 0:m.provider)??"claude")!=="grok",contextSummary:J?`Context: ${nt}k / ${ee}k tokens (${tt}% used)`:void 0,children:e.jsxs("span",{className:"flat-terminal-wrapper__context",tabIndex:0,role:"button",onClick:()=>g.setContextModalAgentId(r),onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),g.setContextModalAgentId(r))},title:((m==null?void 0:m.provider)??"claude")!=="claude"&&((m==null?void 0:m.provider)??"claude")!=="grok"?J?`Context usage: ${nt}k / ${ee}k tokens (${tt}% 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(f,{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:`${he}%`,backgroundColor:xt}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:xt},children:[nt,"k/",ee,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",$t,"% free)"]}),!J&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(f,{name:"warn",size:12})})]})}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),Ve.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:Ve.map(n=>{const o=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""} ${n.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${o?"Hide":"Show"} terminal: ${n.name}${n.hasUrl?"":" (starting...)"}`,onClick:()=>{if(o){ke();return}if(n.hasUrl&<(n.id)==="modal"){Je(n.id);return}n.hasUrl||g.sendBuildingCommand(n.id,"start"),Ce("terminal",n.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),be(n.id,{x:i.clientX,y:i.clientY})},children:e.jsx(f,{name:"terminal",size:14})},n.id)})}),ve.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:ve.map(n=>{const o=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} logs: ${n.name}`,onClick:()=>{o?ke():lt(n.id)==="modal"?Je(n.id):Ce("pm2-logs",n.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),be(n.id,{x:i.clientX,y:i.clientY})},children:e.jsx(f,{name:"scroll",size:14})},n.id)})}),pe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:pe.map(n=>{const o=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} database: ${n.name}`,onClick:()=>{o?ke():lt(n.id)==="modal"?Je(n.id):Ce("database",n.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),be(n.id,{x:i.clientX,y:i.clientY})},children:e.jsx(f,{name:"hard-drives",size:14})},n.id)})}),je.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:je.map(n=>{const o=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""} ${n.working?"flat-terminal-wrapper__building-btn--tests-working":""}`,title:n.working?`Running tests: ${n.name}`:`${o?"Hide":"Show"} tests: ${n.name}`,onClick:()=>{o?ke():lt(n.id)==="modal"?Je(n.id):Ce("tests",n.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),be(n.id,{x:i.clientX,y:i.clientY})},children:e.jsx(f,{name:"flask",size:14})},n.id)})}),K.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area HTTP requests",children:K.map(n=>{const o=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} HTTP requests: ${n.name}`,onClick:()=>{o?ke():lt(n.id)==="modal"?Je(n.id):Ce("http",n.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),be(n.id,{x:i.clientX,y:i.clientY})},children:e.jsx(f,{name:"globe",size:14})},n.id)})}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(_a,{})})]}),Oe&&e.jsx(wa,{agentId:r,agents:Rt,onClose:Lt,branchInfoMap:_e,fetchRemote:we,fetchingDirs:dt,onResizeStart:n=>Tt(n,"right")}),ye&&e.jsx(va,{agentId:r,onClose:Pt}),Be&&e.jsx(ja,{agentId:r,onClose:ae})]})}),Ha={groups:[],gridCols:1,gridRows:1,positions:new Map};function qa({onAgentClick:c,onBuildingClick:r,onBuildingDoubleClick:p,onBuildingPopup:h,onAreaContextMenu:k,onOpenSpawnModal:T,onOpenBossSpawnModal:S,onOpenAreaModal:y}){const{t:Y}=Vt(["common"]),_=Tn(),W=Ln(),[H,re]=a.useState(null),[P,Ee]=a.useState(null),[oe,ce]=a.useState(null);Pn("flatview-image-modal",H!==null,()=>re(null));const[$e,ot]=a.useState(null),[xe,be]=a.useState(null),[m,O]=a.useState(null),[Ie,ze]=a.useState(null),[We,Me]=a.useState(!1),At=a.useCallback(()=>{Me(t=>!t)},[]),ct=a.useCallback(()=>{Me(!1)},[]),[He,de]=a.useState(()=>{const t=Kt(A.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ue=a.useCallback(t=>{de(t),Zt(A.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=s=>{if(s.key!==A.VIEW_MODE)return;const l=s.newValue;(l==="simple"||l==="chat"||l==="advanced")&&de(l)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[Te,ue]=a.useState(()=>Ut(A.FLAT_INSPECTOR_OPEN,!1)),[_e,we]=a.useState(!1),dt=a.useCallback(()=>we(t=>!t),[]),Ve=a.useCallback(()=>we(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:_e}}))},[_e]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:Te}}))},[Te]),a.useEffect(()=>{const t=()=>we(C=>!C),s=()=>{ue(C=>{const E=!C;return ge(A.FLAT_INSPECTOR_OPEN,E),E})},l=()=>{we(!1),ue(!1),ge(A.FLAT_INSPECTOR_OPEN,!1)},x=()=>we(!1),b=()=>{ue(!1),ge(A.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",l),window.addEventListener("tide-close-flat-agents-drawer-only",x),window.addEventListener("tide-close-flat-inspector-only",b),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",s),window.removeEventListener("tide-close-flat-side-views",l),window.removeEventListener("tide-close-flat-agents-drawer-only",x),window.removeEventListener("tide-close-flat-inspector-only",b)}},[]);const ve=a.useRef(null),pe=a.useRef(null),[Le,je]=a.useState(()=>{const t=Jt(A.FLAT_MIDDLE_WIDTH,0);return t>=St?t:null}),[K,Xe]=a.useState(()=>{const t=Jt(A.FLAT_INSPECTOR_WIDTH,0);return t>=Wt?t:null}),te=a.useCallback(t=>{if(typeof window>"u")return t;const s=K!==null?Nt+K:0,l=window.innerWidth-rn-Nt-ln-s;return Math.max(St,Math.min(Math.max(l,St),t))},[K]),Pe=a.useCallback(t=>{var b;if(typeof window>"u")return t;const s=(b=ve.current)==null?void 0:b.querySelector(".flat-middle"),l=(s==null?void 0:s.getBoundingClientRect().width)??St,x=window.innerWidth-rn-l-Nt-ln-Nt;return Math.max(Wt,Math.min(Math.max(x,Wt),t))},[]);a.useEffect(()=>{if(Le===null&&K===null)return;const t=()=>{je(s=>{if(s===null)return s;const l=te(s);return l===s?s:l}),Xe(s=>{if(s===null)return s;const l=Pe(s);return l===s?s:l})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[Le,K,te,Pe]);const ut=a.useCallback(t=>{var l;if(t.button!==0)return;const s=(l=ve.current)==null?void 0:l.querySelector(".flat-middle");s&&(t.currentTarget.setPointerCapture(t.pointerId),pe.current={kind:"middle",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Qe=a.useCallback(t=>{var l;if(t.button!==0)return;const s=(l=ve.current)==null?void 0:l.querySelector(".flat-inspector");s&&(t.currentTarget.setPointerCapture(t.pointerId),pe.current={kind:"inspector",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),j=a.useCallback(t=>{const s=pe.current;if(!s||t.pointerId!==s.pointerId)return;const l=t.clientX-s.startX;s.kind==="middle"?je(te(s.startWidth+l)):Xe(Pe(s.startWidth-l))},[te,Pe]),ne=a.useCallback(t=>{const s=pe.current;if(!s||t.pointerId!==s.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(pe.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-s.startX)>2))return;const x=t.clientX-s.startX;if(s.kind==="middle"){const b=te(s.startWidth+x);je(b),yt(A.FLAT_MIDDLE_WIDTH,b)}else{const b=Pe(s.startWidth-x);Xe(b),yt(A.FLAT_INSPECTOR_WIDTH,b)}},[te,Pe]),Z=a.useCallback(()=>{je(null),yt(A.FLAT_MIDDLE_WIDTH,0)},[]),pt=a.useCallback(()=>{Xe(null),yt(A.FLAT_INSPECTOR_WIDTH,0)},[]),[Q,et]=a.useState(()=>Kt(A.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Ge=a.useCallback(t=>{et(t),Zt(A.FLAT_INSPECTOR_VIEW,t)},[]),B=a.useCallback(()=>{ue(t=>{const s=!t;return ge(A.FLAT_INSPECTOR_OPEN,s),s})},[]),Ce=a.useCallback(()=>{ue(!1),ge(A.FLAT_INSPECTOR_OPEN,!1)},[]),ke=a.useCallback(()=>{Ge("tracking"),ue(!0),ge(A.FLAT_INSPECTOR_OPEN,!0)},[Ge]),Et=Rn(),It=a.useCallback((t,s)=>{re({url:t,name:s})},[]),Mt=a.useCallback((t,s)=>{Ee({command:t,output:s,isLive:!1})},[]),Tt=a.useCallback((t,s)=>{var b;const l=W.size>0?Array.from(W)[0]:null,x=l?(b=g.getState().agents.get(l))==null?void 0:b.cwd:void 0;g.setFileViewerPath(t,s,x)},[W]),Oe=a.useCallback(t=>{ce(t)},[]),mt=a.useCallback((t,s)=>{ot({agentId:t,count:s})},[]),ye=a.useCallback(t=>{p?p(t):r(t)},[r,p]),w=a.useMemo(()=>W.size>0?Array.from(W)[0]:null,[W]),Be=a.useCallback(t=>{w&&be({agentId:w,position:t})},[w]),ft=a.useCallback((t,s)=>{O({buildingId:t,position:s})},[]);a.useEffect(()=>{Me(!1)},[w]);const Ne=a.useRef([]),ae=a.useRef(-1),qe=a.useRef(!1),ht=a.useRef(null),[Lt,Pt]=a.useState(!1),[Rt,Re]=a.useState(!1),Ye=a.useRef(!1),se=a.useRef(null),me=a.useRef(!1),fe=a.useMemo(()=>new Set(_.map(t=>t.id)),[_]),Se=a.useMemo(()=>{const t=new Map(_.map(l=>[l.id,l])),s=new Map;for(const l of _)if((l.isBoss||l.class==="boss")&&l.subordinateIds&&l.subordinateIds.length>0){const x=l.subordinateIds.map(b=>t.get(b)).filter(b=>b!==void 0);x.length>0&&s.set(l.id,x)}return s},[_]),J=a.useCallback(()=>{const t=Ne.current,s=ae.current;Pt(s>0),Re(s>=0&&s<t.length-1)},[]),Ae=a.useCallback(t=>{const s=Ne.current;if(s.length===0)return;let l=ae.current+t;for(;l>=0&&l<s.length;){const x=s[l];if(fe.has(x)){qe.current=!0,ae.current=l,J(),g.selectAgent(x);return}l+=t}},[fe,J]),gt=a.useCallback(()=>Ae(-1),[Ae]),Dt=a.useCallback(()=>Ae(1),[Ae]);Na(a.useCallback(()=>{const t=Ne.current,s=ae.current;return t.length>0&&s>0?(Ae(-1),"handled"):"exit"},[Ae]));const he=a.useCallback((t,s)=>{if(typeof window>"u")return;const l=window.history.state,b={...typeof l=="object"&&l!==null?l:{},__flatAgentNav:{agentId:t}};s==="replace"?window.history.replaceState(b,"",window.location.href):window.history.pushState(b,"",window.location.href)},[]);a.useEffect(()=>{if(!w){Ye.current=!1,se.current=null;return}if(!Ye.current){he(w,"replace"),Ye.current=!0,se.current=w;return}if(me.current){me.current=!1,se.current=w;return}se.current!==w&&(he(w,"push"),se.current=w)},[w,he]),a.useEffect(()=>{const t=s=>{var C,E;const l=(E=(C=s.state)==null?void 0:C.__flatAgentNav)==null?void 0:E.agentId;if(!l||typeof l!="string"||!fe.has(l)||l===w)return;me.current=!0,qe.current=!0;const x=Ne.current,b=x.lastIndexOf(l);b>=0?ae.current=b:(x.push(l),ae.current=x.length-1),J(),g.selectAgent(l)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[fe,w,J]),a.useEffect(()=>{if(!w){Ne.current=[],ae.current=-1,J();return}if(ht.current=w,qe.current){qe.current=!1,J();return}const t=Ne.current,s=ae.current;if(s>=0&&t[s]===w){J();return}const l=s<t.length-1?t.slice(0,s+1):t.slice();l.push(w),l.length>100&&l.shift(),Ne.current=l,ae.current=l.length-1,J()},[w,J]);const tt=a.useCallback(t=>{c(t),we(!1)},[c]),$t=w??"",xt=a.useCallback(()=>{},[]),nt=a.useCallback(t=>{tt(t)},[tt]),ee=Te,[ie,at]=a.useState(ee),[Ke,bt]=a.useState(ee);a.useEffect(()=>{if(ee){at(!0);return}bt(!1);const t=setTimeout(()=>at(!1),240);return()=>clearTimeout(t)},[ee]),a.useEffect(()=>{if(!ie||!ee)return;let t=0;const s=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>bt(!0))});return()=>{cancelAnimationFrame(s),cancelAnimationFrame(t)}},[ie,ee]);const st=a.useRef(null);a.useEffect(()=>{if(w)return;const t=s=>{if(s.key!==" "&&s.key!=="Backspace")return;const l=s.target;if(l.tagName==="INPUT"||l.tagName==="TEXTAREA"||l.isContentEditable)return;const x=ht.current;!x||!fe.has(x)||(s.preventDefault(),g.selectAgent(x))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[w,fe]);const[_t,n]=a.useState(new Set),o=a.useCallback(t=>{n(s=>{const l=new Set(s);return l.has(t)?l.delete(t):l.add(t),l})},[]),[i,d]=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=l=>d(l.matches);return t.addEventListener("change",s),()=>t.removeEventListener("change",s)},[]);const[z,le]=a.useState(null),R=a.useCallback(t=>{le(s=>s===t?null:t)},[]),De=pn(),Ze=mn(),[wt]=Dn(),D=a.useMemo(()=>{if(w)return Ha;const t=new Map,s=[];for(const v of _){const M=g.getAreaForAgent(v.id);if(!Qt((M==null?void 0:M.id)??null))continue;if(!M||M.archived){s.push(v);continue}const L=t.get(M.id);L?L.push(v):t.set(M.id,[v])}const l=new Map,x=[];for(const v of Ze.values()){let M=!1;for(const L of De.values())if(!L.archived&&en(L.id)&&g.isPositionInArea(v.position,L)){const X=l.get(L.id);X?X.push(v):l.set(L.id,[v]),M=!0;break}!M&&Qt(null)&&x.push(v)}const b=[];for(const[,v]of De){if(v.archived||!en(v.id))continue;const M=t.get(v.id),L=l.get(v.id)??[];(M&&M.length>0||L.length>0)&&b.push({area:v,agents:M??[],buildings:L})}(s.length>0||x.length>0)&&b.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:x});const C=b.filter(v=>v.area.id!=="__unassigned__"),E=b.filter(v=>v.area.id==="__unassigned__");let u=1,I=1;const V=new Map;if(C.length>1){let v=1/0,M=-1/0,L=1/0,X=-1/0;for(const G of C)v=Math.min(v,G.area.center.x),M=Math.max(M,G.area.center.x),L=Math.min(L,G.area.center.z),X=Math.max(X,G.area.center.z);const jt=M-v||1,Ct=X-L||1;if(C.length<=4){u=C.length,I=1;const G=[...C].sort((q,zt)=>q.area.center.x-zt.area.center.x);for(let q=0;q<G.length;q++)V.set(G[q].area.id,{row:1,col:q+1})}else{const G=[...C].sort((N,F)=>N.area.center.x-F.area.center.x),q=[];for(let N=1;N<G.length;N++)q.push(G[N].area.center.x-G[N-1].area.center.x);const zt=q.reduce((N,F)=>N+F,0)/q.length||1;let Xt=1;for(const N of q)N>zt*1.3&&Xt++;u=Math.max(2,Math.min(Xt,C.length));const Ot=[...C].sort((N,F)=>N.area.center.z-F.area.center.z),kt=[];for(let N=1;N<Ot.length;N++)kt.push(Ot[N].area.center.z-Ot[N-1].area.center.z);const vn=kt.reduce((N,F)=>N+F,0)/kt.length||1;let Gt=1;for(const N of kt)N>vn*1.3&&Gt++;I=Math.max(2,Math.min(Gt,C.length)),u=Math.max(u,Math.ceil(C.length/I)),I=Math.max(I,Math.ceil(C.length/u));const jn=jt/u,Cn=Ct/I,Bt=new Set;for(const N of C){let F=Math.min(u-1,Math.max(0,Math.floor((N.area.center.x-v)/jn))),Fe=Math.min(I-1,Math.max(0,Math.floor((N.area.center.z-L)/Cn))),it=`${Fe},${F}`,qt=0;const kn=I*u;for(;Bt.has(it)&&qt<kn;)F++,F>=u&&(F=0,Fe=(Fe+1)%I),it=`${Fe},${F}`,qt++;Bt.has(it)&&(Fe=I,F=0,it=`${Fe},${F}`,I++),Bt.add(it),V.set(N.area.id,{row:Fe+1,col:F+1})}}}const $=v=>{v.sort((M,L)=>{var jt,Ct,G,q;const X=(((jt=M.position)==null?void 0:jt.z)??0)-(((Ct=L.position)==null?void 0:Ct.z)??0);return X!==0?X:(((G=M.position)==null?void 0:G.x)??0)-(((q=L.position)==null?void 0:q.x)??0)})};for(const v of C)$(v.agents);for(const v of E)$(v.agents);return{groups:[...C,...E],gridCols:u,gridRows:I,positions:V}},[_,De,Ze,wt,w]),U=a.useMemo(()=>{if(!xe)return[];const t=_.find(s=>s.id===xe.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(f,{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(f,{name:"chat",size:14}),onClick:()=>c(t.id)},{id:"clone-agent",label:"Clone Agent",icon:e.jsx(f,{name:"clipboard",size:14}),onClick:()=>g.cloneAgent(t.id)},{id:"fork-agent",label:"Fork Agent (with history)",icon:e.jsx(f,{name:"git-branch",size:14}),onClick:()=>g.forkAgent(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(f,{name:"trash",size:14}),danger:!0,onClick:()=>{ze({agentId:t.id,name:t.name})}}]:[]},[xe,_,c]),vt=a.useMemo(()=>{var C;if(!m)return[];const t=Ze.get(m.buildingId);if(!t)return[];const s=[],l=t.type==="server"||t.type==="docker"||t.type==="terminal",x=t.status==="running",b=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(f,{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:()=>ye(t.id)}),l&&(x||s.push({id:"start",label:"Start",icon:e.jsx(f,{name:"play",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"start")}),x&&(s.push({id:"restart",label:"Restart",icon:e.jsx(f,{name:"refresh",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"restart")}),s.push({id:"stop",label:"Stop",icon:e.jsx(f,{name:"stop",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"stop")}))),b&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(s.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(f,{name:"launch",size:14}),onClick:()=>{for(const E of t.subordinateBuildingIds)g.sendBuildingCommand(E,"start")}}),s.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(f,{name:"pause",size:14}),onClick:()=>{for(const E of t.subordinateBuildingIds)g.sendBuildingCommand(E,"stop")}}),s.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(f,{name:"restart",size:14}),onClick:()=>{for(const E of t.subordinateBuildingIds)g.sendBuildingCommand(E,"restart")}})),l&&s.push({id:"health-check",label:"Health Check",icon:e.jsx(f,{name:"health",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"healthCheck")}),s.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),s.push({id:"edit",label:"Edit Building",icon:e.jsx(f,{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(f,{name:"copy",size:14}),onClick:()=>{g.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 E of t.urls)s.push({id:`url-${E.label}`,label:E.label,icon:e.jsx(f,{name:"link",size:14}),onClick:()=>window.open(E.url,"_blank","noopener,noreferrer")});return s.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),s.push({id:"delete",label:"Delete Building",icon:e.jsx(f,{name:"trash",size:14}),danger:!0,onClick:()=>g.deleteBuilding(t.id)}),s},[m,Ze,ye]),wn=a.useCallback(t=>{const s=new Set(D.groups.map(l=>l.area.id));s.delete(t),n(s),requestAnimationFrame(()=>{const l=st.current;if(!l)return;const x=l.querySelector(`[data-area-id="${t}"]`);if(!x)return;const b=l.getBoundingClientRect(),E=x.getBoundingClientRect().top-b.top+l.scrollTop-8;l.scrollTo({top:Math.max(0,E),behavior:"smooth"})})},[D]);return e.jsxs("div",{ref:ve,className:`flat-view ${ee?"flat-view--with-inspector":""} ${w?"flat-view--has-chat":""} ${_e?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(Le===null&&K===null)return;const t={};return Le!==null&&(t["--flat-middle-width"]=`${Le}px`),K!==null&&(t["--flat-inspector-width"]=`${K}px`),t})(),children:[_e&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Ve,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children:e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:T,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:S,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:y,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx($n,{activeAgentId:$t,onClose:xt,onSelectAgent:nt,collapsedAreas:_t,onToggleArea:o,agentListRef:st})})]}),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:ut,onPointerMove:j,onPointerUp:ne,onPointerCancel:ne,onDoubleClick:Z}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":_e?"Close agents sidebar":"Open agents sidebar","aria-expanded":_e,onClick:dt,children:[e.jsx(f,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),w?e.jsx(Wa,{agentId:w,terminalViewMode:He,onTerminalViewModeChange:Ue,inspectorOpen:Te,onToggleInspector:B,onShowTaskBoard:ke,onImageClick:It,onFileClick:Tt,onBashClick:Mt,onViewMarkdown:Oe,onRequestClearSubordinates:mt,keyboard:Et,canNavigateBack:Lt,canNavigateForward:Rt,onNavigateBack:gt,onNavigateForward:Dt,agentInfoOpen:We,onToggleAgentInfo:At,onHeaderContextMenu:Be,onBuildingContextMenu:ft}):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(Pa,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${D.gridCols}, 1fr)`},children:D.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var s;const t=i&&z?((s=D.positions.get(z))==null?void 0:s.row)??null:null;return D.groups.map(l=>{var E;const x=l.area.id,b=D.positions.get(x),C=i&&z!==x;return i&&t!=null&&(b==null?void 0:b.row)===t&&x!==z?null:e.jsxs("div",{className:`flat-map-area-card${C?" flat-map-area-card--collapsed":""}`,style:{"--area-color":l.area.color,gridRow:b==null?void 0:b.row,gridColumn:b==null?void 0:b.col},onContextMenu:u=>{k&&(u.preventDefault(),u.stopPropagation(),k(x,{x:u.clientX,y:u.clientY}))},children:[((E=l.area.logo)==null?void 0:E.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:ya(l.area.logo.filename),alt:"","aria-hidden":"true",onError:u=>{u.currentTarget.style.display="none"}}),e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>i?R(x):wn(x),title:i?C?`Expand ${l.area.name}`:`Collapse ${l.area.name}`:`Focus ${l.area.name} in left panel`,"aria-expanded":i?!C:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:l.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:l.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:l.agents.length}),i&&e.jsx(f,{name:C?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:l.agents.map(u=>{const I=u.isBoss||u.class==="boss",V=I?Se.get(u.id):void 0,$=zn(u),v=$.usedPercent>=80?"#ff4a4a":$.usedPercent>=60?"#ff9e4a":$.usedPercent>=40?"#ffd700":"#4aff9e",M=`Context: ${($.totalTokens/1e3).toFixed(1)}k / ${($.contextWindow/1e3).toFixed(1)}k (${$.usedPercent}% used, ${$.freePercent}% free)`,L=u.latestTodos&&u.latestTodos.length>0||V&&V.length>0;return e.jsx(On,{todos:u.latestTodos,subordinates:V,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${u.status}`,onClick:()=>c(u.id),onContextMenu:X=>{X.preventDefault(),X.stopPropagation(),be({agentId:u.id,position:{x:X.clientX,y:X.clientY}})},title:L?void 0:`${I?"Boss · ":""}Open chat with ${u.name}
|
|
2
2
|
${M}`,children:[e.jsx(fn,{agent:u,size:16}),I&&e.jsx("span",{className:"flat-map-agent-chip__crown","aria-hidden":"true",children:e.jsx(f,{name:"crown",size:11,color:"#ffd700",weight:"fill"})}),e.jsx("span",{className:"flat-map-agent-chip__name",children:u.name}),e.jsx("img",{src:gn(u.provider,"/"),alt:u.provider,className:"flat-map-agent-chip__provider-icon",title:hn(u.provider)}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:xn(u.status)}}),u.latestTodos&&u.latestTodos.length>0&&e.jsx(Bn,{todos:u.latestTodos,maxDots:6}),I&&V&&V.length>0&&e.jsx(Fn,{subordinates:V,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:`${$.usedPercent}%`,backgroundColor:v}})})]})},u.id)})}),l.area.directories.length>0&&e.jsx("div",{className:"flat-map-area-card__folders",role:"group","aria-label":`${l.area.name} folders`,children:l.area.directories.map(u=>{const I=u.split("/").filter(Boolean).pop()||u;return e.jsxs("button",{type:"button",className:"flat-map-folder-chip",onClick:V=>{V.stopPropagation(),g.openFileExplorerForAreaFolder(x,u)},title:`Open in file explorer: ${u}`,children:[e.jsx(f,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-map-folder-chip__name",children:I})]},u)})}),l.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:l.buildings.map(u=>{var V;const I=(V=Wn[u.type])==null?void 0:V.color;return e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${u.status}`,style:I?{"--building-type-color":I}:void 0,onClick:$=>{if(h){const v=$.currentTarget.getBoundingClientRect();h(u.id,{x:v.right,y:v.top+v.height/2})}else ye(u.id)},onContextMenu:$=>{$.preventDefault(),$.stopPropagation(),O({buildingId:u.id,position:{x:$.clientX,y:$.clientY}})},title:`${u.name} · ${u.type} · ${u.status}`,children:[e.jsx(f,{name:Hn(u.type),size:12,color:I}),e.jsx("span",{className:"flat-map-building-chip__name",children:u.name}),e.jsx("span",{className:"flat-map-building-chip__dot",style:{backgroundColor:Un(u.status)}})]},u.id)})})]},x)})})()})]})})]}),ee&&e.jsx("div",{className:"flat-splitter flat-splitter--inspector",role:"separator","aria-orientation":"vertical","aria-label":"Resize inspector panel",title:"Drag to resize · Double-click to reset",onPointerDown:Qe,onPointerMove:j,onPointerUp:ne,onPointerCancel:ne,onDoubleClick:pt}),ie&&e.jsxs("aside",{className:`flat-inspector ${Ke?"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":Q==="agent",className:`flat-inspector__tab ${Q==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>Ge("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":Q==="tracking",className:`flat-inspector__tab ${Q==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>Ge("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:Ce,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:Q==="tracking"?e.jsx(Vn,{activeAgentId:w??"",onSelectAgent:t=>{c(t),window.innerWidth<=768&&Ce()}}):(()=>{if(!w)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=_.find(s=>s.id===w);return t?e.jsx(Xn,{agent:t,onFocusAgent:s=>{c(s),window.innerWidth<=768&&Ce()},onKillAgent:s=>g.killAgent(s)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),H&&e.jsx(Gn,{url:H.url,name:H.name,onClose:()=>re(null)}),P&&e.jsx(qn,{state:P,onClose:()=>Ee(null)}),e.jsx(Yn,{agent:w?_.find(t=>t.id===w)??null:null,content:oe,onClose:()=>ce(null)}),$e&&e.jsx(Kn,{action:"clear-subordinates",selectedAgentId:$e.agentId,subordinateCount:$e.count,onClose:()=>ot(null),onClearHistory:()=>{}}),e.jsx(Zn,{agent:w?_.find(t=>t.id===w)??null:null,isOpen:We&&!!w,onClose:ct}),e.jsx(tn,{isOpen:xe!==null,position:(xe==null?void 0:xe.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:U,onClose:()=>be(null)}),e.jsx(tn,{isOpen:m!==null,position:(m==null?void 0:m.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:vt,onClose:()=>O(null)}),e.jsx(Jn,{isOpen:Ie!==null,title:Y("common:confirm.removeAgentTitle"),message:Y("common:confirm.removeAgentMessage",{name:(Ie==null?void 0:Ie.name)??""}),confirmLabel:Y("common:buttons.remove"),cancelLabel:Y("common:buttons.cancel"),variant:"danger",onConfirm:()=>{Ie&&g.removeAgentFromServer(Ie.agentId)},onClose:()=>ze(null)})]})}export{qa as FlatView};
|