tide-commander 1.146.0 → 1.147.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/assets/{BossLogsModal-BR0IXO2N.js → BossLogsModal-Cn8IVdqn.js} +1 -1
- package/dist/assets/{BossSpawnModal-x75-j2da.js → BossSpawnModal-Don-RZyh.js} +1 -1
- package/dist/assets/{ControlsModal-DVil4qEv.js → ControlsModal-C9--xWPi.js} +1 -1
- package/dist/assets/{DockerLogsModal-CFREftxm.js → DockerLogsModal-DSGnpfm5.js} +1 -1
- package/dist/assets/{EmbeddedEditor-BB1dXjgA.js → EmbeddedEditor-DfM3SrO7.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-Bt4lYIib.js → GmailOAuthSetup-DBWs7uzU.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-D9WbR8pi.js → GoogleOAuthSetup-yQjT5QzU.js} +1 -1
- package/dist/assets/{IframeModal-VRxo8uW0.js → IframeModal-DUTIyP5I.js} +1 -1
- package/dist/assets/{IntegrationsPanel-CPGny7vx.js → IntegrationsPanel-DPURuiaz.js} +2 -2
- package/dist/assets/{LogViewerModal-bkAbzlbh.js → LogViewerModal-CDZvTdfO.js} +1 -1
- package/dist/assets/{MonitoringModal-CkpuOazc.js → MonitoringModal-Dq2EJgbH.js} +1 -1
- package/dist/assets/{PM2LogsModal-Cllh-p5p.js → PM2LogsModal-C3dlYlGv.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-DLjiody0.js → RestoreArchivedAreaModal-BMFk0G8D.js} +1 -1
- package/dist/assets/{Scene2DCanvas-UxkEcgli.js → Scene2DCanvas-DlumJCbl.js} +1 -1
- package/dist/assets/{SceneManager-3z1c1ca8.js → SceneManager-UnhMFja8.js} +1 -1
- package/dist/assets/{SkillsPanel-Opv6_qsA.js → SkillsPanel-D326VBDa.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-BRBXqcBK.js → SlackMultiInstanceSetup-CA4nm925.js} +1 -1
- package/dist/assets/{SpawnModal-Cgr2So6H.js → SpawnModal-B1QOjZPe.js} +1 -1
- package/dist/assets/{StatisticsModal-CQ9zX_te.js → StatisticsModal-BUpvkJXA.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-DYl_KFut.js → SubordinateAssignmentModal-DtVsKDqV.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-DteLW6l2.js → TriggerManagerPanel-OD14xVMw.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-C_OQpYuO.js → WorkflowEditorPanel-B4UF3rcS.js} +1 -1
- package/dist/assets/{area-logos-CcA80suT.js → area-logos-Uc9SAeYg.js} +1 -1
- package/dist/assets/{index-CtzZOKXq.js → index-BC3Y_BAQ.js} +1 -1
- package/dist/assets/{index-DQhrNqbn.js → index-BD6swoQU.js} +3 -3
- package/dist/assets/index-C4mf6B5U.js +1 -0
- package/dist/assets/index-COHImd74.js +1 -0
- package/dist/assets/{index-CIuAGpI4.js → index-CScFEdm8.js} +1 -1
- package/dist/assets/{index-CCFfkD_H.js → index-CmmpVZ8w.js} +1 -1
- package/dist/assets/{index-BMCNBI0L.js → index-CuHJm43U.js} +1 -1
- package/dist/assets/{index-DhL1siJA.js → index-DkDzXtdj.js} +1 -1
- package/dist/assets/{index-DtUDyvyC.js → index-xBtKu0I8.js} +2 -2
- package/dist/assets/{main-BhpZ8DMy.js → main-Bp6V_-sL.js} +6 -6
- package/dist/assets/{web-5BrjMiIU.js → web-B-xc0c6e.js} +1 -1
- package/dist/assets/{web-Cx4v8f8d.js → web-BuDeKWBN.js} +1 -1
- package/dist/assets/{web-DpsRRzsh.js → web-DlzqHyn8.js} +1 -1
- package/dist/index.html +1 -1
- package/dist/locales/en/config.json +2 -1
- package/dist/locales/es/config.json +2 -1
- package/dist/src/packages/server/data/event-queries.js +24 -0
- package/dist/src/packages/server/data/migrations/008_slack_messages_chan_ts_index.sql +5 -0
- package/dist/src/packages/server/index.js +2 -0
- package/dist/src/packages/server/integrations/slack/slack-config.js +13 -0
- package/dist/src/packages/server/integrations/slack/slack-instance.js +67 -3
- package/dist/src/packages/server/integrations/slack/slack-polling-client.js +149 -68
- package/package.json +1 -1
- package/dist/assets/index-ClQaYJNq.js +0 -1
- package/dist/assets/index-k4vAPWgE.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as a,B as bn,E as Gt,G as sn,H as ln,j as e,J as rn,K as _n,u as Ht,L as wn,M as vn,N as jn,O as Cn,V as Nn,P as yn,U as kn,W as An,X as qt,S as E,Y as Yt,Z as Wt,_ as Kt,$ as jt,a0 as ye,a1 as Sn,s as f,a2 as on,a3 as cn,a4 as En,w as Zt,x as Jt,I as p,a5 as In,n as Mn,a6 as Tn,a7 as dn,a8 as un,a9 as Pn,aa as Ln,ab as Rn,ac as $n,ad as Dn,ae as zn,af as On,ag as Bn,ah as Fn,ai as Wn,aj as Hn,ak as Un,al as Qt,C as Vn,am as Xn,an as en,ao as Gn,ap as qn,aq as Yn,ar as Kn,as as Zn,at as Jn,au as Qn,av as ea,aw as ta,ax as na,ay as aa,az as sa,aA as ia,aB as la,aC as Ke,aD as ra,aE as oa,aF as ca,aG as da,aH as rt,aI as ua,aJ as pa,aK as ma,aL as fa,aM as ha,aN as ga,aO as xa}from"./main-BhpZ8DMy.js";import{g as ba}from"./area-logos-CcA80suT.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function _a(u){const o=a.useRef(u);o.current=u,a.useEffect(()=>{if(!bn())return;let m=null,h=!1;return Gt.addListener("backButton",()=>{o.current()==="exit"&&Gt.exitApp()}).then(y=>{h?y.remove():m=y}),()=>{h=!0,m&&(m.remove(),m=null)}},[])}async function wa(u){const o=sn(),m=await fetch(`${ln()}/api/agents/${u}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${o}`}});if(!m.ok){const h=await m.json().catch(()=>({}));throw new Error((h==null?void 0:h.error)||`Failed to start terminal (${m.status})`)}return m.json()}async function va(u){const o=sn();await fetch(`${ln()}/api/agents/${u}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${o}`}})}const ot=new Map;function ja({agentId:u}){const[o,m]=a.useState(null),[h,y]=a.useState(null);return a.useEffect(()=>{let R=!1;const P=ot.get(u);return P&&(clearTimeout(P),ot.delete(u)),m(null),y(null),wa(u).then(z=>{R||m(z.url)}).catch(z=>{R||y(z instanceof Error?z.message:"Failed to start terminal")}),()=>{R=!0;const z=ot.get(u);z&&clearTimeout(z),ot.set(u,setTimeout(()=>{ot.delete(u),va(u)},2500))}},[u]),h?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:h})}):o?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(rn,{terminalUrl:o,visible:!0})}):e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:"Attaching to interactive session…"})})}const Ot=new Map,Ca=6e4;function Na({agentId:u,contextSummary:o}){const{t:m}=Ht(["terminal","common"]),[h,y]=a.useState(()=>{var $;return(($=Ot.get(u))==null?void 0:$.snapshot)??null}),[R,P]=a.useState(!1),[z,le]=a.useState(null),_=a.useRef(0);a.useEffect(()=>{const $=Ot.get(u);if($&&Date.now()-$.fetchedAt<Ca){y($.snapshot);return}const U=++_.current;P(!0),le(null),wn(u).then(ee=>{U===_.current&&(Ot.set(u,{snapshot:ee,fetchedAt:Date.now()}),y(ee),P(!1))}).catch(ee=>{U===_.current&&(le(ee.message||"Failed to load plan limits"),P(!1))})},[u]);const O=[];if(h!=null&&h.rateLimits){const $=[{key:"fiveHour",label:m("terminal:usage.currentSession"),window:h.rateLimits.fiveHour},{key:"sevenDay",label:m("terminal:usage.currentWeekAll"),window:h.rateLimits.sevenDay},{key:"sevenDayOpus",label:m("terminal:usage.currentWeekOpus"),window:h.rateLimits.sevenDayOpus},{key:"sevenDaySonnet",label:m("terminal:usage.currentWeekSonnet"),window:h.rateLimits.sevenDaySonnet}];for(const U of $)U.window&&O.push({...U,window:U.window})}return e.jsxs("div",{className:"plan-limits-tooltip",children:[o&&e.jsx("div",{className:"plan-limits-tooltip__context",children:o}),e.jsx("div",{className:"plan-limits-tooltip__title",children:m("terminal:usage.limits")}),R&&!h&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[m("common:status.loading"),"…"]}),!R&&z&&!h&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:m("terminal:usage.limitsError",{message:z})}),O.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:O.map(({key:$,label:U,window:ee})=>{const te=Math.max(0,Math.min(100,ee.utilization)),de=jn(te);return e.jsxs("div",{className:"plan-limits-tooltip__gauge",children:[e.jsxs("div",{className:"plan-limits-tooltip__gauge-head",children:[e.jsx("span",{className:"plan-limits-tooltip__gauge-label",children:U}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:de},children:m("terminal:usage.percentUsed",{percent:Math.round(te)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${te}%`,background:de}})}),e.jsx("div",{className:"plan-limits-tooltip__reset",children:m("terminal:usage.resets",{time:vn(ee.resetsAt)})})]},$)})}):h&&!R&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:h.rateLimitsError?m("terminal:usage.limitsError",{message:h.rateLimitsError}):h.cliHint})]})}function ya({agentId:u,disabled:o,contextSummary:m,children:h}){return e.jsx(_n,{position:"top",maxWidth:320,disabled:o,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx(Na,{agentId:u,contextSummary:m}),children:h})}const ka=a.memo(function({className:o=""}){const{t:m}=Ht(["common"]),[h,y]=Cn(),R=a.useRef(null),[P,z]=a.useState(null);a.useLayoutEffect(()=>{const _=R.current;if(!_)return;const O=_.querySelector(".view-mode-toggle__btn--active");O&&z({left:O.offsetLeft,width:O.offsetWidth})},[h]);const le=a.useCallback(_=>{if(_!==h){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:_}})),_==="3d"){requestAnimationFrame(()=>y(_));return}y(_)}},[h,y]);return e.jsxs("div",{className:`view-mode-toggle ${o}`,ref:R,children:[P&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:P.left,width:P.width}}),Nn.map(_=>e.jsxs("button",{className:`view-mode-toggle__btn ${h===_?"view-mode-toggle__btn--active":""}`,onClick:()=>le(_),title:m(`common:viewMode.descriptions.${_}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[_==="2d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]}),_==="3d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]}),_==="flat"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1"})]}),_==="dashboard"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"12",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"3",y:"16",width:"7",height:"5",rx:"1"})]})]}),e.jsx("span",{className:"view-mode-toggle__label",children:m(`common:viewMode.labels.${_}`)})]},_))]})}),Ct=3,Nt=280,tn=320,Bt=240,nn=64,Aa=["simple","chat","advanced"],Sa={simple:"Simple",chat:"Chat",advanced:"Advanced"},Ea={simple:"○",chat:"◐",advanced:"◉"},Ia={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},an="flat-clear-context",pn="tide:flat-embedded-panels";function mn(){try{const u=localStorage.getItem(pn),o=u?JSON.parse(u):{};return o&&typeof o=="object"?o:{}}catch{return{}}}function Ft(u,o){try{const m=mn();o?m[u]=o:delete m[u],localStorage.setItem(pn,JSON.stringify(m))}catch{}}function Ma(u){const o=u.split("/").filter(Boolean);return o.length===0?u:o.slice(-2).join("/")}function Ta(u){if(u.provider==="codex"){const R=u.codexModel||"gpt-5.6-luna",P=ha[R];return{model:(P==null?void 0:P.label)||R}}if(u.provider==="opencode")return{model:u.opencodeModel||"opencode"};const o=u.model||"sonnet",m=xa[o],h=u.effort,y=h?ga[h]:void 0;return{model:(m==null?void 0:m.label)||o,effort:y==null?void 0:y.label}}function Pa(u,o){if(o.type==="rectangle"&&o.width&&o.height){const m=o.width/2,h=o.height/2;return u.x>=o.center.x-m&&u.x<=o.center.x+m&&u.z>=o.center.z-h&&u.z<=o.center.z+h}if(o.type==="circle"&&o.radius){const m=u.x-o.center.x,h=u.z-o.center.z;return m*m+h*h<=o.radius*o.radius}return!1}const La=Xn.memo(function({agentId:o,terminalViewMode:m,onTerminalViewModeChange:h,inspectorOpen:y,onToggleInspector:R,onImageClick:P,onFileClick:z,onBashClick:le,onViewMarkdown:_,onRequestClearSubordinates:O,keyboard:$,canNavigateBack:U,canNavigateForward:ee,onNavigateBack:te,onNavigateForward:de,agentInfoOpen:Be,onToggleAgentInfo:Ze,onHeaderContextMenu:ct,onBuildingContextMenu:K}){var it,xt;const b=en(o),T=cn(),Je=Gn(),re=a.useRef(null),Fe=a.useRef(null),{displayedAgentId:Pe,fadingOut:Qe}=qn(o),dt=en(Pe),We=!!Je.interactiveMode&&((b==null?void 0:b.provider)??"claude")==="claude"&&!!(b!=null&&b.sessionId),[me,Le]=a.useState(!1);a.useEffect(()=>{Le(!1)},[o]),a.useEffect(()=>{!We&&me&&Le(!1)},[We,me]),a.useEffect(()=>{const n=Fe.current;if(!n)return;const r=d=>{d.button===3?(d.preventDefault(),d.stopPropagation(),te()):d.button===4&&(d.preventDefault(),d.stopPropagation(),de())},l=d=>{(d.button===3||d.button===4)&&d.preventDefault()};return n.addEventListener("mouseup",r),n.addEventListener("mousedown",l),()=>{n.removeEventListener("mouseup",r),n.removeEventListener("mousedown",l)}},[te,de]),a.useEffect(()=>{const n=Fe.current;if(!n)return;let r=0,l=0,d=0;const X=250,Q=600,I=80,Ye=1.5,Ne=ie=>{let W=ie instanceof HTMLElement?ie:null;for(;W&&W!==n;){const t=window.getComputedStyle(W).overflowX;if((t==="auto"||t==="scroll")&&W.scrollWidth>W.clientWidth)return!0;W=W.parentElement}return!1},bt=ie=>{const W=Date.now();if(W<d){ie.preventDefault();return}if(Math.abs(ie.deltaX)<=Math.abs(ie.deltaY)*Ye){r=0;return}if(Ne(ie.target)){r=0;return}W-l>X&&(r=0),l=W,r+=ie.deltaX,r<=-I?(r=0,d=W+Q,ie.preventDefault(),te()):r>=I&&(r=0,d=W+Q,ie.preventDefault(),de())};return n.addEventListener("wheel",bt,{passive:!1}),()=>n.removeEventListener("wheel",bt)},[te,de]);const et=on(),ke=a.useMemo(()=>{if(!b)return null;const n=new Set,r=[];for(const l of et.values())l.archived||l.directories.length===0||l.assignedAgentIds.includes(o)&&(n.add(l.id),r.push(l));for(const l of et.values())l.archived||l.directories.length===0||n.has(l.id)||Pa({x:b.position.x,z:b.position.z},l)&&(n.add(l.id),r.push(l));return r.length===0?null:r.flatMap(l=>l.directories.filter(d=>d&&d.trim().length>0).map(d=>({areaId:l.id,areaName:l.name,dir:d})))},[b,o,et]),{branches:Ae,fetchRemote:fe,fetchingDirs:he}=Yn(ke),He=a.useMemo(()=>{var l;const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const d of T.values())d.type==="terminal"&&f.isPositionInArea(d.position,n)&&r.push({id:d.id,name:d.name,hasUrl:!!((l=d.terminalStatus)!=null&&l.url)});return r},[o,T]),Ue=a.useMemo(()=>{var l;const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const d of T.values())d.type==="server"&&((l=d.pm2)!=null&&l.enabled)&&f.isPositionInArea(d.position,n)&&r.push({id:d.id,name:d.name});return r},[o,T]),ge=a.useMemo(()=>{const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const l of T.values())l.type==="database"&&l.database&&f.isPositionInArea(l.position,n)&&r.push({id:l.id,name:l.name});return r},[o,T]),Se=Kn(),ue=a.useMemo(()=>{const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const l of T.values())if(l.type==="tests"&&f.isPositionInArea(l.position,n)){const d=!!l.folderPath&&Se.some(X=>Zn(X,l.folderPath));r.push({id:l.id,name:l.name,working:d})}return r},[o,T,Se]),xe=a.useMemo(()=>{const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const l of T.values())l.type==="http"&&f.isPositionInArea(l.position,n)&&r.push({id:l.id,name:l.name});return r},[o,T]),[,pe]=a.useReducer(n=>n+1,0),be=((it=re.current)==null?void 0:it.search.searchMode)??!1,Ee=a.useCallback(()=>{var n;(n=re.current)==null||n.search.toggleSearch(),pe()},[]),_e=Jn(),tt=_e.isPending(an),[j,we]=a.useState(null),B=j?T.get(j.buildingId):null,[ut,Ie]=a.useState(""),[ve,yt]=a.useState(()=>Qn()),D=a.useMemo(()=>{var n;return((n=f.getAreaForAgent(o))==null?void 0:n.id)??null},[o,T]),Re=a.useCallback((n,r)=>{Ie(""),we(l=>{const d=(l==null?void 0:l.buildingId)===r?null:{type:n,buildingId:r};return D&&Ft(D,d),d})},[D]),oe=a.useCallback(()=>{Ie(""),we(null),D&&Ft(D,null)},[D]);a.useEffect(()=>{if((j==null?void 0:j.type)!=="pm2-logs")return;const n=j.buildingId;return f.startLogStreaming(n,200),()=>f.stopLogStreaming(n)},[j]);const{height:kt,onResizeStart:At}=ea(),{sidePanelWidth:St,handleSidePanelResizeStart:Et}=ta(),[$e,pt]=a.useState(()=>Wt(E.GIT_PANEL_OPEN,!1)),[je,v]=a.useState(()=>Wt(E.BUILDINGS_PANEL_OPEN,!1)),[Z,ne]=a.useState(!1),Ve=a.useCallback(()=>{ne(n=>{const r=!n;return r&&na.setEnabled(!0),r})},[]),mt=a.useCallback(()=>ne(!1),[]),It=a.useCallback(()=>{pt(n=>{const r=!n;return ye(E.GIT_PANEL_OPEN,r),r})},[]),Mt=a.useCallback(()=>{v(n=>{const r=!n;return ye(E.BUILDINGS_PANEL_OPEN,r),r})},[]),Tt=a.useCallback(()=>{pt(!1),ye(E.GIT_PANEL_OPEN,!1)},[]),Pt=a.useCallback(()=>{v(!1),ye(E.BUILDINGS_PANEL_OPEN,!1)},[]),nt=aa(),ae=a.useMemo(()=>({terminal:He,"pm2-logs":Ue,database:ge,tests:ue,http:xe}),[He,Ue,ge,ue,xe]);a.useEffect(()=>{if(!j)return;ae[j.type].some(r=>r.id===j.buildingId)||(Ie(""),we(null))},[j,ae]);const Xe=a.useRef(void 0);a.useEffect(()=>{var r;if(Xe.current===D)return;Xe.current=D;const n=D?mn()[D]:void 0;Ie(""),n&&((r=ae[n.type])!=null&&r.some(l=>l.id===n.buildingId))?we(n):we(null)},[D,ae]),a.useEffect(()=>{const n=r=>{var X;const l=r.detail;if(!(l!=null&&l.buildingId)||!(l!=null&&l.type)||!((X=ae[l.type])!=null&&X.some(Q=>Q.id===l.buildingId)))return;l.handled=!0,Ie("");const d={type:l.type,buildingId:l.buildingId};we(d),D&&Ft(D,d)};return window.addEventListener("tide:dock-building-flat",n),()=>window.removeEventListener("tide:dock-building-flat",n)},[ae,D]);const[se,Me]=a.useState(!1),J=a.useRef(null);if(a.useEffect(()=>{if(!se)return;const n=r=>{J.current&&!J.current.contains(r.target)&&Me(!1)};return document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[se]),!b)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const V=b.contextStats,at=!!V,ft=V?V.totalTokens:b.contextUsed||0,Ge=V?V.contextWindow:b.contextLimit||2e5,ht=V?V.usedPercent:Math.round(ft/Ge*100),Te=Math.max(0,Math.min(100,ht)),gt=Math.round(Te*10)/10,Lt=Math.round((100-Te)*10)/10,ce=Te>=80?"#ff4a4a":Te>=60?"#ff9e4a":Te>=40?"#ffd700":"#4aff9e",De=(ft/1e3).toFixed(1),qe=(Ge/1e3).toFixed(1),Ce=b.cwd,st=Ce?Ma(Ce):null,ze=((xt=b.subordinateIds)==null?void 0:xt.length)||0,Rt=ze>0;return e.jsxs("div",{ref:Fe,className:`flat-terminal-wrapper ${$e||je||Z?"flat-terminal-wrapper--with-side-panel":""} ${Qe?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${St}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${Be?"flat-terminal-wrapper__header-main--active":""}`,onClick:Ze,onContextMenu:n=>{n.preventDefault(),n.stopPropagation(),ct({x:n.clientX,y:n.clientY})},title:Be?"Hide agent info":"Show agent info","aria-pressed":Be,children:[e.jsx(dn,{agent:b,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:b.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:un(b.status)},children:b.status})]}),b.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:b.taskLabel,children:["📋 ",b.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:b.provider==="codex"?"/assets/codex.png":b.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:b.provider,className:"flat-terminal-wrapper__header-provider-icon",title:b.provider==="codex"?"Codex Agent":b.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:n,effort:r}=Ta(b);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:r?`Model: ${n} · Effort: ${r}`:`Model: ${n}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:n}),r&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:r})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsxs("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:[Aa.map(n=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!me&&m===n?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Le(!1),h(n)},title:Ia[n],"aria-pressed":!me&&m===n,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:Ea[n]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Sa[n]})]},n)),We&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${me?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Le(n=>!n),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":me,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:e.jsx(p,{name:"terminal",size:13})}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:"Classic TUI"})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:te,disabled:!U,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(p,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:de,disabled:!ee,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(p,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${be?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Ee,title:be?"Close search":"Search messages","aria-pressed":be,children:e.jsx(p,{name:be?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${tt?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>_e.handleClick(an,()=>{var n;f.clearContext(o),(n=re.current)==null||n.historyLoader.clearHistory()}),title:tt?"Click again to confirm clear context":"Clear context",children:e.jsx(p,{name:tt?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${$e?"flat-terminal-wrapper__action-btn--active":""}`,onClick:It,title:$e?"Hide git panel":"Show git changes","aria-pressed":$e,children:e.jsx(p,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${je?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Mt,title:je?"Hide buildings panel":"Show area buildings","aria-pressed":je,children:e.jsx(p,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:J,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${se?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>Me(n=>!n),title:"More actions","aria-expanded":se,children:"⋮"}),se&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${Z?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Ve(),Me(!1)},title:Z?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(p,{name:"bug",size:14}),e.jsx("span",{children:Z?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{f.collapseContext(o),Me(!1)},disabled:b.status!=="idle",title:b.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(p,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),Rt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{O(o,ze),Me(!1)},children:[e.jsx(p,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",ze," subordinate",ze===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{f.killAgent(o),Me(!1)},children:[e.jsx(p,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${y?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:R,title:y?"Hide inspector panel":"Show inspector panel","aria-label":y?"Hide inspector panel":"Show inspector panel","aria-pressed":y,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>f.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(p,{name:"cross",size:14})})]})]}),me&&We?e.jsx(ja,{agentId:o}):Pe&&dt?e.jsx(sa,{ref:re,agentId:Pe,agent:dt,viewMode:m,isOpen:!0,onImageClick:P,onFileClick:z,onBashClick:le,onViewMarkdown:_,keyboard:$,hasModalOpen:!1},Pe):null,j&&B&&(()=>{var X,Q;const n=j.type,r={terminal:"terminal","pm2-logs":"scroll",database:"hard-drives",tests:"flask",http:"globe"},l=n==="terminal"&&!((X=B.terminalStatus)!=null&&X.url),d=!l;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:At,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded panel"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`${B.name} panel`,style:{height:kt},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(p,{name:r[n],size:12}),e.jsx("span",{children:B.name}),l&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsxs("span",{className:"flat-bottom-panel__header-actions",children:[n==="pm2-logs"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",className:"guake-bottom-terminal-filter",value:ut,onChange:I=>Ie(I.target.value),placeholder:"Filter logs","aria-label":`Filter logs for ${B.name}`,spellCheck:!1}),e.jsx("select",{className:"guake-bottom-terminal-retention",value:ve===null?"unlimited":String(ve),onChange:I=>{const Ye=I.target.value==="unlimited"?null:Number(I.target.value);yt(Ye),la(Ye)},"aria-label":`Max log retention for ${B.name}`,children:ia.map(I=>e.jsx("option",{value:I===null?"unlimited":String(I),children:I===null?"Unlimited":`${I.toLocaleString()} lines`},I===null?"unlimited":I))}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>f.clearStreamingLogs(j.buildingId),title:"Clear logs",children:e.jsx(p,{name:"trash",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>f.sendBuildingCommand(j.buildingId,"restart"),title:"Restart",children:e.jsx(p,{name:"restart",size:12})})]}),d&&e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>{oe(),Ke(j.buildingId)},title:"Maximize — open as modal","aria-label":"Open as modal",children:e.jsx(p,{name:"fullscreen",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:oe,title:"Close panel","aria-label":"Close panel",children:e.jsx(p,{name:"cross",size:12})})]})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:n==="terminal"?(Q=B.terminalStatus)!=null&&Q.url?e.jsx(rn,{terminalUrl:B.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."}):n==="pm2-logs"?e.jsx(ra,{buildingId:j.buildingId,filterText:ut,maxRetention:ve}):n==="database"?e.jsx(oa,{building:B}):n==="tests"?e.jsx("div",{className:"tests-panel-host",children:e.jsx(ca,{building:B,autoFocusSearch:!1})}):e.jsx("div",{className:"http-requests-panel-host",children:e.jsx(da,{building:B,autoFocusSearch:!1})})})]})]})})(),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[b.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(p,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),Ce&&st&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${Ce}`,"aria-label":`Open ${Ce} in file explorer`,role:"button",tabIndex:0,onClick:()=>f.openFileExplorer(Ce),onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),f.openFileExplorer(Ce))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(p,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:st})]}),ke&&ke.map(({areaId:n,areaName:r,dir:l})=>{const d=Ae.get(l),X=he.has(l),Q=l.split("/").filter(Boolean).pop()||l;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${r}: ${l}${d?` (${d.branch}${d.ahead?` ↑${d.ahead}`:""}${d.behind?` ↓${d.behind}`:""})`:""}`,onClick:()=>f.openFileExplorerForAreaFolder(n,l),children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:Q}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(p,{name:"git-branch",size:10})," ",d.branch]}),d.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${d.ahead} ahead`,children:[e.jsx(p,{name:"arrow-up",size:9}),d.ahead]}),d.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${d.behind} behind`,children:[e.jsx(p,{name:"arrow-down",size:9}),d.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${X?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:I=>{I.stopPropagation(),fe(l)},children:e.jsx(p,{name:X?"hourglass":"download",size:12})})]})]},`${n}:${l}`)}),e.jsx(ya,{agentId:o,disabled:((b==null?void 0:b.provider)??"claude")!=="claude",contextSummary:at?`Context: ${De}k / ${qe}k tokens (${gt}% used)`:void 0,children:e.jsxs("span",{className:"flat-terminal-wrapper__context",tabIndex:0,role:"button",onClick:()=>f.setContextModalAgentId(o),onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),f.setContextModalAgentId(o))},title:((b==null?void 0:b.provider)??"claude")!=="claude"?at?`Context usage: ${De}k / ${qe}k tokens (${gt}% used). Click to view stats.`:"Click to fetch context stats":void 0,children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(p,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${Te}%`,backgroundColor:ce}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:ce},children:[De,"k/",qe,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",Lt,"% free)"]}),!at&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(p,{name:"warn",size:12})})]})}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),He.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:He.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""} ${n.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${r?"Hide":"Show"} terminal: ${n.name}${n.hasUrl?"":" (starting...)"}`,onClick:()=>{if(r){oe();return}if(n.hasUrl&&rt(n.id)==="modal"){Ke(n.id);return}n.hasUrl||f.sendBuildingCommand(n.id,"start"),Re("terminal",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"terminal",size:14})},n.id)})}),Ue.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Ue.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""}`,title:`${r?"Hide":"Show"} logs: ${n.name}`,onClick:()=>{r?oe():rt(n.id)==="modal"?Ke(n.id):Re("pm2-logs",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"scroll",size:14})},n.id)})}),ge.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:ge.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""}`,title:`${r?"Hide":"Show"} database: ${n.name}`,onClick:()=>{r?oe():rt(n.id)==="modal"?Ke(n.id):Re("database",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"hard-drives",size:14})},n.id)})}),ue.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:ue.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""} ${n.working?"flat-terminal-wrapper__building-btn--tests-working":""}`,title:n.working?`Running tests: ${n.name}`:`${r?"Hide":"Show"} tests: ${n.name}`,onClick:()=>{r?oe():rt(n.id)==="modal"?Ke(n.id):Re("tests",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"flask",size:14})},n.id)})}),xe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area HTTP requests",children:xe.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""}`,title:`${r?"Hide":"Show"} HTTP requests: ${n.name}`,onClick:()=>{r?oe():rt(n.id)==="modal"?Ke(n.id):Re("http",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"globe",size:14})},n.id)})}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(ua,{})})]}),$e&&e.jsx(pa,{agentId:o,agents:nt,onClose:Tt,branchInfoMap:Ae,fetchRemote:fe,fetchingDirs:he,onResizeStart:n=>Et(n,"right")}),je&&e.jsx(ma,{agentId:o,onClose:Pt}),Z&&e.jsx(fa,{agentId:o,onClose:mt})]})});function Oa({onAgentClick:u,onBuildingClick:o,onBuildingDoubleClick:m,onBuildingPopup:h,onAreaContextMenu:y,onOpenSpawnModal:R,onOpenBossSpawnModal:P,onOpenAreaModal:z}){const{t:le}=Ht(["common"]),_=yn(),O=kn(),[$,U]=a.useState(null),[ee,te]=a.useState(null),[de,Be]=a.useState(null);An("flatview-image-modal",$!==null,()=>U(null));const[Ze,ct]=a.useState(null),[K,b]=a.useState(null),[T,Je]=a.useState(null),[re,Fe]=a.useState(null),[Pe,Qe]=a.useState(!1),dt=a.useCallback(()=>{Qe(t=>!t)},[]),We=a.useCallback(()=>{Qe(!1)},[]),[me,Le]=a.useState(()=>{const t=qt(E.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),et=a.useCallback(t=>{Le(t),Yt(E.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=s=>{if(s.key!==E.VIEW_MODE)return;const i=s.newValue;(i==="simple"||i==="chat"||i==="advanced")&&Le(i)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[ke,Ae]=a.useState(()=>Wt(E.FLAT_INSPECTOR_OPEN,!1)),[fe,he]=a.useState(!1),He=a.useCallback(()=>he(t=>!t),[]),Ue=a.useCallback(()=>he(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:fe}}))},[fe]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:ke}}))},[ke]),a.useEffect(()=>{const t=()=>he(C=>!C),s=()=>{Ae(C=>{const k=!C;return ye(E.FLAT_INSPECTOR_OPEN,k),k})},i=()=>{he(!1),Ae(!1),ye(E.FLAT_INSPECTOR_OPEN,!1)},g=()=>he(!1),x=()=>{Ae(!1),ye(E.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",s),window.addEventListener("tide-close-flat-side-views",i),window.addEventListener("tide-close-flat-agents-drawer-only",g),window.addEventListener("tide-close-flat-inspector-only",x),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",s),window.removeEventListener("tide-close-flat-side-views",i),window.removeEventListener("tide-close-flat-agents-drawer-only",g),window.removeEventListener("tide-close-flat-inspector-only",x)}},[]);const ge=a.useRef(null),Se=a.useRef(null),[ue,xe]=a.useState(()=>{const t=Kt(E.FLAT_MIDDLE_WIDTH,0);return t>=Nt?t:null}),[pe,be]=a.useState(()=>{const t=Kt(E.FLAT_INSPECTOR_WIDTH,0);return t>=Bt?t:null}),Ee=a.useCallback(t=>{if(typeof window>"u")return t;const s=pe!==null?Ct+pe:0,i=window.innerWidth-nn-Ct-tn-s;return Math.max(Nt,Math.min(Math.max(i,Nt),t))},[pe]),_e=a.useCallback(t=>{var x;if(typeof window>"u")return t;const s=(x=ge.current)==null?void 0:x.querySelector(".flat-middle"),i=(s==null?void 0:s.getBoundingClientRect().width)??Nt,g=window.innerWidth-nn-i-Ct-tn-Ct;return Math.max(Bt,Math.min(Math.max(g,Bt),t))},[]);a.useEffect(()=>{if(ue===null&&pe===null)return;const t=()=>{xe(s=>{if(s===null)return s;const i=Ee(s);return i===s?s:i}),be(s=>{if(s===null)return s;const i=_e(s);return i===s?s:i})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[ue,pe,Ee,_e]);const tt=a.useCallback(t=>{var i;if(t.button!==0)return;const s=(i=ge.current)==null?void 0:i.querySelector(".flat-middle");s&&(t.currentTarget.setPointerCapture(t.pointerId),Se.current={kind:"middle",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),j=a.useCallback(t=>{var i;if(t.button!==0)return;const s=(i=ge.current)==null?void 0:i.querySelector(".flat-inspector");s&&(t.currentTarget.setPointerCapture(t.pointerId),Se.current={kind:"inspector",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),we=a.useCallback(t=>{const s=Se.current;if(!s||t.pointerId!==s.pointerId)return;const i=t.clientX-s.startX;s.kind==="middle"?xe(Ee(s.startWidth+i)):be(_e(s.startWidth-i))},[Ee,_e]),B=a.useCallback(t=>{const s=Se.current;if(!s||t.pointerId!==s.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(Se.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-s.startX)>2))return;const g=t.clientX-s.startX;if(s.kind==="middle"){const x=Ee(s.startWidth+g);xe(x),jt(E.FLAT_MIDDLE_WIDTH,x)}else{const x=_e(s.startWidth-g);be(x),jt(E.FLAT_INSPECTOR_WIDTH,x)}},[Ee,_e]),ut=a.useCallback(()=>{xe(null),jt(E.FLAT_MIDDLE_WIDTH,0)},[]),Ie=a.useCallback(()=>{be(null),jt(E.FLAT_INSPECTOR_WIDTH,0)},[]),[ve,yt]=a.useState(()=>qt(E.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),D=a.useCallback(t=>{yt(t),Yt(E.FLAT_INSPECTOR_VIEW,t)},[]),Re=a.useCallback(()=>{Ae(t=>{const s=!t;return ye(E.FLAT_INSPECTOR_OPEN,s),s})},[]),oe=a.useCallback(()=>{Ae(!1),ye(E.FLAT_INSPECTOR_OPEN,!1)},[]),kt=Sn(),At=a.useCallback((t,s)=>{U({url:t,name:s})},[]),St=a.useCallback((t,s)=>{te({command:t,output:s,isLive:!1})},[]),Et=a.useCallback((t,s)=>{var x;const i=O.size>0?Array.from(O)[0]:null,g=i?(x=f.getState().agents.get(i))==null?void 0:x.cwd:void 0;f.setFileViewerPath(t,s,g)},[O]),$e=a.useCallback(t=>{Be(t)},[]),pt=a.useCallback((t,s)=>{ct({agentId:t,count:s})},[]),je=a.useCallback(t=>{m?m(t):o(t)},[o,m]),v=a.useMemo(()=>O.size>0?Array.from(O)[0]:null,[O]);a.useEffect(()=>{Qe(!1)},[v]);const Z=a.useRef([]),ne=a.useRef(-1),Ve=a.useRef(!1),mt=a.useRef(null),[It,Mt]=a.useState(!1),[Tt,Pt]=a.useState(!1),nt=a.useRef(!1),ae=a.useRef(null),Xe=a.useRef(!1),se=a.useMemo(()=>new Set(_.map(t=>t.id)),[_]),Me=a.useMemo(()=>{const t=new Map(_.map(i=>[i.id,i])),s=new Map;for(const i of _)if((i.isBoss||i.class==="boss")&&i.subordinateIds&&i.subordinateIds.length>0){const g=i.subordinateIds.map(x=>t.get(x)).filter(x=>x!==void 0);g.length>0&&s.set(i.id,g)}return s},[_]),J=a.useCallback(()=>{const t=Z.current,s=ne.current;Mt(s>0),Pt(s>=0&&s<t.length-1)},[]),V=a.useCallback(t=>{const s=Z.current;if(s.length===0)return;let i=ne.current+t;for(;i>=0&&i<s.length;){const g=s[i];if(se.has(g)){Ve.current=!0,ne.current=i,J(),f.selectAgent(g);return}i+=t}},[se,J]),at=a.useCallback(()=>V(-1),[V]),ft=a.useCallback(()=>V(1),[V]);_a(a.useCallback(()=>{const t=Z.current,s=ne.current;return t.length>0&&s>0?(V(-1),"handled"):"exit"},[V]));const Ge=a.useCallback((t,s)=>{if(typeof window>"u")return;const i=window.history.state,x={...typeof i=="object"&&i!==null?i:{},__flatAgentNav:{agentId:t}};s==="replace"?window.history.replaceState(x,"",window.location.href):window.history.pushState(x,"",window.location.href)},[]);a.useEffect(()=>{if(!v){nt.current=!1,ae.current=null;return}if(!nt.current){Ge(v,"replace"),nt.current=!0,ae.current=v;return}if(Xe.current){Xe.current=!1,ae.current=v;return}ae.current!==v&&(Ge(v,"push"),ae.current=v)},[v,Ge]),a.useEffect(()=>{const t=s=>{var C,k;const i=(k=(C=s.state)==null?void 0:C.__flatAgentNav)==null?void 0:k.agentId;if(!i||typeof i!="string"||!se.has(i)||i===v)return;Xe.current=!0,Ve.current=!0;const g=Z.current,x=g.lastIndexOf(i);x>=0?ne.current=x:(g.push(i),ne.current=g.length-1),J(),f.selectAgent(i)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[se,v,J]),a.useEffect(()=>{if(!v){Z.current=[],ne.current=-1,J();return}if(mt.current=v,Ve.current){Ve.current=!1,J();return}const t=Z.current,s=ne.current;if(s>=0&&t[s]===v){J();return}const i=s<t.length-1?t.slice(0,s+1):t.slice();i.push(v),i.length>100&&i.shift(),Z.current=i,ne.current=i.length-1,J()},[v,J]);const ht=a.useCallback(t=>{u(t),he(!1)},[u]),Te=v??"",gt=a.useCallback(()=>{},[]),Lt=a.useCallback(t=>{ht(t)},[ht]),ce=ke,[De,qe]=a.useState(ce),[Ce,st]=a.useState(ce);a.useEffect(()=>{if(ce){qe(!0);return}st(!1);const t=setTimeout(()=>qe(!1),240);return()=>clearTimeout(t)},[ce]),a.useEffect(()=>{if(!De||!ce)return;let t=0;const s=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>st(!0))});return()=>{cancelAnimationFrame(s),cancelAnimationFrame(t)}},[De,ce]);const ze=a.useRef(null);a.useEffect(()=>{if(v)return;const t=s=>{if(s.key!==" "&&s.key!=="Backspace")return;const i=s.target;if(i.tagName==="INPUT"||i.tagName==="TEXTAREA"||i.isContentEditable)return;const g=mt.current;!g||!se.has(g)||(s.preventDefault(),f.selectAgent(g))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[v,se]);const[Rt,it]=a.useState(new Set),xt=a.useCallback(t=>{it(s=>{const i=new Set(s);return i.has(t)?i.delete(t):i.add(t),i})},[]),[n,r]=a.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),s=i=>r(i.matches);return t.addEventListener("change",s),()=>t.removeEventListener("change",s)},[]);const[l,d]=a.useState(null),X=a.useCallback(t=>{d(s=>s===t?null:t)},[]),Q=on(),I=cn(),[Ye]=En(),Ne=a.useMemo(()=>{const t=new Map,s=[];for(const w of _){const S=f.getAreaForAgent(w.id);if(!Zt((S==null?void 0:S.id)??null))continue;if(!S||S.archived){s.push(w);continue}const M=t.get(S.id);M?M.push(w):t.set(S.id,[w])}const i=new Map,g=[];for(const w of I.values()){let S=!1;for(const M of Q.values())if(!M.archived&&Jt(M.id)&&f.isPositionInArea(w.position,M)){const G=i.get(M.id);G?G.push(w):i.set(M.id,[w]),S=!0;break}!S&&Zt(null)&&g.push(w)}const x=[];for(const[,w]of Q){if(w.archived||!Jt(w.id))continue;const S=t.get(w.id),M=i.get(w.id)??[];(S&&S.length>0||M.length>0)&&x.push({area:w,agents:S??[],buildings:M})}(s.length>0||g.length>0)&&x.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:s,buildings:g});const C=x.filter(w=>w.area.id!=="__unassigned__"),k=x.filter(w=>w.area.id==="__unassigned__");let c=1,A=1;const H=new Map;if(C.length>1){let w=1/0,S=-1/0,M=1/0,G=-1/0;for(const q of C)w=Math.min(w,q.area.center.x),S=Math.max(S,q.area.center.x),M=Math.min(M,q.area.center.z),G=Math.max(G,q.area.center.z);const _t=S-w||1,wt=G-M||1;if(C.length<=4){c=C.length,A=1;const q=[...C].sort((Y,$t)=>Y.area.center.x-$t.area.center.x);for(let Y=0;Y<q.length;Y++)H.set(q[Y].area.id,{row:1,col:Y+1})}else{const q=[...C].sort((N,F)=>N.area.center.x-F.area.center.x),Y=[];for(let N=1;N<q.length;N++)Y.push(q[N].area.center.x-q[N-1].area.center.x);const $t=Y.reduce((N,F)=>N+F,0)/Y.length||1;let Ut=1;for(const N of Y)N>$t*1.3&&Ut++;c=Math.max(2,Math.min(Ut,C.length));const Dt=[...C].sort((N,F)=>N.area.center.z-F.area.center.z),vt=[];for(let N=1;N<Dt.length;N++)vt.push(Dt[N].area.center.z-Dt[N-1].area.center.z);const fn=vt.reduce((N,F)=>N+F,0)/vt.length||1;let Vt=1;for(const N of vt)N>fn*1.3&&Vt++;A=Math.max(2,Math.min(Vt,C.length)),c=Math.max(c,Math.ceil(C.length/A)),A=Math.max(A,Math.ceil(C.length/c));const hn=_t/c,gn=wt/A,zt=new Set;for(const N of C){let F=Math.min(c-1,Math.max(0,Math.floor((N.area.center.x-w)/hn))),Oe=Math.min(A-1,Math.max(0,Math.floor((N.area.center.z-M)/gn))),lt=`${Oe},${F}`,Xt=0;const xn=A*c;for(;zt.has(lt)&&Xt<xn;)F++,F>=c&&(F=0,Oe=(Oe+1)%A),lt=`${Oe},${F}`,Xt++;zt.has(lt)&&(Oe=A,F=0,lt=`${Oe},${F}`,A++),zt.add(lt),H.set(N.area.id,{row:Oe+1,col:F+1})}}}const L=w=>{w.sort((S,M)=>{var _t,wt,q,Y;const G=(((_t=S.position)==null?void 0:_t.z)??0)-(((wt=M.position)==null?void 0:wt.z)??0);return G!==0?G:(((q=S.position)==null?void 0:q.x)??0)-(((Y=M.position)==null?void 0:Y.x)??0)})};for(const w of C)L(w.agents);for(const w of k)L(w.agents);return{groups:[...C,...k],gridCols:c,gridRows:A,positions:H}},[_,Q,I,Ye]),bt=a.useMemo(()=>{if(!K)return[];const t=_.find(s=>s.id===K.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(p,{name:"chat",size:14}),onClick:()=>u(t.id)},{id:"clone-agent",label:"Clone Agent",icon:e.jsx(p,{name:"clipboard",size:14}),onClick:()=>f.cloneAgent(t.id)},{id:"fork-agent",label:"Fork Agent (with history)",icon:e.jsx(p,{name:"git-branch",size:14}),onClick:()=>f.forkAgent(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>{Fe({agentId:t.id,name:t.name})}}]:[]},[K,_,u]),ie=a.useMemo(()=>{var C;if(!T)return[];const t=I.get(T.buildingId);if(!t)return[];const s=[],i=t.type==="server"||t.type==="docker"||t.type==="terminal",g=t.status==="running",x=t.type==="boss";if(s.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="tests"?"Open Tests":t.type==="http"?"Open Requests":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((C=t.pm2)!=null&&C.enabled)?"View PM2 Logs":"Open",icon:e.jsx(p,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="tests"?"flask":t.type==="http"?"globe":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>je(t.id)}),i&&(g||s.push({id:"start",label:"Start",icon:e.jsx(p,{name:"play",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"start")}),g&&(s.push({id:"restart",label:"Restart",icon:e.jsx(p,{name:"refresh",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"restart")}),s.push({id:"stop",label:"Stop",icon:e.jsx(p,{name:"stop",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"stop")}))),x&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(s.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(p,{name:"launch",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)f.sendBuildingCommand(k,"start")}}),s.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(p,{name:"pause",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)f.sendBuildingCommand(k,"stop")}}),s.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(p,{name:"restart",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)f.sendBuildingCommand(k,"restart")}})),i&&s.push({id:"health-check",label:"Health Check",icon:e.jsx(p,{name:"health",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"healthCheck")}),s.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),s.push({id:"edit",label:"Edit Building",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),s.push({id:"clone",label:"Clone Building",icon:e.jsx(p,{name:"copy",size:14}),onClick:()=>{f.createBuilding({name:`${t.name} (Copy)`,type:t.type,style:t.style,color:t.color,scale:t.scale,position:{x:t.position.x+2,z:t.position.z+2},cwd:t.cwd,folderPath:t.folderPath,commands:t.commands,pm2:t.pm2,docker:t.docker,database:t.database,terminal:t.terminal,urls:t.urls,subordinateBuildingIds:t.subordinateBuildingIds})}}),t.urls&&t.urls.length>0)for(const k of t.urls)s.push({id:`url-${k.label}`,label:k.label,icon:e.jsx(p,{name:"link",size:14}),onClick:()=>window.open(k.url,"_blank","noopener,noreferrer")});return s.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),s.push({id:"delete",label:"Delete Building",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>f.deleteBuilding(t.id)}),s},[T,I,je]),W=a.useCallback(t=>{const s=new Set(Ne.groups.map(i=>i.area.id));s.delete(t),it(s),requestAnimationFrame(()=>{const i=ze.current;if(!i)return;const g=i.querySelector(`[data-area-id="${t}"]`);if(!g)return;const x=i.getBoundingClientRect(),k=g.getBoundingClientRect().top-x.top+i.scrollTop-8;i.scrollTo({top:Math.max(0,k),behavior:"smooth"})})},[Ne]);return e.jsxs("div",{ref:ge,className:`flat-view ${ce?"flat-view--with-inspector":""} ${v?"flat-view--has-chat":""} ${fe?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(ue===null&&pe===null)return;const t={};return ue!==null&&(t["--flat-middle-width"]=`${ue}px`),pe!==null&&(t["--flat-inspector-width"]=`${pe}px`),t})(),children:[fe&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Ue,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children:e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:R,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:P,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:z,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(In,{activeAgentId:Te,onClose:gt,onSelectAgent:Lt,collapsedAreas:Rt,onToggleArea:xt,agentListRef:ze})})]}),e.jsx("div",{className:"flat-splitter flat-splitter--middle",role:"separator","aria-orientation":"vertical","aria-label":"Resize agents panel",title:"Drag to resize · Double-click to reset",onPointerDown:tt,onPointerMove:we,onPointerUp:B,onPointerCancel:B,onDoubleClick:ut}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":fe?"Close agents sidebar":"Open agents sidebar","aria-expanded":fe,onClick:He,children:[e.jsx(p,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),v?e.jsx(La,{agentId:v,terminalViewMode:me,onTerminalViewModeChange:et,inspectorOpen:ke,onToggleInspector:Re,onImageClick:At,onFileClick:Et,onBashClick:St,onViewMarkdown:$e,onRequestClearSubordinates:pt,keyboard:kt,canNavigateBack:It,canNavigateForward:Tt,onNavigateBack:at,onNavigateForward:ft,agentInfoOpen:Pe,onToggleAgentInfo:dt,onHeaderContextMenu:t=>{v&&b({agentId:v,position:t})},onBuildingContextMenu:(t,s)=>{Je({buildingId:t,position:s})}}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"}),e.jsx(ka,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Ne.gridCols}, 1fr)`},children:Ne.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var s;const t=n&&l?((s=Ne.positions.get(l))==null?void 0:s.row)??null:null;return Ne.groups.map(i=>{var k;const g=i.area.id,x=Ne.positions.get(g),C=n&&l!==g;return n&&t!=null&&(x==null?void 0:x.row)===t&&g!==l?null:e.jsxs("div",{className:`flat-map-area-card${C?" flat-map-area-card--collapsed":""}`,style:{"--area-color":i.area.color,gridRow:x==null?void 0:x.row,gridColumn:x==null?void 0:x.col},onContextMenu:c=>{y&&(c.preventDefault(),c.stopPropagation(),y(g,{x:c.clientX,y:c.clientY}))},children:[((k=i.area.logo)==null?void 0:k.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:ba(i.area.logo.filename),alt:"","aria-hidden":"true",onError:c=>{c.currentTarget.style.display="none"}}),e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>n?X(g):W(g),title:n?C?`Expand ${i.area.name}`:`Collapse ${i.area.name}`:`Focus ${i.area.name} in left panel`,"aria-expanded":n?!C:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:i.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:i.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:i.agents.length}),n&&e.jsx(p,{name:C?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:i.agents.map(c=>{const A=c.isBoss||c.class==="boss",H=A?Me.get(c.id):void 0,L=Mn(c),w=L.usedPercent>=80?"#ff4a4a":L.usedPercent>=60?"#ff9e4a":L.usedPercent>=40?"#ffd700":"#4aff9e",S=`Context: ${(L.totalTokens/1e3).toFixed(1)}k / ${(L.contextWindow/1e3).toFixed(1)}k (${L.usedPercent}% used, ${L.freePercent}% free)`,M=c.latestTodos&&c.latestTodos.length>0||H&&H.length>0;return e.jsx(Tn,{todos:c.latestTodos,subordinates:H,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${c.status}`,onClick:()=>u(c.id),onContextMenu:G=>{G.preventDefault(),G.stopPropagation(),b({agentId:c.id,position:{x:G.clientX,y:G.clientY}})},title:M?void 0:`${A?"Boss · ":""}Open chat with ${c.name}
|
|
1
|
+
import{r as a,B as bn,E as Gt,G as sn,H as ln,j as e,J as rn,K as _n,u as Ht,L as wn,M as vn,N as jn,O as Cn,V as Nn,P as yn,U as kn,W as An,X as qt,S as E,Y as Yt,Z as Wt,_ as Kt,$ as jt,a0 as ye,a1 as Sn,s as f,a2 as on,a3 as cn,a4 as En,w as Zt,x as Jt,I as p,a5 as In,n as Mn,a6 as Tn,a7 as dn,a8 as un,a9 as Pn,aa as Ln,ab as Rn,ac as $n,ad as Dn,ae as zn,af as On,ag as Bn,ah as Fn,ai as Wn,aj as Hn,ak as Un,al as Qt,C as Vn,am as Xn,an as en,ao as Gn,ap as qn,aq as Yn,ar as Kn,as as Zn,at as Jn,au as Qn,av as ea,aw as ta,ax as na,ay as aa,az as sa,aA as ia,aB as la,aC as Ke,aD as ra,aE as oa,aF as ca,aG as da,aH as rt,aI as ua,aJ as pa,aK as ma,aL as fa,aM as ha,aN as ga,aO as xa}from"./main-Bp6V_-sL.js";import{g as ba}from"./area-logos-Uc9SAeYg.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function _a(u){const o=a.useRef(u);o.current=u,a.useEffect(()=>{if(!bn())return;let m=null,h=!1;return Gt.addListener("backButton",()=>{o.current()==="exit"&&Gt.exitApp()}).then(y=>{h?y.remove():m=y}),()=>{h=!0,m&&(m.remove(),m=null)}},[])}async function wa(u){const o=sn(),m=await fetch(`${ln()}/api/agents/${u}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${o}`}});if(!m.ok){const h=await m.json().catch(()=>({}));throw new Error((h==null?void 0:h.error)||`Failed to start terminal (${m.status})`)}return m.json()}async function va(u){const o=sn();await fetch(`${ln()}/api/agents/${u}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${o}`}})}const ot=new Map;function ja({agentId:u}){const[o,m]=a.useState(null),[h,y]=a.useState(null);return a.useEffect(()=>{let R=!1;const P=ot.get(u);return P&&(clearTimeout(P),ot.delete(u)),m(null),y(null),wa(u).then(z=>{R||m(z.url)}).catch(z=>{R||y(z instanceof Error?z.message:"Failed to start terminal")}),()=>{R=!0;const z=ot.get(u);z&&clearTimeout(z),ot.set(u,setTimeout(()=>{ot.delete(u),va(u)},2500))}},[u]),h?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:h})}):o?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(rn,{terminalUrl:o,visible:!0})}):e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:"Attaching to interactive session…"})})}const Ot=new Map,Ca=6e4;function Na({agentId:u,contextSummary:o}){const{t:m}=Ht(["terminal","common"]),[h,y]=a.useState(()=>{var $;return(($=Ot.get(u))==null?void 0:$.snapshot)??null}),[R,P]=a.useState(!1),[z,le]=a.useState(null),_=a.useRef(0);a.useEffect(()=>{const $=Ot.get(u);if($&&Date.now()-$.fetchedAt<Ca){y($.snapshot);return}const U=++_.current;P(!0),le(null),wn(u).then(ee=>{U===_.current&&(Ot.set(u,{snapshot:ee,fetchedAt:Date.now()}),y(ee),P(!1))}).catch(ee=>{U===_.current&&(le(ee.message||"Failed to load plan limits"),P(!1))})},[u]);const O=[];if(h!=null&&h.rateLimits){const $=[{key:"fiveHour",label:m("terminal:usage.currentSession"),window:h.rateLimits.fiveHour},{key:"sevenDay",label:m("terminal:usage.currentWeekAll"),window:h.rateLimits.sevenDay},{key:"sevenDayOpus",label:m("terminal:usage.currentWeekOpus"),window:h.rateLimits.sevenDayOpus},{key:"sevenDaySonnet",label:m("terminal:usage.currentWeekSonnet"),window:h.rateLimits.sevenDaySonnet}];for(const U of $)U.window&&O.push({...U,window:U.window})}return e.jsxs("div",{className:"plan-limits-tooltip",children:[o&&e.jsx("div",{className:"plan-limits-tooltip__context",children:o}),e.jsx("div",{className:"plan-limits-tooltip__title",children:m("terminal:usage.limits")}),R&&!h&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[m("common:status.loading"),"…"]}),!R&&z&&!h&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:m("terminal:usage.limitsError",{message:z})}),O.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:O.map(({key:$,label:U,window:ee})=>{const te=Math.max(0,Math.min(100,ee.utilization)),de=jn(te);return e.jsxs("div",{className:"plan-limits-tooltip__gauge",children:[e.jsxs("div",{className:"plan-limits-tooltip__gauge-head",children:[e.jsx("span",{className:"plan-limits-tooltip__gauge-label",children:U}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:de},children:m("terminal:usage.percentUsed",{percent:Math.round(te)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${te}%`,background:de}})}),e.jsx("div",{className:"plan-limits-tooltip__reset",children:m("terminal:usage.resets",{time:vn(ee.resetsAt)})})]},$)})}):h&&!R&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:h.rateLimitsError?m("terminal:usage.limitsError",{message:h.rateLimitsError}):h.cliHint})]})}function ya({agentId:u,disabled:o,contextSummary:m,children:h}){return e.jsx(_n,{position:"top",maxWidth:320,disabled:o,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx(Na,{agentId:u,contextSummary:m}),children:h})}const ka=a.memo(function({className:o=""}){const{t:m}=Ht(["common"]),[h,y]=Cn(),R=a.useRef(null),[P,z]=a.useState(null);a.useLayoutEffect(()=>{const _=R.current;if(!_)return;const O=_.querySelector(".view-mode-toggle__btn--active");O&&z({left:O.offsetLeft,width:O.offsetWidth})},[h]);const le=a.useCallback(_=>{if(_!==h){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:_}})),_==="3d"){requestAnimationFrame(()=>y(_));return}y(_)}},[h,y]);return e.jsxs("div",{className:`view-mode-toggle ${o}`,ref:R,children:[P&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:P.left,width:P.width}}),Nn.map(_=>e.jsxs("button",{className:`view-mode-toggle__btn ${h===_?"view-mode-toggle__btn--active":""}`,onClick:()=>le(_),title:m(`common:viewMode.descriptions.${_}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[_==="2d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]}),_==="3d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]}),_==="flat"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1"})]}),_==="dashboard"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"12",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"3",y:"16",width:"7",height:"5",rx:"1"})]})]}),e.jsx("span",{className:"view-mode-toggle__label",children:m(`common:viewMode.labels.${_}`)})]},_))]})}),Ct=3,Nt=280,tn=320,Bt=240,nn=64,Aa=["simple","chat","advanced"],Sa={simple:"Simple",chat:"Chat",advanced:"Advanced"},Ea={simple:"○",chat:"◐",advanced:"◉"},Ia={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},an="flat-clear-context",pn="tide:flat-embedded-panels";function mn(){try{const u=localStorage.getItem(pn),o=u?JSON.parse(u):{};return o&&typeof o=="object"?o:{}}catch{return{}}}function Ft(u,o){try{const m=mn();o?m[u]=o:delete m[u],localStorage.setItem(pn,JSON.stringify(m))}catch{}}function Ma(u){const o=u.split("/").filter(Boolean);return o.length===0?u:o.slice(-2).join("/")}function Ta(u){if(u.provider==="codex"){const R=u.codexModel||"gpt-5.6-luna",P=ha[R];return{model:(P==null?void 0:P.label)||R}}if(u.provider==="opencode")return{model:u.opencodeModel||"opencode"};const o=u.model||"sonnet",m=xa[o],h=u.effort,y=h?ga[h]:void 0;return{model:(m==null?void 0:m.label)||o,effort:y==null?void 0:y.label}}function Pa(u,o){if(o.type==="rectangle"&&o.width&&o.height){const m=o.width/2,h=o.height/2;return u.x>=o.center.x-m&&u.x<=o.center.x+m&&u.z>=o.center.z-h&&u.z<=o.center.z+h}if(o.type==="circle"&&o.radius){const m=u.x-o.center.x,h=u.z-o.center.z;return m*m+h*h<=o.radius*o.radius}return!1}const La=Xn.memo(function({agentId:o,terminalViewMode:m,onTerminalViewModeChange:h,inspectorOpen:y,onToggleInspector:R,onImageClick:P,onFileClick:z,onBashClick:le,onViewMarkdown:_,onRequestClearSubordinates:O,keyboard:$,canNavigateBack:U,canNavigateForward:ee,onNavigateBack:te,onNavigateForward:de,agentInfoOpen:Be,onToggleAgentInfo:Ze,onHeaderContextMenu:ct,onBuildingContextMenu:K}){var it,xt;const b=en(o),T=cn(),Je=Gn(),re=a.useRef(null),Fe=a.useRef(null),{displayedAgentId:Pe,fadingOut:Qe}=qn(o),dt=en(Pe),We=!!Je.interactiveMode&&((b==null?void 0:b.provider)??"claude")==="claude"&&!!(b!=null&&b.sessionId),[me,Le]=a.useState(!1);a.useEffect(()=>{Le(!1)},[o]),a.useEffect(()=>{!We&&me&&Le(!1)},[We,me]),a.useEffect(()=>{const n=Fe.current;if(!n)return;const r=d=>{d.button===3?(d.preventDefault(),d.stopPropagation(),te()):d.button===4&&(d.preventDefault(),d.stopPropagation(),de())},l=d=>{(d.button===3||d.button===4)&&d.preventDefault()};return n.addEventListener("mouseup",r),n.addEventListener("mousedown",l),()=>{n.removeEventListener("mouseup",r),n.removeEventListener("mousedown",l)}},[te,de]),a.useEffect(()=>{const n=Fe.current;if(!n)return;let r=0,l=0,d=0;const X=250,Q=600,I=80,Ye=1.5,Ne=ie=>{let W=ie instanceof HTMLElement?ie:null;for(;W&&W!==n;){const t=window.getComputedStyle(W).overflowX;if((t==="auto"||t==="scroll")&&W.scrollWidth>W.clientWidth)return!0;W=W.parentElement}return!1},bt=ie=>{const W=Date.now();if(W<d){ie.preventDefault();return}if(Math.abs(ie.deltaX)<=Math.abs(ie.deltaY)*Ye){r=0;return}if(Ne(ie.target)){r=0;return}W-l>X&&(r=0),l=W,r+=ie.deltaX,r<=-I?(r=0,d=W+Q,ie.preventDefault(),te()):r>=I&&(r=0,d=W+Q,ie.preventDefault(),de())};return n.addEventListener("wheel",bt,{passive:!1}),()=>n.removeEventListener("wheel",bt)},[te,de]);const et=on(),ke=a.useMemo(()=>{if(!b)return null;const n=new Set,r=[];for(const l of et.values())l.archived||l.directories.length===0||l.assignedAgentIds.includes(o)&&(n.add(l.id),r.push(l));for(const l of et.values())l.archived||l.directories.length===0||n.has(l.id)||Pa({x:b.position.x,z:b.position.z},l)&&(n.add(l.id),r.push(l));return r.length===0?null:r.flatMap(l=>l.directories.filter(d=>d&&d.trim().length>0).map(d=>({areaId:l.id,areaName:l.name,dir:d})))},[b,o,et]),{branches:Ae,fetchRemote:fe,fetchingDirs:he}=Yn(ke),He=a.useMemo(()=>{var l;const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const d of T.values())d.type==="terminal"&&f.isPositionInArea(d.position,n)&&r.push({id:d.id,name:d.name,hasUrl:!!((l=d.terminalStatus)!=null&&l.url)});return r},[o,T]),Ue=a.useMemo(()=>{var l;const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const d of T.values())d.type==="server"&&((l=d.pm2)!=null&&l.enabled)&&f.isPositionInArea(d.position,n)&&r.push({id:d.id,name:d.name});return r},[o,T]),ge=a.useMemo(()=>{const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const l of T.values())l.type==="database"&&l.database&&f.isPositionInArea(l.position,n)&&r.push({id:l.id,name:l.name});return r},[o,T]),Se=Kn(),ue=a.useMemo(()=>{const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const l of T.values())if(l.type==="tests"&&f.isPositionInArea(l.position,n)){const d=!!l.folderPath&&Se.some(X=>Zn(X,l.folderPath));r.push({id:l.id,name:l.name,working:d})}return r},[o,T,Se]),xe=a.useMemo(()=>{const n=f.getAreaForAgent(o);if(!n)return[];const r=[];for(const l of T.values())l.type==="http"&&f.isPositionInArea(l.position,n)&&r.push({id:l.id,name:l.name});return r},[o,T]),[,pe]=a.useReducer(n=>n+1,0),be=((it=re.current)==null?void 0:it.search.searchMode)??!1,Ee=a.useCallback(()=>{var n;(n=re.current)==null||n.search.toggleSearch(),pe()},[]),_e=Jn(),tt=_e.isPending(an),[j,we]=a.useState(null),B=j?T.get(j.buildingId):null,[ut,Ie]=a.useState(""),[ve,yt]=a.useState(()=>Qn()),D=a.useMemo(()=>{var n;return((n=f.getAreaForAgent(o))==null?void 0:n.id)??null},[o,T]),Re=a.useCallback((n,r)=>{Ie(""),we(l=>{const d=(l==null?void 0:l.buildingId)===r?null:{type:n,buildingId:r};return D&&Ft(D,d),d})},[D]),oe=a.useCallback(()=>{Ie(""),we(null),D&&Ft(D,null)},[D]);a.useEffect(()=>{if((j==null?void 0:j.type)!=="pm2-logs")return;const n=j.buildingId;return f.startLogStreaming(n,200),()=>f.stopLogStreaming(n)},[j]);const{height:kt,onResizeStart:At}=ea(),{sidePanelWidth:St,handleSidePanelResizeStart:Et}=ta(),[$e,pt]=a.useState(()=>Wt(E.GIT_PANEL_OPEN,!1)),[je,v]=a.useState(()=>Wt(E.BUILDINGS_PANEL_OPEN,!1)),[Z,ne]=a.useState(!1),Ve=a.useCallback(()=>{ne(n=>{const r=!n;return r&&na.setEnabled(!0),r})},[]),mt=a.useCallback(()=>ne(!1),[]),It=a.useCallback(()=>{pt(n=>{const r=!n;return ye(E.GIT_PANEL_OPEN,r),r})},[]),Mt=a.useCallback(()=>{v(n=>{const r=!n;return ye(E.BUILDINGS_PANEL_OPEN,r),r})},[]),Tt=a.useCallback(()=>{pt(!1),ye(E.GIT_PANEL_OPEN,!1)},[]),Pt=a.useCallback(()=>{v(!1),ye(E.BUILDINGS_PANEL_OPEN,!1)},[]),nt=aa(),ae=a.useMemo(()=>({terminal:He,"pm2-logs":Ue,database:ge,tests:ue,http:xe}),[He,Ue,ge,ue,xe]);a.useEffect(()=>{if(!j)return;ae[j.type].some(r=>r.id===j.buildingId)||(Ie(""),we(null))},[j,ae]);const Xe=a.useRef(void 0);a.useEffect(()=>{var r;if(Xe.current===D)return;Xe.current=D;const n=D?mn()[D]:void 0;Ie(""),n&&((r=ae[n.type])!=null&&r.some(l=>l.id===n.buildingId))?we(n):we(null)},[D,ae]),a.useEffect(()=>{const n=r=>{var X;const l=r.detail;if(!(l!=null&&l.buildingId)||!(l!=null&&l.type)||!((X=ae[l.type])!=null&&X.some(Q=>Q.id===l.buildingId)))return;l.handled=!0,Ie("");const d={type:l.type,buildingId:l.buildingId};we(d),D&&Ft(D,d)};return window.addEventListener("tide:dock-building-flat",n),()=>window.removeEventListener("tide:dock-building-flat",n)},[ae,D]);const[se,Me]=a.useState(!1),J=a.useRef(null);if(a.useEffect(()=>{if(!se)return;const n=r=>{J.current&&!J.current.contains(r.target)&&Me(!1)};return document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[se]),!b)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const V=b.contextStats,at=!!V,ft=V?V.totalTokens:b.contextUsed||0,Ge=V?V.contextWindow:b.contextLimit||2e5,ht=V?V.usedPercent:Math.round(ft/Ge*100),Te=Math.max(0,Math.min(100,ht)),gt=Math.round(Te*10)/10,Lt=Math.round((100-Te)*10)/10,ce=Te>=80?"#ff4a4a":Te>=60?"#ff9e4a":Te>=40?"#ffd700":"#4aff9e",De=(ft/1e3).toFixed(1),qe=(Ge/1e3).toFixed(1),Ce=b.cwd,st=Ce?Ma(Ce):null,ze=((xt=b.subordinateIds)==null?void 0:xt.length)||0,Rt=ze>0;return e.jsxs("div",{ref:Fe,className:`flat-terminal-wrapper ${$e||je||Z?"flat-terminal-wrapper--with-side-panel":""} ${Qe?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${St}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${Be?"flat-terminal-wrapper__header-main--active":""}`,onClick:Ze,onContextMenu:n=>{n.preventDefault(),n.stopPropagation(),ct({x:n.clientX,y:n.clientY})},title:Be?"Hide agent info":"Show agent info","aria-pressed":Be,children:[e.jsx(dn,{agent:b,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:b.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:un(b.status)},children:b.status})]}),b.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:b.taskLabel,children:["📋 ",b.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:b.provider==="codex"?"/assets/codex.png":b.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:b.provider,className:"flat-terminal-wrapper__header-provider-icon",title:b.provider==="codex"?"Codex Agent":b.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:n,effort:r}=Ta(b);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:r?`Model: ${n} · Effort: ${r}`:`Model: ${n}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:n}),r&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:r})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsxs("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:[Aa.map(n=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!me&&m===n?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Le(!1),h(n)},title:Ia[n],"aria-pressed":!me&&m===n,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:Ea[n]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Sa[n]})]},n)),We&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${me?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Le(n=>!n),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":me,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:e.jsx(p,{name:"terminal",size:13})}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:"Classic TUI"})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:te,disabled:!U,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(p,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:de,disabled:!ee,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(p,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${be?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Ee,title:be?"Close search":"Search messages","aria-pressed":be,children:e.jsx(p,{name:be?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${tt?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>_e.handleClick(an,()=>{var n;f.clearContext(o),(n=re.current)==null||n.historyLoader.clearHistory()}),title:tt?"Click again to confirm clear context":"Clear context",children:e.jsx(p,{name:tt?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${$e?"flat-terminal-wrapper__action-btn--active":""}`,onClick:It,title:$e?"Hide git panel":"Show git changes","aria-pressed":$e,children:e.jsx(p,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${je?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Mt,title:je?"Hide buildings panel":"Show area buildings","aria-pressed":je,children:e.jsx(p,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:J,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${se?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>Me(n=>!n),title:"More actions","aria-expanded":se,children:"⋮"}),se&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${Z?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Ve(),Me(!1)},title:Z?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(p,{name:"bug",size:14}),e.jsx("span",{children:Z?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{f.collapseContext(o),Me(!1)},disabled:b.status!=="idle",title:b.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(p,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),Rt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{O(o,ze),Me(!1)},children:[e.jsx(p,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",ze," subordinate",ze===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{f.killAgent(o),Me(!1)},children:[e.jsx(p,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${y?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:R,title:y?"Hide inspector panel":"Show inspector panel","aria-label":y?"Hide inspector panel":"Show inspector panel","aria-pressed":y,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>f.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(p,{name:"cross",size:14})})]})]}),me&&We?e.jsx(ja,{agentId:o}):Pe&&dt?e.jsx(sa,{ref:re,agentId:Pe,agent:dt,viewMode:m,isOpen:!0,onImageClick:P,onFileClick:z,onBashClick:le,onViewMarkdown:_,keyboard:$,hasModalOpen:!1},Pe):null,j&&B&&(()=>{var X,Q;const n=j.type,r={terminal:"terminal","pm2-logs":"scroll",database:"hard-drives",tests:"flask",http:"globe"},l=n==="terminal"&&!((X=B.terminalStatus)!=null&&X.url),d=!l;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:At,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded panel"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`${B.name} panel`,style:{height:kt},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(p,{name:r[n],size:12}),e.jsx("span",{children:B.name}),l&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsxs("span",{className:"flat-bottom-panel__header-actions",children:[n==="pm2-logs"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",className:"guake-bottom-terminal-filter",value:ut,onChange:I=>Ie(I.target.value),placeholder:"Filter logs","aria-label":`Filter logs for ${B.name}`,spellCheck:!1}),e.jsx("select",{className:"guake-bottom-terminal-retention",value:ve===null?"unlimited":String(ve),onChange:I=>{const Ye=I.target.value==="unlimited"?null:Number(I.target.value);yt(Ye),la(Ye)},"aria-label":`Max log retention for ${B.name}`,children:ia.map(I=>e.jsx("option",{value:I===null?"unlimited":String(I),children:I===null?"Unlimited":`${I.toLocaleString()} lines`},I===null?"unlimited":I))}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>f.clearStreamingLogs(j.buildingId),title:"Clear logs",children:e.jsx(p,{name:"trash",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>f.sendBuildingCommand(j.buildingId,"restart"),title:"Restart",children:e.jsx(p,{name:"restart",size:12})})]}),d&&e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>{oe(),Ke(j.buildingId)},title:"Maximize — open as modal","aria-label":"Open as modal",children:e.jsx(p,{name:"fullscreen",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:oe,title:"Close panel","aria-label":"Close panel",children:e.jsx(p,{name:"cross",size:12})})]})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:n==="terminal"?(Q=B.terminalStatus)!=null&&Q.url?e.jsx(rn,{terminalUrl:B.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."}):n==="pm2-logs"?e.jsx(ra,{buildingId:j.buildingId,filterText:ut,maxRetention:ve}):n==="database"?e.jsx(oa,{building:B}):n==="tests"?e.jsx("div",{className:"tests-panel-host",children:e.jsx(ca,{building:B,autoFocusSearch:!1})}):e.jsx("div",{className:"http-requests-panel-host",children:e.jsx(da,{building:B,autoFocusSearch:!1})})})]})]})})(),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[b.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(p,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),Ce&&st&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${Ce}`,"aria-label":`Open ${Ce} in file explorer`,role:"button",tabIndex:0,onClick:()=>f.openFileExplorer(Ce),onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),f.openFileExplorer(Ce))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(p,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:st})]}),ke&&ke.map(({areaId:n,areaName:r,dir:l})=>{const d=Ae.get(l),X=he.has(l),Q=l.split("/").filter(Boolean).pop()||l;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${r}: ${l}${d?` (${d.branch}${d.ahead?` ↑${d.ahead}`:""}${d.behind?` ↓${d.behind}`:""})`:""}`,onClick:()=>f.openFileExplorerForAreaFolder(n,l),children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:Q}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(p,{name:"git-branch",size:10})," ",d.branch]}),d.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${d.ahead} ahead`,children:[e.jsx(p,{name:"arrow-up",size:9}),d.ahead]}),d.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${d.behind} behind`,children:[e.jsx(p,{name:"arrow-down",size:9}),d.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${X?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:I=>{I.stopPropagation(),fe(l)},children:e.jsx(p,{name:X?"hourglass":"download",size:12})})]})]},`${n}:${l}`)}),e.jsx(ya,{agentId:o,disabled:((b==null?void 0:b.provider)??"claude")!=="claude",contextSummary:at?`Context: ${De}k / ${qe}k tokens (${gt}% used)`:void 0,children:e.jsxs("span",{className:"flat-terminal-wrapper__context",tabIndex:0,role:"button",onClick:()=>f.setContextModalAgentId(o),onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),f.setContextModalAgentId(o))},title:((b==null?void 0:b.provider)??"claude")!=="claude"?at?`Context usage: ${De}k / ${qe}k tokens (${gt}% used). Click to view stats.`:"Click to fetch context stats":void 0,children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(p,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${Te}%`,backgroundColor:ce}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:ce},children:[De,"k/",qe,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",Lt,"% free)"]}),!at&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(p,{name:"warn",size:12})})]})}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),He.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:He.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""} ${n.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${r?"Hide":"Show"} terminal: ${n.name}${n.hasUrl?"":" (starting...)"}`,onClick:()=>{if(r){oe();return}if(n.hasUrl&&rt(n.id)==="modal"){Ke(n.id);return}n.hasUrl||f.sendBuildingCommand(n.id,"start"),Re("terminal",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"terminal",size:14})},n.id)})}),Ue.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Ue.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""}`,title:`${r?"Hide":"Show"} logs: ${n.name}`,onClick:()=>{r?oe():rt(n.id)==="modal"?Ke(n.id):Re("pm2-logs",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"scroll",size:14})},n.id)})}),ge.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:ge.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""}`,title:`${r?"Hide":"Show"} database: ${n.name}`,onClick:()=>{r?oe():rt(n.id)==="modal"?Ke(n.id):Re("database",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"hard-drives",size:14})},n.id)})}),ue.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:ue.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""} ${n.working?"flat-terminal-wrapper__building-btn--tests-working":""}`,title:n.working?`Running tests: ${n.name}`:`${r?"Hide":"Show"} tests: ${n.name}`,onClick:()=>{r?oe():rt(n.id)==="modal"?Ke(n.id):Re("tests",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"flask",size:14})},n.id)})}),xe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area HTTP requests",children:xe.map(n=>{const r=(j==null?void 0:j.buildingId)===n.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""}`,title:`${r?"Hide":"Show"} HTTP requests: ${n.name}`,onClick:()=>{r?oe():rt(n.id)==="modal"?Ke(n.id):Re("http",n.id)},onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),K(n.id,{x:l.clientX,y:l.clientY})},children:e.jsx(p,{name:"globe",size:14})},n.id)})}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(ua,{})})]}),$e&&e.jsx(pa,{agentId:o,agents:nt,onClose:Tt,branchInfoMap:Ae,fetchRemote:fe,fetchingDirs:he,onResizeStart:n=>Et(n,"right")}),je&&e.jsx(ma,{agentId:o,onClose:Pt}),Z&&e.jsx(fa,{agentId:o,onClose:mt})]})});function Oa({onAgentClick:u,onBuildingClick:o,onBuildingDoubleClick:m,onBuildingPopup:h,onAreaContextMenu:y,onOpenSpawnModal:R,onOpenBossSpawnModal:P,onOpenAreaModal:z}){const{t:le}=Ht(["common"]),_=yn(),O=kn(),[$,U]=a.useState(null),[ee,te]=a.useState(null),[de,Be]=a.useState(null);An("flatview-image-modal",$!==null,()=>U(null));const[Ze,ct]=a.useState(null),[K,b]=a.useState(null),[T,Je]=a.useState(null),[re,Fe]=a.useState(null),[Pe,Qe]=a.useState(!1),dt=a.useCallback(()=>{Qe(t=>!t)},[]),We=a.useCallback(()=>{Qe(!1)},[]),[me,Le]=a.useState(()=>{const t=qt(E.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),et=a.useCallback(t=>{Le(t),Yt(E.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=s=>{if(s.key!==E.VIEW_MODE)return;const i=s.newValue;(i==="simple"||i==="chat"||i==="advanced")&&Le(i)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[ke,Ae]=a.useState(()=>Wt(E.FLAT_INSPECTOR_OPEN,!1)),[fe,he]=a.useState(!1),He=a.useCallback(()=>he(t=>!t),[]),Ue=a.useCallback(()=>he(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:fe}}))},[fe]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:ke}}))},[ke]),a.useEffect(()=>{const t=()=>he(C=>!C),s=()=>{Ae(C=>{const k=!C;return ye(E.FLAT_INSPECTOR_OPEN,k),k})},i=()=>{he(!1),Ae(!1),ye(E.FLAT_INSPECTOR_OPEN,!1)},g=()=>he(!1),x=()=>{Ae(!1),ye(E.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",s),window.addEventListener("tide-close-flat-side-views",i),window.addEventListener("tide-close-flat-agents-drawer-only",g),window.addEventListener("tide-close-flat-inspector-only",x),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",s),window.removeEventListener("tide-close-flat-side-views",i),window.removeEventListener("tide-close-flat-agents-drawer-only",g),window.removeEventListener("tide-close-flat-inspector-only",x)}},[]);const ge=a.useRef(null),Se=a.useRef(null),[ue,xe]=a.useState(()=>{const t=Kt(E.FLAT_MIDDLE_WIDTH,0);return t>=Nt?t:null}),[pe,be]=a.useState(()=>{const t=Kt(E.FLAT_INSPECTOR_WIDTH,0);return t>=Bt?t:null}),Ee=a.useCallback(t=>{if(typeof window>"u")return t;const s=pe!==null?Ct+pe:0,i=window.innerWidth-nn-Ct-tn-s;return Math.max(Nt,Math.min(Math.max(i,Nt),t))},[pe]),_e=a.useCallback(t=>{var x;if(typeof window>"u")return t;const s=(x=ge.current)==null?void 0:x.querySelector(".flat-middle"),i=(s==null?void 0:s.getBoundingClientRect().width)??Nt,g=window.innerWidth-nn-i-Ct-tn-Ct;return Math.max(Bt,Math.min(Math.max(g,Bt),t))},[]);a.useEffect(()=>{if(ue===null&&pe===null)return;const t=()=>{xe(s=>{if(s===null)return s;const i=Ee(s);return i===s?s:i}),be(s=>{if(s===null)return s;const i=_e(s);return i===s?s:i})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[ue,pe,Ee,_e]);const tt=a.useCallback(t=>{var i;if(t.button!==0)return;const s=(i=ge.current)==null?void 0:i.querySelector(".flat-middle");s&&(t.currentTarget.setPointerCapture(t.pointerId),Se.current={kind:"middle",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),j=a.useCallback(t=>{var i;if(t.button!==0)return;const s=(i=ge.current)==null?void 0:i.querySelector(".flat-inspector");s&&(t.currentTarget.setPointerCapture(t.pointerId),Se.current={kind:"inspector",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),we=a.useCallback(t=>{const s=Se.current;if(!s||t.pointerId!==s.pointerId)return;const i=t.clientX-s.startX;s.kind==="middle"?xe(Ee(s.startWidth+i)):be(_e(s.startWidth-i))},[Ee,_e]),B=a.useCallback(t=>{const s=Se.current;if(!s||t.pointerId!==s.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(Se.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-s.startX)>2))return;const g=t.clientX-s.startX;if(s.kind==="middle"){const x=Ee(s.startWidth+g);xe(x),jt(E.FLAT_MIDDLE_WIDTH,x)}else{const x=_e(s.startWidth-g);be(x),jt(E.FLAT_INSPECTOR_WIDTH,x)}},[Ee,_e]),ut=a.useCallback(()=>{xe(null),jt(E.FLAT_MIDDLE_WIDTH,0)},[]),Ie=a.useCallback(()=>{be(null),jt(E.FLAT_INSPECTOR_WIDTH,0)},[]),[ve,yt]=a.useState(()=>qt(E.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),D=a.useCallback(t=>{yt(t),Yt(E.FLAT_INSPECTOR_VIEW,t)},[]),Re=a.useCallback(()=>{Ae(t=>{const s=!t;return ye(E.FLAT_INSPECTOR_OPEN,s),s})},[]),oe=a.useCallback(()=>{Ae(!1),ye(E.FLAT_INSPECTOR_OPEN,!1)},[]),kt=Sn(),At=a.useCallback((t,s)=>{U({url:t,name:s})},[]),St=a.useCallback((t,s)=>{te({command:t,output:s,isLive:!1})},[]),Et=a.useCallback((t,s)=>{var x;const i=O.size>0?Array.from(O)[0]:null,g=i?(x=f.getState().agents.get(i))==null?void 0:x.cwd:void 0;f.setFileViewerPath(t,s,g)},[O]),$e=a.useCallback(t=>{Be(t)},[]),pt=a.useCallback((t,s)=>{ct({agentId:t,count:s})},[]),je=a.useCallback(t=>{m?m(t):o(t)},[o,m]),v=a.useMemo(()=>O.size>0?Array.from(O)[0]:null,[O]);a.useEffect(()=>{Qe(!1)},[v]);const Z=a.useRef([]),ne=a.useRef(-1),Ve=a.useRef(!1),mt=a.useRef(null),[It,Mt]=a.useState(!1),[Tt,Pt]=a.useState(!1),nt=a.useRef(!1),ae=a.useRef(null),Xe=a.useRef(!1),se=a.useMemo(()=>new Set(_.map(t=>t.id)),[_]),Me=a.useMemo(()=>{const t=new Map(_.map(i=>[i.id,i])),s=new Map;for(const i of _)if((i.isBoss||i.class==="boss")&&i.subordinateIds&&i.subordinateIds.length>0){const g=i.subordinateIds.map(x=>t.get(x)).filter(x=>x!==void 0);g.length>0&&s.set(i.id,g)}return s},[_]),J=a.useCallback(()=>{const t=Z.current,s=ne.current;Mt(s>0),Pt(s>=0&&s<t.length-1)},[]),V=a.useCallback(t=>{const s=Z.current;if(s.length===0)return;let i=ne.current+t;for(;i>=0&&i<s.length;){const g=s[i];if(se.has(g)){Ve.current=!0,ne.current=i,J(),f.selectAgent(g);return}i+=t}},[se,J]),at=a.useCallback(()=>V(-1),[V]),ft=a.useCallback(()=>V(1),[V]);_a(a.useCallback(()=>{const t=Z.current,s=ne.current;return t.length>0&&s>0?(V(-1),"handled"):"exit"},[V]));const Ge=a.useCallback((t,s)=>{if(typeof window>"u")return;const i=window.history.state,x={...typeof i=="object"&&i!==null?i:{},__flatAgentNav:{agentId:t}};s==="replace"?window.history.replaceState(x,"",window.location.href):window.history.pushState(x,"",window.location.href)},[]);a.useEffect(()=>{if(!v){nt.current=!1,ae.current=null;return}if(!nt.current){Ge(v,"replace"),nt.current=!0,ae.current=v;return}if(Xe.current){Xe.current=!1,ae.current=v;return}ae.current!==v&&(Ge(v,"push"),ae.current=v)},[v,Ge]),a.useEffect(()=>{const t=s=>{var C,k;const i=(k=(C=s.state)==null?void 0:C.__flatAgentNav)==null?void 0:k.agentId;if(!i||typeof i!="string"||!se.has(i)||i===v)return;Xe.current=!0,Ve.current=!0;const g=Z.current,x=g.lastIndexOf(i);x>=0?ne.current=x:(g.push(i),ne.current=g.length-1),J(),f.selectAgent(i)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[se,v,J]),a.useEffect(()=>{if(!v){Z.current=[],ne.current=-1,J();return}if(mt.current=v,Ve.current){Ve.current=!1,J();return}const t=Z.current,s=ne.current;if(s>=0&&t[s]===v){J();return}const i=s<t.length-1?t.slice(0,s+1):t.slice();i.push(v),i.length>100&&i.shift(),Z.current=i,ne.current=i.length-1,J()},[v,J]);const ht=a.useCallback(t=>{u(t),he(!1)},[u]),Te=v??"",gt=a.useCallback(()=>{},[]),Lt=a.useCallback(t=>{ht(t)},[ht]),ce=ke,[De,qe]=a.useState(ce),[Ce,st]=a.useState(ce);a.useEffect(()=>{if(ce){qe(!0);return}st(!1);const t=setTimeout(()=>qe(!1),240);return()=>clearTimeout(t)},[ce]),a.useEffect(()=>{if(!De||!ce)return;let t=0;const s=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>st(!0))});return()=>{cancelAnimationFrame(s),cancelAnimationFrame(t)}},[De,ce]);const ze=a.useRef(null);a.useEffect(()=>{if(v)return;const t=s=>{if(s.key!==" "&&s.key!=="Backspace")return;const i=s.target;if(i.tagName==="INPUT"||i.tagName==="TEXTAREA"||i.isContentEditable)return;const g=mt.current;!g||!se.has(g)||(s.preventDefault(),f.selectAgent(g))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[v,se]);const[Rt,it]=a.useState(new Set),xt=a.useCallback(t=>{it(s=>{const i=new Set(s);return i.has(t)?i.delete(t):i.add(t),i})},[]),[n,r]=a.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),s=i=>r(i.matches);return t.addEventListener("change",s),()=>t.removeEventListener("change",s)},[]);const[l,d]=a.useState(null),X=a.useCallback(t=>{d(s=>s===t?null:t)},[]),Q=on(),I=cn(),[Ye]=En(),Ne=a.useMemo(()=>{const t=new Map,s=[];for(const w of _){const S=f.getAreaForAgent(w.id);if(!Zt((S==null?void 0:S.id)??null))continue;if(!S||S.archived){s.push(w);continue}const M=t.get(S.id);M?M.push(w):t.set(S.id,[w])}const i=new Map,g=[];for(const w of I.values()){let S=!1;for(const M of Q.values())if(!M.archived&&Jt(M.id)&&f.isPositionInArea(w.position,M)){const G=i.get(M.id);G?G.push(w):i.set(M.id,[w]),S=!0;break}!S&&Zt(null)&&g.push(w)}const x=[];for(const[,w]of Q){if(w.archived||!Jt(w.id))continue;const S=t.get(w.id),M=i.get(w.id)??[];(S&&S.length>0||M.length>0)&&x.push({area:w,agents:S??[],buildings:M})}(s.length>0||g.length>0)&&x.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:s,buildings:g});const C=x.filter(w=>w.area.id!=="__unassigned__"),k=x.filter(w=>w.area.id==="__unassigned__");let c=1,A=1;const H=new Map;if(C.length>1){let w=1/0,S=-1/0,M=1/0,G=-1/0;for(const q of C)w=Math.min(w,q.area.center.x),S=Math.max(S,q.area.center.x),M=Math.min(M,q.area.center.z),G=Math.max(G,q.area.center.z);const _t=S-w||1,wt=G-M||1;if(C.length<=4){c=C.length,A=1;const q=[...C].sort((Y,$t)=>Y.area.center.x-$t.area.center.x);for(let Y=0;Y<q.length;Y++)H.set(q[Y].area.id,{row:1,col:Y+1})}else{const q=[...C].sort((N,F)=>N.area.center.x-F.area.center.x),Y=[];for(let N=1;N<q.length;N++)Y.push(q[N].area.center.x-q[N-1].area.center.x);const $t=Y.reduce((N,F)=>N+F,0)/Y.length||1;let Ut=1;for(const N of Y)N>$t*1.3&&Ut++;c=Math.max(2,Math.min(Ut,C.length));const Dt=[...C].sort((N,F)=>N.area.center.z-F.area.center.z),vt=[];for(let N=1;N<Dt.length;N++)vt.push(Dt[N].area.center.z-Dt[N-1].area.center.z);const fn=vt.reduce((N,F)=>N+F,0)/vt.length||1;let Vt=1;for(const N of vt)N>fn*1.3&&Vt++;A=Math.max(2,Math.min(Vt,C.length)),c=Math.max(c,Math.ceil(C.length/A)),A=Math.max(A,Math.ceil(C.length/c));const hn=_t/c,gn=wt/A,zt=new Set;for(const N of C){let F=Math.min(c-1,Math.max(0,Math.floor((N.area.center.x-w)/hn))),Oe=Math.min(A-1,Math.max(0,Math.floor((N.area.center.z-M)/gn))),lt=`${Oe},${F}`,Xt=0;const xn=A*c;for(;zt.has(lt)&&Xt<xn;)F++,F>=c&&(F=0,Oe=(Oe+1)%A),lt=`${Oe},${F}`,Xt++;zt.has(lt)&&(Oe=A,F=0,lt=`${Oe},${F}`,A++),zt.add(lt),H.set(N.area.id,{row:Oe+1,col:F+1})}}}const L=w=>{w.sort((S,M)=>{var _t,wt,q,Y;const G=(((_t=S.position)==null?void 0:_t.z)??0)-(((wt=M.position)==null?void 0:wt.z)??0);return G!==0?G:(((q=S.position)==null?void 0:q.x)??0)-(((Y=M.position)==null?void 0:Y.x)??0)})};for(const w of C)L(w.agents);for(const w of k)L(w.agents);return{groups:[...C,...k],gridCols:c,gridRows:A,positions:H}},[_,Q,I,Ye]),bt=a.useMemo(()=>{if(!K)return[];const t=_.find(s=>s.id===K.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(p,{name:"chat",size:14}),onClick:()=>u(t.id)},{id:"clone-agent",label:"Clone Agent",icon:e.jsx(p,{name:"clipboard",size:14}),onClick:()=>f.cloneAgent(t.id)},{id:"fork-agent",label:"Fork Agent (with history)",icon:e.jsx(p,{name:"git-branch",size:14}),onClick:()=>f.forkAgent(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>{Fe({agentId:t.id,name:t.name})}}]:[]},[K,_,u]),ie=a.useMemo(()=>{var C;if(!T)return[];const t=I.get(T.buildingId);if(!t)return[];const s=[],i=t.type==="server"||t.type==="docker"||t.type==="terminal",g=t.status==="running",x=t.type==="boss";if(s.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="tests"?"Open Tests":t.type==="http"?"Open Requests":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((C=t.pm2)!=null&&C.enabled)?"View PM2 Logs":"Open",icon:e.jsx(p,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="tests"?"flask":t.type==="http"?"globe":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>je(t.id)}),i&&(g||s.push({id:"start",label:"Start",icon:e.jsx(p,{name:"play",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"start")}),g&&(s.push({id:"restart",label:"Restart",icon:e.jsx(p,{name:"refresh",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"restart")}),s.push({id:"stop",label:"Stop",icon:e.jsx(p,{name:"stop",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"stop")}))),x&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(s.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(p,{name:"launch",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)f.sendBuildingCommand(k,"start")}}),s.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(p,{name:"pause",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)f.sendBuildingCommand(k,"stop")}}),s.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(p,{name:"restart",size:14}),onClick:()=>{for(const k of t.subordinateBuildingIds)f.sendBuildingCommand(k,"restart")}})),i&&s.push({id:"health-check",label:"Health Check",icon:e.jsx(p,{name:"health",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"healthCheck")}),s.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),s.push({id:"edit",label:"Edit Building",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),s.push({id:"clone",label:"Clone Building",icon:e.jsx(p,{name:"copy",size:14}),onClick:()=>{f.createBuilding({name:`${t.name} (Copy)`,type:t.type,style:t.style,color:t.color,scale:t.scale,position:{x:t.position.x+2,z:t.position.z+2},cwd:t.cwd,folderPath:t.folderPath,commands:t.commands,pm2:t.pm2,docker:t.docker,database:t.database,terminal:t.terminal,urls:t.urls,subordinateBuildingIds:t.subordinateBuildingIds})}}),t.urls&&t.urls.length>0)for(const k of t.urls)s.push({id:`url-${k.label}`,label:k.label,icon:e.jsx(p,{name:"link",size:14}),onClick:()=>window.open(k.url,"_blank","noopener,noreferrer")});return s.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),s.push({id:"delete",label:"Delete Building",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>f.deleteBuilding(t.id)}),s},[T,I,je]),W=a.useCallback(t=>{const s=new Set(Ne.groups.map(i=>i.area.id));s.delete(t),it(s),requestAnimationFrame(()=>{const i=ze.current;if(!i)return;const g=i.querySelector(`[data-area-id="${t}"]`);if(!g)return;const x=i.getBoundingClientRect(),k=g.getBoundingClientRect().top-x.top+i.scrollTop-8;i.scrollTo({top:Math.max(0,k),behavior:"smooth"})})},[Ne]);return e.jsxs("div",{ref:ge,className:`flat-view ${ce?"flat-view--with-inspector":""} ${v?"flat-view--has-chat":""} ${fe?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(ue===null&&pe===null)return;const t={};return ue!==null&&(t["--flat-middle-width"]=`${ue}px`),pe!==null&&(t["--flat-inspector-width"]=`${pe}px`),t})(),children:[fe&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Ue,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children:e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:R,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:P,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:z,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(In,{activeAgentId:Te,onClose:gt,onSelectAgent:Lt,collapsedAreas:Rt,onToggleArea:xt,agentListRef:ze})})]}),e.jsx("div",{className:"flat-splitter flat-splitter--middle",role:"separator","aria-orientation":"vertical","aria-label":"Resize agents panel",title:"Drag to resize · Double-click to reset",onPointerDown:tt,onPointerMove:we,onPointerUp:B,onPointerCancel:B,onDoubleClick:ut}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":fe?"Close agents sidebar":"Open agents sidebar","aria-expanded":fe,onClick:He,children:[e.jsx(p,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),v?e.jsx(La,{agentId:v,terminalViewMode:me,onTerminalViewModeChange:et,inspectorOpen:ke,onToggleInspector:Re,onImageClick:At,onFileClick:Et,onBashClick:St,onViewMarkdown:$e,onRequestClearSubordinates:pt,keyboard:kt,canNavigateBack:It,canNavigateForward:Tt,onNavigateBack:at,onNavigateForward:ft,agentInfoOpen:Pe,onToggleAgentInfo:dt,onHeaderContextMenu:t=>{v&&b({agentId:v,position:t})},onBuildingContextMenu:(t,s)=>{Je({buildingId:t,position:s})}}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"}),e.jsx(ka,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Ne.gridCols}, 1fr)`},children:Ne.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var s;const t=n&&l?((s=Ne.positions.get(l))==null?void 0:s.row)??null:null;return Ne.groups.map(i=>{var k;const g=i.area.id,x=Ne.positions.get(g),C=n&&l!==g;return n&&t!=null&&(x==null?void 0:x.row)===t&&g!==l?null:e.jsxs("div",{className:`flat-map-area-card${C?" flat-map-area-card--collapsed":""}`,style:{"--area-color":i.area.color,gridRow:x==null?void 0:x.row,gridColumn:x==null?void 0:x.col},onContextMenu:c=>{y&&(c.preventDefault(),c.stopPropagation(),y(g,{x:c.clientX,y:c.clientY}))},children:[((k=i.area.logo)==null?void 0:k.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:ba(i.area.logo.filename),alt:"","aria-hidden":"true",onError:c=>{c.currentTarget.style.display="none"}}),e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>n?X(g):W(g),title:n?C?`Expand ${i.area.name}`:`Collapse ${i.area.name}`:`Focus ${i.area.name} in left panel`,"aria-expanded":n?!C:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:i.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:i.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:i.agents.length}),n&&e.jsx(p,{name:C?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:i.agents.map(c=>{const A=c.isBoss||c.class==="boss",H=A?Me.get(c.id):void 0,L=Mn(c),w=L.usedPercent>=80?"#ff4a4a":L.usedPercent>=60?"#ff9e4a":L.usedPercent>=40?"#ffd700":"#4aff9e",S=`Context: ${(L.totalTokens/1e3).toFixed(1)}k / ${(L.contextWindow/1e3).toFixed(1)}k (${L.usedPercent}% used, ${L.freePercent}% free)`,M=c.latestTodos&&c.latestTodos.length>0||H&&H.length>0;return e.jsx(Tn,{todos:c.latestTodos,subordinates:H,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${c.status}`,onClick:()=>u(c.id),onContextMenu:G=>{G.preventDefault(),G.stopPropagation(),b({agentId:c.id,position:{x:G.clientX,y:G.clientY}})},title:M?void 0:`${A?"Boss · ":""}Open chat with ${c.name}
|
|
2
2
|
${S}`,children:[e.jsx(dn,{agent:c,size:16}),A&&e.jsx("span",{className:"flat-map-agent-chip__crown","aria-hidden":"true",children:e.jsx(p,{name:"crown",size:11,color:"#ffd700",weight:"fill"})}),e.jsx("span",{className:"flat-map-agent-chip__name",children:c.name}),e.jsx("img",{src:c.provider==="codex"?"/assets/codex.png":c.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:c.provider,className:"flat-map-agent-chip__provider-icon",title:c.provider==="codex"?"Codex Agent":c.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:un(c.status)}}),c.latestTodos&&c.latestTodos.length>0&&e.jsx(Pn,{todos:c.latestTodos,maxDots:6}),A&&H&&H.length>0&&e.jsx(Ln,{subordinates:H,maxDots:6}),e.jsx("span",{className:"flat-map-agent-chip__context-bar","aria-hidden":"true",children:e.jsx("span",{className:"flat-map-agent-chip__context-bar-fill",style:{width:`${L.usedPercent}%`,backgroundColor:w}})})]})},c.id)})}),i.area.directories.length>0&&e.jsx("div",{className:"flat-map-area-card__folders",role:"group","aria-label":`${i.area.name} folders`,children:i.area.directories.map(c=>{const A=c.split("/").filter(Boolean).pop()||c;return e.jsxs("button",{type:"button",className:"flat-map-folder-chip",onClick:H=>{H.stopPropagation(),f.openFileExplorerForAreaFolder(g,c)},title:`Open in file explorer: ${c}`,children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-map-folder-chip__name",children:A})]},c)})}),i.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:i.buildings.map(c=>{var H;const A=(H=Rn[c.type])==null?void 0:H.color;return e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${c.status}`,style:A?{"--building-type-color":A}:void 0,onClick:L=>{if(h){const w=L.currentTarget.getBoundingClientRect();h(c.id,{x:w.right,y:w.top+w.height/2})}else je(c.id)},onContextMenu:L=>{L.preventDefault(),L.stopPropagation(),Je({buildingId:c.id,position:{x:L.clientX,y:L.clientY}})},title:`${c.name} · ${c.type} · ${c.status}`,children:[e.jsx(p,{name:$n(c.type),size:12,color:A}),e.jsx("span",{className:"flat-map-building-chip__name",children:c.name}),e.jsx("span",{className:"flat-map-building-chip__dot",style:{backgroundColor:Dn(c.status)}})]},c.id)})})]},g)})})()})]})})]}),ce&&e.jsx("div",{className:"flat-splitter flat-splitter--inspector",role:"separator","aria-orientation":"vertical","aria-label":"Resize inspector panel",title:"Drag to resize · Double-click to reset",onPointerDown:j,onPointerMove:we,onPointerUp:B,onPointerCancel:B,onDoubleClick:Ie}),De&&e.jsxs("aside",{className:`flat-inspector ${Ce?"flat-inspector--open":"flat-inspector--closing"}`,"aria-label":"Inspector panel",children:[e.jsxs("div",{className:"flat-inspector__header",children:[e.jsxs("div",{className:"flat-inspector__tabs",role:"tablist","aria-label":"Inspector view",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":ve==="agent",className:`flat-inspector__tab ${ve==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>D("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":ve==="tracking",className:`flat-inspector__tab ${ve==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>D("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:oe,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:ve==="tracking"?e.jsx(zn,{activeAgentId:v??"",onSelectAgent:t=>{u(t),window.innerWidth<=768&&oe()}}):(()=>{if(!v)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=_.find(s=>s.id===v);return t?e.jsx(On,{agent:t,onFocusAgent:s=>{u(s),window.innerWidth<=768&&oe()},onKillAgent:s=>f.killAgent(s)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),$&&e.jsx(Bn,{url:$.url,name:$.name,onClose:()=>U(null)}),ee&&e.jsx(Fn,{state:ee,onClose:()=>te(null)}),e.jsx(Wn,{agent:v?_.find(t=>t.id===v)??null:null,content:de,onClose:()=>Be(null)}),Ze&&e.jsx(Hn,{action:"clear-subordinates",selectedAgentId:Ze.agentId,subordinateCount:Ze.count,onClose:()=>ct(null),onClearHistory:()=>{}}),e.jsx(Un,{agent:v?_.find(t=>t.id===v)??null:null,isOpen:Pe&&!!v,onClose:We}),e.jsx(Qt,{isOpen:K!==null,position:(K==null?void 0:K.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:bt,onClose:()=>b(null)}),e.jsx(Qt,{isOpen:T!==null,position:(T==null?void 0:T.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:ie,onClose:()=>Je(null)}),e.jsx(Vn,{isOpen:re!==null,title:le("common:confirm.removeAgentTitle"),message:le("common:confirm.removeAgentMessage",{name:(re==null?void 0:re.name)??""}),confirmLabel:le("common:buttons.remove"),cancelLabel:le("common:buttons.cancel"),variant:"danger",onConfirm:()=>{re&&f.removeAgentFromServer(re.agentId)},onClose:()=>Fe(null)})]})}export{Oa as FlatView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as U,a as ee,r as l,s as u,j as e,D as oe,I as L,C as me,b as be,c as ue,d as he,g as _e,e as pe,Q as xe,R as fe}from"./main-BhpZ8DMy.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const je=({building:a,connections:j,activeConnectionId:d,activeDatabase:n,collapsed:y,onToggleCollapse:_,onConnectionChange:D,onDatabaseChange:R,onInsertTable:N,onSelectTableQuery:F})=>{const{t:x}=U(["terminal"]),f=ee(a.id),[I,G]=l.useState(new Set),[T,r]=l.useState(""),[i,g]=l.useState(""),[w,O]=l.useState(!1),[P,J]=l.useState(null),H=l.useRef(null),K=l.useRef(null),C=l.useRef(null),k=d?f.databases.get(d)??[]:[],q=d&&n?`${d}:${n}`:"",$=q?f.tables.get(q)??[]:[],h=d?f.connectionStatus.get(d):void 0,E=l.useMemo(()=>{if(!T.trim())return k;const t=T.toLowerCase();return k.filter(o=>o.toLowerCase().includes(t))},[k,T]),z=l.useMemo(()=>{if(!i.trim())return $;const t=i.toLowerCase();return $.filter(o=>o.name.toLowerCase().includes(t))},[$,i]);l.useEffect(()=>{const t=o=>{K.current&&!K.current.contains(o.target)&&O(!1)};return w&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[w]),l.useEffect(()=>{d&&!h&&u.testDatabaseConnection(a.id,d)},[a.id,d,h]),l.useEffect(()=>{d&&(h!=null&&h.connected)&&k.length===0&&u.listDatabases(a.id,d)},[a.id,d,h==null?void 0:h.connected,k.length]),l.useEffect(()=>{d&&n&&$.length===0&&u.listTables(a.id,d,n)},[a.id,d,n,$.length]),l.useEffect(()=>{J(null),g("")},[d,n]);const b=l.useCallback(t=>{G(o=>{const v=new Set(o);if(v.has(t))v.delete(t);else if(v.add(t),d&&n){const S=`${d}:${n}:${t}`;f.tableSchemas.has(S)||u.getTableSchema(a.id,d,n,t)}return v})},[a.id,d,n,f.tableSchemas]),p=t=>{if(!d||!n)return null;const o=`${d}:${n}:${t}`;return f.tableSchemas.get(o)};return y?e.jsx("div",{className:"database-sidebar database-sidebar--collapsed",children:e.jsx("button",{className:"database-sidebar__toggle",onClick:_,title:x("terminal:database.expandSidebar"),children:"»"})}):e.jsxs("div",{className:"database-sidebar",children:[e.jsxs("div",{className:"database-sidebar__header",children:[e.jsx("span",{children:x("terminal:database.explorer")}),e.jsx("button",{className:"database-sidebar__toggle",onClick:_,title:x("terminal:database.collapseSidebar"),children:"«"})]}),e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:x("terminal:database.connection")}),e.jsx("select",{className:"database-sidebar__select",value:d||"",onChange:t=>D(t.target.value),children:j.length===0?e.jsx("option",{value:"",children:x("terminal:database.noConnections")}):j.map(t=>{var o;return e.jsxs("option",{value:t.id,children:[((o=oe[t.engine])==null?void 0:o.icon)??"🗄️"," ",t.name]},t.id)})}),h&&e.jsx("div",{className:`database-sidebar__status ${h.connected?"database-sidebar__status--connected":"database-sidebar__status--error"}`,children:h.connected?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✓"}),x("terminal:database.connected"),h.serverVersion&&e.jsxs("span",{className:"database-sidebar__version",children:["(",h.serverVersion,")"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✗"}),h.error||x("terminal:database.disconnected")]})})]}),k.length>0&&e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:x("terminal:database.databaseTitle")}),e.jsxs("div",{className:"database-sidebar__searchable-select",ref:K,children:[e.jsx("input",{ref:H,className:"database-sidebar__search-input",type:"text",value:w?T:n||"",placeholder:x("terminal:database.selectDatabase"),onChange:t=>{r(t.target.value),w||O(!0)},onFocus:()=>{O(!0),r("")},onKeyDown:t=>{var o,v;t.key==="Escape"?(O(!1),r(""),(o=H.current)==null||o.blur()):t.key==="Enter"&&E.length===1&&(R(E[0]),O(!1),r(""),(v=H.current)==null||v.blur())}}),w&&e.jsx("div",{className:"database-sidebar__dropdown",children:E.length===0?e.jsx("div",{className:"database-sidebar__dropdown-empty",children:"No matches"}):E.map(t=>e.jsx("div",{className:`database-sidebar__dropdown-item ${t===n?"database-sidebar__dropdown-item--active":""}`,onMouseDown:o=>{o.preventDefault(),R(t),O(!1),r("")},children:t},t))})]})]}),$.length>0&&e.jsxs("div",{className:"database-sidebar__section database-sidebar__section--tables",children:[e.jsx("div",{className:"database-sidebar__section-title",children:i.trim()?x("terminal:database.tablesCount",{count:z.length})+` / ${$.length}`:x("terminal:database.tablesCount",{count:$.length})}),e.jsxs("div",{className:"database-sidebar__table-filter",children:[e.jsx("input",{ref:C,className:"database-sidebar__table-filter-input",type:"text",value:i,placeholder:x("terminal:database.filterTables"),onChange:t=>g(t.target.value),onKeyDown:t=>{var o;t.key==="Escape"&&(i?g(""):(o=C.current)==null||o.blur(),t.stopPropagation())}}),i&&e.jsx("button",{className:"database-sidebar__table-filter-clear",onClick:()=>{var t;g(""),(t=C.current)==null||t.focus()},title:"Clear filter",children:"×"})]}),e.jsxs("div",{className:"database-sidebar__tables",children:[i.trim()&&z.length===0&&e.jsx("div",{className:"database-sidebar__tables-empty",children:x("terminal:database.noTablesMatch")}),z.map(t=>{const o=I.has(t.name),v=o?p(t.name):null;return e.jsxs("div",{className:"database-sidebar__table",children:[e.jsxs("div",{className:"database-sidebar__table-header",children:[e.jsx("button",{className:"database-sidebar__table-expand",onClick:()=>b(t.name),title:o?"Collapse table schema":"Expand table schema",children:e.jsx(L,{name:o?"caret-down":"caret-right",size:10})}),e.jsx("span",{className:"database-sidebar__table-icon",children:e.jsx(L,{name:t.type==="view"?"eye":"clipboard",size:12})}),e.jsx("span",{className:`database-sidebar__table-name ${P===t.name?"database-sidebar__table-name--selected":""}`,onClick:()=>J(t.name),onDoubleClick:()=>{J(t.name),F(t.name)},children:t.name}),e.jsx("button",{className:"database-sidebar__table-insert",onClick:S=>{S.stopPropagation(),N(t.name)},title:x("terminal:database.insertTableName"),children:"+"})]}),o&&v&&e.jsx("div",{className:"database-sidebar__table-columns",children:v.columns.map(S=>e.jsxs("div",{className:"database-sidebar__column",onClick:()=>N(S.name),title:`${S.type}${S.nullable?" NULL":" NOT NULL"}${S.primaryKey?" PK":""}`,children:[e.jsx("span",{className:"database-sidebar__column-icon",children:S.primaryKey?e.jsx(L,{name:"key",size:11}):null}),e.jsx("span",{className:"database-sidebar__column-name",children:S.name}),e.jsx("span",{className:"database-sidebar__column-type",children:S.type})]},S.name))})]},t.name)})]})]})]})},ye=({buildingId:a,history:j,onLoadQuery:d})=>{const{t:n}=U(["terminal","common"]),[y,_]=l.useState(""),[D,R]=l.useState(!1),[N,F]=l.useState(!1),x=l.useMemo(()=>{let r=j;if(D&&(r=r.filter(i=>i.favorite)),y.trim()){const i=y.toLowerCase();r=r.filter(g=>g.query.toLowerCase().includes(i)||g.database.toLowerCase().includes(i))}return r},[j,D,y]),f=r=>{const i=new Date(r),w=new Date().getTime()-i.getTime();return w<1440*60*1e3?i.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):w<10080*60*1e3?i.toLocaleDateString([],{weekday:"short"})+" "+i.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):i.toLocaleDateString([],{month:"short",day:"numeric"})},I=l.useCallback((r,i)=>{i.stopPropagation(),u.toggleQueryFavorite(a,r)},[a]),G=l.useCallback((r,i)=>{i.stopPropagation(),u.deleteQueryFromHistory(a,r)},[a]),T=l.useCallback(()=>{F(!0)},[]);return j.length===0?e.jsxs("div",{className:"query-history query-history--empty",children:[e.jsx("p",{children:n("terminal:database.noHistory")}),e.jsx("p",{children:n("terminal:database.queriesAppearHere")})]}):e.jsxs("div",{className:"query-history",children:[e.jsxs("div",{className:"query-history__toolbar",children:[e.jsx("input",{type:"text",className:"query-history__search",placeholder:n("terminal:database.searchQueries"),value:y,onChange:r=>_(r.target.value)}),e.jsxs("label",{className:"query-history__filter",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:r=>R(r.target.checked)}),n("terminal:database.favoritesOnly")]}),e.jsx("button",{className:"query-history__clear",onClick:T,title:n("terminal:database.clearAll"),children:n("terminal:database.clearAll")})]}),e.jsxs("div",{className:"query-history__list",children:[x.map(r=>e.jsxs("div",{className:`query-history__item ${r.status==="error"?"query-history__item--error":""}`,onClick:()=>d(r.query),children:[e.jsxs("div",{className:"query-history__item-header",children:[e.jsx("span",{className:`query-history__status ${r.status==="success"?"query-history__status--success":"query-history__status--error"}`,children:e.jsx(L,{name:r.status==="success"?"check":"cross",size:12})}),e.jsx("span",{className:"query-history__database",children:r.database}),e.jsx("span",{className:"query-history__date",children:f(r.executedAt)}),e.jsxs("span",{className:"query-history__duration",children:[r.duration,"ms"]}),r.rowCount!==void 0&&e.jsx("span",{className:"query-history__row-count",children:n("terminal:database.rowCount",{count:r.rowCount})})]}),e.jsx("div",{className:"query-history__query",children:e.jsx("code",{children:r.query.length>200?r.query.substring(0,200)+"...":r.query})}),r.error&&e.jsx("div",{className:"query-history__error",children:r.error}),e.jsxs("div",{className:"query-history__actions",children:[e.jsx("button",{className:`query-history__favorite ${r.favorite?"query-history__favorite--active":""}`,onClick:i=>I(r.id,i),title:r.favorite?n("terminal:database.removeFromFavorites"):n("terminal:database.addToFavorites"),children:e.jsx(L,{name:"star",size:12,weight:r.favorite?"fill":"regular",color:r.favorite?"#facc15":void 0})}),e.jsx("button",{className:"query-history__delete",onClick:i=>G(r.id,i),title:n("terminal:database.deleteFromHistory"),children:e.jsx(L,{name:"trash",size:12})})]})]},r.id)),x.length===0&&e.jsx("div",{className:"query-history__no-results",children:n("terminal:database.noQueriesMatch")})]}),e.jsx(me,{isOpen:N,title:n("terminal:database.clearAll"),message:n("terminal:database.confirmClearHistory"),confirmLabel:n("terminal:database.clearAll"),cancelLabel:n("common:buttons.cancel"),variant:"danger",onConfirm:()=>u.clearQueryHistory(a),onClose:()=>F(!1)})]})},Ne=({tabs:a,activeTabId:j,onTabClick:d,onTabClose:n})=>{const{t:y}=U(["terminal"]);return e.jsx("div",{className:"database-tabs",children:a.map(_=>e.jsxs("div",{className:`database-tabs__tab ${j===_.id?"database-tabs__tab--active":""}`,children:[e.jsxs("button",{className:"database-tabs__tab-label",onClick:()=>d(_),title:`${_.connectionName} / ${_.database}`,children:[_.database,e.jsx("span",{className:"database-tabs__tab-connection",children:_.connectionName})]}),e.jsx("button",{className:"database-tabs__tab-close",onClick:()=>n(_.id),title:y("terminal:database.closeTab"),"aria-label":`Close ${_.database} tab`,children:"×"})]},_.id))})},ae=a=>`db-panel-${a}`;function ve(a){try{const j=localStorage.getItem(ae(a));return j?JSON.parse(j):{}}catch{return{}}}function Se(a,j){try{localStorage.setItem(ae(a),JSON.stringify(j))}catch{}}const we=({building:a,onClose:j,onMinimize:d})=>{var W,Y,X,Z;const{t:n}=U(["terminal","common"]),y=ee(a.id),_=be(a.id),D=ue(a.id),R=he(a.id),N=l.useRef(ve(a.id)),F=l.useRef(null),x=l.useRef(0),f=((W=a.database)==null?void 0:W.connections)??[],I=(s,c)=>`${s}:${c}`,G=s=>s?(N.current.queries??{})[s]??"":N.current.generalQuery??"",[T,r]=l.useState("results"),[i,g]=l.useState(0),[w,O]=l.useState(!1),[P,J]=l.useState(!1),[H,K]=l.useState(()=>(N.current.openTabs??[]).map(c=>{var m;return{id:`${c.connectionId}:${c.database}`,connectionId:c.connectionId,connectionName:((m=f.find(A=>A.id===c.connectionId))==null?void 0:m.name)??c.connectionId,database:c.database}})),[C,k]=l.useState(N.current.activeTabId??null),[q,$]=l.useState(()=>{const s=N.current.queries??{};return N.current.generalQuery,s}),[h,E]=l.useState(G(C)),z=l.useCallback(s=>{E(c=>{const m=typeof s=="function"?s(c):s;return $(A=>{const Q={...A};return C&&(Q[C]=m),Q}),m})},[C]),b=y.activeConnectionId??N.current.connectionId??((Y=a.database)==null?void 0:Y.activeConnectionId)??((X=f[0])==null?void 0:X.id),p=y.activeDatabase??N.current.database??((Z=a.database)==null?void 0:Z.activeDatabase),t=f.find(s=>s.id===b),o=b&&p?`${b}:${p}`:"",v=o?y.tables.get(o)??[]:[],S=l.useMemo(()=>{const s=new Map;return!b||!p||v.forEach(c=>{const m=y.tableSchemas.get(`${b}:${p}:${c.name}`);m&&s.set(c.name,{columns:m.columns})}),s},[b,p,v,y.tableSchemas]),V=l.useCallback((s,c)=>{var Q;const m=I(s,c),A=((Q=f.find(M=>M.id===s))==null?void 0:Q.name)??s;K(M=>{if(M.some(de=>de.id===m))return M;const ie={id:m,connectionId:s,connectionName:A,database:c};return[...M,ie]}),k(m),E(q[m]??""),u.setActiveConnection(a.id,s),u.setActiveDatabase(a.id,c)},[a.id,f,q]),se=l.useCallback(s=>{K(c=>c.filter(m=>m.id!==s)),C===s&&K(c=>{if(c.length>0){const m=c[0];k(m.id),E(q[m.id]??""),u.setActiveConnection(a.id,m.connectionId),u.setActiveDatabase(a.id,m.database)}else k(null),E("");return c})},[C,a.id,q]),te=l.useCallback(s=>{k(s.id),E(q[s.id]??""),u.setActiveConnection(a.id,s.connectionId),u.setActiveDatabase(a.id,s.database)},[a.id,q]);l.useEffect(()=>{if(!P&&f.length>0){const s=N.current;s.connectionId&&f.some(c=>c.id===s.connectionId)&&(u.setActiveConnection(a.id,s.connectionId),u.listDatabases(a.id,s.connectionId),s.database&&(u.setActiveDatabase(a.id,s.database),u.listTables(a.id,s.connectionId,s.database))),J(!0)}},[a.id,f,P]),l.useEffect(()=>{u.requestQueryHistory(a.id)},[a.id]),l.useEffect(()=>{const s=c=>{c.key==="Escape"&&(c.preventDefault(),c.stopPropagation(),j())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[j]),l.useEffect(()=>{P&&b&&Se(a.id,{connectionId:b,database:p,lastQuery:h,queries:q,generalQuery:"",openTabs:H.map(s=>({connectionId:s.connectionId,database:s.database})),activeTabId:C??void 0})},[a.id,b,p,h,P,H,C,q]);const ne=l.useCallback(s=>{var c;if(!(!b||!p||!h.trim()||R))if(s==="cursor"){const m=(c=F.current)==null?void 0:c.querySelector(".query-editor__textarea"),A=(m==null?void 0:m.selectionStart)??x.current,Q=_e(h,A);Q&&u.executeQuery(a.id,b,p,Q)}else{const m=pe(h);if(m.length<=1)u.executeQuery(a.id,b,p,h.trim());else{const A=b,Q=p;(async()=>{for(const M of m)await u.executeQueryAndWait(a.id,A,Q,M.sql)})()}}},[a.id,b,p,h,R]),re=l.useCallback(s=>{z(s),r("results")},[]),le=l.useCallback(s=>{u.setActiveConnection(a.id,s),u.listDatabases(a.id,s)},[a.id]),ce=l.useCallback(s=>{b&&(V(b,s),u.listTables(a.id,b,s))},[a.id,b,V]),B=_[i];return f.length===0?e.jsxs("div",{className:"database-panel",ref:F,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:e.jsx(L,{name:"database",size:16})}),e.jsx("span",{className:"database-panel__name",children:a.name})]}),e.jsx("button",{className:"database-panel__close",onClick:j,children:"×"})]}),e.jsx("div",{className:"database-panel__body",children:e.jsxs("div",{className:"database-panel__no-connections",children:[e.jsx("div",{className:"database-panel__no-connections-icon",children:e.jsx(L,{name:"plug",size:32})}),e.jsx("h3",{children:n("terminal:database.noConnections")}),e.jsx("p",{children:n("terminal:database.noConnectionsDesc")}),e.jsx("p",{children:n("terminal:database.toGetStarted")}),e.jsxs("ol",{children:[e.jsx("li",{children:n("terminal:database.step1Close")}),e.jsx("li",{children:n("terminal:database.step2Settings")}),e.jsx("li",{children:n("terminal:database.step3AddConnection")}),e.jsx("li",{children:n("terminal:database.step4Reopen")})]})]})})]}):e.jsxs("div",{className:"database-panel",ref:F,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:(t==null?void 0:t.engine)==="mysql"?"🐬":"🐘"}),e.jsx("span",{className:"database-panel__name",children:a.name}),t&&e.jsxs("span",{className:"database-panel__connection-info",children:[t.name," / ",p||n("terminal:database.noDatabaseSelected")]})]}),e.jsxs("div",{className:"database-panel__header-actions",children:[d&&e.jsx("button",{className:"database-panel__close",onClick:d,title:"Minimize — dock below the terminal input",children:e.jsx(L,{name:"arrow-down",size:14})}),e.jsx("button",{className:"database-panel__close",onClick:j,children:"×"})]})]}),e.jsxs("div",{className:"database-panel__body",children:[e.jsx(je,{building:a,connections:f,activeConnectionId:b,activeDatabase:p,collapsed:w,onToggleCollapse:()=>O(!w),onConnectionChange:le,onDatabaseChange:ce,onInsertTable:s=>z(c=>c+` ${s}`),onSelectTableQuery:s=>{const c=`SELECT * FROM ${s}`;z(c),b&&p&&u.executeQuery(a.id,b,p,c)}}),e.jsxs("div",{className:"database-panel__main",children:[H.length>0&&e.jsx(Ne,{tabs:H,activeTabId:C,onTabClick:te,onTabClose:se}),e.jsx(xe,{query:h,onChange:z,onExecute:ne,isExecuting:R,disabled:!b||!p,tables:v,tableSchemas:S,onRequestTableSchema:s=>{b&&p&&u.getTableSchema(a.id,b,p,s)}}),e.jsxs("div",{className:"database-panel__tabs",children:[e.jsxs("button",{className:`database-panel__tab ${T==="results"?"database-panel__tab--active":""}`,onClick:()=>r("results"),children:[n("terminal:database.results"),_.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:_.length})]}),e.jsxs("button",{className:`database-panel__tab ${T==="history"?"database-panel__tab--active":""}`,onClick:()=>r("history"),children:[n("terminal:database.history"),D.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:D.length})]}),T==="results"&&_.length>1&&e.jsxs("div",{className:"database-panel__result-nav",children:[e.jsxs("button",{disabled:i>=_.length-1,onClick:()=>g(s=>s+1),children:["← ",n("terminal:database.older")]}),e.jsxs("span",{children:[i+1," / ",_.length]}),e.jsxs("button",{disabled:i<=0,onClick:()=>g(s=>s-1),children:[n("terminal:database.newer")," →"]})]})]}),e.jsx("div",{className:"database-panel__tab-content",children:T==="results"?B?e.jsx(fe,{result:B,buildingId:a.id,building:a}):e.jsxs("div",{className:"database-panel__empty",children:[e.jsx("p",{children:n("terminal:database.noResultsYet")}),e.jsx("p",{children:n("terminal:database.selectDbAndRun")})]}):e.jsx(ye,{buildingId:a.id,history:D,onLoadQuery:re})})]})]})]})};export{we as DatabasePanel,je as DatabaseSidebar,Ne as DatabaseTabs,xe as QueryEditor,ye as QueryHistoryPanel,fe as ResultsTable};
|
|
1
|
+
import{u as U,a as ee,r as l,s as u,j as e,D as oe,I as L,C as me,b as be,c as ue,d as he,g as _e,e as pe,Q as xe,R as fe}from"./main-Bp6V_-sL.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const je=({building:a,connections:j,activeConnectionId:d,activeDatabase:n,collapsed:y,onToggleCollapse:_,onConnectionChange:D,onDatabaseChange:R,onInsertTable:N,onSelectTableQuery:F})=>{const{t:x}=U(["terminal"]),f=ee(a.id),[I,G]=l.useState(new Set),[T,r]=l.useState(""),[i,g]=l.useState(""),[w,O]=l.useState(!1),[P,J]=l.useState(null),H=l.useRef(null),K=l.useRef(null),C=l.useRef(null),k=d?f.databases.get(d)??[]:[],q=d&&n?`${d}:${n}`:"",$=q?f.tables.get(q)??[]:[],h=d?f.connectionStatus.get(d):void 0,E=l.useMemo(()=>{if(!T.trim())return k;const t=T.toLowerCase();return k.filter(o=>o.toLowerCase().includes(t))},[k,T]),z=l.useMemo(()=>{if(!i.trim())return $;const t=i.toLowerCase();return $.filter(o=>o.name.toLowerCase().includes(t))},[$,i]);l.useEffect(()=>{const t=o=>{K.current&&!K.current.contains(o.target)&&O(!1)};return w&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[w]),l.useEffect(()=>{d&&!h&&u.testDatabaseConnection(a.id,d)},[a.id,d,h]),l.useEffect(()=>{d&&(h!=null&&h.connected)&&k.length===0&&u.listDatabases(a.id,d)},[a.id,d,h==null?void 0:h.connected,k.length]),l.useEffect(()=>{d&&n&&$.length===0&&u.listTables(a.id,d,n)},[a.id,d,n,$.length]),l.useEffect(()=>{J(null),g("")},[d,n]);const b=l.useCallback(t=>{G(o=>{const v=new Set(o);if(v.has(t))v.delete(t);else if(v.add(t),d&&n){const S=`${d}:${n}:${t}`;f.tableSchemas.has(S)||u.getTableSchema(a.id,d,n,t)}return v})},[a.id,d,n,f.tableSchemas]),p=t=>{if(!d||!n)return null;const o=`${d}:${n}:${t}`;return f.tableSchemas.get(o)};return y?e.jsx("div",{className:"database-sidebar database-sidebar--collapsed",children:e.jsx("button",{className:"database-sidebar__toggle",onClick:_,title:x("terminal:database.expandSidebar"),children:"»"})}):e.jsxs("div",{className:"database-sidebar",children:[e.jsxs("div",{className:"database-sidebar__header",children:[e.jsx("span",{children:x("terminal:database.explorer")}),e.jsx("button",{className:"database-sidebar__toggle",onClick:_,title:x("terminal:database.collapseSidebar"),children:"«"})]}),e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:x("terminal:database.connection")}),e.jsx("select",{className:"database-sidebar__select",value:d||"",onChange:t=>D(t.target.value),children:j.length===0?e.jsx("option",{value:"",children:x("terminal:database.noConnections")}):j.map(t=>{var o;return e.jsxs("option",{value:t.id,children:[((o=oe[t.engine])==null?void 0:o.icon)??"🗄️"," ",t.name]},t.id)})}),h&&e.jsx("div",{className:`database-sidebar__status ${h.connected?"database-sidebar__status--connected":"database-sidebar__status--error"}`,children:h.connected?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✓"}),x("terminal:database.connected"),h.serverVersion&&e.jsxs("span",{className:"database-sidebar__version",children:["(",h.serverVersion,")"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✗"}),h.error||x("terminal:database.disconnected")]})})]}),k.length>0&&e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:x("terminal:database.databaseTitle")}),e.jsxs("div",{className:"database-sidebar__searchable-select",ref:K,children:[e.jsx("input",{ref:H,className:"database-sidebar__search-input",type:"text",value:w?T:n||"",placeholder:x("terminal:database.selectDatabase"),onChange:t=>{r(t.target.value),w||O(!0)},onFocus:()=>{O(!0),r("")},onKeyDown:t=>{var o,v;t.key==="Escape"?(O(!1),r(""),(o=H.current)==null||o.blur()):t.key==="Enter"&&E.length===1&&(R(E[0]),O(!1),r(""),(v=H.current)==null||v.blur())}}),w&&e.jsx("div",{className:"database-sidebar__dropdown",children:E.length===0?e.jsx("div",{className:"database-sidebar__dropdown-empty",children:"No matches"}):E.map(t=>e.jsx("div",{className:`database-sidebar__dropdown-item ${t===n?"database-sidebar__dropdown-item--active":""}`,onMouseDown:o=>{o.preventDefault(),R(t),O(!1),r("")},children:t},t))})]})]}),$.length>0&&e.jsxs("div",{className:"database-sidebar__section database-sidebar__section--tables",children:[e.jsx("div",{className:"database-sidebar__section-title",children:i.trim()?x("terminal:database.tablesCount",{count:z.length})+` / ${$.length}`:x("terminal:database.tablesCount",{count:$.length})}),e.jsxs("div",{className:"database-sidebar__table-filter",children:[e.jsx("input",{ref:C,className:"database-sidebar__table-filter-input",type:"text",value:i,placeholder:x("terminal:database.filterTables"),onChange:t=>g(t.target.value),onKeyDown:t=>{var o;t.key==="Escape"&&(i?g(""):(o=C.current)==null||o.blur(),t.stopPropagation())}}),i&&e.jsx("button",{className:"database-sidebar__table-filter-clear",onClick:()=>{var t;g(""),(t=C.current)==null||t.focus()},title:"Clear filter",children:"×"})]}),e.jsxs("div",{className:"database-sidebar__tables",children:[i.trim()&&z.length===0&&e.jsx("div",{className:"database-sidebar__tables-empty",children:x("terminal:database.noTablesMatch")}),z.map(t=>{const o=I.has(t.name),v=o?p(t.name):null;return e.jsxs("div",{className:"database-sidebar__table",children:[e.jsxs("div",{className:"database-sidebar__table-header",children:[e.jsx("button",{className:"database-sidebar__table-expand",onClick:()=>b(t.name),title:o?"Collapse table schema":"Expand table schema",children:e.jsx(L,{name:o?"caret-down":"caret-right",size:10})}),e.jsx("span",{className:"database-sidebar__table-icon",children:e.jsx(L,{name:t.type==="view"?"eye":"clipboard",size:12})}),e.jsx("span",{className:`database-sidebar__table-name ${P===t.name?"database-sidebar__table-name--selected":""}`,onClick:()=>J(t.name),onDoubleClick:()=>{J(t.name),F(t.name)},children:t.name}),e.jsx("button",{className:"database-sidebar__table-insert",onClick:S=>{S.stopPropagation(),N(t.name)},title:x("terminal:database.insertTableName"),children:"+"})]}),o&&v&&e.jsx("div",{className:"database-sidebar__table-columns",children:v.columns.map(S=>e.jsxs("div",{className:"database-sidebar__column",onClick:()=>N(S.name),title:`${S.type}${S.nullable?" NULL":" NOT NULL"}${S.primaryKey?" PK":""}`,children:[e.jsx("span",{className:"database-sidebar__column-icon",children:S.primaryKey?e.jsx(L,{name:"key",size:11}):null}),e.jsx("span",{className:"database-sidebar__column-name",children:S.name}),e.jsx("span",{className:"database-sidebar__column-type",children:S.type})]},S.name))})]},t.name)})]})]})]})},ye=({buildingId:a,history:j,onLoadQuery:d})=>{const{t:n}=U(["terminal","common"]),[y,_]=l.useState(""),[D,R]=l.useState(!1),[N,F]=l.useState(!1),x=l.useMemo(()=>{let r=j;if(D&&(r=r.filter(i=>i.favorite)),y.trim()){const i=y.toLowerCase();r=r.filter(g=>g.query.toLowerCase().includes(i)||g.database.toLowerCase().includes(i))}return r},[j,D,y]),f=r=>{const i=new Date(r),w=new Date().getTime()-i.getTime();return w<1440*60*1e3?i.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):w<10080*60*1e3?i.toLocaleDateString([],{weekday:"short"})+" "+i.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):i.toLocaleDateString([],{month:"short",day:"numeric"})},I=l.useCallback((r,i)=>{i.stopPropagation(),u.toggleQueryFavorite(a,r)},[a]),G=l.useCallback((r,i)=>{i.stopPropagation(),u.deleteQueryFromHistory(a,r)},[a]),T=l.useCallback(()=>{F(!0)},[]);return j.length===0?e.jsxs("div",{className:"query-history query-history--empty",children:[e.jsx("p",{children:n("terminal:database.noHistory")}),e.jsx("p",{children:n("terminal:database.queriesAppearHere")})]}):e.jsxs("div",{className:"query-history",children:[e.jsxs("div",{className:"query-history__toolbar",children:[e.jsx("input",{type:"text",className:"query-history__search",placeholder:n("terminal:database.searchQueries"),value:y,onChange:r=>_(r.target.value)}),e.jsxs("label",{className:"query-history__filter",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:r=>R(r.target.checked)}),n("terminal:database.favoritesOnly")]}),e.jsx("button",{className:"query-history__clear",onClick:T,title:n("terminal:database.clearAll"),children:n("terminal:database.clearAll")})]}),e.jsxs("div",{className:"query-history__list",children:[x.map(r=>e.jsxs("div",{className:`query-history__item ${r.status==="error"?"query-history__item--error":""}`,onClick:()=>d(r.query),children:[e.jsxs("div",{className:"query-history__item-header",children:[e.jsx("span",{className:`query-history__status ${r.status==="success"?"query-history__status--success":"query-history__status--error"}`,children:e.jsx(L,{name:r.status==="success"?"check":"cross",size:12})}),e.jsx("span",{className:"query-history__database",children:r.database}),e.jsx("span",{className:"query-history__date",children:f(r.executedAt)}),e.jsxs("span",{className:"query-history__duration",children:[r.duration,"ms"]}),r.rowCount!==void 0&&e.jsx("span",{className:"query-history__row-count",children:n("terminal:database.rowCount",{count:r.rowCount})})]}),e.jsx("div",{className:"query-history__query",children:e.jsx("code",{children:r.query.length>200?r.query.substring(0,200)+"...":r.query})}),r.error&&e.jsx("div",{className:"query-history__error",children:r.error}),e.jsxs("div",{className:"query-history__actions",children:[e.jsx("button",{className:`query-history__favorite ${r.favorite?"query-history__favorite--active":""}`,onClick:i=>I(r.id,i),title:r.favorite?n("terminal:database.removeFromFavorites"):n("terminal:database.addToFavorites"),children:e.jsx(L,{name:"star",size:12,weight:r.favorite?"fill":"regular",color:r.favorite?"#facc15":void 0})}),e.jsx("button",{className:"query-history__delete",onClick:i=>G(r.id,i),title:n("terminal:database.deleteFromHistory"),children:e.jsx(L,{name:"trash",size:12})})]})]},r.id)),x.length===0&&e.jsx("div",{className:"query-history__no-results",children:n("terminal:database.noQueriesMatch")})]}),e.jsx(me,{isOpen:N,title:n("terminal:database.clearAll"),message:n("terminal:database.confirmClearHistory"),confirmLabel:n("terminal:database.clearAll"),cancelLabel:n("common:buttons.cancel"),variant:"danger",onConfirm:()=>u.clearQueryHistory(a),onClose:()=>F(!1)})]})},Ne=({tabs:a,activeTabId:j,onTabClick:d,onTabClose:n})=>{const{t:y}=U(["terminal"]);return e.jsx("div",{className:"database-tabs",children:a.map(_=>e.jsxs("div",{className:`database-tabs__tab ${j===_.id?"database-tabs__tab--active":""}`,children:[e.jsxs("button",{className:"database-tabs__tab-label",onClick:()=>d(_),title:`${_.connectionName} / ${_.database}`,children:[_.database,e.jsx("span",{className:"database-tabs__tab-connection",children:_.connectionName})]}),e.jsx("button",{className:"database-tabs__tab-close",onClick:()=>n(_.id),title:y("terminal:database.closeTab"),"aria-label":`Close ${_.database} tab`,children:"×"})]},_.id))})},ae=a=>`db-panel-${a}`;function ve(a){try{const j=localStorage.getItem(ae(a));return j?JSON.parse(j):{}}catch{return{}}}function Se(a,j){try{localStorage.setItem(ae(a),JSON.stringify(j))}catch{}}const we=({building:a,onClose:j,onMinimize:d})=>{var W,Y,X,Z;const{t:n}=U(["terminal","common"]),y=ee(a.id),_=be(a.id),D=ue(a.id),R=he(a.id),N=l.useRef(ve(a.id)),F=l.useRef(null),x=l.useRef(0),f=((W=a.database)==null?void 0:W.connections)??[],I=(s,c)=>`${s}:${c}`,G=s=>s?(N.current.queries??{})[s]??"":N.current.generalQuery??"",[T,r]=l.useState("results"),[i,g]=l.useState(0),[w,O]=l.useState(!1),[P,J]=l.useState(!1),[H,K]=l.useState(()=>(N.current.openTabs??[]).map(c=>{var m;return{id:`${c.connectionId}:${c.database}`,connectionId:c.connectionId,connectionName:((m=f.find(A=>A.id===c.connectionId))==null?void 0:m.name)??c.connectionId,database:c.database}})),[C,k]=l.useState(N.current.activeTabId??null),[q,$]=l.useState(()=>{const s=N.current.queries??{};return N.current.generalQuery,s}),[h,E]=l.useState(G(C)),z=l.useCallback(s=>{E(c=>{const m=typeof s=="function"?s(c):s;return $(A=>{const Q={...A};return C&&(Q[C]=m),Q}),m})},[C]),b=y.activeConnectionId??N.current.connectionId??((Y=a.database)==null?void 0:Y.activeConnectionId)??((X=f[0])==null?void 0:X.id),p=y.activeDatabase??N.current.database??((Z=a.database)==null?void 0:Z.activeDatabase),t=f.find(s=>s.id===b),o=b&&p?`${b}:${p}`:"",v=o?y.tables.get(o)??[]:[],S=l.useMemo(()=>{const s=new Map;return!b||!p||v.forEach(c=>{const m=y.tableSchemas.get(`${b}:${p}:${c.name}`);m&&s.set(c.name,{columns:m.columns})}),s},[b,p,v,y.tableSchemas]),V=l.useCallback((s,c)=>{var Q;const m=I(s,c),A=((Q=f.find(M=>M.id===s))==null?void 0:Q.name)??s;K(M=>{if(M.some(de=>de.id===m))return M;const ie={id:m,connectionId:s,connectionName:A,database:c};return[...M,ie]}),k(m),E(q[m]??""),u.setActiveConnection(a.id,s),u.setActiveDatabase(a.id,c)},[a.id,f,q]),se=l.useCallback(s=>{K(c=>c.filter(m=>m.id!==s)),C===s&&K(c=>{if(c.length>0){const m=c[0];k(m.id),E(q[m.id]??""),u.setActiveConnection(a.id,m.connectionId),u.setActiveDatabase(a.id,m.database)}else k(null),E("");return c})},[C,a.id,q]),te=l.useCallback(s=>{k(s.id),E(q[s.id]??""),u.setActiveConnection(a.id,s.connectionId),u.setActiveDatabase(a.id,s.database)},[a.id,q]);l.useEffect(()=>{if(!P&&f.length>0){const s=N.current;s.connectionId&&f.some(c=>c.id===s.connectionId)&&(u.setActiveConnection(a.id,s.connectionId),u.listDatabases(a.id,s.connectionId),s.database&&(u.setActiveDatabase(a.id,s.database),u.listTables(a.id,s.connectionId,s.database))),J(!0)}},[a.id,f,P]),l.useEffect(()=>{u.requestQueryHistory(a.id)},[a.id]),l.useEffect(()=>{const s=c=>{c.key==="Escape"&&(c.preventDefault(),c.stopPropagation(),j())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[j]),l.useEffect(()=>{P&&b&&Se(a.id,{connectionId:b,database:p,lastQuery:h,queries:q,generalQuery:"",openTabs:H.map(s=>({connectionId:s.connectionId,database:s.database})),activeTabId:C??void 0})},[a.id,b,p,h,P,H,C,q]);const ne=l.useCallback(s=>{var c;if(!(!b||!p||!h.trim()||R))if(s==="cursor"){const m=(c=F.current)==null?void 0:c.querySelector(".query-editor__textarea"),A=(m==null?void 0:m.selectionStart)??x.current,Q=_e(h,A);Q&&u.executeQuery(a.id,b,p,Q)}else{const m=pe(h);if(m.length<=1)u.executeQuery(a.id,b,p,h.trim());else{const A=b,Q=p;(async()=>{for(const M of m)await u.executeQueryAndWait(a.id,A,Q,M.sql)})()}}},[a.id,b,p,h,R]),re=l.useCallback(s=>{z(s),r("results")},[]),le=l.useCallback(s=>{u.setActiveConnection(a.id,s),u.listDatabases(a.id,s)},[a.id]),ce=l.useCallback(s=>{b&&(V(b,s),u.listTables(a.id,b,s))},[a.id,b,V]),B=_[i];return f.length===0?e.jsxs("div",{className:"database-panel",ref:F,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:e.jsx(L,{name:"database",size:16})}),e.jsx("span",{className:"database-panel__name",children:a.name})]}),e.jsx("button",{className:"database-panel__close",onClick:j,children:"×"})]}),e.jsx("div",{className:"database-panel__body",children:e.jsxs("div",{className:"database-panel__no-connections",children:[e.jsx("div",{className:"database-panel__no-connections-icon",children:e.jsx(L,{name:"plug",size:32})}),e.jsx("h3",{children:n("terminal:database.noConnections")}),e.jsx("p",{children:n("terminal:database.noConnectionsDesc")}),e.jsx("p",{children:n("terminal:database.toGetStarted")}),e.jsxs("ol",{children:[e.jsx("li",{children:n("terminal:database.step1Close")}),e.jsx("li",{children:n("terminal:database.step2Settings")}),e.jsx("li",{children:n("terminal:database.step3AddConnection")}),e.jsx("li",{children:n("terminal:database.step4Reopen")})]})]})})]}):e.jsxs("div",{className:"database-panel",ref:F,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:(t==null?void 0:t.engine)==="mysql"?"🐬":"🐘"}),e.jsx("span",{className:"database-panel__name",children:a.name}),t&&e.jsxs("span",{className:"database-panel__connection-info",children:[t.name," / ",p||n("terminal:database.noDatabaseSelected")]})]}),e.jsxs("div",{className:"database-panel__header-actions",children:[d&&e.jsx("button",{className:"database-panel__close",onClick:d,title:"Minimize — dock below the terminal input",children:e.jsx(L,{name:"arrow-down",size:14})}),e.jsx("button",{className:"database-panel__close",onClick:j,children:"×"})]})]}),e.jsxs("div",{className:"database-panel__body",children:[e.jsx(je,{building:a,connections:f,activeConnectionId:b,activeDatabase:p,collapsed:w,onToggleCollapse:()=>O(!w),onConnectionChange:le,onDatabaseChange:ce,onInsertTable:s=>z(c=>c+` ${s}`),onSelectTableQuery:s=>{const c=`SELECT * FROM ${s}`;z(c),b&&p&&u.executeQuery(a.id,b,p,c)}}),e.jsxs("div",{className:"database-panel__main",children:[H.length>0&&e.jsx(Ne,{tabs:H,activeTabId:C,onTabClick:te,onTabClose:se}),e.jsx(xe,{query:h,onChange:z,onExecute:ne,isExecuting:R,disabled:!b||!p,tables:v,tableSchemas:S,onRequestTableSchema:s=>{b&&p&&u.getTableSchema(a.id,b,p,s)}}),e.jsxs("div",{className:"database-panel__tabs",children:[e.jsxs("button",{className:`database-panel__tab ${T==="results"?"database-panel__tab--active":""}`,onClick:()=>r("results"),children:[n("terminal:database.results"),_.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:_.length})]}),e.jsxs("button",{className:`database-panel__tab ${T==="history"?"database-panel__tab--active":""}`,onClick:()=>r("history"),children:[n("terminal:database.history"),D.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:D.length})]}),T==="results"&&_.length>1&&e.jsxs("div",{className:"database-panel__result-nav",children:[e.jsxs("button",{disabled:i>=_.length-1,onClick:()=>g(s=>s+1),children:["← ",n("terminal:database.older")]}),e.jsxs("span",{children:[i+1," / ",_.length]}),e.jsxs("button",{disabled:i<=0,onClick:()=>g(s=>s-1),children:[n("terminal:database.newer")," →"]})]})]}),e.jsx("div",{className:"database-panel__tab-content",children:T==="results"?B?e.jsx(fe,{result:B,buildingId:a.id,building:a}):e.jsxs("div",{className:"database-panel__empty",children:[e.jsx("p",{children:n("terminal:database.noResultsYet")}),e.jsx("p",{children:n("terminal:database.selectDbAndRun")})]}):e.jsx(ye,{buildingId:a.id,history:D,onLoadQuery:re})})]})]})]})};export{we as DatabasePanel,je as DatabaseSidebar,Ne as DatabaseTabs,xe as QueryEditor,ye as QueryHistoryPanel,fe as ResultsTable};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{bM as He,r as t,s as I,i as ye,bN as Ee,h as _e,j as e,I as z,u as fe,bO as ze,W as Te,bP as Ue,bQ as Be,n as We,bR as Ke,bS as De,bT as Ve,ag as Ge,ah as qe,ai as Ye,bd as Je,X as Me,S as oe,b7 as Xe,b4 as Qe,a7 as Ze,Y as Ie,ay as et,a2 as tt,bU as st,o as X,bV as nt}from"./main-
|
|
1
|
+
import{bM as He,r as t,s as I,i as ye,bN as Ee,h as _e,j as e,I as z,u as fe,bO as ze,W as Te,bP as Ue,bQ as Be,n as We,bR as Ke,bS as De,bT as Ve,ag as Ge,ah as qe,ai as Ye,bd as Je,X as Me,S as oe,b7 as Xe,b4 as Qe,a7 as Ze,Y as Ie,ay as et,a2 as tt,bU as st,o as X,bV as nt}from"./main-Bp6V_-sL.js";import{FileExplorerPanel as at}from"./index-BD6swoQU.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Ne={status:"all",activity:"all",sort:"activity"},lt={"1h":3600*1e3,"6h":360*60*1e3,"24h":1440*60*1e3},Ae=20,me=3,ot={idle:"#4aff9e",working:"#4a9eff",waiting:"#ff9e4a",waiting_permission:"#ffcc00",error:"#ff4a4a",offline:"#888888",orphaned:"#ff9e4a"},ct=12e4;function rt(s){return s.trim().replace(/\r\n/g,`
|
|
2
2
|
`)}function $e(s,a){return`${s}:${rt(a)}`}function it(s,a,l,f){if(s.uuid&&a.has(s.uuid))return!1;if(s.uuid)return!0;const p=s.isUserPrompt?"user":"assistant",d=$e(p,s.text),M=s.timestamp||0,A=l.get(d);return A!==void 0&&Math.abs(M-A)<=ct?!1:M>f}function dt({isOpen:s,agents:a}){const l=He(),[f,p]=t.useState(new Map),d=t.useRef(new Set);t.useRef(a);const M=t.useMemo(()=>Array.from(a.keys()).sort().join(","),[a]),A=t.useMemo(()=>Array.from(a.values()).map(j=>`${j.id}:${j.sessionId||""}`).sort().join(","),[a]);t.useEffect(()=>{s||(d.current.clear(),p(new Map))},[s]),t.useEffect(()=>{if(!s)return;const j=new Set(Array.from(a.keys()));for(const i of d.current)j.has(i)||d.current.delete(i);let h=null;l>0&&(h=I.preserveOutputs(),d.current.clear());const v=async(i,C,F=0)=>{if(d.current.add(i.id),F>0&&await new Promise(x=>setTimeout(x,F)),p(x=>{const k=new Map(x);return k.set(i.id,{agentId:i.id,messages:[],loading:!0,hasMore:!1,totalCount:0}),k}),!i.sessionId){C&&C.length>0&&I.mergeOutputsWithHistory(i.id,[],C),p(x=>{const k=new Map(x);return k.set(i.id,{agentId:i.id,messages:[],loading:!1,hasMore:!1,totalCount:0}),k});return}try{const k=await(await _e(ye(`/api/agents/${i.id}/history?limit=${Ee}&offset=0`))).json(),P=k.messages||[],K=P.length>0?Math.max(...P.map(w=>w.timestamp?new Date(w.timestamp).getTime():0)):0,Y=new Set(P.map(w=>w.uuid).filter(w=>!!w)),V=new Map;for(const w of P){if(w.type!=="user"&&w.type!=="assistant")continue;const c=$e(w.type,w.content),L=w.timestamp?new Date(w.timestamp).getTime():0,W=V.get(c)??0;L>W&&V.set(c,L)}const G=I.getOutputs(i.id),B=(C&&C.length>0?[...C,...G]:G).filter(w=>it(w,Y,V,K));I.clearOutputs(i.id);for(const w of B)I.addOutput(i.id,w);p(w=>{const c=new Map(w);return c.set(i.id,{agentId:i.id,messages:P,loading:!1,hasMore:k.hasMore||!1,totalCount:k.totalCount||0}),c})}catch(x){if(console.error(`Failed to load history for ${i.name}:`,x),C&&C.length>0){I.clearOutputs(i.id);for(const k of C)I.addOutput(i.id,k)}p(k=>{const P=new Map(k);return P.set(i.id,{agentId:i.id,messages:[],loading:!1,hasMore:!1,totalCount:0}),P})}},u=l>0?500:0,D=Array.from(a.values());for(const i of D)if(!d.current.has(i.id)){const C=h==null?void 0:h.get(i.id);v(i,C,u)}},[s,M,A,l]);const R=t.useRef(a),N=t.useRef(f);R.current=a,N.current=f;const b=t.useCallback(async j=>{const h=R.current.get(j),v=N.current.get(j);if(!(h!=null&&h.sessionId)||!v||!v.hasMore)return;const u=v.messages.length;try{const i=await(await fetch(ye(`/api/agents/${j}/history?limit=${Ee}&offset=${u}`))).json();i.messages&&i.messages.length>0&&p(C=>{const F=new Map(C),x=C.get(j);return x&&F.set(j,{...x,messages:[...i.messages,...x.messages],hasMore:i.hasMore||!1}),F})}catch(D){console.error(`Failed to load more history for agent ${j}:`,D)}},[]),E=t.useCallback(j=>{d.current.delete(j),p(h=>{const v=new Map(h),u=h.get(j);return u&&v.set(j,{...u,messages:[],hasMore:!1,totalCount:0,loading:!1}),v})},[]);return{histories:f,loadMoreHistory:b,clearAgentHistory:E}}function ut({command:s,onCommandChange:a,useTextarea:l,forceTextarea:f,onForceTextarea:p,onSend:d,canSend:M,attachedFiles:A,onAddFile:R,onRemoveFile:N,uploadFile:b,onAddPastedText:E,placeholder:j="Message...",className:h="",compact:v=!1,inputRef:u}){const D=t.useRef(null),i=t.useRef(null),C=t.useRef(l);t.useEffect(()=>{if(l&&!C.current&&i.current){const c=i.current;c.focus(),c.selectionStart=c.selectionEnd=c.value.length}C.current=l},[l]),t.useEffect(()=>{const c=i.current;if(!c||!l)return;c.style.height="auto";const L=v?120:180,W=Math.min(c.scrollHeight,L);c.style.height=`${W}px`},[s,l,v]);const F=t.useCallback(async c=>{const L=c.clipboardData.items;for(const _ of L)if(_.type.startsWith("image/")){c.preventDefault();const $=_.getAsFile();if($){const O=await b($);O&&R(O)}return}const W=c.clipboardData.files;if(W.length>0){c.preventDefault();for(const _ of W){const $=await b(_);$&&R($)}return}const U=c.clipboardData.getData("text"),te=(U.match(/\n/g)||[]).length+1;if(te>5){c.preventDefault();const $=`[Pasted text #${E(U)} +${te} lines]`,O=c.target,se=O.selectionStart||0,ae=O.selectionEnd||0,ne=s.slice(0,se)+$+s.slice(ae);a(ne),l||p(!0)}},[s,a,l,p,b,R,E]),x=t.useCallback(async c=>{const L=c.target.files;if(L){for(const W of L){const U=await b(W);U&&R(U)}D.current&&(D.current.value="")}},[b,R]),k=t.useCallback(c=>{if(c.key==="Enter"&&c.shiftKey){l||(c.preventDefault(),p(!0));return}c.key==="Enter"&&(c.preventDefault(),d())},[l,p,d]),P=t.useCallback(c=>{},[]),K=t.useCallback(c=>{c.button===1&&(c.preventDefault(),c.stopPropagation())},[]),Y=t.useCallback(c=>{i.current=c,u==null||u(c)},[u]),V=v?"agent-panel-input":"guake-input",G=v?"agent-panel-input-container":"guake-input-container",Q=v?"agent-panel-attach-btn":"guake-attach-btn",B=v?"agent-panel-send-btn":"",w=l?v?"agent-panel-input-expanded":"guake-input-expanded":"";return e.jsxs(e.Fragment,{children:[A.length>0&&e.jsx("div",{className:v?"agent-panel-attachments":"guake-attachments",children:A.map(c=>e.jsxs("div",{className:`${v?"agent-panel-attachment":"guake-attachment"} ${c.isImage?"is-image":""}`,children:[e.jsx("span",{className:v?"agent-panel-attachment-icon":"guake-attachment-icon",children:e.jsx(z,{name:c.isImage?"file":"paperclip",size:12})}),e.jsx("span",{className:v?"agent-panel-attachment-name":"guake-attachment-name",title:c.path,children:c.name}),!v&&e.jsxs("span",{className:"guake-attachment-size",children:["(",Math.round(c.size/1024),"KB)"]}),e.jsx("button",{className:v?"agent-panel-attachment-remove":"guake-attachment-remove",onClick:()=>N(c.id),title:"Remove",children:"×"})]},c.id))}),e.jsxs("div",{className:`${V} ${w} ${h}`,children:[e.jsx("input",{ref:D,type:"file",multiple:!0,onChange:x,style:{display:"none"},accept:"*"}),e.jsxs("div",{className:G,onAuxClick:K,children:[e.jsx("button",{className:Q,onClick:()=>{var c;return(c=D.current)==null?void 0:c.click()},title:"Attach file (or paste image)",children:e.jsx(z,{name:"paperclip",size:14})}),l?e.jsx("textarea",{ref:Y,placeholder:j,value:s,onChange:c=>a(c.target.value),onKeyDown:k,onPaste:F,onMouseDown:P}):e.jsx("input",{ref:u,type:"text",placeholder:j,value:s,onChange:c=>a(c.target.value),onKeyDown:k,onPaste:F,onMouseDown:P}),e.jsx("button",{className:B,onClick:d,disabled:!M,title:"Send",children:e.jsx(z,{name:"send",size:14})})]})]})]})}function mt(s){const a=Math.floor(s/1e3),l=Math.floor(a/60),f=a%60;return`${l}:${f.toString().padStart(2,"0")}`}const ft=t.memo(function({agentId:a,isWorking:l,timestamp:f}){const{t:p}=fe(["terminal"]),[d,M]=t.useState(0);return t.useEffect(()=>{if(!l||!f){M(0);return}M(Date.now()-f);const A=setInterval(()=>{M(Date.now()-f)},1e3);return()=>clearInterval(A)},[l,f]),l?e.jsxs("div",{className:"guake-stop-bar",children:[e.jsx("span",{className:"guake-elapsed-timer",children:mt(d)}),e.jsxs("button",{className:"guake-stop-btn",onClick:()=>I.stopAgent(a),title:p("terminal:input.stopOperation"),children:[e.jsx("span",{className:"stop-icon",children:e.jsx(z,{name:"stop",size:12,weight:"fill"})}),e.jsx("span",{className:"stop-label",children:p("terminal:input.stop")})]})]}):null});function pt({agent:s,history:a,outputs:l,isExpanded:f,isFocused:p,advancedView:d,onExpand:M,onFocus:A,inputRef:R,onLoadMore:N,onClearHistory:b}){const{t:E}=fe(["terminal","common"]),j=ze(s.id),h=t.useRef(null),[v,u]=t.useState(!1),D=t.useRef(0),i=t.useRef(!1),[C,F]=t.useState(!0),[x,k]=t.useState(!1),[P,K]=t.useState(null),[Y,V]=t.useState(null),[G,Q]=t.useState(null);Te(`commander-image-modal-${s.id}`,P!==null,()=>K(null));const{command:B,setCommand:w,forceTextarea:c,setForceTextarea:L,useTextarea:W,setPastedTexts:U,incrementPastedCount:te,resetPastedCount:_,attachedFiles:$,setAttachedFiles:O,removeAttachedFile:se,uploadFile:ae,expandPastedTexts:ne}=Ue({selectedAgentId:s.id}),le=B.trim().length>0||$.length>0,n=Be({outputs:l,viewMode:d?"advanced":"simple"}),o=t.useMemo(()=>{const S=We(s);return{usedPercent:S.usedPercent,freePercent:S.freePercent,hasData:!!s.contextStats,totalTokens:S.totalTokens,contextWindow:S.contextWindow}},[s.contextStats,s.contextUsed,s.contextLimit]),g=t.useCallback(()=>{!v&&(a!=null&&a.hasMore)&&N&&(u(!0),D.current=h.current?h.current.scrollHeight-h.current.scrollTop:0,N())},[v,a==null?void 0:a.hasMore,N]);t.useEffect(()=>{v&&a&&!a.loading&&u(!1)},[a,v]);const m=t.useCallback(()=>{i.current=!0,F(!1)},[]),T=t.useRef(f),Z=t.useRef(p);t.useEffect(()=>{(f&&!T.current||p&&!Z.current)&&(i.current=!1,F(!0),k(!0)),T.current=f,Z.current=p},[f,p]);const ee=t.useRef(a==null?void 0:a.loading);t.useEffect(()=>{ee.current&&!(a!=null&&a.loading)&&(i.current=!1,F(!0),k(!0)),ee.current=a==null?void 0:a.loading},[a==null?void 0:a.loading]),t.useEffect(()=>{if(!x)return;const S=h.current;if(!S)return;const y=performance.now();let H=0,ue=-1,ke;const Re=()=>{const{scrollTop:Fe,scrollHeight:Se,clientHeight:Le}=S,Oe=Se-Fe-Le<=2;if(Math.abs(Se-ue)<=1&&Oe?H+=1:H=0,ue=Se,H>=3){k(!1);return}if(performance.now()-y>5e3){k(!1);return}ke=requestAnimationFrame(Re)};return ke=requestAnimationFrame(Re),()=>cancelAnimationFrame(ke)},[x]),t.useEffect(()=>{i.current||F(!0)},[n.length]);const q=t.useCallback(()=>!1,[]),ie=t.useCallback(S=>{const y=te();return U(H=>new Map(H).set(y,S)),y},[te,U]),he=t.useCallback(S=>{O(y=>[...y,S])},[O]),xe=t.useCallback(()=>{if(!le)return;if(B.trim()==="/clear"&&$.length===0){I.clearContext(s.id),b(),w(""),L(!1),U(new Map),O([]),_();return}let S=ne(B.trim());if($.length>0){const y=$.map(H=>H.isImage?`[Image: ${H.path}]`:`[File: ${H.path}]`).join(`
|
|
3
3
|
`);S=S?`${S}
|
|
4
4
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/web-
|
|
2
|
-
import{cQ as e,bY as o}from"./main-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/web-BuDeKWBN.js","assets/main-Bp6V_-sL.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-Chj50gSY.js","assets/main-ijcbyjBn.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{cQ as e,bY as o}from"./main-Bp6V_-sL.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";var i;(function(r){r.Heavy="HEAVY",r.Medium="MEDIUM",r.Light="LIGHT"})(i||(i={}));var t;(function(r){r.Success="SUCCESS",r.Warning="WARNING",r.Error="ERROR"})(t||(t={}));const c=e("Haptics",{web:()=>o(()=>import("./web-BuDeKWBN.js"),__vite__mapDeps([0,1,2,3,4])).then(r=>new r.HapticsWeb)});export{c as Haptics,i as ImpactStyle,t as NotificationType};
|