tide-commander 1.69.0 → 1.71.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 (50) hide show
  1. package/dist/assets/{BossLogsModal-CMDdkhTL.js → BossLogsModal-DoW-oomk.js} +1 -1
  2. package/dist/assets/BossSpawnModal-Boc6sIfS.js +1 -0
  3. package/dist/assets/{ControlsModal-BtJJYkcM.js → ControlsModal-C6o3uZcq.js} +1 -1
  4. package/dist/assets/{DockerLogsModal-Lw19ZQVz.js → DockerLogsModal-D0Qo_MwC.js} +1 -1
  5. package/dist/assets/{EmbeddedEditor-UwKqvTkJ.js → EmbeddedEditor-CekqD_9x.js} +1 -1
  6. package/dist/assets/{GmailOAuthSetup-BOlxzJ7D.js → GmailOAuthSetup-9-5bh2P-.js} +1 -1
  7. package/dist/assets/{GoogleOAuthSetup-DYvaSFQp.js → GoogleOAuthSetup-3dJ_OKsM.js} +1 -1
  8. package/dist/assets/{IframeModal-DRJROx67.js → IframeModal-DbXb7CwV.js} +1 -1
  9. package/dist/assets/{IntegrationsPanel-Bp1O-I5s.js → IntegrationsPanel-Bbu-YttD.js} +2 -2
  10. package/dist/assets/{LogViewerModal-BIlhbii5.js → LogViewerModal-Bz-phlyW.js} +1 -1
  11. package/dist/assets/{MonitoringModal-CuDrTaVn.js → MonitoringModal-DPufvsx3.js} +1 -1
  12. package/dist/assets/{PM2LogsModal-C1VLY7hc.js → PM2LogsModal-BRJEoIGZ.js} +1 -1
  13. package/dist/assets/{RestoreArchivedAreaModal-ObvIYj2V.js → RestoreArchivedAreaModal-DcsT_-25.js} +1 -1
  14. package/dist/assets/{Scene2DCanvas-BM_GFevb.js → Scene2DCanvas-DNsc8p5F.js} +1 -1
  15. package/dist/assets/{SceneManager-FeZQ9HI1.js → SceneManager-DPvh-m5A.js} +1 -1
  16. package/dist/assets/{SkillsPanel-CtFwVaQj.js → SkillsPanel-B_xQv-7n.js} +2 -2
  17. package/dist/assets/SpawnModal-B9jRwDuS.js +1 -0
  18. package/dist/assets/{SubordinateAssignmentModal-aDkxc3YR.js → SubordinateAssignmentModal-nNA0eQY3.js} +1 -1
  19. package/dist/assets/TriggerManagerPanel-CRYqCuDW.js +3 -0
  20. package/dist/assets/{WorkflowEditorPanel-D_8Bnuzv.js → WorkflowEditorPanel-DMj6QkhB.js} +1 -1
  21. package/dist/assets/{index-Br8WLiXq.js → index-B0Bgs8A9.js} +1 -1
  22. package/dist/assets/{index-BIkn0arf.js → index-BKI7mhTU.js} +3 -3
  23. package/dist/assets/{index-9Bftos7u.js → index-BSDP6H43.js} +6 -6
  24. package/dist/assets/index-BXuHHEGh.css +1 -0
  25. package/dist/assets/{index-K0KrIo24.js → index-BwN_ChZo.js} +3 -3
  26. package/dist/assets/index-CAYhCfSA.js +2 -0
  27. package/dist/assets/{index-BYR78OCI.js → index-CIDXn3G0.js} +1 -1
  28. package/dist/assets/{index-CX4tk_vI.js → index-QhVjGjw2.js} +1 -1
  29. package/dist/assets/{index-BMayWtlQ.js → index-VvpWwviS.js} +1 -1
  30. package/dist/assets/{index-YH8hJh62.js → index-fFQ_bGrk.js} +2 -2
  31. package/dist/assets/main-C2_Gs1Uu.css +1 -0
  32. package/dist/assets/{main--_0rf6yB.js → main-DchkmHia.js} +89 -89
  33. package/dist/assets/{web-BuuzpQy3.js → web-BYNdUdPc.js} +1 -1
  34. package/dist/assets/{web-Dn-wQDim.js → web-DPcQ0gLD.js} +1 -1
  35. package/dist/index.html +2 -2
  36. package/dist/locales/en/config.json +6 -1
  37. package/dist/locales/en/terminal.json +4 -1
  38. package/dist/src/packages/server/claude/runner.js +42 -33
  39. package/dist/src/packages/server/codex/backend.js +17 -8
  40. package/dist/src/packages/server/services/cron-service.js +49 -0
  41. package/dist/src/packages/server/services/runtime-command-execution.js +29 -12
  42. package/dist/src/packages/server/services/trigger-service.js +65 -0
  43. package/dist/src/packages/shared/agent-types.js +8 -0
  44. package/package.json +1 -1
  45. package/dist/assets/BossSpawnModal-C7lw2Wzh.js +0 -1
  46. package/dist/assets/SpawnModal-37ChIpU2.js +0 -1
  47. package/dist/assets/TriggerManagerPanel-CQxcjiJu.js +0 -3
  48. package/dist/assets/index-D8fn_Wjl.js +0 -1
  49. package/dist/assets/index-DDfjGtDT.css +0 -1
  50. package/dist/assets/main-BXDdkAuE.css +0 -1
@@ -0,0 +1,2 @@
1
+ import{z as rt,B as it,r as n,C as Ye,S as v,E as Ze,G as Ue,H as ie,J as ot,s as _,K as Qe,L as ct,v as dt,w as pt,j as e,I as p,M as mt,m as ut,N as et,O as tt,P as ht,U as ft,V as gt,W as xt,X as _t,Y as bt,Z as wt,_ as jt,$ as Ct,a0 as Nt,a1 as vt,a2 as kt,a3 as At,a4 as St,a5 as Mt,a6 as Et,a7 as yt,a8 as It,a9 as Pt,aa as $t,ab as zt,ac as Ot,ad as Rt,ae as Tt}from"./main-DchkmHia.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Lt=["simple","chat","advanced"],Dt={simple:"Simple",chat:"Chat",advanced:"Advanced"},Bt={simple:"○",chat:"◐",advanced:"◉"},Ft={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Je="flat-clear-context";function Gt(u){const d=u.split("/").filter(Boolean);return d.length===0?u:d.slice(-2).join("/")}function Vt(u){if(u.provider==="codex"){const q=u.codexModel||"gpt-5.3-codex",j=Ot[q];return{model:(j==null?void 0:j.label)||q}}if(u.provider==="opencode")return{model:u.opencodeModel||"opencode"};const d=u.model||"sonnet",b=Tt[d],k=u.effort,M=k?Rt[k]:void 0;return{model:(b==null?void 0:b.label)||d,effort:M==null?void 0:M.label}}function Ht(u,d){if(d.type==="rectangle"&&d.width&&d.height){const b=d.width/2,k=d.height/2;return u.x>=d.center.x-b&&u.x<=d.center.x+b&&u.z>=d.center.z-k&&u.z<=d.center.z+k}if(d.type==="circle"&&d.radius){const b=u.x-d.center.x,k=u.z-d.center.z;return b*b+k*k<=d.radius*d.radius}return!1}const Wt=jt.memo(function({agentId:d,terminalViewMode:b,onTerminalViewModeChange:k,inspectorOpen:M,onToggleInspector:q,onImageClick:j,onFileClick:oe,onBashClick:ce,onViewMarkdown:_e,onRequestClearSubordinates:be,onOpenBuilding:de,keyboard:pe,canNavigateBack:we,canNavigateForward:y,onNavigateBack:Y,onNavigateForward:Z,agentInfoOpen:V,onToggleAgentInfo:$e}){var r,c,E,g;const m=Ct(d),I=Nt(),H=n.useRef(null),je=n.useRef(null);n.useEffect(()=>{const a=je.current;if(!a)return;const o=s=>{s.button===3?(s.preventDefault(),s.stopPropagation(),Y()):s.button===4&&(s.preventDefault(),s.stopPropagation(),Z())},i=s=>{(s.button===3||s.button===4)&&s.preventDefault()};return a.addEventListener("mouseup",o),a.addEventListener("mousedown",i),()=>{a.removeEventListener("mouseup",o),a.removeEventListener("mousedown",i)}},[Y,Z]);const J=Qe(),Q=n.useMemo(()=>{if(!m)return null;const a=new Set,o=[];for(const i of J.values())i.archived||i.directories.length===0||i.assignedAgentIds.includes(d)&&(a.add(i.id),o.push(i));for(const i of J.values())i.archived||i.directories.length===0||a.has(i.id)||Ht({x:m.position.x,z:m.position.z},i)&&(a.add(i.id),o.push(i));return o.length===0?null:o.flatMap(i=>i.directories.filter(s=>s&&s.trim().length>0).map(s=>({areaId:i.id,areaName:i.name,dir:s})))},[m,d,J]),{branches:W,fetchRemote:ee,fetchingDirs:Ce}=vt(Q),te=n.useMemo(()=>{var i;const a=_.getAreaForAgent(d);if(!a)return[];const o=[];for(const s of I.values())s.type==="terminal"&&_.isPositionInArea(s.position,a)&&o.push({id:s.id,name:s.name,hasUrl:!!((i=s.terminalStatus)!=null&&i.url)});return o},[d,I]),T=n.useMemo(()=>{var i;const a=_.getAreaForAgent(d);if(!a)return[];const o=[];for(const s of I.values())s.type==="server"&&((i=s.pm2)!=null&&i.enabled)&&_.isPositionInArea(s.position,a)&&o.push({id:s.id,name:s.name});return o},[d,I]),Ne=n.useMemo(()=>{const a=_.getAreaForAgent(d);if(!a)return[];const o=[];for(const i of I.values())i.type==="database"&&i.database&&_.isPositionInArea(i.position,a)&&o.push({id:i.id,name:i.name});return o},[d,I]),[,ve]=n.useReducer(a=>a+1,0),ae=((r=H.current)==null?void 0:r.search.searchMode)??!1,ze=n.useCallback(()=>{var a;(a=H.current)==null||a.search.toggleSearch(),ve()},[]),ke=kt(),me=ke.isPending(Je),[L,ne]=n.useState(null),D=L?I.get(L):null,{height:Oe,onResizeStart:Re}=At(),[f,B]=n.useState(()=>Ue(v.GIT_PANEL_OPEN,!1)),[A,se]=n.useState(()=>Ue(v.BUILDINGS_PANEL_OPEN,!1)),[F,Ae]=n.useState(!1),Te=n.useCallback(()=>{Ae(a=>{const o=!a;return o&&St.setEnabled(!0),o})},[]),Le=n.useCallback(()=>Ae(!1),[]),De=n.useCallback(()=>{B(a=>{const o=!a;return ie(v.GIT_PANEL_OPEN,o),o})},[]),le=n.useCallback(()=>{se(a=>{const o=!a;return ie(v.BUILDINGS_PANEL_OPEN,o),o})},[]),P=n.useCallback(()=>{B(!1),ie(v.GIT_PANEL_OPEN,!1)},[]),re=n.useCallback(()=>{se(!1),ie(v.BUILDINGS_PANEL_OPEN,!1)},[]),Be=Mt();n.useEffect(()=>{if(!L)return;te.some(o=>o.id===L)||ne(null)},[L,te]);const[U,$]=n.useState(!1),ue=n.useRef(null);if(n.useEffect(()=>{if(!U)return;const a=o=>{ue.current&&!ue.current.contains(o.target)&&$(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[U]),!m)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const z=m.contextStats,Se=!!z,he=z?z.totalTokens:m.contextUsed||0,fe=z?z.contextWindow:m.contextLimit||2e5,Fe=z?z.usedPercent:Math.round(he/fe*100),O=Math.max(0,Math.min(100,Fe)),Ge=Math.max(0,100-O),ge=O>=80?"#ff4a4a":O>=60?"#ff9e4a":O>=40?"#ffd700":"#4aff9e",Me=(he/1e3).toFixed(1),R=(fe/1e3).toFixed(1),X=m.cwd,Ee=X?Gt(X):null,t=((c=m.subordinateIds)==null?void 0:c.length)||0,l=t>0;return e.jsxs("div",{ref:je,className:`flat-terminal-wrapper ${f||A||F?"flat-terminal-wrapper--with-side-panel":""}`,children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${V?"flat-terminal-wrapper__header-main--active":""}`,onClick:$e,title:V?"Hide agent info":"Show agent info","aria-pressed":V,children:[e.jsx(et,{agent:m,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:m.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:tt(m.status)},children:m.status})]}),m.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:m.taskLabel,children:["📋 ",m.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:m.provider==="codex"?"/assets/codex.png":m.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:m.provider,className:"flat-terminal-wrapper__header-provider-icon",title:m.provider==="codex"?"Codex Agent":m.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:a,effort:o}=Vt(m);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:o?`Model: ${a} · Effort: ${o}`:`Model: ${a}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:a}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:o})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsx("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:Lt.map(a=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${b===a?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>k(a),title:Ft[a],"aria-pressed":b===a,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:Bt[a]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Dt[a]})]},a))}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:Y,disabled:!we,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(p,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:Z,disabled:!y,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(p,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ae?"flat-terminal-wrapper__action-btn--active":""}`,onClick:ze,title:ae?"Close search":"Search messages","aria-pressed":ae,children:e.jsx(p,{name:ae?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${me?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>ke.handleClick(Je,()=>{var a;_.clearContext(d),(a=H.current)==null||a.historyLoader.clearHistory()}),title:me?"Click again to confirm clear context":"Clear context",children:e.jsx(p,{name:me?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${f?"flat-terminal-wrapper__action-btn--active":""}`,onClick:De,title:f?"Hide git panel":"Show git changes","aria-pressed":f,children:e.jsx(p,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${A?"flat-terminal-wrapper__action-btn--active":""}`,onClick:le,title:A?"Hide buildings panel":"Show area buildings","aria-pressed":A,children:e.jsx(p,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:ue,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${U?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>$(a=>!a),title:"More actions","aria-expanded":U,children:"⋮"}),U&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${F?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{Te(),$(!1)},title:F?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(p,{name:"bug",size:14}),e.jsx("span",{children:F?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{_.collapseContext(d),$(!1)},disabled:m.status!=="idle",title:m.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(p,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),l&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{be(d,t),$(!1)},children:[e.jsx(p,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",t," subordinate",t===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{_.killAgent(d),$(!1)},children:[e.jsx(p,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${M?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:q,title:M?"Hide inspector panel":"Show inspector panel","aria-label":M?"Hide inspector panel":"Show inspector panel","aria-pressed":M,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>_.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(p,{name:"cross",size:14})})]})]}),e.jsx(Et,{ref:H,agentId:d,agent:m,viewMode:b,isOpen:!0,onImageClick:j,onFileClick:oe,onBashClick:ce,onViewMarkdown:_e,keyboard:pe,hasModalOpen:!1}),D&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:Re,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${D.name}`,style:{height:Oe},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(p,{name:"terminal",size:12}),e.jsx("span",{children:D.name}),!((E=D.terminalStatus)!=null&&E.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>ne(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(p,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:(g=D.terminalStatus)!=null&&g.url?e.jsx(yt,{terminalUrl:D.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."})})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[m.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(p,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),X&&Ee&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:X,onClick:()=>_.setFileViewerPath(X),children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(p,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:Ee})]}),Q&&Q.map(({areaId:a,areaName:o,dir:i})=>{const s=W.get(i),x=Ce.has(i),S=i.split("/").filter(Boolean).pop()||i;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${o}: ${i}${s?` (${s.branch}${s.ahead?` ↑${s.ahead}`:""}${s.behind?` ↓${s.behind}`:""})`:""}`,onClick:()=>_.openFileExplorerForAreaFolder(a,i),children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:S}),s&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(p,{name:"git-branch",size:10})," ",s.branch]}),s.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${s.ahead} ahead`,children:[e.jsx(p,{name:"arrow-up",size:9}),s.ahead]}),s.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${s.behind} behind`,children:[e.jsx(p,{name:"arrow-down",size:9}),s.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${x?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:G=>{G.stopPropagation(),ee(i)},children:e.jsx(p,{name:x?"hourglass":"download",size:12})})]})]},`${a}:${i}`)}),e.jsxs("span",{className:"flat-terminal-wrapper__context",onClick:()=>_.setContextModalAgentId(d),title:Se?`Context usage: ${Me}k / ${R}k tokens (${O}% used). Click to view stats.`:"Click to fetch context stats",children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(p,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${O}%`,backgroundColor:ge}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:ge},children:[Me,"k/",R,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",Ge,"% free)"]}),!Se&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(p,{name:"warn",size:12})})]}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),te.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:te.map(a=>{const o=L===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""} ${a.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${o?"Hide":"Show"} terminal: ${a.name}${a.hasUrl?"":" (starting...)"}`,onClick:()=>{if(o){ne(null);return}a.hasUrl||_.sendBuildingCommand(a.id,"start"),ne(a.id)},children:e.jsx(p,{name:"terminal",size:14})},a.id)})}),T.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:T.map(a=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${a.name}`,onClick:()=>de(a.id),children:e.jsx(p,{name:"scroll",size:14})},a.id))}),Ne.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:Ne.map(a=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${a.name}`,onClick:()=>de(a.id),children:e.jsx(p,{name:"hard-drives",size:14})},a.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(It,{})})]}),f&&e.jsx(Pt,{agentId:d,agents:Be,onClose:P,branchInfoMap:W,fetchRemote:ee,fetchingDirs:Ce}),A&&e.jsx($t,{agentId:d,onClose:re}),F&&e.jsx(zt,{agentId:d,onClose:Le})]})});function qt({onAgentClick:u,onBuildingClick:d,onBuildingDoubleClick:b,onOpenSpawnModal:k,onOpenBossSpawnModal:M,onOpenAreaModal:q}){const j=rt(),oe=it(),[ce,_e]=n.useState(null),[be,de]=n.useState(null),[pe,we]=n.useState(null),[y,Y]=n.useState(null),[Z,V]=n.useState(!1),$e=n.useCallback(()=>{V(t=>!t)},[]),m=n.useCallback(()=>{V(!1)},[]),[I,H]=n.useState(()=>{const t=Ye(v.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),je=n.useCallback(t=>{H(t),Ze(v.VIEW_MODE,t)},[]);n.useEffect(()=>{const t=l=>{if(l.key!==v.VIEW_MODE)return;const r=l.newValue;(r==="simple"||r==="chat"||r==="advanced")&&H(r)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[J,Q]=n.useState(()=>Ue(v.FLAT_INSPECTOR_OPEN,!1)),[W,ee]=n.useState(!1),Ce=n.useCallback(()=>ee(t=>!t),[]),te=n.useCallback(()=>ee(!1),[]),[T,Ne]=n.useState(()=>Ye(v.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),ve=n.useCallback(t=>{Ne(t),Ze(v.FLAT_INSPECTOR_VIEW,t)},[]),ae=n.useCallback(()=>{Q(t=>{const l=!t;return ie(v.FLAT_INSPECTOR_OPEN,l),l})},[]),ze=n.useCallback(()=>{Q(!1),ie(v.FLAT_INSPECTOR_OPEN,!1)},[]),ke=ot(),me=n.useCallback((t,l)=>{_e({url:t,name:l})},[]),L=n.useCallback((t,l)=>{de({command:t,output:l,isLive:!1})},[]),ne=n.useCallback((t,l)=>{_.setFileViewerPath(t,l)},[]),D=n.useCallback(t=>{},[]),Oe=n.useCallback((t,l)=>{we({agentId:t,count:l})},[]),Re=n.useCallback(t=>{b?b(t):d(t)},[d,b]),f=n.useMemo(()=>oe.size>0?Array.from(oe)[0]:null,[oe]);n.useEffect(()=>{V(!1)},[f]);const B=n.useRef([]),A=n.useRef(-1),se=n.useRef(!1),F=n.useRef(null),[Ae,Te]=n.useState(!1),[Le,De]=n.useState(!1),le=n.useMemo(()=>new Set(j.map(t=>t.id)),[j]),P=n.useCallback(()=>{const t=B.current,l=A.current;Te(l>0),De(l>=0&&l<t.length-1)},[]),re=n.useCallback(t=>{const l=B.current;if(l.length===0)return;let r=A.current+t;for(;r>=0&&r<l.length;){const c=l[r];if(le.has(c)){se.current=!0,A.current=r,P(),_.selectAgent(c);return}r+=t}},[le,P]),Be=n.useCallback(()=>re(-1),[re]),U=n.useCallback(()=>re(1),[re]);n.useEffect(()=>{if(!f){B.current=[],A.current=-1,P();return}if(F.current=f,se.current){se.current=!1,P();return}const t=B.current,l=A.current;if(l>=0&&t[l]===f){P();return}const r=l<t.length-1?t.slice(0,l+1):t.slice();r.push(f),r.length>100&&r.shift(),B.current=r,A.current=r.length-1,P()},[f,P]);const $=n.useCallback(t=>{u(t),ee(!1)},[u]),ue=f??"",z=n.useCallback(()=>{},[]),Se=n.useCallback(t=>{$(t)},[$]),he=J,fe=n.useRef(null);n.useEffect(()=>{if(f)return;const t=l=>{if(l.key!==" "&&l.key!=="Backspace")return;const r=l.target;if(r.tagName==="INPUT"||r.tagName==="TEXTAREA"||r.isContentEditable)return;const c=F.current;!c||!le.has(c)||(l.preventDefault(),_.selectAgent(c))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[f,le]);const[Fe,O]=n.useState(new Set),Ge=n.useCallback(t=>{O(l=>{const r=new Set(l);return r.has(t)?r.delete(t):r.add(t),r})},[]),ge=Qe(),[Me]=ct(),R=n.useMemo(()=>{const t=new Map,l=[];for(const s of j){const x=_.getAreaForAgent(s.id);if(!dt((x==null?void 0:x.id)??null))continue;if(!x||x.archived){l.push(s);continue}const S=t.get(x.id);S?S.push(s):t.set(x.id,[s])}const r=[];for(const[,s]of ge){if(s.archived||!pt(s.id))continue;const x=t.get(s.id);x&&x.length>0&&r.push({area:s,agents:x})}l.length>0&&r.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:l});const c=r.filter(s=>s.area.id!=="__unassigned__"),E=r.filter(s=>s.area.id==="__unassigned__");let g=1,a=1;const o=new Map;if(c.length>1){let s=1/0,x=-1/0,S=1/0,G=-1/0;for(const C of c)s=Math.min(s,C.area.center.x),x=Math.max(x,C.area.center.x),S=Math.min(S,C.area.center.z),G=Math.max(G,C.area.center.z);const ye=x-s||1,Ie=G-S||1;if(c.length<=4){g=c.length,a=1;const C=[...c].sort((N,Ve)=>N.area.center.x-Ve.area.center.x);for(let N=0;N<C.length;N++)o.set(C[N].area.id,{row:1,col:N+1})}else{const C=[...c].sort((h,w)=>h.area.center.x-w.area.center.x),N=[];for(let h=1;h<C.length;h++)N.push(C[h].area.center.x-C[h-1].area.center.x);const Ve=N.reduce((h,w)=>h+w,0)/N.length||1;let Xe=1;for(const h of N)h>Ve*1.3&&Xe++;g=Math.max(2,Math.min(Xe,c.length));const He=[...c].sort((h,w)=>h.area.center.z-w.area.center.z),Pe=[];for(let h=1;h<He.length;h++)Pe.push(He[h].area.center.z-He[h-1].area.center.z);const at=Pe.reduce((h,w)=>h+w,0)/Pe.length||1;let Ke=1;for(const h of Pe)h>at*1.3&&Ke++;a=Math.max(2,Math.min(Ke,c.length)),g=Math.max(g,Math.ceil(c.length/a)),a=Math.max(a,Math.ceil(c.length/g));const nt=ye/g,st=Ie/a,We=new Set;for(const h of c){let w=Math.min(g-1,Math.max(0,Math.floor((h.area.center.x-s)/nt))),K=Math.min(a-1,Math.max(0,Math.floor((h.area.center.z-S)/st))),xe=`${K},${w}`,qe=0;const lt=a*g;for(;We.has(xe)&&qe<lt;)w++,w>=g&&(w=0,K=(K+1)%a),xe=`${K},${w}`,qe++;We.has(xe)&&(K=a,w=0,xe=`${K},${w}`,a++),We.add(xe),o.set(h.area.id,{row:K+1,col:w+1})}}}const i=s=>{s.sort((x,S)=>{var ye,Ie,C,N;const G=(((ye=x.position)==null?void 0:ye.z)??0)-(((Ie=S.position)==null?void 0:Ie.z)??0);return G!==0?G:(((C=x.position)==null?void 0:C.x)??0)-(((N=S.position)==null?void 0:N.x)??0)})};for(const s of c)i(s.agents);for(const s of E)i(s.agents);return{groups:[...c,...E],gridCols:g,gridRows:a,positions:o}},[j,ge,Me]),X=n.useMemo(()=>{if(!y)return[];const t=j.find(l=>l.id===y.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(p,{name:"chat",size:14}),onClick:()=>u(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>{window.confirm(`Remove ${t.name} from view?`)&&_.removeAgentFromServer(t.id)}}]:[]},[y,j,u]),Ee=n.useCallback(t=>{const l=new Set(R.groups.map(r=>r.area.id));l.delete(t),O(l),requestAnimationFrame(()=>{const r=fe.current;if(!r)return;const c=r.querySelector(`[data-area-id="${t}"]`);if(!c)return;const E=r.getBoundingClientRect(),a=c.getBoundingClientRect().top-E.top+r.scrollTop-8;r.scrollTo({top:Math.max(0,a),behavior:"smooth"})})},[R]);return e.jsxs("div",{className:`flat-view ${he?"flat-view--with-inspector":""} ${f?"flat-view--has-chat":""} ${W?"flat-view--mobile-sidebar-open":""}`,children:[W&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:te,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsxs("div",{className:"flat-middle__header",children:[e.jsx("h2",{className:"flat-middle__title",children:"👥 Agents"}),e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:k,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:M,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:q,title:"Create new area",children:"+ Area"})]})]}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(mt,{activeAgentId:ue,onClose:z,onSelectAgent:Se,collapsedAreas:Fe,onToggleArea:Ge,agentListRef:fe})})]}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":W?"Close agents sidebar":"Open agents sidebar","aria-expanded":W,onClick:Ce,children:[e.jsx(p,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),f?e.jsx(Wt,{agentId:f,terminalViewMode:I,onTerminalViewModeChange:je,inspectorOpen:J,onToggleInspector:ae,onImageClick:me,onFileClick:ne,onBashClick:L,onViewMarkdown:D,onRequestClearSubordinates:Oe,onOpenBuilding:Re,keyboard:ke,canNavigateBack:Ae,canNavigateForward:Le,onNavigateBack:Be,onNavigateForward:U,agentInfoOpen:Z,onToggleAgentInfo:$e}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${R.gridCols}, 1fr)`},children:R.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):R.groups.map(t=>{const l=t.area.id,r=R.positions.get(l);return e.jsxs("div",{className:"flat-map-area-card",style:{"--area-color":t.area.color,gridRow:r==null?void 0:r.row,gridColumn:r==null?void 0:r.col},children:[e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>Ee(l),title:`Focus ${t.area.name} in left panel`,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:t.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:t.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:t.agents.length})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:t.agents.map(c=>{const E=c.isBoss||c.class==="boss",g=ut(c),a=g.usedPercent>=80?"#ff4a4a":g.usedPercent>=60?"#ff9e4a":g.usedPercent>=40?"#ffd700":"#4aff9e",o=`Context: ${(g.totalTokens/1e3).toFixed(1)}k / ${(g.contextWindow/1e3).toFixed(1)}k (${g.usedPercent}% used, ${g.freePercent}% free)`;return e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${c.status}`,onClick:()=>u(c.id),onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),Y({agentId:c.id,position:{x:i.clientX,y:i.clientY}})},title:`${E?"Boss · ":""}Open chat with ${c.name}
2
+ ${o}`,children:[e.jsx(et,{agent:c,size:16}),E&&e.jsx("span",{className:"flat-map-agent-chip__crown","aria-hidden":"true",children:e.jsx(p,{name:"crown",size:11,color:"#ffd700",weight:"fill"})}),e.jsx("span",{className:"flat-map-agent-chip__name",children:c.name}),e.jsx("img",{src:c.provider==="codex"?"/assets/codex.png":c.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:c.provider,className:"flat-map-agent-chip__provider-icon",title:c.provider==="codex"?"Codex Agent":c.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:tt(c.status)}}),e.jsx("span",{className:"flat-map-agent-chip__context-bar","aria-hidden":"true",children:e.jsx("span",{className:"flat-map-agent-chip__context-bar-fill",style:{width:`${g.usedPercent}%`,backgroundColor:a}})})]},c.id)})})]},l)})})]})})]}),he&&e.jsxs("aside",{className:"flat-inspector","aria-label":"Inspector panel",children:[e.jsxs("div",{className:"flat-inspector__header",children:[e.jsxs("div",{className:"flat-inspector__tabs",role:"tablist","aria-label":"Inspector view",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":T==="agent",className:`flat-inspector__tab ${T==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>ve("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":T==="tracking",className:`flat-inspector__tab ${T==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>ve("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:ze,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:T==="tracking"?e.jsx(ht,{activeAgentId:f??"",onSelectAgent:t=>u(t)}):(()=>{if(!f)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=j.find(l=>l.id===f);return t?e.jsx(ft,{agent:t,onFocusAgent:l=>u(l),onKillAgent:l=>_.killAgent(l)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),ce&&e.jsx(gt,{url:ce.url,name:ce.name,onClose:()=>_e(null)}),be&&e.jsx(xt,{state:be,onClose:()=>de(null)}),pe&&e.jsx(_t,{action:"clear-subordinates",selectedAgentId:pe.agentId,subordinateCount:pe.count,onClose:()=>we(null),onClearHistory:()=>{}}),e.jsx(bt,{agent:f?j.find(t=>t.id===f)??null:null,isOpen:Z&&!!f,onClose:m}),e.jsx(wt,{isOpen:y!==null,position:(y==null?void 0:y.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:X,onClose:()=>Y(null)})]})}export{qt as FlatView};
@@ -1 +1 @@
1
- import{r as m,aF as re,aG as ye,j as e,I,u as q,aH as Se,ak as Ce,f as ge,s as v,aI as ze,k as _e,l as G,aJ as R,aK as Be,az as De,aL as Re,aM as K,aw as oe,aN as Ue,aO as Ve,aP as Ke,aQ as qe,aR as Me,as as Ge,C as He,S as ne,aS as We,aT as Ye,au as Je,aU as de,E as ie,aC as Ze,aV as me,aW as Xe}from"./main--_0rf6yB.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const he="deivid11/tide-commander",Qe=`https://api.github.com/repos/${he}/releases/latest`,es=`https://api.github.com/repos/${he}/releases?per_page=3`,ss=3600*1e3,ke="app_update_dismissed_version",we="1.69.0";function ts(){var y,w;const[s,i]=m.useState({isChecking:!1,updateAvailable:!1,updateInfo:null,recentReleases:[],error:null,currentVersion:we}),n=((w=(y=re)==null?void 0:y.getPlatform)==null?void 0:w.call(y))==="android"||!1,o=d=>d.replace(/^v/,"").split(".").map(c=>parseInt(c,10)||0),r=(d,g)=>{const c=o(d),C=o(g),S=Math.max(c.length,C.length);for(let x=0;x<S;x++){const P=c[x]||0,D=C[x]||0;if(P>D)return 1;if(P<D)return-1}return 0},p=async d=>{var c,C;if(re&&ye&&((C=(c=re).isNativePlatform)==null?void 0:C.call(c))===!0){const S=await ye.get({url:d,headers:{Accept:"application/vnd.github.v3+json"}});return{data:S.data,status:S.status}}else{const S=await fetch(d,{headers:{Accept:"application/vnd.github.v3+json"}});return S.ok?{data:await S.json(),status:S.status}:{data:null,status:S.status}}},l=m.useCallback(async(d=!1)=>{i(g=>({...g,isChecking:!0,error:null}));try{const[g,c]=await Promise.all([p(Qe),p(es)]);if(g.status!==200)throw new Error(`GitHub API error: ${g.status}`);const C=g.data,S=C.tag_name;let x=[];c.status===200&&c.data&&(x=c.data.map(k=>({version:k.tag_name,name:k.name,publishedAt:k.published_at,releaseUrl:k.html_url})));const P=localStorage.getItem(ke);if(!d&&P===S)return i(k=>({...k,isChecking:!1,updateAvailable:!1,recentReleases:x})),null;if(!(r(S,we)>0))return i(k=>({...k,isChecking:!1,updateAvailable:!1,recentReleases:x})),null;const $=C.assets.find(k=>k.name.endsWith(".apk")&&k.content_type==="application/vnd.android.package-archive"),u={version:S,name:C.name,changelog:C.body,releaseUrl:C.html_url,apkUrl:($==null?void 0:$.browser_download_url)||null,apkSize:($==null?void 0:$.size)||null,publishedAt:C.published_at};return i(k=>({...k,isChecking:!1,updateAvailable:!0,updateInfo:u,recentReleases:x})),u}catch(g){const c=g instanceof Error?g.message:"Failed to check for updates";return i(C=>({...C,isChecking:!1,error:c})),null}},[]),a=m.useCallback(async()=>{var d,g,c;if(!((d=s.updateInfo)!=null&&d.apkUrl)){(g=s.updateInfo)!=null&&g.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}if(!n){(c=s.updateInfo)!=null&&c.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}try{window.open(s.updateInfo.apkUrl,"_system"),i(C=>({...C,error:null}))}catch(C){const S=C instanceof Error?C.message:"Failed to open download";i(x=>({...x,error:S}))}},[s.updateInfo,n]),h=m.useCallback(()=>{s.updateInfo&&localStorage.setItem(ke,s.updateInfo.version),i(d=>({...d,updateAvailable:!1,updateInfo:null}))},[s.updateInfo]),A=m.useCallback(()=>{var d;(d=s.updateInfo)!=null&&d.releaseUrl?window.open(s.updateInfo.releaseUrl,"_blank"):window.open(`https://github.com/${he}/releases`,"_blank")},[s.updateInfo]);return m.useEffect(()=>{if(!n)return;const d=setTimeout(()=>{l()},5e3),g=setInterval(()=>{l()},ss);return()=>{clearTimeout(d),clearInterval(g)}},[n,l]),{...s,isAndroid:n,checkForUpdate:l,downloadAndInstall:a,dismissUpdate:h,openReleasePage:A}}const Ae="tide-toolbox-collapse";function as(s,i){try{const n=localStorage.getItem(`${Ae}-${s}`);if(n!==null)return n==="true"}catch{}return i}function ns(s,i){try{localStorage.setItem(`${Ae}-${s}`,String(i))}catch{}}function F({title:s,storageKey:i,defaultOpen:n=!1,forceOpen:o=!1,children:r,headerExtra:p}){const[l,a]=m.useState(()=>i?as(i,n):n),h=()=>{const y=!l;a(y),i&&ns(i,y)},A=o||l;return e.jsxs("div",{className:`collapsible-section ${A?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:h,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(I,{name:A?"caret-down":"caret-right",size:10})})]})]}),A&&e.jsx("div",{className:"collapsible-content",children:r})]})}function os({area:s,isSelected:i,onClick:n,onDelete:o}){const{t:r}=q(["config","common"]),p=s.assignedAgentIds.length,l=s.type==="rectangle"?r("config:areas.rect"):r("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?r("common:labels.agents").toLowerCase():r("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:o,title:r("config:areas.deleteArea"),children:"×"})]})}function is({building:s,isSelected:i,onClick:n,onEdit:o}){var a;const{t:r}=q(["config"]),p=((a=s.pm2Status)==null?void 0:a.ports)||[],l=(h,A)=>{h.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:Se[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(I,{name:Ce(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(h=>e.jsxs("a",{href:`http://localhost:${h}`,className:"building-port-link",onClick:A=>l(A,h),title:`Open :${h}`,children:[":",h]},h))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:h=>{h.stopPropagation(),o()},title:r("config:buildings.editBuilding"),children:e.jsx(I,{name:"gear",size:14})})]})}function ls({building:s,onClose:i,onOpenModal:n}){var A,y,w,d,g,c,C,S;const{t:o}=q(["config","common"]),{buildingLogs:r}=ge(),p=v.getBuildingLogs(s.id),l=ze[s.style||"server-rack"],a=x=>{v.sendBuildingCommand(s.id,x)},h=x=>{window.open(x,"_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(I,{name:Ce(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:Se[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:((y=s.commands)==null?void 0:y.start)||o("config:buildings.noStartCommand"),children:[e.jsx(I,{name:"play",size:12})," ",o("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>a("stop"),disabled:!((w=s.commands)!=null&&w.stop)||s.status==="stopped",title:((d=s.commands)==null?void 0:d.stop)||o("config:buildings.noStopCommand"),children:[e.jsx(I,{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:((c=s.commands)==null?void 0:c.restart)||o("config:buildings.noRestartCommand"),children:[e.jsx(I,{name:"refresh",size:12})," ",o("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>a("healthCheck"),disabled:!((C=s.commands)!=null&&C.healthCheck),title:((S=s.commands)==null?void 0:S.healthCheck)||o("config:buildings.noHealthCheck"),children:[e.jsx(I,{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((x,P)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>h(x.url),title:x.url,children:[e.jsx(I,{name:"link",size:12})," ",x.label||x.url]},P))})]}),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((x,P)=>e.jsx("div",{className:"building-editor-log-entry",children:x},P))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:n,children:[e.jsx(I,{name:"gear",size:12})," ",o("config:buildings.fullSettings")]})})]})}async function cs(s,i){const n=R(),o=await fetch(G(`/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 r=await o.json().catch(()=>({error:o.statusText}));throw new Error(r.error||`Upload failed: ${o.statusText}`)}return o.json()}async function rs(s){const i=R(),n=await fetch(G(`/api/areas/${s}/logo`),{method:"DELETE",headers:{...i?{Authorization:`Bearer ${i}`}:{}}});if(!n.ok)throw new Error(`Failed to delete logo: ${n.statusText}`)}function ds(s){return _e(G(`/api/areas/logos/${s}`))}const ms=[{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 us({area:s,onClose:i,onOpenFolder:n}){var W;const{t:o}=q(["config","common"]),[r,p]=m.useState(s.name),[l,a]=m.useState(s.prompt||""),[h,A]=m.useState(!1),[y,w]=m.useState(""),[d,g]=m.useState(!1),c=m.useRef(null);m.useEffect(()=>{p(s.name)},[s.id,s.name]),m.useEffect(()=>{a(s.prompt||"")},[s.id,s.prompt]);const C=b=>{const T=b.target.value;p(T),v.updateArea(s.id,{name:T})},S=b=>{v.updateArea(s.id,{color:b})},x=b=>{const T=b.target.value;a(T),v.updateArea(s.id,{prompt:T})},P=()=>{y.trim()&&(v.addDirectoryToArea(s.id,y.trim()),w(""),A(!1))},D=(b,T)=>{T.stopPropagation(),v.removeDirectoryFromArea(s.id,b)},$=()=>{v.bringAreaToFront(s.id)},u=()=>{v.sendAreaToBack(s.id)},k=m.useCallback(()=>{let b=2,T=2;s.type==="rectangle"&&s.width&&s.height?(b=s.width,T=s.height):s.type==="circle"&&s.radius&&(b=s.radius*1.414,T=s.radius*1.414);const B=Math.min(b,T)*.4;return{width:Math.round(B*10)/10,height:Math.round(B*10)/10}},[s.type,s.width,s.height,s.radius]),te=async b=>{var B;const T=(B=b.target.files)==null?void 0:B[0];if(T){g(!0);try{const f=await cs(s.id,T),E=k();v.updateArea(s.id,{logo:{filename:f.filename,position:"center",width:E.width,height:E.height,keepAspectRatio:!0,opacity:.8}})}catch(f){console.error("Failed to upload logo:",f)}finally{g(!1),c.current&&(c.current.value="")}}},H=async()=>{try{await rs(s.id),v.updateArea(s.id,{logo:void 0})}catch(b){console.error("Failed to remove logo:",b)}},Z=b=>{s.logo&&v.updateArea(s.id,{logo:{...s.logo,position:b}})},ae=b=>{if(!s.logo)return;const T=parseFloat(b.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const B=s.logo.height/s.logo.width;v.updateArea(s.id,{logo:{...s.logo,width:T,height:Math.round(T*B*10)/10}})}else v.updateArea(s.id,{logo:{...s.logo,width:T}})},X=b=>{if(!s.logo)return;const T=parseFloat(b.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const B=s.logo.width/s.logo.height;v.updateArea(s.id,{logo:{...s.logo,height:T,width:Math.round(T*B*10)/10}})}else v.updateArea(s.id,{logo:{...s.logo,height:T}})},Q=()=>{s.logo&&v.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},ee=b=>{s.logo&&v.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(b.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:r,onChange:C,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:Be.map(b=>e.jsx("div",{className:`color-swatch ${s.color===b?"selected":""}`,style:{backgroundColor:b},onClick:()=>S(b)},b))})]}),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(I,{name:"arrow-up",size:12})," ",o("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:u,title:o("config:areas.sendToBack"),children:[e.jsx(I,{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:[(W=s.logo)!=null&&W.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:ds(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 b;return(b=c.current)==null?void 0:b.click()},disabled:d,children:d?"...":e.jsx(I,{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:ms.map(({key:b,labelKey:T})=>{var B;return e.jsx("button",{className:`area-logo-pos-btn ${((B=s.logo)==null?void 0:B.position)===b?"active":""}`,onClick:()=>Z(b),children:o(`config:areas.${T}`)},b)})})]}),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:ae,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:X,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:Q}),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:ee,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 b;return(b=c.current)==null?void 0:b.click()},disabled:d,children:d?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:c,type:"file",accept:"image/*",style:{display:"none"},onChange:te})]})]}),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(b=>e.jsxs("div",{className:"area-folder-item",title:b,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(I,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:b.split("/").pop()||b}),e.jsx("button",{className:"area-folder-remove",onClick:T=>D(b,T),title:o("config:areas.removeFolder"),children:"×"})]},b)),h?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(De,{value:y,onChange:w,onSubmit:P,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:P,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:x,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 gs(){const{t:s}=q(["config","common"]),i=Re(),[n,o]=m.useState(!1),[r,p]=m.useState(null),[l,a]=m.useState({name:"",key:"",value:"",description:""}),h=()=>{o(!0),p(null),a({name:"",key:"",value:"",description:""})},A=c=>{p(c.id),o(!1),a({name:c.name,key:c.key,value:c.value,description:c.description||""})},y=()=>{o(!1),p(null),a({name:"",key:"",value:"",description:""})},w=()=>{!l.name.trim()||!l.key.trim()||(r?v.updateSecret(r,{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}),y())},d=c=>{confirm(s("config:secrets.deleteConfirm"))&&(v.deleteSecret(c),r===c&&y())},g=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 ${r===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:()=>g(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:()=>A(c),title:s("common:buttons.edit"),children:e.jsx(I,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>d(c.id),title:s("common:buttons.delete"),children:"×"})]})]}),c.description&&e.jsx("div",{className:"secret-item-description",children:c.description})]},c.id))}),(n||r)&&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:y,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:w,disabled:!l.name.trim()||!l.key.trim(),children:s(r?"config:secrets.update":"common:buttons.add")})]})]}),!n&&!r&&e.jsx("button",{className:"secrets-add-btn",onClick:h,children:s("config:secrets.addSecret")})]})}async function hs(){const s=R(),i=await fetch(`${K()}/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 ps(s){const i=R(),n=await fetch(`${K()}/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 fs(){const s=R(),i=await fetch(`${K()}/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 xs(){const s=R(),i=await fetch(`${K()}/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 bs(s){const i=R(),n=await fetch(`${K()}/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 js(){const s=R(),i=await fetch(`${K()}/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 vs(s){const i=R(),n=await fetch(`${K()}/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 Ns(){const s=R(),i=await fetch(`${K()}/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 ys(s){const i=R(),n=await fetch(`${K()}/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 ks(){const s=R(),i=await fetch(`${K()}/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 ws(s){const i=R(),n=await fetch(`${K()}/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 Ss({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 Cs(){const{t:s}=q(["config","common"]),[i,n]=m.useState([]),[o,r]=m.useState(new Set),[p,l]=m.useState(new Set),[a,h]=m.useState(!1),[A,y]=m.useState(!1),[w,d]=m.useState(null),[g,c]=m.useState(null),[C,S]=m.useState(null),[x,P]=m.useState(null),[D,$]=m.useState(!1),[u,k]=m.useState(null);m.useEffect(()=>{oe(G("/api/config/categories")).then(f=>f.json()).then(f=>{const E=Array.isArray(f)?f:[];n(E),r(new Set(E.map(L=>L.id)))}).catch(f=>console.error("Failed to fetch config categories:",f))},[]),m.useEffect(()=>{ks().then(P).catch(f=>{console.error("Failed to fetch backup status:",f),k(f.message||"Failed to fetch backup status")})},[]);const te=async f=>{if(!D){$(!0),k(null);try{const E=await ws(f);P(E)}catch(E){k(E.message||"Failed to update backup setting")}finally{$(!1)}}},H=f=>{r(E=>{const L=new Set(E);return L.has(f)?L.delete(f):L.add(f),L})},Z=f=>{l(E=>{const L=new Set(E);return L.has(f)?L.delete(f):L.add(f),L})},ae=()=>r(new Set(i.map(f=>f.id))),X=()=>r(new Set),Q=()=>{g&&l(new Set(g.categories.map(f=>f.id)))},ee=()=>l(new Set),W=async()=>{var f;if(o.size!==0){h(!0),S(null);try{const E=Array.from(o).join(","),L=await oe(G(`/api/config/export?categories=${E}`));if(!L.ok)throw new Error("Export failed");const M=await L.blob(),V=window.URL.createObjectURL(M),j=document.createElement("a");j.href=V;const _=L.headers.get("Content-Disposition"),le=((f=_==null?void 0:_.match(/filename="(.+)"/))==null?void 0:f[1])||"tide-commander-config.zip";j.download=le,document.body.appendChild(j),j.click(),document.body.removeChild(j),window.URL.revokeObjectURL(V),S({type:"success",text:s("config:data.exportSuccess")})}catch(E){S({type:"error",text:E.message||"Export failed"})}finally{h(!1)}}},b=async f=>{var L;const E=(L=f.target.files)==null?void 0:L[0];if(E){d(E),S(null),c(null),l(new Set);try{const M=await oe(G("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await E.arrayBuffer()});if(!M.ok){const _=await M.json();throw new Error(_.error||"Failed to preview config file")}const V=await M.json(),j=Array.isArray(V.categories)?V.categories:[];c({...V,categories:j}),l(new Set(j.map(_=>_.id)))}catch(M){S({type:"error",text:M.message||"Failed to read config file"}),d(null)}}},T=async()=>{if(!(!w||p.size===0)){y(!0),S(null);try{const f=Array.from(p).join(","),E=await oe(G(`/api/config/import?categories=${f}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await w.arrayBuffer()}),L=await E.json();if(!E.ok)throw new Error(L.error||"Import failed");S({type:"success",text:L.message||s("config:data.importSuccess")}),d(null),c(null),l(new Set)}catch(f){S({type:"error",text:f.message||"Import failed"})}finally{y(!1)}}},B=()=>{d(null),c(null),l(new Set),S(null)};return e.jsxs("div",{className:"data-section",children:[C&&e.jsx("div",{className:`data-message data-message-${C.type}`,children:C.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(Ss,{checked:!!(x!=null&&x.enabled),disabled:D||!x,onChange:te})]}),e.jsxs("div",{className:"data-backup-info",children:[x?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:x.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!x.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:x.scriptPath})]}),x.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(x.lastRunAt).toLocaleString(),x.lastRunOk===!0&&" — ok",x.lastRunOk===!1&&x.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",x.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),u&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:u})]})]}),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:ae,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:X,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:i.map(f=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(f.id),onChange:()=>H(f.id)}),e.jsx("span",{className:"data-category-name",children:f.name})]},f.id))}),e.jsx("button",{className:"data-action-btn export",onClick:W,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")})}),w?g?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:w.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:Q,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:ee,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:g.categories.map(f=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:p.has(f.id),onChange:()=>Z(f.id)}),e.jsx("span",{className:"data-category-name",children:f.name}),f.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",f.fileCount," ",s("config:data.files"),")"]})]},f.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:B,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:b,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}function As(){const[s,i]=m.useState(()=>Ue()),n=o=>{i(o);const r=Ke(o);qe(r)};return e.jsx("div",{className:"theme-selector",children:e.jsx("div",{className:"theme-selector-grid",children:Ve.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 Ts(){const{t:s}=q(["config"]),{updateAvailable:i,updateInfo:n,recentReleases:o,isChecking:r,error:p,currentVersion:l,isAndroid:a,checkForUpdate:h,downloadAndInstall:A,openReleasePage:y}=ts(),w=g=>g?`${(g/(1024*1024)).toFixed(1)} MB`:"",d=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(I,{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:y,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"),": ",w(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:y,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:y,children:s("config:about.viewRelease")})]})]}):e.jsxs("div",{className:"about-update-check",children:[e.jsx("span",{className:"about-update-status",children:s(r?"config:about.checkingUpdates":"config:about.upToDate")}),e.jsx("button",{className:"about-update-btn check",onClick:()=>h(!0),disabled:r,children:r?"...":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:d(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(I,{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 Es={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄"};function Is({onOpenModal:s}){const[i,n]=m.useState([]),[o,r]=m.useState(!0),p=m.useCallback(async()=>{try{const l=await oe(G("/api/integrations"));if(!l.ok)return;const a=await l.json();n(a)}catch{}finally{r(!1)}},[]);return m.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=Es[l.id]||"🔌",h=!!l.status.error,A=l.status.connected,y=h?"#f38ba8":A?"#a6e3a1":"#fab387",w=h?"Error":A?"Connected":"Setup Required",d=h?"✗":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:y,fontSize:11,fontWeight:500,whiteSpace:"nowrap"},children:[d," ",w]}),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 Ps({isOpen:s,onClose:i}){const{t:n}=q(["config"]),[o,r]=m.useState(""),[p,l]=m.useState(""),[a,h]=m.useState(!0),[A,y]=m.useState(null),[w,d]=m.useState(null),[g,c]=m.useState(!1);m.useEffect(()=>{s&&C()},[s]);const C=async()=>{try{h(!0),y(null),d(null);const u=await hs();r(u),l(u),c(!1)}catch(u){y(u instanceof Error?u.message:"Failed to load system prompt")}finally{h(!1)}},S=u=>{const k=u.target.value;r(k),c(k!==p),y(null),d(null)},x=async()=>{try{y(null),d(null),await ps(o),l(o),c(!1),d(n("config:systemPrompt.saved"))}catch(u){y(u instanceof Error?u.message:"Failed to save system prompt")}},P=async()=>{if(window.confirm(n("config:systemPrompt.confirmClear")))try{y(null),d(null),await fs(),r(""),l(""),c(!1),d(n("config:systemPrompt.cleared"))}catch(u){y(u instanceof Error?u.message:"Failed to clear system prompt")}},D=()=>{r(p),c(!1),y(null),d(null)},$=u=>{if(u.key==="Escape"){if(g&&!window.confirm("You have unsaved changes. Close anyway?")){u.preventDefault();return}i()}};return s?e.jsx(Me,{children:e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:i,children:e.jsxs("div",{className:"system-prompt-modal",onClick:u=>u.stopPropagation(),onKeyDown:$,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:n("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:i,"aria-label":"Close",children:e.jsx(I,{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(I,{name:"warn",size:14})}),A]}),w&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),w]}),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:S,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:P,disabled:!o||a,children:n("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:i,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:D,disabled:!g||a,children:n("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:x,disabled:!g||a,children:n("config:systemPrompt.save")})]})]})]})})}):null}const Ls=[{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:"🌙"}],Fs=[{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:"👎"}],Os=[{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:"💜"}],zs=[{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"}],_s=[{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"}],Bs={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},Ds={none:"grass","pokemon-stadium":"pokemon"},Rs={"emote-yes":"yes","emote-no":"no"},Us={"":"auto","#4a90d9":"dayBlue","#0a1a2a":"night","#ff6b35":"sunset","#1a0a2e":"purple","#2d5a27":"matrix","#8b0000":"blood","#000000":"void"};function U({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 se({options:s,value:i,onChange:n,iconOnly:o=!1}){return e.jsx("div",{className:"chip-selector",children:s.map(r=>e.jsxs("button",{className:`chip ${i===r.value?"active":""}`,onClick:()=>n(r.value),title:r.label,children:[e.jsx("span",{className:"chip-icon",children:r.icon}),!o&&e.jsx("span",{className:"chip-label",children:r.label})]},r.value))})}function N({text:s,query:i}){if(!i.trim())return e.jsx(e.Fragment,{children:s});const n=s.toLowerCase(),o=i.toLowerCase(),r=n.indexOf(o);if(r===-1)return e.jsx(e.Fragment,{children:s});const p=s.slice(0,r),l=s.slice(r,r+i.length),a=s.slice(r+i.length);return e.jsxs(e.Fragment,{children:[p,e.jsx("mark",{className:"search-highlight",children:l}),a]})}const Vs=[{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 Ks({config:s,onChange:i,searchQuery:n="",onOpenIntegrationsModal:o,onOpenMonitoringModal:r,onOpenWorkflowEditor:p,onOpenTriggerManager:l}){var ve;const{t:a}=q(["config","common"]),h=ge(),A=Ge(),[y,w]=m.useState(()=>He(ne.DEFAULT_AGENT_CLASS)||"scout"),[d,g]=m.useState(h.settings.historyLimit),[c,C]=m.useState(()=>We()),[S,x]=m.useState(!1),[P,D]=m.useState(()=>R()),[$,u]=m.useState(!1),[k,te]=m.useState(!1),[H,Z]=m.useState(""),[ae,X]=m.useState(!1),[Q,ee]=m.useState(""),[W,b]=m.useState(!1);m.useEffect(()=>{js().then(ee).catch(()=>{})},[]),m.useEffect(()=>{xs().then(t=>{t!==h.settings.experimentalEchoPrompt&&v.updateSettings({experimentalEchoPrompt:t})}).catch(()=>{})},[]),m.useEffect(()=>{Ns().then(t=>{t!==h.settings.tmuxMode&&v.updateSettings({tmuxMode:t})}).catch(()=>{})},[]),m.useEffect(()=>Ye(t=>{C(t),x(!1)}),[]);const T=Ls.map(t=>({...t,label:a(`config:time.${t.value}`)})),B=Fs.map(t=>({...t,label:a(`config:floor.${Ds[t.value]||t.value}`)})),f=$s.map(t=>({...t,label:a(`config:animation.${Rs[t.value]||t.value}`)})),E=Os.map(t=>({...t,label:a(`config:colorMode.${t.value}`)})),L=zs.map(t=>({...t,label:a(`config:terrain.${Bs[t.key]}`)})),M=_s.map(t=>({...t,label:a(`config:sky.${Us[t.value??""]}`)})),V=n.trim()?Vs.filter(t=>{const z=n.toLowerCase();return t.title.toLowerCase().includes(z)||t.keywords.some(ce=>ce.toLowerCase().includes(z))}).map(t=>t.id):null,j=t=>V?V.includes(t):!0,_=h.settings.customAgentNames||[],le=_.length>0?_:Je,pe=()=>{const t=H.trim();t&&!_.includes(t)&&(v.updateSettings({customAgentNames:[..._,t]}),Z(""))},Te=t=>{v.updateSettings({customAgentNames:_.filter(z=>z!==t)})},Ee=()=>{v.updateSettings({customAgentNames:[]})},Ie=t=>{C(t),x(!0)},fe=()=>{Xe(c),x(!1),me()},Pe=t=>{D(t),u(!0)},xe=()=>{ie(ne.AUTH_TOKEN,P),u(!1),me()},Le=t=>{ee(t),b(!0)},be=()=>{vs(Q).catch(()=>{}),b(!1)},Y=t=>{i({...s,terrain:{...s.terrain,...t}})},J=t=>{i({...s,modelStyle:{...s.modelStyle,...t}})},je=t=>{i({...s,animations:{...s.animations,...t}})},Fe=t=>{g(t),v.updateSettings({historyLimit:t})},$e=t=>{const z=s.terrain[t];typeof z=="boolean"&&Y({[t]:!z})},O=n.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-section",children:[V&&V.length===0&&e.jsx("div",{className:"config-no-results",children:a("config:noResults",{query:n})}),j("general")&&e.jsxs(F,{title:a("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:O&&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:d,onChange:t=>Fe(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(U,{checked:h.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(U,{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(U,{checked:h.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(I,{name:"bolt",size:12})]}),e.jsx(U,{checked:h.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(U,{checked:h.settings.tmuxMode,onChange:async t=>{v.updateSettings({tmuxMode:t});try{await ys(t)}catch(z){console.error("Failed to sync tmux mode setting to server:",z)}}})]}),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:h.settings.vibrationIntensity,onChange:t=>v.updateSettings({vibrationIntensity:parseInt(t.target.value)})}),e.jsx("span",{className:"config-value",children:h.settings.vibrationIntensity===0?a("config:vibrationValues.off"):h.settings.vibrationIntensity===1?a("config:vibrationValues.ultraLight"):h.settings.vibrationIntensity===2?a("config:vibrationValues.veryLight"):h.settings.vibrationIntensity===3?a("config:vibrationValues.light"):h.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:h.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:h.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(se,{options:ue,value:localStorage.getItem("tide-commander-language-mode")==="manual"?((ve=ue.find(t=>t.value!=="auto"&&de.language.startsWith(t.value.split("-")[0])))==null?void 0:ve.value)||"en":"auto",onChange:t=>{var z;if(t==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const ce=navigator.language,Oe=((z=ue.find(Ne=>Ne.value!=="auto"&&ce.startsWith(Ne.value.split("-")[0])))==null?void 0:z.value)||"en";de.changeLanguage(Oe)}else localStorage.setItem("tide-commander-language-mode","manual"),de.changeLanguage(t)}})]})]}),j("agentNames")&&e.jsx(F,{title:a("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:O&&j("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children:_.length>0?a("config:agentNames.customConfigured",{count:_.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=>Z(t.target.value),onKeyDown:t=>{t.key==="Enter"&&pe()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:pe,disabled:!H.trim(),title:a("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:le.map((t,z)=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:t}),_.length>0&&e.jsx("button",{className:"agent-name-remove",onClick:()=>Te(t),title:a("common:buttons.remove"),children:"x"})]},`${t}-${z}`))}),_.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:Ee,children:a("common:buttons.resetToDefaults")})]})}),j("defaultClass")&&e.jsx(F,{title:"Default Spawn Class",storageKey:"defaultClass",defaultOpen:!1,forceOpen:O&&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${y==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{w("random"),ie(ne.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries(Ze).map(([t,z])=>e.jsx("div",{className:`agent-name-chip${y===t?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{w(t),ie(ne.DEFAULT_AGENT_CLASS,t)},children:e.jsxs("span",{className:"agent-name-text",children:[z.icon," ",t.charAt(0).toUpperCase()+t.slice(1)]})},t)),A.map(t=>e.jsx("div",{className:`agent-name-chip${y===t.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{w(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(F,{title:a("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:O&&j("appearance"),children:e.jsx(As,{})}),j("connection")&&e.jsxs(F,{title:a("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:O&&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:c,onChange:t=>Ie(t.target.value),placeholder:"http://localhost:5174",onKeyDown:t=>{t.key==="Enter"&&S&&fe()}}),S&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:fe,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:k?"text":"password",className:"config-input config-input-full",value:P,onChange:t=>Pe(t.target.value),placeholder:a("config:connection.tokenPlaceholder"),onKeyDown:t=>{t.key==="Enter"&&$&&xe()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>te(!k),title:a(k?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(I,{name:k?"eye-closed":"eye",size:14})}),$&&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.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:Q,onChange:t=>Le(t.target.value),placeholder:a("config:connection.codexBinaryPathPlaceholder"),onKeyDown:t=>{t.key==="Enter"&&W&&be()}}),W&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:be,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(F,{title:a("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:O&&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(U,{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(se,{options:T,value:s.timeMode,onChange:t=>i({...s,timeMode:t}),iconOnly:!0})]})]}),j("terrain")&&e.jsxs(F,{title:a("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:O&&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(U,{checked:s.terrain.simpleMode??!1,onChange:t=>Y({simpleMode:t})})]}),e.jsx("div",{className:"terrain-icons",style:{opacity:s.terrain.simpleMode?.4:1,pointerEvents:s.terrain.simpleMode?"none":"auto"},children:L.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=>Y({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=>Y({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(se,{options:B,value:s.terrain.floorStyle,onChange:t=>Y({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:M.map(t=>e.jsx("button",{className:`sky-color-btn ${s.terrain.skyColor===t.value?"active":""}`,onClick:()=>Y({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=>Y({battlefieldSize:parseInt(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.battlefieldSize})]})]}),j("modelStyle")&&e.jsxs(F,{title:a("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:O&&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=>J({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=>J({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=>J({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=>J({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=>J({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(U,{checked:s.modelStyle.wireframe,onChange:t=>J({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(se,{options:E,value:s.modelStyle.colorMode,onChange:t=>J({colorMode:t}),iconOnly:!0})]})]}),j("animations")&&e.jsxs(F,{title:a("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:O&&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(se,{options:f,value:s.animations.idleAnimation,onChange:t=>je({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(se,{options:f,value:s.animations.workingAnimation,onChange:t=>je({workingAnimation:t}),iconOnly:!0})]})]}),j("secrets")&&e.jsx(F,{title:a("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:O&&j("secrets"),children:e.jsx(gs,{})}),j("systemPrompt")&&e.jsx(F,{title:a("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:O&&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:()=>X(!0),children:a("config:systemPrompt.editPrompt")})]})}),j("data")&&e.jsx(F,{title:a("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:O&&j("data"),children:e.jsx(Cs,{})}),j("integrations")&&e.jsx(F,{title:"Integrations",storageKey:"integrations",defaultOpen:!1,forceOpen:O&&j("integrations"),children:e.jsx(Is,{onOpenModal:t=>o==null?void 0:o(t)})}),j("workflows")&&e.jsxs(F,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:O&&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(F,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:O&&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(F,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:O&&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:()=>r==null?void 0:r(),children:"Open Monitoring & Logs"})})]}),j("experimental")&&e.jsxs(F,{title:a("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:O&&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(I,{name:"map",size:12})]}),e.jsx(U,{checked:h.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(I,{name:"microphone",size:12})]}),e.jsx(U,{checked:h.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(I,{name:"speaker-on",size:12})]}),e.jsx(U,{checked:h.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(U,{checked:h.settings.experimentalEchoPrompt,onChange:async t=>{v.updateSettings({experimentalEchoPrompt:t});try{await bs(t)}catch(z){console.error("Failed to sync echo prompt setting to server:",z)}}})]}),e.jsx("span",{className:"config-hint",children:a("config:experimental.hint")})]}),j("about")&&e.jsx(F,{title:a("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:O&&j("about"),children:e.jsx(Ts,{})})]}),e.jsx(Ps,{isOpen:ae,onClose:()=>X(!1)})]})}function Hs({onConfigChange:s,onToolChange:i,config:n,isOpen:o,onClose:r,onOpenBuildingModal:p,onOpenAreaExplorer:l,onOpenIntegrationsModal:a,onOpenMonitoringModal:h,onOpenWorkflowEditor:A,onOpenTriggerManager:y}){const{t:w}=q(["config","common"]),d=ge(),g=Array.from(d.areas.values()),c=Array.from(d.buildings.values()),[C,S]=m.useState(""),x=m.useRef(null);if(m.useEffect(()=>{const u=k=>{k.key==="Escape"&&o&&r()};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[o,r]),m.useEffect(()=>{if(o&&x.current){const u=setTimeout(()=>{var k;(k=x.current)==null||k.focus()},50);return()=>clearTimeout(u)}},[o]),!o)return null;const P=u=>{const k=d.activeTool===u?null:u;i(k)},D=u=>{v.selectArea(d.selectedAreaId===u?null:u),i("select")},$=(u,k)=>{u.stopPropagation(),v.deleteArea(k)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"toolbox-backdrop",onClick:r}),e.jsxs("aside",{className:"toolbox",children:[e.jsxs("div",{className:"toolbox-header",children:[e.jsx("span",{children:w("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:r,title:w("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:x,type:"text",placeholder:w("config:searchPlaceholder"),value:C,onChange:u=>S(u.target.value),className:"toolbox-search-input"}),C&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>S(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(F,{title:w("config:areas.title",{count:g.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${d.activeTool==="select"?"active":""}`,onClick:()=>P("select"),title:w("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 ${d.activeTool==="rectangle"?"active":""}`,onClick:()=>P("rectangle"),title:w("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 ${d.activeTool==="circle"?"active":""}`,onClick:()=>P("circle"),title:w("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:w("config:areas.drawToCreate")}):g.map(u=>e.jsx(os,{area:u,isSelected:d.selectedAreaId===u.id,onClick:()=>D(u.id),onDelete:k=>$(k,u.id)},u.id))})]})}),d.selectedAreaId&&e.jsx(us,{area:d.areas.get(d.selectedAreaId),onClose:()=>v.selectArea(null),onOpenFolder:l}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(F,{title:w("config:buildings.title",{count:c.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:u=>{u.stopPropagation(),p==null||p()},title:w("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:c.length===0?e.jsx("div",{className:"buildings-empty",children:w("config:buildings.clickToAdd")}):c.map(u=>e.jsx(is,{building:u,isSelected:d.selectedBuildingIds.has(u.id),onClick:()=>{v.selectBuilding(d.selectedBuildingIds.has(u.id)?null:u.id)},onEdit:()=>p==null?void 0:p(u.id)},u.id))})})}),d.selectedBuildingIds.size===1&&(()=>{const u=Array.from(d.selectedBuildingIds)[0],k=d.buildings.get(u);return k?e.jsx(ls,{building:k,onClose:()=>v.selectBuilding(null),onOpenModal:()=>p==null?void 0:p(u)}):null})(),e.jsx(Ks,{config:n,onChange:s,searchQuery:C,onOpenIntegrationsModal:a,onOpenMonitoringModal:h,onOpenWorkflowEditor:A,onOpenTriggerManager:y})]})]})]})}export{Hs as Toolbox};
1
+ import{r as m,aI as re,aJ as ye,j as e,I,u as q,aK as Se,am as Ce,f as ge,s as v,aL as ze,k as _e,l as G,aM as R,aN as Be,aB as De,aO as Re,aP as K,ay as oe,aQ as Ue,aR as Ve,aS as Ke,aT as qe,aU as Me,au as Ge,C as He,S as ne,aV as We,aW as Ye,aw as Je,aX as de,E as ie,aF as Ze,aY as me,aZ as Xe}from"./main-DchkmHia.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const he="deivid11/tide-commander",Qe=`https://api.github.com/repos/${he}/releases/latest`,es=`https://api.github.com/repos/${he}/releases?per_page=3`,ss=3600*1e3,ke="app_update_dismissed_version",we="1.71.0";function ts(){var y,w;const[s,i]=m.useState({isChecking:!1,updateAvailable:!1,updateInfo:null,recentReleases:[],error:null,currentVersion:we}),n=((w=(y=re)==null?void 0:y.getPlatform)==null?void 0:w.call(y))==="android"||!1,o=d=>d.replace(/^v/,"").split(".").map(c=>parseInt(c,10)||0),r=(d,g)=>{const c=o(d),C=o(g),S=Math.max(c.length,C.length);for(let x=0;x<S;x++){const P=c[x]||0,D=C[x]||0;if(P>D)return 1;if(P<D)return-1}return 0},p=async d=>{var c,C;if(re&&ye&&((C=(c=re).isNativePlatform)==null?void 0:C.call(c))===!0){const S=await ye.get({url:d,headers:{Accept:"application/vnd.github.v3+json"}});return{data:S.data,status:S.status}}else{const S=await fetch(d,{headers:{Accept:"application/vnd.github.v3+json"}});return S.ok?{data:await S.json(),status:S.status}:{data:null,status:S.status}}},l=m.useCallback(async(d=!1)=>{i(g=>({...g,isChecking:!0,error:null}));try{const[g,c]=await Promise.all([p(Qe),p(es)]);if(g.status!==200)throw new Error(`GitHub API error: ${g.status}`);const C=g.data,S=C.tag_name;let x=[];c.status===200&&c.data&&(x=c.data.map(k=>({version:k.tag_name,name:k.name,publishedAt:k.published_at,releaseUrl:k.html_url})));const P=localStorage.getItem(ke);if(!d&&P===S)return i(k=>({...k,isChecking:!1,updateAvailable:!1,recentReleases:x})),null;if(!(r(S,we)>0))return i(k=>({...k,isChecking:!1,updateAvailable:!1,recentReleases:x})),null;const $=C.assets.find(k=>k.name.endsWith(".apk")&&k.content_type==="application/vnd.android.package-archive"),u={version:S,name:C.name,changelog:C.body,releaseUrl:C.html_url,apkUrl:($==null?void 0:$.browser_download_url)||null,apkSize:($==null?void 0:$.size)||null,publishedAt:C.published_at};return i(k=>({...k,isChecking:!1,updateAvailable:!0,updateInfo:u,recentReleases:x})),u}catch(g){const c=g instanceof Error?g.message:"Failed to check for updates";return i(C=>({...C,isChecking:!1,error:c})),null}},[]),a=m.useCallback(async()=>{var d,g,c;if(!((d=s.updateInfo)!=null&&d.apkUrl)){(g=s.updateInfo)!=null&&g.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}if(!n){(c=s.updateInfo)!=null&&c.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}try{window.open(s.updateInfo.apkUrl,"_system"),i(C=>({...C,error:null}))}catch(C){const S=C instanceof Error?C.message:"Failed to open download";i(x=>({...x,error:S}))}},[s.updateInfo,n]),h=m.useCallback(()=>{s.updateInfo&&localStorage.setItem(ke,s.updateInfo.version),i(d=>({...d,updateAvailable:!1,updateInfo:null}))},[s.updateInfo]),A=m.useCallback(()=>{var d;(d=s.updateInfo)!=null&&d.releaseUrl?window.open(s.updateInfo.releaseUrl,"_blank"):window.open(`https://github.com/${he}/releases`,"_blank")},[s.updateInfo]);return m.useEffect(()=>{if(!n)return;const d=setTimeout(()=>{l()},5e3),g=setInterval(()=>{l()},ss);return()=>{clearTimeout(d),clearInterval(g)}},[n,l]),{...s,isAndroid:n,checkForUpdate:l,downloadAndInstall:a,dismissUpdate:h,openReleasePage:A}}const Ae="tide-toolbox-collapse";function as(s,i){try{const n=localStorage.getItem(`${Ae}-${s}`);if(n!==null)return n==="true"}catch{}return i}function ns(s,i){try{localStorage.setItem(`${Ae}-${s}`,String(i))}catch{}}function F({title:s,storageKey:i,defaultOpen:n=!1,forceOpen:o=!1,children:r,headerExtra:p}){const[l,a]=m.useState(()=>i?as(i,n):n),h=()=>{const y=!l;a(y),i&&ns(i,y)},A=o||l;return e.jsxs("div",{className:`collapsible-section ${A?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:h,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(I,{name:A?"caret-down":"caret-right",size:10})})]})]}),A&&e.jsx("div",{className:"collapsible-content",children:r})]})}function os({area:s,isSelected:i,onClick:n,onDelete:o}){const{t:r}=q(["config","common"]),p=s.assignedAgentIds.length,l=s.type==="rectangle"?r("config:areas.rect"):r("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?r("common:labels.agents").toLowerCase():r("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:o,title:r("config:areas.deleteArea"),children:"×"})]})}function is({building:s,isSelected:i,onClick:n,onEdit:o}){var a;const{t:r}=q(["config"]),p=((a=s.pm2Status)==null?void 0:a.ports)||[],l=(h,A)=>{h.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:Se[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(I,{name:Ce(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(h=>e.jsxs("a",{href:`http://localhost:${h}`,className:"building-port-link",onClick:A=>l(A,h),title:`Open :${h}`,children:[":",h]},h))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:h=>{h.stopPropagation(),o()},title:r("config:buildings.editBuilding"),children:e.jsx(I,{name:"gear",size:14})})]})}function ls({building:s,onClose:i,onOpenModal:n}){var A,y,w,d,g,c,C,S;const{t:o}=q(["config","common"]),{buildingLogs:r}=ge(),p=v.getBuildingLogs(s.id),l=ze[s.style||"server-rack"],a=x=>{v.sendBuildingCommand(s.id,x)},h=x=>{window.open(x,"_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(I,{name:Ce(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:Se[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:((y=s.commands)==null?void 0:y.start)||o("config:buildings.noStartCommand"),children:[e.jsx(I,{name:"play",size:12})," ",o("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>a("stop"),disabled:!((w=s.commands)!=null&&w.stop)||s.status==="stopped",title:((d=s.commands)==null?void 0:d.stop)||o("config:buildings.noStopCommand"),children:[e.jsx(I,{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:((c=s.commands)==null?void 0:c.restart)||o("config:buildings.noRestartCommand"),children:[e.jsx(I,{name:"refresh",size:12})," ",o("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>a("healthCheck"),disabled:!((C=s.commands)!=null&&C.healthCheck),title:((S=s.commands)==null?void 0:S.healthCheck)||o("config:buildings.noHealthCheck"),children:[e.jsx(I,{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((x,P)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>h(x.url),title:x.url,children:[e.jsx(I,{name:"link",size:12})," ",x.label||x.url]},P))})]}),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((x,P)=>e.jsx("div",{className:"building-editor-log-entry",children:x},P))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:n,children:[e.jsx(I,{name:"gear",size:12})," ",o("config:buildings.fullSettings")]})})]})}async function cs(s,i){const n=R(),o=await fetch(G(`/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 r=await o.json().catch(()=>({error:o.statusText}));throw new Error(r.error||`Upload failed: ${o.statusText}`)}return o.json()}async function rs(s){const i=R(),n=await fetch(G(`/api/areas/${s}/logo`),{method:"DELETE",headers:{...i?{Authorization:`Bearer ${i}`}:{}}});if(!n.ok)throw new Error(`Failed to delete logo: ${n.statusText}`)}function ds(s){return _e(G(`/api/areas/logos/${s}`))}const ms=[{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 us({area:s,onClose:i,onOpenFolder:n}){var W;const{t:o}=q(["config","common"]),[r,p]=m.useState(s.name),[l,a]=m.useState(s.prompt||""),[h,A]=m.useState(!1),[y,w]=m.useState(""),[d,g]=m.useState(!1),c=m.useRef(null);m.useEffect(()=>{p(s.name)},[s.id,s.name]),m.useEffect(()=>{a(s.prompt||"")},[s.id,s.prompt]);const C=b=>{const T=b.target.value;p(T),v.updateArea(s.id,{name:T})},S=b=>{v.updateArea(s.id,{color:b})},x=b=>{const T=b.target.value;a(T),v.updateArea(s.id,{prompt:T})},P=()=>{y.trim()&&(v.addDirectoryToArea(s.id,y.trim()),w(""),A(!1))},D=(b,T)=>{T.stopPropagation(),v.removeDirectoryFromArea(s.id,b)},$=()=>{v.bringAreaToFront(s.id)},u=()=>{v.sendAreaToBack(s.id)},k=m.useCallback(()=>{let b=2,T=2;s.type==="rectangle"&&s.width&&s.height?(b=s.width,T=s.height):s.type==="circle"&&s.radius&&(b=s.radius*1.414,T=s.radius*1.414);const B=Math.min(b,T)*.4;return{width:Math.round(B*10)/10,height:Math.round(B*10)/10}},[s.type,s.width,s.height,s.radius]),te=async b=>{var B;const T=(B=b.target.files)==null?void 0:B[0];if(T){g(!0);try{const f=await cs(s.id,T),E=k();v.updateArea(s.id,{logo:{filename:f.filename,position:"center",width:E.width,height:E.height,keepAspectRatio:!0,opacity:.8}})}catch(f){console.error("Failed to upload logo:",f)}finally{g(!1),c.current&&(c.current.value="")}}},H=async()=>{try{await rs(s.id),v.updateArea(s.id,{logo:void 0})}catch(b){console.error("Failed to remove logo:",b)}},Z=b=>{s.logo&&v.updateArea(s.id,{logo:{...s.logo,position:b}})},ae=b=>{if(!s.logo)return;const T=parseFloat(b.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const B=s.logo.height/s.logo.width;v.updateArea(s.id,{logo:{...s.logo,width:T,height:Math.round(T*B*10)/10}})}else v.updateArea(s.id,{logo:{...s.logo,width:T}})},X=b=>{if(!s.logo)return;const T=parseFloat(b.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const B=s.logo.width/s.logo.height;v.updateArea(s.id,{logo:{...s.logo,height:T,width:Math.round(T*B*10)/10}})}else v.updateArea(s.id,{logo:{...s.logo,height:T}})},Q=()=>{s.logo&&v.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},ee=b=>{s.logo&&v.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(b.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:r,onChange:C,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:Be.map(b=>e.jsx("div",{className:`color-swatch ${s.color===b?"selected":""}`,style:{backgroundColor:b},onClick:()=>S(b)},b))})]}),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(I,{name:"arrow-up",size:12})," ",o("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:u,title:o("config:areas.sendToBack"),children:[e.jsx(I,{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:[(W=s.logo)!=null&&W.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:ds(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 b;return(b=c.current)==null?void 0:b.click()},disabled:d,children:d?"...":e.jsx(I,{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:ms.map(({key:b,labelKey:T})=>{var B;return e.jsx("button",{className:`area-logo-pos-btn ${((B=s.logo)==null?void 0:B.position)===b?"active":""}`,onClick:()=>Z(b),children:o(`config:areas.${T}`)},b)})})]}),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:ae,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:X,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:Q}),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:ee,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 b;return(b=c.current)==null?void 0:b.click()},disabled:d,children:d?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:c,type:"file",accept:"image/*",style:{display:"none"},onChange:te})]})]}),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(b=>e.jsxs("div",{className:"area-folder-item",title:b,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(I,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:b.split("/").pop()||b}),e.jsx("button",{className:"area-folder-remove",onClick:T=>D(b,T),title:o("config:areas.removeFolder"),children:"×"})]},b)),h?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(De,{value:y,onChange:w,onSubmit:P,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:P,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:x,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 gs(){const{t:s}=q(["config","common"]),i=Re(),[n,o]=m.useState(!1),[r,p]=m.useState(null),[l,a]=m.useState({name:"",key:"",value:"",description:""}),h=()=>{o(!0),p(null),a({name:"",key:"",value:"",description:""})},A=c=>{p(c.id),o(!1),a({name:c.name,key:c.key,value:c.value,description:c.description||""})},y=()=>{o(!1),p(null),a({name:"",key:"",value:"",description:""})},w=()=>{!l.name.trim()||!l.key.trim()||(r?v.updateSecret(r,{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}),y())},d=c=>{confirm(s("config:secrets.deleteConfirm"))&&(v.deleteSecret(c),r===c&&y())},g=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 ${r===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:()=>g(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:()=>A(c),title:s("common:buttons.edit"),children:e.jsx(I,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>d(c.id),title:s("common:buttons.delete"),children:"×"})]})]}),c.description&&e.jsx("div",{className:"secret-item-description",children:c.description})]},c.id))}),(n||r)&&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:y,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:w,disabled:!l.name.trim()||!l.key.trim(),children:s(r?"config:secrets.update":"common:buttons.add")})]})]}),!n&&!r&&e.jsx("button",{className:"secrets-add-btn",onClick:h,children:s("config:secrets.addSecret")})]})}async function hs(){const s=R(),i=await fetch(`${K()}/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 ps(s){const i=R(),n=await fetch(`${K()}/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 fs(){const s=R(),i=await fetch(`${K()}/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 xs(){const s=R(),i=await fetch(`${K()}/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 bs(s){const i=R(),n=await fetch(`${K()}/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 js(){const s=R(),i=await fetch(`${K()}/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 vs(s){const i=R(),n=await fetch(`${K()}/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 Ns(){const s=R(),i=await fetch(`${K()}/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 ys(s){const i=R(),n=await fetch(`${K()}/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 ks(){const s=R(),i=await fetch(`${K()}/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 ws(s){const i=R(),n=await fetch(`${K()}/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 Ss({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 Cs(){const{t:s}=q(["config","common"]),[i,n]=m.useState([]),[o,r]=m.useState(new Set),[p,l]=m.useState(new Set),[a,h]=m.useState(!1),[A,y]=m.useState(!1),[w,d]=m.useState(null),[g,c]=m.useState(null),[C,S]=m.useState(null),[x,P]=m.useState(null),[D,$]=m.useState(!1),[u,k]=m.useState(null);m.useEffect(()=>{oe(G("/api/config/categories")).then(f=>f.json()).then(f=>{const E=Array.isArray(f)?f:[];n(E),r(new Set(E.map(L=>L.id)))}).catch(f=>console.error("Failed to fetch config categories:",f))},[]),m.useEffect(()=>{ks().then(P).catch(f=>{console.error("Failed to fetch backup status:",f),k(f.message||"Failed to fetch backup status")})},[]);const te=async f=>{if(!D){$(!0),k(null);try{const E=await ws(f);P(E)}catch(E){k(E.message||"Failed to update backup setting")}finally{$(!1)}}},H=f=>{r(E=>{const L=new Set(E);return L.has(f)?L.delete(f):L.add(f),L})},Z=f=>{l(E=>{const L=new Set(E);return L.has(f)?L.delete(f):L.add(f),L})},ae=()=>r(new Set(i.map(f=>f.id))),X=()=>r(new Set),Q=()=>{g&&l(new Set(g.categories.map(f=>f.id)))},ee=()=>l(new Set),W=async()=>{var f;if(o.size!==0){h(!0),S(null);try{const E=Array.from(o).join(","),L=await oe(G(`/api/config/export?categories=${E}`));if(!L.ok)throw new Error("Export failed");const M=await L.blob(),V=window.URL.createObjectURL(M),j=document.createElement("a");j.href=V;const _=L.headers.get("Content-Disposition"),le=((f=_==null?void 0:_.match(/filename="(.+)"/))==null?void 0:f[1])||"tide-commander-config.zip";j.download=le,document.body.appendChild(j),j.click(),document.body.removeChild(j),window.URL.revokeObjectURL(V),S({type:"success",text:s("config:data.exportSuccess")})}catch(E){S({type:"error",text:E.message||"Export failed"})}finally{h(!1)}}},b=async f=>{var L;const E=(L=f.target.files)==null?void 0:L[0];if(E){d(E),S(null),c(null),l(new Set);try{const M=await oe(G("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await E.arrayBuffer()});if(!M.ok){const _=await M.json();throw new Error(_.error||"Failed to preview config file")}const V=await M.json(),j=Array.isArray(V.categories)?V.categories:[];c({...V,categories:j}),l(new Set(j.map(_=>_.id)))}catch(M){S({type:"error",text:M.message||"Failed to read config file"}),d(null)}}},T=async()=>{if(!(!w||p.size===0)){y(!0),S(null);try{const f=Array.from(p).join(","),E=await oe(G(`/api/config/import?categories=${f}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await w.arrayBuffer()}),L=await E.json();if(!E.ok)throw new Error(L.error||"Import failed");S({type:"success",text:L.message||s("config:data.importSuccess")}),d(null),c(null),l(new Set)}catch(f){S({type:"error",text:f.message||"Import failed"})}finally{y(!1)}}},B=()=>{d(null),c(null),l(new Set),S(null)};return e.jsxs("div",{className:"data-section",children:[C&&e.jsx("div",{className:`data-message data-message-${C.type}`,children:C.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(Ss,{checked:!!(x!=null&&x.enabled),disabled:D||!x,onChange:te})]}),e.jsxs("div",{className:"data-backup-info",children:[x?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:x.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!x.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:x.scriptPath})]}),x.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(x.lastRunAt).toLocaleString(),x.lastRunOk===!0&&" — ok",x.lastRunOk===!1&&x.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",x.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),u&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:u})]})]}),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:ae,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:X,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:i.map(f=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(f.id),onChange:()=>H(f.id)}),e.jsx("span",{className:"data-category-name",children:f.name})]},f.id))}),e.jsx("button",{className:"data-action-btn export",onClick:W,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")})}),w?g?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:w.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:Q,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:ee,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:g.categories.map(f=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:p.has(f.id),onChange:()=>Z(f.id)}),e.jsx("span",{className:"data-category-name",children:f.name}),f.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",f.fileCount," ",s("config:data.files"),")"]})]},f.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:B,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:b,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}function As(){const[s,i]=m.useState(()=>Ue()),n=o=>{i(o);const r=Ke(o);qe(r)};return e.jsx("div",{className:"theme-selector",children:e.jsx("div",{className:"theme-selector-grid",children:Ve.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 Ts(){const{t:s}=q(["config"]),{updateAvailable:i,updateInfo:n,recentReleases:o,isChecking:r,error:p,currentVersion:l,isAndroid:a,checkForUpdate:h,downloadAndInstall:A,openReleasePage:y}=ts(),w=g=>g?`${(g/(1024*1024)).toFixed(1)} MB`:"",d=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(I,{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:y,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"),": ",w(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:y,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:y,children:s("config:about.viewRelease")})]})]}):e.jsxs("div",{className:"about-update-check",children:[e.jsx("span",{className:"about-update-status",children:s(r?"config:about.checkingUpdates":"config:about.upToDate")}),e.jsx("button",{className:"about-update-btn check",onClick:()=>h(!0),disabled:r,children:r?"...":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:d(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(I,{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 Es={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄"};function Is({onOpenModal:s}){const[i,n]=m.useState([]),[o,r]=m.useState(!0),p=m.useCallback(async()=>{try{const l=await oe(G("/api/integrations"));if(!l.ok)return;const a=await l.json();n(a)}catch{}finally{r(!1)}},[]);return m.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=Es[l.id]||"🔌",h=!!l.status.error,A=l.status.connected,y=h?"#f38ba8":A?"#a6e3a1":"#fab387",w=h?"Error":A?"Connected":"Setup Required",d=h?"✗":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:y,fontSize:11,fontWeight:500,whiteSpace:"nowrap"},children:[d," ",w]}),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 Ps({isOpen:s,onClose:i}){const{t:n}=q(["config"]),[o,r]=m.useState(""),[p,l]=m.useState(""),[a,h]=m.useState(!0),[A,y]=m.useState(null),[w,d]=m.useState(null),[g,c]=m.useState(!1);m.useEffect(()=>{s&&C()},[s]);const C=async()=>{try{h(!0),y(null),d(null);const u=await hs();r(u),l(u),c(!1)}catch(u){y(u instanceof Error?u.message:"Failed to load system prompt")}finally{h(!1)}},S=u=>{const k=u.target.value;r(k),c(k!==p),y(null),d(null)},x=async()=>{try{y(null),d(null),await ps(o),l(o),c(!1),d(n("config:systemPrompt.saved"))}catch(u){y(u instanceof Error?u.message:"Failed to save system prompt")}},P=async()=>{if(window.confirm(n("config:systemPrompt.confirmClear")))try{y(null),d(null),await fs(),r(""),l(""),c(!1),d(n("config:systemPrompt.cleared"))}catch(u){y(u instanceof Error?u.message:"Failed to clear system prompt")}},D=()=>{r(p),c(!1),y(null),d(null)},$=u=>{if(u.key==="Escape"){if(g&&!window.confirm("You have unsaved changes. Close anyway?")){u.preventDefault();return}i()}};return s?e.jsx(Me,{children:e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:i,children:e.jsxs("div",{className:"system-prompt-modal",onClick:u=>u.stopPropagation(),onKeyDown:$,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:n("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:i,"aria-label":"Close",children:e.jsx(I,{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(I,{name:"warn",size:14})}),A]}),w&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),w]}),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:S,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:P,disabled:!o||a,children:n("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:i,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:D,disabled:!g||a,children:n("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:x,disabled:!g||a,children:n("config:systemPrompt.save")})]})]})]})})}):null}const Ls=[{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:"🌙"}],Fs=[{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:"👎"}],Os=[{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:"💜"}],zs=[{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"}],_s=[{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"}],Bs={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},Ds={none:"grass","pokemon-stadium":"pokemon"},Rs={"emote-yes":"yes","emote-no":"no"},Us={"":"auto","#4a90d9":"dayBlue","#0a1a2a":"night","#ff6b35":"sunset","#1a0a2e":"purple","#2d5a27":"matrix","#8b0000":"blood","#000000":"void"};function U({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 se({options:s,value:i,onChange:n,iconOnly:o=!1}){return e.jsx("div",{className:"chip-selector",children:s.map(r=>e.jsxs("button",{className:`chip ${i===r.value?"active":""}`,onClick:()=>n(r.value),title:r.label,children:[e.jsx("span",{className:"chip-icon",children:r.icon}),!o&&e.jsx("span",{className:"chip-label",children:r.label})]},r.value))})}function N({text:s,query:i}){if(!i.trim())return e.jsx(e.Fragment,{children:s});const n=s.toLowerCase(),o=i.toLowerCase(),r=n.indexOf(o);if(r===-1)return e.jsx(e.Fragment,{children:s});const p=s.slice(0,r),l=s.slice(r,r+i.length),a=s.slice(r+i.length);return e.jsxs(e.Fragment,{children:[p,e.jsx("mark",{className:"search-highlight",children:l}),a]})}const Vs=[{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 Ks({config:s,onChange:i,searchQuery:n="",onOpenIntegrationsModal:o,onOpenMonitoringModal:r,onOpenWorkflowEditor:p,onOpenTriggerManager:l}){var ve;const{t:a}=q(["config","common"]),h=ge(),A=Ge(),[y,w]=m.useState(()=>He(ne.DEFAULT_AGENT_CLASS)||"scout"),[d,g]=m.useState(h.settings.historyLimit),[c,C]=m.useState(()=>We()),[S,x]=m.useState(!1),[P,D]=m.useState(()=>R()),[$,u]=m.useState(!1),[k,te]=m.useState(!1),[H,Z]=m.useState(""),[ae,X]=m.useState(!1),[Q,ee]=m.useState(""),[W,b]=m.useState(!1);m.useEffect(()=>{js().then(ee).catch(()=>{})},[]),m.useEffect(()=>{xs().then(t=>{t!==h.settings.experimentalEchoPrompt&&v.updateSettings({experimentalEchoPrompt:t})}).catch(()=>{})},[]),m.useEffect(()=>{Ns().then(t=>{t!==h.settings.tmuxMode&&v.updateSettings({tmuxMode:t})}).catch(()=>{})},[]),m.useEffect(()=>Ye(t=>{C(t),x(!1)}),[]);const T=Ls.map(t=>({...t,label:a(`config:time.${t.value}`)})),B=Fs.map(t=>({...t,label:a(`config:floor.${Ds[t.value]||t.value}`)})),f=$s.map(t=>({...t,label:a(`config:animation.${Rs[t.value]||t.value}`)})),E=Os.map(t=>({...t,label:a(`config:colorMode.${t.value}`)})),L=zs.map(t=>({...t,label:a(`config:terrain.${Bs[t.key]}`)})),M=_s.map(t=>({...t,label:a(`config:sky.${Us[t.value??""]}`)})),V=n.trim()?Vs.filter(t=>{const z=n.toLowerCase();return t.title.toLowerCase().includes(z)||t.keywords.some(ce=>ce.toLowerCase().includes(z))}).map(t=>t.id):null,j=t=>V?V.includes(t):!0,_=h.settings.customAgentNames||[],le=_.length>0?_:Je,pe=()=>{const t=H.trim();t&&!_.includes(t)&&(v.updateSettings({customAgentNames:[..._,t]}),Z(""))},Te=t=>{v.updateSettings({customAgentNames:_.filter(z=>z!==t)})},Ee=()=>{v.updateSettings({customAgentNames:[]})},Ie=t=>{C(t),x(!0)},fe=()=>{Xe(c),x(!1),me()},Pe=t=>{D(t),u(!0)},xe=()=>{ie(ne.AUTH_TOKEN,P),u(!1),me()},Le=t=>{ee(t),b(!0)},be=()=>{vs(Q).catch(()=>{}),b(!1)},Y=t=>{i({...s,terrain:{...s.terrain,...t}})},J=t=>{i({...s,modelStyle:{...s.modelStyle,...t}})},je=t=>{i({...s,animations:{...s.animations,...t}})},Fe=t=>{g(t),v.updateSettings({historyLimit:t})},$e=t=>{const z=s.terrain[t];typeof z=="boolean"&&Y({[t]:!z})},O=n.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-section",children:[V&&V.length===0&&e.jsx("div",{className:"config-no-results",children:a("config:noResults",{query:n})}),j("general")&&e.jsxs(F,{title:a("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:O&&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:d,onChange:t=>Fe(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(U,{checked:h.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(U,{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(U,{checked:h.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(I,{name:"bolt",size:12})]}),e.jsx(U,{checked:h.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(U,{checked:h.settings.tmuxMode,onChange:async t=>{v.updateSettings({tmuxMode:t});try{await ys(t)}catch(z){console.error("Failed to sync tmux mode setting to server:",z)}}})]}),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:h.settings.vibrationIntensity,onChange:t=>v.updateSettings({vibrationIntensity:parseInt(t.target.value)})}),e.jsx("span",{className:"config-value",children:h.settings.vibrationIntensity===0?a("config:vibrationValues.off"):h.settings.vibrationIntensity===1?a("config:vibrationValues.ultraLight"):h.settings.vibrationIntensity===2?a("config:vibrationValues.veryLight"):h.settings.vibrationIntensity===3?a("config:vibrationValues.light"):h.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:h.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:h.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(se,{options:ue,value:localStorage.getItem("tide-commander-language-mode")==="manual"?((ve=ue.find(t=>t.value!=="auto"&&de.language.startsWith(t.value.split("-")[0])))==null?void 0:ve.value)||"en":"auto",onChange:t=>{var z;if(t==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const ce=navigator.language,Oe=((z=ue.find(Ne=>Ne.value!=="auto"&&ce.startsWith(Ne.value.split("-")[0])))==null?void 0:z.value)||"en";de.changeLanguage(Oe)}else localStorage.setItem("tide-commander-language-mode","manual"),de.changeLanguage(t)}})]})]}),j("agentNames")&&e.jsx(F,{title:a("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:O&&j("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children:_.length>0?a("config:agentNames.customConfigured",{count:_.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=>Z(t.target.value),onKeyDown:t=>{t.key==="Enter"&&pe()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:pe,disabled:!H.trim(),title:a("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:le.map((t,z)=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:t}),_.length>0&&e.jsx("button",{className:"agent-name-remove",onClick:()=>Te(t),title:a("common:buttons.remove"),children:"x"})]},`${t}-${z}`))}),_.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:Ee,children:a("common:buttons.resetToDefaults")})]})}),j("defaultClass")&&e.jsx(F,{title:"Default Spawn Class",storageKey:"defaultClass",defaultOpen:!1,forceOpen:O&&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${y==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{w("random"),ie(ne.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries(Ze).map(([t,z])=>e.jsx("div",{className:`agent-name-chip${y===t?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{w(t),ie(ne.DEFAULT_AGENT_CLASS,t)},children:e.jsxs("span",{className:"agent-name-text",children:[z.icon," ",t.charAt(0).toUpperCase()+t.slice(1)]})},t)),A.map(t=>e.jsx("div",{className:`agent-name-chip${y===t.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{w(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(F,{title:a("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:O&&j("appearance"),children:e.jsx(As,{})}),j("connection")&&e.jsxs(F,{title:a("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:O&&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:c,onChange:t=>Ie(t.target.value),placeholder:"http://localhost:5174",onKeyDown:t=>{t.key==="Enter"&&S&&fe()}}),S&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:fe,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:k?"text":"password",className:"config-input config-input-full",value:P,onChange:t=>Pe(t.target.value),placeholder:a("config:connection.tokenPlaceholder"),onKeyDown:t=>{t.key==="Enter"&&$&&xe()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>te(!k),title:a(k?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(I,{name:k?"eye-closed":"eye",size:14})}),$&&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.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:Q,onChange:t=>Le(t.target.value),placeholder:a("config:connection.codexBinaryPathPlaceholder"),onKeyDown:t=>{t.key==="Enter"&&W&&be()}}),W&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:be,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(F,{title:a("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:O&&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(U,{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(se,{options:T,value:s.timeMode,onChange:t=>i({...s,timeMode:t}),iconOnly:!0})]})]}),j("terrain")&&e.jsxs(F,{title:a("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:O&&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(U,{checked:s.terrain.simpleMode??!1,onChange:t=>Y({simpleMode:t})})]}),e.jsx("div",{className:"terrain-icons",style:{opacity:s.terrain.simpleMode?.4:1,pointerEvents:s.terrain.simpleMode?"none":"auto"},children:L.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=>Y({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=>Y({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(se,{options:B,value:s.terrain.floorStyle,onChange:t=>Y({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:M.map(t=>e.jsx("button",{className:`sky-color-btn ${s.terrain.skyColor===t.value?"active":""}`,onClick:()=>Y({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=>Y({battlefieldSize:parseInt(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.battlefieldSize})]})]}),j("modelStyle")&&e.jsxs(F,{title:a("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:O&&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=>J({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=>J({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=>J({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=>J({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=>J({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(U,{checked:s.modelStyle.wireframe,onChange:t=>J({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(se,{options:E,value:s.modelStyle.colorMode,onChange:t=>J({colorMode:t}),iconOnly:!0})]})]}),j("animations")&&e.jsxs(F,{title:a("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:O&&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(se,{options:f,value:s.animations.idleAnimation,onChange:t=>je({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(se,{options:f,value:s.animations.workingAnimation,onChange:t=>je({workingAnimation:t}),iconOnly:!0})]})]}),j("secrets")&&e.jsx(F,{title:a("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:O&&j("secrets"),children:e.jsx(gs,{})}),j("systemPrompt")&&e.jsx(F,{title:a("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:O&&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:()=>X(!0),children:a("config:systemPrompt.editPrompt")})]})}),j("data")&&e.jsx(F,{title:a("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:O&&j("data"),children:e.jsx(Cs,{})}),j("integrations")&&e.jsx(F,{title:"Integrations",storageKey:"integrations",defaultOpen:!1,forceOpen:O&&j("integrations"),children:e.jsx(Is,{onOpenModal:t=>o==null?void 0:o(t)})}),j("workflows")&&e.jsxs(F,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:O&&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(F,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:O&&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(F,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:O&&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:()=>r==null?void 0:r(),children:"Open Monitoring & Logs"})})]}),j("experimental")&&e.jsxs(F,{title:a("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:O&&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(I,{name:"map",size:12})]}),e.jsx(U,{checked:h.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(I,{name:"microphone",size:12})]}),e.jsx(U,{checked:h.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(I,{name:"speaker-on",size:12})]}),e.jsx(U,{checked:h.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(U,{checked:h.settings.experimentalEchoPrompt,onChange:async t=>{v.updateSettings({experimentalEchoPrompt:t});try{await bs(t)}catch(z){console.error("Failed to sync echo prompt setting to server:",z)}}})]}),e.jsx("span",{className:"config-hint",children:a("config:experimental.hint")})]}),j("about")&&e.jsx(F,{title:a("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:O&&j("about"),children:e.jsx(Ts,{})})]}),e.jsx(Ps,{isOpen:ae,onClose:()=>X(!1)})]})}function Hs({onConfigChange:s,onToolChange:i,config:n,isOpen:o,onClose:r,onOpenBuildingModal:p,onOpenAreaExplorer:l,onOpenIntegrationsModal:a,onOpenMonitoringModal:h,onOpenWorkflowEditor:A,onOpenTriggerManager:y}){const{t:w}=q(["config","common"]),d=ge(),g=Array.from(d.areas.values()),c=Array.from(d.buildings.values()),[C,S]=m.useState(""),x=m.useRef(null);if(m.useEffect(()=>{const u=k=>{k.key==="Escape"&&o&&r()};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[o,r]),m.useEffect(()=>{if(o&&x.current){const u=setTimeout(()=>{var k;(k=x.current)==null||k.focus()},50);return()=>clearTimeout(u)}},[o]),!o)return null;const P=u=>{const k=d.activeTool===u?null:u;i(k)},D=u=>{v.selectArea(d.selectedAreaId===u?null:u),i("select")},$=(u,k)=>{u.stopPropagation(),v.deleteArea(k)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"toolbox-backdrop",onClick:r}),e.jsxs("aside",{className:"toolbox",children:[e.jsxs("div",{className:"toolbox-header",children:[e.jsx("span",{children:w("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:r,title:w("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:x,type:"text",placeholder:w("config:searchPlaceholder"),value:C,onChange:u=>S(u.target.value),className:"toolbox-search-input"}),C&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>S(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(F,{title:w("config:areas.title",{count:g.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${d.activeTool==="select"?"active":""}`,onClick:()=>P("select"),title:w("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 ${d.activeTool==="rectangle"?"active":""}`,onClick:()=>P("rectangle"),title:w("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 ${d.activeTool==="circle"?"active":""}`,onClick:()=>P("circle"),title:w("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:w("config:areas.drawToCreate")}):g.map(u=>e.jsx(os,{area:u,isSelected:d.selectedAreaId===u.id,onClick:()=>D(u.id),onDelete:k=>$(k,u.id)},u.id))})]})}),d.selectedAreaId&&e.jsx(us,{area:d.areas.get(d.selectedAreaId),onClose:()=>v.selectArea(null),onOpenFolder:l}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(F,{title:w("config:buildings.title",{count:c.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:u=>{u.stopPropagation(),p==null||p()},title:w("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:c.length===0?e.jsx("div",{className:"buildings-empty",children:w("config:buildings.clickToAdd")}):c.map(u=>e.jsx(is,{building:u,isSelected:d.selectedBuildingIds.has(u.id),onClick:()=>{v.selectBuilding(d.selectedBuildingIds.has(u.id)?null:u.id)},onEdit:()=>p==null?void 0:p(u.id)},u.id))})})}),d.selectedBuildingIds.size===1&&(()=>{const u=Array.from(d.selectedBuildingIds)[0],k=d.buildings.get(u);return k?e.jsx(ls,{building:k,onClose:()=>v.selectBuilding(null),onOpenModal:()=>p==null?void 0:p(u)}):null})(),e.jsx(Ks,{config:n,onChange:s,searchQuery:C,onOpenIntegrationsModal:a,onOpenMonitoringModal:h,onOpenWorkflowEditor:A,onOpenTriggerManager:y})]})]})]})}export{Hs as Toolbox};