@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,2 +0,0 @@
1
- import{c as ol,r as o,j as e,a as D,t,w as _e,X as Me,y as Ks,aC as ki,aD as cl,aX as dl,ar as Ut,aJ as Ht,d as Jt,aY as wi,q as je,ae as ul,L as at,aZ as pl,b as Ee,a_ as ml,g as Cn,a$ as xl,aE as gl,b0 as hl,b1 as fl,b2 as bl,b3 as Ni,ah as vl,b4 as En,Y as yl,b5 as Ws,b6 as jl,b7 as kl,b8 as wl,b9 as Nl,ba as Sl,aH as Cl,bb as An,aG as El,I as Al,bc as Pl,H as Tl,bd as Il,be as Ll,bf as Rl,bg as Bl,A as Ol,B as Fl,bh as Ul,bi as Ml,bj as Dl,bk as zl,i as Gs,aL as _l,bl as ft,bm as Hl,bn as Pn,bo as Tn,bp as In,bq as $l,br as Kl,bs as Wl,az as Ln,F as Gl,aw as ql,G as Rn,aA as Si,e as Bn,bt as On,o as Ps,bu as Vl,C as Ci,an as Ei,ad as Jl,bv as Ai,S as Pi,bw as Yl,v as Ti}from"./styles-DOJOOIp4.js";import{L as re,P as $e,j as Yt,C as qs,k as Xl,X as Ql,Y as Ii,r as Zl,c as Li,A as eo,Z as to,R as so,O as no,B as Xt,F as Ri,v as ao,_ as io,$ as Fn,b as ro,f as Bi,a as lo,g as oo}from"./PlacesRail-3RaNlpug.js";import{al as He,g as M,ew as co,y as ce,bG as uo,ev as pe,gk as it,gl as rt,hC as po,u as _,C as Oi,au as kt,fP as Vs,hD as Ts,aI as L,hE as Js,hF as Ys,hG as Fi,hH as mo,hI as xo,hJ as Xs,hK as go,S as ne,hL as Mt,hM as ho,bb as Qs,hN as Ui,hO as Is,hP as Mi,b4 as J,b5 as V,hQ as Ve,hR as Un,hS as fo,hT as bo,hU as vo,hV as yo,hW as jo,hX as ko,hY as ms,hZ as Di,h as ye,h_ as wo,c as Mn,dX as No,h$ as So,em as Co,i0 as Eo,c8 as Ao,et as Ke,cq as Qt,b9 as ge,b7 as xe,i1 as Po,i2 as To,i3 as Io,i4 as Lo,i5 as Ro,i6 as Bo,i7 as Oo,i8 as Fo,i9 as Uo,e4 as Zt,e3 as Mo,dM as Do,ia as wt,e2 as zo,fO as Zs,ib as _o,ic as Ho,id as $o,ie as Ue,ig as Dn,ih as zn,ii as Ko,ij as Wo,ik as zi,il as Go,im as qo,io as Vo,ip as Jo,iq as Yo,ir as Xo,is as Qo,e as _i,it as _n,iu as Zo,iv as ec,iw as tc,ix as sc,iy as nc,iz as ac,iA as Hn,iB as ic,iC as rc,gC as lc,iD as oc,iE as Hi,a4 as cc,b6 as Ne,iF as es,iG as dc,iH as uc,iI as pc,iJ as mc,iK as xc,iL as $n,g4 as gc,b8 as Nt,b0 as Ae,iM as hc,iN as fc,a8 as $i,r as bc,at as Ki,g5 as vc,iO as ts,iP as Wi,iQ as yc,iR as jc,iS as Kn,iT as Gi,iU as ss,iV as qi,iW as kc,iX as wc,iY as Wn,iZ as Nc,i_ as Sc,i$ as Gn,j0 as Cc,bZ as qn,ck as Ls,j1 as Vn,j2 as Jn,j3 as Ec,j4 as Ac,j5 as Pc,j6 as Yn,j7 as Tc,dm as Ic,j8 as Lc,j9 as Rc,ja as Bc,cj as Oc,jb as Fc,jc as Uc,jd as Vi,je as Ji,jf as Mc,T as We,gh as ns,l as Dc,jg as Xn,z as Qn,jh as Yi,ji as Zn,jj as ea,jk as zc,jl as _c,gi as st,jm as as,jn as Hc,jo as $c,jp as Kc,jq as Wc,jr as lt,dL as Xi,js as Gc,jt as qc,ju as Vc,jv as Jc,jw as xs,jx as Yc,jy as Xc,jz as Qc,gE as Zc,jA as ta,jB as ed,jC as td,dP as sd,jD as sa,jE as nd,jF as ad,dK as id,jG as rd,jH as ld,jI as od,jJ as cd,jK as dd,jL as ud,jM as pd,cw as Je,el as Rs,eX as md,fY as Qi,jN as Zi,jO as Bs,af as xd,dQ as gd,jP as hd,jQ as fd,jR as bd,jS as vd,jT as yd,jU as jd,jV as er,jW as kd,jX as tr,jY as en,i as wd,jZ as Nd,j_ as Sd,j$ as Cd,k0 as Ed,k1 as Ad,k2 as Pd,k3 as Td,k4 as tn,a9 as Id,cN as Ld,ci as qe,e_ as ot,k5 as Rd,eY as Bd,eZ as Od,k6 as ht,k7 as mt,k8 as Fd,k9 as sr,ka as nr,kb as sn,kc as Ud,ed as na,kd as ar,ke as ir,kf as rr,kg as Md,kh as Dd,ki as zd,kj as _d,A as Hd,kk as $d,kl as Kd,km as Wd,kn as Gd,f5 as qd,ko as Vd,kp as lr,gq as Jd,kq as Yd,kr as Xd,ks as Qd,kt as Zd,ku as aa,kv as eu,fi as tu,kw as su}from"./App-BIllYA_e.js";import{r as nu,C as au,s as or,b as iu,c as ru,w as lu,d as ou,T as cu,l as nn,e as ia,f as ra,g as du,h as cr}from"./index-C1PEx1tc.js";import{c as la,b as It,S as an,P as uu,a as pu,d as mu,e as oa}from"./ServerPairingCard-c2fKq1gh.js";import"./phones-J7mYR-fY.js";import{R as bt,C as St,i as dr}from"./MenuMotion-DfjnHTCi.js";import{P as xu}from"./ProIntroduction-B3phUWnc.js";import{B as gu}from"./BrowserProfilesManager-CL3TIl73.js";import{r as ur}from"./memory-BR-ujoQY.js";import{c as hu,A as ca,w as fu,d as bu,e as da}from"./activity-DrX2_Hm9.js";import{A as vt,C as vu,E as yu}from"./EnginesSettings-D643-yZk.js";import{M as ju,w as ku}from"./MacLocalControl-DoEGcs3V.js";import{DefaultBotSettings as wu}from"./NewBotDialog-D3i7j_KP.js";import"./placement-BKtVnQht.js";import"./monitor-DpsqT1_R.js";import"./SignedInSites-B2pCMdic.js";import"./VisibilitySection-Cd3TZvS_.js";import"./org-library-alRyzCTE.js";import"./package-format-BFXbXHk8.js";import"./mcp-servers-DoMFsds6.js";import"./WorksOnGrid-DHo10o0j.js";import"./RoutinesPage-CLXohizn.js";import"./remote-desktop-CsSfkXSy.js";const Nu=[["path",{d:"m19 5 3-3",key:"yk6iyv"}],["path",{d:"m2 22 3-3",key:"19mgm9"}],["path",{d:"M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z",key:"goz73y"}],["path",{d:"M7.5 13.5 10 11",key:"7xgeeb"}],["path",{d:"M10.5 16.5 13 14",key:"10btkg"}],["path",{d:"m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z",key:"1snsnr"}]],Su=ol("unplug",Nu);function Cu(s,n){const a=s&&!window.ogb?.remoteClient?.active?window.ogb?.cloudAccount:void 0,[i,r]=o.useState(null),c=a?.offer?JSON.stringify(n??null):null;return o.useEffect(()=>{if(c===null||!a?.offer)return;let l=!0;return a.offer().then(d=>{l&&r(d)},()=>{}),()=>{l=!1}},[a,c]),a?.offer?i:null}function Eu(s){const n=s?.edition?.license;return!n||typeof n.expiresAt!="string"||!Number.isFinite(n.expiresInDays)?null:n.graceEndsAt?{tone:"danger",text:t("settings.license.grace",{date:n.expiresAt,graceEnd:n.graceEndsAt})}:{tone:"warning",text:t("settings.license.expiring",{date:n.expiresAt,days:String(Math.max(0,n.expiresInDays))})}}function Au({config:s}){const n=Eu(s);return n?e.jsxs("div",{role:"status",className:D("flex items-start gap-2 rounded-xl border px-3 py-2.5 text-[13px] leading-relaxed",n.tone==="danger"?"border-danger/40 bg-danger/10 text-danger":"border-warning/40 bg-warning/10 text-warning"),children:[e.jsx(He,{size:14,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n.text})]}):null}function Pu(s){const n=s.trim().toLowerCase();return!n||/\s/.test(n)?null:n.startsWith("@")?/^@[^@\s]+\.[^@\s]+$/.test(n)?n:null:/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(n)?n:null}function ua(s,n,a){const i=s.admins.filter(c=>c!==n),r=s.members.filter(c=>c!==n);return a==="admin"?{admins:[...i,n],members:r}:{admins:i,members:[...r,n]}}function Tu(s,n){return{admins:s.admins.filter(a=>a!==n),members:s.members.filter(a=>a!==n)}}function pa(s,n){const a=s.replace(/\/+$/,"");return n.startsWith("@")?`${a}/pair`:`${a}/pair?email=${encodeURIComponent(n)}`}function Iu(s,n,a){const i=[],r=new Set,c=(l,d)=>{const u=l.trim().toLowerCase();if(!u||r.has(u))return;r.add(u);const p=n.filter(m=>m.email?.toLowerCase()===u),x=a.find(m=>m.key===`user:${u}`);i.push({entry:u,role:d,isDomain:u.startsWith("@"),lastSeenAt:p.length?Math.max(...p.map(m=>m.lastSeenAt)):null,devices:p.length,turns:x?.turns??0,costUsd:x?.costUsd??null,...it(x?.estimatedUsd)&&x.estimatedUsd>0?{estimated:!0}:{}})};for(const l of s.admins)c(l,"admin");for(const l of s.members)c(l,"member");return i}function Lu(s,n){const a=new Map;for(const i of s){const r=i.email?.trim().toLowerCase();r&&a.set(r,[...a.get(r)??[],i])}return[...a.entries()].map(([i,r])=>{const c=n.find(l=>l.key===`user:${i}`);return{entry:i,role:r.some(l=>l.scopes?.includes("admin"))?"admin":"member",isDomain:!1,lastSeenAt:Math.max(...r.map(l=>l.lastSeenAt)),devices:r.length,turns:c?.turns??0,costUsd:c?.costUsd??null}}).sort((i,r)=>i.role===r.role?i.entry.localeCompare(r.entry):i.role==="admin"?-1:1)}function Ru(s,n=Date.now()){return s===null?t("people.never"):n-s<1440*6e4?t("people.today"):new Date(s).toISOString().slice(0,10)}function pr({people:s,busy:n,onRole:a,onRemove:i,onLink:r,readOnly:c=!1}){if(s.length===0)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(c?"people.portal.empty":"people.empty")});const l="grid grid-cols-[1fr_auto_auto_auto_auto] items-center gap-x-4";return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:D(l,"border-b border-hairline/40 pb-2 text-[12px] font-medium uppercase tracking-wide text-ink-secondary"),children:[e.jsx("span",{children:t("people.colPerson")}),e.jsx("span",{children:t("people.colRole")}),e.jsx("span",{className:"text-right",children:t("people.colLastSeen")}),e.jsx("span",{className:"text-right",children:t("people.colMonth")}),e.jsx("span",{})]}),s.map(d=>e.jsxs("div",{className:D(l,"border-b border-hairline/20 py-2 text-[13px]"),children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-ink",children:d.isDomain?t("people.everyoneAt",{domain:d.entry.slice(1)}):d.entry}),d.devices>0&&e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:t("people.devices",{count:String(d.devices)})})]}),e.jsx("span",{className:D("rounded-full px-2 py-0.5 text-[11px] font-medium",d.role==="admin"?"bg-accent/15 text-accent":"bg-control text-ink-secondary"),children:d.role==="admin"?t("people.roleAdmin"):t("people.roleMember")}),e.jsx("span",{className:"text-right tabular-nums text-ink-secondary",children:d.isDomain?"—":Ru(d.lastSeenAt)}),e.jsx("span",{className:"text-right tabular-nums text-ink",title:t("people.turns",{turns:String(d.turns)}),children:it(d.costUsd)?`${d.estimated?"~":""}${rt(d.costUsd)}`:"—"}),c?e.jsx("span",{}):e.jsxs("span",{className:"flex items-center justify-end gap-2 text-[12px]",children:[e.jsx("button",{type:"button",disabled:n,onClick:()=>r(d),"aria-label":t("people.link"),title:t("people.link"),className:"rounded-md p-1 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:e.jsx(po,{size:13})}),e.jsx("button",{type:"button",disabled:n,onClick:()=>a(d,d.role==="admin"?"member":"admin"),className:"text-ink-secondary hover:text-ink disabled:opacity-50",children:d.role==="admin"?t("people.makeMember"):t("people.makeAdmin")}),e.jsx("button",{type:"button",disabled:n,onClick:()=>i(d),className:"text-danger hover:underline disabled:opacity-50",children:t("people.remove")})]})]},d.entry))]})}function mr({link:s}){const{state:n,copy:a}=Yt(s);return e.jsxs("div",{className:"mt-3 rounded-lg border border-hairline/40 bg-inset p-3 text-[13px]",children:[e.jsx("div",{className:"mb-1 text-ink-secondary",children:t("people.link")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"min-w-0 flex-1 select-all break-all text-ink",children:s}),e.jsxs("button",{type:"button",onClick:a,className:"flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:bg-control hover:text-ink",children:[n==="copied"?e.jsx(_e,{size:13,className:"text-success"}):n==="failed"?e.jsx(Me,{size:13,className:"text-danger"}):e.jsx(qs,{size:13}),t(n==="copied"?"people.copied":n==="failed"?"common.copyFailed":"people.copy")]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("people.linkHint")})]})}function Bu({peopleUrl:s,people:n}){const a=()=>{};return e.jsxs(pe,{title:t("people.title"),subtitle:t("people.portal.subtitle"),children:[e.jsxs("div",{"data-people-portal":!0,className:"flex flex-col gap-3 text-[13px] leading-relaxed text-ink-secondary",children:[e.jsx("p",{children:t("people.portal.managed")}),s&&e.jsxs("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"flex w-fit items-center gap-2 rounded-lg bg-control px-3 py-2 font-medium text-ink hover:bg-control/70",children:[t("people.portal.open")," ",e.jsx(Xl,{size:14,"aria-hidden":"true"})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(pr,{people:n,busy:!1,readOnly:!0,onRole:a,onRemove:a,onLink:a})}),e.jsx("p",{className:"mt-3 text-[12px] leading-relaxed text-ink-secondary",children:t("people.portal.note")})]})}function Ou({simple:s=!1,startOpen:n=!1}){const[a,i]=o.useState(n),[r,c]=o.useState(!1),[l,d]=o.useState(null),[u,p]=o.useState(null),[x,m]=o.useState(null),[g,f]=o.useState([]),[h,j]=o.useState(typeof window<"u"?window.location.origin:""),[b,y]=o.useState(null),[v,w]=o.useState(""),[N,C]=o.useState("member"),[I,F]=o.useState(null),[k,S]=o.useState(!1),[P,E]=o.useState(!1),[A,q]=o.useState(null),R=o.useCallback(async()=>{E(!0),q(null);try{const[Y,B,W,G,le]=await Promise.all([M("/api/config"),M("/api/auth/sessions").catch(()=>({sessions:[]})),M("/api/usage?groupBy=user").catch(()=>({groups:[]})),M("/api/settings/custom-domain").catch(()=>null),fetch("/.well-known/openmausbot/environment").then(ie=>ie.ok?ie.json():null).catch(()=>null)]),U={admins:Array.isArray(Y?.signIn?.admins)?Y.signIn.admins:[],members:Array.isArray(Y?.signIn?.members)?Y.signIn.members:[]},H=co(Y);p(H),m(U);const Q=Array.isArray(B?.sessions)?B.sessions:[],te=Array.isArray(W?.groups)?W.groups:[];f(H.authority==="portal"?Lu(Q,te):Iu(U,Q,te)),typeof G?.publicUrl=="string"&&G.publicUrl&&j(G.publicUrl),y(le?.capabilities?.emailSignIn===!0?!0:le?!1:null)}catch(Y){q(Y instanceof Error?Y.message:String(Y))}finally{E(!1)}},[]);o.useEffect(()=>{nu().then(Y=>{d(Y),la(Y)&&R()})},[R]);const K=async Y=>{S(!0),q(null);try{await M("/api/config",{method:"PUT",body:JSON.stringify({signIn:Y})}),await R()}catch(B){q(B instanceof Error?B.message:String(B))}finally{S(!1)}},Z=async()=>{if(c(!0),!x||k)return;const Y=Pu(v);if(!Y){q(t("remote.signInAccess.invalid"));return}await K(ua(x,Y,N)),w(""),F(pa(h,Y))};if(!la(l))return null;const oe=u?.authority==="portal"?e.jsx(Bu,{peopleUrl:u.peopleUrl,people:g}):null,se=e.jsxs(e.Fragment,{children:[b===!1&&(!s||r)&&e.jsx("p",{className:"mb-3 rounded-lg border border-warning/25 bg-warning/5 px-3 py-2 text-[13px] text-ink-secondary",children:t(u?.pairingCodes===!1?"people.portalSignIn":"people.notHosted")}),e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:Y=>{Y.preventDefault(),Z()},children:[e.jsx("input",{value:v,onChange:Y=>w(Y.target.value),placeholder:t("remote.signInAccess.placeholder"),"aria-label":t("people.inviteEmail"),disabled:k,className:"min-w-[16rem] flex-1 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),e.jsxs(ce,{value:N,onChange:Y=>C(Y.target.value),"aria-label":t("people.colRole"),disabled:k,children:[e.jsx("option",{value:"member",children:t("people.roleMember")}),e.jsx("option",{value:"admin",children:t("people.roleAdmin")})]}),e.jsxs("button",{type:"submit",disabled:k||!v.trim(),className:"ui-button ui-button-primary",children:[k?e.jsx(re,{size:13,className:"animate-spin"}):e.jsx($e,{size:13}),t("people.invite")]}),e.jsx("button",{type:"button",onClick:()=>{R()},disabled:P||k,"aria-label":t("people.refresh"),title:t("people.refresh"),className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:e.jsx(bt,{size:13,className:D(P&&"animate-spin")})})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("people.inviteHint")}),I&&e.jsx(mr,{link:I}),A&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:A}),e.jsx("div",{className:"mt-4",children:e.jsx(pr,{people:g,busy:k,onRole:(Y,B)=>{x&&K(ua(x,Y.entry,B))},onRemove:Y=>{x&&K(Tu(x,Y.entry))},onLink:Y=>F(pa(h,Y.entry))})}),!s&&e.jsx("p",{className:"mt-3 text-[12px] leading-relaxed text-ink-secondary",children:t("people.note")})]});return s?e.jsxs("div",{"data-people-summary":"",children:[e.jsxs("div",{role:"group","aria-label":t("people.title"),className:"flex min-w-0 items-center gap-3 px-4 py-[13px]",children:[e.jsx("span",{"aria-hidden":"true",className:"flex size-11 shrink-0 items-center justify-center rounded-full bg-ink/[0.06] text-ink-secondary",children:e.jsx(uo,{size:20})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[14px] leading-5 text-ink",children:t("people.title")}),e.jsx("div",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.simple.people")})]}),e.jsx("button",{type:"button","aria-expanded":a,className:"ui-button shrink-0",onClick:()=>i(!a),children:a?t("common.done"):t("settings.simple.people.invite")})]}),a&&e.jsx("div",{className:"px-3.5 pb-3.5 pt-1",children:oe??se})]}):oe??e.jsx(pe,{title:t("people.title"),subtitle:t("people.subtitle"),children:se})}function xr(s){return s?.edition?.features?.includes("admin")===!0&&s?.fleet?.available===!0}const Fu=()=>M("/api/fleet");function Uu({fleet:s,onAct:n,busy:a}){return s.workspaces.length===0?e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("workspaces.empty",{domain:s.domain})}):e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"grid grid-cols-[1fr_auto_auto_auto] gap-x-5 border-b border-hairline/40 pb-2 text-[12px] font-medium uppercase tracking-wide text-ink-secondary",children:[e.jsx("span",{children:t("workspaces.colWorkspace")}),e.jsx("span",{className:"text-right",children:t("workspaces.colState")}),e.jsx("span",{className:"text-right",children:t("workspaces.colMonth")}),e.jsx("span",{})]}),s.workspaces.map(i=>{const r=i.status==="suspended",c=i.status==="running"||r,l=i.status==="provisioning"?t("workspaces.provisioning"):i.status==="error"?t("workspaces.error"):i.status==="retained"?t("workspaces.retained"):r?t("workspaces.suspended"):i.live==="active"?t("workspaces.running"):i.live;return e.jsxs("div",{className:"grid grid-cols-[1fr_auto_auto_auto] items-center gap-x-5 border-b border-hairline/20 py-2 text-[13px]",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-ink",children:i.slug}),e.jsx("a",{href:`https://${i.host}`,target:"_blank",rel:"noreferrer",className:"block truncate text-[12px] text-accent hover:underline",children:i.host}),!c&&e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:t("workspaces.recoveryHint")})]}),e.jsx("span",{className:D("text-right",r||i.status==="provisioning"?"text-warning":i.status==="running"&&i.live==="active"?"text-success":"text-danger"),children:l}),e.jsxs("span",{className:"text-right tabular-nums text-ink",title:i.usage.turns===null?void 0:t("workspaces.turns",{turns:String(i.usage.turns)}),children:[it(i.usage.costUsd)?rt(i.usage.costUsd):"—",it(i.usage.billableUsd)&&e.jsxs("span",{className:"text-ink-secondary",children:[" · ",rt(i.usage.billableUsd)]})]}),e.jsx("span",{className:"flex items-center justify-end gap-2 text-[12px]",children:c&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:a!==null,onClick:()=>n(i.slug,"users"),className:"text-ink-secondary hover:text-ink disabled:opacity-50",children:t("workspaces.users")}),e.jsx("button",{type:"button",disabled:a!==null,onClick:()=>n(i.slug,r?"resume":"suspend"),className:"text-ink-secondary hover:text-ink disabled:opacity-50",children:r?t("workspaces.resume"):t("workspaces.suspend")}),e.jsx("button",{type:"button",disabled:a!==null,onClick:()=>n(i.slug,"delete"),className:"text-danger hover:underline disabled:opacity-50",children:t("workspaces.delete")})]})})]},i.slug)})]})}function Mu({domain:s,onCreated:n,disabled:a}){const[i,r]=o.useState(""),[c,l]=o.useState(""),[d,u]=o.useState(""),[p,x]=o.useState(""),[m,g]=o.useState(""),[f,h]=o.useState(!1),[j,b]=o.useState(null),y=async()=>{if(!f){h(!0),b(null);try{const w={slug:i.trim().toLowerCase(),admins:[c.trim()],members:d.split(/[,\s]+/).map(C=>C.trim()).filter(Boolean),...p.trim()?{cap:Number(p)}:{},...m.trim()?{anthropicKey:m.trim()}:{}},N=await M("/api/fleet/workspaces",{method:"POST",body:JSON.stringify(w)});r(""),l(""),u(""),x(""),g(""),n(N.log??[],{slug:w.slug,admin:w.admins[0]})}catch(w){b(w instanceof Error?w.message:String(w))}finally{h(!1)}}},v="w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50";return e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:w=>{w.preventDefault(),y()},children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.name"),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{value:i,onChange:w=>r(w.target.value),placeholder:"acme",pattern:"[a-z][a-z0-9-]{1,30}",required:!0,disabled:a||f,"aria-label":t("workspaces.name"),className:v}),e.jsxs("span",{className:"whitespace-nowrap text-[12px] text-ink-secondary",children:[".",s]})]})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.adminEmail"),e.jsx("input",{value:c,onChange:w=>l(w.target.value),type:"email",required:!0,disabled:a||f,"aria-label":t("workspaces.adminEmail"),className:v})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.members"),e.jsx("input",{value:d,onChange:w=>u(w.target.value),placeholder:"bob@acme.test, @acme.test",disabled:a||f,"aria-label":t("workspaces.members"),className:v})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.cap"),e.jsx("input",{value:p,onChange:w=>x(w.target.value),inputMode:"decimal",placeholder:"50",disabled:a||f,"aria-label":t("workspaces.cap"),className:v})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary sm:col-span-2",children:[t("workspaces.anthropicKey"),e.jsx("input",{value:m,onChange:w=>g(w.target.value),type:"password",autoComplete:"off",placeholder:"sk-ant-…",disabled:a||f,"aria-label":t("workspaces.anthropicKey"),className:v})]})]}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("workspaces.createHint")}),j&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:j}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{type:"submit",disabled:a||f,className:"ui-button ui-button-primary",children:[f?e.jsx(re,{size:13,className:"animate-spin"}):e.jsx($e,{size:13}),f?t("workspaces.creating"):t("workspaces.create")]})})]})}function Du({slug:s,onDone:n}){const[a,i]=o.useState(""),[r,c]=o.useState(!1),[l,d]=o.useState(null),[u,p]=o.useState(null),x=async m=>{if(!l){d(m),p(null);try{const g=await M(`/api/fleet/workspaces/${encodeURIComponent(s)}/users`,{method:"POST",body:JSON.stringify({action:m,email:a.trim(),chatOnly:r})});i(""),n(g.log??[])}catch(g){p(g instanceof Error?g.message:String(g))}finally{d(null)}}};return e.jsxs("div",{className:"mt-2 rounded-lg border border-hairline/40 p-3",children:[e.jsx("div",{className:"mb-2 text-[13px] font-medium text-ink",children:t("workspaces.usersTitle",{slug:s})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{value:a,onChange:m=>i(m.target.value),type:"text",placeholder:"person@example.com or @example.com","aria-label":t("workspaces.email"),disabled:l!==null,className:"min-w-[16rem] flex-1 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),e.jsxs("label",{className:"flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:r,onChange:m=>c(m.target.checked),disabled:l!==null}),t("workspaces.chatOnly")]}),e.jsx("button",{type:"button",disabled:l!==null||!a.trim(),onClick:()=>{x("add")},className:"rounded-lg bg-raised px-3 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:l==="add"?t("workspaces.working"):t("workspaces.addUser")}),e.jsx("button",{type:"button",disabled:l!==null||!a.trim(),onClick:()=>{x("remove")},className:"rounded-lg px-3 py-1.5 text-[12px] text-danger hover:underline disabled:opacity-50",children:l==="remove"?t("workspaces.working"):t("workspaces.removeUser")})]}),u&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:u})]})}function zu({load:s=Fu}){const{state:n}=_(),[a,i]=o.useState(null),[r,c]=o.useState(null),[l,d]=o.useState(!1),[u,p]=o.useState(null),[x,m]=o.useState([]),[g,f]=o.useState(null),[h,j]=o.useState(null),[b,y]=o.useState(!1),[v,w]=o.useState(null),N=o.useCallback(async()=>{d(!0),c(null);try{i(await s())}catch(k){c(k instanceof Error?k.message:String(k))}finally{d(!1)}},[s]);o.useEffect(()=>{N()},[N]);const C=async(k,S)=>{if(S==="users"){f(P=>P===k?null:k);return}if(S==="delete"){j({slug:k,keepData:!1});return}p(k),c(null);try{const P=await M(`/api/fleet/workspaces/${encodeURIComponent(k)}/${S}`,{method:"POST"});m(P.log??[]),await N()}catch(P){c(P instanceof Error?P.message:String(P))}finally{p(null)}},I=async()=>{if(!h)return;const{slug:k,keepData:S}=h;j(null),p(k),c(null);try{const P=await M(`/api/fleet/workspaces/${encodeURIComponent(k)}`,{method:"DELETE",body:JSON.stringify({keepData:S})});m(P.log??[]),await N()}catch(P){c(P instanceof Error?P.message:String(P))}finally{p(null)}},F=async()=>{p("*"),c(null);try{const k=await M("/api/fleet/upgrade",{method:"POST"});m(k.log??[t("workspaces.upgraded")]),await N()}catch(k){c(k instanceof Error?k.message:String(k))}finally{p(null)}};return xr(n.config)?e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsxs(pe,{title:t("workspaces.title"),subtitle:t("workspaces.subtitle"),children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{N()},disabled:l||u!==null,className:"flex items-center gap-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[e.jsx(bt,{size:12,className:D(l&&"animate-spin")}),t("workspaces.refresh")]}),e.jsxs("button",{type:"button",onClick:()=>y(k=>!k),disabled:u!==null,className:"ml-auto flex items-center gap-1.5 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:[e.jsx($e,{size:13}),t("workspaces.new")]}),e.jsx("button",{type:"button",onClick:()=>{F()},disabled:u!==null||!a?.workspaces.length,className:"rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:u==="*"?t("workspaces.working"):t("workspaces.upgradeAll")})]}),b&&a&&e.jsx("div",{className:"mb-4 rounded-xl border border-hairline/40 p-3",children:e.jsx(Mu,{domain:a.domain,disabled:u!==null,onCreated:(k,S)=>{y(!1),m(k),w(`https://${S.slug}.${a.domain}/pair?email=${encodeURIComponent(S.admin)}`),N()}})}),v&&e.jsx("div",{className:"mb-4",children:e.jsx(mr,{link:v})}),r&&e.jsx("p",{role:"alert",className:"mb-2 text-[12px] text-danger",children:r}),a?e.jsx(Uu,{fleet:a,onAct:(k,S)=>{C(k,S)},busy:u}):l?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(re,{size:14,className:"animate-spin"}),t("common.checking")]}):null,g&&e.jsx(Du,{slug:g,onDone:k=>{m(k),N()}}),x.length>0&&e.jsx("pre",{className:"mt-3 max-h-40 overflow-auto rounded-lg bg-inset p-2 text-[12px] text-ink-secondary",children:x.join(`
2
- `)})]}),e.jsx(Oi,{open:h!==null,title:t("workspaces.deleteTitle",{slug:h?.slug??""}),body:t(h?.keepData?"workspaces.deleteKeepHint":"workspaces.deleteHint"),confirmLabel:t("workspaces.delete"),onCancel:()=>j(null),onConfirm:()=>{I()}}),h&&e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:h.keepData,onChange:k=>j({...h,keepData:k.target.checked})}),t("workspaces.keepData")]})]}):null}function _u(){const{state:s}=_(),n=Ks(),a=kt()===!0,i=ki(),r=Hu(),c=typeof window>"u"?void 0:window.ogb,l=c?.remoteClient?.active===!0,d=s.config?.cloudHome===!0,u=!!s.config?.team,p=!!c;return{desktop:p,here:Ts(),home:Ts()||!!c?.home,cloud:d,team:u,client:l,admin:a,places:r>1||!c?.environments&&cl(i),plan:p?!!(c?.cloudAccount||c?.cloudPlan&&d):d&&!u&&a,organization:!!c?.organization&&!l,environments:!!c?.environments,installations:xr(s.config),skills:Vs(s.config),advanced:n}}function Hu(){const[s,n]=o.useState(0);return o.useEffect(()=>{const a=window.ogb?.remoteClient?.active?void 0:window.ogb?.environments;if(!a)return;let i=!0;return a.state().then(r=>{i&&n(r?.environments?.length??0)}).catch(()=>{}),()=>{i=!1}},[]),s}function Ct(s){const{places:n}=ki(),[a,i]=o.useState([]),r=typeof window>"u"||window.ogb?.remoteClient?.active?void 0:window.ogb?.environments;o.useEffect(()=>{if(!r||n.length>0)return;let d=!0;return r.state().then(u=>{!d||!u||i(u.environments.filter(p=>p.id!==u.activeId).map(p=>({key:p.id,name:p.kind==="local"&&!p.dataDir?t("rail.thisComputer"):p.name,kind:p.kind==="remote"?"cloud":"computer",color:p.color??null,open:()=>{r.switch(p.id)}})))}).catch(()=>{}),()=>{d=!1}},[r,n.length]);const c=typeof window>"u"?void 0:window.ogb?.workspaces?.open;if(n.length>0)return n.filter(d=>!d.active).map(d=>({key:d.id,name:d.name,kind:d.kind,color:d.color??null,open:()=>{c?.(d.id)}}));const l=typeof window>"u"||window.ogb?.remoteClient?.active?void 0:window.ogb?.rail?.openComputer;return a.length===0&&l&&!Ts()?[{key:"computer",name:t("rail.thisComputer"),kind:"computer",color:null,open:()=>{l(s).catch(()=>{})}}]:a}const $t=(s=dl())=>t("settings.overview.version",{version:s}),rn=o.createContext(null);function we(){const s=o.useContext(rn);if(!s)throw new Error("useSettingsShell outside Settings");return s}function Et(){const s=o.useContext(rn)?.page,a=Ct(s).find(i=>i.kind==="computer");return{name:a?.name??t("rail.thisComputer"),open:a?.open??null}}function $u({reason:s}){const n=Et();return e.jsxs(e.Fragment,{children:[s??t("settings.inert.fromHere",{place:n.name}),n.open&&e.jsxs(e.Fragment,{children:[" ",e.jsx("button",{type:"button",className:"cursor-pointer text-accent-text hover:underline focus-visible:underline",onClick:n.open,children:t("settings.inert.switchHere",{place:n.name})})]})]})}function ct({title:s,subtitle:n,control:a,reason:i}){const r=Et(),c=i??t("settings.inert.fromHere",{place:r.name});return e.jsx(L,{title:s,subtitle:n,inert:e.jsx($u,{reason:i}),inertText:c,children:a??null})}const Ku="relative flex h-8 w-full shrink-0 cursor-pointer items-center gap-2 rounded-lg px-2 text-left text-[13px] leading-5 text-ink transition-colors motion-reduce:transition-none focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus";function De({place:s,size:n}){if(ul(s.color))return e.jsx(Ii,{place:{kind:s.kind==="server"?"cloud":s.kind,name:s.name,color:s.color,...s.named?{named:!0}:{}},size:n});const a=n<=14?10:n<=20?12:14;return e.jsx("span",{"aria-hidden":"true","data-place-badge":s.kind,className:"grid shrink-0 place-items-center bg-ink/[0.06] font-semibold leading-none text-ink-secondary shadow-[inset_0_0_0_0.5px_var(--settings-edge)]",style:{width:n,height:n,borderRadius:Math.round(n*.3),fontSize:Math.max(7,Math.round(n*.4))},children:s.kind==="computer"&&!s.named?e.jsx(at,{size:a,strokeWidth:1.75}):pl(s.name)})}function gr({size:s}){return e.jsxs("span",{className:"relative shrink-0",style:{width:s,height:s},children:[e.jsx("img",{src:"/app-icon.svg",alt:"",width:s,height:s,className:"rounded-[6px]",style:{width:s,height:s}}),e.jsx("span",{"aria-hidden":"true",className:"absolute inset-0 rounded-[6px] shadow-[inset_0_0_0_0.5px_var(--settings-edge)]"})]})}function Kt({size:s}){const{profile:n}=Ys();return e.jsx(Ql,{initials:Ui(n),avatarUrl:n?.avatarUrl,size:s,fontSize:Math.round(s*.42),className:"bg-ink/[0.08]"})}function Wu(s){const{state:n}=_();if(Xs()?.status==="downloaded"&&s.kind==="computer")return t("sidebar.update.readyShort");if(s.kind==="computer"){const i=n.bots.length;return i===0?t("settings.place.botsNone"):i===1?t("settings.place.botsOne"):t("settings.place.botsMany",{count:i})}return s.kind==="server"?t("settings.place.running"):t("settings.place.alwaysOn")}function Gu(s){const n=Xs();return s?n?.status==="downloaded"?t("settings.app.updateReadyLine",{version:Ht()}):t("settings.app.upToDateLine",{version:Ht()}):t("settings.scope.browser")}function ln(s,n,a){return s==="place"?n.name:s==="account"?t("settings.page.account"):a?t("settings.page.app"):t("settings.page.browser")}function xt(s,n,a){return s.id==="overview"?n.name:s.id==="account"||s.id==="app"?ln(s.owner,n,a):t(s.labelKey)}function qu({page:s,current:n,badge:a,name:i,line:r,onOpen:c,narrow:l}){return e.jsxs("button",{type:"button","data-settings-page":s,"data-settings-section":s,"data-settings-identity":"","aria-current":n?"page":void 0,onClick:c,className:D("flex w-full shrink-0 cursor-pointer items-center gap-2 rounded-lg px-2 py-1 text-left",l?"h-12":"h-11"," transition-colors motion-reduce:transition-none focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus",n?"bg-menu-active":"hover:bg-menu-hover"),children:[e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center overflow-hidden rounded-[6px]",children:a}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate text-[14px] font-medium leading-[18px] text-ink",children:i}),e.jsx("span",{className:"truncate text-[12px] leading-4 text-ink-secondary",children:r})]}),l&&e.jsx(St,{size:14,"aria-hidden":"true",className:"shrink-0 text-ink-tertiary rtl:-scale-x-100"})]})}function Vu({page:s,label:n,current:a,dot:i,onOpen:r}){const c=s.icon;return e.jsxs("button",{type:"button","data-settings-page":s.id,"data-settings-section":s.id,"aria-current":a?"page":void 0,onClick:r,className:D(Ku,a?"bg-menu-active font-medium":"hover:bg-menu-hover"),children:[e.jsx("span",{className:"flex w-6 shrink-0 justify-center",children:c&&e.jsx(c,{size:16,strokeWidth:1.75,"aria-hidden":"true",className:a?"text-ink":"text-ink-secondary"})}),e.jsxs("span",{className:"grid min-w-0 flex-1 grid-cols-[minmax(0,1fr)] overflow-hidden",title:n,children:[e.jsx("span",{className:"min-w-0 overflow-hidden text-ellipsis whitespace-nowrap [grid-area:1/1]",children:n}),e.jsx("span",{"aria-hidden":"true",className:"invisible h-0 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap font-medium [grid-area:1/1]",children:n})]}),i&&e.jsx("span",{"aria-hidden":"true",className:D("size-1.5 shrink-0 rounded-full",i==="success"?"bg-success":"bg-warning")})]})}function Ju({query:s,onQuery:n,onClose:a,onFirst:i}){return e.jsxs("div",{className:"flex h-8 shrink-0 items-center gap-2 rounded-lg border-[0.5px] border-(--settings-edge) px-2 focus-within:border-ink/25",children:[e.jsx(Jt,{size:14,"aria-hidden":"true",className:"shrink-0 text-ink-tertiary"}),e.jsx("input",{"data-settings-search":!0,value:s,onChange:r=>n(r.target.value),onKeyDown:r=>{if(r.key==="ArrowDown"){r.preventDefault(),i();return}r.key==="Escape"&&(r.stopPropagation(),s?n(""):a())},placeholder:t("settings.searchAria"),"aria-label":t("settings.searchAria"),className:"h-full w-full min-w-0 text-ellipsis bg-transparent text-[13px] leading-5 text-ink outline-none placeholder:text-ink-tertiary"}),s?e.jsx("button",{type:"button","aria-label":t("settings.search.clear"),onClick:()=>n(""),className:"flex size-4 shrink-0 cursor-pointer items-center justify-center text-ink-tertiary hover:text-ink",children:e.jsx(Me,{size:12,"aria-hidden":"true"})}):e.jsx("kbd",{"aria-hidden":"true",className:"flex size-4 shrink-0 items-center justify-center rounded-[4px] border-[0.5px] border-(--settings-edge) font-sans text-[11px] font-medium leading-4 text-ink-tertiary",children:"/"})]})}function Yu(s){if(!["ArrowDown","ArrowUp","Home","End"].includes(s.key))return;const n=[...s.currentTarget.querySelectorAll("button[data-settings-page], button[data-settings-hit]")],a=n.indexOf(document.activeElement);if(a<0&&s.key!=="Home"&&s.key!=="End")return;s.preventDefault();const i=s.key==="Home"?0:s.key==="End"?n.length-1:s.key==="ArrowDown"?Math.min(n.length-1,a+1):Math.max(0,a-1);n[i]?.focus()}function Xu({ctx:s,place:n,pages:a,current:i,query:r,hits:c,keyHits:l,onKey:d,onQuery:u,onOpen:p,onHit:x,onClose:m,narrow:g,onAdvanced:f=Ut}){const h=Js(),{profile:j}=Ys(),b={...h,email:h.email??(h.plan?j?.email??null:null)},y=Wu(n),v=Gu(s.desktop),w=Fi(!s.client),N=o.useRef(null),C=s.desktop&&!window.ogb?.cloudAccount&&!window.ogb?.cloudPlan,I={place:{badge:e.jsx(De,{place:n,size:24}),name:n.name,line:y,page:"overview"},account:{badge:e.jsx(Kt,{size:24}),name:t("settings.page.account"),line:mo(b,{browser:!s.desktop,place:n.name,openSource:C}),page:"account"},app:{badge:e.jsx(gr,{size:24}),name:s.desktop?t("settings.page.app"):t("settings.page.browser"),line:v,page:"app"}},F=S=>S==="phone"&&w.kind==="paired"&&w.connected?"success":S==="phone"&&w.kind==="attention"?"warning":null,k=r.trim()!=="";return e.jsxs("nav",{"aria-label":t("settings.title"),className:D("flex min-h-0 flex-col",g?"flex-1":"w-[220px] shrink-0 shadow-[inset_-0.5px_0_0_var(--settings-edge)]"),children:[e.jsx("div",{className:D("shrink-0",g?"px-4 pb-2":"p-3 pb-0"),children:e.jsx(Ju,{query:r,onQuery:u,onClose:m,onFirst:()=>N.current?.querySelector("button[data-settings-hit], button[data-settings-page]")?.focus()})}),e.jsx("div",{ref:N,onKeyDown:Yu,className:D("settings-scroll flex min-h-0 flex-1 flex-col overflow-y-auto",g?"px-2 pb-4 pt-1":"px-3 pb-3 pt-3"),children:k?e.jsx(Zu,{ctx:s,place:n,hits:c,keyHits:l,onKey:d,query:r,onHit:x}):xo.map((S,P)=>{const E=a.filter(q=>q.owner===S&&q.id!==I[S].page),A=I[S];return e.jsxs("div",{role:"group","aria-label":A.name,"data-settings-group":S,className:D("flex flex-col gap-0.5",P>0&&"mt-4"),children:[e.jsx(qu,{page:A.page,current:i===A.page,badge:A.badge,name:A.name,line:A.line,narrow:g,onOpen:()=>p(A.page)}),e.jsx("div",{className:"mt-0.5 flex flex-col gap-0.5",children:E.map(q=>g?e.jsxs("button",{type:"button","data-settings-page":q.id,"data-settings-section":q.id,onClick:()=>p(q.id),className:"flex h-11 w-full cursor-pointer items-center gap-2 rounded-lg px-2 text-left text-[14px] leading-5 text-ink hover:bg-menu-hover",children:[e.jsx("span",{className:"flex w-6 shrink-0 justify-center",children:q.icon&&e.jsx(q.icon,{size:16,strokeWidth:1.75,"aria-hidden":"true",className:"text-ink-secondary"})}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t(q.labelKey)}),F(q.id)&&e.jsx("span",{"aria-hidden":"true",className:D("size-1.5 rounded-full",F(q.id)==="success"?"bg-success":"bg-warning")}),e.jsx(St,{size:14,"aria-hidden":"true",className:"text-ink-tertiary rtl:-scale-x-100"})]},q.id):e.jsx(Vu,{page:q,label:t(q.labelKey),current:i===q.id,dot:F(q.id),onOpen:()=>p(q.id)},q.id))})]},S)})}),e.jsx(Qu,{narrow:g,onChange:f})]})}function Qu({narrow:s,onChange:n}){const a=Ks();return e.jsxs("div",{"data-settings-block":"advanced-mode",title:t("settings.advancedMode.tooltip"),className:D("flex h-12 shrink-0 items-center justify-between gap-3 shadow-[inset_0_0.5px_0_var(--settings-edge)]",s?"px-4":"px-5"),children:[e.jsx("span",{id:"settings-advanced-mode",className:"text-[13px] leading-5 text-ink",children:t("settings.advancedMode.title")}),e.jsx(ne,{checked:a,"aria-labelledby":"settings-advanced-mode","data-settings-advanced-switch":"",onClick:()=>n(!a)})]})}function Zu({ctx:s,place:n,hits:a,keyHits:i,onKey:r,query:c,onHit:l}){const d=a.filter(p=>!p.elsewhere).slice(0,8),u=a.filter(p=>p.elsewhere).slice(0,8);return d.length===0&&u.length===0&&i.length===0?e.jsxs("div",{"data-settings-no-match":"",className:"flex flex-col items-center gap-1 px-2 py-6 text-center",children:[e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.noMatch",{query:c.trim()})}),e.jsx("a",{href:wi,target:"_blank",rel:"noreferrer",className:"text-[12px] leading-4 text-accent-text hover:underline",children:t("settings.search.helpCenter")})]}):e.jsxs("div",{className:"flex flex-col gap-0.5","data-settings-results":"",children:[d.map(p=>e.jsx(ma,{ctx:s,place:n,hit:p,query:c,onHit:l},`h:${p.entry.id}`)),i.map(p=>e.jsxs("button",{type:"button","data-settings-key-result":p.id,onClick:()=>r(p),className:"flex w-full cursor-pointer flex-col rounded-lg px-2 py-1.5 text-left hover:bg-menu-hover focus-visible:bg-menu-hover focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus",children:[e.jsx("span",{className:"truncate text-[13px] leading-5 text-ink",children:hr(t(p.labelKey),c)}),e.jsx("span",{className:"truncate text-[12px] leading-4 text-ink-secondary",children:[n.name,t("settings.group.ai"),t(go(p).titleKey)].join(" › ")})]},`k:${p.id}`)),u.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-2 pb-1 pt-3 text-[12px] leading-4 text-ink-secondary",children:t("settings.search.otherPlaces")}),u.map(p=>e.jsx(ma,{ctx:s,place:n,hit:p,query:c,onHit:l},`e:${p.entry.id}`))]})]})}function hr(s,n){const a=s.toLocaleLowerCase().indexOf(n.trim().toLocaleLowerCase());if(a<0||!n.trim())return s;const i=a+n.trim().length;return e.jsxs(e.Fragment,{children:[s.slice(0,a),e.jsx("span",{className:"font-medium",children:s.slice(a,i)}),s.slice(i)]})}function on(s,n,a){return s.entry.id==="page:overview"?n.name:s.entry.id==="page:account"?t("settings.page.account"):s.entry.id==="page:app"?a?t("settings.page.app"):t("settings.page.browser"):t(s.entry.macLabelKey&&dr()?s.entry.macLabelKey:s.entry.labelKey,{app:je(),helper:""})}function ma({ctx:s,place:n,hit:a,query:i,onHit:r}){const c=a.entry,l=on(a,n,s.desktop),d=ep(a,n,s),u=vr(a,n,s),p=c.jump?null:Mt(c.page).icon,x=a.advanced&&!s.advanced;return e.jsxs("button",{type:"button","data-settings-hit":c.id,onClick:()=>r(a),title:u?`${l} · ${u}`:l,className:"flex w-full cursor-pointer items-start gap-2 rounded-lg px-2 py-1.5 text-left hover:bg-menu-hover focus-visible:bg-menu-hover focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus",children:[e.jsx("span",{className:"flex h-5 w-6 shrink-0 items-center justify-center text-ink-secondary",children:p&&e.jsx(p,{size:16,strokeWidth:1.75,"aria-hidden":"true"})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{"data-settings-hit-title":"",className:"line-clamp-2 text-[13px] leading-5 text-ink [overflow-wrap:anywhere]",children:hr(l,i)}),(d||x)&&e.jsxs("span",{"data-settings-hit-location":"",className:"flex min-w-0 items-center gap-1.5 text-[12px] leading-4 text-ink-secondary",children:[d&&e.jsxs("span",{className:"flex min-w-0 flex-[0_1_auto] overflow-hidden whitespace-nowrap",children:[e.jsx("span",{className:"min-w-[1.5em] shrink-[100] overflow-hidden text-ellipsis",children:d.owner}),d.page&&e.jsx("span",{className:"min-w-0 shrink overflow-hidden text-ellipsis",children:` › ${d.page}`})]}),x&&e.jsx("span",{className:"flex flex-none",children:e.jsx(ho,{children:t("settings.simple.advanced")})})]})]}),c.jump&&e.jsx(Qs,{size:12,"aria-hidden":"true",className:"mt-1 shrink-0 text-ink-tertiary"})]})}const fr={overview:"place",phone:"place",ai:"place",bots:"place",desktops:"place",vault:"place",usage:"place",transfer:"place",data:"place",people:"place",installations:"place",account:"account",plan:"account",app:"app",general:"app",appearance:"app"},br={phone:"settings.section.phoneDevices",ai:"settings.group.ai",bots:"settings.page.bots",desktops:"settings.page.desktops",vault:"settings.section.vault",usage:"settings.page.spending",transfer:"settings.page.importExport",data:"settings.page.data",people:"settings.section.people",installations:"settings.section.workspaces",plan:"settings.page.plan",general:"settings.section.general",appearance:"settings.section.appearance"};function ep(s,n,a){const i=s.entry;if(i.jump)return{owner:vr(s,n,a)};if(i.id.startsWith("page:")&&(i.page==="overview"||i.page==="account"||i.page==="app"))return null;const r=fr[i.page],c=s.elsewhere?t("rail.thisComputer"):r==="place"?n.name:ln(r,n,a.desktop),l=br[i.page];return{owner:c,...l&&!i.id.startsWith("page:")?{page:t(l)}:{}}}function vr(s,n,a){const i=s.entry;if(i.jump==="apps")return t("settings.search.opensApps");if(i.jump==="bot")return t("settings.search.onEachBot");if(i.jump==="automations")return t("settings.search.opensAutomations");if(i.jump==="shortcuts")return t("settings.search.opensShortcuts");const r=fr[i.page],c=s.elsewhere?t("rail.thisComputer"):r==="place"?n.name:ln(r,n,a.desktop),l=br[i.page],d=[c];l&&!i.id.startsWith("page:")&&d.push(t(l));const u=on(s,n,a.desktop);return i.sectionKey&&t(i.sectionKey)!==u&&d.push(t(i.sectionKey)),i.id.startsWith("page:")&&(i.page==="overview"||i.page==="account"||i.page==="app")?"":d.join(" › ")}const tp="https://cal.com/milind-soni-002qed/30min",sp=["feature","price","setup","broken","later","other"],np={feature:"cloudCancel.answer.feature",price:"cloudCancel.answer.price",setup:"cloudCancel.answer.setup",broken:"cloudCancel.answer.broken",later:"cloudCancel.answer.later",other:"cloudCancel.answer.other"},xa=2e3,Os=s=>new Intl.DateTimeFormat(Ee(),{dateStyle:"medium"}).format(new Date(s)),ap=s=>s.endsAt??s.renewsAt;function cn(s){const n=ap(s);return s.trial?n?t("cloudCancel.endedTrial",{date:Os(n)}):t("cloudCancel.endedTrialNoDate"):n?t("cloudCancel.endedPlan",{date:Os(n)}):t("cloudCancel.endedPlanNoDate")}function ip(s){const n=s.team?t("cloudCancel.teamStops",{team:s.team}):t("cloudCancel.stops"),a=s.keptDays;if(a===null)return n;const i=a<=0?t("cloudCancel.keptNone"):Number.isInteger(a)?a===1?t("cloudCancel.keptDay"):t("cloudCancel.keptDays",{days:a}):t("cloudCancel.keptHours",{hours:Math.max(1,Math.round(a*24))});return`${n} ${i}`}function rp(s){return[s.renewsAt?t(s.trial?"cloudCancel.runsTrial":"cloudCancel.runsPlan",{date:Os(s.renewsAt)}):null,t(s.trial?"cloudCancel.nothingCharged":"cloudCancel.noMoreCharges"),s.team?t("cloudCancel.teamStops",{team:s.team}):null].filter(Boolean).join(" ")}function lp({renewal:s,actions:n,onClose:a}){const[i,r]=o.useState(null),[c,l]=o.useState(""),[d,u]=o.useState(""),[p,x]=o.useState({step:"ask"}),[m,g]=o.useState(!1),[f,h]=o.useState(!1),j=o.useRef(!1),b=o.useRef(null),y=()=>{m||a(j.current)};o.useEffect(()=>{const k=document.activeElement instanceof HTMLElement?document.activeElement:null;return b.current?.querySelector("button[aria-pressed]")?.focus(),()=>{k?.isConnected&&k.focus()}},[]);const v=k=>{g(!0),h(!1),k().catch(()=>h(!0)).finally(()=>g(!1))},w=()=>v(async()=>{const k=i!==null||c.trim()!==""||d.trim()!=="",S=await n.cancel(k?{answer:i,...c.trim()?{expected:c}:{},...d.trim()?{improve:d}:{}}:null);S.outcome==="cancelled"?(j.current=!0,x({step:"done",renewal:S.renewal??{...s,cancelled:!0,endsAt:s.renewsAt,renewsAt:null},surveyed:S.surveyed})):S.outcome==="browser"?x({step:"browser"}):h(!0)}),N=()=>v(async()=>{const k=await n.keep();k.outcome==="kept"?(j.current=!0,a(!0)):k.outcome==="browser"?x({step:"browser"}):h(!0)}),C=t(s.trial?"cloudCancel.titleTrial":"cloudCancel.titlePlan"),I="mt-1.5 w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[14px] text-ink disabled:opacity-60",F=f&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("cloudCancel.failed")});return Zl.createPortal(e.jsx("div",{className:"fixed inset-0 z-[80] flex items-center justify-center bg-black/55 p-4",onMouseDown:k=>{k.target===k.currentTarget&&y()},children:e.jsxs("div",{ref:b,role:"dialog","aria-modal":"true","aria-labelledby":"cloud-cancel-title","aria-busy":m,tabIndex:-1,"data-cloud-cancel-sheet":p.step,className:"flex max-h-[90vh] w-full max-w-[480px] flex-col overflow-hidden rounded-2xl border border-hairline/50 bg-panel text-ink shadow-2xl outline-none",onKeyDown:k=>{if(k.key==="Escape"&&(k.stopPropagation(),y()),k.key==="Tab"){const S=b.current?.querySelectorAll("a[href], textarea:enabled, button:enabled");if(!S?.length)return;const P=S[0],E=S[S.length-1];k.shiftKey&&document.activeElement===P?(k.preventDefault(),E.focus()):!k.shiftKey&&document.activeElement===E&&(k.preventDefault(),P.focus())}},children:[e.jsxs("header",{className:"flex items-start justify-between gap-3 px-6 pb-1 pt-5",children:[e.jsx("h2",{id:"cloud-cancel-title",className:"text-[17px] font-semibold",children:C}),e.jsx("button",{type:"button","aria-label":t("cloudCancel.close"),disabled:m,onClick:y,className:"rounded-lg p-1.5 text-ink-secondary hover:bg-raised",children:e.jsx(Me,{size:18})})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 pb-5 pt-1",children:[p.step==="ask"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:rp(s)}),e.jsxs("fieldset",{className:"mt-4",disabled:m,children:[e.jsx("legend",{className:"text-[14px] font-medium text-ink",children:t("cloudCancel.question")}),e.jsx("div",{className:"mt-2.5 flex flex-wrap gap-2",children:sp.map(k=>e.jsx("button",{type:"button","aria-pressed":i===k,onClick:()=>r(S=>S===k?null:k),className:D("ui-button ui-button-pill",i===k&&"border-accent bg-accent/10 font-medium"),children:t(np[k])},k))})]}),e.jsxs("label",{className:"mt-4 block text-[13px] text-ink",children:[t("cloudCancel.expected")," ",e.jsx("span",{className:"text-ink-secondary",children:t("cloudCancel.optional")}),e.jsx("textarea",{rows:2,maxLength:xa,value:c,disabled:m,onChange:k=>l(k.target.value),className:I})]}),e.jsxs("label",{className:"mt-3 block text-[13px] text-ink",children:[t("cloudCancel.improve")," ",e.jsx("span",{className:"text-ink-secondary",children:t("cloudCancel.optional")}),e.jsx("textarea",{rows:2,maxLength:xa,value:d,disabled:m,onChange:k=>u(k.target.value),className:I})]}),e.jsxs("p",{className:"mt-3 text-[12px] text-ink-secondary",children:[t("cloudCancel.talk")," ",e.jsx("a",{href:tp,target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-ink",children:t("cloudCancel.book")})]}),F,e.jsxs("div",{className:"mt-5 flex flex-wrap justify-end gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:m,onClick:y,children:t("cloudCancel.keep")}),e.jsx("button",{type:"button","data-cloud-cancel-confirm":!0,className:"ui-button border-transparent bg-danger text-white hover:brightness-110",disabled:m,onClick:w,children:t(m?"cloudCancel.cancelling":s.trial?"cloudCancel.confirmTrial":"cloudCancel.confirmPlan")})]})]}),p.step==="done"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status",className:"text-[14px] font-medium text-ink",children:cn(p.renewal)}),e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink-secondary",children:ip(p.renewal)}),p.surveyed&&e.jsx("p",{className:"mt-2 text-[13px] leading-relaxed text-ink-secondary",children:t("cloudCancel.thanks")}),F,e.jsxs("div",{className:"mt-5 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-[13px] text-ink-secondary",children:t("cloudCancel.changedMind")}),e.jsx("button",{type:"button",className:"ui-button",disabled:m,onClick:N,children:t(m?"cloudCancel.keeping":"cloudCancel.keep")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary ms-auto",disabled:m,onClick:y,children:t("cloudCancel.done")})]})]}),p.step==="browser"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status",className:"text-[13px] leading-relaxed text-ink",children:t("cloudCancel.browser")}),e.jsx("div",{className:"mt-5 flex justify-end",children:e.jsx("button",{type:"button",className:"ui-button ui-button-primary",onClick:y,children:t("cloudCancel.done")})})]})]})]})}),document.body)}const yr=s=>new Intl.DateTimeFormat(Ee(),{month:"short",day:"numeric"}).format(new Date(s));function jr(s,n,a=!1){const i=a?t("settings.plan.trialName",{plan:s}):s,r=n?.cancelled?n.endsAt??n.renewsAt:null;return r?t("settings.plan.ends",{plan:i,date:yr(r)}):i}function op({usage:s,upgrade:n}){return e.jsx(J,{label:t("settings.plan.thisWeek"),block:"this-week",footnote:jo(s),actions:n?e.jsx(yo,{usage:s,upgrade:n,secondary:!0}):void 0,children:e.jsx(V,{children:s.meters.map(a=>e.jsxs("div",{"data-plan-meter":a.kind,className:"flex flex-col gap-2 px-4 py-3",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-6",children:[e.jsx("span",{className:"text-[14px] leading-5 text-ink",children:Un(a.kind)}),e.jsxs("span",{className:"shrink-0 text-[13px] leading-5 tabular-nums text-ink-secondary",children:[fo(a)," · ",bo(a),"%"]})]}),e.jsx(vo,{meter:a,label:Un(a.kind),compact:!0})]},a.kind))})})}function kr({renewal:s,actions:n,onChanged:a}){const[i,r]=o.useState(!1);return s.cancelled?null:e.jsxs(e.Fragment,{children:[e.jsx("div",{"data-settings-block":"cancel",className:"contents",children:e.jsx(L,{title:t(s.trial?"cloudCancel.cancelTrial":"cloudCancel.cancelPlan"),children:e.jsx("button",{type:"button","data-cloud-cancel":"renewing","data-danger":"",className:"settings-quiet cursor-pointer",onClick:()=>r(!0),"aria-label":t(s.trial?"cloudCancel.cancelTrial":"cloudCancel.cancelPlan"),children:t("settings.plan.cancelAction")})})}),i&&e.jsx(lp,{renewal:s,actions:n,onClose:c=>{r(!1),c&&a?.()}})]})}function wr(s){if(!(!s||s.cancelled||!s.renewsAt))return t(s.trial?"settings.plan.trialEnds":"settings.plan.renews",{date:yr(s.renewsAt)})}function Nr({actions:s,onChanged:n}){const[a,i]=o.useState(!1),[r,c]=o.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"ui-button ui-button-primary","data-cloud-cancel":"cancelled",disabled:a,onClick:()=>{i(!0),c(null),s.keep().then(l=>{l.outcome==="kept"?n?.():c(t(l.outcome==="browser"?"cloudCancel.browser":"cloudCancel.failed"))},()=>c(t("cloudCancel.failed"))).finally(()=>i(!1))},children:t(a?"cloudCancel.keeping":"cloudCancel.keep")}),r&&e.jsx("span",{className:"sr-only",role:"status",children:r})]})}function Sr({title:s,subtitle:n,message:a,primary:i,usage:r,upgrade:c,links:l,extra:d,cancel:u,footnote:p}){return e.jsxs(e.Fragment,{children:[e.jsx(J,{label:t("settings.simple.billing.plan"),block:"plan",footnote:p,children:e.jsxs(V,{children:[e.jsx(L,{title:s,subtitle:n,message:a||void 0,children:i??null}),e.jsx(xu,{}),l,d,u]})}),r&&r.meters.length>0&&e.jsx(op,{usage:r,upgrade:c})]})}function cp({place:s}){const[n,a]=o.useState(void 0);return o.useEffect(()=>{let i=!0;return Is(Mi("week")).then(r=>{i&&a(r.totals.costUsd)}).catch(()=>{i&&a(void 0)}),()=>{i=!1}},[]),e.jsx("div",{"data-plan-spent":"",className:"contents",children:e.jsx(L,{title:t("settings.plan.spent",{place:s}),children:n===void 0?null:e.jsx("span",{className:"text-[13px] leading-5 text-ink-secondary",children:dp(n)})})})}function dp(s){return s==null||!Number.isFinite(s)||s<=0?t("settings.plan.spentNothing"):t("settings.plan.spentWeek",{cost:Ve(s)})}function ga({label:s,suggest:n,className:a="ui-button"}){const{dispatch:i}=_();return e.jsx("button",{type:"button",className:a,onClick:()=>i({type:"showFiles",...n?{suggest:n}:{}}),children:s})}const up={provisioning:"cloudHome.provisioning",ready:"cloudHome.ready",stopped:"cloudHome.stopped","payment-problem":"cloudHome.paymentProblem",failed:"cloudHome.failed"},Cr=s=>new Intl.DateTimeFormat(Ee(),{timeStyle:"short"}).format(new Date(s)),pp=s=>new Intl.DateTimeFormat(Ee(),{dateStyle:"medium"}).format(new Date(s));function Wt(s,n){if(!s&&!n)return null;const a=s?Ws(s):null;return e.jsxs("div",{"data-cloud-trial":s?.state??"none",className:"flex flex-col gap-1",children:[a&&e.jsx("p",{className:"text-[13px] font-medium text-ink",children:a.title}),a&&e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:a.body}),n&&e.jsx("p",{"data-cloud-credit":n.state,className:"text-[13px] leading-relaxed text-ink-secondary",children:jl(n)})]})}function ha({machine:s,busy:n,failed:a,onConnect:i,trial:r=!1,waking:c=!1,moving:l=null,team:d=null}){const u=s.status==="ready"?s.unreachable:void 0,p=s.status==="ready"&&!u,x=u?t(u.cause==="host"?"cloudHome.unreachableHost":"cloudHome.unreachable"):l??(c&&p?t("cloudHome.waking"):d?.name&&s.status==="ready"?t("cloudHome.team.ready",{name:d.name}):s.status==="ready"&&s.power?.sleeps?t("cloudHome.readySleeps"):r&&(s.status==="stopped"||s.status==="payment-problem")?t("cloudHome.stoppedTrial"):s.status==="failed"&&s.retryAt?t("cloudHome.failedRetry",{time:Cr(s.retryAt)}):s.status==="provisioning"&&s.setup?.slow?t("cloudHome.slow"):d&&s.status==="provisioning"?t("cloudHome.team.provisioning"):t(up[s.status])),m=d?.name?t("cloudBuy.setup.open",{name:d.name}):t("settings.plan.openCloud",{place:t("cloudSetup.myCloud")});return p&&!l?e.jsxs("div",{"data-cloud-home":s.status,"data-cloud-team":d?!0:void 0,"data-cloud-waking":c?!0:void 0,className:"contents",children:[e.jsx(ye,{title:m,subtitle:d?.name?t("cloudHome.team.ready",{name:d.name}):t("settings.plan.cloudReadyLine"),value:t(c?"settings.plan.cloudWaking":"settings.plan.cloudReady"),external:!0,onClick:()=>{n||i()},data:{"data-plan-open-cloud":""}}),!d&&Mn()&&e.jsx("p",{className:"px-4 pb-3",children:e.jsx(ga,{label:t("cloudHome.filesLink"),className:"text-[12px] leading-4 text-accent-text hover:underline"})}),a&&e.jsx("p",{role:"alert",className:"px-4 pb-3 text-[12px] leading-4 text-danger",children:t("cloudHome.connectFailed")})]}):e.jsx("div",{"data-cloud-home":s.status,"data-cloud-team":d?!0:void 0,"data-cloud-unreachable":u?.cause,"data-cloud-waking":c&&p?!0:void 0,"data-cloud-moving":l&&!u?!0:void 0,children:e.jsx(L,{title:d?d.name??t("cloudHome.team.title"):t("cloudSetup.myCloud"),subtitle:e.jsx("p",{role:"status",children:x}),message:e.jsxs(e.Fragment,{children:[s.status==="provisioning"&&s.setup&&e.jsx(au,{step:s.setup.step}),p&&!d&&Mn()&&e.jsx(ga,{label:t("cloudHome.filesLink"),className:"text-[12px] leading-4 text-accent-text hover:underline"}),a&&!u&&e.jsx("p",{role:"alert",className:"text-danger",children:t("cloudHome.connectFailed")})]}),children:null})})}function mp(s,n){return n.arrived&&s.status==="signed-out"&&s.message!=="restoring"?"sign-in":!n.connected&&s.status==="connected"&&s.machine?.status==="ready"&&!s.machine.unreachable?"connect":null}const xp={darwin:"cloudAccount.restoreRetryKeychain",linux:"cloudAccount.restoreRetryKeyring"};function gp(s,n,a){return s?s.message==="signout-local-only"?t("cloudAccount.signoutLocalOnly"):s.message==="signout-storage-failed"?t("cloudAccount.storageFailed"):s.message==="restore-failed"?t(xp[a]??"cloudAccount.restoreRetry"):n.kind==="reauth"?t(n.reason==="expired"?"cloudAccount.reauthExpired":"cloudAccount.reauthEnded"):n.kind==="unverified"?t("cloudAccount.unavailable"):n.kind==="purchase"?n.paidAt?t("cloudAccount.purchaseNote",{date:pp(n.paidAt)}):t("cloudAccount.purchaseNoteNoDate"):n.kind==="attention"&&!s.machine&&!s.trial?t("cloudAccount.attention"):s.status==="signed-out"&&s.message==="enrollment-expired"?t("cloudAccount.codeExpired"):s.status==="signed-out"&&s.message==="restore-removed"?t("cloudAccount.restoreRemoved"):s.status==="signed-out"&&s.message&&s.message!=="restoring"?t("cloudAccount.signinFailed"):null:null}function hp(s,n){const a=s.trial&&!s.renewal?.cancelled?Ws(s.trial).action:null;return a?a.label:n.kind==="paid"||n.kind==="unverified"&&n.label?t("cloudAccount.manage"):s.machine?.status==="payment-problem"?t("cloudAccount.updatePayment"):t("cloudAccount.dashboard")}function fp({bridge:s,usage:n=null,upgrade:a,extra:i}){const[r,c]=o.useState(null),[l,d]=o.useState(!1),[u,p]=o.useState(!1),[x,m]=o.useState(0);o.useEffect(()=>{let v=!0;return s.state().then(w=>{v&&c(w)}).catch(()=>{v&&p(!0)}),()=>{v=!1}},[s,x]);const g=s.cancel&&s.keep?{cancel:v=>s.cancel(v),keep:()=>s.keep()}:null;if(u)return e.jsx(J,{label:t("settings.simple.billing.plan"),block:"plan",children:e.jsx(V,{children:e.jsx("div",{"data-cloud-plan":"elsewhere",className:"contents",children:e.jsx(L,{title:t("cloudAccount.onCloudNone"),children:null})})})});const f=yl(r?.tier),h=r?.renewal?.cancelled===!0,j=r?.status==="paid"?jr(f,r.renewal,Ni(r.trial)):r?.status==="attention"?t("cloudAccount.inactive",{plan:r.tier?f:t("settings.simple.billing.plan")}):r?.status==="checking"?t("cloudAccount.lastPlan",{plan:f}):r?.status==="signin"&&r.tier?t("cloudAccount.planName",{plan:f}):r?t(r.home===!0?"cloudAccount.onCloudNoneHome":"cloudAccount.onCloudNone"):t("cloudAccount.loading"),b=v=>{d(!1),v().catch(()=>d(!0))},y=r?.status==="signin"&&s.signIn?e.jsx("button",{type:"button",className:"ui-button ui-button-primary",onClick:()=>b(()=>s.signIn()),children:t("cloudAccount.signInAgain")}):h&&g?e.jsx(Nr,{actions:g,onChanged:()=>m(v=>v+1)}):r?e.jsx("button",{type:"button",className:"ui-button ui-button-primary","data-plan-manage":"",onClick:()=>b(()=>s.manage()),children:r.trial&&!r.renewal?.cancelled&&Ws(r.trial).action?.label||t("settings.plan.manage")}):null;return e.jsx("div",{"data-cloud-plan":r?.status??"loading",className:"contents",children:Sr({title:j,primary:y,usage:n,upgrade:a,extra:i,subtitle:r?.status==="signin"?t("cloudAccount.onCloudSignIn"):h&&r?.renewal?cn(r.renewal):wr(r?.renewal),message:Wt(r?.trial,r?.credit)||l?e.jsxs(e.Fragment,{children:[Wt(r?.trial,r?.credit),l&&e.jsx("p",{role:"alert",className:"text-danger",children:t("cloudAccount.actionFailed")})]}):void 0,cancel:r?.renewal&&g?e.jsx(kr,{renewal:r.renewal,actions:g,onChanged:()=>m(v=>v+1)}):void 0})})}function bp({team:s,admin:n,owner:a=!1}){const i=n||a?En(s,"invite"):null,r=a?En(s,"seats"):null,c=a?"cloudAccount.teamPeopleOwner":n?"cloudAccount.teamPeopleAdmin":"cloudAccount.teamPeopleAsk";return e.jsx(pe,{title:t("cloudAccount.teamPeopleTitle"),children:e.jsxs("div",{"data-cloud-plan":"team",className:"flex flex-col items-start gap-3",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(c,{team:s.name})}),i&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("a",{className:"ui-button",href:i,target:"_blank",rel:"noreferrer","data-team-invite":"",children:t("cloudAccount.teamPeopleInvite")}),r&&e.jsx("a",{className:"ui-button",href:r,target:"_blank",rel:"noreferrer","data-team-seats":"",children:t("cloudAccount.teamPeopleSeats")})]})]})})}function Er({linkRequest:s=0,cloudHome:n=!1,teamHome:a,onAddCloud:i,onSignIn:r,part:c="plan",advanced:l=!0,usage:d=null,upgrade:u,extra:p,avatar:x}={}){const m=window.ogb?.remoteClient?.active?void 0:window.ogb?.cloudAccount,{platform:g}=Li().capabilities.host,[f,h]=o.useState(null),[j,b]=o.useState(!1),[y,v]=o.useState(!1),[w,N]=o.useState(!1),[C,I]=o.useState(!1),[F,k]=o.useState(!1),[S]=o.useState(!1),P=o.useRef(0),E=o.useRef(0),A=o.useRef(!1),q=o.useRef({request:0,arrived:!1,connected:!1});o.useEffect(()=>{const ue=++P.current,Pe=E.current,Te=Ie=>{P.current===ue&&(E.current++,h(Ie),v(!1),Ie.status==="signed-out"&&N(!1))},Be=m?.onState(Te);return m?.state().then(Ie=>{E.current===Pe&&Te(Ie)}).catch(()=>{P.current===ue&&E.current===Pe&&v(!0)}),()=>{P.current++,Be?.()}},[m]);const R=async ue=>{if(!m||A.current)return;A.current=!0,b(!0),v(!1);const Pe=P.current,Te=E.current;try{const Be=await ue();P.current===Pe&&E.current===Te&&h(Be)}catch{P.current===Pe&&E.current===Te&&v(!0)}finally{A.current=!1,P.current===Pe&&b(!1)}},K=()=>{m&&(k(!1),R(async()=>{try{return await m.connectHome()}catch{return k(!0),m.state()}}))},Z=ue=>{m?.openTeam&&(k(!1),R(async()=>{try{await m.openTeam(ue)}catch{k(!0)}return m.state()}))};o.useEffect(()=>{if(s||(q.current.request=0),!m||!s||!f||A.current||(q.current.request!==s&&(q.current={request:s,arrived:!0,connected:!1}),f.status==="signed-out"&&f.message==="restoring"))return;const ue=mp(f,q.current);q.current.arrived=!1,ue==="sign-in"&&R(()=>m.begin()),ue==="connect"&&(q.current.connected=!0,K())},[m,s,f,j]);const[oe]=ko(m?window.ogb?.cloudSendPage:void 0),se=oe?.move?ml(oe.move,"local"):null,Y=se&&se.kind!=="done"?se.text:null,B=Cu(!!f&&ms(Cn(f)),f?.offer),W=m?.cancelPlan&&m.keepPlan?{cancel:ue=>m.cancelPlan(ue),keep:()=>m.keepPlan()}:null;if(!m){const ue=window.ogb?.remoteClient?.active||!n?void 0:window.ogb?.cloudPlan;return c!=="plan"||n&&a?null:ue?e.jsx(fp,{bridge:ue,usage:d,upgrade:u,extra:p}):e.jsx("p",{className:"px-4 text-[13px] text-ink-secondary",children:t("cloudAccount.desktopOnly")})}const G=Cn(f),le=f&&["connected","unavailable","reauth-required"].includes(f.status),U=gp(f,G,g),H=xl(G),Q=gl(f),te=hl(f),ie=G.kind==="paid"?{status:"provisioning"}:void 0,Se=Q?te?.machine??ie:f?.status==="connected"?f.machine??ie:void 0,de=f?.status==="connecting"?f.enrollment:void 0,be=fl(B),$=G.kind==="signed-out"||G.kind==="removed",me=t(bl(B)!==null?"cloudIntro.start":"cloudAccount.upgrade"),he=y&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] leading-4 text-danger",children:t("cloudAccount.actionFailed")});if(c==="account"){const ue=e.jsx("span",{"aria-hidden":"true"});return e.jsxs(e.Fragment,{children:[e.jsxs(J,{label:t("settings.account.mausbot",{app:je()}),block:"mausbot-account",children:[e.jsxs(V,{icons:!0,children:[(!f||G.kind==="unknown")&&e.jsx(L,{title:t("cloudAccount.loading"),leading:x??ue,children:!f&&e.jsx("button",{type:"button",disabled:j,className:"ui-button",onClick:()=>{R(()=>m.state())},children:t("organization.refresh")})}),$&&e.jsx(L,{title:t("settings.account.signInTitle",{app:je()}),subtitle:t("settings.account.signInBody"),message:U&&e.jsx("p",{role:"status",children:U}),leading:x??ue,children:e.jsx("button",{type:"button",disabled:j,className:"ui-button ui-button-primary","data-account-sign-in":"",onClick:()=>r?r():void R(()=>m.begin()),children:t("settings.account.signIn")})}),f?.status==="connecting"&&e.jsxs(L,{title:t("cloudAccount.browser"),leading:x??ue,subtitle:de?`${t("cloudAccount.codeCheck")} ${t("cloudAccount.codeUntil",{time:Cr(de.expiresAt)})}`:void 0,message:de&&e.jsx("code",{"data-cloud-code":!0,dir:"ltr",className:"select-all text-[20px] font-medium leading-7 tracking-[0.08em] text-ink",children:de.userCode}),children:[e.jsx("button",{type:"button",disabled:j,className:"ui-button",onClick:()=>{R(()=>m.reopen())},children:t("organization.reopen")}),e.jsx("button",{type:"button",disabled:j,className:"settings-quiet cursor-pointer",onClick:()=>{R(()=>m.cancel())},children:t("organization.cancel")})]}),le&&e.jsx(L,{title:f.account?.email??t("settings.account.signedIn"),leading:x??ue,subtitle:U?e.jsx("p",{role:"status",children:U}):t("settings.account.signedIn"),children:G.kind==="reauth"?e.jsx("button",{type:"button",disabled:j,className:"ui-button",onClick:()=>{R(()=>m.signInAgain())},children:t("cloudAccount.signInAgain")}):l&&e.jsx("button",{type:"button",disabled:j,className:"settings-quiet cursor-pointer",onClick:()=>{R(()=>m.refresh())},children:t("organization.refresh")})}),le&&e.jsx("div",{"data-settings-block":"sign-out",className:"contents",children:e.jsx(L,{title:t("settings.account.signOut",{app:je()}),leading:ue,children:e.jsx("button",{type:"button",disabled:j,"data-danger":"",className:"settings-quiet cursor-pointer",onClick:()=>N("sign-out"),children:t("settings.account.signOutShort")})})})]}),le&&G.kind==="free"&&!w&&e.jsxs("p",{className:"px-4 text-[12px] leading-4 text-ink-secondary",children:[t(window.ogb?.accounts?"cloudAccount.otherEmailOrTeam":"cloudAccount.otherEmail")," ",e.jsx("button",{type:"button","data-cloud-other-email":!0,disabled:j,className:"cursor-pointer text-accent-text hover:underline",onClick:()=>window.ogb?.accounts?I(!0):N("other-email"),children:t(window.ogb?.accounts?"cloudAccount.addOtherEmail":"cloudAccount.useOtherEmail")})]}),he]}),C&&e.jsx(eo,{adding:"",onClose:()=>I(!1)}),w&&e.jsx(Di,{here:t("rail.thisComputer"),cloud:w==="sign-out"&&G.kind==="paid"?t("cloudSetup.myCloud"):null,onConfirm:()=>R(()=>m.signOut()),onClose:()=>N(!1)})]})}if(c==="sign-out")return null;const ke=f?.status==="connected"&&f.renewal?.cancelled===!0,Re=$||G.kind==="free"&&ms(G)?i&&ms(G)&&e.jsx("button",{type:"button",disabled:j,className:"ui-button ui-button-primary","data-plan-add":"",onClick:i,children:me}):G.kind==="reauth"?e.jsx("button",{type:"button",disabled:j,className:"ui-button ui-button-primary",onClick:()=>{R(()=>m.signInAgain())},children:t("cloudAccount.signInAgain")}):ke&&W?e.jsx(Nr,{actions:W,onChanged:()=>{R(()=>m.state())}}):le&&e.jsx("button",{type:"button",disabled:j,className:"ui-button ui-button-primary","data-plan-manage":"",onClick:()=>{R(()=>m.openDashboard())},children:G.kind==="free"?t("cloudAccount.dashboard"):hp(f,G)}),Ye=!f||G.kind==="unknown"?t("cloudAccount.loading"):G.kind==="signed-out"?t("cloudAccount.free"):G.kind==="paid"&&f.status==="connected"?jr(G.label,f.renewal,Ni(f.trial)):H??t("settings.simple.billing.plan");return e.jsxs(e.Fragment,{children:[Sr({title:Ye,primary:Re||void 0,usage:d,upgrade:u,extra:p,footnote:be,subtitle:G.kind==="signed-out"?wo()?t("settings.plan.offer"):void 0:ke&&f?.status==="connected"&&f.renewal?cn(f.renewal):G.kind==="paid"&&G.checking?t("cloudAccount.checking"):U??(f?.status==="connected"?wr(f.renewal):void 0),message:le&&(f.staging||f.status==="connected"&&Wt(f.trial,f.credit))?e.jsxs(e.Fragment,{children:[f.staging&&e.jsx(vl,{className:"mb-1"}),f.status==="connected"?Wt(f.trial,f.credit):null]}):void 0,links:e.jsxs(e.Fragment,{children:[$&&e.jsx(ye,{title:t("settings.plan.haveOne"),onClick:()=>r?r():void R(()=>m.begin())}),Se&&ha(Q?{machine:Se,busy:j,failed:F,onConnect:()=>{te&&Z(te.id)},team:{name:te?.name??null}}:{machine:Se,busy:j,failed:F,onConnect:K,trial:!!f?.trial,waking:f?.waking===!0,moving:Y})]}),cancel:le&&f.status==="connected"&&f.renewal&&W?e.jsx(kr,{renewal:f.renewal,actions:W,onChanged:()=>{R(()=>m.state())}}):void 0}),he,S&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] text-danger",children:t("cloudPhone.failed")})]})}function Ar(s){return s.readOnly===!0&&s.managed!==void 0&&s.instanceId.startsWith("company.")}function vp(s,n){return s.find(a=>Ar(a)&&a.instanceId.endsWith(`.${n}`))}function dn(s){return!!(s&&!s.policy&&s.snapshot.state==="available"&&(s.access==="custom"||s.snapshot.authenticated!==!1))}function fa(s,n){const a=n.find(i=>i.instanceId===s.instanceId);return dn(a)?!0:!!(a&&!a.policy&&a.snapshot.state==="available"&&a.models.options.some(i=>i.id===s.model&&i.custom))}function yp(s,n){const a=n.filter(l=>Ar(l)&&dn(l)),i=a.find(l=>l.driverKind==="claudeAgent")??a[0];if(!i)return{bots:[],needsAsk:[]};const r={target:i,bots:[],needsAsk:[]},c=l=>n.find(d=>d.instanceId===l)?.driverKind;for(const l of s){if(l.hidden)continue;const d=No(l);if(fa(l.modelSelection,n)||fa(d.modelSelection,n))continue;([l,d].some(p=>So(Co(p),c(p.modelSelection.instanceId),i.driverKind))?r.needsAsk:r.bots).push(l)}return r}const jp={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter"};function kp({providers:s}){const{state:n,dispatch:a,flushBotPatches:i}=_(),[r,c]=o.useState(!1),[l,d]=o.useState(null),u=yp(n.bots,n.instances),p=u.target,x=g=>g.map(f=>f.name).join(", "),m=async()=>{if(!p||!u.bots.length||r)return;const g=u.bots,f={instanceId:p.instanceId,model:p.models.default};c(!0),d(null);for(const h of g)a({type:"setModel",botId:h.id,selection:f});try{const h=await Promise.all(g.map(b=>i(b.id).catch(()=>null))),j=g.filter((b,y)=>h[y]?.modelSelection.instanceId===f.instanceId);j.length&&d({name:p.displayName,bots:j.map(b=>b.name)})}finally{c(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"divide-y divide-hairline/40",children:s.map(g=>e.jsxs("li",{className:"py-2 text-[13px]",children:[e.jsxs("div",{className:"flex flex-wrap justify-between gap-2",children:[e.jsx("span",{className:"text-ink",children:jp[g.id]??g.id}),e.jsx("span",{className:"text-ink-secondary",children:g.configured?t("organization.modelCount",{count:g.models.length}):t("organization.notConfigured")})]}),g.configured&&g.models.length>0&&e.jsx(wp,{instance:vp(n.instances,g.id),instances:n.instances})]},g.id))}),l&&e.jsx("p",{role:"status",className:"break-words text-[12px] text-ink-secondary",children:t("organization.useCompanyDone",{name:l.name,names:l.bots.join(", ")})}),p&&u.bots.length>0&&e.jsxs("div",{"data-company-switch":!0,className:"flex flex-col items-start gap-2 rounded-lg border border-hairline/40 p-3",children:[e.jsx("p",{className:"break-words text-[13px] text-ink",children:t("organization.useCompanyBots",{names:x(u.bots)})}),e.jsx("button",{type:"button",className:"ui-button",disabled:r,onClick:()=>{m()},children:u.bots.length===1?t("organization.useCompanyOne",{name:p.displayName}):t("organization.useCompanyMany",{name:p.displayName,count:u.bots.length})}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("organization.useCompanyNote")})]}),p&&u.needsAsk.length>0&&e.jsx("p",{className:"break-words text-[12px] text-ink-secondary",children:t("organization.useCompanyElevated",{names:x(u.needsAsk)})})]})}function wp({instance:s,instances:n}){if(!s)return null;if(s.policy)return e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:s.policy.reason});if(dn(s))return e.jsxs("p",{className:"mt-1 flex items-center gap-1 text-[12px] text-ink-secondary",children:[e.jsx(_e,{size:12,className:"text-success","aria-hidden":"true"}),t("organization.engineReady")]});const a=s.driverKind==="claudeAgent"||s.driverKind==="codex"?n.find(i=>i.driverKind===s.driverKind&&!i.readOnly&&i.install):void 0;return a&&Eo(a)?e.jsx(Ao,{instance:a,intent:"inject",className:"mt-2",description:t("organization.engineInstallHelp",{engine:a.displayName})}):e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:s.snapshot.reason??t("organization.engineUnavailable")})}const Np={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter"},ba="https://admin.openmausbot.com",va={clearFailed:"organization.status.clearFailed",disconnected:"organization.status.disconnected",runtimeRunning:"organization.status.runtimeRunning",portalUnreachable:"organization.status.portalUnreachable",confirmStopped:"organization.status.confirmStopped",expired:"organization.status.expired",accessEnded:"organization.status.accessEnded",retrying:"organization.status.retrying",codeExpired:"organization.status.codeExpired",denied:"organization.status.denied",completeFailed:"organization.status.completeFailed",removed:"organization.status.removed",restoreFailed:"organization.status.restoreFailed",startFailed:"organization.status.startFailed"};function ya(s){const n=s.messageCodes;return!n?.length||!n.every(a=>Object.hasOwn(va,a))?s.message:n.map(a=>t(va[a])).join(" ")}function Sp({simple:s=!1}={}){const n=window.ogb?.remoteClient?.active?void 0:window.ogb?.organization,[a,i]=o.useState(null),[r,c]=o.useState(""),[l,d]=o.useState(!1),[u,p]=o.useState(""),[x,m]=o.useState(!1),[g,f]=o.useState(!1),[h,j]=o.useState(!1),b=o.useRef(!1),y=o.useRef(0),v=o.useRef(0),w=o.useRef(void 0),N=E=>{const A=w.current!==E.status;w.current=E.status,i(E),A&&p(""),E.status!=="connected"&&E.status!=="reauth-required"&&m(!1)};o.useEffect(()=>{n?.settingsOpened?.().catch(()=>{});const E=++y.current,A=v.current,q=K=>{y.current===E&&(v.current++,N(K))},R=n?.onState(q);return n?.state().then(K=>{v.current===A&&q(K)}).catch(()=>{y.current===E&&v.current===A&&p(t("organization.loadFailed"))}),()=>{y.current++,R?.()}},[n]);const C=async E=>{if(!n||b.current)return;b.current=!0,d(!0),p("");const A=y.current,q=v.current;try{const R=await E();y.current===A&&v.current===q&&N(R)}catch{y.current===A&&v.current===q&&p(t("organization.actionFailed"))}finally{b.current=!1,y.current===A&&d(!1)}};if(!n)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.desktopOnly")});const I=a?.status==="connected"||a?.status==="reauth-required"||a?.status==="unavailable"||a?.status==="license-expired",F=a?.status==="license-expired"||a?.notice==="license-expired",k=a?.enrollment?.expiresAt??a?.expiresAt,S=typeof k=="number"&&Number.isFinite(k)?new Date(k):null,P=S&&Number.isFinite(S.getTime())?new Intl.DateTimeFormat(Ee(),{dateStyle:"medium",timeStyle:"short"}).format(S):null;return a?.status==="signed-out"&&s?e.jsx("div",{"data-settings-rows":"",hidden:!0}):a?.status==="signed-out"?e.jsxs(V,{children:[e.jsx(L,{title:t("organization.signIn"),subtitle:e.jsxs(e.Fragment,{children:[t("organization.signInShort")," ",e.jsx(Ke,{onClick:()=>f(E=>!E)})]}),message:e.jsxs(e.Fragment,{children:[g&&e.jsxs("span",{"data-organization-more":"",className:"block",children:[t("organization.additive")," ",t("organization.privacy")," ",t("cloudAccount.separate")]}),a.message&&e.jsx("span",{role:"status",className:"block",children:ya(a)}),F&&e.jsx("span",{role:"alert",className:"block text-ink",children:t("organization.licenseExpired")}),u&&e.jsx("span",{role:"alert",className:"block text-danger",children:u})]}),children:e.jsx("button",{type:"button",disabled:l,className:"ui-button","data-organization-sign-in":"",onClick:()=>{C(()=>n.begin({portalOrigin:ba}))},children:l?t("organization.working"):t("organization.useWorkSignIn")})}),e.jsx(Qt,{id:"organization-address",title:t("organization.customTitle"),open:h,onToggle:()=>j(E=>!E),children:e.jsxs("form",{className:"flex flex-col gap-2 px-4 py-3",onSubmit:E=>{E.preventDefault(),r.trim()&&C(()=>n.begin({portalOrigin:r.trim()}))},children:[e.jsx(ge,{label:t("organization.address"),hint:t("organization.advancedHelp"),children:e.jsx("input",{type:"url",required:!0,value:r,disabled:l,onChange:E=>c(E.target.value),placeholder:ba,autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,maxLength:2048,className:xe})}),e.jsx("button",{type:"submit",disabled:l||!r.trim(),className:"ui-button self-end",children:t("organization.customSignIn")})]})})]}):e.jsx(e.Fragment,{children:e.jsxs(pe,{children:[!a&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:u||t("organization.loading")}),a?.message&&e.jsx("p",{role:"status",className:"mb-3 text-[13px] text-ink-secondary",children:ya(a)}),F&&e.jsx("p",{role:"alert",className:"mb-3 text-[13px] text-ink",children:t("organization.licenseExpired")}),a?.status==="connecting"&&e.jsxs("div",{className:"flex flex-col items-start gap-3",children:[e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("organization.browserConsent")}),a.enrollment&&e.jsxs("details",{className:"w-full text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"w-fit cursor-pointer hover:text-ink",children:t("organization.securityDetails")}),e.jsx("p",{className:"mt-2",children:t("organization.securityDetailsHelp")}),e.jsx("div",{className:"mt-3",children:t("organization.code")}),e.jsx("code",{dir:"ltr",className:"mt-1 block w-fit select-all rounded-lg bg-inset px-3 py-2 text-base tracking-widest text-ink",children:a.enrollment.userCode})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.enrollment&&n.reopen&&e.jsx("button",{type:"button",disabled:l,className:"ui-button",onClick:()=>{C(()=>n.reopen())},children:t("organization.reopen")}),e.jsx("button",{type:"button",disabled:l,className:"ui-button",onClick:()=>{C(()=>n.cancelEnrollment())},children:t("organization.cancel")})]})]}),I&&e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{children:[a.branding?.logo&&e.jsx("img",{src:a.branding.logo,alt:t("organization.logo"),className:"mb-2 size-12 rounded-lg object-contain"}),e.jsx("div",{className:"break-words text-[15px] font-medium text-ink",children:a.organization?.name}),e.jsx("div",{className:"break-all text-[13px] text-ink-secondary",children:a.email})]}),a.status==="reauth-required"?e.jsx("p",{role:"alert",className:"text-[13px] text-ink-secondary",children:t("organization.reauth")}):a.status==="license-expired"?e.jsx(e.Fragment,{children:a.providers?.some(E=>E.configured&&E.models.length>0)&&e.jsx("ul",{className:"divide-y divide-hairline/40",children:a.providers.filter(E=>E.configured&&E.models.length>0).map(E=>e.jsxs("li",{className:"flex flex-wrap justify-between gap-2 py-2 text-[13px]",children:[e.jsx("span",{className:"text-ink",children:Np[E.id]??E.id}),e.jsx("span",{className:"text-ink-secondary",children:t("organization.companyModelsUnavailable")})]},E.id))})}):a.status==="connected"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.modelHelp")}),a.providers?.some(E=>E.configured&&E.models.length>0)?e.jsx(kp,{providers:a.providers}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("organization.noModels")})]}):null,x?e.jsxs("div",{role:"group","aria-label":t("organization.disconnectTitle"),className:"rounded-lg border border-hairline/40 p-3",children:[e.jsx("p",{className:"text-[13px] text-ink",children:t("organization.disconnectWarning")}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",autoFocus:!0,disabled:l,className:"ui-button",onClick:()=>m(!1),children:t("organization.keepConnection")}),e.jsx("button",{type:"button",disabled:l,className:"ui-button text-danger",onClick:()=>{C(()=>n.disconnect())},children:t("organization.disconnectConfirm")})]})]}):e.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.status!=="reauth-required"&&e.jsx("button",{type:"button",disabled:l,className:"ui-button",onClick:()=>{C(()=>n.refresh())},children:t("organization.refresh")}),e.jsx("button",{type:"button",disabled:l,className:"ui-button",onClick:()=>m(!0),children:t("organization.disconnect")})]})]}),a?.status==="unavailable"&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("organization.unavailable")}),P&&e.jsx("p",{className:"mt-3 text-[12px] text-ink-secondary",children:t("organization.expires",{date:P})}),u&&a&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:u}),!a&&e.jsx("button",{type:"button",disabled:l,className:"ui-button mt-3",onClick:()=>{C(()=>n.refresh())},children:t("organization.refresh")})]})})}function Cp(){const s=Po(),[n,a]=o.useState(!1),[i,r]=o.useState(!1);if(!s?.available||!s.on&&s.here!=="computer")return null;const c=()=>{a(!0),r(!1),To(!s.on).catch(()=>r(!0)).finally(()=>a(!1))};return e.jsx(J,{block:"together",children:e.jsx(V,{children:e.jsx("div",{"data-places-together":s.on?"on":"off",className:"contents",children:e.jsx(L,{title:t("together.switch.title"),tag:t("settings.early.tag"),subtitle:t("together.switch.line"),message:i?e.jsx("span",{role:"alert",className:"block text-danger",children:t("together.switch.failed")}):void 0,children:e.jsx(ne,{checked:s.on,disabled:n,"aria-label":t("together.switch.title"),onClick:c})})})})})}function Ep(){const{ctx:s,place:n,go:a}=we(),{state:i,dispatch:r}=_(),{profile:c,session:l}=Ys(),d=Js(),u=Et(),[p,x]=o.useState(!1),m=s.client?void 0:window.ogb?.cloudAccount,g=s.desktop&&!s.client&&!s.here&&!s.home&&!m,f=d.email??(d.plan?c?.email??null:null),h=window.ogb?.accountSheet,j=e.jsx(De,{place:{kind:"computer",name:u.name,color:null},size:14});return e.jsxs(e.Fragment,{children:[e.jsx(J,{block:"you",children:e.jsx(V,{children:g&&u.open?e.jsx(ye,{title:t("settings.account.nameRow"),badge:j,value:t("settings.account.onPlace",{place:u.name}),external:!0,onClick:u.open,data:{"data-account-name-row":""}}):e.jsx(ye,{title:t("settings.account.nameRow"),badge:e.jsx(De,{place:n,size:14}),value:Lo(c),onClick:()=>a("bots","about-you"),data:{"data-account-name-row":""}})})}),m&&e.jsx(Er,{part:"account",advanced:s.advanced,linkRequest:i.appSettingsCloudLink,avatar:e.jsx(Kt,{size:32}),onSignIn:()=>r({type:"openCloudAdd",source:"app_settings",signIn:!0})}),g&&e.jsx(J,{label:t("settings.account.mausbot",{app:je()}),block:"mausbot-account",children:e.jsxs(V,{icons:!0,children:[e.jsx(L,{title:f??t("settings.account.signedIn"),leading:e.jsx(Kt,{size:32}),subtitle:d.signedIn===!1?t("settings.account.notSignedIn"):t("settings.account.signedIn"),children:null}),h&&e.jsx(ye,{title:t("accounts.manage"),leading:e.jsx("span",{"aria-hidden":"true"}),onClick:()=>{h.open().catch(()=>{})},data:{"data-account-manage":""}}),u.open&&e.jsx(ye,{title:t("settings.account.fromHere",{place:u.name}),leading:e.jsx("span",{"aria-hidden":"true"}),external:!0,onClick:u.open,data:{"data-account-elsewhere":""}})]})}),!s.desktop&&e.jsxs(J,{block:"mausbot-account",children:[e.jsxs(V,{children:[e.jsx(L,{title:t("settings.account.signedInTo",{place:n.name}),subtitle:c?.email,children:null}),l?.kind==="session"&&e.jsx(L,{title:t("settings.account.signOutBrowser"),children:e.jsx("button",{type:"button","data-danger":"",className:"settings-quiet cursor-pointer",onClick:()=>x(!0),children:t("settings.account.signOutShort")})})]}),p&&e.jsx(Di,{browser:!0,here:n.name,onConfirm:()=>M("/api/auth/logout",{method:"POST"}).finally(()=>location.reload()),onClose:()=>x(!1)})]}),s.organization?e.jsx(J,{label:t("settings.section.organization"),block:"organization",children:e.jsx(Sp,{simple:!s.advanced})}):g&&s.advanced&&e.jsx(J,{label:t("settings.section.organization"),block:"organization",children:e.jsx(V,{children:e.jsx(ct,{title:t("settings.account.orgSignIn"),control:e.jsx("button",{type:"button",className:"ui-button",tabIndex:-1,children:t("settings.account.signIn")})})})}),s.desktop&&!s.client&&window.ogb?.updatesConsent&&e.jsx(J,{label:t("settings.account.emails",{app:je()}),block:"emails",children:e.jsx(V,{children:e.jsx(Ro,{})})})]})}function Ap(){const{ctx:s,place:n}=we(),{state:a,dispatch:i}=_(),{usage:r,upgrade:c,dialog:l}=Io();return s.desktop?e.jsxs(e.Fragment,{children:[e.jsx(Er,{part:"plan",advanced:s.advanced,cloudHome:s.cloud,teamHome:a.config?.team,linkRequest:a.appSettingsCloudLink,usage:r,upgrade:c,extra:!s.advanced&&!s.client&&!(s.team&&!s.admin)&&(n.kind==="computer"||n.kind==="server")?e.jsx(cp,{place:n.name}):void 0,onAddCloud:()=>i({type:"openCloudAdd",source:"app_settings"}),onSignIn:()=>i({type:"openCloudAdd",source:"app_settings",signIn:!0})}),e.jsx(Cp,{}),l]}):e.jsx(J,{block:"plan",children:e.jsx(V,{children:e.jsx(L,{title:t("settings.plan.browserTitle"),subtitle:t("settings.plan.browserLine",{app:je()}),children:e.jsxs("a",{className:"ui-button ui-button-primary inline-flex items-center gap-1",href:kl,target:"_blank",rel:"noreferrer",children:[t("settings.plan.openBilling"),e.jsx(Qs,{size:12,"aria-hidden":"true"})]})})})})}const Pp="https://github.com/seira-bot/seira/blob/main/docs/analytics.md";function Tp({simple:s=!1}){const[n,a]=o.useState(wl);if(!Nl())return null;const i=e.jsxs(e.Fragment,{children:[t(s?"settings.simple.analytics":"settings.analytics.subtitle")," ",e.jsx("a",{href:Pp,target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline",children:t(s?"settings.simple.analyticsLink":"settings.analytics.link")})]});return e.jsx(L,{title:t("settings.analytics.title"),subtitle:i,children:e.jsx(ne,{checked:n,"aria-label":t("settings.analytics.aria"),onClick:()=>{const r=!n;Sl(r),a(r)}})})}function Ip(){const[s,n]=o.useState(Al);return e.jsx(L,{title:t("settings.font.title"),subtitle:t("settings.font.line"),children:e.jsx(ce,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("settings.font.aria"),onChange:a=>{const i=a.target.value;Tl(i),n(i)},children:Pl.map(a=>e.jsx("option",{value:a,children:t(`settings.font.${a}`)},a))})})}function Lp(){const[s,n]=o.useState(Cl);return e.jsx(L,{title:t("settings.chatWidth.title"),subtitle:t("settings.chatWidth.line"),children:e.jsx(ce,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("settings.chatWidth.aria"),onChange:a=>{const i=An.find(r=>r===a.target.value);i&&(El(i),n(i))},children:An.map(a=>e.jsx("option",{value:a,children:t(`settings.chatWidth.${a}`)},a))})})}function Rp(){const s=Bo();return e.jsx(L,{title:t("sidebar.toolsLayout.title"),subtitle:t("sidebar.toolsLayout.subtitle"),children:e.jsx(ce,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("sidebar.toolsLayout.chooseAria"),onChange:n=>Fo(Uo(n.target.value)),children:Oo.map(n=>e.jsx("option",{value:n,children:t(`sidebar.toolsLayout.${n}`)},n))})})}function At(){const{dispatch:s}=_(),[n,a]=o.useState(!1),[i,r]=o.useState("");return{saving:n,error:i,save:async l=>{if(!n){a(!0),r("");try{const d=await M("/api/config",{method:"PATCH",body:JSON.stringify(l)});s({type:"configStatus",config:d})}catch(d){r(d instanceof Error?d.message:t("settings.experimental.error"))}finally{a(!1)}}}}}function Bp(){const{state:s}=_(),n=Zt(s.config),a=Mo(s.config),i=s.config?.browserEngine?.installable===!0,r=window.ogb?.platform==="win32"&&!a&&!i,{saving:c,error:l,save:d}=At();return e.jsx(L,{title:t("settings.browser.rowTitle"),subtitle:a?n?t("settings.ai.ready"):t("settings.browser.offShort"):r?t("settings.experimental.browserWindows"):i?n?t("settings.browser.installsFirst"):t("settings.browser.notInstalledShort"):Do(s.config),message:l?e.jsx("p",{role:"alert",className:"text-danger",children:l}):null,children:e.jsx(ne,{checked:n,"aria-label":t("settings.experimental.browserAria"),disabled:c||!n&&!a&&!i,onClick:()=>{d({features:{browser:!n}})},className:"disabled:cursor-wait disabled:opacity-50"})})}function Op(){const{state:s}=_(),n=kt(),a=s.config?.browserEngine?.serverSites,{saving:i,error:r,save:c}=At();return a===void 0||n!==!0||!Zt(s.config)?null:e.jsx(L,{title:t("settings.browser.localSites"),subtitle:t("settings.browser.localSitesPlain"),message:r?e.jsx("p",{role:"alert",className:"text-danger",children:r}):null,children:e.jsx(ne,{checked:a,"aria-label":t("settings.browser.serverSites"),disabled:i,onClick:()=>{c({browserEngine:{egress:{localNetwork:!a}}})},className:"disabled:cursor-wait disabled:opacity-50"})})}function Fp(){const{state:s}=_(),n=kt(),a=s.config?.team?s.config.browserEngine?.proxyEditable===!0:n===!0,i=s.config?.browserEngine?.proxyConfigured===!0,r=s.config?.browserEngine?.proxySaved===!0||i,[c,l]=o.useState(""),{saving:d,error:u,save:p}=At();return!a||!Zt(s.config)&&!r?null:e.jsx(L,{title:t("settings.browser.proxy"),subtitle:i?t("settings.browser.proxyConfigured"):r?t("settings.browser.proxyInactive"):t("settings.browser.proxyDetail"),message:u?e.jsx("p",{role:"alert",className:"text-danger",children:u}):null,children:e.jsxs("div",{className:"flex w-full flex-wrap items-center gap-2 sm:w-auto",children:[e.jsx("input",{"aria-label":t("settings.browser.proxy"),autoComplete:"off",spellCheck:!1,placeholder:"socks5://127.0.0.1:1080",value:c,onChange:x=>l(x.target.value),className:"min-w-0 flex-1 rounded-lg border border-control bg-app px-3 py-2 text-[13px] text-ink sm:w-64 sm:flex-none"}),e.jsx("button",{type:"button",disabled:d||!c.trim(),onClick:()=>{p({browserEngine:{egress:{proxy:c.trim()}}})},className:"rounded-lg bg-control px-3 py-2 text-[13px] text-ink disabled:opacity-50",children:t("settings.browser.proxySave")}),r?e.jsx("button",{type:"button",disabled:d,onClick:()=>{p({browserEngine:{egress:{proxy:""}}})},className:"rounded-lg bg-control px-3 py-2 text-[13px] text-ink disabled:opacity-50",children:t("settings.browser.proxyClear")}):null]})})}function Up(){const{state:s}=_(),n=s.config?.browserEngine?.engine==="chrome",{saving:a,error:i,save:r}=At();return e.jsx("div",{"data-testid":"new-browser-settings",className:"contents",children:e.jsx(L,{title:t("settings.experimental.newBrowser"),tag:t("settings.early.tag"),subtitle:e.jsx(wt,{short:t("settings.experimental.newBrowserShort"),long:t("settings.experimental.newBrowserDetail")}),message:i?e.jsx("span",{role:"alert",className:"text-danger",children:i}):void 0,children:e.jsx(ne,{checked:n,"aria-label":t("settings.experimental.newBrowserAria"),disabled:a,onClick:()=>{r({browserEngine:{engine:n?"agent-browser":"chrome"}})},className:"disabled:cursor-wait disabled:opacity-50"})})})}function Mp(){const{state:s}=_(),n=zo(s.config),{saving:a,error:i,save:r}=At();return s.config?.features?.usbPhoneTakeover===void 0?null:e.jsx("div",{"data-testid":"usb-phone-takeover-settings",className:"contents",children:e.jsx(L,{title:t("settings.experimental.usbPhoneTakeover"),tag:t("settings.early.tag"),subtitle:e.jsx(wt,{short:t("settings.experimental.usbPhoneTakeoverShort"),long:t("settings.experimental.usbPhoneTakeoverDetail")}),message:i?e.jsx("span",{role:"alert",className:"text-danger",children:i}):void 0,children:e.jsx(ne,{checked:n,"aria-label":t("settings.experimental.usbPhoneTakeover"),disabled:a,onClick:()=>{r({features:{usbPhoneTakeover:!n}})},className:"disabled:cursor-wait disabled:opacity-50"})})})}function Dp(){const{state:s,dispatch:n}=_(),a=Zs(s.config),i=_o(s.config),r=Ho(s.config),c=$o(s.bots,s.instances),[l,d]=o.useState(String(r)),[u,p]=o.useState(!1),[x,m]=o.useState(!1),[g,f]=o.useState(""),h=o.useRef(!1);o.useEffect(()=>{u||d(String(r))},[r,u]);const j=async y=>{if(h.current)return!1;h.current=!0,m(!0),f("");try{const v=await M("/api/config",{method:"PATCH",body:JSON.stringify({features:y})});return n({type:"configStatus",config:v}),!0}catch(v){return f(v instanceof Error?v.message:t("settings.experimental.error")),!1}finally{h.current=!1,m(!1)}},b=async()=>{if(!u)return;const y=Ko(l);if(y===null){f(t("settings.experimental.skillReviewStepsRange",{min:zn,max:Dn}));return}await j({skillReviewSteps:y})&&p(!1)};return e.jsxs("div",{"data-testid":"skill-review-settings",className:"contents",children:[e.jsx(L,{title:t("settings.experimental.skillReview"),tag:t("settings.early.tag"),subtitle:a?e.jsx(wt,{short:t("settings.experimental.skillReviewShort"),long:t("settings.experimental.skillReviewDetail")}):t("settings.experimental.skillReviewNeedsAuthoring"),message:c.length?e.jsx(zp,{engines:c}):!i&&g?e.jsx("span",{role:"alert",className:"text-danger",children:g}):void 0,children:e.jsx(ne,{checked:i,"aria-label":t("settings.experimental.skillReviewAria"),disabled:x||!a,onClick:()=>{j({skillReview:!i})}})}),i?e.jsxs(L,{title:t("settings.experimental.skillReviewStepsTitle"),message:g?e.jsx("span",{role:"alert",className:"text-danger",children:g}):void 0,children:[e.jsx("input",{id:"skill-review-steps",type:"number","aria-label":t("settings.experimental.skillReviewSteps"),min:zn,max:Dn,step:1,inputMode:"numeric",value:l,disabled:x,"aria-invalid":!!g,onChange:y=>{d(y.target.value),p(!0),f("")},onBlur:()=>{b()},onKeyDown:y=>{y.key==="Enter"&&y.currentTarget.blur()},className:Ue}),e.jsx("span",{className:"text-[13px] leading-5 text-ink-secondary",children:t("settings.experimental.skillReviewStepsUnit")})]}):null]})}function zp({engines:s}){return s.length?e.jsx("span",{className:"block","data-testid":"skill-review-engine-note",children:t("settings.experimental.skillReviewNoEngine",{engines:s.join(", ")})}):null}const _p=[{value:"off",label:"settings.experimental.shareSkillsOff"},{value:"ask",label:"settings.experimental.shareSkillsAsk"},{value:"auto",label:"settings.experimental.shareSkillsAuto"}];function Hp(){const{state:s,dispatch:n}=_(),[a,i]=o.useState(!1),[r,c]=o.useState("");if(!Vs(s.config))return null;const l=Zs(s.config),d=Wo(s.config),u=async p=>{if(!(a||p===d)){i(!0),c("");try{const x=await M("/api/config",{method:"PATCH",body:JSON.stringify({features:{shareLearnedSkills:p}})});n({type:"configStatus",config:x})}catch(x){c(x instanceof Error?x.message:t("settings.experimental.error"))}finally{i(!1)}}};return e.jsx("div",{"data-testid":"share-learned-skills-settings",className:"contents",children:e.jsx(L,{title:t("settings.experimental.shareSkills"),tag:t("settings.early.tag"),subtitle:l?e.jsx(wt,{short:t("settings.experimental.shareSkillsShort"),long:t("settings.experimental.shareSkillsDetail")}):t("settings.experimental.shareSkillsNeedsAuthoring"),message:r?e.jsx("span",{role:"alert",className:"text-danger",children:r}):void 0,children:e.jsx(zi,{value:d,label:t("settings.experimental.shareSkillsAria"),disabled:a||!l,onChange:p=>{u(p)},options:_p.map(p=>({value:p.value,label:t(p.label)}))})})})}function $p(){return e.jsxs(e.Fragment,{children:[e.jsx(Dp,{}),e.jsx(Hp,{})]})}function Kp({title:s=t("settings.updates.title")}){const n=Xs(),a=window.ogb?.updater;if(!n||!a)return null;if(n.managedByStore)return e.jsx(L,{title:s,subtitle:t("settings.updates.fromPackage"),children:null});const i=n.status==="checking"?t("settings.updates.checking"):n.status==="downloading"?n.percent==null?t("settings.updates.startingDownload"):t("settings.updates.downloading",{percent:Math.round(n.percent)}):n.status==="preparing"?t("settings.updates.preparing"):n.status==="downloaded"?n.installMode==="handoff"?t("settings.updates.readyInstall",{app:je(),version:n.version??""}):t("settings.updates.ready",{app:je(),version:n.version??""}):n.status==="installing"?Hn(n)||(n.installMode==="handoff"?t("settings.updates.openingTerminal"):t("settings.updates.restarting")):n.status==="handed-off"?t("settings.updates.handedOff"):n.status==="error"?t("settings.updates.failed",{message:Hn(n)??t("settings.updates.unknownError")}):t("settings.updates.latest");return e.jsx(L,{title:s,subtitle:i,children:e.jsx("button",{onClick:()=>{if(n.status==="downloaded")return void a.install();a.check()},disabled:n.status==="checking"||n.status==="downloading"||n.status==="preparing"||n.status==="installing"||n.retryable===!1,className:"ui-button",children:n.retryable===!1?t("settings.updates.quitReopen"):n.status==="downloaded"?n.installMode==="handoff"?t("settings.updates.install"):t("settings.updates.restart"):n.status==="preparing"?t("settings.updates.preparingShort"):n.status==="installing"?n.installMode==="handoff"?t("settings.updates.opening"):t("settings.updates.restartingShort"):t("settings.updates.check")})})}function Wp(){const{state:s,dispatch:n}=_(),a=s.config?.newBots?.effort??"",[i,r]=o.useState(!1),[c,l]=o.useState("");return{current:a,saving:i,error:c,save:async u=>{if(!i){r(!0),l("");try{const p=await M("/api/config",{method:"PATCH",body:JSON.stringify({newBots:{effort:oc(u)?u:null}})});n({type:"configStatus",config:p})}catch(p){l(p instanceof Error?p.message:t("settings.newBotEffort.error"))}finally{r(!1)}}}}}function Gp({effort:s,className:n}){return e.jsxs(ce,{size:"sm",className:n,value:s.current,disabled:s.saving,"aria-label":t("settings.newBotEffort.aria"),onChange:a=>{s.save(a.target.value)},children:[e.jsx("option",{value:"",children:t("settings.newBotEffort.default")}),rc.map(a=>e.jsx("option",{value:a,children:lc(a)},a))]})}function qp(){const s=Wp();return e.jsx(L,{title:t("settings.newBotEffort.title"),subtitle:t("settings.newBotEffort.short"),message:s.error?e.jsx("p",{role:"alert",className:"text-danger",children:s.error}):null,children:e.jsx(Gp,{effort:s,className:"w-full max-w-[240px]"})})}function Vp({label:s=t("settings.welcome.appTour")}){const{state:n,dispatch:a}=_(),[i,r]=o.useState(!1),[c,l]=o.useState(!1);return e.jsxs("div",{children:[e.jsx("button",{disabled:i,onClick:()=>{r(!0),l(!1),M("/api/config",{method:"PUT",body:JSON.stringify({onboarding:{...n.config?.onboarding?.completedAt?{}:to().onboarding,hintsSeen:ic(n.config?.onboarding)}}),signal:AbortSignal.timeout(1e4)}).then(d=>{a({type:"configStatus",config:d}),a({type:"toggleTour",open:!0})}).catch(()=>l(!0)).finally(()=>r(!1))},className:"ui-button",children:s}),c&&e.jsx("p",{role:"alert",className:"mt-2 text-[13px] text-danger",children:t("onboarding.tour.error")})]})}function Jp(){const{state:s,dispatch:n}=_();return s.config?.team?null:e.jsxs(e.Fragment,{children:[e.jsx(L,{title:t("settings.welcome.appTour"),subtitle:t("settings.welcome.appTourLine"),children:e.jsx(Vp,{label:t("settings.welcome.replayShort")})}),e.jsx(L,{title:t("settings.welcome.replay"),subtitle:t("settings.welcome.subtitleShort"),children:e.jsx("button",{type:"button",onClick:()=>n({type:"toggleWelcome",open:!0}),className:"ui-button",children:t("settings.welcome.replayShort")})})]})}function Pr({simple:s=!1}){const{state:n}=_(),a=Ol(Fl(),n.config?.language);return e.jsx(L,{title:t("settings.language.title"),subtitle:Dl()?t("settings.language.subtitleComplete"):s?Ee()==="en"?void 0:t("settings.simple.language.partial"):t("settings.language.subtitle"),children:e.jsxs(ce,{size:"sm",variant:s?"ghost":"field",className:s?void 0:"w-full max-w-[240px]",value:a,"aria-label":t("settings.language.aria"),onChange:i=>Ml(i.target.value),children:[e.jsx("option",{value:"",children:t(s?"settings.simple.language.system":"settings.language.system")}),Ul.map(({code:i,label:r})=>e.jsx("option",{value:i,children:r},i))]})})}function Yp({simple:s=!1}){const n=_i();return e.jsx(L,{title:t("settings.sendKey.title"),subtitle:t(s?"settings.simple.sendKey":"settings.sendKey.subtitle",{key:_n("mod-enter")}),children:e.jsx(ce,{size:"sm",variant:s?"ghost":"field",className:s?void 0:"w-full max-w-[240px]",value:n,"aria-label":t("settings.sendKey.title"),onChange:a=>Zo(ec(a.target.value)),children:zl.map(a=>e.jsx("option",{value:a,children:_n(a)},a))})})}function Xp({simple:s=!1}){const n=tc(),a=sc(_i());return e.jsx(L,{title:t("settings.followUp.title"),subtitle:t(s?"settings.simple.followUp":"settings.followUp.subtitle",{key:a}),children:e.jsxs(ce,{size:"sm",variant:s?"ghost":"field",className:s?void 0:"w-full max-w-[240px]",value:n,"aria-label":t("settings.followUp.title"),onChange:i=>nc(ac(i.target.value)),children:[e.jsx("option",{value:"steer",children:t("settings.followUp.steer")}),e.jsx("option",{value:"queue",children:t("settings.followUp.queue")})]})})}function Qp({simple:s=!1}){const n=Go();return e.jsx(L,{title:t(s?"settings.userBubbles.simpleTitle":"settings.userBubbles.title"),subtitle:s?void 0:t("settings.userBubbles.subtitle"),children:e.jsx(ne,{checked:n,"aria-label":t("settings.userBubbles.aria"),onClick:()=>qo(!n)})})}function Zp(){const s=Rl();return e.jsx(L,{title:t("settings.threadDisplay.title"),subtitle:t("settings.threadDisplay.short"),children:e.jsx(ne,{checked:s,"aria-label":t("settings.threadDisplay.show"),onClick:()=>Bl(!s)})})}function em(){const s=Jo();return e.jsx(L,{title:t("settings.pinnedCircles.title"),subtitle:t("settings.pinnedCircles.short"),children:e.jsx(ne,{checked:s,"aria-label":t("settings.pinnedCircles.title"),onClick:()=>Yo(!s)})})}function tm(){const s=Il();return e.jsx(L,{title:t("settings.runCard.rowTitle"),subtitle:t("settings.runCard.line"),children:e.jsx(ne,{checked:s,"aria-label":t("settings.runCard.show"),onClick:()=>Ll(!s)})})}function sm(){const s=Xo();return e.jsx(L,{title:t("settings.universalPins.title"),subtitle:t("settings.universalPins.subtitle"),children:e.jsx(ne,{checked:s,"aria-label":t("settings.universalPins.title"),onClick:()=>Qo(!s)})})}function nm(){const{state:s,dispatch:n}=_(),a=Vo(s.config),[i,r]=o.useState(!1),[c,l]=o.useState(""),d=async()=>{if(!i){r(!0),l("");try{const u=await M("/api/config",{method:"PATCH",body:JSON.stringify({features:{showToolCalls:!a}})});n({type:"configStatus",config:u})}catch(u){l(u instanceof Error?u.message:t("settings.toolCalls.error"))}finally{r(!1)}}};return e.jsx(L,{title:t("settings.toolCalls.title"),subtitle:t("settings.toolCalls.short"),message:c?e.jsx("p",{role:"alert",className:"text-danger",children:c}):null,children:e.jsx(ne,{checked:a,"aria-label":t("settings.toolCalls.aria"),disabled:i,onClick:()=>{d()},className:"disabled:cursor-wait disabled:opacity-50"})})}function am(){const{state:s,dispatch:n}=_(),a=Zs(s.config),[i,r]=o.useState(!1),[c,l]=o.useState(""),d=async u=>{if(!i){r(!0),l("");try{const p=await M("/api/config",{method:"PATCH",body:JSON.stringify({features:{skillAuthoring:u}})});n({type:"configStatus",config:p})}catch(p){l(p instanceof Error?p.message:t("settings.experimental.error"))}finally{r(!1)}}};return e.jsx(J,{label:t("settings.experimental.title"),description:t("settings.experimental.short"),block:"early-features",children:e.jsxs(V,{children:[e.jsx(L,{title:t("settings.experimental.skillAuthoring"),tag:t("settings.early.tag"),subtitle:e.jsx(wt,{short:t("settings.experimental.skillAuthoringShort"),long:t("settings.experimental.skillAuthoringDetail")}),message:c?e.jsx("span",{role:"alert",className:"text-danger",children:c}):void 0,children:e.jsx(ne,{checked:a,"aria-label":t("settings.experimental.skillAuthoringAria"),disabled:i,onClick:()=>{d(!a)},className:"disabled:cursor-wait disabled:opacity-50"})}),e.jsx($p,{}),e.jsx(Mp,{})]})})}function im(){const{state:s}=_(),n=s.config?.browserProfiles??[];return!Zt(s.config)&&n.length===0?null:e.jsx(gu,{})}const rm={list_files:"lending.action.listFiles",read_file:"lending.action.readFile",write_file:"lending.action.writeFile",edit_file:"lending.action.writeFile",append_file:"lending.action.writeFile",delete_file:"lending.action.deleteFile",run_command:"lending.action.runCommand",computer_tools:"lending.action.screenTools",computer_call:"lending.action.screen",invalid:"lending.action.invalid",internet:"lending.action.website",chrome:"lending.action.chrome"};function lm({entries:s}){return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("p",{className:"font-medium text-ink",children:t("lending.activity.title")}),s&&s.length===0&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("lending.activity.empty")}),s&&s.length>0&&e.jsx("ul",{"aria-label":t("lending.activity.title"),className:"flex max-h-56 flex-col gap-1 overflow-y-auto text-[12px]",children:s.map((n,a)=>e.jsxs("li",{className:"flex flex-wrap gap-x-2 text-ink-secondary",children:[e.jsx("time",{dateTime:new Date(n.at).toISOString(),className:"shrink-0 tabular-nums",children:new Date(n.at).toLocaleString(Gs())}),e.jsxs("span",{className:n.ok?"text-ink":"text-danger",children:[t(rm[n.action]??"lending.action.other"),n.ok?"":` · ${t("lending.activity.refused")}`]}),n.detail&&e.jsx("span",{dir:"auto",className:"min-w-0 break-all",children:n.detail})]},`${n.at}-${a}`))})]})}function om({workspace:s,own:n=!1,onClose:a}){const{state:i}=_(),c=n||Hi(i.config)?window.ogb?.computerSharing:void 0,[l,d]=o.useState(null),[u,p]=o.useState([]),[x,m]=o.useState(!1),[g,f]=o.useState(!1),[h,j]=o.useState(!1),[b,y]=o.useState(""),[v,w]=o.useState(null),N=o.useRef(!1),C=o.useRef(!1),I=o.useRef(null),F=S=>{d(S),p(S.folders),m(S.terminal),f(S.computer)};o.useEffect(()=>{N.current=!0,I.current?.scrollIntoView({block:"start"}),c?.state(s.id).then(E=>{N.current&&F(E)}).catch(()=>{N.current&&y(t("computerSharing.loadFailed"))});const S=()=>{c?.state(s.id).then(E=>{N.current&&d(E)}).catch(()=>{}),c?.activity?.(s.id).then(E=>{N.current&&w(E)}).catch(()=>{})};S();const P=setInterval(S,3e3);return()=>{N.current=!1,clearInterval(P)}},[c,s.id]);const k=async S=>{if(!C.current){C.current=!0,j(!0),y("");try{await S()}catch(P){N.current&&y(String(P?.message??P).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,""))}finally{C.current=!1,N.current&&j(!1)}}};return c?e.jsx("div",{ref:I,children:e.jsx(pe,{title:t("computerSharing.title",{name:s.name}),subtitle:s.origin,children:e.jsxs("div",{className:"flex flex-col gap-4 text-[13px]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{role:"status",className:"text-ink-secondary",children:l?l.enabled?l.connected?t("computerSharing.sharing"):"Waiting for the workspace to connect":t("computerSharing.notShared"):t("computerSharing.loading")}),e.jsx("button",{type:"button","aria-label":t("computerSharing.close"),onClick:a,className:"rounded p-1 text-ink-secondary hover:bg-control",children:e.jsx(Me,{size:16})})]}),e.jsx("p",{className:"text-ink-secondary",children:n?t("computerSharing.ownIntro",{name:s.name}):"Choose what this workspace’s bots can use. Shared files and screen content may be sent to its AI provider. Access stays on when you switch workspaces, until you stop sharing or close the desktop app."}),n&&l?.enabled&&e.jsxs("div",{"data-sharing-pause":!0,className:"flex items-center gap-3 rounded-lg bg-inset px-3 py-2",children:[e.jsx("p",{className:"min-w-0 flex-1 text-[12px] text-ink-secondary",children:t(l.paused?"computerSharing.paused":"computerSharing.pauseHint")}),e.jsx("button",{type:"button",disabled:h,onClick:()=>{k(async()=>{await(l.paused?c.resume?.():c.pause?.());const S=await c.state(s.id);N.current&&d(S)})},className:"shrink-0 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink hover:bg-control disabled:opacity-50",children:t(l.paused?"computerSharing.resume":"computerSharing.pause")})]}),e.jsxs("fieldset",{disabled:h||!l,className:"flex flex-col gap-3 disabled:opacity-50",children:[e.jsx("legend",{className:"mb-2 font-medium text-ink",children:t("computerSharing.folders")}),u.length===0&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("computerSharing.noFolders")}),u.map(S=>e.jsxs("div",{className:"flex flex-wrap items-center gap-3 rounded-lg border border-hairline/40 p-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-medium text-ink",children:S.name}),e.jsx("p",{className:"break-all text-[12px] text-ink-secondary",children:S.path})]}),e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:S.write,onChange:P=>p(E=>E.map(A=>A.id===S.id?{...A,write:P.target.checked}:A))}),t("computerSharing.allowEdits")]}),e.jsx("button",{type:"button","aria-label":t("lending.removeFolder",{name:S.name}),onClick:()=>p(P=>P.filter(E=>E.id!==S.id)),className:"rounded p-1 text-ink-secondary hover:bg-control",children:e.jsx(Me,{size:14})})]},S.id)),e.jsxs("button",{type:"button",disabled:u.length>=20,onClick:()=>{k(async()=>{const S=await c.chooseFolder();N.current&&S&&p(P=>P.some(E=>E.path===S.path)?P:[...P,S])})},className:"flex w-fit items-center gap-2 rounded-lg border border-hairline/40 px-3 py-2 text-ink hover:bg-control",children:[e.jsx(cc,{size:14}),t("computerSharing.chooseFolder")]}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("computerSharing.smallFiles")})]}),e.jsxs("fieldset",{disabled:h||!l,className:"flex flex-col gap-3 border-t border-hairline/40 pt-3 disabled:opacity-50",children:[e.jsx("legend",{className:"font-medium text-ink",children:t("computerSharing.broader")}),e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("input",{className:"mt-1",type:"checkbox",checked:x,onChange:S=>m(S.target.checked)}),e.jsxs("span",{className:"text-ink",children:[t("computerSharing.terminal"),e.jsx("span",{className:"mt-1 block text-[12px] text-ink-secondary",children:t("computerSharing.terminalHint")})]})]}),e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("input",{className:"mt-1",type:"checkbox",checked:g,onChange:S=>f(S.target.checked)}),e.jsxs("span",{className:"text-ink",children:[t("computerSharing.control"),e.jsx("span",{className:"mt-1 block text-[12px] text-ink-secondary",children:t("computerSharing.controlHint")})]})]})]}),(b||l?.error)&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:b||l?.error}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",disabled:h||!l||!u.length&&!x&&!g,onClick:()=>{k(async()=>{const S=await c.save(s.id,{folders:u,terminal:x,computer:g});N.current&&S&&F(S)})},className:"rounded-lg bg-accent px-3 py-2 font-medium text-accent-ink disabled:opacity-50",children:t(l?.enabled?"computerSharing.save":"computerSharing.share")}),l?.enabled&&e.jsx("button",{type:"button",disabled:h,onClick:()=>{k(async()=>{const S=await c.revoke(s.id);N.current&&F(S)})},className:"rounded-lg border border-hairline/40 px-3 py-2 text-danger disabled:opacity-50",children:t("computerSharing.stop")})]}),l?.enabled&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("computerSharing.stopHint")}),e.jsx("div",{className:"border-t border-hairline/40 pt-3",children:e.jsx(lm,{entries:v})})]})})}):null}const cm={https:"servers.transport.https",tailscale:"servers.transport.tailscale","private-http":"servers.transport.privateHttp",loopback:"servers.transport.loopback"},dm=s=>new Date(s).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});function um(s,n){return s==="docker"?"git pull && ./update.sh":s==="podman-service"?"~/.local/share/openmausbot/update.sh":s==="global"?`npm install -g @seira-bot/seira@${n}`:s==="source"?"git pull && pnpm install":`npx @seira-bot/seira@${n} serve`}function pm({name:s,status:n,appVersion:a,onHide:i}){const{state:r,copy:c}=Yt(um(n.install,a));return e.jsxs("div",{"data-server-behind":!0,className:"mt-2 flex items-center gap-2 rounded-lg bg-inset px-3 py-2 text-[12px] text-ink",children:[e.jsx("span",{className:"min-w-0 flex-1",children:t("servers.behind",{name:s,server:n.version??"",app:a})}),e.jsx("button",{type:"button",onClick:c,className:"shrink-0 font-medium text-accent-text hover:underline",children:t(r==="copied"?"servers.copied":"servers.behind.copy")}),e.jsx("button",{type:"button",onClick:i,"aria-label":t("servers.behind.hide"),className:"shrink-0 text-ink-secondary hover:text-ink",children:e.jsx(Me,{size:13})})]})}function mm({origin:s,name:n}){const{state:a,copy:i}=Yt(s);return e.jsx("button",{type:"button",onClick:i,"aria-label":t("servers.copyAddressFor",{name:n}),title:t(a==="copied"?"servers.copied":"servers.copyAddress"),className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-ink",children:a==="copied"?e.jsx(_e,{size:14}):e.jsx(qs,{size:14})})}function xm({status:s,onTryNow:n,onPairAgain:a,onEdit:i}){if(!s||s.state==="connected")return null;const r=(d,u)=>e.jsx("button",{type:"button",onClick:u,className:"ml-2 font-medium text-accent-text hover:underline",children:d}),c=s.state==="checking"?t("servers.state.checking"):s.state==="reconnecting"?t("servers.state.reconnecting"):s.state==="cantReach"?t("servers.state.cantReach",{time:dm(s.since)}):s.state==="signedOut"?t("servers.state.signedOut"):t("servers.state.insecure"),l=s.state==="signedOut"||s.state==="insecure";return e.jsxs("div",{"data-server-state":s.state,className:l||s.state==="cantReach"?"text-[12px] text-danger":"text-[12px] text-ink-secondary",children:[c,s.state==="cantReach"&&r(t("servers.tryNow"),n),s.state==="signedOut"&&r(t("servers.pairAgain"),a),s.state==="insecure"&&r(t("servers.editAddress"),i)]})}function gm({name:s,share:n,busy:a,onShare:i,onOpen:r}){const c=n.enabled?n.paused?"servers.share.paused":"servers.share.on":"servers.share.off";return e.jsxs("div",{"data-server-share":n.id,className:"mt-2 flex items-center gap-3 rounded-lg bg-inset px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[12px] font-medium text-ink",children:t("servers.share.title")}),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t(c,{name:s})})]}),n.enabled&&e.jsx("button",{type:"button",disabled:a,onClick:r,className:"shrink-0 text-[12px] font-medium text-accent-text hover:underline disabled:opacity-50",children:t("servers.share.choose")}),e.jsx(ne,{checked:n.enabled,disabled:a,"aria-label":t("servers.share.for",{name:s}),onClick:()=>i(!n.enabled)})]})}function hm({saved:s,busy:n,sharingOffered:a,ownServers:i=[],appVersion:r,onSwitch:c,onForget:l,onComputerAccess:d,onShare:u=()=>{}}){const p=window.ogb?.environments,[x,m]=o.useState([]),[g,f]=o.useState([]),[h,j]=o.useState(null);o.useEffect(()=>{if(!p?.status)return;let N=!0;const C=()=>{p.status().then(F=>{N&&m(F)}).catch(()=>{})};C();const I=p.onStatus?.(C);return()=>{N=!1,I?.()}},[p,s]);const b=N=>x.find(C=>C.id===N),y=N=>j({address:N.origin,locked:!0,title:t("servers.pairAgainTitle",{name:N.name})}),v=N=>j({address:N.origin.replace(/^http:/,"https:"),locked:!1,title:t("connect.title")}),w=[{id:"local",name:t("place.local"),kind:"local"},...s.environments.filter(N=>N.kind!=="local")];return e.jsxs(e.Fragment,{children:[e.jsxs(V,{icons:!0,children:[w.map(N=>{const C=N.id===s.activeId,I=It(N)?b(N.id):void 0,F=N.id==="local"?t("servers.localHint"):It(N)?`${new URL(N.origin).host} · ${t(cm[_l(N.origin)])}`:N.home?t("servers.managed"):new URL(N.origin).host,k=i.find(P=>P.id===N.id),S=I?.behind===!0&&r!==null&&!g.includes(`${N.id}:${I.version}`);return e.jsxs("div",{"data-server-row":N.id,className:"flex flex-col px-4 py-3",children:[e.jsxs("div",{className:"flex min-h-10 items-center gap-3",children:[N.id==="local"?e.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center rounded-full bg-ink/[0.05] text-ink-secondary",children:e.jsx(at,{size:18,strokeWidth:1.75,"aria-hidden":"true"})}):e.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center",children:e.jsx(De,{place:{kind:N.home||N.cloud?"cloud":"server",name:N.name,color:N.color??null,named:!0},size:24})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"flex items-center gap-1.5 truncate text-[14px] leading-5 text-ink",children:N.name}),e.jsx("div",{"data-server-where":!0,className:"truncate text-[13px] leading-[18px] text-ink-secondary",children:F}),e.jsx(xm,{status:I,onTryNow:()=>{p?.retry?.(N.id)},onPairAgain:()=>y(N),onEdit:()=>v(N)})]}),C?e.jsx("span",{className:"shrink-0 text-[13px] leading-5 text-ink-secondary",children:t("servers.current")}):e.jsx("button",{type:"button",disabled:n,"aria-label":t("servers.switchTo",{name:N.name}),onClick:()=>c(N.id),className:"ui-button shrink-0",children:t("servers.switch")}),It(N)&&I?.state!=="signedOut"&&e.jsx("button",{type:"button",disabled:n,onClick:()=>y(N),className:"settings-quiet shrink-0 cursor-pointer",children:t("servers.pairAgain")}),N.id!=="local"&&!N.home&&!N.cloud&&!k&&a&&e.jsx("button",{type:"button",disabled:n,"aria-label":t("servers.computerAccessFor",{name:N.name}),onClick:()=>d(N.id),className:"settings-quiet shrink-0 cursor-pointer",children:t("servers.computerAccess")}),It(N)&&e.jsx(mm,{origin:N.origin,name:N.name}),N.id!=="local"&&!N.home&&e.jsx("button",{type:"button",disabled:n,"data-danger":"","aria-label":t("servers.removeName",{name:N.name}),title:t("servers.removeName",{name:N.name}),onClick:()=>l(N.id),className:"settings-quiet shrink-0 cursor-pointer",children:t("remote.devices.removeShort")})]}),k&&e.jsx("div",{className:"pl-11",children:e.jsx(gm,{name:N.name,share:k,busy:n,onShare:P=>u(N.id,P),onOpen:()=>d(N.id)})}),S&&e.jsx("div",{className:"pl-11",children:e.jsx(pm,{name:N.name,status:I,appVersion:r,onHide:()=>f(P=>[...P,`${N.id}:${I.version}`])})})]},N.id)}),e.jsx(ye,{title:t("connect.title"),leading:e.jsx("span",{className:"flex size-8 items-center justify-center rounded-full bg-ink/[0.05] text-ink-secondary",children:e.jsx($e,{size:18,strokeWidth:1.75,"aria-hidden":"true"})}),onClick:()=>{n||j({address:"",locked:!1,title:t("connect.title")})},data:{"data-server-connect":""}})]}),h&&e.jsx(so,{focusKey:h.locked?"pair-again":"connect",onClose:()=>j(null),children:e.jsx(no,{onBack:null,onConnected:()=>j(null),start:h})})]})}function fm({label:s,description:n}={}){const a=Ks(),[i,r]=o.useState(!1),c=window.ogb?.environments,{state:l}=_(),d=Hi(l.config)&&!!window.ogb?.computerSharing,u=window.ogb?.computerSharing,[p,x]=o.useState([]),[m,g]=o.useState(null),[f,h]=o.useState(!1),[j,b]=o.useState(""),[y,v]=o.useState(()=>new URLSearchParams(window.location?.search??"").get("share-computer")),[w,N]=o.useState(""),[C,I]=o.useState(""),[F,k]=o.useState(null),[S,P]=o.useState(!1),[E,A]=o.useState(""),q=o.useRef(!1),R=o.useRef(0);o.useEffect(()=>{const U=++R.current;return c?.state().then(H=>{R.current===U&&g(H)}).catch(()=>{R.current===U&&b(t("servers.loadFailed"))}),()=>{R.current++}},[c]),o.useEffect(()=>{if(!u?.servers||!m)return;let U=!0;const H=()=>{u.servers().then(te=>{U&&x(te)}).catch(()=>{})};H();const Q=setInterval(H,5e3);return()=>{U=!1,clearInterval(Q)}},[u,m]);const K=(U,H)=>{Z(async()=>{H?await u?.allow?.(U)&&v(U):await u?.revoke(U),u?.servers&&x(await u.servers())})};o.useEffect(()=>{const U=H=>{H&&v(H);const Q=new URL(window.location.href);Q.searchParams.delete("share-computer"),window.history.replaceState(null,"",`${Q.pathname}${Q.search}${Q.hash}`)};return U(),c?.onOpenSettings?.(U)},[c]);const Z=async(U,H=b)=>{if(q.current||!c)return;q.current=!0,h(!0),b(""),A("");const Q=R.current;try{if(await U()===!0)return;const te=await c.state();R.current===Q&&g(te)}catch(te){R.current===Q&&H(String(te?.message??te).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,""))}finally{q.current=!1,R.current===Q&&h(!1)}};if(!c)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("servers.desktopOnly")});const oe=U=>window.ogb?.confirm?window.ogb.confirm(U):window.confirm(U),se=m?.environments.find(U=>U.id===y),Y=se?.origin&&!se.home?{id:se.id,name:se.name,origin:se.origin}:void 0,B=!!(Y&&p.some(U=>U.id===Y.id)),W=m?.environments.filter(U=>U.kind==="local")??[],G=W.find(U=>U.id===F),le=U=>U.dataDir?U.name:t("connectedWorkspaces.defaultName");return e.jsxs(e.Fragment,{children:[e.jsxs(J,{label:s,description:n,block:"your-computers",children:[m?e.jsx(hm,{saved:m,busy:f,sharingOffered:d,ownServers:p,appVersion:window.ogb?.app?.version??null,onShare:K,onSwitch:U=>{Z(async()=>(await c.switch(U),!0))},onForget:U=>{Z(()=>c.forget(U))},onComputerAccess:v}):e.jsx(V,{children:e.jsx(L,{title:t(j?"servers.yours.loadFailed":"servers.yours.loading"),children:null})}),m&&j&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] leading-4 text-danger",children:j})]}),a&&m?.packaged&&e.jsxs(J,{label:t("connectedWorkspaces.localTitle"),description:t("connectedWorkspaces.localSubtitle"),block:"environments",children:[e.jsxs(V,{icons:!0,children:[W.map(U=>{const H=U.id===m.activeId,Q=G?.id===U.id;return e.jsxs(o.Fragment,{children:[e.jsx(L,{title:le(U),leading:e.jsx("span",{className:"flex size-8 items-center justify-center rounded-full bg-ink/[0.05] text-ink-secondary",children:e.jsx(at,{size:18,strokeWidth:1.75,"aria-hidden":"true"})}),subtitle:e.jsxs(e.Fragment,{children:[U.dataDir??t("connectedWorkspaces.mainFolder"),U.missing&&e.jsxs(e.Fragment,{children:[" · ",t("connectedWorkspaces.missing")]})]}),children:H?e.jsx("span",{className:"text-[13px] leading-5 text-ink-secondary",children:t("connectedWorkspaces.current")}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:f,"aria-label":t("connectedWorkspaces.switchTo",{name:U.name}),className:"ui-button",onClick:()=>{Z(async()=>{if(!await oe(t("connectedWorkspaces.switchConfirm",{name:U.name})))return;const te=await c.switch(U.id);if(te&&te.ok===!1)throw new Error(t("connectedWorkspaces.switchError"));return!0},A)},children:t("connectedWorkspaces.switch")}),!G&&e.jsx("button",{type:"button",disabled:f,"data-danger":"","aria-label":t("connectedWorkspaces.forgetName",{name:U.name}),className:"settings-quiet cursor-pointer",onClick:()=>{k(U.id),P(!1)},children:t("connectedWorkspaces.forget")})]})}),Q&&G&&e.jsxs("div",{"data-env-forget":"",className:"flex flex-col gap-2 py-3 pl-[60px] pr-4",children:[e.jsxs("span",{className:"flex items-center justify-between gap-6 text-[12px] leading-4 text-ink-secondary",children:[t("connectedWorkspaces.forgetPurge",{path:G.dataDir??""}),e.jsx(ne,{checked:S,disabled:f,"aria-label":t("connectedWorkspaces.forgetPurge",{path:G.dataDir??""}),onClick:()=>P(!S)})]}),e.jsxs("span",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>k(null),className:"ui-button",children:t("connectedWorkspaces.cancel")}),e.jsx("button",{type:"button",disabled:f,"data-danger":"",onClick:()=>{Z(async()=>{const te=S?await c.forget(G.id,!0):await c.forget(G.id);if(te&&te.ok===!1)throw new Error(t("connectedWorkspaces.forgetError"));k(null)},A)},className:"ui-button !bg-danger !text-danger-ink",children:t("connectedWorkspaces.forget")})]})]})]},U.id)}),e.jsx(Qt,{id:"new-environment",title:t("connectedWorkspaces.newEnvironment"),open:i,onToggle:()=>r(!i),leading:e.jsx("span",{"aria-hidden":"true",className:"flex size-8 items-center justify-center rounded-full bg-ink/[0.05] text-ink-secondary",children:e.jsx($e,{size:18,strokeWidth:1.75})}),children:e.jsxs("form",{className:"flex flex-col gap-3 py-3 pl-[60px] pr-4",onSubmit:U=>{U.preventDefault(),w.trim()&&Z(async()=>{if(!(await c.create(w.trim(),C.trim()||void 0))?.ok)throw new Error(t("connectedWorkspaces.createError"));N(""),I("")},A)},children:[e.jsx(ge,{label:t("connectedWorkspaces.name"),children:e.jsx("input",{required:!0,value:w,disabled:f,maxLength:60,onChange:U=>N(U.target.value),placeholder:t("connectedWorkspaces.environmentPlaceholder"),className:xe})}),e.jsx(ge,{label:t("connectedWorkspaces.dataFolder"),children:e.jsxs("span",{className:"flex gap-2",children:[e.jsx("input",{value:C,disabled:f,onChange:U=>I(U.target.value),placeholder:t("connectedWorkspaces.defaultFolder"),className:xe}),e.jsx("button",{type:"button",disabled:f,className:"ui-button shrink-0 self-center",onClick:()=>{Z(async()=>{const U=await c.pickDir();U?.ok&&U.path&&I(U.path)},A)},children:t("connectedWorkspaces.choose")})]})}),e.jsxs("button",{type:"submit",disabled:f||!w.trim(),className:"ui-button gap-2 self-end",children:[f&&e.jsx(re,{size:14,className:"animate-spin"}),t("connectedWorkspaces.create")]})]})})]}),E&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] leading-4 text-danger",children:E})]}),(d||B)&&Y&&e.jsx(om,{workspace:Y,own:B,onClose:()=>v(null)},Y.id)]})}const Tr=s=>({method:"PUT",body:JSON.stringify(s)}),Gt=s=>s instanceof Error?s.message:String(s);function bm(){return o.useSyncExternalStore(or,()=>lu()?.id??null,()=>null)}function vm(s,n){const a=URL.createObjectURL(new Blob([JSON.stringify(n,null,2)],{type:"application/json"}));Object.assign(document.createElement("a"),{href:a,download:s}).click(),setTimeout(()=>URL.revokeObjectURL(a),1e3)}function ym({id:s,act:n,onClose:a,onDelete:i}){const[r,c]=o.useState(null),[l,d]=o.useState(null),[u,p]=o.useState(!1);if(o.useEffect(()=>{M(`/api/themes/${s}`).then(g=>c(g.theme),g=>d(Gt(g)))},[s]),!r)return e.jsx(Ne,{children:l??t("settings.customThemes.loading")});const x=r.css?ou(r.css):null,m=async()=>{p(!0);try{await M(`/api/themes/${s}`,Tr({theme:{...r,name:r.name.trim(),css:r.css||void 0}})),d(t("settings.customThemes.saved")),await nn()}catch(g){d(Gt(g))}finally{p(!1)}};return e.jsxs("div",{"data-settings-block":"theme-editor",className:"flex flex-col gap-3 px-4 py-3",children:[e.jsx(ge,{label:t("settings.customThemes.name"),children:e.jsx("input",{className:xe,value:r.name,maxLength:60,onChange:g=>c({...r,name:g.target.value})})}),e.jsx("div",{className:"flex flex-wrap gap-4",children:["canvas","accent"].map(g=>e.jsxs("label",{className:"flex items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"color",className:"size-7 cursor-pointer rounded-md bg-transparent",value:r[g]??(g==="canvas"?"#121212":"#1084fe"),onChange:f=>c({...r,[g]:f.target.value})}),t(g==="canvas"?"settings.customThemes.canvas":"settings.customThemes.accent"),r[g]&&e.jsx("button",{type:"button",className:"text-[12px] text-accent-text hover:underline",onClick:()=>c({...r,[g]:void 0}),children:t("settings.customThemes.clear")})]},g))}),e.jsx(ge,{label:t("settings.customThemes.css"),hint:x??t("settings.customThemes.cssHint"),children:e.jsx("textarea",{className:`${xe} h-64 resize-y py-2 font-mono text-[12px]`,spellCheck:!1,maxLength:cu.cssChars,"aria-label":t("settings.customThemes.css"),value:r.css??"",onChange:g=>c({...r,css:g.target.value})})}),e.jsxs(es,{status:l,children:[e.jsxs("div",{className:"mr-auto flex flex-wrap gap-1.5",children:[e.jsx("button",{type:"button",className:"ui-button ui-button-sm",onClick:()=>{n(()=>M(`/api/themes/${s}/duplicate`,{method:"POST",body:JSON.stringify({name:t("settings.customThemes.copyName",{name:r.name}).slice(0,60)})}))},children:t("settings.customThemes.duplicate")}),e.jsx("button",{type:"button",className:"ui-button ui-button-sm",onClick:()=>{n(async()=>vm(`${s}.mausbot-theme.json`,await M(`/api/themes/${s}/export`)))},children:t("settings.customThemes.export")}),e.jsx("button",{type:"button",className:"ui-button ui-button-sm","data-danger":"",onClick:i,children:t("common.delete")})]}),e.jsx("button",{type:"button",className:"ui-button",onClick:a,children:t("common.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary",disabled:u||!!x||!r.name.trim(),onClick:()=>{m()},children:t("common.save")})]})]})}const jm=6;function km(s){const n=s.name??"";switch(s.kind){case"made":return t("settings.customThemes.historyMade",{name:n});case"edited":return t("settings.customThemes.historyEdited",{name:n});case"deleted":return t("settings.customThemes.historyDeleted",{name:n});case"wore":return t("settings.customThemes.historyWore",{name:n});case"skin":return t("settings.customThemes.historySkin",{name:ft.find(a=>a.id===n)?.name??n});case"default":return t("settings.customThemes.historyDefault");case"undid":return t("settings.customThemes.historyUndid")}}function wm({items:s,act:n}){return s.length<2?null:e.jsx(J,{label:t("settings.customThemes.history"),block:"theme-history",description:t("settings.customThemes.historyHint"),children:e.jsx(V,{children:s.slice(0,jm).map(a=>e.jsx(L,{title:km(a),subtitle:ur(Date.parse(a.at)),children:a.index===1?e.jsx("span",{className:"text-[12px] text-ink-tertiary",children:t("settings.customThemes.historyNow")}):e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{n(async()=>{await M("/api/themes/history",{method:"POST",body:JSON.stringify({index:a.index})}),await nn()})},children:t("settings.customThemes.restore")})},a.index))})})}function Nm(){const[s,n]=o.useState(null),[a,i]=o.useState(null),[r,c]=o.useState(null),l=o.useRef(null),d=bm(),[u,p]=o.useState([]),x=o.useCallback(()=>Promise.all([M("/api/themes").then(n,b=>c(Gt(b))),M("/api/themes/history").then(b=>p(b.items),()=>p([]))]),[]);o.useEffect(()=>(x(),or(()=>{x()})),[x]);const m=async b=>{c(null);try{await b()}catch(y){c(Gt(y))}await x()},g=()=>m(async()=>{const b=`theme-${Date.now().toString(36)}`;await M(`/api/themes/${b}`,Tr({theme:{name:t("settings.customThemes.newName")}})),i(b)}),f=b=>b&&m(async()=>{let y;try{y=JSON.parse(await b.text())}catch{throw new Error(t("settings.customThemes.importFailed"))}await M("/api/themes/import",{method:"POST",body:JSON.stringify(y)})}),h=(b,y)=>m(async()=>{const v=await M(`/api/themes/${b}/export`);await M(`/api/themes/${b}`,{method:"DELETE"}),i(null),await nn(),c(e.jsxs(e.Fragment,{children:[t("settings.customThemes.deleted",{name:y})," ",e.jsx("button",{type:"button",className:"text-accent-text hover:underline",onClick:()=>{m(()=>M("/api/themes/import",{method:"POST",body:JSON.stringify(v)}))},children:t("common.undo")})]}))}),j=dr()?"⌘⌥⇧R":"Ctrl+Alt+Shift+R";return e.jsxs(e.Fragment,{children:[e.jsx(J,{label:t("settings.customThemes.title"),block:"custom-themes",description:t("settings.customThemes.description"),actions:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"ui-button",onClick:()=>l.current?.click(),children:t("settings.customThemes.import")}),e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{g()},children:t("settings.customThemes.new")}),e.jsx("input",{ref:l,type:"file",accept:"application/json,.json",hidden:!0,onChange:b=>{f(b.target.files?.[0]),b.target.value=""}})]}),footnote:r,children:e.jsxs(V,{children:[iu()&&e.jsx(Ne,{children:t("settings.customThemes.safe")}),s&&!s.themes.length&&e.jsx(Ne,{children:t("settings.customThemes.empty")}),s?.themes.map(b=>a===b.id?e.jsx(ym,{id:b.id,act:m,onClose:()=>{i(null),x()},onDelete:()=>{h(b.id,b.name)}},b.id):e.jsx(L,{title:b.name,subtitle:d===b.id?t("settings.customThemes.inUse"):b.assets.length?t("settings.customThemes.files",{count:b.assets.length}):void 0,children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",className:"ui-button",onClick:()=>i(b.id),children:t("settings.customThemes.edit")}),d===b.id?e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{m(()=>ia(null))},children:t("settings.customThemes.takeOff")}):e.jsx("button",{type:"button",className:"ui-button ui-button-primary",onClick:()=>{m(()=>ia(b.id))},children:t("settings.customThemes.use")})]})},b.id)),e.jsx(L,{title:t("settings.customThemes.reset"),subtitle:t("settings.customThemes.resetHint",{keys:j}),children:e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{ru(),x()},children:t("settings.customThemes.reset")})})]})}),e.jsx(wm,{items:u,act:m})]})}function Sm({simple:s=!1}){const[n,a]=o.useState(!1),[i,r]=o.useState(null),[c,l]=o.useState(null),d=async()=>{if(!(!window.ogb?.exportDiagnostics||n)){a(!0),r(null);try{const x=await window.ogb.exportDiagnostics();x&&r({kind:"success",message:t("settings.diagnostics.saved",{path:x})})}catch(x){r({kind:"error",message:x instanceof Error?x.message:String(x)})}finally{a(!1)}}},u=async()=>{if(window.ogb?.openLogsFolder){r(null);try{const x=await window.ogb.openLogsFolder();l(x.folder),x.opened||r({kind:"error",message:t("settings.diagnostics.openFailed",{folder:x.folder})})}catch(x){r({kind:"error",message:x instanceof Error?x.message:String(x)})}}},p=!!window.ogb?.exportDiagnostics;return e.jsx(L,{title:t("settings.app.diagnostics"),subtitle:e.jsxs(e.Fragment,{children:[t(s?"settings.simple.diagnostics":"settings.diagnostics.subtitle"),p&&window.ogb?.openLogsFolder&&e.jsxs(e.Fragment,{children:[" ",e.jsx(Ke,{label:t("settings.diagnostics.openLogs"),onClick:()=>{u()}})]})]}),message:c||i||!p?e.jsxs(e.Fragment,{children:[c&&i?.kind!=="error"&&e.jsx("p",{role:"status","data-logs-folder":!0,className:"break-all text-ink-secondary",children:t("settings.diagnostics.logsAt",{folder:c})}),i&&e.jsx("p",{role:i.kind==="error"?"alert":"status",className:D("break-all",i.kind==="error"?"text-danger":"text-success"),children:i.message}),!p&&e.jsx("p",{"data-logs-help":!0,className:"text-ink-secondary",children:t("settings.diagnostics.elsewhere")})]}):void 0,children:p&&e.jsx("button",{type:"button",onClick:()=>{d()},disabled:n,"aria-label":t("settings.diagnostics.aria"),className:"ui-button",children:n?t("settings.diagnostics.exporting"):t("settings.diagnostics.export")})})}function Ir({simple:s=!1}){return e.jsxs(e.Fragment,{children:[e.jsx(Cm,{simple:s}),e.jsx(Em,{simple:s}),e.jsx(Am,{simple:s})]})}const ja=()=>typeof Notification<"u"?Notification.permission:"default";function Cm({simple:s=!1}){const[n,a]=o.useState(ja),i=dc();if(o.useEffect(()=>{const l=()=>{document.visibilityState==="visible"&&a(ja())};return window.addEventListener("focus",l),document.addEventListener("visibilitychange",l),()=>{window.removeEventListener("focus",l),document.removeEventListener("visibilitychange",l)}},[]),typeof Notification>"u")return null;const r=n==="denied",c=async()=>{if(n==="granted")return $n(!i);const l=await gc();l&&(a(l),l==="granted"&&$n(!0))};return e.jsx(L,{title:t("settings.deviceNotifications.title"),subtitle:t(r?"settings.deviceNotifications.blocked":s?"settings.simple.deviceNotifications":"settings.deviceNotifications.subtitle"),children:e.jsx(ne,{checked:n==="granted"&&i,disabled:r,"aria-label":t("settings.deviceNotifications.show"),onClick:()=>{c()}})})}function Em({simple:s=!1}){const n=uc();return e.jsx(L,{title:t("settings.notificationSounds.title"),subtitle:t(s?"settings.simple.notificationSounds":"settings.notificationSounds.subtitle"),children:e.jsx(ne,{checked:n,"aria-label":t("settings.notificationSounds.play"),onClick:()=>pc(!n)})})}function Am({simple:s=!1}){const n=mc();return e.jsx(L,{title:t("settings.notificationFeed.title"),subtitle:t(s?"settings.simple.notificationFeed":"settings.notificationFeed.subtitle"),children:e.jsx(ne,{checked:n,"aria-label":t("settings.notificationFeed.show"),onClick:()=>xc(!n)})})}function Pm({simple:s=!1}){const n=window.ogb?.openAtLogin,[a,i]=o.useState(null),[r,c]=o.useState(!1),[l,d]=o.useState(!1);if(o.useEffect(()=>{let p=!0;return n?.state().then(x=>{p&&i(x)}).catch(()=>{}),()=>{p=!1}},[n]),!n||!a)return null;if(a.startupApps)return e.jsx(L,{title:t("settings.openAtLogin.title"),subtitle:t("settings.openAtLogin.startupApps"),children:null});if(!a.available)return null;const u=p=>{c(!0),d(!1),n.set(p).then(i,()=>d(!0)).finally(()=>c(!1))};return e.jsx(L,{title:t("settings.openAtLogin.title"),subtitle:t(s?"settings.simple.openAtLogin":"settings.openAtLogin.subtitle"),message:l?e.jsx("span",{role:"alert",className:"text-danger",children:t("settings.openAtLogin.failed")}):void 0,children:e.jsx(ne,{checked:a.on,disabled:r,"aria-label":t("settings.openAtLogin.title"),onClick:()=>u(!a.on)})})}function Tm(){const s=Hl(),[n,a]=o.useState(""),[i,r]=o.useState(""),[c,l]=o.useState(""),d=s.length>=Pn,[u,p]=o.useState(!1),x=()=>{const g=$l({name:n,url:i},window.location.origin);return g.ok?(Tn([...s,{id:Kl(s),name:g.name,url:g.url}]),a(""),r(""),l(""),!0):(l(g.error),!1)},m=()=>{p(!1),a(""),r(""),l("")};return e.jsxs(J,{label:t("webPanels.settings.title"),block:"pinned-panels",description:t("webPanels.settings.short"),actions:e.jsx("button",{type:"button",className:"ui-button",disabled:d,onClick:()=>p(!0),children:t("webPanels.settings.addPage")}),footnote:d?t("webPanels.settings.full",{max:Pn}):t("webPanels.settings.help"),children:[e.jsxs(V,{children:[s.length===0&&e.jsx(Ne,{children:t("webPanels.settings.empty")}),s.map(g=>e.jsx(L,{title:g.name,subtitle:e.jsx("span",{className:"block truncate",title:g.url,children:g.url??t("webPanels.settings.chatPage")}),children:e.jsx("button",{type:"button","data-danger":"",className:"settings-quiet cursor-pointer",onClick:()=>Tn(s.filter(f=>f.id!==g.id)),children:t("webPanels.settings.remove")})},g.id))]}),u&&e.jsxs(Nt,{title:t("webPanels.settings.addPage"),onClose:m,footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"ui-button",onClick:m,children:t("common.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary",disabled:d,onClick:()=>{x()&&m()},children:t("webPanels.settings.add")})]}),children:[e.jsx(ge,{label:t("webPanels.settings.name"),children:e.jsx("input",{value:n,maxLength:In,"aria-invalid":c==="name",onChange:g=>{a(g.target.value),l("")},className:D(xe,c==="name"&&"border-danger/60")})}),e.jsx(ge,{label:t("webPanels.settings.url"),children:e.jsx("input",{placeholder:"https://",type:"url",inputMode:"url",value:i,"aria-invalid":c==="url"||c==="self",onChange:g=>{r(g.target.value),l("")},onKeyDown:g=>{g.key==="Enter"&&x()&&m()},className:D(xe,(c==="url"||c==="self")&&"border-danger/60")})}),c&&e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:t(c==="name"?"webPanels.settings.nameInvalid":c==="self"?"webPanels.settings.urlSelf":"webPanels.settings.urlInvalid",{max:In})})]})]})}const gs="w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink placeholder:text-ink-secondary focus:outline-none";function ka(s){return String(s?.message??s).replace(/^Error invoking remote method '[^']*':\s*(?:Error:\s*)?/,"")}function Im(s){const n=s.trim();if(!/^https?:\/\//i.test(n))return!1;const a=Wl(n);return a.ok&&(a.code!==null||a.credential!==null)}function Lm({hideWhenUnavailable:s=!1,legacyOnly:n=!1}){const a=window.ogb?.remoteClient,i=window.ogb?.environments,[r,c]=o.useState({active:a?.active===!0}),[l,d]=o.useState(i?"server":"companion"),[u,p]=o.useState(""),[x,m]=o.useState(""),[g,f]=o.useState(""),[h,j]=o.useState(!1),[b,y]=o.useState(""),v=o.useRef(!1),w=!!i&&l==="server",N=o.useRef(!0),C=o.useCallback(()=>{a?.state().then(k=>{N.current&&c(k)}).catch(()=>{})},[a]);o.useEffect(()=>(N.current=!0,C(),()=>{N.current=!1}),[C]);const I=async()=>{if(!(v.current||!a&&!i)){v.current=!0,j(!0),y("");try{if(w&&i){if(!Im(u))throw new Error(t("remote.client.server.invalidLink"));await i.addFromLink(u.trim()),C()}else a&&(await a.pair(x,g),C())}catch(k){y(ka(k))}finally{v.current=!1,j(!1)}}},F=async()=>{if(!(!a||v.current)){v.current=!0,j(!0),y("");try{await a.disconnect(),C()}catch(k){y(ka(k))}finally{v.current=!1,j(!1)}}};return!a&&!i&&s||n&&!r.active?null:e.jsxs(pe,{title:r.active?t("remote.client.active"):t("remote.client.idle"),subtitle:t("remote.client.subtitle"),children:[!a&&!i?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("remote.client.desktopOnly")}):r.active?e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-success/25 bg-success/10 px-3 py-3",children:[e.jsx(at,{size:18,className:"mt-0.5 shrink-0 text-success"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[14px] font-medium text-ink",children:t("remote.client.connected",{name:r.serverName||t("remote.client.fallbackName")})}),e.jsx("div",{className:"mt-1 break-all text-[12px] text-ink-secondary",children:r.endpoint})]})]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("remote.client.mode")}),e.jsx("p",{role:"status",className:"rounded-lg bg-inset px-3 py-2 text-[13px] leading-relaxed text-ink","data-legacy-client-notice":"",children:t("remote.client.endsDec7")}),e.jsxs("button",{type:"button",disabled:h,onClick:()=>{F()},className:"flex w-fit items-center gap-2 rounded-lg border border-danger/30 px-3 py-2 text-[13px] text-danger hover:bg-danger/10 disabled:opacity-50",children:[h?e.jsx(re,{size:14,className:"animate-spin"}):e.jsx(Su,{size:14}),t("remote.client.disconnect")]})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:k=>{k.preventDefault(),I()},children:[i&&a?e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("remote.client.connectionType"),e.jsxs(ce,{value:l,disabled:h,onChange:k=>{d(k.target.value),y("")},className:"w-full",children:[e.jsx("option",{value:"server",children:t("remote.client.server.option")}),e.jsx("option",{value:"companion",children:t("remote.client.companion.option")})]})]}):null,w?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("remote.client.server.hint")}),e.jsxs("div",{"data-pair-access":"full",className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink",children:t("remote.client.server.fullTitle")}),e.jsx("code",{className:"select-all rounded-lg bg-inset px-3 py-2 text-[12px] text-ink",children:"npx @seira-bot/seira pair"})]}),e.jsxs("div",{"data-pair-access":"client",className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink",children:t("remote.client.server.clientTitle")}),e.jsx("code",{className:"select-all rounded-lg bg-inset px-3 py-2 text-[12px] text-ink",children:"npx @seira-bot/seira pair --client"}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("remote.client.server.clientNote")})]}),e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("remote.client.server.pairingLink"),e.jsx("input",{value:u,onChange:k=>p(k.target.value),placeholder:"https://bots.example.com/pair#code=XXXX-XXXX-XXXX",disabled:h,autoCapitalize:"none",autoCorrect:"off",autoComplete:"off",spellCheck:!1,className:gs})]}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("remote.client.server.domainHint")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("remote.client.companion.hint")}),e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("remote.client.companion.address"),e.jsx("input",{value:x,onChange:k=>m(k.target.value),placeholder:"https://…openmausbot.com or computer.tailnet.ts.net",disabled:h,autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,className:gs})]}),e.jsxs("label",{className:"flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[t("remote.client.companion.code"),e.jsx("input",{value:g,onChange:k=>f(k.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"000000",disabled:h,inputMode:"numeric",autoComplete:"one-time-code",className:`${gs} max-w-40 font-mono tracking-[0.2em]`})]})]}),b?e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:b}):null,e.jsxs("button",{type:"submit",disabled:h||(w?!u.trim():x.trim()===""||g.length!==6),className:"flex w-fit items-center gap-2 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-white hover:brightness-110 disabled:opacity-50",children:[h?e.jsx(re,{size:14,className:"animate-spin"}):e.jsx(at,{size:14}),w?t("remote.client.server.connect"):t("remote.client.pair")]}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:w?t("remote.client.server.switchNote"):t("remote.client.restartNote")})]}),r.active&&b?e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:b}):null]})}const wa=[{choice:"system",label:"settings.theme.system"},{choice:Ln.light,label:"settings.theme.light"},{choice:Ln.dark,label:"settings.theme.dark"}];function un(){return o.useSyncExternalStore(ql,Rn,Rn)}function Rm({simple:s=!1}){const n=un(),a=wa.some(i=>i.choice===n)?void 0:ft.find(i=>i.id===n)?.name;return e.jsx(L,{title:t(s?"settings.theme.lightOrDark":"settings.theme.title"),subtitle:a?t("settings.theme.look",{name:a}):s?void 0:t("settings.theme.subtitle"),children:e.jsx("div",{role:"radiogroup","aria-label":t(s?"settings.theme.lightOrDark":"settings.theme.title"),className:s?"inline-flex h-7 rounded-full bg-ink/[0.06] p-0.5":"inline-flex rounded-full bg-inset p-0.5",children:wa.map(i=>e.jsx("button",{type:"button",role:"radio","aria-checked":n===i.choice,onClick:()=>Gl(i.choice),className:s?D("h-6 rounded-full px-2.5 text-[13px] transition-colors",n===i.choice?"bg-ink/[0.12] text-ink":"text-ink-secondary hover:text-ink"):D("rounded-full px-3 py-1 text-[13px] font-medium transition-colors",n===i.choice?"bg-raised text-ink shadow-sm":"text-ink-secondary hover:text-ink"),children:t(s&&i.choice==="system"?"settings.simple.theme.system":i.label)},i.choice))})})}function Na({skin:s}){return e.jsxs("div",{"data-skin":s,"data-skin-preview":"","aria-hidden":"true",className:"flex h-[78px] w-full overflow-hidden rounded-lg bg-app ring-1 ring-hairline/60",children:[e.jsxs("div",{className:"flex w-[11px] shrink-0 flex-col items-center gap-[3px] bg-panel pt-[5px]",children:[e.jsx("span",{className:"size-[5px] rounded-full bg-accent"}),e.jsx("span",{className:"size-[5px] rounded-full bg-ink-secondary/40"}),e.jsx("span",{className:"size-[5px] rounded-full bg-ink-secondary/40"})]}),e.jsxs("div",{className:"flex w-[30px] shrink-0 flex-col gap-[3px] border-r border-hairline bg-panel p-[4px]",children:[e.jsxs("span",{className:"flex h-[9px] w-full items-center gap-[2px] rounded-sm bg-raised px-[2px]",children:[e.jsx("span",{className:"size-[4px] shrink-0 rounded-full bg-accent"}),e.jsx("span",{className:"h-[2px] flex-1 rounded-full bg-ink/50"})]}),e.jsx("span",{className:"h-[3px] w-[80%] rounded-full bg-ink-secondary/30"}),e.jsx("span",{className:"h-[3px] w-[62%] rounded-full bg-ink-secondary/30"}),e.jsx("span",{className:"h-[3px] w-[74%] rounded-full bg-ink-secondary/30"})]}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-[4px] p-[6px]",children:[e.jsx("span",{className:"h-[13px] w-[62%] self-end rounded-md bg-bubble-user"}),e.jsxs("div",{className:"flex w-[88%] flex-col gap-[3px] rounded-md bg-card p-[4px]",children:[e.jsx("span",{className:"h-[2px] w-full rounded-full bg-ink/45"}),e.jsx("span",{className:"h-[2px] w-[85%] rounded-full bg-ink/45"}),e.jsx("span",{className:"h-[2px] w-[60%] rounded-full bg-ink-secondary/40"})]}),e.jsxs("div",{className:"mt-auto flex items-center gap-[4px]",children:[e.jsx("span",{className:"h-[11px] flex-1 rounded-full bg-inset ring-1 ring-hairline"}),e.jsx("span",{className:"flex size-[11px] items-center justify-center rounded-full bg-accent",children:e.jsx("span",{className:"h-[1.5px] w-[5px] rounded-full",style:{background:"var(--color-accent-ink)"}})})]})]})]})}function Bm(){const s=Si(un());return o.useContext(Ae)?e.jsx(e.Fragment,{children:e.jsx("div",{className:"grid grid-cols-2 gap-x-3 gap-y-4 sm:grid-cols-4",role:"radiogroup","aria-label":t("settings.theme.title"),children:ft.map(a=>{const i=a.id===s;return e.jsxs("button",{type:"button",role:"radio","aria-checked":i,onClick:()=>{On(a.id),ra()},title:Bn(`skins.tagline.${a.id}`,a.tagline),className:"group flex cursor-pointer flex-col gap-2 rounded-lg text-left focus-visible:outline-none",children:[e.jsxs("span",{className:D("relative block rounded-lg ring-offset-2 ring-offset-(--color-menu) [&>[data-skin-preview]]:h-20 [&>[data-skin-preview]]:ring-0","after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] after:shadow-[inset_0_0_0_0.5px_var(--settings-edge)] after:content-['']",i?"ring-2 ring-ink":"group-hover:ring-[0.5px] group-hover:ring-ink/25 group-focus-visible:ring-2 group-focus-visible:ring-focus"),children:[e.jsx(Na,{skin:a.id}),i&&e.jsx("span",{"aria-hidden":"true","data-skin-check":"",className:"absolute -right-2 -top-2 flex size-4 items-center justify-center rounded-full bg-ink text-app",children:e.jsx(_e,{size:12,strokeWidth:2.5})})]}),e.jsx("span",{className:"truncate text-[13px] leading-[18px] text-ink",children:a.name})]},a.id)})})}):e.jsx(e.Fragment,{children:e.jsx("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:ft.map(a=>{const i=a.id===s;return e.jsxs("button",{type:"button",onClick:()=>{On(a.id),ra()},"aria-pressed":i,className:D("cursor-pointer flex flex-col gap-2 rounded-xl border p-2 text-left transition-colors",i?"border-accent-border bg-control":"border-hairline/60 hover:border-hairline hover:bg-control/50"),children:[e.jsx(Na,{skin:a.id}),e.jsxs("div",{className:"flex items-start gap-1.5 px-0.5 pb-0.5",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:a.name}),e.jsx("div",{className:"mt-0.5 text-[11px] leading-snug text-ink-secondary",children:Bn(`skins.tagline.${a.id}`,a.tagline)})]}),i&&e.jsx(_e,{size:13,className:"mt-0.5 shrink-0 text-accent-text"})]})]},a.id)})})})}function Om(){const s=window.ogb?.talkShortcut,[n,a]=o.useState(null),[i,r]=o.useState(!1),[c,l]=o.useState(!1);if(o.useEffect(()=>{let m=!0;return s?.state().then(g=>{m&&a(g)}).catch(()=>{}),()=>{m=!1}},[s]),!s||!n?.available)return null;const d=n.keys.find(m=>m.id===n.key)?.label??"",u=m=>{r(!0),l(!1),s.set(m).then(a,()=>l(!0)).finally(()=>r(!1))},p=c?t("settings.talk.failed"):n.enabled&&n.taken?t("settings.talk.taken",{key:d}):null,x=e.jsxs(e.Fragment,{children:[n.enabled&&e.jsx(ce,{size:"sm",className:"w-full max-w-[240px]",value:n.key,disabled:i,"aria-label":t("settings.talk.keyAria"),onChange:m=>u({key:m.target.value}),children:n.keys.map(m=>e.jsx("option",{value:m.id,children:m.label},m.id))}),p&&e.jsx("div",{role:"alert",className:n.enabled?"mt-2 text-danger":"text-danger",children:p})]});return e.jsx(L,{title:t("settings.talk.title"),subtitle:t("settings.talk.subtitle",{key:d}),message:n.enabled||p?x:null,children:e.jsx(ne,{checked:n.enabled,disabled:i,"aria-label":t("settings.talk.aria"),onClick:()=>u({enabled:!n.enabled})})})}function Fm(){const{capabilities:s}=Li(),n=typeof window>"u"?void 0:window.ogb?.windowFrame,[a,i]=o.useState(null);o.useEffect(()=>{if(!n)return;let d=!0;return n.state().then(u=>{d&&i(u)}).catch(()=>{}),()=>{d=!1}},[n]);const r=s.host?.platform;if(!n||!a||r!=="darwin"&&r!=="win32")return null;const c=window.ogb?.relaunch,l=()=>{n.set(!a.on).then(i).catch(()=>{})};return e.jsxs("div",{"data-window-frame-switch":!0,children:[e.jsx(L,{title:t("settings.windowFrame.title"),subtitle:t("settings.windowFrame.subtitle"),children:e.jsx(ne,{checked:a.on,"aria-label":t("settings.windowFrame.title"),onClick:l})}),a.restart&&e.jsxs("div",{role:"status","data-window-frame-restart":!0,className:"flex flex-wrap items-center gap-x-3 gap-y-1 px-4 pb-3 text-[13px] text-ink-secondary",children:[e.jsx("span",{children:t("settings.windowFrame.restart",{app:je()})}),c&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{c().catch(()=>{})},children:t("settings.windowFrame.restartNow")})]})]})}const Um=(s,n)=>n.desktop&&!n.client&&!n.here&&!n.home&&!s;function Mm(){const{ctx:s}=we(),{dispatch:n}=_(),[a,i]=o.useState(!1),r=s.desktop&&!s.client,c=Et(),l=$t(Ht());return e.jsxs(e.Fragment,{children:[s.desktop&&e.jsx(J,{label:t("settings.updates.title"),block:"updates",children:e.jsx(V,{children:window.ogb?.updater?e.jsx(Kp,{title:l}):s.home||s.client?e.jsx(L,{title:l,subtitle:t("settings.updates.fromPackage"),children:null}):e.jsx(ct,{title:l,reason:t("settings.inert.checkFromHere",{place:c.name}),control:e.jsx("button",{type:"button",className:"ui-button",tabIndex:-1,children:t("settings.updates.check")})})})}),!s.advanced&&e.jsx(J,{label:t("settings.app.languageNotifications"),block:"typing",children:e.jsxs(V,{selectWidth:208,children:[e.jsx(Pr,{simple:!0}),e.jsx(Ir,{simple:!0})]})}),s.desktop&&s.advanced&&(window.ogb?.environments?e.jsx(fm,{label:t("settings.app.computers"),description:t("settings.app.computersLine")}):!s.client&&e.jsx(Dm,{})),s.desktop&&s.advanced&&e.jsx(Lm,{hideWhenUnavailable:!0,legacyOnly:!0}),e.jsx(J,{label:t("sidebar.menu.helpShort"),block:"help",children:e.jsxs(V,{children:[e.jsx(ye,{title:t("sidebar.menu.help"),external:!0,onClick:()=>{Ps(wi)}}),s.advanced&&e.jsx(ye,{title:t("sidebar.menu.feedback"),external:!0,onClick:()=>{Ps(Vl)}}),s.advanced&&e.jsx(ye,{title:t("sidebar.menu.shortcuts"),onClick:()=>{n({type:"toggleAppSettings",open:!1}),n({type:"toggleShortcuts",open:!0})}}),s.advanced&&!s.client&&e.jsx(Jp,{}),r&&s.advanced&&(window.ogb?.exportDiagnostics?e.jsx(Sm,{simple:!0}):e.jsx(ct,{title:t("settings.app.diagnostics"),control:e.jsx("button",{type:"button",className:"ui-button",tabIndex:-1,children:t("settings.diagnostics.export")})})),e.jsx("div",{"data-settings-block":"about",className:"contents",children:e.jsx(ye,{title:t("settings.app.about",{app:je()}),onClick:()=>i(!0)})})]})}),e.jsx(fc,{open:a,onClose:()=>i(!1)})]})}function Dm(){const{place:s}=we(),n=Ct("app"),a=window.ogb?.workspaces;return a?e.jsxs(e.Fragment,{children:[e.jsx(J,{label:t("settings.app.computers"),description:t("settings.app.computersLine"),block:"your-computers",children:e.jsxs(V,{icons:!0,children:[e.jsx(L,{title:s.name,leading:e.jsx(De,{place:s,size:24}),subtitle:t("servers.managed"),children:e.jsx("span",{className:"text-[13px] leading-5 text-ink-secondary",children:t("servers.current")})}),n.map(i=>e.jsx(L,{title:i.name,leading:e.jsx(De,{place:{kind:i.kind==="computer"?"computer":"cloud",name:i.name,color:i.color},size:24}),subtitle:i.kind==="computer"?t("servers.localHint"):void 0,children:e.jsx("button",{type:"button",className:"ui-button","data-place-switch":i.key,onClick:i.open,children:t("servers.switch")})},i.key)),a.add&&e.jsx(ye,{title:t("connect.title"),leading:e.jsx("span",{className:"flex size-8 items-center justify-center rounded-full bg-ink/[0.05] text-ink-secondary",children:e.jsx($e,{size:18,strokeWidth:1.75,"aria-hidden":"true"})}),onClick:()=>{a.add?.("address")},data:{"data-server-connect":""}})]})}),e.jsx(J,{label:t("connectedWorkspaces.localTitle"),block:"environments",children:e.jsx(V,{children:e.jsx(ct,{title:t("connectedWorkspaces.newEnvironment")})})})]}):null}function zm(){const{ctx:s,place:n,go:a}=we();return e.jsxs(e.Fragment,{children:[e.jsx(J,{label:t("settings.simple.group.typing"),block:"typing",children:e.jsxs(V,{selectWidth:208,children:[e.jsx(Pr,{simple:!0}),e.jsx(Yp,{simple:!0}),e.jsx(Xp,{simple:!0}),window.ogb?.talkShortcut?e.jsx(Om,{}):Um(window.ogb?.talkShortcut,s)&&s.cloud?e.jsx(ct,{title:t("settings.search.talk"),control:e.jsx("span",{className:"text-[13px] leading-5 text-ink-secondary",children:t("settings.general.talkOff")})}):null]})}),e.jsx(J,{label:t("notifications.title"),block:"notifications",footnote:!s.client&&e.jsxs(e.Fragment,{children:[t("settings.general.awayEmails")," ",e.jsx("button",{type:"button",className:"cursor-pointer text-accent-text hover:underline",onClick:()=>a("bots","about-you"),children:`${n.name} › ${t("settings.page.bots")}`})]}),children:e.jsx(V,{children:e.jsx(Ir,{simple:!0})})}),s.desktop&&!s.client&&e.jsx(J,{label:t("settings.general.startup"),block:"startup",children:e.jsx(V,{children:window.ogb?.openAtLogin?e.jsx(Pm,{simple:!0}):e.jsx(ct,{title:t("settings.openAtLogin.title"),control:e.jsx(ne,{checked:!1,tabIndex:-1,"aria-label":t("settings.openAtLogin.title")})})})}),e.jsx(J,{label:t("settings.general.privacy"),block:"privacy",children:e.jsx(V,{children:e.jsx(Tp,{simple:!0})})})]})}function _m({open:s,onToggle:n}){const a=un(),i=ft.find(r=>r.id===Si(a))?.name;return e.jsx(L,{title:t("settings.theme.title"),subtitle:a==="system"?t("settings.simple.themes.followHint"):i,children:e.jsx("button",{type:"button",className:"ui-button","aria-expanded":s,"data-settings-themes":"",onClick:n,children:t(s?"settings.appearance.hideThemes":"settings.simple.themes.browse")})})}function Hm(){const{ctx:s,place:n,go:a,anchor:i}=we(),[r,c]=o.useState(i==="themes");return e.jsxs(e.Fragment,{children:[e.jsx(J,{label:t("settings.appearance.look"),block:"look",children:e.jsxs(V,{children:[e.jsx(Rm,{simple:!0}),e.jsx(_m,{open:r,onToggle:()=>c(l=>!l)}),r&&e.jsx("div",{"data-settings-block":"themes",className:"p-4",children:e.jsx(Bm,{})}),e.jsx(Qp,{simple:!0}),!s.client&&e.jsx(ye,{title:t("placeLook.sidebarColor"),value:n.name,badge:e.jsx(De,{place:n,size:14}),onClick:()=>a("overview","sidebar"),data:{"data-settings-door":"sidebar-color"}})]})}),e.jsx(Nm,{}),e.jsx(J,{label:t("settings.appearance.chat"),block:"chat",children:e.jsxs(V,{children:[!s.client&&e.jsx(nm,{}),s.advanced&&e.jsx(tm,{}),s.advanced&&e.jsx(Lp,{}),s.advanced&&e.jsx(Ip,{})]})}),s.advanced&&e.jsx(J,{label:t("settings.appearance.layout"),block:"appearance",children:e.jsxs(V,{children:[e.jsx(hc,{}),e.jsx(Fm,{}),s.advanced&&e.jsx(Zp,{}),s.advanced&&e.jsx(Rp,{}),s.advanced&&e.jsx(em,{}),s.advanced&&e.jsx(sm,{})]})}),s.advanced&&e.jsx(Tm,{})]})}const hs="rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none [color-scheme:dark]";function Sa({entry:s}){const[n,a]=o.useState(!1),i=s.type==="admin"&&(s.changed?.length||s.before||s.after);return e.jsx("li",{className:"border-b border-hairline/20 py-2 text-[13px]","data-activity-entry":s.type,children:e.jsxs("div",{className:"grid grid-cols-[auto_1fr] items-start gap-x-3",children:[e.jsx("time",{className:"whitespace-nowrap tabular-nums text-ink-secondary",dateTime:s.at,children:new Date(s.at).toLocaleString(Gs())}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2",children:[e.jsx("span",{className:"font-medium text-ink",children:fu(s.who)}),e.jsx("span",{className:"min-w-0 break-words text-ink",children:bu(s)})]}),s.type==="approval"&&s.summary&&e.jsx("div",{className:"mt-0.5 truncate text-[12px] text-ink-secondary",children:bc(s.summaryCode,s.summary,s.summaryParams)}),i&&e.jsxs("button",{type:"button",onClick:()=>a(!n),"aria-expanded":n,className:"cursor-pointer mt-0.5 flex items-center gap-1 text-[12px] text-ink-secondary hover:text-ink",children:[e.jsx(St,{size:12,className:D("transition-transform",n&&"rotate-90")}),t("activity.changed",{paths:(s.changed??[]).join(", ")||"—"})]}),i&&n&&s.type==="admin"&&e.jsxs("dl",{className:"mt-1 grid grid-cols-[auto_1fr_1fr] gap-x-3 gap-y-0.5 rounded-lg bg-inset p-2 text-[12px]",children:[e.jsx("dt",{}),e.jsx("dd",{className:"text-ink-secondary",children:t("activity.before")}),e.jsx("dd",{className:"text-ink-secondary",children:t("activity.after")}),(s.changed??Object.keys({...s.before,...s.after})).map(r=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"font-mono text-ink-secondary",children:r}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:da(s.before?.[r])}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:da(s.after?.[r])})]},r))]})]})]})})}function $m(){const[s,n]=o.useState({who:"",what:"all",from:"",to:""}),[a,i]=o.useState([]),[r,c]=o.useState(0),[l,d]=o.useState(null),[u,p]=o.useState(!1),[x,m]=o.useState(null),g=hu(s),f=o.useContext(Ae),h=o.useCallback(async()=>{p(!0),m(null);try{const b=await M(`/api/admin-activity${g}`);i(b.entries),c(b.total),d(b.retentionDays)}catch(b){m(b instanceof Error?b.message:String(b))}finally{p(!1)}},[g]);o.useEffect(()=>{const b=window.setTimeout(()=>{h()},250);return()=>window.clearTimeout(b)},[h]);const j=b=>n(y=>({...y,...b}));return f?e.jsxs(J,{label:t("settings.section.activity"),block:"activity",footnote:t("activity.subtitle",{days:String(l??180)}),actions:e.jsx("a",{href:`/api/admin-activity.csv${g}`,download:!0,className:"ui-button ui-button-md rounded-full",children:t("activity.export")}),children:[e.jsxs(V,{children:[e.jsx(L,{title:t("activity.who"),children:e.jsx("input",{value:s.who,onChange:b=>j({who:b.target.value}),placeholder:t("activity.whoPlaceholder"),"aria-label":t("activity.who"),className:D(Ue,"w-[200px] text-left")})}),e.jsx(L,{title:t("activity.what"),children:e.jsx(ce,{value:s.what,onChange:b=>j({what:b.target.value}),"aria-label":t("activity.what"),children:ca.map(b=>e.jsx("option",{value:b,children:t(`activity.what.${b}`)},b))})}),e.jsxs(L,{title:t("activity.dates"),children:[e.jsx("input",{type:"date",value:s.from,max:s.to||void 0,onChange:b=>j({from:b.target.value}),"aria-label":t("activity.from"),className:D(Ue,"w-[140px] text-left")}),e.jsx("input",{type:"date",value:s.to,min:s.from||void 0,onChange:b=>j({to:b.target.value}),"aria-label":t("activity.to"),className:D(Ue,"w-[140px] text-left")})]}),e.jsx(es,{status:x?e.jsx("span",{role:"alert",className:"text-danger",children:t("activity.error",{message:x})}):r>a.length?t("activity.more",{shown:String(a.length),total:String(r)}):void 0,children:e.jsx("button",{type:"button",onClick:()=>{h()},disabled:u,className:"settings-quiet cursor-pointer",children:u?t("common.checking"):t("activity.refresh")})})]}),e.jsxs(V,{children:[!x&&a.length===0&&!u&&e.jsx(Ne,{children:t("activity.empty")}),a.length>0&&e.jsx("ul",{className:"flex flex-col px-4 py-1",children:a.map((b,y)=>e.jsx(Sa,{entry:b},`${b.at}-${y}`))})]})]}):e.jsxs(pe,{title:t("activity.title"),subtitle:t("activity.subtitle",{days:String(l??180)}),children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.who"),e.jsx("input",{value:s.who,onChange:b=>j({who:b.target.value}),placeholder:t("activity.whoPlaceholder"),className:D(hs,"w-44")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.what"),e.jsx(ce,{value:s.what,onChange:b=>j({what:b.target.value}),children:ca.map(b=>e.jsx("option",{value:b,children:t(`activity.what.${b}`)},b))})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.from"),e.jsx("input",{type:"date",value:s.from,max:s.to||void 0,onChange:b=>j({from:b.target.value}),className:hs})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.to"),e.jsx("input",{type:"date",value:s.to,min:s.from||void 0,onChange:b=>j({to:b.target.value}),className:hs})]}),e.jsx("button",{type:"button",onClick:()=>{h()},disabled:u,"aria-label":t("activity.refresh"),title:t("activity.refresh"),className:"cursor-pointer rounded-md p-2 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:u?e.jsx(re,{size:14,className:"animate-spin"}):e.jsx(bt,{size:14})}),e.jsxs("a",{href:`/api/admin-activity.csv${g}`,download:!0,className:"ui-button hover:bg-raised-hover",children:[e.jsx($i,{size:13,"aria-hidden":"true"}),t("activity.export")]})]}),x&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("activity.error",{message:x})}),!x&&a.length===0&&!u&&e.jsx("p",{className:"mt-4 text-[13px] text-ink-secondary",children:t("activity.empty")}),a.length>0&&e.jsx("ul",{className:"mt-3 flex flex-col",children:a.map((b,y)=>e.jsx(Sa,{entry:b},`${b.at}-${y}`))}),r>a.length&&e.jsx("p",{className:"mt-3 text-[12px] text-ink-secondary",children:t("activity.more",{shown:String(a.length),total:String(r)})})]})}const fs=s=>s===0||s>=1024*1024?`${Math.round(s/(1024*1024))} MB`:`${Math.ceil(s/1024)} KB`;function Km(){const[s,n]=o.useState(null),[a,i]=o.useState(!1),[r,c]=o.useState(!1),[l,d]=o.useState(null);if(o.useEffect(()=>{let p=!0;return M("/api/attachment-storage").then(x=>{p&&n(x)}).catch(()=>{}),()=>{p=!1}},[]),!s)return null;const u=async()=>{c(!0),d(null);try{const p=await M("/api/attachment-storage",{method:"POST"});n(p);const x=t("settings.attachments.cleared",{count:p.removed,freed:fs(p.freedBytes)});d(p.failed>0?{kind:"error",message:`${x} ${t("settings.attachments.failed",{count:p.failed})}`}:{kind:"success",message:x})}catch(p){d({kind:"error",message:p instanceof Error?p.message:String(p)})}finally{c(!1),i(!1)}};return e.jsx(L,{title:t("settings.attachments.title"),subtitle:e.jsxs(e.Fragment,{children:[e.jsx("span",{"data-attachments-used":!0,className:"block",children:t("settings.attachments.used",{used:fs(s.usedBytes),max:fs(s.maxBytes)})}),a&&e.jsx("span",{className:"block",children:t("settings.attachments.confirmText")})]}),message:l&&e.jsx("p",{role:l.kind==="error"?"alert":"status",className:D(l.kind==="error"?"text-danger":"text-success"),children:l.message}),children:e.jsx("div",{className:"flex flex-wrap gap-2",children:a?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>i(!1),disabled:r,className:"ui-button",children:t("settings.attachments.cancel")}),e.jsx("button",{type:"button",onClick:()=>{u()},disabled:r,className:"ui-button !bg-danger !text-danger-ink",children:r?t("settings.attachments.clearing"):t("settings.attachments.confirm")})]}):e.jsx("button",{type:"button",title:t("settings.attachments.help"),onClick:()=>{d(null),i(!0)},className:"ui-button",children:t("settings.attachments.clear")})})})}const pn="flex w-full min-w-0 items-center gap-3 px-3 py-2 text-start",mn="flex flex-col divide-y divide-hairline/30 overflow-hidden rounded-xl border border-hairline/40 bg-card",Wm=s=>s.filter(n=>!n.hidden&&!n.defaultBot?.person).sort((n,a)=>n.name.localeCompare(a.name)),Lr=(s,n)=>ts(s)===n||qi(ss(s),n)!=="none",Rr=(s,n)=>{const a=Wi(s,n);return a?t("lookedAfter.line",{name:a.name}):t("lookedAfter.nobody")},Ca=(s,...n)=>n.some(a=>a?.toLowerCase().includes(s));function Gm(){const{state:s}=_(),n=Ki(),a=vc(),i=o.useRef(null),[r,c]=o.useState("bot"),[l,d]=o.useState(""),[u,p]=o.useState(null),[x,m]=o.useState(null),g=o.useRef(null),[f,h]=o.useState(null),[j,b]=o.useState(""),y=o.useCallback(()=>h(null),[]);if(o.useEffect(()=>{x||!g.current||([...i.current?.querySelectorAll("[data-access-person]")??[]].find(k=>k.dataset.accessPerson===g.current)?.focus(),g.current=null)},[x]),!n||!a)return null;const v=n.people.filter(k=>k.role==="member").sort((k,S)=>k.name.localeCompare(S.name)),w=Wm(s.bots),N=u?w.find(k=>k.id===u):void 0,C=x?v.find(k=>k.email===x):void 0,I=l.trim().toLowerCase(),F=async(k,S,P)=>{b("");const E=ss(k);try{await Kn(k.id,S),h({botId:k.id,before:E,after:S,text:P})}catch(A){b(A instanceof Error?A.message:String(A))}};return e.jsxs("div",{ref:i,className:"flex min-w-0 flex-col gap-3","data-access-overview":!0,children:[C?e.jsx(Jm,{person:C,bots:w.filter(k=>Lr(k,C.email)),team:n,teamName:a,apply:F,onBack:()=>{g.current=C.email,m(null)}}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"ps-4 text-[13px] leading-relaxed text-ink-secondary",children:t("botAccess.overview.introUse",{team:a})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative min-w-[180px] flex-1",children:[e.jsx(Jt,{size:14,"aria-hidden":"true",className:"pointer-events-none absolute start-2.5 top-1/2 -translate-y-1/2 text-ink-secondary"}),e.jsx("input",{type:"search",value:l,"data-access-search":!0,"aria-label":t(r==="bot"?"botAccess.overview.searchBots":"botAccess.overview.searchPeople"),placeholder:t(r==="bot"?"botAccess.overview.searchBots":"botAccess.overview.searchPeople"),onChange:k=>d(k.target.value),onKeyDown:k=>{k.key==="Escape"&&l&&(k.preventDefault(),d(""))},className:"w-full rounded-lg border border-hairline/50 bg-transparent py-1.5 pe-2.5 ps-8 text-[13px] text-ink placeholder:text-ink-secondary focus:border-focus focus:outline-none"})]}),e.jsx("div",{role:"group","aria-label":t("botAccess.overview.listBy"),className:"flex shrink-0 rounded-full bg-raised/70 p-0.5",children:["bot","person"].map(k=>e.jsx("button",{type:"button","aria-pressed":r===k,"data-access-listing":k,onClick:()=>{c(k),d("")},className:D("rounded-full px-3 py-1 text-[13px] leading-[18px]",r===k?"bg-menu font-medium text-ink shadow-sm":"text-ink-secondary hover:text-ink"),children:t(k==="bot"?"botAccess.overview.byBot":"botAccess.overview.byPerson")},k))})]}),r==="bot"?e.jsx(qm,{bots:w.filter(k=>!I||Ca(I,k.name,Wi(k,n)?.name,ts(k)??void 0)),anyBots:w.length>0,team:n,onOpen:p}):e.jsx(Vm,{people:v.filter(k=>!I||Ca(I,k.name,k.email)),anyPeople:v.length>0,bots:w,onOpen:m}),e.jsx("p",{className:"ps-4 text-[12px] text-ink-secondary",children:t("botAccess.admins")})]}),j&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:j}),N&&e.jsx(yc,{bot:N,teamName:a,onClose:()=>p(null),onChanged:k=>h({botId:N.id,...k})}),f&&e.jsx(jc,{text:f.text,onUndo:()=>Kn(f.botId,f.before),onDone:y},`${f.botId}:${f.text}:${JSON.stringify(f.after)}`)]})}function qm({bots:s,anyBots:n,team:a,onOpen:i}){return n?s.length?e.jsx("ul",{className:mn,children:s.map(r=>{const c=ss(r),l=ts(r);return e.jsx("li",{className:"min-w-0",children:e.jsxs("button",{type:"button","aria-haspopup":"dialog","data-access-row":r.id,onClick:()=>i(r.id),className:D(pn,"hover:bg-ink/[0.06] focus-visible:bg-ink/[0.06] focus-visible:outline-none"),children:[e.jsx(Xt,{bot:r,size:32}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[14px] leading-[18px] text-ink",children:r.name}),e.jsx("span",{className:"block truncate text-[12px] leading-4 text-ink-secondary",children:Rr(r,a)})]}),e.jsx("span",{className:"min-w-0 max-w-[40%] truncate text-[13px] text-ink-secondary","data-access-summary":!0,children:c.everyone==="none"?t("botAccess.onlyAdded"):t("botAccess.overview.everyoneUses")}),e.jsx(kc,{entries:Object.keys(c.people).filter(d=>d!==l),team:a})]})},r.id)})}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("botAccess.overview.noBotMatch")}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("botAccess.overview.noBots")})}function Vm({people:s,anyPeople:n,bots:a,onOpen:i}){return n?s.length?e.jsx("ul",{className:mn,children:s.map(r=>{const c=a.filter(l=>Lr(l,r.email)).length;return e.jsx("li",{className:"min-w-0",children:e.jsxs("button",{type:"button","data-access-person":r.email,onClick:()=>i(r.email),className:D(pn,"hover:bg-ink/[0.06] focus-visible:bg-ink/[0.06] focus-visible:outline-none"),children:[e.jsx(Gi,{person:r,size:32}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[14px] leading-[18px] text-ink",children:r.name}),e.jsx("span",{className:"block truncate text-[12px] leading-4 text-ink-secondary",children:r.email})]}),e.jsx("span",{className:"shrink-0 text-[13px] text-ink-secondary",children:c===1?t("botAccess.overview.botCount.one"):t("botAccess.overview.botCount.other",{count:c})})]})},r.email)})}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("botAccess.noMatch")}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("botAccess.overview.noPeople")})}function Jm({person:s,bots:n,team:a,teamName:i,apply:r,onBack:c}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{children:e.jsxs("button",{type:"button",autoFocus:!0,"data-access-back":!0,onClick:c,className:"-ms-2 flex items-center gap-1 rounded-md px-2 py-1 text-[13px] text-ink-secondary hover:bg-ink/[0.06] hover:text-ink",children:[e.jsx(Ci,{size:14,"aria-hidden":"true",className:"rtl:-scale-x-100"}),t("botAccess.overview.allPeople")]})}),e.jsxs("div",{className:"flex min-w-0 items-center gap-3 px-3",children:[e.jsx(Gi,{person:s,size:32}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[14px] font-medium leading-[18px] text-ink",children:s.name}),e.jsx("span",{className:"block truncate text-[12px] leading-4 text-ink-secondary",children:s.email})]})]}),n.length===0?e.jsx("p",{className:"px-3 text-[13px] text-ink-secondary",children:t("botAccess.overview.noBotsForPerson",{name:s.name})}):e.jsx("ul",{className:mn,children:n.map(l=>e.jsx(Ym,{bot:l,person:s,team:a,teamName:i,apply:r},l.id))})]})}function Ym({bot:s,person:n,team:a,teamName:i,apply:r}){const c=ss(s),l=ts(s)===n.email,d=c.people[n.email],u=qi(c,n.email);return e.jsxs("li",{className:pn,"data-access-person-bot":s.id,children:[e.jsx(Xt,{bot:s,size:32}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[14px] leading-[18px] text-ink",children:s.name}),e.jsx("span",{className:"block truncate text-[12px] leading-4 text-ink-secondary",children:!d&&!l&&u===c.everyone?t("botAccess.everyoneUse",{team:i}):Rr(s,a)})]}),e.jsx("span",{className:"min-w-0 shrink-0 text-[13px] text-ink-secondary",children:l?e.jsx("span",{className:"px-2",children:t("lookedAfter.owner")}):d?e.jsx("button",{type:"button","data-access-remove":s.id,"aria-label":t("botAccess.overview.removeFrom",{name:n.name,bot:s.name}),onClick:()=>{r(s,wc(c,n.email,null),t("botAccess.overview.toastRemoved",{name:n.name,bot:s.name}))},className:"rounded-md px-2 py-1 hover:bg-ink/[0.06] hover:text-ink",children:t("botAccess.remove")}):null})]})}const bs="mt-1 w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[14px] text-ink disabled:opacity-50",et=s=>{const n=s>=1073741824?3:s>=1048576?2:1;return`${new Intl.NumberFormat(Ee(),{maximumFractionDigits:2}).format(s/1024**n)} ${["","KiB","MiB","GiB"][n]}`},Ea=s=>{const n=new Date(s.completedAt??s.createdAt??NaN);return Number.isFinite(n.getTime())?new Intl.DateTimeFormat(Ee(),{dateStyle:"medium",timeStyle:"short"}).format(n):t("companyBackup.unknownDate")};function Xm(){const s=window.ogb?.remoteClient?.active?void 0:window.ogb?.organization,n=s?window.ogb?.companyBackups:void 0,[a,i]=o.useState(null),r=o.useRef(0),c=o.useRef(0);return o.useEffect(()=>{const l=++r.current,d=c.current;i(null);const u=x=>{r.current===l&&(c.current++,i(x))},p=s?.onState(u);return s?.state().then(x=>{c.current===d&&u(x)}).catch(()=>{}),()=>{r.current++,p?.()}},[s]),!n||!a?null:a.status!=="connected"||a.cloudBackups!==!0||!a.organization?.id||!a.organization.name?.trim()||!a.email?e.jsx(Qm,{bridge:n}):e.jsx(Zm,{connection:a,bridge:n},`${a.organization.id}:${a.email}:${a.deviceId??""}`)}function Qm({bridge:s}){const[n,a]=o.useState(null),[i,r]=o.useState(!1),[c,l]=o.useState(""),d=o.useRef(0);if(o.useEffect(()=>{const p=++d.current,x=s.onState(m=>{p===d.current&&a(m.schedule??null)});return s.state().then(m=>{p===d.current&&a(m.schedule??null)}).catch(()=>{}),()=>{d.current++,x()}},[s]),!s.configureSchedule||!n?.enabled)return null;const u=async()=>{if(i||!s.configureSchedule)return;const p=d.current;r(!0),l("");try{const x=await s.configureSchedule({enabled:!1});p===d.current&&a(x.schedule??null)}catch{p===d.current&&l(t("companyBackup.scheduleFailed"))}finally{p===d.current&&r(!1)}};return e.jsx(pe,{title:t("companyBackup.title"),subtitle:t("companyBackup.savedSchedule"),children:e.jsxs("div",{className:"rounded-lg border border-hairline/40 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[14px] font-medium",children:t("companyBackup.daily")}),e.jsx(ne,{"aria-label":t("companyBackup.daily"),checked:!0,disabled:i,onClick:()=>{u()}})]}),e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t(`companyBackup.scheduleStatus.${n.status}`)}),c&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:c})]})})}function Zm({connection:s,bridge:n}){const[a,i]=o.useState(null),[r,c]=o.useState(null),[l,d]=o.useState(!1),[u,p]=o.useState(null),[x,m]=o.useState(""),[g,f]=o.useState(null),[h,j]=o.useState(""),[b,y]=o.useState(""),[v,w]=o.useState(null),[N,C]=o.useState(!1),I=o.useRef(0),F=o.useRef(0),k=o.useRef(0),S=o.useRef(void 0),P=o.useRef(!1),E=o.useRef(null),A=async()=>{const $=I.current,me=++k.current,he=F.current;d(!0);try{await Promise.all([n.state().then(ke=>{$===I.current&&me===k.current&&F.current===he&&i(ke)}),n.list().then(ke=>{$===I.current&&me===k.current&&c(ke)})]),$===I.current&&me===k.current&&m("")}catch{$===I.current&&me===k.current&&m(t("companyBackup.loadFailed"))}finally{$===I.current&&me===k.current&&d(!1)}};o.useEffect(()=>{const $=++I.current,me=ke=>{if($!==I.current)return;F.current++,i(ke);const Re=ke.lastBackupAt??ke.schedule?.lastBackupAt;!ke.busy&&!ke.pendingRestore&&Re&&Re!==S.current&&(S.current=Re,A())},he=n.onState(me);return A(),()=>{I.current++,k.current++,he()}},[n]),o.useEffect(()=>{const $=E.current;if(!(!g||!$))return $.showModal(),()=>{$.close()}},[g]);const q=N||a?.pendingRestore===!0,R=u!==null||!a||a.busy||q,K=()=>{f(null),j(""),y(""),w(null)},Z=$=>{R||P.current||(m(""),j(""),y(""),w(null),f($))},oe=async($,me)=>{if(R||P.current)return;P.current=!0,p($),m("");const he=I.current;try{await me(()=>he===I.current)}catch{he===I.current&&m(t($==="restore"?"companyBackup.restoreFailed":"companyBackup.actionFailed"))}finally{P.current=!1,he===I.current&&p(null)}},se=()=>{g?.kind==="create"&&oe("create",async $=>{await n.create({clientState:Sc()}),$()&&(K(),await A())})},Y=async $=>{if(!n.configureSchedule||P.current||!a||$&&(R||g?.kind!=="schedule"||b!=="BACK UP THIS WORKSPACE DAILY"))return;P.current=!0,p("schedule"),m("");const me=I.current,he=F.current;y("");try{const ke=await n.configureSchedule($?{enabled:!0,confirmation:"BACK UP THIS WORKSPACE DAILY"}:{enabled:!1});me===I.current&&(F.current===he&&i(ke),K())}catch{me===I.current&&m(t("companyBackup.scheduleFailed"))}finally{P.current=!1,me===I.current&&p(null)}},B=()=>{g?.kind!=="restore"||g.entry.passwordRequired!==!1&&(h.length<12||h.length>1024)||oe("prepare",async $=>{const me=h;j(""),w(null),y("");const he=await n.prepareRestore({id:g.entry.id,...g.entry.passwordRequired!==!1?{password:me}:{}});$()&&w(he)})},W=()=>{g?.kind!=="restore"||!v||b!=="REPLACE"||oe("restore",async $=>{const me=localStorage.getItem(Gn);if(me&&me!==v.id)throw new Error(t("companyBackup.restorePending"));localStorage.setItem(Gn,v.id),await n.restore({id:v.id,confirmation:"REPLACE"}),$()&&(C(!0),K())})},G=()=>{g?.kind!=="delete"||b!=="DELETE"||oe("delete",async $=>{await n.delete({id:g.entry.id,confirmation:"DELETE"}),$()&&(K(),await A())})},le=async()=>{const $=I.current;try{await n.cancel()}catch{$===I.current&&m(t("companyBackup.actionFailed"))}},U=r?.backups.filter($=>$.status==="ready")??[],H=r?r.backups.length-U.length:0,Q=a?.progress,te=x||a?.message,ie=(a?.busy||u)&&e.jsxs("div",{role:"status",className:"flex flex-col items-start gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{children:u==="restore"?t("backup.restoring"):Q?t(`companyBackup.phase.${Q.phase}`):t("companyBackup.working")}),Q&&Q.totalBytes>0&&e.jsxs(e.Fragment,{children:[e.jsx("progress",{className:"w-full accent-accent",max:Q.totalBytes,value:Math.min(Q.bytesTransferred,Q.totalBytes),"aria-label":t("companyBackup.progress")}),e.jsx("span",{children:t("companyBackup.transferred",{done:et(Q.bytesTransferred),total:et(Q.totalBytes)})})]}),a?.busy&&u!=="restore"&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{le()},children:t("companyBackup.cancelTransfer")})]}),Se=g?.kind==="restore"?t("companyBackup.restore"):g?.kind==="delete"?t("companyBackup.delete"):g?.kind==="schedule"?t("companyBackup.enableSchedule"):t("companyBackup.create"),de=a?.schedule,be=$=>new Intl.DateTimeFormat(Ee(),{dateStyle:"medium",timeStyle:"short"}).format(new Date($));return e.jsxs(pe,{title:t("companyBackup.title"),subtitle:t("companyBackup.account",{organization:s.organization?.name??"",email:s.email??""}),children:[e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.managedScope")}),n.configureSchedule&&de&&e.jsxs("div",{className:"rounded-lg border border-hairline/40 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[14px] font-medium",children:t("companyBackup.daily")}),e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.scheduleHelp")})]}),e.jsx(ne,{"aria-label":t("companyBackup.daily"),checked:de.enabled,disabled:u!==null||!a||!de.enabled&&R,onClick:()=>de.enabled?void Y(!1):Z({kind:"schedule"})})]}),e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t(`companyBackup.scheduleStatus.${de.status}`)}),de.enabled&&de.nextBackupAt&&Number.isFinite(de.nextBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.nextBackup",{date:be(de.nextBackupAt)})}),de.lastBackupAt&&Number.isFinite(de.lastBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.lastScheduledBackup",{date:be(de.lastBackupAt)})}),de.message&&e.jsx("p",{role:"status",className:"mt-1 break-words text-[12px] text-ink-secondary",children:de.message})]}),q?e.jsx("div",{className:"rounded-lg border border-warning/40 bg-warning/10 p-3 text-ink",children:e.jsx(Wn,{})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:R,onClick:()=>Z({kind:"create"}),children:t("companyBackup.create")}),e.jsx("button",{type:"button",className:"ui-button",disabled:u!==null||a?.busy||q||l,onClick:()=>{A()},children:t("companyBackup.refresh")})]}),l&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("companyBackup.loading")}),r&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("companyBackup.quota",{used:et(r.usedBytes),total:et(r.limits.ownerQuotaBytes),count:r.limits.retainedSnapshots})}),H>0&&e.jsx("p",{role:"status",className:"text-[12px] text-ink-secondary",children:t("companyBackup.pending",{count:H})}),r&&U.length===0&&e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.empty")}),e.jsx("ul",{className:"divide-y divide-hairline/40",children:U.map($=>e.jsxs("li",{className:"flex flex-wrap items-center justify-between gap-3 py-3",children:[e.jsxs("div",{className:"min-w-0 text-[13px]",children:[e.jsx("div",{className:"text-ink",children:Ea($)}),e.jsxs("div",{className:"text-[12px] text-ink-secondary",children:[et($.sizeBytes),$.appVersion?` · ${$.appVersion}`:""]}),e.jsx("code",{className:"break-all text-[11px] text-ink-secondary",children:$.id})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:R,onClick:()=>Z({kind:"restore",entry:$}),children:t("companyBackup.restore")}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:R,onClick:()=>Z({kind:"delete",entry:$}),children:t("companyBackup.delete")})]})]},$.id))})]}),!g&&ie,!g&&te&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:te})]}),g&&e.jsx("dialog",{ref:E,"aria-labelledby":"company-backup-dialog-title",onKeyDown:$=>{($.key==="Escape"||$.key==="Tab")&&$.stopPropagation()},onCancel:$=>{$.preventDefault(),u||K()},className:"fixed inset-0 m-auto max-h-[85dvh] w-[min(34rem,calc(100vw-2rem))] overflow-y-auto rounded-xl border border-hairline/50 bg-app p-5 text-ink shadow-xl backdrop:bg-black/45",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("h3",{id:"company-backup-dialog-title",className:"text-[16px] font-semibold",children:Se}),q&&e.jsx(Wn,{}),(g.kind==="restore"||g.kind==="delete")&&e.jsxs("div",{className:"text-[13px] text-ink-secondary",children:[e.jsxs("p",{children:[Ea(g.entry)," · ",et(g.entry.sizeBytes)]}),e.jsx("code",{className:"break-all text-[11px]",children:g.entry.id})]}),(g.kind==="create"||g.kind==="schedule")&&e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:$=>{$.preventDefault(),g.kind==="schedule"?Y(!0):se()},children:[e.jsx("p",{className:"text-[13px] text-ink",children:t(g.kind==="schedule"?"companyBackup.scheduleWarning":"companyBackup.managedUploadWarning",{organization:s.organization?.name??"",email:s.email??""})}),g.kind==="schedule"?e.jsxs("details",{className:"text-[13px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer text-ink",children:t("companyBackup.included")}),e.jsx("p",{className:"mt-2",children:t("backup.excluded")}),e.jsx("p",{className:"mt-2",children:t("companyBackup.managedPrivacy")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("backup.excluded")}),e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.managedPrivacy")})]}),e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.managedEncryption")}),g.kind==="schedule"&&e.jsxs("label",{className:"flex items-start gap-2 text-[13px]",children:[e.jsx("input",{className:"mt-1 accent-accent",type:"checkbox",required:!0,disabled:R,checked:b==="BACK UP THIS WORKSPACE DAILY",onChange:$=>y($.target.checked?"BACK UP THIS WORKSPACE DAILY":"")}),e.jsx("span",{children:t("companyBackup.scheduleConsent")})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:R||g.kind==="schedule"&&b!=="BACK UP THIS WORKSPACE DAILY",children:t(g.kind==="schedule"?"companyBackup.enableSchedule":"companyBackup.create")})]}),g.kind==="restore"&&(v?e.jsxs(e.Fragment,{children:[e.jsx(Nc,{summary:v.summary}),e.jsx("p",{className:"text-[13px] text-danger",children:t("backup.replaceWarning")}),e.jsx("p",{className:"text-[13px] text-danger",children:t("backup.trustWarning")}),e.jsxs("label",{className:"text-[13px]",children:[t("backup.confirmReplace"),e.jsx("input",{autoComplete:"off",spellCheck:!1,maxLength:7,disabled:R,value:b,onChange:$=>y($.target.value),className:bs})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:R||b!=="REPLACE",onClick:W,children:t("backup.replace")})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:$=>{$.preventDefault(),B()},children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.previewHelp")}),g.entry.passwordRequired!==!1&&e.jsxs("label",{className:"text-[13px]",children:[t("backup.importPassword"),e.jsx("input",{type:"password",autoComplete:"off",required:!0,minLength:12,maxLength:1024,disabled:R,value:h,onChange:$=>j($.target.value),className:bs})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:R||g.entry.passwordRequired!==!1&&(h.length<12||h.length>1024),children:t("backup.validate")})]})),g.kind==="delete"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-danger",children:t("companyBackup.deleteWarning")}),e.jsxs("label",{className:"text-[13px]",children:[t("companyBackup.confirmDelete"),e.jsx("input",{autoComplete:"off",spellCheck:!1,maxLength:6,disabled:R,value:b,onChange:$=>y($.target.value),className:bs})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:R||b!=="DELETE",onClick:G,children:t("companyBackup.delete")})]}),ie,te&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:te}),e.jsx("button",{type:"button",autoFocus:!0,className:"ui-button w-fit",disabled:u!==null,onClick:K,children:t("companyBackup.cancel")})]})})]})}function Aa({sources:s}){const n=[...new Set(s.map(a=>a==="claudeDesktop"?"claudeCode":a))];return e.jsx("span",{className:"mr-1.5 inline-flex items-center gap-1 align-[-1px]","aria-hidden":"true",children:n.map(a=>{switch(a){case"codex":return e.jsx(Uc,{size:12},a);case"cursor":return e.jsx(Fc,{size:12},a);case"gemini":return e.jsx(Oc,{preset:"google",size:12},a);default:return e.jsx(Bc,{size:12},a)}})})}function Pa({icon:s,label:n,summary:a,hint:i,sources:r,checked:c,disabled:l,onChange:d}){return o.useContext(Ae)?e.jsxs("div",{className:"flex items-center gap-6 py-2",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-[13px] leading-5 text-ink",children:[e.jsx(Aa,{sources:r}),n]}),e.jsx("span",{className:"text-[12px] leading-4 text-ink-secondary",children:a})]}),e.jsx(ne,{checked:c,disabled:l,"aria-label":n,onClick:()=>d(!c)})]}):e.jsxs("label",{className:D("flex items-start gap-3 px-3.5 py-3 transition-colors",l?"cursor-default":"cursor-pointer hover:bg-raised/40"),children:[e.jsx("input",{type:"checkbox",checked:c,disabled:l,onChange:u=>d(u.target.checked),className:"mt-0.5 size-4 shrink-0 cursor-[inherit] accent-[var(--color-accent)]"}),e.jsx("span",{className:"mt-0.5 flex size-4 shrink-0 items-center justify-center text-ink-secondary",children:s}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsxs("span",{className:"text-[13px] leading-5 text-ink-secondary",children:[e.jsx("span",{className:"mr-2 text-[14px] font-medium text-ink",children:n}),e.jsx(Aa,{sources:r}),a]}),e.jsx("span",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:i})]})]})}const Br="inline-flex items-center justify-center gap-2 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-accent-ink disabled:opacity-40";function ex({local:s,detection:n,chosen:a,status:i,result:r,onChoose:c,onBring:l,onRetry:d,onSkip:u}){const p=i==="working",x=o.useContext(Ae);if(x&&s&&(n===null||i==="failed"))return e.jsx("div",{"data-import-section":"apps",className:"contents",children:e.jsx(L,{title:t("settings.import.appsTitle"),subtitle:t("settings.import.appsShort"),message:e.jsxs("span",{role:"alert",className:"text-danger",children:[t(n===null?"settings.import.lookFailed":"settings.import.bringFailed"),d&&e.jsxs(e.Fragment,{children:[" ",e.jsx("button",{type:"button","data-import-retry":"",className:"cursor-pointer text-accent-text hover:underline focus-visible:underline",onClick:d,children:t("common.tryAgain")})]})]}),children:u&&e.jsx("button",{type:"button","data-import-skip":"",className:"settings-quiet cursor-pointer",onClick:u,children:t("settings.import.skip")})})});const m=x?"ui-button self-end gap-1.5":Br;let g;if(!s)g=e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("settings.import.appsLocalOnly")});else if(n===void 0)g=e.jsxs("p",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(re,{size:14,className:"animate-spin"}),t("settings.import.appsLooking")]});else if(r){const{line:f,notes:h,done:j}=Ec(r);g=e.jsxs("div",{role:"status",className:"flex items-start gap-3",children:[e.jsx("span",{className:D("mt-px flex size-5 shrink-0 items-center justify-center rounded-full",j?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:j?e.jsx(_e,{size:12,strokeWidth:3}):e.jsx(Ac,{size:12,strokeWidth:2.5})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[14px] font-medium text-ink",children:f}),h.map(b=>e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-ink-secondary",children:b},b))]})]})}else!n||Pc(n)===0?g=e.jsx("p",{className:"text-[13px] text-ink-secondary",children:n===null?t("onboarding.import.error"):t("settings.import.appsNothing")}):g=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:x?"flex flex-col":"divide-y divide-hairline/40 overflow-hidden rounded-xl border border-hairline/40",children:[n.skills.length>0&&e.jsx(Pa,{icon:e.jsx(Ic,{size:15}),label:t("onboarding.import.skills"),summary:Tc(n),hint:t("onboarding.import.skillsHint"),sources:Yn(n.skills),checked:a.skills,disabled:p,onChange:f=>c({...a,skills:f})}),n.tools.length>0&&e.jsx(Pa,{icon:e.jsx(Rc,{size:15}),label:t("onboarding.import.tools"),summary:Lc(n),hint:t("onboarding.import.toolsHint"),sources:Yn(n.tools),checked:a.tools,disabled:p,onChange:f=>c({...a,tools:f})})]}),i==="failed"&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("onboarding.import.error")}),e.jsxs("button",{onClick:l,disabled:p||!(a.skills||a.tools),className:D(m,!x&&"mt-3"),children:[p&&e.jsx(re,{size:14,className:"animate-spin"}),p?t("onboarding.import.bringing"):t("onboarding.import.bring")]})]});return x&&!s?e.jsx("div",{"data-import-section":"apps",className:"contents",children:e.jsx(L,{title:t("settings.import.appsTitle"),subtitle:t("settings.import.appsShort"),inert:t("settings.import.appsLocalOnly"),inertText:t("settings.import.appsLocalOnly"),children:e.jsx("button",{type:"button",className:"ui-button",tabIndex:-1,children:t("settings.import.choose")})})}):x?e.jsxs("div",{"data-import-section":"apps",className:"flex flex-col gap-2 px-4 py-3",children:[e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("span",{className:"text-[14px] leading-5 text-ink",children:t("settings.import.appsTitle")}),e.jsx("span",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.import.appsShort")})]}),g]}):e.jsxs("section",{"data-import-section":"apps",className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:t("settings.import.appsTitle")}),e.jsx("div",{className:"mt-0.5 text-[13px] leading-relaxed text-ink-secondary",children:t("settings.import.appsSubtitle")}),e.jsx("div",{className:"mt-4",children:g})]})}function Ta({client:s,local:n}){const[a,i]=o.useState(void 0),[r,c]=o.useState({skills:!0,tools:!0}),[l,d]=o.useState("idle"),[u,p]=o.useState(null),[x,m]=o.useState(0);o.useEffect(()=>{if(!n)return;const f=new AbortController;return i(void 0),s.detect(f.signal).then(i,()=>i(null)),()=>f.abort()},[s,n,x]);const g=async()=>{if(!a||l==="working")return;const f={...r.skills&&a.skills.length?{skills:!0}:{},...r.tools&&a.tools.length?{tools:!0}:{}};if(!(!f.skills&&!f.tools)){d("working");try{const h=await s.apply(f);Jl("setup_import_applied",{skills:h.skills?.added.length??0,tools:h.tools?.added.length??0}),p(h),d("idle")}catch{d("failed")}}};return e.jsx(ex,{local:n,detection:a,chosen:r,status:l,result:u,onChoose:c,onBring:()=>{g()},onRetry:()=>l==="failed"?void g():m(f=>f+1),onSkip:()=>l==="failed"?d("idle"):i({skills:[],tools:[]})})}function Ia(){const[s,n]=o.useState(!1),[a,i]=o.useState(!1);return o.useContext(Ae)?e.jsxs("div",{"data-import-section":"grok","data-settings-block":"grok-move",className:"flex flex-col",children:[e.jsx(L,{title:t("settings.import.grokTitle"),subtitle:t("settings.import.grokLine"),leading:e.jsx(Ls,{children:e.jsx(Vn,{size:18})}),children:e.jsx("button",{type:"button",className:"ui-button","data-grok-move-open":!0,"aria-expanded":a,onClick:()=>{n(!0),i(!a)},children:t(a?"common.close":"settings.import.moveAction")})}),s&&e.jsx("div",{className:a?"px-4 pb-3":"hidden",children:e.jsx(Jn,{inline:!0,onClose:()=>{n(!1),i(!1)}})})]}):e.jsxs("section",{"data-import-section":"grok",className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[15px] font-medium text-ink",children:[e.jsx(Vn,{size:16}),t("settings.import.grokTitle")]}),e.jsx("div",{className:"mt-0.5 text-[13px] leading-relaxed text-ink-secondary",children:t("settings.import.grokSubtitle")}),e.jsxs("button",{type:"button","data-grok-move-open":!0,"aria-expanded":a,onClick:()=>{n(!0),i(!a)},className:D(Br,"mt-3"),children:[t("settings.import.grokTitle"),e.jsx(Ei,{size:14,"aria-hidden":"true",className:D("transition-transform",a&&"rotate-180")})]}),s&&e.jsx("div",{className:a?void 0:"hidden",children:e.jsx(Jn,{inline:!0,onClose:()=>{n(!1),i(!1)}})})]})}function tx({client:s=Cc,children:n}){const{state:a}=_();return o.useContext(Ae)?e.jsxs(V,{children:[e.jsx(Ia,{}),e.jsx(Ta,{client:s,local:qn(a.config?.cloudHome===!0)}),n]}):e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(Ia,{}),e.jsx(Ta,{client:s,local:qn(a.config?.cloudHome===!0)}),n]})}const Or=1,Fr=3650,sx=30,qt=1024*1024,Fs=256*1024,Ur=4*1024*1024*1024,nx=50;function La(s){const n=Number(s);return Number.isInteger(n)&&n>=Or&&n<=Fr?n:null}function Ra(s){const n=Number(s);if(!Number.isFinite(n))return null;const a=Math.round(n*qt);return a>=Fs&&a<=Ur&&a%Fs===0?a:null}function Ba(s){const n=s/qt;return String(Number.isInteger(n)?n:Number(n.toFixed(2)))}function ax(){const{state:s,dispatch:n}=_(),a=s.config?.threads?.eventLogRetentionDays??null,i=s.config?.threads?.eventLogMaxBytes??null,[r,c]=o.useState(null),[l,d]=o.useState(null),[u,p]=o.useState(null),[x,m]=o.useState(""),[g,f]=o.useState(null),h=o.useRef(!1),j=r??String(a===null?sx:a),b=l??(i===null?String(nx):Ba(i));o.useEffect(()=>{r!==null&&a!==null&&String(a)===r&&c(null)},[a,r]),o.useEffect(()=>{l!==null&&i!==null&&Ba(i)===l&&d(null)},[i,l]);const y=async(k,S)=>{if(!h.current){h.current=!0,p(S),m(""),f(null);try{const P=await M("/api/config",{method:"PATCH",body:JSON.stringify({threads:k})});n({type:"configStatus",config:P})}catch(P){m(P instanceof Error?P.message:t("settings.threadCleanup.error")),f(S)}finally{h.current=!1,p(null)}}},v=k=>{if(!k){c(null),m(""),f(null),y({eventLogRetentionDays:null},"retention");return}const S=La(j);if(S===null){m(t("settings.threadCleanup.invalidRetention")),f("retention");return}y({eventLogRetentionDays:S},"retention")},w=k=>{if(!k){d(null),m(""),f(null),y({eventLogMaxBytes:null},"cap");return}const S=Ra(b);if(S===null){m(t("settings.threadCleanup.invalidCap")),f("cap");return}y({eventLogMaxBytes:S},"cap")},N=()=>{if(a===null)return;const k=La(j);if(k===null){m(t("settings.threadCleanup.invalidRetention")),f("retention");return}if(k===a){c(null),m("");return}y({eventLogRetentionDays:k},"retention")},C=()=>{if(i===null)return;const k=Ra(b);if(k===null){m(t("settings.threadCleanup.invalidCap")),f("cap");return}if(k===i){d(null),m("");return}y({eventLogMaxBytes:k},"cap")},I=k=>{const S=k==="retention";return e.jsxs("span",{className:"mt-1 flex items-center gap-2 text-[13px] leading-5 text-ink-secondary",children:[e.jsx("input",{id:S?"thread-log-retention-days":"thread-log-cap-mib",type:"number",min:S?Or:Fs/qt,max:S?Fr:Ur/qt,step:S?1:.25,inputMode:S?"numeric":"decimal",value:S?j:b,disabled:(S?a:i)===null||u!==null,"aria-invalid":g===k,"aria-label":t(S?"settings.threadCleanup.retention.enable":"settings.threadCleanup.cap.enable"),onChange:P=>{S?c(P.target.value):d(P.target.value),m(""),f(null)},onBlur:S?N:C,onKeyDown:P=>{P.key==="Enter"&&P.currentTarget.blur()},className:D(Ue,g===k&&"border-danger/60")}),t(S?"settings.threadCleanup.retention.unit":"settings.threadCleanup.cap.unit")]})},F=k=>u===k?e.jsx("span",{role:"status",children:t("settings.threadCleanup.saving")}):x&&g===k?e.jsx("span",{role:"alert",className:"text-danger",children:x}):void 0;return e.jsx(J,{label:t("settings.threadCleanup.title"),block:"cleanup",children:e.jsxs(V,{children:[e.jsx(L,{title:t("settings.threadCleanup.retention.title"),subtitle:a!==null?e.jsxs(e.Fragment,{children:[t("settings.threadCleanup.retention.short"),I("retention")]}):t("settings.threadCleanup.retention.plain"),message:F("retention"),children:e.jsx(ne,{id:"thread-log-retention-enabled",checked:a!==null,disabled:u!==null,"aria-label":t("settings.threadCleanup.retention.title"),onClick:()=>v(a===null)})}),e.jsx(L,{title:t("settings.threadCleanup.cap.title"),subtitle:i!==null?e.jsxs(e.Fragment,{children:[t("settings.threadCleanup.cap.short"),I("cap")]}):t("settings.threadCleanup.cap.plain"),message:F("cap"),children:e.jsx(ne,{id:"thread-log-cap-enabled",checked:i!==null,disabled:u!==null,"aria-label":t("settings.threadCleanup.cap.title"),onClick:()=>w(i===null)})})]})})}const Dt=[{id:"anthropic",label:"Anthropic",color:"#D97757",pattern:/claude|anthropic|sonnet|opus|haiku/i},{id:"openai",label:"OpenAI",color:"#0C9A76",pattern:/(?:^|[-_/])gpt(?:\d|[-_.]|$)|openai|chatgpt|codex|^o[134](?:-|$)/i},{id:"xai",label:"xAI",color:"#7D8794",pattern:/grok|xai/i},{id:"deepseek",label:"DeepSeek",color:"#4C7DFF",pattern:/deepseek/i},{id:"google",label:"Google",color:"#9A6BE0",pattern:/gemini|google|gemma/i},{id:"qwen",label:"Qwen",color:"#D0634A",pattern:/qwen|tongyi|qwq/i},{id:"mistral",label:"Mistral",color:"#B88A12",pattern:/mistral|codestral|devstral|magistral|pixtral/i},{id:"meta",label:"Meta",color:"#D8578F",pattern:/llama|meta-|^meta$/i},{id:"kimi",label:"Kimi",color:"#1E93AA",pattern:/kimi|moonshot/i},{id:"zai",label:"Z.ai",color:"#7274F2",pattern:/glm|zhipu|z-ai|chatglm/i},{id:"minimax",label:"MiniMax",color:"#E05C7A",pattern:/minimax/i},{id:"cohere",label:"Cohere",color:"#B563D0",pattern:/command-r|cohere|(?:^|[-/])aya(?:[-/]|$)/i},{id:"perplexity",label:"Perplexity",color:"#2F97A6",pattern:/sonar|perplexity/i},{id:"amazon",label:"Amazon",color:"#C77C02",pattern:/nova|amazon|titan/i},{id:"microsoft",label:"Microsoft",color:"#2C90DE",pattern:/(?:^|[-/])phi|microsoft/i},{id:"nvidia",label:"NVIDIA",color:"#5E8C00",pattern:/nemotron|nvidia/i},{id:"opencode",label:"OpenCode",color:"#6F8B9A",pattern:/opencode|big-pickle|crouton|beam/i},{id:"nous",label:"Nous Research",color:"#8A6FD1",pattern:/hermes/i},{id:"cursor",label:"Cursor",color:"#74818C",pattern:/cursor|composer/i},{id:"factory",label:"Factory",color:"#7B8794",pattern:/droid/i},{id:"greenference",label:"Greenference",color:"#3F8F5F",pattern:/greenference/i},{id:"unknown",label:"Other",color:"#76828F",pattern:/(?!)/}];Dt.map(s=>s.color);const ix=[[/claude|anthropic/i,"anthropic"],[/codex|openai/i,"openai"],[/grok|xai/i,"xai"],[/opencode/i,"opencode"],[/gemini|antigravity/i,"google"],[/qwen/i,"qwen"],[/kimi/i,"kimi"],[/mistral/i,"mistral"],[/deepseek/i,"deepseek"],[/copilot/i,"microsoft"],[/cursor/i,"cursor"],[/command/i,"cohere"],[/droid/i,"factory"],[/hermes/i,"nous"],[/greenference/i,"greenference"]],Oa=/^(?:opencode-go|opencode|zen|openrouter|vercel|groq|fireworks(?:-ai)?|together(?:_ai)?|deepinfra|cerebras|togetherai|ollama|lmstudio|local)\//,Fa=/^(?:anthropic|openai|google|meta-llama|meta|mistralai|deepseek|qwen|moonshotai|moonshot|x-ai|xai|z-ai|zhipu|minimax|cohere|perplexity|amazon|nvidia|nousresearch|microsoft|cursor|factory)\//;function Mr(s){if(!s.startsWith("model:"))return s;const n=s.slice(6),a=n.indexOf("/");return a===-1?n:n.slice(a+1)}function rx(s){if(!s.startsWith("model:"))return;const n=s.slice(6),a=n.indexOf("/");return a===-1?void 0:n.slice(0,a)}function Dr(s){let n=s.trim().toLowerCase();for(Oa.test(n)&&(n=n.replace(Oa,""));Fa.test(n);)n=n.replace(Fa,"");return n.replace(/(?::|-)(?:free|beta|preview|latest)$/,"")}function zr(s){const n=Dr(Mr(s)),a=Dt.find(c=>c.id!=="unknown"&&c.pattern.test(n));if(a)return a;const i=rx(s),r=i&&ix.find(([c])=>c.test(i))?.[1];return Dt.find(c=>c.id===r)??Dt.find(c=>c.id==="unknown")}function lx(s){let n=2166136261;for(let a=0;a<s.length;a+=1){let i=s.charCodeAt(a);i=Math.imul(i,3432918353),i=i<<15|i>>>17,i=Math.imul(i,461845907),n^=i,n=n<<13|n>>>19,n=Math.imul(n,5)+3864292196>>>0}return n^=s.length,n^=n>>>16,n=Math.imul(n,2246822507),n^=n>>>13,n=Math.imul(n,3266489909),n^=n>>>16,n>>>0}const ox="shade428:",ut=[-7,-4.7,-2.3,0,2.3,4.7,7],Lt=[-.045,-.03,-.015,0,.015,.03,.045],vs=[.93,1,1.07],cx=["#ffffff","#3a322d"],dx=3.05;function Ua(s){return cx.every(n=>Mc(s,n)>=dx)}function ux(s,n){if(Ua(s))return s;const a=Vi(s);for(let i=0;i<=140;i+=1)for(const r of[-1,1]){const c=a.l+r*i*.002;if(c<.2||c>.95)continue;const l=Ji({...a,l:c});if(Ua(l))return l}return n}function px(s,n){const a=Vi(n.color),i=lx(`${ox}${s}`)%(ut.length*Lt.length*vs.length),r=a.h+ut[i%ut.length],c=a.l+Lt[Math.floor(i/ut.length)%Lt.length],l=a.c*vs[Math.floor(i/(ut.length*Lt.length))%vs.length];return ux(Ji({l:c,c:l,h:r}),n.color)}function yt(s){const n=zr(s);return px(Dr(Mr(s))||s.toLowerCase(),n)}function Ma(s,n,a){const i=s/10**a;try{return new Intl.NumberFormat(Ee(),{style:"currency",currency:n,minimumFractionDigits:a,maximumFractionDigits:a}).format(i)}catch{return`${i.toFixed(Math.min(a,100))} ${n}`}}function mx(s){return t("planUsage.spendAmounts",{used:Ma(s.usedMinor,s.currency,s.exponent),limit:Ma(s.limitMinor,s.currency,s.exponent)})}function xx(s,n){if(!s)return null;const a=Date.parse(s);if(!Number.isFinite(a)||a<=n)return null;const i=Math.floor((a-n)/6e4);if(i<1)return"less than a minute";const r=Math.floor(i/1440),c=Math.floor(i%1440/60),l=i%60;return r>0?c>0?`${r}d ${c}h`:`${r}d`:c>0?l>0?`${c}h ${l}m`:`${c}h`:`${l}m`}function gx(s,n,a){const i=[];for(const r of s.providers){if(!r.ok)continue;const c=[r.fiveHour.available?r.fiveHour.resetsAt:null,r.weekly.available?r.weekly.resetsAt:null,...r.extra.map(l=>l.resetsAt),...(r.models??[]).flatMap(l=>l.windows.map(d=>d.resetsAt))];for(const l of c){if(!l||a.has(l)||i.includes(l))continue;const d=Date.parse(l);Number.isFinite(d)&&d<=n&&i.push(l)}}return i}function hx(s){return s>=90?"bg-danger":s>=70?"bg-warning":"bg-success"}function Da(s){return s==="5-hour"?t("planUsage.fiveHour"):s==="Weekly"?t("planUsage.weekly"):s==="Monthly spend"?t("planUsage.monthlySpend"):s}function _r(s){const n=s.name.trim().toLowerCase();return n==="chatgpt plan"?t("planUsage.provider.chatgptPlan"):n==="claude (api key)"?t("planUsage.provider.claudeApiKey"):s.name}function fx(s){const n=s.error?.trim();if(!n)return null;const a=/^Sign in again in (.+)$/i.exec(n);return a?t("planUsage.signInAgain",{provider:_r({name:a[1]})}):n}function Rt({label:s,window:n,now:a,usedHeadline:i=!1,detail:r}){const c=n.available?xx(n.resetsAt,a):null,l=n.usedPercent??0,d=i?n.usedPercent==null?null:t("planUsage.used",{used:Math.round(n.usedPercent)}):n.remainingPercent==null?null:t("planUsage.left",{remaining:Math.round(n.remainingPercent)});return e.jsxs("div",{className:"grid grid-cols-[4.5rem_minmax(0,1fr)] items-center gap-x-3 gap-y-1",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:s}),n.available&&d?e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 text-[13px] text-ink",children:[e.jsx("span",{className:"tabular-nums",children:d}),r&&e.jsx("span",{"data-plan-spend":!0,className:"text-[12px] tabular-nums text-ink-secondary",children:r}),c&&e.jsx("span",{className:"text-[12px] text-ink-secondary",children:t("planUsage.resetsIn",{when:c})})]}),e.jsx("div",{className:"mt-1 h-1.5 overflow-hidden rounded-full bg-inset",role:"meter","aria-label":s,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(Math.min(100,Math.max(0,l))),children:e.jsx("div",{className:D("h-full rounded-full",hx(l)),style:{width:`${Math.min(100,Math.max(0,l))}%`}})})]}):e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("planUsage.notReported")})]})}function bx(){const[s,n]=o.useState(null),[a,i]=o.useState(!0),[r,c]=o.useState(""),[l,d]=o.useState(()=>Date.now()),u=o.useRef(new Set),p=o.useCallback(async(x=!1)=>{i(!0),c("");try{const m=await M(x?"/api/plan-usage?refresh=1":"/api/plan-usage");n(m),d(Date.now())}catch(m){c(m instanceof Error&&m.message?m.message:t("planUsage.fetchError"))}finally{i(!1)}},[]);return o.useEffect(()=>{p(!1)},[p]),o.useEffect(()=>{const x=window.setInterval(()=>d(Date.now()),3e4);return()=>window.clearInterval(x)},[]),o.useEffect(()=>{if(!s)return;const x=gx(s,l,u.current);if(x.length!==0){for(const m of x)u.current.add(m);p(!0)}},[s,l,p]),{report:s,loading:a,error:r,now:l,load:p}}function za(){const{report:s,loading:n,error:a,now:i,load:r}=bx();return o.useContext(Ae)&&(!s||s.providers.length===0)?e.jsx(J,{label:t("settings.spending.aiLimits"),block:"plan-usage",actions:e.jsxs("button",{type:"button",onClick:()=>{r(!0)},disabled:n,className:"settings-quiet flex cursor-pointer items-center gap-1.5",children:[n?e.jsx(re,{size:14,className:"animate-spin","aria-hidden":"true"}):e.jsx(bt,{size:14,"aria-hidden":"true"}),t("planUsage.refresh")]}),footnote:a?e.jsx("span",{role:"alert",className:"text-danger",children:a}):void 0,children:e.jsx(V,{children:e.jsx(Ne,{children:n&&!s?t("planUsage.loading"):t("planUsage.emptyShort")})})}):e.jsxs(pe,{title:t("planUsage.title"),subtitle:t("planUsage.subtitle"),children:[e.jsx("div",{className:"mb-3 flex justify-end",children:e.jsx("button",{type:"button",onClick:()=>{r(!0)},disabled:n,"aria-label":t("planUsage.refresh"),title:t("planUsage.refresh"),className:"rounded-md p-2 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:n?e.jsx(re,{size:14,className:"animate-spin"}):e.jsx(bt,{size:14})})}),n&&!s&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("planUsage.loading")}),a&&e.jsx("p",{role:"alert",className:"mb-3 text-[13px] text-danger",children:a}),s&&s.providers.length===0&&e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("planUsage.empty")}),s&&s.providers.length>0&&e.jsx("div",{className:"flex flex-col gap-4",children:s.providers.map(l=>e.jsxs("div",{className:"border-t border-hairline/30 pt-3 first:border-t-0 first:pt-0",children:[e.jsxs("div",{className:"mb-2 flex min-w-0 items-baseline gap-2",children:[e.jsx("span",{className:"truncate text-[14px] font-medium text-ink",children:_r(l)}),l.plan&&e.jsx("span",{className:"truncate text-[12px] text-ink-secondary",children:l.plan})]}),l.ok?e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(Rt,{label:t("planUsage.fiveHour"),window:l.fiveHour,now:i}),e.jsx(Rt,{label:t("planUsage.weekly"),window:l.weekly,now:i}),l.extra.map((d,u)=>e.jsx(Rt,{label:Da(d.label),now:i,usedHeadline:!!d.spend,detail:d.spend?mx(d.spend):void 0,window:{available:!0,remainingPercent:d.remainingPercent,usedPercent:d.usedPercent,resetsAt:d.resetsAt}},`${d.label}-${u}`)),(l.models??[]).length>0&&e.jsxs("div",{className:"mt-1 flex flex-col gap-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-[0.08em] text-ink-secondary",children:t("planUsage.byModel")}),(l.models??[]).map(d=>e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",children:d.name}),d.windows.map((u,p)=>e.jsx(Rt,{label:Da(u.label),now:i,usedHeadline:!0,window:{available:!0,remainingPercent:u.remainingPercent,usedPercent:u.usedPercent,resetsAt:u.resetsAt}},`${d.name}-${u.label}-${p}`))]},d.name))]})]}):e.jsx("p",{className:"text-[13px] text-danger",children:fx(l)})]},l.id))})]})}function _a(s,n){return s?.edition?.features?.includes(n)===!0}function vx(s){return s?s.exceeded?"danger":s.warn?"warning":"quiet":"quiet"}function yx({budget:s}){const{state:n,dispatch:a}=_(),i=n.config?.budgets??{},[r,c]=o.useState(i.monthlyUsd===void 0?"":String(i.monthlyUsd)),[l,d]=o.useState(i.warnAtPercent===void 0?"80":String(i.warnAtPercent)),[u,p]=o.useState(!1),[x,m]=o.useState(null);o.useEffect(()=>{c(i.monthlyUsd===void 0?"":String(i.monthlyUsd)),d(i.warnAtPercent===void 0?"80":String(i.warnAtPercent))},[i.monthlyUsd,i.warnAtPercent]);const g=async()=>{if(u)return;const h=r.trim()===""?0:Number(r),j=Number(l);if(!Number.isFinite(h)||h<0||!Number.isInteger(j)||j<1||j>100){m(t("usage.budget.invalid"));return}p(!0),m(null);try{const b=await M("/api/config",{method:"PUT",body:JSON.stringify({budgets:{monthlyUsd:h,warnAtPercent:j}})});a({type:"configStatus",config:b})}catch(b){m(b instanceof Error?b.message:String(b))}finally{p(!1)}},f=vx(s);return e.jsxs(pe,{title:t("usage.budget.title"),subtitle:t("usage.budget.subtitle"),children:[s?e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"mb-1 flex items-baseline justify-between text-[13px]",children:[e.jsx("span",{className:D(f==="danger"?"text-danger":f==="warning"?"text-warning":"text-ink"),children:s.exceeded?t("usage.budget.reached"):s.warn?t("usage.budget.nearing"):t("usage.budget.within")}),e.jsx("span",{className:"tabular-nums text-ink-secondary",children:t("usage.budget.spent",{spent:rt(s.spentUsd),cap:rt(s.monthlyUsd),percent:String(s.percent)})})]}),e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-inset",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.min(100,s.percent),children:e.jsx("div",{className:D("h-full rounded-full",f==="danger"?"bg-danger":f==="warning"?"bg-warning":"bg-accent"),style:{width:`${Math.min(100,s.percent)}%`}})})]}):e.jsx("p",{className:"mb-4 text-[13px] text-ink-secondary",children:t("usage.budget.none")}),e.jsxs("form",{className:"flex flex-wrap items-end gap-3",onSubmit:h=>{h.preventDefault(),g()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("usage.budget.monthly"),e.jsx("input",{value:r,onChange:h=>c(h.target.value),inputMode:"decimal",placeholder:"0","aria-label":t("usage.budget.monthly"),disabled:u,className:"w-32 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50"})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("usage.budget.warnAt"),e.jsx("input",{value:l,onChange:h=>d(h.target.value),inputMode:"numeric","aria-label":t("usage.budget.warnAt"),disabled:u,className:"w-20 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50"})]}),e.jsxs("button",{type:"submit",disabled:u,className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[u&&e.jsx(re,{size:13,className:"animate-spin"}),t("common.save")]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("usage.budget.hint")}),x&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:x})]})}function Ha(s){const n=Object.entries(s??{}).map(([a,i])=>({key:a,input:String(i.inputPerMillion),output:String(i.outputPerMillion),cached:i.cachedInputPerMillion===void 0?"":String(i.cachedInputPerMillion)}));return n.length?n:[{key:"default",input:"",output:"",cached:""}]}function jx(){const{state:s,dispatch:n}=_(),a=s.config?.billing,[i,r]=o.useState(a?.currency??"USD"),[c,l]=o.useState(Ha(a?.prices)),[d,u]=o.useState(!1),[p,x]=o.useState(null);o.useEffect(()=>{r(a?.currency??"USD"),l(Ha(a?.prices))},[a]);const m=(h,j)=>l(b=>b.map((y,v)=>v===h?{...y,...j}:y)),g=async()=>{if(d)return;const h={};for(const j of c){const b=j.key.trim();if(!b)continue;const y=Number(j.input),v=Number(j.output),w=j.cached.trim()===""?void 0:Number(j.cached);if(!Number.isFinite(y)||!Number.isFinite(v)||y<0||v<0||w!==void 0&&(!Number.isFinite(w)||w<0)){x(t("usage.prices.invalid",{model:b}));return}h[b]={inputPerMillion:y,outputPerMillion:v,...w===void 0?{}:{cachedInputPerMillion:w}}}if(!/^[A-Z]{3}$/.test(i.trim().toUpperCase())){x(t("usage.prices.currencyInvalid"));return}u(!0),x(null);try{const j=await M("/api/config",{method:"PUT",body:JSON.stringify({billing:{currency:i.trim().toUpperCase(),prices:h}})});n({type:"configStatus",config:j})}catch(j){x(j instanceof Error?j.message:String(j))}finally{u(!1)}},f="w-full rounded-lg border border-hairline/40 bg-inset px-2 py-1.5 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50";return e.jsxs(pe,{title:t("usage.prices.title"),subtitle:t("usage.prices.subtitle"),children:[e.jsx("div",{className:"mb-3 flex items-center gap-2 text-[12px] text-ink-secondary",children:e.jsxs("label",{className:"flex items-center gap-2",children:[t("usage.prices.currency"),e.jsx("input",{value:i,onChange:h=>r(h.target.value),maxLength:3,"aria-label":t("usage.prices.currency"),disabled:d,className:"w-16 rounded-lg border border-hairline/40 bg-inset px-2 py-1.5 text-[13px] uppercase text-ink focus:outline-none disabled:opacity-50"})]})}),e.jsxs("div",{className:"grid grid-cols-[1fr_5rem_5rem_5rem_auto] items-center gap-x-2 gap-y-1.5 text-[12px] font-medium uppercase tracking-wide text-ink-secondary",children:[e.jsx("span",{children:t("usage.prices.colModel")}),e.jsx("span",{children:t("usage.prices.colInput")}),e.jsx("span",{children:t("usage.prices.colOutput")}),e.jsx("span",{children:t("usage.prices.colCached")}),e.jsx("span",{}),c.map((h,j)=>e.jsxs("div",{className:"contents",children:[e.jsx("input",{value:h.key,onChange:b=>m(j,{key:b.target.value}),placeholder:t("usage.prices.modelPlaceholder"),"aria-label":t("usage.prices.colModel"),disabled:d,className:D(f,"font-mono normal-case tracking-normal")}),e.jsx("input",{value:h.input,onChange:b=>m(j,{input:b.target.value}),inputMode:"decimal","aria-label":t("usage.prices.colInput"),disabled:d,className:f}),e.jsx("input",{value:h.output,onChange:b=>m(j,{output:b.target.value}),inputMode:"decimal","aria-label":t("usage.prices.colOutput"),disabled:d,className:f}),e.jsx("input",{value:h.cached,onChange:b=>m(j,{cached:b.target.value}),inputMode:"decimal",placeholder:"—","aria-label":t("usage.prices.colCached"),disabled:d,className:f}),e.jsx("button",{type:"button",onClick:()=>l(b=>b.filter((y,v)=>v!==j)),"aria-label":t("usage.prices.remove"),disabled:d,className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(We,{size:13})})]},j))]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>l(h=>[...h,{key:"",input:"",output:"",cached:""}]),disabled:d,className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:[e.jsx($e,{size:13}),t("usage.prices.add")]}),e.jsxs("button",{type:"button",onClick:()=>{g()},disabled:d,className:"ml-auto flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[d&&e.jsx(re,{size:13,className:"animate-spin"}),t("common.save")]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("usage.prices.hint")}),p&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:p})]})}function $a({budget:s}){const{state:n}=_(),a=_a(n.config,"budgets"),i=_a(n.config,"billing");return!a&&!i?null:e.jsxs(e.Fragment,{children:[a&&e.jsx(yx,{budget:s}),i&&e.jsx(jx,{})]})}const xn=[{field:"dailyUsd",label:"usage.caps.dailyUsd",whole:!1},{field:"dailyTokens",label:"usage.caps.dailyTokens",whole:!0},{field:"monthlyUsd",label:"usage.caps.monthlyUsd",whole:!1},{field:"monthlyTokens",label:"usage.caps.monthlyTokens",whole:!0}],zt=s=>Object.fromEntries(xn.map(({field:n})=>[n,s?.[n]?String(s[n]):""]));function Ka(s){const n={};for(const{field:a,whole:i}of xn){const r=s[a].trim().replace(/,/g,"");if(r==="")continue;const c=Number(r);if(!Number.isFinite(c)||c<0||i&&!Number.isInteger(c))return null;c>0&&(n[a]=c)}return n}const kx=s=>s.reached?"danger":s.warn?"warning":"quiet",Wa=(s,n)=>s.unit==="usd"?rt(n):t("usage.caps.tokens",{count:ns(Math.round(n))}),wx=s=>new Date(s).toLocaleString(Ai(Ee()),{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"});function Nx({cap:s,name:n}){const a=kx(s);return e.jsxs("li",{"data-testid":"usage-cap","data-cap":s.id,children:[e.jsxs("div",{className:"mb-1 flex flex-wrap items-baseline justify-between gap-x-3 text-[13px]",children:[e.jsx("span",{className:"text-ink",children:t(s.period==="day"?"usage.caps.useDay":"usage.caps.useMonth",{who:n})}),e.jsx("span",{className:"tabular-nums text-ink-secondary",children:t("usage.caps.used",{used:Wa(s,s.used),limit:Wa(s,s.limit),percent:String(s.percent)})})]}),e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-inset",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.min(100,s.percent),children:e.jsx("div",{className:D("h-full rounded-full",a==="danger"?"bg-danger":a==="warning"?"bg-warning":"bg-accent"),style:{width:`${Math.min(100,s.percent)}%`}})}),a!=="quiet"&&e.jsx("p",{className:D("mt-1 text-[12px]",a==="danger"?"text-danger":"text-warning"),children:s.reached?t("usage.caps.reached",{resets:wx(s.resetsAt)}):t("usage.caps.nearing",{percent:String(s.percent)})})]})}const Sx="w-28 rounded-lg border border-hairline/40 bg-inset px-2 py-1.5 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50";function Ga({who:s,draft:n,locked:a,disabled:i,onChange:r}){return e.jsx("div",{className:"flex flex-wrap items-end gap-2",children:xn.map(({field:c,label:l,whole:d})=>e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t(l),e.jsx("input",{value:n[c],onChange:u=>r(c,u.target.value),inputMode:d?"numeric":"decimal",placeholder:t("usage.caps.noCap"),"aria-label":`${s}: ${t(l)}`,disabled:i||a?.includes(c),className:Sx})]},c))})}function qa({view:s,onSaved:n}){return s?e.jsx(Ex,{view:s,onSaved:n}):null}const Va=s=>({...s.server,...s.env.values?.server});function Cx(s,n,a,i){const r={...a};for(const c of s.env.server){const l=s.server[c];l===void 0?delete r[c]:r[c]=l}return{stops:s.env.stops?s.savedStops??"unattended":n,server:r,bots:i}}const Ja=s=>Object.entries(s.bots).map(([n,a])=>({botId:n,draft:zt(a)}));function Ex({view:s,onSaved:n}){const{state:a}=_(),[i,r]=o.useState(s.stops),[c,l]=o.useState(()=>zt(Va(s))),[d,u]=o.useState(()=>Ja(s)),[p,x]=o.useState(!1),[m,g]=o.useState(null),f=JSON.stringify([s.stops,s.server,s.bots,s.env]);o.useEffect(()=>{r(s.stops),l(zt(Va(s))),u(Ja(s))},[f]);const h=y=>a.bots?.find(v=>v.id===y)?.name??t("usage.caps.goneBot"),j=(a.bots??[]).filter(y=>!y.hidden&&!d.some(v=>v.botId===y.id)),b=async()=>{if(p)return;const y=Ka(c),v=d.map(w=>[w.botId,Ka(w.draft)]);if(!y||v.some(([,w])=>!w)){g(t("usage.caps.invalid"));return}x(!0),g(null);try{await M("/api/usage/caps",{method:"PUT",body:JSON.stringify(Cx(s,i,y,Object.fromEntries(v)))}),n?.()}catch(w){g(w instanceof Error?w.message:String(w))}finally{x(!1)}};return e.jsxs(pe,{title:t("usage.caps.title"),subtitle:t("usage.caps.subtitle"),children:[s.caps.length?e.jsx("ul",{className:"mb-4 flex flex-col gap-3",children:s.caps.map(y=>e.jsx(Nx,{cap:y,name:y.scope==="server"?t("usage.caps.server"):h(y.botId)},y.id))}):e.jsx("p",{className:"mb-4 text-[13px] text-ink-secondary",children:t("usage.caps.none")}),e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:y=>{y.preventDefault(),b()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("usage.caps.stops"),e.jsxs(ce,{size:"sm",className:"w-full max-w-md",value:i,onChange:y=>r(y.target.value),disabled:p||s.env.stops,children:[e.jsx("option",{value:"unattended",children:t("usage.caps.stopsUnattended")}),e.jsx("option",{value:"everything",children:t("usage.caps.stopsEverything")})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-1.5 text-[13px] text-ink",children:t("usage.caps.server")}),e.jsx(Ga,{who:t("usage.caps.server"),draft:c,locked:s.env.server,disabled:p,onChange:(y,v)=>l(w=>({...w,[y]:v}))}),(s.env.server.length>0||s.env.stops)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("usage.caps.fromEnv")})]}),d.map(y=>e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-2 text-[13px] text-ink",children:[h(y.botId),e.jsx("button",{type:"button",onClick:()=>u(v=>v.filter(w=>w.botId!==y.botId)),"aria-label":t("usage.caps.removeBot",{bot:h(y.botId)}),disabled:p,className:"rounded-md p-1 text-ink-secondary hover:bg-control hover:text-danger disabled:opacity-50",children:e.jsx(We,{size:13})})]}),e.jsx(Ga,{who:h(y.botId),draft:y.draft,disabled:p,onChange:(v,w)=>u(N=>N.map(C=>C.botId===y.botId?{...C,draft:{...C.draft,[v]:w}}:C))})]},y.botId)),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[j.length>0&&e.jsxs("label",{className:"flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx($e,{size:13}),e.jsxs(ce,{size:"sm",value:"",onChange:y=>{const v=y.target.value;v&&u(w=>[...w,{botId:v,draft:zt(void 0)}])},disabled:p,"aria-label":t("usage.caps.addBot"),children:[e.jsx("option",{value:"",children:t("usage.caps.addBot")}),j.map(y=>e.jsx("option",{value:y.id,children:y.name},y.id))]})]}),e.jsxs("button",{type:"submit",disabled:p,className:"ml-auto flex items-center gap-1.5 rounded-lg bg-raised px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",children:[p&&e.jsx(re,{size:13,className:"animate-spin"}),t("common.save")]})]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("usage.caps.hint")}),m&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:m})]})}const Hr=["model","user","department","day","engine","routine"];function Ya({summary:s}){const n=s?.notBilled?.usd??0,a=s?.total?.unpriced??0;return!(n>0)&&!a?null:e.jsxs("div",{"data-testid":"usage-caveats",className:"flex flex-col gap-0.5 px-1 text-[12px] leading-5 text-ink-secondary",children:[n>0&&e.jsx("p",{children:t("usage.page.notBilled",{cost:Ve(n)})}),a>0&&e.jsx("p",{children:t("usage.page.unpriced",{count:String(a)})})]})}const Us={bot:"usage.history.byBot",model:"usage.history.byModel",user:"usage.history.byUser",day:"usage.history.byDay",engine:"usage.history.byEngine",routine:"usage.history.byRoutine",department:"usage.history.byDepartment"},Xa={today:"usage.page.today",week:"usage.page.week",month:"usage.history.thisMonth",lastMonth:"usage.history.lastMonth",days30:"usage.history.last30Days"},Ax=2e3;function $r(s,n){return n.key==="routine:private"?t("usage.history.privateRoutine"):n.key==="bot:private"?t("usage.history.privateBot"):s==="routine"?n.key==="manual"?t("usage.history.notRoutine"):n.label:s==="department"?n.label||t("usage.history.noDepartment"):s!=="user"?n.label:n.key==="owner"?t("usage.history.owner"):n.key==="bot"?t("usage.history.botToBot"):n.key.startsWith("routine:")?t("usage.history.routine",{name:n.label.replace(/^Routine: /,"")}):n.label}function ze(s){return s.barTokens??st(s)}function Vt(s,n,a,i){const[r,c]=o.useState(null);return o.useEffect(()=>{let l=!0;return M(`/api/usage?from=${encodeURIComponent(s.from)}&to=${encodeURIComponent(s.to)}&groupBy=${n}${i?`&splitBy=${i}`:""}`).then(d=>{l&&c(d)}).catch(()=>{l&&c(null)}),()=>{l=!1}},[s.from,s.to,n,i,a]),r}function Px({group:s,width:n,color:a}){const{state:i}=_(),r=s.segments??[],c=r.reduce((l,d)=>l+ze(d),0);return r.length&&c>0?e.jsx("span",{className:"flex h-full",style:{width:`${n}%`},children:r.map(l=>{const d=ze(l),u=Math.round(d/c*100);return e.jsx("span",{className:"h-full","data-model-color":yt(l.key),style:{width:`${d/c*100}%`,backgroundColor:yt(l.key)},title:`${as(l.label,i.instances)} · ${ns(d)} · ${u}%`},l.key)})}):e.jsx("span",{"data-model-color":a,className:D("block h-full rounded-full",!a&&"bg-accent/70"),style:{width:`${n}%`,backgroundColor:a}})}function Qa({groupBy:s,groups:n}){const{state:a}=_(),i=o.useContext(Ae),r=[...n].sort((l,d)=>ze(d)-ze(l)).slice(0,6),c=Math.max(...r.map(ze),0);return!r.length||c<=0?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("usage.page.whereEmpty")}):e.jsx("ul",{className:"flex flex-col gap-2.5",children:r.map(l=>{const d=s==="bot"?a.bots.find(x=>`bot:${x.id}`===l.key):void 0,u=!i&&s==="model"?zr(l.key):void 0,p=u?yt(l.key):void 0;return e.jsxs("li",{className:"grid grid-cols-[minmax(0,9rem)_1fr_auto] items-center gap-3 text-[13px]",title:t("usage.page.turns",{count:String(l.turns)}),children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2 text-ink",children:[d&&e.jsx(Xt,{bot:d,state:"idle",size:18,animated:!1}),u&&e.jsx("span",{"aria-hidden":"true",title:u.label,"data-model-color":p,className:"size-2 shrink-0 rounded-full",style:{backgroundColor:p}}),e.jsx("span",{className:"truncate",children:d?d.name:s==="model"?as(l.label,a.instances):$r(s,l)})]}),e.jsx("span",{className:D("h-2 overflow-hidden rounded-full",i?"bg-ink/[0.08]":"bg-raised"),children:i?e.jsx("span",{className:"block h-full rounded-full bg-ink",style:{width:`${Math.max(2,ze(l)/c*100)}%`}}):e.jsx(Px,{group:l,width:Math.max(2,ze(l)/c*100),color:p})}),e.jsxs("span",{className:"min-w-[4.5rem] text-right tabular-nums text-ink-secondary",children:[ns(ze(l)),it(l.costUsd)&&l.costUsd>0&&` · ${Ve(l.costUsd)}`]})]},l.key)})})}function Tx({groups:s}){const{state:n}=_(),a=new Map;for(const r of s)for(const c of r.segments??[]){const l=a.get(c.key);a.set(c.key,{label:c.label,tokens:(l?.tokens??0)+st(c)})}const i=[...a.entries()].sort((r,c)=>c[1].tokens-r[1].tokens);return i.length<2?null:e.jsx("ul",{className:"mt-3 flex flex-wrap gap-x-3 gap-y-1",children:i.map(([r,c])=>e.jsxs("li",{className:"flex min-w-0 items-center gap-1.5 text-[11px] text-ink-secondary",children:[e.jsx("span",{"aria-hidden":"true","data-model-color":yt(r),className:"size-2 shrink-0 rounded-full",style:{backgroundColor:yt(r)}}),e.jsx("span",{className:"max-w-[9rem] truncate",children:as(c.label,n.instances)})]},r))})}function Ix({range:s,version:n,onSummary:a}){const[i,r]=o.useState("model"),c=o.useContext(Ae),l=Vt(s,"bot",n,"model"),d=Vt(s,i,n,i==="model"?void 0:"model");return o.useEffect(()=>{a(l)},[l,a]),c?null:e.jsxs("section",{className:"rounded-2xl border border-hairline/50 bg-card p-5","aria-label":t("usage.page.where"),children:[e.jsx("h3",{className:"text-[15px] font-medium text-ink",children:t("usage.page.where")}),e.jsxs("div",{className:"mt-4 grid gap-6 md:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"mb-3 text-[11px] font-medium uppercase tracking-[0.08em] text-ink-secondary",children:t(Us.bot)}),l?e.jsxs(e.Fragment,{children:[e.jsx(Qa,{groupBy:"bot",groups:l.groups}),e.jsx(Tx,{groups:l.groups})]}):e.jsx(re,{size:14,className:"animate-spin text-ink-secondary"})]}),e.jsxs("div",{children:[e.jsx("div",{role:"tablist","aria-label":t("usage.history.groupBy"),className:"-mt-1 mb-2 flex flex-wrap gap-1",children:Hr.map(u=>e.jsx("button",{type:"button",role:"tab","aria-selected":i===u,onClick:()=>r(u),className:D("rounded-md px-2 py-0.5 text-[11px] font-medium uppercase tracking-[0.06em]",i===u?"bg-accent/12 text-accent":"text-ink-secondary hover:bg-raised/60 hover:text-ink"),children:t(Us[u])},u))}),d?.groupBy===i?e.jsx(Qa,{groupBy:i,groups:d.groups}):e.jsx(re,{size:14,className:"animate-spin text-ink-secondary"})]})]})]})}const Lx=["bot",...Hr];function Rx({range:s,version:n,onSummary:a}){const{state:i}=_(),[r,c]=o.useState("bot"),l=Vt(s,"bot",n),d=Vt(s,r,n);o.useEffect(()=>{a(l)},[l,a]);const u=d?.groupBy===r?[...d.groups].sort((p,x)=>st(x)-st(p)).filter(p=>st(p)>0).slice(0,8):null;return e.jsx(J,{label:t("usage.page.where"),block:"where",actions:e.jsx(ce,{value:r,onChange:p=>c(p.target.value),"aria-label":t("usage.history.groupBy"),children:Lx.map(p=>e.jsx("option",{value:p,children:t(Us[p])},p))}),children:e.jsx(V,{children:u?u.length===0?e.jsxs(Ne,{children:[e.jsx(Pi,{state:"sleep",size:48,className:"me-3"}),t("usage.page.whereEmpty")]}):u.map(p=>e.jsx(L,{title:r==="model"?as(p.label,i.instances):$r(r,p),subtitle:t("usage.page.turns",{count:String(p.turns)}),children:e.jsxs("span",{className:"text-[13px] leading-5 tabular-nums text-ink-secondary",children:[ns(st(p)),it(p.costUsd)&&p.costUsd>0?` · ${Ve(p.costUsd)}`:""]})},p.key)):e.jsx(Ne,{children:t("common.checking")})})})}function Bx(s){return new Date(s).toLocaleString(Ai(Ee()),{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}function Za({root:s,onOpen:n}){const{state:a}=_(),i=Hc(s,a.bots),r=s.bots.map(c=>$c(a.bots,c.id,c.name)).join(", ");return e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:n,className:"grid w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 rounded-xl px-3 py-2.5 text-left hover:bg-raised/50","data-testid":"usage-run",children:[e.jsx("span",{className:"flex w-[38px] shrink-0 -space-x-1.5 sm:w-[74px]",children:s.bots.slice(0,4).map((c,l)=>{const d=a.bots.find(u=>u.id===c.id);return d?e.jsx("span",{className:D("rounded-full ring-2 ring-card",l>1&&"hidden sm:block"),children:e.jsx(Xt,{bot:d,state:"idle",size:22,animated:!1})},c.id):e.jsx("span",{className:D("flex size-[22px] items-center justify-center rounded-full bg-raised text-[10px] font-semibold text-ink-secondary ring-2 ring-card",l>1&&"hidden sm:flex"),children:c.name.slice(0,1).toUpperCase()},c.id)})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-[14px] text-ink",children:i}),e.jsxs("span",{className:"block truncate text-[12px] text-ink-tertiary",children:[Bx(s.startedAt)," · ",r]})]}),e.jsxs("span",{className:"flex items-center gap-3 text-[13px] tabular-nums text-ink-secondary",children:[s.running&&e.jsx(Kc,{}),s.errors>0&&e.jsx("span",{className:"rounded-md bg-danger/12 px-1.5 py-0.5 text-[12px] font-medium text-danger",children:t("trace.groupErrors",{count:String(s.errors)})}),s.timed?e.jsx("span",{className:"hidden min-w-[3.5rem] text-right sm:inline",children:Yi(s.durationMs)}):e.jsx("span",{className:"hidden rounded bg-raised px-1.5 text-[11px] sm:inline",children:t("trace.notTimed")}),e.jsx("span",{className:"min-w-[3.5rem] text-right text-ink",children:Ve(s.costUsd)}),e.jsx(St,{size:14,className:"text-ink-tertiary"})]})]})})}function Ox(){const s=o.useContext(Ae),[n,a]=o.useState("month"),i=o.useMemo(()=>Mi(n),[n]),[r,c]=o.useState(null),[l,d]=o.useState(null),[u,p]=o.useState(0),[x,m]=o.useState(null),g=x?.budget??null,[f,h]=o.useState(null),j=o.useRef(null);o.useEffect(()=>{let v=!0;return Is(i).then(w=>{v&&(c(w),d(null))}).catch(w=>{v&&d(w instanceof Error?w.message:String(w))}),()=>{v=!1}},[i,u]),o.useEffect(()=>Dc({onFrame:v=>{if(v.kind!=="runtime"||j.current)return;const w=v.event?.type;w!=="turn.started"&&w!=="turn.completed"||(j.current=setTimeout(()=>{j.current=null,p(N=>N+1)},Ax))},onMissedFrames:()=>p(v=>v+1)}),[]),o.useEffect(()=>()=>{j.current&&clearTimeout(j.current)},[]);const b=()=>{r?.next&&Is(i,r.next).then(v=>c(w=>w?{...v,roots:[...w.roots,...v.roots]}:v))},y=r?.roots.some(v=>!v.timed);if(s){const v=r?.totals;return e.jsxs("div",{className:"flex flex-col gap-6","data-testid":"usage-page",children:[f?e.jsx(Xn,{id:f.id,at:f.at,actions:e.jsxs("button",{type:"button",onClick:()=>h(null),className:"settings-quiet flex shrink-0 cursor-pointer items-center gap-1",children:[e.jsx(Qn,{size:13}),t("trace.back")]})}):e.jsxs(e.Fragment,{children:[e.jsx(J,{label:t("usage.page.summary"),block:"totals",actions:e.jsx(ce,{value:n,onChange:w=>{a(w.target.value),h(null)},"aria-label":t("usage.history.period"),children:Zn.map(w=>e.jsx("option",{value:w,children:t(Xa[w])},w))}),footnote:l?e.jsx("span",{role:"alert",className:"text-danger",children:l}):void 0,children:e.jsx(V,{children:e.jsx("div",{"data-testid":"usage-totals",className:"contents",children:v?e.jsxs(e.Fragment,{children:[e.jsx(L,{title:t("trace.stat.cost"),children:e.jsx("span",{className:"text-[13px] leading-5 tabular-nums text-ink-secondary",children:v.costUsd?t("usage.page.estimated",{cost:Ve(v.costUsd)}):Ve(0)})}),e.jsx(L,{title:t("usage.page.runs"),children:e.jsxs("span",{className:"text-[13px] leading-5 tabular-nums text-ink-secondary",children:[String(r.roots.length),r.next!==void 0?"+":""]})}),e.jsx(L,{title:t("trace.stat.errors"),children:e.jsx("span",{className:"text-[13px] leading-5 tabular-nums text-ink-secondary",children:String(v.errors)})}),e.jsx(L,{title:t("trace.stat.time"),children:e.jsx("span",{className:"text-[13px] leading-5 tabular-nums text-ink-secondary",children:v.durationMs>0?Yi(Math.max(1e3,v.durationMs)):"—"})})]}):e.jsx(Ne,{children:t("common.checking")})})})}),e.jsx(Ya,{summary:x}),e.jsx(Rx,{range:i,version:u,onSummary:m}),e.jsx(J,{label:t("usage.page.runs"),block:"runs",footnote:y?t("usage.page.untimedNote"):void 0,actions:e.jsx("a",{href:ea(i),download:!0,className:"ui-button ui-button-md rounded-full",children:t("usage.history.export")}),children:e.jsxs(V,{children:[r&&!r.roots.length&&e.jsx(Ne,{children:t("usage.page.runsEmpty")}),r?.roots.length?e.jsx("ul",{className:"flex flex-col p-1",children:r.roots.map(w=>e.jsx(Za,{root:w,onOpen:()=>h({id:w.id,at:w.startedAt})},w.id))}):null,r?.next!==void 0&&e.jsx("div",{className:"px-4 py-2",children:e.jsx("button",{type:"button",onClick:b,className:"settings-quiet cursor-pointer",children:t("usage.page.more")})})]})})]}),e.jsx(za,{}),e.jsx(qa,{view:x?.caps,onSaved:()=>p(w=>w+1)}),e.jsx($a,{budget:g})]})}return e.jsxs("div",{className:"flex flex-col gap-4","data-testid":"usage-page",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-4",children:[e.jsx("p",{className:"min-w-0 flex-1 text-[13px] leading-relaxed text-ink-secondary",children:t("usage.page.subtitle")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{size:"sm",value:n,onChange:v=>{a(v.target.value),h(null)},"aria-label":t("usage.history.period"),children:Zn.map(v=>e.jsx("option",{value:v,children:t(Xa[v])},v))}),e.jsxs("a",{href:ea(i),download:!0,className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink",children:[e.jsx($i,{size:13}),t("usage.history.export")]})]})]}),l&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:l}),f?e.jsx(Xn,{id:f.id,at:f.at,actions:e.jsxs("button",{type:"button",onClick:()=>h(null),className:"flex shrink-0 items-center gap-1 rounded-lg px-2 py-1 text-[13px] text-ink-secondary hover:bg-raised hover:text-ink",children:[e.jsx(Qn,{size:13}),t("trace.back")]})}):e.jsxs(e.Fragment,{children:[e.jsx("section",{className:"overflow-hidden rounded-2xl border border-hairline/50 bg-card","data-testid":"usage-totals",children:r?e.jsx(zc,{items:_c(r.totals,t("trace.stat.time"))}):e.jsxs("div",{className:"flex items-center gap-2 p-5 text-[13px] text-ink-secondary",children:[e.jsx(re,{size:14,className:"animate-spin"}),t("common.checking")]})}),e.jsx(Ya,{summary:x}),e.jsx(Ix,{range:i,version:u,onSummary:m}),e.jsxs("section",{className:"rounded-2xl border border-hairline/50 bg-card p-2","aria-label":t("usage.page.runs"),children:[e.jsxs("div",{className:"px-3 pb-1 pt-3",children:[e.jsx("h3",{className:"text-[15px] font-medium text-ink",children:t("usage.page.runs")}),e.jsx("p",{className:"mt-0.5 text-[13px] text-ink-secondary",children:t("usage.page.runsHint")})]}),r&&!r.roots.length&&e.jsx("p",{className:"px-3 py-3 text-[13px] text-ink-secondary",children:t("usage.page.runsEmpty")}),e.jsx("ul",{className:"mt-1 flex flex-col",children:r?.roots.map(v=>e.jsx(Za,{root:v,onOpen:()=>h({id:v.id,at:v.startedAt})},v.id))}),r?.next!==void 0&&e.jsx("button",{type:"button",onClick:b,className:"m-2 rounded-lg px-3 py-1.5 text-[13px] text-accent hover:bg-raised/50",children:t("usage.page.more")}),y&&e.jsx("p",{className:"px-3 pb-3 pt-1 text-[12px] text-ink-tertiary",children:t("usage.page.untimedNote")})]})]}),e.jsx(za,{}),e.jsx(qa,{view:x?.caps,onSaved:()=>p(v=>v+1)}),e.jsx($a,{budget:g})]})}const Fx=Wc,Ms="w-full min-w-0 rounded-lg border border-hairline/60 bg-inset px-3 py-1.5 text-[13px] text-ink outline-none placeholder:text-ink-tertiary focus:border-accent disabled:opacity-60",Ds="flex flex-col gap-1 text-[12px] font-medium text-ink-secondary";function Kr({onSubmit:s,onCancel:n,pending:a,error:i,submitLabel:r,children:c,form:l}){return e.jsxs("form",{onSubmit:s,className:"flex flex-col gap-2.5","aria-busy":a,[`data-${l}`]:"",children:[c,e.jsxs("p",{className:"flex items-start gap-1 text-[12px] leading-snug text-ink-tertiary",children:[e.jsx(Xi,{size:11,"aria-hidden":"true",className:"mt-[3px] shrink-0"})," ",t("settings.vault.secret.private")]}),i&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:i}),e.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:n,disabled:a,className:"ui-button ui-button-md",children:t("logins.cancel")}),e.jsxs("button",{type:"submit",disabled:a,className:"ui-button ui-button-md ui-button-primary inline-flex items-center gap-1.5",children:[a&&e.jsx(re,{size:13,className:"animate-spin"}),r]})]})]})}function ei({secret:s,bots:n,onCancel:a,onSaved:i}){const[r,c]=o.useState(s?.name??""),[l,d]=o.useState(""),[u,p]=o.useState(s?.bots??"all"),[x,m]=o.useState(!1),[g,f]=o.useState(null),h=async j=>{if(j.preventDefault(),!x){m(!0),f(null);try{s?await Gc(s.id,{...r.trim()!==s.name?{name:r.trim()}:{},value:l,bots:u}):await qc(r.trim(),l,u),d(""),await i()}catch(b){f(b instanceof Error&&b.message?b.message:t("settings.vault.secret.saveError"))}finally{m(!1)}}};return e.jsxs(Kr,{form:"secret-form",onSubmit:j=>{h(j)},onCancel:a,pending:x,error:g,submitLabel:t(s?"settings.logins.saveChange":"settings.vault.secret.save"),children:[e.jsxs("label",{className:Ds,children:[t("settings.vault.secret.name"),e.jsx("input",{name:"secretName",type:"text",autoComplete:"off",spellCheck:!1,required:!0,maxLength:Fx,value:r,autoFocus:!0,placeholder:t("settings.vault.secret.namePlaceholder"),onChange:j=>c(j.target.value),disabled:x,className:Ms}),e.jsx("span",{className:"text-[12px] font-normal leading-snug text-ink-tertiary",children:t("settings.vault.secret.nameHint")})]}),e.jsxs("label",{className:Ds,children:[t(s?"settings.vault.secret.valueKeep":"settings.vault.secret.value"),e.jsx("input",{name:"secretValue",type:"password",autoComplete:"new-password",spellCheck:!1,required:!s,value:l,placeholder:"••••••••",onChange:j=>d(j.target.value),disabled:x,className:Ms})]}),e.jsx(lt,{value:u,onChange:p,bots:n,disabled:x})]})}function Ux({bots:s,onCancel:n,onSaved:a}){const[i,r]=o.useState(""),[c,l]=o.useState("all"),[d,u]=o.useState(!1),[p,x]=o.useState(null),[m,g]=o.useState(null),f=async h=>{if(h.preventDefault(),d)return;const j=Vc(i);if(!j.length){x(t("settings.vault.env.none"));return}u(!0),x(null),g(null);try{g(await Jc(j,c)),r("")}catch(b){x(b instanceof Error&&b.message?b.message:t("settings.vault.secret.saveError"))}finally{u(!1),await a().catch(()=>{})}};return e.jsxs(Kr,{form:"env-form",onSubmit:h=>{f(h)},onCancel:n,pending:d,error:p,submitLabel:t("settings.vault.env.submit"),children:[e.jsxs("label",{className:Ds,children:[t("settings.vault.env.label"),e.jsx("textarea",{name:"envText",rows:5,autoComplete:"off",spellCheck:!1,autoFocus:!0,value:i,onChange:h=>r(h.target.value),disabled:d,placeholder:"STRIPE_SECRET_KEY=…",dir:"ltr",className:`${Ms} font-mono`}),e.jsx("span",{className:"text-[12px] font-normal leading-snug text-ink-tertiary",children:t("settings.vault.env.hint")})]}),e.jsx(lt,{value:c,onChange:l,bots:s,disabled:d}),m!==null&&e.jsx("p",{role:"status",className:"text-[12px] text-ink-secondary",children:t("settings.vault.env.done",{count:String(m)})})]})}const ys="self-hosted";function Mx({status:s,disabled:n,team:a,onChange:i}){const[r,c]=o.useState(!1),[l,d]=o.useState(xs[0]),[u,p]=o.useState(""),[x,m]=o.useState(""),[g,f]=o.useState(""),[h,j]=o.useState(""),[b,y]=o.useState(null),[v,w]=o.useState(null),N=()=>{m(""),f(""),j("")},C=async(P,E)=>{if(!b){y(P),w(null);try{await i(await E()),P==="connect"&&(N(),c(!1))}catch(A){w(A instanceof Error&&A.message?A.message:t("settings.vault.bitwarden.error"))}finally{y(null)}}},I=l===ys?u.trim():l,F=!!(I&&x.trim()&&g.trim()&&h),k=P=>{P.preventDefault(),F&&C("connect",()=>Yc({serverUrl:I,clientId:x.trim(),clientSecret:g.trim(),password:h}))},S=s.connected?t("settings.vault.bitwarden.connected",{account:s.account??s.server??"Bitwarden",count:String(s.items??0)}):t("settings.vault.bitwarden.line");return e.jsxs("section",{className:"flex flex-col gap-2 px-4 py-3","aria-label":t("settings.vault.bitwarden.title"),"data-bitwarden":!0,children:[e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsx("span",{className:"text-[14px] leading-5 text-ink",children:t("settings.vault.bitwarden.title")}),e.jsx("span",{className:"text-[13px] leading-[18px] text-ink-secondary","data-bitwarden-line":!0,children:S})]}),s.connected?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"settings-quiet cursor-pointer",disabled:n||b!==null,onClick:()=>{C("refresh",Xc)},children:t("settings.logins.onePassword.refresh")}),e.jsx("button",{type:"button",className:"ui-button",disabled:n||b!==null,"aria-label":t("settings.vault.bitwarden.disconnect"),onClick:()=>{C("disconnect",Qc)},children:t("settings.logins.onePassword.disconnect")})]}):e.jsx("button",{type:"button",className:"ui-button",disabled:n,onClick:()=>c(!0),children:t("settings.vault.bitwarden.connect")})]}),a&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-tertiary","data-bitwarden-team":!0,children:t("settings.vault.bitwarden.team")}),s.connected&&s.error&&e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:s.error}),v&&!r&&e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:v}),r&&!s.connected&&e.jsx(Nt,{title:t("settings.vault.bitwarden.connect"),onClose:()=>{N(),c(!1)},footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{N(),c(!1)},children:t("common.cancel")}),e.jsxs("button",{type:"submit",form:"bitwarden-connect",className:"ui-button ui-button-primary gap-1.5",disabled:n||b!==null||!F,children:[b==="connect"&&e.jsx(re,{size:13,className:"animate-spin"}),t("settings.vault.bitwarden.connect")]})]}),children:e.jsxs("form",{id:"bitwarden-connect",className:"flex flex-col gap-3",onSubmit:k,children:[e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary","data-bitwarden-guide":!0,children:t("settings.vault.bitwarden.guide")}),e.jsx(ge,{label:t("settings.vault.bitwarden.server"),children:e.jsxs(ce,{name:"bitwardenServer",value:l,onChange:P=>d(P.target.value),disabled:b!==null,children:[e.jsx("option",{value:xs[0],children:"bitwarden.com"}),e.jsx("option",{value:xs[1],children:"bitwarden.eu"}),e.jsx("option",{value:ys,children:t("settings.vault.bitwarden.selfHosted")})]})}),l===ys&&e.jsx(ge,{label:t("settings.vault.bitwarden.address"),children:e.jsx("input",{name:"bitwardenServerUrl",type:"url",autoComplete:"off",spellCheck:!1,placeholder:"https://vault.example.com",maxLength:2048,value:u,onChange:P=>p(P.target.value),disabled:b!==null,className:xe})}),e.jsx(ge,{label:"client_id",children:e.jsx("input",{name:"bitwardenClientId",type:"text",autoComplete:"off",spellCheck:!1,maxLength:200,value:x,onChange:P=>m(P.target.value),disabled:b!==null,className:xe})}),e.jsx(ge,{label:"client_secret",children:e.jsx("input",{name:"bitwardenClientSecret",type:"password",autoComplete:"off",spellCheck:!1,maxLength:256,value:g,onChange:P=>f(P.target.value),disabled:b!==null,className:xe})}),e.jsx(ge,{label:t("settings.vault.bitwarden.password"),hint:t("settings.vault.bitwarden.note"),children:e.jsx("input",{name:"bitwardenPassword",type:"password",autoComplete:"off",spellCheck:!1,maxLength:1024,value:h,onChange:P=>j(P.target.value),disabled:b!==null,className:xe})}),v&&e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:v})]})})]})}const zs={card:"settings.logins.source.card",settings:"settings.logins.source.settings","1password":"settings.logins.source.1password",bitwarden:"settings.logins.source.bitwarden",linked:"settings.logins.source.1password"},Dx=s=>s.source==="linked"&&s.provider==="bitwarden"?zs.bitwarden:zs[s.source],_t="flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",zx=[["login","settings.vault.addLogin"],["secret","settings.vault.addSecret"],["env","settings.vault.importEnv"]];function _x(s,n,a,i){const r=i.trim().toLowerCase();return[...a==="secrets"?[]:s.map(l=>({kind:"login",key:[l.site,l.username,...l.hosts].join(" "),login:l})),...a==="logins"?[]:n.map(l=>({kind:"secret",key:l.name,secret:l}))].filter(l=>!r||l.key.toLowerCase().includes(r)).sort((l,d)=>l.key.localeCompare(d.key))}function Hx(){const{state:s,dispatch:n}=_(),a=kt(),i=a===!1&&!!s.config?.team,r=s.bots.map(T=>({id:T.id,name:T.name})),[c,l]=o.useState(null),[d,u]=o.useState([]),[p,x]=o.useState({connected:!1}),[m,g]=o.useState(null),[f,h]=o.useState(null),[j,b]=o.useState(""),[y,v]=o.useState("all"),[w,N]=o.useState(!1),[C,I]=o.useState(!1),[F,k]=o.useState(null),[S,P]=o.useState(""),[E,A]=o.useState("all"),[q,R]=o.useState(!1),[K,Z]=o.useState(null),[oe,se]=o.useState("all"),[Y,B]=o.useState(!1),[W,G]=o.useState(""),[le,U]=o.useState(!1),[H,Q]=o.useState(null),[te,ie]=o.useState(!1),[Se,de]=o.useState([]),be=async()=>{try{const T=await td();l(T.logins??[]),u(T.secrets??[]),x(T.onePassword??{connected:!1}),g(T.bitwarden??null),h(null)}catch(T){h(T instanceof Error&&T.message?T.message:t("settings.vault.loadError"))}};if(o.useEffect(()=>{(a||i)&&be()},[a,i]),a===!1&&!i)return e.jsx(pe,{title:t("settings.vault.title"),subtitle:t("settings.vault.adminOnly")});const $=T=>{if(T==="all")return t("settings.logins.allBots");const ae=T.flatMap(ve=>r.find(Ge=>Ge.id===ve)?.name??[]);return ae.length?ae.join(", "):t("settings.logins.noBots")},me=T=>T?t("settings.logins.used",{when:ur(T)}):t("settings.logins.neverUsed"),he=(T,ae)=>{k(null),Q(null),U(!1),ae&&(se(ae.bots),B(ae.exactHost),G(ae.hosts[0]??ae.site)),Z(T)},ke=T=>{N(!1),Z(null),Q(null),k(T)},Re=async(T,ae)=>{if(H!==T){Q(T);return}ie(!0),de([]);try{ae==="login"?await ld(T):de(await od(T)),Q(null),await be()}catch(ve){h(ve instanceof Error&&ve.message?ve.message:t("settings.logins.deleteError"))}finally{ie(!1)}},Ye=(T,ae,ve,Ge)=>e.jsxs("div",{className:"flex shrink-0 gap-1",children:[!i&&e.jsx("button",{type:"button",className:_t,disabled:te,onClick:Ge,"aria-label":ae==="login"?t("settings.logins.changeFor",{site:ve}):t("settings.vault.secret.changeFor",{name:ve}),children:t("settings.logins.change")}),e.jsxs("button",{type:"button",className:_t,disabled:te,onClick:()=>{Re(T,ae)},"aria-label":H===T?t("settings.logins.deleteConfirm"):ae==="login"?t("settings.logins.deleteFor",{site:ve}):t("settings.vault.secret.deleteFor",{name:ve}),children:[e.jsx(We,{size:13}),H===T?t("settings.logins.deleteConfirm"):t("settings.logins.delete")]})]}),ue=(T,ae)=>ae&&!ae.ownBots?t("settings.logins.onePassword.vaultChoice",{who:$(T)}):$(T),Pe=(T,ae)=>!i&&K!==T&&e.jsx("button",{type:"button",className:_t,disabled:te,onClick:()=>he(T),"aria-label":t("settings.logins.onePassword.changeItem",{name:ae}),children:t("settings.logins.change")}),Te=(T,ae)=>e.jsx($x,{item:T,value:ae,bots:r,onCancel:()=>Z(null),onSaved:async()=>{Z(null),await be()}}),Be=_x(c??[],d,y,j),Ie=c!==null&&c.length===0&&d.length===0,rs=T=>e.jsxs("li",{className:"flex flex-col gap-2 py-2.5","data-login-row":T.site,children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx(Xi,{size:14,"aria-hidden":"true",className:"mt-[3px] shrink-0 text-ink-tertiary"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5",children:[e.jsx("span",{dir:"ltr",className:"truncate text-[13px] font-medium text-ink",title:T.site,children:T.site}),T.hasTotp&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 rounded-full bg-ink/[0.07] px-1.5 text-[11px] text-ink-secondary",children:[e.jsx(sd,{size:11,"aria-hidden":"true"}),t("settings.logins.twoFactor")]})]}),e.jsx("div",{dir:"auto",className:"truncate text-[12px] text-ink-secondary",children:T.username||t("settings.logins.noUsername")}),ti(T)&&e.jsx("div",{dir:"ltr",className:"truncate text-[12px] text-ink-tertiary","data-login-hosts":!0,children:ti(T)}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-snug text-ink-tertiary",children:[t(zs[T.source]),ue(T.bots,T.onePassword),me(T.lastUsedAt)].join(" · ")}),sa(T,s.bots).length>0&&e.jsx("div",{className:"mt-0.5 text-[12px] leading-snug text-warning","data-login-held-back":!0,children:t("settings.logins.sharedBrowser",{bots:$(sa(T,s.bots))})})]}),T.source!=="1password"&&T.source!=="bitwarden"&&Ye(T.id,"login",T.site,()=>he(T.id,T)),T.onePassword&&Pe(T.id,T.site)]}),K===T.id&&T.onePassword&&Te(T.onePassword,T.bots),K===T.id&&!T.onePassword&&e.jsx("div",{className:"ms-6 rounded-lg bg-inset/60 p-3",children:e.jsxs(ta,{site:{value:W,onChange:G},username:!1,replacing:!0,submitLabel:t("settings.logins.saveChange"),autoFocus:!0,onCancel:()=>Z(null),onSubmit:async ae=>{const ve=nd(W);await ad(T.id,{...ve&&T.hosts.includes(ve)?{}:{site:W},password:ae.password,totp:ae.totp,removeTotp:le,bots:oe,...Y===T.exactHost?{}:{exactHost:Y}}),Z(null),await be()},children:[T.hasTotp&&e.jsxs("label",{className:"flex items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"checkbox",checked:le,onChange:ae=>U(ae.target.checked)}),t("settings.logins.removeTotp")]}),e.jsx(si,{checked:Y,onChange:B,label:t("settings.logins.exactHostFor",{hosts:T.hosts.join(", "),site:T.site})}),e.jsx(lt,{value:oe,onChange:se,bots:r})]})})]},T.id),ls=T=>e.jsxs("li",{className:"flex flex-col gap-2 py-2.5","data-secret-row":T.name,children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx(id,{size:14,"aria-hidden":"true",className:"mt-[3px] shrink-0 text-ink-tertiary"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{dir:"auto",className:"truncate text-[13px] font-medium text-ink",title:T.name,children:T.name}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-snug text-ink-tertiary",children:[t(Dx(T)),ue(T.bots,T.source==="linked"?T.onePassword:void 0),me(T.lastUsedAt)].join(" · ")})]}),T.source!=="linked"&&Ye(T.id,"secret",T.name,()=>he(T.id)),T.source==="linked"&&T.onePassword&&Pe(T.id,T.name)]}),K===T.id&&T.source==="linked"&&T.onePassword&&Te(T.onePassword,T.bots),K===T.id&&T.source!=="linked"&&e.jsx("div",{className:"ms-6 rounded-lg bg-inset/60 p-3",children:e.jsx(ei,{secret:T,bots:r,onCancel:()=>Z(null),onSaved:async()=>{Z(null),await be()}})})]},T.id);return e.jsxs("div",{className:"flex flex-col gap-6","aria-busy":c===null||te,"data-vault":!0,children:[e.jsxs(J,{label:t("settings.vault.saved"),block:"saved-list",description:i?t("settings.vault.memberSubtitle"):s.config?.cloudHome===!0?e.jsx("span",{"data-logins-cloud-own":!0,children:t("settings.logins.cloudOwn")}):void 0,actions:i?void 0:e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",className:"ui-button gap-1",disabled:c===null,"aria-expanded":w,onClick:()=>N(!w),onKeyDown:T=>{T.key==="Escape"&&N(!1)},children:[t("settings.vault.add"),e.jsx(Ei,{size:12,"aria-hidden":"true"})]}),w&&e.jsx("div",{className:"popover-surface absolute end-0 top-full z-10 mt-1 flex min-w-[11rem] flex-col rounded-[12px] p-1","data-vault-add":!0,"data-look":"popover",children:zx.map(([T,ae])=>e.jsx("button",{type:"button",className:"h-8 rounded-lg px-2 text-start text-[14px] leading-5 text-ink hover:bg-menu-hover",onClick:()=>ke(T),children:t(ae)},T))})]}),footnote:i?void 0:e.jsxs(e.Fragment,{children:[t("settings.vault.limitsShort")," ",e.jsx(Ke,{onClick:()=>I(T=>!T)}),C&&e.jsx("span",{className:"mt-1 block",children:t("settings.logins.limits")})]}),children:[!Ie&&e.jsxs("div",{className:"flex flex-wrap items-center gap-3 px-4",children:[!i&&e.jsx(Zc,{label:t("settings.vault.filter"),attr:"data-vault-filter",value:y,onChange:v,options:[{value:"all",label:t("settings.vault.filter.all")},{value:"logins",label:t("settings.vault.filter.logins")},{value:"secrets",label:t("settings.vault.filter.secrets")}]}),e.jsx("input",{"data-vault-search":!0,type:"text",value:j,onChange:T=>b(T.target.value),autoComplete:"off",spellCheck:!1,placeholder:t("settings.vault.search"),"aria-label":t("settings.vault.search"),className:`${xe} ms-auto h-7 max-w-[200px]`})]}),e.jsxs(V,{children:[F==="login"&&e.jsx("div",{className:"p-4",children:e.jsxs(ta,{site:{value:S,onChange:P},submitLabel:t("settings.logins.save"),autoFocus:!0,onCancel:()=>k(null),onSubmit:async T=>{await ed(S,T,E,q),k(null),P(""),A("all"),R(!1),await be()},children:[e.jsx(si,{checked:q,onChange:R,label:t("settings.logins.exactHost")}),e.jsx(lt,{value:E,onChange:A,bots:r})]})}),F==="secret"&&e.jsx("div",{className:"p-4",children:e.jsx(ei,{bots:r,onCancel:()=>k(null),onSaved:async()=>{k(null),await be()}})}),F==="env"&&e.jsx("div",{className:"p-4",children:e.jsx(Ux,{bots:r,onCancel:()=>k(null),onSaved:be})}),c===null&&!f&&e.jsx(Ne,{children:t("settings.vault.loading")}),Ie&&!F&&e.jsxs(Ne,{children:[e.jsx(Pi,{state:"sleep",size:48,className:"me-3"}),t(i?"settings.vault.memberEmpty":"settings.vault.emptyShort")]}),!Ie&&c!==null&&Be.length===0&&e.jsx("div",{"data-vault-none":!0,className:"contents",children:e.jsx(Ne,{children:t("settings.vault.noMatch")})}),Be.length>0&&e.jsx("ul",{className:"divide-y-[0.5px] divide-(--settings-edge) px-4","data-logins-list":!0,children:Be.map(T=>T.kind==="login"?rs(T.login):ls(T.secret))})]}),Se.length>0&&e.jsx("p",{role:"status",className:"px-4 text-[12px] leading-4 text-warning","data-vault-keys-off":!0,children:t("settings.vault.secret.keyOff",{servers:Se.join(", ")})}),f&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] leading-4 text-danger",children:f})]}),!i&&e.jsx(J,{label:t("settings.vault.elsewhere"),block:"vault-more",children:e.jsxs(V,{children:[e.jsx("div",{"data-vault-keys":!0,className:"contents",children:e.jsx(ye,{title:t("settings.vault.keys.title"),subtitle:t("settings.vault.keys.hintShort",{app:je()}),onClick:()=>n({type:"toggleAppSettings",open:!0,section:"connections"})})}),e.jsx(Wx,{status:p,disabled:c===null,bots:r,botNames:$,team:!!s.config?.team,onChange:async T=>{x(T),await be()}}),m&&e.jsx(Mx,{status:m,disabled:c===null,team:!!s.config?.team,onChange:async T=>{g(T),await be()}})]})})]})}function ti(s){if(s.exactHost)return t("settings.logins.onlyOn",{hosts:s.hosts.join(", ")});const n=s.hosts.filter(a=>a!==s.site);return n.length?t("settings.logins.signsInOn",{hosts:n.join(", ")}):null}function si({checked:s,onChange:n,label:a}){return e.jsxs("label",{className:"flex items-start gap-2 text-[13px] leading-snug text-ink",children:[e.jsx("input",{type:"checkbox",name:"exactHost",className:"mt-[2px]",checked:s,onChange:i=>n(i.target.checked)}),a]})}function $x({item:s,value:n,bots:a,onCancel:i,onSaved:r}){const[c,l]=o.useState(n),[d,u]=o.useState(!1),[p,x]=o.useState(null),m=async g=>{u(!0),x(null);try{await dd(s.item,g),await r()}catch(f){x(f instanceof Error&&f.message?f.message:t("settings.logins.onePassword.error"))}finally{u(!1)}};return e.jsxs("div",{className:"ms-6 flex flex-col gap-2 rounded-lg bg-inset/60 p-3","data-onepassword-item":s.item,children:[e.jsx(lt,{value:c,onChange:l,bots:a,disabled:d}),e.jsx("p",{className:"text-[12px] text-ink-tertiary",children:t("settings.logins.onePassword.itemNote")}),p&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:p}),e.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[s.ownBots&&e.jsx("button",{type:"button",className:"ui-button ui-button-md",disabled:d,onClick:()=>{m(null)},children:t("settings.logins.onePassword.useVaultChoice")}),e.jsx("button",{type:"button",className:"ui-button ui-button-md",disabled:d,onClick:i,children:t("logins.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-md ui-button-primary",disabled:d,onClick:()=>{m(c)},children:t("settings.logins.saveChange")})]})]})}function Kx({vault:s,bots:n,botNames:a,disabled:i,onChange:r}){const[c,l]=o.useState(!1),[d,u]=o.useState(s.bots),[p,x]=o.useState(!1),[m,g]=o.useState(null),f=async()=>{x(!0),g(null);try{await r(await cd(s.id,d)),l(!1)}catch(h){g(h instanceof Error&&h.message?h.message:t("settings.logins.onePassword.error"))}finally{x(!1)}};return e.jsxs("li",{className:"flex flex-col gap-2 py-2","data-vault":s.title,children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",children:s.title}),e.jsx("div",{className:"text-[12px] text-ink-tertiary",children:t("settings.logins.onePassword.vaultUse",{count:String(s.items),who:a(s.bots)})})]}),!c&&e.jsx("button",{type:"button",className:_t,disabled:i||p,onClick:()=>{u(s.bots),l(!0)},"aria-label":t("settings.logins.onePassword.changeVault",{vault:s.title}),children:t("settings.logins.change")})]}),c&&e.jsxs("div",{className:"flex flex-col gap-2 rounded-lg bg-inset/60 p-3",children:[e.jsx(lt,{value:d,onChange:u,bots:n,disabled:p}),m&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:m}),e.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[e.jsx("button",{type:"button",className:"ui-button ui-button-md",disabled:p,onClick:()=>l(!1),children:t("logins.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-md ui-button-primary",disabled:p,onClick:()=>{f()},children:t("settings.logins.saveChange")})]})]})]})}function Wx({status:s,disabled:n,bots:a,botNames:i,team:r,onChange:c}){const[l,d]=o.useState(""),[u,p]=o.useState(!1),[x,m]=o.useState(null),[g,f]=o.useState(null),h=async(b,y)=>{if(!x){m(b),f(null);try{await c(await y()),b==="connect"&&(d(""),p(!1))}catch(v){f(v instanceof Error&&v.message?v.message:t("settings.logins.onePassword.error"))}finally{m(null)}}},j=b=>{b.preventDefault(),l.trim()&&h("connect",()=>rd(l.trim()))};return e.jsxs("section",{className:"flex flex-col gap-2 px-4 py-3","aria-label":t("settings.vault.manager"),"data-onepassword":!0,children:[e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsx("span",{className:"text-[14px] leading-5 text-ink",children:t("settings.vault.connectManager")}),e.jsx("span",{className:"text-[13px] leading-[18px] text-ink-secondary",children:s.connected?t("settings.logins.onePassword.connected",{vaults:(s.vaults??[]).map(b=>b.title).join(", ")||"—",count:String(s.items??0)}):t("settings.vault.managerLine")})]}),s.connected?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"settings-quiet cursor-pointer",disabled:n||x!==null,onClick:()=>{h("refresh",ud)},children:t("settings.logins.onePassword.refresh")}),e.jsx("button",{type:"button",className:"ui-button",disabled:n||x!==null,onClick:()=>{h("disconnect",pd)},children:t("settings.logins.onePassword.disconnect")})]}):e.jsx("button",{type:"button",className:"ui-button",disabled:n,onClick:()=>p(!0),children:t("settings.logins.onePassword.connect")})]}),r&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-tertiary","data-onepassword-team":!0,children:t("settings.logins.onePassword.team")}),s.connected&&s.error&&e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:s.error}),s.connected&&!!s.vaults?.length&&e.jsx("ul",{className:"divide-y-[0.5px] divide-(--settings-edge)","aria-label":t("settings.logins.onePassword.vaults"),children:s.vaults.map(b=>e.jsx(Kx,{vault:b,bots:a,botNames:i,disabled:n,onChange:c},b.id))}),g&&!u&&e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:g}),u&&!s.connected&&e.jsx(Nt,{title:t("settings.vault.connectManager"),onClose:()=>p(!1),footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"ui-button",onClick:()=>p(!1),children:t("common.cancel")}),e.jsxs("button",{type:"submit",form:"onepassword-connect",className:"ui-button ui-button-primary gap-1.5",disabled:n||x!==null||!l.trim(),children:[x==="connect"&&e.jsx(re,{size:13,className:"animate-spin"}),t("settings.logins.onePassword.connect")]})]}),children:e.jsxs("form",{id:"onepassword-connect",className:"flex flex-col gap-3",onSubmit:b=>{j(b)},children:[e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.logins.onePassword.guide")}),r&&e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.logins.onePassword.team")}),e.jsx(ge,{label:t("settings.logins.onePassword.token"),hint:t("settings.logins.onePassword.note"),children:e.jsx("input",{name:"onePasswordToken",type:"password",autoComplete:"off",spellCheck:!1,maxLength:8192,value:l,onChange:b=>d(b.target.value),disabled:n||x!==null,className:xe})}),g&&e.jsx("p",{role:"alert",className:"text-[12px] leading-4 text-danger",children:g})]})})]})}function Gx(){const{state:s,dispatch:n}=_(),[a,i]=o.useState(null),[r,c]=o.useState(!1),[l,d]=o.useState(""),[u,p]=o.useState(!1),x=o.useRef(!1),m=a??s.config?.automaticRecovery??{enabled:!1},g=s.instances.filter(C=>C.snapshot.state==="available"&&!C.policy),f=C=>g.find(I=>I.instanceId===C.backup?.instanceId),h=C=>{const I=f(C);return I?.models.options.filter(F=>!F.orgBlocked&&!F.needsCliUpdate&&(I.snapshot.authenticated!==!1||F.custom))??[]},j=f(m),b=h(m),y=b.some(C=>C.id===m.backup?.model),v=async C=>{if(!x.current){x.current=!0,c(!0),d("");try{const I=await M("/api/config",{method:"PUT",body:JSON.stringify({automaticRecovery:{enabled:C.enabled,...C.backup?.model?{backup:C.backup}:{}}})});n({type:"configStatus",config:I}),i(null)}catch(I){d(I instanceof Error?I.message:t("settings.recovery.error"))}finally{x.current=!1,c(!1)}}},w=C=>{i(C),d(""),(!C.enabled||h(C).some(F=>F.id===C.backup?.model))&&v(C)},N=l?e.jsx("span",{role:"alert",className:"text-danger",children:l}):r?e.jsx("span",{role:"status",children:t("settings.threads.saving")}):m.enabled&&!y?t("settings.recovery.required"):void 0;return e.jsxs(V,{selectWidth:200,children:[e.jsx(L,{title:t("settings.recovery.enable"),subtitle:e.jsxs("span",{id:"automatic-recovery-help",children:[t("settings.recovery.short")," ",e.jsx(Ke,{onClick:()=>p(C=>!C)})]}),message:u||!m.enabled&&l?e.jsxs("span",{"data-recovery-more":"",className:"flex flex-col gap-1",children:[u&&e.jsxs(e.Fragment,{children:[e.jsx("span",{id:"automatic-recovery-scope",children:t("settings.recovery.help")}),e.jsx("span",{children:t("settings.recovery.scopeHanded")}),e.jsx("span",{id:"automatic-recovery-own",children:t("settings.recovery.ownBackups")}),e.jsx("span",{children:t("settings.recovery.charges")})]}),!m.enabled&&l&&e.jsx("span",{role:"alert",className:"text-danger",children:l})]}):void 0,children:e.jsx(ne,{id:"automatic-recovery-enabled",checked:m.enabled,disabled:r||!s.config,"aria-label":t("settings.recovery.enable"),"aria-describedby":"automatic-recovery-help",onClick:()=>w({...m,enabled:!m.enabled})})}),m.enabled&&e.jsx(L,{title:t("settings.recovery.engine"),children:e.jsxs(ce,{id:"automatic-recovery-engine","aria-label":t("settings.recovery.engine"),value:m.backup?.instanceId??"",disabled:r,onChange:C=>w({enabled:m.enabled,...C.target.value?{backup:{instanceId:C.target.value,model:""}}:{}}),children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseEngine")}),m.backup&&!j&&e.jsx("option",{value:m.backup.instanceId,disabled:!0,children:t("settings.recovery.unavailable",{name:m.backup.instanceId})}),g.map(C=>e.jsx("option",{value:C.instanceId,disabled:!C.models.options.some(I=>C.snapshot.authenticated!==!1||I.custom),children:C.displayName},C.instanceId))]})}),m.enabled&&e.jsx(L,{title:t("settings.recovery.model"),message:N,children:e.jsxs(ce,{id:"automatic-recovery-model","aria-label":t("settings.recovery.model"),value:m.backup?.model??"",disabled:r||!j,onChange:C=>w({enabled:m.enabled,backup:{instanceId:j.instanceId,model:C.target.value}}),children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseModel")}),m.backup?.model&&!y&&e.jsx("option",{value:m.backup.model,disabled:!0,children:t("settings.recovery.unavailable",{name:m.backup.model})}),b.map(C=>e.jsx("option",{value:C.id,children:C.label},C.id))]})})]})}function qx({row:s=!1}){const n=!!_().state.config?.team,[a,i]=o.useState(null),[r,c]=o.useState(!1),l=o.useId();o.useEffect(()=>{if(!n)return;let u=!0;return M("/api/me/away-emails",{timeoutMs:1e4}).then(p=>{u&&i(p.on)},()=>{}),()=>{u=!1}},[n]);const d=u=>{const p=a;i(u),c(!1),M("/api/me/away-emails",{method:"PUT",body:JSON.stringify({on:u}),timeoutMs:1e4}).then(x=>i(x.on),()=>{i(p),c(!0)})};return!n||a===null?null:e.jsxs("div",{className:s?"flex flex-col gap-1 px-4 py-[13px]":"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{id:l,className:"text-[14px] text-ink",children:t("settings.profile.awayEmails")}),e.jsx(ne,{"aria-labelledby":l,checked:a,onClick:()=>d(!a)})]}),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("settings.profile.awayEmailsHelp")}),r&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:t("settings.profile.awayEmailsError")})]})}function Vx({bridge:s}){const n=s?.keepHere,a=s?.setKeepHere;return s&&n&&a?e.jsx(Jx,{bridge:s,read:n,write:a}):null}function Jx({bridge:s,read:n,write:a}){const[i,r]=o.useState(null),[c,l]=o.useState(!1),[d,u]=o.useState(!1),[p,x]=o.useState(null);if(o.useEffect(()=>{let f=!0;const h=()=>{n().then(b=>{f&&r(b)}).catch(()=>{})};h();const j=s.onNotice(h);return()=>{f=!1,j()}},[s,n]),!i?.shown)return null;const m=f=>{l(!1),u(!0),x(null),a(f).then(h=>r(h),h=>x(Yl(h)??t("cloudAccount.keepHere.failed"))).finally(()=>u(!1))},g=()=>{i.on?m(!1):i.moved?l(!0):m(!0)};return e.jsxs(J,{label:t("settings.data.move",{place:t("cloudSetup.myCloud")}),block:"move",children:[e.jsx(V,{children:e.jsx("div",{"data-cloud-keep":i.coming?"coming":i.on?"on":"off",className:"contents",children:e.jsx(L,{title:t("cloudAccount.keepHere.title"),subtitle:t("cloudAccount.keepHere.line"),message:e.jsxs(e.Fragment,{children:[i.coming&&e.jsx("span",{role:"status",className:"block",children:t("cloudAccount.keepHere.coming")}),p&&e.jsx("span",{role:"alert",className:"block text-danger",children:p})]}),children:e.jsx(ne,{checked:i.on||i.coming,disabled:d||i.coming,"aria-label":t("cloudAccount.keepHere.title"),onClick:g})})})}),c&&e.jsxs(Nt,{title:t("cloudAccount.keepHere.confirmTitle"),onClose:()=>l(!1),children:[e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("cloudAccount.keepHere.confirm")}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{type:"button","data-autofocus":"",className:"ui-button",onClick:()=>l(!1),children:t("common.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary",onClick:()=>m(!0),children:t("cloudAccount.keepHere.bringBack")})]})]})]})}function Yx(s){const n=s.trim();if(!n||/[\s\\?#@%]/.test(n))return null;try{const a=new URL(n.includes("://")?n:`https://${n}`),i=a.hostname.replace(/\.$/,"");return a.protocol!=="https:"||a.port||a.pathname!=="/"||!i.includes(".")||i.length>253||/^[\d.]+$/.test(i)||!i.split(".").every(r=>/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(r))||/(?:^|\.)(?:localhost|local|internal|invalid|test)$/.test(i)?null:i}catch{return null}}function Xx({domain:s,serverIpv4:n}){const a=Yx(s);if(!a)return e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("settings.domain.enterDomain")});const i=[[t("settings.domain.recordType"),"A"],[t("settings.domain.recordName"),a],[t("settings.domain.recordValue"),n]];return e.jsxs("section",{"aria-label":t("settings.domain.dnsRecord"),className:"flex flex-col gap-1.5",children:[e.jsx("p",{className:"text-[13px] font-medium leading-[18px] text-ink",children:t("settings.domain.dnsRecord")}),e.jsx("dl",{className:"flex flex-col",children:i.map(([r,c])=>e.jsxs("div",{className:"grid min-h-7 grid-cols-[96px_minmax(0,1fr)] items-center gap-2",children:[e.jsx("dt",{className:"text-[12px] leading-4 text-ink-secondary",children:r}),e.jsx("dd",{className:"min-w-0",children:c?e.jsx(Qx,{value:c,label:t("settings.domain.copyField",{field:r})},c):e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("settings.domain.missingIp")})})]},r))}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("settings.domain.recordHint")})]})}function Qx({value:s,label:n}){const{state:a,copy:i}=Yt(s);return e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("code",{className:"min-w-0 select-all truncate font-mono text-[12px] leading-4 text-ink",children:s}),e.jsx("button",{type:"button",onClick:i,"aria-label":a==="failed"?t("common.copyFailed"):n,className:"flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-md text-ink-secondary hover:bg-menu-hover hover:text-ink focus-visible:outline-2 focus-visible:outline-focus",children:a==="copied"?e.jsx(_e,{size:12,className:"text-success"}):e.jsx(qs,{size:12})})]})}const Zx="https://github.com/seira-bot/seira/blob/main/docs/self-hosting.md#connect-a-custom-domain-in-settings";function eg(){const[s,n]=o.useState(null),[a,i]=o.useState(""),[r,c]=o.useState("loading"),[l,d]=o.useState(null),[u,p]=o.useState(null),[x,m]=o.useState(!1);o.useEffect(()=>{const h=new AbortController;return M("/api/settings/custom-domain",{signal:h.signal}).then(j=>{h.signal.aborted||(n(j),i(j.customDomain??""))}).catch(j=>{h.signal.aborted||d(j instanceof Error?j.message:t("settings.domain.failed"))}).finally(()=>{h.signal.aborted||c(null)}),()=>h.abort()},[]);const g=async h=>{c(h?"removing":"saving"),d(null),p(null);try{const j=await M("/api/settings/custom-domain",{method:h?"DELETE":"POST",...h?{}:{body:JSON.stringify({domain:a.trim()})}});n(j),i(j.customDomain??""),p(h?t("settings.domain.removed"):t("settings.domain.saved"))}catch(j){d(j instanceof Error?j.message:t("settings.domain.failed"))}finally{c(null)}},f=!!s?.customDomain;return e.jsx(J,{label:t("settings.domain.title"),block:"address",children:e.jsxs(V,{children:[r==="loading"&&e.jsx(an,{}),s&&!s.supported&&e.jsx(Ne,{children:t("settings.domain.serverOnly")}),s?.supported&&e.jsxs(e.Fragment,{children:[e.jsx(L,{title:t("settings.domain.label"),subtitle:f&&s.publicUrl?e.jsx("span",{className:"break-all",children:s.publicUrl}):e.jsxs(e.Fragment,{children:[t("settings.domain.rowLine")," ",e.jsx(Ke,{href:Zx})]}),message:!x&&u?e.jsx("span",{role:"status",children:u}):void 0,children:e.jsx("button",{type:"button",className:"ui-button","aria-expanded":x,"data-custom-domain-open":"",onClick:()=>m(!x),children:t(x?"common.close":f?"settings.domain.change":"settings.domain.verify")})}),x&&e.jsxs("form",{"data-custom-domain-settings":"",onSubmit:h=>{h.preventDefault(),a.trim()&&!r&&g(!1)},className:"flex flex-col gap-2 px-4 pb-4 pt-3",children:[e.jsx(ge,{label:t("settings.domain.title"),hint:l?e.jsx("span",{role:"alert",className:"text-danger",children:l}):u?e.jsx("span",{role:"status",children:u}):t("settings.domain.httpsFirst"),children:e.jsx("input",{id:"custom-domain",type:"text",value:a,disabled:r!==null,onChange:h=>{i(h.target.value),p(null),d(null)},placeholder:"bots.yourcompany.com",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,className:xe})}),e.jsx(Xx,{domain:a,serverIpv4:s.serverIpv4}),e.jsxs("div",{className:"flex items-center justify-end gap-2","data-settings-form-foot":"",children:[s.customDomain&&e.jsx("button",{type:"button",disabled:r!==null,onClick:()=>{g(!0)},"data-danger":"",className:"settings-quiet mr-auto -ms-1.5 cursor-pointer",children:r==="removing"?t("settings.domain.removing"):t("settings.domain.remove")}),e.jsx("button",{type:"submit",disabled:!a.trim()||r!==null,className:"ui-button ui-button-md ui-button-primary rounded-full",children:r==="saving"?t("settings.domain.verifying"):t("settings.domain.verify")})]})]}),x&&s.customDomain&&e.jsx(Ne,{children:s.fallbackUrl?t("settings.domain.fallback",{url:s.fallbackUrl}):t("settings.domain.noFallback")})]}),!s?.supported&&l&&e.jsx(Ne,{children:e.jsx("span",{role:"alert",className:"text-danger",children:l})})]})})}const tg="https://dash.cloudflare.com/profile/api-tokens",sg=/^[0-9a-f]{32}$/i;function ng({failureText:s}){const{state:n,dispatch:a}=_(),i=n.config?.helpers,r=i?.own.workersAi===!0,c=i?.workersAiAccountId??"",[l,d]=o.useState(null),[u,p]=o.useState(""),[x,m]=o.useState(!1),[g,f]=o.useState(!1),[h,j]=o.useState(null),[b,y]=o.useState(null),v=(l??c).trim(),w=u.trim(),N=!w&&r&&l===null,C=l!==null&&v!==c,I=S=>a({type:"configStatus",config:S}),F=async()=>{if(!(x||!w&&!r&&!C)){if(w&&!sg.test(v))return j(t("decider.workersAi.needsAccount"));m(!0),j(null),y(null);try{(C||w&&!c)&&I(await M("/api/config",{method:"PUT",body:JSON.stringify({decider:{workersAiAccountId:v}})})),(w||N)&&I(window.ogb?.setCredential?await window.ogb.setCredential("workersAiToken",w):await M("/api/config",{method:"PUT",body:JSON.stringify({decider:{workersAiToken:w}})})),p(""),d(null)}catch(S){j(S instanceof Error?S.message:String(S))}finally{m(!1)}}},k=async()=>{if(!(g||x||!w&&!r)){f(!0),y(null),j(null);try{const S=await M("/api/decider/test",{method:"POST",body:JSON.stringify({provider:"workersai",...w?{key:w,accountId:v}:{}})}),P=S.extraction?[t(S.extraction.ok?"decider.test.extractionOk":"decider.test.extractionFailed")]:[];y(S.ok?{ok:S.extraction?.ok!==!1,text:[t("decider.workersAi.test.ok",{ms:String(S.latencyMs)}),...P].join(" ")}:{ok:!1,text:s(S)})}catch(S){y({ok:!1,text:S instanceof Error?S.message:String(S)})}finally{f(!1)}}};return e.jsx(J,{label:t("decider.workersAi.title"),description:t("decider.workersAi.detail"),block:"workers-ai",children:e.jsxs(V,{children:[e.jsxs("div",{className:"flex flex-col gap-3 px-4 pb-1 pt-3",children:[e.jsx(ge,{label:t("decider.workersAi.accountId"),children:e.jsx("input",{type:"text","data-testid":"workers-ai-account",value:l??c,onChange:S=>{y(null),j(null),d(S.target.value)},disabled:x,placeholder:t("decider.workersAi.accountIdPlaceholder"),autoComplete:"off",spellCheck:!1,className:xe})}),e.jsx(ge,{label:t("decider.workersAi.token"),children:e.jsx("input",{type:"password","data-testid":"workers-ai-token",value:u,onChange:S=>{y(null),j(null),p(S.target.value)},onKeyDown:S=>S.key==="Enter"&&void F(),disabled:x,placeholder:r?t("keys.replace"):t("decider.workersAi.tokenPlaceholder"),autoComplete:"off",spellCheck:!1,className:xe})}),e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:e.jsx("a",{href:tg,target:"_blank",rel:"noopener noreferrer",className:"cursor-pointer text-accent-text hover:underline focus-visible:underline",children:t("decider.workersAi.getKey")})})]}),e.jsxs(es,{status:e.jsxs("span",{className:"flex flex-col gap-1",children:[e.jsxs("span",{role:"status",className:"flex items-center",children:[r?e.jsx(Je,{tone:"success"}):e.jsx("span",{"aria-hidden":"true",className:"mr-1.5 inline-block size-1.5 rounded-full bg-ink/20"}),t(r?"decider.status.connected":"decider.status.notSetUpShort")]}),h&&e.jsx("span",{role:"alert",className:"text-danger",children:h}),b&&e.jsx("span",{role:"status",className:b.ok?"text-ink-secondary":"text-danger",children:b.text})]}),children:[e.jsx("button",{type:"button","data-testid":"workers-ai-test",onClick:()=>{k()},disabled:g||x||!w&&!r,className:"ui-button ui-button-md cursor-pointer rounded-full",children:g?t("keys.testing"):t("keys.test")}),e.jsx("button",{type:"button","data-testid":"workers-ai-save",onClick:()=>{F()},disabled:x||!w&&!r&&!C,title:N?t("keys.removeKey"):t("common.save"),className:D("ui-button ui-button-md cursor-pointer rounded-full",N&&"!text-danger"),children:x?t("settings.threads.saving"):N?t("keys.clear"):t("common.save")})]})]})})}const ni=s=>s==="decisions"||s==="chat"?s:"systemone",ag={jev:"https://typesafe.ai",openrouter:"https://openrouter.ai/keys"},ai={jev:{credential:"jevApiKey",field:"key"},openrouter:{credential:"openrouterDeciderKey",field:"openrouterKey"},custom:{credential:"customDeciderKey",field:"customKey"}},pt={jev:{master:"decider.master",needsKey:"decider.masterNeedsKey",keyLabel:"decider.key.label",placeholder:"decider.key.placeholder"},openrouter:{master:"decider.openrouter.master",needsKey:"decider.masterNeedsKey.openrouter",keyLabel:"decider.openrouter.key.label",placeholder:"decider.openrouter.key.placeholder"},custom:{master:"decider.custom.master",needsKey:"decider.custom.masterNeedsKey",keyLabel:"decider.custom.key.label",placeholder:"decider.custom.key.placeholder"}},ig=1500,rg={recommended:"decider.model.recommended",more:"decider.model.more",chat:"decider.model.geminiChat"},is={rejected:"decider.error.rejected",unreachable:"decider.error.unreachable",timeout:"decider.error.timeout",rate_limited:"decider.error.rateLimited",overloaded:"decider.error.overloaded",malformed:"decider.error.malformed",no_key:"decider.error.noKey",misconfigured:"decider.error.misconfigured"},ii={rejected:"decider.included.error.rejected",rate_limited:"decider.included.error.limited"},lg={...is,rejected:"decider.openrouter.error.rejected",unreachable:"decider.openrouter.error.unreachable",timeout:"decider.openrouter.error.timeout",rate_limited:"decider.openrouter.error.rateLimited",overloaded:"decider.openrouter.error.overloaded",malformed:"decider.openrouter.error.malformed"},og={...is,rejected:"decider.custom.error.rejected",unreachable:"decider.custom.error.unreachable",timeout:"decider.custom.error.timeout",rate_limited:"decider.custom.error.rateLimited",overloaded:"decider.custom.error.overloaded",malformed:"decider.custom.error.malformed",misconfigured:"decider.custom.error.misconfigured"},cg={...is,rejected:"decider.workersAi.error.rejected",unreachable:"decider.workersAi.error.unreachable",timeout:"decider.workersAi.error.timeout",rate_limited:"decider.workersAi.error.rateLimited",overloaded:"decider.workersAi.error.overloaded",malformed:"decider.workersAi.error.malformed"},js={jev:"decider.status.byJev",workersai:"decider.status.byWorkersAi",openrouter:"decider.status.byOpenRouter",custom:"decider.status.byCustom",gemini:"decider.status.byGemini"};function dg(s){const n=s?.decider,a=s?.helpers?.extraction,i=n?.configured?n.included?t("decider.status.byCloud"):t(js[n.provider]??js.jev):t("decider.status.notSetUp"),r=a?.provider?a.included?t("decider.status.byCloud"):t(js[a.provider]):t("decider.status.notSetUp");return t("decider.status.line",{decisions:i,extraction:r})}function ri(s,n=!1,a="jev"){if(a==="workersai"){if(s.reason==="http_error")return t("decider.workersAi.error.http",{status:String(s.status??"?")});const r=cg[s.reason];return r?t(r):t("decider.error.other")}if(a==="custom"){if(s.reason==="http_error")return t("decider.custom.error.http",{status:String(s.status??"?")});const r=og[s.reason];return r?t(r):t("decider.error.other")}if(a==="openrouter"){if(s.reason==="http_error"&&s.status===402)return t("decider.openrouter.error.credits");if(s.reason==="http_error")return t("decider.openrouter.error.http",{status:String(s.status??"?")});const r=lg[s.reason];return r?t(r):t("decider.error.other")}if(n&&s.reason==="http_error"&&s.status===402)return t("decider.included.error.subscription");if(n&&ii[s.reason])return t(ii[s.reason]);if(s.reason==="http_error")return t("decider.error.http",{status:String(s.status??"?")});const i=is[s.reason];return i?t(i):t("decider.error.other")}const li=s=>s==="openrouter"||s==="custom"?s:"jev";function oi({saved:s,onSave:n,disabled:a,label:i,placeholder:r,testId:c}){const[l,d]=o.useState(s);o.useEffect(()=>d(s),[s]);const u=()=>{l.trim()!==s&&n(l.trim())};return e.jsx("input",{type:"text","data-testid":c,value:l,onChange:p=>d(p.target.value),onBlur:u,onKeyDown:p=>p.key==="Enter"&&u(),disabled:a,placeholder:r,"aria-label":i,autoComplete:"off",spellCheck:!1,className:D(xe,"[width:var(--settings-select-width,200px)] max-w-full")})}function ug(){const{state:s,dispatch:n}=_(),a=s.config?.decider,i=li(a?.chosen??a?.provider),r=i==="openrouter",c=i==="custom",l=a?.configured??!1,d=l&&a?.included===!0,u=l&&a?.keySource==="shared",p=r&&u,x=r&&a?.sharedKey===!0,m=l&&a?.provider==="gemini",g=l&&!d&&!u&&!m,f=a?.enabled??!1,h=a?.jobs.roomRouting??!0,[j,b]=o.useState(""),[y,v]=o.useState(!1),[w,N]=o.useState(!1),[C,I]=o.useState(!1),[F,k]=o.useState(null),[S,P]=o.useState(null),[E,A]=o.useState(null),[q,R]=o.useState(!1),K=j.trim(),Z=!K&&g,oe=!r||d?null:u?"decider.openrouter.status.sharedHint":l?x?"decider.openrouter.status.ownFallbackHint":null:"decider.openrouter.status.notConnectedHint",se=H=>n({type:"configStatus",config:H}),Y=async H=>{if(!w){N(!0),k(null);try{se(await M("/api/config",{method:"PUT",body:JSON.stringify({decider:H})}))}catch(Q){k(Q instanceof Error?Q.message:String(Q))}finally{N(!1)}}};o.useEffect(()=>{if(!r||E)return;let H=!1;return M("/api/decider/models").then(Q=>{H||A(Q)},()=>{}),()=>{H=!0}},[r,E]);const B=H=>{b(""),P(null),Y(H)},W=async()=>{if(!(y||!K&&!g)){v(!0),k(null),P(null);try{const H=window.ogb?.setCredential?await window.ogb.setCredential(ai[i].credential,K):await M("/api/config",{method:"PUT",body:JSON.stringify({decider:{[ai[i].field]:K}})});se(H),b("")}catch(H){k(H instanceof Error?H.message:String(H))}finally{v(!1)}}},G=async()=>{if(C||y||!K&&!l)return;I(!0),P(null),k(null);const H=!K&&d,Q=!K&&u,te=!K&&m;try{const ie=await M("/api/decider/test",{method:"POST",body:JSON.stringify(K?{key:K}:{})});P(ie.ok?{ok:!0,text:r||c||Q||te?[t(te?"decider.gemini.test.ok":c?"decider.custom.test.ok":Q?"decider.openrouter.test.okShared":"decider.openrouter.test.ok",{ms:String(ie.latencyMs)}),...ie.latencyMs>ig?[t("decider.test.slow")]:[]].join(" "):t("decider.test.ok",{ms:String(ie.latencyMs)})}:{ok:!1,text:te?t(ie.reason==="rejected"?"decider.gemini.error.rejected":"decider.error.other"):ri(ie,H,Q?"openrouter":i)})}catch(ie){P({ok:!1,text:ie instanceof Error?ie.message:String(ie)})}finally{I(!1)}},le=t(pt[i].keyLabel),U=d?t("keys.includedWithCloudPro"):u?t("decider.openrouter.status.shared"):l?t(x?"decider.openrouter.status.own":"decider.status.connected"):t("decider.status.notConnected");return e.jsxs(e.Fragment,{children:[e.jsxs(J,{label:t("settings.ai.routing"),block:"routing",description:e.jsxs(e.Fragment,{children:[t("decider.introShort")," ",e.jsx(Ke,{onClick:()=>R(!q)})]}),children:[q&&e.jsx("p",{"data-decider-more":"",className:"px-4 text-[12px] leading-4 text-ink-secondary",children:t("decider.intro")}),e.jsx(V,{children:e.jsx(L,{title:t(pt[i].master),subtitle:e.jsx("span",{role:"status","data-testid":"helpers-status",children:dg(s.config)}),message:l?void 0:t(pt[i].needsKey),children:e.jsx(ne,{"data-testid":"decider-master","aria-label":t(pt[i].master),checked:f,disabled:!l||w||!s.config,onClick:()=>{Y({enabled:!f})},className:"cursor-pointer"})})})]}),e.jsx(ng,{failureText:H=>ri(H,!1,"workersai")}),e.jsx(J,{label:t("decider.provider.label"),block:"routing-key",children:e.jsxs(V,{selectWidth:200,children:[e.jsx(L,{title:t("decider.provider.title"),children:e.jsxs(ce,{"data-testid":"decider-provider",value:i,onChange:H=>B({provider:li(H.target.value)}),disabled:w||!s.config,"aria-label":t("decider.provider.label"),children:[e.jsx("option",{value:"jev",children:t("decider.provider.jev")}),e.jsx("option",{value:"openrouter",children:t("decider.provider.openrouter")}),e.jsx("option",{value:"custom",children:t("decider.provider.custom")})]})}),c&&e.jsxs(e.Fragment,{children:[e.jsx(L,{title:t("decider.custom.baseUrl"),subtitle:t("decider.custom.baseUrlDetail"),children:e.jsx(oi,{testId:"decider-custom-base-url",saved:a?.baseUrl??"",disabled:w,label:t("decider.custom.baseUrl"),placeholder:t("decider.custom.baseUrlPlaceholder"),onSave:H=>{Y({customBaseUrl:H})}})}),e.jsx(L,{title:t("decider.custom.model"),children:e.jsx(oi,{testId:"decider-custom-model",saved:a?.model??"",disabled:w,label:t("decider.custom.model"),placeholder:t("decider.custom.modelPlaceholder"),onSave:H=>{Y({customModel:H})}})}),e.jsx(L,{title:t("decider.custom.api"),children:e.jsxs(ce,{"data-testid":"decider-custom-api",value:ni(a?.api),onChange:H=>B({customApi:ni(H.target.value)}),disabled:w,"aria-label":t("decider.custom.api"),children:[e.jsx("option",{value:"systemone",children:t("decider.custom.api.systemone")}),e.jsx("option",{value:"decisions",children:t("decider.custom.api.decisions")}),e.jsx("option",{value:"chat",children:t("decider.custom.api.chat")})]})})]}),r&&e.jsx(L,{title:t("decider.model.label"),subtitle:E?.source==="builtin"?t("decider.model.builtinNote"):void 0,children:e.jsxs(ce,{"data-testid":"decider-model",value:a?.model??"",onChange:H=>B({openrouterModel:H.target.value,openrouterApi:E?.models.find(Q=>Q.id===H.target.value)?.api??"chat"}),disabled:w,"aria-label":t("decider.model.label"),children:[a?.model&&!E?.models.some(H=>H.id===a.model)&&e.jsx("option",{value:a.model,children:a.model}),["recommended","more","chat"].map(H=>{const Q=E?.models.filter(te=>te.group===H)??[];return Q.length>0&&e.jsx("optgroup",{label:t(rg[H]),children:Q.map(te=>e.jsx("option",{value:te.id,children:te.name},te.id))},H)})]})}),e.jsxs("div",{"data-decider-key":"",className:"flex flex-col gap-2 px-4 pb-1 pt-3",children:[e.jsx(ge,{label:le,children:e.jsx("input",{type:"password",value:j,onChange:H=>{P(null),k(null),b(H.target.value)},onKeyDown:H=>H.key==="Enter"&&void W(),disabled:y,placeholder:g?t("keys.replace"):t(p?"decider.openrouter.key.overridePlaceholder":pt[i].placeholder),"aria-label":le,autoComplete:"off",spellCheck:!1,className:xe})}),e.jsxs("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:[oe&&e.jsxs(e.Fragment,{children:[t(oe)," "]}),oe&&!g&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","data-testid":"decider-manage-keys",onClick:()=>n(Rs("openrouter")),className:"cursor-pointer text-accent-text hover:underline",children:t("decider.openrouter.key.manageLink")})," "]}),!p&&i!=="custom"&&e.jsx("a",{href:ag[i],target:"_blank",rel:"noopener noreferrer",className:"cursor-pointer text-accent-text hover:underline focus-visible:underline",children:t(r?"decider.openrouter.key.getKey":"decider.key.getKey")})]})]}),e.jsxs(es,{status:e.jsxs("span",{className:"flex flex-col gap-1",children:[e.jsxs("span",{role:"status",className:"flex items-center",children:[e.jsx(Je,{tone:l?"success":null}),!l&&e.jsx("span",{"aria-hidden":"true",className:"mr-1.5 inline-block size-1.5 rounded-full bg-ink/20"}),U]}),F&&e.jsx("span",{role:"alert",className:"text-danger",children:F}),S&&e.jsx("span",{role:"status",className:S.ok?"text-ink-secondary":"text-danger",children:S.text})]}),children:[e.jsx("button",{type:"button","data-testid":"decider-test",onClick:()=>{G()},disabled:C||y||!K&&!l,className:"ui-button ui-button-md cursor-pointer rounded-full",children:C?t("keys.testing"):t("keys.test")}),e.jsx("button",{type:"button","data-testid":"decider-save",onClick:()=>{W()},disabled:y||!K&&!g,title:Z?t("keys.removeKey"):t("common.save"),className:D("ui-button ui-button-md cursor-pointer rounded-full",Z&&"!text-danger"),children:y?t("settings.threads.saving"):Z?t("keys.clear"):t("common.save")})]})]})}),e.jsx(J,{label:t("decider.jobs.title"),block:"routing-jobs",children:e.jsx(V,{children:e.jsx(L,{title:t("decider.jobs.roomRouting"),subtitle:t("decider.jobs.roomRoutingDetail"),children:e.jsx(ne,{"data-testid":"decider-job-roomRouting","aria-label":t("decider.jobs.roomRouting"),checked:f&&h,disabled:!f||w,onClick:()=>{Y({jobs:{roomRouting:!h}})},className:"cursor-pointer"})})})})]})}function pg(){const s=!!_().state.config?.team,[n,a]=o.useState(null),[i,r]=o.useState(""),[c,l]=o.useState(!1),d=o.useId();if(o.useEffect(()=>{if(s)return;let p=!0;return M("/api/me",{timeoutMs:1e4}).then(x=>{!p||typeof x?.displayName!="string"||(a(x),r(x.displayName))},()=>{}),()=>{p=!1}},[s]),s||!n)return null;const u=()=>{i.trim()!==n.displayName&&(l(!1),M("/api/me",{method:"PUT",body:JSON.stringify({displayName:i}),timeoutMs:1e4}).then(p=>{a(p),r(p.displayName)},()=>l(!0)))};return e.jsxs("div",{className:"flex flex-col gap-1 px-4 py-[13px]",children:[e.jsx("label",{id:d,htmlFor:`${d}-input`,className:"text-[14px] text-ink",children:t("settings.profile.displayName")}),e.jsx("input",{id:`${d}-input`,"aria-labelledby":d,value:i,maxLength:60,placeholder:n.shownAs,onChange:p=>r(p.target.value),onBlur:u,className:xe}),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("settings.profile.displayNameHelp")}),c&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:t("settings.profile.displayNameError")})]})}const mg=["openai","xai","gemini","openrouter","custom"],xg=4,gg=["low","medium","high"];function hg(s){return s.provider==="openai"&&s.model.startsWith("gpt-image-2.6-")}const Wr={openai:"gpt-image-2",xai:"grok-imagine-image-2.0",gemini:"gemini-2.5-flash-image",openrouter:"google/gemini-2.5-flash-image",custom:""},fg={openai:[{id:"gpt-image-2.6-sunburst",name:"GPT Image 2.6 Sunburst"},{id:"gpt-image-2.6-flare",name:"GPT Image 2.6 Flare"},{id:"gpt-image-2",name:"GPT Image 2"},{id:"gpt-image-1",name:"GPT Image 1"},{id:"gpt-image-1-mini",name:"GPT Image 1 Mini"}],xai:[{id:"grok-imagine-image-2.0",name:"Grok Imagine Image 2.0"}],gemini:[{id:"gemini-2.5-flash-image",name:"Nano Banana (Gemini 2.5 Flash Image)"}],openrouter:[{id:"google/gemini-2.5-flash-image",name:"Google: Nano Banana (Gemini 2.5 Flash Image)"},{id:"google/gemini-3.1-flash-image",name:"Google: Nano Banana 2 (Gemini 3.1 Flash Image)"},{id:"google/gemini-3-pro-image",name:"Google: Nano Banana Pro (Gemini 3 Pro Image)"},{id:"openai/gpt-image-2",name:"OpenAI: GPT Image 2"},{id:"black-forest-labs/flux-3-image",name:"Black Forest Labs: FLUX 3 Image"},{id:"bytedance-seed/seedream-5-0-pro",name:"ByteDance Seed: Seedream 5.0 Pro"},{id:"x-ai/grok-imagine-image-2.0",name:"xAI: Grok Imagine Image 2.0"},{id:"qwen/qwen-image-3",name:"Qwen: Qwen Image 3"}],custom:[]};function bg(s){const n="Use an HTTPS API base URL, or HTTP for a local router, without passwords, query parameters or fragments";let a;try{a=new URL(s.trim())}catch{throw new Error(n)}if(s.length>2048||a.username||a.password||a.search||a.hash)throw new Error(n);const i=a.hostname.toLowerCase(),r=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/.exec(i),c=i==="localhost"||i.endsWith(".localhost")||i.endsWith(".local")||i==="host.docker.internal"||i==="host.containers.internal"||i==="[::1]"||/^\[f[cd][0-9a-f]{2}:/.test(i)||r&&(Number(r[1])===127||Number(r[1])===10||Number(r[1])===192&&Number(r[2])===168||Number(r[1])===172&&Number(r[2])>=16&&Number(r[2])<=31);if(a.protocol!=="https:"&&!(a.protocol==="http:"&&c))throw new Error(n);if(r&&(Number(r[1])===0||Number(r[1])===169&&Number(r[2])===254))throw new Error(n);return a.pathname=a.pathname.replace(/\/+$/,"").replace(/\/images\/generations$/,""),a.toString().replace(/\/+$/,"")}const jt={openai:"OpenAI",xai:"Grok (xAI)",gemini:"Gemini",openrouter:"OpenRouter",custom:"Custom"},vg={openai:{credential:"openaiImageApiKey",patch:s=>({imageGen:{key:s}}),label:"imageGen.key.openai"},gemini:{credential:"geminiImageApiKey",patch:s=>({imageGen:{geminiKey:s}}),label:"imageGen.key.gemini"},custom:{credential:"customImageApiKey",patch:s=>({imageGen:{customApiKey:s}}),label:"imageGen.key.custom"}},yg={xai:{label:"imageGen.key.xai",note:"imageGen.key.sharedXai"},openrouter:{label:"imageGen.key.openrouter",note:"imageGen.key.sharedOpenrouter"}},ci={openai:"https://platform.openai.com/api-keys",gemini:"https://aistudio.google.com/apikey",xai:"https://console.x.ai",openrouter:"https://openrouter.ai/keys"},ks="\0other";function jg(s,n){return n.ok?n.freeTier?{ok:!1,text:t("imageGen.test.noCredit")}:{ok:!0,text:t(s==="openrouter"?"imageGen.test.okOpenrouter":"imageGen.test.ok")}:n.reason==="model_missing"?{ok:!1,text:t("imageGen.test.modelMissing",{model:n.model})}:n.reason==="rejected"?{ok:!1,text:t("imageGen.test.rejected")}:n.reason==="unreachable"?{ok:!1,text:t("imageGen.test.unreachable")}:n.reason==="no_key"?{ok:!1,text:t("imageGen.key.missing")}:n.reason==="no_url"?{ok:!1,text:t("imageGen.test.noUrl")}:{ok:!1,text:t("imageGen.test.unexpected")}}function kg(s,n){return n==="openai"?s?.openaiConfigured===!0:n==="xai"?s?.xaiConfigured===!0:n==="gemini"?s?.geminiConfigured===!0:n==="openrouter"?s?.openrouterConfigured===!0:s?.customKeyConfigured===!0}function wg(){const{state:s,dispatch:n}=_(),a=s.config?.imageGen,i=a?.primary??{provider:a?.provider??"openai",model:a?.model??Wr.openai,configured:a?.configured===!0},r=a?.fallback??null,[c,l]=o.useState(!1),[d,u]=o.useState(null),[p,x]=o.useState(null),[m,g]=o.useState(!1),f=i.provider==="openrouter"||r?.provider==="openrouter";o.useEffect(()=>{if(!f||p)return;let v=!1;return M("/api/images/openrouter-models").then(w=>{v||x(Array.isArray(w?.models)?w:{source:"builtin",models:[]})},()=>{v||x({source:"builtin",models:[]})}),()=>{v=!0}},[f,p]);const h=async v=>{l(!0),u(null);try{const w=await M("/api/config",{method:"PUT",body:JSON.stringify(v)});n({type:"configStatus",config:w})}catch(w){u(w instanceof Error?w.message:String(w))}finally{l(!1)}},j=(v,w)=>{if(v==="fallback"&&w==="")return void h({imageGen:{fallback:null}});const N=w,C=v==="primary"&&r?.provider===N;h({imageGen:{[v]:{provider:N},...C?{fallback:null}:{}}})},b=[i.provider,...r?[r.provider]:[]].filter((v,w,N)=>N.indexOf(v)===w),y=a?.ready?i.configured?t("imageGen.status.ready",{provider:jt[i.provider]}):t("imageGen.status.backupOnly",{provider:jt[r.provider]}):t("imageGen.status.notReady");return e.jsxs(e.Fragment,{children:[e.jsxs(J,{label:t("settings.ai.images"),block:"images",description:e.jsxs(e.Fragment,{children:[t("imageGen.introShort")," ",e.jsx(Ke,{onClick:()=>g(v=>!v)})]}),footnote:e.jsxs("span",{role:"status","data-testid":"image-gen-status",className:"inline-flex items-center",children:[a?.ready?e.jsx(Je,{tone:i.configured?"success":"warning"}):e.jsx("span",{"aria-hidden":"true",className:"mr-1.5 inline-block size-1.5 rounded-full bg-ink/20"}),y]}),children:[m&&e.jsx("p",{"data-image-gen-more":"",className:"px-4 text-[12px] leading-4 text-ink-secondary",children:t("imageGen.intro")}),e.jsxs(V,{selectWidth:200,children:[e.jsx(di,{slot:"primary",provider:i.provider,model:i.model,configured:i.configured,openrouterModels:p,disabled:c||!s.config,onProvider:j,onModel:v=>{h({imageGen:{primary:{provider:i.provider,model:v}}})}}),e.jsx(di,{slot:"fallback",provider:r?.provider??null,model:r?.model??"",configured:r?.configured===!0,exclude:i.provider,openrouterModels:p,disabled:c||!s.config,onProvider:j,onModel:v=>r&&void h({imageGen:{fallback:{provider:r.provider,model:v}}})}),e.jsx(L,{title:t("imageGen.maxPerTurn.label"),subtitle:t("imageGen.maxPerTurn.help"),message:d?e.jsx("span",{role:"alert",className:"text-danger",children:d}):void 0,children:e.jsx(ce,{"data-testid":"image-gen-max",value:String(a?.maxPerTurn??xg),onChange:v=>{h({imageGen:{maxPerTurn:Number(v.target.value)}})},disabled:c||!s.config,"aria-label":t("imageGen.maxPerTurn.label"),children:Array.from({length:10},(v,w)=>w+1).map(v=>e.jsx("option",{value:v,children:v},v))})}),[i,r].some(v=>v&&hg(v))&&e.jsx(L,{title:t("imageGen.complexity.label"),subtitle:t("imageGen.complexity.help"),children:e.jsx(ce,{"data-testid":"image-gen-complexity",value:a?.complexity??"high",onChange:v=>{h({imageGen:{complexity:v.target.value}})},disabled:c||!s.config,"aria-label":t("imageGen.complexity.label"),children:gg.map(v=>e.jsx("option",{value:v,children:t(`imageGen.complexity.${v}`)},v))})})]})]}),b.map(v=>e.jsx(Sg,{provider:v,status:a},v))]})}function di({slot:s,provider:n,model:a,configured:i,exclude:r,openrouterModels:c,disabled:l,onProvider:d,onModel:u}){const p=t(s==="primary"?"imageGen.primary.label":"imageGen.fallback.label");return e.jsxs(e.Fragment,{children:[e.jsx(L,{title:p,subtitle:n&&!i?t(n==="custom"?"imageGen.slot.needsConnection":"imageGen.slot.needsKey"):t(s==="primary"?"imageGen.primary.help":"imageGen.fallback.help"),children:e.jsxs(ce,{"data-testid":`image-gen-${s}`,value:n??"",onChange:x=>d(s,x.target.value),disabled:l,"aria-label":p,children:[s==="fallback"&&e.jsx("option",{value:"",children:t("imageGen.fallback.none")}),mg.filter(x=>x!==r).map(x=>e.jsx("option",{value:x,children:jt[x]},x))]})}),n&&e.jsx(Ng,{slot:s,slotLabel:p,provider:n,model:a,openrouterModels:c,disabled:l,onModel:u})]})}function Ng({slot:s,slotLabel:n,provider:a,model:i,openrouterModels:r,disabled:c,onModel:l}){const[d,u]=o.useState(null),x=(a==="openrouter"&&r?.source==="openrouter"?r.models:null)??fg[a].map(h=>({...h,group:"recommended"})),m=d!==null||x.length===0,g=()=>{d!==null&&(u(null),d.trim()&&d.trim()!==i&&l(d.trim()))},f=h=>{if(h===ks)return u(i);u(null),l(h)};return e.jsx(L,{title:t("decider.model.label"),subtitle:a==="openrouter"&&r?.source==="builtin"?t("decider.model.builtinNote"):void 0,children:e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[x.length>0&&e.jsxs(ce,{"data-testid":`image-gen-${s}-model`,value:m?ks:i,onChange:h=>f(h.target.value),disabled:c,"aria-label":t("imageGen.model.label",{slot:n}),children:[i&&!x.some(h=>h.id===i)&&e.jsx("option",{value:i,children:i}),["recommended","more"].map(h=>{const j=x.filter(b=>b.group===h);return j.length>0&&e.jsx("optgroup",{label:t(h==="recommended"?"decider.model.recommended":"decider.model.more"),children:j.map(b=>e.jsx("option",{value:b.id,children:b.name},b.id))},h)}),e.jsx("option",{value:ks,children:t("imageGen.model.other")})]}),m&&e.jsx("input",{value:d??i,onChange:h=>u(h.target.value),onBlur:g,onKeyDown:h=>h.key==="Enter"&&g(),disabled:c,placeholder:Wr[a]||t("imageGen.model.placeholder"),"aria-label":t("imageGen.model.idLabel",{slot:n}),autoComplete:"off",spellCheck:!1,className:D(Ue,"w-[200px] text-left")})]})})}function Sg({provider:s,status:n}){const{dispatch:a}=_(),[i,r]=o.useState(""),[c,l]=o.useState(null),[d,u]=o.useState(!1),[p,x]=o.useState(null),[m,g]=o.useState(!1),[f,h]=o.useState(null),j=s==="openrouter"?[n?.primary,n?.fallback].filter(E=>E?.provider===s).map(E=>E?.model).join(" "):"",b=f?.models===j?f:null,y=E=>h(E&&{...E,models:j}),v=kg(n,s),w=s==="openai"||s==="gemini"||s==="custom"?vg[s]:null,N=s==="xai"||s==="openrouter"?yg[s]:null,C=c??n?.customUrl??"",I=async E=>{u(!0),x(null),y(null);try{a({type:"configStatus",config:await E()}),r(""),l(null)}catch(A){x(A instanceof Error?A.message:String(A))}finally{u(!1)}},F=E=>I(async()=>s==="xai"||s==="openrouter"?md(s,E,!1):window.ogb?.setCredential&&w?window.ogb.setCredential(w.credential,E):M("/api/config",{method:"PUT",body:JSON.stringify(w.patch(E))})),k=()=>I(async()=>{const E=C.trim()?bg(C.trim()):"";return M("/api/config",{method:"PUT",body:JSON.stringify({imageGen:{customUrl:E}})})}),S=async()=>{g(!0),y(null);try{y(jg(s,await M("/api/images/test",{method:"POST",body:JSON.stringify({provider:s})})))}catch(E){y({ok:!1,text:E instanceof Error?E.message:String(E)})}finally{g(!1)}},P=t(v?"imageGen.key.saved":s==="custom"?"imageGen.key.optional":"imageGen.key.missing");return e.jsx(J,{label:jt[s],block:`images-${s}`,children:e.jsx(V,{children:e.jsxs("div",{className:"flex flex-col gap-2 px-4 pb-4 pt-3","data-image-key-form":"",children:[s==="custom"&&e.jsx(ge,{label:t("imageGen.custom.url"),children:e.jsx("input",{type:"url",value:C,onChange:E=>l(E.target.value),onKeyDown:E=>E.key==="Enter"&&void k(),onBlur:()=>c!==null&&void k(),disabled:d,placeholder:"http://127.0.0.1:4000/v1",autoComplete:"off",className:xe})}),e.jsx(ge,{label:t("imageGen.key.label"),hint:e.jsxs("span",{className:"flex flex-col gap-1",children:[e.jsxs("span",{role:"status",className:"flex items-center",children:[v?e.jsx(Je,{tone:"success"}):e.jsx("span",{"aria-hidden":"true",className:"mr-1.5 inline-block size-1.5 rounded-full bg-ink/20"}),P]}),b&&e.jsx("span",{role:"status",className:b.ok?"text-ink-secondary":"text-danger",children:b.text}),p&&e.jsx("span",{role:"alert",className:"text-danger",children:p})]}),children:e.jsx("input",{type:"password",value:i,onChange:E=>r(E.target.value),onKeyDown:E=>E.key==="Enter"&&i.trim()&&void F(i.trim()),disabled:d,placeholder:v?t("keys.replace"):t("keys.row.pasteKey"),"aria-label":t((w??N).label),autoComplete:"off",spellCheck:!1,className:xe})}),e.jsxs("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:[N?e.jsxs(e.Fragment,{children:[t(N.note)," ",e.jsx("button",{type:"button",onClick:()=>a({type:"toggleAppSettings",open:!0,section:"connections"}),className:"cursor-pointer text-accent-text hover:underline",children:t("imageGen.key.manage")})," "]}):s==="custom"?e.jsx(e.Fragment,{children:t("imageGen.custom.help",{app:je()})}):e.jsxs(e.Fragment,{children:[t("imageGen.key.line",{app:je(),provider:jt[s]})," "]}),ci[s]&&e.jsx("a",{href:ci[s],target:"_blank",rel:"noreferrer",className:"text-accent-text hover:underline focus-visible:underline",children:t("imageGen.key.get")})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2","data-settings-form-foot":"",children:[v&&e.jsx("button",{type:"button",onClick:()=>{F("")},disabled:d,"data-danger":"",className:"settings-quiet mr-auto -ms-1.5 cursor-pointer",children:t("keys.removeKey")}),v&&e.jsx("button",{type:"button",onClick:()=>{S()},disabled:m||d,className:"ui-button ui-button-md cursor-pointer rounded-full",children:m?t("keys.testing"):t("keys.test")}),e.jsx("button",{type:"button",onClick:()=>{F(i.trim())},disabled:d||!i.trim(),className:"ui-button ui-button-md cursor-pointer rounded-full",children:d?t("settings.threads.saving"):t("common.save")})]})]})})})}const Cg={status:"/api/local-computer","local-vms":"/api/local-computer/instances",cloud:"/api/computers/boxes",vps:"/api/computers/vps"};function gt(s,n){return[Cg[s],{signal:n}]}function gn(s,n){return[s,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)}]}function Eg({instances:s,configured:n,aliases:a,loading:i,removingName:r,error:c,unavailableReason:l,onRefresh:d,onRemove:u}){return e.jsxs(pe,{title:t("vm.vps.title"),subtitle:t("vm.vps.subtitle"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:n===!0?t("vm.vps.sshHost",{alias:a.join(", ")||t("vm.vps.configuredFallback")}):n===!1?e.jsxs(e.Fragment,{children:[t("vm.vps.needsAlias")," ",e.jsx(Qi,{id:"vps"})]}):t("vm.vps.refreshHint")}),e.jsx("button",{type:"button",onClick:d,disabled:i||r!==null,"aria-label":t("vm.vps.refreshAria"),className:"settings-quiet flex shrink-0 cursor-pointer items-center disabled:opacity-40",children:t("vm.refresh")})]}),c&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] leading-4 text-danger",children:c}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:i?t("vm.vps.checking"):l?t("vm.vps.unavailable",{reason:l}):n===!1?t("vm.vps.notConfigured"):s.length===1?t("vm.vps.foundOne"):t("vm.vps.foundMany",{count:s.length})}),!(n===!1&&!i&&!l)&&e.jsxs("div",{"aria-busy":i||r!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:[l&&s.length>0&&e.jsxs("div",{className:"flex items-center gap-2 border-b border-hairline/35 px-3 py-2.5 text-[12px] text-ink-secondary",children:[e.jsx(He,{size:14,className:"shrink-0 text-warning"})," ",l]}),i&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(re,{size:13,className:"animate-spin"})," ",t("vm.vps.checkingList")]}):l&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(He,{size:14,className:"shrink-0 text-warning"})," ",l]}):n===!1?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Ri,{size:14,className:"shrink-0"})," ",t("vm.vps.notConfigured")]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.vps.noneFound")}):s.map((p,x)=>{const m=Ug(p),g=hn(m),f=r===p.name,h=fn(p.name);return e.jsxs("div",{className:D("flex items-start justify-between gap-3 px-3 py-3",x>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[14px] font-medium text-ink",children:p.orphaned?t("vm.vps.orphan",{id:h}):p.ownerName}),e.jsx("span",{className:D("rounded-full px-2 py-0.5 text-[11px]",p.inUse||m==="running"?"bg-success/15 text-success":m==="stopped"||m==="paused"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:g}),a.length>1&&e.jsx("span",{className:"rounded-full bg-control px-2 py-0.5 font-mono text-[11px] text-ink-secondary",children:p.vpsAlias})]}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:p.orphaned?t("vm.owner.gone"):t("vm.owner.owned")}),p.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.vps.stopFirst")})]}),e.jsxs("button",{type:"button",onClick:()=>u(p),disabled:i||p.inUse||r!==null,"aria-busy":f||void 0,title:t("vm.vps.removeTitle"),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[f?e.jsx(re,{size:12,className:"animate-spin"}):e.jsx(We,{size:12}),t("vm.vps.remove")]})]},`${p.vpsAlias??""}:${p.name}`)})]})]})}const Ag=[1e3,2e3,4e3];function Pg(s){return new Promise(n=>window.setTimeout(n,s))}const Tg={auto:"vm.dest.auto",cloud:"place.cloud",vm:"vm.dest.vm",local:"vm.dest.local",browser:"vm.dest.browser",off:"vm.dest.off"},Ig={unmanaged:"vm.state.notManaged","in-use":"vm.state.inUse",stopped:"vm.state.stopped",running:"vm.state.running",attention:"vm.state.attention",sleeping:"vm.state.sleeping","going-to-sleep":"vm.state.goingToSleep",starting:"vm.state.starting",restarting:"vm.state.restarting",removing:"vm.state.removing",paused:"vm.state.paused"};function hn(s){return t(Ig[s])}function Lg(s){return s.managed?s.inUse?"in-use":s.container==="stopped"?"stopped":s.ready?"running":"attention":"unmanaged"}function Rg(s){return hn(Lg(s))}function Bg(s){return s.inUse?"in-use":s.state==="removing"?"removing":s.state==="archived"?"sleeping":s.state==="archiving"?"going-to-sleep":["idle","ready","running"].includes(s.state)?"running":["init","provisioning","provisioned","cloning"].includes(s.state)?"starting":"attention"}function Gr(s,n,a){const i={...a},r=new Set(s.map(l=>l.boxId)),c=s.flatMap(l=>{const d=a[l.boxId];return d==="deleted"?[]:d==="deleting"?[{...l,state:"removing"}]:d!=="sleeping"?[l]:l.state==="archived"?(delete i[l.boxId],[l]):[{...l,state:"archived"}]});for(const l of n)a[l.boxId]!=="sleeping"||r.has(l.boxId)||c.push({...l,state:"archived"});for(const[l,d]of Object.entries(a))(d==="deleted"||d==="deleting")&&!r.has(l)&&delete i[l];return{instances:c,overrides:i}}function Og(s,n,a){return s.configured!==!0||s.available!==!0?{instances:n,overrides:{...a}}:Gr(Array.isArray(s.instances)?s.instances:[],n,a)}function Fg(s){return["idle","ready","running"].includes(s.state)}function Ug(s){return s.inUse?"in-use":s.state==="running"?"running":s.state==="restarting"?"restarting":s.state==="removing"?"removing":["created","exited"].includes(s.state)?"stopped":s.state==="paused"?"paused":"attention"}function fn(s){const n=/-([a-f0-9]{12})$/i.exec(s)?.[1];return n?n.slice(-8).toLowerCase():"unknown"}function Mg(s){return{confirmation:t("vm.confirm.deleteBotVm",{name:s.name}),request:gn(`/api/bots/${s.botId}/local-computer/remove`,{})}}function Dg(s,n){return{confirmation:s==="delete"?t("vm.confirm.deleteCloud",{subject:n.orphaned?t("vm.confirm.orphanCloud"):t("vm.confirm.ownedCloud",{name:n.ownerName??""})}):null,request:gn(`/api/computers/boxes/${encodeURIComponent(n.boxId)}/${s}`,s==="delete"?{confirmName:n.name}:{})}}function zg(s){const n=fn(s.name);return{confirmation:t("vm.confirm.removeVps",{subject:s.orphaned?t("vm.confirm.orphanVps",{id:n}):t("vm.confirm.ownedVps",{name:s.ownerName??""})}),request:gn(`/api/computers/vps/${encodeURIComponent(s.name)}/remove`,{confirmName:s.name,alias:s.vpsAlias})}}function ws(s,n){return s.confirmation!==null&&!n(s.confirmation)?null:s.request}function _g({instances:s,configured:n,loading:a,pending:i,error:r,unavailableReason:c,onRefresh:l,onSleep:d,onDelete:u}){return e.jsxs(pe,{title:t("vm.cloud.title"),subtitle:t("vm.cloud.subtitle"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:n===!0?t("vm.cloud.includesOrphans"):n===!1?e.jsxs(e.Fragment,{children:[t("vm.cloud.needsKey")," ",e.jsx(Qi,{id:"box"})]}):t("vm.cloud.refreshHint")}),e.jsx("button",{type:"button",onClick:l,disabled:a||i!==null,"aria-label":t("vm.cloud.refreshAria"),className:"settings-quiet -me-1.5 flex shrink-0 cursor-pointer items-center disabled:opacity-40",children:t("vm.refresh")})]}),r&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] leading-4 text-danger",children:r}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a?t("vm.cloud.checking"):c?t("vm.cloud.unavailable",{reason:c}):n===!1?t("vm.cloud.notConnected"):s.length===1?t("vm.cloud.foundOne"):t("vm.cloud.foundMany",{count:s.length})}),!(n===!1&&!a&&!c)&&e.jsx("div",{"aria-busy":a||i!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsx("div",{role:"status","aria-label":t("vm.cloud.checkingList"),className:"flex flex-col",children:e.jsx(an,{})}):c?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(He,{size:14,className:"shrink-0 text-warning"})," ",c]}):n===!1?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Ti,{size:14,className:"shrink-0"})," ",t("vm.cloud.notConnected")]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.cloud.noneFound")}):s.map((p,x)=>{const m=Bg(p),g=hn(m),f=i?.boxId===p.boxId,h=Fg(p),j=m==="removing";return e.jsxs("div",{className:D("flex items-start justify-between gap-3 px-3 py-3",x>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[14px] font-medium text-ink",children:p.orphaned?t("vm.cloud.orphan"):p.ownerName}),e.jsx("span",{className:D("rounded-full px-2 py-0.5 text-[11px]",p.inUse||m==="running"?"bg-success/15 text-success":m==="sleeping"||m==="going-to-sleep"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:g})]}),e.jsxs("div",{className:"mt-1 break-all text-[12px] text-ink-secondary",children:[p.orphaned?t("vm.owner.gone"):t("vm.owner.owned")," · ",p.name]}),p.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.cloud.stopFirst")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>d(p),disabled:a||p.inUse||i!==null||!h,"aria-busy":f&&i?.action==="sleep"?!0:void 0,title:h?t("vm.cloud.sleepTitle"):t("vm.cloud.sleepBlocked",{state:g.toLowerCase()}),className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:cursor-not-allowed disabled:opacity-40",children:[f&&i?.action==="sleep"?e.jsx(re,{size:12,className:"animate-spin"}):e.jsx(ao,{size:12}),t("vm.cloud.sleep")]}),e.jsxs("button",{type:"button",onClick:()=>u(p),disabled:a||p.inUse||i!==null||j,"aria-busy":f&&i?.action==="delete"?!0:void 0,title:t("vm.cloud.deleteTitle"),className:"flex items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[f&&i?.action==="delete"?e.jsx(re,{size:12,className:"animate-spin"}):e.jsx(We,{size:12}),t("common.delete")]})]})]},p.boxId)})})]})}function Hg({instances:s,maxInstances:n,loading:a,deletingBotId:i,error:r,unavailableReason:c,onRefresh:l,onDelete:d}){return e.jsxs(pe,{title:t("vm.perBot.title"),subtitle:t("vm.perBot.subtitle",{count:c?t("vm.perBot.inventoryUnavailable"):t("vm.perBot.created",{count:s.length,max:n})}),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("vm.perBot.deleteHint")}),e.jsx("button",{type:"button",onClick:l,disabled:a||i!==null,"aria-label":t("vm.perBot.refreshAria"),className:"settings-quiet flex shrink-0 cursor-pointer items-center disabled:opacity-40",children:t("vm.refresh")})]}),r&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] leading-4 text-danger",children:r}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a?t("vm.perBot.checking"):c?t("vm.perBot.unavailable",{reason:c}):s.length===1?t("vm.perBot.foundOne"):t("vm.perBot.foundMany",{count:s.length})}),e.jsx("div",{"aria-busy":a||i!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsx("div",{role:"status","aria-label":t("vm.perBot.checkingList"),className:"flex flex-col",children:e.jsx(an,{})}):c?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(He,{size:14,className:"shrink-0 text-warning"})," ",c]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.perBot.none")}):s.map((u,p)=>{const x=Rg(u),m=i===u.botId,g=u.managed===!0;return e.jsxs("div",{className:D("flex items-start justify-between gap-3 px-3 py-3",p>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[14px] font-medium text-ink",children:u.name}),e.jsx("span",{className:D("rounded-full px-2 py-0.5 text-[11px]",g?u.inUse||u.ready?"bg-success/15 text-success":u.container==="stopped"?"bg-control text-ink-secondary":"bg-warning/15 text-warning":"bg-warning/15 text-warning"),children:x})]}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.perBot.destination",{destination:t(Tg[u.destination])})}),!g&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:t("vm.perBot.unmanaged")}),g&&u.problem&&!u.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:Zi(u.problem)}),g&&u.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.perBot.stopFirst")})]}),g&&e.jsxs("button",{type:"button",onClick:()=>d(u),disabled:a||u.inUse||i!==null,"aria-busy":m||void 0,title:u.inUse?t("vm.perBot.deleteBlocked"):t("vm.perBot.deleteTitle",{name:u.name}),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[m?e.jsx(re,{size:12,className:"animate-spin"}):e.jsx(We,{size:12}),t("common.delete")]})]},u.botId)})})]})}function Bt({n:s,title:n,done:a,children:i}){return e.jsxs("div",{className:"flex gap-3","data-vm-step":s,children:[e.jsx("span",{className:"flex size-8 shrink-0 items-start justify-center pt-0.5",children:e.jsx("span",{"aria-hidden":"true",className:"flex size-5 items-center justify-center rounded-full bg-ink/[0.06] text-[12px] font-medium leading-4 text-ink-secondary",children:a?e.jsx(_e,{size:12}):s})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:D("text-[14px] leading-5",a?"text-ink-secondary":"text-ink"),children:n}),!a&&i&&e.jsx("div",{className:"mt-2 flex flex-col items-start gap-2 [&>*]:max-w-full",children:i})]})]})}function tt({action:s,pending:n,children:a,onClick:i,danger:r=!1}){return e.jsxs("button",{onClick:i,"aria-busy":n===s,disabled:n!==null,"data-danger":r?"":void 0,className:D(r?"settings-quiet flex cursor-pointer items-center gap-1.5":"ui-button ui-button-md cursor-pointer rounded-full","disabled:opacity-50"),children:[n===s&&e.jsx(re,{size:13,className:"animate-spin"}),a]})}const qr=5,Vr=1440,$g=480;function Kg(s){const n=s.trim();if(!/^\d+$/.test(n))return null;const a=Number(n);return a>=qr&&a<=Vr?a:null}function Wg({minutes:s,disabled:n,onSave:a}){const[i,r]=o.useState(String(s)),[c,l]=o.useState(!1),[d,u]=o.useState(""),[p,x]=o.useState(!1);o.useEffect(()=>{c||r(String(s))},[s,c]);const m=async()=>{if(!c||p)return;const g=Kg(i);if(g===null){u(t("vm.idle.range"));return}x(!0);try{await a(g),r(String(g)),l(!1),u("")}catch(f){u(f instanceof Error?f.message:t("vm.idle.error"))}finally{x(!1)}};return e.jsxs("div",{className:"mt-3 flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-6",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:"local-vm-idle-timeout",className:"text-[14px] leading-5 text-ink",children:t("vm.idle.label")}),e.jsx("div",{id:"local-vm-idle-timeout-help",className:"text-[13px] leading-[18px] text-ink-secondary",children:t("vm.idle.detail")})]}),e.jsxs("span",{className:"flex shrink-0 items-center gap-2",children:[e.jsx("input",{id:"local-vm-idle-timeout",type:"number",min:qr,max:Vr,step:1,inputMode:"numeric",value:i,disabled:n||p,"aria-invalid":!!d,"aria-describedby":d?"local-vm-idle-timeout-error local-vm-idle-timeout-help":"local-vm-idle-timeout-help",onChange:g=>{r(g.target.value),l(!0),u("")},onBlur:()=>{m()},onKeyDown:g=>{g.key==="Enter"&&g.currentTarget.blur()},className:D(Ue,"w-16 bg-transparent",d&&"border-danger/60")}),e.jsx("span",{className:"text-[13px] leading-5 text-ink-secondary",children:t("vm.idle.minutes")})]})]}),d?e.jsx("p",{id:"local-vm-idle-timeout-error",role:"alert",className:"text-[12px] leading-4 text-danger",children:d}):null]})}function ui({label:s,command:n}){const[a,i]=o.useState(!1);return e.jsxs("div",{className:"flex w-full flex-col gap-2",children:[e.jsx("button",{type:"button","aria-expanded":a,className:"settings-quiet -ml-1.5 cursor-pointer self-start",onClick:()=>i(r=>!r),children:s}),a&&e.jsx(Bs,{command:n})]})}function Gg({perBot:s,path:n}){const[a,i]=o.useState(!1);return e.jsxs("div",{className:"flex flex-col gap-1 text-[13px] leading-[18px] text-ink-secondary",children:[e.jsxs("p",{children:[t(s?"vm.safety.perBotShort":"vm.safety.sharedShort",{path:n})," ",e.jsx(Ke,{onClick:()=>i(r=>!r)})]}),a&&e.jsx("p",{className:"text-[12px] leading-4",children:t(s?"vm.safety.perBot":"vm.safety.shared",{path:n})})]})}function Jr({privateOnly:s=!1}){const n=_().state.config?.cloudHome===!0,[a,i]=o.useState(null),[r,c]=o.useState(!0),[l,d]=o.useState(null),u=o.useRef(null);o.useEffect(()=>()=>u.current?.abort(),[]);const[p,x]=o.useState(null),[m,g]=o.useState(!1),[f,h]=o.useState(0),[j,b]=o.useState([]),[y,v]=o.useState(2),[w,N]=o.useState(!1),[C,I]=o.useState(null),[F,k]=o.useState(null),[S,P]=o.useState(null),[E,A]=o.useState(0),[q,R]=o.useState([]),[K,Z]=o.useState(null),[oe,se]=o.useState(!0),[Y,B]=o.useState(null),[W,G]=o.useState(null),[le,U]=o.useState(null),[H,Q]=o.useState(0),te=o.useRef([]),ie=o.useRef({}),[Se,de]=o.useState([]),[be,$]=o.useState(null),[me,he]=o.useState([]),[ke,Re]=o.useState(!0),[Ye,ue]=o.useState(null),[Pe,Te]=o.useState(null),[Be,Ie]=o.useState(null),[rs,ls]=o.useState(0),[T,ae]=o.useState(""),ve=o.useCallback(async O=>{const z=await fetch(...gt("status",O)),X=await z.json().catch(()=>({}));if(!O?.aborted){if(!z.ok)throw new Error(X.error??t("vm.err.status",{code:z.status}));return i(X),x(null),X}},[]),Ge=o.useCallback(async O=>{const z=await fetch(...gt("local-vms",O)),X=await z.json().catch(()=>({}));if(!z.ok)throw new Error(X.error??t("vm.err.inventory",{code:z.status}));const ee=X;b(ee.instances),v(ee.maxInstances),k(ee.available?null:Zi(ee.problem)??t("vm.err.runtimeUnavailable")),I(null)},[]),dt=o.useCallback(async O=>{const z=await fetch(...gt("cloud",O)),X=await z.json().catch(()=>({}));if(!z.ok)throw new Error(X.error??t("vm.err.cloudInventory",{code:z.status}));const ee=X,fe=Og(ee,te.current,ie.current);ie.current=fe.overrides,te.current=fe.instances,R(fe.instances),Z(ee.configured===!0),G(ee.available||!ee.configured?null:ee.problem??t("vm.err.cloudUnavailable")),B(null)},[]),os=o.useCallback(async O=>{const z=await fetch(...gt("vps",O)),X=await z.json().catch(()=>({}));if(!z.ok)throw new Error(X.error??t("vm.err.vpsInventory",{code:z.status}));const ee=X;de(Array.isArray(ee.instances)?ee.instances:[]),$(ee.configured===!0),he(Array.isArray(ee.vpsAliases)?ee.vpsAliases:[]),Te(ee.available||!ee.configured?null:ee.problem??t("vm.err.vpsUnavailable")),ue(null)},[]);o.useEffect(()=>{if(n)return;let O=!0,z,X;const ee=async()=>{X=new AbortController;try{await ve(X.signal)}catch(fe){O&&!(fe instanceof DOMException&&fe.name==="AbortError")&&(i(null),x(fe instanceof Error?fe.message:String(fe)))}finally{O&&(c(!1),z=window.setTimeout(()=>{ee()},5e3))}};return ee(),()=>{O=!1,X?.abort(),z!==void 0&&window.clearTimeout(z)}},[n,ve,f]),o.useEffect(()=>{if(a?.mode!=="per-bot"){b([]),N(!1),I(null),k(null);return}const O=new AbortController;return N(!0),Ge(O.signal).catch(z=>{z instanceof DOMException&&z.name==="AbortError"||I(z instanceof Error?z.message:String(z))}).finally(()=>{O.signal.aborted||N(!1)}),()=>O.abort()},[E,Ge,a?.mode]),o.useEffect(()=>{if(s)return;const O=new AbortController;return se(!0),dt(O.signal).catch(z=>{z instanceof DOMException&&z.name==="AbortError"||G(z instanceof Error?z.message:String(z))}).finally(()=>{O.signal.aborted||se(!1)}),()=>O.abort()},[H,s,dt]),o.useEffect(()=>{if(s)return;const O=new AbortController;return Re(!0),os(O.signal).catch(z=>{z instanceof DOMException&&z.name==="AbortError"||Te(z instanceof Error?z.message:String(z))}).finally(()=>{O.signal.aborted||Re(!1)}),()=>O.abort()},[s,os,rs]);const cs=async(O,z)=>{const X=await fetch(`/api/local-computer/${O}`,{method:"POST",headers:{"content-type":"application/json"},body:"{}",signal:z}),ee=await X.json().catch(()=>({})),fe={pull:"vm.err.prepare",run:"vm.err.create",start:"vm.err.start",stop:"vm.err.stop",remove:"vm.deleteError"};if(!X.ok)throw new Error(ee.error??t(fe[O]));return z.throwIfAborted(),i(ee),ee},bn=O=>window.ogb?.confirm?window.ogb.confirm(O):window.confirm(O),Xe=async O=>{if(l!==null||u.current)return;const z=new AbortController;u.current=z,d(O),x(null);try{if(O==="remove"&&!await bn(t("vm.confirm.deleteShared"))||O==="recreate"&&!await bn(t("vm.confirm.recreate")))return;let X;if(O==="recreate"?(await cs("remove",z.signal),X=await cs("run",z.signal)):X=await cs(O,z.signal),(O==="run"||O==="start"||O==="recreate")&&(X=await ku(X,async()=>await ve(z.signal)??X,z.signal),!X.ready))throw new Error(X.problem??t("vm.err.start"));await ve(),ae(O==="remove"?t("vm.announce.deleted"):O==="stop"?t("vm.announce.stopped"):t("vm.announce.updated"))}catch(X){if(z.signal.aborted)return;x(X instanceof Error?X.message:String(X))}finally{u.current=null,z.signal.aborted||d(null)}},vn=async(O,z)=>{g(!0),x(null);try{const X=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{mode:O,maxInstances:z}})}),ee=await X.json().catch(()=>({}));if(!X.ok)throw new Error(ee.error??t("vm.policyError"));i(fe=>fe&&{...fe,mode:O,max_instances:z}),await ve()}catch(X){x(X instanceof Error?X.message:String(X))}finally{g(!1)}},al=async O=>{const z=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{idleTimeoutMinutes:O}})}),X=await z.json().catch(()=>({}));if(!z.ok)throw new Error(X.error??t("vm.idle.error"));i(ee=>ee&&{...ee,idle_timeout_ms:O*6e4})},il=async O=>{if(!O.managed){I(t("vm.unmanagedError"));return}const z=ws(Mg(O),X=>window.confirm(X));if(z){P(O.botId),I(null);try{const X=await fetch(...z),ee=await X.json().catch(()=>({}));if(!X.ok)throw new Error(ee.error??t("vm.deleteError"));await Ge(),ae(t("vm.announce.deletedBot",{name:O.name}))}catch(X){I(X instanceof Error?X.message:String(X))}finally{P(null)}}},yn=async(O,z)=>{const X=ws(Dg(O,z),ee=>window.confirm(ee));if(X){U({boxId:z.boxId,action:O}),B(null),ae("");try{const ee=await fetch(...X),fe=await ee.json().catch(()=>({}));if(!ee.ok)throw new Error(fe.error??t(O==="delete"?"vm.cloud.deleteError":"vm.cloud.sleepError"));const us=O==="delete"&&fe?.pending===!0;ie.current={...ie.current,[z.boxId]:O==="delete"?us?"deleting":"deleted":"sleeping"};const ps=Gr(te.current,te.current,ie.current);ie.current=ps.overrides,te.current=ps.instances,R(ps.instances);const Qe=z.orphaned?t("vm.announce.orphanCloud"):t("vm.confirm.ownedCloud",{name:z.ownerName??""});if(ae(us?`${Qe}: ${t("vm.state.removing")}.`:t(O==="delete"?"vm.announce.cloudDeleted":"vm.announce.cloudSleeping",{subject:Qe})),us){for(const Le of Ag){await Pg(Le);try{await dt()}catch{}if(ie.current[z.boxId]!=="deleting"){ae(t("vm.announce.cloudDeleted",{subject:Qe}));return}}const Ze={...ie.current};delete Ze[z.boxId],ie.current=Ze;const Tt=te.current.map(Le=>Le.boxId===z.boxId?{...Le,state:z.state}:Le);te.current=Tt,R(Tt);try{await dt(),te.current.some(Le=>Le.boxId===z.boxId)||ae(t("vm.announce.cloudDeleted",{subject:Qe}))}catch(Le){const ll=Le instanceof Error?Le.message:String(Le);B(`${Qe}: ${t("vm.state.removing")}. ${ll}`)}return}try{await dt()}catch(Ze){const Tt=Ze instanceof Error?Ze.message:String(Ze);B(t(O==="delete"?"vm.cloud.deletedRefreshError":"vm.cloud.sleepRefreshError",{subject:Qe,detail:Tt}))}}catch(ee){B(ee instanceof Error?ee.message:String(ee))}finally{U(null)}}},rl=async O=>{const z=fn(O.name),X=ws(zg(O),ee=>window.confirm(ee));if(X){Ie(O.name),ue(null);try{const ee=await fetch(...X),fe=await ee.json().catch(()=>({}));if(!ee.ok)throw new Error(fe.error??t("vm.vpsRemoveError"));await os(),ae(t("vm.announce.vpsRemoved",{subject:O.orphaned?t("vm.announce.orphanVps",{id:z}):t("vm.confirm.ownedVps",{name:O.ownerName??""})}))}catch(ee){ue(ee instanceof Error?ee.message:String(ee))}finally{Ie(null)}}},Oe=a?.commands,Pt=a?.ready===!0,jn=a?.container!=="missing",kn=!!(jn&&(!a?.imageMatches||!a?.managed||a?.network==="unsafe"||a?.security==="unsafe"||a?.persistence==="unsafe")),wn=!r&&!a,Nn=a?.platform==="darwin"?t("vm.host.mac"):t("vm.host.computer"),Ce=a?.mode==="per-bot",ds=Ce&&a?.runtime==="container",Sn=Ce?!!(a?.daemonUp&&a?.image&&!ds):Pt;return e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:T}),!s&&e.jsxs(e.Fragment,{children:[e.jsx(_g,{instances:q,configured:K,loading:oe,pending:le,error:Y,unavailableReason:W,onRefresh:()=>Q(O=>O+1),onSleep:O=>{yn("sleep",O)},onDelete:O=>{yn("delete",O)}}),e.jsx(Eg,{instances:Se,configured:be,aliases:me,loading:ke,removingName:Be,error:Ye,unavailableReason:Pe,onRefresh:()=>ls(O=>O+1),onRemove:O=>{rl(O)}}),e.jsx(ju,{})]}),!n&&e.jsxs(e.Fragment,{children:[e.jsxs(pe,{title:t("vm.main.title"),subtitle:Ce?t("vm.main.perBotSubtitle",{host:Nn}):t("vm.main.sharedSubtitle",{host:Nn}),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{"aria-live":"polite",className:"mr-auto flex items-center text-[13px] leading-[18px] text-ink-secondary",children:[r?e.jsx(re,{size:12,className:"mr-1.5 animate-spin"}):e.jsx(Je,{tone:Sn?"success":null}),r?t("common.checking"):wn?t("vm.main.statusUnavailable"):Ce&&Sn?t("vm.main.readyPerBot"):ds?t("vm.main.perBotUnsupported"):Pt?t("vm.main.ready"):a?.problem??t("vm.main.notReady")]}),e.jsx("button",{onClick:()=>{c(!0),h(O=>O+1),A(O=>O+1)},disabled:r||l!==null,className:"settings-quiet cursor-pointer last:-me-1.5 disabled:opacity-40",children:t("vm.main.recheck")}),Pt&&!Ce&&e.jsx("a",{href:a?.viewer_url??Oe?.view,target:"_blank",rel:"noreferrer",className:"settings-quiet cursor-pointer",children:t("vm.main.watch")})]}),p&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] leading-4 text-danger",children:p})]}),e.jsxs(pe,{title:t("vm.isolation.title"),subtitle:t("vm.isolation.subtitle"),children:[e.jsx("div",{className:"flex justify-end",children:e.jsx(zi,{label:t("vm.isolation.title"),value:a?.mode==="per-bot"?"per-bot":"shared",disabled:!a||m,onChange:O=>{a&&vn(O,a.max_instances??2)},options:[{value:"shared",label:t("vm.isolation.shared")},{value:"per-bot",label:t("vm.isolation.perBot")}]})}),Ce&&e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[13px] text-ink",children:t("vm.isolation.max")}),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("vm.isolation.maxDetail")})]}),e.jsx(ce,{size:"sm","aria-label":t("vm.isolation.maxAria"),value:a?.max_instances??2,disabled:!a||m,onChange:O=>{vn(a?.mode??"shared",Number(O.target.value))},children:[1,2,3,4,5,6,7,8].map(O=>e.jsx("option",{value:O,children:O},O))})]}),e.jsx(Wg,{minutes:a?Math.round(a.idle_timeout_ms/6e4):$g,disabled:!a||m,onSave:al}),m&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx(re,{size:12,className:"animate-spin"})," ",t("vm.saving")]})]}),e.jsx(pe,{title:t("vm.setup.title"),subtitle:t("vm.setup.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs(Bt,{n:1,title:t("vm.setup.step1"),done:!!a?.runtime,children:[e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.step1Detail")}),Oe?.install?e.jsx(Bs,{command:Oe.install}):e.jsx("a",{href:"https://podman.io/docs/installation",target:"_blank",rel:"noreferrer",className:"text-[13px] text-accent hover:underline",children:t("vm.setup.podmanGuide")})]}),e.jsx(Bt,{n:2,title:a?.runtime&&!a.daemonUp?t("vm.setup.step2Open",{runtime:a.runtime}):t("vm.setup.step2"),done:!!a?.daemonUp,children:a?.runtime?Oe?.runtimeStart?e.jsx(Bs,{command:Oe.runtimeStart}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.step2Detail")}):null}),e.jsxs(Bt,{n:3,title:t("vm.setup.step3"),done:!!a?.image,children:[a?.daemonUp&&e.jsx(tt,{action:"pull",pending:l,onClick:()=>{Xe("pull")},children:t("vm.setup.prepare")}),Oe?.pull&&e.jsx(ui,{label:t("vm.setup.showPull"),command:Oe.pull})]}),e.jsxs(Bt,{n:4,title:Ce?t("vm.setup.step4PerBot"):kn?t("vm.setup.step4Recreate"):t("vm.setup.step4"),done:!Ce&&Pt,children:[Ce?e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:ds?t("vm.setup.applePort"):t("vm.setup.perBotHint")}):kn?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2 text-[13px] text-warning",children:[e.jsx(He,{size:15,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:a?.problem})]}),a?.image?e.jsxs(tt,{action:"recreate",pending:l,onClick:()=>{Xe("recreate")},danger:!0,children:[e.jsx(xd,{size:13})," ",t("vm.setup.recreate")]}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.prepareFirst")})]}):a?.container==="stopped"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(a.stop_reason==="idle"?"vm.stopped.idle":"vm.stopped.detail")}),e.jsx(tt,{action:"start",pending:l,onClick:()=>{Xe("start")},children:t("vm.setup.start")})]}):a?.container==="running"?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(re,{size:13,className:"animate-spin"})," ",t("vm.setup.waiting")]}):a?.image?e.jsxs(e.Fragment,{children:[e.jsx(tt,{action:"run",pending:l,onClick:()=>{Xe("run")},children:t("vm.setup.start")}),e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.idleHint")})]}):null,Oe?.run&&e.jsx(ui,{label:t("vm.setup.showCommand"),command:Oe.run})]})]})}),Ce&&e.jsx(Hg,{instances:j,maxInstances:y||a?.max_instances||2,loading:w,deletingBotId:S,error:C,unavailableReason:F,onRefresh:()=>A(O=>O+1),onDelete:O=>{il(O)}}),wn&&e.jsx(pe,{children:e.jsxs("div",{className:"flex gap-2 text-[13px] text-ink-secondary",children:[e.jsx(He,{size:15,className:"mt-0.5 shrink-0 text-warning"}),e.jsx("span",{children:t("vm.inspectFailed")})]})}),e.jsxs(pe,{title:t("vm.safety.title"),children:[e.jsx(Gg,{perBot:Ce,path:a?.workspace_guest_path??"/home/cua/workspace"}),jn&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[a?.container==="running"&&e.jsxs(tt,{action:"stop",pending:l,onClick:()=>{Xe("stop")},children:[e.jsx(gd,{size:12})," ",t("vm.safety.stop")]}),e.jsxs(tt,{action:"remove",pending:l,onClick:()=>{Xe("remove")},danger:!0,children:[e.jsx(We,{size:12})," ",Ce?t("vm.safety.deleteLegacy"):t("vm.safety.deleteVm")]})]}),e.jsx("div",{"data-vm-folder":"",className:"flex flex-col font-mono text-[12px] leading-4 text-ink-secondary",children:[...t("vm.safety.workspace",{path:a?.workspace_path??t("vm.safety.notCreated"),driver:a?.driver_version??"0.37.0",image:a?.image_ref??t("vm.safety.notPrepared")}).split(" · "),...a?.base_image_ref?[t("vm.safety.baseImage",{image:a.base_image_ref})]:[]].map(O=>{const z=O.indexOf(": "),X=z<0?O:O.slice(z+2);return e.jsxs("span",{className:"block",children:[z<0?null:O.slice(0,z+2),e.jsx("span",{className:/[@:]sha256|^sha256|[0-9a-f]{24,}/.test(X)?"[overflow-wrap:anywhere]":"break-words",children:X})]},O)})})]})]})]})}const qg=10,Yr=1,Xr=60,pi="Enter a whole number from 1 to 60.";function Vg(s){const n=s.trim();if(!/^\d+$/.test(n))return{ok:!1,error:pi};const a=Number(n);return a<Yr||a>Xr?{ok:!1,error:pi}:{ok:!0,minutes:a}}function mi(s){return s?.mcp?.callTimeoutMinutes??qg}function Jg(){const{state:s,dispatch:n}=_(),a=mi(s.config),[i,r]=o.useState(String(a)),[c,l]=o.useState(!1),[d,u]=o.useState(""),[p,x]=o.useState(!1),m=o.useRef(!1);o.useEffect(()=>{c||r(String(a))},[a,c]);const g=async()=>{if(!c||m.current)return;const f=Vg(i);if(!f.ok){u(t("settings.mcpCalls.range"));return}m.current=!0,x(!0);try{const h=await M("/api/config",{method:"PUT",body:JSON.stringify({mcp:{callTimeoutMinutes:f.minutes}})});n({type:"configStatus",config:h}),r(String(mi(h))),l(!1),u("")}catch(h){u(h instanceof Error?h.message:t("settings.mcpCalls.error"))}finally{m.current=!1,x(!1)}};return e.jsx(L,{title:t("settings.limits.toolTime"),subtitle:t("settings.limits.toolTimeLine"),message:d?e.jsx("span",{id:"mcp-call-timeout-error",role:"alert",className:"text-danger",children:d}):void 0,children:e.jsxs("span",{className:"flex w-[160px] items-center gap-2 text-[13px] leading-5 text-ink-secondary",children:[e.jsx("input",{id:"mcp-call-timeout",type:"number",min:Yr,max:Xr,step:1,inputMode:"numeric",value:i,disabled:p,"aria-label":t("settings.limits.toolTime"),"aria-invalid":!!d,"aria-describedby":d?"mcp-call-timeout-error":void 0,title:t("settings.mcpCalls.help"),onChange:f=>{r(f.target.value),l(!0),u("")},onBlur:()=>{g()},onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()},className:D(Ue,"w-auto min-w-0 flex-1",d&&"border-danger/60")}),t("settings.mcpCalls.minutes")]})})}const Yg={format:"placeLook.imageFormat",read:"placeLook.imageRead",size:"placeLook.imageSize",animated:"placeLook.imageMoving",failed:"placeLook.imageFailed"};function Xg({banner:s,canChange:n,subtitle:a}){const i=o.useRef(null),[r,c]=o.useState(!1),[l,d]=o.useState(null),u=hd(s),p=async g=>{c(!0),d(null);const f=await Promise.resolve().then(g).catch(()=>({ok:!1,problem:"failed"}));c(!1),f.ok||d(Yg[f.problem])},x=g=>{i.current&&(i.current.value=""),!(!g||!n)&&p(async()=>{const f=await bd(g);return f.ok?vd(f.blob):f})},m=l?e.jsx("p",{role:"alert",className:"text-danger",children:t(l)}):n?null:e.jsx("p",{className:"text-ink-secondary",children:t("placeLook.imageAdmins")});return e.jsx("div",{"data-place-picture":u?"set":"none",children:e.jsx(L,{title:t("placeLook.sidebarPicture"),subtitle:a,message:m,children:e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[u&&e.jsx("img",{src:u,alt:t("placeLook.currentImage"),className:"h-8 w-14 rounded-md border border-ink/10 object-cover"}),e.jsx("button",{type:"button",className:"ui-button",disabled:!n||r,onClick:()=>i.current?.click(),children:r?t("placeLook.imageSaving"):t(u?"placeLook.changeImage":"placeLook.useImage")}),u&&e.jsx("button",{type:"button",className:"ui-button",disabled:!n||r,onClick:()=>{p(yd)},children:t("placeLook.removeImage")}),e.jsx("input",{ref:i,type:"file",accept:fd,hidden:!0,"data-place-picture-input":!0,onChange:g=>x(g.target.files?.[0])})]})})})}function Qg(){const s=jd(),n=er(),{state:a}=_(),i=kt()===!0,r=window.ogb?.app?.ownPage===!0,[c,l]=o.useState(null),[d,u]=o.useState(null),p=s?.change===null,x=g=>{!s||p||c||g===(s.swatch??"slate")||(l(g),u(null),kd(g).then(f=>{l(null),u(f)}))},m=s?.reason==="member"||d==="refused"?t("placeLook.member"):s?.reason==="signed-out"?t("placeLook.signedOut"):d==="unsupported"?t("placeLook.unsupported"):null;return e.jsxs(e.Fragment,{children:[s&&e.jsx("div",{"data-place-look":s.change??"locked",children:e.jsx(L,{title:t("placeLook.sidebarColor"),subtitle:t("placeLook.colorLine",{place:n.name}),message:d==="failed"?e.jsx("p",{role:"alert",className:"text-danger",children:t("placeLook.failed")}):m&&e.jsx("p",{className:"text-ink-secondary",children:m}),children:e.jsx(io,{value:c??s.swatch,onChange:x,label:r?t("placeLook.sidebarColor"):t("placeLook.aria",{name:n.name}),disabled:p,offset:"menu",none:!0})})}),e.jsx(Xg,{banner:a.config?.workspaceBanner??null,canChange:i,subtitle:t("placeLook.pictureLine")})]})}function Qr(s,n){let a={value:s,status:"idle"},i=!1,r,c;const l=new Set,d=(p,x)=>{a={value:p,status:x};for(const m of l)m()},u=()=>(clearTimeout(c),r||(i?(d(a.value,"saving"),r=(async()=>{try{for(;i;){const p=a.value;await n(p),i=a.value!==p}d(a.value,"saved")}catch{d(a.value,"error")}})().finally(()=>{r=void 0}),r):Promise.resolve()));return{getSnapshot:()=>a,subscribe(p){return l.add(p),()=>{l.delete(p)}},confirm(p){!i&&!r&&p!==a.value&&d(p,"idle")},edit(p){i=!0,d(p,"idle"),clearTimeout(c),c=setTimeout(()=>{u()},600)},flush:u}}const xi=new WeakMap;function Zg(){const{state:s,dispatch:n}=_(),a=s.config?.profile?.aboutMe??"",i=!!s.config?.team;let r=xi.get(n);if(!r){const p={current:i};r={team:p,controller:Qr(a,async x=>{const m=p.current?await en({aboutMe:x}):(await M("/api/config",{method:"PUT",body:JSON.stringify({profile:{aboutMe:x}}),timeoutMs:1e4})).profile;n({type:"profileSaved",profile:{aboutMe:m?.aboutMe??x}})})},xi.set(n,r)}r.team.current=i;const c=r.controller,{value:l,status:d}=o.useSyncExternalStore(c.subscribe,c.getSnapshot,c.getSnapshot),{flush:u}=c;return o.useEffect(()=>{c.confirm(a)},[c,a]),o.useEffect(()=>()=>{u()},[u]),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"profile-about-me",title:t("settings.profile.aboutMeHelp"),className:"text-[13px] font-medium leading-[18px] text-ink",children:t("settings.profile.aboutMe")}),e.jsx("textarea",{id:"profile-about-me",value:l,rows:5,maxLength:i?4e3:24e3,onChange:p=>c.edit(p.target.value),onBlur:()=>{u()},placeholder:t("settings.profile.aboutMeHelp"),className:`min-h-[96px] w-full resize-none rounded-lg ${tr} bg-app px-2 py-1.5 text-[13px] leading-5 text-ink placeholder:text-ink-tertiary focus:outline-none focus-visible:outline-2 focus-visible:outline-offset-0 focus-visible:outline-focus`}),e.jsx(eh,{onChanged:p=>{c.confirm(p),n({type:"profileSaved",profile:{aboutMe:p}})}}),e.jsxs("div",{className:"text-[12px] leading-4 empty:hidden",role:"status",children:[d==="saving"&&e.jsx("span",{className:"text-ink-secondary",children:t("settings.profile.saving")}),d==="saved"&&e.jsx("span",{className:"text-success",children:t("settings.profile.saved")}),d==="error"&&e.jsxs("span",{className:"text-danger",children:[t("settings.profile.saveError")," "," ",e.jsx("button",{type:"button",onClick:()=>{u()},className:"underline",children:t("settings.profile.retry")})]})]})]})}function eh({onChanged:s}){const[n,a]=o.useState([]),[i,r]=o.useState(null),[c,l]=o.useState(!1);o.useEffect(()=>{let u=!1;return M("/api/profile/learned").then(p=>{u||a(p.learned)}).catch(()=>{}),()=>{u=!0}},[]);const d=async u=>{r(u),l(!1);try{const p=await M(`/api/profile/learned/${encodeURIComponent(u)}/remove`,{method:"POST"});a(p.learned),s(p.aboutMe)}catch{l(!0)}finally{r(null)}};return n.length?e.jsxs("div",{className:"mt-1 rounded-lg border border-hairline/40 bg-inset p-3",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("settings.profile.learned.title")}),e.jsx("p",{className:"mt-0.5 text-[12px] text-ink-secondary",children:t("settings.profile.learned.hint")}),e.jsx("ul",{className:"mt-2 flex flex-col gap-2",children:n.map(u=>e.jsxs("li",{className:"flex flex-wrap items-center gap-2 text-[13px] text-ink",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[u.text," ",e.jsx("span",{className:"text-[12px] text-ink-secondary",children:t("settings.profile.learned.from",{name:u.botName})})]}),e.jsx("button",{type:"button",disabled:i===u.id,onClick:()=>{d(u.id)},className:"rounded-md px-2 py-1 text-[13px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:t("settings.profile.learned.remove")})]},u.id))}),c&&e.jsx("div",{className:"mt-2 text-[12px] text-danger",children:t("settings.profile.learned.error")})]}):null}const gi=new WeakMap;function th(){const{state:s,dispatch:n}=_(),a=s.config?.everyBotRules;let i=gi.get(n);i||(i=Qr(a??"",async p=>{const x=await M("/api/config",{method:"PUT",body:JSON.stringify({everyBotRules:p}),timeoutMs:1e4});n({type:"configStatus",config:x})}),gi.set(n,i));const{value:r,status:c}=o.useSyncExternalStore(i.subscribe,i.getSnapshot,i.getSnapshot),{confirm:l,edit:d,flush:u}=i;return o.useEffect(()=>{l(a??"")},[l,a]),o.useEffect(()=>()=>{u()},[u]),a===void 0?null:e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"profile-every-bot-rules",className:"text-[13px] font-medium leading-[18px] text-ink",children:t("settings.profile.everyBotRules")}),e.jsx("textarea",{id:"profile-every-bot-rules",value:r,rows:4,maxLength:24e3,placeholder:t("settings.profile.everyBotRulesPlaceholder"),onChange:p=>d(p.target.value),onBlur:()=>{u()},className:`min-h-[96px] w-full resize-none rounded-lg ${tr} bg-app px-2 py-1.5 text-[13px] leading-5 text-ink placeholder:text-ink-tertiary focus:outline-none focus-visible:outline-2 focus-visible:outline-offset-0 focus-visible:outline-focus`}),e.jsxs("div",{className:"text-[12px] leading-4 empty:hidden",role:"status",children:[c==="saving"&&e.jsx("span",{className:"text-ink-secondary",children:t("settings.profile.saving")}),c==="saved"&&e.jsx("span",{className:"text-success",children:t("settings.profile.saved")}),c==="error"&&e.jsxs("span",{className:"text-danger",children:[t("settings.profile.saveError")," "," ",e.jsx("button",{type:"button",onClick:()=>{u()},className:"underline",children:t("settings.profile.retry")})]})]})]})}const hi=64,fi=8192,Ot=512;function sh(s){return Nd(s)?s.size>Sd?"settings.profile.avatar.tooLarge":null:"settings.profile.avatar.invalidType"}function nh(s,n){return s<hi||n<hi?"settings.profile.avatar.tooSmall":s>fi||n>fi?"settings.profile.avatar.tooLargeDimensions":null}async function Zr(s,n){const a=URL.createObjectURL(s);try{const i=await new Promise((r,c)=>{const l=new Image;l.onload=()=>r(l),l.onerror=()=>c(new Error("invalid-image")),l.src=a});if(i.naturalWidth<=0||i.naturalHeight<=0)throw new Error("invalid-image");return await n(i)}finally{URL.revokeObjectURL(a)}}function ah(s,n){return Zr(s,async a=>{const i=Math.min(a.naturalWidth,a.naturalHeight)/Math.max(1,n),r=document.createElement("canvas");r.width=Ot,r.height=Ot;const c=r.getContext("2d");if(!c)throw new Error("canvas-unavailable");c.drawImage(a,(a.naturalWidth-i)/2,(a.naturalHeight-i)/2,i,i,0,0,Ot,Ot);const l=await new Promise((d,u)=>r.toBlob(p=>p?d(p):u(new Error("image-encode-failed")),"image/webp",.9));return new File([l],"profile-photo.webp",{type:"image/webp"})})}function ih({initials:s}){const{state:n,dispatch:a}=_(),i=n.config?.profile?.avatarUrl??"",[r,c]=o.useState(!1),[l,d]=o.useState(null),[u,p]=o.useState(null),x=o.useRef(null),m=y=>{const v=x.current;v&&v.previewUrl!==y?.previewUrl&&URL.revokeObjectURL(v.previewUrl),x.current=y,p(y)};o.useEffect(()=>()=>{x.current&&URL.revokeObjectURL(x.current.previewUrl)},[]);const g=!!n.config?.team,f=async y=>{const v=g?await en({avatarUrl:y}):(await M("/api/config",{method:"PUT",body:JSON.stringify({profile:{avatarUrl:y}})})).profile;a({type:"profileSaved",profile:{avatarUrl:v?.avatarUrl}})},h=y=>{if(!y)return;d(null);const v=sh(y);if(v)return d(t(v));Zr(y,w=>({width:w.naturalWidth,height:w.naturalHeight})).then(({width:w,height:N})=>{const C=nh(w,N);if(C)return d(t(C));m({file:y,previewUrl:URL.createObjectURL(y),width:w,height:N,zoom:1})},()=>d(t("settings.profile.avatar.invalidType")))},j=y=>{c(!0),d(null),ah(y.file,y.zoom).then(v=>wd(v)).then(v=>{const w=v?ro(v.path):null;if(!w)throw new Error("avatar");return f(w)}).then(()=>m(null),()=>d(t("settings.profile.avatar.saveError"))).finally(()=>c(!1))},b=()=>{d(null),f("").catch(()=>d(t("settings.profile.avatar.saveError")))};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[u?e.jsx("div",{className:"flex w-full flex-col gap-2 rounded-lg border border-hairline/40 bg-inset p-2",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-16 shrink-0 overflow-hidden rounded-full bg-raised",children:e.jsx("img",{src:u.previewUrl,alt:"",className:"size-full object-cover",style:{transform:`scale(${u.zoom})`}})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[12px] font-medium text-ink",children:t("settings.profile.avatar.cropTitle")}),e.jsxs("div",{className:"text-[11px] text-ink-secondary",children:[u.width," × ",u.height,"px"]}),e.jsxs("label",{className:"mt-1 block text-[11px] text-ink-secondary",children:[t("settings.profile.avatar.zoom"),e.jsx("input",{"aria-label":t("settings.profile.avatar.zoom"),type:"range",min:"1",max:"2.5",step:"0.05",value:u.zoom,onChange:y=>m({...u,zoom:Number(y.target.value)}),className:"ml-2 w-28 align-middle accent-accent"})]})]}),e.jsx("button",{type:"button",className:"rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:bg-control",onClick:()=>m(null),children:t("settings.profile.avatar.cancel")}),e.jsx("button",{type:"button",className:"rounded-md bg-control px-2 py-1 text-[12px] text-ink hover:bg-raised-hover",disabled:r,onClick:()=>j(u),children:t("settings.profile.avatar.save")})]})}):i?e.jsx("img",{...Fn("person","picture"),src:i,alt:"",className:"size-10 rounded-full object-cover"}):e.jsx("span",{...Fn("person","initials"),"aria-hidden":"true",className:"flex size-10 shrink-0 items-center justify-center rounded-full bg-ink/[0.08] text-[14px] font-medium leading-[18px] text-ink-secondary",children:s}),e.jsxs("label",{className:"ui-button ui-button-md cursor-pointer rounded-full",children:[r?t("settings.profile.avatar.uploading"):t(i?"settings.profile.avatar.change":"settings.profile.avatar.choose"),e.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",className:"sr-only",disabled:r,onChange:y=>{const v=y.target.files?.[0];y.currentTarget.value="",h(v)}})]}),i&&!u&&e.jsx("button",{type:"button","data-danger":"",className:"settings-quiet cursor-pointer",onClick:b,children:t("settings.profile.avatar.remove")})]}),l&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:l})]})}function rh(){const{state:s,dispatch:n}=_(),[a,i]=o.useState(s.config?.profile?.name??""),[r,c]=o.useState(s.config?.profile?.email??"");o.useEffect(()=>{i(s.config?.profile?.name??""),c(s.config?.profile?.email??"")},[s.config?.profile?.name,s.config?.profile?.email]);const l=!!s.config?.team,d=()=>{if(l){en({name:a.trim()}).then(u=>n({type:"profileSaved",profile:{name:u.name,email:u.email}})).catch(()=>{});return}fetch("/api/config",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({profile:{name:a.trim(),email:r.trim().toLowerCase()}})}).then(u=>{if(!u.ok)throw new Error("Profile save failed");return u.json()}).then(u=>{u.profile&&n({type:"profileSaved",profile:{name:u.profile.name,email:u.profile.email}})}).catch(()=>{})};return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(ih,{initials:Ui({name:a,email:r})}),e.jsx(ge,{label:t("settings.profile.name"),children:e.jsx("input",{id:"profile-name","aria-label":t("settings.profile.name"),value:a,onChange:u=>i(u.target.value),onBlur:d,placeholder:t("settings.profile.name"),className:xe})}),e.jsx(ge,{label:t("phone.signIn.email"),children:e.jsx("input",{type:"email","aria-label":t("phone.signIn.email"),value:r,onChange:u=>c(u.target.value),onBlur:l?void 0:d,readOnly:l,placeholder:t("common.emailPlaceholder"),className:xe})}),e.jsx(Zg,{}),e.jsx(th,{})]})}function lh(){const{state:s,dispatch:n}=_(),a=s.config?.rooms.turnTimeoutMinutes??5,[i,r]=o.useState(String(a)),[c,l]=o.useState(!1),[d,u]=o.useState(""),[p,x]=o.useState(!1),m=o.useRef(!1);o.useEffect(()=>{c||r(String(a))},[a,c]);const g=async()=>{if(!c||m.current)return;const f=Ad(i);if(!f.ok){u(t("settings.roomTurns.range"));return}m.current=!0,x(!0);try{const h=await M("/api/config",{method:"PUT",body:JSON.stringify({rooms:{turnTimeoutMinutes:f.minutes}})});n({type:"configStatus",config:h}),r(String(h.rooms.turnTimeoutMinutes)),l(!1),u("")}catch(h){u(h instanceof Error?h.message:t("settings.roomTurns.error"))}finally{m.current=!1,x(!1)}};return e.jsx(L,{title:t("settings.limits.groupTurn"),subtitle:t("settings.limits.groupTurnLine"),message:d?e.jsx("span",{id:"room-turn-timeout-error",role:"alert",className:"text-danger",children:d}):void 0,children:e.jsxs("span",{className:"flex w-[160px] items-center gap-2 text-[13px] leading-5 text-ink-secondary",children:[e.jsx("input",{id:"room-turn-timeout",type:"number",min:Ed,max:Cd,step:1,inputMode:"numeric",value:i,disabled:p,"aria-label":t("settings.limits.groupTurn"),"aria-invalid":!!d,title:t("settings.roomTurns.help"),onChange:f=>{r(f.target.value),l(!0),u("")},onBlur:()=>{g()},onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()},className:D(Ue,"w-auto min-w-0 flex-1",d&&"border-danger/60")}),t("settings.roomTurns.minutes")]})})}function oh(){const{state:s,dispatch:n}=_(),a=Pd(s.config),[i,r]=o.useState(!1),[c,l]=o.useState("");if(!Td(s.config))return null;const d=async()=>{if(!i){r(!0),l("");try{const u=await M("/api/config",{method:"PATCH",body:JSON.stringify({features:{savedSteps:!a}})});n({type:"configStatus",config:u})}catch(u){l(u instanceof Error?u.message:t("settings.savedSteps.error"))}finally{r(!1)}}};return e.jsx(L,{title:t("settings.savedSteps.title"),subtitle:t("settings.savedSteps.subtitle"),children:e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx(ne,{checked:a,disabled:i,"aria-label":t("settings.savedSteps.aria"),onClick:d}),c&&e.jsx("span",{role:"alert",className:"text-[12px] text-danger",children:c})]})})}const Ns=async s=>{const n=await fetch(...gt(s)).catch(()=>null);return n?.ok?await n.json().catch(()=>null):null};function ch(s,n){return s==="ready"?{tone:"success",text:t("settings.ai.ready")}:s==="attention"?{tone:"warning",text:t("settings.ai.attention")}:s==="setup"?{tone:null,text:t("settings.desktops.needsSetup")}:s==="elsewhere"?{tone:null,text:t("settings.account.onPlace",{place:n})}:{tone:null,text:t("settings.ai.notSetUp")}}function dh({status:s,onCheck:n,onClose:a}){const[i,r]=o.useState(!1),c=[{title:t("settings.desktops.step1"),done:!!s?.runtime},{title:t("settings.desktops.step2"),done:!!s?.daemonUp},{title:t("settings.desktops.step3"),done:!!s?.image}];return e.jsxs(Nt,{title:t("settings.desktops.setupTitle"),onClose:a,footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"ui-button mr-auto",onClick:()=>r(l=>!l),children:t(i?"settings.desktops.hideDetails":"settings.desktops.details")}),e.jsx("button",{type:"button",className:"ui-button",onClick:a,children:t("common.close")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary",onClick:n,children:t("settings.desktops.checkAgain")})]}),children:[e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.desktops.stepsLine",{app:je()})}),e.jsx("ol",{className:"flex flex-col gap-2",children:c.map((l,d)=>e.jsxs("li",{"data-desktop-step":d+1,"data-done":l.done?"":void 0,className:"flex items-center gap-3 text-[14px] leading-5 text-ink",children:[e.jsx("span",{"aria-hidden":"true",className:"flex size-5 shrink-0 items-center justify-center rounded-full bg-ink/[0.06] text-[12px] font-medium leading-4 text-ink-secondary",children:l.done?"✓":d+1}),l.title]},l.title))}),i&&e.jsx("div",{"data-desktop-details":"",className:"max-h-[40vh] overflow-y-auto",children:e.jsx(Jr,{privateOnly:!0})})]})}function uh(){const{ctx:s,place:n,go:a}=we(),{state:i}=_(),r=i.config?.cloudHome===!0,[c,l]=o.useState(null),[d,u]=o.useState(null),[p,x]=o.useState(null),[m,g]=o.useState(!1),f=o.useCallback(()=>{r||Ns("status").then(l),Ns("cloud").then(u),Ns("vps").then(x)},[r]);o.useEffect(f,[f]);const h=Js(),b=Ct("desktops").find(I=>I.kind==="cloud"),y=!r&&h.paid&&!d?.configured,v=c?.ready?"ready":c?.runtime?"setup":"none",w=r||y?"elsewhere":d?.configured?d.available?"ready":"attention":"none",N=p?.configured?p.available?"ready":"attention":"none",C=(I,F,k,S,P,E)=>{const A=ch(I,y&&E==="cloud"?b?.name??t("cloudSetup.myCloud"):n.name);return I==="elsewhere"&&y&&E==="cloud"?e.jsx("div",{"data-desktop-kind":E,className:"contents",children:e.jsx(ye,{title:F,leading:e.jsx(Ls,{children:S}),subtitle:e.jsxs(e.Fragment,{children:[e.jsx(Je,{tone:A.tone}),A.text," · ",k]}),external:!0,onClick:()=>b?.open(),data:{"data-desktop-elsewhere":""}})}):e.jsx("div",{"data-desktop-kind":E,className:"contents",children:e.jsx(L,{title:F,leading:e.jsx(Ls,{children:S}),subtitle:e.jsxs(e.Fragment,{children:[e.jsx(Je,{tone:A.tone}),A.text," · ",k]}),children:I!=="elsewhere"&&e.jsx("button",{type:"button",className:"ui-button",onClick:P,children:t(I==="ready"?"settings.simple.ai.manage":"settings.simple.ai.setUp")})})})};return e.jsxs(J,{label:t("settings.desktops.kinds"),block:"desktops",children:[e.jsxs(V,{icons:!0,children:[C(w,t("settings.desktops.cloud"),t("settings.desktops.cloudLine"),e.jsx(Ti,{strokeWidth:1.75}),()=>a(s.plan&&!d?.configured?"plan":"ai",s.plan&&!d?.configured?void 0:"ai-keys"),"cloud"),!r&&C(v,t("settings.desktops.private"),t("settings.desktops.privateLine"),e.jsx(at,{strokeWidth:1.75}),()=>g(!0),"private"),(s.advanced||p?.configured)&&C(N,t("settings.desktops.servers"),t("settings.desktops.serversLine"),e.jsx(Ri,{strokeWidth:1.75}),()=>a("ai","ai-keys"),"servers")]}),m&&e.jsx(dh,{status:c,onCheck:f,onClose:()=>g(!1)})]})}function ph(s,n,a){const i=n.trim().toLowerCase();return s.filter(r=>a&&!r.tags.includes(a)?!1:i?[r.name,r.description,r.source].some(c=>c.toLowerCase().includes(i)):!0)}function el({skill:s}){return e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-ink-secondary",children:[e.jsx("span",{className:"truncate",title:s.source,children:t("skills.source",{source:s.source})}),e.jsx("span",{children:s.version?t("skills.library.version",{version:s.version}):t("skills.library.noVersion")}),e.jsx("span",{children:t("skills.library.importedAt",{date:new Date(s.importedAt).toLocaleDateString(Gs())})}),s.tags.map(n=>e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 font-mono",children:n},n))]})}function mh(){const{state:s}=_(),[n,a]=o.useState([]),[i,r]=o.useState(!0),[c,l]=o.useState(""),[d,u]=o.useState(""),[p,x]=o.useState(null),[m,g]=o.useState(null),[f,h]=o.useState(""),[j,b]=o.useState(""),[y,v]=o.useState(!1),[w,N]=o.useState(""),[C,I]=o.useState(""),F=o.useRef(!1),k=s.bots.filter(B=>!B.hidden),S=o.useMemo(()=>[...new Set(n.flatMap(B=>B.tags))].sort((B,W)=>B.localeCompare(W)),[n]),P=ph(n,d,p),E=async B=>{try{const W=await fetch("/api/skills-library"),G=await W.json();if(!W.ok)throw new Error(G.error??t("skills.library.loadError"));if(B?.())return;a(G.skills??[]),l("")}catch(W){B?.()||l(W instanceof Error?W.message:t("skills.library.loadError"))}finally{B?.()||r(!1)}};o.useEffect(()=>{let B=!1;return r(!0),E(()=>B),()=>{B=!0}},[]);const A=async(B,W,G)=>{if(F.current)return;F.current=!0;const le=`${W}:${B}`;h(le),l("");try{const U=await fetch("/api/skills-library"),H=await U.json();if(!U.ok)throw new Error(H.error??t("skills.library.loadError"));const Q=(H.skills??[]).filter(de=>de.assignedBots.some(be=>be.id===B)).map(de=>de.name),te=G?Q.filter(de=>de!==W):[...new Set([...Q,W])],ie=await fetch(`/api/bots/${encodeURIComponent(B)}/skills-library`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({skills:te})}),Se=await ie.json();if(!ie.ok)throw new Error(Se.error??t("skills.error.assignments"));await E()}catch(U){l(U instanceof Error?U.message:t("skills.error.assignments"))}finally{F.current=!1,h("")}},q=async B=>{C&&await A(C,B.name,!1)},R=async(B,W)=>{await A(W,B.name,!0)},K=async(B,W=!1)=>{if(!F.current){if(!B.enabled&&!W)return oe(B,!0);F.current=!0,h(B.name),l("");try{const G=await fetch(`/api/skills-library/${encodeURIComponent(B.name)}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({enabled:!B.enabled})}),le=await G.json();if(!G.ok)throw new Error(le.error??t("skills.error.update"));W&&g(null),await E()}catch(G){l(G instanceof Error?G.message:t("skills.error.update"))}finally{F.current=!1,h("")}}},Z=async B=>{if(!F.current){F.current=!0,h(B.name),l("");try{const W=await fetch(`/api/skills-library/${encodeURIComponent(B.name)}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({everyBot:!B.everyBot})}),G=await W.json();if(!W.ok)throw new Error(G.error??"Could not update this skill.");await E()}catch(W){l(W instanceof Error?W.message:"Could not update this skill.")}finally{F.current=!1,h("")}}},oe=async(B,W=!1)=>{l("");try{const G=await fetch(`/api/skills-library/${encodeURIComponent(B.name)}`),le=await G.json();if(!G.ok)throw new Error(le.error??t("skills.error.load"));if(!le.text)throw new Error(t("skills.error.contentsImport"));g({skill:B,text:le.text,review:W})}catch(G){l(G instanceof Error?G.message:t("skills.error.load"))}},se=async()=>{const B=j.trim();if(B){v(!0),l(""),N("");try{const W=await fetch("/api/skills-library",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({text:B})}),G=await W.json();if(!W.ok)throw new Error(G.error??t("skills.error.import"));N(t("skills.library.imported",{name:G.skill?.name??""})),b(""),await E()}catch(W){l(W instanceof Error?W.message:t("skills.error.import"))}finally{v(!1)}}},Y="w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink placeholder:text-ink-secondary focus:outline-none";return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(pe,{title:t("skills.library.title"),subtitle:t("skills.library.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Jt,{size:15,className:"shrink-0 text-ink-secondary"}),e.jsx("input",{className:Y,placeholder:t("skills.library.searchPlaceholder"),"aria-label":t("skills.library.searchPlaceholder"),value:d,onChange:B=>u(B.target.value)})]}),S.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>x(null),className:p===null?"rounded-full bg-control px-2.5 py-1 text-[12px] font-medium text-ink":"rounded-full px-2.5 py-1 text-[12px] text-ink-secondary hover:bg-control/50 hover:text-ink",children:t("skills.library.allTags")}),S.map(B=>e.jsx("button",{type:"button",onClick:()=>x(p===B?null:B),className:p===B?"rounded-full bg-control px-2.5 py-1 font-mono text-[12px] font-medium text-ink":"rounded-full px-2.5 py-1 font-mono text-[12px] text-ink-secondary hover:bg-control/50 hover:text-ink",children:B},B))]}),i?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("skills.library.loading")}):P.length===0?e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[12px] text-ink-secondary",children:n.length===0?t("skills.library.empty"):t("skills.library.noMatches")}):e.jsx("div",{className:"divide-y divide-hairline/40 overflow-hidden rounded-lg border border-hairline/40",children:P.map(B=>e.jsxs("div",{className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{oe(B)},className:"min-w-0 flex-1 text-left","aria-label":t("skills.library.view",{skill:B.name}),children:[e.jsx("div",{className:"truncate font-mono text-[13px] text-ink",children:B.name}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[12px] text-ink-secondary",children:B.description})]}),e.jsx(ne,{checked:B.enabled,"aria-label":B.enabled?t("skills.library.disable",{skill:B.name}):t("skills.library.enable",{skill:B.name}),disabled:!!(f||y),onClick:()=>{K(B)}})]}),e.jsx(el,{skill:B}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-3 rounded-lg bg-inset px-2.5 py-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[12px] font-medium text-ink",children:t("skills.library.everyBot")}),e.jsx("div",{className:"text-[11px] text-ink-secondary",children:t("skills.library.everyBotHint")})]}),e.jsx(ne,{checked:B.everyBot,"aria-label":t("skills.library.everyBot"),disabled:!!(f||y),onClick:()=>{Z(B)}})]}),B.warnings.length>0&&e.jsx("div",{className:"mt-1 text-[11px] text-warning",children:B.warnings.join(" · ")}),e.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5 text-[11px] text-ink-secondary",children:B.assignedBots.length===0?e.jsx("span",{children:t("skills.library.notAssigned")}):B.assignedBots.map(W=>e.jsxs("span",{className:"flex items-center gap-1 rounded-full bg-control px-2 py-0.5",children:[e.jsx("span",{className:"max-w-40 truncate",children:W.name}),e.jsx("button",{type:"button","aria-label":t("skills.library.removeAssignment",{bot:W.name}),title:t("skills.library.removeAssignment",{bot:W.name}),disabled:!!(f||y),onClick:()=>{R(B,W.id)},className:"flex size-4 items-center justify-center rounded-full text-ink-secondary hover:bg-danger/10 hover:text-danger disabled:opacity-40",children:e.jsx(Me,{size:11})})]},W.id))}),k.length>0&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.jsxs(ce,{size:"sm","aria-label":t("skills.library.assignLabel"),value:C,disabled:!!(f||y),onChange:W=>I(W.target.value),className:"max-w-45",children:[e.jsx("option",{value:"",children:t("skills.library.assignPickBot")}),k.map(W=>e.jsx("option",{value:W.id,children:W.name},W.id))]}),e.jsx("button",{type:"button",disabled:!C||!!(f||y),onClick:()=>{q(B)},className:"rounded-lg bg-control px-2.5 py-1 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:t("skills.library.assign")})]})]},B.name))}),c&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] text-danger",children:c})]})}),e.jsx(pe,{title:t("skills.library.importTitle"),subtitle:t("skills.library.importHint"),children:e.jsxs("form",{className:"flex flex-col gap-2",onSubmit:B=>{B.preventDefault(),se()},children:[e.jsx("textarea",{className:`${Y} min-h-32 font-mono text-[12px]`,placeholder:t("skills.library.importPlaceholder"),"aria-label":t("skills.library.importTitle"),value:j,onChange:B=>b(B.target.value)}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[w?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:w}):e.jsx("span",{}),e.jsx("button",{type:"submit",disabled:y||!!f||!j.trim(),className:"shrink-0 rounded-lg bg-control px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",children:y?t("skills.library.importing"):t("skills.library.importButton")})]})]})}),m&&e.jsx(Bi,{modal:!0,children:e.jsx(xh,{viewing:m,error:c,working:!!f,onClose:()=>{f||g(null)},onEnable:()=>{K(m.skill,!0)}})})]})}function xh({viewing:s,error:n,working:a,onClose:i,onEnable:r}){const c=o.useRef(null);return lo(c,i),e.jsx("div",{ref:c,tabIndex:-1,role:"dialog","aria-modal":"true","aria-labelledby":"skills-library-view-title",className:"fixed inset-0 z-[90] flex items-center justify-center bg-black/45 p-6",children:e.jsxs("div",{className:"flex max-h-[min(760px,90vh)] w-full max-w-2xl flex-col rounded-2xl bg-card p-5 shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{id:"skills-library-view-title",className:"text-[16px] font-semibold text-ink",children:s.review?t("skills.reviewTitle",{name:s.skill.name}):s.skill.name}),e.jsx("button",{type:"button",disabled:a,onClick:i,className:"rounded-md px-2 py-1 text-[13px] text-ink-secondary hover:bg-control hover:text-ink",children:t("skills.library.close")})]}),s.review&&e.jsx(el,{skill:s.skill}),s.skill.warnings.length>0&&e.jsx("div",{className:"mt-2 text-[12px] text-warning",children:s.skill.warnings.join(" · ")}),e.jsx("pre",{tabIndex:0,"aria-label":`${t("skills.library.view",{skill:s.skill.name})}`,className:"mt-3 min-h-0 flex-1 overflow-auto whitespace-pre-wrap break-words rounded-xl bg-inset p-3 font-mono text-[12px] leading-relaxed text-ink",children:s.text}),n&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] text-danger",children:n}),s.review&&e.jsx("button",{type:"button",disabled:a,onClick:r,className:"mt-4 self-end rounded-lg bg-accent px-4 py-2 text-[13px] font-semibold text-white disabled:opacity-40",children:t("skills.enableReviewed")})]})})}function gh(){const{state:s,dispatch:n}=_(),a=s.config?.threads?.maxConcurrentPerBot??3,i=s.config?.cloudStarter===!0,[r,c]=o.useState(null),[l,d]=o.useState(""),u=o.useRef(!1),p=async x=>{if(!(u.current||x===a)){u.current=!0,c(x),d("");try{const m=await M("/api/config",{method:"PATCH",body:JSON.stringify({threads:{maxConcurrentPerBot:x}})});n({type:"configStatus",config:m})}catch(m){d(m instanceof Error?m.message:t("settings.threads.error"))}finally{u.current=!1,c(null)}}};return e.jsx("div",{"data-settings-block":"parallel",className:"contents",children:e.jsx(L,{title:t("settings.threads.title"),subtitle:i?t("settings.threads.starterShort"):t("settings.threads.short"),message:r!==null?e.jsx("span",{role:"status",children:t("settings.threads.saving")}):l?e.jsx("span",{role:"alert",className:"text-danger",children:l}):void 0,children:e.jsx(ce,{id:"thread-concurrency","aria-label":t("settings.threads.label"),title:t("settings.threads.helpHanded"),value:r??a,disabled:r!==null||i,onChange:x=>{p(Number(x.target.value))},children:Array.from({length:16},(x,m)=>m+1).map(x=>e.jsx("option",{value:x,children:x},x))})})})}function tl(){const{state:s,dispatch:n}=_(),[a,i]=o.useState(!1),[r,c]=o.useState(null),l=s.config?.tts?.everyReply===!0,d=o.useContext(Ae),u=()=>{i(!0),c(null),M("/api/config",{method:"PUT",body:JSON.stringify({tts:{everyReply:!l}})}).then(p=>n({type:"configStatus",config:p})).catch(p=>c(p.message)).finally(()=>i(!1))};return d?e.jsx("div",{"data-voice-every-reply":!0,className:"contents",children:e.jsx(L,{title:t("voice.everyReply"),subtitle:t("voice.everyReply.allHelp"),leading:e.jsx("span",{"aria-hidden":"true"}),message:r?e.jsx("span",{role:"alert",className:"text-danger",children:r}):void 0,children:e.jsx(ne,{checked:l,disabled:a,"aria-label":t("voice.everyReply"),onClick:u})})}):e.jsxs("div",{"data-voice-every-reply":!0,className:"flex items-center justify-between gap-4 px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[14px] font-medium leading-5 text-ink",children:t("voice.everyReply")}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-4 text-ink-secondary",children:t("voice.everyReply.allHelp")}),r&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:r})]}),e.jsx(ne,{checked:l,disabled:a,"aria-label":t("voice.everyReply"),onClick:u})]})}function Ss(s){return[...new Set(s.split(/[,,、\s]+/).map(n=>n.trim()).filter(Boolean))]}const Fe=D(qe,"font-sans"),hh=[5,10,20,30,60],bi="flex flex-col gap-1 text-[12px] leading-4 text-ink-secondary",Cs="ui-icon-button shrink-0 hover:text-ink",Es={name:"Google Gemini",url:"https://generativelanguage.googleapis.com/v1beta/openai"},_s={count:64,length:200},fh=s=>s.length<=_s.count&&s.every(n=>n.length<=_s.length),Hs=(s,n)=>M(`/api/instances/${encodeURIComponent(s)}`,{method:"PATCH",body:JSON.stringify(n)});function bh(s,n){try{return!s||new URL(n.trim()).origin!==new URL(s).origin}catch{return!1}}function sl({server:s,disabled:n,onPick:a}){return e.jsxs(ce,{size:"sm",className:"shrink-0",value:s.replyWaitMinutes??"",onChange:i=>a(i.target.value?Number(i.target.value):null),disabled:n,"aria-label":t("apiInstances.replyWaitFor",{name:s.displayName}),title:t("apiInstances.replyWaitHint"),children:[e.jsx("option",{value:"",children:t("apiInstances.replyWaitDefault")}),[...new Set([...hh,...s.replyWaitMinutes?[s.replyWaitMinutes]:[]])].sort((i,r)=>i-r).map(i=>e.jsx("option",{value:i,children:t("apiInstances.replyWaitMinutes",{minutes:String(i)})},i))]})}function vh(){const{state:s,dispatch:n,refreshInstances:a}=_(),[i,r]=o.useState(!1),[c,l]=o.useState(null),d=s.instances.find(p=>p.instanceId==="openaiCompat"&&p.driverKind==="openai-compat");if(!d||!s.config?.openaiCompat?.url)return null;const u=p=>{i||(r(!0),l(null),Hs(d.instanceId,{replyWaitMinutes:p}).then(async({instances:x})=>{Array.isArray(x)?n({type:"instances",instances:x}):await a({reportErrors:!0})}).catch(x=>l(x.message||t("apiInstances.failed"))).finally(()=>r(!1)))};return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(sl,{server:d,disabled:i,onPick:u}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.replyWaitHint")}),c&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:c})]})}function yh(){const{state:s}=_();return e.jsx(jh,{servers:tn(s.instances)})}function jh({servers:s}){const{dispatch:n,refreshInstances:a}=_(),[i,r]=o.useState(""),[c,l]=o.useState(""),[d,u]=o.useState(""),[p,x]=o.useState(""),[m,g]=o.useState(null),[f,h]=o.useState(null),[j,b]=o.useState(null),[y,v]=o.useState(""),[w,N]=o.useState(""),[C,I]=o.useState(""),[F,k]=o.useState(null),S=!!(i.trim()&&c.trim()&&d.trim()),P=(A,q,R,K)=>{m||(g(A),h(null),k(null),q().then(async({instances:Z,warning:oe})=>{Array.isArray(Z)?n({type:"instances",instances:Z}):await a({reportErrors:!0}),R?.(!!oe)}).catch(Z=>h({text:Z.message||t("apiInstances.failed"),at:K})).finally(()=>g(null)))},E=()=>S&&P("add",()=>M("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:i.trim(),url:c.trim(),key:d.trim(),...Ss(p).length?{models:Ss(p)}:{}})}).then(A=>(ot("custom_endpoint","settings","unverified"),A),A=>{throw ot("custom_endpoint","settings","error"),A}),()=>{r(""),l(""),u(""),x("")});return e.jsxs("div",{"data-api-keys-other":!0,children:[e.jsx("div",{className:"mb-0.5 text-[13px] font-medium leading-[18px] text-ink",children:t("apiInstances.title")}),e.jsx("p",{className:"mb-2 text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.subtitle")}),s.length===0&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.empty")}),s.map(A=>{const q=w.trim().replace(/\/+$/,""),R=q!==(A.url??""),K=R&&!C.trim()&&!A.placeholderKey&&bh(A.url,q);return e.jsxs("div",{className:"py-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] leading-5 text-ink",children:A.displayName}),A.url&&e.jsx("div",{className:"truncate text-[12px] leading-4 text-ink-secondary",children:A.url})]}),e.jsx(sl,{server:A,disabled:m!==null,onPick:Z=>P("other",()=>Hs(A.instanceId,{replyWaitMinutes:Z}))}),e.jsx("button",{type:"button",onClick:()=>{v((A.managedModels??[]).join(", ")),N(A.url??""),I(""),b(j===A.instanceId?null:A.instanceId),h(null),k(null)},disabled:m!==null,"aria-label":t("apiInstances.editServer",{name:A.displayName}),"aria-expanded":j===A.instanceId,title:t("apiInstances.editServer",{name:A.displayName}),className:Cs,children:e.jsx(Id,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>P("other",()=>M(`/api/instances/${encodeURIComponent(A.instanceId)}/refresh-models`,{method:"POST"})),disabled:m!==null,"aria-label":t("apiInstances.refreshModels",{name:A.displayName}),title:t("apiInstances.refreshModels",{name:A.displayName}),className:Cs,children:e.jsx(Ld,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>P("other",()=>M(`/api/instances/${encodeURIComponent(A.instanceId)}`,{method:"DELETE"})),disabled:m!==null,"aria-label":t("apiInstances.remove",{name:A.displayName}),title:t("apiInstances.remove",{name:A.displayName}),className:`${Cs} hover:bg-danger/10 hover:text-danger`,children:e.jsx(We,{size:13,"aria-hidden":"true"})})]}),j===A.instanceId&&e.jsxs("div",{className:"mt-1.5 flex flex-col gap-1.5",children:[e.jsxs("label",{className:bi,children:[t("apiInstances.url"),e.jsx("input",{type:"url",value:w,onChange:Z=>N(Z.target.value),placeholder:"https://api.example.com/v1","aria-label":t("apiInstances.urlFor",{name:A.displayName}),spellCheck:!1,disabled:m!==null,className:Fe})]}),e.jsxs("label",{className:bi,children:[t("apiInstances.key"),e.jsx("input",{type:"password",value:C,onChange:Z=>I(Z.target.value),placeholder:t("apiInstances.keepKey"),"aria-label":t("apiInstances.keyFor",{name:A.displayName}),autoComplete:"off",disabled:m!==null,className:Fe})]}),K&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.newHostKey")}),e.jsx("input",{value:y,onChange:Z=>v(Z.target.value),placeholder:t("apiInstances.models"),"aria-label":t("apiInstances.modelsFor",{name:A.displayName}),spellCheck:!1,disabled:m!==null,className:Fe}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.editModelsHint")}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{const Z=Ss(y);if(!fh(Z)){h({text:t("apiInstances.modelsLimit",_s),at:A.instanceId});return}const oe={models:Z,...R?{url:q}:{},...C.trim()?{apiKey:C.trim()}:{}};P("other",()=>Hs(A.instanceId,oe),se=>{I(""),se?k(A.instanceId):b(null)},A.instanceId)},disabled:m!==null||K,className:"ui-button",children:t("common.save")}),e.jsx("button",{type:"button",onClick:()=>{b(null),I("")},disabled:m!==null,className:"ui-button",children:t("common.cancel")})]}),f?.at===A.instanceId&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:f.text}),F===A.instanceId&&e.jsx("p",{role:"status",className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.modelsUnreadable")})]})]},A.instanceId)}),e.jsxs("div",{className:"mt-2 flex flex-col gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{r(Es.name),l(Es.url)},disabled:m!==null,className:"ui-button self-end",children:t("apiInstances.geminiPreset")}),c.trim()===Es.url&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.geminiKeyHint")}),e.jsx("input",{value:i,onChange:A=>r(A.target.value),placeholder:t("apiInstances.name"),"aria-label":t("apiInstances.name"),spellCheck:!1,disabled:m!==null,className:Fe}),e.jsx("input",{type:"url",value:c,onChange:A=>l(A.target.value),placeholder:"https://api.example.com/v1","aria-label":t("apiInstances.url"),spellCheck:!1,disabled:m!==null,className:Fe}),e.jsx("input",{type:"password",value:d,onChange:A=>u(A.target.value),placeholder:t("apiInstances.key"),"aria-label":t("apiInstances.key"),autoComplete:"off",disabled:m!==null,className:Fe}),e.jsx("input",{value:p,onChange:A=>x(A.target.value),placeholder:t("apiInstances.models"),"aria-label":t("apiInstances.models"),spellCheck:!1,disabled:m!==null,className:Fe}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.modelsHint")}),e.jsx("button",{type:"button",onClick:E,disabled:m!==null||!S,className:"ui-button self-end",children:m==="add"?t("apiInstances.adding"):t("apiInstances.add")})]}),f&&!f.at&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:f.text})]})}const kh="lm-studio";function wh(s){const n=s.trim();if(!/^[1-9]\d{0,4}$/.test(n))return null;const a=Number(n);return a>65535?null:`http://127.0.0.1:${a}/v1`}function Nh({heading:s=!0}={}){const{state:n,dispatch:a,refreshInstances:i}=_(),r=tn(n.instances),[c,l]=o.useState("1234"),[d,u]=o.useState(""),[p,x]=o.useState(!1),[m,g]=o.useState(null),f=wh(c),h=!!(f&&r.some(b=>b.url===f)),j=()=>{p||!f||h||(x(!0),g(null),M("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:"LM Studio",url:f,key:d.trim()||kh,catalog:"lmstudio"})}).then(async b=>{ot("custom_endpoint","settings","unverified"),Array.isArray(b.instances)?a({type:"instances",instances:b.instances}):await i({reportErrors:!0}),u("")},b=>{ot("custom_endpoint","settings","error"),g(b instanceof Error&&b.message?b.message:t("apiInstances.failed"))}).finally(()=>x(!1)))};return e.jsxs("div",{children:[s&&e.jsx("div",{className:"text-[13px] text-ink",children:t("lmStudio.title")}),e.jsx("p",{className:D("text-[12px] leading-4 text-ink-secondary",s&&"mt-1"),children:t("lmStudio.desc")}),e.jsxs("div",{className:"mt-2 flex flex-col gap-1.5",children:[e.jsxs("label",{className:"flex flex-col gap-1.5 text-[13px] font-medium leading-[18px] text-ink",children:[t("lmStudio.port"),e.jsx("input",{inputMode:"numeric",value:c,onChange:b=>l(b.target.value),"aria-label":t("lmStudio.port"),spellCheck:!1,disabled:p,className:Fe})]}),e.jsx("input",{type:"password",value:d,onChange:b=>u(b.target.value),placeholder:t("lmStudio.token"),"aria-label":t("lmStudio.token"),autoComplete:"off",disabled:p,className:Fe}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("lmStudio.tokenHint")}),f&&e.jsx("p",{className:"truncate text-[12px] leading-4 text-ink-secondary",children:f}),e.jsx("button",{type:"button",onClick:j,disabled:p||!f||h,className:"ui-button self-end",children:p?t("lmStudio.adding"):t("lmStudio.add")}),h&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("lmStudio.added")})]}),m&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:m})]})}const Sh="ollama",Ch="https://ollama.com/download",Eh=s=>`${s.replace(/\/+$/,"")}/v1`,Ah=(s,n)=>s?.trim().replace(/\/+$/,"")===n;function Ph({visible:s}){const{state:n,dispatch:a,refreshInstances:i}=_(),[r,c]=o.useState(""),[l,d]=o.useState(null),[u,p]=o.useState(!1),[x,m]=o.useState(!1),[g,f]=o.useState(null),h=o.useRef(0),j=o.useRef(!1),b=o.useCallback(C=>{const I=++h.current;p(!0),f(null),M(`/api/instances/ollama${C?`?url=${encodeURIComponent(C)}`:""}`).then(F=>{I===h.current&&d(F.status)}).catch(F=>{I===h.current&&(d(null),f(F.message||t("apiInstances.failed")))}).finally(()=>{I===h.current&&p(!1)})},[]);o.useEffect(()=>{!s||j.current||(j.current=!0,b(""))},[s,b]);const y=l?Eh(l.url):null,v=!!(y&&(tn(n.instances).some(C=>C.url===y)||Ah(n.config?.openaiCompat?.url,y))),w=!!(y&&!v&&!x&&!u&&(l?.state==="ready"||l?.state==="no-models")),N=()=>{!w||!y||(m(!0),f(null),M("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:"Ollama",url:y,key:Sh,catalog:"ollama"})}).then(async C=>{ot("custom_endpoint","settings","unverified"),Array.isArray(C.instances)?a({type:"instances",instances:C.instances}):await i({reportErrors:!0})},C=>{ot("custom_endpoint","settings","error"),f(C instanceof Error&&C.message?C.message:t("apiInstances.failed"))}).finally(()=>m(!1)))};return e.jsxs("div",{"data-ollama-server":!0,children:[e.jsx("div",{role:"status","aria-live":"polite",children:u?e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] leading-4 text-ink-secondary",children:[e.jsx(re,{size:12,className:"animate-spin","aria-hidden":"true"}),t("ollama.checking")]}):l&&e.jsx(Rd,{status:l})}),!u&&l?.state==="not-running"&&e.jsx("a",{href:Ch,target:"_blank",rel:"noopener noreferrer",className:"mt-1 inline-block text-[12px] font-medium text-accent-text hover:underline",children:t("ollama.download")}),e.jsxs("div",{className:"mt-2 flex flex-col gap-1.5",children:[e.jsx("input",{type:"url",value:r,onChange:C=>c(C.target.value),onKeyDown:C=>{C.key==="Enter"&&b(r.trim())},placeholder:"http://127.0.0.1:11434","aria-label":t("ollama.address"),spellCheck:!1,disabled:x,className:qe}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("ollama.addressHint")}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:N,disabled:!w,className:"ui-button",children:x?t("ollama.adding"):t("ollama.add")}),e.jsx("button",{type:"button",onClick:()=>b(r.trim()),disabled:u||x,className:"settings-quiet cursor-pointer",children:t("common.checkAgain")})]}),v&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("ollama.added")})]}),g&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:g})]})}function Th(){const{state:s,dispatch:n}=_(),a=s.config?.opencodeGo?.providerKeys??[],[i,r]=o.useState(""),[c,l]=o.useState(""),[d,u]=o.useState(!1),[p,x]=o.useState(null),[m,g]=o.useState(null),f=d||p!==null,h=(y,v)=>M("/api/config",{method:"PUT",body:JSON.stringify({opencodeGo:{providerKeys:{[y]:v}}})}).then(w=>n({type:"configStatus",config:w})),j=()=>{const y=i.trim().toUpperCase(),v=Bd(c);if(!(f||!y||!v)){if(!Od(v)){g(t("keys.notAKey"));return}u(!0),g(null),h(y,v).then(()=>{r(""),l("")}).catch(w=>g(w.message)).finally(()=>u(!1))}},b=y=>{f||(x(y),g(null),h(y,"").catch(v=>g(v.message)).finally(()=>x(null)))};return e.jsxs("div",{"data-opencode-provider-keys":!0,className:"flex flex-col gap-2",children:[e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("keys.opencode.otherProviders.hint")}),s.config?.cloudHome!==!0&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("keys.opencode.providersHint").split("{command}").flatMap((y,v)=>v===0?[y]:[e.jsx("code",{className:"font-mono",children:"opencode auth login"},v),y])}),a.map(y=>e.jsxs("div",{"data-opencode-provider-key":y,className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:D(qe,"block flex-1 truncate text-ink"),children:y}),e.jsx("button",{type:"button",onClick:()=>b(y),disabled:f,"aria-label":t("keys.opencode.otherProviders.removeAria",{name:y}),className:"ui-button shrink-0",children:p===y?e.jsx(re,{size:13,className:"animate-spin","aria-hidden":"true"}):t("keys.row.remove")})]},y)),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{type:"text",value:i,onChange:y=>{g(null),r(y.target.value)},onKeyDown:y=>y.key==="Enter"&&j(),disabled:f,placeholder:"VENICE_API_KEY","aria-label":t("keys.opencode.otherProviders.name"),autoComplete:"off",spellCheck:!1,className:D(qe,"w-auto min-w-[min(100%,10rem)] flex-1 uppercase placeholder:normal-case")}),e.jsx("input",{type:"password",value:c,onChange:y=>{g(null),l(y.target.value)},onKeyDown:y=>y.key==="Enter"&&j(),disabled:f,placeholder:t("keys.opencode.otherProviders.keyPlaceholder"),"aria-label":t("keys.opencode.otherProviders.key"),autoComplete:"off",className:D(qe,"w-auto min-w-[min(100%,10rem)] flex-1")}),e.jsx("button",{type:"button",onClick:j,disabled:f||!i.trim()||!c.trim(),className:"ui-button shrink-0",children:d?e.jsx(re,{size:13,className:"animate-spin","aria-hidden":"true"}):t("common.save")})]}),m&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:m})]})}function Ih(){const{state:s,dispatch:n}=_(),[a,i]=o.useState(!1),[r,c]=o.useState(null);if(!s.config?.anthropic?.configured)return null;const l=s.config.anthropic.everyClaudeBot===!0,d=()=>{a||(i(!0),c(null),M("/api/config",{method:"PUT",body:JSON.stringify({anthropic:{everyClaudeBot:!l}})}).then(u=>n({type:"configStatus",config:u})).catch(u=>c(u.message)).finally(()=>i(!1)))};return e.jsxs("div",{"data-anthropic-every-claude-bot":!0,className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[13px] leading-[18px] text-ink",children:t("keys.anthropic.everyBot")}),e.jsx("div",{className:"text-[12px] leading-4 text-ink-secondary",children:l?t("keys.anthropic.everyBotOn"):t("keys.anthropic.everyBotOff")})]}),e.jsx(ne,{checked:l,disabled:a,onClick:d,"aria-label":t("keys.anthropic.everyBot")})]}),l&&e.jsxs("p",{className:"flex gap-1.5 text-[12px] leading-4 text-warning",children:[e.jsx(He,{size:13,className:"mt-px shrink-0","aria-hidden":"true"}),e.jsx("span",{children:t("keys.anthropic.warning")})]}),r&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:r})]})}function Lh(){const{state:s,dispatch:n}=_(),[a,i]=o.useState(""),[r,c]=o.useState(!1),[l,d]=o.useState(null),u=!!s.config?.vps?.configured,p=!a.trim()&&u;o.useEffect(()=>{i(s.config?.vps?.sshAlias??"")},[s.config?.vps?.sshAlias]);const x=()=>{r||!a.trim()&&!u||(c(!0),d(null),M("/api/config",{method:"PUT",body:JSON.stringify({vps:{sshAlias:a.trim()}})}).then(m=>{n({type:"configStatus",config:m}),i(m.vps?.sshAlias??"")}).catch(m=>d(m.message)).finally(()=>c(!1)))};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("p",{className:"text-[12px] leading-4 text-ink-secondary",children:[t("keys.vps.descBefore"),e.jsx("a",{href:"https://github.com/seira-bot/seira/blob/main/docs/byo-vps.md",target:"_blank",rel:"noopener noreferrer",className:"text-accent-text hover:underline",children:t("keys.vps.descLink")}),t("keys.vps.descAfter")]}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("keys.vps.anyMachine")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{type:"text","data-key-input":!0,value:a,onChange:m=>i(m.target.value),onKeyDown:m=>m.key==="Enter"&&x(),placeholder:"my-vps","aria-label":t("keys.vps.aria"),autoComplete:"off",spellCheck:!1,className:D(qe,"w-auto min-w-[min(100%,12rem)] flex-1")}),e.jsx("button",{type:"button",onClick:x,disabled:r||!a.trim()&&!u||a.trim()===(s.config?.vps?.sshAlias??""),className:D("ui-button shrink-0",!p&&"ui-button-primary"),title:p?t("keys.vps.removeAlias"):void 0,children:r?e.jsx(re,{size:13,className:"animate-spin","aria-hidden":"true"}):p?t("keys.row.remove"):t("common.save")})]}),l&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:l})]})}function Rh(){const{state:s,dispatch:n}=_(),a=s.config?.openaiCompat?.url??"",[i,r]=o.useState(a),[c,l]=o.useState(!1),[d,u]=o.useState(null),p=o.useRef(!1);o.useEffect(()=>{r(a)},[a]);const x=i.trim()!==a,m=()=>{p.current||!x||(p.current=!0,l(!0),u(null),M("/api/config",{method:"PUT",body:JSON.stringify({openaiCompat:{url:i.trim()}})}).then(g=>n({type:"configStatus",config:g})).catch(g=>u(g.message)).finally(()=>{p.current=!1,l(!1)}))};return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("div",{className:"text-[13px] leading-[18px] text-ink",children:t("keys.openaiCompat.url")}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"url",value:i,onChange:g=>r(g.target.value),onBlur:m,onKeyDown:g=>g.key==="Enter"&&m(),placeholder:"https://api.groq.com/openai/v1","aria-label":t("keys.openaiCompat.url"),spellCheck:!1,className:D(qe,"pr-8")}),c&&e.jsx(re,{size:13,"aria-hidden":"true",className:"absolute right-2.5 top-1/2 -translate-y-1/2 animate-spin text-ink-secondary"})]}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("keys.openaiCompat.urlHint")}),d&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:d})]})}const Bh="rounded-xl bg-card in-data-[settings-look=simple]:rounded-[12px] in-data-[settings-look=simple]:border-[0.5px] in-data-[settings-look=simple]:border-(--settings-edge) in-data-[settings-look=simple]:bg-menu",Oh=1600,Fh={opencodeProviders:()=>e.jsx(Th,{}),ollama:s=>e.jsx(Ph,{visible:s}),lmStudio:()=>e.jsx(Nh,{heading:!1}),vps:()=>e.jsx(Lh,{})},Uh={anthropic:()=>e.jsx(Ih,{}),openaiCompat:()=>e.jsxs(e.Fragment,{children:[e.jsx(Rh,{}),e.jsx(vh,{}),e.jsx(yh,{})]}),liveKey:()=>e.jsx(Dd,{})};function $s(s,n){if(s.kind==="uses")return!1;const a=sn(s,n);return a.configured||a.included===!0}function Mh({entry:s,visible:n}){const{state:a}=_(),i=o.useId(),c=sn(s,a.config).configured?{tone:"ok",text:t("keys.connected")}:null;return e.jsxs("div",{"data-key-row":s.id,role:"group","aria-labelledby":i,className:ar,children:[e.jsx(ir,{entry:s,status:c,titleId:i}),e.jsx("div",{className:D("flex flex-col gap-2",rr),children:Fh[s.id]?.(n)})]})}function Dh({entry:s}){const{state:n,dispatch:a}=_(),i=o.useId(),r=s.opens,c=sn(s,n.config),l=c.configured?{tone:"ok",text:t("keys.connected")}:null;return e.jsxs("div",{"data-key-row":s.id,role:"group","aria-labelledby":i,className:ar,children:[e.jsx(ir,{entry:s,status:l,titleId:i}),e.jsxs("div",{className:D("flex flex-col gap-2",rr),children:[c.configured&&e.jsx("div",{className:"flex",children:e.jsx(Md,{saved:c,label:t(s.labelKey)})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[s.whereKey&&e.jsx("span",{className:"min-w-0 flex-1 text-[12px] leading-4 text-ink-secondary",children:t(s.whereKey)}),r&&e.jsx("button",{type:"button","data-key-open":!0,className:"ui-button shrink-0",onClick:()=>a({type:"toggleAppSettings",open:!0,section:r}),children:t("keys.row.open")})]})]})]})}function nl({entry:s,visible:n}){return s.kind==="uses"&&s.uses?e.jsx(na,{id:s.uses,row:s.id}):s.kind==="panel"?e.jsx(Mh,{entry:s,visible:n}):s.kind==="elsewhere"?e.jsx(Dh,{entry:s}):e.jsx(na,{id:s.id,children:Uh[s.id]?.()})}function zh({id:s,rows:n,open:a,onToggle:i}){const{state:r}=_(),c=ht.find(p=>p.id===s),l=o.useId(),d=o.useId(),u=n.filter(p=>$s(p,r.config)).length;return e.jsxs("section",{"data-keys-section":s,"aria-labelledby":l,className:Bh,children:[e.jsxs("button",{type:"button","aria-expanded":a,"aria-controls":d,onClick:i,className:"flex w-full cursor-pointer items-center gap-3 rounded-[inherit] px-4 py-2.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus/60",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsx("span",{id:l,className:"text-[14px] font-medium leading-5 text-ink",children:t(c.titleKey)}),e.jsx("span",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t(c.purposeKey)})]}),u>0&&e.jsx("span",{className:"shrink-0 text-[12px] leading-4 text-ink-secondary",children:t("keys.section.connected",{count:u})}),e.jsx(St,{size:14,"aria-hidden":"true",className:D("shrink-0 text-ink-secondary transition-transform motion-reduce:transition-none",a&&"rotate-90")})]}),e.jsxs("div",{id:d,hidden:!a,className:"flex flex-col gap-0.5 border-t border-hairline/40 px-1 py-1.5 in-data-[settings-look=simple]:border-t-[0.5px] in-data-[settings-look=simple]:border-(--settings-edge)",children:[n.map(p=>e.jsx(nl,{entry:p,visible:a},p.id)),s==="voice"&&e.jsx(tl,{})]})]})}function _h(s,n,a){const i=n.row?s?.querySelector(`[data-key-row="${n.row}"]`):s?.querySelector(`[data-keys-section="${a}"]`);if(!i||i.closest("[hidden]"))return!1;const r=du(i);return r&&cr(r,i,n.row?"center":"start",16),n.row&&(i.querySelector("[data-key-input], [data-key-replace], [data-key-own], [data-key-open], input, button")?.focus({preventScroll:!0}),i.setAttribute("data-key-highlight",""),window.setTimeout(()=>i.removeAttribute("data-key-highlight"),Oh)),!0}function Hh({bare:s=!1,exclude:n=[]}={}){const{state:a}=_(),[i,r]=o.useState(""),[c,l]=o.useState(()=>new Set(ht.filter(h=>h.id==="ai"||mt.some(j=>j.section===h.id&&$s(j,a.config))).map(h=>h.id))),d=o.useRef(null),u=Fd(),p=i.trim().toLowerCase();o.useEffect(()=>{if(!u)return;const h=mt.find(v=>v.id===u.row)?.section??"ai";r(""),l(v=>v.has(h)?v:new Set([...v,h]));let j=0,b=0;const y=()=>{_h(d.current,u,h)||++b>60?Ud(u):j=window.requestAnimationFrame(y)};return j=window.requestAnimationFrame(y),()=>window.cancelAnimationFrame(j)},[u]);const x=mt.filter(h=>sr(h,p,a.config)&&!nr(h.id,a.config)),m=u?mt.find(h=>h.id===u.row)?.section:void 0,g=ht.filter(h=>!n.includes(h.id)||h.id===m).flatMap(h=>{const j=x.filter(b=>b.section===h.id);return j.length>0?[{id:h.id,rows:j}]:[]}),f=h=>l(j=>{const b=new Set(j);return b.has(h)?b.delete(h):b.add(h),b});return s?e.jsx("div",{ref:d,"data-keys-page":"",children:e.jsx(V,{icons:!0,children:g.map(({id:h,rows:j})=>{const b=ht.find(v=>v.id===h),y=j.filter(v=>$s(v,a.config)).length;return e.jsx(Qt,{id:`keys-${h}`,title:t(b.titleKey),subtitle:t(b.purposeKey),leading:e.jsx("span",{"aria-hidden":"true"}),value:y>0?t("keys.section.connected",{count:y}):void 0,open:c.has(h),onToggle:()=>f(h),children:e.jsxs("div",{"data-keys-section":h,className:"flex flex-col gap-0.5 py-1.5",children:[j.map(v=>e.jsx(nl,{entry:v,visible:c.has(h)},v.id)),h==="voice"&&e.jsx(tl,{})]})},h)})})}):e.jsxs("div",{ref:d,"data-keys-page":!0,className:"flex flex-col gap-4",children:[e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.connections.subtitle")}),e.jsxs("div",{className:"flex h-8 items-center gap-2 rounded-lg bg-ink/[0.05] px-[9px] focus-within:ring-2 focus-within:ring-focus/60",children:[e.jsx(Jt,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-keys-search":!0,type:"text",value:i,onChange:h=>r(h.target.value),onKeyDown:h=>{h.key!=="Escape"||!i||(h.preventDefault(),h.stopPropagation(),r(""))},placeholder:t("keys.search.placeholder"),"aria-label":t("keys.search.aria"),autoComplete:"off",spellCheck:!1,className:"w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),g.length===0?e.jsx("p",{"data-keys-empty":!0,className:"px-1 text-[13px] leading-[18px] text-ink-secondary",children:t("keys.search.none",{query:i.trim()})}):g.map(({id:h,rows:j})=>e.jsx(zh,{id:h,rows:j,open:p!==""||c.has(h),onToggle:()=>l(b=>{const y=new Set(b);return y.has(h)?y.delete(h):y.add(h),y})},h))]})}const As="/api/updates/server",$h=4e3;function Kh(){const s=typeof window>"u"?void 0:window.ogb;return s?.app?.ownPage===!1&&s.appUpdate&&s.app.version?s.app.version:null}const vi=s=>s?.run?.outcome!=="requested"&&s?.run?.outcome!=="running";function Wh(){const{state:s}=_(),n=s.connected!==!1,[a,i]=o.useState(null),[r,c]=o.useState(null),[l,d]=o.useState(!1),[u,p]=o.useState(!1),[x,m]=o.useState(!1),[g,f]=o.useState(null),[h,j]=o.useState(null),b=o.useCallback(async()=>{const E=await _d(As,()=>M(As,{timeoutMs:2e4}),null);return c(E),E},[]),y=o.useCallback(async()=>{d(!0),p(!1);try{const E=await M("/api/updates/check",{timeoutMs:2e4});i(E),E.install!=="desktop"&&E.install!=="managed"&&await b().catch(()=>null)}catch{p(!0)}finally{d(!1)}},[b]);o.useEffect(()=>{y()},[y]);const v=x||!vi(r),[w,N]=o.useState(null),[C,I]=o.useState(()=>Date.now());o.useEffect(()=>{if(!v)return void N(null);N(A=>A??Date.now());const E=setInterval(()=>I(Date.now()),3e4);return()=>clearInterval(E)},[v]),o.useEffect(()=>{if(!v||!n)return;let E=!0;const A=()=>{b().then(R=>{E&&vi(R)&&y()}).catch(()=>{})};A();const q=setInterval(A,$h);return()=>{E=!1,clearInterval(q)}},[v,n,b,y]);const F=o.useCallback(async()=>{m(!0),f(null);try{const E=await M(As,{method:"POST",body:"{}",timeoutMs:2e4});c(E.status)}catch(E){if(E instanceof Hd){const A=E.body;A?.status&&c(A.status),f(E.status===429?t("serverUpdate.reason.tooSoon"):E.status===409?null:t("serverUpdate.failed"))}else c(A=>A&&{...A,run:{outcome:"requested",from:A.current,at:Date.now()}})}finally{m(!1)}},[]),k=o.useCallback(async()=>{try{j(await window.ogb.appUpdate.request())}catch{j("failed")}},[]),S=w===null?0:Math.max(0,C-w),P=$d({check:a,status:r,app:Kh(),checking:l,failed:u,pressed:x,appAnswer:h,waitedMs:S});return{check:a,status:r,view:g?{...P,note:g,noteTone:"danger"}:P,load:y,readStatus:b,updateServer:F,updateApp:k}}const Gh={check:"settings.updates.check","update-server":"serverUpdate.updateServer","update-app":"serverUpdate.updateApp",reload:"settings.simple.updates.reload"};function qh({title:s}){const n=Wh(),[a,i]=o.useState(!1),{view:r,check:c,status:l}=n,d=()=>{if(r.action==="check")return void n.load();if(r.action==="reload")return window.location.reload();if(r.action==="update-app")return void n.updateApp();r.action==="update-server"&&(n.readStatus().catch(()=>null),i(!0))},u=c?.available&&c.releaseUrl&&r.action!=="check"?c.releaseUrl:null;return e.jsxs(e.Fragment,{children:[e.jsx(L,{title:s,subtitle:[r.label,r.subtitle].filter(Boolean).join(" "),message:r.note?e.jsx("span",{className:r.noteTone==="danger"?"text-danger":"text-ink-secondary",children:r.note}):void 0,children:e.jsxs("div",{className:"flex items-center gap-2",children:[u&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>Ps(u),children:t("settings.simple.updates.seeRelease")}),r.action&&e.jsx("button",{type:"button",className:"ui-button",disabled:r.busy,onClick:d,children:t(Gh[r.action])})]})}),e.jsx(Oi,{open:a,title:t("serverUpdate.confirmTitle"),body:zd(l?.activeTurns??0),confirmLabel:t("serverUpdate.updateServer"),onCancel:()=>i(!1),onConfirm:()=>{i(!1),n.updateServer()}})]})}function nt({anchor:s,also:n=[],children:a}){const{ctx:i,anchor:r}=we();return i.advanced?e.jsx(e.Fragment,{children:a}):r!==s&&!(r&&n.includes(r))?null:e.jsx(e.Fragment,{children:a})}const Ft="omb-settings-grouped-note",Vh=30;function Jh(){const[s,n]=o.useState(!1);return o.useEffect(()=>{try{const a=localStorage.getItem(Ft);if(a==="dismissed")return;const i=a?Number(a):null;if(i===null){if(!["omb-skin","omb-advanced-mode","omb-send-key"].some(c=>localStorage.getItem(c)!==null)){localStorage.setItem(Ft,"dismissed");return}localStorage.setItem(Ft,String(Date.now())),n(!0);return}n(Date.now()-i<Vh*864e5)}catch{}},[]),[s,()=>{n(!1);try{localStorage.setItem(Ft,"dismissed")}catch{}}]}function Yh(){const{ctx:s,place:n,go:a}=we(),{state:i,dispatch:r}=_(),[c,l]=Jh(),d=Fi(!s.client),u=i.config?.team,p=Ki()?.me?.role==="owner",x=d.kind==="paired"||d.kind==="attention"?t("settings.glance.phonePaired",{count:d.count}):d.kind==="none"?t("settings.glance.notSetUp"):void 0,m=i.instances.filter(f=>f.snapshot.state==="available").length,g=Xh();return e.jsxs(e.Fragment,{children:[c&&e.jsx(V,{children:e.jsxs("div",{className:"flex min-h-11 items-center gap-6 py-2 pl-4 pr-2","data-settings-grouped-note":"",children:[e.jsx("p",{className:"min-w-0 flex-1 text-[14px] leading-5 text-ink",children:t(s.desktop?"settings.overview.grouped":"settings.overview.groupedBrowser",{place:n.name})}),e.jsx("button",{type:"button","aria-label":t("settings.dismiss"),onClick:l,className:"flex size-7 shrink-0 cursor-pointer items-center justify-center rounded-full text-ink-secondary hover:bg-menu-hover hover:text-ink focus-visible:outline-2 focus-visible:outline-focus",children:e.jsx(Me,{size:14,"aria-hidden":"true"})})]})}),n.kind==="server"&&!s.client&&!window.ogb?.updater&&e.jsx(J,{label:t("settings.updates.title"),block:"version",children:e.jsx(V,{children:e.jsx(qh,{title:$t()})})}),e.jsx(J,{label:t("settings.overview.glance"),block:"glance",children:e.jsxs(V,{children:[!s.client&&e.jsx(ye,{title:t("settings.section.phoneDevices"),value:x,onClick:()=>a("phone"),data:{"data-glance":"phone"}}),!s.client&&e.jsx(ye,{title:t("settings.group.ai"),onClick:()=>a("ai","providers"),data:{"data-glance":"ai"},value:s.admin?m>0?t("settings.glance.aiReady",{count:m}):t("settings.glance.aiStart"):t("settings.glance.aiAdmin")}),s.advanced&&e.jsx(ye,{title:t("settings.glance.apps"),external:!0,value:g===null?void 0:g>0?t("settings.glance.appsConnected",{count:g}):t("settings.glance.appsNone"),onClick:()=>{r({type:"toggleAppSettings",open:!1}),r({type:"togglePlugins",open:!0})},data:{"data-glance":"apps"}})]})}),e.jsx(J,{label:t("settings.overview.sidebar"),block:"sidebar",children:e.jsxs(V,{children:[e.jsx(Qg,{}),e.jsx(Gd,{simple:!0})]})}),s.desktop&&s.cloud&&u&&u.cloudPage&&e.jsx("div",{"data-settings-block":"people-and-plan",children:e.jsx(bp,{team:u,admin:s.admin,owner:p})}),n.kind==="server"&&!s.client&&s.advanced&&e.jsx(eg,{})]})}function Xh(){const[s,n]=o.useState(null);return o.useEffect(()=>{let a=!0;return qd().then(i=>{a&&n(Object.values(i.services).filter(r=>r.connected).length)}).catch(()=>{}),()=>{a=!1}},[]),s}function Qh(){const{ctx:s,anchor:n}=we(),[a,i]=o.useState(!1),[r,c]=o.useState(s.advanced||n==="ai-keys"),l=s.advanced||r||n==="ai-keys",d=ht.filter(u=>u.id!=="ai").length;return e.jsx(e.Fragment,{children:e.jsxs(vt,{children:[e.jsx("div",{"data-settings-block":"providers",className:"flex scroll-mt-4 flex-col gap-6",children:e.jsx(yu,{simple:!0,more:{id:"ai-more",open:a,onToggle:()=>i(u=>!u)}})}),!s.advanced&&e.jsx(J,{block:"ai-keys-fold",children:e.jsx(V,{children:e.jsx(Qt,{id:"ai-other-services",title:t("settings.ai.otherServices"),value:String(d),open:l,onToggle:()=>c(!l)})})}),l&&e.jsx(J,{label:s.advanced?t("settings.ai.otherServices"):void 0,block:"ai-keys",children:e.jsx(Hh,{bare:!0,exclude:n==="ai-keys"?[]:["ai"]})}),e.jsx(nt,{anchor:"backup-model",children:e.jsx(J,{label:t("settings.ai.backupModel"),block:"backup-model",children:e.jsx(Gx,{})})}),e.jsx(nt,{anchor:"routing",children:e.jsx(ug,{})}),e.jsx(nt,{anchor:"images",children:e.jsx(wg,{})})]})})}function Zh(){const{ctx:s}=we(),{state:n}=_(),a=(n.config?.pausedBots?.length??0)>0;return e.jsxs(e.Fragment,{children:[a&&e.jsx(J,{block:"awake",children:e.jsx(V,{children:e.jsx(L,{title:t("settings.bots.awakeTitle"),subtitle:t("settings.bots.awakeLine"),children:e.jsx(Wd,{})})})}),e.jsx(J,{label:t("settings.bots.aboutYou"),block:"about-you",footnote:s.here||!s.desktop?t("settings.bots.aboutYouHome",{app:je()}):void 0,children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(pe,{children:e.jsx(rh,{})}),e.jsxs(V,{children:[e.jsx(pg,{}),e.jsx(qx,{row:!0})]})]})}),e.jsx(J,{label:t("settings.bots.newBots"),block:"new-bots",children:e.jsxs(V,{children:[e.jsx(qp,{}),e.jsx(wu,{simple:!0})]})}),!(s.team&&!s.admin)&&e.jsx(nt,{anchor:"limits",also:["parallel","group-turns","tool-time","keep-warm"],children:e.jsx(J,{label:t("settings.simple.more.limits"),block:"limits",children:e.jsxs(V,{selectWidth:160,children:[e.jsx("div",{"data-settings-block":"group-turns",className:"contents",children:e.jsx(lh,{})}),e.jsx("div",{"data-settings-block":"tool-time",className:"contents",children:e.jsx(Jg,{})}),e.jsx(gh,{}),e.jsx("div",{"data-settings-block":"keep-warm",className:"contents",children:e.jsx(vu,{})})]})})}),Vs(n.config)&&e.jsx("div",{"data-settings-block":"skills",children:e.jsx(mh,{})}),e.jsx(nt,{anchor:"early",children:e.jsx("div",{"data-settings-block":"early",children:e.jsx(am,{})})})]})}function ef(){const{ctx:s,anchor:n}=we(),[a,i]=o.useState(n==="desktop-details");return e.jsxs(e.Fragment,{children:[e.jsx(J,{label:t("settings.desktops.browserSection"),block:"browser",children:e.jsxs(V,{children:[e.jsx(Bp,{}),e.jsx(Op,{}),e.jsx(Fp,{}),s.advanced&&e.jsx("div",{"data-settings-block":"new-browser",className:"contents",children:e.jsx(Up,{})})]})}),e.jsx(vt,{children:e.jsx(uh,{})}),e.jsx(im,{}),s.advanced&&e.jsx(vt,{children:e.jsx(Kd,{id:"desktop-details",block:"desktop-details",title:t("settings.desktops.detailsTitle"),subtitle:t("settings.desktops.detailsLine"),open:a,onToggle:()=>i(r=>!r),children:e.jsx("div",{className:"flex flex-col gap-6 px-4 py-4",children:e.jsx(Jr,{})})})}),e.jsx(nt,{anchor:"automation",children:e.jsx(J,{label:t("settings.desktops.automation"),block:"automation",children:e.jsx(V,{children:e.jsx(oh,{})})})})]})}function tf(){const{ctx:s}=we();return!s.here||!window.ogb?.cloudSendPage?null:e.jsx(Vx,{bridge:window.ogb.cloudSendPage})}function sf(){return e.jsx("div",{"data-settings-block":"saved",className:"flex flex-col gap-6",children:e.jsx(Hx,{})})}function nf(){return e.jsx("div",{"data-settings-block":"summary",className:"flex flex-col gap-6",children:e.jsx(vt,{note:"settings.adminOnly.usage",children:e.jsx(Ox,{})})})}function af(){return e.jsx(vt,{children:e.jsx(Vd,{layout:({importRow:s,exportRow:n})=>e.jsxs(e.Fragment,{children:[e.jsx(J,{label:t("settings.data.bringIn"),block:"bring-in",children:e.jsx(tx,{children:s})}),e.jsxs(J,{label:t("settings.data.takeOut"),block:"take-out",children:[e.jsx(V,{children:n}),e.jsx(Xm,{})]}),e.jsx(tf,{})]})})})}function rf(){const{ctx:s}=we();return e.jsxs(e.Fragment,{children:[e.jsx(J,{label:t("settings.data.storage"),block:"storage",children:e.jsx(V,{children:e.jsx(Km,{})})}),s.advanced&&e.jsx(ax,{}),!s.desktop&&s.admin&&e.jsx($m,{})]})}function lf(){const{ctx:s}=we();return e.jsxs(e.Fragment,{children:[!s.desktop&&!s.cloud&&e.jsx(J,{label:t("settings.people.members"),block:"members",children:e.jsx(Ou,{})}),s.team&&e.jsx(J,{label:t("settings.section.botAccess"),block:"bot-access",footnote:s.desktop?void 0:t("settings.people.activityIn"),children:e.jsx(Gm,{})})]})}function of(){return e.jsx(zu,{})}function cf(){const{cloud:s,bridge:n}=lr(!0),a=Ct(),[i,r]=o.useState(!1);if(s!=="ready"||!n)return null;const c=a.find(d=>d.kind==="cloud")??null,l=c?.name||t("cloudSetup.myCloud");return e.jsxs("div",{"data-settings-block":"pair-cloud",className:"flex flex-col gap-2",children:[e.jsx(V,{icons:!0,children:e.jsxs("button",{type:"button","data-pair-with-cloud":"",onClick:()=>{r(!1),n.connectHomeForPhone().catch(()=>r(!0))},className:"flex min-h-16 w-full cursor-pointer items-center gap-3 px-4 py-3 text-left transition-colors hover:bg-menu-hover focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus",children:[e.jsx("span",{className:"flex size-8 shrink-0 items-center justify-center",children:e.jsx(Ii,{place:{kind:"cloud",name:l,color:c?.color??null},size:24})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsx("span",{className:"text-[14px] leading-5 text-ink",children:t("phone.pair.withPlace",{place:l})}),e.jsx("span",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("phone.pair.withPlaceLine",{place:l})})]}),e.jsx(Qs,{size:12,"aria-hidden":"true",className:"shrink-0 text-ink-tertiary"})]})}),i&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] leading-4 text-danger",children:t("cloudPhone.failed")})]})}function df(){const{ctx:s}=we(),{cloud:n,bridge:a}=lr(s.here),i=s.here&&n==="ready"&&!!a,r=Ct("phone").filter(c=>!(i&&c.kind==="cloud"));return!s.desktop||s.client||r.length===0?null:e.jsx(J,{label:t("settings.otherPlaces"),block:"other-places",children:e.jsx(V,{icons:!0,children:r.map(c=>e.jsx(ye,{title:c.name,subtitle:t("phone.otherPlace.line",{place:c.name}),leading:e.jsx(De,{place:{kind:c.kind==="computer"?"computer":"cloud",name:c.name,color:c.color},size:24}),external:!0,onClick:c.open,data:{"data-other-place":c.key}},c.key))})})}function uf(){const{ctx:s,place:n}=we(),{state:a}=_(),i=a.appSettingsPhonePairing;return e.jsxs(e.Fragment,{children:[s.here?e.jsx(uu,{profileEmail:a.config?.profile?.email,focusRequest:i,simple:!s.advanced,placeName:n.name,top:e.jsx(cf,{})}):e.jsx(pu,{cloudHome:s.cloud,focusRequest:i,team:a.config?.team?.name,placeName:n.name,simple:!s.advanced,teamPhoneBlocked:a.config?.managedPolicy?.remoteAccess===!1?t("policy.teamRemoteBlocked",{organization:a.config.managedPolicy.organizationName}):null}),e.jsx(df,{})]})}const pf={overview:Yh,phone:uf,ai:Qh,bots:Zh,desktops:ef,vault:sf,usage:nf,transfer:af,data:rf,people:lf,installations:of,account:Ep,plan:Ap,app:Mm,general:zm,appearance:Hm};function mf({page:s}){const n=pf[s];return e.jsx(n,{})}const yi={bots:"settings.bots.intro",desktops:"settings.desktops.intro",vault:"settings.vault.intro",app:"settings.app.intro"};function xf(s){const[a="",i=""]=t("settings.scope.for",{place:"⁣"}).split("⁣");return e.jsxs(e.Fragment,{children:[a&&e.jsx("span",{className:"text-ink-secondary",children:a}),e.jsx("span",{className:"text-ink",children:s}),i&&e.jsx("span",{className:"text-ink-secondary",children:i})]})}function gf(s){return s.places&&s.desktop?e.jsxs("span",{className:"text-ink-secondary",children:[" · ",t("settings.scope.everyPlace")]}):null}function hf(s){return s.kind==="computer"?`${$t(Ht())} · ${t("settings.overview.updatesWithApp")}`:`${s.kind==="server"?t("settings.place.running"):t("settings.place.alwaysOn")} · ${$t()}`}function ff({page:s,ctx:n,place:a}){if(s.id==="overview")return e.jsxs("p",{"data-settings-scope":"",className:"flex items-center gap-1.5 text-[13px] leading-[18px] text-ink-secondary",children:[a.kind!=="computer"&&e.jsx("span",{"aria-hidden":"true",className:"size-1.5 shrink-0 rounded-full bg-success"}),hf(a)]});const i=s.owner==="place"?e.jsx(De,{place:a,size:14}):s.owner==="account"?e.jsx(Kt,{size:14}):e.jsx(gr,{size:14}),r=s.owner==="place"?xf(a.name):s.owner==="account"?n.desktop?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-ink",children:t("settings.scope.account",{app:je()})}),gf(n)]}):e.jsx("span",{className:"text-ink-secondary",children:t("settings.scope.browserAccount",{place:a.name})}):n.desktop?e.jsx("span",{className:"text-ink",children:t("settings.scope.app",{app:je()})}):e.jsx("span",{className:"text-ink-secondary",children:t("settings.scope.browser")});return e.jsxs("p",{"data-settings-scope":"",className:"flex min-w-0 items-center gap-1.5 text-[13px] leading-[18px]",children:[e.jsx("span",{className:"flex size-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[4px]",children:i}),e.jsx("span",{className:"min-w-0 truncate",children:r})]})}function bf({page:s,ctx:n,place:a,narrow:i,missing:r}){const c=s.id!=="app"?yi[s.id]:n.desktop?n.advanced?yi.app:"settings.app.introSimple":n.advanced?"settings.app.introBrowserAdvanced":"settings.app.introBrowser",l=s.id==="account"?t("settings.page.account"):xt(s,a,n.desktop);return e.jsxs("header",{"data-settings-header":"",className:D("flex flex-col gap-1 pb-5",i?"px-8 pt-1":"pl-4 pt-4"),children:[!i&&e.jsx("h2",{id:"settings-page-title",className:"truncate pr-12 text-[18px] font-semibold leading-6 tracking-[-0.01em] text-ink",children:l}),e.jsx(ff,{page:s,ctx:n,place:a}),c&&e.jsx("p",{"data-settings-intro":c,className:"text-[13px] leading-[18px] text-ink-secondary",children:t(c,{place:a.name,app:je()})}),r&&e.jsx("p",{role:"status",className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.missingHere",{page:r,place:a.name})})]})}const vf="(max-width: 767.98px)",yf='button:not([disabled]), a[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, [tabindex]:not([tabindex="-1"])',ji="omb-settings-opened";function jf(){try{localStorage.getItem(ji)||localStorage.setItem(ji,String(Date.now()))}catch{}}function kf(s,n){if(!s||!n)return;const a=s.querySelector(`[data-settings-block="${CSS.escape(n)}"]`);if(!a)return;const i=getComputedStyle(a).display==="contents"?a.firstElementChild??a:a,r=s.querySelector("[data-settings-header]");if(i!==a||a.matches("[data-setting-row], [data-setting-row] *")){const l=i.getBoundingClientRect().top-s.getBoundingClientRect().top+s.scrollTop;s.scrollTop=Math.max(0,l-s.clientHeight/3),i.querySelector("input, select, textarea, button")?.focus({preventScroll:!0})}else cr(s,a,"start",(r?.offsetHeight??96)+8);i.setAttribute("data-settings-highlight",""),window.setTimeout(()=>i.removeAttribute("data-settings-highlight"),1200)}function wf(){const s=oo(),{state:n,dispatch:a}=_(),i=_u(),r=er(),c=Jd(vf,!1),l=Yd(n.appSettingsSection,i),[d,u]=o.useState(l.anchor??null),[p,x]=o.useState(n.appSettingsSection!=="overview"),[m,g]=o.useState(""),f=Xd(i),h=Mt(l.page),j=o.useRef(null),b=o.useRef(null);o.useEffect(()=>{u(l.anchor??null),x(R=>R||n.appSettingsSection!=="overview")},[n.appSettingsSection,l.anchor]),o.useEffect(()=>{const R=window.requestAnimationFrame(()=>{d?kf(b.current,d):b.current&&(b.current.scrollTop=0)});return()=>window.cancelAnimationFrame(R)},[d,l.page]),o.useEffect(()=>{l.advanced&&Ut(!0)},[l.advanced]),o.useEffect(()=>window.ogb?.onOpenAppSettings?.(()=>g("")),[]),o.useEffect(jf,[]);const y=o.useMemo(()=>Qd(m,i,R=>on({entry:R},r,i.desktop),R=>xt(R,r,i.desktop)),[m,i,r]),v=o.useMemo(()=>i.client||!m.trim()?[]:mt.filter(R=>!nr(R.id,n.config)&&sr(R,m.trim().toLowerCase(),n.config)).slice(0,8),[i.client,m,n.config]),w=R=>{g(""),x(!0),a(R.uses?Rs(R.uses,R.id):Rs(R.id))},N=Et(),C=()=>a({type:"toggleAppSettings",open:!1}),I=(R,K)=>{x(!0),R===l.page&&u(K??null),a({type:"toggleAppSettings",open:!0,section:R}),K&&window.setTimeout(()=>u(K),0)},F=R=>{const K=R.entry;if(K.jump==="apps"){C(),a({type:"togglePlugins",open:!0});return}if(K.jump==="automations"){C(),a({type:"showRoutines",view:"list"});return}if(K.jump==="shortcuts"){C(),a({type:"toggleShortcuts",open:!0});return}if(K.jump==="bot"){C();return}if(R.elsewhere){N.open?.();return}(R.advanced||su({page:K.page,anchor:K.anchor},i))&&Ut(!0),I(K.page,K.anchor)},k=R=>{!R&&!Mt(l.page).when({...i,advanced:!1})&&a({type:"toggleAppSettings",open:!0,section:"overview"}),Ut(R)};o.useEffect(()=>{const R=document.activeElement instanceof HTMLElement?document.activeElement:null,K=j.current,Z=K?.querySelector("[data-settings-search]");Z?.checkVisibility()?Z.focus({preventScroll:!0}):K?.focus();const oe=se=>{if(!s()||!K||se.defaultPrevented||[...K.querySelectorAll('[role="dialog"], [role="alertdialog"]')].some(U=>U.getClientRects().length))return;const Y=K.querySelector("[data-settings-search]"),B=document.activeElement instanceof HTMLInputElement||document.activeElement instanceof HTMLTextAreaElement||document.activeElement?.isContentEditable;if(Y&&(se.key==="/"&&!B||se.key.toLowerCase()==="f"&&(se.metaKey||se.ctrlKey))){se.preventDefault(),Y.focus(),Y.select();return}if(se.key==="Escape"){se.preventDefault(),C();return}if(se.key!=="Tab")return;const W=[...K.querySelectorAll(yf)].filter(U=>U.checkVisibility());if(W.length===0){se.preventDefault(),K.focus();return}const G=W[0],le=W[W.length-1];se.shiftKey&&(document.activeElement===G||!K.contains(document.activeElement))?(se.preventDefault(),le.focus()):!se.shiftKey&&document.activeElement===le&&(se.preventDefault(),G.focus())};return window.addEventListener("keydown",oe),()=>{window.removeEventListener("keydown",oe),R?.focus()}},[a,s]);const S={ctx:i,place:r,page:l.page,anchor:d,go:I},P=l.missing?xt(Mt(l.missing),r,i.desktop):void 0,E=c&&!p,A=c&&typeof window<"u"&&window.innerWidth/2-16-(30+t("settings.title").length*7)<xt(h,r,i.desktop).length*9/2,q=e.jsx("button",{type:"button",onClick:C,"aria-label":t("settings.close"),title:`${t("settings.close")} (${Zd("close-panel")})`,className:D("ui-icon-button z-20 size-8 shrink-0 cursor-pointer rounded-full text-ink-secondary hover:bg-menu-hover hover:text-ink",!c&&"absolute right-3 top-3"),children:e.jsx(Me,{size:16,"aria-hidden":"true"})});return e.jsx(Ae.Provider,{value:!0,children:e.jsx(rn.Provider,{value:S,children:e.jsxs("div",{className:"glass-popup-frame","data-settings-sheet":!0,"data-settings-look":"simple",style:{...tu(),"--settings-narrow-top":`${aa()===eu?12:aa()}px`},onMouseDown:R=>R.target===R.currentTarget&&C(),children:[e.jsx("div",{"aria-hidden":"true",className:"glass-scrim pointer-events-none absolute inset-0"}),e.jsxs("div",{ref:j,role:"dialog","data-look":"settings","aria-modal":"true","aria-labelledby":"app-settings-title",tabIndex:-1,style:{outline:"none"},"data-settings-page-open":l.page,"data-settings-advanced":i.advanced?"":void 0,className:"glass-surface glass-popup animate-pop-in relative flex flex-col overflow-hidden text-ink",children:[e.jsx("span",{id:"app-settings-title",className:"sr-only",children:t("settings.title")}),c&&e.jsxs("div",{className:"flex shrink-0 flex-col",children:[e.jsx("span",{"aria-hidden":"true",className:"mx-auto mt-2 h-1 w-8 rounded-full bg-ink/15"}),e.jsxs("div",{className:"relative flex h-12 items-center justify-between gap-2 px-2",children:[E?e.jsx("h2",{className:"flex-1 px-2 text-[16px] font-semibold leading-[22px] text-ink",children:t("settings.title")}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","data-settings-back":"","aria-label":A?t("settings.backTo"):void 0,onClick:()=>{x(!1),g("")},className:D("flex h-8 shrink-0 cursor-pointer items-center gap-0.5 rounded-full text-[13px] font-medium leading-5 text-ink-secondary hover:bg-menu-hover hover:text-ink",A?"w-8 justify-center":"pl-1 pr-2"),children:[e.jsx(Ci,{size:16,"aria-hidden":"true",className:"rtl:-scale-x-100"}),!A&&t("settings.title")]}),e.jsx("h2",{className:D("pointer-events-none absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 truncate text-center text-[16px] font-semibold leading-[22px] text-ink",A?"max-w-[calc(100%-96px)]":"max-w-[calc(100%-224px)]"),children:xt(h,r,i.desktop)})]}),q]})]}),e.jsxs("div",{className:"flex min-h-0 flex-1",children:[(!c||E)&&e.jsx(Xu,{ctx:i,place:r,pages:f,current:c?null:l.page,query:m,hits:y,narrow:c,onQuery:g,onOpen:R=>I(R),onHit:F,keyHits:v,onKey:w,onClose:C,onAdvanced:k}),(!c||!E)&&e.jsxs("div",{className:"relative flex min-h-0 min-w-0 flex-1 flex-col",children:[!c&&q,e.jsx("div",{ref:b,"data-settings-scroll":!0,"data-settings-content":"",className:D("settings-scroll min-h-0 flex-1 overflow-y-auto [scrollbar-gutter:stable]",c?"pb-12":"px-8 pb-12"),children:e.jsxs("div",{className:D("flex max-w-[640px] flex-col",c&&"max-w-none"),children:[e.jsx(bf,{page:h,ctx:i,place:r,narrow:c,missing:P}),e.jsxs("div",{"data-settings-page-body":l.page,className:D("flex flex-col gap-6",c&&"px-4"),children:[e.jsx(Au,{config:n.config}),h.owner==="place"&&n.config===null?n.error?e.jsx(mu,{place:r.name,onRetry:()=>{M("/api/config").then(R=>a({type:"configStatus",config:R})).catch(()=>{})}}):e.jsxs(e.Fragment,{children:[e.jsx(oa,{place:r.name}),e.jsx(oa,{place:r.name})]}):e.jsx(mf,{page:l.page})]},l.page)]})})]})]})]})]})})})}function Vf(){return e.jsx(Bi,{modal:!0,children:e.jsx(wf,{})})}export{Vf as SettingsModal};