tide-commander 1.115.0 → 1.115.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/dist/assets/{BossLogsModal-1l3Dmpeu.js → BossLogsModal-AfK7wIsE.js} +1 -1
- package/dist/assets/{BossSpawnModal-B-s6zGBU.js → BossSpawnModal-Clplm8hk.js} +1 -1
- package/dist/assets/{ControlsModal-BuGaW0oz.js → ControlsModal-lI2agchh.js} +1 -1
- package/dist/assets/{DockerLogsModal-DjLbi8Us.js → DockerLogsModal-DRe4ZFlh.js} +1 -1
- package/dist/assets/{EmbeddedEditor-b53zq5TQ.js → EmbeddedEditor-Bv-yzABI.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-vIWl70B9.js → GmailOAuthSetup-BOiBGTFJ.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-CL_2866g.js → GoogleOAuthSetup-BHQLKpcm.js} +1 -1
- package/dist/assets/{IframeModal-CZQXaWBI.js → IframeModal-4RgF4sMR.js} +1 -1
- package/dist/assets/{IntegrationsPanel-BiHxKb1E.js → IntegrationsPanel-CmF-BzRr.js} +2 -2
- package/dist/assets/{LogViewerModal-Bbn24mSR.js → LogViewerModal-DBVyr1Y1.js} +1 -1
- package/dist/assets/{MonitoringModal-Ck7VjF9z.js → MonitoringModal-Dpjj9pk_.js} +1 -1
- package/dist/assets/{PM2LogsModal-CQXYJGfq.js → PM2LogsModal-4jN7vvoJ.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-CGD6M-zs.js → RestoreArchivedAreaModal-CkDhmpIM.js} +1 -1
- package/dist/assets/{Scene2DCanvas-AQ2ULfCK.js → Scene2DCanvas-g9Yq37vO.js} +1 -1
- package/dist/assets/{SceneManager-B886dAHx.js → SceneManager-BcwcIbjr.js} +1 -1
- package/dist/assets/{SkillsPanel-Bnc1s1On.js → SkillsPanel-CqN95jsT.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-CgFFqxAh.js → SlackMultiInstanceSetup-gd8RY65M.js} +1 -1
- package/dist/assets/{SpawnModal-aThIWFUh.js → SpawnModal-DEFoiByJ.js} +1 -1
- package/dist/assets/{StatisticsModal-D5LTZRvO.js → StatisticsModal-BwMnVNUg.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-CauSxx7g.js → SubordinateAssignmentModal-CGusmw8L.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-BNVS5XzT.js → TriggerManagerPanel-DSMXjXI5.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-BQB_voKW.js → WorkflowEditorPanel-_x7Z1UvX.js} +1 -1
- package/dist/assets/{index-Cz06mBKl.js → index-3VCTVRSR.js} +1 -1
- package/dist/assets/{index-BDMpvgpZ.js → index-C6Dib9i7.js} +1 -1
- package/dist/assets/{index-L9DZAwh1.js → index-CCSwoBsg.js} +3 -3
- package/dist/assets/{index-CCh8jkeM.js → index-CNaBG2mh.js} +1 -1
- package/dist/assets/{index-BI3DUv9g.js → index-CZpDYtJ9.js} +2 -2
- package/dist/assets/{index-C2BUEDtK.js → index-CkJuCE-P.js} +1 -1
- package/dist/assets/{index-D1zVYRl1.js → index-DcDWJR7R.js} +1 -1
- package/dist/assets/{index-CpLnSkYS.js → index-WbHLNGDb.js} +1 -1
- package/dist/assets/{index-BWXK-Hx7.js → index-gtiJa_Pf.js} +1 -1
- package/dist/assets/{main-CMDpEoqP.js → main-D7pG1mPb.js} +4 -4
- package/dist/assets/{web-D2KP2o6R.js → web-BNh1BOR3.js} +1 -1
- package/dist/assets/{web-BPXoiLCp.js → web-CfofafWw.js} +1 -1
- package/dist/assets/{web-SPiIaILk.js → web-DdGv1tcY.js} +1 -1
- package/dist/index.html +1 -1
- package/dist/src/packages/server/integrations/gmail/gmail-client.js +33 -1
- package/dist/src/packages/server/integrations/gmail/gmail-trigger-handler.js +5 -0
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as a,B as rn,E as Tt,u as Wt,G as on,j as e,V as cn,H as dn,J as un,K as Pt,S as y,L as Lt,M as At,N as Rt,O as ht,P as le,U as pn,s as x,W as Ht,X as Vt,Y as mn,w as Dt,x as zt,I as u,Z as fn,n as hn,_ as gn,$ as Xt,a0 as Gt,a1 as xn,a2 as bn,a3 as _n,a4 as wn,a5 as vn,a6 as Cn,a7 as jn,a8 as Nn,a9 as kn,aa as yn,ab as An,ac as In,ad as $t,C as Sn,ae as En,af as Mn,ag as Tn,ah as Pn,ai as Ln,aj as Rn,ak as Dn,al as zn,am as $n,an as On,ao as Bn,ap as Fn,aq as Wn,ar as Hn,as as Vn,at as Xn,au as Gn}from"./main-CMDpEoqP.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Un(w){const d=a.useRef(w);d.current=w,a.useEffect(()=>{if(!rn())return;let v=null,A=!1;return Tt.addListener("backButton",()=>{d.current()==="exit"&&Tt.exitApp()}).then(E=>{A?E.remove():v=E}),()=>{A=!0,v&&(v.remove(),v=null)}},[])}const qn=a.memo(function({className:d=""}){const{t:v}=Wt(["common"]),[A,E]=on(),K=a.useRef(null),[B,De]=a.useState(null);a.useLayoutEffect(()=>{const g=K.current;if(!g)return;const Z=g.querySelector(".view-mode-toggle__btn--active");Z&&De({left:Z.offsetLeft,width:Z.offsetWidth})},[A]);const ie=a.useCallback(g=>{if(g!==A){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:g}})),g==="3d"){requestAnimationFrame(()=>E(g));return}E(g)}},[A,E]);return e.jsxs("div",{className:`view-mode-toggle ${d}`,ref:K,children:[B&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:B.left,width:B.width}}),cn.map(g=>e.jsxs("button",{className:`view-mode-toggle__btn ${A===g?"view-mode-toggle__btn--active":""}`,onClick:()=>ie(g),title:v(`common:viewMode.descriptions.${g}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[g==="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"})]}),g==="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"})]}),g==="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"})]}),g==="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:v(`common:viewMode.labels.${g}`)})]},g))]})}),gt=3,xt=280,Ot=320,yt=240,Bt=64,Yn=["simple","chat","advanced"],Kn={simple:"Simple",chat:"Chat",advanced:"Advanced"},Zn={simple:"○",chat:"◐",advanced:"◉"},Jn={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Ft="flat-clear-context";function Qn(w){const d=w.split("/").filter(Boolean);return d.length===0?w:d.slice(-2).join("/")}function ea(w){if(w.provider==="codex"){const K=w.codexModel||"gpt-5.3-codex",B=Vn[K];return{model:(B==null?void 0:B.label)||K}}if(w.provider==="opencode")return{model:w.opencodeModel||"opencode"};const d=w.model||"sonnet",v=Gn[d],A=w.effort,E=A?Xn[A]:void 0;return{model:(v==null?void 0:v.label)||d,effort:E==null?void 0:E.label}}function ta(w,d){if(d.type==="rectangle"&&d.width&&d.height){const v=d.width/2,A=d.height/2;return w.x>=d.center.x-v&&w.x<=d.center.x+v&&w.z>=d.center.z-A&&w.z<=d.center.z+A}if(d.type==="circle"&&d.radius){const v=w.x-d.center.x,A=w.z-d.center.z;return v*v+A*A<=d.radius*d.radius}return!1}const na=En.memo(function({agentId:d,terminalViewMode:v,onTerminalViewModeChange:A,inspectorOpen:E,onToggleInspector:K,onImageClick:B,onFileClick:De,onBashClick:ie,onViewMarkdown:g,onRequestClearSubordinates:Z,onOpenBuilding:ye,keyboard:Ge,canNavigateBack:Ue,canNavigateForward:qe,onNavigateBack:pe,onNavigateForward:re,agentInfoOpen:me,onToggleAgentInfo:Ye,onHeaderContextMenu:J,onBuildingContextMenu:fe}){var ne,ct,$,ae;const f=Mn(d),F=Vt(),W=a.useRef(null),Ae=a.useRef(null);a.useEffect(()=>{const l=Ae.current;if(!l)return;const r=c=>{c.button===3?(c.preventDefault(),c.stopPropagation(),pe()):c.button===4&&(c.preventDefault(),c.stopPropagation(),re())},o=c=>{(c.button===3||c.button===4)&&c.preventDefault()};return l.addEventListener("mouseup",r),l.addEventListener("mousedown",o),()=>{l.removeEventListener("mouseup",r),l.removeEventListener("mousedown",o)}},[pe,re]),a.useEffect(()=>{const l=Ae.current;if(!l)return;let r=0,o=0,c=0;const Pe=250,Le=600,Re=80,Y=1.5,We=O=>{let T=O instanceof HTMLElement?O:null;for(;T&&T!==l;){const Ve=window.getComputedStyle(T).overflowX;if((Ve==="auto"||Ve==="scroll")&&T.scrollWidth>T.clientWidth)return!0;T=T.parentElement}return!1},He=O=>{const T=Date.now();if(T<c){O.preventDefault();return}if(Math.abs(O.deltaX)<=Math.abs(O.deltaY)*Y){r=0;return}if(We(O.target)){r=0;return}T-o>Pe&&(r=0),o=T,r+=O.deltaX,r<=-Re?(r=0,c=T+Le,O.preventDefault(),pe()):r>=Re&&(r=0,c=T+Le,O.preventDefault(),re())};return l.addEventListener("wheel",He,{passive:!1}),()=>l.removeEventListener("wheel",He)},[pe,re]);const Ie=Ht(),he=a.useMemo(()=>{if(!f)return null;const l=new Set,r=[];for(const o of Ie.values())o.archived||o.directories.length===0||o.assignedAgentIds.includes(d)&&(l.add(o.id),r.push(o));for(const o of Ie.values())o.archived||o.directories.length===0||l.has(o.id)||ta({x:f.position.x,z:f.position.z},o)&&(l.add(o.id),r.push(o));return r.length===0?null:r.flatMap(o=>o.directories.filter(c=>c&&c.trim().length>0).map(c=>({areaId:o.id,areaName:o.name,dir:c})))},[f,d,Ie]),{branches:Ke,fetchRemote:Ze,fetchingDirs:Je}=Tn(he),ge=a.useMemo(()=>{var o;const l=x.getAreaForAgent(d);if(!l)return[];const r=[];for(const c of F.values())c.type==="terminal"&&x.isPositionInArea(c.position,l)&&r.push({id:c.id,name:c.name,hasUrl:!!((o=c.terminalStatus)!=null&&o.url)});return r},[d,F]),Qe=a.useMemo(()=>{var o;const l=x.getAreaForAgent(d);if(!l)return[];const r=[];for(const c of F.values())c.type==="server"&&((o=c.pm2)!=null&&o.enabled)&&x.isPositionInArea(c.position,l)&&r.push({id:c.id,name:c.name});return r},[d,F]),xe=a.useMemo(()=>{const l=x.getAreaForAgent(d);if(!l)return[];const r=[];for(const o of F.values())o.type==="database"&&o.database&&x.isPositionInArea(o.position,l)&&r.push({id:o.id,name:o.name});return r},[d,F]),[,be]=a.useReducer(l=>l+1,0),H=((ne=W.current)==null?void 0:ne.search.searchMode)??!1,oe=a.useCallback(()=>{var l;(l=W.current)==null||l.search.toggleSearch(),be()},[]),et=Pn(),ze=et.isPending(Ft),[V,X]=a.useState(null),D=V?F.get(V):null,{height:Se,onResizeStart:G}=Ln(),{sidePanelWidth:Ee,handleSidePanelResizeStart:ce}=Rn(),[z,tt]=a.useState(()=>At(y.GIT_PANEL_OPEN,!1)),[_e,$e]=a.useState(()=>At(y.BUILDINGS_PANEL_OPEN,!1)),[U,nt]=a.useState(!1),bt=a.useCallback(()=>{nt(l=>{const r=!l;return r&&Dn.setEnabled(!0),r})},[]),we=a.useCallback(()=>nt(!1),[]),_t=a.useCallback(()=>{tt(l=>{const r=!l;return le(y.GIT_PANEL_OPEN,r),r})},[]),at=a.useCallback(()=>{$e(l=>{const r=!l;return le(y.BUILDINGS_PANEL_OPEN,r),r})},[]),wt=a.useCallback(()=>{tt(!1),le(y.GIT_PANEL_OPEN,!1)},[]),Oe=a.useCallback(()=>{$e(!1),le(y.BUILDINGS_PANEL_OPEN,!1)},[]),vt=zn();a.useEffect(()=>{if(!V)return;ge.some(r=>r.id===V)||X(null)},[V,ge]);const[ve,de]=a.useState(!1),Be=a.useRef(null);if(a.useEffect(()=>{if(!ve)return;const l=r=>{Be.current&&!Be.current.contains(r.target)&&de(!1)};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[ve]),!f)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const Q=f.contextStats,st=!!Q,Ce=Q?Q.totalTokens:f.contextUsed||0,h=Q?Q.contextWindow:f.contextLimit||2e5,ee=Q?Q.usedPercent:Math.round(Ce/h*100),M=Math.max(0,Math.min(100,ee)),Me=Math.round(M*10)/10,lt=Math.round((100-M)*10)/10,it=M>=80?"#ff4a4a":M>=60?"#ff9e4a":M>=40?"#ffd700":"#4aff9e",rt=(Ce/1e3).toFixed(1),ot=(h/1e3).toFixed(1),te=f.cwd,Te=te?Qn(te):null,q=((ct=f.subordinateIds)==null?void 0:ct.length)||0,Fe=q>0;return e.jsxs("div",{ref:Ae,className:`flat-terminal-wrapper ${z||_e||U?"flat-terminal-wrapper--with-side-panel":""}`,style:{"--guake-side-panel-width":`min(${Ee}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${me?"flat-terminal-wrapper__header-main--active":""}`,onClick:Ye,onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),J({x:l.clientX,y:l.clientY})},title:me?"Hide agent info":"Show agent info","aria-pressed":me,children:[e.jsx(Xt,{agent:f,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:f.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:Gt(f.status)},children:f.status})]}),f.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:f.taskLabel,children:["📋 ",f.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:f.provider==="codex"?"/assets/codex.png":f.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:f.provider,className:"flat-terminal-wrapper__header-provider-icon",title:f.provider==="codex"?"Codex Agent":f.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:l,effort:r}=ea(f);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:r?`Model: ${l} · Effort: ${r}`:`Model: ${l}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:l}),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.jsx("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:Yn.map(l=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${v===l?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>A(l),title:Jn[l],"aria-pressed":v===l,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:Zn[l]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Kn[l]})]},l))}),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:pe,disabled:!Ue,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(u,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:re,disabled:!qe,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(u,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${H?"flat-terminal-wrapper__action-btn--active":""}`,onClick:oe,title:H?"Close search":"Search messages","aria-pressed":H,children:e.jsx(u,{name:H?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${ze?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>et.handleClick(Ft,()=>{var l;x.clearContext(d),(l=W.current)==null||l.historyLoader.clearHistory()}),title:ze?"Click again to confirm clear context":"Clear context",children:e.jsx(u,{name:ze?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${z?"flat-terminal-wrapper__action-btn--active":""}`,onClick:_t,title:z?"Hide git panel":"Show git changes","aria-pressed":z,children:e.jsx(u,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${_e?"flat-terminal-wrapper__action-btn--active":""}`,onClick:at,title:_e?"Hide buildings panel":"Show area buildings","aria-pressed":_e,children:e.jsx(u,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:Be,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ve?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>de(l=>!l),title:"More actions","aria-expanded":ve,children:"⋮"}),ve&&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 ${U?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{bt(),de(!1)},title:U?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(u,{name:"bug",size:14}),e.jsx("span",{children:U?"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:()=>{x.collapseContext(d),de(!1)},disabled:f.status!=="idle",title:f.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(u,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),Fe&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{Z(d,q),de(!1)},children:[e.jsx(u,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",q," subordinate",q===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:()=>{x.killAgent(d),de(!1)},children:[e.jsx(u,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${E?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:K,title:E?"Hide inspector panel":"Show inspector panel","aria-label":E?"Hide inspector panel":"Show inspector panel","aria-pressed":E,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:()=>x.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(u,{name:"cross",size:14})})]})]}),e.jsx($n,{ref:W,agentId:d,agent:f,viewMode:v,isOpen:!0,onImageClick:B,onFileClick:De,onBashClick:ie,onViewMarkdown:g,keyboard:Ge,hasModalOpen:!1}),D&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:G,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${D.name}`,style:{height:Se},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(u,{name:"terminal",size:12}),e.jsx("span",{children:D.name}),!(($=D.terminalStatus)!=null&&$.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>X(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(u,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:(ae=D.terminalStatus)!=null&&ae.url?e.jsx(On,{terminalUrl:D.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."})})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[f.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(u,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),te&&Te&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${te}`,"aria-label":`Open ${te} in file explorer`,role:"button",tabIndex:0,onClick:()=>x.openFileExplorer(te),onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),x.openFileExplorer(te))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(u,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:Te})]}),he&&he.map(({areaId:l,areaName:r,dir:o})=>{const c=Ke.get(o),Pe=Je.has(o),Le=o.split("/").filter(Boolean).pop()||o;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${r}: ${o}${c?` (${c.branch}${c.ahead?` ↑${c.ahead}`:""}${c.behind?` ↓${c.behind}`:""})`:""}`,onClick:()=>x.openFileExplorerForAreaFolder(l,o),children:[e.jsx(u,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:Le}),c&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(u,{name:"git-branch",size:10})," ",c.branch]}),c.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${c.ahead} ahead`,children:[e.jsx(u,{name:"arrow-up",size:9}),c.ahead]}),c.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${c.behind} behind`,children:[e.jsx(u,{name:"arrow-down",size:9}),c.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${Pe?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:Re=>{Re.stopPropagation(),Ze(o)},children:e.jsx(u,{name:Pe?"hourglass":"download",size:12})})]})]},`${l}:${o}`)}),e.jsxs("span",{className:"flat-terminal-wrapper__context",onClick:()=>x.setContextModalAgentId(d),title:st?`Context usage: ${rt}k / ${ot}k tokens (${Me}% used). Click to view stats.`:"Click to fetch context stats",children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(u,{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:`${M}%`,backgroundColor:it}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:it},children:[rt,"k/",ot,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",lt,"% free)"]}),!st&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(u,{name:"warn",size:12})})]}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),ge.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:ge.map(l=>{const r=V===l.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""} ${l.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${r?"Hide":"Show"} terminal: ${l.name}${l.hasUrl?"":" (starting...)"}`,onClick:()=>{if(r){X(null);return}l.hasUrl||x.sendBuildingCommand(l.id,"start"),X(l.id)},onContextMenu:o=>{o.preventDefault(),o.stopPropagation(),fe(l.id,{x:o.clientX,y:o.clientY})},children:e.jsx(u,{name:"terminal",size:14})},l.id)})}),Qe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Qe.map(l=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${l.name}`,onClick:()=>ye(l.id),onContextMenu:r=>{r.preventDefault(),r.stopPropagation(),fe(l.id,{x:r.clientX,y:r.clientY})},children:e.jsx(u,{name:"scroll",size:14})},l.id))}),xe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:xe.map(l=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${l.name}`,onClick:()=>ye(l.id),onContextMenu:r=>{r.preventDefault(),r.stopPropagation(),fe(l.id,{x:r.clientX,y:r.clientY})},children:e.jsx(u,{name:"hard-drives",size:14})},l.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(Bn,{})})]}),z&&e.jsx(Fn,{agentId:d,agents:vt,onClose:wt,branchInfoMap:Ke,fetchRemote:Ze,fetchingDirs:Je,onResizeStart:l=>ce(l,"right")}),_e&&e.jsx(Wn,{agentId:d,onClose:Oe}),U&&e.jsx(Hn,{agentId:d,onClose:we})]})});function ia({onAgentClick:w,onBuildingClick:d,onBuildingDoubleClick:v,onBuildingPopup:A,onAreaContextMenu:E,onOpenSpawnModal:K,onOpenBossSpawnModal:B,onOpenAreaModal:De}){const{t:ie}=Wt(["common"]),g=dn(),Z=un(),[ye,Ge]=a.useState(null),[Ue,qe]=a.useState(null),[pe,re]=a.useState(null),[me,Ye]=a.useState(null),[J,fe]=a.useState(null),[f,F]=a.useState(null),[W,Ae]=a.useState(null),[Ie,he]=a.useState(!1),Ke=a.useCallback(()=>{he(t=>!t)},[]),Ze=a.useCallback(()=>{he(!1)},[]),[Je,ge]=a.useState(()=>{const t=Pt(y.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Qe=a.useCallback(t=>{ge(t),Lt(y.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=n=>{if(n.key!==y.VIEW_MODE)return;const s=n.newValue;(s==="simple"||s==="chat"||s==="advanced")&&ge(s)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[xe,be]=a.useState(()=>At(y.FLAT_INSPECTOR_OPEN,!1)),[H,oe]=a.useState(!1),et=a.useCallback(()=>oe(t=>!t),[]),ze=a.useCallback(()=>oe(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:H}}))},[H]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:xe}}))},[xe]),a.useEffect(()=>{const t=()=>oe(_=>!_),n=()=>{be(_=>{const i=!_;return le(y.FLAT_INSPECTOR_OPEN,i),i})},s=()=>{oe(!1),be(!1),le(y.FLAT_INSPECTOR_OPEN,!1)},p=()=>oe(!1),m=()=>{be(!1),le(y.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",n),window.addEventListener("tide-close-flat-side-views",s),window.addEventListener("tide-close-flat-agents-drawer-only",p),window.addEventListener("tide-close-flat-inspector-only",m),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",n),window.removeEventListener("tide-close-flat-side-views",s),window.removeEventListener("tide-close-flat-agents-drawer-only",p),window.removeEventListener("tide-close-flat-inspector-only",m)}},[]);const V=a.useRef(null),X=a.useRef(null),[D,Se]=a.useState(()=>{const t=Rt(y.FLAT_MIDDLE_WIDTH,0);return t>=xt?t:null}),[G,Ee]=a.useState(()=>{const t=Rt(y.FLAT_INSPECTOR_WIDTH,0);return t>=yt?t:null}),ce=a.useCallback(t=>{if(typeof window>"u")return t;const n=G!==null?gt+G:0,s=window.innerWidth-Bt-gt-Ot-n;return Math.max(xt,Math.min(Math.max(s,xt),t))},[G]),z=a.useCallback(t=>{var m;if(typeof window>"u")return t;const n=(m=V.current)==null?void 0:m.querySelector(".flat-middle"),s=(n==null?void 0:n.getBoundingClientRect().width)??xt,p=window.innerWidth-Bt-s-gt-Ot-gt;return Math.max(yt,Math.min(Math.max(p,yt),t))},[]);a.useEffect(()=>{if(D===null&&G===null)return;const t=()=>{Se(n=>{if(n===null)return n;const s=ce(n);return s===n?n:s}),Ee(n=>{if(n===null)return n;const s=z(n);return s===n?n:s})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[D,G,ce,z]);const tt=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=V.current)==null?void 0:s.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),X.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),_e=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=V.current)==null?void 0:s.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),X.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),$e=a.useCallback(t=>{const n=X.current;if(!n||t.pointerId!==n.pointerId)return;const s=t.clientX-n.startX;n.kind==="middle"?Se(ce(n.startWidth+s)):Ee(z(n.startWidth-s))},[ce,z]),U=a.useCallback(t=>{const n=X.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(X.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const p=t.clientX-n.startX;if(n.kind==="middle"){const m=ce(n.startWidth+p);Se(m),ht(y.FLAT_MIDDLE_WIDTH,m)}else{const m=z(n.startWidth-p);Ee(m),ht(y.FLAT_INSPECTOR_WIDTH,m)}},[ce,z]),nt=a.useCallback(()=>{Se(null),ht(y.FLAT_MIDDLE_WIDTH,0)},[]),bt=a.useCallback(()=>{Ee(null),ht(y.FLAT_INSPECTOR_WIDTH,0)},[]),[we,_t]=a.useState(()=>Pt(y.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),at=a.useCallback(t=>{_t(t),Lt(y.FLAT_INSPECTOR_VIEW,t)},[]),wt=a.useCallback(()=>{be(t=>{const n=!t;return le(y.FLAT_INSPECTOR_OPEN,n),n})},[]),Oe=a.useCallback(()=>{be(!1),le(y.FLAT_INSPECTOR_OPEN,!1)},[]),vt=pn(),ve=a.useCallback((t,n)=>{Ge({url:t,name:n})},[]),de=a.useCallback((t,n)=>{qe({command:t,output:n,isLive:!1})},[]),Be=a.useCallback((t,n)=>{x.setFileViewerPath(t,n)},[]),Q=a.useCallback(t=>{re(t)},[]),st=a.useCallback((t,n)=>{Ye({agentId:t,count:n})},[]),Ce=a.useCallback(t=>{v?v(t):d(t)},[d,v]),h=a.useMemo(()=>Z.size>0?Array.from(Z)[0]:null,[Z]);a.useEffect(()=>{he(!1)},[h]);const ee=a.useRef([]),M=a.useRef(-1),Me=a.useRef(!1),lt=a.useRef(null),[it,rt]=a.useState(!1),[ot,te]=a.useState(!1),Te=a.useRef(!1),q=a.useRef(null),Fe=a.useRef(!1),ne=a.useMemo(()=>new Set(g.map(t=>t.id)),[g]),ct=a.useMemo(()=>{const t=new Map(g.map(s=>[s.id,s])),n=new Map;for(const s of g)if((s.isBoss||s.class==="boss")&&s.subordinateIds&&s.subordinateIds.length>0){const p=s.subordinateIds.map(m=>t.get(m)).filter(m=>m!==void 0);p.length>0&&n.set(s.id,p)}return n},[g]),$=a.useCallback(()=>{const t=ee.current,n=M.current;rt(n>0),te(n>=0&&n<t.length-1)},[]),ae=a.useCallback(t=>{const n=ee.current;if(n.length===0)return;let s=M.current+t;for(;s>=0&&s<n.length;){const p=n[s];if(ne.has(p)){Me.current=!0,M.current=s,$(),x.selectAgent(p);return}s+=t}},[ne,$]),l=a.useCallback(()=>ae(-1),[ae]),r=a.useCallback(()=>ae(1),[ae]);Un(a.useCallback(()=>{const t=ee.current,n=M.current;return t.length>0&&n>0?(ae(-1),"handled"):"exit"},[ae]));const o=a.useCallback((t,n)=>{if(typeof window>"u")return;const s=window.history.state,m={...typeof s=="object"&&s!==null?s:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(m,"",window.location.href):window.history.pushState(m,"",window.location.href)},[]);a.useEffect(()=>{if(!h){Te.current=!1,q.current=null;return}if(!Te.current){o(h,"replace"),Te.current=!0,q.current=h;return}if(Fe.current){Fe.current=!1,q.current=h;return}q.current!==h&&(o(h,"push"),q.current=h)},[h,o]),a.useEffect(()=>{const t=n=>{var _,i;const s=(i=(_=n.state)==null?void 0:_.__flatAgentNav)==null?void 0:i.agentId;if(!s||typeof s!="string"||!ne.has(s)||s===h)return;Fe.current=!0,Me.current=!0;const p=ee.current,m=p.lastIndexOf(s);m>=0?M.current=m:(p.push(s),M.current=p.length-1),$(),x.selectAgent(s)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[ne,h,$]),a.useEffect(()=>{if(!h){ee.current=[],M.current=-1,$();return}if(lt.current=h,Me.current){Me.current=!1,$();return}const t=ee.current,n=M.current;if(n>=0&&t[n]===h){$();return}const s=n<t.length-1?t.slice(0,n+1):t.slice();s.push(h),s.length>100&&s.shift(),ee.current=s,M.current=s.length-1,$()},[h,$]);const c=a.useCallback(t=>{w(t),oe(!1)},[w]),Pe=h??"",Le=a.useCallback(()=>{},[]),Re=a.useCallback(t=>{c(t)},[c]),Y=xe,[We,He]=a.useState(Y),[O,T]=a.useState(Y);a.useEffect(()=>{if(Y){He(!0);return}T(!1);const t=setTimeout(()=>He(!1),240);return()=>clearTimeout(t)},[Y]),a.useEffect(()=>{if(!We||!Y)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>T(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[We,Y]);const Ve=a.useRef(null);a.useEffect(()=>{if(h)return;const t=n=>{if(n.key!==" "&&n.key!=="Backspace")return;const s=n.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const p=lt.current;!p||!ne.has(p)||(n.preventDefault(),x.selectAgent(p))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[h,ne]);const[Ut,It]=a.useState(new Set),qt=a.useCallback(t=>{It(n=>{const s=new Set(n);return s.has(t)?s.delete(t):s.add(t),s})},[]),[je,Yt]=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)"),n=s=>Yt(s.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const[dt,Kt]=a.useState(null),Zt=a.useCallback(t=>{Kt(n=>n===t?null:t)},[]),Ct=Ht(),ut=Vt(),[Jt]=mn(),Ne=a.useMemo(()=>{const t=new Map,n=[];for(const b of g){const k=x.getAreaForAgent(b.id);if(!Dt((k==null?void 0:k.id)??null))continue;if(!k||k.archived){n.push(b);continue}const N=t.get(k.id);N?N.push(b):t.set(k.id,[b])}const s=new Map,p=[];for(const b of ut.values()){let k=!1;for(const N of Ct.values())if(!N.archived&&zt(N.id)&&x.isPositionInArea(b.position,N)){const se=s.get(N.id);se?se.push(b):s.set(N.id,[b]),k=!0;break}!k&&Dt(null)&&p.push(b)}const m=[];for(const[,b]of Ct){if(b.archived||!zt(b.id))continue;const k=t.get(b.id),N=s.get(b.id)??[];(k&&k.length>0||N.length>0)&&m.push({area:b,agents:k??[],buildings:N})}(n.length>0||p.length>0)&&m.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:n,buildings:p});const _=m.filter(b=>b.area.id!=="__unassigned__"),i=m.filter(b=>b.area.id==="__unassigned__");let I=1,j=1;const S=new Map;if(_.length>1){let b=1/0,k=-1/0,N=1/0,se=-1/0;for(const L of _)b=Math.min(b,L.area.center.x),k=Math.max(k,L.area.center.x),N=Math.min(N,L.area.center.z),se=Math.max(se,L.area.center.z);const pt=k-b||1,mt=se-N||1;if(_.length<=4){I=_.length,j=1;const L=[..._].sort((R,jt)=>R.area.center.x-jt.area.center.x);for(let R=0;R<L.length;R++)S.set(L[R].area.id,{row:1,col:R+1})}else{const L=[..._].sort((C,P)=>C.area.center.x-P.area.center.x),R=[];for(let C=1;C<L.length;C++)R.push(L[C].area.center.x-L[C-1].area.center.x);const jt=R.reduce((C,P)=>C+P,0)/R.length||1;let St=1;for(const C of R)C>jt*1.3&&St++;I=Math.max(2,Math.min(St,_.length));const Nt=[..._].sort((C,P)=>C.area.center.z-P.area.center.z),ft=[];for(let C=1;C<Nt.length;C++)ft.push(Nt[C].area.center.z-Nt[C-1].area.center.z);const nn=ft.reduce((C,P)=>C+P,0)/ft.length||1;let Et=1;for(const C of ft)C>nn*1.3&&Et++;j=Math.max(2,Math.min(Et,_.length)),I=Math.max(I,Math.ceil(_.length/j)),j=Math.max(j,Math.ceil(_.length/I));const an=pt/I,sn=mt/j,kt=new Set;for(const C of _){let P=Math.min(I-1,Math.max(0,Math.floor((C.area.center.x-b)/an))),ke=Math.min(j-1,Math.max(0,Math.floor((C.area.center.z-N)/sn))),Xe=`${ke},${P}`,Mt=0;const ln=j*I;for(;kt.has(Xe)&&Mt<ln;)P++,P>=I&&(P=0,ke=(ke+1)%j),Xe=`${ke},${P}`,Mt++;kt.has(Xe)&&(ke=j,P=0,Xe=`${ke},${P}`,j++),kt.add(Xe),S.set(C.area.id,{row:ke+1,col:P+1})}}}const ue=b=>{b.sort((k,N)=>{var pt,mt,L,R;const se=(((pt=k.position)==null?void 0:pt.z)??0)-(((mt=N.position)==null?void 0:mt.z)??0);return se!==0?se:(((L=k.position)==null?void 0:L.x)??0)-(((R=N.position)==null?void 0:R.x)??0)})};for(const b of _)ue(b.agents);for(const b of i)ue(b.agents);return{groups:[..._,...i],gridCols:I,gridRows:j,positions:S}},[g,Ct,ut,Jt]),Qt=a.useMemo(()=>{if(!J)return[];const t=g.find(n=>n.id===J.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(u,{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(u,{name:"chat",size:14}),onClick:()=>w(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>{Ae({agentId:t.id,name:t.name})}}]:[]},[J,g,w]),en=a.useMemo(()=>{var _;if(!f)return[];const t=ut.get(f.buildingId);if(!t)return[];const n=[],s=t.type==="server"||t.type==="docker"||t.type==="terminal",p=t.status==="running",m=t.type==="boss";if(n.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((_=t.pm2)!=null&&_.enabled)?"View PM2 Logs":"Open",icon:e.jsx(u,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>Ce(t.id)}),s&&(p||n.push({id:"start",label:"Start",icon:e.jsx(u,{name:"play",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"start")}),p&&(n.push({id:"restart",label:"Restart",icon:e.jsx(u,{name:"refresh",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(u,{name:"stop",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"stop")}))),m&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(n.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(u,{name:"launch",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"start")}}),n.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(u,{name:"pause",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"stop")}}),n.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(u,{name:"restart",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"restart")}})),s&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(u,{name:"health",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"healthCheck")}),n.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),n.push({id:"edit",label:"Edit Building",icon:e.jsx(u,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),n.push({id:"clone",label:"Clone Building",icon:e.jsx(u,{name:"copy",size:14}),onClick:()=>{x.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 i of t.urls)n.push({id:`url-${i.label}`,label:i.label,icon:e.jsx(u,{name:"link",size:14}),onClick:()=>window.open(i.url,"_blank","noopener,noreferrer")});return n.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),n.push({id:"delete",label:"Delete Building",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>x.deleteBuilding(t.id)}),n},[f,ut,Ce]),tn=a.useCallback(t=>{const n=new Set(Ne.groups.map(s=>s.area.id));n.delete(t),It(n),requestAnimationFrame(()=>{const s=Ve.current;if(!s)return;const p=s.querySelector(`[data-area-id="${t}"]`);if(!p)return;const m=s.getBoundingClientRect(),i=p.getBoundingClientRect().top-m.top+s.scrollTop-8;s.scrollTo({top:Math.max(0,i),behavior:"smooth"})})},[Ne]);return e.jsxs("div",{ref:V,className:`flat-view ${Y?"flat-view--with-inspector":""} ${h?"flat-view--has-chat":""} ${H?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(D===null&&G===null)return;const t={};return D!==null&&(t["--flat-middle-width"]=`${D}px`),G!==null&&(t["--flat-inspector-width"]=`${G}px`),t})(),children:[H&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:ze,"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:K,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:B,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:De,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(fn,{activeAgentId:Pe,onClose:Le,onSelectAgent:Re,collapsedAreas:Ut,onToggleArea:qt,agentListRef:Ve})})]}),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:$e,onPointerUp:U,onPointerCancel:U,onDoubleClick:nt}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":H?"Close agents sidebar":"Open agents sidebar","aria-expanded":H,onClick:et,children:[e.jsx(u,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),h?e.jsx(na,{agentId:h,terminalViewMode:Je,onTerminalViewModeChange:Qe,inspectorOpen:xe,onToggleInspector:wt,onImageClick:ve,onFileClick:Be,onBashClick:de,onViewMarkdown:Q,onRequestClearSubordinates:st,onOpenBuilding:Ce,keyboard:vt,canNavigateBack:it,canNavigateForward:ot,onNavigateBack:l,onNavigateForward:r,agentInfoOpen:Ie,onToggleAgentInfo:Ke,onHeaderContextMenu:t=>{h&&fe({agentId:h,position:t})},onBuildingContextMenu:(t,n)=>{F({buildingId:t,position:n})}}):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(qn,{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 n;const t=je&&dt?((n=Ne.positions.get(dt))==null?void 0:n.row)??null:null;return Ne.groups.map(s=>{const p=s.area.id,m=Ne.positions.get(p),_=je&&dt!==p;return je&&t!=null&&(m==null?void 0:m.row)===t&&p!==dt?null:e.jsxs("div",{className:`flat-map-area-card${_?" flat-map-area-card--collapsed":""}`,style:{"--area-color":s.area.color,gridRow:m==null?void 0:m.row,gridColumn:m==null?void 0:m.col},onContextMenu:i=>{E&&(i.preventDefault(),i.stopPropagation(),E(p,{x:i.clientX,y:i.clientY}))},children:[e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>je?Zt(p):tn(p),title:je?_?`Expand ${s.area.name}`:`Collapse ${s.area.name}`:`Focus ${s.area.name} in left panel`,"aria-expanded":je?!_:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:s.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:s.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:s.agents.length}),je&&e.jsx(u,{name:_?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:s.agents.map(i=>{const I=i.isBoss||i.class==="boss",j=I?ct.get(i.id):void 0,S=hn(i),ue=S.usedPercent>=80?"#ff4a4a":S.usedPercent>=60?"#ff9e4a":S.usedPercent>=40?"#ffd700":"#4aff9e",b=`Context: ${(S.totalTokens/1e3).toFixed(1)}k / ${(S.contextWindow/1e3).toFixed(1)}k (${S.usedPercent}% used, ${S.freePercent}% free)`,k=i.latestTodos&&i.latestTodos.length>0||j&&j.length>0;return e.jsx(gn,{todos:i.latestTodos,subordinates:j,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${i.status}`,onClick:()=>w(i.id),onContextMenu:N=>{N.preventDefault(),N.stopPropagation(),fe({agentId:i.id,position:{x:N.clientX,y:N.clientY}})},title:k?void 0:`${I?"Boss · ":""}Open chat with ${i.name}
|
|
1
|
+
import{r as a,B as rn,E as Tt,u as Wt,G as on,j as e,V as cn,H as dn,J as un,K as Pt,S as y,L as Lt,M as At,N as Rt,O as ht,P as le,U as pn,s as x,W as Ht,X as Vt,Y as mn,w as Dt,x as zt,I as u,Z as fn,n as hn,_ as gn,$ as Xt,a0 as Gt,a1 as xn,a2 as bn,a3 as _n,a4 as wn,a5 as vn,a6 as Cn,a7 as jn,a8 as Nn,a9 as kn,aa as yn,ab as An,ac as In,ad as $t,C as Sn,ae as En,af as Mn,ag as Tn,ah as Pn,ai as Ln,aj as Rn,ak as Dn,al as zn,am as $n,an as On,ao as Bn,ap as Fn,aq as Wn,ar as Hn,as as Vn,at as Xn,au as Gn}from"./main-D7pG1mPb.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Un(w){const d=a.useRef(w);d.current=w,a.useEffect(()=>{if(!rn())return;let v=null,A=!1;return Tt.addListener("backButton",()=>{d.current()==="exit"&&Tt.exitApp()}).then(E=>{A?E.remove():v=E}),()=>{A=!0,v&&(v.remove(),v=null)}},[])}const qn=a.memo(function({className:d=""}){const{t:v}=Wt(["common"]),[A,E]=on(),K=a.useRef(null),[B,De]=a.useState(null);a.useLayoutEffect(()=>{const g=K.current;if(!g)return;const Z=g.querySelector(".view-mode-toggle__btn--active");Z&&De({left:Z.offsetLeft,width:Z.offsetWidth})},[A]);const ie=a.useCallback(g=>{if(g!==A){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:g}})),g==="3d"){requestAnimationFrame(()=>E(g));return}E(g)}},[A,E]);return e.jsxs("div",{className:`view-mode-toggle ${d}`,ref:K,children:[B&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:B.left,width:B.width}}),cn.map(g=>e.jsxs("button",{className:`view-mode-toggle__btn ${A===g?"view-mode-toggle__btn--active":""}`,onClick:()=>ie(g),title:v(`common:viewMode.descriptions.${g}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[g==="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"})]}),g==="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"})]}),g==="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"})]}),g==="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:v(`common:viewMode.labels.${g}`)})]},g))]})}),gt=3,xt=280,Ot=320,yt=240,Bt=64,Yn=["simple","chat","advanced"],Kn={simple:"Simple",chat:"Chat",advanced:"Advanced"},Zn={simple:"○",chat:"◐",advanced:"◉"},Jn={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Ft="flat-clear-context";function Qn(w){const d=w.split("/").filter(Boolean);return d.length===0?w:d.slice(-2).join("/")}function ea(w){if(w.provider==="codex"){const K=w.codexModel||"gpt-5.3-codex",B=Vn[K];return{model:(B==null?void 0:B.label)||K}}if(w.provider==="opencode")return{model:w.opencodeModel||"opencode"};const d=w.model||"sonnet",v=Gn[d],A=w.effort,E=A?Xn[A]:void 0;return{model:(v==null?void 0:v.label)||d,effort:E==null?void 0:E.label}}function ta(w,d){if(d.type==="rectangle"&&d.width&&d.height){const v=d.width/2,A=d.height/2;return w.x>=d.center.x-v&&w.x<=d.center.x+v&&w.z>=d.center.z-A&&w.z<=d.center.z+A}if(d.type==="circle"&&d.radius){const v=w.x-d.center.x,A=w.z-d.center.z;return v*v+A*A<=d.radius*d.radius}return!1}const na=En.memo(function({agentId:d,terminalViewMode:v,onTerminalViewModeChange:A,inspectorOpen:E,onToggleInspector:K,onImageClick:B,onFileClick:De,onBashClick:ie,onViewMarkdown:g,onRequestClearSubordinates:Z,onOpenBuilding:ye,keyboard:Ge,canNavigateBack:Ue,canNavigateForward:qe,onNavigateBack:pe,onNavigateForward:re,agentInfoOpen:me,onToggleAgentInfo:Ye,onHeaderContextMenu:J,onBuildingContextMenu:fe}){var ne,ct,$,ae;const f=Mn(d),F=Vt(),W=a.useRef(null),Ae=a.useRef(null);a.useEffect(()=>{const l=Ae.current;if(!l)return;const r=c=>{c.button===3?(c.preventDefault(),c.stopPropagation(),pe()):c.button===4&&(c.preventDefault(),c.stopPropagation(),re())},o=c=>{(c.button===3||c.button===4)&&c.preventDefault()};return l.addEventListener("mouseup",r),l.addEventListener("mousedown",o),()=>{l.removeEventListener("mouseup",r),l.removeEventListener("mousedown",o)}},[pe,re]),a.useEffect(()=>{const l=Ae.current;if(!l)return;let r=0,o=0,c=0;const Pe=250,Le=600,Re=80,Y=1.5,We=O=>{let T=O instanceof HTMLElement?O:null;for(;T&&T!==l;){const Ve=window.getComputedStyle(T).overflowX;if((Ve==="auto"||Ve==="scroll")&&T.scrollWidth>T.clientWidth)return!0;T=T.parentElement}return!1},He=O=>{const T=Date.now();if(T<c){O.preventDefault();return}if(Math.abs(O.deltaX)<=Math.abs(O.deltaY)*Y){r=0;return}if(We(O.target)){r=0;return}T-o>Pe&&(r=0),o=T,r+=O.deltaX,r<=-Re?(r=0,c=T+Le,O.preventDefault(),pe()):r>=Re&&(r=0,c=T+Le,O.preventDefault(),re())};return l.addEventListener("wheel",He,{passive:!1}),()=>l.removeEventListener("wheel",He)},[pe,re]);const Ie=Ht(),he=a.useMemo(()=>{if(!f)return null;const l=new Set,r=[];for(const o of Ie.values())o.archived||o.directories.length===0||o.assignedAgentIds.includes(d)&&(l.add(o.id),r.push(o));for(const o of Ie.values())o.archived||o.directories.length===0||l.has(o.id)||ta({x:f.position.x,z:f.position.z},o)&&(l.add(o.id),r.push(o));return r.length===0?null:r.flatMap(o=>o.directories.filter(c=>c&&c.trim().length>0).map(c=>({areaId:o.id,areaName:o.name,dir:c})))},[f,d,Ie]),{branches:Ke,fetchRemote:Ze,fetchingDirs:Je}=Tn(he),ge=a.useMemo(()=>{var o;const l=x.getAreaForAgent(d);if(!l)return[];const r=[];for(const c of F.values())c.type==="terminal"&&x.isPositionInArea(c.position,l)&&r.push({id:c.id,name:c.name,hasUrl:!!((o=c.terminalStatus)!=null&&o.url)});return r},[d,F]),Qe=a.useMemo(()=>{var o;const l=x.getAreaForAgent(d);if(!l)return[];const r=[];for(const c of F.values())c.type==="server"&&((o=c.pm2)!=null&&o.enabled)&&x.isPositionInArea(c.position,l)&&r.push({id:c.id,name:c.name});return r},[d,F]),xe=a.useMemo(()=>{const l=x.getAreaForAgent(d);if(!l)return[];const r=[];for(const o of F.values())o.type==="database"&&o.database&&x.isPositionInArea(o.position,l)&&r.push({id:o.id,name:o.name});return r},[d,F]),[,be]=a.useReducer(l=>l+1,0),H=((ne=W.current)==null?void 0:ne.search.searchMode)??!1,oe=a.useCallback(()=>{var l;(l=W.current)==null||l.search.toggleSearch(),be()},[]),et=Pn(),ze=et.isPending(Ft),[V,X]=a.useState(null),D=V?F.get(V):null,{height:Se,onResizeStart:G}=Ln(),{sidePanelWidth:Ee,handleSidePanelResizeStart:ce}=Rn(),[z,tt]=a.useState(()=>At(y.GIT_PANEL_OPEN,!1)),[_e,$e]=a.useState(()=>At(y.BUILDINGS_PANEL_OPEN,!1)),[U,nt]=a.useState(!1),bt=a.useCallback(()=>{nt(l=>{const r=!l;return r&&Dn.setEnabled(!0),r})},[]),we=a.useCallback(()=>nt(!1),[]),_t=a.useCallback(()=>{tt(l=>{const r=!l;return le(y.GIT_PANEL_OPEN,r),r})},[]),at=a.useCallback(()=>{$e(l=>{const r=!l;return le(y.BUILDINGS_PANEL_OPEN,r),r})},[]),wt=a.useCallback(()=>{tt(!1),le(y.GIT_PANEL_OPEN,!1)},[]),Oe=a.useCallback(()=>{$e(!1),le(y.BUILDINGS_PANEL_OPEN,!1)},[]),vt=zn();a.useEffect(()=>{if(!V)return;ge.some(r=>r.id===V)||X(null)},[V,ge]);const[ve,de]=a.useState(!1),Be=a.useRef(null);if(a.useEffect(()=>{if(!ve)return;const l=r=>{Be.current&&!Be.current.contains(r.target)&&de(!1)};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[ve]),!f)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const Q=f.contextStats,st=!!Q,Ce=Q?Q.totalTokens:f.contextUsed||0,h=Q?Q.contextWindow:f.contextLimit||2e5,ee=Q?Q.usedPercent:Math.round(Ce/h*100),M=Math.max(0,Math.min(100,ee)),Me=Math.round(M*10)/10,lt=Math.round((100-M)*10)/10,it=M>=80?"#ff4a4a":M>=60?"#ff9e4a":M>=40?"#ffd700":"#4aff9e",rt=(Ce/1e3).toFixed(1),ot=(h/1e3).toFixed(1),te=f.cwd,Te=te?Qn(te):null,q=((ct=f.subordinateIds)==null?void 0:ct.length)||0,Fe=q>0;return e.jsxs("div",{ref:Ae,className:`flat-terminal-wrapper ${z||_e||U?"flat-terminal-wrapper--with-side-panel":""}`,style:{"--guake-side-panel-width":`min(${Ee}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${me?"flat-terminal-wrapper__header-main--active":""}`,onClick:Ye,onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),J({x:l.clientX,y:l.clientY})},title:me?"Hide agent info":"Show agent info","aria-pressed":me,children:[e.jsx(Xt,{agent:f,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:f.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:Gt(f.status)},children:f.status})]}),f.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:f.taskLabel,children:["📋 ",f.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:f.provider==="codex"?"/assets/codex.png":f.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:f.provider,className:"flat-terminal-wrapper__header-provider-icon",title:f.provider==="codex"?"Codex Agent":f.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:l,effort:r}=ea(f);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:r?`Model: ${l} · Effort: ${r}`:`Model: ${l}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:l}),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.jsx("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:Yn.map(l=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${v===l?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>A(l),title:Jn[l],"aria-pressed":v===l,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:Zn[l]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Kn[l]})]},l))}),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:pe,disabled:!Ue,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(u,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:re,disabled:!qe,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(u,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${H?"flat-terminal-wrapper__action-btn--active":""}`,onClick:oe,title:H?"Close search":"Search messages","aria-pressed":H,children:e.jsx(u,{name:H?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${ze?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>et.handleClick(Ft,()=>{var l;x.clearContext(d),(l=W.current)==null||l.historyLoader.clearHistory()}),title:ze?"Click again to confirm clear context":"Clear context",children:e.jsx(u,{name:ze?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${z?"flat-terminal-wrapper__action-btn--active":""}`,onClick:_t,title:z?"Hide git panel":"Show git changes","aria-pressed":z,children:e.jsx(u,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${_e?"flat-terminal-wrapper__action-btn--active":""}`,onClick:at,title:_e?"Hide buildings panel":"Show area buildings","aria-pressed":_e,children:e.jsx(u,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:Be,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ve?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>de(l=>!l),title:"More actions","aria-expanded":ve,children:"⋮"}),ve&&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 ${U?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{bt(),de(!1)},title:U?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(u,{name:"bug",size:14}),e.jsx("span",{children:U?"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:()=>{x.collapseContext(d),de(!1)},disabled:f.status!=="idle",title:f.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(u,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),Fe&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{Z(d,q),de(!1)},children:[e.jsx(u,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",q," subordinate",q===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:()=>{x.killAgent(d),de(!1)},children:[e.jsx(u,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${E?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:K,title:E?"Hide inspector panel":"Show inspector panel","aria-label":E?"Hide inspector panel":"Show inspector panel","aria-pressed":E,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:()=>x.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(u,{name:"cross",size:14})})]})]}),e.jsx($n,{ref:W,agentId:d,agent:f,viewMode:v,isOpen:!0,onImageClick:B,onFileClick:De,onBashClick:ie,onViewMarkdown:g,keyboard:Ge,hasModalOpen:!1}),D&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:G,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${D.name}`,style:{height:Se},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(u,{name:"terminal",size:12}),e.jsx("span",{children:D.name}),!(($=D.terminalStatus)!=null&&$.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>X(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(u,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:(ae=D.terminalStatus)!=null&&ae.url?e.jsx(On,{terminalUrl:D.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."})})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[f.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(u,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),te&&Te&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${te}`,"aria-label":`Open ${te} in file explorer`,role:"button",tabIndex:0,onClick:()=>x.openFileExplorer(te),onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),x.openFileExplorer(te))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(u,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:Te})]}),he&&he.map(({areaId:l,areaName:r,dir:o})=>{const c=Ke.get(o),Pe=Je.has(o),Le=o.split("/").filter(Boolean).pop()||o;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${r}: ${o}${c?` (${c.branch}${c.ahead?` ↑${c.ahead}`:""}${c.behind?` ↓${c.behind}`:""})`:""}`,onClick:()=>x.openFileExplorerForAreaFolder(l,o),children:[e.jsx(u,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:Le}),c&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(u,{name:"git-branch",size:10})," ",c.branch]}),c.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${c.ahead} ahead`,children:[e.jsx(u,{name:"arrow-up",size:9}),c.ahead]}),c.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${c.behind} behind`,children:[e.jsx(u,{name:"arrow-down",size:9}),c.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${Pe?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:Re=>{Re.stopPropagation(),Ze(o)},children:e.jsx(u,{name:Pe?"hourglass":"download",size:12})})]})]},`${l}:${o}`)}),e.jsxs("span",{className:"flat-terminal-wrapper__context",onClick:()=>x.setContextModalAgentId(d),title:st?`Context usage: ${rt}k / ${ot}k tokens (${Me}% used). Click to view stats.`:"Click to fetch context stats",children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(u,{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:`${M}%`,backgroundColor:it}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:it},children:[rt,"k/",ot,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",lt,"% free)"]}),!st&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(u,{name:"warn",size:12})})]}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),ge.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:ge.map(l=>{const r=V===l.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""} ${l.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${r?"Hide":"Show"} terminal: ${l.name}${l.hasUrl?"":" (starting...)"}`,onClick:()=>{if(r){X(null);return}l.hasUrl||x.sendBuildingCommand(l.id,"start"),X(l.id)},onContextMenu:o=>{o.preventDefault(),o.stopPropagation(),fe(l.id,{x:o.clientX,y:o.clientY})},children:e.jsx(u,{name:"terminal",size:14})},l.id)})}),Qe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Qe.map(l=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${l.name}`,onClick:()=>ye(l.id),onContextMenu:r=>{r.preventDefault(),r.stopPropagation(),fe(l.id,{x:r.clientX,y:r.clientY})},children:e.jsx(u,{name:"scroll",size:14})},l.id))}),xe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:xe.map(l=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${l.name}`,onClick:()=>ye(l.id),onContextMenu:r=>{r.preventDefault(),r.stopPropagation(),fe(l.id,{x:r.clientX,y:r.clientY})},children:e.jsx(u,{name:"hard-drives",size:14})},l.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(Bn,{})})]}),z&&e.jsx(Fn,{agentId:d,agents:vt,onClose:wt,branchInfoMap:Ke,fetchRemote:Ze,fetchingDirs:Je,onResizeStart:l=>ce(l,"right")}),_e&&e.jsx(Wn,{agentId:d,onClose:Oe}),U&&e.jsx(Hn,{agentId:d,onClose:we})]})});function ia({onAgentClick:w,onBuildingClick:d,onBuildingDoubleClick:v,onBuildingPopup:A,onAreaContextMenu:E,onOpenSpawnModal:K,onOpenBossSpawnModal:B,onOpenAreaModal:De}){const{t:ie}=Wt(["common"]),g=dn(),Z=un(),[ye,Ge]=a.useState(null),[Ue,qe]=a.useState(null),[pe,re]=a.useState(null),[me,Ye]=a.useState(null),[J,fe]=a.useState(null),[f,F]=a.useState(null),[W,Ae]=a.useState(null),[Ie,he]=a.useState(!1),Ke=a.useCallback(()=>{he(t=>!t)},[]),Ze=a.useCallback(()=>{he(!1)},[]),[Je,ge]=a.useState(()=>{const t=Pt(y.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Qe=a.useCallback(t=>{ge(t),Lt(y.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=n=>{if(n.key!==y.VIEW_MODE)return;const s=n.newValue;(s==="simple"||s==="chat"||s==="advanced")&&ge(s)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[xe,be]=a.useState(()=>At(y.FLAT_INSPECTOR_OPEN,!1)),[H,oe]=a.useState(!1),et=a.useCallback(()=>oe(t=>!t),[]),ze=a.useCallback(()=>oe(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:H}}))},[H]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:xe}}))},[xe]),a.useEffect(()=>{const t=()=>oe(_=>!_),n=()=>{be(_=>{const i=!_;return le(y.FLAT_INSPECTOR_OPEN,i),i})},s=()=>{oe(!1),be(!1),le(y.FLAT_INSPECTOR_OPEN,!1)},p=()=>oe(!1),m=()=>{be(!1),le(y.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",n),window.addEventListener("tide-close-flat-side-views",s),window.addEventListener("tide-close-flat-agents-drawer-only",p),window.addEventListener("tide-close-flat-inspector-only",m),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",n),window.removeEventListener("tide-close-flat-side-views",s),window.removeEventListener("tide-close-flat-agents-drawer-only",p),window.removeEventListener("tide-close-flat-inspector-only",m)}},[]);const V=a.useRef(null),X=a.useRef(null),[D,Se]=a.useState(()=>{const t=Rt(y.FLAT_MIDDLE_WIDTH,0);return t>=xt?t:null}),[G,Ee]=a.useState(()=>{const t=Rt(y.FLAT_INSPECTOR_WIDTH,0);return t>=yt?t:null}),ce=a.useCallback(t=>{if(typeof window>"u")return t;const n=G!==null?gt+G:0,s=window.innerWidth-Bt-gt-Ot-n;return Math.max(xt,Math.min(Math.max(s,xt),t))},[G]),z=a.useCallback(t=>{var m;if(typeof window>"u")return t;const n=(m=V.current)==null?void 0:m.querySelector(".flat-middle"),s=(n==null?void 0:n.getBoundingClientRect().width)??xt,p=window.innerWidth-Bt-s-gt-Ot-gt;return Math.max(yt,Math.min(Math.max(p,yt),t))},[]);a.useEffect(()=>{if(D===null&&G===null)return;const t=()=>{Se(n=>{if(n===null)return n;const s=ce(n);return s===n?n:s}),Ee(n=>{if(n===null)return n;const s=z(n);return s===n?n:s})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[D,G,ce,z]);const tt=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=V.current)==null?void 0:s.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),X.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),_e=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=V.current)==null?void 0:s.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),X.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),$e=a.useCallback(t=>{const n=X.current;if(!n||t.pointerId!==n.pointerId)return;const s=t.clientX-n.startX;n.kind==="middle"?Se(ce(n.startWidth+s)):Ee(z(n.startWidth-s))},[ce,z]),U=a.useCallback(t=>{const n=X.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(X.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const p=t.clientX-n.startX;if(n.kind==="middle"){const m=ce(n.startWidth+p);Se(m),ht(y.FLAT_MIDDLE_WIDTH,m)}else{const m=z(n.startWidth-p);Ee(m),ht(y.FLAT_INSPECTOR_WIDTH,m)}},[ce,z]),nt=a.useCallback(()=>{Se(null),ht(y.FLAT_MIDDLE_WIDTH,0)},[]),bt=a.useCallback(()=>{Ee(null),ht(y.FLAT_INSPECTOR_WIDTH,0)},[]),[we,_t]=a.useState(()=>Pt(y.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),at=a.useCallback(t=>{_t(t),Lt(y.FLAT_INSPECTOR_VIEW,t)},[]),wt=a.useCallback(()=>{be(t=>{const n=!t;return le(y.FLAT_INSPECTOR_OPEN,n),n})},[]),Oe=a.useCallback(()=>{be(!1),le(y.FLAT_INSPECTOR_OPEN,!1)},[]),vt=pn(),ve=a.useCallback((t,n)=>{Ge({url:t,name:n})},[]),de=a.useCallback((t,n)=>{qe({command:t,output:n,isLive:!1})},[]),Be=a.useCallback((t,n)=>{x.setFileViewerPath(t,n)},[]),Q=a.useCallback(t=>{re(t)},[]),st=a.useCallback((t,n)=>{Ye({agentId:t,count:n})},[]),Ce=a.useCallback(t=>{v?v(t):d(t)},[d,v]),h=a.useMemo(()=>Z.size>0?Array.from(Z)[0]:null,[Z]);a.useEffect(()=>{he(!1)},[h]);const ee=a.useRef([]),M=a.useRef(-1),Me=a.useRef(!1),lt=a.useRef(null),[it,rt]=a.useState(!1),[ot,te]=a.useState(!1),Te=a.useRef(!1),q=a.useRef(null),Fe=a.useRef(!1),ne=a.useMemo(()=>new Set(g.map(t=>t.id)),[g]),ct=a.useMemo(()=>{const t=new Map(g.map(s=>[s.id,s])),n=new Map;for(const s of g)if((s.isBoss||s.class==="boss")&&s.subordinateIds&&s.subordinateIds.length>0){const p=s.subordinateIds.map(m=>t.get(m)).filter(m=>m!==void 0);p.length>0&&n.set(s.id,p)}return n},[g]),$=a.useCallback(()=>{const t=ee.current,n=M.current;rt(n>0),te(n>=0&&n<t.length-1)},[]),ae=a.useCallback(t=>{const n=ee.current;if(n.length===0)return;let s=M.current+t;for(;s>=0&&s<n.length;){const p=n[s];if(ne.has(p)){Me.current=!0,M.current=s,$(),x.selectAgent(p);return}s+=t}},[ne,$]),l=a.useCallback(()=>ae(-1),[ae]),r=a.useCallback(()=>ae(1),[ae]);Un(a.useCallback(()=>{const t=ee.current,n=M.current;return t.length>0&&n>0?(ae(-1),"handled"):"exit"},[ae]));const o=a.useCallback((t,n)=>{if(typeof window>"u")return;const s=window.history.state,m={...typeof s=="object"&&s!==null?s:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(m,"",window.location.href):window.history.pushState(m,"",window.location.href)},[]);a.useEffect(()=>{if(!h){Te.current=!1,q.current=null;return}if(!Te.current){o(h,"replace"),Te.current=!0,q.current=h;return}if(Fe.current){Fe.current=!1,q.current=h;return}q.current!==h&&(o(h,"push"),q.current=h)},[h,o]),a.useEffect(()=>{const t=n=>{var _,i;const s=(i=(_=n.state)==null?void 0:_.__flatAgentNav)==null?void 0:i.agentId;if(!s||typeof s!="string"||!ne.has(s)||s===h)return;Fe.current=!0,Me.current=!0;const p=ee.current,m=p.lastIndexOf(s);m>=0?M.current=m:(p.push(s),M.current=p.length-1),$(),x.selectAgent(s)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[ne,h,$]),a.useEffect(()=>{if(!h){ee.current=[],M.current=-1,$();return}if(lt.current=h,Me.current){Me.current=!1,$();return}const t=ee.current,n=M.current;if(n>=0&&t[n]===h){$();return}const s=n<t.length-1?t.slice(0,n+1):t.slice();s.push(h),s.length>100&&s.shift(),ee.current=s,M.current=s.length-1,$()},[h,$]);const c=a.useCallback(t=>{w(t),oe(!1)},[w]),Pe=h??"",Le=a.useCallback(()=>{},[]),Re=a.useCallback(t=>{c(t)},[c]),Y=xe,[We,He]=a.useState(Y),[O,T]=a.useState(Y);a.useEffect(()=>{if(Y){He(!0);return}T(!1);const t=setTimeout(()=>He(!1),240);return()=>clearTimeout(t)},[Y]),a.useEffect(()=>{if(!We||!Y)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>T(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[We,Y]);const Ve=a.useRef(null);a.useEffect(()=>{if(h)return;const t=n=>{if(n.key!==" "&&n.key!=="Backspace")return;const s=n.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const p=lt.current;!p||!ne.has(p)||(n.preventDefault(),x.selectAgent(p))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[h,ne]);const[Ut,It]=a.useState(new Set),qt=a.useCallback(t=>{It(n=>{const s=new Set(n);return s.has(t)?s.delete(t):s.add(t),s})},[]),[je,Yt]=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)"),n=s=>Yt(s.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const[dt,Kt]=a.useState(null),Zt=a.useCallback(t=>{Kt(n=>n===t?null:t)},[]),Ct=Ht(),ut=Vt(),[Jt]=mn(),Ne=a.useMemo(()=>{const t=new Map,n=[];for(const b of g){const k=x.getAreaForAgent(b.id);if(!Dt((k==null?void 0:k.id)??null))continue;if(!k||k.archived){n.push(b);continue}const N=t.get(k.id);N?N.push(b):t.set(k.id,[b])}const s=new Map,p=[];for(const b of ut.values()){let k=!1;for(const N of Ct.values())if(!N.archived&&zt(N.id)&&x.isPositionInArea(b.position,N)){const se=s.get(N.id);se?se.push(b):s.set(N.id,[b]),k=!0;break}!k&&Dt(null)&&p.push(b)}const m=[];for(const[,b]of Ct){if(b.archived||!zt(b.id))continue;const k=t.get(b.id),N=s.get(b.id)??[];(k&&k.length>0||N.length>0)&&m.push({area:b,agents:k??[],buildings:N})}(n.length>0||p.length>0)&&m.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:n,buildings:p});const _=m.filter(b=>b.area.id!=="__unassigned__"),i=m.filter(b=>b.area.id==="__unassigned__");let I=1,j=1;const S=new Map;if(_.length>1){let b=1/0,k=-1/0,N=1/0,se=-1/0;for(const L of _)b=Math.min(b,L.area.center.x),k=Math.max(k,L.area.center.x),N=Math.min(N,L.area.center.z),se=Math.max(se,L.area.center.z);const pt=k-b||1,mt=se-N||1;if(_.length<=4){I=_.length,j=1;const L=[..._].sort((R,jt)=>R.area.center.x-jt.area.center.x);for(let R=0;R<L.length;R++)S.set(L[R].area.id,{row:1,col:R+1})}else{const L=[..._].sort((C,P)=>C.area.center.x-P.area.center.x),R=[];for(let C=1;C<L.length;C++)R.push(L[C].area.center.x-L[C-1].area.center.x);const jt=R.reduce((C,P)=>C+P,0)/R.length||1;let St=1;for(const C of R)C>jt*1.3&&St++;I=Math.max(2,Math.min(St,_.length));const Nt=[..._].sort((C,P)=>C.area.center.z-P.area.center.z),ft=[];for(let C=1;C<Nt.length;C++)ft.push(Nt[C].area.center.z-Nt[C-1].area.center.z);const nn=ft.reduce((C,P)=>C+P,0)/ft.length||1;let Et=1;for(const C of ft)C>nn*1.3&&Et++;j=Math.max(2,Math.min(Et,_.length)),I=Math.max(I,Math.ceil(_.length/j)),j=Math.max(j,Math.ceil(_.length/I));const an=pt/I,sn=mt/j,kt=new Set;for(const C of _){let P=Math.min(I-1,Math.max(0,Math.floor((C.area.center.x-b)/an))),ke=Math.min(j-1,Math.max(0,Math.floor((C.area.center.z-N)/sn))),Xe=`${ke},${P}`,Mt=0;const ln=j*I;for(;kt.has(Xe)&&Mt<ln;)P++,P>=I&&(P=0,ke=(ke+1)%j),Xe=`${ke},${P}`,Mt++;kt.has(Xe)&&(ke=j,P=0,Xe=`${ke},${P}`,j++),kt.add(Xe),S.set(C.area.id,{row:ke+1,col:P+1})}}}const ue=b=>{b.sort((k,N)=>{var pt,mt,L,R;const se=(((pt=k.position)==null?void 0:pt.z)??0)-(((mt=N.position)==null?void 0:mt.z)??0);return se!==0?se:(((L=k.position)==null?void 0:L.x)??0)-(((R=N.position)==null?void 0:R.x)??0)})};for(const b of _)ue(b.agents);for(const b of i)ue(b.agents);return{groups:[..._,...i],gridCols:I,gridRows:j,positions:S}},[g,Ct,ut,Jt]),Qt=a.useMemo(()=>{if(!J)return[];const t=g.find(n=>n.id===J.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(u,{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(u,{name:"chat",size:14}),onClick:()=>w(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>{Ae({agentId:t.id,name:t.name})}}]:[]},[J,g,w]),en=a.useMemo(()=>{var _;if(!f)return[];const t=ut.get(f.buildingId);if(!t)return[];const n=[],s=t.type==="server"||t.type==="docker"||t.type==="terminal",p=t.status==="running",m=t.type==="boss";if(n.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((_=t.pm2)!=null&&_.enabled)?"View PM2 Logs":"Open",icon:e.jsx(u,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>Ce(t.id)}),s&&(p||n.push({id:"start",label:"Start",icon:e.jsx(u,{name:"play",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"start")}),p&&(n.push({id:"restart",label:"Restart",icon:e.jsx(u,{name:"refresh",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(u,{name:"stop",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"stop")}))),m&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(n.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(u,{name:"launch",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"start")}}),n.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(u,{name:"pause",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"stop")}}),n.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(u,{name:"restart",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"restart")}})),s&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(u,{name:"health",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"healthCheck")}),n.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),n.push({id:"edit",label:"Edit Building",icon:e.jsx(u,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),n.push({id:"clone",label:"Clone Building",icon:e.jsx(u,{name:"copy",size:14}),onClick:()=>{x.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 i of t.urls)n.push({id:`url-${i.label}`,label:i.label,icon:e.jsx(u,{name:"link",size:14}),onClick:()=>window.open(i.url,"_blank","noopener,noreferrer")});return n.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),n.push({id:"delete",label:"Delete Building",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>x.deleteBuilding(t.id)}),n},[f,ut,Ce]),tn=a.useCallback(t=>{const n=new Set(Ne.groups.map(s=>s.area.id));n.delete(t),It(n),requestAnimationFrame(()=>{const s=Ve.current;if(!s)return;const p=s.querySelector(`[data-area-id="${t}"]`);if(!p)return;const m=s.getBoundingClientRect(),i=p.getBoundingClientRect().top-m.top+s.scrollTop-8;s.scrollTo({top:Math.max(0,i),behavior:"smooth"})})},[Ne]);return e.jsxs("div",{ref:V,className:`flat-view ${Y?"flat-view--with-inspector":""} ${h?"flat-view--has-chat":""} ${H?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(D===null&&G===null)return;const t={};return D!==null&&(t["--flat-middle-width"]=`${D}px`),G!==null&&(t["--flat-inspector-width"]=`${G}px`),t})(),children:[H&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:ze,"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:K,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:B,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:De,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(fn,{activeAgentId:Pe,onClose:Le,onSelectAgent:Re,collapsedAreas:Ut,onToggleArea:qt,agentListRef:Ve})})]}),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:$e,onPointerUp:U,onPointerCancel:U,onDoubleClick:nt}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":H?"Close agents sidebar":"Open agents sidebar","aria-expanded":H,onClick:et,children:[e.jsx(u,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),h?e.jsx(na,{agentId:h,terminalViewMode:Je,onTerminalViewModeChange:Qe,inspectorOpen:xe,onToggleInspector:wt,onImageClick:ve,onFileClick:Be,onBashClick:de,onViewMarkdown:Q,onRequestClearSubordinates:st,onOpenBuilding:Ce,keyboard:vt,canNavigateBack:it,canNavigateForward:ot,onNavigateBack:l,onNavigateForward:r,agentInfoOpen:Ie,onToggleAgentInfo:Ke,onHeaderContextMenu:t=>{h&&fe({agentId:h,position:t})},onBuildingContextMenu:(t,n)=>{F({buildingId:t,position:n})}}):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(qn,{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 n;const t=je&&dt?((n=Ne.positions.get(dt))==null?void 0:n.row)??null:null;return Ne.groups.map(s=>{const p=s.area.id,m=Ne.positions.get(p),_=je&&dt!==p;return je&&t!=null&&(m==null?void 0:m.row)===t&&p!==dt?null:e.jsxs("div",{className:`flat-map-area-card${_?" flat-map-area-card--collapsed":""}`,style:{"--area-color":s.area.color,gridRow:m==null?void 0:m.row,gridColumn:m==null?void 0:m.col},onContextMenu:i=>{E&&(i.preventDefault(),i.stopPropagation(),E(p,{x:i.clientX,y:i.clientY}))},children:[e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>je?Zt(p):tn(p),title:je?_?`Expand ${s.area.name}`:`Collapse ${s.area.name}`:`Focus ${s.area.name} in left panel`,"aria-expanded":je?!_:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:s.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:s.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:s.agents.length}),je&&e.jsx(u,{name:_?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:s.agents.map(i=>{const I=i.isBoss||i.class==="boss",j=I?ct.get(i.id):void 0,S=hn(i),ue=S.usedPercent>=80?"#ff4a4a":S.usedPercent>=60?"#ff9e4a":S.usedPercent>=40?"#ffd700":"#4aff9e",b=`Context: ${(S.totalTokens/1e3).toFixed(1)}k / ${(S.contextWindow/1e3).toFixed(1)}k (${S.usedPercent}% used, ${S.freePercent}% free)`,k=i.latestTodos&&i.latestTodos.length>0||j&&j.length>0;return e.jsx(gn,{todos:i.latestTodos,subordinates:j,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${i.status}`,onClick:()=>w(i.id),onContextMenu:N=>{N.preventDefault(),N.stopPropagation(),fe({agentId:i.id,position:{x:N.clientX,y:N.clientY}})},title:k?void 0:`${I?"Boss · ":""}Open chat with ${i.name}
|
|
2
2
|
${b}`,children:[e.jsx(Xt,{agent:i,size:16}),I&&e.jsx("span",{className:"flat-map-agent-chip__crown","aria-hidden":"true",children:e.jsx(u,{name:"crown",size:11,color:"#ffd700",weight:"fill"})}),e.jsx("span",{className:"flat-map-agent-chip__name",children:i.name}),e.jsx("img",{src:i.provider==="codex"?"/assets/codex.png":i.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:i.provider,className:"flat-map-agent-chip__provider-icon",title:i.provider==="codex"?"Codex Agent":i.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:Gt(i.status)}}),i.latestTodos&&i.latestTodos.length>0&&e.jsx(xn,{todos:i.latestTodos,maxDots:6}),I&&j&&j.length>0&&e.jsx(bn,{subordinates:j,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:`${S.usedPercent}%`,backgroundColor:ue}})})]})},i.id)})}),s.area.directories.length>0&&e.jsx("div",{className:"flat-map-area-card__folders",role:"group","aria-label":`${s.area.name} folders`,children:s.area.directories.map(i=>{const I=i.split("/").filter(Boolean).pop()||i;return e.jsxs("button",{type:"button",className:"flat-map-folder-chip",onClick:j=>{j.stopPropagation(),x.openFileExplorerForAreaFolder(p,i)},title:`Open in file explorer: ${i}`,children:[e.jsx(u,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-map-folder-chip__name",children:I})]},i)})}),s.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:s.buildings.map(i=>{var j;const I=(j=_n[i.type])==null?void 0:j.color;return e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${i.status}`,style:I?{"--building-type-color":I}:void 0,onClick:S=>{if(A){const ue=S.currentTarget.getBoundingClientRect();A(i.id,{x:ue.right,y:ue.top+ue.height/2})}else Ce(i.id)},onContextMenu:S=>{S.preventDefault(),S.stopPropagation(),F({buildingId:i.id,position:{x:S.clientX,y:S.clientY}})},title:`${i.name} · ${i.type} · ${i.status}`,children:[e.jsx(u,{name:wn(i.type),size:12,color:I}),e.jsx("span",{className:"flat-map-building-chip__name",children:i.name}),e.jsx("span",{className:"flat-map-building-chip__dot",style:{backgroundColor:vn(i.status)}})]},i.id)})})]},p)})})()})]})})]}),Y&&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:_e,onPointerMove:$e,onPointerUp:U,onPointerCancel:U,onDoubleClick:bt}),We&&e.jsxs("aside",{className:`flat-inspector ${O?"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":we==="agent",className:`flat-inspector__tab ${we==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>at("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":we==="tracking",className:`flat-inspector__tab ${we==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>at("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:we==="tracking"?e.jsx(Cn,{activeAgentId:h??"",onSelectAgent:t=>{w(t),window.innerWidth<=768&&Oe()}}):(()=>{if(!h)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=g.find(n=>n.id===h);return t?e.jsx(jn,{agent:t,onFocusAgent:n=>{w(n),window.innerWidth<=768&&Oe()},onKillAgent:n=>x.killAgent(n)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),ye&&e.jsx(Nn,{url:ye.url,name:ye.name,onClose:()=>Ge(null)}),Ue&&e.jsx(kn,{state:Ue,onClose:()=>qe(null)}),e.jsx(yn,{agent:h?g.find(t=>t.id===h)??null:null,content:pe,onClose:()=>re(null)}),me&&e.jsx(An,{action:"clear-subordinates",selectedAgentId:me.agentId,subordinateCount:me.count,onClose:()=>Ye(null),onClearHistory:()=>{}}),e.jsx(In,{agent:h?g.find(t=>t.id===h)??null:null,isOpen:Ie&&!!h,onClose:Ze}),e.jsx($t,{isOpen:J!==null,position:(J==null?void 0:J.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:Qt,onClose:()=>fe(null)}),e.jsx($t,{isOpen:f!==null,position:(f==null?void 0:f.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:en,onClose:()=>F(null)}),e.jsx(Sn,{isOpen:W!==null,title:ie("common:confirm.removeAgentTitle"),message:ie("common:confirm.removeAgentMessage",{name:(W==null?void 0:W.name)??""}),confirmLabel:ie("common:buttons.remove"),cancelLabel:ie("common:buttons.cancel"),variant:"danger",onConfirm:()=>{W&&x.removeAgentFromServer(W.agentId)},onClose:()=>Ae(null)})]})}export{ia as FlatView};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{bq as Oe,r as t,s as I,i as ye,br as Ee,h as _e,j as e,I as z,u as fe,bs as ze,bt as Te,bu as Be,bv as Ue,n as Ke,bw as We,bx as De,by as Ve,a8 as qe,a9 as Ge,aa as Ye,aV as Je,K as Me,S as oe,aP as Xe,aM as Qe,$ as Ze,L as Ie,al as et,W as tt,bz as st,o as X,bA as nt}from"./main-
|
|
1
|
+
import{bq as Oe,r as t,s as I,i as ye,br as Ee,h as _e,j as e,I as z,u as fe,bs as ze,bt as Te,bu as Be,bv as Ue,n as Ke,bw as We,bx as De,by as Ve,a8 as qe,a9 as Ge,aa as Ye,aV as Je,K as Me,S as oe,aP as Xe,aM as Qe,$ as Ze,L as Ie,al as et,W as tt,bz as st,o as X,bA as nt}from"./main-D7pG1mPb.js";import{FileExplorerPanel as at}from"./index-CCSwoBsg.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=Oe(),[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||[],W=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,K=V.get(c)??0;L>K&&V.set(c,L)}const q=I.getOutputs(i.id),U=(C&&C.length>0?[...C,...q]:q).filter(w=>it(w,Y,V,W));I.clearOutputs(i.id);for(const w of U)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,K=Math.min(c.scrollHeight,L);c.style.height=`${K}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 H=await b($);H&&R(H)}return}const K=c.clipboardData.files;if(K.length>0){c.preventDefault();for(const _ of K){const $=await b(_);$&&R($)}return}const B=c.clipboardData.getData("text"),te=(B.match(/\n/g)||[]).length+1;if(te>5){c.preventDefault();const $=`[Pasted text #${E(B)} +${te} lines]`,H=c.target,se=H.selectionStart||0,ae=H.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 K of L){const B=await b(K);B&&R(B)}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=>{},[]),W=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",q=v?"agent-panel-input-container":"guake-input-container",Q=v?"agent-panel-attach-btn":"guake-attach-btn",U=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:q,onAuxClick:W,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:U,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,W]=t.useState(null),[Y,V]=t.useState(null),[q,Q]=t.useState(null);Te(`commander-image-modal-${s.id}`,P!==null,()=>W(null));const{command:U,setCommand:w,forceTextarea:c,setForceTextarea:L,useTextarea:K,setPastedTexts:B,incrementPastedCount:te,resetPastedCount:_,attachedFiles:$,setAttachedFiles:H,removeAttachedFile:se,uploadFile:ae,expandPastedTexts:ne}=Be({selectedAgentId:s.id}),le=U.trim().length>0||$.length>0,n=Ue({outputs:l,viewMode:d?"advanced":"simple"}),o=t.useMemo(()=>{const S=Ke(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 O=0,ue=-1,ke;const Re=()=>{const{scrollTop:Fe,scrollHeight:Se,clientHeight:Le}=S,He=Se-Fe-Le<=2;if(Math.abs(Se-ue)<=1&&He?O+=1:O=0,ue=Se,O>=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 G=t.useCallback(()=>!1,[]),ie=t.useCallback(S=>{const y=te();return B(O=>new Map(O).set(y,S)),y},[te,B]),he=t.useCallback(S=>{H(y=>[...y,S])},[H]),xe=t.useCallback(()=>{if(!le)return;if(U.trim()==="/clear"&&$.length===0){I.clearContext(s.id),b(),w(""),L(!1),B(new Map),H([]),_();return}let S=ne(U.trim());if($.length>0){const y=$.map(O=>O.isImage?`[Image: ${O.path}]`:`[File: ${O.path}]`).join(`
|
|
3
3
|
`);S=S?`${S}
|
|
4
4
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as l,I as V,al as yt,W as xt,X as Et,bZ as Ct,b_ as bt,av as wt,r as f,L as Mt,S as ge,b$ as vt,s as se,c0 as He,$ as Ft,c1 as St,ae as Fe,K as _t,p as st,u as we,a0 as kt}from"./main-CMDpEoqP.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function ne(t){return Array.isArray?Array.isArray(t):it(t)==="[object Array]"}function It(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function jt(t){return t==null?"":It(t)}function Z(t){return typeof t=="string"}function nt(t){return typeof t=="number"}function Bt(t){return t===!0||t===!1||Dt(t)&&it(t)=="[object Boolean]"}function rt(t){return typeof t=="object"}function Dt(t){return rt(t)&&t!==null}function Q(t){return t!=null}function Se(t){return!t.trim().length}function it(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const Nt="Incorrect 'index' type",Rt=t=>`Invalid value for key ${t}`,Tt=t=>`Pattern length exceeds max of ${t}.`,Lt=t=>`Missing ${t} property in key`,$t=t=>`Property 'weight' in key '${t}' must be a positive integer`,Ue=Object.prototype.hasOwnProperty;class Pt{constructor(e){this._keys=[],this._keyMap={};let s=0;e.forEach(r=>{let i=ct(r);this._keys.push(i),this._keyMap[i.id]=i,s+=i.weight}),this._keys.forEach(r=>{r.weight/=s})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function ct(t){let e=null,s=null,r=null,i=1,c=null;if(Z(t)||ne(t))r=t,e=Ye(t),s=_e(t);else{if(!Ue.call(t,"name"))throw new Error(Lt("name"));const o=t.name;if(r=o,Ue.call(t,"weight")&&(i=t.weight,i<=0))throw new Error($t(o));e=Ye(o),s=_e(o),c=t.getFn}return{path:e,id:s,weight:i,src:r,getFn:c}}function Ye(t){return ne(t)?t:t.split(".")}function _e(t){return ne(t)?t.join("."):t}function Ot(t,e){let s=[],r=!1;const i=(c,o,u)=>{if(Q(c))if(!o[u])s.push(c);else{let a=o[u];const h=c[a];if(!Q(h))return;if(u===o.length-1&&(Z(h)||nt(h)||Bt(h)))s.push(jt(h));else if(ne(h)){r=!0;for(let d=0,g=h.length;d<g;d+=1)i(h[d],o,u+1)}else o.length&&i(h,o,u+1)}};return i(t,Z(e)?e.split("."):e,0),r?s:s[0]}const Kt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},zt={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},Qt={location:0,threshold:.6,distance:100},Wt={useExtendedSearch:!1,getFn:Ot,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var A={...zt,...Kt,...Qt,...Wt};const Gt=/[^ ]+/g;function Ht(t=1,e=3){const s=new Map,r=Math.pow(10,e);return{get(i){const c=i.match(Gt).length;if(s.has(c))return s.get(c);const o=1/Math.pow(c,.5*t),u=parseFloat(Math.round(o*r)/r);return s.set(c,u),u},clear(){s.clear()}}}class Ne{constructor({getFn:e=A.getFn,fieldNormWeight:s=A.fieldNormWeight}={}){this.norm=Ht(s,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((s,r)=>{this._keysMap[s.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,Z(this.docs[0])?this.docs.forEach((e,s)=>{this._addString(e,s)}):this.docs.forEach((e,s)=>{this._addObject(e,s)}),this.norm.clear())}add(e){const s=this.size();Z(e)?this._addString(e,s):this._addObject(e,s)}removeAt(e){this.records.splice(e,1);for(let s=e,r=this.size();s<r;s+=1)this.records[s].i-=1}getValueForItemAtKeyId(e,s){return e[this._keysMap[s]]}size(){return this.records.length}_addString(e,s){if(!Q(e)||Se(e))return;let r={v:e,i:s,n:this.norm.get(e)};this.records.push(r)}_addObject(e,s){let r={i:s,$:{}};this.keys.forEach((i,c)=>{let o=i.getFn?i.getFn(e):this.getFn(e,i.path);if(Q(o)){if(ne(o)){let u=[];const a=[{nestedArrIndex:-1,value:o}];for(;a.length;){const{nestedArrIndex:h,value:d}=a.pop();if(Q(d))if(Z(d)&&!Se(d)){let g={v:d,i:h,n:this.norm.get(d)};u.push(g)}else ne(d)&&d.forEach((g,E)=>{a.push({nestedArrIndex:E,value:g})})}r.$[c]=u}else if(Z(o)&&!Se(o)){let u={v:o,n:this.norm.get(o)};r.$[c]=u}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function ot(t,e,{getFn:s=A.getFn,fieldNormWeight:r=A.fieldNormWeight}={}){const i=new Ne({getFn:s,fieldNormWeight:r});return i.setKeys(t.map(ct)),i.setSources(e),i.create(),i}function Ut(t,{getFn:e=A.getFn,fieldNormWeight:s=A.fieldNormWeight}={}){const{keys:r,records:i}=t,c=new Ne({getFn:e,fieldNormWeight:s});return c.setKeys(r),c.setIndexRecords(i),c}function xe(t,{errors:e=0,currentLocation:s=0,expectedLocation:r=0,distance:i=A.distance,ignoreLocation:c=A.ignoreLocation}={}){const o=e/t.length;if(c)return o;const u=Math.abs(r-s);return i?o+u/i:u?1:o}function Yt(t=[],e=A.minMatchCharLength){let s=[],r=-1,i=-1,c=0;for(let o=t.length;c<o;c+=1){let u=t[c];u&&r===-1?r=c:!u&&r!==-1&&(i=c-1,i-r+1>=e&&s.push([r,i]),r=-1)}return t[c-1]&&c-r>=e&&s.push([r,c-1]),s}const ue=32;function Vt(t,e,s,{location:r=A.location,distance:i=A.distance,threshold:c=A.threshold,findAllMatches:o=A.findAllMatches,minMatchCharLength:u=A.minMatchCharLength,includeMatches:a=A.includeMatches,ignoreLocation:h=A.ignoreLocation}={}){if(e.length>ue)throw new Error(Tt(ue));const d=e.length,g=t.length,E=Math.max(0,Math.min(r,g));let m=c,p=E;const M=u>1||a,w=M?Array(g):[];let N;for(;(N=t.indexOf(e,p))>-1;){let T=xe(e,{currentLocation:N,expectedLocation:E,distance:i,ignoreLocation:h});if(m=Math.min(T,m),p=N+d,M){let P=0;for(;P<d;)w[N+P]=1,P+=1}}p=-1;let $=[],W=1,G=d+g;const oe=1<<d-1;for(let T=0;T<d;T+=1){let P=0,I=G;for(;P<I;)xe(e,{errors:T,currentLocation:E+I,expectedLocation:E,distance:i,ignoreLocation:h})<=m?P=I:G=I,I=Math.floor((G-P)/2+P);G=I;let ae=Math.max(1,E-I+1),H=o?g:Math.min(E+I,g)+d,v=Array(H+2);v[H+1]=(1<<T)-1;for(let j=H;j>=ae;j-=1){let q=j-1,U=s[t.charAt(q)];if(M&&(w[q]=+!!U),v[j]=(v[j+1]<<1|1)&U,T&&(v[j]|=($[j+1]|$[j])<<1|1|$[j+1]),v[j]&oe&&(W=xe(e,{errors:T,currentLocation:q,expectedLocation:E,distance:i,ignoreLocation:h}),W<=m)){if(m=W,p=q,p<=E)break;ae=Math.max(1,2*E-p)}}if(xe(e,{errors:T+1,currentLocation:E,expectedLocation:E,distance:i,ignoreLocation:h})>m)break;$=v}const re={isMatch:p>=0,score:Math.max(.001,W)};if(M){const T=Yt(w,u);T.length?a&&(re.indices=T):re.isMatch=!1}return re}function Jt(t){let e={};for(let s=0,r=t.length;s<r;s+=1){const i=t.charAt(s);e[i]=(e[i]||0)|1<<r-s-1}return e}const Ce=String.prototype.normalize?(t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(t=>t);class at{constructor(e,{location:s=A.location,threshold:r=A.threshold,distance:i=A.distance,includeMatches:c=A.includeMatches,findAllMatches:o=A.findAllMatches,minMatchCharLength:u=A.minMatchCharLength,isCaseSensitive:a=A.isCaseSensitive,ignoreDiacritics:h=A.ignoreDiacritics,ignoreLocation:d=A.ignoreLocation}={}){if(this.options={location:s,threshold:r,distance:i,includeMatches:c,findAllMatches:o,minMatchCharLength:u,isCaseSensitive:a,ignoreDiacritics:h,ignoreLocation:d},e=a?e:e.toLowerCase(),e=h?Ce(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const g=(m,p)=>{this.chunks.push({pattern:m,alphabet:Jt(m),startIndex:p})},E=this.pattern.length;if(E>ue){let m=0;const p=E%ue,M=E-p;for(;m<M;)g(this.pattern.substr(m,ue),m),m+=ue;if(p){const w=E-ue;g(this.pattern.substr(w),w)}}else g(this.pattern,0)}searchIn(e){const{isCaseSensitive:s,ignoreDiacritics:r,includeMatches:i}=this.options;if(e=s?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern===e){let M={isMatch:!0,score:0};return i&&(M.indices=[[0,e.length-1]]),M}const{location:c,distance:o,threshold:u,findAllMatches:a,minMatchCharLength:h,ignoreLocation:d}=this.options;let g=[],E=0,m=!1;this.chunks.forEach(({pattern:M,alphabet:w,startIndex:N})=>{const{isMatch:$,score:W,indices:G}=Vt(e,M,w,{location:c+N,distance:o,threshold:u,findAllMatches:a,minMatchCharLength:h,includeMatches:i,ignoreLocation:d});$&&(m=!0),E+=W,$&&G&&(g=[...g,...G])});let p={isMatch:m,score:m?E/this.chunks.length:1};return m&&i&&(p.indices=g),p}}class ce{constructor(e){this.pattern=e}static isMultiMatch(e){return Ve(e,this.multiRegex)}static isSingleMatch(e){return Ve(e,this.singleRegex)}search(){}}function Ve(t,e){const s=t.match(e);return s?s[1]:null}class Xt extends ce{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const s=e===this.pattern;return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class Zt extends ce{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const r=e.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}}class qt extends ce{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const s=e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class es extends ce{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const s=!e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class ts extends ce{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const s=e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class ss extends ce{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const s=!e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class ut extends ce{constructor(e,{location:s=A.location,threshold:r=A.threshold,distance:i=A.distance,includeMatches:c=A.includeMatches,findAllMatches:o=A.findAllMatches,minMatchCharLength:u=A.minMatchCharLength,isCaseSensitive:a=A.isCaseSensitive,ignoreDiacritics:h=A.ignoreDiacritics,ignoreLocation:d=A.ignoreLocation}={}){super(e),this._bitapSearch=new at(e,{location:s,threshold:r,distance:i,includeMatches:c,findAllMatches:o,minMatchCharLength:u,isCaseSensitive:a,ignoreDiacritics:h,ignoreLocation:d})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class lt extends ce{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let s=0,r;const i=[],c=this.pattern.length;for(;(r=e.indexOf(this.pattern,s))>-1;)s=r+c,i.push([r,s-1]);const o=!!i.length;return{isMatch:o,score:o?0:1,indices:i}}}const ke=[Xt,lt,qt,es,ss,ts,Zt,ut],Je=ke.length,ns=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,rs="|";function is(t,e={}){return t.split(rs).map(s=>{let r=s.trim().split(ns).filter(c=>c&&!!c.trim()),i=[];for(let c=0,o=r.length;c<o;c+=1){const u=r[c];let a=!1,h=-1;for(;!a&&++h<Je;){const d=ke[h];let g=d.isMultiMatch(u);g&&(i.push(new d(g,e)),a=!0)}if(!a)for(h=-1;++h<Je;){const d=ke[h];let g=d.isSingleMatch(u);if(g){i.push(new d(g,e));break}}}return i})}const cs=new Set([ut.type,lt.type]);class os{constructor(e,{isCaseSensitive:s=A.isCaseSensitive,ignoreDiacritics:r=A.ignoreDiacritics,includeMatches:i=A.includeMatches,minMatchCharLength:c=A.minMatchCharLength,ignoreLocation:o=A.ignoreLocation,findAllMatches:u=A.findAllMatches,location:a=A.location,threshold:h=A.threshold,distance:d=A.distance}={}){this.query=null,this.options={isCaseSensitive:s,ignoreDiacritics:r,includeMatches:i,minMatchCharLength:c,findAllMatches:u,ignoreLocation:o,location:a,threshold:h,distance:d},e=s?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern=e,this.query=is(this.pattern,this.options)}static condition(e,s){return s.useExtendedSearch}searchIn(e){const s=this.query;if(!s)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:i,ignoreDiacritics:c}=this.options;e=i?e:e.toLowerCase(),e=c?Ce(e):e;let o=0,u=[],a=0;for(let h=0,d=s.length;h<d;h+=1){const g=s[h];u.length=0,o=0;for(let E=0,m=g.length;E<m;E+=1){const p=g[E],{isMatch:M,indices:w,score:N}=p.search(e);if(M){if(o+=1,a+=N,r){const $=p.constructor.type;cs.has($)?u=[...u,...w]:u.push(w)}}else{a=0,o=0,u.length=0;break}}if(o){let E={isMatch:!0,score:a/o};return r&&(E.indices=u),E}}return{isMatch:!1,score:1}}}const Ie=[];function as(...t){Ie.push(...t)}function je(t,e){for(let s=0,r=Ie.length;s<r;s+=1){let i=Ie[s];if(i.condition(t,e))return new i(t,e)}return new at(t,e)}const be={AND:"$and",OR:"$or"},Be={PATH:"$path",PATTERN:"$val"},De=t=>!!(t[be.AND]||t[be.OR]),us=t=>!!t[Be.PATH],ls=t=>!ne(t)&&rt(t)&&!De(t),Xe=t=>({[be.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function ht(t,e,{auto:s=!0}={}){const r=i=>{let c=Object.keys(i);const o=us(i);if(!o&&c.length>1&&!De(i))return r(Xe(i));if(ls(i)){const a=o?i[Be.PATH]:c[0],h=o?i[Be.PATTERN]:i[a];if(!Z(h))throw new Error(Rt(a));const d={keyId:_e(a),pattern:h};return s&&(d.searcher=je(h,e)),d}let u={children:[],operator:c[0]};return c.forEach(a=>{const h=i[a];ne(h)&&h.forEach(d=>{u.children.push(r(d))})}),u};return De(t)||(t=Xe(t)),r(t)}function hs(t,{ignoreFieldNorm:e=A.ignoreFieldNorm}){t.forEach(s=>{let r=1;s.matches.forEach(({key:i,norm:c,score:o})=>{const u=i?i.weight:null;r*=Math.pow(o===0&&u?Number.EPSILON:o,(u||1)*(e?1:c))}),s.score=r})}function ds(t,e){const s=t.matches;e.matches=[],Q(s)&&s.forEach(r=>{if(!Q(r.indices)||!r.indices.length)return;const{indices:i,value:c}=r;let o={indices:i,value:c};r.key&&(o.key=r.key.src),r.idx>-1&&(o.refIndex=r.idx),e.matches.push(o)})}function fs(t,e){e.score=t.score}function ms(t,e,{includeMatches:s=A.includeMatches,includeScore:r=A.includeScore}={}){const i=[];return s&&i.push(ds),r&&i.push(fs),t.map(c=>{const{idx:o}=c,u={item:e[o],refIndex:o};return i.length&&i.forEach(a=>{a(c,u)}),u})}class X{constructor(e,s={},r){this.options={...A,...s},this.options.useExtendedSearch,this._keyStore=new Pt(this.options.keys),this.setCollection(e,r)}setCollection(e,s){if(this._docs=e,s&&!(s instanceof Ne))throw new Error(Nt);this._myIndex=s||ot(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){Q(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const s=[];for(let r=0,i=this._docs.length;r<i;r+=1){const c=this._docs[r];e(c,r)&&(this.removeAt(r),r-=1,i-=1,s.push(c))}return s}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:s=-1}={}){const{includeMatches:r,includeScore:i,shouldSort:c,sortFn:o,ignoreFieldNorm:u}=this.options;let a=Z(e)?Z(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return hs(a,{ignoreFieldNorm:u}),c&&a.sort(o),nt(s)&&s>-1&&(a=a.slice(0,s)),ms(a,this._docs,{includeMatches:r,includeScore:i})}_searchStringList(e){const s=je(e,this.options),{records:r}=this._myIndex,i=[];return r.forEach(({v:c,i:o,n:u})=>{if(!Q(c))return;const{isMatch:a,score:h,indices:d}=s.searchIn(c);a&&i.push({item:c,idx:o,matches:[{score:h,value:c,norm:u,indices:d}]})}),i}_searchLogical(e){const s=ht(e,this.options),r=(u,a,h)=>{if(!u.children){const{keyId:g,searcher:E}=u,m=this._findMatches({key:this._keyStore.get(g),value:this._myIndex.getValueForItemAtKeyId(a,g),searcher:E});return m&&m.length?[{idx:h,item:a,matches:m}]:[]}const d=[];for(let g=0,E=u.children.length;g<E;g+=1){const m=u.children[g],p=r(m,a,h);if(p.length)d.push(...p);else if(u.operator===be.AND)return[]}return d},i=this._myIndex.records,c={},o=[];return i.forEach(({$:u,i:a})=>{if(Q(u)){let h=r(s,u,a);h.length&&(c[a]||(c[a]={idx:a,item:u,matches:[]},o.push(c[a])),h.forEach(({matches:d})=>{c[a].matches.push(...d)}))}}),o}_searchObjectList(e){const s=je(e,this.options),{keys:r,records:i}=this._myIndex,c=[];return i.forEach(({$:o,i:u})=>{if(!Q(o))return;let a=[];r.forEach((h,d)=>{a.push(...this._findMatches({key:h,value:o[d],searcher:s}))}),a.length&&c.push({idx:u,item:o,matches:a})}),c}_findMatches({key:e,value:s,searcher:r}){if(!Q(s))return[];let i=[];if(ne(s))s.forEach(({v:c,i:o,n:u})=>{if(!Q(c))return;const{isMatch:a,score:h,indices:d}=r.searchIn(c);a&&i.push({score:h,key:e,value:c,idx:o,norm:u,indices:d})});else{const{v:c,n:o}=s,{isMatch:u,score:a,indices:h}=r.searchIn(c);u&&i.push({score:a,key:e,value:c,norm:o,indices:h})}return i}}X.version="7.1.0";X.createIndex=ot;X.parseIndex=Ut;X.config=A;X.parseQuery=ht;as(os);const he=["all","agents","buildings","areas","commands"],Ze={".ts":"file-code",".tsx":"atom",".js":"file-code",".jsx":"atom",".py":"file-code",".rs":"file-code",".go":"file-code",".md":"file-text",".json":"clipboard",".yaml":"gear",".yml":"gear",".css":"palette",".scss":"palette",".html":"globe",".sql":"database",".sh":"terminal",".env":"lock",".toml":"gear",".lock":"lock",default:"file-text"};function gs(t){switch(t){case"scout":return"class-scout";case"builder":return"class-builder";case"debugger":return"class-debugger";case"architect":return"class-architect";case"warrior":return"class-warrior";case"support":return"class-support";case"boss":return"class-boss";default:return"class-default"}}function ps(t,e=16){var i;const s="."+(((i=t.split(".").pop())==null?void 0:i.toLowerCase())??""),r=Ze[s]||Ze.default;return l.jsx(V,{name:r,size:e})}function js(t,e=16){return l.jsx(V,{name:gs(t),size:e,weight:"fill"})}function dt(t){const e=Math.floor(t/1e3),s=Math.floor(e/60),r=Math.floor(s/60),i=Math.floor(r/24);return i>0?`${i}d ${r%24}h ago`:r>0?`${r}h ${s%60}m ago`:s>0?`${s}m ago`:"just now"}function Bs(t){const s=Date.now()-t;return dt(s)}const ft="tide-commander:spotlight-recent-agents",As=15;function mt(){try{const t=localStorage.getItem(ft);if(!t)return{};const e=JSON.parse(t);if(!e||typeof e!="object"||Array.isArray(e))return{};const s={};for(const[r,i]of Object.entries(e))typeof r=="string"&&typeof i=="number"&&(s[r]=i);return s}catch{return{}}}function ys(t){try{const e=mt();e[t]=Date.now();const s=Object.entries(e).sort((r,i)=>i[1]-r[1]).slice(0,As);localStorage.setItem(ft,JSON.stringify(Object.fromEntries(s)))}catch{}}function Ee(t,e,s){const r=t?s[t]??0:0;return Math.max(e??0,r)}function qe(t){switch(t){case"agent":return"Agent";case"command":return"Command";case"area":return"Area";case"modified-file":return"Changed";case"building":return"Server";default:return t}}const xs=["command","agent","building","area","modified-file"];function Es(){const t=st(ge.SPOTLIGHT_TAB,"all");return he.includes(t)?t:"all"}function et(){return _t(ge.SPOTLIGHT_QUERY,"")}function Cs(){const t=st(ge.AOP_CONFIG,{});return t.sortMode==="name"||t.sortMode==="status"||t.sortMode==="recent"?t.sortMode:"recent"}function bs({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:r,onOpenToolbox:i,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:u,onOpenDatabasePanel:a,onOpenMonitoringModal:h}){const d=yt(),g=xt(),E=Et(),m=Ct(),p=bt(),M=wt(),w=f.useRef(e);w.current=e;const N=f.useRef(s);N.current=s;const $=f.useRef(r);$.current=r;const W=f.useRef(i);W.current=i;const G=f.useRef(c);G.current=c;const oe=f.useRef(o);oe.current=o;const re=f.useRef(u);re.current=u;const T=f.useRef(a);T.current=a;const P=f.useRef(h);P.current=h;const[I,ae]=f.useState(et),[H,v]=f.useState(0),[C,j]=f.useState(Es),q=f.useCallback(n=>{ae(n),Mt(ge.SPOTLIGHT_QUERY,n)},[]);f.useEffect(()=>{t&&(ae(et()),v(0))},[t]);const U=f.useCallback(n=>{j(n),vt(ge.SPOTLIGHT_TAB,n)},[]),Re=f.useRef(C);Re.current=C;const gt=f.useCallback(n=>{const x=he.indexOf(Re.current),b=he[(x+n+he.length)%he.length];U(b)},[U]);f.useEffect(()=>{v(0)},[C]);const Me=se.getShortcuts(),de=f.useMemo(()=>t?mt():{},[t]),pe=f.useMemo(()=>{if(!t)return[];const n=Me.find(b=>b.id==="spawn-agent"),x=Me.find(b=>b.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:n?He(n):"Alt+N",icon:l.jsx(V,{name:"plus",size:16}),action:()=>{w.current(),N.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:x?He(x):"Ctrl+K",icon:l.jsx(V,{name:"dashboard",size:16}),action:()=>{w.current(),$.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:l.jsx(V,{name:"gear",size:16}),action:()=>{w.current(),W.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:l.jsx(V,{name:"chart-line",size:16}),action:()=>{var b;w.current(),(b=P.current)==null||b.call(P)}}]},[t,Me]),le=f.useMemo(()=>t?Array.from(d.values()).map(n=>{const x=(m||[]).filter(O=>O.agentId===n.id).map(O=>O.filePath),b=[...new Set(x)],F=b.map(O=>O.split("/").pop()||O),_=[];n.lastAssignedTask&&_.push(n.lastAssignedTask);const R=`${n.class} • ${n.cwd}`;let B=`${n.name} ${n.class} ${n.status} ${n.cwd}`;n.taskLabel&&(B+=` ${n.taskLabel}`),F.length>0&&(B+=` ${F.join(" ")} ${b.join(" ")}`),_.length>0&&(B+=` ${_.join(" ")}`);const L=Date.now()-n.lastActivity;let J;return n.lastAssignedTask&&(n.lastAssignedTask.length>150?J=n.lastAssignedTask.slice(0,150)+"...":J=n.lastAssignedTask),{id:`agent-${n.id}`,type:"agent",title:n.name,subtitle:R,lastUserInput:J,timeAway:L,icon:l.jsx(Ft,{agent:n,size:20}),_searchText:B,_modifiedFiles:b,_userQueries:_,_agentId:n.id,_lastActivity:n.lastActivity,_taskLabel:n.taskLabel,_status:n.status,action:()=>{w.current(),ys(n.id),se.selectAgent(n.id),se.getState().viewMode!=="flat"&&se.requestTerminalExpand()}}}):[],[t,d,m]),Ae=f.useMemo(()=>t?Array.from(g.values()).map(n=>{var x;return{id:`area-${n.id}`,type:"area",title:n.name,subtitle:`${n.assignedAgentIds.length} agents • ${((x=n.directories)==null?void 0:x.length)||0} folders`,icon:l.jsx(V,{name:"map",size:16}),action:()=>{w.current(),se.selectArea(n.id)}}}):[],[t,g]),Te=f.useMemo(()=>{const n=new Map;for(const x of le)x._agentId&&n.set(x._agentId,x);return n},[le]),Le=f.useMemo(()=>{const n=new Map;if(!t)return n;for(const x of d.values()){const b=se.getAreaForAgent(x.id);if(!b||b.archived)continue;const F=n.get(b.id);F?F.push(x):n.set(b.id,[x])}return n},[t,d,g]),$e=f.useMemo(()=>{const n=new Map;for(const x of p)n.has(x.agentId)||n.set(x.agentId,x.timestamp);return n},[p]),ve=f.useMemo(()=>{if(!t)return[];const n=I.trim().toLowerCase(),x=St({sortMode:Cs(),agentsWithUnseenOutput:M,getLatestToolTimestamp:_=>$e.get(_)}),b=Array.from(g.values()).filter(_=>!_.archived).filter(_=>n?_.name.toLowerCase().includes(n):!0).sort((_,R)=>_.name.localeCompare(R.name,void 0,{sensitivity:"base"})),F=[];for(const _ of b){const B=(Le.get(_.id)||[]).slice().sort(x).map(L=>Te.get(L.id)).filter(L=>!!L);!n&&B.length===0||F.push({areaId:_.id,areaName:_.name,areaColor:_.color,agents:B})}return F},[t,I,g,Le,Te,M,$e]),ye=f.useMemo(()=>t?Array.from(E.values()).filter(n=>n.type==="server"||n.type==="boss"||n.type==="database").map(n=>{var L,J,O,ie,me;const x=n.status==="running"?"#4ade80":n.status==="stopped"?"#f87171":"#facc15",b=n.type==="boss"?"crown":n.type==="database"?"database":"desktop";let _=`${n.type==="boss"?"Boss":n.type==="database"?"Database":"Server"} • ${n.status}`;if(n.type==="database"&&((J=(L=n.database)==null?void 0:L.connections)!=null&&J.length)){const z=n.database.connections[0];_+=` • ${z.engine} @ ${z.host}`}else n.cwd&&(_+=` • ${n.cwd}`);const R=((O=n.pm2Status)==null?void 0:O.ports)||[];let B=`${n.name} ${n.type} ${n.status} ${n.cwd||""} ${((ie=n.pm2)==null?void 0:ie.name)||""}`;if(R.length>0&&(B+=` ${R.join(" ")}`),n.type==="database"&&((me=n.database)!=null&&me.connections))for(const z of n.database.connections)B+=` ${z.name} ${z.engine} ${z.host} ${z.database||""} mysql postgresql sql`;return{id:`building-${n.id}`,type:"building",title:n.name,subtitle:_,_ports:R,icon:l.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[l.jsx(V,{name:"status-pending",size:10,weight:"fill",color:x}),l.jsx(V,{name:b,size:16})]}),_searchText:B,action:()=>{var z;w.current(),n.type==="boss"?re.current(n.id):n.type==="database"?T.current(n.id):(z=n.pm2)!=null&&z.enabled&&oe.current(n.id)}}}):[],[t,E]),Pe=f.useMemo(()=>{if(!t)return[];const n=m||[],x=new Set,b=[];for(const F of n){if(x.has(F.filePath))continue;x.add(F.filePath);const _=F.filePath.split("/").pop()||F.filePath,R=F.action==="created"?"Created":F.action==="modified"?"Modified":F.action==="deleted"?"Deleted":"Read";if(b.push({id:`modified-${F.filePath}-${F.timestamp}`,type:"modified-file",title:_,subtitle:`${R} by ${F.agentName} • ${F.filePath}`,matchedText:F.filePath,icon:F.action==="deleted"?l.jsx(V,{name:"trash",size:16}):ps(F.filePath),action:()=>{w.current();const B=Array.from(se.getState().areas.values());for(const L of B)for(const J of L.directories||[])if(F.filePath.startsWith(J)){se.setFileViewerPath(F.filePath),G.current(L.id);return}se.selectAgent(F.agentId)}}),b.length>=50)break}return b},[t,m]),Oe=f.useMemo(()=>new X(le,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[le]),Ke=f.useMemo(()=>new X(pe,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[pe]),ze=f.useMemo(()=>new X(Ae,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[Ae]),Qe=f.useMemo(()=>new X(Pe,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[Pe]),We=f.useMemo(()=>new X(ye,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ye]),fe=f.useMemo(()=>{if(!I.trim()){const y=[];y.push(...ye);const S=[...le].sort((D,K)=>{const ee=Ee(D._agentId,D._lastActivity,de);return Ee(K._agentId,K._lastActivity,de)-ee});y.push(...S),y.push(...pe.slice(0,2)),y.push(...Ae.slice(0,2));const k={};return xs.forEach((D,K)=>{k[D]=K}),y.sort((D,K)=>(k[D.type]??999)-(k[K.type]??999)),y}const n=I.trim().toLowerCase(),x=Oe.search(I).slice(0,8),b=Ke.search(I).slice(0,3),F=ze.search(I).slice(0,2),_=Qe.search(I).slice(0,3),R=We.search(I).filter(y=>{const S=y.score??1;return`${y.item.title} ${y.item.subtitle||""} ${y.item._searchText||""}`.toLowerCase().includes(n)||S<=.2}).slice(0,4),B={agent:5,building:4,command:3,area:2,"modified-file":1},L=y=>{if(!n)return 1;const S=y.title.toLowerCase();return S===n?6:S.startsWith(n)?5:S.split(/[^a-z0-9]+/i).includes(n)?4:S.includes(n)?3:`${y.subtitle||""} ${y._searchText||""} ${y.matchedText||""}`.toLowerCase().includes(n)?2:1},J=(y,S)=>{const k=(1-Math.min(1,S??1))*4;return L(y)*100+(B[y.type]??0)*5+k},O=new Map,ie=(y,S)=>{const k=O.get(y.type),D={item:y,score:J(y,S)};k?k.push(D):O.set(y.type,[D])};for(const y of x){const S={...y.item};if(S._modifiedFiles&&S._modifiedFiles.length>0){const k=S._modifiedFiles.filter(D=>{var te;const K=((te=D.split("/").pop())==null?void 0:te.toLowerCase())||"",ee=D.toLowerCase();return K.includes(n)||ee.includes(n)});k.length>0&&(S.matchedFiles=k)}if(S._userQueries&&S._userQueries.length>0){const k=S._userQueries.find(D=>D.toLowerCase().includes(n));if(k)if(k.length>200){const K=k.toLowerCase().indexOf(n),ee=Math.max(0,K-60),te=Math.min(k.length,K+n.length+100);S.matchedQuery=(ee>0?"...":"")+k.slice(ee,te)+(te<k.length?"...":"")}else S.matchedQuery=k}ie(S,y.score)}for(const y of R)ie(y.item,y.score);for(const y of b)ie(y.item,y.score);for(const y of F)ie(y.item,y.score);for(const y of _)ie(y.item,y.score);for(const[y,S]of O)y==="agent"?S.sort((k,D)=>{const K=L(k.item),ee=L(D.item);if(ee!==K)return ee-K;const te=Ee(k.item._agentId,k.item._lastActivity,de),Ge=Ee(D.item._agentId,D.item._lastActivity,de);return Ge!==te?Ge-te:D.score-k.score}):S.sort((k,D)=>D.score-k.score);const me=y=>y.reduce((S,k)=>Math.max(S,k.score),-1),z=[];return Array.from(O.values()).sort((y,S)=>me(S)-me(y)).forEach(y=>{for(const S of y)z.push(S.item)}),z},[I,Oe,Ke,ze,Qe,We,pe,le,Ae,ye,de]),Y=f.useMemo(()=>{switch(C){case"agents":return fe.filter(n=>n.type==="agent");case"buildings":return fe.filter(n=>n.type==="building");case"commands":return fe.filter(n=>n.type==="command");case"areas":return ve.flatMap(n=>n.agents);case"all":default:return fe}},[C,fe,ve]);f.useEffect(()=>{H>=Y.length&&v(Math.max(0,Y.length-1))},[Y.length,H]);const pt=f.useCallback(n=>{if(n.altKey&&!n.ctrlKey&&!n.metaKey&&(n.key==="p"||n.key==="n"||n.key==="P"||n.key==="N")){n.preventDefault(),n.stopPropagation(),n.nativeEvent.stopImmediatePropagation();const x=n.key.toLowerCase();v(x==="p"?b=>b>0?b-1:Y.length-1:b=>b<Y.length-1?b+1:0);return}switch(n.key){case"Escape":n.preventDefault(),w.current();break;case"ArrowUp":n.preventDefault(),v(x=>x>0?x-1:Y.length-1);break;case"ArrowDown":n.preventDefault(),v(x=>x<Y.length-1?x+1:0);break;case"Enter":n.preventDefault(),Y[H]&&Y[H].action();break}},[Y,H]),At=f.useCallback((n,x)=>{if(!x||!n)return n;const b=n.toLowerCase(),F=x.toLowerCase(),_=[];let R=0,B=b.indexOf(F),L=0;for(;B!==-1;)B>R&&_.push(n.slice(R,B)),_.push(Fe.createElement("mark",{key:L++,className:"spotlight-highlight"},n.slice(B,B+x.length))),R=B+x.length,B=b.indexOf(F,R);return R<n.length&&_.push(n.slice(R)),_.length>0?Fe.createElement(Fe.Fragment,null,..._):n},[]);return{query:I,setQuery:q,selectedIndex:H,setSelectedIndex:v,results:Y,activeTab:C,setActiveTab:U,cycleTab:gt,areaSections:ve,handleKeyDown:pt,highlightMatch:At}}const ws=f.forwardRef(function({query:e,onQueryChange:s,onKeyDown:r,onResetSelection:i},c){const{t:o}=we(["common"]);return l.jsxs("div",{className:"spotlight-input-wrapper",children:[l.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),l.jsx("input",{ref:c,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:u=>{s(u.target.value),i()},onKeyDown:r,autoFocus:!0,spellCheck:!1}),l.jsxs("div",{className:"spotlight-input-hints",children:[l.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),l.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),l.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Ms=f.memo(function({activeTab:e,onSelect:s}){const{t:r}=we(["terminal"]);return l.jsxs("div",{className:"spotlight-tabs",role:"tablist","aria-label":r("terminal:spotlight.tabsLabel"),children:[he.map(i=>l.jsx("button",{type:"button",role:"tab","aria-selected":i===e,tabIndex:-1,className:`spotlight-tab${i===e?" active":""}`,onClick:()=>s(i),children:r(`terminal:spotlight.tabs.${i}`)},i)),l.jsx("span",{className:"spotlight-tabs-hint",children:l.jsx("kbd",{children:"Tab"})})]})}),tt=f.memo(function({result:e,isSelected:s,query:r,highlightMatch:i,onClick:c,onMouseEnter:o}){const u=e.activityText||e.matchedFiles&&e.matchedFiles.length>0||e.matchedQuery,a=e._status?kt(e._status):void 0,h=e.type==="building"?e._ports:void 0;return l.jsxs("div",{className:`spotlight-item ${s?"selected":""} ${e.activityText?"has-activity":""}`,onClick:c,onMouseEnter:o,role:"option","aria-selected":s,children:[l.jsx("span",{className:"spotlight-item-icon","aria-hidden":"true",children:e.icon}),l.jsxs("div",{className:"spotlight-item-content",children:[l.jsxs("div",{className:"spotlight-item-header",children:[l.jsx("span",{className:"spotlight-item-title",children:i(e.title,r)}),e._status&&a&&l.jsxs("span",{className:`spotlight-item-agent-status${e._status==="working"?" spotlight-item-agent-status--working":""}`,style:{color:a,background:`${a}1f`,borderColor:`${a}55`},children:[e._status==="working"&&l.jsx("span",{className:"spotlight-working-dot","aria-hidden":"true"}),e._status.replace(/_/g," ")]}),e._taskLabel&&l.jsxs("span",{className:"spotlight-item-task-label",title:e._taskLabel,children:[l.jsx(V,{name:"task",size:9,"aria-hidden":!0}),i(e._taskLabel,r)]}),l.jsx("span",{className:`spotlight-item-type ${e.type}`,"aria-label":qe(e.type),children:qe(e.type)})]}),e.subtitle&&l.jsx("span",{className:"spotlight-item-subtitle",children:i(e.subtitle,r)}),h&&h.length>0&&l.jsx("span",{className:"spotlight-item-ports",children:h.map(d=>l.jsxs("a",{className:"spotlight-port-link",href:`http://localhost:${d}`,target:"_blank",rel:"noopener noreferrer",title:`http://localhost:${d}`,onClick:g=>g.stopPropagation(),children:[":",d]},d))}),e.activityText&&l.jsx("span",{className:"spotlight-item-activity",children:i(e.activityText,r)}),u&&l.jsxs("div",{className:"spotlight-item-details",children:[e.matchedFiles&&e.matchedFiles.length>0&&l.jsx("span",{className:"spotlight-item-files",children:e.matchedFiles.map((d,g)=>l.jsxs("span",{className:"file-badge",children:[g>0&&l.jsx("span",{className:"file-separator",children:"•"}),i(d.split("/").pop()||d,r)]},d))}),e.matchedQuery&&l.jsx("span",{className:"spotlight-item-query",children:i(e.matchedQuery,r)})]}),e.timeAway!==void 0&&l.jsx("span",{className:"spotlight-item-time",children:l.jsxs("span",{className:"spotlight-time-away",children:["Idle: ",dt(e.timeAway)]})}),e.lastUserInput&&!e.matchedQuery&&l.jsxs("span",{className:"spotlight-item-last-input",children:['"',i(e.lastUserInput,r),'"']})]})]})}),vs=f.forwardRef(function({results:e,selectedIndex:s,query:r,activeTab:i,areaSections:c,highlightMatch:o,onSelectIndex:u},a){const{t:h}=we(["terminal"]),d=f.useRef(!1);f.useEffect(()=>{d.current=!1},[e]),f.useEffect(()=>{const m=typeof a=="function"?null:a==null?void 0:a.current;if(!m)return;const p=()=>{d.current=!0};return m.addEventListener("mousemove",p),()=>{m.removeEventListener("mousemove",p)}},[a,e]);const g={command:h("terminal:spotlight.categories.commands"),agent:h("terminal:spotlight.categories.agents"),building:h("terminal:spotlight.categories.infrastructure"),area:h("terminal:spotlight.categories.areas"),"modified-file":h("terminal:spotlight.categories.modifiedFiles")},E=f.useMemo(()=>{const m=[];let p=null,M=[];return e.forEach((w,N)=>{w.type!==p&&(p!==null&&M.length>0&&m.push([p,M]),p=w.type,M=[]),M.push({result:w,index:N})}),p!==null&&M.length>0&&m.push([p,M]),m},[e]);if(f.useEffect(()=>{if(!a||typeof a=="function")return;const m=a.current;if(!m)return;const p=m.querySelector(".spotlight-item.selected");p&&p.scrollIntoView({block:"nearest",behavior:"smooth"})},[s,a]),i==="areas"){if(c.length===0)return l.jsx("div",{className:"spotlight-results",ref:a,children:l.jsx("div",{className:"spotlight-empty",children:h("terminal:spotlight.noResults")})});let m=0;return l.jsx("div",{className:"spotlight-results",ref:a,children:c.map(p=>l.jsxs("div",{children:[l.jsxs("div",{className:"spotlight-category-header spotlight-area-section-header",children:[l.jsx("span",{className:"spotlight-area-dot",style:{background:p.areaColor},"aria-hidden":"true"}),l.jsx("span",{className:"spotlight-area-name",children:p.areaName}),l.jsx("span",{className:"spotlight-area-count",children:p.agents.length})]}),p.agents.length===0?l.jsx("div",{className:"spotlight-area-empty",children:h("terminal:spotlight.noAgentsInArea")}):p.agents.map(M=>{const w=m++;return l.jsx(tt,{result:M,isSelected:w===s,query:r,highlightMatch:o,onClick:()=>M.action(),onMouseEnter:()=>{d.current&&u(w)}},M.id)})]},p.areaId))})}return e.length===0?l.jsx("div",{className:"spotlight-results",ref:a,children:l.jsx("div",{className:"spotlight-empty",children:h("terminal:spotlight.noResults")})}):l.jsx("div",{className:"spotlight-results",ref:a,children:E.map(([m,p])=>l.jsxs("div",{children:[E.length>1&&l.jsx("div",{className:"spotlight-category-header",children:g[m]||m}),p.map(({result:M,index:w})=>l.jsx(tt,{result:M,isSelected:w===s,query:r,highlightMatch:o,onClick:()=>M.action(),onMouseEnter:()=>{d.current&&u(w)}},M.id))]},m))})}),Fs=f.memo(function(){const{t:e}=we(["terminal"]);return l.jsxs("div",{className:"spotlight-footer",children:[l.jsxs("div",{className:"spotlight-footer-left",children:[l.jsxs("span",{className:"spotlight-footer-hint",children:[l.jsx("kbd",{children:"↑"}),l.jsx("kbd",{children:"↓"})," ",l.jsx("kbd",{children:"Alt+N"}),l.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),l.jsxs("span",{className:"spotlight-footer-hint",children:[l.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]}),l.jsxs("span",{className:"spotlight-footer-hint",children:[l.jsx("kbd",{children:"Tab"})," ",e("terminal:spotlight.switchTabs")]})]}),l.jsx("div",{className:"spotlight-footer-right",children:l.jsxs("span",{className:"spotlight-footer-hint",children:[l.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),Ss=768;function Ds({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:r,onOpenToolbox:i,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:u,onOpenDatabasePanel:a,onOpenMonitoringModal:h}){const d=f.useRef(null),g=f.useRef(null),E=f.useRef(null),m=f.useRef(0),{query:p,setQuery:M,selectedIndex:w,setSelectedIndex:N,results:$,activeTab:W,setActiveTab:G,cycleTab:oe,areaSections:re,handleKeyDown:T,highlightMatch:P}=bs({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:r,onOpenToolbox:i,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:u,onOpenDatabasePanel:a,onOpenMonitoringModal:h});m.current=$.length;const I=f.useRef(oe);I.current=oe,f.useEffect(()=>{t&&setTimeout(()=>{var v,C;(v=d.current)==null||v.focus(),(C=d.current)==null||C.select()},50)},[t]),f.useEffect(()=>{if(!t)return;const v=window.visualViewport;if(!v||window.innerWidth>Ss)return;const C=()=>{const j=g.current;j&&(j.style.height=`${v.height}px`,j.style.top=`${v.offsetTop}px`)};return C(),v.addEventListener("resize",C),v.addEventListener("scroll",C),()=>{v.removeEventListener("resize",C),v.removeEventListener("scroll",C);const j=g.current;j&&(j.style.height="",j.style.top="")}},[t]),f.useEffect(()=>{if(!t)return;const v=C=>{if(C.key==="Escape"){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation(),e();return}if(C.key==="Tab"){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation(),I.current(C.shiftKey?-1:1);return}if(C.altKey&&!C.ctrlKey&&!C.metaKey&&(C.key==="n"||C.key==="p"||C.key==="N"||C.key==="P")){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation();const j=C.key.toLowerCase(),q=m.current;N(j==="p"?U=>U>0?U-1:q-1:U=>U<q-1?U+1:0);return}};return window.addEventListener("keydown",v,{capture:!0}),()=>{window.removeEventListener("keydown",v,{capture:!0})}},[t,e]);const ae=f.useCallback(v=>{v.target===v.currentTarget&&e()},[e]),H=f.useCallback(()=>{N(0)},[N]);return t?l.jsx("div",{ref:g,className:"spotlight-overlay",onClick:ae,children:l.jsxs("div",{className:"spotlight-modal",children:[l.jsx(ws,{ref:d,query:p,onQueryChange:M,onKeyDown:T,onResetSelection:H}),l.jsx(Ms,{activeTab:W,onSelect:G}),l.jsx(vs,{ref:E,results:$,selectedIndex:w,query:p,activeTab:W,areaSections:re,highlightMatch:P,onSelectIndex:N}),l.jsx(Fs,{})]})}):null}export{Ze as FILE_ICON_NAMES,Ds as Spotlight,Fs as SpotlightFooter,ws as SpotlightInput,tt as SpotlightItem,vs as SpotlightResults,dt as formatDuration,Bs as formatRelativeTime,js as getAgentIcon,ps as getFileIconFromPath,qe as getTypeLabel,bs as useSpotlightSearch};
|
|
1
|
+
import{j as l,I as V,al as yt,W as xt,X as Et,bZ as Ct,b_ as bt,av as wt,r as f,L as Mt,S as ge,b$ as vt,s as se,c0 as He,$ as Ft,c1 as St,ae as Fe,K as _t,p as st,u as we,a0 as kt}from"./main-D7pG1mPb.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function ne(t){return Array.isArray?Array.isArray(t):it(t)==="[object Array]"}function It(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function jt(t){return t==null?"":It(t)}function Z(t){return typeof t=="string"}function nt(t){return typeof t=="number"}function Bt(t){return t===!0||t===!1||Dt(t)&&it(t)=="[object Boolean]"}function rt(t){return typeof t=="object"}function Dt(t){return rt(t)&&t!==null}function Q(t){return t!=null}function Se(t){return!t.trim().length}function it(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const Nt="Incorrect 'index' type",Rt=t=>`Invalid value for key ${t}`,Tt=t=>`Pattern length exceeds max of ${t}.`,Lt=t=>`Missing ${t} property in key`,$t=t=>`Property 'weight' in key '${t}' must be a positive integer`,Ue=Object.prototype.hasOwnProperty;class Pt{constructor(e){this._keys=[],this._keyMap={};let s=0;e.forEach(r=>{let i=ct(r);this._keys.push(i),this._keyMap[i.id]=i,s+=i.weight}),this._keys.forEach(r=>{r.weight/=s})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function ct(t){let e=null,s=null,r=null,i=1,c=null;if(Z(t)||ne(t))r=t,e=Ye(t),s=_e(t);else{if(!Ue.call(t,"name"))throw new Error(Lt("name"));const o=t.name;if(r=o,Ue.call(t,"weight")&&(i=t.weight,i<=0))throw new Error($t(o));e=Ye(o),s=_e(o),c=t.getFn}return{path:e,id:s,weight:i,src:r,getFn:c}}function Ye(t){return ne(t)?t:t.split(".")}function _e(t){return ne(t)?t.join("."):t}function Ot(t,e){let s=[],r=!1;const i=(c,o,u)=>{if(Q(c))if(!o[u])s.push(c);else{let a=o[u];const h=c[a];if(!Q(h))return;if(u===o.length-1&&(Z(h)||nt(h)||Bt(h)))s.push(jt(h));else if(ne(h)){r=!0;for(let d=0,g=h.length;d<g;d+=1)i(h[d],o,u+1)}else o.length&&i(h,o,u+1)}};return i(t,Z(e)?e.split("."):e,0),r?s:s[0]}const Kt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},zt={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},Qt={location:0,threshold:.6,distance:100},Wt={useExtendedSearch:!1,getFn:Ot,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var A={...zt,...Kt,...Qt,...Wt};const Gt=/[^ ]+/g;function Ht(t=1,e=3){const s=new Map,r=Math.pow(10,e);return{get(i){const c=i.match(Gt).length;if(s.has(c))return s.get(c);const o=1/Math.pow(c,.5*t),u=parseFloat(Math.round(o*r)/r);return s.set(c,u),u},clear(){s.clear()}}}class Ne{constructor({getFn:e=A.getFn,fieldNormWeight:s=A.fieldNormWeight}={}){this.norm=Ht(s,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((s,r)=>{this._keysMap[s.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,Z(this.docs[0])?this.docs.forEach((e,s)=>{this._addString(e,s)}):this.docs.forEach((e,s)=>{this._addObject(e,s)}),this.norm.clear())}add(e){const s=this.size();Z(e)?this._addString(e,s):this._addObject(e,s)}removeAt(e){this.records.splice(e,1);for(let s=e,r=this.size();s<r;s+=1)this.records[s].i-=1}getValueForItemAtKeyId(e,s){return e[this._keysMap[s]]}size(){return this.records.length}_addString(e,s){if(!Q(e)||Se(e))return;let r={v:e,i:s,n:this.norm.get(e)};this.records.push(r)}_addObject(e,s){let r={i:s,$:{}};this.keys.forEach((i,c)=>{let o=i.getFn?i.getFn(e):this.getFn(e,i.path);if(Q(o)){if(ne(o)){let u=[];const a=[{nestedArrIndex:-1,value:o}];for(;a.length;){const{nestedArrIndex:h,value:d}=a.pop();if(Q(d))if(Z(d)&&!Se(d)){let g={v:d,i:h,n:this.norm.get(d)};u.push(g)}else ne(d)&&d.forEach((g,E)=>{a.push({nestedArrIndex:E,value:g})})}r.$[c]=u}else if(Z(o)&&!Se(o)){let u={v:o,n:this.norm.get(o)};r.$[c]=u}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function ot(t,e,{getFn:s=A.getFn,fieldNormWeight:r=A.fieldNormWeight}={}){const i=new Ne({getFn:s,fieldNormWeight:r});return i.setKeys(t.map(ct)),i.setSources(e),i.create(),i}function Ut(t,{getFn:e=A.getFn,fieldNormWeight:s=A.fieldNormWeight}={}){const{keys:r,records:i}=t,c=new Ne({getFn:e,fieldNormWeight:s});return c.setKeys(r),c.setIndexRecords(i),c}function xe(t,{errors:e=0,currentLocation:s=0,expectedLocation:r=0,distance:i=A.distance,ignoreLocation:c=A.ignoreLocation}={}){const o=e/t.length;if(c)return o;const u=Math.abs(r-s);return i?o+u/i:u?1:o}function Yt(t=[],e=A.minMatchCharLength){let s=[],r=-1,i=-1,c=0;for(let o=t.length;c<o;c+=1){let u=t[c];u&&r===-1?r=c:!u&&r!==-1&&(i=c-1,i-r+1>=e&&s.push([r,i]),r=-1)}return t[c-1]&&c-r>=e&&s.push([r,c-1]),s}const ue=32;function Vt(t,e,s,{location:r=A.location,distance:i=A.distance,threshold:c=A.threshold,findAllMatches:o=A.findAllMatches,minMatchCharLength:u=A.minMatchCharLength,includeMatches:a=A.includeMatches,ignoreLocation:h=A.ignoreLocation}={}){if(e.length>ue)throw new Error(Tt(ue));const d=e.length,g=t.length,E=Math.max(0,Math.min(r,g));let m=c,p=E;const M=u>1||a,w=M?Array(g):[];let N;for(;(N=t.indexOf(e,p))>-1;){let T=xe(e,{currentLocation:N,expectedLocation:E,distance:i,ignoreLocation:h});if(m=Math.min(T,m),p=N+d,M){let P=0;for(;P<d;)w[N+P]=1,P+=1}}p=-1;let $=[],W=1,G=d+g;const oe=1<<d-1;for(let T=0;T<d;T+=1){let P=0,I=G;for(;P<I;)xe(e,{errors:T,currentLocation:E+I,expectedLocation:E,distance:i,ignoreLocation:h})<=m?P=I:G=I,I=Math.floor((G-P)/2+P);G=I;let ae=Math.max(1,E-I+1),H=o?g:Math.min(E+I,g)+d,v=Array(H+2);v[H+1]=(1<<T)-1;for(let j=H;j>=ae;j-=1){let q=j-1,U=s[t.charAt(q)];if(M&&(w[q]=+!!U),v[j]=(v[j+1]<<1|1)&U,T&&(v[j]|=($[j+1]|$[j])<<1|1|$[j+1]),v[j]&oe&&(W=xe(e,{errors:T,currentLocation:q,expectedLocation:E,distance:i,ignoreLocation:h}),W<=m)){if(m=W,p=q,p<=E)break;ae=Math.max(1,2*E-p)}}if(xe(e,{errors:T+1,currentLocation:E,expectedLocation:E,distance:i,ignoreLocation:h})>m)break;$=v}const re={isMatch:p>=0,score:Math.max(.001,W)};if(M){const T=Yt(w,u);T.length?a&&(re.indices=T):re.isMatch=!1}return re}function Jt(t){let e={};for(let s=0,r=t.length;s<r;s+=1){const i=t.charAt(s);e[i]=(e[i]||0)|1<<r-s-1}return e}const Ce=String.prototype.normalize?(t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(t=>t);class at{constructor(e,{location:s=A.location,threshold:r=A.threshold,distance:i=A.distance,includeMatches:c=A.includeMatches,findAllMatches:o=A.findAllMatches,minMatchCharLength:u=A.minMatchCharLength,isCaseSensitive:a=A.isCaseSensitive,ignoreDiacritics:h=A.ignoreDiacritics,ignoreLocation:d=A.ignoreLocation}={}){if(this.options={location:s,threshold:r,distance:i,includeMatches:c,findAllMatches:o,minMatchCharLength:u,isCaseSensitive:a,ignoreDiacritics:h,ignoreLocation:d},e=a?e:e.toLowerCase(),e=h?Ce(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const g=(m,p)=>{this.chunks.push({pattern:m,alphabet:Jt(m),startIndex:p})},E=this.pattern.length;if(E>ue){let m=0;const p=E%ue,M=E-p;for(;m<M;)g(this.pattern.substr(m,ue),m),m+=ue;if(p){const w=E-ue;g(this.pattern.substr(w),w)}}else g(this.pattern,0)}searchIn(e){const{isCaseSensitive:s,ignoreDiacritics:r,includeMatches:i}=this.options;if(e=s?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern===e){let M={isMatch:!0,score:0};return i&&(M.indices=[[0,e.length-1]]),M}const{location:c,distance:o,threshold:u,findAllMatches:a,minMatchCharLength:h,ignoreLocation:d}=this.options;let g=[],E=0,m=!1;this.chunks.forEach(({pattern:M,alphabet:w,startIndex:N})=>{const{isMatch:$,score:W,indices:G}=Vt(e,M,w,{location:c+N,distance:o,threshold:u,findAllMatches:a,minMatchCharLength:h,includeMatches:i,ignoreLocation:d});$&&(m=!0),E+=W,$&&G&&(g=[...g,...G])});let p={isMatch:m,score:m?E/this.chunks.length:1};return m&&i&&(p.indices=g),p}}class ce{constructor(e){this.pattern=e}static isMultiMatch(e){return Ve(e,this.multiRegex)}static isSingleMatch(e){return Ve(e,this.singleRegex)}search(){}}function Ve(t,e){const s=t.match(e);return s?s[1]:null}class Xt extends ce{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const s=e===this.pattern;return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class Zt extends ce{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const r=e.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}}class qt extends ce{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const s=e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,this.pattern.length-1]}}}class es extends ce{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const s=!e.startsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class ts extends ce{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const s=e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class ss extends ce{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const s=!e.endsWith(this.pattern);return{isMatch:s,score:s?0:1,indices:[0,e.length-1]}}}class ut extends ce{constructor(e,{location:s=A.location,threshold:r=A.threshold,distance:i=A.distance,includeMatches:c=A.includeMatches,findAllMatches:o=A.findAllMatches,minMatchCharLength:u=A.minMatchCharLength,isCaseSensitive:a=A.isCaseSensitive,ignoreDiacritics:h=A.ignoreDiacritics,ignoreLocation:d=A.ignoreLocation}={}){super(e),this._bitapSearch=new at(e,{location:s,threshold:r,distance:i,includeMatches:c,findAllMatches:o,minMatchCharLength:u,isCaseSensitive:a,ignoreDiacritics:h,ignoreLocation:d})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class lt extends ce{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let s=0,r;const i=[],c=this.pattern.length;for(;(r=e.indexOf(this.pattern,s))>-1;)s=r+c,i.push([r,s-1]);const o=!!i.length;return{isMatch:o,score:o?0:1,indices:i}}}const ke=[Xt,lt,qt,es,ss,ts,Zt,ut],Je=ke.length,ns=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,rs="|";function is(t,e={}){return t.split(rs).map(s=>{let r=s.trim().split(ns).filter(c=>c&&!!c.trim()),i=[];for(let c=0,o=r.length;c<o;c+=1){const u=r[c];let a=!1,h=-1;for(;!a&&++h<Je;){const d=ke[h];let g=d.isMultiMatch(u);g&&(i.push(new d(g,e)),a=!0)}if(!a)for(h=-1;++h<Je;){const d=ke[h];let g=d.isSingleMatch(u);if(g){i.push(new d(g,e));break}}}return i})}const cs=new Set([ut.type,lt.type]);class os{constructor(e,{isCaseSensitive:s=A.isCaseSensitive,ignoreDiacritics:r=A.ignoreDiacritics,includeMatches:i=A.includeMatches,minMatchCharLength:c=A.minMatchCharLength,ignoreLocation:o=A.ignoreLocation,findAllMatches:u=A.findAllMatches,location:a=A.location,threshold:h=A.threshold,distance:d=A.distance}={}){this.query=null,this.options={isCaseSensitive:s,ignoreDiacritics:r,includeMatches:i,minMatchCharLength:c,findAllMatches:u,ignoreLocation:o,location:a,threshold:h,distance:d},e=s?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern=e,this.query=is(this.pattern,this.options)}static condition(e,s){return s.useExtendedSearch}searchIn(e){const s=this.query;if(!s)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:i,ignoreDiacritics:c}=this.options;e=i?e:e.toLowerCase(),e=c?Ce(e):e;let o=0,u=[],a=0;for(let h=0,d=s.length;h<d;h+=1){const g=s[h];u.length=0,o=0;for(let E=0,m=g.length;E<m;E+=1){const p=g[E],{isMatch:M,indices:w,score:N}=p.search(e);if(M){if(o+=1,a+=N,r){const $=p.constructor.type;cs.has($)?u=[...u,...w]:u.push(w)}}else{a=0,o=0,u.length=0;break}}if(o){let E={isMatch:!0,score:a/o};return r&&(E.indices=u),E}}return{isMatch:!1,score:1}}}const Ie=[];function as(...t){Ie.push(...t)}function je(t,e){for(let s=0,r=Ie.length;s<r;s+=1){let i=Ie[s];if(i.condition(t,e))return new i(t,e)}return new at(t,e)}const be={AND:"$and",OR:"$or"},Be={PATH:"$path",PATTERN:"$val"},De=t=>!!(t[be.AND]||t[be.OR]),us=t=>!!t[Be.PATH],ls=t=>!ne(t)&&rt(t)&&!De(t),Xe=t=>({[be.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function ht(t,e,{auto:s=!0}={}){const r=i=>{let c=Object.keys(i);const o=us(i);if(!o&&c.length>1&&!De(i))return r(Xe(i));if(ls(i)){const a=o?i[Be.PATH]:c[0],h=o?i[Be.PATTERN]:i[a];if(!Z(h))throw new Error(Rt(a));const d={keyId:_e(a),pattern:h};return s&&(d.searcher=je(h,e)),d}let u={children:[],operator:c[0]};return c.forEach(a=>{const h=i[a];ne(h)&&h.forEach(d=>{u.children.push(r(d))})}),u};return De(t)||(t=Xe(t)),r(t)}function hs(t,{ignoreFieldNorm:e=A.ignoreFieldNorm}){t.forEach(s=>{let r=1;s.matches.forEach(({key:i,norm:c,score:o})=>{const u=i?i.weight:null;r*=Math.pow(o===0&&u?Number.EPSILON:o,(u||1)*(e?1:c))}),s.score=r})}function ds(t,e){const s=t.matches;e.matches=[],Q(s)&&s.forEach(r=>{if(!Q(r.indices)||!r.indices.length)return;const{indices:i,value:c}=r;let o={indices:i,value:c};r.key&&(o.key=r.key.src),r.idx>-1&&(o.refIndex=r.idx),e.matches.push(o)})}function fs(t,e){e.score=t.score}function ms(t,e,{includeMatches:s=A.includeMatches,includeScore:r=A.includeScore}={}){const i=[];return s&&i.push(ds),r&&i.push(fs),t.map(c=>{const{idx:o}=c,u={item:e[o],refIndex:o};return i.length&&i.forEach(a=>{a(c,u)}),u})}class X{constructor(e,s={},r){this.options={...A,...s},this.options.useExtendedSearch,this._keyStore=new Pt(this.options.keys),this.setCollection(e,r)}setCollection(e,s){if(this._docs=e,s&&!(s instanceof Ne))throw new Error(Nt);this._myIndex=s||ot(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){Q(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const s=[];for(let r=0,i=this._docs.length;r<i;r+=1){const c=this._docs[r];e(c,r)&&(this.removeAt(r),r-=1,i-=1,s.push(c))}return s}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:s=-1}={}){const{includeMatches:r,includeScore:i,shouldSort:c,sortFn:o,ignoreFieldNorm:u}=this.options;let a=Z(e)?Z(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return hs(a,{ignoreFieldNorm:u}),c&&a.sort(o),nt(s)&&s>-1&&(a=a.slice(0,s)),ms(a,this._docs,{includeMatches:r,includeScore:i})}_searchStringList(e){const s=je(e,this.options),{records:r}=this._myIndex,i=[];return r.forEach(({v:c,i:o,n:u})=>{if(!Q(c))return;const{isMatch:a,score:h,indices:d}=s.searchIn(c);a&&i.push({item:c,idx:o,matches:[{score:h,value:c,norm:u,indices:d}]})}),i}_searchLogical(e){const s=ht(e,this.options),r=(u,a,h)=>{if(!u.children){const{keyId:g,searcher:E}=u,m=this._findMatches({key:this._keyStore.get(g),value:this._myIndex.getValueForItemAtKeyId(a,g),searcher:E});return m&&m.length?[{idx:h,item:a,matches:m}]:[]}const d=[];for(let g=0,E=u.children.length;g<E;g+=1){const m=u.children[g],p=r(m,a,h);if(p.length)d.push(...p);else if(u.operator===be.AND)return[]}return d},i=this._myIndex.records,c={},o=[];return i.forEach(({$:u,i:a})=>{if(Q(u)){let h=r(s,u,a);h.length&&(c[a]||(c[a]={idx:a,item:u,matches:[]},o.push(c[a])),h.forEach(({matches:d})=>{c[a].matches.push(...d)}))}}),o}_searchObjectList(e){const s=je(e,this.options),{keys:r,records:i}=this._myIndex,c=[];return i.forEach(({$:o,i:u})=>{if(!Q(o))return;let a=[];r.forEach((h,d)=>{a.push(...this._findMatches({key:h,value:o[d],searcher:s}))}),a.length&&c.push({idx:u,item:o,matches:a})}),c}_findMatches({key:e,value:s,searcher:r}){if(!Q(s))return[];let i=[];if(ne(s))s.forEach(({v:c,i:o,n:u})=>{if(!Q(c))return;const{isMatch:a,score:h,indices:d}=r.searchIn(c);a&&i.push({score:h,key:e,value:c,idx:o,norm:u,indices:d})});else{const{v:c,n:o}=s,{isMatch:u,score:a,indices:h}=r.searchIn(c);u&&i.push({score:a,key:e,value:c,norm:o,indices:h})}return i}}X.version="7.1.0";X.createIndex=ot;X.parseIndex=Ut;X.config=A;X.parseQuery=ht;as(os);const he=["all","agents","buildings","areas","commands"],Ze={".ts":"file-code",".tsx":"atom",".js":"file-code",".jsx":"atom",".py":"file-code",".rs":"file-code",".go":"file-code",".md":"file-text",".json":"clipboard",".yaml":"gear",".yml":"gear",".css":"palette",".scss":"palette",".html":"globe",".sql":"database",".sh":"terminal",".env":"lock",".toml":"gear",".lock":"lock",default:"file-text"};function gs(t){switch(t){case"scout":return"class-scout";case"builder":return"class-builder";case"debugger":return"class-debugger";case"architect":return"class-architect";case"warrior":return"class-warrior";case"support":return"class-support";case"boss":return"class-boss";default:return"class-default"}}function ps(t,e=16){var i;const s="."+(((i=t.split(".").pop())==null?void 0:i.toLowerCase())??""),r=Ze[s]||Ze.default;return l.jsx(V,{name:r,size:e})}function js(t,e=16){return l.jsx(V,{name:gs(t),size:e,weight:"fill"})}function dt(t){const e=Math.floor(t/1e3),s=Math.floor(e/60),r=Math.floor(s/60),i=Math.floor(r/24);return i>0?`${i}d ${r%24}h ago`:r>0?`${r}h ${s%60}m ago`:s>0?`${s}m ago`:"just now"}function Bs(t){const s=Date.now()-t;return dt(s)}const ft="tide-commander:spotlight-recent-agents",As=15;function mt(){try{const t=localStorage.getItem(ft);if(!t)return{};const e=JSON.parse(t);if(!e||typeof e!="object"||Array.isArray(e))return{};const s={};for(const[r,i]of Object.entries(e))typeof r=="string"&&typeof i=="number"&&(s[r]=i);return s}catch{return{}}}function ys(t){try{const e=mt();e[t]=Date.now();const s=Object.entries(e).sort((r,i)=>i[1]-r[1]).slice(0,As);localStorage.setItem(ft,JSON.stringify(Object.fromEntries(s)))}catch{}}function Ee(t,e,s){const r=t?s[t]??0:0;return Math.max(e??0,r)}function qe(t){switch(t){case"agent":return"Agent";case"command":return"Command";case"area":return"Area";case"modified-file":return"Changed";case"building":return"Server";default:return t}}const xs=["command","agent","building","area","modified-file"];function Es(){const t=st(ge.SPOTLIGHT_TAB,"all");return he.includes(t)?t:"all"}function et(){return _t(ge.SPOTLIGHT_QUERY,"")}function Cs(){const t=st(ge.AOP_CONFIG,{});return t.sortMode==="name"||t.sortMode==="status"||t.sortMode==="recent"?t.sortMode:"recent"}function bs({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:r,onOpenToolbox:i,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:u,onOpenDatabasePanel:a,onOpenMonitoringModal:h}){const d=yt(),g=xt(),E=Et(),m=Ct(),p=bt(),M=wt(),w=f.useRef(e);w.current=e;const N=f.useRef(s);N.current=s;const $=f.useRef(r);$.current=r;const W=f.useRef(i);W.current=i;const G=f.useRef(c);G.current=c;const oe=f.useRef(o);oe.current=o;const re=f.useRef(u);re.current=u;const T=f.useRef(a);T.current=a;const P=f.useRef(h);P.current=h;const[I,ae]=f.useState(et),[H,v]=f.useState(0),[C,j]=f.useState(Es),q=f.useCallback(n=>{ae(n),Mt(ge.SPOTLIGHT_QUERY,n)},[]);f.useEffect(()=>{t&&(ae(et()),v(0))},[t]);const U=f.useCallback(n=>{j(n),vt(ge.SPOTLIGHT_TAB,n)},[]),Re=f.useRef(C);Re.current=C;const gt=f.useCallback(n=>{const x=he.indexOf(Re.current),b=he[(x+n+he.length)%he.length];U(b)},[U]);f.useEffect(()=>{v(0)},[C]);const Me=se.getShortcuts(),de=f.useMemo(()=>t?mt():{},[t]),pe=f.useMemo(()=>{if(!t)return[];const n=Me.find(b=>b.id==="spawn-agent"),x=Me.find(b=>b.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:n?He(n):"Alt+N",icon:l.jsx(V,{name:"plus",size:16}),action:()=>{w.current(),N.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:x?He(x):"Ctrl+K",icon:l.jsx(V,{name:"dashboard",size:16}),action:()=>{w.current(),$.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:l.jsx(V,{name:"gear",size:16}),action:()=>{w.current(),W.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:l.jsx(V,{name:"chart-line",size:16}),action:()=>{var b;w.current(),(b=P.current)==null||b.call(P)}}]},[t,Me]),le=f.useMemo(()=>t?Array.from(d.values()).map(n=>{const x=(m||[]).filter(O=>O.agentId===n.id).map(O=>O.filePath),b=[...new Set(x)],F=b.map(O=>O.split("/").pop()||O),_=[];n.lastAssignedTask&&_.push(n.lastAssignedTask);const R=`${n.class} • ${n.cwd}`;let B=`${n.name} ${n.class} ${n.status} ${n.cwd}`;n.taskLabel&&(B+=` ${n.taskLabel}`),F.length>0&&(B+=` ${F.join(" ")} ${b.join(" ")}`),_.length>0&&(B+=` ${_.join(" ")}`);const L=Date.now()-n.lastActivity;let J;return n.lastAssignedTask&&(n.lastAssignedTask.length>150?J=n.lastAssignedTask.slice(0,150)+"...":J=n.lastAssignedTask),{id:`agent-${n.id}`,type:"agent",title:n.name,subtitle:R,lastUserInput:J,timeAway:L,icon:l.jsx(Ft,{agent:n,size:20}),_searchText:B,_modifiedFiles:b,_userQueries:_,_agentId:n.id,_lastActivity:n.lastActivity,_taskLabel:n.taskLabel,_status:n.status,action:()=>{w.current(),ys(n.id),se.selectAgent(n.id),se.getState().viewMode!=="flat"&&se.requestTerminalExpand()}}}):[],[t,d,m]),Ae=f.useMemo(()=>t?Array.from(g.values()).map(n=>{var x;return{id:`area-${n.id}`,type:"area",title:n.name,subtitle:`${n.assignedAgentIds.length} agents • ${((x=n.directories)==null?void 0:x.length)||0} folders`,icon:l.jsx(V,{name:"map",size:16}),action:()=>{w.current(),se.selectArea(n.id)}}}):[],[t,g]),Te=f.useMemo(()=>{const n=new Map;for(const x of le)x._agentId&&n.set(x._agentId,x);return n},[le]),Le=f.useMemo(()=>{const n=new Map;if(!t)return n;for(const x of d.values()){const b=se.getAreaForAgent(x.id);if(!b||b.archived)continue;const F=n.get(b.id);F?F.push(x):n.set(b.id,[x])}return n},[t,d,g]),$e=f.useMemo(()=>{const n=new Map;for(const x of p)n.has(x.agentId)||n.set(x.agentId,x.timestamp);return n},[p]),ve=f.useMemo(()=>{if(!t)return[];const n=I.trim().toLowerCase(),x=St({sortMode:Cs(),agentsWithUnseenOutput:M,getLatestToolTimestamp:_=>$e.get(_)}),b=Array.from(g.values()).filter(_=>!_.archived).filter(_=>n?_.name.toLowerCase().includes(n):!0).sort((_,R)=>_.name.localeCompare(R.name,void 0,{sensitivity:"base"})),F=[];for(const _ of b){const B=(Le.get(_.id)||[]).slice().sort(x).map(L=>Te.get(L.id)).filter(L=>!!L);!n&&B.length===0||F.push({areaId:_.id,areaName:_.name,areaColor:_.color,agents:B})}return F},[t,I,g,Le,Te,M,$e]),ye=f.useMemo(()=>t?Array.from(E.values()).filter(n=>n.type==="server"||n.type==="boss"||n.type==="database").map(n=>{var L,J,O,ie,me;const x=n.status==="running"?"#4ade80":n.status==="stopped"?"#f87171":"#facc15",b=n.type==="boss"?"crown":n.type==="database"?"database":"desktop";let _=`${n.type==="boss"?"Boss":n.type==="database"?"Database":"Server"} • ${n.status}`;if(n.type==="database"&&((J=(L=n.database)==null?void 0:L.connections)!=null&&J.length)){const z=n.database.connections[0];_+=` • ${z.engine} @ ${z.host}`}else n.cwd&&(_+=` • ${n.cwd}`);const R=((O=n.pm2Status)==null?void 0:O.ports)||[];let B=`${n.name} ${n.type} ${n.status} ${n.cwd||""} ${((ie=n.pm2)==null?void 0:ie.name)||""}`;if(R.length>0&&(B+=` ${R.join(" ")}`),n.type==="database"&&((me=n.database)!=null&&me.connections))for(const z of n.database.connections)B+=` ${z.name} ${z.engine} ${z.host} ${z.database||""} mysql postgresql sql`;return{id:`building-${n.id}`,type:"building",title:n.name,subtitle:_,_ports:R,icon:l.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[l.jsx(V,{name:"status-pending",size:10,weight:"fill",color:x}),l.jsx(V,{name:b,size:16})]}),_searchText:B,action:()=>{var z;w.current(),n.type==="boss"?re.current(n.id):n.type==="database"?T.current(n.id):(z=n.pm2)!=null&&z.enabled&&oe.current(n.id)}}}):[],[t,E]),Pe=f.useMemo(()=>{if(!t)return[];const n=m||[],x=new Set,b=[];for(const F of n){if(x.has(F.filePath))continue;x.add(F.filePath);const _=F.filePath.split("/").pop()||F.filePath,R=F.action==="created"?"Created":F.action==="modified"?"Modified":F.action==="deleted"?"Deleted":"Read";if(b.push({id:`modified-${F.filePath}-${F.timestamp}`,type:"modified-file",title:_,subtitle:`${R} by ${F.agentName} • ${F.filePath}`,matchedText:F.filePath,icon:F.action==="deleted"?l.jsx(V,{name:"trash",size:16}):ps(F.filePath),action:()=>{w.current();const B=Array.from(se.getState().areas.values());for(const L of B)for(const J of L.directories||[])if(F.filePath.startsWith(J)){se.setFileViewerPath(F.filePath),G.current(L.id);return}se.selectAgent(F.agentId)}}),b.length>=50)break}return b},[t,m]),Oe=f.useMemo(()=>new X(le,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[le]),Ke=f.useMemo(()=>new X(pe,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[pe]),ze=f.useMemo(()=>new X(Ae,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[Ae]),Qe=f.useMemo(()=>new X(Pe,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[Pe]),We=f.useMemo(()=>new X(ye,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ye]),fe=f.useMemo(()=>{if(!I.trim()){const y=[];y.push(...ye);const S=[...le].sort((D,K)=>{const ee=Ee(D._agentId,D._lastActivity,de);return Ee(K._agentId,K._lastActivity,de)-ee});y.push(...S),y.push(...pe.slice(0,2)),y.push(...Ae.slice(0,2));const k={};return xs.forEach((D,K)=>{k[D]=K}),y.sort((D,K)=>(k[D.type]??999)-(k[K.type]??999)),y}const n=I.trim().toLowerCase(),x=Oe.search(I).slice(0,8),b=Ke.search(I).slice(0,3),F=ze.search(I).slice(0,2),_=Qe.search(I).slice(0,3),R=We.search(I).filter(y=>{const S=y.score??1;return`${y.item.title} ${y.item.subtitle||""} ${y.item._searchText||""}`.toLowerCase().includes(n)||S<=.2}).slice(0,4),B={agent:5,building:4,command:3,area:2,"modified-file":1},L=y=>{if(!n)return 1;const S=y.title.toLowerCase();return S===n?6:S.startsWith(n)?5:S.split(/[^a-z0-9]+/i).includes(n)?4:S.includes(n)?3:`${y.subtitle||""} ${y._searchText||""} ${y.matchedText||""}`.toLowerCase().includes(n)?2:1},J=(y,S)=>{const k=(1-Math.min(1,S??1))*4;return L(y)*100+(B[y.type]??0)*5+k},O=new Map,ie=(y,S)=>{const k=O.get(y.type),D={item:y,score:J(y,S)};k?k.push(D):O.set(y.type,[D])};for(const y of x){const S={...y.item};if(S._modifiedFiles&&S._modifiedFiles.length>0){const k=S._modifiedFiles.filter(D=>{var te;const K=((te=D.split("/").pop())==null?void 0:te.toLowerCase())||"",ee=D.toLowerCase();return K.includes(n)||ee.includes(n)});k.length>0&&(S.matchedFiles=k)}if(S._userQueries&&S._userQueries.length>0){const k=S._userQueries.find(D=>D.toLowerCase().includes(n));if(k)if(k.length>200){const K=k.toLowerCase().indexOf(n),ee=Math.max(0,K-60),te=Math.min(k.length,K+n.length+100);S.matchedQuery=(ee>0?"...":"")+k.slice(ee,te)+(te<k.length?"...":"")}else S.matchedQuery=k}ie(S,y.score)}for(const y of R)ie(y.item,y.score);for(const y of b)ie(y.item,y.score);for(const y of F)ie(y.item,y.score);for(const y of _)ie(y.item,y.score);for(const[y,S]of O)y==="agent"?S.sort((k,D)=>{const K=L(k.item),ee=L(D.item);if(ee!==K)return ee-K;const te=Ee(k.item._agentId,k.item._lastActivity,de),Ge=Ee(D.item._agentId,D.item._lastActivity,de);return Ge!==te?Ge-te:D.score-k.score}):S.sort((k,D)=>D.score-k.score);const me=y=>y.reduce((S,k)=>Math.max(S,k.score),-1),z=[];return Array.from(O.values()).sort((y,S)=>me(S)-me(y)).forEach(y=>{for(const S of y)z.push(S.item)}),z},[I,Oe,Ke,ze,Qe,We,pe,le,Ae,ye,de]),Y=f.useMemo(()=>{switch(C){case"agents":return fe.filter(n=>n.type==="agent");case"buildings":return fe.filter(n=>n.type==="building");case"commands":return fe.filter(n=>n.type==="command");case"areas":return ve.flatMap(n=>n.agents);case"all":default:return fe}},[C,fe,ve]);f.useEffect(()=>{H>=Y.length&&v(Math.max(0,Y.length-1))},[Y.length,H]);const pt=f.useCallback(n=>{if(n.altKey&&!n.ctrlKey&&!n.metaKey&&(n.key==="p"||n.key==="n"||n.key==="P"||n.key==="N")){n.preventDefault(),n.stopPropagation(),n.nativeEvent.stopImmediatePropagation();const x=n.key.toLowerCase();v(x==="p"?b=>b>0?b-1:Y.length-1:b=>b<Y.length-1?b+1:0);return}switch(n.key){case"Escape":n.preventDefault(),w.current();break;case"ArrowUp":n.preventDefault(),v(x=>x>0?x-1:Y.length-1);break;case"ArrowDown":n.preventDefault(),v(x=>x<Y.length-1?x+1:0);break;case"Enter":n.preventDefault(),Y[H]&&Y[H].action();break}},[Y,H]),At=f.useCallback((n,x)=>{if(!x||!n)return n;const b=n.toLowerCase(),F=x.toLowerCase(),_=[];let R=0,B=b.indexOf(F),L=0;for(;B!==-1;)B>R&&_.push(n.slice(R,B)),_.push(Fe.createElement("mark",{key:L++,className:"spotlight-highlight"},n.slice(B,B+x.length))),R=B+x.length,B=b.indexOf(F,R);return R<n.length&&_.push(n.slice(R)),_.length>0?Fe.createElement(Fe.Fragment,null,..._):n},[]);return{query:I,setQuery:q,selectedIndex:H,setSelectedIndex:v,results:Y,activeTab:C,setActiveTab:U,cycleTab:gt,areaSections:ve,handleKeyDown:pt,highlightMatch:At}}const ws=f.forwardRef(function({query:e,onQueryChange:s,onKeyDown:r,onResetSelection:i},c){const{t:o}=we(["common"]);return l.jsxs("div",{className:"spotlight-input-wrapper",children:[l.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),l.jsx("input",{ref:c,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:u=>{s(u.target.value),i()},onKeyDown:r,autoFocus:!0,spellCheck:!1}),l.jsxs("div",{className:"spotlight-input-hints",children:[l.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),l.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),l.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Ms=f.memo(function({activeTab:e,onSelect:s}){const{t:r}=we(["terminal"]);return l.jsxs("div",{className:"spotlight-tabs",role:"tablist","aria-label":r("terminal:spotlight.tabsLabel"),children:[he.map(i=>l.jsx("button",{type:"button",role:"tab","aria-selected":i===e,tabIndex:-1,className:`spotlight-tab${i===e?" active":""}`,onClick:()=>s(i),children:r(`terminal:spotlight.tabs.${i}`)},i)),l.jsx("span",{className:"spotlight-tabs-hint",children:l.jsx("kbd",{children:"Tab"})})]})}),tt=f.memo(function({result:e,isSelected:s,query:r,highlightMatch:i,onClick:c,onMouseEnter:o}){const u=e.activityText||e.matchedFiles&&e.matchedFiles.length>0||e.matchedQuery,a=e._status?kt(e._status):void 0,h=e.type==="building"?e._ports:void 0;return l.jsxs("div",{className:`spotlight-item ${s?"selected":""} ${e.activityText?"has-activity":""}`,onClick:c,onMouseEnter:o,role:"option","aria-selected":s,children:[l.jsx("span",{className:"spotlight-item-icon","aria-hidden":"true",children:e.icon}),l.jsxs("div",{className:"spotlight-item-content",children:[l.jsxs("div",{className:"spotlight-item-header",children:[l.jsx("span",{className:"spotlight-item-title",children:i(e.title,r)}),e._status&&a&&l.jsxs("span",{className:`spotlight-item-agent-status${e._status==="working"?" spotlight-item-agent-status--working":""}`,style:{color:a,background:`${a}1f`,borderColor:`${a}55`},children:[e._status==="working"&&l.jsx("span",{className:"spotlight-working-dot","aria-hidden":"true"}),e._status.replace(/_/g," ")]}),e._taskLabel&&l.jsxs("span",{className:"spotlight-item-task-label",title:e._taskLabel,children:[l.jsx(V,{name:"task",size:9,"aria-hidden":!0}),i(e._taskLabel,r)]}),l.jsx("span",{className:`spotlight-item-type ${e.type}`,"aria-label":qe(e.type),children:qe(e.type)})]}),e.subtitle&&l.jsx("span",{className:"spotlight-item-subtitle",children:i(e.subtitle,r)}),h&&h.length>0&&l.jsx("span",{className:"spotlight-item-ports",children:h.map(d=>l.jsxs("a",{className:"spotlight-port-link",href:`http://localhost:${d}`,target:"_blank",rel:"noopener noreferrer",title:`http://localhost:${d}`,onClick:g=>g.stopPropagation(),children:[":",d]},d))}),e.activityText&&l.jsx("span",{className:"spotlight-item-activity",children:i(e.activityText,r)}),u&&l.jsxs("div",{className:"spotlight-item-details",children:[e.matchedFiles&&e.matchedFiles.length>0&&l.jsx("span",{className:"spotlight-item-files",children:e.matchedFiles.map((d,g)=>l.jsxs("span",{className:"file-badge",children:[g>0&&l.jsx("span",{className:"file-separator",children:"•"}),i(d.split("/").pop()||d,r)]},d))}),e.matchedQuery&&l.jsx("span",{className:"spotlight-item-query",children:i(e.matchedQuery,r)})]}),e.timeAway!==void 0&&l.jsx("span",{className:"spotlight-item-time",children:l.jsxs("span",{className:"spotlight-time-away",children:["Idle: ",dt(e.timeAway)]})}),e.lastUserInput&&!e.matchedQuery&&l.jsxs("span",{className:"spotlight-item-last-input",children:['"',i(e.lastUserInput,r),'"']})]})]})}),vs=f.forwardRef(function({results:e,selectedIndex:s,query:r,activeTab:i,areaSections:c,highlightMatch:o,onSelectIndex:u},a){const{t:h}=we(["terminal"]),d=f.useRef(!1);f.useEffect(()=>{d.current=!1},[e]),f.useEffect(()=>{const m=typeof a=="function"?null:a==null?void 0:a.current;if(!m)return;const p=()=>{d.current=!0};return m.addEventListener("mousemove",p),()=>{m.removeEventListener("mousemove",p)}},[a,e]);const g={command:h("terminal:spotlight.categories.commands"),agent:h("terminal:spotlight.categories.agents"),building:h("terminal:spotlight.categories.infrastructure"),area:h("terminal:spotlight.categories.areas"),"modified-file":h("terminal:spotlight.categories.modifiedFiles")},E=f.useMemo(()=>{const m=[];let p=null,M=[];return e.forEach((w,N)=>{w.type!==p&&(p!==null&&M.length>0&&m.push([p,M]),p=w.type,M=[]),M.push({result:w,index:N})}),p!==null&&M.length>0&&m.push([p,M]),m},[e]);if(f.useEffect(()=>{if(!a||typeof a=="function")return;const m=a.current;if(!m)return;const p=m.querySelector(".spotlight-item.selected");p&&p.scrollIntoView({block:"nearest",behavior:"smooth"})},[s,a]),i==="areas"){if(c.length===0)return l.jsx("div",{className:"spotlight-results",ref:a,children:l.jsx("div",{className:"spotlight-empty",children:h("terminal:spotlight.noResults")})});let m=0;return l.jsx("div",{className:"spotlight-results",ref:a,children:c.map(p=>l.jsxs("div",{children:[l.jsxs("div",{className:"spotlight-category-header spotlight-area-section-header",children:[l.jsx("span",{className:"spotlight-area-dot",style:{background:p.areaColor},"aria-hidden":"true"}),l.jsx("span",{className:"spotlight-area-name",children:p.areaName}),l.jsx("span",{className:"spotlight-area-count",children:p.agents.length})]}),p.agents.length===0?l.jsx("div",{className:"spotlight-area-empty",children:h("terminal:spotlight.noAgentsInArea")}):p.agents.map(M=>{const w=m++;return l.jsx(tt,{result:M,isSelected:w===s,query:r,highlightMatch:o,onClick:()=>M.action(),onMouseEnter:()=>{d.current&&u(w)}},M.id)})]},p.areaId))})}return e.length===0?l.jsx("div",{className:"spotlight-results",ref:a,children:l.jsx("div",{className:"spotlight-empty",children:h("terminal:spotlight.noResults")})}):l.jsx("div",{className:"spotlight-results",ref:a,children:E.map(([m,p])=>l.jsxs("div",{children:[E.length>1&&l.jsx("div",{className:"spotlight-category-header",children:g[m]||m}),p.map(({result:M,index:w})=>l.jsx(tt,{result:M,isSelected:w===s,query:r,highlightMatch:o,onClick:()=>M.action(),onMouseEnter:()=>{d.current&&u(w)}},M.id))]},m))})}),Fs=f.memo(function(){const{t:e}=we(["terminal"]);return l.jsxs("div",{className:"spotlight-footer",children:[l.jsxs("div",{className:"spotlight-footer-left",children:[l.jsxs("span",{className:"spotlight-footer-hint",children:[l.jsx("kbd",{children:"↑"}),l.jsx("kbd",{children:"↓"})," ",l.jsx("kbd",{children:"Alt+N"}),l.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),l.jsxs("span",{className:"spotlight-footer-hint",children:[l.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]}),l.jsxs("span",{className:"spotlight-footer-hint",children:[l.jsx("kbd",{children:"Tab"})," ",e("terminal:spotlight.switchTabs")]})]}),l.jsx("div",{className:"spotlight-footer-right",children:l.jsxs("span",{className:"spotlight-footer-hint",children:[l.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),Ss=768;function Ds({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:r,onOpenToolbox:i,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:u,onOpenDatabasePanel:a,onOpenMonitoringModal:h}){const d=f.useRef(null),g=f.useRef(null),E=f.useRef(null),m=f.useRef(0),{query:p,setQuery:M,selectedIndex:w,setSelectedIndex:N,results:$,activeTab:W,setActiveTab:G,cycleTab:oe,areaSections:re,handleKeyDown:T,highlightMatch:P}=bs({isOpen:t,onClose:e,onOpenSpawnModal:s,onOpenCommanderView:r,onOpenToolbox:i,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:u,onOpenDatabasePanel:a,onOpenMonitoringModal:h});m.current=$.length;const I=f.useRef(oe);I.current=oe,f.useEffect(()=>{t&&setTimeout(()=>{var v,C;(v=d.current)==null||v.focus(),(C=d.current)==null||C.select()},50)},[t]),f.useEffect(()=>{if(!t)return;const v=window.visualViewport;if(!v||window.innerWidth>Ss)return;const C=()=>{const j=g.current;j&&(j.style.height=`${v.height}px`,j.style.top=`${v.offsetTop}px`)};return C(),v.addEventListener("resize",C),v.addEventListener("scroll",C),()=>{v.removeEventListener("resize",C),v.removeEventListener("scroll",C);const j=g.current;j&&(j.style.height="",j.style.top="")}},[t]),f.useEffect(()=>{if(!t)return;const v=C=>{if(C.key==="Escape"){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation(),e();return}if(C.key==="Tab"){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation(),I.current(C.shiftKey?-1:1);return}if(C.altKey&&!C.ctrlKey&&!C.metaKey&&(C.key==="n"||C.key==="p"||C.key==="N"||C.key==="P")){C.preventDefault(),C.stopPropagation(),C.stopImmediatePropagation();const j=C.key.toLowerCase(),q=m.current;N(j==="p"?U=>U>0?U-1:q-1:U=>U<q-1?U+1:0);return}};return window.addEventListener("keydown",v,{capture:!0}),()=>{window.removeEventListener("keydown",v,{capture:!0})}},[t,e]);const ae=f.useCallback(v=>{v.target===v.currentTarget&&e()},[e]),H=f.useCallback(()=>{N(0)},[N]);return t?l.jsx("div",{ref:g,className:"spotlight-overlay",onClick:ae,children:l.jsxs("div",{className:"spotlight-modal",children:[l.jsx(ws,{ref:d,query:p,onQueryChange:M,onKeyDown:T,onResetSelection:H}),l.jsx(Ms,{activeTab:W,onSelect:G}),l.jsx(vs,{ref:E,results:$,selectedIndex:w,query:p,activeTab:W,areaSections:re,highlightMatch:P,onSelectIndex:N}),l.jsx(Fs,{})]})}):null}export{Ze as FILE_ICON_NAMES,Ds as Spotlight,Fs as SpotlightFooter,ws as SpotlightInput,tt as SpotlightItem,vs as SpotlightResults,dt as formatDuration,Bs as formatRelativeTime,js as getAgentIcon,ps as getFileIconFromPath,qe as getTypeLabel,bs as useSpotlightSearch};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{bj as ta,u as B,j as e,aO as j,bm as Ms,bn as Fs,aP as Ue,s as D,bo as Ks,r as d,D as Z,I as F,a4 as Us,aY as qe,f as na,bp as la,K as ia,S as oa,k as ra,a3 as $s,aZ as He}from"./main-
|
|
1
|
+
import{bj as ta,u as B,j as e,aO as j,bm as Ms,bn as Fs,aP as Ue,s as D,bo as Ks,r as d,D as Z,I as F,a4 as Us,aY as qe,f as na,bp as la,K as ia,S as oa,k as ra,a3 as $s,aZ as He}from"./main-D7pG1mPb.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const ca=[{value:"",labelKey:"terminal:building.colorDefault"},{value:"#2a2a3a",labelKey:"terminal:building.colorDarkGray"},{value:"#3a2a2a",labelKey:"terminal:building.colorDarkRed"},{value:"#2a3a2a",labelKey:"terminal:building.colorDarkGreen"},{value:"#2a2a4a",labelKey:"terminal:building.colorDarkBlue"},{value:"#3a3a2a",labelKey:"terminal:building.colorDarkYellow"},{value:"#3a2a3a",labelKey:"terminal:building.colorDarkPurple"},{value:"#2a3a3a",labelKey:"terminal:building.colorDarkCyan"},{value:"#4a3a3a",labelKey:"terminal:building.colorWarmBrown"},{value:"#3a4a4a",labelKey:"terminal:building.colorCoolSteel"}];function ma(o){return ta.t(o)}function Ve(o){if(o===0)return"0 B";const p=1024,u=["B","KB","MB","GB"],x=Math.floor(Math.log(o)/Math.log(p));return parseFloat((o/Math.pow(p,x)).toFixed(1))+" "+u[x]}function da(o){const u=Date.now()-o,x=Math.floor(u/(1e3*60*60)),n=Math.floor(u%(1e3*60*60)/(1e3*60));return x>0?`${x}h ${n}m`:`${n}m`}const Hs={30:"#1a1a1a",31:"#e74c3c",32:"#2ecc71",33:"#f39c12",34:"#3498db",35:"#9b59b6",36:"#00bcd4",37:"#ecf0f1",90:"#7f8c8d",91:"#ff6b6b",92:"#4ade80",93:"#fbbf24",94:"#60a5fa",95:"#c084fc",96:"#22d3ee",97:"#ffffff"};function qs(o){const p=[],u=/\x1B\[([0-9;]*)m/g;let x=0,n=null,y;for(;(y=u.exec(o))!==null;){if(y.index>x){const g=o.slice(x,y.index);n?p.push(e.jsx("span",{style:{color:n},children:g},p.length)):p.push(g)}const C=y[1].split(";").map(Number);for(const g of C)g===0||g===39?n=null:Hs[g]&&(n=Hs[g]);x=u.lastIndex}if(x<o.length){const C=o.slice(x);n?p.push(e.jsx("span",{style:{color:n},children:C},p.length)):p.push(C)}return p.length>0?p:[o]}function ua({buildingName:o,onClose:p,onConfirm:u}){const{t:x}=B(["terminal","common"]);return e.jsx("div",{className:"modal-overlay visible",onClick:p,children:e.jsxs("div",{className:"modal confirm-modal",onClick:n=>n.stopPropagation(),children:[e.jsx("div",{className:"modal-header",children:x("terminal:building.deleteBuilding")}),e.jsxs("div",{className:"modal-body confirm-modal-body",children:[e.jsx("p",{children:x("terminal:building.deleteConfirm",{name:o})}),e.jsx("p",{className:"confirm-modal-note",children:x("terminal:building.deleteNote")})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("button",{className:"btn btn-secondary",onClick:p,children:x("common:buttons.cancel")}),e.jsx("button",{className:"btn btn-danger",onClick:u,autoFocus:!0,children:x("common:buttons.delete")})]})]})})}function pa({usePM2:o,setUsePM2:p}){const{t:u}=B(["terminal"]);return e.jsxs("div",{className:"form-section pm2-toggle-section",children:[e.jsxs("label",{className:"toggle-switch",children:[e.jsx("input",{type:"checkbox",className:"toggle-input",checked:o,onChange:x=>p(x.target.checked)}),e.jsx("span",{className:"toggle-track",children:e.jsx("span",{className:"toggle-thumb"})}),e.jsxs("span",{className:"toggle-label",children:[e.jsx("span",{className:"pm2-badge",children:"PM2"}),u("terminal:building.usePM2")]})]}),e.jsx("div",{className:"form-hint",children:u("terminal:building.pm2Hint")})]})}function ha({usePM2:o,pm2Script:p,setPm2Script:u,pm2Args:x,setPm2Args:n,pm2Interpreter:y,setPm2Interpreter:C,pm2InterpreterArgs:g,setPm2InterpreterArgs:v,pm2Env:s,setPm2Env:h,isEditMode:a,building:t,handleCommand:r}){var N;const{t:i}=B(["terminal","common"]);return o?e.jsxs("div",{className:"form-section pm2-config-section",children:[e.jsx("label",{className:"form-label",children:i("terminal:building.pm2Configuration")}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Script"),e.jsx(j,{text:i("terminal:building.helpPm2Script"),title:i("terminal:building.pm2Script"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:p,onChange:b=>u(b.target.value),placeholder:"npm, java, python, ./app.js",required:o})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Arguments"),e.jsx(j,{text:i("terminal:building.helpPm2Arguments"),title:i("terminal:building.pm2Arguments"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:x,onChange:b=>n(b.target.value),placeholder:"run dev, -jar app.jar, app.py"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Interpreter"),e.jsx(j,{text:i("terminal:building.helpPm2Interpreter"),title:i("terminal:building.pm2Interpreter"),position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:y,onChange:b=>C(b.target.value),children:Object.keys(Ms).map(b=>e.jsx("option",{value:b,children:Ms[b].label},b))})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2InterpArgs"),e.jsx(j,{text:i("terminal:building.helpPm2InterpArgs"),title:i("terminal:building.pm2InterpArgs"),position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:g,onChange:b=>v(b.target.value),placeholder:"-jar (for Java)"})]}),e.jsxs("div",{className:"command-row env-row",children:[e.jsxs("span",{className:"command-label",children:[i("terminal:building.pm2Environment"),e.jsx(j,{text:i("terminal:building.helpPm2Environment"),title:i("terminal:building.pm2Environment"),position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input form-textarea",value:s,onChange:b=>h(b.target.value),placeholder:`KEY=value
|
|
2
2
|
SERVER_PORT=7201
|
|
3
3
|
NODE_ENV=production`,rows:3})]}),e.jsx("div",{className:"pm2-examples",children:e.jsxs("details",{children:[e.jsx("summary",{children:i("terminal:building.pm2Examples")}),e.jsxs("div",{className:"pm2-examples-content",children:[e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Node.js:"})," Script: ",e.jsx("code",{children:"npm"}),", Args: ",e.jsx("code",{children:"run dev"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Symfony:"})," Script: ",e.jsx("code",{children:"symfony"}),", Args: ",e.jsx("code",{children:"serve --no-daemon"}),", Interpreter: ",e.jsx("code",{children:"None"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Java JAR:"})," Script: ",e.jsx("code",{children:"app.jar"}),", Interpreter: ",e.jsx("code",{children:"Java"}),", Interp. Args: ",e.jsx("code",{children:"-jar"})]}),e.jsxs("div",{className:"pm2-example",children:[e.jsx("strong",{children:"Python:"})," Script: ",e.jsx("code",{children:"app.py"}),", Interpreter: ",e.jsx("code",{children:"Python 3"})]})]})]})}),a&&(t==null?void 0:t.pm2Status)&&e.jsx("div",{className:"pm2-status-display",children:e.jsxs("div",{className:"pm2-status-row",children:[e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"PID"}),e.jsx("span",{className:"pm2-metric-value",children:t.pm2Status.pid||"-"})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"CPU"}),e.jsxs("span",{className:"pm2-metric-value",children:[((N=t.pm2Status.cpu)==null?void 0:N.toFixed(1))||"0","%"]})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"MEM"}),e.jsx("span",{className:"pm2-metric-value",children:Ve(t.pm2Status.memory||0)})]}),e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"Restarts"}),e.jsx("span",{className:"pm2-metric-value",children:t.pm2Status.restarts||0})]}),t.pm2Status.uptime&&e.jsxs("span",{className:"pm2-metric",children:[e.jsx("span",{className:"pm2-metric-label",children:"Uptime"}),e.jsx("span",{className:"pm2-metric-value",children:da(t.pm2Status.uptime)})]})]})}),a&&e.jsxs("div",{className:"pm2-actions",children:[e.jsx("button",{type:"button",className:"btn btn-sm btn-success",onClick:()=>r("start"),children:i("common:buttons.start")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>r("stop"),children:i("common:buttons.stop")}),e.jsx("button",{type:"button",className:"btn btn-sm btn-warning",onClick:()=>r("restart"),children:i("terminal:buildingAction.restart")}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>r("logs"),children:i("terminal:logs.title")})]})]}):null}function xa({dockerMode:o,setDockerMode:p,dockerImage:u,setDockerImage:x,dockerContainerName:n,setDockerContainerName:y,dockerCommand:C,setDockerCommand:g,dockerPorts:v,setDockerPorts:s,dockerVolumes:h,setDockerVolumes:a,dockerNetwork:t,setDockerNetwork:r,dockerRestart:i,setDockerRestart:N,dockerPull:b,setDockerPull:L,dockerEnv:T,setDockerEnv:A,dockerComposePath:K,setDockerComposePath:R,dockerComposeProject:$,setDockerComposeProject:I,dockerComposeServices:H,setDockerComposeServices:O,selectedExistingContainer:c,setSelectedExistingContainer:E,dockerContainersList:q,isEditMode:V,building:k,handleCommand:_}){const{t:M}=B(["config","common"]);return e.jsxs("div",{className:"form-section docker-config-section",children:[e.jsx("label",{className:"form-label",children:M("config:buildings.dockerConfig")}),e.jsxs("div",{className:"docker-mode-selector",children:[e.jsxs("label",{className:`docker-mode-option ${o==="container"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"container",checked:o==="container",onChange:()=>p("container")}),e.jsx("span",{className:"docker-mode-icon",children:"📦"}),e.jsx("span",{className:"docker-mode-label",children:"Container"}),e.jsx("span",{className:"docker-mode-desc",children:"Create a new container"})]}),e.jsxs("label",{className:`docker-mode-option ${o==="compose"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"compose",checked:o==="compose",onChange:()=>p("compose")}),e.jsx("span",{className:"docker-mode-icon",children:"🛠"}),e.jsx("span",{className:"docker-mode-label",children:"Compose"}),e.jsx("span",{className:"docker-mode-desc",children:"Manage multiple services"})]}),e.jsxs("label",{className:`docker-mode-option ${o==="existing"?"active":""}`,children:[e.jsx("input",{type:"radio",name:"dockerMode",value:"existing",checked:o==="existing",onChange:()=>p("existing")}),e.jsx("span",{className:"docker-mode-icon",children:"🔎"}),e.jsx("span",{className:"docker-mode-label",children:"Existing"}),e.jsx("span",{className:"docker-mode-desc",children:"Adopt existing container"})]})]}),o==="container"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Image:",e.jsx(j,{text:"Docker image to run, e.g., nginx:latest, redis:alpine, my-app:v1",title:"Image",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:u,onChange:l=>x(l.target.value),placeholder:"nginx:latest",required:!0})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Container Name:",e.jsx(j,{text:"Custom name for the container. If empty, auto-generated based on building name.",title:"Container Name",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:n,onChange:l=>y(l.target.value),placeholder:"Auto-generated (tc-{name}-{id})"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Command:",e.jsx(j,{text:"Override the default container command. Leave empty to use image's CMD.",title:"Command Override",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:C,onChange:l=>g(l.target.value),placeholder:"Optional command override"})]}),e.jsxs("div",{className:"form-section docker-ports-section",children:[e.jsxs("label",{className:"form-label",children:["Port Mappings",e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>s([...v,""]),children:"+ Add"})]}),v.map((l,S)=>e.jsxs("div",{className:"docker-mapping-row",children:[e.jsx("input",{type:"text",className:"form-input",value:l,onChange:U=>{const z=[...v];z[S]=U.target.value,s(z)},placeholder:"8080:80 or 3000"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>s(v.filter((U,z)=>z!==S)),children:"x"})]},S)),v.length===0&&e.jsx("div",{className:"form-hint",children:"Format: host:container (e.g., 8080:80) or same port (e.g., 3000)"})]}),e.jsxs("div",{className:"form-section docker-volumes-section",children:[e.jsxs("label",{className:"form-label",children:["Volume Mounts",e.jsx("button",{type:"button",className:"btn btn-sm btn-add",onClick:()=>a([...h,""]),children:"+ Add"})]}),h.map((l,S)=>e.jsxs("div",{className:"docker-mapping-row",children:[e.jsx("input",{type:"text",className:"form-input",value:l,onChange:U=>{const z=[...h];z[S]=U.target.value,a(z)},placeholder:"./data:/app/data or /host/path:/container/path"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-danger",onClick:()=>a(h.filter((U,z)=>z!==S)),children:"x"})]},S)),h.length===0&&e.jsx("div",{className:"form-hint",children:"Format: host_path:container_path (relative paths resolved from working directory)"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Network:",e.jsx(j,{text:"Docker network to connect to. Leave empty for default bridge network.",title:"Network",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:t,onChange:l=>r(l.target.value),placeholder:"bridge (default)"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Restart Policy:",e.jsx(j,{text:"When should Docker restart the container automatically?",title:"Restart Policy",position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:i,onChange:l=>N(l.target.value),children:Object.keys(Fs).map(l=>e.jsx("option",{value:l,children:Fs[l].label},l))})]})]}),o==="compose"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Compose File:",e.jsx(j,{text:"Path to docker-compose.yml file, relative to working directory.",title:"Compose File",position:"top",size:"sm"})]}),e.jsx(Ue,{value:K,onChange:R,placeholder:"docker-compose.yml",className:"form-input",directoriesOnly:!1})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Project Name:",e.jsx(j,{text:"Override the compose project name. Leave empty for auto-generated name.",title:"Project Name",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:$,onChange:l=>I(l.target.value),placeholder:"Auto-generated"})]}),e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Services:",e.jsx(j,{text:"Specific services to manage (comma-separated). Leave empty for all services.",title:"Services",position:"top",size:"sm"})]}),e.jsx("input",{type:"text",className:"form-input",value:H,onChange:l=>O(l.target.value),placeholder:"All services (or: api, db, redis)"})]})]}),o==="existing"&&e.jsxs("div",{className:"docker-existing-section",children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Select Container:",e.jsx(j,{text:"Choose an existing Docker container to monitor and control. The container will not be deleted when removing the building.",title:"Existing Container",position:"top",size:"sm"})]}),e.jsxs("div",{className:"docker-existing-select-wrapper",children:[e.jsxs("select",{className:"form-input form-select",value:c,onChange:l=>E(l.target.value),required:o==="existing",children:[e.jsx("option",{value:"",children:"Select a container..."}),q.map(l=>e.jsxs("option",{value:l.name,children:[l.name," (",l.image,") - ",l.state]},l.id))]}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>D.requestDockerContainersList(),title:"Refresh container list",children:"↻"})]})]}),q.length===0&&e.jsx("div",{className:"form-hint docker-existing-hint",children:"No containers found. Make sure Docker is running and you have containers available."}),c&&e.jsx("div",{className:"docker-existing-info",children:(()=>{const l=q.find(S=>S.name===c);return l?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Image:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.image})]}),e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Status:"}),e.jsx("span",{className:`docker-existing-info-value docker-status-${l.status}`,children:l.state})]}),e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"ID:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.id.slice(0,12)})]}),l.ports.length>0&&e.jsxs("div",{className:"docker-existing-info-row",children:[e.jsx("span",{className:"docker-existing-info-label",children:"Ports:"}),e.jsx("span",{className:"docker-existing-info-value",children:l.ports.map(S=>`${S.host}:${S.container}/${S.protocol}`).join(", ")})]})]}):null})()}),e.jsx("div",{className:"form-hint",children:"Note: Existing containers will not be deleted when you remove this building."})]}),o!=="existing"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"command-row",children:[e.jsxs("span",{className:"command-label",children:["Pull Policy:",e.jsx(j,{text:"When to pull images: always, only if missing, or never.",title:"Pull Policy",position:"top",size:"sm"})]}),e.jsx("select",{className:"form-input form-select",value:b,onChange:l=>L(l.target.value),children:Object.keys(Ks).map(l=>e.jsx("option",{value:l,children:Ks[l].label},l))})]}),e.jsxs("div",{className:"command-row env-row",children:[e.jsxs("span",{className:"command-label",children:["Environment:",e.jsx(j,{text:"Environment variables in KEY=value format, one per line.",title:"Environment Variables",position:"top",size:"sm"})]}),e.jsx("textarea",{className:"form-input form-textarea",value:T,onChange:l=>A(l.target.value),placeholder:`KEY=value
|
|
4
4
|
DATABASE_URL=postgres://...
|