tide-commander 1.180.0 → 1.182.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 (180) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +27 -4
  3. package/dist/assets/{AudioPlayer-Cz_qaJt7.js → AudioPlayer-BwhOjJ2c.js} +1 -1
  4. package/dist/assets/{BossLogsModal-DL1RQ_c8.js → BossLogsModal-DAHZQ1pi.js} +1 -1
  5. package/dist/assets/BossSpawnModal-E7SGuXA2.js +1 -0
  6. package/dist/assets/ControlsModal-bAaYejMT.js +1 -0
  7. package/dist/assets/{DockerLogsModal-B6s9FxxT.js → DockerLogsModal-BJx8N4kK.js} +1 -1
  8. package/dist/assets/{EmbeddedEditor-BUKbOOgr.js → EmbeddedEditor-Be-cO4-9.js} +1 -1
  9. package/dist/assets/{FcStdViewer-Bx5hMoK9.js → FcStdViewer-DEwQ08Bb.js} +1 -1
  10. package/dist/assets/{GcodeViewer-CRz3h-C6.js → GcodeViewer-ncf61wWb.js} +1 -1
  11. package/dist/assets/{GlbViewer-DaVg-HwZ.js → GlbViewer-D12gmnGd.js} +1 -1
  12. package/dist/assets/{GmailOAuthSetup-raTkXEzN.js → GmailOAuthSetup-C-GvDGQm.js} +1 -1
  13. package/dist/assets/{GoogleOAuthSetup-oB9PTp3c.js → GoogleOAuthSetup-BDjIAgur.js} +1 -1
  14. package/dist/assets/{IframeModal-BA2IpgVa.js → IframeModal-CCocGfa7.js} +1 -1
  15. package/dist/assets/IntegrationsPanel-CBpaeiJG.js +2 -0
  16. package/dist/assets/{LogViewerModal-wvxDKRNy.js → LogViewerModal-CaN7XU8z.js} +1 -1
  17. package/dist/assets/{MonitoringModal-BAZh_17S.js → MonitoringModal-I3nCNlbU.js} +1 -1
  18. package/dist/assets/{PM2LogsModal-D1CyGphi.js → PM2LogsModal-Bki_LCvj.js} +1 -1
  19. package/dist/assets/RestoreArchivedAreaModal-Ciy6t7et.js +1 -0
  20. package/dist/assets/Scene2DCanvas-DR56E5p7.js +1 -0
  21. package/dist/assets/SceneManager-DKg8ugY_.js +104 -0
  22. package/dist/assets/{SkillsPanel-DHKmED86.js → SkillsPanel-C_dxzS6F.js} +1 -1
  23. package/dist/assets/{SlackMultiInstanceSetup-DeI76a7K.js → SlackMultiInstanceSetup-BwiTMMvL.js} +1 -1
  24. package/dist/assets/SpawnModal-DUMcIHoz.js +1 -0
  25. package/dist/assets/{StatisticsModal-B6Ua3fi6.js → StatisticsModal-BKXcBthy.js} +1 -1
  26. package/dist/assets/{StlViewer-CbcEbSjC.js → StlViewer-DjdLvysP.js} +1 -1
  27. package/dist/assets/{SubordinateAssignmentModal-Dr5Gjs16.js → SubordinateAssignmentModal-Rl4cdHpe.js} +1 -1
  28. package/dist/assets/{ThreeAreaSelector-Dh_fDEGq.js → ThreeAreaSelector-C-9JJ1Hh.js} +1 -1
  29. package/dist/assets/{ThreeViewShortcuts-BVaOMNTJ.js → ThreeViewShortcuts-DL0Hmuj0.js} +1 -1
  30. package/dist/assets/{TriggerManagerPanel-D6oUAmpx.js → TriggerManagerPanel-BtCOoX1g.js} +1 -1
  31. package/dist/assets/{VideoPlayer-DSKjm0Rl.js → VideoPlayer-BoTr9gkT.js} +1 -1
  32. package/dist/assets/{WorkflowEditorPanel-BLMxrEav.js → WorkflowEditorPanel-DlcSaDPD.js} +1 -1
  33. package/dist/assets/{abnfDiagram-VRR7QNED-BLKdtiAT.js → abnfDiagram-VRR7QNED-CEBRXYsw.js} +1 -1
  34. package/dist/assets/{arc-BHCFYdNr.js → arc-COf9R405.js} +1 -1
  35. package/dist/assets/{architectureDiagram-ZJ3FMSHR-CK8TJwVc.js → architectureDiagram-ZJ3FMSHR-DGBRfu4B.js} +1 -1
  36. package/dist/assets/{area-logos-CLcDGHt_.js → area-logos-BRuKyQ5J.js} +1 -1
  37. package/dist/assets/{blockDiagram-677ZJIJ3-BOk8UxeA.js → blockDiagram-677ZJIJ3-CN0t4U2k.js} +1 -1
  38. package/dist/assets/{c4Diagram-LMCZKHZV-CWmx6n3m.js → c4Diagram-LMCZKHZV-Cq0IftW5.js} +1 -1
  39. package/dist/assets/channel-DF_pUJhw.js +1 -0
  40. package/dist/assets/{chunk-2Q5K7J3B-2BAqevAz.js → chunk-2Q5K7J3B-adR2VoGA.js} +1 -1
  41. package/dist/assets/{chunk-32BRIVSS-B1otNrWa.js → chunk-32BRIVSS-B6LCChZq.js} +1 -1
  42. package/dist/assets/{chunk-5VM5RSS4-YCDhdxCC.js → chunk-5VM5RSS4-CcH2c7y_.js} +1 -1
  43. package/dist/assets/{chunk-EX3LRPZG-DDtm7s-z.js → chunk-EX3LRPZG-zBWa-mu2.js} +1 -1
  44. package/dist/assets/{chunk-JWPE2WC7-Vbn7w4Z5.js → chunk-JWPE2WC7-DBQlYiWn.js} +1 -1
  45. package/dist/assets/{chunk-MOJQB5TN-CQ9u77Ko.js → chunk-MOJQB5TN-BjbsCplS.js} +1 -1
  46. package/dist/assets/{chunk-RYQCIY6F-DepOO-2a.js → chunk-RYQCIY6F-B946ZxlN.js} +1 -1
  47. package/dist/assets/{chunk-V7JOEXUC-CUMPiqnf.js → chunk-V7JOEXUC-DEeYHnRT.js} +1 -1
  48. package/dist/assets/{chunk-VR4S4FIN-Dtx2puKW.js → chunk-VR4S4FIN-B_QmrVGt.js} +1 -1
  49. package/dist/assets/{chunk-XXDRQBXY-DflWhtMT.js → chunk-XXDRQBXY-cgYh6YrW.js} +1 -1
  50. package/dist/assets/classDiagram-OUVF2IWQ-CeYNs9YM.js +1 -0
  51. package/dist/assets/classDiagram-v2-EOCWNBFH-CeYNs9YM.js +1 -0
  52. package/dist/assets/{cose-bilkent-JH36ORCC-BPCVBohN.js → cose-bilkent-JH36ORCC-DJUmw0Ip.js} +1 -1
  53. package/dist/assets/{cynefin-VYW2F7L2-DFQe8Pa0.js → cynefin-VYW2F7L2-BUxR220i.js} +1 -1
  54. package/dist/assets/{cynefinDiagram-TSTJHNR4-Zk4bhRmG.js → cynefinDiagram-TSTJHNR4-nYR1MwE2.js} +1 -1
  55. package/dist/assets/{dagre-VKFMJZFB-Bd5Kw9Yw.js → dagre-VKFMJZFB-A5VPim2l.js} +1 -1
  56. package/dist/assets/{diagram-FQU43EPY-B9CcbcB0.js → diagram-FQU43EPY-wdgwDoVg.js} +1 -1
  57. package/dist/assets/{diagram-G47NLZAW-CdAGXxiX.js → diagram-G47NLZAW-CylyJQBQ.js} +1 -1
  58. package/dist/assets/{diagram-NH7WQ7WH-D5Oky8Ra.js → diagram-NH7WQ7WH-BOF1uKhH.js} +1 -1
  59. package/dist/assets/{diagram-OA4YK3LP-CxrBKuWK.js → diagram-OA4YK3LP-B0B5zmh5.js} +1 -1
  60. package/dist/assets/{diagram-WEI45ONY-BV_xqGTJ.js → diagram-WEI45ONY-vKP2IU9q.js} +1 -1
  61. package/dist/assets/{ebnfDiagram-CCIWWBDH-BR8zM3WP.js → ebnfDiagram-CCIWWBDH-DM8hIEJM.js} +1 -1
  62. package/dist/assets/{erDiagram-Q63AITRT-B1O13nas.js → erDiagram-Q63AITRT-iuRH3hWX.js} +1 -1
  63. package/dist/assets/{flowDiagram-23GEKE2U-DTtaohaz.js → flowDiagram-23GEKE2U-CddCUoGB.js} +1 -1
  64. package/dist/assets/{ganttDiagram-NO4QXBWP-CF7GsC2n.js → ganttDiagram-NO4QXBWP-CIfvQLcu.js} +1 -1
  65. package/dist/assets/{gitGraphDiagram-IHSO6WYX-D0RiPHL-.js → gitGraphDiagram-IHSO6WYX-CbW0FQci.js} +1 -1
  66. package/dist/assets/index-B4YklnOy.js +1 -0
  67. package/dist/assets/{index-BddR9Hew.js → index-BmD7ycmn.js} +1 -1
  68. package/dist/assets/index-CIcFjlRX.js +2 -0
  69. package/dist/assets/index-CRhUiTuD.js +5 -0
  70. package/dist/assets/{index-COqQ_1sL.css → index-D1GfjaTN.css} +1 -1
  71. package/dist/assets/index-DHuT10Pa.js +1 -0
  72. package/dist/assets/{index-Dqzs1ikY.js → index-DoJdznbY.js} +1 -1
  73. package/dist/assets/index-Du8eK_OX.js +1 -0
  74. package/dist/assets/index-HYcYan1q.js +19 -0
  75. package/dist/assets/index-HhAZ3SIm.js +2 -0
  76. package/dist/assets/{infoDiagram-FWYZ7A6U-aneMMKcw.js → infoDiagram-FWYZ7A6U-C0it9hLc.js} +1 -1
  77. package/dist/assets/{ishikawaDiagram-FXEZZL3T-DUn2XrMN.js → ishikawaDiagram-FXEZZL3T-pKZnNgqp.js} +1 -1
  78. package/dist/assets/{journeyDiagram-5HDEW3XC-mvoaOTx8.js → journeyDiagram-5HDEW3XC-Ib9FpXdB.js} +1 -1
  79. package/dist/assets/{kanban-definition-HUTT4EX6-BKYcDsJ8.js → kanban-definition-HUTT4EX6-aOTfe6f6.js} +1 -1
  80. package/dist/assets/{linear-BsLXRSOu.js → linear-B_ipWlyx.js} +1 -1
  81. package/dist/assets/main-Bvn8CMZc.css +1 -0
  82. package/dist/assets/{main-CN0vutCJ.js → main-m3NNcAo4.js} +123 -123
  83. package/dist/assets/{mermaid.core-i9VF0Zpk.js → mermaid.core-EY9hyXLz.js} +4 -4
  84. package/dist/assets/{mindmap-definition-LN4V7U3C-DzkNRyrc.js → mindmap-definition-LN4V7U3C-B_p1LOAa.js} +1 -1
  85. package/dist/assets/{pegDiagram-2B236MQR-j0c_f4--.js → pegDiagram-2B236MQR-BgCd9rWg.js} +1 -1
  86. package/dist/assets/pi.ico +0 -0
  87. package/dist/assets/pi.png +0 -0
  88. package/dist/assets/pi.svg +4 -0
  89. package/dist/assets/{pieDiagram-ENE6RG2P-CRd7Wdjw.js → pieDiagram-ENE6RG2P-d8ofNooq.js} +1 -1
  90. package/dist/assets/{quadrantDiagram-ABIIQ3AL-DgG32Ucv.js → quadrantDiagram-ABIIQ3AL-27DPJdZF.js} +1 -1
  91. package/dist/assets/{railroadDiagram-RFXS5EU6-8og5AiqA.js → railroadDiagram-RFXS5EU6-C7S8pppU.js} +1 -1
  92. package/dist/assets/{requirementDiagram-TGXJPOKE-_TyvWq5_.js → requirementDiagram-TGXJPOKE-BbTkDbLO.js} +1 -1
  93. package/dist/assets/{sankeyDiagram-HTMAVEWB-Cda8LUXs.js → sankeyDiagram-HTMAVEWB-lU57KWVw.js} +1 -1
  94. package/dist/assets/{sequenceDiagram-DBY2YBRQ-3VD9Qswm.js → sequenceDiagram-DBY2YBRQ-Bg18P0LT.js} +1 -1
  95. package/dist/assets/{sizeCapture-X5ZJPWSS-DcvxmWDr.js → sizeCapture-X5ZJPWSS-FDhyxAiu.js} +1 -1
  96. package/dist/assets/{stateDiagram-2N3HPSRC-DoJZPzL9.js → stateDiagram-2N3HPSRC-pp9KUH2d.js} +1 -1
  97. package/dist/assets/stateDiagram-v2-6OUMAXLB-BmoS7QDQ.js +1 -0
  98. package/dist/assets/swimlanes-5IMT3BWC-BCUZKORl.js +2 -0
  99. package/dist/assets/swimlanesDiagram-G3AALYLV-Da6QbdiL.js +8 -0
  100. package/dist/assets/{timeline-definition-FHXFAJF6-B7Ze_1_m.js → timeline-definition-FHXFAJF6-BaeOwVlH.js} +1 -1
  101. package/dist/assets/{vennDiagram-L72KCM5P-Br9P67sq.js → vennDiagram-L72KCM5P-BkhqU_hz.js} +1 -1
  102. package/dist/assets/{wardleyDiagram-EHGQE667-D6_zW1Qq.js → wardleyDiagram-EHGQE667-DvPxIC6q.js} +1 -1
  103. package/dist/assets/{web-DjnthuJQ.js → web-BhVPxATx.js} +1 -1
  104. package/dist/assets/{web-Dkft1Ie_.js → web-CR-app3U.js} +1 -1
  105. package/dist/assets/{web-ChLjyxaY.js → web-DOiXCdVs.js} +1 -1
  106. package/dist/assets/{xychartDiagram-FW5EYKEG-bDjV8_Lg.js → xychartDiagram-FW5EYKEG-B9MrBAD_.js} +1 -1
  107. package/dist/build-info.json +1 -1
  108. package/dist/index.html +2 -2
  109. package/dist/locales/de/config.json +5 -0
  110. package/dist/locales/de/terminal.json +1 -0
  111. package/dist/locales/en/config.json +6 -0
  112. package/dist/locales/en/terminal.json +2 -0
  113. package/dist/locales/es/config.json +5 -0
  114. package/dist/locales/es/terminal.json +11 -0
  115. package/dist/locales/fr/config.json +5 -0
  116. package/dist/locales/fr/terminal.json +1 -0
  117. package/dist/locales/hi/config.json +5 -0
  118. package/dist/locales/hi/terminal.json +1 -0
  119. package/dist/locales/it/config.json +5 -0
  120. package/dist/locales/it/terminal.json +1 -0
  121. package/dist/locales/ja/config.json +5 -0
  122. package/dist/locales/ja/terminal.json +1 -0
  123. package/dist/locales/pt/config.json +5 -0
  124. package/dist/locales/pt/terminal.json +1 -0
  125. package/dist/locales/ru/config.json +5 -0
  126. package/dist/locales/ru/terminal.json +1 -0
  127. package/dist/locales/zh-CN/config.json +5 -0
  128. package/dist/locales/zh-CN/terminal.json +1 -0
  129. package/dist/src/packages/server/claude/runner/stdout-pipeline.js +3 -1
  130. package/dist/src/packages/server/claude/session-loader.js +284 -0
  131. package/dist/src/packages/server/data/builtin-skills/boss-instructions.js +4 -2
  132. package/dist/src/packages/server/data/index.js +1 -0
  133. package/dist/src/packages/server/grok/backend.js +7 -10
  134. package/dist/src/packages/server/index.js +61 -34
  135. package/dist/src/packages/server/pi/backend.js +264 -0
  136. package/dist/src/packages/server/pi/index.js +3 -0
  137. package/dist/src/packages/server/pi/json-event-parser.js +275 -0
  138. package/dist/src/packages/server/pi/rpc/pi-rpc-runner.js +391 -0
  139. package/dist/src/packages/server/routes/agents.js +79 -2
  140. package/dist/src/packages/server/routes/files.js +45 -19
  141. package/dist/src/packages/server/runtime/index.js +1 -0
  142. package/dist/src/packages/server/runtime/pi-runner-router.js +105 -0
  143. package/dist/src/packages/server/runtime/pi-runtime-provider.js +12 -0
  144. package/dist/src/packages/server/services/agent-service.js +14 -2
  145. package/dist/src/packages/server/services/global-file-search.js +281 -0
  146. package/dist/src/packages/server/services/prompt-inspection-service.js +15 -0
  147. package/dist/src/packages/server/services/runtime-command-execution.js +4 -2
  148. package/dist/src/packages/server/services/runtime-events.js +18 -3
  149. package/dist/src/packages/server/services/runtime-service.js +19 -3
  150. package/dist/src/packages/server/services/system-prompt-service.js +46 -0
  151. package/dist/src/packages/server/websocket/handler.js +16 -6
  152. package/dist/src/packages/server/websocket/handlers/agent-handler.js +23 -11
  153. package/dist/src/packages/server/websocket/handlers/boss-response-handler.js +4 -4
  154. package/dist/src/packages/server/websocket/listeners/runtime-listeners.js +7 -0
  155. package/dist/src/packages/shared/agent-types.js +60 -5
  156. package/dist/src/packages/shared/file-search.js +49 -0
  157. package/dist/src/packages/shared/types.js +1 -0
  158. package/package.json +1 -1
  159. package/scripts/recover-agents.ts +1 -1
  160. package/dist/assets/BossSpawnModal-HFw-EI4q.js +0 -1
  161. package/dist/assets/ControlsModal-B5x8krS0.js +0 -1
  162. package/dist/assets/IntegrationsPanel-CkpN3tEm.js +0 -2
  163. package/dist/assets/RestoreArchivedAreaModal-ChxxCEBp.js +0 -1
  164. package/dist/assets/Scene2DCanvas-CsWUWMyg.js +0 -1
  165. package/dist/assets/SceneManager-KFc6HxE-.js +0 -104
  166. package/dist/assets/SpawnModal-Dv4942eR.js +0 -1
  167. package/dist/assets/channel-C1UbIsM4.js +0 -1
  168. package/dist/assets/classDiagram-OUVF2IWQ-Dr6eXMS3.js +0 -1
  169. package/dist/assets/classDiagram-v2-EOCWNBFH-Dr6eXMS3.js +0 -1
  170. package/dist/assets/index-B2tBflVO.js +0 -2
  171. package/dist/assets/index-Bxr4AiEk.js +0 -2
  172. package/dist/assets/index-C6jqY5vM.js +0 -1
  173. package/dist/assets/index-Cpz94DKJ.js +0 -1
  174. package/dist/assets/index-DGOAfDCV.js +0 -1
  175. package/dist/assets/index-DYh_qbU4.js +0 -5
  176. package/dist/assets/index-gQjHBiGd.js +0 -19
  177. package/dist/assets/main-DQoNBeOV.css +0 -1
  178. package/dist/assets/stateDiagram-v2-6OUMAXLB-BUtkiS3W.js +0 -1
  179. package/dist/assets/swimlanes-5IMT3BWC-Co7uCoVg.js +0 -2
  180. package/dist/assets/swimlanesDiagram-G3AALYLV-C3seowIK.js +0 -8
@@ -1 +0,0 @@
1
- import{r as l,j as e,I,u as X,c2 as ms,af as gs,c3 as _s,c5 as Is,s as w,cI as $s,F as Os,cJ as Ls,X as xe,K as Z,aV as Y,c as Ne,d as ye,cK as Ds,cL as Fs,cM as Rs,cN as Bs,cO as Ms,cP as Us,cQ as zs,cR as fs,cS as Vs,cT as Ks,cU as Hs,aU as qs,as as Ws,a2 as $e,n as Gs,cV as xs,cW as Ys,cX as Xe,cY as Js,cZ as Xs,c_ as Zs,c$ as Qs,d0 as et,d1 as st,d2 as tt,bn as at,k as nt,m as ot,S as _e,d3 as it,d4 as lt,d5 as ct,d6 as He,d7 as rt,d8 as dt,B as ut,d9 as pt,da as ht,db as mt,dc as gt,dd as bs,de as is,df as js,dg as ft,dh as xt,di as Ie,dj as bt,dk as qe,dl as ls,b_ as We,w as Fe,v as jt,dm as Ge,dn as vt,dp as cs,dq as wt,dr as Nt,ds as yt,_ as kt,f as St,dt as Ct,du as At,dv as Tt}from"./main-CN0vutCJ.js";import{g as Et,d as Pt,u as _t}from"./area-logos-CLcDGHt_.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-CBPuP1jE.js";const vs="tide-toolbox-collapse";function It(s,n){try{const t=localStorage.getItem(`${vs}-${s}`);if(t!==null)return t==="true"}catch{}return n}function $t(s,n){try{localStorage.setItem(`${vs}-${s}`,String(n))}catch{}}function q({title:s,storageKey:n,defaultOpen:t=!1,forceOpen:i=!1,children:d,headerExtra:c}){const[r,g]=l.useState(()=>n?It(n,t):t),o=()=>{const N=!r;g(N),n&&$t(n,N)},u=i||r;return e.jsxs("div",{className:`collapsible-section ${u?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:o,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[c,e.jsx("span",{className:"collapsible-arrow",children:e.jsx(I,{name:u?"caret-down":"caret-right",size:10})})]})]}),u&&e.jsx("div",{className:"collapsible-content",children:d})]})}function Ot({area:s,isSelected:n,onClick:t,onDelete:i}){const{t:d}=X(["config","common"]),c=s.assignedAgentIds.length,r=s.type==="rectangle"?d("config:areas.rect"):d("config:areas.circle");return e.jsxs("div",{className:`area-item ${n?"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:[r," ",c>0&&`• ${c} ${c>1?d("common:labels.agents").toLowerCase():d("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:i,title:d("config:areas.deleteArea"),children:"×"})]})}function Lt({building:s,isSelected:n,onClick:t,onEdit:i}){var g;const{t:d}=X(["config"]),c=((g=s.pm2Status)==null?void 0:g.ports)||[],r=(o,u)=>{o.stopPropagation(),window.open(`http://${window.location.hostname}:${u}`,"_blank")};return e.jsxs("div",{className:`building-item ${n?"selected":""}`,onClick:t,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:ms[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:e.jsx(I,{name:gs(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,c.length>0&&e.jsx("span",{className:"building-ports",children:c.map(o=>e.jsxs("a",{href:`http://${window.location.hostname}:${o}`,className:"building-port-link",onClick:u=>r(u,o),title:`Open :${o}`,children:[":",o]},o))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:o=>{o.stopPropagation(),i()},title:d("config:buildings.editBuilding"),children:e.jsx(I,{name:"gear",size:14})})]})}function Dt({building:s,onClose:n,onOpenModal:t}){var u,N,k,m,P,b,E,x;const{t:i}=X(["config","common"]),c=_s().get(s.id)||[],r=Is[s.style||"server-rack"],g=p=>{w.sendBuildingCommand(s.id,p)},o=p=>{window.open(p,"_blank")};return e.jsxs("div",{className:"building-editor",children:[e.jsxs("div",{className:"building-editor-header",children:[e.jsxs("div",{className:"building-editor-title-row",children:[e.jsx("span",{className:"building-editor-icon",children:e.jsx(I,{name:gs(s.type),size:18})}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:ms[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:n,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:i("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:i("config:buildings.style")}),e.jsx("span",{className:"building-editor-info-value",children:r.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:i("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:i("config:buildings.actions")}),e.jsxs("div",{className:"building-editor-actions",children:[e.jsxs("button",{className:"building-editor-action-btn start",onClick:()=>g("start"),disabled:!((u=s.commands)!=null&&u.start)||s.status==="running",title:((N=s.commands)==null?void 0:N.start)||i("config:buildings.noStartCommand"),children:[e.jsx(I,{name:"play",size:12})," ",i("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>g("stop"),disabled:!((k=s.commands)!=null&&k.stop)||s.status==="stopped",title:((m=s.commands)==null?void 0:m.stop)||i("config:buildings.noStopCommand"),children:[e.jsx(I,{name:"stop",size:12,weight:"fill"})," ",i("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>g("restart"),disabled:!((P=s.commands)!=null&&P.restart),title:((b=s.commands)==null?void 0:b.restart)||i("config:buildings.noRestartCommand"),children:[e.jsx(I,{name:"refresh",size:12})," ",i("common:buttons.retry")]}),e.jsxs("button",{className:"building-editor-action-btn health",onClick:()=>g("healthCheck"),disabled:!((E=s.commands)!=null&&E.healthCheck),title:((x=s.commands)==null?void 0:x.healthCheck)||i("config:buildings.noHealthCheck"),children:[e.jsx(I,{name:"heart",size:12})," Health"]})]})]}),s.urls&&s.urls.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:i("config:buildings.links")}),e.jsx("div",{className:"building-editor-links",children:s.urls.map((p,S)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>o(p.url),title:p.url,children:[e.jsx(I,{name:"link",size:12})," ",p.label||p.url]},S))})]}),c.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsxs("div",{className:"building-editor-section-title",children:[i("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>w.clearBuildingLogs(s.id),title:i("common:buttons.clear"),children:i("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:c.slice(-5).map((p,S)=>e.jsx("div",{className:"building-editor-log-entry",children:p},S))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:t,children:[e.jsx(I,{name:"gear",size:12})," ",i("config:buildings.fullSettings")]})})]})}const Ft=[{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 Rt({area:s,onClose:n,onOpenFolder:t}){var ne;const{t:i}=X(["config","common"]),[d,c]=l.useState(s.name),[r,g]=l.useState(s.prompt||""),[o,u]=l.useState(!1),[N,k]=l.useState(""),[m,P]=l.useState(!1),b=l.useRef(null);l.useEffect(()=>{c(s.name)},[s.id,s.name]),l.useEffect(()=>{g(s.prompt||"")},[s.id,s.prompt]);const E=j=>{const L=j.target.value;c(L),w.updateArea(s.id,{name:L})},x=j=>{w.updateArea(s.id,{color:j})},p=j=>{const L=j.target.value;g(L),w.updateArea(s.id,{prompt:L})},S=()=>{N.trim()&&(w.addDirectoryToArea(s.id,N.trim()),k(""),u(!1))},M=(j,L)=>{L.stopPropagation(),w.removeDirectoryFromArea(s.id,j)},F=()=>{w.bringAreaToFront(s.id)},Q=()=>{w.sendAreaToBack(s.id)},W=l.useCallback(()=>{let j=2,L=2;s.type==="rectangle"&&s.width&&s.height?(j=s.width,L=s.height):s.type==="circle"&&s.radius&&(j=s.radius*1.414,L=s.radius*1.414);const z=Math.min(j,L)*.4;return{width:Math.round(z*10)/10,height:Math.round(z*10)/10}},[s.type,s.width,s.height,s.radius]),J=async j=>{var z;const L=(z=j.target.files)==null?void 0:z[0];if(L){P(!0);try{const v=await _t(s.id,L),O=W();w.updateArea(s.id,{logo:{filename:v.filename,position:"center",width:O.width,height:O.height,keepAspectRatio:!0,opacity:.8}})}catch(v){console.error("Failed to upload logo:",v)}finally{P(!1),b.current&&(b.current.value="")}}},U=async()=>{try{await Pt(s.id),w.updateArea(s.id,{logo:void 0})}catch(j){console.error("Failed to remove logo:",j)}},V=j=>{s.logo&&w.updateArea(s.id,{logo:{...s.logo,position:j}})},h=j=>{if(!s.logo)return;const L=parseFloat(j.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const z=s.logo.height/s.logo.width;w.updateArea(s.id,{logo:{...s.logo,width:L,height:Math.round(L*z*10)/10}})}else w.updateArea(s.id,{logo:{...s.logo,width:L}})},$=j=>{if(!s.logo)return;const L=parseFloat(j.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const z=s.logo.width/s.logo.height;w.updateArea(s.id,{logo:{...s.logo,height:L,width:Math.round(L*z*10)/10}})}else w.updateArea(s.id,{logo:{...s.logo,height:L}})},R=()=>{s.logo&&w.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},H=j=>{s.logo&&w.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(j.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:i("config:areas.editArea")}),e.jsx("button",{className:"area-editor-close",onClick:n,children:"×"})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:d,onChange:E,placeholder:i("config:areas.areaName")})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("config:areas.color")}),e.jsx("div",{className:"color-picker-row",children:$s.map(j=>e.jsx("button",{type:"button",className:`color-swatch ${s.color===j?"selected":""}`,style:{backgroundColor:j},onClick:()=>x(j),"aria-label":`Set area color ${j}`,"aria-pressed":s.color===j,title:j},j))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:i("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:F,title:i("config:areas.bringToFront"),children:[e.jsx(I,{name:"arrow-up",size:12})," ",i("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:Q,title:i("config:areas.sendToBack"),children:[e.jsx(I,{name:"arrow-down",size:12})," ",i("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:i("config:areas.logo")}),e.jsxs("div",{className:"area-logo-section",children:[(ne=s.logo)!=null&&ne.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:Et(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:U,children:i("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var j;return(j=b.current)==null?void 0:j.click()},disabled:m,children:m?"...":e.jsx(I,{name:"refresh",size:12})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:i("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:Ft.map(({key:j,labelKey:L})=>{var z;return e.jsx("button",{className:`area-logo-pos-btn ${((z=s.logo)==null?void 0:z.position)===j?"active":""}`,onClick:()=>V(j),children:i(`config:areas.${L}`)},j)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:i("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:i("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:h,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:i("config:areas.logoHeight")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.height,onChange:$,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-aspect-label",title:i("config:areas.keepAspectRatio"),children:[e.jsx("input",{type:"checkbox",checked:s.logo.keepAspectRatio,onChange:R}),i("config:areas.keepAspectRatio")]})]})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:i("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:H,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 j;return(j=b.current)==null?void 0:j.click()},disabled:m,children:m?"...":i("config:areas.uploadLogo")}),e.jsx("input",{ref:b,type:"file",accept:"image/*",style:{display:"none"},onChange:J})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:i("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(j=>e.jsxs("div",{className:"area-folder-item",title:j,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>t==null?void 0:t(s.id),title:i("config:areas.openFolder"),children:e.jsx(I,{name:"folder",size:14})}),e.jsx("span",{className:"area-folder-path",children:j.split("/").pop()||j}),e.jsx("button",{className:"area-folder-remove",onClick:L=>M(j,L),title:i("config:areas.removeFolder"),children:"×"})]},j)),o?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(Os,{value:N,onChange:k,onSubmit:S,placeholder:i("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:S,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>u(!0),children:i("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:i("config:areas.prompt","Prompt")}),e.jsx("textarea",{className:"area-editor-input",value:r,onChange:p,placeholder:i("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:i("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:i("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:i("config:areas.rightClickUnassign")})]})]})}function Bt(){const{t:s}=X(["config","common"]),n=Ls(),[t,i]=l.useState(!1),[d,c]=l.useState(null),[r,g]=l.useState({name:"",key:"",value:"",description:""}),[o,u]=l.useState(null),N=()=>{i(!0),c(null),g({name:"",key:"",value:"",description:""})},k=p=>{c(p.id),i(!1),g({name:p.name,key:p.key,value:p.value,description:p.description||""})},m=()=>{i(!1),c(null),g({name:"",key:"",value:"",description:""})},P=()=>{!r.name.trim()||!r.key.trim()||(d?w.updateSecret(d,{name:r.name.trim(),key:r.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:r.value,description:r.description.trim()||void 0}):w.createSecret({name:r.name.trim(),key:r.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:r.value,description:r.description.trim()||void 0}),m())},b=p=>{u(p)},E=()=>{o&&(w.deleteSecret(o),d===o&&m())},x=p=>{navigator.clipboard.writeText(`{{${p}}}`)};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:n.length===0&&!t?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):n.map(p=>e.jsxs("div",{className:`secret-item ${d===p.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:p.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>x(p.key),title:s("config:secrets.copyPlaceholder"),children:`{{${p.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>k(p),title:s("common:buttons.edit"),children:e.jsx(I,{name:"edit",size:12})}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>b(p.id),title:s("common:buttons.delete"),children:"×"})]})]}),p.description&&e.jsx("div",{className:"secret-item-description",children:p.description})]},p.id))}),(t||d)&&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:r.name,onChange:p=>g({...r,name:p.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:r.key,onChange:p=>g({...r,key:p.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${r.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:r.value,onChange:p=>g({...r,value:p.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:r.description,onChange:p=>g({...r,description:p.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:m,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:P,disabled:!r.name.trim()||!r.key.trim(),children:s(d?"config:secrets.update":"common:buttons.add")})]})]}),!t&&!d&&e.jsx("button",{className:"secrets-add-btn",onClick:N,children:s("config:secrets.addSecret")}),e.jsx(xe,{isOpen:o!==null,title:s("common:buttons.delete"),message:s("config:secrets.deleteConfirm"),confirmLabel:s("common:buttons.delete"),cancelLabel:s("common:buttons.cancel"),variant:"danger",onConfirm:E,onClose:()=>u(null)})]})}async function Mt(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch system prompt: ${n.statusText}`);return(await n.json()).prompt||""}async function Ut(s){const n=Z(),t=await fetch(`${Y()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({prompt:s})});if(!t.ok)throw new Error(`Failed to update system prompt: ${t.statusText}`)}async function zt(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to clear system prompt: ${n.statusText}`)}async function Vt(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch echo prompt setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function Kt(s){const n=Z(),t=await fetch(`${Y()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update echo prompt setting: ${t.statusText}`)}async function Ht(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch codex binary path: ${n.statusText}`);return(await n.json()).path||""}async function qt(s){const n=Z(),t=await fetch(`${Y()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({path:s})});if(!t.ok)throw new Error(`Failed to update codex binary path: ${t.statusText}`)}async function Wt(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/tmux-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch tmux mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function Gt(s){const n=Z(),t=await fetch(`${Y()}/api/agents/system-settings/tmux-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update tmux mode setting: ${t.statusText}`)}async function Yt(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/interactive-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch interactive mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function Jt(s){const n=Z(),t=await fetch(`${Y()}/api/agents/system-settings/interactive-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update interactive mode setting: ${t.statusText}`)}async function Xt(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/codex-app-server-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch codex app-server mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function Zt(s){const n=Z(),t=await fetch(`${Y()}/api/agents/system-settings/codex-app-server-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update codex app-server mode setting: ${t.statusText}`)}async function Qt(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/opencode-server-mode`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch opencode server mode setting: ${n.statusText}`);return(await n.json()).enabled||!1}async function ea(s){const n=Z(),t=await fetch(`${Y()}/api/agents/system-settings/opencode-server-mode`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok)throw new Error(`Failed to update opencode server mode setting: ${t.statusText}`)}async function sa(){const s=Z(),n=await fetch(`${Y()}/api/agents/system-settings/backup`,{headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error(`Failed to fetch backup status: ${n.statusText}`);return n.json()}async function ta(s){const n=Z(),t=await fetch(`${Y()}/api/agents/system-settings/backup`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({enabled:s})});if(!t.ok){const i=await t.json().catch(()=>({}));throw new Error(i.error||`Failed to update backup setting: ${t.statusText}`)}return t.json()}function aa({checked:s,onChange:n,disabled:t}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,disabled:t,onChange:i=>n(i.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function na(){const{t:s}=X(["config","common"]),[n,t]=l.useState([]),[i,d]=l.useState(new Set),[c,r]=l.useState(new Set),[g,o]=l.useState(!1),[u,N]=l.useState(!1),[k,m]=l.useState(null),[P,b]=l.useState(null),[E,x]=l.useState(null),[p,S]=l.useState(null),[M,F]=l.useState(!1),[Q,W]=l.useState(null);l.useEffect(()=>{Ne(ye("/api/config/categories")).then(v=>v.json()).then(v=>{const O=Array.isArray(v)?v:[];t(O),d(new Set(O.map(D=>D.id)))}).catch(v=>console.error("Failed to fetch config categories:",v))},[]),l.useEffect(()=>{sa().then(S).catch(v=>{console.error("Failed to fetch backup status:",v),W(v.message||"Failed to fetch backup status")})},[]);const J=async v=>{if(!M){F(!0),W(null);try{const O=await ta(v);S(O)}catch(O){W(O.message||"Failed to update backup setting")}finally{F(!1)}}},U=v=>{d(O=>{const D=new Set(O);return D.has(v)?D.delete(v):D.add(v),D})},V=v=>{r(O=>{const D=new Set(O);return D.has(v)?D.delete(v):D.add(v),D})},h=()=>d(new Set(n.map(v=>v.id))),$=()=>d(new Set),R=()=>{P&&r(new Set(P.categories.map(v=>v.id)))},H=()=>r(new Set),ne=async()=>{var v;if(i.size!==0){o(!0),x(null);try{const O=Array.from(i).join(","),D=await Ne(ye(`/api/config/export?categories=${O}`));if(!D.ok)throw new Error("Export failed");const se=await D.blob(),ae=window.URL.createObjectURL(se),T=document.createElement("a");T.href=ae;const y=D.headers.get("Content-Disposition"),te=((v=y==null?void 0:y.match(/filename="(.+)"/))==null?void 0:v[1])||"tide-commander-config.zip";T.download=te,document.body.appendChild(T),T.click(),document.body.removeChild(T),window.URL.revokeObjectURL(ae),x({type:"success",text:s("config:data.exportSuccess")})}catch(O){x({type:"error",text:O.message||"Export failed"})}finally{o(!1)}}},j=async v=>{var D;const O=(D=v.target.files)==null?void 0:D[0];if(O){m(O),x(null),b(null),r(new Set);try{const se=await Ne(ye("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await O.arrayBuffer()});if(!se.ok){const y=await se.json();throw new Error(y.error||"Failed to preview config file")}const ae=await se.json(),T=Array.isArray(ae.categories)?ae.categories:[];b({...ae,categories:T}),r(new Set(T.map(y=>y.id)))}catch(se){x({type:"error",text:se.message||"Failed to read config file"}),m(null)}}},L=async()=>{if(!(!k||c.size===0)){N(!0),x(null);try{const v=Array.from(c).join(","),O=await Ne(ye(`/api/config/import?categories=${v}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await k.arrayBuffer()}),D=await O.json();if(!O.ok)throw new Error(D.error||"Import failed");x({type:"success",text:D.message||s("config:data.importSuccess")}),m(null),b(null),r(new Set)}catch(v){x({type:"error",text:v.message||"Import failed"})}finally{N(!1)}}},z=()=>{m(null),b(null),r(new Set),x(null)};return e.jsxs("div",{className:"data-section",children:[E&&e.jsx("div",{className:`data-message data-message-${E.type}`,children:E.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(aa,{checked:!!(p!=null&&p.enabled),disabled:M||!p,onChange:J})]}),e.jsxs("div",{className:"data-backup-info",children:[p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:["Saves a compressed snapshot of your data every hour to"," ",e.jsx("code",{children:p.backupDir}),". Identical snapshots are skipped. Keeps the 8 newest plus one from each of the 2 most recent prior days."]}),!p.scriptExists&&e.jsxs("div",{style:{marginTop:6,color:"var(--dracula-red, #ff5555)"},children:["Backup script not found at ",e.jsx("code",{children:p.scriptPath})]}),p.lastRunAt&&e.jsxs("div",{style:{marginTop:6},children:["Last run: ",new Date(p.lastRunAt).toLocaleString(),p.lastRunOk===!0&&" — ok",p.lastRunOk===!1&&p.lastRunError&&e.jsxs("span",{style:{color:"var(--dracula-red, #ff5555)"},children:[" — ",p.lastRunError]})]})]}):e.jsx("div",{children:"Loading backup status…"}),Q&&e.jsx("div",{className:"data-message data-message-error",style:{marginTop:6},children:Q})]})]}),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:h,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:$,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:n.map(v=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:i.has(v.id),onChange:()=>U(v.id)}),e.jsx("span",{className:"data-category-name",children:v.name})]},v.id))}),e.jsx("button",{className:"data-action-btn export",onClick:ne,disabled:g||i.size===0,children:g?s("config:data.exporting"):s("config:data.exportCount",{count:i.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")})}),k?P?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:k.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:R,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:H,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:P.categories.map(v=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:c.has(v.id),onChange:()=>V(v.id)}),e.jsx("span",{className:"data-category-name",children:v.name}),v.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",v.fileCount," ",s("config:data.files"),")"]})]},v.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:z,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:L,disabled:u||c.size===0,children:u?s("config:data.importing"):s("config:data.importCount",{count:c.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:j,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}function oa(){const[s,n]=l.useState(()=>Ds()),t=i=>{n(i);const d=Ms(i);Us(d)};return e.jsx("div",{className:"theme-selector",children:e.jsx("div",{className:"theme-selector-grid",children:Fs.map(i=>e.jsxs("button",{className:`theme-option ${s===i.id?"active":""}`,onClick:()=>t(i.id),title:i.description,children:[e.jsx("div",{className:"theme-preview",children:e.jsxs("div",{className:"theme-preview-bg",style:{backgroundColor:i.colors.bgPrimary},children:[e.jsx("div",{className:"theme-preview-accent",style:{backgroundColor:i.colors.accentBlue}}),e.jsx("div",{className:"theme-preview-claude",style:{backgroundColor:i.colors.accentClaude}})]})}),e.jsx("span",{className:"theme-name",children:i.name})]},i.id))})})}function ia(){const{t:s}=X(["config"]),{installInfo:n,phase:t,output:i,error:d,newVersion:c,autoRestart:r,refreshInstallInfo:g,runUpdate:o,reset:u}=zs(),[N,k]=l.useState(!1),m=l.useRef(null);l.useEffect(()=>{g()},[g]),l.useEffect(()=>{m.current&&(m.current.scrollTop=m.current.scrollHeight)},[i]);const P=l.useCallback(()=>{k(!0)},[]),b=l.useCallback(()=>{k(!1)},[]),E=l.useCallback(()=>{k(!1),o()},[o]),x=l.useCallback(()=>{u(),k(!1),g()},[u,g]),p=fs.isNativePlatform(),S=s(p?"config:about.autoUpdateServerTitle":"config:about.autoUpdateTitle");return n?n.isGlobalInstall?n.autoUpdateSupported?!n.updateAvailable&&t==="idle"?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:S}),t==="idle"&&!N&&n.updateAvailable&&e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsxs("span",{className:"about-autoupdate-versions",children:[e.jsx("span",{className:"about-autoupdate-current",children:n.currentVersion}),e.jsx("span",{className:"about-autoupdate-arrow",children:"→"}),e.jsx("span",{className:"about-autoupdate-latest",children:n.latestVersion})]}),e.jsx("button",{className:"about-update-btn download",onClick:P,children:s("config:about.autoUpdateButton")})]}),t==="idle"&&N&&e.jsxs("div",{className:"about-autoupdate-confirm",children:[e.jsx("div",{className:"about-autoupdate-confirm-title",children:s("config:about.autoUpdateConfirmTitle")}),e.jsx("div",{className:"about-autoupdate-confirm-body",children:s("config:about.autoUpdateConfirmBody")}),e.jsxs("div",{className:"about-autoupdate-confirm-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:b,children:s("config:about.autoUpdateCancel")}),e.jsx("button",{className:"about-update-btn download",onClick:E,children:s("config:about.autoUpdateConfirm")})]})]}),(t==="running"||t==="success"||t==="failed")&&e.jsxs("div",{className:"about-autoupdate-stream",children:[e.jsxs("div",{className:"about-autoupdate-stream-title",children:[t==="running"&&s("config:about.autoUpdateRunning"),t==="success"&&s("config:about.autoUpdateSuccess"),t==="failed"&&s("config:about.autoUpdateFailed")]}),e.jsx("pre",{ref:m,className:"about-autoupdate-output",children:i||"..."}),t==="success"&&e.jsxs("div",{className:"about-autoupdate-success-hint",children:[c&&e.jsxs("div",{className:"about-autoupdate-newversion",children:["v",c]}),e.jsx("div",{children:s(r?"config:about.autoUpdateReconnectHint":"config:about.autoUpdateRestartHint")})]}),t==="failed"&&d&&e.jsx("div",{className:"about-update-error",children:d}),(t==="success"||t==="failed")&&e.jsx("div",{className:"about-autoupdate-stream-actions",children:e.jsx("button",{className:"about-update-btn changelog",onClick:x,children:s("config:about.autoUpdateClose")})})]})]}):p?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:S}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdatePackageManagerNotice",{pm:n.packageManager})}),n.suggestedManualCommand&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"about-autoupdate-manualhint",children:s("config:about.autoUpdateManualCommand")}),e.jsx("pre",{className:"about-autoupdate-manualcmd",children:n.suggestedManualCommand})]})]}):p?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:S}),e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.autoUpdateDevMode")})]}):null}function la(){const{t:s}=X(["config"]),[n,t]=l.useState(null),[i,d]=l.useState(!1),[c,r]=l.useState(null);l.useEffect(()=>{Vs().then(t).catch(N=>r(N.message))},[]);const g=l.useCallback(async N=>{if(!i){d(!0),r(null);try{t(await Ks(N))}catch(k){r(k.message)}finally{d(!1)}}},[i]),o=fs.isNativePlatform(),u=s(o?"config:about.unattendedServerTitle":"config:about.unattendedTitle");return!n&&!c?null:n?o&&!n.supported?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:u}),e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsx("span",{className:"about-autoupdate-devnote",children:s("config:about.unattendedDesc")}),e.jsxs("label",{className:"config-toggle",style:n.supported?void 0:{opacity:.5},children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:n.enabled,disabled:i||!n.supported,onChange:N=>void g(N.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})]}),!n.supported&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.unattendedUnsupported")}),n.supported&&n.enabled&&n.pendingRestartVersion&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:about.unattendedPendingRestart",{version:n.pendingRestartVersion})}),n.supported&&n.enabled&&!n.pendingRestartVersion&&n.lastResult&&e.jsx("div",{className:"about-autoupdate-devnote",children:n.lastResult}),c&&e.jsx("div",{className:"about-update-error",children:c})]}):o?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:u}),e.jsx("div",{className:"about-update-error",children:c})]})}function ca(){var M;const{t:s}=X(["config"]),{isAndroid:n,supported:t,otaActive:i,bundleState:d,serverInfo:c,infoError:r,updateAvailable:g,phase:o,progress:u,error:N,autoSync:k,checkNow:m,syncNow:P,resetToBundled:b,setAutoSync:E}=Hs(),[x,p]=l.useState(null),S=l.useRef(m);return S.current=m,l.useEffect(()=>{n&&(S.current(!1),qs.getInfo().then(F=>p(F.version)).catch(()=>{}))},[n]),!n||t===!1?null:e.jsxs("div",{className:"about-autoupdate",children:[e.jsx("div",{className:"about-autoupdate-title",children:s("config:webBundle.title")}),e.jsxs("div",{className:"about-autoupdate-devnote",children:[i?s("config:webBundle.sourceOta",{hash:((M=d==null?void 0:d.hash)==null?void 0:M.slice(0,8))??"?"}):s("config:webBundle.sourceBundled"),x&&` · ${s("config:webBundle.apkVersion",{version:x})}`]}),c?e.jsxs("div",{className:"about-autoupdate-devnote",children:[s("config:webBundle.serverBundle",{version:c.version,hash:c.hash.slice(0,8)})," — ",s(g?"config:webBundle.updateAvailable":"config:webBundle.upToDate")]}):r&&e.jsx("div",{className:"about-autoupdate-devnote",children:s("config:webBundle.serverUnavailable")}),N&&e.jsx("div",{className:"about-update-error",children:N}),e.jsxs("div",{className:"about-autoupdate-row",children:[e.jsx("span",{className:"about-autoupdate-devnote",children:s("config:webBundle.autoSync")}),e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:k,onChange:F=>E(F.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})]}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn download",onClick:()=>void P(),disabled:o!=="idle"||!c,children:o==="syncing"?s("config:webBundle.syncingPct",{percent:u??0}):s("config:webBundle.syncNow")}),i&&e.jsx("button",{className:"about-update-btn changelog",onClick:()=>void b(),children:s("config:webBundle.reset")})]})]})}function ra(){const{t:s}=X(["config"]),{updateAvailable:n,updateInfo:t,recentReleases:i,isChecking:d,error:c,currentVersion:r,isAndroid:g,downloadPhase:o,downloadProgress:u,checkForUpdate:N,downloadAndInstall:k,openReleasePage:m}=Rs(),[P,b]=l.useState(!1),E=p=>p?`${(p/(1024*1024)).toFixed(1)} MB`:"",x=p=>new Date(p).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"});return e.jsxs("div",{className:"about-section",children:[e.jsxs("div",{className:"about-logo",children:[e.jsx("span",{className:"about-logo-icon",children:e.jsx(I,{name:"waves",size:24})}),e.jsx("span",{className:"about-logo-text",children:"Tide Commander"})]}),e.jsxs("div",{className:"about-version",children:[e.jsx("span",{className:"about-version-label",children:s("config:about.version")}),e.jsxs("div",{className:"about-version-info",children:[e.jsx("span",{className:"about-version-value",children:r}),n&&t?e.jsx("span",{className:"about-version-update-badge",onClick:m,title:`Update available: ${t.version}`,children:t.version}):e.jsxs("a",{href:"https://github.com/deivid11/tide-commander/releases",target:"_blank",rel:"noopener noreferrer",className:"about-version-status",children:["(",s("config:about.updated"),")"]})]})]}),e.jsx(ia,{}),e.jsx(la,{}),e.jsx(ca,{}),e.jsx("div",{className:"about-changelog-row",children:e.jsx("button",{className:"about-update-btn changelog",onClick:()=>b(!0),children:s("config:about.changelog")})}),e.jsxs("div",{className:"about-update",children:[n&&t?e.jsxs("div",{className:"about-update-available",children:[e.jsxs("div",{className:"about-update-header",children:[e.jsx("span",{className:"about-update-badge",children:s("config:about.updateAvailable")}),e.jsx("span",{className:"about-update-version",children:t.version})]}),t.apkSize&&e.jsxs("div",{className:"about-update-size",children:[s("config:about.sizeLabel"),": ",E(t.apkSize)]}),c&&e.jsx("div",{className:"about-update-error",children:c}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:m,children:s("config:about.changelog")}),g&&t.apkUrl?e.jsx("button",{className:"about-update-btn download",onClick:()=>void k(),disabled:o!=="idle",children:o==="downloading"?s("config:appUpdateBanner.downloadingPct",{percent:u??0}):s(o==="installing"?"config:appUpdateBanner.installHint":"config:about.downloadAPK")}):e.jsx("button",{className:"about-update-btn download",onClick:m,children:s("config:about.viewRelease")})]})]}):e.jsxs("div",{className:"about-update-check",children:[e.jsx("span",{className:"about-update-status",children:s(d?"config:about.checkingUpdates":"config:about.upToDate")}),e.jsx("button",{className:"about-update-btn check",onClick:()=>N(!0),disabled:d,children:d?"...":s("config:about.check")})]}),i.length>0&&e.jsxs("div",{className:"about-releases",children:[e.jsx("div",{className:"about-releases-title",children:s("config:about.recentReleases")}),e.jsx("div",{className:"about-releases-list",children:i.map(p=>e.jsxs("a",{href:p.releaseUrl,target:"_blank",rel:"noopener noreferrer",className:`about-release-item ${p.version===`v${r}`||p.version===r?"current":""}`,children:[e.jsx("span",{className:"about-release-version",children:p.version}),e.jsx("span",{className:"about-release-date",children:x(p.publishedAt)})]},p.version))})]})]}),e.jsx("div",{className:"about-description",children:s("config:about.tagline")}),e.jsxs("div",{className:"about-principles",children:[e.jsx("div",{className:"about-principles-title",children:s("config:about.corePrinciples")}),e.jsxs("ul",{className:"about-principles-list",children:[e.jsx("li",{children:s("config:about.principle1")}),e.jsx("li",{children:s("config:about.principle2")}),e.jsx("li",{children:s("config:about.principle3")}),e.jsx("li",{children:s("config:about.principle4")})]})]}),e.jsx("div",{className:"about-links",children:e.jsxs("a",{href:"https://github.com/deivid11/tide-commander",target:"_blank",rel:"noopener noreferrer",className:"about-link",children:[e.jsx("span",{className:"about-link-icon",children:e.jsx(I,{name:"package",size:14})}),e.jsx("span",{children:s("config:about.repository")})]})}),e.jsxs("div",{className:"about-credits",children:[e.jsx("div",{className:"about-credits-title",children:s("config:about.specialThanks")}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://kenney.nl",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Kenney.nl"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.kenneyCredit")})]}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://claude.ai/code",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Claude Code"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.claudeCodeCredit")})]})]}),P&&e.jsx(Bs,{onClose:()=>b(!1)})]})}const da={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄",whatsapp:"📱"};function ua({onOpenModal:s}){const[n,t]=l.useState([]),[i,d]=l.useState(!0),c=l.useCallback(async()=>{try{const r=await Ne(ye("/api/integrations"));if(!r.ok)return;const g=await r.json();t(g)}catch{}finally{d(!1)}},[]);return l.useEffect(()=>{c()},[c]),i?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"Loading..."}):n.length===0?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"No integrations available."}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[n.map(r=>{const g=da[r.id]||"🔌",o=!!r.status.error,u=r.status.connected,N=o?"#f38ba8":u?"#a6e3a1":"#fab387",k=o?"Error":u?"Connected":"Setup Required",m=o?"✗":u?"✓":"⚠";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"3px 8px",borderRadius:4,background:"var(--surface-1, #181825)",border:"1px solid var(--border, #313244)",fontSize:12,minHeight:26},children:[e.jsx("span",{style:{fontSize:13,flexShrink:0},children:g}),e.jsx("span",{style:{flex:1,minWidth:0,color:"var(--text-primary, #cdd6f4)",fontWeight:500,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:r.name}),e.jsx("span",{style:{color:N,fontSize:10,fontWeight:500,whiteSpace:"nowrap"},title:k,children:m}),e.jsx("button",{onClick:()=>s(r.id),title:`Configure ${r.name}`,style:{background:"none",border:"none",cursor:"pointer",padding:"1px 3px",fontSize:12,color:"var(--text-secondary, #a6adc8)",borderRadius:3,flexShrink:0,lineHeight:1},onMouseEnter:P=>{P.target.style.color="var(--text-primary, #cdd6f4)"},onMouseLeave:P=>{P.target.style.color="var(--text-secondary, #a6adc8)"},children:"⚙️"})]},r.id)}),e.jsx("button",{onClick:()=>s(),style:{background:"none",border:"1px dashed var(--border, #313244)",borderRadius:4,padding:"3px 8px",cursor:"pointer",color:"var(--text-secondary, #a6adc8)",fontSize:11,textAlign:"center",marginTop:2},onMouseEnter:r=>{r.target.style.borderColor="var(--accent, #89b4fa)",r.target.style.color="var(--accent, #89b4fa)"},onMouseLeave:r=>{r.target.style.borderColor="var(--border, #313244)",r.target.style.color="var(--text-secondary, #a6adc8)"},children:"Manage All Integrations"})]})}const Re="__global__";function pa({isOpen:s,onClose:n,initialAgentId:t}){const{t:i}=X(["config"]),d=Ws(),[c,r]=l.useState(""),[g,o]=l.useState(""),[u,N]=l.useState(!1),[k,m]=l.useState(""),[P,b]=l.useState(""),[E,x]=l.useState(null),[p,S]=l.useState(null),[M,F]=l.useState(!1),[Q,W]=l.useState(!1),[J,U]=l.useState(!1),[V,h]=l.useState(null),$=l.useMemo(()=>[...d].sort((T,y)=>T.name.localeCompare(y.name)),[d]),R=l.useMemo(()=>d.find(T=>T.id===c),[d,c]),H=c===Re;l.useEffect(()=>{if(!s)return;const T=t&&d.some(y=>y.id===t)?t:Re;r(T),N(!1),Mt().then(y=>o(y)).catch(()=>o("")).finally(()=>N(!0))},[s]),l.useEffect(()=>{const T=c===Re?g:(R==null?void 0:R.customPrompt)??"";m(T),b(T),F(!1),x(null),S(null)},[c,u]);const ne=T=>{const y=T.target.value;m(y),F(y!==P),x(null),S(null)},j=async()=>{if(c)try{x(null),S(null),H?(await Ut(k),o(k),S(i("config:systemPrompt.savedGlobal"))):(w.updateAgentProperties(c,{customPrompt:k}),S(i("config:systemPrompt.saved"))),b(k),F(!1)}catch(T){x(T instanceof Error?T.message:"Failed to save system prompt")}},L=()=>{W(!0)},z=async()=>{if(c)try{x(null),S(null),H?(await zt(),o(""),S(i("config:systemPrompt.clearedGlobal"))):(w.updateAgentProperties(c,{customPrompt:""}),S(i("config:systemPrompt.cleared"))),m(""),b(""),F(!1)}catch(T){x(T instanceof Error?T.message:"Failed to clear system prompt")}},v=()=>{m(P),F(!1),x(null),S(null)},O=T=>{if(T!==c){if(M){h(T),U(!0);return}r(T)}},D=()=>{if(M){h(null),U(!0);return}n()},se=()=>{if(U(!1),V){const T=V;h(null),r(T)}else n()},ae=T=>{T.key==="Escape"&&(T.preventDefault(),D())};return s?e.jsxs($e,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:D,children:e.jsxs("div",{className:"system-prompt-modal",onClick:T=>T.stopPropagation(),onKeyDown:ae,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:i("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:D,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"modal-description",children:i("config:systemPrompt.description")}),e.jsxs("div",{className:"agent-picker",children:[e.jsx("label",{htmlFor:"system-prompt-agent",className:"editor-label",children:i("config:systemPrompt.agentLabel")}),e.jsxs("div",{className:"agent-picker-row",children:[H?e.jsx(I,{name:"globe",size:20,className:"agent-picker-icon"}):R&&e.jsx(Gs,{classId:R.class,size:20,className:"agent-picker-icon"}),e.jsxs("select",{id:"system-prompt-agent",className:"agent-picker-select",value:c,onChange:T=>O(T.target.value),children:[e.jsxs("option",{value:Re,children:[i("config:systemPrompt.globalOption"),g?" • ✦":""]}),$.map(T=>e.jsxs("option",{value:T.id,children:[T.name,T.customPrompt?" • ✦":""]},T.id))]})]})]}),E&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),E]}),p&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),p]}),e.jsxs("div",{className:"editor-wrapper",children:[e.jsxs("div",{className:"editor-header",children:[e.jsx("label",{htmlFor:"prompt-input",className:"editor-label",children:i("config:systemPrompt.editPrompt")}),e.jsxs("span",{className:"char-count",children:[k.length," ",i("config:systemPrompt.characters")]})]}),e.jsx("textarea",{id:"prompt-input",className:"prompt-editor",value:k,onChange:ne,placeholder:i("config:systemPrompt.placeholder"),rows:18,disabled:H&&!u,autoFocus:!0}),e.jsx("div",{className:"editor-hint",children:i(H?"config:systemPrompt.hintGlobal":"config:systemPrompt.hint")})]})]}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:L,disabled:!k||!c,children:i("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:D,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:v,disabled:!M,children:i("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:j,disabled:!M||!c,children:i("config:systemPrompt.save")})]})]})]})}),e.jsx(xe,{isOpen:Q,title:i("config:systemPrompt.clear"),message:i(H?"config:systemPrompt.confirmClearGlobal":"config:systemPrompt.confirmClear"),confirmLabel:i("config:systemPrompt.clear"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{z()},onClose:()=>W(!1)}),e.jsx(xe,{isOpen:J,title:"Unsaved Changes",message:"You have unsaved changes for this agent. Discard them?",confirmLabel:"Discard",cancelLabel:"Keep editing",variant:"danger",onConfirm:se,onClose:()=>{U(!1),h(null)}})]}):null}const rs={enabled:!1,baseUrl:"",defaultSessionId:"",webhookVerifyToken:"",showIncomingToasts:!0},ha=2500,ma=12e4;function ds(s){return{enabled:s.enabled??!1,baseUrl:s.baseUrl??"",defaultSessionId:s.defaultSessionId??"",webhookVerifyToken:s.webhookVerifyToken??"",showIncomingToasts:s.showIncomingToasts??!0}}function ga(s,n){return s.enabled===n.enabled&&s.baseUrl===n.baseUrl&&s.defaultSessionId===n.defaultSessionId&&s.webhookVerifyToken===n.webhookVerifyToken&&s.showIncomingToasts===n.showIncomingToasts}function fa({isOpen:s,onClose:n}){const{t}=X(["config"]),[i,d]=l.useState(rs),[c,r]=l.useState(rs),[g,o]=l.useState(!1),[u,N]=l.useState([]),[k,m]=l.useState(!0),[P,b]=l.useState(null),[E,x]=l.useState(null),[p,S]=l.useState(""),[M,F]=l.useState(!1),[Q,W]=l.useState(""),[J,U]=l.useState(null),[V,h]=l.useState(null),[$,R]=l.useState(null),H=l.useRef(null),ne=l.useRef(0),[j,L]=l.useState(""),[z,v]=l.useState(""),[O,D]=l.useState(null),[se,ae]=l.useState(!1),[T,y]=l.useState(!1),[te,oe]=l.useState(!1),[de,ie]=l.useState(!1),[he,ke]=l.useState(null),Ae=!ga(i,c),ue=l.useCallback(()=>{H.current&&(clearTimeout(H.current),H.current=null)},[]),Te=l.useCallback(async()=>{try{m(!0),b(null),x(null);const[f,K]=await Promise.all([xs(),Ys()]),ce=ds(f);if(d(ce),r(ce),o(!!K.configured),K.configured)try{const je=await Xe();N(Array.isArray(je)?je:[])}catch{N([])}else N([])}catch(f){b(f instanceof Error?f.message:t("config:whatsapp.errors.loadFailed"))}finally{m(!1)}},[t]),me=l.useCallback(async()=>{try{const f=await Xe();N(Array.isArray(f)?f:[])}catch{}},[]);l.useEffect(()=>(s?Te():(ue(),U(null),h(null),R(null),S(""),F(!1),D(null)),()=>{ue()}),[s,Te,ue]);const ge=(f,K)=>{d(ce=>({...ce,[f]:K})),b(null),x(null)},Oe=async()=>{try{b(null),x(null);const f=await et({enabled:i.enabled,baseUrl:i.baseUrl.trim(),defaultSessionId:i.defaultSessionId.trim(),webhookVerifyToken:i.webhookVerifyToken,showIncomingToasts:i.showIncomingToasts});window.dispatchEvent(new CustomEvent("tide:whatsapp-config-updated"));const K=ds(f);d(K),r(K),x(t("config:whatsapp.saved"))}catch(f){b(f instanceof Error?f.message:t("config:whatsapp.errors.saveFailed"))}},Me=()=>{d(c),b(null),x(null)},Se=()=>{if(Ae){y(!0);return}n()},Le=f=>{f.key==="Escape"&&(f.preventDefault(),Se())},Ue=async()=>{const f=p.trim();if(f)try{b(null),x(null),await Xs(f),S(""),F(!1),o(!0),x(t("config:whatsapp.apiKeySaved"))}catch(K){b(K instanceof Error?K.message:t("config:whatsapp.errors.apiKeySaveFailed"))}},ze=()=>{oe(!0)},Ve=async()=>{try{b(null),x(null),await st(),o(!1),x(t("config:whatsapp.apiKeyCleared"))}catch(f){b(f instanceof Error?f.message:t("config:whatsapp.errors.apiKeyClearFailed"))}},be=l.useCallback(async f=>{if(Date.now()>ne.current){R(t("config:whatsapp.pairingTimeout")),U(null),h(null),ue(),me();return}try{const K=await Js(f);if(K.status&&["connected","paired","open","ready"].includes(K.status.toLowerCase())){R(t("config:whatsapp.pairingSuccess")),U(null),h(null),ue(),me();return}const je=K.qrUrl??K.qr??null;je&&h(je)}catch(K){R(K instanceof Error?K.message:t("config:whatsapp.errors.qrFetchFailed"))}H.current=setTimeout(()=>{be(f)},ha)},[me,ue,t]),_=async()=>{const f=Q.trim();if(f)try{b(null),x(null),R(null),h(null),ue(),await Zs(f),W(""),U(f),ne.current=Date.now()+ma,be(f),me()}catch(K){b(K instanceof Error?K.message:t("config:whatsapp.errors.sessionCreateFailed"))}},Ee=()=>{ue(),U(null),h(null),R(null)},pe=f=>{ke(f),ie(!0)},Ke=async()=>{if(he)try{b(null),x(null),await tt(he),J===he&&Ee(),me(),x(t("config:whatsapp.sessionDeleted"))}catch(f){b(f instanceof Error?f.message:t("config:whatsapp.errors.sessionDeleteFailed"))}finally{ke(null)}},De=async()=>{const f=j.trim(),K=z.trim();if(!(!f||!K))try{ae(!0),D(null);const ce=i.defaultSessionId.trim()||void 0;await Qs(f,K,ce),D({kind:"success",text:t("config:whatsapp.testSent")})}catch(ce){D({kind:"error",text:ce instanceof Error?ce.message:t("config:whatsapp.errors.testSendFailed")})}finally{ae(!1)}};return s?e.jsxs($e,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:Se,children:e.jsxs("div",{className:"whatsapp-config-modal",onClick:f=>f.stopPropagation(),onKeyDown:Le,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsapp.title")}),e.jsx("button",{className:"modal-close",onClick:Se,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:k?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsapp.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:t("config:whatsapp.description")}),P&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),P]}),E&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),E]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.general")}),e.jsxs("div",{className:"wa-field wa-field-row",children:[e.jsx("label",{htmlFor:"wa-enabled",className:"wa-label",children:t("config:whatsapp.enabled")}),e.jsxs("label",{className:"wa-toggle",children:[e.jsx("input",{id:"wa-enabled",type:"checkbox",checked:i.enabled,onChange:f=>ge("enabled",f.target.checked)}),e.jsx("span",{className:"wa-toggle-track",children:e.jsx("span",{className:"wa-toggle-thumb"})})]})]}),e.jsxs("div",{className:"wa-field wa-field-row",children:[e.jsx("label",{htmlFor:"wa-show-toasts",className:"wa-label",children:t("config:whatsapp.showIncomingToasts")}),e.jsxs("label",{className:"wa-toggle",children:[e.jsx("input",{id:"wa-show-toasts",type:"checkbox",checked:i.showIncomingToasts,onChange:f=>ge("showIncomingToasts",f.target.checked)}),e.jsx("span",{className:"wa-toggle-track",children:e.jsx("span",{className:"wa-toggle-thumb"})})]})]}),e.jsx("span",{className:"wa-hint",children:t("config:whatsapp.showIncomingToastsHelp")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-base-url",className:"wa-label",children:t("config:whatsapp.baseUrl")}),e.jsx("input",{id:"wa-base-url",type:"text",className:"wa-input",placeholder:"http://localhost:3007",value:i.baseUrl,onChange:f=>ge("baseUrl",f.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-default-session",className:"wa-label",children:t("config:whatsapp.defaultSessionId")}),e.jsx("input",{id:"wa-default-session",type:"text",className:"wa-input",placeholder:t("config:whatsapp.defaultSessionIdPlaceholder"),value:i.defaultSessionId,onChange:f=>ge("defaultSessionId",f.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-webhook-token",className:"wa-label",children:t("config:whatsapp.webhookVerifyToken")}),e.jsx("input",{id:"wa-webhook-token",type:"text",className:"wa-input",placeholder:t("config:whatsapp.webhookVerifyTokenPlaceholder"),value:i.webhookVerifyToken,onChange:f=>ge("webhookVerifyToken",f.target.value)})]})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.apiKey")}),e.jsx("div",{className:"wa-key-status",children:g?e.jsxs("span",{className:"wa-status wa-status-ok",children:[e.jsx(I,{name:"check",size:12})," ",t("config:whatsapp.configured")]}):e.jsxs("span",{className:"wa-status wa-status-warn",children:[e.jsx(I,{name:"warn",size:12})," ",t("config:whatsapp.notConfigured")]})}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:M?"text":"password",className:"wa-input",placeholder:t("config:whatsapp.apiKeyPlaceholder"),value:p,onChange:f=>S(f.target.value)}),e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:()=>F(f=>!f),title:t(M?"config:whatsapp.hideKey":"config:whatsapp.showKey"),children:e.jsx(I,{name:M?"eye-closed":"eye",size:14})}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:Ue,disabled:!p.trim(),children:t("config:whatsapp.saveKey")}),e.jsx("button",{type:"button",className:"btn btn-danger",onClick:ze,disabled:!g,children:t("config:whatsapp.clearKey")})]}),e.jsx("span",{className:"wa-hint",children:t("config:whatsapp.apiKeyHint")})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.sessions")}),e.jsx("div",{className:"wa-sessions-list",children:!Array.isArray(u)||u.length===0?e.jsx("div",{className:"wa-empty",children:t("config:whatsapp.noSessions")}):u.map(f=>e.jsxs("div",{className:"wa-session-row",children:[e.jsxs("div",{className:"wa-session-info",children:[e.jsx("span",{className:"wa-session-id",children:f.id}),e.jsx("span",{className:`wa-session-status status-${(f.status??"unknown").toLowerCase()}`,children:f.status||"—"}),f.pairedNumber&&e.jsx("span",{className:"wa-session-paired",children:f.pairedNumber})]}),e.jsx("button",{type:"button",className:"btn btn-danger btn-sm",onClick:()=>pe(f.id),children:t("config:whatsapp.deleteSession")})]},f.id))}),e.jsxs("div",{className:"wa-field wa-field-inline",children:[e.jsx("input",{type:"text",className:"wa-input",placeholder:t("config:whatsapp.addSessionPlaceholder"),value:Q,onChange:f=>W(f.target.value),onKeyDown:f=>{f.key==="Enter"&&_()}}),e.jsx("button",{type:"button",className:"btn btn-primary",onClick:_,disabled:!Q.trim()||J!==null,children:t("config:whatsapp.addSession")})]}),J&&e.jsxs("div",{className:"wa-qr-panel",children:[e.jsxs("div",{className:"wa-qr-header",children:[e.jsx("span",{children:t("config:whatsapp.qrPrompt",{id:J})}),e.jsx("button",{type:"button",className:"btn btn-secondary btn-sm",onClick:Ee,children:t("config:whatsapp.cancelPairing")})]}),V?e.jsx("div",{className:"wa-qr-image",children:e.jsx("img",{src:V,alt:"WhatsApp pairing QR code"})}):e.jsxs("div",{className:"wa-qr-loading",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsapp.waitingForQr")})]})]}),$&&!J&&e.jsx("div",{className:"wa-pairing-message",children:$})]}),e.jsxs("section",{className:"wa-section",children:[e.jsx("h3",{className:"wa-section-title",children:t("config:whatsapp.sections.testMessage")}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-to",className:"wa-label",children:t("config:whatsapp.testTo")}),e.jsx("input",{id:"wa-test-to",type:"text",className:"wa-input",placeholder:t("config:whatsapp.testToPlaceholder"),value:j,onChange:f=>L(f.target.value)})]}),e.jsxs("div",{className:"wa-field",children:[e.jsx("label",{htmlFor:"wa-test-message",className:"wa-label",children:t("config:whatsapp.testMessageBody")}),e.jsx("textarea",{id:"wa-test-message",className:"wa-textarea",rows:4,placeholder:t("config:whatsapp.testMessageBodyPlaceholder"),value:z,onChange:f=>v(f.target.value)})]}),e.jsx("div",{className:"wa-field-inline wa-field-end",children:e.jsx("button",{type:"button",className:"btn btn-primary",onClick:De,disabled:!j.trim()||!z.trim()||se,children:t(se?"config:whatsapp.sending":"config:whatsapp.sendTest")})}),O&&e.jsxs("div",{className:`alert ${O.kind==="success"?"alert-success":"alert-error"}`,children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:O.kind==="success"?"check":"warn",size:14})}),O.text]})]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left"}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:Se,children:t("config:whatsapp.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:Me,disabled:!Ae||k,children:t("config:whatsapp.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:Oe,disabled:!Ae||k,children:t("config:whatsapp.save")})]})]})]})}),e.jsx(xe,{isOpen:T,title:t("config:whatsapp.unsavedTitle"),message:t("config:whatsapp.unsavedMessage"),confirmLabel:t("config:whatsapp.closeAnyway"),cancelLabel:t("config:whatsapp.keepEditing"),variant:"danger",onConfirm:()=>{y(!1),n()},onClose:()=>y(!1)}),e.jsx(xe,{isOpen:te,title:t("config:whatsapp.clearKey"),message:t("config:whatsapp.confirmClearKey"),confirmLabel:t("config:whatsapp.clearKey"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Ve()},onClose:()=>oe(!1)}),e.jsx(xe,{isOpen:de,title:t("config:whatsapp.deleteSession"),message:t("config:whatsapp.confirmDeleteSession",{id:he??""}),confirmLabel:t("config:whatsapp.deleteSession"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{Ke()},onClose:()=>{ie(!1),ke(null)}})]}):null}const ws=["messages","statusChanges","taskComplete","errors","planReady","agentSpawned","agentStopped"];function Ze(s=!1){const n=Z(),t={};return n&&(t.Authorization=`Bearer ${n}`),s&&(t["Content-Type"]="application/json"),t}async function Qe(s,n){try{const t=await s.json();if(t&&typeof t.error=="string")return t.error;if(t&&typeof t.message=="string")return t.message}catch{}return`${n}: ${s.statusText}`}async function xa(){const s=await fetch(`${Y()}/api/whatsapp/notification-config`,{headers:Ze()});if(!s.ok)throw new Error(await Qe(s,"Failed to fetch WhatsApp notification config"));return s.json()}async function ba(s){const n=await fetch(`${Y()}/api/whatsapp/notification-config`,{method:"PATCH",headers:Ze(!0),body:JSON.stringify(s)});if(!n.ok)throw new Error(await Qe(n,"Failed to update WhatsApp notification config"));return n.json()}async function ja(){const s=await fetch(`${Y()}/api/whatsapp/notification-config`,{method:"DELETE",headers:Ze()});if(!s.ok)throw new Error(await Qe(s,"Failed to reset WhatsApp notification config"));return s.json()}const Be={messages:!0,statusChanges:!0,taskComplete:!0,errors:!0,planReady:!0,agentSpawned:!0,agentStopped:!0},us={filter:{...Be},recipient:""};function va(s,n){if(s.recipient!==n.recipient)return!1;for(const t of ws)if(s.filter[t]!==n.filter[t])return!1;return!0}function wa({isOpen:s,onClose:n}){const{t}=X(["config"]),[i,d]=l.useState(us),[c,r]=l.useState(us),[g,o]=l.useState(!0),[u,N]=l.useState(null),[k,m]=l.useState(null),[P,b]=l.useState(!1),[E,x]=l.useState(!1),p=!va(i,c),S=l.useCallback(async()=>{try{o(!0),N(null),m(null);const h=await xa(),$={filter:{...Be,...h.filter},recipient:h.recipient??""};d($),r($)}catch(h){N(h instanceof Error?h.message:t("config:whatsappNotifications.errors.loadFailed"))}finally{o(!1)}},[t]);l.useEffect(()=>{s&&S()},[s,S]);const M=(h,$)=>{d(R=>({...R,filter:{...R.filter,[h]:$}})),N(null),m(null)},F=h=>{d($=>({...$,recipient:h})),N(null),m(null)},Q=async()=>{try{N(null),m(null);const h=await ba({filter:i.filter,recipient:i.recipient.trim()}),$={filter:{...Be,...h.filter},recipient:h.recipient??""};d($),r($),m(t("config:whatsappNotifications.saved"))}catch(h){N(h instanceof Error?h.message:t("config:whatsappNotifications.errors.saveFailed"))}},W=()=>{d(c),N(null),m(null)},J=async()=>{try{N(null),m(null);const h=await ja(),$={filter:{...Be,...h.filter},recipient:h.recipient??""};d($),r($),m(t("config:whatsappNotifications.resetDone"))}catch(h){N(h instanceof Error?h.message:t("config:whatsappNotifications.errors.resetFailed"))}},U=()=>{if(p){b(!0);return}n()},V=h=>{h.key==="Escape"&&(h.preventDefault(),U())};return s?e.jsxs($e,{children:[e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:U,children:e.jsxs("div",{className:"whatsapp-notifications-modal",onClick:h=>h.stopPropagation(),onKeyDown:V,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsappNotifications.title")}),e.jsx("button",{className:"modal-close",onClick:U,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsx("div",{className:"modal-body",children:g?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:t("config:whatsappNotifications.loading")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:t("config:whatsappNotifications.description")}),u&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"warn",size:14})}),u]}),k&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:e.jsx(I,{name:"check",size:14})}),k]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:t("config:whatsappNotifications.sections.recipient")}),e.jsxs("div",{className:"wan-field",children:[e.jsx("label",{htmlFor:"wan-recipient",className:"wan-label",children:t("config:whatsappNotifications.recipientLabel")}),e.jsx("input",{id:"wan-recipient",type:"text",className:"wan-input",placeholder:t("config:whatsappNotifications.recipientPlaceholder"),value:i.recipient,onChange:h=>F(h.target.value)}),e.jsx("span",{className:"wan-hint",children:t("config:whatsappNotifications.recipientHint")})]})]}),e.jsxs("section",{className:"wan-section",children:[e.jsx("h3",{className:"wan-section-title",children:t("config:whatsappNotifications.sections.events")}),e.jsx("p",{className:"wan-section-hint",children:t("config:whatsappNotifications.eventsHint")}),ws.map(h=>e.jsxs("div",{className:"wan-toggle-row",children:[e.jsxs("div",{className:"wan-toggle-info",children:[e.jsx("span",{className:"wan-toggle-title",children:t(`config:whatsappNotifications.events.${h}.title`)}),e.jsx("span",{className:"wan-toggle-help",children:t(`config:whatsappNotifications.events.${h}.help`)})]}),e.jsxs("label",{className:"wan-toggle",children:[e.jsx("input",{type:"checkbox",checked:i.filter[h],onChange:$=>M(h,$.target.checked)}),e.jsx("span",{className:"wan-toggle-track",children:e.jsx("span",{className:"wan-toggle-thumb"})})]})]},h))]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:()=>x(!0),disabled:g,children:t("config:whatsappNotifications.resetToDefaults")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:U,children:t("config:whatsappNotifications.close")}),e.jsx("button",{className:"btn btn-secondary",onClick:W,disabled:!p||g,children:t("config:whatsappNotifications.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:Q,disabled:!p||g,children:t("config:whatsappNotifications.save")})]})]})]})}),e.jsx(xe,{isOpen:P,title:t("config:whatsappNotifications.unsavedTitle"),message:t("config:whatsappNotifications.unsavedMessage"),confirmLabel:t("config:whatsappNotifications.closeAnyway"),cancelLabel:t("config:whatsappNotifications.keepEditing"),variant:"danger",onConfirm:()=>{b(!1),n()},onClose:()=>b(!1)}),e.jsx(xe,{isOpen:E,title:t("config:whatsappNotifications.resetToDefaults"),message:t("config:whatsappNotifications.confirmReset"),confirmLabel:t("config:whatsappNotifications.resetToDefaults"),cancelLabel:"Cancel",variant:"danger",onConfirm:()=>{J(),x(!1)},onClose:()=>x(!1)})]}):null}function Ns(s){const n=s.replace(/@.*$/,"");return/^\d{10,15}$/.test(n)?n.startsWith("521")&&n.length===13?`+52 1 ${n.slice(3,5)} ${n.slice(5,9)} ${n.slice(9)}`:n.startsWith("52")&&n.length===12?`+52 ${n.slice(2,4)} ${n.slice(4,8)} ${n.slice(8)}`:n.startsWith("1")&&n.length===11?`+1 ${n.slice(1,4)} ${n.slice(4,7)} ${n.slice(7)}`:`+${n}`:s}function Na(s,n=Date.now()){const t=s*1e3,i=n-t;if(i<0)return ps(t);const d=Math.floor(i/6e4);if(d<1)return"now";if(d<60)return`${d}m`;const c=Math.floor(d/60);if(c<24)return`${c}h`;const r=Math.floor(c/24);return r===1?"yesterday":r<7?`${r}d`:ps(t)}function ps(s){return new Date(s).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function ya(s){const n=s*1e3;return new Date(n).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1})}function ys(s){switch(s){case"image":return"📷";case"audio":return"🎤";case"video":return"📹";case"document":return"📎";case"location":return"📍";case"contact":return"👤";case"sticker":return"🌟";case"reaction":return"👍";case"unknown":return"❓";case"text":default:return null}}function ka(s,n){return s.length<=n?s:s.slice(0,Math.max(0,n-1)).trimEnd()+"…"}function Sa({chats:s,selectedChatId:n,loading:t,error:i,onSelect:d,onRefresh:c,now:r}){const{t:g}=X(["config","common"]);return e.jsxs("div",{className:"whatsapp-history-chatlist",children:[e.jsxs("div",{className:"whatsapp-history-chatlist__header",children:[e.jsx("span",{className:"whatsapp-history-chatlist__title",children:g("config:whatsappHistory.chats")}),e.jsx("button",{type:"button",className:"whatsapp-history-chatlist__refresh",onClick:c,disabled:t,"aria-label":g("config:whatsappHistory.refresh"),title:g("config:whatsappHistory.refresh"),children:"⟳"})]}),i&&e.jsx("div",{className:"whatsapp-history-chatlist__error",children:i}),t&&s.length===0&&e.jsxs("div",{className:"whatsapp-history-chatlist__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:g("config:whatsappHistory.loadingChats")})]}),!t&&!i&&s.length===0&&e.jsx("div",{className:"whatsapp-history-chatlist__empty",children:g("config:whatsappHistory.emptyChats")}),e.jsx("ul",{className:"whatsapp-history-chatlist__items",children:s.map(o=>{const u=ys(o.lastMessageType),N=o.lastMessagePreview||`[${o.lastMessageType}]`,k=o.chatId===n,m=Ns(o.chatId),P=o.isGroup?o.groupName:o.fromName,b=P||m,E=!!P&&P!==m;return e.jsx("li",{className:`whatsapp-history-chatlist__item ${k?"is-selected":""}`,children:e.jsxs("button",{type:"button",className:"whatsapp-history-chatlist__button",onClick:()=>d(o.chatId),children:[e.jsxs("div",{className:"whatsapp-history-chatlist__row",children:[e.jsx("span",{className:"whatsapp-history-chatlist__name",title:o.chatId,children:b}),e.jsx("span",{className:"whatsapp-history-chatlist__time",children:Na(o.lastTimestamp,r)})]}),E&&e.jsx("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--jid",children:e.jsx("span",{className:"whatsapp-history-chatlist__jid",children:m})}),e.jsxs("div",{className:"whatsapp-history-chatlist__row whatsapp-history-chatlist__row--secondary",children:[e.jsxs("span",{className:"whatsapp-history-chatlist__preview",children:[o.lastDirection==="outbound"&&e.jsx("span",{className:"whatsapp-history-chatlist__direction",children:"↗ "}),u&&e.jsxs("span",{className:"whatsapp-history-chatlist__preview-icon",children:[u," "]}),ka(N,40)]}),o.unreadCount>0&&e.jsx("span",{className:"whatsapp-history-chatlist__unread",children:o.unreadCount})]})]})},o.chatId)})})]})}function Ca({message:s}){const n=s.direction==="outbound"?"outbound":"inbound",t=ys(s.messageType),i=(s.body??"").trim(),d=i.length>0,c=d?null:`[${s.messageType}]`;return e.jsx("div",{className:`whatsapp-history-bubble whatsapp-history-bubble--${n}`,children:e.jsxs("div",{className:"whatsapp-history-bubble__inner",children:[t&&e.jsx("span",{className:"whatsapp-history-bubble__type-icon",title:s.messageType,children:t}),d?e.jsx("span",{className:"whatsapp-history-bubble__body",children:i}):e.jsx("span",{className:"whatsapp-history-bubble__placeholder",children:c}),s.audioTranscription&&e.jsxs("span",{className:"whatsapp-history-bubble__transcription",children:["“",s.audioTranscription,"”"]}),s.mediaPath&&e.jsx("a",{className:"whatsapp-history-bubble__media-link",href:s.mediaPath,target:"_blank",rel:"noopener noreferrer",children:s.mediaFilename||"open media"}),e.jsx("span",{className:"whatsapp-history-bubble__time",children:ya(s.timestamp)})]})})}const Aa=["all","inbound","outbound"],Ta=["all","text","image","audio","video","document","sticker","location","contact","reaction","unknown"];function Ea({direction:s,type:n,onDirectionChange:t,onTypeChange:i,disabled:d}){const{t:c}=X(["config"]);return e.jsxs("div",{className:"whatsapp-history-filters",children:[e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:c("config:whatsappHistory.direction")}),e.jsx("select",{value:s,onChange:r=>t(r.target.value),disabled:d,children:Aa.map(r=>e.jsx("option",{value:r,children:c(`config:whatsappHistory.directionValues.${r}`)},r))})]}),e.jsxs("label",{className:"whatsapp-history-filters__field",children:[e.jsx("span",{children:c("config:whatsappHistory.type")}),e.jsx("select",{value:n,onChange:r=>i(r.target.value),disabled:d,children:Ta.map(r=>e.jsx("option",{value:r,children:c(`config:whatsappHistory.typeValues.${r}`)},r))})]})]})}const Pa=80;function _a({chatId:s,messages:n,loading:t,loadingMore:i,error:d,hasMore:c,direction:r,type:g,onDirectionChange:o,onTypeChange:u,onLoadMore:N}){const{t:k}=X(["config"]),m=l.useRef(null),P=l.useRef(null),b=l.useRef(!1),E=l.useRef(null);l.useEffect(()=>{P.current!==s&&(P.current=s,b.current=!1)},[s]),l.useLayoutEffect(()=>{m.current&&(b.current||n.length!==0&&(m.current.scrollTop=m.current.scrollHeight,b.current=!0))},[s,n.length]),l.useLayoutEffect(()=>{if(!m.current||E.current===null)return;const S=m.current.scrollHeight-E.current;E.current=null,S>0&&(m.current.scrollTop+=S)},[n.length]);const x=l.useCallback(()=>{!c||i||t||(m.current&&(E.current=m.current.scrollHeight),N())},[c,i,t,N]),p=l.useCallback(S=>{if(!b.current)return;S.currentTarget.scrollTop<=Pa&&x()},[x]);return s?e.jsxs("div",{className:"whatsapp-history-messages",children:[e.jsxs("div",{className:"whatsapp-history-messages__header",children:[e.jsx("div",{className:"whatsapp-history-messages__title",children:Ns(s)}),e.jsx(Ea,{direction:r,type:g,onDirectionChange:o,onTypeChange:u,disabled:t})]}),e.jsxs("div",{className:"whatsapp-history-messages__scroll",ref:m,onScroll:p,children:[c&&e.jsx("div",{className:"whatsapp-history-messages__load-more-row",children:e.jsx("button",{type:"button",className:"whatsapp-history-messages__load-more",onClick:x,disabled:i||t,children:k(i?"config:whatsappHistory.loadingOlder":"config:whatsappHistory.loadOlder")})}),d&&e.jsx("div",{className:"whatsapp-history-messages__error",children:d}),t&&n.length===0&&e.jsxs("div",{className:"whatsapp-history-messages__loading",children:[e.jsx("span",{className:"spinner"}),e.jsx("span",{children:k("config:whatsappHistory.loadingMessages")})]}),!t&&!d&&n.length===0&&e.jsx("div",{className:"whatsapp-history-messages__empty",children:k("config:whatsappHistory.emptyMessages")}),n.map(S=>e.jsx(Ca,{message:S},Ia(S)))]})]}):e.jsx("div",{className:"whatsapp-history-messages whatsapp-history-messages--empty",children:e.jsx("div",{className:"whatsapp-history-messages__placeholder",children:k("config:whatsappHistory.selectChat")})})}function Ia(s){return typeof s.id=="number"?`id:${s.id}`:s.messageId?`mid:${s.messageId}`:`t:${s.timestamp}:${s.fromJid}:${(s.body??"").slice(0,16)}`}function ks(){const s=Z(),n={};return s&&(n.Authorization=`Bearer ${s}`),n}async function Ss(s,n){try{const t=await s.json();if(t&&typeof t.error=="string")return t.error;if(t&&typeof t.message=="string")return t.message}catch{}return`${n}: ${s.statusText}`}async function $a(s){const n=`${Y()}/api/whatsapp/chats/${encodeURIComponent(s)}`,t=await fetch(n,{headers:ks()});if(!t.ok)throw new Error(await Ss(t,"Failed to fetch WhatsApp chats"));return t.json()}async function hs(s,n,t={}){const i=new URLSearchParams;t.cursor&&i.set("cursor",t.cursor),typeof t.limit=="number"&&i.set("limit",String(t.limit)),t.direction&&i.set("direction",t.direction),t.type&&i.set("type",t.type);const d=i.toString(),c=`${Y()}/api/whatsapp/chats/${encodeURIComponent(s)}/${encodeURIComponent(n)}/messages${d?`?${d}`:""}`,r=await fetch(c,{headers:ks()});if(!r.ok)throw new Error(await Ss(r,"Failed to fetch WhatsApp messages"));return r.json()}const Oa=50;function La({isOpen:s,onClose:n}){const{t}=X(["config"]),[i,d]=l.useState([]),[c,r]=l.useState(null),[g,o]=l.useState(null),[u,N]=l.useState([]),[k,m]=l.useState(!1),[P,b]=l.useState(null),[E,x]=l.useState(null),[p,S]=l.useState([]),[M,F]=l.useState(!1),[Q,W]=l.useState(!1),[J,U]=l.useState(null),[V,h]=l.useState(null),[$,R]=l.useState("all"),[H,ne]=l.useState("all"),[j,L]=l.useState(()=>Date.now()),z=l.useRef(0);l.useEffect(()=>{if(!s)return;const y=window.setInterval(()=>L(Date.now()),6e4);return()=>window.clearInterval(y)},[s]),l.useEffect(()=>{if(!s)return;let y=!1;return(async()=>{var te;try{o(null);const[oe,de]=await Promise.all([Xe().catch(()=>[]),xs().catch(()=>null)]);if(y)return;d(oe);const ie=(de==null?void 0:de.defaultSessionId)||((te=oe[0])==null?void 0:te.id)||null;r(he=>he??ie)}catch(oe){if(y)return;o(oe instanceof Error?oe.message:String(oe))}})(),()=>{y=!0}},[s]);const v=l.useCallback(async y=>{m(!0),b(null);try{const te=await $a(y);N(te.chats)}catch(te){b(te instanceof Error?te.message:String(te))}finally{m(!1)}},[]);l.useEffect(()=>{!s||!c||(x(null),S([]),h(null),v(c))},[s,c,v]);const O=l.useMemo(()=>{const y={limit:Oa};return $!=="all"&&(y.direction=$),H!=="all"&&(y.type=H),y},[$,H]),D=l.useCallback(async(y,te,oe)=>{const de=++z.current;F(!0),U(null),S([]),h(null);try{const ie=await hs(y,te,oe);if(de!==z.current)return;S([...ie.messages].reverse()),h(ie.nextCursor)}catch(ie){if(de!==z.current)return;U(ie instanceof Error?ie.message:String(ie))}finally{de===z.current&&F(!1)}},[]);l.useEffect(()=>{!s||!c||!E||D(c,E,O)},[s,c,E,O,D]);const se=l.useCallback(async()=>{if(!(!c||!E||!V)){W(!0),U(null);try{const y=await hs(c,E,{...O,cursor:V});S(te=>[...[...y.messages].reverse(),...te]),h(y.nextCursor)}catch(y){U(y instanceof Error?y.message:String(y))}finally{W(!1)}}},[c,E,V,O]),ae=l.useCallback(()=>{c&&v(c)},[c,v]),T=l.useCallback(y=>{y.key==="Escape"&&(y.preventDefault(),n())},[n]);return s?e.jsx($e,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"whatsapp-history-modal",onClick:y=>y.stopPropagation(),onKeyDown:T,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:t("config:whatsappHistory.title")}),e.jsx("div",{className:"whatsapp-history-modal__session",children:e.jsxs("label",{children:[e.jsx("span",{children:t("config:whatsappHistory.session")}),e.jsxs("select",{value:c??"",onChange:y=>r(y.target.value||null),disabled:i.length===0,children:[i.length===0&&e.jsx("option",{value:"",children:t("config:whatsappHistory.noSessions")}),i.map(y=>e.jsxs("option",{value:y.id,children:[y.id,y.pairedNumber?` (${y.pairedNumber})`:""]},y.id))]})]})}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),g&&e.jsx("div",{className:"whatsapp-history-modal__alert",children:g}),e.jsxs("div",{className:"whatsapp-history-modal__body",children:[e.jsx(Sa,{chats:u,selectedChatId:E,loading:k,error:P,onSelect:x,onRefresh:ae,now:j}),e.jsx(_a,{chatId:E,messages:p,loading:M,loadingMore:Q,error:J,hasMore:V!==null,direction:$,type:H,onDirectionChange:R,onTypeChange:ne,onLoadMore:se})]})]})})}):null}function Da({isOpen:s,onClose:n,onOpenConfig:t,onOpenNotifications:i,onOpenHistory:d}){const{t:c}=X(["config"]);if(l.useEffect(()=>{if(!s)return;const g=o=>{o.key==="Escape"&&(o.preventDefault(),n())};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[s,n]),!s)return null;const r=g=>{n(),g()};return e.jsx($e,{children:e.jsx("div",{className:"modal-overlay visible",onClick:n,children:e.jsxs("div",{className:"whatsapp-hub-modal",onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{className:"modal-header",children:[e.jsxs("h2",{children:[e.jsx("span",{className:"whatsapp-hub-modal__icon",children:"📱"}),c("config:whatsappHub.title",{defaultValue:"WhatsApp"})]}),e.jsx("button",{className:"modal-close",onClick:n,"aria-label":"Close",children:e.jsx(I,{name:"close",size:16})})]}),e.jsxs("div",{className:"modal-body",children:[e.jsx("p",{className:"whatsapp-hub-modal__intro",children:c("config:whatsappHub.intro",{defaultValue:"Pick what you want to manage for the WhatsApp integration."})}),e.jsxs("div",{className:"whatsapp-hub-modal__options",children:[e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>r(t),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(I,{name:"gear",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:c("config:whatsappHub.config",{defaultValue:"Integration config"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:c("config:whatsappHub.configDesc",{defaultValue:"Server URL, API key, sessions and pairing."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>r(i),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(I,{name:"bell",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:c("config:whatsappHub.notifications",{defaultValue:"Notifications"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:c("config:whatsappHub.notificationsDesc",{defaultValue:"Which agent events get forwarded and to whom."})})]})]}),e.jsxs("button",{type:"button",className:"whatsapp-hub-modal__option",onClick:()=>r(d),children:[e.jsx("span",{className:"whatsapp-hub-modal__option-icon",children:e.jsx(I,{name:"hourglass",size:18})}),e.jsxs("span",{className:"whatsapp-hub-modal__option-text",children:[e.jsx("span",{className:"whatsapp-hub-modal__option-title",children:c("config:whatsappHub.history",{defaultValue:"History"})}),e.jsx("span",{className:"whatsapp-hub-modal__option-desc",children:c("config:whatsappHub.historyDesc",{defaultValue:"Browse persisted chats and messages."})})]})]})]})]})]})})})}const Ye=[{kind:"question",settingKey:"toneQuestion",label:"Agent asks you something",when:"A question, a plan to approve, or a permission request. Repeats twice up front, then every 10s until you answer (stops after 2 min).",sound:"Two taps, then a rising bend",play:js},{kind:"notification",settingKey:"toneNotification",label:"Agent sends a notification",when:"Any agent notification: task complete, error, or a heads-up.",sound:"Soft two-note chime",play:bs},{kind:"completion",settingKey:"toneCompletion",label:"Agent finishes working",when:"An agent stops working and goes idle.",sound:"Gentle descending arpeggio",play:ft}],Fa=[{value:"auto",label:"Auto",icon:"🕐"},{value:"dawn",label:"Dawn",icon:"🌅"},{value:"day",label:"Day",icon:"☀️"},{value:"dusk",label:"Dusk",icon:"🌇"},{value:"night",label:"Night",icon:"🌙"}],Ra=[{value:"none",label:"Grass",icon:"🌱"},{value:"concrete",label:"Concrete",icon:"🏗️"},{value:"galactic",label:"Galactic",icon:"🌌"},{value:"metal",label:"Metal",icon:"⚙️"},{value:"hex",label:"Hex",icon:"⬡"},{value:"circuit",label:"Circuit",icon:"🔌"},{value:"pokemon-stadium",label:"Pokemon",icon:"🔴"}],Ba=[{value:"static",label:"Static",icon:"🧍"},{value:"idle",label:"Idle",icon:"🚶"},{value:"walk",label:"Walk",icon:"🚶‍♂️"},{value:"sprint",label:"Sprint",icon:"🏃"},{value:"jump",label:"Jump",icon:"⬆️"},{value:"fall",label:"Fall",icon:"⬇️"},{value:"crouch",label:"Crouch",icon:"🧎"},{value:"sit",label:"Sit",icon:"🪑"},{value:"die",label:"Die",icon:"💀"},{value:"emote-yes",label:"Yes",icon:"👍"},{value:"emote-no",label:"No",icon:"👎"}],Ma=[{value:"normal",label:"Normal",icon:"🎨"},{value:"bw",label:"B&W",icon:"⬛"},{value:"sepia",label:"Sepia",icon:"🟤"},{value:"cool",label:"Cool",icon:"❄️"},{value:"warm",label:"Warm",icon:"🔥"},{value:"neon",label:"Neon",icon:"💜"}],Ua=[{key:"showTrees",icon:"🌳",label:"Trees"},{key:"showBushes",icon:"🌿",label:"Bushes"},{key:"showHouse",icon:"🏠",label:"House"},{key:"showLamps",icon:"💡",label:"Lamps"},{key:"showGrass",icon:"🟩",label:"Grass"},{key:"showClouds",icon:"☁️",label:"Clouds"}],za=[{value:null,label:"Auto",color:"linear-gradient(135deg, #4a90d9 0%, #0a1a2a 100%)"},{value:"#4a90d9",label:"Day Blue",color:"#4a90d9"},{value:"#0a1a2a",label:"Night",color:"#0a1a2a"},{value:"#ff6b35",label:"Sunset",color:"#ff6b35"},{value:"#1a0a2e",label:"Purple",color:"#1a0a2e"},{value:"#2d5a27",label:"Matrix",color:"#2d5a27"},{value:"#8b0000",label:"Blood",color:"#8b0000"},{value:"#000000",label:"Void",color:"#000000"}],Va={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},Ka={none:"grass","pokemon-stadium":"pokemon"},Ha={"emote-yes":"yes","emote-no":"no"},qa={"":"auto","#4a90d9":"dayBlue","#0a1a2a":"night","#ff6b35":"sunset","#1a0a2e":"purple","#2d5a27":"matrix","#8b0000":"blood","#000000":"void"};function ee({checked:s,onChange:n}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,onChange:t=>n(t.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function Ce({options:s,value:n,onChange:t,iconOnly:i=!1}){return e.jsx("div",{className:"chip-selector",children:s.map(d=>e.jsxs("button",{className:`chip ${n===d.value?"active":""}`,onClick:()=>t(d.value),title:d.label,children:[e.jsx("span",{className:"chip-icon",children:d.icon}),!i&&e.jsx("span",{className:"chip-label",children:d.label})]},d.value))})}function C({text:s,query:n}){if(!n.trim())return e.jsx(e.Fragment,{children:s});const t=s.toLowerCase(),i=n.toLowerCase(),d=t.indexOf(i);if(d===-1)return e.jsx(e.Fragment,{children:s});const c=s.slice(0,d),r=s.slice(d,d+n.length),g=s.slice(d+n.length);return e.jsxs(e.Fragment,{children:[c,e.jsx("mark",{className:"search-highlight",children:r}),g]})}const Wa=[{id:"general",title:"General",keywords:["history","hide costs","grid","fps","power saving","low power","battery","bajo consumo","performance","limit","editor","external editor","language","idioma","语言","vibration","haptic","intensity","tab title","tmux","process persistence","interactive","tui","terminal","experimental","claude","stream","streaming","word by word","live text","grok","codex","app-server","app server","opencode","serve","hover","preview","tooltip","ctrl","popup","vista previa","sound","sounds","sonido","sonidos","notification","notifications","notificacion","notificaciones","volume","volumen","tone","tones","tono","chime","alert","cue","audio","mute","silence","dock","activity","recent","notification sound","silenciar","custom sound","upload sound","alerta"]},{id:"agentNames",title:"Agent Names",keywords:["agent","names","custom","characters","rename"]},{id:"defaultClass",title:"Default Spawn Class",keywords:["default","class","spawn","agent","scout","builder","random"]},{id:"appearance",title:"Appearance",keywords:["theme","appearance","color","dark","light","style","look"]},{id:"connection",title:"Connection",keywords:["backend","url","auth","token","reconnect","server","api","connect","codex","opencode","binary","path"]},{id:"scene",title:"Scene",keywords:["character","size","indicator","scale","time","dawn","day","dusk","night","auto"]},{id:"terrain",title:"Terrain",keywords:["trees","bushes","house","lamps","grass","clouds","fog","brightness","floor","sky","color","environment","battlefield","size","grid","simple","minimal","dark","clean"]},{id:"modelStyle",title:"Agent Model Style",keywords:["saturation","roughness","metalness","glow","emissive","reflections","wireframe","color mode","material","shader"]},{id:"animations",title:"Animations",keywords:["idle","working","animation","walk","run","sprint","jump","sit","crouch"]},{id:"secrets",title:"Secrets",keywords:["secrets","api","key","password","credentials","env","environment"]},{id:"claudeAccounts",title:"Claude Accounts",keywords:["claude","accounts","credentials","oauth","rate limit","session","david","profile","switch account","subscription"]},{id:"grokAccounts",title:"Grok Accounts",keywords:["grok","xai","x.ai","accounts","credentials","oauth","session","profile","switch account","subscription"]},{id:"codexAccounts",title:"Codex Accounts",keywords:["codex","openai","chatgpt","accounts","credentials","oauth","session","profile","switch account","subscription"]},{id:"systemPrompt",title:"System Prompt",keywords:["system","prompt","global","instructions","ai","agent","rules","guidelines"]},{id:"data",title:"Data",keywords:["export","import","backup","restore","save","load","json"]},{id:"integrations",title:"Integrations",keywords:["integrations","integraciones","plugins","gmail","slack","jira","calendar","docx","email","whatsapp","notifications","notification","baileys","history","historial","chat","messages","inbox","config","setup"]},{id:"workflows",title:"Workflows",keywords:["workflow","automation","state machine","editor","actions","transitions","pipeline"]},{id:"triggers",title:"Triggers",keywords:["trigger","event","webhook","cron","slack","email","jira","matching","fire"]},{id:"monitoring",title:"Monitoring",keywords:["monitoring","logs","triggers","events","history","workflow","traces","audit","timeline"]},{id:"statistics",title:"Statistics",keywords:["statistics","stats","usage","tokens","token","claude","chart","graph","pie","cost"]},{id:"experimental",title:"Experimental",keywords:["experimental","2d","view","voice","assistant","speech","tts","text to speech","echo","prompt","duplicate"]},{id:"about",title:"About",keywords:["about","version","update","credits","github","releases"]}],Je=[{value:"auto",label:"Auto",icon:"🌐"},{value:"en",label:"English",icon:"🇺🇸"},{value:"zh-CN",label:"中文",icon:"🇨🇳"},{value:"es",label:"Español",icon:"🇪🇸"},{value:"hi",label:"हिन्दी",icon:"🇮🇳"},{value:"pt",label:"Português",icon:"🇧🇷"},{value:"ru",label:"Русский",icon:"🇷🇺"},{value:"ja",label:"日本語",icon:"🇯🇵"},{value:"de",label:"Deutsch",icon:"🇩🇪"},{value:"fr",label:"Français",icon:"🇫🇷"},{value:"it",label:"Italiano",icon:"🇮🇹"}];function Ga({config:s,onChange:n,searchQuery:t="",onOpenIntegrationsModal:i,onOpenMonitoringModal:d,onOpenStatisticsModal:c,onOpenWorkflowEditor:r,onOpenTriggerManager:g}){var ns;const{t:o}=X(["config","common"]),u=at(),N=nt(),[k,m]=l.useState(()=>ot(_e.DEFAULT_AGENT_CLASS)||"scout"),P=it(),b=lt(),[E,x]=l.useState(()=>ct()),[p,S]=l.useState(null),[M,F]=l.useState(null);l.useEffect(()=>{He().then(x)},[]);const Q=async(a,A)=>{F(null),S(a);try{const B=await Ne(ye(`/api/custom-sounds/${a}`),{method:"POST",headers:{"Content-Type":A.type||"audio/mpeg"},body:A});if(!B.ok){const re=await B.json().catch(()=>({error:`Upload failed (${B.status})`}));throw new Error(re.error||`Upload failed (${B.status})`)}const le=await He();x({...le});const fe=Ye.find(re=>re.kind===a);fe&&w.updateSettings({[fe.settingKey]:Ie}),qe(Ie,u.notificationSoundVolume,a)}catch(B){F(B instanceof Error?B.message:"Upload failed")}finally{S(null)}},W=async a=>{F(null);try{await Ne(ye(`/api/custom-sounds/${a}`),{method:"DELETE"}),wt({[a]:null});const A=await He();x({...A});const B=Ye.find(le=>le.kind===a);B&&w.getSettings()[B.settingKey]===Ie&&w.updateSettings({[B.settingKey]:Nt[a]})}catch(A){F(A instanceof Error?A.message:"Failed to reset sound")}},[J,U]=l.useState(u.historyLimit),[V,h]=l.useState(()=>rt()),[$,R]=l.useState(!1),[H,ne]=l.useState(""),[j,L]=l.useState(()=>Z()),[z,v]=l.useState(!1),[O,D]=l.useState(!1),[se,ae]=l.useState(""),[T,y]=l.useState(!1),[te,oe]=l.useState(!1),[de,ie]=l.useState(!1),[he,ke]=l.useState(!1),[Ae,ue]=l.useState(!1),[Te,me]=l.useState(""),[ge,Oe]=l.useState(!1);l.useEffect(()=>{Ht().then(me).catch(()=>{})},[]),l.useEffect(()=>{Vt().then(a=>{a!==u.experimentalEchoPrompt&&w.updateSettings({experimentalEchoPrompt:a})}).catch(()=>{})},[]),l.useEffect(()=>{Wt().then(a=>{a!==u.tmuxMode&&w.updateSettings({tmuxMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{Yt().then(a=>{a!==u.interactiveMode&&w.updateSettings({interactiveMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{Xt().then(a=>{a!==u.codexAppServerMode&&w.updateSettings({codexAppServerMode:a})}).catch(()=>{})},[]),l.useEffect(()=>{Qt().then(a=>{a!==u.opencodeServerMode&&w.updateSettings({opencodeServerMode:a})}).catch(()=>{})},[]),l.useEffect(()=>dt(a=>{h(a),R(!1)}),[]);const Me=Fa.map(a=>({...a,label:o(`config:time.${a.value}`)})),Se=Ra.map(a=>({...a,label:o(`config:floor.${Ka[a.value]||a.value}`)})),Le=Ba.map(a=>({...a,label:o(`config:animation.${Ha[a.value]||a.value}`)})),Ue=Ma.map(a=>({...a,label:o(`config:colorMode.${a.value}`)})),ze=Ua.map(a=>({...a,label:o(`config:terrain.${Va[a.key]}`)})),Ve=za.map(a=>({...a,label:o(`config:sky.${qa[a.value??""]}`)})),be=t.trim()?Wa.filter(a=>{const A=t.toLowerCase();return a.title.toLowerCase().includes(A)||a.keywords.some(B=>B.toLowerCase().includes(A))}).map(a=>a.id):null,_=a=>be?be.includes(a):!0,Ee=_("integrations"),pe=u.customAgentNames||[],Ke=pe.length>0?pe:ut,De=()=>{const a=se.trim();a&&!pe.includes(a)&&(w.updateSettings({customAgentNames:[...pe,a]}),ae(""))},f=a=>{w.updateSettings({customAgentNames:pe.filter(A=>A!==a)})},K=()=>{w.updateSettings({customAgentNames:[]})},ce=()=>{const a=H.trim();if(a){if(V.includes(a)){ne("");return}h([...V,a]),R(!0),ne("")}},je=a=>{h(V.filter((A,B)=>B!==a)),R(!0)},es=(a,A)=>{const B=a+A;if(B<0||B>=V.length)return;const le=V.slice();[le[a],le[B]]=[le[B],le[a]],h(le),R(!0)},Cs=()=>{yt(V),R(!1),Ge()},As=a=>{L(a),v(!0)},ss=()=>{Fe(_e.AUTH_TOKEN,j),v(!1),Ge()},Ts=a=>{me(a),Oe(!0)},ts=()=>{qt(Te).catch(()=>{}),Oe(!1)},ve=a=>{n({...s,terrain:{...s.terrain,...a}})},we=a=>{n({...s,modelStyle:{...s.modelStyle,...a}})},as=a=>{n({...s,animations:{...s.animations,...a}})},Es=a=>{U(a),w.updateSettings({historyLimit:a})},Ps=a=>{const A=s.terrain[a];typeof A=="boolean"&&ve({[a]:!A})},G=t.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-section",children:[be&&be.length===0&&e.jsx("div",{className:"config-no-results",children:o("config:noResults",{query:t})}),_("general")&&e.jsxs(q,{title:o("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:G&&_("general"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.history"),query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:J,onChange:a=>Es(parseInt(a.target.value)||100),min:50,max:2e3,step:50})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.hideCosts"),query:t})}),e.jsx(ee,{checked:u.hideCost,onChange:a=>w.updateSettings({hideCost:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.streamTextLiveTitle"),children:e.jsx(C,{text:o("config:general.streamTextLive"),query:t})}),e.jsx(ee,{checked:u.streamTextLive!==!1,onChange:a=>w.updateSettings({streamTextLive:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:o("config:general.toolHoverPreviewTitle"),children:e.jsx(C,{text:o("config:general.toolHoverPreview"),query:t})}),e.jsx(ee,{checked:u.toolHoverPreview!==!1,onChange:a=>w.updateSettings({toolHoverPreview:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Where the strip of recently-active and currently-working agent thumbnails sits.",children:e.jsx(C,{text:"Agent activity dock",query:t})}),e.jsx("select",{className:"config-select",value:P,onChange:a=>mt(a.target.value),children:pt.map(a=>e.jsx("option",{value:a,children:ht[a]},a))})]}),P!=="hidden"&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"How many recently-active agents the dock shows alongside the ones working right now. 0 shows only working agents.",children:e.jsx(C,{text:"Recent agents in dock",query:t})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:b,min:0,max:20,step:1,onChange:a=>gt(parseInt(a.target.value,10)||0)})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.grid"),query:t})}),e.jsx(ee,{checked:s.gridVisible,onChange:a=>n({...s,gridVisible:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.showFPS"),query:t})}),e.jsx(ee,{checked:u.showFPS,onChange:a=>w.updateSettings({showFPS:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.fpsLimit"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"120",step:"10",value:s.fpsLimit,onChange:a=>n({...s,fpsLimit:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.fpsLimit===0?"∞":s.fpsLimit})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: Reduce FPS when idle to save power",children:[e.jsx(C,{text:o("config:general.powerSaving"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.powerSaving,onChange:a=>w.updateSettings({powerSaving:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Battery saver for mobile: caps scene FPS (20 active / 5 idle), freezes decorative animations and disables word-by-word streaming. Off = normal mode.",children:[e.jsx(C,{text:o("config:general.lowPowerMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.lowPowerMode===!0,onChange:a=>w.updateSettings({lowPowerMode:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Wrap agent processes in tmux sessions so they survive server restarts (requires tmux installed)",children:e.jsx(C,{text:o("config:general.tmuxMode"),query:t})}),e.jsx(ee,{checked:u.tmuxMode,onChange:async a=>{w.updateSettings({tmuxMode:a});try{await Gt(a)}catch(A){console.error("Failed to sync tmux mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run Claude agents as the real interactive `claude` TUI inside tmux, reconstructing the conversation from the session transcript (requires tmux). Takes effect on server restart.",children:[e.jsx(C,{text:o("config:general.interactiveMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.interactiveMode,onChange:async a=>{w.updateSettings({interactiveMode:a});try{await Jt(a)}catch(A){console.error("Failed to sync interactive mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run Codex agents through a persistent `codex app-server` so replies stream word-by-word (token deltas) instead of appearing as one block. The app-server runs detached and survives commander restarts — in-flight turns keep running and reconnect automatically. Applies to new Codex turns; no server restart needed to toggle.",children:[e.jsx(C,{text:o("config:general.codexAppServerMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.codexAppServerMode,onChange:async a=>{w.updateSettings({codexAppServerMode:a});try{await Zt(a)}catch(A){console.error("Failed to sync codex app-server mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: run OpenCode agents through a persistent, detached `opencode serve` HTTP server so replies stream word-by-word (token deltas over SSE) instead of appearing as one block. The server survives commander restarts — in-flight turns keep running and reconnect automatically. Applies to new OpenCode turns; no server restart needed to toggle.",children:[e.jsx(C,{text:o("config:general.opencodeServerMode"),query:t})," ",e.jsx(I,{name:"bolt",size:12})]}),e.jsx(ee,{checked:u.opencodeServerMode,onChange:async a=>{w.updateSettings({opencodeServerMode:a});try{await ea(a)}catch(A){console.error("Failed to sync opencode server mode setting to server:",A)}}})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.vibrationIntensity"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"5",step:"1",value:u.vibrationIntensity,onChange:a=>w.updateSettings({vibrationIntensity:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:u.vibrationIntensity===0?o("config:vibrationValues.off"):u.vibrationIntensity===1?o("config:vibrationValues.ultraLight"):u.vibrationIntensity===2?o("config:vibrationValues.veryLight"):u.vibrationIntensity===3?o("config:vibrationValues.light"):u.vibrationIntensity===4?o("config:vibrationValues.medium"):o("config:vibrationValues.heavy")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Play pleasant sounds: a chime for agent notifications, a distinctive rising cue when an agent asks you a question (repeats until answered), and a resolving cue when an agent finishes its work.",children:e.jsx(C,{text:"Notification sounds",query:t})}),e.jsx(ee,{checked:u.notificationSoundEnabled,onChange:a=>{w.updateSettings({notificationSoundEnabled:a}),a&&bs(u.notificationSoundVolume,u.toneNotification)}})]}),u.notificationSoundEnabled&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"Notification sound volume",query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:is,step:"1",value:u.notificationSoundVolume,onChange:a=>{const A=parseInt(a.target.value);w.updateSettings({notificationSoundVolume:A}),js(A,u.toneQuestion)}}),e.jsx("span",{className:"config-value",children:u.notificationSoundVolume===0?o("config:vibrationValues.off"):`${u.notificationSoundVolume}/${is}`})]}),u.notificationSoundEnabled&&u.notificationSoundVolume>0&&e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"Sounds per event",query:t})}),e.jsx("div",{className:"config-sound-hint",children:'Pick a tone for each event — or upload your own file (mp3, wav, ogg, m4a — max 5MB), which is stored on the commander so every device hears it. "None" silences that event.'}),Ye.map(a=>{var fe;const A=!!E[a.kind],B=u[a.settingKey],le=A&&B===Ie;return e.jsxs("div",{className:"config-sound-row",children:[e.jsxs("div",{className:"config-sound-info",children:[e.jsxs("div",{className:"config-sound-head",children:[e.jsx("span",{className:"config-sound-name",children:a.label}),e.jsx("span",{className:`config-sound-badge${le?" custom":""}`,children:le?"Your file":((fe=xt(B))==null?void 0:fe.label)??a.sound})]}),e.jsx("div",{className:"config-sound-when",children:a.when})]}),e.jsxs("div",{className:"config-sound-actions",children:[e.jsxs("select",{className:"config-select",value:B,onChange:re=>{const Pe=re.target.value;w.updateSettings({[a.settingKey]:Pe}),qe(Pe,u.notificationSoundVolume,a.kind)},children:[A&&e.jsx("option",{value:Ie,children:"Your uploaded file"}),bt.map(re=>e.jsx("option",{value:re.id,children:re.label},re.id))]}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>void qe(B,u.notificationSoundVolume,a.kind),disabled:ls(B),title:ls(B)?"This event is silenced — pick a tone to hear it":"Hear the sound that plays for this event",children:"▶"}),e.jsxs("label",{className:"config-btn config-btn-sm config-sound-upload",title:"Replace this sound with your own audio file (mp3, wav, ogg, m4a — max 5MB)",children:[p===a.kind?"Uploading…":"Upload",e.jsx("input",{type:"file",accept:"audio/*",style:{display:"none"},onChange:re=>{var os;const Pe=(os=re.target.files)==null?void 0:os[0];re.target.value="",Pe&&Q(a.kind,Pe)}})]}),A&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>void W(a.kind),title:"Delete your file and go back to a built-in tone",children:"Reset"})]})]},a.kind)}),M&&e.jsx("div",{className:"config-sound-error",children:M})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.externalEditor"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:o("config:general.externalEditorPlaceholder"),value:u.externalEditorCommand||"",onChange:a=>w.updateSettings({externalEditorCommand:a.target.value})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.tabTitle"),query:t})}),e.jsx("input",{type:"text",className:"config-input",placeholder:o("config:general.tabTitlePlaceholder"),value:u.tabTitle||"",onChange:a=>w.updateSettings({tabTitle:a.target.value})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:general.language"),query:t})}),e.jsx(Ce,{options:Je,value:localStorage.getItem("tide-commander-language-mode")==="manual"?((ns=Je.find(a=>a.value!=="auto"&&We.language.startsWith(a.value.split("-")[0])))==null?void 0:ns.value)||"en":"auto",onChange:a=>{var A;if(a==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const B=navigator.language,le=((A=Je.find(fe=>fe.value!=="auto"&&B.startsWith(fe.value.split("-")[0])))==null?void 0:A.value)||"en";We.changeLanguage(le)}else localStorage.setItem("tide-commander-language-mode","manual"),We.changeLanguage(a)}})]})]}),_("agentNames")&&e.jsx(q,{title:o("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:G&&_("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children:pe.length>0?o("config:agentNames.customConfigured",{count:pe.length}):o("config:agentNames.usingDefaults")}),e.jsxs("div",{className:"agent-names-input-row",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",placeholder:o("config:agentNames.addPlaceholder"),value:se,onChange:a=>ae(a.target.value),onKeyDown:a=>{a.key==="Enter"&&De()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:De,disabled:!se.trim(),title:o("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:Ke.map((a,A)=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:a}),pe.length>0&&e.jsx("button",{className:"agent-name-remove",onClick:()=>f(a),title:o("common:buttons.remove"),children:"x"})]},`${a}-${A}`))}),pe.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:K,children:o("common:buttons.resetToDefaults")})]})}),_("defaultClass")&&e.jsx(q,{title:"Default Spawn Class",storageKey:"defaultClass",defaultOpen:!1,forceOpen:G&&_("defaultClass"),children:e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-hint",children:'Class pre-selected when the spawn modal opens. "Random" picks a different class each time.'}),e.jsxs("div",{className:"agent-names-list",style:{flexWrap:"wrap",gap:"6px",marginTop:"8px"},children:[e.jsx("div",{className:`agent-name-chip${k==="random"?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m("random"),Fe(_e.DEFAULT_AGENT_CLASS,"random")},children:e.jsx("span",{className:"agent-name-text",children:"🎲 Random"})}),Object.entries(jt).map(([a,A])=>e.jsx("div",{className:`agent-name-chip${k===a?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m(a),Fe(_e.DEFAULT_AGENT_CLASS,a)},children:e.jsxs("span",{className:"agent-name-text",children:[A.icon," ",a.charAt(0).toUpperCase()+a.slice(1)]})},a)),N.map(a=>e.jsx("div",{className:`agent-name-chip${k===a.id?" agent-name-chip--selected":""}`,style:{cursor:"pointer",userSelect:"none"},onClick:()=>{m(a.id),Fe(_e.DEFAULT_AGENT_CLASS,a.id)},children:e.jsxs("span",{className:"agent-name-text",children:[a.icon," ",a.name]})},a.id))]})]})}),_("appearance")&&e.jsx(q,{title:o("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:G&&_("appearance"),children:e.jsx(oa,{})}),_("connection")&&e.jsxs(q,{title:o("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:G&&_("connection"),children:[e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:connection.backendUrl"),query:t})}),e.jsx("div",{className:"backend-urls-list",children:V.map((a,A)=>e.jsxs("div",{className:"backend-url-row",children:[e.jsx("span",{className:"backend-url-priority",title:o("config:connection.priorityLabel",{defaultValue:"Priority"}),children:A+1}),e.jsx("span",{className:"backend-url-text",title:a,children:a}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>es(A,-1),disabled:A===0,title:o("config:connection.moveUp",{defaultValue:"Move up"}),children:"↑"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>es(A,1),disabled:A===V.length-1,title:o("config:connection.moveDown",{defaultValue:"Move down"}),children:"↓"}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>je(A),title:o("common:buttons.remove"),children:"x"})]},`${a}-${A}`))}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:H,onChange:a=>ne(a.target.value),placeholder:o("config:connection.addUrlPlaceholder",{defaultValue:"http://host:port"}),onKeyDown:a=>{a.key==="Enter"&&ce()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:ce,disabled:!H.trim(),title:o("config:connection.addUrl",{defaultValue:"Add URL"}),children:"+"}),$&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:Cs,title:o("config:connection.saveAndReconnect"),children:o("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:o("config:connection.urlsHint",{defaultValue:"Tried in order on connect; the first reachable host wins. Leave empty for auto-detect."})})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:connection.authToken"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:O?"text":"password",className:"config-input config-input-full",value:j,onChange:a=>As(a.target.value),placeholder:o("config:connection.tokenPlaceholder"),onKeyDown:a=>{a.key==="Enter"&&z&&ss()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>D(!O),title:o(O?"config:connection.hideToken":"config:connection.showToken"),children:e.jsx(I,{name:O?"eye-closed":"eye",size:14})}),z&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:ss,title:o("config:connection.saveAndReconnect"),children:o("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:o("config:connection.tokenRequired")})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:connection.codexBinaryPath"),query:t})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:Te,onChange:a=>Ts(a.target.value),placeholder:o("config:connection.codexBinaryPathPlaceholder"),onKeyDown:a=>{a.key==="Enter"&&ge&&ts()}}),ge&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:ts,children:o("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:o("config:connection.codexBinaryPathHint")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("common:buttons.reconnect"),query:t})}),e.jsx("button",{className:"config-btn",onClick:()=>Ge(),title:"Force reconnect to server",children:o("common:buttons.reconnect")})]})]}),_("scene")&&e.jsxs(q,{title:o("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:G&&_("scene"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:scene.characterSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"3.0",step:"0.1",value:s.characterScale,onChange:a=>n({...s,characterScale:parseFloat(a.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.characterScale.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:scene.scale2d",{defaultValue:"2D Scale"}),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale2d,onChange:a=>n({...s,scale2d:parseFloat(a.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.scale2d.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:scene.scale3d",{defaultValue:"3D Scale"}),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale3d,onChange:a=>n({...s,scale3d:parseFloat(a.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.scale3d.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:scene.show2DTaskLabels",{defaultValue:"Show 2D task labels"}),query:t})}),e.jsx(ee,{checked:s.show2DTaskLabels,onChange:a=>n({...s,show2DTaskLabels:a})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:scene.time"),query:t})}),e.jsx(Ce,{options:Me,value:s.timeMode,onChange:a=>n({...s,timeMode:a}),iconOnly:!0})]})]}),_("terrain")&&e.jsxs(q,{title:o("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:G&&_("terrain"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.simpleMode",{defaultValue:"Simple Mode"}),query:t})}),e.jsx(ee,{checked:s.terrain.simpleMode??!1,onChange:a=>ve({simpleMode:a})})]}),e.jsx("div",{className:"terrain-icons",style:{opacity:s.terrain.simpleMode?.4:1,pointerEvents:s.terrain.simpleMode?"none":"auto"},children:ze.map(a=>e.jsx("button",{className:`terrain-icon-btn ${s.terrain[a.key]?"active":""}`,onClick:()=>Ps(a.key),title:a.label,children:a.icon},a.key))}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.fog"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.terrain.fogDensity,onChange:a=>ve({fogDensity:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.fogDensity===0?o("config:fogValues.off"):s.terrain.fogDensity<=1?o("config:fogValues.low"):o("config:fogValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.brightness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.2",max:"2",step:"0.1",value:s.terrain.brightness,onChange:a=>ve({brightness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.brightness<=.5?o("config:brightnessValues.dark"):s.terrain.brightness<=1.2?o("config:brightnessValues.normal"):o("config:brightnessValues.bright")})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.floor"),query:t})}),e.jsx(Ce,{options:Se,value:s.terrain.floorStyle,onChange:a=>ve({floorStyle:a}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.sky"),query:t})}),e.jsx("div",{className:"sky-color-selector",children:Ve.map(a=>e.jsx("button",{className:`sky-color-btn ${s.terrain.skyColor===a.value?"active":""}`,onClick:()=>ve({skyColor:a.value}),title:a.label,style:{background:a.color}},a.value??"auto"))})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:terrainSettings.battlefieldSize"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"30",max:"200",step:"10",value:s.terrain.battlefieldSize,onChange:a=>ve({battlefieldSize:parseInt(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.battlefieldSize})]})]}),_("modelStyle")&&e.jsxs(q,{title:o("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:G&&_("modelStyle"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.saturation"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.modelStyle.saturation,onChange:a=>we({saturation:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.saturation<=.3?o("config:saturationValues.gray"):s.modelStyle.saturation<=1.2?o("config:saturationValues.normal"):o("config:saturationValues.vivid")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.roughness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.roughness,onChange:a=>we({roughness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.roughness<0?o("config:roughnessValues.auto"):s.modelStyle.roughness<=.3?o("config:roughnessValues.glossy"):s.modelStyle.roughness<=.7?o("config:roughnessValues.normal"):o("config:roughnessValues.matte")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.metalness"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.metalness,onChange:a=>we({metalness:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.metalness<0?o("config:metalnessValues.auto"):s.modelStyle.metalness<=.3?o("config:metalnessValues.plastic"):s.modelStyle.metalness<=.7?o("config:metalnessValues.mixed"):o("config:metalnessValues.metal")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.glow"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"1",step:"0.05",value:s.modelStyle.emissiveBoost,onChange:a=>we({emissiveBoost:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.emissiveBoost<=.1?o("config:glowValues.off"):s.modelStyle.emissiveBoost<=.4?o("config:glowValues.low"):s.modelStyle.emissiveBoost<=.7?o("config:glowValues.med"):o("config:glowValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.reflections"),query:t})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"2",step:"0.1",value:s.modelStyle.envMapIntensity,onChange:a=>we({envMapIntensity:parseFloat(a.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.envMapIntensity<0?o("config:reflectionValues.auto"):s.modelStyle.envMapIntensity<=.3?o("config:reflectionValues.low"):s.modelStyle.envMapIntensity<=1?o("config:reflectionValues.normal"):o("config:reflectionValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.wireframe"),query:t})}),e.jsx(ee,{checked:s.modelStyle.wireframe,onChange:a=>we({wireframe:a})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:modelStyleSettings.colorMode"),query:t})}),e.jsx(Ce,{options:Ue,value:s.modelStyle.colorMode,onChange:a=>we({colorMode:a}),iconOnly:!0})]})]}),_("animations")&&e.jsxs(q,{title:o("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:G&&_("animations"),children:[e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:animationSettings.idle"),query:t})}),e.jsx(Ce,{options:Le,value:s.animations.idleAnimation,onChange:a=>as({idleAnimation:a}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:animationSettings.working"),query:t})}),e.jsx(Ce,{options:Le,value:s.animations.workingAnimation,onChange:a=>as({workingAnimation:a}),iconOnly:!0})]})]}),_("secrets")&&e.jsx(q,{title:o("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:G&&_("secrets"),children:e.jsx(Bt,{})}),_("claudeAccounts")&&e.jsx(q,{title:o("config:sections.claudeAccounts",{defaultValue:"Claude Accounts"}),storageKey:"claudeAccounts",defaultOpen:!1,forceOpen:G&&_("claudeAccounts"),children:e.jsx(vt,{})}),_("grokAccounts")&&e.jsx(q,{title:o("config:sections.grokAccounts",{defaultValue:"Grok Accounts"}),storageKey:"grokAccounts",defaultOpen:!1,forceOpen:G&&_("grokAccounts"),children:e.jsx(cs,{provider:"grok"})}),_("codexAccounts")&&e.jsx(q,{title:o("config:sections.codexAccounts",{defaultValue:"Codex Accounts"}),storageKey:"codexAccounts",defaultOpen:!1,forceOpen:G&&_("codexAccounts"),children:e.jsx(cs,{provider:"codex"})}),_("systemPrompt")&&e.jsx(q,{title:o("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:G&&_("systemPrompt"),children:e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(C,{text:o("config:systemPrompt.title"),query:t})}),e.jsx("button",{className:"config-button",onClick:()=>y(!0),children:o("config:systemPrompt.editPrompt")})]})}),_("data")&&e.jsx(q,{title:o("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:G&&_("data"),children:e.jsx(na,{})}),Ee&&e.jsx(q,{title:o("config:sections.integrations"),storageKey:"integrations",defaultOpen:!1,forceOpen:G&&Ee,children:e.jsx(ua,{onOpenModal:a=>{a==="whatsapp"?ue(!0):i==null||i(a)}})}),_("workflows")&&e.jsxs(q,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:G&&_("workflows"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"Create and manage automated workflow pipelines with visual state machine editor",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>r==null?void 0:r(),children:"Open Workflow Editor"})})]}),_("triggers")&&e.jsxs(q,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:G&&_("triggers"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"Create and manage event-driven triggers that fire agents with templates",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>g==null?void 0:g(),children:"Open Trigger Manager"})})]}),_("monitoring")&&e.jsxs(q,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:G&&_("monitoring"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"View event logs, trigger history, workflow traces, and system stats",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>d==null?void 0:d(),children:"Open Monitoring & Logs"})})]}),_("statistics")&&e.jsxs(q,{title:"Statistics",storageKey:"statistics",defaultOpen:!1,forceOpen:G&&_("statistics"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(C,{text:"View token usage charts and system-wide agent statistics",query:t})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>c==null?void 0:c(),children:"Open Statistics"})})]}),_("experimental")&&e.jsxs(q,{title:o("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:G&&_("experimental"),children:[e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Lightweight 2D top-down view for better performance",children:[e.jsx(C,{text:o("config:experimental.2dView"),query:t})," ",e.jsx(I,{name:"map",size:12})]}),e.jsx(ee,{checked:u.experimental2DView,onChange:a=>w.updateSettings({experimental2DView:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Voice assistant for hands-free agent control",children:[e.jsx(C,{text:o("config:experimental.voiceAssistant"),query:t})," ",e.jsx(I,{name:"microphone",size:12})]}),e.jsx(ee,{checked:u.experimentalVoiceAssistant,onChange:a=>w.updateSettings({experimentalVoiceAssistant:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Text-to-speech for reading agent responses",children:[e.jsx(C,{text:o("config:experimental.tts"),query:t})," ",e.jsx(I,{name:"speaker-on",size:12})]}),e.jsx(ee,{checked:u.experimentalTTS,onChange:a=>w.updateSettings({experimentalTTS:a})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Duplicate system prompt for improved LLM attention coverage. Increases input token usage.",children:e.jsx(C,{text:o("config:experimental.echoPrompt"),query:t})}),e.jsx(ee,{checked:u.experimentalEchoPrompt,onChange:async a=>{w.updateSettings({experimentalEchoPrompt:a});try{await Kt(a)}catch(A){console.error("Failed to sync echo prompt setting to server:",A)}}})]}),e.jsx("span",{className:"config-hint",children:o("config:experimental.hint")})]}),_("about")&&e.jsx(q,{title:o("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:G&&_("about"),children:e.jsx(ra,{})})]}),e.jsx(pa,{isOpen:T,onClose:()=>y(!1)}),e.jsx(fa,{isOpen:te,onClose:()=>oe(!1)}),e.jsx(wa,{isOpen:de,onClose:()=>ie(!1)}),e.jsx(La,{isOpen:he,onClose:()=>ke(!1)}),e.jsx(Da,{isOpen:Ae,onClose:()=>ue(!1),onOpenConfig:()=>oe(!0),onOpenNotifications:()=>ie(!0),onOpenHistory:()=>ke(!0)})]})}function Qa({onConfigChange:s,onToolChange:n,config:t,isOpen:i,onClose:d,onOpenBuildingModal:c,onOpenAreaExplorer:r,onOpenIntegrationsModal:g,onOpenMonitoringModal:o,onOpenStatisticsModal:u,onOpenWorkflowEditor:N,onOpenTriggerManager:k}){const{t:m}=X(["config","common"]),P=kt(),b=St(),E=Ct(),x=At(),p=Tt(),S=Array.from(P.values()),M=Array.from(b.values()),[F,Q]=l.useState(""),W=l.useRef(null);if(l.useEffect(()=>{const h=$=>{$.key==="Escape"&&i&&d()};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[i,d]),l.useEffect(()=>{if(i&&W.current){if(typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches)return;const $=setTimeout(()=>{var R;(R=W.current)==null||R.focus()},50);return()=>clearTimeout($)}},[i]),!i)return null;const J=h=>{n(p===h?null:h)},U=h=>{w.selectArea(x===h?null:h),n("select")},V=(h,$)=>{h.stopPropagation(),w.deleteArea($)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"toolbox-backdrop",onClick:d}),e.jsxs("aside",{className:"toolbox",children:[e.jsxs("div",{className:"toolbox-header",children:[e.jsx("span",{children:m("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:d,title:m("common:buttons.close"),children:"×"})]}),e.jsxs("div",{className:"toolbox-search",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]}),e.jsx("input",{ref:W,type:"text",placeholder:m("config:searchPlaceholder"),value:F,onChange:h=>Q(h.target.value),className:"toolbox-search-input"}),F&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>Q(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(q,{title:m("config:areas.title",{count:S.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${p==="select"?"active":""}`,onClick:()=>J("select"),title:m("config:tools.select"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"})})})}),e.jsx("button",{className:`tool-btn ${p==="rectangle"?"active":""}`,onClick:()=>J("rectangle"),title:m("config:tools.rectangle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"})})})}),e.jsx("button",{className:`tool-btn ${p==="circle"?"active":""}`,onClick:()=>J("circle"),title:m("config:tools.circle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("circle",{cx:"12",cy:"12",r:"9"})})})})]}),e.jsx("div",{className:"areas-list",children:S.length===0?e.jsx("div",{className:"areas-empty",children:m("config:areas.drawToCreate")}):S.map(h=>e.jsx(Ot,{area:h,isSelected:x===h.id,onClick:()=>U(h.id),onDelete:$=>V($,h.id)},h.id))})]})}),x&&e.jsx(Rt,{area:P.get(x),onClose:()=>w.selectArea(null),onOpenFolder:r}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(q,{title:m("config:buildings.title",{count:M.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:h=>{h.stopPropagation(),c==null||c()},title:m("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:M.length===0?e.jsx("div",{className:"buildings-empty",children:m("config:buildings.clickToAdd")}):M.map(h=>e.jsx(Lt,{building:h,isSelected:E.has(h.id),onClick:()=>{w.selectBuilding(E.has(h.id)?null:h.id)},onEdit:()=>c==null?void 0:c(h.id)},h.id))})})}),E.size===1&&(()=>{const h=Array.from(E)[0],$=b.get(h);return $?e.jsx(Dt,{building:$,onClose:()=>w.selectBuilding(null),onOpenModal:()=>c==null?void 0:c(h)}):null})(),e.jsx(Ga,{config:t,onChange:s,searchQuery:F,onOpenIntegrationsModal:g,onOpenMonitoringModal:o,onOpenStatisticsModal:u,onOpenWorkflowEditor:N,onOpenTriggerManager:k})]})]})]})}export{Qa as Toolbox};
@@ -1,5 +0,0 @@
1
- import{aw as ze,r as t,s as I,d as ye,ax as Ee,c as Oe,j as e,I as O,u as fe,ay as _e,az as Te,aA as Be,aB as Ue,aC as Ke,aD as We,a3 as De,aE as Ve,aF as Ge,aG as qe,aH as Je,z as Ye,m as Me,S as le,F as Xe,C as Qe,n as Ze,w as Ie,x as et,_ as tt,aI as st,an as X,aJ as nt}from"./main-CN0vutCJ.js";import{FileExplorerPanel as at}from"./index-gQjHBiGd.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-CBPuP1jE.js";const Se={status:"all",activity:"all",sort:"activity"},ct={"1h":3600*1e3,"6h":360*60*1e3,"24h":1440*60*1e3},Ae=20,me=3,lt={idle:"#4aff9e",working:"#4a9eff",waiting:"#ff9e4a",waiting_permission:"#ffcc00",error:"#ff4a4a",offline:"#888888",orphaned:"#ff9e4a"},ot=12e4;function rt(s){return s.trim().replace(/\r\n/g,`
2
- `)}function $e(s,a){return`${s}:${rt(a)}`}function it(s,a,c,f){if(s.uuid&&a.has(s.uuid))return!1;if(s.uuid)return!0;const p=s.isUserPrompt?"user":"assistant",d=$e(p,s.text),M=s.timestamp||0,A=c.get(d);return A!==void 0&&Math.abs(M-A)<=ot?!1:M>f}function dt({isOpen:s,agents:a}){const c=ze(),[f,p]=t.useState(new Map),d=t.useRef(new Set);t.useRef(a);const M=t.useMemo(()=>Array.from(a.keys()).sort().join(","),[a]),A=t.useMemo(()=>Array.from(a.values()).map(j=>`${j.id}:${j.sessionId||""}`).sort().join(","),[a]);t.useEffect(()=>{s||(d.current.clear(),p(new Map))},[s]),t.useEffect(()=>{if(!s)return;const j=new Set(Array.from(a.keys()));for(const i of d.current)j.has(i)||d.current.delete(i);let h=null;c>0&&(h=I.preserveOutputs(),d.current.clear());const v=async(i,k,$=0)=>{if(d.current.add(i.id),$>0&&await new Promise(x=>setTimeout(x,$)),p(x=>{const b=new Map(x);return b.set(i.id,{agentId:i.id,messages:[],loading:!0,hasMore:!1,totalCount:0}),b}),!i.sessionId){k&&k.length>0&&I.mergeOutputsWithHistory(i.id,[],k),p(x=>{const b=new Map(x);return b.set(i.id,{agentId:i.id,messages:[],loading:!1,hasMore:!1,totalCount:0}),b});return}try{const b=await(await Oe(ye(`/api/agents/${i.id}/history?limit=${Ee}&offset=0`))).json(),P=b.messages||[],W=P.length>0?Math.max(...P.map(w=>w.timestamp?new Date(w.timestamp).getTime():0)):0,J=new Set(P.map(w=>w.uuid).filter(w=>!!w)),V=new Map;for(const w of P){if(w.type!=="user"&&w.type!=="assistant")continue;const o=$e(w.type,w.content),L=w.timestamp?new Date(w.timestamp).getTime():0,K=V.get(o)??0;L>K&&V.set(o,L)}const G=I.getOutputs(i.id),U=(k&&k.length>0?[...k,...G]:G).filter(w=>it(w,J,V,W));I.clearOutputs(i.id);for(const w of U)I.addOutput(i.id,w);p(w=>{const o=new Map(w);return o.set(i.id,{agentId:i.id,messages:P,loading:!1,hasMore:b.hasMore||!1,totalCount:b.totalCount||0}),o})}catch(x){if(console.error(`Failed to load history for ${i.name}:`,x),k&&k.length>0){I.clearOutputs(i.id);for(const b of k)I.addOutput(i.id,b)}p(b=>{const P=new Map(b);return P.set(i.id,{agentId:i.id,messages:[],loading:!1,hasMore:!1,totalCount:0}),P})}},u=c>0?500:0,D=Array.from(a.values());for(const i of D)if(!d.current.has(i.id)){const k=h==null?void 0:h.get(i.id);v(i,k,u)}},[s,M,A,c]);const R=t.useRef(a),N=t.useRef(f);R.current=a,N.current=f;const C=t.useCallback(async j=>{const h=R.current.get(j),v=N.current.get(j);if(!(h!=null&&h.sessionId)||!v||!v.hasMore)return;const u=v.messages.length;try{const i=await(await fetch(ye(`/api/agents/${j}/history?limit=${Ee}&offset=${u}`))).json();i.messages&&i.messages.length>0&&p(k=>{const $=new Map(k),x=k.get(j);return x&&$.set(j,{...x,messages:[...i.messages,...x.messages],hasMore:i.hasMore||!1}),$})}catch(D){console.error(`Failed to load more history for agent ${j}:`,D)}},[]),E=t.useCallback(j=>{d.current.delete(j),p(h=>{const v=new Map(h),u=h.get(j);return u&&v.set(j,{...u,messages:[],hasMore:!1,totalCount:0,loading:!1}),v})},[]);return{histories:f,loadMoreHistory:C,clearAgentHistory:E}}function ut({command:s,onCommandChange:a,useTextarea:c,forceTextarea:f,onForceTextarea:p,onSend:d,canSend:M,attachedFiles:A,onAddFile:R,onRemoveFile:N,uploadFile:C,onAddPastedText:E,placeholder:j="Message...",className:h="",compact:v=!1,inputRef:u}){const D=t.useRef(null),i=t.useRef(null),k=t.useRef(c);t.useEffect(()=>{if(c&&!k.current&&i.current){const o=i.current;o.focus(),o.selectionStart=o.selectionEnd=o.value.length}k.current=c},[c]),t.useEffect(()=>{const o=i.current;if(!o||!c)return;o.style.height="auto";const L=v?120:180,K=Math.min(o.scrollHeight,L);o.style.height=`${K}px`},[s,c,v]);const $=t.useCallback(async o=>{const L=o.clipboardData.items;for(const _ of L)if(_.type.startsWith("image/")){o.preventDefault();const F=_.getAsFile();if(F){const H=await C(F);H&&R(H)}return}const K=o.clipboardData.files;if(K.length>0){o.preventDefault();for(const _ of K){const F=await C(_);F&&R(F)}return}const B=o.clipboardData.getData("text"),te=(B.match(/\n/g)||[]).length+1;if(te>5){o.preventDefault();const F=`[Pasted text #${E(B)} +${te} lines]`,H=o.target,se=H.selectionStart||0,ae=H.selectionEnd||0,ne=s.slice(0,se)+F+s.slice(ae);a(ne),c||p(!0)}},[s,a,c,p,C,R,E]),x=t.useCallback(async o=>{const L=o.target.files;if(L){for(const K of L){const B=await C(K);B&&R(B)}D.current&&(D.current.value="")}},[C,R]),b=t.useCallback(o=>{if(o.key==="Enter"&&o.shiftKey){c||(o.preventDefault(),p(!0));return}o.key==="Enter"&&(o.preventDefault(),d())},[c,p,d]),P=t.useCallback(o=>{},[]),W=t.useCallback(o=>{o.button===1&&(o.preventDefault(),o.stopPropagation())},[]),J=t.useCallback(o=>{i.current=o,u==null||u(o)},[u]),V=v?"agent-panel-input":"guake-input",G=v?"agent-panel-input-container":"guake-input-container",Q=v?"agent-panel-attach-btn":"guake-attach-btn",U=v?"agent-panel-send-btn":"",w=c?v?"agent-panel-input-expanded":"guake-input-expanded":"";return e.jsxs(e.Fragment,{children:[A.length>0&&e.jsx("div",{className:v?"agent-panel-attachments":"guake-attachments",children:A.map(o=>e.jsxs("div",{className:`${v?"agent-panel-attachment":"guake-attachment"} ${o.isImage?"is-image":""}`,children:[e.jsx("span",{className:v?"agent-panel-attachment-icon":"guake-attachment-icon",children:e.jsx(O,{name:o.isImage?"file":"paperclip",size:12})}),e.jsx("span",{className:v?"agent-panel-attachment-name":"guake-attachment-name",title:o.path,children:o.name}),!v&&e.jsxs("span",{className:"guake-attachment-size",children:["(",Math.round(o.size/1024),"KB)"]}),e.jsx("button",{className:v?"agent-panel-attachment-remove":"guake-attachment-remove",onClick:()=>N(o.id),title:"Remove",children:"×"})]},o.id))}),e.jsxs("div",{className:`${V} ${w} ${h}`,children:[e.jsx("input",{ref:D,type:"file",multiple:!0,onChange:x,style:{display:"none"},accept:"*"}),e.jsxs("div",{className:G,onAuxClick:W,children:[e.jsx("button",{className:Q,onClick:()=>{var o;return(o=D.current)==null?void 0:o.click()},title:"Attach file (or paste image)",children:e.jsx(O,{name:"paperclip",size:14})}),c?e.jsx("textarea",{ref:J,placeholder:j,value:s,onChange:o=>a(o.target.value),onKeyDown:b,onPaste:$,onMouseDown:P}):e.jsx("input",{ref:u,type:"text",placeholder:j,value:s,onChange:o=>a(o.target.value),onKeyDown:b,onPaste:$,onMouseDown:P}),e.jsx("button",{className:U,onClick:d,disabled:!M,title:"Send",children:e.jsx(O,{name:"send",size:14})})]})]})]})}function mt(s){const a=Math.floor(s/1e3),c=Math.floor(a/60),f=a%60;return`${c}:${f.toString().padStart(2,"0")}`}const ft=t.memo(function({agentId:a,isWorking:c,timestamp:f}){const{t:p}=fe(["terminal"]),[d,M]=t.useState(0);return t.useEffect(()=>{if(!c||!f){M(0);return}M(Date.now()-f);const A=setInterval(()=>{M(Date.now()-f)},1e3);return()=>clearInterval(A)},[c,f]),c?e.jsxs("div",{className:"guake-stop-bar",children:[e.jsx("span",{className:"guake-elapsed-timer",children:mt(d)}),e.jsxs("button",{className:"guake-stop-btn",onClick:()=>I.stopAgent(a),title:p("terminal:input.stopOperation"),children:[e.jsx("span",{className:"stop-icon",children:e.jsx(O,{name:"stop",size:12,weight:"fill"})}),e.jsx("span",{className:"stop-label",children:p("terminal:input.stop")})]})]}):null});function pt({agent:s,history:a,outputs:c,isExpanded:f,isFocused:p,advancedView:d,onExpand:M,onFocus:A,inputRef:R,onLoadMore:N,onClearHistory:C}){const{t:E}=fe(["terminal","common"]),j=_e(s.id),h=t.useRef(null),[v,u]=t.useState(!1),D=t.useRef(0),i=t.useRef(!1),[k,$]=t.useState(!0),[x,b]=t.useState(!1),[P,W]=t.useState(null),[J,V]=t.useState(null),[G,Q]=t.useState(null);Te(`commander-image-modal-${s.id}`,P!==null,()=>W(null));const{command:U,setCommand:w,forceTextarea:o,setForceTextarea:L,useTextarea:K,setPastedTexts:B,incrementPastedCount:te,resetPastedCount:_,attachedFiles:F,setAttachedFiles:H,removeAttachedFile:se,uploadFile:ae,expandPastedTexts:ne}=Be({selectedAgentId:s.id}),ce=U.trim().length>0||F.length>0,n=Ue({outputs:c,viewMode:d?"advanced":"simple"}),l=t.useMemo(()=>{const S=Ke(s);return{usedPercent:S.usedPercent,freePercent:S.freePercent,hasData:!!s.contextStats,totalTokens:S.totalTokens,contextWindow:S.contextWindow}},[s.contextStats,s.contextUsed,s.contextLimit]),g=t.useCallback(()=>{!v&&(a!=null&&a.hasMore)&&N&&(u(!0),D.current=h.current?h.current.scrollHeight-h.current.scrollTop:0,N())},[v,a==null?void 0:a.hasMore,N]);t.useEffect(()=>{v&&a&&!a.loading&&u(!1)},[a,v]);const m=t.useCallback(()=>{i.current=!0,$(!1)},[]),T=t.useRef(f),Z=t.useRef(p);t.useEffect(()=>{(f&&!T.current||p&&!Z.current)&&(i.current=!1,$(!0),b(!0)),T.current=f,Z.current=p},[f,p]);const ee=t.useRef(a==null?void 0:a.loading);t.useEffect(()=>{ee.current&&!(a!=null&&a.loading)&&(i.current=!1,$(!0),b(!0)),ee.current=a==null?void 0:a.loading},[a==null?void 0:a.loading]),t.useEffect(()=>{if(!x)return;const S=h.current;if(!S)return;const y=performance.now();let z=0,ue=-1,be;const Re=()=>{const{scrollTop:Fe,scrollHeight:Ne,clientHeight:Le}=S,He=Ne-Fe-Le<=2;if(Math.abs(Ne-ue)<=1&&He?z+=1:z=0,ue=Ne,z>=3){b(!1);return}if(performance.now()-y>5e3){b(!1);return}be=requestAnimationFrame(Re)};return be=requestAnimationFrame(Re),()=>cancelAnimationFrame(be)},[x]),t.useEffect(()=>{i.current||$(!0)},[n.length]);const q=t.useCallback(()=>!1,[]),ie=t.useCallback(S=>{const y=te();return B(z=>new Map(z).set(y,S)),y},[te,B]),he=t.useCallback(S=>{H(y=>[...y,S])},[H]),xe=t.useCallback(()=>{if(!ce)return;if(U.trim()==="/clear"&&F.length===0){I.clearContext(s.id),C(),w(""),L(!1),B(new Map),H([]),_();return}let S=ne(U.trim());if(F.length>0){const y=F.map(z=>z.isImage?`[Image: ${z.path}]`:`[File: ${z.path}]`).join(`
3
- `);S=S?`${S}
4
-
5
- ${y}`:y}I.sendCommand(s.id,S),i.current=!1,$(!0),b(!0),w(""),L(!1),B(new Map),H([]),_()},[s.id,U,ce,F,ne,C,_,w,L,B,H]),ge=t.useCallback((S,y)=>{W({url:S,name:y})},[]),ve=t.useCallback((S,y)=>{const z=We(S,s.cwd),ue=z.line?{...y||{},targetLine:z.line}:y;I.setFileViewerPath(z.path,ue,s.cwd)},[s.cwd]),je=t.useCallback((S,y)=>{V({command:S,output:y,isLive:y==="Running..."})},[]),we=t.useCallback(S=>{Q(S)},[]),Ce=t.useCallback(()=>{b(!1),i.current=!0,$(!1)},[]),ke=t.useCallback(()=>W(null),[]),r=t.useCallback(()=>V(null),[]),Y=t.useCallback(()=>Q(null),[]),de=t.useCallback(S=>{S.stopPropagation(),M()},[M]),oe=lt[s.status]||"#888888",re=(a==null?void 0:a.messages)||[];return e.jsxs("div",{className:`agent-panel ${s.status==="working"?"working":""} ${f?"expanded":""} ${p?"focused":""}`,onClick:p?void 0:A,children:[e.jsxs("div",{className:"agent-panel-header",onClick:p?A:void 0,children:[e.jsxs("div",{className:"agent-panel-info",children:[e.jsx("span",{className:"agent-panel-status",style:{background:oe},title:s.status}),e.jsxs("span",{className:"agent-panel-name",children:[(s.isBoss||s.class==="boss")&&e.jsx("span",{className:"agent-panel-boss-crown",children:e.jsx(O,{name:"crown",size:14})}),s.name]}),e.jsx("span",{className:`agent-panel-status-label ${s.status}`,children:s.status}),e.jsx("span",{className:"agent-panel-class",children:s.class}),e.jsx("span",{className:`agent-panel-provider ${s.provider==="codex"?"codex":s.provider==="opencode"?"opencode":s.provider==="grok"?"grok":"claude"}`,children:s.provider||"claude"}),e.jsxs("span",{className:"agent-panel-id",title:`ID: ${s.id}`,children:["[",s.id.substring(0,4),"]"]}),s.taskLabel?e.jsxs("div",{className:"agent-panel-task agent-panel-task-label",title:s.taskLabel,children:[e.jsx(O,{name:"task",size:12})," ",s.taskLabel]}):s.currentTask?e.jsxs("div",{className:"agent-panel-task",title:s.currentTask,children:[s.currentTask.substring(0,40),"..."]}):null]}),e.jsxs("div",{className:"agent-panel-context",title:`Context: ${Math.round(l.usedPercent)}% used (${De(l.totalTokens)} / ${De(l.contextWindow)})`,children:[e.jsx("div",{className:"agent-panel-context-bar",style:{background:l.freePercent<20?"#ff4a4a":l.freePercent<50?"#ff9e4a":"#4aff9e",width:`${l.freePercent}%`}}),e.jsxs("span",{className:"agent-panel-context-text",children:[Math.round(l.freePercent),"%"]})]}),e.jsx("div",{className:"agent-panel-actions",children:e.jsx("button",{className:"agent-panel-expand",onClick:de,title:E(f?"commander.collapsePanel":"commander.expandPanel"),children:f?e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("polyline",{points:"4 14 10 14 10 20"}),e.jsx("polyline",{points:"20 10 14 10 14 4"}),e.jsx("line",{x1:"14",y1:"10",x2:"21",y2:"3"}),e.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]}):e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("polyline",{points:"15 3 21 3 21 9"}),e.jsx("polyline",{points:"9 21 3 21 3 15"}),e.jsx("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),e.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})})})]}),e.jsx("div",{className:"agent-panel-content",ref:h,children:a!=null&&a.loading?e.jsx("div",{className:"agent-panel-loading",children:E("common:status.loading")}):e.jsx(e.Fragment,{children:!re.length&&!n.length?e.jsxs("div",{className:"agent-panel-empty",children:[E("commander.noMessages"),!s.sessionId&&e.jsx("div",{style:{fontSize:"10px",color:"#666"},children:E("commander.noSessionId")})]}):e.jsx(Ve,{historyMessages:re,liveOutputs:n,agentId:s.id,viewMode:d?"advanced":"simple",selectedMessageIndex:null,isMessageSelected:q,onImageClick:ge,onFileClick:ve,onBashClick:je,onViewMarkdown:we,scrollContainerRef:h,onScrollTopReached:g,isLoadingMore:v,hasMore:a==null?void 0:a.hasMore,shouldAutoScroll:k,onUserScroll:m,pinToBottom:x,onPinCancel:Ce,isLoadingHistory:a==null?void 0:a.loading})})}),e.jsxs("div",{className:`guake-input-wrapper ${s.status==="working"?"has-stop-btn is-working":""}`,children:[e.jsx(ft,{agentId:s.id,isWorking:s.status==="working",timestamp:j==null?void 0:j.timestamp}),e.jsx(ut,{command:U,onCommandChange:w,useTextarea:K,forceTextarea:o,onForceTextarea:L,onSend:xe,canSend:ce,attachedFiles:F,onAddFile:he,onRemoveFile:se,uploadFile:ae,onAddPastedText:ie,placeholder:E("commander.command",{name:s.name}),compact:!1,inputRef:R})]}),P&&e.jsx(Ge,{url:P.url,name:P.name,onClose:ke}),J&&e.jsx(qe,{state:J,onClose:r}),e.jsx(Je,{agent:s,content:G,onClose:Y})]})}function ht({currentArea:s,onClose:a}){const{t:c}=fe(["terminal","common"]),[f,p]=t.useState(()=>{const u=new Set(Array.from(I.getState().agents.values()).map(D=>D.name));return Ye.find(D=>!u.has(D))||`Agent-${Date.now().toString(36)}`}),[d,M]=t.useState(()=>Me(le.LAST_CWD)),[A,R]=t.useState("scout"),[N,C]=t.useState("claude"),[E,j]=t.useState(!1),h=()=>{if(!f.trim()||!d.trim())return;j(!0),Ie(le.LAST_CWD,d);let u;s&&(u={x:s.center.x,z:s.center.z}),I.spawnAgent(f.trim(),A,d.trim(),u,void 0,void 0,void 0,void 0,N),setTimeout(()=>{a()},500)},v=u=>{u.key==="Enter"&&!u.shiftKey&&(u.preventDefault(),h()),u.key==="Escape"&&a()};return e.jsx("div",{className:"commander-spawn-overlay",onClick:a,children:e.jsxs("div",{className:"commander-spawn-form",onClick:u=>u.stopPropagation(),children:[e.jsxs("div",{className:"commander-spawn-header",children:[e.jsx("h3",{children:c("spawn.addNewAgent")}),s&&e.jsxs("span",{className:"commander-spawn-area",children:[e.jsx("span",{className:"commander-spawn-area-dot",style:{background:s.color}}),s.name]})]}),e.jsxs("div",{className:"commander-spawn-body",children:[e.jsxs("div",{className:"commander-spawn-field",children:[e.jsx("label",{children:c("common:labels.name")}),e.jsx("input",{type:"text",value:f,onChange:u=>p(u.target.value),onKeyDown:v,autoFocus:!0})]}),e.jsxs("div",{className:"commander-spawn-field",children:[e.jsx("label",{children:c("common:labels.workingDirectory")}),e.jsx(Xe,{value:d,onChange:M,onSubmit:h,placeholder:c("spawn.workingDirPlaceholder"),directoriesOnly:!0})]}),e.jsxs("div",{className:"commander-spawn-field",children:[e.jsx("label",{children:c("common:labels.class")}),e.jsx("div",{className:"commander-spawn-classes",children:Qe.map(u=>e.jsxs("button",{className:`commander-spawn-class ${A===u.id?"selected":""}`,onClick:()=>R(u.id),children:[e.jsx(Ze,{classId:u.id,size:18,className:"commander-spawn-class-icon"}),e.jsx("span",{children:u.name})]},u.id))})]}),e.jsxs("div",{className:"commander-spawn-field",children:[e.jsx("label",{children:c("common:labels.runtime")}),e.jsxs("div",{className:"commander-spawn-classes",children:[e.jsxs("button",{className:`commander-spawn-class ${N==="claude"?"selected":""}`,onClick:()=>C("claude"),children:[e.jsx("span",{className:"commander-spawn-class-icon",children:e.jsx(O,{name:"brain",size:14})}),e.jsx("span",{children:"Claude"})]}),e.jsxs("button",{className:`commander-spawn-class ${N==="codex"?"selected":""}`,onClick:()=>C("codex"),children:[e.jsx("span",{className:"commander-spawn-class-icon",children:e.jsx(O,{name:"gear",size:14})}),e.jsx("span",{children:"Codex"})]}),e.jsxs("button",{className:`commander-spawn-class ${N==="opencode"?"selected":""}`,onClick:()=>C("opencode"),children:[e.jsx("span",{className:"commander-spawn-class-icon",children:e.jsx(O,{name:"status-pending",size:12,weight:"fill",color:"#4ade80"})}),e.jsx("span",{children:"OpenCode"})]}),e.jsxs("button",{className:`commander-spawn-class ${N==="grok"?"selected":""}`,onClick:()=>C("grok"),children:[e.jsx("span",{className:"commander-spawn-class-icon",children:e.jsx(O,{name:"status-pending",size:12,weight:"fill",color:"#6366f1"})}),e.jsx("span",{children:"Grok"})]})]})]})]}),e.jsxs("div",{className:"commander-spawn-footer",children:[e.jsx("button",{className:"commander-spawn-cancel",onClick:a,children:c("common:buttons.cancel")}),e.jsx("button",{className:"commander-spawn-submit",onClick:h,disabled:!f.trim()||!d.trim()||E,children:c(E?"common:buttons.deploying":"common:buttons.deploy")})]})]})})}const Pe=t.memo(function({agent:a,history:c,isExpanded:f,isFocused:p,advancedView:d,index:M,onExpand:A,onCollapse:R,onFocus:N,onInputRef:C,onLoadMore:E,onClearHistory:j}){const h=nt(a.id),v=t.useCallback(()=>{f?R():A(a.id)},[a.id,f,A,R]),u=t.useCallback(()=>{N(p?-1:M)},[M,p,N]),D=t.useCallback($=>{C(a.id,$)},[a.id,C]),i=t.useCallback(()=>{E(a.id)},[a.id,E]),k=t.useCallback(()=>{j(a.id)},[a.id,j]);return e.jsx(pt,{agent:a,history:c,outputs:h,isExpanded:f,isFocused:p,advancedView:d,onExpand:v,onFocus:u,inputRef:D,onLoadMore:i,onClearHistory:k})});function Ct({isOpen:s,onClose:a}){const{t:c}=fe(["terminal","common"]),f=et(),p=tt(),[d,M]=t.useState(()=>Me(le.COMMANDER_TAB,"all")),[A,R]=t.useState(0),[N,C]=t.useState(null),E=t.useRef(null),[j,h]=t.useState(0),[v,u]=t.useState(!1),[D,i]=t.useState(null),[k,$]=t.useState(!1),[x,b]=t.useState(()=>{try{const n=Me(le.COMMANDER_FILTERS,"");if(n)return{...Se,...JSON.parse(n)}}catch{}return Se}),P=t.useRef(new Map),W=t.useRef([]),J=t.useRef(0),V=t.useRef([]),G=t.useRef(d),{histories:Q,loadMoreHistory:U,clearAgentHistory:w}=dt({isOpen:s,agents:f});t.useEffect(()=>{s||(C(null),h(0),u(!1))},[s]);const o=t.useMemo(()=>{const n=Array.from(p.values()).sort((g,m)=>g.name.localeCompare(m.name)),l=[{id:"all",name:c("common:labels.all")}];for(const g of n)l.push({id:g.id,name:g.name,color:g.color});return l.push({id:"unassigned",name:c("commander.unassigned")}),l},[p]),L=t.useMemo(()=>d==="all"||d==="unassigned"?null:p.get(d)||null,[d,p]),K=t.useMemo(()=>{const n=new Map;n.set("all",f.size);let l=0;for(const g of f.values()){const m=I.getAreaForAgent(g.id);m?n.set(m.id,(n.get(m.id)||0)+1):l++}return n.set("unassigned",l),n},[f]),B=x.status!=="all"||x.activity!=="all"||x.sort!=="activity",te=(x.status!=="all"?1:0)+(x.activity!=="all"?1:0)+(x.sort!=="activity"?1:0),_=t.useMemo(()=>{const n=m=>m.isBoss===!0||m.class==="boss",l=Date.now();let g=Array.from(f.values());if(d==="unassigned"?g=g.filter(m=>!I.getAreaForAgent(m.id)):d!=="all"&&(g=g.filter(m=>{const T=I.getAreaForAgent(m.id);return(T==null?void 0:T.id)===d})),x.status!=="all"&&(g=g.filter(m=>{switch(x.status){case"working":return m.status==="working";case"idle":return m.status==="idle";case"error":return m.status==="error"||m.status==="waiting"||m.status==="waiting_permission";case"offline":return m.status==="offline"||m.status==="orphaned";default:return!0}})),x.activity!=="all"){const m=ct[x.activity];g=g.filter(T=>l-(T.lastActivity||0)<m)}return g.sort((m,T)=>{var Z,ee;if(n(m)&&!n(T))return-1;if(!n(m)&&n(T))return 1;switch(x.sort){case"activity":return(T.lastActivity||0)-(m.lastActivity||0);case"name":return m.name.localeCompare(T.name);case"created":return(m.createdAt||0)-(T.createdAt||0);case"context":{const q=((Z=m.contextStats)==null?void 0:Z.usedPercent)??(m.contextUsed||0)/(m.contextLimit||2e5)*100;return(((ee=T.contextStats)==null?void 0:ee.usedPercent)??(T.contextUsed||0)/(T.contextLimit||2e5)*100)-q}default:return(T.lastActivity||0)-(m.lastActivity||0)}}),g},[f,d,x]),F=Math.ceil(_.length/Ae),H=t.useMemo(()=>_.slice(A*Ae,(A+1)*Ae),[_,A]);W.current=H,E.current=N,J.current=j,V.current=o,G.current=d,Te("commander-expanded",N!==null,()=>C(null));const se=st();t.useEffect(()=>{s&&se&&(C(se),I.clearCommanderExpandRequest())},[s,se]);const ae=t.useCallback(()=>C(null),[]),ne=t.useCallback(n=>C(n),[]),ce=t.useCallback(n=>h(n),[]),pe=t.useCallback((n,l)=>{l?P.current.set(n,l):P.current.delete(n)},[]);return t.useEffect(()=>{R(0),Ie(le.COMMANDER_TAB,d)},[d]),t.useEffect(()=>{Ie(le.COMMANDER_FILTERS,JSON.stringify(x)),R(0)},[x]),t.useEffect(()=>{var l;if(!s||window.matchMedia("(pointer: coarse)").matches)return;const n=N||((l=W.current[j])==null?void 0:l.id);if(n){const g=P.current.get(n);g&&document.activeElement!==g&&setTimeout(()=>g.focus(),50)}},[s,j,N]),t.useEffect(()=>{if(!s)return;const n=l=>{const g=I.getShortcuts(),m=l.target,T=m.tagName==="INPUT"||m.tagName==="TEXTAREA",Z=W.current,ee=Z.length-1,q=E.current,ie=g.find(r=>r.id==="commander-close");if(X(l,ie)){const{fileViewerPath:r,contextModalAgentId:Y}=I.getState();if(r||Y)return;l.preventDefault(),l.stopImmediatePropagation(),q?C(null):a();return}const he=g.find(r=>r.id==="commander-vim-left");if(X(l,he)&&!q){l.preventDefault(),h(r=>r>0?r-1:r);return}const xe=g.find(r=>r.id==="commander-vim-right");if(X(l,xe)&&!q){l.preventDefault(),h(r=>r<ee?r+1:r);return}const ge=g.find(r=>r.id==="commander-vim-up");if(X(l,ge)&&!q){l.preventDefault(),h(r=>r>=me?r-me:r);return}const ve=g.find(r=>r.id==="commander-vim-down");if(X(l,ve)&&!q){l.preventDefault(),h(r=>r+me<=ee?r+me:r);return}const je=g.find(r=>r.id==="commander-expand");if(X(l,je)){if(l.preventDefault(),q)C(null);else{const r=Z[J.current];r&&C(r.id)}return}const we=g.find(r=>r.id==="commander-new-agent");if(X(l,we)){l.preventDefault(),u(!0);return}const Ce=g.find(r=>r.id==="commander-next-tab"),ke=g.find(r=>r.id==="commander-prev-tab");if(!T){const r=V.current;if(X(l,Ce)){const Y=I.getState().latestNotificationAgentId;if(Y){if(l.preventDefault(),l.stopPropagation(),!I.getState().agents.get(Y)){I.setLatestNotificationAgentId(null);return}const y=I.getAreaForAgent(Y);y&&r.some(z=>z.id===y.id)?M(y.id):M("unassigned"),C(Y),h(0),R(0),I.setLatestNotificationAgentId(null);return}l.preventDefault(),l.stopPropagation();const oe=(r.findIndex(re=>re.id===G.current)+1)%r.length;M(r[oe].id),h(0);return}if(X(l,ke)){l.preventDefault(),l.stopPropagation();const de=(r.findIndex(oe=>oe.id===G.current)-1+r.length)%r.length;M(r[de].id),h(0);return}}};return document.addEventListener("keydown",n,!0),()=>document.removeEventListener("keydown",n,!0)},[s,a]),s?e.jsx("div",{className:"commander-overlay",onClick:a,children:e.jsxs("div",{className:"commander-view",onClick:n=>n.stopPropagation(),children:[e.jsxs("div",{className:"commander-header",children:[e.jsxs("div",{className:"commander-title-section",children:[e.jsx("h2",{className:"commander-title",children:c("commander.title")}),e.jsx("span",{className:"commander-shortcuts",children:c("commander.shortcuts")})]}),e.jsxs("div",{className:"commander-controls",children:[e.jsx("button",{className:`commander-view-toggle ${k?"active":""}`,onClick:()=>$(!k),title:c(k?"commander.simple":"commander.advanced"),children:k?e.jsxs(e.Fragment,{children:[e.jsx(O,{name:"target",size:12})," ",c("commander.advanced")]}):e.jsxs(e.Fragment,{children:[e.jsx(O,{name:"status-pending",size:12})," ",c("commander.simple")]})}),e.jsx("button",{className:"commander-add-btn",onClick:()=>u(!0),title:c("commander.addAgent"),children:c("commander.addAgent")}),e.jsx("button",{className:"commander-close",onClick:a,children:c("commander.close")})]})]}),e.jsx("div",{className:"commander-tabs",children:o.map(n=>{const l=n.id!=="all"&&n.id!=="unassigned"?p.get(n.id):null,g=l&&l.directories&&l.directories.length>0;return e.jsxs("button",{className:`commander-tab ${d===n.id?"active":""}`,onClick:()=>{M(n.id),h(0)},style:n.color?{borderBottomColor:d===n.id?n.color:"transparent"}:void 0,children:[n.color&&e.jsx("span",{className:"commander-tab-dot",style:{background:n.color}}),e.jsx("span",{children:n.name}),e.jsx("span",{className:"commander-tab-count",children:K.get(n.id)||0}),g&&e.jsx("span",{className:"commander-tab-folder",onClick:m=>{m.stopPropagation(),i(n.id)},title:c("commander.openFileExplorer"),children:e.jsx(O,{name:"folder",size:12})})]},n.id)})}),e.jsxs("div",{className:"commander-filters",children:[e.jsxs("div",{className:"commander-filter-group",children:[e.jsx("span",{className:"commander-filter-label",children:c("commander.filters.status")}),["all","working","idle","error","offline"].map(n=>e.jsx("button",{className:`commander-filter-btn ${x.status===n?"active":""}`,onClick:()=>b(l=>({...l,status:n})),children:n==="all"?c("commander.filters.all"):n==="error"?c("commander.filters.needsAttn"):n.charAt(0).toUpperCase()+n.slice(1)},n))]}),e.jsxs("div",{className:"commander-filter-group",children:[e.jsx("span",{className:"commander-filter-label",children:c("commander.filters.active")}),["all","1h","6h","24h"].map(n=>e.jsx("button",{className:`commander-filter-btn ${x.activity===n?"active":""}`,onClick:()=>b(l=>({...l,activity:n})),children:n==="all"?c("commander.filters.any"):`< ${n}`},n))]}),e.jsxs("div",{className:"commander-filter-group",children:[e.jsx("span",{className:"commander-filter-label",children:c("commander.filters.sort")}),["activity","name","created","context"].map(n=>e.jsx("button",{className:`commander-filter-btn ${x.sort===n?"active":""}`,onClick:()=>b(l=>({...l,sort:n})),children:n==="activity"?c("commander.filters.recent"):n==="context"?c("commander.filters.context"):n.charAt(0).toUpperCase()+n.slice(1)},n))]}),B&&e.jsx("button",{className:"commander-filter-clear",onClick:()=>b(Se),title:c("commander.clearFilters"),children:c("commander.filters.clearFilters",{count:te})})]}),F>1&&e.jsxs("div",{className:"commander-pagination",children:[e.jsxs("button",{className:"commander-page-btn",onClick:()=>R(n=>Math.max(0,n-1)),disabled:A===0,children:[e.jsx(O,{name:"caret-left",size:12})," ",c("commander.prev")]}),e.jsx("span",{className:"commander-page-info",children:c("commander.page",{current:A+1,total:F,count:_.length})}),e.jsxs("button",{className:"commander-page-btn",onClick:()=>R(n=>Math.min(F-1,n+1)),disabled:A===F-1,children:[c("commander.next")," ",e.jsx(O,{name:"caret-right",size:12})]})]}),e.jsx("div",{className:`commander-grid ${N?"has-expanded":""}`,"data-agent-count":N?1:H.length,children:H.length===0?e.jsx("div",{className:"commander-empty",children:c(d==="all"?"commander.noAgentsAll":d==="unassigned"?"commander.noAgentsUnassigned":"commander.noAgentsArea")}):N?(()=>{const n=f.get(N);return n?e.jsx(Pe,{agent:n,history:Q.get(n.id),isExpanded:!0,isFocused:!0,advancedView:k,index:0,onExpand:ne,onCollapse:ae,onFocus:ce,onInputRef:pe,onLoadMore:U,onClearHistory:w},n.id):null})():H.map((n,l)=>e.jsx(Pe,{agent:n,history:Q.get(n.id),isExpanded:!1,isFocused:l===j,advancedView:k,index:l,onExpand:ne,onCollapse:ae,onFocus:ce,onInputRef:pe,onLoadMore:U,onClearHistory:w},n.id))}),v&&e.jsx(ht,{currentArea:L,onClose:()=>u(!1)}),D&&e.jsx(at,{isOpen:!0,areaId:D,onClose:()=>i(null),onChangeArea:n=>i(n)})]})}):null}export{Ct as CommanderView};