@seira-bot/seira 0.1.180 → 0.1.181

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 (173) hide show
  1. package/dist/assets/{ActivityPanel-DpipGqnm.js → ActivityPanel-tZLxRHYi.js} +1 -1
  2. package/dist/assets/{AnnouncementsPage-GCXia4xK.js → AnnouncementsPage-BrGYAaS0.js} +1 -1
  3. package/dist/assets/{App-BIllYA_e.js → App-h8WTNY4l.js} +136 -136
  4. package/dist/assets/{AppEventEditor-DYdUkpiM.js → AppEventEditor-CLpZ2lyb.js} +1 -1
  5. package/dist/assets/{BotSettingsDialog-DxRMUwAP.js → BotSettingsDialog-COjDhP9V.js} +1 -1
  6. package/dist/assets/{BrowserPanel-Cu_GqDA1.js → BrowserPanel-D_kPeSZ3.js} +1 -1
  7. package/dist/assets/{BrowserProfilesManager-CL3TIl73.js → BrowserProfilesManager-haN8RgPf.js} +1 -1
  8. package/dist/assets/{CloudAddDialog-DUk6i4df.js → CloudAddDialog-vwGwJIYN.js} +1 -1
  9. package/dist/assets/{ComputerFilesPane-HvpeAXhL.js → ComputerFilesPane-DJu1k1Ap.js} +1 -1
  10. package/dist/assets/{ComputerPanel-CozzFQeF.js → ComputerPanel-D9bTedHq.js} +2 -2
  11. package/dist/assets/{DataPanel-DGqcWB1O.js → DataPanel-CsuS_ybT.js} +1 -1
  12. package/dist/assets/{DesktopViewer-BoBSIDfB.js → DesktopViewer-YvIV04Lf.js} +1 -1
  13. package/dist/assets/{EnginesSettings-D643-yZk.js → EnginesSettings-C27xDaBN.js} +1 -1
  14. package/dist/assets/{FilesView-b5DFlMDt.js → FilesView-Dsxj73nW.js} +1 -1
  15. package/dist/assets/{GrokMoveDialog-gGTLfrGg.js → GrokMoveDialog-DEgRQW9G.js} +1 -1
  16. package/dist/assets/{ImportDialog-Bu5X6qOF.js → ImportDialog-DLVTgN-h.js} +1 -1
  17. package/dist/assets/{InspectorPanel-DU7_iwQR.js → InspectorPanel-gvFj5wfe.js} +1 -1
  18. package/dist/assets/{KeyboardShortcutsModal-Wxnn1d66.js → KeyboardShortcutsModal-aF0vhD29.js} +1 -1
  19. package/dist/assets/{LiveDesktop-D9PC-iAT.js → LiveDesktop-Bca91cEb.js} +1 -1
  20. package/dist/assets/{LocalVmWorkspace-0YxB-I-X.js → LocalVmWorkspace-CVLDY3ws.js} +1 -1
  21. package/dist/assets/{MacLocalControl-DoEGcs3V.js → MacLocalControl-BeNWQ9oY.js} +1 -1
  22. package/dist/assets/{MarkdownFilePreview-CAlARwd0.js → MarkdownFilePreview-CYw3CQ3T.js} +1 -1
  23. package/dist/assets/{MenuMotion-DfjnHTCi.js → MenuMotion-CHp-hB40.js} +1 -1
  24. package/dist/assets/{NewBotDialog-D3i7j_KP.js → NewBotDialog-BxeQktoI.js} +1 -1
  25. package/dist/assets/{PhoneAppDialog-OeXLO0Wb.js → PhoneAppDialog-CIlw_m5U.js} +1 -1
  26. package/dist/assets/{PlacesRail-3RaNlpug.js → PlacesRail-Df-jNTHn.js} +1 -1
  27. package/dist/assets/PluginsPanel-CMqZcDkC.js +8 -0
  28. package/dist/assets/{ProIntroduction-B3phUWnc.js → ProIntroduction-D8hWm9R5.js} +1 -1
  29. package/dist/assets/{PublishedAppsPage-BXWDYkhG.js → PublishedAppsPage-BMn3C64O.js} +1 -1
  30. package/dist/assets/{RemoteAgentSettingsPanel-vgrEf5B7.js → RemoteAgentSettingsPanel-B7QJizjx.js} +1 -1
  31. package/dist/assets/{RoomPanel-BmXypXPv.js → RoomPanel-CyWZ4kkq.js} +1 -1
  32. package/dist/assets/RoutinesPage-B9kKyfFp.js +2 -0
  33. package/dist/assets/{ServerPairingCard-c2fKq1gh.js → ServerPairingCard-D21dP5Bc.js} +1 -1
  34. package/dist/assets/SettingsModal-afRPXeYI.js +2 -0
  35. package/dist/assets/{ShareDepartmentDialog-CJITsmAd.js → ShareDepartmentDialog-CwErWDth.js} +1 -1
  36. package/dist/assets/{SignedInSites-B2pCMdic.js → SignedInSites-CFyvOLSc.js} +1 -1
  37. package/dist/assets/{TeamFilesPage-B10cdbwa.js → TeamFilesPage-BvhXs2O5.js} +1 -1
  38. package/dist/assets/{TeamLibraryPanel-CRmTfBOI.js → TeamLibraryPanel-Dm8wjNB4.js} +1 -1
  39. package/dist/assets/{TeamMapPage-BoTNppEy.js → TeamMapPage-jCSzFPvB.js} +1 -1
  40. package/dist/assets/{ToolPageShell-BPd_nyJ8.js → ToolPageShell-DKZUregg.js} +1 -1
  41. package/dist/assets/{TriggersPage-DDxtJMT4.js → TriggersPage-wSB6z1cp.js} +1 -1
  42. package/dist/assets/{VisibilitySection-Cd3TZvS_.js → VisibilitySection-CFr6fOzq.js} +1 -1
  43. package/dist/assets/{WebhookTrigger-AJduidiC.js → WebhookTrigger-BJN-V-bx.js} +1 -1
  44. package/dist/assets/{WorksOnGrid-DHo10o0j.js → WorksOnGrid-B3wYro9M.js} +1 -1
  45. package/dist/assets/{abnfDiagram-YUKMZFIV-DnIZyeSK.js → abnfDiagram-YUKMZFIV-DRhWKTiz.js} +1 -1
  46. package/dist/assets/{activity-DrX2_Hm9.js → activity-l0oTqbd6.js} +1 -1
  47. package/dist/assets/{architectureDiagram-47P4ROYG-DHdulT2e.js → architectureDiagram-47P4ROYG-C_qnTvJF.js} +1 -1
  48. package/dist/assets/{blockDiagram-E7TT5TSB-BGReDH4k.js → blockDiagram-E7TT5TSB-DzLSloVY.js} +1 -1
  49. package/dist/assets/{c4Diagram-CRA5TL53-BV9zDZsL.js → c4Diagram-CRA5TL53-BzVViHCA.js} +1 -1
  50. package/dist/assets/{calendar-days-Ddhxf1PV.js → calendar-days-DFd3GKf_.js} +1 -1
  51. package/dist/assets/channel-B2D6cAE5.js +1 -0
  52. package/dist/assets/{chunk-2Q5K7J3B-DAj16syq.js → chunk-2Q5K7J3B-hR-bQJHo.js} +1 -1
  53. package/dist/assets/{chunk-5VM5RSS4-CMyoXW_3.js → chunk-5VM5RSS4-BWmBW1XC.js} +1 -1
  54. package/dist/assets/{chunk-7TKQ45FW--z54G8Jv.js → chunk-7TKQ45FW-DuUk7RXl.js} +1 -1
  55. package/dist/assets/{chunk-AW2ZBBNX-CPPbUHIj.js → chunk-AW2ZBBNX-Madgl1uv.js} +1 -1
  56. package/dist/assets/{chunk-FVRAUYC3-pKEz9wbK.js → chunk-FVRAUYC3-WSgsvIGA.js} +2 -2
  57. package/dist/assets/{chunk-HTAEGDNF-DIOqwx2X.js → chunk-HTAEGDNF-CfoPR2yG.js} +1 -1
  58. package/dist/assets/{chunk-JWPE2WC7-BW474-Li.js → chunk-JWPE2WC7-tLRHdBom.js} +1 -1
  59. package/dist/assets/{chunk-KQW6MTUR-DjAEB-Df.js → chunk-KQW6MTUR-BqwuNuVY.js} +1 -1
  60. package/dist/assets/{chunk-XXDRQBXY-CMZz2xNV.js → chunk-XXDRQBXY-BOeb8xE4.js} +1 -1
  61. package/dist/assets/{classDiagram-v2-K4WV4PDN-7GYDWs2n.js → classDiagram-v2-K4WV4PDN-CFeH5trZ.js} +1 -1
  62. package/dist/assets/{core-Dq4LUz6X.js → core-CnInZb-o.js} +1 -1
  63. package/dist/assets/{cose-bilkent-JH36ORCC-Dy2zOVu3.js → cose-bilkent-JH36ORCC-BEg68hhI.js} +1 -1
  64. package/dist/assets/{cynefin-EF2NZ3EQ-C7I3qmqf.js → cynefin-EF2NZ3EQ-B_Xq3hQ3.js} +1 -1
  65. package/dist/assets/{cynefinDiagram-3GCD6N5R-CsPcUXHD.js → cynefinDiagram-3GCD6N5R-DN1o2ihW.js} +1 -1
  66. package/dist/assets/{dagre-W4DXFKR2-DxvGlifm.js → dagre-W4DXFKR2-BFf83-nP.js} +1 -1
  67. package/dist/assets/{de-CrlnmnfQ.js → de-BpsYkrLY.js} +1 -1
  68. package/dist/assets/{desktop-connection-Df-k5QBM.js → desktop-connection-CU6jsy2e.js} +1 -1
  69. package/dist/assets/{diagram-2UJZ2QOL-Qz2-e2_u.js → diagram-2UJZ2QOL-_qwbS5JH.js} +1 -1
  70. package/dist/assets/{diagram-OVF4WLC6-D1u4ioUX.js → diagram-OVF4WLC6-9sq9EfiF.js} +1 -1
  71. package/dist/assets/{diagram-PFPMY2P6-DZiCtcMI.js → diagram-PFPMY2P6-Ow1v5ZhK.js} +1 -1
  72. package/dist/assets/{diagram-UMYRVEAY-DmVn9h1H.js → diagram-UMYRVEAY-DDTBFPls.js} +1 -1
  73. package/dist/assets/{diagram-YEKJPTXX-CJK2ajcB.js → diagram-YEKJPTXX-D1zZ8KqI.js} +1 -1
  74. package/dist/assets/{diagram-ZIFT7M5P-NoYT_JX9.js → diagram-ZIFT7M5P-C_vZWUw8.js} +1 -1
  75. package/dist/assets/{ebnfDiagram-VR2GEFS7-BooF3Pem.js → ebnfDiagram-VR2GEFS7-D_1GvBDx.js} +1 -1
  76. package/dist/assets/{elk-IJKZMXRS-4Ai0igvq.js → elk-IJKZMXRS-CV-PzspH.js} +1 -1
  77. package/dist/assets/{erDiagram-O2IAPWRE-CdhhzqVX.js → erDiagram-O2IAPWRE-CnKVd0av.js} +1 -1
  78. package/dist/assets/{es-BIPy8tP9.js → es-COLCGADa.js} +1 -1
  79. package/dist/assets/{file-up-Bs5NWcjw.js → file-up-Bjx5Vcmk.js} +1 -1
  80. package/dist/assets/{flowDiagram-OXPTDLAJ-SeyZJAiT.js → flowDiagram-OXPTDLAJ-CGJh171P.js} +1 -1
  81. package/dist/assets/{fr-CCbXz1Dc.js → fr-CJ1x1iRl.js} +1 -1
  82. package/dist/assets/{ganttDiagram-R7TSEDQI-rmA_SJlC.js → ganttDiagram-R7TSEDQI-CygoACFs.js} +1 -1
  83. package/dist/assets/{gitGraphDiagram-XJZIOB7I-Coc2oeHo.js → gitGraphDiagram-XJZIOB7I-ByxErzHV.js} +1 -1
  84. package/dist/assets/{hi-DmCL9a_Y.js → hi-BC0iO7jD.js} +1 -1
  85. package/dist/assets/{index-uiyAwyX1.js → index-BRfvYRb5.js} +1 -1
  86. package/dist/assets/{index-D69O3YiA.js → index-DQZxP2c4.js} +2 -2
  87. package/dist/assets/{index-C1PEx1tc.js → index-DtDQrExn.js} +3 -3
  88. package/dist/assets/{infoDiagram-5W2HQ5XZ-DScYPtht.js → infoDiagram-5W2HQ5XZ-BlzjfTwq.js} +1 -1
  89. package/dist/assets/{ishikawaDiagram-K3B6WC7H-Cf7mJB_l.js → ishikawaDiagram-K3B6WC7H-2rf_4lR_.js} +1 -1
  90. package/dist/assets/{it-BWkdcVfm.js → it-BIwsqdpz.js} +2 -2
  91. package/dist/assets/{ja-BaOL6cSA.js → ja-BJYXkO5E.js} +2 -2
  92. package/dist/assets/{journeyDiagram-COXZFDF6-Dtmolw3A.js → journeyDiagram-COXZFDF6-mGgPoETt.js} +1 -1
  93. package/dist/assets/{kanban-definition-P3RFRI5V-CSL1-s5L.js → kanban-definition-P3RFRI5V-j2hU8Bw4.js} +1 -1
  94. package/dist/assets/{kit-Cjq8TV0N.js → kit-qjammJR4.js} +1 -1
  95. package/dist/assets/{ko-ebMBLBXv.js → ko-7QtaPFvf.js} +2 -2
  96. package/dist/assets/{livekit-KT4NEVZO-B3DA1PsD.js → livekit-KT4NEVZO-DbFoU2r9.js} +1 -1
  97. package/dist/assets/{mcp-servers-DoMFsds6.js → mcp-servers-Tb2cnkiM.js} +1 -1
  98. package/dist/assets/{memory-BR-ujoQY.js → memory-BNaMRI5v.js} +1 -1
  99. package/dist/assets/{mermaid.core-BK1qxlD4.js → mermaid.core-B1mlFiOp.js} +4 -4
  100. package/dist/assets/{mindmap-definition-LZFPQGKD-Cb7ESZ0y.js → mindmap-definition-LZFPQGKD-C7XLkIzZ.js} +1 -1
  101. package/dist/assets/{minimize-msM7mbil.js → minimize-Dga3UCb8.js} +1 -1
  102. package/dist/assets/{monitor-DpsqT1_R.js → monitor-DMPjQDZP.js} +1 -1
  103. package/dist/assets/{org-library-alRyzCTE.js → org-library-IKFXm7D6.js} +1 -1
  104. package/dist/assets/{package-format-BFXbXHk8.js → package-format-COujx3jP.js} +1 -1
  105. package/dist/assets/{pegDiagram-BGZESJAR-CqmJQKhe.js → pegDiagram-BGZESJAR-BS2zKH6g.js} +1 -1
  106. package/dist/assets/{phones-J7mYR-fY.js → phones-CINpTjZv.js} +1 -1
  107. package/dist/assets/{pieDiagram-CAPJLFHJ-w_QuumOv.js → pieDiagram-CAPJLFHJ-DVAuLXem.js} +1 -1
  108. package/dist/assets/{pl-CSbinyb5.js → pl-CLa2ta1_.js} +2 -2
  109. package/dist/assets/{pt-br-BkWykL5e.js → pt-br-8RQzCbpg.js} +3 -3
  110. package/dist/assets/{quadrantDiagram-GDMTTRAM-248q9C3h.js → quadrantDiagram-GDMTTRAM-H7QRxmHt.js} +1 -1
  111. package/dist/assets/{rail-DRr_33Fe.js → rail-DNpLzOxa.js} +1 -1
  112. package/dist/assets/{railroadDiagram-SM67HX2B-BLzQ_5t7.js → railroadDiagram-SM67HX2B-dq6Rokc9.js} +1 -1
  113. package/dist/assets/{remote-desktop-panel-BPK6Q0O6.js → remote-desktop-panel-Cxv6Qt3x.js} +1 -1
  114. package/dist/assets/{requirementDiagram-X7JNWC4A-Bgi1TLdN.js → requirementDiagram-X7JNWC4A-BeWeL_-r.js} +1 -1
  115. package/dist/assets/{ru-DD01Hb1S.js → ru-CIdzvRVZ.js} +2 -2
  116. package/dist/assets/{sankeyDiagram-UM26HJRW-CrZgn-Cf.js → sankeyDiagram-UM26HJRW-BmJ-9lt-.js} +1 -1
  117. package/dist/assets/{sequenceDiagram-ZO4K6R2Y-gAwq1ZfG.js → sequenceDiagram-ZO4K6R2Y-Uuh1hEOh.js} +1 -1
  118. package/dist/assets/{sizeCapture-INFHLROL-BlXmG_DJ.js → sizeCapture-INFHLROL-mKDf6lys.js} +1 -1
  119. package/dist/assets/{stateDiagram-v2-TBUQTH76-CEFB1Iaq.js → stateDiagram-v2-TBUQTH76-BaEihzov.js} +1 -1
  120. package/dist/assets/{styles-DOJOOIp4.js → styles-3g-ZPS7M.js} +5 -5
  121. package/dist/assets/styles-CsrDURJH.css +1 -0
  122. package/dist/assets/{swimlanes-N4OXWK64-BtJmWAOz.js → swimlanes-N4OXWK64-CpP-NKGz.js} +1 -1
  123. package/dist/assets/swimlanesDiagram-K3J5GTZL-C50Dm6LQ.js +8 -0
  124. package/dist/assets/{template-add-BcTS64TG.js → template-add-CHwGLPet.js} +1 -1
  125. package/dist/assets/{timeline-definition-YOQAKGHF-BZ270zxf.js → timeline-definition-YOQAKGHF-Ca3rjetv.js} +1 -1
  126. package/dist/assets/{tr-Bw35A32w.js → tr-BhclavHM.js} +1 -1
  127. package/dist/assets/{uk-DsPsCgp4.js → uk-Or5wmf6s.js} +1 -1
  128. package/dist/assets/{usecaseDiagram-VIAY4XPW-D5yZb3KQ.js → usecaseDiagram-VIAY4XPW-BuuYl689.js} +1 -1
  129. package/dist/assets/{vennDiagram-BLWOH2XV-OFx2qTzp.js → vennDiagram-BLWOH2XV-C__pWnnE.js} +1 -1
  130. package/dist/assets/{vi-DhPdzwW-.js → vi-CYbGVqh-.js} +1 -1
  131. package/dist/assets/{wardleyDiagram-YMQ3BMBF-DzSmrVKa.js → wardleyDiagram-YMQ3BMBF-yWcEHD-N.js} +1 -1
  132. package/dist/assets/{xychartDiagram-TAQBALBS-UP1H1u5V.js → xychartDiagram-TAQBALBS-CvcdOA7A.js} +1 -1
  133. package/dist/assets/{zh-CzC3CUQA.js → zh-iptM1e_T.js} +2 -2
  134. package/dist/assets/{zh-tw-DeXHnAvy.js → zh-tw-BaO1c--E.js} +2 -2
  135. package/dist/index.html +3 -3
  136. package/dist/rail.html +5 -5
  137. package/dist-server/container-mcp.js +18 -17
  138. package/dist-server/index.js +1136 -1114
  139. package/dist-server/openmausbot.js +182 -180
  140. package/dist-server/package.json +1 -1
  141. package/dist-server/pair-cli.js +182 -180
  142. package/dist-server/server/ai-pool.js +72 -0
  143. package/dist-server/server/cloud-connected-apps.js +33 -16
  144. package/dist-server/server/composio-broker-access.js +1 -1
  145. package/dist-server/server/composio.js +3 -2
  146. package/dist-server/server/config.js +5 -7
  147. package/dist-server/server/connector-auth-config-hint.js +5 -0
  148. package/dist-server/server/drivers/claude.js +14 -11
  149. package/dist-server/server/flatpak-host.js +5 -2
  150. package/dist-server/server/host/ai-pool.js +109 -0
  151. package/dist-server/server/host/app-suggestions.js +2 -1
  152. package/dist-server/server/host/limit-takeover.js +11 -4
  153. package/dist-server/server/index.js +33 -26
  154. package/dist-server/server/limit-failover.js +3 -0
  155. package/dist-server/server/model-selection-schema.js +9 -0
  156. package/dist-server/server/routes/ai-pool-patch.js +24 -0
  157. package/dist-server/server/routes/config.js +8 -1
  158. package/dist-server/server/routine-dispatch.js +21 -0
  159. package/dist-server/server/routines.js +4 -18
  160. package/dist-server/server/tailscale.js +16 -6
  161. package/dist-server/server/workspace-backup-http.js +2 -2
  162. package/dist-server/shared/limit-backup.js +1 -1
  163. package/dist-server/shared/settings-places.js +1 -0
  164. package/dist-server/shared/toolkit-card.js +1 -0
  165. package/dist-server/vps-container-mcp.js +18 -17
  166. package/dist-server/workspace-backup.worker.js +18 -17
  167. package/package.json +1 -1
  168. package/dist/assets/PluginsPanel-B5Q70eO8.js +0 -8
  169. package/dist/assets/RoutinesPage-CLXohizn.js +0 -2
  170. package/dist/assets/SettingsModal-BlX9XoBu.js +0 -2
  171. package/dist/assets/channel-DZM5KU--.js +0 -1
  172. package/dist/assets/styles-9UFSdSaJ.css +0 -1
  173. package/dist/assets/swimlanesDiagram-K3J5GTZL-pBTtzroP.js +0 -8
@@ -1 +1 @@
1
- import{c as We,t as s,r as a,j as e,a as se,x as Qe,X as Be,w as vt,i as Ee,am as kt}from"./styles-DOJOOIp4.js";import{L as Re,v as jt,B as Ze,E as wt,P as Ke,r as et,k as Ct,u as Nt}from"./PlacesRail-3RaNlpug.js";import{g as ne,l as St,al as It,u as Ne,bG as dt,dm as ut,dn as mt,a9 as Mt,T as pt,dp as ft,dq as Tt,dr as Et,ds as At,dt as Rt,at as Ot,bw as Bt,aU as Xe,du as tt,cl as Dt,dv as zt,dw as Lt,y as xt,aj as $e,ao as Je,bb as Pt,C as Ge,dx as $t,dy as _t,e as Ht,dz as Kt,dA as Ut,dB as qt,dC as Ft,d6 as Yt,dD as Xt,dE as Jt,au as Gt,cR as Vt,ap as Wt,dF as Qt,dG as Zt}from"./App-BIllYA_e.js";import"./index-C1PEx1tc.js";import{M as Oe}from"./monitor-DpsqT1_R.js";import{R as en,d as tn}from"./MenuMotion-DfjnHTCi.js";import"./placement-BKtVnQht.js";const nn=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",key:"1sd12s"}]],sn=We("message-circle",nn);const an=[["path",{d:"M17 17H4a2 2 0 0 1-2-2V5c0-1.5 1-2 1-2",key:"k0q8oc"}],["path",{d:"M22 15V5a2 2 0 0 0-2-2H9",key:"cp1ac0"}],["path",{d:"M8 21h8",key:"1ev6f3"}],["path",{d:"M12 17v4",key:"1riwvh"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],rn=We("monitor-off",an);const on=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]],ln=We("save",on),cn={collaborations:[],queued:[],running:[]};function dn(n,r=[]){const i=new Map;for(const c of n){if(c.hidden)continue;const o=c.section?.trim()||"";i.set(o,[...i.get(o)??[],c])}for(const c of r){const o=c.trim();o&&!i.has(o)&&i.set(o,[])}return[...i].map(([c,o])=>({key:c,name:c||s("teamSettings.general"),chiefs:o.filter(l=>l.chiefOfStaff),members:o.filter(l=>!l.chiefOfStaff)}))}function un(n,r){const i=new Set(n.filter(l=>!l.hidden).map(l=>l.id)),c=new Map,o=(l,S)=>[l,S].sort().join(":");for(const l of r.collaborations){const[S,g]=l.botIds;!i.has(S)||!i.has(g)||c.set(o(S,g),{sourceBotId:S,targetBotId:g,state:"connected",groupId:l.groupId,lastAt:l.lastAt})}for(const l of r.queued)!i.has(l.sourceBotId)||!i.has(l.targetBotId)||c.set(o(l.sourceBotId,l.targetBotId),{sourceBotId:l.sourceBotId,targetBotId:l.targetBotId,state:"queued",reason:l.reason,groupId:l.groupId,threadId:l.threadId});for(const l of r.running)!i.has(l.sourceBotId)||!i.has(l.targetBotId)||c.set(o(l.sourceBotId,l.targetBotId),{sourceBotId:l.sourceBotId,targetBotId:l.targetBotId,state:"running",groupId:l.groupId,threadId:l.threadId});return[...c.values()].sort((l,S)=>{const g={running:0,queued:1,connected:2};return g[l.state]-g[S.state]||(S.lastAt??0)-(l.lastAt??0)})}function mn(n){return n.activity==="waiting-on-you"?{label:s("canvas.status.waiting"),tone:"warning"}:n.activity==="dead"||n.activity==="no-signal"?{label:s("canvas.status.noSignal"),tone:"danger"}:n.busy||n.activity==="working"?{label:s("canvas.status.working"),tone:"success"}:{label:s("canvas.status.ready"),tone:"idle"}}function pn(n){return n===1?s("canvas.botCountOne"):s("canvas.botCount",{count:n})}const _e=236,Me=126,He=16,we=20,Te=64,qe="application/x-omb-computer";function ke(n,r=[]){const i=new Map(r.map((c,o)=>[c,o]));return[...n].sort((c,o)=>(i.get(c.id)??1/0)-(i.get(o.id)??1/0))}function fn(n,r,i){const c=n.map(l=>l.id);if(!c.includes(r))return c;const o=c.filter(l=>l!==r);return o.splice(Math.max(0,Math.min(o.length,i)),0,r),o}function xn(n){try{const r=JSON.parse(n??"null");return r===null||typeof r!="object"||Array.isArray(r)?{}:Object.fromEntries(Object.entries(r).flatMap(([i,c])=>Array.isArray(c)?[[i,[...new Set(c.filter(o=>typeof o=="string"&&o.length>0))]]]:[]))}catch{return{}}}function ht(n){const r=n.chiefs.length>0&&n.members.length>0,i=r?Math.max(n.chiefs.length,n.members.length):Math.max(1,n.chiefs.length+n.members.length);return{width:_e*(r?2:1)+we*2+(r?40:0),height:Te+we+i*(Me+He)-He}}function hn(n,r,i={}){const c=i.sizes??n.map(ht),o=Math.max(1,Math.floor(i.columns??2)),l=[40];for(let g=1;g<o;g++){const x=Math.max(0,...c.filter((I,h)=>h%o===g-1).map(I=>I.width));l.push(l[g-1]+x+56)}let S=40;return n.map((g,x)=>{x>0&&x%o===0&&(S+=Math.max(...c.slice(x-o,x).map(h=>h.height))+56);const I=Object.hasOwn(r,g.key)?r[g.key]:void 0;return{key:g.key,x:I?.x??l[x%o],y:I?.y??S,...c[x]}})}function gn(n,r,i){if(!n.length)return{x:0,y:0,scale:1};const c=Math.min(...n.map(x=>x.x)),o=Math.min(...n.map(x=>x.y)),l=Math.max(...n.map(x=>x.x+x.width))-c,S=Math.max(...n.map(x=>x.y+x.height))-o,g=Math.max(.3,Math.min(1,(r-80)/l,(i-80)/S));return{x:(r-l*g)/2-c*g,y:(i-S*g)/2-o*g,scale:g}}function at(n,r,i){const c=r/n.scale;return{x:i.x-(i.x-n.x)*c,y:i.y-(i.y-n.y)*c,scale:r}}function bn(n){try{const r=JSON.parse(n??"null");return r===null||typeof r!="object"||Array.isArray(r)?{}:Object.fromEntries(Object.entries(r).flatMap(([i,c])=>{if(c===null||typeof c!="object"||Array.isArray(c))return[];const{x:o,y:l}=c;return typeof o=="number"&&Number.isFinite(o)&&Math.abs(o)<1e5&&typeof l=="number"&&Number.isFinite(l)&&Math.abs(l)<1e5?[[i,{x:o,y:l}]]:[]}))}catch{return{}}}const Ve=272,je=208,Fe=44,Ye=28;function yn(n,r){const i=[...n.chiefs,...n.members],c=i.filter(v=>r.own.has(v.id));if(!c.length&&!r.team)return null;const o=n.chiefs.length>0&&n.members.length>0,l=c.length?je:Me,S=v=>Te+v*(l+He),g=v=>S(v)+l/2,x=we+(o?Ye:0)+_e,I=x+Fe,h=i.map((v,b)=>({botId:v.id,x:we+(o&&b>=n.chiefs.length?Ye:0),y:S(b)+(l-Me)/2})),k=[],y=[];i.forEach((v,b)=>{const j=r.own.get(v.id);j&&(k.push({id:j,x:I,y:S(b)+(l-je)/2}),y.push({botId:v.id,computerId:j,points:[{x:h[b].x+_e,y:g(b)},{x:I,y:g(b)}]}))});const z=S(i.length)-He;let U=Math.max(z,Te+Me),A=c.length?I+Ve:x;if(r.team){const v=i.map((K,G)=>({bot:K,index:G})).filter(({bot:K})=>r.team.botIds.includes(K.id)),b=(v.length?v:i.map((K,G)=>({bot:K,index:G}))).map(({index:K})=>g(K)),j=b.length?(Math.min(...b)+Math.max(...b))/2:Te+je/2,E=A+Fe*(c.length?1.5:2),$=Math.max(Te,j-je/2),W=E-Fe/2,_=$+je/2;k.push({id:r.team.id,x:E,y:$});for(const{bot:K,index:G}of v){const R={x:h[G].x+_e,y:g(G)};y.push({botId:K.id,computerId:r.team.id,points:[R,{x:W,y:R.y},{x:W,y:_},{x:E,y:_}]})}A=E+Ve,U=Math.max(U,$+je)}const H=[];if(o){const v=we+Ye/2,b=n.chiefs.length;H.push([{x:v,y:h[b-1].y+Me},{x:v,y:g(i.length-1)}]);for(let j=b;j<i.length;j++)H.push([{x:v,y:g(j)},{x:h[j].x,y:g(j)}])}return{width:A+we,height:U+we,cards:h,monitors:k,links:y,tree:H}}function vn(n,r,i=56){if(n.length<2||r.width<=0||r.height<=0)return 2;let c={columns:2,scale:0};for(let o=1;o<=Math.min(n.length,6);o++){const l=Array.from({length:o},(k,y)=>Math.max(0,...n.filter((z,U)=>U%o===y).map(z=>z.width))),S=Math.ceil(n.length/o),g=Array.from({length:S},(k,y)=>Math.max(0,...n.slice(y*o,y*o+o).map(z=>z.height))),x=l.reduce((k,y)=>k+y,0)+i*(o-1),I=g.reduce((k,y)=>k+y,0)+i*(S-1),h=Math.min((r.width-80)/x,(r.height-80)/I);h>c.scale+.01&&(c={columns:o,scale:h})}return c.columns}function rt(n){return n.map((r,i)=>`${i?"L":"M"}${r.x} ${r.y}`).join(" ")}const kn=2e3;function jn(n,r){return n.find(i=>i.kind==="bot"&&i.id===r)??n.find(i=>i.kind==="team"&&i.botIds.includes(r))}function wn(n,r,i){const c=new Set(r),o=i.find(l=>l.kind==="team"&&l.section===n);return{own:new Map(i.filter(l=>l.kind==="bot"&&c.has(l.id)).map(l=>[l.id,l.id])),...o?{team:{id:o.id,botIds:o.botIds.filter(l=>c.has(l))}}:{}}}function Cn(n){return Object.entries(n).map(([r,i])=>`${r}:${i.version}`).join(",")}function Nn(n,r,i){return i-Math.max(0,r-n)}function Sn(n,r){const i=atob(n),c=new Uint8Array(i.length);for(let o=0;o<i.length;o++)c[o]=i.charCodeAt(o);return new Blob([c],{type:r})}function In(n){const[r,i]=a.useState(null),[c,o]=a.useState({}),[l,S]=a.useState(null),g=a.useRef(c);g.current=c;const x=a.useRef([]);x.current=r?.computers??[];const I=a.useRef(new Set),h=a.useRef(!0),k=a.useCallback(async(y,z,U,A,H)=>{if((g.current[y]?.at??-1/0)>=A)return;let v;try{v=URL.createObjectURL(Sn(z,U))}catch{return}try{const j=new Image;j.src=v,await j.decode()}catch{URL.revokeObjectURL(v);return}if(!h.current||(g.current[y]?.at??-1/0)>=A){URL.revokeObjectURL(v);return}const b=g.current[y]?.url;g.current={...g.current,[y]:{url:v,at:A,version:H}},o(g.current),b&&(I.current.add(b),window.setTimeout(()=>{URL.revokeObjectURL(b),I.current.delete(b)},2e3))},[]);return a.useEffect(()=>(h.current=!0,()=>{h.current=!1;for(const y of Object.values(g.current))URL.revokeObjectURL(y.url);for(const y of I.current)URL.revokeObjectURL(y)}),[]),a.useEffect(()=>{if(!n)return;let y=!1,z=!1;const U=async()=>{if(!(y||z||document.visibilityState!=="visible")){z=!0;try{const v=Cn(g.current),b=await ne(`/api/computers/frames${v?`?have=${encodeURIComponent(v)}`:""}`,{signal:AbortSignal.timeout(3e4)});if(y)return;const j=Date.now();i(b),S(null);for(const E of b.computers){const $=E.frame;$?.data&&k(E.id,$.data,$.mime,Nn($.at,b.now,j),$.version)}}catch(v){y||S(v instanceof Error?v.message:String(v))}finally{z=!1}}};U();const A=window.setInterval(U,kn),H=St({screens:!0,onFrame:v=>{if(v.kind!=="screen"||v.surface!=="computer"||!v.png)return;const b=jn(x.current,v.botId);b&&k(b.id,v.png,v.mime??"image/png",Date.now(),"live")}});return()=>{y=!0,window.clearInterval(A),H()}},[n,k]),{computers:r?.computers??[],configured:r?.configured??null,frames:c,error:l}}function Mn(n){const[r,i]=a.useState(null),[c,o]=a.useState(null),[l,S]=a.useState(!1);a.useEffect(()=>{let x=!0;return ne("/.well-known/openmausbot/environment",{signal:AbortSignal.timeout(5e3)}).then(I=>{if(!x||typeof I.environmentId!="string")return;const h=`omb-team-canvas:${I.environmentId}:computers`;i(h);try{const k=localStorage.getItem(h);(k==="on"||k==="off")&&o(k==="on")}catch{}}).catch(()=>{}).finally(()=>{x&&S(!0)}),()=>{x=!1}},[]);const g=a.useCallback(x=>{if(o(x),!!r)try{localStorage.setItem(r,x?"on":"off")}catch{}},[r]);return{show:c??n,loaded:l,choose:g}}const ot=28;function Tn(n){if(n&&typeof n=="object"&&!Array.isArray(n))return n;if(typeof n!="string")return{};try{const r=JSON.parse(n);return r&&typeof r=="object"&&!Array.isArray(r)?r:{}}catch{return{}}}function En(n){const r=/(?:^|__)computer__(\w+)$/.exec(n.name)?.[1]??null;if(!r)return null;const i=Tn(n.input);if(r==="open_url")try{return s("mapComputer.step.open",{site:new URL(String(i.url)).hostname.replace(/^www\./,"")})}catch{return s("mapComputer.step.openPage")}if(r==="type_text"&&typeof i.text=="string"&&i.text.trim()){const c=i.text.replace(/\s+/g," ").trim();return s("mapComputer.step.type",{text:c.length>ot?`${c.slice(0,ot)}…`:c})}if(r==="key_press"){const c=[i.keys,i.key,i.combo].find(l=>typeof l=="string"||Array.isArray(l)),o=Array.isArray(c)?c.join("+"):typeof c=="string"?c:"";return o?s("mapComputer.step.key",{keys:o.slice(0,24)}):s("mapComputer.step.keyAny")}return r==="click"||r==="double_click"||r==="right_click"?s("mapComputer.step.click"):r==="scroll"?s("mapComputer.step.scroll"):r==="screenshot"?s("mapComputer.step.look"):r==="drag"?s("mapComputer.step.drag"):null}const it={starting:"mapComputer.state.starting",working:"mapComputer.state.working",idle:"mapComputer.state.idle",asleep:"mapComputer.state.asleep",off:"mapComputer.state.off",problem:"mapComputer.state.problem"},An={starting:"bg-warning",working:"bg-success",idle:"bg-sky-400",asleep:"bg-white/35",off:"bg-white/25",problem:"bg-danger"},Rn=a.memo(function({computer:r,bots:i,frameUrl:c,state:o,activity:l,x:S,y:g,onOpen:x}){const I=o==="working",h=r.kind==="team"?r.name:s("mapComputer.botComputer",{name:r.name});return e.jsxs("div",{"data-computer-node":r.id,className:"absolute",style:{left:S,top:g,width:Ve,height:je},children:[I&&e.jsx("span",{"aria-hidden":!0,className:"pointer-events-none absolute -inset-[5px] animate-computer-glow rounded-[22px] border-2 border-success/70 shadow-[0_0_24px_rgba(52,199,89,0.35)]"}),e.jsxs("button",{type:"button",onClick:x,disabled:!x,title:l?`${h} · ${l}`:h,"aria-label":s("mapComputer.open",{name:h,state:s(it[o])}),className:"relative flex size-full flex-col rounded-[18px] border border-white/10 bg-[#0f1117] p-2 text-left shadow-[0_10px_30px_rgba(0,0,0,0.35)] outline-none transition-transform hover:-translate-y-0.5 focus-visible:ring-2 focus-visible:ring-accent disabled:cursor-default",children:[e.jsxs("span",{className:"relative block h-[160px] w-full overflow-hidden rounded-[8px] bg-[#06070b] [contain:paint]",children:[c?e.jsx("img",{src:c,alt:"",draggable:!1,decoding:"async",className:se("size-full object-cover",o==="asleep"||o==="off"?"opacity-40 grayscale":"")}):e.jsxs("span",{className:"flex size-full flex-col items-center justify-center gap-2 bg-[radial-gradient(circle_at_50%_40%,#1b2030,#06070b_70%)] text-[11px] text-white/45",children:[o==="starting"?e.jsx(Re,{size:20,className:"animate-spin"}):o==="asleep"?e.jsx(jt,{size:20}):o==="problem"?e.jsx(It,{size:20}):e.jsx(rn,{size:20}),s(o==="starting"?"mapComputer.empty.starting":o==="asleep"?"mapComputer.empty.asleep":o==="problem"?"mapComputer.empty.problem":o==="off"?"mapComputer.empty.off":"mapComputer.empty.waiting")]}),e.jsxs("span",{className:"absolute left-2 top-2 flex items-center gap-1.5 rounded-full bg-black/65 px-2 py-0.5 text-[10px] font-medium text-white/90 backdrop-blur-[2px]",children:[e.jsx("span",{className:se("size-1.5 rounded-full",An[o],I&&"animate-pulse")}),s(it[o])]}),l&&I&&e.jsx("span",{className:"absolute inset-x-0 bottom-0 truncate bg-gradient-to-t from-black/85 via-black/55 to-transparent px-2.5 pb-1.5 pt-6 text-[11px] leading-tight text-white/90",children:l})]}),e.jsxs("span",{className:"flex h-[32px] min-w-0 items-center gap-2 px-1 pt-1.5",children:[e.jsx("span",{className:"flex shrink-0 -space-x-1.5",children:i.slice(0,3).map(k=>e.jsx("span",{className:"rounded-full ring-2 ring-[#0f1117]",children:e.jsx(Ze,{bot:k,size:20,animated:!1,motion:"none",motionKey:0})},k.id))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-medium text-white/90",children:h}),i.length>3&&e.jsxs("span",{className:"shrink-0 text-[10px] text-white/50",children:["+",i.length-3]})]})]})]})}),Ae="flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-control hover:text-ink focus-visible:outline-2 focus-visible:outline-accent",Ie="flex w-full items-center gap-2 rounded-lg px-3 py-2.5 text-left text-[12px] text-ink-secondary hover:bg-control hover:text-ink";function On({bot:n,selected:r,moving:i,connected:c,tagged:o=!1,sent:l,onComputer:S,onArrange:g}){const{state:x,dispatch:I}=Ne(),h=Qe(),k=mn(n),y=Rt(n,Ot()),z=x.instances.find(A=>A.instanceId===n.modelSelection.instanceId),U=z?.models.options.find(A=>A.id===n.modelSelection.model)?.label??n.modelSelection.model;return e.jsxs("article",{className:se("relative h-[126px] w-[236px] shrink-0 rounded-xl border bg-card shadow-sm transition-colors",r?"border-accent/60 ring-1 ring-accent/15":c?"border-accent/40":"border-hairline/50 hover:border-ink-secondary/40",o&&"border-accent ring-4 ring-accent/25",i&&"opacity-35"),children:[l!==void 0&&e.jsx("span",{"data-sent-highlight":!0,"aria-hidden":!0,className:"pointer-events-none absolute -inset-px animate-sent-border rounded-xl border-2 border-accent"},l),e.jsxs("button",{"data-bot-id":n.id,"aria-label":s("canvas.editBot",{name:y}),onClick:()=>Xe(I,"identity",{botId:n.id}),title:g?s("canvas.reorderHint"):void 0,onKeyDown:A=>{!g||!A.altKey||A.key!=="ArrowUp"&&A.key!=="ArrowDown"||(A.preventDefault(),A.stopPropagation(),g(n,A.key==="ArrowUp"?-1:1))},className:"flex h-[82px] w-full cursor-grab items-center gap-3 rounded-t-xl px-4 text-left active:cursor-grabbing focus-visible:outline-2 focus-visible:outline-accent",children:[e.jsx(Ze,{bot:n,size:38,motion:"none",motionKey:0,animated:!1}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[14px] font-semibold",children:y}),n.chiefOfStaff&&e.jsx(Bt,{size:12,className:"shrink-0 text-warning","aria-label":s("chat.chiefOfStaff")})]}),e.jsx("span",{className:"mt-1 block truncate text-[11px] text-ink-secondary",children:n.title||(n.chiefOfStaff?s("chat.chiefOfStaff"):s("canvas.bot"))})]})]}),e.jsxs("div",{className:"flex h-[43px] items-center gap-1 border-t border-hairline/30 px-2",children:[e.jsx("button",{className:se(Ae,"size-8"),"aria-label":s("canvas.openBotChat",{name:n.name}),title:s("canvas.openChat"),onClick:()=>tt(I,n,h),children:e.jsx(sn,{size:13})}),k.tone!=="idle"&&e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] text-ink-secondary",title:k.label,children:[e.jsx("span",{className:se("size-1.5 rounded-full",k.tone==="success"?"bg-success":k.tone==="warning"?"bg-warning":k.tone==="danger"?"bg-danger":"bg-ink-secondary/35")}),k.label]}),r&&S&&e.jsx("button",{className:se(Ae,"size-8"),"aria-label":s("canvas.botComputer",{name:n.name}),title:s("computer.tab.computer"),onClick:()=>S(n),children:e.jsx(Oe,{size:13})}),e.jsxs("button",{"aria-label":s("canvas.changeModel",{name:n.name}),title:`${s("canvas.defaultModel")}: ${U}`,onClick:()=>Xe(I,"model",{botId:n.id}),className:"ml-auto flex h-8 min-w-0 max-w-[130px] items-center gap-1.5 rounded-md px-2 text-[10px] text-ink-secondary hover:bg-control hover:text-ink focus-visible:outline-2 focus-visible:outline-accent",children:[e.jsx("span",{className:"flex size-3.5 shrink-0 items-center justify-center",children:z?e.jsx(Dt,{instance:z,size:13}):e.jsx(zt,{driverKind:"",size:13})}),e.jsx("span",{className:"truncate",children:U||s("canvas.defaultModel")})]})]})]})}const Bn=[];function Dn(n,r){if(!n?.busy)return;const i=n.tasks?.find(o=>o.threadId===n.threadId),c=!i||i.busy?n.messages.findLast(o=>o.kind==="activity"&&o.tool):void 0;return c?.tool?En(c.tool)??Et(c.tool,At(n,r),c.dataResult):n.tasks?.find(o=>o.busy&&o.threadId!==n.threadId&&o.title.trim())?.title}function zn({sections:n,canManage:r,onMove:i,onInstructions:c,onMemory:o,onEditTeam:l,onDeleteTeam:S,onComputer:g,onComputerDrop:x,onTeamComputer:I,teamComputers:h={},connectedBotIds:k=[],computers:y=Bn,computerFrames:z={},onOpenComputer:U,taggedBotIds:A=[],sent:H,bottomInset:v=0}){const{state:b}=Ne(),j=a.useRef(null),E=a.useRef(null),$=a.useRef(!1),W=a.useRef(!1),_=a.useRef(null),[K,G]=a.useState({}),[R,q]=a.useState({}),[u,B]=a.useState({x:40,y:40,scale:1}),[N,O]=a.useState(null),[M,F]=a.useState(null),[oe,w]=a.useState(null),[Y,ce]=a.useState(null),[ie,re]=a.useState(null),[xe,me]=a.useState(""),[pe,ue]=a.useState(!1),[be,ve]=a.useState(null),[ge,Se]=a.useState({width:0,height:0}),de=a.useMemo(()=>n.map(t=>{if(!y.length)return null;const p=Object.hasOwn(R,t.key)?R[t.key]:[],d=ke(t.chiefs,p),C=ke(t.members,p);return yn({chiefs:d,members:C},wn(t.key,[...d,...C].map(T=>T.id),y))}),[n,y,R]),fe=a.useMemo(()=>{if(!de.some(Boolean))return;const t=de.map((p,d)=>p??ht(n[d]));return{sizes:t,columns:vn(t,{width:Math.round(ge.width/200)*200,height:Math.round(ge.height/200)*200})}},[de,n,ge]),f=a.useMemo(()=>hn(n,K,fe),[n,K,fe]),D=a.useRef({view:u,positions:K,tiles:f,selectedId:b.selectedId,settingsOpen:b.settingsOpen,bottomInset:v});D.current={view:u,positions:K,tiles:f,selectedId:b.selectedId,settingsOpen:b.settingsOpen,bottomInset:v},a.useEffect(()=>{let t=!0;return ne("/.well-known/openmausbot/environment",{signal:AbortSignal.timeout(5e3)}).then(p=>{if(!(!t||typeof p.environmentId!="string")){_.current=`omb-team-canvas:${p.environmentId}`;try{const d=bn(localStorage.getItem(_.current));G(C=>({...d,...C})),q(xn(localStorage.getItem(`${_.current}:bot-order`)))}catch{}}}).catch(()=>{}).finally(()=>{t&&ue(!0)}),()=>{t=!1}},[]);const Q=t=>{if(G(t),!!_.current)try{localStorage.setItem(_.current,JSON.stringify(Object.fromEntries(n.filter(p=>Object.hasOwn(t,p.key)).map(p=>[p.key,t[p.key]]))))}catch{}},m=t=>Object.hasOwn(R,t)?R[t]:[],L=(t,p,d,C)=>{const T={...R,[t.key]:[...fn(p,d.id,C),...ke(d.chiefOfStaff?t.members:t.chiefs,m(t.key)).map(ee=>ee.id)]};if(q(T),_.current)try{localStorage.setItem(`${_.current}:bot-order`,JSON.stringify(T))}catch{}me(s("canvas.arrangedBot",{name:d.name,team:t.name}))},V=(t,p)=>{const d=n.find(T=>T.key===(t.section?.trim()??""));if(!d)return;const C=ke(t.chiefOfStaff?d.chiefs:d.members,m(d.key));L(d,C,t,C.findIndex(T=>T.id===t.id)+p)},te=a.useCallback(()=>{const t=j.current?.getBoundingClientRect();t&&B(gn(D.current.tiles,t.width,Math.max(200,t.height-D.current.bottomInset)))},[]);a.useEffect(()=>{const t=j.current;if(!t)return;let p=null;const d=new ResizeObserver(()=>{const C=t.getBoundingClientRect();if(Se({width:C.width,height:C.height}),!p)te();else{const T=D.current.settingsOpen?[...t.querySelectorAll("[data-bot-id]")].find(J=>J.dataset.botId===D.current.selectedId)?.getBoundingClientRect():void 0,ee=T?C.width/2-(T.left-C.left+T.width/2):(C.width-p.width)/2,ae=T?C.height/2-(T.top-C.top+T.height/2):(C.height-p.height)/2;B(J=>({...J,x:J.x+ee,y:J.y+ae}))}p={width:C.width,height:C.height}});return d.observe(t),()=>d.disconnect()},[te]);const le=JSON.stringify(f.map(({key:t,width:p,height:d})=>[t,p,d]));a.useEffect(()=>{te()},[te,le,pe]),a.useEffect(()=>{const t=j.current?.querySelector("details[open]"),p=j.current?.getBoundingClientRect();t&&p&&ve(t.getBoundingClientRect().bottom>p.bottom-210*u.scale?t.closest("[data-team-key]")?.dataset.teamKey??null:null)},[u,le]),a.useEffect(()=>{const t=j.current;if(!t)return;const p=d=>{if(d.target.closest("details[open]")||(d.preventDefault(),E.current))return;const C=D.current.view,T=t.getBoundingClientRect();if(d.ctrlKey||d.metaKey){const ee=Math.min(1.5,Math.max(.3,C.scale*Math.exp(-d.deltaY*.006)));B(at(C,ee,{x:d.clientX-T.left,y:d.clientY-T.top}))}else{const ee=d.deltaMode===1?16:d.deltaMode===2?T.height:1;B({...C,x:C.x-d.deltaX*ee,y:C.y-d.deltaY*ee})}};return t.addEventListener("wheel",p,{passive:!1}),()=>t.removeEventListener("wheel",p)},[]);const Z=t=>{if(t.button!==0||!t.isPrimary||E.current)return;const p=t.target,d=p.closest("[data-bot-id]")?.dataset.botId,C=p.closest("[data-arrange-team]")?.dataset.arrangeTeam,T=d?n.flatMap(J=>[...J.chiefs,...J.members]).find(J=>J.id===d):void 0;if(!T&&C===void 0&&p.closest("button, details, a, input, [data-team-key]")||T&&(ie||!pe)||C!==void 0&&!pe)return;const ee={id:t.pointerId,start:{x:t.clientX,y:t.clientY},view:u,positions:K,moved:!1},ae=C===void 0?void 0:f.find(J=>J.key===C);E.current=T?{...ee,kind:"bot",bot:T}:ae?{...ee,kind:"team",key:ae.key,origin:ae}:{...ee,kind:"pan"},$.current=!1},nt=(t,p)=>{const d=document.elementFromPoint(t,p)?.closest("[data-team-key]");return d&&j.current?.contains(d)?d.dataset.teamKey??null:null},st=(t,p)=>{const d=n.find(J=>J.key===(t.section?.trim()??""));if(!d)return null;const C=ke(t.chiefOfStaff?d.chiefs:d.members,m(d.key)),T=C.filter(J=>J.id!==t.id),ee=[...j.current?.querySelectorAll("[data-bot-id]")??[]],ae=T.findIndex(J=>{const P=ee.find(X=>X.dataset.botId===J.id)?.closest("article")?.getBoundingClientRect();return P?p<P.top+P.height/2:!1});return{section:d,lane:C,remaining:T,index:ae<0?T.length:ae}},gt=t=>{const p=E.current;if(!p||p.id!==t.pointerId)return;if(t.buttons===0){Ce(t,!0);return}const d=t.clientX-p.start.x,C=t.clientY-p.start.y;if(!(!p.moved&&Math.hypot(d,C)<5)&&(p.moved=!0,t.currentTarget.setPointerCapture(t.pointerId),p.kind==="pan"&&B({...p.view,x:p.view.x+d,y:p.view.y+C}),p.kind==="team"&&G({...p.positions,[p.key]:{x:p.origin.x+d/u.scale,y:p.origin.y+C/u.scale}}),p.kind==="bot")){const T=t.currentTarget.getBoundingClientRect();O({bot:p.bot,point:{x:t.clientX-T.left,y:t.clientY-T.top}});const ee=nt(t.clientX,t.clientY),ae=ee===(p.bot.section?.trim()??"");F(ae||r?ee:null);const J=ae?st(p.bot,t.clientY):null,P=J?.remaining[J.index]??J?.remaining.at(-1);ce(J&&P?{botId:P.id,after:J.index===J.remaining.length}:null)}},Ce=(t,p=!1)=>{const d=E.current;if(!(!d||t&&d.id!==t.pointerId)){if(E.current=null,$.current=d.moved,window.setTimeout(()=>{$.current=!1},0),O(null),F(null),ce(null),j.current?.hasPointerCapture(d.id)&&j.current.releasePointerCapture(d.id),p){G(d.positions),B(d.view);return}if(d.moved&&(d.kind==="team"&&t&&Q({...d.positions,[d.key]:{x:d.origin.x+(t.clientX-d.start.x)/d.view.scale,y:d.origin.y+(t.clientY-d.start.y)/d.view.scale}}),d.kind==="bot"&&t)){const C=nt(t.clientX,t.clientY);if(C===null)return;if(C===(d.bot.section?.trim()??"")){const T=st(d.bot,t.clientY);T&&L(T.section,T.lane,d.bot,T.index);return}if(!r)return;re(d.bot.id),me(s("canvas.reviewMove",{name:d.bot.name,team:C||s("settings.section.general")})),i(d.bot,C).then(T=>{me(T===!1?s("canvas.moveCancelled"):s("canvas.moved",{name:d.bot.name,team:C||s("settings.section.general")}))}).catch(T=>{me(T instanceof Error?T.message:String(T))}).finally(()=>re(null))}}},De=t=>{const p=j.current?.getBoundingClientRect();p&&B(at(u,Math.max(.3,Math.min(1.5,u.scale*t)),{x:p.width/2,y:p.height/2}))},ze=new Map(n.flatMap(t=>[...t.chiefs,...t.members]).map(t=>[t.id,t])),bt=new Map(y.map(t=>[t.id,t])),yt=t=>{const p=t.botIds.flatMap(d=>ze.get(d)??[]);return t.state==="idle"&&p.some(d=>d.busy)?"working":t.state!=="working"&&p.some(d=>b.computerStarts[d.id])?"starting":t.state},Le=n.find(t=>t.key===M),Pe=oe!==null?s("canvas.assignComputer",{team:n.find(t=>t.key===oe)?.name??oe}):N&&Le?(N.bot.section?.trim()??"")===Le.key?s("canvas.arrangeBot",{name:N.bot.name,team:Le.name}):s("canvas.moveBot",{name:N.bot.name,team:Le.name}):null;return e.jsxs("div",{ref:j,role:"region","aria-label":s("canvas.region"),tabIndex:0,"data-team-canvas":!0,className:"relative min-h-0 flex-1 touch-none overflow-clip outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent/40",style:{backgroundImage:"radial-gradient(circle, color-mix(in srgb, var(--color-ink-secondary) 18%, transparent) 1px, transparent 1px)",backgroundSize:`${24*u.scale}px ${24*u.scale}px`,backgroundPosition:`${u.x}px ${u.y}px`},onPointerDown:Z,onPointerMove:gt,onPointerUp:t=>Ce(t),onPointerCancel:t=>Ce(t,!0),onDragOver:t=>{if(!r||!x||!t.dataTransfer.types.includes(qe))return;const p=t.target.closest("[data-team-key]"),d=p&&t.currentTarget.contains(p)?p.dataset.teamKey??null:null;w(d),d!==null&&(t.preventDefault(),t.dataTransfer.dropEffect="link")},onDragLeave:t=>{(!(t.relatedTarget instanceof Node)||!t.currentTarget.contains(t.relatedTarget))&&w(null)},onDrop:t=>{if(w(null),!r||!x||!t.dataTransfer.types.includes(qe))return;const p=t.target.closest("[data-team-key]"),d=p&&t.currentTarget.contains(p)?p.dataset.teamKey:void 0,C=t.dataTransfer.getData(qe);d===void 0||!n.some(T=>T.key===d)||!C||(t.preventDefault(),x(C,d))},onDragEnd:()=>w(null),onPointerDownCapture:t=>{W.current=!1,t.target.closest("details")||t.currentTarget.querySelectorAll("details[open]").forEach(p=>p.removeAttribute("open"))},onKeyDownCapture:t=>{t.key==="Tab"&&(W.current=!0)},onPointerLeave:()=>{E.current&&!E.current.moved&&Ce(void 0,!0)},onLostPointerCapture:()=>{E.current&&Ce(void 0,!0)},onFocusCapture:t=>{if(!W.current||!(t.target instanceof HTMLElement)||!t.target.closest("[data-canvas-world]"))return;const p=t.currentTarget.getBoundingClientRect(),d=t.target.getBoundingClientRect(),C=d.left<p.left+16?p.left+16-d.left:d.right>p.right-16?p.right-16-d.right:0,T=d.top<p.top+16?p.top+16-d.top:d.bottom>p.bottom-70?p.bottom-70-d.bottom:0;(C||T)&&B(ee=>({...ee,x:ee.x+C,y:ee.y+T}))},onClickCapture:t=>{$.current&&($.current=!1,t.preventDefault(),t.stopPropagation())},onKeyDown:t=>{if(t.key==="Escape"&&(Ce(void 0,!0),t.currentTarget.querySelectorAll("details[open]").forEach(C=>{C.querySelector("summary")?.focus({preventScroll:!0}),C.removeAttribute("open")})),t.target!==t.currentTarget)return;const d={ArrowLeft:{x:60,y:0},ArrowRight:{x:-60,y:0},ArrowUp:{x:0,y:60},ArrowDown:{x:0,y:-60}}[t.key];d&&(t.preventDefault(),B({...u,x:u.x+d.x,y:u.y+d.y})),(t.key==="+"||t.key==="=")&&(t.preventDefault(),De(1.2)),t.key==="-"&&(t.preventDefault(),De(1/1.2)),t.key==="0"&&(t.preventDefault(),te())},children:[e.jsx("div",{"data-canvas-world":!0,className:"absolute left-0 top-0 origin-top-left",style:{transform:`translate(${u.x}px, ${u.y}px) scale(${u.scale})`},children:n.map((t,p)=>{const d=f[p],C=de[p],T=t.chiefs.length>0&&t.members.length>0,ee=oe===t.key||N&&M===t.key&&(N.bot.section?.trim()??"")!==t.key,ae=Object.hasOwn(h,t.key)?h[t.key]:void 0,J=P=>e.jsxs("div",{className:"relative",children:[Y?.botId===P.id&&e.jsx("div",{className:se("pointer-events-none absolute inset-x-1 h-0.5 rounded bg-accent",Y.after?"-bottom-[9px]":"-top-[9px]")}),e.jsx(On,{bot:P,selected:b.selectedId===P.id&&b.settingsOpen,moving:N?.bot.id===P.id||ie===P.id,connected:k.includes(P.id),tagged:A.includes(P.id),sent:H?.botIds.includes(P.id)?H.key:void 0,onComputer:g,onArrange:pe?V:void 0})]},P.id);return e.jsxs("section",{"data-team-key":t.key,"aria-label":s("canvas.teamRegion",{name:t.name}),className:se("absolute rounded-2xl border bg-panel/90 shadow-sm has-[details[open]]:z-20 data-[computer-dropping=true]:border-accent data-[computer-dropping=true]:ring-2 data-[computer-dropping=true]:ring-accent/25",ee?"border-accent ring-2 ring-accent/25":"border-hairline/50"),style:{left:d.x,top:d.y,width:d.width,height:d.height},children:[e.jsxs("header",{className:"flex h-16 items-center gap-2 px-5",children:[e.jsx("button",{"data-arrange-team":t.key,disabled:!pe,"aria-label":s("canvas.arrange",{name:t.name}),title:s("canvas.arrangeHint"),className:"min-w-0 flex-1 cursor-grab rounded-md py-2 text-left active:cursor-grabbing focus-visible:outline-2 focus-visible:outline-accent",onKeyDown:P=>{const X={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]}[P.key];if(!X)return;P.preventDefault(),P.stopPropagation();const ye=P.shiftKey?40:10;Q({...K,[t.key]:{x:d.x+X[0]*ye,y:d.y+X[1]*ye}})},children:e.jsx("h2",{className:"truncate text-[13px] font-semibold tracking-tight",children:t.name})}),ae&&e.jsxs("button",{"aria-label":s("canvas.teamComputer",{team:t.name,name:ae.name}),title:`${ae.name}${ae.state?` · ${ae.state}`:""}`,disabled:!I,onClick:()=>I?.(t.key),className:"flex min-w-0 max-w-[120px] shrink items-center gap-1.5 rounded-md px-1.5 py-2 text-[10px] text-ink-secondary hover:bg-control hover:text-ink focus-visible:outline-2 focus-visible:outline-accent disabled:pointer-events-none",children:[e.jsx(Oe,{size:12,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:ae.name})]}),e.jsx("span",{className:"text-[11px] tabular-nums text-ink-secondary",children:t.chiefs.length+t.members.length}),r&&e.jsxs("details",{className:"relative",onToggle:P=>{if(P.currentTarget.open){const X=j.current?.getBoundingClientRect();ve(X&&P.currentTarget.getBoundingClientRect().bottom>X.bottom-210*u.scale?t.key:null),j.current?.querySelectorAll("details[open]").forEach(ye=>{ye!==P.currentTarget&&ye.removeAttribute("open")})}},children:[e.jsx("summary",{"aria-label":s("canvas.manageTeam",{name:t.name}),className:se(Ae,"cursor-pointer list-none [&::-webkit-details-marker]:hidden"),children:e.jsx(wt,{size:17})}),e.jsxs("div",{className:se("absolute right-0 z-30 w-[220px] animate-pop-in rounded-xl border border-hairline bg-panel p-1.5 shadow-xl",be===t.key?"bottom-10":"top-10"),onClick:P=>{const X=P.currentTarget.closest("details");X?.querySelector("summary")?.focus(),X?.removeAttribute("open")},children:[e.jsxs("button",{className:Ie,onClick:()=>l(t.key),"aria-label":s("team.moveTo",{name:t.name}),children:[e.jsx(dt,{size:14}),s("team.moveTo",{name:t.name})]}),e.jsxs("button",{className:Ie,onClick:()=>c(t.key,t.name),"aria-label":s("team.instructionsEdit",{name:t.name}),children:[e.jsx(ut,{size:14}),s("team.instructions")]}),o&&e.jsxs("button",{className:Ie,onClick:()=>o(t.key,t.name),"aria-label":s("team.memoryFor",{name:t.name}),children:[e.jsx(mt,{size:14}),s("team.memory")]}),t.key&&e.jsxs("button",{className:Ie,onClick:()=>l(t.key,!0),"aria-label":s("team.renameAria",{name:t.name}),children:[e.jsx(Mt,{size:14}),s("team.rename")]}),t.key&&e.jsxs("button",{className:se(Ie,"hover:text-danger"),onClick:()=>S(t.key),"aria-label":s("team.deleteAria",{name:t.name}),children:[e.jsx(pt,{size:14}),s("team.delete")]})]})]})]}),ee&&e.jsx("div",{className:"pointer-events-none absolute -top-7 left-2 z-30 max-w-[calc(100%-16px)] truncate rounded-md bg-accent px-2 py-1 text-[10px] text-white shadow-sm",children:Pe}),C?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 overflow-visible",width:d.width,height:d.height,children:[C.tree.map((P,X)=>e.jsx("path",{d:rt(P),fill:"none",strokeWidth:1.5,className:"stroke-ink-secondary/25"},`tree-${X}`)),C.links.map(P=>{const X=ze.get(P.botId)?.busy===!0;return e.jsx("path",{d:rt(P.points),fill:"none",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:X?2.25:1.5,strokeDasharray:X?"7 5":void 0,className:X?"animate-link-flow stroke-success/80":"stroke-ink-secondary/35"},`${P.botId}:${P.computerId}`)})]}),C.cards.map(P=>{const X=ze.get(P.botId);return X?e.jsx("div",{className:"absolute",style:{left:P.x,top:P.y},children:J(X)},X.id):null}),C.monitors.map(P=>{const X=bt.get(P.id);if(!X)return null;const ye=X.botIds.flatMap(Ue=>ze.get(Ue)??[]);return e.jsx(Rn,{computer:X,bots:ye,x:P.x,y:P.y,frameUrl:Object.hasOwn(z,X.id)?z[X.id].url:void 0,state:yt(X),activity:Dn(ye.find(Ue=>Ue.busy),b.instances),onOpen:U?()=>U(X):void 0},X.id)})]}):e.jsxs("div",{className:"flex items-center px-5 pb-5",children:[t.chiefs.length>0&&e.jsx("div",{className:"flex flex-col gap-4",children:ke(t.chiefs,m(t.key)).map(J)}),T&&e.jsx("div",{className:"flex w-10 shrink-0 justify-center text-ink-secondary/35","aria-hidden":"true",children:e.jsx(ft,{size:22,strokeWidth:1})}),t.members.length>0&&e.jsx("div",{className:"flex flex-col gap-4",children:ke(t.members,m(t.key)).map(J)}),t.chiefs.length+t.members.length===0&&e.jsx("p",{className:"flex h-[126px] w-[236px] items-center justify-center rounded-xl border border-dashed border-hairline/70 px-6 text-center text-[12px] leading-relaxed text-ink-secondary",children:s("canvas.dropHere")})]})]},t.key)})}),N&&e.jsxs("div",{className:"pointer-events-none absolute z-40 rounded-xl border border-accent/40 bg-card px-4 py-3 text-[13px] shadow-lg",style:{left:N.point.x+16,top:N.point.y+16},children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ze,{bot:N.bot,size:24,animated:!1}),N.bot.name]}),Pe&&e.jsx("p",{className:"mt-1 text-[10px] text-ink-secondary",children:Pe})]}),e.jsxs("div",{className:"pointer-events-none absolute inset-x-5 bottom-5 flex items-end justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 rounded-lg bg-app/90 px-2 py-1.5 text-[11px] text-ink-secondary",children:[!v&&e.jsx("p",{className:"max-sm:hidden",children:s("canvas.hint")}),e.jsx("p",{role:"status","aria-live":"polite",className:"max-w-[440px]",children:Pe??xe})]}),e.jsxs("div",{className:"pointer-events-auto flex shrink-0 items-center gap-0.5 rounded-xl border border-hairline/60 bg-panel p-1 shadow-sm",children:[e.jsx("button",{className:Ae,"aria-label":s("canvas.zoomOut"),onClick:()=>De(1/1.2),children:e.jsx(Tt,{size:15})}),e.jsxs("button",{className:"min-w-12 rounded-md px-1 py-2 text-[11px] tabular-nums text-ink-secondary hover:bg-control","aria-label":s("canvas.fit"),title:s("canvas.fitHint"),onClick:te,children:[Math.round(u.scale*100),"%"]}),e.jsx("button",{className:Ae,"aria-label":s("canvas.zoomIn"),onClick:()=>De(1.2),children:e.jsx(Ke,{size:15})})]})]})]})}const lt=[{kind:"person",titleKey:"teamMemory.kind.people",hintKey:"teamMemory.kind.peopleHint"},{kind:"place",titleKey:"teamMemory.kind.places",hintKey:"teamMemory.kind.placesHint"},{kind:"decision",titleKey:"teamMemory.kind.decisions",hintKey:"teamMemory.kind.decisionsHint"},{kind:"term",titleKey:"teamMemory.kind.terms",hintKey:"teamMemory.kind.termsHint"}];function Ln({section:n,label:r,onClose:i}){const c=a.useRef(null),[o,l]=a.useState(null),[S,g]=a.useState([]),[x,I]=a.useState({}),[h,k]=a.useState(null),[y,z]=a.useState(null),U=a.useRef(!1),A=a.useRef(0),[H,v]=a.useState(!1),[b,j]=a.useState({kind:"term",name:"",detail:""}),E=`section=${encodeURIComponent(n)}`,$=a.useCallback(async()=>{const u=++A.current;try{const B=await ne(`/api/team-memory?${E}`);if(A.current!==u)return;l(B.entries),g(B.loadedIds),k(null)}catch(B){if(A.current!==u)return;k(B instanceof Error?B.message:String(B))}},[E]);a.useEffect(()=>(l(null),k(null),$(),()=>{A.current+=1}),[$]),a.useEffect(()=>{const u=document.activeElement instanceof HTMLElement?document.activeElement:null;c.current?.focus();const B=N=>{if(N.key==="Escape"&&(N.preventDefault(),i()),N.key==="Tab"){const O=c.current?.querySelectorAll("button:enabled, input:enabled, select:enabled");if(!O?.length)return;const M=O[0],F=O[O.length-1];N.shiftKey&&document.activeElement===M?(N.preventDefault(),F.focus()):!N.shiftKey&&document.activeElement===F&&(N.preventDefault(),M.focus())}};return window.addEventListener("keydown",B),()=>{window.removeEventListener("keydown",B),u?.focus()}},[i]);const W=async(u,B)=>{if(U.current)return!1;U.current=!0;const N=++A.current;z(u??"new"),k(null);try{const O=await B();return A.current!==N?!1:(l(O.entries),z(null),O.loadedIds?g(O.loadedIds):$(),!0)}catch(O){return A.current===N&&k(O instanceof Error?O.message:String(O)),!1}finally{U.current=!1,A.current===N&&z(null)}},_=u=>W(u.id,()=>ne(`/api/team-memory/${u.id}?${E}`,{method:"PATCH",body:JSON.stringify({accept:!0,expectedRevision:u.revision})})),K=u=>W(u.id,()=>ne(`/api/team-memory/${u.id}?${E}&revision=${u.revision}`,{method:"DELETE"})),G=(u,B,N)=>{B.trim()===u.detail&&(N===void 0||N===u.name)||W(u.id,()=>ne(`/api/team-memory/${u.id}?${E}`,{method:"PATCH",body:JSON.stringify({detail:B,...N===void 0?{}:{name:N},expectedRevision:u.revision})})).then(O=>I(M=>{const F={...M};return O?delete F[u.id]:F[u.id]={name:N??u.name,text:B},F}))},R=()=>{!b.name.trim()||!b.detail.trim()||W(null,()=>ne(`/api/team-memory?${E}`,{method:"POST",body:JSON.stringify(b)})).then(u=>{u&&(j({kind:b.kind,name:"",detail:""}),v(!1))})},q=(o??[]).filter(u=>u.status==="proposed");return et.createPortal(e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/55 p-4 sm:p-6",onMouseDown:u=>u.target===u.currentTarget&&i(),children:e.jsxs("div",{ref:c,role:"dialog","aria-modal":"true","aria-labelledby":"team-memory-title",tabIndex:-1,className:"animate-pop-in flex max-h-[min(720px,calc(100dvh-2rem))] w-full max-w-[720px] flex-col overflow-hidden rounded-2xl border border-hairline/50 bg-panel shadow-2xl shadow-black/50 outline-none",children:[e.jsxs("header",{className:"flex items-start justify-between gap-4 border-b border-hairline/40 px-6 pb-4 pt-6 sm:px-8 sm:pt-7",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(mt,{size:19,className:"text-accent"}),e.jsx("h2",{id:"team-memory-title",className:"text-[20px] font-semibold tracking-[-0.01em] text-ink",children:s("teamMemory.title",{name:r})})]}),e.jsx("p",{className:"mt-1.5 max-w-[560px] text-[13px] leading-relaxed text-ink-secondary",children:s("teamMemory.description")})]}),e.jsx("button",{onClick:i,"aria-label":s("teamMemory.close"),className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-raised hover:text-ink",children:e.jsx(Be,{size:19})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-5 sm:px-8",children:[o===null&&!h&&e.jsx("div",{className:"flex min-h-[200px] items-center justify-center text-ink-secondary",children:e.jsx(Re,{size:20,className:"animate-spin","aria-label":s("teamMemory.loading")})}),o&&e.jsx("p",{className:"mb-3 text-[12px] text-ink-secondary",children:s("teamMemory.loadedSummary",{loaded:S.length,total:o.filter(u=>u.status==="accepted").length})}),h&&e.jsxs("div",{role:"alert",className:"mb-3 rounded-lg border border-danger/30 bg-danger/10 px-3 py-2 text-[12px] text-danger",children:[h," ",e.jsx("button",{onClick:()=>{$()},className:"underline",children:s("teamMemory.reload")})]}),Object.entries(x).map(([u,B])=>e.jsxs("p",{className:"mb-3 text-[12px] text-ink-secondary",children:[e.jsx("strong",{children:B.name})," · ",s("teamMemory.unsaved",{text:B.text})]},u)),q.length>0&&e.jsxs("section",{className:"mb-5 rounded-xl border border-accent/30 bg-accent/5 p-3",children:[e.jsx("h3",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-accent",children:s("teamMemory.waiting")}),e.jsx("ul",{className:"mt-2 space-y-2",children:q.map(u=>e.jsxs("li",{className:"flex items-start gap-3 text-[13px]",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"text-ink-secondary",children:[s(`teamMemory.kind.${u.kind}`),": "]}),e.jsx("span",{className:"font-medium text-ink",children:u.name}),u.aliases.length>0&&e.jsxs("span",{className:"text-ink-secondary",children:[" (",s("teamMemory.also")," ",u.aliases.join(", "),")"]}),e.jsxs("span",{className:"text-ink",children:[" — ",u.detail]}),e.jsxs("span",{className:"block text-[11px] text-ink-secondary",children:[s("teamMemory.source",{name:u.source.botName}),u.source.quote&&` · ${s("teamMemory.sourceQuote",{quote:u.source.quote})}`]})]}),e.jsxs("button",{onClick:()=>{_(u)},disabled:y!==null,className:"flex shrink-0 items-center gap-1 rounded-md bg-accent px-2.5 py-1 text-[12px] font-medium text-white disabled:opacity-50",children:[e.jsx(vt,{size:12})," ",s("teamMemory.remember")]}),e.jsx("button",{onClick:()=>{K(u)},disabled:y!==null,className:"shrink-0 rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:s("teamMemory.skip")})]},u.id))})]}),o!==null&&o.filter(u=>u.status==="accepted").length===0&&q.length===0&&e.jsx("div",{className:"rounded-xl bg-inset px-4 py-6 text-center text-[13px] text-ink-secondary",children:s("teamMemory.empty")}),lt.map(({kind:u,titleKey:B,hintKey:N})=>{const O=(o??[]).filter(M=>M.status==="accepted"&&M.kind===u);return O.length===0?null:e.jsxs("section",{className:"mb-5",children:[e.jsx("h3",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-ink-secondary",title:s(N),children:s(B)}),e.jsx("ul",{className:"mt-2 divide-y divide-hairline/20 rounded-xl bg-inset",children:O.map(M=>e.jsxs("li",{className:"flex items-start gap-3 px-3 py-2 text-[13px]",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"font-medium text-ink",children:M.name}),M.aliases.length>0&&e.jsxs("span",{className:"text-ink-secondary",children:[" (",s("teamMemory.also")," ",M.aliases.join(", "),")"]}),e.jsx("input",{defaultValue:M.detail,disabled:y!==null,onBlur:F=>G(M,F.target.value),onKeyDown:F=>{F.key==="Enter"&&F.target.blur()},"aria-label":s("teamMemory.entryDetailLabel",{name:M.name}),className:"mt-0.5 block w-full rounded bg-transparent px-1 py-0.5 text-[13px] text-ink outline-none hover:bg-card focus:bg-card"},M.revision),e.jsxs("span",{className:"block px-1 text-[11px] text-ink-secondary",children:[M.source.botName||s("teamMemory.you")," · ",new Date(M.updatedAt).toLocaleDateString(Ee())," · ",S.includes(M.id)?s("teamMemory.loaded"):s("teamMemory.searchable")]}),!!M.history?.length&&e.jsxs("details",{className:"mt-1 text-[11px] text-ink-secondary",children:[e.jsx("summary",{children:s("teamMemory.history")}),M.history.map((F,oe)=>e.jsxs("div",{className:"mt-1",children:[new Date(F.at).toLocaleDateString(Ee()),": ",F.name," — ",F.detail," ",e.jsx("button",{disabled:y!==null,onClick:()=>G(M,F.detail,F.name),className:"underline",children:s("teamMemory.restore")})]},oe))]})]}),e.jsx("button",{"aria-label":s(M.pinned?"teamMemory.unpin":"teamMemory.pin",{name:M.name}),"aria-pressed":M.pinned??!1,disabled:y!==null,className:"p-1 text-ink-secondary hover:text-accent",onClick:()=>{W(M.id,()=>ne(`/api/team-memory/${M.id}?${E}`,{method:"PATCH",body:JSON.stringify({pinned:!M.pinned,expectedRevision:M.revision})}))},children:e.jsx(Lt,{size:13})}),e.jsx("button",{onClick:()=>{K(M)},disabled:y!==null,"aria-label":s("teamMemory.remove",{name:M.name}),className:"shrink-0 rounded-md p-1 text-ink-secondary hover:text-danger disabled:opacity-50",children:e.jsx(pt,{size:13})})]},M.id))})]},u)}),H?e.jsxs("div",{className:"rounded-xl border border-hairline/40 bg-card p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(xt,{size:"sm",value:b.kind,onChange:u=>j({...b,kind:u.target.value}),"aria-label":s("teamMemory.kindLabel"),children:lt.map(({kind:u})=>e.jsx("option",{value:u,children:s(`teamMemory.kind.${u}`)},u))}),e.jsx("input",{value:b.name,onChange:u=>j({...b,name:u.target.value}),placeholder:s("teamMemory.namePlaceholder"),"aria-label":s("teamMemory.nameLabel"),className:"min-w-[140px] flex-1 rounded-lg border border-hairline/40 bg-inset px-2 py-1 text-[13px] text-ink outline-none focus:border-accent"})]}),e.jsx("input",{value:b.detail,onChange:u=>j({...b,detail:u.target.value}),onKeyDown:u=>{u.key==="Enter"&&R()},placeholder:s("teamMemory.detailPlaceholder"),"aria-label":s("teamMemory.detailLabel"),className:"mt-2 w-full rounded-lg border border-hairline/40 bg-inset px-2 py-1 text-[13px] text-ink outline-none focus:border-accent"}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("button",{onClick:R,disabled:y!==null||!b.name.trim()||!b.detail.trim(),className:"rounded-lg bg-accent px-3 py-1 text-[13px] font-medium text-white disabled:opacity-50",children:y==="new"?s("teamMemory.adding"):s("teamMemory.add")}),e.jsx("button",{onClick:()=>v(!1),className:"text-[13px] text-ink-secondary hover:text-ink",children:s("common.cancel")})]})]}):e.jsxs("button",{onClick:()=>v(!0),className:se("flex items-center gap-1.5 text-[13px] text-ink-secondary hover:text-ink",o===null&&"hidden"),children:[e.jsx(Ke,{size:13})," ",s("teamMemory.addEntry")]})]})]})}),document.body)}const he="rounded-lg px-3 py-2 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",Pn="w-full rounded-lg border border-hairline/60 bg-inset px-3 py-2 text-[12px] text-ink outline-none focus:border-accent";function $n(n,r){if(r)return s("canvasComputers.updating");const i={idle:"idle",ready:"ready",running:"running",init:"starting",provisioning:"provisioning",provisioned:"starting",cloning:"starting",starting:"starting",sleeping:"sleeping"}[n];return i?s(`canvasComputers.state.${i}`):n}function _n({open:n,createRequest:r,drop:i,sections:c,onClose:o,onDropHandled:l,onChange:S}){const{dispatch:g}=Ne(),[x,I]=a.useState(null),[h,k]=a.useState(!1),[y,z]=a.useState(""),[U,A]=a.useState(""),[H,v]=a.useState(null),[b,j]=a.useState(!1),[E,$]=a.useState(""),W=a.useRef($e()),_=a.useRef(null),K=a.useRef(null),G=a.useRef(null),R=a.useRef(!1),q=a.useRef(!0),u=a.useRef(null),B=a.useRef(S);B.current=S;const[N,O]=a.useState(null),[M,F]=a.useState(null),[oe,w]=a.useState(null),Y=a.useRef($e()),ce=a.useRef(null),ie=a.useRef(null),re=a.useRef(null),xe=a.useRef(null),[me,pe]=a.useState(null),ue=a.useCallback(()=>{const m=re.current;re.current=null,xe.current?.removeAttribute("data-computer-dropping"),xe.current=null,m?.handle.hasPointerCapture(m.id)&&m.handle.releasePointerCapture(m.id),pe(null)},[]);a.useEffect(()=>(n||ue(),()=>{xe.current?.removeAttribute("data-computer-dropping")}),[n,ue]),a.useEffect(()=>{ce.current=oe},[oe]),a.useEffect(()=>()=>{const m=ce.current;m&&fetch(`/api/team-computers/${encodeURIComponent(m)}/control`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"release",controlLeaseId:Y.current}),keepalive:!0}).catch(()=>{})},[]);const be=a.useCallback((m,L)=>{if(!(R.current||m.section===L)){if(m.section!==null&&L!==null){z(s("canvasComputers.unassignBeforeMove",{computer:m.name,team:m.section||s("settings.section.general")}));return}z(""),O({computer:m,section:L})}},[]),ve=(m,L)=>{const V=ie.current?.parentElement?.querySelector("[data-team-canvas]"),te=document.elementFromPoint(m,L)?.closest("[data-team-key]");return te&&V?.contains(te)&&c.some(le=>le.key===te.dataset.teamKey)?te:null},ge=m=>{const L=re.current;if(!L||m.pointerId!==L.id)return;if(m.buttons===0){ue();return}if(!L.moved&&Math.hypot(m.clientX-L.x,m.clientY-L.y)<5)return;L.moved=!0,m.currentTarget.setPointerCapture(m.pointerId);const V=ve(m.clientX,m.clientY);xe.current!==V&&(xe.current?.removeAttribute("data-computer-dropping"),V?.setAttribute("data-computer-dropping","true"),xe.current=V);const te=V?c.find(le=>le.key===V.dataset.teamKey):null;pe({name:L.computer.name,x:m.clientX,y:m.clientY,hint:te?L.computer.section!==null&&L.computer.section!==te.key?s("canvasComputers.unassignBeforeMoving"):s("canvasComputers.assignTo",{team:te.name}):s("canvasComputers.dropOntoTeam")})},Se=m=>{const L=re.current;if(!L||L.id!==m.pointerId)return;const V=L.moved?ve(m.clientX,m.clientY)?.dataset.teamKey:void 0;ue(),V!==void 0&&be(L.computer,V)},de=a.useCallback(async(m=!1)=>{u.current?.abort();const L=new AbortController;u.current=L,k(!0);try{const V=await ne("/api/team-computers",{signal:AbortSignal.any([L.signal,AbortSignal.timeout(3e4)]),background:m});if(L.signal.aborted||!q.current)return;I(V),A(""),B.current(V.computers)}catch(V){!L.signal.aborted&&q.current&&A(V instanceof Error?V.message:String(V))}finally{!L.signal.aborted&&q.current&&k(!1)}},[]);a.useEffect(()=>(q.current=!0,de(),()=>{q.current=!1,u.current?.abort()}),[de]),a.useEffect(()=>{if(!n)return;de();const m=window.setInterval(()=>{!R.current&&document.visibilityState==="visible"&&de(!0)},2e4);return()=>window.clearInterval(m)},[n,de]),a.useEffect(()=>{r>0&&j(!0)},[r]),a.useEffect(()=>{if(!n)return;const m=document.activeElement instanceof HTMLElement?document.activeElement:null;return G.current?.focus(),()=>{m?.isConnected&&m.focus()}},[n]),a.useEffect(()=>{n&&b&&K.current?.focus()},[n,b]),a.useEffect(()=>{if(!i)return;const m=x?.computers.find(L=>L.id===i.id);m&&be(m,i.section),l()},[i,x,l,be]);const fe=async(m,L,V,te)=>{if(!R.current){R.current=!0,v(m),z(""),u.current?.abort();try{const le=await L();q.current&&V?.(le)}catch(le){q.current&&(z(le instanceof Error?le.message:String(le)),te?.())}finally{R.current=!1,q.current&&(v(null),await de())}}},f=a.useCallback(()=>O(null),[]),D=(m,L,V={})=>ne(`/api/team-computers/${encodeURIComponent(m)}/${L}`,{method:"POST",body:JSON.stringify(V)}),Q=()=>{o(),g({type:"toggleAppSettings",open:!0,section:"computer"})};return e.jsxs(e.Fragment,{children:[n&&e.jsxs("aside",{ref:ie,"aria-label":s("canvasComputers.title"),onKeyDown:m=>{m.key==="Escape"&&!N&&(m.stopPropagation(),re.current?ue():o())},className:"flex w-[300px] max-w-[90vw] shrink-0 flex-col border-l border-hairline/50 bg-panel max-sm:absolute max-sm:inset-y-0 max-sm:right-0 max-sm:z-30 max-sm:shadow-xl",children:[e.jsxs("header",{className:"flex items-center gap-2 border-b border-hairline/40 px-4 py-3",children:[e.jsx(Oe,{size:16,className:"text-ink-secondary"}),e.jsx("h2",{className:"flex-1 text-[13px] font-semibold",children:s("canvasComputers.title")}),e.jsx("button",{"aria-label":s("canvasComputers.refresh"),className:he,disabled:h||H!==null,onClick:()=>{z(""),de()},children:e.jsx(en,{size:14,className:h?"animate-spin":""})}),e.jsx("button",{ref:G,"aria-label":s("canvasComputers.close"),className:he,onClick:o,children:e.jsx(Be,{size:15})})]}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-3 overflow-y-auto p-4",children:[e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:s("canvasComputers.hint")}),(y||U||x?.problem)&&e.jsx("p",{role:"alert",className:"rounded-lg bg-danger/10 p-3 text-[12px] text-danger",children:y||U||x?.problem}),x&&!x.configured&&e.jsxs("div",{className:"rounded-xl border border-hairline/50 p-3 text-[12px]",children:[e.jsx("p",{className:"text-ink-secondary",children:s("canvasComputers.connectBoatHint")}),e.jsx("button",{className:`${he} mt-2 border border-hairline/50`,onClick:Q,children:s("canvasComputers.connectBoat")})]}),b?e.jsxs("form",{className:"space-y-3 rounded-xl border border-hairline/60 bg-card p-3",onSubmit:m=>{m.preventDefault();const L=_.current??E.trim();!L||!x?.configured||(_.current=L,fe("create",()=>ne("/api/team-computers",{method:"POST",body:JSON.stringify({name:L,requestId:W.current,acknowledgeCost:!0})}),()=>{$(""),j(!1),W.current=$e(),_.current=null},()=>{_.current=null}))},children:[e.jsx("label",{className:"block text-[12px] font-medium",htmlFor:"canvas-computer-name",children:s("canvasComputers.newCloud")}),e.jsx("input",{ref:K,id:"canvas-computer-name",className:Pn,value:E,maxLength:60,placeholder:s("canvasComputers.namePlaceholder"),disabled:H!==null||_.current!==null,onChange:m=>$(m.target.value)}),e.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:s("canvasComputers.createHint")}),e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx("button",{type:"button",className:he,disabled:H!==null,onClick:()=>j(!1),children:s("common.cancel")}),e.jsxs("button",{type:"submit",className:"flex items-center gap-2 rounded-lg bg-accent px-3 py-2 text-[12px] font-medium text-white disabled:opacity-40",disabled:!x?.configured||!E.trim()||H!==null,children:[H==="create"&&e.jsx(Re,{size:13,className:"animate-spin"}),s("canvasComputers.create")]})]})]}):e.jsxs("button",{className:"flex w-full items-center justify-center gap-2 rounded-xl border border-dashed border-hairline/60 px-3 py-3 text-[12px] text-ink-secondary hover:bg-control hover:text-ink",disabled:H!==null,onClick:()=>j(!0),children:[e.jsx(Ke,{size:14})," ",s("canvasComputers.newCloud")]}),x?.computers.map(m=>{const L=["idle","ready","running"].includes(m.state),V=["init","provisioning","provisioned","cloning","starting"].includes(m.state),te=oe===m.id,le=m.held||te;return e.jsxs("article",{"data-computer-id":m.id,className:"rounded-xl border border-hairline/60 bg-card p-3",children:[e.jsxs("div",{"data-computer-drag-id":m.id,role:"group",tabIndex:-1,"aria-label":s("canvasComputers.dragToTeam",{name:m.name}),onPointerDown:Z=>{R.current||re.current||Z.button!==0||!Z.isPrimary||(Z.currentTarget.focus({preventScroll:!0}),re.current={id:Z.pointerId,x:Z.clientX,y:Z.clientY,moved:!1,computer:m,handle:Z.currentTarget},Z.currentTarget.setPointerCapture(Z.pointerId))},onPointerMove:ge,onPointerUp:Se,onPointerCancel:ue,onLostPointerCapture:()=>{re.current&&ue()},className:"flex touch-none select-none cursor-grab items-center gap-2.5 rounded-lg py-1 outline-none active:cursor-grabbing",children:[e.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-lg bg-control text-ink-secondary",children:e.jsx(Je,{size:18})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-[13px] font-medium",children:m.name}),e.jsxs("span",{className:"block text-[11px] text-ink-secondary",children:[s("canvasComputers.cloudComputer")," · ",$n(m.state,H===m.id)]})]})]}),m.problem&&e.jsx("p",{className:"mt-2 text-[11px] text-danger",children:m.problem}),e.jsx("label",{className:"sr-only",htmlFor:`computer-team-${m.id}`,children:s("canvasComputers.teamFor",{name:m.name})}),e.jsxs(xt,{id:`computer-team-${m.id}`,className:"mt-3 w-full",disabled:H!==null,value:m.section===null?"unassigned":`team:${m.section}`,onChange:Z=>be(m,Z.target.value==="unassigned"?null:Z.target.value.slice(5)),children:[e.jsx("option",{value:"unassigned",children:s("canvasComputers.unassigned")}),c.filter(Z=>m.section===null||Z.key===m.section).map(Z=>e.jsx("option",{value:`team:${Z.key}`,children:Z.name},Z.key))]}),m.section!==null&&e.jsx("p",{className:"mt-1.5 text-[10px] text-ink-secondary",children:s("canvasComputers.unassignHint")}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1",children:[!L&&!V&&e.jsx("button",{className:he,title:s("canvasComputers.startTitle"),disabled:H!==null||le,onClick:()=>{fe(m.id,()=>D(m.id,"provision",{acknowledgeCost:!0}))},children:s("canvasComputers.startRetry")}),L&&!le&&e.jsx("button",{className:he,disabled:H!==null,onClick:()=>{fe(m.id,()=>D(m.id,"sleep"))},children:s("canvasComputers.sleep")}),L&&e.jsxs("button",{className:`${he} flex items-center gap-1.5`,title:s("canvasComputers.openTitle"),disabled:H!==null,onClick:()=>{fe(m.id,async()=>(await D(m.id,"control",{action:"take",controlLeaseId:Y.current}),w(m.id),D(m.id,"join")),Z=>{typeof Z.joinUrl=="string"&&Z.joinUrl.startsWith("https://")&&F({id:m.id,url:Z.joinUrl})})},children:[s("canvasComputers.openDesktop")," ",e.jsx(Ct,{size:11})]}),te&&e.jsx("button",{className:`${he} text-accent`,disabled:H!==null,onClick:()=>{fe(m.id,()=>D(m.id,"control",{action:"release",controlLeaseId:Y.current}),()=>{w(null),F(null)})},children:s("canvasComputers.returnToBots")}),m.held&&!te&&e.jsx("button",{className:he,disabled:!0,title:s("canvasComputers.inUseTitle"),children:s("canvasComputers.inUse")})]}),M?.id===m.id&&e.jsxs("a",{href:M.url,target:"_blank",rel:"noopener noreferrer",className:"mt-2 block rounded-lg px-3 py-2 text-[12px] text-accent hover:bg-control",children:[s("canvasComputers.openSecure")," ",e.jsx(Pt,{size:14,"aria-hidden":"true",className:"inline align-[-2px]"})]})]},m.id)})]}),e.jsx("footer",{className:"border-t border-hairline/40 p-3",children:e.jsx("button",{className:`${he} w-full text-left`,onClick:Q,children:s("canvasComputers.moreSettings")})})]}),me&&et.createPortal(e.jsxs("div",{role:"status",className:"pointer-events-none fixed z-[70] rounded-xl border border-accent/40 bg-card px-4 py-3 text-[12px] text-ink shadow-xl",style:{left:me.x+14,top:me.y+14},children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Je,{size:15}),me.name]}),e.jsx("p",{className:"mt-1 text-[10px] text-ink-secondary",children:me.hint})]}),document.body),e.jsx(Ge,{open:N!==null,tone:"neutral",title:N?.section===null?s("canvasComputers.unassignTitle",{name:N?.computer.name??s("canvasComputers.computer")}):s("canvasComputers.assignTitle",{name:N?.computer.name??s("canvasComputers.computer"),team:N?.section||s("settings.section.general")}),body:N?.section===null?s("canvasComputers.unassignBody"):s("canvasComputers.assignBody"),confirmLabel:N?.section===null?s("canvasComputers.unassign"):s("canvasComputers.assign"),onCancel:f,onConfirm:()=>{const m=N;m&&(O(null),F(null),fe(m.computer.id,()=>ne(`/api/team-computers/${encodeURIComponent(m.computer.id)}`,{method:"PATCH",body:JSON.stringify({section:m.section,acknowledgeSharedAccess:!0})})))}})]})}function Hn(n,r,i){const c=r.filter(h=>!h.hidden&&h.name.trim()),o=[...c.map(h=>({name:h.name,tag:{kind:"bot",name:h.name,botIds:[h.id]}})),...i.filter(h=>h.name.trim()).map(h=>({name:h.name,tag:{kind:"team",name:h.name,botIds:c.filter(k=>(k.section?.trim()??"")===h.key).map(k=>k.id)}})),{name:"everyone",tag:{kind:"everyone",name:"everyone",botIds:c.map(h=>h.id)}}].sort((h,k)=>k.name.length-h.name.length),l=[],S=[],g=[];let x=-1;for(;(x=n.indexOf("@",x+1))!==-1;){if(!$t(n,x))continue;const h=n.slice(x+1),k=o.find(({name:z})=>h.slice(0,z.length).toLowerCase()===z.toLowerCase()&&!_t(h.slice(z.length)));if(k){l.push(k.tag),g.push([x,x+1+k.name.length]),x+=k.name.length;continue}const y=/^[\p{L}\p{N}\p{M}_.-]+/u.exec(h)?.[0];y&&S.push(y)}const I=g.reduceRight((h,[k,y])=>h.slice(0,k)+h.slice(y),n).replace(/\s+/g," ").trim();return{botIds:[...new Set(l.flatMap(h=>h.botIds))],tags:l,unknown:S,words:I}}function ct(n,r,i){if(!n.tags.some(l=>l.kind==="everyone"))return{botIds:n.botIds};if(i)return{botIds:n.botIds,text:n.words};const c=Kn(r);if(!c)return{botIds:n.botIds};const o=n.tags.filter(l=>l.kind!=="everyone").flatMap(l=>l.botIds);return{botIds:[...new Set([c.id,...o])],chief:c}}function Kn(n){const r=n.filter(i=>i.chiefOfStaff&&!i.hidden);return r.find(i=>!i.section?.trim())??r[0]}function Un(n,r=2){return n.length<=r+1?{names:[...n],more:0}:{names:n.slice(0,r),more:n.length-r}}function qn({bots:n,teams:r,onTagged:i,onSent:c}){const{dispatch:o}=Ne(),l=Qe(),S=Ht(),g=a.useRef(null),x=a.useRef(null),[I,h]=a.useState(""),[k,y]=a.useState(0),[z,U]=a.useState(null),[A,H]=a.useState(0),[v,b]=a.useState(null),j=a.useMemo(()=>n.filter(w=>!w.hidden),[n]),E=a.useMemo(()=>Hn(I,j,r),[I,j,r]),$=a.useMemo(()=>ct(E,j,!1),[E,j]),W=$.botIds.join(",");a.useEffect(()=>{i(W?W.split(","):[])},[W,i]),a.useEffect(()=>()=>i([]),[i]);const _=Kt(I,k),K=a.useMemo(()=>{if(!_||_.start===z)return[];const w=[...j.length>1?[{id:"__everyone__",name:"everyone",all:{count:j.length}}]:[],...r.filter(Y=>Y.count>0).map(Y=>({id:`team:${Y.key}`,name:Y.name,team:{count:Y.count}})),...j.map(Y=>({id:Y.id,name:Y.name,bot:Y}))];return Ut(w,_.query)},[_,z,j,r]),G=K.length>0,R=tn(G);a.useEffect(()=>H(0),[_?.start,_?.query]),a.useEffect(()=>{G&&x.current?.querySelector(`[data-mention-index="${A}"]`)?.scrollIntoView({block:"nearest"})},[A,G]);const q=w=>{if(!_)return;const Y=`${I.slice(0,_.start)}@${w.name} ${I.slice(k)}`,ce=_.start+w.name.length+2;h(Y),y(ce),U(_.start),requestAnimationFrame(()=>{g.current?.focus(),g.current?.setSelectionRange(ce,ce)})},u=I.trim().length>0&&E.botIds.length>0,B=async()=>{if(!u)return;const w=I.trim(),Y=E;h(""),y(0),U(null);const ce=$.chief?await ne("/api/stop-line",{method:"POST",body:JSON.stringify({text:Y.words})}).then(re=>re.stop===!0,()=>null):!1,ie=ce===null?{botIds:Y.botIds}:ct(Y,j,ce);for(const re of ie.botIds)o({type:"send",botId:re,text:ie.text||w,sendId:$e()});c(ie.botIds),b({botIds:ie.botIds,expanded:!1,...ie.chief?{chiefId:ie.chief.id}:{}})},N=v?.chiefId?j.find(w=>w.id===v.chiefId):void 0,O=(v?.botIds??[]).filter(w=>w!==N?.id).flatMap(w=>j.find(Y=>Y.id===w)??[]),M=Un(O.map(w=>w.name)),F=v?.expanded?O:O.slice(0,M.names.length),oe=I.trim()&&!E.botIds.length?s("mapComposer.tagHint"):$.chief?s("mapComposer.willSendViaChief",{name:$.chief.name}):null;return e.jsx(e.Fragment,{children:e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-5 z-30 flex justify-center px-4",children:e.jsxs("div",{className:"pointer-events-auto w-full max-w-[620px]",children:[v&&(N||O.length>0)&&e.jsxs("p",{role:"status",className:"mb-2 flex flex-wrap items-center gap-x-1 gap-y-0.5 rounded-xl bg-panel/95 px-3 py-1.5 text-[12px] text-ink-secondary shadow-sm ring-1 ring-hairline/50",children:[N&&e.jsxs("span",{children:[s("mapComposer.sentViaChief",{name:N.name}),O.length>0?" ·":""]}),O.length>0&&e.jsx("span",{children:s("mapComposer.sentTo")}),F.map((w,Y)=>e.jsxs("span",{children:[e.jsx("button",{className:"font-medium text-ink underline-offset-2 hover:underline",onClick:()=>tt(o,w,l),children:w.name}),Y<F.length-1?",":""]},w.id)),!v.expanded&&M.more>0&&e.jsx("button",{className:"text-ink underline-offset-2 hover:underline",onClick:()=>b({...v,expanded:!0}),children:s("mapComposer.andMore",{count:M.more})}),e.jsx("button",{"aria-label":s("common.close"),className:"ml-auto rounded p-0.5 hover:bg-control",onClick:()=>b(null),children:e.jsx(Be,{size:12})})]}),e.jsxs("div",{className:"relative flex items-end gap-2 rounded-2xl bg-composer px-3 py-2 shadow-lg ring-1 ring-composer-ring",children:[e.jsx(qt,{listRef:x,motion:R,choices:K,highlight:A,everyoneCount:j.length,onPick:q,onHighlight:H}),e.jsx(Ft,{inputRef:g,peers:[...j,...r.map(w=>({name:w.name}))],everyone:!0,"aria-label":s("mapComposer.label"),placeholder:s("mapComposer.placeholder"),dir:"auto",rows:1,value:I,className:"block max-h-[9rem] min-h-6 w-full resize-none overflow-y-auto bg-transparent px-1 py-1 text-[15px] leading-6 placeholder:text-ink-secondary focus:outline-none",onChange:w=>{h(w.target.value),y(w.target.selectionStart??w.target.value.length),U(null)},onKeyUp:w=>y(w.target.selectionStart??0),onClick:w=>y(w.target.selectionStart??0),onKeyDown:w=>{if(!Yt(w.nativeEvent)){if(G){if(w.key==="ArrowDown"||w.key==="ArrowUp"){w.preventDefault(),H(Y=>(Y+(w.key==="ArrowDown"?1:-1)+K.length)%K.length);return}if(w.key==="Enter"||w.key==="Tab"){w.preventDefault(),q(K[A]);return}if(w.key==="Escape"){w.preventDefault(),w.stopPropagation(),U(_?.start??null);return}}Xt(w.nativeEvent,S)&&(w.preventDefault(),B())}}}),e.jsx("button",{onClick:()=>{B()},disabled:!u,"aria-label":s("mapComposer.send"),title:u?$.botIds.length===1?s("mapComposer.sendToOne"):s("mapComposer.sendTo",{count:$.botIds.length}):s("mapComposer.tagHint"),className:se("mb-0.5 flex size-8 shrink-0 items-center justify-center rounded-full text-white transition-opacity",u?"bg-accent hover:brightness-110":"bg-ink-secondary/30"),children:e.jsx(Jt,{size:16})})]}),(oe||E.botIds.length>0)&&e.jsx("p",{className:"mt-1.5 px-3 text-[11px] text-ink-secondary",children:oe??($.botIds.length===1?s("mapComposer.willSendOne"):s("mapComposer.willSend",{count:$.botIds.length}))})]})})})}function Fn({edge:n,bots:r}){const{state:i,dispatch:c}=Ne(),o=Qe(),l=r.find(x=>x.id===n.sourceBotId),S=r.find(x=>x.id===n.targetBotId);if(!l||!S)return null;const g=n.state!=="connected";return e.jsxs("button",{onClick:()=>{!n.groupId&&n.threadId?Zt(c,{botId:S.id,threadId:n.threadId},i,o):n.groupId?c({type:"select",id:n.groupId}):tt(c,S,o)},className:"flex w-full items-center gap-3 rounded-xl border border-hairline/40 bg-card px-3 py-2.5 text-left transition hover:bg-raised/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-ink",children:l.name}),e.jsx(ft,{size:13,className:se("shrink-0",g?"text-accent":"text-ink-secondary")}),e.jsx("span",{className:"truncate text-[13px] font-medium text-ink",children:S.name})]}),n.reason&&e.jsx("span",{className:"max-w-[220px] truncate text-[12px] text-ink-secondary",children:n.reason}),e.jsx("span",{className:se("rounded-full px-2 py-0.5 text-[11px] font-medium",n.state==="running"?"bg-success/15 text-success":n.state==="queued"?"bg-warning/15 text-warning":"bg-control text-ink-secondary"),children:n.state==="running"?s("canvas.edge.running"):n.state==="queued"?s("canvas.edge.queued"):n.lastAt?kt(n.lastAt):s("canvas.edge.connected")})]})}function Yn({section:n,label:r,onClose:i}){const c=a.useRef(null),o=a.useRef(null),l=a.useRef(i),S=a.useRef(!1),g=a.useRef(!1),[x,I]=a.useState(""),[h,k]=a.useState(""),[y,z]=a.useState(24e3),[U,A]=a.useState(null),[H,v]=a.useState(!0),[b,j]=a.useState(!1),[E,$]=a.useState(null),W=x!==h,_=a.useMemo(()=>new TextEncoder().encode(x).byteLength,[x]);l.current=i,S.current=b,g.current=W;const K=a.useCallback(()=>{S.current||g.current&&!window.confirm(s("team.instructionsDiscard"))||l.current()},[]);a.useEffect(()=>{const R=document.activeElement instanceof HTMLElement?document.activeElement:null;c.current?.focus();const q=u=>{if(u.key==="Escape"&&!S.current){u.preventDefault(),K();return}if(u.key!=="Tab")return;const B=c.current;if(!B)return;const N=[...B.querySelectorAll('button:not([disabled]), textarea:not([disabled]), input:not([disabled]), [href], [tabindex]:not([tabindex="-1"])')];if(N.length===0){u.preventDefault(),B.focus();return}const O=N[0],M=N[N.length-1];u.shiftKey&&document.activeElement===O?(u.preventDefault(),M.focus()):!u.shiftKey&&document.activeElement===M&&(u.preventDefault(),O.focus())};return window.addEventListener("keydown",q),()=>{window.removeEventListener("keydown",q),R?.focus()}},[K]),a.useEffect(()=>{let R=!1;return v(!0),$(null),ne(`/api/section-context?section=${encodeURIComponent(n)}`).then(q=>{R||(I(q.text),k(q.text),A(q.updatedAt),z(q.maxBytes),window.setTimeout(()=>o.current?.focus(),0))}).catch(q=>{R||$(q instanceof Error?q.message:String(q))}).finally(()=>{R||v(!1)}),()=>{R=!0}},[n]);const G=async()=>{if(!(_>y)){j(!0),$(null);try{const R=await ne(`/api/section-context?section=${encodeURIComponent(n)}`,{method:"PUT",body:JSON.stringify({text:x})});k(R.text),I(R.text),A(R.updatedAt),z(R.maxBytes)}catch(R){$(R instanceof Error?R.message:String(R))}finally{j(!1)}}};return et.createPortal(e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/55 p-4 sm:p-6",onMouseDown:R=>R.target===R.currentTarget&&K(),children:e.jsxs("div",{ref:c,role:"dialog","aria-modal":"true","aria-labelledby":"section-context-title",tabIndex:-1,className:"animate-pop-in flex max-h-[min(680px,calc(100dvh-2rem))] w-full max-w-[680px] flex-col overflow-hidden rounded-2xl border border-hairline/50 bg-panel shadow-2xl shadow-black/50 outline-none",children:[e.jsxs("header",{className:"flex items-start justify-between gap-4 border-b border-hairline/40 px-6 pb-4 pt-6 sm:px-8 sm:pt-7",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ut,{size:19,className:"text-accent"}),e.jsx("h2",{id:"section-context-title",className:"text-[20px] font-semibold tracking-[-0.01em] text-ink",children:s("team.instructionsTitle",{name:r})})]}),e.jsx("p",{className:"mt-1.5 max-w-[520px] text-[13px] leading-relaxed text-ink-secondary",children:s("team.instructionsHint")})]}),e.jsx("button",{onClick:K,disabled:b,"aria-label":s("team.instructionsClose"),className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-40",children:e.jsx(Be,{size:19})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-5 sm:px-8",children:[H?e.jsx("div",{className:"flex min-h-[260px] items-center justify-center text-ink-secondary",children:e.jsx(Re,{size:20,className:"animate-spin","aria-label":s("team.instructionsLoading")})}):e.jsxs(e.Fragment,{children:[e.jsx("textarea",{ref:o,value:x,onChange:R=>I(R.target.value),placeholder:s("team.instructionsPlaceholder"),"aria-label":s("team.instructionsTitle",{name:r}),className:"min-h-[280px] w-full resize-y rounded-xl border border-hairline/60 bg-inset px-4 py-3 font-mono text-[13px] leading-relaxed text-ink outline-none placeholder:text-ink-tertiary focus:border-accent/50"}),e.jsxs("div",{className:"mt-2 flex items-start justify-between gap-4 text-[12px] text-ink-secondary",children:[e.jsxs("span",{children:[s("team.instructionsFactHint")," ",U?` ${s("team.instructionsLastSaved",{time:new Date(U).toLocaleString(Ee())})}`:""]}),e.jsx("span",{className:se("shrink-0 tabular-nums",_>y&&"text-danger"),children:s("team.instructionsBytes",{bytes:_.toLocaleString(Ee()),limit:y.toLocaleString(Ee())})})]})]}),E&&e.jsx("div",{className:"mt-3 rounded-lg border border-danger/30 bg-danger/10 px-3 py-2 text-[12px] text-danger",children:E})]}),e.jsxs("footer",{className:"flex items-center justify-end gap-2 border-t border-hairline/40 px-6 py-4 sm:px-8",children:[e.jsx("button",{onClick:K,disabled:b,className:"rounded-lg px-3.5 py-2 text-[13px] text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-40",children:s("common.cancel")}),e.jsxs("button",{onClick:()=>{G()},disabled:H||b||!W||_>y,className:"flex items-center gap-2 rounded-lg bg-accent px-4 py-2 text-[13px] font-medium text-white hover:brightness-110 disabled:opacity-40",children:[b?e.jsx(Re,{size:14,className:"animate-spin"}):e.jsx(ln,{size:14}),s("team.instructionsSave")]})]})]})}),document.body)}const Xn=1400;function ts(){const{state:n,dispatch:r}=Ne(),{dragProps:i}=Nt(),c=window.ogb?.remoteClient?.active===!0,o=Gt(),[l,S]=a.useState(cn),[g,x]=a.useState(null),[I,h]=a.useState(null),[k,y]=a.useState(null),[z,U]=a.useState(null),[A,H]=a.useState(null),[v,b]=a.useState(null),[j,E]=a.useState(!1),[$,W]=a.useState(0),[_,K]=a.useState([]),[G,R]=a.useState(null),q=a.useCallback(()=>R(null),[]),[u,B]=a.useState(null),N=a.useRef(u);N.current=u,a.useEffect(()=>()=>N.current?.resolve(!1),[]);const O=a.useMemo(()=>n.bots.filter(f=>!f.hidden),[n.bots]),M=a.useMemo(()=>{const f=[...new Set([...n.sections??[],...n.groups.flatMap(Q=>Q.section?[Q.section]:[])])],D=Q=>Q===""?-1:f.includes(Q)?f.indexOf(Q):f.length;return dn(O,f).sort((Q,m)=>D(Q.key)-D(m.key))},[O,n.sections,n.groups]),F=a.useMemo(()=>un(O,l),[O,l]),oe=O.some(f=>f.computer==="cloud"&&f.cloudBackend!=="vps")||_.some(f=>f.section!==null),{show:w,loaded:Y,choose:ce}=Mn(oe),ie=In(!c&&Y&&w),[re,xe]=a.useState([]),[me,pe]=a.useState(null),ue=a.useRef(void 0),be=a.useCallback(f=>{window.clearTimeout(ue.current),pe(D=>({botIds:f,key:(D?.key??0)+1})),ue.current=window.setTimeout(()=>pe(null),Xn)},[]);a.useEffect(()=>()=>window.clearTimeout(ue.current),[]);const ve=a.useMemo(()=>M.map(f=>({key:f.key,name:f.name,count:f.chiefs.length+f.members.length})),[M]),ge=a.useCallback(async(f=!1)=>{try{S(await ne("/api/team-map",f?{background:f}:void 0)),h(null)}catch(D){h(D instanceof Error?D.message:String(D))}},[]);a.useEffect(()=>{ge();const f=window.setInterval(()=>{document.visibilityState==="visible"&&ge(!0)},3e3);return()=>window.clearInterval(f)},[ge]);const Se=async(f,D)=>{x(null);try{const Q=await ne("/api/sidebar-sections",{method:"POST",body:JSON.stringify({name:D,botIds:[f.id]})});r({type:"sections",sections:Q.sections});for(const m of Q.bots)r({type:"botPatched",bot:m})}catch(Q){throw x(Q instanceof Error?Q.message:String(Q)),Q}},de=(f,D)=>new Promise(Q=>{N.current?.resolve(!1),B({bot:f,destination:D,resolve:Q})}),fe=a.useCallback(()=>{N.current?.resolve(!1),B(null)},[]);return e.jsxs("main",{className:"flex min-w-0 flex-1 flex-col overflow-hidden bg-app text-ink",children:[e.jsxs("header",{...i,className:"flex shrink-0 flex-wrap items-center justify-between gap-3 border-b border-hairline/40 px-6 py-4 max-md:pl-12",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Vt,{size:18,className:"text-ink-secondary"}),e.jsx("h1",{className:"text-[17px] font-semibold",children:s("canvas.title")}),e.jsx("span",{className:"ml-1 text-[11px] text-ink-secondary",children:pn(O.length)})]}),e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:s("canvas.description")})]}),!c&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>ce(!w),"aria-pressed":w,title:s("canvas.showComputersHint"),className:se("flex items-center gap-2 rounded-lg border px-3 py-2 text-[12px] font-medium transition-colors",w?"border-accent/40 bg-accent/10 text-ink":"border-hairline/60 bg-panel text-ink-secondary hover:bg-control hover:text-ink"),children:[e.jsx("span",{"aria-hidden":!0,className:se("relative h-4 w-7 shrink-0 rounded-full transition-colors",w?"bg-accent":"bg-control"),children:e.jsx("span",{className:se("absolute top-0.5 size-3 rounded-full bg-white shadow-sm transition-[left]",w?"left-3.5":"left-0.5")})}),s("canvas.showComputers")]}),e.jsx("button",{onClick:()=>E(f=>!f),"aria-label":s("canvas.computers"),"aria-expanded":j,className:"rounded-lg p-2 text-ink-secondary hover:bg-control hover:text-ink",children:e.jsx(Oe,{size:17})}),o!==!1&&e.jsxs("details",{className:"relative",onBlur:f=>{f.currentTarget.contains(f.relatedTarget)||f.currentTarget.removeAttribute("open")},onKeyDown:f=>{f.key==="Escape"&&(f.currentTarget.removeAttribute("open"),f.currentTarget.querySelector("summary")?.focus())},children:[e.jsxs("summary",{"aria-label":s("canvas.addToMap"),className:"flex cursor-pointer list-none items-center gap-1.5 rounded-lg border border-hairline/60 bg-panel px-3 py-2 text-[12px] font-medium hover:bg-control [&::-webkit-details-marker]:hidden",children:[e.jsx(Ke,{size:14})," ",s("common.add")]}),e.jsxs("div",{className:"absolute right-0 top-full z-40 mt-2 w-52 rounded-xl border border-hairline/60 bg-panel p-1.5 shadow-xl",onClick:f=>{const D=f.currentTarget.closest("details");D?.querySelector("summary")?.focus(),D?.removeAttribute("open")},children:[e.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-3 py-2.5 text-left text-[12px] hover:bg-control",onClick:()=>H({}),children:[e.jsx(dt,{size:14}),s("team.create")]}),e.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-3 py-2.5 text-left text-[12px] hover:bg-control",onClick:()=>{E(!0),W(f=>f+1)},children:[e.jsx(Je,{size:14}),s("canvas.cloudComputer")]}),Wt("vm",n.config)&&e.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-3 py-2.5 text-left text-[12px] hover:bg-control",onClick:()=>r({type:"toggleAppSettings",section:"computer",open:!0}),children:[e.jsx(Oe,{size:14}),s("canvas.localVm")]})]})]})]})]}),(g||I)&&e.jsxs("div",{role:"alert",className:"flex shrink-0 items-center justify-between gap-3 border-b border-danger/20 bg-danger/10 px-6 py-2 text-[12px] text-danger",children:[g||I,e.jsx("button",{"aria-label":s("common.close"),className:"rounded p-1 hover:bg-danger/10",onClick:()=>{x(null),h(null)},children:e.jsx(Be,{size:14})})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1",children:[e.jsxs("div",{className:"relative flex min-h-0 min-w-0 flex-1",children:[e.jsx(zn,{sections:M,canManage:!c&&o!==!1,onMove:de,taggedBotIds:re,sent:me,bottomInset:O.length?96:0,connectedBotIds:n.settingsOpen?F.flatMap(f=>f.sourceBotId===n.selectedId?[f.targetBotId]:f.targetBotId===n.selectedId?[f.sourceBotId]:[]):[],onComputer:f=>Xe(r,"access",{botId:f.id}),computers:w&&Y&&!c?ie.computers:void 0,computerFrames:ie.frames,onOpenComputer:f=>f.kind==="team"?E(!0):r({type:"toggleComputer",open:!0,botId:f.id}),teamComputers:Object.fromEntries(_.filter(f=>f.section!==null).map(f=>[f.section,{name:f.name,state:f.state}])),onTeamComputer:()=>E(!0),onComputerDrop:(f,D)=>{c||(E(!0),R({id:f,section:D}))},onInstructions:(f,D)=>y({section:f,label:D}),onMemory:(f,D)=>U({section:f,label:D}),onEditTeam:(f,D)=>H({section:f,rename:D}),onDeleteTeam:b,isEmpty:f=>![...n.bots,...n.groups].some(D=>D.section?.trim()===f)}),O.length>0&&e.jsx(qn,{bots:O,teams:ve,onTagged:xe,onSent:be})]}),!c&&e.jsx(_n,{open:j,createRequest:$,drop:G,sections:M,onClose:()=>E(!1),onDropHandled:q,onChange:K})]}),F.length>0&&e.jsxs("details",{className:"shrink-0 border-t border-hairline/40 bg-panel px-6 py-3",children:[e.jsxs("summary",{className:"cursor-pointer text-[12px] text-ink-secondary",children:[s("canvas.whoHandsOn")," · ",F.length]}),e.jsx("div",{className:"mt-3 max-h-48 space-y-2 overflow-y-auto",children:F.slice(0,12).map(f=>e.jsx(Fn,{edge:f,bots:O},`${f.sourceBotId}:${f.targetBotId}`))})]}),k&&e.jsx(Yn,{section:k.section,label:k.label,onClose:()=>y(null)}),A&&e.jsx(Qt,{...A,onClose:()=>H(null)}),z&&e.jsx(Ln,{...z,onClose:()=>U(null)},z.section),e.jsx(Ge,{open:u!==null,tone:"neutral",title:s("canvas.moveConfirmTitle",{name:u?.bot.name??s("canvas.bot"),team:u?.destination||s("settings.section.general")}),body:s("canvas.moveConfirmBody"),confirmLabel:s("canvas.moveConfirm"),onCancel:fe,onConfirm:()=>{const f=N.current;f&&(B(null),Se(f.bot,f.destination).then(()=>f.resolve(!0),()=>f.resolve(!1)))}}),e.jsx(Ge,{open:v!==null,title:s("team.deleteTitle",{name:v??""}),body:s("team.deleteKeepBotsDescription"),confirmLabel:s("team.delete"),onCancel:()=>b(null),onConfirm:()=>{const f=v;b(null),f&&ne(`/api/sidebar-sections?section=${encodeURIComponent(f)}`,{method:"DELETE"}).then(({sections:D})=>r({type:"sections",sections:D})).catch(D=>x(D instanceof Error?D.message:String(D)))}})]})}export{Fn as EdgeRow,Yn as SectionContextDialog,ts as TeamMapPage};
1
+ import{c as We,t as s,r as a,j as e,a as se,x as Qe,X as Be,w as vt,i as Ee,am as kt}from"./styles-3g-ZPS7M.js";import{L as Re,v as jt,B as Ze,E as wt,P as Ke,r as et,k as Ct,u as Nt}from"./PlacesRail-Df-jNTHn.js";import{g as ne,l as St,al as It,u as Ne,bG as dt,dm as ut,dn as mt,a9 as Mt,T as pt,dp as ft,dq as Tt,dr as Et,ds as At,dt as Rt,at as Ot,bw as Bt,aU as Xe,du as tt,cl as Dt,dv as zt,dw as Lt,y as xt,aj as $e,ao as Je,bb as Pt,C as Ge,dx as $t,dy as _t,e as Ht,dz as Kt,dA as Ut,dB as qt,dC as Ft,d6 as Yt,dD as Xt,dE as Jt,au as Gt,cR as Vt,ap as Wt,dF as Qt,dG as Zt}from"./App-h8WTNY4l.js";import"./index-DtDQrExn.js";import{M as Oe}from"./monitor-DMPjQDZP.js";import{R as en,d as tn}from"./MenuMotion-CHp-hB40.js";import"./placement-BKtVnQht.js";const nn=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",key:"1sd12s"}]],sn=We("message-circle",nn);const an=[["path",{d:"M17 17H4a2 2 0 0 1-2-2V5c0-1.5 1-2 1-2",key:"k0q8oc"}],["path",{d:"M22 15V5a2 2 0 0 0-2-2H9",key:"cp1ac0"}],["path",{d:"M8 21h8",key:"1ev6f3"}],["path",{d:"M12 17v4",key:"1riwvh"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],rn=We("monitor-off",an);const on=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]],ln=We("save",on),cn={collaborations:[],queued:[],running:[]};function dn(n,r=[]){const i=new Map;for(const c of n){if(c.hidden)continue;const o=c.section?.trim()||"";i.set(o,[...i.get(o)??[],c])}for(const c of r){const o=c.trim();o&&!i.has(o)&&i.set(o,[])}return[...i].map(([c,o])=>({key:c,name:c||s("teamSettings.general"),chiefs:o.filter(l=>l.chiefOfStaff),members:o.filter(l=>!l.chiefOfStaff)}))}function un(n,r){const i=new Set(n.filter(l=>!l.hidden).map(l=>l.id)),c=new Map,o=(l,S)=>[l,S].sort().join(":");for(const l of r.collaborations){const[S,g]=l.botIds;!i.has(S)||!i.has(g)||c.set(o(S,g),{sourceBotId:S,targetBotId:g,state:"connected",groupId:l.groupId,lastAt:l.lastAt})}for(const l of r.queued)!i.has(l.sourceBotId)||!i.has(l.targetBotId)||c.set(o(l.sourceBotId,l.targetBotId),{sourceBotId:l.sourceBotId,targetBotId:l.targetBotId,state:"queued",reason:l.reason,groupId:l.groupId,threadId:l.threadId});for(const l of r.running)!i.has(l.sourceBotId)||!i.has(l.targetBotId)||c.set(o(l.sourceBotId,l.targetBotId),{sourceBotId:l.sourceBotId,targetBotId:l.targetBotId,state:"running",groupId:l.groupId,threadId:l.threadId});return[...c.values()].sort((l,S)=>{const g={running:0,queued:1,connected:2};return g[l.state]-g[S.state]||(S.lastAt??0)-(l.lastAt??0)})}function mn(n){return n.activity==="waiting-on-you"?{label:s("canvas.status.waiting"),tone:"warning"}:n.activity==="dead"||n.activity==="no-signal"?{label:s("canvas.status.noSignal"),tone:"danger"}:n.busy||n.activity==="working"?{label:s("canvas.status.working"),tone:"success"}:{label:s("canvas.status.ready"),tone:"idle"}}function pn(n){return n===1?s("canvas.botCountOne"):s("canvas.botCount",{count:n})}const _e=236,Me=126,He=16,we=20,Te=64,qe="application/x-omb-computer";function ke(n,r=[]){const i=new Map(r.map((c,o)=>[c,o]));return[...n].sort((c,o)=>(i.get(c.id)??1/0)-(i.get(o.id)??1/0))}function fn(n,r,i){const c=n.map(l=>l.id);if(!c.includes(r))return c;const o=c.filter(l=>l!==r);return o.splice(Math.max(0,Math.min(o.length,i)),0,r),o}function xn(n){try{const r=JSON.parse(n??"null");return r===null||typeof r!="object"||Array.isArray(r)?{}:Object.fromEntries(Object.entries(r).flatMap(([i,c])=>Array.isArray(c)?[[i,[...new Set(c.filter(o=>typeof o=="string"&&o.length>0))]]]:[]))}catch{return{}}}function ht(n){const r=n.chiefs.length>0&&n.members.length>0,i=r?Math.max(n.chiefs.length,n.members.length):Math.max(1,n.chiefs.length+n.members.length);return{width:_e*(r?2:1)+we*2+(r?40:0),height:Te+we+i*(Me+He)-He}}function hn(n,r,i={}){const c=i.sizes??n.map(ht),o=Math.max(1,Math.floor(i.columns??2)),l=[40];for(let g=1;g<o;g++){const x=Math.max(0,...c.filter((I,h)=>h%o===g-1).map(I=>I.width));l.push(l[g-1]+x+56)}let S=40;return n.map((g,x)=>{x>0&&x%o===0&&(S+=Math.max(...c.slice(x-o,x).map(h=>h.height))+56);const I=Object.hasOwn(r,g.key)?r[g.key]:void 0;return{key:g.key,x:I?.x??l[x%o],y:I?.y??S,...c[x]}})}function gn(n,r,i){if(!n.length)return{x:0,y:0,scale:1};const c=Math.min(...n.map(x=>x.x)),o=Math.min(...n.map(x=>x.y)),l=Math.max(...n.map(x=>x.x+x.width))-c,S=Math.max(...n.map(x=>x.y+x.height))-o,g=Math.max(.3,Math.min(1,(r-80)/l,(i-80)/S));return{x:(r-l*g)/2-c*g,y:(i-S*g)/2-o*g,scale:g}}function at(n,r,i){const c=r/n.scale;return{x:i.x-(i.x-n.x)*c,y:i.y-(i.y-n.y)*c,scale:r}}function bn(n){try{const r=JSON.parse(n??"null");return r===null||typeof r!="object"||Array.isArray(r)?{}:Object.fromEntries(Object.entries(r).flatMap(([i,c])=>{if(c===null||typeof c!="object"||Array.isArray(c))return[];const{x:o,y:l}=c;return typeof o=="number"&&Number.isFinite(o)&&Math.abs(o)<1e5&&typeof l=="number"&&Number.isFinite(l)&&Math.abs(l)<1e5?[[i,{x:o,y:l}]]:[]}))}catch{return{}}}const Ve=272,je=208,Fe=44,Ye=28;function yn(n,r){const i=[...n.chiefs,...n.members],c=i.filter(v=>r.own.has(v.id));if(!c.length&&!r.team)return null;const o=n.chiefs.length>0&&n.members.length>0,l=c.length?je:Me,S=v=>Te+v*(l+He),g=v=>S(v)+l/2,x=we+(o?Ye:0)+_e,I=x+Fe,h=i.map((v,b)=>({botId:v.id,x:we+(o&&b>=n.chiefs.length?Ye:0),y:S(b)+(l-Me)/2})),k=[],y=[];i.forEach((v,b)=>{const j=r.own.get(v.id);j&&(k.push({id:j,x:I,y:S(b)+(l-je)/2}),y.push({botId:v.id,computerId:j,points:[{x:h[b].x+_e,y:g(b)},{x:I,y:g(b)}]}))});const z=S(i.length)-He;let U=Math.max(z,Te+Me),A=c.length?I+Ve:x;if(r.team){const v=i.map((K,G)=>({bot:K,index:G})).filter(({bot:K})=>r.team.botIds.includes(K.id)),b=(v.length?v:i.map((K,G)=>({bot:K,index:G}))).map(({index:K})=>g(K)),j=b.length?(Math.min(...b)+Math.max(...b))/2:Te+je/2,E=A+Fe*(c.length?1.5:2),$=Math.max(Te,j-je/2),W=E-Fe/2,_=$+je/2;k.push({id:r.team.id,x:E,y:$});for(const{bot:K,index:G}of v){const R={x:h[G].x+_e,y:g(G)};y.push({botId:K.id,computerId:r.team.id,points:[R,{x:W,y:R.y},{x:W,y:_},{x:E,y:_}]})}A=E+Ve,U=Math.max(U,$+je)}const H=[];if(o){const v=we+Ye/2,b=n.chiefs.length;H.push([{x:v,y:h[b-1].y+Me},{x:v,y:g(i.length-1)}]);for(let j=b;j<i.length;j++)H.push([{x:v,y:g(j)},{x:h[j].x,y:g(j)}])}return{width:A+we,height:U+we,cards:h,monitors:k,links:y,tree:H}}function vn(n,r,i=56){if(n.length<2||r.width<=0||r.height<=0)return 2;let c={columns:2,scale:0};for(let o=1;o<=Math.min(n.length,6);o++){const l=Array.from({length:o},(k,y)=>Math.max(0,...n.filter((z,U)=>U%o===y).map(z=>z.width))),S=Math.ceil(n.length/o),g=Array.from({length:S},(k,y)=>Math.max(0,...n.slice(y*o,y*o+o).map(z=>z.height))),x=l.reduce((k,y)=>k+y,0)+i*(o-1),I=g.reduce((k,y)=>k+y,0)+i*(S-1),h=Math.min((r.width-80)/x,(r.height-80)/I);h>c.scale+.01&&(c={columns:o,scale:h})}return c.columns}function rt(n){return n.map((r,i)=>`${i?"L":"M"}${r.x} ${r.y}`).join(" ")}const kn=2e3;function jn(n,r){return n.find(i=>i.kind==="bot"&&i.id===r)??n.find(i=>i.kind==="team"&&i.botIds.includes(r))}function wn(n,r,i){const c=new Set(r),o=i.find(l=>l.kind==="team"&&l.section===n);return{own:new Map(i.filter(l=>l.kind==="bot"&&c.has(l.id)).map(l=>[l.id,l.id])),...o?{team:{id:o.id,botIds:o.botIds.filter(l=>c.has(l))}}:{}}}function Cn(n){return Object.entries(n).map(([r,i])=>`${r}:${i.version}`).join(",")}function Nn(n,r,i){return i-Math.max(0,r-n)}function Sn(n,r){const i=atob(n),c=new Uint8Array(i.length);for(let o=0;o<i.length;o++)c[o]=i.charCodeAt(o);return new Blob([c],{type:r})}function In(n){const[r,i]=a.useState(null),[c,o]=a.useState({}),[l,S]=a.useState(null),g=a.useRef(c);g.current=c;const x=a.useRef([]);x.current=r?.computers??[];const I=a.useRef(new Set),h=a.useRef(!0),k=a.useCallback(async(y,z,U,A,H)=>{if((g.current[y]?.at??-1/0)>=A)return;let v;try{v=URL.createObjectURL(Sn(z,U))}catch{return}try{const j=new Image;j.src=v,await j.decode()}catch{URL.revokeObjectURL(v);return}if(!h.current||(g.current[y]?.at??-1/0)>=A){URL.revokeObjectURL(v);return}const b=g.current[y]?.url;g.current={...g.current,[y]:{url:v,at:A,version:H}},o(g.current),b&&(I.current.add(b),window.setTimeout(()=>{URL.revokeObjectURL(b),I.current.delete(b)},2e3))},[]);return a.useEffect(()=>(h.current=!0,()=>{h.current=!1;for(const y of Object.values(g.current))URL.revokeObjectURL(y.url);for(const y of I.current)URL.revokeObjectURL(y)}),[]),a.useEffect(()=>{if(!n)return;let y=!1,z=!1;const U=async()=>{if(!(y||z||document.visibilityState!=="visible")){z=!0;try{const v=Cn(g.current),b=await ne(`/api/computers/frames${v?`?have=${encodeURIComponent(v)}`:""}`,{signal:AbortSignal.timeout(3e4)});if(y)return;const j=Date.now();i(b),S(null);for(const E of b.computers){const $=E.frame;$?.data&&k(E.id,$.data,$.mime,Nn($.at,b.now,j),$.version)}}catch(v){y||S(v instanceof Error?v.message:String(v))}finally{z=!1}}};U();const A=window.setInterval(U,kn),H=St({screens:!0,onFrame:v=>{if(v.kind!=="screen"||v.surface!=="computer"||!v.png)return;const b=jn(x.current,v.botId);b&&k(b.id,v.png,v.mime??"image/png",Date.now(),"live")}});return()=>{y=!0,window.clearInterval(A),H()}},[n,k]),{computers:r?.computers??[],configured:r?.configured??null,frames:c,error:l}}function Mn(n){const[r,i]=a.useState(null),[c,o]=a.useState(null),[l,S]=a.useState(!1);a.useEffect(()=>{let x=!0;return ne("/.well-known/openmausbot/environment",{signal:AbortSignal.timeout(5e3)}).then(I=>{if(!x||typeof I.environmentId!="string")return;const h=`omb-team-canvas:${I.environmentId}:computers`;i(h);try{const k=localStorage.getItem(h);(k==="on"||k==="off")&&o(k==="on")}catch{}}).catch(()=>{}).finally(()=>{x&&S(!0)}),()=>{x=!1}},[]);const g=a.useCallback(x=>{if(o(x),!!r)try{localStorage.setItem(r,x?"on":"off")}catch{}},[r]);return{show:c??n,loaded:l,choose:g}}const ot=28;function Tn(n){if(n&&typeof n=="object"&&!Array.isArray(n))return n;if(typeof n!="string")return{};try{const r=JSON.parse(n);return r&&typeof r=="object"&&!Array.isArray(r)?r:{}}catch{return{}}}function En(n){const r=/(?:^|__)computer__(\w+)$/.exec(n.name)?.[1]??null;if(!r)return null;const i=Tn(n.input);if(r==="open_url")try{return s("mapComputer.step.open",{site:new URL(String(i.url)).hostname.replace(/^www\./,"")})}catch{return s("mapComputer.step.openPage")}if(r==="type_text"&&typeof i.text=="string"&&i.text.trim()){const c=i.text.replace(/\s+/g," ").trim();return s("mapComputer.step.type",{text:c.length>ot?`${c.slice(0,ot)}…`:c})}if(r==="key_press"){const c=[i.keys,i.key,i.combo].find(l=>typeof l=="string"||Array.isArray(l)),o=Array.isArray(c)?c.join("+"):typeof c=="string"?c:"";return o?s("mapComputer.step.key",{keys:o.slice(0,24)}):s("mapComputer.step.keyAny")}return r==="click"||r==="double_click"||r==="right_click"?s("mapComputer.step.click"):r==="scroll"?s("mapComputer.step.scroll"):r==="screenshot"?s("mapComputer.step.look"):r==="drag"?s("mapComputer.step.drag"):null}const it={starting:"mapComputer.state.starting",working:"mapComputer.state.working",idle:"mapComputer.state.idle",asleep:"mapComputer.state.asleep",off:"mapComputer.state.off",problem:"mapComputer.state.problem"},An={starting:"bg-warning",working:"bg-success",idle:"bg-sky-400",asleep:"bg-white/35",off:"bg-white/25",problem:"bg-danger"},Rn=a.memo(function({computer:r,bots:i,frameUrl:c,state:o,activity:l,x:S,y:g,onOpen:x}){const I=o==="working",h=r.kind==="team"?r.name:s("mapComputer.botComputer",{name:r.name});return e.jsxs("div",{"data-computer-node":r.id,className:"absolute",style:{left:S,top:g,width:Ve,height:je},children:[I&&e.jsx("span",{"aria-hidden":!0,className:"pointer-events-none absolute -inset-[5px] animate-computer-glow rounded-[22px] border-2 border-success/70 shadow-[0_0_24px_rgba(52,199,89,0.35)]"}),e.jsxs("button",{type:"button",onClick:x,disabled:!x,title:l?`${h} · ${l}`:h,"aria-label":s("mapComputer.open",{name:h,state:s(it[o])}),className:"relative flex size-full flex-col rounded-[18px] border border-white/10 bg-[#0f1117] p-2 text-left shadow-[0_10px_30px_rgba(0,0,0,0.35)] outline-none transition-transform hover:-translate-y-0.5 focus-visible:ring-2 focus-visible:ring-accent disabled:cursor-default",children:[e.jsxs("span",{className:"relative block h-[160px] w-full overflow-hidden rounded-[8px] bg-[#06070b] [contain:paint]",children:[c?e.jsx("img",{src:c,alt:"",draggable:!1,decoding:"async",className:se("size-full object-cover",o==="asleep"||o==="off"?"opacity-40 grayscale":"")}):e.jsxs("span",{className:"flex size-full flex-col items-center justify-center gap-2 bg-[radial-gradient(circle_at_50%_40%,#1b2030,#06070b_70%)] text-[11px] text-white/45",children:[o==="starting"?e.jsx(Re,{size:20,className:"animate-spin"}):o==="asleep"?e.jsx(jt,{size:20}):o==="problem"?e.jsx(It,{size:20}):e.jsx(rn,{size:20}),s(o==="starting"?"mapComputer.empty.starting":o==="asleep"?"mapComputer.empty.asleep":o==="problem"?"mapComputer.empty.problem":o==="off"?"mapComputer.empty.off":"mapComputer.empty.waiting")]}),e.jsxs("span",{className:"absolute left-2 top-2 flex items-center gap-1.5 rounded-full bg-black/65 px-2 py-0.5 text-[10px] font-medium text-white/90 backdrop-blur-[2px]",children:[e.jsx("span",{className:se("size-1.5 rounded-full",An[o],I&&"animate-pulse")}),s(it[o])]}),l&&I&&e.jsx("span",{className:"absolute inset-x-0 bottom-0 truncate bg-gradient-to-t from-black/85 via-black/55 to-transparent px-2.5 pb-1.5 pt-6 text-[11px] leading-tight text-white/90",children:l})]}),e.jsxs("span",{className:"flex h-[32px] min-w-0 items-center gap-2 px-1 pt-1.5",children:[e.jsx("span",{className:"flex shrink-0 -space-x-1.5",children:i.slice(0,3).map(k=>e.jsx("span",{className:"rounded-full ring-2 ring-[#0f1117]",children:e.jsx(Ze,{bot:k,size:20,animated:!1,motion:"none",motionKey:0})},k.id))}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] font-medium text-white/90",children:h}),i.length>3&&e.jsxs("span",{className:"shrink-0 text-[10px] text-white/50",children:["+",i.length-3]})]})]})]})}),Ae="flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-control hover:text-ink focus-visible:outline-2 focus-visible:outline-accent",Ie="flex w-full items-center gap-2 rounded-lg px-3 py-2.5 text-left text-[12px] text-ink-secondary hover:bg-control hover:text-ink";function On({bot:n,selected:r,moving:i,connected:c,tagged:o=!1,sent:l,onComputer:S,onArrange:g}){const{state:x,dispatch:I}=Ne(),h=Qe(),k=mn(n),y=Rt(n,Ot()),z=x.instances.find(A=>A.instanceId===n.modelSelection.instanceId),U=z?.models.options.find(A=>A.id===n.modelSelection.model)?.label??n.modelSelection.model;return e.jsxs("article",{className:se("relative h-[126px] w-[236px] shrink-0 rounded-xl border bg-card shadow-sm transition-colors",r?"border-accent/60 ring-1 ring-accent/15":c?"border-accent/40":"border-hairline/50 hover:border-ink-secondary/40",o&&"border-accent ring-4 ring-accent/25",i&&"opacity-35"),children:[l!==void 0&&e.jsx("span",{"data-sent-highlight":!0,"aria-hidden":!0,className:"pointer-events-none absolute -inset-px animate-sent-border rounded-xl border-2 border-accent"},l),e.jsxs("button",{"data-bot-id":n.id,"aria-label":s("canvas.editBot",{name:y}),onClick:()=>Xe(I,"identity",{botId:n.id}),title:g?s("canvas.reorderHint"):void 0,onKeyDown:A=>{!g||!A.altKey||A.key!=="ArrowUp"&&A.key!=="ArrowDown"||(A.preventDefault(),A.stopPropagation(),g(n,A.key==="ArrowUp"?-1:1))},className:"flex h-[82px] w-full cursor-grab items-center gap-3 rounded-t-xl px-4 text-left active:cursor-grabbing focus-visible:outline-2 focus-visible:outline-accent",children:[e.jsx(Ze,{bot:n,size:38,motion:"none",motionKey:0,animated:!1}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[14px] font-semibold",children:y}),n.chiefOfStaff&&e.jsx(Bt,{size:12,className:"shrink-0 text-warning","aria-label":s("chat.chiefOfStaff")})]}),e.jsx("span",{className:"mt-1 block truncate text-[11px] text-ink-secondary",children:n.title||(n.chiefOfStaff?s("chat.chiefOfStaff"):s("canvas.bot"))})]})]}),e.jsxs("div",{className:"flex h-[43px] items-center gap-1 border-t border-hairline/30 px-2",children:[e.jsx("button",{className:se(Ae,"size-8"),"aria-label":s("canvas.openBotChat",{name:n.name}),title:s("canvas.openChat"),onClick:()=>tt(I,n,h),children:e.jsx(sn,{size:13})}),k.tone!=="idle"&&e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] text-ink-secondary",title:k.label,children:[e.jsx("span",{className:se("size-1.5 rounded-full",k.tone==="success"?"bg-success":k.tone==="warning"?"bg-warning":k.tone==="danger"?"bg-danger":"bg-ink-secondary/35")}),k.label]}),r&&S&&e.jsx("button",{className:se(Ae,"size-8"),"aria-label":s("canvas.botComputer",{name:n.name}),title:s("computer.tab.computer"),onClick:()=>S(n),children:e.jsx(Oe,{size:13})}),e.jsxs("button",{"aria-label":s("canvas.changeModel",{name:n.name}),title:`${s("canvas.defaultModel")}: ${U}`,onClick:()=>Xe(I,"model",{botId:n.id}),className:"ml-auto flex h-8 min-w-0 max-w-[130px] items-center gap-1.5 rounded-md px-2 text-[10px] text-ink-secondary hover:bg-control hover:text-ink focus-visible:outline-2 focus-visible:outline-accent",children:[e.jsx("span",{className:"flex size-3.5 shrink-0 items-center justify-center",children:z?e.jsx(Dt,{instance:z,size:13}):e.jsx(zt,{driverKind:"",size:13})}),e.jsx("span",{className:"truncate",children:U||s("canvas.defaultModel")})]})]})]})}const Bn=[];function Dn(n,r){if(!n?.busy)return;const i=n.tasks?.find(o=>o.threadId===n.threadId),c=!i||i.busy?n.messages.findLast(o=>o.kind==="activity"&&o.tool):void 0;return c?.tool?En(c.tool)??Et(c.tool,At(n,r),c.dataResult):n.tasks?.find(o=>o.busy&&o.threadId!==n.threadId&&o.title.trim())?.title}function zn({sections:n,canManage:r,onMove:i,onInstructions:c,onMemory:o,onEditTeam:l,onDeleteTeam:S,onComputer:g,onComputerDrop:x,onTeamComputer:I,teamComputers:h={},connectedBotIds:k=[],computers:y=Bn,computerFrames:z={},onOpenComputer:U,taggedBotIds:A=[],sent:H,bottomInset:v=0}){const{state:b}=Ne(),j=a.useRef(null),E=a.useRef(null),$=a.useRef(!1),W=a.useRef(!1),_=a.useRef(null),[K,G]=a.useState({}),[R,q]=a.useState({}),[u,B]=a.useState({x:40,y:40,scale:1}),[N,O]=a.useState(null),[M,F]=a.useState(null),[oe,w]=a.useState(null),[Y,ce]=a.useState(null),[ie,re]=a.useState(null),[xe,me]=a.useState(""),[pe,ue]=a.useState(!1),[be,ve]=a.useState(null),[ge,Se]=a.useState({width:0,height:0}),de=a.useMemo(()=>n.map(t=>{if(!y.length)return null;const p=Object.hasOwn(R,t.key)?R[t.key]:[],d=ke(t.chiefs,p),C=ke(t.members,p);return yn({chiefs:d,members:C},wn(t.key,[...d,...C].map(T=>T.id),y))}),[n,y,R]),fe=a.useMemo(()=>{if(!de.some(Boolean))return;const t=de.map((p,d)=>p??ht(n[d]));return{sizes:t,columns:vn(t,{width:Math.round(ge.width/200)*200,height:Math.round(ge.height/200)*200})}},[de,n,ge]),f=a.useMemo(()=>hn(n,K,fe),[n,K,fe]),D=a.useRef({view:u,positions:K,tiles:f,selectedId:b.selectedId,settingsOpen:b.settingsOpen,bottomInset:v});D.current={view:u,positions:K,tiles:f,selectedId:b.selectedId,settingsOpen:b.settingsOpen,bottomInset:v},a.useEffect(()=>{let t=!0;return ne("/.well-known/openmausbot/environment",{signal:AbortSignal.timeout(5e3)}).then(p=>{if(!(!t||typeof p.environmentId!="string")){_.current=`omb-team-canvas:${p.environmentId}`;try{const d=bn(localStorage.getItem(_.current));G(C=>({...d,...C})),q(xn(localStorage.getItem(`${_.current}:bot-order`)))}catch{}}}).catch(()=>{}).finally(()=>{t&&ue(!0)}),()=>{t=!1}},[]);const Q=t=>{if(G(t),!!_.current)try{localStorage.setItem(_.current,JSON.stringify(Object.fromEntries(n.filter(p=>Object.hasOwn(t,p.key)).map(p=>[p.key,t[p.key]]))))}catch{}},m=t=>Object.hasOwn(R,t)?R[t]:[],L=(t,p,d,C)=>{const T={...R,[t.key]:[...fn(p,d.id,C),...ke(d.chiefOfStaff?t.members:t.chiefs,m(t.key)).map(ee=>ee.id)]};if(q(T),_.current)try{localStorage.setItem(`${_.current}:bot-order`,JSON.stringify(T))}catch{}me(s("canvas.arrangedBot",{name:d.name,team:t.name}))},V=(t,p)=>{const d=n.find(T=>T.key===(t.section?.trim()??""));if(!d)return;const C=ke(t.chiefOfStaff?d.chiefs:d.members,m(d.key));L(d,C,t,C.findIndex(T=>T.id===t.id)+p)},te=a.useCallback(()=>{const t=j.current?.getBoundingClientRect();t&&B(gn(D.current.tiles,t.width,Math.max(200,t.height-D.current.bottomInset)))},[]);a.useEffect(()=>{const t=j.current;if(!t)return;let p=null;const d=new ResizeObserver(()=>{const C=t.getBoundingClientRect();if(Se({width:C.width,height:C.height}),!p)te();else{const T=D.current.settingsOpen?[...t.querySelectorAll("[data-bot-id]")].find(J=>J.dataset.botId===D.current.selectedId)?.getBoundingClientRect():void 0,ee=T?C.width/2-(T.left-C.left+T.width/2):(C.width-p.width)/2,ae=T?C.height/2-(T.top-C.top+T.height/2):(C.height-p.height)/2;B(J=>({...J,x:J.x+ee,y:J.y+ae}))}p={width:C.width,height:C.height}});return d.observe(t),()=>d.disconnect()},[te]);const le=JSON.stringify(f.map(({key:t,width:p,height:d})=>[t,p,d]));a.useEffect(()=>{te()},[te,le,pe]),a.useEffect(()=>{const t=j.current?.querySelector("details[open]"),p=j.current?.getBoundingClientRect();t&&p&&ve(t.getBoundingClientRect().bottom>p.bottom-210*u.scale?t.closest("[data-team-key]")?.dataset.teamKey??null:null)},[u,le]),a.useEffect(()=>{const t=j.current;if(!t)return;const p=d=>{if(d.target.closest("details[open]")||(d.preventDefault(),E.current))return;const C=D.current.view,T=t.getBoundingClientRect();if(d.ctrlKey||d.metaKey){const ee=Math.min(1.5,Math.max(.3,C.scale*Math.exp(-d.deltaY*.006)));B(at(C,ee,{x:d.clientX-T.left,y:d.clientY-T.top}))}else{const ee=d.deltaMode===1?16:d.deltaMode===2?T.height:1;B({...C,x:C.x-d.deltaX*ee,y:C.y-d.deltaY*ee})}};return t.addEventListener("wheel",p,{passive:!1}),()=>t.removeEventListener("wheel",p)},[]);const Z=t=>{if(t.button!==0||!t.isPrimary||E.current)return;const p=t.target,d=p.closest("[data-bot-id]")?.dataset.botId,C=p.closest("[data-arrange-team]")?.dataset.arrangeTeam,T=d?n.flatMap(J=>[...J.chiefs,...J.members]).find(J=>J.id===d):void 0;if(!T&&C===void 0&&p.closest("button, details, a, input, [data-team-key]")||T&&(ie||!pe)||C!==void 0&&!pe)return;const ee={id:t.pointerId,start:{x:t.clientX,y:t.clientY},view:u,positions:K,moved:!1},ae=C===void 0?void 0:f.find(J=>J.key===C);E.current=T?{...ee,kind:"bot",bot:T}:ae?{...ee,kind:"team",key:ae.key,origin:ae}:{...ee,kind:"pan"},$.current=!1},nt=(t,p)=>{const d=document.elementFromPoint(t,p)?.closest("[data-team-key]");return d&&j.current?.contains(d)?d.dataset.teamKey??null:null},st=(t,p)=>{const d=n.find(J=>J.key===(t.section?.trim()??""));if(!d)return null;const C=ke(t.chiefOfStaff?d.chiefs:d.members,m(d.key)),T=C.filter(J=>J.id!==t.id),ee=[...j.current?.querySelectorAll("[data-bot-id]")??[]],ae=T.findIndex(J=>{const P=ee.find(X=>X.dataset.botId===J.id)?.closest("article")?.getBoundingClientRect();return P?p<P.top+P.height/2:!1});return{section:d,lane:C,remaining:T,index:ae<0?T.length:ae}},gt=t=>{const p=E.current;if(!p||p.id!==t.pointerId)return;if(t.buttons===0){Ce(t,!0);return}const d=t.clientX-p.start.x,C=t.clientY-p.start.y;if(!(!p.moved&&Math.hypot(d,C)<5)&&(p.moved=!0,t.currentTarget.setPointerCapture(t.pointerId),p.kind==="pan"&&B({...p.view,x:p.view.x+d,y:p.view.y+C}),p.kind==="team"&&G({...p.positions,[p.key]:{x:p.origin.x+d/u.scale,y:p.origin.y+C/u.scale}}),p.kind==="bot")){const T=t.currentTarget.getBoundingClientRect();O({bot:p.bot,point:{x:t.clientX-T.left,y:t.clientY-T.top}});const ee=nt(t.clientX,t.clientY),ae=ee===(p.bot.section?.trim()??"");F(ae||r?ee:null);const J=ae?st(p.bot,t.clientY):null,P=J?.remaining[J.index]??J?.remaining.at(-1);ce(J&&P?{botId:P.id,after:J.index===J.remaining.length}:null)}},Ce=(t,p=!1)=>{const d=E.current;if(!(!d||t&&d.id!==t.pointerId)){if(E.current=null,$.current=d.moved,window.setTimeout(()=>{$.current=!1},0),O(null),F(null),ce(null),j.current?.hasPointerCapture(d.id)&&j.current.releasePointerCapture(d.id),p){G(d.positions),B(d.view);return}if(d.moved&&(d.kind==="team"&&t&&Q({...d.positions,[d.key]:{x:d.origin.x+(t.clientX-d.start.x)/d.view.scale,y:d.origin.y+(t.clientY-d.start.y)/d.view.scale}}),d.kind==="bot"&&t)){const C=nt(t.clientX,t.clientY);if(C===null)return;if(C===(d.bot.section?.trim()??"")){const T=st(d.bot,t.clientY);T&&L(T.section,T.lane,d.bot,T.index);return}if(!r)return;re(d.bot.id),me(s("canvas.reviewMove",{name:d.bot.name,team:C||s("settings.section.general")})),i(d.bot,C).then(T=>{me(T===!1?s("canvas.moveCancelled"):s("canvas.moved",{name:d.bot.name,team:C||s("settings.section.general")}))}).catch(T=>{me(T instanceof Error?T.message:String(T))}).finally(()=>re(null))}}},De=t=>{const p=j.current?.getBoundingClientRect();p&&B(at(u,Math.max(.3,Math.min(1.5,u.scale*t)),{x:p.width/2,y:p.height/2}))},ze=new Map(n.flatMap(t=>[...t.chiefs,...t.members]).map(t=>[t.id,t])),bt=new Map(y.map(t=>[t.id,t])),yt=t=>{const p=t.botIds.flatMap(d=>ze.get(d)??[]);return t.state==="idle"&&p.some(d=>d.busy)?"working":t.state!=="working"&&p.some(d=>b.computerStarts[d.id])?"starting":t.state},Le=n.find(t=>t.key===M),Pe=oe!==null?s("canvas.assignComputer",{team:n.find(t=>t.key===oe)?.name??oe}):N&&Le?(N.bot.section?.trim()??"")===Le.key?s("canvas.arrangeBot",{name:N.bot.name,team:Le.name}):s("canvas.moveBot",{name:N.bot.name,team:Le.name}):null;return e.jsxs("div",{ref:j,role:"region","aria-label":s("canvas.region"),tabIndex:0,"data-team-canvas":!0,className:"relative min-h-0 flex-1 touch-none overflow-clip outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent/40",style:{backgroundImage:"radial-gradient(circle, color-mix(in srgb, var(--color-ink-secondary) 18%, transparent) 1px, transparent 1px)",backgroundSize:`${24*u.scale}px ${24*u.scale}px`,backgroundPosition:`${u.x}px ${u.y}px`},onPointerDown:Z,onPointerMove:gt,onPointerUp:t=>Ce(t),onPointerCancel:t=>Ce(t,!0),onDragOver:t=>{if(!r||!x||!t.dataTransfer.types.includes(qe))return;const p=t.target.closest("[data-team-key]"),d=p&&t.currentTarget.contains(p)?p.dataset.teamKey??null:null;w(d),d!==null&&(t.preventDefault(),t.dataTransfer.dropEffect="link")},onDragLeave:t=>{(!(t.relatedTarget instanceof Node)||!t.currentTarget.contains(t.relatedTarget))&&w(null)},onDrop:t=>{if(w(null),!r||!x||!t.dataTransfer.types.includes(qe))return;const p=t.target.closest("[data-team-key]"),d=p&&t.currentTarget.contains(p)?p.dataset.teamKey:void 0,C=t.dataTransfer.getData(qe);d===void 0||!n.some(T=>T.key===d)||!C||(t.preventDefault(),x(C,d))},onDragEnd:()=>w(null),onPointerDownCapture:t=>{W.current=!1,t.target.closest("details")||t.currentTarget.querySelectorAll("details[open]").forEach(p=>p.removeAttribute("open"))},onKeyDownCapture:t=>{t.key==="Tab"&&(W.current=!0)},onPointerLeave:()=>{E.current&&!E.current.moved&&Ce(void 0,!0)},onLostPointerCapture:()=>{E.current&&Ce(void 0,!0)},onFocusCapture:t=>{if(!W.current||!(t.target instanceof HTMLElement)||!t.target.closest("[data-canvas-world]"))return;const p=t.currentTarget.getBoundingClientRect(),d=t.target.getBoundingClientRect(),C=d.left<p.left+16?p.left+16-d.left:d.right>p.right-16?p.right-16-d.right:0,T=d.top<p.top+16?p.top+16-d.top:d.bottom>p.bottom-70?p.bottom-70-d.bottom:0;(C||T)&&B(ee=>({...ee,x:ee.x+C,y:ee.y+T}))},onClickCapture:t=>{$.current&&($.current=!1,t.preventDefault(),t.stopPropagation())},onKeyDown:t=>{if(t.key==="Escape"&&(Ce(void 0,!0),t.currentTarget.querySelectorAll("details[open]").forEach(C=>{C.querySelector("summary")?.focus({preventScroll:!0}),C.removeAttribute("open")})),t.target!==t.currentTarget)return;const d={ArrowLeft:{x:60,y:0},ArrowRight:{x:-60,y:0},ArrowUp:{x:0,y:60},ArrowDown:{x:0,y:-60}}[t.key];d&&(t.preventDefault(),B({...u,x:u.x+d.x,y:u.y+d.y})),(t.key==="+"||t.key==="=")&&(t.preventDefault(),De(1.2)),t.key==="-"&&(t.preventDefault(),De(1/1.2)),t.key==="0"&&(t.preventDefault(),te())},children:[e.jsx("div",{"data-canvas-world":!0,className:"absolute left-0 top-0 origin-top-left",style:{transform:`translate(${u.x}px, ${u.y}px) scale(${u.scale})`},children:n.map((t,p)=>{const d=f[p],C=de[p],T=t.chiefs.length>0&&t.members.length>0,ee=oe===t.key||N&&M===t.key&&(N.bot.section?.trim()??"")!==t.key,ae=Object.hasOwn(h,t.key)?h[t.key]:void 0,J=P=>e.jsxs("div",{className:"relative",children:[Y?.botId===P.id&&e.jsx("div",{className:se("pointer-events-none absolute inset-x-1 h-0.5 rounded bg-accent",Y.after?"-bottom-[9px]":"-top-[9px]")}),e.jsx(On,{bot:P,selected:b.selectedId===P.id&&b.settingsOpen,moving:N?.bot.id===P.id||ie===P.id,connected:k.includes(P.id),tagged:A.includes(P.id),sent:H?.botIds.includes(P.id)?H.key:void 0,onComputer:g,onArrange:pe?V:void 0})]},P.id);return e.jsxs("section",{"data-team-key":t.key,"aria-label":s("canvas.teamRegion",{name:t.name}),className:se("absolute rounded-2xl border bg-panel/90 shadow-sm has-[details[open]]:z-20 data-[computer-dropping=true]:border-accent data-[computer-dropping=true]:ring-2 data-[computer-dropping=true]:ring-accent/25",ee?"border-accent ring-2 ring-accent/25":"border-hairline/50"),style:{left:d.x,top:d.y,width:d.width,height:d.height},children:[e.jsxs("header",{className:"flex h-16 items-center gap-2 px-5",children:[e.jsx("button",{"data-arrange-team":t.key,disabled:!pe,"aria-label":s("canvas.arrange",{name:t.name}),title:s("canvas.arrangeHint"),className:"min-w-0 flex-1 cursor-grab rounded-md py-2 text-left active:cursor-grabbing focus-visible:outline-2 focus-visible:outline-accent",onKeyDown:P=>{const X={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]}[P.key];if(!X)return;P.preventDefault(),P.stopPropagation();const ye=P.shiftKey?40:10;Q({...K,[t.key]:{x:d.x+X[0]*ye,y:d.y+X[1]*ye}})},children:e.jsx("h2",{className:"truncate text-[13px] font-semibold tracking-tight",children:t.name})}),ae&&e.jsxs("button",{"aria-label":s("canvas.teamComputer",{team:t.name,name:ae.name}),title:`${ae.name}${ae.state?` · ${ae.state}`:""}`,disabled:!I,onClick:()=>I?.(t.key),className:"flex min-w-0 max-w-[120px] shrink items-center gap-1.5 rounded-md px-1.5 py-2 text-[10px] text-ink-secondary hover:bg-control hover:text-ink focus-visible:outline-2 focus-visible:outline-accent disabled:pointer-events-none",children:[e.jsx(Oe,{size:12,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:ae.name})]}),e.jsx("span",{className:"text-[11px] tabular-nums text-ink-secondary",children:t.chiefs.length+t.members.length}),r&&e.jsxs("details",{className:"relative",onToggle:P=>{if(P.currentTarget.open){const X=j.current?.getBoundingClientRect();ve(X&&P.currentTarget.getBoundingClientRect().bottom>X.bottom-210*u.scale?t.key:null),j.current?.querySelectorAll("details[open]").forEach(ye=>{ye!==P.currentTarget&&ye.removeAttribute("open")})}},children:[e.jsx("summary",{"aria-label":s("canvas.manageTeam",{name:t.name}),className:se(Ae,"cursor-pointer list-none [&::-webkit-details-marker]:hidden"),children:e.jsx(wt,{size:17})}),e.jsxs("div",{className:se("absolute right-0 z-30 w-[220px] animate-pop-in rounded-xl border border-hairline bg-panel p-1.5 shadow-xl",be===t.key?"bottom-10":"top-10"),onClick:P=>{const X=P.currentTarget.closest("details");X?.querySelector("summary")?.focus(),X?.removeAttribute("open")},children:[e.jsxs("button",{className:Ie,onClick:()=>l(t.key),"aria-label":s("team.moveTo",{name:t.name}),children:[e.jsx(dt,{size:14}),s("team.moveTo",{name:t.name})]}),e.jsxs("button",{className:Ie,onClick:()=>c(t.key,t.name),"aria-label":s("team.instructionsEdit",{name:t.name}),children:[e.jsx(ut,{size:14}),s("team.instructions")]}),o&&e.jsxs("button",{className:Ie,onClick:()=>o(t.key,t.name),"aria-label":s("team.memoryFor",{name:t.name}),children:[e.jsx(mt,{size:14}),s("team.memory")]}),t.key&&e.jsxs("button",{className:Ie,onClick:()=>l(t.key,!0),"aria-label":s("team.renameAria",{name:t.name}),children:[e.jsx(Mt,{size:14}),s("team.rename")]}),t.key&&e.jsxs("button",{className:se(Ie,"hover:text-danger"),onClick:()=>S(t.key),"aria-label":s("team.deleteAria",{name:t.name}),children:[e.jsx(pt,{size:14}),s("team.delete")]})]})]})]}),ee&&e.jsx("div",{className:"pointer-events-none absolute -top-7 left-2 z-30 max-w-[calc(100%-16px)] truncate rounded-md bg-accent px-2 py-1 text-[10px] text-white shadow-sm",children:Pe}),C?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 overflow-visible",width:d.width,height:d.height,children:[C.tree.map((P,X)=>e.jsx("path",{d:rt(P),fill:"none",strokeWidth:1.5,className:"stroke-ink-secondary/25"},`tree-${X}`)),C.links.map(P=>{const X=ze.get(P.botId)?.busy===!0;return e.jsx("path",{d:rt(P.points),fill:"none",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:X?2.25:1.5,strokeDasharray:X?"7 5":void 0,className:X?"animate-link-flow stroke-success/80":"stroke-ink-secondary/35"},`${P.botId}:${P.computerId}`)})]}),C.cards.map(P=>{const X=ze.get(P.botId);return X?e.jsx("div",{className:"absolute",style:{left:P.x,top:P.y},children:J(X)},X.id):null}),C.monitors.map(P=>{const X=bt.get(P.id);if(!X)return null;const ye=X.botIds.flatMap(Ue=>ze.get(Ue)??[]);return e.jsx(Rn,{computer:X,bots:ye,x:P.x,y:P.y,frameUrl:Object.hasOwn(z,X.id)?z[X.id].url:void 0,state:yt(X),activity:Dn(ye.find(Ue=>Ue.busy),b.instances),onOpen:U?()=>U(X):void 0},X.id)})]}):e.jsxs("div",{className:"flex items-center px-5 pb-5",children:[t.chiefs.length>0&&e.jsx("div",{className:"flex flex-col gap-4",children:ke(t.chiefs,m(t.key)).map(J)}),T&&e.jsx("div",{className:"flex w-10 shrink-0 justify-center text-ink-secondary/35","aria-hidden":"true",children:e.jsx(ft,{size:22,strokeWidth:1})}),t.members.length>0&&e.jsx("div",{className:"flex flex-col gap-4",children:ke(t.members,m(t.key)).map(J)}),t.chiefs.length+t.members.length===0&&e.jsx("p",{className:"flex h-[126px] w-[236px] items-center justify-center rounded-xl border border-dashed border-hairline/70 px-6 text-center text-[12px] leading-relaxed text-ink-secondary",children:s("canvas.dropHere")})]})]},t.key)})}),N&&e.jsxs("div",{className:"pointer-events-none absolute z-40 rounded-xl border border-accent/40 bg-card px-4 py-3 text-[13px] shadow-lg",style:{left:N.point.x+16,top:N.point.y+16},children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ze,{bot:N.bot,size:24,animated:!1}),N.bot.name]}),Pe&&e.jsx("p",{className:"mt-1 text-[10px] text-ink-secondary",children:Pe})]}),e.jsxs("div",{className:"pointer-events-none absolute inset-x-5 bottom-5 flex items-end justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 rounded-lg bg-app/90 px-2 py-1.5 text-[11px] text-ink-secondary",children:[!v&&e.jsx("p",{className:"max-sm:hidden",children:s("canvas.hint")}),e.jsx("p",{role:"status","aria-live":"polite",className:"max-w-[440px]",children:Pe??xe})]}),e.jsxs("div",{className:"pointer-events-auto flex shrink-0 items-center gap-0.5 rounded-xl border border-hairline/60 bg-panel p-1 shadow-sm",children:[e.jsx("button",{className:Ae,"aria-label":s("canvas.zoomOut"),onClick:()=>De(1/1.2),children:e.jsx(Tt,{size:15})}),e.jsxs("button",{className:"min-w-12 rounded-md px-1 py-2 text-[11px] tabular-nums text-ink-secondary hover:bg-control","aria-label":s("canvas.fit"),title:s("canvas.fitHint"),onClick:te,children:[Math.round(u.scale*100),"%"]}),e.jsx("button",{className:Ae,"aria-label":s("canvas.zoomIn"),onClick:()=>De(1.2),children:e.jsx(Ke,{size:15})})]})]})]})}const lt=[{kind:"person",titleKey:"teamMemory.kind.people",hintKey:"teamMemory.kind.peopleHint"},{kind:"place",titleKey:"teamMemory.kind.places",hintKey:"teamMemory.kind.placesHint"},{kind:"decision",titleKey:"teamMemory.kind.decisions",hintKey:"teamMemory.kind.decisionsHint"},{kind:"term",titleKey:"teamMemory.kind.terms",hintKey:"teamMemory.kind.termsHint"}];function Ln({section:n,label:r,onClose:i}){const c=a.useRef(null),[o,l]=a.useState(null),[S,g]=a.useState([]),[x,I]=a.useState({}),[h,k]=a.useState(null),[y,z]=a.useState(null),U=a.useRef(!1),A=a.useRef(0),[H,v]=a.useState(!1),[b,j]=a.useState({kind:"term",name:"",detail:""}),E=`section=${encodeURIComponent(n)}`,$=a.useCallback(async()=>{const u=++A.current;try{const B=await ne(`/api/team-memory?${E}`);if(A.current!==u)return;l(B.entries),g(B.loadedIds),k(null)}catch(B){if(A.current!==u)return;k(B instanceof Error?B.message:String(B))}},[E]);a.useEffect(()=>(l(null),k(null),$(),()=>{A.current+=1}),[$]),a.useEffect(()=>{const u=document.activeElement instanceof HTMLElement?document.activeElement:null;c.current?.focus();const B=N=>{if(N.key==="Escape"&&(N.preventDefault(),i()),N.key==="Tab"){const O=c.current?.querySelectorAll("button:enabled, input:enabled, select:enabled");if(!O?.length)return;const M=O[0],F=O[O.length-1];N.shiftKey&&document.activeElement===M?(N.preventDefault(),F.focus()):!N.shiftKey&&document.activeElement===F&&(N.preventDefault(),M.focus())}};return window.addEventListener("keydown",B),()=>{window.removeEventListener("keydown",B),u?.focus()}},[i]);const W=async(u,B)=>{if(U.current)return!1;U.current=!0;const N=++A.current;z(u??"new"),k(null);try{const O=await B();return A.current!==N?!1:(l(O.entries),z(null),O.loadedIds?g(O.loadedIds):$(),!0)}catch(O){return A.current===N&&k(O instanceof Error?O.message:String(O)),!1}finally{U.current=!1,A.current===N&&z(null)}},_=u=>W(u.id,()=>ne(`/api/team-memory/${u.id}?${E}`,{method:"PATCH",body:JSON.stringify({accept:!0,expectedRevision:u.revision})})),K=u=>W(u.id,()=>ne(`/api/team-memory/${u.id}?${E}&revision=${u.revision}`,{method:"DELETE"})),G=(u,B,N)=>{B.trim()===u.detail&&(N===void 0||N===u.name)||W(u.id,()=>ne(`/api/team-memory/${u.id}?${E}`,{method:"PATCH",body:JSON.stringify({detail:B,...N===void 0?{}:{name:N},expectedRevision:u.revision})})).then(O=>I(M=>{const F={...M};return O?delete F[u.id]:F[u.id]={name:N??u.name,text:B},F}))},R=()=>{!b.name.trim()||!b.detail.trim()||W(null,()=>ne(`/api/team-memory?${E}`,{method:"POST",body:JSON.stringify(b)})).then(u=>{u&&(j({kind:b.kind,name:"",detail:""}),v(!1))})},q=(o??[]).filter(u=>u.status==="proposed");return et.createPortal(e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/55 p-4 sm:p-6",onMouseDown:u=>u.target===u.currentTarget&&i(),children:e.jsxs("div",{ref:c,role:"dialog","aria-modal":"true","aria-labelledby":"team-memory-title",tabIndex:-1,className:"animate-pop-in flex max-h-[min(720px,calc(100dvh-2rem))] w-full max-w-[720px] flex-col overflow-hidden rounded-2xl border border-hairline/50 bg-panel shadow-2xl shadow-black/50 outline-none",children:[e.jsxs("header",{className:"flex items-start justify-between gap-4 border-b border-hairline/40 px-6 pb-4 pt-6 sm:px-8 sm:pt-7",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(mt,{size:19,className:"text-accent"}),e.jsx("h2",{id:"team-memory-title",className:"text-[20px] font-semibold tracking-[-0.01em] text-ink",children:s("teamMemory.title",{name:r})})]}),e.jsx("p",{className:"mt-1.5 max-w-[560px] text-[13px] leading-relaxed text-ink-secondary",children:s("teamMemory.description")})]}),e.jsx("button",{onClick:i,"aria-label":s("teamMemory.close"),className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-raised hover:text-ink",children:e.jsx(Be,{size:19})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-5 sm:px-8",children:[o===null&&!h&&e.jsx("div",{className:"flex min-h-[200px] items-center justify-center text-ink-secondary",children:e.jsx(Re,{size:20,className:"animate-spin","aria-label":s("teamMemory.loading")})}),o&&e.jsx("p",{className:"mb-3 text-[12px] text-ink-secondary",children:s("teamMemory.loadedSummary",{loaded:S.length,total:o.filter(u=>u.status==="accepted").length})}),h&&e.jsxs("div",{role:"alert",className:"mb-3 rounded-lg border border-danger/30 bg-danger/10 px-3 py-2 text-[12px] text-danger",children:[h," ",e.jsx("button",{onClick:()=>{$()},className:"underline",children:s("teamMemory.reload")})]}),Object.entries(x).map(([u,B])=>e.jsxs("p",{className:"mb-3 text-[12px] text-ink-secondary",children:[e.jsx("strong",{children:B.name})," · ",s("teamMemory.unsaved",{text:B.text})]},u)),q.length>0&&e.jsxs("section",{className:"mb-5 rounded-xl border border-accent/30 bg-accent/5 p-3",children:[e.jsx("h3",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-accent",children:s("teamMemory.waiting")}),e.jsx("ul",{className:"mt-2 space-y-2",children:q.map(u=>e.jsxs("li",{className:"flex items-start gap-3 text-[13px]",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"text-ink-secondary",children:[s(`teamMemory.kind.${u.kind}`),": "]}),e.jsx("span",{className:"font-medium text-ink",children:u.name}),u.aliases.length>0&&e.jsxs("span",{className:"text-ink-secondary",children:[" (",s("teamMemory.also")," ",u.aliases.join(", "),")"]}),e.jsxs("span",{className:"text-ink",children:[" — ",u.detail]}),e.jsxs("span",{className:"block text-[11px] text-ink-secondary",children:[s("teamMemory.source",{name:u.source.botName}),u.source.quote&&` · ${s("teamMemory.sourceQuote",{quote:u.source.quote})}`]})]}),e.jsxs("button",{onClick:()=>{_(u)},disabled:y!==null,className:"flex shrink-0 items-center gap-1 rounded-md bg-accent px-2.5 py-1 text-[12px] font-medium text-white disabled:opacity-50",children:[e.jsx(vt,{size:12})," ",s("teamMemory.remember")]}),e.jsx("button",{onClick:()=>{K(u)},disabled:y!==null,className:"shrink-0 rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:s("teamMemory.skip")})]},u.id))})]}),o!==null&&o.filter(u=>u.status==="accepted").length===0&&q.length===0&&e.jsx("div",{className:"rounded-xl bg-inset px-4 py-6 text-center text-[13px] text-ink-secondary",children:s("teamMemory.empty")}),lt.map(({kind:u,titleKey:B,hintKey:N})=>{const O=(o??[]).filter(M=>M.status==="accepted"&&M.kind===u);return O.length===0?null:e.jsxs("section",{className:"mb-5",children:[e.jsx("h3",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-ink-secondary",title:s(N),children:s(B)}),e.jsx("ul",{className:"mt-2 divide-y divide-hairline/20 rounded-xl bg-inset",children:O.map(M=>e.jsxs("li",{className:"flex items-start gap-3 px-3 py-2 text-[13px]",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"font-medium text-ink",children:M.name}),M.aliases.length>0&&e.jsxs("span",{className:"text-ink-secondary",children:[" (",s("teamMemory.also")," ",M.aliases.join(", "),")"]}),e.jsx("input",{defaultValue:M.detail,disabled:y!==null,onBlur:F=>G(M,F.target.value),onKeyDown:F=>{F.key==="Enter"&&F.target.blur()},"aria-label":s("teamMemory.entryDetailLabel",{name:M.name}),className:"mt-0.5 block w-full rounded bg-transparent px-1 py-0.5 text-[13px] text-ink outline-none hover:bg-card focus:bg-card"},M.revision),e.jsxs("span",{className:"block px-1 text-[11px] text-ink-secondary",children:[M.source.botName||s("teamMemory.you")," · ",new Date(M.updatedAt).toLocaleDateString(Ee())," · ",S.includes(M.id)?s("teamMemory.loaded"):s("teamMemory.searchable")]}),!!M.history?.length&&e.jsxs("details",{className:"mt-1 text-[11px] text-ink-secondary",children:[e.jsx("summary",{children:s("teamMemory.history")}),M.history.map((F,oe)=>e.jsxs("div",{className:"mt-1",children:[new Date(F.at).toLocaleDateString(Ee()),": ",F.name," — ",F.detail," ",e.jsx("button",{disabled:y!==null,onClick:()=>G(M,F.detail,F.name),className:"underline",children:s("teamMemory.restore")})]},oe))]})]}),e.jsx("button",{"aria-label":s(M.pinned?"teamMemory.unpin":"teamMemory.pin",{name:M.name}),"aria-pressed":M.pinned??!1,disabled:y!==null,className:"p-1 text-ink-secondary hover:text-accent",onClick:()=>{W(M.id,()=>ne(`/api/team-memory/${M.id}?${E}`,{method:"PATCH",body:JSON.stringify({pinned:!M.pinned,expectedRevision:M.revision})}))},children:e.jsx(Lt,{size:13})}),e.jsx("button",{onClick:()=>{K(M)},disabled:y!==null,"aria-label":s("teamMemory.remove",{name:M.name}),className:"shrink-0 rounded-md p-1 text-ink-secondary hover:text-danger disabled:opacity-50",children:e.jsx(pt,{size:13})})]},M.id))})]},u)}),H?e.jsxs("div",{className:"rounded-xl border border-hairline/40 bg-card p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(xt,{size:"sm",value:b.kind,onChange:u=>j({...b,kind:u.target.value}),"aria-label":s("teamMemory.kindLabel"),children:lt.map(({kind:u})=>e.jsx("option",{value:u,children:s(`teamMemory.kind.${u}`)},u))}),e.jsx("input",{value:b.name,onChange:u=>j({...b,name:u.target.value}),placeholder:s("teamMemory.namePlaceholder"),"aria-label":s("teamMemory.nameLabel"),className:"min-w-[140px] flex-1 rounded-lg border border-hairline/40 bg-inset px-2 py-1 text-[13px] text-ink outline-none focus:border-accent"})]}),e.jsx("input",{value:b.detail,onChange:u=>j({...b,detail:u.target.value}),onKeyDown:u=>{u.key==="Enter"&&R()},placeholder:s("teamMemory.detailPlaceholder"),"aria-label":s("teamMemory.detailLabel"),className:"mt-2 w-full rounded-lg border border-hairline/40 bg-inset px-2 py-1 text-[13px] text-ink outline-none focus:border-accent"}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("button",{onClick:R,disabled:y!==null||!b.name.trim()||!b.detail.trim(),className:"rounded-lg bg-accent px-3 py-1 text-[13px] font-medium text-white disabled:opacity-50",children:y==="new"?s("teamMemory.adding"):s("teamMemory.add")}),e.jsx("button",{onClick:()=>v(!1),className:"text-[13px] text-ink-secondary hover:text-ink",children:s("common.cancel")})]})]}):e.jsxs("button",{onClick:()=>v(!0),className:se("flex items-center gap-1.5 text-[13px] text-ink-secondary hover:text-ink",o===null&&"hidden"),children:[e.jsx(Ke,{size:13})," ",s("teamMemory.addEntry")]})]})]})}),document.body)}const he="rounded-lg px-3 py-2 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",Pn="w-full rounded-lg border border-hairline/60 bg-inset px-3 py-2 text-[12px] text-ink outline-none focus:border-accent";function $n(n,r){if(r)return s("canvasComputers.updating");const i={idle:"idle",ready:"ready",running:"running",init:"starting",provisioning:"provisioning",provisioned:"starting",cloning:"starting",starting:"starting",sleeping:"sleeping"}[n];return i?s(`canvasComputers.state.${i}`):n}function _n({open:n,createRequest:r,drop:i,sections:c,onClose:o,onDropHandled:l,onChange:S}){const{dispatch:g}=Ne(),[x,I]=a.useState(null),[h,k]=a.useState(!1),[y,z]=a.useState(""),[U,A]=a.useState(""),[H,v]=a.useState(null),[b,j]=a.useState(!1),[E,$]=a.useState(""),W=a.useRef($e()),_=a.useRef(null),K=a.useRef(null),G=a.useRef(null),R=a.useRef(!1),q=a.useRef(!0),u=a.useRef(null),B=a.useRef(S);B.current=S;const[N,O]=a.useState(null),[M,F]=a.useState(null),[oe,w]=a.useState(null),Y=a.useRef($e()),ce=a.useRef(null),ie=a.useRef(null),re=a.useRef(null),xe=a.useRef(null),[me,pe]=a.useState(null),ue=a.useCallback(()=>{const m=re.current;re.current=null,xe.current?.removeAttribute("data-computer-dropping"),xe.current=null,m?.handle.hasPointerCapture(m.id)&&m.handle.releasePointerCapture(m.id),pe(null)},[]);a.useEffect(()=>(n||ue(),()=>{xe.current?.removeAttribute("data-computer-dropping")}),[n,ue]),a.useEffect(()=>{ce.current=oe},[oe]),a.useEffect(()=>()=>{const m=ce.current;m&&fetch(`/api/team-computers/${encodeURIComponent(m)}/control`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({action:"release",controlLeaseId:Y.current}),keepalive:!0}).catch(()=>{})},[]);const be=a.useCallback((m,L)=>{if(!(R.current||m.section===L)){if(m.section!==null&&L!==null){z(s("canvasComputers.unassignBeforeMove",{computer:m.name,team:m.section||s("settings.section.general")}));return}z(""),O({computer:m,section:L})}},[]),ve=(m,L)=>{const V=ie.current?.parentElement?.querySelector("[data-team-canvas]"),te=document.elementFromPoint(m,L)?.closest("[data-team-key]");return te&&V?.contains(te)&&c.some(le=>le.key===te.dataset.teamKey)?te:null},ge=m=>{const L=re.current;if(!L||m.pointerId!==L.id)return;if(m.buttons===0){ue();return}if(!L.moved&&Math.hypot(m.clientX-L.x,m.clientY-L.y)<5)return;L.moved=!0,m.currentTarget.setPointerCapture(m.pointerId);const V=ve(m.clientX,m.clientY);xe.current!==V&&(xe.current?.removeAttribute("data-computer-dropping"),V?.setAttribute("data-computer-dropping","true"),xe.current=V);const te=V?c.find(le=>le.key===V.dataset.teamKey):null;pe({name:L.computer.name,x:m.clientX,y:m.clientY,hint:te?L.computer.section!==null&&L.computer.section!==te.key?s("canvasComputers.unassignBeforeMoving"):s("canvasComputers.assignTo",{team:te.name}):s("canvasComputers.dropOntoTeam")})},Se=m=>{const L=re.current;if(!L||L.id!==m.pointerId)return;const V=L.moved?ve(m.clientX,m.clientY)?.dataset.teamKey:void 0;ue(),V!==void 0&&be(L.computer,V)},de=a.useCallback(async(m=!1)=>{u.current?.abort();const L=new AbortController;u.current=L,k(!0);try{const V=await ne("/api/team-computers",{signal:AbortSignal.any([L.signal,AbortSignal.timeout(3e4)]),background:m});if(L.signal.aborted||!q.current)return;I(V),A(""),B.current(V.computers)}catch(V){!L.signal.aborted&&q.current&&A(V instanceof Error?V.message:String(V))}finally{!L.signal.aborted&&q.current&&k(!1)}},[]);a.useEffect(()=>(q.current=!0,de(),()=>{q.current=!1,u.current?.abort()}),[de]),a.useEffect(()=>{if(!n)return;de();const m=window.setInterval(()=>{!R.current&&document.visibilityState==="visible"&&de(!0)},2e4);return()=>window.clearInterval(m)},[n,de]),a.useEffect(()=>{r>0&&j(!0)},[r]),a.useEffect(()=>{if(!n)return;const m=document.activeElement instanceof HTMLElement?document.activeElement:null;return G.current?.focus(),()=>{m?.isConnected&&m.focus()}},[n]),a.useEffect(()=>{n&&b&&K.current?.focus()},[n,b]),a.useEffect(()=>{if(!i)return;const m=x?.computers.find(L=>L.id===i.id);m&&be(m,i.section),l()},[i,x,l,be]);const fe=async(m,L,V,te)=>{if(!R.current){R.current=!0,v(m),z(""),u.current?.abort();try{const le=await L();q.current&&V?.(le)}catch(le){q.current&&(z(le instanceof Error?le.message:String(le)),te?.())}finally{R.current=!1,q.current&&(v(null),await de())}}},f=a.useCallback(()=>O(null),[]),D=(m,L,V={})=>ne(`/api/team-computers/${encodeURIComponent(m)}/${L}`,{method:"POST",body:JSON.stringify(V)}),Q=()=>{o(),g({type:"toggleAppSettings",open:!0,section:"computer"})};return e.jsxs(e.Fragment,{children:[n&&e.jsxs("aside",{ref:ie,"aria-label":s("canvasComputers.title"),onKeyDown:m=>{m.key==="Escape"&&!N&&(m.stopPropagation(),re.current?ue():o())},className:"flex w-[300px] max-w-[90vw] shrink-0 flex-col border-l border-hairline/50 bg-panel max-sm:absolute max-sm:inset-y-0 max-sm:right-0 max-sm:z-30 max-sm:shadow-xl",children:[e.jsxs("header",{className:"flex items-center gap-2 border-b border-hairline/40 px-4 py-3",children:[e.jsx(Oe,{size:16,className:"text-ink-secondary"}),e.jsx("h2",{className:"flex-1 text-[13px] font-semibold",children:s("canvasComputers.title")}),e.jsx("button",{"aria-label":s("canvasComputers.refresh"),className:he,disabled:h||H!==null,onClick:()=>{z(""),de()},children:e.jsx(en,{size:14,className:h?"animate-spin":""})}),e.jsx("button",{ref:G,"aria-label":s("canvasComputers.close"),className:he,onClick:o,children:e.jsx(Be,{size:15})})]}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-3 overflow-y-auto p-4",children:[e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:s("canvasComputers.hint")}),(y||U||x?.problem)&&e.jsx("p",{role:"alert",className:"rounded-lg bg-danger/10 p-3 text-[12px] text-danger",children:y||U||x?.problem}),x&&!x.configured&&e.jsxs("div",{className:"rounded-xl border border-hairline/50 p-3 text-[12px]",children:[e.jsx("p",{className:"text-ink-secondary",children:s("canvasComputers.connectBoatHint")}),e.jsx("button",{className:`${he} mt-2 border border-hairline/50`,onClick:Q,children:s("canvasComputers.connectBoat")})]}),b?e.jsxs("form",{className:"space-y-3 rounded-xl border border-hairline/60 bg-card p-3",onSubmit:m=>{m.preventDefault();const L=_.current??E.trim();!L||!x?.configured||(_.current=L,fe("create",()=>ne("/api/team-computers",{method:"POST",body:JSON.stringify({name:L,requestId:W.current,acknowledgeCost:!0})}),()=>{$(""),j(!1),W.current=$e(),_.current=null},()=>{_.current=null}))},children:[e.jsx("label",{className:"block text-[12px] font-medium",htmlFor:"canvas-computer-name",children:s("canvasComputers.newCloud")}),e.jsx("input",{ref:K,id:"canvas-computer-name",className:Pn,value:E,maxLength:60,placeholder:s("canvasComputers.namePlaceholder"),disabled:H!==null||_.current!==null,onChange:m=>$(m.target.value)}),e.jsx("p",{className:"text-[11px] leading-relaxed text-ink-secondary",children:s("canvasComputers.createHint")}),e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx("button",{type:"button",className:he,disabled:H!==null,onClick:()=>j(!1),children:s("common.cancel")}),e.jsxs("button",{type:"submit",className:"flex items-center gap-2 rounded-lg bg-accent px-3 py-2 text-[12px] font-medium text-white disabled:opacity-40",disabled:!x?.configured||!E.trim()||H!==null,children:[H==="create"&&e.jsx(Re,{size:13,className:"animate-spin"}),s("canvasComputers.create")]})]})]}):e.jsxs("button",{className:"flex w-full items-center justify-center gap-2 rounded-xl border border-dashed border-hairline/60 px-3 py-3 text-[12px] text-ink-secondary hover:bg-control hover:text-ink",disabled:H!==null,onClick:()=>j(!0),children:[e.jsx(Ke,{size:14})," ",s("canvasComputers.newCloud")]}),x?.computers.map(m=>{const L=["idle","ready","running"].includes(m.state),V=["init","provisioning","provisioned","cloning","starting"].includes(m.state),te=oe===m.id,le=m.held||te;return e.jsxs("article",{"data-computer-id":m.id,className:"rounded-xl border border-hairline/60 bg-card p-3",children:[e.jsxs("div",{"data-computer-drag-id":m.id,role:"group",tabIndex:-1,"aria-label":s("canvasComputers.dragToTeam",{name:m.name}),onPointerDown:Z=>{R.current||re.current||Z.button!==0||!Z.isPrimary||(Z.currentTarget.focus({preventScroll:!0}),re.current={id:Z.pointerId,x:Z.clientX,y:Z.clientY,moved:!1,computer:m,handle:Z.currentTarget},Z.currentTarget.setPointerCapture(Z.pointerId))},onPointerMove:ge,onPointerUp:Se,onPointerCancel:ue,onLostPointerCapture:()=>{re.current&&ue()},className:"flex touch-none select-none cursor-grab items-center gap-2.5 rounded-lg py-1 outline-none active:cursor-grabbing",children:[e.jsx("span",{className:"flex size-9 shrink-0 items-center justify-center rounded-lg bg-control text-ink-secondary",children:e.jsx(Je,{size:18})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-[13px] font-medium",children:m.name}),e.jsxs("span",{className:"block text-[11px] text-ink-secondary",children:[s("canvasComputers.cloudComputer")," · ",$n(m.state,H===m.id)]})]})]}),m.problem&&e.jsx("p",{className:"mt-2 text-[11px] text-danger",children:m.problem}),e.jsx("label",{className:"sr-only",htmlFor:`computer-team-${m.id}`,children:s("canvasComputers.teamFor",{name:m.name})}),e.jsxs(xt,{id:`computer-team-${m.id}`,className:"mt-3 w-full",disabled:H!==null,value:m.section===null?"unassigned":`team:${m.section}`,onChange:Z=>be(m,Z.target.value==="unassigned"?null:Z.target.value.slice(5)),children:[e.jsx("option",{value:"unassigned",children:s("canvasComputers.unassigned")}),c.filter(Z=>m.section===null||Z.key===m.section).map(Z=>e.jsx("option",{value:`team:${Z.key}`,children:Z.name},Z.key))]}),m.section!==null&&e.jsx("p",{className:"mt-1.5 text-[10px] text-ink-secondary",children:s("canvasComputers.unassignHint")}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1",children:[!L&&!V&&e.jsx("button",{className:he,title:s("canvasComputers.startTitle"),disabled:H!==null||le,onClick:()=>{fe(m.id,()=>D(m.id,"provision",{acknowledgeCost:!0}))},children:s("canvasComputers.startRetry")}),L&&!le&&e.jsx("button",{className:he,disabled:H!==null,onClick:()=>{fe(m.id,()=>D(m.id,"sleep"))},children:s("canvasComputers.sleep")}),L&&e.jsxs("button",{className:`${he} flex items-center gap-1.5`,title:s("canvasComputers.openTitle"),disabled:H!==null,onClick:()=>{fe(m.id,async()=>(await D(m.id,"control",{action:"take",controlLeaseId:Y.current}),w(m.id),D(m.id,"join")),Z=>{typeof Z.joinUrl=="string"&&Z.joinUrl.startsWith("https://")&&F({id:m.id,url:Z.joinUrl})})},children:[s("canvasComputers.openDesktop")," ",e.jsx(Ct,{size:11})]}),te&&e.jsx("button",{className:`${he} text-accent`,disabled:H!==null,onClick:()=>{fe(m.id,()=>D(m.id,"control",{action:"release",controlLeaseId:Y.current}),()=>{w(null),F(null)})},children:s("canvasComputers.returnToBots")}),m.held&&!te&&e.jsx("button",{className:he,disabled:!0,title:s("canvasComputers.inUseTitle"),children:s("canvasComputers.inUse")})]}),M?.id===m.id&&e.jsxs("a",{href:M.url,target:"_blank",rel:"noopener noreferrer",className:"mt-2 block rounded-lg px-3 py-2 text-[12px] text-accent hover:bg-control",children:[s("canvasComputers.openSecure")," ",e.jsx(Pt,{size:14,"aria-hidden":"true",className:"inline align-[-2px]"})]})]},m.id)})]}),e.jsx("footer",{className:"border-t border-hairline/40 p-3",children:e.jsx("button",{className:`${he} w-full text-left`,onClick:Q,children:s("canvasComputers.moreSettings")})})]}),me&&et.createPortal(e.jsxs("div",{role:"status",className:"pointer-events-none fixed z-[70] rounded-xl border border-accent/40 bg-card px-4 py-3 text-[12px] text-ink shadow-xl",style:{left:me.x+14,top:me.y+14},children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Je,{size:15}),me.name]}),e.jsx("p",{className:"mt-1 text-[10px] text-ink-secondary",children:me.hint})]}),document.body),e.jsx(Ge,{open:N!==null,tone:"neutral",title:N?.section===null?s("canvasComputers.unassignTitle",{name:N?.computer.name??s("canvasComputers.computer")}):s("canvasComputers.assignTitle",{name:N?.computer.name??s("canvasComputers.computer"),team:N?.section||s("settings.section.general")}),body:N?.section===null?s("canvasComputers.unassignBody"):s("canvasComputers.assignBody"),confirmLabel:N?.section===null?s("canvasComputers.unassign"):s("canvasComputers.assign"),onCancel:f,onConfirm:()=>{const m=N;m&&(O(null),F(null),fe(m.computer.id,()=>ne(`/api/team-computers/${encodeURIComponent(m.computer.id)}`,{method:"PATCH",body:JSON.stringify({section:m.section,acknowledgeSharedAccess:!0})})))}})]})}function Hn(n,r,i){const c=r.filter(h=>!h.hidden&&h.name.trim()),o=[...c.map(h=>({name:h.name,tag:{kind:"bot",name:h.name,botIds:[h.id]}})),...i.filter(h=>h.name.trim()).map(h=>({name:h.name,tag:{kind:"team",name:h.name,botIds:c.filter(k=>(k.section?.trim()??"")===h.key).map(k=>k.id)}})),{name:"everyone",tag:{kind:"everyone",name:"everyone",botIds:c.map(h=>h.id)}}].sort((h,k)=>k.name.length-h.name.length),l=[],S=[],g=[];let x=-1;for(;(x=n.indexOf("@",x+1))!==-1;){if(!$t(n,x))continue;const h=n.slice(x+1),k=o.find(({name:z})=>h.slice(0,z.length).toLowerCase()===z.toLowerCase()&&!_t(h.slice(z.length)));if(k){l.push(k.tag),g.push([x,x+1+k.name.length]),x+=k.name.length;continue}const y=/^[\p{L}\p{N}\p{M}_.-]+/u.exec(h)?.[0];y&&S.push(y)}const I=g.reduceRight((h,[k,y])=>h.slice(0,k)+h.slice(y),n).replace(/\s+/g," ").trim();return{botIds:[...new Set(l.flatMap(h=>h.botIds))],tags:l,unknown:S,words:I}}function ct(n,r,i){if(!n.tags.some(l=>l.kind==="everyone"))return{botIds:n.botIds};if(i)return{botIds:n.botIds,text:n.words};const c=Kn(r);if(!c)return{botIds:n.botIds};const o=n.tags.filter(l=>l.kind!=="everyone").flatMap(l=>l.botIds);return{botIds:[...new Set([c.id,...o])],chief:c}}function Kn(n){const r=n.filter(i=>i.chiefOfStaff&&!i.hidden);return r.find(i=>!i.section?.trim())??r[0]}function Un(n,r=2){return n.length<=r+1?{names:[...n],more:0}:{names:n.slice(0,r),more:n.length-r}}function qn({bots:n,teams:r,onTagged:i,onSent:c}){const{dispatch:o}=Ne(),l=Qe(),S=Ht(),g=a.useRef(null),x=a.useRef(null),[I,h]=a.useState(""),[k,y]=a.useState(0),[z,U]=a.useState(null),[A,H]=a.useState(0),[v,b]=a.useState(null),j=a.useMemo(()=>n.filter(w=>!w.hidden),[n]),E=a.useMemo(()=>Hn(I,j,r),[I,j,r]),$=a.useMemo(()=>ct(E,j,!1),[E,j]),W=$.botIds.join(",");a.useEffect(()=>{i(W?W.split(","):[])},[W,i]),a.useEffect(()=>()=>i([]),[i]);const _=Kt(I,k),K=a.useMemo(()=>{if(!_||_.start===z)return[];const w=[...j.length>1?[{id:"__everyone__",name:"everyone",all:{count:j.length}}]:[],...r.filter(Y=>Y.count>0).map(Y=>({id:`team:${Y.key}`,name:Y.name,team:{count:Y.count}})),...j.map(Y=>({id:Y.id,name:Y.name,bot:Y}))];return Ut(w,_.query)},[_,z,j,r]),G=K.length>0,R=tn(G);a.useEffect(()=>H(0),[_?.start,_?.query]),a.useEffect(()=>{G&&x.current?.querySelector(`[data-mention-index="${A}"]`)?.scrollIntoView({block:"nearest"})},[A,G]);const q=w=>{if(!_)return;const Y=`${I.slice(0,_.start)}@${w.name} ${I.slice(k)}`,ce=_.start+w.name.length+2;h(Y),y(ce),U(_.start),requestAnimationFrame(()=>{g.current?.focus(),g.current?.setSelectionRange(ce,ce)})},u=I.trim().length>0&&E.botIds.length>0,B=async()=>{if(!u)return;const w=I.trim(),Y=E;h(""),y(0),U(null);const ce=$.chief?await ne("/api/stop-line",{method:"POST",body:JSON.stringify({text:Y.words})}).then(re=>re.stop===!0,()=>null):!1,ie=ce===null?{botIds:Y.botIds}:ct(Y,j,ce);for(const re of ie.botIds)o({type:"send",botId:re,text:ie.text||w,sendId:$e()});c(ie.botIds),b({botIds:ie.botIds,expanded:!1,...ie.chief?{chiefId:ie.chief.id}:{}})},N=v?.chiefId?j.find(w=>w.id===v.chiefId):void 0,O=(v?.botIds??[]).filter(w=>w!==N?.id).flatMap(w=>j.find(Y=>Y.id===w)??[]),M=Un(O.map(w=>w.name)),F=v?.expanded?O:O.slice(0,M.names.length),oe=I.trim()&&!E.botIds.length?s("mapComposer.tagHint"):$.chief?s("mapComposer.willSendViaChief",{name:$.chief.name}):null;return e.jsx(e.Fragment,{children:e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-5 z-30 flex justify-center px-4",children:e.jsxs("div",{className:"pointer-events-auto w-full max-w-[620px]",children:[v&&(N||O.length>0)&&e.jsxs("p",{role:"status",className:"mb-2 flex flex-wrap items-center gap-x-1 gap-y-0.5 rounded-xl bg-panel/95 px-3 py-1.5 text-[12px] text-ink-secondary shadow-sm ring-1 ring-hairline/50",children:[N&&e.jsxs("span",{children:[s("mapComposer.sentViaChief",{name:N.name}),O.length>0?" ·":""]}),O.length>0&&e.jsx("span",{children:s("mapComposer.sentTo")}),F.map((w,Y)=>e.jsxs("span",{children:[e.jsx("button",{className:"font-medium text-ink underline-offset-2 hover:underline",onClick:()=>tt(o,w,l),children:w.name}),Y<F.length-1?",":""]},w.id)),!v.expanded&&M.more>0&&e.jsx("button",{className:"text-ink underline-offset-2 hover:underline",onClick:()=>b({...v,expanded:!0}),children:s("mapComposer.andMore",{count:M.more})}),e.jsx("button",{"aria-label":s("common.close"),className:"ml-auto rounded p-0.5 hover:bg-control",onClick:()=>b(null),children:e.jsx(Be,{size:12})})]}),e.jsxs("div",{className:"relative flex items-end gap-2 rounded-2xl bg-composer px-3 py-2 shadow-lg ring-1 ring-composer-ring",children:[e.jsx(qt,{listRef:x,motion:R,choices:K,highlight:A,everyoneCount:j.length,onPick:q,onHighlight:H}),e.jsx(Ft,{inputRef:g,peers:[...j,...r.map(w=>({name:w.name}))],everyone:!0,"aria-label":s("mapComposer.label"),placeholder:s("mapComposer.placeholder"),dir:"auto",rows:1,value:I,className:"block max-h-[9rem] min-h-6 w-full resize-none overflow-y-auto bg-transparent px-1 py-1 text-[15px] leading-6 placeholder:text-ink-secondary focus:outline-none",onChange:w=>{h(w.target.value),y(w.target.selectionStart??w.target.value.length),U(null)},onKeyUp:w=>y(w.target.selectionStart??0),onClick:w=>y(w.target.selectionStart??0),onKeyDown:w=>{if(!Yt(w.nativeEvent)){if(G){if(w.key==="ArrowDown"||w.key==="ArrowUp"){w.preventDefault(),H(Y=>(Y+(w.key==="ArrowDown"?1:-1)+K.length)%K.length);return}if(w.key==="Enter"||w.key==="Tab"){w.preventDefault(),q(K[A]);return}if(w.key==="Escape"){w.preventDefault(),w.stopPropagation(),U(_?.start??null);return}}Xt(w.nativeEvent,S)&&(w.preventDefault(),B())}}}),e.jsx("button",{onClick:()=>{B()},disabled:!u,"aria-label":s("mapComposer.send"),title:u?$.botIds.length===1?s("mapComposer.sendToOne"):s("mapComposer.sendTo",{count:$.botIds.length}):s("mapComposer.tagHint"),className:se("mb-0.5 flex size-8 shrink-0 items-center justify-center rounded-full text-white transition-opacity",u?"bg-accent hover:brightness-110":"bg-ink-secondary/30"),children:e.jsx(Jt,{size:16})})]}),(oe||E.botIds.length>0)&&e.jsx("p",{className:"mt-1.5 px-3 text-[11px] text-ink-secondary",children:oe??($.botIds.length===1?s("mapComposer.willSendOne"):s("mapComposer.willSend",{count:$.botIds.length}))})]})})})}function Fn({edge:n,bots:r}){const{state:i,dispatch:c}=Ne(),o=Qe(),l=r.find(x=>x.id===n.sourceBotId),S=r.find(x=>x.id===n.targetBotId);if(!l||!S)return null;const g=n.state!=="connected";return e.jsxs("button",{onClick:()=>{!n.groupId&&n.threadId?Zt(c,{botId:S.id,threadId:n.threadId},i,o):n.groupId?c({type:"select",id:n.groupId}):tt(c,S,o)},className:"flex w-full items-center gap-3 rounded-xl border border-hairline/40 bg-card px-3 py-2.5 text-left transition hover:bg-raised/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-ink",children:l.name}),e.jsx(ft,{size:13,className:se("shrink-0",g?"text-accent":"text-ink-secondary")}),e.jsx("span",{className:"truncate text-[13px] font-medium text-ink",children:S.name})]}),n.reason&&e.jsx("span",{className:"max-w-[220px] truncate text-[12px] text-ink-secondary",children:n.reason}),e.jsx("span",{className:se("rounded-full px-2 py-0.5 text-[11px] font-medium",n.state==="running"?"bg-success/15 text-success":n.state==="queued"?"bg-warning/15 text-warning":"bg-control text-ink-secondary"),children:n.state==="running"?s("canvas.edge.running"):n.state==="queued"?s("canvas.edge.queued"):n.lastAt?kt(n.lastAt):s("canvas.edge.connected")})]})}function Yn({section:n,label:r,onClose:i}){const c=a.useRef(null),o=a.useRef(null),l=a.useRef(i),S=a.useRef(!1),g=a.useRef(!1),[x,I]=a.useState(""),[h,k]=a.useState(""),[y,z]=a.useState(24e3),[U,A]=a.useState(null),[H,v]=a.useState(!0),[b,j]=a.useState(!1),[E,$]=a.useState(null),W=x!==h,_=a.useMemo(()=>new TextEncoder().encode(x).byteLength,[x]);l.current=i,S.current=b,g.current=W;const K=a.useCallback(()=>{S.current||g.current&&!window.confirm(s("team.instructionsDiscard"))||l.current()},[]);a.useEffect(()=>{const R=document.activeElement instanceof HTMLElement?document.activeElement:null;c.current?.focus();const q=u=>{if(u.key==="Escape"&&!S.current){u.preventDefault(),K();return}if(u.key!=="Tab")return;const B=c.current;if(!B)return;const N=[...B.querySelectorAll('button:not([disabled]), textarea:not([disabled]), input:not([disabled]), [href], [tabindex]:not([tabindex="-1"])')];if(N.length===0){u.preventDefault(),B.focus();return}const O=N[0],M=N[N.length-1];u.shiftKey&&document.activeElement===O?(u.preventDefault(),M.focus()):!u.shiftKey&&document.activeElement===M&&(u.preventDefault(),O.focus())};return window.addEventListener("keydown",q),()=>{window.removeEventListener("keydown",q),R?.focus()}},[K]),a.useEffect(()=>{let R=!1;return v(!0),$(null),ne(`/api/section-context?section=${encodeURIComponent(n)}`).then(q=>{R||(I(q.text),k(q.text),A(q.updatedAt),z(q.maxBytes),window.setTimeout(()=>o.current?.focus(),0))}).catch(q=>{R||$(q instanceof Error?q.message:String(q))}).finally(()=>{R||v(!1)}),()=>{R=!0}},[n]);const G=async()=>{if(!(_>y)){j(!0),$(null);try{const R=await ne(`/api/section-context?section=${encodeURIComponent(n)}`,{method:"PUT",body:JSON.stringify({text:x})});k(R.text),I(R.text),A(R.updatedAt),z(R.maxBytes)}catch(R){$(R instanceof Error?R.message:String(R))}finally{j(!1)}}};return et.createPortal(e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/55 p-4 sm:p-6",onMouseDown:R=>R.target===R.currentTarget&&K(),children:e.jsxs("div",{ref:c,role:"dialog","aria-modal":"true","aria-labelledby":"section-context-title",tabIndex:-1,className:"animate-pop-in flex max-h-[min(680px,calc(100dvh-2rem))] w-full max-w-[680px] flex-col overflow-hidden rounded-2xl border border-hairline/50 bg-panel shadow-2xl shadow-black/50 outline-none",children:[e.jsxs("header",{className:"flex items-start justify-between gap-4 border-b border-hairline/40 px-6 pb-4 pt-6 sm:px-8 sm:pt-7",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ut,{size:19,className:"text-accent"}),e.jsx("h2",{id:"section-context-title",className:"text-[20px] font-semibold tracking-[-0.01em] text-ink",children:s("team.instructionsTitle",{name:r})})]}),e.jsx("p",{className:"mt-1.5 max-w-[520px] text-[13px] leading-relaxed text-ink-secondary",children:s("team.instructionsHint")})]}),e.jsx("button",{onClick:K,disabled:b,"aria-label":s("team.instructionsClose"),className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-40",children:e.jsx(Be,{size:19})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-5 sm:px-8",children:[H?e.jsx("div",{className:"flex min-h-[260px] items-center justify-center text-ink-secondary",children:e.jsx(Re,{size:20,className:"animate-spin","aria-label":s("team.instructionsLoading")})}):e.jsxs(e.Fragment,{children:[e.jsx("textarea",{ref:o,value:x,onChange:R=>I(R.target.value),placeholder:s("team.instructionsPlaceholder"),"aria-label":s("team.instructionsTitle",{name:r}),className:"min-h-[280px] w-full resize-y rounded-xl border border-hairline/60 bg-inset px-4 py-3 font-mono text-[13px] leading-relaxed text-ink outline-none placeholder:text-ink-tertiary focus:border-accent/50"}),e.jsxs("div",{className:"mt-2 flex items-start justify-between gap-4 text-[12px] text-ink-secondary",children:[e.jsxs("span",{children:[s("team.instructionsFactHint")," ",U?` ${s("team.instructionsLastSaved",{time:new Date(U).toLocaleString(Ee())})}`:""]}),e.jsx("span",{className:se("shrink-0 tabular-nums",_>y&&"text-danger"),children:s("team.instructionsBytes",{bytes:_.toLocaleString(Ee()),limit:y.toLocaleString(Ee())})})]})]}),E&&e.jsx("div",{className:"mt-3 rounded-lg border border-danger/30 bg-danger/10 px-3 py-2 text-[12px] text-danger",children:E})]}),e.jsxs("footer",{className:"flex items-center justify-end gap-2 border-t border-hairline/40 px-6 py-4 sm:px-8",children:[e.jsx("button",{onClick:K,disabled:b,className:"rounded-lg px-3.5 py-2 text-[13px] text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-40",children:s("common.cancel")}),e.jsxs("button",{onClick:()=>{G()},disabled:H||b||!W||_>y,className:"flex items-center gap-2 rounded-lg bg-accent px-4 py-2 text-[13px] font-medium text-white hover:brightness-110 disabled:opacity-40",children:[b?e.jsx(Re,{size:14,className:"animate-spin"}):e.jsx(ln,{size:14}),s("team.instructionsSave")]})]})]})}),document.body)}const Xn=1400;function ts(){const{state:n,dispatch:r}=Ne(),{dragProps:i}=Nt(),c=window.ogb?.remoteClient?.active===!0,o=Gt(),[l,S]=a.useState(cn),[g,x]=a.useState(null),[I,h]=a.useState(null),[k,y]=a.useState(null),[z,U]=a.useState(null),[A,H]=a.useState(null),[v,b]=a.useState(null),[j,E]=a.useState(!1),[$,W]=a.useState(0),[_,K]=a.useState([]),[G,R]=a.useState(null),q=a.useCallback(()=>R(null),[]),[u,B]=a.useState(null),N=a.useRef(u);N.current=u,a.useEffect(()=>()=>N.current?.resolve(!1),[]);const O=a.useMemo(()=>n.bots.filter(f=>!f.hidden),[n.bots]),M=a.useMemo(()=>{const f=[...new Set([...n.sections??[],...n.groups.flatMap(Q=>Q.section?[Q.section]:[])])],D=Q=>Q===""?-1:f.includes(Q)?f.indexOf(Q):f.length;return dn(O,f).sort((Q,m)=>D(Q.key)-D(m.key))},[O,n.sections,n.groups]),F=a.useMemo(()=>un(O,l),[O,l]),oe=O.some(f=>f.computer==="cloud"&&f.cloudBackend!=="vps")||_.some(f=>f.section!==null),{show:w,loaded:Y,choose:ce}=Mn(oe),ie=In(!c&&Y&&w),[re,xe]=a.useState([]),[me,pe]=a.useState(null),ue=a.useRef(void 0),be=a.useCallback(f=>{window.clearTimeout(ue.current),pe(D=>({botIds:f,key:(D?.key??0)+1})),ue.current=window.setTimeout(()=>pe(null),Xn)},[]);a.useEffect(()=>()=>window.clearTimeout(ue.current),[]);const ve=a.useMemo(()=>M.map(f=>({key:f.key,name:f.name,count:f.chiefs.length+f.members.length})),[M]),ge=a.useCallback(async(f=!1)=>{try{S(await ne("/api/team-map",f?{background:f}:void 0)),h(null)}catch(D){h(D instanceof Error?D.message:String(D))}},[]);a.useEffect(()=>{ge();const f=window.setInterval(()=>{document.visibilityState==="visible"&&ge(!0)},3e3);return()=>window.clearInterval(f)},[ge]);const Se=async(f,D)=>{x(null);try{const Q=await ne("/api/sidebar-sections",{method:"POST",body:JSON.stringify({name:D,botIds:[f.id]})});r({type:"sections",sections:Q.sections});for(const m of Q.bots)r({type:"botPatched",bot:m})}catch(Q){throw x(Q instanceof Error?Q.message:String(Q)),Q}},de=(f,D)=>new Promise(Q=>{N.current?.resolve(!1),B({bot:f,destination:D,resolve:Q})}),fe=a.useCallback(()=>{N.current?.resolve(!1),B(null)},[]);return e.jsxs("main",{className:"flex min-w-0 flex-1 flex-col overflow-hidden bg-app text-ink",children:[e.jsxs("header",{...i,className:"flex shrink-0 flex-wrap items-center justify-between gap-3 border-b border-hairline/40 px-6 py-4 max-md:pl-12",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Vt,{size:18,className:"text-ink-secondary"}),e.jsx("h1",{className:"text-[17px] font-semibold",children:s("canvas.title")}),e.jsx("span",{className:"ml-1 text-[11px] text-ink-secondary",children:pn(O.length)})]}),e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:s("canvas.description")})]}),!c&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>ce(!w),"aria-pressed":w,title:s("canvas.showComputersHint"),className:se("flex items-center gap-2 rounded-lg border px-3 py-2 text-[12px] font-medium transition-colors",w?"border-accent/40 bg-accent/10 text-ink":"border-hairline/60 bg-panel text-ink-secondary hover:bg-control hover:text-ink"),children:[e.jsx("span",{"aria-hidden":!0,className:se("relative h-4 w-7 shrink-0 rounded-full transition-colors",w?"bg-accent":"bg-control"),children:e.jsx("span",{className:se("absolute top-0.5 size-3 rounded-full bg-white shadow-sm transition-[left]",w?"left-3.5":"left-0.5")})}),s("canvas.showComputers")]}),e.jsx("button",{onClick:()=>E(f=>!f),"aria-label":s("canvas.computers"),"aria-expanded":j,className:"rounded-lg p-2 text-ink-secondary hover:bg-control hover:text-ink",children:e.jsx(Oe,{size:17})}),o!==!1&&e.jsxs("details",{className:"relative",onBlur:f=>{f.currentTarget.contains(f.relatedTarget)||f.currentTarget.removeAttribute("open")},onKeyDown:f=>{f.key==="Escape"&&(f.currentTarget.removeAttribute("open"),f.currentTarget.querySelector("summary")?.focus())},children:[e.jsxs("summary",{"aria-label":s("canvas.addToMap"),className:"flex cursor-pointer list-none items-center gap-1.5 rounded-lg border border-hairline/60 bg-panel px-3 py-2 text-[12px] font-medium hover:bg-control [&::-webkit-details-marker]:hidden",children:[e.jsx(Ke,{size:14})," ",s("common.add")]}),e.jsxs("div",{className:"absolute right-0 top-full z-40 mt-2 w-52 rounded-xl border border-hairline/60 bg-panel p-1.5 shadow-xl",onClick:f=>{const D=f.currentTarget.closest("details");D?.querySelector("summary")?.focus(),D?.removeAttribute("open")},children:[e.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-3 py-2.5 text-left text-[12px] hover:bg-control",onClick:()=>H({}),children:[e.jsx(dt,{size:14}),s("team.create")]}),e.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-3 py-2.5 text-left text-[12px] hover:bg-control",onClick:()=>{E(!0),W(f=>f+1)},children:[e.jsx(Je,{size:14}),s("canvas.cloudComputer")]}),Wt("vm",n.config)&&e.jsxs("button",{className:"flex w-full items-center gap-2 rounded-lg px-3 py-2.5 text-left text-[12px] hover:bg-control",onClick:()=>r({type:"toggleAppSettings",section:"computer",open:!0}),children:[e.jsx(Oe,{size:14}),s("canvas.localVm")]})]})]})]})]}),(g||I)&&e.jsxs("div",{role:"alert",className:"flex shrink-0 items-center justify-between gap-3 border-b border-danger/20 bg-danger/10 px-6 py-2 text-[12px] text-danger",children:[g||I,e.jsx("button",{"aria-label":s("common.close"),className:"rounded p-1 hover:bg-danger/10",onClick:()=>{x(null),h(null)},children:e.jsx(Be,{size:14})})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1",children:[e.jsxs("div",{className:"relative flex min-h-0 min-w-0 flex-1",children:[e.jsx(zn,{sections:M,canManage:!c&&o!==!1,onMove:de,taggedBotIds:re,sent:me,bottomInset:O.length?96:0,connectedBotIds:n.settingsOpen?F.flatMap(f=>f.sourceBotId===n.selectedId?[f.targetBotId]:f.targetBotId===n.selectedId?[f.sourceBotId]:[]):[],onComputer:f=>Xe(r,"access",{botId:f.id}),computers:w&&Y&&!c?ie.computers:void 0,computerFrames:ie.frames,onOpenComputer:f=>f.kind==="team"?E(!0):r({type:"toggleComputer",open:!0,botId:f.id}),teamComputers:Object.fromEntries(_.filter(f=>f.section!==null).map(f=>[f.section,{name:f.name,state:f.state}])),onTeamComputer:()=>E(!0),onComputerDrop:(f,D)=>{c||(E(!0),R({id:f,section:D}))},onInstructions:(f,D)=>y({section:f,label:D}),onMemory:(f,D)=>U({section:f,label:D}),onEditTeam:(f,D)=>H({section:f,rename:D}),onDeleteTeam:b,isEmpty:f=>![...n.bots,...n.groups].some(D=>D.section?.trim()===f)}),O.length>0&&e.jsx(qn,{bots:O,teams:ve,onTagged:xe,onSent:be})]}),!c&&e.jsx(_n,{open:j,createRequest:$,drop:G,sections:M,onClose:()=>E(!1),onDropHandled:q,onChange:K})]}),F.length>0&&e.jsxs("details",{className:"shrink-0 border-t border-hairline/40 bg-panel px-6 py-3",children:[e.jsxs("summary",{className:"cursor-pointer text-[12px] text-ink-secondary",children:[s("canvas.whoHandsOn")," · ",F.length]}),e.jsx("div",{className:"mt-3 max-h-48 space-y-2 overflow-y-auto",children:F.slice(0,12).map(f=>e.jsx(Fn,{edge:f,bots:O},`${f.sourceBotId}:${f.targetBotId}`))})]}),k&&e.jsx(Yn,{section:k.section,label:k.label,onClose:()=>y(null)}),A&&e.jsx(Qt,{...A,onClose:()=>H(null)}),z&&e.jsx(Ln,{...z,onClose:()=>U(null)},z.section),e.jsx(Ge,{open:u!==null,tone:"neutral",title:s("canvas.moveConfirmTitle",{name:u?.bot.name??s("canvas.bot"),team:u?.destination||s("settings.section.general")}),body:s("canvas.moveConfirmBody"),confirmLabel:s("canvas.moveConfirm"),onCancel:fe,onConfirm:()=>{const f=N.current;f&&(B(null),Se(f.bot,f.destination).then(()=>f.resolve(!0),()=>f.resolve(!1)))}}),e.jsx(Ge,{open:v!==null,title:s("team.deleteTitle",{name:v??""}),body:s("team.deleteKeepBotsDescription"),confirmLabel:s("team.delete"),onCancel:()=>b(null),onConfirm:()=>{const f=v;b(null),f&&ne(`/api/sidebar-sections?section=${encodeURIComponent(f)}`,{method:"DELETE"}).then(({sections:D})=>r({type:"sections",sections:D})).catch(D=>x(D instanceof Error?D.message:String(D)))}})]})}export{Fn as EdgeRow,Yn as SectionContextDialog,ts as TeamMapPage};
@@ -1 +1 @@
1
- import{j as t,a as m}from"./styles-DOJOOIp4.js";import{c as n,w as x}from"./PlacesRail-3RaNlpug.js";import{z as d}from"./App-BIllYA_e.js";const h="mr-1 text-[18px] font-semibold tracking-tight text-ink",f={WebkitAppRegion:"drag"},r={WebkitAppRegion:"no-drag"};function o(){return n().capabilities.windowChrome==="mac-inset"}function k({label:e,children:i}){return t.jsx("main",{"aria-label":e,className:"flex h-full min-w-0 flex-1 flex-col bg-app animate-workspace-in",children:i})}function j({backLabel:e,onBack:i,backRef:l,besideSidebar:a=!0,children:c}){const{capabilities:p}=n(),s=o();return t.jsx("header",{className:m("shrink-0 border-b border-hairline/35 bg-app py-3 pr-4",s&&!x(p)&&!a?"pl-[86px]":a?"pl-12 md:pl-4":"pl-4"),style:s?f:void 0,children:t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("button",{type:"button",ref:l,onClick:i,"aria-label":e,title:e,className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-raised hover:text-ink",style:s?r:void 0,children:t.jsx(d,{size:18})}),c]})})}function w({children:e}){return t.jsx("div",{className:"ml-auto flex items-center gap-3",style:o()?r:void 0,children:e})}export{k as T,j as a,h as b,w as c};
1
+ import{j as t,a as m}from"./styles-3g-ZPS7M.js";import{c as n,w as x}from"./PlacesRail-Df-jNTHn.js";import{z as d}from"./App-h8WTNY4l.js";const h="mr-1 text-[18px] font-semibold tracking-tight text-ink",f={WebkitAppRegion:"drag"},r={WebkitAppRegion:"no-drag"};function o(){return n().capabilities.windowChrome==="mac-inset"}function k({label:e,children:i}){return t.jsx("main",{"aria-label":e,className:"flex h-full min-w-0 flex-1 flex-col bg-app animate-workspace-in",children:i})}function j({backLabel:e,onBack:i,backRef:l,besideSidebar:a=!0,children:c}){const{capabilities:p}=n(),s=o();return t.jsx("header",{className:m("shrink-0 border-b border-hairline/35 bg-app py-3 pr-4",s&&!x(p)&&!a?"pl-[86px]":a?"pl-12 md:pl-4":"pl-4"),style:s?f:void 0,children:t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("button",{type:"button",ref:l,onClick:i,"aria-label":e,title:e,className:"flex size-9 shrink-0 items-center justify-center rounded-lg text-ink-secondary hover:bg-raised hover:text-ink",style:s?r:void 0,children:t.jsx(d,{size:18})}),c]})})}function w({children:e}){return t.jsx("div",{className:"ml-auto flex items-center gap-3",style:o()?r:void 0,children:e})}export{k as T,j as a,h as b,w as c};