tide-commander 1.111.2 → 1.112.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 (41) hide show
  1. package/dist/assets/{BossLogsModal-DLTh_jKZ.js → BossLogsModal-CwHTS7Io.js} +1 -1
  2. package/dist/assets/{BossSpawnModal-DzivoRl1.js → BossSpawnModal-BXfNSkDz.js} +1 -1
  3. package/dist/assets/{ControlsModal-B8j6My0t.js → ControlsModal-DR0t4ILF.js} +1 -1
  4. package/dist/assets/{DockerLogsModal-BNwx7lVp.js → DockerLogsModal-DwnzwL14.js} +1 -1
  5. package/dist/assets/{EmbeddedEditor-CBoOoGL8.js → EmbeddedEditor-Cgbf4PPi.js} +1 -1
  6. package/dist/assets/{GmailOAuthSetup-BACIjX54.js → GmailOAuthSetup-COUn-rL4.js} +1 -1
  7. package/dist/assets/{GoogleOAuthSetup-BuASGyWh.js → GoogleOAuthSetup-DY-oV0lC.js} +1 -1
  8. package/dist/assets/{IframeModal-ckpeQpQB.js → IframeModal-Cw0HXgic.js} +1 -1
  9. package/dist/assets/{IntegrationsPanel-Dh7UOnTC.js → IntegrationsPanel-Barw4hcr.js} +2 -2
  10. package/dist/assets/{LogViewerModal-Cj7Hv-mD.js → LogViewerModal-Wbt81evL.js} +1 -1
  11. package/dist/assets/{MonitoringModal-Bx4vcjBr.js → MonitoringModal-CNicCwC1.js} +1 -1
  12. package/dist/assets/{PM2LogsModal-RBIjfi4J.js → PM2LogsModal-CjxdOw_Q.js} +1 -1
  13. package/dist/assets/{RestoreArchivedAreaModal-BBYlYIso.js → RestoreArchivedAreaModal-DMQSgBDn.js} +1 -1
  14. package/dist/assets/{Scene2DCanvas-CYB1Y5Wa.js → Scene2DCanvas-Bv96khxo.js} +1 -1
  15. package/dist/assets/{SceneManager-6vk047Kd.js → SceneManager-BegYb5dZ.js} +1 -1
  16. package/dist/assets/{SkillsPanel-CRRypqdy.js → SkillsPanel-BMXqdVzv.js} +1 -1
  17. package/dist/assets/{SlackMultiInstanceSetup-DisMBGxX.js → SlackMultiInstanceSetup-C00oSgQy.js} +1 -1
  18. package/dist/assets/{SpawnModal-qiu5nT-F.js → SpawnModal-pU2K5vrz.js} +1 -1
  19. package/dist/assets/StatisticsModal-CC9rhzmt.js +1 -0
  20. package/dist/assets/{SubordinateAssignmentModal-AUCAiGkE.js → SubordinateAssignmentModal-BPSip6u2.js} +1 -1
  21. package/dist/assets/{TriggerManagerPanel-56SuYzNh.js → TriggerManagerPanel-DPSqS7Vo.js} +1 -1
  22. package/dist/assets/{WorkflowEditorPanel-H0IGkyMd.js → WorkflowEditorPanel-Cq7ZF7dg.js} +1 -1
  23. package/dist/assets/{index-pRI5GcXd.js → index-44R4VNzL.js} +1 -1
  24. package/dist/assets/{index--3sQ1gHE.js → index-B-I8YHsB.js} +3 -3
  25. package/dist/assets/{index-DFWA70Lq.js → index-BL_PuMCK.js} +1 -1
  26. package/dist/assets/{index-C-kx99MP.js → index-ByFl2HJL.js} +1 -1
  27. package/dist/assets/{index-DY395tVJ.js → index-CiYtVsF2.js} +2 -2
  28. package/dist/assets/{index-94AqwQn0.js → index-DFJv26as.js} +1 -1
  29. package/dist/assets/{index-Dv0tQnLX.js → index-DKYfRvHE.js} +1 -1
  30. package/dist/assets/{index-DZP3fZ3b.js → index-DhZrpzSa.js} +1 -1
  31. package/dist/assets/{index-9NugNkE4.js → index-WmtsKBi6.js} +1 -1
  32. package/dist/assets/{main-Bon1sZAi.js → main-D9ETZv9V.js} +20 -20
  33. package/dist/assets/{main-BUSv52j9.css → main-OfLIQ_-I.css} +1 -1
  34. package/dist/assets/{web-RZLwjKCT.js → web-B5kMJoeB.js} +1 -1
  35. package/dist/assets/{web-CccJFC0m.js → web-DthvRrDx.js} +1 -1
  36. package/dist/assets/{web-CdhZGenV.js → web-gLG4upzZ.js} +1 -1
  37. package/dist/index.html +2 -2
  38. package/dist/src/packages/server/routes/agents.js +17 -1
  39. package/dist/src/packages/server/services/claude-usage-service.js +164 -9
  40. package/package.json +1 -1
  41. package/dist/assets/StatisticsModal-Bzk7qqOd.js +0 -1
@@ -1 +1 @@
1
- import{u as J,a as Z,r,s as h,j as e,D as de,I as H,C as oe,b as me,c as be,d as ue,g as he,e as _e,Q as pe,R as xe}from"./main-Bon1sZAi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const fe=({building:a,connections:x,activeConnectionId:l,activeDatabase:c,collapsed:y,onToggleCollapse:f,onConnectionChange:Q,onDatabaseChange:S,onInsertTable:L,onSelectTableQuery:P})=>{const{t:m}=J(["terminal"]),q=Z(a.id),[I,R]=r.useState(new Set),[k,n]=r.useState(""),[d,g]=r.useState(""),[$,w]=r.useState(!1),[U,F]=r.useState(null),K=r.useRef(null),C=r.useRef(null),O=r.useRef(null),N=l?q.databases.get(l)??[]:[],G=l&&c?`${l}:${c}`:"",j=G?q.tables.get(G)??[]:[],p=l?q.connectionStatus.get(l):void 0,D=r.useMemo(()=>{if(!k.trim())return N;const t=k.toLowerCase();return N.filter(o=>o.toLowerCase().includes(t))},[N,k]),b=r.useMemo(()=>{if(!d.trim())return j;const t=d.toLowerCase();return j.filter(o=>o.name.toLowerCase().includes(t))},[j,d]);r.useEffect(()=>{const t=o=>{C.current&&!C.current.contains(o.target)&&w(!1)};return $&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[$]),r.useEffect(()=>{l&&!p&&h.testDatabaseConnection(a.id,l)},[a.id,l,p]),r.useEffect(()=>{l&&(p!=null&&p.connected)&&N.length===0&&h.listDatabases(a.id,l)},[a.id,l,p==null?void 0:p.connected,N.length]),r.useEffect(()=>{l&&c&&j.length===0&&h.listTables(a.id,l,c)},[a.id,l,c,j.length]),r.useEffect(()=>{F(null),g("")},[l,c]);const _=r.useCallback(t=>{R(o=>{const T=new Set(o);if(T.has(t))T.delete(t);else if(T.add(t),l&&c){const v=`${l}:${c}:${t}`;q.tableSchemas.has(v)||h.getTableSchema(a.id,l,c,t)}return T})},[a.id,l,c,q.tableSchemas]),z=t=>{if(!l||!c)return null;const o=`${l}:${c}:${t}`;return q.tableSchemas.get(o)};return y?e.jsx("div",{className:"database-sidebar database-sidebar--collapsed",children:e.jsx("button",{className:"database-sidebar__toggle",onClick:f,title:m("terminal:database.expandSidebar"),children:"»"})}):e.jsxs("div",{className:"database-sidebar",children:[e.jsxs("div",{className:"database-sidebar__header",children:[e.jsx("span",{children:m("terminal:database.explorer")}),e.jsx("button",{className:"database-sidebar__toggle",onClick:f,title:m("terminal:database.collapseSidebar"),children:"«"})]}),e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:m("terminal:database.connection")}),e.jsx("select",{className:"database-sidebar__select",value:l||"",onChange:t=>Q(t.target.value),children:x.length===0?e.jsx("option",{value:"",children:m("terminal:database.noConnections")}):x.map(t=>{var o;return e.jsxs("option",{value:t.id,children:[((o=de[t.engine])==null?void 0:o.icon)??"🗄️"," ",t.name]},t.id)})}),p&&e.jsx("div",{className:`database-sidebar__status ${p.connected?"database-sidebar__status--connected":"database-sidebar__status--error"}`,children:p.connected?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✓"}),m("terminal:database.connected"),p.serverVersion&&e.jsxs("span",{className:"database-sidebar__version",children:["(",p.serverVersion,")"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✗"}),p.error||m("terminal:database.disconnected")]})})]}),N.length>0&&e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:m("terminal:database.databaseTitle")}),e.jsxs("div",{className:"database-sidebar__searchable-select",ref:C,children:[e.jsx("input",{ref:K,className:"database-sidebar__search-input",type:"text",value:$?k:c||"",placeholder:m("terminal:database.selectDatabase"),onChange:t=>{n(t.target.value),$||w(!0)},onFocus:()=>{w(!0),n("")},onKeyDown:t=>{var o,T;t.key==="Escape"?(w(!1),n(""),(o=K.current)==null||o.blur()):t.key==="Enter"&&D.length===1&&(S(D[0]),w(!1),n(""),(T=K.current)==null||T.blur())}}),$&&e.jsx("div",{className:"database-sidebar__dropdown",children:D.length===0?e.jsx("div",{className:"database-sidebar__dropdown-empty",children:"No matches"}):D.map(t=>e.jsx("div",{className:`database-sidebar__dropdown-item ${t===c?"database-sidebar__dropdown-item--active":""}`,onMouseDown:o=>{o.preventDefault(),S(t),w(!1),n("")},children:t},t))})]})]}),j.length>0&&e.jsxs("div",{className:"database-sidebar__section database-sidebar__section--tables",children:[e.jsx("div",{className:"database-sidebar__section-title",children:d.trim()?m("terminal:database.tablesCount",{count:b.length})+` / ${j.length}`:m("terminal:database.tablesCount",{count:j.length})}),e.jsxs("div",{className:"database-sidebar__table-filter",children:[e.jsx("input",{ref:O,className:"database-sidebar__table-filter-input",type:"text",value:d,placeholder:m("terminal:database.filterTables"),onChange:t=>g(t.target.value),onKeyDown:t=>{var o;t.key==="Escape"&&(d?g(""):(o=O.current)==null||o.blur(),t.stopPropagation())}}),d&&e.jsx("button",{className:"database-sidebar__table-filter-clear",onClick:()=>{var t;g(""),(t=O.current)==null||t.focus()},title:"Clear filter",children:"×"})]}),e.jsxs("div",{className:"database-sidebar__tables",children:[d.trim()&&b.length===0&&e.jsx("div",{className:"database-sidebar__tables-empty",children:m("terminal:database.noTablesMatch")}),b.map(t=>{const o=I.has(t.name),T=o?z(t.name):null;return e.jsxs("div",{className:"database-sidebar__table",children:[e.jsxs("div",{className:"database-sidebar__table-header",children:[e.jsx("button",{className:"database-sidebar__table-expand",onClick:()=>_(t.name),title:o?"Collapse table schema":"Expand table schema",children:e.jsx(H,{name:o?"caret-down":"caret-right",size:10})}),e.jsx("span",{className:"database-sidebar__table-icon",children:e.jsx(H,{name:t.type==="view"?"eye":"clipboard",size:12})}),e.jsx("span",{className:`database-sidebar__table-name ${U===t.name?"database-sidebar__table-name--selected":""}`,onClick:()=>F(t.name),onDoubleClick:()=>{F(t.name),P(t.name)},children:t.name}),e.jsx("button",{className:"database-sidebar__table-insert",onClick:v=>{v.stopPropagation(),L(t.name)},title:m("terminal:database.insertTableName"),children:"+"})]}),o&&T&&e.jsx("div",{className:"database-sidebar__table-columns",children:T.columns.map(v=>e.jsxs("div",{className:"database-sidebar__column",onClick:()=>L(v.name),title:`${v.type}${v.nullable?" NULL":" NOT NULL"}${v.primaryKey?" PK":""}`,children:[e.jsx("span",{className:"database-sidebar__column-icon",children:v.primaryKey?e.jsx(H,{name:"key",size:11}):null}),e.jsx("span",{className:"database-sidebar__column-name",children:v.name}),e.jsx("span",{className:"database-sidebar__column-type",children:v.type})]},v.name))})]},t.name)})]})]})]})},je=({buildingId:a,history:x,onLoadQuery:l})=>{const{t:c}=J(["terminal","common"]),[y,f]=r.useState(""),[Q,S]=r.useState(!1),[L,P]=r.useState(!1),m=r.useMemo(()=>{let n=x;if(Q&&(n=n.filter(d=>d.favorite)),y.trim()){const d=y.toLowerCase();n=n.filter(g=>g.query.toLowerCase().includes(d)||g.database.toLowerCase().includes(d))}return n},[x,Q,y]),q=n=>{const d=new Date(n),$=new Date().getTime()-d.getTime();return $<1440*60*1e3?d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):$<10080*60*1e3?d.toLocaleDateString([],{weekday:"short"})+" "+d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):d.toLocaleDateString([],{month:"short",day:"numeric"})},I=r.useCallback((n,d)=>{d.stopPropagation(),h.toggleQueryFavorite(a,n)},[a]),R=r.useCallback((n,d)=>{d.stopPropagation(),h.deleteQueryFromHistory(a,n)},[a]),k=r.useCallback(()=>{P(!0)},[]);return x.length===0?e.jsxs("div",{className:"query-history query-history--empty",children:[e.jsx("p",{children:c("terminal:database.noHistory")}),e.jsx("p",{children:c("terminal:database.queriesAppearHere")})]}):e.jsxs("div",{className:"query-history",children:[e.jsxs("div",{className:"query-history__toolbar",children:[e.jsx("input",{type:"text",className:"query-history__search",placeholder:c("terminal:database.searchQueries"),value:y,onChange:n=>f(n.target.value)}),e.jsxs("label",{className:"query-history__filter",children:[e.jsx("input",{type:"checkbox",checked:Q,onChange:n=>S(n.target.checked)}),c("terminal:database.favoritesOnly")]}),e.jsx("button",{className:"query-history__clear",onClick:k,title:c("terminal:database.clearAll"),children:c("terminal:database.clearAll")})]}),e.jsxs("div",{className:"query-history__list",children:[m.map(n=>e.jsxs("div",{className:`query-history__item ${n.status==="error"?"query-history__item--error":""}`,onClick:()=>l(n.query),children:[e.jsxs("div",{className:"query-history__item-header",children:[e.jsx("span",{className:`query-history__status ${n.status==="success"?"query-history__status--success":"query-history__status--error"}`,children:e.jsx(H,{name:n.status==="success"?"check":"cross",size:12})}),e.jsx("span",{className:"query-history__database",children:n.database}),e.jsx("span",{className:"query-history__date",children:q(n.executedAt)}),e.jsxs("span",{className:"query-history__duration",children:[n.duration,"ms"]}),n.rowCount!==void 0&&e.jsx("span",{className:"query-history__row-count",children:c("terminal:database.rowCount",{count:n.rowCount})})]}),e.jsx("div",{className:"query-history__query",children:e.jsx("code",{children:n.query.length>200?n.query.substring(0,200)+"...":n.query})}),n.error&&e.jsx("div",{className:"query-history__error",children:n.error}),e.jsxs("div",{className:"query-history__actions",children:[e.jsx("button",{className:`query-history__favorite ${n.favorite?"query-history__favorite--active":""}`,onClick:d=>I(n.id,d),title:n.favorite?c("terminal:database.removeFromFavorites"):c("terminal:database.addToFavorites"),children:e.jsx(H,{name:"star",size:12,weight:n.favorite?"fill":"regular",color:n.favorite?"#facc15":void 0})}),e.jsx("button",{className:"query-history__delete",onClick:d=>R(n.id,d),title:c("terminal:database.deleteFromHistory"),children:e.jsx(H,{name:"trash",size:12})})]})]},n.id)),m.length===0&&e.jsx("div",{className:"query-history__no-results",children:c("terminal:database.noQueriesMatch")})]}),e.jsx(oe,{isOpen:L,title:c("terminal:database.clearAll"),message:c("terminal:database.confirmClearHistory"),confirmLabel:c("terminal:database.clearAll"),cancelLabel:c("common:buttons.cancel"),variant:"danger",onConfirm:()=>h.clearQueryHistory(a),onClose:()=>P(!1)})]})},ye=({tabs:a,activeTabId:x,onTabClick:l,onTabClose:c})=>{const{t:y}=J(["terminal"]);return e.jsx("div",{className:"database-tabs",children:a.map(f=>e.jsxs("div",{className:`database-tabs__tab ${x===f.id?"database-tabs__tab--active":""}`,children:[e.jsxs("button",{className:"database-tabs__tab-label",onClick:()=>l(f),title:`${f.connectionName} / ${f.database}`,children:[f.database,e.jsx("span",{className:"database-tabs__tab-connection",children:f.connectionName})]}),e.jsx("button",{className:"database-tabs__tab-close",onClick:()=>c(f.id),title:y("terminal:database.closeTab"),"aria-label":`Close ${f.database} tab`,children:"×"})]},f.id))})},ee=a=>`db-panel-${a}`;function Ne(a){try{const x=localStorage.getItem(ee(a));return x?JSON.parse(x):{}}catch{return{}}}function ve(a,x){try{localStorage.setItem(ee(a),JSON.stringify(x))}catch{}}const ge=({building:a,onClose:x})=>{var B,W,Y,X;const{t:l}=J(["terminal","common"]),c=Z(a.id),y=me(a.id),f=be(a.id),Q=ue(a.id),S=r.useRef(Ne(a.id)),L=r.useRef(null),P=r.useRef(0),m=((B=a.database)==null?void 0:B.connections)??[],q=(s,i)=>`${s}:${i}`,I=s=>s?(S.current.queries??{})[s]??"":S.current.generalQuery??"",[R,k]=r.useState("results"),[n,d]=r.useState(0),[g,$]=r.useState(!1),[w,U]=r.useState(!1),[F,K]=r.useState(()=>(S.current.openTabs??[]).map(i=>{var u;return{id:`${i.connectionId}:${i.database}`,connectionId:i.connectionId,connectionName:((u=m.find(A=>A.id===i.connectionId))==null?void 0:u.name)??i.connectionId,database:i.database}})),[C,O]=r.useState(S.current.activeTabId??null),[N,G]=r.useState(()=>{const s=S.current.queries??{};return S.current.generalQuery,s}),[j,p]=r.useState(I(C)),D=r.useCallback(s=>{p(i=>{const u=typeof s=="function"?s(i):s;return G(A=>{const E={...A};return C&&(E[C]=u),E}),u})},[C]),b=c.activeConnectionId??S.current.connectionId??((W=a.database)==null?void 0:W.activeConnectionId)??((Y=m[0])==null?void 0:Y.id),_=c.activeDatabase??S.current.database??((X=a.database)==null?void 0:X.activeDatabase),z=m.find(s=>s.id===b),t=b&&_?`${b}:${_}`:"",o=t?c.tables.get(t)??[]:[],T=r.useMemo(()=>{const s=new Map;return!b||!_||o.forEach(i=>{const u=c.tableSchemas.get(`${b}:${_}:${i.name}`);u&&s.set(i.name,{columns:u.columns})}),s},[b,_,o,c.tableSchemas]),v=r.useCallback((s,i)=>{var E;const u=q(s,i),A=((E=m.find(M=>M.id===s))==null?void 0:E.name)??s;K(M=>{if(M.some(ie=>ie.id===u))return M;const ce={id:u,connectionId:s,connectionName:A,database:i};return[...M,ce]}),O(u),p(N[u]??""),h.setActiveConnection(a.id,s),h.setActiveDatabase(a.id,i)},[a.id,m,N]),ae=r.useCallback(s=>{K(i=>i.filter(u=>u.id!==s)),C===s&&K(i=>{if(i.length>0){const u=i[0];O(u.id),p(N[u.id]??""),h.setActiveConnection(a.id,u.connectionId),h.setActiveDatabase(a.id,u.database)}else O(null),p("");return i})},[C,a.id,N]),se=r.useCallback(s=>{O(s.id),p(N[s.id]??""),h.setActiveConnection(a.id,s.connectionId),h.setActiveDatabase(a.id,s.database)},[a.id,N]);r.useEffect(()=>{if(!w&&m.length>0){const s=S.current;s.connectionId&&m.some(i=>i.id===s.connectionId)&&(h.setActiveConnection(a.id,s.connectionId),h.listDatabases(a.id,s.connectionId),s.database&&(h.setActiveDatabase(a.id,s.database),h.listTables(a.id,s.connectionId,s.database))),U(!0)}},[a.id,m,w]),r.useEffect(()=>{h.requestQueryHistory(a.id)},[a.id]),r.useEffect(()=>{const s=i=>{i.key==="Escape"&&(i.preventDefault(),i.stopPropagation(),x())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[x]),r.useEffect(()=>{w&&b&&ve(a.id,{connectionId:b,database:_,lastQuery:j,queries:N,generalQuery:"",openTabs:F.map(s=>({connectionId:s.connectionId,database:s.database})),activeTabId:C??void 0})},[a.id,b,_,j,w,F,C,N]);const te=r.useCallback(s=>{var i;if(!(!b||!_||!j.trim()||Q))if(s==="cursor"){const u=(i=L.current)==null?void 0:i.querySelector(".query-editor__textarea"),A=(u==null?void 0:u.selectionStart)??P.current,E=he(j,A);E&&h.executeQuery(a.id,b,_,E)}else{const u=_e(j);if(u.length<=1)h.executeQuery(a.id,b,_,j.trim());else{const A=b,E=_;(async()=>{for(const M of u)await h.executeQueryAndWait(a.id,A,E,M.sql)})()}}},[a.id,b,_,j,Q]),ne=r.useCallback(s=>{D(s),k("results")},[]),re=r.useCallback(s=>{h.setActiveConnection(a.id,s),h.listDatabases(a.id,s)},[a.id]),le=r.useCallback(s=>{b&&(v(b,s),h.listTables(a.id,b,s))},[a.id,b,v]),V=y[n];return m.length===0?e.jsxs("div",{className:"database-panel",ref:L,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:e.jsx(H,{name:"database",size:16})}),e.jsx("span",{className:"database-panel__name",children:a.name})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsx("div",{className:"database-panel__body",children:e.jsxs("div",{className:"database-panel__no-connections",children:[e.jsx("div",{className:"database-panel__no-connections-icon",children:e.jsx(H,{name:"plug",size:32})}),e.jsx("h3",{children:l("terminal:database.noConnections")}),e.jsx("p",{children:l("terminal:database.noConnectionsDesc")}),e.jsx("p",{children:l("terminal:database.toGetStarted")}),e.jsxs("ol",{children:[e.jsx("li",{children:l("terminal:database.step1Close")}),e.jsx("li",{children:l("terminal:database.step2Settings")}),e.jsx("li",{children:l("terminal:database.step3AddConnection")}),e.jsx("li",{children:l("terminal:database.step4Reopen")})]})]})})]}):e.jsxs("div",{className:"database-panel",ref:L,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:(z==null?void 0:z.engine)==="mysql"?"🐬":"🐘"}),e.jsx("span",{className:"database-panel__name",children:a.name}),z&&e.jsxs("span",{className:"database-panel__connection-info",children:[z.name," / ",_||l("terminal:database.noDatabaseSelected")]})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsxs("div",{className:"database-panel__body",children:[e.jsx(fe,{building:a,connections:m,activeConnectionId:b,activeDatabase:_,collapsed:g,onToggleCollapse:()=>$(!g),onConnectionChange:re,onDatabaseChange:le,onInsertTable:s=>D(i=>i+` ${s}`),onSelectTableQuery:s=>{const i=`SELECT * FROM ${s}`;D(i),b&&_&&h.executeQuery(a.id,b,_,i)}}),e.jsxs("div",{className:"database-panel__main",children:[F.length>0&&e.jsx(ye,{tabs:F,activeTabId:C,onTabClick:se,onTabClose:ae}),e.jsx(pe,{query:j,onChange:D,onExecute:te,isExecuting:Q,disabled:!b||!_,tables:o,tableSchemas:T,onRequestTableSchema:s=>{b&&_&&h.getTableSchema(a.id,b,_,s)}}),e.jsxs("div",{className:"database-panel__tabs",children:[e.jsxs("button",{className:`database-panel__tab ${R==="results"?"database-panel__tab--active":""}`,onClick:()=>k("results"),children:[l("terminal:database.results"),y.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:y.length})]}),e.jsxs("button",{className:`database-panel__tab ${R==="history"?"database-panel__tab--active":""}`,onClick:()=>k("history"),children:[l("terminal:database.history"),f.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:f.length})]}),R==="results"&&y.length>1&&e.jsxs("div",{className:"database-panel__result-nav",children:[e.jsxs("button",{disabled:n>=y.length-1,onClick:()=>d(s=>s+1),children:["← ",l("terminal:database.older")]}),e.jsxs("span",{children:[n+1," / ",y.length]}),e.jsxs("button",{disabled:n<=0,onClick:()=>d(s=>s-1),children:[l("terminal:database.newer")," →"]})]})]}),e.jsx("div",{className:"database-panel__tab-content",children:R==="results"?V?e.jsx(xe,{result:V,buildingId:a.id,building:a}):e.jsxs("div",{className:"database-panel__empty",children:[e.jsx("p",{children:l("terminal:database.noResultsYet")}),e.jsx("p",{children:l("terminal:database.selectDbAndRun")})]}):e.jsx(je,{buildingId:a.id,history:f,onLoadQuery:ne})})]})]})]})};export{ge as DatabasePanel,fe as DatabaseSidebar,ye as DatabaseTabs,pe as QueryEditor,je as QueryHistoryPanel,xe as ResultsTable};
1
+ import{u as J,a as Z,r,s as h,j as e,D as de,I as H,C as oe,b as me,c as be,d as ue,g as he,e as _e,Q as pe,R as xe}from"./main-D9ETZv9V.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const fe=({building:a,connections:x,activeConnectionId:l,activeDatabase:c,collapsed:y,onToggleCollapse:f,onConnectionChange:Q,onDatabaseChange:S,onInsertTable:L,onSelectTableQuery:P})=>{const{t:m}=J(["terminal"]),q=Z(a.id),[I,R]=r.useState(new Set),[k,n]=r.useState(""),[d,g]=r.useState(""),[$,w]=r.useState(!1),[U,F]=r.useState(null),K=r.useRef(null),C=r.useRef(null),O=r.useRef(null),N=l?q.databases.get(l)??[]:[],G=l&&c?`${l}:${c}`:"",j=G?q.tables.get(G)??[]:[],p=l?q.connectionStatus.get(l):void 0,D=r.useMemo(()=>{if(!k.trim())return N;const t=k.toLowerCase();return N.filter(o=>o.toLowerCase().includes(t))},[N,k]),b=r.useMemo(()=>{if(!d.trim())return j;const t=d.toLowerCase();return j.filter(o=>o.name.toLowerCase().includes(t))},[j,d]);r.useEffect(()=>{const t=o=>{C.current&&!C.current.contains(o.target)&&w(!1)};return $&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[$]),r.useEffect(()=>{l&&!p&&h.testDatabaseConnection(a.id,l)},[a.id,l,p]),r.useEffect(()=>{l&&(p!=null&&p.connected)&&N.length===0&&h.listDatabases(a.id,l)},[a.id,l,p==null?void 0:p.connected,N.length]),r.useEffect(()=>{l&&c&&j.length===0&&h.listTables(a.id,l,c)},[a.id,l,c,j.length]),r.useEffect(()=>{F(null),g("")},[l,c]);const _=r.useCallback(t=>{R(o=>{const T=new Set(o);if(T.has(t))T.delete(t);else if(T.add(t),l&&c){const v=`${l}:${c}:${t}`;q.tableSchemas.has(v)||h.getTableSchema(a.id,l,c,t)}return T})},[a.id,l,c,q.tableSchemas]),z=t=>{if(!l||!c)return null;const o=`${l}:${c}:${t}`;return q.tableSchemas.get(o)};return y?e.jsx("div",{className:"database-sidebar database-sidebar--collapsed",children:e.jsx("button",{className:"database-sidebar__toggle",onClick:f,title:m("terminal:database.expandSidebar"),children:"»"})}):e.jsxs("div",{className:"database-sidebar",children:[e.jsxs("div",{className:"database-sidebar__header",children:[e.jsx("span",{children:m("terminal:database.explorer")}),e.jsx("button",{className:"database-sidebar__toggle",onClick:f,title:m("terminal:database.collapseSidebar"),children:"«"})]}),e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:m("terminal:database.connection")}),e.jsx("select",{className:"database-sidebar__select",value:l||"",onChange:t=>Q(t.target.value),children:x.length===0?e.jsx("option",{value:"",children:m("terminal:database.noConnections")}):x.map(t=>{var o;return e.jsxs("option",{value:t.id,children:[((o=de[t.engine])==null?void 0:o.icon)??"🗄️"," ",t.name]},t.id)})}),p&&e.jsx("div",{className:`database-sidebar__status ${p.connected?"database-sidebar__status--connected":"database-sidebar__status--error"}`,children:p.connected?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✓"}),m("terminal:database.connected"),p.serverVersion&&e.jsxs("span",{className:"database-sidebar__version",children:["(",p.serverVersion,")"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✗"}),p.error||m("terminal:database.disconnected")]})})]}),N.length>0&&e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:m("terminal:database.databaseTitle")}),e.jsxs("div",{className:"database-sidebar__searchable-select",ref:C,children:[e.jsx("input",{ref:K,className:"database-sidebar__search-input",type:"text",value:$?k:c||"",placeholder:m("terminal:database.selectDatabase"),onChange:t=>{n(t.target.value),$||w(!0)},onFocus:()=>{w(!0),n("")},onKeyDown:t=>{var o,T;t.key==="Escape"?(w(!1),n(""),(o=K.current)==null||o.blur()):t.key==="Enter"&&D.length===1&&(S(D[0]),w(!1),n(""),(T=K.current)==null||T.blur())}}),$&&e.jsx("div",{className:"database-sidebar__dropdown",children:D.length===0?e.jsx("div",{className:"database-sidebar__dropdown-empty",children:"No matches"}):D.map(t=>e.jsx("div",{className:`database-sidebar__dropdown-item ${t===c?"database-sidebar__dropdown-item--active":""}`,onMouseDown:o=>{o.preventDefault(),S(t),w(!1),n("")},children:t},t))})]})]}),j.length>0&&e.jsxs("div",{className:"database-sidebar__section database-sidebar__section--tables",children:[e.jsx("div",{className:"database-sidebar__section-title",children:d.trim()?m("terminal:database.tablesCount",{count:b.length})+` / ${j.length}`:m("terminal:database.tablesCount",{count:j.length})}),e.jsxs("div",{className:"database-sidebar__table-filter",children:[e.jsx("input",{ref:O,className:"database-sidebar__table-filter-input",type:"text",value:d,placeholder:m("terminal:database.filterTables"),onChange:t=>g(t.target.value),onKeyDown:t=>{var o;t.key==="Escape"&&(d?g(""):(o=O.current)==null||o.blur(),t.stopPropagation())}}),d&&e.jsx("button",{className:"database-sidebar__table-filter-clear",onClick:()=>{var t;g(""),(t=O.current)==null||t.focus()},title:"Clear filter",children:"×"})]}),e.jsxs("div",{className:"database-sidebar__tables",children:[d.trim()&&b.length===0&&e.jsx("div",{className:"database-sidebar__tables-empty",children:m("terminal:database.noTablesMatch")}),b.map(t=>{const o=I.has(t.name),T=o?z(t.name):null;return e.jsxs("div",{className:"database-sidebar__table",children:[e.jsxs("div",{className:"database-sidebar__table-header",children:[e.jsx("button",{className:"database-sidebar__table-expand",onClick:()=>_(t.name),title:o?"Collapse table schema":"Expand table schema",children:e.jsx(H,{name:o?"caret-down":"caret-right",size:10})}),e.jsx("span",{className:"database-sidebar__table-icon",children:e.jsx(H,{name:t.type==="view"?"eye":"clipboard",size:12})}),e.jsx("span",{className:`database-sidebar__table-name ${U===t.name?"database-sidebar__table-name--selected":""}`,onClick:()=>F(t.name),onDoubleClick:()=>{F(t.name),P(t.name)},children:t.name}),e.jsx("button",{className:"database-sidebar__table-insert",onClick:v=>{v.stopPropagation(),L(t.name)},title:m("terminal:database.insertTableName"),children:"+"})]}),o&&T&&e.jsx("div",{className:"database-sidebar__table-columns",children:T.columns.map(v=>e.jsxs("div",{className:"database-sidebar__column",onClick:()=>L(v.name),title:`${v.type}${v.nullable?" NULL":" NOT NULL"}${v.primaryKey?" PK":""}`,children:[e.jsx("span",{className:"database-sidebar__column-icon",children:v.primaryKey?e.jsx(H,{name:"key",size:11}):null}),e.jsx("span",{className:"database-sidebar__column-name",children:v.name}),e.jsx("span",{className:"database-sidebar__column-type",children:v.type})]},v.name))})]},t.name)})]})]})]})},je=({buildingId:a,history:x,onLoadQuery:l})=>{const{t:c}=J(["terminal","common"]),[y,f]=r.useState(""),[Q,S]=r.useState(!1),[L,P]=r.useState(!1),m=r.useMemo(()=>{let n=x;if(Q&&(n=n.filter(d=>d.favorite)),y.trim()){const d=y.toLowerCase();n=n.filter(g=>g.query.toLowerCase().includes(d)||g.database.toLowerCase().includes(d))}return n},[x,Q,y]),q=n=>{const d=new Date(n),$=new Date().getTime()-d.getTime();return $<1440*60*1e3?d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):$<10080*60*1e3?d.toLocaleDateString([],{weekday:"short"})+" "+d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):d.toLocaleDateString([],{month:"short",day:"numeric"})},I=r.useCallback((n,d)=>{d.stopPropagation(),h.toggleQueryFavorite(a,n)},[a]),R=r.useCallback((n,d)=>{d.stopPropagation(),h.deleteQueryFromHistory(a,n)},[a]),k=r.useCallback(()=>{P(!0)},[]);return x.length===0?e.jsxs("div",{className:"query-history query-history--empty",children:[e.jsx("p",{children:c("terminal:database.noHistory")}),e.jsx("p",{children:c("terminal:database.queriesAppearHere")})]}):e.jsxs("div",{className:"query-history",children:[e.jsxs("div",{className:"query-history__toolbar",children:[e.jsx("input",{type:"text",className:"query-history__search",placeholder:c("terminal:database.searchQueries"),value:y,onChange:n=>f(n.target.value)}),e.jsxs("label",{className:"query-history__filter",children:[e.jsx("input",{type:"checkbox",checked:Q,onChange:n=>S(n.target.checked)}),c("terminal:database.favoritesOnly")]}),e.jsx("button",{className:"query-history__clear",onClick:k,title:c("terminal:database.clearAll"),children:c("terminal:database.clearAll")})]}),e.jsxs("div",{className:"query-history__list",children:[m.map(n=>e.jsxs("div",{className:`query-history__item ${n.status==="error"?"query-history__item--error":""}`,onClick:()=>l(n.query),children:[e.jsxs("div",{className:"query-history__item-header",children:[e.jsx("span",{className:`query-history__status ${n.status==="success"?"query-history__status--success":"query-history__status--error"}`,children:e.jsx(H,{name:n.status==="success"?"check":"cross",size:12})}),e.jsx("span",{className:"query-history__database",children:n.database}),e.jsx("span",{className:"query-history__date",children:q(n.executedAt)}),e.jsxs("span",{className:"query-history__duration",children:[n.duration,"ms"]}),n.rowCount!==void 0&&e.jsx("span",{className:"query-history__row-count",children:c("terminal:database.rowCount",{count:n.rowCount})})]}),e.jsx("div",{className:"query-history__query",children:e.jsx("code",{children:n.query.length>200?n.query.substring(0,200)+"...":n.query})}),n.error&&e.jsx("div",{className:"query-history__error",children:n.error}),e.jsxs("div",{className:"query-history__actions",children:[e.jsx("button",{className:`query-history__favorite ${n.favorite?"query-history__favorite--active":""}`,onClick:d=>I(n.id,d),title:n.favorite?c("terminal:database.removeFromFavorites"):c("terminal:database.addToFavorites"),children:e.jsx(H,{name:"star",size:12,weight:n.favorite?"fill":"regular",color:n.favorite?"#facc15":void 0})}),e.jsx("button",{className:"query-history__delete",onClick:d=>R(n.id,d),title:c("terminal:database.deleteFromHistory"),children:e.jsx(H,{name:"trash",size:12})})]})]},n.id)),m.length===0&&e.jsx("div",{className:"query-history__no-results",children:c("terminal:database.noQueriesMatch")})]}),e.jsx(oe,{isOpen:L,title:c("terminal:database.clearAll"),message:c("terminal:database.confirmClearHistory"),confirmLabel:c("terminal:database.clearAll"),cancelLabel:c("common:buttons.cancel"),variant:"danger",onConfirm:()=>h.clearQueryHistory(a),onClose:()=>P(!1)})]})},ye=({tabs:a,activeTabId:x,onTabClick:l,onTabClose:c})=>{const{t:y}=J(["terminal"]);return e.jsx("div",{className:"database-tabs",children:a.map(f=>e.jsxs("div",{className:`database-tabs__tab ${x===f.id?"database-tabs__tab--active":""}`,children:[e.jsxs("button",{className:"database-tabs__tab-label",onClick:()=>l(f),title:`${f.connectionName} / ${f.database}`,children:[f.database,e.jsx("span",{className:"database-tabs__tab-connection",children:f.connectionName})]}),e.jsx("button",{className:"database-tabs__tab-close",onClick:()=>c(f.id),title:y("terminal:database.closeTab"),"aria-label":`Close ${f.database} tab`,children:"×"})]},f.id))})},ee=a=>`db-panel-${a}`;function Ne(a){try{const x=localStorage.getItem(ee(a));return x?JSON.parse(x):{}}catch{return{}}}function ve(a,x){try{localStorage.setItem(ee(a),JSON.stringify(x))}catch{}}const ge=({building:a,onClose:x})=>{var B,W,Y,X;const{t:l}=J(["terminal","common"]),c=Z(a.id),y=me(a.id),f=be(a.id),Q=ue(a.id),S=r.useRef(Ne(a.id)),L=r.useRef(null),P=r.useRef(0),m=((B=a.database)==null?void 0:B.connections)??[],q=(s,i)=>`${s}:${i}`,I=s=>s?(S.current.queries??{})[s]??"":S.current.generalQuery??"",[R,k]=r.useState("results"),[n,d]=r.useState(0),[g,$]=r.useState(!1),[w,U]=r.useState(!1),[F,K]=r.useState(()=>(S.current.openTabs??[]).map(i=>{var u;return{id:`${i.connectionId}:${i.database}`,connectionId:i.connectionId,connectionName:((u=m.find(A=>A.id===i.connectionId))==null?void 0:u.name)??i.connectionId,database:i.database}})),[C,O]=r.useState(S.current.activeTabId??null),[N,G]=r.useState(()=>{const s=S.current.queries??{};return S.current.generalQuery,s}),[j,p]=r.useState(I(C)),D=r.useCallback(s=>{p(i=>{const u=typeof s=="function"?s(i):s;return G(A=>{const E={...A};return C&&(E[C]=u),E}),u})},[C]),b=c.activeConnectionId??S.current.connectionId??((W=a.database)==null?void 0:W.activeConnectionId)??((Y=m[0])==null?void 0:Y.id),_=c.activeDatabase??S.current.database??((X=a.database)==null?void 0:X.activeDatabase),z=m.find(s=>s.id===b),t=b&&_?`${b}:${_}`:"",o=t?c.tables.get(t)??[]:[],T=r.useMemo(()=>{const s=new Map;return!b||!_||o.forEach(i=>{const u=c.tableSchemas.get(`${b}:${_}:${i.name}`);u&&s.set(i.name,{columns:u.columns})}),s},[b,_,o,c.tableSchemas]),v=r.useCallback((s,i)=>{var E;const u=q(s,i),A=((E=m.find(M=>M.id===s))==null?void 0:E.name)??s;K(M=>{if(M.some(ie=>ie.id===u))return M;const ce={id:u,connectionId:s,connectionName:A,database:i};return[...M,ce]}),O(u),p(N[u]??""),h.setActiveConnection(a.id,s),h.setActiveDatabase(a.id,i)},[a.id,m,N]),ae=r.useCallback(s=>{K(i=>i.filter(u=>u.id!==s)),C===s&&K(i=>{if(i.length>0){const u=i[0];O(u.id),p(N[u.id]??""),h.setActiveConnection(a.id,u.connectionId),h.setActiveDatabase(a.id,u.database)}else O(null),p("");return i})},[C,a.id,N]),se=r.useCallback(s=>{O(s.id),p(N[s.id]??""),h.setActiveConnection(a.id,s.connectionId),h.setActiveDatabase(a.id,s.database)},[a.id,N]);r.useEffect(()=>{if(!w&&m.length>0){const s=S.current;s.connectionId&&m.some(i=>i.id===s.connectionId)&&(h.setActiveConnection(a.id,s.connectionId),h.listDatabases(a.id,s.connectionId),s.database&&(h.setActiveDatabase(a.id,s.database),h.listTables(a.id,s.connectionId,s.database))),U(!0)}},[a.id,m,w]),r.useEffect(()=>{h.requestQueryHistory(a.id)},[a.id]),r.useEffect(()=>{const s=i=>{i.key==="Escape"&&(i.preventDefault(),i.stopPropagation(),x())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[x]),r.useEffect(()=>{w&&b&&ve(a.id,{connectionId:b,database:_,lastQuery:j,queries:N,generalQuery:"",openTabs:F.map(s=>({connectionId:s.connectionId,database:s.database})),activeTabId:C??void 0})},[a.id,b,_,j,w,F,C,N]);const te=r.useCallback(s=>{var i;if(!(!b||!_||!j.trim()||Q))if(s==="cursor"){const u=(i=L.current)==null?void 0:i.querySelector(".query-editor__textarea"),A=(u==null?void 0:u.selectionStart)??P.current,E=he(j,A);E&&h.executeQuery(a.id,b,_,E)}else{const u=_e(j);if(u.length<=1)h.executeQuery(a.id,b,_,j.trim());else{const A=b,E=_;(async()=>{for(const M of u)await h.executeQueryAndWait(a.id,A,E,M.sql)})()}}},[a.id,b,_,j,Q]),ne=r.useCallback(s=>{D(s),k("results")},[]),re=r.useCallback(s=>{h.setActiveConnection(a.id,s),h.listDatabases(a.id,s)},[a.id]),le=r.useCallback(s=>{b&&(v(b,s),h.listTables(a.id,b,s))},[a.id,b,v]),V=y[n];return m.length===0?e.jsxs("div",{className:"database-panel",ref:L,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:e.jsx(H,{name:"database",size:16})}),e.jsx("span",{className:"database-panel__name",children:a.name})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsx("div",{className:"database-panel__body",children:e.jsxs("div",{className:"database-panel__no-connections",children:[e.jsx("div",{className:"database-panel__no-connections-icon",children:e.jsx(H,{name:"plug",size:32})}),e.jsx("h3",{children:l("terminal:database.noConnections")}),e.jsx("p",{children:l("terminal:database.noConnectionsDesc")}),e.jsx("p",{children:l("terminal:database.toGetStarted")}),e.jsxs("ol",{children:[e.jsx("li",{children:l("terminal:database.step1Close")}),e.jsx("li",{children:l("terminal:database.step2Settings")}),e.jsx("li",{children:l("terminal:database.step3AddConnection")}),e.jsx("li",{children:l("terminal:database.step4Reopen")})]})]})})]}):e.jsxs("div",{className:"database-panel",ref:L,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:(z==null?void 0:z.engine)==="mysql"?"🐬":"🐘"}),e.jsx("span",{className:"database-panel__name",children:a.name}),z&&e.jsxs("span",{className:"database-panel__connection-info",children:[z.name," / ",_||l("terminal:database.noDatabaseSelected")]})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsxs("div",{className:"database-panel__body",children:[e.jsx(fe,{building:a,connections:m,activeConnectionId:b,activeDatabase:_,collapsed:g,onToggleCollapse:()=>$(!g),onConnectionChange:re,onDatabaseChange:le,onInsertTable:s=>D(i=>i+` ${s}`),onSelectTableQuery:s=>{const i=`SELECT * FROM ${s}`;D(i),b&&_&&h.executeQuery(a.id,b,_,i)}}),e.jsxs("div",{className:"database-panel__main",children:[F.length>0&&e.jsx(ye,{tabs:F,activeTabId:C,onTabClick:se,onTabClose:ae}),e.jsx(pe,{query:j,onChange:D,onExecute:te,isExecuting:Q,disabled:!b||!_,tables:o,tableSchemas:T,onRequestTableSchema:s=>{b&&_&&h.getTableSchema(a.id,b,_,s)}}),e.jsxs("div",{className:"database-panel__tabs",children:[e.jsxs("button",{className:`database-panel__tab ${R==="results"?"database-panel__tab--active":""}`,onClick:()=>k("results"),children:[l("terminal:database.results"),y.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:y.length})]}),e.jsxs("button",{className:`database-panel__tab ${R==="history"?"database-panel__tab--active":""}`,onClick:()=>k("history"),children:[l("terminal:database.history"),f.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:f.length})]}),R==="results"&&y.length>1&&e.jsxs("div",{className:"database-panel__result-nav",children:[e.jsxs("button",{disabled:n>=y.length-1,onClick:()=>d(s=>s+1),children:["← ",l("terminal:database.older")]}),e.jsxs("span",{children:[n+1," / ",y.length]}),e.jsxs("button",{disabled:n<=0,onClick:()=>d(s=>s-1),children:[l("terminal:database.newer")," →"]})]})]}),e.jsx("div",{className:"database-panel__tab-content",children:R==="results"?V?e.jsx(xe,{result:V,buildingId:a.id,building:a}):e.jsxs("div",{className:"database-panel__empty",children:[e.jsx("p",{children:l("terminal:database.noResultsYet")}),e.jsx("p",{children:l("terminal:database.selectDbAndRun")})]}):e.jsx(je,{buildingId:a.id,history:f,onLoadQuery:ne})})]})]})]})};export{ge as DatabasePanel,fe as DatabaseSidebar,ye as DatabaseTabs,pe as QueryEditor,je as QueryHistoryPanel,xe as ResultsTable};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/web-RZLwjKCT.js","assets/main-Bon1sZAi.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-Chj50gSY.js","assets/main-BUSv52j9.css"])))=>i.map(i=>d[i]);
2
- import{cc as e,bD as o}from"./main-Bon1sZAi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";var i;(function(r){r.Heavy="HEAVY",r.Medium="MEDIUM",r.Light="LIGHT"})(i||(i={}));var t;(function(r){r.Success="SUCCESS",r.Warning="WARNING",r.Error="ERROR"})(t||(t={}));const c=e("Haptics",{web:()=>o(()=>import("./web-RZLwjKCT.js"),__vite__mapDeps([0,1,2,3,4])).then(r=>new r.HapticsWeb)});export{c as Haptics,i as ImpactStyle,t as NotificationType};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/web-B5kMJoeB.js","assets/main-D9ETZv9V.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-Chj50gSY.js","assets/main-OfLIQ_-I.css"])))=>i.map(i=>d[i]);
2
+ import{cd as e,bD as o}from"./main-D9ETZv9V.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";var i;(function(r){r.Heavy="HEAVY",r.Medium="MEDIUM",r.Light="LIGHT"})(i||(i={}));var t;(function(r){r.Success="SUCCESS",r.Warning="WARNING",r.Error="ERROR"})(t||(t={}));const c=e("Haptics",{web:()=>o(()=>import("./web-B5kMJoeB.js"),__vite__mapDeps([0,1,2,3,4])).then(r=>new r.HapticsWeb)});export{c as Haptics,i as ImpactStyle,t as NotificationType};
@@ -1,2 +1,2 @@
1
- import{r as a,z as rn,B as Tt,u as Wt,E as on,j as e,V as cn,G as dn,H as un,J as Pt,S as y,K as Lt,L as At,M as Rt,N as ht,O as le,P as pn,s as x,U as Ht,W as Vt,X as mn,v as Dt,w as zt,I as u,Y as fn,m as hn,Z as gn,_ as Xt,$ as Gt,a0 as xn,a1 as bn,a2 as _n,a3 as wn,a4 as vn,a5 as Cn,a6 as jn,a7 as Nn,a8 as kn,a9 as yn,aa as An,ab as In,ac as $t,C as Sn,ad as En,ae as Mn,af as Tn,ag as Pn,ah as Ln,ai as Rn,aj as Dn,ak as zn,al as $n,am as On,an as Bn,ao as Fn,ap as Wn,aq as Hn,ar as Vn,as as Xn,at as Gn}from"./main-Bon1sZAi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Un(w){const d=a.useRef(w);d.current=w,a.useEffect(()=>{if(!rn())return;let v=null,A=!1;return Tt.addListener("backButton",()=>{d.current()==="exit"&&Tt.exitApp()}).then(E=>{A?E.remove():v=E}),()=>{A=!0,v&&(v.remove(),v=null)}},[])}const qn=a.memo(function({className:d=""}){const{t:v}=Wt(["common"]),[A,E]=on(),K=a.useRef(null),[B,De]=a.useState(null);a.useLayoutEffect(()=>{const g=K.current;if(!g)return;const Z=g.querySelector(".view-mode-toggle__btn--active");Z&&De({left:Z.offsetLeft,width:Z.offsetWidth})},[A]);const ie=a.useCallback(g=>{if(g!==A){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:g}})),g==="3d"){requestAnimationFrame(()=>E(g));return}E(g)}},[A,E]);return e.jsxs("div",{className:`view-mode-toggle ${d}`,ref:K,children:[B&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:B.left,width:B.width}}),cn.map(g=>e.jsxs("button",{className:`view-mode-toggle__btn ${A===g?"view-mode-toggle__btn--active":""}`,onClick:()=>ie(g),title:v(`common:viewMode.descriptions.${g}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[g==="2d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]}),g==="3d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]}),g==="flat"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1"})]}),g==="dashboard"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"12",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"3",y:"16",width:"7",height:"5",rx:"1"})]})]}),e.jsx("span",{className:"view-mode-toggle__label",children:v(`common:viewMode.labels.${g}`)})]},g))]})}),gt=3,xt=280,Ot=320,yt=240,Bt=64,Yn=["simple","chat","advanced"],Kn={simple:"Simple",chat:"Chat",advanced:"Advanced"},Zn={simple:"○",chat:"◐",advanced:"◉"},Jn={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Ft="flat-clear-context";function Qn(w){const d=w.split("/").filter(Boolean);return d.length===0?w:d.slice(-2).join("/")}function ea(w){if(w.provider==="codex"){const K=w.codexModel||"gpt-5.3-codex",B=Vn[K];return{model:(B==null?void 0:B.label)||K}}if(w.provider==="opencode")return{model:w.opencodeModel||"opencode"};const d=w.model||"sonnet",v=Gn[d],A=w.effort,E=A?Xn[A]:void 0;return{model:(v==null?void 0:v.label)||d,effort:E==null?void 0:E.label}}function ta(w,d){if(d.type==="rectangle"&&d.width&&d.height){const v=d.width/2,A=d.height/2;return w.x>=d.center.x-v&&w.x<=d.center.x+v&&w.z>=d.center.z-A&&w.z<=d.center.z+A}if(d.type==="circle"&&d.radius){const v=w.x-d.center.x,A=w.z-d.center.z;return v*v+A*A<=d.radius*d.radius}return!1}const na=En.memo(function({agentId:d,terminalViewMode:v,onTerminalViewModeChange:A,inspectorOpen:E,onToggleInspector:K,onImageClick:B,onFileClick:De,onBashClick:ie,onViewMarkdown:g,onRequestClearSubordinates:Z,onOpenBuilding:ye,keyboard:Ge,canNavigateBack:Ue,canNavigateForward:qe,onNavigateBack:pe,onNavigateForward:re,agentInfoOpen:me,onToggleAgentInfo:Ye,onHeaderContextMenu:J,onBuildingContextMenu:fe}){var ne,ct,$,ae;const f=Mn(d),F=Vt(),W=a.useRef(null),Ae=a.useRef(null);a.useEffect(()=>{const l=Ae.current;if(!l)return;const r=c=>{c.button===3?(c.preventDefault(),c.stopPropagation(),pe()):c.button===4&&(c.preventDefault(),c.stopPropagation(),re())},o=c=>{(c.button===3||c.button===4)&&c.preventDefault()};return l.addEventListener("mouseup",r),l.addEventListener("mousedown",o),()=>{l.removeEventListener("mouseup",r),l.removeEventListener("mousedown",o)}},[pe,re]),a.useEffect(()=>{const l=Ae.current;if(!l)return;let r=0,o=0,c=0;const Pe=250,Le=600,Re=80,Y=1.5,We=O=>{let T=O instanceof HTMLElement?O:null;for(;T&&T!==l;){const Ve=window.getComputedStyle(T).overflowX;if((Ve==="auto"||Ve==="scroll")&&T.scrollWidth>T.clientWidth)return!0;T=T.parentElement}return!1},He=O=>{const T=Date.now();if(T<c){O.preventDefault();return}if(Math.abs(O.deltaX)<=Math.abs(O.deltaY)*Y){r=0;return}if(We(O.target)){r=0;return}T-o>Pe&&(r=0),o=T,r+=O.deltaX,r<=-Re?(r=0,c=T+Le,O.preventDefault(),pe()):r>=Re&&(r=0,c=T+Le,O.preventDefault(),re())};return l.addEventListener("wheel",He,{passive:!1}),()=>l.removeEventListener("wheel",He)},[pe,re]);const Ie=Ht(),he=a.useMemo(()=>{if(!f)return null;const l=new Set,r=[];for(const o of Ie.values())o.archived||o.directories.length===0||o.assignedAgentIds.includes(d)&&(l.add(o.id),r.push(o));for(const o of Ie.values())o.archived||o.directories.length===0||l.has(o.id)||ta({x:f.position.x,z:f.position.z},o)&&(l.add(o.id),r.push(o));return r.length===0?null:r.flatMap(o=>o.directories.filter(c=>c&&c.trim().length>0).map(c=>({areaId:o.id,areaName:o.name,dir:c})))},[f,d,Ie]),{branches:Ke,fetchRemote:Ze,fetchingDirs:Je}=Tn(he),ge=a.useMemo(()=>{var o;const l=x.getAreaForAgent(d);if(!l)return[];const r=[];for(const c of F.values())c.type==="terminal"&&x.isPositionInArea(c.position,l)&&r.push({id:c.id,name:c.name,hasUrl:!!((o=c.terminalStatus)!=null&&o.url)});return r},[d,F]),Qe=a.useMemo(()=>{var o;const l=x.getAreaForAgent(d);if(!l)return[];const r=[];for(const c of F.values())c.type==="server"&&((o=c.pm2)!=null&&o.enabled)&&x.isPositionInArea(c.position,l)&&r.push({id:c.id,name:c.name});return r},[d,F]),xe=a.useMemo(()=>{const l=x.getAreaForAgent(d);if(!l)return[];const r=[];for(const o of F.values())o.type==="database"&&o.database&&x.isPositionInArea(o.position,l)&&r.push({id:o.id,name:o.name});return r},[d,F]),[,be]=a.useReducer(l=>l+1,0),H=((ne=W.current)==null?void 0:ne.search.searchMode)??!1,oe=a.useCallback(()=>{var l;(l=W.current)==null||l.search.toggleSearch(),be()},[]),et=Pn(),ze=et.isPending(Ft),[V,X]=a.useState(null),D=V?F.get(V):null,{height:Se,onResizeStart:G}=Ln(),{sidePanelWidth:Ee,handleSidePanelResizeStart:ce}=Rn(),[z,tt]=a.useState(()=>At(y.GIT_PANEL_OPEN,!1)),[_e,$e]=a.useState(()=>At(y.BUILDINGS_PANEL_OPEN,!1)),[U,nt]=a.useState(!1),bt=a.useCallback(()=>{nt(l=>{const r=!l;return r&&Dn.setEnabled(!0),r})},[]),we=a.useCallback(()=>nt(!1),[]),_t=a.useCallback(()=>{tt(l=>{const r=!l;return le(y.GIT_PANEL_OPEN,r),r})},[]),at=a.useCallback(()=>{$e(l=>{const r=!l;return le(y.BUILDINGS_PANEL_OPEN,r),r})},[]),wt=a.useCallback(()=>{tt(!1),le(y.GIT_PANEL_OPEN,!1)},[]),Oe=a.useCallback(()=>{$e(!1),le(y.BUILDINGS_PANEL_OPEN,!1)},[]),vt=zn();a.useEffect(()=>{if(!V)return;ge.some(r=>r.id===V)||X(null)},[V,ge]);const[ve,de]=a.useState(!1),Be=a.useRef(null);if(a.useEffect(()=>{if(!ve)return;const l=r=>{Be.current&&!Be.current.contains(r.target)&&de(!1)};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[ve]),!f)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const Q=f.contextStats,st=!!Q,Ce=Q?Q.totalTokens:f.contextUsed||0,h=Q?Q.contextWindow:f.contextLimit||2e5,ee=Q?Q.usedPercent:Math.round(Ce/h*100),M=Math.max(0,Math.min(100,ee)),Me=Math.round(M*10)/10,lt=Math.round((100-M)*10)/10,it=M>=80?"#ff4a4a":M>=60?"#ff9e4a":M>=40?"#ffd700":"#4aff9e",rt=(Ce/1e3).toFixed(1),ot=(h/1e3).toFixed(1),te=f.cwd,Te=te?Qn(te):null,q=((ct=f.subordinateIds)==null?void 0:ct.length)||0,Fe=q>0;return e.jsxs("div",{ref:Ae,className:`flat-terminal-wrapper ${z||_e||U?"flat-terminal-wrapper--with-side-panel":""}`,style:{"--guake-side-panel-width":`min(${Ee}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${me?"flat-terminal-wrapper__header-main--active":""}`,onClick:Ye,onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),J({x:l.clientX,y:l.clientY})},title:me?"Hide agent info":"Show agent info","aria-pressed":me,children:[e.jsx(Xt,{agent:f,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:f.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:Gt(f.status)},children:f.status})]}),f.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:f.taskLabel,children:["📋 ",f.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:f.provider==="codex"?"/assets/codex.png":f.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:f.provider,className:"flat-terminal-wrapper__header-provider-icon",title:f.provider==="codex"?"Codex Agent":f.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:l,effort:r}=ea(f);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:r?`Model: ${l} · Effort: ${r}`:`Model: ${l}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:l}),r&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:r})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsx("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:Yn.map(l=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${v===l?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>A(l),title:Jn[l],"aria-pressed":v===l,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:Zn[l]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Kn[l]})]},l))}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:pe,disabled:!Ue,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(u,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:re,disabled:!qe,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(u,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${H?"flat-terminal-wrapper__action-btn--active":""}`,onClick:oe,title:H?"Close search":"Search messages","aria-pressed":H,children:e.jsx(u,{name:H?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${ze?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>et.handleClick(Ft,()=>{var l;x.clearContext(d),(l=W.current)==null||l.historyLoader.clearHistory()}),title:ze?"Click again to confirm clear context":"Clear context",children:e.jsx(u,{name:ze?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${z?"flat-terminal-wrapper__action-btn--active":""}`,onClick:_t,title:z?"Hide git panel":"Show git changes","aria-pressed":z,children:e.jsx(u,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${_e?"flat-terminal-wrapper__action-btn--active":""}`,onClick:at,title:_e?"Hide buildings panel":"Show area buildings","aria-pressed":_e,children:e.jsx(u,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:Be,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ve?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>de(l=>!l),title:"More actions","aria-expanded":ve,children:"⋮"}),ve&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${U?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{bt(),de(!1)},title:U?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(u,{name:"bug",size:14}),e.jsx("span",{children:U?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{x.collapseContext(d),de(!1)},disabled:f.status!=="idle",title:f.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(u,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),Fe&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{Z(d,q),de(!1)},children:[e.jsx(u,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",q," subordinate",q===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{x.killAgent(d),de(!1)},children:[e.jsx(u,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${E?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:K,title:E?"Hide inspector panel":"Show inspector panel","aria-label":E?"Hide inspector panel":"Show inspector panel","aria-pressed":E,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>x.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(u,{name:"cross",size:14})})]})]}),e.jsx($n,{ref:W,agentId:d,agent:f,viewMode:v,isOpen:!0,onImageClick:B,onFileClick:De,onBashClick:ie,onViewMarkdown:g,keyboard:Ge,hasModalOpen:!1}),D&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:G,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${D.name}`,style:{height:Se},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(u,{name:"terminal",size:12}),e.jsx("span",{children:D.name}),!(($=D.terminalStatus)!=null&&$.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>X(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(u,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:(ae=D.terminalStatus)!=null&&ae.url?e.jsx(On,{terminalUrl:D.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."})})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[f.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(u,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),te&&Te&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${te}`,"aria-label":`Open ${te} in file explorer`,role:"button",tabIndex:0,onClick:()=>x.openFileExplorer(te),onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),x.openFileExplorer(te))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(u,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:Te})]}),he&&he.map(({areaId:l,areaName:r,dir:o})=>{const c=Ke.get(o),Pe=Je.has(o),Le=o.split("/").filter(Boolean).pop()||o;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${r}: ${o}${c?` (${c.branch}${c.ahead?` ↑${c.ahead}`:""}${c.behind?` ↓${c.behind}`:""})`:""}`,onClick:()=>x.openFileExplorerForAreaFolder(l,o),children:[e.jsx(u,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:Le}),c&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(u,{name:"git-branch",size:10})," ",c.branch]}),c.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${c.ahead} ahead`,children:[e.jsx(u,{name:"arrow-up",size:9}),c.ahead]}),c.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${c.behind} behind`,children:[e.jsx(u,{name:"arrow-down",size:9}),c.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${Pe?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:Re=>{Re.stopPropagation(),Ze(o)},children:e.jsx(u,{name:Pe?"hourglass":"download",size:12})})]})]},`${l}:${o}`)}),e.jsxs("span",{className:"flat-terminal-wrapper__context",onClick:()=>x.setContextModalAgentId(d),title:st?`Context usage: ${rt}k / ${ot}k tokens (${Me}% used). Click to view stats.`:"Click to fetch context stats",children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(u,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${M}%`,backgroundColor:it}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:it},children:[rt,"k/",ot,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",lt,"% free)"]}),!st&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(u,{name:"warn",size:12})})]}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),ge.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:ge.map(l=>{const r=V===l.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""} ${l.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${r?"Hide":"Show"} terminal: ${l.name}${l.hasUrl?"":" (starting...)"}`,onClick:()=>{if(r){X(null);return}l.hasUrl||x.sendBuildingCommand(l.id,"start"),X(l.id)},onContextMenu:o=>{o.preventDefault(),o.stopPropagation(),fe(l.id,{x:o.clientX,y:o.clientY})},children:e.jsx(u,{name:"terminal",size:14})},l.id)})}),Qe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Qe.map(l=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${l.name}`,onClick:()=>ye(l.id),onContextMenu:r=>{r.preventDefault(),r.stopPropagation(),fe(l.id,{x:r.clientX,y:r.clientY})},children:e.jsx(u,{name:"scroll",size:14})},l.id))}),xe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:xe.map(l=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${l.name}`,onClick:()=>ye(l.id),onContextMenu:r=>{r.preventDefault(),r.stopPropagation(),fe(l.id,{x:r.clientX,y:r.clientY})},children:e.jsx(u,{name:"hard-drives",size:14})},l.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(Bn,{})})]}),z&&e.jsx(Fn,{agentId:d,agents:vt,onClose:wt,branchInfoMap:Ke,fetchRemote:Ze,fetchingDirs:Je,onResizeStart:l=>ce(l,"right")}),_e&&e.jsx(Wn,{agentId:d,onClose:Oe}),U&&e.jsx(Hn,{agentId:d,onClose:we})]})});function ia({onAgentClick:w,onBuildingClick:d,onBuildingDoubleClick:v,onBuildingPopup:A,onAreaContextMenu:E,onOpenSpawnModal:K,onOpenBossSpawnModal:B,onOpenAreaModal:De}){const{t:ie}=Wt(["common"]),g=dn(),Z=un(),[ye,Ge]=a.useState(null),[Ue,qe]=a.useState(null),[pe,re]=a.useState(null),[me,Ye]=a.useState(null),[J,fe]=a.useState(null),[f,F]=a.useState(null),[W,Ae]=a.useState(null),[Ie,he]=a.useState(!1),Ke=a.useCallback(()=>{he(t=>!t)},[]),Ze=a.useCallback(()=>{he(!1)},[]),[Je,ge]=a.useState(()=>{const t=Pt(y.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Qe=a.useCallback(t=>{ge(t),Lt(y.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=n=>{if(n.key!==y.VIEW_MODE)return;const s=n.newValue;(s==="simple"||s==="chat"||s==="advanced")&&ge(s)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[xe,be]=a.useState(()=>At(y.FLAT_INSPECTOR_OPEN,!1)),[H,oe]=a.useState(!1),et=a.useCallback(()=>oe(t=>!t),[]),ze=a.useCallback(()=>oe(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:H}}))},[H]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:xe}}))},[xe]),a.useEffect(()=>{const t=()=>oe(_=>!_),n=()=>{be(_=>{const i=!_;return le(y.FLAT_INSPECTOR_OPEN,i),i})},s=()=>{oe(!1),be(!1),le(y.FLAT_INSPECTOR_OPEN,!1)},p=()=>oe(!1),m=()=>{be(!1),le(y.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",n),window.addEventListener("tide-close-flat-side-views",s),window.addEventListener("tide-close-flat-agents-drawer-only",p),window.addEventListener("tide-close-flat-inspector-only",m),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",n),window.removeEventListener("tide-close-flat-side-views",s),window.removeEventListener("tide-close-flat-agents-drawer-only",p),window.removeEventListener("tide-close-flat-inspector-only",m)}},[]);const V=a.useRef(null),X=a.useRef(null),[D,Se]=a.useState(()=>{const t=Rt(y.FLAT_MIDDLE_WIDTH,0);return t>=xt?t:null}),[G,Ee]=a.useState(()=>{const t=Rt(y.FLAT_INSPECTOR_WIDTH,0);return t>=yt?t:null}),ce=a.useCallback(t=>{if(typeof window>"u")return t;const n=G!==null?gt+G:0,s=window.innerWidth-Bt-gt-Ot-n;return Math.max(xt,Math.min(Math.max(s,xt),t))},[G]),z=a.useCallback(t=>{var m;if(typeof window>"u")return t;const n=(m=V.current)==null?void 0:m.querySelector(".flat-middle"),s=(n==null?void 0:n.getBoundingClientRect().width)??xt,p=window.innerWidth-Bt-s-gt-Ot-gt;return Math.max(yt,Math.min(Math.max(p,yt),t))},[]);a.useEffect(()=>{if(D===null&&G===null)return;const t=()=>{Se(n=>{if(n===null)return n;const s=ce(n);return s===n?n:s}),Ee(n=>{if(n===null)return n;const s=z(n);return s===n?n:s})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[D,G,ce,z]);const tt=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=V.current)==null?void 0:s.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),X.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),_e=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=V.current)==null?void 0:s.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),X.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),$e=a.useCallback(t=>{const n=X.current;if(!n||t.pointerId!==n.pointerId)return;const s=t.clientX-n.startX;n.kind==="middle"?Se(ce(n.startWidth+s)):Ee(z(n.startWidth-s))},[ce,z]),U=a.useCallback(t=>{const n=X.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(X.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const p=t.clientX-n.startX;if(n.kind==="middle"){const m=ce(n.startWidth+p);Se(m),ht(y.FLAT_MIDDLE_WIDTH,m)}else{const m=z(n.startWidth-p);Ee(m),ht(y.FLAT_INSPECTOR_WIDTH,m)}},[ce,z]),nt=a.useCallback(()=>{Se(null),ht(y.FLAT_MIDDLE_WIDTH,0)},[]),bt=a.useCallback(()=>{Ee(null),ht(y.FLAT_INSPECTOR_WIDTH,0)},[]),[we,_t]=a.useState(()=>Pt(y.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),at=a.useCallback(t=>{_t(t),Lt(y.FLAT_INSPECTOR_VIEW,t)},[]),wt=a.useCallback(()=>{be(t=>{const n=!t;return le(y.FLAT_INSPECTOR_OPEN,n),n})},[]),Oe=a.useCallback(()=>{be(!1),le(y.FLAT_INSPECTOR_OPEN,!1)},[]),vt=pn(),ve=a.useCallback((t,n)=>{Ge({url:t,name:n})},[]),de=a.useCallback((t,n)=>{qe({command:t,output:n,isLive:!1})},[]),Be=a.useCallback((t,n)=>{x.setFileViewerPath(t,n)},[]),Q=a.useCallback(t=>{re(t)},[]),st=a.useCallback((t,n)=>{Ye({agentId:t,count:n})},[]),Ce=a.useCallback(t=>{v?v(t):d(t)},[d,v]),h=a.useMemo(()=>Z.size>0?Array.from(Z)[0]:null,[Z]);a.useEffect(()=>{he(!1)},[h]);const ee=a.useRef([]),M=a.useRef(-1),Me=a.useRef(!1),lt=a.useRef(null),[it,rt]=a.useState(!1),[ot,te]=a.useState(!1),Te=a.useRef(!1),q=a.useRef(null),Fe=a.useRef(!1),ne=a.useMemo(()=>new Set(g.map(t=>t.id)),[g]),ct=a.useMemo(()=>{const t=new Map(g.map(s=>[s.id,s])),n=new Map;for(const s of g)if((s.isBoss||s.class==="boss")&&s.subordinateIds&&s.subordinateIds.length>0){const p=s.subordinateIds.map(m=>t.get(m)).filter(m=>m!==void 0);p.length>0&&n.set(s.id,p)}return n},[g]),$=a.useCallback(()=>{const t=ee.current,n=M.current;rt(n>0),te(n>=0&&n<t.length-1)},[]),ae=a.useCallback(t=>{const n=ee.current;if(n.length===0)return;let s=M.current+t;for(;s>=0&&s<n.length;){const p=n[s];if(ne.has(p)){Me.current=!0,M.current=s,$(),x.selectAgent(p);return}s+=t}},[ne,$]),l=a.useCallback(()=>ae(-1),[ae]),r=a.useCallback(()=>ae(1),[ae]);Un(a.useCallback(()=>{const t=ee.current,n=M.current;return t.length>0&&n>0?(ae(-1),"handled"):"exit"},[ae]));const o=a.useCallback((t,n)=>{if(typeof window>"u")return;const s=window.history.state,m={...typeof s=="object"&&s!==null?s:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(m,"",window.location.href):window.history.pushState(m,"",window.location.href)},[]);a.useEffect(()=>{if(!h){Te.current=!1,q.current=null;return}if(!Te.current){o(h,"replace"),Te.current=!0,q.current=h;return}if(Fe.current){Fe.current=!1,q.current=h;return}q.current!==h&&(o(h,"push"),q.current=h)},[h,o]),a.useEffect(()=>{const t=n=>{var _,i;const s=(i=(_=n.state)==null?void 0:_.__flatAgentNav)==null?void 0:i.agentId;if(!s||typeof s!="string"||!ne.has(s)||s===h)return;Fe.current=!0,Me.current=!0;const p=ee.current,m=p.lastIndexOf(s);m>=0?M.current=m:(p.push(s),M.current=p.length-1),$(),x.selectAgent(s)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[ne,h,$]),a.useEffect(()=>{if(!h){ee.current=[],M.current=-1,$();return}if(lt.current=h,Me.current){Me.current=!1,$();return}const t=ee.current,n=M.current;if(n>=0&&t[n]===h){$();return}const s=n<t.length-1?t.slice(0,n+1):t.slice();s.push(h),s.length>100&&s.shift(),ee.current=s,M.current=s.length-1,$()},[h,$]);const c=a.useCallback(t=>{w(t),oe(!1)},[w]),Pe=h??"",Le=a.useCallback(()=>{},[]),Re=a.useCallback(t=>{c(t)},[c]),Y=xe,[We,He]=a.useState(Y),[O,T]=a.useState(Y);a.useEffect(()=>{if(Y){He(!0);return}T(!1);const t=setTimeout(()=>He(!1),240);return()=>clearTimeout(t)},[Y]),a.useEffect(()=>{if(!We||!Y)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>T(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[We,Y]);const Ve=a.useRef(null);a.useEffect(()=>{if(h)return;const t=n=>{if(n.key!==" "&&n.key!=="Backspace")return;const s=n.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const p=lt.current;!p||!ne.has(p)||(n.preventDefault(),x.selectAgent(p))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[h,ne]);const[Ut,It]=a.useState(new Set),qt=a.useCallback(t=>{It(n=>{const s=new Set(n);return s.has(t)?s.delete(t):s.add(t),s})},[]),[je,Yt]=a.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),n=s=>Yt(s.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const[dt,Kt]=a.useState(null),Zt=a.useCallback(t=>{Kt(n=>n===t?null:t)},[]),Ct=Ht(),ut=Vt(),[Jt]=mn(),Ne=a.useMemo(()=>{const t=new Map,n=[];for(const b of g){const k=x.getAreaForAgent(b.id);if(!Dt((k==null?void 0:k.id)??null))continue;if(!k||k.archived){n.push(b);continue}const N=t.get(k.id);N?N.push(b):t.set(k.id,[b])}const s=new Map,p=[];for(const b of ut.values()){let k=!1;for(const N of Ct.values())if(!N.archived&&zt(N.id)&&x.isPositionInArea(b.position,N)){const se=s.get(N.id);se?se.push(b):s.set(N.id,[b]),k=!0;break}!k&&Dt(null)&&p.push(b)}const m=[];for(const[,b]of Ct){if(b.archived||!zt(b.id))continue;const k=t.get(b.id),N=s.get(b.id)??[];(k&&k.length>0||N.length>0)&&m.push({area:b,agents:k??[],buildings:N})}(n.length>0||p.length>0)&&m.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:n,buildings:p});const _=m.filter(b=>b.area.id!=="__unassigned__"),i=m.filter(b=>b.area.id==="__unassigned__");let I=1,j=1;const S=new Map;if(_.length>1){let b=1/0,k=-1/0,N=1/0,se=-1/0;for(const L of _)b=Math.min(b,L.area.center.x),k=Math.max(k,L.area.center.x),N=Math.min(N,L.area.center.z),se=Math.max(se,L.area.center.z);const pt=k-b||1,mt=se-N||1;if(_.length<=4){I=_.length,j=1;const L=[..._].sort((R,jt)=>R.area.center.x-jt.area.center.x);for(let R=0;R<L.length;R++)S.set(L[R].area.id,{row:1,col:R+1})}else{const L=[..._].sort((C,P)=>C.area.center.x-P.area.center.x),R=[];for(let C=1;C<L.length;C++)R.push(L[C].area.center.x-L[C-1].area.center.x);const jt=R.reduce((C,P)=>C+P,0)/R.length||1;let St=1;for(const C of R)C>jt*1.3&&St++;I=Math.max(2,Math.min(St,_.length));const Nt=[..._].sort((C,P)=>C.area.center.z-P.area.center.z),ft=[];for(let C=1;C<Nt.length;C++)ft.push(Nt[C].area.center.z-Nt[C-1].area.center.z);const nn=ft.reduce((C,P)=>C+P,0)/ft.length||1;let Et=1;for(const C of ft)C>nn*1.3&&Et++;j=Math.max(2,Math.min(Et,_.length)),I=Math.max(I,Math.ceil(_.length/j)),j=Math.max(j,Math.ceil(_.length/I));const an=pt/I,sn=mt/j,kt=new Set;for(const C of _){let P=Math.min(I-1,Math.max(0,Math.floor((C.area.center.x-b)/an))),ke=Math.min(j-1,Math.max(0,Math.floor((C.area.center.z-N)/sn))),Xe=`${ke},${P}`,Mt=0;const ln=j*I;for(;kt.has(Xe)&&Mt<ln;)P++,P>=I&&(P=0,ke=(ke+1)%j),Xe=`${ke},${P}`,Mt++;kt.has(Xe)&&(ke=j,P=0,Xe=`${ke},${P}`,j++),kt.add(Xe),S.set(C.area.id,{row:ke+1,col:P+1})}}}const ue=b=>{b.sort((k,N)=>{var pt,mt,L,R;const se=(((pt=k.position)==null?void 0:pt.z)??0)-(((mt=N.position)==null?void 0:mt.z)??0);return se!==0?se:(((L=k.position)==null?void 0:L.x)??0)-(((R=N.position)==null?void 0:R.x)??0)})};for(const b of _)ue(b.agents);for(const b of i)ue(b.agents);return{groups:[..._,...i],gridCols:I,gridRows:j,positions:S}},[g,Ct,ut,Jt]),Qt=a.useMemo(()=>{if(!J)return[];const t=g.find(n=>n.id===J.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(u,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(u,{name:"chat",size:14}),onClick:()=>w(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>{Ae({agentId:t.id,name:t.name})}}]:[]},[J,g,w]),en=a.useMemo(()=>{var _;if(!f)return[];const t=ut.get(f.buildingId);if(!t)return[];const n=[],s=t.type==="server"||t.type==="docker"||t.type==="terminal",p=t.status==="running",m=t.type==="boss";if(n.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((_=t.pm2)!=null&&_.enabled)?"View PM2 Logs":"Open",icon:e.jsx(u,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>Ce(t.id)}),s&&(p||n.push({id:"start",label:"Start",icon:e.jsx(u,{name:"play",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"start")}),p&&(n.push({id:"restart",label:"Restart",icon:e.jsx(u,{name:"refresh",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(u,{name:"stop",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"stop")}))),m&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(n.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(u,{name:"launch",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"start")}}),n.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(u,{name:"pause",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"stop")}}),n.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(u,{name:"restart",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"restart")}})),s&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(u,{name:"health",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"healthCheck")}),n.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),n.push({id:"edit",label:"Edit Building",icon:e.jsx(u,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),n.push({id:"clone",label:"Clone Building",icon:e.jsx(u,{name:"copy",size:14}),onClick:()=>{x.createBuilding({name:`${t.name} (Copy)`,type:t.type,style:t.style,color:t.color,scale:t.scale,position:{x:t.position.x+2,z:t.position.z+2},cwd:t.cwd,folderPath:t.folderPath,commands:t.commands,pm2:t.pm2,docker:t.docker,database:t.database,terminal:t.terminal,urls:t.urls,subordinateBuildingIds:t.subordinateBuildingIds})}}),t.urls&&t.urls.length>0)for(const i of t.urls)n.push({id:`url-${i.label}`,label:i.label,icon:e.jsx(u,{name:"link",size:14}),onClick:()=>window.open(i.url,"_blank","noopener,noreferrer")});return n.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),n.push({id:"delete",label:"Delete Building",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>x.deleteBuilding(t.id)}),n},[f,ut,Ce]),tn=a.useCallback(t=>{const n=new Set(Ne.groups.map(s=>s.area.id));n.delete(t),It(n),requestAnimationFrame(()=>{const s=Ve.current;if(!s)return;const p=s.querySelector(`[data-area-id="${t}"]`);if(!p)return;const m=s.getBoundingClientRect(),i=p.getBoundingClientRect().top-m.top+s.scrollTop-8;s.scrollTo({top:Math.max(0,i),behavior:"smooth"})})},[Ne]);return e.jsxs("div",{ref:V,className:`flat-view ${Y?"flat-view--with-inspector":""} ${h?"flat-view--has-chat":""} ${H?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(D===null&&G===null)return;const t={};return D!==null&&(t["--flat-middle-width"]=`${D}px`),G!==null&&(t["--flat-inspector-width"]=`${G}px`),t})(),children:[H&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:ze,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children:e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:K,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:B,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:De,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(fn,{activeAgentId:Pe,onClose:Le,onSelectAgent:Re,collapsedAreas:Ut,onToggleArea:qt,agentListRef:Ve})})]}),e.jsx("div",{className:"flat-splitter flat-splitter--middle",role:"separator","aria-orientation":"vertical","aria-label":"Resize agents panel",title:"Drag to resize · Double-click to reset",onPointerDown:tt,onPointerMove:$e,onPointerUp:U,onPointerCancel:U,onDoubleClick:nt}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":H?"Close agents sidebar":"Open agents sidebar","aria-expanded":H,onClick:et,children:[e.jsx(u,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),h?e.jsx(na,{agentId:h,terminalViewMode:Je,onTerminalViewModeChange:Qe,inspectorOpen:xe,onToggleInspector:wt,onImageClick:ve,onFileClick:Be,onBashClick:de,onViewMarkdown:Q,onRequestClearSubordinates:st,onOpenBuilding:Ce,keyboard:vt,canNavigateBack:it,canNavigateForward:ot,onNavigateBack:l,onNavigateForward:r,agentInfoOpen:Ie,onToggleAgentInfo:Ke,onHeaderContextMenu:t=>{h&&fe({agentId:h,position:t})},onBuildingContextMenu:(t,n)=>{F({buildingId:t,position:n})}}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"}),e.jsx(qn,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Ne.gridCols}, 1fr)`},children:Ne.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var n;const t=je&&dt?((n=Ne.positions.get(dt))==null?void 0:n.row)??null:null;return Ne.groups.map(s=>{const p=s.area.id,m=Ne.positions.get(p),_=je&&dt!==p;return je&&t!=null&&(m==null?void 0:m.row)===t&&p!==dt?null:e.jsxs("div",{className:`flat-map-area-card${_?" flat-map-area-card--collapsed":""}`,style:{"--area-color":s.area.color,gridRow:m==null?void 0:m.row,gridColumn:m==null?void 0:m.col},onContextMenu:i=>{E&&(i.preventDefault(),i.stopPropagation(),E(p,{x:i.clientX,y:i.clientY}))},children:[e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>je?Zt(p):tn(p),title:je?_?`Expand ${s.area.name}`:`Collapse ${s.area.name}`:`Focus ${s.area.name} in left panel`,"aria-expanded":je?!_:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:s.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:s.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:s.agents.length}),je&&e.jsx(u,{name:_?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:s.agents.map(i=>{const I=i.isBoss||i.class==="boss",j=I?ct.get(i.id):void 0,S=hn(i),ue=S.usedPercent>=80?"#ff4a4a":S.usedPercent>=60?"#ff9e4a":S.usedPercent>=40?"#ffd700":"#4aff9e",b=`Context: ${(S.totalTokens/1e3).toFixed(1)}k / ${(S.contextWindow/1e3).toFixed(1)}k (${S.usedPercent}% used, ${S.freePercent}% free)`,k=i.latestTodos&&i.latestTodos.length>0||j&&j.length>0;return e.jsx(gn,{todos:i.latestTodos,subordinates:j,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${i.status}`,onClick:()=>w(i.id),onContextMenu:N=>{N.preventDefault(),N.stopPropagation(),fe({agentId:i.id,position:{x:N.clientX,y:N.clientY}})},title:k?void 0:`${I?"Boss · ":""}Open chat with ${i.name}
1
+ import{r as a,z as rn,B as Tt,u as Wt,E as on,j as e,V as cn,G as dn,H as un,J as Pt,S as y,K as Lt,L as At,M as Rt,N as ht,O as le,P as pn,s as x,U as Ht,W as Vt,X as mn,v as Dt,w as zt,I as u,Y as fn,m as hn,Z as gn,_ as Xt,$ as Gt,a0 as xn,a1 as bn,a2 as _n,a3 as wn,a4 as vn,a5 as Cn,a6 as jn,a7 as Nn,a8 as kn,a9 as yn,aa as An,ab as In,ac as $t,C as Sn,ad as En,ae as Mn,af as Tn,ag as Pn,ah as Ln,ai as Rn,aj as Dn,ak as zn,al as $n,am as On,an as Bn,ao as Fn,ap as Wn,aq as Hn,ar as Vn,as as Xn,at as Gn}from"./main-D9ETZv9V.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Un(w){const d=a.useRef(w);d.current=w,a.useEffect(()=>{if(!rn())return;let v=null,A=!1;return Tt.addListener("backButton",()=>{d.current()==="exit"&&Tt.exitApp()}).then(E=>{A?E.remove():v=E}),()=>{A=!0,v&&(v.remove(),v=null)}},[])}const qn=a.memo(function({className:d=""}){const{t:v}=Wt(["common"]),[A,E]=on(),K=a.useRef(null),[B,De]=a.useState(null);a.useLayoutEffect(()=>{const g=K.current;if(!g)return;const Z=g.querySelector(".view-mode-toggle__btn--active");Z&&De({left:Z.offsetLeft,width:Z.offsetWidth})},[A]);const ie=a.useCallback(g=>{if(g!==A){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:g}})),g==="3d"){requestAnimationFrame(()=>E(g));return}E(g)}},[A,E]);return e.jsxs("div",{className:`view-mode-toggle ${d}`,ref:K,children:[B&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:B.left,width:B.width}}),cn.map(g=>e.jsxs("button",{className:`view-mode-toggle__btn ${A===g?"view-mode-toggle__btn--active":""}`,onClick:()=>ie(g),title:v(`common:viewMode.descriptions.${g}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[g==="2d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]}),g==="3d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]}),g==="flat"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1"})]}),g==="dashboard"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"12",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"3",y:"16",width:"7",height:"5",rx:"1"})]})]}),e.jsx("span",{className:"view-mode-toggle__label",children:v(`common:viewMode.labels.${g}`)})]},g))]})}),gt=3,xt=280,Ot=320,yt=240,Bt=64,Yn=["simple","chat","advanced"],Kn={simple:"Simple",chat:"Chat",advanced:"Advanced"},Zn={simple:"○",chat:"◐",advanced:"◉"},Jn={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Ft="flat-clear-context";function Qn(w){const d=w.split("/").filter(Boolean);return d.length===0?w:d.slice(-2).join("/")}function ea(w){if(w.provider==="codex"){const K=w.codexModel||"gpt-5.3-codex",B=Vn[K];return{model:(B==null?void 0:B.label)||K}}if(w.provider==="opencode")return{model:w.opencodeModel||"opencode"};const d=w.model||"sonnet",v=Gn[d],A=w.effort,E=A?Xn[A]:void 0;return{model:(v==null?void 0:v.label)||d,effort:E==null?void 0:E.label}}function ta(w,d){if(d.type==="rectangle"&&d.width&&d.height){const v=d.width/2,A=d.height/2;return w.x>=d.center.x-v&&w.x<=d.center.x+v&&w.z>=d.center.z-A&&w.z<=d.center.z+A}if(d.type==="circle"&&d.radius){const v=w.x-d.center.x,A=w.z-d.center.z;return v*v+A*A<=d.radius*d.radius}return!1}const na=En.memo(function({agentId:d,terminalViewMode:v,onTerminalViewModeChange:A,inspectorOpen:E,onToggleInspector:K,onImageClick:B,onFileClick:De,onBashClick:ie,onViewMarkdown:g,onRequestClearSubordinates:Z,onOpenBuilding:ye,keyboard:Ge,canNavigateBack:Ue,canNavigateForward:qe,onNavigateBack:pe,onNavigateForward:re,agentInfoOpen:me,onToggleAgentInfo:Ye,onHeaderContextMenu:J,onBuildingContextMenu:fe}){var ne,ct,$,ae;const f=Mn(d),F=Vt(),W=a.useRef(null),Ae=a.useRef(null);a.useEffect(()=>{const l=Ae.current;if(!l)return;const r=c=>{c.button===3?(c.preventDefault(),c.stopPropagation(),pe()):c.button===4&&(c.preventDefault(),c.stopPropagation(),re())},o=c=>{(c.button===3||c.button===4)&&c.preventDefault()};return l.addEventListener("mouseup",r),l.addEventListener("mousedown",o),()=>{l.removeEventListener("mouseup",r),l.removeEventListener("mousedown",o)}},[pe,re]),a.useEffect(()=>{const l=Ae.current;if(!l)return;let r=0,o=0,c=0;const Pe=250,Le=600,Re=80,Y=1.5,We=O=>{let T=O instanceof HTMLElement?O:null;for(;T&&T!==l;){const Ve=window.getComputedStyle(T).overflowX;if((Ve==="auto"||Ve==="scroll")&&T.scrollWidth>T.clientWidth)return!0;T=T.parentElement}return!1},He=O=>{const T=Date.now();if(T<c){O.preventDefault();return}if(Math.abs(O.deltaX)<=Math.abs(O.deltaY)*Y){r=0;return}if(We(O.target)){r=0;return}T-o>Pe&&(r=0),o=T,r+=O.deltaX,r<=-Re?(r=0,c=T+Le,O.preventDefault(),pe()):r>=Re&&(r=0,c=T+Le,O.preventDefault(),re())};return l.addEventListener("wheel",He,{passive:!1}),()=>l.removeEventListener("wheel",He)},[pe,re]);const Ie=Ht(),he=a.useMemo(()=>{if(!f)return null;const l=new Set,r=[];for(const o of Ie.values())o.archived||o.directories.length===0||o.assignedAgentIds.includes(d)&&(l.add(o.id),r.push(o));for(const o of Ie.values())o.archived||o.directories.length===0||l.has(o.id)||ta({x:f.position.x,z:f.position.z},o)&&(l.add(o.id),r.push(o));return r.length===0?null:r.flatMap(o=>o.directories.filter(c=>c&&c.trim().length>0).map(c=>({areaId:o.id,areaName:o.name,dir:c})))},[f,d,Ie]),{branches:Ke,fetchRemote:Ze,fetchingDirs:Je}=Tn(he),ge=a.useMemo(()=>{var o;const l=x.getAreaForAgent(d);if(!l)return[];const r=[];for(const c of F.values())c.type==="terminal"&&x.isPositionInArea(c.position,l)&&r.push({id:c.id,name:c.name,hasUrl:!!((o=c.terminalStatus)!=null&&o.url)});return r},[d,F]),Qe=a.useMemo(()=>{var o;const l=x.getAreaForAgent(d);if(!l)return[];const r=[];for(const c of F.values())c.type==="server"&&((o=c.pm2)!=null&&o.enabled)&&x.isPositionInArea(c.position,l)&&r.push({id:c.id,name:c.name});return r},[d,F]),xe=a.useMemo(()=>{const l=x.getAreaForAgent(d);if(!l)return[];const r=[];for(const o of F.values())o.type==="database"&&o.database&&x.isPositionInArea(o.position,l)&&r.push({id:o.id,name:o.name});return r},[d,F]),[,be]=a.useReducer(l=>l+1,0),H=((ne=W.current)==null?void 0:ne.search.searchMode)??!1,oe=a.useCallback(()=>{var l;(l=W.current)==null||l.search.toggleSearch(),be()},[]),et=Pn(),ze=et.isPending(Ft),[V,X]=a.useState(null),D=V?F.get(V):null,{height:Se,onResizeStart:G}=Ln(),{sidePanelWidth:Ee,handleSidePanelResizeStart:ce}=Rn(),[z,tt]=a.useState(()=>At(y.GIT_PANEL_OPEN,!1)),[_e,$e]=a.useState(()=>At(y.BUILDINGS_PANEL_OPEN,!1)),[U,nt]=a.useState(!1),bt=a.useCallback(()=>{nt(l=>{const r=!l;return r&&Dn.setEnabled(!0),r})},[]),we=a.useCallback(()=>nt(!1),[]),_t=a.useCallback(()=>{tt(l=>{const r=!l;return le(y.GIT_PANEL_OPEN,r),r})},[]),at=a.useCallback(()=>{$e(l=>{const r=!l;return le(y.BUILDINGS_PANEL_OPEN,r),r})},[]),wt=a.useCallback(()=>{tt(!1),le(y.GIT_PANEL_OPEN,!1)},[]),Oe=a.useCallback(()=>{$e(!1),le(y.BUILDINGS_PANEL_OPEN,!1)},[]),vt=zn();a.useEffect(()=>{if(!V)return;ge.some(r=>r.id===V)||X(null)},[V,ge]);const[ve,de]=a.useState(!1),Be=a.useRef(null);if(a.useEffect(()=>{if(!ve)return;const l=r=>{Be.current&&!Be.current.contains(r.target)&&de(!1)};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[ve]),!f)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const Q=f.contextStats,st=!!Q,Ce=Q?Q.totalTokens:f.contextUsed||0,h=Q?Q.contextWindow:f.contextLimit||2e5,ee=Q?Q.usedPercent:Math.round(Ce/h*100),M=Math.max(0,Math.min(100,ee)),Me=Math.round(M*10)/10,lt=Math.round((100-M)*10)/10,it=M>=80?"#ff4a4a":M>=60?"#ff9e4a":M>=40?"#ffd700":"#4aff9e",rt=(Ce/1e3).toFixed(1),ot=(h/1e3).toFixed(1),te=f.cwd,Te=te?Qn(te):null,q=((ct=f.subordinateIds)==null?void 0:ct.length)||0,Fe=q>0;return e.jsxs("div",{ref:Ae,className:`flat-terminal-wrapper ${z||_e||U?"flat-terminal-wrapper--with-side-panel":""}`,style:{"--guake-side-panel-width":`min(${Ee}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${me?"flat-terminal-wrapper__header-main--active":""}`,onClick:Ye,onContextMenu:l=>{l.preventDefault(),l.stopPropagation(),J({x:l.clientX,y:l.clientY})},title:me?"Hide agent info":"Show agent info","aria-pressed":me,children:[e.jsx(Xt,{agent:f,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:f.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:Gt(f.status)},children:f.status})]}),f.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:f.taskLabel,children:["📋 ",f.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:f.provider==="codex"?"/assets/codex.png":f.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:f.provider,className:"flat-terminal-wrapper__header-provider-icon",title:f.provider==="codex"?"Codex Agent":f.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:l,effort:r}=ea(f);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:r?`Model: ${l} · Effort: ${r}`:`Model: ${l}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:l}),r&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:r})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsx("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:Yn.map(l=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${v===l?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>A(l),title:Jn[l],"aria-pressed":v===l,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:Zn[l]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:Kn[l]})]},l))}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:pe,disabled:!Ue,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(u,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:re,disabled:!qe,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(u,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${H?"flat-terminal-wrapper__action-btn--active":""}`,onClick:oe,title:H?"Close search":"Search messages","aria-pressed":H,children:e.jsx(u,{name:H?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${ze?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>et.handleClick(Ft,()=>{var l;x.clearContext(d),(l=W.current)==null||l.historyLoader.clearHistory()}),title:ze?"Click again to confirm clear context":"Clear context",children:e.jsx(u,{name:ze?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${z?"flat-terminal-wrapper__action-btn--active":""}`,onClick:_t,title:z?"Hide git panel":"Show git changes","aria-pressed":z,children:e.jsx(u,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${_e?"flat-terminal-wrapper__action-btn--active":""}`,onClick:at,title:_e?"Hide buildings panel":"Show area buildings","aria-pressed":_e,children:e.jsx(u,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:Be,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${ve?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>de(l=>!l),title:"More actions","aria-expanded":ve,children:"⋮"}),ve&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${U?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{bt(),de(!1)},title:U?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(u,{name:"bug",size:14}),e.jsx("span",{children:U?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{x.collapseContext(d),de(!1)},disabled:f.status!=="idle",title:f.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(u,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),Fe&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{Z(d,q),de(!1)},children:[e.jsx(u,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",q," subordinate",q===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{x.killAgent(d),de(!1)},children:[e.jsx(u,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${E?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:K,title:E?"Hide inspector panel":"Show inspector panel","aria-label":E?"Hide inspector panel":"Show inspector panel","aria-pressed":E,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>x.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(u,{name:"cross",size:14})})]})]}),e.jsx($n,{ref:W,agentId:d,agent:f,viewMode:v,isOpen:!0,onImageClick:B,onFileClick:De,onBashClick:ie,onViewMarkdown:g,keyboard:Ge,hasModalOpen:!1}),D&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:G,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${D.name}`,style:{height:Se},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(u,{name:"terminal",size:12}),e.jsx("span",{children:D.name}),!(($=D.terminalStatus)!=null&&$.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>X(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(u,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:(ae=D.terminalStatus)!=null&&ae.url?e.jsx(On,{terminalUrl:D.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."})})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[f.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(u,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),te&&Te&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${te}`,"aria-label":`Open ${te} in file explorer`,role:"button",tabIndex:0,onClick:()=>x.openFileExplorer(te),onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),x.openFileExplorer(te))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(u,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:Te})]}),he&&he.map(({areaId:l,areaName:r,dir:o})=>{const c=Ke.get(o),Pe=Je.has(o),Le=o.split("/").filter(Boolean).pop()||o;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${r}: ${o}${c?` (${c.branch}${c.ahead?` ↑${c.ahead}`:""}${c.behind?` ↓${c.behind}`:""})`:""}`,onClick:()=>x.openFileExplorerForAreaFolder(l,o),children:[e.jsx(u,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:Le}),c&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(u,{name:"git-branch",size:10})," ",c.branch]}),c.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${c.ahead} ahead`,children:[e.jsx(u,{name:"arrow-up",size:9}),c.ahead]}),c.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${c.behind} behind`,children:[e.jsx(u,{name:"arrow-down",size:9}),c.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${Pe?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:Re=>{Re.stopPropagation(),Ze(o)},children:e.jsx(u,{name:Pe?"hourglass":"download",size:12})})]})]},`${l}:${o}`)}),e.jsxs("span",{className:"flat-terminal-wrapper__context",onClick:()=>x.setContextModalAgentId(d),title:st?`Context usage: ${rt}k / ${ot}k tokens (${Me}% used). Click to view stats.`:"Click to fetch context stats",children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(u,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${M}%`,backgroundColor:it}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:it},children:[rt,"k/",ot,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",lt,"% free)"]}),!st&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(u,{name:"warn",size:12})})]}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),ge.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:ge.map(l=>{const r=V===l.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""} ${l.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${r?"Hide":"Show"} terminal: ${l.name}${l.hasUrl?"":" (starting...)"}`,onClick:()=>{if(r){X(null);return}l.hasUrl||x.sendBuildingCommand(l.id,"start"),X(l.id)},onContextMenu:o=>{o.preventDefault(),o.stopPropagation(),fe(l.id,{x:o.clientX,y:o.clientY})},children:e.jsx(u,{name:"terminal",size:14})},l.id)})}),Qe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:Qe.map(l=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${l.name}`,onClick:()=>ye(l.id),onContextMenu:r=>{r.preventDefault(),r.stopPropagation(),fe(l.id,{x:r.clientX,y:r.clientY})},children:e.jsx(u,{name:"scroll",size:14})},l.id))}),xe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:xe.map(l=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${l.name}`,onClick:()=>ye(l.id),onContextMenu:r=>{r.preventDefault(),r.stopPropagation(),fe(l.id,{x:r.clientX,y:r.clientY})},children:e.jsx(u,{name:"hard-drives",size:14})},l.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(Bn,{})})]}),z&&e.jsx(Fn,{agentId:d,agents:vt,onClose:wt,branchInfoMap:Ke,fetchRemote:Ze,fetchingDirs:Je,onResizeStart:l=>ce(l,"right")}),_e&&e.jsx(Wn,{agentId:d,onClose:Oe}),U&&e.jsx(Hn,{agentId:d,onClose:we})]})});function ia({onAgentClick:w,onBuildingClick:d,onBuildingDoubleClick:v,onBuildingPopup:A,onAreaContextMenu:E,onOpenSpawnModal:K,onOpenBossSpawnModal:B,onOpenAreaModal:De}){const{t:ie}=Wt(["common"]),g=dn(),Z=un(),[ye,Ge]=a.useState(null),[Ue,qe]=a.useState(null),[pe,re]=a.useState(null),[me,Ye]=a.useState(null),[J,fe]=a.useState(null),[f,F]=a.useState(null),[W,Ae]=a.useState(null),[Ie,he]=a.useState(!1),Ke=a.useCallback(()=>{he(t=>!t)},[]),Ze=a.useCallback(()=>{he(!1)},[]),[Je,ge]=a.useState(()=>{const t=Pt(y.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Qe=a.useCallback(t=>{ge(t),Lt(y.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=n=>{if(n.key!==y.VIEW_MODE)return;const s=n.newValue;(s==="simple"||s==="chat"||s==="advanced")&&ge(s)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[xe,be]=a.useState(()=>At(y.FLAT_INSPECTOR_OPEN,!1)),[H,oe]=a.useState(!1),et=a.useCallback(()=>oe(t=>!t),[]),ze=a.useCallback(()=>oe(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:H}}))},[H]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:xe}}))},[xe]),a.useEffect(()=>{const t=()=>oe(_=>!_),n=()=>{be(_=>{const i=!_;return le(y.FLAT_INSPECTOR_OPEN,i),i})},s=()=>{oe(!1),be(!1),le(y.FLAT_INSPECTOR_OPEN,!1)},p=()=>oe(!1),m=()=>{be(!1),le(y.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",n),window.addEventListener("tide-close-flat-side-views",s),window.addEventListener("tide-close-flat-agents-drawer-only",p),window.addEventListener("tide-close-flat-inspector-only",m),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",n),window.removeEventListener("tide-close-flat-side-views",s),window.removeEventListener("tide-close-flat-agents-drawer-only",p),window.removeEventListener("tide-close-flat-inspector-only",m)}},[]);const V=a.useRef(null),X=a.useRef(null),[D,Se]=a.useState(()=>{const t=Rt(y.FLAT_MIDDLE_WIDTH,0);return t>=xt?t:null}),[G,Ee]=a.useState(()=>{const t=Rt(y.FLAT_INSPECTOR_WIDTH,0);return t>=yt?t:null}),ce=a.useCallback(t=>{if(typeof window>"u")return t;const n=G!==null?gt+G:0,s=window.innerWidth-Bt-gt-Ot-n;return Math.max(xt,Math.min(Math.max(s,xt),t))},[G]),z=a.useCallback(t=>{var m;if(typeof window>"u")return t;const n=(m=V.current)==null?void 0:m.querySelector(".flat-middle"),s=(n==null?void 0:n.getBoundingClientRect().width)??xt,p=window.innerWidth-Bt-s-gt-Ot-gt;return Math.max(yt,Math.min(Math.max(p,yt),t))},[]);a.useEffect(()=>{if(D===null&&G===null)return;const t=()=>{Se(n=>{if(n===null)return n;const s=ce(n);return s===n?n:s}),Ee(n=>{if(n===null)return n;const s=z(n);return s===n?n:s})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[D,G,ce,z]);const tt=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=V.current)==null?void 0:s.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),X.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),_e=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=V.current)==null?void 0:s.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),X.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),$e=a.useCallback(t=>{const n=X.current;if(!n||t.pointerId!==n.pointerId)return;const s=t.clientX-n.startX;n.kind==="middle"?Se(ce(n.startWidth+s)):Ee(z(n.startWidth-s))},[ce,z]),U=a.useCallback(t=>{const n=X.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(X.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const p=t.clientX-n.startX;if(n.kind==="middle"){const m=ce(n.startWidth+p);Se(m),ht(y.FLAT_MIDDLE_WIDTH,m)}else{const m=z(n.startWidth-p);Ee(m),ht(y.FLAT_INSPECTOR_WIDTH,m)}},[ce,z]),nt=a.useCallback(()=>{Se(null),ht(y.FLAT_MIDDLE_WIDTH,0)},[]),bt=a.useCallback(()=>{Ee(null),ht(y.FLAT_INSPECTOR_WIDTH,0)},[]),[we,_t]=a.useState(()=>Pt(y.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),at=a.useCallback(t=>{_t(t),Lt(y.FLAT_INSPECTOR_VIEW,t)},[]),wt=a.useCallback(()=>{be(t=>{const n=!t;return le(y.FLAT_INSPECTOR_OPEN,n),n})},[]),Oe=a.useCallback(()=>{be(!1),le(y.FLAT_INSPECTOR_OPEN,!1)},[]),vt=pn(),ve=a.useCallback((t,n)=>{Ge({url:t,name:n})},[]),de=a.useCallback((t,n)=>{qe({command:t,output:n,isLive:!1})},[]),Be=a.useCallback((t,n)=>{x.setFileViewerPath(t,n)},[]),Q=a.useCallback(t=>{re(t)},[]),st=a.useCallback((t,n)=>{Ye({agentId:t,count:n})},[]),Ce=a.useCallback(t=>{v?v(t):d(t)},[d,v]),h=a.useMemo(()=>Z.size>0?Array.from(Z)[0]:null,[Z]);a.useEffect(()=>{he(!1)},[h]);const ee=a.useRef([]),M=a.useRef(-1),Me=a.useRef(!1),lt=a.useRef(null),[it,rt]=a.useState(!1),[ot,te]=a.useState(!1),Te=a.useRef(!1),q=a.useRef(null),Fe=a.useRef(!1),ne=a.useMemo(()=>new Set(g.map(t=>t.id)),[g]),ct=a.useMemo(()=>{const t=new Map(g.map(s=>[s.id,s])),n=new Map;for(const s of g)if((s.isBoss||s.class==="boss")&&s.subordinateIds&&s.subordinateIds.length>0){const p=s.subordinateIds.map(m=>t.get(m)).filter(m=>m!==void 0);p.length>0&&n.set(s.id,p)}return n},[g]),$=a.useCallback(()=>{const t=ee.current,n=M.current;rt(n>0),te(n>=0&&n<t.length-1)},[]),ae=a.useCallback(t=>{const n=ee.current;if(n.length===0)return;let s=M.current+t;for(;s>=0&&s<n.length;){const p=n[s];if(ne.has(p)){Me.current=!0,M.current=s,$(),x.selectAgent(p);return}s+=t}},[ne,$]),l=a.useCallback(()=>ae(-1),[ae]),r=a.useCallback(()=>ae(1),[ae]);Un(a.useCallback(()=>{const t=ee.current,n=M.current;return t.length>0&&n>0?(ae(-1),"handled"):"exit"},[ae]));const o=a.useCallback((t,n)=>{if(typeof window>"u")return;const s=window.history.state,m={...typeof s=="object"&&s!==null?s:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(m,"",window.location.href):window.history.pushState(m,"",window.location.href)},[]);a.useEffect(()=>{if(!h){Te.current=!1,q.current=null;return}if(!Te.current){o(h,"replace"),Te.current=!0,q.current=h;return}if(Fe.current){Fe.current=!1,q.current=h;return}q.current!==h&&(o(h,"push"),q.current=h)},[h,o]),a.useEffect(()=>{const t=n=>{var _,i;const s=(i=(_=n.state)==null?void 0:_.__flatAgentNav)==null?void 0:i.agentId;if(!s||typeof s!="string"||!ne.has(s)||s===h)return;Fe.current=!0,Me.current=!0;const p=ee.current,m=p.lastIndexOf(s);m>=0?M.current=m:(p.push(s),M.current=p.length-1),$(),x.selectAgent(s)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[ne,h,$]),a.useEffect(()=>{if(!h){ee.current=[],M.current=-1,$();return}if(lt.current=h,Me.current){Me.current=!1,$();return}const t=ee.current,n=M.current;if(n>=0&&t[n]===h){$();return}const s=n<t.length-1?t.slice(0,n+1):t.slice();s.push(h),s.length>100&&s.shift(),ee.current=s,M.current=s.length-1,$()},[h,$]);const c=a.useCallback(t=>{w(t),oe(!1)},[w]),Pe=h??"",Le=a.useCallback(()=>{},[]),Re=a.useCallback(t=>{c(t)},[c]),Y=xe,[We,He]=a.useState(Y),[O,T]=a.useState(Y);a.useEffect(()=>{if(Y){He(!0);return}T(!1);const t=setTimeout(()=>He(!1),240);return()=>clearTimeout(t)},[Y]),a.useEffect(()=>{if(!We||!Y)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>T(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[We,Y]);const Ve=a.useRef(null);a.useEffect(()=>{if(h)return;const t=n=>{if(n.key!==" "&&n.key!=="Backspace")return;const s=n.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const p=lt.current;!p||!ne.has(p)||(n.preventDefault(),x.selectAgent(p))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[h,ne]);const[Ut,It]=a.useState(new Set),qt=a.useCallback(t=>{It(n=>{const s=new Set(n);return s.has(t)?s.delete(t):s.add(t),s})},[]),[je,Yt]=a.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);a.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),n=s=>Yt(s.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const[dt,Kt]=a.useState(null),Zt=a.useCallback(t=>{Kt(n=>n===t?null:t)},[]),Ct=Ht(),ut=Vt(),[Jt]=mn(),Ne=a.useMemo(()=>{const t=new Map,n=[];for(const b of g){const k=x.getAreaForAgent(b.id);if(!Dt((k==null?void 0:k.id)??null))continue;if(!k||k.archived){n.push(b);continue}const N=t.get(k.id);N?N.push(b):t.set(k.id,[b])}const s=new Map,p=[];for(const b of ut.values()){let k=!1;for(const N of Ct.values())if(!N.archived&&zt(N.id)&&x.isPositionInArea(b.position,N)){const se=s.get(N.id);se?se.push(b):s.set(N.id,[b]),k=!0;break}!k&&Dt(null)&&p.push(b)}const m=[];for(const[,b]of Ct){if(b.archived||!zt(b.id))continue;const k=t.get(b.id),N=s.get(b.id)??[];(k&&k.length>0||N.length>0)&&m.push({area:b,agents:k??[],buildings:N})}(n.length>0||p.length>0)&&m.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:n,buildings:p});const _=m.filter(b=>b.area.id!=="__unassigned__"),i=m.filter(b=>b.area.id==="__unassigned__");let I=1,j=1;const S=new Map;if(_.length>1){let b=1/0,k=-1/0,N=1/0,se=-1/0;for(const L of _)b=Math.min(b,L.area.center.x),k=Math.max(k,L.area.center.x),N=Math.min(N,L.area.center.z),se=Math.max(se,L.area.center.z);const pt=k-b||1,mt=se-N||1;if(_.length<=4){I=_.length,j=1;const L=[..._].sort((R,jt)=>R.area.center.x-jt.area.center.x);for(let R=0;R<L.length;R++)S.set(L[R].area.id,{row:1,col:R+1})}else{const L=[..._].sort((C,P)=>C.area.center.x-P.area.center.x),R=[];for(let C=1;C<L.length;C++)R.push(L[C].area.center.x-L[C-1].area.center.x);const jt=R.reduce((C,P)=>C+P,0)/R.length||1;let St=1;for(const C of R)C>jt*1.3&&St++;I=Math.max(2,Math.min(St,_.length));const Nt=[..._].sort((C,P)=>C.area.center.z-P.area.center.z),ft=[];for(let C=1;C<Nt.length;C++)ft.push(Nt[C].area.center.z-Nt[C-1].area.center.z);const nn=ft.reduce((C,P)=>C+P,0)/ft.length||1;let Et=1;for(const C of ft)C>nn*1.3&&Et++;j=Math.max(2,Math.min(Et,_.length)),I=Math.max(I,Math.ceil(_.length/j)),j=Math.max(j,Math.ceil(_.length/I));const an=pt/I,sn=mt/j,kt=new Set;for(const C of _){let P=Math.min(I-1,Math.max(0,Math.floor((C.area.center.x-b)/an))),ke=Math.min(j-1,Math.max(0,Math.floor((C.area.center.z-N)/sn))),Xe=`${ke},${P}`,Mt=0;const ln=j*I;for(;kt.has(Xe)&&Mt<ln;)P++,P>=I&&(P=0,ke=(ke+1)%j),Xe=`${ke},${P}`,Mt++;kt.has(Xe)&&(ke=j,P=0,Xe=`${ke},${P}`,j++),kt.add(Xe),S.set(C.area.id,{row:ke+1,col:P+1})}}}const ue=b=>{b.sort((k,N)=>{var pt,mt,L,R;const se=(((pt=k.position)==null?void 0:pt.z)??0)-(((mt=N.position)==null?void 0:mt.z)??0);return se!==0?se:(((L=k.position)==null?void 0:L.x)??0)-(((R=N.position)==null?void 0:R.x)??0)})};for(const b of _)ue(b.agents);for(const b of i)ue(b.agents);return{groups:[..._,...i],gridCols:I,gridRows:j,positions:S}},[g,Ct,ut,Jt]),Qt=a.useMemo(()=>{if(!J)return[];const t=g.find(n=>n.id===J.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(u,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(u,{name:"chat",size:14}),onClick:()=>w(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>{Ae({agentId:t.id,name:t.name})}}]:[]},[J,g,w]),en=a.useMemo(()=>{var _;if(!f)return[];const t=ut.get(f.buildingId);if(!t)return[];const n=[],s=t.type==="server"||t.type==="docker"||t.type==="terminal",p=t.status==="running",m=t.type==="boss";if(n.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((_=t.pm2)!=null&&_.enabled)?"View PM2 Logs":"Open",icon:e.jsx(u,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>Ce(t.id)}),s&&(p||n.push({id:"start",label:"Start",icon:e.jsx(u,{name:"play",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"start")}),p&&(n.push({id:"restart",label:"Restart",icon:e.jsx(u,{name:"refresh",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(u,{name:"stop",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"stop")}))),m&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(n.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(u,{name:"launch",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"start")}}),n.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(u,{name:"pause",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"stop")}}),n.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(u,{name:"restart",size:14}),onClick:()=>{for(const i of t.subordinateBuildingIds)x.sendBuildingCommand(i,"restart")}})),s&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(u,{name:"health",size:14}),onClick:()=>x.sendBuildingCommand(t.id,"healthCheck")}),n.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),n.push({id:"edit",label:"Edit Building",icon:e.jsx(u,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),n.push({id:"clone",label:"Clone Building",icon:e.jsx(u,{name:"copy",size:14}),onClick:()=>{x.createBuilding({name:`${t.name} (Copy)`,type:t.type,style:t.style,color:t.color,scale:t.scale,position:{x:t.position.x+2,z:t.position.z+2},cwd:t.cwd,folderPath:t.folderPath,commands:t.commands,pm2:t.pm2,docker:t.docker,database:t.database,terminal:t.terminal,urls:t.urls,subordinateBuildingIds:t.subordinateBuildingIds})}}),t.urls&&t.urls.length>0)for(const i of t.urls)n.push({id:`url-${i.label}`,label:i.label,icon:e.jsx(u,{name:"link",size:14}),onClick:()=>window.open(i.url,"_blank","noopener,noreferrer")});return n.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),n.push({id:"delete",label:"Delete Building",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>x.deleteBuilding(t.id)}),n},[f,ut,Ce]),tn=a.useCallback(t=>{const n=new Set(Ne.groups.map(s=>s.area.id));n.delete(t),It(n),requestAnimationFrame(()=>{const s=Ve.current;if(!s)return;const p=s.querySelector(`[data-area-id="${t}"]`);if(!p)return;const m=s.getBoundingClientRect(),i=p.getBoundingClientRect().top-m.top+s.scrollTop-8;s.scrollTo({top:Math.max(0,i),behavior:"smooth"})})},[Ne]);return e.jsxs("div",{ref:V,className:`flat-view ${Y?"flat-view--with-inspector":""} ${h?"flat-view--has-chat":""} ${H?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(D===null&&G===null)return;const t={};return D!==null&&(t["--flat-middle-width"]=`${D}px`),G!==null&&(t["--flat-inspector-width"]=`${G}px`),t})(),children:[H&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:ze,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children:e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:K,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:B,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:De,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(fn,{activeAgentId:Pe,onClose:Le,onSelectAgent:Re,collapsedAreas:Ut,onToggleArea:qt,agentListRef:Ve})})]}),e.jsx("div",{className:"flat-splitter flat-splitter--middle",role:"separator","aria-orientation":"vertical","aria-label":"Resize agents panel",title:"Drag to resize · Double-click to reset",onPointerDown:tt,onPointerMove:$e,onPointerUp:U,onPointerCancel:U,onDoubleClick:nt}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":H?"Close agents sidebar":"Open agents sidebar","aria-expanded":H,onClick:et,children:[e.jsx(u,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),h?e.jsx(na,{agentId:h,terminalViewMode:Je,onTerminalViewModeChange:Qe,inspectorOpen:xe,onToggleInspector:wt,onImageClick:ve,onFileClick:Be,onBashClick:de,onViewMarkdown:Q,onRequestClearSubordinates:st,onOpenBuilding:Ce,keyboard:vt,canNavigateBack:it,canNavigateForward:ot,onNavigateBack:l,onNavigateForward:r,agentInfoOpen:Ie,onToggleAgentInfo:Ke,onHeaderContextMenu:t=>{h&&fe({agentId:h,position:t})},onBuildingContextMenu:(t,n)=>{F({buildingId:t,position:n})}}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"}),e.jsx(qn,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Ne.gridCols}, 1fr)`},children:Ne.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(()=>{var n;const t=je&&dt?((n=Ne.positions.get(dt))==null?void 0:n.row)??null:null;return Ne.groups.map(s=>{const p=s.area.id,m=Ne.positions.get(p),_=je&&dt!==p;return je&&t!=null&&(m==null?void 0:m.row)===t&&p!==dt?null:e.jsxs("div",{className:`flat-map-area-card${_?" flat-map-area-card--collapsed":""}`,style:{"--area-color":s.area.color,gridRow:m==null?void 0:m.row,gridColumn:m==null?void 0:m.col},onContextMenu:i=>{E&&(i.preventDefault(),i.stopPropagation(),E(p,{x:i.clientX,y:i.clientY}))},children:[e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>je?Zt(p):tn(p),title:je?_?`Expand ${s.area.name}`:`Collapse ${s.area.name}`:`Focus ${s.area.name} in left panel`,"aria-expanded":je?!_:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:s.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:s.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:s.agents.length}),je&&e.jsx(u,{name:_?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:s.agents.map(i=>{const I=i.isBoss||i.class==="boss",j=I?ct.get(i.id):void 0,S=hn(i),ue=S.usedPercent>=80?"#ff4a4a":S.usedPercent>=60?"#ff9e4a":S.usedPercent>=40?"#ffd700":"#4aff9e",b=`Context: ${(S.totalTokens/1e3).toFixed(1)}k / ${(S.contextWindow/1e3).toFixed(1)}k (${S.usedPercent}% used, ${S.freePercent}% free)`,k=i.latestTodos&&i.latestTodos.length>0||j&&j.length>0;return e.jsx(gn,{todos:i.latestTodos,subordinates:j,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${i.status}`,onClick:()=>w(i.id),onContextMenu:N=>{N.preventDefault(),N.stopPropagation(),fe({agentId:i.id,position:{x:N.clientX,y:N.clientY}})},title:k?void 0:`${I?"Boss · ":""}Open chat with ${i.name}
2
2
  ${b}`,children:[e.jsx(Xt,{agent:i,size:16}),I&&e.jsx("span",{className:"flat-map-agent-chip__crown","aria-hidden":"true",children:e.jsx(u,{name:"crown",size:11,color:"#ffd700",weight:"fill"})}),e.jsx("span",{className:"flat-map-agent-chip__name",children:i.name}),e.jsx("img",{src:i.provider==="codex"?"/assets/codex.png":i.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:i.provider,className:"flat-map-agent-chip__provider-icon",title:i.provider==="codex"?"Codex Agent":i.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:Gt(i.status)}}),i.latestTodos&&i.latestTodos.length>0&&e.jsx(xn,{todos:i.latestTodos,maxDots:6}),I&&j&&j.length>0&&e.jsx(bn,{subordinates:j,maxDots:6}),e.jsx("span",{className:"flat-map-agent-chip__context-bar","aria-hidden":"true",children:e.jsx("span",{className:"flat-map-agent-chip__context-bar-fill",style:{width:`${S.usedPercent}%`,backgroundColor:ue}})})]})},i.id)})}),s.area.directories.length>0&&e.jsx("div",{className:"flat-map-area-card__folders",role:"group","aria-label":`${s.area.name} folders`,children:s.area.directories.map(i=>{const I=i.split("/").filter(Boolean).pop()||i;return e.jsxs("button",{type:"button",className:"flat-map-folder-chip",onClick:j=>{j.stopPropagation(),x.openFileExplorerForAreaFolder(p,i)},title:`Open in file explorer: ${i}`,children:[e.jsx(u,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-map-folder-chip__name",children:I})]},i)})}),s.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:s.buildings.map(i=>{var j;const I=(j=_n[i.type])==null?void 0:j.color;return e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${i.status}`,style:I?{"--building-type-color":I}:void 0,onClick:S=>{if(A){const ue=S.currentTarget.getBoundingClientRect();A(i.id,{x:ue.right,y:ue.top+ue.height/2})}else Ce(i.id)},onContextMenu:S=>{S.preventDefault(),S.stopPropagation(),F({buildingId:i.id,position:{x:S.clientX,y:S.clientY}})},title:`${i.name} · ${i.type} · ${i.status}`,children:[e.jsx(u,{name:wn(i.type),size:12,color:I}),e.jsx("span",{className:"flat-map-building-chip__name",children:i.name}),e.jsx("span",{className:"flat-map-building-chip__dot",style:{backgroundColor:vn(i.status)}})]},i.id)})})]},p)})})()})]})})]}),Y&&e.jsx("div",{className:"flat-splitter flat-splitter--inspector",role:"separator","aria-orientation":"vertical","aria-label":"Resize inspector panel",title:"Drag to resize · Double-click to reset",onPointerDown:_e,onPointerMove:$e,onPointerUp:U,onPointerCancel:U,onDoubleClick:bt}),We&&e.jsxs("aside",{className:`flat-inspector ${O?"flat-inspector--open":"flat-inspector--closing"}`,"aria-label":"Inspector panel",children:[e.jsxs("div",{className:"flat-inspector__header",children:[e.jsxs("div",{className:"flat-inspector__tabs",role:"tablist","aria-label":"Inspector view",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":we==="agent",className:`flat-inspector__tab ${we==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>at("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":we==="tracking",className:`flat-inspector__tab ${we==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>at("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:Oe,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:we==="tracking"?e.jsx(Cn,{activeAgentId:h??"",onSelectAgent:t=>{w(t),window.innerWidth<=768&&Oe()}}):(()=>{if(!h)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=g.find(n=>n.id===h);return t?e.jsx(jn,{agent:t,onFocusAgent:n=>{w(n),window.innerWidth<=768&&Oe()},onKillAgent:n=>x.killAgent(n)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),ye&&e.jsx(Nn,{url:ye.url,name:ye.name,onClose:()=>Ge(null)}),Ue&&e.jsx(kn,{state:Ue,onClose:()=>qe(null)}),e.jsx(yn,{agent:h?g.find(t=>t.id===h)??null:null,content:pe,onClose:()=>re(null)}),me&&e.jsx(An,{action:"clear-subordinates",selectedAgentId:me.agentId,subordinateCount:me.count,onClose:()=>Ye(null),onClearHistory:()=>{}}),e.jsx(In,{agent:h?g.find(t=>t.id===h)??null:null,isOpen:Ie&&!!h,onClose:Ze}),e.jsx($t,{isOpen:J!==null,position:(J==null?void 0:J.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:Qt,onClose:()=>fe(null)}),e.jsx($t,{isOpen:f!==null,position:(f==null?void 0:f.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:en,onClose:()=>F(null)}),e.jsx(Sn,{isOpen:W!==null,title:ie("common:confirm.removeAgentTitle"),message:ie("common:confirm.removeAgentMessage",{name:(W==null?void 0:W.name)??""}),confirmLabel:ie("common:buttons.remove"),cancelLabel:ie("common:buttons.cancel"),variant:"danger",onConfirm:()=>{W&&x.removeAgentFromServer(W.agentId)},onClose:()=>Ae(null)})]})}export{ia as FlatView};
@@ -1,4 +1,4 @@
1
- import{r as l,aW as Re,aX as Ye,j as e,I as L,u as Y,aY as as,a3 as ns,f as Ve,s as E,aZ as ms,k as is,l as he,a_ as Z,a$ as gs,aP as fs,b0 as xs,C as me,b1 as J,aM as we,b2 as bs,b3 as js,b4 as ws,b5 as ys,b6 as Se,b7 as os,b8 as Ns,b9 as Me,ba as vs,bb as ks,bc as Ss,bd as Cs,be as Ts,bf as As,bg as _s,aI as Es,J as Is,S as ke,bh as Ps,bi as $s,aK as Ls,bj as Ue,K as Ie,aT as Ds,bk as ze,bl as Fs}from"./main-Bon1sZAi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Ke="deivid11/tide-commander",Os=`https://api.github.com/repos/${Ke}/releases/latest`,Rs=`https://api.github.com/repos/${Ke}/releases?per_page=3`,Us=3600*1e3,Je="app_update_dismissed_version",Ze="1.111.2";function zs(){var w,C;const[s,a]=l.useState({isChecking:!1,updateAvailable:!1,updateInfo:null,recentReleases:[],error:null,currentVersion:Ze}),t=((C=(w=Re)==null?void 0:w.getPlatform)==null?void 0:C.call(w))==="android"||!1,o=u=>u.replace(/^v/,"").split(".").map(m=>parseInt(m,10)||0),r=(u,p)=>{const m=o(u),j=o(p),b=Math.max(m.length,j.length);for(let h=0;h<b;h++){const k=m[h]||0,$=j[h]||0;if(k>$)return 1;if(k<$)return-1}return 0},d=async u=>{var m,j;if(Re&&Ye&&((j=(m=Re).isNativePlatform)==null?void 0:j.call(m))===!0){const b=await Ye.get({url:u,headers:{Accept:"application/vnd.github.v3+json"}});return{data:b.data,status:b.status}}else{const b=await fetch(u,{headers:{Accept:"application/vnd.github.v3+json"}});return b.ok?{data:await b.json(),status:b.status}:{data:null,status:b.status}}},c=l.useCallback(async(u=!1)=>{a(p=>({...p,isChecking:!0,error:null}));try{const[p,m]=await Promise.all([d(Os),d(Rs)]);if(p.status!==200)throw new Error(`GitHub API error: ${p.status}`);const j=p.data,b=j.tag_name;let h=[];m.status===200&&m.data&&(h=m.data.map(y=>({version:y.tag_name,name:y.name,publishedAt:y.published_at,releaseUrl:y.html_url})));const k=localStorage.getItem(Je);if(!u&&k===b)return a(y=>({...y,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;if(!(r(b,Ze)>0))return a(y=>({...y,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;const P=j.assets.find(y=>y.name.endsWith(".apk")&&y.content_type==="application/vnd.android.package-archive"),K={version:b,name:j.name,changelog:j.body,releaseUrl:j.html_url,apkUrl:(P==null?void 0:P.browser_download_url)||null,apkSize:(P==null?void 0:P.size)||null,publishedAt:j.published_at};return a(y=>({...y,isChecking:!1,updateAvailable:!0,updateInfo:K,recentReleases:h})),K}catch(p){const m=p instanceof Error?p.message:"Failed to check for updates";return a(j=>({...j,isChecking:!1,error:m})),null}},[]),g=l.useCallback(async()=>{var u,p,m;if(!((u=s.updateInfo)!=null&&u.apkUrl)){(p=s.updateInfo)!=null&&p.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}if(!t){(m=s.updateInfo)!=null&&m.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}try{window.open(s.updateInfo.apkUrl,"_system"),a(j=>({...j,error:null}))}catch(j){const b=j instanceof Error?j.message:"Failed to open download";a(h=>({...h,error:b}))}},[s.updateInfo,t]),n=l.useCallback(()=>{s.updateInfo&&localStorage.setItem(Je,s.updateInfo.version),a(u=>({...u,updateAvailable:!1,updateInfo:null}))},[s.updateInfo]),x=l.useCallback(()=>{var u;(u=s.updateInfo)!=null&&u.releaseUrl?window.open(s.updateInfo.releaseUrl,"_blank"):window.open(`https://github.com/${Ke}/releases`,"_blank")},[s.updateInfo]);return l.useEffect(()=>{if(!t)return;const u=setTimeout(()=>{c()},5e3),p=setInterval(()=>{c()},Us);return()=>{clearTimeout(u),clearInterval(p)}},[t,c]),{...s,isAndroid:t,checkForUpdate:c,downloadAndInstall:g,dismissUpdate:n,openReleasePage:x}}const ls="tide-toolbox-collapse";function Bs(s,a){try{const t=localStorage.getItem(`${ls}-${s}`);if(t!==null)return t==="true"}catch{}return a}function Ms(s,a){try{localStorage.setItem(`${ls}-${s}`,String(a))}catch{}}function W({title:s,storageKey:a,defaultOpen:t=!1,forceOpen:o=!1,children:r,headerExtra:d}){const[c,g]=l.useState(()=>a?Bs(a,t):t),n=()=>{const w=!c;g(w),a&&Ms(a,w)},x=o||c;return e.jsxs("div",{className:`collapsible-section ${x?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:n,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[d,e.jsx("span",{className:"collapsible-arrow",children:e.jsx(L,{name:x?"caret-down":"caret-right",size:10})})]})]}),x&&e.jsx("div",{className:"collapsible-content",children:r})]})}function Vs({area:s,isSelected:a,onClick:t,onDelete:o}){const{t:r}=Y(["config","common"]),d=s.assignedAgentIds.length,c=s.type==="rectangle"?r("config:areas.rect"):r("config:areas.circle");return e.jsxs("div",{className:`area-item ${a?"selected":""}`,onClick:t,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:[c," ",d>0&&`• ${d} ${d>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 Ks({building:s,isSelected:a,onClick:t,onEdit:o}){var g;const{t:r}=Y(["config"]),d=((g=s.pm2Status)==null?void 0:g.ports)||[],c=(n,x)=>{n.stopPropagation(),window.open(`http://${window.location.hostname}:${x}`,"_blank")};return e.jsxs("div",{className:`building-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:as[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(L,{name:ns(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,d.length>0&&e.jsx("span",{className:"building-ports",children:d.map(n=>e.jsxs("a",{href:`http://${window.location.hostname}:${n}`,className:"building-port-link",onClick:x=>c(x,n),title:`Open :${n}`,children:[":",n]},n))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:n=>{n.stopPropagation(),o()},title:r("config:buildings.editBuilding"),children:e.jsx(L,{name:"gear",size:14})})]})}function Hs({building:s,onClose:a,onOpenModal:t}){var x,w,C,u,p,m,j,b;const{t:o}=Y(["config","common"]),{buildingLogs:r}=Ve(),d=E.getBuildingLogs(s.id),c=ms[s.style||"server-rack"],g=h=>{E.sendBuildingCommand(s.id,h)},n=h=>{window.open(h,"_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(L,{name:ns(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:as[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:a,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:c.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:()=>g("start"),disabled:!((x=s.commands)!=null&&x.start)||s.status==="running",title:((w=s.commands)==null?void 0:w.start)||o("config:buildings.noStartCommand"),children:[e.jsx(L,{name:"play",size:12})," ",o("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>g("stop"),disabled:!((C=s.commands)!=null&&C.stop)||s.status==="stopped",title:((u=s.commands)==null?void 0:u.stop)||o("config:buildings.noStopCommand"),children:[e.jsx(L,{name:"stop",size:12,weight:"fill"})," ",o("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>g("restart"),disabled:!((p=s.commands)!=null&&p.restart),title:((m=s.commands)==null?void 0:m.restart)||o("config:buildings.noRestartCommand"),children:[e.jsx(L,{name:"refresh",size:12})," ",o("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>g("healthCheck"),disabled:!((j=s.commands)!=null&&j.healthCheck),title:((b=s.commands)==null?void 0:b.healthCheck)||o("config:buildings.noHealthCheck"),children:[e.jsx(L,{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((h,k)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>n(h.url),title:h.url,children:[e.jsx(L,{name:"link",size:12})," ",h.label||h.url]},k))})]}),d.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:()=>E.clearBuildingLogs(s.id),title:o("common:buttons.clear"),children:o("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:d.slice(-5).map((h,k)=>e.jsx("div",{className:"building-editor-log-entry",children:h},k))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx(L,{name:"gear",size:12})," ",o("config:buildings.fullSettings")]})})]})}async function Ws(s,a){const t=Z(),o=await fetch(he(`/api/areas/${s}/logo`),{method:"POST",headers:{"Content-Type":a.type||"image/png","X-Filename":encodeURIComponent(a.name),...t?{Authorization:`Bearer ${t}`}:{}},body:a});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 qs(s){const a=Z(),t=await fetch(he(`/api/areas/${s}/logo`),{method:"DELETE",headers:{...a?{Authorization:`Bearer ${a}`}:{}}});if(!t.ok)throw new Error(`Failed to delete logo: ${t.statusText}`)}function Gs(s){return is(he(`/api/areas/logos/${s}`))}const Ys=[{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 Js({area:s,onClose:a,onOpenFolder:t}){var ie;const{t:o}=Y(["config","common"]),[r,d]=l.useState(s.name),[c,g]=l.useState(s.prompt||""),[n,x]=l.useState(!1),[w,C]=l.useState(""),[u,p]=l.useState(!1),m=l.useRef(null);l.useEffect(()=>{d(s.name)},[s.id,s.name]),l.useEffect(()=>{g(s.prompt||"")},[s.id,s.prompt]);const j=v=>{const F=v.target.value;d(F),E.updateArea(s.id,{name:F})},b=v=>{E.updateArea(s.id,{color:v})},h=v=>{const F=v.target.value;g(F),E.updateArea(s.id,{prompt:F})},k=()=>{w.trim()&&(E.addDirectoryToArea(s.id,w.trim()),C(""),x(!1))},$=(v,F)=>{F.stopPropagation(),E.removeDirectoryFromArea(s.id,v)},P=()=>{E.bringAreaToFront(s.id)},K=()=>{E.sendAreaToBack(s.id)},y=l.useCallback(()=>{let v=2,F=2;s.type==="rectangle"&&s.width&&s.height?(v=s.width,F=s.height):s.type==="circle"&&s.radius&&(v=s.radius*1.414,F=s.radius*1.414);const M=Math.min(v,F)*.4;return{width:Math.round(M*10)/10,height:Math.round(M*10)/10}},[s.type,s.width,s.height,s.radius]),U=async v=>{var M;const F=(M=v.target.files)==null?void 0:M[0];if(F){p(!0);try{const N=await Ws(s.id,F),D=y();E.updateArea(s.id,{logo:{filename:N.filename,position:"center",width:D.width,height:D.height,keepAspectRatio:!0,opacity:.8}})}catch(N){console.error("Failed to upload logo:",N)}finally{p(!1),m.current&&(m.current.value="")}}},B=async()=>{try{await qs(s.id),E.updateArea(s.id,{logo:void 0})}catch(v){console.error("Failed to remove logo:",v)}},V=v=>{s.logo&&E.updateArea(s.id,{logo:{...s.logo,position:v}})},S=v=>{if(!s.logo)return;const F=parseFloat(v.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const M=s.logo.height/s.logo.width;E.updateArea(s.id,{logo:{...s.logo,width:F,height:Math.round(F*M*10)/10}})}else E.updateArea(s.id,{logo:{...s.logo,width:F}})},T=v=>{if(!s.logo)return;const F=parseFloat(v.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const M=s.logo.width/s.logo.height;E.updateArea(s.id,{logo:{...s.logo,height:F,width:Math.round(F*M*10)/10}})}else E.updateArea(s.id,{logo:{...s.logo,height:F}})},H=()=>{s.logo&&E.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},X=v=>{s.logo&&E.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(v.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:a,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:j,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:gs.map(v=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===v?"selected":""}`,style:{backgroundColor:v},onClick:()=>b(v),"aria-label":`Set area color ${v}`,"aria-pressed":s.color===v,title:v},v))})]}),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:P,title:o("config:areas.bringToFront"),children:[e.jsx(L,{name:"arrow-up",size:12})," ",o("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:K,title:o("config:areas.sendToBack"),children:[e.jsx(L,{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:[(ie=s.logo)!=null&&ie.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:Gs(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:B,children:o("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var v;return(v=m.current)==null?void 0:v.click()},disabled:u,children:u?"...":e.jsx(L,{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:Ys.map(({key:v,labelKey:F})=>{var M;return e.jsx("button",{className:`area-logo-pos-btn ${((M=s.logo)==null?void 0:M.position)===v?"active":""}`,onClick:()=>V(v),children:o(`config:areas.${F}`)},v)})})]}),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:S,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:T,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:H}),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:X,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 v;return(v=m.current)==null?void 0:v.click()},disabled:u,children:u?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:m,type:"file",accept:"image/*",style:{display:"none"},onChange:U})]})]}),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(v=>e.jsxs("div",{className:"area-folder-item",title:v,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:o("config:areas.openFolder"),children:e.jsx(L,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:v.split("/").pop()||v}),e.jsx("button",{className:"area-folder-remove",onClick:F=>$(v,F),title:o("config:areas.removeFolder"),children:"×"})]},v)),n?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(fs,{value:w,onChange:C,onSubmit:k,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:k,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>x(!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:c,onChange:h,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 Zs(){const{t:s}=Y(["config","common"]),a=xs(),[t,o]=l.useState(!1),[r,d]=l.useState(null),[c,g]=l.useState({name:"",key:"",value:"",description:""}),[n,x]=l.useState(null),w=()=>{o(!0),d(null),g({name:"",key:"",value:"",description:""})},C=h=>{d(h.id),o(!1),g({name:h.name,key:h.key,value:h.value,description:h.description||""})},u=()=>{o(!1),d(null),g({name:"",key:"",value:"",description:""})},p=()=>{!c.name.trim()||!c.key.trim()||(r?E.updateSecret(r,{name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}):E.createSecret({name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}),u())},m=h=>{x(h)},j=()=>{n&&(E.deleteSecret(n),r===n&&u())},b=h=>{navigator.clipboard.writeText(`{{${h}}}`)};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:a.length===0&&!t?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):a.map(h=>e.jsxs("div",{className:`secret-item ${r===h.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:h.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>b(h.key),title:s("config:secrets.copyPlaceholder"),children:`{{${h.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>C(h),title:s("common:buttons.edit"),children:e.jsx(L,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>m(h.id),title:s("common:buttons.delete"),children:"×"})]})]}),h.description&&e.jsx("div",{className:"secret-item-description",children:h.description})]},h.id))}),(t||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:c.name,onChange:h=>g({...c,name:h.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:c.key,onChange:h=>g({...c,key:h.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${c.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:c.value,onChange:h=>g({...c,value:h.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:c.description,onChange:h=>g({...c,description:h.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:u,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:p,disabled:!c.name.trim()||!c.key.trim(),children:s(r?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!r&&e.jsx("button",{className:"secrets-add-btn",onClick:w,children:s("config:secrets.addSecret")}),e.jsx(me,{isOpen:n!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:j,onClose:()=>x(null)})]})}async function Xs(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch system prompt: ${a.statusText}`);return(await a.json()).prompt||""}async function Qs(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({prompt:s})});if(!t.ok)throw new Error(`Failed to update system prompt: ${t.statusText}`)}async function et(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to clear system prompt: ${a.statusText}`)}async function st(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch echo prompt setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function tt(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function at(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch codex binary path: ${a.statusText}`);return(await a.json()).path||""}async function nt(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function it(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch tmux mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function ot(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function lt(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch backup status: ${a.statusText}`);return a.json()}async function ct(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok){const o=await t.json().catch(()=>({}));throw new Error(o.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function rt({checked:s,onChange:a,disabled:t}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:t,onChange:o=>a(o.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function dt(){const{t:s}=Y(["config","common"]),[a,t]=l.useState([]),[o,r]=l.useState(new Set),[d,c]=l.useState(new Set),[g,n]=l.useState(!1),[x,w]=l.useState(!1),[C,u]=l.useState(null),[p,m]=l.useState(null),[j,b]=l.useState(null),[h,k]=l.useState(null),[$,P]=l.useState(!1),[K,y]=l.useState(null);l.useEffect(()=>{we(he("/api/config/categories")).then(N=>N.json()).then(N=>{const D=Array.isArray(N)?N:[];t(D),r(new Set(D.map(O=>O.id)))}).catch(N=>console.error("Failed to fetch config categories:",N))},[]),l.useEffect(()=>{lt().then(k).catch(N=>{console.error("Failed to fetch backup status:",N),y(N.message||"Failed to fetch backup status")})},[]);const U=async N=>{if(!$){P(!0),y(null);try{const D=await ct(N);k(D)}catch(D){y(D.message||"Failed to update backup setting")}finally{P(!1)}}},B=N=>{r(D=>{const O=new Set(D);return O.has(N)?O.delete(N):O.add(N),O})},V=N=>{c(D=>{const O=new Set(D);return O.has(N)?O.delete(N):O.add(N),O})},S=()=>r(new Set(a.map(N=>N.id))),T=()=>r(new Set),H=()=>{p&&c(new Set(p.categories.map(N=>N.id)))},X=()=>c(new Set),ie=async()=>{var N;if(o.size!==0){n(!0),b(null);try{const D=Array.from(o).join(","),O=await we(he(`/api/config/export?categories=${D}`));if(!O.ok)throw new Error("Export failed");const ee=await O.blob(),se=window.URL.createObjectURL(ee),Q=document.createElement("a");Q.href=se;const A=O.headers.get("Content-Disposition"),q=((N=A==null?void 0:A.match(/filename="(.+)"/))==null?void 0:N[1])||"tide-commander-config.zip";Q.download=q,document.body.appendChild(Q),Q.click(),document.body.removeChild(Q),window.URL.revokeObjectURL(se),b({type:"success",text:s("config:data.exportSuccess")})}catch(D){b({type:"error",text:D.message||"Export failed"})}finally{n(!1)}}},v=async N=>{var O;const D=(O=N.target.files)==null?void 0:O[0];if(D){u(D),b(null),m(null),c(new Set);try{const ee=await we(he("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await D.arrayBuffer()});if(!ee.ok){const A=await ee.json();throw new Error(A.error||"Failed to preview config file")}const se=await ee.json(),Q=Array.isArray(se.categories)?se.categories:[];m({...se,categories:Q}),c(new Set(Q.map(A=>A.id)))}catch(ee){b({type:"error",text:ee.message||"Failed to read config file"}),u(null)}}},F=async()=>{if(!(!C||d.size===0)){w(!0),b(null);try{const N=Array.from(d).join(","),D=await we(he(`/api/config/import?categories=${N}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await C.arrayBuffer()}),O=await D.json();if(!D.ok)throw new Error(O.error||"Import failed");b({type:"success",text:O.message||s("config:data.importSuccess")}),u(null),m(null),c(new Set)}catch(N){b({type:"error",text:N.message||"Import failed"})}finally{w(!1)}}},M=()=>{u(null),m(null),c(new Set),b(null)};return e.jsxs("div",{className:"data-section",children:[j&&e.jsx("div",{className:`data-message data-message-${j.type}`,children:j.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(rt,{checked:!!(h!=null&&h.enabled),disabled:$||!h,onChange:U})]}),e.jsxs("div",{className:"data-backup-info",children:[h?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:h.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!h.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:h.scriptPath})]}),h.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(h.lastRunAt).toLocaleString(),h.lastRunOk===!0&&" — ok",h.lastRunOk===!1&&h.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",h.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),K&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:K})]})]}),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:S,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:T,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:a.map(N=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(N.id),onChange:()=>B(N.id)}),e.jsx("span",{className:"data-category-name",children:N.name})]},N.id))}),e.jsx("button",{className:"data-action-btn export",onClick:ie,disabled:g||o.size===0,children:g?s("config:data.exporting"):s("config:data.exportCount",{count:o.size})})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsx("div",{className:"data-subsection-header",children:e.jsx("span",{className:"data-subsection-title",children:s("config:data.importData")})}),C?p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:C.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(p.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:H,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:p.categories.map(N=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:d.has(N.id),onChange:()=>V(N.id)}),e.jsx("span",{className:"data-category-name",children:N.name}),N.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",N.fileCount," ",s("config:data.files"),")"]})]},N.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:M,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:F,disabled:x||d.size===0,children:x?s("config:data.importing"):s("config:data.importCount",{count:d.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:v,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}async function ut(){const s=await we(`${J()}/api/system/install-info`);if(!s.ok)throw new Error(`Failed to fetch install info: ${s.statusText}`);return s.json()}function pt(s,a){const t=new AbortController;return(async()=>{try{const o=await fetch(is(`${J()}/api/system/self-update`),{method:"POST",signal:t.signal,headers:{Accept:"text/event-stream"}});if(!o.ok||!o.body){const g=await o.text().catch(()=>"");let n=null;try{n=JSON.parse(g)}catch{}const x=n&&typeof n=="object"&&"error"in n&&typeof n.error=="string"?n.error:`Self-update failed: ${o.status} ${o.statusText}`;s({type:"error",message:x}),a(new Error(x));return}const r=o.body.getReader(),d=new TextDecoder("utf-8");let c="";for(;;){const{value:g,done:n}=await r.read();if(n)break;c+=d.decode(g,{stream:!0});let x=c.indexOf(`
1
+ import{r as l,aW as Re,aX as Ye,j as e,I as L,u as Y,aY as as,a3 as ns,f as Ve,s as E,aZ as ms,k as is,l as he,a_ as Z,a$ as gs,aP as fs,b0 as xs,C as me,b1 as J,aM as we,b2 as bs,b3 as js,b4 as ws,b5 as ys,b6 as Se,b7 as os,b8 as Ns,b9 as Me,ba as vs,bb as ks,bc as Ss,bd as Cs,be as Ts,bf as As,bg as _s,aI as Es,J as Is,S as ke,bh as Ps,bi as $s,aK as Ls,bj as Ue,K as Ie,aT as Ds,bk as ze,bl as Fs}from"./main-D9ETZv9V.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Ke="deivid11/tide-commander",Os=`https://api.github.com/repos/${Ke}/releases/latest`,Rs=`https://api.github.com/repos/${Ke}/releases?per_page=3`,Us=3600*1e3,Je="app_update_dismissed_version",Ze="1.112.0";function zs(){var w,C;const[s,a]=l.useState({isChecking:!1,updateAvailable:!1,updateInfo:null,recentReleases:[],error:null,currentVersion:Ze}),t=((C=(w=Re)==null?void 0:w.getPlatform)==null?void 0:C.call(w))==="android"||!1,o=u=>u.replace(/^v/,"").split(".").map(m=>parseInt(m,10)||0),r=(u,p)=>{const m=o(u),j=o(p),b=Math.max(m.length,j.length);for(let h=0;h<b;h++){const k=m[h]||0,$=j[h]||0;if(k>$)return 1;if(k<$)return-1}return 0},d=async u=>{var m,j;if(Re&&Ye&&((j=(m=Re).isNativePlatform)==null?void 0:j.call(m))===!0){const b=await Ye.get({url:u,headers:{Accept:"application/vnd.github.v3+json"}});return{data:b.data,status:b.status}}else{const b=await fetch(u,{headers:{Accept:"application/vnd.github.v3+json"}});return b.ok?{data:await b.json(),status:b.status}:{data:null,status:b.status}}},c=l.useCallback(async(u=!1)=>{a(p=>({...p,isChecking:!0,error:null}));try{const[p,m]=await Promise.all([d(Os),d(Rs)]);if(p.status!==200)throw new Error(`GitHub API error: ${p.status}`);const j=p.data,b=j.tag_name;let h=[];m.status===200&&m.data&&(h=m.data.map(y=>({version:y.tag_name,name:y.name,publishedAt:y.published_at,releaseUrl:y.html_url})));const k=localStorage.getItem(Je);if(!u&&k===b)return a(y=>({...y,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;if(!(r(b,Ze)>0))return a(y=>({...y,isChecking:!1,updateAvailable:!1,recentReleases:h})),null;const P=j.assets.find(y=>y.name.endsWith(".apk")&&y.content_type==="application/vnd.android.package-archive"),K={version:b,name:j.name,changelog:j.body,releaseUrl:j.html_url,apkUrl:(P==null?void 0:P.browser_download_url)||null,apkSize:(P==null?void 0:P.size)||null,publishedAt:j.published_at};return a(y=>({...y,isChecking:!1,updateAvailable:!0,updateInfo:K,recentReleases:h})),K}catch(p){const m=p instanceof Error?p.message:"Failed to check for updates";return a(j=>({...j,isChecking:!1,error:m})),null}},[]),g=l.useCallback(async()=>{var u,p,m;if(!((u=s.updateInfo)!=null&&u.apkUrl)){(p=s.updateInfo)!=null&&p.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}if(!t){(m=s.updateInfo)!=null&&m.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}try{window.open(s.updateInfo.apkUrl,"_system"),a(j=>({...j,error:null}))}catch(j){const b=j instanceof Error?j.message:"Failed to open download";a(h=>({...h,error:b}))}},[s.updateInfo,t]),n=l.useCallback(()=>{s.updateInfo&&localStorage.setItem(Je,s.updateInfo.version),a(u=>({...u,updateAvailable:!1,updateInfo:null}))},[s.updateInfo]),x=l.useCallback(()=>{var u;(u=s.updateInfo)!=null&&u.releaseUrl?window.open(s.updateInfo.releaseUrl,"_blank"):window.open(`https://github.com/${Ke}/releases`,"_blank")},[s.updateInfo]);return l.useEffect(()=>{if(!t)return;const u=setTimeout(()=>{c()},5e3),p=setInterval(()=>{c()},Us);return()=>{clearTimeout(u),clearInterval(p)}},[t,c]),{...s,isAndroid:t,checkForUpdate:c,downloadAndInstall:g,dismissUpdate:n,openReleasePage:x}}const ls="tide-toolbox-collapse";function Bs(s,a){try{const t=localStorage.getItem(`${ls}-${s}`);if(t!==null)return t==="true"}catch{}return a}function Ms(s,a){try{localStorage.setItem(`${ls}-${s}`,String(a))}catch{}}function W({title:s,storageKey:a,defaultOpen:t=!1,forceOpen:o=!1,children:r,headerExtra:d}){const[c,g]=l.useState(()=>a?Bs(a,t):t),n=()=>{const w=!c;g(w),a&&Ms(a,w)},x=o||c;return e.jsxs("div",{className:`collapsible-section ${x?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:n,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[d,e.jsx("span",{className:"collapsible-arrow",children:e.jsx(L,{name:x?"caret-down":"caret-right",size:10})})]})]}),x&&e.jsx("div",{className:"collapsible-content",children:r})]})}function Vs({area:s,isSelected:a,onClick:t,onDelete:o}){const{t:r}=Y(["config","common"]),d=s.assignedAgentIds.length,c=s.type==="rectangle"?r("config:areas.rect"):r("config:areas.circle");return e.jsxs("div",{className:`area-item ${a?"selected":""}`,onClick:t,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:[c," ",d>0&&`• ${d} ${d>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 Ks({building:s,isSelected:a,onClick:t,onEdit:o}){var g;const{t:r}=Y(["config"]),d=((g=s.pm2Status)==null?void 0:g.ports)||[],c=(n,x)=>{n.stopPropagation(),window.open(`http://${window.location.hostname}:${x}`,"_blank")};return e.jsxs("div",{className:`building-item ${a?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:as[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(L,{name:ns(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,d.length>0&&e.jsx("span",{className:"building-ports",children:d.map(n=>e.jsxs("a",{href:`http://${window.location.hostname}:${n}`,className:"building-port-link",onClick:x=>c(x,n),title:`Open :${n}`,children:[":",n]},n))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:n=>{n.stopPropagation(),o()},title:r("config:buildings.editBuilding"),children:e.jsx(L,{name:"gear",size:14})})]})}function Hs({building:s,onClose:a,onOpenModal:t}){var x,w,C,u,p,m,j,b;const{t:o}=Y(["config","common"]),{buildingLogs:r}=Ve(),d=E.getBuildingLogs(s.id),c=ms[s.style||"server-rack"],g=h=>{E.sendBuildingCommand(s.id,h)},n=h=>{window.open(h,"_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(L,{name:ns(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:as[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:a,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:c.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:()=>g("start"),disabled:!((x=s.commands)!=null&&x.start)||s.status==="running",title:((w=s.commands)==null?void 0:w.start)||o("config:buildings.noStartCommand"),children:[e.jsx(L,{name:"play",size:12})," ",o("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>g("stop"),disabled:!((C=s.commands)!=null&&C.stop)||s.status==="stopped",title:((u=s.commands)==null?void 0:u.stop)||o("config:buildings.noStopCommand"),children:[e.jsx(L,{name:"stop",size:12,weight:"fill"})," ",o("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>g("restart"),disabled:!((p=s.commands)!=null&&p.restart),title:((m=s.commands)==null?void 0:m.restart)||o("config:buildings.noRestartCommand"),children:[e.jsx(L,{name:"refresh",size:12})," ",o("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>g("healthCheck"),disabled:!((j=s.commands)!=null&&j.healthCheck),title:((b=s.commands)==null?void 0:b.healthCheck)||o("config:buildings.noHealthCheck"),children:[e.jsx(L,{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((h,k)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>n(h.url),title:h.url,children:[e.jsx(L,{name:"link",size:12})," ",h.label||h.url]},k))})]}),d.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:()=>E.clearBuildingLogs(s.id),title:o("common:buttons.clear"),children:o("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:d.slice(-5).map((h,k)=>e.jsx("div",{className:"building-editor-log-entry",children:h},k))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx(L,{name:"gear",size:12})," ",o("config:buildings.fullSettings")]})})]})}async function Ws(s,a){const t=Z(),o=await fetch(he(`/api/areas/${s}/logo`),{method:"POST",headers:{"Content-Type":a.type||"image/png","X-Filename":encodeURIComponent(a.name),...t?{Authorization:`Bearer ${t}`}:{}},body:a});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 qs(s){const a=Z(),t=await fetch(he(`/api/areas/${s}/logo`),{method:"DELETE",headers:{...a?{Authorization:`Bearer ${a}`}:{}}});if(!t.ok)throw new Error(`Failed to delete logo: ${t.statusText}`)}function Gs(s){return is(he(`/api/areas/logos/${s}`))}const Ys=[{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 Js({area:s,onClose:a,onOpenFolder:t}){var ie;const{t:o}=Y(["config","common"]),[r,d]=l.useState(s.name),[c,g]=l.useState(s.prompt||""),[n,x]=l.useState(!1),[w,C]=l.useState(""),[u,p]=l.useState(!1),m=l.useRef(null);l.useEffect(()=>{d(s.name)},[s.id,s.name]),l.useEffect(()=>{g(s.prompt||"")},[s.id,s.prompt]);const j=v=>{const F=v.target.value;d(F),E.updateArea(s.id,{name:F})},b=v=>{E.updateArea(s.id,{color:v})},h=v=>{const F=v.target.value;g(F),E.updateArea(s.id,{prompt:F})},k=()=>{w.trim()&&(E.addDirectoryToArea(s.id,w.trim()),C(""),x(!1))},$=(v,F)=>{F.stopPropagation(),E.removeDirectoryFromArea(s.id,v)},P=()=>{E.bringAreaToFront(s.id)},K=()=>{E.sendAreaToBack(s.id)},y=l.useCallback(()=>{let v=2,F=2;s.type==="rectangle"&&s.width&&s.height?(v=s.width,F=s.height):s.type==="circle"&&s.radius&&(v=s.radius*1.414,F=s.radius*1.414);const M=Math.min(v,F)*.4;return{width:Math.round(M*10)/10,height:Math.round(M*10)/10}},[s.type,s.width,s.height,s.radius]),U=async v=>{var M;const F=(M=v.target.files)==null?void 0:M[0];if(F){p(!0);try{const N=await Ws(s.id,F),D=y();E.updateArea(s.id,{logo:{filename:N.filename,position:"center",width:D.width,height:D.height,keepAspectRatio:!0,opacity:.8}})}catch(N){console.error("Failed to upload logo:",N)}finally{p(!1),m.current&&(m.current.value="")}}},B=async()=>{try{await qs(s.id),E.updateArea(s.id,{logo:void 0})}catch(v){console.error("Failed to remove logo:",v)}},V=v=>{s.logo&&E.updateArea(s.id,{logo:{...s.logo,position:v}})},S=v=>{if(!s.logo)return;const F=parseFloat(v.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const M=s.logo.height/s.logo.width;E.updateArea(s.id,{logo:{...s.logo,width:F,height:Math.round(F*M*10)/10}})}else E.updateArea(s.id,{logo:{...s.logo,width:F}})},T=v=>{if(!s.logo)return;const F=parseFloat(v.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const M=s.logo.width/s.logo.height;E.updateArea(s.id,{logo:{...s.logo,height:F,width:Math.round(F*M*10)/10}})}else E.updateArea(s.id,{logo:{...s.logo,height:F}})},H=()=>{s.logo&&E.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},X=v=>{s.logo&&E.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(v.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:a,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:j,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:gs.map(v=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===v?"selected":""}`,style:{backgroundColor:v},onClick:()=>b(v),"aria-label":`Set area color ${v}`,"aria-pressed":s.color===v,title:v},v))})]}),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:P,title:o("config:areas.bringToFront"),children:[e.jsx(L,{name:"arrow-up",size:12})," ",o("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:K,title:o("config:areas.sendToBack"),children:[e.jsx(L,{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:[(ie=s.logo)!=null&&ie.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:Gs(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:B,children:o("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var v;return(v=m.current)==null?void 0:v.click()},disabled:u,children:u?"...":e.jsx(L,{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:Ys.map(({key:v,labelKey:F})=>{var M;return e.jsx("button",{className:`area-logo-pos-btn ${((M=s.logo)==null?void 0:M.position)===v?"active":""}`,onClick:()=>V(v),children:o(`config:areas.${F}`)},v)})})]}),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:S,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:T,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:H}),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:X,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 v;return(v=m.current)==null?void 0:v.click()},disabled:u,children:u?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:m,type:"file",accept:"image/*",style:{display:"none"},onChange:U})]})]}),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(v=>e.jsxs("div",{className:"area-folder-item",title:v,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:o("config:areas.openFolder"),children:e.jsx(L,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:v.split("/").pop()||v}),e.jsx("button",{className:"area-folder-remove",onClick:F=>$(v,F),title:o("config:areas.removeFolder"),children:"×"})]},v)),n?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(fs,{value:w,onChange:C,onSubmit:k,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:k,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>x(!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:c,onChange:h,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 Zs(){const{t:s}=Y(["config","common"]),a=xs(),[t,o]=l.useState(!1),[r,d]=l.useState(null),[c,g]=l.useState({name:"",key:"",value:"",description:""}),[n,x]=l.useState(null),w=()=>{o(!0),d(null),g({name:"",key:"",value:"",description:""})},C=h=>{d(h.id),o(!1),g({name:h.name,key:h.key,value:h.value,description:h.description||""})},u=()=>{o(!1),d(null),g({name:"",key:"",value:"",description:""})},p=()=>{!c.name.trim()||!c.key.trim()||(r?E.updateSecret(r,{name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}):E.createSecret({name:c.name.trim(),key:c.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:c.value,description:c.description.trim()||void 0}),u())},m=h=>{x(h)},j=()=>{n&&(E.deleteSecret(n),r===n&&u())},b=h=>{navigator.clipboard.writeText(`{{${h}}}`)};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:a.length===0&&!t?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):a.map(h=>e.jsxs("div",{className:`secret-item ${r===h.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:h.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>b(h.key),title:s("config:secrets.copyPlaceholder"),children:`{{${h.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>C(h),title:s("common:buttons.edit"),children:e.jsx(L,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>m(h.id),title:s("common:buttons.delete"),children:"×"})]})]}),h.description&&e.jsx("div",{className:"secret-item-description",children:h.description})]},h.id))}),(t||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:c.name,onChange:h=>g({...c,name:h.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:c.key,onChange:h=>g({...c,key:h.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${c.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:c.value,onChange:h=>g({...c,value:h.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:c.description,onChange:h=>g({...c,description:h.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:u,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:p,disabled:!c.name.trim()||!c.key.trim(),children:s(r?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!r&&e.jsx("button",{className:"secrets-add-btn",onClick:w,children:s("config:secrets.addSecret")}),e.jsx(me,{isOpen:n!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:j,onClose:()=>x(null)})]})}async function Xs(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch system prompt: ${a.statusText}`);return(await a.json()).prompt||""}async function Qs(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({prompt:s})});if(!t.ok)throw new Error(`Failed to update system prompt: ${t.statusText}`)}async function et(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to clear system prompt: ${a.statusText}`)}async function st(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch echo prompt setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function tt(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function at(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch codex binary path: ${a.statusText}`);return(await a.json()).path||""}async function nt(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function it(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch tmux mode setting: ${a.statusText}`);return(await a.json()).enabled||!1}async function ot(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function lt(){const s=Z(),a=await fetch(`${J()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!a.ok)throw new Error(`Failed to fetch backup status: ${a.statusText}`);return a.json()}async function ct(s){const a=Z(),t=await fetch(`${J()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({enabled:s})});if(!t.ok){const o=await t.json().catch(()=>({}));throw new Error(o.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function rt({checked:s,onChange:a,disabled:t}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:t,onChange:o=>a(o.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function dt(){const{t:s}=Y(["config","common"]),[a,t]=l.useState([]),[o,r]=l.useState(new Set),[d,c]=l.useState(new Set),[g,n]=l.useState(!1),[x,w]=l.useState(!1),[C,u]=l.useState(null),[p,m]=l.useState(null),[j,b]=l.useState(null),[h,k]=l.useState(null),[$,P]=l.useState(!1),[K,y]=l.useState(null);l.useEffect(()=>{we(he("/api/config/categories")).then(N=>N.json()).then(N=>{const D=Array.isArray(N)?N:[];t(D),r(new Set(D.map(O=>O.id)))}).catch(N=>console.error("Failed to fetch config categories:",N))},[]),l.useEffect(()=>{lt().then(k).catch(N=>{console.error("Failed to fetch backup status:",N),y(N.message||"Failed to fetch backup status")})},[]);const U=async N=>{if(!$){P(!0),y(null);try{const D=await ct(N);k(D)}catch(D){y(D.message||"Failed to update backup setting")}finally{P(!1)}}},B=N=>{r(D=>{const O=new Set(D);return O.has(N)?O.delete(N):O.add(N),O})},V=N=>{c(D=>{const O=new Set(D);return O.has(N)?O.delete(N):O.add(N),O})},S=()=>r(new Set(a.map(N=>N.id))),T=()=>r(new Set),H=()=>{p&&c(new Set(p.categories.map(N=>N.id)))},X=()=>c(new Set),ie=async()=>{var N;if(o.size!==0){n(!0),b(null);try{const D=Array.from(o).join(","),O=await we(he(`/api/config/export?categories=${D}`));if(!O.ok)throw new Error("Export failed");const ee=await O.blob(),se=window.URL.createObjectURL(ee),Q=document.createElement("a");Q.href=se;const A=O.headers.get("Content-Disposition"),q=((N=A==null?void 0:A.match(/filename="(.+)"/))==null?void 0:N[1])||"tide-commander-config.zip";Q.download=q,document.body.appendChild(Q),Q.click(),document.body.removeChild(Q),window.URL.revokeObjectURL(se),b({type:"success",text:s("config:data.exportSuccess")})}catch(D){b({type:"error",text:D.message||"Export failed"})}finally{n(!1)}}},v=async N=>{var O;const D=(O=N.target.files)==null?void 0:O[0];if(D){u(D),b(null),m(null),c(new Set);try{const ee=await we(he("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await D.arrayBuffer()});if(!ee.ok){const A=await ee.json();throw new Error(A.error||"Failed to preview config file")}const se=await ee.json(),Q=Array.isArray(se.categories)?se.categories:[];m({...se,categories:Q}),c(new Set(Q.map(A=>A.id)))}catch(ee){b({type:"error",text:ee.message||"Failed to read config file"}),u(null)}}},F=async()=>{if(!(!C||d.size===0)){w(!0),b(null);try{const N=Array.from(d).join(","),D=await we(he(`/api/config/import?categories=${N}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await C.arrayBuffer()}),O=await D.json();if(!D.ok)throw new Error(O.error||"Import failed");b({type:"success",text:O.message||s("config:data.importSuccess")}),u(null),m(null),c(new Set)}catch(N){b({type:"error",text:N.message||"Import failed"})}finally{w(!1)}}},M=()=>{u(null),m(null),c(new Set),b(null)};return e.jsxs("div",{className:"data-section",children:[j&&e.jsx("div",{className:`data-message data-message-${j.type}`,children:j.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(rt,{checked:!!(h!=null&&h.enabled),disabled:$||!h,onChange:U})]}),e.jsxs("div",{className:"data-backup-info",children:[h?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:h.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!h.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:h.scriptPath})]}),h.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(h.lastRunAt).toLocaleString(),h.lastRunOk===!0&&" — ok",h.lastRunOk===!1&&h.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",h.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),K&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:K})]})]}),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:S,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:T,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:a.map(N=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(N.id),onChange:()=>B(N.id)}),e.jsx("span",{className:"data-category-name",children:N.name})]},N.id))}),e.jsx("button",{className:"data-action-btn export",onClick:ie,disabled:g||o.size===0,children:g?s("config:data.exporting"):s("config:data.exportCount",{count:o.size})})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsx("div",{className:"data-subsection-header",children:e.jsx("span",{className:"data-subsection-title",children:s("config:data.importData")})}),C?p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:C.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(p.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:H,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:p.categories.map(N=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:d.has(N.id),onChange:()=>V(N.id)}),e.jsx("span",{className:"data-category-name",children:N.name}),N.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",N.fileCount," ",s("config:data.files"),")"]})]},N.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:M,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:F,disabled:x||d.size===0,children:x?s("config:data.importing"):s("config:data.importCount",{count:d.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:v,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}async function ut(){const s=await we(`${J()}/api/system/install-info`);if(!s.ok)throw new Error(`Failed to fetch install info: ${s.statusText}`);return s.json()}function pt(s,a){const t=new AbortController;return(async()=>{try{const o=await fetch(is(`${J()}/api/system/self-update`),{method:"POST",signal:t.signal,headers:{Accept:"text/event-stream"}});if(!o.ok||!o.body){const g=await o.text().catch(()=>"");let n=null;try{n=JSON.parse(g)}catch{}const x=n&&typeof n=="object"&&"error"in n&&typeof n.error=="string"?n.error:`Self-update failed: ${o.status} ${o.statusText}`;s({type:"error",message:x}),a(new Error(x));return}const r=o.body.getReader(),d=new TextDecoder("utf-8");let c="";for(;;){const{value:g,done:n}=await r.read();if(n)break;c+=d.decode(g,{stream:!0});let x=c.indexOf(`
2
2
 
3
3
  `);for(;x!==-1;){const w=c.slice(0,x);c=c.slice(x+2);const C=w.split(`
4
4
  `);let u="message",p="";for(const m of C)m.startsWith(":")||(m.startsWith("event:")?u=m.slice(6).trim():m.startsWith("data:")&&(p+=(p?`