tide-commander 1.155.0 → 1.156.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/dist/assets/{BossLogsModal-OFobifVq.js → BossLogsModal-CwkpdKon.js} +1 -1
  3. package/dist/assets/{BossSpawnModal-Dho-x6rm.js → BossSpawnModal-q2-ZjkYi.js} +1 -1
  4. package/dist/assets/{ControlsModal-DJBDhvNO.js → ControlsModal-CihuU69p.js} +1 -1
  5. package/dist/assets/{DockerLogsModal-C9TRTcsO.js → DockerLogsModal-BFHVU_1p.js} +1 -1
  6. package/dist/assets/{EmbeddedEditor-GDE_Khwz.js → EmbeddedEditor-DZ5bE7j_.js} +1 -1
  7. package/dist/assets/{GmailOAuthSetup-D9m5zMWC.js → GmailOAuthSetup-Dj_nP_GS.js} +1 -1
  8. package/dist/assets/{GoogleOAuthSetup-BxkN7LjY.js → GoogleOAuthSetup-CWs9nRX5.js} +1 -1
  9. package/dist/assets/{IframeModal-Do_I_wI7.js → IframeModal-CfItUAJ8.js} +1 -1
  10. package/dist/assets/{IntegrationsPanel-jRrwC2-G.js → IntegrationsPanel-BVjniF4n.js} +2 -2
  11. package/dist/assets/{LogViewerModal-BtcUe5i2.js → LogViewerModal-B7Jgt6ds.js} +1 -1
  12. package/dist/assets/{MonitoringModal-BTmSXrzv.js → MonitoringModal-CS8nfYl3.js} +1 -1
  13. package/dist/assets/{PM2LogsModal-CUf7NGHz.js → PM2LogsModal-DmToSbls.js} +1 -1
  14. package/dist/assets/{RestoreArchivedAreaModal-B72UKeRP.js → RestoreArchivedAreaModal-DD9YQJ47.js} +1 -1
  15. package/dist/assets/{Scene2DCanvas-BCfxX7JU.js → Scene2DCanvas-CxLa2T6K.js} +1 -1
  16. package/dist/assets/{SceneManager-BQubdlgd.js → SceneManager-gVDwrjJj.js} +1 -1
  17. package/dist/assets/{SkillsPanel-3qreMiJs.js → SkillsPanel-DMmqzmAb.js} +1 -1
  18. package/dist/assets/{SlackMultiInstanceSetup-BSCT5nAB.js → SlackMultiInstanceSetup-CvOqPr4x.js} +1 -1
  19. package/dist/assets/{SpawnModal-DaWjnugM.js → SpawnModal-DwpQZPIm.js} +1 -1
  20. package/dist/assets/{StatisticsModal-DCjCAU2o.js → StatisticsModal-DHwmDvMq.js} +1 -1
  21. package/dist/assets/{SubordinateAssignmentModal-9iPXraIi.js → SubordinateAssignmentModal-vJ3xMaqe.js} +1 -1
  22. package/dist/assets/{TriggerManagerPanel-B4dCLEi_.js → TriggerManagerPanel-B8iv-tyr.js} +1 -1
  23. package/dist/assets/{WorkflowEditorPanel-BaYXKfYH.js → WorkflowEditorPanel-CznY7cLk.js} +1 -1
  24. package/dist/assets/{area-logos-CgVT13bp.js → area-logos-CkHS76Vd.js} +1 -1
  25. package/dist/assets/{index-CetQ5OX1.js → index-B2XtMSw5.js} +1 -1
  26. package/dist/assets/{index-0y0WY2XK.js → index-BTvXV7CT.js} +1 -1
  27. package/dist/assets/index-BdDicCLy.js +2 -0
  28. package/dist/assets/{index-C3jAbuv2.js → index-CO38FP9S.js} +1 -1
  29. package/dist/assets/{index-C-tbJxGb.js → index-Ce90LqMC.js} +1 -1
  30. package/dist/assets/{index-DiZy3nuB.js → index-Cout14yl.js} +1 -1
  31. package/dist/assets/{index-C7t_6aP3.js → index-DpRKadlB.js} +2 -2
  32. package/dist/assets/{index-BPjQZacc.css → index-Ja-ujZ-0.css} +1 -1
  33. package/dist/assets/{index-DNjdlOwh.js → index-krziBkQk.js} +1 -1
  34. package/dist/assets/{index-D8dlRudN.js → index-oQI2DZbz.js} +3 -3
  35. package/dist/assets/{main-BHBs2E1L.css → main-C10O3GdP.css} +1 -1
  36. package/dist/assets/{main-DDwa0x9e.js → main-Du_kWg5E.js} +9 -9
  37. package/dist/assets/{web-EBdZk56y.js → web-C9cC59SM.js} +1 -1
  38. package/dist/assets/{web-PXjd4vZ8.js → web-DF-qnU6X.js} +1 -1
  39. package/dist/assets/{web-Dj2DYQG1.js → web-tQ-Hwgn-.js} +1 -1
  40. package/dist/build-info.json +1 -1
  41. package/dist/index.html +2 -2
  42. package/package.json +1 -1
  43. package/dist/assets/index-C3Yb-3TP.js +0 -2
@@ -0,0 +1,2 @@
1
+ import{r as a,H as yn,J as Zt,K as dn,L as un,j as e,M as mn,N as Sn,u as Gt,O as An,P as En,U as Mn,V as In,W as Tn,X as Ln,Y as Pn,Z as pn,_ as Jt,S as A,$ as Qt,a0 as Xt,a1 as en,a2 as yt,a3 as be,a4 as Rn,s as h,a5 as fn,m as hn,a6 as Dn,z as tn,B as nn,I as d,a7 as zn,q as $n,a8 as On,a9 as gn,aa as xn,ab as bn,ac as _n,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 an,C as Jn,aq as Qn,ar as sn,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 ma,aF as pa,aG as fa,aH as et,aI as ha,aJ as ga,aK as xa,aL as ba,aM as mt,aN as _a,aO as wa,aP as va,aQ as ja,aR as Ca,aS as ln,aT as ka}from"./main-Du_kWg5E.js";import{g as Na}from"./area-logos-CkHS76Vd.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function ya(c){const r=a.useRef(c);r.current=c,a.useEffect(()=>{if(!yn())return;let p=null,g=!1;return Zt.addListener("backButton",()=>{r.current()==="exit"&&Zt.exitApp()}).then(k=>{g?k.remove():p=k}),()=>{g=!0,p&&(p.remove(),p=null)}},[])}async function Sa(c){const r=dn(),p=await fetch(`${un()}/api/agents/${c}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${r}`}});if(!p.ok){const g=await p.json().catch(()=>({}));throw new Error((g==null?void 0:g.error)||`Failed to start terminal (${p.status})`)}return p.json()}async function Aa(c){const r=dn();await fetch(`${un()}/api/agents/${c}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${r}`}})}const pt=new Map;function Ea({agentId:c}){const[r,p]=a.useState(null),[g,k]=a.useState(null);return a.useEffect(()=>{let T=!1;const S=pt.get(c);return S&&(clearTimeout(S),pt.delete(c)),p(null),k(null),Sa(c).then(N=>{T||p(N.url)}).catch(N=>{T||k(N instanceof Error?N.message:"Failed to start terminal")}),()=>{T=!0;const N=pt.get(c);N&&clearTimeout(N),pt.set(c,setTimeout(()=>{pt.delete(c),Aa(c)},2500))}},[c]),g?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:g})}):r?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(mn,{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 Wt=new Map,Ma=6e4;function rn(c){return Number.isFinite(c)?Math.abs(c)>=1e3?c.toLocaleString(void 0,{maximumFractionDigits:0}):c.toLocaleString(void 0,{maximumFractionDigits:2}):String(c)}function Ia(c,r){var k,T,S;const p=[];if(!c.rateLimits)return p;if(c.provider==="claude"){const N=c,Z=[{key:"fiveHour",label:r("terminal:usage.currentSession"),window:N.rateLimits.fiveHour},{key:"sevenDay",label:r("terminal:usage.currentWeekAll"),window:N.rateLimits.sevenDay},{key:"sevenDayOpus",label:r("terminal:usage.currentWeekOpus"),window:N.rateLimits.sevenDayOpus},{key:"sevenDaySonnet",label:r("terminal:usage.currentWeekSonnet"),window:N.rateLimits.sevenDaySonnet}];for(const w of Z)w.window&&p.push({...w,window:w.window});return p}const g=c;return(k=g.rateLimits)!=null&&k.weekly&&p.push({key:"weekly",label:r("terminal:usage.weeklyLimit"),window:g.rateLimits.weekly}),(T=g.rateLimits)!=null&&T.monthly&&p.push({key:"monthly",label:r("terminal:usage.monthlyLimit"),window:g.rateLimits.monthly}),(S=g.rateLimits)!=null&&S.onDemand&&p.push({key:"onDemand",label:r("terminal:usage.onDemandLimit"),window:g.rateLimits.onDemand}),p}function Ta({agentId:c,contextSummary:r}){const{t:p}=Gt(["terminal","common"]),[g,k]=a.useState(()=>{var $;return(($=Wt.get(c))==null?void 0:$.snapshot)??null}),[T,S]=a.useState(!1),[N,Z]=a.useState(null),w=a.useRef(0);a.useEffect(()=>{const $=Wt.get(c);if($&&Date.now()-$.fetchedAt<Ma){k($.snapshot);return}const ie=++w.current;S(!0),Z(null),An(c).then(P=>{ie===w.current&&(Wt.set(c,{snapshot:P,fetchedAt:Date.now()}),k(P),S(!1))}).catch(P=>{ie===w.current&&(Z(P.message||"Failed to load plan limits"),S(!1))})},[c]);const V=g?Ia(g,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&&!g&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[p("common:status.loading"),"…"]}),!T&&N&&!g&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:p("terminal:usage.limitsError",{message:N})}),V.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:V.map(({key:$,label:ie,window:P})=>{const Se=Math.max(0,Math.min(100,P.utilization)),le=Mn(Se),re=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:ie}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:le},children:p("terminal:usage.percentUsed",{percent:Math.round(Se)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${Se}%`,background:le}})}),e.jsxs("div",{className:"plan-limits-tooltip__reset",children:[p("terminal:usage.resets",{time:En(P.resetsAt)}),re&&e.jsx("span",{style:{marginLeft:8},children:p("terminal:usage.creditsUsed",{used:rn(P.used),limit:rn(P.limit)})})]})]},$)})}):g&&!T&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:g.rateLimitsError?p("terminal:usage.limitsError",{message:g.rateLimitsError}):g.cliHint})]})}function La({agentId:c,disabled:r,contextSummary:p,children:g}){return e.jsx(Sn,{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:g})}const Pa=a.memo(function({className:r=""}){const{t:p}=Gt(["common"]),[g,k]=In(),T=a.useRef(null),[S,N]=a.useState(null);a.useLayoutEffect(()=>{const w=T.current;if(!w)return;const V=w.querySelector(".view-mode-toggle__btn--active");V&&N({left:V.offsetLeft,width:V.offsetWidth})},[g]);const Z=a.useCallback(w=>{if(w!==g){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:w}})),w==="3d"){requestAnimationFrame(()=>k(w));return}k(w)}},[g,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}}),Tn.map(w=>e.jsxs("button",{className:`view-mode-toggle__btn ${g===w?"view-mode-toggle__btn--active":""}`,onClick:()=>Z(w),title:p(`common:viewMode.descriptions.${w}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[w==="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"})]}),w==="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"})]}),w==="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"})]}),w==="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.${w}`)})]},w))]})}),St=3,At=280,on=320,Ht=240,cn=64,Ra=["simple","chat","advanced"],Da={simple:"Simple",chat:"Chat",advanced:"Advanced"},za={simple:"○",chat:"◐",advanced:"◉"},$a={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Ut="flat-clear-context",wn="tide:flat-embedded-panels";function vn(){try{const c=localStorage.getItem(wn),r=c?JSON.parse(c):{};return r&&typeof r=="object"?r:{}}catch{return{}}}function Vt(c,r){try{const p=vn();r?p[c]=r:delete p[c],localStorage.setItem(wn,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,N=S?ln[S]:void 0;return{model:T,effort:N==null?void 0:N.label}}const r=c.model||"sonnet",p=ka[r],g=c.effort,k=g?ln[g]: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,g=r.height/2;return c.x>=r.center.x-p&&c.x<=r.center.x+p&&c.z>=r.center.z-g&&c.z<=r.center.z+g}if(r.type==="circle"&&r.radius){const p=c.x-r.center.x,g=c.z-r.center.z;return p*p+g*g<=r.radius*r.radius}return!1}const Wa=Qn.memo(function({agentId:r,terminalViewMode:p,onTerminalViewModeChange:g,inspectorOpen:k,onToggleInspector:T,onShowTaskBoard:S,onImageClick:N,onFileClick:Z,onBashClick:w,onViewMarkdown:V,onRequestClearSubordinates:$,keyboard:ie,canNavigateBack:P,canNavigateForward:Se,onNavigateBack:le,onNavigateForward:re,agentInfoOpen:ze,onToggleAgentInfo:ft,onHeaderContextMenu:_e,onBuildingContextMenu:we}){var vt,xe;const f=sn(r),O=hn(),Ae=ea(),Ee=a.useRef(null),qe=a.useRef(null),{displayedAgentId:Me,fadingOut:Et}=ta(r),ht=sn(Me),Ye=!!Ae.interactiveMode&&((f==null?void 0:f.provider)??"claude")==="claude"&&!!(f!=null&&f.sessionId),[oe,Ke]=a.useState(!1),[$e,ce]=a.useState(!1),R=a.useCallback(()=>ce(!1),[]);pn("flat-chat-actions",$e,R),a.useEffect(()=>{const n=()=>ce(o=>!o);return window.addEventListener("tide:toggle-chat-actions",n),()=>window.removeEventListener("tide:toggle-chat-actions",n)},[]),a.useEffect(()=>{Ke(!1),ce(!1)},[r]),a.useEffect(()=>{!Ye&&oe&&Ke(!1)},[Ye,oe]),a.useEffect(()=>{const n=qe.current;if(!n)return;const o=u=>{u.button===3?(u.preventDefault(),u.stopPropagation(),le()):u.button===4&&(u.preventDefault(),u.stopPropagation(),re())},l=u=>{(u.button===3||u.button===4)&&u.preventDefault()};return n.addEventListener("mouseup",o),n.addEventListener("mousedown",l),()=>{n.removeEventListener("mouseup",o),n.removeEventListener("mousedown",l)}},[le,re]),a.useEffect(()=>{const n=qe.current;if(!n)return;let o=0,l=0,u=0;const H=250,G=600,D=80,te=1.5,$t=ne=>{let t=ne instanceof HTMLElement?ne:null;for(;t&&t!==n;){const s=window.getComputedStyle(t).overflowX;if((s==="auto"||s==="scroll")&&t.scrollWidth>t.clientWidth)return!0;t=t.parentElement}return!1},jt=ne=>{const t=Date.now();if(t<u){ne.preventDefault();return}if(Math.abs(ne.deltaX)<=Math.abs(ne.deltaY)*te){o=0;return}if($t(ne.target)){o=0;return}t-l>H&&(o=0),l=t,o+=ne.deltaX,o<=-D?(o=0,u=t+G,ne.preventDefault(),le()):o>=D&&(o=0,u=t+G,ne.preventDefault(),re())};return n.addEventListener("wheel",jt,{passive:!1}),()=>n.removeEventListener("wheel",jt)},[le,re]);const de=fn(),tt=a.useMemo(()=>{if(!f)return null;const n=new Set,o=[];for(const l of de.values())l.archived||l.directories.length===0||l.assignedAgentIds.includes(r)&&(n.add(l.id),o.push(l));for(const l of de.values())l.archived||l.directories.length===0||n.has(l.id)||Fa({x:f.position.x,z:f.position.z},l)&&(n.add(l.id),o.push(l));return o.length===0?null:o.flatMap(l=>l.directories.filter(u=>u&&u.trim().length>0).map(u=>({areaId:l.id,areaName:l.name,dir:u})))},[f,r,de]),{branches:gt,fetchRemote:Oe,fetchingDirs:Ie}=na(tt),ue=a.useMemo(()=>{var l;const n=h.getAreaForAgent(r);if(!n)return[];const o=[];for(const u of O.values())u.type==="terminal"&&h.isPositionInArea(u.position,n)&&o.push({id:u.id,name:u.name,hasUrl:!!((l=u.terminalStatus)!=null&&l.url)});return o},[r,O]),ve=a.useMemo(()=>{var l;const n=h.getAreaForAgent(r);if(!n)return[];const o=[];for(const u of O.values())u.type==="server"&&((l=u.pm2)!=null&&l.enabled)&&h.isPositionInArea(u.position,n)&&o.push({id:u.id,name:u.name});return o},[r,O]),J=a.useMemo(()=>{const n=h.getAreaForAgent(r);if(!n)return[];const o=[];for(const l of O.values())l.type==="database"&&l.database&&h.isPositionInArea(l.position,n)&&o.push({id:l.id,name:l.name});return o},[r,O]),Be=aa(),ae=a.useMemo(()=>{const n=h.getAreaForAgent(r);if(!n)return[];const o=[];for(const l of O.values())if(l.type==="tests"&&h.isPositionInArea(l.position,n)){const u=!!l.folderPath&&Be.some(H=>sa(H,l.folderPath));o.push({id:l.id,name:l.name,working:u})}return o},[r,O,Be]),se=a.useMemo(()=>{const n=h.getAreaForAgent(r);if(!n)return[];const o=[];for(const l of O.values())l.type==="http"&&h.isPositionInArea(l.position,n)&&o.push({id:l.id,name:l.name});return o},[r,O]),[,Mt]=a.useReducer(n=>n+1,0),je=((vt=Ee.current)==null?void 0:vt.search.searchMode)??!1,nt=a.useCallback(()=>{var n;(n=Ee.current)==null||n.search.toggleSearch(),Mt()},[]),Te=ia(),Le=Te.isPending(Ut),[j,ee]=a.useState(null),Q=j?O.get(j.buildingId):null,[Fe,Pe]=a.useState(""),[We,It]=a.useState(()=>la()),B=a.useMemo(()=>{var n;return((n=h.getAreaForAgent(r))==null?void 0:n.id)??null},[r,O]),He=a.useCallback((n,o)=>{Pe(""),ee(l=>{const u=(l==null?void 0:l.buildingId)===o?null:{type:n,buildingId:o};return B&&Vt(B,u),u})},[B]),Ce=a.useCallback(()=>{Pe(""),ee(null),B&&Vt(B,null)},[B]);a.useEffect(()=>{if((j==null?void 0:j.type)!=="pm2-logs")return;const n=j.buildingId;return h.startLogStreaming(n,200),()=>h.stopLogStreaming(n)},[j]);const{height:Tt,onResizeStart:Lt}=ra(),{sidePanelWidth:Pt,handleSidePanelResizeStart:at}=oa(),[_,xt]=a.useState(()=>Xt(A.GIT_PANEL_OPEN,!1)),[Re,me]=a.useState(()=>Xt(A.BUILDINGS_PANEL_OPEN,!1)),[F,Ue]=a.useState(!1),st=a.useCallback(()=>{Ue(n=>{const o=!n;return o&&ca.setEnabled(!0),o})},[]),Rt=a.useCallback(()=>Ue(!1),[]),bt=a.useCallback(()=>{xt(n=>{const o=!n;return be(A.GIT_PANEL_OPEN,o),o})},[]),_t=a.useCallback(()=>{me(n=>{const o=!n;return be(A.BUILDINGS_PANEL_OPEN,o),o})},[]),Dt=a.useCallback(()=>{xt(!1),be(A.GIT_PANEL_OPEN,!1)},[]),it=a.useCallback(()=>{me(!1),be(A.BUILDINGS_PANEL_OPEN,!1)},[]),Ve=da(),pe=a.useMemo(()=>({terminal:ue,"pm2-logs":ve,database:J,tests:ae,http:se}),[ue,ve,J,ae,se]);a.useEffect(()=>{if(!j)return;pe[j.type].some(o=>o.id===j.buildingId)||(Pe(""),ee(null))},[j,pe]);const ke=a.useRef(void 0);a.useEffect(()=>{var o;if(ke.current===B)return;ke.current=B;const n=B?vn()[B]:void 0;Pe(""),n&&((o=pe[n.type])!=null&&o.some(l=>l.id===n.buildingId))?ee(n):ee(null)},[B,pe]),a.useEffect(()=>{const n=o=>{var H;const l=o.detail;if(!(l!=null&&l.buildingId)||!(l!=null&&l.type)||!((H=pe[l.type])!=null&&H.some(G=>G.id===l.buildingId)))return;l.handled=!0,Pe("");const u={type:l.type,buildingId:l.buildingId};ee(u),B&&Vt(B,u)};return window.addEventListener("tide:dock-building-flat",n),()=>window.removeEventListener("tide:dock-building-flat",n)},[pe,B]);const[Xe,W]=a.useState(!1),fe=a.useRef(null);if(a.useEffect(()=>{if(!Xe)return;const n=o=>{fe.current&&!fe.current.contains(o.target)&&W(!1)};return document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[Xe]),!f)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const Ne=f.contextStats,lt=!!Ne,Ze=Ne?Ne.totalTokens:f.contextUsed||0,rt=Ne?Ne.contextWindow:f.contextLimit||(f.provider==="grok"?5e5:2e5),zt=Ne?Ne.usedPercent:Math.round(Ze/rt*100),De=Math.max(0,Math.min(100,zt)),wt=Math.round(De*10)/10,he=Math.round((100-De)*10)/10,Je=De>=80?"#ff4a4a":De>=60?"#ff9e4a":De>=40?"#ffd700":"#4aff9e",Qe=(Ze/1e3).toFixed(1),ot=(rt/1e3).toFixed(1),ge=f.cwd,ct=ge?Oa(ge):null,ye=((xe=f.subordinateIds)==null?void 0:xe.length)||0,dt=ye>0;return e.jsxs("div",{ref:qe,className:`flat-terminal-wrapper ${_||Re||F?"flat-terminal-wrapper--with-side-panel":""} ${Et?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${Pt}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${ze?"flat-terminal-wrapper__header-main--active":""}`,onClick:ft,onContextMenu:n=>{n.preventDefault(),n.stopPropagation(),_e({x:n.clientX,y:n.clientY})},title:ze?"Hide agent info":"Show agent info","aria-pressed":ze,children:[e.jsx("span",{className:`flat-terminal-wrapper__header-avatar${f.status==="working"?" is-working":""}`,children:e.jsx(gn,{agent:f,size:28})}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:f.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:_n(f.status)},children:f.status})]}),f.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:f.taskLabel,children:["📋 ",f.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:bn(f.provider,"/"),alt:f.provider,className:"flat-terminal-wrapper__header-provider-icon",title:xn(f.provider)}),(()=>{const{model:n,effort:o}=Ba(f);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 ${!oe&&p===n?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Ke(!1),g(n)},title:$a[n],"aria-pressed":!oe&&p===n,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:za[n]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Da[n]})]},n)),Ye&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${oe?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Ke(n=>!n),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":oe,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:e.jsx(d,{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:le,disabled:!P,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(d,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:re,disabled:!Se,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(d,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${je?"flat-terminal-wrapper__action-btn--active":""}`,onClick:nt,title:je?"Close search":"Search messages","aria-pressed":je,children:e.jsx(d,{name:je?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Le?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>Te.handleClick(Ut,()=>{var n;h.clearContext(r),(n=Ee.current)==null||n.historyLoader.clearHistory()}),title:Le?"Click again to confirm clear context":"Clear context",children:e.jsx(d,{name:Le?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${_?"flat-terminal-wrapper__action-btn--active":""}`,onClick:bt,title:_?"Hide git panel":"Show git changes","aria-pressed":_,children:e.jsx(d,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Re?"flat-terminal-wrapper__action-btn--active":""}`,onClick:_t,title:Re?"Hide buildings panel":"Show area buildings","aria-pressed":Re,children:e.jsx(d,{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 ${Xe?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>W(n=>!n),title:"More actions","aria-expanded":Xe,children:"⋮"}),Xe&&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 ${F?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{st(),W(!1)},title:F?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(d,{name:"bug",size:14}),e.jsx("span",{children:F?"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:()=>{h.collapseContext(r),W(!1)},disabled:f.status!=="idle",title:f.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(d,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),dt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{$(r,ye),W(!1)},children:[e.jsx(d,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",ye," subordinate",ye===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:()=>{h.killAgent(r),W(!1)},children:[e.jsx(d,{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:()=>h.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(d,{name:"cross",size:14})})]})]}),$e&&e.jsxs("div",{className:"flat-chat-actions-sheet-root",role:"presentation",children:[e.jsx("div",{className:"flat-chat-actions-sheet__backdrop",onClick:R}),e.jsxs("div",{className:"flat-chat-actions-sheet",role:"menu","aria-label":"Chat actions",children:[e.jsx("div",{className:"flat-chat-actions-sheet__grabber","aria-hidden":"true"}),e.jsxs("div",{className:"flat-chat-actions-sheet__title-row",children:[e.jsx("span",{className:"flat-chat-actions-sheet__title",children:f.name}),e.jsx("button",{type:"button",className:"flat-chat-actions-sheet__done",onClick:R,children:"Done"})]}),e.jsxs("div",{className:"flat-chat-actions-sheet__grid",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${je?"is-active":""}`,onClick:()=>{nt(),R()},children:[e.jsx(d,{name:je?"cross":"search",size:20}),e.jsx("span",{children:je?"Close search":"Search"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${_?"is-active":""}`,onClick:()=>{bt(),R()},children:[e.jsx(d,{name:"git-branch",size:20}),e.jsx("span",{children:"Git changes"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${Re?"is-active":""}`,onClick:()=>{_t(),R()},children:[e.jsx(d,{name:"buildings",size:20}),e.jsx("span",{children:"Buildings"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${F?"is-active":""}`,onClick:()=>{st(),R()},children:[e.jsx(d,{name:"bug",size:20}),e.jsx("span",{children:"Debug"})]})]}),e.jsxs("div",{className:"flat-chat-actions-sheet__list",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__row flat-chat-actions-sheet__row--danger ${Le?"is-armed":""}`,onClick:()=>Te.handleClick(Ut,()=>{var n;h.clearContext(r),(n=Ee.current)==null||n.historyLoader.clearHistory(),R()}),children:[e.jsx(d,{name:Le?"question":"clear",size:18}),e.jsx("span",{children:Le?"Tap again to confirm clear":"Clear context"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row",disabled:f.status!=="idle",onClick:()=>{h.collapseContext(r),R()},children:[e.jsx(d,{name:"package",size:18}),e.jsx("span",{children:"Collapse context"})]}),dt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row flat-chat-actions-sheet__row--danger",onClick:()=>{$(r,ye),R()},children:[e.jsx(d,{name:"crown",size:18}),e.jsxs("span",{children:["Clear ",ye," subordinate",ye===1?"":"s"]})]}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row flat-chat-actions-sheet__row--danger",onClick:()=>{h.killAgent(r),R()},children:[e.jsx(d,{name:"cross",size:18}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsx(ua,{agent:f,onClick:S}),oe&&Ye?e.jsx(Ea,{agentId:r}):Me&&ht?e.jsx(ma,{ref:Ee,agentId:Me,agent:ht,viewMode:p,isOpen:!0,onImageClick:N,onFileClick:Z,onBashClick:w,onViewMarkdown:V,keyboard:ie,hasModalOpen:!1},Me):null,j&&Q&&(()=>{var H,G;const n=j.type,o={terminal:"terminal","pm2-logs":"scroll",database:"hard-drives",tests:"flask",http:"globe"},l=n==="terminal"&&!((H=Q.terminalStatus)!=null&&H.url),u=!l;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:Lt,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded panel"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`${Q.name} panel`,style:{height:Tt},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(d,{name:o[n],size:12}),e.jsx("span",{children:Q.name}),l&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsxs("span",{className:"flat-bottom-panel__header-actions",children:[n==="pm2-logs"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",className:"guake-bottom-terminal-filter",value:Fe,onChange:D=>Pe(D.target.value),placeholder:"Filter logs","aria-label":`Filter logs for ${Q.name}`,spellCheck:!1}),e.jsx("select",{className:"guake-bottom-terminal-retention",value:We===null?"unlimited":String(We),onChange:D=>{const te=D.target.value==="unlimited"?null:Number(D.target.value);It(te),fa(te)},"aria-label":`Max log retention for ${Q.name}`,children:pa.map(D=>e.jsx("option",{value:D===null?"unlimited":String(D),children:D===null?"Unlimited":`${D.toLocaleString()} lines`},D===null?"unlimited":D))}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>h.clearStreamingLogs(j.buildingId),title:"Clear logs",children:e.jsx(d,{name:"trash",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>h.sendBuildingCommand(j.buildingId,"restart"),title:"Restart",children:e.jsx(d,{name:"restart",size:12})})]}),u&&e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>{Ce(),et(j.buildingId)},title:"Maximize — open as modal","aria-label":"Open as modal",children:e.jsx(d,{name:"fullscreen",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:Ce,title:"Close panel","aria-label":"Close panel",children:e.jsx(d,{name:"cross",size:12})})]})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:n==="terminal"?(G=Q.terminalStatus)!=null&&G.url?e.jsx(mn,{terminalUrl:Q.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:Fe,maxRetention:We}):n==="database"?e.jsx(ga,{building:Q}):n==="tests"?e.jsx("div",{className:"tests-panel-host",children:e.jsx(xa,{building:Q,autoFocusSearch:!1})}):e.jsx("div",{className:"http-requests-panel-host",children:e.jsx(ba,{building:Q,autoFocusSearch:!1})})})]})]})})(),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[f.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(d,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),ge&&ct&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${ge}`,"aria-label":`Open ${ge} in file explorer`,role:"button",tabIndex:0,onClick:()=>h.openFileExplorer(ge),onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),h.openFileExplorer(ge))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(d,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:ct})]}),tt&&tt.map(({areaId:n,areaName:o,dir:l})=>{const u=gt.get(l),H=Ie.has(l),G=l.split("/").filter(Boolean).pop()||l;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${o}: ${l}${u?` (${u.branch}${u.ahead?` ↑${u.ahead}`:""}${u.behind?` ↓${u.behind}`:""})`:""}`,onClick:()=>h.openFileExplorerForAreaFolder(n,l),children:[e.jsx(d,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:G}),u&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(d,{name:"git-branch",size:10})," ",u.branch]}),u.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${u.ahead} ahead`,children:[e.jsx(d,{name:"arrow-up",size:9}),u.ahead]}),u.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${u.behind} behind`,children:[e.jsx(d,{name:"arrow-down",size:9}),u.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${H?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:D=>{D.stopPropagation(),Oe(l)},children:e.jsx(d,{name:H?"hourglass":"download",size:12})})]})]},`${n}:${l}`)}),e.jsx(La,{agentId:r,disabled:((f==null?void 0:f.provider)??"claude")!=="claude"&&((f==null?void 0:f.provider)??"claude")!=="grok",contextSummary:lt?`Context: ${Qe}k / ${ot}k tokens (${wt}% used)`:void 0,children:e.jsxs("span",{className:"flat-terminal-wrapper__context",tabIndex:0,role:"button",onClick:()=>h.setContextModalAgentId(r),onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),h.setContextModalAgentId(r))},title:((f==null?void 0:f.provider)??"claude")!=="claude"&&((f==null?void 0:f.provider)??"claude")!=="grok"?lt?`Context usage: ${Qe}k / ${ot}k tokens (${wt}% 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(d,{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:`${De}%`,backgroundColor:Je}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:Je},children:[Qe,"k/",ot,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",he,"% free)"]}),!lt&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(d,{name:"warn",size:12})})]})}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),ue.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:ue.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){Ce();return}if(n.hasUrl&&mt(n.id)==="modal"){et(n.id);return}n.hasUrl||h.sendBuildingCommand(n.id,"start"),He("terminal",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),we(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(d,{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?Ce():mt(n.id)==="modal"?et(n.id):He("pm2-logs",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),we(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(d,{name:"scroll",size:14})},n.id)})}),J.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:J.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?Ce():mt(n.id)==="modal"?et(n.id):He("database",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),we(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(d,{name:"hard-drives",size:14})},n.id)})}),ae.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:ae.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?Ce():mt(n.id)==="modal"?et(n.id):He("tests",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),we(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(d,{name:"flask",size:14})},n.id)})}),se.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area HTTP requests",children:se.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?Ce():mt(n.id)==="modal"?et(n.id):He("http",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),we(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(d,{name:"globe",size:14})},n.id)})}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(_a,{})})]}),_&&e.jsx(wa,{agentId:r,agents:Ve,onClose:Dt,branchInfoMap:gt,fetchRemote:Oe,fetchingDirs:Ie,onResizeStart:n=>at(n,"right")}),Re&&e.jsx(va,{agentId:r,onClose:it}),F&&e.jsx(ja,{agentId:r,onClose:Rt})]})}),Ha={groups:[],gridCols:1,gridRows:1,positions:new Map};function qa({onAgentClick:c,onBuildingClick:r,onBuildingDoubleClick:p,onBuildingPopup:g,onAreaContextMenu:k,onOpenSpawnModal:T,onOpenBossSpawnModal:S,onOpenAreaModal:N}){const{t:Z}=Gt(["common"]),w=Ln(),V=Pn(),[$,ie]=a.useState(null),[P,Se]=a.useState(null),[le,re]=a.useState(null);pn("flatview-image-modal",$!==null,()=>ie(null));const[ze,ft]=a.useState(null),[_e,we]=a.useState(null),[f,O]=a.useState(null),[Ae,Ee]=a.useState(null),[qe,Me]=a.useState(!1),Et=a.useCallback(()=>{Me(t=>!t)},[]),ht=a.useCallback(()=>{Me(!1)},[]),[Ye,oe]=a.useState(()=>{const t=Jt(A.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ke=a.useCallback(t=>{oe(t),Qt(A.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=s=>{if(s.key!==A.VIEW_MODE)return;const i=s.newValue;(i==="simple"||i==="chat"||i==="advanced")&&oe(i)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[$e,ce]=a.useState(()=>Xt(A.FLAT_INSPECTOR_OPEN,!1)),[R,de]=a.useState(!1),tt=a.useCallback(()=>de(t=>!t),[]),gt=a.useCallback(()=>de(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:R}}))},[R]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:$e}}))},[$e]),a.useEffect(()=>{const t=()=>de(C=>!C),s=()=>{ce(C=>{const E=!C;return be(A.FLAT_INSPECTOR_OPEN,E),E})},i=()=>{de(!1),ce(!1),be(A.FLAT_INSPECTOR_OPEN,!1)},x=()=>de(!1),b=()=>{ce(!1),be(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",i),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",i),window.removeEventListener("tide-close-flat-agents-drawer-only",x),window.removeEventListener("tide-close-flat-inspector-only",b)}},[]);const Oe=a.useRef(null),Ie=a.useRef(null),[ue,ve]=a.useState(()=>{const t=en(A.FLAT_MIDDLE_WIDTH,0);return t>=At?t:null}),[J,Be]=a.useState(()=>{const t=en(A.FLAT_INSPECTOR_WIDTH,0);return t>=Ht?t:null}),ae=a.useCallback(t=>{if(typeof window>"u")return t;const s=J!==null?St+J:0,i=window.innerWidth-cn-St-on-s;return Math.max(At,Math.min(Math.max(i,At),t))},[J]),se=a.useCallback(t=>{var b;if(typeof window>"u")return t;const s=(b=Oe.current)==null?void 0:b.querySelector(".flat-middle"),i=(s==null?void 0:s.getBoundingClientRect().width)??At,x=window.innerWidth-cn-i-St-on-St;return Math.max(Ht,Math.min(Math.max(x,Ht),t))},[]);a.useEffect(()=>{if(ue===null&&J===null)return;const t=()=>{ve(s=>{if(s===null)return s;const i=ae(s);return i===s?s:i}),Be(s=>{if(s===null)return s;const i=se(s);return i===s?s:i})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[ue,J,ae,se]);const Mt=a.useCallback(t=>{var i;if(t.button!==0)return;const s=(i=Oe.current)==null?void 0:i.querySelector(".flat-middle");s&&(t.currentTarget.setPointerCapture(t.pointerId),Ie.current={kind:"middle",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),je=a.useCallback(t=>{var i;if(t.button!==0)return;const s=(i=Oe.current)==null?void 0:i.querySelector(".flat-inspector");s&&(t.currentTarget.setPointerCapture(t.pointerId),Ie.current={kind:"inspector",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),nt=a.useCallback(t=>{const s=Ie.current;if(!s||t.pointerId!==s.pointerId)return;const i=t.clientX-s.startX;s.kind==="middle"?ve(ae(s.startWidth+i)):Be(se(s.startWidth-i))},[ae,se]),Te=a.useCallback(t=>{const s=Ie.current;if(!s||t.pointerId!==s.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(Ie.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=ae(s.startWidth+x);ve(b),yt(A.FLAT_MIDDLE_WIDTH,b)}else{const b=se(s.startWidth-x);Be(b),yt(A.FLAT_INSPECTOR_WIDTH,b)}},[ae,se]),Le=a.useCallback(()=>{ve(null),yt(A.FLAT_MIDDLE_WIDTH,0)},[]),j=a.useCallback(()=>{Be(null),yt(A.FLAT_INSPECTOR_WIDTH,0)},[]),[ee,Q]=a.useState(()=>Jt(A.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Fe=a.useCallback(t=>{Q(t),Qt(A.FLAT_INSPECTOR_VIEW,t)},[]),Pe=a.useCallback(()=>{ce(t=>{const s=!t;return be(A.FLAT_INSPECTOR_OPEN,s),s})},[]),We=a.useCallback(()=>{ce(!1),be(A.FLAT_INSPECTOR_OPEN,!1)},[]),It=a.useCallback(()=>{Fe("tracking"),ce(!0),be(A.FLAT_INSPECTOR_OPEN,!0)},[Fe]),B=Rn(),He=a.useCallback((t,s)=>{ie({url:t,name:s})},[]),Ce=a.useCallback((t,s)=>{Se({command:t,output:s,isLive:!1})},[]),Tt=a.useCallback((t,s)=>{var b;const i=V.size>0?Array.from(V)[0]:null,x=i?(b=h.getState().agents.get(i))==null?void 0:b.cwd:void 0;h.setFileViewerPath(t,s,x)},[V]),Lt=a.useCallback(t=>{re(t)},[]),Pt=a.useCallback((t,s)=>{ft({agentId:t,count:s})},[]),at=a.useCallback(t=>{p?p(t):r(t)},[r,p]),_=a.useMemo(()=>V.size>0?Array.from(V)[0]:null,[V]),xt=a.useCallback(t=>{_&&we({agentId:_,position:t})},[_]),Re=a.useCallback((t,s)=>{O({buildingId:t,position:s})},[]);a.useEffect(()=>{Me(!1)},[_]);const me=a.useRef([]),F=a.useRef(-1),Ue=a.useRef(!1),st=a.useRef(null),[Rt,bt]=a.useState(!1),[_t,Dt]=a.useState(!1),it=a.useRef(!1),Ve=a.useRef(null),pe=a.useRef(!1),ke=a.useMemo(()=>new Set(w.map(t=>t.id)),[w]),Xe=a.useMemo(()=>{const t=new Map(w.map(i=>[i.id,i])),s=new Map;for(const i of w)if((i.isBoss||i.class==="boss")&&i.subordinateIds&&i.subordinateIds.length>0){const x=i.subordinateIds.map(b=>t.get(b)).filter(b=>b!==void 0);x.length>0&&s.set(i.id,x)}return s},[w]),W=a.useCallback(()=>{const t=me.current,s=F.current;bt(s>0),Dt(s>=0&&s<t.length-1)},[]),fe=a.useCallback(t=>{const s=me.current;if(s.length===0)return;let i=F.current+t;for(;i>=0&&i<s.length;){const x=s[i];if(ke.has(x)){Ue.current=!0,F.current=i,W(),h.selectAgent(x);return}i+=t}},[ke,W]),Ne=a.useCallback(()=>fe(-1),[fe]),lt=a.useCallback(()=>fe(1),[fe]);ya(a.useCallback(()=>{const t=me.current,s=F.current;return t.length>0&&s>0?(fe(-1),"handled"):"exit"},[fe]));const Ze=a.useCallback((t,s)=>{if(typeof window>"u")return;const i=window.history.state,b={...typeof i=="object"&&i!==null?i:{},__flatAgentNav:{agentId:t}};s==="replace"?window.history.replaceState(b,"",window.location.href):window.history.pushState(b,"",window.location.href)},[]);a.useEffect(()=>{if(!_){it.current=!1,Ve.current=null;return}if(!it.current){Ze(_,"replace"),it.current=!0,Ve.current=_;return}if(pe.current){pe.current=!1,Ve.current=_;return}Ve.current!==_&&(Ze(_,"push"),Ve.current=_)},[_,Ze]),a.useEffect(()=>{const t=s=>{var C,E;const i=(E=(C=s.state)==null?void 0:C.__flatAgentNav)==null?void 0:E.agentId;if(!i||typeof i!="string"||!ke.has(i)||i===_)return;pe.current=!0,Ue.current=!0;const x=me.current,b=x.lastIndexOf(i);b>=0?F.current=b:(x.push(i),F.current=x.length-1),W(),h.selectAgent(i)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[ke,_,W]),a.useEffect(()=>{if(!_){me.current=[],F.current=-1,W();return}if(st.current=_,Ue.current){Ue.current=!1,W();return}const t=me.current,s=F.current;if(s>=0&&t[s]===_){W();return}const i=s<t.length-1?t.slice(0,s+1):t.slice();i.push(_),i.length>100&&i.shift(),me.current=i,F.current=i.length-1,W()},[_,W]);const rt=a.useCallback(t=>{c(t),de(!1)},[c]),zt=_??"",De=a.useCallback(()=>{},[]),wt=a.useCallback(t=>{rt(t)},[rt]),he=$e,[Je,Qe]=a.useState(he),[ot,ge]=a.useState(he);a.useEffect(()=>{if(he){Qe(!0);return}ge(!1);const t=setTimeout(()=>Qe(!1),240);return()=>clearTimeout(t)},[he]),a.useEffect(()=>{if(!Je||!he)return;let t=0;const s=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>ge(!0))});return()=>{cancelAnimationFrame(s),cancelAnimationFrame(t)}},[Je,he]);const ct=a.useRef(null);a.useEffect(()=>{if(_)return;const t=s=>{if(s.key!==" "&&s.key!=="Backspace")return;const i=s.target;if(i.tagName==="INPUT"||i.tagName==="TEXTAREA"||i.isContentEditable)return;const x=st.current;!x||!ke.has(x)||(s.preventDefault(),h.selectAgent(x))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[_,ke]);const[ye,dt]=a.useState(new Set),vt=a.useCallback(t=>{dt(s=>{const i=new Set(s);return i.has(t)?i.delete(t):i.add(t),i})},[]),[xe,n]=a.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),s=i=>n(i.matches);return t.addEventListener("change",s),()=>t.removeEventListener("change",s)},[]);const[o,l]=a.useState(null),u=a.useCallback(t=>{l(s=>s===t?null:t)},[]),H=fn(),G=hn(),[D]=Dn(),te=a.useMemo(()=>{if(_)return Ha;const t=new Map,s=[];for(const v of w){const I=h.getAreaForAgent(v.id);if(!tn((I==null?void 0:I.id)??null))continue;if(!I||I.archived){s.push(v);continue}const L=t.get(I.id);L?L.push(v):t.set(I.id,[v])}const i=new Map,x=[];for(const v of G.values()){let I=!1;for(const L of H.values())if(!L.archived&&nn(L.id)&&h.isPositionInArea(v.position,L)){const q=i.get(L.id);q?q.push(v):i.set(L.id,[v]),I=!0;break}!I&&tn(null)&&x.push(v)}const b=[];for(const[,v]of H){if(v.archived||!nn(v.id))continue;const I=t.get(v.id),L=i.get(v.id)??[];(I&&I.length>0||L.length>0)&&b.push({area:v,agents:I??[],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 m=1,M=1;const X=new Map;if(C.length>1){let v=1/0,I=-1/0,L=1/0,q=-1/0;for(const Y of C)v=Math.min(v,Y.area.center.x),I=Math.max(I,Y.area.center.x),L=Math.min(L,Y.area.center.z),q=Math.max(q,Y.area.center.z);const Ct=I-v||1,kt=q-L||1;if(C.length<=4){m=C.length,M=1;const Y=[...C].sort((K,Ot)=>K.area.center.x-Ot.area.center.x);for(let K=0;K<Y.length;K++)X.set(Y[K].area.id,{row:1,col:K+1})}else{const Y=[...C].sort((y,U)=>y.area.center.x-U.area.center.x),K=[];for(let y=1;y<Y.length;y++)K.push(Y[y].area.center.x-Y[y-1].area.center.x);const Ot=K.reduce((y,U)=>y+U,0)/K.length||1;let qt=1;for(const y of K)y>Ot*1.3&&qt++;m=Math.max(2,Math.min(qt,C.length));const Bt=[...C].sort((y,U)=>y.area.center.z-U.area.center.z),Nt=[];for(let y=1;y<Bt.length;y++)Nt.push(Bt[y].area.center.z-Bt[y-1].area.center.z);const jn=Nt.reduce((y,U)=>y+U,0)/Nt.length||1;let Yt=1;for(const y of Nt)y>jn*1.3&&Yt++;M=Math.max(2,Math.min(Yt,C.length)),m=Math.max(m,Math.ceil(C.length/M)),M=Math.max(M,Math.ceil(C.length/m));const Cn=Ct/m,kn=kt/M,Ft=new Set;for(const y of C){let U=Math.min(m-1,Math.max(0,Math.floor((y.area.center.x-v)/Cn))),Ge=Math.min(M-1,Math.max(0,Math.floor((y.area.center.z-L)/kn))),ut=`${Ge},${U}`,Kt=0;const Nn=M*m;for(;Ft.has(ut)&&Kt<Nn;)U++,U>=m&&(U=0,Ge=(Ge+1)%M),ut=`${Ge},${U}`,Kt++;Ft.has(ut)&&(Ge=M,U=0,ut=`${Ge},${U}`,M++),Ft.add(ut),X.set(y.area.id,{row:Ge+1,col:U+1})}}}const z=v=>{v.sort((I,L)=>{var Ct,kt,Y,K;const q=(((Ct=I.position)==null?void 0:Ct.z)??0)-(((kt=L.position)==null?void 0:kt.z)??0);return q!==0?q:(((Y=I.position)==null?void 0:Y.x)??0)-(((K=L.position)==null?void 0:K.x)??0)})};for(const v of C)z(v.agents);for(const v of E)z(v.agents);return{groups:[...C,...E],gridCols:m,gridRows:M,positions:X}},[w,H,G,D,_]),$t=a.useMemo(()=>{if(!_e)return[];const t=w.find(s=>s.id===_e.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(d,{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(d,{name:"chat",size:14}),onClick:()=>c(t.id)},{id:"clone-agent",label:"Clone Agent",icon:e.jsx(d,{name:"clipboard",size:14}),onClick:()=>h.cloneAgent(t.id)},{id:"fork-agent",label:"Fork Agent (with history)",icon:e.jsx(d,{name:"git-branch",size:14}),onClick:()=>h.forkAgent(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(d,{name:"trash",size:14}),danger:!0,onClick:()=>{Ee({agentId:t.id,name:t.name})}}]:[]},[_e,w,c]),jt=a.useMemo(()=>{var C;if(!f)return[];const t=G.get(f.buildingId);if(!t)return[];const s=[],i=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(d,{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:()=>at(t.id)}),i&&(x||s.push({id:"start",label:"Start",icon:e.jsx(d,{name:"play",size:14}),onClick:()=>h.sendBuildingCommand(t.id,"start")}),x&&(s.push({id:"restart",label:"Restart",icon:e.jsx(d,{name:"refresh",size:14}),onClick:()=>h.sendBuildingCommand(t.id,"restart")}),s.push({id:"stop",label:"Stop",icon:e.jsx(d,{name:"stop",size:14}),onClick:()=>h.sendBuildingCommand(t.id,"stop")}))),b&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(s.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(d,{name:"launch",size:14}),onClick:()=>{for(const E of t.subordinateBuildingIds)h.sendBuildingCommand(E,"start")}}),s.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(d,{name:"pause",size:14}),onClick:()=>{for(const E of t.subordinateBuildingIds)h.sendBuildingCommand(E,"stop")}}),s.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(d,{name:"restart",size:14}),onClick:()=>{for(const E of t.subordinateBuildingIds)h.sendBuildingCommand(E,"restart")}})),i&&s.push({id:"health-check",label:"Health Check",icon:e.jsx(d,{name:"health",size:14}),onClick:()=>h.sendBuildingCommand(t.id,"healthCheck")}),s.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),s.push({id:"edit",label:"Edit Building",icon:e.jsx(d,{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(d,{name:"copy",size:14}),onClick:()=>{h.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(d,{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(d,{name:"trash",size:14}),danger:!0,onClick:()=>h.deleteBuilding(t.id)}),s},[f,G,at]),ne=a.useCallback(t=>{const s=new Set(te.groups.map(i=>i.area.id));s.delete(t),dt(s),requestAnimationFrame(()=>{const i=ct.current;if(!i)return;const x=i.querySelector(`[data-area-id="${t}"]`);if(!x)return;const b=i.getBoundingClientRect(),E=x.getBoundingClientRect().top-b.top+i.scrollTop-8;i.scrollTo({top:Math.max(0,E),behavior:"smooth"})})},[te]);return e.jsxs("div",{ref:Oe,className:`flat-view ${he?"flat-view--with-inspector":""} ${_?"flat-view--has-chat":""} ${R?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(ue===null&&J===null)return;const t={};return ue!==null&&(t["--flat-middle-width"]=`${ue}px`),J!==null&&(t["--flat-inspector-width"]=`${J}px`),t})(),children:[R&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:gt,"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:N,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(zn,{activeAgentId:zt,onClose:De,onSelectAgent:wt,collapsedAreas:ye,onToggleArea:vt,agentListRef:ct})})]}),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:Mt,onPointerMove:nt,onPointerUp:Te,onPointerCancel:Te,onDoubleClick:Le}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":R?"Close agents sidebar":"Open agents sidebar","aria-expanded":R,onClick:tt,children:[e.jsx(d,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),_?e.jsx(Wa,{agentId:_,terminalViewMode:Ye,onTerminalViewModeChange:Ke,inspectorOpen:$e,onToggleInspector:Pe,onShowTaskBoard:It,onImageClick:He,onFileClick:Tt,onBashClick:Ce,onViewMarkdown:Lt,onRequestClearSubordinates:Pt,keyboard:B,canNavigateBack:Rt,canNavigateForward:_t,onNavigateBack:Ne,onNavigateForward:lt,agentInfoOpen:qe,onToggleAgentInfo:Et,onHeaderContextMenu:xt,onBuildingContextMenu:Re}):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(${te.gridCols}, 1fr)`},children:te.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var s;const t=xe&&o?((s=te.positions.get(o))==null?void 0:s.row)??null:null;return te.groups.map(i=>{var E;const x=i.area.id,b=te.positions.get(x),C=xe&&o!==x;return xe&&t!=null&&(b==null?void 0:b.row)===t&&x!==o?null:e.jsxs("div",{className:`flat-map-area-card${C?" flat-map-area-card--collapsed":""}`,style:{"--area-color":i.area.color,gridRow:b==null?void 0:b.row,gridColumn:b==null?void 0:b.col},onContextMenu:m=>{k&&(m.preventDefault(),m.stopPropagation(),k(x,{x:m.clientX,y:m.clientY}))},children:[((E=i.area.logo)==null?void 0:E.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:Na(i.area.logo.filename),alt:"","aria-hidden":"true",onError:m=>{m.currentTarget.style.display="none"}}),e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>xe?u(x):ne(x),title:xe?C?`Expand ${i.area.name}`:`Collapse ${i.area.name}`:`Focus ${i.area.name} in left panel`,"aria-expanded":xe?!C:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:i.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:i.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:i.agents.length}),xe&&e.jsx(d,{name:C?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:i.agents.map(m=>{const M=m.isBoss||m.class==="boss",X=M?Xe.get(m.id):void 0,z=$n(m),v=z.usedPercent>=80?"#ff4a4a":z.usedPercent>=60?"#ff9e4a":z.usedPercent>=40?"#ffd700":"#4aff9e",I=`Context: ${(z.totalTokens/1e3).toFixed(1)}k / ${(z.contextWindow/1e3).toFixed(1)}k (${z.usedPercent}% used, ${z.freePercent}% free)`,L=m.latestTodos&&m.latestTodos.length>0||X&&X.length>0;return e.jsx(On,{todos:m.latestTodos,subordinates:X,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${m.status}`,onClick:()=>c(m.id),onContextMenu:q=>{q.preventDefault(),q.stopPropagation(),we({agentId:m.id,position:{x:q.clientX,y:q.clientY}})},title:L?void 0:`${M?"Boss · ":""}Open chat with ${m.name}
2
+ ${I}`,children:[e.jsx(gn,{agent:m,size:16}),M&&e.jsx("span",{className:"flat-map-agent-chip__crown","aria-hidden":"true",children:e.jsx(d,{name:"crown",size:11,color:"#ffd700",weight:"fill"})}),e.jsx("span",{className:"flat-map-agent-chip__name",children:m.name}),e.jsx("img",{src:bn(m.provider,"/"),alt:m.provider,className:"flat-map-agent-chip__provider-icon",title:xn(m.provider)}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:_n(m.status)}}),m.latestTodos&&m.latestTodos.length>0&&e.jsx(Bn,{todos:m.latestTodos,maxDots:6}),M&&X&&X.length>0&&e.jsx(Fn,{subordinates:X,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:`${z.usedPercent}%`,backgroundColor:v}})})]})},m.id)})}),i.area.directories.length>0&&e.jsx("div",{className:"flat-map-area-card__folders",role:"group","aria-label":`${i.area.name} folders`,children:i.area.directories.map(m=>{const M=m.split("/").filter(Boolean).pop()||m;return e.jsxs("button",{type:"button",className:"flat-map-folder-chip",onClick:X=>{X.stopPropagation(),h.openFileExplorerForAreaFolder(x,m)},title:`Open in file explorer: ${m}`,children:[e.jsx(d,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-map-folder-chip__name",children:M})]},m)})}),i.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:i.buildings.map(m=>{var X;const M=(X=Wn[m.type])==null?void 0:X.color;return e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${m.status}`,style:M?{"--building-type-color":M}:void 0,onClick:z=>{if(g){const v=z.currentTarget.getBoundingClientRect();g(m.id,{x:v.right,y:v.top+v.height/2})}else at(m.id)},onContextMenu:z=>{z.preventDefault(),z.stopPropagation(),O({buildingId:m.id,position:{x:z.clientX,y:z.clientY}})},title:`${m.name} · ${m.type} · ${m.status}`,children:[e.jsx(d,{name:Hn(m.type),size:12,color:M}),e.jsx("span",{className:"flat-map-building-chip__name",children:m.name}),e.jsx("span",{className:"flat-map-building-chip__dot",style:{backgroundColor:Un(m.status)}})]},m.id)})})]},x)})})()})]})})]}),he&&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:je,onPointerMove:nt,onPointerUp:Te,onPointerCancel:Te,onDoubleClick:j}),Je&&e.jsxs("aside",{className:`flat-inspector ${ot?"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":ee==="agent",className:`flat-inspector__tab ${ee==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>Fe("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":ee==="tracking",className:`flat-inspector__tab ${ee==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>Fe("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:We,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:ee==="tracking"?e.jsx(Vn,{activeAgentId:_??"",onSelectAgent:t=>{c(t),window.innerWidth<=768&&We()}}):(()=>{if(!_)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=w.find(s=>s.id===_);return t?e.jsx(Xn,{agent:t,onFocusAgent:s=>{c(s),window.innerWidth<=768&&We()},onKillAgent:s=>h.killAgent(s)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),$&&e.jsx(Gn,{url:$.url,name:$.name,onClose:()=>ie(null)}),P&&e.jsx(qn,{state:P,onClose:()=>Se(null)}),e.jsx(Yn,{agent:_?w.find(t=>t.id===_)??null:null,content:le,onClose:()=>re(null)}),ze&&e.jsx(Kn,{action:"clear-subordinates",selectedAgentId:ze.agentId,subordinateCount:ze.count,onClose:()=>ft(null),onClearHistory:()=>{}}),e.jsx(Zn,{agent:_?w.find(t=>t.id===_)??null:null,isOpen:qe&&!!_,onClose:ht}),e.jsx(an,{isOpen:_e!==null,position:(_e==null?void 0:_e.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:$t,onClose:()=>we(null)}),e.jsx(an,{isOpen:f!==null,position:(f==null?void 0:f.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:jt,onClose:()=>O(null)}),e.jsx(Jn,{isOpen:Ae!==null,title:Z("common:confirm.removeAgentTitle"),message:Z("common:confirm.removeAgentMessage",{name:(Ae==null?void 0:Ae.name)??""}),confirmLabel:Z("common:buttons.remove"),cancelLabel:Z("common:buttons.cancel"),variant:"danger",onConfirm:()=>{Ae&&h.removeAgentFromServer(Ae.agentId)},onClose:()=>Ee(null)})]})}export{qa as FlatView};