tide-commander 1.74.0 → 1.75.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/assets/{BossLogsModal-XZupQ15_.js → BossLogsModal-zgU4bJCC.js} +1 -1
  2. package/dist/assets/{BossSpawnModal-BkggsiGJ.js → BossSpawnModal-CpIKJJg-.js} +1 -1
  3. package/dist/assets/ControlsModal-DtgIcdVS.js +1 -0
  4. package/dist/assets/{DockerLogsModal-YHRrsjQp.js → DockerLogsModal-D_L7V-4J.js} +1 -1
  5. package/dist/assets/{EmbeddedEditor-BSRJDqGd.js → EmbeddedEditor-Dp-ni_0-.js} +1 -1
  6. package/dist/assets/{GmailOAuthSetup-2Ppyuv5K.js → GmailOAuthSetup-ChNYMY0L.js} +1 -1
  7. package/dist/assets/{GoogleOAuthSetup-gENk0zRj.js → GoogleOAuthSetup-D8Svmp1q.js} +1 -1
  8. package/dist/assets/{IframeModal-_fp3neFL.js → IframeModal-DZKuQ8yg.js} +1 -1
  9. package/dist/assets/{IntegrationsPanel-B89N7AAS.js → IntegrationsPanel-D6n9toD7.js} +2 -2
  10. package/dist/assets/{LogViewerModal-DuGXmrPm.js → LogViewerModal-D39zaEBu.js} +1 -1
  11. package/dist/assets/{MonitoringModal-D9PPfBx9.js → MonitoringModal--xeaRySJ.js} +1 -1
  12. package/dist/assets/{PM2LogsModal-r8jxzq2F.js → PM2LogsModal-DCMfD-1P.js} +1 -1
  13. package/dist/assets/{RestoreArchivedAreaModal-BzAJjHn6.js → RestoreArchivedAreaModal-PXDQ5bgM.js} +1 -1
  14. package/dist/assets/{Scene2DCanvas-CLn_E93K.js → Scene2DCanvas-DI6ma9Bq.js} +1 -1
  15. package/dist/assets/{SceneManager--vMpx8gM.js → SceneManager-BC5pQh74.js} +1 -1
  16. package/dist/assets/SkillsPanel-DW0Hg7aS.js +28 -0
  17. package/dist/assets/{SpawnModal-Ca4C2H3v.js → SpawnModal-qTu1uEr_.js} +1 -1
  18. package/dist/assets/{SubordinateAssignmentModal-DVbBhkFt.js → SubordinateAssignmentModal--nlGf-YQ.js} +1 -1
  19. package/dist/assets/{TriggerManagerPanel-DNsMPzBx.js → TriggerManagerPanel-CxC7fKWg.js} +2 -2
  20. package/dist/assets/{WorkflowEditorPanel-BEae9pPl.js → WorkflowEditorPanel-BZdJ-r-o.js} +1 -1
  21. package/dist/assets/{index-Ulo84ewo.js → index-B2lMVBaQ.js} +1 -1
  22. package/dist/assets/index-BJGkjKD9.js +2 -0
  23. package/dist/assets/{index-BinaXrmY.js → index-CApTVPt4.js} +4 -4
  24. package/dist/assets/index-CKChsLUr.js +1 -0
  25. package/dist/assets/{index-CDGC6iEM.js → index-Cj5PMAWN.js} +1 -1
  26. package/dist/assets/index-CmgyNPZ8.js +1 -0
  27. package/dist/assets/{index-Cho7e9wl.js → index-DTmsNGgH.js} +2 -2
  28. package/dist/assets/{index-BtQIlMbZ.js → index-DvodeLUF.js} +3 -3
  29. package/dist/assets/{index-Cpm8pHhE.js → index-z_X_5i8B.js} +5 -5
  30. package/dist/assets/{main-BnUsuS5B.js → main-BjcLCHKw.js} +86 -86
  31. package/dist/assets/main-CVksVK2O.css +1 -0
  32. package/dist/assets/{web-Bz9_47wH.js → web-C7yID6Q0.js} +1 -1
  33. package/dist/assets/{web-CA59D-C5.js → web-iMMHHHFW.js} +1 -1
  34. package/dist/index.html +2 -2
  35. package/dist/locales/en/common.json +4 -1
  36. package/dist/src/packages/server/services/agent-service.js +6 -0
  37. package/dist/src/packages/server/websocket/listeners/runtime-listeners.js +30 -0
  38. package/package.json +1 -1
  39. package/dist/assets/ControlsModal-BACb1yEc.js +0 -1
  40. package/dist/assets/SkillsPanel-qhKWxfpL.js +0 -28
  41. package/dist/assets/index-G2EIaT8y.js +0 -1
  42. package/dist/assets/index-WfwvOPbk.js +0 -1
  43. package/dist/assets/index-rKeTU0Q2.js +0 -2
  44. package/dist/assets/main-BCNShZjZ.css +0 -1
@@ -1,5 +1,5 @@
1
- import{b5 as Oe,r as t,s as I,l as ye,b6 as Ee,aA as _e,j as e,I as z,u as fe,b7 as ze,b8 as Te,b9 as Be,ba as Ue,m as Ke,bb as We,bc as De,bd as Ve,X as Ge,Y as qe,be as Ye,aJ as Je,C as Me,S as ce,aD as Xe,az as Qe,P as Ze,E as Ie,a7 as et,M as tt,bf as st,n as X,bg as nt}from"./main-BnUsuS5B.js";import{F as at}from"./index-BtQIlMbZ.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,ct={idle:"#4aff9e",working:"#4a9eff",waiting:"#ff9e4a",waiting_permission:"#ffcc00",error:"#ff4a4a",offline:"#888888",orphaned:"#ff9e4a"},ot=12e4;function rt(n){return n.trim().replace(/\r\n/g,`
2
- `)}function $e(n,a){return`${n}:${rt(a)}`}function it(n,a,l,f){if(n.uuid&&a.has(n.uuid))return!1;const p=n.isUserPrompt?"user":"assistant",d=$e(p,n.text),M=n.timestamp||0,A=l.get(d);return A!==void 0&&Math.abs(M-A)<=ot?!1:M>f}function dt({isOpen:n,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(()=>{n||(d.current.clear(),p(new Map))},[n]),t.useEffect(()=>{if(!n)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 o=$e(w.type,w.content),L=w.timestamp?new Date(w.timestamp).getTime():0,K=V.get(o)??0;L>K&&V.set(o,L)}const G=I.getOutputs(i.id),U=(C&&C.length>0?[...C,...G]:G).filter(w=>it(w,Y,V,W));I.clearOutputs(i.id);for(const w of U)I.addOutput(i.id,w);p(w=>{const o=new Map(w);return o.set(i.id,{agentId:i.id,messages:P,loading:!1,hasMore:k.hasMore||!1,totalCount:k.totalCount||0}),o})}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)}},[n,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:n,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 o=i.current;o.focus(),o.selectionStart=o.selectionEnd=o.value.length}C.current=l},[l]),t.useEffect(()=>{const o=i.current;if(!o||!l)return;o.style.height="auto";const L=v?120:180,K=Math.min(o.scrollHeight,L);o.style.height=`${K}px`},[n,l,v]);const F=t.useCallback(async o=>{const L=o.clipboardData.items;for(const _ of L)if(_.type.startsWith("image/")){o.preventDefault();const $=_.getAsFile();if($){const H=await b($);H&&R(H)}return}const K=o.clipboardData.files;if(K.length>0){o.preventDefault();for(const _ of K){const $=await b(_);$&&R($)}return}const B=o.clipboardData.getData("text"),te=(B.match(/\n/g)||[]).length+1;if(te>5){o.preventDefault();const $=`[Pasted text #${E(B)} +${te} lines]`,H=o.target,se=H.selectionStart||0,ae=H.selectionEnd||0,ne=n.slice(0,se)+$+n.slice(ae);a(ne),l||p(!0)}},[n,a,l,p,b,R,E]),x=t.useCallback(async o=>{const L=o.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(o=>{if(o.key==="Enter"&&o.shiftKey){l||(o.preventDefault(),p(!0));return}o.key==="Enter"&&(o.preventDefault(),d())},[l,p,d]),P=t.useCallback(o=>{},[]),W=t.useCallback(o=>{o.button===1&&(o.preventDefault(),o.stopPropagation())},[]),Y=t.useCallback(o=>{i.current=o,u==null||u(o)},[u]),V=v?"agent-panel-input":"guake-input",G=v?"agent-panel-input-container":"guake-input-container",Q=v?"agent-panel-attach-btn":"guake-attach-btn",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(o=>e.jsxs("div",{className:`${v?"agent-panel-attachment":"guake-attachment"} ${o.isImage?"is-image":""}`,children:[e.jsx("span",{className:v?"agent-panel-attachment-icon":"guake-attachment-icon",children:e.jsx(z,{name:o.isImage?"file":"paperclip",size:12})}),e.jsx("span",{className:v?"agent-panel-attachment-name":"guake-attachment-name",title:o.path,children:o.name}),!v&&e.jsxs("span",{className:"guake-attachment-size",children:["(",Math.round(o.size/1024),"KB)"]}),e.jsx("button",{className:v?"agent-panel-attachment-remove":"guake-attachment-remove",onClick:()=>N(o.id),title:"Remove",children:"×"})]},o.id))}),e.jsxs("div",{className:`${V} ${w} ${h}`,children:[e.jsx("input",{ref:D,type:"file",multiple:!0,onChange:x,style:{display:"none"},accept:"*"}),e.jsxs("div",{className:G,onAuxClick:W,children:[e.jsx("button",{className:Q,onClick:()=>{var o;return(o=D.current)==null?void 0:o.click()},title:"Attach file (or paste image)",children:e.jsx(z,{name:"paperclip",size:14})}),l?e.jsx("textarea",{ref:Y,placeholder:j,value:n,onChange:o=>a(o.target.value),onKeyDown:k,onPaste:F,onMouseDown:P}):e.jsx("input",{ref:u,type:"text",placeholder:j,value:n,onChange:o=>a(o.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(n){const a=Math.floor(n/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:n,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(n.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),[G,Q]=t.useState(null);Te(`commander-image-modal-${n.id}`,P!==null,()=>W(null));const{command:U,setCommand:w,forceTextarea:o,setForceTextarea:L,useTextarea:K,setPastedTexts:B,incrementPastedCount:te,resetPastedCount:_,attachedFiles:$,setAttachedFiles:H,removeAttachedFile:se,uploadFile:ae,expandPastedTexts:ne}=Be({selectedAgentId:n.id}),le=U.trim().length>0||$.length>0,s=Ue({outputs:l,viewMode:d?"advanced":"simple"}),c=t.useMemo(()=>{const S=Ke(n);return{usedPercent:S.usedPercent,freePercent:S.freePercent,hasData:!!n.contextStats,totalTokens:S.totalTokens,contextWindow:S.contextWindow}},[n.contextStats,n.contextUsed,n.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)},[s.length]);const q=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(n.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
- `);S=S?`${S}
1
+ import{b6 as Oe,r as t,s as I,l as ye,b7 as Ee,aB as _e,j as e,I as z,u as fe,b8 as ze,b9 as Te,ba as Be,bb as Ue,m as Ke,bc as We,bd as De,be as Ve,Y as Ge,Z as qe,bf as Ye,aK as Je,E as Me,S as ce,aE as Xe,aA as Ze,U as Qe,G as Ie,a8 as et,N as tt,bg as st,n as X,bh as nt}from"./main-BjcLCHKw.js";import{F as at}from"./index-DvodeLUF.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Se={status:"all",activity:"all",sort:"activity"},lt={"1h":3600*1e3,"6h":360*60*1e3,"24h":1440*60*1e3},Ae=20,me=3,ct={idle:"#4aff9e",working:"#4a9eff",waiting:"#ff9e4a",waiting_permission:"#ffcc00",error:"#ff4a4a",offline:"#888888",orphaned:"#ff9e4a"},ot=12e4;function rt(n){return n.trim().replace(/\r\n/g,`
2
+ `)}function $e(n,a){return`${n}:${rt(a)}`}function it(n,a,l,f){if(n.uuid&&a.has(n.uuid))return!1;const p=n.isUserPrompt?"user":"assistant",d=$e(p,n.text),M=n.timestamp||0,A=l.get(d);return A!==void 0&&Math.abs(M-A)<=ot?!1:M>f}function dt({isOpen:n,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(()=>{n||(d.current.clear(),p(new Map))},[n]),t.useEffect(()=>{if(!n)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 o=$e(w.type,w.content),L=w.timestamp?new Date(w.timestamp).getTime():0,K=V.get(o)??0;L>K&&V.set(o,L)}const G=I.getOutputs(i.id),U=(C&&C.length>0?[...C,...G]:G).filter(w=>it(w,Y,V,W));I.clearOutputs(i.id);for(const w of U)I.addOutput(i.id,w);p(w=>{const o=new Map(w);return o.set(i.id,{agentId:i.id,messages:P,loading:!1,hasMore:k.hasMore||!1,totalCount:k.totalCount||0}),o})}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)}},[n,M,A,l]);const R=t.useRef(a),S=t.useRef(f);R.current=a,S.current=f;const b=t.useCallback(async j=>{const h=R.current.get(j),v=S.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:n,onCommandChange:a,useTextarea:l,forceTextarea:f,onForceTextarea:p,onSend:d,canSend:M,attachedFiles:A,onAddFile:R,onRemoveFile:S,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 o=i.current;o.focus(),o.selectionStart=o.selectionEnd=o.value.length}C.current=l},[l]),t.useEffect(()=>{const o=i.current;if(!o||!l)return;o.style.height="auto";const L=v?120:180,K=Math.min(o.scrollHeight,L);o.style.height=`${K}px`},[n,l,v]);const F=t.useCallback(async o=>{const L=o.clipboardData.items;for(const _ of L)if(_.type.startsWith("image/")){o.preventDefault();const $=_.getAsFile();if($){const H=await b($);H&&R(H)}return}const K=o.clipboardData.files;if(K.length>0){o.preventDefault();for(const _ of K){const $=await b(_);$&&R($)}return}const B=o.clipboardData.getData("text"),te=(B.match(/\n/g)||[]).length+1;if(te>5){o.preventDefault();const $=`[Pasted text #${E(B)} +${te} lines]`,H=o.target,se=H.selectionStart||0,ae=H.selectionEnd||0,ne=n.slice(0,se)+$+n.slice(ae);a(ne),l||p(!0)}},[n,a,l,p,b,R,E]),x=t.useCallback(async o=>{const L=o.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(o=>{if(o.key==="Enter"&&o.shiftKey){l||(o.preventDefault(),p(!0));return}o.key==="Enter"&&(o.preventDefault(),d())},[l,p,d]),P=t.useCallback(o=>{},[]),W=t.useCallback(o=>{o.button===1&&(o.preventDefault(),o.stopPropagation())},[]),Y=t.useCallback(o=>{i.current=o,u==null||u(o)},[u]),V=v?"agent-panel-input":"guake-input",G=v?"agent-panel-input-container":"guake-input-container",Z=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(o=>e.jsxs("div",{className:`${v?"agent-panel-attachment":"guake-attachment"} ${o.isImage?"is-image":""}`,children:[e.jsx("span",{className:v?"agent-panel-attachment-icon":"guake-attachment-icon",children:e.jsx(z,{name:o.isImage?"file":"paperclip",size:12})}),e.jsx("span",{className:v?"agent-panel-attachment-name":"guake-attachment-name",title:o.path,children:o.name}),!v&&e.jsxs("span",{className:"guake-attachment-size",children:["(",Math.round(o.size/1024),"KB)"]}),e.jsx("button",{className:v?"agent-panel-attachment-remove":"guake-attachment-remove",onClick:()=>S(o.id),title:"Remove",children:"×"})]},o.id))}),e.jsxs("div",{className:`${V} ${w} ${h}`,children:[e.jsx("input",{ref:D,type:"file",multiple:!0,onChange:x,style:{display:"none"},accept:"*"}),e.jsxs("div",{className:G,onAuxClick:W,children:[e.jsx("button",{className:Z,onClick:()=>{var o;return(o=D.current)==null?void 0:o.click()},title:"Attach file (or paste image)",children:e.jsx(z,{name:"paperclip",size:14})}),l?e.jsx("textarea",{ref:Y,placeholder:j,value:n,onChange:o=>a(o.target.value),onKeyDown:k,onPaste:F,onMouseDown:P}):e.jsx("input",{ref:u,type:"text",placeholder:j,value:n,onChange:o=>a(o.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(n){const a=Math.floor(n/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:n,history:a,outputs:l,isExpanded:f,isFocused:p,advancedView:d,onExpand:M,onFocus:A,inputRef:R,onLoadMore:S,onClearHistory:b}){const{t:E}=fe(["terminal","common"]),j=ze(n.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),[G,Z]=t.useState(null);Te(`commander-image-modal-${n.id}`,P!==null,()=>W(null));const{command:U,setCommand:w,forceTextarea:o,setForceTextarea:L,useTextarea:K,setPastedTexts:B,incrementPastedCount:te,resetPastedCount:_,attachedFiles:$,setAttachedFiles:H,removeAttachedFile:se,uploadFile:ae,expandPastedTexts:ne}=Be({selectedAgentId:n.id}),le=U.trim().length>0||$.length>0,s=Ue({outputs:l,viewMode:d?"advanced":"simple"}),c=t.useMemo(()=>{const N=Ke(n);return{usedPercent:N.usedPercent,freePercent:N.freePercent,hasData:!!n.contextStats,totalTokens:N.totalTokens,contextWindow:N.contextWindow}},[n.contextStats,n.contextUsed,n.contextLimit]),g=t.useCallback(()=>{!v&&(a!=null&&a.hasMore)&&S&&(u(!0),D.current=h.current?h.current.scrollHeight-h.current.scrollTop:0,S())},[v,a==null?void 0:a.hasMore,S]);t.useEffect(()=>{v&&a&&!a.loading&&u(!1)},[a,v]);const m=t.useCallback(()=>{i.current=!0,F(!1)},[]),T=t.useRef(f),Q=t.useRef(p);t.useEffect(()=>{(f&&!T.current||p&&!Q.current)&&(i.current=!1,F(!0),k(!0)),T.current=f,Q.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 N=h.current;if(!N)return;const y=performance.now();let O=0,ue=-1,ke;const Re=()=>{const{scrollTop:Fe,scrollHeight:Ne,clientHeight:Le}=N,He=Ne-Fe-Le<=2;if(Math.abs(Ne-ue)<=1&&He?O+=1:O=0,ue=Ne,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)},[s.length]);const q=t.useCallback(()=>!1,[]),ie=t.useCallback(N=>{const y=te();return B(O=>new Map(O).set(y,N)),y},[te,B]),he=t.useCallback(N=>{H(y=>[...y,N])},[H]),xe=t.useCallback(()=>{if(!le)return;if(U.trim()==="/clear"&&$.length===0){I.clearContext(n.id),b(),w(""),L(!1),B(new Map),H([]),_();return}let N=ne(U.trim());if($.length>0){const y=$.map(O=>O.isImage?`[Image: ${O.path}]`:`[File: ${O.path}]`).join(`
3
+ `);N=N?`${N}
4
4
 
5
- ${y}`:y}I.sendCommand(n.id,S),w(""),L(!1),B(new Map),H([]),_()},[n.id,U,le,$,ne,b,_,w,L,B,H]),ge=t.useCallback((S,y)=>{W({url:S,name:y})},[]),ve=t.useCallback((S,y)=>{const O=We(S,n.cwd),ue=O.line?{...y||{},targetLine:O.line}:y;I.setFileViewerPath(O.path,ue,n.cwd)},[n.cwd]),je=t.useCallback((S,y)=>{V({command:S,output:y,isLive:y==="Running..."})},[]),we=t.useCallback(S=>{Q(S)},[]),Ce=t.useCallback(()=>{k(!1),i.current=!0,F(!1)},[]),be=t.useCallback(()=>W(null),[]),r=t.useCallback(()=>V(null),[]),J=t.useCallback(()=>Q(null),[]),de=t.useCallback(S=>{S.stopPropagation(),M()},[M]),oe=ct[n.status]||"#888888",re=(a==null?void 0:a.messages)||[];return e.jsxs("div",{className:`agent-panel ${n.status==="working"?"working":""} ${f?"expanded":""} ${p?"focused":""}`,onClick:p?void 0:A,children:[e.jsxs("div",{className:"agent-panel-header",onClick:p?A:void 0,children:[e.jsxs("div",{className:"agent-panel-info",children:[e.jsx("span",{className:"agent-panel-status",style:{background:oe},title:n.status}),e.jsxs("span",{className:"agent-panel-name",children:[(n.isBoss||n.class==="boss")&&e.jsx("span",{className:"agent-panel-boss-crown",children:e.jsx(z,{name:"crown",size:14})}),n.name]}),e.jsx("span",{className:`agent-panel-status-label ${n.status}`,children:n.status}),e.jsx("span",{className:"agent-panel-class",children:n.class}),e.jsx("span",{className:`agent-panel-provider ${n.provider==="codex"?"codex":n.provider==="opencode"?"opencode":"claude"}`,children:n.provider||"claude"}),e.jsxs("span",{className:"agent-panel-id",title:`ID: ${n.id}`,children:["[",n.id.substring(0,4),"]"]}),n.taskLabel?e.jsxs("div",{className:"agent-panel-task agent-panel-task-label",title:n.taskLabel,children:[e.jsx(z,{name:"task",size:12})," ",n.taskLabel]}):n.currentTask?e.jsxs("div",{className:"agent-panel-task",title:n.currentTask,children:[n.currentTask.substring(0,40),"..."]}):null]}),e.jsxs("div",{className:"agent-panel-context",title:`Context: ${Math.round(c.usedPercent)}% used (${De(c.totalTokens)} / ${De(c.contextWindow)})`,children:[e.jsx("div",{className:"agent-panel-context-bar",style:{background:c.freePercent<20?"#ff4a4a":c.freePercent<50?"#ff9e4a":"#4aff9e",width:`${c.freePercent}%`}}),e.jsxs("span",{className:"agent-panel-context-text",children:[Math.round(c.freePercent),"%"]})]}),e.jsx("div",{className:"agent-panel-actions",children:e.jsx("button",{className:"agent-panel-expand",onClick:de,title:E(f?"commander.collapsePanel":"commander.expandPanel"),children:f?e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("polyline",{points:"4 14 10 14 10 20"}),e.jsx("polyline",{points:"20 10 14 10 14 4"}),e.jsx("line",{x1:"14",y1:"10",x2:"21",y2:"3"}),e.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]}):e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("polyline",{points:"15 3 21 3 21 9"}),e.jsx("polyline",{points:"9 21 3 21 3 15"}),e.jsx("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),e.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})})})]}),e.jsx("div",{className:"agent-panel-content",ref:h,children:a!=null&&a.loading?e.jsx("div",{className:"agent-panel-loading",children:E("common:status.loading")}):e.jsx(e.Fragment,{children:!re.length&&!s.length?e.jsxs("div",{className:"agent-panel-empty",children:[E("commander.noMessages"),!n.sessionId&&e.jsx("div",{style:{fontSize:"10px",color:"#666"},children:E("commander.noSessionId")})]}):e.jsx(Ve,{historyMessages:re,liveOutputs:s,agentId:n.id,viewMode:d?"advanced":"simple",selectedMessageIndex:null,isMessageSelected:q,onImageClick:ge,onFileClick:ve,onBashClick:je,onViewMarkdown:we,scrollContainerRef:h,onScrollTopReached:g,isLoadingMore:v,hasMore:a==null?void 0:a.hasMore,shouldAutoScroll:C,onUserScroll:m,pinToBottom:x,onPinCancel:Ce,isLoadingHistory:a==null?void 0:a.loading})})}),e.jsxs("div",{className:`guake-input-wrapper ${n.status==="working"?"has-stop-btn is-working":""}`,children:[e.jsx(ft,{agentId:n.id,isWorking:n.status==="working",timestamp:j==null?void 0:j.timestamp}),e.jsx(ut,{command:U,onCommandChange:w,useTextarea:K,forceTextarea:o,onForceTextarea:L,onSend:xe,canSend:le,attachedFiles:$,onAddFile:he,onRemoveFile:se,uploadFile:ae,onAddPastedText:ie,placeholder:E("commander.command",{name:n.name}),compact:!1,inputRef:R})]}),P&&e.jsx(Ge,{url:P.url,name:P.name,onClose:be}),Y&&e.jsx(qe,{state:Y,onClose:r}),e.jsx(Ye,{agent:n,content:G,onClose:J})]})}function ht({currentArea:n,onClose:a}){const{t:l}=fe(["terminal","common"]),[f,p]=t.useState(()=>{const u=new Set(Array.from(I.getState().agents.values()).map(D=>D.name));return Je.find(D=>!u.has(D))||`Agent-${Date.now().toString(36)}`}),[d,M]=t.useState(()=>Me(ce.LAST_CWD)),[A,R]=t.useState("scout"),[N,b]=t.useState("claude"),[E,j]=t.useState(!1),h=()=>{if(!f.trim()||!d.trim())return;j(!0),Ie(ce.LAST_CWD,d);let u;n&&(u={x:n.center.x,z:n.center.z}),I.spawnAgent(f.trim(),A,d.trim(),u,void 0,void 0,void 0,void 0,N),setTimeout(()=>{a()},500)},v=u=>{u.key==="Enter"&&!u.shiftKey&&(u.preventDefault(),h()),u.key==="Escape"&&a()};return e.jsx("div",{className:"commander-spawn-overlay",onClick:a,children:e.jsxs("div",{className:"commander-spawn-form",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"commander-spawn-header",children:[e.jsx("h3",{children:l("spawn.addNewAgent")}),n&&e.jsxs("span",{className:"commander-spawn-area",children:[e.jsx("span",{className:"commander-spawn-area-dot",style:{background:n.color}}),n.name]})]}),e.jsxs("div",{className:"commander-spawn-body",children:[e.jsxs("div",{className:"commander-spawn-field",children:[e.jsx("label",{children:l("common:labels.name")}),e.jsx("input",{type:"text",value:f,onChange:u=>p(u.target.value),onKeyDown:v,autoFocus:!0})]}),e.jsxs("div",{className:"commander-spawn-field",children:[e.jsx("label",{children:l("common:labels.workingDirectory")}),e.jsx(Xe,{value:d,onChange:M,onSubmit:h,placeholder:l("spawn.workingDirPlaceholder"),directoriesOnly:!0})]}),e.jsxs("div",{className:"commander-spawn-field",children:[e.jsx("label",{children:l("common:labels.class")}),e.jsx("div",{className:"commander-spawn-classes",children:Qe.map(u=>e.jsxs("button",{className:`commander-spawn-class ${A===u.id?"selected":""}`,onClick:()=>R(u.id),children:[e.jsx(Ze,{classId:u.id,size:18,className:"commander-spawn-class-icon"}),e.jsx("span",{children:u.name})]},u.id))})]}),e.jsxs("div",{className:"commander-spawn-field",children:[e.jsx("label",{children:l("common:labels.runtime")}),e.jsxs("div",{className:"commander-spawn-classes",children:[e.jsxs("button",{className:`commander-spawn-class ${N==="claude"?"selected":""}`,onClick:()=>b("claude"),children:[e.jsx("span",{className:"commander-spawn-class-icon",children:e.jsx(z,{name:"brain",size:14})}),e.jsx("span",{children:"Claude"})]}),e.jsxs("button",{className:`commander-spawn-class ${N==="codex"?"selected":""}`,onClick:()=>b("codex"),children:[e.jsx("span",{className:"commander-spawn-class-icon",children:e.jsx(z,{name:"gear",size:14})}),e.jsx("span",{children:"Codex"})]}),e.jsxs("button",{className:`commander-spawn-class ${N==="opencode"?"selected":""}`,onClick:()=>b("opencode"),children:[e.jsx("span",{className:"commander-spawn-class-icon",children:e.jsx(z,{name:"status-pending",size:12,weight:"fill",color:"#4ade80"})}),e.jsx("span",{children:"OpenCode"})]})]})]})]}),e.jsxs("div",{className:"commander-spawn-footer",children:[e.jsx("button",{className:"commander-spawn-cancel",onClick:a,children:l("common:buttons.cancel")}),e.jsx("button",{className:"commander-spawn-submit",onClick:h,disabled:!f.trim()||!d.trim()||E,children:l(E?"common:buttons.deploying":"common:buttons.deploy")})]})]})})}const Pe=t.memo(function({agent:a,history:l,isExpanded:f,isFocused:p,advancedView:d,index:M,onExpand:A,onCollapse:R,onFocus:N,onInputRef:b,onLoadMore:E,onClearHistory:j}){const h=nt(a.id),v=t.useCallback(()=>{f?R():A(a.id)},[a.id,f,A,R]),u=t.useCallback(()=>{N(p?-1:M)},[M,p,N]),D=t.useCallback(F=>{b(a.id,F)},[a.id,b]),i=t.useCallback(()=>{E(a.id)},[a.id,E]),C=t.useCallback(()=>{j(a.id)},[a.id,j]);return e.jsx(pt,{agent:a,history:l,outputs:h,isExpanded:f,isFocused:p,advancedView:d,onExpand:v,onFocus:u,inputRef:D,onLoadMore:i,onClearHistory:C})});function Ct({isOpen:n,onClose:a}){const{t:l}=fe(["terminal","common"]),f=et(),p=tt(),[d,M]=t.useState(()=>Me(ce.COMMANDER_TAB,"all")),[A,R]=t.useState(0),[N,b]=t.useState(null),E=t.useRef(null),[j,h]=t.useState(0),[v,u]=t.useState(!1),[D,i]=t.useState(null),[C,F]=t.useState(!1),[x,k]=t.useState(()=>{try{const s=Me(ce.COMMANDER_FILTERS,"");if(s)return{...Ne,...JSON.parse(s)}}catch{}return Ne}),P=t.useRef(new Map),W=t.useRef([]),Y=t.useRef(0),V=t.useRef([]),G=t.useRef(d),{histories:Q,loadMoreHistory:U,clearAgentHistory:w}=dt({isOpen:n,agents:f});t.useEffect(()=>{n||(b(null),h(0),u(!1))},[n]);const o=t.useMemo(()=>{const s=Array.from(p.values()).sort((g,m)=>g.name.localeCompare(m.name)),c=[{id:"all",name:l("common:labels.all")}];for(const g of s)c.push({id:g.id,name:g.name,color:g.color});return c.push({id:"unassigned",name:l("commander.unassigned")}),c},[p]),L=t.useMemo(()=>d==="all"||d==="unassigned"?null:p.get(d)||null,[d,p]),K=t.useMemo(()=>{const s=new Map;s.set("all",f.size);let c=0;for(const g of f.values()){const m=I.getAreaForAgent(g.id);m?s.set(m.id,(s.get(m.id)||0)+1):c++}return s.set("unassigned",c),s},[f]),B=x.status!=="all"||x.activity!=="all"||x.sort!=="activity",te=(x.status!=="all"?1:0)+(x.activity!=="all"?1:0)+(x.sort!=="activity"?1:0),_=t.useMemo(()=>{const s=m=>m.isBoss===!0||m.class==="boss",c=Date.now();let g=Array.from(f.values());if(d==="unassigned"?g=g.filter(m=>!I.getAreaForAgent(m.id)):d!=="all"&&(g=g.filter(m=>{const T=I.getAreaForAgent(m.id);return(T==null?void 0:T.id)===d})),x.status!=="all"&&(g=g.filter(m=>{switch(x.status){case"working":return m.status==="working";case"idle":return m.status==="idle";case"error":return m.status==="error"||m.status==="waiting"||m.status==="waiting_permission";case"offline":return m.status==="offline"||m.status==="orphaned";default:return!0}})),x.activity!=="all"){const m=lt[x.activity];g=g.filter(T=>c-(T.lastActivity||0)<m)}return g.sort((m,T)=>{var Z,ee;if(s(m)&&!s(T))return-1;if(!s(m)&&s(T))return 1;switch(x.sort){case"activity":return(T.lastActivity||0)-(m.lastActivity||0);case"name":return m.name.localeCompare(T.name);case"created":return(m.createdAt||0)-(T.createdAt||0);case"context":{const q=((Z=m.contextStats)==null?void 0:Z.usedPercent)??(m.contextUsed||0)/(m.contextLimit||2e5)*100;return(((ee=T.contextStats)==null?void 0:ee.usedPercent)??(T.contextUsed||0)/(T.contextLimit||2e5)*100)-q}default:return(T.lastActivity||0)-(m.lastActivity||0)}}),g},[f,d,x]),$=Math.ceil(_.length/Ae),H=t.useMemo(()=>_.slice(A*Ae,(A+1)*Ae),[_,A]);W.current=H,E.current=N,Y.current=j,V.current=o,G.current=d,Te("commander-expanded",N!==null,()=>b(null));const se=st();t.useEffect(()=>{n&&se&&(b(se),I.clearCommanderExpandRequest())},[n,se]);const ae=t.useCallback(()=>b(null),[]),ne=t.useCallback(s=>b(s),[]),le=t.useCallback(s=>h(s),[]),pe=t.useCallback((s,c)=>{c?P.current.set(s,c):P.current.delete(s)},[]);return t.useEffect(()=>{R(0),Ie(ce.COMMANDER_TAB,d)},[d]),t.useEffect(()=>{Ie(ce.COMMANDER_FILTERS,JSON.stringify(x)),R(0)},[x]),t.useEffect(()=>{var c;if(!n||window.matchMedia("(pointer: coarse)").matches)return;const s=N||((c=W.current[j])==null?void 0:c.id);if(s){const g=P.current.get(s);g&&document.activeElement!==g&&setTimeout(()=>g.focus(),50)}},[n,j,N]),t.useEffect(()=>{if(!n)return;const s=c=>{const g=I.getShortcuts(),m=c.target,T=m.tagName==="INPUT"||m.tagName==="TEXTAREA",Z=W.current,ee=Z.length-1,q=E.current,ie=g.find(r=>r.id==="commander-close");if(X(c,ie)){const{fileViewerPath:r,contextModalAgentId:J}=I.getState();if(r||J)return;c.preventDefault(),c.stopImmediatePropagation(),q?b(null):a();return}const he=g.find(r=>r.id==="commander-vim-left");if(X(c,he)&&!q){c.preventDefault(),h(r=>r>0?r-1:r);return}const xe=g.find(r=>r.id==="commander-vim-right");if(X(c,xe)&&!q){c.preventDefault(),h(r=>r<ee?r+1:r);return}const ge=g.find(r=>r.id==="commander-vim-up");if(X(c,ge)&&!q){c.preventDefault(),h(r=>r>=me?r-me:r);return}const ve=g.find(r=>r.id==="commander-vim-down");if(X(c,ve)&&!q){c.preventDefault(),h(r=>r+me<=ee?r+me:r);return}const je=g.find(r=>r.id==="commander-expand");if(X(c,je)){if(c.preventDefault(),q)b(null);else{const r=Z[Y.current];r&&b(r.id)}return}const we=g.find(r=>r.id==="commander-new-agent");if(X(c,we)){c.preventDefault(),u(!0);return}const Ce=g.find(r=>r.id==="commander-next-tab"),be=g.find(r=>r.id==="commander-prev-tab");if(!T){const r=V.current;if(X(c,Ce)){const J=I.getState().latestNotificationAgentId;if(J){if(c.preventDefault(),c.stopPropagation(),!I.getState().agents.get(J)){I.setLatestNotificationAgentId(null);return}const y=I.getAreaForAgent(J);y&&r.some(O=>O.id===y.id)?M(y.id):M("unassigned"),b(J),h(0),R(0),I.setLatestNotificationAgentId(null);return}c.preventDefault(),c.stopPropagation();const oe=(r.findIndex(re=>re.id===G.current)+1)%r.length;M(r[oe].id),h(0);return}if(X(c,be)){c.preventDefault(),c.stopPropagation();const de=(r.findIndex(oe=>oe.id===G.current)-1+r.length)%r.length;M(r[de].id),h(0);return}}};return document.addEventListener("keydown",s,!0),()=>document.removeEventListener("keydown",s,!0)},[n,a]),n?e.jsx("div",{className:"commander-overlay",onClick:a,children:e.jsxs("div",{className:"commander-view",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"commander-header",children:[e.jsxs("div",{className:"commander-title-section",children:[e.jsx("h2",{className:"commander-title",children:l("commander.title")}),e.jsx("span",{className:"commander-shortcuts",children:l("commander.shortcuts")})]}),e.jsxs("div",{className:"commander-controls",children:[e.jsx("button",{className:`commander-view-toggle ${C?"active":""}`,onClick:()=>F(!C),title:l(C?"commander.simple":"commander.advanced"),children:C?e.jsxs(e.Fragment,{children:[e.jsx(z,{name:"target",size:12})," ",l("commander.advanced")]}):e.jsxs(e.Fragment,{children:[e.jsx(z,{name:"status-pending",size:12})," ",l("commander.simple")]})}),e.jsx("button",{className:"commander-add-btn",onClick:()=>u(!0),title:l("commander.addAgent"),children:l("commander.addAgent")}),e.jsx("button",{className:"commander-close",onClick:a,children:l("commander.close")})]})]}),e.jsx("div",{className:"commander-tabs",children:o.map(s=>{const c=s.id!=="all"&&s.id!=="unassigned"?p.get(s.id):null,g=c&&c.directories&&c.directories.length>0;return e.jsxs("button",{className:`commander-tab ${d===s.id?"active":""}`,onClick:()=>{M(s.id),h(0)},style:s.color?{borderBottomColor:d===s.id?s.color:"transparent"}:void 0,children:[s.color&&e.jsx("span",{className:"commander-tab-dot",style:{background:s.color}}),e.jsx("span",{children:s.name}),e.jsx("span",{className:"commander-tab-count",children:K.get(s.id)||0}),g&&e.jsx("span",{className:"commander-tab-folder",onClick:m=>{m.stopPropagation(),i(s.id)},title:l("commander.openFileExplorer"),children:e.jsx(z,{name:"folder",size:12})})]},s.id)})}),e.jsxs("div",{className:"commander-filters",children:[e.jsxs("div",{className:"commander-filter-group",children:[e.jsx("span",{className:"commander-filter-label",children:l("commander.filters.status")}),["all","working","idle","error","offline"].map(s=>e.jsx("button",{className:`commander-filter-btn ${x.status===s?"active":""}`,onClick:()=>k(c=>({...c,status:s})),children:s==="all"?l("commander.filters.all"):s==="error"?l("commander.filters.needsAttn"):s.charAt(0).toUpperCase()+s.slice(1)},s))]}),e.jsxs("div",{className:"commander-filter-group",children:[e.jsx("span",{className:"commander-filter-label",children:l("commander.filters.active")}),["all","1h","6h","24h"].map(s=>e.jsx("button",{className:`commander-filter-btn ${x.activity===s?"active":""}`,onClick:()=>k(c=>({...c,activity:s})),children:s==="all"?l("commander.filters.any"):`< ${s}`},s))]}),e.jsxs("div",{className:"commander-filter-group",children:[e.jsx("span",{className:"commander-filter-label",children:l("commander.filters.sort")}),["activity","name","created","context"].map(s=>e.jsx("button",{className:`commander-filter-btn ${x.sort===s?"active":""}`,onClick:()=>k(c=>({...c,sort:s})),children:s==="activity"?l("commander.filters.recent"):s==="context"?l("commander.filters.context"):s.charAt(0).toUpperCase()+s.slice(1)},s))]}),B&&e.jsx("button",{className:"commander-filter-clear",onClick:()=>k(Ne),title:l("commander.clearFilters"),children:l("commander.filters.clearFilters",{count:te})})]}),$>1&&e.jsxs("div",{className:"commander-pagination",children:[e.jsxs("button",{className:"commander-page-btn",onClick:()=>R(s=>Math.max(0,s-1)),disabled:A===0,children:[e.jsx(z,{name:"caret-left",size:12})," ",l("commander.prev")]}),e.jsx("span",{className:"commander-page-info",children:l("commander.page",{current:A+1,total:$,count:_.length})}),e.jsxs("button",{className:"commander-page-btn",onClick:()=>R(s=>Math.min($-1,s+1)),disabled:A===$-1,children:[l("commander.next")," ",e.jsx(z,{name:"caret-right",size:12})]})]}),e.jsx("div",{className:`commander-grid ${N?"has-expanded":""}`,"data-agent-count":N?1:H.length,children:H.length===0?e.jsx("div",{className:"commander-empty",children:l(d==="all"?"commander.noAgentsAll":d==="unassigned"?"commander.noAgentsUnassigned":"commander.noAgentsArea")}):N?(()=>{const s=f.get(N);return s?e.jsx(Pe,{agent:s,history:Q.get(s.id),isExpanded:!0,isFocused:!0,advancedView:C,index:0,onExpand:ne,onCollapse:ae,onFocus:le,onInputRef:pe,onLoadMore:U,onClearHistory:w},s.id):null})():H.map((s,c)=>e.jsx(Pe,{agent:s,history:Q.get(s.id),isExpanded:!1,isFocused:c===j,advancedView:C,index:c,onExpand:ne,onCollapse:ae,onFocus:le,onInputRef:pe,onLoadMore:U,onClearHistory:w},s.id))}),v&&e.jsx(ht,{currentArea:L,onClose:()=>u(!1)}),D&&e.jsx(at,{isOpen:!0,areaId:D,onClose:()=>i(null),onChangeArea:s=>i(s)})]})}):null}export{Ct as CommanderView};
5
+ ${y}`:y}I.sendCommand(n.id,N),w(""),L(!1),B(new Map),H([]),_()},[n.id,U,le,$,ne,b,_,w,L,B,H]),ge=t.useCallback((N,y)=>{W({url:N,name:y})},[]),ve=t.useCallback((N,y)=>{const O=We(N,n.cwd),ue=O.line?{...y||{},targetLine:O.line}:y;I.setFileViewerPath(O.path,ue,n.cwd)},[n.cwd]),je=t.useCallback((N,y)=>{V({command:N,output:y,isLive:y==="Running..."})},[]),we=t.useCallback(N=>{Z(N)},[]),Ce=t.useCallback(()=>{k(!1),i.current=!0,F(!1)},[]),be=t.useCallback(()=>W(null),[]),r=t.useCallback(()=>V(null),[]),J=t.useCallback(()=>Z(null),[]),de=t.useCallback(N=>{N.stopPropagation(),M()},[M]),oe=ct[n.status]||"#888888",re=(a==null?void 0:a.messages)||[];return e.jsxs("div",{className:`agent-panel ${n.status==="working"?"working":""} ${f?"expanded":""} ${p?"focused":""}`,onClick:p?void 0:A,children:[e.jsxs("div",{className:"agent-panel-header",onClick:p?A:void 0,children:[e.jsxs("div",{className:"agent-panel-info",children:[e.jsx("span",{className:"agent-panel-status",style:{background:oe},title:n.status}),e.jsxs("span",{className:"agent-panel-name",children:[(n.isBoss||n.class==="boss")&&e.jsx("span",{className:"agent-panel-boss-crown",children:e.jsx(z,{name:"crown",size:14})}),n.name]}),e.jsx("span",{className:`agent-panel-status-label ${n.status}`,children:n.status}),e.jsx("span",{className:"agent-panel-class",children:n.class}),e.jsx("span",{className:`agent-panel-provider ${n.provider==="codex"?"codex":n.provider==="opencode"?"opencode":"claude"}`,children:n.provider||"claude"}),e.jsxs("span",{className:"agent-panel-id",title:`ID: ${n.id}`,children:["[",n.id.substring(0,4),"]"]}),n.taskLabel?e.jsxs("div",{className:"agent-panel-task agent-panel-task-label",title:n.taskLabel,children:[e.jsx(z,{name:"task",size:12})," ",n.taskLabel]}):n.currentTask?e.jsxs("div",{className:"agent-panel-task",title:n.currentTask,children:[n.currentTask.substring(0,40),"..."]}):null]}),e.jsxs("div",{className:"agent-panel-context",title:`Context: ${Math.round(c.usedPercent)}% used (${De(c.totalTokens)} / ${De(c.contextWindow)})`,children:[e.jsx("div",{className:"agent-panel-context-bar",style:{background:c.freePercent<20?"#ff4a4a":c.freePercent<50?"#ff9e4a":"#4aff9e",width:`${c.freePercent}%`}}),e.jsxs("span",{className:"agent-panel-context-text",children:[Math.round(c.freePercent),"%"]})]}),e.jsx("div",{className:"agent-panel-actions",children:e.jsx("button",{className:"agent-panel-expand",onClick:de,title:E(f?"commander.collapsePanel":"commander.expandPanel"),children:f?e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("polyline",{points:"4 14 10 14 10 20"}),e.jsx("polyline",{points:"20 10 14 10 14 4"}),e.jsx("line",{x1:"14",y1:"10",x2:"21",y2:"3"}),e.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]}):e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("polyline",{points:"15 3 21 3 21 9"}),e.jsx("polyline",{points:"9 21 3 21 3 15"}),e.jsx("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),e.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})})})]}),e.jsx("div",{className:"agent-panel-content",ref:h,children:a!=null&&a.loading?e.jsx("div",{className:"agent-panel-loading",children:E("common:status.loading")}):e.jsx(e.Fragment,{children:!re.length&&!s.length?e.jsxs("div",{className:"agent-panel-empty",children:[E("commander.noMessages"),!n.sessionId&&e.jsx("div",{style:{fontSize:"10px",color:"#666"},children:E("commander.noSessionId")})]}):e.jsx(Ve,{historyMessages:re,liveOutputs:s,agentId:n.id,viewMode:d?"advanced":"simple",selectedMessageIndex:null,isMessageSelected:q,onImageClick:ge,onFileClick:ve,onBashClick:je,onViewMarkdown:we,scrollContainerRef:h,onScrollTopReached:g,isLoadingMore:v,hasMore:a==null?void 0:a.hasMore,shouldAutoScroll:C,onUserScroll:m,pinToBottom:x,onPinCancel:Ce,isLoadingHistory:a==null?void 0:a.loading})})}),e.jsxs("div",{className:`guake-input-wrapper ${n.status==="working"?"has-stop-btn is-working":""}`,children:[e.jsx(ft,{agentId:n.id,isWorking:n.status==="working",timestamp:j==null?void 0:j.timestamp}),e.jsx(ut,{command:U,onCommandChange:w,useTextarea:K,forceTextarea:o,onForceTextarea:L,onSend:xe,canSend:le,attachedFiles:$,onAddFile:he,onRemoveFile:se,uploadFile:ae,onAddPastedText:ie,placeholder:E("commander.command",{name:n.name}),compact:!1,inputRef:R})]}),P&&e.jsx(Ge,{url:P.url,name:P.name,onClose:be}),Y&&e.jsx(qe,{state:Y,onClose:r}),e.jsx(Ye,{agent:n,content:G,onClose:J})]})}function ht({currentArea:n,onClose:a}){const{t:l}=fe(["terminal","common"]),[f,p]=t.useState(()=>{const u=new Set(Array.from(I.getState().agents.values()).map(D=>D.name));return Je.find(D=>!u.has(D))||`Agent-${Date.now().toString(36)}`}),[d,M]=t.useState(()=>Me(ce.LAST_CWD)),[A,R]=t.useState("scout"),[S,b]=t.useState("claude"),[E,j]=t.useState(!1),h=()=>{if(!f.trim()||!d.trim())return;j(!0),Ie(ce.LAST_CWD,d);let u;n&&(u={x:n.center.x,z:n.center.z}),I.spawnAgent(f.trim(),A,d.trim(),u,void 0,void 0,void 0,void 0,S),setTimeout(()=>{a()},500)},v=u=>{u.key==="Enter"&&!u.shiftKey&&(u.preventDefault(),h()),u.key==="Escape"&&a()};return e.jsx("div",{className:"commander-spawn-overlay",onClick:a,children:e.jsxs("div",{className:"commander-spawn-form",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"commander-spawn-header",children:[e.jsx("h3",{children:l("spawn.addNewAgent")}),n&&e.jsxs("span",{className:"commander-spawn-area",children:[e.jsx("span",{className:"commander-spawn-area-dot",style:{background:n.color}}),n.name]})]}),e.jsxs("div",{className:"commander-spawn-body",children:[e.jsxs("div",{className:"commander-spawn-field",children:[e.jsx("label",{children:l("common:labels.name")}),e.jsx("input",{type:"text",value:f,onChange:u=>p(u.target.value),onKeyDown:v,autoFocus:!0})]}),e.jsxs("div",{className:"commander-spawn-field",children:[e.jsx("label",{children:l("common:labels.workingDirectory")}),e.jsx(Xe,{value:d,onChange:M,onSubmit:h,placeholder:l("spawn.workingDirPlaceholder"),directoriesOnly:!0})]}),e.jsxs("div",{className:"commander-spawn-field",children:[e.jsx("label",{children:l("common:labels.class")}),e.jsx("div",{className:"commander-spawn-classes",children:Ze.map(u=>e.jsxs("button",{className:`commander-spawn-class ${A===u.id?"selected":""}`,onClick:()=>R(u.id),children:[e.jsx(Qe,{classId:u.id,size:18,className:"commander-spawn-class-icon"}),e.jsx("span",{children:u.name})]},u.id))})]}),e.jsxs("div",{className:"commander-spawn-field",children:[e.jsx("label",{children:l("common:labels.runtime")}),e.jsxs("div",{className:"commander-spawn-classes",children:[e.jsxs("button",{className:`commander-spawn-class ${S==="claude"?"selected":""}`,onClick:()=>b("claude"),children:[e.jsx("span",{className:"commander-spawn-class-icon",children:e.jsx(z,{name:"brain",size:14})}),e.jsx("span",{children:"Claude"})]}),e.jsxs("button",{className:`commander-spawn-class ${S==="codex"?"selected":""}`,onClick:()=>b("codex"),children:[e.jsx("span",{className:"commander-spawn-class-icon",children:e.jsx(z,{name:"gear",size:14})}),e.jsx("span",{children:"Codex"})]}),e.jsxs("button",{className:`commander-spawn-class ${S==="opencode"?"selected":""}`,onClick:()=>b("opencode"),children:[e.jsx("span",{className:"commander-spawn-class-icon",children:e.jsx(z,{name:"status-pending",size:12,weight:"fill",color:"#4ade80"})}),e.jsx("span",{children:"OpenCode"})]})]})]})]}),e.jsxs("div",{className:"commander-spawn-footer",children:[e.jsx("button",{className:"commander-spawn-cancel",onClick:a,children:l("common:buttons.cancel")}),e.jsx("button",{className:"commander-spawn-submit",onClick:h,disabled:!f.trim()||!d.trim()||E,children:l(E?"common:buttons.deploying":"common:buttons.deploy")})]})]})})}const Pe=t.memo(function({agent:a,history:l,isExpanded:f,isFocused:p,advancedView:d,index:M,onExpand:A,onCollapse:R,onFocus:S,onInputRef:b,onLoadMore:E,onClearHistory:j}){const h=nt(a.id),v=t.useCallback(()=>{f?R():A(a.id)},[a.id,f,A,R]),u=t.useCallback(()=>{S(p?-1:M)},[M,p,S]),D=t.useCallback(F=>{b(a.id,F)},[a.id,b]),i=t.useCallback(()=>{E(a.id)},[a.id,E]),C=t.useCallback(()=>{j(a.id)},[a.id,j]);return e.jsx(pt,{agent:a,history:l,outputs:h,isExpanded:f,isFocused:p,advancedView:d,onExpand:v,onFocus:u,inputRef:D,onLoadMore:i,onClearHistory:C})});function Ct({isOpen:n,onClose:a}){const{t:l}=fe(["terminal","common"]),f=et(),p=tt(),[d,M]=t.useState(()=>Me(ce.COMMANDER_TAB,"all")),[A,R]=t.useState(0),[S,b]=t.useState(null),E=t.useRef(null),[j,h]=t.useState(0),[v,u]=t.useState(!1),[D,i]=t.useState(null),[C,F]=t.useState(!1),[x,k]=t.useState(()=>{try{const s=Me(ce.COMMANDER_FILTERS,"");if(s)return{...Se,...JSON.parse(s)}}catch{}return Se}),P=t.useRef(new Map),W=t.useRef([]),Y=t.useRef(0),V=t.useRef([]),G=t.useRef(d),{histories:Z,loadMoreHistory:U,clearAgentHistory:w}=dt({isOpen:n,agents:f});t.useEffect(()=>{n||(b(null),h(0),u(!1))},[n]);const o=t.useMemo(()=>{const s=Array.from(p.values()).sort((g,m)=>g.name.localeCompare(m.name)),c=[{id:"all",name:l("common:labels.all")}];for(const g of s)c.push({id:g.id,name:g.name,color:g.color});return c.push({id:"unassigned",name:l("commander.unassigned")}),c},[p]),L=t.useMemo(()=>d==="all"||d==="unassigned"?null:p.get(d)||null,[d,p]),K=t.useMemo(()=>{const s=new Map;s.set("all",f.size);let c=0;for(const g of f.values()){const m=I.getAreaForAgent(g.id);m?s.set(m.id,(s.get(m.id)||0)+1):c++}return s.set("unassigned",c),s},[f]),B=x.status!=="all"||x.activity!=="all"||x.sort!=="activity",te=(x.status!=="all"?1:0)+(x.activity!=="all"?1:0)+(x.sort!=="activity"?1:0),_=t.useMemo(()=>{const s=m=>m.isBoss===!0||m.class==="boss",c=Date.now();let g=Array.from(f.values());if(d==="unassigned"?g=g.filter(m=>!I.getAreaForAgent(m.id)):d!=="all"&&(g=g.filter(m=>{const T=I.getAreaForAgent(m.id);return(T==null?void 0:T.id)===d})),x.status!=="all"&&(g=g.filter(m=>{switch(x.status){case"working":return m.status==="working";case"idle":return m.status==="idle";case"error":return m.status==="error"||m.status==="waiting"||m.status==="waiting_permission";case"offline":return m.status==="offline"||m.status==="orphaned";default:return!0}})),x.activity!=="all"){const m=lt[x.activity];g=g.filter(T=>c-(T.lastActivity||0)<m)}return g.sort((m,T)=>{var Q,ee;if(s(m)&&!s(T))return-1;if(!s(m)&&s(T))return 1;switch(x.sort){case"activity":return(T.lastActivity||0)-(m.lastActivity||0);case"name":return m.name.localeCompare(T.name);case"created":return(m.createdAt||0)-(T.createdAt||0);case"context":{const q=((Q=m.contextStats)==null?void 0:Q.usedPercent)??(m.contextUsed||0)/(m.contextLimit||2e5)*100;return(((ee=T.contextStats)==null?void 0:ee.usedPercent)??(T.contextUsed||0)/(T.contextLimit||2e5)*100)-q}default:return(T.lastActivity||0)-(m.lastActivity||0)}}),g},[f,d,x]),$=Math.ceil(_.length/Ae),H=t.useMemo(()=>_.slice(A*Ae,(A+1)*Ae),[_,A]);W.current=H,E.current=S,Y.current=j,V.current=o,G.current=d,Te("commander-expanded",S!==null,()=>b(null));const se=st();t.useEffect(()=>{n&&se&&(b(se),I.clearCommanderExpandRequest())},[n,se]);const ae=t.useCallback(()=>b(null),[]),ne=t.useCallback(s=>b(s),[]),le=t.useCallback(s=>h(s),[]),pe=t.useCallback((s,c)=>{c?P.current.set(s,c):P.current.delete(s)},[]);return t.useEffect(()=>{R(0),Ie(ce.COMMANDER_TAB,d)},[d]),t.useEffect(()=>{Ie(ce.COMMANDER_FILTERS,JSON.stringify(x)),R(0)},[x]),t.useEffect(()=>{var c;if(!n||window.matchMedia("(pointer: coarse)").matches)return;const s=S||((c=W.current[j])==null?void 0:c.id);if(s){const g=P.current.get(s);g&&document.activeElement!==g&&setTimeout(()=>g.focus(),50)}},[n,j,S]),t.useEffect(()=>{if(!n)return;const s=c=>{const g=I.getShortcuts(),m=c.target,T=m.tagName==="INPUT"||m.tagName==="TEXTAREA",Q=W.current,ee=Q.length-1,q=E.current,ie=g.find(r=>r.id==="commander-close");if(X(c,ie)){const{fileViewerPath:r,contextModalAgentId:J}=I.getState();if(r||J)return;c.preventDefault(),c.stopImmediatePropagation(),q?b(null):a();return}const he=g.find(r=>r.id==="commander-vim-left");if(X(c,he)&&!q){c.preventDefault(),h(r=>r>0?r-1:r);return}const xe=g.find(r=>r.id==="commander-vim-right");if(X(c,xe)&&!q){c.preventDefault(),h(r=>r<ee?r+1:r);return}const ge=g.find(r=>r.id==="commander-vim-up");if(X(c,ge)&&!q){c.preventDefault(),h(r=>r>=me?r-me:r);return}const ve=g.find(r=>r.id==="commander-vim-down");if(X(c,ve)&&!q){c.preventDefault(),h(r=>r+me<=ee?r+me:r);return}const je=g.find(r=>r.id==="commander-expand");if(X(c,je)){if(c.preventDefault(),q)b(null);else{const r=Q[Y.current];r&&b(r.id)}return}const we=g.find(r=>r.id==="commander-new-agent");if(X(c,we)){c.preventDefault(),u(!0);return}const Ce=g.find(r=>r.id==="commander-next-tab"),be=g.find(r=>r.id==="commander-prev-tab");if(!T){const r=V.current;if(X(c,Ce)){const J=I.getState().latestNotificationAgentId;if(J){if(c.preventDefault(),c.stopPropagation(),!I.getState().agents.get(J)){I.setLatestNotificationAgentId(null);return}const y=I.getAreaForAgent(J);y&&r.some(O=>O.id===y.id)?M(y.id):M("unassigned"),b(J),h(0),R(0),I.setLatestNotificationAgentId(null);return}c.preventDefault(),c.stopPropagation();const oe=(r.findIndex(re=>re.id===G.current)+1)%r.length;M(r[oe].id),h(0);return}if(X(c,be)){c.preventDefault(),c.stopPropagation();const de=(r.findIndex(oe=>oe.id===G.current)-1+r.length)%r.length;M(r[de].id),h(0);return}}};return document.addEventListener("keydown",s,!0),()=>document.removeEventListener("keydown",s,!0)},[n,a]),n?e.jsx("div",{className:"commander-overlay",onClick:a,children:e.jsxs("div",{className:"commander-view",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"commander-header",children:[e.jsxs("div",{className:"commander-title-section",children:[e.jsx("h2",{className:"commander-title",children:l("commander.title")}),e.jsx("span",{className:"commander-shortcuts",children:l("commander.shortcuts")})]}),e.jsxs("div",{className:"commander-controls",children:[e.jsx("button",{className:`commander-view-toggle ${C?"active":""}`,onClick:()=>F(!C),title:l(C?"commander.simple":"commander.advanced"),children:C?e.jsxs(e.Fragment,{children:[e.jsx(z,{name:"target",size:12})," ",l("commander.advanced")]}):e.jsxs(e.Fragment,{children:[e.jsx(z,{name:"status-pending",size:12})," ",l("commander.simple")]})}),e.jsx("button",{className:"commander-add-btn",onClick:()=>u(!0),title:l("commander.addAgent"),children:l("commander.addAgent")}),e.jsx("button",{className:"commander-close",onClick:a,children:l("commander.close")})]})]}),e.jsx("div",{className:"commander-tabs",children:o.map(s=>{const c=s.id!=="all"&&s.id!=="unassigned"?p.get(s.id):null,g=c&&c.directories&&c.directories.length>0;return e.jsxs("button",{className:`commander-tab ${d===s.id?"active":""}`,onClick:()=>{M(s.id),h(0)},style:s.color?{borderBottomColor:d===s.id?s.color:"transparent"}:void 0,children:[s.color&&e.jsx("span",{className:"commander-tab-dot",style:{background:s.color}}),e.jsx("span",{children:s.name}),e.jsx("span",{className:"commander-tab-count",children:K.get(s.id)||0}),g&&e.jsx("span",{className:"commander-tab-folder",onClick:m=>{m.stopPropagation(),i(s.id)},title:l("commander.openFileExplorer"),children:e.jsx(z,{name:"folder",size:12})})]},s.id)})}),e.jsxs("div",{className:"commander-filters",children:[e.jsxs("div",{className:"commander-filter-group",children:[e.jsx("span",{className:"commander-filter-label",children:l("commander.filters.status")}),["all","working","idle","error","offline"].map(s=>e.jsx("button",{className:`commander-filter-btn ${x.status===s?"active":""}`,onClick:()=>k(c=>({...c,status:s})),children:s==="all"?l("commander.filters.all"):s==="error"?l("commander.filters.needsAttn"):s.charAt(0).toUpperCase()+s.slice(1)},s))]}),e.jsxs("div",{className:"commander-filter-group",children:[e.jsx("span",{className:"commander-filter-label",children:l("commander.filters.active")}),["all","1h","6h","24h"].map(s=>e.jsx("button",{className:`commander-filter-btn ${x.activity===s?"active":""}`,onClick:()=>k(c=>({...c,activity:s})),children:s==="all"?l("commander.filters.any"):`< ${s}`},s))]}),e.jsxs("div",{className:"commander-filter-group",children:[e.jsx("span",{className:"commander-filter-label",children:l("commander.filters.sort")}),["activity","name","created","context"].map(s=>e.jsx("button",{className:`commander-filter-btn ${x.sort===s?"active":""}`,onClick:()=>k(c=>({...c,sort:s})),children:s==="activity"?l("commander.filters.recent"):s==="context"?l("commander.filters.context"):s.charAt(0).toUpperCase()+s.slice(1)},s))]}),B&&e.jsx("button",{className:"commander-filter-clear",onClick:()=>k(Se),title:l("commander.clearFilters"),children:l("commander.filters.clearFilters",{count:te})})]}),$>1&&e.jsxs("div",{className:"commander-pagination",children:[e.jsxs("button",{className:"commander-page-btn",onClick:()=>R(s=>Math.max(0,s-1)),disabled:A===0,children:[e.jsx(z,{name:"caret-left",size:12})," ",l("commander.prev")]}),e.jsx("span",{className:"commander-page-info",children:l("commander.page",{current:A+1,total:$,count:_.length})}),e.jsxs("button",{className:"commander-page-btn",onClick:()=>R(s=>Math.min($-1,s+1)),disabled:A===$-1,children:[l("commander.next")," ",e.jsx(z,{name:"caret-right",size:12})]})]}),e.jsx("div",{className:`commander-grid ${S?"has-expanded":""}`,"data-agent-count":S?1:H.length,children:H.length===0?e.jsx("div",{className:"commander-empty",children:l(d==="all"?"commander.noAgentsAll":d==="unassigned"?"commander.noAgentsUnassigned":"commander.noAgentsArea")}):S?(()=>{const s=f.get(S);return s?e.jsx(Pe,{agent:s,history:Z.get(s.id),isExpanded:!0,isFocused:!0,advancedView:C,index:0,onExpand:ne,onCollapse:ae,onFocus:le,onInputRef:pe,onLoadMore:U,onClearHistory:w},s.id):null})():H.map((s,c)=>e.jsx(Pe,{agent:s,history:Z.get(s.id),isExpanded:!1,isFocused:c===j,advancedView:C,index:c,onExpand:ne,onCollapse:ae,onFocus:le,onInputRef:pe,onLoadMore:U,onClearHistory:w},s.id))}),v&&e.jsx(ht,{currentArea:L,onClose:()=>u(!1)}),D&&e.jsx(at,{isOpen:!0,areaId:D,onClose:()=>i(null),onChangeArea:s=>i(s)})]})}):null}export{Ct as CommanderView};
@@ -0,0 +1 @@
1
+ import{u as J,a as Z,r,s as u,j as e,D as le,I as H,C as ce,b as ie,c as de,d as oe,g as me,e as ue,Q as be,R as he}from"./main-BjcLCHKw.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const _e=({building:a,connections:x,activeConnectionId:l,activeDatabase:c,collapsed:j,onToggleCollapse:p,onConnectionChange:Q,onDatabaseChange:N,onInsertTable:A,onSelectTableQuery:P})=>{const{t:o}=J(["terminal"]),q=Z(a.id),[M,R]=r.useState(new Set),[w,n]=r.useState(""),[d,T]=r.useState(""),[E,k]=r.useState(!1),[U,F]=r.useState(null),z=r.useRef(null),S=r.useRef(null),O=r.useRef(null),y=l?q.databases.get(l)??[]:[],I=l&&c?`${l}:${c}`:"",f=I?q.tables.get(I)??[]:[],_=l?q.connectionStatus.get(l):void 0,D=r.useMemo(()=>{if(!w.trim())return y;const t=w.toLowerCase();return y.filter(m=>m.toLowerCase().includes(t))},[y,w]),h=r.useMemo(()=>{if(!d.trim())return f;const t=d.toLowerCase();return f.filter(m=>m.name.toLowerCase().includes(t))},[f,d]);r.useEffect(()=>{const t=m=>{S.current&&!S.current.contains(m.target)&&k(!1)};return E&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[E]),r.useEffect(()=>{l&&!_&&u.testDatabaseConnection(a.id,l)},[a.id,l,_]),r.useEffect(()=>{l&&(_!=null&&_.connected)&&y.length===0&&u.listDatabases(a.id,l)},[a.id,l,_==null?void 0:_.connected,y.length]),r.useEffect(()=>{l&&c&&f.length===0&&u.listTables(a.id,l,c)},[a.id,l,c,f.length]),r.useEffect(()=>{F(null),T("")},[l,c]);const v=r.useCallback(t=>{R(m=>{const g=new Set(m);if(g.has(t))g.delete(t);else if(g.add(t),l&&c){const C=`${l}:${c}:${t}`;q.tableSchemas.has(C)||u.getTableSchema(a.id,l,c,t)}return g})},[a.id,l,c,q.tableSchemas]),K=t=>{if(!l||!c)return null;const m=`${l}:${c}:${t}`;return q.tableSchemas.get(m)};return j?e.jsx("div",{className:"database-sidebar database-sidebar--collapsed",children:e.jsx("button",{className:"database-sidebar__toggle",onClick:p,title:o("terminal:database.expandSidebar"),children:"»"})}):e.jsxs("div",{className:"database-sidebar",children:[e.jsxs("div",{className:"database-sidebar__header",children:[e.jsx("span",{children:o("terminal:database.explorer")}),e.jsx("button",{className:"database-sidebar__toggle",onClick:p,title:o("terminal:database.collapseSidebar"),children:"«"})]}),e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:o("terminal:database.connection")}),e.jsx("select",{className:"database-sidebar__select",value:l||"",onChange:t=>Q(t.target.value),children:x.length===0?e.jsx("option",{value:"",children:o("terminal:database.noConnections")}):x.map(t=>{var m;return e.jsxs("option",{value:t.id,children:[((m=le[t.engine])==null?void 0:m.icon)??"🗄️"," ",t.name]},t.id)})}),_&&e.jsx("div",{className:`database-sidebar__status ${_.connected?"database-sidebar__status--connected":"database-sidebar__status--error"}`,children:_.connected?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✓"}),o("terminal:database.connected"),_.serverVersion&&e.jsxs("span",{className:"database-sidebar__version",children:["(",_.serverVersion,")"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✗"}),_.error||o("terminal:database.disconnected")]})})]}),y.length>0&&e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:o("terminal:database.databaseTitle")}),e.jsxs("div",{className:"database-sidebar__searchable-select",ref:S,children:[e.jsx("input",{ref:z,className:"database-sidebar__search-input",type:"text",value:E?w:c||"",placeholder:o("terminal:database.selectDatabase"),onChange:t=>{n(t.target.value),E||k(!0)},onFocus:()=>{k(!0),n("")},onKeyDown:t=>{var m,g;t.key==="Escape"?(k(!1),n(""),(m=z.current)==null||m.blur()):t.key==="Enter"&&D.length===1&&(N(D[0]),k(!1),n(""),(g=z.current)==null||g.blur())}}),E&&e.jsx("div",{className:"database-sidebar__dropdown",children:D.length===0?e.jsx("div",{className:"database-sidebar__dropdown-empty",children:"No matches"}):D.map(t=>e.jsx("div",{className:`database-sidebar__dropdown-item ${t===c?"database-sidebar__dropdown-item--active":""}`,onMouseDown:m=>{m.preventDefault(),N(t),k(!1),n("")},children:t},t))})]})]}),f.length>0&&e.jsxs("div",{className:"database-sidebar__section database-sidebar__section--tables",children:[e.jsx("div",{className:"database-sidebar__section-title",children:d.trim()?o("terminal:database.tablesCount",{count:h.length})+` / ${f.length}`:o("terminal:database.tablesCount",{count:f.length})}),e.jsxs("div",{className:"database-sidebar__table-filter",children:[e.jsx("input",{ref:O,className:"database-sidebar__table-filter-input",type:"text",value:d,placeholder:o("terminal:database.filterTables"),onChange:t=>T(t.target.value),onKeyDown:t=>{var m;t.key==="Escape"&&(d?T(""):(m=O.current)==null||m.blur(),t.stopPropagation())}}),d&&e.jsx("button",{className:"database-sidebar__table-filter-clear",onClick:()=>{var t;T(""),(t=O.current)==null||t.focus()},title:"Clear filter",children:"×"})]}),e.jsxs("div",{className:"database-sidebar__tables",children:[d.trim()&&h.length===0&&e.jsx("div",{className:"database-sidebar__tables-empty",children:o("terminal:database.noTablesMatch")}),h.map(t=>{const m=M.has(t.name),g=m?K(t.name):null;return e.jsxs("div",{className:"database-sidebar__table",children:[e.jsxs("div",{className:"database-sidebar__table-header",children:[e.jsx("button",{className:"database-sidebar__table-expand",onClick:()=>v(t.name),title:m?"Collapse table schema":"Expand table schema",children:e.jsx(H,{name:m?"caret-down":"caret-right",size:10})}),e.jsx("span",{className:"database-sidebar__table-icon",children:e.jsx(H,{name:t.type==="view"?"eye":"clipboard",size:12})}),e.jsx("span",{className:`database-sidebar__table-name ${U===t.name?"database-sidebar__table-name--selected":""}`,onClick:()=>F(t.name),onDoubleClick:()=>{F(t.name),P(t.name)},children:t.name}),e.jsx("button",{className:"database-sidebar__table-insert",onClick:C=>{C.stopPropagation(),A(t.name)},title:o("terminal:database.insertTableName"),children:"+"})]}),m&&g&&e.jsx("div",{className:"database-sidebar__table-columns",children:g.columns.map(C=>e.jsxs("div",{className:"database-sidebar__column",onClick:()=>A(C.name),title:`${C.type}${C.nullable?" NULL":" NOT NULL"}${C.primaryKey?" PK":""}`,children:[e.jsx("span",{className:"database-sidebar__column-icon",children:C.primaryKey?e.jsx(H,{name:"key",size:11}):null}),e.jsx("span",{className:"database-sidebar__column-name",children:C.name}),e.jsx("span",{className:"database-sidebar__column-type",children:C.type})]},C.name))})]},t.name)})]})]})]})},xe=({buildingId:a,history:x,onLoadQuery:l})=>{const{t:c}=J(["terminal","common"]),[j,p]=r.useState(""),[Q,N]=r.useState(!1),[A,P]=r.useState(!1),o=r.useMemo(()=>{let n=x;if(Q&&(n=n.filter(d=>d.favorite)),j.trim()){const d=j.toLowerCase();n=n.filter(T=>T.query.toLowerCase().includes(d)||T.database.toLowerCase().includes(d))}return n},[x,Q,j]),q=n=>{const d=new Date(n),E=new Date().getTime()-d.getTime();return E<1440*60*1e3?d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):E<10080*60*1e3?d.toLocaleDateString([],{weekday:"short"})+" "+d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):d.toLocaleDateString([],{month:"short",day:"numeric"})},M=r.useCallback((n,d)=>{d.stopPropagation(),u.toggleQueryFavorite(a,n)},[a]),R=r.useCallback((n,d)=>{d.stopPropagation(),u.deleteQueryFromHistory(a,n)},[a]),w=r.useCallback(()=>{P(!0)},[]);return x.length===0?e.jsxs("div",{className:"query-history query-history--empty",children:[e.jsx("p",{children:c("terminal:database.noHistory")}),e.jsx("p",{children:c("terminal:database.queriesAppearHere")})]}):e.jsxs("div",{className:"query-history",children:[e.jsxs("div",{className:"query-history__toolbar",children:[e.jsx("input",{type:"text",className:"query-history__search",placeholder:c("terminal:database.searchQueries"),value:j,onChange:n=>p(n.target.value)}),e.jsxs("label",{className:"query-history__filter",children:[e.jsx("input",{type:"checkbox",checked:Q,onChange:n=>N(n.target.checked)}),c("terminal:database.favoritesOnly")]}),e.jsx("button",{className:"query-history__clear",onClick:w,title:c("terminal:database.clearAll"),children:c("terminal:database.clearAll")})]}),e.jsxs("div",{className:"query-history__list",children:[o.map(n=>e.jsxs("div",{className:`query-history__item ${n.status==="error"?"query-history__item--error":""}`,onClick:()=>l(n.query),children:[e.jsxs("div",{className:"query-history__item-header",children:[e.jsx("span",{className:`query-history__status ${n.status==="success"?"query-history__status--success":"query-history__status--error"}`,children:e.jsx(H,{name:n.status==="success"?"check":"cross",size:12})}),e.jsx("span",{className:"query-history__database",children:n.database}),e.jsx("span",{className:"query-history__date",children:q(n.executedAt)}),e.jsxs("span",{className:"query-history__duration",children:[n.duration,"ms"]}),n.rowCount!==void 0&&e.jsx("span",{className:"query-history__row-count",children:c("terminal:database.rowCount",{count:n.rowCount})})]}),e.jsx("div",{className:"query-history__query",children:e.jsx("code",{children:n.query.length>200?n.query.substring(0,200)+"...":n.query})}),n.error&&e.jsx("div",{className:"query-history__error",children:n.error}),e.jsxs("div",{className:"query-history__actions",children:[e.jsx("button",{className:`query-history__favorite ${n.favorite?"query-history__favorite--active":""}`,onClick:d=>M(n.id,d),title:n.favorite?c("terminal:database.removeFromFavorites"):c("terminal:database.addToFavorites"),children:e.jsx(H,{name:"star",size:12,weight:n.favorite?"fill":"regular",color:n.favorite?"#facc15":void 0})}),e.jsx("button",{className:"query-history__delete",onClick:d=>R(n.id,d),title:c("terminal:database.deleteFromHistory"),children:e.jsx(H,{name:"trash",size:12})})]})]},n.id)),o.length===0&&e.jsx("div",{className:"query-history__no-results",children:c("terminal:database.noQueriesMatch")})]}),e.jsx(ce,{isOpen:A,title:c("terminal:database.clearAll"),message:c("terminal:database.confirmClearHistory"),confirmLabel:c("terminal:database.clearAll"),cancelLabel:c("common:buttons.cancel"),variant:"danger",onConfirm:()=>u.clearQueryHistory(a),onClose:()=>P(!1)})]})},pe=({tabs:a,activeTabId:x,onTabClick:l,onTabClose:c})=>{const{t:j}=J(["terminal"]);return e.jsx("div",{className:"database-tabs",children:a.map(p=>e.jsxs("div",{className:`database-tabs__tab ${x===p.id?"database-tabs__tab--active":""}`,children:[e.jsxs("button",{className:"database-tabs__tab-label",onClick:()=>l(p),title:`${p.connectionName} / ${p.database}`,children:[p.database,e.jsx("span",{className:"database-tabs__tab-connection",children:p.connectionName})]}),e.jsx("button",{className:"database-tabs__tab-close",onClick:()=>c(p.id),title:j("terminal:database.closeTab"),"aria-label":`Close ${p.database} tab`,children:"×"})]},p.id))})},ee=a=>`db-panel-${a}`;function fe(a){try{const x=localStorage.getItem(ee(a));return x?JSON.parse(x):{}}catch{return{}}}function je(a,x){try{localStorage.setItem(ee(a),JSON.stringify(x))}catch{}}const Ce=({building:a,onClose:x})=>{var B,Y,W,X;const{t:l}=J(["terminal","common"]),c=Z(a.id),j=ie(a.id),p=de(a.id),Q=oe(a.id),N=r.useRef(fe(a.id)),A=r.useRef(null),P=r.useRef(0),o=((B=a.database)==null?void 0:B.connections)??[],q=(s,i)=>`${s}:${i}`,M=s=>s?(N.current.queries??{})[s]??"":N.current.generalQuery??"",[R,w]=r.useState("results"),[n,d]=r.useState(0),[T,E]=r.useState(!1),[k,U]=r.useState(!1),[F,z]=r.useState(()=>(N.current.openTabs??[]).map(i=>{var b;return{id:`${i.connectionId}:${i.database}`,connectionId:i.connectionId,connectionName:((b=o.find(L=>L.id===i.connectionId))==null?void 0:b.name)??i.connectionId,database:i.database}})),[S,O]=r.useState(N.current.activeTabId??null),[y,I]=r.useState(()=>{const s=N.current.queries??{};return N.current.generalQuery,s}),[f,_]=r.useState(M(S)),D=r.useCallback(s=>{_(i=>{const b=typeof s=="function"?s(i):s;return I(L=>{const $={...L};return S&&($[S]=b),$}),b})},[S]),h=c.activeConnectionId??N.current.connectionId??((Y=a.database)==null?void 0:Y.activeConnectionId)??((W=o[0])==null?void 0:W.id),v=c.activeDatabase??N.current.database??((X=a.database)==null?void 0:X.activeDatabase),K=o.find(s=>s.id===h),t=r.useCallback((s,i)=>{var $;const b=q(s,i),L=(($=o.find(G=>G.id===s))==null?void 0:$.name)??s;z(G=>{if(G.some(re=>re.id===b))return G;const ne={id:b,connectionId:s,connectionName:L,database:i};return[...G,ne]}),O(b),_(y[b]??""),u.setActiveConnection(a.id,s),u.setActiveDatabase(a.id,i)},[a.id,o,y]),m=r.useCallback(s=>{z(i=>i.filter(b=>b.id!==s)),S===s&&z(i=>{if(i.length>0){const b=i[0];O(b.id),_(y[b.id]??""),u.setActiveConnection(a.id,b.connectionId),u.setActiveDatabase(a.id,b.database)}else O(null),_("");return i})},[S,a.id,y]),g=r.useCallback(s=>{O(s.id),_(y[s.id]??""),u.setActiveConnection(a.id,s.connectionId),u.setActiveDatabase(a.id,s.database)},[a.id,y]);r.useEffect(()=>{if(!k&&o.length>0){const s=N.current;s.connectionId&&o.some(i=>i.id===s.connectionId)&&(u.setActiveConnection(a.id,s.connectionId),u.listDatabases(a.id,s.connectionId),s.database&&(u.setActiveDatabase(a.id,s.database),u.listTables(a.id,s.connectionId,s.database))),U(!0)}},[a.id,o,k]),r.useEffect(()=>{u.requestQueryHistory(a.id)},[a.id]),r.useEffect(()=>{const s=i=>{i.key==="Escape"&&(i.preventDefault(),i.stopPropagation(),x())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[x]),r.useEffect(()=>{k&&h&&je(a.id,{connectionId:h,database:v,lastQuery:f,queries:y,generalQuery:"",openTabs:F.map(s=>({connectionId:s.connectionId,database:s.database})),activeTabId:S??void 0})},[a.id,h,v,f,k,F,S,y]);const C=r.useCallback(s=>{var i;if(!(!h||!v||!f.trim()||Q))if(s==="cursor"){const b=(i=A.current)==null?void 0:i.querySelector(".query-editor__textarea"),L=(b==null?void 0:b.selectionStart)??P.current,$=me(f,L);$&&u.executeQuery(a.id,h,v,$)}else{const b=ue(f);b.length<=1?u.executeQuery(a.id,h,v,f.trim()):b.forEach((L,$)=>{setTimeout(()=>{u.executeQuery(a.id,h,v,L.sql)},$*150)})}},[a.id,h,v,f,Q]),ae=r.useCallback(s=>{D(s),w("results")},[]),se=r.useCallback(s=>{u.setActiveConnection(a.id,s),u.listDatabases(a.id,s)},[a.id]),te=r.useCallback(s=>{h&&(t(h,s),u.listTables(a.id,h,s))},[a.id,h,t]),V=j[n];return o.length===0?e.jsxs("div",{className:"database-panel",ref:A,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:e.jsx(H,{name:"database",size:16})}),e.jsx("span",{className:"database-panel__name",children:a.name})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsx("div",{className:"database-panel__body",children:e.jsxs("div",{className:"database-panel__no-connections",children:[e.jsx("div",{className:"database-panel__no-connections-icon",children:e.jsx(H,{name:"plug",size:32})}),e.jsx("h3",{children:l("terminal:database.noConnections")}),e.jsx("p",{children:l("terminal:database.noConnectionsDesc")}),e.jsx("p",{children:l("terminal:database.toGetStarted")}),e.jsxs("ol",{children:[e.jsx("li",{children:l("terminal:database.step1Close")}),e.jsx("li",{children:l("terminal:database.step2Settings")}),e.jsx("li",{children:l("terminal:database.step3AddConnection")}),e.jsx("li",{children:l("terminal:database.step4Reopen")})]})]})})]}):e.jsxs("div",{className:"database-panel",ref:A,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:(K==null?void 0:K.engine)==="mysql"?"🐬":"🐘"}),e.jsx("span",{className:"database-panel__name",children:a.name}),K&&e.jsxs("span",{className:"database-panel__connection-info",children:[K.name," / ",v||l("terminal:database.noDatabaseSelected")]})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsxs("div",{className:"database-panel__body",children:[e.jsx(_e,{building:a,connections:o,activeConnectionId:h,activeDatabase:v,collapsed:T,onToggleCollapse:()=>E(!T),onConnectionChange:se,onDatabaseChange:te,onInsertTable:s=>D(i=>i+` ${s}`),onSelectTableQuery:s=>{const i=`SELECT * FROM ${s}`;D(i),h&&v&&u.executeQuery(a.id,h,v,i)}}),e.jsxs("div",{className:"database-panel__main",children:[F.length>0&&e.jsx(pe,{tabs:F,activeTabId:S,onTabClick:g,onTabClose:m}),e.jsx(be,{query:f,onChange:D,onExecute:C,isExecuting:Q,disabled:!h||!v}),e.jsxs("div",{className:"database-panel__tabs",children:[e.jsxs("button",{className:`database-panel__tab ${R==="results"?"database-panel__tab--active":""}`,onClick:()=>w("results"),children:[l("terminal:database.results"),j.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:j.length})]}),e.jsxs("button",{className:`database-panel__tab ${R==="history"?"database-panel__tab--active":""}`,onClick:()=>w("history"),children:[l("terminal:database.history"),p.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:p.length})]}),R==="results"&&j.length>1&&e.jsxs("div",{className:"database-panel__result-nav",children:[e.jsxs("button",{disabled:n>=j.length-1,onClick:()=>d(s=>s+1),children:["← ",l("terminal:database.older")]}),e.jsxs("span",{children:[n+1," / ",j.length]}),e.jsxs("button",{disabled:n<=0,onClick:()=>d(s=>s-1),children:[l("terminal:database.newer")," →"]})]})]}),e.jsx("div",{className:"database-panel__tab-content",children:R==="results"?V?e.jsx(he,{result:V,buildingId:a.id,building:a}):e.jsxs("div",{className:"database-panel__empty",children:[e.jsx("p",{children:l("terminal:database.noResultsYet")}),e.jsx("p",{children:l("terminal:database.selectDbAndRun")})]}):e.jsx(xe,{buildingId:a.id,history:p,onLoadQuery:ae})})]})]})]})};export{Ce as DatabasePanel,_e as DatabaseSidebar,pe as DatabaseTabs,be as QueryEditor,xe as QueryHistoryPanel,he as ResultsTable};
@@ -1 +1 @@
1
- import{a0 as as,u as ts,ah as vs,ai as bs,aj as zs,j as s,I as F,P as Is,ak as Es,al as $s,am as Ds,an as Ms,r as c,ao as Ls,a7 as Ps,a2 as Ss,M as Xs,B as Rs,ap as Ys,aq as Gs,ar as Us,as as ms,at as _s,s as M,au as Fs,n as U}from"./main-BnUsuS5B.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const fs=as.memo(({agent:a,isSelected:A,isKeyboardFocused:L=!1,onSelect:P,onDoubleClick:n,onChat:g,onFocus:h,onKill:w,onDragStart:S})=>{const{t:x}=ts(["dashboard","common"]),X=vs().has(a.id),N=bs(a.status),B=zs(a),j=Ms(B),I=a.taskLabel?s.jsxs(s.Fragment,{children:[s.jsx(F,{name:"task",size:12})," ",a.taskLabel]}):a.currentTask||a.lastAssignedTask,m=a.status==="idle"&&a.lastActivity>0,[,H]=as.useState(0);return as.useEffect(()=>{if(!m)return;const b=window.setInterval(()=>H(T=>T+1),15e3);return()=>window.clearInterval(b)},[m]),s.jsxs("div",{className:`dash-card dash-card--${N} ${A?"dash-card--selected":""} ${L?"dash-card--keyboard-focused":""}`,"data-agent-id":a.id,onClick:P,onDoubleClick:b=>{b.stopPropagation(),n()},onDragStart:b=>{S==null||S(a),b.dataTransfer.effectAllowed="move"},draggable:!0,title:x("cards.doubleClickHint"),children:[s.jsxs("div",{className:"dash-card__row1",children:[s.jsx("span",{className:`dash-card__status-dot dash-card__status-dot--${N}`}),s.jsx("span",{className:"dash-card__name",children:a.name}),s.jsxs("span",{className:"dash-card__class",children:[s.jsx(Is,{agent:a,size:14})," ",a.class]}),s.jsxs("span",{className:`dash-card__provider dash-card__provider--${a.provider}`,children:[s.jsx(F,{name:a.provider==="codex"||a.provider==="opencode"?"status-pending":"robot",size:11,weight:a.provider==="codex"||a.provider==="opencode"?"fill":"regular",color:a.provider==="codex"?"#a16207":a.provider==="opencode"?"#4ade80":void 0})," ",a.provider]}),X&&s.jsx("span",{className:"dash-card__unseen-badge",title:"New output available - click to view",children:"!"})]}),s.jsxs("div",{className:"dash-card__row2",children:[s.jsx("span",{className:`dash-card__status dash-card__status--${N}`,children:X?"Unseen":a.status}),s.jsxs("div",{className:"dash-card__context",children:[s.jsx("div",{className:"dash-card__context-bar",children:s.jsx("div",{className:`dash-card__context-fill dash-card__context-fill--${j}`,style:{width:`${B}%`}})}),s.jsxs("span",{className:`dash-card__context-pct dash-card__context-pct--${j}`,children:[B,"%"]})]})]}),s.jsxs("div",{className:"dash-card__row3",children:[s.jsxs("span",{className:"dash-card__workdir",title:a.cwd,children:[s.jsx(F,{name:"folder",size:11})," ",a.cwd.split("/").pop()||a.cwd]}),m&&s.jsxs("span",{className:"dash-card__idle-time",style:{color:Ds(a.lastActivity)},title:$s(a.lastActivity),children:[s.jsx(F,{name:"status-waiting-input",size:10})," ",Es(a.lastActivity)]})]}),I&&s.jsx("div",{className:"dash-card__row4",children:s.jsx("span",{className:"dash-card__task",children:I})}),s.jsxs("div",{className:"dash-card__actions",children:[g&&s.jsx("button",{className:"dash-card__action-btn dash-card__action-btn--chat",onClick:b=>{b.stopPropagation(),g()},title:x("cards.openTerminal"),children:x("cards.chat")}),w&&s.jsx("button",{className:"dash-card__action-btn dash-card__action-btn--danger",onClick:b=>{b.stopPropagation(),w()},title:x("cards.killAgent"),children:x("cards.stop")})]})]})});fs.displayName="AgentCard";const ws=({buildings:a,onSelectBuilding:A})=>{const{t:L}=ts(["dashboard"]),P=c.useMemo(()=>Array.from(a.values()).sort((n,g)=>n.name.localeCompare(g.name)),[a]);return s.jsxs("div",{className:"dashboard-view__buildings",children:[s.jsxs("div",{className:"dashboard-view__buildings-header",children:[s.jsx("span",{className:"dashboard-view__buildings-title",children:L("buildings.title")}),s.jsx("span",{className:"dashboard-view__buildings-count",children:P.length})]}),s.jsx("div",{className:"dashboard-view__buildings-row",children:P.map(n=>{const g=bs(n.status),h=Ls(n.type);return s.jsxs("button",{className:`dash-pill dash-pill--${g}`,onClick:()=>A==null?void 0:A(n.id),title:`${n.name} (${n.type}) - ${n.status}`,children:[s.jsx("span",{className:"dash-pill__icon",children:s.jsx(F,{name:h,size:14})}),s.jsx("span",{className:"dash-pill__name",children:n.name}),s.jsx("span",{className:`dash-pill__dot dash-pill__dot--${g}`})]},n.id)})})]})};ws.displayName="BuildingPills";function Ws({onSelectAgent:a,onFocusAgent:A,onKillAgent:L,onSelectBuilding:P,onOpenTerminal:n,onFocusZone:g}){const{t:h}=ts(["dashboard","common"]),w=Ps(),S=Ss(),x=Xs(),rs=Rs(),X=vs(),[N,B]=c.useState(""),[j,I]=c.useState("all"),[m,H]=c.useState("zone"),[b,T]=c.useState(new Set),[k,J]=c.useState(null),[ps,W]=c.useState(null),[R,Q]=c.useState(!1),[p,Z]=c.useState(null),K=c.useMemo(()=>{const e=Array.from(w.values());return{total:e.length,working:e.filter(i=>i.status==="working"||i.status==="waiting"||i.status==="waiting_permission").length,idle:e.filter(i=>i.status==="idle").length,error:e.filter(i=>i.status==="error"||i.status==="offline"||i.status==="orphaned").length}},[w]),ns=c.useMemo(()=>m==="zone"?Ys(w,x):m==="status"?Gs(w,X):Us(w),[w,x,m,X]),V=c.useMemo(()=>{const e=N.toLowerCase().trim(),i=ns.map(l=>({...l,agents:l.agents.filter(_=>{if(j==="working"){if(_.status!=="working"&&_.status!=="waiting"&&_.status!=="waiting_permission")return!1}else if(j==="error"&&_.status!=="error"&&_.status!=="offline"&&_.status!=="orphaned")return!1;return!(e&&!_.name.toLowerCase().includes(e)&&!_.class.toLowerCase().includes(e))})}));return m==="zone"?i:i.filter(l=>l.agents.length>0)},[ns,j,N,m]),O=c.useCallback(e=>e.area?`area:${e.area.id}`:`${m}:${e.label}`,[m]),C=c.useMemo(()=>{const e=[];return V.forEach(i=>{const l=O(i);if(b.has(l))return;const _=m==="status"?ms(i.agents,{prioritizeRecentlyIdle:!0}):_s(i.agents);e.push(..._)}),e},[V,b,m,O]),gs=c.useCallback(e=>{T(i=>{const l=new Set(i);return l.has(e)?l.delete(e):l.add(e),l})},[]),xs=c.useCallback(e=>{n==null||n(e)},[n]),js=c.useCallback(e=>{J(e)},[]),Ns=c.useCallback((e,i)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",W(i)},[]),ks=c.useCallback(()=>{W(null)},[]),Cs=c.useCallback(e=>{if(!k)return;if(e===null){const E=M.getState(),t=Array.from(E.areas.values()).find(r=>r.assignedAgentIds.includes(k.id));t&&M.unassignAgentFromArea(k.id,t.id),J(null),W(null);return}const i=x.get(e);if(!i)return;const l=Array.from(w.values()),_=Fs(i,l,k.position);M.updateAgent({...k,position:{...k.position,x:_.x,z:_.z}}),M.assignAgentToArea(k.id,e),J(null),W(null)},[k,x,w]);return c.useEffect(()=>{if(C.length===0){Q(!1),Z(null);return}R&&(!p||!C.some(e=>e.id===p))&&(Z(C[0].id),a==null||a(C[0].id))},[C,R,p,a]),c.useEffect(()=>{const e=t=>t instanceof HTMLElement?t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT"||t.isContentEditable:!1,i=t=>t instanceof HTMLElement?!!t.closest(".guake-terminal")||t.classList.contains("guake-input")||t.classList.contains("agent-panel-input"):!1,l=t=>{const r=Array.from(document.querySelectorAll(".dash-card[data-agent-id]")).find(z=>z.dataset.agentId===t);r==null||r.scrollIntoView({block:"nearest",inline:"nearest"})},_=(t,r)=>{var ds,os,cs,ls,us,hs;const z=Array.from(document.querySelectorAll(".dash-card[data-agent-id]")).map(d=>{const u=d.dataset.agentId;if(!u)return null;const y=d.getBoundingClientRect();return{id:u,centerX:y.left+y.width/2,centerY:y.top+y.height/2,height:y.height}}).filter(d=>d!==null).sort((d,u)=>d.centerY-u.centerY||d.centerX-u.centerX);if(z.length===0)return t;const ss=z.reduce((d,u)=>d+u.height,0)/z.length,es=Math.max(18,ss*.6),f=[];for(const d of z){const u=f[f.length-1];if(!u){f.push([{id:d.id,centerX:d.centerX,centerY:d.centerY}]);continue}const y=u.reduce((ys,As)=>ys+As.centerY,0)/u.length;Math.abs(d.centerY-y)<=es?u.push({id:d.id,centerX:d.centerX,centerY:d.centerY}):f.push([{id:d.id,centerX:d.centerX,centerY:d.centerY}])}f.forEach(d=>d.sort((u,y)=>u.centerX-y.centerX));const Y=f.findIndex(d=>d.some(u=>u.id===t));if(Y===-1)return((os=(ds=f[0])==null?void 0:ds[0])==null?void 0:os.id)??t;const $=f[Y],v=$.findIndex(d=>d.id===t);if(v===-1)return((ls=(cs=f[0])==null?void 0:cs[0])==null?void 0:ls.id)??t;if(r==="left")return((us=$[Math.max(0,v-1)])==null?void 0:us.id)??t;if(r==="right")return((hs=$[Math.min($.length-1,v+1)])==null?void 0:hs.id)??t;const q=r==="up"?Math.max(0,Y-1):Math.min(f.length-1,Y+1),o=f[q],G=$[v].centerX;let D=o[0],is=Math.abs(D.centerX-G);for(const d of o){const u=Math.abs(d.centerX-G);u<is&&(D=d,is=u)}return(D==null?void 0:D.id)??t},E=t=>{const r=M.getShortcuts(),z=r.find(o=>o.id==="dashboard-selector-toggle"),ss=r.find(o=>o.id==="dashboard-vim-left"),es=r.find(o=>o.id==="dashboard-vim-down"),f=r.find(o=>o.id==="dashboard-vim-up"),Y=r.find(o=>o.id==="dashboard-vim-right"),$=r.find(o=>o.id==="open-terminal"),v=M.getState();if(e(t.target))if(!v.terminalOpen&&i(t.target)&&document.activeElement instanceof HTMLElement)document.activeElement.blur();else return;if(U(t,z)){if(C.length===0)return;t.preventDefault(),t.stopPropagation(),Q(!0),Z(o=>{const G=o&&C.some(D=>D.id===o)?o:C[0].id;return a==null||a(G),window.setTimeout(()=>l(G),0),G});return}const q=U(t,ss)||t.key==="ArrowLeft"?"left":U(t,es)||t.key==="ArrowDown"?"down":U(t,f)||t.key==="ArrowUp"?"up":U(t,Y)||t.key==="ArrowRight"?"right":null;if(q&&R&&p){t.preventDefault(),t.stopPropagation();const o=_(p,q);o!==p&&(Z(o),a==null||a(o),window.setTimeout(()=>l(o),0));return}if(U(t,$)){if(v.terminalOpen)return;if(R&&p&&v.agents.has(p)){t.preventDefault(),n==null||n(p);return}if(v.selectedAgentIds.size===1){t.preventDefault();const o=Array.from(v.selectedAgentIds)[0];n==null||n(o);return}if(v.lastSelectedAgentId&&v.agents.has(v.lastSelectedAgentId)){t.preventDefault(),n==null||n(v.lastSelectedAgentId);return}}};return document.addEventListener("keydown",E,!0),()=>document.removeEventListener("keydown",E,!0)},[C,R,p,n,a]),c.useEffect(()=>{const e=document.activeElement;e instanceof HTMLElement&&e.closest(".guake-terminal")&&!M.getState().terminalOpen&&e.blur()},[]),s.jsxs("div",{className:"dashboard-view",children:[s.jsxs("div",{className:"dashboard-view__topbar",children:[s.jsxs("div",{className:"dashboard-view__metrics",children:[s.jsxs("button",{className:`dashboard-view__metric-btn ${j==="all"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("all"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.total}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:labels.agents")})]}),s.jsxs("button",{className:`dashboard-view__metric-btn dashboard-view__metric-btn--working ${j==="working"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("working"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.working}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.working")})]}),s.jsxs("button",{className:"dashboard-view__metric-btn dashboard-view__metric-btn--idle ",onClick:()=>I("all"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.idle}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.idle")})]}),s.jsxs("button",{className:`dashboard-view__metric-btn dashboard-view__metric-btn--error ${j==="error"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("error"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.error}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.error")})]})]}),s.jsx("input",{className:"dashboard-view__search",type:"text",placeholder:h("searchPlaceholder"),value:N,onChange:e=>B(e.target.value)})]}),s.jsxs("div",{className:"dashboard-view__grouping",children:[s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="zone"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>H("zone"),children:h("grouping.byZone")}),s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="status"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>H("status"),children:h("grouping.byStatus")}),s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="activity"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>H("activity"),children:h("grouping.byActivity")})]}),s.jsxs("div",{className:"dashboard-view__content",children:[V.map(e=>{const i=O(e),l=b.has(i),_=m==="status"?ms(e.agents,{prioritizeRecentlyIdle:!0}):_s(e.agents),E=e.agents.filter(r=>r.status==="working"||r.status==="waiting"||r.status==="waiting_permission").length,t=e.agents.filter(r=>X.has(r.id)).length;return s.jsxs("div",{className:`dashboard-view__zone ${ps===(e.area?e.area.id:null)&&k?"dashboard-view__zone--drag-over":""}`,onDragOver:r=>Ns(r,e.area?e.area.id:null),onDragLeave:ks,onDrop:()=>Cs(e.area?e.area.id:null),children:[s.jsxs("div",{className:"dashboard-view__zone-header",onClick:()=>gs(i),children:[s.jsxs("div",{className:"dashboard-view__zone-left",children:[s.jsx("span",{className:`dashboard-view__zone-chevron ${l?"dashboard-view__zone-chevron--collapsed":""}`,children:s.jsx(F,{name:"caret-down",size:12})}),s.jsx("span",{className:"dashboard-view__zone-dot",style:{backgroundColor:e.color}}),s.jsx("span",{className:"dashboard-view__zone-name",children:e.label}),s.jsxs("span",{className:"dashboard-view__zone-count",children:[h("agentCount",{count:e.agents.length}),E>0&&s.jsxs("span",{className:"dashboard-view__zone-working",children:[" · ",E," ",h("working")]}),t>0&&s.jsxs("span",{className:"dashboard-view__zone-unseen",children:[" · ",t," Unseen"]})]})]}),e.area&&g&&s.jsx("button",{className:"dashboard-view__zone-focus",onClick:r=>{r.stopPropagation(),g(e.area.id)},title:h("focusZone"),children:h("focusZone")})]}),!l&&s.jsx("div",{className:"dashboard-view__zone-grid",children:_.map(r=>s.jsx(fs,{agent:r,isSelected:rs.has(r.id),isKeyboardFocused:R&&p===r.id,onSelect:()=>{a==null||a(r.id),Q(!0),Z(r.id)},onDoubleClick:()=>xs(r.id),onChat:()=>n==null?void 0:n(r.id),onFocus:A?()=>A(r.id):void 0,onKill:L?()=>L(r.id):void 0,onDragStart:js},r.id))})]},i)}),V.length===0&&s.jsx("div",{className:"dashboard-view__empty",children:N?h("noAgentsMatching",{search:N}):h("noAgentsSpawned")}),S.size>0&&s.jsx(ws,{buildings:S,onSelectBuilding:P})]})]})}export{Ws as DashboardView};
1
+ import{a1 as as,u as ts,ai as vs,aj as bs,ak as zs,j as s,I as F,U as Is,al as Es,am as $s,an as Ds,ao as Ms,r as c,ap as Ls,a8 as Ss,a3 as Xs,N as Ps,B as Rs,aq as Ys,ar as Us,as as Gs,at as ms,au as _s,s as M,av as Fs,n as G}from"./main-BjcLCHKw.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const fs=as.memo(({agent:a,isSelected:A,isKeyboardFocused:L=!1,onSelect:S,onDoubleClick:n,onChat:g,onFocus:h,onKill:w,onDragStart:X})=>{const{t:x}=ts(["dashboard","common"]),P=vs().has(a.id),N=bs(a.status),B=zs(a),j=Ms(B),I=a.taskLabel?s.jsxs(s.Fragment,{children:[s.jsx(F,{name:"task",size:12})," ",a.taskLabel]}):a.currentTask||a.lastAssignedTask,m=a.status==="idle"&&a.lastActivity>0,[,H]=as.useState(0);return as.useEffect(()=>{if(!m)return;const b=window.setInterval(()=>H(T=>T+1),15e3);return()=>window.clearInterval(b)},[m]),s.jsxs("div",{className:`dash-card dash-card--${N} ${A?"dash-card--selected":""} ${L?"dash-card--keyboard-focused":""}`,"data-agent-id":a.id,onClick:S,onDoubleClick:b=>{b.stopPropagation(),n()},onDragStart:b=>{X==null||X(a),b.dataTransfer.effectAllowed="move"},draggable:!0,title:x("cards.doubleClickHint"),children:[s.jsxs("div",{className:"dash-card__row1",children:[s.jsx("span",{className:`dash-card__status-dot dash-card__status-dot--${N}`}),s.jsx("span",{className:"dash-card__name",children:a.name}),s.jsxs("span",{className:"dash-card__class",children:[s.jsx(Is,{agent:a,size:14})," ",a.class]}),s.jsxs("span",{className:`dash-card__provider dash-card__provider--${a.provider}`,children:[s.jsx(F,{name:a.provider==="codex"||a.provider==="opencode"?"status-pending":"robot",size:11,weight:a.provider==="codex"||a.provider==="opencode"?"fill":"regular",color:a.provider==="codex"?"#a16207":a.provider==="opencode"?"#4ade80":void 0})," ",a.provider]}),P&&s.jsx("span",{className:"dash-card__unseen-badge",title:"New output available - click to view",children:"!"})]}),s.jsxs("div",{className:"dash-card__row2",children:[s.jsx("span",{className:`dash-card__status dash-card__status--${N}`,children:P?"Unseen":a.status}),s.jsxs("div",{className:"dash-card__context",children:[s.jsx("div",{className:"dash-card__context-bar",children:s.jsx("div",{className:`dash-card__context-fill dash-card__context-fill--${j}`,style:{width:`${B}%`}})}),s.jsxs("span",{className:`dash-card__context-pct dash-card__context-pct--${j}`,children:[B,"%"]})]})]}),s.jsxs("div",{className:"dash-card__row3",children:[s.jsxs("span",{className:"dash-card__workdir",title:a.cwd,children:[s.jsx(F,{name:"folder",size:11})," ",a.cwd.split("/").pop()||a.cwd]}),m&&s.jsxs("span",{className:"dash-card__idle-time",style:{color:Ds(a.lastActivity)},title:$s(a.lastActivity),children:[s.jsx(F,{name:"status-waiting-input",size:10})," ",Es(a.lastActivity)]})]}),I&&s.jsx("div",{className:"dash-card__row4",children:s.jsx("span",{className:"dash-card__task",children:I})}),s.jsxs("div",{className:"dash-card__actions",children:[g&&s.jsx("button",{className:"dash-card__action-btn dash-card__action-btn--chat",onClick:b=>{b.stopPropagation(),g()},title:x("cards.openTerminal"),children:x("cards.chat")}),w&&s.jsx("button",{className:"dash-card__action-btn dash-card__action-btn--danger",onClick:b=>{b.stopPropagation(),w()},title:x("cards.killAgent"),children:x("cards.stop")})]})]})});fs.displayName="AgentCard";const ws=({buildings:a,onSelectBuilding:A})=>{const{t:L}=ts(["dashboard"]),S=c.useMemo(()=>Array.from(a.values()).sort((n,g)=>n.name.localeCompare(g.name)),[a]);return s.jsxs("div",{className:"dashboard-view__buildings",children:[s.jsxs("div",{className:"dashboard-view__buildings-header",children:[s.jsx("span",{className:"dashboard-view__buildings-title",children:L("buildings.title")}),s.jsx("span",{className:"dashboard-view__buildings-count",children:S.length})]}),s.jsx("div",{className:"dashboard-view__buildings-row",children:S.map(n=>{const g=bs(n.status),h=Ls(n.type);return s.jsxs("button",{className:`dash-pill dash-pill--${g}`,onClick:()=>A==null?void 0:A(n.id),title:`${n.name} (${n.type}) - ${n.status}`,children:[s.jsx("span",{className:"dash-pill__icon",children:s.jsx(F,{name:h,size:14})}),s.jsx("span",{className:"dash-pill__name",children:n.name}),s.jsx("span",{className:`dash-pill__dot dash-pill__dot--${g}`})]},n.id)})})]})};ws.displayName="BuildingPills";function Ws({onSelectAgent:a,onFocusAgent:A,onKillAgent:L,onSelectBuilding:S,onOpenTerminal:n,onFocusZone:g}){const{t:h}=ts(["dashboard","common"]),w=Ss(),X=Xs(),x=Ps(),rs=Rs(),P=vs(),[N,B]=c.useState(""),[j,I]=c.useState("all"),[m,H]=c.useState("zone"),[b,T]=c.useState(new Set),[k,J]=c.useState(null),[ps,W]=c.useState(null),[R,Q]=c.useState(!1),[p,Z]=c.useState(null),K=c.useMemo(()=>{const e=Array.from(w.values());return{total:e.length,working:e.filter(i=>i.status==="working"||i.status==="waiting"||i.status==="waiting_permission").length,idle:e.filter(i=>i.status==="idle").length,error:e.filter(i=>i.status==="error"||i.status==="offline"||i.status==="orphaned").length}},[w]),ns=c.useMemo(()=>m==="zone"?Ys(w,x):m==="status"?Us(w,P):Gs(w),[w,x,m,P]),V=c.useMemo(()=>{const e=N.toLowerCase().trim(),i=ns.map(l=>({...l,agents:l.agents.filter(_=>{if(j==="working"){if(_.status!=="working"&&_.status!=="waiting"&&_.status!=="waiting_permission")return!1}else if(j==="error"&&_.status!=="error"&&_.status!=="offline"&&_.status!=="orphaned")return!1;return!(e&&!_.name.toLowerCase().includes(e)&&!_.class.toLowerCase().includes(e))})}));return m==="zone"?i:i.filter(l=>l.agents.length>0)},[ns,j,N,m]),O=c.useCallback(e=>e.area?`area:${e.area.id}`:`${m}:${e.label}`,[m]),C=c.useMemo(()=>{const e=[];return V.forEach(i=>{const l=O(i);if(b.has(l))return;const _=m==="status"?ms(i.agents,{prioritizeRecentlyIdle:!0}):_s(i.agents);e.push(..._)}),e},[V,b,m,O]),gs=c.useCallback(e=>{T(i=>{const l=new Set(i);return l.has(e)?l.delete(e):l.add(e),l})},[]),xs=c.useCallback(e=>{n==null||n(e)},[n]),js=c.useCallback(e=>{J(e)},[]),Ns=c.useCallback((e,i)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",W(i)},[]),ks=c.useCallback(()=>{W(null)},[]),Cs=c.useCallback(e=>{if(!k)return;if(e===null){const E=M.getState(),t=Array.from(E.areas.values()).find(r=>r.assignedAgentIds.includes(k.id));t&&M.unassignAgentFromArea(k.id,t.id),J(null),W(null);return}const i=x.get(e);if(!i)return;const l=Array.from(w.values()),_=Fs(i,l,k.position);M.updateAgent({...k,position:{...k.position,x:_.x,z:_.z}}),M.assignAgentToArea(k.id,e),J(null),W(null)},[k,x,w]);return c.useEffect(()=>{if(C.length===0){Q(!1),Z(null);return}R&&(!p||!C.some(e=>e.id===p))&&(Z(C[0].id),a==null||a(C[0].id))},[C,R,p,a]),c.useEffect(()=>{const e=t=>t instanceof HTMLElement?t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT"||t.isContentEditable:!1,i=t=>t instanceof HTMLElement?!!t.closest(".guake-terminal")||t.classList.contains("guake-input")||t.classList.contains("agent-panel-input"):!1,l=t=>{const r=Array.from(document.querySelectorAll(".dash-card[data-agent-id]")).find(z=>z.dataset.agentId===t);r==null||r.scrollIntoView({block:"nearest",inline:"nearest"})},_=(t,r)=>{var ds,os,cs,ls,us,hs;const z=Array.from(document.querySelectorAll(".dash-card[data-agent-id]")).map(d=>{const u=d.dataset.agentId;if(!u)return null;const y=d.getBoundingClientRect();return{id:u,centerX:y.left+y.width/2,centerY:y.top+y.height/2,height:y.height}}).filter(d=>d!==null).sort((d,u)=>d.centerY-u.centerY||d.centerX-u.centerX);if(z.length===0)return t;const ss=z.reduce((d,u)=>d+u.height,0)/z.length,es=Math.max(18,ss*.6),f=[];for(const d of z){const u=f[f.length-1];if(!u){f.push([{id:d.id,centerX:d.centerX,centerY:d.centerY}]);continue}const y=u.reduce((ys,As)=>ys+As.centerY,0)/u.length;Math.abs(d.centerY-y)<=es?u.push({id:d.id,centerX:d.centerX,centerY:d.centerY}):f.push([{id:d.id,centerX:d.centerX,centerY:d.centerY}])}f.forEach(d=>d.sort((u,y)=>u.centerX-y.centerX));const Y=f.findIndex(d=>d.some(u=>u.id===t));if(Y===-1)return((os=(ds=f[0])==null?void 0:ds[0])==null?void 0:os.id)??t;const $=f[Y],v=$.findIndex(d=>d.id===t);if(v===-1)return((ls=(cs=f[0])==null?void 0:cs[0])==null?void 0:ls.id)??t;if(r==="left")return((us=$[Math.max(0,v-1)])==null?void 0:us.id)??t;if(r==="right")return((hs=$[Math.min($.length-1,v+1)])==null?void 0:hs.id)??t;const q=r==="up"?Math.max(0,Y-1):Math.min(f.length-1,Y+1),o=f[q],U=$[v].centerX;let D=o[0],is=Math.abs(D.centerX-U);for(const d of o){const u=Math.abs(d.centerX-U);u<is&&(D=d,is=u)}return(D==null?void 0:D.id)??t},E=t=>{const r=M.getShortcuts(),z=r.find(o=>o.id==="dashboard-selector-toggle"),ss=r.find(o=>o.id==="dashboard-vim-left"),es=r.find(o=>o.id==="dashboard-vim-down"),f=r.find(o=>o.id==="dashboard-vim-up"),Y=r.find(o=>o.id==="dashboard-vim-right"),$=r.find(o=>o.id==="open-terminal"),v=M.getState();if(e(t.target))if(!v.terminalOpen&&i(t.target)&&document.activeElement instanceof HTMLElement)document.activeElement.blur();else return;if(G(t,z)){if(C.length===0)return;t.preventDefault(),t.stopPropagation(),Q(!0),Z(o=>{const U=o&&C.some(D=>D.id===o)?o:C[0].id;return a==null||a(U),window.setTimeout(()=>l(U),0),U});return}const q=G(t,ss)||t.key==="ArrowLeft"?"left":G(t,es)||t.key==="ArrowDown"?"down":G(t,f)||t.key==="ArrowUp"?"up":G(t,Y)||t.key==="ArrowRight"?"right":null;if(q&&R&&p){t.preventDefault(),t.stopPropagation();const o=_(p,q);o!==p&&(Z(o),a==null||a(o),window.setTimeout(()=>l(o),0));return}if(G(t,$)){if(v.terminalOpen)return;if(R&&p&&v.agents.has(p)){t.preventDefault(),n==null||n(p);return}if(v.selectedAgentIds.size===1){t.preventDefault();const o=Array.from(v.selectedAgentIds)[0];n==null||n(o);return}if(v.lastSelectedAgentId&&v.agents.has(v.lastSelectedAgentId)){t.preventDefault(),n==null||n(v.lastSelectedAgentId);return}}};return document.addEventListener("keydown",E,!0),()=>document.removeEventListener("keydown",E,!0)},[C,R,p,n,a]),c.useEffect(()=>{const e=document.activeElement;e instanceof HTMLElement&&e.closest(".guake-terminal")&&!M.getState().terminalOpen&&e.blur()},[]),s.jsxs("div",{className:"dashboard-view",children:[s.jsxs("div",{className:"dashboard-view__topbar",children:[s.jsxs("div",{className:"dashboard-view__metrics",children:[s.jsxs("button",{className:`dashboard-view__metric-btn ${j==="all"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("all"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.total}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:labels.agents")})]}),s.jsxs("button",{className:`dashboard-view__metric-btn dashboard-view__metric-btn--working ${j==="working"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("working"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.working}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.working")})]}),s.jsxs("button",{className:"dashboard-view__metric-btn dashboard-view__metric-btn--idle ",onClick:()=>I("all"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.idle}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.idle")})]}),s.jsxs("button",{className:`dashboard-view__metric-btn dashboard-view__metric-btn--error ${j==="error"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("error"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.error}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.error")})]})]}),s.jsx("input",{className:"dashboard-view__search",type:"text",placeholder:h("searchPlaceholder"),value:N,onChange:e=>B(e.target.value)})]}),s.jsxs("div",{className:"dashboard-view__grouping",children:[s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="zone"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>H("zone"),children:h("grouping.byZone")}),s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="status"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>H("status"),children:h("grouping.byStatus")}),s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="activity"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>H("activity"),children:h("grouping.byActivity")})]}),s.jsxs("div",{className:"dashboard-view__content",children:[V.map(e=>{const i=O(e),l=b.has(i),_=m==="status"?ms(e.agents,{prioritizeRecentlyIdle:!0}):_s(e.agents),E=e.agents.filter(r=>r.status==="working"||r.status==="waiting"||r.status==="waiting_permission").length,t=e.agents.filter(r=>P.has(r.id)).length;return s.jsxs("div",{className:`dashboard-view__zone ${ps===(e.area?e.area.id:null)&&k?"dashboard-view__zone--drag-over":""}`,onDragOver:r=>Ns(r,e.area?e.area.id:null),onDragLeave:ks,onDrop:()=>Cs(e.area?e.area.id:null),children:[s.jsxs("div",{className:"dashboard-view__zone-header",onClick:()=>gs(i),children:[s.jsxs("div",{className:"dashboard-view__zone-left",children:[s.jsx("span",{className:`dashboard-view__zone-chevron ${l?"dashboard-view__zone-chevron--collapsed":""}`,children:s.jsx(F,{name:"caret-down",size:12})}),s.jsx("span",{className:"dashboard-view__zone-dot",style:{backgroundColor:e.color}}),s.jsx("span",{className:"dashboard-view__zone-name",children:e.label}),s.jsxs("span",{className:"dashboard-view__zone-count",children:[h("agentCount",{count:e.agents.length}),E>0&&s.jsxs("span",{className:"dashboard-view__zone-working",children:[" · ",E," ",h("working")]}),t>0&&s.jsxs("span",{className:"dashboard-view__zone-unseen",children:[" · ",t," Unseen"]})]})]}),e.area&&g&&s.jsx("button",{className:"dashboard-view__zone-focus",onClick:r=>{r.stopPropagation(),g(e.area.id)},title:h("focusZone"),children:h("focusZone")})]}),!l&&s.jsx("div",{className:"dashboard-view__zone-grid",children:_.map(r=>s.jsx(fs,{agent:r,isSelected:rs.has(r.id),isKeyboardFocused:R&&p===r.id,onSelect:()=>{a==null||a(r.id),Q(!0),Z(r.id)},onDoubleClick:()=>xs(r.id),onChat:()=>n==null?void 0:n(r.id),onFocus:A?()=>A(r.id):void 0,onKill:L?()=>L(r.id):void 0,onDragStart:js},r.id))})]},i)}),V.length===0&&s.jsx("div",{className:"dashboard-view__empty",children:N?h("noAgentsMatching",{search:N}):h("noAgentsSpawned")}),X.size>0&&s.jsx(ws,{buildings:X,onSelectBuilding:S})]})]})}export{Ws as DashboardView};
@@ -0,0 +1 @@
1
+ import{r as d,aL as re,aM as ke,j as e,I as P,u as G,aN as Ce,ap as Ae,f as pe,s as v,aO as _e,k as Be,l as J,aP as U,aQ as De,aE as Re,aR as Ue,C as ge,aS as M,aB as oe,aT as Ve,aU as Ke,aV as qe,aW as Me,aX as Ge,ax as He,E as We,S as ne,aY as Ye,aZ as Je,az as Ze,a_ as de,G as ie,aI as Xe,a$ as me,b0 as Qe}from"./main-BjcLCHKw.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const he="deivid11/tide-commander",es=`https://api.github.com/repos/${he}/releases/latest`,ss=`https://api.github.com/repos/${he}/releases?per_page=3`,ts=3600*1e3,we="app_update_dismissed_version",Se="1.75.0";function as(){var k,C;const[s,i]=d.useState({isChecking:!1,updateAvailable:!1,updateInfo:null,recentReleases:[],error:null,currentVersion:Se}),n=((C=(k=re)==null?void 0:k.getPlatform)==null?void 0:C.call(k))==="android"||!1,o=r=>r.replace(/^v/,"").split(".").map(x=>parseInt(x,10)||0),m=(r,g)=>{const x=o(r),S=o(g),y=Math.max(x.length,S.length);for(let c=0;c<y;c++){const L=x[c]||0,R=S[c]||0;if(L>R)return 1;if(L<R)return-1}return 0},p=async r=>{var x,S;if(re&&ke&&((S=(x=re).isNativePlatform)==null?void 0:S.call(x))===!0){const y=await ke.get({url:r,headers:{Accept:"application/vnd.github.v3+json"}});return{data:y.data,status:y.status}}else{const y=await fetch(r,{headers:{Accept:"application/vnd.github.v3+json"}});return y.ok?{data:await y.json(),status:y.status}:{data:null,status:y.status}}},l=d.useCallback(async(r=!1)=>{i(g=>({...g,isChecking:!0,error:null}));try{const[g,x]=await Promise.all([p(es),p(ss)]);if(g.status!==200)throw new Error(`GitHub API error: ${g.status}`);const S=g.data,y=S.tag_name;let c=[];x.status===200&&x.data&&(c=x.data.map(w=>({version:w.tag_name,name:w.name,publishedAt:w.published_at,releaseUrl:w.html_url})));const L=localStorage.getItem(we);if(!r&&L===y)return i(w=>({...w,isChecking:!1,updateAvailable:!1,recentReleases:c})),null;if(!(m(y,Se)>0))return i(w=>({...w,isChecking:!1,updateAvailable:!1,recentReleases:c})),null;const $=S.assets.find(w=>w.name.endsWith(".apk")&&w.content_type==="application/vnd.android.package-archive"),b={version:y,name:S.name,changelog:S.body,releaseUrl:S.html_url,apkUrl:($==null?void 0:$.browser_download_url)||null,apkSize:($==null?void 0:$.size)||null,publishedAt:S.published_at};return i(w=>({...w,isChecking:!1,updateAvailable:!0,updateInfo:b,recentReleases:c})),b}catch(g){const x=g instanceof Error?g.message:"Failed to check for updates";return i(S=>({...S,isChecking:!1,error:x})),null}},[]),a=d.useCallback(async()=>{var r,g,x;if(!((r=s.updateInfo)!=null&&r.apkUrl)){(g=s.updateInfo)!=null&&g.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}if(!n){(x=s.updateInfo)!=null&&x.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}try{window.open(s.updateInfo.apkUrl,"_system"),i(S=>({...S,error:null}))}catch(S){const y=S instanceof Error?S.message:"Failed to open download";i(c=>({...c,error:y}))}},[s.updateInfo,n]),u=d.useCallback(()=>{s.updateInfo&&localStorage.setItem(we,s.updateInfo.version),i(r=>({...r,updateAvailable:!1,updateInfo:null}))},[s.updateInfo]),A=d.useCallback(()=>{var r;(r=s.updateInfo)!=null&&r.releaseUrl?window.open(s.updateInfo.releaseUrl,"_blank"):window.open(`https://github.com/${he}/releases`,"_blank")},[s.updateInfo]);return d.useEffect(()=>{if(!n)return;const r=setTimeout(()=>{l()},5e3),g=setInterval(()=>{l()},ts);return()=>{clearTimeout(r),clearInterval(g)}},[n,l]),{...s,isAndroid:n,checkForUpdate:l,downloadAndInstall:a,dismissUpdate:u,openReleasePage:A}}const Te="tide-toolbox-collapse";function ns(s,i){try{const n=localStorage.getItem(`${Te}-${s}`);if(n!==null)return n==="true"}catch{}return i}function os(s,i){try{localStorage.setItem(`${Te}-${s}`,String(i))}catch{}}function O({title:s,storageKey:i,defaultOpen:n=!1,forceOpen:o=!1,children:m,headerExtra:p}){const[l,a]=d.useState(()=>i?ns(i,n):n),u=()=>{const k=!l;a(k),i&&os(i,k)},A=o||l;return e.jsxs("div",{className:`collapsible-section ${A?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:u,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[p,e.jsx("span",{className:"collapsible-arrow",children:e.jsx(P,{name:A?"caret-down":"caret-right",size:10})})]})]}),A&&e.jsx("div",{className:"collapsible-content",children:m})]})}function is({area:s,isSelected:i,onClick:n,onDelete:o}){const{t:m}=G(["config","common"]),p=s.assignedAgentIds.length,l=s.type==="rectangle"?m("config:areas.rect"):m("config:areas.circle");return e.jsxs("div",{className:`area-item ${i?"selected":""}`,onClick:n,children:[e.jsx("div",{className:"area-color-dot",style:{backgroundColor:s.color}}),e.jsxs("div",{className:"area-info",children:[e.jsx("div",{className:"area-name",children:s.name}),e.jsxs("div",{className:"area-meta",children:[l," ",p>0&&`• ${p} ${p>1?m("common:labels.agents").toLowerCase():m("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:o,title:m("config:areas.deleteArea"),children:"×"})]})}function ls({building:s,isSelected:i,onClick:n,onEdit:o}){var a;const{t:m}=G(["config"]),p=((a=s.pm2Status)==null?void 0:a.ports)||[],l=(u,A)=>{u.stopPropagation(),window.open(`http://localhost:${A}`,"_blank")};return e.jsxs("div",{className:`building-item ${i?"selected":""}`,onClick:n,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:Ce[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(P,{name:Ae(s.type),size:16})}),e.jsxs("div",{className:"building-info",children:[e.jsx("div",{className:"building-name",children:s.name}),e.jsxs("div",{className:"building-meta",children:[s.type,p.length>0&&e.jsx("span",{className:"building-ports",children:p.map(u=>e.jsxs("a",{href:`http://localhost:${u}`,className:"building-port-link",onClick:A=>l(A,u),title:`Open :${u}`,children:[":",u]},u))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:u=>{u.stopPropagation(),o()},title:m("config:buildings.editBuilding"),children:e.jsx(P,{name:"gear",size:14})})]})}function cs({building:s,onClose:i,onOpenModal:n}){var A,k,C,r,g,x,S,y;const{t:o}=G(["config","common"]),{buildingLogs:m}=pe(),p=v.getBuildingLogs(s.id),l=_e[s.style||"server-rack"],a=c=>{v.sendBuildingCommand(s.id,c)},u=c=>{window.open(c,"_blank")};return e.jsxs("div",{className:"building-editor",children:[e.jsxs("div",{className:"building-editor-header",children:[e.jsxs("div",{className:"building-editor-title-row",children:[e.jsx("span",{className:"building-editor-icon",children:e.jsx(P,{name:Ae(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:Ce[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:i,children:"×"})]}),e.jsx("div",{className:"building-editor-section",children:e.jsxs("div",{className:"building-editor-info-grid",children:[e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("common:labels.type")}),e.jsx("span",{className:"building-editor-info-value",children:s.type})]}),e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.style")}),e.jsx("span",{className:"building-editor-info-value",children:l.label})]}),s.cwd&&e.jsxs("div",{className:"building-editor-info-item building-editor-info-wide",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.directory")}),e.jsx("span",{className:"building-editor-info-value building-editor-cwd",title:s.cwd,children:s.cwd.split("/").pop()||s.cwd})]})]})}),s.type==="server"&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.actions")}),e.jsxs("div",{className:"building-editor-actions",children:[e.jsxs("button",{className:"building-editor-action-btn start",onClick:()=>a("start"),disabled:!((A=s.commands)!=null&&A.start)||s.status==="running",title:((k=s.commands)==null?void 0:k.start)||o("config:buildings.noStartCommand"),children:[e.jsx(P,{name:"play",size:12})," ",o("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>a("stop"),disabled:!((C=s.commands)!=null&&C.stop)||s.status==="stopped",title:((r=s.commands)==null?void 0:r.stop)||o("config:buildings.noStopCommand"),children:[e.jsx(P,{name:"stop",size:12,weight:"fill"})," ",o("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>a("restart"),disabled:!((g=s.commands)!=null&&g.restart),title:((x=s.commands)==null?void 0:x.restart)||o("config:buildings.noRestartCommand"),children:[e.jsx(P,{name:"refresh",size:12})," ",o("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>a("healthCheck"),disabled:!((S=s.commands)!=null&&S.healthCheck),title:((y=s.commands)==null?void 0:y.healthCheck)||o("config:buildings.noHealthCheck"),children:[e.jsx(P,{name:"heart",size:12})," Health"]})]})]}),s.urls&&s.urls.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.links")}),e.jsx("div",{className:"building-editor-links",children:s.urls.map((c,L)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>u(c.url),title:c.url,children:[e.jsx(P,{name:"link",size:12})," ",c.label||c.url]},L))})]}),p.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsxs("div",{className:"building-editor-section-title",children:[o("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>v.clearBuildingLogs(s.id),title:o("common:buttons.clear"),children:o("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:p.slice(-5).map((c,L)=>e.jsx("div",{className:"building-editor-log-entry",children:c},L))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:n,children:[e.jsx(P,{name:"gear",size:12})," ",o("config:buildings.fullSettings")]})})]})}async function rs(s,i){const n=U(),o=await fetch(J(`/api/areas/${s}/logo`),{method:"POST",headers:{"Content-Type":i.type||"image/png","X-Filename":encodeURIComponent(i.name),...n?{Authorization:`Bearer ${n}`}:{}},body:i});if(!o.ok){const m=await o.json().catch(()=>({error:o.statusText}));throw new Error(m.error||`Upload failed: ${o.statusText}`)}return o.json()}async function ds(s){const i=U(),n=await fetch(J(`/api/areas/${s}/logo`),{method:"DELETE",headers:{...i?{Authorization:`Bearer ${i}`}:{}}});if(!n.ok)throw new Error(`Failed to delete logo: ${n.statusText}`)}function ms(s){return Be(J(`/api/areas/logos/${s}`))}const us=[{key:"center",labelKey:"posCenter"},{key:"top-left",labelKey:"posTopLeft"},{key:"top-right",labelKey:"posTopRight"},{key:"bottom-left",labelKey:"posBottomLeft"},{key:"bottom-right",labelKey:"posBottomRight"}];function gs({area:s,onClose:i,onOpenFolder:n}){var Q;const{t:o}=G(["config","common"]),[m,p]=d.useState(s.name),[l,a]=d.useState(s.prompt||""),[u,A]=d.useState(!1),[k,C]=d.useState(""),[r,g]=d.useState(!1),x=d.useRef(null);d.useEffect(()=>{p(s.name)},[s.id,s.name]),d.useEffect(()=>{a(s.prompt||"")},[s.id,s.prompt]);const S=f=>{const T=f.target.value;p(T),v.updateArea(s.id,{name:T})},y=f=>{v.updateArea(s.id,{color:f})},c=f=>{const T=f.target.value;a(T),v.updateArea(s.id,{prompt:T})},L=()=>{k.trim()&&(v.addDirectoryToArea(s.id,k.trim()),C(""),A(!1))},R=(f,T)=>{T.stopPropagation(),v.removeDirectoryFromArea(s.id,f)},$=()=>{v.bringAreaToFront(s.id)},b=()=>{v.sendAreaToBack(s.id)},w=d.useCallback(()=>{let f=2,T=2;s.type==="rectangle"&&s.width&&s.height?(f=s.width,T=s.height):s.type==="circle"&&s.radius&&(f=s.radius*1.414,T=s.radius*1.414);const D=Math.min(f,T)*.4;return{width:Math.round(D*10)/10,height:Math.round(D*10)/10}},[s.type,s.width,s.height,s.radius]),Z=async f=>{var D;const T=(D=f.target.files)==null?void 0:D[0];if(T){g(!0);try{const h=await rs(s.id,T),E=w();v.updateArea(s.id,{logo:{filename:h.filename,position:"center",width:E.width,height:E.height,keepAspectRatio:!0,opacity:.8}})}catch(h){console.error("Failed to upload logo:",h)}finally{g(!1),x.current&&(x.current.value="")}}},H=async()=>{try{await ds(s.id),v.updateArea(s.id,{logo:void 0})}catch(f){console.error("Failed to remove logo:",f)}},K=f=>{s.logo&&v.updateArea(s.id,{logo:{...s.logo,position:f}})},X=f=>{if(!s.logo)return;const T=parseFloat(f.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const D=s.logo.height/s.logo.width;v.updateArea(s.id,{logo:{...s.logo,width:T,height:Math.round(T*D*10)/10}})}else v.updateArea(s.id,{logo:{...s.logo,width:T}})},I=f=>{if(!s.logo)return;const T=parseFloat(f.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const D=s.logo.width/s.logo.height;v.updateArea(s.id,{logo:{...s.logo,height:T,width:Math.round(T*D*10)/10}})}else v.updateArea(s.id,{logo:{...s.logo,height:T}})},W=()=>{s.logo&&v.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},te=f=>{s.logo&&v.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(f.target.value)}})};return e.jsxs("div",{className:"area-editor",children:[e.jsxs("div",{className:"area-editor-header",children:[e.jsx("span",{className:"area-editor-title",children:o("config:areas.editArea")}),e.jsx("button",{className:"area-editor-close",onClick:i,children:"×"})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:m,onChange:S,placeholder:o("config:areas.areaName")})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.color")}),e.jsx("div",{className:"color-picker-row",children:De.map(f=>e.jsx("div",{className:`color-swatch ${s.color===f?"selected":""}`,style:{backgroundColor:f},onClick:()=>y(f)},f))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:$,title:o("config:areas.bringToFront"),children:[e.jsx(P,{name:"arrow-up",size:12})," ",o("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:b,title:o("config:areas.sendToBack"),children:[e.jsx(P,{name:"arrow-down",size:12})," ",o("config:areas.back")]})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.logo")}),e.jsxs("div",{className:"area-logo-section",children:[(Q=s.logo)!=null&&Q.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:ms(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:H,children:o("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var f;return(f=x.current)==null?void 0:f.click()},disabled:r,children:r?"...":e.jsx(P,{name:"refresh",size:12})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:us.map(({key:f,labelKey:T})=>{var D;return e.jsx("button",{className:`area-logo-pos-btn ${((D=s.logo)==null?void 0:D.position)===f?"active":""}`,onClick:()=>K(f),children:o(`config:areas.${T}`)},f)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoSize")}),e.jsxs("div",{className:"area-logo-size-row",children:[e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:X,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoHeight")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.height,onChange:I,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-aspect-label",title:o("config:areas.keepAspectRatio"),children:[e.jsx("input",{type:"checkbox",checked:s.logo.keepAspectRatio,onChange:W}),o("config:areas.keepAspectRatio")]})]})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoOpacity")}),e.jsxs("div",{className:"area-logo-opacity-row",children:[e.jsx("input",{type:"range",min:0,max:1,step:.05,value:s.logo.opacity??.8,onChange:te,className:"area-logo-opacity-slider"}),e.jsxs("span",{className:"area-logo-opacity-value",children:[Math.round((s.logo.opacity??.8)*100),"%"]})]})]})]}):e.jsx("button",{className:"area-logo-upload-btn",onClick:()=>{var f;return(f=x.current)==null?void 0:f.click()},disabled:r,children:r?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:x,type:"file",accept:"image/*",style:{display:"none"},onChange:Z})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(f=>e.jsxs("div",{className:"area-folder-item",title:f,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>n==null?void 0:n(s.id),title:o("config:areas.openFolder"),children:e.jsx(P,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:f.split("/").pop()||f}),e.jsx("button",{className:"area-folder-remove",onClick:T=>R(f,T),title:o("config:areas.removeFolder"),children:"×"})]},f)),u?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(Re,{value:k,onChange:C,onSubmit:L,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:L,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>A(!0),children:o("config:areas.addFolder")})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.prompt","Prompt")}),e.jsx("textarea",{className:"area-editor-input",value:l,onChange:c,placeholder:o("config:areas.promptPlaceholder","System prompt for agents in this area..."),rows:4,style:{resize:"vertical",fontFamily:"monospace",fontSize:12}}),e.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:4},children:o("config:areas.promptHint","This prompt is injected into agents assigned to this area. Takes effect on next context refresh.")})]}),s.assignedAgentIds.length>0&&e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:o("config:areas.rightClickUnassign")})]})]})}function ps(){const{t:s}=G(["config","common"]),i=Ue(),[n,o]=d.useState(!1),[m,p]=d.useState(null),[l,a]=d.useState({name:"",key:"",value:"",description:""}),[u,A]=d.useState(null),k=()=>{o(!0),p(null),a({name:"",key:"",value:"",description:""})},C=c=>{p(c.id),o(!1),a({name:c.name,key:c.key,value:c.value,description:c.description||""})},r=()=>{o(!1),p(null),a({name:"",key:"",value:"",description:""})},g=()=>{!l.name.trim()||!l.key.trim()||(m?v.updateSecret(m,{name:l.name.trim(),key:l.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:l.value,description:l.description.trim()||void 0}):v.createSecret({name:l.name.trim(),key:l.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:l.value,description:l.description.trim()||void 0}),r())},x=c=>{A(c)},S=()=>{u&&(v.deleteSecret(u),m===u&&r())},y=c=>{navigator.clipboard.writeText(`{{${c}}}`)};return e.jsxs("div",{className:"secrets-section",children:[e.jsx("div",{className:"secrets-description",children:s("config:secrets.description",{placeholder:"{{KEY}}"})}),e.jsx("div",{className:"secrets-list",children:i.length===0&&!n?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):i.map(c=>e.jsxs("div",{className:`secret-item ${m===c.id?"editing":""}`,children:[e.jsxs("div",{className:"secret-item-header",children:[e.jsxs("div",{className:"secret-item-info",children:[e.jsx("span",{className:"secret-item-name",children:c.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>y(c.key),title:s("config:secrets.copyPlaceholder"),children:`{{${c.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>C(c),title:s("common:buttons.edit"),children:e.jsx(P,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>x(c.id),title:s("common:buttons.delete"),children:"×"})]})]}),c.description&&e.jsx("div",{className:"secret-item-description",children:c.description})]},c.id))}),(n||m)&&e.jsxs("div",{className:"secret-form",children:[e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.name")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.namePlaceholder"),value:l.name,onChange:c=>a({...l,name:c.target.value}),autoFocus:!0})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:"Key"}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.keyPlaceholder"),value:l.key,onChange:c=>a({...l,key:c.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${l.key||"KEY"}}}`})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("config:secrets.secretValue")}),e.jsx("input",{type:"password",className:"secret-form-input",placeholder:s("config:secrets.valuePlaceholder"),value:l.value,onChange:c=>a({...l,value:c.target.value})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.description")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.descriptionPlaceholder"),value:l.description,onChange:c=>a({...l,description:c.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:r,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:g,disabled:!l.name.trim()||!l.key.trim(),children:s(m?"config:secrets.update":"common:buttons.add")})]})]}),!n&&!m&&e.jsx("button",{className:"secrets-add-btn",onClick:k,children:s("config:secrets.addSecret")}),e.jsx(ge,{isOpen:u!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:S,onClose:()=>A(null)})]})}async function hs(){const s=U(),i=await fetch(`${M()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!i.ok)throw new Error(`Failed to fetch system prompt: ${i.statusText}`);return(await i.json()).prompt||""}async function fs(s){const i=U(),n=await fetch(`${M()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({prompt:s})});if(!n.ok)throw new Error(`Failed to update system prompt: ${n.statusText}`)}async function xs(){const s=U(),i=await fetch(`${M()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!i.ok)throw new Error(`Failed to clear system prompt: ${i.statusText}`)}async function bs(){const s=U(),i=await fetch(`${M()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!i.ok)throw new Error(`Failed to fetch echo prompt setting: ${i.statusText}`);return(await i.json()).enabled||!1}async function js(s){const i=U(),n=await fetch(`${M()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({enabled:s})});if(!n.ok)throw new Error(`Failed to update echo prompt setting: ${n.statusText}`)}async function vs(){const s=U(),i=await fetch(`${M()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!i.ok)throw new Error(`Failed to fetch codex binary path: ${i.statusText}`);return(await i.json()).path||""}async function Ns(s){const i=U(),n=await fetch(`${M()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({path:s})});if(!n.ok)throw new Error(`Failed to update codex binary path: ${n.statusText}`)}async function ys(){const s=U(),i=await fetch(`${M()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!i.ok)throw new Error(`Failed to fetch tmux mode setting: ${i.statusText}`);return(await i.json()).enabled||!1}async function ks(s){const i=U(),n=await fetch(`${M()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({enabled:s})});if(!n.ok)throw new Error(`Failed to update tmux mode setting: ${n.statusText}`)}async function ws(){const s=U(),i=await fetch(`${M()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!i.ok)throw new Error(`Failed to fetch backup status: ${i.statusText}`);return i.json()}async function Ss(s){const i=U(),n=await fetch(`${M()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({enabled:s})});if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||`Failed to update backup setting: ${n.statusText}`)}return n.json()}function Cs({checked:s,onChange:i,disabled:n}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:n,onChange:o=>i(o.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function As(){const{t:s}=G(["config","common"]),[i,n]=d.useState([]),[o,m]=d.useState(new Set),[p,l]=d.useState(new Set),[a,u]=d.useState(!1),[A,k]=d.useState(!1),[C,r]=d.useState(null),[g,x]=d.useState(null),[S,y]=d.useState(null),[c,L]=d.useState(null),[R,$]=d.useState(!1),[b,w]=d.useState(null);d.useEffect(()=>{oe(J("/api/config/categories")).then(h=>h.json()).then(h=>{const E=Array.isArray(h)?h:[];n(E),m(new Set(E.map(F=>F.id)))}).catch(h=>console.error("Failed to fetch config categories:",h))},[]),d.useEffect(()=>{ws().then(L).catch(h=>{console.error("Failed to fetch backup status:",h),w(h.message||"Failed to fetch backup status")})},[]);const Z=async h=>{if(!R){$(!0),w(null);try{const E=await Ss(h);L(E)}catch(E){w(E.message||"Failed to update backup setting")}finally{$(!1)}}},H=h=>{m(E=>{const F=new Set(E);return F.has(h)?F.delete(h):F.add(h),F})},K=h=>{l(E=>{const F=new Set(E);return F.has(h)?F.delete(h):F.add(h),F})},X=()=>m(new Set(i.map(h=>h.id))),I=()=>m(new Set),W=()=>{g&&l(new Set(g.categories.map(h=>h.id)))},te=()=>l(new Set),Q=async()=>{var h;if(o.size!==0){u(!0),y(null);try{const E=Array.from(o).join(","),F=await oe(J(`/api/config/export?categories=${E}`));if(!F.ok)throw new Error("Export failed");const Y=await F.blob(),q=window.URL.createObjectURL(Y),j=document.createElement("a");j.href=q;const B=F.headers.get("Content-Disposition"),le=((h=B==null?void 0:B.match(/filename="(.+)"/))==null?void 0:h[1])||"tide-commander-config.zip";j.download=le,document.body.appendChild(j),j.click(),document.body.removeChild(j),window.URL.revokeObjectURL(q),y({type:"success",text:s("config:data.exportSuccess")})}catch(E){y({type:"error",text:E.message||"Export failed"})}finally{u(!1)}}},f=async h=>{var F;const E=(F=h.target.files)==null?void 0:F[0];if(E){r(E),y(null),x(null),l(new Set);try{const Y=await oe(J("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await E.arrayBuffer()});if(!Y.ok){const B=await Y.json();throw new Error(B.error||"Failed to preview config file")}const q=await Y.json(),j=Array.isArray(q.categories)?q.categories:[];x({...q,categories:j}),l(new Set(j.map(B=>B.id)))}catch(Y){y({type:"error",text:Y.message||"Failed to read config file"}),r(null)}}},T=async()=>{if(!(!C||p.size===0)){k(!0),y(null);try{const h=Array.from(p).join(","),E=await oe(J(`/api/config/import?categories=${h}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await C.arrayBuffer()}),F=await E.json();if(!E.ok)throw new Error(F.error||"Import failed");y({type:"success",text:F.message||s("config:data.importSuccess")}),r(null),x(null),l(new Set)}catch(h){y({type:"error",text:h.message||"Import failed"})}finally{k(!1)}}},D=()=>{r(null),x(null),l(new Set),y(null)};return e.jsxs("div",{className:"data-section",children:[S&&e.jsx("div",{className:`data-message data-message-${S.type}`,children:S.text}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:"Hourly Backups"}),e.jsx(Cs,{checked:!!(c!=null&&c.enabled),disabled:R||!c,onChange:Z})]}),e.jsxs("div",{className:"data-backup-info",children:[c?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:c.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!c.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:c.scriptPath})]}),c.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(c.lastRunAt).toLocaleString(),c.lastRunOk===!0&&" — ok",c.lastRunOk===!1&&c.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",c.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),b&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:b})]})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:s("config:data.exportData")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:X,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:I,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:i.map(h=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(h.id),onChange:()=>H(h.id)}),e.jsx("span",{className:"data-category-name",children:h.name})]},h.id))}),e.jsx("button",{className:"data-action-btn export",onClick:Q,disabled:a||o.size===0,children:a?s("config:data.exporting"):s("config:data.exportCount",{count:o.size})})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsx("div",{className:"data-subsection-header",children:e.jsx("span",{className:"data-subsection-title",children:s("config:data.importData")})}),C?g?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:C.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(g.exportedAt).toLocaleDateString()]})]}),e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-subtitle",children:s("config:data.selectToImport")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:W,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:te,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:g.categories.map(h=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:p.has(h.id),onChange:()=>K(h.id)}),e.jsx("span",{className:"data-category-name",children:h.name}),h.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",h.fileCount," ",s("config:data.files"),")"]})]},h.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:D,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:T,disabled:A||p.size===0,children:A?s("config:data.importing"):s("config:data.importCount",{count:p.size})})]})]}):e.jsx("div",{className:"data-loading",children:s("config:data.readingFile")}):e.jsxs("label",{className:"data-file-input",children:[e.jsx("input",{type:"file",accept:".zip",onChange:f,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}function Ts(){const[s,i]=d.useState(()=>Ve()),n=o=>{i(o);const m=qe(o);Me(m)};return e.jsx("div",{className:"theme-selector",children:e.jsx("div",{className:"theme-selector-grid",children:Ke.map(o=>e.jsxs("button",{className:`theme-option ${s===o.id?"active":""}`,onClick:()=>n(o.id),title:o.description,children:[e.jsx("div",{className:"theme-preview",children:e.jsxs("div",{className:"theme-preview-bg",style:{backgroundColor:o.colors.bgPrimary},children:[e.jsx("div",{className:"theme-preview-accent",style:{backgroundColor:o.colors.accentBlue}}),e.jsx("div",{className:"theme-preview-claude",style:{backgroundColor:o.colors.accentClaude}})]})}),e.jsx("span",{className:"theme-name",children:o.name})]},o.id))})})}function Es(){const{t:s}=G(["config"]),{updateAvailable:i,updateInfo:n,recentReleases:o,isChecking:m,error:p,currentVersion:l,isAndroid:a,checkForUpdate:u,downloadAndInstall:A,openReleasePage:k}=as(),C=g=>g?`${(g/(1024*1024)).toFixed(1)} MB`:"",r=g=>new Date(g).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"});return e.jsxs("div",{className:"about-section",children:[e.jsxs("div",{className:"about-logo",children:[e.jsx("span",{className:"about-logo-icon",children:e.jsx(P,{name:"waves",size:24})}),e.jsx("span",{className:"about-logo-text",children:"Tide Commander"})]}),e.jsxs("div",{className:"about-version",children:[e.jsx("span",{className:"about-version-label",children:s("config:about.version")}),e.jsxs("div",{className:"about-version-info",children:[e.jsx("span",{className:"about-version-value",children:l}),i&&n?e.jsx("span",{className:"about-version-update-badge",onClick:k,title:`Update available: ${n.version}`,children:n.version}):e.jsxs("a",{href:"https://github.com/deivid11/tide-commander/releases",target:"_blank",rel:"noopener noreferrer",className:"about-version-status",children:["(",s("config:about.updated"),")"]})]})]}),e.jsxs("div",{className:"about-update",children:[i&&n?e.jsxs("div",{className:"about-update-available",children:[e.jsxs("div",{className:"about-update-header",children:[e.jsx("span",{className:"about-update-badge",children:s("config:about.updateAvailable")}),e.jsx("span",{className:"about-update-version",children:n.version})]}),n.apkSize&&e.jsxs("div",{className:"about-update-size",children:[s("config:about.sizeLabel"),": ",C(n.apkSize)]}),p&&e.jsx("div",{className:"about-update-error",children:p}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:k,children:s("config:about.changelog")}),a&&n.apkUrl?e.jsx("button",{className:"about-update-btn download",onClick:A,children:s("config:about.downloadAPK")}):e.jsx("button",{className:"about-update-btn download",onClick:k,children:s("config:about.viewRelease")})]})]}):e.jsxs("div",{className:"about-update-check",children:[e.jsx("span",{className:"about-update-status",children:s(m?"config:about.checkingUpdates":"config:about.upToDate")}),e.jsx("button",{className:"about-update-btn check",onClick:()=>u(!0),disabled:m,children:m?"...":s("config:about.check")})]}),o.length>0&&e.jsxs("div",{className:"about-releases",children:[e.jsx("div",{className:"about-releases-title",children:s("config:about.recentReleases")}),e.jsx("div",{className:"about-releases-list",children:o.map(g=>e.jsxs("a",{href:g.releaseUrl,target:"_blank",rel:"noopener noreferrer",className:`about-release-item ${g.version===`v${l}`||g.version===l?"current":""}`,children:[e.jsx("span",{className:"about-release-version",children:g.version}),e.jsx("span",{className:"about-release-date",children:r(g.publishedAt)})]},g.version))})]})]}),e.jsx("div",{className:"about-description",children:s("config:about.tagline")}),e.jsxs("div",{className:"about-principles",children:[e.jsx("div",{className:"about-principles-title",children:s("config:about.corePrinciples")}),e.jsxs("ul",{className:"about-principles-list",children:[e.jsx("li",{children:s("config:about.principle1")}),e.jsx("li",{children:s("config:about.principle2")}),e.jsx("li",{children:s("config:about.principle3")}),e.jsx("li",{children:s("config:about.principle4")})]})]}),e.jsx("div",{className:"about-links",children:e.jsxs("a",{href:"https://github.com/deivid11/tide-commander",target:"_blank",rel:"noopener noreferrer",className:"about-link",children:[e.jsx("span",{className:"about-link-icon",children:e.jsx(P,{name:"package",size:14})}),e.jsx("span",{children:s("config:about.repository")})]})}),e.jsxs("div",{className:"about-credits",children:[e.jsx("div",{className:"about-credits-title",children:s("config:about.specialThanks")}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://kenney.nl",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Kenney.nl"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.kenneyCredit")})]}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://claude.ai/code",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Claude Code"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.claudeCodeCredit")})]})]})]})}const Is={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄"};function Ps({onOpenModal:s}){const[i,n]=d.useState([]),[o,m]=d.useState(!0),p=d.useCallback(async()=>{try{const l=await oe(J("/api/integrations"));if(!l.ok)return;const a=await l.json();n(a)}catch{}finally{m(!1)}},[]);return d.useEffect(()=>{p()},[p]),o?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"Loading..."}):i.length===0?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"No integrations available."}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[i.map(l=>{const a=Is[l.id]||"🔌",u=!!l.status.error,A=l.status.connected,k=u?"#f38ba8":A?"#a6e3a1":"#fab387",C=u?"Error":A?"Connected":"Setup Required",r=u?"✗":A?"✓":"⚠";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 8px",borderRadius:6,background:"var(--surface-1, #181825)",border:"1px solid var(--border, #313244)",fontSize:13},children:[e.jsx("span",{style:{fontSize:15,flexShrink:0},children:a}),e.jsx("span",{style:{flex:1,color:"var(--text-primary, #cdd6f4)",fontWeight:500},children:l.name}),e.jsxs("span",{style:{color:k,fontSize:11,fontWeight:500,whiteSpace:"nowrap"},children:[r," ",C]}),e.jsx("button",{onClick:()=>s(l.id),title:`Configure ${l.name}`,style:{background:"none",border:"none",cursor:"pointer",padding:"2px 4px",fontSize:14,color:"var(--text-secondary, #a6adc8)",borderRadius:4,flexShrink:0},onMouseEnter:g=>{g.target.style.color="var(--text-primary, #cdd6f4)"},onMouseLeave:g=>{g.target.style.color="var(--text-secondary, #a6adc8)"},children:"⚙️"})]},l.id)}),e.jsx("button",{onClick:()=>s(),style:{background:"none",border:"1px dashed var(--border, #313244)",borderRadius:6,padding:"6px 8px",cursor:"pointer",color:"var(--text-secondary, #a6adc8)",fontSize:12,textAlign:"center",marginTop:2},onMouseEnter:l=>{l.target.style.borderColor="var(--accent, #89b4fa)",l.target.style.color="var(--accent, #89b4fa)"},onMouseLeave:l=>{l.target.style.borderColor="var(--border, #313244)",l.target.style.color="var(--text-secondary, #a6adc8)"},children:"Manage All Integrations"})]})}function Ls({isOpen:s,onClose:i}){const{t:n}=G(["config"]),[o,m]=d.useState(""),[p,l]=d.useState(""),[a,u]=d.useState(!0),[A,k]=d.useState(null),[C,r]=d.useState(null),[g,x]=d.useState(!1),[S,y]=d.useState(!1),[c,L]=d.useState(!1);d.useEffect(()=>{s&&R()},[s]);const R=async()=>{try{u(!0),k(null),r(null);const I=await hs();m(I),l(I),x(!1)}catch(I){k(I instanceof Error?I.message:"Failed to load system prompt")}finally{u(!1)}},$=I=>{const W=I.target.value;m(W),x(W!==p),k(null),r(null)},b=async()=>{try{k(null),r(null),await fs(o),l(o),x(!1),r(n("config:systemPrompt.saved"))}catch(I){k(I instanceof Error?I.message:"Failed to save system prompt")}},w=()=>{y(!0)},Z=async()=>{try{k(null),r(null),await xs(),m(""),l(""),x(!1),r(n("config:systemPrompt.cleared"))}catch(I){k(I instanceof Error?I.message:"Failed to clear system prompt")}},H=()=>{m(p),x(!1),k(null),r(null)},K=()=>{if(g){L(!0);return}i()},X=I=>{I.key==="Escape"&&(I.preventDefault(),K())};return s?e.jsxs(Ge,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:K,children:e.jsxs("div",{className:"system-prompt-modal",onClick:I=>I.stopPropagation(),onKeyDown:X,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:n("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:K,"aria-label":"Close",children:e.jsx(P,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:a?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:"Loading system prompt..."})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:n("config:systemPrompt.description")}),A&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(P,{name:"warn",size:14})}),A]}),C&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(P,{name:"check",size:14})}),C]}),e.jsxs("div",{className:"editor-wrapper",children:[e.jsxs("div",{className:"editor-header",children:[e.jsx("label",{htmlFor:"prompt-input",className:"editor-label",children:n("config:systemPrompt.editPrompt")}),e.jsxs("span",{className:"char-count",children:[o.length," ",n("config:systemPrompt.characters")]})]}),e.jsx("textarea",{id:"prompt-input",className:"prompt-editor",value:o,onChange:$,placeholder:n("config:systemPrompt.placeholder"),rows:18,autoFocus:!0}),e.jsx("div",{className:"editor-hint",children:n("config:systemPrompt.hint")})]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:w,disabled:!o||a,children:n("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:K,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:H,disabled:!g||a,children:n("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:b,disabled:!g||a,children:n("config:systemPrompt.save")})]})]})]})}),e.jsx(ge,{isOpen:S,title:n("config:systemPrompt.clear"),message:n("config:systemPrompt.confirmClear"),confirmLabel:n("config:systemPrompt.clear"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Z()},onClose:()=>y(!1)}),e.jsx(ge,{isOpen:c,title:"Unsaved Changes",message:"You have unsaved changes. Close anyway?",confirmLabel:"Close anyway",cancelLabel:"Keep editing",variant:"danger",onConfirm:i,onClose:()=>L(!1)})]}):null}const Fs=[{value:"auto",label:"Auto",icon:"🕐"},{value:"dawn",label:"Dawn",icon:"🌅"},{value:"day",label:"Day",icon:"☀️"},{value:"dusk",label:"Dusk",icon:"🌇"},{value:"night",label:"Night",icon:"🌙"}],Os=[{value:"none",label:"Grass",icon:"🌱"},{value:"concrete",label:"Concrete",icon:"🏗️"},{value:"galactic",label:"Galactic",icon:"🌌"},{value:"metal",label:"Metal",icon:"⚙️"},{value:"hex",label:"Hex",icon:"⬡"},{value:"circuit",label:"Circuit",icon:"🔌"},{value:"pokemon-stadium",label:"Pokemon",icon:"🔴"}],$s=[{value:"static",label:"Static",icon:"🧍"},{value:"idle",label:"Idle",icon:"🚶"},{value:"walk",label:"Walk",icon:"🚶‍♂️"},{value:"sprint",label:"Sprint",icon:"🏃"},{value:"jump",label:"Jump",icon:"⬆️"},{value:"fall",label:"Fall",icon:"⬇️"},{value:"crouch",label:"Crouch",icon:"🧎"},{value:"sit",label:"Sit",icon:"🪑"},{value:"die",label:"Die",icon:"💀"},{value:"emote-yes",label:"Yes",icon:"👍"},{value:"emote-no",label:"No",icon:"👎"}],zs=[{value:"normal",label:"Normal",icon:"🎨"},{value:"bw",label:"B&W",icon:"⬛"},{value:"sepia",label:"Sepia",icon:"🟤"},{value:"cool",label:"Cool",icon:"❄️"},{value:"warm",label:"Warm",icon:"🔥"},{value:"neon",label:"Neon",icon:"💜"}],_s=[{key:"showTrees",icon:"🌳",label:"Trees"},{key:"showBushes",icon:"🌿",label:"Bushes"},{key:"showHouse",icon:"🏠",label:"House"},{key:"showLamps",icon:"💡",label:"Lamps"},{key:"showGrass",icon:"🟩",label:"Grass"},{key:"showClouds",icon:"☁️",label:"Clouds"}],Bs=[{value:null,label:"Auto",color:"linear-gradient(135deg, #4a90d9 0%, #0a1a2a 100%)"},{value:"#4a90d9",label:"Day Blue",color:"#4a90d9"},{value:"#0a1a2a",label:"Night",color:"#0a1a2a"},{value:"#ff6b35",label:"Sunset",color:"#ff6b35"},{value:"#1a0a2e",label:"Purple",color:"#1a0a2e"},{value:"#2d5a27",label:"Matrix",color:"#2d5a27"},{value:"#8b0000",label:"Blood",color:"#8b0000"},{value:"#000000",label:"Void",color:"#000000"}],Ds={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},Rs={none:"grass","pokemon-stadium":"pokemon"},Us={"emote-yes":"yes","emote-no":"no"},Vs={"":"auto","#4a90d9":"dayBlue","#0a1a2a":"night","#ff6b35":"sunset","#1a0a2e":"purple","#2d5a27":"matrix","#8b0000":"blood","#000000":"void"};function V({checked:s,onChange:i}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,onChange:n=>i(n.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function ae({options:s,value:i,onChange:n,iconOnly:o=!1}){return e.jsx("div",{className:"chip-selector",children:s.map(m=>e.jsxs("button",{className:`chip ${i===m.value?"active":""}`,onClick:()=>n(m.value),title:m.label,children:[e.jsx("span",{className:"chip-icon",children:m.icon}),!o&&e.jsx("span",{className:"chip-label",children:m.label})]},m.value))})}function N({text:s,query:i}){if(!i.trim())return e.jsx(e.Fragment,{children:s});const n=s.toLowerCase(),o=i.toLowerCase(),m=n.indexOf(o);if(m===-1)return e.jsx(e.Fragment,{children:s});const p=s.slice(0,m),l=s.slice(m,m+i.length),a=s.slice(m+i.length);return e.jsxs(e.Fragment,{children:[p,e.jsx("mark",{className:"search-highlight",children:l}),a]})}const Ks=[{id:"general",title:"General",keywords:["history","hide costs","grid","fps","power saving","performance","limit","editor","external editor","language","idioma","语言","vibration","haptic","intensity","tab title","tmux","process persistence"]},{id:"agentNames",title:"Agent Names",keywords:["agent","names","custom","characters","rename"]},{id:"defaultClass",title:"Default Spawn Class",keywords:["default","class","spawn","agent","scout","builder","random"]},{id:"appearance",title:"Appearance",keywords:["theme","appearance","color","dark","light","style","look"]},{id:"connection",title:"Connection",keywords:["backend","url","auth","token","reconnect","server","api","connect","codex","opencode","binary","path"]},{id:"scene",title:"Scene",keywords:["character","size","indicator","scale","time","dawn","day","dusk","night","auto"]},{id:"terrain",title:"Terrain",keywords:["trees","bushes","house","lamps","grass","clouds","fog","brightness","floor","sky","color","environment","battlefield","size","grid","simple","minimal","dark","clean"]},{id:"modelStyle",title:"Agent Model Style",keywords:["saturation","roughness","metalness","glow","emissive","reflections","wireframe","color mode","material","shader"]},{id:"animations",title:"Animations",keywords:["idle","working","animation","walk","run","sprint","jump","sit","crouch"]},{id:"secrets",title:"Secrets",keywords:["secrets","api","key","password","credentials","env","environment"]},{id:"systemPrompt",title:"System Prompt",keywords:["system","prompt","global","instructions","ai","agent","rules","guidelines"]},{id:"data",title:"Data",keywords:["export","import","backup","restore","save","load","json"]},{id:"integrations",title:"Integrations",keywords:["integrations","plugins","gmail","slack","jira","calendar","docx","email","config","setup"]},{id:"workflows",title:"Workflows",keywords:["workflow","automation","state machine","editor","actions","transitions","pipeline"]},{id:"triggers",title:"Triggers",keywords:["trigger","event","webhook","cron","slack","email","jira","matching","fire"]},{id:"monitoring",title:"Monitoring",keywords:["monitoring","logs","triggers","events","history","workflow","traces","audit","timeline"]},{id:"experimental",title:"Experimental",keywords:["experimental","2d","view","voice","assistant","speech","tts","text to speech","echo","prompt","duplicate"]},{id:"about",title:"About",keywords:["about","version","update","credits","github","releases"]}],ue=[{value:"auto",label:"Auto",icon:"🌐"},{value:"en",label:"English",icon:"🇺🇸"},{value:"zh-CN",label:"中文",icon:"🇨🇳"},{value:"es",label:"Español",icon:"🇪🇸"},{value:"hi",label:"हिन्दी",icon:"🇮🇳"},{value:"pt",label:"Português",icon:"🇧🇷"},{value:"ru",label:"Русский",icon:"🇷🇺"},{value:"ja",label:"日本語",icon:"🇯🇵"},{value:"de",label:"Deutsch",icon:"🇩🇪"},{value:"fr",label:"Français",icon:"🇫🇷"},{value:"it",label:"Italiano",icon:"🇮🇹"}];function qs({config:s,onChange:i,searchQuery:n="",onOpenIntegrationsModal:o,onOpenMonitoringModal:m,onOpenWorkflowEditor:p,onOpenTriggerManager:l}){var Ne;const{t:a}=G(["config","common"]),u=pe(),A=He(),[k,C]=d.useState(()=>We(ne.DEFAULT_AGENT_CLASS)||"scout"),[r,g]=d.useState(u.settings.historyLimit),[x,S]=d.useState(()=>Ye()),[y,c]=d.useState(!1),[L,R]=d.useState(()=>U()),[$,b]=d.useState(!1),[w,Z]=d.useState(!1),[H,K]=d.useState(""),[X,I]=d.useState(!1),[W,te]=d.useState(""),[Q,f]=d.useState(!1);d.useEffect(()=>{vs().then(te).catch(()=>{})},[]),d.useEffect(()=>{bs().then(t=>{t!==u.settings.experimentalEchoPrompt&&v.updateSettings({experimentalEchoPrompt:t})}).catch(()=>{})},[]),d.useEffect(()=>{ys().then(t=>{t!==u.settings.tmuxMode&&v.updateSettings({tmuxMode:t})}).catch(()=>{})},[]),d.useEffect(()=>Je(t=>{S(t),c(!1)}),[]);const T=Fs.map(t=>({...t,label:a(`config:time.${t.value}`)})),D=Os.map(t=>({...t,label:a(`config:floor.${Rs[t.value]||t.value}`)})),h=$s.map(t=>({...t,label:a(`config:animation.${Us[t.value]||t.value}`)})),E=zs.map(t=>({...t,label:a(`config:colorMode.${t.value}`)})),F=_s.map(t=>({...t,label:a(`config:terrain.${Ds[t.key]}`)})),Y=Bs.map(t=>({...t,label:a(`config:sky.${Vs[t.value??""]}`)})),q=n.trim()?Ks.filter(t=>{const _=n.toLowerCase();return t.title.toLowerCase().includes(_)||t.keywords.some(ce=>ce.toLowerCase().includes(_))}).map(t=>t.id):null,j=t=>q?q.includes(t):!0,B=u.settings.customAgentNames||[],le=B.length>0?B:Ze,fe=()=>{const t=H.trim();t&&!B.includes(t)&&(v.updateSettings({customAgentNames:[...B,t]}),K(""))},Ee=t=>{v.updateSettings({customAgentNames:B.filter(_=>_!==t)})},Ie=()=>{v.updateSettings({customAgentNames:[]})},Pe=t=>{S(t),c(!0)},xe=()=>{Qe(x),c(!1),me()},Le=t=>{R(t),b(!0)},be=()=>{ie(ne.AUTH_TOKEN,L),b(!1),me()},Fe=t=>{te(t),f(!0)},je=()=>{Ns(W).catch(()=>{}),f(!1)},ee=t=>{i({...s,terrain:{...s.terrain,...t}})},se=t=>{i({...s,modelStyle:{...s.modelStyle,...t}})},ve=t=>{i({...s,animations:{...s.animations,...t}})},Oe=t=>{g(t),v.updateSettings({historyLimit:t})},$e=t=>{const _=s.terrain[t];typeof _=="boolean"&&ee({[t]:!_})},z=n.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-section",children:[q&&q.length===0&&e.jsx("div",{className:"config-no-results",children:a("config:noResults",{query:n})}),j("general")&&e.jsxs(O,{title:a("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:z&&j("general"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:general.history"),query:n})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:r,onChange:t=>Oe(parseInt(t.target.value)||100),min:50,max:2e3,step:50})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:general.hideCosts"),query:n})}),e.jsx(V,{checked:u.settings.hideCost,onChange:t=>v.updateSettings({hideCost:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:general.grid"),query:n})}),e.jsx(V,{checked:s.gridVisible,onChange:t=>i({...s,gridVisible:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:general.showFPS"),query:n})}),e.jsx(V,{checked:u.settings.showFPS,onChange:t=>v.updateSettings({showFPS:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:general.fpsLimit"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"120",step:"10",value:s.fpsLimit,onChange:t=>i({...s,fpsLimit:parseInt(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.fpsLimit===0?"∞":s.fpsLimit})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: Reduce FPS when idle to save power",children:[e.jsx(N,{text:a("config:general.powerSaving"),query:n})," ",e.jsx(P,{name:"bolt",size:12})]}),e.jsx(V,{checked:u.settings.powerSaving,onChange:t=>v.updateSettings({powerSaving:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Wrap agent processes in tmux sessions so they survive server restarts (requires tmux installed)",children:e.jsx(N,{text:a("config:general.tmuxMode"),query:n})}),e.jsx(V,{checked:u.settings.tmuxMode,onChange:async t=>{v.updateSettings({tmuxMode:t});try{await ks(t)}catch(_){console.error("Failed to sync tmux mode setting to server:",_)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:general.vibrationIntensity"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"5",step:"1",value:u.settings.vibrationIntensity,onChange:t=>v.updateSettings({vibrationIntensity:parseInt(t.target.value)})}),e.jsx("span",{className:"config-value",children:u.settings.vibrationIntensity===0?a("config:vibrationValues.off"):u.settings.vibrationIntensity===1?a("config:vibrationValues.ultraLight"):u.settings.vibrationIntensity===2?a("config:vibrationValues.veryLight"):u.settings.vibrationIntensity===3?a("config:vibrationValues.light"):u.settings.vibrationIntensity===4?a("config:vibrationValues.medium"):a("config:vibrationValues.heavy")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:general.externalEditor"),query:n})}),e.jsx("input",{type:"text",className:"config-input",placeholder:a("config:general.externalEditorPlaceholder"),value:u.settings.externalEditorCommand||"",onChange:t=>v.updateSettings({externalEditorCommand:t.target.value})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:general.tabTitle"),query:n})}),e.jsx("input",{type:"text",className:"config-input",placeholder:a("config:general.tabTitlePlaceholder"),value:u.settings.tabTitle||"",onChange:t=>v.updateSettings({tabTitle:t.target.value})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:general.language"),query:n})}),e.jsx(ae,{options:ue,value:localStorage.getItem("tide-commander-language-mode")==="manual"?((Ne=ue.find(t=>t.value!=="auto"&&de.language.startsWith(t.value.split("-")[0])))==null?void 0:Ne.value)||"en":"auto",onChange:t=>{var _;if(t==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const ce=navigator.language,ze=((_=ue.find(ye=>ye.value!=="auto"&&ce.startsWith(ye.value.split("-")[0])))==null?void 0:_.value)||"en";de.changeLanguage(ze)}else localStorage.setItem("tide-commander-language-mode","manual"),de.changeLanguage(t)}})]})]}),j("agentNames")&&e.jsx(O,{title:a("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:z&&j("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children:B.length>0?a("config:agentNames.customConfigured",{count:B.length}):a("config:agentNames.usingDefaults")}),e.jsxs("div",{className:"agent-names-input-row",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",placeholder:a("config:agentNames.addPlaceholder"),value:H,onChange:t=>K(t.target.value),onKeyDown:t=>{t.key==="Enter"&&fe()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:fe,disabled:!H.trim(),title:a("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:le.map((t,_)=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:t}),B.length>0&&e.jsx("button",{className:"agent-name-remove",onClick:()=>Ee(t),title:a("common:buttons.remove"),children:"x"})]},`${t}-${_}`))}),B.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:Ie,children:a("common:buttons.resetToDefaults")})]})}),j("defaultClass")&&e.jsx(O,{title:"Default Spawn Class",storageKey:"defaultClass",defaultOpen:!1,forceOpen:z&&j("defaultClass"),children:e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-hint",children:'Class pre-selected when the spawn modal opens. "Random" picks a different class each time.'}),e.jsxs("div",{className:"agent-names-list",style:{flexWrap:"wrap",gap:"6px",marginTop:"8px"},children:[e.jsx("div",{className:`agent-name-chip${k==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{C("random"),ie(ne.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries(Xe).map(([t,_])=>e.jsx("div",{className:`agent-name-chip${k===t?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{C(t),ie(ne.DEFAULT_AGENT_CLASS,t)},children:e.jsxs("span",{className:"agent-name-text",children:[_.icon," ",t.charAt(0).toUpperCase()+t.slice(1)]})},t)),A.map(t=>e.jsx("div",{className:`agent-name-chip${k===t.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{C(t.id),ie(ne.DEFAULT_AGENT_CLASS,t.id)},children:e.jsxs("span",{className:"agent-name-text",children:[t.icon," ",t.name]})},t.id))]})]})}),j("appearance")&&e.jsx(O,{title:a("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:z&&j("appearance"),children:e.jsx(Ts,{})}),j("connection")&&e.jsxs(O,{title:a("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:z&&j("connection"),children:[e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:connection.backendUrl"),query:n})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:x,onChange:t=>Pe(t.target.value),placeholder:"http://localhost:5174",onKeyDown:t=>{t.key==="Enter"&&y&&xe()}}),y&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:xe,title:a("config:connection.saveAndReconnect"),children:a("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:a("config:connection.autoDetectHint")})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:connection.authToken"),query:n})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:w?"text":"password",className:"config-input config-input-full",value:L,onChange:t=>Le(t.target.value),placeholder:a("config:connection.tokenPlaceholder"),onKeyDown:t=>{t.key==="Enter"&&$&&be()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>Z(!w),title:a(w?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(P,{name:w?"eye-closed":"eye",size:14})}),$&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:be,title:a("config:connection.saveAndReconnect"),children:a("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:a("config:connection.tokenRequired")})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:connection.codexBinaryPath"),query:n})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:W,onChange:t=>Fe(t.target.value),placeholder:a("config:connection.codexBinaryPathPlaceholder"),onKeyDown:t=>{t.key==="Enter"&&Q&&je()}}),Q&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:je,children:a("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:a("config:connection.codexBinaryPathHint")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("common:buttons.reconnect"),query:n})}),e.jsx("button",{className:"config-btn",onClick:()=>me(),title:"Force reconnect to server",children:a("common:buttons.reconnect")})]})]}),j("scene")&&e.jsxs(O,{title:a("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:z&&j("scene"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:scene.characterSize"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"3.0",step:"0.1",value:s.characterScale,onChange:t=>i({...s,characterScale:parseFloat(t.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.characterScale.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:scene.scale2d",{defaultValue:"2D Scale"}),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale2d,onChange:t=>i({...s,scale2d:parseFloat(t.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.scale2d.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:scene.scale3d",{defaultValue:"3D Scale"}),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale3d,onChange:t=>i({...s,scale3d:parseFloat(t.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.scale3d.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:scene.show2DTaskLabels",{defaultValue:"Show 2D task labels"}),query:n})}),e.jsx(V,{checked:s.show2DTaskLabels,onChange:t=>i({...s,show2DTaskLabels:t})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:scene.time"),query:n})}),e.jsx(ae,{options:T,value:s.timeMode,onChange:t=>i({...s,timeMode:t}),iconOnly:!0})]})]}),j("terrain")&&e.jsxs(O,{title:a("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:z&&j("terrain"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:terrainSettings.simpleMode",{defaultValue:"Simple Mode"}),query:n})}),e.jsx(V,{checked:s.terrain.simpleMode??!1,onChange:t=>ee({simpleMode:t})})]}),e.jsx("div",{className:"terrain-icons",style:{opacity:s.terrain.simpleMode?.4:1,pointerEvents:s.terrain.simpleMode?"none":"auto"},children:F.map(t=>e.jsx("button",{className:`terrain-icon-btn ${s.terrain[t.key]?"active":""}`,onClick:()=>$e(t.key),title:t.label,children:t.icon},t.key))}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:terrainSettings.fog"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.terrain.fogDensity,onChange:t=>ee({fogDensity:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.fogDensity===0?a("config:fogValues.off"):s.terrain.fogDensity<=1?a("config:fogValues.low"):a("config:fogValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:terrainSettings.brightness"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.2",max:"2",step:"0.1",value:s.terrain.brightness,onChange:t=>ee({brightness:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.brightness<=.5?a("config:brightnessValues.dark"):s.terrain.brightness<=1.2?a("config:brightnessValues.normal"):a("config:brightnessValues.bright")})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:terrainSettings.floor"),query:n})}),e.jsx(ae,{options:D,value:s.terrain.floorStyle,onChange:t=>ee({floorStyle:t}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:terrainSettings.sky"),query:n})}),e.jsx("div",{className:"sky-color-selector",children:Y.map(t=>e.jsx("button",{className:`sky-color-btn ${s.terrain.skyColor===t.value?"active":""}`,onClick:()=>ee({skyColor:t.value}),title:t.label,style:{background:t.color}},t.value??"auto"))})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:terrainSettings.battlefieldSize"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"30",max:"200",step:"10",value:s.terrain.battlefieldSize,onChange:t=>ee({battlefieldSize:parseInt(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.battlefieldSize})]})]}),j("modelStyle")&&e.jsxs(O,{title:a("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:z&&j("modelStyle"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:modelStyleSettings.saturation"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.modelStyle.saturation,onChange:t=>se({saturation:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.saturation<=.3?a("config:saturationValues.gray"):s.modelStyle.saturation<=1.2?a("config:saturationValues.normal"):a("config:saturationValues.vivid")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:modelStyleSettings.roughness"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.roughness,onChange:t=>se({roughness:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.roughness<0?a("config:roughnessValues.auto"):s.modelStyle.roughness<=.3?a("config:roughnessValues.glossy"):s.modelStyle.roughness<=.7?a("config:roughnessValues.normal"):a("config:roughnessValues.matte")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:modelStyleSettings.metalness"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.metalness,onChange:t=>se({metalness:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.metalness<0?a("config:metalnessValues.auto"):s.modelStyle.metalness<=.3?a("config:metalnessValues.plastic"):s.modelStyle.metalness<=.7?a("config:metalnessValues.mixed"):a("config:metalnessValues.metal")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:modelStyleSettings.glow"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"1",step:"0.05",value:s.modelStyle.emissiveBoost,onChange:t=>se({emissiveBoost:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.emissiveBoost<=.1?a("config:glowValues.off"):s.modelStyle.emissiveBoost<=.4?a("config:glowValues.low"):s.modelStyle.emissiveBoost<=.7?a("config:glowValues.med"):a("config:glowValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:modelStyleSettings.reflections"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"2",step:"0.1",value:s.modelStyle.envMapIntensity,onChange:t=>se({envMapIntensity:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.envMapIntensity<0?a("config:reflectionValues.auto"):s.modelStyle.envMapIntensity<=.3?a("config:reflectionValues.low"):s.modelStyle.envMapIntensity<=1?a("config:reflectionValues.normal"):a("config:reflectionValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:modelStyleSettings.wireframe"),query:n})}),e.jsx(V,{checked:s.modelStyle.wireframe,onChange:t=>se({wireframe:t})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:modelStyleSettings.colorMode"),query:n})}),e.jsx(ae,{options:E,value:s.modelStyle.colorMode,onChange:t=>se({colorMode:t}),iconOnly:!0})]})]}),j("animations")&&e.jsxs(O,{title:a("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:z&&j("animations"),children:[e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:animationSettings.idle"),query:n})}),e.jsx(ae,{options:h,value:s.animations.idleAnimation,onChange:t=>ve({idleAnimation:t}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:animationSettings.working"),query:n})}),e.jsx(ae,{options:h,value:s.animations.workingAnimation,onChange:t=>ve({workingAnimation:t}),iconOnly:!0})]})]}),j("secrets")&&e.jsx(O,{title:a("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:z&&j("secrets"),children:e.jsx(ps,{})}),j("systemPrompt")&&e.jsx(O,{title:a("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:z&&j("systemPrompt"),children:e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(N,{text:a("config:systemPrompt.title"),query:n})}),e.jsx("button",{className:"config-button",onClick:()=>I(!0),children:a("config:systemPrompt.editPrompt")})]})}),j("data")&&e.jsx(O,{title:a("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:z&&j("data"),children:e.jsx(As,{})}),j("integrations")&&e.jsx(O,{title:"Integrations",storageKey:"integrations",defaultOpen:!1,forceOpen:z&&j("integrations"),children:e.jsx(Ps,{onOpenModal:t=>o==null?void 0:o(t)})}),j("workflows")&&e.jsxs(O,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:z&&j("workflows"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(N,{text:"Create and manage automated workflow pipelines with visual state machine editor",query:n})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>p==null?void 0:p(),children:"Open Workflow Editor"})})]}),j("triggers")&&e.jsxs(O,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:z&&j("triggers"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(N,{text:"Create and manage event-driven triggers that fire agents with templates",query:n})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>l==null?void 0:l(),children:"Open Trigger Manager"})})]}),j("monitoring")&&e.jsxs(O,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:z&&j("monitoring"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(N,{text:"View event logs, trigger history, workflow traces, and system stats",query:n})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>m==null?void 0:m(),children:"Open Monitoring & Logs"})})]}),j("experimental")&&e.jsxs(O,{title:a("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:z&&j("experimental"),children:[e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Lightweight 2D top-down view for better performance",children:[e.jsx(N,{text:a("config:experimental.2dView"),query:n})," ",e.jsx(P,{name:"map",size:12})]}),e.jsx(V,{checked:u.settings.experimental2DView,onChange:t=>v.updateSettings({experimental2DView:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Voice assistant for hands-free agent control",children:[e.jsx(N,{text:a("config:experimental.voiceAssistant"),query:n})," ",e.jsx(P,{name:"microphone",size:12})]}),e.jsx(V,{checked:u.settings.experimentalVoiceAssistant,onChange:t=>v.updateSettings({experimentalVoiceAssistant:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Text-to-speech for reading agent responses",children:[e.jsx(N,{text:a("config:experimental.tts"),query:n})," ",e.jsx(P,{name:"speaker-on",size:12})]}),e.jsx(V,{checked:u.settings.experimentalTTS,onChange:t=>v.updateSettings({experimentalTTS:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Duplicate system prompt for improved LLM attention coverage. Increases input token usage.",children:e.jsx(N,{text:a("config:experimental.echoPrompt"),query:n})}),e.jsx(V,{checked:u.settings.experimentalEchoPrompt,onChange:async t=>{v.updateSettings({experimentalEchoPrompt:t});try{await js(t)}catch(_){console.error("Failed to sync echo prompt setting to server:",_)}}})]}),e.jsx("span",{className:"config-hint",children:a("config:experimental.hint")})]}),j("about")&&e.jsx(O,{title:a("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:z&&j("about"),children:e.jsx(Es,{})})]}),e.jsx(Ls,{isOpen:X,onClose:()=>I(!1)})]})}function Ws({onConfigChange:s,onToolChange:i,config:n,isOpen:o,onClose:m,onOpenBuildingModal:p,onOpenAreaExplorer:l,onOpenIntegrationsModal:a,onOpenMonitoringModal:u,onOpenWorkflowEditor:A,onOpenTriggerManager:k}){const{t:C}=G(["config","common"]),r=pe(),g=Array.from(r.areas.values()),x=Array.from(r.buildings.values()),[S,y]=d.useState(""),c=d.useRef(null);if(d.useEffect(()=>{const b=w=>{w.key==="Escape"&&o&&m()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[o,m]),d.useEffect(()=>{if(o&&c.current){const b=setTimeout(()=>{var w;(w=c.current)==null||w.focus()},50);return()=>clearTimeout(b)}},[o]),!o)return null;const L=b=>{const w=r.activeTool===b?null:b;i(w)},R=b=>{v.selectArea(r.selectedAreaId===b?null:b),i("select")},$=(b,w)=>{b.stopPropagation(),v.deleteArea(w)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"toolbox-backdrop",onClick:m}),e.jsxs("aside",{className:"toolbox",children:[e.jsxs("div",{className:"toolbox-header",children:[e.jsx("span",{children:C("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:m,title:C("common:buttons.close"),children:"×"})]}),e.jsxs("div",{className:"toolbox-search",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]}),e.jsx("input",{ref:c,type:"text",placeholder:C("config:searchPlaceholder"),value:S,onChange:b=>y(b.target.value),className:"toolbox-search-input"}),S&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>y(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(O,{title:C("config:areas.title",{count:g.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${r.activeTool==="select"?"active":""}`,onClick:()=>L("select"),title:C("config:tools.select"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"})})})}),e.jsx("button",{className:`tool-btn ${r.activeTool==="rectangle"?"active":""}`,onClick:()=>L("rectangle"),title:C("config:tools.rectangle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",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("button",{className:`tool-btn ${r.activeTool==="circle"?"active":""}`,onClick:()=>L("circle"),title:C("config:tools.circle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("circle",{cx:"12",cy:"12",r:"9"})})})})]}),e.jsx("div",{className:"areas-list",children:g.length===0?e.jsx("div",{className:"areas-empty",children:C("config:areas.drawToCreate")}):g.map(b=>e.jsx(is,{area:b,isSelected:r.selectedAreaId===b.id,onClick:()=>R(b.id),onDelete:w=>$(w,b.id)},b.id))})]})}),r.selectedAreaId&&e.jsx(gs,{area:r.areas.get(r.selectedAreaId),onClose:()=>v.selectArea(null),onOpenFolder:l}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(O,{title:C("config:buildings.title",{count:x.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:b=>{b.stopPropagation(),p==null||p()},title:C("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:x.length===0?e.jsx("div",{className:"buildings-empty",children:C("config:buildings.clickToAdd")}):x.map(b=>e.jsx(ls,{building:b,isSelected:r.selectedBuildingIds.has(b.id),onClick:()=>{v.selectBuilding(r.selectedBuildingIds.has(b.id)?null:b.id)},onEdit:()=>p==null?void 0:p(b.id)},b.id))})})}),r.selectedBuildingIds.size===1&&(()=>{const b=Array.from(r.selectedBuildingIds)[0],w=r.buildings.get(b);return w?e.jsx(cs,{building:w,onClose:()=>v.selectBuilding(null),onOpenModal:()=>p==null?void 0:p(b)}):null})(),e.jsx(qs,{config:n,onChange:s,searchQuery:S,onOpenIntegrationsModal:a,onOpenMonitoringModal:u,onOpenWorkflowEditor:A,onOpenTriggerManager:k})]})]})]})}export{Ws as Toolbox};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/web-CA59D-C5.js","assets/main-BnUsuS5B.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-Chj50gSY.js","assets/main-BCNShZjZ.css"])))=>i.map(i=>d[i]);
2
- import{bS as e,bj as o}from"./main-BnUsuS5B.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";var i;(function(r){r.Heavy="HEAVY",r.Medium="MEDIUM",r.Light="LIGHT"})(i||(i={}));var t;(function(r){r.Success="SUCCESS",r.Warning="WARNING",r.Error="ERROR"})(t||(t={}));const E=e("Haptics",{web:()=>o(()=>import("./web-CA59D-C5.js"),__vite__mapDeps([0,1,2,3,4])).then(r=>new r.HapticsWeb)});export{E as Haptics,i as ImpactStyle,t as NotificationType};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/web-iMMHHHFW.js","assets/main-BjcLCHKw.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-Chj50gSY.js","assets/main-CVksVK2O.css"])))=>i.map(i=>d[i]);
2
+ import{bT as e,bk as o}from"./main-BjcLCHKw.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";var i;(function(r){r.Heavy="HEAVY",r.Medium="MEDIUM",r.Light="LIGHT"})(i||(i={}));var t;(function(r){r.Success="SUCCESS",r.Warning="WARNING",r.Error="ERROR"})(t||(t={}));const E=e("Haptics",{web:()=>o(()=>import("./web-iMMHHHFW.js"),__vite__mapDeps([0,1,2,3,4])).then(r=>new r.HapticsWeb)});export{E as Haptics,i as ImpactStyle,t as NotificationType};